@cleocode/core 2026.3.74 → 2026.4.0

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 (428) hide show
  1. package/README.md +1 -1
  2. package/dist/agents/agent-schema.d.ts.map +1 -1
  3. package/dist/agents/retry.js +26 -21
  4. package/dist/agents/retry.js.map +1 -1
  5. package/dist/cant/approval.d.ts +110 -0
  6. package/dist/cant/approval.d.ts.map +1 -0
  7. package/dist/cant/approval.js +185 -0
  8. package/dist/cant/approval.js.map +1 -0
  9. package/dist/cant/context-builder.d.ts +79 -0
  10. package/dist/cant/context-builder.d.ts.map +1 -0
  11. package/dist/cant/context-builder.js +117 -0
  12. package/dist/cant/context-builder.js.map +1 -0
  13. package/dist/cant/discretion.d.ts +95 -0
  14. package/dist/cant/discretion.d.ts.map +1 -0
  15. package/dist/cant/discretion.js +116 -0
  16. package/dist/cant/discretion.js.map +1 -0
  17. package/dist/cant/index.d.ts +25 -0
  18. package/dist/cant/index.d.ts.map +1 -0
  19. package/dist/cant/index.js +23 -0
  20. package/dist/cant/index.js.map +1 -0
  21. package/dist/cant/parallel-runner.d.ts +38 -0
  22. package/dist/cant/parallel-runner.d.ts.map +1 -0
  23. package/dist/cant/parallel-runner.js +173 -0
  24. package/dist/cant/parallel-runner.js.map +1 -0
  25. package/dist/cant/types.d.ts +127 -0
  26. package/dist/cant/types.d.ts.map +1 -0
  27. package/dist/cant/types.js +11 -0
  28. package/dist/cant/types.js.map +1 -0
  29. package/dist/cant/workflow-executor.d.ts +105 -0
  30. package/dist/cant/workflow-executor.d.ts.map +1 -0
  31. package/dist/cant/workflow-executor.js +440 -0
  32. package/dist/cant/workflow-executor.js.map +1 -0
  33. package/dist/cleo.js +21 -1
  34. package/dist/cleo.js.map +1 -1
  35. package/dist/code/index.d.ts +10 -0
  36. package/dist/code/index.d.ts.map +1 -0
  37. package/dist/code/outline.d.ts +51 -0
  38. package/dist/code/outline.d.ts.map +1 -0
  39. package/dist/code/parser.d.ts +30 -0
  40. package/dist/code/parser.d.ts.map +1 -0
  41. package/dist/code/search.d.ts +42 -0
  42. package/dist/code/search.d.ts.map +1 -0
  43. package/dist/code/unfold.d.ts +44 -0
  44. package/dist/code/unfold.d.ts.map +1 -0
  45. package/dist/conduit/conduit-client.d.ts +35 -0
  46. package/dist/conduit/conduit-client.d.ts.map +1 -0
  47. package/dist/conduit/conduit-client.js +94 -0
  48. package/dist/conduit/conduit-client.js.map +1 -0
  49. package/dist/conduit/factory.d.ts +15 -0
  50. package/dist/conduit/factory.d.ts.map +1 -0
  51. package/dist/conduit/factory.js +35 -0
  52. package/dist/conduit/factory.js.map +1 -0
  53. package/dist/conduit/http-transport.d.ts +44 -0
  54. package/dist/conduit/http-transport.d.ts.map +1 -0
  55. package/dist/conduit/http-transport.js +165 -0
  56. package/dist/conduit/http-transport.js.map +1 -0
  57. package/dist/conduit/index.d.ts +15 -0
  58. package/dist/conduit/index.d.ts.map +1 -0
  59. package/dist/conduit/index.js +12 -0
  60. package/dist/conduit/index.js.map +1 -0
  61. package/dist/conduit/local-transport.d.ts +91 -0
  62. package/dist/conduit/local-transport.d.ts.map +1 -0
  63. package/dist/conduit/sse-transport.d.ts +68 -0
  64. package/dist/conduit/sse-transport.d.ts.map +1 -0
  65. package/dist/config.js +4 -3
  66. package/dist/config.js.map +1 -1
  67. package/dist/crypto/credentials.d.ts +40 -0
  68. package/dist/crypto/credentials.d.ts.map +1 -0
  69. package/dist/crypto/credentials.js +144 -0
  70. package/dist/crypto/credentials.js.map +1 -0
  71. package/dist/engine-result.d.ts +1 -1
  72. package/dist/engine-result.d.ts.map +1 -1
  73. package/dist/error-catalog.d.ts +1 -1
  74. package/dist/error-catalog.d.ts.map +1 -1
  75. package/dist/error-registry.d.ts +1 -1
  76. package/dist/error-registry.d.ts.map +1 -1
  77. package/dist/errors.d.ts +1 -1
  78. package/dist/errors.d.ts.map +1 -1
  79. package/dist/hooks/handlers/agent-hooks.d.ts.map +1 -1
  80. package/dist/hooks/handlers/agent-hooks.js +106 -0
  81. package/dist/hooks/handlers/agent-hooks.js.map +1 -0
  82. package/dist/hooks/handlers/context-hooks.d.ts.map +1 -1
  83. package/dist/hooks/handlers/context-hooks.js +111 -0
  84. package/dist/hooks/handlers/context-hooks.js.map +1 -0
  85. package/dist/hooks/handlers/error-hooks.d.ts +14 -5
  86. package/dist/hooks/handlers/error-hooks.d.ts.map +1 -1
  87. package/dist/hooks/handlers/error-hooks.js +15 -6
  88. package/dist/hooks/handlers/error-hooks.js.map +1 -1
  89. package/dist/hooks/handlers/file-hooks.d.ts.map +1 -1
  90. package/dist/hooks/handlers/file-hooks.js +35 -11
  91. package/dist/hooks/handlers/file-hooks.js.map +1 -1
  92. package/dist/hooks/handlers/handler-helpers.d.ts +41 -0
  93. package/dist/hooks/handlers/handler-helpers.d.ts.map +1 -0
  94. package/dist/hooks/handlers/handler-helpers.js +61 -0
  95. package/dist/hooks/handlers/handler-helpers.js.map +1 -0
  96. package/dist/hooks/handlers/index.js +10 -1
  97. package/dist/hooks/handlers/index.js.map +1 -1
  98. package/dist/hooks/handlers/mcp-hooks.d.ts.map +1 -1
  99. package/dist/hooks/handlers/mcp-hooks.js +88 -21
  100. package/dist/hooks/handlers/mcp-hooks.js.map +1 -1
  101. package/dist/hooks/handlers/session-hooks.d.ts.map +1 -1
  102. package/dist/hooks/handlers/session-hooks.js +5 -10
  103. package/dist/hooks/handlers/session-hooks.js.map +1 -1
  104. package/dist/hooks/handlers/task-hooks.d.ts.map +1 -1
  105. package/dist/hooks/handlers/task-hooks.js +5 -10
  106. package/dist/hooks/handlers/task-hooks.js.map +1 -1
  107. package/dist/hooks/handlers/work-capture-hooks.d.ts.map +1 -1
  108. package/dist/hooks/handlers/work-capture-hooks.js +165 -0
  109. package/dist/hooks/handlers/work-capture-hooks.js.map +1 -0
  110. package/dist/hooks/payload-schemas.js +83 -26
  111. package/dist/hooks/payload-schemas.js.map +1 -1
  112. package/dist/hooks/provider-hooks.js +37 -5
  113. package/dist/hooks/provider-hooks.js.map +1 -1
  114. package/dist/hooks/registry.js +76 -23
  115. package/dist/hooks/registry.js.map +1 -1
  116. package/dist/hooks/types.js +17 -13
  117. package/dist/hooks/types.js.map +1 -1
  118. package/dist/index.d.ts +4 -1
  119. package/dist/index.d.ts.map +1 -1
  120. package/dist/index.js +6452 -3371
  121. package/dist/index.js.map +4 -4
  122. package/dist/init.d.ts.map +1 -1
  123. package/dist/init.js +12 -0
  124. package/dist/init.js.map +1 -1
  125. package/dist/internal.d.ts +11 -1
  126. package/dist/internal.d.ts.map +1 -1
  127. package/dist/internal.js +10 -0
  128. package/dist/internal.js.map +1 -1
  129. package/dist/lib/index.d.ts +1 -0
  130. package/dist/lib/index.d.ts.map +1 -1
  131. package/dist/lib/tree-sitter-languages.d.ts +29 -0
  132. package/dist/lib/tree-sitter-languages.d.ts.map +1 -0
  133. package/dist/memory/brain-links.d.ts.map +1 -1
  134. package/dist/memory/brain-maintenance.d.ts +13 -0
  135. package/dist/memory/brain-maintenance.d.ts.map +1 -1
  136. package/dist/memory/brain-retrieval.d.ts +3 -0
  137. package/dist/memory/brain-retrieval.d.ts.map +1 -1
  138. package/dist/memory/brain-retrieval.js +5 -0
  139. package/dist/memory/brain-retrieval.js.map +1 -1
  140. package/dist/memory/decisions.d.ts.map +1 -1
  141. package/dist/mvi-helpers.d.ts +52 -0
  142. package/dist/mvi-helpers.d.ts.map +1 -0
  143. package/dist/mvi-helpers.js +74 -0
  144. package/dist/mvi-helpers.js.map +1 -0
  145. package/dist/nexus/index.js +2 -0
  146. package/dist/nexus/index.js.map +1 -1
  147. package/dist/nexus/workspace.d.ts.map +1 -1
  148. package/dist/nexus/workspace.js +355 -0
  149. package/dist/nexus/workspace.js.map +1 -0
  150. package/dist/orchestration/hierarchy.d.ts +32 -0
  151. package/dist/orchestration/hierarchy.d.ts.map +1 -0
  152. package/dist/orchestration/index.d.ts +1 -0
  153. package/dist/orchestration/index.d.ts.map +1 -1
  154. package/dist/output.d.ts +2 -2
  155. package/dist/output.d.ts.map +1 -1
  156. package/dist/output.js +40 -8
  157. package/dist/output.js.map +1 -1
  158. package/dist/pagination.d.ts +1 -1
  159. package/dist/pagination.d.ts.map +1 -1
  160. package/dist/sessions/find.d.ts +3 -0
  161. package/dist/sessions/find.d.ts.map +1 -1
  162. package/dist/sessions/find.js +3 -1
  163. package/dist/sessions/find.js.map +1 -1
  164. package/dist/sessions/index.d.ts.map +1 -1
  165. package/dist/sessions/index.js +11 -4
  166. package/dist/sessions/index.js.map +1 -1
  167. package/dist/sessions/snapshot.js +213 -0
  168. package/dist/sessions/snapshot.js.map +1 -0
  169. package/dist/store/agent-registry-accessor.d.ts +31 -0
  170. package/dist/store/agent-registry-accessor.d.ts.map +1 -0
  171. package/dist/store/agent-registry-accessor.js +169 -0
  172. package/dist/store/agent-registry-accessor.js.map +1 -0
  173. package/dist/store/converters.d.ts.map +1 -1
  174. package/dist/store/converters.js +2 -0
  175. package/dist/store/converters.js.map +1 -1
  176. package/dist/store/cross-db-cleanup.d.ts +34 -0
  177. package/dist/store/cross-db-cleanup.d.ts.map +1 -1
  178. package/dist/store/db-helpers.d.ts.map +1 -1
  179. package/dist/store/db-helpers.js +1 -0
  180. package/dist/store/db-helpers.js.map +1 -1
  181. package/dist/store/json.js +2 -2
  182. package/dist/store/safety-data-accessor.d.ts +7 -0
  183. package/dist/store/safety-data-accessor.d.ts.map +1 -1
  184. package/dist/store/safety-data-accessor.js +14 -0
  185. package/dist/store/safety-data-accessor.js.map +1 -1
  186. package/dist/store/signaldock-sqlite.d.ts +48 -0
  187. package/dist/store/signaldock-sqlite.d.ts.map +1 -0
  188. package/dist/store/signaldock-sqlite.js +178 -0
  189. package/dist/store/signaldock-sqlite.js.map +1 -0
  190. package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
  191. package/dist/store/sqlite-data-accessor.js +50 -0
  192. package/dist/store/sqlite-data-accessor.js.map +1 -1
  193. package/dist/store/sqlite.d.ts.map +1 -1
  194. package/dist/store/sqlite.js +30 -1
  195. package/dist/store/sqlite.js.map +1 -1
  196. package/dist/store/task-store.d.ts.map +1 -1
  197. package/dist/store/task-store.js +2 -0
  198. package/dist/store/task-store.js.map +1 -1
  199. package/dist/store/tasks-schema.d.ts +16 -0
  200. package/dist/store/tasks-schema.d.ts.map +1 -1
  201. package/dist/store/tasks-schema.js +33 -0
  202. package/dist/store/tasks-schema.js.map +1 -1
  203. package/dist/store/validation-schemas.d.ts +32 -0
  204. package/dist/store/validation-schemas.d.ts.map +1 -1
  205. package/dist/system/health.d.ts +1 -1
  206. package/dist/system/health.d.ts.map +1 -1
  207. package/dist/system/health.js +35 -0
  208. package/dist/system/health.js.map +1 -1
  209. package/dist/task-work/index.d.ts.map +1 -1
  210. package/dist/task-work/index.js +8 -4
  211. package/dist/task-work/index.js.map +1 -1
  212. package/dist/tasks/complete.js +5 -2
  213. package/dist/tasks/complete.js.map +1 -1
  214. package/dist/tasks/find.d.ts +3 -0
  215. package/dist/tasks/find.d.ts.map +1 -1
  216. package/dist/tasks/find.js +7 -1
  217. package/dist/tasks/find.js.map +1 -1
  218. package/dist/tasks/list.d.ts +5 -2
  219. package/dist/tasks/list.d.ts.map +1 -1
  220. package/dist/tasks/list.js +9 -2
  221. package/dist/tasks/list.js.map +1 -1
  222. package/dist/tasks/show.d.ts +3 -0
  223. package/dist/tasks/show.d.ts.map +1 -1
  224. package/dist/tasks/show.js +2 -0
  225. package/dist/tasks/show.js.map +1 -1
  226. package/dist/upgrade.d.ts.map +1 -1
  227. package/dist/upgrade.js +15 -0
  228. package/dist/upgrade.js.map +1 -1
  229. package/migrations/drizzle-tasks/20260324000000_assignee-column/migration.sql +6 -0
  230. package/migrations/drizzle-tasks/20260324000000_assignee-column/snapshot.json +9 -0
  231. package/migrations/drizzle-tasks/20260327000000_agent-credentials/migration.sql +23 -0
  232. package/package.json +17 -7
  233. package/src/__tests__/cli-parity.test.js +11 -1
  234. package/src/__tests__/cli-parity.test.js.map +1 -1
  235. package/src/__tests__/cli-parity.test.ts +17 -1
  236. package/src/__tests__/human-output.test.js +11 -1
  237. package/src/__tests__/human-output.test.js.map +1 -1
  238. package/src/__tests__/human-output.test.ts +18 -1
  239. package/src/__tests__/injection-chain.test.js +3 -2
  240. package/src/__tests__/injection-chain.test.js.map +1 -1
  241. package/src/__tests__/injection-mvi-tiers.test.d.ts +2 -2
  242. package/src/__tests__/injection-mvi-tiers.test.js +15 -15
  243. package/src/__tests__/injection-mvi-tiers.test.js.map +1 -1
  244. package/src/__tests__/lafs-conformance.test.d.ts +1 -1
  245. package/src/__tests__/lafs-conformance.test.js +2 -2
  246. package/src/__tests__/sharing.test.js +19 -0
  247. package/src/__tests__/sharing.test.js.map +1 -1
  248. package/src/agents/__tests__/agent-registry.test.d.ts +12 -0
  249. package/src/agents/__tests__/agent-registry.test.d.ts.map +1 -0
  250. package/src/agents/__tests__/agent-registry.test.js +262 -0
  251. package/src/agents/__tests__/agent-registry.test.js.map +1 -0
  252. package/src/agents/__tests__/execution-learning.test.d.ts +14 -0
  253. package/src/agents/__tests__/execution-learning.test.d.ts.map +1 -0
  254. package/src/agents/__tests__/execution-learning.test.js +533 -0
  255. package/src/agents/__tests__/execution-learning.test.js.map +1 -0
  256. package/src/agents/__tests__/health-monitor.test.d.ts +10 -0
  257. package/src/agents/__tests__/health-monitor.test.d.ts.map +1 -0
  258. package/src/agents/__tests__/health-monitor.test.js +259 -0
  259. package/src/agents/__tests__/health-monitor.test.js.map +1 -0
  260. package/src/agents/__tests__/registry.test.js +27 -2
  261. package/src/agents/__tests__/registry.test.js.map +1 -1
  262. package/src/agents/agent-schema.ts +2 -5
  263. package/src/cant/__tests__/cant-agent-parse.test.ts +94 -0
  264. package/src/cant/approval.ts +218 -0
  265. package/src/cant/context-builder.ts +135 -0
  266. package/src/cant/discretion.ts +149 -0
  267. package/src/cant/index.ts +58 -0
  268. package/src/cant/parallel-runner.ts +205 -0
  269. package/src/cant/types.ts +158 -0
  270. package/src/cant/workflow-executor.ts +618 -0
  271. package/src/code/index.ts +10 -0
  272. package/src/code/outline.ts +214 -0
  273. package/src/code/parser.ts +299 -0
  274. package/src/code/search.ts +173 -0
  275. package/src/code/unfold.ts +204 -0
  276. package/src/conduit/__tests__/dual-api-e2e.test.ts +212 -0
  277. package/src/conduit/__tests__/local-credential-flow.test.ts +230 -0
  278. package/src/conduit/__tests__/local-transport.test.ts +320 -0
  279. package/src/conduit/__tests__/sse-transport.test.ts +344 -0
  280. package/src/conduit/conduit-client.ts +123 -0
  281. package/src/conduit/factory.ts +49 -0
  282. package/src/conduit/http-transport.ts +201 -0
  283. package/src/conduit/index.ts +15 -0
  284. package/src/conduit/local-transport.ts +309 -0
  285. package/src/conduit/sse-transport.ts +382 -0
  286. package/src/crypto/credentials.ts +166 -0
  287. package/src/engine-result.ts +1 -1
  288. package/src/error-catalog.ts +1 -1
  289. package/src/error-registry.ts +1 -1
  290. package/src/errors.ts +1 -1
  291. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.d.ts +13 -0
  292. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.d.ts.map +1 -0
  293. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.js +501 -0
  294. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.js.map +1 -0
  295. package/src/hooks/handlers/agent-hooks.ts +1 -30
  296. package/src/hooks/handlers/context-hooks.ts +1 -30
  297. package/src/hooks/handlers/error-hooks.ts +14 -5
  298. package/src/hooks/handlers/file-hooks.ts +1 -6
  299. package/src/hooks/handlers/handler-helpers.ts +62 -0
  300. package/src/hooks/handlers/mcp-hooks.ts +2 -14
  301. package/src/hooks/handlers/session-hooks.ts +1 -6
  302. package/src/hooks/handlers/task-hooks.ts +1 -6
  303. package/src/hooks/handlers/work-capture-hooks.ts +1 -10
  304. package/src/index.ts +12 -1
  305. package/src/init.ts +12 -0
  306. package/src/intelligence/__tests__/adaptive-validation.test.d.ts +11 -0
  307. package/src/intelligence/__tests__/adaptive-validation.test.d.ts.map +1 -0
  308. package/src/intelligence/__tests__/adaptive-validation.test.js +517 -0
  309. package/src/intelligence/__tests__/adaptive-validation.test.js.map +1 -0
  310. package/src/intelligence/__tests__/impact.test.d.ts +1 -0
  311. package/src/intelligence/__tests__/impact.test.d.ts.map +1 -1
  312. package/src/intelligence/__tests__/impact.test.js +132 -1
  313. package/src/intelligence/__tests__/impact.test.js.map +1 -1
  314. package/src/internal.ts +22 -0
  315. package/src/lib/__tests__/retry.test.d.ts +7 -0
  316. package/src/lib/__tests__/retry.test.d.ts.map +1 -0
  317. package/src/lib/__tests__/retry.test.js +225 -0
  318. package/src/lib/__tests__/retry.test.js.map +1 -0
  319. package/src/lib/index.ts +8 -0
  320. package/src/lib/tree-sitter-languages.ts +88 -0
  321. package/src/lifecycle/__tests__/chain-store.test.js +6 -0
  322. package/src/lifecycle/__tests__/chain-store.test.js.map +1 -1
  323. package/src/lifecycle/__tests__/tessera-engine.test.js +52 -0
  324. package/src/lifecycle/__tests__/tessera-engine.test.js.map +1 -1
  325. package/src/memory/__tests__/brain-automation.test.d.ts +11 -0
  326. package/src/memory/__tests__/brain-automation.test.d.ts.map +1 -0
  327. package/src/memory/__tests__/brain-automation.test.js +730 -0
  328. package/src/memory/__tests__/brain-automation.test.js.map +1 -0
  329. package/src/memory/__tests__/brain-links.test.ts +14 -0
  330. package/src/memory/__tests__/brain-retrieval.test.ts +10 -0
  331. package/src/memory/__tests__/session-memory.test.ts +17 -0
  332. package/src/memory/brain-links.ts +17 -0
  333. package/src/memory/brain-maintenance.ts +33 -1
  334. package/src/memory/brain-retrieval.ts +27 -2
  335. package/src/memory/decisions.ts +18 -2
  336. package/src/mvi-helpers.ts +81 -0
  337. package/src/nexus/workspace.ts +19 -7
  338. package/src/orchestration/hierarchy.ts +202 -0
  339. package/src/orchestration/index.ts +1 -0
  340. package/src/output.ts +43 -10
  341. package/src/pagination.ts +1 -1
  342. package/src/sessions/__tests__/session-edge-cases.test.js +20 -1
  343. package/src/sessions/__tests__/session-edge-cases.test.js.map +1 -1
  344. package/src/sessions/__tests__/session-find.test.js +1 -1
  345. package/src/sessions/__tests__/session-find.test.js.map +1 -1
  346. package/src/sessions/__tests__/session-find.test.ts +1 -1
  347. package/src/sessions/find.ts +6 -1
  348. package/src/sessions/index.ts +9 -0
  349. package/src/store/__tests__/migration-safety.test.js +3 -0
  350. package/src/store/__tests__/migration-safety.test.js.map +1 -1
  351. package/src/store/__tests__/session-store.test.js +128 -1
  352. package/src/store/__tests__/session-store.test.js.map +1 -1
  353. package/src/store/__tests__/task-store.test.js +18 -1
  354. package/src/store/__tests__/task-store.test.js.map +1 -1
  355. package/src/store/__tests__/test-db-helper.d.ts.map +1 -1
  356. package/src/store/__tests__/test-db-helper.js +12 -0
  357. package/src/store/__tests__/test-db-helper.js.map +1 -1
  358. package/src/store/agent-registry-accessor.ts +375 -0
  359. package/src/store/converters.ts +2 -0
  360. package/src/store/cross-db-cleanup.ts +175 -1
  361. package/src/store/db-helpers.ts +1 -0
  362. package/src/store/safety-data-accessor.ts +23 -0
  363. package/src/store/signaldock-sqlite.ts +429 -0
  364. package/src/store/sqlite-data-accessor.ts +72 -0
  365. package/src/store/sqlite.ts +4 -1
  366. package/src/store/task-store.ts +9 -1
  367. package/src/store/tasks-schema.ts +7 -0
  368. package/src/system/__tests__/health.test.ts +2 -2
  369. package/src/system/health.ts +54 -2
  370. package/src/task-work/index.ts +5 -0
  371. package/src/tasks/__tests__/add.test.js +19 -1
  372. package/src/tasks/__tests__/add.test.js.map +1 -1
  373. package/src/tasks/__tests__/assignee.test.d.ts +14 -0
  374. package/src/tasks/__tests__/assignee.test.d.ts.map +1 -0
  375. package/src/tasks/__tests__/assignee.test.js +125 -0
  376. package/src/tasks/__tests__/assignee.test.js.map +1 -0
  377. package/src/tasks/__tests__/assignee.test.ts +162 -0
  378. package/src/tasks/__tests__/complete-unblocks.test.js +13 -1
  379. package/src/tasks/__tests__/complete-unblocks.test.js.map +1 -1
  380. package/src/tasks/__tests__/complete.test.js +28 -7
  381. package/src/tasks/__tests__/complete.test.js.map +1 -1
  382. package/src/tasks/__tests__/epic-enforcement.test.d.ts +15 -0
  383. package/src/tasks/__tests__/epic-enforcement.test.d.ts.map +1 -0
  384. package/src/tasks/__tests__/epic-enforcement.test.js +669 -0
  385. package/src/tasks/__tests__/epic-enforcement.test.js.map +1 -0
  386. package/src/tasks/__tests__/hierarchy-policy.test.js +5 -0
  387. package/src/tasks/__tests__/hierarchy-policy.test.js.map +1 -1
  388. package/src/tasks/__tests__/minimal-test.test.d.ts +2 -0
  389. package/src/tasks/__tests__/minimal-test.test.d.ts.map +1 -0
  390. package/src/tasks/__tests__/minimal-test.test.js +25 -0
  391. package/src/tasks/__tests__/minimal-test.test.js.map +1 -0
  392. package/src/tasks/__tests__/pipeline-stage.test.d.ts +14 -0
  393. package/src/tasks/__tests__/pipeline-stage.test.d.ts.map +1 -0
  394. package/src/tasks/__tests__/pipeline-stage.test.js +277 -0
  395. package/src/tasks/__tests__/pipeline-stage.test.js.map +1 -0
  396. package/src/tasks/__tests__/update.test.js +43 -6
  397. package/src/tasks/__tests__/update.test.js.map +1 -1
  398. package/src/tasks/find.ts +11 -1
  399. package/src/tasks/list.ts +14 -3
  400. package/src/tasks/show.ts +6 -0
  401. package/src/upgrade.ts +16 -0
  402. package/dist/tasks/reparent.d.ts +0 -38
  403. package/dist/tasks/reparent.d.ts.map +0 -1
  404. package/dist/ui/injection-legacy.d.ts +0 -26
  405. package/dist/ui/injection-legacy.d.ts.map +0 -1
  406. package/dist/ui/injection-legacy.js +0 -42
  407. package/dist/ui/injection-legacy.js.map +0 -1
  408. package/src/signaldock/__tests__/claude-code-transport.test.d.ts +0 -7
  409. package/src/signaldock/__tests__/claude-code-transport.test.d.ts.map +0 -1
  410. package/src/signaldock/__tests__/claude-code-transport.test.js +0 -147
  411. package/src/signaldock/__tests__/claude-code-transport.test.js.map +0 -1
  412. package/src/signaldock/__tests__/claude-code-transport.test.ts +0 -180
  413. package/src/signaldock/__tests__/factory.test.d.ts +0 -7
  414. package/src/signaldock/__tests__/factory.test.d.ts.map +0 -1
  415. package/src/signaldock/__tests__/factory.test.js +0 -55
  416. package/src/signaldock/__tests__/factory.test.js.map +0 -1
  417. package/src/signaldock/__tests__/factory.test.ts +0 -61
  418. package/src/signaldock/__tests__/signaldock-transport.test.d.ts +0 -9
  419. package/src/signaldock/__tests__/signaldock-transport.test.d.ts.map +0 -1
  420. package/src/signaldock/__tests__/signaldock-transport.test.js +0 -321
  421. package/src/signaldock/__tests__/signaldock-transport.test.js.map +0 -1
  422. package/src/signaldock/__tests__/signaldock-transport.test.ts +0 -421
  423. package/src/signaldock/claude-code-transport.ts +0 -137
  424. package/src/signaldock/factory.ts +0 -39
  425. package/src/signaldock/index.ts +0 -28
  426. package/src/signaldock/signaldock-transport.ts +0 -194
  427. package/src/signaldock/transport.ts +0 -78
  428. package/src/signaldock/types.ts +0 -100
package/README.md CHANGED
@@ -565,7 +565,7 @@ async function buildKnowledge() {
565
565
 
566
566
  - `@cleocode/contracts` - Type definitions
567
567
  - `@cleocode/caamp` - Context-aware agent memory protocol
568
- - `@cleocode/lafs-protocol` - Language-agnostic feedback schema
568
+ - `@cleocode/lafs` - Language-agnostic feedback schema
569
569
  - `drizzle-orm` - Database ORM
570
570
  - `zod` - Schema validation
571
571
  - `pino` - Logging
@@ -1 +1 @@
1
- {"version":3,"file":"agent-schema.d.ts","sourceRoot":"","sources":["../../src/agents/agent-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AASH,iEAAiE;AACjE,eAAO,MAAM,uBAAuB,wEAO1B,CAAC;AAEX,4CAA4C;AAC5C,eAAO,MAAM,WAAW,uGAQd,CAAC;AAMX,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;EA2B1B,CAAC;AAMF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBzB,CAAC;AAMF,MAAM,MAAM,gBAAgB,GAAG,OAAO,cAAc,CAAC,YAAY,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,OAAO,cAAc,CAAC,YAAY,CAAC;AACrE,MAAM,MAAM,gBAAgB,GAAG,OAAO,aAAa,CAAC,YAAY,CAAC;AACjE,MAAM,MAAM,mBAAmB,GAAG,OAAO,aAAa,CAAC,YAAY,CAAC;AACpE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC3E,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,WAAW,GAAG,SAAS,CAAC"}
@@ -110,30 +110,35 @@ export function shouldRetry(error, attempt, policy) {
110
110
  */
111
111
  export async function withRetry(fn, policy) {
112
112
  const effectivePolicy = createRetryPolicy(policy);
113
- const { withRetry: coreRetry } = await import('../lib/retry.js');
114
113
  let attemptCount = 0;
115
- try {
116
- const value = await coreRetry(async () => {
114
+ let totalDelayMs = 0;
115
+ const maxAttempts = effectivePolicy.maxRetries + 1;
116
+ let lastError;
117
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
118
+ try {
117
119
  attemptCount++;
118
- return fn();
119
- }, {
120
- maxAttempts: effectivePolicy.maxRetries + 1,
121
- baseDelayMs: effectivePolicy.baseDelayMs,
122
- maxDelayMs: effectivePolicy.maxDelayMs,
123
- retryableErrors: [(err) => shouldRetry(err, attemptCount - 1, effectivePolicy)],
124
- });
125
- return { success: true, value, attempts: attemptCount, totalDelayMs: 0 };
126
- }
127
- catch (err) {
128
- const error = err instanceof Error ? err : new Error(String(err));
129
- const context = err;
130
- return {
131
- success: false,
132
- error,
133
- attempts: attemptCount,
134
- totalDelayMs: context.totalDelayMs ?? 0,
135
- };
120
+ const value = await fn();
121
+ return { success: true, value, attempts: attemptCount, totalDelayMs };
122
+ }
123
+ catch (err) {
124
+ lastError = err;
125
+ const isLastAttempt = attempt === maxAttempts - 1;
126
+ if (isLastAttempt)
127
+ break;
128
+ if (!shouldRetry(err, attempt, effectivePolicy))
129
+ break;
130
+ const delay = calculateDelay(attempt, effectivePolicy);
131
+ totalDelayMs += delay;
132
+ await new Promise((resolve) => setTimeout(resolve, delay));
133
+ }
136
134
  }
135
+ const error = lastError instanceof Error ? lastError : new Error(String(lastError));
136
+ return {
137
+ success: false,
138
+ error,
139
+ attempts: attemptCount,
140
+ totalDelayMs,
141
+ };
137
142
  }
138
143
  /**
139
144
  * Attempt to recover crashed agents.
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/agents/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAsBvB,6DAA6D;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAA0B,MAAM,CAAC,MAAM,CAAC;IACvE,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,KAAK;IAClB,UAAU,EAAE,MAAM;IAClB,iBAAiB,EAAE,CAAC;IACpB,MAAM,EAAE,IAAI;IACZ,cAAc,EAAE,IAAI;CACrB,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAgC;IAChE,OAAO,EAAE,GAAG,oBAAoB,EAAE,GAAG,SAAS,EAAE,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAAC,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E,EAAE,GAAG,CAAC,CAAC;QAC/D,OAAO,CAAC,IAAI,CAAC;YACX,OAAO,EAAE,KAAK,CAAC,EAAE;YACjB,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,WAAW;YACnB,MAAM,EAAE,2CAA2C;SACpD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Approval gate manager for CANT workflow execution.
3
+ *
4
+ * Manages the lifecycle of approval tokens: generation, validation,
5
+ * approval, rejection, and expiration. Tokens follow the state machine
6
+ * defined in CANT-DSL-SPEC.md Section 8.2.
7
+ *
8
+ * State transitions are atomic (CAS): only `pending -> approved`,
9
+ * `pending -> rejected`, and `pending -> expired` are permitted.
10
+ *
11
+ * @see docs/specs/CANT-DSL-SPEC.md Section 8 (Approval Token Protocol)
12
+ */
13
+ import type { ApprovalToken, TokenValidation } from './types.js';
14
+ /**
15
+ * Manages approval tokens for CANT workflow gates.
16
+ *
17
+ * Tokens are stored in-memory per instance. In production, these are
18
+ * persisted via the session's `approvalTokensJson` column in tasks.db.
19
+ */
20
+ export declare class ApprovalManager {
21
+ /** In-memory token store keyed by token UUID. */
22
+ private tokens;
23
+ /**
24
+ * Generates a new approval token for a workflow gate.
25
+ *
26
+ * @param sessionId - The session that owns this token.
27
+ * @param workflowName - The workflow containing the approval gate.
28
+ * @param gateName - The label of the specific approval gate.
29
+ * @param message - The message to display to the approver.
30
+ * @param workflowHash - SHA-256 hash of the workflow definition.
31
+ * @param requestedBy - The agent/workflow requesting approval.
32
+ * @param expiresInMs - Token lifetime in milliseconds (default: 24h).
33
+ * @returns The generated approval token.
34
+ */
35
+ generateToken(sessionId: string, workflowName: string, gateName: string, message: string, workflowHash: string, requestedBy: string, expiresInMs?: number): ApprovalToken;
36
+ /**
37
+ * Validates an approval token against the current execution context.
38
+ *
39
+ * Checks: (a) token exists, (b) sessionId matches, (c) status is pending,
40
+ * (d) not expired, (e) workflowHash matches current workflow.
41
+ *
42
+ * @param tokenId - The token UUID to validate.
43
+ * @param currentSessionId - The current session to validate against.
44
+ * @param currentWorkflowHash - The current workflow hash for TOCTOU check.
45
+ * @returns Validation result with reason if invalid.
46
+ */
47
+ validateToken(tokenId: string, currentSessionId: string, currentWorkflowHash: string): TokenValidation;
48
+ /**
49
+ * Approves a pending token.
50
+ *
51
+ * Performs an atomic CAS transition: `pending -> approved`. If the token
52
+ * is not in `pending` state, the operation is a no-op and returns false.
53
+ *
54
+ * @param tokenId - The token UUID to approve.
55
+ * @param approvedBy - The identifier of the approving actor.
56
+ * @returns `true` if the transition succeeded, `false` if CAS failed.
57
+ */
58
+ approveToken(tokenId: string, approvedBy: string): boolean;
59
+ /**
60
+ * Rejects a pending token.
61
+ *
62
+ * Performs an atomic CAS transition: `pending -> rejected`.
63
+ *
64
+ * @param tokenId - The token UUID to reject.
65
+ * @returns `true` if the transition succeeded, `false` if CAS failed.
66
+ */
67
+ rejectToken(tokenId: string): boolean;
68
+ /**
69
+ * Expires a pending token.
70
+ *
71
+ * Performs an atomic CAS transition: `pending -> expired`.
72
+ *
73
+ * @param tokenId - The token UUID to expire.
74
+ * @returns `true` if the transition succeeded, `false` if CAS failed.
75
+ */
76
+ expireToken(tokenId: string): boolean;
77
+ /**
78
+ * Retrieves a token by its UUID.
79
+ *
80
+ * @param tokenId - The token UUID to look up.
81
+ * @returns The token if found, otherwise undefined.
82
+ */
83
+ getToken(tokenId: string): ApprovalToken | undefined;
84
+ /**
85
+ * Lists all tokens for a given session.
86
+ *
87
+ * @param sessionId - The session to filter by.
88
+ * @returns Array of tokens belonging to the session.
89
+ */
90
+ getTokensForSession(sessionId: string): ApprovalToken[];
91
+ /**
92
+ * Computes a SHA-256 hash of a workflow definition string.
93
+ *
94
+ * Used for TOCTOU protection: the hash at token creation time is compared
95
+ * against the hash at approval time.
96
+ *
97
+ * @param workflowText - The raw workflow definition text.
98
+ * @returns Hex-encoded SHA-256 hash.
99
+ */
100
+ static computeWorkflowHash(workflowText: string): string;
101
+ /**
102
+ * Atomically transitions a token from `pending` to the target status.
103
+ *
104
+ * @param tokenId - The token UUID.
105
+ * @param targetStatus - The desired new status.
106
+ * @returns `true` if the CAS transition succeeded.
107
+ */
108
+ private transitionStatus;
109
+ }
110
+ //# sourceMappingURL=approval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval.d.ts","sourceRoot":"","sources":["../../src/cant/approval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAuB,eAAe,EAAE,MAAM,YAAY,CAAC;AAKtF;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,iDAAiD;IACjD,OAAO,CAAC,MAAM,CAAyC;IAEvD;;;;;;;;;;;OAWG;IACH,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,WAAW,GAAE,MAA0B,GACtC,aAAa;IAmBhB;;;;;;;;;;OAUG;IACH,aAAa,CACX,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,EACxB,mBAAmB,EAAE,MAAM,GAC1B,eAAe;IA8BlB;;;;;;;;;OASG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;IAc1D;;;;;;;OAOG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAWrC;;;;;;;OAOG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIrC;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAIpD;;;;;OAKG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE;IAIvD;;;;;;;;OAQG;IACH,MAAM,CAAC,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAIxD;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;CASzB"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Approval gate manager for CANT workflow execution.
3
+ *
4
+ * Manages the lifecycle of approval tokens: generation, validation,
5
+ * approval, rejection, and expiration. Tokens follow the state machine
6
+ * defined in CANT-DSL-SPEC.md Section 8.2.
7
+ *
8
+ * State transitions are atomic (CAS): only `pending -> approved`,
9
+ * `pending -> rejected`, and `pending -> expired` are permitted.
10
+ *
11
+ * @see docs/specs/CANT-DSL-SPEC.md Section 8 (Approval Token Protocol)
12
+ */
13
+ import { createHash, randomUUID } from 'node:crypto';
14
+ /** Default token expiration duration: 24 hours in milliseconds. */
15
+ const DEFAULT_EXPIRY_MS = 24 * 60 * 60 * 1000;
16
+ /**
17
+ * Manages approval tokens for CANT workflow gates.
18
+ *
19
+ * Tokens are stored in-memory per instance. In production, these are
20
+ * persisted via the session's `approvalTokensJson` column in tasks.db.
21
+ */
22
+ export class ApprovalManager {
23
+ /** In-memory token store keyed by token UUID. */
24
+ tokens = new Map();
25
+ /**
26
+ * Generates a new approval token for a workflow gate.
27
+ *
28
+ * @param sessionId - The session that owns this token.
29
+ * @param workflowName - The workflow containing the approval gate.
30
+ * @param gateName - The label of the specific approval gate.
31
+ * @param message - The message to display to the approver.
32
+ * @param workflowHash - SHA-256 hash of the workflow definition.
33
+ * @param requestedBy - The agent/workflow requesting approval.
34
+ * @param expiresInMs - Token lifetime in milliseconds (default: 24h).
35
+ * @returns The generated approval token.
36
+ */
37
+ generateToken(sessionId, workflowName, gateName, message, workflowHash, requestedBy, expiresInMs = DEFAULT_EXPIRY_MS) {
38
+ const now = new Date();
39
+ const token = {
40
+ token: randomUUID(),
41
+ sessionId,
42
+ workflowName,
43
+ gateName,
44
+ workflowHash,
45
+ message,
46
+ createdAt: now.toISOString(),
47
+ expiresAt: new Date(now.getTime() + expiresInMs).toISOString(),
48
+ status: 'pending',
49
+ requestedBy,
50
+ };
51
+ this.tokens.set(token.token, token);
52
+ return token;
53
+ }
54
+ /**
55
+ * Validates an approval token against the current execution context.
56
+ *
57
+ * Checks: (a) token exists, (b) sessionId matches, (c) status is pending,
58
+ * (d) not expired, (e) workflowHash matches current workflow.
59
+ *
60
+ * @param tokenId - The token UUID to validate.
61
+ * @param currentSessionId - The current session to validate against.
62
+ * @param currentWorkflowHash - The current workflow hash for TOCTOU check.
63
+ * @returns Validation result with reason if invalid.
64
+ */
65
+ validateToken(tokenId, currentSessionId, currentWorkflowHash) {
66
+ const token = this.tokens.get(tokenId);
67
+ if (!token) {
68
+ return { valid: false, reason: 'not_found' };
69
+ }
70
+ if (token.sessionId !== currentSessionId) {
71
+ return { valid: false, reason: 'wrong_session', token };
72
+ }
73
+ if (token.status !== 'pending') {
74
+ return { valid: false, reason: 'not_pending', token };
75
+ }
76
+ // Check expiration
77
+ if (new Date(token.expiresAt).getTime() < Date.now()) {
78
+ // Atomically transition to expired
79
+ this.transitionStatus(tokenId, 'expired');
80
+ return { valid: false, reason: 'expired', token: { ...token, status: 'expired' } };
81
+ }
82
+ // TOCTOU: verify workflow has not been modified
83
+ if (token.workflowHash !== currentWorkflowHash) {
84
+ return { valid: false, reason: 'hash_mismatch', token };
85
+ }
86
+ return { valid: true, token };
87
+ }
88
+ /**
89
+ * Approves a pending token.
90
+ *
91
+ * Performs an atomic CAS transition: `pending -> approved`. If the token
92
+ * is not in `pending` state, the operation is a no-op and returns false.
93
+ *
94
+ * @param tokenId - The token UUID to approve.
95
+ * @param approvedBy - The identifier of the approving actor.
96
+ * @returns `true` if the transition succeeded, `false` if CAS failed.
97
+ */
98
+ approveToken(tokenId, approvedBy) {
99
+ const token = this.tokens.get(tokenId);
100
+ if (!token || token.status !== 'pending') {
101
+ return false;
102
+ }
103
+ const now = new Date().toISOString();
104
+ token.status = 'approved';
105
+ token.approvedBy = approvedBy;
106
+ token.approvedAt = now;
107
+ token.usedAt = now;
108
+ return true;
109
+ }
110
+ /**
111
+ * Rejects a pending token.
112
+ *
113
+ * Performs an atomic CAS transition: `pending -> rejected`.
114
+ *
115
+ * @param tokenId - The token UUID to reject.
116
+ * @returns `true` if the transition succeeded, `false` if CAS failed.
117
+ */
118
+ rejectToken(tokenId) {
119
+ const token = this.tokens.get(tokenId);
120
+ if (!token || token.status !== 'pending') {
121
+ return false;
122
+ }
123
+ token.status = 'rejected';
124
+ token.usedAt = new Date().toISOString();
125
+ return true;
126
+ }
127
+ /**
128
+ * Expires a pending token.
129
+ *
130
+ * Performs an atomic CAS transition: `pending -> expired`.
131
+ *
132
+ * @param tokenId - The token UUID to expire.
133
+ * @returns `true` if the transition succeeded, `false` if CAS failed.
134
+ */
135
+ expireToken(tokenId) {
136
+ return this.transitionStatus(tokenId, 'expired');
137
+ }
138
+ /**
139
+ * Retrieves a token by its UUID.
140
+ *
141
+ * @param tokenId - The token UUID to look up.
142
+ * @returns The token if found, otherwise undefined.
143
+ */
144
+ getToken(tokenId) {
145
+ return this.tokens.get(tokenId);
146
+ }
147
+ /**
148
+ * Lists all tokens for a given session.
149
+ *
150
+ * @param sessionId - The session to filter by.
151
+ * @returns Array of tokens belonging to the session.
152
+ */
153
+ getTokensForSession(sessionId) {
154
+ return Array.from(this.tokens.values()).filter((t) => t.sessionId === sessionId);
155
+ }
156
+ /**
157
+ * Computes a SHA-256 hash of a workflow definition string.
158
+ *
159
+ * Used for TOCTOU protection: the hash at token creation time is compared
160
+ * against the hash at approval time.
161
+ *
162
+ * @param workflowText - The raw workflow definition text.
163
+ * @returns Hex-encoded SHA-256 hash.
164
+ */
165
+ static computeWorkflowHash(workflowText) {
166
+ return createHash('sha256').update(workflowText).digest('hex');
167
+ }
168
+ /**
169
+ * Atomically transitions a token from `pending` to the target status.
170
+ *
171
+ * @param tokenId - The token UUID.
172
+ * @param targetStatus - The desired new status.
173
+ * @returns `true` if the CAS transition succeeded.
174
+ */
175
+ transitionStatus(tokenId, targetStatus) {
176
+ const token = this.tokens.get(tokenId);
177
+ if (!token || token.status !== 'pending') {
178
+ return false;
179
+ }
180
+ token.status = targetStatus;
181
+ token.usedAt = new Date().toISOString();
182
+ return true;
183
+ }
184
+ }
185
+ //# sourceMappingURL=approval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/cant/approval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGrD,mEAAmE;AACnE,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAC1B,iDAAiD;IACzC,MAAM,GAA+B,IAAI,GAAG,EAAE,CAAC;IAEvD;;;;;;;;;;;OAWG;IACH,aAAa,CACX,SAAiB,EACjB,YAAoB,EACpB,QAAgB,EAChB,OAAe,EACf,YAAoB,EACpB,WAAmB,EACnB,cAAsB,iBAAiB;QAEvC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAkB;YAC3B,KAAK,EAAE,UAAU,EAAE;YACnB,SAAS;YACT,YAAY;YACZ,QAAQ;YACR,YAAY;YACZ,OAAO;YACP,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE;YAC5B,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC,CAAC,WAAW,EAAE;YAC9D,MAAM,EAAE,SAAS;YACjB,WAAW;SACZ,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;;;OAUG;IACH,aAAa,CACX,OAAe,EACf,gBAAwB,EACxB,mBAA2B;QAE3B,MAAM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AM,CAAC,mBAAmB,CAAC,YAAoB;QAC7C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjE,CAAC;IAED;;;;;;OAMG;IACK,gBAAgB,CAAC,OAAe,EAAE,YAAiC;QACzE,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACzC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC;QAC5B,KAAK,CAAC,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Execution context builder for CANT workflows.
3
+ *
4
+ * Resolves variable references and manages the scope chain for workflow
5
+ * execution. Variables from workflow parameters, step outputs, and
6
+ * intermediate bindings are tracked in a hierarchical scope.
7
+ *
8
+ * @see docs/specs/CANT-DSL-SPEC.md Section 7.2 (Workflow Execution)
9
+ */
10
+ import type { ExecutionScope } from './types.js';
11
+ /**
12
+ * Creates a new root execution scope with initial variable bindings.
13
+ *
14
+ * @param initialBindings - Initial variable values (typically workflow parameters).
15
+ * @returns A new root scope.
16
+ */
17
+ export declare function createScope(initialBindings?: Record<string, unknown>): ExecutionScope;
18
+ /**
19
+ * Creates a child scope that inherits from a parent.
20
+ *
21
+ * Lookups in the child scope fall through to the parent if not found locally.
22
+ * This is used for parallel arms, loop iterations, and nested blocks.
23
+ *
24
+ * @param parent - The parent scope.
25
+ * @param localBindings - Local variable overrides for this child scope.
26
+ * @returns A new child scope.
27
+ */
28
+ export declare function createChildScope(parent: ExecutionScope, localBindings?: Record<string, unknown>): ExecutionScope;
29
+ /**
30
+ * Resolves a variable name in the scope chain.
31
+ *
32
+ * Searches the current scope first, then walks up the parent chain.
33
+ *
34
+ * @param scope - The scope to search in.
35
+ * @param name - The variable name to resolve.
36
+ * @returns The variable value, or `undefined` if not found in any scope.
37
+ */
38
+ export declare function resolveVariable(scope: ExecutionScope, name: string): unknown;
39
+ /**
40
+ * Sets a variable in the current scope (does not affect parent scopes).
41
+ *
42
+ * @param scope - The scope to modify.
43
+ * @param name - The variable name to set.
44
+ * @param value - The value to assign.
45
+ */
46
+ export declare function setVariable(scope: ExecutionScope, name: string, value: unknown): void;
47
+ /**
48
+ * Resolves `{variable}` placeholders in a template string against the scope.
49
+ *
50
+ * Performs single-pass replacement per the T07 security rule: nested
51
+ * interpolation within resolved values is treated as literal text.
52
+ *
53
+ * @param template - The string containing `{variable}` placeholders.
54
+ * @param scope - The execution scope for variable resolution.
55
+ * @returns The string with all placeholders resolved.
56
+ * @throws {Error} If a referenced variable is not found in any scope.
57
+ */
58
+ export declare function resolveTemplate(template: string, scope: ExecutionScope): string;
59
+ /**
60
+ * Merges step output into the current scope.
61
+ *
62
+ * Binds `<stepName>.stdout`, `<stepName>.stderr`, and `<stepName>.exitCode`
63
+ * for use in subsequent step variable resolution.
64
+ *
65
+ * @param scope - The scope to add bindings to.
66
+ * @param stepName - The name of the completed step.
67
+ * @param output - The step output to merge.
68
+ */
69
+ export declare function mergeStepOutput(scope: ExecutionScope, stepName: string, output: Record<string, unknown>): void;
70
+ /**
71
+ * Collects all variable bindings visible from the given scope (including parents).
72
+ *
73
+ * Parent bindings are overridden by child bindings of the same name.
74
+ *
75
+ * @param scope - The scope to flatten.
76
+ * @returns A flat record of all visible variable bindings.
77
+ */
78
+ export declare function flattenScope(scope: ExecutionScope): Record<string, unknown>;
79
+ //# sourceMappingURL=context-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-builder.d.ts","sourceRoot":"","sources":["../../src/cant/context-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,eAAe,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,cAAc,CAIzF;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,cAAc,EACtB,aAAa,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAC1C,cAAc,CAKhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAY5E;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAErF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM,CAQ/E;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,IAAI,CAQN;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAG3E"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Execution context builder for CANT workflows.
3
+ *
4
+ * Resolves variable references and manages the scope chain for workflow
5
+ * execution. Variables from workflow parameters, step outputs, and
6
+ * intermediate bindings are tracked in a hierarchical scope.
7
+ *
8
+ * @see docs/specs/CANT-DSL-SPEC.md Section 7.2 (Workflow Execution)
9
+ */
10
+ /**
11
+ * Creates a new root execution scope with initial variable bindings.
12
+ *
13
+ * @param initialBindings - Initial variable values (typically workflow parameters).
14
+ * @returns A new root scope.
15
+ */
16
+ export function createScope(initialBindings = {}) {
17
+ return {
18
+ variables: { ...initialBindings },
19
+ };
20
+ }
21
+ /**
22
+ * Creates a child scope that inherits from a parent.
23
+ *
24
+ * Lookups in the child scope fall through to the parent if not found locally.
25
+ * This is used for parallel arms, loop iterations, and nested blocks.
26
+ *
27
+ * @param parent - The parent scope.
28
+ * @param localBindings - Local variable overrides for this child scope.
29
+ * @returns A new child scope.
30
+ */
31
+ export function createChildScope(parent, localBindings = {}) {
32
+ return {
33
+ variables: { ...localBindings },
34
+ parent,
35
+ };
36
+ }
37
+ /**
38
+ * Resolves a variable name in the scope chain.
39
+ *
40
+ * Searches the current scope first, then walks up the parent chain.
41
+ *
42
+ * @param scope - The scope to search in.
43
+ * @param name - The variable name to resolve.
44
+ * @returns The variable value, or `undefined` if not found in any scope.
45
+ */
46
+ export function resolveVariable(scope, name) {
47
+ // Check current scope
48
+ if (name in scope.variables) {
49
+ return scope.variables[name];
50
+ }
51
+ // Check parent chain
52
+ if (scope.parent) {
53
+ return resolveVariable(scope.parent, name);
54
+ }
55
+ return undefined;
56
+ }
57
+ /**
58
+ * Sets a variable in the current scope (does not affect parent scopes).
59
+ *
60
+ * @param scope - The scope to modify.
61
+ * @param name - The variable name to set.
62
+ * @param value - The value to assign.
63
+ */
64
+ export function setVariable(scope, name, value) {
65
+ scope.variables[name] = value;
66
+ }
67
+ /**
68
+ * Resolves `{variable}` placeholders in a template string against the scope.
69
+ *
70
+ * Performs single-pass replacement per the T07 security rule: nested
71
+ * interpolation within resolved values is treated as literal text.
72
+ *
73
+ * @param template - The string containing `{variable}` placeholders.
74
+ * @param scope - The execution scope for variable resolution.
75
+ * @returns The string with all placeholders resolved.
76
+ * @throws {Error} If a referenced variable is not found in any scope.
77
+ */
78
+ export function resolveTemplate(template, scope) {
79
+ return template.replace(/\{([^}]+)\}/g, (_match, varName) => {
80
+ const value = resolveVariable(scope, varName);
81
+ if (value === undefined) {
82
+ throw new Error(`Variable '${varName}' not found in execution scope`);
83
+ }
84
+ return String(value);
85
+ });
86
+ }
87
+ /**
88
+ * Merges step output into the current scope.
89
+ *
90
+ * Binds `<stepName>.stdout`, `<stepName>.stderr`, and `<stepName>.exitCode`
91
+ * for use in subsequent step variable resolution.
92
+ *
93
+ * @param scope - The scope to add bindings to.
94
+ * @param stepName - The name of the completed step.
95
+ * @param output - The step output to merge.
96
+ */
97
+ export function mergeStepOutput(scope, stepName, output) {
98
+ // Bind the full output object under the step name
99
+ scope.variables[stepName] = output;
100
+ // Also bind dotted access for convenience
101
+ for (const [key, value] of Object.entries(output)) {
102
+ scope.variables[`${stepName}.${key}`] = value;
103
+ }
104
+ }
105
+ /**
106
+ * Collects all variable bindings visible from the given scope (including parents).
107
+ *
108
+ * Parent bindings are overridden by child bindings of the same name.
109
+ *
110
+ * @param scope - The scope to flatten.
111
+ * @returns A flat record of all visible variable bindings.
112
+ */
113
+ export function flattenScope(scope) {
114
+ const parentVars = scope.parent ? flattenScope(scope.parent) : {};
115
+ return { ...parentVars, ...scope.variables };
116
+ }
117
+ //# sourceMappingURL=context-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-builder.js","sourceRoot":"","sources":["../../src/cant/context-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,kBAA2C,EAAE;IACvE,OAAO;QACL,SAAS,EAAE,EAAE,GAAG,eAAe,EAAE;KAClC,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAsB,EACtB,gBAAyC,EAAE;IAE3C,OAAO;QACL,SAAS,EAAE,EAAE,GAAG,aAAa,EAAE;QAC/B,MAAM;KACP,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,KAAqB,EAAE,IAAY;IACjE,sBAAsB;IACtB,IAAI,IAAI,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QAC5B,OAAO,K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