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,90 @@
1
+ import { detectPlanCollisions } from '../../core/collisions.js';
2
+ import { pathExists, stableHash } from '../../core/fs.js';
3
+ function normalizeSet(array) {
4
+ return [...new Set(array)].sort((a, b) => a.localeCompare(b));
5
+ }
6
+ function readHeldLocks(frontMatter) {
7
+ const locks = frontMatter?.locks && typeof frontMatter.locks === 'object' ? frontMatter.locks : {};
8
+ const held = Array.isArray(locks.held) ? locks.held : [];
9
+ return held.filter((item) => typeof item === 'string');
10
+ }
11
+ function createCollisionFingerprint(collisions) {
12
+ return stableHash(JSON.stringify(collisions));
13
+ }
14
+ export class ReportingService {
15
+ port;
16
+ constructor(port) {
17
+ this.port = port;
18
+ }
19
+ async collisionsScan() {
20
+ const plans = await this.port.collectAcceptedPlans();
21
+ const matrix = [];
22
+ for (let i = 0; i < plans.length; i += 1) {
23
+ for (let j = i + 1; j < plans.length; j += 1) {
24
+ const candidatePlan = plans[i];
25
+ const comparisonPlan = plans[j];
26
+ const result = detectPlanCollisions(candidatePlan, [comparisonPlan], this.port.getPolicySnapshot());
27
+ if (result.hasCollisions) {
28
+ matrix.push({
29
+ feature_id: candidatePlan.feature_id,
30
+ with_feature_id: comparisonPlan.feature_id,
31
+ collisions: result.collisions,
32
+ fingerprint: createCollisionFingerprint(result.collisions)
33
+ });
34
+ }
35
+ }
36
+ }
37
+ return {
38
+ data: {
39
+ collisions: matrix
40
+ }
41
+ };
42
+ }
43
+ async reportDashboard() {
44
+ const index = await this.port.readIndex();
45
+ const featureIds = normalizeSet([
46
+ ...index.active,
47
+ ...index.blocked,
48
+ ...index.merged,
49
+ ...Object.values(index.locks).filter(Boolean)
50
+ ]);
51
+ const features = [];
52
+ for (const featureId of featureIds) {
53
+ const statePath = this.port.statePath(featureId);
54
+ if (!(await pathExists(statePath))) {
55
+ continue;
56
+ }
57
+ const state = await this.port.readState(featureId);
58
+ features.push({
59
+ feature_id: featureId,
60
+ status: state.frontMatter.status,
61
+ locks: readHeldLocks(state.frontMatter),
62
+ gate_profile: state.frontMatter.gate_profile,
63
+ gates: state.frontMatter.gates,
64
+ last_updated: state.frontMatter.last_updated
65
+ });
66
+ }
67
+ return {
68
+ data: {
69
+ index,
70
+ features
71
+ }
72
+ };
73
+ }
74
+ async reportFeatureSummary(featureId) {
75
+ const state = await this.port.featureStateGet(featureId);
76
+ const bundle = await this.port.repoDiffBundle(featureId);
77
+ const qa = await this.port.qaTestIndexGet(featureId);
78
+ return {
79
+ data: {
80
+ feature_id: featureId,
81
+ state: state.data.front_matter,
82
+ diff_stat: bundle.data.diff_stat,
83
+ touched_files: bundle.data.touched_files,
84
+ last_gate_summary: bundle.data.last_gate_summary,
85
+ qa_summary: qa.data.summary
86
+ }
87
+ };
88
+ }
89
+ }
90
+ //# sourceMappingURL=reporting-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporting-service.js","sourceRoot":"","sources":["../../../../../apps/control-plane/src/application/services/reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK1D,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,aAAa,CAAC,WAAsB;IAC3C,MAAM,KAAK,GAAG,WAAW,EAAE,KAAK,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACnG,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,IAAa,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC;AAClF,CAAC;AAED,SAAS,0BAA0B,CAAC,UAAmB;IACrD,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;AAChD,CAAC;AAaD,MAAM,OAAO,gBAAg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CAAC,CAAC;QAE1E,OAAO;YACL,IAAI,EAAE;gBACJ,UAAU,EAAE,SAAS;gBACrB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY;gBAC9B,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS;gBAChC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,aAAa;gBACxC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,iBAAiB;gBAChD,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO;aAC5B;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,74 @@
1
+ import type { RuntimeSessionsSnapshot } from '../../core/runtime-sessions.js';
2
+ export interface AcquireRunLeaseInput {
3
+ run_id: string;
4
+ owner_instance_id: string;
5
+ provider: string;
6
+ model: string;
7
+ provider_config_ref_hash: string;
8
+ takeover_stale_run?: boolean;
9
+ }
10
+ interface RuntimeFeatureSessionUpdateParams {
11
+ run_id: string;
12
+ owner_instance_id: string;
13
+ feature_id: string;
14
+ planner_session_id: string;
15
+ builder_session_id: string;
16
+ qa_session_id: string;
17
+ }
18
+ interface PruneFeatureSessionParams {
19
+ run_id: string;
20
+ owner_instance_id: string;
21
+ active_feature_ids: string[];
22
+ }
23
+ type IndexSnapshot = Record<string, any>;
24
+ export interface RunLeaseServicePort {
25
+ runLeaseTtlSeconds(): number;
26
+ withIndexLock<T>(operation: () => Promise<T>): Promise<T>;
27
+ readIndex(): Promise<IndexSnapshot>;
28
+ writeIndex(index: IndexSnapshot): Promise<void>;
29
+ normalizeRuntimeSessions(value: unknown, at?: string): RuntimeSessionsSnapshot;
30
+ isRunLeaseFresh(runtimeSessions: RuntimeSessionsSnapshot): boolean;
31
+ emptyRuntimeSessions(at?: string): RuntimeSessionsSnapshot;
32
+ }
33
+ export declare class RunLeaseService {
34
+ private readonly port;
35
+ constructor(port: RunLeaseServicePort);
36
+ acquireRunLease(input: AcquireRunLeaseInput): Promise<{
37
+ data: {
38
+ runtime_sessions: RuntimeSessionsSnapshot;
39
+ took_over_stale: boolean;
40
+ reused_existing_owner: boolean;
41
+ };
42
+ }>;
43
+ renewRunLease(runId: string, ownerInstanceId: string): Promise<{
44
+ data: {
45
+ lease_expires_at: string;
46
+ };
47
+ }>;
48
+ releaseRunLease(runId: string, ownerInstanceId: string): Promise<{
49
+ data: {
50
+ released: boolean;
51
+ };
52
+ }>;
53
+ updateOrchestratorSession(params: {
54
+ run_id: string;
55
+ owner_instance_id: string;
56
+ orchestrator_session_id: string;
57
+ increment_epoch?: boolean;
58
+ }): Promise<{
59
+ data: {
60
+ runtime_sessions: RuntimeSessionsSnapshot;
61
+ };
62
+ }>;
63
+ updateFeatureSessionAssignment(params: RuntimeFeatureSessionUpdateParams): Promise<{
64
+ data: {
65
+ updated: boolean;
66
+ };
67
+ }>;
68
+ pruneFeatureSessionAssignments(params: PruneFeatureSessionParams): Promise<{
69
+ data: {
70
+ removed: string[];
71
+ };
72
+ }>;
73
+ }
74
+ export {};
@@ -0,0 +1,263 @@
1
+ import crypto from 'node:crypto';
2
+ import { nowIso, stableHash } from '../../core/fs.js';
3
+ import { fail } from '../../core/response.js';
4
+ import { ERROR_CODES } from '../../core/error-codes.js';
5
+ export class RunLeaseService {
6
+ port;
7
+ constructor(port) {
8
+ this.port = port;
9
+ }
10
+ async acquireRunLease(input) {
11
+ if (!input.run_id || !input.owner_instance_id) {
12
+ throw {
13
+ normalizedResponse: fail(ERROR_CODES.INVALID_ARGUMENT, 'run_id and owner_instance_id are required', {
14
+ retryable: false,
15
+ requires_human: true
16
+ })
17
+ };
18
+ }
19
+ const ttlMs = this.port.runLeaseTtlSeconds() * 1000;
20
+ const normalizedProviderHash = input.provider_config_ref_hash && input.provider_config_ref_hash.length > 0
21
+ ? input.provider_config_ref_hash
22
+ : stableHash('none');
23
+ return await this.port.withIndexLock(async () => {
24
+ const index = await this.port.readIndex();
25
+ const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
26
+ const hasLease = current.run_id !== 'none' && current.owner_instance_id !== 'none';
27
+ const fresh = hasLease && this.port.isRunLeaseFresh(current);
28
+ const sameOwner = current.run_id === input.run_id && current.owner_instance_id === input.owner_instance_id;
29
+ if (fresh && !sameOwner) {
30
+ throw {
31
+ normalizedResponse: fail(ERROR_CODES.RUN_ALREADY_ACTIVE, 'Another active run already owns this repository', {
32
+ active_run_id: current.run_id,
33
+ owner_instance_id: current.owner_instance_id,
34
+ lease_expires_at: current.lease_expires_at,
35
+ stale: false,
36
+ retryable: false,
37
+ requires_human: true
38
+ })
39
+ };
40
+ }
41
+ const staleOwnedByOther = hasLease && !fresh && !sameOwner;
42
+ if (staleOwnedByOther && !input.takeover_stale_run) {
43
+ throw {
44
+ normalizedResponse: fail(ERROR_CODES.RUN_ALREADY_ACTIVE, 'A stale run lease exists; explicit takeover is required', {
45
+ active_run_id: current.run_id,
46
+ owner_instance_id: current.owner_instance_id,
47
+ lease_expires_at: current.lease_expires_at,
48
+ stale: true,
49
+ requires_takeover: true,
50
+ retryable: false,
51
+ requires_human: true
52
+ })
53
+ };
54
+ }
55
+ const now = nowIso();
56
+ const isInitialRun = !hasLease || current.run_id === 'none';
57
+ const claimed = {
58
+ ...current,
59
+ run_id: input.run_id,
60
+ owner_instance_id: input.owner_instance_id,
61
+ lease_id: crypto.randomUUID(),
62
+ provider: input.provider,
63
+ model: input.model,
64
+ provider_config_ref_hash: normalizedProviderHash,
65
+ started_at: sameOwner && current.started_at ? current.started_at : now,
66
+ last_heartbeat_at: now,
67
+ lease_expires_at: new Date(Date.now() + ttlMs).toISOString(),
68
+ orchestrator_epoch: isInitialRun ? 0 : Number(current.orchestrator_epoch ?? 0)
69
+ };
70
+ if (!sameOwner) {
71
+ claimed.orchestrator_session_id = 'unknown';
72
+ claimed.feature_sessions = {};
73
+ }
74
+ index.runtime_sessions = claimed;
75
+ index.version += 1;
76
+ index.updated_at = nowIso();
77
+ await this.port.writeIndex(index);
78
+ return {
79
+ data: {
80
+ runtime_sessions: claimed,
81
+ took_over_stale: staleOwnedByOther,
82
+ reused_existing_owner: sameOwner
83
+ }
84
+ };
85
+ });
86
+ }
87
+ async renewRunLease(runId, ownerInstanceId) {
88
+ if (!runId || !ownerInstanceId) {
89
+ throw {
90
+ normalizedResponse: fail(ERROR_CODES.INVALID_ARGUMENT, 'runId and ownerInstanceId are required', {
91
+ retryable: false,
92
+ requires_human: true
93
+ })
94
+ };
95
+ }
96
+ const ttlMs = this.port.runLeaseTtlSeconds() * 1000;
97
+ return await this.port.withIndexLock(async () => {
98
+ const index = await this.port.readIndex();
99
+ const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
100
+ if (current.run_id !== runId || current.owner_instance_id !== ownerInstanceId) {
101
+ throw {
102
+ normalizedResponse: fail(ERROR_CODES.RUN_LEASE_NOT_OWNED, 'Cannot renew a run lease not owned by this instance', {
103
+ run_id: runId,
104
+ owner_instance_id: ownerInstanceId,
105
+ active_run_id: current.run_id,
106
+ active_owner_instance_id: current.owner_instance_id,
107
+ retryable: false,
108
+ requires_human: true
109
+ })
110
+ };
111
+ }
112
+ const updated = {
113
+ ...current,
114
+ last_heartbeat_at: nowIso(),
115
+ lease_expires_at: new Date(Date.now() + ttlMs).toISOString()
116
+ };
117
+ index.runtime_sessions = updated;
118
+ index.version += 1;
119
+ index.updated_at = nowIso();
120
+ await this.port.writeIndex(index);
121
+ return {
122
+ data: {
123
+ lease_expires_at: updated.lease_expires_at
124
+ }
125
+ };
126
+ });
127
+ }
128
+ async releaseRunLease(runId, ownerInstanceId) {
129
+ return await this.port.withIndexLock(async () => {
130
+ const index = await this.port.readIndex();
131
+ const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
132
+ if (current.run_id !== runId || current.owner_instance_id !== ownerInstanceId) {
133
+ return { data: { released: false } };
134
+ }
135
+ index.runtime_sessions = this.port.emptyRuntimeSessions(nowIso());
136
+ index.version += 1;
137
+ index.updated_at = nowIso();
138
+ await this.port.writeIndex(index);
139
+ return { data: { released: true } };
140
+ });
141
+ }
142
+ async updateOrchestratorSession(params) {
143
+ const { run_id, owner_instance_id, orchestrator_session_id, increment_epoch = false } = params;
144
+ if (!run_id || !owner_instance_id || !orchestrator_session_id) {
145
+ throw {
146
+ normalizedResponse: fail(ERROR_CODES.INVALID_ARGUMENT, 'run_id, owner_instance_id, and orchestrator_session_id are required', {
147
+ retryable: false,
148
+ requires_human: true
149
+ })
150
+ };
151
+ }
152
+ return await this.port.withIndexLock(async () => {
153
+ const index = await this.port.readIndex();
154
+ const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
155
+ if (current.run_id !== run_id || current.owner_instance_id !== owner_instance_id) {
156
+ throw {
157
+ normalizedResponse: fail(ERROR_CODES.RUN_LEASE_NOT_OWNED, 'Cannot update orchestrator session without run ownership', {
158
+ run_id,
159
+ owner_instance_id,
160
+ active_run_id: current.run_id,
161
+ active_owner_instance_id: current.owner_instance_id,
162
+ retryable: false,
163
+ requires_human: true
164
+ })
165
+ };
166
+ }
167
+ const nextEpoch = increment_epoch
168
+ ? Number(current.orchestrator_epoch ?? 0) + 1
169
+ : Number(current.orchestrator_epoch ?? 0);
170
+ const updated = {
171
+ ...current,
172
+ orchestrator_session_id,
173
+ orchestrator_epoch: nextEpoch
174
+ };
175
+ index.runtime_sessions = updated;
176
+ index.version += 1;
177
+ index.updated_at = nowIso();
178
+ await this.port.writeIndex(index);
179
+ return {
180
+ data: {
181
+ runtime_sessions: updated
182
+ }
183
+ };
184
+ });
185
+ }
186
+ async updateFeatureSessionAssignment(params) {
187
+ const { run_id, owner_instance_id, feature_id, planner_session_id, builder_session_id, qa_session_id } = params;
188
+ return await this.port.withIndexLock(async () => {
189
+ const index = await this.port.readIndex();
190
+ const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
191
+ if (current.run_id !== run_id || current.owner_instance_id !== owner_instance_id) {
192
+ throw {
193
+ normalizedResponse: fail(ERROR_CODES.RUN_LEASE_NOT_OWNED, 'Cannot update feature sessions without run ownership', {
194
+ run_id,
195
+ owner_instance_id,
196
+ active_run_id: current.run_id,
197
+ active_owner_instance_id: current.owner_instance_id,
198
+ retryable: false,
199
+ requires_human: true
200
+ })
201
+ };
202
+ }
203
+ const nextFeatureSessions = {
204
+ ...(current.feature_sessions ?? {}),
205
+ [feature_id]: {
206
+ planner_session_id,
207
+ builder_session_id,
208
+ qa_session_id
209
+ }
210
+ };
211
+ index.runtime_sessions = {
212
+ ...current,
213
+ feature_sessions: nextFeatureSessions
214
+ };
215
+ index.version += 1;
216
+ index.updated_at = nowIso();
217
+ await this.port.writeIndex(index);
218
+ return { data: { updated: true } };
219
+ });
220
+ }
221
+ async pruneFeatureSessionAssignments(params) {
222
+ const active = new Set(params.active_feature_ids);
223
+ return await this.port.withIndexLock(async () => {
224
+ const index = await this.port.readIndex();
225
+ const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
226
+ if (current.run_id !== params.run_id || current.owner_instance_id !== params.owner_instance_id) {
227
+ throw {
228
+ normalizedResponse: fail(ERROR_CODES.RUN_LEASE_NOT_OWNED, 'Cannot prune feature sessions without run ownership', {
229
+ run_id: params.run_id,
230
+ owner_instance_id: params.owner_instance_id,
231
+ active_run_id: current.run_id,
232
+ active_owner_instance_id: current.owner_instance_id,
233
+ retryable: false,
234
+ requires_human: true
235
+ })
236
+ };
237
+ }
238
+ const existing = current.feature_sessions ?? {};
239
+ const kept = {};
240
+ const removed = [];
241
+ for (const [featureId, assignment] of Object.entries(existing)) {
242
+ if (active.has(featureId)) {
243
+ kept[featureId] = assignment;
244
+ }
245
+ else {
246
+ removed.push(featureId);
247
+ }
248
+ }
249
+ if (removed.length > 0) {
250
+ index.runtime_sessions = {
251
+ ...current,
252
+ feature_sessions: kept
253
+ };
254
+ index.version += 1;
255
+ index.updated_at = nowIso();
256
+ await this.port.writeIndex(index);
257
+ }
258
+ removed.sort((a, b) => a.localeCompare(b));
259
+ return { data: { removed } };
260
+ });
261
+ }
262
+ }
263
+ //# sourceMappingURL=run-lease-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-lease-service.js","sourceRoot":"","sources":["../../../../../apps/control-plane/src/application/services/run-lease-service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAwCxD,MAAM,OAAO,eAAe;IACT,IAAI,CAAsB;IAE3C,YAAY,IAAyB;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,KAA2B;QAO/C,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC9C,MAAM;gBACJ,kBAAkB,EAAE,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,2CAA2C,EAAE;oBAClG,SAAS,EAAE,KAAK;oBAChB,cAAc,EAAE,IAAI;iBACrB,CAAC;aACH,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC;QACpD,MAAM,sBAAsB,GAC1B,KAAK,CAAC,wBAAwB,IAAI,KAAK,CAAC,wBAAwB,CAAC,MAAM,GAAG,CAAC;YACzE,CAAC,CAAC,KAAK,CAAC,wBAAwB;YAChC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,IAAI,EAAE;YAC9C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAC3E,MAAM,QAAQ,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gD,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAa,EAAE,CAAC;YAC7B,KAAK,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC/D,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;oBAC1B,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC;gBAC/B,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC;YAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,KAAK,CAAC,gBAAgB,GAAG;oBACvB,GAAG,OAAO;oBACV,gBAAgB,EAAE,IAAI;iBACvB,CAAC;gBACF,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;gBACnB,KAAK,CAAC,UAAU,GAAG,MAAM,EAAE,CAAC;gBAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;YAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,OAAO,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ export interface ToolBehaviorMetadata {
2
+ mutating: boolean;
3
+ requires_operation_id: boolean;
4
+ }
5
+ export declare const TOOL_BEHAVIOR_METADATA: Readonly<Record<string, ToolBehaviorMetadata>>;
6
+ export declare function isMutatingTool(toolName: string): boolean;
7
+ export declare function toolRequiresOperationId(toolName: string): boolean;
8
+ export declare function withOperationIdIfRequired(toolName: string, args: Record<string, unknown>, createOperationId: (toolName: string, featureId?: string) => string): Record<string, unknown>;
@@ -0,0 +1,37 @@
1
+ import { TOOLS } from '../../core/constants.js';
2
+ const MUTATING_TOOLS = [
3
+ TOOLS.FEATURE_INIT,
4
+ TOOLS.FEATURE_STATE_PATCH,
5
+ TOOLS.FEATURE_LOG_APPEND,
6
+ TOOLS.PLAN_SUBMIT,
7
+ TOOLS.PLAN_UPDATE,
8
+ TOOLS.REPO_ENSURE_WORKTREE,
9
+ TOOLS.REPO_APPLY_PATCH,
10
+ TOOLS.GATES_RUN,
11
+ TOOLS.QA_TEST_INDEX_UPDATE,
12
+ TOOLS.LOCKS_ACQUIRE,
13
+ TOOLS.LOCKS_RELEASE,
14
+ TOOLS.FEATURE_READY_TO_MERGE,
15
+ TOOLS.FEATURE_DELETE
16
+ ];
17
+ export const TOOL_BEHAVIOR_METADATA = Object.freeze(Object.fromEntries(MUTATING_TOOLS.map((name) => [name, { mutating: true, requires_operation_id: true }])));
18
+ export function isMutatingTool(toolName) {
19
+ return TOOL_BEHAVIOR_METADATA[toolName]?.mutating ?? false;
20
+ }
21
+ export function toolRequiresOperationId(toolName) {
22
+ return TOOL_BEHAVIOR_METADATA[toolName]?.requires_operation_id ?? false;
23
+ }
24
+ export function withOperationIdIfRequired(toolName, args, createOperationId) {
25
+ if (!toolRequiresOperationId(toolName)) {
26
+ return { ...args };
27
+ }
28
+ if (typeof args.operation_id === 'string') {
29
+ return { ...args };
30
+ }
31
+ const featureId = typeof args.feature_id === 'string' ? args.feature_id : undefined;
32
+ return {
33
+ ...args,
34
+ operation_id: createOperationId(toolName, featureId)
35
+ };
36
+ }
37
+ //# sourceMappingURL=tool-metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-metadata.js","sourceRoot":"","sources":["../../../../../apps/control-plane/src/application/tools/tool-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAOhD,MAAM,cAAc,GAAG;IACrB,KAAK,CAAC,YAAY;IAClB,KAAK,CAAC,mBAAmB;IACzB,KAAK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AY,EAAE,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC;KACrD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ export interface ToolHandlerContext {
2
+ actorType: string;
3
+ actorId: string;
4
+ }
5
+ export type ToolHandler = (args: Record<string, unknown>, context: ToolHandlerContext) => Promise<unknown>;
6
+ export declare class ToolHandlerRegistry {
7
+ private readonly handlers;
8
+ register(toolName: string, handler: ToolHandler): void;
9
+ lookup(toolName: string): ToolHandler | undefined;
10
+ }
11
+ export declare class ToolRouter {
12
+ private readonly registry;
13
+ private readonly unknownToolHandler;
14
+ constructor(registry: ToolHandlerRegistry, unknownToolHandler: (toolName: string) => Promise<unknown>);
15
+ route(toolName: string, args: Record<string, unknown>, context: ToolHandlerContext): Promise<unknown>;
16
+ }
@@ -0,0 +1,25 @@
1
+ export class ToolHandlerRegistry {
2
+ handlers = new Map();
3
+ register(toolName, handler) {
4
+ this.handlers.set(toolName, handler);
5
+ }
6
+ lookup(toolName) {
7
+ return this.handlers.get(toolName);
8
+ }
9
+ }
10
+ export class ToolRouter {
11
+ registry;
12
+ unknownToolHandler;
13
+ constructor(registry, unknownToolHandler) {
14
+ this.registry = registry;
15
+ this.unknownToolHandler = unknownToolHandler;
16
+ }
17
+ async route(toolName, args, context) {
18
+ const handler = this.registry.lookup(toolName);
19
+ if (!handler) {
20
+ return await this.unknownToolHandler(toolName);
21
+ }
22
+ return await handler(args, context);
23
+ }
24
+ }
25
+ //# sourceMappingURL=tool-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-router.js","sourceRoot":"","sources":["../../../../../apps/control-plane/src/application/tools/tool-router.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,mBAAmB;IACb,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAE3D,QAAQ,CAAC,QAAgB,EAAE,OAAoB;QAC7C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,QAAgB;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;CACF;AAED,MAAM,OAAO,UAAU;IACJ,QAAQ,CAAsB;IAC9B,kBAAkB,CAAyC;IAE5E,YAAY,QAA6B,EAAE,kBAA0D;QACnG,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,KAAK,CACT,QAAgB,EAChB,IAA6B,EAC7B,OAA2B;QAE3B,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,MAAM,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env -S tsx
2
+ import type { RuntimeContext } from './types.js';
3
+ export declare function main(argv?: string[], runtime?: RuntimeContext): Promise<number>;
4
+ export declare function isDirectExecution(importMetaUrl: string, argv1: string | undefined): boolean;
5
+ export declare function runAsEntrypoint(importMetaUrl: string, argv1: string | undefined, executeMain?: () => Promise<number>): boolean;
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env -S tsx
2
+ import { runCli } from '../interfaces/cli/bootstrap.js';
3
+ export async function main(argv = process.argv.slice(2), runtime = { cwd: process.cwd(), env: process.env }) {
4
+ return await runCli(argv, runtime);
5
+ }
6
+ export function isDirectExecution(importMetaUrl, argv1) {
7
+ return importMetaUrl === `file://${argv1 ?? ''}`;
8
+ }
9
+ export function runAsEntrypoint(importMetaUrl, argv1, executeMain = () => main()) {
10
+ if (!isDirectExecution(importMetaUrl, argv1)) {
11
+ return false;
12
+ }
13
+ void executeMain().then((exitCode) => {
14
+ process.exitCode = exitCode;
15
+ });
16
+ return true;
17
+ }
18
+ runAsEntrypoint(import.meta.url, process.argv[1]);
19
+ //# sourceMappingURL=aop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aop.js","sourceRoot":"","sources":["../../../../apps/control-plane/src/cli/aop.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAGxD,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,OAAiB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EACtC,UAA0B,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAElE,OAAO,MAAM,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,aAAqB,EAAE,KAAyB;IAChF,OAAO,aAAa,KAAK,UAAU,KAAK,IAAI,EAAE,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,aAAqB,EACrB,KAAyB,EACzB,cAAqC,GAAG,EAAE,CAAC,IAAI,EAAE;IAEjD,IAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;QACnC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC9B,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC;AAED,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { CliOptions, ToolTransport } from './types.js';
2
+ export declare class CliArgumentParser {
3
+ parse(argv: string[]): CliOptions;
4
+ resolveTransport(option: string | undefined): ToolTransport;
5
+ }