/** * Per-phase workspace isolation ("worktree isolation", STRATEGY H2). * * By default a phase's `cwd` is a literal path (or inherited from the run). * Three reserved keywords ask the runtime to ALLOCATE an isolated working * directory for the phase's subagent(s) and tear it down afterwards: * * - `"temp"` — an ephemeral dir under the OS tmpdir; removed when the * phase finishes (success or failure). For scratch work that * must not touch the main tree. * - `"dedicated"` — a persistent dir under the run's own state directory * (`/ws//`); kept after the phase so * its artifacts survive for inspection / downstream reuse. * Idempotent across resume (same path for the same phase). * - `"worktree"` — a real `git worktree` on a throwaway branch, rooted at the * run's git repo; removed (`git worktree remove --force`) * when the phase finishes. For changes you want to diff / * commit / discard in isolation. Falls back to a `temp` dir * (fail-open) when the base dir is not a git work tree. * * Invariants honoured (AGENTS.md "Critical invariants"): * - Fail-open: any allocation/teardown error degrades gracefully and never * sinks the phase (a failed allocation falls back to the base cwd). * - No new deps: OS tmpdir via `fs.mkdtemp`, git via `child_process` (already * a peer of the runner). No third-party libraries. * - Resume-safe: `dedicated` is deterministic per (runId, phaseId) so a resume * reuses the same dir; `temp`/`worktree` are re-allocated cleanly. * - Path containment: `dedicated` dirs are contained under the run dir; * sanitized phase ids prevent traversal. */ /** The reserved `cwd` keywords that trigger workspace allocation. */ export declare const WORKSPACE_KEYWORDS: readonly ["temp", "dedicated", "worktree"]; export type WorkspaceKind = (typeof WORKSPACE_KEYWORDS)[number]; export declare function isWorkspaceKeyword(cwd: string | undefined): cwd is WorkspaceKind; /** A handle to an allocated workspace. `dir` is where the subagent runs. */ export interface Workspace { /** Resolved absolute working directory for the phase's subagent(s). */ dir: string; /** What was actually allocated (may differ from requested on fail-open). */ kind: WorkspaceKind | "inherited"; /** Idempotent teardown — safe to call once, after the phase completes. */ teardown(): void; /** For `worktree`: the throwaway branch name (diagnostics only). */ branch?: string; /** Non-fatal diagnostic if allocation degraded (e.g. worktree→temp). */ note?: string; } interface AllocOpts { /** The phase's effective base cwd (where it would run without isolation). */ baseCwd: string; /** Run id — anchors `dedicated` dirs and names throwaway worktree branches. */ runId: string; /** Phase id — second path segment / branch suffix. */ phaseId: string; /** The run's state dir root (`runsDir(cwd)`) for `dedicated` workspaces. */ runsRoot: string; } /** * Allocate an isolated workspace for a phase. Always returns a usable handle: * on any failure it falls back to the base cwd (fail-open) with a `note`. */ export declare function allocateWorkspace(kind: WorkspaceKind, opts: AllocOpts): Workspace; export {}; //# sourceMappingURL=workspace.d.ts.map