@agentic-sdlc-kit/contracts 0.0.0-stage → 0.9.1

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 +86 -0
  140. package/dist/installer/ownership-manifest.d.ts.map +1 -0
  141. package/dist/installer/ownership-manifest.js +34 -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 +153 -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 +87 -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 +40 -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 +168 -0
  480. package/src/secret-guard/finding.ts +95 -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,19 @@
1
+ // packages/contracts/src/learning/promotion.ts
2
+ //
3
+ // M33 Controlled Promotion and Rollback contracts.
4
+ // Enforces independent verification, human authorization, and reversible rollouts.
5
+
6
+ import { z } from 'zod';
7
+
8
+ export const SkillPromotionRequestSchema = z.object({
9
+ id: z.string().min(1),
10
+ hypothesisId: z.string().min(1),
11
+ targetSkill: z.string().min(1),
12
+ branchName: z.string().min(1),
13
+ diffSummary: z.string().min(1),
14
+ status: z.enum(['pending_approval', 'approved', 'rejected', 'rolled_back']),
15
+ approvedBy: z.string().optional(),
16
+ createdAt: z.string().min(1),
17
+ });
18
+
19
+ export type SkillPromotionRequest = z.infer<typeof SkillPromotionRequestSchema>;
@@ -0,0 +1,119 @@
1
+ // packages/contracts/src/maintenance/bug-fix-workflow.ts
2
+ //
3
+ // Bug-fix workflow state and transitions (M9 — M9-03 through M9-10).
4
+ //
5
+ // Lifecycle (post-M7 roadmap §3.1):
6
+ // Bug Report → Discovery → Reproduction → Root Cause →
7
+ // Regression Test → Minimal Fix → Focused Verification →
8
+ // Regression Verification → Review → Completion Report
9
+ //
10
+ // CRITICAL RULES (post-M7 roadmap §3.1):
11
+ // - Do not fix a symptom without investigating the root cause.
12
+ // - Do not delete or weaken a failing test to make the build green.
13
+ // - Do not claim reproduction when only a theoretical explanation exists.
14
+ // - A non-reproducible issue must be reported as such.
15
+ // - Changes must remain within the approved scope unless expanded.
16
+
17
+ import { z } from 'zod';
18
+
19
+ export const BUG_FIX_STAGE = z.enum([
20
+ 'report', // bug report captured
21
+ 'discovery', // affected-code discovery
22
+ 'reproduction', // reproduce the defect
23
+ 'root-cause', // root cause analysis
24
+ 'regression-test', // write a failing regression test
25
+ 'minimal-fix', // implement the smallest valid correction
26
+ 'focused-verify', // focused test evidence
27
+ 'regression-verify', // broader regression evidence
28
+ 'review', // independent review
29
+ 'completion', // completion report
30
+ ]);
31
+ export type BugFixStage = z.infer<typeof BUG_FIX_STAGE>;
32
+
33
+ export const BUG_FIX_STATUS = z.enum(['pending', 'in_progress', 'blocked', 'completed', 'failed']);
34
+ export type BugFixStatus = z.infer<typeof BUG_FIX_STATUS>;
35
+
36
+ export const BUG_FIX_TRANSITION = z.enum([
37
+ 'start',
38
+ 'advance',
39
+ 'block',
40
+ 'resume',
41
+ 'complete',
42
+ 'fail',
43
+ ]);
44
+ export type BugFixTransition = z.infer<typeof BUG_FIX_TRANSITION>;
45
+
46
+ export const BugFixStateSchema = z.object({
47
+ schemaVersion: z.literal(1),
48
+ runId: z.string(),
49
+ bugId: z.string(),
50
+ status: BUG_FIX_STATUS,
51
+ stage: BUG_FIX_STAGE,
52
+ startedAt: z.string().optional(),
53
+ // Filled in during root-cause:
54
+ rootCauseSummary: z.string().optional(),
55
+ // Filled in during regression-test:
56
+ regressionTestPath: z.string().optional(),
57
+ // Filled in during focused-verify / regression-verify:
58
+ verificationReportIds: z.array(z.string()).default([]),
59
+ // Files the fix touched (for review).
60
+ affectedFiles: z.array(z.string()).default([]),
61
+ });
62
+
63
+ export type BugFixState = z.infer<typeof BugFixStateSchema>;
64
+
65
+ export const BUG_FIX_STAGE_ORDER: ReadonlyArray<BugFixStage> = [
66
+ 'report',
67
+ 'discovery',
68
+ 'reproduction',
69
+ 'root-cause',
70
+ 'regression-test',
71
+ 'minimal-fix',
72
+ 'focused-verify',
73
+ 'regression-verify',
74
+ 'review',
75
+ 'completion',
76
+ ];
77
+
78
+ export const BUG_FIX_TRANSITIONS_BY_STATUS: Readonly<
79
+ Record<BugFixStatus, ReadonlyArray<BugFixTransition>>
80
+ > = {
81
+ pending: ['start'],
82
+ in_progress: ['advance', 'block', 'complete', 'fail'],
83
+ blocked: ['resume', 'fail'],
84
+ completed: [],
85
+ failed: [],
86
+ };
87
+
88
+ export const BUG_FIX_TARGET_STATUS: Readonly<Record<BugFixTransition, BugFixStatus>> = {
89
+ start: 'in_progress',
90
+ advance: 'in_progress',
91
+ block: 'blocked',
92
+ resume: 'in_progress',
93
+ complete: 'completed',
94
+ fail: 'failed',
95
+ };
96
+
97
+ /**
98
+ * The completion stage is the only stage from which `complete` is allowed.
99
+ */
100
+ export const BUG_FIX_COMPLETABLE_STAGES: ReadonlyArray<BugFixStage> = ['completion'];
101
+
102
+ /**
103
+ * INVARIANT: the regression-test stage MUST be completed before the
104
+ * minimal-fix stage can advance. This is the most important invariant in
105
+ * the bug-fix workflow — without a regression test, there is no proof the
106
+ * fix actually fixes anything.
107
+ */
108
+ export function regressionTestRequiredBeforeFix(
109
+ fromStage: BugFixStage,
110
+ toStage: BugFixStage,
111
+ ): boolean {
112
+ if (toStage === 'minimal-fix') {
113
+ // The stage before minimal-fix in canonical order is regression-test.
114
+ const fixIdx = BUG_FIX_STAGE_ORDER.indexOf('minimal-fix');
115
+ const prevStage = BUG_FIX_STAGE_ORDER[fixIdx - 1];
116
+ return prevStage === 'regression-test' && fromStage !== 'regression-test';
117
+ }
118
+ return false;
119
+ }
@@ -0,0 +1,58 @@
1
+ // packages/contracts/src/maintenance/bug-report.ts
2
+ //
3
+ // Bug report contract (M9 — M9-01, M9-02).
4
+ //
5
+ // A bug report is the input to /kit:fix. The kit classifies it and decides
6
+ // whether reproduction is possible. A non-reproducible issue MUST be
7
+ // reported as such — the kit MUST NOT claim reproduction when only a
8
+ // theoretical explanation exists.
9
+
10
+ import { z } from 'zod';
11
+
12
+ export const BugCategorySchema = z.enum([
13
+ 'functional',
14
+ 'regression',
15
+ 'data',
16
+ 'security',
17
+ 'performance',
18
+ 'ui',
19
+ 'other',
20
+ ]);
21
+
22
+ export const ReproductionStatusSchema = z.enum([
23
+ 'not-attempted',
24
+ 'reproduced',
25
+ 'not-reproducible',
26
+ 'intermittent',
27
+ ]);
28
+
29
+ export const BugReportSchema = z
30
+ .object({
31
+ id: z.string().regex(/^[A-Z]+-[0-9]{3,}$/, 'id must match BUG-NNN'),
32
+ title: z.string().min(1).max(200),
33
+ description: z.string().min(1),
34
+ reportedAt: z.string(),
35
+ reportedBy: z.string(),
36
+ category: BugCategorySchema,
37
+ severity: z.enum(['low', 'medium', 'high', 'critical']),
38
+ // Steps to reproduce as reported by the user.
39
+ reportedSteps: z.array(z.string()),
40
+ expectedBehavior: z.string().min(1),
41
+ actualBehavior: z.string().min(1),
42
+ // URLs / commit SHAs / environments where the bug was observed.
43
+ environment: z
44
+ .array(
45
+ z.object({
46
+ key: z.string(),
47
+ value: z.string(),
48
+ }),
49
+ )
50
+ .default([]),
51
+ // Initial reproduction status. Set to "not-attempted" by default.
52
+ reproductionStatus: ReproductionStatusSchema.default('not-attempted'),
53
+ })
54
+ .strict();
55
+
56
+ export type BugCategory = z.infer<typeof BugCategorySchema>;
57
+ export type ReproductionStatus = z.infer<typeof ReproductionStatusSchema>;
58
+ export type BugReport = z.infer<typeof BugReportSchema>;
@@ -0,0 +1,6 @@
1
+ // packages/contracts/src/maintenance/index.ts
2
+ export * from './bug-report.js';
3
+ export * from './bug-fix-workflow.js';
4
+ export * from './refactor-contract.js';
5
+ export * from './refactor-workflow.js';
6
+ export * from './performance-baseline.js';
@@ -0,0 +1,219 @@
1
+ // packages/contracts/src/maintenance/maintenance.test.ts
2
+ import { describe, expect, it } from 'vitest';
3
+ import { BugReportSchema } from './bug-report.js';
4
+ import {
5
+ BUG_FIX_STAGE_ORDER,
6
+ BUG_FIX_TRANSITIONS_BY_STATUS,
7
+ regressionTestRequiredBeforeFix,
8
+ } from './bug-fix-workflow.js';
9
+ import { RefactorContractSchema } from './refactor-contract.js';
10
+ import {
11
+ REFACTOR_STAGE_ORDER,
12
+ REFACTOR_TRANSITIONS_BY_STATUS,
13
+ characterizationRequiredBeforeRefactor,
14
+ } from './refactor-workflow.js';
15
+ import { PerformanceProblemSchema } from './performance-baseline.js';
16
+
17
+ const validBug = {
18
+ id: 'BUG-001',
19
+ title: 'Duplicate invoices on webhook retry',
20
+ description: 'When the payment provider sends the same webhook twice, two invoices are created.',
21
+ reportedAt: '2026-01-01T00:00:00.000Z',
22
+ reportedBy: 'user',
23
+ category: 'functional',
24
+ severity: 'high',
25
+ reportedSteps: ['send webhook', 'resend same webhook'],
26
+ expectedBehavior: 'Only one invoice per payment.',
27
+ actualBehavior: 'Two invoices are created.',
28
+ environment: [],
29
+ };
30
+
31
+ describe('BugReportSchema', () => {
32
+ it('accepts a valid report', () => {
33
+ expect(BugReportSchema.safeParse(validBug).success).toBe(true);
34
+ });
35
+ it('defaults reproductionStatus to not-attempted', () => {
36
+ const r = BugReportSchema.safeParse(validBug);
37
+ expect(r.success).toBe(true);
38
+ if (r.success) expect(r.data.reproductionStatus).toBe('not-attempted');
39
+ });
40
+ it('rejects an invalid category', () => {
41
+ expect(BugReportSchema.safeParse({ ...validBug, category: 'weird' }).success).toBe(false);
42
+ });
43
+ });
44
+
45
+ describe('BugFixStage order and transitions', () => {
46
+ it('lists the 10 stages in canonical order', () => {
47
+ expect(BUG_FIX_STAGE_ORDER).toEqual([
48
+ 'report',
49
+ 'discovery',
50
+ 'reproduction',
51
+ 'root-cause',
52
+ 'regression-test',
53
+ 'minimal-fix',
54
+ 'focused-verify',
55
+ 'regression-verify',
56
+ 'review',
57
+ 'completion',
58
+ ]);
59
+ });
60
+ it('only allows start from pending', () => {
61
+ expect(BUG_FIX_TRANSITIONS_BY_STATUS.pending).toEqual(['start']);
62
+ });
63
+ it('makes completed and failed terminal', () => {
64
+ expect(BUG_FIX_TRANSITIONS_BY_STATUS.completed).toEqual([]);
65
+ expect(BUG_FIX_TRANSITIONS_BY_STATUS.failed).toEqual([]);
66
+ });
67
+ });
68
+
69
+ describe('regressionTestRequiredBeforeFix invariant', () => {
70
+ it('flags an attempt to enter minimal-fix from a non-regression-test stage', () => {
71
+ expect(regressionTestRequiredBeforeFix('root-cause', 'minimal-fix')).toBe(true);
72
+ });
73
+ it('does NOT flag entering minimal-fix from regression-test', () => {
74
+ expect(regressionTestRequiredBeforeFix('regression-test', 'minimal-fix')).toBe(false);
75
+ });
76
+ it('does NOT flag other stage transitions', () => {
77
+ expect(regressionTestRequiredBeforeFix('report', 'discovery')).toBe(false);
78
+ });
79
+ });
80
+
81
+ const validRefactor = {
82
+ id: 'REFACTOR-001',
83
+ title: 'Reduce coupling in invoice module',
84
+ targetModule: 'src/invoice',
85
+ goal: 'reduce-coupling',
86
+ targetStructure: 'Extract InvoiceProcessor service.',
87
+ rationale: 'improve testability',
88
+ publicContracts: [
89
+ {
90
+ id: 'PC-1',
91
+ kind: 'function-signature',
92
+ description: 'processInvoice(paymentId): Invoice',
93
+ },
94
+ ],
95
+ candidatePatterns: [],
96
+ behaviorChangeApproved: false,
97
+ inScopePaths: ['src/invoice'],
98
+ outOfScopePaths: [],
99
+ };
100
+
101
+ describe('RefactorContractSchema', () => {
102
+ it('accepts a valid contract', () => {
103
+ expect(RefactorContractSchema.safeParse(validRefactor).success).toBe(true);
104
+ });
105
+ it('rejects behaviorChangeApproved=true without rationale', () => {
106
+ expect(
107
+ RefactorContractSchema.safeParse({
108
+ ...validRefactor,
109
+ behaviorChangeApproved: true,
110
+ }).success,
111
+ ).toBe(false);
112
+ });
113
+ it('accepts behaviorChangeApproved=true with rationale', () => {
114
+ expect(
115
+ RefactorContractSchema.safeParse({
116
+ ...validRefactor,
117
+ behaviorChangeApproved: true,
118
+ behaviorChangeRationale: 'API spec change approved by team',
119
+ }).success,
120
+ ).toBe(true);
121
+ });
122
+ it('rejects a contract with no public contracts (must have at least one)', () => {
123
+ expect(
124
+ RefactorContractSchema.safeParse({ ...validRefactor, publicContracts: [] }).success,
125
+ ).toBe(false);
126
+ });
127
+ });
128
+
129
+ describe('RefactorStage order and transitions', () => {
130
+ it('lists the 10 stages in canonical order', () => {
131
+ expect(REFACTOR_STAGE_ORDER).toEqual([
132
+ 'contract',
133
+ 'discover-deps',
134
+ 'characterization-tests',
135
+ 'target-structure',
136
+ 'identify-patterns',
137
+ 'incremental-refactor',
138
+ 'contract-validation',
139
+ 'regression-testing',
140
+ 'quality-comparison',
141
+ 'review',
142
+ ]);
143
+ });
144
+ it('only allows start from pending', () => {
145
+ expect(REFACTOR_TRANSITIONS_BY_STATUS.pending).toEqual(['start']);
146
+ });
147
+ });
148
+
149
+ describe('characterizationRequiredBeforeRefactor invariant', () => {
150
+ it('flags an attempt to enter incremental-refactor with no characterization tests', () => {
151
+ expect(
152
+ characterizationRequiredBeforeRefactor(
153
+ {
154
+ schemaVersion: 1,
155
+ runId: 'RUN-001',
156
+ refactorId: 'REFACTOR-001',
157
+ status: 'in_progress',
158
+ stage: 'target-structure',
159
+ characterizationTestPaths: [],
160
+ incrementsApplied: [],
161
+ },
162
+ 'incremental-refactor',
163
+ ),
164
+ ).toBe(true);
165
+ });
166
+ it('does NOT flag entering incremental-refactor when characterization tests exist', () => {
167
+ expect(
168
+ characterizationRequiredBeforeRefactor(
169
+ {
170
+ schemaVersion: 1,
171
+ runId: 'RUN-001',
172
+ refactorId: 'REFACTOR-001',
173
+ status: 'in_progress',
174
+ stage: 'target-structure',
175
+ characterizationTestPaths: ['tests/invoice.test.ts'],
176
+ incrementsApplied: [],
177
+ },
178
+ 'incremental-refactor',
179
+ ),
180
+ ).toBe(false);
181
+ });
182
+ });
183
+
184
+ describe('PerformanceProblemSchema', () => {
185
+ it('accepts a valid problem with baseline and target', () => {
186
+ expect(
187
+ PerformanceProblemSchema.safeParse({
188
+ id: 'PERF-001',
189
+ description: 'Invoice generation is slow.',
190
+ targetOperation: 'POST /invoices',
191
+ baseline: {
192
+ command: ['node', 'bench/invoices.js'],
193
+ metric: 'p95',
194
+ repetitions: 10,
195
+ environment: 'local-mac-m1',
196
+ },
197
+ target: { metric: 'p95', value: 200, unit: 'ms', direction: 'lower-is-better' },
198
+ bottleneckHypothesis: 'N+1 query in invoice items loader.',
199
+ }).success,
200
+ ).toBe(true);
201
+ });
202
+ it('rejects an invalid id', () => {
203
+ expect(
204
+ PerformanceProblemSchema.safeParse({
205
+ id: 'perf-1',
206
+ description: 'x',
207
+ targetOperation: 'x',
208
+ baseline: {
209
+ command: ['x'],
210
+ metric: 'p50',
211
+ repetitions: 1,
212
+ environment: 'x',
213
+ },
214
+ target: { metric: 'x', value: 1, unit: 'ms', direction: 'lower-is-better' },
215
+ bottleneckHypothesis: 'x',
216
+ }).success,
217
+ ).toBe(false);
218
+ });
219
+ });
@@ -0,0 +1,35 @@
1
+ // packages/contracts/src/maintenance/performance-baseline.ts
2
+ //
3
+ // Performance optimization contract (M9 optional extension — §3.3).
4
+ //
5
+ // Declared in 0.6.0; full /kit:optimize workflow lands in a later release.
6
+ //
7
+ // INVARIANT: performance optimization requires baseline measurements. The
8
+ // kit MUST NOT propose an optimization without an established baseline.
9
+
10
+ import { z } from 'zod';
11
+
12
+ export const PerformanceProblemSchema = z.object({
13
+ id: z.string().regex(/^[A-Z]+-[0-9]{3,}$/, 'id must match PERF-NNN'),
14
+ description: z.string().min(1),
15
+ targetOperation: z.string().min(1),
16
+ // Reproducible baseline: the command(s) to run and the metric to record.
17
+ baseline: z.object({
18
+ command: z.array(z.string().min(1)).min(1),
19
+ metric: z.enum(['p50', 'p95', 'p99', 'throughput', 'rss', 'heap', 'cpu', 'custom']),
20
+ customMetricName: z.string().optional(),
21
+ repetitions: z.number().int().min(1).max(100),
22
+ environment: z.string().min(1),
23
+ }),
24
+ // Measurable target. Must be a number with a unit.
25
+ target: z.object({
26
+ metric: z.string(),
27
+ value: z.number(),
28
+ unit: z.string(),
29
+ direction: z.enum(['lower-is-better', 'higher-is-better']),
30
+ }),
31
+ // Bottleneck hypothesis, to be validated by profiling.
32
+ bottleneckHypothesis: z.string().min(1),
33
+ });
34
+
35
+ export type PerformanceProblem = z.infer<typeof PerformanceProblemSchema>;
@@ -0,0 +1,77 @@
1
+ // packages/contracts/src/maintenance/refactor-contract.ts
2
+ //
3
+ // Refactoring contract (M9 — M9-11, M9-12).
4
+ //
5
+ // A refactor contract captures the structural-change specification: what
6
+ // is being refactored, the target structure, and the public contracts that
7
+ // MUST be preserved.
8
+ //
9
+ // INVARIANT (post-M7 roadmap §3.2): preserve observable behavior unless
10
+ // behavior changes are explicitly approved. The contract's
11
+ // `behaviorChangeApproved` field defaults to false; if any change
12
+ // modifies public behavior, it must be set to true with rationale.
13
+
14
+ import { z } from 'zod';
15
+
16
+ export const RefactorGoalSchema = z.enum([
17
+ 'reduce-coupling',
18
+ 'improve-testability',
19
+ 'improve-readability',
20
+ 'extract-module',
21
+ 'extract-component',
22
+ 'simplify-control-flow',
23
+ 'introduce-pattern',
24
+ 'remove-dead-code',
25
+ 'modernize-syntax',
26
+ 'other',
27
+ ]);
28
+
29
+ export const PublicContractSchema = z.object({
30
+ id: z.string(),
31
+ // API surface, data shape, observable side effect, etc.
32
+ kind: z.enum(['api-endpoint', 'function-signature', 'data-shape', 'cli', 'event', 'side-effect']),
33
+ description: z.string().min(1),
34
+ // The characterization test that pins this contract.
35
+ characterizationTestPath: z.string().optional(),
36
+ });
37
+
38
+ export const RefactorContractSchema = z
39
+ .object({
40
+ id: z.string().regex(/^[A-Z]+-[0-9]{3,}$/, 'id must match REFACTOR-NNN'),
41
+ title: z.string().min(1).max(200),
42
+ targetModule: z.string().min(1),
43
+ goal: RefactorGoalSchema,
44
+ targetStructure: z.string().min(1),
45
+ rationale: z.string().min(1),
46
+ // The public contracts that MUST be preserved.
47
+ publicContracts: z.array(PublicContractSchema).min(1, 'at least one public contract required'),
48
+ // Candidate design patterns (with justification per post-M7 §3.2:
49
+ // "Do not use a design pattern simply because it exists").
50
+ candidatePatterns: z
51
+ .array(
52
+ z.object({
53
+ pattern: z.string(),
54
+ whyItApplies: z.string().min(1),
55
+ whenNotToUse: z.string().min(1),
56
+ simplerAlternative: z.string().min(1),
57
+ }),
58
+ )
59
+ .default([]),
60
+ // Default false. If true, the refactor is allowed to change observable
61
+ // behavior; the rationale MUST be present.
62
+ behaviorChangeApproved: z.boolean().default(false),
63
+ behaviorChangeRationale: z.string().optional(),
64
+ // Files / modules in scope.
65
+ inScopePaths: z.array(z.string()),
66
+ // Files / modules explicitly out of scope.
67
+ outOfScopePaths: z.array(z.string()).default([]),
68
+ })
69
+ .strict()
70
+ .refine(
71
+ (c) => !c.behaviorChangeApproved || c.behaviorChangeRationale,
72
+ 'behaviorChangeApproved=true requires behaviorChangeRationale',
73
+ );
74
+
75
+ export type RefactorGoal = z.infer<typeof RefactorGoalSchema>;
76
+ export type PublicContract = z.infer<typeof PublicContractSchema>;
77
+ export type RefactorContract = z.infer<typeof RefactorContractSchema>;
@@ -0,0 +1,121 @@
1
+ // packages/contracts/src/maintenance/refactor-workflow.ts
2
+ //
3
+ // Refactor workflow state and transitions (M9 — M9-13 through M9-20).
4
+ //
5
+ // Lifecycle (post-M7 roadmap §3.2):
6
+ // Contract → Discover Deps → Characterization Tests → Target Structure →
7
+ // Identify Patterns → Incremental Refactor → Public-Contract Validation →
8
+ // Regression Testing → Quality Comparison → Review
9
+ //
10
+ // INVARIANT (post-M7 roadmap §3.2): characterization tests MUST exist
11
+ // before structural changes. The workflow enforces this: the
12
+ // `incremental-refactor` stage cannot be entered from a stage other than
13
+ // `characterization-tests` (or `target-structure` if characterization
14
+ // tests have already been recorded).
15
+
16
+ import { z } from 'zod';
17
+
18
+ export const REFACTOR_STAGE = z.enum([
19
+ 'contract',
20
+ 'discover-deps',
21
+ 'characterization-tests',
22
+ 'target-structure',
23
+ 'identify-patterns',
24
+ 'incremental-refactor',
25
+ 'contract-validation',
26
+ 'regression-testing',
27
+ 'quality-comparison',
28
+ 'review',
29
+ ]);
30
+ export type RefactorStage = z.infer<typeof REFACTOR_STAGE>;
31
+
32
+ export const REFACTOR_STATUS = z.enum(['pending', 'in_progress', 'blocked', 'completed', 'failed']);
33
+ export type RefactorStatus = z.infer<typeof REFACTOR_STATUS>;
34
+
35
+ export const REFACTOR_TRANSITION = z.enum([
36
+ 'start',
37
+ 'advance',
38
+ 'block',
39
+ 'resume',
40
+ 'complete',
41
+ 'fail',
42
+ ]);
43
+ export type RefactorTransition = z.infer<typeof REFACTOR_TRANSITION>;
44
+
45
+ export const RefactorStateSchema = z.object({
46
+ schemaVersion: z.literal(1),
47
+ runId: z.string(),
48
+ refactorId: z.string(),
49
+ status: REFACTOR_STATUS,
50
+ stage: REFACTOR_STAGE,
51
+ startedAt: z.string().optional(),
52
+ // Filled in during discover-deps:
53
+ dependencyMapPath: z.string().optional(),
54
+ // Filled in during characterization-tests:
55
+ characterizationTestPaths: z.array(z.string()).default([]),
56
+ // Filled in during incremental-refactor:
57
+ incrementsApplied: z
58
+ .array(
59
+ z.object({
60
+ id: z.string(),
61
+ summary: z.string(),
62
+ affectedFiles: z.array(z.string()),
63
+ regressionPassed: z.boolean(),
64
+ }),
65
+ )
66
+ .default([]),
67
+ // Filled in during quality-comparison:
68
+ beforeAfterReportPath: z.string().optional(),
69
+ });
70
+
71
+ export type RefactorState = z.infer<typeof RefactorStateSchema>;
72
+
73
+ export const REFACTOR_STAGE_ORDER: ReadonlyArray<RefactorStage> = [
74
+ 'contract',
75
+ 'discover-deps',
76
+ 'characterization-tests',
77
+ 'target-structure',
78
+ 'identify-patterns',
79
+ 'incremental-refactor',
80
+ 'contract-validation',
81
+ 'regression-testing',
82
+ 'quality-comparison',
83
+ 'review',
84
+ ];
85
+
86
+ export const REFACTOR_TRANSITIONS_BY_STATUS: Readonly<
87
+ Record<RefactorStatus, ReadonlyArray<RefactorTransition>>
88
+ > = {
89
+ pending: ['start'],
90
+ in_progress: ['advance', 'block', 'complete', 'fail'],
91
+ blocked: ['resume', 'fail'],
92
+ completed: [],
93
+ failed: [],
94
+ };
95
+
96
+ export const REFACTOR_TARGET_STATUS: Readonly<Record<RefactorTransition, RefactorStatus>> = {
97
+ start: 'in_progress',
98
+ advance: 'in_progress',
99
+ block: 'blocked',
100
+ resume: 'in_progress',
101
+ complete: 'completed',
102
+ fail: 'failed',
103
+ };
104
+
105
+ export const REFACTOR_COMPLETABLE_STAGES: ReadonlyArray<RefactorStage> = ['review'];
106
+
107
+ /**
108
+ * INVARIANT: the incremental-refactor stage cannot be entered until
109
+ * characterization tests have been recorded. This is the most important
110
+ * invariant in the refactor workflow — without a baseline, "preserve
111
+ * observable behavior" is meaningless.
112
+ */
113
+ export function characterizationRequiredBeforeRefactor(
114
+ state: RefactorState,
115
+ toStage: RefactorStage,
116
+ ): boolean {
117
+ if (toStage === 'incremental-refactor') {
118
+ return state.characterizationTestPaths.length === 0;
119
+ }
120
+ return false;
121
+ }