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,693 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { LockService } from '../src/application/services/lock-service.js';
|
|
6
|
+
import { ReportingService } from '../src/application/services/reporting-service.js';
|
|
7
|
+
import { RunLeaseService } from '../src/application/services/run-lease-service.js';
|
|
8
|
+
import { stableHash } from '../src/core/fs.js';
|
|
9
|
+
import { ERROR_CODES } from '../src/core/error-codes.js';
|
|
10
|
+
import { STATUS } from '../src/core/constants.js';
|
|
11
|
+
import type { RuntimeSessionsSnapshot } from '../src/core/runtime-sessions.js';
|
|
12
|
+
|
|
13
|
+
type AnyRecord = Record<string, any>;
|
|
14
|
+
|
|
15
|
+
function clone<T>(value: T): T {
|
|
16
|
+
return JSON.parse(JSON.stringify(value)) as T;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function makeRuntimeSessions(overrides: AnyRecord = {}): AnyRecord {
|
|
20
|
+
const now = new Date().toISOString();
|
|
21
|
+
return {
|
|
22
|
+
run_id: 'none',
|
|
23
|
+
orchestrator_session_id: 'unknown',
|
|
24
|
+
provider: 'unknown',
|
|
25
|
+
model: 'unknown',
|
|
26
|
+
provider_config_ref_hash: stableHash('none'),
|
|
27
|
+
owner_instance_id: 'none',
|
|
28
|
+
lease_id: 'none',
|
|
29
|
+
started_at: now,
|
|
30
|
+
last_heartbeat_at: now,
|
|
31
|
+
lease_expires_at: now,
|
|
32
|
+
orchestrator_epoch: 0,
|
|
33
|
+
feature_sessions: {},
|
|
34
|
+
...overrides
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function makeIndex(overrides: AnyRecord = {}): AnyRecord {
|
|
39
|
+
return {
|
|
40
|
+
version: 1,
|
|
41
|
+
active: [],
|
|
42
|
+
blocked: [],
|
|
43
|
+
merged: [],
|
|
44
|
+
locks: {
|
|
45
|
+
openapi: null,
|
|
46
|
+
db_migrations: null
|
|
47
|
+
},
|
|
48
|
+
lock_leases: {
|
|
49
|
+
openapi: null,
|
|
50
|
+
db_migrations: null
|
|
51
|
+
},
|
|
52
|
+
blocked_queue: [],
|
|
53
|
+
updated_at: new Date().toISOString(),
|
|
54
|
+
runtime_sessions: makeRuntimeSessions(),
|
|
55
|
+
...overrides
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function makeRunLeaseHarness(initialIndex: AnyRecord = makeIndex()) {
|
|
60
|
+
let index = clone(initialIndex);
|
|
61
|
+
const writes: AnyRecord[] = [];
|
|
62
|
+
|
|
63
|
+
const normalizeRuntimeSessions = (value: unknown): RuntimeSessionsSnapshot => {
|
|
64
|
+
const source = value && typeof value === 'object' ? (value as AnyRecord) : {};
|
|
65
|
+
const fallback = makeRuntimeSessions() as RuntimeSessionsSnapshot;
|
|
66
|
+
return {
|
|
67
|
+
...fallback,
|
|
68
|
+
...source,
|
|
69
|
+
feature_sessions:
|
|
70
|
+
source.feature_sessions && typeof source.feature_sessions === 'object'
|
|
71
|
+
? source.feature_sessions
|
|
72
|
+
: {}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const emptyRuntimeSessions = (at?: string): RuntimeSessionsSnapshot =>
|
|
77
|
+
makeRuntimeSessions({
|
|
78
|
+
started_at: at ?? new Date().toISOString(),
|
|
79
|
+
last_heartbeat_at: at ?? new Date().toISOString(),
|
|
80
|
+
lease_expires_at: at ?? new Date().toISOString()
|
|
81
|
+
}) as RuntimeSessionsSnapshot;
|
|
82
|
+
|
|
83
|
+
const service = new RunLeaseService({
|
|
84
|
+
runLeaseTtlSeconds: () => 30,
|
|
85
|
+
withIndexLock: async <T>(operation: () => Promise<T>) => await operation(),
|
|
86
|
+
readIndex: async () => clone(index),
|
|
87
|
+
writeIndex: async (nextIndex: AnyRecord) => {
|
|
88
|
+
index = clone(nextIndex);
|
|
89
|
+
writes.push(clone(nextIndex));
|
|
90
|
+
},
|
|
91
|
+
normalizeRuntimeSessions,
|
|
92
|
+
isRunLeaseFresh: (runtimeSessions: AnyRecord) => new Date(runtimeSessions.lease_expires_at).getTime() > Date.now(),
|
|
93
|
+
emptyRuntimeSessions
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
service,
|
|
98
|
+
getIndex: () => clone(index),
|
|
99
|
+
writes
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function makeLockPolicy(overrides: AnyRecord = {}): AnyRecord {
|
|
104
|
+
const lockDefaults = {
|
|
105
|
+
resources: ['openapi', 'db_migrations'],
|
|
106
|
+
lease_ttl_seconds: 60,
|
|
107
|
+
acquire_behavior: 'wait',
|
|
108
|
+
default_wait_timeout_seconds: 1,
|
|
109
|
+
acquire_backoff: {
|
|
110
|
+
initial_ms: 1,
|
|
111
|
+
max_ms: 4,
|
|
112
|
+
multiplier: 2,
|
|
113
|
+
jitter_ms: 0
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const lockOverrides = overrides.locks ?? {};
|
|
117
|
+
return {
|
|
118
|
+
...overrides,
|
|
119
|
+
locks: {
|
|
120
|
+
...lockDefaults,
|
|
121
|
+
...lockOverrides,
|
|
122
|
+
acquire_backoff: {
|
|
123
|
+
...lockDefaults.acquire_backoff,
|
|
124
|
+
...(lockOverrides.acquire_backoff ?? {})
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function makeLockHarness(options: {
|
|
131
|
+
policy?: AnyRecord;
|
|
132
|
+
index?: AnyRecord;
|
|
133
|
+
states?: Record<string, AnyRecord>;
|
|
134
|
+
} = {}) {
|
|
135
|
+
let index = clone(options.index ?? makeIndex());
|
|
136
|
+
const states = new Map<string, AnyRecord>(
|
|
137
|
+
Object.entries(
|
|
138
|
+
options.states ?? {
|
|
139
|
+
feature_a: {
|
|
140
|
+
version: 1,
|
|
141
|
+
status: STATUS.PLANNING,
|
|
142
|
+
locks: { held: [] }
|
|
143
|
+
},
|
|
144
|
+
feature_b: {
|
|
145
|
+
version: 1,
|
|
146
|
+
status: STATUS.PLANNING,
|
|
147
|
+
locks: { held: [] }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
const policy = makeLockPolicy(options.policy);
|
|
153
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-lock-service-'));
|
|
154
|
+
|
|
155
|
+
const service = new LockService({
|
|
156
|
+
withIndexLock: async <T>(operation: () => Promise<T>) => await operation(),
|
|
157
|
+
readIndex: async () => clone(index),
|
|
158
|
+
writeIndex: async (nextIndex: AnyRecord) => {
|
|
159
|
+
index = clone(nextIndex);
|
|
160
|
+
},
|
|
161
|
+
updateState: async (featureId: string, _expectedVersion: number | null, updater: any) => {
|
|
162
|
+
const existing = states.get(featureId) ?? { version: 1, status: STATUS.PLANNING, locks: { held: [] } };
|
|
163
|
+
const updateResult = await updater(clone(existing), '');
|
|
164
|
+
const next = {
|
|
165
|
+
...existing,
|
|
166
|
+
...(updateResult.frontMatter ?? {})
|
|
167
|
+
};
|
|
168
|
+
states.set(featureId, next);
|
|
169
|
+
return clone(next);
|
|
170
|
+
},
|
|
171
|
+
statePath: (featureId: string) => path.join(tmpDir, `${featureId}.state.md`),
|
|
172
|
+
getPolicySnapshot: () => policy
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
service,
|
|
177
|
+
policy,
|
|
178
|
+
tmpDir,
|
|
179
|
+
setIndex: (nextIndex: AnyRecord) => {
|
|
180
|
+
index = clone(nextIndex);
|
|
181
|
+
},
|
|
182
|
+
getIndex: () => clone(index),
|
|
183
|
+
getState: (featureId: string) => clone(states.get(featureId)),
|
|
184
|
+
writeStateFile: async (featureId: string) => {
|
|
185
|
+
const filePath = path.join(tmpDir, `${featureId}.state.md`);
|
|
186
|
+
await fs.writeFile(filePath, '---\nfeature_id: test\n---\n', 'utf8');
|
|
187
|
+
},
|
|
188
|
+
cleanup: async () => await fs.rm(tmpDir, { recursive: true, force: true })
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function makeReportingHarness() {
|
|
193
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-reporting-service-'));
|
|
194
|
+
const stateMap = new Map<string, AnyRecord>();
|
|
195
|
+
const plans: AnyRecord[] = [];
|
|
196
|
+
let index = makeIndex({
|
|
197
|
+
active: ['feature_a'],
|
|
198
|
+
blocked: ['feature_b'],
|
|
199
|
+
merged: ['feature_c'],
|
|
200
|
+
locks: {
|
|
201
|
+
openapi: 'feature_lock',
|
|
202
|
+
db_migrations: null
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const ensureState = async (featureId: string, frontMatter: AnyRecord) => {
|
|
207
|
+
const featureDir = path.join(tmpDir, featureId);
|
|
208
|
+
await fs.mkdir(featureDir, { recursive: true });
|
|
209
|
+
await fs.writeFile(path.join(featureDir, 'state.md'), '# state\n', 'utf8');
|
|
210
|
+
stateMap.set(featureId, frontMatter);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const service = new ReportingService({
|
|
214
|
+
collectAcceptedPlans: async () => clone(plans),
|
|
215
|
+
getPolicySnapshot: () => ({
|
|
216
|
+
exclusive_areas: ['libs/core'],
|
|
217
|
+
protected_areas: ['agentic/orchestrator']
|
|
218
|
+
}),
|
|
219
|
+
readIndex: async () => clone(index),
|
|
220
|
+
statePath: (featureId: string) => path.join(tmpDir, featureId, 'state.md'),
|
|
221
|
+
readState: async (featureId: string) => ({
|
|
222
|
+
frontMatter: clone(stateMap.get(featureId) ?? {})
|
|
223
|
+
}),
|
|
224
|
+
featureStateGet: async (featureId: string) => ({
|
|
225
|
+
data: {
|
|
226
|
+
front_matter: clone(stateMap.get(featureId) ?? {})
|
|
227
|
+
}
|
|
228
|
+
}),
|
|
229
|
+
repoDiffBundle: async () => ({
|
|
230
|
+
data: {
|
|
231
|
+
diff_stat: '1 file changed',
|
|
232
|
+
touched_files: ['src/example.ts'],
|
|
233
|
+
last_gate_summary: { overall: 'pass' }
|
|
234
|
+
}
|
|
235
|
+
}),
|
|
236
|
+
qaTestIndexGet: async () => ({
|
|
237
|
+
data: {
|
|
238
|
+
summary: {
|
|
239
|
+
required_total: 1,
|
|
240
|
+
pending_required: 0
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
service,
|
|
248
|
+
plans,
|
|
249
|
+
setIndex: (nextIndex: AnyRecord) => {
|
|
250
|
+
index = clone(nextIndex);
|
|
251
|
+
},
|
|
252
|
+
ensureState,
|
|
253
|
+
cleanup: async () => await fs.rm(tmpDir, { recursive: true, force: true })
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
describe('RunLeaseService', () => {
|
|
258
|
+
it('rejects invalid acquisition input and protects fresh leases', async () => {
|
|
259
|
+
const freshLease = makeRuntimeSessions({
|
|
260
|
+
run_id: 'run:existing',
|
|
261
|
+
owner_instance_id: 'owner:existing',
|
|
262
|
+
lease_expires_at: new Date(Date.now() + 60_000).toISOString()
|
|
263
|
+
});
|
|
264
|
+
const { service } = makeRunLeaseHarness(makeIndex({ runtime_sessions: freshLease }));
|
|
265
|
+
|
|
266
|
+
await expect(
|
|
267
|
+
service.acquireRunLease({
|
|
268
|
+
run_id: '',
|
|
269
|
+
owner_instance_id: 'owner:new',
|
|
270
|
+
provider: 'provider',
|
|
271
|
+
model: 'model',
|
|
272
|
+
provider_config_ref_hash: ''
|
|
273
|
+
} as any)
|
|
274
|
+
).rejects.toMatchObject({
|
|
275
|
+
normalizedResponse: { error: { code: ERROR_CODES.INVALID_ARGUMENT } }
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
await expect(
|
|
279
|
+
service.acquireRunLease({
|
|
280
|
+
run_id: 'run:new',
|
|
281
|
+
owner_instance_id: 'owner:new',
|
|
282
|
+
provider: 'provider',
|
|
283
|
+
model: 'model',
|
|
284
|
+
provider_config_ref_hash: ''
|
|
285
|
+
})
|
|
286
|
+
).rejects.toMatchObject({
|
|
287
|
+
normalizedResponse: {
|
|
288
|
+
error: {
|
|
289
|
+
code: ERROR_CODES.RUN_ALREADY_ACTIVE,
|
|
290
|
+
details: { stale: false }
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('enforces explicit takeover for stale leases and allows takeover when requested', async () => {
|
|
297
|
+
const staleLease = makeRuntimeSessions({
|
|
298
|
+
run_id: 'run:stale',
|
|
299
|
+
owner_instance_id: 'owner:stale',
|
|
300
|
+
orchestrator_session_id: 'orch:old',
|
|
301
|
+
feature_sessions: { feature_x: { planner_session_id: 'p', builder_session_id: 'b', qa_session_id: 'q' } },
|
|
302
|
+
lease_expires_at: new Date(Date.now() - 60_000).toISOString()
|
|
303
|
+
});
|
|
304
|
+
const harness = makeRunLeaseHarness(makeIndex({ runtime_sessions: staleLease }));
|
|
305
|
+
|
|
306
|
+
await expect(
|
|
307
|
+
harness.service.acquireRunLease({
|
|
308
|
+
run_id: 'run:new',
|
|
309
|
+
owner_instance_id: 'owner:new',
|
|
310
|
+
provider: 'provider',
|
|
311
|
+
model: 'model',
|
|
312
|
+
provider_config_ref_hash: '',
|
|
313
|
+
takeover_stale_run: false
|
|
314
|
+
})
|
|
315
|
+
).rejects.toMatchObject({
|
|
316
|
+
normalizedResponse: {
|
|
317
|
+
error: {
|
|
318
|
+
code: ERROR_CODES.RUN_ALREADY_ACTIVE,
|
|
319
|
+
details: { stale: true, requires_takeover: true }
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const takeover = await harness.service.acquireRunLease({
|
|
325
|
+
run_id: 'run:new',
|
|
326
|
+
owner_instance_id: 'owner:new',
|
|
327
|
+
provider: 'provider',
|
|
328
|
+
model: 'model',
|
|
329
|
+
provider_config_ref_hash: '',
|
|
330
|
+
takeover_stale_run: true
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
expect(takeover.data.took_over_stale).toBe(true);
|
|
334
|
+
expect(takeover.data.reused_existing_owner).toBe(false);
|
|
335
|
+
expect(takeover.data.runtime_sessions.orchestrator_session_id).toBe('unknown');
|
|
336
|
+
expect(takeover.data.runtime_sessions.feature_sessions).toEqual({});
|
|
337
|
+
expect(takeover.data.runtime_sessions.provider_config_ref_hash).toBe(stableHash('none'));
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('renews, updates, prunes, and releases when owner matches', async () => {
|
|
341
|
+
const initial = makeRuntimeSessions({
|
|
342
|
+
run_id: 'run:owner',
|
|
343
|
+
owner_instance_id: 'owner:owner',
|
|
344
|
+
started_at: '2026-01-01T00:00:00.000Z',
|
|
345
|
+
last_heartbeat_at: '2026-01-01T00:00:00.000Z',
|
|
346
|
+
lease_expires_at: '2026-01-01T00:00:30.000Z',
|
|
347
|
+
feature_sessions: {
|
|
348
|
+
keep_feature: { planner_session_id: 'p1', builder_session_id: 'b1', qa_session_id: 'q1' },
|
|
349
|
+
stale_feature: { planner_session_id: 'p2', builder_session_id: 'b2', qa_session_id: 'q2' }
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
const harness = makeRunLeaseHarness(makeIndex({ runtime_sessions: initial }));
|
|
353
|
+
|
|
354
|
+
const renewed = await harness.service.renewRunLease('run:owner', 'owner:owner');
|
|
355
|
+
expect(typeof renewed.data.lease_expires_at).toBe('string');
|
|
356
|
+
|
|
357
|
+
await harness.service.updateOrchestratorSession({
|
|
358
|
+
run_id: 'run:owner',
|
|
359
|
+
owner_instance_id: 'owner:owner',
|
|
360
|
+
orchestrator_session_id: 'orch:new',
|
|
361
|
+
increment_epoch: true
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
await harness.service.updateFeatureSessionAssignment({
|
|
365
|
+
run_id: 'run:owner',
|
|
366
|
+
owner_instance_id: 'owner:owner',
|
|
367
|
+
feature_id: 'keep_feature',
|
|
368
|
+
planner_session_id: 'p-next',
|
|
369
|
+
builder_session_id: 'b-next',
|
|
370
|
+
qa_session_id: 'q-next'
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const pruned = await harness.service.pruneFeatureSessionAssignments({
|
|
374
|
+
run_id: 'run:owner',
|
|
375
|
+
owner_instance_id: 'owner:owner',
|
|
376
|
+
active_feature_ids: ['keep_feature']
|
|
377
|
+
});
|
|
378
|
+
expect(pruned.data.removed).toEqual(['stale_feature']);
|
|
379
|
+
|
|
380
|
+
const released = await harness.service.releaseRunLease('run:owner', 'owner:owner');
|
|
381
|
+
expect(released.data.released).toBe(true);
|
|
382
|
+
expect(harness.getIndex().runtime_sessions.run_id).toBe('none');
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('reuses existing owner metadata and rejects not-owned lease operations', async () => {
|
|
386
|
+
const existing = makeRuntimeSessions({
|
|
387
|
+
run_id: 'run:same',
|
|
388
|
+
owner_instance_id: 'owner:same',
|
|
389
|
+
started_at: '2026-01-01T00:00:00.000Z',
|
|
390
|
+
lease_expires_at: new Date(Date.now() + 60_000).toISOString()
|
|
391
|
+
});
|
|
392
|
+
const harness = makeRunLeaseHarness(makeIndex({ runtime_sessions: existing }));
|
|
393
|
+
|
|
394
|
+
const reused = await harness.service.acquireRunLease({
|
|
395
|
+
run_id: 'run:same',
|
|
396
|
+
owner_instance_id: 'owner:same',
|
|
397
|
+
provider: 'provider',
|
|
398
|
+
model: 'model',
|
|
399
|
+
provider_config_ref_hash: 'hash'
|
|
400
|
+
});
|
|
401
|
+
expect(reused.data.reused_existing_owner).toBe(true);
|
|
402
|
+
expect(reused.data.runtime_sessions.started_at).toBe('2026-01-01T00:00:00.000Z');
|
|
403
|
+
|
|
404
|
+
await expect(harness.service.renewRunLease('', '')).rejects.toMatchObject({
|
|
405
|
+
normalizedResponse: { error: { code: ERROR_CODES.INVALID_ARGUMENT } }
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
await expect(harness.service.renewRunLease('run:other', 'owner:other')).rejects.toMatchObject({
|
|
409
|
+
normalizedResponse: { error: { code: ERROR_CODES.RUN_LEASE_NOT_OWNED } }
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const notReleased = await harness.service.releaseRunLease('run:other', 'owner:other');
|
|
413
|
+
expect(notReleased.data.released).toBe(false);
|
|
414
|
+
|
|
415
|
+
await expect(
|
|
416
|
+
harness.service.updateOrchestratorSession({
|
|
417
|
+
run_id: '',
|
|
418
|
+
owner_instance_id: 'owner:same',
|
|
419
|
+
orchestrator_session_id: ''
|
|
420
|
+
} as any)
|
|
421
|
+
).rejects.toMatchObject({
|
|
422
|
+
normalizedResponse: { error: { code: ERROR_CODES.INVALID_ARGUMENT } }
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
await expect(
|
|
426
|
+
harness.service.updateFeatureSessionAssignment({
|
|
427
|
+
run_id: 'run:other',
|
|
428
|
+
owner_instance_id: 'owner:other',
|
|
429
|
+
feature_id: 'feature_a',
|
|
430
|
+
planner_session_id: 'planner',
|
|
431
|
+
builder_session_id: 'builder',
|
|
432
|
+
qa_session_id: 'qa'
|
|
433
|
+
})
|
|
434
|
+
).rejects.toMatchObject({
|
|
435
|
+
normalizedResponse: { error: { code: ERROR_CODES.RUN_LEASE_NOT_OWNED } }
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
await expect(
|
|
439
|
+
harness.service.pruneFeatureSessionAssignments({
|
|
440
|
+
run_id: 'run:other',
|
|
441
|
+
owner_instance_id: 'owner:other',
|
|
442
|
+
active_feature_ids: []
|
|
443
|
+
})
|
|
444
|
+
).rejects.toMatchObject({
|
|
445
|
+
normalizedResponse: { error: { code: ERROR_CODES.RUN_LEASE_NOT_OWNED } }
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
describe('LockService', () => {
|
|
451
|
+
const cleanups: Array<() => Promise<void>> = [];
|
|
452
|
+
|
|
453
|
+
afterEach(async () => {
|
|
454
|
+
while (cleanups.length > 0) {
|
|
455
|
+
const cleanup = cleanups.pop();
|
|
456
|
+
if (cleanup) {
|
|
457
|
+
await cleanup();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it('acquires and releases lock resources while rejecting invalid arguments', async () => {
|
|
463
|
+
const harness = await makeLockHarness();
|
|
464
|
+
cleanups.push(harness.cleanup);
|
|
465
|
+
|
|
466
|
+
await expect(harness.service.locksAcquire('missing', 'feature_a')).rejects.toMatchObject({
|
|
467
|
+
normalizedResponse: { error: { code: ERROR_CODES.INVALID_ARGUMENT } }
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
await expect(harness.service.locksAcquire('openapi', null)).rejects.toMatchObject({
|
|
471
|
+
normalizedResponse: { error: { code: ERROR_CODES.INVALID_ARGUMENT } }
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
const acquired = await harness.service.locksAcquire('openapi', 'feature_a');
|
|
475
|
+
expect(acquired.data.feature_id).toBe('feature_a');
|
|
476
|
+
expect(harness.getState('feature_a').locks.held).toContain('openapi');
|
|
477
|
+
|
|
478
|
+
await expect(harness.service.locksRelease('openapi', 'feature_b')).rejects.toMatchObject({
|
|
479
|
+
normalizedResponse: { error: { code: ERROR_CODES.LOCK_CONFLICT } }
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
const released = await harness.service.locksRelease('openapi', 'feature_a');
|
|
483
|
+
expect(released.data.released).toBe(true);
|
|
484
|
+
expect(harness.getState('feature_a').locks.held).toEqual([]);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it('reclaims stale locks, supports fail-fast behavior, renews, and recovers expired leases', async () => {
|
|
488
|
+
const staleIndex = makeIndex({
|
|
489
|
+
active: ['feature_a'],
|
|
490
|
+
locks: {
|
|
491
|
+
openapi: 'feature_old',
|
|
492
|
+
db_migrations: 'feature_b'
|
|
493
|
+
},
|
|
494
|
+
lock_leases: {
|
|
495
|
+
openapi: {
|
|
496
|
+
holder: 'feature_old',
|
|
497
|
+
lease_id: 'lease-old',
|
|
498
|
+
expires_at: new Date(Date.now() - 60_000).toISOString()
|
|
499
|
+
},
|
|
500
|
+
db_migrations: {
|
|
501
|
+
holder: 'feature_b',
|
|
502
|
+
lease_id: 'lease-b',
|
|
503
|
+
expires_at: new Date(Date.now() + 60_000).toISOString()
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
const harness = await makeLockHarness({
|
|
508
|
+
index: staleIndex,
|
|
509
|
+
policy: {
|
|
510
|
+
locks: {
|
|
511
|
+
acquire_behavior: 'wait',
|
|
512
|
+
default_wait_timeout_seconds: 1
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
cleanups.push(harness.cleanup);
|
|
517
|
+
|
|
518
|
+
const reclaimed = await harness.service.locksAcquire('openapi', 'feature_a');
|
|
519
|
+
expect(reclaimed.data.stale_reclaimed).toBe(true);
|
|
520
|
+
expect(reclaimed.evidence?.code).toBe(ERROR_CODES.STALE_LOCK_RECLAIMED);
|
|
521
|
+
|
|
522
|
+
await harness.service.renewLeases(['feature_a']);
|
|
523
|
+
const renewed = harness.getIndex();
|
|
524
|
+
expect(renewed.lock_leases.openapi.holder).toBe('feature_a');
|
|
525
|
+
expect(renewed.lock_leases.db_migrations.holder).toBe('feature_b');
|
|
526
|
+
|
|
527
|
+
const expiredSnapshot = harness.getIndex();
|
|
528
|
+
expiredSnapshot.locks.openapi = 'feature_a';
|
|
529
|
+
expiredSnapshot.lock_leases.openapi = {
|
|
530
|
+
holder: 'feature_a',
|
|
531
|
+
lease_id: 'lease-stale',
|
|
532
|
+
expires_at: new Date(Date.now() - 60_000).toISOString()
|
|
533
|
+
};
|
|
534
|
+
harness.setIndex(expiredSnapshot);
|
|
535
|
+
|
|
536
|
+
await harness.writeStateFile('feature_a');
|
|
537
|
+
const recovered = await harness.service.recoverFromState();
|
|
538
|
+
expect(recovered.data.recovered).toBe(true);
|
|
539
|
+
expect(recovered.data.stale_features).toContain('feature_a');
|
|
540
|
+
expect(harness.getState('feature_a').status).toBe(STATUS.BLOCKED);
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
it('fails fast when configured and lock is held by another feature', async () => {
|
|
544
|
+
const harness = await makeLockHarness({
|
|
545
|
+
policy: {
|
|
546
|
+
locks: {
|
|
547
|
+
acquire_behavior: 'fail'
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
index: makeIndex({
|
|
551
|
+
locks: {
|
|
552
|
+
openapi: 'feature_other',
|
|
553
|
+
db_migrations: null
|
|
554
|
+
},
|
|
555
|
+
lock_leases: {
|
|
556
|
+
openapi: {
|
|
557
|
+
holder: 'feature_other',
|
|
558
|
+
lease_id: 'lease-1',
|
|
559
|
+
expires_at: new Date(Date.now() + 60_000).toISOString()
|
|
560
|
+
},
|
|
561
|
+
db_migrations: null
|
|
562
|
+
}
|
|
563
|
+
})
|
|
564
|
+
});
|
|
565
|
+
cleanups.push(harness.cleanup);
|
|
566
|
+
|
|
567
|
+
await expect(harness.service.locksAcquire('openapi', 'feature_a')).rejects.toMatchObject({
|
|
568
|
+
normalizedResponse: { error: { code: ERROR_CODES.LOCK_CONFLICT } }
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
it('times out in wait mode and handles missing release arguments', async () => {
|
|
573
|
+
const harness = await makeLockHarness({
|
|
574
|
+
policy: {
|
|
575
|
+
locks: {
|
|
576
|
+
acquire_behavior: undefined,
|
|
577
|
+
default_wait_timeout_seconds: 0
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
states: {
|
|
581
|
+
feature_a: {
|
|
582
|
+
version: 1,
|
|
583
|
+
status: STATUS.PLANNING
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
index: makeIndex({
|
|
587
|
+
locks: {
|
|
588
|
+
openapi: 'feature_other',
|
|
589
|
+
db_migrations: null
|
|
590
|
+
},
|
|
591
|
+
lock_leases: {
|
|
592
|
+
openapi: {
|
|
593
|
+
holder: 'feature_other',
|
|
594
|
+
lease_id: 'lease-wait',
|
|
595
|
+
expires_at: new Date(Date.now() + 60_000).toISOString()
|
|
596
|
+
},
|
|
597
|
+
db_migrations: null
|
|
598
|
+
}
|
|
599
|
+
})
|
|
600
|
+
});
|
|
601
|
+
cleanups.push(harness.cleanup);
|
|
602
|
+
|
|
603
|
+
await expect(harness.service.locksAcquire('openapi', 'feature_a', 0)).rejects.toMatchObject({
|
|
604
|
+
normalizedResponse: { error: { code: ERROR_CODES.LOCK_CONFLICT } }
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
await expect(harness.service.locksRelease(null, null)).rejects.toMatchObject({
|
|
608
|
+
normalizedResponse: { error: { code: ERROR_CODES.INVALID_ARGUMENT } }
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
await harness.service.locksRelease('db_migrations', 'feature_a');
|
|
612
|
+
expect(harness.getState('feature_a').locks.held).toEqual([]);
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
describe('ReportingService', () => {
|
|
617
|
+
const cleanups: Array<() => Promise<void>> = [];
|
|
618
|
+
|
|
619
|
+
afterEach(async () => {
|
|
620
|
+
while (cleanups.length > 0) {
|
|
621
|
+
const cleanup = cleanups.pop();
|
|
622
|
+
if (cleanup) {
|
|
623
|
+
await cleanup();
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
it('builds collision matrix and dashboard summaries', async () => {
|
|
629
|
+
const harness = await makeReportingHarness();
|
|
630
|
+
cleanups.push(harness.cleanup);
|
|
631
|
+
|
|
632
|
+
harness.plans.push(
|
|
633
|
+
{
|
|
634
|
+
feature_id: 'feature_a',
|
|
635
|
+
files: { modify: ['src/shared.ts'] },
|
|
636
|
+
allowed_areas: ['libs/core'],
|
|
637
|
+
contracts: { openapi: 'none', events: 'none', db: 'none' }
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
feature_id: 'feature_b',
|
|
641
|
+
files: { create: ['src/shared.ts'] },
|
|
642
|
+
allowed_areas: ['libs/core/module'],
|
|
643
|
+
contracts: { openapi: 'none', events: 'none', db: 'none' }
|
|
644
|
+
}
|
|
645
|
+
);
|
|
646
|
+
|
|
647
|
+
await harness.ensureState('feature_a', {
|
|
648
|
+
status: STATUS.BUILDING,
|
|
649
|
+
locks: { held: ['openapi'] },
|
|
650
|
+
gate_profile: 'default',
|
|
651
|
+
gates: { plan: 'pass' },
|
|
652
|
+
last_updated: '2026-01-01T00:00:00.000Z'
|
|
653
|
+
});
|
|
654
|
+
await harness.ensureState('feature_lock', {
|
|
655
|
+
status: STATUS.BLOCKED,
|
|
656
|
+
locks: { held: [] },
|
|
657
|
+
gate_profile: 'default',
|
|
658
|
+
gates: { plan: 'na' },
|
|
659
|
+
last_updated: '2026-01-02T00:00:00.000Z'
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
const collisions = await harness.service.collisionsScan();
|
|
663
|
+
expect(collisions.data.collisions).toHaveLength(1);
|
|
664
|
+
expect(collisions.data.collisions[0].feature_id).toBe('feature_a');
|
|
665
|
+
expect(typeof collisions.data.collisions[0].fingerprint).toBe('string');
|
|
666
|
+
|
|
667
|
+
const dashboard = await harness.service.reportDashboard();
|
|
668
|
+
expect(dashboard.data.features.map((item: AnyRecord) => item.feature_id)).toEqual(['feature_a', 'feature_lock']);
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
it('aggregates feature summary from state, diff bundle, and qa index', async () => {
|
|
672
|
+
const harness = await makeReportingHarness();
|
|
673
|
+
cleanups.push(harness.cleanup);
|
|
674
|
+
await harness.ensureState('feature_summary', {
|
|
675
|
+
status: STATUS.QA,
|
|
676
|
+
gates: { full: 'pass' },
|
|
677
|
+
locks: { held: [] }
|
|
678
|
+
});
|
|
679
|
+
harness.setIndex(
|
|
680
|
+
makeIndex({
|
|
681
|
+
active: ['feature_summary'],
|
|
682
|
+
blocked: [],
|
|
683
|
+
merged: []
|
|
684
|
+
})
|
|
685
|
+
);
|
|
686
|
+
|
|
687
|
+
const summary = await harness.service.reportFeatureSummary('feature_summary');
|
|
688
|
+
expect(summary.data.feature_id).toBe('feature_summary');
|
|
689
|
+
expect(summary.data.state.status).toBe(STATUS.QA);
|
|
690
|
+
expect(summary.data.touched_files).toEqual(['src/example.ts']);
|
|
691
|
+
expect(summary.data.qa_summary.pending_required).toBe(0);
|
|
692
|
+
});
|
|
693
|
+
});
|