@cleocode/core 2026.11.1-canary.9 → 2026.11.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.
Files changed (128) hide show
  1. package/dist/.source-stamp.json +1 -1
  2. package/dist/build-provenance.json +2 -2
  3. package/dist/config.js +2 -0
  4. package/dist/config.js.map +1 -1
  5. package/dist/doctor/db-substrate.js +14 -6
  6. package/dist/doctor/db-substrate.js.map +1 -1
  7. package/dist/doctor/migrations.d.ts +16 -0
  8. package/dist/doctor/migrations.js +85 -1
  9. package/dist/doctor/migrations.js.map +1 -1
  10. package/dist/doctor/system-health.d.ts +77 -1
  11. package/dist/doctor/system-health.js +145 -0
  12. package/dist/doctor/system-health.js.map +1 -1
  13. package/dist/errors-to-engine.d.ts +8 -4
  14. package/dist/errors-to-engine.js +9 -5
  15. package/dist/errors-to-engine.js.map +1 -1
  16. package/dist/errors.d.ts +14 -0
  17. package/dist/errors.js +10 -0
  18. package/dist/errors.js.map +1 -1
  19. package/dist/git/work-tree.js +1 -1
  20. package/dist/git/work-tree.js.map +1 -1
  21. package/dist/hygiene/census.d.ts +181 -12
  22. package/dist/hygiene/census.js +564 -86
  23. package/dist/hygiene/census.js.map +1 -1
  24. package/dist/hygiene/prune-plan-worker.d.ts +17 -0
  25. package/dist/hygiene/prune-plan-worker.js +42 -0
  26. package/dist/hygiene/prune-plan-worker.js.map +1 -0
  27. package/dist/hygiene/task-status.d.ts +20 -0
  28. package/dist/hygiene/task-status.js +71 -0
  29. package/dist/hygiene/task-status.js.map +1 -0
  30. package/dist/memory/pipeline-manifest-sqlite.d.ts +2 -1
  31. package/dist/memory/pipeline-manifest-sqlite.js +3 -2
  32. package/dist/memory/pipeline-manifest-sqlite.js.map +1 -1
  33. package/dist/orchestrate/agentmbx.d.ts +5 -2
  34. package/dist/orchestrate/agentmbx.js +7 -4
  35. package/dist/orchestrate/agentmbx.js.map +1 -1
  36. package/dist/orchestrate/dispatch-workers.d.ts +10 -3
  37. package/dist/orchestrate/dispatch-workers.js +26 -14
  38. package/dist/orchestrate/dispatch-workers.js.map +1 -1
  39. package/dist/orchestrate/lead.d.ts +3 -0
  40. package/dist/orchestrate/lead.js +1 -0
  41. package/dist/orchestrate/lead.js.map +1 -1
  42. package/dist/orchestrate/orca-execution.d.ts +151 -0
  43. package/dist/orchestrate/orca-execution.js +571 -0
  44. package/dist/orchestrate/orca-execution.js.map +1 -0
  45. package/dist/orchestrate/orca-routing.d.ts +13 -0
  46. package/dist/orchestrate/orca-routing.js +142 -0
  47. package/dist/orchestrate/orca-routing.js.map +1 -0
  48. package/dist/orchestrate/spawn-ops.d.ts +50 -20
  49. package/dist/orchestrate/spawn-ops.js +332 -86
  50. package/dist/orchestrate/spawn-ops.js.map +1 -1
  51. package/dist/orchestrate/worker-records.d.ts +97 -5
  52. package/dist/orchestrate/worker-records.js +503 -11
  53. package/dist/orchestrate/worker-records.js.map +1 -1
  54. package/dist/orchestrate/worker-report.js +1 -0
  55. package/dist/orchestrate/worker-report.js.map +1 -1
  56. package/dist/orchestration/index.d.ts +8 -2
  57. package/dist/orchestration/index.js +70 -17
  58. package/dist/orchestration/index.js.map +1 -1
  59. package/dist/orchestration/spawn-prompt.d.ts +9 -2
  60. package/dist/orchestration/spawn-prompt.js +47 -18
  61. package/dist/orchestration/spawn-prompt.js.map +1 -1
  62. package/dist/orchestration/spawn.d.ts +20 -6
  63. package/dist/orchestration/spawn.js +14 -6
  64. package/dist/orchestration/spawn.js.map +1 -1
  65. package/dist/release/ci-evidence.d.ts +55 -2
  66. package/dist/release/ci-evidence.js +161 -51
  67. package/dist/release/ci-evidence.js.map +1 -1
  68. package/dist/resources/admission-ledger.d.ts +6 -0
  69. package/dist/resources/admission-ledger.js +100 -10
  70. package/dist/resources/admission-ledger.js.map +1 -1
  71. package/dist/resources/agent-lease.d.ts +7 -0
  72. package/dist/resources/agent-lease.js +37 -4
  73. package/dist/resources/agent-lease.js.map +1 -1
  74. package/dist/resources/hook-footprint.d.ts +22 -0
  75. package/dist/resources/hook-footprint.js +49 -2
  76. package/dist/resources/hook-footprint.js.map +1 -1
  77. package/dist/resources/run-class.d.ts +9 -1
  78. package/dist/resources/run-class.js +87 -6
  79. package/dist/resources/run-class.js.map +1 -1
  80. package/dist/spawn/adapter-registry.js +5 -0
  81. package/dist/spawn/adapter-registry.js.map +1 -1
  82. package/dist/spawn/branch-integration.d.ts +4 -0
  83. package/dist/spawn/branch-integration.js +10 -1
  84. package/dist/spawn/branch-integration.js.map +1 -1
  85. package/dist/store/open-cleo-db.d.ts +17 -0
  86. package/dist/store/open-cleo-db.js +39 -0
  87. package/dist/store/open-cleo-db.js.map +1 -1
  88. package/dist/store/restore-marker.js +4 -0
  89. package/dist/store/restore-marker.js.map +1 -1
  90. package/dist/store/sqlite.d.ts +21 -0
  91. package/dist/store/sqlite.js +33 -0
  92. package/dist/store/sqlite.js.map +1 -1
  93. package/dist/store/worktree-build-guard.js +3 -0
  94. package/dist/store/worktree-build-guard.js.map +1 -1
  95. package/dist/tasks/add.js +8 -0
  96. package/dist/tasks/add.js.map +1 -1
  97. package/dist/tasks/complete.d.ts +7 -3
  98. package/dist/tasks/complete.js +5 -0
  99. package/dist/tasks/complete.js.map +1 -1
  100. package/dist/tasks/engine-wrap.d.ts +3 -1
  101. package/dist/tasks/engine-wrap.js +6 -18
  102. package/dist/tasks/engine-wrap.js.map +1 -1
  103. package/dist/tasks/merge-close.d.ts +5 -3
  104. package/dist/tasks/merge-close.js +30 -10
  105. package/dist/tasks/merge-close.js.map +1 -1
  106. package/dist/tasks/pipeline-stage.d.ts +7 -1
  107. package/dist/tasks/pipeline-stage.js +44 -0
  108. package/dist/tasks/pipeline-stage.js.map +1 -1
  109. package/dist/tasks/update.js +8 -0
  110. package/dist/tasks/update.js.map +1 -1
  111. package/dist/upgrade.d.ts +4 -0
  112. package/dist/upgrade.js +32 -0
  113. package/dist/upgrade.js.map +1 -1
  114. package/dist/worktree/in-use-probe.d.ts +19 -0
  115. package/dist/worktree/in-use-probe.js +87 -0
  116. package/dist/worktree/in-use-probe.js.map +1 -1
  117. package/dist/worktree/list.d.ts +6 -6
  118. package/dist/worktree/list.js +42 -30
  119. package/dist/worktree/list.js.map +1 -1
  120. package/dist/worktree/own-project.d.ts +32 -0
  121. package/dist/worktree/own-project.js +68 -0
  122. package/dist/worktree/own-project.js.map +1 -0
  123. package/dist/worktree/prune.d.ts +11 -1
  124. package/dist/worktree/prune.js +83 -2
  125. package/dist/worktree/prune.js.map +1 -1
  126. package/package.json +12 -12
  127. package/templates/CLEO-INJECTION.md +1 -1
  128. package/templates/CLEO-REFERENCE.md +2 -2
@@ -7,7 +7,8 @@
7
7
  * deleted ones, scratch clones) were never swept: 484 had accumulated. The
8
8
  * CI cleanup workflow ran where no worktree exists and swallowed every error.
9
9
  *
10
- * The census walks every project hash directory under the root:
10
+ * The census walks every project hash directory and every registered project's
11
+ * git worktree registry (including unadopted external worktrees):
11
12
  *
12
13
  * - a directory whose hash matches a registered project (the nexus registry)
13
14
  * is classified by that project's {@link listWorktrees}: the disposal proof
@@ -16,22 +17,31 @@
16
17
  * - a directory no registered project owns, and any directory git does not
17
18
  * list as a worktree, is reported `unknown`, report only.
18
19
  *
19
- * `--apply` removes only `redundant` worktrees of the projects it is allowed
20
- * to act on (by default the project it runs in; other projects stay report
21
- * only until the owner's plan question C is answered), each re-proved by
20
+ * The CLI reports by default. `--apply` removes only `redundant` terminal
21
+ * worktrees of the current project; foreign projects remain report-only;
22
+ * automatic completion and scheduled cleanup opt in explicitly, each re-proved by
22
23
  * `disposeWorktree` with the task's evidence. Every run writes one census
23
24
  * record (counts, apparent bytes, bytes reclaimed, the free-space delta and
24
25
  * every kept worktree with its reason) under `<cleoHome>/hygiene/census/`.
25
26
  *
26
27
  * One census runs at a time per machine (a heartbeat lock), and the lazy spawn
27
- * claims at most one run per 24 h; it never starts in CI, under vitest, or in
28
+ * claims at most one run per project per 24 h; it never starts in CI, under vitest, or in
28
29
  * a process git started (T14189).
29
30
  *
31
+ * Every row also carries the visibility fields the machine-hygiene epic needs
32
+ * (T14440): the owning task's status, last activity and creation time, git and
33
+ * task locks, the dirty-entry count, and the `node_modules` kind and size.
34
+ * Per project the record rolls up worktree counts, bytes and merged local and
35
+ * remote branches, and names why each project's store was or was not read;
36
+ * machine-wide it names the orphan hash directories and the global pnpm
37
+ * store's size.
38
+ *
30
39
  * @task T14275
40
+ * @task T14440
31
41
  */
32
42
  import { type SpawnOptions } from 'node:child_process';
33
43
  import type { WorktreeStatusCategory } from '@cleocode/contracts';
34
- /** The lazy census runs at most this often per machine. */
44
+ /** The lazy census runs at most this often per project. */
35
45
  export declare const CENSUS_INTERVAL_MS: number;
36
46
  /** One worktree directory the census found. */
37
47
  export interface CensusRow {
@@ -49,13 +59,77 @@ export interface CensusRow {
49
59
  keepReason?: string;
50
60
  /** Apparent size (the sum of file sizes, as `du --apparent-size`), in bytes. */
51
61
  apparentBytes: number;
62
+ /** The branch is retained after removal. */
63
+ branch?: string;
64
+ /** Last recorded activity, used to order eligible worktrees oldest first. */
65
+ lastActivity?: string;
66
+ /** Task state at discovery; only done and cancelled tasks are removal candidates. */
67
+ taskStatus?: string | null;
68
+ /** ISO creation time (git admin file, adopt sentinel or dir mtime); `null` when unknown (T14440). */
69
+ createdAt: string | null;
70
+ /** `git worktree list --porcelain` lock state (T14440). */
71
+ gitLocked: boolean;
72
+ /** A CLEO task lock is held on this worktree's task (T14440). */
73
+ taskLocked: boolean;
74
+ /** Changed + untracked entries from `git status --porcelain`; `null` when git failed or time ran out (T14440). */
75
+ dirtyFiles: number | null;
76
+ /** The worktree's `node_modules`: `absent`, a `symlink`, or a `real` directory (T14440). */
77
+ nodeModules: 'absent' | 'symlink' | 'real';
78
+ /** Apparent bytes of a `real` `node_modules` (symlinks count as 0); 0 otherwise (T14440). */
79
+ nodeModulesBytes: number;
80
+ /** Selected by the TTL and retained-size budget, including in a dry run. */
81
+ selected?: boolean;
52
82
  /** Set when `--apply` removed it. */
53
83
  removed?: boolean;
54
84
  }
85
+ /**
86
+ * Per-project rollup of one census run (T14440).
87
+ */
88
+ export interface ProjectCensusRollup {
89
+ /** Registered project root, or `null` when the hash dir matches no registered project. */
90
+ project: string | null;
91
+ /** The hash directory. */
92
+ projectHash: string;
93
+ /** Worktrees found under it. */
94
+ worktrees: number;
95
+ /** Their apparent bytes. */
96
+ apparentBytes: number;
97
+ /**
98
+ * Local branches the SDK integration probe classifies as merged into the
99
+ * integration target (primary checkout and the target itself excluded);
100
+ * `null` when the probe failed (T14440).
101
+ */
102
+ mergedLocalBranches: number | null;
103
+ /** Remote branches merged into the target (HEAD refs excluded); `null` when git failed (T14440). */
104
+ mergedRemoteBranches: number | null;
105
+ /** True when no registered project owns this hash directory. */
106
+ orphan: boolean;
107
+ /**
108
+ * The foreign-store verdict behind this rollup's task statuses: `read` when
109
+ * the store was opened, otherwise why it was skipped (T14440 AC3).
110
+ */
111
+ storeRead: string;
112
+ }
113
+ /** A worktrees-home hash directory that matches no registered project (T14440). */
114
+ export interface OrphanHashDir {
115
+ /** The directory name under the worktrees home. */
116
+ projectHash: string;
117
+ /** Worktree-like directories found under it. */
118
+ worktrees: number;
119
+ /** Their apparent bytes. */
120
+ apparentBytes: number;
121
+ }
122
+ /** The global pnpm content-addressable store and its size (T14440). */
123
+ export interface PnpmStoreCensus {
124
+ /** The store directory (`pnpm store path`). */
125
+ path: string;
126
+ /** Apparent bytes of the store. */
127
+ apparentBytes: number;
128
+ }
55
129
  /** The record one census run writes. */
56
130
  export interface CensusRecord {
57
131
  /** Record format version. */
58
- schemaVersion: 1;
132
+ schemaVersion: 2;
59
133
  /** `report` reads only; `apply` removed proven-redundant worktrees. */
60
134
  mode: 'report' | 'apply';
61
135
  /** ISO time the run started. */
@@ -86,6 +160,21 @@ export interface CensusRecord {
86
160
  rows: CensusRow[];
87
161
  /** True when the wall-clock budget ran out: rows and bytes are a lower bound. */
88
162
  partial: boolean;
163
+ /** Minimum idle age of eligible worktrees, in days. */
164
+ ttlDays?: number;
165
+ /** Target retained apparent bytes; safety and TTL may prevent reaching it. */
166
+ maxBytes?: number;
167
+ /** Registered projects that could not be assessed; never eligible for removal. */
168
+ projectErrors?: Array<{
169
+ project: string;
170
+ error: string;
171
+ }>;
172
+ /** Per-project rollup: worktree count, bytes, merged branches, store verdict (T14440). */
173
+ projects: ProjectCensusRollup[];
174
+ /** Hash directories under the machine root that no registered project owns (T14440). */
175
+ orphanFolders: OrphanHashDir[];
176
+ /** The global pnpm store and its apparent size, when it could be resolved (T14440). */
177
+ pnpmStore: PnpmStoreCensus | null;
89
178
  }
90
179
  /** Options of {@link runWorktreeCensus}. */
91
180
  export interface WorktreeCensusOptions {
@@ -93,6 +182,14 @@ export interface WorktreeCensusOptions {
93
182
  apply?: boolean;
94
183
  /** Projects `apply` may act on (default: none; the CLI passes the current project). */
95
184
  applyProjects?: readonly string[];
185
+ /** Report every registered project; foreign projects remain ineligible for removal. */
186
+ allProjects?: boolean;
187
+ /** Minimum idle age in days (default: zero); a budget never overrides it. */
188
+ ttlDays?: number;
189
+ /** Stop removing once retained apparent bytes reach this budget (default: zero). */
190
+ maxBytes?: number;
191
+ /** Explicitly allow merged ignored build output to be regenerated; never force-archive. */
192
+ exemptRegenerable?: boolean;
96
193
  /** Registered project roots (default: read from the nexus registry). */
97
194
  projects?: readonly string[];
98
195
  /** Where the record is written (default: `<cleoHome>/hygiene/census`). */
@@ -101,6 +198,19 @@ export interface WorktreeCensusOptions {
101
198
  machineRoot?: string;
102
199
  /** Wall-clock deadline (ms epoch): past it the walk stops and the record is `partial`. */
103
200
  deadline?: number;
201
+ /**
202
+ * The global pnpm store census to embed. `undefined` resolves and sizes the
203
+ * real store (`pnpm store path`); `null` records none; tests stub a value.
204
+ */
205
+ pnpmStore?: PnpmStoreCensus | null;
206
+ /**
207
+ * Merged-branch counter override (tests). Default: {@link mergedBranchCounts}
208
+ * with the walk deadline and the worker-bounded SDK probe.
209
+ */
210
+ branchesOf?: (projectRoot: string) => Promise<{
211
+ mergedLocal: number | null;
212
+ mergedRemote: number | null;
213
+ }>;
104
214
  }
105
215
  /**
106
216
  * Apparent size of a tree: the sum of `lstat` sizes, symlinks never followed;
@@ -111,12 +221,13 @@ export declare function apparentBytes(path: string, deadline?: number): number;
111
221
  * Registered project roots from the nexus registry; `[]` when it cannot be read.
112
222
  *
113
223
  * @param load - The registry listing (default: `nexusList`; tests stub it).
224
+ * @param onError - Capture missing registry coverage in the census receipt.
114
225
  * @returns Each registered project's path.
115
226
  * @internal Exported for tests.
116
227
  */
117
228
  export declare function registeredProjects(load?: () => Promise<ReadonlyArray<{
118
229
  path: string;
119
- }>>): Promise<string[]>;
230
+ }>>, onError?: (message: string) => void): Promise<string[]>;
120
231
  /**
121
232
  * Run the census once, under the machine's census lock.
122
233
  *
@@ -130,6 +241,60 @@ export declare function runWorktreeCensus(opts?: WorktreeCensusOptions): Promise
130
241
  } | {
131
242
  skipped: string;
132
243
  }>;
244
+ /** The plan shape the worker returns (a subset of the SDK prune plan). */
245
+ export interface BoundedPrunePlan {
246
+ candidates: Array<{
247
+ kind: string;
248
+ branch?: string | undefined;
249
+ }>;
250
+ }
251
+ /**
252
+ * The SDK integration probe, run in a Worker built from a REAL module file
253
+ * (never eval — an eval worker inherits the parent's `--input-type=module`
254
+ * and cannot bootstrap) that the shared deadline TERMINATES (T14440, round 5).
255
+ * The napi `pruneWorktrees` walk over a large repository is synchronous and
256
+ * uninterruptible in-process, so it runs off-thread and a deadline overrun
257
+ * kills it before the census releases its lock. Any failure yields `null` —
258
+ * a failed probe is never a zero.
259
+ *
260
+ * @param repoRoot - The repository root to probe.
261
+ * @param integrationTarget - The branch "merged" is tested against.
262
+ * @param deadline - Wall-clock ms epoch; past it the worker is terminated.
263
+ * @returns The prune plan, or `null`.
264
+ */
265
+ export declare function prunePlanBounded(repoRoot: string, integrationTarget: string, deadline: number,
266
+ /** Test hook: the worker writes this file markerDelayMs after the walk. */
267
+ markerPath?: string,
268
+ /** Test hook: the marker delay (ms) after the walk completes. */
269
+ markerDelayMs?: number,
270
+ /** Test hook: invoked when the worker has fully exited (round 7, item 5). */
271
+ onWorkerExit?: () => void): Promise<BoundedPrunePlan | null>;
272
+ /**
273
+ * Merged-branch counts for one project: local via the worker-bounded SDK
274
+ * integration probe (primary checkout and target excluded), remote via
275
+ * `git for-each-ref --merged` with HEAD refs excluded, all under the shared
276
+ * walk deadline. `null` per side when its probe fails or the deadline ends -
277
+ * a failed probe is never a zero (T14440).
278
+ *
279
+ * @param projectRoot - The registered project's repository root.
280
+ * @param deadline - Wall-clock ms epoch past which probes stop.
281
+ * @param planOf - The SDK probe (tests stub it; default {@link prunePlanBounded}).
282
+ * @returns Merged local and remote branch counts.
283
+ */
284
+ export declare function mergedBranchCounts(projectRoot: string, deadline?: number, planOf?: (repoRoot: string, integrationTarget: string, deadline: number) => Promise<BoundedPrunePlan | null>): Promise<{
285
+ mergedLocal: number | null;
286
+ mergedRemote: number | null;
287
+ }>;
288
+ /**
289
+ * The global pnpm content-addressable store and its apparent size (T14440).
290
+ * `pnpm store path` resolves the location from the home dir (an inherited
291
+ * per-worktree cwd would honour that worktree's `.npmrc` store-dir); any
292
+ * failure yields `null`, never a zero-sized store.
293
+ *
294
+ * @param deadline - Past it, `null`.
295
+ * @returns The store census, or `null`.
296
+ */
297
+ export declare function pnpmStoreCensus(deadline?: number): PnpmStoreCensus | null;
133
298
  /** The lazy census child's wall-clock budget: past it, a partial record and exit. */
134
299
  export declare const LAZY_CENSUS_BUDGET_MS: number;
135
300
  /**
@@ -158,6 +323,8 @@ export declare function startLazyCensus(env: NodeJS.ProcessEnv, deps?: {
158
323
  };
159
324
  dir?: string;
160
325
  now?: number;
326
+ /** Canonical project root: each project has its own daily claim. */
327
+ projectRoot?: string;
161
328
  }): string | null;
162
329
  /**
163
330
  * The lazy census child's body (T14275): background CPU priority, a
@@ -166,9 +333,10 @@ export declare function startLazyCensus(env: NodeJS.ProcessEnv, deps?: {
166
333
  * process alive. The lock is released on every exit path.
167
334
  *
168
335
  * @param dir - The census directory.
336
+ * @param projectRoot - The project captured by the scheduling caller.
169
337
  * @task T14275
170
338
  */
171
- export declare function runLazyCensus(dir?: string): Promise<void>;
339
+ export declare function runLazyCensus(dir?: string, projectRoot?: string): Promise<void>;
172
340
  /**
173
341
  * Whether a read command may start the lazy census: never in CI, under vitest,
174
342
  * or in a process git started (T14189: a hook carries GIT_EXEC_PATH,
@@ -180,15 +348,16 @@ export declare function runLazyCensus(dir?: string): Promise<void>;
180
348
  */
181
349
  export declare function censusSpawnAllowed(env: NodeJS.ProcessEnv): boolean;
182
350
  /**
183
- * Claim today's lazy census, atomically: true for exactly one caller per
184
- * {@link CENSUS_INTERVAL_MS} on this machine.
351
+ * Claim today's lazy census, atomically: one caller per project per interval,
352
+ * or one machine-wide report when no project is supplied.
185
353
  *
186
354
  * @param now - Current time (ms).
187
355
  * @param dir - The census directory (tests).
356
+ * @param projectRoot - The canonical project root whose daily run is claimed.
188
357
  * @returns True when this caller should start the census.
189
358
  * @task T14275
190
359
  */
191
- export declare function claimCensus(now?: number, dir?: string): boolean;
360
+ export declare function claimCensus(now?: number, dir?: string, projectRoot?: string): boolean;
192
361
  /**
193
362
  * The newest census record, or `null` when none was written.
194
363
  *