oh-my-super-agent 0.1.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 (461) hide show
  1. package/.agents/agents/advisor.md +15 -0
  2. package/.agents/agents/conductor.md +32 -0
  3. package/.agents/agents/dreamer.md +13 -0
  4. package/.agents/agents/executor.md +17 -0
  5. package/.agents/agents/grader.md +15 -0
  6. package/.agents/config/endurance-policy.json +8 -0
  7. package/.agents/config/oms-config.json +119 -0
  8. package/.agents/config/release-policy.json +12 -0
  9. package/.agents/config/secret-scan-policy.json +7 -0
  10. package/.agents/config/verification-plan.json +33 -0
  11. package/.agents/registry.json +11 -0
  12. package/.agents/rules/constitution.md +7 -0
  13. package/.agents/skills/conductor/SKILL.md +23 -0
  14. package/.agents/skills/dream/SKILL.md +14 -0
  15. package/.agents/skills/executor/SKILL.md +13 -0
  16. package/.agents/skills/oms/SKILL.md +52 -0
  17. package/.agents/skills/quota-aware/SKILL.md +12 -0
  18. package/.agents/skills/schedule/SKILL.md +13 -0
  19. package/.agents/skills/team-protocol/SKILL.md +20 -0
  20. package/LICENSE +21 -0
  21. package/README.md +146 -0
  22. package/dist/src/audit/run-ledger.d.ts +183 -0
  23. package/dist/src/audit/run-ledger.js +1655 -0
  24. package/dist/src/audit/run-ledger.js.map +1 -0
  25. package/dist/src/cli.d.ts +61 -0
  26. package/dist/src/cli.js +2096 -0
  27. package/dist/src/cli.js.map +1 -0
  28. package/dist/src/commands/github-queue-probe.d.ts +26 -0
  29. package/dist/src/commands/github-queue-probe.js +51 -0
  30. package/dist/src/commands/github-queue-probe.js.map +1 -0
  31. package/dist/src/commands/trace-fixture.d.ts +20 -0
  32. package/dist/src/commands/trace-fixture.js +72 -0
  33. package/dist/src/commands/trace-fixture.js.map +1 -0
  34. package/dist/src/conductor/activity.d.ts +46 -0
  35. package/dist/src/conductor/activity.js +224 -0
  36. package/dist/src/conductor/activity.js.map +1 -0
  37. package/dist/src/conductor/bridge.d.ts +53 -0
  38. package/dist/src/conductor/bridge.js +652 -0
  39. package/dist/src/conductor/bridge.js.map +1 -0
  40. package/dist/src/conductor/notifications.d.ts +59 -0
  41. package/dist/src/conductor/notifications.js +381 -0
  42. package/dist/src/conductor/notifications.js.map +1 -0
  43. package/dist/src/conductor/recovery.d.ts +29 -0
  44. package/dist/src/conductor/recovery.js +198 -0
  45. package/dist/src/conductor/recovery.js.map +1 -0
  46. package/dist/src/conductor/start.d.ts +73 -0
  47. package/dist/src/conductor/start.js +519 -0
  48. package/dist/src/conductor/start.js.map +1 -0
  49. package/dist/src/conductor/waiter.d.ts +88 -0
  50. package/dist/src/conductor/waiter.js +427 -0
  51. package/dist/src/conductor/waiter.js.map +1 -0
  52. package/dist/src/config.d.ts +9 -0
  53. package/dist/src/config.js +40 -0
  54. package/dist/src/config.js.map +1 -0
  55. package/dist/src/dispatch/advice-source.d.ts +61 -0
  56. package/dist/src/dispatch/advice-source.js +198 -0
  57. package/dist/src/dispatch/advice-source.js.map +1 -0
  58. package/dist/src/dispatch/advice-store.d.ts +41 -0
  59. package/dist/src/dispatch/advice-store.js +201 -0
  60. package/dist/src/dispatch/advice-store.js.map +1 -0
  61. package/dist/src/dispatch/advice.d.ts +34 -0
  62. package/dist/src/dispatch/advice.js +371 -0
  63. package/dist/src/dispatch/advice.js.map +1 -0
  64. package/dist/src/dispatch/authority.d.ts +124 -0
  65. package/dist/src/dispatch/authority.js +1202 -0
  66. package/dist/src/dispatch/authority.js.map +1 -0
  67. package/dist/src/dispatch/intent.d.ts +66 -0
  68. package/dist/src/dispatch/intent.js +71 -0
  69. package/dist/src/dispatch/intent.js.map +1 -0
  70. package/dist/src/dispatch/runtime-authority.d.ts +42 -0
  71. package/dist/src/dispatch/runtime-authority.js +52 -0
  72. package/dist/src/dispatch/runtime-authority.js.map +1 -0
  73. package/dist/src/doctor.d.ts +20 -0
  74. package/dist/src/doctor.js +85 -0
  75. package/dist/src/doctor.js.map +1 -0
  76. package/dist/src/domain/records.d.ts +44 -0
  77. package/dist/src/domain/records.js +138 -0
  78. package/dist/src/domain/records.js.map +1 -0
  79. package/dist/src/domain/role-policy.d.ts +67 -0
  80. package/dist/src/domain/role-policy.js +547 -0
  81. package/dist/src/domain/role-policy.js.map +1 -0
  82. package/dist/src/events/bus.d.ts +32 -0
  83. package/dist/src/events/bus.js +115 -0
  84. package/dist/src/events/bus.js.map +1 -0
  85. package/dist/src/events/kinds.d.ts +126 -0
  86. package/dist/src/events/kinds.js +14 -0
  87. package/dist/src/events/kinds.js.map +1 -0
  88. package/dist/src/evidence/immutable-file.d.ts +12 -0
  89. package/dist/src/evidence/immutable-file.js +141 -0
  90. package/dist/src/evidence/immutable-file.js.map +1 -0
  91. package/dist/src/evidence/store.d.ts +125 -0
  92. package/dist/src/evidence/store.js +1189 -0
  93. package/dist/src/evidence/store.js.map +1 -0
  94. package/dist/src/evidence/verdict.d.ts +17 -0
  95. package/dist/src/evidence/verdict.js +23 -0
  96. package/dist/src/evidence/verdict.js.map +1 -0
  97. package/dist/src/generation/agent.d.ts +5 -0
  98. package/dist/src/generation/agent.js +34 -0
  99. package/dist/src/generation/agent.js.map +1 -0
  100. package/dist/src/generation/frontmatter.d.ts +7 -0
  101. package/dist/src/generation/frontmatter.js +33 -0
  102. package/dist/src/generation/frontmatter.js.map +1 -0
  103. package/dist/src/github/adapter.d.ts +44 -0
  104. package/dist/src/github/adapter.js +592 -0
  105. package/dist/src/github/adapter.js.map +1 -0
  106. package/dist/src/github/dispatch-eligibility.d.ts +9 -0
  107. package/dist/src/github/dispatch-eligibility.js +94 -0
  108. package/dist/src/github/dispatch-eligibility.js.map +1 -0
  109. package/dist/src/github/projector.d.ts +23 -0
  110. package/dist/src/github/projector.js +181 -0
  111. package/dist/src/github/projector.js.map +1 -0
  112. package/dist/src/github/review.d.ts +39 -0
  113. package/dist/src/github/review.js +1450 -0
  114. package/dist/src/github/review.js.map +1 -0
  115. package/dist/src/github/sync.d.ts +21 -0
  116. package/dist/src/github/sync.js +518 -0
  117. package/dist/src/github/sync.js.map +1 -0
  118. package/dist/src/github/types.d.ts +134 -0
  119. package/dist/src/github/types.js +11 -0
  120. package/dist/src/github/types.js.map +1 -0
  121. package/dist/src/goals/artifact-store.d.ts +31 -0
  122. package/dist/src/goals/artifact-store.js +241 -0
  123. package/dist/src/goals/artifact-store.js.map +1 -0
  124. package/dist/src/goals/authority.d.ts +112 -0
  125. package/dist/src/goals/authority.js +621 -0
  126. package/dist/src/goals/authority.js.map +1 -0
  127. package/dist/src/goals/native-snapshot.d.ts +12 -0
  128. package/dist/src/goals/native-snapshot.js +53 -0
  129. package/dist/src/goals/native-snapshot.js.map +1 -0
  130. package/dist/src/goals/runtime-authority.d.ts +7 -0
  131. package/dist/src/goals/runtime-authority.js +20 -0
  132. package/dist/src/goals/runtime-authority.js.map +1 -0
  133. package/dist/src/health/release-assessment.d.ts +11 -0
  134. package/dist/src/health/release-assessment.js +83 -0
  135. package/dist/src/health/release-assessment.js.map +1 -0
  136. package/dist/src/health/release-policy.d.ts +16 -0
  137. package/dist/src/health/release-policy.js +40 -0
  138. package/dist/src/health/release-policy.js.map +1 -0
  139. package/dist/src/hooks/native.d.ts +30 -0
  140. package/dist/src/hooks/native.js +495 -0
  141. package/dist/src/hooks/native.js.map +1 -0
  142. package/dist/src/hooks/provider-runtime.d.ts +55 -0
  143. package/dist/src/hooks/provider-runtime.js +479 -0
  144. package/dist/src/hooks/provider-runtime.js.map +1 -0
  145. package/dist/src/hooks/provider.d.ts +102 -0
  146. package/dist/src/hooks/provider.js +358 -0
  147. package/dist/src/hooks/provider.js.map +1 -0
  148. package/dist/src/live/contact-journal.d.ts +73 -0
  149. package/dist/src/live/contact-journal.js +439 -0
  150. package/dist/src/live/contact-journal.js.map +1 -0
  151. package/dist/src/live-probes/gh-adapter.d.ts +28 -0
  152. package/dist/src/live-probes/gh-adapter.js +188 -0
  153. package/dist/src/live-probes/gh-adapter.js.map +1 -0
  154. package/dist/src/live-probes/github-queue.d.ts +1 -0
  155. package/dist/src/live-probes/github-queue.js +2 -0
  156. package/dist/src/live-probes/github-queue.js.map +1 -0
  157. package/dist/src/notifications/slack-request.d.ts +13 -0
  158. package/dist/src/notifications/slack-request.js +40 -0
  159. package/dist/src/notifications/slack-request.js.map +1 -0
  160. package/dist/src/outbox/processor.d.ts +27 -0
  161. package/dist/src/outbox/processor.js +63 -0
  162. package/dist/src/outbox/processor.js.map +1 -0
  163. package/dist/src/outbox/store.d.ts +158 -0
  164. package/dist/src/outbox/store.js +834 -0
  165. package/dist/src/outbox/store.js.map +1 -0
  166. package/dist/src/package-root.d.ts +1 -0
  167. package/dist/src/package-root.js +26 -0
  168. package/dist/src/package-root.js.map +1 -0
  169. package/dist/src/project.d.ts +12 -0
  170. package/dist/src/project.js +60 -0
  171. package/dist/src/project.js.map +1 -0
  172. package/dist/src/projection/generated-file.d.ts +15 -0
  173. package/dist/src/projection/generated-file.js +72 -0
  174. package/dist/src/projection/generated-file.js.map +1 -0
  175. package/dist/src/projection/project-workspace.d.ts +11 -0
  176. package/dist/src/projection/project-workspace.js +94 -0
  177. package/dist/src/projection/project-workspace.js.map +1 -0
  178. package/dist/src/projection/registry.d.ts +15 -0
  179. package/dist/src/projection/registry.js +59 -0
  180. package/dist/src/projection/registry.js.map +1 -0
  181. package/dist/src/projection/safe-path.d.ts +4 -0
  182. package/dist/src/projection/safe-path.js +106 -0
  183. package/dist/src/projection/safe-path.js.map +1 -0
  184. package/dist/src/providers/claude-interactive.d.ts +38 -0
  185. package/dist/src/providers/claude-interactive.js +287 -0
  186. package/dist/src/providers/claude-interactive.js.map +1 -0
  187. package/dist/src/providers/claude-structured-bridge.d.ts +32 -0
  188. package/dist/src/providers/claude-structured-bridge.js +215 -0
  189. package/dist/src/providers/claude-structured-bridge.js.map +1 -0
  190. package/dist/src/providers/claude-structured-completion.d.ts +23 -0
  191. package/dist/src/providers/claude-structured-completion.js +229 -0
  192. package/dist/src/providers/claude-structured-completion.js.map +1 -0
  193. package/dist/src/providers/claude-structured-pane.d.ts +23 -0
  194. package/dist/src/providers/claude-structured-pane.js +156 -0
  195. package/dist/src/providers/claude-structured-pane.js.map +1 -0
  196. package/dist/src/providers/claude-structured-store.d.ts +48 -0
  197. package/dist/src/providers/claude-structured-store.js +212 -0
  198. package/dist/src/providers/claude-structured-store.js.map +1 -0
  199. package/dist/src/providers/claude-structured.d.ts +56 -0
  200. package/dist/src/providers/claude-structured.js +250 -0
  201. package/dist/src/providers/claude-structured.js.map +1 -0
  202. package/dist/src/providers/codex-exec.d.ts +29 -0
  203. package/dist/src/providers/codex-exec.js +127 -0
  204. package/dist/src/providers/codex-exec.js.map +1 -0
  205. package/dist/src/providers/grading.d.ts +2 -0
  206. package/dist/src/providers/grading.js +20 -0
  207. package/dist/src/providers/grading.js.map +1 -0
  208. package/dist/src/providers/native-dispatch.d.ts +24 -0
  209. package/dist/src/providers/native-dispatch.js +34 -0
  210. package/dist/src/providers/native-dispatch.js.map +1 -0
  211. package/dist/src/providers/preflight.d.ts +65 -0
  212. package/dist/src/providers/preflight.js +256 -0
  213. package/dist/src/providers/preflight.js.map +1 -0
  214. package/dist/src/providers/process.d.ts +18 -0
  215. package/dist/src/providers/process.js +21 -0
  216. package/dist/src/providers/process.js.map +1 -0
  217. package/dist/src/queue/model.d.ts +37 -0
  218. package/dist/src/queue/model.js +51 -0
  219. package/dist/src/queue/model.js.map +1 -0
  220. package/dist/src/queue/service.d.ts +1 -0
  221. package/dist/src/queue/service.js +2 -0
  222. package/dist/src/queue/service.js.map +1 -0
  223. package/dist/src/reflections/store.d.ts +21 -0
  224. package/dist/src/reflections/store.js +60 -0
  225. package/dist/src/reflections/store.js.map +1 -0
  226. package/dist/src/reports/daily-trust.d.ts +11 -0
  227. package/dist/src/reports/daily-trust.js +98 -0
  228. package/dist/src/reports/daily-trust.js.map +1 -0
  229. package/dist/src/runs/controller.d.ts +187 -0
  230. package/dist/src/runs/controller.js +1182 -0
  231. package/dist/src/runs/controller.js.map +1 -0
  232. package/dist/src/runtime/composition.d.ts +9 -0
  233. package/dist/src/runtime/composition.js +35 -0
  234. package/dist/src/runtime/composition.js.map +1 -0
  235. package/dist/src/runtime/endurance-authorities.d.ts +44 -0
  236. package/dist/src/runtime/endurance-authorities.js +101 -0
  237. package/dist/src/runtime/endurance-authorities.js.map +1 -0
  238. package/dist/src/runtime/endurance-policy.d.ts +12 -0
  239. package/dist/src/runtime/endurance-policy.js +13 -0
  240. package/dist/src/runtime/endurance-policy.js.map +1 -0
  241. package/dist/src/runtime/lock.d.ts +63 -0
  242. package/dist/src/runtime/lock.js +577 -0
  243. package/dist/src/runtime/lock.js.map +1 -0
  244. package/dist/src/runtime/process-identity.d.ts +10 -0
  245. package/dist/src/runtime/process-identity.js +43 -0
  246. package/dist/src/runtime/process-identity.js.map +1 -0
  247. package/dist/src/runtime/quota.d.ts +130 -0
  248. package/dist/src/runtime/quota.js +590 -0
  249. package/dist/src/runtime/quota.js.map +1 -0
  250. package/dist/src/runtime/record-store.d.ts +45 -0
  251. package/dist/src/runtime/record-store.js +272 -0
  252. package/dist/src/runtime/record-store.js.map +1 -0
  253. package/dist/src/runtime/schema.d.ts +28 -0
  254. package/dist/src/runtime/schema.js +194 -0
  255. package/dist/src/runtime/schema.js.map +1 -0
  256. package/dist/src/runtime/stable-id.d.ts +3 -0
  257. package/dist/src/runtime/stable-id.js +27 -0
  258. package/dist/src/runtime/stable-id.js.map +1 -0
  259. package/dist/src/runtime/system-clock.d.ts +8 -0
  260. package/dist/src/runtime/system-clock.js +35 -0
  261. package/dist/src/runtime/system-clock.js.map +1 -0
  262. package/dist/src/schedule/service-plan.d.ts +58 -0
  263. package/dist/src/schedule/service-plan.js +327 -0
  264. package/dist/src/schedule/service-plan.js.map +1 -0
  265. package/dist/src/schedule/user-installation.d.ts +62 -0
  266. package/dist/src/schedule/user-installation.js +701 -0
  267. package/dist/src/schedule/user-installation.js.map +1 -0
  268. package/dist/src/schedule/user-plan.d.ts +47 -0
  269. package/dist/src/schedule/user-plan.js +286 -0
  270. package/dist/src/schedule/user-plan.js.map +1 -0
  271. package/dist/src/scheduler/minute.d.ts +31 -0
  272. package/dist/src/scheduler/minute.js +441 -0
  273. package/dist/src/scheduler/minute.js.map +1 -0
  274. package/dist/src/schemas/registry.d.ts +10 -0
  275. package/dist/src/schemas/registry.js +36 -0
  276. package/dist/src/schemas/registry.js.map +1 -0
  277. package/dist/src/security/secret-scan.d.ts +50 -0
  278. package/dist/src/security/secret-scan.js +384 -0
  279. package/dist/src/security/secret-scan.js.map +1 -0
  280. package/dist/src/sessions/registry.d.ts +89 -0
  281. package/dist/src/sessions/registry.js +443 -0
  282. package/dist/src/sessions/registry.js.map +1 -0
  283. package/dist/src/state.d.ts +27 -0
  284. package/dist/src/state.js +235 -0
  285. package/dist/src/state.js.map +1 -0
  286. package/dist/src/status/hud.d.ts +37 -0
  287. package/dist/src/status/hud.js +88 -0
  288. package/dist/src/status/hud.js.map +1 -0
  289. package/dist/src/team/plan.d.ts +31 -0
  290. package/dist/src/team/plan.js +184 -0
  291. package/dist/src/team/plan.js.map +1 -0
  292. package/dist/src/team/projection.d.ts +24 -0
  293. package/dist/src/team/projection.js +79 -0
  294. package/dist/src/team/projection.js.map +1 -0
  295. package/dist/src/tickets/admission.d.ts +34 -0
  296. package/dist/src/tickets/admission.js +169 -0
  297. package/dist/src/tickets/admission.js.map +1 -0
  298. package/dist/src/tickets/materializer.d.ts +1 -0
  299. package/dist/src/tickets/materializer.js +2 -0
  300. package/dist/src/tickets/materializer.js.map +1 -0
  301. package/dist/src/tickets/runtime-authority.d.ts +32 -0
  302. package/dist/src/tickets/runtime-authority.js +46 -0
  303. package/dist/src/tickets/runtime-authority.js.map +1 -0
  304. package/dist/src/tickets/store.d.ts +221 -0
  305. package/dist/src/tickets/store.js +2025 -0
  306. package/dist/src/tickets/store.js.map +1 -0
  307. package/dist/src/tracer/one-ticket.d.ts +58 -0
  308. package/dist/src/tracer/one-ticket.js +578 -0
  309. package/dist/src/tracer/one-ticket.js.map +1 -0
  310. package/dist/src/trust/assessment.d.ts +24 -0
  311. package/dist/src/trust/assessment.js +124 -0
  312. package/dist/src/trust/assessment.js.map +1 -0
  313. package/dist/src/trust/runs.d.ts +13 -0
  314. package/dist/src/trust/runs.js +46 -0
  315. package/dist/src/trust/runs.js.map +1 -0
  316. package/dist/src/types.d.ts +6 -0
  317. package/dist/src/types.js +2 -0
  318. package/dist/src/types.js.map +1 -0
  319. package/dist/src/utils/fs.d.ts +13 -0
  320. package/dist/src/utils/fs.js +188 -0
  321. package/dist/src/utils/fs.js.map +1 -0
  322. package/dist/src/verification/authority.d.ts +28 -0
  323. package/dist/src/verification/authority.js +153 -0
  324. package/dist/src/verification/authority.js.map +1 -0
  325. package/dist/src/verification/grade-source.d.ts +17 -0
  326. package/dist/src/verification/grade-source.js +30 -0
  327. package/dist/src/verification/grade-source.js.map +1 -0
  328. package/dist/src/verification/plan.d.ts +20 -0
  329. package/dist/src/verification/plan.js +128 -0
  330. package/dist/src/verification/plan.js.map +1 -0
  331. package/dist/src/verification/protected-runner.d.ts +50 -0
  332. package/dist/src/verification/protected-runner.js +171 -0
  333. package/dist/src/verification/protected-runner.js.map +1 -0
  334. package/dist/src/verification/result-gate-store.d.ts +72 -0
  335. package/dist/src/verification/result-gate-store.js +193 -0
  336. package/dist/src/verification/result-gate-store.js.map +1 -0
  337. package/dist/src/verification/result-gate.d.ts +41 -0
  338. package/dist/src/verification/result-gate.js +731 -0
  339. package/dist/src/verification/result-gate.js.map +1 -0
  340. package/dist/src/verification/runner.d.ts +38 -0
  341. package/dist/src/verification/runner.js +143 -0
  342. package/dist/src/verification/runner.js.map +1 -0
  343. package/dist/src/verification/sandbox.d.ts +16 -0
  344. package/dist/src/verification/sandbox.js +199 -0
  345. package/dist/src/verification/sandbox.js.map +1 -0
  346. package/dist/src/verify.d.ts +8 -0
  347. package/dist/src/verify.js +35 -0
  348. package/dist/src/verify.js.map +1 -0
  349. package/dist/src/watchdog/reconcile.d.ts +42 -0
  350. package/dist/src/watchdog/reconcile.js +440 -0
  351. package/dist/src/watchdog/reconcile.js.map +1 -0
  352. package/dist/src/workers/bridge.d.ts +35 -0
  353. package/dist/src/workers/bridge.js +426 -0
  354. package/dist/src/workers/bridge.js.map +1 -0
  355. package/dist/src/workers/delivery.d.ts +31 -0
  356. package/dist/src/workers/delivery.js +876 -0
  357. package/dist/src/workers/delivery.js.map +1 -0
  358. package/dist/src/workers/panes.d.ts +32 -0
  359. package/dist/src/workers/panes.js +212 -0
  360. package/dist/src/workers/panes.js.map +1 -0
  361. package/dist/src/workers/registry.d.ts +80 -0
  362. package/dist/src/workers/registry.js +351 -0
  363. package/dist/src/workers/registry.js.map +1 -0
  364. package/dist/src/workers/runtime.d.ts +44 -0
  365. package/dist/src/workers/runtime.js +21 -0
  366. package/dist/src/workers/runtime.js.map +1 -0
  367. package/dist/src/worktrees/manager.d.ts +35 -0
  368. package/dist/src/worktrees/manager.js +315 -0
  369. package/dist/src/worktrees/manager.js.map +1 -0
  370. package/docs/ARCHITECTURE.md +323 -0
  371. package/docs/PLAN.md +216 -0
  372. package/docs/REFERENCES.md +42 -0
  373. package/docs/ROADMAP.md +327 -0
  374. package/docs/SECURITY.md +242 -0
  375. package/docs/adr/0001-tracer-first-file-backed-certification.md +41 -0
  376. package/docs/adr/0002-conductor-first-typed-dispatch.md +102 -0
  377. package/docs/adr/0003-mandatory-pre-dispatch-advice.md +59 -0
  378. package/docs/compatibility/claude-code-2.1.207.md +25 -0
  379. package/loop/contract.md +102 -0
  380. package/package.json +54 -0
  381. package/schemas/advisor-evidence.schema.json +54 -0
  382. package/schemas/advisor-output.schema.json +31 -0
  383. package/schemas/conductor-activity-payload.schema.json +38 -0
  384. package/schemas/conductor-decision.schema.json +29 -0
  385. package/schemas/conductor-dispatch-intent.schema.json +71 -0
  386. package/schemas/conductor-dispatch-preparation.schema.json +46 -0
  387. package/schemas/conductor-dispatch-proposal.schema.json +82 -0
  388. package/schemas/conductor-goal-proposal.schema.json +30 -0
  389. package/schemas/conductor-manage-worker.schema.json +17 -0
  390. package/schemas/conductor-notification-payload.schema.json +39 -0
  391. package/schemas/conductor-process-result.schema.json +14 -0
  392. package/schemas/conductor-route.schema.json +51 -0
  393. package/schemas/conductor-start-team.schema.json +16 -0
  394. package/schemas/conductor-waiter-payload.schema.json +68 -0
  395. package/schemas/deterministic-check.schema.json +107 -0
  396. package/schemas/dispatch-acknowledgement.schema.json +15 -0
  397. package/schemas/dispatch-advice-payload.schema.json +64 -0
  398. package/schemas/dispatch-payload.schema.json +131 -0
  399. package/schemas/dispatch-result.schema.json +28 -0
  400. package/schemas/endurance-policy.schema.json +16 -0
  401. package/schemas/events/dispatch-delivery-requested.schema.json +17 -0
  402. package/schemas/events/github-observed.schema.json +28 -0
  403. package/schemas/events/native-hook-observed.schema.json +35 -0
  404. package/schemas/events/provider-observed.schema.json +64 -0
  405. package/schemas/events/run-heartbeat-due.schema.json +10 -0
  406. package/schemas/events/slack-notification-requested.schema.json +14 -0
  407. package/schemas/events/structured-role-completed.schema.json +54 -0
  408. package/schemas/events/ticket-resume-due.schema.json +28 -0
  409. package/schemas/events/watchdog-lease-expired.schema.json +14 -0
  410. package/schemas/events/watchdog-outbox-stalled.schema.json +12 -0
  411. package/schemas/events/watchdog-session-stalled.schema.json +11 -0
  412. package/schemas/evidence-record.schema.json +37 -0
  413. package/schemas/executor-result.schema.json +17 -0
  414. package/schemas/github-observation.schema.json +33 -0
  415. package/schemas/github-watermark.schema.json +66 -0
  416. package/schemas/goal-artifact.schema.json +19 -0
  417. package/schemas/goal-create-input.schema.json +14 -0
  418. package/schemas/goal-executor-result.schema.json +18 -0
  419. package/schemas/goal-payload.schema.json +95 -0
  420. package/schemas/grader-output.schema.json +33 -0
  421. package/schemas/lease-expiry.schema.json +19 -0
  422. package/schemas/live-disclosure.schema.json +16 -0
  423. package/schemas/live-outcome.schema.json +52 -0
  424. package/schemas/native-goal-snapshot.schema.json +27 -0
  425. package/schemas/provider-observed.schema.json +64 -0
  426. package/schemas/quota-observation.schema.json +72 -0
  427. package/schemas/reflection-evidence.schema.json +61 -0
  428. package/schemas/reflection.schema.json +13 -0
  429. package/schemas/regression-request.schema.json +54 -0
  430. package/schemas/release-assessment.schema.json +34 -0
  431. package/schemas/release-policy.schema.json +30 -0
  432. package/schemas/result-gate-payload.schema.json +244 -0
  433. package/schemas/review-delivery-payload.schema.json +42 -0
  434. package/schemas/role-policy.schema.json +111 -0
  435. package/schemas/run-abort-input.schema.json +11 -0
  436. package/schemas/run-completion-proof.schema.json +62 -0
  437. package/schemas/run-ledger-entry.schema.json +78 -0
  438. package/schemas/run-manifest.schema.json +74 -0
  439. package/schemas/run-start-intent.schema.json +74 -0
  440. package/schemas/runtime-record.schema.json +111 -0
  441. package/schemas/service-plan.schema.json +35 -0
  442. package/schemas/session-payload.schema.json +80 -0
  443. package/schemas/structured-role-read-request.schema.json +14 -0
  444. package/schemas/structured-role-request.schema.json +44 -0
  445. package/schemas/structured-role-result.schema.json +38 -0
  446. package/schemas/structured-role-submit-result.schema.json +15 -0
  447. package/schemas/team-checkpoint.schema.json +42 -0
  448. package/schemas/team-plan.schema.json +30 -0
  449. package/schemas/ticket-content.schema.json +38 -0
  450. package/schemas/ticket-queue-payload.schema.json +191 -0
  451. package/schemas/trust-report.schema.json +68 -0
  452. package/schemas/trust-run.schema.json +47 -0
  453. package/schemas/ultragoal-checkpoint.schema.json +49 -0
  454. package/schemas/user-schedule-installation-v1.schema.json +32 -0
  455. package/schemas/user-schedule-installation.schema.json +38 -0
  456. package/schemas/user-schedule-plan.schema.json +39 -0
  457. package/schemas/verification-plan-evidence.schema.json +37 -0
  458. package/schemas/worker-acknowledge-dispatch.schema.json +12 -0
  459. package/schemas/worker-payload.schema.json +47 -0
  460. package/schemas/worker-read-dispatch.schema.json +11 -0
  461. package/schemas/worker-record-dispatch-result.schema.json +14 -0
@@ -0,0 +1,45 @@
1
+ import { type RuntimeRecord, type TransitionOutcome } from "../domain/records.js";
2
+ import { type JsonSchemaNode } from "./schema.js";
3
+ export interface RecordStoreOptions {
4
+ recordsRoot: string;
5
+ locksRoot: string;
6
+ schema?: JsonSchemaNode;
7
+ createValidator?: (record: RuntimeRecord) => void;
8
+ recordValidator?: (record: RuntimeRecord) => void;
9
+ transitionValidator?: (current: RuntimeRecord, next: RuntimeRecord) => void;
10
+ }
11
+ export declare class RecordAlreadyExistsError extends Error {
12
+ readonly recordId: string;
13
+ constructor(recordId: string);
14
+ }
15
+ export interface TransitionOptions<State extends string, Payload extends Record<string, unknown>> {
16
+ recordId: string;
17
+ ownerId: string;
18
+ expectedVersion: number;
19
+ nonce: string;
20
+ expectedActor: string;
21
+ expectedAttempt: number;
22
+ expectedLeaseToken: string | null;
23
+ nextActor?: string;
24
+ nextAttempt?: number;
25
+ nextLeaseToken?: string | null;
26
+ fromStates: readonly State[];
27
+ toState: State;
28
+ updatePayload?: (current: Readonly<RuntimeRecord<State, Payload>>) => Payload;
29
+ }
30
+ export type TransitionResult<State extends string, Payload extends Record<string, unknown>> = {
31
+ status: "applied";
32
+ record: RuntimeRecord<State, Payload>;
33
+ outcome: TransitionOutcome<State>;
34
+ } | {
35
+ status: "replayed";
36
+ record: RuntimeRecord<State, Payload>;
37
+ outcome: TransitionOutcome<State>;
38
+ };
39
+ export declare function createRecordStore(options: RecordStoreOptions): {
40
+ create<State extends string, Payload extends Record<string, unknown>>(record: RuntimeRecord<State, Payload>): RuntimeRecord<State, Payload>;
41
+ read<State extends string, Payload extends Record<string, unknown>>(recordId: string): RuntimeRecord<State, Payload>;
42
+ readIfExists<State extends string, Payload extends Record<string, unknown>>(recordId: string): RuntimeRecord<State, Payload> | undefined;
43
+ list<State extends string, Payload extends Record<string, unknown>>(): readonly RuntimeRecord<State, Payload>[];
44
+ transition<State extends string, Payload extends Record<string, unknown>>(transition: TransitionOptions<State, Payload>): TransitionResult<State, Payload>;
45
+ };
@@ -0,0 +1,272 @@
1
+ import { lstatSync, readdirSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { MAX_TRANSITION_OUTCOMES, assertActorId, assertLeaseToken, assertRecordId, assertTransitionNonce, loadRuntimeRecordSchema, parseRuntimeRecord, recordFileName, recordLockId, } from "../domain/records.js";
4
+ import { lstatIfExists, readJsonFileNoFollow, validateExistingDirectory, writeJsonAtomic, writeJsonAtomicNoReplace, } from "../utils/fs.js";
5
+ import { acquireDirectoryLock } from "./lock.js";
6
+ import { assertSchema } from "./schema.js";
7
+ export class RecordAlreadyExistsError extends Error {
8
+ recordId;
9
+ constructor(recordId) {
10
+ super(`record already exists: ${recordId}`);
11
+ this.name = "RecordAlreadyExistsError";
12
+ this.recordId = recordId;
13
+ }
14
+ }
15
+ export function createRecordStore(options) {
16
+ const schema = frozenStructuredClone(options.schema ?? loadRuntimeRecordSchema());
17
+ const createValidator = options.createValidator;
18
+ const recordValidator = options.recordValidator;
19
+ const transitionValidator = options.transitionValidator;
20
+ const recordsRoot = validateExistingDirectory(options.recordsRoot, "records root");
21
+ const locksRoot = validateExistingDirectory(options.locksRoot, "locks root");
22
+ if (recordsRoot === locksRoot)
23
+ throw new Error("records root and locks root must be different directories");
24
+ const recordsRootIdentity = captureDirectoryIdentity(recordsRoot);
25
+ const locksRootIdentity = captureDirectoryIdentity(locksRoot);
26
+ function validateRoots() {
27
+ validateDirectoryIdentity(recordsRootIdentity, "records root");
28
+ validateDirectoryIdentity(locksRootIdentity, "locks root");
29
+ }
30
+ return {
31
+ create(record) {
32
+ validateRoots();
33
+ const detachedRecord = cloneJson(record, "runtime record create input");
34
+ const candidate = validateRecord(detachedRecord, schema, recordValidator, "runtime record");
35
+ const lock = acquireDirectoryLock({
36
+ locksRoot,
37
+ lockId: recordLockId(candidate.record_id),
38
+ ownerId: candidate.actor,
39
+ note: `create:${candidate.record_id}`,
40
+ });
41
+ try {
42
+ validateRoots();
43
+ const lockedCandidate = validateRecord(candidate, schema, recordValidator, "runtime record under create lock");
44
+ if (lockedCandidate.record_id !== candidate.record_id) {
45
+ throw new Error("runtime record id changed during create validation");
46
+ }
47
+ createValidator?.(frozenStructuredClone(lockedCandidate));
48
+ const path = recordPath(recordsRoot, lockedCandidate.record_id);
49
+ const entry = lstatIfExists(path);
50
+ if (entry) {
51
+ if (entry.isSymbolicLink() || !entry.isFile())
52
+ throw new Error(`unsafe existing record path: ${lockedCandidate.record_id}`);
53
+ throw new RecordAlreadyExistsError(lockedCandidate.record_id);
54
+ }
55
+ try {
56
+ writeJsonAtomicNoReplace(path, lockedCandidate);
57
+ }
58
+ catch (error) {
59
+ if (isErrorCode(error, "EEXIST"))
60
+ throw new RecordAlreadyExistsError(lockedCandidate.record_id);
61
+ throw error;
62
+ }
63
+ const stored = loadRecord(path, schema, recordValidator);
64
+ validateRoots();
65
+ return stored;
66
+ }
67
+ finally {
68
+ lock.release();
69
+ }
70
+ },
71
+ read(recordId) {
72
+ validateRoots();
73
+ const path = recordPath(recordsRoot, assertRecordId(recordId));
74
+ const record = loadRecord(path, schema, recordValidator);
75
+ validateRoots();
76
+ return record;
77
+ },
78
+ readIfExists(recordId) {
79
+ validateRoots();
80
+ const path = recordPath(recordsRoot, assertRecordId(recordId));
81
+ const entry = lstatIfExists(path);
82
+ if (!entry) {
83
+ validateRoots();
84
+ return undefined;
85
+ }
86
+ if (entry.isSymbolicLink() || !entry.isFile())
87
+ throw new Error(`unsafe existing record path: ${recordId}`);
88
+ const record = loadRecord(path, schema, recordValidator);
89
+ validateRoots();
90
+ return record;
91
+ },
92
+ list() {
93
+ validateRoots();
94
+ const entries = readdirSync(recordsRoot, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));
95
+ validateRoots();
96
+ const records = [];
97
+ for (const entry of entries) {
98
+ if (!entry.name.endsWith(".json"))
99
+ continue;
100
+ if (!entry.isFile())
101
+ throw new Error(`unsafe record directory entry: ${entry.name}`);
102
+ const recordId = assertRecordId(entry.name.slice(0, -".json".length));
103
+ if (recordFileName(recordId) !== entry.name)
104
+ throw new Error(`invalid record filename: ${entry.name}`);
105
+ validateRoots();
106
+ records.push(loadRecord(join(recordsRoot, entry.name), schema, recordValidator));
107
+ validateRoots();
108
+ }
109
+ validateRoots();
110
+ return Object.freeze(records);
111
+ },
112
+ transition(transition) {
113
+ validateRoots();
114
+ const recordId = assertRecordId(transition.recordId);
115
+ const nonce = assertTransitionNonce(transition.nonce);
116
+ const lock = acquireDirectoryLock({
117
+ locksRoot,
118
+ lockId: recordLockId(recordId),
119
+ ownerId: transition.ownerId,
120
+ note: `transition:${recordId}`,
121
+ });
122
+ try {
123
+ validateRoots();
124
+ const path = recordPath(recordsRoot, recordId);
125
+ const current = loadRecord(path, schema, recordValidator);
126
+ validateRoots();
127
+ const replayed = current.transition_outcomes.find((outcome) => outcome.nonce === nonce);
128
+ if (replayed)
129
+ return Object.freeze({ status: "replayed", record: current, outcome: replayed });
130
+ const normalized = validateTransition(current, transition, nonce);
131
+ const next = buildNextRecord(current, transition, normalized);
132
+ transitionValidator?.(frozenStructuredClone(current), frozenStructuredClone(next));
133
+ const candidate = validateRecord(next, schema, recordValidator, "next runtime record");
134
+ writeJsonAtomic(path, candidate);
135
+ const stored = loadRecord(path, schema, recordValidator);
136
+ validateRoots();
137
+ const outcome = stored.transition_outcomes.at(-1);
138
+ if (!outcome)
139
+ throw new Error("stored runtime record is missing its transition outcome");
140
+ return Object.freeze({ status: "applied", record: stored, outcome });
141
+ }
142
+ finally {
143
+ lock.release();
144
+ }
145
+ },
146
+ };
147
+ }
148
+ function recordPath(recordsRoot, recordId) {
149
+ return join(recordsRoot, recordFileName(recordId));
150
+ }
151
+ function loadRecord(path, schema, recordValidator) {
152
+ const raw = readJsonFileNoFollow(path);
153
+ return validateRecord(raw, schema, recordValidator, "stored runtime record");
154
+ }
155
+ function validateRecord(value, schema, recordValidator, label) {
156
+ assertSchema(value, schema, label);
157
+ const record = parseRuntimeRecord(value);
158
+ const snapshot = frozenStructuredClone(record);
159
+ recordValidator?.(snapshot);
160
+ return snapshot;
161
+ }
162
+ function validateTransition(current, transition, nonce) {
163
+ assertNonNegativeInteger(transition.expectedVersion, "expected version");
164
+ assertPositiveInteger(transition.expectedAttempt, "expected attempt");
165
+ const expectedActor = assertActorId(transition.expectedActor, "expected actor");
166
+ const expectedLeaseToken = transition.expectedLeaseToken === null
167
+ ? null
168
+ : assertLeaseToken(transition.expectedLeaseToken, "expected lease token");
169
+ const nextActor = transition.nextActor === undefined
170
+ ? current.actor
171
+ : assertActorId(transition.nextActor, "next actor");
172
+ const nextAttempt = transition.nextAttempt ?? current.attempt;
173
+ const nextLeaseToken = transition.nextLeaseToken === undefined
174
+ ? current.lease_token
175
+ : transition.nextLeaseToken === null
176
+ ? null
177
+ : assertLeaseToken(transition.nextLeaseToken, "next lease token");
178
+ assertPositiveInteger(nextAttempt, "next attempt");
179
+ if (current.version !== transition.expectedVersion)
180
+ throw new Error("stale version");
181
+ if (current.actor !== expectedActor)
182
+ throw new Error("actor mismatch");
183
+ if (current.attempt !== transition.expectedAttempt)
184
+ throw new Error("attempt mismatch");
185
+ if (current.lease_token !== expectedLeaseToken)
186
+ throw new Error("lease token mismatch");
187
+ if (!transition.fromStates.includes(current.state))
188
+ throw new Error("illegal transition");
189
+ if (nextAttempt < current.attempt)
190
+ throw new Error("attempt cannot move backwards");
191
+ if (nextAttempt > current.attempt + 1)
192
+ throw new Error("attempt must advance by exactly one");
193
+ if (nextAttempt > current.max_attempts)
194
+ throw new Error("attempt budget exhausted");
195
+ if (current.transition_outcomes.length >= MAX_TRANSITION_OUTCOMES) {
196
+ throw new Error("transition outcome history is full");
197
+ }
198
+ return { nonce, nextActor, nextAttempt, nextLeaseToken };
199
+ }
200
+ function buildNextRecord(current, transition, normalized) {
201
+ const callbackCurrent = recursivelyFreeze(cloneJson(current, "runtime record snapshot"));
202
+ const proposedPayload = transition.updatePayload
203
+ ? transition.updatePayload(callbackCurrent)
204
+ : callbackCurrent.payload;
205
+ if (!proposedPayload || typeof proposedPayload !== "object" || Array.isArray(proposedPayload)) {
206
+ throw new Error("payload update must return an object");
207
+ }
208
+ const nextPayload = cloneJson(proposedPayload, "payload update");
209
+ const outcome = {
210
+ nonce: normalized.nonce,
211
+ version: current.version + 1,
212
+ state: transition.toState,
213
+ attempt: normalized.nextAttempt,
214
+ actor: normalized.nextActor,
215
+ lease_token: normalized.nextLeaseToken,
216
+ };
217
+ return {
218
+ ...current,
219
+ version: outcome.version,
220
+ state: outcome.state,
221
+ attempt: outcome.attempt,
222
+ actor: outcome.actor,
223
+ lease_token: outcome.lease_token,
224
+ transition_nonce: outcome.nonce,
225
+ payload: nextPayload,
226
+ transition_outcomes: [...current.transition_outcomes, outcome],
227
+ };
228
+ }
229
+ function cloneJson(value, label) {
230
+ try {
231
+ const serialized = JSON.stringify(value);
232
+ if (serialized === undefined)
233
+ throw new Error("value is not JSON serializable");
234
+ return JSON.parse(serialized);
235
+ }
236
+ catch (error) {
237
+ throw new Error(`${label} must be JSON serializable`, { cause: error });
238
+ }
239
+ }
240
+ function recursivelyFreeze(value) {
241
+ if (typeof value !== "object" || value === null || Object.isFrozen(value))
242
+ return value;
243
+ for (const nested of Object.values(value))
244
+ recursivelyFreeze(nested);
245
+ return Object.freeze(value);
246
+ }
247
+ function frozenStructuredClone(value) {
248
+ return recursivelyFreeze(structuredClone(value));
249
+ }
250
+ function assertNonNegativeInteger(value, label) {
251
+ if (!Number.isSafeInteger(value) || value < 0)
252
+ throw new Error(`${label} must be a non-negative integer`);
253
+ }
254
+ function assertPositiveInteger(value, label) {
255
+ if (!Number.isSafeInteger(value) || value < 1)
256
+ throw new Error(`${label} must be a positive integer`);
257
+ }
258
+ function captureDirectoryIdentity(path) {
259
+ const entry = lstatSync(path);
260
+ return { path, device: entry.dev, inode: entry.ino };
261
+ }
262
+ function validateDirectoryIdentity(expected, label) {
263
+ const path = validateExistingDirectory(expected.path, label);
264
+ const entry = lstatSync(path);
265
+ if (path !== expected.path || entry.dev !== expected.device || entry.ino !== expected.inode) {
266
+ throw new Error(`${label} changed after store creation`);
267
+ }
268
+ }
269
+ function isErrorCode(error, code) {
270
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
271
+ }
272
+ //# sourceMappingURL=record-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-store.js","sourceRoot":"","sources":["../../../src/runtime/record-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,YAAY,GAGb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,yBAAyB,EACzB,eAAe,EACf,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,YAAY,EAAuB,MAAM,aAAa,CAAC;AAWhE,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxC,QAAQ,CAAS;IAE1B,YAAY,QAAgB;QAC1B,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAsBD,MAAM,UAAU,iBAAiB,CAAC,OAA2B;IAC3D,MAAM,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,MAAM,IAAI,uBAAuB,EAAE,CAAC,CAAC;IAClF,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAChD,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAChD,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IACxD,MAAM,WAAW,GAAG,yBAAyB,CAAC,OAAO,CAAC,WAAW,EAAE,cAAc,CA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AACvD,CAAC;AAED,SAAS,yBAAyB,CAAC,QAA2B,EAAE,KAAa;IAC3E,MAAM,IAAI,GAAG,yBAAyB,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC5F,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,+BAA+B,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,IAAY;IAC/C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC/F,CAAC"}
@@ -0,0 +1,28 @@
1
+ export interface JsonSchemaNode {
2
+ type?: string | readonly string[];
3
+ properties?: Record<string, JsonSchemaNode>;
4
+ required?: readonly string[];
5
+ additionalProperties?: boolean;
6
+ const?: unknown;
7
+ enum?: readonly unknown[];
8
+ minimum?: number;
9
+ maximum?: number;
10
+ minLength?: number;
11
+ maxLength?: number;
12
+ minItems?: number;
13
+ maxItems?: number;
14
+ pattern?: string;
15
+ items?: JsonSchemaNode;
16
+ }
17
+ export interface SchemaValidationIssue {
18
+ path: string;
19
+ message: string;
20
+ }
21
+ export declare class SchemaValidationError extends Error {
22
+ readonly issues: readonly SchemaValidationIssue[];
23
+ constructor(message: string, issues: readonly SchemaValidationIssue[]);
24
+ }
25
+ export declare function loadJsonSchema(path: string): JsonSchemaNode;
26
+ export declare function parseJsonSchema(value: unknown, label?: string): JsonSchemaNode;
27
+ export declare function assertSchema(value: unknown, schema: JsonSchemaNode, label: string): void;
28
+ export declare function validateWithSchema(value: unknown, schema: JsonSchemaNode, path?: string): SchemaValidationIssue[];
@@ -0,0 +1,194 @@
1
+ import { isRecord, readJsonFile } from "../utils/fs.js";
2
+ const SUPPORTED_SCHEMA_KEYS = new Set([
3
+ "$schema",
4
+ "$id",
5
+ "title",
6
+ "description",
7
+ "default",
8
+ "type",
9
+ "properties",
10
+ "required",
11
+ "additionalProperties",
12
+ "const",
13
+ "enum",
14
+ "minimum",
15
+ "maximum",
16
+ "minLength",
17
+ "maxLength",
18
+ "minItems",
19
+ "maxItems",
20
+ "pattern",
21
+ "items",
22
+ ]);
23
+ export class SchemaValidationError extends Error {
24
+ issues;
25
+ constructor(message, issues) {
26
+ super(message);
27
+ this.name = "SchemaValidationError";
28
+ this.issues = issues;
29
+ }
30
+ }
31
+ export function loadJsonSchema(path) {
32
+ return parseJsonSchema(readJsonFile(path), path);
33
+ }
34
+ export function parseJsonSchema(value, label = "schema") {
35
+ const issues = validateSchemaShape(value, "$");
36
+ if (issues.length > 0) {
37
+ const first = issues[0];
38
+ throw new SchemaValidationError(`invalid schema: ${label}: ${first?.path ?? "$"} ${first?.message ?? "validation failed"}`, issues);
39
+ }
40
+ return value;
41
+ }
42
+ export function assertSchema(value, schema, label) {
43
+ const issues = validateWithSchema(value, schema, "$");
44
+ if (issues.length > 0)
45
+ throw new SchemaValidationError(`${label} failed schema validation`, issues);
46
+ }
47
+ export function validateWithSchema(value, schema, path = "$") {
48
+ const issues = [];
49
+ if (schema.const !== undefined && !Object.is(value, schema.const)) {
50
+ issues.push({ path, message: `expected constant ${JSON.stringify(schema.const)}` });
51
+ return issues;
52
+ }
53
+ if (schema.enum && !schema.enum.some((candidate) => Object.is(candidate, value))) {
54
+ issues.push({ path, message: `expected one of ${schema.enum.map((item) => JSON.stringify(item)).join(", ")}` });
55
+ return issues;
56
+ }
57
+ if (schema.type && !matchesAllowedType(value, schema.type)) {
58
+ issues.push({ path, message: `expected ${describeAllowedTypes(schema.type)}` });
59
+ return issues;
60
+ }
61
+ if (schema.pattern && typeof value === "string" && !new RegExp(schema.pattern, "u").test(value)) {
62
+ issues.push({ path, message: `expected string matching ${schema.pattern}` });
63
+ }
64
+ if (schema.minimum !== undefined && typeof value === "number" && value < schema.minimum) {
65
+ issues.push({ path, message: `expected number >= ${schema.minimum}` });
66
+ }
67
+ if (schema.maximum !== undefined && typeof value === "number" && value > schema.maximum) {
68
+ issues.push({ path, message: `expected number <= ${schema.maximum}` });
69
+ }
70
+ if (schema.minLength !== undefined && typeof value === "string" && value.length < schema.minLength) {
71
+ issues.push({ path, message: `expected at least ${schema.minLength} characters` });
72
+ }
73
+ if (schema.maxLength !== undefined && typeof value === "string" && value.length > schema.maxLength) {
74
+ issues.push({ path, message: `expected at most ${schema.maxLength} characters` });
75
+ }
76
+ if (schema.minItems !== undefined && Array.isArray(value) && value.length < schema.minItems) {
77
+ issues.push({ path, message: `expected at least ${schema.minItems} items` });
78
+ }
79
+ if (schema.maxItems !== undefined && Array.isArray(value) && value.length > schema.maxItems) {
80
+ issues.push({ path, message: `expected at most ${schema.maxItems} items` });
81
+ }
82
+ if (issues.length > 0)
83
+ return issues;
84
+ if (isRecord(value)) {
85
+ const required = new Set(schema.required ?? []);
86
+ for (const property of required) {
87
+ if (!Object.hasOwn(value, property))
88
+ issues.push({ path: `${path}.${property}`, message: "missing required property" });
89
+ }
90
+ const properties = schema.properties ?? {};
91
+ for (const [property, childSchema] of Object.entries(properties)) {
92
+ if (Object.hasOwn(value, property))
93
+ issues.push(...validateWithSchema(value[property], childSchema, `${path}.${property}`));
94
+ }
95
+ if (schema.additionalProperties === false) {
96
+ for (const property of Object.keys(value)) {
97
+ if (!Object.hasOwn(properties, property)) {
98
+ issues.push({ path: `${path}.${property}`, message: "unexpected property" });
99
+ }
100
+ }
101
+ }
102
+ }
103
+ if (Array.isArray(value) && schema.items) {
104
+ for (let index = 0; index < value.length; index += 1) {
105
+ issues.push(...validateWithSchema(value[index], schema.items, `${path}[${index}]`));
106
+ }
107
+ }
108
+ return issues;
109
+ }
110
+ function validateSchemaShape(value, path) {
111
+ if (!isRecord(value))
112
+ return [{ path, message: "schema node must be an object" }];
113
+ const issues = [];
114
+ for (const keyword of Object.keys(value)) {
115
+ if (!SUPPORTED_SCHEMA_KEYS.has(keyword))
116
+ issues.push({ path: `${path}.${keyword}`, message: "unsupported schema keyword" });
117
+ }
118
+ if ("type" in value && !isTypeKeyword(value.type)) {
119
+ issues.push({ path: `${path}.type`, message: "type must be a string or string array" });
120
+ }
121
+ if ("properties" in value) {
122
+ if (!isRecord(value.properties)) {
123
+ issues.push({ path: `${path}.properties`, message: "properties must be an object" });
124
+ }
125
+ else {
126
+ for (const [property, child] of Object.entries(value.properties)) {
127
+ issues.push(...validateSchemaShape(child, `${path}.properties.${property}`));
128
+ }
129
+ }
130
+ }
131
+ if ("required" in value && (!Array.isArray(value.required) || value.required.some((entry) => typeof entry !== "string"))) {
132
+ issues.push({ path: `${path}.required`, message: "required must be a string array" });
133
+ }
134
+ if ("additionalProperties" in value && typeof value.additionalProperties !== "boolean") {
135
+ issues.push({ path: `${path}.additionalProperties`, message: "additionalProperties must be boolean" });
136
+ }
137
+ if ("minimum" in value && typeof value.minimum !== "number") {
138
+ issues.push({ path: `${path}.minimum`, message: "minimum must be a number" });
139
+ }
140
+ if ("maximum" in value && typeof value.maximum !== "number") {
141
+ issues.push({ path: `${path}.maximum`, message: "maximum must be a number" });
142
+ }
143
+ if ("minLength" in value && (typeof value.minLength !== "number" || !Number.isSafeInteger(value.minLength) || value.minLength < 0)) {
144
+ issues.push({ path: `${path}.minLength`, message: "minLength must be a non-negative integer" });
145
+ }
146
+ if ("maxLength" in value && (typeof value.maxLength !== "number" || !Number.isSafeInteger(value.maxLength) || value.maxLength < 0)) {
147
+ issues.push({ path: `${path}.maxLength`, message: "maxLength must be a non-negative integer" });
148
+ }
149
+ if ("minItems" in value && (typeof value.minItems !== "number" || !Number.isSafeInteger(value.minItems) || value.minItems < 0)) {
150
+ issues.push({ path: `${path}.minItems`, message: "minItems must be a non-negative integer" });
151
+ }
152
+ if ("maxItems" in value && (typeof value.maxItems !== "number" || !Number.isSafeInteger(value.maxItems) || value.maxItems < 0)) {
153
+ issues.push({ path: `${path}.maxItems`, message: "maxItems must be a non-negative integer" });
154
+ }
155
+ if ("pattern" in value && typeof value.pattern !== "string") {
156
+ issues.push({ path: `${path}.pattern`, message: "pattern must be a string" });
157
+ }
158
+ if ("items" in value)
159
+ issues.push(...validateSchemaShape(value.items, `${path}.items`));
160
+ return issues;
161
+ }
162
+ function isTypeKeyword(value) {
163
+ return typeof value === "string" || (Array.isArray(value) && value.every((entry) => typeof entry === "string"));
164
+ }
165
+ function matchesAllowedType(value, allowed) {
166
+ const types = Array.isArray(allowed) ? allowed : [allowed];
167
+ return types.some((type) => matchesType(value, type));
168
+ }
169
+ function matchesType(value, type) {
170
+ switch (type) {
171
+ case "object":
172
+ return isRecord(value);
173
+ case "string":
174
+ return typeof value === "string";
175
+ case "integer":
176
+ return typeof value === "number" && Number.isSafeInteger(value);
177
+ case "number":
178
+ return typeof value === "number" && Number.isFinite(value);
179
+ case "boolean":
180
+ return typeof value === "boolean";
181
+ case "array":
182
+ return Array.isArray(value);
183
+ case "null":
184
+ return value === null;
185
+ default:
186
+ return false;
187
+ }
188
+ }
189
+ function describeAllowedTypes(allowed) {
190
+ if (typeof allowed === "string")
191
+ return allowed;
192
+ return Array.from(allowed).join(" or ");
193
+ }
194
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/runtime/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAmBxD,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,SAAS;IACT,KAAK;IACL,OAAO;IACP,aAAa;IACb,SAAS;IACT,MAAM;IACN,YAAY;IACZ,UAAU;IACV,sBAAsB;IACtB,OAAO;IACP,MAAM;IACN,SAAS;IAC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,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,IAAY;IAC/C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;QACzB,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;QACnC,KAAK,SAAS;YACZ,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAClE,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC7D,KAAK,SAAS;YACZ,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;QACpC,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,KAAK,MAAM;YACT,OAAO,KAAK,KAAK,IAAI,CAAC;QACxB;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAmC;IAC/D,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type OpaqueId, type TransitionNonce } from "../domain/records.js";
2
+ export declare function createStableId(prefix: string, ...parts: readonly string[]): OpaqueId;
3
+ export declare function createTransitionNonce(action: string, recordId: string, operationId: string): TransitionNonce;
@@ -0,0 +1,27 @@
1
+ import { createHash } from "node:crypto";
2
+ import { assertOpaqueId, assertTransitionNonce } from "../domain/records.js";
3
+ const DIGEST_LENGTH = 48;
4
+ const MAX_PREFIX_LENGTH = 14;
5
+ export function createStableId(prefix, ...parts) {
6
+ const normalizedPrefix = assertOpaqueId(prefix, "stable id prefix");
7
+ if (normalizedPrefix.length > MAX_PREFIX_LENGTH) {
8
+ throw new Error(`stable id prefix exceeds ${MAX_PREFIX_LENGTH} characters`);
9
+ }
10
+ if (parts.length === 0)
11
+ throw new Error("stable id requires at least one identity part");
12
+ const hash = createHash("sha256");
13
+ hash.update(`${normalizedPrefix.length}:${normalizedPrefix}`);
14
+ for (const part of parts) {
15
+ if (typeof part !== "string")
16
+ throw new Error("stable id parts must be strings");
17
+ hash.update(`\0${Buffer.byteLength(part, "utf8")}:`);
18
+ hash.update(part, "utf8");
19
+ }
20
+ return assertOpaqueId(`${normalizedPrefix}-${hash.digest("hex").slice(0, DIGEST_LENGTH)}`, "stable id");
21
+ }
22
+ export function createTransitionNonce(action, recordId, operationId) {
23
+ const normalizedAction = assertOpaqueId(action, "transition action");
24
+ const normalizedOperation = assertOpaqueId(operationId, "operation id");
25
+ return assertTransitionNonce(createStableId("nonce", normalizedAction, recordId, normalizedOperation));
26
+ }
27
+ //# sourceMappingURL=stable-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stable-id.js","sourceRoot":"","sources":["../../../src/runtime/stable-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAuC,MAAM,sBAAsB,CAAC;AAElH,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,GAAG,KAAwB;IACxE,MAAM,gBAAgB,GAAG,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;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SystemClockSample {
3
+ readonly wallTime: string;
4
+ readonly monotonicNs: bigint;
5
+ readonly bootId: OpaqueId;
6
+ }
7
+ export declare function systemClockSample(): SystemClockSample;
8
+ export declare function systemBootId(): OpaqueId;