@cleocode/worktree 2026.4.117
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 +126 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +160 -0
- package/dist/compat.js.map +1 -0
- package/dist/git.d.ts +53 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +90 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +51 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +66 -0
- package/dist/paths.js.map +1 -0
- package/dist/worktree-create.d.ts +36 -0
- package/dist/worktree-create.d.ts.map +1 -0
- package/dist/worktree-create.js +127 -0
- package/dist/worktree-create.js.map +1 -0
- package/dist/worktree-destroy.d.ts +30 -0
- package/dist/worktree-destroy.d.ts.map +1 -0
- package/dist/worktree-destroy.js +110 -0
- package/dist/worktree-destroy.js.map +1 -0
- package/dist/worktree-hooks.d.ts +32 -0
- package/dist/worktree-hooks.d.ts.map +1 -0
- package/dist/worktree-hooks.js +67 -0
- package/dist/worktree-hooks.js.map +1 -0
- package/dist/worktree-include.d.ts +54 -0
- package/dist/worktree-include.d.ts.map +1 -0
- package/dist/worktree-include.js +99 -0
- package/dist/worktree-include.js.map +1 -0
- package/dist/worktree-list.d.ts +40 -0
- package/dist/worktree-list.d.ts.map +1 -0
- package/dist/worktree-list.js +110 -0
- package/dist/worktree-list.js.map +1 -0
- package/dist/worktree-prune.d.ts +27 -0
- package/dist/worktree-prune.d.ts.map +1 -0
- package/dist/worktree-prune.js +91 -0
- package/dist/worktree-prune.js.map +1 -0
- package/package.json +49 -0
package/dist/compat.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
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 `destroyWorktree` with `cherryPickFirst: true` from
|
|
109
|
+
* `@cleocode/worktree`.
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["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AAoB,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,CA2BvF"}
|
package/dist/compat.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
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 { 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 `destroyWorktree` with `cherryPickFirst: true` from
|
|
70
|
+
* `@cleocode/worktree`.
|
|
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
|
+
const output = execFileSync('git', ['worktree', 'list', '--porcelain'], {
|
|
102
|
+
cwd: config.gitRoot,
|
|
103
|
+
encoding: 'utf-8',
|
|
104
|
+
});
|
|
105
|
+
const entries = [];
|
|
106
|
+
const root = legacyResolveWorktreeRoot(config);
|
|
107
|
+
let currentPath = '';
|
|
108
|
+
let currentBranch = '';
|
|
109
|
+
for (const line of output.split('\n')) {
|
|
110
|
+
if (line.startsWith('worktree ')) {
|
|
111
|
+
currentPath = line.slice('worktree '.length);
|
|
112
|
+
}
|
|
113
|
+
else if (line.startsWith('branch ')) {
|
|
114
|
+
currentBranch = line.slice('branch refs/heads/'.length);
|
|
115
|
+
}
|
|
116
|
+
else if (line === '') {
|
|
117
|
+
if (currentPath.startsWith(root)) {
|
|
118
|
+
entries.push({ path: currentPath, branch: currentBranch });
|
|
119
|
+
}
|
|
120
|
+
currentPath = '';
|
|
121
|
+
currentBranch = '';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return entries;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// Internal helpers
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
/**
|
|
134
|
+
* Build a legacy WorktreeHandle with a cleanup closure.
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
function buildLegacyHandle(worktreePath, branch, baseRef, taskId, config) {
|
|
138
|
+
return {
|
|
139
|
+
path: worktreePath,
|
|
140
|
+
branch,
|
|
141
|
+
baseRef,
|
|
142
|
+
taskId,
|
|
143
|
+
projectHash: config.projectHash,
|
|
144
|
+
cleanup(deleteBranch = false) {
|
|
145
|
+
try {
|
|
146
|
+
gitSilent(['worktree', 'unlock', worktreePath], config.gitRoot);
|
|
147
|
+
if (!gitSilent(['worktree', 'remove', '--force', worktreePath], config.gitRoot)) {
|
|
148
|
+
rmSync(worktreePath, { recursive: true, force: true });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
rmSync(worktreePath, { recursive: true, force: true });
|
|
153
|
+
}
|
|
154
|
+
if (deleteBranch) {
|
|
155
|
+
gitSilent(['branch', '-D', branch], config.gitRoot);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=compat.js.map
|
|
@@ -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D,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,iBAAiB,CACxB,YAAoB,EACpB,MAAc,EACd,OAAe,EACf,MAAc,EACd,MAA4B;IAE5B,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,MAAM;QACN,OAAO;QACP,MAAM;QACN,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,CAAC,YAAY,GAAG,KAAK;YAC1B,IAAI,CAAC;gBACH,SAAS,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;gBAChE,IAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;oBAChF,MAAM,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBACzD,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACzD,CAAC;YACD,IAAI,YAAY,EAAE,CAAC;gBACjB,SAAS,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level git helpers for @cleocode/worktree.
|
|
3
|
+
*
|
|
4
|
+
* All git invocations use `execFileSync` / `execFile` with explicit arg
|
|
5
|
+
* arrays (never shell interpolation) to prevent command injection.
|
|
6
|
+
*
|
|
7
|
+
* @task T1161
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Run a git command synchronously and return trimmed stdout.
|
|
11
|
+
*
|
|
12
|
+
* @param args - Git argument array (do NOT include "git" as first element).
|
|
13
|
+
* @param cwd - Working directory for the git command.
|
|
14
|
+
* @returns Trimmed stdout string.
|
|
15
|
+
* @throws Error if the command exits non-zero.
|
|
16
|
+
*/
|
|
17
|
+
export declare function gitSync(args: string[], cwd: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Run a git command synchronously, returning false instead of throwing on error.
|
|
20
|
+
*
|
|
21
|
+
* Useful for best-effort cleanup operations where failure is non-fatal.
|
|
22
|
+
*
|
|
23
|
+
* @param args - Git argument array.
|
|
24
|
+
* @param cwd - Working directory.
|
|
25
|
+
* @returns true on exit 0, false otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export declare function gitSilent(args: string[], cwd: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Run a git command asynchronously, returning trimmed stdout.
|
|
30
|
+
*
|
|
31
|
+
* @param args - Git argument array.
|
|
32
|
+
* @param cwd - Working directory.
|
|
33
|
+
* @returns Promise resolving to trimmed stdout.
|
|
34
|
+
* @throws Error if the command exits non-zero.
|
|
35
|
+
*/
|
|
36
|
+
export declare function gitAsync(args: string[], cwd: string): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Determine the git root directory for a given project path.
|
|
39
|
+
*
|
|
40
|
+
* @param projectRoot - Absolute path to start the search from.
|
|
41
|
+
* @returns Absolute path to the git root.
|
|
42
|
+
* @throws Error if not inside a git repository.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getGitRoot(projectRoot: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve the current HEAD ref (branch name or SHA) for a git repository.
|
|
47
|
+
*
|
|
48
|
+
* @param gitRoot - Absolute path to the git root.
|
|
49
|
+
* @param fallback - Value to return if HEAD resolution fails.
|
|
50
|
+
* @returns Current HEAD ref string.
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveHeadRef(gitRoot: string, fallback?: string): string;
|
|
53
|
+
//# sourceMappingURL=git.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAO9D;AAED;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAM3E;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAMtD;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,SAAS,GAAG,MAAM,CAMzE"}
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level git helpers for @cleocode/worktree.
|
|
3
|
+
*
|
|
4
|
+
* All git invocations use `execFileSync` / `execFile` with explicit arg
|
|
5
|
+
* arrays (never shell interpolation) to prevent command injection.
|
|
6
|
+
*
|
|
7
|
+
* @task T1161
|
|
8
|
+
*/
|
|
9
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
10
|
+
import { promisify } from 'node:util';
|
|
11
|
+
const execFileAsync = promisify(execFile);
|
|
12
|
+
/**
|
|
13
|
+
* Run a git command synchronously and return trimmed stdout.
|
|
14
|
+
*
|
|
15
|
+
* @param args - Git argument array (do NOT include "git" as first element).
|
|
16
|
+
* @param cwd - Working directory for the git command.
|
|
17
|
+
* @returns Trimmed stdout string.
|
|
18
|
+
* @throws Error if the command exits non-zero.
|
|
19
|
+
*/
|
|
20
|
+
export function gitSync(args, cwd) {
|
|
21
|
+
return execFileSync('git', args, {
|
|
22
|
+
cwd,
|
|
23
|
+
encoding: 'utf-8',
|
|
24
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
25
|
+
}).trim();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run a git command synchronously, returning false instead of throwing on error.
|
|
29
|
+
*
|
|
30
|
+
* Useful for best-effort cleanup operations where failure is non-fatal.
|
|
31
|
+
*
|
|
32
|
+
* @param args - Git argument array.
|
|
33
|
+
* @param cwd - Working directory.
|
|
34
|
+
* @returns true on exit 0, false otherwise.
|
|
35
|
+
*/
|
|
36
|
+
export function gitSilent(args, cwd) {
|
|
37
|
+
try {
|
|
38
|
+
execFileSync('git', args, { cwd, stdio: 'pipe' });
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Run a git command asynchronously, returning trimmed stdout.
|
|
47
|
+
*
|
|
48
|
+
* @param args - Git argument array.
|
|
49
|
+
* @param cwd - Working directory.
|
|
50
|
+
* @returns Promise resolving to trimmed stdout.
|
|
51
|
+
* @throws Error if the command exits non-zero.
|
|
52
|
+
*/
|
|
53
|
+
export async function gitAsync(args, cwd) {
|
|
54
|
+
const { stdout } = await execFileAsync('git', args, {
|
|
55
|
+
cwd,
|
|
56
|
+
encoding: 'utf-8',
|
|
57
|
+
});
|
|
58
|
+
return stdout.trim();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Determine the git root directory for a given project path.
|
|
62
|
+
*
|
|
63
|
+
* @param projectRoot - Absolute path to start the search from.
|
|
64
|
+
* @returns Absolute path to the git root.
|
|
65
|
+
* @throws Error if not inside a git repository.
|
|
66
|
+
*/
|
|
67
|
+
export function getGitRoot(projectRoot) {
|
|
68
|
+
try {
|
|
69
|
+
return gitSync(['rev-parse', '--show-toplevel'], projectRoot);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
throw new Error(`Not a git repository: ${projectRoot}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolve the current HEAD ref (branch name or SHA) for a git repository.
|
|
77
|
+
*
|
|
78
|
+
* @param gitRoot - Absolute path to the git root.
|
|
79
|
+
* @param fallback - Value to return if HEAD resolution fails.
|
|
80
|
+
* @returns Current HEAD ref string.
|
|
81
|
+
*/
|
|
82
|
+
export function resolveHeadRef(gitRoot, fallback = 'main') {
|
|
83
|
+
try {
|
|
84
|
+
return gitSync(['rev-parse', '--abbrev-ref', 'HEAD'], gitRoot);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return fallback;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=git.js.map
|
package/dist/git.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,IAAc,EAAE,GAAW;IACjD,OAAO,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE;QAC/B,GAAG;QACH,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;KAChC,CAAC,CAAC,IAAI,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,GAAW;IACnD,IAAI,CAAC;QACH,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAc,EAAE,GAAW;IACxD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE;QAClD,GAAG;QACH,QAAQ,EAAE,OAAO;KAClB,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,WAAmB;IAC5C,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,CAAC,WAAW,EAAE,iBAAiB,CAAC,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,yBAAyB,WAAW,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,QAAQ,GAAG,MAAM;IAC/D,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,CAAC,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @cleocode/worktree — Native CLEO worktree backend SDK.
|
|
3
|
+
*
|
|
4
|
+
* Formalizes the scattered worktree logic from:
|
|
5
|
+
* - `packages/cant/src/worktree.ts`
|
|
6
|
+
* - `packages/core/src/spawn/branch-lock.ts`
|
|
7
|
+
* - `packages/core/src/sentient/baseline.ts` (integrated via dispatch)
|
|
8
|
+
* - `packages/core/src/sentient/merge.ts` (integrated via dispatch)
|
|
9
|
+
*
|
|
10
|
+
* Canonical worktree path layout per D029:
|
|
11
|
+
* `~/.local/share/cleo/worktrees/<projectHash>/<taskId>/`
|
|
12
|
+
*
|
|
13
|
+
* Native lift of worktrunk's two missing features (D030):
|
|
14
|
+
* 1. Declarative hooks framework (post-create / post-start)
|
|
15
|
+
* 2. `.cleo/worktree-include` glob pattern support
|
|
16
|
+
*
|
|
17
|
+
* Zero worktrunk dependency — all logic is CLEO-native.
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
* @task T1161
|
|
21
|
+
* @adr ADR-055
|
|
22
|
+
*/
|
|
23
|
+
export type { CreateWorktreeOptions, CreateWorktreeResult, DestroyWorktreeOptions, DestroyWorktreeResult, ListWorktreesOptions, PruneWorktreesOptions, PruneWorktreesResult, WorktreeHook, WorktreeHookResult, WorktreeIncludePattern, WorktreeListEntry, } from '@cleocode/contracts';
|
|
24
|
+
export type { LegacyMergeResult, LegacyWorktreeConfig, LegacyWorktreeEntry, LegacyWorktreeHandle, LegacyWorktreeRequest, } from './compat.js';
|
|
25
|
+
export { legacyCreateWorktree, legacyListWorktrees, legacyMergeWorktree, legacyResolveWorktreeRoot, } from './compat.js';
|
|
26
|
+
export { createWorktree } from './worktree-create.js';
|
|
27
|
+
export { destroyWorktree } from './worktree-destroy.js';
|
|
28
|
+
export { runWorktreeHooks } from './worktree-hooks.js';
|
|
29
|
+
export { applyIncludePatterns, loadWorktreeIncludePatterns } from './worktree-include.js';
|
|
30
|
+
export { listWorktrees, listWorktreesByProjectRoot, resolveWorktreeRoot, } from './worktree-list.js';
|
|
31
|
+
export { pruneWorktrees } from './worktree-prune.js';
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,EACL,aAAa,EACb,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @cleocode/worktree — Native CLEO worktree backend SDK.
|
|
3
|
+
*
|
|
4
|
+
* Formalizes the scattered worktree logic from:
|
|
5
|
+
* - `packages/cant/src/worktree.ts`
|
|
6
|
+
* - `packages/core/src/spawn/branch-lock.ts`
|
|
7
|
+
* - `packages/core/src/sentient/baseline.ts` (integrated via dispatch)
|
|
8
|
+
* - `packages/core/src/sentient/merge.ts` (integrated via dispatch)
|
|
9
|
+
*
|
|
10
|
+
* Canonical worktree path layout per D029:
|
|
11
|
+
* `~/.local/share/cleo/worktrees/<projectHash>/<taskId>/`
|
|
12
|
+
*
|
|
13
|
+
* Native lift of worktrunk's two missing features (D030):
|
|
14
|
+
* 1. Declarative hooks framework (post-create / post-start)
|
|
15
|
+
* 2. `.cleo/worktree-include` glob pattern support
|
|
16
|
+
*
|
|
17
|
+
* Zero worktrunk dependency — all logic is CLEO-native.
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
* @task T1161
|
|
21
|
+
* @adr ADR-055
|
|
22
|
+
*/
|
|
23
|
+
export { legacyCreateWorktree, legacyListWorktrees, legacyMergeWorktree, legacyResolveWorktreeRoot, } from './compat.js';
|
|
24
|
+
export { createWorktree } from './worktree-create.js';
|
|
25
|
+
export { destroyWorktree } from './worktree-destroy.js';
|
|
26
|
+
export { runWorktreeHooks } from './worktree-hooks.js';
|
|
27
|
+
export { applyIncludePatterns, loadWorktreeIncludePatterns } from './worktree-include.js';
|
|
28
|
+
export { listWorktrees, listWorktreesByProjectRoot, resolveWorktreeRoot, } from './worktree-list.js';
|
|
29
|
+
export { pruneWorktrees } from './worktree-prune.js';
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAwBH,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,EACL,aAAa,EACb,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XDG-compliant worktree path resolution for @cleocode/worktree.
|
|
3
|
+
*
|
|
4
|
+
* Canonical layout per D029:
|
|
5
|
+
* Linux: ~/.local/share/cleo/worktrees/<projectHash>/<taskId>/
|
|
6
|
+
* macOS: ~/Library/Application Support/cleo/worktrees/<projectHash>/<taskId>/
|
|
7
|
+
* Windows: %LOCALAPPDATA%\cleo\Data\worktrees\<projectHash>\<taskId>\
|
|
8
|
+
*
|
|
9
|
+
* All path derivation flows through `resolveWorktreeRootForHash` — never
|
|
10
|
+
* hardcode `~/.local/share/cleo`. Use env-paths + `CLEO_HOME` env override
|
|
11
|
+
* matching the convention in `packages/core/src/system/platform-paths.ts`.
|
|
12
|
+
*
|
|
13
|
+
* @task T1161
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Compute a project hash from an absolute project root path.
|
|
17
|
+
*
|
|
18
|
+
* Produces a 16-character hex prefix of SHA-256 to stay consistent with
|
|
19
|
+
* `packages/core/src/spawn/branch-lock.ts#resolveAgentWorktreeRoot`.
|
|
20
|
+
*
|
|
21
|
+
* @param projectRoot - Absolute path to the project root.
|
|
22
|
+
* @returns 16-character lowercase hex string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function computeProjectHash(projectRoot: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the XDG worktrees root directory for a given project hash.
|
|
27
|
+
*
|
|
28
|
+
* Priority order:
|
|
29
|
+
* 1. `worktreeRoot` arg (explicit override — for tests or config)
|
|
30
|
+
* 2. `CLEO_HOME` env var (backward-compat with legacy installations)
|
|
31
|
+
* 3. env-paths XDG data dir (platform-appropriate default)
|
|
32
|
+
*
|
|
33
|
+
* Result: `<dataDir>/worktrees/<projectHash>/`
|
|
34
|
+
*
|
|
35
|
+
* @param projectHash - 16-char project hash from {@link computeProjectHash}.
|
|
36
|
+
* @param worktreeRoot - Optional override for the full worktree root.
|
|
37
|
+
* @returns Absolute path to the project-scoped worktree root directory.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveWorktreeRootForHash(projectHash: string, worktreeRoot?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the worktree directory for a specific task.
|
|
42
|
+
*
|
|
43
|
+
* Result: `<worktreeRoot>/<taskId>/`
|
|
44
|
+
*
|
|
45
|
+
* @param projectHash - 16-char project hash.
|
|
46
|
+
* @param taskId - The task ID.
|
|
47
|
+
* @param worktreeRoot - Optional override for the root directory.
|
|
48
|
+
* @returns Absolute path to the task-specific worktree directory.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveTaskWorktreePath(projectHash: string, taskId: string, worktreeRoot?: string): string;
|
|
51
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAM7F;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAER"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XDG-compliant worktree path resolution for @cleocode/worktree.
|
|
3
|
+
*
|
|
4
|
+
* Canonical layout per D029:
|
|
5
|
+
* Linux: ~/.local/share/cleo/worktrees/<projectHash>/<taskId>/
|
|
6
|
+
* macOS: ~/Library/Application Support/cleo/worktrees/<projectHash>/<taskId>/
|
|
7
|
+
* Windows: %LOCALAPPDATA%\cleo\Data\worktrees\<projectHash>\<taskId>\
|
|
8
|
+
*
|
|
9
|
+
* All path derivation flows through `resolveWorktreeRootForHash` — never
|
|
10
|
+
* hardcode `~/.local/share/cleo`. Use env-paths + `CLEO_HOME` env override
|
|
11
|
+
* matching the convention in `packages/core/src/system/platform-paths.ts`.
|
|
12
|
+
*
|
|
13
|
+
* @task T1161
|
|
14
|
+
*/
|
|
15
|
+
import { createHash } from 'node:crypto';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import envPaths from 'env-paths';
|
|
18
|
+
const APP_NAME = 'cleo';
|
|
19
|
+
/**
|
|
20
|
+
* Compute a project hash from an absolute project root path.
|
|
21
|
+
*
|
|
22
|
+
* Produces a 16-character hex prefix of SHA-256 to stay consistent with
|
|
23
|
+
* `packages/core/src/spawn/branch-lock.ts#resolveAgentWorktreeRoot`.
|
|
24
|
+
*
|
|
25
|
+
* @param projectRoot - Absolute path to the project root.
|
|
26
|
+
* @returns 16-character lowercase hex string.
|
|
27
|
+
*/
|
|
28
|
+
export function computeProjectHash(projectRoot) {
|
|
29
|
+
return createHash('sha256').update(projectRoot).digest('hex').slice(0, 16);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the XDG worktrees root directory for a given project hash.
|
|
33
|
+
*
|
|
34
|
+
* Priority order:
|
|
35
|
+
* 1. `worktreeRoot` arg (explicit override — for tests or config)
|
|
36
|
+
* 2. `CLEO_HOME` env var (backward-compat with legacy installations)
|
|
37
|
+
* 3. env-paths XDG data dir (platform-appropriate default)
|
|
38
|
+
*
|
|
39
|
+
* Result: `<dataDir>/worktrees/<projectHash>/`
|
|
40
|
+
*
|
|
41
|
+
* @param projectHash - 16-char project hash from {@link computeProjectHash}.
|
|
42
|
+
* @param worktreeRoot - Optional override for the full worktree root.
|
|
43
|
+
* @returns Absolute path to the project-scoped worktree root directory.
|
|
44
|
+
*/
|
|
45
|
+
export function resolveWorktreeRootForHash(projectHash, worktreeRoot) {
|
|
46
|
+
if (worktreeRoot)
|
|
47
|
+
return worktreeRoot;
|
|
48
|
+
const ep = envPaths(APP_NAME, { suffix: '' });
|
|
49
|
+
// CLEO_HOME overrides the data path for backward compatibility.
|
|
50
|
+
const dataDir = process.env['CLEO_HOME'] ?? ep.data;
|
|
51
|
+
return join(dataDir, 'worktrees', projectHash);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolve the worktree directory for a specific task.
|
|
55
|
+
*
|
|
56
|
+
* Result: `<worktreeRoot>/<taskId>/`
|
|
57
|
+
*
|
|
58
|
+
* @param projectHash - 16-char project hash.
|
|
59
|
+
* @param taskId - The task ID.
|
|
60
|
+
* @param worktreeRoot - Optional override for the root directory.
|
|
61
|
+
* @returns Absolute path to the task-specific worktree directory.
|
|
62
|
+
*/
|
|
63
|
+
export function resolveTaskWorktreePath(projectHash, taskId, worktreeRoot) {
|
|
64
|
+
return join(resolveWorktreeRootForHash(projectHash, worktreeRoot), taskId);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAExB;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB;IACpD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,0BAA0B,CAAC,WAAmB,EAAE,YAAqB;IACnF,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC;IACtC,MAAM,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9C,gEAAgE;IAChE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC;IACpD,OAAO,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CACrC,WAAmB,EACnB,MAAc,EACd,YAAqB;IAErB,OAAO,IAAI,CAAC,0BAA0B,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,CAAC;AAC7E,CAAC"}
|