/** SDK-owned platform module. This implementation is maintained in goodvibes-sdk. */ import { type CommitWorkingTreeResult } from '../agents/worktree.js'; import type { OrchestrationEvent, WorkItem, Workstream } from './types.js'; export interface WorktreeIsolationManagerDeps { readonly projectRoot: string; readonly emit: (event: OrchestrationEvent) => void; readonly now?: (() => number) | undefined; /** Bounds how many KEPT (conflict/dirty) worktrees are retained before oldest-first eviction. Default 20. */ readonly keptWorktreeCap?: number | undefined; /** * Cold-start setup hook run once, right after a worktree is first created, so * an isolated agent starts with dependencies installed and carried-over * untracked files present instead of broken-by-default. The wiring is * responsible for capturing/recording the honest outcome (e.g. onto the * worktree registry record); a thrown/rejected setup NEVER fails worktree * creation, a broken setup is surfaced as a visible state, not a lost * worktree. Absent → today's behavior (no provisioning). */ readonly runSetup?: ((worktreePath: string) => Promise | void) | undefined; } export interface ItemWorktreeHandle { readonly path: string; commit(message: string, paths?: string[]): Promise; } export interface WorktreeIsolationManager { /** Ensure this item has a dedicated worktree (idempotent, created once, at first claim). Only meaningful when workstream.isolation === 'worktree'. */ ensureWorktree(workstream: Workstream, item: WorkItem): Promise; /** * Enqueue a just-passed item's branch onto the sequential integration lane. * Resolves once THIS item's attempt (merged/conflict/empty) and any * resulting cleanup has settled. Callers that don't need to wait may let * the returned promise run fire-and-forget (errors are caught internally, * this never rejects). */ enqueueIntegration(workstream: Workstream, item: WorkItem): Promise; /** Fail/kill cleanup rule: remove the item's worktree if clean, else KEEP it (data safety). No-op if the item never got a worktree. Never throws. */ cleanupTerminated(workstream: Workstream, item: WorkItem): Promise; /** Synchronous orphan scan, see the module doc. Call once, right after registering an imported workstream, before start()/tick(). */ reconcileOrphans(workstream: Workstream): void; /** * The diff an item's worktree branch introduced over base (best-of-N candidate * diff). Returns null when the item has no live worktree instance (e.g. already * cleaned, or never claimed). Never throws. */ diffItem(item: WorkItem): Promise<{ files: string[]; unifiedDiff: string; stat: string; } | null>; } export declare function itemWorktreeBranch(workstreamId: string, itemId: string): string; export declare function createWorktreeIsolationManager(deps: WorktreeIsolationManagerDeps): WorktreeIsolationManager; //# sourceMappingURL=worktree-isolation.d.ts.map