@cleocode/worktree 2026.4.161 → 2026.5.1
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.
- package/dist/compat.d.ts +2 -2
- package/dist/compat.js +2 -2
- package/dist/worktree-destroy.d.ts +14 -10
- package/dist/worktree-destroy.d.ts.map +1 -1
- package/dist/worktree-destroy.js +19 -44
- package/dist/worktree-destroy.js.map +1 -1
- package/package.json +2 -2
package/dist/compat.d.ts
CHANGED
|
@@ -105,8 +105,8 @@ export declare function legacyCreateWorktree(request: LegacyWorktreeRequest, con
|
|
|
105
105
|
/**
|
|
106
106
|
* Merge a worktree's branch back into the current branch (legacy API).
|
|
107
107
|
*
|
|
108
|
-
* @deprecated Use `
|
|
109
|
-
* `@cleocode/worktree
|
|
108
|
+
* @deprecated Use `completeAgentWorktreeViaMerge` from `@cleocode/core`
|
|
109
|
+
* followed by `destroyWorktree` from `@cleocode/worktree` (ADR-062).
|
|
110
110
|
* @param handle - Legacy worktree handle.
|
|
111
111
|
* @param config - Legacy worktree config.
|
|
112
112
|
* @param options - Merge strategy options.
|
package/dist/compat.js
CHANGED
|
@@ -66,8 +66,8 @@ export function legacyCreateWorktree(request, config) {
|
|
|
66
66
|
/**
|
|
67
67
|
* Merge a worktree's branch back into the current branch (legacy API).
|
|
68
68
|
*
|
|
69
|
-
* @deprecated Use `
|
|
70
|
-
* `@cleocode/worktree
|
|
69
|
+
* @deprecated Use `completeAgentWorktreeViaMerge` from `@cleocode/core`
|
|
70
|
+
* followed by `destroyWorktree` from `@cleocode/worktree` (ADR-062).
|
|
71
71
|
* @param handle - Legacy worktree handle.
|
|
72
72
|
* @param config - Legacy worktree config.
|
|
73
73
|
* @param options - Merge strategy options.
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Worktree destroy operation for @cleocode/worktree.
|
|
3
3
|
*
|
|
4
|
-
* Removes the git worktree for a completed task.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Removes the git worktree for a completed task. Integration (merge) is
|
|
5
|
+
* performed separately via `completeAgentWorktreeViaMerge` (ADR-062) before
|
|
6
|
+
* calling destroy. Destroy only removes the worktree filesystem entry and
|
|
7
|
+
* optionally the task branch.
|
|
7
8
|
*
|
|
8
9
|
* @task T1161
|
|
10
|
+
* @adr ADR-062
|
|
9
11
|
*/
|
|
10
12
|
import type { DestroyWorktreeOptions, DestroyWorktreeResult } from '@cleocode/contracts';
|
|
11
13
|
/**
|
|
12
14
|
* Destroy the git worktree for a task.
|
|
13
15
|
*
|
|
14
16
|
* Steps:
|
|
15
|
-
* 1.
|
|
16
|
-
* 2.
|
|
17
|
-
* 3.
|
|
18
|
-
* 4. Optionally delete the task branch.
|
|
17
|
+
* 1. Unlock the worktree (`git worktree unlock`).
|
|
18
|
+
* 2. Remove the worktree directory (`git worktree remove --force`).
|
|
19
|
+
* 3. Optionally delete the task branch.
|
|
19
20
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
21
|
+
* Integration (merging commits back to the target branch) is performed by
|
|
22
|
+
* `completeAgentWorktreeViaMerge` before this function is called. Non-fatal
|
|
23
|
+
* errors are captured in the result's `error` field. The caller decides
|
|
24
|
+
* whether to propagate them.
|
|
22
25
|
*
|
|
23
26
|
* @param projectRoot - Absolute path to the project root directory.
|
|
24
|
-
* @param options - Destroy options including task ID and optional
|
|
27
|
+
* @param options - Destroy options including task ID and optional branch deletion.
|
|
25
28
|
* @returns Structured result of the destroy operation.
|
|
26
29
|
*
|
|
27
30
|
* @task T1161
|
|
31
|
+
* @adr ADR-062
|
|
28
32
|
*/
|
|
29
33
|
export declare function destroyWorktree(projectRoot: string, options: DestroyWorktreeOptions): DestroyWorktreeResult;
|
|
30
34
|
//# sourceMappingURL=worktree-destroy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree-destroy.d.ts","sourceRoot":"","sources":["../src/worktree-destroy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worktree-destroy.d.ts","sourceRoot":"","sources":["../src/worktree-destroy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAIzF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,sBAAsB,GAC9B,qBAAqB,CAiDvB"}
|
package/dist/worktree-destroy.js
CHANGED
|
@@ -1,72 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Worktree destroy operation for @cleocode/worktree.
|
|
3
3
|
*
|
|
4
|
-
* Removes the git worktree for a completed task.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Removes the git worktree for a completed task. Integration (merge) is
|
|
5
|
+
* performed separately via `completeAgentWorktreeViaMerge` (ADR-062) before
|
|
6
|
+
* calling destroy. Destroy only removes the worktree filesystem entry and
|
|
7
|
+
* optionally the task branch.
|
|
7
8
|
*
|
|
8
9
|
* @task T1161
|
|
10
|
+
* @adr ADR-062
|
|
9
11
|
*/
|
|
10
12
|
import { existsSync, rmSync } from 'node:fs';
|
|
11
|
-
import { getGitRoot, gitSilent, gitSync
|
|
13
|
+
import { getGitRoot, gitSilent, gitSync } from './git.js';
|
|
12
14
|
import { computeProjectHash, resolveTaskWorktreePath } from './paths.js';
|
|
13
15
|
/**
|
|
14
16
|
* Destroy the git worktree for a task.
|
|
15
17
|
*
|
|
16
18
|
* Steps:
|
|
17
|
-
* 1.
|
|
18
|
-
* 2.
|
|
19
|
-
* 3.
|
|
20
|
-
* 4. Optionally delete the task branch.
|
|
19
|
+
* 1. Unlock the worktree (`git worktree unlock`).
|
|
20
|
+
* 2. Remove the worktree directory (`git worktree remove --force`).
|
|
21
|
+
* 3. Optionally delete the task branch.
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
23
|
+
* Integration (merging commits back to the target branch) is performed by
|
|
24
|
+
* `completeAgentWorktreeViaMerge` before this function is called. Non-fatal
|
|
25
|
+
* errors are captured in the result's `error` field. The caller decides
|
|
26
|
+
* whether to propagate them.
|
|
24
27
|
*
|
|
25
28
|
* @param projectRoot - Absolute path to the project root directory.
|
|
26
|
-
* @param options - Destroy options including task ID and optional
|
|
29
|
+
* @param options - Destroy options including task ID and optional branch deletion.
|
|
27
30
|
* @returns Structured result of the destroy operation.
|
|
28
31
|
*
|
|
29
32
|
* @task T1161
|
|
33
|
+
* @adr ADR-062
|
|
30
34
|
*/
|
|
31
35
|
export function destroyWorktree(projectRoot, options) {
|
|
32
|
-
const { taskId, deleteBranch = true
|
|
36
|
+
const { taskId, deleteBranch = true } = options;
|
|
33
37
|
const gitRoot = getGitRoot(projectRoot);
|
|
34
38
|
const projectHash = computeProjectHash(projectRoot);
|
|
35
39
|
const worktreePath = resolveTaskWorktreePath(projectHash, taskId);
|
|
36
40
|
const branch = `task/${taskId}`;
|
|
37
|
-
const baseRef = resolveHeadRef(gitRoot);
|
|
38
|
-
let cherryPicked = false;
|
|
39
|
-
let commitCount = 0;
|
|
40
41
|
let worktreeRemoved = false;
|
|
41
42
|
let branchDeleted = false;
|
|
42
43
|
let error;
|
|
43
|
-
// Step 1:
|
|
44
|
-
if (cherryPickFirst) {
|
|
45
|
-
try {
|
|
46
|
-
const branchExists = gitSync(['branch', '--list', branch], gitRoot);
|
|
47
|
-
if (branchExists) {
|
|
48
|
-
const log = gitSync(['log', '--reverse', '--format=%H', `${baseRef}..${branch}`], gitRoot);
|
|
49
|
-
const commits = log
|
|
50
|
-
.split('\n')
|
|
51
|
-
.map((s) => s.trim())
|
|
52
|
-
.filter(Boolean);
|
|
53
|
-
if (commits.length > 0) {
|
|
54
|
-
gitSync(['cherry-pick', ...commits], gitRoot);
|
|
55
|
-
cherryPicked = true;
|
|
56
|
-
commitCount = commits.length;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
cherryPicked = true;
|
|
60
|
-
commitCount = 0;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
gitSilent(['cherry-pick', '--abort'], gitRoot);
|
|
66
|
-
error = `Cherry-pick failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// Step 2: Unlock + remove the worktree (even if cherry-pick failed — caller decided).
|
|
44
|
+
// Step 1: Unlock + remove the worktree.
|
|
70
45
|
if (existsSync(worktreePath)) {
|
|
71
46
|
gitSilent(['worktree', 'unlock', worktreePath], gitRoot);
|
|
72
47
|
if (gitSilent(['worktree', 'remove', '--force', worktreePath], gitRoot)) {
|
|
@@ -87,7 +62,7 @@ export function destroyWorktree(projectRoot, options) {
|
|
|
87
62
|
else {
|
|
88
63
|
worktreeRemoved = true; // already gone
|
|
89
64
|
}
|
|
90
|
-
// Step
|
|
65
|
+
// Step 2: Optionally delete the branch.
|
|
91
66
|
if (deleteBranch) {
|
|
92
67
|
try {
|
|
93
68
|
const branchExists = gitSync(['branch', '--list', branch], gitRoot);
|
|
@@ -105,6 +80,6 @@ export function destroyWorktree(projectRoot, options) {
|
|
|
105
80
|
else {
|
|
106
81
|
branchDeleted = false;
|
|
107
82
|
}
|
|
108
|
-
return { taskId,
|
|
83
|
+
return { taskId, worktreeRemoved, branchDeleted, error };
|
|
109
84
|
}
|
|
110
85
|
//# sourceMappingURL=worktree-destroy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree-destroy.js","sourceRoot":"","sources":["../src/worktree-destroy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worktree-destroy.js","sourceRoot":"","sources":["../src/worktree-destroy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,SA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MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9F,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;SAAM,CAAC;QACN,eAAe,GAAG,IAAI,CAAC,CAAC,eAAe;IACzC,CAAC;IAED,wCAAwC;IACxC,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;YACpE,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;YAC7C,CAAC;YACD,aAAa,GAAG,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,KAAK,GAAG,4BAA4B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACzF,CAAC;QACH,CAAC;IACH,CAAC;SAAM,CAAC;QACN,aAAa,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleocode/worktree",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.5.1",
|
|
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)",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"env-paths": "^4.0.0",
|
|
34
|
-
"@cleocode/contracts": "2026.
|
|
34
|
+
"@cleocode/contracts": "2026.5.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^24.3.0",
|