@humwick/server 0.0.0-stage → 0.130.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 (2508) hide show
  1. package/CLA.md +66 -0
  2. package/CONTRIBUTING.md +144 -0
  3. package/LICENSE +167 -0
  4. package/README.md +511 -2
  5. package/SECURITY.md +67 -0
  6. package/THIRD_PARTY_NOTICES.md +144 -0
  7. package/bundled/prompts/README.md +10 -0
  8. package/bundled/prompts/context.advisory.compact.md +1 -0
  9. package/bundled/prompts/context.advisory.warn.md +1 -0
  10. package/bundled/prompts/continuation.envelope.md +18 -0
  11. package/bundled/prompts/manifest.json +838 -0
  12. package/bundled/prompts/memory.capture.boundary.post.md +1 -0
  13. package/bundled/prompts/memory.capture.boundary.pre.md +1 -0
  14. package/bundled/prompts/memory.charter.md +3 -0
  15. package/bundled/prompts/memory.native-off.md +0 -0
  16. package/bundled/prompts/notify.agent.exited.md +1 -0
  17. package/bundled/prompts/notify.agent.never-ready.md +1 -0
  18. package/bundled/prompts/notify.agent.ready.md +1 -0
  19. package/bundled/prompts/notify.automation.budget-warning.md +1 -0
  20. package/bundled/prompts/notify.land.failure.md +1 -0
  21. package/bundled/prompts/notify.land.steward-taken.coordinator.md +1 -0
  22. package/bundled/prompts/notify.land.steward-taken.md +1 -0
  23. package/bundled/prompts/notify.land.success.md +1 -0
  24. package/bundled/prompts/notify.routing.policy-changed.md +2 -0
  25. package/bundled/prompts/notify.spawn.failed.md +1 -0
  26. package/bundled/prompts/notify.spawn.queued.md +1 -0
  27. package/bundled/prompts/notify.spawn.recovered.md +1 -0
  28. package/bundled/prompts/notify.spawn.unconfirmed.md +1 -0
  29. package/bundled/prompts/profile.coordinator.charter.md +17 -0
  30. package/bundled/prompts/profile.debugger.system.md +12 -0
  31. package/bundled/prompts/profile.device-qa.system.md +10 -0
  32. package/bundled/prompts/profile.image-gen.append.0.md +2 -0
  33. package/bundled/prompts/profile.image-gen.system.md +4 -0
  34. package/bundled/prompts/profile.ops-assistant.brief.md +4 -0
  35. package/bundled/prompts/profile.probe.system.md +5 -0
  36. package/bundled/prompts/profile.qa.system.md +10 -0
  37. package/bundled/prompts/profile.sec-ops.system.md +14 -0
  38. package/bundled/prompts/profile.social-media.system.md +7 -0
  39. package/bundled/prompts/profile.software-design.system.md +26 -0
  40. package/bundled/prompts/profile.sub-coordinator.charter.md +2 -0
  41. package/bundled/prompts/profile.worker-gui.system.md +7 -0
  42. package/bundled/prompts/profile.worker.system.md +2 -0
  43. package/bundled/prompts/relay.agent-core.delivery.md +13 -0
  44. package/bundled/prompts/relay.agent-core.engineering.md +13 -0
  45. package/bundled/prompts/relay.agent-core.md +22 -0
  46. package/bundled/prompts/relay.context.claude.md +1 -0
  47. package/bundled/prompts/relay.context.claude.readonly.md +3 -0
  48. package/bundled/prompts/relay.context.codex.md +1 -0
  49. package/bundled/prompts/relay.context.opencode.md +1 -0
  50. package/bundled/prompts/relay.manual.claude.md +8 -0
  51. package/bundled/prompts/relay.search.fff.md +1 -0
  52. package/bundled/prompts/relay.temp-dir.md +1 -0
  53. package/bundled/prompts/relay.web.brave.md +1 -0
  54. package/bundled/prompts/relay.web.fetch.md +1 -0
  55. package/bundled/prompts/skill.device-lane.md +20 -0
  56. package/bundled/prompts/skill.security-code-review.md +10 -0
  57. package/bundled/prompts/skill.security-hardening.md +10 -0
  58. package/bundled/prompts/skill.security-host-audit.md +11 -0
  59. package/bundled/prompts/spawn.primer.md +6 -0
  60. package/bundled/prompts/spawn.reportup.child.md +3 -0
  61. package/bundled/prompts/spawn.reportup.coordinator.md +2 -0
  62. package/bundled/prompts/spawn.reportup.workflow-step.md +4 -0
  63. package/bundled/prompts/spawn.validation.delivery.md +1 -0
  64. package/bundled/prompts/spawn.validation.iterate.generic.md +1 -0
  65. package/bundled/prompts/spawn.validation.iterate.imperative.md +1 -0
  66. package/bundled/prompts/spawn.validation.landgates.header.md +1 -0
  67. package/bundled/prompts/steward.merge-stall.md +1 -0
  68. package/bundled/prompts/steward.prompt.md +20 -0
  69. package/bundled/prompts/steward.wake.md +1 -0
  70. package/bundled/prompts/task.claim.instruction.md +1 -0
  71. package/bundled/prompts/task.hydration.md +23 -0
  72. package/bundled/prompts/user.response.brief.md +1 -0
  73. package/bundled/prompts/user.response.normal.md +1 -0
  74. package/bundled/prompts/user.style.neutral.md +1 -0
  75. package/bundled/prompts/user.style.warm.md +1 -0
  76. package/bundled/prompts/workspace.deps.command.md +1 -0
  77. package/bundled/prompts/workspace.deps.none.md +1 -0
  78. package/bundled/prompts/workspace.deps.symlink.md +1 -0
  79. package/bundled/prompts/workspace.lifecycle.md +4 -0
  80. package/bundled/prompts/workspace.mcp.instructions.md +7 -0
  81. package/bundled/prompts/workspace.phase.abandoned.headline.md +1 -0
  82. package/bundled/prompts/workspace.phase.abandoned.hint.md +1 -0
  83. package/bundled/prompts/workspace.phase.active.headline.md +1 -0
  84. package/bundled/prompts/workspace.phase.active.hint.md +1 -0
  85. package/bundled/prompts/workspace.phase.conflict.headline.md +1 -0
  86. package/bundled/prompts/workspace.phase.conflict.hint.md +1 -0
  87. package/bundled/prompts/workspace.phase.merge-planned.headline.md +1 -0
  88. package/bundled/prompts/workspace.phase.merge-planned.hint.md +1 -0
  89. package/bundled/prompts/workspace.phase.merged.headline.md +1 -0
  90. package/bundled/prompts/workspace.phase.merged.hint.md +1 -0
  91. package/bundled/prompts/workspace.phase.ready.headline.md +1 -0
  92. package/bundled/prompts/workspace.phase.ready.hint.md +1 -0
  93. package/bundled/prompts/workspace.ready.contract.md +6 -0
  94. package/bundled/prompts/workspace.symlinks.md +1 -0
  95. package/bundled/roles/builder.md +18 -0
  96. package/bundled/roles/design-reviewer.md +13 -0
  97. package/bundled/roles/designer.md +11 -0
  98. package/bundled/roles/plan-auditor.md +29 -0
  99. package/bundled/roles/reviewer.md +36 -0
  100. package/bundled/roles/slice-qa.md +13 -0
  101. package/bundled/roles/verifier.md +13 -0
  102. package/bundled/skills/agent-browser/SKILL.md +72 -0
  103. package/bundled/skills/test-audit/SKILL.md +75 -0
  104. package/bundled/workflows/build-review.yaml +8 -0
  105. package/bundled/workflows/design-review.yaml +60 -0
  106. package/bundled/workflows/plan-conformance.yaml +5 -0
  107. package/bundled/workflows/slice-proof.yaml +85 -0
  108. package/bundled/workflows/verify-deployed.yaml +140 -0
  109. package/docs/guides/sub-coordinators.md +114 -0
  110. package/docs/guides/tools-administration.md +83 -0
  111. package/docs/guides/tools-agents.md +137 -0
  112. package/docs/guides/tools-coordination.md +228 -0
  113. package/docs/guides/tools-execution.md +48 -0
  114. package/docs/guides/tools-issues.md +69 -0
  115. package/docs/guides/tools-memory.md +150 -0
  116. package/docs/guides/tools-messages.md +192 -0
  117. package/docs/guides/tools-operations.md +133 -0
  118. package/docs/guides/tools-tasks.md +235 -0
  119. package/docs/guides/workflows.md +324 -0
  120. package/docs/license-faq.md +37 -0
  121. package/docs/openapi.json +18531 -0
  122. package/examples/integrations/github-issue.ts +48 -0
  123. package/examples/integrations/ops-alert.sh +27 -0
  124. package/examples/integrations/prometheus-alertmanager.ts +55 -0
  125. package/examples/integrations/support-ticket.sh +28 -0
  126. package/node_modules/@humwick/kernel/LICENSE +167 -0
  127. package/node_modules/@humwick/kernel/async-entity-persistence.ts +344 -0
  128. package/node_modules/@humwick/kernel/async-event-log.ts +107 -0
  129. package/node_modules/@humwick/kernel/automations.pilot.ts +147 -0
  130. package/node_modules/@humwick/kernel/config.ts +111 -0
  131. package/node_modules/@humwick/kernel/contract.ts +572 -0
  132. package/node_modules/@humwick/kernel/control-authz.ts +281 -0
  133. package/node_modules/@humwick/kernel/control.ts +645 -0
  134. package/node_modules/@humwick/kernel/effects.ts +493 -0
  135. package/node_modules/@humwick/kernel/event-log.ts +319 -0
  136. package/node_modules/@humwick/kernel/http-transport.ts +384 -0
  137. package/node_modules/@humwick/kernel/identity-grammar.ts +20 -0
  138. package/node_modules/@humwick/kernel/identity.ts +248 -0
  139. package/node_modules/@humwick/kernel/index.ts +28 -0
  140. package/node_modules/@humwick/kernel/kernel-persistence.ts +181 -0
  141. package/node_modules/@humwick/kernel/landing-incident.ts +306 -0
  142. package/node_modules/@humwick/kernel/landing.ts +953 -0
  143. package/node_modules/@humwick/kernel/manifest-validation.ts +460 -0
  144. package/node_modules/@humwick/kernel/mcp-transport.ts +109 -0
  145. package/node_modules/@humwick/kernel/message-authority-chaos-worker.ts +200 -0
  146. package/node_modules/@humwick/kernel/message-authority.ts +281 -0
  147. package/node_modules/@humwick/kernel/module-host.ts +722 -0
  148. package/node_modules/@humwick/kernel/openapi-init.ts +14 -0
  149. package/node_modules/@humwick/kernel/package.json +47 -0
  150. package/node_modules/@humwick/kernel/persistence-schema.ts +248 -0
  151. package/node_modules/@humwick/kernel/persistence.ts +510 -0
  152. package/node_modules/@humwick/kernel/registry.ts +60 -0
  153. package/node_modules/@humwick/kernel/sqlite-kernel-persistence.ts +499 -0
  154. package/node_modules/@humwick/kernel/sqlite-module-host.ts +87 -0
  155. package/node_modules/@humwick/kernel/timers-chaos-worker.ts +186 -0
  156. package/node_modules/@humwick/kernel/timers.pilot.ts +1411 -0
  157. package/node_modules/@humwick/kernel/workflow-activation.ts +25 -0
  158. package/node_modules/@humwick/kernel/workflow-backstop.ts +40 -0
  159. package/node_modules/@humwick/kernel/workflow-cancel-tree.ts +20 -0
  160. package/node_modules/@humwick/kernel/workflow-chaos-worker.ts +213 -0
  161. package/node_modules/@humwick/kernel/workflow-composition.ts +231 -0
  162. package/node_modules/@humwick/kernel/workflow-container.ts +72 -0
  163. package/node_modules/@humwick/kernel/workflow-control.test-fixture.ts +42 -0
  164. package/node_modules/@humwick/kernel/workflow-control.ts +178 -0
  165. package/node_modules/@humwick/kernel/workflow-definition.ts +507 -0
  166. package/node_modules/@humwick/kernel/workflow-dispatch.ts +60 -0
  167. package/node_modules/@humwick/kernel/workflow-foreach.ts +167 -0
  168. package/node_modules/@humwick/kernel/workflow-journal-codec.ts +339 -0
  169. package/node_modules/@humwick/kernel/workflow-journal.ts +922 -0
  170. package/node_modules/@humwick/kernel/workflow-lane.ts +48 -0
  171. package/node_modules/@humwick/kernel/workflow-lease-owner.ts +60 -0
  172. package/node_modules/@humwick/kernel/workflow-recovery.test-fixture.ts +19 -0
  173. package/node_modules/@humwick/kernel/workflow-runtime.ts +938 -0
  174. package/node_modules/@humwick/kernel/workflow-script.ts +11 -0
  175. package/node_modules/@humwick/kernel/workflow-state.ts +299 -0
  176. package/node_modules/@humwick/kernel/workflow-step-commit.ts +195 -0
  177. package/node_modules/@humwick/kernel/workflow-transitions.ts +317 -0
  178. package/node_modules/@humwick/kernel/workflow-values.ts +153 -0
  179. package/node_modules/@humwick/kernel/workflow.pilot.ts +376 -0
  180. package/node_modules/@humwick/offload/LICENSE +167 -0
  181. package/node_modules/@humwick/offload/README.md +57 -0
  182. package/node_modules/@humwick/offload/dist/async-runner.d.ts +18 -0
  183. package/node_modules/@humwick/offload/dist/async-runner.d.ts.map +1 -0
  184. package/node_modules/@humwick/offload/dist/async-runner.js +158 -0
  185. package/node_modules/@humwick/offload/dist/async-runner.js.map +1 -0
  186. package/node_modules/@humwick/offload/dist/envelope.d.ts +25 -0
  187. package/node_modules/@humwick/offload/dist/envelope.d.ts.map +1 -0
  188. package/node_modules/@humwick/offload/dist/envelope.js +80 -0
  189. package/node_modules/@humwick/offload/dist/envelope.js.map +1 -0
  190. package/node_modules/@humwick/offload/dist/fixtures/worker-task.d.ts +10 -0
  191. package/node_modules/@humwick/offload/dist/fixtures/worker-task.d.ts.map +1 -0
  192. package/node_modules/@humwick/offload/dist/fixtures/worker-task.js +59 -0
  193. package/node_modules/@humwick/offload/dist/fixtures/worker-task.js.map +1 -0
  194. package/node_modules/@humwick/offload/dist/index.d.ts +5 -0
  195. package/node_modules/@humwick/offload/dist/index.d.ts.map +1 -0
  196. package/node_modules/@humwick/offload/dist/index.js +5 -0
  197. package/node_modules/@humwick/offload/dist/index.js.map +1 -0
  198. package/node_modules/@humwick/offload/dist/subprocess-runner.d.ts +62 -0
  199. package/node_modules/@humwick/offload/dist/subprocess-runner.d.ts.map +1 -0
  200. package/node_modules/@humwick/offload/dist/subprocess-runner.js +295 -0
  201. package/node_modules/@humwick/offload/dist/subprocess-runner.js.map +1 -0
  202. package/node_modules/@humwick/offload/dist/types.d.ts +111 -0
  203. package/node_modules/@humwick/offload/dist/types.d.ts.map +1 -0
  204. package/node_modules/@humwick/offload/dist/types.js +176 -0
  205. package/node_modules/@humwick/offload/dist/types.js.map +1 -0
  206. package/node_modules/@humwick/offload/dist/worker-pool.d.ts +23 -0
  207. package/node_modules/@humwick/offload/dist/worker-pool.d.ts.map +1 -0
  208. package/node_modules/@humwick/offload/dist/worker-pool.js +435 -0
  209. package/node_modules/@humwick/offload/dist/worker-pool.js.map +1 -0
  210. package/node_modules/@humwick/offload/dist/worker-runtime.d.ts +2 -0
  211. package/node_modules/@humwick/offload/dist/worker-runtime.d.ts.map +1 -0
  212. package/node_modules/@humwick/offload/dist/worker-runtime.js +27 -0
  213. package/node_modules/@humwick/offload/dist/worker-runtime.js.map +1 -0
  214. package/node_modules/@humwick/offload/dist/worker.d.ts +5 -0
  215. package/node_modules/@humwick/offload/dist/worker.d.ts.map +1 -0
  216. package/node_modules/@humwick/offload/dist/worker.js +1 -0
  217. package/node_modules/@humwick/offload/dist/worker.js.map +1 -0
  218. package/node_modules/@humwick/offload/package.json +46 -0
  219. package/node_modules/@humwick/offload/src/async-runner.ts +170 -0
  220. package/node_modules/@humwick/offload/src/envelope.ts +92 -0
  221. package/node_modules/@humwick/offload/src/fixtures/worker-task.ts +49 -0
  222. package/node_modules/@humwick/offload/src/index.ts +4 -0
  223. package/node_modules/@humwick/offload/src/subprocess-runner.ts +334 -0
  224. package/node_modules/@humwick/offload/src/types.ts +235 -0
  225. package/node_modules/@humwick/offload/src/worker-pool.ts +463 -0
  226. package/node_modules/@humwick/offload/src/worker-runtime.ts +32 -0
  227. package/node_modules/@humwick/offload/src/worker.ts +5 -0
  228. package/package.json +229 -4
  229. package/public/assets/MessageBubble-BWpoBjl4.js +4 -0
  230. package/public/assets/PlanGraphPanel-C0auck3n.js +2 -0
  231. package/public/assets/TraceView-DBnOx7AQ.js +5 -0
  232. package/public/assets/VaultDecisionCard-0kp2oNBC.js +2 -0
  233. package/public/assets/activity-TMzFOdh2.js +2 -0
  234. package/public/assets/activity-yLztXEBt.js +2 -0
  235. package/public/assets/agent-lineage-BbJDR1dW.js +2 -0
  236. package/public/assets/agent-liveness-DyqxfB-t.js +2 -0
  237. package/public/assets/agent-name-CTZBrSD9.js +2 -0
  238. package/public/assets/agent-profiles-BpI_jTxq.js +2 -0
  239. package/public/assets/agent-project-badge-9TqzUUYE.js +2 -0
  240. package/public/assets/agent-tools-D4n40pn8.js +2 -0
  241. package/public/assets/agent-type-icon-D6FUarOf.js +2 -0
  242. package/public/assets/agents-BYDslkJc.js +2 -0
  243. package/public/assets/analytics-B-XSbEMC.js +910 -0
  244. package/public/assets/andromeeda-vGVdxbeo.js +2 -0
  245. package/public/assets/angular-html-BVBpGdXr.js +2 -0
  246. package/public/assets/angular-ts-BfdufMKP.js +2 -0
  247. package/public/assets/api-CIIVBtAV.js +10 -0
  248. package/public/assets/archive-CIuPSvmx.js +2 -0
  249. package/public/assets/arrow-right-vFsRqG8V.js +2 -0
  250. package/public/assets/arrow-up-a-z-CKC2RCjD.js +2 -0
  251. package/public/assets/artifact-viewer-DdWIfV6M.js +2 -0
  252. package/public/assets/artifacts-DPN1q4pA.js +2 -0
  253. package/public/assets/artifacts-oBOqks-2.js +2 -0
  254. package/public/assets/astro-JKRPP03v.js +2 -0
  255. package/public/assets/aurora-x-CDeNXAV0.js +2 -0
  256. package/public/assets/automation-4KcRFXEu.js +2 -0
  257. package/public/assets/ayu-dark-DluEY0Gj.js +2 -0
  258. package/public/assets/ayu-light-C3h-C4tm.js +2 -0
  259. package/public/assets/ayu-mirage-Bqwy1Gya.js +2 -0
  260. package/public/assets/backlog-Cw9xPTCF.js +2 -0
  261. package/public/assets/badge-DqJRtj_p.js +2 -0
  262. package/public/assets/bell-_Yzbxxrt.js +2 -0
  263. package/public/assets/blade-DA8yMPsw.js +2 -0
  264. package/public/assets/bot-B0NpDNhr.js +2 -0
  265. package/public/assets/boxes-Cv7Wq3h4.js +2 -0
  266. package/public/assets/braces-BOks9SsY.js +2 -0
  267. package/public/assets/brain-CagXMEKE.js +2 -0
  268. package/public/assets/brain-circuit-CpQeSmp3.js +2 -0
  269. package/public/assets/bundle-web-ifbJd0t-.js +14 -0
  270. package/public/assets/busy-health-CTu32MZt.js +2 -0
  271. package/public/assets/button-Do6Z3vvn.js +2 -0
  272. package/public/assets/c-Wt1voDr2.js +2 -0
  273. package/public/assets/calendar-QJjoZ1JU.js +2 -0
  274. package/public/assets/calendar-clock-CDG_KBhx.js +2 -0
  275. package/public/assets/card-C4QJ4hCW.js +2 -0
  276. package/public/assets/catppuccin-frappe-3VR1Za6u.js +2 -0
  277. package/public/assets/catppuccin-latte-DwIHMF0Q.js +2 -0
  278. package/public/assets/catppuccin-macchiato-DYnBP6_5.js +2 -0
  279. package/public/assets/catppuccin-mocha-DYhrFGRu.js +2 -0
  280. package/public/assets/channels-BiXzg1G9.js +2 -0
  281. package/public/assets/chart-column-S02ZGfTR.js +2 -0
  282. package/public/assets/chat-Ctk2qwvA.js +6 -0
  283. package/public/assets/check-B3M9Ug1P.js +2 -0
  284. package/public/assets/chevron-down-BoG3JCZn.js +2 -0
  285. package/public/assets/chevron-right-iljytE0x.js +2 -0
  286. package/public/assets/chevron-up-Bv3yC5ma.js +2 -0
  287. package/public/assets/circle-UESLMi2-.js +2 -0
  288. package/public/assets/circle-alert-CryagaZd.js +2 -0
  289. package/public/assets/circle-arrow-up-B432r0Kk.js +2 -0
  290. package/public/assets/circle-check-CkUkN96J.js +2 -0
  291. package/public/assets/circle-x-CZ0erS7Q.js +2 -0
  292. package/public/assets/clipboard-list-W2YeUsxT.js +2 -0
  293. package/public/assets/clock-3-BH47318N.js +2 -0
  294. package/public/assets/clock-BWPPBh1_.js +2 -0
  295. package/public/assets/code-preview-Bm1wWqAp.js +3 -0
  296. package/public/assets/coffee-CThvmt4R.js +2 -0
  297. package/public/assets/connectors-C36ax4Vw.js +2 -0
  298. package/public/assets/copy-DFxhHRtV.js +2 -0
  299. package/public/assets/copy-button-CjOj4HEf.js +2 -0
  300. package/public/assets/cosmos-Dn8XrlnS.css +1 -0
  301. package/public/assets/cosmos-Jj9LK2Wf.js +3993 -0
  302. package/public/assets/cpp-C5WNSHb9.js +2 -0
  303. package/public/assets/cpu-Dndy84IU.js +2 -0
  304. package/public/assets/crate-agent-H6S7-B9T.js +2 -0
  305. package/public/assets/css-DJp_X0uY.js +2 -0
  306. package/public/assets/csv-Dx-8-gkx.js +2 -0
  307. package/public/assets/dark-plus-Cs2F2srj.js +2 -0
  308. package/public/assets/dependency-graph-Cd1E23wa.js +2 -0
  309. package/public/assets/deploys-Bwfq146q.js +2 -0
  310. package/public/assets/dialog-uuJ9_geR.js +6 -0
  311. package/public/assets/display-CfO7rTuF.js +3 -0
  312. package/public/assets/dist-B2h2GeWt.js +2 -0
  313. package/public/assets/dist-BeVYU67E.js +2 -0
  314. package/public/assets/dist-Bmm-RKub.js +2 -0
  315. package/public/assets/dist-C1xmD7qJ.js +2 -0
  316. package/public/assets/dist-C2J943E6.js +2 -0
  317. package/public/assets/dist-C6lpJDoA.js +2 -0
  318. package/public/assets/dist-CoWL6B0c.js +2 -0
  319. package/public/assets/dist-D93SmTNC.js +2 -0
  320. package/public/assets/dist-Da7HrHNA.js +2 -0
  321. package/public/assets/dist-DeW2Y1R5.js +2 -0
  322. package/public/assets/dist-DwBdqQ6H.js +2 -0
  323. package/public/assets/dist-Dz182zaW.js +2 -0
  324. package/public/assets/dist-H3DLHJ0C.js +2 -0
  325. package/public/assets/dist-RrY9C4SI.js +2 -0
  326. package/public/assets/download-KgtpDbt5.js +2 -0
  327. package/public/assets/dracula-BHWKrbxM.js +2 -0
  328. package/public/assets/dracula-soft-5eyTD99u.js +2 -0
  329. package/public/assets/dropdown-menu-BXiNephE.js +2 -0
  330. package/public/assets/es2015-DMmZ8vbD.js +42 -0
  331. package/public/assets/esm-ZSuD7QuY.js +2 -0
  332. package/public/assets/everforest-dark-sB-x3p7T.js +2 -0
  333. package/public/assets/everforest-light-Df2xbC6M.js +2 -0
  334. package/public/assets/external-link-BRfu-fHG.js +2 -0
  335. package/public/assets/eye-BAP6fHrX.js +2 -0
  336. package/public/assets/file-code-corner-CXhIR1vB.js +2 -0
  337. package/public/assets/file-pen-Crunre5f.js +2 -0
  338. package/public/assets/file-text-CKuoMR2U.js +2 -0
  339. package/public/assets/files-DhhZI2Ih.js +3 -0
  340. package/public/assets/flag-CnEG9PH-.js +2 -0
  341. package/public/assets/flame-CxBuz46L.js +2 -0
  342. package/public/assets/fleet-BL4UXS_k.js +2 -0
  343. package/public/assets/fleet-metrics-BkHP-P3R.js +2 -0
  344. package/public/assets/folder-git-2-CJOmTT06.js +2 -0
  345. package/public/assets/folder-open-CBUCMSlu.js +2 -0
  346. package/public/assets/folder-tree-BG3Y9nqH.js +2 -0
  347. package/public/assets/formatted-body-Cm1RrzmN.js +3 -0
  348. package/public/assets/formatted-body-impl-DQiOuOD1.js +3 -0
  349. package/public/assets/gauge-BIODY-BQ.js +2 -0
  350. package/public/assets/geist-cyrillic-wght-normal-CHSlOQsW.woff2 +0 -0
  351. package/public/assets/geist-latin-ext-wght-normal-DMtmJ5ZE.woff2 +0 -0
  352. package/public/assets/geist-latin-wght-normal-Dm3htQBi.woff2 +0 -0
  353. package/public/assets/git-branch-yxhV0m8E.js +2 -0
  354. package/public/assets/git-commit-horizontal-DS1pJ_SS.js +2 -0
  355. package/public/assets/git-merge-C7eIG425.js +2 -0
  356. package/public/assets/github-dark-C-LZuMrd.js +2 -0
  357. package/public/assets/github-dark-default-DXG-b-1a.js +2 -0
  358. package/public/assets/github-dark-dimmed-Bx1FflLF.js +2 -0
  359. package/public/assets/github-dark-high-contrast-B_tTalzw.js +2 -0
  360. package/public/assets/github-light-EUqPIrTm.js +2 -0
  361. package/public/assets/github-light-default-BXViO-2h.js +2 -0
  362. package/public/assets/github-light-high-contrast-B68TUdTA.js +2 -0
  363. package/public/assets/globe-Cl5fXtqs.js +2 -0
  364. package/public/assets/glsl-Dv5r7kPw.js +2 -0
  365. package/public/assets/graphql-CcFwQwm0.js +2 -0
  366. package/public/assets/gruvbox-dark-hard-C820rvS2.js +2 -0
  367. package/public/assets/gruvbox-dark-medium-BPjhmG05.js +2 -0
  368. package/public/assets/gruvbox-dark-soft-MrdJrrXF.js +2 -0
  369. package/public/assets/gruvbox-light-hard-BC_s9l72.js +2 -0
  370. package/public/assets/gruvbox-light-medium-BAWPOn9u.js +2 -0
  371. package/public/assets/gruvbox-light-soft-BSMLrYjP.js +2 -0
  372. package/public/assets/haml-Bg4I2hiD.js +2 -0
  373. package/public/assets/handlebars-DnwbnL5R.js +2 -0
  374. package/public/assets/hash-CbtKih3g.js +2 -0
  375. package/public/assets/horizon-CE9ld1lL.js +2 -0
  376. package/public/assets/horizon-bright-DSNQnXHK.js +2 -0
  377. package/public/assets/host-mTgRw7xh.js +2 -0
  378. package/public/assets/host-providers-dialog-CHqwXTov.js +2 -0
  379. package/public/assets/hourglass-txu4ax6n.js +2 -0
  380. package/public/assets/houston-CsvMBhTu.js +2 -0
  381. package/public/assets/html-C8UlPnhE.js +2 -0
  382. package/public/assets/html-derivative-CY6NRz-J.js +2 -0
  383. package/public/assets/http-CoW620Fi.js +2 -0
  384. package/public/assets/humwick-lockup-on-dark-Ds44Y7BK.svg +19 -0
  385. package/public/assets/humwick-lockup-on-light-ClALZAHt.svg +19 -0
  386. package/public/assets/hurl-CSSETujw.js +2 -0
  387. package/public/assets/imba-DsUTQ-LC.js +2 -0
  388. package/public/assets/inbox-Dfwk3Gt8.js +2 -0
  389. package/public/assets/index-B7ZerHLY.css +2 -0
  390. package/public/assets/index-BK0WV6hF.js +15 -0
  391. package/public/assets/input-CsTB6jIx.js +2 -0
  392. package/public/assets/insights-fH1EL-qZ.js +2 -0
  393. package/public/assets/integrations-C5Oix6ng.js +2 -0
  394. package/public/assets/issue-ref-chip-ODyondIa.js +3 -0
  395. package/public/assets/java-CGc3VwQr.js +2 -0
  396. package/public/assets/javascript-CUt1pgmJ.js +2 -0
  397. package/public/assets/jinja-CD-Z-FLd.js +2 -0
  398. package/public/assets/jison-imPNup1l.js +2 -0
  399. package/public/assets/json-qhed-kSA.js +2 -0
  400. package/public/assets/json5-BR5RXkoi.js +2 -0
  401. package/public/assets/jsonc-CYpm1nAK.js +2 -0
  402. package/public/assets/jsonl-CmCQp5Yx.js +2 -0
  403. package/public/assets/jsx-CY6oMTks.js +2 -0
  404. package/public/assets/julia-CjffhBEM.js +2 -0
  405. package/public/assets/kanagawa-dragon-CXtmUGW6.js +2 -0
  406. package/public/assets/kanagawa-lotus-BN08jTvb.js +2 -0
  407. package/public/assets/kanagawa-wave-CTweb8Dz.js +2 -0
  408. package/public/assets/kernel-Bqr0CZGv.js +2 -0
  409. package/public/assets/key-round-CcSxl5qr.js +2 -0
  410. package/public/assets/keyboard-DcmEulph.js +2 -0
  411. package/public/assets/label-BPBzm9FJ.js +2 -0
  412. package/public/assets/laserwave-C_8bwKvT.js +2 -0
  413. package/public/assets/layers-DEfClY-v.js +2 -0
  414. package/public/assets/legacy-storage-carry-C-tBSxRA.js +2 -0
  415. package/public/assets/less-DVTAwKKz.js +2 -0
  416. package/public/assets/lib-D7DTGM1F.js +2 -0
  417. package/public/assets/lib-G-25QXXf.js +30 -0
  418. package/public/assets/light-plus-DVQuIRkW.js +2 -0
  419. package/public/assets/lightbulb-RDhZ4p-D.js +2 -0
  420. package/public/assets/link-2-off-DfRF9Hwb.js +2 -0
  421. package/public/assets/link-6RR7Hy3-.js +2 -0
  422. package/public/assets/list-checks-CwnS3hly.js +2 -0
  423. package/public/assets/list-ordered-D8nCM7rT.js +2 -0
  424. package/public/assets/list-todo-9qT0fgxZ.js +2 -0
  425. package/public/assets/loader-circle-BfPd4kOD.js +2 -0
  426. package/public/assets/lock-BW8MPKw_.js +2 -0
  427. package/public/assets/log-viewer-Cvfy6PW7.js +4 -0
  428. package/public/assets/mail-DyaDmwfY.js +2 -0
  429. package/public/assets/maintenance-D8CDH5wZ.js +2 -0
  430. package/public/assets/managed-agents-egllbpij.js +4 -0
  431. package/public/assets/markdown-BYOwaDjH.js +2 -0
  432. package/public/assets/markdown-preview-CYSFgVgK.js +3 -0
  433. package/public/assets/markdown-preview-impl-BteVIjX4.js +2 -0
  434. package/public/assets/marko-DvhNOisQ.js +2 -0
  435. package/public/assets/material-theme-Bm3Qr25_.js +2 -0
  436. package/public/assets/material-theme-darker-2IIEA8gg.js +2 -0
  437. package/public/assets/material-theme-lighter-uhdI0v04.js +2 -0
  438. package/public/assets/material-theme-ocean-CHQ94UKr.js +2 -0
  439. package/public/assets/material-theme-palenight-B5W6OYN7.js +2 -0
  440. package/public/assets/mdc-CazklSAj.js +2 -0
  441. package/public/assets/mdx-DQZ5AkYe.js +2 -0
  442. package/public/assets/memory-C8WmXsyr.js +2 -0
  443. package/public/assets/message-circle-wjztgHBe.js +2 -0
  444. package/public/assets/message-square-C-1G8dMM.js +2 -0
  445. package/public/assets/message-square-reply-B9Z4cbQx.js +2 -0
  446. package/public/assets/messages-BzQdqlO6.js +2 -0
  447. package/public/assets/messages-square-DVM1ZtcI.js +2 -0
  448. package/public/assets/min-dark-BSWPekZh.js +2 -0
  449. package/public/assets/min-light-DDpmG2fV.js +2 -0
  450. package/public/assets/minimize-2-BkK6XoMP.js +2 -0
  451. package/public/assets/monokai-CdkpiU2Y.js +2 -0
  452. package/public/assets/night-owl-DhmEMT88.js +2 -0
  453. package/public/assets/night-owl-light-eJ-hLW7d.js +2 -0
  454. package/public/assets/nord-Cb4Vim4T.js +2 -0
  455. package/public/assets/octagon-x-B5lnUY-8.js +2 -0
  456. package/public/assets/one-dark-pro-CLwyXe_n.js +2 -0
  457. package/public/assets/one-light-D7Lr4KcI.js +2 -0
  458. package/public/assets/orchestrators-B1HxzkNw.js +2 -0
  459. package/public/assets/overview-DCUnI4Z7.js +2 -0
  460. package/public/assets/package-open-ckPgcjpv.js +2 -0
  461. package/public/assets/package-plus-C1AKMjsl.js +2 -0
  462. package/public/assets/pairs-ftCd2XcD.js +2 -0
  463. package/public/assets/paperclip-CNpKZKum.js +2 -0
  464. package/public/assets/pause-DttnHD4c.js +2 -0
  465. package/public/assets/pencil-B1Hf2V_J.js +2 -0
  466. package/public/assets/php-CBqsN0ai.js +2 -0
  467. package/public/assets/pin-DcsKeXxr.js +2 -0
  468. package/public/assets/plastic-DQwYfKfQ.js +2 -0
  469. package/public/assets/play-BbT8m7A0.js +2 -0
  470. package/public/assets/plug-vIyO9_P8.js +2 -0
  471. package/public/assets/plug-zap-V0wMDJ-G.js +2 -0
  472. package/public/assets/plus-D5Ek4e2S.js +2 -0
  473. package/public/assets/poimandres-DRFjx7u4.js +2 -0
  474. package/public/assets/popover-8w1TWKMG.js +2 -0
  475. package/public/assets/postcss-BXeXVLqQ.js +2 -0
  476. package/public/assets/power-6tZOhYPg.js +2 -0
  477. package/public/assets/preload-helper-HclGiUj8.js +1 -0
  478. package/public/assets/profile-icon-B2zH8DMH.js +2 -0
  479. package/public/assets/projects-B_lmcqfO.js +2 -0
  480. package/public/assets/prompt-settings-Bftq9czX.js +2 -0
  481. package/public/assets/provider-brand-icon-_67JR7Zh.js +2 -0
  482. package/public/assets/provider-display-DbLWpP3j.js +2 -0
  483. package/public/assets/pug-C5hz5LQ7.js +2 -0
  484. package/public/assets/python-gzcpVVnB.js +2 -0
  485. package/public/assets/r-Dzep-lPg.js +2 -0
  486. package/public/assets/radio-Bn0_qc0G.js +2 -0
  487. package/public/assets/react-dom-DSFxiC7T.js +2 -0
  488. package/public/assets/red-CJ3rzSJv.js +2 -0
  489. package/public/assets/refresh-cw-CfpvQcUn.js +2 -0
  490. package/public/assets/regexp-Omp9DhTb.js +2 -0
  491. package/public/assets/registry-DWCU5c8q.js +4 -0
  492. package/public/assets/repeat-hl4p_Klo.js +2 -0
  493. package/public/assets/rocket-BmO1qSu-.js +2 -0
  494. package/public/assets/rolldown-runtime-QTnfLwEv.js +1 -0
  495. package/public/assets/rose-pine-BthvhNj6.js +2 -0
  496. package/public/assets/rose-pine-dawn-Dg85fqjY.js +2 -0
  497. package/public/assets/rose-pine-moon-hon4tzzS.js +2 -0
  498. package/public/assets/rotate-ccw-CtD77qkX.js +2 -0
  499. package/public/assets/rotate-cw-FPtkDewA.js +2 -0
  500. package/public/assets/run-card-CO_bguQf.js +2 -0
  501. package/public/assets/sass-DXrisJhu.js +2 -0
  502. package/public/assets/save-B_PGqSm4.js +2 -0
  503. package/public/assets/scroll-area-CIN4KQse.js +2 -0
  504. package/public/assets/scss-DdSxiZKl.js +2 -0
  505. package/public/assets/search-DjzbnTbf.js +2 -0
  506. package/public/assets/secrets-C7GIUATz.js +2 -0
  507. package/public/assets/security-BUFau5-N.js +3 -0
  508. package/public/assets/select-DTQMP4Dk.js +2 -0
  509. package/public/assets/separator-t1cLZErD.js +2 -0
  510. package/public/assets/server-CZIRjFyY.js +2 -0
  511. package/public/assets/service-access-settings-C3aujqTG.js +2 -0
  512. package/public/assets/settings-C6sZ9eBa.js +6 -0
  513. package/public/assets/shellscript-CLZ0U2zV.js +2 -0
  514. package/public/assets/shield-CtXNUA0i.js +2 -0
  515. package/public/assets/shield-alert-B9jCWcKW.js +2 -0
  516. package/public/assets/shipping-Bu8p1gEw.js +2 -0
  517. package/public/assets/shipping-stats-BiMTsA4A.js +2 -0
  518. package/public/assets/slack-dark-DnToyrRv.js +2 -0
  519. package/public/assets/slack-ochin-B2OO5cIa.js +2 -0
  520. package/public/assets/smile-plus-q6EQBXHZ.js +2 -0
  521. package/public/assets/snazzy-light-4G7pJPwS.js +2 -0
  522. package/public/assets/solarized-dark-DV17i1UV.js +2 -0
  523. package/public/assets/solarized-light-DSh2HLQt.js +2 -0
  524. package/public/assets/sparkles-CzwR10ZU.js +2 -0
  525. package/public/assets/sql-DNssxck8.js +2 -0
  526. package/public/assets/square-Bqly37YM.js +2 -0
  527. package/public/assets/stats-V9Z-GxUd.js +2 -0
  528. package/public/assets/status-dot-CVv0iGHL.js +2 -0
  529. package/public/assets/stethoscope-SCBrnQQ8.js +2 -0
  530. package/public/assets/store-BvtFdlGX.js +9 -0
  531. package/public/assets/stylus-B6D30XZt.js +2 -0
  532. package/public/assets/svelte-DOdLCIlh.js +2 -0
  533. package/public/assets/switch-DuCA7mrB.js +2 -0
  534. package/public/assets/synthwave-84-nFMaYfgc.js +2 -0
  535. package/public/assets/tabs-jZgNvNHr.js +2 -0
  536. package/public/assets/task-chip-CYj0mpoL.js +2 -0
  537. package/public/assets/tasks-BIyeAaPC.js +2 -0
  538. package/public/assets/tasks-CXU75HRF.js +11 -0
  539. package/public/assets/teams-BPf976zb.js +2 -0
  540. package/public/assets/terminal-Bl2u7KxT.js +2 -0
  541. package/public/assets/terminal-viewer-DE9BOe-8.js +3 -0
  542. package/public/assets/terminal-viewer-impl-BrP-ENHg.css +1 -0
  543. package/public/assets/terminal-viewer-impl-D04pjmGh.js +143 -0
  544. package/public/assets/textarea-hs6Mpyfl.js +2 -0
  545. package/public/assets/themes-G5j9m1Ji.js +2 -0
  546. package/public/assets/tokyo-night-oM2G3aXe.js +2 -0
  547. package/public/assets/trash-2-FbcSq927.js +2 -0
  548. package/public/assets/triangle-alert-BBNhfgMi.js +2 -0
  549. package/public/assets/ts-tags-Ca73dJJY.js +2 -0
  550. package/public/assets/tsx-5Eka4NBX.js +2 -0
  551. package/public/assets/typescript-DOu2WMV5.js +2 -0
  552. package/public/assets/use-agent-terminal-B1yR456R.js +2 -0
  553. package/public/assets/use-decisions-D-S4tpDf.js +2 -0
  554. package/public/assets/use-project-list-B-T2Bnnn.js +2 -0
  555. package/public/assets/use-selectors-CnrAk2YP.js +6 -0
  556. package/public/assets/user-avatar-nBFIcR4M.js +2 -0
  557. package/public/assets/user-cog-CKcouW1J.js +2 -0
  558. package/public/assets/user-plus-D9749q73.js +2 -0
  559. package/public/assets/users-C7B3u9jv.js +2 -0
  560. package/public/assets/versioned-prompt-editor-Diu8BIaM.js +8 -0
  561. package/public/assets/vesper-DdrHHSXu.js +2 -0
  562. package/public/assets/vitesse-black-fwtXNY1n.js +2 -0
  563. package/public/assets/vitesse-dark-BZCL-v6S.js +2 -0
  564. package/public/assets/vitesse-light-VbXTXTou.js +2 -0
  565. package/public/assets/volume-2-XrcRKD9Z.js +2 -0
  566. package/public/assets/vue-Bfx0ffIq.js +2 -0
  567. package/public/assets/vue-html-BeluIYX0.js +2 -0
  568. package/public/assets/vue-vine-DGUAbOCX.js +2 -0
  569. package/public/assets/warehouse-BanzOanY.js +2 -0
  570. package/public/assets/wasm-BnjxR4X6.js +2 -0
  571. package/public/assets/wasm-ByWQv1Qj.js +2 -0
  572. package/public/assets/waypoints-CIzINtLT.js +2 -0
  573. package/public/assets/wgsl-BsKzXJz4.js +2 -0
  574. package/public/assets/wit-DdvCle-K.js +2 -0
  575. package/public/assets/work-queue-TCjJxeT-.js +2 -0
  576. package/public/assets/workflow-marker-Cf3Hf2fN.js +2 -0
  577. package/public/assets/workflows-CXQX20Qj.js +6 -0
  578. package/public/assets/workspaces-qSYzKYMA.js +3 -0
  579. package/public/assets/wrench-C7-4CgnY.js +2 -0
  580. package/public/assets/x-Bge17hWJ.js +2 -0
  581. package/public/assets/xml-DIqSwXR3.js +2 -0
  582. package/public/assets/yaml-rwi0_p6S.js +2 -0
  583. package/public/assets/zap-DGuDTw4w.js +2 -0
  584. package/public/assets/zoom-in-Bs8Qv8VL.js +2 -0
  585. package/public/assets/zoomable-image-B3Og53nj.js +2 -0
  586. package/public/cosmos/audio/README.md +50 -0
  587. package/public/cosmos/audio/alert.mp3 +0 -0
  588. package/public/cosmos/audio/ambient-bed.mp3 +0 -0
  589. package/public/cosmos/audio/comet.mp3 +0 -0
  590. package/public/cosmos/audio/cross-galaxy.mp3 +0 -0
  591. package/public/cosmos/audio/deploy.mp3 +0 -0
  592. package/public/cosmos/audio/galaxy-dissipate.mp3 +0 -0
  593. package/public/cosmos/audio/galaxy-form.mp3 +0 -0
  594. package/public/cosmos/audio/land.mp3 +0 -0
  595. package/public/cosmos/audio/reap.mp3 +0 -0
  596. package/public/cosmos/audio/spawn.mp3 +0 -0
  597. package/public/cosmos.html +34 -0
  598. package/public/favicon.ico +0 -0
  599. package/public/favicon.svg +10 -0
  600. package/public/icons/apple-touch-icon.png +0 -0
  601. package/public/icons/humwick-192.png +0 -0
  602. package/public/icons/humwick-512.png +0 -0
  603. package/public/icons/humwick.svg +19 -0
  604. package/public/index.html +188 -0
  605. package/public/manifest.webmanifest +45 -0
  606. package/public/sw.js +160 -0
  607. package/recipes/code-review.yaml +26 -0
  608. package/recipes/debug.yaml +20 -0
  609. package/recipes/feature.yaml +26 -0
  610. package/recipes/refactor.yaml +20 -0
  611. package/recipes/test.yaml +20 -0
  612. package/runner/LICENSE +167 -0
  613. package/runner/agent-bin/agent-relay-browser +10 -0
  614. package/runner/agent-bin/humwick +10 -0
  615. package/runner/hooks/fff-search-redirect/fff-search-redirect.cjs +161 -0
  616. package/runner/hooks/fff-search-redirect/hooks.json +13 -0
  617. package/runner/hooks/rg-r-guard/hooks.json +18 -0
  618. package/runner/hooks/rg-r-guard/rg-r-guard.cjs +144 -0
  619. package/runner/hooks/web-tools-redirect/hooks.json +13 -0
  620. package/runner/hooks/web-tools-redirect/web-tools-redirect.cjs +84 -0
  621. package/runner/plugins/browser/skills/playwright-cli/SKILL.md +53 -0
  622. package/runner/plugins/claude/.claude-plugin/plugin.json +8 -0
  623. package/runner/plugins/claude/claude-statusline-probe.cjs +144 -0
  624. package/runner/plugins/claude/hooks/gate-run-guard.provisioned.mjs +914 -0
  625. package/runner/plugins/claude/hooks/gate-run-guard.sh +9 -0
  626. package/runner/plugins/claude/hooks/gate-run-guard.ts +237 -0
  627. package/runner/plugins/claude/hooks/hooks.json +158 -0
  628. package/runner/plugins/claude/hooks/kill-guard.provisioned.mjs +7027 -0
  629. package/runner/plugins/claude/hooks/kill-guard.sh +341 -0
  630. package/runner/plugins/claude/hooks/kill-guard.ts +337 -0
  631. package/runner/plugins/claude/hooks/permission-request.sh +22 -0
  632. package/runner/plugins/claude/hooks/post-compact.sh +10 -0
  633. package/runner/plugins/claude/hooks/post-tool-use.sh +8 -0
  634. package/runner/plugins/claude/hooks/pre-compact.sh +12 -0
  635. package/runner/plugins/claude/hooks/read-only-bash-guard.sh +587 -0
  636. package/runner/plugins/claude/hooks/relay-status.sh +373 -0
  637. package/runner/plugins/claude/hooks/session-end.sh +26 -0
  638. package/runner/plugins/claude/hooks/session-start.sh +31 -0
  639. package/runner/plugins/claude/hooks/shell-trust.ts +28 -0
  640. package/runner/plugins/claude/hooks/stop-failure.sh +47 -0
  641. package/runner/plugins/claude/hooks/stop.sh +48 -0
  642. package/runner/plugins/claude/hooks/subagent-guard.cjs +26 -0
  643. package/runner/plugins/claude/hooks/subagent-skill-policy.cjs +160 -0
  644. package/runner/plugins/claude/hooks/subagent-start.sh +13 -0
  645. package/runner/plugins/claude/hooks/subagent-stop.sh +19 -0
  646. package/runner/plugins/claude/hooks/user-prompt-submit.sh +18 -0
  647. package/runner/plugins/claude/hooks/wait-loop-guard.ts +120 -0
  648. package/runner/plugins/claude/monitors/monitors.json +7 -0
  649. package/runner/plugins/claude/monitors/relay-monitor.provisioned.mjs +786 -0
  650. package/runner/plugins/claude/monitors/relay-monitor.ts +58 -0
  651. package/runner/plugins/claude/skills/disconnect/SKILL.md +16 -0
  652. package/runner/plugins/claude/skills/label/SKILL.md +23 -0
  653. package/runner/plugins/claude/skills/message/SKILL.md +40 -0
  654. package/runner/plugins/claude/skills/pair/SKILL.md +30 -0
  655. package/runner/plugins/claude/skills/react/SKILL.md +18 -0
  656. package/runner/plugins/claude/skills/read-message/SKILL.md +24 -0
  657. package/runner/plugins/claude/skills/reply/SKILL.md +44 -0
  658. package/runner/plugins/claude/skills/send-claimable/SKILL.md +39 -0
  659. package/runner/plugins/claude/skills/slice-first/SKILL.md +32 -0
  660. package/runner/plugins/claude/skills/slice-first/references/plan-recipe.md +46 -0
  661. package/runner/plugins/claude/skills/status/SKILL.md +16 -0
  662. package/runner/plugins/claude/skills/tags/SKILL.md +25 -0
  663. package/runner/plugins/claude/skills/task/SKILL.md +28 -0
  664. package/runner/plugins/claude-output-style/.claude-plugin/plugin.json +5 -0
  665. package/runner/plugins/claude-output-style/output-styles/agent-relay.md +5 -0
  666. package/runner/plugins/codex/skills/disconnect/SKILL.md +15 -0
  667. package/runner/plugins/codex/skills/guide/SKILL.md +15 -0
  668. package/runner/plugins/codex/skills/label/SKILL.md +22 -0
  669. package/runner/plugins/codex/skills/message/SKILL.md +40 -0
  670. package/runner/plugins/codex/skills/pair/SKILL.md +29 -0
  671. package/runner/plugins/codex/skills/react/SKILL.md +17 -0
  672. package/runner/plugins/codex/skills/read-message/SKILL.md +23 -0
  673. package/runner/plugins/codex/skills/reply/SKILL.md +44 -0
  674. package/runner/plugins/codex/skills/send-claimable/SKILL.md +39 -0
  675. package/runner/plugins/codex/skills/slice-first/SKILL.md +32 -0
  676. package/runner/plugins/codex/skills/slice-first/references/plan-recipe.md +46 -0
  677. package/runner/plugins/codex/skills/status/SKILL.md +15 -0
  678. package/runner/plugins/codex/skills/tags/SKILL.md +24 -0
  679. package/runner/plugins/codex/skills/task/SKILL.md +28 -0
  680. package/runner/src/adapter.ts +1061 -0
  681. package/runner/src/adapters/__fixtures__/codex-app-server.ts +47 -0
  682. package/runner/src/adapters/claude-api.ts +243 -0
  683. package/runner/src/adapters/claude-context-command.ts +16 -0
  684. package/runner/src/adapters/claude-credentials.ts +22 -0
  685. package/runner/src/adapters/claude-delivery-lanes.ts +28 -0
  686. package/runner/src/adapters/claude-delivery.ts +166 -0
  687. package/runner/src/adapters/claude-effort.ts +94 -0
  688. package/runner/src/adapters/claude-exit.ts +290 -0
  689. package/runner/src/adapters/claude-headless-mirror.ts +88 -0
  690. package/runner/src/adapters/claude-headless-refusal.ts +51 -0
  691. package/runner/src/adapters/claude-headless.ts +617 -0
  692. package/runner/src/adapters/claude-monitor-delivery-plan.ts +317 -0
  693. package/runner/src/adapters/claude-permission.ts +243 -0
  694. package/runner/src/adapters/claude-prompt-gates.ts +269 -0
  695. package/runner/src/adapters/claude-prompt-hook.ts +145 -0
  696. package/runner/src/adapters/claude-session-capture.ts +293 -0
  697. package/runner/src/adapters/claude-session-probe.ts +414 -0
  698. package/runner/src/adapters/claude-shutdown.ts +190 -0
  699. package/runner/src/adapters/claude-status-detectors.ts +426 -0
  700. package/runner/src/adapters/claude-subagents.ts +93 -0
  701. package/runner/src/adapters/claude-submit-confirmation.ts +287 -0
  702. package/runner/src/adapters/claude-tmux.ts +548 -0
  703. package/runner/src/adapters/claude-token-usage-capture.ts +253 -0
  704. package/runner/src/adapters/claude-tool-policy.ts +165 -0
  705. package/runner/src/adapters/claude-transcript-tail.ts +193 -0
  706. package/runner/src/adapters/claude-transcript.ts +812 -0
  707. package/runner/src/adapters/claude.ts +1097 -0
  708. package/runner/src/adapters/codex-agent-message-capture.ts +189 -0
  709. package/runner/src/adapters/codex-app-server.ts +70 -0
  710. package/runner/src/adapters/codex-client.ts +362 -0
  711. package/runner/src/adapters/codex-effective-config.ts +87 -0
  712. package/runner/src/adapters/codex-launch-config.ts +153 -0
  713. package/runner/src/adapters/codex-rollout-context.ts +272 -0
  714. package/runner/src/adapters/codex-skill-discovery.ts +18 -0
  715. package/runner/src/adapters/codex-token-usage-capture.ts +163 -0
  716. package/runner/src/adapters/codex-tool-output.ts +53 -0
  717. package/runner/src/adapters/codex-turn-outcome.ts +27 -0
  718. package/runner/src/adapters/codex-version.ts +64 -0
  719. package/runner/src/adapters/codex.ts +1442 -0
  720. package/runner/src/adapters/incremental-file.ts +110 -0
  721. package/runner/src/adapters/opencode-api.ts +71 -0
  722. package/runner/src/adapters/opencode-context.ts +277 -0
  723. package/runner/src/adapters/opencode-model-registry.ts +126 -0
  724. package/runner/src/adapters/opencode-provider.ts +169 -0
  725. package/runner/src/adapters/opencode-server-retry.ts +50 -0
  726. package/runner/src/adapters/opencode-soft-steer.ts +302 -0
  727. package/runner/src/adapters/opencode-spawn.ts +145 -0
  728. package/runner/src/adapters/opencode-subscribe.ts +62 -0
  729. package/runner/src/adapters/opencode-token-usage-capture.ts +187 -0
  730. package/runner/src/adapters/opencode-tool-events.ts +302 -0
  731. package/runner/src/adapters/opencode-tools-config.ts +17 -0
  732. package/runner/src/adapters/opencode.ts +2264 -0
  733. package/runner/src/adapters/project-shell.ts +80 -0
  734. package/runner/src/adapters/provider-launch-config.ts +21 -0
  735. package/runner/src/adapters/provider-quota-harvest.ts +127 -0
  736. package/runner/src/adapters/service-access.ts +153 -0
  737. package/runner/src/adapters/tmux-offload.ts +207 -0
  738. package/runner/src/adapters/tool-summary.ts +214 -0
  739. package/runner/src/agent-redact.ts +75 -0
  740. package/runner/src/agent-runner/commands/dispatch.ts +185 -0
  741. package/runner/src/agent-runner/commands/lifecycle.ts +84 -0
  742. package/runner/src/agent-runner/commands/prompt.ts +284 -0
  743. package/runner/src/agent-runner/credentials.ts +208 -0
  744. package/runner/src/agent-runner/http-liveness.ts +85 -0
  745. package/runner/src/agent-runner/lifecycle-milestones.ts +207 -0
  746. package/runner/src/agent-runner/lifecycle-phase.ts +80 -0
  747. package/runner/src/agent-runner/registration.ts +163 -0
  748. package/runner/src/agent-runner/runner-context.ts +158 -0
  749. package/runner/src/agent-runner/session-mirror.ts +278 -0
  750. package/runner/src/agent-runner/task-claims.ts +116 -0
  751. package/runner/src/agent-runner/token-usage-coverage.ts +54 -0
  752. package/runner/src/agent-runner/turn-report.ts +269 -0
  753. package/runner/src/api-budget-accounting.ts +91 -0
  754. package/runner/src/area-memory.ts +255 -0
  755. package/runner/src/artifact-path-materialize.ts +52 -0
  756. package/runner/src/async-guard.ts +35 -0
  757. package/runner/src/attachment-cache-sweep.ts +31 -0
  758. package/runner/src/attachment-cache.ts +195 -0
  759. package/runner/src/background-script-reconcile.ts +106 -0
  760. package/runner/src/bounded-log.ts +59 -0
  761. package/runner/src/bounded-spawn-sync.ts +18 -0
  762. package/runner/src/busy-reconciler.ts +282 -0
  763. package/runner/src/claim-tracker.ts +140 -0
  764. package/runner/src/claude-settings.ts +167 -0
  765. package/runner/src/claude-workspace-trust.ts +289 -0
  766. package/runner/src/config.ts +547 -0
  767. package/runner/src/context-boundary.ts +101 -0
  768. package/runner/src/context-command.ts +151 -0
  769. package/runner/src/context-probe-state.ts +6 -0
  770. package/runner/src/continuation-archive.ts +179 -0
  771. package/runner/src/control-server.ts +730 -0
  772. package/runner/src/delivery-policy.ts +9 -0
  773. package/runner/src/delivery-result.ts +24 -0
  774. package/runner/src/effort-command.ts +125 -0
  775. package/runner/src/empty-turn.ts +816 -0
  776. package/runner/src/free-port.ts +25 -0
  777. package/runner/src/fs-offload.ts +26 -0
  778. package/runner/src/gate-run-config.ts +35 -0
  779. package/runner/src/gate-run-lease-probe.ts +38 -0
  780. package/runner/src/host-asset-plan.ts +450 -0
  781. package/runner/src/host-claude-config-worker.ts +34 -0
  782. package/runner/src/host-sources.ts +40 -0
  783. package/runner/src/inbox-carrier.ts +7 -0
  784. package/runner/src/index.ts +386 -0
  785. package/runner/src/launch-assembly.ts +955 -0
  786. package/runner/src/liveness.ts +105 -0
  787. package/runner/src/logger.ts +108 -0
  788. package/runner/src/mcp-outbox.ts +204 -0
  789. package/runner/src/mcp-preflight.ts +86 -0
  790. package/runner/src/mcp-source-selection.ts +54 -0
  791. package/runner/src/mcp-tool-deferral.ts +35 -0
  792. package/runner/src/mcp-vault-env.ts +25 -0
  793. package/runner/src/message-body-config/config.ts +16 -0
  794. package/runner/src/message-body-config.ts +1 -0
  795. package/runner/src/mid-turn-delivery.ts +43 -0
  796. package/runner/src/native-memory-lever.ts +329 -0
  797. package/runner/src/native-self-resume.ts +244 -0
  798. package/runner/src/outbox.ts +453 -0
  799. package/runner/src/park-post.ts +17 -0
  800. package/runner/src/pending-permission-store.ts +148 -0
  801. package/runner/src/process-meta.ts +9 -0
  802. package/runner/src/profile-home.ts +419 -0
  803. package/runner/src/profile-projection.ts +411 -0
  804. package/runner/src/project-hooks.ts +65 -0
  805. package/runner/src/project-instructions.ts +119 -0
  806. package/runner/src/provider-double.ts +59 -0
  807. package/runner/src/provider-hold.ts +228 -0
  808. package/runner/src/provider-home-marker.ts +3 -0
  809. package/runner/src/provider-home-tombstone.ts +4 -0
  810. package/runner/src/provider-input-queue.ts +134 -0
  811. package/runner/src/provider-integration.ts +93 -0
  812. package/runner/src/provider-processes.ts +17 -0
  813. package/runner/src/provider-submit-failure.ts +15 -0
  814. package/runner/src/providers.ts +35 -0
  815. package/runner/src/provisioning.ts +703 -0
  816. package/runner/src/question-decision.ts +18 -0
  817. package/runner/src/quota.ts +22 -0
  818. package/runner/src/rate-limit.ts +351 -0
  819. package/runner/src/refused-prompt-store.ts +36 -0
  820. package/runner/src/relay-injection-events.ts +161 -0
  821. package/runner/src/relay-instructions.ts +107 -0
  822. package/runner/src/relay-mcp-proxy.long-turn-e2e.ts +183 -0
  823. package/runner/src/relay-mcp-proxy.ts +704 -0
  824. package/runner/src/relay-mcp.ts +583 -0
  825. package/runner/src/reply-obligation-cache.ts +211 -0
  826. package/runner/src/response-capture-report.ts +111 -0
  827. package/runner/src/response-routing.ts +6 -0
  828. package/runner/src/runner-core.ts +2955 -0
  829. package/runner/src/runner-exit.ts +12 -0
  830. package/runner/src/runner-helpers.ts +582 -0
  831. package/runner/src/runner-insights.ts +105 -0
  832. package/runner/src/runner-mcp-proxy.ts +46 -0
  833. package/runner/src/runner-spawn-config.ts +68 -0
  834. package/runner/src/runner-stale-scratch-sweep.ts +21 -0
  835. package/runner/src/runner.ts +9 -0
  836. package/runner/src/runtime-token-file.ts +45 -0
  837. package/runner/src/runtime-token-remint.ts +56 -0
  838. package/runner/src/service-access.ts +88 -0
  839. package/runner/src/session-destroy.ts +27 -0
  840. package/runner/src/session-insights.ts +118 -0
  841. package/runner/src/session-scratch.ts +296 -0
  842. package/runner/src/spawn-input.ts +147 -0
  843. package/runner/src/startup-config-fetch.ts +48 -0
  844. package/runner/src/subreaper.ts +113 -0
  845. package/runner/src/template-resolver.ts +29 -0
  846. package/runner/src/test-run-dedup.ts +435 -0
  847. package/runner/src/transcript-context.ts +99 -0
  848. package/runner/src/transport-errors.ts +48 -0
  849. package/runner/src/turn-opener.ts +55 -0
  850. package/runner/src/turn-reconcile-event.ts +88 -0
  851. package/runner/src/vault-proxy-hop.ts +99 -0
  852. package/runner/src/version.ts +44 -0
  853. package/runner/src/web-tool-call-proxy.ts +128 -0
  854. package/runner/src/web-tools.ts +59 -0
  855. package/runner/test-support/codex-web-config-proof.ts +149 -0
  856. package/runner/test-support/effective-launch.ts +189 -0
  857. package/runner/test-support/native-context-sources.ts +77 -0
  858. package/runner/test-support/provisioning-context.ts +55 -0
  859. package/runner/test-support/recorder-double.ts +130 -0
  860. package/runner/test-support/recording-provider.ts +242 -0
  861. package/runner/test-support/runner-harness.ts +249 -0
  862. package/runner/test-support/service-access-fixture.ts +12 -0
  863. package/scripts/agent-vault/bootstrap.py +87 -0
  864. package/scripts/agent-vault/install.py +200 -0
  865. package/scripts/agent-vault/install_refresh.py +98 -0
  866. package/scripts/agent-vault/refresh.py +116 -0
  867. package/scripts/agent-vault/refresh_provision.py +109 -0
  868. package/scripts/agent-vault/refresh_store.py +54 -0
  869. package/scripts/agent-vault/runtime.py +253 -0
  870. package/scripts/agent-vault/sec-ops-activation.json +23 -0
  871. package/scripts/artifact-checkout-gc.ts +51 -0
  872. package/scripts/cd-config.ts +224 -0
  873. package/scripts/cd-deploy-debounce.ts +94 -0
  874. package/scripts/cd-deploy-worktree-gc.ts +235 -0
  875. package/scripts/cd-fleet-membership.ts +48 -0
  876. package/scripts/cd-host-epochs.ts +101 -0
  877. package/scripts/cd-hub-wake.ts +40 -0
  878. package/scripts/cd-land-boundary.ts +49 -0
  879. package/scripts/cd-watcher.ts +985 -0
  880. package/scripts/dashboard-build-marker.ts +71 -0
  881. package/scripts/fleet-sha-coverage.ts +66 -0
  882. package/scripts/gate-run-lease.ts +329 -0
  883. package/scripts/gate-slot +9 -0
  884. package/scripts/gate-slot-fleet-health.ts +60 -0
  885. package/scripts/gate.sh +6 -0
  886. package/scripts/install-bin-shim.cjs +149 -0
  887. package/scripts/orchestrator-spawn-smoke.ts +398 -0
  888. package/scripts/provisioning-matrix.ts +72 -0
  889. package/scripts/release-cd-stamp.ts +146 -0
  890. package/scripts/release-health.ts +133 -0
  891. package/scripts/release-report.ts +102 -0
  892. package/scripts/release-upgrade.ts +1296 -0
  893. package/scripts/steward-policy-cleanup.ts +73 -0
  894. package/scripts/wait-for-deploy.ts +43 -0
  895. package/src/agent-authz.ts +219 -0
  896. package/src/agent-branch-state.ts +45 -0
  897. package/src/agent-busy-health.ts +158 -0
  898. package/src/agent-card-projection.ts +86 -0
  899. package/src/agent-channel-binding.ts +49 -0
  900. package/src/agent-command-activity.ts +39 -0
  901. package/src/agent-core.ts +29 -0
  902. package/src/agent-death-diagnosis.ts +314 -0
  903. package/src/agent-drive-arbiter.ts +112 -0
  904. package/src/agent-exit-alarm.ts +10 -0
  905. package/src/agent-exit-cleanup-async.ts +69 -0
  906. package/src/agent-exit-cleanup.ts +99 -0
  907. package/src/agent-exit-report.ts +28 -0
  908. package/src/agent-issue-repo.ts +53 -0
  909. package/src/agent-launch-shape-redaction.ts +72 -0
  910. package/src/agent-lifecycle-events.ts +428 -0
  911. package/src/agent-principal.ts +14 -0
  912. package/src/agent-profile-catalog.ts +188 -0
  913. package/src/agent-ref.ts +340 -0
  914. package/src/agent-spawn.ts +45 -0
  915. package/src/agent-status-events.ts +41 -0
  916. package/src/agent-system-tags.ts +38 -0
  917. package/src/artifact-media.ts +34 -0
  918. package/src/artifact-storage.ts +245 -0
  919. package/src/artifact-text.ts +31 -0
  920. package/src/async-deadline.ts +59 -0
  921. package/src/auth/admin-routes.ts +36 -0
  922. package/src/auth/index.ts +23 -0
  923. package/src/auth/login-rate-limiter.ts +153 -0
  924. package/src/auth/password.ts +142 -0
  925. package/src/auth/provider.ts +60 -0
  926. package/src/auth/role-scopes.ts +15 -0
  927. package/src/auth/session-cookie.ts +35 -0
  928. package/src/auth/session-refresh.ts +61 -0
  929. package/src/auth/session.test-fixture.ts +10 -0
  930. package/src/auth/session.ts +107 -0
  931. package/src/authority-audit.ts +56 -0
  932. package/src/authz-meta-keys.ts +64 -0
  933. package/src/auto-spawn-dispatch.ts +154 -0
  934. package/src/automations/constants.ts +14 -0
  935. package/src/automations/cron.ts +129 -0
  936. package/src/automations/crud.ts +129 -0
  937. package/src/automations/dispatch.ts +299 -0
  938. package/src/automations/index.ts +5 -0
  939. package/src/automations/precheck.ts +124 -0
  940. package/src/automations/reconcile.ts +314 -0
  941. package/src/automations/storage.ts +200 -0
  942. package/src/automations/types.ts +16 -0
  943. package/src/automations/validation.ts +216 -0
  944. package/src/automations.ts +1 -0
  945. package/src/branch-landed.ts +761 -0
  946. package/src/browser-authz.ts +18 -0
  947. package/src/browser-config.ts +31 -0
  948. package/src/bundled-workflows.ts +48 -0
  949. package/src/bus-outbox-async.ts +16 -0
  950. package/src/bus-outbox.ts +265 -0
  951. package/src/bus-resume-commands.ts +18 -0
  952. package/src/bus.ts +792 -0
  953. package/src/canonical-repo-root.ts +131 -0
  954. package/src/cd-deploy-notify.ts +59 -0
  955. package/src/cd-host-deferrals.ts +23 -0
  956. package/src/cd-host-lag-notify.ts +36 -0
  957. package/src/cd-repository.ts +49 -0
  958. package/src/channel-output-control.ts +43 -0
  959. package/src/channel-output-validation.ts +11 -0
  960. package/src/channel-policy-health.ts +20 -0
  961. package/src/channel-target.ts +40 -0
  962. package/src/channels-host-service.ts +219 -0
  963. package/src/ci/bun-test-log.ts +41 -0
  964. package/src/ci/failed-test-files.ts +52 -0
  965. package/src/ci/gate-history.ts +66 -0
  966. package/src/ci/github-actions.ts +145 -0
  967. package/src/ci/incidents.ts +175 -0
  968. package/src/ci/index.ts +6 -0
  969. package/src/ci/job-verdict.ts +27 -0
  970. package/src/ci/land-boundary-ci.ts +104 -0
  971. package/src/ci/monitor.ts +528 -0
  972. package/src/ci/not-triggered.ts +116 -0
  973. package/src/ci/notifications.ts +234 -0
  974. package/src/ci/provider.ts +87 -0
  975. package/src/ci/root-missing.ts +35 -0
  976. package/src/ci/transition-notify.ts +279 -0
  977. package/src/ci-monitor.ts +7 -0
  978. package/src/claude-api-budget-async.ts +11 -0
  979. package/src/claude-api-budget-config.ts +23 -0
  980. package/src/claude-api-expiry.ts +70 -0
  981. package/src/claude-api-overflow.ts +146 -0
  982. package/src/claude-app/config.ts +13 -0
  983. package/src/claude-app/oauth-http.ts +127 -0
  984. package/src/claude-app/oauth-provider.ts +136 -0
  985. package/src/claude-app/passphrase.ts +14 -0
  986. package/src/claude-app-auth.ts +65 -0
  987. package/src/claude-app-gateway.ts +68 -0
  988. package/src/cli/_shared.ts +136 -0
  989. package/src/cli/agent-detect.ts +175 -0
  990. package/src/cli/agent-guide.ts +152 -0
  991. package/src/cli/agent-keep.ts +37 -0
  992. package/src/cli/agent-meta.ts +111 -0
  993. package/src/cli/artifact.ts +154 -0
  994. package/src/cli/browser.ts +56 -0
  995. package/src/cli/channel-output.ts +17 -0
  996. package/src/cli/channels-host.ts +13 -0
  997. package/src/cli/channels.ts +16 -0
  998. package/src/cli/claude-api-budget.ts +41 -0
  999. package/src/cli/context-probe.ts +90 -0
  1000. package/src/cli/credentials.ts +1 -0
  1001. package/src/cli/daemon.ts +125 -0
  1002. package/src/cli/dev.ts +185 -0
  1003. package/src/cli/ephemeral.ts +159 -0
  1004. package/src/cli/hosts.ts +41 -0
  1005. package/src/cli/index.ts +442 -0
  1006. package/src/cli/introspect.ts +74 -0
  1007. package/src/cli/maintenance.ts +24 -0
  1008. package/src/cli/merges.ts +78 -0
  1009. package/src/cli/message.ts +229 -0
  1010. package/src/cli/orchestrator.ts +384 -0
  1011. package/src/cli/pair.ts +135 -0
  1012. package/src/cli/profile.ts +35 -0
  1013. package/src/cli/project.ts +52 -0
  1014. package/src/cli/prompts.ts +23 -0
  1015. package/src/cli/provider-enablement.ts +42 -0
  1016. package/src/cli/provider.ts +230 -0
  1017. package/src/cli/recipe.ts +110 -0
  1018. package/src/cli/reply.ts +130 -0
  1019. package/src/cli/roles.ts +60 -0
  1020. package/src/cli/routing-policy.ts +20 -0
  1021. package/src/cli/run.ts +96 -0
  1022. package/src/cli/secrets-backup.ts +85 -0
  1023. package/src/cli/secrets.ts +55 -0
  1024. package/src/cli/service-access.ts +23 -0
  1025. package/src/cli/setup.ts +57 -0
  1026. package/src/cli/shutdown.ts +16 -0
  1027. package/src/cli/spawn.ts +31 -0
  1028. package/src/cli/state.ts +73 -0
  1029. package/src/cli/steward.ts +58 -0
  1030. package/src/cli/task.ts +151 -0
  1031. package/src/cli/team.ts +18 -0
  1032. package/src/cli/timers.ts +53 -0
  1033. package/src/cli/token.ts +72 -0
  1034. package/src/cli/upgrade.ts +200 -0
  1035. package/src/cli/web-tool-calls.ts +17 -0
  1036. package/src/cli/workflow.ts +46 -0
  1037. package/src/cli/workspace.ts +544 -0
  1038. package/src/cli.ts +4 -0
  1039. package/src/codex-reset-consume.ts +274 -0
  1040. package/src/codex-wham-quota.ts +177 -0
  1041. package/src/command-events.ts +69 -0
  1042. package/src/command-secrets.ts +198 -0
  1043. package/src/command-ttl.ts +63 -0
  1044. package/src/commands-db.ts +1196 -0
  1045. package/src/commands-landing-async.ts +166 -0
  1046. package/src/commands-write.ts +160 -0
  1047. package/src/comment-blocks.ts +84 -0
  1048. package/src/compaction-watch.ts +259 -0
  1049. package/src/config-model-selection.ts +14 -0
  1050. package/src/config-store-write.ts +39 -0
  1051. package/src/config-store.ts +1253 -0
  1052. package/src/config.ts +939 -0
  1053. package/src/connector-boot-health.ts +27 -0
  1054. package/src/connector-paths.ts +47 -0
  1055. package/src/connectors.ts +547 -0
  1056. package/src/content-security.ts +12 -0
  1057. package/src/context-advisory.ts +279 -0
  1058. package/src/context-block-rendered-at.ts +33 -0
  1059. package/src/context-injection-channel.ts +49 -0
  1060. package/src/context-router.ts +121 -0
  1061. package/src/context-threshold-config.ts +52 -0
  1062. package/src/continuation-replay-edge.ts +30 -0
  1063. package/src/continuity-working-state.ts +107 -0
  1064. package/src/contracts.ts +109 -0
  1065. package/src/coordinator-authority.ts +100 -0
  1066. package/src/coordinator-digest-config.ts +20 -0
  1067. package/src/cosmos-events.ts +164 -0
  1068. package/src/daemon.ts +570 -0
  1069. package/src/dashboard-notifications.ts +169 -0
  1070. package/src/dashboard-presence.ts +86 -0
  1071. package/src/db/activity-async.ts +58 -0
  1072. package/src/db/activity-read-ops.ts +42 -0
  1073. package/src/db/activity-write-ops.ts +43 -0
  1074. package/src/db/activity.ts +454 -0
  1075. package/src/db/agent-card-read.ts +98 -0
  1076. package/src/db/agent-effort-state.ts +146 -0
  1077. package/src/db/agent-exit-cleanup.ts +94 -0
  1078. package/src/db/agent-exit-report.ts +33 -0
  1079. package/src/db/agent-gate-runs-write-ops.ts +7 -0
  1080. package/src/db/agent-gate-runs.ts +96 -0
  1081. package/src/db/agent-identity-archive.test-fixture.ts +12 -0
  1082. package/src/db/agent-identity-archive.ts +75 -0
  1083. package/src/db/agent-keep.ts +21 -0
  1084. package/src/db/agent-lifecycle-write-ops.ts +92 -0
  1085. package/src/db/agent-meta.ts +74 -0
  1086. package/src/db/agent-outstanding-work.ts +154 -0
  1087. package/src/db/agent-ownership-async.ts +45 -0
  1088. package/src/db/agent-ownership-read-ops.ts +12 -0
  1089. package/src/db/agent-ownership-write-ops.ts +50 -0
  1090. package/src/db/agent-ownership.ts +200 -0
  1091. package/src/db/agent-predicates.ts +64 -0
  1092. package/src/db/agent-read.ts +39 -0
  1093. package/src/db/agent-search-async.ts +21 -0
  1094. package/src/db/agent-search-read-ops.ts +8 -0
  1095. package/src/db/agent-search.ts +162 -0
  1096. package/src/db/agent-shutdown-in-flight.ts +21 -0
  1097. package/src/db/agents-async.ts +333 -0
  1098. package/src/db/agents-prune-write-op.ts +37 -0
  1099. package/src/db/agents-read-ops.ts +33 -0
  1100. package/src/db/agents-write-ops.ts +174 -0
  1101. package/src/db/agents.ts +1284 -0
  1102. package/src/db/api-budget-schema.ts +144 -0
  1103. package/src/db/api-budget-usage-migration.ts +31 -0
  1104. package/src/db/api-budget-usage.ts +40 -0
  1105. package/src/db/artifact-browse.ts +145 -0
  1106. package/src/db/artifact-retention.ts +115 -0
  1107. package/src/db/artifacts-async.ts +81 -0
  1108. package/src/db/artifacts-read-ops.ts +24 -0
  1109. package/src/db/artifacts-write-ops.ts +46 -0
  1110. package/src/db/artifacts.ts +307 -0
  1111. package/src/db/auth-identities.ts +128 -0
  1112. package/src/db/backlog.ts +172 -0
  1113. package/src/db/blackboard.ts +171 -0
  1114. package/src/db/broadcast-scope.ts +63 -0
  1115. package/src/db/broker-memory-migration.ts +71 -0
  1116. package/src/db/browser-sessions.ts +89 -0
  1117. package/src/db/budget-lineage.ts +26 -0
  1118. package/src/db/bus-outbox-read-ops.ts +29 -0
  1119. package/src/db/bus-outbox-write-ops.ts +57 -0
  1120. package/src/db/bus-prune-async.ts +16 -0
  1121. package/src/db/busy-regression.worker.ts +48 -0
  1122. package/src/db/caller-lifecycle.ts +24 -0
  1123. package/src/db/carry-pending-marker.ts +129 -0
  1124. package/src/db/carry-pending.ts +145 -0
  1125. package/src/db/channel-binding-delete.ts +15 -0
  1126. package/src/db/channel-egress-allowlist.ts +200 -0
  1127. package/src/db/channel-identity.ts +38 -0
  1128. package/src/db/channel-runtime.ts +19 -0
  1129. package/src/db/channels-async.ts +55 -0
  1130. package/src/db/channels-read-ops.ts +13 -0
  1131. package/src/db/channels-session-fence.ts +18 -0
  1132. package/src/db/channels-write-ops.ts +42 -0
  1133. package/src/db/channels.ts +654 -0
  1134. package/src/db/checkout-refresh.ts +36 -0
  1135. package/src/db/ci-gate-runs.ts +92 -0
  1136. package/src/db/ci-incidents-async.ts +76 -0
  1137. package/src/db/ci-incidents-read-ops.ts +15 -0
  1138. package/src/db/ci-incidents-write-ops.ts +57 -0
  1139. package/src/db/ci-incidents.ts +667 -0
  1140. package/src/db/ci-sha-observations-schema.ts +33 -0
  1141. package/src/db/claim-sql.ts +44 -0
  1142. package/src/db/claude-api-budget-ops.ts +15 -0
  1143. package/src/db/claude-api-budget-reconcile.ts +39 -0
  1144. package/src/db/claude-api-budget.ts +198 -0
  1145. package/src/db/claude-app-oauth.ts +74 -0
  1146. package/src/db/claude-catalog-reconcile.ts +27 -0
  1147. package/src/db/codex-reset-consumes-async.ts +9 -0
  1148. package/src/db/codex-reset-consumes-read-ops.ts +5 -0
  1149. package/src/db/codex-reset-consumes-write-ops.ts +19 -0
  1150. package/src/db/codex-reset-consumes.ts +122 -0
  1151. package/src/db/command-agent-profiles.ts +58 -0
  1152. package/src/db/command-row.ts +88 -0
  1153. package/src/db/command-terminal-status.ts +33 -0
  1154. package/src/db/command-vault-pruning.ts +30 -0
  1155. package/src/db/commands-cancel-write.ts +45 -0
  1156. package/src/db/commands-claim-admission.ts +144 -0
  1157. package/src/db/commands-effort-read.ts +58 -0
  1158. package/src/db/commands-host-land-admission.ts +106 -0
  1159. package/src/db/commands-kernel-landing.ts +268 -0
  1160. package/src/db/commands-land-occupancy.ts +40 -0
  1161. package/src/db/commands-land-wait.ts +38 -0
  1162. package/src/db/commands-landing-completeness.ts +66 -0
  1163. package/src/db/commands-landing-tuples.ts +22 -0
  1164. package/src/db/commands-landing.ts +1046 -0
  1165. package/src/db/commands-leaseless-sweep.ts +72 -0
  1166. package/src/db/commands-list-query.ts +47 -0
  1167. package/src/db/commands-planner-stats.test-fixture.ts +97 -0
  1168. package/src/db/commands-read-ops.ts +49 -0
  1169. package/src/db/commands-scheduler-recovery.ts +71 -0
  1170. package/src/db/commands-spawn-read.ts +33 -0
  1171. package/src/db/commands-write-ops.ts +286 -0
  1172. package/src/db/config-store-write-ops.ts +58 -0
  1173. package/src/db/connection-instrumentation.ts +76 -0
  1174. package/src/db/connection.ts +532 -0
  1175. package/src/db/context-reset-carry.ts +144 -0
  1176. package/src/db/continuation-archive-purge.ts +48 -0
  1177. package/src/db/continuation-archive-search.ts +249 -0
  1178. package/src/db/continuation-archives-async.ts +59 -0
  1179. package/src/db/continuation-archives-read-ops.ts +10 -0
  1180. package/src/db/continuation-archives-write-ops.ts +15 -0
  1181. package/src/db/continuation-archives.ts +158 -0
  1182. package/src/db/continuations.ts +201 -0
  1183. package/src/db/coordinator-delivery.ts +10 -0
  1184. package/src/db/coordinator-digest-async.ts +13 -0
  1185. package/src/db/coordinator-digest-flush.ts +6 -0
  1186. package/src/db/coordinator-digest.ts +145 -0
  1187. package/src/db/coordinator-seat.ts +130 -0
  1188. package/src/db/crash-reports.ts +115 -0
  1189. package/src/db/db-error-registry.ts +290 -0
  1190. package/src/db/db-reader-worker.ts +91 -0
  1191. package/src/db/db-writer-worker.ts +66 -0
  1192. package/src/db/deferred-lineage-report-queries.ts +28 -0
  1193. package/src/db/deferred-lineage-reports.ts +44 -0
  1194. package/src/db/delivery-async.ts +102 -0
  1195. package/src/db/delivery-expiration-health.ts +97 -0
  1196. package/src/db/delivery-expiration.ts +52 -0
  1197. package/src/db/delivery-quality-async.ts +23 -0
  1198. package/src/db/delivery-quality.ts +116 -0
  1199. package/src/db/delivery-read-ops.ts +26 -0
  1200. package/src/db/delivery-report-echo.ts +53 -0
  1201. package/src/db/delivery-write-ops.ts +72 -0
  1202. package/src/db/delivery.ts +545 -0
  1203. package/src/db/deploy-events-async.ts +66 -0
  1204. package/src/db/deploy-events-read-ops.ts +25 -0
  1205. package/src/db/deploy-events-write-ops.ts +81 -0
  1206. package/src/db/deploy-events.ts +554 -0
  1207. package/src/db/deploy-task-completion.ts +48 -0
  1208. package/src/db/drive-leases.ts +165 -0
  1209. package/src/db/durable-payloads.ts +92 -0
  1210. package/src/db/fixtures/writer-shutdown.ts +28 -0
  1211. package/src/db/fts-query.ts +8 -0
  1212. package/src/db/gate-policy.ts +27 -0
  1213. package/src/db/gate-runs.ts +181 -0
  1214. package/src/db/gateway.ts +513 -0
  1215. package/src/db/generation-launch.ts +82 -0
  1216. package/src/db/guides-search.ts +18 -0
  1217. package/src/db/history-delivery-settle.ts +57 -0
  1218. package/src/db/hosts-async.ts +150 -0
  1219. package/src/db/hosts-backfill.ts +91 -0
  1220. package/src/db/hosts-read-ops.ts +21 -0
  1221. package/src/db/hosts-registration.ts +452 -0
  1222. package/src/db/hosts-views.ts +259 -0
  1223. package/src/db/hosts-write-ops.ts +94 -0
  1224. package/src/db/hosts.ts +251 -0
  1225. package/src/db/human-address.ts +6 -0
  1226. package/src/db/idle-digest.ts +54 -0
  1227. package/src/db/idle-self-care.ts +100 -0
  1228. package/src/db/inbox-async.ts +29 -0
  1229. package/src/db/inbox-read-ops.ts +8 -0
  1230. package/src/db/inbox-write-ops.ts +25 -0
  1231. package/src/db/inbox.ts +197 -0
  1232. package/src/db/index.ts +147 -0
  1233. package/src/db/injection-attempts.ts +41 -0
  1234. package/src/db/insights-read-ops.ts +12 -0
  1235. package/src/db/insights-write-ops.ts +15 -0
  1236. package/src/db/integrations.ts +297 -0
  1237. package/src/db/issue-associations.ts +136 -0
  1238. package/src/db/issue-lifecycle.ts +199 -0
  1239. package/src/db/issue-refs.ts +312 -0
  1240. package/src/db/kernel-event-log-schema.ts +14 -0
  1241. package/src/db/kernel-landing-admission.ts +15 -0
  1242. package/src/db/kernel-landing-command-authority.ts +222 -0
  1243. package/src/db/kernel-persistence-async.ts +48 -0
  1244. package/src/db/kernel-persistence-read-ops.ts +24 -0
  1245. package/src/db/kernel-persistence-write-ops.ts +43 -0
  1246. package/src/db/land-boundaries.ts +138 -0
  1247. package/src/db/land-executing.ts +147 -0
  1248. package/src/db/land-gate-attestations.ts +161 -0
  1249. package/src/db/land-incident-eligibility.ts +44 -0
  1250. package/src/db/land-queue-trace.ts +28 -0
  1251. package/src/db/land-stack.ts +80 -0
  1252. package/src/db/land-telemetry-schema.ts +50 -0
  1253. package/src/db/land-telemetry-write-ops.ts +16 -0
  1254. package/src/db/land-telemetry.ts +114 -0
  1255. package/src/db/land-withdrawal-state.ts +26 -0
  1256. package/src/db/landed-merge-evidence.ts +72 -0
  1257. package/src/db/landed-task-attribution.ts +23 -0
  1258. package/src/db/landing-audit.ts +18 -0
  1259. package/src/db/landing-controllers.ts +67 -0
  1260. package/src/db/landing-ingress-async.ts +102 -0
  1261. package/src/db/landing-ingress-read-ops.ts +8 -0
  1262. package/src/db/landing-ingress-write-ops.ts +42 -0
  1263. package/src/db/landing-ingress.ts +380 -0
  1264. package/src/db/landing-read-ops.ts +18 -0
  1265. package/src/db/landing-receipts.ts +206 -0
  1266. package/src/db/landing-schema.ts +479 -0
  1267. package/src/db/launch-facts.ts +60 -0
  1268. package/src/db/legacy-landing-publication.ts +103 -0
  1269. package/src/db/legacy-message-backfill.ts +90 -0
  1270. package/src/db/lifecycle-seq.ts +127 -0
  1271. package/src/db/lifecycle-write-window.ts +216 -0
  1272. package/src/db/lineage-pair-dedupe-sql.ts +80 -0
  1273. package/src/db/lineage-startup-captures.ts +43 -0
  1274. package/src/db/long-running-work-async.ts +12 -0
  1275. package/src/db/long-running-work-write-ops.ts +8 -0
  1276. package/src/db/long-running-work.ts +78 -0
  1277. package/src/db/macos-privacy.ts +72 -0
  1278. package/src/db/main-connection-writes.ts +44 -0
  1279. package/src/db/main-thread-state.ts +38 -0
  1280. package/src/db/maintenance-health.ts +560 -0
  1281. package/src/db/maintenance-indexes.ts +37 -0
  1282. package/src/db/maintenance-job-runs-async.ts +15 -0
  1283. package/src/db/maintenance-job-runs.ts +62 -0
  1284. package/src/db/maintenance-job-write-ops.ts +10 -0
  1285. package/src/db/maintenance-pauses.ts +224 -0
  1286. package/src/db/maintenance-worker.ts +111 -0
  1287. package/src/db/mappers.ts +422 -0
  1288. package/src/db/memory-preamble-read.ts +13 -0
  1289. package/src/db/memory-resolve.ts +209 -0
  1290. package/src/db/memory-retirement-plan.ts +31 -0
  1291. package/src/db/memory-retirement.ts +15 -0
  1292. package/src/db/merge-drain-async.ts +8 -0
  1293. package/src/db/merge-lease.ts +225 -0
  1294. package/src/db/message-claims.ts +16 -0
  1295. package/src/db/message-queries.ts +16 -0
  1296. package/src/db/message-read-mark.ts +32 -0
  1297. package/src/db/message-reads-async.ts +46 -0
  1298. package/src/db/message-reads-read-ops.ts +35 -0
  1299. package/src/db/message-reads-write-ops.ts +24 -0
  1300. package/src/db/message-reads.ts +553 -0
  1301. package/src/db/message-send-suppression.ts +58 -0
  1302. package/src/db/message-send.ts +76 -0
  1303. package/src/db/message-thread.ts +15 -0
  1304. package/src/db/message-write-ops.ts +96 -0
  1305. package/src/db/messages-async.ts +31 -0
  1306. package/src/db/messages-read-ops.ts +14 -0
  1307. package/src/db/messages.ts +1201 -0
  1308. package/src/db/migration-marker.ts +13 -0
  1309. package/src/db/migrations.ts +1761 -0
  1310. package/src/db/notification-subscriptions.ts +282 -0
  1311. package/src/db/on-loop-write-transaction.ts +34 -0
  1312. package/src/db/operator-actions-schema.ts +10 -0
  1313. package/src/db/operator-decisions.ts +180 -0
  1314. package/src/db/orchestrators-async.ts +57 -0
  1315. package/src/db/orchestrators-read-ops.ts +7 -0
  1316. package/src/db/orchestrators-write-ops.ts +52 -0
  1317. package/src/db/orchestrators.ts +485 -0
  1318. package/src/db/outbox-codec.ts +16 -0
  1319. package/src/db/pair-maintenance.ts +9 -0
  1320. package/src/db/pairs-async.ts +10 -0
  1321. package/src/db/pairs-write-ops.ts +8 -0
  1322. package/src/db/pairs.ts +264 -0
  1323. package/src/db/pending-relay-runs.ts +73 -0
  1324. package/src/db/plan-blurb-migration.ts +158 -0
  1325. package/src/db/plan-ci-blocks.ts +28 -0
  1326. package/src/db/plan-completion.ts +55 -0
  1327. package/src/db/plan-conformance.ts +104 -0
  1328. package/src/db/plan-dispatch-schema.ts +17 -0
  1329. package/src/db/plan-dispatch-store.ts +112 -0
  1330. package/src/db/plan-external.ts +79 -0
  1331. package/src/db/plan-graph-async.ts +23 -0
  1332. package/src/db/plan-graph-read-ops.ts +16 -0
  1333. package/src/db/plan-graph-write-ops.ts +37 -0
  1334. package/src/db/plan-graph.ts +403 -0
  1335. package/src/db/plan-import-schema.ts +19 -0
  1336. package/src/db/plan-import.ts +211 -0
  1337. package/src/db/plan-task-create.ts +44 -0
  1338. package/src/db/planner-stats.ts +123 -0
  1339. package/src/db/plans-async.ts +22 -0
  1340. package/src/db/plans-read-ops.ts +11 -0
  1341. package/src/db/plans-write-ops.ts +9 -0
  1342. package/src/db/plans.ts +385 -0
  1343. package/src/db/policy-runtime.ts +14 -0
  1344. package/src/db/presence-buffer.ts +111 -0
  1345. package/src/db/presence-loop.ts +58 -0
  1346. package/src/db/presence-write-ops.ts +28 -0
  1347. package/src/db/presence-write.ts +38 -0
  1348. package/src/db/profile-artifact-backfill-migration.ts +32 -0
  1349. package/src/db/profile-host-sources-migration.ts +150 -0
  1350. package/src/db/profile-legacy-project-instructions-migration.ts +41 -0
  1351. package/src/db/profile-name-case-migration.ts +46 -0
  1352. package/src/db/profile-override-migration.ts +200 -0
  1353. package/src/db/profile-project-ack-migration.ts +55 -0
  1354. package/src/db/profile-slim-migration.ts +125 -0
  1355. package/src/db/profile-slim-plan.ts +190 -0
  1356. package/src/db/project-entries-async.ts +18 -0
  1357. package/src/db/project-entries-read-ops.ts +28 -0
  1358. package/src/db/project-entries.ts +514 -0
  1359. package/src/db/project-entry-search.ts +63 -0
  1360. package/src/db/project-identity.ts +16 -0
  1361. package/src/db/project-journal.ts +256 -0
  1362. package/src/db/project-lifecycle.ts +80 -0
  1363. package/src/db/project-memory-group-migration.ts +76 -0
  1364. package/src/db/project-phantom-merge.ts +228 -0
  1365. package/src/db/project-root-schema.ts +30 -0
  1366. package/src/db/project-trust-approvals.ts +98 -0
  1367. package/src/db/projects-async.ts +50 -0
  1368. package/src/db/projects-read-ops.ts +59 -0
  1369. package/src/db/projects-write-ops.ts +74 -0
  1370. package/src/db/projects.ts +629 -0
  1371. package/src/db/prompt-templates-schema.ts +23 -0
  1372. package/src/db/prompt-templates.ts +138 -0
  1373. package/src/db/prompt-version-migration.ts +115 -0
  1374. package/src/db/prompt-versions-ops.ts +16 -0
  1375. package/src/db/prompt-versions.ts +167 -0
  1376. package/src/db/provider-catalog-async.ts +31 -0
  1377. package/src/db/provider-catalog-read-ops.ts +8 -0
  1378. package/src/db/provider-catalog-write-ops.ts +16 -0
  1379. package/src/db/provider-config-history.ts +49 -0
  1380. package/src/db/provider-config-secrets.ts +117 -0
  1381. package/src/db/provider-flap-messages-async.ts +6 -0
  1382. package/src/db/provider-flap-messages-write-ops.ts +12 -0
  1383. package/src/db/provider-flap-messages.ts +19 -0
  1384. package/src/db/provider-quota-advisory-types.ts +39 -0
  1385. package/src/db/provider-quota-burn.ts +322 -0
  1386. package/src/db/provider-quota-effect-occurrences.ts +13 -0
  1387. package/src/db/provider-quota-lease-write-ops.ts +23 -0
  1388. package/src/db/provider-quota-leases-async.ts +35 -0
  1389. package/src/db/provider-quota-leases.ts +174 -0
  1390. package/src/db/provider-quota-matrix-cache.ts +85 -0
  1391. package/src/db/provider-quota-matrix-fetch.ts +85 -0
  1392. package/src/db/provider-quota-merge.ts +90 -0
  1393. package/src/db/provider-quota-notification-write.ts +98 -0
  1394. package/src/db/provider-quota-prune.ts +35 -0
  1395. package/src/db/provider-quota-read-async.ts +77 -0
  1396. package/src/db/provider-quota-read-ops.ts +56 -0
  1397. package/src/db/provider-quota-recipients.ts +38 -0
  1398. package/src/db/provider-quota-state.ts +139 -0
  1399. package/src/db/provider-quota-visibility.ts +22 -0
  1400. package/src/db/provider-quota-write-ops.ts +69 -0
  1401. package/src/db/provider-quotas.ts +726 -0
  1402. package/src/db/provider-secret-scrub.ts +64 -0
  1403. package/src/db/provisioning-assets-migration.ts +85 -0
  1404. package/src/db/provisioning-async.ts +116 -0
  1405. package/src/db/provisioning-callmux.ts +184 -0
  1406. package/src/db/provisioning-github-api.ts +16 -0
  1407. package/src/db/provisioning-github-import-target.ts +29 -0
  1408. package/src/db/provisioning-mcp-validation.ts +103 -0
  1409. package/src/db/provisioning-read-ops.ts +23 -0
  1410. package/src/db/provisioning-registry.ts +1122 -0
  1411. package/src/db/provisioning-resolve.ts +321 -0
  1412. package/src/db/provisioning-write-ops.ts +43 -0
  1413. package/src/db/qa-skill-seed.ts +27 -0
  1414. package/src/db/quota-lease-busy.worker.ts +62 -0
  1415. package/src/db/read-op-marshaling-fixtures.ts +724 -0
  1416. package/src/db/read-ops.ts +266 -0
  1417. package/src/db/reader-pool.ts +252 -0
  1418. package/src/db/recipe-read-ops.ts +15 -0
  1419. package/src/db/recipe-write-ops.ts +68 -0
  1420. package/src/db/reply-obligations.ts +265 -0
  1421. package/src/db/report-suppression.ts +126 -0
  1422. package/src/db/restart-epoch-admin-async.ts +14 -0
  1423. package/src/db/restart-epoch-admin.ts +67 -0
  1424. package/src/db/restart-epoch-admission.ts +114 -0
  1425. package/src/db/restart-epoch-async.ts +80 -0
  1426. package/src/db/restart-epoch-begin.ts +177 -0
  1427. package/src/db/restart-epoch-read-ops.ts +40 -0
  1428. package/src/db/restart-epoch-release.ts +248 -0
  1429. package/src/db/restart-epoch-write-ops.ts +117 -0
  1430. package/src/db/restart-epoch.test-fixture.ts +37 -0
  1431. package/src/db/restart-epoch.ts +623 -0
  1432. package/src/db/restart-sensitive.ts +81 -0
  1433. package/src/db/retention.ts +423 -0
  1434. package/src/db/review-ref-cleanups.ts +306 -0
  1435. package/src/db/routing-policy.ts +64 -0
  1436. package/src/db/scheduled-timer-projection.ts +123 -0
  1437. package/src/db/scheduled-timer-quota-chaos-worker.ts +84 -0
  1438. package/src/db/scheduled-timers.ts +521 -0
  1439. package/src/db/schema.ts +1472 -0
  1440. package/src/db/scoped-message-reads.ts +31 -0
  1441. package/src/db/secrets-broker-async.ts +31 -0
  1442. package/src/db/secrets-broker-read-ops.ts +8 -0
  1443. package/src/db/secrets-broker-write-ops.ts +23 -0
  1444. package/src/db/secrets-broker.ts +221 -0
  1445. package/src/db/secrets-vault-import.ts +37 -0
  1446. package/src/db/secrets-vault-key-lifecycle.ts +64 -0
  1447. package/src/db/secrets-vault-metadata.ts +37 -0
  1448. package/src/db/secrets-vault-migration.ts +53 -0
  1449. package/src/db/secrets-vault-write.ts +97 -0
  1450. package/src/db/secrets-vault.ts +69 -0
  1451. package/src/db/self-effort-permissions.ts +50 -0
  1452. package/src/db/service-access-read-ops.ts +10 -0
  1453. package/src/db/services-async.ts +29 -0
  1454. package/src/db/services-read-ops.ts +134 -0
  1455. package/src/db/services-write-ops.ts +71 -0
  1456. package/src/db/shared.ts +7 -0
  1457. package/src/db/shipping-board-async.ts +6 -0
  1458. package/src/db/shipping-board.ts +319 -0
  1459. package/src/db/shipping-stats-async.ts +24 -0
  1460. package/src/db/shipping-stats-histogram.ts +45 -0
  1461. package/src/db/shipping-stats-schema.ts +8 -0
  1462. package/src/db/shipping-stats.ts +265 -0
  1463. package/src/db/snapshot-ledger-prune.ts +53 -0
  1464. package/src/db/spawn-budget.ts +145 -0
  1465. package/src/db/spawn-command-busy.worker.ts +71 -0
  1466. package/src/db/spawn-delegation-state.ts +124 -0
  1467. package/src/db/spawn-delegation.ts +114 -0
  1468. package/src/db/spawn-host-cap.ts +29 -0
  1469. package/src/db/spawn-in-flight-count.ts +37 -0
  1470. package/src/db/spawn-in-flight.ts +15 -0
  1471. package/src/db/spawn-process-evidence.ts +68 -0
  1472. package/src/db/spawn-project-target.ts +57 -0
  1473. package/src/db/spawn-registration-confirmed-backfill.ts +71 -0
  1474. package/src/db/spawn-request-id-migration.ts +36 -0
  1475. package/src/db/spawn-request-id.ts +35 -0
  1476. package/src/db/spawn-request-reuse.ts +28 -0
  1477. package/src/db/spawn-tree-cleanup.ts +89 -0
  1478. package/src/db/spawn-tree.ts +29 -0
  1479. package/src/db/sql-audit-indexes.ts +77 -0
  1480. package/src/db/stalled-message-delivery.ts +52 -0
  1481. package/src/db/startup-write-lock.ts +36 -0
  1482. package/src/db/stats-async.ts +235 -0
  1483. package/src/db/stats-health-read-model.ts +225 -0
  1484. package/src/db/stats-read-ops.ts +25 -0
  1485. package/src/db/stats.ts +633 -0
  1486. package/src/db/target-host.ts +25 -0
  1487. package/src/db/task-async.ts +165 -0
  1488. package/src/db/task-comment-through-async.ts +14 -0
  1489. package/src/db/task-comment-through-read-ops.ts +4 -0
  1490. package/src/db/task-comment-through-write-ops.ts +7 -0
  1491. package/src/db/task-comment-through.ts +123 -0
  1492. package/src/db/task-core.ts +44 -0
  1493. package/src/db/task-deliverables-async.ts +60 -0
  1494. package/src/db/task-deliverables-read-ops.ts +4 -0
  1495. package/src/db/task-deliverables-write-ops.ts +37 -0
  1496. package/src/db/task-deliverables.ts +387 -0
  1497. package/src/db/task-dependency-cycle.worker.ts +43 -0
  1498. package/src/db/task-detail-projection.ts +91 -0
  1499. package/src/db/task-entity-async.ts +252 -0
  1500. package/src/db/task-entity-read-ops.ts +51 -0
  1501. package/src/db/task-entity-write-ops.ts +197 -0
  1502. package/src/db/task-entity.ts +1143 -0
  1503. package/src/db/task-execution.ts +20 -0
  1504. package/src/db/task-issue-relation.ts +23 -0
  1505. package/src/db/task-issue-source.ts +46 -0
  1506. package/src/db/task-land-withdraw-async.ts +10 -0
  1507. package/src/db/task-land-withdraw-read-ops.ts +13 -0
  1508. package/src/db/task-land-withdraw-read.ts +47 -0
  1509. package/src/db/task-land-withdraw-write-ops.ts +31 -0
  1510. package/src/db/task-land-withdraw.ts +423 -0
  1511. package/src/db/task-list.ts +113 -0
  1512. package/src/db/task-maintenance.ts +25 -0
  1513. package/src/db/task-memory-async.ts +19 -0
  1514. package/src/db/task-memory-read-ops.ts +9 -0
  1515. package/src/db/task-memory-write-ops.ts +23 -0
  1516. package/src/db/task-memory.ts +170 -0
  1517. package/src/db/task-owner.ts +126 -0
  1518. package/src/db/task-read-ops.ts +44 -0
  1519. package/src/db/task-review-hold-async.ts +20 -0
  1520. package/src/db/task-review-hold-delivery.ts +58 -0
  1521. package/src/db/task-review-hold-write-ops.ts +26 -0
  1522. package/src/db/task-review-hold.ts +615 -0
  1523. package/src/db/task-state-reconcile-async.ts +12 -0
  1524. package/src/db/task-state-reconcile.ts +163 -0
  1525. package/src/db/task-validation.ts +71 -0
  1526. package/src/db/task-write-ops.ts +145 -0
  1527. package/src/db/tasks.ts +528 -0
  1528. package/src/db/team-epics.ts +37 -0
  1529. package/src/db/team-idle.ts +35 -0
  1530. package/src/db/team-project.ts +69 -0
  1531. package/src/db/team-spawn-delegation-read.ts +36 -0
  1532. package/src/db/team-spawn-delegation.ts +49 -0
  1533. package/src/db/teams-async.ts +58 -0
  1534. package/src/db/teams-read-ops.ts +27 -0
  1535. package/src/db/teams-write-ops.ts +17 -0
  1536. package/src/db/teams.ts +504 -0
  1537. package/src/db/terminal-events.ts +113 -0
  1538. package/src/db/timer-async.ts +523 -0
  1539. package/src/db/timer-cutover-core.ts +545 -0
  1540. package/src/db/timer-cutover-report-read-ops.ts +211 -0
  1541. package/src/db/timer-cutover-write-ops.ts +275 -0
  1542. package/src/db/timer-ingress-payload.ts +160 -0
  1543. package/src/db/timer-ingress-read-ops.ts +39 -0
  1544. package/src/db/timer-ingress-request-keys.ts +282 -0
  1545. package/src/db/timer-ingress-write-ops.ts +145 -0
  1546. package/src/db/timer-ingress.ts +515 -0
  1547. package/src/db/timer-message-cutover.ts +322 -0
  1548. package/src/db/timer-message-fire-deadletter.ts +136 -0
  1549. package/src/db/timer-message-fire.ts +209 -0
  1550. package/src/db/timer-message-flip-chaos-worker.ts +89 -0
  1551. package/src/db/timer-message-flip-consistency.ts +147 -0
  1552. package/src/db/timer-message-flip.ts +676 -0
  1553. package/src/db/timer-message-participant.ts +138 -0
  1554. package/src/db/timer-migrate-input.ts +92 -0
  1555. package/src/db/timer-operator-async.ts +177 -0
  1556. package/src/db/timer-operator-read-ops.ts +21 -0
  1557. package/src/db/timer-operator-stage10.ts +119 -0
  1558. package/src/db/timer-operator-write-ops.ts +102 -0
  1559. package/src/db/timer-operator.ts +393 -0
  1560. package/src/db/timer-read-ops.ts +147 -0
  1561. package/src/db/timer-transfer-errors.ts +10 -0
  1562. package/src/db/timer-transfer-write-ops.ts +39 -0
  1563. package/src/db/timer-verifier-schema.ts +29 -0
  1564. package/src/db/timer-verifier.ts +379 -0
  1565. package/src/db/timer-write-ops.ts +277 -0
  1566. package/src/db/token-db-write-ops.ts +92 -0
  1567. package/src/db/token-standing.ts +84 -0
  1568. package/src/db/token-usage-read-ops.ts +8 -0
  1569. package/src/db/token-usage-write-ops.ts +35 -0
  1570. package/src/db/token-usage.ts +338 -0
  1571. package/src/db/tool-groups-empty-migration.ts +59 -0
  1572. package/src/db/urgent-intake.ts +30 -0
  1573. package/src/db/user-invites.ts +107 -0
  1574. package/src/db/user-settings-read-ops.ts +19 -0
  1575. package/src/db/user-settings-write-ops.ts +42 -0
  1576. package/src/db/users.ts +173 -0
  1577. package/src/db/vault-backup.ts +59 -0
  1578. package/src/db/vault-expiry.ts +71 -0
  1579. package/src/db/vault-health.ts +99 -0
  1580. package/src/db/vault-token-launch.ts +77 -0
  1581. package/src/db/vault-token-ops.ts +14 -0
  1582. package/src/db/vault-tokens.ts +101 -0
  1583. package/src/db/viewer-scope.ts +117 -0
  1584. package/src/db/wal-checkpointer-worker.ts +48 -0
  1585. package/src/db/wal-checkpointer.ts +107 -0
  1586. package/src/db/wal-index.ts +53 -0
  1587. package/src/db/wal-live-log.ts +68 -0
  1588. package/src/db/wal-reclaim-async.ts +45 -0
  1589. package/src/db/wal-reclaim.ts +140 -0
  1590. package/src/db/web-tool-call-ops.ts +15 -0
  1591. package/src/db/web-tool-calls.ts +87 -0
  1592. package/src/db/withdraw-land-error.ts +18 -0
  1593. package/src/db/work-evidence.ts +43 -0
  1594. package/src/db/workflow-budget.ts +44 -0
  1595. package/src/db/workflow-contact.ts +173 -0
  1596. package/src/db/workflow-execution.ts +10 -0
  1597. package/src/db/workflow-journal-async.ts +64 -0
  1598. package/src/db/workflow-journal-prune.ts +71 -0
  1599. package/src/db/workflow-journal-read-ops.ts +21 -0
  1600. package/src/db/workflow-journal-schema.ts +9 -0
  1601. package/src/db/workflow-journal-write-ops.ts +33 -0
  1602. package/src/db/workflow-journal.ts +324 -0
  1603. package/src/db/workflow-spawn-quota.ts +57 -0
  1604. package/src/db/workflow-stats-read-ops.ts +177 -0
  1605. package/src/db/workflow-step-tasks.ts +74 -0
  1606. package/src/db/workflow-task-read-ops.ts +187 -0
  1607. package/src/db/workspace-land-state.ts +65 -0
  1608. package/src/db/workspace-merge-hold.ts +28 -0
  1609. package/src/db/workspace-persistence.ts +77 -0
  1610. package/src/db/workspace-rekey-write-ops.ts +11 -0
  1611. package/src/db/workspace-rekey.ts +148 -0
  1612. package/src/db/workspace-steward-cancel.ts +85 -0
  1613. package/src/db/workspace-steward-fence.ts +30 -0
  1614. package/src/db/workspace-write-ops.ts +26 -0
  1615. package/src/db/workspace-writes-async.ts +46 -0
  1616. package/src/db/workspace-writes.ts +196 -0
  1617. package/src/db/workspaces.ts +617 -0
  1618. package/src/db/write-ops.ts +594 -0
  1619. package/src/db/writer-drain.ts +27 -0
  1620. package/src/db/writer-fault-seam.ts +101 -0
  1621. package/src/db/writer-gateway.ts +840 -0
  1622. package/src/db/writer-ledger.ts +56 -0
  1623. package/src/db.ts +4 -0
  1624. package/src/deploy-executor.ts +139 -0
  1625. package/src/dev.ts +541 -0
  1626. package/src/dispatch-availability.ts +55 -0
  1627. package/src/dispatch-match.ts +21 -0
  1628. package/src/ephemeral/host-landing-slots-proof-worker.ts +45 -0
  1629. package/src/ephemeral/index.ts +58 -0
  1630. package/src/ephemeral/instance.ts +832 -0
  1631. package/src/ephemeral/landing-ingress-proof-worker.ts +30 -0
  1632. package/src/ephemeral/ports.ts +40 -0
  1633. package/src/ephemeral/profile.ts +323 -0
  1634. package/src/ephemeral/rehearsal-stamps.ts +149 -0
  1635. package/src/ephemeral/rehearsal.ts +213 -0
  1636. package/src/ephemeral/snapshot-kernel.ts +41 -0
  1637. package/src/ephemeral/snapshot.ts +753 -0
  1638. package/src/ephemeral/sweep.ts +40 -0
  1639. package/src/event-loop-lag.ts +584 -0
  1640. package/src/event-loop-yield.ts +27 -0
  1641. package/src/events.ts +140 -0
  1642. package/src/execution-mode.ts +63 -0
  1643. package/src/fleet-convergence.ts +123 -0
  1644. package/src/gate-resolver.ts +151 -0
  1645. package/src/gate-run-capture.ts +71 -0
  1646. package/src/git-sha.ts +58 -0
  1647. package/src/guides.ts +73 -0
  1648. package/src/host/capacity.ts +79 -0
  1649. package/src/host/gate-capacity-alert.ts +90 -0
  1650. package/src/host/identity.ts +128 -0
  1651. package/src/host/presentation.ts +234 -0
  1652. package/src/host/pressure-details.ts +89 -0
  1653. package/src/host/pressure.ts +216 -0
  1654. package/src/host/state.ts +132 -0
  1655. package/src/host/utilization-buffer.ts +71 -0
  1656. package/src/host-awareness.ts +57 -0
  1657. package/src/host-identity.ts +39 -0
  1658. package/src/host-provider-enablement.ts +75 -0
  1659. package/src/host-provider-store.ts +102 -0
  1660. package/src/host-tools.ts +39 -0
  1661. package/src/http-body.ts +49 -0
  1662. package/src/http-compression.ts +16 -0
  1663. package/src/hub-metrics-report.ts +67 -0
  1664. package/src/hub-metrics.ts +166 -0
  1665. package/src/idle-digest-config.ts +40 -0
  1666. package/src/idle-self-care.ts +58 -0
  1667. package/src/index.ts +35 -0
  1668. package/src/injection-sweep-pacing.ts +24 -0
  1669. package/src/insights-async.ts +16 -0
  1670. package/src/insights-db.ts +188 -0
  1671. package/src/internal-spawn-model.ts +18 -0
  1672. package/src/invite-link.ts +11 -0
  1673. package/src/issue-tracker/adapter.ts +58 -0
  1674. package/src/issue-tracker/github.ts +342 -0
  1675. package/src/issue-tracker/index.ts +12 -0
  1676. package/src/issue-tracker/registry.ts +26 -0
  1677. package/src/journal-preamble.ts +350 -0
  1678. package/src/kernel-correlation.ts +28 -0
  1679. package/src/land-authorization.ts +73 -0
  1680. package/src/land-block.ts +59 -0
  1681. package/src/land-failure-event-key.ts +8 -0
  1682. package/src/land-gate-failure-routing.ts +69 -0
  1683. package/src/land-gate-notifications.ts +173 -0
  1684. package/src/land-gate-queue-progress.ts +54 -0
  1685. package/src/land-gates-source.ts +126 -0
  1686. package/src/land-gates.ts +29 -0
  1687. package/src/land-lifecycle-drives.ts +15 -0
  1688. package/src/land-settle-dispatch.ts +134 -0
  1689. package/src/land-stack-depth.ts +11 -0
  1690. package/src/land-telemetry.ts +40 -0
  1691. package/src/landing-base-ref.ts +3 -0
  1692. package/src/landing-host-safety.ts +38 -0
  1693. package/src/landing-lane-key.ts +74 -0
  1694. package/src/launch-mode-support.ts +11 -0
  1695. package/src/launch-mode.ts +58 -0
  1696. package/src/legacy-landing.test-fixture.ts +56 -0
  1697. package/src/lifecycle-context-pressure.ts +134 -0
  1698. package/src/lifecycle-manager.ts +831 -0
  1699. package/src/lifecycle-signal-registry.ts +87 -0
  1700. package/src/live-runs-section.ts +38 -0
  1701. package/src/loop-block-attribution.ts +442 -0
  1702. package/src/loop-block-regression-alarm.ts +156 -0
  1703. package/src/loop-task-stamps.ts +62 -0
  1704. package/src/main-thread-clock.ts +95 -0
  1705. package/src/maintenance/agent-identity-archive-job.ts +15 -0
  1706. package/src/maintenance/artifact-checkout-gc-job.ts +14 -0
  1707. package/src/maintenance/artifact-checkout-gc.ts +33 -0
  1708. package/src/maintenance/artifact-sweep.ts +23 -0
  1709. package/src/maintenance/breaker.ts +200 -0
  1710. package/src/maintenance/cd-watcher.ts +176 -0
  1711. package/src/maintenance/checkout-refresh.ts +83 -0
  1712. package/src/maintenance/ci-monitor.ts +14 -0
  1713. package/src/maintenance/claude-api-budget-job.ts +16 -0
  1714. package/src/maintenance/constants.ts +134 -0
  1715. package/src/maintenance/continuation-archive-search-job.ts +27 -0
  1716. package/src/maintenance/critical-job-watchdog.ts +252 -0
  1717. package/src/maintenance/db-planner-stats-job.ts +19 -0
  1718. package/src/maintenance/db-wal-reclaim-job.ts +82 -0
  1719. package/src/maintenance/events.ts +28 -0
  1720. package/src/maintenance/gate-capacity-sample-job.ts +16 -0
  1721. package/src/maintenance/index.ts +10 -0
  1722. package/src/maintenance/jobs.ts +857 -0
  1723. package/src/maintenance/long-running-work.ts +41 -0
  1724. package/src/maintenance/orphaned-sessions.ts +126 -0
  1725. package/src/maintenance/pauses.ts +174 -0
  1726. package/src/maintenance/provider-secret-scrub-job.ts +16 -0
  1727. package/src/maintenance/queued-message-expiration.ts +23 -0
  1728. package/src/maintenance/red-main-controller-job.ts +22 -0
  1729. package/src/maintenance/reply-obligation-parity-job.ts +27 -0
  1730. package/src/maintenance/restart-epoch-hold-health.ts +62 -0
  1731. package/src/maintenance/run-registry.ts +194 -0
  1732. package/src/maintenance/scheduler.ts +778 -0
  1733. package/src/maintenance/service-access-job.ts +31 -0
  1734. package/src/maintenance/shipping-stats-rollup-job.ts +23 -0
  1735. package/src/maintenance/snapshot-ledger-prune-job.ts +17 -0
  1736. package/src/maintenance/stalled-delivery-pager.ts +125 -0
  1737. package/src/maintenance/steward-handback.ts +11 -0
  1738. package/src/maintenance/task-state-reconcile-job.ts +22 -0
  1739. package/src/maintenance/teams.ts +426 -0
  1740. package/src/maintenance/types.ts +124 -0
  1741. package/src/maintenance/vault-backup-job.ts +34 -0
  1742. package/src/maintenance/vault-expiry-job.ts +29 -0
  1743. package/src/maintenance/web-tool-call-prune-job.ts +13 -0
  1744. package/src/maintenance/workflow-backstop-job.ts +12 -0
  1745. package/src/maintenance/workflow-journal-prune-job.ts +29 -0
  1746. package/src/maintenance/workspaces.ts +784 -0
  1747. package/src/maintenance.ts +1 -0
  1748. package/src/managed-policy-escalation.ts +123 -0
  1749. package/src/managed-policy.ts +236 -0
  1750. package/src/managed-provider-gate.ts +27 -0
  1751. package/src/managed-spawn-reservation.ts +23 -0
  1752. package/src/markdown-frontmatter.ts +14 -0
  1753. package/src/mcp/activity-output.ts +57 -0
  1754. package/src/mcp/artifact-upload.ts +53 -0
  1755. package/src/mcp/context-output.ts +73 -0
  1756. package/src/mcp/dispatch-shape-schema.ts +13 -0
  1757. package/src/mcp/guides.ts +33 -0
  1758. package/src/mcp/http.ts +27 -0
  1759. package/src/mcp/identity-projection.ts +121 -0
  1760. package/src/mcp/identity.ts +235 -0
  1761. package/src/mcp/index.ts +355 -0
  1762. package/src/mcp/issue-selector-schema.ts +12 -0
  1763. package/src/mcp/message-read.ts +87 -0
  1764. package/src/mcp/output-descriptions.ts +72 -0
  1765. package/src/mcp/output-levels.ts +71 -0
  1766. package/src/mcp/output-projection.ts +88 -0
  1767. package/src/mcp/plan-presentation.ts +166 -0
  1768. package/src/mcp/presentation-values.ts +11 -0
  1769. package/src/mcp/presentation.ts +653 -0
  1770. package/src/mcp/project-entry-search-schema.ts +7 -0
  1771. package/src/mcp/prompts.ts +36 -0
  1772. package/src/mcp/runtime-output.ts +84 -0
  1773. package/src/mcp/schema-budget.ts +28 -0
  1774. package/src/mcp/self-care-visibility.ts +23 -0
  1775. package/src/mcp/service-access.ts +18 -0
  1776. package/src/mcp/spawn-targets-matrix.ts +68 -0
  1777. package/src/mcp/spawn-targets.test-fixture.ts +21 -0
  1778. package/src/mcp/task-validation-presentation.ts +19 -0
  1779. package/src/mcp/tool-generation.ts +8 -0
  1780. package/src/mcp/tool-groups.ts +136 -0
  1781. package/src/mcp/tools-artifacts.ts +82 -0
  1782. package/src/mcp/tools-messaging.ts +541 -0
  1783. package/src/mcp/tools-permission.ts +88 -0
  1784. package/src/mcp/tools-run.ts +73 -0
  1785. package/src/mcp/tools-scheduler.ts +156 -0
  1786. package/src/mcp/tools-spawn.ts +418 -0
  1787. package/src/mcp/tools-web-tool-calls.ts +28 -0
  1788. package/src/mcp/tools-workspace.ts +260 -0
  1789. package/src/mcp/types.ts +68 -0
  1790. package/src/mcp/validation.ts +66 -0
  1791. package/src/mcp-agent-action.ts +96 -0
  1792. package/src/mcp-agent-keep.ts +37 -0
  1793. package/src/mcp-backlog-tools.ts +137 -0
  1794. package/src/mcp-blackboard-tools.ts +131 -0
  1795. package/src/mcp-channel-binding-tools.ts +27 -0
  1796. package/src/mcp-claude-api-budget.ts +35 -0
  1797. package/src/mcp-codex-reset.ts +43 -0
  1798. package/src/mcp-decision-tools.ts +96 -0
  1799. package/src/mcp-dispatch-tools.ts +142 -0
  1800. package/src/mcp-egress-tools.ts +168 -0
  1801. package/src/mcp-errors.ts +7 -0
  1802. package/src/mcp-host-tools.ts +61 -0
  1803. package/src/mcp-interrupt-agent.ts +47 -0
  1804. package/src/mcp-issue-activity-tools.ts +114 -0
  1805. package/src/mcp-issue-association-tools.ts +103 -0
  1806. package/src/mcp-issue-lifecycle-tools.ts +49 -0
  1807. package/src/mcp-issue-ref-tools.ts +214 -0
  1808. package/src/mcp-maintenance-tools.ts +113 -0
  1809. package/src/mcp-merge-tools.ts +66 -0
  1810. package/src/mcp-notification-subscription-tools.ts +297 -0
  1811. package/src/mcp-output-levels.test-fixture.ts +95 -0
  1812. package/src/mcp-plan-tools.ts +347 -0
  1813. package/src/mcp-profile-trust-tools.ts +47 -0
  1814. package/src/mcp-project-journal-tools.ts +160 -0
  1815. package/src/mcp-project-tools.ts +420 -0
  1816. package/src/mcp-provider-catalog.ts +9 -0
  1817. package/src/mcp-release-tools.ts +33 -0
  1818. package/src/mcp-routing-policy-tools.ts +35 -0
  1819. package/src/mcp-secrets-tools.ts +87 -0
  1820. package/src/mcp-task-deliver-tools.ts +166 -0
  1821. package/src/mcp-task-land-withdraw-tools.ts +49 -0
  1822. package/src/mcp-task-memory-tools.ts +119 -0
  1823. package/src/mcp-task-review-hold-tools.ts +57 -0
  1824. package/src/mcp-task-tools.ts +342 -0
  1825. package/src/mcp-task-validation-tools.ts +30 -0
  1826. package/src/mcp-task-weave-tools.ts +63 -0
  1827. package/src/mcp-team-template-tools.ts +141 -0
  1828. package/src/mcp-team-tools.ts +197 -0
  1829. package/src/mcp-tool-allowlist.ts +88 -0
  1830. package/src/mcp-workflow-tools.ts +158 -0
  1831. package/src/mcp.ts +1 -0
  1832. package/src/memory-admission-rank.ts +55 -0
  1833. package/src/memory-area-injection.ts +216 -0
  1834. package/src/memory-boundary-capture.ts +206 -0
  1835. package/src/memory-entry-safety.ts +28 -0
  1836. package/src/memory-inject-filter.ts +190 -0
  1837. package/src/memory-injection.ts +954 -0
  1838. package/src/memory-preamble-admission.ts +158 -0
  1839. package/src/memory-preamble-async.ts +13 -0
  1840. package/src/memory-preamble.ts +1142 -0
  1841. package/src/memory-retirement.ts +11 -0
  1842. package/src/memory-seam.ts +273 -0
  1843. package/src/memory-tokens.ts +91 -0
  1844. package/src/merge-drain.ts +101 -0
  1845. package/src/merge-pause-maintenance.ts +19 -0
  1846. package/src/message-visibility.ts +50 -0
  1847. package/src/messaging-policy.ts +94 -0
  1848. package/src/native-memory.ts +59 -0
  1849. package/src/notification-prefs.ts +25 -0
  1850. package/src/notification-role-policy.ts +14 -0
  1851. package/src/notification-router.ts +329 -0
  1852. package/src/notification-rules.ts +390 -0
  1853. package/src/notification-settings-store.ts +47 -0
  1854. package/src/notification-settings.ts +166 -0
  1855. package/src/notification-subscription-rules.ts +11 -0
  1856. package/src/notification-types.ts +312 -0
  1857. package/src/notify.ts +55 -0
  1858. package/src/observed-reset-boundary.ts +23 -0
  1859. package/src/observed-reset-refresh.ts +21 -0
  1860. package/src/operator-alarm.ts +41 -0
  1861. package/src/operator-decisions-section.ts +29 -0
  1862. package/src/orchestrator-lookup.ts +29 -0
  1863. package/src/orchestrator-self-report-authz.ts +34 -0
  1864. package/src/package-pack.ts +246 -0
  1865. package/src/post-bind-startup.ts +58 -0
  1866. package/src/process-guard.ts +31 -0
  1867. package/src/profile-cells.ts +305 -0
  1868. package/src/profile-effective-survey.ts +121 -0
  1869. package/src/profile-host-sources.ts +73 -0
  1870. package/src/profile-instruction-blocks.ts +11 -0
  1871. package/src/profile-project-validation.ts +23 -0
  1872. package/src/profile-provider-options.ts +59 -0
  1873. package/src/profile-role-templates.ts +26 -0
  1874. package/src/profile-workflow-policy.ts +14 -0
  1875. package/src/project-claudemd-sweep.ts +176 -0
  1876. package/src/project-file-source.ts +54 -0
  1877. package/src/project-ingest.ts +195 -0
  1878. package/src/project-instructions.ts +700 -0
  1879. package/src/project-mcp.ts +18 -0
  1880. package/src/project-role-assets.ts +109 -0
  1881. package/src/project-roles-validate.ts +53 -0
  1882. package/src/project-roles.ts +364 -0
  1883. package/src/project-settings.ts +5 -0
  1884. package/src/project-skills.ts +5 -0
  1885. package/src/project-toolchain.ts +58 -0
  1886. package/src/project-trust-fingerprint.ts +174 -0
  1887. package/src/project-trust.ts +262 -0
  1888. package/src/project-workflows.ts +185 -0
  1889. package/src/prompt-resolver.ts +697 -0
  1890. package/src/prompt-template-fallback.ts +15 -0
  1891. package/src/prompt-version-errors.ts +13 -0
  1892. package/src/provider-catalog-store.ts +393 -0
  1893. package/src/provider-config-store.ts +308 -0
  1894. package/src/provider-enablement.ts +36 -0
  1895. package/src/provider-home-gc.ts +58 -0
  1896. package/src/provider-model-seed.ts +18 -0
  1897. package/src/provider-quota-async.ts +152 -0
  1898. package/src/provider-quota-config-store.ts +60 -0
  1899. package/src/provider-secrets.test-fixture.ts +34 -0
  1900. package/src/provider-state.ts +93 -0
  1901. package/src/provider-timeline-event.ts +76 -0
  1902. package/src/quota-advisory.ts +359 -0
  1903. package/src/quota-band-delivery.ts +13 -0
  1904. package/src/quota-band-projection.ts +149 -0
  1905. package/src/quota-band-transition.ts +316 -0
  1906. package/src/quota-pacing.ts +46 -0
  1907. package/src/quota-threshold-config.ts +46 -0
  1908. package/src/quota.ts +61 -0
  1909. package/src/ratchet-files.ts +202 -0
  1910. package/src/recipe-async.ts +50 -0
  1911. package/src/recipe-db.ts +260 -0
  1912. package/src/recipe-loader.ts +132 -0
  1913. package/src/recipe-runner.ts +259 -0
  1914. package/src/recipe-validator.ts +107 -0
  1915. package/src/relay-event-drain.ts +39 -0
  1916. package/src/relay-host-locality.ts +20 -0
  1917. package/src/relay-run-lease.ts +17 -0
  1918. package/src/repo-config-source.ts +209 -0
  1919. package/src/report-verbosity.ts +5 -0
  1920. package/src/restart-epoch-deploy-hold.ts +221 -0
  1921. package/src/retention-config-store.ts +32 -0
  1922. package/src/retention-config.ts +70 -0
  1923. package/src/reviewer-pipeline.ts +238 -0
  1924. package/src/routes/_route.ts +70 -0
  1925. package/src/routes/_shared.ts +513 -0
  1926. package/src/routes/activity.ts +70 -0
  1927. package/src/routes/agent-effort.ts +69 -0
  1928. package/src/routes/agent-keep.ts +27 -0
  1929. package/src/routes/agent-profiles.ts +169 -0
  1930. package/src/routes/agent-reporting.ts +19 -0
  1931. package/src/routes/agent-self-effort.ts +51 -0
  1932. package/src/routes/agent-sessions.ts +650 -0
  1933. package/src/routes/agent-sharing.ts +23 -0
  1934. package/src/routes/agents-spawn.ts +258 -0
  1935. package/src/routes/agents.ts +452 -0
  1936. package/src/routes/artifacts.ts +340 -0
  1937. package/src/routes/auth.ts +123 -0
  1938. package/src/routes/authority-audit.ts +14 -0
  1939. package/src/routes/automations.ts +83 -0
  1940. package/src/routes/backlog.ts +112 -0
  1941. package/src/routes/blackboard.ts +54 -0
  1942. package/src/routes/browser.ts +73 -0
  1943. package/src/routes/channel-binding-delete.ts +21 -0
  1944. package/src/routes/channel-output.ts +17 -0
  1945. package/src/routes/claude-api-budget.ts +65 -0
  1946. package/src/routes/commands-listing.ts +50 -0
  1947. package/src/routes/commands.ts +586 -0
  1948. package/src/routes/config.ts +75 -0
  1949. package/src/routes/connectors.ts +108 -0
  1950. package/src/routes/context-resets.ts +35 -0
  1951. package/src/routes/continuation-archives.ts +37 -0
  1952. package/src/routes/coordinator-teams.ts +14 -0
  1953. package/src/routes/decisions.ts +82 -0
  1954. package/src/routes/deploys.ts +15 -0
  1955. package/src/routes/fleet-convergence.ts +5 -0
  1956. package/src/routes/guides.ts +13 -0
  1957. package/src/routes/host-providers.ts +73 -0
  1958. package/src/routes/host-resource-control.ts +45 -0
  1959. package/src/routes/host-secret-files.ts +38 -0
  1960. package/src/routes/hosts.ts +240 -0
  1961. package/src/routes/inbox.ts +151 -0
  1962. package/src/routes/index.ts +614 -0
  1963. package/src/routes/insights.ts +86 -0
  1964. package/src/routes/integrations.ts +636 -0
  1965. package/src/routes/issue-activity.ts +78 -0
  1966. package/src/routes/issue-associations.ts +76 -0
  1967. package/src/routes/issue-lifecycle.ts +34 -0
  1968. package/src/routes/issue-refs.ts +163 -0
  1969. package/src/routes/kernel-timers-operator.ts +57 -0
  1970. package/src/routes/memory.ts +25 -0
  1971. package/src/routes/merges.ts +109 -0
  1972. package/src/routes/message-viewer.ts +4 -0
  1973. package/src/routes/messages.ts +621 -0
  1974. package/src/routes/notifications.ts +36 -0
  1975. package/src/routes/orchestrator-bootstrap.ts +101 -0
  1976. package/src/routes/orchestrator-host-registration.ts +125 -0
  1977. package/src/routes/orchestrator-host-utilization.ts +255 -0
  1978. package/src/routes/orchestrator-proxy.ts +174 -0
  1979. package/src/routes/orchestrator.ts +699 -0
  1980. package/src/routes/pairs.ts +214 -0
  1981. package/src/routes/plans.ts +98 -0
  1982. package/src/routes/project-onboarding.ts +56 -0
  1983. package/src/routes/project-trust.ts +73 -0
  1984. package/src/routes/projects.ts +296 -0
  1985. package/src/routes/prompt-templates.ts +106 -0
  1986. package/src/routes/provider-config.ts +232 -0
  1987. package/src/routes/provider-quota-config.ts +48 -0
  1988. package/src/routes/provider-quotas.ts +312 -0
  1989. package/src/routes/provisioning-registry.ts +192 -0
  1990. package/src/routes/recipes.ts +129 -0
  1991. package/src/routes/restart-epochs.ts +98 -0
  1992. package/src/routes/routing-policy.ts +30 -0
  1993. package/src/routes/run-command.ts +25 -0
  1994. package/src/routes/secrets-backup.ts +53 -0
  1995. package/src/routes/secrets-import.ts +32 -0
  1996. package/src/routes/secrets-page.ts +98 -0
  1997. package/src/routes/secrets-vault.ts +121 -0
  1998. package/src/routes/secrets.ts +165 -0
  1999. package/src/routes/service-access.ts +57 -0
  2000. package/src/routes/settings.ts +191 -0
  2001. package/src/routes/shipping.ts +56 -0
  2002. package/src/routes/spawn-policy.ts +299 -0
  2003. package/src/routes/spec.ts +58 -0
  2004. package/src/routes/sse.ts +18 -0
  2005. package/src/routes/stats.ts +159 -0
  2006. package/src/routes/steward.ts +49 -0
  2007. package/src/routes/task-graph.ts +30 -0
  2008. package/src/routes/task-http.ts +27 -0
  2009. package/src/routes/task-issues.ts +81 -0
  2010. package/src/routes/task-reads.ts +139 -0
  2011. package/src/routes/task-validation.ts +22 -0
  2012. package/src/routes/tasks.ts +553 -0
  2013. package/src/routes/team-templates.ts +65 -0
  2014. package/src/routes/teams-config.ts +15 -0
  2015. package/src/routes/teams.ts +141 -0
  2016. package/src/routes/token-usage.ts +167 -0
  2017. package/src/routes/tokens.ts +393 -0
  2018. package/src/routes/users.ts +248 -0
  2019. package/src/routes/viewer-read.ts +27 -0
  2020. package/src/routes/web-tool-calls.ts +38 -0
  2021. package/src/routes/workflows.ts +142 -0
  2022. package/src/routes/workspaces.ts +642 -0
  2023. package/src/routes.ts +3 -0
  2024. package/src/routing-eligibility.ts +42 -0
  2025. package/src/routing-model-aliases.ts +21 -0
  2026. package/src/routing-policy-normalize.ts +412 -0
  2027. package/src/routing-policy-push.ts +154 -0
  2028. package/src/routing-policy-service.ts +19 -0
  2029. package/src/routing-policy-store.ts +16 -0
  2030. package/src/routing-preferences.ts +82 -0
  2031. package/src/routing-step-defaults.ts +31 -0
  2032. package/src/runtime-grant.ts +164 -0
  2033. package/src/runtime-prefix.ts +8 -0
  2034. package/src/runtime-tokens.ts +395 -0
  2035. package/src/search-query.ts +10 -0
  2036. package/src/secret-keys.ts +24 -0
  2037. package/src/secrets-broker/config.ts +53 -0
  2038. package/src/secrets-broker/error.ts +8 -0
  2039. package/src/secrets-broker/infisical.ts +259 -0
  2040. package/src/secrets-broker/reader-infisical.ts +41 -0
  2041. package/src/secrets-broker/reader.ts +101 -0
  2042. package/src/secrets-broker/service.ts +242 -0
  2043. package/src/secrets-broker/tool-credentials.ts +9 -0
  2044. package/src/secrets-vault/backend-conformance.ts +26 -0
  2045. package/src/secrets-vault/backend.ts +102 -0
  2046. package/src/secrets-vault/backup.ts +103 -0
  2047. package/src/secrets-vault/config.ts +7 -0
  2048. package/src/secrets-vault/expiry.ts +10 -0
  2049. package/src/secrets-vault/identity.ts +27 -0
  2050. package/src/secrets-vault/import.ts +90 -0
  2051. package/src/secrets-vault/key-files.ts +91 -0
  2052. package/src/secrets-vault/keys.ts +79 -0
  2053. package/src/secrets-vault/metadata.ts +51 -0
  2054. package/src/secrets-vault/provider-env.ts +25 -0
  2055. package/src/secrets-vault/resolve.ts +101 -0
  2056. package/src/secrets-vault/restore.ts +57 -0
  2057. package/src/secrets-vault/scope.ts +25 -0
  2058. package/src/secrets-vault/service.ts +192 -0
  2059. package/src/secrets-vault/shared.ts +10 -0
  2060. package/src/security.ts +772 -0
  2061. package/src/self-effort-rule.ts +36 -0
  2062. package/src/self-resume-carry.ts +131 -0
  2063. package/src/self-resume-command.ts +24 -0
  2064. package/src/self-resume-config.ts +54 -0
  2065. package/src/self-resume-identity.ts +40 -0
  2066. package/src/self-resume-supersede.ts +19 -0
  2067. package/src/self-resume.ts +884 -0
  2068. package/src/server-background.ts +24 -0
  2069. package/src/server.ts +726 -0
  2070. package/src/service-access/config.ts +3 -0
  2071. package/src/service-access/health.ts +151 -0
  2072. package/src/service-access/host-health.ts +62 -0
  2073. package/src/service-access/host.ts +63 -0
  2074. package/src/service-access/operations.ts +21 -0
  2075. package/src/service-access/policy.ts +30 -0
  2076. package/src/service-access/probe.ts +62 -0
  2077. package/src/service-access/request-logs.ts +93 -0
  2078. package/src/service-access/scope.ts +7 -0
  2079. package/src/service-access/service.ts +185 -0
  2080. package/src/service-access/tokens.ts +174 -0
  2081. package/src/service-access/validation.ts +75 -0
  2082. package/src/service-access/vault.ts +59 -0
  2083. package/src/services/agent-action.ts +238 -0
  2084. package/src/services/agent-control-host.ts +74 -0
  2085. package/src/services/agent-effort.ts +60 -0
  2086. package/src/services/agent-hang-watchdog-job.ts +513 -0
  2087. package/src/services/agent-hang-watchdog-wiring.ts +487 -0
  2088. package/src/services/agent-hang-watchdog.ts +395 -0
  2089. package/src/services/agent-keep.ts +72 -0
  2090. package/src/services/agent-message-fanout.ts +91 -0
  2091. package/src/services/agent-outstanding-work.ts +66 -0
  2092. package/src/services/agent-reporting.ts +27 -0
  2093. package/src/services/artifact-access.ts +39 -0
  2094. package/src/services/artifact-multipart.ts +70 -0
  2095. package/src/services/artifact-path-host.ts +55 -0
  2096. package/src/services/artifact-read.ts +88 -0
  2097. package/src/services/artifact-write.ts +25 -0
  2098. package/src/services/auth-context.ts +117 -0
  2099. package/src/services/automatic-disposal.ts +33 -0
  2100. package/src/services/backlog.ts +149 -0
  2101. package/src/services/browser-inventory.ts +52 -0
  2102. package/src/services/browser-session-state.ts +41 -0
  2103. package/src/services/browser-session.ts +167 -0
  2104. package/src/services/bus-command-update.ts +84 -0
  2105. package/src/services/bus-expiration-death.ts +57 -0
  2106. package/src/services/canonical-root.ts +284 -0
  2107. package/src/services/captured-delivery-gate.ts +12 -0
  2108. package/src/services/carry-pending.ts +5 -0
  2109. package/src/services/channel-binding-delete.ts +20 -0
  2110. package/src/services/channel-suppression-receipt.ts +28 -0
  2111. package/src/services/checkout-refresh-state.ts +18 -0
  2112. package/src/services/checkout-refresh.test-fixture.ts +12 -0
  2113. package/src/services/child-work-evidence.ts +77 -0
  2114. package/src/services/claude-app.ts +91 -0
  2115. package/src/services/command-claim-rejection.ts +23 -0
  2116. package/src/services/command-host.ts +42 -0
  2117. package/src/services/coordinator-digest.ts +30 -0
  2118. package/src/services/decision-audience.ts +26 -0
  2119. package/src/services/delivery-gate-policy.ts +98 -0
  2120. package/src/services/delivery-tip.test-fixture.ts +25 -0
  2121. package/src/services/diff-gate.ts +110 -0
  2122. package/src/services/dispatch-command.ts +388 -0
  2123. package/src/services/effective-launch-driver.ts +240 -0
  2124. package/src/services/effective-launch-harness.ts +257 -0
  2125. package/src/services/errors.ts +31 -0
  2126. package/src/services/git-process.ts +176 -0
  2127. package/src/services/git-remote.ts +100 -0
  2128. package/src/services/harness-subagents.ts +12 -0
  2129. package/src/services/host-changed-paths.test-fixture.ts +134 -0
  2130. package/src/services/host-landing-placement.ts +65 -0
  2131. package/src/services/host-project-readiness.ts +49 -0
  2132. package/src/services/host-providers.ts +114 -0
  2133. package/src/services/host-utilization.ts +70 -0
  2134. package/src/services/idle-agent-digest.ts +318 -0
  2135. package/src/services/idle-epics.ts +105 -0
  2136. package/src/services/idle-self-care.ts +47 -0
  2137. package/src/services/interrupt-agent.ts +146 -0
  2138. package/src/services/isolated-workspace-placement.ts +258 -0
  2139. package/src/services/issue-activity.ts +23 -0
  2140. package/src/services/issue-associations.ts +72 -0
  2141. package/src/services/issue-completion-drain.ts +24 -0
  2142. package/src/services/issue-completion.ts +24 -0
  2143. package/src/services/issue-lifecycle-comments.ts +12 -0
  2144. package/src/services/issue-lifecycle.ts +620 -0
  2145. package/src/services/issue-refs.ts +65 -0
  2146. package/src/services/kernel-command-bridge.ts +219 -0
  2147. package/src/services/kernel-control-host.ts +78 -0
  2148. package/src/services/kernel-control-http.ts +119 -0
  2149. package/src/services/kernel-control-mcp.ts +193 -0
  2150. package/src/services/kernel-landing-command.ts +28 -0
  2151. package/src/services/kernel-landing-ingress.ts +65 -0
  2152. package/src/services/kernel-timers-authoritative-ingress.ts +48 -0
  2153. package/src/services/kernel-timers-authz.ts +229 -0
  2154. package/src/services/kernel-timers-command.ts +182 -0
  2155. package/src/services/kernel-timers-cutover-chaos-worker.ts +209 -0
  2156. package/src/services/kernel-timers-cutover.ts +39 -0
  2157. package/src/services/kernel-timers-ingress-apply.ts +39 -0
  2158. package/src/services/kernel-timers-ingress-chaos-worker.ts +312 -0
  2159. package/src/services/kernel-timers-ingress.ts +702 -0
  2160. package/src/services/kernel-timers-message-authority-chaos-worker.ts +97 -0
  2161. package/src/services/kernel-timers-migrate.ts +158 -0
  2162. package/src/services/kernel-timers-operator-chaos-worker.ts +259 -0
  2163. package/src/services/kernel-timers-operator-preflight.ts +18 -0
  2164. package/src/services/kernel-timers-operator.ts +424 -0
  2165. package/src/services/kernel-timers-outbox.ts +138 -0
  2166. package/src/services/kernel-timers-request-key-migration-chaos-worker.ts +77 -0
  2167. package/src/services/kernel-timers-stage10-operator.ts +210 -0
  2168. package/src/services/kernel-timers-stage10.ts +85 -0
  2169. package/src/services/kernel-timers-stage9.ts +57 -0
  2170. package/src/services/kernel-timers-transfer-chaos-worker.ts +118 -0
  2171. package/src/services/kernel-timers-transfer.ts +525 -0
  2172. package/src/services/kernel-timers-verifier.ts +39 -0
  2173. package/src/services/kernel-timers.ts +247 -0
  2174. package/src/services/land-boundary-settle.ts +32 -0
  2175. package/src/services/land-gate-placement.ts +60 -0
  2176. package/src/services/land-issue-relations.ts +46 -0
  2177. package/src/services/land-restart-retry.ts +77 -0
  2178. package/src/services/landed-ancestry.ts +417 -0
  2179. package/src/services/landed-task-attribution.ts +14 -0
  2180. package/src/services/landing-terminal-report.ts +119 -0
  2181. package/src/services/legacy-landing-backfill.ts +159 -0
  2182. package/src/services/legacy-landing-host.ts +291 -0
  2183. package/src/services/legacy-landing-publication.ts +35 -0
  2184. package/src/services/legacy-landing-recovery.ts +111 -0
  2185. package/src/services/macos-privacy.ts +34 -0
  2186. package/src/services/managed-running.ts +189 -0
  2187. package/src/services/memory-areas.ts +172 -0
  2188. package/src/services/memory-identity.ts +162 -0
  2189. package/src/services/merge-pause.ts +37 -0
  2190. package/src/services/message-delivery-actions.ts +11 -0
  2191. package/src/services/operator-decisions.ts +260 -0
  2192. package/src/services/orchestrator-landing-recovery.ts +55 -0
  2193. package/src/services/orchestrator-registration-recovery.ts +12 -0
  2194. package/src/services/orchestrator-upgrade.ts +83 -0
  2195. package/src/services/parity-harness.ts +141 -0
  2196. package/src/services/permission-decision.ts +129 -0
  2197. package/src/services/plan-ci-recovery.ts +76 -0
  2198. package/src/services/plan-conformance.ts +105 -0
  2199. package/src/services/plan-dispatch-policy.ts +79 -0
  2200. package/src/services/plan-dispatch.ts +372 -0
  2201. package/src/services/plan-external-view.ts +7 -0
  2202. package/src/services/plan-frontier.ts +34 -0
  2203. package/src/services/plan-graph.ts +703 -0
  2204. package/src/services/plan-import.ts +66 -0
  2205. package/src/services/plan-live-bindings.ts +139 -0
  2206. package/src/services/plan-task-create.ts +80 -0
  2207. package/src/services/plan-terminal-refs.ts +83 -0
  2208. package/src/services/plan-wake-digest.ts +88 -0
  2209. package/src/services/plan-wake-policy.ts +12 -0
  2210. package/src/services/profile-trust.ts +54 -0
  2211. package/src/services/project-checkout-binding.ts +65 -0
  2212. package/src/services/project-checkout-enrollment.ts +27 -0
  2213. package/src/services/project-cwd.ts +41 -0
  2214. package/src/services/project-onboarding.ts +165 -0
  2215. package/src/services/project-repo-create.ts +27 -0
  2216. package/src/services/project-role.test-fixture.ts +74 -0
  2217. package/src/services/project.ts +191 -0
  2218. package/src/services/prompt-templates.ts +46 -0
  2219. package/src/services/prompt-version-writer.ts +42 -0
  2220. package/src/services/provider-catalog.ts +7 -0
  2221. package/src/services/provider-hold-flap.ts +130 -0
  2222. package/src/services/provider-hold-nudge.ts +191 -0
  2223. package/src/services/provider-hold-record.ts +137 -0
  2224. package/src/services/provider-state-audit.ts +214 -0
  2225. package/src/services/provisioning-harness/analyze.ts +285 -0
  2226. package/src/services/provisioning-harness/budget-baseline.json +391 -0
  2227. package/src/services/provisioning-harness/capture.ts +197 -0
  2228. package/src/services/provisioning-harness/config.ts +55 -0
  2229. package/src/services/provisioning-harness/context-sources.ts +85 -0
  2230. package/src/services/provisioning-harness/driver.ts +156 -0
  2231. package/src/services/provisioning-harness/expect.ts +81 -0
  2232. package/src/services/provisioning-harness/fixture-matrix.ts +38 -0
  2233. package/src/services/provisioning-harness/fixtures/project/.agent-relay/land-gates.json +1 -0
  2234. package/src/services/provisioning-harness/fixtures/project/.claude/skills/harness-skill/SKILL.md +6 -0
  2235. package/src/services/provisioning-harness/fixtures/project/.mcp.json +1 -0
  2236. package/src/services/provisioning-harness/fixtures/project/AGENTS.md +1 -0
  2237. package/src/services/provisioning-harness/fixtures/project/CLAUDE.md +1 -0
  2238. package/src/services/provisioning-harness/fixtures/project/mcp-server.ts +33 -0
  2239. package/src/services/provisioning-harness/fixtures/provider-home/AGENTS.md +1 -0
  2240. package/src/services/provisioning-harness/fixtures/provider-home/CLAUDE.md +1 -0
  2241. package/src/services/provisioning-harness/host-fixtures.ts +25 -0
  2242. package/src/services/provisioning-harness/index.ts +4 -0
  2243. package/src/services/provisioning-harness/inventory-types.ts +8 -0
  2244. package/src/services/provisioning-harness/inventory.ts +33 -0
  2245. package/src/services/provisioning-harness/lifecycle.ts +193 -0
  2246. package/src/services/provisioning-harness/live.ts +61 -0
  2247. package/src/services/provisioning-harness/manifests.ts +118 -0
  2248. package/src/services/provisioning-harness/prepare.ts +113 -0
  2249. package/src/services/provisioning-harness/redundancy-report.ts +32 -0
  2250. package/src/services/provisioning-harness/redundancy.ts +137 -0
  2251. package/src/services/provisioning-harness/report.ts +129 -0
  2252. package/src/services/provisioning-harness/types.ts +174 -0
  2253. package/src/services/provisioning-registry.ts +15 -0
  2254. package/src/services/rate-limit-resume.ts +220 -0
  2255. package/src/services/reap-verdict.ts +52 -0
  2256. package/src/services/red-main-auto-revert.ts +103 -0
  2257. package/src/services/red-main-controller-deps.ts +80 -0
  2258. package/src/services/red-main-controller.ts +262 -0
  2259. package/src/services/red-main-incident.ts +44 -0
  2260. package/src/services/red-main-quarantine.ts +92 -0
  2261. package/src/services/register-agent.ts +447 -0
  2262. package/src/services/release-readiness.ts +219 -0
  2263. package/src/services/reported-exit-death.ts +29 -0
  2264. package/src/services/response-report-admission.ts +17 -0
  2265. package/src/services/restart-epoch-driver.ts +290 -0
  2266. package/src/services/restart-epoch-reconciler.ts +326 -0
  2267. package/src/services/restart-epoch-stale-command-recovery.ts +133 -0
  2268. package/src/services/restart-instructions.ts +86 -0
  2269. package/src/services/restart-project-role.ts +74 -0
  2270. package/src/services/restart-secret-refs.ts +14 -0
  2271. package/src/services/restart-spawn.ts +510 -0
  2272. package/src/services/review-publish.ts +76 -0
  2273. package/src/services/review-ref-reconcile.ts +337 -0
  2274. package/src/services/run-command-input.ts +22 -0
  2275. package/src/services/run-command.ts +510 -0
  2276. package/src/services/run-completion-message.ts +70 -0
  2277. package/src/services/run-log.ts +212 -0
  2278. package/src/services/run-queue.ts +63 -0
  2279. package/src/services/scheduler-command-cancel.ts +49 -0
  2280. package/src/services/scheduler-command.ts +590 -0
  2281. package/src/services/scheduler-create.ts +25 -0
  2282. package/src/services/scheduler-plan.ts +202 -0
  2283. package/src/services/scheduler-recovery.ts +31 -0
  2284. package/src/services/scheduler.ts +406 -0
  2285. package/src/services/self-care-state.ts +10 -0
  2286. package/src/services/self-effort-grant.ts +93 -0
  2287. package/src/services/self-effort.ts +152 -0
  2288. package/src/services/send-message.ts +548 -0
  2289. package/src/services/server-credentials.ts +53 -0
  2290. package/src/services/shipping-board.ts +111 -0
  2291. package/src/services/shipping-project-config.ts +86 -0
  2292. package/src/services/shipping-stats.ts +86 -0
  2293. package/src/services/shutdown-agent.ts +463 -0
  2294. package/src/services/shutdown-watchdog.ts +119 -0
  2295. package/src/services/spawn-agent.ts +967 -0
  2296. package/src/services/spawn-approval.ts +26 -0
  2297. package/src/services/spawn-brief.ts +39 -0
  2298. package/src/services/spawn-chain-inspector.ts +286 -0
  2299. package/src/services/spawn-cwd-placement.ts +250 -0
  2300. package/src/services/spawn-identity.ts +127 -0
  2301. package/src/services/spawn-instruction-inputs.ts +114 -0
  2302. package/src/services/spawn-issue-activity.ts +102 -0
  2303. package/src/services/spawn-launch-decision.ts +32 -0
  2304. package/src/services/spawn-launch.ts +116 -0
  2305. package/src/services/spawn-loss-escalation.ts +253 -0
  2306. package/src/services/spawn-placement.test-fixture.ts +30 -0
  2307. package/src/services/spawn-project-role.ts +133 -0
  2308. package/src/services/spawn-registration-watchdog.ts +352 -0
  2309. package/src/services/spawn-replay.ts +61 -0
  2310. package/src/services/spawn-repo-probe.ts +118 -0
  2311. package/src/services/spawn-tree-cleanup.ts +37 -0
  2312. package/src/services/spawn-warnings.ts +13 -0
  2313. package/src/services/steward-reaper.ts +244 -0
  2314. package/src/services/task-context-hydration.ts +413 -0
  2315. package/src/services/task-delivery-close.ts +26 -0
  2316. package/src/services/task-delivery-event.ts +11 -0
  2317. package/src/services/task-delivery-land-policy.ts +35 -0
  2318. package/src/services/task-delivery-summary.ts +38 -0
  2319. package/src/services/task-delivery.ts +762 -0
  2320. package/src/services/task-dependency-graph.ts +116 -0
  2321. package/src/services/task-dispatch.ts +178 -0
  2322. package/src/services/task-done-when.ts +45 -0
  2323. package/src/services/task-entity.ts +758 -0
  2324. package/src/services/task-from-issue.ts +80 -0
  2325. package/src/services/task-issue-digest.ts +45 -0
  2326. package/src/services/task-issue-link.ts +158 -0
  2327. package/src/services/task-issue-weave.ts +570 -0
  2328. package/src/services/task-land-withdraw.ts +462 -0
  2329. package/src/services/task-lifecycle.ts +668 -0
  2330. package/src/services/task-nothing-to-land.ts +37 -0
  2331. package/src/services/task-plan-view.ts +172 -0
  2332. package/src/services/task-review-hold.ts +244 -0
  2333. package/src/services/task-semantic-events.ts +396 -0
  2334. package/src/services/task-stage-wake.ts +15 -0
  2335. package/src/services/task-state-reconcile.ts +169 -0
  2336. package/src/services/task-validation.ts +42 -0
  2337. package/src/services/team-claim-race.worker.ts +72 -0
  2338. package/src/services/team-spawn-delegation.ts +30 -0
  2339. package/src/services/team-templates.ts +172 -0
  2340. package/src/services/team.ts +320 -0
  2341. package/src/services/terminal-provider-exit.ts +57 -0
  2342. package/src/services/timer-message-fire-chaos-worker.ts +29 -0
  2343. package/src/services/timer-message-fire-outbox.ts +184 -0
  2344. package/src/services/transient-agent-reaper.ts +412 -0
  2345. package/src/services/turn-reconcile-audit.ts +236 -0
  2346. package/src/services/user-onboarding.ts +98 -0
  2347. package/src/services/user-profile.ts +57 -0
  2348. package/src/services/web-search.ts +83 -0
  2349. package/src/services/web-tool-calls.ts +65 -0
  2350. package/src/services/withdraw-steward.ts +57 -0
  2351. package/src/services/work-finality.ts +34 -0
  2352. package/src/services/workflow-agent-obligation.ts +35 -0
  2353. package/src/services/workflow-auto-start.ts +126 -0
  2354. package/src/services/workflow-backstop.ts +38 -0
  2355. package/src/services/workflow-budget.test-fixture.ts +10 -0
  2356. package/src/services/workflow-caller.ts +32 -0
  2357. package/src/services/workflow-catalog.ts +43 -0
  2358. package/src/services/workflow-child-proof-worker.ts +76 -0
  2359. package/src/services/workflow-child.test-fixture.ts +51 -0
  2360. package/src/services/workflow-ci-main.ts +93 -0
  2361. package/src/services/workflow-control-proof-worker.ts +149 -0
  2362. package/src/services/workflow-coordinator-decision-proof-worker.ts +123 -0
  2363. package/src/services/workflow-coordinator.ts +8 -0
  2364. package/src/services/workflow-decision-answer.ts +18 -0
  2365. package/src/services/workflow-decision-proof-worker.ts +92 -0
  2366. package/src/services/workflow-decision.test-fixture.ts +58 -0
  2367. package/src/services/workflow-decisions.ts +107 -0
  2368. package/src/services/workflow-deferred-cleanup.ts +40 -0
  2369. package/src/services/workflow-dispatch-result.ts +20 -0
  2370. package/src/services/workflow-effect-driver.ts +165 -0
  2371. package/src/services/workflow-effects.ts +544 -0
  2372. package/src/services/workflow-foreach-proof-worker.ts +209 -0
  2373. package/src/services/workflow-land-notice.ts +18 -0
  2374. package/src/services/workflow-land.ts +105 -0
  2375. package/src/services/workflow-notice.ts +32 -0
  2376. package/src/services/workflow-overdue-notice.ts +19 -0
  2377. package/src/services/workflow-pins.ts +162 -0
  2378. package/src/services/workflow-reconcile.ts +210 -0
  2379. package/src/services/workflow-resume-pins.ts +30 -0
  2380. package/src/services/workflow-run-chaos-worker.ts +67 -0
  2381. package/src/services/workflow-run-view.ts +71 -0
  2382. package/src/services/workflow-run.test-fixture.ts +165 -0
  2383. package/src/services/workflow-runs.ts +370 -0
  2384. package/src/services/workflow-scripts.ts +100 -0
  2385. package/src/services/workflow-slice-proof.ts +14 -0
  2386. package/src/services/workflow-stats.ts +208 -0
  2387. package/src/services/workflow-supervisor-state.ts +117 -0
  2388. package/src/services/workflow-supervisor.ts +122 -0
  2389. package/src/services/workflow-verification.ts +68 -0
  2390. package/src/services/workspace-recovery.ts +168 -0
  2391. package/src/services/workspace-task-binding.ts +22 -0
  2392. package/src/settings/modules.ts +149 -0
  2393. package/src/settings/registry.ts +629 -0
  2394. package/src/settings/user-settings.ts +81 -0
  2395. package/src/setup.ts +199 -0
  2396. package/src/shared-mcp.ts +87 -0
  2397. package/src/shutdown.ts +33 -0
  2398. package/src/spawn-admission.ts +48 -0
  2399. package/src/spawn-budget.ts +18 -0
  2400. package/src/spawn-command.ts +373 -0
  2401. package/src/spawn-env.ts +27 -0
  2402. package/src/spawn-intent.ts +17 -0
  2403. package/src/spawn-lease.ts +41 -0
  2404. package/src/spawn-models.ts +22 -0
  2405. package/src/spawn-placement.ts +348 -0
  2406. package/src/spawn-profile-errors.ts +9 -0
  2407. package/src/spawn-quota.ts +15 -0
  2408. package/src/spawn-targets.ts +679 -0
  2409. package/src/sse-agent-status.ts +35 -0
  2410. package/src/sse-outbox-cursor.ts +28 -0
  2411. package/src/sse-visibility.ts +36 -0
  2412. package/src/sse.ts +684 -0
  2413. package/src/startup-context-injection.ts +518 -0
  2414. package/src/startup-timing.ts +30 -0
  2415. package/src/state-adoption/artifacts.ts +27 -0
  2416. package/src/state-adoption/cd-cutover.ts +125 -0
  2417. package/src/state-adoption/files.ts +31 -0
  2418. package/src/state-adoption/index.ts +166 -0
  2419. package/src/state-adoption/linux-plan.ts +67 -0
  2420. package/src/state-adoption/linux.ts +104 -0
  2421. package/src/state-adoption/macos-plan.ts +58 -0
  2422. package/src/state-adoption/macos.ts +112 -0
  2423. package/src/steward-claim-release.ts +38 -0
  2424. package/src/steward-handoff.ts +28 -0
  2425. package/src/steward-identity.ts +54 -0
  2426. package/src/steward-policy-cleanup.ts +222 -0
  2427. package/src/steward-policy-model-reconcile.ts +33 -0
  2428. package/src/steward-policy-name.ts +13 -0
  2429. package/src/steward-provenance.ts +59 -0
  2430. package/src/steward-queue.ts +85 -0
  2431. package/src/steward-slot-recovery.ts +34 -0
  2432. package/src/steward-spawn-guard.ts +344 -0
  2433. package/src/steward.test-fixture.ts +11 -0
  2434. package/src/steward.ts +199 -0
  2435. package/src/stream-proxy.ts +84 -0
  2436. package/src/task-authz.ts +40 -0
  2437. package/src/task-completion.ts +39 -0
  2438. package/src/task-dispatch-live.ts +70 -0
  2439. package/src/task-dispatcher-ranking.ts +136 -0
  2440. package/src/task-dispatcher.ts +841 -0
  2441. package/src/task-owner-notices.ts +35 -0
  2442. package/src/task-owner.ts +63 -0
  2443. package/src/task-plan-status.ts +21 -0
  2444. package/src/task-verification.ts +35 -0
  2445. package/src/team-idle-tracker.ts +39 -0
  2446. package/src/team-template-config.ts +100 -0
  2447. package/src/teams-config-store.ts +22 -0
  2448. package/src/terminal-authz.ts +49 -0
  2449. package/src/token-db-write.ts +44 -0
  2450. package/src/token-db.ts +487 -0
  2451. package/src/token-usage-async.ts +40 -0
  2452. package/src/transport-subscriptions.ts +57 -0
  2453. package/src/types.ts +1 -0
  2454. package/src/upgrade-install-verify.ts +179 -0
  2455. package/src/upgrade-local-id.ts +3 -0
  2456. package/src/upgrade-services.ts +125 -0
  2457. package/src/upgrade.ts +1006 -0
  2458. package/src/user-awaiting-reply.ts +42 -0
  2459. package/src/user-path.ts +246 -0
  2460. package/src/user-settings-async.ts +33 -0
  2461. package/src/user-settings-store.ts +106 -0
  2462. package/src/user-style.ts +83 -0
  2463. package/src/utils.ts +42 -0
  2464. package/src/validation.ts +324 -0
  2465. package/src/vault-backup-config.ts +28 -0
  2466. package/src/vault-expiry-config.ts +12 -0
  2467. package/src/versioned-prompts.ts +57 -0
  2468. package/src/workflow-capabilities.ts +10 -0
  2469. package/src/workflow-prompt-templates.ts +20 -0
  2470. package/src/workspace-action-audit.ts +42 -0
  2471. package/src/workspace-actions.ts +689 -0
  2472. package/src/workspace-auto-merge.ts +1055 -0
  2473. package/src/workspace-changed-paths-client.ts +97 -0
  2474. package/src/workspace-claim.ts +45 -0
  2475. package/src/workspace-cleanup-settle.ts +51 -0
  2476. package/src/workspace-cleanup-stale.ts +231 -0
  2477. package/src/workspace-command-settle.ts +589 -0
  2478. package/src/workspace-config.ts +7 -0
  2479. package/src/workspace-conflict-resolver.ts +182 -0
  2480. package/src/workspace-dead-owner-recovery.ts +19 -0
  2481. package/src/workspace-delivery-tip.ts +51 -0
  2482. package/src/workspace-escalation.ts +107 -0
  2483. package/src/workspace-git-state-client.ts +42 -0
  2484. package/src/workspace-host-client.ts +86 -0
  2485. package/src/workspace-host-target.ts +5 -0
  2486. package/src/workspace-host.ts +61 -0
  2487. package/src/workspace-human-escalation.ts +70 -0
  2488. package/src/workspace-land-gate-watchdog.ts +76 -0
  2489. package/src/workspace-land-gate.ts +99 -0
  2490. package/src/workspace-land-result.ts +12 -0
  2491. package/src/workspace-land-retry.ts +82 -0
  2492. package/src/workspace-land-stopped.ts +57 -0
  2493. package/src/workspace-merge-dispatch.ts +27 -0
  2494. package/src/workspace-merge-progress.ts +369 -0
  2495. package/src/workspace-merge-retry-policy.ts +59 -0
  2496. package/src/workspace-merge.ts +614 -0
  2497. package/src/workspace-nothing-to-land-notice.ts +27 -0
  2498. package/src/workspace-orphans.ts +927 -0
  2499. package/src/workspace-phase.ts +507 -0
  2500. package/src/workspace-pr-completion.ts +285 -0
  2501. package/src/workspace-probe.ts +212 -0
  2502. package/src/workspace-recorded-land.ts +47 -0
  2503. package/src/workspace-recovery-authz.ts +88 -0
  2504. package/src/workspace-rekey.ts +106 -0
  2505. package/src/workspace-steward-authority.ts +16 -0
  2506. package/src/workspace-steward-failure.ts +42 -0
  2507. package/src/workspace-steward-wake.ts +150 -0
  2508. package/src/workspace-steward-watchdog.ts +240 -0
@@ -0,0 +1,1411 @@
1
+ import { z } from "zod";
2
+ import { type EntityStore, type Grant, type HostCommandRun, type ModuleCtx, type StepResult, OpError, defineModule } from "./contract";
3
+
4
+ /**
5
+ * The timers pilot module: a Timers CRUD (`create`/`get`/`list`/`cancel`) served through the module
6
+ * host — default-deny authz, I/O validation, scope-tagged persistence and events, and atomic
7
+ * commit/rollback — plus DURABLE FIRING riding on the K7 workflow runtime (M3). Creating a timer
8
+ * enqueues a one-shot `fire` workflow that sleeps until `fireAt` and then, on a wakeup pass, flips
9
+ * the timer `scheduled → fired` and emits `timers.fired`. Firing is a `sleeping` journal row a
10
+ * wakeup pass claims — never a live `setTimeout` — so it is crash-durable and clock-deterministic.
11
+ *
12
+ * ── Command timers (Phase-2 P2-2, #1409) ────────────────────────────────────────────────────────
13
+ * A timer may carry a `command` spec. Instead of the plain `scheduled → fired` flip, its firing
14
+ * workflow issues a durable P3 command (`ctx.commands.issue("run-command", …)`) at the deadline and
15
+ * parks `waiting` on that command's terminal status (`waitFor:{kind:"command"}`). The orchestrator —
16
+ * NOT this process — execs the shell; the kernel only dispatches an authz-gated command and awaits
17
+ * it. The command's `idempotencyKey` is the timer id, so a re-driven `fire` step (a crash after the
18
+ * issue but before the journal memo) dedupes onto the SAME orchestrator command and never
19
+ * double-dispatches. The completion relay message rides the P2-3 outbox — see the `await` step.
20
+ *
21
+ * ── Relay-dispatch transactional outbox (Phase-2 P2-3, #1409) ────────────────────────────────────
22
+ * A timer that carries a `message` spec dispatches a Relay message on fire. The firing step does NOT
23
+ * call `sendMessageService` (the kernel must not import src, and a raw send would be a non-durable
24
+ * dual-write); instead it writes a `relaySend` OUTBOX row INSIDE its atomic step-commit. That single
25
+ * transaction commits the fired flip + `timers.fired` event + outbox row together or not at all, so the
26
+ * DECISION to send is journal-atomic exactly-once. A src-side drainer (`kernel-timers-outbox.ts`) then
27
+ * scans pending rows, calls `sendMessageService`, and marks each sent — at-least-once delivery deduped
28
+ * to effectively-once by the run-scoped `base:run:N` idempotency key `sendMessageService` already
29
+ * honors, identical to legacy `fireClaimedTimer`. Closes BOTH parity seams: the message-timer send and
30
+ * the command-timer completion send.
31
+ *
32
+ * SECURITY (R1): the command runs under the timer's FROZEN create-time identity snapshot
33
+ * (`command.identity`), reconstructed src-side into a cwd-constrained component token that
34
+ * `dispatchCommand`'s #968 gate binds the command cwd to. The kernel carries the snapshot opaquely;
35
+ * it never fabricates authority. See `src/services/kernel-timers-command.ts`.
36
+ *
37
+ * ── Recurring/interval + failure backoff (Phase-2 P2-5, #1409) ───────────────────────────────────
38
+ * A timer carrying `everyMs` is RECURRING: firing is a LOOPING workflow (arm→fire→arm) that reschedules
39
+ * the next deadline deterministically from durable state — `max(now+everyMs, prevFireAt+everyMs)`, no
40
+ * drift, no live `setTimeout` — and disables at `maxRuns`/`expiresAt` (parity with legacy
41
+ * `completeScheduledTimerRun`). The run number `N` a fire dispatches under lives in the firing workflow's
42
+ * MEMOIZED state (`state.run`, reconstructed by the journal fold), so a crash-recovery re-drive of run N
43
+ * recomputes the SAME N → the `base:run:N` outbox dedup holds → exactly-once send (G3). A fire that
44
+ * ERRORS is a timer-run-level failure: it bumps `consecutiveFailures`, reschedules at `now+retryMs`, and
45
+ * disables after `maxFailures` (parity with legacy `recordScheduledTimerFailure`) — distinct from the M3
46
+ * per-step retry.
47
+ *
48
+ * Cutover note (#1408): this proves kernel-served firing at the module's own semantic level
49
+ * (schedule/cancel/list/fire/command/relay-send/recurring). It is NOT yet a full functional replacement
50
+ * for the legacy prod timers in `src/db/scheduled-timers.ts`: the MCP write surface for recurring params
51
+ * remains deferred create-path parity work (P2-7) before a real prod cutover. Relay message dispatch
52
+ * (message + command-completion sends) is covered by the P2-3 outbox above.
53
+ */
54
+
55
+ // `disabled` (P2-5) is the terminal state a recurring/one-shot timer lands in when it stops WITHOUT a
56
+ // clean fire — it expired before delivery, or its FIRE failed `SCHEDULER_MAX_FAILURES` times (the
57
+ // legacy `enabled=0 + last_error` disable). `fired` remains "completed a run" (one-shot fired, or a
58
+ // recurring timer reached `maxRuns` / would run past `expiresAt` AFTER a successful run). `cancelled`
59
+ // stays user-initiated. Only `scheduled` is active/armed — the fire step's cancel-safe guard keys on it.
60
+ const statusSchema = z.enum(["scheduled", "fired", "cancelled", "disabled"]);
61
+
62
+ /** Ceiling on a command-timer shell string, mirroring the legacy `cleanCommand` 8000-char cap
63
+ * (`scheduler-command.ts`). Bounds the durable-command payload the kernel path can persist. */
64
+ const MAX_COMMAND_CHARS = 8_000;
65
+
66
+ /** The grant a command timer's creator must hold — the kernel spelling of the legacy `command:write`
67
+ * scope `normalizeScheduleCommand` requires. `command:write` is a valid flat {@link Grant}, so the op
68
+ * can enforce it from `ctx.principal.grants` (the invoker-resolved principal) with no contract change. */
69
+ const COMMAND_WRITE_GRANT: Grant = "command:write";
70
+
71
+ /** The admin grant that lets a principal cross creators on `list`/`cancel` (mirrors the legacy
72
+ * `canAdministerTimers`: `actor.kind === "system" || hasScope("system:admin")`). The kernel Principal
73
+ * carries no actor-kind, so the MCP binding maps a system/admin token to this grant. */
74
+ const TIMERS_ADMIN_GRANT: Grant = "system:admin";
75
+
76
+ /** The grant the P2-3 relay-outbox drainer holds. A system-only capability distinct from the
77
+ * creator-facing `timers:read`/`timers:write` — the drain ops (`drainRelaySends`/`markRelaySendSent`)
78
+ * cross creators to see every pending send, so an ordinary timer creator must NOT be able to invoke
79
+ * them. The src supervisor injects an identity carrying exactly this grant; the ops are never exposed
80
+ * over any transport (see `expose`). */
81
+ const TIMERS_DRAIN_GRANT: Grant = "timers:admin";
82
+
83
+ /** The grant that lets a principal create an UNBOUNDED recurring timer (no `maxRuns`/`expiresAt`) —
84
+ * the kernel spelling of the legacy `schedule:persistent` scope `canCreatePersistentTimer` honors. A
85
+ * `system:admin` principal also qualifies (mirrors `canAdministerTimers`). The scope→grant mapping the
86
+ * MCP binding performs is the deferred P2-7 create-path seam (gates G1/G2); the `create` op enforces
87
+ * the RULE from `ctx.principal.grants` here, with no contract change. */
88
+ const SCHEDULE_PERSISTENT_GRANT: Grant = "schedule:admin";
89
+
90
+ /** The frozen create-time creator identity a timer's external effects fire under (R1). Mirrors the
91
+ * legacy `persistedAuthContext` snapshot (createdBy/kind/scopes/constraints). BOTH parity seams carry
92
+ * it: a command timer's `run-command` exec (P2-2) AND a message/command timer's relay-send outbox
93
+ * (P2-3), so the src side reconstructs the SAME `ComponentToken` the creator held — never a widened
94
+ * one. The kernel treats `constraints` as an OPAQUE JSON blob — it never imports the src
95
+ * `TokenConstraints` type — and hands it verbatim to the src translator/drainer.
96
+ *
97
+ * SECURITY (P2-4 / C2 residual #1): this snapshot is the SERVER-resolved authority — the `create` op
98
+ * builds it from `ctx.principal` (createdBy = the authenticated actor; createdByScopes = the invoker
99
+ * -resolved grants) + the token's real cwd constraint, NEVER from client input. See `create.handler`. */
100
+ const frozenIdentitySchema = z.object({
101
+ createdBy: z.string(),
102
+ createdByKind: z.string(),
103
+ createdByScopes: z.array(z.string()),
104
+ createdByConstraints: z.record(z.string(), z.unknown()).optional(),
105
+ createdAt: z.number().int(),
106
+ });
107
+
108
+ /** A command timer's persisted payload: the shell command + where/how it runs + the FROZEN creator
109
+ * identity. This is the ENTITY / `run-command` shape — the server-built `identity` is present. The
110
+ * client-facing create INPUT uses {@link commandRequestSchema} instead (no server-owned identity). */
111
+ const commandSpecSchema = z.object({
112
+ command: z.string().min(1).max(MAX_COMMAND_CHARS),
113
+ cwd: z.string().min(1),
114
+ env: z.record(z.string(), z.string()).optional(),
115
+ timeoutMs: z.number().int().positive(),
116
+ orchestratorId: z.string().min(1),
117
+ identity: frozenIdentitySchema,
118
+ });
119
+
120
+ /** The client-facing command spec on the `create` op input: the exec request WITHOUT any creator
121
+ * identity. G1 (#1409): NO identity field is accepted from op input at all — createdBy / kind / scopes
122
+ * / constraints are ALL server-resolved by the op from `ctx.principal` (its `actor`, `grants`, and the
123
+ * trusted `resolvedIdentity` the host binding attaches from the authenticated token) + the kernel clock.
124
+ * A client thus cannot name a creator, broaden its scopes, or supply a wider cwd constraint — even a
125
+ * hostile `identity`/`createdByConstraints` key on the wire is an unknown Zod strips before the handler
126
+ * runs. See `freezeIdentity` / `freezeCommandTimer`. */
127
+ const commandRequestSchema = z.object({
128
+ command: z.string().min(1).max(MAX_COMMAND_CHARS),
129
+ cwd: z.string().min(1),
130
+ env: z.record(z.string(), z.string()).optional(),
131
+ timeoutMs: z.number().int().positive(),
132
+ orchestratorId: z.string().min(1),
133
+ });
134
+
135
+ /** ── Relay-dispatch outbox (P2-3, #1409) ─────────────────────────────────────────────────────────
136
+ * The fully-resolved relay send a timer fires, persisted so a MESSAGE timer (and a command timer's
137
+ * completion) can dispatch a Relay message at parity with legacy `sendMessageService`. The kernel
138
+ * NEVER sends: it writes the send as an outbox row IN the atomic step-commit tx (journal-atomic
139
+ * exactly-once on the DECISION to send), and a src-side drainer performs the effect, deduped by the
140
+ * run-scoped `idempotencyKey` (`base:run:N`) `sendMessageService` already honors. See the `fire`/
141
+ * `await` steps + `src/services/kernel-timers-outbox.ts`. */
142
+
143
+ /** The client-facing message spec on `create`: WHERE/WHAT to send, plus the same server-resolved
144
+ * authority hints the command request carries. `from` defaults to the resolved creator; `body` is
145
+ * required for a pure message timer (validated in the handler) but optional for a command timer, whose
146
+ * completion body defaults from the command outcome. `idempotencyKey` is the OPTIONAL delivery-dedup
147
+ * BASE — the outbox stamps `base:run:N` from it (falling back to `scheduler:<id>`), matching legacy. */
148
+ const messageRequestSchema = z.object({
149
+ to: z.string().min(1),
150
+ from: z.string().min(1).optional(),
151
+ kind: z.string().min(1).optional(),
152
+ channel: z.string().min(1).optional(),
153
+ subject: z.string().min(1).optional(),
154
+ body: z.string().min(1).optional(),
155
+ claimable: z.boolean().optional(),
156
+ payload: z.record(z.string(), z.unknown()).optional(),
157
+ meta: z.record(z.string(), z.unknown()).optional(),
158
+ idempotencyKey: z.string().min(1).optional(),
159
+ // G1 (#1409): NO creator identity is accepted from op input — the send fires under the server-resolved
160
+ // frozen identity (`freezeIdentity` from `ctx.principal`), never a client-named one.
161
+ });
162
+
163
+ /** A timer's persisted relay-send spec: the resolved send + the FROZEN creator identity the drainer
164
+ * fires under (R1 — mirrors legacy `persistedAuthContext`, so the component send gate runs under the
165
+ * creator's real reach, not a widened one). `from` and `identity` are server-resolved. */
166
+ const messageSpecSchema = z.object({
167
+ from: z.string().min(1),
168
+ to: z.string().min(1),
169
+ kind: z.string().min(1).optional(),
170
+ channel: z.string().min(1).optional(),
171
+ subject: z.string().min(1).optional(),
172
+ body: z.string().min(1).optional(),
173
+ claimable: z.boolean().optional(),
174
+ payload: z.record(z.string(), z.unknown()).optional(),
175
+ meta: z.record(z.string(), z.unknown()).optional(),
176
+ idempotencyKey: z.string().min(1).optional(),
177
+ /** D1 (#1409): the legacy `scheduler.correlationId` (`timer:<id>`) the fired message's payload/meta
178
+ * `scheduler` block carries, so a kernel-fired message is byte-identical to a legacy-fired one for a
179
+ * consumer keying off it. Server-derived at create (`timer:<id>`); the migrate op carries the legacy
180
+ * row's persisted value verbatim. Absent → the outbox falls back to `timer:<timerId>` (see
181
+ * `messageOutboxInput`), so a correlationId is ALWAYS stamped. */
182
+ correlationId: z.string().min(1).optional(),
183
+ identity: frozenIdentitySchema,
184
+ });
185
+
186
+ const relaySendStatusSchema = z.enum(["pending", "sent"]);
187
+
188
+ /** ── T-0 apply fencing (#1409 hardening) ─────────────────────────────────────────────────────────
189
+ * The durable per-timer LAST-APPLIED-FENCE record for the ingress apply seam. The fence token is the
190
+ * ingress log's `seq` — globally monotone and never reused, hence STRICTLY monotone per timer. A
191
+ * fenced `migrate`/`cancelMirror` whose `fence` is LOWER than this row's is refused AT THE KERNEL
192
+ * WRITE (`fenced: true`, no entity mutation, no workflow start, no event): a live-but-lease-expired
193
+ * applier resuming a stale create after a newer cancel already applied can never arm the timer.
194
+ * A fenced cancel of an ABSENT entity still writes this row — the durable KERNEL TOMBSTONE that
195
+ * refuses the stale create ("a cancel has already been applied for this timerId at fence ≥ mine").
196
+ * Cross-process safety: the row is read-checked in the handler and (re-)written in the op's atomic
197
+ * commit, whose optimistic-version CAS / PK-conflict aborts a raced flush — the loser retries,
198
+ * re-reads the newer fence, and refuses cleanly. Equal fences (a same-intent crash re-drive)
199
+ * proceed idempotently. Unfenced calls (no `fence` input — the pre-activation shadow mirror and the
200
+ * P2-6 migration script, which run under LEGACY authority) neither check nor touch this record.
201
+ *
202
+ * SECOND-PASS HARDENING (#1409, T1175): the CAS covers ALL side effects of an apply, not just the
203
+ * entity — `migrate`'s firing-workflow enqueue is ENLISTED in the same atomic op commit
204
+ * (`enlist: "op-commit"`), so the instance seed sits in the very transaction this fence's
205
+ * CAS/PK-conflict aborts. A migrate that read a stale fence and loses the flush race commits
206
+ * NOTHING (no entity, no event, no fence, no workflow instance); a later same-id create therefore
207
+ * has no orphan to dedupe onto and can never fire at a rolled-back migrate's stale deadline. */
208
+ const applyFenceSchema = z.object({
209
+ /** The timer id this fence guards (the entity key). */
210
+ id: z.string(),
211
+ /** The highest ingress fence (log seq) whose apply committed for this timer. */
212
+ fence: z.number().int().positive(),
213
+ /** Which op applied at that fence — `cancel` on an absent entity IS the durable tombstone. */
214
+ op: z.enum(["create", "cancel"]),
215
+ updatedAt: z.number().int(),
216
+ });
217
+
218
+ /** The transactional-outbox entity: one fully-resolved, ready-to-dispatch Relay send. Written INSIDE
219
+ * the firing step's atomic commit (so the decision to send is journal-atomic exactly-once) and drained
220
+ * by the src side, which flips `status` to `sent` after `sendMessageService` returns. Delivery is
221
+ * at-least-once (a crash between send and mark re-drains) but deduped to effectively-once by
222
+ * `idempotencyKey` (`base:run:N`) — the exact key `sendMessageService` dedupes on. `identity` is the
223
+ * frozen creator snapshot the drainer reconstructs the send AuthContext from. */
224
+ const relaySendSchema = z.object({
225
+ id: z.string(),
226
+ /** The timer that produced this send — for tracing/observability + the drainer's per-row context. */
227
+ timerId: z.string(),
228
+ /** The run-scoped delivery-dedup key `sendMessageService` honors: a re-drain re-presents the SAME
229
+ * key, so a crash between the send and the `sent` mark never doubles the message. */
230
+ idempotencyKey: z.string(),
231
+ status: relaySendStatusSchema.default("pending"),
232
+ from: z.string(),
233
+ to: z.string(),
234
+ kind: z.string().optional(),
235
+ channel: z.string().optional(),
236
+ subject: z.string().optional(),
237
+ body: z.string(),
238
+ claimable: z.boolean().optional(),
239
+ payload: z.record(z.string(), z.unknown()).optional(),
240
+ meta: z.record(z.string(), z.unknown()).optional(),
241
+ /** The frozen creator identity the drainer fires the send under (R1). */
242
+ identity: frozenIdentitySchema,
243
+ /** Set by the drainer once the send lands — observability only; dedup is by `idempotencyKey`. */
244
+ sentMessageId: z.number().int().optional(),
245
+ createdAt: z.number().int(),
246
+ });
247
+
248
+ const timerSchema = z.object({
249
+ id: z.string(),
250
+ label: z.string(),
251
+ /** The actor id (from `ctx.principal.actor`) that created the timer — the per-creator ownership key
252
+ * `list`/`cancel`/`get` filter on for a non-admin principal (C2). Server-stamped; never client input. */
253
+ createdBy: z.string(),
254
+ /** Epoch milliseconds at which the timer is due to fire. For a recurring timer this is the CURRENT
255
+ * run's deadline; the fire step advances it deterministically for each subsequent run. */
256
+ fireAt: z.number().int(),
257
+ status: statusSchema.default("scheduled"),
258
+ /** ── Recurring/interval (P2-5) ─────────────────────────────────────────────────────────────────
259
+ * Present iff this is a RECURRING timer: the fixed interval between runs. Firing loops arm→fire→arm
260
+ * (a looping workflow), rescheduling `fireAt` to `max(now+everyMs, prevFireAt+everyMs)` — computed
261
+ * from durable state, never the wall clock, so it cannot drift. Command timers may NOT be recurring
262
+ * (legacy parity); enforced at `create`. */
263
+ everyMs: z.number().int().positive().optional(),
264
+ /** A recurring timer disables (terminal `fired`) once it has completed this many runs. */
265
+ maxRuns: z.number().int().positive().optional(),
266
+ /** Epoch ms after which the timer stops: it disables before firing a run past this, and a fire whose
267
+ * deadline is already past `expiresAt` disables WITHOUT firing (legacy `fireClaimedTimer` expiry). */
268
+ expiresAt: z.number().int().optional(),
269
+ /** Runs COMPLETED so far (bumped on each successful fire) — the observability counter, parity with
270
+ * legacy `run_count`. NOTE: the durable, re-drive-stable run NUMBER a fire dispatches under lives in
271
+ * the firing workflow's memoized `state.run` (the journal fold), NOT here — this is a projection. */
272
+ runCount: z.number().int().nonnegative().default(0),
273
+ /** Consecutive FIRE failures (parity with legacy `consecutive_failures`): bumped when a fire errors,
274
+ * reset to 0 on a successful run. The timer disables after `maxFailures` consecutive failures. */
275
+ consecutiveFailures: z.number().int().nonnegative().default(0),
276
+ /** The last fire error (parity with legacy `last_error`); cleared on a successful run. */
277
+ lastError: z.string().optional(),
278
+ /** Present iff this is a command timer: firing dispatches this command and awaits it (see above). */
279
+ command: commandSpecSchema.optional(),
280
+ /** Present iff the timer dispatches a Relay message on fire (P2-3): the resolved send + frozen
281
+ * creator identity. A MESSAGE timer carries it as its whole effect; a COMMAND timer may carry it as
282
+ * the completion send composed once the command settles. Absent → firing is a pure status flip
283
+ * (the pre-P2-3 pilot behavior, preserved). */
284
+ message: messageSpecSchema.optional(),
285
+ });
286
+
287
+ const configSchema = z.object({
288
+ /** Per-creator active (scheduled) timer quota — the kernel spelling of legacy
289
+ * `SCHEDULER_MAX_ACTIVE_TIMERS` (default 100). env-backed, so it must coerce from a string. */
290
+ maxTimers: z.coerce.number().int().positive().default(100),
291
+ /** Max lead time a timer may be scheduled ahead — the kernel spelling of the legacy command
292
+ * `afterMs ≤ 24h` ceiling, applied to EVERY timer so the kernel path can't evade it. */
293
+ maxFireAheadMs: z.coerce.number().int().positive().default(24 * 60 * 60 * 1000),
294
+ /** Minimum interval a RECURRING timer may specify — the kernel spelling of legacy
295
+ * `SCHEDULER_MIN_RECURRING_INTERVAL_MS` (default 60s). Enforced at `create` (P2-5 SCOPE 4). */
296
+ minRecurringIntervalMs: z.coerce.number().int().positive().default(60 * 1000),
297
+ /** Backoff before a FAILED fire's next attempt — the kernel spelling of legacy `SCHEDULER_RETRY_MS`
298
+ * (default 60s). A fire error reschedules the SAME run at `now + retryMs` (P2-5 SCOPE 3). */
299
+ retryMs: z.coerce.number().int().positive().default(60 * 1000),
300
+ /** Consecutive fire failures that disable a timer — the kernel spelling of legacy
301
+ * `SCHEDULER_MAX_FAILURES` (default 3) (P2-5 SCOPE 3). */
302
+ maxFailures: z.coerce.number().int().positive().default(3),
303
+ /** Label applied to a created timer when the caller supplies none. */
304
+ defaultLabel: z.string().min(1).default("timer"),
305
+ });
306
+
307
+ export type Timer = z.output<typeof timerSchema>;
308
+ export type TimerCommandSpec = z.output<typeof commandSpecSchema>;
309
+ export type TimerMessageSpec = z.output<typeof messageSpecSchema>;
310
+ export type RelaySend = z.output<typeof relaySendSchema>;
311
+ export type TimerApplyFence = z.output<typeof applyFenceSchema>;
312
+ export type TimersConfig = z.output<typeof configSchema>;
313
+
314
+ /** Does the opaque constraint blob pin the cwd(s) a command may run in? Mirrors the bridge's
315
+ * `hasCwdConstraint` / `dispatch-command`'s #968 precondition: an UNCONSTRAINED creator identity would
316
+ * clear the fire-time authz WITHOUT the cwd gate ever running, so a command timer must carry one at
317
+ * create. Kept structural (no src `TokenConstraints` import) — checks the two known cwd axes. */
318
+ function hasCwdConstraint(constraints: Record<string, unknown> | undefined): boolean {
319
+ if (!constraints) return false;
320
+ const cwd = constraints.cwd;
321
+ const prefixes = constraints.cwdPrefixes;
322
+ return (typeof cwd === "string" && cwd.length > 0) || (Array.isArray(prefixes) && prefixes.length > 0);
323
+ }
324
+
325
+ /** A principal may cross creators (see/cancel any timer) iff it holds the admin grant (C2). Mirrors
326
+ * legacy `canAdministerTimers`; the MCP binding maps a `system` actor / `system:admin` scope onto it. */
327
+ function isTimersAdmin(ctx: ModuleCtx): boolean {
328
+ return ctx.principal.grants.has(TIMERS_ADMIN_GRANT);
329
+ }
330
+
331
+ /** The per-creator ownership filter a non-admin op applies from the authenticated actor (C2). An admin
332
+ * returns `undefined` (no restriction). This is the op-level `where: {createdBy}` the design mandates. */
333
+ function creatorFilter(ctx: ModuleCtx): { createdBy: string } | undefined {
334
+ return isTimersAdmin(ctx) ? undefined : { createdBy: ctx.principal.actor };
335
+ }
336
+
337
+ /** May this principal create an UNBOUNDED recurring timer (no `maxRuns`/`expiresAt`)? Mirrors legacy
338
+ * `canCreatePersistentTimer`: an admin, or a holder of the persistent grant (P2-5 SCOPE 4). */
339
+ function canCreatePersistentTimer(ctx: ModuleCtx): boolean {
340
+ return isTimersAdmin(ctx) || ctx.principal.grants.has(SCHEDULE_PERSISTENT_GRANT);
341
+ }
342
+
343
+ /** Human-readable message from any thrown value (inlined; the kernel never imports the src SDK). */
344
+ function errMessage(error: unknown): string {
345
+ return error instanceof Error ? error.message : String(error);
346
+ }
347
+
348
+ /**
349
+ * Server-resolve + FREEZE a creator identity from the authenticated principal (G1/G2, #1409). Every
350
+ * field is server-sourced — NONE from client op input:
351
+ * • `createdBy` = `ctx.principal.actor` (the authenticated actor);
352
+ * • `createdAt` = the kernel clock;
353
+ * • `createdByKind` / `createdByScopes` / `createdByConstraints` = the trusted
354
+ * `ctx.principal.resolvedIdentity` the host binding attached from the authenticated TOKEN.
355
+ * So a client can neither name a different creator, broaden its scopes, nor widen its cwd constraint
356
+ * (G1 — a hostile `createdByConstraints:["/"] ` on the wire never reaches here). The frozen snapshot
357
+ * reconstructs the SAME create-time authority legacy `persistedAuthContext` did — shared by both parity
358
+ * seams (command exec P2-2 and relay send P2-3).
359
+ *
360
+ * G2 (#1409): `createdByScopes` is the creator's REAL transport scopes (`resolvedIdentity.scopes`,
361
+ * e.g. `message:send`) — NOT the flat kernel grants, which the grammar cannot spell `message:send` in.
362
+ * That is what lets the P2-3 outbox drainer's `sendMessageService` authorize under the creator's
363
+ * message-send scope instead of failing closed at fire time. When no `resolvedIdentity` rides the
364
+ * principal (a system/test caller that mints no durable send), it falls back to the principal grants.
365
+ */
366
+ function freezeIdentity(ctx: ModuleCtx, createdBy: string, now: number): z.output<typeof frozenIdentitySchema> {
367
+ const resolved = ctx.principal.resolvedIdentity;
368
+ const constraints = resolved?.constraints;
369
+ return {
370
+ createdBy,
371
+ createdByKind: resolved?.kind ?? "component",
372
+ createdByScopes: resolved?.scopes ? [...resolved.scopes] : ([...ctx.principal.grants] as string[]),
373
+ ...(constraints ? { createdByConstraints: { ...constraints } } : {}),
374
+ createdAt: now,
375
+ };
376
+ }
377
+
378
+ /**
379
+ * Server-resolve + FREEZE a command timer's exec spec + creator identity. Preconditions mirror the
380
+ * legacy `normalizeScheduleCommand` + `assertScheduleCommandAuthorized`:
381
+ * • the caller MUST hold the `command:write` grant (else no command timer at all), and
382
+ * • the frozen identity MUST carry a cwd constraint (else the fire-time #968 gate would not fire).
383
+ * Throws a typed {@link OpError} (fail-closed) on either.
384
+ */
385
+ function freezeCommandTimer(
386
+ ctx: ModuleCtx,
387
+ request: z.output<typeof commandRequestSchema>,
388
+ createdBy: string,
389
+ now: number,
390
+ ): z.output<typeof commandSpecSchema> {
391
+ if (!ctx.principal.grants.has(COMMAND_WRITE_GRANT)) {
392
+ throw new OpError("unauthorized", 403, "command timers require the 'command:write' grant");
393
+ }
394
+ // The cwd constraint is read from the SERVER-resolved identity (`ctx.principal.resolvedIdentity`),
395
+ // never from client input (G1) — so an unconstrained creator cannot create a command timer, and a
396
+ // client cannot fabricate a wide constraint to clear this gate.
397
+ if (!hasCwdConstraint(ctx.principal.resolvedIdentity?.constraints)) {
398
+ throw new OpError("unauthorized", 403, "command timers require a cwd-constrained creator identity");
399
+ }
400
+ return {
401
+ command: request.command,
402
+ cwd: request.cwd,
403
+ ...(request.env ? { env: request.env } : {}),
404
+ timeoutMs: request.timeoutMs,
405
+ orchestratorId: request.orchestratorId,
406
+ identity: freezeIdentity(ctx, createdBy, now),
407
+ };
408
+ }
409
+
410
+ /**
411
+ * Server-resolve + FREEZE a timer's relay-send spec (P2-3). `from` resolves server-side (the wire
412
+ * `from`, else the resolved creator) and `identity` is frozen from the authenticated principal, so the
413
+ * drainer fires the send under the creator's REAL reach — the component send gate runs exactly as it
414
+ * did for legacy `persistedAuthContext`. A message timer (no command) additionally REQUIRES a body; a
415
+ * command timer's completion body may be absent (it defaults from the command outcome at settle).
416
+ */
417
+ function freezeMessageTimer(
418
+ ctx: ModuleCtx,
419
+ request: z.output<typeof messageRequestSchema>,
420
+ createdBy: string,
421
+ now: number,
422
+ requireBody: boolean,
423
+ correlationId: string,
424
+ ): z.output<typeof messageSpecSchema> {
425
+ if (requireBody && (request.body === undefined || request.body.length === 0)) {
426
+ throw new OpError("invalid_input", 400, "a message timer requires message.body");
427
+ }
428
+ return {
429
+ from: request.from ?? createdBy,
430
+ to: request.to,
431
+ ...(request.kind ? { kind: request.kind } : {}),
432
+ ...(request.channel ? { channel: request.channel } : {}),
433
+ ...(request.subject ? { subject: request.subject } : {}),
434
+ ...(request.body ? { body: request.body } : {}),
435
+ ...(request.claimable !== undefined ? { claimable: request.claimable } : {}),
436
+ ...(request.payload ? { payload: request.payload } : {}),
437
+ ...(request.meta ? { meta: request.meta } : {}),
438
+ ...(request.idempotencyKey ? { idempotencyKey: request.idempotencyKey } : {}),
439
+ // D1 (#1409): stamp legacy's `timer:<id>` correlation id so the fired message is byte-identical.
440
+ correlationId,
441
+ identity: freezeIdentity(ctx, createdBy, now),
442
+ };
443
+ }
444
+
445
+ /** ── Recurring reschedule + failure backoff math (P2-5) — PURE, mirroring legacy exactly ───────────
446
+ * These derive the NEXT deadline from DURABLE state (the timer entity + the workflow's memoized run
447
+ * number), never the wall clock, so a re-drive recomputes an identical result. Exported for direct
448
+ * unit tests (parity with `completeScheduledTimerRun` / `recordScheduledTimerFailure`). */
449
+
450
+ /** The next recurring run's absolute deadline: `max(now+everyMs, prevFireAt+everyMs)`. Mirrors legacy
451
+ * `completeScheduledTimerRun`'s `candidateNextRunAt` — a late wakeup schedules the next run `everyMs`
452
+ * after NOW (self-correcting), never in the past, and an on-time run stays perfectly on the grid (no
453
+ * drift, since it derives from `prevFireAt`, not the actual — possibly late — wakeup time). */
454
+ export function nextRecurringFireAt(everyMs: number, now: number, prevFireAt: number): number {
455
+ return Math.max(now + everyMs, prevFireAt + everyMs);
456
+ }
457
+
458
+ /** Whether a recurring timer keeps looping after completing run `runsCompleted`, and its next deadline.
459
+ * Mirrors legacy `completeScheduledTimerRun`'s disable logic: a non-recurring timer is always terminal;
460
+ * a recurring one disables at `maxRuns` or when its next deadline would fall past `expiresAt`. */
461
+ export type RecurringContinuation =
462
+ | { readonly kind: "continue"; readonly nextFireAt: number; readonly nextRun: number }
463
+ | { readonly kind: "terminal" };
464
+
465
+ export function recurringContinuation(input: {
466
+ everyMs: number | undefined;
467
+ now: number;
468
+ prevFireAt: number;
469
+ runsCompleted: number;
470
+ maxRuns: number | undefined;
471
+ expiresAt: number | undefined;
472
+ }): RecurringContinuation {
473
+ if (input.everyMs === undefined) return { kind: "terminal" };
474
+ const nextFireAt = nextRecurringFireAt(input.everyMs, input.now, input.prevFireAt);
475
+ const reachedMaxRuns = input.maxRuns !== undefined && input.runsCompleted >= input.maxRuns;
476
+ const expiredBeforeNext = input.expiresAt !== undefined && nextFireAt > input.expiresAt;
477
+ if (reachedMaxRuns || expiredBeforeNext) return { kind: "terminal" };
478
+ return { kind: "continue", nextFireAt, nextRun: input.runsCompleted + 1 };
479
+ }
480
+
481
+ /** The outcome of a FAILED fire: retry after `retryMs` (same run number), or disable once
482
+ * `consecutiveFailures` reaches `maxFailures`. Mirrors legacy `recordScheduledTimerFailure`. */
483
+ export type FailureOutcome =
484
+ | { readonly kind: "retry"; readonly nextFireAt: number; readonly failures: number }
485
+ | { readonly kind: "disable"; readonly failures: number };
486
+
487
+ export function failureBackoff(input: {
488
+ now: number;
489
+ consecutiveFailures: number;
490
+ retryMs: number;
491
+ maxFailures: number;
492
+ }): FailureOutcome {
493
+ const failures = input.consecutiveFailures + 1;
494
+ if (failures >= input.maxFailures) return { kind: "disable", failures };
495
+ return { kind: "retry", nextFireAt: input.now + input.retryMs, failures };
496
+ }
497
+
498
+ /** The run-scoped delivery-dedup key `sendMessageService` honors (`base:run:N`). Mirrors legacy
499
+ * `timerRunIdempotencyKey`: base is the caller's `idempotencyKey`, else `scheduler:<timerId>`. */
500
+ function relaySendKey(message: z.output<typeof messageSpecSchema>, timerId: string, run: number): string {
501
+ const base = message.idempotencyKey ?? `scheduler:${timerId}`;
502
+ return `${base}:run:${run}`;
503
+ }
504
+
505
+ /** Stamp the legacy `scheduler` correlation block onto a send's payload/meta so a drained message is
506
+ * observably a timer fire (parity with `fireClaimedTimer`). Non-mutating. */
507
+ function withScheduler(
508
+ base: Record<string, unknown> | undefined,
509
+ scheduler: Record<string, unknown>,
510
+ ): Record<string, unknown> {
511
+ return { ...(base ?? {}), scheduler };
512
+ }
513
+
514
+ /** A durable command result the completion send summarizes (the `run-command` decl's result shape). */
515
+ type CommandRunResult = { exitCode: number | null; timedOut: boolean; stdoutTail: string; stderrTail: string };
516
+
517
+ /** A human completion line for a command timer whose configured `message.body` was omitted. Mirrors
518
+ * the shape of legacy `commandSummary` (status + exit code) over the kernel command result. */
519
+ function commandCompletionBody(result: CommandRunResult | undefined): string {
520
+ if (!result) return "Background command completed";
521
+ const label = result.timedOut ? "timed out" : result.exitCode === 0 ? "succeeded" : "failed";
522
+ const code = result.exitCode === null || result.exitCode === undefined ? "" : ` (exit ${result.exitCode})`;
523
+ return `Background command ${label}${code}`;
524
+ }
525
+
526
+ /** Build the fully-resolved outbox row for a MESSAGE timer's send. `run` is the DURABLE, re-drive-stable
527
+ * run number (`state.run` from the firing workflow's journal fold — 1, 2, 3, … for a recurring timer);
528
+ * the `scheduler` stamp + `base:run:N` key mirror legacy `fireClaimedTimer`. */
529
+ function messageOutboxInput(
530
+ ctx: ModuleCtx,
531
+ timer: Timer,
532
+ message: z.output<typeof messageSpecSchema>,
533
+ run: number,
534
+ ): z.input<typeof relaySendSchema> {
535
+ // D1 (#1409): stamp `correlationId` (`timer:<id>`) alongside `timerId`/`run` so the delivered
536
+ // message's `scheduler` block is byte-identical to legacy `fireClaimedTimer`. Always present: the
537
+ // frozen `message.correlationId` when set (native create / migrate), else derived from the timer id.
538
+ const scheduler = { timerId: timer.id, correlationId: message.correlationId ?? `timer:${timer.id}`, run };
539
+ return {
540
+ id: ctx.rng.uuid(),
541
+ timerId: timer.id,
542
+ idempotencyKey: relaySendKey(message, timer.id, run),
543
+ status: "pending",
544
+ from: message.from,
545
+ to: message.to,
546
+ ...(message.kind ? { kind: message.kind } : {}),
547
+ ...(message.channel ? { channel: message.channel } : {}),
548
+ ...(message.subject ? { subject: message.subject } : {}),
549
+ body: message.body ?? "",
550
+ ...(message.claimable !== undefined ? { claimable: message.claimable } : {}),
551
+ payload: withScheduler(message.payload, scheduler),
552
+ meta: withScheduler(message.meta, scheduler),
553
+ identity: message.identity,
554
+ createdAt: ctx.clock.now(),
555
+ };
556
+ }
557
+
558
+ /** Project a pure MESSAGE send into the shared immutable fire/outbox payload. */
559
+ function authoritySendPayload(timer: Timer, message: z.output<typeof messageSpecSchema>, run: number) {
560
+ const scheduler = { timerId: timer.id, correlationId: message.correlationId ?? `timer:${timer.id}`, run };
561
+ const idempotencyKey = relaySendKey(message, timer.id, run);
562
+ return {
563
+ idempotencyKey,
564
+ sendPayload: {
565
+ input: {
566
+ from: message.from,
567
+ to: message.to,
568
+ ...(message.kind ? { kind: message.kind } : {}),
569
+ ...(message.channel ? { channel: message.channel } : {}),
570
+ ...(message.subject ? { subject: message.subject } : {}),
571
+ body: message.body ?? "",
572
+ ...(message.claimable !== undefined ? { claimable: message.claimable } : {}),
573
+ payload: withScheduler(message.payload, scheduler),
574
+ meta: withScheduler(message.meta, scheduler),
575
+ idempotencyKey,
576
+ },
577
+ identity: { ...message.identity, deliveryFrom: message.from },
578
+ },
579
+ };
580
+ }
581
+
582
+ /** Build the fully-resolved outbox row for a COMMAND timer's completion send. The body defaults from
583
+ * the command outcome when the timer configured none; the `scheduler`/`commandResult` blocks carry the
584
+ * result so the message is observably a settled background command (parity with legacy
585
+ * `fireScheduledCommandWake`). */
586
+ function commandCompletionOutboxInput(
587
+ ctx: ModuleCtx,
588
+ timer: Timer,
589
+ message: z.output<typeof messageSpecSchema>,
590
+ run: number,
591
+ commandId: string | null,
592
+ result: CommandRunResult | undefined,
593
+ ): z.input<typeof relaySendSchema> {
594
+ const scheduler = { timerId: timer.id, correlationId: message.correlationId ?? `timer:${timer.id}`, run, ...(commandId ? { commandId } : {}) };
595
+ return {
596
+ id: ctx.rng.uuid(),
597
+ timerId: timer.id,
598
+ idempotencyKey: relaySendKey(message, timer.id, run),
599
+ status: "pending",
600
+ from: message.from,
601
+ to: message.to,
602
+ ...(message.kind ? { kind: message.kind } : {}),
603
+ ...(message.channel ? { channel: message.channel } : {}),
604
+ ...(message.subject ? { subject: message.subject } : {}),
605
+ body: message.body ?? commandCompletionBody(result),
606
+ ...(message.claimable !== undefined ? { claimable: message.claimable } : {}),
607
+ payload: withScheduler(message.payload, { ...scheduler, command: result ?? null }),
608
+ meta: withScheduler(message.meta, scheduler),
609
+ identity: message.identity,
610
+ createdAt: ctx.clock.now(),
611
+ };
612
+ }
613
+
614
+ /** The firing workflow state. `commandId` is null until a command timer's `fire` step has issued its
615
+ * P3 command; the `await` step reads it back to settle firing.
616
+ *
617
+ * `run` is the CRUX of P2-5's exactly-once (G3): the run number the CURRENT iteration fires under. It is
618
+ * carried in the workflow state — which is memoized in the durable journal and reconstructed by the
619
+ * fold — so a crash-recovery RE-DRIVE of a given run recomputes the SAME `run`, hence the SAME
620
+ * `base:run:N` outbox dedup key, hence NO double-send. It is NOT a live counter: the `fire` step reads
621
+ * `run` from folded state to stamp the send, and only the COMMITTED transition to the next `arm`
622
+ * advances it to `run+1` for the next iteration. A one-shot timer simply never advances past run 1. */
623
+ type FireState = {
624
+ id: string;
625
+ /** F is null for native/shadow workflows; authority generations carry exact F/G/R. */
626
+ fence: number | null;
627
+ generation: number;
628
+ fireAt: number;
629
+ commandId: string | null;
630
+ run: number;
631
+ };
632
+
633
+ /** The manifest handler receives the un-parameterized `ModuleCtx` (the manifest type is not yet
634
+ * available at its own declaration site), so a module narrows its own entities/config here. */
635
+ function timerStore(ctx: ModuleCtx): EntityStore<{ schema: typeof timerSchema }> {
636
+ return (ctx.entities as unknown as { readonly timer: EntityStore<{ schema: typeof timerSchema }> }).timer;
637
+ }
638
+
639
+ /** The relay-send outbox store (P2-3). Written by the firing steps in-tx; read/marked by the src drainer. */
640
+ function relaySendStore(ctx: ModuleCtx): EntityStore<{ schema: typeof relaySendSchema }> {
641
+ return (ctx.entities as unknown as { readonly relaySend: EntityStore<{ schema: typeof relaySendSchema }> }).relaySend;
642
+ }
643
+
644
+ /** The per-timer apply-fence store (T-0 hardening). Read-checked + upserted by `migrate`/`cancelMirror`. */
645
+ function applyFenceStore(ctx: ModuleCtx): EntityStore<{ schema: typeof applyFenceSchema }> {
646
+ return (ctx.entities as unknown as { readonly applyFence: EntityStore<{ schema: typeof applyFenceSchema }> }).applyFence;
647
+ }
648
+
649
+ /** Raise the durable fence to `fence` for `op` — a no-op at equality (same-intent re-drive). Runs in
650
+ * the op's atomic commit: a concurrent raced write aborts the WHOLE op via the flush CAS/PK conflict,
651
+ * so the fence can never regress and a stale write can never slip past a newer one. */
652
+ async function raiseApplyFence(
653
+ ctx: ModuleCtx,
654
+ gate: TimerApplyFence | undefined,
655
+ id: string,
656
+ fence: number,
657
+ op: "create" | "cancel",
658
+ ): Promise<void> {
659
+ const fences = applyFenceStore(ctx);
660
+ if (!gate) await fences.create({ id, fence, op, updatedAt: ctx.clock.now() });
661
+ else if (fence > gate.fence) await fences.update(id, { fence, op, updatedAt: ctx.clock.now() });
662
+ }
663
+
664
+ function timersConfig(ctx: ModuleCtx): TimersConfig {
665
+ return ctx.config as unknown as TimersConfig;
666
+ }
667
+
668
+ /**
669
+ * Handle a FAILED fire at the TIMER-RUN level (SCOPE 3) — distinct from the M3 per-step retry. Bumps
670
+ * `consecutiveFailures` on the entity (read fresh, so a re-drive after a rolled-back commit recomputes
671
+ * the SAME count), and either reschedules the SAME run at `now + retryMs` (looping back to `arm`) or
672
+ * disables the timer once `maxFailures` consecutive failures accumulate. The failure bookkeeping commits
673
+ * atomically with the step's journal memo. The run number is NOT advanced — a retry re-fires under the
674
+ * same `state.run`, so its eventual send keeps the same `base:run:N` key (parity with legacy, which
675
+ * leaves `run_count` untouched on `recordScheduledTimerFailure`).
676
+ */
677
+ async function applyFireFailure(
678
+ ctx: ModuleCtx,
679
+ timer: Timer,
680
+ state: FireState,
681
+ now: number,
682
+ error: unknown,
683
+ ): Promise<StepResult<FireState>> {
684
+ const cfg = timersConfig(ctx);
685
+ const outcome = failureBackoff({
686
+ now,
687
+ consecutiveFailures: timer.consecutiveFailures,
688
+ retryMs: cfg.retryMs,
689
+ maxFailures: cfg.maxFailures,
690
+ });
691
+ const store = timerStore(ctx);
692
+ if (outcome.kind === "disable") {
693
+ await store.update(state.id, { status: "disabled", consecutiveFailures: outcome.failures, lastError: errMessage(error) });
694
+ return { state, next: "done" };
695
+ }
696
+ await store.update(state.id, { consecutiveFailures: outcome.failures, lastError: errMessage(error) });
697
+ return { state: { ...state, fireAt: outcome.nextFireAt }, next: "arm" };
698
+ }
699
+
700
+ export const timers = defineModule({
701
+ id: "timers",
702
+ title: "Timers & Schedules",
703
+ description: "Kernel-served timers pilot: durable message + command firing on the K7 workflow runtime.",
704
+ config: {
705
+ schema: configSchema,
706
+ env: {
707
+ maxTimers: "TIMERS_MAX_TIMERS",
708
+ minRecurringIntervalMs: "TIMERS_MIN_RECURRING_INTERVAL_MS",
709
+ retryMs: "TIMERS_RETRY_MS",
710
+ maxFailures: "TIMERS_MAX_FAILURES",
711
+ },
712
+ overridableAt: {
713
+ maxTimers: ["host"],
714
+ minRecurringIntervalMs: ["host"],
715
+ retryMs: ["host"],
716
+ maxFailures: ["host"],
717
+ defaultLabel: ["instance", "host"],
718
+ },
719
+ },
720
+ entities: {
721
+ timer: {
722
+ schema: timerSchema,
723
+ // `createdBy` is indexed so the per-creator ownership filter (C2) on list/cancel/get is a keyed
724
+ // lookup, not a scan; `status` backs the active-quota count + status filter.
725
+ indexes: ["status", "createdBy"],
726
+ },
727
+ // The relay-dispatch transactional outbox (P2-3). A firing step writes one `pending` row IN its
728
+ // atomic step-commit (journal-atomic exactly-once on the send DECISION); the src drainer scans
729
+ // `pending` rows, calls `sendMessageService`, and flips them `sent`. `status` is indexed so the
730
+ // drainer's pending scan is a keyed lookup, not a table scan.
731
+ relaySend: {
732
+ schema: relaySendSchema,
733
+ indexes: ["status"],
734
+ },
735
+ // The per-timer durable last-applied-fence / tombstone record for the T-0 ingress apply seam
736
+ // (see `applyFenceSchema`). Point-read by id only — no secondary indexes.
737
+ applyFence: {
738
+ schema: applyFenceSchema,
739
+ },
740
+ },
741
+ events: {
742
+ "timers.created": z.object({ id: z.string(), label: z.string(), fireAt: z.number().int() }),
743
+ "timers.fired": z.object({ id: z.string(), firedAt: z.number().int(), run: z.number().int() }),
744
+ "timers.cancelled": z.object({ id: z.string() }),
745
+ },
746
+ commands: {
747
+ // The durable P3 shell command a command timer fires. The relay process NEVER execs — this
748
+ // dispatches onto the orchestrator command bus (src `dispatchCommand`), which the runner claims
749
+ // and runs as `bash -lc` at `cwd`, cwd-pinned + cgroup-reaped + timeout-bounded (the pre-existing
750
+ // legacy exec surface; the kernel neither moves nor widens it). `grant:"command:run-command"`
751
+ // maps src-side to — and never widens beyond — the legacy `command:write` + cwd-constrained authz
752
+ // (`dispatchCommand`'s #968 gate). `idempotencyKey` is the TIMER ID: a re-driven `fire` step
753
+ // dedupes onto the same command instead of double-dispatching (exactly-once boundary, #1408).
754
+ "run-command": {
755
+ input: z.object({
756
+ timerId: z.string().min(1),
757
+ command: z.string().min(1),
758
+ cwd: z.string().min(1),
759
+ env: z.record(z.string(), z.string()).optional(),
760
+ timeoutMs: z.number().int().positive(),
761
+ orchestratorId: z.string().min(1),
762
+ identity: frozenIdentitySchema,
763
+ }),
764
+ result: z.object({
765
+ exitCode: z.number().nullable(),
766
+ timedOut: z.boolean(),
767
+ stdoutTail: z.string(),
768
+ stderrTail: z.string(),
769
+ }),
770
+ target: "runner",
771
+ grant: "command:run-command",
772
+ idempotencyKey: (input) => input.timerId,
773
+ // Static declared ceiling (≤ 24h, matching the legacy COMMAND_MAX_MS). The ACTUAL per-run exec
774
+ // timeout rides in `input.timeoutMs`; this is the coarse manifest-level bound.
775
+ timeoutMs: 24 * 60 * 60 * 1000,
776
+ whenDegraded: "queue",
777
+ },
778
+ },
779
+ workflows: {
780
+ // Durable firing for a single timer — a LOOPING workflow (P2-5). `create` starts it with the timer
781
+ // id + fireAt + run 1.
782
+ // arm → parks the instance `sleeping` until the absolute `fireAt` (in state), never a setTimeout.
783
+ // fire → on the wakeup pass at/after fireAt, reads the timer and — only if still `scheduled`:
784
+ // • past its `expiresAt` → disables WITHOUT firing (legacy expiry-before-delivery).
785
+ // • a COMMAND timer issues its P3 `run-command` and parks `waiting` on it (→ `await`); a
786
+ // dispatch ERROR is a timer-run failure → backoff/disable (SCOPE 3). Command timers are
787
+ // NEVER recurring (legacy parity), so they always settle to `done` via `await`.
788
+ // • a MESSAGE/plain timer flips status + emits `timers.fired` (+ writes the P2-3 outbox
789
+ // row) in ONE atomic step commit, then — if it is a RECURRING interval still under
790
+ // `maxRuns`/`expiresAt` — loops back to `arm` with the NEXT deadline and run number `N+1`;
791
+ // otherwise it disables (terminal `fired`).
792
+ // Cancel-safe + idempotent by construction: the timer entity is the source of truth, so a timer
793
+ // cancelled (or already terminal) before a deadline simply no-ops when its firing workflow wakes.
794
+ //
795
+ // G3 (exactly-once): the run number `N` a fire dispatches under is `state.run` — carried in the
796
+ // DURABLE workflow state (memoized in the journal, reconstructed by the fold), NOT a live counter.
797
+ // A re-drive of run N recomputes the SAME N (its `arm` memo pins `state.run` before `fire` re-runs),
798
+ // so the `base:run:N` outbox dedup holds → no double-send. A fresh run only ever gets `N` from the
799
+ // PREVIOUS fire's COMMITTED transition to `run+1`, so distinct committed runs get distinct N.
800
+ fire: {
801
+ // `initialRun` (optional, default 1) is the run number the FIRST fire dispatches under. The
802
+ // create path never supplies it (→ run 1, unchanged behavior). The P2-6 migrate-at-cutover op
803
+ // seeds it to `legacyRunCount + 1` so a mid-stream recurring timer's kernel run numbering
804
+ // CONTINUES the legacy sequence instead of restarting at 1 — that alignment is what makes the
805
+ // §4.2 dual-read `base:run:N` dedup hold for a migrated recurring timer during the bake window.
806
+ input: z.object({
807
+ id: z.string(),
808
+ fireAt: z.number().int(),
809
+ initialRun: z.number().int().positive().optional(),
810
+ fence: z.number().int().nonnegative().nullable().optional(),
811
+ generation: z.number().int().nonnegative().optional(),
812
+ run: z.number().int().positive().optional(),
813
+ }),
814
+ state: z.object({
815
+ id: z.string(),
816
+ fence: z.number().int().nonnegative().nullable(),
817
+ generation: z.number().int().nonnegative(),
818
+ fireAt: z.number().int(),
819
+ commandId: z.string().nullable(),
820
+ run: z.number().int().positive(),
821
+ }),
822
+ init: (input) => ({
823
+ id: input.id,
824
+ fence: input.fence ?? null,
825
+ generation: input.generation ?? 0,
826
+ fireAt: input.fireAt,
827
+ commandId: null,
828
+ run: input.run ?? input.initialRun ?? 1,
829
+ }),
830
+ start: "arm",
831
+ steps: {
832
+ arm: {
833
+ run: async (_ctx, state: FireState): Promise<StepResult<FireState>> => {
834
+ // Deterministic: the deadline comes from state (the current run's fireAt), never the clock.
835
+ return { state, next: "fire", sleepUntil: state.fireAt };
836
+ },
837
+ },
838
+ fire: {
839
+ run: async (ctx, state: FireState): Promise<StepResult<FireState>> => {
840
+ const store = timerStore(ctx);
841
+ const timer = await store.get(state.id);
842
+ // Cancelled or already terminal before the deadline: no-op (cancel-safe firing).
843
+ if (!timer || timer.status !== "scheduled") return { state, next: "done" };
844
+ const now = ctx.clock.now();
845
+ // Expiry-before-delivery (legacy `fireClaimedTimer`): a timer past its expiry disables WITHOUT
846
+ // firing this run — no flip to `fired`, no event, no send.
847
+ if (timer.expiresAt !== undefined && timer.expiresAt <= now) {
848
+ await store.update(state.id, { status: "disabled", lastError: "timer expired before delivery" });
849
+ if (state.fence !== null) {
850
+ if (!timer.message) throw new TypeError("authority workflow requires a pure MESSAGE timer");
851
+ ctx.messageAuthority.decideFire({
852
+ timer: { timerId: timer.id, message: timer.message },
853
+ fence: state.fence,
854
+ generation: state.generation,
855
+ run: state.run,
856
+ engine: "kernel",
857
+ decision: "expired",
858
+ fireAt: state.fireAt,
859
+ lifecycle: "disabled",
860
+ nextRun: null,
861
+ nextRunAt: null,
862
+ decidedAt: now,
863
+ sendPayload: null,
864
+ idempotencyKey: null,
865
+ });
866
+ }
867
+ return { state, next: "done" };
868
+ }
869
+ if (timer.command) {
870
+ // Command timer: dispatch the authz-gated P3 command and park on its terminal status. The
871
+ // issue is idempotency-keyed on the timer id (see the decl), so a crash-and-re-drive of THIS
872
+ // step dedupes onto the same orchestrator command — never a second dispatch. A dispatch
873
+ // ERROR is a TIMER-RUN failure (distinct from M3 per-step retry): back off + disable after
874
+ // `maxFailures` (SCOPE 3), rather than terminating the whole firing workflow.
875
+ let run: HostCommandRun;
876
+ try {
877
+ run = await ctx.commands.issue(
878
+ "run-command",
879
+ {
880
+ timerId: timer.id,
881
+ command: timer.command.command,
882
+ cwd: timer.command.cwd,
883
+ ...(timer.command.env ? { env: timer.command.env } : {}),
884
+ timeoutMs: timer.command.timeoutMs,
885
+ orchestratorId: timer.command.orchestratorId,
886
+ identity: timer.command.identity,
887
+ },
888
+ { host: timer.command.orchestratorId },
889
+ );
890
+ } catch (error) {
891
+ return applyFireFailure(ctx, timer, state, now, error);
892
+ }
893
+ // A successful dispatch clears any prior failure streak (parity: success resets it).
894
+ if (timer.consecutiveFailures > 0) {
895
+ await store.update(state.id, { consecutiveFailures: 0, lastError: undefined });
896
+ }
897
+ return { state: { ...state, commandId: run.id }, next: "await", waitFor: { kind: "command", commandId: run.id } };
898
+ }
899
+ // Message/plain timer: decide the recurring continuation from DURABLE state (this run number
900
+ // = runs completed once it lands), then flip + emit AND — if it carries a resolved send —
901
+ // write the relay-dispatch outbox row (P2-3), all in ONE atomic step commit. The outbox
902
+ // `create` buffers into the same K4 session `commitStepAttempt` flushes with the journal memo,
903
+ // so the DECISION to send is journal-atomic exactly-once: a fault between the step effects and
904
+ // the commit rolls the whole tx back (no flip, no event, NO outbox row, NO run advance); a
905
+ // re-drive re-runs THIS run (same `state.run`) atomically. The src drainer performs the actual
906
+ // send, deduped effectively-once by `base:run:N`.
907
+ const cont = recurringContinuation({
908
+ everyMs: timer.everyMs,
909
+ now,
910
+ prevFireAt: state.fireAt,
911
+ runsCompleted: state.run,
912
+ maxRuns: timer.maxRuns,
913
+ expiresAt: timer.expiresAt,
914
+ });
915
+ await store.update(state.id, {
916
+ status: cont.kind === "terminal" ? "fired" : "scheduled",
917
+ ...(cont.kind === "continue" ? { fireAt: cont.nextFireAt } : {}),
918
+ runCount: state.run,
919
+ consecutiveFailures: 0,
920
+ lastError: undefined,
921
+ });
922
+ await ctx.events.emit("timers.fired", { id: state.id, firedAt: now, run: state.run });
923
+ if (timer.message) {
924
+ if (state.fence === null) {
925
+ await relaySendStore(ctx).create(messageOutboxInput(ctx, timer, timer.message, state.run));
926
+ } else {
927
+ const send = authoritySendPayload(timer, timer.message, state.run);
928
+ ctx.messageAuthority.decideFire({
929
+ timer: { timerId: timer.id, message: timer.message },
930
+ fence: state.fence,
931
+ generation: state.generation,
932
+ run: state.run,
933
+ engine: "kernel",
934
+ decision: "dispatch",
935
+ fireAt: state.fireAt,
936
+ lifecycle: cont.kind === "continue" ? "scheduled" : "fired",
937
+ nextRun: cont.kind === "continue" ? cont.nextRun : null,
938
+ nextRunAt: cont.kind === "continue" ? cont.nextFireAt : null,
939
+ decidedAt: now,
940
+ sendPayload: send.sendPayload,
941
+ idempotencyKey: send.idempotencyKey,
942
+ });
943
+ }
944
+ }
945
+ // Recurring: loop back to `arm` with the next deadline + the NEXT run number. The advance to
946
+ // `run+1` is only durable once THIS transition commits, so a re-drive of this run never sees it.
947
+ if (cont.kind === "continue") {
948
+ return { state: { ...state, fireAt: cont.nextFireAt, run: cont.nextRun }, next: "arm" };
949
+ }
950
+ return { state, next: "done" };
951
+ },
952
+ },
953
+ await: {
954
+ run: async (ctx, state: FireState): Promise<StepResult<FireState>> => {
955
+ // Reached only by a command timer (never recurring), once the wait evaluator reports terminal.
956
+ const store = timerStore(ctx);
957
+ const timer = await store.get(state.id);
958
+ // Still cancel-safe: a cancel between issue and settle → no fired flip, no event, no send.
959
+ if (timer && timer.status === "scheduled") {
960
+ await store.update(state.id, { status: "fired", runCount: state.run });
961
+ await ctx.events.emit("timers.fired", { id: state.id, firedAt: ctx.clock.now(), run: state.run });
962
+ // P2-3 (completion seam now CLOSED): if the command timer carries a completion send, write
963
+ // its outbox row IN this same atomic commit. The command result ({exitCode, timedOut,
964
+ // stdoutTail, stderrTail}) is durable and read back via `ctx.commands.status(commandId)`;
965
+ // the completion body/payload compose from it. Same journal-atomic exactly-once guarantee
966
+ // as the message path — the outbox row commits with the fired flip + event or not at all.
967
+ if (timer.message) {
968
+ const run = state.commandId ? await ctx.commands.status(state.commandId) : undefined;
969
+ const result = run?.result as CommandRunResult | undefined;
970
+ await relaySendStore(ctx).create(
971
+ commandCompletionOutboxInput(ctx, timer, timer.message, state.run, state.commandId, result),
972
+ );
973
+ }
974
+ }
975
+ return { state, next: "done", output: { id: state.id, commandId: state.commandId } };
976
+ },
977
+ },
978
+ },
979
+ },
980
+ },
981
+ ops: {
982
+ create: {
983
+ kind: "mutation",
984
+ idempotent: false,
985
+ grant: "timers:write",
986
+ summary: "Create a scheduled timer.",
987
+ emits: ["timers.created"],
988
+ http: { method: "POST", path: "/timers" },
989
+ // `command` (optional) makes this a COMMAND timer (see the module header + `run-command` decl).
990
+ // `message` (optional) makes firing dispatch a Relay message via the P2-3 outbox: on a plain
991
+ // timer it is the whole effect; on a command timer it is the completion send. Both freeze a
992
+ // server-resolved identity the drainer fires under.
993
+ // P2-4 (C2 residual #1): the create input carries NO client-owned frozen identity — the op
994
+ // SERVER-RESOLVES it from the authenticated principal (`ctx.principal`) + the token's real cwd
995
+ // constraint. A client cannot name/broaden its own authority; the fire-time reconstruction binds
996
+ // the command cwd to the creator's REAL constraint via `dispatchCommand`'s #968 gate (R1).
997
+ // `everyMs` (optional) makes this a RECURRING interval timer (P2-5): firing loops arm→fire→arm,
998
+ // rescheduling `fireAt` deterministically. `maxRuns`/`expiresAt` bound it. Command timers may NOT
999
+ // be recurring; a recurring timer needs a bound (`maxRuns`/`expiresAt`) or the persistent grant.
1000
+ input: z.object({
1001
+ label: z.string().min(1).optional(),
1002
+ fireAt: z.number().int(),
1003
+ everyMs: z.number().int().positive().optional(),
1004
+ maxRuns: z.number().int().positive().optional(),
1005
+ expiresAt: z.number().int().optional(),
1006
+ command: commandRequestSchema.optional(),
1007
+ message: messageRequestSchema.optional(),
1008
+ }),
1009
+ output: timerSchema,
1010
+ handler: async (ctx, input) => {
1011
+ const cfg = timersConfig(ctx);
1012
+ const now = ctx.clock.now();
1013
+ const createdBy = ctx.principal.actor;
1014
+
1015
+ // Quota / limit re-expression (C2 threat 3), so the kernel path can't be used to evade the
1016
+ // legacy scheduler's DoS ceilings:
1017
+ // • afterMs ≤ 24h → the timer may not be scheduled further than `maxFireAheadMs` ahead.
1018
+ if (input.fireAt > now + cfg.maxFireAheadMs) {
1019
+ throw new OpError("invalid_input", 400, `fireAt is more than ${cfg.maxFireAheadMs}ms ahead of now`);
1020
+ }
1021
+
1022
+ // SCOPE 4 — recurring/interval validation parity (legacy `scheduleTimer`):
1023
+ // • command timers may NOT be recurring;
1024
+ // • `everyMs >= minRecurringIntervalMs`;
1025
+ // • a recurring timer needs a bound (`maxRuns`/`expiresAt`) OR the persistent grant;
1026
+ // • `expiresAt` (any timer) must be after the first run.
1027
+ if (input.everyMs !== undefined) {
1028
+ if (input.command) {
1029
+ throw new OpError("invalid_input", 400, "everyMs is not supported with command timers");
1030
+ }
1031
+ if (input.everyMs < cfg.minRecurringIntervalMs) {
1032
+ throw new OpError("invalid_input", 400, `everyMs must be at least ${cfg.minRecurringIntervalMs}`);
1033
+ }
1034
+ if (input.maxRuns === undefined && input.expiresAt === undefined && !canCreatePersistentTimer(ctx)) {
1035
+ throw new OpError("unauthorized", 403, "recurring timers require maxRuns, expiresAt, or the schedule:persistent grant");
1036
+ }
1037
+ }
1038
+ if (input.expiresAt !== undefined && input.expiresAt <= input.fireAt) {
1039
+ throw new OpError("invalid_input", 400, "expiresAt must be after the first run");
1040
+ }
1041
+
1042
+ // • SCHEDULER_MAX_ACTIVE_TIMERS per creator → count this creator's active (scheduled) timers.
1043
+ // The entity page caps at 200; `min` keeps the count within it (the default quota is 100).
1044
+ const active = await timerStore(ctx).list({ where: { status: "scheduled", createdBy }, limit: Math.min(cfg.maxTimers, 200) });
1045
+ if (active.items.length >= cfg.maxTimers) {
1046
+ throw new OpError("quota_exceeded", 429, `active timer quota exceeded (${cfg.maxTimers})`);
1047
+ }
1048
+
1049
+ // SCOPE 1 — server-resolve + FREEZE the command-timer identity from the authenticated principal.
1050
+ // A command timer additionally requires the `command:write` grant AND a cwd-constrained creator
1051
+ // identity at create (mirroring legacy `normalizeScheduleCommand` + `assertScheduleCommandAuthorized`),
1052
+ // so an unconstrained / non-command-write caller cannot create a command timer AT ALL.
1053
+ const command = input.command ? freezeCommandTimer(ctx, input.command, createdBy, now) : undefined;
1054
+
1055
+ // The timer id is generated up-front so the frozen message can carry the `timer:<id>`
1056
+ // correlation id (D1) — byte-parity with legacy `insertScheduledTimer`, which derives the same.
1057
+ const id = ctx.rng.uuid();
1058
+
1059
+ // SCOPE 1 (P2-3) — server-resolve + FREEZE the relay-send spec. A pure message timer REQUIRES a
1060
+ // body; a command timer's completion body may be omitted (it defaults from the command outcome).
1061
+ const message = input.message
1062
+ ? freezeMessageTimer(ctx, input.message, createdBy, now, /*requireBody*/ !command, `timer:${id}`)
1063
+ : undefined;
1064
+
1065
+ const label = input.label ?? cfg.defaultLabel;
1066
+ const created = await timerStore(ctx).create({
1067
+ id,
1068
+ label,
1069
+ createdBy,
1070
+ fireAt: input.fireAt,
1071
+ ...(input.everyMs !== undefined ? { everyMs: input.everyMs } : {}),
1072
+ ...(input.maxRuns !== undefined ? { maxRuns: input.maxRuns } : {}),
1073
+ ...(input.expiresAt !== undefined ? { expiresAt: input.expiresAt } : {}),
1074
+ ...(command ? { command } : {}),
1075
+ ...(message ? { message } : {}),
1076
+ });
1077
+ await ctx.events.emit("timers.created", { id, label, fireAt: input.fireAt });
1078
+ // Enqueue durable firing, ENLISTED in this op's atomic commit (T-0 #1409 finding 1): the
1079
+ // instance seed executes INSIDE the same transaction as the entity + event flush, so the
1080
+ // timer and its firing workflow commit together or not at all — an op that rolls back
1081
+ // (validation failure, version conflict) leaves NO orphaned instance keyed to this id for
1082
+ // any later create/migrate of the same id to dedupe onto. The drive runs after the commit;
1083
+ // a crash before it leaves a durable `pending` instance the recovery pass converges.
1084
+ // Idempotency key = timer id, so a retried create dedupes onto the same instance.
1085
+ await ctx.workflows.start("fire", { id, fireAt: input.fireAt }, { idempotencyKey: id, enlist: "op-commit" });
1086
+ return created;
1087
+ },
1088
+ },
1089
+ get: {
1090
+ kind: "query",
1091
+ grant: "timers:read",
1092
+ summary: "Fetch a timer by id.",
1093
+ http: { method: "GET", path: "/timers/{id}" },
1094
+ input: z.object({ id: z.string() }),
1095
+ output: timerSchema,
1096
+ handler: async (ctx, input) => {
1097
+ const timer = await timerStore(ctx).get(input.id);
1098
+ // Per-creator ownership (C2): a non-admin principal cannot even OBSERVE another creator's timer.
1099
+ // Report the same 404 as a genuinely-missing id, so a non-owner cannot probe existence.
1100
+ const owner = creatorFilter(ctx);
1101
+ if (!timer || (owner && timer.createdBy !== owner.createdBy)) {
1102
+ throw new OpError("not_found", 404, `timer '${input.id}' was not found`);
1103
+ }
1104
+ return timer;
1105
+ },
1106
+ },
1107
+ list: {
1108
+ kind: "query",
1109
+ grant: "timers:read",
1110
+ summary: "List timers, optionally filtered by status.",
1111
+ http: { method: "GET", path: "/timers" },
1112
+ input: z.object({
1113
+ status: statusSchema.optional(),
1114
+ // Coerced: over HTTP this arrives as a query-string value; in-process callers may still
1115
+ // pass a number. `z.coerce.number` accepts both, so the transport stays type-agnostic.
1116
+ limit: z.coerce.number().int().min(1).max(200).optional(),
1117
+ cursor: z.string().optional(),
1118
+ }),
1119
+ output: z.object({ items: z.array(timerSchema), cursor: z.string().optional() }),
1120
+ handler: async (ctx, input) => {
1121
+ // Per-creator ownership (C2): a non-admin principal only ever sees its OWN timers — the op
1122
+ // applies a `where: {createdBy}` filter from `ctx.principal.actor`; an admin (system:admin)
1123
+ // crosses creators. Merged with the optional status filter.
1124
+ const where = { ...creatorFilter(ctx), ...(input.status ? { status: input.status } : {}) };
1125
+ const page = await timerStore(ctx).list({
1126
+ limit: input.limit,
1127
+ cursor: input.cursor,
1128
+ ...(Object.keys(where).length ? { where } : {}),
1129
+ });
1130
+ return { items: [...page.items], ...(page.cursor ? { cursor: page.cursor } : {}) };
1131
+ },
1132
+ },
1133
+ cancel: {
1134
+ kind: "mutation",
1135
+ idempotent: true,
1136
+ grant: "timers:write",
1137
+ summary: "Cancel a scheduled timer.",
1138
+ emits: ["timers.cancelled"],
1139
+ http: { method: "DELETE", path: "/timers/{id}" },
1140
+ input: z.object({ id: z.string() }),
1141
+ output: timerSchema,
1142
+ handler: async (ctx, input) => {
1143
+ const store = timerStore(ctx);
1144
+ const timer = await store.get(input.id);
1145
+ // Per-creator ownership (C2): a non-admin principal cannot cancel another creator's timer, and
1146
+ // gets the SAME 404 a missing id yields (no existence disclosure). Admin (system:admin) crosses.
1147
+ const owner = creatorFilter(ctx);
1148
+ if (!timer || (owner && timer.createdBy !== owner.createdBy)) {
1149
+ throw new OpError("not_found", 404, `timer '${input.id}' was not found`);
1150
+ }
1151
+ // Idempotent: a repeat cancel is a no-op that emits nothing and mutates nothing.
1152
+ if (timer.status === "cancelled") return timer;
1153
+ const cancelled = await store.update(input.id, { status: "cancelled" });
1154
+ await ctx.events.emit("timers.cancelled", { id: input.id });
1155
+ return cancelled;
1156
+ },
1157
+ },
1158
+ // ── P2-6 migrate-at-cutover surface (SYSTEM-only; the src migration script invokes this) ───────
1159
+ // The one-time forward migration (§4.2, RATIFIED disjoint-tables model) copies an ACTIVE legacy
1160
+ // `scheduled_timers` row into the kernel timer entity + enqueues its `fire` workflow. Like the drain
1161
+ // ops it is drainer-only (`timers:admin`) and never exposed over any transport, so it lands as a
1162
+ // prod no-op until the cutover script runs it. The src side (`kernel-timers-migrate.ts`) owns the
1163
+ // legacy→kernel field mapping; this op just faithfully UPSERTS the resolved entity.
1164
+ //
1165
+ // IDEMPOTENT (the crux, keyed on the LEGACY timer id): the kernel timer id IS the legacy id, so a
1166
+ // re-run finds the entity already present and does NOT create a duplicate. It ALWAYS (re-)starts the
1167
+ // fire workflow with `idempotencyKey = id`, which the runtime dedupes onto the existing instance —
1168
+ // so a crash BETWEEN the entity create and the workflow start converges on re-run (the entity is
1169
+ // there, the still-missing instance gets started). Safe to re-run / resume after a crash.
1170
+ //
1171
+ // FENCED (T-0 hardening, #1409): an optional `fence` (the caller's ingress seq) makes the write
1172
+ // refuse when stale — `fence <` the per-timer `applyFence` record (e.g. a cancel tombstone) returns
1173
+ // `{fenced: true}` with NO entity write, NO workflow start, NO event. Equal fence = same-intent
1174
+ // re-drive, proceeds idempotently. And when the staleness is only discovered AT FLUSH (both ops
1175
+ // read the old fence; the other committed first), the lost CAS aborts the WHOLE commit — including
1176
+ // the enlisted workflow seed — so the losing migrate leaves nothing at all behind (second-pass
1177
+ // hardening, T1175). See `applyFenceSchema` for the full contract.
1178
+ //
1179
+ // SECURITY (server-trusted snapshot — sidesteps G1's client-input concern): `command.identity` /
1180
+ // `message.identity` here are the LEGACY row's PERSISTED create-time identity (the server-resolved
1181
+ // snapshot `insertScheduledTimer` froze), carried verbatim — NOT client input at migrate time. So no
1182
+ // creator-facing re-validation (quota / persistent-grant / cwd-constraint) runs: those gated the
1183
+ // legacy row at ITS create, and this copies that already-trusted state. The fire-time #968 cwd gate
1184
+ // still binds a command's cwd to `command.identity` exactly as for a natively-created kernel timer.
1185
+ migrate: {
1186
+ kind: "mutation",
1187
+ idempotent: true,
1188
+ grant: TIMERS_DRAIN_GRANT,
1189
+ summary: "Forward-migrate one active legacy timer into the kernel entity + enqueue firing (P2-6; system-only).",
1190
+ emits: ["timers.created"],
1191
+ expose: { http: false, mcp: false, cli: false },
1192
+ input: z.object({
1193
+ id: z.string().min(1),
1194
+ label: z.string().min(1),
1195
+ createdBy: z.string().min(1),
1196
+ fireAt: z.number().int(),
1197
+ everyMs: z.number().int().positive().optional(),
1198
+ maxRuns: z.number().int().positive().optional(),
1199
+ expiresAt: z.number().int().optional(),
1200
+ // Runs the legacy timer already COMPLETED. The kernel entity carries it as its projection and
1201
+ // the fire workflow starts at `runCount + 1`, so the migrated timer's next run number CONTINUES
1202
+ // the legacy sequence (dual-read dedup parity for recurring timers).
1203
+ runCount: z.number().int().nonnegative().default(0),
1204
+ // Failure-backoff state must SURVIVE migration (#1409): a legacy timer mid-backoff (e.g. 2 of 3
1205
+ // consecutive failures) migrates with its streak intact, so the kernel keeps disabling it after
1206
+ // `maxFailures` rather than resetting to 0 and re-granting it a full retry budget.
1207
+ consecutiveFailures: z.number().int().nonnegative().default(0),
1208
+ lastError: z.string().optional(),
1209
+ command: commandSpecSchema.optional(),
1210
+ message: messageSpecSchema.optional(),
1211
+ // T-0 apply fence (#1409 hardening): the caller's ingress seq. When present, a stale write
1212
+ // (fence < the stored per-timer fence) is REFUSED before any effect — see `applyFenceSchema`.
1213
+ fence: z.number().int().positive().optional(),
1214
+ // Stage 5 authority snapshot. These are supplied together only when a real authority row
1215
+ // exists; shadow/fence-only ingress intentionally omits them and retains its old workflow.
1216
+ generation: z.number().int().nonnegative().optional(),
1217
+ run: z.number().int().positive().optional(),
1218
+ }),
1219
+ output: z.object({ timer: timerSchema.optional(), created: z.boolean(), fenced: z.boolean() }),
1220
+ handler: async (ctx, input) => {
1221
+ const authorityApply = input.generation !== undefined || input.run !== undefined;
1222
+ if (authorityApply && (input.fence === undefined || input.generation === undefined || input.run === undefined || !input.message || input.command)) {
1223
+ throw new OpError("invalid_input", 400, "authority migrate requires a pure MESSAGE timer with exact fence/generation/run");
1224
+ }
1225
+ // Fence check FIRST — before the entity write AND before the workflow start (which commits in
1226
+ // its own transaction): a stale fenced migrate must have NO effect at all. The read-check is
1227
+ // raced-safe because the fence upsert below flushes in this op's atomic commit (CAS-guarded);
1228
+ // a loser aborts wholesale and its retry re-reads the newer fence here.
1229
+ const gate = input.fence !== undefined ? await applyFenceStore(ctx).get(input.id) : undefined;
1230
+ if (input.fence !== undefined && gate !== undefined && input.fence < gate.fence) {
1231
+ return { created: false, fenced: true };
1232
+ }
1233
+ const store = timerStore(ctx);
1234
+ const existing = await store.get(input.id);
1235
+ let timer = existing;
1236
+ const created = existing === undefined;
1237
+ if (!existing) {
1238
+ timer = await store.create({
1239
+ id: input.id,
1240
+ label: input.label,
1241
+ createdBy: input.createdBy,
1242
+ fireAt: input.fireAt,
1243
+ runCount: input.runCount,
1244
+ consecutiveFailures: input.consecutiveFailures,
1245
+ ...(input.lastError !== undefined ? { lastError: input.lastError } : {}),
1246
+ ...(input.everyMs !== undefined ? { everyMs: input.everyMs } : {}),
1247
+ ...(input.maxRuns !== undefined ? { maxRuns: input.maxRuns } : {}),
1248
+ ...(input.expiresAt !== undefined ? { expiresAt: input.expiresAt } : {}),
1249
+ ...(input.command ? { command: input.command } : {}),
1250
+ ...(input.message ? { message: input.message } : {}),
1251
+ });
1252
+ await ctx.events.emit("timers.created", { id: input.id, label: input.label, fireAt: input.fireAt });
1253
+ } else if (input.fence !== undefined && (gate === undefined || input.fence > gate.fence)) {
1254
+ // Higher-F apply is convergence, not create-only mirroring. Write every timer field,
1255
+ // including explicit undefined values that clear fields removed by the new intent.
1256
+ timer = await store.update(input.id, {
1257
+ label: input.label,
1258
+ createdBy: input.createdBy,
1259
+ fireAt: input.fireAt,
1260
+ status: "scheduled",
1261
+ everyMs: input.everyMs,
1262
+ maxRuns: input.maxRuns,
1263
+ expiresAt: input.expiresAt,
1264
+ runCount: input.runCount,
1265
+ consecutiveFailures: input.consecutiveFailures,
1266
+ lastError: input.lastError,
1267
+ command: input.command,
1268
+ message: input.message,
1269
+ });
1270
+ }
1271
+ // ALWAYS (re-)enqueue firing, idempotently AND — the T-0 #1409 finding-1 crux — ENLISTED in
1272
+ // this op's atomic commit: the instance seed executes INSIDE the same transaction that
1273
+ // flushes the entity and the applyFence CAS below. A migrate that read a stale fence and
1274
+ // LOSES that CAS at flush (a concurrent newer cancel/create committed first) therefore
1275
+ // rolls back the workflow seed WITH the entity and the fence — a fence-losing migrate
1276
+ // commits NOTHING: no entity, no event, no fence write, no instance. That closes the
1277
+ // orphaned-workflow adoption hole: an instance keyed `idempotencyKey = id` can only exist
1278
+ // if the op that seeded it COMMITTED, i.e. its entity + fence exist at that fence — so a
1279
+ // later create can never dedupe onto a rolled-back migrate's workflow and fire at a stale
1280
+ // deadline. The drive runs post-commit; a crash before it leaves a durable `pending`
1281
+ // instance which the ingress re-drive (equal fence, idempotent) or `recover()` converges.
1282
+ // The first run number continues the legacy sequence (`runCount + 1`); the workflow input
1283
+ // is validated EAGERLY at this call (typed `invalid_input` on failure — finding 2), so a
1284
+ // deterministically-rejectable row aborts here before anything is buffered.
1285
+ await ctx.workflows.start(
1286
+ "fire",
1287
+ authorityApply
1288
+ ? { id: input.id, fence: input.fence!, generation: input.generation!, fireAt: input.fireAt, run: input.run! }
1289
+ : { id: input.id, fireAt: input.fireAt, initialRun: input.runCount + 1 },
1290
+ {
1291
+ idempotencyKey: authorityApply ? `${input.id}:generation:${input.generation}` : input.id,
1292
+ enlist: "op-commit",
1293
+ },
1294
+ );
1295
+ if (input.fence !== undefined) {
1296
+ await raiseApplyFence(ctx, gate, input.id, input.fence, "create");
1297
+ if (authorityApply) {
1298
+ ctx.messageAuthority.applyFence({
1299
+ timer: { timerId: input.id, message: input.message! },
1300
+ fence: input.fence,
1301
+ updatedAt: ctx.clock.now(),
1302
+ });
1303
+ }
1304
+ }
1305
+ return { timer: timer!, created, fenced: false };
1306
+ },
1307
+ },
1308
+ // ── P2-7 live CANCEL ingress (#1414; SYSTEM-only) — the `migrate` (create) counterpart ─────────
1309
+ // When a legacy timer is CANCELLED via the legacy path (`cancelTimer`), the src ingress mirrors that
1310
+ // cancel into the kernel so the kernel copy STOPS firing — otherwise the mirror stays `scheduled` and
1311
+ // keeps firing autonomously until it independently hits `maxRuns`/`expiresAt` (the #1414 phantom-fire).
1312
+ // Like `migrate`/the drain ops it is drainer-only (`timers:admin`) and never exposed over any transport
1313
+ // (`expose` all false): the ordinary creator-facing `cancel` op requires `timers:write` AND applies the
1314
+ // C2 per-creator filter, so it cannot serve a cross-creator SYSTEM ingress. This op crosses creators by
1315
+ // construction (system-trusted) — it is the src→kernel cancel seam, mirroring how `migrate` is the
1316
+ // create seam.
1317
+ //
1318
+ // Only an ARMED (`scheduled`) timer transitions to `cancelled` (flipping the fire step's cancel-safe
1319
+ // guard, which keys on `status === "scheduled"`). Idempotent + terminal-safe: an already-`cancelled`,
1320
+ // `fired`, or `disabled` timer is a no-op (never resurrects a terminal row). A not-yet-mirrored id (a
1321
+ // create-mirror miss, or a command timer the create-mirror deliberately skipped) never MANUFACTURES a
1322
+ // kernel TIMER row — but a FENCED cancel of an absent entity DOES durably record its fence as the
1323
+ // kernel TOMBSTONE (T-0 hardening), so a stale lower-fence create can never arm the timer afterwards.
1324
+ // An unfenced absent-entity cancel stays a pure best-effort no-op (pre-activation seams).
1325
+ cancelMirror: {
1326
+ kind: "mutation",
1327
+ idempotent: true,
1328
+ grant: TIMERS_DRAIN_GRANT,
1329
+ summary: "Cancel a migrated timer's kernel mirror when its legacy row is cancelled (P2-7; system-only).",
1330
+ emits: ["timers.cancelled"],
1331
+ expose: { http: false, mcp: false, cli: false },
1332
+ input: z.object({
1333
+ id: z.string().min(1),
1334
+ // T-0 apply fence (#1409 hardening): the caller's ingress seq — see `migrate` and `applyFenceSchema`.
1335
+ fence: z.number().int().positive().optional(),
1336
+ }),
1337
+ output: z.object({ cancelled: z.boolean(), fenced: z.boolean() }),
1338
+ handler: async (ctx, input) => {
1339
+ // Stale-fence refusal first (same contract as `migrate`): a cancel that lost to a NEWER applied
1340
+ // intent must not touch the entity nor regress the fence.
1341
+ const gate = input.fence !== undefined ? await applyFenceStore(ctx).get(input.id) : undefined;
1342
+ if (input.fence !== undefined && gate !== undefined && input.fence < gate.fence) {
1343
+ return { cancelled: false, fenced: true };
1344
+ }
1345
+ const store = timerStore(ctx);
1346
+ const timer = await store.get(input.id);
1347
+ if (!timer) {
1348
+ // ABSENT entity: the fenced cancel's fence row IS the durable kernel tombstone — the whole
1349
+ // point of the T-0 hardening (an absent-entity cancel must NOT be a silent no-op).
1350
+ if (input.fence !== undefined) await raiseApplyFence(ctx, gate, input.id, input.fence, "cancel");
1351
+ return { cancelled: false, fenced: false };
1352
+ }
1353
+ if (timer.status !== "scheduled") {
1354
+ if (input.fence !== undefined) await raiseApplyFence(ctx, gate, input.id, input.fence, "cancel");
1355
+ return { cancelled: false, fenced: false };
1356
+ }
1357
+ await store.update(input.id, { status: "cancelled" });
1358
+ await ctx.events.emit("timers.cancelled", { id: input.id });
1359
+ if (input.fence !== undefined) await raiseApplyFence(ctx, gate, input.id, input.fence, "cancel");
1360
+ return { cancelled: true, fenced: false };
1361
+ },
1362
+ },
1363
+ // ── P2-3 relay-outbox drain surface (SYSTEM-only; the src drainer invokes these) ───────────────
1364
+ // The kernel emits the send INTENT (the in-tx outbox row); the src side performs the EFFECT. These
1365
+ // two ops are the narrow, authz-gated seam it does that through — no `kernel/`→`src/` import, and no
1366
+ // ad-hoc entity-store leak. They require the drainer-only `timers:admin` grant and are never exposed
1367
+ // over any transport (`expose` all false), so an ordinary caller can neither read nor settle the
1368
+ // outbox. Marking a row sent is idempotent, which is exactly what makes the at-least-once drain safe
1369
+ // (a crash between `sendMessageService` returning and the mark landing re-drains + re-sends, deduped
1370
+ // by `base:run:N`; the second mark is a no-op).
1371
+ drainRelaySends: {
1372
+ kind: "query",
1373
+ grant: TIMERS_DRAIN_GRANT,
1374
+ summary: "List pending relay-send outbox rows (P2-3 drainer; system-only).",
1375
+ expose: { http: false, mcp: false, cli: false },
1376
+ input: z.object({
1377
+ limit: z.coerce.number().int().min(1).max(200).optional(),
1378
+ cursor: z.string().optional(),
1379
+ }),
1380
+ output: z.object({ items: z.array(relaySendSchema), cursor: z.string().optional() }),
1381
+ handler: async (ctx, input) => {
1382
+ const page = await relaySendStore(ctx).list({
1383
+ where: { status: "pending" },
1384
+ ...(input.limit !== undefined ? { limit: input.limit } : {}),
1385
+ ...(input.cursor !== undefined ? { cursor: input.cursor } : {}),
1386
+ });
1387
+ return { items: [...page.items], ...(page.cursor ? { cursor: page.cursor } : {}) };
1388
+ },
1389
+ },
1390
+ markRelaySendSent: {
1391
+ kind: "mutation",
1392
+ idempotent: true,
1393
+ grant: TIMERS_DRAIN_GRANT,
1394
+ summary: "Mark a relay-send outbox row sent (P2-3 drainer; system-only).",
1395
+ expose: { http: false, mcp: false, cli: false },
1396
+ input: z.object({ id: z.string(), messageId: z.number().int().optional() }),
1397
+ output: relaySendSchema,
1398
+ handler: async (ctx, input) => {
1399
+ const store = relaySendStore(ctx);
1400
+ const row = await store.get(input.id);
1401
+ if (!row) throw new OpError("not_found", 404, `relay send '${input.id}' was not found`);
1402
+ // Idempotent: a re-mark (a re-drained row already settled, or a duplicate drain) is a no-op.
1403
+ if (row.status === "sent") return row;
1404
+ return store.update(input.id, {
1405
+ status: "sent",
1406
+ ...(input.messageId !== undefined ? { sentMessageId: input.messageId } : {}),
1407
+ });
1408
+ },
1409
+ },
1410
+ },
1411
+ });