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,776 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { AopKernel, NullWorkerProvider, SupervisorRuntime } from '../src/index.js';
|
|
5
|
+
import { MCP_PROTOCOL_PIN, REQUIRED_MCP_TRANSPORTS } from '../src/mcp/protocol-contract.js';
|
|
6
|
+
import { createToolingRuntime } from '../src/index.js';
|
|
7
|
+
import { type ToolClient, createOperationId } from '../src/mcp/tool-client.js';
|
|
8
|
+
import { runGit } from '../src/core/git.js';
|
|
9
|
+
import { makeTempRepo, writeFeatureSpec } from './helpers.js';
|
|
10
|
+
|
|
11
|
+
let repoRoot: string;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
repoRoot = await makeTempRepo(process.cwd());
|
|
15
|
+
await writeFastTestGates(repoRoot);
|
|
16
|
+
await fs.mkdir(path.join(repoRoot, 'src'), { recursive: true });
|
|
17
|
+
await fs.writeFile(path.join(repoRoot, 'src', 'sample.txt'), 'hello\n', 'utf8');
|
|
18
|
+
await runGit(repoRoot, ['add', '.']);
|
|
19
|
+
await runGit(repoRoot, ['commit', '-m', 'add mcp parity fixture']);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
async function boot() {
|
|
23
|
+
const kernel = new AopKernel(repoRoot);
|
|
24
|
+
await kernel.ensureLoaded();
|
|
25
|
+
return {
|
|
26
|
+
kernel,
|
|
27
|
+
tooling: await createToolingRuntime(repoRoot, kernel)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function identity(runId: string, actorType: string, actorId: string, sessionId: string) {
|
|
32
|
+
return {
|
|
33
|
+
run_id: runId,
|
|
34
|
+
session_id: sessionId,
|
|
35
|
+
actor_type: actorType,
|
|
36
|
+
actor_id: actorId
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function selectClient(
|
|
41
|
+
tooling: Awaited<ReturnType<typeof createToolingRuntime>>,
|
|
42
|
+
transport: 'inprocess' | 'mcp'
|
|
43
|
+
): ToolClient {
|
|
44
|
+
return transport === 'mcp' ? tooling.mcpClient : tooling.inProcessClient;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function readIndex() {
|
|
48
|
+
const raw = await fs.readFile(path.join(repoRoot, '.aop', 'features', 'index.json'), 'utf8');
|
|
49
|
+
return JSON.parse(raw);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function writeIndex(index: Record<string, unknown>) {
|
|
53
|
+
await fs.writeFile(path.join(repoRoot, '.aop', 'features', 'index.json'), `${JSON.stringify(index, null, 2)}\n`, 'utf8');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function setReattachTimeoutMs(timeoutMs: number) {
|
|
57
|
+
const policyPath = path.join(repoRoot, 'agentic', 'orchestrator', 'policy.yaml');
|
|
58
|
+
const policy = await fs.readFile(policyPath, 'utf8');
|
|
59
|
+
const updated = policy.replace(
|
|
60
|
+
/orchestrator_session_reattach_timeout_ms:\s*\d+/,
|
|
61
|
+
`orchestrator_session_reattach_timeout_ms: ${timeoutMs}`
|
|
62
|
+
);
|
|
63
|
+
await fs.writeFile(policyPath, updated, 'utf8');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function writeFastTestGates(root: string): Promise<void> {
|
|
67
|
+
const gatesPath = path.join(root, 'agentic', 'orchestrator', 'gates.yaml');
|
|
68
|
+
await fs.writeFile(
|
|
69
|
+
gatesPath,
|
|
70
|
+
[
|
|
71
|
+
'version: 1',
|
|
72
|
+
'profiles:',
|
|
73
|
+
' default:',
|
|
74
|
+
' modes:',
|
|
75
|
+
' fast:',
|
|
76
|
+
' - name: fast_pass',
|
|
77
|
+
' cmd: ["node", "-e", "process.exit(0)"]',
|
|
78
|
+
' full:',
|
|
79
|
+
' - name: full_pass',
|
|
80
|
+
' cmd: ["node", "-e", "process.exit(0)"]',
|
|
81
|
+
' merge:',
|
|
82
|
+
' - name: merge_pass',
|
|
83
|
+
' cmd: ["node", "-e", "process.exit(0)"]',
|
|
84
|
+
' parsers:',
|
|
85
|
+
' coverage:',
|
|
86
|
+
' type: none',
|
|
87
|
+
' parity:',
|
|
88
|
+
' modes:',
|
|
89
|
+
' fast:',
|
|
90
|
+
' - name: parity_fast_pass',
|
|
91
|
+
' cmd: ["node", "-e", "process.exit(0)"]',
|
|
92
|
+
' full:',
|
|
93
|
+
' - name: parity_full_pass',
|
|
94
|
+
' cmd: ["node", "-e", "process.exit(0)"]',
|
|
95
|
+
' merge:',
|
|
96
|
+
' - name: parity_merge_pass',
|
|
97
|
+
' cmd: ["node", "-e", "process.exit(0)"]',
|
|
98
|
+
' parsers:',
|
|
99
|
+
' coverage:',
|
|
100
|
+
' type: none',
|
|
101
|
+
'capabilities:',
|
|
102
|
+
' - none'
|
|
103
|
+
].join('\n'),
|
|
104
|
+
'utf8'
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function buildPlan(featureId: string, modifyPath: string, planVersion = 1, revisionOf: number | null = null) {
|
|
109
|
+
const plan = {
|
|
110
|
+
feature_id: featureId,
|
|
111
|
+
plan_version: planVersion,
|
|
112
|
+
summary: `Plan ${featureId} v${planVersion}`,
|
|
113
|
+
allowed_areas: ['src'],
|
|
114
|
+
forbidden_areas: [],
|
|
115
|
+
base_ref: 'HEAD',
|
|
116
|
+
files: {
|
|
117
|
+
create: [],
|
|
118
|
+
modify: [modifyPath],
|
|
119
|
+
delete: []
|
|
120
|
+
},
|
|
121
|
+
contracts: {
|
|
122
|
+
openapi: 'none',
|
|
123
|
+
events: 'none',
|
|
124
|
+
db: 'none'
|
|
125
|
+
},
|
|
126
|
+
acceptance_criteria: ['Deterministic transport parity is preserved'],
|
|
127
|
+
gate_profile: 'parity'
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
if (revisionOf != null) {
|
|
131
|
+
(plan as any).revision_of = revisionOf;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return plan;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function buildUnifiedDiff(featureId: string, relativeFilePath: string, nextContent: string): Promise<string> {
|
|
138
|
+
const worktreePath = path.join(repoRoot, '.worktrees', featureId);
|
|
139
|
+
const samplePath = path.join(worktreePath, relativeFilePath);
|
|
140
|
+
const original = await fs.readFile(samplePath, 'utf8');
|
|
141
|
+
await fs.writeFile(samplePath, nextContent, 'utf8');
|
|
142
|
+
const diff = await runGit(repoRoot, ['diff'], { cwd: worktreePath });
|
|
143
|
+
await fs.writeFile(samplePath, original, 'utf8');
|
|
144
|
+
expect(diff.code).toBe(0);
|
|
145
|
+
expect(diff.stdout.length).toBeGreaterThan(0);
|
|
146
|
+
return diff.stdout;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function normalizeEnvelope(response: any): Record<string, unknown> {
|
|
150
|
+
if (response?.ok) {
|
|
151
|
+
return {
|
|
152
|
+
ok: true,
|
|
153
|
+
data_keys: Object.keys(response.data ?? {}).sort((a, b) => a.localeCompare(b))
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
ok: false,
|
|
158
|
+
error_code: response?.error?.code ?? 'unknown_error',
|
|
159
|
+
detail_keys: Object.keys(response?.error?.details ?? {}).sort((a, b) => a.localeCompare(b))
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
class TimeoutReattachProvider extends NullWorkerProvider {
|
|
164
|
+
readonly orchestratorSessionIds: string[];
|
|
165
|
+
|
|
166
|
+
constructor() {
|
|
167
|
+
super({
|
|
168
|
+
provider: 'custom',
|
|
169
|
+
model: 'test-model',
|
|
170
|
+
provider_config_env: null,
|
|
171
|
+
provider_config_ref: null
|
|
172
|
+
});
|
|
173
|
+
this.orchestratorSessionIds = [];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async createSession(role: string, featureId: string, systemPrompt: string | null) {
|
|
177
|
+
const created = await super.createSession(role, featureId, systemPrompt);
|
|
178
|
+
if (role === 'orchestrator') {
|
|
179
|
+
this.orchestratorSessionIds.push(created.session_id);
|
|
180
|
+
}
|
|
181
|
+
return created;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async reattachSession(_sessionId: string): Promise<Awaited<ReturnType<NullWorkerProvider['reattachSession']>>> {
|
|
185
|
+
return await new Promise<Awaited<ReturnType<NullWorkerProvider['reattachSession']>>>(() => {
|
|
186
|
+
// Intentional unresolved promise to force timeout fallback.
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
describe('MCP formalization', () => {
|
|
192
|
+
it('lists tools from registry and keeps tools.md generated from catalog', async () => {
|
|
193
|
+
const { tooling } = await boot();
|
|
194
|
+
const listed = await tooling.mcpAdapter.toolsList();
|
|
195
|
+
const catalogNames = [...tooling.registry.toolsByName.keys()].sort((a, b) => a.localeCompare(b));
|
|
196
|
+
const listedNames = listed.tools.map((tool) => tool.name).sort((a, b) => a.localeCompare(b));
|
|
197
|
+
|
|
198
|
+
expect(listedNames).toEqual(catalogNames);
|
|
199
|
+
|
|
200
|
+
const toolsMd = await fs.readFile(path.join(repoRoot, 'agentic', 'orchestrator', 'tools.md'), 'utf8');
|
|
201
|
+
expect(toolsMd).toContain('Generated from `agentic/orchestrator/tools/catalog.json`.');
|
|
202
|
+
expect(toolsMd).toContain('- feature.delete');
|
|
203
|
+
expect(toolsMd).toContain('- feature.init');
|
|
204
|
+
expect(tooling.registry.protocol.mcp_protocol_version).toBe(MCP_PROTOCOL_PIN.mcp_protocol_version);
|
|
205
|
+
expect(tooling.registry.protocol.sdk.package).toBe(MCP_PROTOCOL_PIN.sdk.package);
|
|
206
|
+
expect(tooling.registry.protocol.sdk.version).toBe(MCP_PROTOCOL_PIN.sdk.version);
|
|
207
|
+
for (const transport of REQUIRED_MCP_TRANSPORTS) {
|
|
208
|
+
expect(tooling.registry.protocol.enabled_transports).toContain(transport);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('rejects invalid/expired/mismatched actor claims and system misuse', async () => {
|
|
213
|
+
const { tooling } = await boot();
|
|
214
|
+
|
|
215
|
+
const invalid = await tooling.mcpAdapter.toolsCall({
|
|
216
|
+
name: 'report.dashboard',
|
|
217
|
+
arguments: {}
|
|
218
|
+
});
|
|
219
|
+
expect(invalid.ok).toBe(false);
|
|
220
|
+
expect((invalid as any).error.code).toBe('unauthenticated');
|
|
221
|
+
|
|
222
|
+
const expiredToken = tooling.authVerifier.issueToken({
|
|
223
|
+
run_id: 'run-expired',
|
|
224
|
+
session_id: 'session-expired',
|
|
225
|
+
actor_type: 'orchestrator',
|
|
226
|
+
actor_id: 'actor-expired',
|
|
227
|
+
expires_at: new Date(Date.now() - 60_000).toISOString()
|
|
228
|
+
});
|
|
229
|
+
const expired = await tooling.mcpAdapter.toolsCall({
|
|
230
|
+
name: 'report.dashboard',
|
|
231
|
+
arguments: {},
|
|
232
|
+
session_token: expiredToken
|
|
233
|
+
});
|
|
234
|
+
expect(expired.ok).toBe(false);
|
|
235
|
+
expect((expired as any).error.code).toBe('unauthenticated');
|
|
236
|
+
|
|
237
|
+
const valid = tooling.authVerifier.issueToken({
|
|
238
|
+
run_id: 'run-valid',
|
|
239
|
+
session_id: 'session-valid',
|
|
240
|
+
actor_type: 'orchestrator',
|
|
241
|
+
actor_id: 'actor-valid'
|
|
242
|
+
});
|
|
243
|
+
const mismatch = await tooling.mcpAdapter.toolsCall({
|
|
244
|
+
name: 'report.dashboard',
|
|
245
|
+
arguments: {
|
|
246
|
+
actor_type: 'qa',
|
|
247
|
+
actor_id: 'qa-user'
|
|
248
|
+
},
|
|
249
|
+
session_token: valid
|
|
250
|
+
});
|
|
251
|
+
expect(mismatch.ok).toBe(false);
|
|
252
|
+
expect((mismatch as any).error.code).toBe('invalid_actor_claim');
|
|
253
|
+
|
|
254
|
+
expect(() =>
|
|
255
|
+
tooling.authVerifier.issueToken({
|
|
256
|
+
run_id: 'run-system',
|
|
257
|
+
session_id: 'worker:system',
|
|
258
|
+
actor_type: 'system',
|
|
259
|
+
actor_id: 'system:worker'
|
|
260
|
+
})
|
|
261
|
+
).toThrow();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('enforces idempotency ledger for mutating tools', async () => {
|
|
265
|
+
const { tooling } = await boot();
|
|
266
|
+
await writeFeatureSpec(repoRoot, 'idem_feature');
|
|
267
|
+
|
|
268
|
+
const runId = 'run-idem';
|
|
269
|
+
const claims = identity(runId, 'orchestrator', 'orch:idem', 'session-idem');
|
|
270
|
+
const operationId = 'op-idempotent-0001';
|
|
271
|
+
|
|
272
|
+
const first = await tooling.inProcessClient.call('feature.init', {
|
|
273
|
+
feature_id: 'idem_feature',
|
|
274
|
+
operation_id: operationId
|
|
275
|
+
}, claims);
|
|
276
|
+
expect(first.ok).toBe(true);
|
|
277
|
+
|
|
278
|
+
const second = await tooling.inProcessClient.call('feature.init', {
|
|
279
|
+
feature_id: 'idem_feature',
|
|
280
|
+
operation_id: operationId
|
|
281
|
+
}, claims);
|
|
282
|
+
expect(second.ok).toBe(true);
|
|
283
|
+
|
|
284
|
+
const mismatch = await tooling.inProcessClient.call('feature.init', {
|
|
285
|
+
feature_id: 'different_feature',
|
|
286
|
+
operation_id: operationId
|
|
287
|
+
}, claims);
|
|
288
|
+
expect(mismatch.ok).toBe(false);
|
|
289
|
+
expect((mismatch as any).error.code).toBe('operation_id_reuse_mismatch');
|
|
290
|
+
|
|
291
|
+
const ledgerPath = path.join(repoRoot, '.aop', 'runtime', 'operation-ledger', `${runId}.json`);
|
|
292
|
+
const ledger = JSON.parse(await fs.readFile(ledgerPath, 'utf8'));
|
|
293
|
+
expect(Object.keys(ledger.operations)).toContain(operationId);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('fails startup when policy grants roles outside supported_roles', async () => {
|
|
297
|
+
const catalogPath = path.join(repoRoot, 'agentic', 'orchestrator', 'tools', 'catalog.json');
|
|
298
|
+
const catalog = JSON.parse(await fs.readFile(catalogPath, 'utf8'));
|
|
299
|
+
const entry = catalog.tools.find((tool: any) => tool.name === 'report.dashboard');
|
|
300
|
+
entry.supported_roles = ['system'];
|
|
301
|
+
await fs.writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`, 'utf8');
|
|
302
|
+
|
|
303
|
+
const kernel = new AopKernel(repoRoot);
|
|
304
|
+
await kernel.ensureLoaded();
|
|
305
|
+
|
|
306
|
+
await expect(createToolingRuntime(repoRoot, kernel)).rejects.toThrow('policy_role_outside_supported_roles');
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('preserves transport parity for full critical path envelopes and deterministic state transitions', async () => {
|
|
310
|
+
const { tooling } = await boot();
|
|
311
|
+
|
|
312
|
+
await writeFeatureSpec(repoRoot, 'parity_inprocess');
|
|
313
|
+
await writeFeatureSpec(repoRoot, 'parity_mcp');
|
|
314
|
+
await fs.writeFile(path.join(repoRoot, 'src', 'parity_inprocess.txt'), 'hello parity inprocess\n', 'utf8');
|
|
315
|
+
await fs.writeFile(path.join(repoRoot, 'src', 'parity_mcp.txt'), 'hello parity mcp\n', 'utf8');
|
|
316
|
+
await runGit(repoRoot, ['add', '.']);
|
|
317
|
+
await runGit(repoRoot, ['commit', '-m', 'add parity transport fixtures']);
|
|
318
|
+
|
|
319
|
+
const inprocessResult = await runCriticalFlow(tooling.inProcessClient, {
|
|
320
|
+
runId: 'run-parity-in',
|
|
321
|
+
featureId: 'parity_inprocess',
|
|
322
|
+
actorType: 'orchestrator',
|
|
323
|
+
actorId: 'orchestrator:in',
|
|
324
|
+
sessionId: 'session:in'
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const mcpResult = await runCriticalFlow(tooling.mcpClient, {
|
|
328
|
+
runId: 'run-parity-mcp',
|
|
329
|
+
featureId: 'parity_mcp',
|
|
330
|
+
actorType: 'orchestrator',
|
|
331
|
+
actorId: 'orchestrator:mcp',
|
|
332
|
+
sessionId: 'session:mcp'
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
expect(inprocessResult.statusTimeline).toEqual(['planning', 'building', 'qa', 'ready_to_merge', 'ready_to_merge', 'merged']);
|
|
336
|
+
expect(mcpResult.statusTimeline).toEqual(inprocessResult.statusTimeline);
|
|
337
|
+
expect(mcpResult.envelopes).toEqual(inprocessResult.envelopes);
|
|
338
|
+
expect(mcpResult.gateProfile).toBe('parity');
|
|
339
|
+
expect(inprocessResult.gateProfile).toBe('parity');
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('preserves cross-transport parity for lock contention and collision queue re-drive outcomes', async () => {
|
|
343
|
+
const { kernel, tooling } = await boot();
|
|
344
|
+
kernel.policy.collision_policy = 'block';
|
|
345
|
+
kernel.policy.locks.acquire_behavior = 'fail';
|
|
346
|
+
|
|
347
|
+
const inprocessResult = await runLockAndCollisionFlow(selectClient(tooling, 'inprocess'), 'inprocess');
|
|
348
|
+
const mcpResult = await runLockAndCollisionFlow(selectClient(tooling, 'mcp'), 'mcp');
|
|
349
|
+
|
|
350
|
+
expect(inprocessResult).toEqual({
|
|
351
|
+
lockConflictCode: 'lock_conflict',
|
|
352
|
+
queuedCodes: ['blocked_by_collision_policy', 'blocked_by_collision_policy'],
|
|
353
|
+
queueCounts: {
|
|
354
|
+
afterQueue: 2,
|
|
355
|
+
afterFirstReplay: 1,
|
|
356
|
+
afterSecondReplay: 0
|
|
357
|
+
},
|
|
358
|
+
replayOrder: ['second_feature', 'third_feature'],
|
|
359
|
+
acceptedVersions: {
|
|
360
|
+
second: 1,
|
|
361
|
+
third: 1
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
expect(mcpResult).toEqual(inprocessResult);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('preserves cross-transport parity for stale-lease takeover and restart recovery', async () => {
|
|
368
|
+
await setReattachTimeoutMs(10);
|
|
369
|
+
const { kernel, tooling } = await boot();
|
|
370
|
+
await kernel.ensureFeatureLayout('global');
|
|
371
|
+
|
|
372
|
+
const inprocessResult = await runTakeoverAndRecoveryFlow(kernel, selectClient(tooling, 'inprocess'), 'inprocess');
|
|
373
|
+
const mcpResult = await runTakeoverAndRecoveryFlow(kernel, selectClient(tooling, 'mcp'), 'mcp');
|
|
374
|
+
|
|
375
|
+
expect(inprocessResult).toEqual({
|
|
376
|
+
noTakeoverCode: 'run_already_active',
|
|
377
|
+
takeoverSucceeded: true,
|
|
378
|
+
epochIncrementedOnRecovery: true,
|
|
379
|
+
orchestratorSessionRotated: true
|
|
380
|
+
});
|
|
381
|
+
expect(mcpResult).toEqual(inprocessResult);
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
async function runCriticalFlow(
|
|
386
|
+
client: ToolClient,
|
|
387
|
+
input: {
|
|
388
|
+
runId: string;
|
|
389
|
+
featureId: string;
|
|
390
|
+
actorType: string;
|
|
391
|
+
actorId: string;
|
|
392
|
+
sessionId: string;
|
|
393
|
+
}
|
|
394
|
+
): Promise<{
|
|
395
|
+
statusTimeline: string[];
|
|
396
|
+
gateProfile: string;
|
|
397
|
+
envelopes: Record<string, Record<string, unknown>>;
|
|
398
|
+
}> {
|
|
399
|
+
const orchestratorClaims = identity(input.runId, input.actorType, input.actorId, input.sessionId);
|
|
400
|
+
const builderClaims = identity(input.runId, 'builder', `${input.actorId}:builder`, `${input.sessionId}:builder`);
|
|
401
|
+
|
|
402
|
+
const init = await client.call(
|
|
403
|
+
'feature.init',
|
|
404
|
+
{
|
|
405
|
+
feature_id: input.featureId,
|
|
406
|
+
operation_id: createOperationId('feature.init', input.featureId)
|
|
407
|
+
},
|
|
408
|
+
orchestratorClaims
|
|
409
|
+
);
|
|
410
|
+
expect(init.ok).toBe(true);
|
|
411
|
+
|
|
412
|
+
const planningState = await client.call('feature.state_get', { feature_id: input.featureId }, orchestratorClaims);
|
|
413
|
+
expect(planningState.ok).toBe(true);
|
|
414
|
+
|
|
415
|
+
const plannedFilePath = `src/${input.featureId}.txt`;
|
|
416
|
+
const initialPlan = buildPlan(input.featureId, plannedFilePath);
|
|
417
|
+
const planSubmit = await client.call(
|
|
418
|
+
'plan.submit',
|
|
419
|
+
{
|
|
420
|
+
feature_id: input.featureId,
|
|
421
|
+
plan_json: initialPlan,
|
|
422
|
+
operation_id: createOperationId('plan.submit', input.featureId)
|
|
423
|
+
},
|
|
424
|
+
orchestratorClaims
|
|
425
|
+
);
|
|
426
|
+
expect(planSubmit.ok).toBe(true);
|
|
427
|
+
|
|
428
|
+
const buildingState = await client.call('feature.state_get', { feature_id: input.featureId }, orchestratorClaims);
|
|
429
|
+
expect(buildingState.ok).toBe(true);
|
|
430
|
+
|
|
431
|
+
const diff = await buildUnifiedDiff(input.featureId, plannedFilePath, `hello parity ${input.featureId}\n`);
|
|
432
|
+
const applyPatch = await client.call(
|
|
433
|
+
'repo.apply_patch',
|
|
434
|
+
{
|
|
435
|
+
feature_id: input.featureId,
|
|
436
|
+
unified_diff: diff,
|
|
437
|
+
operation_id: createOperationId('repo.apply_patch', input.featureId)
|
|
438
|
+
},
|
|
439
|
+
builderClaims
|
|
440
|
+
);
|
|
441
|
+
expect(applyPatch.ok).toBe(true);
|
|
442
|
+
|
|
443
|
+
const gateFast = await client.call(
|
|
444
|
+
'gates.run',
|
|
445
|
+
{
|
|
446
|
+
feature_id: input.featureId,
|
|
447
|
+
profile: 'parity',
|
|
448
|
+
mode: 'fast',
|
|
449
|
+
operation_id: createOperationId('gates.run.fast', input.featureId)
|
|
450
|
+
},
|
|
451
|
+
builderClaims
|
|
452
|
+
);
|
|
453
|
+
expect(gateFast.ok).toBe(true);
|
|
454
|
+
|
|
455
|
+
const qaState = await client.call('feature.state_get', { feature_id: input.featureId }, orchestratorClaims);
|
|
456
|
+
expect(qaState.ok).toBe(true);
|
|
457
|
+
|
|
458
|
+
const gateFull = await client.call(
|
|
459
|
+
'gates.run',
|
|
460
|
+
{
|
|
461
|
+
feature_id: input.featureId,
|
|
462
|
+
profile: 'parity',
|
|
463
|
+
mode: 'full',
|
|
464
|
+
operation_id: createOperationId('gates.run.full', input.featureId)
|
|
465
|
+
},
|
|
466
|
+
builderClaims
|
|
467
|
+
);
|
|
468
|
+
expect(gateFull.ok).toBe(true);
|
|
469
|
+
|
|
470
|
+
const readyState = await client.call('feature.state_get', { feature_id: input.featureId }, orchestratorClaims);
|
|
471
|
+
expect(readyState.ok).toBe(true);
|
|
472
|
+
|
|
473
|
+
const gateMerge = await client.call(
|
|
474
|
+
'gates.run',
|
|
475
|
+
{
|
|
476
|
+
feature_id: input.featureId,
|
|
477
|
+
profile: 'parity',
|
|
478
|
+
mode: 'merge',
|
|
479
|
+
operation_id: createOperationId('gates.run.merge', input.featureId)
|
|
480
|
+
},
|
|
481
|
+
builderClaims
|
|
482
|
+
);
|
|
483
|
+
expect(gateMerge.ok).toBe(true);
|
|
484
|
+
|
|
485
|
+
const stillReadyState = await client.call('feature.state_get', { feature_id: input.featureId }, orchestratorClaims);
|
|
486
|
+
expect(stillReadyState.ok).toBe(true);
|
|
487
|
+
|
|
488
|
+
const missingApproval = await client.call(
|
|
489
|
+
'feature.ready_to_merge',
|
|
490
|
+
{
|
|
491
|
+
feature_id: input.featureId,
|
|
492
|
+
commit_message: `feat: merge ${input.featureId}`,
|
|
493
|
+
merge_strategy: 'merge_commit',
|
|
494
|
+
operation_id: createOperationId('feature.ready_to_merge.reject', input.featureId)
|
|
495
|
+
},
|
|
496
|
+
orchestratorClaims
|
|
497
|
+
);
|
|
498
|
+
expect(missingApproval.ok).toBe(false);
|
|
499
|
+
|
|
500
|
+
const merged = await client.call(
|
|
501
|
+
'feature.ready_to_merge',
|
|
502
|
+
{
|
|
503
|
+
feature_id: input.featureId,
|
|
504
|
+
commit_message: `feat: merge ${input.featureId}`,
|
|
505
|
+
merge_strategy: 'merge_commit',
|
|
506
|
+
user_approval_token: 'approved',
|
|
507
|
+
operation_id: createOperationId('feature.ready_to_merge.pass', input.featureId)
|
|
508
|
+
},
|
|
509
|
+
orchestratorClaims
|
|
510
|
+
);
|
|
511
|
+
expect(merged.ok).toBe(true);
|
|
512
|
+
|
|
513
|
+
await expect(
|
|
514
|
+
fs.stat(path.join(repoRoot, '.aop', 'features', input.featureId))
|
|
515
|
+
).rejects.toMatchObject({ code: 'ENOENT' });
|
|
516
|
+
|
|
517
|
+
return {
|
|
518
|
+
statusTimeline: [
|
|
519
|
+
(planningState as any).data.front_matter.status,
|
|
520
|
+
(buildingState as any).data.front_matter.status,
|
|
521
|
+
(qaState as any).data.front_matter.status,
|
|
522
|
+
(readyState as any).data.front_matter.status,
|
|
523
|
+
(stillReadyState as any).data.front_matter.status,
|
|
524
|
+
(merged as any).data.status
|
|
525
|
+
],
|
|
526
|
+
gateProfile: (stillReadyState as any).data.front_matter.gate_profile,
|
|
527
|
+
envelopes: {
|
|
528
|
+
init: normalizeEnvelope(init),
|
|
529
|
+
planSubmit: normalizeEnvelope(planSubmit),
|
|
530
|
+
applyPatch: normalizeEnvelope(applyPatch),
|
|
531
|
+
gateFast: normalizeEnvelope(gateFast),
|
|
532
|
+
gateFull: normalizeEnvelope(gateFull),
|
|
533
|
+
gateMerge: normalizeEnvelope(gateMerge),
|
|
534
|
+
readyWithoutApproval: normalizeEnvelope(missingApproval),
|
|
535
|
+
readyWithApproval: normalizeEnvelope(merged)
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
async function runLockAndCollisionFlow(
|
|
541
|
+
client: ToolClient,
|
|
542
|
+
label: string
|
|
543
|
+
): Promise<{
|
|
544
|
+
lockConflictCode: string;
|
|
545
|
+
queuedCodes: string[];
|
|
546
|
+
queueCounts: { afterQueue: number; afterFirstReplay: number; afterSecondReplay: number };
|
|
547
|
+
replayOrder: string[];
|
|
548
|
+
acceptedVersions: { second: number; third: number };
|
|
549
|
+
}> {
|
|
550
|
+
const firstFeature = `${label}_first_feature`;
|
|
551
|
+
const secondFeature = `${label}_second_feature`;
|
|
552
|
+
const thirdFeature = `${label}_third_feature`;
|
|
553
|
+
const sharedPath = `src/${label}-shared.txt`;
|
|
554
|
+
const leaderPath = `src/${label}-leader.txt`;
|
|
555
|
+
const secondUniquePath = `src/${label}-second-unique.txt`;
|
|
556
|
+
for (const featureId of [firstFeature, secondFeature, thirdFeature]) {
|
|
557
|
+
await writeFeatureSpec(repoRoot, featureId);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const orchestrator = identity(`run:${label}:collision`, 'orchestrator', `orch:${label}`, `session:${label}:orch`);
|
|
561
|
+
for (const featureId of [firstFeature, secondFeature, thirdFeature]) {
|
|
562
|
+
const init = await client.call(
|
|
563
|
+
'feature.init',
|
|
564
|
+
{ feature_id: featureId, operation_id: createOperationId('feature.init', featureId) },
|
|
565
|
+
orchestrator
|
|
566
|
+
);
|
|
567
|
+
expect(init.ok).toBe(true);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const acquireFirst = await client.call(
|
|
571
|
+
'locks.acquire',
|
|
572
|
+
{ resource: 'openapi', feature_id: firstFeature, operation_id: createOperationId('locks.acquire', firstFeature) },
|
|
573
|
+
orchestrator
|
|
574
|
+
);
|
|
575
|
+
expect(acquireFirst.ok).toBe(true);
|
|
576
|
+
|
|
577
|
+
const acquireConflict = await client.call(
|
|
578
|
+
'locks.acquire',
|
|
579
|
+
{ resource: 'openapi', feature_id: secondFeature, operation_id: createOperationId('locks.acquire', secondFeature) },
|
|
580
|
+
orchestrator
|
|
581
|
+
);
|
|
582
|
+
expect(acquireConflict.ok).toBe(false);
|
|
583
|
+
|
|
584
|
+
const acceptedFirst = await client.call(
|
|
585
|
+
'plan.submit',
|
|
586
|
+
{
|
|
587
|
+
feature_id: firstFeature,
|
|
588
|
+
plan_json: buildPlan(firstFeature, sharedPath, 1),
|
|
589
|
+
operation_id: createOperationId('plan.submit', firstFeature)
|
|
590
|
+
},
|
|
591
|
+
orchestrator
|
|
592
|
+
);
|
|
593
|
+
expect(acceptedFirst.ok).toBe(true);
|
|
594
|
+
|
|
595
|
+
const queuedSecond = await client.call(
|
|
596
|
+
'plan.submit',
|
|
597
|
+
{
|
|
598
|
+
feature_id: secondFeature,
|
|
599
|
+
plan_json: buildPlan(secondFeature, sharedPath, 1),
|
|
600
|
+
operation_id: createOperationId('plan.submit', secondFeature)
|
|
601
|
+
},
|
|
602
|
+
orchestrator
|
|
603
|
+
);
|
|
604
|
+
const queuedThird = await client.call(
|
|
605
|
+
'plan.submit',
|
|
606
|
+
{
|
|
607
|
+
feature_id: thirdFeature,
|
|
608
|
+
plan_json: buildPlan(thirdFeature, sharedPath, 1),
|
|
609
|
+
operation_id: createOperationId('plan.submit', thirdFeature)
|
|
610
|
+
},
|
|
611
|
+
orchestrator
|
|
612
|
+
);
|
|
613
|
+
expect(queuedSecond.ok).toBe(false);
|
|
614
|
+
expect(queuedThird.ok).toBe(false);
|
|
615
|
+
|
|
616
|
+
const queuedIndex = await readIndex();
|
|
617
|
+
expect(queuedIndex.blocked_queue).toHaveLength(2);
|
|
618
|
+
await writeIndex({
|
|
619
|
+
...queuedIndex,
|
|
620
|
+
blocked_queue: queuedIndex.blocked_queue.map((entry: any) => ({
|
|
621
|
+
...entry,
|
|
622
|
+
detected_at: '2026-02-28T12:00:00Z'
|
|
623
|
+
}))
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
const revisedFirst = await client.call(
|
|
627
|
+
'plan.update',
|
|
628
|
+
{
|
|
629
|
+
feature_id: firstFeature,
|
|
630
|
+
expected_plan_version: 1,
|
|
631
|
+
plan_json: buildPlan(firstFeature, leaderPath, 2, 1),
|
|
632
|
+
operation_id: createOperationId('plan.update', firstFeature)
|
|
633
|
+
},
|
|
634
|
+
orchestrator
|
|
635
|
+
);
|
|
636
|
+
expect(revisedFirst.ok).toBe(true);
|
|
637
|
+
|
|
638
|
+
const firstRelease = await client.call(
|
|
639
|
+
'locks.release',
|
|
640
|
+
{ resource: 'openapi', feature_id: firstFeature, operation_id: createOperationId('locks.release.1', firstFeature) },
|
|
641
|
+
orchestrator
|
|
642
|
+
);
|
|
643
|
+
expect(firstRelease.ok).toBe(true);
|
|
644
|
+
|
|
645
|
+
const indexAfterFirstReplay = await readIndex();
|
|
646
|
+
expect(indexAfterFirstReplay.blocked_queue).toHaveLength(1);
|
|
647
|
+
const remainingAfterFirstReplay = indexAfterFirstReplay.blocked_queue.map((entry: any) =>
|
|
648
|
+
String(entry.feature_id).replace(`${label}_`, '')
|
|
649
|
+
);
|
|
650
|
+
expect(remainingAfterFirstReplay).toEqual(['third_feature']);
|
|
651
|
+
|
|
652
|
+
const secondPlan = await client.call('plan.get', { feature_id: secondFeature }, orchestrator);
|
|
653
|
+
expect(secondPlan.ok).toBe(true);
|
|
654
|
+
|
|
655
|
+
const revisedSecond = await client.call(
|
|
656
|
+
'plan.update',
|
|
657
|
+
{
|
|
658
|
+
feature_id: secondFeature,
|
|
659
|
+
expected_plan_version: 1,
|
|
660
|
+
plan_json: buildPlan(secondFeature, secondUniquePath, 2, 1),
|
|
661
|
+
operation_id: createOperationId('plan.update', secondFeature)
|
|
662
|
+
},
|
|
663
|
+
orchestrator
|
|
664
|
+
);
|
|
665
|
+
expect(revisedSecond.ok).toBe(true);
|
|
666
|
+
|
|
667
|
+
const reacquireFirst = await client.call(
|
|
668
|
+
'locks.acquire',
|
|
669
|
+
{ resource: 'openapi', feature_id: firstFeature, operation_id: createOperationId('locks.acquire.re', firstFeature) },
|
|
670
|
+
orchestrator
|
|
671
|
+
);
|
|
672
|
+
expect(reacquireFirst.ok).toBe(true);
|
|
673
|
+
|
|
674
|
+
const secondRelease = await client.call(
|
|
675
|
+
'locks.release',
|
|
676
|
+
{ resource: 'openapi', feature_id: firstFeature, operation_id: createOperationId('locks.release.2', firstFeature) },
|
|
677
|
+
orchestrator
|
|
678
|
+
);
|
|
679
|
+
expect(secondRelease.ok).toBe(true);
|
|
680
|
+
|
|
681
|
+
const indexAfterSecondReplay = await readIndex();
|
|
682
|
+
expect(indexAfterSecondReplay.blocked_queue).toHaveLength(0);
|
|
683
|
+
|
|
684
|
+
const thirdPlan = await client.call('plan.get', { feature_id: thirdFeature }, orchestrator);
|
|
685
|
+
expect(thirdPlan.ok).toBe(true);
|
|
686
|
+
|
|
687
|
+
const replayOrder = ['second_feature', ...remainingAfterFirstReplay];
|
|
688
|
+
|
|
689
|
+
return {
|
|
690
|
+
lockConflictCode: (acquireConflict as any).error.code,
|
|
691
|
+
queuedCodes: [(queuedSecond as any).error.code, (queuedThird as any).error.code],
|
|
692
|
+
queueCounts: {
|
|
693
|
+
afterQueue: queuedIndex.blocked_queue.length,
|
|
694
|
+
afterFirstReplay: indexAfterFirstReplay.blocked_queue.length,
|
|
695
|
+
afterSecondReplay: indexAfterSecondReplay.blocked_queue.length
|
|
696
|
+
},
|
|
697
|
+
replayOrder,
|
|
698
|
+
acceptedVersions: {
|
|
699
|
+
second: (secondPlan as any).data.plan.plan_version,
|
|
700
|
+
third: (thirdPlan as any).data.plan.plan_version
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
async function runTakeoverAndRecoveryFlow(
|
|
706
|
+
kernel: AopKernel,
|
|
707
|
+
client: ToolClient,
|
|
708
|
+
label: string
|
|
709
|
+
): Promise<{
|
|
710
|
+
noTakeoverCode: string;
|
|
711
|
+
takeoverSucceeded: boolean;
|
|
712
|
+
epochIncrementedOnRecovery: boolean;
|
|
713
|
+
orchestratorSessionRotated: boolean;
|
|
714
|
+
}> {
|
|
715
|
+
const existingRun = await kernel.getRuntimeSessions();
|
|
716
|
+
if (existingRun.run_id !== 'none' && existingRun.owner_instance_id !== 'none') {
|
|
717
|
+
await kernel.releaseRunLease(existingRun.run_id, existingRun.owner_instance_id);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
const provider = new TimeoutReattachProvider();
|
|
721
|
+
const featureId = `${label}_recovery_feature`;
|
|
722
|
+
await writeFeatureSpec(repoRoot, featureId, '# Spec\n\nRecover stale run.\n');
|
|
723
|
+
const orchestrator = identity(`run:${label}:recovery`, 'orchestrator', `orch:${label}:recovery`, `session:${label}:recovery`);
|
|
724
|
+
|
|
725
|
+
const init = await client.call(
|
|
726
|
+
'feature.init',
|
|
727
|
+
{ feature_id: featureId, operation_id: createOperationId('feature.init', featureId) },
|
|
728
|
+
orchestrator
|
|
729
|
+
);
|
|
730
|
+
expect(init.ok).toBe(true);
|
|
731
|
+
|
|
732
|
+
const sourceRuntime = new SupervisorRuntime(kernel, provider, client, {
|
|
733
|
+
run_id: `run:${label}:source`,
|
|
734
|
+
max_iterations_per_phase: 0
|
|
735
|
+
});
|
|
736
|
+
await sourceRuntime.start([{ feature_id: featureId }]);
|
|
737
|
+
|
|
738
|
+
const staleIndex = await readIndex();
|
|
739
|
+
staleIndex.runtime_sessions.lease_expires_at = new Date(Date.now() - 60_000).toISOString();
|
|
740
|
+
await writeIndex(staleIndex);
|
|
741
|
+
|
|
742
|
+
const noTakeoverRuntime = new SupervisorRuntime(kernel, provider, client, {
|
|
743
|
+
run_id: `run:${label}:target:no-takeover`,
|
|
744
|
+
max_iterations_per_phase: 0,
|
|
745
|
+
takeover_stale_run: false
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
let noTakeoverCode = 'unknown';
|
|
749
|
+
await noTakeoverRuntime.start([{ feature_id: featureId }]).catch((error: any) => {
|
|
750
|
+
noTakeoverCode = error?.normalizedResponse?.error?.code ?? error?.code ?? 'unknown';
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
const takeoverRuntime = new SupervisorRuntime(kernel, provider, client, {
|
|
754
|
+
run_id: `run:${label}:target:takeover`,
|
|
755
|
+
max_iterations_per_phase: 0,
|
|
756
|
+
takeover_stale_run: true
|
|
757
|
+
});
|
|
758
|
+
await takeoverRuntime.start([{ feature_id: featureId }]);
|
|
759
|
+
|
|
760
|
+
const postTakeover = await readIndex();
|
|
761
|
+
const takeoverSessionId = postTakeover.runtime_sessions.orchestrator_session_id;
|
|
762
|
+
const takeoverEpoch = Number(postTakeover.runtime_sessions.orchestrator_epoch ?? 0);
|
|
763
|
+
|
|
764
|
+
postTakeover.runtime_sessions.lease_expires_at = new Date(Date.now() - 60_000).toISOString();
|
|
765
|
+
await writeIndex(postTakeover);
|
|
766
|
+
|
|
767
|
+
await takeoverRuntime.start([{ feature_id: featureId }]);
|
|
768
|
+
const postRecovery = await readIndex();
|
|
769
|
+
|
|
770
|
+
return {
|
|
771
|
+
noTakeoverCode,
|
|
772
|
+
takeoverSucceeded: postTakeover.runtime_sessions.run_id === `run:${label}:target:takeover`,
|
|
773
|
+
epochIncrementedOnRecovery: Number(postRecovery.runtime_sessions.orchestrator_epoch ?? 0) === takeoverEpoch + 1,
|
|
774
|
+
orchestratorSessionRotated: postRecovery.runtime_sessions.orchestrator_session_id !== takeoverSessionId
|
|
775
|
+
};
|
|
776
|
+
}
|