/** * Workspace Command Helper * * Handles workspace-aware command execution for monorepos. * Detects workspace commands, groups packages by workspace, * and provides utilities for distributing results to packages. * * Supports: * - Cargo workspaces (--workspace, --manifest-path) * - npm/pnpm workspaces (--workspaces, -w, --recursive) * - Yarn workspaces */ import type { PackageLayer } from '../types/layer-types'; /** * Ecosystem types for workspace detection */ export type WorkspaceEcosystem = 'rust' | 'node' | 'python' | 'go'; /** * Information about a workspace command */ export interface WorkspaceCommandInfo { /** Whether this command targets an entire workspace */ isWorkspaceCommand: boolean; /** * The workspace root directory extracted from the command * e.g., "codex-rs" from "--manifest-path codex-rs/Cargo.toml" */ workspaceRoot?: string; /** The ecosystem this command belongs to */ ecosystem?: WorkspaceEcosystem; } /** * A group of packages that belong to the same workspace */ export interface WorkspaceGroup { /** The workspace root directory (relative to repo root) */ workspaceRoot: string; /** Path to the workspace manifest file */ manifestPath: string; /** The ecosystem (rust, node, etc.) */ ecosystem: WorkspaceEcosystem; /** Packages that are members of this workspace */ memberPackages: PackageLayer[]; /** The root package of the workspace (if it exists as a package) */ rootPackage?: PackageLayer; } /** * Detect if a command is a workspace-wide command and extract workspace info. * * Detects: * - Cargo: --workspace, --manifest-path * - pnpm: -r, --recursive, -w, --workspace-root, --filter * - npm: --workspaces, -ws * - yarn: workspaces foreach * * @param command - The command being executed (e.g., "cargo", "pnpm") * @param args - Command arguments as an array * @returns WorkspaceCommandInfo with detection results * * @example * ```ts * // Cargo workspace command * detectWorkspaceCommand('cargo', ['clippy', '--manifest-path', 'codex-rs/Cargo.toml', '--workspace']) * // => { isWorkspaceCommand: true, workspaceRoot: 'codex-rs', ecosystem: 'rust' } * * // pnpm recursive command * detectWorkspaceCommand('pnpm', ['-r', 'run', 'lint']) * // => { isWorkspaceCommand: true, ecosystem: 'node' } * * // Regular command (not workspace-wide) * detectWorkspaceCommand('cargo', ['clippy']) * // => { isWorkspaceCommand: false } * ``` */ export declare function detectWorkspaceCommand(command: string, args: string[]): WorkspaceCommandInfo; /** * Group discovered packages by their workspace. * * Uses the package's `isWorkspace`, `parentPackage`, and `isMonorepoRoot` * fields to determine workspace membership. * * @param packages - Array of discovered packages * @returns Array of workspace groups * * @example * ```ts * const packages = await packageModule.discoverPackages(fileTree); * const workspaceGroups = groupPackagesByWorkspace(packages); * * for (const group of workspaceGroups) { * console.log(`Workspace: ${group.workspaceRoot}`); * console.log(`Members: ${group.memberPackages.map(p => p.packageData.name)}`); * } * ``` */ export declare function groupPackagesByWorkspace(packages: PackageLayer[]): WorkspaceGroup[]; /** * Match a file path to its package within a workspace. * * Used to distribute lens results to the correct packages. * Takes a file path (relative to workspace root) and finds * which package it belongs to. * * @param filePath - File path relative to workspace root (e.g., "protocol/src/lib.rs") * @param workspaceRoot - Workspace root directory (e.g., "codex-rs") * @param packages - Array of packages to search * @returns The matching package, or undefined if not found * * @example * ```ts * // Clippy outputs: "protocol/src/lib.rs" (relative to codex-rs/) * // We need to find which package this belongs to * * const pkg = matchPathToPackage( * 'protocol/src/lib.rs', * 'codex-rs', * packages * ); * // => PackageLayer for "codex-rs/protocol" * ``` */ export declare function matchPathToPackage(filePath: string, workspaceRoot: string, packages: PackageLayer[]): PackageLayer | undefined; /** * Prefix a file path with the workspace root. * * Utility function to convert paths from workspace-relative * to repo-relative. * * @param filePath - File path relative to workspace root * @param workspaceRoot - Workspace root directory * @returns Full path relative to repo root * * @example * ```ts * prefixWithWorkspaceRoot('protocol/src/lib.rs', 'codex-rs') * // => 'codex-rs/protocol/src/lib.rs' * ``` */ export declare function prefixWithWorkspaceRoot(filePath: string, workspaceRoot: string): string; //# sourceMappingURL=WorkspaceCommandHelper.d.ts.map