@cleocode/core 2026.3.59 → 2026.3.61

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 (826) hide show
  1. package/dist/adapters/adapter-registry.js +64 -0
  2. package/dist/adapters/adapter-registry.js.map +1 -0
  3. package/dist/adapters/discovery.js +83 -0
  4. package/dist/adapters/discovery.js.map +1 -0
  5. package/dist/adapters/index.js +9 -0
  6. package/dist/adapters/index.js.map +1 -0
  7. package/dist/adapters/manager.js +260 -0
  8. package/dist/adapters/manager.js.map +1 -0
  9. package/dist/admin/export-tasks.js +171 -0
  10. package/dist/admin/export-tasks.js.map +1 -0
  11. package/dist/admin/export.js +103 -0
  12. package/dist/admin/export.js.map +1 -0
  13. package/dist/admin/help.js +106 -0
  14. package/dist/admin/help.js.map +1 -0
  15. package/dist/admin/import-tasks.js +182 -0
  16. package/dist/admin/import-tasks.js.map +1 -0
  17. package/dist/admin/import.js +129 -0
  18. package/dist/admin/import.js.map +1 -0
  19. package/dist/admin/index.js +13 -0
  20. package/dist/admin/index.js.map +1 -0
  21. package/dist/adrs/find.js +134 -0
  22. package/dist/adrs/find.js.map +1 -0
  23. package/dist/adrs/index.js +15 -0
  24. package/dist/adrs/index.js.map +1 -0
  25. package/dist/adrs/link-pipeline.js +160 -0
  26. package/dist/adrs/link-pipeline.js.map +1 -0
  27. package/dist/adrs/list.js +43 -0
  28. package/dist/adrs/list.js.map +1 -0
  29. package/dist/adrs/parse.js +51 -0
  30. package/dist/adrs/parse.js.map +1 -0
  31. package/dist/adrs/show.js +22 -0
  32. package/dist/adrs/show.js.map +1 -0
  33. package/dist/adrs/sync.js +188 -0
  34. package/dist/adrs/sync.js.map +1 -0
  35. package/dist/adrs/types.js +9 -0
  36. package/dist/adrs/types.js.map +1 -0
  37. package/dist/adrs/validate.js +57 -0
  38. package/dist/adrs/validate.js.map +1 -0
  39. package/dist/agents/agent-registry.js +288 -0
  40. package/dist/agents/agent-registry.js.map +1 -0
  41. package/dist/agents/agent-schema.js +85 -0
  42. package/dist/agents/agent-schema.js.map +1 -0
  43. package/dist/agents/capacity.js +116 -0
  44. package/dist/agents/capacity.js.map +1 -0
  45. package/dist/agents/execution-learning.js +474 -0
  46. package/dist/agents/execution-learning.js.map +1 -0
  47. package/dist/agents/health-monitor.js +217 -0
  48. package/dist/agents/health-monitor.js.map +1 -0
  49. package/dist/agents/index.js +29 -0
  50. package/dist/agents/index.js.map +1 -0
  51. package/dist/agents/registry.js +314 -0
  52. package/dist/agents/registry.js.map +1 -0
  53. package/dist/agents/retry.js +229 -0
  54. package/dist/agents/retry.js.map +1 -0
  55. package/dist/audit-prune.js +94 -0
  56. package/dist/audit-prune.js.map +1 -0
  57. package/dist/audit.js +68 -0
  58. package/dist/audit.js.map +1 -0
  59. package/dist/backfill/index.js +229 -0
  60. package/dist/backfill/index.js.map +1 -0
  61. package/dist/bootstrap.d.ts +2 -1
  62. package/dist/bootstrap.d.ts.map +1 -1
  63. package/dist/bootstrap.js +367 -0
  64. package/dist/bootstrap.js.map +1 -0
  65. package/dist/caamp/adapter.js +434 -0
  66. package/dist/caamp/adapter.js.map +1 -0
  67. package/dist/caamp/capability-check.js +38 -0
  68. package/dist/caamp/capability-check.js.map +1 -0
  69. package/dist/caamp/index.js +23 -0
  70. package/dist/caamp/index.js.map +1 -0
  71. package/dist/caamp-init.js +16 -0
  72. package/dist/caamp-init.js.map +1 -0
  73. package/dist/cleo.d.ts +40 -0
  74. package/dist/cleo.d.ts.map +1 -1
  75. package/dist/cleo.js +267 -0
  76. package/dist/cleo.js.map +1 -0
  77. package/dist/codebase-map/analyzers/architecture.js +130 -0
  78. package/dist/codebase-map/analyzers/architecture.js.map +1 -0
  79. package/dist/codebase-map/analyzers/concerns.js +122 -0
  80. package/dist/codebase-map/analyzers/concerns.js.map +1 -0
  81. package/dist/codebase-map/analyzers/conventions.js +149 -0
  82. package/dist/codebase-map/analyzers/conventions.js.map +1 -0
  83. package/dist/codebase-map/analyzers/integrations.js +108 -0
  84. package/dist/codebase-map/analyzers/integrations.js.map +1 -0
  85. package/dist/codebase-map/analyzers/stack.js +117 -0
  86. package/dist/codebase-map/analyzers/stack.js.map +1 -0
  87. package/dist/codebase-map/analyzers/structure.js +137 -0
  88. package/dist/codebase-map/analyzers/structure.js.map +1 -0
  89. package/dist/codebase-map/analyzers/testing.js +118 -0
  90. package/dist/codebase-map/analyzers/testing.js.map +1 -0
  91. package/dist/codebase-map/index.js +57 -0
  92. package/dist/codebase-map/index.js.map +1 -0
  93. package/dist/codebase-map/store.js +122 -0
  94. package/dist/codebase-map/store.js.map +1 -0
  95. package/dist/codebase-map/summary.js +152 -0
  96. package/dist/codebase-map/summary.js.map +1 -0
  97. package/dist/compliance/index.js +288 -0
  98. package/dist/compliance/index.js.map +1 -0
  99. package/dist/compliance/protocol-enforcement.js +332 -0
  100. package/dist/compliance/protocol-enforcement.js.map +1 -0
  101. package/dist/compliance/protocol-rules.js +786 -0
  102. package/dist/compliance/protocol-rules.js.map +1 -0
  103. package/dist/compliance/protocol-types.js +80 -0
  104. package/dist/compliance/protocol-types.js.map +1 -0
  105. package/dist/compliance/store.js +53 -0
  106. package/dist/compliance/store.js.map +1 -0
  107. package/dist/config/build-config.js +29 -0
  108. package/dist/config/build-config.js.map +1 -0
  109. package/dist/config.js +370 -0
  110. package/dist/config.js.map +1 -0
  111. package/dist/constants.js +18 -0
  112. package/dist/constants.js.map +1 -0
  113. package/dist/context/index.js +137 -0
  114. package/dist/context/index.js.map +1 -0
  115. package/dist/engine-result.js +12 -0
  116. package/dist/engine-result.js.map +1 -0
  117. package/dist/error-catalog.js +404 -0
  118. package/dist/error-catalog.js.map +1 -0
  119. package/dist/error-registry.js +393 -0
  120. package/dist/error-registry.js.map +1 -0
  121. package/dist/errors.js +167 -0
  122. package/dist/errors.js.map +1 -0
  123. package/dist/hooks/handlers/error-hooks.js +43 -0
  124. package/dist/hooks/handlers/error-hooks.js.map +1 -0
  125. package/dist/hooks/handlers/file-hooks.js +80 -0
  126. package/dist/hooks/handlers/file-hooks.js.map +1 -0
  127. package/dist/hooks/handlers/index.js +19 -0
  128. package/dist/hooks/handlers/index.js.map +1 -0
  129. package/dist/hooks/handlers/mcp-hooks.js +80 -0
  130. package/dist/hooks/handlers/mcp-hooks.js.map +1 -0
  131. package/dist/hooks/handlers/session-hooks.js +73 -0
  132. package/dist/hooks/handlers/session-hooks.js.map +1 -0
  133. package/dist/hooks/handlers/task-hooks.js +63 -0
  134. package/dist/hooks/handlers/task-hooks.js.map +1 -0
  135. package/dist/hooks/index.js +13 -0
  136. package/dist/hooks/index.js.map +1 -0
  137. package/dist/hooks/payload-schemas.js +163 -0
  138. package/dist/hooks/payload-schemas.js.map +1 -0
  139. package/dist/hooks/provider-hooks.js +34 -0
  140. package/dist/hooks/provider-hooks.js.map +1 -0
  141. package/dist/hooks/registry.js +176 -0
  142. package/dist/hooks/registry.js.map +1 -0
  143. package/dist/hooks/types.js +62 -0
  144. package/dist/hooks/types.js.map +1 -0
  145. package/dist/hooks.js +136 -0
  146. package/dist/hooks.js.map +1 -0
  147. package/dist/index.js +193 -35
  148. package/dist/index.js.map +3 -3
  149. package/dist/init.js +711 -0
  150. package/dist/init.js.map +1 -0
  151. package/dist/inject/index.js +82 -0
  152. package/dist/inject/index.js.map +1 -0
  153. package/dist/injection.js +343 -0
  154. package/dist/injection.js.map +1 -0
  155. package/dist/intelligence/adaptive-validation.js +497 -0
  156. package/dist/intelligence/adaptive-validation.js.map +1 -0
  157. package/dist/intelligence/impact.js +675 -0
  158. package/dist/intelligence/impact.js.map +1 -0
  159. package/dist/intelligence/index.js +22 -0
  160. package/dist/intelligence/index.js.map +1 -0
  161. package/dist/intelligence/patterns.js +492 -0
  162. package/dist/intelligence/patterns.js.map +1 -0
  163. package/dist/intelligence/prediction.js +499 -0
  164. package/dist/intelligence/prediction.js.map +1 -0
  165. package/dist/intelligence/types.js +13 -0
  166. package/dist/intelligence/types.js.map +1 -0
  167. package/dist/internal.d.ts +1 -0
  168. package/dist/internal.d.ts.map +1 -1
  169. package/dist/internal.js +267 -0
  170. package/dist/internal.js.map +1 -0
  171. package/dist/issue/create.js +121 -0
  172. package/dist/issue/create.js.map +1 -0
  173. package/dist/issue/diagnostics.js +59 -0
  174. package/dist/issue/diagnostics.js.map +1 -0
  175. package/dist/issue/index.js +10 -0
  176. package/dist/issue/index.js.map +1 -0
  177. package/dist/issue/template-parser.js +267 -0
  178. package/dist/issue/template-parser.js.map +1 -0
  179. package/dist/json-schema-validator.js +76 -0
  180. package/dist/json-schema-validator.js.map +1 -0
  181. package/dist/lib/index.js +10 -0
  182. package/dist/lib/index.js.map +1 -0
  183. package/dist/lib/retry.js +152 -0
  184. package/dist/lib/retry.js.map +1 -0
  185. package/dist/lifecycle/chain-composition.js +152 -0
  186. package/dist/lifecycle/chain-composition.js.map +1 -0
  187. package/dist/lifecycle/chain-store.js +246 -0
  188. package/dist/lifecycle/chain-store.js.map +1 -0
  189. package/dist/lifecycle/consolidate-rcasd.js +352 -0
  190. package/dist/lifecycle/consolidate-rcasd.js.map +1 -0
  191. package/dist/lifecycle/default-chain.js +167 -0
  192. package/dist/lifecycle/default-chain.js.map +1 -0
  193. package/dist/lifecycle/evidence.js +180 -0
  194. package/dist/lifecycle/evidence.js.map +1 -0
  195. package/dist/lifecycle/frontmatter.js +363 -0
  196. package/dist/lifecycle/frontmatter.js.map +1 -0
  197. package/dist/lifecycle/index.js +753 -0
  198. package/dist/lifecycle/index.js.map +1 -0
  199. package/dist/lifecycle/pipeline.js +656 -0
  200. package/dist/lifecycle/pipeline.js.map +1 -0
  201. package/dist/lifecycle/rcasd-index.js +326 -0
  202. package/dist/lifecycle/rcasd-index.js.map +1 -0
  203. package/dist/lifecycle/rcasd-paths.js +220 -0
  204. package/dist/lifecycle/rcasd-paths.js.map +1 -0
  205. package/dist/lifecycle/resume.js +864 -0
  206. package/dist/lifecycle/resume.js.map +1 -0
  207. package/dist/lifecycle/stage-artifacts.js +94 -0
  208. package/dist/lifecycle/stage-artifacts.js.map +1 -0
  209. package/dist/lifecycle/stages.js +534 -0
  210. package/dist/lifecycle/stages.js.map +1 -0
  211. package/dist/lifecycle/state-machine.js +516 -0
  212. package/dist/lifecycle/state-machine.js.map +1 -0
  213. package/dist/lifecycle/tessera-engine.js +249 -0
  214. package/dist/lifecycle/tessera-engine.js.map +1 -0
  215. package/dist/logger.js +140 -0
  216. package/dist/logger.js.map +1 -0
  217. package/dist/mcp/index.js +146 -0
  218. package/dist/mcp/index.js.map +1 -0
  219. package/dist/memory/auto-extract.js +143 -0
  220. package/dist/memory/auto-extract.js.map +1 -0
  221. package/dist/memory/brain-embedding.js +49 -0
  222. package/dist/memory/brain-embedding.js.map +1 -0
  223. package/dist/memory/brain-lifecycle.js +298 -0
  224. package/dist/memory/brain-lifecycle.js.map +1 -0
  225. package/dist/memory/brain-links.js +148 -0
  226. package/dist/memory/brain-links.js.map +1 -0
  227. package/dist/memory/brain-migration.js +149 -0
  228. package/dist/memory/brain-migration.js.map +1 -0
  229. package/dist/memory/brain-reasoning.js +215 -0
  230. package/dist/memory/brain-reasoning.js.map +1 -0
  231. package/dist/memory/brain-retrieval.js +474 -0
  232. package/dist/memory/brain-retrieval.js.map +1 -0
  233. package/dist/memory/brain-row-types.js +10 -0
  234. package/dist/memory/brain-row-types.js.map +1 -0
  235. package/dist/memory/brain-search.js +519 -0
  236. package/dist/memory/brain-search.js.map +1 -0
  237. package/dist/memory/brain-similarity.js +145 -0
  238. package/dist/memory/brain-similarity.js.map +1 -0
  239. package/dist/memory/claude-mem-migration.js +277 -0
  240. package/dist/memory/claude-mem-migration.js.map +1 -0
  241. package/dist/memory/decisions.js +148 -0
  242. package/dist/memory/decisions.js.map +1 -0
  243. package/dist/memory/engine-compat.js +1030 -0
  244. package/dist/memory/engine-compat.js.map +1 -0
  245. package/dist/memory/index.js +773 -0
  246. package/dist/memory/index.js.map +1 -0
  247. package/dist/memory/learnings.js +121 -0
  248. package/dist/memory/learnings.js.map +1 -0
  249. package/dist/memory/memory-bridge.js +289 -0
  250. package/dist/memory/memory-bridge.js.map +1 -0
  251. package/dist/memory/patterns.js +122 -0
  252. package/dist/memory/patterns.js.map +1 -0
  253. package/dist/memory/pipeline-manifest-sqlite.js +975 -0
  254. package/dist/memory/pipeline-manifest-sqlite.js.map +1 -0
  255. package/dist/memory/session-memory.js +226 -0
  256. package/dist/memory/session-memory.js.map +1 -0
  257. package/dist/metrics/ab-test.js +260 -0
  258. package/dist/metrics/ab-test.js.map +1 -0
  259. package/dist/metrics/aggregation.js +363 -0
  260. package/dist/metrics/aggregation.js.map +1 -0
  261. package/dist/metrics/common.js +64 -0
  262. package/dist/metrics/common.js.map +1 -0
  263. package/dist/metrics/enums.js +78 -0
  264. package/dist/metrics/enums.js.map +1 -0
  265. package/dist/metrics/index.js +19 -0
  266. package/dist/metrics/index.js.map +1 -0
  267. package/dist/metrics/model-provider-registry.js +88 -0
  268. package/dist/metrics/model-provider-registry.js.map +1 -0
  269. package/dist/metrics/otel-integration.js +263 -0
  270. package/dist/metrics/otel-integration.js.map +1 -0
  271. package/dist/metrics/provider-detection.js +103 -0
  272. package/dist/metrics/provider-detection.js.map +1 -0
  273. package/dist/metrics/token-estimation.js +253 -0
  274. package/dist/metrics/token-estimation.js.map +1 -0
  275. package/dist/metrics/token-service.js +450 -0
  276. package/dist/metrics/token-service.js.map +1 -0
  277. package/dist/migration/agent-outputs.js +316 -0
  278. package/dist/migration/agent-outputs.js.map +1 -0
  279. package/dist/migration/checksum.js +92 -0
  280. package/dist/migration/checksum.js.map +1 -0
  281. package/dist/migration/index.js +282 -0
  282. package/dist/migration/index.js.map +1 -0
  283. package/dist/migration/logger.js +360 -0
  284. package/dist/migration/logger.js.map +1 -0
  285. package/dist/migration/preflight.js +9 -0
  286. package/dist/migration/preflight.js.map +1 -0
  287. package/dist/migration/state.js +421 -0
  288. package/dist/migration/state.js.map +1 -0
  289. package/dist/migration/validate.js +241 -0
  290. package/dist/migration/validate.js.map +1 -0
  291. package/dist/nexus/deps.js +375 -0
  292. package/dist/nexus/deps.js.map +1 -0
  293. package/dist/nexus/discover.js +288 -0
  294. package/dist/nexus/discover.js.map +1 -0
  295. package/dist/nexus/hash.js +10 -0
  296. package/dist/nexus/hash.js.map +1 -0
  297. package/dist/nexus/index.js +38 -0
  298. package/dist/nexus/index.js.map +1 -0
  299. package/dist/nexus/migrate-json-to-sqlite.js +115 -0
  300. package/dist/nexus/migrate-json-to-sqlite.js.map +1 -0
  301. package/dist/nexus/permissions.js +105 -0
  302. package/dist/nexus/permissions.js.map +1 -0
  303. package/dist/nexus/query.js +175 -0
  304. package/dist/nexus/query.js.map +1 -0
  305. package/dist/nexus/registry.js +584 -0
  306. package/dist/nexus/registry.js.map +1 -0
  307. package/dist/nexus/sharing/index.js +288 -0
  308. package/dist/nexus/sharing/index.js.map +1 -0
  309. package/dist/nexus/transfer-types.js +8 -0
  310. package/dist/nexus/transfer-types.js.map +1 -0
  311. package/dist/nexus/transfer.js +263 -0
  312. package/dist/nexus/transfer.js.map +1 -0
  313. package/dist/observability/index.js +103 -0
  314. package/dist/observability/index.js.map +1 -0
  315. package/dist/observability/log-filter.js +63 -0
  316. package/dist/observability/log-filter.js.map +1 -0
  317. package/dist/observability/log-parser.js +99 -0
  318. package/dist/observability/log-parser.js.map +1 -0
  319. package/dist/observability/log-reader.js +139 -0
  320. package/dist/observability/log-reader.js.map +1 -0
  321. package/dist/observability/types.js +19 -0
  322. package/dist/observability/types.js.map +1 -0
  323. package/dist/orchestration/analyze.js +107 -0
  324. package/dist/orchestration/analyze.js.map +1 -0
  325. package/dist/orchestration/bootstrap.js +132 -0
  326. package/dist/orchestration/bootstrap.js.map +1 -0
  327. package/dist/orchestration/context.js +56 -0
  328. package/dist/orchestration/context.js.map +1 -0
  329. package/dist/orchestration/critical-path.js +100 -0
  330. package/dist/orchestration/critical-path.js.map +1 -0
  331. package/dist/orchestration/index.js +286 -0
  332. package/dist/orchestration/index.js.map +1 -0
  333. package/dist/orchestration/parallel.js +89 -0
  334. package/dist/orchestration/parallel.js.map +1 -0
  335. package/dist/orchestration/protocol-validators.js +524 -0
  336. package/dist/orchestration/protocol-validators.js.map +1 -0
  337. package/dist/orchestration/skill-ops.js +98 -0
  338. package/dist/orchestration/skill-ops.js.map +1 -0
  339. package/dist/orchestration/status.js +107 -0
  340. package/dist/orchestration/status.js.map +1 -0
  341. package/dist/orchestration/unblock.js +103 -0
  342. package/dist/orchestration/unblock.js.map +1 -0
  343. package/dist/orchestration/validate-spawn.js +67 -0
  344. package/dist/orchestration/validate-spawn.js.map +1 -0
  345. package/dist/orchestration/waves.js +86 -0
  346. package/dist/orchestration/waves.js.map +1 -0
  347. package/dist/otel/index.js +163 -0
  348. package/dist/otel/index.js.map +1 -0
  349. package/dist/output.js +132 -0
  350. package/dist/output.js.map +1 -0
  351. package/dist/pagination.js +61 -0
  352. package/dist/pagination.js.map +1 -0
  353. package/dist/paths.js +337 -0
  354. package/dist/paths.js.map +1 -0
  355. package/dist/phases/deps.js +369 -0
  356. package/dist/phases/deps.js.map +1 -0
  357. package/dist/phases/index.js +349 -0
  358. package/dist/phases/index.js.map +1 -0
  359. package/dist/pipeline/index.js +10 -0
  360. package/dist/pipeline/index.js.map +1 -0
  361. package/dist/pipeline/phase.js +45 -0
  362. package/dist/pipeline/phase.js.map +1 -0
  363. package/dist/platform.js +211 -0
  364. package/dist/platform.js.map +1 -0
  365. package/dist/project-info.js +84 -0
  366. package/dist/project-info.js.map +1 -0
  367. package/dist/reconciliation/index.js +10 -0
  368. package/dist/reconciliation/index.js.map +1 -0
  369. package/dist/reconciliation/link-store.js +129 -0
  370. package/dist/reconciliation/link-store.js.map +1 -0
  371. package/dist/reconciliation/reconciliation-engine.js +298 -0
  372. package/dist/reconciliation/reconciliation-engine.js.map +1 -0
  373. package/dist/release/artifacts.js +427 -0
  374. package/dist/release/artifacts.js.map +1 -0
  375. package/dist/release/changelog-writer.js +151 -0
  376. package/dist/release/changelog-writer.js.map +1 -0
  377. package/dist/release/channel.js +144 -0
  378. package/dist/release/channel.js.map +1 -0
  379. package/dist/release/ci.js +166 -0
  380. package/dist/release/ci.js.map +1 -0
  381. package/dist/release/github-pr.js +225 -0
  382. package/dist/release/github-pr.js.map +1 -0
  383. package/dist/release/guards.js +116 -0
  384. package/dist/release/guards.js.map +1 -0
  385. package/dist/release/index.js +22 -0
  386. package/dist/release/index.js.map +1 -0
  387. package/dist/release/release-config.js +158 -0
  388. package/dist/release/release-config.js.map +1 -0
  389. package/dist/release/release-manifest.js +1019 -0
  390. package/dist/release/release-manifest.js.map +1 -0
  391. package/dist/release/version-bump.js +255 -0
  392. package/dist/release/version-bump.js.map +1 -0
  393. package/dist/remote/index.js +257 -0
  394. package/dist/remote/index.js.map +1 -0
  395. package/dist/repair.d.ts +7 -0
  396. package/dist/repair.d.ts.map +1 -1
  397. package/dist/repair.js +89 -0
  398. package/dist/repair.js.map +1 -0
  399. package/dist/research/index.js +2 -0
  400. package/dist/research/index.js.map +1 -0
  401. package/dist/roadmap/index.js +59 -0
  402. package/dist/roadmap/index.js.map +1 -0
  403. package/dist/routing/capability-matrix.js +1550 -0
  404. package/dist/routing/capability-matrix.js.map +1 -0
  405. package/dist/routing/index.js +9 -0
  406. package/dist/routing/index.js.map +1 -0
  407. package/dist/scaffold.d.ts.map +1 -1
  408. package/dist/scaffold.js +1178 -0
  409. package/dist/scaffold.js.map +1 -0
  410. package/dist/schema-management.js +295 -0
  411. package/dist/schema-management.js.map +1 -0
  412. package/dist/security/index.js +9 -0
  413. package/dist/security/index.js.map +1 -0
  414. package/dist/security/input-sanitization.js +321 -0
  415. package/dist/security/input-sanitization.js.map +1 -0
  416. package/dist/sequence/index.js +295 -0
  417. package/dist/sequence/index.js.map +1 -0
  418. package/dist/sessions/assumptions.js +54 -0
  419. package/dist/sessions/assumptions.js.map +1 -0
  420. package/dist/sessions/briefing.js +377 -0
  421. package/dist/sessions/briefing.js.map +1 -0
  422. package/dist/sessions/context-alert.js +222 -0
  423. package/dist/sessions/context-alert.js.map +1 -0
  424. package/dist/sessions/context-inject.js +61 -0
  425. package/dist/sessions/context-inject.js.map +1 -0
  426. package/dist/sessions/context-monitor.js +98 -0
  427. package/dist/sessions/context-monitor.js.map +1 -0
  428. package/dist/sessions/decisions.js +65 -0
  429. package/dist/sessions/decisions.js.map +1 -0
  430. package/dist/sessions/find.js +63 -0
  431. package/dist/sessions/find.js.map +1 -0
  432. package/dist/sessions/handoff.js +328 -0
  433. package/dist/sessions/handoff.js.map +1 -0
  434. package/dist/sessions/hitl-warnings.js +254 -0
  435. package/dist/sessions/hitl-warnings.js.map +1 -0
  436. package/dist/sessions/index.js +318 -0
  437. package/dist/sessions/index.js.map +1 -0
  438. package/dist/sessions/session-archive.js +40 -0
  439. package/dist/sessions/session-archive.js.map +1 -0
  440. package/dist/sessions/session-cleanup.js +59 -0
  441. package/dist/sessions/session-cleanup.js.map +1 -0
  442. package/dist/sessions/session-drift.js +134 -0
  443. package/dist/sessions/session-drift.js.map +1 -0
  444. package/dist/sessions/session-enforcement.js +144 -0
  445. package/dist/sessions/session-enforcement.js.map +1 -0
  446. package/dist/sessions/session-grade.js +253 -0
  447. package/dist/sessions/session-grade.js.map +1 -0
  448. package/dist/sessions/session-history.js +42 -0
  449. package/dist/sessions/session-history.js.map +1 -0
  450. package/dist/sessions/session-id.js +81 -0
  451. package/dist/sessions/session-id.js.map +1 -0
  452. package/dist/sessions/session-memory-bridge.js +52 -0
  453. package/dist/sessions/session-memory-bridge.js.map +1 -0
  454. package/dist/sessions/session-show.js +24 -0
  455. package/dist/sessions/session-show.js.map +1 -0
  456. package/dist/sessions/session-stats.js +69 -0
  457. package/dist/sessions/session-stats.js.map +1 -0
  458. package/dist/sessions/session-suspend.js +39 -0
  459. package/dist/sessions/session-suspend.js.map +1 -0
  460. package/dist/sessions/session-switch.js +51 -0
  461. package/dist/sessions/session-switch.js.map +1 -0
  462. package/dist/sessions/session-view.js +76 -0
  463. package/dist/sessions/session-view.js.map +1 -0
  464. package/dist/sessions/statusline-setup.js +85 -0
  465. package/dist/sessions/statusline-setup.js.map +1 -0
  466. package/dist/sessions/types.js +8 -0
  467. package/dist/sessions/types.js.map +1 -0
  468. package/dist/signaldock/claude-code-transport.js +107 -0
  469. package/dist/signaldock/claude-code-transport.js.map +1 -0
  470. package/dist/signaldock/factory.js +25 -0
  471. package/dist/signaldock/factory.js.map +1 -0
  472. package/dist/signaldock/index.js +9 -0
  473. package/dist/signaldock/index.js.map +1 -0
  474. package/dist/signaldock/signaldock-transport.js +122 -0
  475. package/dist/signaldock/signaldock-transport.js.map +1 -0
  476. package/dist/signaldock/transport.js +11 -0
  477. package/dist/signaldock/transport.js.map +1 -0
  478. package/dist/signaldock/types.js +11 -0
  479. package/dist/signaldock/types.js.map +1 -0
  480. package/dist/skills/agents/config.js +94 -0
  481. package/dist/skills/agents/config.js.map +1 -0
  482. package/dist/skills/agents/install.js +116 -0
  483. package/dist/skills/agents/install.js.map +1 -0
  484. package/dist/skills/agents/registry.js +161 -0
  485. package/dist/skills/agents/registry.js.map +1 -0
  486. package/dist/skills/discovery.js +333 -0
  487. package/dist/skills/discovery.js.map +1 -0
  488. package/dist/skills/dispatch.js +347 -0
  489. package/dist/skills/dispatch.js.map +1 -0
  490. package/dist/skills/dynamic-skill-generator.js +100 -0
  491. package/dist/skills/dynamic-skill-generator.js.map +1 -0
  492. package/dist/skills/index.js +44 -0
  493. package/dist/skills/index.js.map +1 -0
  494. package/dist/skills/injection/subagent.js +195 -0
  495. package/dist/skills/injection/subagent.js.map +1 -0
  496. package/dist/skills/injection/token.js +260 -0
  497. package/dist/skills/injection/token.js.map +1 -0
  498. package/dist/skills/install.js +40 -0
  499. package/dist/skills/install.js.map +1 -0
  500. package/dist/skills/manifests/contribution.js +175 -0
  501. package/dist/skills/manifests/contribution.js.map +1 -0
  502. package/dist/skills/manifests/research.js +281 -0
  503. package/dist/skills/manifests/research.js.map +1 -0
  504. package/dist/skills/manifests/resolver.js +146 -0
  505. package/dist/skills/manifests/resolver.js.map +1 -0
  506. package/dist/skills/marketplace.js +90 -0
  507. package/dist/skills/marketplace.js.map +1 -0
  508. package/dist/skills/orchestrator/spawn.js +178 -0
  509. package/dist/skills/orchestrator/spawn.js.map +1 -0
  510. package/dist/skills/orchestrator/startup.js +451 -0
  511. package/dist/skills/orchestrator/startup.js.map +1 -0
  512. package/dist/skills/orchestrator/validator.js +301 -0
  513. package/dist/skills/orchestrator/validator.js.map +1 -0
  514. package/dist/skills/precedence-integration.js +73 -0
  515. package/dist/skills/precedence-integration.js.map +1 -0
  516. package/dist/skills/precedence-types.js +16 -0
  517. package/dist/skills/precedence-types.js.map +1 -0
  518. package/dist/skills/routing-table.js +63 -0
  519. package/dist/skills/routing-table.js.map +1 -0
  520. package/dist/skills/skill-paths.js +220 -0
  521. package/dist/skills/skill-paths.js.map +1 -0
  522. package/dist/skills/test-utility.js +55 -0
  523. package/dist/skills/test-utility.js.map +1 -0
  524. package/dist/skills/types.js +118 -0
  525. package/dist/skills/types.js.map +1 -0
  526. package/dist/skills/validation.js +183 -0
  527. package/dist/skills/validation.js.map +1 -0
  528. package/dist/skills/version.js +57 -0
  529. package/dist/skills/version.js.map +1 -0
  530. package/dist/snapshot/index.js +188 -0
  531. package/dist/snapshot/index.js.map +1 -0
  532. package/dist/spawn/adapter-registry.js +246 -0
  533. package/dist/spawn/adapter-registry.js.map +1 -0
  534. package/dist/spawn/index.js +10 -0
  535. package/dist/spawn/index.js.map +1 -0
  536. package/dist/stats/index.js +341 -0
  537. package/dist/stats/index.js.map +1 -0
  538. package/dist/stats/workflow-telemetry.js +400 -0
  539. package/dist/stats/workflow-telemetry.js.map +1 -0
  540. package/dist/sticky/archive.js +47 -0
  541. package/dist/sticky/archive.js.map +1 -0
  542. package/dist/sticky/convert.js +235 -0
  543. package/dist/sticky/convert.js.map +1 -0
  544. package/dist/sticky/create.js +48 -0
  545. package/dist/sticky/create.js.map +1 -0
  546. package/dist/sticky/id.js +35 -0
  547. package/dist/sticky/id.js.map +1 -0
  548. package/dist/sticky/index.js +16 -0
  549. package/dist/sticky/index.js.map +1 -0
  550. package/dist/sticky/list.js +44 -0
  551. package/dist/sticky/list.js.map +1 -0
  552. package/dist/sticky/purge.js +45 -0
  553. package/dist/sticky/purge.js.map +1 -0
  554. package/dist/sticky/show.js +42 -0
  555. package/dist/sticky/show.js.map +1 -0
  556. package/dist/sticky/types.js +10 -0
  557. package/dist/sticky/types.js.map +1 -0
  558. package/dist/store/atomic.js +167 -0
  559. package/dist/store/atomic.js.map +1 -0
  560. package/dist/store/backup.js +94 -0
  561. package/dist/store/backup.js.map +1 -0
  562. package/dist/store/brain-accessor.js +397 -0
  563. package/dist/store/brain-accessor.js.map +1 -0
  564. package/dist/store/brain-schema.js +215 -0
  565. package/dist/store/brain-schema.js.map +1 -0
  566. package/dist/store/brain-sqlite.js +271 -0
  567. package/dist/store/brain-sqlite.js.map +1 -0
  568. package/dist/store/cache.js +168 -0
  569. package/dist/store/cache.js.map +1 -0
  570. package/dist/store/chain-schema.js +51 -0
  571. package/dist/store/chain-schema.js.map +1 -0
  572. package/dist/store/converters.js +122 -0
  573. package/dist/store/converters.js.map +1 -0
  574. package/dist/store/cross-db-cleanup.js +169 -0
  575. package/dist/store/cross-db-cleanup.js.map +1 -0
  576. package/dist/store/data-accessor.js +26 -0
  577. package/dist/store/data-accessor.js.map +1 -0
  578. package/dist/store/data-safety-central.js +269 -0
  579. package/dist/store/data-safety-central.js.map +1 -0
  580. package/dist/store/data-safety.js +274 -0
  581. package/dist/store/data-safety.js.map +1 -0
  582. package/dist/store/db-helpers.js +223 -0
  583. package/dist/store/db-helpers.js.map +1 -0
  584. package/dist/store/export.js +155 -0
  585. package/dist/store/export.js.map +1 -0
  586. package/dist/store/file-utils.js +270 -0
  587. package/dist/store/file-utils.js.map +1 -0
  588. package/dist/store/git-checkpoint.js +365 -0
  589. package/dist/store/git-checkpoint.js.map +1 -0
  590. package/dist/store/import-logging.js +139 -0
  591. package/dist/store/import-logging.js.map +1 -0
  592. package/dist/store/import-remap.js +145 -0
  593. package/dist/store/import-remap.js.map +1 -0
  594. package/dist/store/import-sort.js +121 -0
  595. package/dist/store/import-sort.js.map +1 -0
  596. package/dist/store/index.js +28 -0
  597. package/dist/store/index.js.map +1 -0
  598. package/dist/store/json.js +208 -0
  599. package/dist/store/json.js.map +1 -0
  600. package/dist/store/lifecycle-store.js +249 -0
  601. package/dist/store/lifecycle-store.js.map +1 -0
  602. package/dist/store/lock.js +70 -0
  603. package/dist/store/lock.js.map +1 -0
  604. package/dist/store/migration-sqlite.js +676 -0
  605. package/dist/store/migration-sqlite.js.map +1 -0
  606. package/dist/store/nexus-schema.js +62 -0
  607. package/dist/store/nexus-schema.js.map +1 -0
  608. package/dist/store/nexus-sqlite.js +217 -0
  609. package/dist/store/nexus-sqlite.js.map +1 -0
  610. package/dist/store/nexus-validation-schemas.js +40 -0
  611. package/dist/store/nexus-validation-schemas.js.map +1 -0
  612. package/dist/store/parsers.js +37 -0
  613. package/dist/store/parsers.js.map +1 -0
  614. package/dist/store/project-detect.js +457 -0
  615. package/dist/store/project-detect.js.map +1 -0
  616. package/dist/store/provider.js +101 -0
  617. package/dist/store/provider.js.map +1 -0
  618. package/dist/store/safety-data-accessor.js +243 -0
  619. package/dist/store/safety-data-accessor.js.map +1 -0
  620. package/dist/store/schema.js +7 -0
  621. package/dist/store/schema.js.map +1 -0
  622. package/dist/store/session-store.js +219 -0
  623. package/dist/store/session-store.js.map +1 -0
  624. package/dist/store/sqlite-backup.js +105 -0
  625. package/dist/store/sqlite-backup.js.map +1 -0
  626. package/dist/store/sqlite-data-accessor.js +734 -0
  627. package/dist/store/sqlite-data-accessor.js.map +1 -0
  628. package/dist/store/sqlite.d.ts.map +1 -1
  629. package/dist/store/sqlite.js +500 -0
  630. package/dist/store/sqlite.js.map +1 -0
  631. package/dist/store/status-registry.js +8 -0
  632. package/dist/store/status-registry.js.map +1 -0
  633. package/dist/store/task-store.js +348 -0
  634. package/dist/store/task-store.js.map +1 -0
  635. package/dist/store/tasks-schema.js +604 -0
  636. package/dist/store/tasks-schema.js.map +1 -0
  637. package/dist/store/typed-query.js +15 -0
  638. package/dist/store/typed-query.js.map +1 -0
  639. package/dist/store/validation-schemas.js +278 -0
  640. package/dist/store/validation-schemas.js.map +1 -0
  641. package/dist/system/archive-analytics.js +277 -0
  642. package/dist/system/archive-analytics.js.map +1 -0
  643. package/dist/system/archive-stats.js +64 -0
  644. package/dist/system/archive-stats.js.map +1 -0
  645. package/dist/system/audit.js +145 -0
  646. package/dist/system/audit.js.map +1 -0
  647. package/dist/system/backup.js +99 -0
  648. package/dist/system/backup.js.map +1 -0
  649. package/dist/system/cleanup.js +134 -0
  650. package/dist/system/cleanup.js.map +1 -0
  651. package/dist/system/health.js +1054 -0
  652. package/dist/system/health.js.map +1 -0
  653. package/dist/system/index.js +18 -0
  654. package/dist/system/index.js.map +1 -0
  655. package/dist/system/inject-generate.js +122 -0
  656. package/dist/system/inject-generate.js.map +1 -0
  657. package/dist/system/labels.js +38 -0
  658. package/dist/system/labels.js.map +1 -0
  659. package/dist/system/metrics.js +61 -0
  660. package/dist/system/metrics.js.map +1 -0
  661. package/dist/system/migrate.js +43 -0
  662. package/dist/system/migrate.js.map +1 -0
  663. package/dist/system/platform-paths.js +80 -0
  664. package/dist/system/platform-paths.js.map +1 -0
  665. package/dist/system/runtime.js +161 -0
  666. package/dist/system/runtime.js.map +1 -0
  667. package/dist/system/safestop.js +99 -0
  668. package/dist/system/safestop.js.map +1 -0
  669. package/dist/system/storage-preflight.js +123 -0
  670. package/dist/system/storage-preflight.js.map +1 -0
  671. package/dist/task-work/index.js +155 -0
  672. package/dist/task-work/index.js.map +1 -0
  673. package/dist/tasks/add.js +594 -0
  674. package/dist/tasks/add.js.map +1 -0
  675. package/dist/tasks/analyze.js +85 -0
  676. package/dist/tasks/analyze.js.map +1 -0
  677. package/dist/tasks/archive.js +90 -0
  678. package/dist/tasks/archive.js.map +1 -0
  679. package/dist/tasks/atomicity.js +83 -0
  680. package/dist/tasks/atomicity.js.map +1 -0
  681. package/dist/tasks/cancel-ops.js +83 -0
  682. package/dist/tasks/cancel-ops.js.map +1 -0
  683. package/dist/tasks/complete.js +235 -0
  684. package/dist/tasks/complete.js.map +1 -0
  685. package/dist/tasks/crossref-extract.js +73 -0
  686. package/dist/tasks/crossref-extract.js.map +1 -0
  687. package/dist/tasks/delete-preview.js +192 -0
  688. package/dist/tasks/delete-preview.js.map +1 -0
  689. package/dist/tasks/delete.js +120 -0
  690. package/dist/tasks/delete.js.map +1 -0
  691. package/dist/tasks/deletion-strategy.js +200 -0
  692. package/dist/tasks/deletion-strategy.js.map +1 -0
  693. package/dist/tasks/dependency-check.js +278 -0
  694. package/dist/tasks/dependency-check.js.map +1 -0
  695. package/dist/tasks/deps-ready.js +32 -0
  696. package/dist/tasks/deps-ready.js.map +1 -0
  697. package/dist/tasks/enforcement.js +89 -0
  698. package/dist/tasks/enforcement.js.map +1 -0
  699. package/dist/tasks/epic-enforcement.js +294 -0
  700. package/dist/tasks/epic-enforcement.js.map +1 -0
  701. package/dist/tasks/find.js +148 -0
  702. package/dist/tasks/find.js.map +1 -0
  703. package/dist/tasks/graph-cache.js +127 -0
  704. package/dist/tasks/graph-cache.js.map +1 -0
  705. package/dist/tasks/graph-ops.js +171 -0
  706. package/dist/tasks/graph-ops.js.map +1 -0
  707. package/dist/tasks/graph-rag.js +328 -0
  708. package/dist/tasks/graph-rag.js.map +1 -0
  709. package/dist/tasks/hierarchy-policy.js +149 -0
  710. package/dist/tasks/hierarchy-policy.js.map +1 -0
  711. package/dist/tasks/hierarchy.js +185 -0
  712. package/dist/tasks/hierarchy.js.map +1 -0
  713. package/dist/tasks/id-generator.js +65 -0
  714. package/dist/tasks/id-generator.js.map +1 -0
  715. package/dist/tasks/index.js +14 -0
  716. package/dist/tasks/index.js.map +1 -0
  717. package/dist/tasks/labels.js +52 -0
  718. package/dist/tasks/labels.js.map +1 -0
  719. package/dist/tasks/list.js +68 -0
  720. package/dist/tasks/list.js.map +1 -0
  721. package/dist/tasks/phase-tracking.js +133 -0
  722. package/dist/tasks/phase-tracking.js.map +1 -0
  723. package/dist/tasks/pipeline-stage.js +248 -0
  724. package/dist/tasks/pipeline-stage.js.map +1 -0
  725. package/dist/tasks/plan.js +268 -0
  726. package/dist/tasks/plan.js.map +1 -0
  727. package/dist/tasks/relates.js +89 -0
  728. package/dist/tasks/relates.js.map +1 -0
  729. package/dist/tasks/reparent.d.ts +38 -0
  730. package/dist/tasks/reparent.d.ts.map +1 -0
  731. package/dist/tasks/show.js +78 -0
  732. package/dist/tasks/show.js.map +1 -0
  733. package/dist/tasks/size-weighting.js +86 -0
  734. package/dist/tasks/size-weighting.js.map +1 -0
  735. package/dist/tasks/staleness.js +86 -0
  736. package/dist/tasks/staleness.js.map +1 -0
  737. package/dist/tasks/task-ops.js +1340 -0
  738. package/dist/tasks/task-ops.js.map +1 -0
  739. package/dist/tasks/update.js +271 -0
  740. package/dist/tasks/update.js.map +1 -0
  741. package/dist/templates/index.js +10 -0
  742. package/dist/templates/index.js.map +1 -0
  743. package/dist/templates/parser.js +254 -0
  744. package/dist/templates/parser.js.map +1 -0
  745. package/dist/ui/aliases.js +153 -0
  746. package/dist/ui/aliases.js.map +1 -0
  747. package/dist/ui/changelog.js +184 -0
  748. package/dist/ui/changelog.js.map +1 -0
  749. package/dist/ui/command-registry.js +168 -0
  750. package/dist/ui/command-registry.js.map +1 -0
  751. package/dist/ui/flags.js +94 -0
  752. package/dist/ui/flags.js.map +1 -0
  753. package/dist/ui/index.js +24 -0
  754. package/dist/ui/index.js.map +1 -0
  755. package/dist/ui/injection-legacy.d.ts +26 -0
  756. package/dist/ui/injection-legacy.d.ts.map +1 -0
  757. package/dist/ui/injection-legacy.js +42 -0
  758. package/dist/ui/injection-legacy.js.map +1 -0
  759. package/dist/upgrade.js +901 -0
  760. package/dist/upgrade.js.map +1 -0
  761. package/dist/validation/chain-validation.js +146 -0
  762. package/dist/validation/chain-validation.js.map +1 -0
  763. package/dist/validation/compliance.js +155 -0
  764. package/dist/validation/compliance.js.map +1 -0
  765. package/dist/validation/docs-sync.js +212 -0
  766. package/dist/validation/docs-sync.js.map +1 -0
  767. package/dist/validation/doctor/checks.js +1069 -0
  768. package/dist/validation/doctor/checks.js.map +1 -0
  769. package/dist/validation/doctor/index.js +9 -0
  770. package/dist/validation/doctor/index.js.map +1 -0
  771. package/dist/validation/doctor/project-cache.js +160 -0
  772. package/dist/validation/doctor/project-cache.js.map +1 -0
  773. package/dist/validation/doctor/utils.js +155 -0
  774. package/dist/validation/doctor/utils.js.map +1 -0
  775. package/dist/validation/engine.js +902 -0
  776. package/dist/validation/engine.js.map +1 -0
  777. package/dist/validation/gap-check.js +175 -0
  778. package/dist/validation/gap-check.js.map +1 -0
  779. package/dist/validation/index.js +40 -0
  780. package/dist/validation/index.js.map +1 -0
  781. package/dist/validation/manifest.js +237 -0
  782. package/dist/validation/manifest.js.map +1 -0
  783. package/dist/validation/operation-gate-validators.js +724 -0
  784. package/dist/validation/operation-gate-validators.js.map +1 -0
  785. package/dist/validation/operation-verification-gates.js +532 -0
  786. package/dist/validation/operation-verification-gates.js.map +1 -0
  787. package/dist/validation/param-utils.js +139 -0
  788. package/dist/validation/param-utils.js.map +1 -0
  789. package/dist/validation/protocol-common.js +300 -0
  790. package/dist/validation/protocol-common.js.map +1 -0
  791. package/dist/validation/protocols/consensus.js +71 -0
  792. package/dist/validation/protocols/consensus.js.map +1 -0
  793. package/dist/validation/protocols/contribution.js +59 -0
  794. package/dist/validation/protocols/contribution.js.map +1 -0
  795. package/dist/validation/protocols/decomposition.js +59 -0
  796. package/dist/validation/protocols/decomposition.js.map +1 -0
  797. package/dist/validation/protocols/implementation.js +59 -0
  798. package/dist/validation/protocols/implementation.js.map +1 -0
  799. package/dist/validation/protocols/release-protocol.js +60 -0
  800. package/dist/validation/protocols/release-protocol.js.map +1 -0
  801. package/dist/validation/protocols/research.js +77 -0
  802. package/dist/validation/protocols/research.js.map +1 -0
  803. package/dist/validation/protocols/specification.js +84 -0
  804. package/dist/validation/protocols/specification.js.map +1 -0
  805. package/dist/validation/protocols/testing-protocol.js +70 -0
  806. package/dist/validation/protocols/testing-protocol.js.map +1 -0
  807. package/dist/validation/protocols/validation-protocol.js +70 -0
  808. package/dist/validation/protocols/validation-protocol.js.map +1 -0
  809. package/dist/validation/schema-integrity.js +170 -0
  810. package/dist/validation/schema-integrity.js.map +1 -0
  811. package/dist/validation/schema-validator.js +176 -0
  812. package/dist/validation/schema-validator.js.map +1 -0
  813. package/dist/validation/validate-ops.js +937 -0
  814. package/dist/validation/validate-ops.js.map +1 -0
  815. package/dist/validation/validation-rules.js +226 -0
  816. package/dist/validation/validation-rules.js.map +1 -0
  817. package/dist/validation/verification.js +321 -0
  818. package/dist/validation/verification.js.map +1 -0
  819. package/package.json +5 -5
  820. package/src/agents/__tests__/agent-registry.test.ts +1 -1
  821. package/src/bootstrap.ts +171 -30
  822. package/src/cleo.ts +103 -2
  823. package/src/internal.ts +1 -1
  824. package/src/repair.ts +53 -2
  825. package/src/scaffold.ts +24 -2
  826. package/src/store/sqlite.ts +72 -5
@@ -88,7 +88,7 @@ describe('Agent Registry (T041)', () => {
88
88
  .values({
89
89
  id: 'T-cap-001',
90
90
  title: 'Capacity test task',
91
- status: 'in_progress',
91
+ status: 'active',
92
92
  priority: 'medium',
93
93
  createdAt: new Date().toISOString(),
94
94
  })
package/src/bootstrap.ts CHANGED
@@ -41,7 +41,8 @@ export interface BootstrapOptions {
41
41
  * Bootstrap the global CLEO directory structure and install templates.
42
42
  *
43
43
  * Creates:
44
- * - ~/.cleo/templates/CLEO-INJECTION.md (from bundled template or injection content)
44
+ * - ~/.local/share/cleo/templates/CLEO-INJECTION.md (XDG primary)
45
+ * - ~/.cleo/templates/CLEO-INJECTION.md (legacy sync)
45
46
  * - ~/.agents/AGENTS.md with CAAMP injection block
46
47
  *
47
48
  * This is idempotent — safe to call multiple times.
@@ -60,7 +61,7 @@ export async function bootstrapGlobalCleo(options?: BootstrapOptions): Promise<B
60
61
  // Best-effort — don't fail bootstrap if cleanup fails
61
62
  }
62
63
 
63
- // Step 1: Ensure global templates
64
+ // Step 1: Ensure global templates (XDG + legacy sync)
64
65
  await ensureGlobalTemplatesBootstrap(ctx, options?.packageRoot);
65
66
 
66
67
  // Step 2: CAAMP injection into ~/.agents/AGENTS.md
@@ -78,11 +79,30 @@ export async function bootstrapGlobalCleo(options?: BootstrapOptions): Promise<B
78
79
  // Step 6: Install provider adapters
79
80
  await installProviderAdapters(ctx, options?.packageRoot);
80
81
 
82
+ // Step 7: Verify injection chain health
83
+ await verifyBootstrapHealth(ctx);
84
+
81
85
  return ctx;
82
86
  }
83
87
 
84
88
  // ── Step 1: Global templates ─────────────────────────────────────────
85
89
 
90
+ /**
91
+ * Write template content to a destination path, creating parent dirs as needed.
92
+ * Returns true if written, false if dry-run.
93
+ */
94
+ async function writeTemplateTo(
95
+ content: string,
96
+ destPath: string,
97
+ isDryRun: boolean,
98
+ ): Promise<boolean> {
99
+ if (isDryRun) return false;
100
+ const { dirname } = await import('node:path');
101
+ await mkdir(dirname(destPath), { recursive: true });
102
+ await writeFile(destPath, content);
103
+ return true;
104
+ }
105
+
86
106
  async function ensureGlobalTemplatesBootstrap(
87
107
  ctx: BootstrapContext,
88
108
  packageRootOverride?: string,
@@ -93,43 +113,85 @@ async function ensureGlobalTemplatesBootstrap(
93
113
  await mkdir(globalTemplatesDir, { recursive: true });
94
114
  }
95
115
 
116
+ // Resolve template content from bundled file or embedded fallback
117
+ let templateContent: string | null = null;
118
+
96
119
  try {
97
120
  const pkgRoot = packageRootOverride ?? getPackageRoot();
98
121
  const templatePath = join(pkgRoot, 'templates', 'CLEO-INJECTION.md');
99
122
  if (existsSync(templatePath)) {
100
- const content = readFileSync(templatePath, 'utf-8');
101
- const destPath = join(globalTemplatesDir, 'CLEO-INJECTION.md');
102
- if (!ctx.isDryRun) {
103
- await writeFile(destPath, content);
104
- }
105
- ctx.created.push(
106
- `~/.cleo/templates/CLEO-INJECTION.md (${ctx.isDryRun ? 'would refresh' : 'refreshed'})`,
107
- );
108
- } else {
109
- // Fallback: try using the injection content generator
110
- try {
111
- const { getInjectionTemplateContent } = await import('./injection.js');
112
- const content = getInjectionTemplateContent();
113
- if (content) {
114
- const destPath = join(globalTemplatesDir, 'CLEO-INJECTION.md');
115
- if (!ctx.isDryRun) {
116
- await writeFile(destPath, content);
117
- }
118
- ctx.created.push(
119
- `~/.cleo/templates/CLEO-INJECTION.md (${ctx.isDryRun ? 'would refresh' : 'refreshed'} from embedded)`,
120
- );
121
- }
122
- } catch {
123
- ctx.warnings.push('Could not refresh CLEO-INJECTION.md template');
124
- }
123
+ templateContent = readFileSync(templatePath, 'utf-8');
125
124
  }
126
125
  } catch {
126
+ // Fall through to embedded fallback
127
+ }
128
+
129
+ if (!templateContent) {
130
+ try {
131
+ const { getInjectionTemplateContent } = await import('./injection.js');
132
+ templateContent = getInjectionTemplateContent() ?? null;
133
+ } catch {
134
+ ctx.warnings.push('Could not refresh CLEO-INJECTION.md template');
135
+ return;
136
+ }
137
+ }
138
+
139
+ if (!templateContent) {
127
140
  ctx.warnings.push('Could not refresh CLEO-INJECTION.md template');
141
+ return;
142
+ }
143
+
144
+ // Write to XDG primary path
145
+ const xdgDest = join(globalTemplatesDir, 'CLEO-INJECTION.md');
146
+ const xdgWritten = await writeTemplateTo(templateContent, xdgDest, ctx.isDryRun);
147
+ ctx.created.push(
148
+ `${getCleoTemplatesTildePath()}/CLEO-INJECTION.md (${xdgWritten ? 'refreshed' : 'would refresh'})`,
149
+ );
150
+
151
+ // Sync to legacy ~/.cleo/templates/ if it exists (backward compat for
152
+ // project AGENTS.md files that still reference the old path)
153
+ const home = homedir();
154
+ const legacyTemplatesDir = join(home, '.cleo', 'templates');
155
+ if (legacyTemplatesDir !== globalTemplatesDir && existsSync(join(home, '.cleo'))) {
156
+ const legacyDest = join(legacyTemplatesDir, 'CLEO-INJECTION.md');
157
+ const legacyWritten = await writeTemplateTo(templateContent, legacyDest, ctx.isDryRun);
158
+ if (legacyWritten) {
159
+ ctx.created.push('~/.cleo/templates/CLEO-INJECTION.md (legacy sync)');
160
+ }
128
161
  }
129
162
  }
130
163
 
131
164
  // ── Step 2: CAAMP injection into ~/.agents/AGENTS.md ─────────────────
132
165
 
166
+ /**
167
+ * Sanitize a CAAMP-managed file by removing orphaned content outside
168
+ * CAAMP blocks. This fixes corruption from failed CAAMP consolidation
169
+ * (e.g. partial old block removal leaving `TION.md` fragments).
170
+ *
171
+ * Strategy: keep ONLY content inside valid CAAMP blocks + any non-CAAMP
172
+ * user content that doesn't look like an orphaned reference fragment.
173
+ */
174
+ function sanitizeCaampFile(content: string): string {
175
+ // Remove any duplicate <!-- CAAMP:END --> markers
176
+ let cleaned = content.replace(/(<!-- CAAMP:END -->)\s*(<!-- CAAMP:END -->)/g, '$1');
177
+
178
+ // Remove orphaned content between CAAMP:END and the next CAAMP:START (or EOF)
179
+ // that looks like a fragment of a CLEO reference (e.g. "TION.md", "INJECTION.md")
180
+ cleaned = cleaned.replace(
181
+ /<!-- CAAMP:END -->\s*[A-Z][A-Za-z-]*\.md\s*(?:<!-- CAAMP:END -->)?/g,
182
+ '<!-- CAAMP:END -->',
183
+ );
184
+
185
+ // Remove any lines that are just orphaned .md filename fragments
186
+ // (leftover from partial CAAMP block removal)
187
+ cleaned = cleaned.replace(/^[A-Z][A-Za-z-]*\.md\s*$/gm, '');
188
+
189
+ // Collapse multiple blank lines
190
+ cleaned = cleaned.replace(/\n{3,}/g, '\n\n');
191
+
192
+ return cleaned.trim() + '\n';
193
+ }
194
+
133
195
  async function injectAgentsHub(ctx: BootstrapContext): Promise<void> {
134
196
  const globalAgentsDir = getAgentsHome();
135
197
  const globalAgentsMd = join(globalAgentsDir, 'AGENTS.md');
@@ -143,21 +205,39 @@ async function injectAgentsHub(ctx: BootstrapContext): Promise<void> {
143
205
  await mkdir(globalAgentsDir, { recursive: true });
144
206
 
145
207
  // Strip legacy CLEO blocks (versioned markers from pre-CAAMP era)
208
+ // AND sanitize CAAMP corruption (orphaned fragments from bad consolidation)
146
209
  if (existsSync(globalAgentsMd)) {
147
210
  const content = await readFile(globalAgentsMd, 'utf8');
211
+
212
+ // Step A: Remove legacy <!-- CLEO:START -->...<!-- CLEO:END --> blocks
148
213
  const stripped = content.replace(
149
214
  /\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g,
150
215
  '',
151
216
  );
152
- if (stripped !== content) {
153
- await writeFile(globalAgentsMd, stripped, 'utf8');
217
+
218
+ // Step B: Sanitize CAAMP corruption (orphaned fragments, duplicate markers)
219
+ const sanitized = sanitizeCaampFile(stripped);
220
+
221
+ if (sanitized !== content) {
222
+ await writeFile(globalAgentsMd, sanitized, 'utf8');
223
+ ctx.created.push('~/.agents/AGENTS.md (sanitized CAAMP corruption)');
154
224
  }
155
225
  }
156
226
 
157
- // CAAMP 1.8.1: inject() is idempotent AND consolidates duplicates
227
+ // CAAMP inject() is idempotent writes the current XDG template reference
158
228
  const templateRef = `@${getCleoTemplatesTildePath()}/CLEO-INJECTION.md`;
159
229
  const action = await inject(globalAgentsMd, templateRef);
160
230
  ctx.created.push(`~/.agents/AGENTS.md (${action})`);
231
+
232
+ // Post-inject validation: verify the file is clean
233
+ const postContent = await readFile(globalAgentsMd, 'utf8');
234
+ const caampBlocks = postContent.match(/<!-- CAAMP:START -->/g);
235
+ const caampEnds = postContent.match(/<!-- CAAMP:END -->/g);
236
+ if (caampBlocks && caampEnds && caampBlocks.length !== caampEnds.length) {
237
+ ctx.warnings.push(
238
+ `~/.agents/AGENTS.md has mismatched CAAMP markers (${caampBlocks.length} START vs ${caampEnds.length} END)`,
239
+ );
240
+ }
161
241
  } else {
162
242
  ctx.created.push('~/.agents/AGENTS.md (would create/update CAAMP block)');
163
243
  }
@@ -330,3 +410,64 @@ async function installProviderAdapters(
330
410
  );
331
411
  }
332
412
  }
413
+
414
+ // ── Step 7: Post-bootstrap health verification ───────────────────────
415
+
416
+ /**
417
+ * Verify the injection chain is intact after bootstrap.
418
+ * Checks:
419
+ * 1. XDG template exists and has a version header
420
+ * 2. Legacy template (if present) matches XDG version
421
+ * 3. ~/.agents/AGENTS.md references the correct template path
422
+ * 4. No orphaned content in AGENTS.md
423
+ */
424
+ async function verifyBootstrapHealth(ctx: BootstrapContext): Promise<void> {
425
+ if (ctx.isDryRun) return;
426
+
427
+ try {
428
+ const xdgTemplatePath = join(getCleoTemplatesDir(), 'CLEO-INJECTION.md');
429
+ const agentsMd = join(getAgentsHome(), 'AGENTS.md');
430
+
431
+ // Check 1: XDG template exists
432
+ if (!existsSync(xdgTemplatePath)) {
433
+ ctx.warnings.push('Health: XDG template missing after bootstrap');
434
+ return;
435
+ }
436
+
437
+ const xdgContent = await readFile(xdgTemplatePath, 'utf8');
438
+ const xdgVersion = xdgContent.match(/^Version:\s*(.+)$/m)?.[1]?.trim();
439
+
440
+ // Check 2: Legacy template version sync
441
+ const home = homedir();
442
+ const legacyTemplatePath = join(home, '.cleo', 'templates', 'CLEO-INJECTION.md');
443
+ if (existsSync(legacyTemplatePath)) {
444
+ const legacyContent = await readFile(legacyTemplatePath, 'utf8');
445
+ const legacyVersion = legacyContent.match(/^Version:\s*(.+)$/m)?.[1]?.trim();
446
+ if (legacyVersion !== xdgVersion) {
447
+ ctx.warnings.push(
448
+ `Health: Legacy template version (${legacyVersion}) != XDG version (${xdgVersion})`,
449
+ );
450
+ }
451
+ }
452
+
453
+ // Check 3: AGENTS.md references the correct path
454
+ if (existsSync(agentsMd)) {
455
+ const agentsContent = await readFile(agentsMd, 'utf8');
456
+ const expectedRef = `@${getCleoTemplatesTildePath()}/CLEO-INJECTION.md`;
457
+ if (!agentsContent.includes(expectedRef)) {
458
+ ctx.warnings.push(`Health: ~/.agents/AGENTS.md does not reference ${expectedRef}`);
459
+ }
460
+
461
+ // Check 4: No orphaned .md fragments outside CAAMP blocks
462
+ const outsideCaamp = agentsContent.replace(
463
+ /<!-- CAAMP:START -->[\s\S]*?<!-- CAAMP:END -->/g,
464
+ '',
465
+ );
466
+ if (/[A-Z][A-Za-z-]*\.md/.test(outsideCaamp)) {
467
+ ctx.warnings.push('Health: ~/.agents/AGENTS.md has orphaned content outside CAAMP blocks');
468
+ }
469
+ }
470
+ } catch {
471
+ // Health check is non-critical — don't fail bootstrap
472
+ }
473
+ }
package/src/cleo.ts CHANGED
@@ -31,6 +31,28 @@ import type {
31
31
  import { exportTasks } from './admin/export.js';
32
32
  import type { ImportParams } from './admin/import.js';
33
33
  import { importTasks } from './admin/import.js';
34
+ // Agents
35
+ import {
36
+ type AgentCapacity,
37
+ type AgentHealthStatus,
38
+ type AgentInstanceRow,
39
+ checkAgentHealth,
40
+ deregisterAgent,
41
+ detectCrashedAgents,
42
+ getAgentCapacity,
43
+ heartbeat,
44
+ isOverloaded,
45
+ listAgentInstances,
46
+ type RegisterAgentOptions,
47
+ registerAgent,
48
+ } from './agents/index.js';
49
+ // Intelligence
50
+ import {
51
+ type BlastRadius,
52
+ calculateBlastRadius,
53
+ type ImpactReport,
54
+ predictImpact,
55
+ } from './intelligence/index.js';
34
56
  // Lifecycle
35
57
  import {
36
58
  checkGate,
@@ -127,6 +149,8 @@ import {
127
149
  } from './sticky/index.js';
128
150
  // Store
129
151
  import { getAccessor } from './store/data-accessor.js';
152
+ // Task Work (start/stop/current)
153
+ import { currentTask, startTask, stopTask } from './task-work/index.js';
130
154
  // Tasks
131
155
  import { addTask } from './tasks/add.js';
132
156
  import { archiveTasks } from './tasks/archive.js';
@@ -179,10 +203,21 @@ export interface TasksAPI {
179
203
  complete(params: { taskId: string; notes?: string }): Promise<unknown>;
180
204
  delete(params: { taskId: string; force?: boolean }): Promise<unknown>;
181
205
  archive(params?: { before?: string; taskIds?: string[]; dryRun?: boolean }): Promise<unknown>;
206
+ /** Start working on a specific task (sets focus). */
207
+ start(taskId: string): Promise<unknown>;
208
+ /** Stop working on the current task (clears focus). */
209
+ stop(): Promise<{ previousTask: string | null }>;
210
+ /** Get the current task work state. */
211
+ current(): Promise<unknown>;
182
212
  }
183
213
 
184
214
  export interface SessionsAPI {
185
- start(params: { name: string; scope: string; agent?: string }): Promise<unknown>;
215
+ start(params: {
216
+ name: string;
217
+ scope: string;
218
+ agent?: string;
219
+ startTask?: string;
220
+ }): Promise<unknown>;
186
221
  end(params?: { note?: string }): Promise<unknown>;
187
222
  status(): Promise<unknown>;
188
223
  resume(sessionId: string): Promise<unknown>;
@@ -324,6 +359,32 @@ export interface SyncAPI {
324
359
  removeProviderLinks(providerId: string): Promise<number>;
325
360
  }
326
361
 
362
+ export interface AgentsAPI {
363
+ /** Register a new agent instance. */
364
+ register(options: RegisterAgentOptions): Promise<AgentInstanceRow>;
365
+ /** Deregister an agent instance. */
366
+ deregister(agentId: string): Promise<AgentInstanceRow | null>;
367
+ /** Get health status for a specific agent. */
368
+ health(agentId: string): Promise<AgentHealthStatus | null>;
369
+ /** Detect agents that have crashed (missed heartbeats). */
370
+ detectCrashed(thresholdMs?: number): Promise<AgentInstanceRow[]>;
371
+ /** Record a heartbeat for an agent. */
372
+ recordHeartbeat(agentId: string): Promise<unknown>;
373
+ /** Get capacity info for an agent. */
374
+ capacity(agentId: string): Promise<AgentCapacity | null>;
375
+ /** Check if system is overloaded (available capacity below threshold). */
376
+ isOverloaded(threshold?: number): Promise<boolean>;
377
+ /** List all agent instances with optional filters. */
378
+ list(params?: { status?: string; agentType?: string }): Promise<AgentInstanceRow[]>;
379
+ }
380
+
381
+ export interface IntelligenceAPI {
382
+ /** Predict impact of a change description on related tasks. */
383
+ predictImpact(change: string): Promise<ImpactReport>;
384
+ /** Calculate blast radius for a task change. */
385
+ blastRadius(taskId: string): Promise<BlastRadius>;
386
+ }
387
+
327
388
  // ============================================================================
328
389
  // Init options
329
390
  // ============================================================================
@@ -410,6 +471,9 @@ export class Cleo {
410
471
  delete: (p) => deleteTask({ taskId: p.taskId, force: p.force }, root, store),
411
472
  archive: (p) =>
412
473
  archiveTasks({ before: p?.before, taskIds: p?.taskIds, dryRun: p?.dryRun }, root, store),
474
+ start: (taskId) => startTask(taskId, root, store),
475
+ stop: () => stopTask(root, store),
476
+ current: () => currentTask(root, store),
413
477
  };
414
478
  }
415
479
 
@@ -418,7 +482,12 @@ export class Cleo {
418
482
  const root = this.projectRoot;
419
483
  const store = this._store ?? undefined;
420
484
  return {
421
- start: (p) => startSession({ name: p.name, scope: p.scope, agent: p.agent }, root, store),
485
+ start: (p) =>
486
+ startSession(
487
+ { name: p.name, scope: p.scope, agent: p.agent, startTask: p.startTask },
488
+ root,
489
+ store,
490
+ ),
422
491
  end: (p) => endSession({ note: p?.note }, root, store),
423
492
  status: () => sessionStatus(root, store),
424
493
  resume: (id) => resumeSession(id, root, store),
@@ -570,6 +639,38 @@ export class Cleo {
570
639
  };
571
640
  }
572
641
 
642
+ // === Agents ===
643
+ get agents(): AgentsAPI {
644
+ const root = this.projectRoot;
645
+ return {
646
+ register: (opts) => registerAgent(opts, root),
647
+ deregister: (agentId) => deregisterAgent(agentId, root),
648
+ health: (agentId) => checkAgentHealth(agentId, undefined, root),
649
+ detectCrashed: (thresholdMs) => detectCrashedAgents(thresholdMs, root),
650
+ recordHeartbeat: (agentId) => heartbeat(agentId, root),
651
+ capacity: (agentId) => getAgentCapacity(agentId, root),
652
+ isOverloaded: (threshold) => isOverloaded(threshold, root),
653
+ list: (p) =>
654
+ listAgentInstances(
655
+ {
656
+ status: p?.status as 'active' | 'idle' | 'crashed' | undefined,
657
+ agentType: p?.agentType as import('./agents/index.js').AgentType | undefined,
658
+ },
659
+ root,
660
+ ),
661
+ };
662
+ }
663
+
664
+ // === Intelligence ===
665
+ get intelligence(): IntelligenceAPI {
666
+ const root = this.projectRoot;
667
+ const store = this._store ?? undefined;
668
+ return {
669
+ predictImpact: (change) => predictImpact(change, root, store ?? undefined),
670
+ blastRadius: (taskId) => calculateBlastRadius(taskId, store ?? undefined, root),
671
+ };
672
+ }
673
+
573
674
  // === Sync (Task Reconciliation) ===
574
675
  get sync(): SyncAPI {
575
676
  const root = this.projectRoot;
package/src/internal.ts CHANGED
@@ -98,7 +98,7 @@ export type {
98
98
  RiskFactor,
99
99
  ValidationPrediction,
100
100
  } from './intelligence/types.js';
101
-
101
+ export { type AddIssueParams, type AddIssueResult, addIssue } from './issue/create.js';
102
102
  // Issue
103
103
  export { collectDiagnostics } from './issue/diagnostics.js';
104
104
  // Lib — shared primitives
package/src/repair.ts CHANGED
@@ -105,6 +105,56 @@ export async function repairMissingCompletedAt(
105
105
  };
106
106
  }
107
107
 
108
+ /**
109
+ * Detect and add missing required columns on the tasks table.
110
+ * Uses PRAGMA table_info to check actual schema vs required columns.
111
+ *
112
+ * @see https://github.com/anthropics/cleo/issues/63
113
+ */
114
+ export async function repairMissingColumns(
115
+ cwd: string | undefined,
116
+ dryRun: boolean,
117
+ ): Promise<RepairAction> {
118
+ const { getDb } = await import('./store/sqlite.js');
119
+ const db = await getDb(cwd);
120
+
121
+ // getDb() already calls ensureRequiredColumns(), so if we get here
122
+ // the column should exist. But we still report the action for visibility.
123
+ const { sql } = await import('drizzle-orm');
124
+ const columns = db.all<{ name: string }>(sql`PRAGMA table_info(tasks)`);
125
+ const existingCols = new Set(columns.map((c: { name: string }) => c.name));
126
+
127
+ const missingCols = ['pipeline_stage'].filter((c) => !existingCols.has(c));
128
+
129
+ if (missingCols.length === 0) {
130
+ return {
131
+ action: 'fix_missing_columns',
132
+ status: 'skipped',
133
+ details: 'All required columns present on tasks table',
134
+ };
135
+ }
136
+
137
+ if (dryRun) {
138
+ return {
139
+ action: 'fix_missing_columns',
140
+ status: 'preview',
141
+ details: `Would add missing column(s): ${missingCols.join(', ')}`,
142
+ };
143
+ }
144
+
145
+ // Columns should already be added by ensureRequiredColumns() in getDb(),
146
+ // but apply again defensively.
147
+ for (const col of missingCols) {
148
+ db.run(sql.raw(`ALTER TABLE tasks ADD COLUMN ${col} text`));
149
+ }
150
+
151
+ return {
152
+ action: 'fix_missing_columns',
153
+ status: 'applied',
154
+ details: `Added missing column(s): ${missingCols.join(', ')}`,
155
+ };
156
+ }
157
+
108
158
  /**
109
159
  * Run all repair functions.
110
160
  * Returns all actions taken (or previewed in dry-run mode).
@@ -113,9 +163,10 @@ export async function runAllRepairs(
113
163
  cwd: string | undefined,
114
164
  dryRun: boolean,
115
165
  ): Promise<RepairAction[]> {
116
- const [sizes, completedAt] = await Promise.all([
166
+ const [sizes, completedAt, columns] = await Promise.all([
117
167
  repairMissingSizes(cwd, dryRun),
118
168
  repairMissingCompletedAt(cwd, dryRun),
169
+ repairMissingColumns(cwd, dryRun),
119
170
  ]);
120
- return [sizes, completedAt];
171
+ return [sizes, completedAt, columns];
121
172
  }
package/src/scaffold.ts CHANGED
@@ -14,6 +14,7 @@ import { execFile } from 'node:child_process';
14
14
  import { randomUUID } from 'node:crypto';
15
15
  import { existsSync, constants as fsConstants, readFileSync, statSync } from 'node:fs';
16
16
  import { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
17
+ import { homedir as getHomedir } from 'node:os';
17
18
  import { dirname, join, resolve } from 'node:path';
18
19
  import { fileURLToPath } from 'node:url';
19
20
  import { promisify } from 'node:util';
@@ -1278,12 +1279,33 @@ export function checkGlobalTemplates(): CheckResult {
1278
1279
  };
1279
1280
  }
1280
1281
 
1282
+ // Check version sync between XDG and legacy paths
1283
+ const xdgContent = readFileSync(injectionPath, 'utf-8');
1284
+ const xdgVersion = xdgContent.match(/^Version:\s*(.+)$/m)?.[1]?.trim();
1285
+ const home = getHomedir();
1286
+ const legacyPath = join(home, '.cleo', 'templates', 'CLEO-INJECTION.md');
1287
+
1288
+ if (existsSync(legacyPath)) {
1289
+ const legacyContent = readFileSync(legacyPath, 'utf-8');
1290
+ const legacyVersion = legacyContent.match(/^Version:\s*(.+)$/m)?.[1]?.trim();
1291
+ if (legacyVersion && xdgVersion && legacyVersion !== xdgVersion) {
1292
+ return {
1293
+ id: 'global_templates',
1294
+ category: 'global',
1295
+ status: 'warning',
1296
+ message: `Legacy template version (${legacyVersion}) out of sync with XDG (${xdgVersion})`,
1297
+ details: { path: injectionPath, exists: true, xdgVersion, legacyVersion, legacyPath },
1298
+ fix: 'npm install -g @cleocode/cleo (reinstall syncs both paths)',
1299
+ };
1300
+ }
1301
+ }
1302
+
1281
1303
  return {
1282
1304
  id: 'global_templates',
1283
1305
  category: 'global',
1284
1306
  status: 'passed',
1285
- message: 'Global injection template present',
1286
- details: { path: injectionPath, exists: true },
1307
+ message: `Global injection template present (v${xdgVersion ?? 'unknown'})`,
1308
+ details: { path: injectionPath, exists: true, version: xdgVersion },
1287
1309
  fix: null,
1288
1310
  };
1289
1311
  }
@@ -462,18 +462,48 @@ function runMigrations(nativeDb: DatabaseSync, db: NodeSQLiteDatabase<typeof sch
462
462
  }
463
463
  }
464
464
 
465
+ // Fix #63: Reconcile stale migration journal entries from older CLEO versions.
466
+ // When the DB has __drizzle_migrations entries whose hashes don't match ANY
467
+ // local migration file, drizzle's migrate() either throws or tries to re-run
468
+ // all migrations (causing "table already exists" errors). Fix by clearing stale
469
+ // entries and marking all local migrations as applied (tables already exist),
470
+ // then relying on ensureRequiredColumns() to patch any schema gaps.
471
+ if (tableExists(nativeDb, '__drizzle_migrations') && tableExists(nativeDb, 'tasks')) {
472
+ const localMigrations = readMigrationFiles({ migrationsFolder });
473
+ const localHashes = new Set(localMigrations.map((m) => m.hash));
474
+ const dbEntries = nativeDb.prepare('SELECT hash FROM "__drizzle_migrations"').all() as Array<{
475
+ hash: string;
476
+ }>;
477
+ const hasOrphanedEntries = dbEntries.some((e) => !localHashes.has(e.hash));
478
+
479
+ if (hasOrphanedEntries) {
480
+ const log = getLogger('sqlite');
481
+ log.warn(
482
+ { orphaned: dbEntries.filter((e) => !localHashes.has(e.hash)).length },
483
+ 'Detected stale migration journal entries from a previous CLEO version. Reconciling.',
484
+ );
485
+ // Clear all entries and mark every local migration as applied.
486
+ // The existing tables were created by the previous version's migrations,
487
+ // so we skip re-running them. ensureRequiredColumns() fills any schema gaps.
488
+ nativeDb.exec('DELETE FROM "__drizzle_migrations"');
489
+ for (const m of localMigrations) {
490
+ nativeDb.exec(
491
+ `INSERT INTO "__drizzle_migrations" ("hash", "created_at") VALUES ('${m.hash}', ${m.folderMillis})`,
492
+ );
493
+ }
494
+ }
495
+ }
496
+
465
497
  // Run pending migrations via drizzle-orm/node-sqlite/migrator (synchronous).
466
498
  // The new migrator handles its own transactions. T5185: retry on SQLITE_BUSY.
467
- let lastError: unknown;
468
499
  for (let attempt = 1; attempt <= MAX_MIGRATION_RETRIES; attempt++) {
469
500
  try {
470
501
  migrate(db, { migrationsFolder });
471
- return;
502
+ break;
472
503
  } catch (err) {
473
504
  if (!isSqliteBusy(err) || attempt === MAX_MIGRATION_RETRIES) {
474
505
  throw err;
475
506
  }
476
- lastError = err;
477
507
  const delay = Math.min(
478
508
  MIGRATION_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1) * (1 + Math.random() * 0.5),
479
509
  MIGRATION_RETRY_MAX_DELAY_MS,
@@ -481,8 +511,45 @@ function runMigrations(nativeDb: DatabaseSync, db: NodeSQLiteDatabase<typeof sch
481
511
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.round(delay));
482
512
  }
483
513
  }
484
- /* c8 ignore next */
485
- throw lastError;
514
+
515
+ // Fix #63: Defensive column safety net — add any columns the schema expects
516
+ // but that are missing from the actual table. This catches gaps from stale
517
+ // migration journals, partial migrations, or version skew.
518
+ ensureRequiredColumns(nativeDb);
519
+ }
520
+
521
+ /**
522
+ * Required columns that MUST exist on the tasks table.
523
+ * Maps column name → ALTER TABLE ADD COLUMN DDL suffix.
524
+ * Only TEXT columns with no constraints are safe for ALTER TABLE ADD in SQLite.
525
+ *
526
+ * @see https://github.com/anthropics/cleo/issues/63
527
+ */
528
+ const REQUIRED_TASK_COLUMNS: Array<{ name: string; ddl: string }> = [
529
+ { name: 'pipeline_stage', ddl: 'text' },
530
+ ];
531
+
532
+ /**
533
+ * Ensure all required columns exist on the tasks table.
534
+ * Uses PRAGMA table_info to inspect the schema and adds any missing columns
535
+ * via ALTER TABLE ADD COLUMN. This is a safety net for databases where
536
+ * Drizzle migrations could not run due to journal corruption or version skew.
537
+ *
538
+ * @see https://github.com/anthropics/cleo/issues/63
539
+ */
540
+ function ensureRequiredColumns(nativeDb: DatabaseSync): void {
541
+ if (!tableExists(nativeDb, 'tasks')) return;
542
+
543
+ const columns = nativeDb.prepare('PRAGMA table_info(tasks)').all() as Array<{ name: string }>;
544
+ const existingCols = new Set(columns.map((c) => c.name));
545
+
546
+ for (const req of REQUIRED_TASK_COLUMNS) {
547
+ if (!existingCols.has(req.name)) {
548
+ const log = getLogger('sqlite');
549
+ log.warn({ column: req.name }, `Adding missing column tasks.${req.name} via ALTER TABLE`);
550
+ nativeDb.exec(`ALTER TABLE tasks ADD COLUMN ${req.name} ${req.ddl}`);
551
+ }
552
+ }
486
553
  }
487
554
 
488
555
  /**