/** * `cleo worktree adopt` — register an externally-created worktree in the SSoT * (T9804 — Claude Code Agent isolation:worktree bridge). * * ## Rationale (Option B: Adopt) * * Claude Code's Agent tool `isolation:worktree` creates worktrees under * `.claude/worktrees//` and does NOT call `cleo orchestrate spawn`. * CLEO cannot modify the harness directly, so we adopt the worktrees post-hoc: * * 1. `cleo worktree adopt ` reads the worktree's `.git` gitlink to * extract the branch name. * 2. The entry is upserted into `/.cleo/worktrees.json` (the in-project * sentinel index, council D009 hybrid pattern). * 3. An audit-log entry `{action:"adopt", source:"claude-agent", ...}` is * appended to `.cleo/audit/worktree-lifecycle.jsonl` via the T9547 helper. * 4. After adoption `cleo worktree list` returns the entry tagged with * `source: "claude-agent"` in addition to the git-native worktrees. * * Idempotent: re-adopting the same path updates the index entry but does not * create duplicate audit entries (the audit helper always appends so the * duplicate-adopt is still visible in the log for traceability). * * ## Lifecycle / Cleanup * * Adopted worktrees surface in `cleo worktree list` and are therefore subject * to the same auto-cleanup hooks as CLEO-spawned worktrees — namely: * * - `cleo worktree prune --orphaned` will offer to remove adopted orphans. * - T9805 auto-cleanup hooks will fire on PR merge for adopted branches. * * @task T9804 * @epic T9804 * @saga T9800 * @adr ADR-055 — worktree canonical paths * @adr ADR-062 — git merge --no-ff integration semantics */ import type { AdoptWorktreeOpts, AdoptWorktreeResult } from '@cleocode/contracts'; import { type EngineResult } from '@cleocode/contracts'; export type { AdoptWorktreeOpts, AdoptWorktreeResult }; /** * Register an externally-created worktree in the CLEO SSoT. * * This is the SDK primitive behind `cleo worktree adopt `. It: * * 1. Validates that `worktreePath` is a real directory containing a `.git` * gitlink (or `.git` directory for primary worktrees). * 2. Extracts the current branch name from the gitlink's `HEAD` file. * 3. Upserts the entry into `/.cleo/worktrees.json`. * 4. Appends an audit-log entry to `.cleo/audit/worktree-lifecycle.jsonl`. * * @param opts - Adoption options. * @returns EngineResult containing an {@link AdoptWorktreeResult} on success. * * @example * ```ts * const result = await adoptWorktree({ * worktreePath: '/mnt/projects/cleocode/.claude/worktrees/session-abc/', * projectRoot: '/mnt/projects/cleocode', * source: 'claude-agent', * }); * if (result.success) { * console.log('Adopted:', result.data.branch, '(new:', result.data.isNew, ')'); * } * ``` */ export declare function adoptWorktree(opts: AdoptWorktreeOpts): Promise>; /** Success shape for {@link extractBranchFromWorktree}. */ interface BranchSuccess { success: true; branch: string; } /** Failure shape for {@link extractBranchFromWorktree}. */ interface BranchFailure { success: false; error: string; } /** * Read the branch name from a worktree directory. * * A git worktree directory may contain: * - A `.git` file (gitlink) pointing to the admin dir under `.git/worktrees//` * - A real `.git/` directory (primary checkout) * * In both cases the current branch is recorded in `HEAD` as either: * - `ref: refs/heads/` — normal branch checkout * - A raw commit SHA — detached HEAD * * @param worktreePath - Absolute path to the worktree directory. * @returns Branch name on success, or an error string on failure. * @internal Exported for tests only. */ export declare function extractBranchFromWorktree(worktreePath: string): BranchSuccess | BranchFailure; /** * Extract a task ID from a branch name following the `task/T####` or * `feat/T####` naming convention. * * Mirrors the same logic in `list.ts` with an extension for `feat/` branches * (common for Claude Code Agent worktrees). Duplicated here to avoid a circular * import between `adopt` and `list`. * * @param branch - Git branch name. * @returns The task ID string, or null if the branch does not match. * @internal Exported for tests only. */ export declare function taskIdFromBranch(branch: string): string | null; //# sourceMappingURL=worktree-adopt.d.ts.map