@cleocode/worktree 2026.5.100 → 2026.5.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,15 +2,21 @@
2
2
  * Worktree listing operations for @cleocode/worktree.
3
3
  *
4
4
  * `listWorktrees` and `listWorktreesByProjectRoot` scan the CLEO XDG worktrees
5
- * directory to return structured entries.
5
+ * directory and use `@cleocode/worktree-napi` (`listWorktrees` →
6
+ * `worktrunk_core::git_wt::list_worktrees`) to look up per-entry branch info
7
+ * in a single Rust call — the prior N+1 `git rev-parse` loop is gone.
6
8
  *
9
+ * Classification of each entry (status / stale / orphan / owningTask) stays in
10
+ * TS because it consumes the tasks DB and other CLEO-specific state.
11
+ *
12
+ * @task T9982
7
13
  * @task T1161
8
14
  */
9
- import { execFileSync } from 'node:child_process';
10
15
  import { existsSync, readdirSync } from 'node:fs';
11
16
  import { join } from 'node:path';
12
17
  import { computeProjectHash, getCleoWorktreesRoot, resolveWorktreeRootForHash, } from '@cleocode/paths';
13
- import { DEFAULT_GIT_TIMEOUT_MS } from './git.js';
18
+ import { getGitRoot } from './git.js';
19
+ import { listWorktrees as napiListWorktrees } from './napi-binding.js';
14
20
  /**
15
21
  * Resolve the worktree root directory for a given project hash.
16
22
  *
@@ -23,14 +29,43 @@ import { DEFAULT_GIT_TIMEOUT_MS } from './git.js';
23
29
  export function resolveWorktreeRoot(projectHash, worktreeRoot) {
24
30
  return resolveWorktreeRootForHash(projectHash, worktreeRoot);
25
31
  }
32
+ /**
33
+ * Build a `worktreePath → branch` lookup table for all worktrees registered
34
+ * with `gitRoot`, using the napi binding for the porcelain parse.
35
+ *
36
+ * Falls back to an empty map on any error — callers degrade gracefully to
37
+ * the synthesized `task/<taskId>` default in {@link listWorktrees}.
38
+ *
39
+ * @internal
40
+ */
41
+ function buildBranchLookup(gitRoot) {
42
+ if (!gitRoot)
43
+ return new Map();
44
+ let infos;
45
+ try {
46
+ infos = napiListWorktrees({ repoRoot: gitRoot });
47
+ }
48
+ catch {
49
+ return new Map();
50
+ }
51
+ const lookup = new Map();
52
+ for (const info of infos) {
53
+ if (info.branch)
54
+ lookup.set(info.path, info.branch);
55
+ }
56
+ return lookup;
57
+ }
26
58
  /**
27
59
  * List all active CLEO worktrees scoped to a specific project hash.
28
60
  *
29
61
  * Scans the XDG worktrees filesystem directory. Entries without a valid
30
- * worktree path on disk are omitted.
62
+ * worktree path on disk are omitted. Branch lookup is performed once per call
63
+ * via `napi.listWorktrees` — no per-entry `git rev-parse` invocation.
31
64
  *
32
65
  * @param options - Listing options including optional project hash filter.
33
66
  * @returns Array of worktree entries.
67
+ *
68
+ * @task T9982
34
69
  */
35
70
  export function listWorktrees(options = {}) {
36
71
  const worktreesBase = getCleoWorktreesRoot();
@@ -44,6 +79,9 @@ export function listWorktrees(options = {}) {
44
79
  catch {
45
80
  return [];
46
81
  }
82
+ // Cache one branch lookup per gitRoot — callers typically pass a single
83
+ // projectHash, so this collapses to a single napi call per listWorktrees().
84
+ const branchLookups = new Map();
47
85
  for (const hash of projectHashes) {
48
86
  // Filter by project hash when provided
49
87
  if (options.projectHash && hash !== options.projectHash)
@@ -60,7 +98,19 @@ export function listWorktrees(options = {}) {
60
98
  const worktreePath = join(hashDir, taskId);
61
99
  if (!existsSync(worktreePath))
62
100
  continue;
63
- const branch = resolveWorktreeBranch(worktreePath) ?? `task/${taskId}`;
101
+ let gitRoot;
102
+ try {
103
+ gitRoot = getGitRoot(worktreePath);
104
+ }
105
+ catch {
106
+ gitRoot = null;
107
+ }
108
+ let lookup = gitRoot ? branchLookups.get(gitRoot) : undefined;
109
+ if (gitRoot && !lookup) {
110
+ lookup = buildBranchLookup(gitRoot);
111
+ branchLookups.set(gitRoot, lookup);
112
+ }
113
+ const branch = lookup?.get(worktreePath) ?? `task/${taskId}`;
64
114
  entries.push({
65
115
  path: worktreePath,
66
116
  branch,
@@ -84,27 +134,4 @@ export function listWorktreesByProjectRoot(projectRoot) {
84
134
  const projectHash = computeProjectHash(projectRoot);
85
135
  return listWorktrees({ projectHash });
86
136
  }
87
- /**
88
- * Resolve the current branch for a worktree directory by invoking git.
89
- *
90
- * Returns null if the path is not a valid git worktree or git fails.
91
- *
92
- * @param worktreePath - Absolute path to the worktree directory.
93
- * @returns Branch name string, or null if not determinable.
94
- * @internal
95
- */
96
- function resolveWorktreeBranch(worktreePath) {
97
- try {
98
- // T9545 — bound git rev-parse with a default timeout so a wedged child
99
- // can never block worktree enumeration in the spawn pipeline.
100
- return execFileSync('git', ['-C', worktreePath, 'rev-parse', '--abbrev-ref', 'HEAD'], {
101
- encoding: 'utf-8',
102
- stdio: ['pipe', 'pipe', 'pipe'],
103
- timeout: DEFAULT_GIT_TIMEOUT_MS,
104
- }).trim();
105
- }
106
- catch {
107
- return null;
108
- }
109
- }
110
137
  //# sourceMappingURL=worktree-list.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worktree-list.js","sourceRoot":"","sources":["../src/worktree-list.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAmB,EAAE,YAAqB;IAC5E,OAAO,0BAA0B,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,UAAgC,EAAE;IAC9D,MAAM,aAAa,GAAG,oBAAoB,EAAE,CAAC;IAE7C,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAA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AS;YAExC,IAAI,OAAsB,CAAC;YAC3B,IAAI,CAAC;gBACH,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;YACrC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC;YAED,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC9D,IAAI,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;gBACvB,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;gBACpC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACrC,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,IAAI,QAAQ,MAAM,EAAE,CAAC;YAC7D,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,YAAY;gBAClB,MAAM;gBACN,MAAM;gBACN,WAAW,EAAE,IAAI;aAClB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CAAC,WAAmB;IAC5D,MAAM,WAAW,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;IACpD,OAAO,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;AACxC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleocode/worktree",
3
- "version": "2026.5.100",
3
+ "version": "2026.5.101",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Native CLEO worktree backend SDK — createWorktree, destroyWorktree, listWorktrees, pruneWorktrees with XDG path canon and declarative hooks (T1161)",
@@ -30,14 +30,15 @@
30
30
  "author": "CLEO Code <hello@cleocode.dev>",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@cleocode/contracts": "2026.5.100",
34
- "@cleocode/paths": "2026.5.100"
33
+ "@cleocode/worktree-napi": "file:../../crates/worktree-napi",
34
+ "@cleocode/contracts": "2026.5.101",
35
+ "@cleocode/paths": "2026.5.101"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/node": "^24.3.0",
38
39
  "typescript": "^6.0.2",
39
40
  "vitest": "^4.1.4",
40
- "@cleocode/core": "2026.5.100"
41
+ "@cleocode/core": "2026.5.101"
41
42
  },
42
43
  "repository": {
43
44
  "type": "git",
package/dist/compat.d.ts DELETED
@@ -1,126 +0,0 @@
1
- /**
2
- * Backward-compatibility shim for callers of `packages/cant/src/worktree.ts`.
3
- *
4
- * Provides the legacy `WorktreeConfig`-based API surface on top of the new
5
- * native SDK. Callers that import from `@cleocode/cant` continue working
6
- * unchanged; new callers should use the primary SDK surface in `index.ts`.
7
- *
8
- * @remarks
9
- * These adapters are deprecated and will be removed once all callers have
10
- * been migrated to `@cleocode/worktree`.
11
- *
12
- * @deprecated Use `@cleocode/worktree` directly.
13
- * @task T1161
14
- */
15
- /**
16
- * Request payload for creating a new git worktree (legacy API).
17
- *
18
- * @deprecated Use {@link CreateWorktreeOptions} from `@cleocode/worktree`.
19
- */
20
- export interface LegacyWorktreeRequest {
21
- /** The base ref to branch from (e.g. "main", "develop", a SHA). */
22
- baseRef: string;
23
- /** Branch name for the worktree. If absent, derived from taskId. */
24
- branchName?: string;
25
- /** Task ID driving this worktree. */
26
- taskId: string;
27
- /** Why this worktree is being created. */
28
- reason: 'subagent' | 'experiment' | 'parallel-wave';
29
- }
30
- /**
31
- * Handle returned after worktree creation (legacy API).
32
- *
33
- * @deprecated Use {@link CreateWorktreeResult} from `@cleocode/worktree`.
34
- */
35
- export interface LegacyWorktreeHandle {
36
- /** Absolute path to the worktree directory. */
37
- path: string;
38
- /** Branch name created for this worktree. */
39
- branch: string;
40
- /** The base ref it was branched from. */
41
- baseRef: string;
42
- /** Task ID. */
43
- taskId: string;
44
- /** Project hash. */
45
- projectHash: string;
46
- /** Clean up: remove the worktree and optionally delete the branch. */
47
- cleanup(deleteBranch?: boolean): void;
48
- }
49
- /**
50
- * Configuration for worktree path resolution (legacy API).
51
- *
52
- * @deprecated Use `projectRoot` directly with the new SDK functions.
53
- */
54
- export interface LegacyWorktreeConfig {
55
- /** Root directory for worktrees. Defaults to XDG_DATA_HOME/cleo/worktrees/<projectHash>/ */
56
- worktreeRoot?: string;
57
- /** Project hash for path scoping. */
58
- projectHash: string;
59
- /** The project's git root directory. */
60
- gitRoot: string;
61
- }
62
- /**
63
- * Result of a merge operation (legacy API).
64
- *
65
- * @deprecated Use {@link DestroyWorktreeResult} from `@cleocode/worktree`.
66
- */
67
- export interface LegacyMergeResult {
68
- /** Whether the merge succeeded. */
69
- success: boolean;
70
- /** Error message if the merge failed. */
71
- error?: string;
72
- }
73
- /**
74
- * Entry in the list of active worktrees (legacy API).
75
- *
76
- * @deprecated Use {@link WorktreeListEntry} from `@cleocode/contracts`.
77
- */
78
- export interface LegacyWorktreeEntry {
79
- /** Absolute path to the worktree directory. */
80
- path: string;
81
- /** Branch checked out in this worktree. */
82
- branch: string;
83
- }
84
- /**
85
- * Resolve the worktree root directory (legacy API).
86
- *
87
- * @deprecated Use `resolveWorktreeRoot` from `@cleocode/worktree`.
88
- * @param config - Legacy worktree config.
89
- * @returns Absolute path to the worktree root directory.
90
- */
91
- export declare function legacyResolveWorktreeRoot(config: LegacyWorktreeConfig): string;
92
- /**
93
- * Create a git worktree using the legacy config-based API.
94
- *
95
- * Wraps the new native SDK but returns a {@link LegacyWorktreeHandle} for
96
- * backward compatibility. Callers should migrate to `createWorktree` from
97
- * `@cleocode/worktree`.
98
- *
99
- * @deprecated Use `createWorktree` from `@cleocode/worktree`.
100
- * @param request - Legacy worktree request.
101
- * @param config - Legacy worktree config.
102
- * @returns A legacy handle with a cleanup function.
103
- */
104
- export declare function legacyCreateWorktree(request: LegacyWorktreeRequest, config: LegacyWorktreeConfig): LegacyWorktreeHandle;
105
- /**
106
- * Merge a worktree's branch back into the current branch (legacy API).
107
- *
108
- * @deprecated Use `completeAgentWorktreeViaMerge` from `@cleocode/core`
109
- * followed by `destroyWorktree` from `@cleocode/worktree` (ADR-062).
110
- * @param handle - Legacy worktree handle.
111
- * @param config - Legacy worktree config.
112
- * @param options - Merge strategy options.
113
- * @returns Merge result.
114
- */
115
- export declare function legacyMergeWorktree(handle: LegacyWorktreeHandle, config: LegacyWorktreeConfig, options?: {
116
- strategy?: 'ff-only' | 'no-ff';
117
- }): LegacyMergeResult;
118
- /**
119
- * List active worktrees scoped to the current project (legacy API).
120
- *
121
- * @deprecated Use `listWorktrees` from `@cleocode/worktree`.
122
- * @param config - Legacy worktree config.
123
- * @returns Array of legacy worktree entries.
124
- */
125
- export declare function legacyListWorktrees(config: LegacyWorktreeConfig): LegacyWorktreeEntry[];
126
- //# sourceMappingURL=compat.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAYH;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,eAAe,CAAC;CACrD;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe;IACf,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,OAAO,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACvC;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,4FAA4F;IAC5F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAMD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAE9E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,oBAAoB,GAC3B,oBAAoB,CAuBtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,EAC5B,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,SAAS,GAAG,OAAO,CAAA;CAAO,GAC/C,iBAAiB,CAenB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,oBAAoB,GAAG,mBAAmB,EAAE,CA8BvF"}
package/dist/compat.js DELETED
@@ -1,163 +0,0 @@
1
- /**
2
- * Backward-compatibility shim for callers of `packages/cant/src/worktree.ts`.
3
- *
4
- * Provides the legacy `WorktreeConfig`-based API surface on top of the new
5
- * native SDK. Callers that import from `@cleocode/cant` continue working
6
- * unchanged; new callers should use the primary SDK surface in `index.ts`.
7
- *
8
- * @remarks
9
- * These adapters are deprecated and will be removed once all callers have
10
- * been migrated to `@cleocode/worktree`.
11
- *
12
- * @deprecated Use `@cleocode/worktree` directly.
13
- * @task T1161
14
- */
15
- import { execFileSync } from 'node:child_process';
16
- import { existsSync, mkdirSync, rmSync } from 'node:fs';
17
- import { join } from 'node:path';
18
- import { DEFAULT_GIT_TIMEOUT_MS, gitSilent, gitSync } from './git.js';
19
- import { resolveWorktreeRootForHash } from './paths.js';
20
- // ---------------------------------------------------------------------------
21
- // Legacy API implementations
22
- // ---------------------------------------------------------------------------
23
- /**
24
- * Resolve the worktree root directory (legacy API).
25
- *
26
- * @deprecated Use `resolveWorktreeRoot` from `@cleocode/worktree`.
27
- * @param config - Legacy worktree config.
28
- * @returns Absolute path to the worktree root directory.
29
- */
30
- export function legacyResolveWorktreeRoot(config) {
31
- return resolveWorktreeRootForHash(config.projectHash, config.worktreeRoot);
32
- }
33
- /**
34
- * Create a git worktree using the legacy config-based API.
35
- *
36
- * Wraps the new native SDK but returns a {@link LegacyWorktreeHandle} for
37
- * backward compatibility. Callers should migrate to `createWorktree` from
38
- * `@cleocode/worktree`.
39
- *
40
- * @deprecated Use `createWorktree` from `@cleocode/worktree`.
41
- * @param request - Legacy worktree request.
42
- * @param config - Legacy worktree config.
43
- * @returns A legacy handle with a cleanup function.
44
- */
45
- export function legacyCreateWorktree(request, config) {
46
- const root = legacyResolveWorktreeRoot(config);
47
- mkdirSync(root, { recursive: true });
48
- const branch = request.branchName ?? `task/${request.taskId}`;
49
- const worktreePath = join(root, request.taskId);
50
- // Remove stale worktree if it exists.
51
- if (existsSync(worktreePath)) {
52
- try {
53
- gitSilent(['worktree', 'unlock', worktreePath], config.gitRoot);
54
- if (!gitSilent(['worktree', 'remove', '--force', worktreePath], config.gitRoot)) {
55
- rmSync(worktreePath, { recursive: true, force: true });
56
- }
57
- }
58
- catch {
59
- rmSync(worktreePath, { recursive: true, force: true });
60
- }
61
- }
62
- // Create the worktree.
63
- gitSync(['worktree', 'add', worktreePath, '-b', branch, request.baseRef], config.gitRoot);
64
- return buildLegacyHandle(worktreePath, branch, request.baseRef, request.taskId, config);
65
- }
66
- /**
67
- * Merge a worktree's branch back into the current branch (legacy API).
68
- *
69
- * @deprecated Use `completeAgentWorktreeViaMerge` from `@cleocode/core`
70
- * followed by `destroyWorktree` from `@cleocode/worktree` (ADR-062).
71
- * @param handle - Legacy worktree handle.
72
- * @param config - Legacy worktree config.
73
- * @param options - Merge strategy options.
74
- * @returns Merge result.
75
- */
76
- export function legacyMergeWorktree(handle, config, options = {}) {
77
- const strategy = options.strategy ?? 'ff-only';
78
- const mergeFlag = strategy === 'ff-only' ? '--ff-only' : '--no-ff';
79
- try {
80
- gitSync(['merge', mergeFlag, handle.branch], config.gitRoot);
81
- handle.cleanup(true);
82
- return { success: true };
83
- }
84
- catch (err) {
85
- const message = err instanceof Error ? err.message : String(err);
86
- return {
87
- success: false,
88
- error: `Merge failed: ${message}. Worktree retained at ${handle.path} for forensics.`,
89
- };
90
- }
91
- }
92
- /**
93
- * List active worktrees scoped to the current project (legacy API).
94
- *
95
- * @deprecated Use `listWorktrees` from `@cleocode/worktree`.
96
- * @param config - Legacy worktree config.
97
- * @returns Array of legacy worktree entries.
98
- */
99
- export function legacyListWorktrees(config) {
100
- try {
101
- // T9545 — bound `git worktree list` with a default timeout so a wedged
102
- // child can never block legacy worktree enumeration callers.
103
- const output = execFileSync('git', ['worktree', 'list', '--porcelain'], {
104
- cwd: config.gitRoot,
105
- encoding: 'utf-8',
106
- timeout: DEFAULT_GIT_TIMEOUT_MS,
107
- });
108
- const entries = [];
109
- const root = legacyResolveWorktreeRoot(config);
110
- let currentPath = '';
111
- let currentBranch = '';
112
- for (const line of output.split('\n')) {
113
- if (line.startsWith('worktree ')) {
114
- currentPath = line.slice('worktree '.length);
115
- }
116
- else if (line.startsWith('branch ')) {
117
- currentBranch = line.slice('branch refs/heads/'.length);
118
- }
119
- else if (line === '') {
120
- if (currentPath.startsWith(root)) {
121
- entries.push({ path: currentPath, branch: currentBranch });
122
- }
123
- currentPath = '';
124
- currentBranch = '';
125
- }
126
- }
127
- return entries;
128
- }
129
- catch {
130
- return [];
131
- }
132
- }
133
- // ---------------------------------------------------------------------------
134
- // Internal helpers
135
- // ---------------------------------------------------------------------------
136
- /**
137
- * Build a legacy WorktreeHandle with a cleanup closure.
138
- * @internal
139
- */
140
- function buildLegacyHandle(worktreePath, branch, baseRef, taskId, config) {
141
- return {
142
- path: worktreePath,
143
- branch,
144
- baseRef,
145
- taskId,
146
- projectHash: config.projectHash,
147
- cleanup(deleteBranch = false) {
148
- try {
149
- gitSilent(['worktree', 'unlock', worktreePath], config.gitRoot);
150
- if (!gitSilent(['worktree', 'remove', '--force', worktreePath], config.gitRoot)) {
151
- rmSync(worktreePath, { recursive: true, force: true });
152
- }
153
- }
154
- catch {
155
- rmSync(worktreePath, { recursive: true, force: true });
156
- }
157
- if (deleteBranch) {
158
- gitSilent(['branch', '-D', branch], config.gitRoot);
159
- }
160
- },
161
- };
162
- }
163
- //# sourceMappingURL=compat.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compat.js","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAgFxD,8EAA8E;AAC9E,6BAA6B;AAC7B,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAA4B;IACpE,OAAO,0BAA0B,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;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