@deksden-com/dd-flow-cli 0.9.0-beta.16 → 0.9.0-beta.161
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/CHANGELOG.md +965 -0
- package/README.md +139 -10
- package/dist/build-info.json +8 -8
- package/dist/cli/argument-values.js +38 -0
- package/dist/cli/command-inputs.js +417 -0
- package/dist/cli/command-metadata.js +303 -0
- package/dist/cli/command-option-descriptions.js +192 -0
- package/dist/cli/completion-cli.js +70 -0
- package/dist/cli/completion.js +57 -0
- package/dist/cli/delivery.js +108 -0
- package/dist/cli/diagnostic-invocation.js +62 -0
- package/dist/cli/diagnostic.js +131 -0
- package/dist/cli/error-output.js +62 -0
- package/dist/cli/executor-onboarding.js +76 -0
- package/dist/cli/flows.js +29 -0
- package/dist/cli/harnesses.js +84 -0
- package/dist/cli/help.js +521 -19
- package/dist/cli/hook-ingress.js +89 -0
- package/dist/cli/input-preparation.js +193 -0
- package/dist/cli/interactive-invocation.js +33 -0
- package/dist/cli/interactive.js +114 -0
- package/dist/cli/memory-fix-invocation.js +52 -0
- package/dist/cli/memory-fix.js +100 -0
- package/dist/cli/memory-flow-admission.js +54 -0
- package/dist/cli/memory-init-invocation.js +85 -0
- package/dist/cli/memory-init.js +250 -0
- package/dist/cli/memory-storage-admission.js +54 -0
- package/dist/cli/memory-storage-qualification.js +105 -0
- package/dist/cli/memory-storage-transition.js +123 -0
- package/dist/cli/memory-upgrade.js +189 -0
- package/dist/cli/models.js +39 -0
- package/dist/cli/native-hook-ingress.js +94 -0
- package/dist/cli/native-hook-preparation.js +82 -0
- package/dist/cli/operator-profiles.js +61 -0
- package/dist/cli/output-options.js +35 -0
- package/dist/cli/response-file.js +72 -0
- package/dist/cli/run-cli.js +2020 -555
- package/dist/cli/runtime-maintenance-diagnostics.js +46 -0
- package/dist/cli/runtime-maintenance-ingress.js +52 -0
- package/dist/cli/runtime-process.js +153 -0
- package/dist/cli/setup.js +150 -0
- package/dist/cli.js +103 -2
- package/dist/domain/delivery-flows.js +8 -0
- package/dist/domain/diagnostic-aspects.js +103 -0
- package/dist/domain/diagnostic-flows.js +8 -0
- package/dist/domain/distill-flow.js +20 -0
- package/dist/domain/interactive-flow.js +1 -0
- package/dist/domain/memory-fix-flow.js +2 -0
- package/dist/domain/review-fix-flow.js +2 -0
- package/dist/domain/source-snapshot-flows.js +4 -0
- package/dist/domain/stage-catalog.js +1 -1
- package/dist/domain/stage-handler-identities.js +28 -0
- package/dist/harness-runtime/DD-ZCODE.md +112 -0
- package/dist/harness-runtime/OPENCODE-LICENSE.txt +24 -0
- package/dist/harness-runtime/bin/dd-agy.mjs +71 -0
- package/dist/harness-runtime/bin/dd-codex.mjs +27 -0
- package/dist/harness-runtime/bin/dd-droid.mjs +34 -0
- package/dist/harness-runtime/bin/dd-grok.mjs +50 -0
- package/dist/harness-runtime/bin/dd-opencode.mjs +22 -0
- package/dist/harness-runtime/bin/dd-zcode.mjs +95 -0
- package/dist/harness-runtime/lib/adapter-timeouts.d.mts +5 -0
- package/dist/harness-runtime/lib/adapter-timeouts.mjs +34 -0
- package/dist/harness-runtime/lib/agy-error-boundary.mjs +87 -0
- package/dist/harness-runtime/lib/agy-hooks.d.mts +1 -0
- package/dist/harness-runtime/lib/agy-hooks.mjs +9 -0
- package/dist/harness-runtime/lib/agy-native-inspection.mjs +225 -0
- package/dist/harness-runtime/lib/agy-native-inventory.mjs +19 -0
- package/dist/harness-runtime/lib/agy-native_pb.js +117 -0
- package/dist/harness-runtime/lib/agy-terminal-envelope.mjs +74 -0
- package/dist/harness-runtime/lib/agy-transcript-stream.mjs +54 -0
- package/dist/harness-runtime/lib/daemon-observation.d.mts +3 -0
- package/dist/harness-runtime/lib/daemon-observation.mjs +171 -0
- package/dist/harness-runtime/lib/daemon-operations.d.mts +2 -0
- package/dist/harness-runtime/lib/daemon-operations.mjs +512 -0
- package/dist/harness-runtime/lib/dd-agy-daemon.d.mts +7 -0
- package/dist/harness-runtime/lib/dd-agy-daemon.mjs +1362 -0
- package/dist/harness-runtime/lib/dd-agy.mjs +105 -0
- package/dist/harness-runtime/lib/dd-codex-daemon.d.mts +1 -0
- package/dist/harness-runtime/lib/dd-codex-daemon.mjs +271 -0
- package/dist/harness-runtime/lib/dd-codex.d.mts +1 -0
- package/dist/harness-runtime/lib/dd-codex.mjs +986 -0
- package/dist/harness-runtime/lib/dd-droid-daemon.mjs +155 -0
- package/dist/harness-runtime/lib/dd-droid.mjs +739 -0
- package/dist/harness-runtime/lib/dd-grok-daemon.d.mts +1 -0
- package/dist/harness-runtime/lib/dd-grok-daemon.mjs +667 -0
- package/dist/harness-runtime/lib/dd-grok.mjs +182 -0
- package/dist/harness-runtime/lib/dd-opencode-daemon.mjs +772 -0
- package/dist/harness-runtime/lib/dd-opencode.mjs +411 -0
- package/dist/harness-runtime/lib/dd-zcode-daemon.d.mts +1 -0
- package/dist/harness-runtime/lib/dd-zcode-daemon.mjs +845 -0
- package/dist/harness-runtime/lib/dd-zcode.mjs +1239 -0
- package/dist/harness-runtime/lib/delegation-instructions.d.mts +16 -0
- package/dist/harness-runtime/lib/delegation-instructions.mjs +179 -0
- package/dist/harness-runtime/lib/delivery-command.mjs +84 -0
- package/dist/harness-runtime/lib/dispatch-fence.mjs +14 -0
- package/dist/harness-runtime/lib/driver-recovery.mjs +121 -0
- package/dist/harness-runtime/lib/droid-observation.mjs +70 -0
- package/dist/harness-runtime/lib/entity-references.d.mts +2 -0
- package/dist/harness-runtime/lib/entity-references.mjs +9 -0
- package/dist/harness-runtime/lib/lease-renewal.d.mts +8 -0
- package/dist/harness-runtime/lib/lease-renewal.mjs +37 -0
- package/dist/harness-runtime/lib/lifecycle-command.d.mts +20 -0
- package/dist/harness-runtime/lib/lifecycle-command.mjs +273 -0
- package/dist/harness-runtime/lib/lifecycle-contract.d.mts +11 -0
- package/dist/harness-runtime/lib/lifecycle-contract.mjs +20 -0
- package/dist/harness-runtime/lib/managed-daemon.d.mts +16 -0
- package/dist/harness-runtime/lib/managed-daemon.mjs +698 -0
- package/dist/harness-runtime/lib/managed-flow-env.mjs +15 -0
- package/dist/harness-runtime/lib/model-observations.mjs +113 -0
- package/dist/harness-runtime/lib/native-children.d.mts +34 -0
- package/dist/harness-runtime/lib/native-children.mjs +265 -0
- package/dist/harness-runtime/lib/native-hook-command.d.mts +8 -0
- package/dist/harness-runtime/lib/native-hook-command.mjs +306 -0
- package/dist/harness-runtime/lib/native-request-proof.d.mts +2 -0
- package/dist/harness-runtime/lib/native-request-proof.mjs +65 -0
- package/dist/harness-runtime/lib/native-streams.mjs +38 -0
- package/dist/harness-runtime/lib/observation-clock.d.mts +18 -0
- package/dist/harness-runtime/lib/observation-clock.mjs +95 -0
- package/dist/harness-runtime/lib/opencode-plugin.mjs +112 -0
- package/dist/harness-runtime/lib/operation-context.mjs +5 -0
- package/dist/harness-runtime/lib/operation-errors.d.mts +16 -0
- package/dist/harness-runtime/lib/operation-errors.mjs +140 -0
- package/dist/harness-runtime/lib/operation-progress.d.mts +7 -0
- package/dist/harness-runtime/lib/operation-progress.mjs +118 -0
- package/dist/harness-runtime/lib/process-json.d.mts +5 -0
- package/dist/harness-runtime/lib/process-json.mjs +200 -0
- package/dist/harness-runtime/lib/process-snapshot.mjs +10 -0
- package/dist/harness-runtime/lib/provider-overload-policy.d.mts +23 -0
- package/dist/harness-runtime/lib/provider-overload-policy.mjs +242 -0
- package/dist/harness-runtime/lib/runner-events.mjs +202 -0
- package/dist/harness-runtime/lib/runner-lock.mjs +42 -0
- package/dist/harness-runtime/lib/session-settlement.mjs +30 -0
- package/dist/harness-runtime/lib/setup-progress.d.mts +9 -0
- package/dist/harness-runtime/lib/setup-progress.mjs +53 -0
- package/dist/harness-runtime/lib/tool-observations.d.mts +21 -0
- package/dist/harness-runtime/lib/tool-observations.mjs +238 -0
- package/dist/harness-runtime/lib/zcode-native-hook-ownership.mjs +109 -0
- package/dist/harness-runtime/lib/zcode-usage.mjs +55 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-1y4a697q.js +81 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-2ny4vxct.js +92 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-6mptkzbc.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-7x67cf1q.js +52 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-9rqn6x4v.js +16 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-9vdz0zwn.js +1661 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ecs5ftka.js +1466 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-frbwqjmf.js +145 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-gne7h7mq.js +50 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-gx9wnkzr.js +105 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-m2eywc8w.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-nwcpakzx.js +12 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-q4g3afnw.js +623 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-qav6mfdz.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-sxt88q69.js +12 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-t1xa31vm.js +39 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ve4aws36.js +103 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vmytr4q8.js +4 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vt9jbch8.js +36 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vyas3vgt.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-wjyeq25y.js +30 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-xgnj2w4v.js +20 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-y2etg5bs.js +9 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ydhz1zrh.js +238 -0
- package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-z6qdwcsf.js +62 -0
- package/dist/harness-runtime/vendor/opencode-client/contract.d.ts +1 -0
- package/dist/harness-runtime/vendor/opencode-client/contract.js +12 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/api/api.d.ts +2806 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/api/api.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/api.d.ts +4 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/api.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/client.d.ts +2530 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/client.js +15 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/client-error.d.ts +7 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/client-error.js +6 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/client.d.ts +2529 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/client.js +8 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/index.d.ts +2 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/generated/index.js +12 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/index.d.ts +35 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/index.js +75 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/rpc.d.ts +20 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/rpc.js +11 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/service.d.ts +90 -0
- package/dist/harness-runtime/vendor/opencode-client/effect/service.js +187 -0
- package/dist/harness-runtime/vendor/opencode-client/package.json +84 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/api.d.ts +21 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/api.js +0 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/client.d.ts +252 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/client.js +14 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/client-error.d.ts +8 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/client-error.js +6 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/client.d.ts +259 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/client.js +7 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/index.d.ts +3 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/index.js +79 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/types.d.ts +8932 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/generated/types.js +70 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/index.d.ts +6 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/index.js +83 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/rpc.d.ts +32 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/rpc.js +7 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/service.d.ts +24 -0
- package/dist/harness-runtime/vendor/opencode-client/promise/service.js +187 -0
- package/dist/harness-runtime/vendor/opencode-client/pty-handoff.d.ts +12 -0
- package/dist/harness-runtime/vendor/opencode-client/pty-handoff.js +14 -0
- package/dist/harness-runtime/vendor/opencode-client/rpc-runtime.d.ts +20 -0
- package/dist/harness-runtime/vendor/opencode-client/rpc-runtime.js +14 -0
- package/dist/harness-runtime/vendor/opencode-client/service-contender.d.ts +37 -0
- package/dist/harness-runtime/vendor/opencode-client/service-contender.js +10 -0
- package/dist/harness-runtime/vendor/opencode-client/service-probe.d.ts +70 -0
- package/dist/harness-runtime/vendor/opencode-client/service-probe.js +16 -0
- package/dist/harness-runtime/vendor/opencode-client/service-timing.d.ts +12 -0
- package/dist/harness-runtime/vendor/opencode-client/service-timing.js +10 -0
- package/dist/harness-runtime/vendor/opencode-client/service-version.d.ts +2 -0
- package/dist/harness-runtime/vendor/opencode-client/service-version.js +6 -0
- package/dist/harness-runtime/vendor/opencode-client/service.d.ts +52 -0
- package/dist/harness-runtime/vendor/opencode-client/service.js +1 -0
- package/dist/harness-runtime/vendor/opencode-client/shared-events.d.ts +11 -0
- package/dist/harness-runtime/vendor/opencode-client/shared-events.js +8 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/connection.d.ts +37 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/connection.js +10 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/data.d.ts +211 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/data.js +18 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/index.d.ts +3 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/index.js +32 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/pty.d.ts +22 -0
- package/dist/harness-runtime/vendor/opencode-client/solid/pty.js +8 -0
- package/dist/harness-runtime/vendor/opencode-plugin.mjs +3 -0
- package/dist/protocol/local-files.js +18 -9
- package/dist/runtime/context.js +8 -4
- package/dist/schemas/agent-profile.schema.json +1 -1
- package/dist/schemas/code-review-decision.schema.json +9 -0
- package/dist/schemas/code-review-result.schema.json +1 -1
- package/dist/schemas/code-verification.schema.json +7 -5
- package/dist/schemas/code-work-batch.schema.json +2 -2
- package/dist/schemas/code-work-result.schema.json +2 -1
- package/dist/schemas/delivery-stage-result.schema.json +286 -0
- package/dist/schemas/diagnostic-stage-result.schema.json +354 -0
- package/dist/schemas/diagnostic-work-result.schema.json +296 -0
- package/dist/schemas/discovery-result.schema.json +184 -0
- package/dist/schemas/distill-stage-result.schema.json +667 -0
- package/dist/schemas/distill-work-result.schema.json +428 -0
- package/dist/schemas/execution-bundle.schema.json +215 -0
- package/dist/schemas/execution-settings.schema.json +162 -0
- package/dist/schemas/flow-descriptor.schema.json +54 -0
- package/dist/schemas/flow-run.schema.json +29 -0
- package/dist/schemas/harness-catalog.schema.json +80 -0
- package/dist/schemas/interactive-stage-result.schema.json +47 -0
- package/dist/schemas/interactive-work-result.schema.json +63 -0
- package/dist/schemas/mb-fix-stage-result.schema.json +93 -0
- package/dist/schemas/mb-init-compose-result.schema.json +457 -0
- package/dist/schemas/mb-init-discover-result.schema.json +500 -0
- package/dist/schemas/mb-init-finish-result.schema.json +422 -0
- package/dist/schemas/mb-init-preflight-result.schema.json +367 -0
- package/dist/schemas/mb-init-review-result.schema.json +396 -0
- package/dist/schemas/mb-init-verify-result.schema.json +391 -0
- package/dist/schemas/mb-upgrade-stage-result.schema.json +863 -0
- package/dist/schemas/memory-bootstrap-receipt-v2.schema.json +67 -0
- package/dist/schemas/memory-bootstrap-receipt.schema.json +354 -0
- package/dist/schemas/memory-composition-work-result.schema.json +38 -0
- package/dist/schemas/memory-repair-work-result.schema.json +56 -0
- package/dist/schemas/memory-review-correction-plan.schema.json +30 -0
- package/dist/schemas/memory-review-work-result.schema.json +43 -0
- package/dist/schemas/model-catalog.schema.json +153 -0
- package/dist/schemas/plan-review-decision.schema.json +12 -3
- package/dist/schemas/plan-review-result.schema.json +2 -2
- package/dist/schemas/profile-settings.schema.json +122 -0
- package/dist/schemas/project-flow-pack-manifest.schema.json +2 -2
- package/dist/schemas/release-impact.schema.json +3 -3
- package/dist/schemas/release-manifest.schema.json +291 -0
- package/dist/schemas/review-fix-stage-result.schema.json +210 -0
- package/dist/schemas/run-control-receipt.schema.json +119 -0
- package/dist/schemas/run-control-request.schema.json +36 -0
- package/dist/schemas/run-engine-binding.schema.json +1 -1
- package/dist/schemas/stage-start-response.schema.json +4 -0
- package/dist/schemas/vnext-protocol-plan.schema.json +3 -3
- package/dist/services/accepted-intent.js +139 -0
- package/dist/services/assigned-lifecycle.js +382 -0
- package/dist/services/branch-context.js +3 -3
- package/dist/services/canon.js +54 -15
- package/dist/services/check-environment.js +21 -0
- package/dist/services/check-runner-evidence.js +344 -0
- package/dist/services/check-runner-proof.js +373 -0
- package/dist/services/cleanup.js +133 -40
- package/dist/services/cli-operation-classifier.js +32 -64
- package/dist/services/cli-upgrade-allowlist.js +27 -0
- package/dist/services/code-checks.js +1426 -121
- package/dist/services/codex-capacity.js +367 -0
- package/dist/services/codex-hook-delivery.js +41 -0
- package/dist/services/command-context.js +80 -0
- package/dist/services/compatibility-preflight.js +16 -3
- package/dist/services/config.js +11 -8
- package/dist/services/continuation-outcome.js +25 -0
- package/dist/services/controller-child-capacity.js +71 -0
- package/dist/services/controller-child-observer.js +121 -0
- package/dist/services/controller-child-repair.js +117 -0
- package/dist/services/controller-execution.js +97 -0
- package/dist/services/controller-fanout.js +277 -0
- package/dist/services/controller-memory-task.js +45 -0
- package/dist/services/controller-memory-worker.js +51 -0
- package/dist/services/controller-result-authority.js +127 -0
- package/dist/services/controller-work-failure.js +198 -0
- package/dist/services/dashboard.js +145 -58
- package/dist/services/delivery-access.js +123 -0
- package/dist/services/delivery-approval.js +68 -0
- package/dist/services/delivery-artifact.js +86 -0
- package/dist/services/delivery-checks.js +178 -0
- package/dist/services/delivery-execution.js +181 -0
- package/dist/services/delivery-intents.js +212 -0
- package/dist/services/delivery-operation.js +81 -0
- package/dist/services/delivery-policy.js +91 -0
- package/dist/services/delivery-procedures.js +43 -0
- package/dist/services/delivery-request.js +99 -0
- package/dist/services/delivery-result.js +144 -0
- package/dist/services/delivery-stage-commands.js +26 -0
- package/dist/services/delivery-stage-entry.js +56 -0
- package/dist/services/delivery-stage-handlers.js +135 -0
- package/dist/services/delivery-stage-results.js +94 -0
- package/dist/services/descriptor-coordinator-session.js +37 -0
- package/dist/services/descriptor-root-work.js +53 -0
- package/dist/services/descriptor-run-settlement.js +107 -0
- package/dist/services/descriptor-run-start.js +495 -0
- package/dist/services/descriptor-stage-coordinator.js +318 -0
- package/dist/services/descriptor-stage-settlement.js +268 -0
- package/dist/services/descriptor-stage-start.js +175 -0
- package/dist/services/diagnostic-evidence.js +73 -0
- package/dist/services/diagnostic-repair-intake.js +123 -0
- package/dist/services/diagnostic-repair-source-intake.js +102 -0
- package/dist/services/diagnostic-report-publication.js +72 -0
- package/dist/services/diagnostic-report.js +97 -0
- package/dist/services/diagnostic-run-bundle.js +113 -0
- package/dist/services/diagnostic-snapshot.js +159 -0
- package/dist/services/diagnostic-stage-handlers.js +109 -0
- package/dist/services/diagnostic-stage-results.js +158 -0
- package/dist/services/diagnostic-start.js +134 -0
- package/dist/services/diagnostic-work-batch.js +34 -0
- package/dist/services/diagnostic-work-collection.js +97 -0
- package/dist/services/diagnostic-work-registration.js +101 -0
- package/dist/services/diagnostic-work-results.js +93 -0
- package/dist/services/discovery/agy-discovery.js +2 -0
- package/dist/services/discovery/codex-discovery.js +2 -0
- package/dist/services/discovery/droid-discovery.js +2 -0
- package/dist/services/discovery/grok-discovery.js +2 -0
- package/dist/services/discovery/opencode-discovery.js +2 -0
- package/dist/services/discovery/static.js +31 -0
- package/dist/services/discovery/zcode-discovery.js +2 -0
- package/dist/services/distill-document-publication.js +280 -0
- package/dist/services/distill-promotion.js +197 -0
- package/dist/services/distill-publication-custody.js +162 -0
- package/dist/services/distill-stage-handlers.js +249 -0
- package/dist/services/distill-stage-results.js +105 -0
- package/dist/services/distill-user-inputs.js +4 -0
- package/dist/services/distill-work-batch.js +42 -0
- package/dist/services/distill-work-collection.js +74 -0
- package/dist/services/distill-work-registration.js +93 -0
- package/dist/services/distill-work-results.js +98 -0
- package/dist/services/engines.js +354 -163
- package/dist/services/eval-snapshots.js +1326 -150
- package/dist/services/execution-bundles.js +275 -0
- package/dist/services/execution-policy.js +185 -0
- package/dist/services/executor-onboarding.js +56 -0
- package/dist/services/external-work-launch.js +316 -0
- package/dist/services/flow-catalog.js +54 -0
- package/dist/services/flow-descriptors.js +82 -0
- package/dist/services/frozen-engine.js +404 -0
- package/dist/services/generic-execution.js +165 -0
- package/dist/services/harness-adapter.js +342 -35
- package/dist/services/harness-config.js +2 -0
- package/dist/services/harness-discovery.js +29 -0
- package/dist/services/harness-doctor.js +75 -0
- package/dist/services/harness-probe-effects.js +51 -0
- package/dist/services/harness-version-probe.js +100 -0
- package/dist/services/hook-memory-routing.js +188 -0
- package/dist/services/hook-recovery-guard.js +14 -0
- package/dist/services/hook-session-observation.js +24 -0
- package/dist/services/hooks.js +813 -327
- package/dist/services/hybrid-contracts.js +479 -0
- package/dist/services/hybrid-digest.js +14 -0
- package/dist/services/ids.js +29 -1
- package/dist/services/installation-lock.js +95 -0
- package/dist/services/installed-flow-source.js +261 -0
- package/dist/services/interactive-attached-session.js +215 -0
- package/dist/services/interactive-baseline-custody.js +54 -0
- package/dist/services/interactive-before-versions.js +148 -0
- package/dist/services/interactive-bundle-data.js +85 -0
- package/dist/services/interactive-checks.js +179 -0
- package/dist/services/interactive-execution.js +33 -0
- package/dist/services/interactive-finish-integration.js +236 -0
- package/dist/services/interactive-git-baseline.js +230 -0
- package/dist/services/interactive-git-dispatch.js +278 -0
- package/dist/services/interactive-input-delivery.js +82 -0
- package/dist/services/interactive-mutation-scope.js +231 -0
- package/dist/services/interactive-request.js +287 -0
- package/dist/services/interactive-run-bundle.js +109 -0
- package/dist/services/interactive-stage-entry.js +41 -0
- package/dist/services/interactive-stage-handlers.js +289 -0
- package/dist/services/interactive-stage-observation.js +136 -0
- package/dist/services/interactive-stage-results.js +111 -0
- package/dist/services/interactive-user-inputs.js +142 -0
- package/dist/services/interactive-work-batch.js +43 -0
- package/dist/services/interactive-work-collection.js +119 -0
- package/dist/services/interactive-work-completion.js +180 -0
- package/dist/services/interactive-work-context.js +249 -0
- package/dist/services/interactive-work-history.js +112 -0
- package/dist/services/interactive-work-registration.js +124 -0
- package/dist/services/interactive-work-results.js +115 -0
- package/dist/services/interactive-work-start.js +155 -0
- package/dist/services/lanes.js +78 -65
- package/dist/services/lifecycle-command.js +1 -288
- package/dist/services/lifecycle-contract.js +1 -0
- package/dist/services/lifecycle-invocations.js +2549 -0
- package/dist/services/managed-daemon-binding.js +129 -0
- package/dist/services/managed-lease-monitor.js +133 -0
- package/dist/services/managed-processes.js +449 -69
- package/dist/services/memory-accepted-composition.js +78 -0
- package/dist/services/memory-baseline-preservation.js +65 -0
- package/dist/services/memory-completed-correction-wave.js +328 -0
- package/dist/services/memory-compose-handler.js +380 -0
- package/dist/services/memory-composition-acceptance.js +375 -0
- package/dist/services/memory-composition-graph.js +165 -0
- package/dist/services/memory-composition-registration.js +161 -0
- package/dist/services/memory-composition-work-custody.js +156 -0
- package/dist/services/memory-composition-work-results.js +108 -0
- package/dist/services/memory-corrected-review-acceptance.js +129 -0
- package/dist/services/memory-corrected-review-batch.js +37 -0
- package/dist/services/memory-corrected-review-findings.js +108 -0
- package/dist/services/memory-corrected-review-inputs.js +215 -0
- package/dist/services/memory-corrected-review-projection.js +78 -0
- package/dist/services/memory-corrected-review-receipt.js +178 -0
- package/dist/services/memory-corrected-review-registration.js +192 -0
- package/dist/services/memory-correction-check-receipt.js +235 -0
- package/dist/services/memory-correction-input-owner.js +6 -0
- package/dist/services/memory-custody-snapshot.js +36 -0
- package/dist/services/memory-discover-handler.js +104 -0
- package/dist/services/memory-finish-evidence.js +457 -0
- package/dist/services/memory-finish-handler.js +229 -0
- package/dist/services/memory-finish-integration.js +491 -0
- package/dist/services/memory-finish-readiness.js +169 -0
- package/dist/services/memory-fix-finish-integration.js +129 -0
- package/dist/services/memory-fix-git-dispatch.js +139 -0
- package/dist/services/memory-fix-intake-custody.js +11 -0
- package/dist/services/memory-fix-intake-settlement.js +127 -0
- package/dist/services/memory-fix-publication.js +196 -0
- package/dist/services/memory-fix-repair-admission.js +116 -0
- package/dist/services/memory-fix-request.js +141 -0
- package/dist/services/memory-fix-run-bundle.js +83 -0
- package/dist/services/memory-fix-scope.js +78 -0
- package/dist/services/memory-fix-sources.js +85 -0
- package/dist/services/memory-fix-stage-entry.js +24 -0
- package/dist/services/memory-fix-stage-handlers.js +282 -0
- package/dist/services/memory-fix-stage-results.js +106 -0
- package/dist/services/memory-fix-workspace.js +127 -0
- package/dist/services/memory-flow-user-inputs.js +88 -0
- package/dist/services/memory-git-integration.js +220 -0
- package/dist/services/memory-historical-corrected-review.js +212 -0
- package/dist/services/memory-historical-original-review.js +143 -0
- package/dist/services/memory-historical-repair-registration.js +105 -0
- package/dist/services/memory-historical-second-review.js +147 -0
- package/dist/services/memory-init-bootstrap-readiness.js +210 -0
- package/dist/services/memory-init-contexts.js +181 -0
- package/dist/services/memory-init-controller-start.js +119 -0
- package/dist/services/memory-init-engine-release.js +223 -0
- package/dist/services/memory-init-git-policy.js +165 -0
- package/dist/services/memory-init-lint-capability.js +203 -0
- package/dist/services/memory-init-native-capacity.js +309 -0
- package/dist/services/memory-init-preflight.js +334 -0
- package/dist/services/memory-init-project-bootstrap.js +599 -0
- package/dist/services/memory-init-request-candidate.js +213 -0
- package/dist/services/memory-init-request-input.js +82 -0
- package/dist/services/memory-init-resource-storage.js +125 -0
- package/dist/services/memory-init-run-allocation.js +81 -0
- package/dist/services/memory-init-run-bundle.js +135 -0
- package/dist/services/memory-init-start.js +181 -0
- package/dist/services/memory-init-startup-custody.js +80 -0
- package/dist/services/memory-init-startup-input.js +240 -0
- package/dist/services/memory-init-storage.js +91 -0
- package/dist/services/memory-init-stores.js +359 -0
- package/dist/services/memory-init-worktrunk-capability.js +174 -0
- package/dist/services/memory-layer-publication.js +611 -0
- package/dist/services/memory-layer.js +225 -0
- package/dist/services/memory-lint-config.js +194 -0
- package/dist/services/memory-native-review-copy.js +127 -0
- package/dist/services/memory-normal-flow-entry.js +87 -0
- package/dist/services/memory-ordinary-defaults.js +129 -0
- package/dist/services/memory-preflight-bootstrap-custody.js +115 -0
- package/dist/services/memory-preflight-handler.js +274 -0
- package/dist/services/memory-repair-current-view.js +299 -0
- package/dist/services/memory-repair-document-delta.js +489 -0
- package/dist/services/memory-repair-history.js +496 -0
- package/dist/services/memory-repair-physical-binding.js +194 -0
- package/dist/services/memory-repair-publication-files.js +152 -0
- package/dist/services/memory-repair-publication-intent.js +27 -0
- package/dist/services/memory-repair-publication-plan.js +162 -0
- package/dist/services/memory-repair-publication-source.js +225 -0
- package/dist/services/memory-repair-publication.js +795 -0
- package/dist/services/memory-repair-registration.js +240 -0
- package/dist/services/memory-repair-work-baseline.js +415 -0
- package/dist/services/memory-repair-work-completion.js +117 -0
- package/dist/services/memory-repair-work-custody.js +73 -0
- package/dist/services/memory-repair-work-results.js +108 -0
- package/dist/services/memory-repair-workspace.js +261 -0
- package/dist/services/memory-repair-writer-copy.js +736 -0
- package/dist/services/memory-result-binding.js +239 -0
- package/dist/services/memory-retained-review-authority.js +138 -0
- package/dist/services/memory-retained-review-results.js +70 -0
- package/dist/services/memory-retained-second-baseline.js +102 -0
- package/dist/services/memory-retained-second-repairs.js +162 -0
- package/dist/services/memory-review-acceptance.js +214 -0
- package/dist/services/memory-review-correction-plan.js +206 -0
- package/dist/services/memory-review-handler.js +585 -0
- package/dist/services/memory-review-inputs.js +246 -0
- package/dist/services/memory-review-limits.js +10 -0
- package/dist/services/memory-review-receipt.js +180 -0
- package/dist/services/memory-review-registration.js +117 -0
- package/dist/services/memory-review-work-custody.js +126 -0
- package/dist/services/memory-review-work-input.js +91 -0
- package/dist/services/memory-review-work-results.js +95 -0
- package/dist/services/memory-second-corrected-review-inputs.js +167 -0
- package/dist/services/memory-second-correction-plan.js +77 -0
- package/dist/services/memory-second-repair-baseline.js +91 -0
- package/dist/services/memory-second-repair-launch.js +614 -0
- package/dist/services/memory-second-repair-registration.js +88 -0
- package/dist/services/memory-second-repair-source.js +187 -0
- package/dist/services/memory-second-review-acceptance.js +115 -0
- package/dist/services/memory-source-observations.js +117 -0
- package/dist/services/memory-stage-dispatch.js +65 -0
- package/dist/services/memory-stage-results.js +290 -0
- package/dist/services/memory-tool-probe.js +25 -0
- package/dist/services/memory-upgrade-analysis-handler.js +243 -0
- package/dist/services/memory-upgrade-bootstrap-readiness.js +251 -0
- package/dist/services/memory-upgrade-evidence.js +100 -0
- package/dist/services/memory-upgrade-inventory.js +442 -0
- package/dist/services/memory-upgrade-publication-custody.js +73 -0
- package/dist/services/memory-upgrade-publication.js +413 -0
- package/dist/services/memory-upgrade-selection.js +430 -0
- package/dist/services/memory-upgrade-start.js +60 -0
- package/dist/services/memory-upgrade-storage-readiness.js +340 -0
- package/dist/services/memory-verification-acceptance.js +156 -0
- package/dist/services/memory-verification-checks.js +317 -0
- package/dist/services/memory-verification-receipt.js +160 -0
- package/dist/services/memory-verify-handler.js +137 -0
- package/dist/services/memory-work-result-json.js +12 -0
- package/dist/services/memory-work-result-preparation.js +64 -0
- package/dist/services/merge-queue.js +228 -149
- package/dist/services/merge-server.js +163 -35
- package/dist/services/migrations.js +164 -114
- package/dist/services/model-catalog.js +109 -0
- package/dist/services/model-discovery.js +46 -0
- package/dist/services/native-daemon-history.js +50 -0
- package/dist/services/native-session-control.js +39 -0
- package/dist/services/operator-profiles.js +236 -0
- package/dist/services/physical-startup.js +45 -0
- package/dist/services/plan-runtime.js +26 -11
- package/dist/services/plans.js +28 -25
- package/dist/services/project-flow-source.js +195 -0
- package/dist/services/project-git-integration.js +92 -0
- package/dist/services/project-registry.js +97 -0
- package/dist/services/project-summary.js +1 -1
- package/dist/services/projects.js +17 -87
- package/dist/services/prompt-delivery.js +71 -0
- package/dist/services/prompts.js +28 -17
- package/dist/services/protocols.js +163 -87
- package/dist/services/provider-capacity.js +463 -0
- package/dist/services/recovery-observation-budget.js +121 -0
- package/dist/services/recovery-snapshot-database.js +588 -0
- package/dist/services/release-archive-producer.js +52 -0
- package/dist/services/release-archive.js +143 -0
- package/dist/services/release-cache.js +150 -0
- package/dist/services/release-compatibility.js +18 -0
- package/dist/services/release-download.js +67 -0
- package/dist/services/release-envelope.js +104 -0
- package/dist/services/release-manifest.js +45 -0
- package/dist/services/release-payload.js +114 -0
- package/dist/services/release-producer.js +63 -0
- package/dist/services/release-provenance.js +160 -0
- package/dist/services/release-registry.js +66 -0
- package/dist/services/release-source.js +194 -0
- package/dist/services/repair-intents.js +29 -0
- package/dist/services/repair-receipt.js +13 -0
- package/dist/services/retained-native-hook.js +274 -0
- package/dist/services/review-copy.js +165 -0
- package/dist/services/review-deferral.js +23 -0
- package/dist/services/review-fix-handoff.js +82 -0
- package/dist/services/review-fix-intake-custody.js +17 -0
- package/dist/services/review-fix-stage-entry.js +43 -0
- package/dist/services/review-fix-stage-handlers.js +176 -0
- package/dist/services/review-fix-stage-results.js +86 -0
- package/dist/services/run-control-receipt.js +56 -0
- package/dist/services/run-control-worker.js +469 -0
- package/dist/services/run-control.js +1109 -0
- package/dist/services/run-controller-adapter.js +434 -0
- package/dist/services/run-controller-capture.js +186 -0
- package/dist/services/run-controller-process.js +226 -0
- package/dist/services/run-controller-recovery.js +335 -0
- package/dist/services/run-controller-state.js +106 -0
- package/dist/services/run-controller.js +1717 -0
- package/dist/services/run-engine-bindings.js +1 -1
- package/dist/services/run-fork.js +147 -0
- package/dist/services/run-health.js +149 -0
- package/dist/services/run-observations.js +152 -0
- package/dist/services/run-projection.js +22 -64
- package/dist/services/run-recovery-guard.js +107 -0
- package/dist/services/run-recovery-runtime.js +112 -0
- package/dist/services/run-recovery.js +485 -0
- package/dist/services/run-start-custody.js +189 -0
- package/dist/services/run-timeline.js +59 -0
- package/dist/services/runs.js +996 -271
- package/dist/services/runtime-budget.js +446 -0
- package/dist/services/runtime-command.js +43 -0
- package/dist/services/runtime-scope-capture.js +52 -0
- package/dist/services/runtime-scope-control.js +468 -0
- package/dist/services/runtime-scope-resume.js +605 -0
- package/dist/services/runtime-scope-stop.js +211 -0
- package/dist/services/runtime-scope-worker.js +314 -0
- package/dist/services/runtime-service.js +19 -14
- package/dist/services/schema-validation.js +10 -8
- package/dist/services/scope-writer-cleanup.js +27 -0
- package/dist/services/sessions.js +37 -91
- package/dist/services/setup.js +427 -0
- package/dist/services/stage-blocker.js +17 -7
- package/dist/services/stage-context.js +240 -18
- package/dist/services/stage-handlers.js +141 -0
- package/dist/services/stage-lifecycle.js +156 -119
- package/dist/services/stage-pause.js +222 -94
- package/dist/services/stage-report-renderer.js +230 -6
- package/dist/services/stage-work-graph.js +52 -0
- package/dist/services/technical-notes.js +31 -0
- package/dist/services/tooling.js +111 -44
- package/dist/services/usage.js +49 -101
- package/dist/services/verification-matrix.js +393 -0
- package/dist/services/version-status.js +1 -1
- package/dist/services/vnext-code-review.js +302 -91
- package/dist/services/vnext-code.js +325 -251
- package/dist/services/vnext-contracts.js +10 -1
- package/dist/services/vnext-execution-profile.js +80 -5
- package/dist/services/vnext-fanout.js +399 -20
- package/dist/services/vnext-merge.js +336 -114
- package/dist/services/vnext-plan-review.js +288 -133
- package/dist/services/vnext-plan.js +257 -110
- package/dist/services/vnext-protocolize.js +534 -96
- package/dist/services/vnext-specify.js +131 -84
- package/dist/services/vnext-workspace-policy.js +7 -2
- package/dist/services/work-registry.js +1950 -215
- package/dist/services/work-retry-context.js +55 -0
- package/dist/services/workspace-bootstrap.js +53 -15
- package/dist/services/workspace-files.js +85 -0
- package/dist/services/worktrees.js +108 -48
- package/dist/shared/entity-references.js +1 -0
- package/dist/shared/errors.js +27 -0
- package/dist/storage/agent-output.js +26 -0
- package/dist/storage/data-preservation.js +65 -0
- package/dist/storage/database.js +931 -40
- package/dist/storage/foreign-key-transaction.js +39 -0
- package/dist/storage/immutable-input.js +45 -0
- package/dist/storage/import-guard.js +159 -0
- package/dist/storage/memory-upgrade-schema-bootstrap.js +38 -0
- package/dist/storage/native-cleanup.js +52 -0
- package/dist/storage/paired-writer-migration.js +424 -0
- package/dist/storage/paths.js +17 -4
- package/dist/storage/projection-lock.js +73 -0
- package/dist/storage/work-references.js +23 -0
- package/dist/storage/writer-contract.js +96 -0
- package/dist/storage/writer-migration.js +346 -0
- package/dist/storage/writer-restore.js +217 -0
- package/dist/verification-components.json +384 -0
- package/package.json +52 -13
- package/tools/create-canon-release.mjs +33 -0
- package/tools/probe-codex-history.mjs +37 -0
- package/tools/produce-hybrid-release.mjs +41 -0
- package/tools/repair-paused-run-status.mjs +84 -0
- package/tools/verification-jobs.mjs +342 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { AppError } from "../shared/errors.js";
|
|
2
|
+
import { resolveProjectRoot } from "../storage/paths.js";
|
|
3
|
+
import { hybridDigest } from "./hybrid-contracts.js";
|
|
4
|
+
import { readDiagnosticRepairIntake } from "./diagnostic-repair-intake.js";
|
|
5
|
+
import { ObservedMemorySources } from "./memory-source-observations.js";
|
|
6
|
+
import { memorySourceKey } from "./memory-stage-results.js";
|
|
7
|
+
import { MemoryRepairDocumentBaseline } from "./memory-repair-document-delta.js";
|
|
8
|
+
function refuse(reason) {
|
|
9
|
+
throw new AppError("memory_fix_source_invalid", "Memory repair source observations changed or exceed their bounds", 2, { reason, effect: "no_effect" });
|
|
10
|
+
}
|
|
11
|
+
/** Only selected target metadata, including absence, becomes intake authority.
|
|
12
|
+
* Neighboring current documents remain protected by the later publication plan
|
|
13
|
+
* but unrelated edits do not invalidate target approval by themselves. */
|
|
14
|
+
export function observeMemoryFixWriteTargets(projectRoot, paths) {
|
|
15
|
+
if (!paths.length)
|
|
16
|
+
return [];
|
|
17
|
+
const baseline = MemoryRepairDocumentBaseline.capture(projectRoot, paths);
|
|
18
|
+
return memoryFixWriteTargetsFromBaseline(baseline);
|
|
19
|
+
}
|
|
20
|
+
export function memoryFixWriteTargetsFromBaseline(baseline) {
|
|
21
|
+
const value = JSON.parse(baseline.bytes().toString("utf8"));
|
|
22
|
+
const entries = new Map(baseline.entries().map(entry => [entry.path, entry]));
|
|
23
|
+
return value.write_paths.slice().sort().map(logical => ({ path: logical, before: entries.get(logical) ?? null }));
|
|
24
|
+
}
|
|
25
|
+
/** Read-only drift evidence, never a replacement for the original finding or
|
|
26
|
+
* permission to repair/close it. The Stage owner must assess drift and revalidate
|
|
27
|
+
* this same observation before admitting any writer. Unavailable is not unchanged.
|
|
28
|
+
*/
|
|
29
|
+
export function observeMemoryFixSources(context, input) {
|
|
30
|
+
return observeSources(resolveProjectRoot(input.projectRoot), () => readDiagnosticRepairIntake(context, input));
|
|
31
|
+
}
|
|
32
|
+
/** The handler must first admit this intake from its own frozen RUN bundle.
|
|
33
|
+
* A scoped restore need not contain the neighboring source audit's SQL rows.
|
|
34
|
+
* This helper grants no intake/approval authority and never searches another Home.
|
|
35
|
+
*/
|
|
36
|
+
export function observeRetainedMemoryFixSources(projectRoot, intake) {
|
|
37
|
+
const retained = structuredClone(intake);
|
|
38
|
+
return observeSources(resolveProjectRoot(projectRoot), () => retained);
|
|
39
|
+
}
|
|
40
|
+
function observeSources(projectRoot, readIntake) {
|
|
41
|
+
const capture = () => {
|
|
42
|
+
const intake = readIntake(), references = new Map();
|
|
43
|
+
for (const finding of intake.selected_findings) {
|
|
44
|
+
for (const reference of [...finding.evidence, ...finding.resolution.evidence,
|
|
45
|
+
...finding.critic_decisions.flatMap(critic => critic.decision.evidence)]) {
|
|
46
|
+
if (typeof reference.path !== "string" || reference.path.length > 4096 || reference.path.split("/").includes(".git")
|
|
47
|
+
|| !/^[a-f0-9]{64}$/.test(reference.sha256))
|
|
48
|
+
refuse("invalid_original_source");
|
|
49
|
+
if (references.has(reference.path) && references.get(reference.path) !== reference.sha256)
|
|
50
|
+
refuse("conflicting_original_source");
|
|
51
|
+
references.set(reference.path, reference.sha256);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (references.size > 20_000)
|
|
55
|
+
refuse("source_inventory_exceeds_bound");
|
|
56
|
+
let total = 0;
|
|
57
|
+
const observations = [...references].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([path, original_sha256]) => {
|
|
58
|
+
try {
|
|
59
|
+
const location = { root: "project", path };
|
|
60
|
+
const observed = ObservedMemorySources.capture({ project: projectRoot }, [location]);
|
|
61
|
+
total += observed.bytes(location).length;
|
|
62
|
+
if (total > 64 * 1024 * 1024)
|
|
63
|
+
refuse("source_bytes_exceed_bound");
|
|
64
|
+
const current_sha256 = observed.hashes().get(memorySourceKey("project", path));
|
|
65
|
+
return { path, original_sha256, current_sha256,
|
|
66
|
+
state: current_sha256 === original_sha256 ? "unchanged" : "changed", reason: null };
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (!(error instanceof AppError) || error.code !== "memory_source_observation_failed")
|
|
70
|
+
throw error;
|
|
71
|
+
return { path, original_sha256, current_sha256: null, state: "unavailable",
|
|
72
|
+
reason: String(error.details?.reason ?? "source_unavailable") };
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return { schema_id: "dd-flow/mb-fix-source-observation@1", source: intake.source,
|
|
76
|
+
finding_ids: intake.selected_findings.map(finding => finding.id), observations,
|
|
77
|
+
requires_reassessment: !observations.length || observations.some(source => source.state !== "unchanged"),
|
|
78
|
+
authorization: "not_granted" };
|
|
79
|
+
};
|
|
80
|
+
const original = capture();
|
|
81
|
+
return { snapshot: () => structuredClone(original), revalidate: () => {
|
|
82
|
+
if (hybridDigest(capture()) !== hybridDigest(original))
|
|
83
|
+
refuse("sources_changed_after_observation");
|
|
84
|
+
} };
|
|
85
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AppError } from "../shared/errors.js";
|
|
2
|
+
import { memoryFixStages } from "../domain/memory-fix-flow.js";
|
|
3
|
+
import { readFlowRunExecutionBundle } from "./runs.js";
|
|
4
|
+
import { requireProjectByRoot } from "./projects.js";
|
|
5
|
+
import { resolveProjectRoot } from "../storage/paths.js";
|
|
6
|
+
import { readMemoryFixSourceIntake, assertMemoryFixSourceIntakeCustody } from "./memory-fix-intake-custody.js";
|
|
7
|
+
import { PreparedDescriptorStageStart } from "./descriptor-stage-start.js";
|
|
8
|
+
import { PreparedDescriptorStageCoordinator } from "./descriptor-stage-coordinator.js";
|
|
9
|
+
/** Registered entry implementation, not standalone RUN-start permission.
|
|
10
|
+
* Generic runtime alone owns attempts, root Work, coordinator and replay.
|
|
11
|
+
*/
|
|
12
|
+
export function startMemoryFixStage(context, input) {
|
|
13
|
+
const project = requireProjectByRoot(context, resolveProjectRoot(input.projectRoot));
|
|
14
|
+
const bundle = readFlowRunExecutionBundle(context, input);
|
|
15
|
+
if (!bundle || bundle.manifest.flow_id !== "mb-fix" || !memoryFixStages.includes(input.stage))
|
|
16
|
+
throw new AppError("memory_fix_stage_invalid", "Memory repair requires its registered five-stage flow and retained intake", 2, { reason: "memory_fix_stage_required", effect: "no_effect" });
|
|
17
|
+
bundle.descriptor.stage(input.stage);
|
|
18
|
+
const source = readMemoryFixSourceIntake(context, input, bundle);
|
|
19
|
+
const scope = { projectId: project.id, runId: input.runId };
|
|
20
|
+
const fence = (writer) => assertMemoryFixSourceIntakeCustody(writer, scope, bundle, source.sha256);
|
|
21
|
+
const start = PreparedDescriptorStageStart.prepare(context, input).apply(context, fence);
|
|
22
|
+
const coordinator = PreparedDescriptorStageCoordinator.prepare(context, input).apply(context, fence);
|
|
23
|
+
return { ...start, ...coordinator, intake_sha256: source.sha256, source_intake: source.reference };
|
|
24
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { AppError } from "../shared/errors.js";
|
|
4
|
+
import { resolveProjectRoot } from "../storage/paths.js";
|
|
5
|
+
import { entityReferenceVariants } from "../shared/entity-references.js";
|
|
6
|
+
import { requireProjectByRoot } from "./projects.js";
|
|
7
|
+
import { readFlowRunExecutionBundle, assertPreparedRunBundleSqlAuthority } from "./runs.js";
|
|
8
|
+
import { readDescriptorStageInput } from "./descriptor-stage-coordinator.js";
|
|
9
|
+
import { PreparedDescriptorStageSettlement, readAcceptedDescriptorStageSettlement, readActiveDescriptorStageCoordinator } from "./descriptor-stage-settlement.js";
|
|
10
|
+
import { readAcceptedStageData, prepareStagePacket, acceptStagePacket, resolveStagePublicationPath, prepareStageReport, acceptStageReport, publishStageReport } from "./stage-report-renderer.js";
|
|
11
|
+
import { readMemoryFixSourceIntake, assertMemoryFixSourceIntakeCustody } from "./memory-fix-intake-custody.js";
|
|
12
|
+
import { finishMemoryFixIntake, readAcceptedMemoryFixIntakeEvidence } from "./memory-fix-intake-settlement.js";
|
|
13
|
+
import { readMemoryFixPublication, readMemoryFixPublicationReference } from "./memory-fix-publication.js";
|
|
14
|
+
import { memoryFixBeforeDocumentReferences, publishMemoryFixBeforeDocuments } from "./distill-document-publication.js";
|
|
15
|
+
import { readPreparedMemoryFlowUserInputs } from "./memory-flow-user-inputs.js";
|
|
16
|
+
import { validateMemoryFixStageResult, assertMemoryFixStageScope, memoryFixClosureProjection } from "./memory-fix-stage-results.js";
|
|
17
|
+
import { PreparedDescriptorRunSettlement } from "./descriptor-run-settlement.js";
|
|
18
|
+
import { prepareMemoryFixFinishIntegration } from "./memory-fix-finish-integration.js";
|
|
19
|
+
import { stageLifecycleMatchKey } from "./hooks.js";
|
|
20
|
+
import { assertDiagnosticSessionIndependence } from "./diagnostic-work-collection.js";
|
|
21
|
+
import { hybridDigest } from "./hybrid-contracts.js";
|
|
22
|
+
import { memoryFixStages } from "../domain/memory-fix-flow.js";
|
|
23
|
+
import { startMemoryFixStage } from "./memory-fix-stage-entry.js";
|
|
24
|
+
/** Engine-owned handlers only; source admission does not allocate or start a RUN. */
|
|
25
|
+
export const memoryFixStageHandlers = Object.freeze(memoryFixStages.map(stage => Object.freeze({
|
|
26
|
+
flowId: "mb-fix", stage, entryId: "memory-fix-stage-entry", finishId: "memory-fix-stage-finish",
|
|
27
|
+
entry: startMemoryFixStage, finish: finishMemoryFixStage
|
|
28
|
+
})));
|
|
29
|
+
function refuse(reason) {
|
|
30
|
+
const correctable = reason.startsWith("changed_") || ["invalid_result_json", "invalid_result_details", "result_exceeds_bound",
|
|
31
|
+
"preservation_evidence_required", "output_evidence_required"].includes(reason);
|
|
32
|
+
throw new AppError("memory_fix_stage_invalid", "Repair Stage requires its admitted publication and independent observations", 2, { reason, effect: "no_effect", ...(correctable ? { phase: "prepare", recoverable: true } : {}) });
|
|
33
|
+
}
|
|
34
|
+
function readTerminalReport(context, scope, attempt, root) {
|
|
35
|
+
const rows = context.db.all("SELECT payload_json FROM audit_events WHERE project_id=? AND event_type='flow_run.stage_report' AND json_extract(payload_json,'$.run_id')=? AND json_extract(payload_json,'$.stage')='finish' AND json_extract(payload_json,'$.attempt')=? LIMIT 2", [scope.projectId, scope.runId, attempt]);
|
|
36
|
+
if (!rows.length)
|
|
37
|
+
return null;
|
|
38
|
+
if (rows.length !== 1 || Buffer.byteLength(rows[0].payload_json) > 8 * 1024 * 1024)
|
|
39
|
+
refuse("terminal_report_custody_invalid");
|
|
40
|
+
try {
|
|
41
|
+
const retained = JSON.parse(rows[0].payload_json);
|
|
42
|
+
const report = prepareStageReport(JSON.parse(retained.bytes.json));
|
|
43
|
+
if (retained.sha256 !== report.sha256 || hybridDigest(retained.bytes) !== hybridDigest(report.bytes)
|
|
44
|
+
|| resolveStagePublicationPath(context, scope.projectId, scope.runId, retained.root) !== root)
|
|
45
|
+
refuse("terminal_report_changed");
|
|
46
|
+
return report;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof AppError)
|
|
50
|
+
throw error;
|
|
51
|
+
return refuse("terminal_report_custody_invalid");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Common Stage settlement; public launch still requires the real RUN factory,
|
|
55
|
+
* command dispatch and installed family acceptance. */
|
|
56
|
+
export function finishMemoryFixStage(context, input) {
|
|
57
|
+
if (input.stage === "intake")
|
|
58
|
+
return finishMemoryFixIntake(context, input);
|
|
59
|
+
if (!["repair", "verify", "review", "finish"].includes(input.stage))
|
|
60
|
+
refuse("repair_stage_required");
|
|
61
|
+
const stage = input.stage;
|
|
62
|
+
const project = requireProjectByRoot(context, resolveProjectRoot(input.projectRoot));
|
|
63
|
+
const bundle = readFlowRunExecutionBundle(context, input);
|
|
64
|
+
if (!bundle || bundle.manifest.flow_id !== "mb-fix")
|
|
65
|
+
refuse("memory_fix_bundle_required");
|
|
66
|
+
const scope = { projectId: project.id, runId: input.runId, stage };
|
|
67
|
+
const source = readMemoryFixSourceIntake(context, input, bundle), run = assertPreparedRunBundleSqlAuthority(context, scope, bundle);
|
|
68
|
+
const packet = readDescriptorStageInput(context, scope, bundle, true, true);
|
|
69
|
+
const previousStage = stage === "repair" ? "intake" : stage === "verify" ? "repair" : stage === "review" ? "verify" : "review";
|
|
70
|
+
const previous = readAcceptedStageData(context, { ...scope, stage: previousStage });
|
|
71
|
+
if (packet.input.predecessor?.stage !== previousStage || hybridDigest(packet.input.predecessor.result) !== hybridDigest(previous.result))
|
|
72
|
+
refuse("predecessor_changed");
|
|
73
|
+
const prior = JSON.parse(previous.bytes.toString("utf8"));
|
|
74
|
+
const intakeFile = path.join(packet.runRoot, bundle.descriptor.stage("intake").directory, "intake-evidence.json");
|
|
75
|
+
const intake = readAcceptedMemoryFixIntakeEvidence(context, scope, intakeFile);
|
|
76
|
+
if (intake.intake_sha256 !== source.sha256)
|
|
77
|
+
refuse("source_intake_changed");
|
|
78
|
+
const publication = readMemoryFixPublication(context, { project_id: project.id, run_id: input.runId });
|
|
79
|
+
const repairInput = stage === "repair" ? packet : readDescriptorStageInput(context, { ...scope, stage: "repair" }, bundle, true, true);
|
|
80
|
+
const intakeResult = readAcceptedStageData(context, { ...scope, stage: "intake" });
|
|
81
|
+
if (intake.write_scope) {
|
|
82
|
+
if (!publication?.completed || publication.binding.bundle_sha256 !== bundle.sha256
|
|
83
|
+
|| publication.binding.attempt !== repairInput.attempt || publication.binding.input_sha256 !== repairInput.inputSha256
|
|
84
|
+
|| publication.binding.intake_sha256 !== source.sha256 || publication.binding.source_observation_sha256 !== intake.source_observation_sha256
|
|
85
|
+
|| hybridDigest(publication.binding.intake_result) !== hybridDigest(intakeResult.result)
|
|
86
|
+
|| hybridDigest(publication.binding.write_scope) !== hybridDigest(intake.write_scope))
|
|
87
|
+
refuse("completed_publication_required");
|
|
88
|
+
}
|
|
89
|
+
else if (publication)
|
|
90
|
+
refuse("publication_without_accepted_scope");
|
|
91
|
+
const reference = publication ? readMemoryFixPublicationReference(context, publication, `${bundle.descriptor.stage("repair").directory}/publication.json`) : null;
|
|
92
|
+
if (publication && !reference)
|
|
93
|
+
refuse("publication_reference_required");
|
|
94
|
+
if (!input.bytes.length || input.bytes.length > 1024 * 1024)
|
|
95
|
+
refuse("result_exceeds_bound");
|
|
96
|
+
let result;
|
|
97
|
+
try {
|
|
98
|
+
result = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.bytes));
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return refuse("invalid_result_json");
|
|
102
|
+
}
|
|
103
|
+
if (!result?.details || typeof result.details !== "object" || !Array.isArray(result.details.limitations))
|
|
104
|
+
refuse("invalid_result_details");
|
|
105
|
+
const insert = (object, field, expected) => {
|
|
106
|
+
const proposed = object[field];
|
|
107
|
+
if (proposed != null && !(Array.isArray(proposed) && !proposed.length) && hybridDigest(proposed) !== hybridDigest(expected))
|
|
108
|
+
refuse(`changed_${field}`);
|
|
109
|
+
Object.assign(object, { [field]: structuredClone(expected) });
|
|
110
|
+
};
|
|
111
|
+
for (const [field, expected] of Object.entries({ schema_id: "dd-flow/mb-fix-stage-result@1", flow_id: "mb-fix", run_id: input.runId, stage,
|
|
112
|
+
input_sha256: packet.inputSha256, intake_sha256: source.sha256, source_observation_sha256: intake.source_observation_sha256,
|
|
113
|
+
predecessors: [{ stage: previousStage, ...previous.result }] }))
|
|
114
|
+
insert(result, field, expected);
|
|
115
|
+
insert(result.details, "routing", intake.routing);
|
|
116
|
+
insert(result.details, "write_scope", intake.write_scope);
|
|
117
|
+
insert(result.details, "repair_receipt", reference);
|
|
118
|
+
if (stage === "review" || stage === "finish")
|
|
119
|
+
insert(result.details, "verification", prior.details.verification);
|
|
120
|
+
if (stage === "finish")
|
|
121
|
+
insert(result.details, "review", prior.details.review);
|
|
122
|
+
result.details.limitations = [...new Set([...prior.details.limitations, ...source.intake.limitations, ...result.details.limitations])];
|
|
123
|
+
const bytes = Buffer.from(JSON.stringify(result));
|
|
124
|
+
const index = JSON.parse(run.index_json), replay = index.stage_runs.some((entry) => entry.stage === stage && entry.status === "done");
|
|
125
|
+
const logicalReadback = `${bundle.descriptor.stage(stage).directory}/publication-readback.json`;
|
|
126
|
+
const readback = prepareStagePacket(path.join(packet.runRoot, logicalReadback), Buffer.from(JSON.stringify({
|
|
127
|
+
schema_id: "dd-flow/mb-fix-publication-readback@1", run_id: input.runId, stage, input_sha256: packet.inputSha256,
|
|
128
|
+
result_sha256: createHash("sha256").update(bytes).digest("hex"), publication: reference,
|
|
129
|
+
documents: publication ? publication.binding.write_scope.paths.map(logical => ({ path: logical,
|
|
130
|
+
after: publication.plan.state(publication.plan.actions().length).entries().find(entry => entry.path === logical) ?? null })) : []
|
|
131
|
+
})));
|
|
132
|
+
if (replay) {
|
|
133
|
+
if (!readAcceptedStageData(context, scope).bytes.equals(bytes))
|
|
134
|
+
refuse("accepted_result_changed");
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
if (publication) {
|
|
138
|
+
const actual = publication.plan.classify(run.workspace_root);
|
|
139
|
+
if (actual.completed !== actual.total)
|
|
140
|
+
refuse("publication_not_observed");
|
|
141
|
+
publishMemoryFixBeforeDocuments(packet.runRoot, publication.plan, publication.beforeDocuments);
|
|
142
|
+
}
|
|
143
|
+
result = validateMemoryFixStageResult(bytes, bundle.descriptor.stageBlob(stage, "result_schema"), {
|
|
144
|
+
runId: input.runId, stage, inputSha256: packet.inputSha256, intakeSha256: source.sha256, sourceObservationSha256: intake.source_observation_sha256,
|
|
145
|
+
findingIds: source.intake.selected_findings.map(finding => finding.id), projectRoot: run.workspace_root, runRoot: packet.runRoot,
|
|
146
|
+
predecessors: [{ stage: previousStage, ...previous.result }], writeScope: intake.write_scope, repairReceipt: reference
|
|
147
|
+
});
|
|
148
|
+
if (publication && stage !== "repair") {
|
|
149
|
+
const evidence = result.details.verification.flatMap(item => item.evidence);
|
|
150
|
+
if (memoryFixBeforeDocumentReferences(publication.plan).some(document => !evidence.some(ref => ref.root === "run"
|
|
151
|
+
&& ref.path === document.source.path && ref.sha256 === document.source.sha256)))
|
|
152
|
+
refuse("preservation_evidence_required");
|
|
153
|
+
const after = publication.plan.state(publication.plan.actions().length).entries();
|
|
154
|
+
if (publication.binding.write_scope.paths.some(logical => {
|
|
155
|
+
const document = after.find(entry => entry.path === logical);
|
|
156
|
+
return document?.kind === "file" && !evidence.some(ref => ref.root === "project" && ref.path === logical && ref.sha256 === document.sha256);
|
|
157
|
+
}))
|
|
158
|
+
refuse("output_evidence_required");
|
|
159
|
+
}
|
|
160
|
+
assertMemoryFixStageScope(result, prior);
|
|
161
|
+
}
|
|
162
|
+
const settlement = PreparedDescriptorStageSettlement.prepare(context, { ...input, bytes });
|
|
163
|
+
const keys = (name) => entityReferenceVariants(input.runId).map(ref => stageLifecycleMatchKey("stage_finish", ref, name, input.projectRoot));
|
|
164
|
+
const repairKeys = stage !== "repair" || replay ? keys("repair") : [];
|
|
165
|
+
const verifyKeys = stage === "review" || stage === "finish" ? keys("verify") : [];
|
|
166
|
+
const reviewKeys = stage === "finish" ? keys("review") : [];
|
|
167
|
+
const readOwner = (writer) => {
|
|
168
|
+
const physical = (sessionId) => {
|
|
169
|
+
const session = writer.db.get("SELECT harness,provider_session_id FROM sessions WHERE project_id=? AND run_id=? AND session_id=?", [project.id, input.runId, sessionId]);
|
|
170
|
+
if (!session?.harness || !session.provider_session_id)
|
|
171
|
+
refuse("physical_owner_missing");
|
|
172
|
+
return session;
|
|
173
|
+
};
|
|
174
|
+
const repair = stage !== "repair" || replay ? readAcceptedDescriptorStageSettlement(writer, { ...scope, stage: "repair" }, bundle, repairKeys) : null;
|
|
175
|
+
const verify = stage === "review" || stage === "finish" ? readAcceptedDescriptorStageSettlement(writer, { ...scope, stage: "verify" }, bundle, verifyKeys) : null;
|
|
176
|
+
const review = stage === "finish" ? readAcceptedDescriptorStageSettlement(writer, { ...scope, stage: "review" }, bundle, reviewKeys) : null;
|
|
177
|
+
const authorId = repair?.binding.sessionId ?? settlement.coordinatorSessionId(), author = physical(authorId);
|
|
178
|
+
const authorProof = repair ? { work_id: repair.work_id, work_session_id: repair.work_session_id, session_id: authorId,
|
|
179
|
+
...author, start_hook: repair.binding.startHook, association_sha256: repair.binding.associationSha256,
|
|
180
|
+
physical_binding_sha256: repair.binding.physicalBindingSha256, prompt_path: repair.binding.promptPath }
|
|
181
|
+
: readActiveDescriptorStageCoordinator(writer, scope, bundle);
|
|
182
|
+
if (publication && hybridDigest(publication.binding.author) !== hybridDigest(authorProof))
|
|
183
|
+
refuse("publication_author_changed");
|
|
184
|
+
if (stage === "finish") {
|
|
185
|
+
assertDiagnosticSessionIndependence([physical(verify.binding.sessionId)], [author]);
|
|
186
|
+
assertDiagnosticSessionIndependence([physical(review.binding.sessionId)], [author, physical(verify.binding.sessionId)]);
|
|
187
|
+
}
|
|
188
|
+
else if (stage !== "repair")
|
|
189
|
+
assertDiagnosticSessionIndependence([physical(settlement.coordinatorSessionId())], [author, ...(verify ? [physical(verify.binding.sessionId)] : [])]);
|
|
190
|
+
return { repair, verify, review, author };
|
|
191
|
+
};
|
|
192
|
+
const owner = context.db.readSnapshot(() => readOwner(context));
|
|
193
|
+
const closure = stage === "finish" ? memoryFixClosureProjection(result) : null;
|
|
194
|
+
const reportRoot = path.join(packet.runRoot, bundle.descriptor.stage(stage).directory);
|
|
195
|
+
const retainedReport = stage === "finish" ? readTerminalReport(context, scope, packet.attempt, reportRoot) : null;
|
|
196
|
+
if (stage === "finish" && replay && !retainedReport)
|
|
197
|
+
refuse("accepted_terminal_report_missing");
|
|
198
|
+
const acceptedRepair = !!closure && !!publication && !closure.some(item => item.status === "open");
|
|
199
|
+
const integration = stage === "finish" && acceptedRepair && (!replay || run.status !== "done")
|
|
200
|
+
? prepareMemoryFixFinishIntegration(context, scope, bundle) : null;
|
|
201
|
+
const integrationOutcome = replay && retainedReport ? retainedReport.normalized.integration
|
|
202
|
+
: integration ? { state: "integrated", observation: integration.value() }
|
|
203
|
+
: { state: publication ? "not_integrated_open_findings" : "not_applicable" };
|
|
204
|
+
const report = closure ? prepareStageReport({ run_id: input.runId, stage: "finish",
|
|
205
|
+
verdict: closure.some(item => item.status === "open") ? "completed_with_open_findings" : "completed", summary: result.summary,
|
|
206
|
+
memory_fix: { result, closure, source: source.intake.source, source_intake: source.reference,
|
|
207
|
+
unselected_ids: source.intake.unselected_ids, limitations: source.intake.limitations }, integration: integrationOutcome,
|
|
208
|
+
semantic: { acceptance: closure.map(item => `${item.finding_id}: ${item.status}; route=${item.route}`),
|
|
209
|
+
checks: result.details.verification.map(item => `${item.finding_id}: ${item.verdict}; ${item.summary}`),
|
|
210
|
+
evidence: [...result.details.verification, ...result.details.review].flatMap(item => item.evidence.map(ref => `${ref.root}:${ref.path}@${ref.sha256}`)),
|
|
211
|
+
next_action: closure.some(item => item.status === "open") ? "Open findings remain open; retain unintegrated work for explicit follow-up. Do not silently retry or close DEF records."
|
|
212
|
+
: "Only this accepted scope is complete; routed, deferred and unselected findings are not repaired by this RUN." } }) : null;
|
|
213
|
+
if (report && Buffer.byteLength(JSON.stringify(report.bytes)) > 7 * 1024 * 1024)
|
|
214
|
+
refuse("terminal_report_exceeds_bound");
|
|
215
|
+
if (retainedReport && report && retainedReport.sha256 !== report.sha256)
|
|
216
|
+
refuse("accepted_terminal_report_changed");
|
|
217
|
+
integration?.revalidate();
|
|
218
|
+
if (!replay && publication) {
|
|
219
|
+
const observed = publication.plan.classify(run.workspace_root);
|
|
220
|
+
if (observed.completed !== observed.total)
|
|
221
|
+
refuse("publication_not_observed");
|
|
222
|
+
}
|
|
223
|
+
const fence = (writer) => {
|
|
224
|
+
assertMemoryFixSourceIntakeCustody(writer, scope, bundle, source.sha256);
|
|
225
|
+
if (hybridDigest(readAcceptedStageData(writer, { ...scope, stage: previousStage })) !== hybridDigest(previous)
|
|
226
|
+
|| hybridDigest(readAcceptedMemoryFixIntakeEvidence(writer, scope, intakeFile)) !== hybridDigest(intake)
|
|
227
|
+
|| hybridDigest(readOwner(writer)) !== hybridDigest(owner))
|
|
228
|
+
refuse("stage_authority_changed");
|
|
229
|
+
const current = readMemoryFixPublication(writer, { project_id: project.id, run_id: input.runId });
|
|
230
|
+
if (publication && (!current?.completed || current.plan.sha256 !== publication.plan.sha256 || hybridDigest(current.binding) !== hybridDigest(publication.binding)
|
|
231
|
+
|| hybridDigest(readMemoryFixPublicationReference(writer, current, reference.path)) !== hybridDigest(reference)))
|
|
232
|
+
refuse("publication_changed");
|
|
233
|
+
if (!publication && current)
|
|
234
|
+
refuse("publication_without_accepted_scope");
|
|
235
|
+
if (stage === "repair" && !replay && intake.user_inputs_sha256 !== hybridDigest(readPreparedMemoryFlowUserInputs(writer, scope, "mb-fix", bundle)))
|
|
236
|
+
refuse("user_inputs_changed");
|
|
237
|
+
const rows = writer.db.all("SELECT payload_json FROM audit_events WHERE project_id=? AND event_type='flow_run.stage_packet' AND json_extract(payload_json,'$.run_id')=? AND json_extract(payload_json,'$.stage')=? AND json_extract(payload_json,'$.attempt')=? LIMIT 33", [project.id, input.runId, stage, packet.attempt]);
|
|
238
|
+
if (rows.length > 32 || rows.some(row => Buffer.byteLength(row.payload_json) > 8 * 1024 * 1024))
|
|
239
|
+
refuse("readback_custody_invalid");
|
|
240
|
+
const packets = rows.map(row => JSON.parse(row.payload_json)).filter(value => typeof value.file === "string"
|
|
241
|
+
&& resolveStagePublicationPath(writer, project.id, input.runId, value.file) === readback.file);
|
|
242
|
+
if (packets.length > 1 || packets.some(value => value.sha256 !== readback.sha256 || value.base64 !== readback.bytes.toString("base64")))
|
|
243
|
+
refuse("readback_custody_changed");
|
|
244
|
+
if (!packets.length) {
|
|
245
|
+
if (replay)
|
|
246
|
+
refuse("accepted_readback_missing");
|
|
247
|
+
acceptStagePacket(writer, { ...scope, prepared: readback });
|
|
248
|
+
}
|
|
249
|
+
integration?.assertCustody(writer);
|
|
250
|
+
if (report) {
|
|
251
|
+
const currentReport = readTerminalReport(writer, scope, packet.attempt, reportRoot);
|
|
252
|
+
if (currentReport && currentReport.sha256 !== report.sha256)
|
|
253
|
+
refuse("terminal_report_changed");
|
|
254
|
+
if (!currentReport) {
|
|
255
|
+
if (replay)
|
|
256
|
+
refuse("accepted_terminal_report_missing");
|
|
257
|
+
acceptStageReport(writer, { ...scope, root: reportRoot, prepared: report });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
try {
|
|
262
|
+
const accepted = settlement.apply(context, fence);
|
|
263
|
+
if (stage !== "finish")
|
|
264
|
+
return accepted;
|
|
265
|
+
integration?.revalidate();
|
|
266
|
+
const complete = PreparedDescriptorRunSettlement.prepare(context, input).apply(context, fence);
|
|
267
|
+
publishStageReport(context, project.id, input.runId, "finish", reportRoot);
|
|
268
|
+
return { ...accepted, ...complete, closure, reports: ["json", "md", "html"].map(extension => path.join(reportRoot, `stage-report.${extension}`)) };
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
if (stage !== "finish")
|
|
272
|
+
throw error;
|
|
273
|
+
let committed = false;
|
|
274
|
+
try {
|
|
275
|
+
committed = readAcceptedStageData(context, scope).bytes.equals(bytes);
|
|
276
|
+
}
|
|
277
|
+
catch { /* No accepted terminal data. */ }
|
|
278
|
+
if (!committed)
|
|
279
|
+
throw error;
|
|
280
|
+
throw new AppError("memory_fix_finish_pending", "Accepted finish requires projection or RUN settlement reconciliation", 1, { effect: "committed", run_id: input.runId, next_action: "reconcile_accepted_finish", cause: error instanceof AppError ? error.code : "finish_settlement_failed" });
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
2
|
+
import { AppError } from "../shared/errors.js";
|
|
3
|
+
import { hybridDigest } from "./hybrid-contracts.js";
|
|
4
|
+
import { validateMemoryFixRouting } from "./diagnostic-repair-intake.js";
|
|
5
|
+
import { assertMemoryRepairWritePaths } from "./memory-review-correction-plan.js";
|
|
6
|
+
import { verifyDiagnosticSources } from "./diagnostic-evidence.js";
|
|
7
|
+
function refuse(reason) {
|
|
8
|
+
throw new AppError("memory_fix_stage_result_invalid", "Memory repair result requires its selected input, bounded publication and independent observations", 2, { reason, effect: "no_effect", ...(reason === "invalid_schema" ? { phase: "prepare", recoverable: true } : {}) });
|
|
9
|
+
}
|
|
10
|
+
/** Contract/evidence validation only. Registered handlers must prove actual
|
|
11
|
+
* delivered consent, source-drift assessment, publication and distinct physical
|
|
12
|
+
* writer/verifier/reviewer ownership before settlement or finding closure.
|
|
13
|
+
*/
|
|
14
|
+
export function validateMemoryFixStageResult(bytes, schemaBytes, binding) {
|
|
15
|
+
if (!bytes.length || bytes.length > 1024 * 1024 || !schemaBytes.length || schemaBytes.length > 1024 * 1024)
|
|
16
|
+
refuse("result_exceeds_bound");
|
|
17
|
+
let result;
|
|
18
|
+
try {
|
|
19
|
+
result = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return refuse("invalid_schema");
|
|
23
|
+
}
|
|
24
|
+
const validate = (() => {
|
|
25
|
+
try {
|
|
26
|
+
const schema = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(schemaBytes));
|
|
27
|
+
if (schema.$id !== "dd-flow/mb-fix-stage-result@1")
|
|
28
|
+
refuse("frozen_schema_invalid");
|
|
29
|
+
return new Ajv2020({ strict: true, validateFormats: false }).compile(schema);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return refuse("frozen_schema_invalid");
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
if (!validate(result) || result?.schema_id !== "dd-flow/mb-fix-stage-result@1" || result.flow_id !== "mb-fix"
|
|
36
|
+
|| typeof result.summary !== "string" || !result.summary.trim())
|
|
37
|
+
refuse("invalid_schema");
|
|
38
|
+
if (result.run_id !== binding.runId || result.stage !== binding.stage || result.input_sha256 !== binding.inputSha256
|
|
39
|
+
|| result.intake_sha256 !== binding.intakeSha256 || result.source_observation_sha256 !== binding.sourceObservationSha256
|
|
40
|
+
|| hybridDigest(result.predecessors) !== hybridDigest(binding.predecessors))
|
|
41
|
+
refuse("foreign_stage_binding");
|
|
42
|
+
const details = result.details, routing = validateMemoryFixRouting(binding.findingIds, details.routing);
|
|
43
|
+
if (hybridDigest(routing) !== hybridDigest(details.routing))
|
|
44
|
+
refuse("routing_order_changed");
|
|
45
|
+
const repairs = routing.filter(decision => decision.route === "memory_repair").map(decision => decision.finding_id);
|
|
46
|
+
if (hybridDigest(details.write_scope) !== hybridDigest(binding.writeScope)
|
|
47
|
+
|| hybridDigest(details.repair_receipt) !== hybridDigest(binding.repairReceipt))
|
|
48
|
+
refuse("unowned_repair_claim");
|
|
49
|
+
if (details.write_scope) {
|
|
50
|
+
const scope = details.write_scope, paths = [...new Set(routing.flatMap(decision => decision.write_paths))].sort();
|
|
51
|
+
assertMemoryRepairWritePaths(scope.paths);
|
|
52
|
+
if (hybridDigest(scope.finding_ids) !== hybridDigest(repairs)
|
|
53
|
+
|| hybridDigest([...scope.paths].sort()) !== hybridDigest(paths))
|
|
54
|
+
refuse("repair_scope_changed");
|
|
55
|
+
}
|
|
56
|
+
if (!repairs.length && (details.write_scope || details.repair_receipt))
|
|
57
|
+
refuse("publication_without_repair_findings");
|
|
58
|
+
if (repairs.length && !details.write_scope)
|
|
59
|
+
refuse("intake_requires_approved_scope");
|
|
60
|
+
if (binding.stage === "intake" && details.repair_receipt)
|
|
61
|
+
refuse("repair_before_intake");
|
|
62
|
+
if (binding.stage !== "intake" && repairs.length && (!details.write_scope || !details.repair_receipt))
|
|
63
|
+
refuse("repair_requires_scope_and_receipt");
|
|
64
|
+
// Approval/publication authority is independently selected from SQL by the
|
|
65
|
+
// handler. Re-reading mutable projections here neither proves user consent
|
|
66
|
+
// nor strengthens that custody, and would break supported projection restore.
|
|
67
|
+
const verify = binding.stage === "verify" || binding.stage === "review" || binding.stage === "finish";
|
|
68
|
+
const review = binding.stage === "review" || binding.stage === "finish";
|
|
69
|
+
const observations = (items, expected) => {
|
|
70
|
+
const ids = items.map(item => item.finding_id);
|
|
71
|
+
if (new Set(ids).size !== ids.length || ids.length !== expected.length || expected.some(id => !ids.includes(id)))
|
|
72
|
+
refuse("incomplete_finding_observations");
|
|
73
|
+
for (const item of items) {
|
|
74
|
+
if (!item.summary.trim())
|
|
75
|
+
refuse("invalid_schema");
|
|
76
|
+
for (const evidence of item.evidence)
|
|
77
|
+
verifyDiagnosticSources(evidence.root === "run" ? binding.runRoot : binding.projectRoot, [evidence]);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
observations(details.verification, verify ? repairs : []);
|
|
81
|
+
observations(details.review, review ? binding.findingIds : []);
|
|
82
|
+
if (details.verification.some(item => item.verdict === "resolved" && !item.evidence.length))
|
|
83
|
+
refuse("closure_without_evidence");
|
|
84
|
+
if (details.review.some(item => item.disposition === "accept" && !item.evidence.length))
|
|
85
|
+
refuse("closure_without_evidence");
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
export function assertMemoryFixStageScope(result, prior) {
|
|
89
|
+
if (result.intake_sha256 !== prior.intake_sha256 || result.source_observation_sha256 !== prior.source_observation_sha256
|
|
90
|
+
|| hybridDigest(result.details.routing) !== hybridDigest(prior.details.routing)
|
|
91
|
+
|| hybridDigest(result.details.write_scope) !== hybridDigest(prior.details.write_scope)
|
|
92
|
+
|| prior.details.limitations.some(value => !result.details.limitations.includes(value))
|
|
93
|
+
|| prior.stage !== "intake" && hybridDigest(result.details.repair_receipt) !== hybridDigest(prior.details.repair_receipt)
|
|
94
|
+
|| ["verify", "review"].includes(prior.stage) && hybridDigest(result.details.verification) !== hybridDigest(prior.details.verification)
|
|
95
|
+
|| prior.stage === "review" && hybridDigest(result.details.review) !== hybridDigest(prior.details.review))
|
|
96
|
+
refuse("accepted_scope_changed");
|
|
97
|
+
}
|
|
98
|
+
/** Proposed report projection, never a DEF mutation or independent ownership proof. */
|
|
99
|
+
export function memoryFixClosureProjection(result) {
|
|
100
|
+
if (result.stage !== "finish")
|
|
101
|
+
refuse("finish_required");
|
|
102
|
+
return result.details.routing.map(decision => ({ finding_id: decision.finding_id, route: decision.route,
|
|
103
|
+
status: decision.route === "defer" ? "deferred" : decision.route !== "memory_repair" ? "routed"
|
|
104
|
+
: result.details.verification.some(item => item.finding_id === decision.finding_id && item.verdict === "resolved")
|
|
105
|
+
&& result.details.review.some(item => item.finding_id === decision.finding_id && item.disposition === "accept") ? "closed" : "open" }));
|
|
106
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { AppError } from "../shared/errors.js";
|
|
5
|
+
import { projectCheckoutRoot, resolveProjectRoot } from "../storage/paths.js";
|
|
6
|
+
import { requireProjectByRoot } from "./projects.js";
|
|
7
|
+
import { loadVnextWorkspacePolicy } from "./vnext-workspace-policy.js";
|
|
8
|
+
import { prepareManagedWorktree, createManagedWorktree } from "./worktrees.js";
|
|
9
|
+
import { inspectMemoryGitExecutable } from "./memory-init-preflight.js";
|
|
10
|
+
import { prepareMemoryFixGitPolicy } from "./memory-fix-finish-integration.js";
|
|
11
|
+
import { hybridDigest } from "./hybrid-contracts.js";
|
|
12
|
+
import { appendAudit } from "./audit.js";
|
|
13
|
+
const intentEvent = "memory_fix.workspace_intent", readyEvent = "memory_fix.workspace_ready";
|
|
14
|
+
function refuse(reason) { throw new AppError("memory_fix_workspace_invalid", "Repair workspace requires its original project-scoped selection", 2, { reason, effect: "no_effect" }); }
|
|
15
|
+
function pending(reason, details = {}) {
|
|
16
|
+
throw new AppError("memory_fix_workspace_pending", "Reconcile the original workspace creation before redispatch", 1, { reason, effect: "unknown", next_action: "reconcile_original_workspace", ...details });
|
|
17
|
+
}
|
|
18
|
+
/** Worktrunk owns physical creation. This wrapper retains one intent before
|
|
19
|
+
* dispatch and never reruns an unresolved creation or adopts a foreign tree. */
|
|
20
|
+
export async function prepareMemoryFixWorkspace(context, input) {
|
|
21
|
+
if (context.db.isOwnedWriteTransaction?.())
|
|
22
|
+
refuse("preparation_outside_writer_required");
|
|
23
|
+
const projectRoot = resolveProjectRoot(input.projectRoot), project = requireProjectByRoot(context, projectRoot);
|
|
24
|
+
if (projectRoot !== input.projectRoot || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,95}$/.test(input.requestId))
|
|
25
|
+
refuse("invalid_scope");
|
|
26
|
+
if (input.selectionSha256 !== undefined && !/^[a-f0-9]{64}$/.test(input.selectionSha256))
|
|
27
|
+
refuse("invalid_selection_identity");
|
|
28
|
+
const scope = { projectRoot, requestId: input.requestId };
|
|
29
|
+
const read = (event) => {
|
|
30
|
+
const rows = context.db.all("SELECT payload_json FROM audit_events WHERE project_id=? AND event_type=? AND json_extract(payload_json,'$.scope.requestId')=? LIMIT 2", [project.id, event, input.requestId]);
|
|
31
|
+
if (!rows.length)
|
|
32
|
+
return null;
|
|
33
|
+
if (rows.length !== 1 || Buffer.byteLength(rows[0].payload_json) > 32768)
|
|
34
|
+
pending("ambiguous_workspace_custody");
|
|
35
|
+
try {
|
|
36
|
+
const value = JSON.parse(rows[0].payload_json);
|
|
37
|
+
if (hybridDigest(value.scope) !== hybridDigest(scope))
|
|
38
|
+
pending("workspace_scope_changed");
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return pending("invalid_workspace_custody");
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const observe = (intent) => {
|
|
46
|
+
const policy = prepareMemoryFixGitPolicy(context.env, { scope: { ...scope, workspaceRoot: intent.workspace_root }, gitExecutable: intent.git_executable, selection: intent.git_policy });
|
|
47
|
+
const git = JSON.parse(policy.bytes.toString("utf8")).policy;
|
|
48
|
+
if (intent.creation && (git.workspace_branch !== intent.creation.branch || git.initial_head !== intent.creation.base))
|
|
49
|
+
refuse("created_workspace_baseline_changed");
|
|
50
|
+
const stat = fs.lstatSync(intent.workspace_root);
|
|
51
|
+
if (!stat.isDirectory() || fs.realpathSync(intent.workspace_root) !== intent.workspace_root)
|
|
52
|
+
refuse("workspace_identity_changed");
|
|
53
|
+
return { policy_sha256: policy.sha256, owner: { dev: stat.dev, ino: stat.ino } };
|
|
54
|
+
};
|
|
55
|
+
const retainReady = (intent, actual) => context.db.writeTransaction(() => {
|
|
56
|
+
const intentSha256 = hybridDigest(intent), value = { scope, intent_sha256: intentSha256, ...actual };
|
|
57
|
+
if (hybridDigest(read(intentEvent)) !== intentSha256)
|
|
58
|
+
pending("workspace_custody_changed");
|
|
59
|
+
const current = read(readyEvent);
|
|
60
|
+
if (current) {
|
|
61
|
+
if (hybridDigest(current) !== hybridDigest(value))
|
|
62
|
+
pending("workspace_custody_changed");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
appendAudit(context, { projectId: project.id, eventType: readyEvent, payload: value });
|
|
66
|
+
});
|
|
67
|
+
const prior = read(intentEvent);
|
|
68
|
+
let ready = read(readyEvent);
|
|
69
|
+
if (prior) {
|
|
70
|
+
if (input.workspaceRoot !== undefined && input.workspaceRoot !== prior.workspace_root
|
|
71
|
+
|| input.selectionSha256 !== undefined && input.selectionSha256 !== prior.selection_sha256
|
|
72
|
+
|| input.gitPolicy !== undefined && hybridDigest(input.gitPolicy) !== hybridDigest(prior.git_policy))
|
|
73
|
+
refuse("request_changed");
|
|
74
|
+
if (!ready && prior.creation && fs.existsSync(prior.workspace_root)) {
|
|
75
|
+
// Read-only reconciliation of an original creation with a lost reply.
|
|
76
|
+
// Exact private path/repository/branch/base and a clean tree are required;
|
|
77
|
+
// no second Worktrunk call, reset or adoption of changed user work occurs.
|
|
78
|
+
const actual = observe(prior), result = spawnSync(prior.git_executable, ["-c", "core.fsmonitor=false", "-C", prior.workspace_root, "status", "--porcelain=v1", "-z", "--untracked-files=all"], { env: { ...Object.fromEntries(Object.entries(context.env).filter(([key]) => !key.startsWith("GIT_"))), GIT_OPTIONAL_LOCKS: "0" }, timeout: 5000, maxBuffer: 1024 * 1024 });
|
|
79
|
+
if (result.error || result.signal || result.status !== 0 || result.stdout.length)
|
|
80
|
+
pending("created_workspace_not_pristine");
|
|
81
|
+
retainReady(prior, actual);
|
|
82
|
+
ready = read(readyEvent);
|
|
83
|
+
}
|
|
84
|
+
if (!ready || ready.intent_sha256 !== hybridDigest(prior))
|
|
85
|
+
pending("workspace_creation_unresolved");
|
|
86
|
+
const actual = observe(prior);
|
|
87
|
+
if (hybridDigest(actual) !== hybridDigest({ policy_sha256: ready.policy_sha256, owner: ready.owner }))
|
|
88
|
+
refuse("workspace_changed_before_request_retention");
|
|
89
|
+
return { workspaceRoot: prior.workspace_root, gitPolicy: prior.git_policy, gitExecutable: prior.git_executable };
|
|
90
|
+
}
|
|
91
|
+
if (ready)
|
|
92
|
+
pending("workspace_intent_missing");
|
|
93
|
+
const defaults = input.gitPolicy ? null : loadVnextWorkspacePolicy(projectRoot).workspace;
|
|
94
|
+
const gitPolicy = input.gitPolicy ?? { route: defaults.route, integrationBranch: defaults.integration_branch };
|
|
95
|
+
const gitExecutable = inspectMemoryGitExecutable(context.env).executable;
|
|
96
|
+
const key = hybridDigest({ project_id: project.id, scope }).slice(0, 16);
|
|
97
|
+
const workspaceRoot = input.workspaceRoot ?? (gitPolicy.route === "integration_branch_direct" ? projectRoot
|
|
98
|
+
: path.join(projectCheckoutRoot(context.ddFlowHome, project.id), "worktrees", `mb-fix-${key}`, path.basename(projectRoot)));
|
|
99
|
+
const creation = input.workspaceRoot === undefined && gitPolicy.route === "feature_worktree"
|
|
100
|
+
? prepareManagedWorktree({ projectRoot, branch: `codex/mb-fix-${key}`, base: gitPolicy.integrationBranch, path: workspaceRoot }) : null;
|
|
101
|
+
const intent = { scope, workspace_root: workspaceRoot, git_policy: structuredClone(gitPolicy), git_executable: gitExecutable,
|
|
102
|
+
selection_sha256: input.selectionSha256 ?? null, creation };
|
|
103
|
+
if (!creation)
|
|
104
|
+
observe(intent);
|
|
105
|
+
const claimed = context.db.writeTransaction(() => {
|
|
106
|
+
if (read(intentEvent) || read(readyEvent))
|
|
107
|
+
return false;
|
|
108
|
+
appendAudit(context, { projectId: project.id, eventType: intentEvent, payload: intent });
|
|
109
|
+
return true;
|
|
110
|
+
});
|
|
111
|
+
if (!claimed)
|
|
112
|
+
pending("workspace_creation_already_owned");
|
|
113
|
+
try {
|
|
114
|
+
if (creation) {
|
|
115
|
+
const created = await createManagedWorktree(context, creation, creation);
|
|
116
|
+
if (created.worktreePath !== workspaceRoot)
|
|
117
|
+
pending("unexpected_worktrunk_workspace", { expected_workspace_root: workspaceRoot, observed_workspace_root: created.worktreePath });
|
|
118
|
+
}
|
|
119
|
+
retainReady(intent, observe(intent));
|
|
120
|
+
return { workspaceRoot, gitPolicy, gitExecutable };
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error instanceof AppError && error.code === "memory_fix_workspace_pending")
|
|
124
|
+
throw error;
|
|
125
|
+
return pending(error instanceof AppError ? error.code : "workspace_creation_failed");
|
|
126
|
+
}
|
|
127
|
+
}
|