@aibyzero/cm-workflow 0.17.1 → 0.19.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 +242 -0
- package/README.md +20 -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/autonomy.mjs +152 -0
- 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 +56 -17
- 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 +115 -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 +581 -65
- 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 +5 -4
- 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 +21 -7
- package/scripts/cm-ai-admission.test.mjs +171 -3
- 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-autonomy.mjs +94 -0
- package/scripts/cm-autonomy.test.mjs +162 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +60 -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 +581 -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 +323 -0
- package/scripts/cm-start-check.test.mjs +406 -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 +4 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N3-execute-task.md +1 -1
- 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 +82 -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 +14 -9
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +8 -1
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-change-recovery.md +14 -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
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Shared install-manifest and install-lock helpers for install.sh and
|
|
3
|
+
# install-codex.sh.
|
|
4
|
+
# Sourced by the installers (bash 3.2 compatible); it prints nothing itself so
|
|
5
|
+
# each installer keeps its own language. A manifest records the sha256 of every
|
|
6
|
+
# file the previous install wrote; a mismatch on reinstall means a local edit
|
|
7
|
+
# (real incident: a hand-edited ~/.claude/scripts/cm-ai-host.mjs was silently
|
|
8
|
+
# overwritten by another session's `./install.sh --yes`).
|
|
9
|
+
#
|
|
10
|
+
# Manifest format (v1):
|
|
11
|
+
# line 1: "# cm-workflow install manifest v1"
|
|
12
|
+
# then: "<64 lowercase hex> <relative path>"
|
|
13
|
+
|
|
14
|
+
CM_MANIFEST_HEADER="# cm-workflow install manifest v1"
|
|
15
|
+
CM_SHA256_TOOL=""
|
|
16
|
+
|
|
17
|
+
# Pick a sha256 tool. Returns 1 when neither exists; callers must stop rather
|
|
18
|
+
# than skip the local-edit check.
|
|
19
|
+
cm_manifest_select_hasher() {
|
|
20
|
+
if command -v shasum >/dev/null 2>&1; then
|
|
21
|
+
CM_SHA256_TOOL=shasum
|
|
22
|
+
elif command -v sha256sum >/dev/null 2>&1; then
|
|
23
|
+
CM_SHA256_TOOL=sha256sum
|
|
24
|
+
else
|
|
25
|
+
CM_SHA256_TOOL=""
|
|
26
|
+
return 1
|
|
27
|
+
fi
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
cm_manifest_abs() {
|
|
31
|
+
case "$1" in
|
|
32
|
+
/*) printf '%s\n' "$1" ;;
|
|
33
|
+
*) printf '%s\n' "$PWD/$1" ;;
|
|
34
|
+
esac
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# cm_manifest_hash_list ROOT LIST OUT
|
|
38
|
+
# Hash each relative path listed in LIST (one per line) under ROOT and write
|
|
39
|
+
# "<hash> <path>" lines to OUT. Returns 1 on any hashing failure, and when
|
|
40
|
+
# LIST is missing or unreadable (only a readable empty LIST is an empty list).
|
|
41
|
+
cm_manifest_hash_list() {
|
|
42
|
+
hl_root=$1
|
|
43
|
+
hl_list=$(cm_manifest_abs "$2")
|
|
44
|
+
hl_out=$(cm_manifest_abs "$3")
|
|
45
|
+
[ -n "$CM_SHA256_TOOL" ] || return 1
|
|
46
|
+
if [ ! -f "$hl_list" ] || [ ! -r "$hl_list" ]; then
|
|
47
|
+
return 1
|
|
48
|
+
fi
|
|
49
|
+
: > "$hl_out" || return 1
|
|
50
|
+
[ -s "$hl_list" ] || return 0
|
|
51
|
+
if [ "$CM_SHA256_TOOL" = shasum ]; then
|
|
52
|
+
(cd "$hl_root" && tr '\n' '\0' < "$hl_list" | xargs -0 shasum -a 256) > "$hl_out" || return 1
|
|
53
|
+
else
|
|
54
|
+
(cd "$hl_root" && tr '\n' '\0' < "$hl_list" | xargs -0 sha256sum) > "$hl_out" || return 1
|
|
55
|
+
fi
|
|
56
|
+
# GNU sha256sum escapes names containing a backslash or newline with a leading
|
|
57
|
+
# backslash; such names cannot round-trip through this format.
|
|
58
|
+
hl_grep=0
|
|
59
|
+
grep -q '^\\' "$hl_out" || hl_grep=$?
|
|
60
|
+
[ "$hl_grep" -eq 1 ] || return 1
|
|
61
|
+
# Every listed file must have exactly one hash line; a failed count is a
|
|
62
|
+
# failure, never an "equal" pair of empty strings.
|
|
63
|
+
hl_out_lines=$(wc -l < "$hl_out") || return 1
|
|
64
|
+
hl_list_lines=$(wc -l < "$hl_list") || return 1
|
|
65
|
+
[ -n "$hl_out_lines" ] && [ "$((hl_out_lines))" -eq "$((hl_list_lines))" ] || return 1
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# cm_manifest_write ROOT LIST OUT
|
|
69
|
+
# Write a complete v1 manifest for the files listed in LIST under ROOT.
|
|
70
|
+
# Python bytecode caches and Finder metadata are regenerated outside the
|
|
71
|
+
# installer, so they are copied but never recorded (otherwise they would later
|
|
72
|
+
# look like hand edits).
|
|
73
|
+
cm_manifest_write() {
|
|
74
|
+
mw_out=$(cm_manifest_abs "$3")
|
|
75
|
+
# The line format cannot round-trip a backslash in a name (GNU checksum
|
|
76
|
+
# tools escape it); refuse such names instead of writing a bad manifest.
|
|
77
|
+
mw_grep=0
|
|
78
|
+
grep -q '\\' "$2" || mw_grep=$?
|
|
79
|
+
# 0: a backslash was found; 2: LIST could not be read. Only 1 may continue.
|
|
80
|
+
[ "$mw_grep" -eq 1 ] || return 1
|
|
81
|
+
grep -Ev '(^|/)__pycache__/|(^|/)\.DS_Store$' "$2" > "${mw_out}.list" || [ $? -eq 1 ] || return 1
|
|
82
|
+
cm_manifest_hash_list "$1" "${mw_out}.list" "${mw_out}.body" ||
|
|
83
|
+
{ rm -f "${mw_out}.list" "${mw_out}.body"; return 1; }
|
|
84
|
+
rm -f "${mw_out}.list"
|
|
85
|
+
{
|
|
86
|
+
printf '%s\n' "$CM_MANIFEST_HEADER"
|
|
87
|
+
LC_ALL=C sort -k2 "${mw_out}.body"
|
|
88
|
+
} > "$mw_out" || { rm -f "${mw_out}.body"; return 1; }
|
|
89
|
+
rm -f "${mw_out}.body"
|
|
90
|
+
# Never publish a manifest the next install would reject as malformed.
|
|
91
|
+
cm_manifest_validate "$mw_out" || return 1
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# cm_manifest_validate MANIFEST
|
|
95
|
+
# Check the whole manifest in one awk pass that always reads to the end (an
|
|
96
|
+
# early-exit `grep -q` at the end of a pipeline dies with SIGPIPE under
|
|
97
|
+
# pipefail and silently skipped these checks). Returns 0 when valid, 3 when
|
|
98
|
+
# malformed (bad header, bad hash/separator, empty or absolute path, or a `..`
|
|
99
|
+
# segment), 1 when the check itself failed.
|
|
100
|
+
cm_manifest_validate() {
|
|
101
|
+
if awk -v header="$CM_MANIFEST_HEADER" '
|
|
102
|
+
NR == 1 { if ($0 != header) bad = 1; next }
|
|
103
|
+
{
|
|
104
|
+
hash = substr($0, 1, 64)
|
|
105
|
+
relative = substr($0, 67)
|
|
106
|
+
if (length($0) < 67 || length(hash) != 64 || hash ~ /[^0-9a-f]/ || substr($0, 65, 2) != " ") { bad = 1; next }
|
|
107
|
+
if (relative ~ /^\// || ("/" relative "/") ~ /\/\.\.\//) bad = 1
|
|
108
|
+
}
|
|
109
|
+
END { if (NR < 1) bad = 1; exit (bad ? 3 : 0) }' "$1"; then
|
|
110
|
+
return 0
|
|
111
|
+
else
|
|
112
|
+
va_status=$?
|
|
113
|
+
[ "$va_status" -eq 3 ] && return 3
|
|
114
|
+
return 1
|
|
115
|
+
fi
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# cm_manifest_parent_is_safe ROOT RELATIVE
|
|
119
|
+
# Whether RELATIVE's existence can be judged inside ROOT. Returns 0 when every
|
|
120
|
+
# existing parent (ROOT included) is a real, searchable directory, so `-e`,
|
|
121
|
+
# `-f` and `-L` on RELATIVE are trustworthy; 1 when ROOT or a parent is a
|
|
122
|
+
# symlink or not a directory (hashing must never follow a link out of ROOT);
|
|
123
|
+
# 2 when ROOT or a parent cannot be searched, so "absent" cannot be told apart
|
|
124
|
+
# from "not accessible" and the caller must treat it as a check failure.
|
|
125
|
+
cm_manifest_parent_is_safe() {
|
|
126
|
+
ps_current=$1
|
|
127
|
+
if [ -L "$ps_current" ]; then
|
|
128
|
+
return 1
|
|
129
|
+
fi
|
|
130
|
+
if [ ! -e "$ps_current" ]; then
|
|
131
|
+
return 0
|
|
132
|
+
fi
|
|
133
|
+
[ -d "$ps_current" ] || return 1
|
|
134
|
+
[ -x "$ps_current" ] || return 2
|
|
135
|
+
ps_remaining=$(dirname "$2")
|
|
136
|
+
while [ -n "$ps_remaining" ] && [ "$ps_remaining" != "." ]; do
|
|
137
|
+
case "$ps_remaining" in
|
|
138
|
+
*/*) ps_component=${ps_remaining%%/*}; ps_remaining=${ps_remaining#*/} ;;
|
|
139
|
+
*) ps_component=$ps_remaining; ps_remaining="" ;;
|
|
140
|
+
esac
|
|
141
|
+
ps_current="$ps_current/$ps_component"
|
|
142
|
+
if [ -L "$ps_current" ]; then
|
|
143
|
+
return 1
|
|
144
|
+
fi
|
|
145
|
+
# The parent of this component was searchable, so "missing" is real.
|
|
146
|
+
if [ ! -e "$ps_current" ]; then
|
|
147
|
+
return 0
|
|
148
|
+
fi
|
|
149
|
+
[ -d "$ps_current" ] || return 1
|
|
150
|
+
[ -x "$ps_current" ] || return 2
|
|
151
|
+
done
|
|
152
|
+
return 0
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# cm_manifest_find_edits ROOT MANIFEST EDITS_OUT WORK_DIR
|
|
156
|
+
# Write to EDITS_OUT every manifest path that still exists under ROOT but no
|
|
157
|
+
# longer matches its recorded hash. A symlink or non-file at that path, or a
|
|
158
|
+
# symlinked / non-directory parent, also counts. Paths absent from ROOT or from
|
|
159
|
+
# the manifest are not judged; a path whose parent cannot be searched is a
|
|
160
|
+
# check failure (status 1), never "absent".
|
|
161
|
+
# Returns 0 on success, 3 when the manifest is malformed or not a regular file,
|
|
162
|
+
# 1 on any check or hashing failure.
|
|
163
|
+
cm_manifest_find_edits() {
|
|
164
|
+
fe_root=$1
|
|
165
|
+
fe_manifest=$2
|
|
166
|
+
fe_edits=$(cm_manifest_abs "$3")
|
|
167
|
+
fe_work=$(cm_manifest_abs "$4")
|
|
168
|
+
: > "$fe_edits" || return 1
|
|
169
|
+
if [ -L "$fe_manifest" ] || [ ! -f "$fe_manifest" ]; then
|
|
170
|
+
return 3
|
|
171
|
+
fi
|
|
172
|
+
if cm_manifest_validate "$fe_manifest"; then
|
|
173
|
+
:
|
|
174
|
+
else
|
|
175
|
+
return $?
|
|
176
|
+
fi
|
|
177
|
+
awk 'NR > 1 { print substr($0, 67) }' "$fe_manifest" > "$fe_work/recorded-paths" || return 1
|
|
178
|
+
: > "$fe_work/existing-paths" || return 1
|
|
179
|
+
# Read the whole list first so an open or read failure is a check failure;
|
|
180
|
+
# a loop fed by `< file` would just see no lines and report "no edits".
|
|
181
|
+
fe_paths=$(cat "$fe_work/recorded-paths") || return 1
|
|
182
|
+
case $- in *f*) fe_noglob=1 ;; *) fe_noglob=0 ;; esac
|
|
183
|
+
fe_saved_ifs=$IFS
|
|
184
|
+
IFS='
|
|
185
|
+
'
|
|
186
|
+
set -f
|
|
187
|
+
fe_failed=0
|
|
188
|
+
for fe_rel in $fe_paths; do
|
|
189
|
+
[ -n "$fe_rel" ] || continue
|
|
190
|
+
fe_target="$fe_root/$fe_rel"
|
|
191
|
+
fe_parent=0
|
|
192
|
+
cm_manifest_parent_is_safe "$fe_root" "$fe_rel" || fe_parent=$?
|
|
193
|
+
if [ "$fe_parent" -eq 2 ]; then
|
|
194
|
+
# Cannot tell "deleted" from "not accessible": a check failure.
|
|
195
|
+
fe_failed=1
|
|
196
|
+
break
|
|
197
|
+
elif [ "$fe_parent" -ne 0 ]; then
|
|
198
|
+
printf '%s\n' "$fe_rel" >> "$fe_edits" || { fe_failed=1; break; }
|
|
199
|
+
elif [ -L "$fe_target" ]; then
|
|
200
|
+
printf '%s\n' "$fe_rel" >> "$fe_edits" || { fe_failed=1; break; }
|
|
201
|
+
elif [ -f "$fe_target" ]; then
|
|
202
|
+
printf '%s\n' "$fe_rel" >> "$fe_work/existing-paths" || { fe_failed=1; break; }
|
|
203
|
+
elif [ -e "$fe_target" ]; then
|
|
204
|
+
printf '%s\n' "$fe_rel" >> "$fe_edits" || { fe_failed=1; break; }
|
|
205
|
+
fi
|
|
206
|
+
done
|
|
207
|
+
IFS=$fe_saved_ifs
|
|
208
|
+
[ "$fe_noglob" -eq 1 ] || set +f
|
|
209
|
+
[ "$fe_failed" -eq 0 ] || return 1
|
|
210
|
+
cm_manifest_hash_list "$fe_root" "$fe_work/existing-paths" "$fe_work/current-hashes" || return 1
|
|
211
|
+
awk 'NR == FNR { if (FNR > 1) recorded[substr($0, 67)] = substr($0, 1, 64); next }
|
|
212
|
+
{ path = substr($0, 67); if (recorded[path] != substr($0, 1, 64)) print path }' \
|
|
213
|
+
"$fe_manifest" "$fe_work/current-hashes" >> "$fe_edits" || return 1
|
|
214
|
+
LC_ALL=C sort -o "$fe_edits" "$fe_edits" || return 1
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
# cm_manifest_recorded_hash MANIFEST RELATIVE
|
|
218
|
+
# Print the recorded hash for RELATIVE (empty when not recorded). The manifest
|
|
219
|
+
# must already have passed cm_manifest_validate.
|
|
220
|
+
cm_manifest_recorded_hash() {
|
|
221
|
+
awk -v wanted="$2" 'NR > 1 && substr($0, 67) == wanted { print substr($0, 1, 64); exit }' "$1"
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
# cm_manifest_file_hash FILE
|
|
225
|
+
# Print the sha256 of one file; returns 1 on failure.
|
|
226
|
+
cm_manifest_file_hash() {
|
|
227
|
+
if [ "$CM_SHA256_TOOL" = shasum ]; then
|
|
228
|
+
fh_line=$(shasum -a 256 < "$1") || return 1
|
|
229
|
+
else
|
|
230
|
+
fh_line=$(sha256sum < "$1") || return 1
|
|
231
|
+
fi
|
|
232
|
+
printf '%s\n' "${fh_line%% *}"
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
# ---- Install lock -----------------------------------------------------------
|
|
236
|
+
# One install transaction per target at a time (bash 3.2: `mkdir` is atomic).
|
|
237
|
+
# A stale lock is never taken over automatically; the installer reports the
|
|
238
|
+
# holder and the manual removal command, and a person decides.
|
|
239
|
+
|
|
240
|
+
# cm_install_lock_acquire LOCK_DIR -> 0 acquired, 1 not acquired. Call it
|
|
241
|
+
# between cm_defer_signals and cm_resume_signals and register ownership right
|
|
242
|
+
# after. mkdir runs via cm_run_shielded, so a signal sent to the whole process
|
|
243
|
+
# group cannot kill it after the directory exists: the exit status always
|
|
244
|
+
# tells whether this run created the lock.
|
|
245
|
+
cm_install_lock_acquire() {
|
|
246
|
+
cm_run_shielded mkdir "$1" 2>/dev/null
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
# cm_install_lock_write_owner LOCK_DIR TARGET
|
|
250
|
+
cm_install_lock_write_owner() {
|
|
251
|
+
printf 'pid=%s\nstarted=%s\ntarget=%s\n' "$$" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$2" > "$1/owner" || true
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
# cm_install_lock_field LOCK_DIR FIELD -> value from the owner file, or empty
|
|
255
|
+
cm_install_lock_field() {
|
|
256
|
+
[ -f "$1/owner" ] || return 0
|
|
257
|
+
awk -v key="$2" 'index($0, key "=") == 1 { print substr($0, length(key) + 2); exit }' "$1/owner"
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
# cm_install_lock_pid_state PID -> alive | not-running | unknown
|
|
261
|
+
cm_install_lock_pid_state() {
|
|
262
|
+
case "$1" in
|
|
263
|
+
''|*[!0-9]*) echo unknown; return 0 ;;
|
|
264
|
+
esac
|
|
265
|
+
if kill -0 "$1" 2>/dev/null; then
|
|
266
|
+
echo alive
|
|
267
|
+
elif ps -p "$1" >/dev/null 2>&1; then
|
|
268
|
+
echo alive
|
|
269
|
+
else
|
|
270
|
+
echo not-running
|
|
271
|
+
fi
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
# cm_install_lock_path CANONICAL_TARGET -> the one lock path for that target.
|
|
275
|
+
# Both installers use this rule, so any spelling of the same real directory
|
|
276
|
+
# (and the Claude and Codex installers aimed at the same directory) share it.
|
|
277
|
+
cm_install_lock_path() {
|
|
278
|
+
printf '%s/.%s.cm-install.lock\n' "$(dirname "$1")" "$(basename "$1")"
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
# cm_install_canonical_target PATH
|
|
282
|
+
# Print the physical path of an install root: trailing "/" and "/." are
|
|
283
|
+
# dropped and the parent is resolved with `pwd -P` (creating it if needed).
|
|
284
|
+
# Returns 2 when the root itself is a symlink or not a directory, 1 when the
|
|
285
|
+
# path is empty, ends in ".." or its parent cannot be resolved.
|
|
286
|
+
cm_install_canonical_target() {
|
|
287
|
+
ct_path=$1
|
|
288
|
+
while :; do
|
|
289
|
+
case "$ct_path" in
|
|
290
|
+
?*/) ct_path=${ct_path%/} ;;
|
|
291
|
+
?*/.) ct_path=${ct_path%/.} ;;
|
|
292
|
+
*) break ;;
|
|
293
|
+
esac
|
|
294
|
+
done
|
|
295
|
+
case "$ct_path" in
|
|
296
|
+
''|.|..|*/..|/) return 1 ;;
|
|
297
|
+
esac
|
|
298
|
+
if [ -L "$ct_path" ]; then
|
|
299
|
+
return 2
|
|
300
|
+
fi
|
|
301
|
+
if [ -e "$ct_path" ] && [ ! -d "$ct_path" ]; then
|
|
302
|
+
return 2
|
|
303
|
+
fi
|
|
304
|
+
ct_parent=$(dirname "$ct_path")
|
|
305
|
+
mkdir -p "$ct_parent" 2>/dev/null || return 1
|
|
306
|
+
ct_parent=$(cd "$ct_parent" 2>/dev/null && pwd -P) || return 1
|
|
307
|
+
printf '%s/%s\n' "${ct_parent%/}" "$(basename "$ct_path")"
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
# Shell-quote one argument for a command shown to a person (bash 3.2 %q).
|
|
311
|
+
cm_install_quote() {
|
|
312
|
+
printf '%q' "$1"
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
# ---- Signal deferral ----------------------------------------------------------
|
|
316
|
+
# Between a state change and the variable that tells cleanup about it (lock
|
|
317
|
+
# taken / directory renamed), HUP/INT/TERM are recorded instead of acted on,
|
|
318
|
+
# then honoured once the state is registered.
|
|
319
|
+
CM_PENDING_SIGNAL=""
|
|
320
|
+
cm_defer_signals() {
|
|
321
|
+
CM_PENDING_SIGNAL=""
|
|
322
|
+
trap 'CM_PENDING_SIGNAL=129' HUP
|
|
323
|
+
trap 'CM_PENDING_SIGNAL=130' INT
|
|
324
|
+
trap 'CM_PENDING_SIGNAL=143' TERM
|
|
325
|
+
}
|
|
326
|
+
cm_resume_signals() {
|
|
327
|
+
trap 'exit 129' HUP
|
|
328
|
+
trap 'exit 130' INT
|
|
329
|
+
trap 'exit 143' TERM
|
|
330
|
+
if [ -n "$CM_PENDING_SIGNAL" ]; then
|
|
331
|
+
exit "$CM_PENDING_SIGNAL"
|
|
332
|
+
fi
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
# cm_run_shielded COMMAND [ARGS...]
|
|
336
|
+
# Run one state-changing external command with HUP/INT/TERM ignored (the
|
|
337
|
+
# ignored disposition survives exec), so its exit status reports whether the
|
|
338
|
+
# side effect happened even when the whole process group is signalled. The
|
|
339
|
+
# parent records such signals through cm_defer_signals and acts on them after
|
|
340
|
+
# registering the result.
|
|
341
|
+
cm_run_shielded() {
|
|
342
|
+
(trap '' HUP INT TERM; exec "$@")
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
# Test-only fault injection point. CM_INSTALL_TEST_HOOK is unset outside the
|
|
346
|
+
# repository's tests; when set it is run as `$CM_INSTALL_TEST_HOOK <point> ...`.
|
|
347
|
+
cm_install_test_hook() {
|
|
348
|
+
if [ -n "${CM_INSTALL_TEST_HOOK:-}" ]; then
|
|
349
|
+
"$CM_INSTALL_TEST_HOOK" "$@"
|
|
350
|
+
fi
|
|
351
|
+
}
|
|
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import {createLiveEvidence} from '../runtime/js/cm-ai/live-evidence.mjs';
|
|
6
|
+
import {createLiveEvidence,qaAnswerWindowShortfall} from '../runtime/js/cm-ai/live-evidence.mjs';
|
|
7
7
|
|
|
8
8
|
function fixture(t){
|
|
9
9
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-live-evidence-')));
|
|
@@ -62,3 +62,61 @@ test('future parallel worktree roots are protected before they exist, including
|
|
|
62
62
|
assert.throws(()=>createLiveEvidence({directory:path.join(future,'run','exchange'),kinds:['qa_logic']},
|
|
63
63
|
{protectedRoots:[path.join(alias,'.cm-worktrees')]}),/live_evidence_protected_directory/);
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
// Batch session member develop (design 3.4): the bridge package travels unchanged
|
|
67
|
+
// and each of the three reply shapes comes back exactly as the session wrote it.
|
|
68
|
+
const bridgePackage={request:{identity:{repositoryId:'r',runId:'task-a',taskId:'T-002',attempt:1},payload:{scope:['docs/qa.md']}},
|
|
69
|
+
prompt:'Implement T-002',codeProject:'/fixture/app',route:{role:'developer'},editMode:'protected-text-v1',expected:{'docs/qa.md':null}};
|
|
70
|
+
const developRow={...row,kind:'develop',callId:'call-develop',payload:bridgePackage};
|
|
71
|
+
const replies={
|
|
72
|
+
proposal:{status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
73
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null},requirements:[]},
|
|
74
|
+
edits:[{path:'docs/qa.md',beforeSha256:null,content:'# QA walk-through\n'}]},
|
|
75
|
+
blocked:{status:'succeeded',value:{outcome:'blocked',reason:'browser environment unavailable',
|
|
76
|
+
application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}},edits:[]},
|
|
77
|
+
failed:{status:'failed',code:'session_unavailable'}};
|
|
78
|
+
for(const [name,reply] of Object.entries(replies))test(`develop live request passes the full bridge package and returns the ${name} reply unchanged`,async t=>{
|
|
79
|
+
const f=fixture(t);let request;
|
|
80
|
+
const live=createLiveEvidence({directory:f.directory,kinds:['develop'],timeoutMs:1000},{base:f.root,protectedRoots:[f.project],
|
|
81
|
+
allowedKinds:['develop'],notify:p=>{request=JSON.parse(fs.readFileSync(p,'utf8'));
|
|
82
|
+
fs.writeFileSync(p.replace('.request.json','.result.json'),JSON.stringify({type:'host_result',sessionId:request.sessionId,
|
|
83
|
+
callId:request.callId,requestDigest:request.requestDigest,result:reply}));}});
|
|
84
|
+
assert.deepEqual(await live.answer(developRow),reply);
|
|
85
|
+
assert.deepEqual(request,developRow);
|
|
86
|
+
});
|
|
87
|
+
test('develop is opt-in and its wait floor applies to develop only',t=>{
|
|
88
|
+
const f=fixture(t),options={base:f.root,protectedRoots:[f.project]};
|
|
89
|
+
assert.throws(()=>createLiveEvidence({directory:f.directory,kinds:['develop']},options),/live_evidence_invalid_config/);
|
|
90
|
+
const live=createLiveEvidence({directory:f.directory,kinds:['develop','qa_logic'],timeoutMs:1000},
|
|
91
|
+
{...options,allowedKinds:['develop','qa_logic'],minimumTimeouts:{develop:1860000}});
|
|
92
|
+
assert.equal(live.timeoutFor('develop'),1860000);assert.equal(live.timeoutFor('qa_logic'),1000);
|
|
93
|
+
assert.equal(live.timeoutFor('qa_browser'),null);
|
|
94
|
+
// A longer configured wait is kept; the floor never shortens it.
|
|
95
|
+
assert.equal(createLiveEvidence({directory:f.directory,kinds:['develop'],timeoutMs:3600000},
|
|
96
|
+
{...options,allowedKinds:['develop'],minimumTimeouts:{develop:1860000}}).timeoutFor('develop'),3600000);
|
|
97
|
+
for(const minimumTimeouts of [{develop:0},{develop:'1'},{unknown:1000}])
|
|
98
|
+
assert.throws(()=>createLiveEvidence({directory:f.directory,kinds:['develop']},{...options,allowedKinds:['develop'],minimumTimeouts}),/live_evidence_invalid_limit/);
|
|
99
|
+
});
|
|
100
|
+
test('develop wait uses its floor, not the shorter configured timeout',async t=>{
|
|
101
|
+
const f=fixture(t);
|
|
102
|
+
const live=createLiveEvidence({directory:f.directory,kinds:['develop','qa_logic'],timeoutMs:20},{base:f.root,protectedRoots:[f.project],
|
|
103
|
+
allowedKinds:['develop','qa_logic'],minimumTimeouts:{develop:400}});
|
|
104
|
+
const started=Date.now();
|
|
105
|
+
await assert.rejects(live.answer(developRow),/live_evidence_timeout/);
|
|
106
|
+
assert.ok(Date.now()-started>=400,'develop waits for its floor');
|
|
107
|
+
const quick=Date.now();await assert.rejects(live.answer({...row,callId:'call-q'}),/live_evidence_timeout/);
|
|
108
|
+
assert.ok(Date.now()-quick<400,'other kinds keep the configured timeout');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('the QA answer window is compared with the live wait for qa_logic/qa_browser only',()=>{
|
|
112
|
+
const live=kinds=>({has:kind=>kinds.includes(kind),timeoutFor:kind=>kinds.includes(kind)?900000:null});
|
|
113
|
+
assert.equal(qaAnswerWindowShortfall(null,live(['qa_browser']),['qa_browser']),null);
|
|
114
|
+
assert.match(qaAnswerWindowShortfall({commands:[]},live(['qa_browser']),['qa_assess','qa_browser']),
|
|
115
|
+
/未填(默认 60000) 毫秒,短于 PLAN\.liveEvidence 对 qa_browser 的等待 900000 毫秒/);
|
|
116
|
+
assert.match(qaAnswerWindowShortfall({timeoutMs:300000},live(['qa_logic','qa_browser']),['qa_logic','qa_browser','qa_logic']),
|
|
117
|
+
/为 300000 毫秒,短于 PLAN\.liveEvidence 对 qa_logic、qa_browser 的等待/);
|
|
118
|
+
assert.equal(qaAnswerWindowShortfall({timeoutMs:900000},live(['qa_browser']),['qa_browser']),null);
|
|
119
|
+
// Not answered live, or not asked: the window is not this driver's wait.
|
|
120
|
+
assert.equal(qaAnswerWindowShortfall({},live([]),['qa_browser']),null);
|
|
121
|
+
assert.equal(qaAnswerWindowShortfall({},live(['verification_precheck']),['verification_precheck','check']),null);
|
|
122
|
+
});
|
package/scripts/cm-log-event.mjs
CHANGED
|
@@ -149,14 +149,21 @@ export function generatedRunId(now=new Date(),uuid=randomUUID()){
|
|
|
149
149
|
return `${stamp}-${uuid.replaceAll('-','').slice(0,8)}`;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
export function selectRunId({explicit,event,pointer,latestProjectRun,projectStates,now,uuid}){
|
|
152
|
+
export function selectRunId({explicit,event,workflow,pointer,latestProjectRun,projectStates,projectWorkflows={},now,uuid}){
|
|
153
153
|
if(explicit!==null&&explicit!==undefined){
|
|
154
154
|
if(typeof explicit!=='string'||!RUN_ID.test(explicit))throw new UsageError('invalid --run-id');
|
|
155
155
|
return {runId:explicit,newRun:event==='run_start'};
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
// 另一个工作流的 run_start 不可能是续跑:不接到别人遗留的进行中运行上,开新运行。
|
|
158
|
+
const joinable=(runId,fallbackWorkflow)=>{
|
|
159
|
+
if(event!=='run_start')return true;
|
|
160
|
+
const owner=projectWorkflows[runId]??fallbackWorkflow;
|
|
161
|
+
return typeof owner!=='string'||owner===workflow;
|
|
162
|
+
};
|
|
163
|
+
if(pointer?.status==='running'&&projectStates[pointer.run_id]!=='done'&&joinable(pointer.run_id,pointer.workflow))
|
|
164
|
+
return {runId:pointer.run_id,newRun:false};
|
|
158
165
|
if(pointer?.status==='done'&&TERMINAL_EVENTS.has(event))return {runId:pointer.run_id,newRun:false};
|
|
159
|
-
if(latestProjectRun&&projectStates[latestProjectRun]==='running')return {runId:latestProjectRun,newRun:false};
|
|
166
|
+
if(latestProjectRun&&projectStates[latestProjectRun]==='running'&&joinable(latestProjectRun,latestProjectRun===pointer?.run_id?pointer.workflow:undefined))return {runId:latestProjectRun,newRun:false};
|
|
160
167
|
if(latestProjectRun&&projectStates[latestProjectRun]==='done'&&TERMINAL_EVENTS.has(event))
|
|
161
168
|
return {runId:latestProjectRun,newRun:false};
|
|
162
169
|
return {runId:generatedRunId(now,uuid),newRun:true};
|
|
@@ -252,8 +259,9 @@ export function buildEvent(input,state={}){
|
|
|
252
259
|
const project=input.project??(projectRoot?path.basename(projectRoot):'unscoped');
|
|
253
260
|
if(typeof project!=='string'||[...project].length>120||/[\n\r\0]/.test(project))
|
|
254
261
|
throw new UsageError('--project must be one line and at most 120 characters');
|
|
255
|
-
const selection=selectRunId({explicit:input.runId??null,event,pointer:state.pointer??null,
|
|
256
|
-
latestProjectRun:state.latestProjectRun??null,projectStates:state.projectStates??{},
|
|
262
|
+
const selection=selectRunId({explicit:input.runId??null,event,workflow,pointer:state.pointer??null,
|
|
263
|
+
latestProjectRun:state.latestProjectRun??null,projectStates:state.projectStates??{},projectWorkflows:state.projectWorkflows??{},
|
|
264
|
+
now:state.now,uuid:state.uuid});
|
|
257
265
|
const value={schema_version:1,run_id:selection.runId,at,workflow,event,runtime,project,detail};
|
|
258
266
|
if(phase)value.phase=phase;if(projectRoot)value.project_path=projectRoot;if(specsDir)value.specs_path=specsDir;
|
|
259
267
|
Object.assign(value,data);value.event_id=deterministicEventId(value);
|
|
@@ -298,17 +306,18 @@ function readJsonLines(file,{strict=false}={}){
|
|
|
298
306
|
}
|
|
299
307
|
|
|
300
308
|
function loadProjectRunState(file){
|
|
301
|
-
let latestProjectRun=null;const projectStates={};
|
|
309
|
+
let latestProjectRun=null;const projectStates={},projectWorkflows={};
|
|
302
310
|
try{
|
|
303
311
|
for(const value of readJsonLines(file)){
|
|
304
312
|
if(!value||typeof value!=='object'||typeof value.run_id!=='string'||!RUN_ID.test(value.run_id)||typeof value.event!=='string')continue;
|
|
305
313
|
latestProjectRun=value.run_id;
|
|
314
|
+
if(!Object.hasOwn(projectWorkflows,value.run_id)&&typeof value.workflow==='string')projectWorkflows[value.run_id]=value.workflow;
|
|
306
315
|
if(value.event==='run_start'||value.event==='resume')projectStates[value.run_id]='running';
|
|
307
316
|
else if(TERMINAL_EVENTS.has(value.event))projectStates[value.run_id]='done';
|
|
308
317
|
else if(!Object.hasOwn(projectStates,value.run_id))projectStates[value.run_id]='running';
|
|
309
318
|
}
|
|
310
|
-
}catch{return {latestProjectRun:null,projectStates:{}};}
|
|
311
|
-
return {latestProjectRun,projectStates};
|
|
319
|
+
}catch{return {latestProjectRun:null,projectStates:{},projectWorkflows:{}};}
|
|
320
|
+
return {latestProjectRun,projectStates,projectWorkflows};
|
|
312
321
|
}
|
|
313
322
|
|
|
314
323
|
function findJsonlEvent(file,eventId){
|
|
@@ -462,10 +471,52 @@ export function inspectRunClosure(file,runId){
|
|
|
462
471
|
|
|
463
472
|
function compactJson(value){return `${JSON.stringify(value)}\n`;}
|
|
464
473
|
function ensureDirectory(directory,mode){fs.mkdirSync(directory,{recursive:true,mode});if(process.platform!=='win32')fs.chmodSync(directory,mode);}
|
|
474
|
+
// The bytes after the last LF of a JSON Lines log. Readers accept a final record
|
|
475
|
+
// without LF, but appending straight after it would glue two records together.
|
|
476
|
+
const LOG_TAIL_LIMIT=4*1024*1024;
|
|
477
|
+
function unterminatedTail(descriptor){
|
|
478
|
+
const size=fs.fstatSync(descriptor).size;
|
|
479
|
+
if(size===0)return null;
|
|
480
|
+
const last=Buffer.alloc(1);fs.readSync(descriptor,last,0,1,size-1);
|
|
481
|
+
if(last[0]===0x0a)return null;
|
|
482
|
+
const chunk=64*1024;let end=size,tail=Buffer.alloc(0);
|
|
483
|
+
while(end>0&&tail.length<=LOG_TAIL_LIMIT){
|
|
484
|
+
const start=Math.max(0,end-chunk),piece=Buffer.alloc(end-start);
|
|
485
|
+
fs.readSync(descriptor,piece,0,piece.length,start);
|
|
486
|
+
const newline=piece.lastIndexOf(0x0a);
|
|
487
|
+
if(newline!==-1){
|
|
488
|
+
const found=Buffer.concat([piece.subarray(newline+1),tail]);
|
|
489
|
+
return found.length<=LOG_TAIL_LIMIT?found:false;
|
|
490
|
+
}
|
|
491
|
+
tail=Buffer.concat([piece,tail]);end=start;
|
|
492
|
+
}
|
|
493
|
+
return end===0&&tail.length<=LOG_TAIL_LIMIT?tail:false;
|
|
494
|
+
}
|
|
495
|
+
// JSON whitespace only (space, tab, CR): harmless padding the next record can
|
|
496
|
+
// start after, exactly as the plain O_APPEND writer always did.
|
|
497
|
+
const blankTail=tail=>tail.every(byte=>byte===0x20||byte===0x09||byte===0x0d);
|
|
498
|
+
// Readers decode logs as strict UTF-8; a tail they would reject is not complete.
|
|
499
|
+
// ignoreBOM keeps a leading BOM in the text, so JSON.parse rejects it as the host reader does.
|
|
500
|
+
const strictUtf8=new TextDecoder('utf-8',{fatal:true,ignoreBOM:true});
|
|
465
501
|
function appendLine(file,value,{privateFile=false}={}){
|
|
466
502
|
fs.mkdirSync(path.dirname(file),{recursive:true});
|
|
467
|
-
const descriptor=fs.openSync(file,fs.constants.O_APPEND|fs.constants.O_CREAT|fs.constants.
|
|
468
|
-
try{
|
|
503
|
+
const descriptor=fs.openSync(file,fs.constants.O_APPEND|fs.constants.O_CREAT|fs.constants.O_RDWR,privateFile?0o600:0o644);
|
|
504
|
+
try{
|
|
505
|
+
// Callers hold the log's write lock, so the tail cannot change underneath.
|
|
506
|
+
// A complete final record without LF is closed first; a half-written one is
|
|
507
|
+
// left byte for byte and refused rather than buried under a new record.
|
|
508
|
+
const tail=unterminatedTail(descriptor);
|
|
509
|
+
let complete=false,blank=false;
|
|
510
|
+
if(tail!==null&&tail!==false){
|
|
511
|
+
blank=blankTail(tail);
|
|
512
|
+
if(!blank)try{JSON.parse(strictUtf8.decode(tail));complete=true;}catch{}
|
|
513
|
+
}
|
|
514
|
+
if(tail!==null&&!complete&&!blank){
|
|
515
|
+
const error=new Error(`log_tail_incomplete: ${file} ends with an incomplete record; repair or move that last line before writing more events`);
|
|
516
|
+
error.code='log_tail_incomplete';throw error;
|
|
517
|
+
}
|
|
518
|
+
fs.writeFileSync(descriptor,(complete?'\n':'')+compactJson(value));fs.fsyncSync(descriptor);
|
|
519
|
+
}finally{fs.closeSync(descriptor);}
|
|
469
520
|
if(privateFile&&process.platform!=='win32')fs.chmodSync(file,0o600);
|
|
470
521
|
}
|
|
471
522
|
|