@cleocode/core 2026.10.8 → 2026.10.9

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 (266) hide show
  1. package/dist/build-provenance.json +2 -2
  2. package/dist/cloud/auto-sync-command-entry.d.ts +13 -0
  3. package/dist/cloud/auto-sync-command-entry.d.ts.map +1 -0
  4. package/dist/cloud/auto-sync-command-entry.js +18 -0
  5. package/dist/cloud/auto-sync-command-entry.js.map +1 -0
  6. package/dist/cloud/auto-sync-command.d.ts +64 -0
  7. package/dist/cloud/auto-sync-command.d.ts.map +1 -0
  8. package/dist/cloud/auto-sync-command.js +109 -0
  9. package/dist/cloud/auto-sync-command.js.map +1 -0
  10. package/dist/cloud/auto-sync.d.ts +111 -0
  11. package/dist/cloud/auto-sync.d.ts.map +1 -0
  12. package/dist/cloud/auto-sync.js +275 -0
  13. package/dist/cloud/auto-sync.js.map +1 -0
  14. package/dist/cloud/nexus-cloud-device-overview.d.ts +52 -0
  15. package/dist/cloud/nexus-cloud-device-overview.d.ts.map +1 -0
  16. package/dist/cloud/nexus-cloud-device-overview.js +105 -0
  17. package/dist/cloud/nexus-cloud-device-overview.js.map +1 -0
  18. package/dist/cloud/nexus-cloud-journal-activity.d.ts +56 -0
  19. package/dist/cloud/nexus-cloud-journal-activity.d.ts.map +1 -0
  20. package/dist/cloud/nexus-cloud-journal-activity.js +98 -0
  21. package/dist/cloud/nexus-cloud-journal-activity.js.map +1 -0
  22. package/dist/cloud/nexus-cloud-status.d.ts.map +1 -1
  23. package/dist/cloud/nexus-cloud-status.js +88 -5
  24. package/dist/cloud/nexus-cloud-status.js.map +1 -1
  25. package/dist/cloud/nexus-vault.d.ts +19 -5
  26. package/dist/cloud/nexus-vault.d.ts.map +1 -1
  27. package/dist/cloud/nexus-vault.js +376 -71
  28. package/dist/cloud/nexus-vault.js.map +1 -1
  29. package/dist/cloud/replica-rebind.d.ts +14 -0
  30. package/dist/cloud/replica-rebind.d.ts.map +1 -1
  31. package/dist/cloud/replica-rebind.js +20 -1
  32. package/dist/cloud/replica-rebind.js.map +1 -1
  33. package/dist/config.d.ts +10 -0
  34. package/dist/config.d.ts.map +1 -1
  35. package/dist/config.js +19 -0
  36. package/dist/config.js.map +1 -1
  37. package/dist/docs/docs-ops.d.ts +4 -2
  38. package/dist/docs/docs-ops.d.ts.map +1 -1
  39. package/dist/docs/docs-ops.js +107 -15
  40. package/dist/docs/docs-ops.js.map +1 -1
  41. package/dist/doctor/system-health.d.ts +76 -2
  42. package/dist/doctor/system-health.d.ts.map +1 -1
  43. package/dist/doctor/system-health.js +264 -41
  44. package/dist/doctor/system-health.js.map +1 -1
  45. package/dist/hooks/project-runner.d.ts +10 -0
  46. package/dist/hooks/project-runner.d.ts.map +1 -0
  47. package/dist/hooks/project-runner.js +328 -0
  48. package/dist/hooks/project-runner.js.map +1 -0
  49. package/dist/hooks/project-state.d.ts +41 -0
  50. package/dist/hooks/project-state.d.ts.map +1 -0
  51. package/dist/hooks/project-state.js +331 -0
  52. package/dist/hooks/project-state.js.map +1 -0
  53. package/dist/hooks/release-gate.d.ts +61 -0
  54. package/dist/hooks/release-gate.d.ts.map +1 -0
  55. package/dist/hooks/release-gate.js +70 -0
  56. package/dist/hooks/release-gate.js.map +1 -0
  57. package/dist/nexus/analyze-orchestrator.d.ts +2 -0
  58. package/dist/nexus/analyze-orchestrator.d.ts.map +1 -1
  59. package/dist/nexus/analyze-orchestrator.js +1 -0
  60. package/dist/nexus/analyze-orchestrator.js.map +1 -1
  61. package/dist/nexus/freshness.d.ts +67 -3
  62. package/dist/nexus/freshness.d.ts.map +1 -1
  63. package/dist/nexus/freshness.js +130 -9
  64. package/dist/nexus/freshness.js.map +1 -1
  65. package/dist/nexus/refresh-child.d.ts +14 -0
  66. package/dist/nexus/refresh-child.d.ts.map +1 -0
  67. package/dist/nexus/refresh-child.js +24 -0
  68. package/dist/nexus/refresh-child.js.map +1 -0
  69. package/dist/orchestrate/spawn-ops.d.ts +8 -1
  70. package/dist/orchestrate/spawn-ops.d.ts.map +1 -1
  71. package/dist/orchestrate/spawn-ops.js +42 -12
  72. package/dist/orchestrate/spawn-ops.js.map +1 -1
  73. package/dist/orchestration/spawn.d.ts +5 -0
  74. package/dist/orchestration/spawn.d.ts.map +1 -1
  75. package/dist/orchestration/spawn.js +4 -1
  76. package/dist/orchestration/spawn.js.map +1 -1
  77. package/dist/release/channel.d.ts.map +1 -1
  78. package/dist/release/channel.js +10 -0
  79. package/dist/release/channel.js.map +1 -1
  80. package/dist/release/github-pr.d.ts.map +1 -1
  81. package/dist/release/github-pr.js +1 -0
  82. package/dist/release/github-pr.js.map +1 -1
  83. package/dist/release/plan.d.ts +8 -3
  84. package/dist/release/plan.d.ts.map +1 -1
  85. package/dist/release/plan.js +72 -15
  86. package/dist/release/plan.js.map +1 -1
  87. package/dist/release/reconcile.d.ts.map +1 -1
  88. package/dist/release/reconcile.js +6 -15
  89. package/dist/release/reconcile.js.map +1 -1
  90. package/dist/sentient/daemon-entry.d.ts +6 -0
  91. package/dist/sentient/daemon-entry.d.ts.map +1 -1
  92. package/dist/sentient/daemon-entry.js +12 -0
  93. package/dist/sentient/daemon-entry.js.map +1 -1
  94. package/dist/sentient/worktree-dispatch.d.ts +7 -0
  95. package/dist/sentient/worktree-dispatch.d.ts.map +1 -1
  96. package/dist/sentient/worktree-dispatch.js +37 -1
  97. package/dist/sentient/worktree-dispatch.js.map +1 -1
  98. package/dist/sessions/session-end-snapshot-entry.d.ts +4 -1
  99. package/dist/sessions/session-end-snapshot-entry.d.ts.map +1 -1
  100. package/dist/sessions/session-end-snapshot-entry.js +9 -1
  101. package/dist/sessions/session-end-snapshot-entry.js.map +1 -1
  102. package/dist/spawn/agent-identity.d.ts.map +1 -1
  103. package/dist/spawn/agent-identity.js +96 -1
  104. package/dist/spawn/agent-identity.js.map +1 -1
  105. package/dist/spawn/branch-lock.d.ts +27 -8
  106. package/dist/spawn/branch-lock.d.ts.map +1 -1
  107. package/dist/spawn/branch-lock.js +57 -73
  108. package/dist/spawn/branch-lock.js.map +1 -1
  109. package/dist/store/agent-resolver.d.ts +6 -0
  110. package/dist/store/agent-resolver.d.ts.map +1 -1
  111. package/dist/store/agent-resolver.js +2 -0
  112. package/dist/store/agent-resolver.js.map +1 -1
  113. package/dist/store/dual-scope-db.d.ts +20 -0
  114. package/dist/store/dual-scope-db.d.ts.map +1 -1
  115. package/dist/store/dual-scope-db.js +81 -8
  116. package/dist/store/dual-scope-db.js.map +1 -1
  117. package/dist/store/exodus/bare-family.d.ts.map +1 -1
  118. package/dist/store/exodus/bare-family.js +4 -1
  119. package/dist/store/exodus/bare-family.js.map +1 -1
  120. package/dist/store/exodus/migrate.d.ts.map +1 -1
  121. package/dist/store/exodus/migrate.js +2 -0
  122. package/dist/store/exodus/migrate.js.map +1 -1
  123. package/dist/store/exodus/on-open.d.ts.map +1 -1
  124. package/dist/store/exodus/on-open.js +16 -4
  125. package/dist/store/exodus/on-open.js.map +1 -1
  126. package/dist/store/exodus/reconcile.d.ts.map +1 -1
  127. package/dist/store/exodus/reconcile.js +2 -0
  128. package/dist/store/exodus/reconcile.js.map +1 -1
  129. package/dist/store/portable-bundle-import.d.ts +17 -0
  130. package/dist/store/portable-bundle-import.d.ts.map +1 -1
  131. package/dist/store/portable-bundle-import.js +46 -31
  132. package/dist/store/portable-bundle-import.js.map +1 -1
  133. package/dist/store/portable-bundle-scan.d.ts.map +1 -1
  134. package/dist/store/portable-bundle-scan.js +5 -0
  135. package/dist/store/portable-bundle-scan.js.map +1 -1
  136. package/dist/store/row-identity-registry.d.ts +4 -3
  137. package/dist/store/row-identity-registry.d.ts.map +1 -1
  138. package/dist/store/row-identity-registry.js +37 -35
  139. package/dist/store/row-identity-registry.js.map +1 -1
  140. package/dist/store/row-identity.d.ts.map +1 -1
  141. package/dist/store/row-identity.js +6 -1
  142. package/dist/store/row-identity.js.map +1 -1
  143. package/dist/store/schema/cleo-global/agent-registry.d.ts +16 -0
  144. package/dist/store/schema/cleo-global/agent-registry.d.ts.map +1 -1
  145. package/dist/store/schema/cleo-global/agent-registry.js +4 -1
  146. package/dist/store/schema/cleo-global/agent-registry.js.map +1 -1
  147. package/dist/store/schema/cleo-project/provenance-orphans.d.ts +126 -1
  148. package/dist/store/schema/cleo-project/provenance-orphans.d.ts.map +1 -1
  149. package/dist/store/schema/cleo-project/provenance-orphans.js +41 -1
  150. package/dist/store/schema/cleo-project/provenance-orphans.js.map +1 -1
  151. package/dist/store/sqlite-data-accessor.d.ts +40 -0
  152. package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
  153. package/dist/store/sqlite-data-accessor.js +122 -0
  154. package/dist/store/sqlite-data-accessor.js.map +1 -1
  155. package/dist/store/sync/activity.d.ts +64 -0
  156. package/dist/store/sync/activity.d.ts.map +1 -0
  157. package/dist/store/sync/activity.js +220 -0
  158. package/dist/store/sync/activity.js.map +1 -0
  159. package/dist/store/sync/apply/applier.d.ts.map +1 -1
  160. package/dist/store/sync/apply/applier.js +58 -2
  161. package/dist/store/sync/apply/applier.js.map +1 -1
  162. package/dist/store/sync/apply/write-api.d.ts.map +1 -1
  163. package/dist/store/sync/apply/write-api.js +45 -3
  164. package/dist/store/sync/apply/write-api.js.map +1 -1
  165. package/dist/store/sync/capture.d.ts +6 -4
  166. package/dist/store/sync/capture.d.ts.map +1 -1
  167. package/dist/store/sync/capture.js +16 -4
  168. package/dist/store/sync/capture.js.map +1 -1
  169. package/dist/store/sync/collision-settle.d.ts +120 -0
  170. package/dist/store/sync/collision-settle.d.ts.map +1 -1
  171. package/dist/store/sync/collision-settle.js +342 -5
  172. package/dist/store/sync/collision-settle.js.map +1 -1
  173. package/dist/store/sync/flags.d.ts +34 -0
  174. package/dist/store/sync/flags.d.ts.map +1 -1
  175. package/dist/store/sync/flags.js +46 -0
  176. package/dist/store/sync/flags.js.map +1 -1
  177. package/dist/store/sync/genesis.d.ts +8 -0
  178. package/dist/store/sync/genesis.d.ts.map +1 -1
  179. package/dist/store/sync/genesis.js +18 -5
  180. package/dist/store/sync/genesis.js.map +1 -1
  181. package/dist/store/sync/push.d.ts +4 -2
  182. package/dist/store/sync/push.d.ts.map +1 -1
  183. package/dist/store/sync/push.js +10 -1
  184. package/dist/store/sync/push.js.map +1 -1
  185. package/dist/store/sync/rebind.d.ts +20 -0
  186. package/dist/store/sync/rebind.d.ts.map +1 -1
  187. package/dist/store/sync/rebind.js +86 -4
  188. package/dist/store/sync/rebind.js.map +1 -1
  189. package/dist/store/sync/reconcile-copy.d.ts +152 -0
  190. package/dist/store/sync/reconcile-copy.d.ts.map +1 -0
  191. package/dist/store/sync/reconcile-copy.js +428 -0
  192. package/dist/store/sync/reconcile-copy.js.map +1 -0
  193. package/dist/store/sync/reconcile.d.ts +80 -0
  194. package/dist/store/sync/reconcile.d.ts.map +1 -1
  195. package/dist/store/sync/reconcile.js +97 -5
  196. package/dist/store/sync/reconcile.js.map +1 -1
  197. package/dist/store/sync/repair.d.ts +11 -0
  198. package/dist/store/sync/repair.d.ts.map +1 -1
  199. package/dist/store/sync/repair.js +14 -3
  200. package/dist/store/sync/repair.js.map +1 -1
  201. package/dist/store/sync/replica.d.ts +74 -1
  202. package/dist/store/sync/replica.d.ts.map +1 -1
  203. package/dist/store/sync/replica.js +104 -6
  204. package/dist/store/sync/replica.js.map +1 -1
  205. package/dist/store/sync/row-meta.d.ts +4 -2
  206. package/dist/store/sync/row-meta.d.ts.map +1 -1
  207. package/dist/store/sync/row-meta.js +6 -4
  208. package/dist/store/sync/row-meta.js.map +1 -1
  209. package/dist/store/sync/sealer.d.ts +2 -0
  210. package/dist/store/sync/sealer.d.ts.map +1 -1
  211. package/dist/store/sync/sealer.js +33 -4
  212. package/dist/store/sync/sealer.js.map +1 -1
  213. package/dist/store/sync/structural.d.ts.map +1 -1
  214. package/dist/store/sync/structural.js +3 -1
  215. package/dist/store/sync/structural.js.map +1 -1
  216. package/dist/store/sync/timestamp-canon.d.ts.map +1 -1
  217. package/dist/store/sync/timestamp-canon.js +2 -0
  218. package/dist/store/sync/timestamp-canon.js.map +1 -1
  219. package/dist/store/table-classification.d.ts +29 -0
  220. package/dist/store/table-classification.d.ts.map +1 -1
  221. package/dist/store/table-classification.js +85 -19
  222. package/dist/store/table-classification.js.map +1 -1
  223. package/dist/store/twin-collapse.d.ts.map +1 -1
  224. package/dist/store/twin-collapse.js +28 -10
  225. package/dist/store/twin-collapse.js.map +1 -1
  226. package/dist/store/vault-manifest.d.ts +5 -0
  227. package/dist/store/vault-manifest.d.ts.map +1 -1
  228. package/dist/store/vault-manifest.js +14 -1
  229. package/dist/store/vault-manifest.js.map +1 -1
  230. package/dist/tasks/affected-packages.d.ts +15 -5
  231. package/dist/tasks/affected-packages.d.ts.map +1 -1
  232. package/dist/tasks/affected-packages.js +20 -8
  233. package/dist/tasks/affected-packages.js.map +1 -1
  234. package/dist/tasks/done-record.d.ts +14 -4
  235. package/dist/tasks/done-record.d.ts.map +1 -1
  236. package/dist/tasks/done-record.js +21 -9
  237. package/dist/tasks/done-record.js.map +1 -1
  238. package/dist/tasks/evidence.d.ts.map +1 -1
  239. package/dist/tasks/evidence.js +45 -4
  240. package/dist/tasks/evidence.js.map +1 -1
  241. package/dist/tasks/gate-runner.d.ts +5 -4
  242. package/dist/tasks/gate-runner.d.ts.map +1 -1
  243. package/dist/tasks/gate-runner.js +18 -11
  244. package/dist/tasks/gate-runner.js.map +1 -1
  245. package/dist/tasks/tool-cache.d.ts +27 -1
  246. package/dist/tasks/tool-cache.d.ts.map +1 -1
  247. package/dist/tasks/tool-cache.js +110 -6
  248. package/dist/tasks/tool-cache.js.map +1 -1
  249. package/dist/tools/fs.d.ts +3 -1
  250. package/dist/tools/fs.d.ts.map +1 -1
  251. package/dist/tools/fs.js +35 -2
  252. package/dist/tools/fs.js.map +1 -1
  253. package/dist/validation/engine-ops.d.ts +10 -3
  254. package/dist/validation/engine-ops.d.ts.map +1 -1
  255. package/dist/validation/engine-ops.js +17 -8
  256. package/dist/validation/engine-ops.js.map +1 -1
  257. package/migrations/drizzle-cleo-global/20261010180000_t12915-agent-registry-uids/migration.sql +18 -0
  258. package/migrations/drizzle-cleo-project/20261010170000_t12896b-brain-task-observations/migration.sql +37 -0
  259. package/migrations/sync-journal/20261009150000_t13335-capture-pin/migration.sql +13 -0
  260. package/package.json +18 -13
  261. package/schemas/config.schema.json +12 -0
  262. package/schemas/project-context.schema.json +5 -0
  263. package/templates/CLEO-INJECTION.md +2 -2
  264. package/templates/CLEO-REFERENCE.md +6 -4
  265. package/templates/git-hooks/pre-push +29 -1
  266. package/templates/workflows/release-prepare.yml.tmpl +1 -0
@@ -35,6 +35,24 @@ async function backend() {
35
35
  // ---------------------------------------------------------------------------
36
36
  // Public dispatch API
37
37
  // ---------------------------------------------------------------------------
38
+ /**
39
+ * Admit one worktree dependency install as a `scoped-build` run, without
40
+ * waiting: the release on a grant, `null` when the budget is busy.
41
+ *
42
+ * @task T13524
43
+ */
44
+ export async function admitWorktreeInstall() {
45
+ const { governor } = await import('../resources/governor.js');
46
+ try {
47
+ const grant = await governor.acquire('scoped-build', { blocking: false });
48
+ return grant.deferred ? null : () => grant.release();
49
+ }
50
+ catch {
51
+ // Admission state cannot be kept here (sandbox, read-only home): fail open,
52
+ // as every other governed run does.
53
+ return async () => { };
54
+ }
55
+ }
38
56
  /**
39
57
  * Create a worktree for an agent task via the native backend.
40
58
  *
@@ -50,7 +68,25 @@ async function backend() {
50
68
  */
51
69
  export async function spawnWorktree(projectRoot, options) {
52
70
  const { createWorktree } = await backend();
53
- return createWorktree(projectRoot, options);
71
+ const { createProjectHookExecutor } = await import('../hooks/project-runner.js');
72
+ const hookOptions = {
73
+ ...options,
74
+ projectHookExecutor: options.projectHookExecutor ?? createProjectHookExecutor(projectRoot),
75
+ };
76
+ // T13522: install the git shim before the worktree advertises strict protection.
77
+ let withShim = hookOptions;
78
+ if (!options.gitShim) {
79
+ const { ensureGitShimDir } = await import('../spawn/branch-lock.js');
80
+ const shim = ensureGitShimDir(projectRoot);
81
+ withShim = { ...hookOptions, gitShim: { dir: shim.dir, installed: shim.installed } };
82
+ }
83
+ // T13524: admit the dependency install through the machine-wide heavy queue
84
+ // (the same `scoped-build` class as `cleo run --class build`); a busy budget
85
+ // defers it to the worker instead of blocking the spawn.
86
+ const admitted = withShim.skipInstall || withShim.admitInstall
87
+ ? withShim
88
+ : { ...withShim, admitInstall: admitWorktreeInstall };
89
+ return createWorktree(projectRoot, admitted);
54
90
  }
55
91
  /**
56
92
  * Destroy a worktree for a completed task via the native backend.
@@ -1 +1 @@
1
- {"version":3,"file":"worktree-dispatch.js","sourceRoot":"","sources":["../../src/sentient/worktree-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAYH,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E;;;;;GAKG;AACH,KAAK,UAAU,OAAO;IACpB,OAAO,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACtC,CAAC;AAED,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,WAAmB,EACnB,OAA8B;IAE9B,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,OAAO,EAAE,CAAC;IAC3C,OAAO,cAAc,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,WAAmB,EACnB,OAA+B;IAE/B,MAAM,GAAG,GAAG,MAAM,OAAO,EAAE,CAAC;IAC5B,OAAO,GAAG,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAgC,EAAE;IACrE,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB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AC;AAC7F,IAAI,mBAAmB,GAA6D,IAAI,CAAC;AACzF,IAAI,oBAAoB,GAA8D,IAAI,CAAC;AAE3F;;;GAGG;AACH,SAAS,kBAAkB,CAAC,OAA6B;IACvD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC,CAAC,sCAAsC;IACnD,CAAC;IACD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,OAA0E;IAE1E,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,OAAO;YACL,OAAO,EAAE,CAAC;YACV,YAAY,EAAE,EAAE;YAChB,WAAW,EAAE,CAAC;YACd,gBAAgB,EAAE,EAAE;YACpB,MAAM,EAAE,EAAE;YACV,WAAW,EAAE,KAAK;SACnB,CAAC;IACJ,CAAC;IACD,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,IAAI,qBAAqB;QAAE,OAAO,CAAC,qBAAqB;IAExD,MAAM,GAAG,GAAG,MAAM,OAAO,EAAE,CAAC;IAC5B,qBAAqB,GAAG,GAAG,CAAC,eAAe,CAAC;IAC5C,mBAAmB,GAAG,GAAG,CAAC,aAAa,CAAC;IACxC,oBAAoB,GAAG,GAAG,CAAC,cAAc,CAAC;AAC5C,CAAC"}
@@ -19,12 +19,15 @@
19
19
  * reader, and CLEO keeps stdout for LAFS envelopes).
20
20
  *
21
21
  * After the snapshot it embeds one bounded batch of observations that one-shot
22
- * processes stored unembedded (T13126, `memory/embedding-backfill.ts`).
22
+ * processes stored unembedded (T13126, `memory/embedding-backfill.ts`), then
23
+ * runs the automatic cloud sync (T13468, `cloud/auto-sync.ts`). Both run only
24
+ * here, in the detached worker, never in the process that ended the session.
23
25
  *
24
26
  * argv: `<projectRoot> <markerToken>`
25
27
  *
26
28
  * @task T12508
27
29
  * @task T13126
30
+ * @task T13468
28
31
  */
29
32
  export {};
30
33
  //# sourceMappingURL=session-end-snapshot-entry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-end-snapshot-entry.d.ts","sourceRoot":"","sources":["../../src/sessions/session-end-snapshot-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG"}
1
+ {"version":3,"file":"session-end-snapshot-entry.d.ts","sourceRoot":"","sources":["../../src/sessions/session-end-snapshot-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG"}
@@ -19,15 +19,19 @@
19
19
  * reader, and CLEO keeps stdout for LAFS envelopes).
20
20
  *
21
21
  * After the snapshot it embeds one bounded batch of observations that one-shot
22
- * processes stored unembedded (T13126, `memory/embedding-backfill.ts`).
22
+ * processes stored unembedded (T13126, `memory/embedding-backfill.ts`), then
23
+ * runs the automatic cloud sync (T13468, `cloud/auto-sync.ts`). Both run only
24
+ * here, in the detached worker, never in the process that ended the session.
23
25
  *
24
26
  * argv: `<projectRoot> <markerToken>`
25
27
  *
26
28
  * @task T12508
27
29
  * @task T13126
30
+ * @task T13468
28
31
  */
29
32
  import { appendFileSync, mkdirSync } from 'node:fs';
30
33
  import { join } from 'node:path';
34
+ import { autoCloudSync } from '../cloud/auto-sync.js';
31
35
  import { runBoundedEmbeddingBackfill } from '../memory/embedding-backfill.js';
32
36
  import { getCleoDir } from '../paths.js';
33
37
  import { SNAPSHOT_LOCK_WAIT_RETRIES } from '../store/snapshot-gate.js';
@@ -50,6 +54,9 @@ releaseSessionEndWorkerMarker(projectRoot, markerToken);
50
54
  // class, so the model loads once per session instead of once per observe. It is
51
55
  // a no-op when nothing is pending. Best-effort: it never throws.
52
56
  const embeddings = await runBoundedEmbeddingBackfill(projectRoot);
57
+ // T13468: sync the main brain (and the project) with the cloud. Best-effort,
58
+ // throttled, single-flight and bounded; it never throws.
59
+ const autoSync = await autoCloudSync(projectRoot, 'session-end');
53
60
  try {
54
61
  const logsDir = join(getCleoDir(projectRoot), 'logs');
55
62
  mkdirSync(logsDir, { recursive: true });
@@ -60,6 +67,7 @@ try {
60
67
  projectRoot,
61
68
  result,
62
69
  embeddings,
70
+ autoSync,
63
71
  })}\n`);
64
72
  }
65
73
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"session-end-snapshot-entry.js","sourceRoot":"","sources":["../../src/sessions/session-end-snapshot-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEnG,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpC,IAAI,CAAC,WAAW,EAAE,CAAC;IACjB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACtF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AACD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAE1C,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,WAAW,EAAE;IACxD,eAAe,EAAE,0BAA0B;IAC3C,cAAc,EAAE,IAAI;IACpB,cAAc,EAAE,GAAG,EAAE,CAAC,6BAA6B,CAAC,WAAW,EAAE,WAAW,CAAC;CAC9E,CAAC,CAAC;AACH,2EAA2E;AAC3E,6BAA6B,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAExD,iFAAiF;AACjF,gFAAgF;AAChF,gFAAgF;AAChF,iEAAiE;AACjE,MAAM,UAAU,GAAG,MAAM,2BAA2B,CAAC,WAAW,CAAC,CAAC;AAElE,IAAI,CAAC;IACH,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;IACtD,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,cAAc,CACZ,IAAI,CAAC,OAAO,EAAE,0BAA0B,CAAC,EACzC,GAAG,IAAI,CAAC,SAAS,CAAC;QAChB,KAAK,EAAE,sBAAsB;QAC7B,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAC5B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,WAAW;QACX,MAAM;QACN,UAAU;KACX,CAAC,IAAI,CACP,CAAC;AACJ,CAAC;AAAC,MAAM,CAAC;IACP,mEAAmE;AACrE,CAAC;AACD,6DAA6D;AAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"session-end-snapshot-entry.js","sourceRoot":"","sources":["../../src/sessions/session-end-snapshot-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEnG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C,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAwB,GACzF,OAAO,CAAC,sBAAsB,CAAC,CAsDjC;AAwGD;;;;;;;;;;;GAWG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,OAAO,CAAC,sBAAsB,EAAE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,GACxD,OAAO,CAAC,IAAI,CAAC,CAQf"}
@@ -25,7 +25,8 @@ import { generateSessionId } from '../sessions/session-id.js';
25
25
  import { getTaskAccessor } from '../store/data-accessor.js';
26
26
  import { withLock } from '../store/lock.js';
27
27
  import { endSession } from '../store/session-store.js';
28
- import { claimSpawnedTask, releaseSpawnClaim, } from '../task-work/claims.js';
28
+ import { isClaimExpired, taskClaimedError, taskClaimLeaseMs } from '../store/task-claim.js';
29
+ import { claimSpawnedTask, releaseOwnClaim, releaseSpawnClaim, } from '../task-work/claims.js';
29
30
  /**
30
31
  * Derive a deterministic agent handle for a spawned task.
31
32
  *
@@ -154,6 +155,16 @@ export async function requireSpawnSession(projectRoot, taskId, allocate = alloca
154
155
  cause,
155
156
  };
156
157
  }
158
+ if (identity.reused) {
159
+ const verdict = await assessReusedSession(projectRoot, taskId, identity);
160
+ if (verdict.kind === 'refuse')
161
+ return verdict.refusal;
162
+ // An unused session keeps its spawn lease untouched: renewing it here would
163
+ // read as worker activity to the next re-spawn.
164
+ if (verdict.kind === 'unused') {
165
+ return { ok: true, identity, claim: { claim: verdict.lease, previous: verdict.lease } };
166
+ }
167
+ }
157
168
  let claim;
158
169
  try {
159
170
  claim = await claimSpawnedTask(projectRoot, taskId, {
@@ -179,6 +190,90 @@ export async function requireSpawnSession(projectRoot, taskId, allocate = alloca
179
190
  }
180
191
  return { ok: true, identity, claim };
181
192
  }
193
+ /**
194
+ * Decide what a re-spawn may do with the task's per-agent session (T13491,
195
+ * axiom T1544). A re-spawn reuses that session; a second agent bound to a
196
+ * session a live worker is using would bleed into it.
197
+ *
198
+ * The worker signal is the lease itself: spawn grants `claimedAt + lease`,
199
+ * and every mutation the holder makes renews it at once (no throttle, unlike
200
+ * `lastActivity`). A live lease that runs past what its spawn granted means a
201
+ * worker has done work under the session: refuse with `E_TASK_CLAIMED` naming
202
+ * the holder and a hand-off. A live lease still at its spawn value means no
203
+ * worker has used the session yet (the orchestrator asks for the prompt
204
+ * again): reuse it without renewing, so the next re-spawn still reads it as
205
+ * unused.
206
+ *
207
+ * The holder stops counting as live through the existing rules only: ending
208
+ * its session releases the lease and worktree lock (T13425, SQL trigger), and
209
+ * a lease its worker stopped renewing expires. An expired lease is released
210
+ * (audited as `spawn_session_reclaim`) so the re-claim starts a fresh lease
211
+ * with a new `claimedAt`.
212
+ *
213
+ * shortcut: the comparison uses the current `CLEO_CLAIM_LEASE_MINUTES`; a
214
+ * lease length changed between spawn and re-spawn misreads one lease period.
215
+ *
216
+ * @param projectRoot - Project root.
217
+ * @param taskId - The task being spawned.
218
+ * @param identity - The reused per-agent session.
219
+ * @returns Claim as usual, reuse the unused lease, or refuse.
220
+ * @task T13491
221
+ * @task T13498
222
+ */
223
+ async function assessReusedSession(projectRoot, taskId, identity) {
224
+ const acc = await getTaskAccessor(projectRoot);
225
+ const held = (await acc.loadSingleTask(taskId))?.claim;
226
+ if (!held || held.sessionId !== identity.sessionId)
227
+ return { kind: 'claim' };
228
+ const now = new Date().toISOString();
229
+ if (isClaimExpired(held, now)) {
230
+ await releaseOwnClaim(acc, taskId, identity.sessionId);
231
+ await acc.appendLog({
232
+ action: 'spawn_session_reclaim',
233
+ taskId,
234
+ actor: identity.agentId,
235
+ sessionId: identity.sessionId,
236
+ timestamp: now,
237
+ details: { reason: 'lease-expired', leaseExpiresAt: held.leaseExpiresAt },
238
+ before: held,
239
+ });
240
+ return { kind: 'claim' };
241
+ }
242
+ const granted = Date.parse(held.claimedAt) + taskClaimLeaseMs();
243
+ // Spawn writes claimedAt and the expiry from one instant, so an untouched lease is exact.
244
+ if (Date.parse(held.leaseExpiresAt) <= granted) {
245
+ return { kind: 'unused', lease: held };
246
+ }
247
+ const err = taskClaimedError(taskId, held, { sessionId: null, agentId: null }, now, 'orchestrate spawn');
248
+ const who = held.agentId
249
+ ? `session ${held.sessionId} (agent ${held.agentId})`
250
+ : `session ${held.sessionId}`;
251
+ const message = `Refusing to spawn ${taskId}: a live worker is using ${who}, the session this spawn would hand the child; ` +
252
+ `it renewed its lease after the spawn (lease now expires ${held.leaseExpiresAt}).`;
253
+ return {
254
+ kind: 'refuse',
255
+ refusal: {
256
+ ok: false,
257
+ // @sync-invariant none:local-only refuses before any write; lease liveness is this device's spawn coordination
258
+ code: 'E_TASK_CLAIMED',
259
+ exitCode: ExitCode.TASK_CLAIMED,
260
+ message,
261
+ fix: `Hand off instead of spawning over it: coordinate with that worker, or once it has stopped end its session ` +
262
+ `(cleo session end --session ${held.sessionId}), which releases its claim and worktree lock, then spawn again. ` +
263
+ `A worker that stops renewing loses the lease at ${held.leaseExpiresAt}; the next spawn then reclaims the session (audited).`,
264
+ cause: message,
265
+ details: {
266
+ ...(err.details ?? {}),
267
+ handoff: {
268
+ holderSessionId: held.sessionId,
269
+ holderAgentId: held.agentId,
270
+ claimedAt: held.claimedAt,
271
+ leaseExpiresAt: held.leaseExpiresAt,
272
+ },
273
+ },
274
+ },
275
+ };
276
+ }
182
277
  /**
183
278
  * Undo a {@link requireSpawnSession} whose spawn then failed (T12502): give
184
279
  * the task claim back to its previous holder (the orchestrator on a
@@ -1 +1 @@
1
- {"version":3,"file":"agent-identity.js","sourceRoot":"","sources":["../../src/spawn/agent-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAA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AACH,CAAC"}
@@ -67,7 +67,9 @@ export declare function createAgentWorktree(taskId: string, projectRoot: string)
67
67
  * env block and prompt preamble that bind the agent to its worktree.
68
68
  *
69
69
  * @param worktree - The created worktree state.
70
- * @param shimDir - Directory containing the git shim symlink.
70
+ * @param shim - The {@link ensureGitShimDir} result; strict protection and the
71
+ * PATH entry apply only when it is installed (T13522). A bare directory
72
+ * string is taken as installed (legacy callers).
71
73
  * @param identity - Per-agent session + agent identity to inject (T11343).
72
74
  * `sessionId` → `CLEO_SESSION_ID`, `agentId` → `CLEO_AGENT_ID`. Only set
73
75
  * when non-empty so an unallocated identity never clobbers an inherited env.
@@ -78,7 +80,7 @@ export declare function createAgentWorktree(taskId: string, projectRoot: string)
78
80
  * @task T1121
79
81
  * @task T11343
80
82
  */
81
- export declare function buildWorktreeSpawnResult(worktree: AgentWorktreeState, shimDir: string, identity?: {
83
+ export declare function buildWorktreeSpawnResult(worktree: AgentWorktreeState, shim: string | GitShimInstall, identity?: {
82
84
  sessionId?: string | null;
83
85
  agentId?: string | null;
84
86
  }): WorktreeSpawnResult;
@@ -352,18 +354,35 @@ export declare function completeAgentWorktreeIntegration(taskId: string, project
352
354
  skipFetch?: boolean;
353
355
  auditLogPath?: string;
354
356
  }): WorktreeIntegrationResult;
357
+ /** Result of {@link ensureGitShimDir}. */
358
+ export interface GitShimInstall {
359
+ /** Directory to prepend to a worker's PATH. */
360
+ readonly dir: string;
361
+ /** True only when an executable `git` launcher now points at the real shim. */
362
+ readonly installed: boolean;
363
+ /** The shim entry point used, when one was found. */
364
+ readonly shimBinPath: string | null;
365
+ /** Why the shim is not installed. */
366
+ readonly reason?: string;
367
+ }
355
368
  /**
356
- * Ensure the git shim symlink exists in the project's `.cleo/bin/git-shim/` dir.
369
+ * Install the git shim launcher in the project's `.cleo/bin/git-shim/` dir
370
+ * (T1118, wired in by T13522). Idempotent.
357
371
  *
358
- * The shim directory is prepended to PATH in agent spawn env. Idempotent.
372
+ * The shim is resolved from the `@cleocode/git-shim` package the running CLI
373
+ * was installed with, not from the project's node_modules, so a standalone
374
+ * project gets it too. When it cannot be found or the launcher cannot be
375
+ * written, nothing is installed and `installed` is `false`: callers then
376
+ * advertise `CLEO_BRANCH_PROTECTION=unavailable` rather than a fence that is
377
+ * not there.
359
378
  *
360
379
  * @param projectRoot - Absolute path to the project root.
361
- * @returns Absolute path to the shim directory (to prepend to PATH).
362
- *
380
+ * @param shimBinPath - The shim entry point (tests); defaults to the installed package's.
381
+ * @returns Where the shim lives and whether it is installed.
363
382
  * @task T1118
364
- * @task T1121
383
+ * @task T13522
365
384
  */
366
- export declare function ensureGitShimDir(projectRoot: string): string;
385
+ export declare function ensureGitShimDir(projectRoot: string, shimBinPath?: string): GitShimInstall;
367
386
  /**
368
387
  * Detect platform capabilities for filesystem hardening.
369
388
  *
@@ -1 +1 @@
1
- {"version":3,"file":"branch-lock.d.ts","sourceRoot":"","sources":["../../src/spawn/branch-lock.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;GAmBG;AAgBH,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAc7B,OAAO,EAEL,UAAU,EAOX,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,UAAU,EAAE,CAAC;AAMtB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAGpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,kBAAkB,CAqE3F;AAeD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,G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,CAAC,EAAE,MAAM,CAAC;CAClB,GACL,yBAAyB,CAgC3B;AAMD,0CAA0C;AAC1C,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,qDAAqD;IACrD,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,qCAAqC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,WAAW,GAAE,MAA6B,GACzC,cAAc,CA4BhB;AAMD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,IAAI,oBAAoB,CA+BjE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,aAAa,CAyC/F;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,aAAa,GAAG,IAAI,CA0B/D;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,cAAc,EAAE,mBAAmB,EACnC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAyC,GACtE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExB"}
@@ -20,10 +20,10 @@
20
20
  * @adr ADR-062
21
21
  */
22
22
  import { execFileSync } from 'node:child_process';
23
- import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync, } from 'node:fs';
23
+ import { accessSync, appendFileSync, chmodSync, constants, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, } from 'node:fs';
24
24
  import { platform } from 'node:os';
25
25
  import { dirname, isAbsolute, join, relative } from 'node:path';
26
- import { installGitShimLaunchers } from '@cleocode/git-shim';
26
+ import { installGitShimLaunchers, resolveShimBinPath } from '@cleocode/git-shim';
27
27
  import { computeProjectHash, findOnPath, pathEnvKey, prependPathEntry, resolveWorktreeRootForHash, } from '@cleocode/paths';
28
28
  // ---------------------------------------------------------------------------
29
29
  // Re-exports from @cleocode/worktree
@@ -155,7 +155,9 @@ function shellQuote(value) {
155
155
  * env block and prompt preamble that bind the agent to its worktree.
156
156
  *
157
157
  * @param worktree - The created worktree state.
158
- * @param shimDir - Directory containing the git shim symlink.
158
+ * @param shim - The {@link ensureGitShimDir} result; strict protection and the
159
+ * PATH entry apply only when it is installed (T13522). A bare directory
160
+ * string is taken as installed (legacy callers).
159
161
  * @param identity - Per-agent session + agent identity to inject (T11343).
160
162
  * `sessionId` → `CLEO_SESSION_ID`, `agentId` → `CLEO_AGENT_ID`. Only set
161
163
  * when non-empty so an unallocated identity never clobbers an inherited env.
@@ -166,20 +168,26 @@ function shellQuote(value) {
166
168
  * @task T1121
167
169
  * @task T11343
168
170
  */
169
- export function buildWorktreeSpawnResult(worktree, shimDir, identity = {}) {
171
+ export function buildWorktreeSpawnResult(worktree, shim, identity = {}) {
170
172
  const pathKey = pathEnvKey();
173
+ const shimDir = typeof shim === 'string' ? shim : shim.dir;
174
+ const shimActive = typeof shim === 'string' || shim.installed;
171
175
  const envVars = {
172
176
  CLEO_AGENT_ROLE: 'worker',
173
177
  CLEO_AGENT_CWD: worktree.path,
174
178
  CLEO_WORKTREE_ROOT: worktree.path,
175
179
  CLEO_WORKTREE_BRANCH: worktree.branch,
176
180
  CLEO_PROJECT_HASH: worktree.projectHash,
177
- CLEO_BRANCH_PROTECTION: 'strict',
178
- CLEO_SHIM_MARKER: '.cleo/bin/git-shim',
179
- // Prepend the shim directory so `git` resolves to the shim. The platform
180
- // delimiter matters: `${shimDir}:${PATH}` on Windows fuses the shim dir
181
- // with the first real entry and loses both (T12605).
182
- [pathKey]: prependPathEntry(shimDir, process.env[pathKey]),
181
+ CLEO_BRANCH_PROTECTION: shimActive ? 'strict' : 'unavailable',
182
+ ...(shimActive
183
+ ? {
184
+ CLEO_SHIM_MARKER: '.cleo/bin/git-shim',
185
+ // Prepend the shim directory so `git` resolves to the shim. The platform
186
+ // delimiter matters: `${shimDir}:${PATH}` on Windows fuses the shim dir
187
+ // with the first real entry and loses both (T12605).
188
+ [pathKey]: prependPathEntry(shimDir, process.env[pathKey]),
189
+ }
190
+ : {}),
183
191
  };
184
192
  // T11343 — bind the spawned agent's OWN session + identity into the worker
185
193
  // env so every short-lived `cleo` call inside the worktree resolves THIS
@@ -204,7 +212,9 @@ export function buildWorktreeSpawnResult(worktree, shimDir, identity = {}) {
204
212
  ' git checkout, git switch, git branch -b/-D, git reset --hard,',
205
213
  ' git worktree add/remove, git rebase, git stash pop, git push --force',
206
214
  '',
207
- 'A git shim is active on your PATH that will exit 77 if you attempt these.',
215
+ shimActive
216
+ ? 'A git shim is active on your PATH that will exit 77 if you attempt these, or a push to main.'
217
+ : 'No git shim could be installed for this worktree: these rules are NOT enforced, so follow them yourself.',
208
218
  `Your working directory is: ${worktree.path}`,
209
219
  'All your commits must land on YOUR branch only.',
210
220
  '',
@@ -982,78 +992,52 @@ export function completeAgentWorktreeIntegration(taskId, projectRoot, opts = {})
982
992
  }
983
993
  return { ...mergeResult, auditLogEntry };
984
994
  }
985
- // ---------------------------------------------------------------------------
986
- // L2 — Shim materialisation
987
- // ---------------------------------------------------------------------------
988
- /** Minimal stub shim script content for when the package isn't installed. */
989
- const STUB_SHIM_CONTENT = `#!/usr/bin/env node
990
- // git-shim stub (install @cleocode/git-shim for the full binary)
991
- import { spawnSync } from 'node:child_process';
992
- const RESTRICTED = new Set(['worker','lead','subagent']);
993
- const BLOCKED = new Set(['checkout','switch','rebase']);
994
- const role = process.env['CLEO_AGENT_ROLE'];
995
- const sub = process.argv[2];
996
- if (role && RESTRICTED.has(role) && sub && BLOCKED.has(sub) && !process.env['CLEO_ALLOW_BRANCH_OPS']) {
997
- process.stderr.write('[git-shim] BLOCKED: ' + sub + ' is not allowed for role ' + role + '\\n');
998
- process.exit(77);
999
- }
1000
- const git = process.env['CLEO_REAL_GIT_PATH'] || '/usr/bin/git';
1001
- const r = spawnSync(git, process.argv.slice(2), { stdio: 'inherit' });
1002
- process.exit(r.status ?? 0);
1003
- `;
1004
995
  /**
1005
- * Ensure the git shim symlink exists in the project's `.cleo/bin/git-shim/` dir.
996
+ * Install the git shim launcher in the project's `.cleo/bin/git-shim/` dir
997
+ * (T1118, wired in by T13522). Idempotent.
1006
998
  *
1007
- * The shim directory is prepended to PATH in agent spawn env. Idempotent.
999
+ * The shim is resolved from the `@cleocode/git-shim` package the running CLI
1000
+ * was installed with, not from the project's node_modules, so a standalone
1001
+ * project gets it too. When it cannot be found or the launcher cannot be
1002
+ * written, nothing is installed and `installed` is `false`: callers then
1003
+ * advertise `CLEO_BRANCH_PROTECTION=unavailable` rather than a fence that is
1004
+ * not there.
1008
1005
  *
1009
1006
  * @param projectRoot - Absolute path to the project root.
1010
- * @returns Absolute path to the shim directory (to prepend to PATH).
1011
- *
1007
+ * @param shimBinPath - The shim entry point (tests); defaults to the installed package's.
1008
+ * @returns Where the shim lives and whether it is installed.
1012
1009
  * @task T1118
1013
- * @task T1121
1010
+ * @task T13522
1014
1011
  */
1015
- export function ensureGitShimDir(projectRoot) {
1016
- const shimDir = join(projectRoot, '.cleo', 'bin', 'git-shim');
1017
- mkdirSync(shimDir, { recursive: true });
1018
- // Resolve the shim binary from @cleocode/git-shim package.
1019
- let shimBinPath = null;
1020
- try {
1021
- // Node.js require.resolve to find the installed package binary.
1022
- // We use a dynamic import approach compatible with ESM.
1023
- const candidatePaths = [
1024
- join(projectRoot, 'node_modules', '@cleocode', 'git-shim', 'dist', 'shim.js'),
1025
- join(projectRoot, '..', '..', 'node_modules', '@cleocode', 'git-shim', 'dist', 'shim.js'),
1026
- ];
1027
- for (const p of candidatePaths) {
1028
- if (existsSync(p)) {
1029
- shimBinPath = p;
1030
- break;
1031
- }
1032
- }
1033
- }
1034
- catch {
1035
- // ignore
1036
- }
1037
- if (!shimBinPath) {
1038
- // Write a minimal stub shim.
1039
- shimBinPath = join(shimDir, '_shim_bin.cjs');
1040
- try {
1041
- writeFileSync(shimBinPath, STUB_SHIM_CONTENT, { encoding: 'utf-8', mode: 0o755 });
1042
- }
1043
- catch {
1044
- // ignore — best effort
1045
- }
1012
+ export function ensureGitShimDir(projectRoot, shimBinPath = resolveShimBinPath()) {
1013
+ const dir = join(projectRoot, '.cleo', 'bin', 'git-shim');
1014
+ if (!existsSync(shimBinPath)) {
1015
+ return {
1016
+ dir,
1017
+ installed: false,
1018
+ shimBinPath: null,
1019
+ reason: `git shim not found at ${shimBinPath}`,
1020
+ };
1046
1021
  }
1047
- // Create/update the `git` launcher: a symlink on POSIX; on Windows a
1048
- // `git.cmd` + sh launcher, since PATHEXT ignores extensionless files and
1049
- // file symlinks need privileges (T12605).
1050
1022
  try {
1051
- installGitShimLaunchers(shimDir, shimBinPath);
1023
+ // A symlink on POSIX; on Windows a `git.cmd` + sh launcher, since PATHEXT
1024
+ // ignores extensionless files and file symlinks need privileges (T12605).
1025
+ const launchers = installGitShimLaunchers(dir, shimBinPath);
1026
+ // Windows has no execute bit: there the launcher existing is the check.
1027
+ for (const launcher of launchers) {
1028
+ accessSync(launcher, process.platform === 'win32' ? constants.F_OK : constants.X_OK);
1029
+ }
1030
+ return { dir, installed: true, shimBinPath };
1052
1031
  }
1053
- catch {
1054
- // Launcher install may fail on some filesystems — non-fatal.
1032
+ catch (err) {
1033
+ const reason = err instanceof Error ? err.message : String(err);
1034
+ return {
1035
+ dir,
1036
+ installed: false,
1037
+ shimBinPath,
1038
+ reason: `git shim launcher not installed: ${reason}`,
1039
+ };
1055
1040
  }
1056
- return shimDir;
1057
1041
  }
1058
1042
  // ---------------------------------------------------------------------------
1059
1043
  // L3 — Filesystem hardening