/** * Path utilities for init command * Handles finding package root and source directories */ import type { ParentSpecweaveFolder, UmbrellaParentResult, SuspiciousPathResult, UmbrellaDiscoveryResult } from './types.js'; import type { WorkspaceConfig } from '../../../core/config/types.js'; /** * Find the package root by walking up the directory tree looking for package.json * This works reliably on all platforms including Windows with UNC paths * * @param startDir - Directory to start searching from * @returns Path to package root or null if not found */ export declare function findPackageRoot(startDir: string): string | null; /** * Find the source directory, trying multiple possible locations * Handles both development and installed package scenarios * Windows-compatible with proper path normalization * * @param relativePath - Relative path to find (e.g., 'templates', 'plugins/specweave') * @param dirname - Current __dirname value * @returns Absolute path to the source directory */ export declare function findSourceDir(relativePath: string, dirname: string): string; /** * Detect ALL parent directories that contain .specweave/ folders * SpecWeave ONLY supports root-level .specweave/ folders * Nested .specweave/ folders are NOT supported * * EXCEPTION: User-level ~/.specweave is VALID and doesn't block initialization. * This is used for global SpecWeave settings (memory, logs, state, skills-cache). * * @param targetDir - Directory where user wants to initialize * @returns Array of paths to parent .specweave/ folders with depth info, or null if none found */ export declare function detectNestedSpecweave(targetDir: string): ParentSpecweaveFolder[] | null; /** * Segments that indicate a path is NOT a project root. * Used by detectSuspiciousPath() to prevent init in wrong locations. */ export declare const SUSPICIOUS_PATH_SEGMENTS: readonly string[]; /** * Detect if the target directory is inside an umbrella project. * Walks up from targetDir looking for parent .specweave/config.json * that indicates an umbrella repo (has repository.umbrellaRepo or * a sibling repositories/ directory). * * @param targetDir - Directory where user wants to initialize * @returns UmbrellaParentResult if inside an umbrella, null otherwise */ export declare function detectUmbrellaParent(targetDir: string): UmbrellaParentResult | null; /** * Check if a path is inside the OS system temp directory. * * Uses os.tmpdir() to detect the real system temp dir, avoiding false positives * on user-created folders named "temp" or "tmp". * * @param resolvedPath - Absolute path to check * @returns true if the path is the system temp dir or a subdirectory of it */ export declare function isSystemTempDir(resolvedPath: string): boolean; /** * Detect if the target directory path contains suspicious segments * that indicate it's NOT a project root (e.g., node_modules, dist, .git), * or if it's inside the system temp directory. * * @param targetDir - Directory where user wants to initialize * @returns SuspiciousPathResult if suspicious segment found, null otherwise */ export declare function detectSuspiciousPath(targetDir: string): SuspiciousPathResult | null; /** * Discover the repositories a workspace folder holds. No layout is required: * * - `repositories//` (where `specweave get` clones) and `repositories/` always count. * - A folder outside any Git checkout can only be a folder of repositories, so any checkout up * to three levels down counts too, whatever its folders are called (`api`, `services/web`). * - In a checkout, or a folder inside one, other nested checkouts may be fixtures or vendored * copies, so they are not added; {@link scanUnregisteredCheckouts} names them for * `specweave get ./`. * * Sibling and external repositories are never guessed: `specweave get ../` registers them. * * @param targetDir - The project root directory to scan * @returns UmbrellaDiscoveryResult if repos found, null otherwise */ export declare function scanUmbrellaRepos(targetDir: string): UmbrellaDiscoveryResult | null; /** * Discover workspace repos: the registered `workspace.repos` entries, then the * nested checkouts scanUmbrellaRepos finds that are not registered yet. * * @param targetDir - The project root directory to scan * @returns UmbrellaDiscoveryResult if repos found, null otherwise */ export declare function scanWorkspaceRepos(targetDir: string): UmbrellaDiscoveryResult | null; /** * Separate clones (a `.git` folder) nested in a workspace folder that is, or sits inside, * a Git checkout and not listed by the scan, as POSIX paths relative to it. Init names each * with the command that adds it in place. Submodules and linked worktrees (a `.git` * file) belong to the folder's own repository and are left out. * * @param targetDir - The project root directory to scan * @param discovery - Result of scanWorkspaceRepos(), whose repositories are already listed * @returns Relative paths of the unlisted clones, sorted */ export declare function scanUnregisteredCheckouts(targetDir: string, discovery: UmbrellaDiscoveryResult | null): string[]; /** * Build umbrella config fragment from discovered repos. * Generates 3-char uppercase prefixes with deduplication (2-char + numeric suffix on collision). * * @param discovery - Result of scanUmbrellaRepos() * @param projectName - Name of the umbrella project * @returns Config fragment with umbrella and repository fields */ export declare function buildUmbrellaConfig(discovery: UmbrellaDiscoveryResult, projectName: string): { umbrella: { enabled: true; projectName: string; childRepos: Array<{ id: string; path: string; name: string; prefix: string; }>; }; repository: { umbrellaRepo: true; }; }; /** * Build workspace config fragment from discovered repos. * Returns { workspace: WorkspaceConfig } instead of the legacy { umbrella: UmbrellaConfig }. * Each repo gets an empty sync: {} default. * * @param discovery - Result of scanWorkspaceRepos() * @param projectName - Name of the workspace project * @returns Config fragment with workspace field */ export declare function buildWorkspaceConfig(discovery: UmbrellaDiscoveryResult, projectName: string): { workspace: WorkspaceConfig; repository: { umbrellaRepo: true; }; }; /** * Count files recursively in a directory * Used for logging before deletion * * @param dir - Directory to count files in * @returns Total file count */ export declare function countFilesRecursive(dir: string): number; //# sourceMappingURL=path-utils.d.ts.map