import { GitService } from '../../git/service.js'; import type { WorktreeSetupResult } from './setup.js'; export type ManagedWorktreeState = 'active' | 'paused' | 'kept' | 'discard' | 'pending-cleanup'; export type ManagedWorktreeKind = 'agent' | 'orchestrator' | 'manual'; export interface ManagedWorktreeMeta { readonly path: string; readonly kind: ManagedWorktreeKind; readonly state: ManagedWorktreeState; readonly ownerId?: string | undefined; readonly sessionId?: string | undefined; readonly taskId?: string | undefined; readonly updatedAt: number; /** * Cold-start setup outcome for this worktree, when setup ran (on creation or * a re-run). Persisted so a failed setup is a VISIBLE worktree/fleet-node * state, never silent, surfaces read it straight off the worktree record * (worktrees.snapshot). Absent when no setup has ever run for this worktree. */ readonly setup?: WorktreeSetupResult | undefined; } export interface WorktreeStatusRecord extends ManagedWorktreeMeta { readonly branch: string; readonly head: string; } export interface WorktreeOwnershipSummary { readonly total: number; readonly active: number; readonly paused: number; readonly kept: number; readonly discard: number; readonly pendingCleanup: number; readonly sessionAttached: number; readonly taskAttached: number; readonly agentOwned: number; readonly orchestratorOwned: number; readonly manualOwned: number; } export interface WorktreeAttachmentReview { readonly targetKind: 'session' | 'task'; readonly targetId: string; readonly total: number; readonly active: number; readonly paused: number; readonly kept: number; readonly discard: number; readonly pendingCleanup: number; readonly records: readonly ManagedWorktreeMeta[]; } export interface WorktreeRegistryPaths { readonly workingDirectory: string; readonly surfaceRoot?: string | undefined; } export declare function listPersistedWorktreeMeta(options: WorktreeRegistryPaths): ManagedWorktreeMeta[]; export declare function getPersistedWorktreeMeta(path: string, options: WorktreeRegistryPaths): ManagedWorktreeMeta | null; export declare function reviewWorktreeAttachments(targetKind: 'session' | 'task', targetId: string, options: WorktreeRegistryPaths): WorktreeAttachmentReview; export declare function summarizeWorktreeOwnership(records: readonly ManagedWorktreeMeta[]): WorktreeOwnershipSummary; export declare class WorktreeRegistry { private readonly git; private readonly workingDirectory; private readonly surfaceRoot?; constructor(workingDirectory: string, options?: { readonly surfaceRoot?: string; }); /** * List live worktrees, reconciling the register against `git worktree list`. * * This is also the register's recurring housekeeping point: surfaces poll it, * so reaping here is not startup-only. It reclaims records whose worktree is * gone, ages out and count-caps `kept` tombstones, and sweeps expired * preserved-aside register files, disclosing every count. */ list(): Promise; attach(path: string, target: { sessionId?: string; taskId?: string; }): void; setState(path: string, state: ManagedWorktreeState): void; /** * Record a cold-start setup outcome onto a worktree's record (on creation or * a re-run), so a failed setup is a visible, queryable worktree/fleet-node * state rather than a lost log. Upserts the record if setup ran before the * worktree was otherwise registered. */ recordSetup(path: string, setup: WorktreeSetupResult): void; cleanup(path: string): Promise; /** * DISCARD actually discards, per the eviction-preserving rules: * 1. Any uncommitted state is first COMMITTED onto the worktree's branch * (data safety; a preservation failure refuses the removal rather than * losing work). * 2. The worktree DIRECTORY is removed (`git worktree remove`). * 3. The BRANCH is kept, never deleted on this path. * Returns an honest receipt either way; the record is dropped only when the * directory really came off disk. */ discard(path: string): Promise; /** Injectable seam for tests: a GitService rooted INSIDE the worktree being discarded. */ protected createWorktreeGit(worktreePath: string): Pick; } /** The honest record of one discard: what came off disk, what was kept, what was preserved. */ export interface WorktreeDiscardReceipt { readonly path: string; /** True only when the directory really came off disk. */ readonly ok: boolean; /** The branch that was KEPT (never deleted by discard). */ readonly branch?: string | undefined; /** The preservation commit recorded for uncommitted state, when the tree was dirty. */ readonly preservedCommit?: string | undefined; readonly discardedAt: number; readonly detail: string; } //# sourceMappingURL=registry.d.ts.map