@aibyzero/cm-workflow 0.17.1 → 0.18.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/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +23 -0
- package/CHANGELOG.md +224 -0
- package/README.md +14 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/VERSION +1 -1
- package/compat/claude-commands/cm-challenge.md +3 -0
- package/docs/architecture.md +11 -0
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +150 -15
- package/docs/live-evidence-drivers.md +28 -4
- package/docs/out-of-scope/README.md +25 -0
- package/docs/out-of-scope/background-supervisor.md +32 -0
- package/docs/reviewed-integration.md +48 -0
- package/docs/user-guide.md +50 -21
- package/install-codex.sh +331 -18
- package/install.ps1 +28 -2
- package/install.sh +321 -17
- package/package.json +2 -1
- package/runtime/js/cm-ai/batch-location.mjs +55 -0
- package/runtime/js/cm-ai/batch-plan.mjs +242 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
- package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -2
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
- package/runtime/js/cm-ai/control-policy.mjs +21 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +114 -11
- package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
- package/runtime/js/cm-ai/effect-contract.mjs +11 -2
- package/runtime/js/cm-ai/execution-policy.mjs +3 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
- package/runtime/js/cm-ai/execution-store.mjs +60 -17
- package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
- package/runtime/js/cm-ai/host-check.mjs +11 -5
- package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
- package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
- package/runtime/js/cm-ai/host-replay.mjs +148 -0
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
- package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
- package/runtime/js/cm-ai/live-evidence.mjs +28 -6
- package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
- package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
- package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
- package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
- package/runtime/js/cm-ai/review-package.mjs +79 -7
- package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
- package/runtime/js/cm-ai/review-presentation.mjs +177 -8
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
- package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
- package/runtime/js/cm-ai/scope-revision.mjs +38 -0
- package/runtime/js/cm-ai/specification-material.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +242 -39
- package/runtime/js/cm-ai/verification-auto.mjs +38 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
- package/runtime/js/cm-ai/worker-claude.mjs +35 -13
- package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
- package/runtime/js/cm-ai/worker-codex.mjs +41 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
- package/runtime/js/cm-fix/cause-package.mjs +46 -1
- package/runtime/js/cm-fix/command-correction.mjs +37 -0
- package/runtime/js/cm-fix/cooperative.mjs +12 -0
- package/runtime/js/cm-fix/dossier.mjs +8 -2
- package/runtime/js/cm-fix/execution.mjs +578 -100
- package/runtime/js/cm-fix/final-review.mjs +39 -8
- package/runtime/js/cm-fix/finish.mjs +15 -11
- package/runtime/js/cm-fix/host-review.mjs +65 -10
- package/runtime/js/cm-fix/host.mjs +35 -12
- package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
- package/runtime/js/cm-fix/metrics.mjs +18 -5
- package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
- package/runtime/js/cm-fix/regression.mjs +16 -7
- package/runtime/js/cm-fix/repair.mjs +29 -8
- package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
- package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
- package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
- package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
- package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
- package/runtime/js/cm-fix/review-verification.mjs +214 -0
- package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
- package/runtime/js/cm-fix/start.mjs +6 -3
- package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
- package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
- package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
- package/runtime/js/cm-prd/accepted-design.mjs +8 -0
- package/runtime/js/cm-prd/analysis.mjs +13 -9
- package/runtime/js/cm-prd/change.mjs +37 -16
- package/runtime/js/cm-prd/draft-save.mjs +13 -6
- package/runtime/js/cm-prd/draft.mjs +31 -3
- package/runtime/js/cm-prd/failed-correction.mjs +19 -3
- package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
- package/runtime/js/cm-prd/review-correction.mjs +6 -4
- package/runtime/js/cm-prd/review-disposition.mjs +7 -1
- package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
- package/runtime/js/cm-prd/self-check.mjs +125 -6
- package/runtime/js/cm-prd/session.mjs +30 -1
- package/runtime/js/cm-prd/summary.mjs +11 -5
- package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
- package/runtime/js/cm-prd/tree-digest.mjs +34 -0
- package/runtime/js/cm-prd/validation-reason.mjs +8 -4
- package/runtime/js/cm-security/scan.mjs +1 -1
- package/runtime/js/commander/decision.mjs +44 -0
- package/runtime/js/commander/dispatch-registry.mjs +110 -0
- package/runtime/js/commander/ledger.mjs +265 -0
- package/runtime/js/commander/preflight.mjs +107 -0
- package/runtime/js/notify-later.mjs +13 -0
- package/runtime/js/notify-send.mjs +6 -2
- package/runtime/js/notify.mjs +570 -63
- package/runtime/js/review-findings.mjs +38 -0
- package/runtime/js/session-boundary.mjs +56 -0
- package/runtime/js/session-handoff.mjs +68 -0
- package/runtime/js/spec-task-line.mjs +27 -13
- package/runtime/js/specs-status.mjs +1 -1
- package/runtime/js/task-scope.mjs +197 -0
- package/runtime/logging.md +6 -1
- package/runtime/model-efficiency.md +69 -10
- package/runtime/orchestration.md +3 -1
- package/runtime/project-learning.md +2 -0
- package/runtime/review.md +3 -2
- package/runtime/test-contract.md +1 -0
- package/scripts/ci-test-weights.json +3 -0
- package/scripts/cm-ai-admission.mjs +11 -5
- package/scripts/cm-ai-admission.test.mjs +23 -2
- package/scripts/cm-ai-batch-drive.mjs +79 -18
- package/scripts/cm-ai-batch-drive.test.mjs +169 -3
- package/scripts/cm-ai-batch-host.mjs +38 -9
- package/scripts/cm-ai-batch-host.test.mjs +6 -5
- package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
- package/scripts/cm-ai-batch-location.test.mjs +57 -0
- package/scripts/cm-ai-batch-plan.mjs +52 -0
- package/scripts/cm-ai-batch-plan.test.mjs +397 -0
- package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
- package/scripts/cm-ai-batch-run.mjs +471 -57
- package/scripts/cm-ai-batch-run.test.mjs +23 -4
- package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
- package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
- package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
- package/scripts/cm-ai-control-launch.test.mjs +21 -0
- package/scripts/cm-ai-control-policy.test.mjs +14 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
- package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
- package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
- package/scripts/cm-ai-development-rework.test.mjs +423 -0
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +34 -2
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
- package/scripts/cm-ai-integration-independence.test.mjs +23 -0
- package/scripts/cm-ai-integration-launch.test.mjs +240 -0
- package/scripts/cm-ai-integration-preview.mjs +41 -0
- package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
- package/scripts/cm-ai-nested-execution.test.mjs +29 -1
- package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
- package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
- package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
- package/scripts/cm-ai-review-failure.test.mjs +150 -5
- package/scripts/cm-ai-run.mjs +88 -21
- package/scripts/cm-ai-scope-revision.test.mjs +341 -0
- package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
- package/scripts/cm-ai-supersede.test.mjs +28 -0
- package/scripts/cm-ai-verification-auto.test.mjs +99 -0
- package/scripts/cm-announce-hook.mjs +35 -8
- package/scripts/cm-announce-hook.test.mjs +25 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +58 -1
- package/scripts/cm-claude-developer-worker.test.mjs +56 -7
- package/scripts/cm-claude-install-layout.test.mjs +1 -1
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +13 -0
- package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
- package/scripts/cm-codex-developer-worker.test.mjs +120 -0
- package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
- package/scripts/cm-codex-prompt-input.test.mjs +153 -0
- package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
- package/scripts/cm-commander-ledger.test.mjs +260 -0
- package/scripts/cm-commander-p2.test.mjs +295 -0
- package/scripts/cm-commander-preflight.mjs +84 -0
- package/scripts/cm-commander.mjs +116 -0
- package/scripts/cm-config-lock.mjs +35 -0
- package/scripts/cm-controlled-correction.test.mjs +10 -1
- package/scripts/cm-developer-failure-code.test.mjs +62 -0
- package/scripts/cm-display-task-id.test.mjs +41 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
- package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
- package/scripts/cm-external-batch-host.test.mjs +4 -3
- package/scripts/cm-external-process-cleanup.test.mjs +128 -0
- package/scripts/cm-external-qa-fix.test.mjs +89 -7
- package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
- package/scripts/cm-failover.mjs +48 -10
- package/scripts/cm-failover.test.mjs +46 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
- package/scripts/cm-fix-command-correction.mjs +17 -0
- package/scripts/cm-fix-command-correction.test.mjs +211 -0
- package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
- package/scripts/cm-fix-drive.mjs +33 -5
- package/scripts/cm-fix-drive.test.mjs +49 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
- package/scripts/cm-fix-host-review.test.mjs +21 -9
- package/scripts/cm-fix-host.mjs +26 -8
- package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
- package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
- package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
- package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
- package/scripts/cm-fix-review-preflight.mjs +24 -0
- package/scripts/cm-fix-review-storage.test.mjs +233 -0
- package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
- package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
- package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
- package/scripts/cm-fix-review-verification.test.mjs +146 -0
- package/scripts/cm-fix-revision-transport.test.mjs +81 -0
- package/scripts/cm-fix-source-correction.test.mjs +296 -0
- package/scripts/cm-fix-test-type-correction.mjs +18 -0
- package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
- package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
- package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
- package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
- package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
- package/scripts/cm-fix-verification-recovery.mjs +33 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
- package/scripts/cm-install-manifest.sh +351 -0
- package/scripts/cm-live-evidence.test.mjs +59 -1
- package/scripts/cm-log-event.mjs +61 -10
- package/scripts/cm-log-event.test.mjs +121 -1
- package/scripts/cm-matt-skills.mjs +576 -0
- package/scripts/cm-matt-skills.test.mjs +550 -0
- package/scripts/cm-notify-command.test.mjs +42 -10
- package/scripts/cm-notify.mjs +14 -10
- package/scripts/cm-notify.test.mjs +575 -59
- package/scripts/cm-patrol.mjs +4 -1
- package/scripts/cm-patrol.test.mjs +23 -5
- package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
- package/scripts/cm-prd-completion.test.mjs +56 -13
- package/scripts/cm-prd-design-phase.test.mjs +78 -8
- package/scripts/cm-prd-draft-save.test.mjs +12 -0
- package/scripts/cm-prd-draft.test.mjs +1 -1
- package/scripts/cm-prd-drive.mjs +13 -6
- package/scripts/cm-prd-drive.test.mjs +45 -1
- package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
- package/scripts/cm-prd-host.mjs +10 -5
- package/scripts/cm-prd-host.test.mjs +4 -2
- package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
- package/scripts/cm-prd-review-disposition.test.mjs +124 -8
- package/scripts/cm-prd-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
- package/scripts/cm-prd-self-check.test.mjs +105 -5
- package/scripts/cm-prd-summary.test.mjs +24 -3
- package/scripts/cm-prd-task-grouping.test.mjs +6 -6
- package/scripts/cm-prd-tree-digest.test.mjs +74 -0
- package/scripts/cm-refactor-drive.mjs +2 -1
- package/scripts/cm-refactor-drive.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +1 -1
- package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
- package/scripts/cm-skill-hints-exam.mjs +149 -0
- package/scripts/cm-skill-hints-install.test.mjs +168 -0
- package/scripts/cm-skill-hints.exam.json +706 -0
- package/scripts/cm-skill-hints.json +119 -0
- package/scripts/cm-skill-hints.mjs +669 -0
- package/scripts/cm-skill-hints.test.mjs +831 -0
- package/scripts/cm-skill-judge.mjs +181 -0
- package/scripts/cm-skill-judge.test.mjs +255 -0
- package/scripts/cm-specs-status.test.mjs +4 -2
- package/scripts/cm-start-check.mjs +208 -0
- package/scripts/cm-start-check.test.mjs +321 -0
- package/scripts/cm-task-gate.mjs +150 -29
- package/scripts/cm-task-gate.test.mjs +73 -1
- package/scripts/cm-task-id-grammar.test.mjs +66 -0
- package/scripts/cm-task-scope.test.mjs +308 -0
- package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
- package/scripts/cm-upgrade-compat.test.mjs +239 -0
- package/scripts/cm-workflow-config.mjs +12 -2
- package/scripts/fixtures/fix-verification-claude.mjs +44 -0
- package/scripts/fixtures/reviewed-integration.mjs +202 -0
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/session-boundary.test.mjs +170 -0
- package/scripts/test-npm-install.py +14 -3
- package/scripts/test-shell-compat.sh +2 -0
- package/scripts/validate-public-repo.py +1 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N4-review.md +2 -1
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/N8-finish.md +22 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
- package/skills/cm-ai/references/js-host-recovery.md +79 -3
- package/skills/cm-ai/references/js-host.md +56 -16
- package/skills/cm-challenge/SKILL.md +65 -0
- package/skills/cm-challenge/evals/README.md +18 -0
- package/skills/cm-challenge/evals/trigger-cases.json +20 -0
- package/skills/cm-challenge/evals/trigger-config.json +28 -0
- package/skills/cm-challenge/references/examples.md +15 -0
- package/skills/cm-check/SKILL.md +5 -0
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +12 -3
- package/skills/cm-fix/references/command-correction.md +67 -0
- package/skills/cm-fix/references/isolated-review.md +54 -0
- package/skills/cm-fix/references/js-host.md +62 -2
- package/skills/cm-fix/references/test-type-correction.md +72 -0
- package/skills/cm-fix/references/verification-recovery.md +114 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-notify/SKILL.md +2 -0
- package/skills/cm-prd/SKILL.md +12 -8
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +6 -0
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-host.md +4 -2
- package/skills/cm-prd/references/spec-self-check.md +5 -1
- package/skills/cm-refactor/SKILL.md +8 -0
- package/skills/cm-refactor/references/js-host.md +2 -0
- package/skills/cm-test/SKILL.md +4 -0
- package/templates/dashboard/dashboard.html +2 -2
- package/templates/pixel/cm-pixel.html +1 -1
- package/templates/pixel/cm-pixel.sh +1 -1
- package/templates/pixel/dev/template.html +1 -1
- package/templates/statusline/cm-statusline.sh +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {typeFiles} from './test-type-recovery.mjs';
|
|
2
|
+
import {inspectTestTypeCorrection} from './test-type-correction.mjs';
|
|
1
3
|
// Current-host minimal repair. The owner supplies prior admitted evidence and
|
|
2
4
|
// durable registration; this capability neither runs providers nor completes a task.
|
|
3
5
|
import {currentTestFiles,verifyExtensionFiles} from './test-extension.mjs';
|
|
@@ -10,9 +12,13 @@ import {inspectFixBaseline,fixBaselineFiles} from './baseline.mjs';
|
|
|
10
12
|
import {digest,json,need,shape,validIdentity} from '../cm-ai/effect-contract.mjs';
|
|
11
13
|
import {inspectFixRepairReview} from './final-review.mjs';
|
|
12
14
|
|
|
13
|
-
// Fixed documentation targets
|
|
15
|
+
// Fixed documentation targets, including subproject maps, still require the
|
|
16
|
+
// host-approved scope and all developer/snapshot path protections.
|
|
14
17
|
// They are not root-cause source material: new maps do not exist at cause Review.
|
|
15
|
-
export
|
|
18
|
+
export function isFixMapPath(file){
|
|
19
|
+
try{validateDeveloperScope([file]);}catch{return false;}
|
|
20
|
+
return /^(?:[^/]+\/)*docs\/codebase-context\/(?:00-index|01-overview|02-directory|03-architecture|04-api-routes|05-data-models|06-core-modules|07-business-logic|08-conventions|09-changelog)\.md$/.test(file);
|
|
21
|
+
}
|
|
16
22
|
|
|
17
23
|
export function inspectFixRepair(raw,baselineRaw,{allowUnchanged=false}={}){
|
|
18
24
|
const baseline=readReviewBaseline(baselineRaw),value=json(raw);
|
|
@@ -35,20 +41,35 @@ export function inspectFixRepair(raw,baselineRaw,{allowUnchanged=false}={}){
|
|
|
35
41
|
return value;
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
export function verifyFixRepair({codeProject,specsRoot,baseline,result,allowUnchanged=false}){
|
|
44
|
+
export function verifyFixRepair({codeProject,specsRoot,baseline,result,allowUnchanged=false,testTypeCorrection=null,allowTypeBefore=false}){
|
|
39
45
|
const checked=inspectFixRepair(result,baseline,{allowUnchanged});
|
|
40
46
|
const after=captureReviewBaseline({root:codeProject,specsRoot,identity:baseline.identity,version:baseline.version,scope:baseline.scope,requirements:baseline.requirements});
|
|
41
47
|
const previous=new Map(baseline.files.map(file=>[file.path,file])),current=new Map(after.files.map(file=>[file.path,file]));
|
|
48
|
+
// One proof per fresh snapshot; unrelated inventory entries do not change it.
|
|
49
|
+
const c=testTypeCorrection?inspectTestTypeCorrection(testTypeCorrection):null;
|
|
50
|
+
const metadata=f=>{if(!f)return null;const {contentBase64,...rest}=f;return rest;};
|
|
42
51
|
for(const file of new Set([...previous.keys(),...current.keys()])){
|
|
43
|
-
if(!baseline.scope.includes(file))
|
|
52
|
+
if(!baseline.scope.includes(file)){
|
|
53
|
+
const allowed=c&&file===c.path&&digest(metadata(previous.get(file)))===digest(metadata(c.before))
|
|
54
|
+
&&(digest(metadata(current.get(file)))===digest(metadata(c.after))||allowTypeBefore&&digest(metadata(current.get(file)))===digest(metadata(c.before)));
|
|
55
|
+
need(allowed||digest(previous.get(file)??null)===digest(current.get(file)??null),'out_of_scope');
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
58
|
const files=after.files.filter(file=>baseline.scope.includes(file.path)).map(({contentBase64,...metadata})=>metadata);
|
|
46
59
|
need(digest(files)===digest(checked.files),'repair_evidence_changed');
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
export function prepareFixRepair(options,{bridge,assertReviewReady,pinnedBaseline=null,protectedMode=false}){
|
|
50
|
-
|
|
51
|
-
|
|
63
|
+
// Inspect only the own-key before json validates every descriptor/plain value;
|
|
64
|
+
// never read a feedback getter or strip unvalidated evidence to make it fit.
|
|
65
|
+
const hasReviewFeedback=options!==null&&typeof options==='object'&&Object.hasOwn(options,'reviewFeedback');
|
|
66
|
+
const config=hasReviewFeedback?json(options,13*1024*1024+Buffer.byteLength(',"reviewFeedback":')):json(options);
|
|
67
|
+
if(hasReviewFeedback){
|
|
68
|
+
const {reviewFeedback,...parameters}=config;
|
|
69
|
+
json(parameters); // All ordinary repair arguments retain their original 1 MiB budget.
|
|
70
|
+
}
|
|
71
|
+
shape(config,['codeProject','specsRoot','identity','scope','requirements','defect','diagnosis',
|
|
72
|
+
'redTest','baseline','redEvidence','beforeBaseline',...(Object.hasOwn(config,'reviewFeedback')?['reviewFeedback']:[]),...(Object.hasOwn(config,'testExtension')?['testExtension']:[]),...(Object.hasOwn(config,'testTypeCorrection')?['testTypeCorrection']:[])]);
|
|
52
73
|
const priorReview=Object.hasOwn(config,'reviewFeedback')?inspectFixRepairReview(config.reviewFeedback,config.identity):null;
|
|
53
74
|
validIdentity(config.identity);validateDeveloperScope(config.scope);
|
|
54
75
|
need(config.diagnosis.status==='diagnosed'&&Array.isArray(config.diagnosis.affectedPaths)
|
|
@@ -66,8 +87,8 @@ export function prepareFixRepair(options,{bridge,assertReviewReady,pinnedBaselin
|
|
|
66
87
|
need(bridge&&typeof bridge.call==='function'&&typeof assertReviewReady==='function','repair_unavailable');
|
|
67
88
|
const verifyTests=()=>{
|
|
68
89
|
verifyExtensionFiles(config.codeProject,config.testExtension);
|
|
69
|
-
verifyFixRedEvidence(red,config.redTest,config.specsRoot,currentTestFiles(red.testFiles,config.testExtension));
|
|
70
|
-
need(digest(fixBaselineFiles(config.baseline))===digest(currentTestFiles(previous.testFiles,config.testExtension)),'baseline_files_changed');
|
|
90
|
+
verifyFixRedEvidence(red,config.redTest,config.specsRoot,currentTestFiles(typeFiles(red.testFiles,config.testTypeCorrection),config.testExtension));
|
|
91
|
+
need(digest(fixBaselineFiles(config.baseline))===digest(currentTestFiles(typeFiles(previous.testFiles,config.testTypeCorrection),config.testExtension)),'baseline_files_changed');
|
|
71
92
|
};
|
|
72
93
|
verifyTests();
|
|
73
94
|
const capture=()=>captureReviewBaseline({root:config.codeProject,specsRoot:config.specsRoot,identity:config.identity,
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Reviewer commands run only in their disposable copy. The authenticated CLI
|
|
2
|
+
// never shares its environment or network permission with project test code.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import {spawn,spawnSync} from 'node:child_process';
|
|
7
|
+
import {types} from 'node:util';
|
|
8
|
+
import {ownedProcessCleanup} from '../cm-ai/owned-process-cleanup.mjs';
|
|
9
|
+
import {need} from '../cm-ai/effect-contract.mjs';
|
|
10
|
+
|
|
11
|
+
const SYSTEM_READ=['/System/Library','/System/Cryptexes','/usr/bin','/usr/sbin','/usr/lib','/usr/libexec','/usr/share',
|
|
12
|
+
'/bin','/sbin','/Library/Apple','/opt/homebrew/Cellar'];
|
|
13
|
+
const SYSTEM_ROOTS=['/System','/usr','/bin','/sbin','/Library','/opt','/private/etc','/private/var/db'];
|
|
14
|
+
const unavailable=(code,output='')=>({exitCode:null,outcome:'unavailable',code,output});
|
|
15
|
+
const inside=(root,file)=>file===root||file.startsWith(root+path.sep);
|
|
16
|
+
function profile(cwd){
|
|
17
|
+
// Homebrew's etc/var may hold local credentials. Only installed formulae are
|
|
18
|
+
// readable, not the entire prefix. A user-installed Node needs one exact file.
|
|
19
|
+
// macOS executable startup needs the root directory itself, not its children.
|
|
20
|
+
const readable=[...SYSTEM_READ,cwd];
|
|
21
|
+
const metadata=new Set(['/','/dev','/System','/usr','/opt','/opt/homebrew']);
|
|
22
|
+
for(const leaf of [cwd,fs.realpathSync(process.execPath)]){
|
|
23
|
+
for(let parent=path.dirname(leaf);;parent=path.dirname(parent)){
|
|
24
|
+
metadata.add(parent);if(parent===path.dirname(parent))break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// A native helper in the copy could otherwise read any same-user process's launch
|
|
28
|
+
// arguments and environment (KERN_PROCARGS2), including the host's credentials.
|
|
29
|
+
// Both rules are needed; denying all of sysctl* instead makes Node abort at startup.
|
|
30
|
+
return `(version 1)(allow default)
|
|
31
|
+
(deny file-read*)(deny file-write*)(deny network*)(deny signal)(deny mach-lookup)
|
|
32
|
+
(deny process-info*)(deny sysctl-read (sysctl-name-prefix "kern.proc"))
|
|
33
|
+
(allow signal (target children))
|
|
34
|
+
(allow file-read* ${readable.map(p=>`(subpath ${JSON.stringify(p)})`).join(' ')}
|
|
35
|
+
(literal ${JSON.stringify(fs.realpathSync(process.execPath))})
|
|
36
|
+
(literal "/")
|
|
37
|
+
(literal "/dev/null") (literal "/dev/random") (literal "/dev/urandom"))
|
|
38
|
+
(allow file-read-metadata ${[...metadata].map(p=>`(literal ${JSON.stringify(p)})`).join(' ')} (subpath "/opt/homebrew/opt")
|
|
39
|
+
(subpath "/opt/homebrew/bin") (subpath "/opt/homebrew/sbin"))
|
|
40
|
+
(allow file-write* (subpath ${JSON.stringify(cwd)}) (literal "/dev/null"))`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function runVerificationCommand({cwd,command,timeoutMs,signal,onSpawn=null,onClose=null}){
|
|
44
|
+
try{
|
|
45
|
+
if(typeof cwd!=='string'||!path.isAbsolute(cwd)||path.resolve(cwd)!==cwd
|
|
46
|
+
||fs.realpathSync(cwd)!==cwd||!fs.lstatSync(cwd).isDirectory()
|
|
47
|
+
||cwd===path.parse(cwd).root||SYSTEM_ROOTS.some(root=>inside(cwd,root)||inside(root,cwd))
|
|
48
|
+
||inside(cwd,fs.realpathSync(os.homedir()))||inside(cwd,fs.realpathSync(os.tmpdir()))
|
|
49
|
+
||cwd==='/private/tmp')
|
|
50
|
+
return unavailable('verification_path_invalid');
|
|
51
|
+
}catch{return unavailable('verification_path_invalid');}
|
|
52
|
+
if(!Array.isArray(command)||command.length===0||command.length>128
|
|
53
|
+
||command.some(arg=>typeof arg!=='string'||arg.length===0||arg.includes('\0')||Buffer.byteLength(arg)>32768)
|
|
54
|
+
||!Number.isSafeInteger(timeoutMs)||timeoutMs<1||timeoutMs>3600000
|
|
55
|
+
||!signal||typeof signal.addEventListener!=='function'
|
|
56
|
+
||[onSpawn,onClose].some(fn=>fn!==null&&typeof fn!=='function'))return unavailable('verification_command_invalid');
|
|
57
|
+
if(process.platform!=='darwin'||!fs.existsSync('/usr/bin/sandbox-exec'))
|
|
58
|
+
return unavailable('verification_isolation_unsupported');
|
|
59
|
+
if(signal.aborted)return unavailable('verification_cancelled');
|
|
60
|
+
let scratch;
|
|
61
|
+
try{
|
|
62
|
+
scratch=fs.mkdtempSync(path.join(cwd,'.cm-review-command-'));
|
|
63
|
+
fs.chmodSync(scratch,0o700);
|
|
64
|
+
const home=path.join(scratch,'home'),tmp=path.join(scratch,'tmp');
|
|
65
|
+
fs.mkdirSync(home,{mode:0o700});fs.mkdirSync(tmp,{mode:0o700});
|
|
66
|
+
const env={PATH:[path.dirname(fs.realpathSync(process.execPath)),'/usr/bin','/bin','/usr/sbin','/sbin','/opt/homebrew/bin'].join(':'),
|
|
67
|
+
HOME:home,TMPDIR:tmp,LANG:'C.UTF-8',LC_ALL:'C.UTF-8'};
|
|
68
|
+
return await new Promise(resolve=>{
|
|
69
|
+
let child;
|
|
70
|
+
try{child=spawn('/usr/bin/sandbox-exec',['-p',profile(cwd),...command],
|
|
71
|
+
{cwd,env,shell:false,detached:true,stdio:['ignore','pipe','pipe']});}
|
|
72
|
+
catch{resolve(unavailable('verification_spawn_failed'));return;}
|
|
73
|
+
const cleanup=ownedProcessCleanup(child);
|
|
74
|
+
let failure=null,bytes=0,retained=Buffer.alloc(0),settled=false,closeSeen=false,drainTimer,cleanupSucceeded=false;
|
|
75
|
+
const notify=fn=>{
|
|
76
|
+
if(fn===null||!Number.isInteger(child.pid))return;
|
|
77
|
+
const result=fn(child.pid);
|
|
78
|
+
if(types.isPromise(result))Promise.prototype.then.call(result,()=>{},()=>{});
|
|
79
|
+
if(result!==undefined)throw Error('verification_observer_failed');
|
|
80
|
+
};
|
|
81
|
+
const clean=()=>cleanup().then(()=>{cleanupSucceeded=true;}).catch(()=>{failure='verification_cleanup_unknown';});
|
|
82
|
+
// A detached descendant can keep pipe descriptors open after its leader
|
|
83
|
+
// exits. Bound that wait too; never infer successful cleanup from silence.
|
|
84
|
+
const drain=()=>{if(closeSeen||settled)return;drainTimer??=setTimeout(()=>{
|
|
85
|
+
if(closeSeen||settled)return;
|
|
86
|
+
failure='verification_cleanup_unknown';child.stdout.destroy();child.stderr.destroy();
|
|
87
|
+
void finish(null,null);
|
|
88
|
+
},1500);};
|
|
89
|
+
const stop=code=>{failure??=code;void clean().then(drain);};
|
|
90
|
+
const abort=()=>stop('verification_cancelled');
|
|
91
|
+
const timer=setTimeout(()=>stop('verification_timeout'),timeoutMs);
|
|
92
|
+
signal.addEventListener('abort',abort,{once:true});
|
|
93
|
+
if(signal.aborted)abort();
|
|
94
|
+
for(const stream of [child.stdout,child.stderr]){
|
|
95
|
+
stream.on('data',chunk=>{
|
|
96
|
+
bytes+=chunk.length;
|
|
97
|
+
if(retained.length<8192)retained=Buffer.concat([retained,chunk.subarray(0,8192-retained.length)]);
|
|
98
|
+
if(bytes>4*1024*1024)stop('verification_output_limit');
|
|
99
|
+
});
|
|
100
|
+
stream.on('error',()=>stop('verification_output_failed'));
|
|
101
|
+
}
|
|
102
|
+
child.once('error',()=>stop('verification_spawn_failed'));
|
|
103
|
+
child.once('exit',()=>{void clean().then(drain);});
|
|
104
|
+
const finish=async(exitCode,exitSignal)=>{
|
|
105
|
+
if(settled)return;settled=true;
|
|
106
|
+
clearTimeout(timer);clearTimeout(drainTimer);signal.removeEventListener('abort',abort);await clean();
|
|
107
|
+
if(cleanupSucceeded&&failure!=='verification_cleanup_unknown'){
|
|
108
|
+
try{notify(onClose);}catch{failure='verification_observer_failed';}
|
|
109
|
+
}
|
|
110
|
+
const output=retained.toString('utf8').slice(0,8192);
|
|
111
|
+
if(failure){resolve(unavailable(failure,output));return;}
|
|
112
|
+
if(exitSignal||!Number.isInteger(exitCode)){resolve(unavailable('verification_signal_exit',output));return;}
|
|
113
|
+
if(exitCode!==0&&/^sandbox-exec:/m.test(output)){resolve(unavailable('verification_isolation_failed',output));return;}
|
|
114
|
+
resolve({exitCode,outcome:exitCode===0?'passed':'failed',code:null,output});
|
|
115
|
+
};
|
|
116
|
+
child.once('close',(exitCode,exitSignal)=>{closeSeen=true;void finish(exitCode,exitSignal);});
|
|
117
|
+
try{notify(onSpawn);}catch{stop('verification_observer_failed');}
|
|
118
|
+
});
|
|
119
|
+
}catch{return unavailable('verification_isolation_failed');}
|
|
120
|
+
finally{if(scratch)try{fs.rmSync(scratch,{recursive:true,force:true});}catch{/* private disposable copy remains caller-owned */}}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Writes a file of the disposable copy from inside the same sandbox as the commands, so a
|
|
124
|
+
// path that an escaped command replaced with a link cannot redirect the write outside it.
|
|
125
|
+
const WRITER="const fs=require('fs');const data=fs.readFileSync(0);"
|
|
126
|
+
+"const fd=fs.openSync(process.argv[1],fs.constants.O_WRONLY|fs.constants.O_TRUNC|fs.constants.O_NOFOLLOW);"
|
|
127
|
+
+"try{let at=0;while(at<data.length){const n=fs.writeSync(fd,data,at,data.length-at,at);if(!(n>0))throw Error('short write');at+=n;}if(process.argv[2]!=='keep')fs.fchmodSync(fd,Number(process.argv[2]));fs.fsyncSync(fd);}finally{fs.closeSync(fd);}";
|
|
128
|
+
export function writeInsideCopy({cwd,file,data,mode=null}){
|
|
129
|
+
need(typeof file==='string'&&file&&!path.isAbsolute(file)&&!/[\\\0]/.test(file)&&file.split('/').every(part=>part&&part!=='.'&&part!=='..')
|
|
130
|
+
&&Buffer.isBuffer(data)&&(mode===null||Number.isInteger(mode)&&mode>=0&&mode<=0o7777),'verification_write_invalid');
|
|
131
|
+
need(process.platform==='darwin'&&fs.existsSync('/usr/bin/sandbox-exec'),'verification_isolation_unsupported');
|
|
132
|
+
const written=spawnSync('/usr/bin/sandbox-exec',['-p',profile(cwd),process.execPath,'-e',WRITER,path.join(cwd,file),mode===null?'keep':String(mode)],
|
|
133
|
+
{cwd,input:data,env:{PATH:'/usr/bin:/bin',LANG:'C.UTF-8',LC_ALL:'C.UTF-8'},timeout:30000,maxBuffer:1024*1024});
|
|
134
|
+
need(!written.error&&written.status===0,'review_verification_copy_drift');
|
|
135
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Optional, mechanically collected verification. No identity or approval proof.
|
|
2
|
+
import {digest,json,need,shape,hex,id} from '../cm-ai/effect-contract.mjs';
|
|
3
|
+
export const VERIFICATION_TOOLS=Object.freeze(['mcp__cm_review__read_file','mcp__cm_review__run_check','mcp__cm_review__mutate_check']);
|
|
4
|
+
export function verificationPath(value){
|
|
5
|
+
need(typeof value==='string'&&value.length<=240&&!value.includes('\\')&&!value.includes('\0')
|
|
6
|
+
&&!value.startsWith('/')&&value.split('/').every(p=>p&&p!=='.'&&p!=='..')
|
|
7
|
+
&&!value.split('/').some(p=>/^(?:\.env(?:\..*)?|\.git|\.reviews|\.codex|\.claude|\.ssh|\.aws|\.npmrc|\.netrc|\.pypirc|credentials\.json|id_rsa|node_modules)$/i.test(p)),'review_verification_path');
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export function readReviewVerification(raw){
|
|
11
|
+
const c=json(raw,32768);shape(c,['files','checks','mutationPaths','timeoutMs']);
|
|
12
|
+
for(const key of ['files','mutationPaths']){
|
|
13
|
+
need(Array.isArray(c[key])&&c[key].length>0&&c[key].length<=256&&new Set(c[key]).size===c[key].length,'review_verification_config');
|
|
14
|
+
c[key].forEach(verificationPath);
|
|
15
|
+
}
|
|
16
|
+
need(c.mutationPaths.every(p=>c.files.includes(p)&&!/(^|\/)(?:tests?|fixtures|AGENTS\.md|CLAUDE\.md)(\/|$)|\.(?:test|spec)\./i.test(p)),'review_verification_config');
|
|
17
|
+
need(Array.isArray(c.checks)&&c.checks.length>0&&c.checks.length<=8&&new Set(c.checks.map(c=>c.id)).size===c.checks.length,'review_verification_config');
|
|
18
|
+
for(const check of c.checks){shape(check,['id','command']);id(check.id);
|
|
19
|
+
need(Array.isArray(check.command)&&check.command.length>0&&check.command.length<=32
|
|
20
|
+
&&check.command.every(v=>typeof v==='string'&&v.length>0&&v.length<=2048&&!/[\0\r\n]/.test(v)),'review_verification_config');}
|
|
21
|
+
need(Number.isInteger(c.timeoutMs)&&c.timeoutMs>=1&&c.timeoutMs<=300000,'review_verification_config');
|
|
22
|
+
return c;
|
|
23
|
+
}
|
|
24
|
+
export function bindVerificationFiles(files,pkg){
|
|
25
|
+
const required=[...(pkg.files??[]),...(pkg.contextFiles??[]),...(pkg.changes??[]).filter(c=>c.after).map(c=>({...c.after,path:c.path})),
|
|
26
|
+
...(pkg.unchangedScope??[]),...(pkg.requirements??[]),...(pkg.instructions??[])];
|
|
27
|
+
for(const r of required)need(files.some(f=>f.path===r.path&&f.sha256===r.sha256&&(r.mode===undefined||f.mode===r.mode)), 'review_verification_package_binding');
|
|
28
|
+
for(const r of (pkg.changes??[]).filter(c=>!c.after))need(!files.some(f=>f.path===r.path&&f.sha256!==null),'review_verification_package_binding');
|
|
29
|
+
}
|
|
30
|
+
export function inspectReviewVerificationEvidence(raw,{request,configuration,providerThreadId}){
|
|
31
|
+
const c=readReviewVerification(configuration),e=json(raw,128*1024);
|
|
32
|
+
shape(e,['version','requestDigest','packageDigest','profileDigest','providerThreadId','files','snapshotDigest','checks','mutations']);
|
|
33
|
+
need(e.version===1&&e.requestDigest===request.requestDigest&&e.packageDigest===request.payload.reviewPackage.packageDigest
|
|
34
|
+
&&e.profileDigest===digest(c)&&e.providerThreadId===providerThreadId&&request.provider==='claude','review_verification_binding');
|
|
35
|
+
id(e.providerThreadId);
|
|
36
|
+
need(Array.isArray(e.files)&&e.files.length===c.files.length,'review_verification_binding');
|
|
37
|
+
for(const f of e.files){shape(f,['path','sha256','mode']);verificationPath(f.path);if(f.sha256===null)need(f.mode===null,'review_verification_binding');else{hex(f.sha256);need(Number.isInteger(f.mode)&&f.mode>=0&&f.mode<=511,'review_verification_binding');}}
|
|
38
|
+
need(digest(e.files.map(f=>f.path).sort())===digest([...c.files].sort())&&e.snapshotDigest===digest(e.files),'review_verification_binding');
|
|
39
|
+
bindVerificationFiles(e.files,request.payload.reviewPackage);
|
|
40
|
+
const timing=r=>need(Number.isSafeInteger(r.startedAt)&&Number.isSafeInteger(r.endedAt)&&r.startedAt<=r.endedAt,'review_verification_evidence');
|
|
41
|
+
need(Array.isArray(e.checks)&&e.checks.length===c.checks.length,'review_verification_evidence');
|
|
42
|
+
for(const [i,r] of e.checks.entries()){
|
|
43
|
+
shape(r,['id','commandDigest','exitCode','outputSha256','startedAt','endedAt']);timing(r);hex(r.outputSha256);
|
|
44
|
+
need(r.id===c.checks[i].id&&r.commandDigest===digest(c.checks[i].command)&&r.exitCode===0,'review_verification_evidence');
|
|
45
|
+
}
|
|
46
|
+
need(Array.isArray(e.mutations)&&e.mutations.length>=1&&e.mutations.length<=8,'review_verification_evidence');
|
|
47
|
+
for(const m of e.mutations){
|
|
48
|
+
shape(m,['path','beforeSha256','afterSha256','checkId','baselineExitCode','mutatedExitCode','restoredExitCode','restoredSha256','startedAt','endedAt']);timing(m);hex(m.afterSha256);
|
|
49
|
+
need(c.mutationPaths.includes(m.path)&&c.checks.some(r=>r.id===m.checkId)&&m.beforeSha256===e.files.find(f=>f.path===m.path)?.sha256
|
|
50
|
+
&&m.afterSha256!==m.beforeSha256&&m.restoredSha256===m.beforeSha256&&m.baselineExitCode===0
|
|
51
|
+
&&Number.isInteger(m.mutatedExitCode)&&m.mutatedExitCode>0&&m.mutatedExitCode<=255&&m.restoredExitCode===0,'review_verification_evidence');
|
|
52
|
+
}
|
|
53
|
+
return e;
|
|
54
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Bounded failure metadata, never a verdict, raw output or identity proof.
|
|
2
|
+
import {createHash} from 'node:crypto';
|
|
3
|
+
import {digest,json,need,shape,hex,id} from '../cm-ai/effect-contract.mjs';
|
|
4
|
+
const phases=new Set(['snapshot','worker','check','baseline','mutation','restore','finish','callback','cleanup']);
|
|
5
|
+
const codes=new Set(['review_verification_failed','review_verification_check_failed','review_verification_check_missing',
|
|
6
|
+
'review_verification_mutation_missing','review_verification_mutation_survived','review_verification_restore_failed',
|
|
7
|
+
'review_verification_baseline_failed','review_verification_binding','review_verification_invalid',
|
|
8
|
+
'review_verification_package_binding','review_verification_source_drift','review_verification_copy_drift',
|
|
9
|
+
'review_verification_cleanup','review_verification_evidence','review_verification_path','review_verification_limit',
|
|
10
|
+
'review_verification_mutation','review_verification_check','review_verification_prompt_contract',
|
|
11
|
+
'review_verification_callback_failed','fix_verification_recovery_binding','reviewer_auth_failed','review_verification_isolation_unavailable','review_verification_tool','cancelled','review_verification_cleanup_unknown','process_cleanup_unknown',
|
|
12
|
+
'verification_cleanup_unknown','verification_timeout','verification_cancelled','verification_signal_exit',
|
|
13
|
+
'verification_spawn_failed','verification_isolation_failed','verification_isolation_unsupported','verification_write_invalid',
|
|
14
|
+
'verification_path_invalid','verification_command_invalid','verification_output_limit','verification_output_failed',
|
|
15
|
+
'verification_observer_failed']);
|
|
16
|
+
export const verificationFailureCode=error=>{
|
|
17
|
+
try{
|
|
18
|
+
const property=error!==null&&['object','function'].includes(typeof error)?Object.getOwnPropertyDescriptor(error,'code'):null;
|
|
19
|
+
return property&&Object.hasOwn(property,'value')&&codes.has(property.value)?property.value:'review_verification_failed';
|
|
20
|
+
}catch{return 'review_verification_failed';}
|
|
21
|
+
};
|
|
22
|
+
export function verificationFailure({phase='finish',code='review_verification_failed',checkId=null,result=null}){
|
|
23
|
+
const output=typeof result?.output==='string'?result.output:null;
|
|
24
|
+
return {phase:phases.has(phase)?phase:'finish',code:codes.has(code)?code:'review_verification_failed',checkId,
|
|
25
|
+
exitCode:Number.isInteger(result?.exitCode)?result.exitCode:null,
|
|
26
|
+
outcome:['passed','failed','unavailable'].includes(result?.outcome)?result.outcome:null,
|
|
27
|
+
outputSha256:output===null?null:digestOutput(output),
|
|
28
|
+
runtimeFailure:output!==null&&/SyntaxError: The requested module '[^'\r\n]{1,240}' does not provide an export named '[A-Za-z_$][\w$]{0,100}'/.test(output)?'module_export_missing':null};
|
|
29
|
+
}
|
|
30
|
+
// Matches the byte-level output digest used by successful verification records.
|
|
31
|
+
const digestOutput=output=>createHash('sha256').update(output).digest('hex');
|
|
32
|
+
export function bindVerificationDiagnostic(failure,{request,configuration,providerThreadId=null}){
|
|
33
|
+
return {version:1,requestDigest:request.requestDigest,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
34
|
+
profileDigest:digest(configuration),providerThreadId,...failure};
|
|
35
|
+
}
|
|
36
|
+
export function inspectVerificationDiagnostic(raw,{request,configuration,providerThreadId}){
|
|
37
|
+
const d=json(raw,4096);
|
|
38
|
+
shape(d,['version','requestDigest','packageDigest','profileDigest','providerThreadId','phase','code','checkId','exitCode','outcome','outputSha256','runtimeFailure']);
|
|
39
|
+
need(request.provider==='claude'&&d.version===1&&d.requestDigest===request.requestDigest&&d.packageDigest===request.payload.reviewPackage.packageDigest
|
|
40
|
+
&&d.profileDigest===digest(configuration)&&d.providerThreadId===providerThreadId,'review_verification_binding');
|
|
41
|
+
if(d.providerThreadId!==null)id(d.providerThreadId);
|
|
42
|
+
need(phases.has(d.phase)&&codes.has(d.code)&&
|
|
43
|
+
(d.checkId===null||configuration.checks.some(c=>c.id===d.checkId))&&
|
|
44
|
+
(d.exitCode===null||Number.isInteger(d.exitCode)&&d.exitCode>=0&&d.exitCode<=255)&&
|
|
45
|
+
(d.outcome===null||['passed','failed','unavailable'].includes(d.outcome))&&
|
|
46
|
+
(d.runtimeFailure===null||d.runtimeFailure==='module_export_missing'),'review_verification_invalid');
|
|
47
|
+
if(d.outputSha256!==null)hex(d.outputSha256);
|
|
48
|
+
return d;
|
|
49
|
+
}
|
|
50
|
+
export function splitVerificationResult(result){
|
|
51
|
+
if(!result||!Object.hasOwn(result,'verificationDiagnostic'))return {result};
|
|
52
|
+
const {verificationDiagnostic,...observationResult}=json(result,1024*1024);
|
|
53
|
+
need(observationResult.status==='failed','review_verification_invalid');
|
|
54
|
+
return {result:observationResult,verificationDiagnostic};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Owner callback rejection overrides a worker that swallows the exception or
|
|
58
|
+
// returns an approval anyway. Persist only host-bound failure metadata.
|
|
59
|
+
export function verificationCallbackFailure(error,context){
|
|
60
|
+
const code=verificationFailureCode(error);
|
|
61
|
+
return {status:'failed',code,verificationDiagnostic:bindVerificationDiagnostic(verificationFailure({phase:'callback',code}),context)};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Failure metadata is optional. Reject it independently without dropping the
|
|
65
|
+
// already-failed observation; none of this path can create a completed review.
|
|
66
|
+
export function inspectResultWithFailureDiagnostic(value,inspect,context){
|
|
67
|
+
try{return {value,inspection:inspect(value)};}catch(error){
|
|
68
|
+
if(!context.configuration||value?.observation?.result?.status!=='failed'||!Object.hasOwn(value,'verificationDiagnostic'))throw error;
|
|
69
|
+
const {verificationDiagnostic,...without}=value;
|
|
70
|
+
inspect(without);
|
|
71
|
+
const code=verificationFailureCode(error);
|
|
72
|
+
const safe={...without,verificationDiagnostic:bindVerificationDiagnostic(verificationFailure({phase:'finish',code}),context)};
|
|
73
|
+
return {value:safe,inspection:inspect(safe)};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// One append-only continuation for a failed isolated verification; not a review verdict.
|
|
2
|
+
import {digest,json,need,shape,hex} from '../cm-ai/effect-contract.mjs';
|
|
3
|
+
import {readReviewVerification,bindVerificationFiles} from './review-verification-contract.mjs';
|
|
4
|
+
export const VERIFICATION_RECOVERY='fix-verification-recovery';
|
|
5
|
+
export const recoveryPreparation=records=>records.find(r=>r.id===`${VERIFICATION_RECOVERY}-prepared`)??null;
|
|
6
|
+
export function recoveryFor(records,phase){
|
|
7
|
+
const row=recoveryPreparation(records);if(row?.payload.target.phase!==phase)return null;
|
|
8
|
+
if(phase==='cause_review'&&records.some(r=>r.id==='fix-rediagnosis-intent'&&r.seq>row.seq))return null;
|
|
9
|
+
return row;
|
|
10
|
+
}
|
|
11
|
+
export function verificationRecoveryTarget({records,configuration,stage,phase,registration,started,result,baseline}){
|
|
12
|
+
need(stage==='unknown'&&configuration.reviewVerification&&configuration.causeReview?.provider==='claude','fix_verification_recovery_unavailable');
|
|
13
|
+
need(!configuration.externalModels&&!configuration.executionPolicy,'external_review_reconciliation_required');
|
|
14
|
+
need(registration&&started&&result,'fix_verification_recovery_unavailable');
|
|
15
|
+
// Observation correction binds a distinct historical package. Never prepare a
|
|
16
|
+
// continuation that cannot preserve that original correction contract.
|
|
17
|
+
need(!Object.hasOwn(registration.payload.request.payload.reviewPackage,'correction'),'fix_verification_recovery_unavailable');
|
|
18
|
+
const observation=result.payload.observation;
|
|
19
|
+
// Do not infer eligibility from a generic unknown/transport error or a valid rejection.
|
|
20
|
+
need(observation?.result?.status==='failed'&&observation.result.code==='review_verification_evidence', 'fix_verification_recovery_unavailable');
|
|
21
|
+
need(observation.events.some(e=>e.event==='process_closed'&&e.exit_code===0&&e.timed_out===false&&e.signal===null),'fix_verification_recovery_process_unconfirmed');
|
|
22
|
+
need(['cause_review','final_review','revision_final_review'].includes(phase),'fix_verification_recovery_unavailable');
|
|
23
|
+
const threads=[...new Set(records.filter(r=>r.id.endsWith('-started')&&r.payload.providerThreadId).map(r=>r.payload.providerThreadId))];
|
|
24
|
+
const target={phase,invocationId:registration.payload.request.invocationId,packageDigest:registration.payload.request.payload.reviewPackage.packageDigest,
|
|
25
|
+
configurationDigest:digest(configuration),historyDigest:digest(records),registrationDigest:digest(registration),startedDigest:digest(started),resultDigest:digest(result),
|
|
26
|
+
providerThreadIds:threads,files:baseline.files,snapshotDigest:baseline.snapshotDigest};
|
|
27
|
+
inspectRecoveryBaseline(baseline,configuration.reviewVerification,registration.payload.request.payload.reviewPackage);
|
|
28
|
+
return json(target,128*1024);
|
|
29
|
+
}
|
|
30
|
+
export function inspectRecoveryBaseline(baseline,configuration,pkg){
|
|
31
|
+
const c=readReviewVerification(configuration),{files,snapshotDigest,checks}=baseline;
|
|
32
|
+
need(Array.isArray(files)&&files.length===c.files.length&&digest(files.map(f=>f.path).sort())===digest([...c.files].sort())&&snapshotDigest===digest(files),'fix_verification_recovery_binding');
|
|
33
|
+
for(const f of files){shape(f,['path','sha256','mode']);if(f.sha256===null)need(f.mode===null,'fix_verification_recovery_binding');else{hex(f.sha256);need(Number.isInteger(f.mode)&&f.mode>=0&&f.mode<=511,'fix_verification_recovery_binding');}}
|
|
34
|
+
bindVerificationFiles(files,pkg);
|
|
35
|
+
need(Array.isArray(checks)&&checks.length===c.checks.length,'fix_verification_recovery_baseline');
|
|
36
|
+
for(const [i,r] of checks.entries())need(r.id===c.checks[i].id&&r.commandDigest===digest(c.checks[i].command)&&r.exitCode===0,'fix_verification_recovery_baseline');
|
|
37
|
+
}
|
|
38
|
+
export function inspectRecoveryPreparation(value,context){
|
|
39
|
+
shape(value,['target','checks','reason','previousInvocationStopped']);
|
|
40
|
+
need(value.previousInvocationStopped===true&&typeof value.reason==='string'&&value.reason.trim()&&Buffer.byteLength(value.reason)<=1000&&!/[\r\n\0\u0085\u2028\u2029]/.test(value.reason),'fix_verification_recovery_confirmation');
|
|
41
|
+
const baseline={files:value.target.files,snapshotDigest:value.target.snapshotDigest,checks:value.checks};
|
|
42
|
+
const expected=verificationRecoveryTarget({...context,baseline});
|
|
43
|
+
need(digest(expected)===digest(value.target),'fix_verification_recovery_binding');return value;
|
|
44
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Narrow stdio MCP transport; only this server's three fixed operations exist.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import {createInterface} from 'node:readline';
|
|
4
|
+
import {createVerificationTools} from './review-verification.mjs';
|
|
5
|
+
// A dispatch owns one server for its lifetime. A restart must fail closed instead
|
|
6
|
+
// of clearing accumulated evidence or running a second mutation concurrently.
|
|
7
|
+
try{const fd=fs.openSync(process.argv[2]+'.server-started','wx',384);fs.closeSync(fd);}
|
|
8
|
+
catch{process.stderr.write('review_verification_server_already_started\n');process.exit(1);}
|
|
9
|
+
const config=JSON.parse(fs.readFileSync(process.argv[2],'utf8')),tools=createVerificationTools(config);
|
|
10
|
+
const schema=(properties,required=Object.keys(properties))=>({type:'object',properties,required,additionalProperties:false});
|
|
11
|
+
const str={type:'string'},checkId={type:'string',enum:config.configuration.checks.map(c=>c.id)};
|
|
12
|
+
const registeredIds=JSON.stringify(checkId.enum);
|
|
13
|
+
const catalog=[
|
|
14
|
+
{name:'read_file',description:'Read at most 16 KiB of one registered UTF-8 file from the isolated snapshot. Optional offset is a UTF-8 byte cursor (default 0); follow nextOffset until null. sha256 covers the whole file. Cursors must be character boundaries.',inputSchema:schema({path:str,offset:{type:'integer',minimum:0,maximum:2*1024*1024}},['path'])},
|
|
15
|
+
{name:'run_check',description:`Run only a registered check in the OS sandbox. Valid IDs: ${registeredIds}. Package check labels are not tool IDs.`,inputSchema:schema({id:checkId})},
|
|
16
|
+
{name:'mutate_check',description:'Run baseline, exact unique source mutation, check, exact restoration, restored check. Never edits original source.',inputSchema:schema({path:{type:'string',enum:config.configuration.mutationPaths},find:str,replace:str,checkId})},
|
|
17
|
+
];
|
|
18
|
+
let queue=Promise.resolve(),count=0;const controller=new AbortController();
|
|
19
|
+
for(const sig of ['SIGTERM','SIGINT'])process.on(sig,()=>{controller.abort();});
|
|
20
|
+
const send=value=>process.stdout.write(JSON.stringify(value)+'\n');
|
|
21
|
+
const input=createInterface({input:process.stdin,crlfDelay:Infinity});
|
|
22
|
+
input.on('line',line=>{
|
|
23
|
+
if(Buffer.byteLength(line)>65536||++count>64){controller.abort();input.close();return;}
|
|
24
|
+
queue=queue.then(async()=>{
|
|
25
|
+
let r;try{r=JSON.parse(line);if(r.id===undefined)return;
|
|
26
|
+
let result;
|
|
27
|
+
if(r.method==='initialize')result={protocolVersion:'2024-11-05',capabilities:{tools:{}},serverInfo:{name:'cm-review-verification',version:'1.0.0'}};
|
|
28
|
+
else if(r.method==='ping')result={};
|
|
29
|
+
else if(r.method==='tools/list')result={tools:catalog};
|
|
30
|
+
else if(r.method==='tools/call'){
|
|
31
|
+
try{const value=await tools.call(r.params.name,r.params.arguments,controller.signal);result={content:[{type:'text',text:JSON.stringify(value)}]};}
|
|
32
|
+
catch(e){result={isError:true,content:[{type:'text',text:/^[a-z_]+$/.test(e.code??'')?e.code:'review_verification_failed'}]};}
|
|
33
|
+
}else {send({jsonrpc:'2.0',id:r.id,error:{code:-32601,message:'Method not found'}});return;}
|
|
34
|
+
send({jsonrpc:'2.0',id:r.id,result});
|
|
35
|
+
}catch{if(r?.id!==undefined)send({jsonrpc:'2.0',id:r.id,error:{code:-32600,message:'Invalid request'}});}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
input.on('close',()=>controller.abort());
|