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.
- package/.dockerignore +24 -0
- package/.github/workflows/mcp-contract-validation.yml +38 -0
- package/Agentic-Orchestrator.iml +9 -0
- package/LICENSE +21 -0
- package/README.md +679 -0
- package/agentic/orchestrator/agents.yaml +14 -0
- package/agentic/orchestrator/gates.yaml +31 -0
- package/agentic/orchestrator/policy.yaml +145 -0
- package/agentic/orchestrator/prompts/builder.system.md +1 -0
- package/agentic/orchestrator/prompts/planner.system.md +15 -0
- package/agentic/orchestrator/prompts/qa.system.md +1 -0
- package/agentic/orchestrator/schemas/agents.schema.json +49 -0
- package/agentic/orchestrator/schemas/gates.schema.json +65 -0
- package/agentic/orchestrator/schemas/index.schema.json +108 -0
- package/agentic/orchestrator/schemas/plan.schema.json +127 -0
- package/agentic/orchestrator/schemas/policy.schema.json +227 -0
- package/agentic/orchestrator/schemas/qa_test_index.schema.json +53 -0
- package/agentic/orchestrator/schemas/state.schema.json +92 -0
- package/agentic/orchestrator/tools/catalog.json +399 -0
- package/agentic/orchestrator/tools/errors.schema.json +21 -0
- package/agentic/orchestrator/tools/protocol.json +8 -0
- package/agentic/orchestrator/tools/schemas/input/collisions.scan.input.schema.json +7 -0
- package/agentic/orchestrator/tools/schemas/input/evidence.latest.input.schema.json +15 -0
- package/agentic/orchestrator/tools/schemas/input/feature.delete.input.schema.json +42 -0
- package/agentic/orchestrator/tools/schemas/input/feature.discover_specs.input.schema.json +7 -0
- package/agentic/orchestrator/tools/schemas/input/feature.get_context.input.schema.json +15 -0
- package/agentic/orchestrator/tools/schemas/input/feature.init.input.schema.json +21 -0
- package/agentic/orchestrator/tools/schemas/input/feature.log_append.input.schema.json +26 -0
- package/agentic/orchestrator/tools/schemas/input/feature.ready_to_merge.input.schema.json +34 -0
- package/agentic/orchestrator/tools/schemas/input/feature.state_get.input.schema.json +15 -0
- package/agentic/orchestrator/tools/schemas/input/feature.state_patch.input.schema.json +28 -0
- package/agentic/orchestrator/tools/schemas/input/gates.list.input.schema.json +11 -0
- package/agentic/orchestrator/tools/schemas/input/gates.run.input.schema.json +29 -0
- package/agentic/orchestrator/tools/schemas/input/locks.acquire.input.schema.json +29 -0
- package/agentic/orchestrator/tools/schemas/input/locks.release.input.schema.json +26 -0
- package/agentic/orchestrator/tools/schemas/input/mutating.schema.json +14 -0
- package/agentic/orchestrator/tools/schemas/input/plan.get.input.schema.json +15 -0
- package/agentic/orchestrator/tools/schemas/input/plan.submit.input.schema.json +28 -0
- package/agentic/orchestrator/tools/schemas/input/plan.update.input.schema.json +29 -0
- package/agentic/orchestrator/tools/schemas/input/qa.test_index_get.input.schema.json +15 -0
- package/agentic/orchestrator/tools/schemas/input/qa.test_index_update.input.schema.json +38 -0
- package/agentic/orchestrator/tools/schemas/input/read.schema.json +6 -0
- package/agentic/orchestrator/tools/schemas/input/repo.apply_patch.input.schema.json +25 -0
- package/agentic/orchestrator/tools/schemas/input/repo.diff.input.schema.json +21 -0
- package/agentic/orchestrator/tools/schemas/input/repo.diff_bundle.input.schema.json +15 -0
- package/agentic/orchestrator/tools/schemas/input/repo.ensure_worktree.input.schema.json +21 -0
- package/agentic/orchestrator/tools/schemas/input/repo.read_file.input.schema.json +20 -0
- package/agentic/orchestrator/tools/schemas/input/repo.search.input.schema.json +20 -0
- package/agentic/orchestrator/tools/schemas/input/repo.status.input.schema.json +15 -0
- package/agentic/orchestrator/tools/schemas/input/report.dashboard.input.schema.json +7 -0
- package/agentic/orchestrator/tools/schemas/input/report.feature_summary.input.schema.json +15 -0
- package/agentic/orchestrator/tools/schemas/output/collisions.scan.output.schema.json +17 -0
- package/agentic/orchestrator/tools/schemas/output/evidence.latest.output.schema.json +20 -0
- package/agentic/orchestrator/tools/schemas/output/feature.delete.output.schema.json +224 -0
- package/agentic/orchestrator/tools/schemas/output/feature.discover_specs.output.schema.json +32 -0
- package/agentic/orchestrator/tools/schemas/output/feature.get_context.output.schema.json +40 -0
- package/agentic/orchestrator/tools/schemas/output/feature.init.output.schema.json +24 -0
- package/agentic/orchestrator/tools/schemas/output/feature.log_append.output.schema.json +24 -0
- package/agentic/orchestrator/tools/schemas/output/feature.ready_to_merge.output.schema.json +30 -0
- package/agentic/orchestrator/tools/schemas/output/feature.state_get.output.schema.json +18 -0
- package/agentic/orchestrator/tools/schemas/output/feature.state_patch.output.schema.json +24 -0
- package/agentic/orchestrator/tools/schemas/output/gates.list.output.schema.json +42 -0
- package/agentic/orchestrator/tools/schemas/output/gates.run.output.schema.json +37 -0
- package/agentic/orchestrator/tools/schemas/output/locks.acquire.output.schema.json +34 -0
- package/agentic/orchestrator/tools/schemas/output/locks.release.output.schema.json +24 -0
- package/agentic/orchestrator/tools/schemas/output/plan.get.output.schema.json +26 -0
- package/agentic/orchestrator/tools/schemas/output/plan.submit.output.schema.json +23 -0
- package/agentic/orchestrator/tools/schemas/output/plan.update.output.schema.json +23 -0
- package/agentic/orchestrator/tools/schemas/output/qa.test_index_get.output.schema.json +22 -0
- package/agentic/orchestrator/tools/schemas/output/qa.test_index_update.output.schema.json +19 -0
- package/agentic/orchestrator/tools/schemas/output/repo.apply_patch.output.schema.json +33 -0
- package/agentic/orchestrator/tools/schemas/output/repo.diff.output.schema.json +19 -0
- package/agentic/orchestrator/tools/schemas/output/repo.diff_bundle.output.schema.json +32 -0
- package/agentic/orchestrator/tools/schemas/output/repo.ensure_worktree.output.schema.json +29 -0
- package/agentic/orchestrator/tools/schemas/output/repo.read_file.output.schema.json +24 -0
- package/agentic/orchestrator/tools/schemas/output/repo.search.output.schema.json +26 -0
- package/agentic/orchestrator/tools/schemas/output/repo.status.output.schema.json +27 -0
- package/agentic/orchestrator/tools/schemas/output/report.dashboard.output.schema.json +21 -0
- package/agentic/orchestrator/tools/schemas/output/report.feature_summary.output.schema.json +36 -0
- package/agentic/orchestrator/tools/schemas/output/standard_success.schema.json +6 -0
- package/agentic/orchestrator/tools.md +32 -0
- package/apps/control-plane/project.json +39 -0
- package/apps/control-plane/scripts/validate-architecture-rules.mjs +170 -0
- package/apps/control-plane/scripts/validate-docker-mcp-contract.mjs +84 -0
- package/apps/control-plane/scripts/validate-mcp-contracts.ts +61 -0
- package/apps/control-plane/src/application/services/collision-queue-service.ts +227 -0
- package/apps/control-plane/src/application/services/feature-deletion-service.ts +459 -0
- package/apps/control-plane/src/application/services/feature-lifecycle-service.ts +177 -0
- package/apps/control-plane/src/application/services/feature-state-service.ts +125 -0
- package/apps/control-plane/src/application/services/gate-service.ts +232 -0
- package/apps/control-plane/src/application/services/lock-service.ts +298 -0
- package/apps/control-plane/src/application/services/merge-service.ts +246 -0
- package/apps/control-plane/src/application/services/patch-service.ts +259 -0
- package/apps/control-plane/src/application/services/plan-service.ts +302 -0
- package/apps/control-plane/src/application/services/qa-index-service.ts +98 -0
- package/apps/control-plane/src/application/services/reporting-service.ts +120 -0
- package/apps/control-plane/src/application/services/run-lease-service.ts +340 -0
- package/apps/control-plane/src/application/tools/tool-metadata.ts +56 -0
- package/apps/control-plane/src/application/tools/tool-router.ts +43 -0
- package/apps/control-plane/src/cli/aop.ts +31 -0
- package/apps/control-plane/src/cli/cli-argument-parser.ts +116 -0
- package/apps/control-plane/src/cli/delete-command-handler.ts +90 -0
- package/apps/control-plane/src/cli/io.ts +14 -0
- package/apps/control-plane/src/cli/resume-command-handler.ts +228 -0
- package/apps/control-plane/src/cli/run-command-handler.ts +57 -0
- package/apps/control-plane/src/cli/spec-ingestion-service.ts +88 -0
- package/apps/control-plane/src/cli/spec-input-resolver.ts +95 -0
- package/apps/control-plane/src/cli/spec-utils.ts +40 -0
- package/apps/control-plane/src/cli/status-command-handler.ts +17 -0
- package/apps/control-plane/src/cli/stop-command-handler.ts +5 -0
- package/apps/control-plane/src/cli/tooling.ts +36 -0
- package/apps/control-plane/src/cli/types.ts +34 -0
- package/apps/control-plane/src/core/collisions.ts +121 -0
- package/apps/control-plane/src/core/constants.ts +72 -0
- package/apps/control-plane/src/core/error-codes.ts +54 -0
- package/apps/control-plane/src/core/frontmatter.ts +42 -0
- package/apps/control-plane/src/core/fs.ts +173 -0
- package/apps/control-plane/src/core/gates.ts +361 -0
- package/apps/control-plane/src/core/git.ts +115 -0
- package/apps/control-plane/src/core/kernel.ts +1077 -0
- package/apps/control-plane/src/core/patch.ts +152 -0
- package/apps/control-plane/src/core/path-layout.ts +113 -0
- package/apps/control-plane/src/core/path-rules.ts +71 -0
- package/apps/control-plane/src/core/qa-index.ts +179 -0
- package/apps/control-plane/src/core/response.ts +62 -0
- package/apps/control-plane/src/core/runtime-sessions.ts +20 -0
- package/apps/control-plane/src/core/schemas.ts +125 -0
- package/apps/control-plane/src/index.ts +21 -0
- package/apps/control-plane/src/interfaces/cli/bootstrap.ts +100 -0
- package/apps/control-plane/src/mcp/kernel-tool-executor.ts +39 -0
- package/apps/control-plane/src/mcp/mcp-server-adapter.ts +74 -0
- package/apps/control-plane/src/mcp/operation-ledger.ts +108 -0
- package/apps/control-plane/src/mcp/protocol-contract.ts +9 -0
- package/apps/control-plane/src/mcp/runtime-factory.ts +105 -0
- package/apps/control-plane/src/mcp/runtime-types.ts +44 -0
- package/apps/control-plane/src/mcp/token-auth-verifier.ts +63 -0
- package/apps/control-plane/src/mcp/token-claims-validator.ts +72 -0
- package/apps/control-plane/src/mcp/token-codec.ts +62 -0
- package/apps/control-plane/src/mcp/tool-authorizer.ts +43 -0
- package/apps/control-plane/src/mcp/tool-client.ts +78 -0
- package/apps/control-plane/src/mcp/tool-contract-validator.ts +83 -0
- package/apps/control-plane/src/mcp/tool-registry-loader.ts +135 -0
- package/apps/control-plane/src/mcp/tool-runtime.ts +336 -0
- package/apps/control-plane/src/mcp/tools-markdown-generator.ts +26 -0
- package/apps/control-plane/src/mcp/transport-types.ts +16 -0
- package/apps/control-plane/src/mcp/types.ts +2 -0
- package/apps/control-plane/src/providers/providers.ts +177 -0
- package/apps/control-plane/src/supervisor/build-wave-executor.ts +55 -0
- package/apps/control-plane/src/supervisor/lease-heartbeat-service.ts +22 -0
- package/apps/control-plane/src/supervisor/planning-wave-executor.ts +316 -0
- package/apps/control-plane/src/supervisor/prompt-bundle-loader.ts +62 -0
- package/apps/control-plane/src/supervisor/qa-wave-executor.ts +99 -0
- package/apps/control-plane/src/supervisor/run-coordinator.ts +224 -0
- package/apps/control-plane/src/supervisor/runtime.ts +347 -0
- package/apps/control-plane/src/supervisor/session-orchestrator.ts +268 -0
- package/apps/control-plane/src/supervisor/types.ts +149 -0
- package/apps/control-plane/src/supervisor/worker-decision-loop.ts +299 -0
- package/apps/control-plane/test/aop.spec.ts +101 -0
- package/apps/control-plane/test/cli-helpers.spec.ts +102 -0
- package/apps/control-plane/test/cli.spec.ts +12 -0
- package/apps/control-plane/test/cli.unit.spec.ts +609 -0
- package/apps/control-plane/test/collision-queue.spec.ts +158 -0
- package/apps/control-plane/test/collisions.spec.ts +138 -0
- package/apps/control-plane/test/core-utils.spec.ts +102 -0
- package/apps/control-plane/test/delete-command-handler.spec.ts +202 -0
- package/apps/control-plane/test/epoch-tracking.spec.ts +121 -0
- package/apps/control-plane/test/gates.spec.ts +452 -0
- package/apps/control-plane/test/helpers.ts +68 -0
- package/apps/control-plane/test/index.spec.ts +18 -0
- package/apps/control-plane/test/kernel-collision-replay.spec.ts +222 -0
- package/apps/control-plane/test/kernel.branches.spec.ts +321 -0
- package/apps/control-plane/test/kernel.coverage.spec.ts +408 -0
- package/apps/control-plane/test/kernel.spec.ts +369 -0
- package/apps/control-plane/test/mcp-helpers.spec.ts +195 -0
- package/apps/control-plane/test/mcp.spec.ts +776 -0
- package/apps/control-plane/test/merge-service.spec.ts +357 -0
- package/apps/control-plane/test/plan-service.spec.ts +195 -0
- package/apps/control-plane/test/planning-wave-executor.spec.ts +229 -0
- package/apps/control-plane/test/providers.spec.ts +168 -0
- package/apps/control-plane/test/qa-index-service.spec.ts +187 -0
- package/apps/control-plane/test/qa-index.spec.ts +317 -0
- package/apps/control-plane/test/response.spec.ts +55 -0
- package/apps/control-plane/test/run-coordinator.spec.ts +334 -0
- package/apps/control-plane/test/schema-date-time.spec.ts +170 -0
- package/apps/control-plane/test/service-retry-paths.spec.ts +305 -0
- package/apps/control-plane/test/services.spec.ts +693 -0
- package/apps/control-plane/test/spec-input-resolver.spec.ts +76 -0
- package/apps/control-plane/test/supervisor-collaborators.spec.ts +201 -0
- package/apps/control-plane/test/supervisor.calltool.spec.ts +120 -0
- package/apps/control-plane/test/supervisor.spec.ts +415 -0
- package/apps/control-plane/test/supervisor.unit.spec.ts +522 -0
- package/apps/control-plane/test/token-auth-verifier.spec.ts +111 -0
- package/apps/control-plane/test/tool-registry-loader.spec.ts +268 -0
- package/apps/control-plane/test/tool-runtime.spec.ts +294 -0
- package/apps/control-plane/test/worker-decision-loop.spec.ts +587 -0
- package/apps/control-plane/tsconfig.build.json +17 -0
- package/apps/control-plane/tsconfig.json +11 -0
- package/apps/control-plane/vitest.config.ts +28 -0
- package/dist/apps/control-plane/application/services/collision-queue-service.d.ts +69 -0
- package/dist/apps/control-plane/application/services/collision-queue-service.js +158 -0
- package/dist/apps/control-plane/application/services/collision-queue-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/feature-deletion-service.d.ts +79 -0
- package/dist/apps/control-plane/application/services/feature-deletion-service.js +336 -0
- package/dist/apps/control-plane/application/services/feature-deletion-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/feature-lifecycle-service.d.ts +81 -0
- package/dist/apps/control-plane/application/services/feature-lifecycle-service.js +117 -0
- package/dist/apps/control-plane/application/services/feature-lifecycle-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/feature-state-service.d.ts +34 -0
- package/dist/apps/control-plane/application/services/feature-state-service.js +90 -0
- package/dist/apps/control-plane/application/services/feature-state-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/gate-service.d.ts +46 -0
- package/dist/apps/control-plane/application/services/gate-service.js +160 -0
- package/dist/apps/control-plane/application/services/gate-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/lock-service.d.ts +56 -0
- package/dist/apps/control-plane/application/services/lock-service.js +242 -0
- package/dist/apps/control-plane/application/services/lock-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/merge-service.d.ts +33 -0
- package/dist/apps/control-plane/application/services/merge-service.js +194 -0
- package/dist/apps/control-plane/application/services/merge-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/patch-service.d.ts +39 -0
- package/dist/apps/control-plane/application/services/patch-service.js +189 -0
- package/dist/apps/control-plane/application/services/patch-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/plan-service.d.ts +60 -0
- package/dist/apps/control-plane/application/services/plan-service.js +234 -0
- package/dist/apps/control-plane/application/services/plan-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/qa-index-service.d.ts +26 -0
- package/dist/apps/control-plane/application/services/qa-index-service.js +66 -0
- package/dist/apps/control-plane/application/services/qa-index-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/reporting-service.d.ts +47 -0
- package/dist/apps/control-plane/application/services/reporting-service.js +90 -0
- package/dist/apps/control-plane/application/services/reporting-service.js.map +1 -0
- package/dist/apps/control-plane/application/services/run-lease-service.d.ts +74 -0
- package/dist/apps/control-plane/application/services/run-lease-service.js +263 -0
- package/dist/apps/control-plane/application/services/run-lease-service.js.map +1 -0
- package/dist/apps/control-plane/application/tools/tool-metadata.d.ts +8 -0
- package/dist/apps/control-plane/application/tools/tool-metadata.js +37 -0
- package/dist/apps/control-plane/application/tools/tool-metadata.js.map +1 -0
- package/dist/apps/control-plane/application/tools/tool-router.d.ts +16 -0
- package/dist/apps/control-plane/application/tools/tool-router.js +25 -0
- package/dist/apps/control-plane/application/tools/tool-router.js.map +1 -0
- package/dist/apps/control-plane/cli/aop.d.ts +5 -0
- package/dist/apps/control-plane/cli/aop.js +19 -0
- package/dist/apps/control-plane/cli/aop.js.map +1 -0
- package/dist/apps/control-plane/cli/cli-argument-parser.d.ts +5 -0
- package/dist/apps/control-plane/cli/cli-argument-parser.js +109 -0
- package/dist/apps/control-plane/cli/cli-argument-parser.js.map +1 -0
- package/dist/apps/control-plane/cli/delete-command-handler.d.ts +8 -0
- package/dist/apps/control-plane/cli/delete-command-handler.js +77 -0
- package/dist/apps/control-plane/cli/delete-command-handler.js.map +1 -0
- package/dist/apps/control-plane/cli/io.d.ts +2 -0
- package/dist/apps/control-plane/cli/io.js +14 -0
- package/dist/apps/control-plane/cli/io.js.map +1 -0
- package/dist/apps/control-plane/cli/resume-command-handler.d.ts +17 -0
- package/dist/apps/control-plane/cli/resume-command-handler.js +178 -0
- package/dist/apps/control-plane/cli/resume-command-handler.js.map +1 -0
- package/dist/apps/control-plane/cli/run-command-handler.d.ts +15 -0
- package/dist/apps/control-plane/cli/run-command-handler.js +39 -0
- package/dist/apps/control-plane/cli/run-command-handler.js.map +1 -0
- package/dist/apps/control-plane/cli/spec-ingestion-service.d.ts +8 -0
- package/dist/apps/control-plane/cli/spec-ingestion-service.js +77 -0
- package/dist/apps/control-plane/cli/spec-ingestion-service.js.map +1 -0
- package/dist/apps/control-plane/cli/spec-input-resolver.d.ts +9 -0
- package/dist/apps/control-plane/cli/spec-input-resolver.js +81 -0
- package/dist/apps/control-plane/cli/spec-input-resolver.js.map +1 -0
- package/dist/apps/control-plane/cli/spec-utils.d.ts +3 -0
- package/dist/apps/control-plane/cli/spec-utils.js +36 -0
- package/dist/apps/control-plane/cli/spec-utils.js.map +1 -0
- package/dist/apps/control-plane/cli/status-command-handler.d.ts +7 -0
- package/dist/apps/control-plane/cli/status-command-handler.js +14 -0
- package/dist/apps/control-plane/cli/status-command-handler.js.map +1 -0
- package/dist/apps/control-plane/cli/stop-command-handler.d.ts +3 -0
- package/dist/apps/control-plane/cli/stop-command-handler.js +6 -0
- package/dist/apps/control-plane/cli/stop-command-handler.js.map +1 -0
- package/dist/apps/control-plane/cli/tooling.d.ts +4 -0
- package/dist/apps/control-plane/cli/tooling.js +24 -0
- package/dist/apps/control-plane/cli/tooling.js.map +1 -0
- package/dist/apps/control-plane/cli/types.d.ts +31 -0
- package/dist/apps/control-plane/cli/types.js +2 -0
- package/dist/apps/control-plane/cli/types.js.map +1 -0
- package/dist/apps/control-plane/core/collisions.d.ts +39 -0
- package/dist/apps/control-plane/core/collisions.js +78 -0
- package/dist/apps/control-plane/core/collisions.js.map +1 -0
- package/dist/apps/control-plane/core/constants.d.ts +64 -0
- package/dist/apps/control-plane/core/constants.js +64 -0
- package/dist/apps/control-plane/core/constants.js.map +1 -0
- package/dist/apps/control-plane/core/error-codes.d.ts +50 -0
- package/dist/apps/control-plane/core/error-codes.js +52 -0
- package/dist/apps/control-plane/core/error-codes.js.map +1 -0
- package/dist/apps/control-plane/core/frontmatter.d.ts +11 -0
- package/dist/apps/control-plane/core/frontmatter.js +30 -0
- package/dist/apps/control-plane/core/frontmatter.js.map +1 -0
- package/dist/apps/control-plane/core/fs.d.ts +33 -0
- package/dist/apps/control-plane/core/fs.js +134 -0
- package/dist/apps/control-plane/core/fs.js.map +1 -0
- package/dist/apps/control-plane/core/gates.d.ts +88 -0
- package/dist/apps/control-plane/core/gates.js +229 -0
- package/dist/apps/control-plane/core/gates.js.map +1 -0
- package/dist/apps/control-plane/core/git.d.ts +31 -0
- package/dist/apps/control-plane/core/git.js +79 -0
- package/dist/apps/control-plane/core/git.js.map +1 -0
- package/dist/apps/control-plane/core/kernel.d.ts +445 -0
- package/dist/apps/control-plane/core/kernel.js +805 -0
- package/dist/apps/control-plane/core/kernel.js.map +1 -0
- package/dist/apps/control-plane/core/patch.d.ts +23 -0
- package/dist/apps/control-plane/core/patch.js +118 -0
- package/dist/apps/control-plane/core/patch.js.map +1 -0
- package/dist/apps/control-plane/core/path-layout.d.ts +23 -0
- package/dist/apps/control-plane/core/path-layout.js +90 -0
- package/dist/apps/control-plane/core/path-layout.js.map +1 -0
- package/dist/apps/control-plane/core/path-rules.d.ts +13 -0
- package/dist/apps/control-plane/core/path-rules.js +52 -0
- package/dist/apps/control-plane/core/path-rules.js.map +1 -0
- package/dist/apps/control-plane/core/qa-index.d.ts +53 -0
- package/dist/apps/control-plane/core/qa-index.js +112 -0
- package/dist/apps/control-plane/core/qa-index.js.map +1 -0
- package/dist/apps/control-plane/core/response.d.ts +19 -0
- package/dist/apps/control-plane/core/response.js +34 -0
- package/dist/apps/control-plane/core/response.js.map +1 -0
- package/dist/apps/control-plane/core/runtime-sessions.d.ts +19 -0
- package/dist/apps/control-plane/core/runtime-sessions.js +2 -0
- package/dist/apps/control-plane/core/runtime-sessions.js.map +1 -0
- package/dist/apps/control-plane/core/schemas.d.ts +23 -0
- package/dist/apps/control-plane/core/schemas.js +80 -0
- package/dist/apps/control-plane/core/schemas.js.map +1 -0
- package/dist/apps/control-plane/index.d.ts +11 -0
- package/dist/apps/control-plane/index.js +9 -0
- package/dist/apps/control-plane/index.js.map +1 -0
- package/dist/apps/control-plane/interfaces/cli/bootstrap.d.ts +2 -0
- package/dist/apps/control-plane/interfaces/cli/bootstrap.js +86 -0
- package/dist/apps/control-plane/interfaces/cli/bootstrap.js.map +1 -0
- package/dist/apps/control-plane/mcp/kernel-tool-executor.d.ts +14 -0
- package/dist/apps/control-plane/mcp/kernel-tool-executor.js +26 -0
- package/dist/apps/control-plane/mcp/kernel-tool-executor.js.map +1 -0
- package/dist/apps/control-plane/mcp/mcp-server-adapter.d.ts +19 -0
- package/dist/apps/control-plane/mcp/mcp-server-adapter.js +55 -0
- package/dist/apps/control-plane/mcp/mcp-server-adapter.js.map +1 -0
- package/dist/apps/control-plane/mcp/operation-ledger.d.ts +21 -0
- package/dist/apps/control-plane/mcp/operation-ledger.js +75 -0
- package/dist/apps/control-plane/mcp/operation-ledger.js.map +1 -0
- package/dist/apps/control-plane/mcp/protocol-contract.d.ts +8 -0
- package/dist/apps/control-plane/mcp/protocol-contract.js +9 -0
- package/dist/apps/control-plane/mcp/protocol-contract.js.map +1 -0
- package/dist/apps/control-plane/mcp/runtime-factory.d.ts +38 -0
- package/dist/apps/control-plane/mcp/runtime-factory.js +71 -0
- package/dist/apps/control-plane/mcp/runtime-factory.js.map +1 -0
- package/dist/apps/control-plane/mcp/runtime-types.d.ts +40 -0
- package/dist/apps/control-plane/mcp/runtime-types.js +2 -0
- package/dist/apps/control-plane/mcp/runtime-types.js.map +1 -0
- package/dist/apps/control-plane/mcp/token-auth-verifier.d.ts +24 -0
- package/dist/apps/control-plane/mcp/token-auth-verifier.js +45 -0
- package/dist/apps/control-plane/mcp/token-auth-verifier.js.map +1 -0
- package/dist/apps/control-plane/mcp/token-claims-validator.d.ts +9 -0
- package/dist/apps/control-plane/mcp/token-claims-validator.js +62 -0
- package/dist/apps/control-plane/mcp/token-claims-validator.js.map +1 -0
- package/dist/apps/control-plane/mcp/token-codec.d.ts +11 -0
- package/dist/apps/control-plane/mcp/token-codec.js +46 -0
- package/dist/apps/control-plane/mcp/token-codec.js.map +1 -0
- package/dist/apps/control-plane/mcp/tool-authorizer.d.ts +8 -0
- package/dist/apps/control-plane/mcp/tool-authorizer.js +36 -0
- package/dist/apps/control-plane/mcp/tool-authorizer.js.map +1 -0
- package/dist/apps/control-plane/mcp/tool-client.d.ts +30 -0
- package/dist/apps/control-plane/mcp/tool-client.js +50 -0
- package/dist/apps/control-plane/mcp/tool-client.js.map +1 -0
- package/dist/apps/control-plane/mcp/tool-contract-validator.d.ts +29 -0
- package/dist/apps/control-plane/mcp/tool-contract-validator.js +61 -0
- package/dist/apps/control-plane/mcp/tool-contract-validator.js.map +1 -0
- package/dist/apps/control-plane/mcp/tool-registry-loader.d.ts +15 -0
- package/dist/apps/control-plane/mcp/tool-registry-loader.js +109 -0
- package/dist/apps/control-plane/mcp/tool-registry-loader.js.map +1 -0
- package/dist/apps/control-plane/mcp/tool-runtime.d.ts +34 -0
- package/dist/apps/control-plane/mcp/tool-runtime.js +252 -0
- package/dist/apps/control-plane/mcp/tool-runtime.js.map +1 -0
- package/dist/apps/control-plane/mcp/tools-markdown-generator.d.ts +7 -0
- package/dist/apps/control-plane/mcp/tools-markdown-generator.js +22 -0
- package/dist/apps/control-plane/mcp/tools-markdown-generator.js.map +1 -0
- package/dist/apps/control-plane/mcp/transport-types.d.ts +14 -0
- package/dist/apps/control-plane/mcp/transport-types.js +2 -0
- package/dist/apps/control-plane/mcp/transport-types.js.map +1 -0
- package/dist/apps/control-plane/mcp/types.d.ts +2 -0
- package/dist/apps/control-plane/mcp/types.js +3 -0
- package/dist/apps/control-plane/mcp/types.js.map +1 -0
- package/dist/apps/control-plane/providers/providers.d.ts +72 -0
- package/dist/apps/control-plane/providers/providers.js +94 -0
- package/dist/apps/control-plane/providers/providers.js.map +1 -0
- package/dist/apps/control-plane/supervisor/build-wave-executor.d.ts +13 -0
- package/dist/apps/control-plane/supervisor/build-wave-executor.js +40 -0
- package/dist/apps/control-plane/supervisor/build-wave-executor.js.map +1 -0
- package/dist/apps/control-plane/supervisor/lease-heartbeat-service.d.ts +12 -0
- package/dist/apps/control-plane/supervisor/lease-heartbeat-service.js +14 -0
- package/dist/apps/control-plane/supervisor/lease-heartbeat-service.js.map +1 -0
- package/dist/apps/control-plane/supervisor/planning-wave-executor.d.ts +19 -0
- package/dist/apps/control-plane/supervisor/planning-wave-executor.js +249 -0
- package/dist/apps/control-plane/supervisor/planning-wave-executor.js.map +1 -0
- package/dist/apps/control-plane/supervisor/prompt-bundle-loader.d.ts +9 -0
- package/dist/apps/control-plane/supervisor/prompt-bundle-loader.js +53 -0
- package/dist/apps/control-plane/supervisor/prompt-bundle-loader.js.map +1 -0
- package/dist/apps/control-plane/supervisor/qa-wave-executor.d.ts +24 -0
- package/dist/apps/control-plane/supervisor/qa-wave-executor.js +70 -0
- package/dist/apps/control-plane/supervisor/qa-wave-executor.js.map +1 -0
- package/dist/apps/control-plane/supervisor/run-coordinator.d.ts +49 -0
- package/dist/apps/control-plane/supervisor/run-coordinator.js +162 -0
- package/dist/apps/control-plane/supervisor/run-coordinator.js.map +1 -0
- package/dist/apps/control-plane/supervisor/runtime.d.ts +58 -0
- package/dist/apps/control-plane/supervisor/runtime.js +270 -0
- package/dist/apps/control-plane/supervisor/runtime.js.map +1 -0
- package/dist/apps/control-plane/supervisor/session-orchestrator.d.ts +29 -0
- package/dist/apps/control-plane/supervisor/session-orchestrator.js +211 -0
- package/dist/apps/control-plane/supervisor/session-orchestrator.js.map +1 -0
- package/dist/apps/control-plane/supervisor/types.d.ts +148 -0
- package/dist/apps/control-plane/supervisor/types.js +2 -0
- package/dist/apps/control-plane/supervisor/types.js.map +1 -0
- package/dist/apps/control-plane/supervisor/worker-decision-loop.d.ts +37 -0
- package/dist/apps/control-plane/supervisor/worker-decision-loop.js +236 -0
- package/dist/apps/control-plane/supervisor/worker-decision-loop.js.map +1 -0
- package/docker/mcp.Dockerfile +14 -0
- package/docker/mcp.compose.yaml +15 -0
- package/docker/mcp.entrypoint.sh +17 -0
- package/eslint.config.mjs +93 -0
- package/example-configurations/README.md +26 -0
- package/example-configurations/java/agents.yaml +14 -0
- package/example-configurations/java/gates.yaml +29 -0
- package/example-configurations/java/policy.yaml +148 -0
- package/example-configurations/node/agents.yaml +14 -0
- package/example-configurations/node/gates.yaml +32 -0
- package/example-configurations/node/policy.yaml +143 -0
- package/nx.json +16 -0
- package/package.json +39 -0
- package/prompts/vitest-testing-standards.instructions.md +204 -0
- package/scripts/dev-shell-env.sh +7 -0
- package/scripts/nx-safe.mjs +33 -0
- package/spec-files/agentic_orchestrator_cli_delete_command_spec.md +310 -0
- package/spec-files/agentic_orchestrator_dot_aop_generated_artifacts_spec.md +211 -0
- package/spec-files/agentic_orchestrator_mcp_formalization_spec.md +379 -0
- package/spec-files/agentic_orchestrator_oop_refactor_spec.md +415 -0
- package/spec-files/agentic_orchestrator_single_global_orchestrator_spec.md +265 -0
- package/spec-files/agentic_orchestrator_spec.md +1334 -0
- package/spec-files/progress.md +452 -0
- package/tsconfig.base.json +15 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,340 @@
|
|
|
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
|
+
import type { RuntimeSessionsSnapshot } from '../../core/runtime-sessions.js';
|
|
6
|
+
|
|
7
|
+
export interface AcquireRunLeaseInput {
|
|
8
|
+
run_id: string;
|
|
9
|
+
owner_instance_id: string;
|
|
10
|
+
provider: string;
|
|
11
|
+
model: string;
|
|
12
|
+
provider_config_ref_hash: string;
|
|
13
|
+
takeover_stale_run?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface RuntimeFeatureSessionUpdateParams {
|
|
17
|
+
run_id: string;
|
|
18
|
+
owner_instance_id: string;
|
|
19
|
+
feature_id: string;
|
|
20
|
+
planner_session_id: string;
|
|
21
|
+
builder_session_id: string;
|
|
22
|
+
qa_session_id: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface PruneFeatureSessionParams {
|
|
26
|
+
run_id: string;
|
|
27
|
+
owner_instance_id: string;
|
|
28
|
+
active_feature_ids: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
type IndexSnapshot = Record<string, any>;
|
|
33
|
+
|
|
34
|
+
export interface RunLeaseServicePort {
|
|
35
|
+
runLeaseTtlSeconds(): number;
|
|
36
|
+
withIndexLock<T>(operation: () => Promise<T>): Promise<T>;
|
|
37
|
+
readIndex(): Promise<IndexSnapshot>;
|
|
38
|
+
writeIndex(index: IndexSnapshot): Promise<void>;
|
|
39
|
+
normalizeRuntimeSessions(value: unknown, at?: string): RuntimeSessionsSnapshot;
|
|
40
|
+
isRunLeaseFresh(runtimeSessions: RuntimeSessionsSnapshot): boolean;
|
|
41
|
+
emptyRuntimeSessions(at?: string): RuntimeSessionsSnapshot;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class RunLeaseService {
|
|
45
|
+
private readonly port: RunLeaseServicePort;
|
|
46
|
+
|
|
47
|
+
constructor(port: RunLeaseServicePort) {
|
|
48
|
+
this.port = port;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async acquireRunLease(input: AcquireRunLeaseInput): Promise<{
|
|
52
|
+
data: {
|
|
53
|
+
runtime_sessions: RuntimeSessionsSnapshot;
|
|
54
|
+
took_over_stale: boolean;
|
|
55
|
+
reused_existing_owner: boolean;
|
|
56
|
+
};
|
|
57
|
+
}> {
|
|
58
|
+
if (!input.run_id || !input.owner_instance_id) {
|
|
59
|
+
throw {
|
|
60
|
+
normalizedResponse: fail(ERROR_CODES.INVALID_ARGUMENT, 'run_id and owner_instance_id are required', {
|
|
61
|
+
retryable: false,
|
|
62
|
+
requires_human: true
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const ttlMs = this.port.runLeaseTtlSeconds() * 1000;
|
|
68
|
+
const normalizedProviderHash =
|
|
69
|
+
input.provider_config_ref_hash && input.provider_config_ref_hash.length > 0
|
|
70
|
+
? input.provider_config_ref_hash
|
|
71
|
+
: stableHash('none');
|
|
72
|
+
|
|
73
|
+
return await this.port.withIndexLock(async () => {
|
|
74
|
+
const index = await this.port.readIndex();
|
|
75
|
+
const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
|
|
76
|
+
const hasLease = current.run_id !== 'none' && current.owner_instance_id !== 'none';
|
|
77
|
+
const fresh = hasLease && this.port.isRunLeaseFresh(current);
|
|
78
|
+
const sameOwner = current.run_id === input.run_id && current.owner_instance_id === input.owner_instance_id;
|
|
79
|
+
|
|
80
|
+
if (fresh && !sameOwner) {
|
|
81
|
+
throw {
|
|
82
|
+
normalizedResponse: fail(ERROR_CODES.RUN_ALREADY_ACTIVE, 'Another active run already owns this repository', {
|
|
83
|
+
active_run_id: current.run_id,
|
|
84
|
+
owner_instance_id: current.owner_instance_id,
|
|
85
|
+
lease_expires_at: current.lease_expires_at,
|
|
86
|
+
stale: false,
|
|
87
|
+
retryable: false,
|
|
88
|
+
requires_human: true
|
|
89
|
+
})
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const staleOwnedByOther = hasLease && !fresh && !sameOwner;
|
|
94
|
+
if (staleOwnedByOther && !input.takeover_stale_run) {
|
|
95
|
+
throw {
|
|
96
|
+
normalizedResponse: fail(ERROR_CODES.RUN_ALREADY_ACTIVE, 'A stale run lease exists; explicit takeover is required', {
|
|
97
|
+
active_run_id: current.run_id,
|
|
98
|
+
owner_instance_id: current.owner_instance_id,
|
|
99
|
+
lease_expires_at: current.lease_expires_at,
|
|
100
|
+
stale: true,
|
|
101
|
+
requires_takeover: true,
|
|
102
|
+
retryable: false,
|
|
103
|
+
requires_human: true
|
|
104
|
+
})
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const now = nowIso();
|
|
109
|
+
const isInitialRun = !hasLease || current.run_id === 'none';
|
|
110
|
+
const claimed: RuntimeSessionsSnapshot = {
|
|
111
|
+
...current,
|
|
112
|
+
run_id: input.run_id,
|
|
113
|
+
owner_instance_id: input.owner_instance_id,
|
|
114
|
+
lease_id: crypto.randomUUID(),
|
|
115
|
+
provider: input.provider,
|
|
116
|
+
model: input.model,
|
|
117
|
+
provider_config_ref_hash: normalizedProviderHash,
|
|
118
|
+
started_at: sameOwner && current.started_at ? current.started_at : now,
|
|
119
|
+
last_heartbeat_at: now,
|
|
120
|
+
lease_expires_at: new Date(Date.now() + ttlMs).toISOString(),
|
|
121
|
+
orchestrator_epoch: isInitialRun ? 0 : Number(current.orchestrator_epoch ?? 0)
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if (!sameOwner) {
|
|
125
|
+
claimed.orchestrator_session_id = 'unknown';
|
|
126
|
+
claimed.feature_sessions = {};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
index.runtime_sessions = claimed;
|
|
130
|
+
index.version += 1;
|
|
131
|
+
index.updated_at = nowIso();
|
|
132
|
+
await this.port.writeIndex(index);
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
data: {
|
|
136
|
+
runtime_sessions: claimed,
|
|
137
|
+
took_over_stale: staleOwnedByOther,
|
|
138
|
+
reused_existing_owner: sameOwner
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async renewRunLease(runId: string, ownerInstanceId: string): Promise<{ data: { lease_expires_at: string } }> {
|
|
145
|
+
if (!runId || !ownerInstanceId) {
|
|
146
|
+
throw {
|
|
147
|
+
normalizedResponse: fail(ERROR_CODES.INVALID_ARGUMENT, 'runId and ownerInstanceId are required', {
|
|
148
|
+
retryable: false,
|
|
149
|
+
requires_human: true
|
|
150
|
+
})
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const ttlMs = this.port.runLeaseTtlSeconds() * 1000;
|
|
155
|
+
return await this.port.withIndexLock(async () => {
|
|
156
|
+
const index = await this.port.readIndex();
|
|
157
|
+
const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
|
|
158
|
+
if (current.run_id !== runId || current.owner_instance_id !== ownerInstanceId) {
|
|
159
|
+
throw {
|
|
160
|
+
normalizedResponse: fail(ERROR_CODES.RUN_LEASE_NOT_OWNED, 'Cannot renew a run lease not owned by this instance', {
|
|
161
|
+
run_id: runId,
|
|
162
|
+
owner_instance_id: ownerInstanceId,
|
|
163
|
+
active_run_id: current.run_id,
|
|
164
|
+
active_owner_instance_id: current.owner_instance_id,
|
|
165
|
+
retryable: false,
|
|
166
|
+
requires_human: true
|
|
167
|
+
})
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const updated: RuntimeSessionsSnapshot = {
|
|
172
|
+
...current,
|
|
173
|
+
last_heartbeat_at: nowIso(),
|
|
174
|
+
lease_expires_at: new Date(Date.now() + ttlMs).toISOString()
|
|
175
|
+
};
|
|
176
|
+
index.runtime_sessions = updated;
|
|
177
|
+
index.version += 1;
|
|
178
|
+
index.updated_at = nowIso();
|
|
179
|
+
await this.port.writeIndex(index);
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
data: {
|
|
183
|
+
lease_expires_at: updated.lease_expires_at
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async releaseRunLease(runId: string, ownerInstanceId: string): Promise<{ data: { released: boolean } }> {
|
|
190
|
+
return await this.port.withIndexLock(async () => {
|
|
191
|
+
const index = await this.port.readIndex();
|
|
192
|
+
const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
|
|
193
|
+
if (current.run_id !== runId || current.owner_instance_id !== ownerInstanceId) {
|
|
194
|
+
return { data: { released: false } };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
index.runtime_sessions = this.port.emptyRuntimeSessions(nowIso());
|
|
198
|
+
index.version += 1;
|
|
199
|
+
index.updated_at = nowIso();
|
|
200
|
+
await this.port.writeIndex(index);
|
|
201
|
+
return { data: { released: true } };
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async updateOrchestratorSession(params: {
|
|
206
|
+
run_id: string;
|
|
207
|
+
owner_instance_id: string;
|
|
208
|
+
orchestrator_session_id: string;
|
|
209
|
+
increment_epoch?: boolean;
|
|
210
|
+
}): Promise<{ data: { runtime_sessions: RuntimeSessionsSnapshot } }> {
|
|
211
|
+
const { run_id, owner_instance_id, orchestrator_session_id, increment_epoch = false } = params;
|
|
212
|
+
if (!run_id || !owner_instance_id || !orchestrator_session_id) {
|
|
213
|
+
throw {
|
|
214
|
+
normalizedResponse: fail(ERROR_CODES.INVALID_ARGUMENT, 'run_id, owner_instance_id, and orchestrator_session_id are required', {
|
|
215
|
+
retryable: false,
|
|
216
|
+
requires_human: true
|
|
217
|
+
})
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return await this.port.withIndexLock(async () => {
|
|
222
|
+
const index = await this.port.readIndex();
|
|
223
|
+
const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
|
|
224
|
+
if (current.run_id !== run_id || current.owner_instance_id !== owner_instance_id) {
|
|
225
|
+
throw {
|
|
226
|
+
normalizedResponse: fail(ERROR_CODES.RUN_LEASE_NOT_OWNED, 'Cannot update orchestrator session without run ownership', {
|
|
227
|
+
run_id,
|
|
228
|
+
owner_instance_id,
|
|
229
|
+
active_run_id: current.run_id,
|
|
230
|
+
active_owner_instance_id: current.owner_instance_id,
|
|
231
|
+
retryable: false,
|
|
232
|
+
requires_human: true
|
|
233
|
+
})
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const nextEpoch = increment_epoch
|
|
238
|
+
? Number(current.orchestrator_epoch ?? 0) + 1
|
|
239
|
+
: Number(current.orchestrator_epoch ?? 0);
|
|
240
|
+
const updated: RuntimeSessionsSnapshot = {
|
|
241
|
+
...current,
|
|
242
|
+
orchestrator_session_id,
|
|
243
|
+
orchestrator_epoch: nextEpoch
|
|
244
|
+
};
|
|
245
|
+
index.runtime_sessions = updated;
|
|
246
|
+
index.version += 1;
|
|
247
|
+
index.updated_at = nowIso();
|
|
248
|
+
await this.port.writeIndex(index);
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
data: {
|
|
252
|
+
runtime_sessions: updated
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async updateFeatureSessionAssignment(params: RuntimeFeatureSessionUpdateParams): Promise<{ data: { updated: boolean } }> {
|
|
259
|
+
const { run_id, owner_instance_id, feature_id, planner_session_id, builder_session_id, qa_session_id } = params;
|
|
260
|
+
|
|
261
|
+
return await this.port.withIndexLock(async () => {
|
|
262
|
+
const index = await this.port.readIndex();
|
|
263
|
+
const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
|
|
264
|
+
if (current.run_id !== run_id || current.owner_instance_id !== owner_instance_id) {
|
|
265
|
+
throw {
|
|
266
|
+
normalizedResponse: fail(ERROR_CODES.RUN_LEASE_NOT_OWNED, 'Cannot update feature sessions without run ownership', {
|
|
267
|
+
run_id,
|
|
268
|
+
owner_instance_id,
|
|
269
|
+
active_run_id: current.run_id,
|
|
270
|
+
active_owner_instance_id: current.owner_instance_id,
|
|
271
|
+
retryable: false,
|
|
272
|
+
requires_human: true
|
|
273
|
+
})
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const nextFeatureSessions = {
|
|
278
|
+
...(current.feature_sessions ?? {}),
|
|
279
|
+
[feature_id]: {
|
|
280
|
+
planner_session_id,
|
|
281
|
+
builder_session_id,
|
|
282
|
+
qa_session_id
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
index.runtime_sessions = {
|
|
287
|
+
...current,
|
|
288
|
+
feature_sessions: nextFeatureSessions
|
|
289
|
+
};
|
|
290
|
+
index.version += 1;
|
|
291
|
+
index.updated_at = nowIso();
|
|
292
|
+
await this.port.writeIndex(index);
|
|
293
|
+
return { data: { updated: true } };
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async pruneFeatureSessionAssignments(params: PruneFeatureSessionParams): Promise<{ data: { removed: string[] } }> {
|
|
298
|
+
const active = new Set(params.active_feature_ids);
|
|
299
|
+
return await this.port.withIndexLock(async () => {
|
|
300
|
+
const index = await this.port.readIndex();
|
|
301
|
+
const current = this.port.normalizeRuntimeSessions(index.runtime_sessions);
|
|
302
|
+
if (current.run_id !== params.run_id || current.owner_instance_id !== params.owner_instance_id) {
|
|
303
|
+
throw {
|
|
304
|
+
normalizedResponse: fail(ERROR_CODES.RUN_LEASE_NOT_OWNED, 'Cannot prune feature sessions without run ownership', {
|
|
305
|
+
run_id: params.run_id,
|
|
306
|
+
owner_instance_id: params.owner_instance_id,
|
|
307
|
+
active_run_id: current.run_id,
|
|
308
|
+
active_owner_instance_id: current.owner_instance_id,
|
|
309
|
+
retryable: false,
|
|
310
|
+
requires_human: true
|
|
311
|
+
})
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const existing = current.feature_sessions ?? {};
|
|
316
|
+
const kept: RuntimeSessionsSnapshot['feature_sessions'] = {};
|
|
317
|
+
const removed: string[] = [];
|
|
318
|
+
for (const [featureId, assignment] of Object.entries(existing)) {
|
|
319
|
+
if (active.has(featureId)) {
|
|
320
|
+
kept[featureId] = assignment;
|
|
321
|
+
} else {
|
|
322
|
+
removed.push(featureId);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (removed.length > 0) {
|
|
327
|
+
index.runtime_sessions = {
|
|
328
|
+
...current,
|
|
329
|
+
feature_sessions: kept
|
|
330
|
+
};
|
|
331
|
+
index.version += 1;
|
|
332
|
+
index.updated_at = nowIso();
|
|
333
|
+
await this.port.writeIndex(index);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
removed.sort((a, b) => a.localeCompare(b));
|
|
337
|
+
return { data: { removed } };
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { TOOLS } from '../../core/constants.js';
|
|
2
|
+
|
|
3
|
+
export interface ToolBehaviorMetadata {
|
|
4
|
+
mutating: boolean;
|
|
5
|
+
requires_operation_id: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const MUTATING_TOOLS = [
|
|
9
|
+
TOOLS.FEATURE_INIT,
|
|
10
|
+
TOOLS.FEATURE_STATE_PATCH,
|
|
11
|
+
TOOLS.FEATURE_LOG_APPEND,
|
|
12
|
+
TOOLS.PLAN_SUBMIT,
|
|
13
|
+
TOOLS.PLAN_UPDATE,
|
|
14
|
+
TOOLS.REPO_ENSURE_WORKTREE,
|
|
15
|
+
TOOLS.REPO_APPLY_PATCH,
|
|
16
|
+
TOOLS.GATES_RUN,
|
|
17
|
+
TOOLS.QA_TEST_INDEX_UPDATE,
|
|
18
|
+
TOOLS.LOCKS_ACQUIRE,
|
|
19
|
+
TOOLS.LOCKS_RELEASE,
|
|
20
|
+
TOOLS.FEATURE_READY_TO_MERGE,
|
|
21
|
+
TOOLS.FEATURE_DELETE
|
|
22
|
+
] as const;
|
|
23
|
+
|
|
24
|
+
export const TOOL_BEHAVIOR_METADATA: Readonly<Record<string, ToolBehaviorMetadata>> = Object.freeze(
|
|
25
|
+
Object.fromEntries(
|
|
26
|
+
MUTATING_TOOLS.map((name) => [name, { mutating: true, requires_operation_id: true }])
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export function isMutatingTool(toolName: string): boolean {
|
|
31
|
+
return TOOL_BEHAVIOR_METADATA[toolName]?.mutating ?? false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function toolRequiresOperationId(toolName: string): boolean {
|
|
35
|
+
return TOOL_BEHAVIOR_METADATA[toolName]?.requires_operation_id ?? false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function withOperationIdIfRequired(
|
|
39
|
+
toolName: string,
|
|
40
|
+
args: Record<string, unknown>,
|
|
41
|
+
createOperationId: (toolName: string, featureId?: string) => string
|
|
42
|
+
): Record<string, unknown> {
|
|
43
|
+
if (!toolRequiresOperationId(toolName)) {
|
|
44
|
+
return { ...args };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof args.operation_id === 'string') {
|
|
48
|
+
return { ...args };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const featureId = typeof args.feature_id === 'string' ? args.feature_id : undefined;
|
|
52
|
+
return {
|
|
53
|
+
...args,
|
|
54
|
+
operation_id: createOperationId(toolName, featureId)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface ToolHandlerContext {
|
|
2
|
+
actorType: string;
|
|
3
|
+
actorId: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type ToolHandler = (
|
|
7
|
+
args: Record<string, unknown>,
|
|
8
|
+
context: ToolHandlerContext
|
|
9
|
+
) => Promise<unknown>;
|
|
10
|
+
|
|
11
|
+
export class ToolHandlerRegistry {
|
|
12
|
+
private readonly handlers = new Map<string, ToolHandler>();
|
|
13
|
+
|
|
14
|
+
register(toolName: string, handler: ToolHandler): void {
|
|
15
|
+
this.handlers.set(toolName, handler);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
lookup(toolName: string): ToolHandler | undefined {
|
|
19
|
+
return this.handlers.get(toolName);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class ToolRouter {
|
|
24
|
+
private readonly registry: ToolHandlerRegistry;
|
|
25
|
+
private readonly unknownToolHandler: (toolName: string) => Promise<unknown>;
|
|
26
|
+
|
|
27
|
+
constructor(registry: ToolHandlerRegistry, unknownToolHandler: (toolName: string) => Promise<unknown>) {
|
|
28
|
+
this.registry = registry;
|
|
29
|
+
this.unknownToolHandler = unknownToolHandler;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async route(
|
|
33
|
+
toolName: string,
|
|
34
|
+
args: Record<string, unknown>,
|
|
35
|
+
context: ToolHandlerContext
|
|
36
|
+
): Promise<unknown> {
|
|
37
|
+
const handler = this.registry.lookup(toolName);
|
|
38
|
+
if (!handler) {
|
|
39
|
+
return await this.unknownToolHandler(toolName);
|
|
40
|
+
}
|
|
41
|
+
return await handler(args, context);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env -S tsx
|
|
2
|
+
import { runCli } from '../interfaces/cli/bootstrap.js';
|
|
3
|
+
import type { RuntimeContext } from './types.js';
|
|
4
|
+
|
|
5
|
+
export async function main(
|
|
6
|
+
argv: string[] = process.argv.slice(2),
|
|
7
|
+
runtime: RuntimeContext = { cwd: process.cwd(), env: process.env }
|
|
8
|
+
): Promise<number> {
|
|
9
|
+
return await runCli(argv, runtime);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isDirectExecution(importMetaUrl: string, argv1: string | undefined): boolean {
|
|
13
|
+
return importMetaUrl === `file://${argv1 ?? ''}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function runAsEntrypoint(
|
|
17
|
+
importMetaUrl: string,
|
|
18
|
+
argv1: string | undefined,
|
|
19
|
+
executeMain: () => Promise<number> = () => main()
|
|
20
|
+
): boolean {
|
|
21
|
+
if (!isDirectExecution(importMetaUrl, argv1)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
void executeMain().then((exitCode) => {
|
|
26
|
+
process.exitCode = exitCode;
|
|
27
|
+
});
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
runAsEntrypoint(import.meta.url, process.argv[1]);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ERROR_CODES } from '../core/error-codes.js';
|
|
2
|
+
import type { AppError } from '../providers/providers.js';
|
|
3
|
+
import type { CliOptions, ToolTransport } from './types.js';
|
|
4
|
+
|
|
5
|
+
function parseOptionalBooleanToken(token: string | undefined): boolean | null {
|
|
6
|
+
if (token === 'true') {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (token === 'false') {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class CliArgumentParser {
|
|
16
|
+
parse(argv: string[]): CliOptions {
|
|
17
|
+
const [first, ...rest] = argv;
|
|
18
|
+
const command = first !== undefined && !first.startsWith('-') ? first : 'run';
|
|
19
|
+
const tokens = first !== undefined && !first.startsWith('-') ? rest : argv;
|
|
20
|
+
const options: CliOptions = {
|
|
21
|
+
command: command ?? 'run'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
25
|
+
const token = tokens[index];
|
|
26
|
+
const next = tokens[index + 1];
|
|
27
|
+
|
|
28
|
+
if (token === '-fi') {
|
|
29
|
+
options.file_input = next;
|
|
30
|
+
index += 1;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (token === '-fl') {
|
|
34
|
+
options.folder_input = next;
|
|
35
|
+
index += 1;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (token === '--agent-provider') {
|
|
39
|
+
options.agent_provider = next;
|
|
40
|
+
index += 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (token === '--feature-id') {
|
|
44
|
+
options.feature_id = next;
|
|
45
|
+
index += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (token === '--dry-run') {
|
|
49
|
+
const parsed = parseOptionalBooleanToken(next);
|
|
50
|
+
if (parsed === null) {
|
|
51
|
+
options.dry_run = true;
|
|
52
|
+
} else {
|
|
53
|
+
options.dry_run = parsed;
|
|
54
|
+
index += 1;
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (token === '--yes') {
|
|
59
|
+
options.yes = true;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (token === '--remove-worktree') {
|
|
63
|
+
const parsed = parseOptionalBooleanToken(next);
|
|
64
|
+
if (parsed === null) {
|
|
65
|
+
options.remove_worktree = true;
|
|
66
|
+
} else {
|
|
67
|
+
options.remove_worktree = parsed;
|
|
68
|
+
index += 1;
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (token === '--remove-branch') {
|
|
73
|
+
options.remove_branch = next;
|
|
74
|
+
index += 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (token === '--agent-model') {
|
|
78
|
+
options.agent_model = next;
|
|
79
|
+
index += 1;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (token === '--provider-config-env') {
|
|
83
|
+
options.provider_config_env = next;
|
|
84
|
+
index += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (token === '--transport') {
|
|
88
|
+
options.transport = next;
|
|
89
|
+
index += 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (token === '--takeover-stale-run') {
|
|
93
|
+
options.takeover_stale_run = true;
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return options;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
resolveTransport(option: string | undefined): ToolTransport {
|
|
102
|
+
const raw = (option ?? 'mcp').toLowerCase();
|
|
103
|
+
if (raw === 'inprocess' || raw === 'mcp') {
|
|
104
|
+
return raw;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const error = new Error(ERROR_CODES.INVALID_CLI_ARGS) as AppError;
|
|
108
|
+
error.code = ERROR_CODES.INVALID_CLI_ARGS;
|
|
109
|
+
error.details = {
|
|
110
|
+
reason: 'Invalid --transport value',
|
|
111
|
+
provided: option,
|
|
112
|
+
expected: ['inprocess', 'mcp']
|
|
113
|
+
};
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ERROR_CODES } from '../core/error-codes.js';
|
|
2
|
+
import { TOOLS } from '../core/constants.js';
|
|
3
|
+
import type { AppError } from '../providers/providers.js';
|
|
4
|
+
import type { ToolClient } from '../mcp/tool-client.js';
|
|
5
|
+
import type { CliOptions, RemoveBranchMode } from './types.js';
|
|
6
|
+
import { callCliTool } from './tooling.js';
|
|
7
|
+
|
|
8
|
+
function isValidFeatureId(value: string): boolean {
|
|
9
|
+
return /^[a-z0-9_][a-z0-9_-]*$/.test(value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function asRemoveBranchMode(value: string | undefined): RemoveBranchMode | null {
|
|
13
|
+
if (value === undefined) {
|
|
14
|
+
return 'none';
|
|
15
|
+
}
|
|
16
|
+
if (value === 'none' || value === 'safe' || value === 'force') {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function invalidCliArgs(details: Record<string, unknown>): never {
|
|
23
|
+
const error = new Error(ERROR_CODES.INVALID_CLI_ARGS) as AppError;
|
|
24
|
+
error.code = ERROR_CODES.INVALID_CLI_ARGS;
|
|
25
|
+
error.details = details;
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class DeleteCommandHandler {
|
|
30
|
+
private readonly toolClient: ToolClient;
|
|
31
|
+
private readonly runId: string;
|
|
32
|
+
|
|
33
|
+
constructor(toolClient: ToolClient, runId: string) {
|
|
34
|
+
this.toolClient = toolClient;
|
|
35
|
+
this.runId = runId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async execute(options: CliOptions): Promise<unknown> {
|
|
39
|
+
const featureId = options.feature_id;
|
|
40
|
+
if (!featureId) {
|
|
41
|
+
invalidCliArgs({
|
|
42
|
+
reason: '--feature-id is required for delete',
|
|
43
|
+
expected: '--feature-id <feature_id>'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (!isValidFeatureId(featureId)) {
|
|
47
|
+
invalidCliArgs({
|
|
48
|
+
reason: 'Invalid --feature-id value',
|
|
49
|
+
provided: featureId,
|
|
50
|
+
expected_pattern: '^[a-z0-9_][a-z0-9_-]*$'
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const removeBranch = asRemoveBranchMode(options.remove_branch);
|
|
55
|
+
if (removeBranch === null) {
|
|
56
|
+
invalidCliArgs({
|
|
57
|
+
reason: 'Invalid --remove-branch value',
|
|
58
|
+
provided: options.remove_branch,
|
|
59
|
+
expected: ['none', 'safe', 'force']
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (options.yes !== true && options.dry_run === false) {
|
|
64
|
+
invalidCliArgs({
|
|
65
|
+
reason: 'Destructive delete requires --yes',
|
|
66
|
+
expected: 'Provide --yes or omit --dry-run=false'
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const dryRun = options.yes === true ? (options.dry_run ?? false) : true;
|
|
71
|
+
const confirm = options.yes === true;
|
|
72
|
+
const removeWorktree = options.remove_worktree ?? true;
|
|
73
|
+
|
|
74
|
+
const response = await callCliTool(this.toolClient, this.runId, TOOLS.FEATURE_DELETE, {
|
|
75
|
+
feature_id: featureId,
|
|
76
|
+
dry_run: dryRun,
|
|
77
|
+
confirm,
|
|
78
|
+
remove_worktree: removeWorktree,
|
|
79
|
+
remove_branch: removeBranch
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
ok: true,
|
|
84
|
+
data: {
|
|
85
|
+
command: 'delete',
|
|
86
|
+
...(response.data ?? {})
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function printPayload(payload: unknown): void {
|
|
2
|
+
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function printError(code: string, message: string, details: Record<string, unknown> = {}): void {
|
|
6
|
+
printPayload({
|
|
7
|
+
ok: false,
|
|
8
|
+
error: {
|
|
9
|
+
code,
|
|
10
|
+
message,
|
|
11
|
+
details
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|