agentic-orchestrator 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/.dockerignore +24 -0
  2. package/.github/workflows/mcp-contract-validation.yml +38 -0
  3. package/Agentic-Orchestrator.iml +9 -0
  4. package/LICENSE +21 -0
  5. package/README.md +679 -0
  6. package/agentic/orchestrator/agents.yaml +14 -0
  7. package/agentic/orchestrator/gates.yaml +31 -0
  8. package/agentic/orchestrator/policy.yaml +145 -0
  9. package/agentic/orchestrator/prompts/builder.system.md +1 -0
  10. package/agentic/orchestrator/prompts/planner.system.md +15 -0
  11. package/agentic/orchestrator/prompts/qa.system.md +1 -0
  12. package/agentic/orchestrator/schemas/agents.schema.json +49 -0
  13. package/agentic/orchestrator/schemas/gates.schema.json +65 -0
  14. package/agentic/orchestrator/schemas/index.schema.json +108 -0
  15. package/agentic/orchestrator/schemas/plan.schema.json +127 -0
  16. package/agentic/orchestrator/schemas/policy.schema.json +227 -0
  17. package/agentic/orchestrator/schemas/qa_test_index.schema.json +53 -0
  18. package/agentic/orchestrator/schemas/state.schema.json +92 -0
  19. package/agentic/orchestrator/tools/catalog.json +399 -0
  20. package/agentic/orchestrator/tools/errors.schema.json +21 -0
  21. package/agentic/orchestrator/tools/protocol.json +8 -0
  22. package/agentic/orchestrator/tools/schemas/input/collisions.scan.input.schema.json +7 -0
  23. package/agentic/orchestrator/tools/schemas/input/evidence.latest.input.schema.json +15 -0
  24. package/agentic/orchestrator/tools/schemas/input/feature.delete.input.schema.json +42 -0
  25. package/agentic/orchestrator/tools/schemas/input/feature.discover_specs.input.schema.json +7 -0
  26. package/agentic/orchestrator/tools/schemas/input/feature.get_context.input.schema.json +15 -0
  27. package/agentic/orchestrator/tools/schemas/input/feature.init.input.schema.json +21 -0
  28. package/agentic/orchestrator/tools/schemas/input/feature.log_append.input.schema.json +26 -0
  29. package/agentic/orchestrator/tools/schemas/input/feature.ready_to_merge.input.schema.json +34 -0
  30. package/agentic/orchestrator/tools/schemas/input/feature.state_get.input.schema.json +15 -0
  31. package/agentic/orchestrator/tools/schemas/input/feature.state_patch.input.schema.json +28 -0
  32. package/agentic/orchestrator/tools/schemas/input/gates.list.input.schema.json +11 -0
  33. package/agentic/orchestrator/tools/schemas/input/gates.run.input.schema.json +29 -0
  34. package/agentic/orchestrator/tools/schemas/input/locks.acquire.input.schema.json +29 -0
  35. package/agentic/orchestrator/tools/schemas/input/locks.release.input.schema.json +26 -0
  36. package/agentic/orchestrator/tools/schemas/input/mutating.schema.json +14 -0
  37. package/agentic/orchestrator/tools/schemas/input/plan.get.input.schema.json +15 -0
  38. package/agentic/orchestrator/tools/schemas/input/plan.submit.input.schema.json +28 -0
  39. package/agentic/orchestrator/tools/schemas/input/plan.update.input.schema.json +29 -0
  40. package/agentic/orchestrator/tools/schemas/input/qa.test_index_get.input.schema.json +15 -0
  41. package/agentic/orchestrator/tools/schemas/input/qa.test_index_update.input.schema.json +38 -0
  42. package/agentic/orchestrator/tools/schemas/input/read.schema.json +6 -0
  43. package/agentic/orchestrator/tools/schemas/input/repo.apply_patch.input.schema.json +25 -0
  44. package/agentic/orchestrator/tools/schemas/input/repo.diff.input.schema.json +21 -0
  45. package/agentic/orchestrator/tools/schemas/input/repo.diff_bundle.input.schema.json +15 -0
  46. package/agentic/orchestrator/tools/schemas/input/repo.ensure_worktree.input.schema.json +21 -0
  47. package/agentic/orchestrator/tools/schemas/input/repo.read_file.input.schema.json +20 -0
  48. package/agentic/orchestrator/tools/schemas/input/repo.search.input.schema.json +20 -0
  49. package/agentic/orchestrator/tools/schemas/input/repo.status.input.schema.json +15 -0
  50. package/agentic/orchestrator/tools/schemas/input/report.dashboard.input.schema.json +7 -0
  51. package/agentic/orchestrator/tools/schemas/input/report.feature_summary.input.schema.json +15 -0
  52. package/agentic/orchestrator/tools/schemas/output/collisions.scan.output.schema.json +17 -0
  53. package/agentic/orchestrator/tools/schemas/output/evidence.latest.output.schema.json +20 -0
  54. package/agentic/orchestrator/tools/schemas/output/feature.delete.output.schema.json +224 -0
  55. package/agentic/orchestrator/tools/schemas/output/feature.discover_specs.output.schema.json +32 -0
  56. package/agentic/orchestrator/tools/schemas/output/feature.get_context.output.schema.json +40 -0
  57. package/agentic/orchestrator/tools/schemas/output/feature.init.output.schema.json +24 -0
  58. package/agentic/orchestrator/tools/schemas/output/feature.log_append.output.schema.json +24 -0
  59. package/agentic/orchestrator/tools/schemas/output/feature.ready_to_merge.output.schema.json +30 -0
  60. package/agentic/orchestrator/tools/schemas/output/feature.state_get.output.schema.json +18 -0
  61. package/agentic/orchestrator/tools/schemas/output/feature.state_patch.output.schema.json +24 -0
  62. package/agentic/orchestrator/tools/schemas/output/gates.list.output.schema.json +42 -0
  63. package/agentic/orchestrator/tools/schemas/output/gates.run.output.schema.json +37 -0
  64. package/agentic/orchestrator/tools/schemas/output/locks.acquire.output.schema.json +34 -0
  65. package/agentic/orchestrator/tools/schemas/output/locks.release.output.schema.json +24 -0
  66. package/agentic/orchestrator/tools/schemas/output/plan.get.output.schema.json +26 -0
  67. package/agentic/orchestrator/tools/schemas/output/plan.submit.output.schema.json +23 -0
  68. package/agentic/orchestrator/tools/schemas/output/plan.update.output.schema.json +23 -0
  69. package/agentic/orchestrator/tools/schemas/output/qa.test_index_get.output.schema.json +22 -0
  70. package/agentic/orchestrator/tools/schemas/output/qa.test_index_update.output.schema.json +19 -0
  71. package/agentic/orchestrator/tools/schemas/output/repo.apply_patch.output.schema.json +33 -0
  72. package/agentic/orchestrator/tools/schemas/output/repo.diff.output.schema.json +19 -0
  73. package/agentic/orchestrator/tools/schemas/output/repo.diff_bundle.output.schema.json +32 -0
  74. package/agentic/orchestrator/tools/schemas/output/repo.ensure_worktree.output.schema.json +29 -0
  75. package/agentic/orchestrator/tools/schemas/output/repo.read_file.output.schema.json +24 -0
  76. package/agentic/orchestrator/tools/schemas/output/repo.search.output.schema.json +26 -0
  77. package/agentic/orchestrator/tools/schemas/output/repo.status.output.schema.json +27 -0
  78. package/agentic/orchestrator/tools/schemas/output/report.dashboard.output.schema.json +21 -0
  79. package/agentic/orchestrator/tools/schemas/output/report.feature_summary.output.schema.json +36 -0
  80. package/agentic/orchestrator/tools/schemas/output/standard_success.schema.json +6 -0
  81. package/agentic/orchestrator/tools.md +32 -0
  82. package/apps/control-plane/project.json +39 -0
  83. package/apps/control-plane/scripts/validate-architecture-rules.mjs +170 -0
  84. package/apps/control-plane/scripts/validate-docker-mcp-contract.mjs +84 -0
  85. package/apps/control-plane/scripts/validate-mcp-contracts.ts +61 -0
  86. package/apps/control-plane/src/application/services/collision-queue-service.ts +227 -0
  87. package/apps/control-plane/src/application/services/feature-deletion-service.ts +459 -0
  88. package/apps/control-plane/src/application/services/feature-lifecycle-service.ts +177 -0
  89. package/apps/control-plane/src/application/services/feature-state-service.ts +125 -0
  90. package/apps/control-plane/src/application/services/gate-service.ts +232 -0
  91. package/apps/control-plane/src/application/services/lock-service.ts +298 -0
  92. package/apps/control-plane/src/application/services/merge-service.ts +246 -0
  93. package/apps/control-plane/src/application/services/patch-service.ts +259 -0
  94. package/apps/control-plane/src/application/services/plan-service.ts +302 -0
  95. package/apps/control-plane/src/application/services/qa-index-service.ts +98 -0
  96. package/apps/control-plane/src/application/services/reporting-service.ts +120 -0
  97. package/apps/control-plane/src/application/services/run-lease-service.ts +340 -0
  98. package/apps/control-plane/src/application/tools/tool-metadata.ts +56 -0
  99. package/apps/control-plane/src/application/tools/tool-router.ts +43 -0
  100. package/apps/control-plane/src/cli/aop.ts +31 -0
  101. package/apps/control-plane/src/cli/cli-argument-parser.ts +116 -0
  102. package/apps/control-plane/src/cli/delete-command-handler.ts +90 -0
  103. package/apps/control-plane/src/cli/io.ts +14 -0
  104. package/apps/control-plane/src/cli/resume-command-handler.ts +228 -0
  105. package/apps/control-plane/src/cli/run-command-handler.ts +57 -0
  106. package/apps/control-plane/src/cli/spec-ingestion-service.ts +88 -0
  107. package/apps/control-plane/src/cli/spec-input-resolver.ts +95 -0
  108. package/apps/control-plane/src/cli/spec-utils.ts +40 -0
  109. package/apps/control-plane/src/cli/status-command-handler.ts +17 -0
  110. package/apps/control-plane/src/cli/stop-command-handler.ts +5 -0
  111. package/apps/control-plane/src/cli/tooling.ts +36 -0
  112. package/apps/control-plane/src/cli/types.ts +34 -0
  113. package/apps/control-plane/src/core/collisions.ts +121 -0
  114. package/apps/control-plane/src/core/constants.ts +72 -0
  115. package/apps/control-plane/src/core/error-codes.ts +54 -0
  116. package/apps/control-plane/src/core/frontmatter.ts +42 -0
  117. package/apps/control-plane/src/core/fs.ts +173 -0
  118. package/apps/control-plane/src/core/gates.ts +361 -0
  119. package/apps/control-plane/src/core/git.ts +115 -0
  120. package/apps/control-plane/src/core/kernel.ts +1077 -0
  121. package/apps/control-plane/src/core/patch.ts +152 -0
  122. package/apps/control-plane/src/core/path-layout.ts +113 -0
  123. package/apps/control-plane/src/core/path-rules.ts +71 -0
  124. package/apps/control-plane/src/core/qa-index.ts +179 -0
  125. package/apps/control-plane/src/core/response.ts +62 -0
  126. package/apps/control-plane/src/core/runtime-sessions.ts +20 -0
  127. package/apps/control-plane/src/core/schemas.ts +125 -0
  128. package/apps/control-plane/src/index.ts +21 -0
  129. package/apps/control-plane/src/interfaces/cli/bootstrap.ts +100 -0
  130. package/apps/control-plane/src/mcp/kernel-tool-executor.ts +39 -0
  131. package/apps/control-plane/src/mcp/mcp-server-adapter.ts +74 -0
  132. package/apps/control-plane/src/mcp/operation-ledger.ts +108 -0
  133. package/apps/control-plane/src/mcp/protocol-contract.ts +9 -0
  134. package/apps/control-plane/src/mcp/runtime-factory.ts +105 -0
  135. package/apps/control-plane/src/mcp/runtime-types.ts +44 -0
  136. package/apps/control-plane/src/mcp/token-auth-verifier.ts +63 -0
  137. package/apps/control-plane/src/mcp/token-claims-validator.ts +72 -0
  138. package/apps/control-plane/src/mcp/token-codec.ts +62 -0
  139. package/apps/control-plane/src/mcp/tool-authorizer.ts +43 -0
  140. package/apps/control-plane/src/mcp/tool-client.ts +78 -0
  141. package/apps/control-plane/src/mcp/tool-contract-validator.ts +83 -0
  142. package/apps/control-plane/src/mcp/tool-registry-loader.ts +135 -0
  143. package/apps/control-plane/src/mcp/tool-runtime.ts +336 -0
  144. package/apps/control-plane/src/mcp/tools-markdown-generator.ts +26 -0
  145. package/apps/control-plane/src/mcp/transport-types.ts +16 -0
  146. package/apps/control-plane/src/mcp/types.ts +2 -0
  147. package/apps/control-plane/src/providers/providers.ts +177 -0
  148. package/apps/control-plane/src/supervisor/build-wave-executor.ts +55 -0
  149. package/apps/control-plane/src/supervisor/lease-heartbeat-service.ts +22 -0
  150. package/apps/control-plane/src/supervisor/planning-wave-executor.ts +316 -0
  151. package/apps/control-plane/src/supervisor/prompt-bundle-loader.ts +62 -0
  152. package/apps/control-plane/src/supervisor/qa-wave-executor.ts +99 -0
  153. package/apps/control-plane/src/supervisor/run-coordinator.ts +224 -0
  154. package/apps/control-plane/src/supervisor/runtime.ts +347 -0
  155. package/apps/control-plane/src/supervisor/session-orchestrator.ts +268 -0
  156. package/apps/control-plane/src/supervisor/types.ts +149 -0
  157. package/apps/control-plane/src/supervisor/worker-decision-loop.ts +299 -0
  158. package/apps/control-plane/test/aop.spec.ts +101 -0
  159. package/apps/control-plane/test/cli-helpers.spec.ts +102 -0
  160. package/apps/control-plane/test/cli.spec.ts +12 -0
  161. package/apps/control-plane/test/cli.unit.spec.ts +609 -0
  162. package/apps/control-plane/test/collision-queue.spec.ts +158 -0
  163. package/apps/control-plane/test/collisions.spec.ts +138 -0
  164. package/apps/control-plane/test/core-utils.spec.ts +102 -0
  165. package/apps/control-plane/test/delete-command-handler.spec.ts +202 -0
  166. package/apps/control-plane/test/epoch-tracking.spec.ts +121 -0
  167. package/apps/control-plane/test/gates.spec.ts +452 -0
  168. package/apps/control-plane/test/helpers.ts +68 -0
  169. package/apps/control-plane/test/index.spec.ts +18 -0
  170. package/apps/control-plane/test/kernel-collision-replay.spec.ts +222 -0
  171. package/apps/control-plane/test/kernel.branches.spec.ts +321 -0
  172. package/apps/control-plane/test/kernel.coverage.spec.ts +408 -0
  173. package/apps/control-plane/test/kernel.spec.ts +369 -0
  174. package/apps/control-plane/test/mcp-helpers.spec.ts +195 -0
  175. package/apps/control-plane/test/mcp.spec.ts +776 -0
  176. package/apps/control-plane/test/merge-service.spec.ts +357 -0
  177. package/apps/control-plane/test/plan-service.spec.ts +195 -0
  178. package/apps/control-plane/test/planning-wave-executor.spec.ts +229 -0
  179. package/apps/control-plane/test/providers.spec.ts +168 -0
  180. package/apps/control-plane/test/qa-index-service.spec.ts +187 -0
  181. package/apps/control-plane/test/qa-index.spec.ts +317 -0
  182. package/apps/control-plane/test/response.spec.ts +55 -0
  183. package/apps/control-plane/test/run-coordinator.spec.ts +334 -0
  184. package/apps/control-plane/test/schema-date-time.spec.ts +170 -0
  185. package/apps/control-plane/test/service-retry-paths.spec.ts +305 -0
  186. package/apps/control-plane/test/services.spec.ts +693 -0
  187. package/apps/control-plane/test/spec-input-resolver.spec.ts +76 -0
  188. package/apps/control-plane/test/supervisor-collaborators.spec.ts +201 -0
  189. package/apps/control-plane/test/supervisor.calltool.spec.ts +120 -0
  190. package/apps/control-plane/test/supervisor.spec.ts +415 -0
  191. package/apps/control-plane/test/supervisor.unit.spec.ts +522 -0
  192. package/apps/control-plane/test/token-auth-verifier.spec.ts +111 -0
  193. package/apps/control-plane/test/tool-registry-loader.spec.ts +268 -0
  194. package/apps/control-plane/test/tool-runtime.spec.ts +294 -0
  195. package/apps/control-plane/test/worker-decision-loop.spec.ts +587 -0
  196. package/apps/control-plane/tsconfig.build.json +17 -0
  197. package/apps/control-plane/tsconfig.json +11 -0
  198. package/apps/control-plane/vitest.config.ts +28 -0
  199. package/dist/apps/control-plane/application/services/collision-queue-service.d.ts +69 -0
  200. package/dist/apps/control-plane/application/services/collision-queue-service.js +158 -0
  201. package/dist/apps/control-plane/application/services/collision-queue-service.js.map +1 -0
  202. package/dist/apps/control-plane/application/services/feature-deletion-service.d.ts +79 -0
  203. package/dist/apps/control-plane/application/services/feature-deletion-service.js +336 -0
  204. package/dist/apps/control-plane/application/services/feature-deletion-service.js.map +1 -0
  205. package/dist/apps/control-plane/application/services/feature-lifecycle-service.d.ts +81 -0
  206. package/dist/apps/control-plane/application/services/feature-lifecycle-service.js +117 -0
  207. package/dist/apps/control-plane/application/services/feature-lifecycle-service.js.map +1 -0
  208. package/dist/apps/control-plane/application/services/feature-state-service.d.ts +34 -0
  209. package/dist/apps/control-plane/application/services/feature-state-service.js +90 -0
  210. package/dist/apps/control-plane/application/services/feature-state-service.js.map +1 -0
  211. package/dist/apps/control-plane/application/services/gate-service.d.ts +46 -0
  212. package/dist/apps/control-plane/application/services/gate-service.js +160 -0
  213. package/dist/apps/control-plane/application/services/gate-service.js.map +1 -0
  214. package/dist/apps/control-plane/application/services/lock-service.d.ts +56 -0
  215. package/dist/apps/control-plane/application/services/lock-service.js +242 -0
  216. package/dist/apps/control-plane/application/services/lock-service.js.map +1 -0
  217. package/dist/apps/control-plane/application/services/merge-service.d.ts +33 -0
  218. package/dist/apps/control-plane/application/services/merge-service.js +194 -0
  219. package/dist/apps/control-plane/application/services/merge-service.js.map +1 -0
  220. package/dist/apps/control-plane/application/services/patch-service.d.ts +39 -0
  221. package/dist/apps/control-plane/application/services/patch-service.js +189 -0
  222. package/dist/apps/control-plane/application/services/patch-service.js.map +1 -0
  223. package/dist/apps/control-plane/application/services/plan-service.d.ts +60 -0
  224. package/dist/apps/control-plane/application/services/plan-service.js +234 -0
  225. package/dist/apps/control-plane/application/services/plan-service.js.map +1 -0
  226. package/dist/apps/control-plane/application/services/qa-index-service.d.ts +26 -0
  227. package/dist/apps/control-plane/application/services/qa-index-service.js +66 -0
  228. package/dist/apps/control-plane/application/services/qa-index-service.js.map +1 -0
  229. package/dist/apps/control-plane/application/services/reporting-service.d.ts +47 -0
  230. package/dist/apps/control-plane/application/services/reporting-service.js +90 -0
  231. package/dist/apps/control-plane/application/services/reporting-service.js.map +1 -0
  232. package/dist/apps/control-plane/application/services/run-lease-service.d.ts +74 -0
  233. package/dist/apps/control-plane/application/services/run-lease-service.js +263 -0
  234. package/dist/apps/control-plane/application/services/run-lease-service.js.map +1 -0
  235. package/dist/apps/control-plane/application/tools/tool-metadata.d.ts +8 -0
  236. package/dist/apps/control-plane/application/tools/tool-metadata.js +37 -0
  237. package/dist/apps/control-plane/application/tools/tool-metadata.js.map +1 -0
  238. package/dist/apps/control-plane/application/tools/tool-router.d.ts +16 -0
  239. package/dist/apps/control-plane/application/tools/tool-router.js +25 -0
  240. package/dist/apps/control-plane/application/tools/tool-router.js.map +1 -0
  241. package/dist/apps/control-plane/cli/aop.d.ts +5 -0
  242. package/dist/apps/control-plane/cli/aop.js +19 -0
  243. package/dist/apps/control-plane/cli/aop.js.map +1 -0
  244. package/dist/apps/control-plane/cli/cli-argument-parser.d.ts +5 -0
  245. package/dist/apps/control-plane/cli/cli-argument-parser.js +109 -0
  246. package/dist/apps/control-plane/cli/cli-argument-parser.js.map +1 -0
  247. package/dist/apps/control-plane/cli/delete-command-handler.d.ts +8 -0
  248. package/dist/apps/control-plane/cli/delete-command-handler.js +77 -0
  249. package/dist/apps/control-plane/cli/delete-command-handler.js.map +1 -0
  250. package/dist/apps/control-plane/cli/io.d.ts +2 -0
  251. package/dist/apps/control-plane/cli/io.js +14 -0
  252. package/dist/apps/control-plane/cli/io.js.map +1 -0
  253. package/dist/apps/control-plane/cli/resume-command-handler.d.ts +17 -0
  254. package/dist/apps/control-plane/cli/resume-command-handler.js +178 -0
  255. package/dist/apps/control-plane/cli/resume-command-handler.js.map +1 -0
  256. package/dist/apps/control-plane/cli/run-command-handler.d.ts +15 -0
  257. package/dist/apps/control-plane/cli/run-command-handler.js +39 -0
  258. package/dist/apps/control-plane/cli/run-command-handler.js.map +1 -0
  259. package/dist/apps/control-plane/cli/spec-ingestion-service.d.ts +8 -0
  260. package/dist/apps/control-plane/cli/spec-ingestion-service.js +77 -0
  261. package/dist/apps/control-plane/cli/spec-ingestion-service.js.map +1 -0
  262. package/dist/apps/control-plane/cli/spec-input-resolver.d.ts +9 -0
  263. package/dist/apps/control-plane/cli/spec-input-resolver.js +81 -0
  264. package/dist/apps/control-plane/cli/spec-input-resolver.js.map +1 -0
  265. package/dist/apps/control-plane/cli/spec-utils.d.ts +3 -0
  266. package/dist/apps/control-plane/cli/spec-utils.js +36 -0
  267. package/dist/apps/control-plane/cli/spec-utils.js.map +1 -0
  268. package/dist/apps/control-plane/cli/status-command-handler.d.ts +7 -0
  269. package/dist/apps/control-plane/cli/status-command-handler.js +14 -0
  270. package/dist/apps/control-plane/cli/status-command-handler.js.map +1 -0
  271. package/dist/apps/control-plane/cli/stop-command-handler.d.ts +3 -0
  272. package/dist/apps/control-plane/cli/stop-command-handler.js +6 -0
  273. package/dist/apps/control-plane/cli/stop-command-handler.js.map +1 -0
  274. package/dist/apps/control-plane/cli/tooling.d.ts +4 -0
  275. package/dist/apps/control-plane/cli/tooling.js +24 -0
  276. package/dist/apps/control-plane/cli/tooling.js.map +1 -0
  277. package/dist/apps/control-plane/cli/types.d.ts +31 -0
  278. package/dist/apps/control-plane/cli/types.js +2 -0
  279. package/dist/apps/control-plane/cli/types.js.map +1 -0
  280. package/dist/apps/control-plane/core/collisions.d.ts +39 -0
  281. package/dist/apps/control-plane/core/collisions.js +78 -0
  282. package/dist/apps/control-plane/core/collisions.js.map +1 -0
  283. package/dist/apps/control-plane/core/constants.d.ts +64 -0
  284. package/dist/apps/control-plane/core/constants.js +64 -0
  285. package/dist/apps/control-plane/core/constants.js.map +1 -0
  286. package/dist/apps/control-plane/core/error-codes.d.ts +50 -0
  287. package/dist/apps/control-plane/core/error-codes.js +52 -0
  288. package/dist/apps/control-plane/core/error-codes.js.map +1 -0
  289. package/dist/apps/control-plane/core/frontmatter.d.ts +11 -0
  290. package/dist/apps/control-plane/core/frontmatter.js +30 -0
  291. package/dist/apps/control-plane/core/frontmatter.js.map +1 -0
  292. package/dist/apps/control-plane/core/fs.d.ts +33 -0
  293. package/dist/apps/control-plane/core/fs.js +134 -0
  294. package/dist/apps/control-plane/core/fs.js.map +1 -0
  295. package/dist/apps/control-plane/core/gates.d.ts +88 -0
  296. package/dist/apps/control-plane/core/gates.js +229 -0
  297. package/dist/apps/control-plane/core/gates.js.map +1 -0
  298. package/dist/apps/control-plane/core/git.d.ts +31 -0
  299. package/dist/apps/control-plane/core/git.js +79 -0
  300. package/dist/apps/control-plane/core/git.js.map +1 -0
  301. package/dist/apps/control-plane/core/kernel.d.ts +445 -0
  302. package/dist/apps/control-plane/core/kernel.js +805 -0
  303. package/dist/apps/control-plane/core/kernel.js.map +1 -0
  304. package/dist/apps/control-plane/core/patch.d.ts +23 -0
  305. package/dist/apps/control-plane/core/patch.js +118 -0
  306. package/dist/apps/control-plane/core/patch.js.map +1 -0
  307. package/dist/apps/control-plane/core/path-layout.d.ts +23 -0
  308. package/dist/apps/control-plane/core/path-layout.js +90 -0
  309. package/dist/apps/control-plane/core/path-layout.js.map +1 -0
  310. package/dist/apps/control-plane/core/path-rules.d.ts +13 -0
  311. package/dist/apps/control-plane/core/path-rules.js +52 -0
  312. package/dist/apps/control-plane/core/path-rules.js.map +1 -0
  313. package/dist/apps/control-plane/core/qa-index.d.ts +53 -0
  314. package/dist/apps/control-plane/core/qa-index.js +112 -0
  315. package/dist/apps/control-plane/core/qa-index.js.map +1 -0
  316. package/dist/apps/control-plane/core/response.d.ts +19 -0
  317. package/dist/apps/control-plane/core/response.js +34 -0
  318. package/dist/apps/control-plane/core/response.js.map +1 -0
  319. package/dist/apps/control-plane/core/runtime-sessions.d.ts +19 -0
  320. package/dist/apps/control-plane/core/runtime-sessions.js +2 -0
  321. package/dist/apps/control-plane/core/runtime-sessions.js.map +1 -0
  322. package/dist/apps/control-plane/core/schemas.d.ts +23 -0
  323. package/dist/apps/control-plane/core/schemas.js +80 -0
  324. package/dist/apps/control-plane/core/schemas.js.map +1 -0
  325. package/dist/apps/control-plane/index.d.ts +11 -0
  326. package/dist/apps/control-plane/index.js +9 -0
  327. package/dist/apps/control-plane/index.js.map +1 -0
  328. package/dist/apps/control-plane/interfaces/cli/bootstrap.d.ts +2 -0
  329. package/dist/apps/control-plane/interfaces/cli/bootstrap.js +86 -0
  330. package/dist/apps/control-plane/interfaces/cli/bootstrap.js.map +1 -0
  331. package/dist/apps/control-plane/mcp/kernel-tool-executor.d.ts +14 -0
  332. package/dist/apps/control-plane/mcp/kernel-tool-executor.js +26 -0
  333. package/dist/apps/control-plane/mcp/kernel-tool-executor.js.map +1 -0
  334. package/dist/apps/control-plane/mcp/mcp-server-adapter.d.ts +19 -0
  335. package/dist/apps/control-plane/mcp/mcp-server-adapter.js +55 -0
  336. package/dist/apps/control-plane/mcp/mcp-server-adapter.js.map +1 -0
  337. package/dist/apps/control-plane/mcp/operation-ledger.d.ts +21 -0
  338. package/dist/apps/control-plane/mcp/operation-ledger.js +75 -0
  339. package/dist/apps/control-plane/mcp/operation-ledger.js.map +1 -0
  340. package/dist/apps/control-plane/mcp/protocol-contract.d.ts +8 -0
  341. package/dist/apps/control-plane/mcp/protocol-contract.js +9 -0
  342. package/dist/apps/control-plane/mcp/protocol-contract.js.map +1 -0
  343. package/dist/apps/control-plane/mcp/runtime-factory.d.ts +38 -0
  344. package/dist/apps/control-plane/mcp/runtime-factory.js +71 -0
  345. package/dist/apps/control-plane/mcp/runtime-factory.js.map +1 -0
  346. package/dist/apps/control-plane/mcp/runtime-types.d.ts +40 -0
  347. package/dist/apps/control-plane/mcp/runtime-types.js +2 -0
  348. package/dist/apps/control-plane/mcp/runtime-types.js.map +1 -0
  349. package/dist/apps/control-plane/mcp/token-auth-verifier.d.ts +24 -0
  350. package/dist/apps/control-plane/mcp/token-auth-verifier.js +45 -0
  351. package/dist/apps/control-plane/mcp/token-auth-verifier.js.map +1 -0
  352. package/dist/apps/control-plane/mcp/token-claims-validator.d.ts +9 -0
  353. package/dist/apps/control-plane/mcp/token-claims-validator.js +62 -0
  354. package/dist/apps/control-plane/mcp/token-claims-validator.js.map +1 -0
  355. package/dist/apps/control-plane/mcp/token-codec.d.ts +11 -0
  356. package/dist/apps/control-plane/mcp/token-codec.js +46 -0
  357. package/dist/apps/control-plane/mcp/token-codec.js.map +1 -0
  358. package/dist/apps/control-plane/mcp/tool-authorizer.d.ts +8 -0
  359. package/dist/apps/control-plane/mcp/tool-authorizer.js +36 -0
  360. package/dist/apps/control-plane/mcp/tool-authorizer.js.map +1 -0
  361. package/dist/apps/control-plane/mcp/tool-client.d.ts +30 -0
  362. package/dist/apps/control-plane/mcp/tool-client.js +50 -0
  363. package/dist/apps/control-plane/mcp/tool-client.js.map +1 -0
  364. package/dist/apps/control-plane/mcp/tool-contract-validator.d.ts +29 -0
  365. package/dist/apps/control-plane/mcp/tool-contract-validator.js +61 -0
  366. package/dist/apps/control-plane/mcp/tool-contract-validator.js.map +1 -0
  367. package/dist/apps/control-plane/mcp/tool-registry-loader.d.ts +15 -0
  368. package/dist/apps/control-plane/mcp/tool-registry-loader.js +109 -0
  369. package/dist/apps/control-plane/mcp/tool-registry-loader.js.map +1 -0
  370. package/dist/apps/control-plane/mcp/tool-runtime.d.ts +34 -0
  371. package/dist/apps/control-plane/mcp/tool-runtime.js +252 -0
  372. package/dist/apps/control-plane/mcp/tool-runtime.js.map +1 -0
  373. package/dist/apps/control-plane/mcp/tools-markdown-generator.d.ts +7 -0
  374. package/dist/apps/control-plane/mcp/tools-markdown-generator.js +22 -0
  375. package/dist/apps/control-plane/mcp/tools-markdown-generator.js.map +1 -0
  376. package/dist/apps/control-plane/mcp/transport-types.d.ts +14 -0
  377. package/dist/apps/control-plane/mcp/transport-types.js +2 -0
  378. package/dist/apps/control-plane/mcp/transport-types.js.map +1 -0
  379. package/dist/apps/control-plane/mcp/types.d.ts +2 -0
  380. package/dist/apps/control-plane/mcp/types.js +3 -0
  381. package/dist/apps/control-plane/mcp/types.js.map +1 -0
  382. package/dist/apps/control-plane/providers/providers.d.ts +72 -0
  383. package/dist/apps/control-plane/providers/providers.js +94 -0
  384. package/dist/apps/control-plane/providers/providers.js.map +1 -0
  385. package/dist/apps/control-plane/supervisor/build-wave-executor.d.ts +13 -0
  386. package/dist/apps/control-plane/supervisor/build-wave-executor.js +40 -0
  387. package/dist/apps/control-plane/supervisor/build-wave-executor.js.map +1 -0
  388. package/dist/apps/control-plane/supervisor/lease-heartbeat-service.d.ts +12 -0
  389. package/dist/apps/control-plane/supervisor/lease-heartbeat-service.js +14 -0
  390. package/dist/apps/control-plane/supervisor/lease-heartbeat-service.js.map +1 -0
  391. package/dist/apps/control-plane/supervisor/planning-wave-executor.d.ts +19 -0
  392. package/dist/apps/control-plane/supervisor/planning-wave-executor.js +249 -0
  393. package/dist/apps/control-plane/supervisor/planning-wave-executor.js.map +1 -0
  394. package/dist/apps/control-plane/supervisor/prompt-bundle-loader.d.ts +9 -0
  395. package/dist/apps/control-plane/supervisor/prompt-bundle-loader.js +53 -0
  396. package/dist/apps/control-plane/supervisor/prompt-bundle-loader.js.map +1 -0
  397. package/dist/apps/control-plane/supervisor/qa-wave-executor.d.ts +24 -0
  398. package/dist/apps/control-plane/supervisor/qa-wave-executor.js +70 -0
  399. package/dist/apps/control-plane/supervisor/qa-wave-executor.js.map +1 -0
  400. package/dist/apps/control-plane/supervisor/run-coordinator.d.ts +49 -0
  401. package/dist/apps/control-plane/supervisor/run-coordinator.js +162 -0
  402. package/dist/apps/control-plane/supervisor/run-coordinator.js.map +1 -0
  403. package/dist/apps/control-plane/supervisor/runtime.d.ts +58 -0
  404. package/dist/apps/control-plane/supervisor/runtime.js +270 -0
  405. package/dist/apps/control-plane/supervisor/runtime.js.map +1 -0
  406. package/dist/apps/control-plane/supervisor/session-orchestrator.d.ts +29 -0
  407. package/dist/apps/control-plane/supervisor/session-orchestrator.js +211 -0
  408. package/dist/apps/control-plane/supervisor/session-orchestrator.js.map +1 -0
  409. package/dist/apps/control-plane/supervisor/types.d.ts +148 -0
  410. package/dist/apps/control-plane/supervisor/types.js +2 -0
  411. package/dist/apps/control-plane/supervisor/types.js.map +1 -0
  412. package/dist/apps/control-plane/supervisor/worker-decision-loop.d.ts +37 -0
  413. package/dist/apps/control-plane/supervisor/worker-decision-loop.js +236 -0
  414. package/dist/apps/control-plane/supervisor/worker-decision-loop.js.map +1 -0
  415. package/docker/mcp.Dockerfile +14 -0
  416. package/docker/mcp.compose.yaml +15 -0
  417. package/docker/mcp.entrypoint.sh +17 -0
  418. package/eslint.config.mjs +93 -0
  419. package/example-configurations/README.md +26 -0
  420. package/example-configurations/java/agents.yaml +14 -0
  421. package/example-configurations/java/gates.yaml +29 -0
  422. package/example-configurations/java/policy.yaml +148 -0
  423. package/example-configurations/node/agents.yaml +14 -0
  424. package/example-configurations/node/gates.yaml +32 -0
  425. package/example-configurations/node/policy.yaml +143 -0
  426. package/nx.json +16 -0
  427. package/package.json +39 -0
  428. package/prompts/vitest-testing-standards.instructions.md +204 -0
  429. package/scripts/dev-shell-env.sh +7 -0
  430. package/scripts/nx-safe.mjs +33 -0
  431. package/spec-files/agentic_orchestrator_cli_delete_command_spec.md +310 -0
  432. package/spec-files/agentic_orchestrator_dot_aop_generated_artifacts_spec.md +211 -0
  433. package/spec-files/agentic_orchestrator_mcp_formalization_spec.md +379 -0
  434. package/spec-files/agentic_orchestrator_oop_refactor_spec.md +415 -0
  435. package/spec-files/agentic_orchestrator_single_global_orchestrator_spec.md +265 -0
  436. package/spec-files/agentic_orchestrator_spec.md +1334 -0
  437. package/spec-files/progress.md +452 -0
  438. package/tsconfig.base.json +15 -0
  439. package/tsconfig.json +11 -0
@@ -0,0 +1,81 @@
1
+ type AnyRecord = Record<string, any>;
2
+ type FeatureContext = {
3
+ actorType: string;
4
+ actorId: string;
5
+ };
6
+ export interface FeatureLifecycleServicePort {
7
+ getRepoRoot(): string;
8
+ getFeaturesDir(): string;
9
+ featurePath(featureId: string): string;
10
+ statePath(featureId: string): string;
11
+ qaIndexPath(featureId: string): string;
12
+ decisionsPath(featureId: string): string;
13
+ specPath(featureId: string): string;
14
+ ensureFeatureLayout(featureId: string): Promise<void>;
15
+ repoEnsureWorktree(featureId: string): Promise<{
16
+ data: {
17
+ worktree_path_abs: string;
18
+ };
19
+ }>;
20
+ makeDefaultState(featureId: string, branch: string, worktreePath: string): AnyRecord;
21
+ writeState(featureId: string, frontMatter: AnyRecord, body?: string): Promise<void>;
22
+ withIndexLock<T>(operation: () => Promise<T>): Promise<T>;
23
+ readIndex(): Promise<AnyRecord>;
24
+ writeIndex(index: AnyRecord): Promise<void>;
25
+ featureStateGet(featureId: string): Promise<{
26
+ data: {
27
+ front_matter: AnyRecord;
28
+ body: string;
29
+ };
30
+ }>;
31
+ planGet(featureId: string): Promise<{
32
+ data: {
33
+ plan: unknown;
34
+ };
35
+ }>;
36
+ qaTestIndexGet(featureId: string): Promise<{
37
+ data: unknown;
38
+ }>;
39
+ evidenceLatest(featureId: string): Promise<{
40
+ data: {
41
+ latest?: unknown | null;
42
+ };
43
+ }>;
44
+ }
45
+ export declare class FeatureLifecycleService {
46
+ private readonly port;
47
+ constructor(port: FeatureLifecycleServicePort);
48
+ featureDiscoverSpecs(): Promise<{
49
+ data: {
50
+ specs: Array<{
51
+ feature_id: string;
52
+ spec_path: string;
53
+ }>;
54
+ };
55
+ }>;
56
+ featureInit(featureId: string | null): Promise<{
57
+ data: {
58
+ feature_id: string | null;
59
+ initialized: boolean;
60
+ worktree_path: string;
61
+ };
62
+ }>;
63
+ featureGetContext(featureId: string): Promise<{
64
+ data: {
65
+ feature_id: string;
66
+ spec: string;
67
+ state: unknown;
68
+ plan: unknown;
69
+ qa_test_index: unknown;
70
+ latest_evidence: unknown;
71
+ };
72
+ }>;
73
+ featureLogAppend(featureId: string, note: string, context: FeatureContext): Promise<{
74
+ data: {
75
+ feature_id: string;
76
+ appended: boolean;
77
+ log_path: string;
78
+ };
79
+ }>;
80
+ }
81
+ export {};
@@ -0,0 +1,117 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { atomicWriteJson, nowIso, pathExists, stableHash } from '../../core/fs.js';
4
+ import { fail } from '../../core/response.js';
5
+ import { ERROR_CODES } from '../../core/error-codes.js';
6
+ function normalizeSet(array) {
7
+ return [...new Set(array)].sort((a, b) => a.localeCompare(b));
8
+ }
9
+ function normalizeRepoPathForState(repoRoot, absolutePath) {
10
+ const relative = path.relative(repoRoot, absolutePath).replaceAll('\\\\', '/');
11
+ if (!relative || relative === '.') {
12
+ return '.';
13
+ }
14
+ return relative;
15
+ }
16
+ export class FeatureLifecycleService {
17
+ port;
18
+ constructor(port) {
19
+ this.port = port;
20
+ }
21
+ async featureDiscoverSpecs() {
22
+ const discovered = [];
23
+ const repoRoot = this.port.getRepoRoot();
24
+ const featuresDir = this.port.getFeaturesDir();
25
+ if (!(await pathExists(featuresDir))) {
26
+ return { data: { specs: [] } };
27
+ }
28
+ const entries = await fs.readdir(featuresDir, { withFileTypes: true });
29
+ for (const entry of entries) {
30
+ if (!entry.isDirectory()) {
31
+ continue;
32
+ }
33
+ const specPath = path.join(featuresDir, entry.name, 'spec.md');
34
+ if (await pathExists(specPath)) {
35
+ discovered.push({
36
+ feature_id: entry.name,
37
+ spec_path: normalizeRepoPathForState(repoRoot, specPath)
38
+ });
39
+ }
40
+ }
41
+ discovered.sort((a, b) => a.feature_id.localeCompare(b.feature_id));
42
+ return { data: { specs: discovered } };
43
+ }
44
+ async featureInit(featureId) {
45
+ if (!featureId) {
46
+ throw {
47
+ normalizedResponse: fail(ERROR_CODES.INVALID_ARGUMENT, 'feature_id is required', {
48
+ retryable: false,
49
+ requires_human: true
50
+ })
51
+ };
52
+ }
53
+ const repoRoot = this.port.getRepoRoot();
54
+ await this.port.ensureFeatureLayout(featureId);
55
+ const worktreeResult = await this.port.repoEnsureWorktree(featureId);
56
+ const stateFileExists = await pathExists(this.port.statePath(featureId));
57
+ if (!stateFileExists) {
58
+ const defaultState = this.port.makeDefaultState(featureId, featureId, worktreeResult.data.worktree_path_abs);
59
+ await this.port.writeState(featureId, defaultState, '## Activity\n\nInitialized feature.\n');
60
+ }
61
+ const qaIndexExists = await pathExists(this.port.qaIndexPath(featureId));
62
+ if (!qaIndexExists) {
63
+ await atomicWriteJson(this.port.qaIndexPath(featureId), {
64
+ feature_id: featureId,
65
+ version: 1,
66
+ source_diff_ref: stableHash('empty'),
67
+ items: []
68
+ });
69
+ }
70
+ await this.port.withIndexLock(async () => {
71
+ const index = await this.port.readIndex();
72
+ index.active = normalizeSet([...(index.active ?? []), featureId]);
73
+ index.blocked = normalizeSet((index.blocked ?? []).filter((id) => id !== featureId));
74
+ index.version += 1;
75
+ index.updated_at = nowIso();
76
+ await this.port.writeIndex(index);
77
+ });
78
+ return {
79
+ data: {
80
+ feature_id: featureId,
81
+ initialized: true,
82
+ worktree_path: normalizeRepoPathForState(repoRoot, worktreeResult.data.worktree_path_abs)
83
+ }
84
+ };
85
+ }
86
+ async featureGetContext(featureId) {
87
+ const state = await this.port.featureStateGet(featureId);
88
+ const plan = await this.port.planGet(featureId);
89
+ const qaIndex = await this.port.qaTestIndexGet(featureId);
90
+ const evidence = await this.port.evidenceLatest(featureId);
91
+ const specText = await fs.readFile(this.port.specPath(featureId), 'utf8').catch(() => '');
92
+ return {
93
+ data: {
94
+ feature_id: featureId,
95
+ spec: specText,
96
+ state: state.data,
97
+ plan: plan.data.plan,
98
+ qa_test_index: qaIndex.data,
99
+ latest_evidence: evidence.data?.latest ?? null
100
+ }
101
+ };
102
+ }
103
+ async featureLogAppend(featureId, note, context) {
104
+ const repoRoot = this.port.getRepoRoot();
105
+ const logPath = this.port.decisionsPath(featureId);
106
+ const line = `- ${nowIso()} [${context.actorType}:${context.actorId}] ${note}\n`;
107
+ await fs.appendFile(logPath, line, 'utf8');
108
+ return {
109
+ data: {
110
+ feature_id: featureId,
111
+ appended: true,
112
+ log_path: normalizeRepoPathForState(repoRoot, logPath)
113
+ }
114
+ };
115
+ }
116
+ }
117
+ //# sourceMappingURL=feature-lifecycle-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-lifecycle-service.js","sourceRoot":"","sources":["../../../../../apps/control-plane/src/application/services/feature-lifecycle-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAUxD,SAAS,YAAY,CAAC,KAAe;IACnC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,yBAAyB,CAAC,QAAgB,EAAE,YAAoB;IACvE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/E,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;QAClC,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAuBD,MAAM,OAAO,uBAAuB;IACjB,IAAI,CAA8B;IAEnD,YAAY,IAAiC;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,oBAAoB;QACxB,MAAM,UAAU,GAAqD,EAAE,CAAC;QACxE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;QAE/C,IAAI,CAAC,CAAC,MAAM,UAAU,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3B,eAAe,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,IAAI;aAC/C;SACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,SAAiB,EACjB,IAAY,EACZ,OAAuB;QAEvB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACnD,MAAM,IAAI,GAAG,KAAK,MAAM,EAAE,KAAK,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,IAAI,CAAC;QACjF,MAAM,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3C,OAAO;YACL,IAAI,EAAE;gBACJ,UAAU,EAAE,SAAS;gBACrB,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,yBAAyB,CAAC,QAAQ,EAAE,OAAO,CAAC;aACvD;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,34 @@
1
+ type AnyRecord = Record<string, any>;
2
+ type StateReadResult = {
3
+ frontMatter: AnyRecord;
4
+ body: string;
5
+ raw?: string;
6
+ };
7
+ type StateUpdater = (frontMatter: AnyRecord, body: string) => Promise<{
8
+ frontMatter?: AnyRecord;
9
+ body?: string;
10
+ }>;
11
+ export interface FeatureStateServicePort {
12
+ withFeatureLock<T>(featureId: string, operation: () => Promise<T>): Promise<T>;
13
+ readState(featureId: string): Promise<StateReadResult>;
14
+ writeState(featureId: string, frontMatter: AnyRecord, body?: string): Promise<void>;
15
+ }
16
+ export declare class FeatureStateService {
17
+ private readonly port;
18
+ constructor(port: FeatureStateServicePort);
19
+ updateState(featureId: string, expectedVersion: number | null, updater: StateUpdater): Promise<AnyRecord>;
20
+ featureStateGet(featureId: string): Promise<{
21
+ data: {
22
+ front_matter: AnyRecord;
23
+ body: string;
24
+ };
25
+ }>;
26
+ featureStatePatch(featureId: string, expectedVersion: number | null, patch: AnyRecord | null | undefined): Promise<{
27
+ data: {
28
+ feature_id: string;
29
+ version: number;
30
+ status: string;
31
+ };
32
+ }>;
33
+ }
34
+ export {};
@@ -0,0 +1,90 @@
1
+ import { nowIso } from '../../core/fs.js';
2
+ import { fail } from '../../core/response.js';
3
+ import { ERROR_CODES } from '../../core/error-codes.js';
4
+ import { STATUS } from '../../core/constants.js';
5
+ const LEGAL_TRANSITIONS = {
6
+ [STATUS.PLANNING]: [STATUS.BUILDING, STATUS.BLOCKED, STATUS.PLANNING],
7
+ [STATUS.BUILDING]: [STATUS.QA, STATUS.BLOCKED, STATUS.BUILDING],
8
+ [STATUS.QA]: [STATUS.READY_TO_MERGE, STATUS.BLOCKED, STATUS.QA],
9
+ [STATUS.READY_TO_MERGE]: [STATUS.MERGED, STATUS.BLOCKED, STATUS.READY_TO_MERGE],
10
+ [STATUS.BLOCKED]: [STATUS.PLANNING, STATUS.BUILDING, STATUS.QA, STATUS.BLOCKED],
11
+ [STATUS.MERGED]: [STATUS.MERGED],
12
+ [STATUS.FAILED]: [STATUS.FAILED, STATUS.BLOCKED]
13
+ };
14
+ function isTransitionLegal(from, to) {
15
+ const allowed = LEGAL_TRANSITIONS[from] ?? [];
16
+ return allowed.includes(to);
17
+ }
18
+ function readVersion(frontMatter) {
19
+ const raw = frontMatter.version;
20
+ if (typeof raw === 'number' && Number.isFinite(raw)) {
21
+ return raw;
22
+ }
23
+ return 0;
24
+ }
25
+ export class FeatureStateService {
26
+ port;
27
+ constructor(port) {
28
+ this.port = port;
29
+ }
30
+ async updateState(featureId, expectedVersion, updater) {
31
+ return await this.port.withFeatureLock(featureId, async () => {
32
+ const current = await this.port.readState(featureId);
33
+ if (expectedVersion != null && current.frontMatter.version !== expectedVersion) {
34
+ throw {
35
+ normalizedResponse: fail(ERROR_CODES.VERSION_CONFLICT, 'state version conflict', {
36
+ expected_version: expectedVersion,
37
+ actual_version: current.frontMatter.version,
38
+ retryable: true,
39
+ requires_human: false
40
+ })
41
+ };
42
+ }
43
+ const next = await updater(structuredClone(current.frontMatter), current.body);
44
+ const merged = {
45
+ ...current.frontMatter,
46
+ ...next.frontMatter,
47
+ version: readVersion(current.frontMatter) + 1,
48
+ last_updated: nowIso()
49
+ };
50
+ if (!isTransitionLegal(current.frontMatter.status, merged.status)) {
51
+ throw {
52
+ normalizedResponse: fail(ERROR_CODES.INVALID_STATUS_TRANSITION, 'illegal state status transition', {
53
+ from: current.frontMatter.status,
54
+ to: merged.status,
55
+ retryable: false,
56
+ requires_human: true
57
+ })
58
+ };
59
+ }
60
+ await this.port.writeState(featureId, merged, next.body ?? current.body);
61
+ return merged;
62
+ });
63
+ }
64
+ async featureStateGet(featureId) {
65
+ const state = await this.port.readState(featureId);
66
+ return {
67
+ data: {
68
+ front_matter: state.frontMatter,
69
+ body: state.body
70
+ }
71
+ };
72
+ }
73
+ async featureStatePatch(featureId, expectedVersion, patch) {
74
+ const updated = await this.updateState(featureId, expectedVersion, (frontMatter, body) => {
75
+ const nextFront = { ...frontMatter, ...(patch?.front_matter ?? {}) };
76
+ return Promise.resolve({
77
+ frontMatter: nextFront,
78
+ body: patch?.body ?? body
79
+ });
80
+ });
81
+ return {
82
+ data: {
83
+ feature_id: featureId,
84
+ version: updated.version,
85
+ status: updated.status
86
+ }
87
+ };
88
+ }
89
+ }
90
+ //# sourceMappingURL=feature-state-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-state-service.js","sourceRoot":"","sources":["../../../../../apps/control-plane/src/application/services/feature-state-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAgBjD,MAAM,iBAAiB,GAAG;IACxB,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, any>;
2
+ type StateUpdater = (frontMatter: AnyRecord, body: string) => Promise<{
3
+ frontMatter?: AnyRecord;
4
+ body?: string;
5
+ }>;
6
+ export interface GateServicePort {
7
+ getRepoRoot(): string;
8
+ getGatesConfig(): AnyRecord;
9
+ getPolicySnapshot(): AnyRecord;
10
+ readState(featureId: string): Promise<{
11
+ frontMatter: AnyRecord;
12
+ }>;
13
+ updateState(featureId: string, expectedVersion: number | null, updater: StateUpdater): Promise<AnyRecord>;
14
+ worktreePath(featureId: string): string;
15
+ logsPath(featureId: string): string;
16
+ evidencePath(featureId: string): string;
17
+ }
18
+ export declare class GateService {
19
+ private readonly port;
20
+ constructor(port: GateServicePort);
21
+ gatesList(profileName?: string | null): {
22
+ data: AnyRecord;
23
+ };
24
+ gateProfileAndMode(profileName: string, mode: string): AnyRecord;
25
+ gatesRun(featureId: string, profileName: string | null, mode: string): Promise<{
26
+ data: {
27
+ feature_id: string;
28
+ mode: string;
29
+ profile: string;
30
+ overall: string;
31
+ coverage: unknown;
32
+ evidence_path: string;
33
+ };
34
+ evidence: {
35
+ log_path: string;
36
+ };
37
+ }>;
38
+ evidenceLatest(featureId: string): Promise<{
39
+ data: {
40
+ feature_id: string;
41
+ latest: AnyRecord | null;
42
+ path?: string;
43
+ };
44
+ }>;
45
+ }
46
+ export {};
@@ -0,0 +1,160 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { pathExists } from '../../core/fs.js';
4
+ import { runGateMode } from '../../core/gates.js';
5
+ import { ERROR_CODES } from '../../core/error-codes.js';
6
+ import { fail } from '../../core/response.js';
7
+ import { GATE_RESULT, STATUS } from '../../core/constants.js';
8
+ function normalizeRepoPathForState(repoRoot, absolutePath) {
9
+ const relative = path.relative(repoRoot, absolutePath).replaceAll('\\\\', '/');
10
+ if (!relative || relative === '.') {
11
+ return '.';
12
+ }
13
+ return relative;
14
+ }
15
+ function deriveStatusFromGateResult(currentStatus, mode, overall) {
16
+ if (overall === 'fail') {
17
+ return STATUS.BLOCKED;
18
+ }
19
+ if (currentStatus === STATUS.BUILDING && mode === 'fast' && overall === 'pass') {
20
+ return STATUS.QA;
21
+ }
22
+ if (currentStatus === STATUS.QA && mode === 'full' && overall === 'pass') {
23
+ return STATUS.READY_TO_MERGE;
24
+ }
25
+ return currentStatus;
26
+ }
27
+ export class GateService {
28
+ port;
29
+ constructor(port) {
30
+ this.port = port;
31
+ }
32
+ gatesList(profileName = null) {
33
+ const gatesConfig = this.port.getGatesConfig();
34
+ if (profileName) {
35
+ return {
36
+ data: {
37
+ profile: profileName,
38
+ config: gatesConfig.profiles[profileName] ?? null
39
+ }
40
+ };
41
+ }
42
+ return {
43
+ data: {
44
+ profiles: gatesConfig.profiles
45
+ }
46
+ };
47
+ }
48
+ gateProfileAndMode(profileName, mode) {
49
+ const profile = this.port.getGatesConfig().profiles[profileName];
50
+ if (!profile || !profile.modes?.[mode]) {
51
+ throw {
52
+ normalizedResponse: fail(ERROR_CODES.UNKNOWN_GATE_PROFILE_OR_MODE, 'Unknown gate profile or mode', {
53
+ profile: profileName,
54
+ mode,
55
+ retryable: false,
56
+ requires_human: true
57
+ })
58
+ };
59
+ }
60
+ return profile;
61
+ }
62
+ async gatesRun(featureId, profileName, mode) {
63
+ const state = await this.port.readState(featureId);
64
+ const effectiveProfileName = profileName ?? state.frontMatter.gate_profile ?? 'default';
65
+ const profile = this.gateProfileAndMode(effectiveProfileName, mode);
66
+ const repoRoot = this.port.getRepoRoot();
67
+ const runResult = (await runGateMode({
68
+ featureId,
69
+ mode,
70
+ profileName: effectiveProfileName,
71
+ profile,
72
+ policy: this.port.getPolicySnapshot(),
73
+ worktreePath: this.port.worktreePath(featureId),
74
+ logDirectory: this.port.logsPath(featureId),
75
+ evidenceDirectory: this.port.evidencePath(featureId)
76
+ }));
77
+ const nextStateStatus = deriveStatusFromGateResult(state.frontMatter.status, mode, runResult.overall);
78
+ await this.port.updateState(featureId, state.frontMatter.version, (frontMatter, body) => Promise.resolve({
79
+ frontMatter: {
80
+ status: nextStateStatus,
81
+ status_reason: runResult.overall === 'fail' ? `Gate mode ${mode} failed` : frontMatter.status_reason,
82
+ gates: {
83
+ ...frontMatter.gates,
84
+ [mode]: runResult.overall === 'pass' ? GATE_RESULT.PASS : GATE_RESULT.FAIL
85
+ },
86
+ evidence: {
87
+ last_gate_mode: mode,
88
+ last_gate_evidence_path: normalizeRepoPathForState(repoRoot, runResult.evidence_path),
89
+ coverage_status: runResult.coverage_status
90
+ }
91
+ },
92
+ body
93
+ }));
94
+ if (runResult.overall === 'fail' && runResult.coverage_status === 'fail') {
95
+ throw {
96
+ normalizedResponse: fail(ERROR_CODES.COVERAGE_BELOW_MINIMUM, 'Coverage thresholds not met', {
97
+ feature_id: featureId,
98
+ mode,
99
+ coverage: runResult.coverage,
100
+ thresholds: runResult.thresholds,
101
+ retryable: true,
102
+ requires_human: false
103
+ }, {
104
+ log_path: normalizeRepoPathForState(repoRoot, runResult.latest_path)
105
+ })
106
+ };
107
+ }
108
+ return {
109
+ data: {
110
+ feature_id: featureId,
111
+ mode,
112
+ profile: effectiveProfileName,
113
+ overall: runResult.overall,
114
+ coverage: runResult.coverage,
115
+ evidence_path: normalizeRepoPathForState(repoRoot, runResult.evidence_path)
116
+ },
117
+ evidence: {
118
+ log_path: normalizeRepoPathForState(repoRoot, runResult.latest_path)
119
+ }
120
+ };
121
+ }
122
+ async evidenceLatest(featureId) {
123
+ const repoRoot = this.port.getRepoRoot();
124
+ const evidenceDir = this.port.evidencePath(featureId);
125
+ if (!(await pathExists(evidenceDir))) {
126
+ return {
127
+ data: {
128
+ feature_id: featureId,
129
+ latest: null
130
+ }
131
+ };
132
+ }
133
+ const files = (await fs.readdir(evidenceDir))
134
+ .filter((file) => file.endsWith('.json'))
135
+ .map((file) => path.join(evidenceDir, file));
136
+ if (files.length === 0) {
137
+ return {
138
+ data: {
139
+ feature_id: featureId,
140
+ latest: null
141
+ }
142
+ };
143
+ }
144
+ const withStats = await Promise.all(files.map(async (file) => {
145
+ const stat = await fs.stat(file);
146
+ return { file, mtimeMs: stat.mtimeMs };
147
+ }));
148
+ withStats.sort((a, b) => b.mtimeMs - a.mtimeMs);
149
+ const latestFile = withStats[0].file;
150
+ const latest = JSON.parse(await fs.readFile(latestFile, 'utf8'));
151
+ return {
152
+ data: {
153
+ feature_id: featureId,
154
+ latest,
155
+ path: normalizeRepoPathForState(repoRoot, latestFile)
156
+ }
157
+ };
158
+ }
159
+ }
160
+ //# sourceMappingURL=gate-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate-service.js","sourceRoot":"","sources":["../../../../../apps/control-plane/src/application/services/gate-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAmB9D,SAAS,yBAAyB,CAAC,QAAgB,EAAE,YAAoB;IACvE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/E,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;QAClC,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,0BAA0B,CAAC,aAAqB,EAAE,IAAY,EAAE,OAAwB;IAC/F,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,IAAI,aAAa,KA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C,OAAO,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;QAEjE,OAAO;YACL,IAAI,EAAE;gBACJ,UAAU,EAAE,SAAS;gBACrB,MAAM;gBACN,IAAI,EAAE,yBAAyB,CAAC,QAAQ,EAAE,UAAU,CAAC;aACtD;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,56 @@
1
+ type AnyRecord = Record<string, any>;
2
+ type StateUpdater = (frontMatter: AnyRecord, body: string) => Promise<{
3
+ frontMatter?: AnyRecord;
4
+ body?: string;
5
+ }>;
6
+ interface CollisionQueueDrivePort {
7
+ reDriveBlockedQueue(): Promise<{
8
+ data: {
9
+ processed: number;
10
+ retried: number;
11
+ still_blocked: number;
12
+ };
13
+ }>;
14
+ }
15
+ export interface LockServicePort {
16
+ withIndexLock<T>(operation: () => Promise<T>): Promise<T>;
17
+ readIndex(): Promise<AnyRecord>;
18
+ writeIndex(index: AnyRecord): Promise<void>;
19
+ updateState(featureId: string, expectedVersion: number | null, updater: StateUpdater): Promise<AnyRecord>;
20
+ statePath(featureId: string): string;
21
+ getPolicySnapshot(): AnyRecord;
22
+ collisionQueueService?: CollisionQueueDrivePort;
23
+ }
24
+ export declare class LockService {
25
+ private readonly port;
26
+ constructor(port: LockServicePort);
27
+ locksAcquire(resource: string | null, featureId: string | null, waitTimeoutSeconds?: number | null): Promise<{
28
+ data: {
29
+ resource: string;
30
+ feature_id: string;
31
+ lease_id: any;
32
+ expires_at: any;
33
+ stale_reclaimed: any;
34
+ };
35
+ evidence: {
36
+ code: "stale_lock_reclaimed";
37
+ message: string;
38
+ };
39
+ }>;
40
+ locksRelease(resource: string | null, featureId: string | null): Promise<{
41
+ data: {
42
+ resource: string;
43
+ feature_id: string;
44
+ released: boolean;
45
+ };
46
+ }>;
47
+ renewLeases(featureIds: string[]): Promise<void>;
48
+ recoverFromState(): Promise<{
49
+ data: {
50
+ recovered: boolean;
51
+ stale_features: string[];
52
+ active: unknown;
53
+ };
54
+ }>;
55
+ }
56
+ export {};