@agentic-sdlc-kit/contracts 0.0.0-stage → 0.8.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 (495) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/dist/agent/capability.d.ts +9 -0
  4. package/dist/agent/capability.d.ts.map +1 -0
  5. package/dist/agent/capability.js +31 -0
  6. package/dist/agent/capability.js.map +1 -0
  7. package/dist/agent/errors.d.ts +30 -0
  8. package/dist/agent/errors.d.ts.map +1 -0
  9. package/dist/agent/errors.js +62 -0
  10. package/dist/agent/errors.js.map +1 -0
  11. package/dist/agent/events.d.ts +222 -0
  12. package/dist/agent/events.d.ts.map +1 -0
  13. package/dist/agent/events.js +92 -0
  14. package/dist/agent/events.js.map +1 -0
  15. package/dist/agent/execution.d.ts +553 -0
  16. package/dist/agent/execution.d.ts.map +1 -0
  17. package/dist/agent/execution.js +229 -0
  18. package/dist/agent/execution.js.map +1 -0
  19. package/dist/agent/index.d.ts +8 -0
  20. package/dist/agent/index.d.ts.map +1 -0
  21. package/dist/agent/index.js +19 -0
  22. package/dist/agent/index.js.map +1 -0
  23. package/dist/agent/policy.d.ts +135 -0
  24. package/dist/agent/policy.d.ts.map +1 -0
  25. package/dist/agent/policy.js +78 -0
  26. package/dist/agent/policy.js.map +1 -0
  27. package/dist/agent/provider.d.ts +82 -0
  28. package/dist/agent/provider.d.ts.map +1 -0
  29. package/dist/agent/provider.js +33 -0
  30. package/dist/agent/provider.js.map +1 -0
  31. package/dist/agent/session.d.ts +17 -0
  32. package/dist/agent/session.d.ts.map +1 -0
  33. package/dist/agent/session.js +23 -0
  34. package/dist/agent/session.js.map +1 -0
  35. package/dist/application/application-context.d.ts +512 -0
  36. package/dist/application/application-context.d.ts.map +1 -0
  37. package/dist/application/application-context.js +42 -0
  38. package/dist/application/application-context.js.map +1 -0
  39. package/dist/application/application-persistence.d.ts +846 -0
  40. package/dist/application/application-persistence.d.ts.map +1 -0
  41. package/dist/application/application-persistence.js +37 -0
  42. package/dist/application/application-persistence.js.map +1 -0
  43. package/dist/application/application-state.d.ts +89 -0
  44. package/dist/application/application-state.d.ts.map +1 -0
  45. package/dist/application/application-state.js +66 -0
  46. package/dist/application/application-state.js.map +1 -0
  47. package/dist/application/application-transitions.d.ts +23 -0
  48. package/dist/application/application-transitions.d.ts.map +1 -0
  49. package/dist/application/application-transitions.js +60 -0
  50. package/dist/application/application-transitions.js.map +1 -0
  51. package/dist/application/index.d.ts +5 -0
  52. package/dist/application/index.d.ts.map +1 -0
  53. package/dist/application/index.js +6 -0
  54. package/dist/application/index.js.map +1 -0
  55. package/dist/architecture/api-contract.d.ts +259 -0
  56. package/dist/architecture/api-contract.d.ts.map +1 -0
  57. package/dist/architecture/api-contract.js +43 -0
  58. package/dist/architecture/api-contract.js.map +1 -0
  59. package/dist/architecture/architecture-approval.d.ts +40 -0
  60. package/dist/architecture/architecture-approval.d.ts.map +1 -0
  61. package/dist/architecture/architecture-approval.js +24 -0
  62. package/dist/architecture/architecture-approval.js.map +1 -0
  63. package/dist/architecture/architecture-options.d.ts +103 -0
  64. package/dist/architecture/architecture-options.d.ts.map +1 -0
  65. package/dist/architecture/architecture-options.js +35 -0
  66. package/dist/architecture/architecture-options.js.map +1 -0
  67. package/dist/architecture/component-map.d.ts +76 -0
  68. package/dist/architecture/component-map.d.ts.map +1 -0
  69. package/dist/architecture/component-map.js +28 -0
  70. package/dist/architecture/component-map.js.map +1 -0
  71. package/dist/architecture/data-model.d.ts +252 -0
  72. package/dist/architecture/data-model.d.ts.map +1 -0
  73. package/dist/architecture/data-model.js +53 -0
  74. package/dist/architecture/data-model.js.map +1 -0
  75. package/dist/architecture/index.d.ts +8 -0
  76. package/dist/architecture/index.d.ts.map +1 -0
  77. package/dist/architecture/index.js +9 -0
  78. package/dist/architecture/index.js.map +1 -0
  79. package/dist/architecture/operational-design.d.ts +134 -0
  80. package/dist/architecture/operational-design.d.ts.map +1 -0
  81. package/dist/architecture/operational-design.js +46 -0
  82. package/dist/architecture/operational-design.js.map +1 -0
  83. package/dist/architecture/security-design.d.ts +107 -0
  84. package/dist/architecture/security-design.d.ts.map +1 -0
  85. package/dist/architecture/security-design.js +40 -0
  86. package/dist/architecture/security-design.js.map +1 -0
  87. package/dist/common/errors.d.ts +40 -0
  88. package/dist/common/errors.d.ts.map +1 -0
  89. package/dist/common/errors.js +45 -0
  90. package/dist/common/errors.js.map +1 -0
  91. package/dist/common/identifier.d.ts +12 -0
  92. package/dist/common/identifier.d.ts.map +1 -0
  93. package/dist/common/identifier.js +21 -0
  94. package/dist/common/identifier.js.map +1 -0
  95. package/dist/common/index.d.ts +4 -0
  96. package/dist/common/index.d.ts.map +1 -0
  97. package/dist/common/index.js +5 -0
  98. package/dist/common/index.js.map +1 -0
  99. package/dist/common/result.d.ts +28 -0
  100. package/dist/common/result.d.ts.map +1 -0
  101. package/dist/common/result.js +33 -0
  102. package/dist/common/result.js.map +1 -0
  103. package/dist/evaluation/benchmark.d.ts +88 -0
  104. package/dist/evaluation/benchmark.d.ts.map +1 -0
  105. package/dist/evaluation/benchmark.js +34 -0
  106. package/dist/evaluation/benchmark.js.map +1 -0
  107. package/dist/evaluation/index.d.ts +3 -0
  108. package/dist/evaluation/index.d.ts.map +1 -0
  109. package/dist/evaluation/index.js +4 -0
  110. package/dist/evaluation/index.js.map +1 -0
  111. package/dist/evaluation/metrics.d.ts +164 -0
  112. package/dist/evaluation/metrics.d.ts.map +1 -0
  113. package/dist/evaluation/metrics.js +64 -0
  114. package/dist/evaluation/metrics.js.map +1 -0
  115. package/dist/evolution/experiment.d.ts +85 -0
  116. package/dist/evolution/experiment.d.ts.map +1 -0
  117. package/dist/evolution/experiment.js +52 -0
  118. package/dist/evolution/experiment.js.map +1 -0
  119. package/dist/evolution/improvement-hypothesis.d.ts +98 -0
  120. package/dist/evolution/improvement-hypothesis.d.ts.map +1 -0
  121. package/dist/evolution/improvement-hypothesis.js +59 -0
  122. package/dist/evolution/improvement-hypothesis.js.map +1 -0
  123. package/dist/evolution/index.d.ts +3 -0
  124. package/dist/evolution/index.d.ts.map +1 -0
  125. package/dist/evolution/index.js +4 -0
  126. package/dist/evolution/index.js.map +1 -0
  127. package/dist/index.d.ts +24 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +43 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/installer/index.d.ts +4 -0
  132. package/dist/installer/index.d.ts.map +1 -0
  133. package/dist/installer/index.js +5 -0
  134. package/dist/installer/index.js.map +1 -0
  135. package/dist/installer/install-plan.d.ts +168 -0
  136. package/dist/installer/install-plan.d.ts.map +1 -0
  137. package/dist/installer/install-plan.js +40 -0
  138. package/dist/installer/install-plan.js.map +1 -0
  139. package/dist/installer/ownership-manifest.d.ts +78 -0
  140. package/dist/installer/ownership-manifest.d.ts.map +1 -0
  141. package/dist/installer/ownership-manifest.js +30 -0
  142. package/dist/installer/ownership-manifest.js.map +1 -0
  143. package/dist/installer/package-manifest.d.ts +55 -0
  144. package/dist/installer/package-manifest.d.ts.map +1 -0
  145. package/dist/installer/package-manifest.js +46 -0
  146. package/dist/installer/package-manifest.js.map +1 -0
  147. package/dist/learning/engineering-lesson.d.ts +84 -0
  148. package/dist/learning/engineering-lesson.d.ts.map +1 -0
  149. package/dist/learning/engineering-lesson.js +47 -0
  150. package/dist/learning/engineering-lesson.js.map +1 -0
  151. package/dist/learning/engineering-memory.d.ts +66 -0
  152. package/dist/learning/engineering-memory.d.ts.map +1 -0
  153. package/dist/learning/engineering-memory.js +44 -0
  154. package/dist/learning/engineering-memory.js.map +1 -0
  155. package/dist/learning/experience-episode.d.ts +176 -0
  156. package/dist/learning/experience-episode.d.ts.map +1 -0
  157. package/dist/learning/experience-episode.js +68 -0
  158. package/dist/learning/experience-episode.js.map +1 -0
  159. package/dist/learning/experience.d.ts +68 -0
  160. package/dist/learning/experience.d.ts.map +1 -0
  161. package/dist/learning/experience.js +22 -0
  162. package/dist/learning/experience.js.map +1 -0
  163. package/dist/learning/hypothesis.d.ts +57 -0
  164. package/dist/learning/hypothesis.d.ts.map +1 -0
  165. package/dist/learning/hypothesis.js +27 -0
  166. package/dist/learning/hypothesis.js.map +1 -0
  167. package/dist/learning/index.d.ts +8 -0
  168. package/dist/learning/index.d.ts.map +1 -0
  169. package/dist/learning/index.js +9 -0
  170. package/dist/learning/index.js.map +1 -0
  171. package/dist/learning/memory.d.ts +42 -0
  172. package/dist/learning/memory.d.ts.map +1 -0
  173. package/dist/learning/memory.js +20 -0
  174. package/dist/learning/memory.js.map +1 -0
  175. package/dist/learning/promotion.d.ts +31 -0
  176. package/dist/learning/promotion.d.ts.map +1 -0
  177. package/dist/learning/promotion.js +16 -0
  178. package/dist/learning/promotion.js.map +1 -0
  179. package/dist/maintenance/bug-fix-workflow.d.ts +57 -0
  180. package/dist/maintenance/bug-fix-workflow.d.ts.map +1 -0
  181. package/dist/maintenance/bug-fix-workflow.js +100 -0
  182. package/dist/maintenance/bug-fix-workflow.js.map +1 -0
  183. package/dist/maintenance/bug-report.d.ts +62 -0
  184. package/dist/maintenance/bug-report.d.ts.map +1 -0
  185. package/dist/maintenance/bug-report.js +49 -0
  186. package/dist/maintenance/bug-report.js.map +1 -0
  187. package/dist/maintenance/index.d.ts +6 -0
  188. package/dist/maintenance/index.d.ts.map +1 -0
  189. package/dist/maintenance/index.js +7 -0
  190. package/dist/maintenance/index.js.map +1 -0
  191. package/dist/maintenance/performance-baseline.d.ts +80 -0
  192. package/dist/maintenance/performance-baseline.d.ts.map +1 -0
  193. package/dist/maintenance/performance-baseline.js +32 -0
  194. package/dist/maintenance/performance-baseline.js.map +1 -0
  195. package/dist/maintenance/refactor-contract.d.ts +158 -0
  196. package/dist/maintenance/refactor-contract.d.ts.map +1 -0
  197. package/dist/maintenance/refactor-contract.js +65 -0
  198. package/dist/maintenance/refactor-contract.js.map +1 -0
  199. package/dist/maintenance/refactor-workflow.d.ts +79 -0
  200. package/dist/maintenance/refactor-workflow.d.ts.map +1 -0
  201. package/dist/maintenance/refactor-workflow.js +100 -0
  202. package/dist/maintenance/refactor-workflow.js.map +1 -0
  203. package/dist/observer/event-schema.d.ts +49 -0
  204. package/dist/observer/event-schema.d.ts.map +1 -0
  205. package/dist/observer/event-schema.js +48 -0
  206. package/dist/observer/event-schema.js.map +1 -0
  207. package/dist/observer/index.d.ts +5 -0
  208. package/dist/observer/index.d.ts.map +1 -0
  209. package/dist/observer/index.js +6 -0
  210. package/dist/observer/index.js.map +1 -0
  211. package/dist/observer/journal.d.ts +83 -0
  212. package/dist/observer/journal.d.ts.map +1 -0
  213. package/dist/observer/journal.js +76 -0
  214. package/dist/observer/journal.js.map +1 -0
  215. package/dist/observer/retention.d.ts +25 -0
  216. package/dist/observer/retention.d.ts.map +1 -0
  217. package/dist/observer/retention.js +21 -0
  218. package/dist/observer/retention.js.map +1 -0
  219. package/dist/observer/run-summary.d.ts +260 -0
  220. package/dist/observer/run-summary.d.ts.map +1 -0
  221. package/dist/observer/run-summary.js +32 -0
  222. package/dist/observer/run-summary.js.map +1 -0
  223. package/dist/patterns/index.d.ts +2 -0
  224. package/dist/patterns/index.d.ts.map +1 -0
  225. package/dist/patterns/index.js +3 -0
  226. package/dist/patterns/index.js.map +1 -0
  227. package/dist/patterns/pattern.d.ts +106 -0
  228. package/dist/patterns/pattern.d.ts.map +1 -0
  229. package/dist/patterns/pattern.js +69 -0
  230. package/dist/patterns/pattern.js.map +1 -0
  231. package/dist/planning/index.d.ts +2 -0
  232. package/dist/planning/index.d.ts.map +1 -0
  233. package/dist/planning/index.js +3 -0
  234. package/dist/planning/index.js.map +1 -0
  235. package/dist/planning/task.d.ts +178 -0
  236. package/dist/planning/task.d.ts.map +1 -0
  237. package/dist/planning/task.js +35 -0
  238. package/dist/planning/task.js.map +1 -0
  239. package/dist/policy/index.d.ts +2 -0
  240. package/dist/policy/index.d.ts.map +1 -0
  241. package/dist/policy/index.js +3 -0
  242. package/dist/policy/index.js.map +1 -0
  243. package/dist/policy/policy.d.ts +83 -0
  244. package/dist/policy/policy.d.ts.map +1 -0
  245. package/dist/policy/policy.js +57 -0
  246. package/dist/policy/policy.js.map +1 -0
  247. package/dist/product/index.d.ts +5 -0
  248. package/dist/product/index.d.ts.map +1 -0
  249. package/dist/product/index.js +6 -0
  250. package/dist/product/index.js.map +1 -0
  251. package/dist/product/mvp-scope.d.ts +25 -0
  252. package/dist/product/mvp-scope.d.ts.map +1 -0
  253. package/dist/product/mvp-scope.js +18 -0
  254. package/dist/product/mvp-scope.js.map +1 -0
  255. package/dist/product/product-brief.d.ts +94 -0
  256. package/dist/product/product-brief.d.ts.map +1 -0
  257. package/dist/product/product-brief.js +44 -0
  258. package/dist/product/product-brief.js.map +1 -0
  259. package/dist/product/requirements.d.ts +251 -0
  260. package/dist/product/requirements.d.ts.map +1 -0
  261. package/dist/product/requirements.js +50 -0
  262. package/dist/product/requirements.js.map +1 -0
  263. package/dist/product/traceability.d.ts +50 -0
  264. package/dist/product/traceability.d.ts.map +1 -0
  265. package/dist/product/traceability.js +20 -0
  266. package/dist/product/traceability.js.map +1 -0
  267. package/dist/project/index.d.ts +3 -0
  268. package/dist/project/index.d.ts.map +1 -0
  269. package/dist/project/index.js +4 -0
  270. package/dist/project/index.js.map +1 -0
  271. package/dist/project/project-profile.d.ts +79 -0
  272. package/dist/project/project-profile.d.ts.map +1 -0
  273. package/dist/project/project-profile.js +53 -0
  274. package/dist/project/project-profile.js.map +1 -0
  275. package/dist/project/repository-scan.d.ts +82 -0
  276. package/dist/project/repository-scan.d.ts.map +1 -0
  277. package/dist/project/repository-scan.js +29 -0
  278. package/dist/project/repository-scan.js.map +1 -0
  279. package/dist/routing/capability-registry.d.ts +87 -0
  280. package/dist/routing/capability-registry.d.ts.map +1 -0
  281. package/dist/routing/capability-registry.js +26 -0
  282. package/dist/routing/capability-registry.js.map +1 -0
  283. package/dist/routing/escalation.d.ts +25 -0
  284. package/dist/routing/escalation.d.ts.map +1 -0
  285. package/dist/routing/escalation.js +21 -0
  286. package/dist/routing/escalation.js.map +1 -0
  287. package/dist/routing/index.d.ts +5 -0
  288. package/dist/routing/index.d.ts.map +1 -0
  289. package/dist/routing/index.js +6 -0
  290. package/dist/routing/index.js.map +1 -0
  291. package/dist/routing/routing-policy.d.ts +103 -0
  292. package/dist/routing/routing-policy.d.ts.map +1 -0
  293. package/dist/routing/routing-policy.js +32 -0
  294. package/dist/routing/routing-policy.js.map +1 -0
  295. package/dist/routing/routing-request.d.ts +63 -0
  296. package/dist/routing/routing-request.d.ts.map +1 -0
  297. package/dist/routing/routing-request.js +46 -0
  298. package/dist/routing/routing-request.js.map +1 -0
  299. package/dist/runtime-guard/action-classification.d.ts +54 -0
  300. package/dist/runtime-guard/action-classification.d.ts.map +1 -0
  301. package/dist/runtime-guard/action-classification.js +90 -0
  302. package/dist/runtime-guard/action-classification.js.map +1 -0
  303. package/dist/runtime-guard/audit-event.d.ts +98 -0
  304. package/dist/runtime-guard/audit-event.d.ts.map +1 -0
  305. package/dist/runtime-guard/audit-event.js +45 -0
  306. package/dist/runtime-guard/audit-event.js.map +1 -0
  307. package/dist/runtime-guard/index.d.ts +4 -0
  308. package/dist/runtime-guard/index.d.ts.map +1 -0
  309. package/dist/runtime-guard/index.js +5 -0
  310. package/dist/runtime-guard/index.js.map +1 -0
  311. package/dist/runtime-guard/policy-schema.d.ts +139 -0
  312. package/dist/runtime-guard/policy-schema.d.ts.map +1 -0
  313. package/dist/runtime-guard/policy-schema.js +50 -0
  314. package/dist/runtime-guard/policy-schema.js.map +1 -0
  315. package/dist/scaffolding/index.d.ts +3 -0
  316. package/dist/scaffolding/index.d.ts.map +1 -0
  317. package/dist/scaffolding/index.js +4 -0
  318. package/dist/scaffolding/index.js.map +1 -0
  319. package/dist/scaffolding/scaffold-contract.d.ts +528 -0
  320. package/dist/scaffolding/scaffold-contract.d.ts.map +1 -0
  321. package/dist/scaffolding/scaffold-contract.js +50 -0
  322. package/dist/scaffolding/scaffold-contract.js.map +1 -0
  323. package/dist/scaffolding/template-manifest.d.ts +105 -0
  324. package/dist/scaffolding/template-manifest.d.ts.map +1 -0
  325. package/dist/scaffolding/template-manifest.js +44 -0
  326. package/dist/scaffolding/template-manifest.js.map +1 -0
  327. package/dist/secret-guard/detection-rule.d.ts +33 -0
  328. package/dist/secret-guard/detection-rule.d.ts.map +1 -0
  329. package/dist/secret-guard/detection-rule.js +109 -0
  330. package/dist/secret-guard/detection-rule.js.map +1 -0
  331. package/dist/secret-guard/finding.d.ts +89 -0
  332. package/dist/secret-guard/finding.d.ts.map +1 -0
  333. package/dist/secret-guard/finding.js +85 -0
  334. package/dist/secret-guard/finding.js.map +1 -0
  335. package/dist/secret-guard/index.d.ts +5 -0
  336. package/dist/secret-guard/index.d.ts.map +1 -0
  337. package/dist/secret-guard/index.js +6 -0
  338. package/dist/secret-guard/index.js.map +1 -0
  339. package/dist/secret-guard/redaction-policy.d.ts +26 -0
  340. package/dist/secret-guard/redaction-policy.d.ts.map +1 -0
  341. package/dist/secret-guard/redaction-policy.js +30 -0
  342. package/dist/secret-guard/redaction-policy.js.map +1 -0
  343. package/dist/secret-guard/scanner-failure.d.ts +59 -0
  344. package/dist/secret-guard/scanner-failure.d.ts.map +1 -0
  345. package/dist/secret-guard/scanner-failure.js +40 -0
  346. package/dist/secret-guard/scanner-failure.js.map +1 -0
  347. package/dist/specification/index.d.ts +2 -0
  348. package/dist/specification/index.d.ts.map +1 -0
  349. package/dist/specification/index.js +3 -0
  350. package/dist/specification/index.js.map +1 -0
  351. package/dist/specification/specification.d.ts +229 -0
  352. package/dist/specification/specification.d.ts.map +1 -0
  353. package/dist/specification/specification.js +67 -0
  354. package/dist/specification/specification.js.map +1 -0
  355. package/dist/stack-pack/index.d.ts +2 -0
  356. package/dist/stack-pack/index.d.ts.map +1 -0
  357. package/dist/stack-pack/index.js +3 -0
  358. package/dist/stack-pack/index.js.map +1 -0
  359. package/dist/stack-pack/manifest.d.ts +88 -0
  360. package/dist/stack-pack/manifest.d.ts.map +1 -0
  361. package/dist/stack-pack/manifest.js +51 -0
  362. package/dist/stack-pack/manifest.js.map +1 -0
  363. package/dist/verification/index.d.ts +2 -0
  364. package/dist/verification/index.d.ts.map +1 -0
  365. package/dist/verification/index.js +3 -0
  366. package/dist/verification/index.js.map +1 -0
  367. package/dist/verification/report.d.ts +95 -0
  368. package/dist/verification/report.d.ts.map +1 -0
  369. package/dist/verification/report.js +57 -0
  370. package/dist/verification/report.js.map +1 -0
  371. package/dist/workflow/index.d.ts +3 -0
  372. package/dist/workflow/index.d.ts.map +1 -0
  373. package/dist/workflow/index.js +4 -0
  374. package/dist/workflow/index.js.map +1 -0
  375. package/dist/workflow/next-action.d.ts +130 -0
  376. package/dist/workflow/next-action.d.ts.map +1 -0
  377. package/dist/workflow/next-action.js +92 -0
  378. package/dist/workflow/next-action.js.map +1 -0
  379. package/dist/workflow/workflow.d.ts +68 -0
  380. package/dist/workflow/workflow.d.ts.map +1 -0
  381. package/dist/workflow/workflow.js +33 -0
  382. package/dist/workflow/workflow.js.map +1 -0
  383. package/package.json +31 -3
  384. package/src/agent/agent.test.ts +451 -0
  385. package/src/agent/capability.ts +35 -0
  386. package/src/agent/errors.ts +69 -0
  387. package/src/agent/events.ts +107 -0
  388. package/src/agent/execution.ts +275 -0
  389. package/src/agent/index.ts +19 -0
  390. package/src/agent/policy.ts +82 -0
  391. package/src/agent/provider.ts +124 -0
  392. package/src/agent/session.ts +29 -0
  393. package/src/application/application-context.ts +47 -0
  394. package/src/application/application-persistence.ts +44 -0
  395. package/src/application/application-state.test.ts +107 -0
  396. package/src/application/application-state.ts +81 -0
  397. package/src/application/application-transitions.ts +71 -0
  398. package/src/application/index.ts +5 -0
  399. package/src/architecture/api-contract.ts +56 -0
  400. package/src/architecture/architecture-approval.ts +27 -0
  401. package/src/architecture/architecture-options.ts +42 -0
  402. package/src/architecture/architecture.test.ts +263 -0
  403. package/src/architecture/component-map.ts +35 -0
  404. package/src/architecture/data-model.ts +66 -0
  405. package/src/architecture/index.ts +8 -0
  406. package/src/architecture/operational-design.ts +55 -0
  407. package/src/architecture/security-design.ts +47 -0
  408. package/src/common/errors.test.ts +46 -0
  409. package/src/common/errors.ts +114 -0
  410. package/src/common/identifier.test.ts +51 -0
  411. package/src/common/identifier.ts +33 -0
  412. package/src/common/index.ts +4 -0
  413. package/src/common/result.test.ts +52 -0
  414. package/src/common/result.ts +50 -0
  415. package/src/evaluation/benchmark.ts +42 -0
  416. package/src/evaluation/index.ts +3 -0
  417. package/src/evaluation/metrics.ts +76 -0
  418. package/src/evolution/experiment.ts +61 -0
  419. package/src/evolution/improvement-hypothesis.ts +67 -0
  420. package/src/evolution/index.ts +3 -0
  421. package/src/index.test.ts +54 -0
  422. package/src/index.ts +53 -0
  423. package/src/installer/index.ts +4 -0
  424. package/src/installer/install-plan.ts +49 -0
  425. package/src/installer/ownership-manifest.ts +36 -0
  426. package/src/installer/package-manifest.ts +54 -0
  427. package/src/learning/engineering-lesson.ts +55 -0
  428. package/src/learning/engineering-memory.ts +51 -0
  429. package/src/learning/experience-episode.ts +76 -0
  430. package/src/learning/experience.ts +27 -0
  431. package/src/learning/hypothesis.ts +33 -0
  432. package/src/learning/index.ts +8 -0
  433. package/src/learning/memory.ts +25 -0
  434. package/src/learning/promotion.ts +19 -0
  435. package/src/maintenance/bug-fix-workflow.ts +119 -0
  436. package/src/maintenance/bug-report.ts +58 -0
  437. package/src/maintenance/index.ts +6 -0
  438. package/src/maintenance/maintenance.test.ts +219 -0
  439. package/src/maintenance/performance-baseline.ts +35 -0
  440. package/src/maintenance/refactor-contract.ts +77 -0
  441. package/src/maintenance/refactor-workflow.ts +121 -0
  442. package/src/observer/event-schema.ts +54 -0
  443. package/src/observer/index.ts +5 -0
  444. package/src/observer/journal.test.ts +73 -0
  445. package/src/observer/journal.ts +84 -0
  446. package/src/observer/retention.ts +24 -0
  447. package/src/observer/run-summary.ts +37 -0
  448. package/src/patterns/index.ts +2 -0
  449. package/src/patterns/pattern.ts +80 -0
  450. package/src/planning/index.ts +2 -0
  451. package/src/planning/task.ts +47 -0
  452. package/src/policy/index.ts +2 -0
  453. package/src/policy/policy.test.ts +50 -0
  454. package/src/policy/policy.ts +67 -0
  455. package/src/product/index.ts +5 -0
  456. package/src/product/mvp-scope.ts +21 -0
  457. package/src/product/product-brief.test.ts +108 -0
  458. package/src/product/product-brief.ts +53 -0
  459. package/src/product/requirements.ts +59 -0
  460. package/src/product/traceability.ts +25 -0
  461. package/src/project/index.ts +3 -0
  462. package/src/project/project-profile.test.ts +98 -0
  463. package/src/project/project-profile.ts +65 -0
  464. package/src/project/repository-scan.ts +34 -0
  465. package/src/routing/capability-registry.ts +31 -0
  466. package/src/routing/escalation.ts +24 -0
  467. package/src/routing/index.ts +5 -0
  468. package/src/routing/routing-policy.ts +38 -0
  469. package/src/routing/routing-request.ts +55 -0
  470. package/src/runtime-guard/action-classification.ts +99 -0
  471. package/src/runtime-guard/audit-event.ts +49 -0
  472. package/src/runtime-guard/index.ts +4 -0
  473. package/src/runtime-guard/policy-schema.ts +56 -0
  474. package/src/runtime-guard/runtime-guard.test.ts +147 -0
  475. package/src/scaffolding/index.ts +3 -0
  476. package/src/scaffolding/scaffold-contract.test.ts +107 -0
  477. package/src/scaffolding/scaffold-contract.ts +63 -0
  478. package/src/scaffolding/template-manifest.ts +52 -0
  479. package/src/secret-guard/detection-rule.ts +115 -0
  480. package/src/secret-guard/finding.ts +93 -0
  481. package/src/secret-guard/index.ts +5 -0
  482. package/src/secret-guard/redaction-policy.ts +34 -0
  483. package/src/secret-guard/scanner-failure.ts +47 -0
  484. package/src/secret-guard/secret-guard.test.ts +130 -0
  485. package/src/specification/index.ts +2 -0
  486. package/src/specification/specification.ts +79 -0
  487. package/src/stack-pack/index.ts +2 -0
  488. package/src/stack-pack/manifest.ts +60 -0
  489. package/src/verification/index.ts +2 -0
  490. package/src/verification/report.test.ts +91 -0
  491. package/src/verification/report.ts +62 -0
  492. package/src/workflow/index.ts +3 -0
  493. package/src/workflow/next-action.test.ts +101 -0
  494. package/src/workflow/next-action.ts +101 -0
  495. package/src/workflow/workflow.ts +49 -0
@@ -0,0 +1,451 @@
1
+ // packages/contracts/src/agent/agent.test.ts
2
+ //
3
+ // Contract tests for the M36 agent execution surface (v2 revisions A–D).
4
+ // These verify the Zod schemas parse valid payloads, reject invalid ones,
5
+ // and survive a JSON round trip (no functions, no undefined-dependent
6
+ // shapes). See TESTING.md §4.4 and CONTRACTS.md §10.
7
+
8
+ import { describe, expect, it } from 'vitest';
9
+ import {
10
+ AGENT_CAPABILITIES,
11
+ AGENT_EVENT_SCHEMA_VERSION,
12
+ AGENT_EXECUTION_SCHEMA_VERSION,
13
+ AGENT_POLICY_SNAPSHOT_SCHEMA_VERSION,
14
+ AgentCapabilitySchema,
15
+ AgentErrorCodeSchema,
16
+ AgentExecutionErrorSchema,
17
+ AgentExecutionEventSchema,
18
+ AgentExecutionRequestSchema,
19
+ AgentExecutionResultSchema,
20
+ AgentExecutionStatusSchema,
21
+ AgentPolicySnapshotSchema,
22
+ BudgetEnforcementLevelSchema,
23
+ ExecutionBudgetSchema,
24
+ ExecutionWorkspaceSchema,
25
+ NON_SUCCESS_ERROR_CODES,
26
+ RETRYABLE_ERROR_CODES,
27
+ computePolicyHash,
28
+ } from './index.js';
29
+
30
+ const validRequest = {
31
+ schemaVersion: AGENT_EXECUTION_SCHEMA_VERSION,
32
+ executionId: 'exec-001',
33
+ workflowRunId: 'run-001',
34
+ taskId: 'TASK-001',
35
+ providerId: 'claude-code',
36
+ taskKind: 'implementation',
37
+ policyHash: 'sha256:9f2c1ab4',
38
+ workspace: {
39
+ id: 'ws-001',
40
+ kind: 'git-worktree',
41
+ rootPath: '/repo/worktrees/run-001',
42
+ branch: 'kit/run-001',
43
+ baseCommitSha: 'a1b2c3d4e5f6',
44
+ createdAt: '2026-11-20T12:00:00.000Z',
45
+ },
46
+ instructions: 'Implement user registration with email verification.',
47
+ context: {
48
+ specificationRef: 'docs/specifications/features/FEATURE-001/spec.md',
49
+ planRef: 'docs/plans/FEATURE-001/plan.md',
50
+ relevantFiles: ['src/auth/registration.ts'],
51
+ constraints: ['No new runtime dependencies'],
52
+ },
53
+ permissions: {
54
+ capabilities: ['repository.read', 'repository.write', 'process.test'],
55
+ writablePaths: ['/repo/worktrees/run-001/src'],
56
+ networkAllowed: false,
57
+ },
58
+ budget: {
59
+ maxDurationMs: 600_000,
60
+ maxToolCalls: 50,
61
+ maxInputTokens: 150_000,
62
+ maxOutputTokens: 50_000,
63
+ },
64
+ approvalPolicy: {
65
+ requireApprovalFor: ['external.approval'],
66
+ allowAutonomousExecution: true,
67
+ },
68
+ };
69
+
70
+ const validResult = {
71
+ schemaVersion: AGENT_EXECUTION_SCHEMA_VERSION,
72
+ executionId: 'exec-001',
73
+ workflowRunId: 'run-001',
74
+ taskId: 'TASK-001',
75
+ providerId: 'claude-code',
76
+ status: 'completed',
77
+ summary: 'Implemented registration service and email verification flow.',
78
+ proposedArtifacts: [
79
+ { path: 'src/auth/registration.ts', operation: 'create' },
80
+ { path: 'src/auth/verification.ts', operation: 'create' },
81
+ ],
82
+ requestedApprovals: [],
83
+ usage: { inputTokens: 12_000, outputTokens: 3_400, durationMs: 42_000 },
84
+ errors: [],
85
+ };
86
+
87
+ function event(over: Record<string, unknown>): unknown {
88
+ return {
89
+ schemaVersion: AGENT_EVENT_SCHEMA_VERSION,
90
+ eventId: 'evt-001',
91
+ executionId: 'exec-001',
92
+ sequence: 1,
93
+ policyHash: validRequest.policyHash,
94
+ occurredAt: '2026-11-20T12:00:00.000Z',
95
+ ...over,
96
+ };
97
+ }
98
+
99
+ describe('AgentExecutionRequestSchema (v2)', () => {
100
+ it('parses a valid, fully-populated request', () => {
101
+ const r = AgentExecutionRequestSchema.safeParse(validRequest);
102
+ expect(r.success).toBe(true);
103
+ });
104
+
105
+ it('survives a JSON round trip', () => {
106
+ const parsed = AgentExecutionRequestSchema.parse(validRequest);
107
+ const re = AgentExecutionRequestSchema.safeParse(JSON.parse(JSON.stringify(parsed)));
108
+ expect(re.success).toBe(true);
109
+ });
110
+
111
+ it('rejects an uppercase providerId (must be kebab-case)', () => {
112
+ const r = AgentExecutionRequestSchema.safeParse({ ...validRequest, providerId: 'ClaudeCode' });
113
+ expect(r.success).toBe(false);
114
+ });
115
+
116
+ it('rejects an empty instructions string', () => {
117
+ const r = AgentExecutionRequestSchema.safeParse({ ...validRequest, instructions: '' });
118
+ expect(r.success).toBe(false);
119
+ });
120
+
121
+ it('rejects a missing workspace (revision B: no cwd assumption)', () => {
122
+ const { workspace, ...withoutWorkspace } = validRequest;
123
+ expect(workspace).toBeDefined();
124
+ const r = AgentExecutionRequestSchema.safeParse(withoutWorkspace);
125
+ expect(r.success).toBe(false);
126
+ });
127
+
128
+ it('rejects a git-worktree workspace without branch/baseCommitSha', () => {
129
+ const r = AgentExecutionRequestSchema.safeParse({
130
+ ...validRequest,
131
+ workspace: { ...validRequest.workspace, branch: undefined, baseCommitSha: undefined },
132
+ });
133
+ expect(r.success).toBe(false);
134
+ });
135
+
136
+ it('rejects a workspace with an unknown kind', () => {
137
+ const r = AgentExecutionRequestSchema.safeParse({
138
+ ...validRequest,
139
+ workspace: { ...validRequest.workspace, kind: 'vm' },
140
+ });
141
+ expect(r.success).toBe(false);
142
+ });
143
+
144
+ it('rejects a missing budget (revision C)', () => {
145
+ const { budget, ...withoutBudget } = validRequest;
146
+ expect(budget).toBeDefined();
147
+ const r = AgentExecutionRequestSchema.safeParse(withoutBudget);
148
+ expect(r.success).toBe(false);
149
+ });
150
+
151
+ it('rejects a missing policyHash (revision D: policy traceability)', () => {
152
+ const { policyHash, ...withoutHash } = validRequest;
153
+ expect(policyHash).toBeDefined();
154
+ const r = AgentExecutionRequestSchema.safeParse(withoutHash);
155
+ expect(r.success).toBe(false);
156
+ });
157
+
158
+ it('rejects a capability outside the allowlist (arbitrary shell is not a capability)', () => {
159
+ const r = AgentExecutionRequestSchema.safeParse({
160
+ ...validRequest,
161
+ permissions: { ...validRequest.permissions, capabilities: ['process.shell'] },
162
+ });
163
+ expect(r.success).toBe(false);
164
+ });
165
+
166
+ it('rejects a v1 schemaVersion', () => {
167
+ const r = AgentExecutionRequestSchema.safeParse({ ...validRequest, schemaVersion: 1 });
168
+ expect(r.success).toBe(false);
169
+ });
170
+ });
171
+
172
+ describe('ExecutionWorkspaceSchema', () => {
173
+ it('accepts a container workspace without git fields', () => {
174
+ const r = ExecutionWorkspaceSchema.safeParse({
175
+ id: 'ws-c',
176
+ kind: 'container',
177
+ rootPath: '/var/containers/exec-1',
178
+ createdAt: '2026-11-20T12:00:00.000Z',
179
+ });
180
+ expect(r.success).toBe(true);
181
+ });
182
+
183
+ it('rejects an empty rootPath', () => {
184
+ const r = ExecutionWorkspaceSchema.safeParse({
185
+ id: 'ws-c',
186
+ kind: 'directory',
187
+ rootPath: '',
188
+ createdAt: '2026-11-20T12:00:00.000Z',
189
+ });
190
+ expect(r.success).toBe(false);
191
+ });
192
+ });
193
+
194
+ describe('ExecutionBudgetSchema', () => {
195
+ it('requires duration and tool calls (gateway-enforceable)', () => {
196
+ const r = ExecutionBudgetSchema.safeParse({ maxDurationMs: 1000, maxToolCalls: 10 });
197
+ expect(r.success).toBe(true);
198
+ });
199
+
200
+ it('rejects a non-positive duration', () => {
201
+ const r = ExecutionBudgetSchema.safeParse({ maxDurationMs: 0, maxToolCalls: 10 });
202
+ expect(r.success).toBe(false);
203
+ });
204
+
205
+ it('accepts an estimated cost with currency', () => {
206
+ const r = ExecutionBudgetSchema.safeParse({
207
+ maxDurationMs: 1000,
208
+ maxToolCalls: 10,
209
+ maxEstimatedCost: { amount: 2.5, currency: 'USD' },
210
+ });
211
+ expect(r.success).toBe(true);
212
+ });
213
+
214
+ it('rejects an estimated cost without currency', () => {
215
+ const r = ExecutionBudgetSchema.safeParse({
216
+ maxDurationMs: 1000,
217
+ maxToolCalls: 10,
218
+ maxEstimatedCost: { amount: 2.5 },
219
+ });
220
+ expect(r.success).toBe(false);
221
+ });
222
+ });
223
+
224
+ describe('BudgetEnforcementLevelSchema (revision C honesty)', () => {
225
+ it('accepts exactly the three honest levels', () => {
226
+ expect(BudgetEnforcementLevelSchema.options).toEqual([
227
+ 'provider-enforced',
228
+ 'gateway-enforced',
229
+ 'best-effort',
230
+ ]);
231
+ });
232
+
233
+ it('rejects a made-up level like "always-enforced"', () => {
234
+ const r = BudgetEnforcementLevelSchema.safeParse('always-enforced');
235
+ expect(r.success).toBe(false);
236
+ });
237
+ });
238
+
239
+ describe('AgentExecutionResultSchema', () => {
240
+ it('parses a valid completed result', () => {
241
+ const r = AgentExecutionResultSchema.safeParse(validResult);
242
+ expect(r.success).toBe(true);
243
+ });
244
+
245
+ it('parses a failed result with a typed error', () => {
246
+ const r = AgentExecutionResultSchema.safeParse({
247
+ ...validResult,
248
+ status: 'timed_out',
249
+ summary: 'Agent exceeded budget maxDurationMs after partial implementation.',
250
+ errors: [{ code: 'PROVIDER_TIMEOUT', message: 'exceeded 600000ms', retryable: false }],
251
+ });
252
+ expect(r.success).toBe(true);
253
+ });
254
+
255
+ it('rejects an empty summary (a result must explain itself)', () => {
256
+ const r = AgentExecutionResultSchema.safeParse({ ...validResult, summary: '' });
257
+ expect(r.success).toBe(false);
258
+ });
259
+
260
+ it('rejects an unknown status', () => {
261
+ const r = AgentExecutionResultSchema.safeParse({ ...validResult, status: 'success' });
262
+ expect(r.success).toBe(false);
263
+ });
264
+
265
+ it('rejects a result whose proposedArtifacts use an invalid operation', () => {
266
+ const r = AgentExecutionResultSchema.safeParse({
267
+ ...validResult,
268
+ proposedArtifacts: [{ path: 'src/x.ts', operation: 'move' }],
269
+ });
270
+ expect(r.success).toBe(false);
271
+ });
272
+ });
273
+
274
+ describe('AgentExecutionEventSchema (v2 envelope, revision D)', () => {
275
+ it('parses each event variant', () => {
276
+ const cases: Array<{ type: string; extra: Record<string, unknown> }> = [
277
+ { type: 'execution.started', extra: {} },
278
+ { type: 'message.delta', extra: { content: 'hello' } },
279
+ { type: 'tool.requested', extra: { toolCallId: 'tc-1', capability: 'process.test' } },
280
+ { type: 'tool.result', extra: { toolCallId: 'tc-1', status: 'succeeded' } },
281
+ {
282
+ type: 'approval.required',
283
+ extra: { approvalId: 'ap-1', action: 'deploy', reason: 'production deploy' },
284
+ },
285
+ { type: 'execution.progress', extra: { taskId: 'TASK-001', progress: 0.5 } },
286
+ { type: 'execution.completed', extra: { status: 'completed' } },
287
+ ];
288
+ for (const [i, c] of cases.entries()) {
289
+ const r = AgentExecutionEventSchema.safeParse(
290
+ event({ type: c.type, sequence: i + 1, eventId: `evt-${i + 1}`, ...c.extra }),
291
+ );
292
+ expect(r.success, `event type ${c.type}`).toBe(true);
293
+ }
294
+ });
295
+
296
+ it('rejects an event missing the monotonic sequence field', () => {
297
+ const e = event({ type: 'execution.started' });
298
+ delete (e as { sequence?: number }).sequence;
299
+ const r = AgentExecutionEventSchema.safeParse(e);
300
+ expect(r.success).toBe(false);
301
+ });
302
+
303
+ it('rejects an event missing eventId (idempotent persistence key)', () => {
304
+ const e = event({ type: 'execution.started' });
305
+ delete (e as { eventId?: string }).eventId;
306
+ const r = AgentExecutionEventSchema.safeParse(e);
307
+ expect(r.success).toBe(false);
308
+ });
309
+
310
+ it('rejects an event missing policyHash (policy traceability)', () => {
311
+ const e = event({ type: 'execution.started' });
312
+ delete (e as { policyHash?: string }).policyHash;
313
+ const r = AgentExecutionEventSchema.safeParse(e);
314
+ expect(r.success).toBe(false);
315
+ });
316
+
317
+ it('rejects an event with an unknown discriminator', () => {
318
+ const r = AgentExecutionEventSchema.safeParse(event({ type: 'tool.queued' }));
319
+ expect(r.success).toBe(false);
320
+ });
321
+
322
+ it('rejects a tool.requested event whose capability is outside the allowlist', () => {
323
+ const r = AgentExecutionEventSchema.safeParse(
324
+ event({ type: 'tool.requested', toolCallId: 'tc-1', capability: 'process.shell' }),
325
+ );
326
+ expect(r.success).toBe(false);
327
+ });
328
+ });
329
+
330
+ describe('capability and error taxonomy', () => {
331
+ it('AGENT_CAPABILITIES matches the schema options (cannot drift)', () => {
332
+ expect(AgentCapabilitySchema.options).toEqual([...AGENT_CAPABILITIES]);
333
+ });
334
+
335
+ it('does not include an arbitrary-shell capability', () => {
336
+ expect(AgentCapabilitySchema.options).not.toContain('process.shell');
337
+ expect(AgentCapabilitySchema.options).not.toContain('shell.exec');
338
+ });
339
+
340
+ it('NON_SUCCESS and RETRYABLE error sets are disjoint', () => {
341
+ const overlap = NON_SUCCESS_ERROR_CODES.filter((c) => RETRYABLE_ERROR_CODES.includes(c));
342
+ expect(overlap).toEqual([]);
343
+ });
344
+
345
+ it('every error code in the sets is a valid AgentErrorCode', () => {
346
+ const valid = AgentErrorCodeSchema.options;
347
+ for (const c of [...NON_SUCCESS_ERROR_CODES, ...RETRYABLE_ERROR_CODES]) {
348
+ expect(valid).toContain(c);
349
+ }
350
+ });
351
+
352
+ it('AgentExecutionErrorSchema rejects an unknown code', () => {
353
+ const r = AgentExecutionErrorSchema.safeParse({
354
+ code: 'WHOOPS',
355
+ message: 'x',
356
+ retryable: false,
357
+ });
358
+ expect(r.success).toBe(false);
359
+ });
360
+ });
361
+
362
+ describe('status taxonomy', () => {
363
+ it('does not include a "success" alias — only "completed"', () => {
364
+ expect(AgentExecutionStatusSchema.options).toContain('completed');
365
+ expect(AgentExecutionStatusSchema.options).not.toContain('success');
366
+ });
367
+ });
368
+
369
+ describe('canonical policy snapshot (ADR-0020 §1)', () => {
370
+ const snapshot = {
371
+ schemaVersion: AGENT_POLICY_SNAPSHOT_SCHEMA_VERSION,
372
+ permissions: {
373
+ capabilities: ['repository.read', 'repository.write', 'process.test'] as const,
374
+ writablePaths: ['/repo/worktrees/run-001'],
375
+ networkAllowed: false,
376
+ },
377
+ budget: {
378
+ maxDurationMs: 600_000,
379
+ maxToolCalls: 200,
380
+ },
381
+ approvalPolicy: {
382
+ requireApprovalFor: ['external.approval'] as const,
383
+ allowAutonomousExecution: true,
384
+ },
385
+ };
386
+
387
+ it('parses a valid snapshot', () => {
388
+ const r = AgentPolicySnapshotSchema.safeParse(snapshot);
389
+ expect(r.success).toBe(true);
390
+ });
391
+
392
+ it('rejects an empty capability grant (least privilege means explicit, not none)', () => {
393
+ const r = AgentPolicySnapshotSchema.safeParse({
394
+ ...snapshot,
395
+ permissions: { ...snapshot.permissions, capabilities: [] },
396
+ });
397
+ expect(r.success).toBe(false);
398
+ });
399
+
400
+ it('rejects a capability outside the allowlist', () => {
401
+ const r = AgentPolicySnapshotSchema.safeParse({
402
+ ...snapshot,
403
+ permissions: {
404
+ ...snapshot.permissions,
405
+ capabilities: ['repository.read', 'process.shell'],
406
+ },
407
+ });
408
+ expect(r.success).toBe(false);
409
+ });
410
+
411
+ it('rejects the wrong schemaVersion', () => {
412
+ const r = AgentPolicySnapshotSchema.safeParse({ ...snapshot, schemaVersion: 2 });
413
+ expect(r.success).toBe(false);
414
+ });
415
+
416
+ it('hashes to a stable sha256:<hex> value', () => {
417
+ const h = computePolicyHash(AgentPolicySnapshotSchema.parse(snapshot));
418
+ expect(h).toMatch(/^sha256:[0-9a-f]{64}$/);
419
+ expect(computePolicyHash(AgentPolicySnapshotSchema.parse(snapshot))).toBe(h);
420
+ });
421
+
422
+ it('is independent of property insertion order (canonical JSON)', () => {
423
+ const reordered = {
424
+ approvalPolicy: snapshot.approvalPolicy,
425
+ budget: { maxToolCalls: 200, maxDurationMs: 600_000 },
426
+ permissions: {
427
+ networkAllowed: false,
428
+ writablePaths: ['/repo/worktrees/run-001'],
429
+ capabilities: ['repository.read', 'repository.write', 'process.test'],
430
+ },
431
+ schemaVersion: AGENT_POLICY_SNAPSHOT_SCHEMA_VERSION,
432
+ };
433
+ expect(computePolicyHash(AgentPolicySnapshotSchema.parse(reordered))).toBe(
434
+ computePolicyHash(AgentPolicySnapshotSchema.parse(snapshot)),
435
+ );
436
+ });
437
+
438
+ it('changes when the policy changes (a different grant is a different policy)', () => {
439
+ const changed = { ...snapshot, permissions: { ...snapshot.permissions, networkAllowed: true } };
440
+ expect(computePolicyHash(AgentPolicySnapshotSchema.parse(changed))).not.toBe(
441
+ computePolicyHash(AgentPolicySnapshotSchema.parse(snapshot)),
442
+ );
443
+ });
444
+
445
+ it('changes when the budget changes', () => {
446
+ const changed = { ...snapshot, budget: { maxDurationMs: 300_000, maxToolCalls: 200 } };
447
+ expect(computePolicyHash(AgentPolicySnapshotSchema.parse(changed))).not.toBe(
448
+ computePolicyHash(AgentPolicySnapshotSchema.parse(snapshot)),
449
+ );
450
+ });
451
+ });
@@ -0,0 +1,35 @@
1
+ // packages/contracts/src/agent/capability.ts
2
+ //
3
+ // M36 agent capability taxonomy (ADR-0020). Capabilities are the unit of
4
+ // least privilege granted to an agent execution: a provider may only
5
+ // exercise capabilities the orchestrator explicitly granted in
6
+ // AgentExecutionRequest.permissions.capabilities, and the tool broker
7
+ // authorizes each tool call against that set.
8
+ //
9
+ // Invariant (SECURITY.md §1, ADR-0020): an agent MUST NOT receive
10
+ // unrestricted authority merely because it is connected to Kit. The
11
+ // capability set is allowlisted; "execute arbitrary shell" is NOT a
12
+ // capability and never will be.
13
+
14
+ import { z } from 'zod';
15
+
16
+ export const AgentCapabilitySchema = z.enum([
17
+ 'repository.read',
18
+ 'repository.write',
19
+ 'git.read',
20
+ 'git.write',
21
+ 'process.test',
22
+ 'process.build',
23
+ 'process.lint',
24
+ 'process.typecheck',
25
+ 'network.access',
26
+ 'external.approval',
27
+ ]);
28
+
29
+ export type AgentCapability = z.infer<typeof AgentCapabilitySchema>;
30
+
31
+ /**
32
+ * The full capability allowlist, derived from the schema so it cannot
33
+ * drift. Tool-broker policy and runtime Mods both read from this set.
34
+ */
35
+ export const AGENT_CAPABILITIES: readonly AgentCapability[] = AgentCapabilitySchema.options;
@@ -0,0 +1,69 @@
1
+ // packages/contracts/src/agent/errors.ts
2
+ //
3
+ // M36 agent execution error taxonomy (ADR-0019). Errors are classified by
4
+ // whether a retry can succeed: a provider crash or rate limit is retryable;
5
+ // a policy denial or malformed request is not. A timeout or cancellation
6
+ // is NEVER reported as `completed`.
7
+
8
+ import { z } from 'zod';
9
+
10
+ export const AgentErrorCodeSchema = z.enum([
11
+ // Provider could not be reached (network, auth, service down).
12
+ 'PROVIDER_UNREACHABLE',
13
+ // Provider rate-limited the request; retryable with backoff.
14
+ 'PROVIDER_RATE_LIMITED',
15
+ // Provider returned an internal error; retryable.
16
+ 'PROVIDER_INTERNAL',
17
+ // The agent attempted an operation outside its granted capabilities.
18
+ // NOT retryable — the grant must change.
19
+ 'CAPABILITY_DENIED',
20
+ // An approval-required action was encountered; execution paused.
21
+ 'APPROVAL_REQUIRED',
22
+ // A requested approval was rejected by the human approver.
23
+ 'APPROVAL_REJECTED',
24
+ // The request was malformed or violated contract; NOT retryable.
25
+ 'REQUEST_INVALID',
26
+ // A budget (tokens, tool calls, duration) was exceeded.
27
+ 'BUDGET_EXCEEDED',
28
+ // The provider session expired or was evicted; resume may be impossible.
29
+ 'SESSION_EXPIRED',
30
+ // The execution exceeded maxDurationMs.
31
+ 'PROVIDER_TIMEOUT',
32
+ // The execution was cancelled via AbortSignal or cancel().
33
+ 'CANCELLED',
34
+ // Unclassified; treated as non-retryable unless proven otherwise.
35
+ 'UNKNOWN',
36
+ ]);
37
+
38
+ export type AgentErrorCode = z.infer<typeof AgentErrorCodeSchema>;
39
+
40
+ export const AgentExecutionErrorSchema = z.object({
41
+ code: AgentErrorCodeSchema,
42
+ message: z.string().min(1),
43
+ retryable: z.boolean(),
44
+ });
45
+ export type AgentExecutionError = z.infer<typeof AgentExecutionErrorSchema>;
46
+
47
+ /**
48
+ * Codes that mean "the execution did not produce usable work and must not
49
+ * be treated as success under any circumstance." A workflow task MUST NOT
50
+ * advance when the execution ended with any of these, regardless of any
51
+ * `completed`-flavored summary the provider also returned.
52
+ */
53
+ export const NON_SUCCESS_ERROR_CODES: readonly AgentErrorCode[] = [
54
+ 'CAPABILITY_DENIED',
55
+ 'APPROVAL_REJECTED',
56
+ 'REQUEST_INVALID',
57
+ 'PROVIDER_TIMEOUT',
58
+ 'CANCELLED',
59
+ ];
60
+
61
+ /**
62
+ * Codes that MAY justify an automatic retry (with backoff) by the
63
+ * orchestrator. Everything else is terminal for this execution.
64
+ */
65
+ export const RETRYABLE_ERROR_CODES: readonly AgentErrorCode[] = [
66
+ 'PROVIDER_UNREACHABLE',
67
+ 'PROVIDER_RATE_LIMITED',
68
+ 'PROVIDER_INTERNAL',
69
+ ];
@@ -0,0 +1,107 @@
1
+ // packages/contracts/src/agent/events.ts
2
+ //
3
+ // M36 agent execution event contract (ADR-0019 v2, revision D). Events
4
+ // are the normalized lifecycle stream emitted by a provider during an
5
+ // execution; the GATEWAY persists them and replay is idempotent. Every
6
+ // event carries:
7
+ // - `eventId` — unique per event; makes persistence and replay
8
+ // idempotent (the same event stored twice is
9
+ // detectable, not duplicable)
10
+ // - `sequence` — monotonically increasing per executionId; gaps and
11
+ // duplicates are detectable in the audit log
12
+ // - `policyHash` — echo of the request's policy snapshot hash; the
13
+ // gateway rejects events whose hash does not match
14
+ // the execution's policy (fail closed, ADR-0020 §4)
15
+ //
16
+ // Invariant: events are OBSERVABILITY, not control.
17
+ // - A `tool.requested` event does NOT authorize the tool — the tool
18
+ // broker's authorization decision is the only authority.
19
+ // - An `execution.completed` event does NOT complete the workflow task —
20
+ // only Kit's independent evidence check can mark a task complete
21
+ // (ADR-0018, ADR-0019).
22
+
23
+ import { z } from 'zod';
24
+ import { AgentCapabilitySchema } from './capability.js';
25
+
26
+ export const AgentExecutionEventKindSchema = z.enum([
27
+ 'execution.started',
28
+ 'message.delta',
29
+ 'tool.requested',
30
+ 'tool.result',
31
+ 'approval.required',
32
+ 'execution.progress',
33
+ 'execution.completed',
34
+ ]);
35
+ export type AgentExecutionEventKind = z.infer<typeof AgentExecutionEventKindSchema>;
36
+
37
+ export const AGENT_EVENT_SCHEMA_VERSION = 2 as const;
38
+
39
+ // Fields common to every event variant (the persistence envelope, kept
40
+ // stable while per-kind payloads stay typed in the discriminated union).
41
+ const AgentExecutionEventBaseSchema = z.object({
42
+ schemaVersion: z.literal(AGENT_EVENT_SCHEMA_VERSION),
43
+ // Unique per event; gateway persistence is idempotent on it.
44
+ eventId: z.string().min(1),
45
+ // Correlates to AgentExecutionRequest.executionId.
46
+ executionId: z.string().min(1),
47
+ // Monotonic per-execution sequence; the first event for an executionId
48
+ // is sequence=1. Kit uses it to detect gaps and duplicates in the audit log.
49
+ sequence: z.number().int().positive(),
50
+ // Echo of AgentExecutionRequest.policyHash — the policy snapshot in
51
+ // force when the event was produced. Mismatches fail closed.
52
+ policyHash: z.string().min(1),
53
+ // ISO 8601 timestamp.
54
+ occurredAt: z.string(),
55
+ });
56
+
57
+ export const AgentExecutionEventSchema = z.discriminatedUnion('type', [
58
+ AgentExecutionEventBaseSchema.extend({
59
+ type: z.literal('execution.started'),
60
+ }),
61
+ AgentExecutionEventBaseSchema.extend({
62
+ type: z.literal('message.delta'),
63
+ content: z.string(),
64
+ }),
65
+ AgentExecutionEventBaseSchema.extend({
66
+ type: z.literal('tool.requested'),
67
+ toolCallId: z.string().min(1),
68
+ capability: AgentCapabilitySchema,
69
+ }),
70
+ AgentExecutionEventBaseSchema.extend({
71
+ type: z.literal('tool.result'),
72
+ toolCallId: z.string().min(1),
73
+ status: z.enum(['succeeded', 'failed', 'denied']),
74
+ }),
75
+ AgentExecutionEventBaseSchema.extend({
76
+ type: z.literal('approval.required'),
77
+ approvalId: z.string().min(1),
78
+ action: z.string().min(1),
79
+ reason: z.string().min(1),
80
+ }),
81
+ AgentExecutionEventBaseSchema.extend({
82
+ type: z.literal('execution.progress'),
83
+ taskId: z.string().min(1),
84
+ progress: z.number().min(0).max(1).optional(),
85
+ }),
86
+ AgentExecutionEventBaseSchema.extend({
87
+ type: z.literal('execution.completed'),
88
+ status: z.enum([
89
+ 'completed',
90
+ 'failed',
91
+ 'cancelled',
92
+ 'timed_out',
93
+ 'interrupted',
94
+ 'needs_approval',
95
+ ]),
96
+ }),
97
+ ]);
98
+
99
+ export type AgentExecutionEvent = z.infer<typeof AgentExecutionEventSchema>;
100
+
101
+ /**
102
+ * Event sink subscribed via an AgentExecutionHandle. Providers that emit
103
+ * lifecycle events deliver them through the handle's `events()`
104
+ * subscription; providers that do not stream simply never deliver.
105
+ * The subscription returns an unsubscribe function.
106
+ */
107
+ export type AgentEventSink = (event: AgentExecutionEvent) => void;