@cleocode/worktree 2026.5.25 → 2026.5.27

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/paths.d.ts CHANGED
@@ -1,51 +1,18 @@
1
1
  /**
2
- * XDG-compliant worktree path resolution for @cleocode/worktree.
2
+ * Worktree path resolution for `@cleocode/worktree`.
3
+ *
4
+ * Re-exports the worktree primitives from `@cleocode/paths` (the XDG / env-paths
5
+ * SSoT) — `computeProjectHash`, `resolveWorktreeRootForHash`, and
6
+ * `resolveTaskWorktreePath`. Public API of this file is unchanged; the
7
+ * implementation now lives in the shared package.
3
8
  *
4
9
  * Canonical layout per D029:
5
10
  * Linux: ~/.local/share/cleo/worktrees/<projectHash>/<taskId>/
6
11
  * macOS: ~/Library/Application Support/cleo/worktrees/<projectHash>/<taskId>/
7
12
  * Windows: %LOCALAPPDATA%\cleo\Data\worktrees\<projectHash>\<taskId>\
8
13
  *
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.
14
+ * @task T1161 (original)
15
+ * @task T1885 (migrated to @cleocode/paths SSoT)
49
16
  */
50
- export declare function resolveTaskWorktreePath(projectHash: string, taskId: string, worktreeRoot?: string): string;
17
+ export { computeProjectHash, resolveTaskWorktreePath, resolveWorktreeRootForHash, } from '@cleocode/paths';
51
18
  //# sourceMappingURL=paths.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC"}
package/dist/paths.js CHANGED
@@ -1,66 +1,18 @@
1
1
  /**
2
- * XDG-compliant worktree path resolution for @cleocode/worktree.
2
+ * Worktree path resolution for `@cleocode/worktree`.
3
+ *
4
+ * Re-exports the worktree primitives from `@cleocode/paths` (the XDG / env-paths
5
+ * SSoT) — `computeProjectHash`, `resolveWorktreeRootForHash`, and
6
+ * `resolveTaskWorktreePath`. Public API of this file is unchanged; the
7
+ * implementation now lives in the shared package.
3
8
  *
4
9
  * Canonical layout per D029:
5
10
  * Linux: ~/.local/share/cleo/worktrees/<projectHash>/<taskId>/
6
11
  * macOS: ~/Library/Application Support/cleo/worktrees/<projectHash>/<taskId>/
7
12
  * Windows: %LOCALAPPDATA%\cleo\Data\worktrees\<projectHash>\<taskId>\
8
13
  *
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.
14
+ * @task T1161 (original)
15
+ * @task T1885 (migrated to @cleocode/paths SSoT)
62
16
  */
63
- export function resolveTaskWorktreePath(projectHash, taskId, worktreeRoot) {
64
- return join(resolveWorktreeRootForHash(projectHash, worktreeRoot), taskId);
65
- }
17
+ export { computeProjectHash, resolveTaskWorktreePath, resolveWorktreeRootForHash, } from '@cleocode/paths';
66
18
  //# sourceMappingURL=paths.js.map
package/dist/paths.js.map CHANGED
@@ -1 +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"}
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC"}
@@ -19,18 +19,27 @@ import type { CreateWorktreeOptions, CreateWorktreeResult } from '@cleocode/cont
19
19
  * Steps:
20
20
  * 1. Resolve paths and project hash from the project root.
21
21
  * 2. Remove stale worktree at the same path if it exists.
22
- * 3. Run `git worktree add <path> -b <branch> <baseRef>`.
22
+ * 3. If `task/<taskId>` branch already exists (leftover from a prior aborted
23
+ * spawn), attach to it via `git worktree add <path> <branch>` (no `-b`).
24
+ * Otherwise create a new branch via `git worktree add -b <branch> <path> <baseRef>`.
23
25
  * 4. Optionally apply `git worktree lock` to prevent pruning.
24
26
  * 5. Run declarative `post-create` hooks.
25
27
  * 6. Apply `.cleo/worktree-include` glob patterns (symlinks).
26
28
  * 7. Build and return the {@link CreateWorktreeResult}.
27
29
  *
30
+ * Branch-reuse semantics: when a prior spawn aborted after creating the branch
31
+ * but before the worker committed anything, the branch still points to
32
+ * `baseRef`. Reattaching is safe — the worker continues from a clean state.
33
+ * The returned result includes {@link CreateWorktreeResult.reused} so callers
34
+ * can distinguish between a fresh branch and a reattached one if needed.
35
+ *
28
36
  * @param projectRoot - Absolute path to the project root directory.
29
37
  * @param options - Options controlling the worktree creation.
30
38
  * @returns The created worktree result with env vars and preamble.
31
39
  * @throws Error if git worktree add fails.
32
40
  *
33
41
  * @task T1161
42
+ * @task T1878
34
43
  */
35
44
  export declare function createWorktree(projectRoot: string, options: CreateWorktreeOptions): Promise<CreateWorktreeResult>;
36
45
  //# sourceMappingURL=worktree-create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worktree-create.d.ts","sourceRoot":"","sources":["../src/worktree-create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAUvF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAkG/B"}
1
+ {"version":3,"file":"worktree-create.d.ts","sourceRoot":"","sources":["../src/worktree-create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAUvF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAsH/B"}
@@ -24,18 +24,27 @@ import { applyIncludePatterns, loadWorktreeIncludePatterns } from './worktree-in
24
24
  * Steps:
25
25
  * 1. Resolve paths and project hash from the project root.
26
26
  * 2. Remove stale worktree at the same path if it exists.
27
- * 3. Run `git worktree add <path> -b <branch> <baseRef>`.
27
+ * 3. If `task/<taskId>` branch already exists (leftover from a prior aborted
28
+ * spawn), attach to it via `git worktree add <path> <branch>` (no `-b`).
29
+ * Otherwise create a new branch via `git worktree add -b <branch> <path> <baseRef>`.
28
30
  * 4. Optionally apply `git worktree lock` to prevent pruning.
29
31
  * 5. Run declarative `post-create` hooks.
30
32
  * 6. Apply `.cleo/worktree-include` glob patterns (symlinks).
31
33
  * 7. Build and return the {@link CreateWorktreeResult}.
32
34
  *
35
+ * Branch-reuse semantics: when a prior spawn aborted after creating the branch
36
+ * but before the worker committed anything, the branch still points to
37
+ * `baseRef`. Reattaching is safe — the worker continues from a clean state.
38
+ * The returned result includes {@link CreateWorktreeResult.reused} so callers
39
+ * can distinguish between a fresh branch and a reattached one if needed.
40
+ *
33
41
  * @param projectRoot - Absolute path to the project root directory.
34
42
  * @param options - Options controlling the worktree creation.
35
43
  * @returns The created worktree result with env vars and preamble.
36
44
  * @throws Error if git worktree add fails.
37
45
  *
38
46
  * @task T1161
47
+ * @task T1878
39
48
  */
40
49
  export async function createWorktree(projectRoot, options) {
41
50
  const { taskId, hooks = [], lockWorktree = true } = options;
@@ -53,11 +62,30 @@ export async function createWorktree(projectRoot, options) {
53
62
  if (!gitSilent(['worktree', 'remove', '--force', worktreePath], gitRoot)) {
54
63
  rmSync(worktreePath, { recursive: true, force: true });
55
64
  }
56
- // Best-effort: delete the stale branch.
65
+ // Best-effort: delete the stale branch so we always start fresh when the
66
+ // directory existed (the branch-reuse path below handles the case where
67
+ // only the branch survives without a directory).
57
68
  gitSilent(['branch', '-D', branch], gitRoot);
58
69
  }
59
- // Create the worktree with a new branch.
60
- gitSync(['worktree', 'add', worktreePath, '-b', branch, baseRef], gitRoot);
70
+ // Check whether the branch already exists without a worktree directory.
71
+ // This happens when a prior spawn created the branch but the worktree
72
+ // directory was cleaned up (e.g. aborted after `git worktree add` but
73
+ // before the agent ran). Attaching to the existing branch avoids the
74
+ // "branch already exists" error from `git worktree add -b`.
75
+ // `git branch --list <branch>` exits 0 regardless; non-empty output means
76
+ // the branch exists.
77
+ const branchExists = gitSync(['branch', '--list', branch], gitRoot).trim() !== '';
78
+ let reused;
79
+ if (branchExists) {
80
+ // Attach to the existing branch — no -b flag.
81
+ gitSync(['worktree', 'add', worktreePath, branch], gitRoot);
82
+ reused = true;
83
+ }
84
+ else {
85
+ // Create the worktree with a new branch.
86
+ gitSync(['worktree', 'add', '-b', branch, worktreePath, baseRef], gitRoot);
87
+ reused = false;
88
+ }
61
89
  // Apply git worktree lock to prevent accidental pruning.
62
90
  let locked = false;
63
91
  if (lockWorktree) {
@@ -118,6 +146,7 @@ export async function createWorktree(projectRoot, options) {
118
146
  projectHash,
119
147
  createdAt,
120
148
  locked,
149
+ reused,
121
150
  envVars,
122
151
  preamble,
123
152
  hookResults,
@@ -1 +1 @@
1
- {"version":3,"file":"worktree-create.js","sourceRoot":"","sources":["../src/worktree-create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAE1F;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,WAAmB,EACnB,OAA8B;IAE9B,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,YAAY,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAC5D,MAAM,YAAY,GAAG,OAAO,CAAC,oBAAoB,KAAK,KAAK,CAAC;IAE5D,MAAM,OAAO,G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wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,iBAAiB,EAAE,CA2CrF;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAGnF"}
1
+ {"version":3,"file":"worktree-list.d.ts","sourceRoot":"","sources":["../src/worktree-list.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAOnF;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtF;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,iBAAiB,EAAE,CAyCrF;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAGnF"}
@@ -9,9 +9,7 @@
9
9
  import { execFileSync } from 'node:child_process';
10
10
  import { existsSync, readdirSync } from 'node:fs';
11
11
  import { join } from 'node:path';
12
- import envPaths from 'env-paths';
13
- import { computeProjectHash, resolveWorktreeRootForHash } from './paths.js';
14
- const APP_NAME = 'cleo';
12
+ import { computeProjectHash, getCleoWorktreesRoot, resolveWorktreeRootForHash, } from '@cleocode/paths';
15
13
  /**
16
14
  * Resolve the worktree root directory for a given project hash.
17
15
  *
@@ -34,9 +32,7 @@ export function resolveWorktreeRoot(projectHash, worktreeRoot) {
34
32
  * @returns Array of worktree entries.
35
33
  */
36
34
  export function listWorktrees(options = {}) {
37
- const ep = envPaths(APP_NAME, { suffix: '' });
38
- const dataDir = process.env['CLEO_HOME'] ?? ep.data;
39
- const worktreesBase = join(dataDir, 'worktrees');
35
+ const worktreesBase = getCleoWorktreesRoot();
40
36
  if (!existsSync(worktreesBase))
41
37
  return [];
42
38
  const entries = [];
@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AAE,CAAC;YAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC3C,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;gBAAE,SAAS;YAExC,MAAM,MAAM,GAAG,qBAAqB,CAAC,YAAY,CAAC,IAAI,QAAQ,MAAM,EAAE,CAAC;YACvE,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;AAED;;;;;;;;GAQG;AACH,SAAS,qBAAqB,CAAC,YAAoB;IACjD,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE;YACpF,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;SAChC,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleocode/worktree",
3
- "version": "2026.5.25",
3
+ "version": "2026.5.27",
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,8 +30,8 @@
30
30
  "author": "CLEO Code <hello@cleocode.dev>",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "env-paths": "^4.0.0",
34
- "@cleocode/contracts": "2026.5.25"
33
+ "@cleocode/contracts": "2026.5.27",
34
+ "@cleocode/paths": "2026.5.27"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^24.3.0",