@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
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// Commander phase 2: dispatch registry with deadlines, dispatch preflight, the
|
|
2
|
+
// recovery decision table, and the acceptance replay of the aihot record
|
|
3
|
+
// (30 reopens and 8 stopped background jobs, 重开原因分类-2026-10-14.md).
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import {addDispatch,finishDispatch,readRegistry,openDispatches,registryDir,registryProblem} from '../runtime/js/commander/dispatch-registry.mjs';
|
|
10
|
+
import {decideRecovery,DECISIONS} from '../runtime/js/commander/decision.mjs';
|
|
11
|
+
import {answerValueFindings,answerChangeFindings,checkDevices,deviceFindings,checksDriftFindings} from '../runtime/js/commander/preflight.mjs';
|
|
12
|
+
import {composeLedger,registryInput} from '../runtime/js/commander/ledger.mjs';
|
|
13
|
+
import {inspectFixDiagnosis} from '../runtime/js/cm-fix/diagnosis.mjs';
|
|
14
|
+
import {main} from './cm-commander.mjs';
|
|
15
|
+
import {answerAttempt} from './cm-commander-preflight.mjs';
|
|
16
|
+
|
|
17
|
+
const isolated=fs.mkdtempSync(path.join(os.tmpdir(),'cm-commander-p2-home-'));
|
|
18
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolated,'user');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
|
|
19
|
+
test.after(()=>fs.rmSync(isolated,{recursive:true,force:true}));
|
|
20
|
+
const NOW='2026-10-20T10:00:00.000Z';
|
|
21
|
+
const later=minutes=>new Date(Date.parse(NOW)+minutes*60000).toISOString();
|
|
22
|
+
const specs=t=>{const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-commander-p2-specs-')));
|
|
23
|
+
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));return dir;};
|
|
24
|
+
const UDID='0A1B2C3D-4E5F-6789-ABCD-EF0123456789',UDID2='1B2C3D4E-5F60-789A-BCDE-F0123456789A';
|
|
25
|
+
const registryFile=dir=>path.join(registryDir(dir),'dispatch.jsonl');
|
|
26
|
+
|
|
27
|
+
test('the registry records a deadline, closes once, and reports overdue jobs; it never writes into specs',t=>{
|
|
28
|
+
const dir=specs(t),before=fs.readdirSync(dir);
|
|
29
|
+
const {id,deadline}=addDispatch(dir,{label:'xcodebuild test',deadlineMinutes:30,runId:'run-1',resources:[`device:${UDID}`],now:NOW});
|
|
30
|
+
assert.equal(deadline,later(30));
|
|
31
|
+
assert.deepEqual(fs.readdirSync(dir),before,'the registry lives under the CM home, not in specs');
|
|
32
|
+
assert.ok(registryDir(dir).startsWith(process.env.CM_WORKFLOW_HOME));
|
|
33
|
+
let open=openDispatches(readRegistry(dir),later(29));
|
|
34
|
+
assert.equal(open.length,1);assert.equal(open[0].overdue,false);
|
|
35
|
+
open=openDispatches(readRegistry(dir),later(45));
|
|
36
|
+
assert.equal(open[0].overdue,true);assert.equal(open[0].overdueMinutes,15);
|
|
37
|
+
finishDispatch(dir,{id,now:later(46)});
|
|
38
|
+
assert.equal(openDispatches(readRegistry(dir),later(50)).length,0);
|
|
39
|
+
assert.throws(()=>finishDispatch(dir,{id}),{code:'dispatch_already_done'});
|
|
40
|
+
assert.throws(()=>finishDispatch(dir,{id:'nope'}),{code:'unknown_dispatch'});
|
|
41
|
+
assert.throws(()=>addDispatch(dir,{label:'again',deadlineMinutes:5,id}),{code:'dispatch_exists'});
|
|
42
|
+
assert.equal(registryProblem(readRegistry(dir)),null);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('the registry refuses bad input and a held lock; done is checked inside the lock',t=>{
|
|
46
|
+
const dir=specs(t);
|
|
47
|
+
for(const [input,code] of [[{label:'',deadlineMinutes:5},'invalid_label'],[{label:'a\nb',deadlineMinutes:5},'invalid_label'],
|
|
48
|
+
[{label:'x',deadlineMinutes:0},'invalid_deadline'],[{label:'x',deadlineMinutes:1.5},'invalid_deadline'],
|
|
49
|
+
[{label:'x',deadlineMinutes:24*60+1},'invalid_deadline'],[{label:'x',deadlineMinutes:5,resources:['gpu:1']},'invalid_resource'],
|
|
50
|
+
[{label:'x',deadlineMinutes:5,runId:'../x'},'invalid_run_id']])
|
|
51
|
+
assert.throws(()=>addDispatch(dir,input),{code},JSON.stringify(input));
|
|
52
|
+
const {id}=addDispatch(dir,{label:'ok',deadlineMinutes:5,now:NOW});
|
|
53
|
+
const lock=path.join(registryDir(dir),'dispatch.lock'),bytes=fs.readFileSync(registryFile(dir));
|
|
54
|
+
fs.writeFileSync(lock,'');
|
|
55
|
+
assert.throws(()=>addDispatch(dir,{label:'x',deadlineMinutes:5}),{code:'registry_locked'},'a held lock is reported, never broken');
|
|
56
|
+
assert.throws(()=>finishDispatch(dir,{id}),{code:'registry_locked'},'finishing waits for the same lock as the check');
|
|
57
|
+
assert.deepEqual(fs.readFileSync(registryFile(dir)),bytes);fs.rmSync(lock);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('a torn tail refuses the next append and keeps the bytes; bad rows are reported, never read as "no jobs"',t=>{
|
|
61
|
+
const dir=specs(t);
|
|
62
|
+
addDispatch(dir,{label:'first',deadlineMinutes:5,now:NOW,id:'a'});
|
|
63
|
+
fs.appendFileSync(registryFile(dir),'{"v":1,"op":"add","id":"torn"');
|
|
64
|
+
const before=fs.readFileSync(registryFile(dir));
|
|
65
|
+
assert.throws(()=>addDispatch(dir,{label:'second',deadlineMinutes:5}),{code:'registry_torn'});
|
|
66
|
+
assert.deepEqual(fs.readFileSync(registryFile(dir)),before,'nothing is appended after a torn tail');
|
|
67
|
+
assert.equal(registryProblem(readRegistry(dir)),'registry_torn');
|
|
68
|
+
const clean=specs(t);addDispatch(clean,{label:'x',deadlineMinutes:5,now:NOW});
|
|
69
|
+
fs.appendFileSync(registryFile(clean),'not json\n');
|
|
70
|
+
assert.equal(registryProblem(readRegistry(clean)),'registry_invalid_rows:1');
|
|
71
|
+
const listed=main(['dispatch','list','--specs',clean]);
|
|
72
|
+
assert.equal(listed.code,1);assert.match(listed.text,/登记有问题.*registry_invalid_rows:1/);
|
|
73
|
+
assert.equal(main(['dispatch','list','--specs',clean,'--json']).code,1);
|
|
74
|
+
assert.equal(registryInput(clean,NOW).registryError,'registry_invalid_rows:1','the ledger sees the bad rows');
|
|
75
|
+
assert.equal(registryInput(dir,NOW).registryError,'registry_torn');
|
|
76
|
+
assert.deepEqual(registryInput(specs(t),NOW),{dispatches:[],registryError:null},'no registry at all is simply empty');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('the decision table commits only where the record settles it; every first step is reading status',()=>{
|
|
80
|
+
const cases=[
|
|
81
|
+
[{verified:false},'read_status',false],[{state:'unknown',pending:'develop'},'wait',false],
|
|
82
|
+
[{state:'blocked',code:'spec_drift'},'spec_change',true],[{state:'blocked',code:'protected_scope'},'human_sync',true],
|
|
83
|
+
[{state:'blocked',code:'execution_error'},'escalate',true],[{state:'unknown',code:'reconciliation_required'},'escalate',true],
|
|
84
|
+
[{state:'blocked',code:'review_transport_timeout'},'read_status',true],[{state:'blocked',code:'develop_checks_not_passed'},'read_status',true],
|
|
85
|
+
[{state:'blocked',code:'review_package_changed'},'read_status',true],[{state:'blocked',code:'review_blocked'},'read_status',true],
|
|
86
|
+
[{state:'blocked',code:'develop_retry_limit'},'read_status',true],[{state:'cancelled',code:'cancelled'},'read_status',true],
|
|
87
|
+
[{state:'blocked',code:'something_new'},'read_status',false]];
|
|
88
|
+
for(const [input,decision,approval] of cases){
|
|
89
|
+
const out=decideRecovery(input);
|
|
90
|
+
assert.equal(out.decision,decision,JSON.stringify(input));assert.equal(out.needsApproval,approval,JSON.stringify(input));
|
|
91
|
+
assert.ok(DECISIONS.includes(out.decision));assert.match(out.steps[0],/读 status/,JSON.stringify(input));
|
|
92
|
+
}
|
|
93
|
+
assert.ok(decideRecovery({state:'blocked',code:'develop_retry_limit'}).candidates.some(c=>/development_rework/.test(c)),
|
|
94
|
+
'an exhausted develop budget may still offer the original run’s rework');
|
|
95
|
+
assert.ok(decideRecovery({state:'blocked',code:'review_transport_timeout'}).candidates.some(c=>/abandon_review.*需用户批准/.test(c)));
|
|
96
|
+
const redo=decideRecovery({state:'blocked',code:'documentation_sync_answer_missing'});
|
|
97
|
+
assert.equal(redo.needsApproval,true,'develop_redo is an explicit recovery');
|
|
98
|
+
assert.ok(redo.candidates.some(c=>/develop_redo.*需用户批准/.test(c)));
|
|
99
|
+
assert.equal(decideRecovery({state:'blocked',code:'something_new'}).needsApproval,false,'nothing listed, nothing to approve');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const identity={repositoryId:'r',runId:'run-1',taskId:'T-001',attempt:1};
|
|
103
|
+
const answer=(application,retrospective={status:'no_new_lesson',candidates:[],reason:null},edits={'a.mjs':'a.txt'})=>
|
|
104
|
+
({status:'succeeded',value:{outcome:'implemented',application,retrospective},edits});
|
|
105
|
+
const lesson={status:'lesson_candidate',reason:null,candidates:[{classification:'structured',trigger:'t',action:'a',evidence:['a.mjs']}]};
|
|
106
|
+
|
|
107
|
+
test('preflight: an answer over a host bound is an error before dispatch; within bounds passes',()=>{
|
|
108
|
+
assert.deepEqual(answerValueFindings(answer({status:'applied',note:'x'.repeat(512)}),{feature:'1.work',identity}),[]);
|
|
109
|
+
const long=answerValueFindings(answer({status:'applied',note:'x'.repeat(513)}),{feature:'1.work',identity});
|
|
110
|
+
assert.equal(long[0].code,'develop_answer_invalid');assert.match(long[0].message,/513 个字符/);
|
|
111
|
+
assert.equal(answerValueFindings(answer({status:'applied',note:'😀'.repeat(257)}),{feature:'1.work',identity}).length,1,'an emoji counts as 2');
|
|
112
|
+
const retro=answerValueFindings(answer({status:'no_relevant_lesson',note:null},{status:'lesson_candidate',candidates:[],reason:null}),{feature:'1.work',identity});
|
|
113
|
+
assert.equal(retro[0].part,'retrospective');
|
|
114
|
+
assert.deepEqual(answerValueFindings({status:'failed'},{feature:'1.work',identity}),[]);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('preflight: a no-op answer is an error; a real change, a deletion or a lesson-only delivery is not',t=>{
|
|
118
|
+
const root=specs(t),answersDir=path.join(root,'answers'),codeProject=path.join(root,'app');
|
|
119
|
+
fs.mkdirSync(answersDir);fs.mkdirSync(codeProject);
|
|
120
|
+
fs.writeFileSync(path.join(codeProject,'a.mjs'),'same\n');fs.writeFileSync(path.join(answersDir,'a.txt'),'same\n');
|
|
121
|
+
fs.writeFileSync(path.join(answersDir,'b.txt'),'new\n');
|
|
122
|
+
const value=answer({status:'no_relevant_lesson',note:null}),at={answersDir,codeProject};
|
|
123
|
+
assert.equal(answerChangeFindings(value,at)[0].code,'develop_no_change');
|
|
124
|
+
assert.deepEqual(answerChangeFindings({...value,edits:{'a.mjs':'a.txt','b.mjs':'b.txt'}},at),[]);
|
|
125
|
+
assert.deepEqual(answerChangeFindings({...value,edits:{'a.mjs':{delete:true}}},at),[]);
|
|
126
|
+
assert.equal(answerChangeFindings({...value,edits:{'gone.mjs':{delete:true}}},at)[0].code,'develop_no_change');
|
|
127
|
+
assert.equal(answerChangeFindings({...value,edits:{}},at)[0].code,'develop_no_change');
|
|
128
|
+
assert.deepEqual(answerChangeFindings(answer({status:'no_relevant_lesson',note:null},lesson,{}),at),[],
|
|
129
|
+
'a lesson candidate changes AGENTS.md through the writeback, so it is a delivery');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const xcode=(id,extra=[],device=UDID)=>({id,command:['xcodebuild','test','-scheme','App','-destination',`platform=iOS Simulator,id=${device}`,...extra]});
|
|
133
|
+
test('preflight devices: only addressed devices count, ids compare in one form, parallel and multiple destinations differ',()=>{
|
|
134
|
+
const held=[{label:'别的会话的 UI 测试',runId:'other',resources:[`device:${UDID.toLowerCase()}`]}];
|
|
135
|
+
assert.equal(deviceFindings([xcode('ui')],held)[0].code,'device_busy','a lowercase registration is the same device');
|
|
136
|
+
assert.deepEqual(deviceFindings([xcode('ui')],held,{runId:'other'}),[],'a run does not block itself');
|
|
137
|
+
assert.deepEqual(checkDevices([{id:'db',command:['node','check-db.mjs','--record-id',UDID]}]).devices,[],'an unrelated UUID is not a device');
|
|
138
|
+
assert.deepEqual(checkDevices([{id:'boot',command:['xcrun','simctl','boot',UDID]}]).devices,[UDID]);
|
|
139
|
+
const wrapped={id:'sh',command:['sh','-c',`xcrun simctl boot ${UDID} && xcodebuild test -destination 'id=${UDID2}'`]};
|
|
140
|
+
assert.deepEqual(checkDevices([wrapped]).devices.sort(),[UDID,UDID2].sort());
|
|
141
|
+
assert.equal(deviceFindings([wrapped],[])[0].code,'parallel_simulators','two devices in one check');
|
|
142
|
+
assert.equal(deviceFindings([xcode('ui',['-parallel-testing-worker-count','4'])],[])[0].code,'parallel_simulators');
|
|
143
|
+
assert.equal(deviceFindings([xcode('ui',['-destination','platform=iOS Simulator,name=iPhone 15'])],[])[0].code,'multiple_destinations');
|
|
144
|
+
assert.deepEqual(deviceFindings([xcode('ui',['-parallel-testing-enabled','NO'])],[]),[]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('preflight drift: completion checks must equal the approved package’s',()=>{
|
|
148
|
+
const recorded=[{id:'syntax',command:['node','--check','a.mjs']}];
|
|
149
|
+
assert.deepEqual(checksDriftFindings(recorded,recorded),[]);
|
|
150
|
+
assert.equal(checksDriftFindings([{id:'syntax',command:['node','--check','b.mjs']}],recorded)[0].code,'checks_changed_since_review');
|
|
151
|
+
assert.deepEqual(checksDriftFindings(undefined,recorded),[]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
function preflightProject(t,{scope=['a.mjs'],develop}={}){
|
|
155
|
+
const root=specs(t),specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),answersDir=path.join(root,'answers');
|
|
156
|
+
for(const dir of [specsDir,codeProject,answersDir])fs.mkdirSync(dir);
|
|
157
|
+
fs.writeFileSync(path.join(codeProject,'a.mjs'),'old\n');fs.writeFileSync(path.join(answersDir,'a.txt'),'old\n');
|
|
158
|
+
if(develop)for(const [name,value] of Object.entries(develop))fs.writeFileSync(path.join(answersDir,name),JSON.stringify(value));
|
|
159
|
+
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify({version:1,specsDir,codeProject,feature:'1.work',identity,scope,requirements:[]}));
|
|
160
|
+
const plan=(extra={})=>{const file=path.join(root,`plan-${Math.random().toString(36).slice(2)}.json`);
|
|
161
|
+
fs.writeFileSync(file,JSON.stringify({config:'run.json',mode:'create',answers:'answers',checks:[xcode('ui')],...extra}));return file;};
|
|
162
|
+
return {root,specsDir,plan};
|
|
163
|
+
}
|
|
164
|
+
const preflight=(file,operation)=>{const out=main(['preflight','--plan',file,'--operation',operation,'--json']);return {code:out.code,...JSON.parse(out.text)};};
|
|
165
|
+
|
|
166
|
+
test('preflight reads the attempt the driver will: 1 on create, the journal’s own attempt on resume',()=>{
|
|
167
|
+
assert.equal(answerAttempt('create',null),1);
|
|
168
|
+
assert.equal(answerAttempt('resume',{state:'changes_requested',attempt:2}),2,'the runner already moved to 2: develop-a2.json');
|
|
169
|
+
assert.equal(answerAttempt('resume',{state:'developing',attempt:1}),1);
|
|
170
|
+
assert.equal(answerAttempt('resume',null),null);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('preflight CLI: start-check errors and the commander’s own add up for a develop step, exit 1',t=>{
|
|
174
|
+
const p=preflightProject(t,{scope:['a.mjs','AGENTS.md'],develop:{'develop.json':answer({status:'applied',note:'x'.repeat(600)})}});
|
|
175
|
+
addDispatch(p.specsDir,{label:'另一条运行的 UI 测试',deadlineMinutes:60,runId:'other',resources:[`device:${UDID}`]});
|
|
176
|
+
const out=preflight(p.plan(),'start'),codes=out.findings.map(item=>item.code);
|
|
177
|
+
assert.equal(out.code,1);
|
|
178
|
+
for(const code of ['protected_scope','develop_answer_invalid','develop_no_change','device_busy'])assert.ok(codes.includes(code),`${code} in ${codes}`);
|
|
179
|
+
assert.match(main(['preflight','--plan',p.plan(),'--operation','start']).text,/develop\.json:开发应答会在派出后被判无效/);
|
|
180
|
+
assert.equal(main(['preflight','--plan',path.join(p.root,'missing.json'),'--operation','start','--json']).code,1);
|
|
181
|
+
assert.equal(main(['preflight','--plan',p.plan()]).code,2,'the operation is required');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('preflight CLI: answers are judged only for a develop step, a refused start check is an error, both a1 names conflict',t=>{
|
|
185
|
+
const p=preflightProject(t,{develop:{'develop.json':answer({status:'applied',note:'x'.repeat(600)})}});
|
|
186
|
+
const status=preflight(p.plan(),'status');
|
|
187
|
+
assert.ok(!status.findings.some(item=>item.code.startsWith('develop_')),'a read-only status step does not judge answers');
|
|
188
|
+
const bad=preflightProject(t,{scope:[]});
|
|
189
|
+
const refused=preflight(bad.plan(),'status');
|
|
190
|
+
assert.equal(refused.code,1);assert.ok(refused.findings.some(item=>item.code==='start_check_refused'));
|
|
191
|
+
assert.doesNotMatch(main(['preflight','--plan',bad.plan(),'--operation','status']).text,/体检通过/);
|
|
192
|
+
const both=preflightProject(t,{develop:{'develop.json':answer({status:'no_relevant_lesson',note:null}),
|
|
193
|
+
'develop-a1.json':answer({status:'no_relevant_lesson',note:null})}});
|
|
194
|
+
assert.ok(preflight(both.plan(),'start').findings.some(item=>item.code==='develop_answer_ambiguous'));
|
|
195
|
+
const resume=preflight(p.plan({mode:'resume'}),'resume');
|
|
196
|
+
assert.ok(resume.findings.some(item=>item.code==='answer_check_skipped'),'without a readable journal the attempt is unknown, so answers are skipped and said so');
|
|
197
|
+
assert.match(main(['preflight','--plan',p.plan({mode:'resume'}),'--operation','resume']).text,/跳过/);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const ready={state:'ready',reason:'task_selected',nextTask:{feature:'1.work',id:'T-002'}};
|
|
201
|
+
const features=[{name:'1.work',tasks:[{id:'T-001',completed:false,dropped:false,dependsOn:[]},{id:'T-002',completed:false,dropped:false,dependsOn:[]}]}];
|
|
202
|
+
const noLog={present:true,invalid:0,runs:new Map()};
|
|
203
|
+
const job=(id,overdue,extra={})=>({id,label:`job-${id}`,runId:null,resources:[],deadline:NOW,startedAt:NOW,doneAt:null,overdue,overdueMinutes:overdue?30:0,...extra});
|
|
204
|
+
|
|
205
|
+
test('ledger: an overdue job is checked first, an open one is waited on, an unhealthy registry blocks new work',t=>{
|
|
206
|
+
const overdue=composeLedger({specsDir:'/s',admission:ready,features,runs:[],log:noLog,now:NOW,dispatches:[job('a',true)]});
|
|
207
|
+
assert.equal(overdue.next.kind,'overdue_dispatch');assert.match(overdue.next.why,/30 分钟/);
|
|
208
|
+
const open=composeLedger({specsDir:'/s',admission:ready,features,runs:[],log:noLog,now:NOW,dispatches:[job('b',false)]});
|
|
209
|
+
assert.equal(open.next.kind,'wait_dispatch','single-flight covers registered jobs too');
|
|
210
|
+
for(const problem of ['EACCES','registry_torn','registry_invalid_rows:1']){
|
|
211
|
+
const broken=composeLedger({specsDir:'/s',admission:ready,features,runs:[],log:noLog,now:NOW,registryError:problem});
|
|
212
|
+
assert.equal(broken.next.kind,'check_records',problem);
|
|
213
|
+
}
|
|
214
|
+
const stopped=composeLedger({specsDir:'/s',admission:ready,features,log:noLog,now:NOW,
|
|
215
|
+
runs:[{runId:'r',kind:'cm-ai',verified:true,feature:'1.work',taskId:'T-001',state:'blocked',code:'develop_retry_limit',attempt:2,
|
|
216
|
+
pending:null,committed:false,trustedPrevious:[],claimedPrevious:[],records:9}]});
|
|
217
|
+
assert.equal(stopped.next.decision.decision,'read_status');assert.equal(stopped.next.decision.needsApproval,true);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// Acceptance replay of the 30 aihot reopens. Each is mapped, on its recorded
|
|
221
|
+
// cause, to what now happens before dispatch:
|
|
222
|
+
// blocked — an error stops the step (exit 1/2) before any host or run;
|
|
223
|
+
// warned — a warning names the cause, but the step may still be sent;
|
|
224
|
+
// resolved — the current design removed the cause itself;
|
|
225
|
+
// variant — only a neighbouring variant is caught, not the recorded path;
|
|
226
|
+
// workflow — a workflow code defect, not a dispatch-time matter;
|
|
227
|
+
// none — not caught yet (task difficulty, external, scope change...).
|
|
228
|
+
// Inputs are rebuilt from the recorded cause; the original journals are not replayed.
|
|
229
|
+
const REPLAY=[
|
|
230
|
+
[1,'A','workflow'],[2,'A','workflow'],
|
|
231
|
+
[3,'D','resolved','review-package.mjs verifyCompletionReviewPackage: 检查说明文字可变,文件与结果须一致'],
|
|
232
|
+
[4,'D','warned','cm-start-check: dirty scope files warn'],[5,'C','blocked','commander device_busy'],[6,'C','none'],
|
|
233
|
+
[7,'B','blocked','commander develop_answer_invalid'],[8,'C','warned','cm-start-check: two xcodebuild test checks on one scheme warn'],
|
|
234
|
+
[9,'E','none'],[10,'D','warned','cm-start-check: dirty scope files warn(只能提示,不能证明代码来源)'],[11,'A','workflow'],[12,'A','workflow'],
|
|
235
|
+
[13,'B','blocked','cm-ai-develop-driver-gaps: #19 scope material above 2 MiB is refused before launch(四张 PNG 截图)'],
|
|
236
|
+
[14,'B','blocked','cm-start-check: protected scope paths are errors and exit 1'],[15,'E','none'],[16,'E','none'],
|
|
237
|
+
[17,'B','blocked','cm-fix-drive: inspectFixDiagnosis 在开宿主前校验 crossLayer 与 affectedModules'],
|
|
238
|
+
[18,'C','none'],[19,'E','none'],[20,'C','none'],[21,'E','none'],[22,'E','none'],[23,'F','none'],[24,'E','none'],[25,'F','none'],
|
|
239
|
+
[26,'C','warned','commander parallel_simulators(日志量过大未覆盖)'],[27,'A','workflow'],
|
|
240
|
+
[28,'B','variant','commander develop_no_change 只覆盖 cm-ai 开发应答;原事故是 cm-fix 测试应答 test-edits.json'],
|
|
241
|
+
[29,'E','none'],[30,'A','workflow']];
|
|
242
|
+
|
|
243
|
+
test('replay: the 30 aihot reopens — of the 11 judged stoppable, 5 are blocked, 4 warned, 1 resolved, 1 only as a variant',t=>{
|
|
244
|
+
assert.equal(REPLAY.length,30);
|
|
245
|
+
const byClass=REPLAY.reduce((map,[,cls])=>({...map,[cls]:(map[cls]??0)+1}),{});
|
|
246
|
+
assert.deepEqual(byClass,{A:6,B:5,C:6,D:3,E:8,F:2},'same classification as the 2026-10-14 record');
|
|
247
|
+
const stoppable=new Set([3,4,5,7,8,10,13,14,17,26,28]);
|
|
248
|
+
const tally=REPLAY.filter(([n])=>stoppable.has(n)).reduce((map,[,,via])=>({...map,[via]:(map[via]??0)+1}),{});
|
|
249
|
+
assert.deepEqual(tally,{resolved:1,warned:4,blocked:5,variant:1});
|
|
250
|
+
// The commander's own blocks, through the real CLI: exit 1 before dispatch.
|
|
251
|
+
const p=preflightProject(t,{develop:{'develop.json':answer({status:'applied',note:'x'.repeat(600)},undefined,{'a.mjs':'b.txt'})}});
|
|
252
|
+
fs.writeFileSync(path.join(p.root,'answers','b.txt'),'new\n');
|
|
253
|
+
const seven=preflight(p.plan(),'start');
|
|
254
|
+
assert.equal(seven.code,1);assert.ok(seven.findings.some(item=>item.code==='develop_answer_invalid'&&item.level==='error'),'#7');
|
|
255
|
+
const five=preflightProject(t,{develop:{'develop.json':answer({status:'no_relevant_lesson',note:null},undefined,{'a.mjs':'b.txt'})}});
|
|
256
|
+
fs.writeFileSync(path.join(five.root,'answers','b.txt'),'new\n');
|
|
257
|
+
addDispatch(five.specsDir,{label:'同一模拟器上并行跑的别的测试',deadlineMinutes:60,runId:'other',resources:[`device:${UDID}`]});
|
|
258
|
+
const busy=preflight(five.plan(),'start');
|
|
259
|
+
assert.equal(busy.code,1);assert.ok(busy.findings.some(item=>item.code==='device_busy'&&item.level==='error'),'#5');
|
|
260
|
+
// #17: the existing cm-fix validator refuses a diagnosis without the required fields.
|
|
261
|
+
const diagnosis={status:'diagnosed',rootCause:'r',affectedPaths:['a.mjs'],plan:'p',crossLayer:false,affectedModules:['a']};
|
|
262
|
+
inspectFixDiagnosis(diagnosis);
|
|
263
|
+
for(const field of ['crossLayer','affectedModules']){const {[field]:missing,...rest}=diagnosis;assert.throws(()=>inspectFixDiagnosis(rest),`#17 ${field}`);}
|
|
264
|
+
// #26 is a warning, not a block.
|
|
265
|
+
const parallel=deviceFindings([xcode('ui',['-parallel-testing-worker-count','4'])],[]);
|
|
266
|
+
assert.equal(parallel[0].level,'warn');
|
|
267
|
+
t.diagnostic(JSON.stringify(Object.fromEntries(['blocked','warned','resolved','variant','workflow','none']
|
|
268
|
+
.map(via=>[via,REPLAY.filter(r=>r[2]===via).map(r=>r[0])]))));
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('replay: the 8 stopped background jobs are each found once past their deadline (when registered)',t=>{
|
|
272
|
+
const dir=specs(t);
|
|
273
|
+
const jobs=[['会话自写的等待命令:条件写错',20],['会话自写的找报告命令:没设超时',20],['等待 Codex 报告的轮询',30],['等宿主结束的轮询',30],
|
|
274
|
+
['cm-ai-drive 后台步骤:没设超时',60],['cm-ai-drive 后台步骤:超过外层时限',60],['codex exec 没关 stdin',45],['cm-fix 补测无输出',45]];
|
|
275
|
+
for(const [label,minutes] of jobs)addDispatch(dir,{label,deadlineMinutes:minutes,now:NOW});
|
|
276
|
+
const dispatches=openDispatches(readRegistry(dir),later(61));
|
|
277
|
+
assert.equal(dispatches.filter(job=>job.overdue).length,8);
|
|
278
|
+
const ledger=composeLedger({specsDir:dir,admission:ready,features,runs:[],log:noLog,now:later(61),dispatches});
|
|
279
|
+
assert.equal(ledger.next.kind,'overdue_dispatch');
|
|
280
|
+
assert.equal([ledger.next,...ledger.queue].filter(item=>item.kind==='overdue_dispatch').length,8);
|
|
281
|
+
assert.equal(composeLedger({specsDir:dir,admission:ready,features,runs:[],log:noLog,now:later(10),
|
|
282
|
+
dispatches:openDispatches(readRegistry(dir),later(10))}).next.kind,'wait_dispatch','before any deadline nothing is flagged');
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('CLI: dispatch add / list / done round trip, and usage errors exit 2',t=>{
|
|
286
|
+
const dir=specs(t);
|
|
287
|
+
const added=main(['dispatch','add','--specs',dir,'--label','ui test','--deadline-minutes','15','--device',UDID.toLowerCase(),'--json']);
|
|
288
|
+
assert.equal(added.code,0);const {id}=JSON.parse(added.text);
|
|
289
|
+
assert.match(main(['dispatch','list','--specs',dir]).text,new RegExp(`\\[进行\\] ${id} ui test.*device:${UDID}`));
|
|
290
|
+
assert.equal(main(['dispatch','done','--specs',dir,'--id',id]).code,0);
|
|
291
|
+
assert.match(main(['dispatch','list','--specs',dir]).text,/没有未结束的登记/);
|
|
292
|
+
assert.equal(main(['dispatch','add','--specs',dir,'--label','x']).code,2);
|
|
293
|
+
assert.equal(main(['dispatch','nope','--specs',dir]).code,2);
|
|
294
|
+
assert.throws(()=>main(['dispatch','add','--specs',dir,'--label','x','--deadline-minutes','abc']),{code:'invalid_deadline'});
|
|
295
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Commander phase 2 dispatch preflight: cm-start-check's findings plus the
|
|
2
|
+
// commander's own, for the one driver operation about to be dispatched. Each
|
|
3
|
+
// rule applies only where the driver would act the same way, so a legitimate
|
|
4
|
+
// second round, a recovery or a read-only step is not refused. Read-only.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import {loadStartInputs,startCheck} from './cm-start-check.mjs';
|
|
8
|
+
import {answerValueFindings,answerChangeFindings,deviceFindings,checksDriftFindings} from '../runtime/js/commander/preflight.mjs';
|
|
9
|
+
import {readRegistry,openDispatches,registryProblem} from '../runtime/js/commander/dispatch-registry.mjs';
|
|
10
|
+
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
11
|
+
import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
12
|
+
|
|
13
|
+
// Operations whose host step may ask for a develop answer (cm-ai-drive ADVANCE).
|
|
14
|
+
export const DEVELOP_OPERATIONS=new Set(['advance','start','resume']);
|
|
15
|
+
// Operations that re-run the reviewed checks for completion.
|
|
16
|
+
const COMPLETION_OPERATIONS=new Set(['complete','advance','resume']);
|
|
17
|
+
|
|
18
|
+
// The run as its journal records it, or null for a create or an unreadable run.
|
|
19
|
+
function recordedRun(definition){
|
|
20
|
+
let specsRoot;try{specsRoot=fs.realpathSync(definition.specsDir);}catch{return null;}
|
|
21
|
+
try{
|
|
22
|
+
const snapshot=readExecutionSnapshot({specsRoot,identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});
|
|
23
|
+
const first=snapshot.records[0].payload;return readRunnerHistory(snapshot.records,first.config,first.version).state;
|
|
24
|
+
}catch{return null;}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The answer file the driver reads for this attempt (attemptAnswerName's rule,
|
|
28
|
+
// reported instead of exiting when both attempt-1 names exist).
|
|
29
|
+
function answerFile(answersDir,attempt){
|
|
30
|
+
if(attempt!==1)return {name:`develop-a${attempt}.json`};
|
|
31
|
+
const legacy=fs.existsSync(path.join(answersDir,'develop.json')),named=fs.existsSync(path.join(answersDir,'develop-a1.json'));
|
|
32
|
+
if(legacy&&named)return {error:'develop.json 与 develop-a1.json 不能同时存在;驾驶员会拒绝启动'};
|
|
33
|
+
return {name:named?'develop-a1.json':'develop.json'};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Which attempt's answer this step reads: attempt 1 on create; on resume the
|
|
37
|
+
// journal's own attempt, which the runner already advances to 2 when the first
|
|
38
|
+
// review requests changes (the driver reads develop-a2.json then).
|
|
39
|
+
export const answerAttempt=(mode,state)=>mode==='create'?1:state?state.attempt:null;
|
|
40
|
+
|
|
41
|
+
export function commanderPreflight(planFile,{operation,now=new Date().toISOString()}={}){
|
|
42
|
+
const findings=[];
|
|
43
|
+
let plan,definition;
|
|
44
|
+
try{({plan,definition}=loadStartInputs(planFile));}
|
|
45
|
+
catch(error){return {findings:[{level:'error',code:'plan_unreadable',message:error.message}]};}
|
|
46
|
+
// cm-start-check refuses some inputs with no verdict (invalid scope, modes it
|
|
47
|
+
// does not model). That refusal keeps its weight: it is an error here too.
|
|
48
|
+
try{findings.push(...startCheck(planFile));}
|
|
49
|
+
catch(error){findings.push({level:'error',code:'start_check_refused',message:`开工体检拒绝给出结论:${error.message}`});}
|
|
50
|
+
const state=plan.mode==='resume'?recordedRun(definition):null;
|
|
51
|
+
const base=path.dirname(path.resolve(planFile));
|
|
52
|
+
const answersDir=typeof plan.answers==='string'?path.resolve(base,plan.answers):null;
|
|
53
|
+
if(answersDir&&DEVELOP_OPERATIONS.has(operation)){
|
|
54
|
+
const attempt=answerAttempt(plan.mode,state);
|
|
55
|
+
if(attempt===null)findings.push({level:'info',code:'answer_check_skipped',message:'读不了原运行记录,没能确定本步用哪一轮的开发应答,已跳过应答核对'});
|
|
56
|
+
else{
|
|
57
|
+
const chosen=answerFile(answersDir,attempt);
|
|
58
|
+
if(chosen.error)findings.push({level:'error',code:'develop_answer_ambiguous',message:chosen.error});
|
|
59
|
+
else if(fs.existsSync(path.join(answersDir,chosen.name))){
|
|
60
|
+
let answer;try{answer=JSON.parse(fs.readFileSync(path.join(answersDir,chosen.name),'utf8'));}
|
|
61
|
+
catch{answer=null;findings.push({level:'error',code:'develop_answer_unreadable',message:`${chosen.name} 不是合法 JSON`});}
|
|
62
|
+
const tag=items=>items.map(item=>({...item,answer:chosen.name,message:`${chosen.name}:${item.message}`}));
|
|
63
|
+
if(answer){
|
|
64
|
+
findings.push(...tag(answerValueFindings(answer,{feature:definition.feature,identity:{...definition.identity,attempt}})));
|
|
65
|
+
// Only on create is the code root the delivery's own baseline; after a
|
|
66
|
+
// delivery the driver compares against the recorded baseline instead.
|
|
67
|
+
if(plan.mode==='create')findings.push(...tag(answerChangeFindings(answer,{answersDir,codeProject:definition.codeProject})));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let specsReadable=true;try{fs.realpathSync(definition.specsDir);}catch{specsReadable=false;}
|
|
73
|
+
if(specsReadable){
|
|
74
|
+
const registry=readRegistry(definition.specsDir),problem=registryProblem(registry);
|
|
75
|
+
if(problem)findings.push({level:'error',code:'registry_unreadable',message:`派活登记有问题(${problem}),不能确认设备是否空闲;先核对登记文件`});
|
|
76
|
+
findings.push(...deviceFindings(plan.checks,openDispatches(registry,now),{runId:definition.identity?.runId??null}));
|
|
77
|
+
}
|
|
78
|
+
// Completion re-runs the checks of the approved package of this attempt; only
|
|
79
|
+
// then must PLAN.checks equal them. A new delivery may use other checks.
|
|
80
|
+
if(state&&COMPLETION_OPERATIONS.has(operation)&&state.state==='approved'
|
|
81
|
+
&&state.reviewPackage?.identity?.attempt===state.attempt)
|
|
82
|
+
findings.push(...checksDriftFindings(plan.checks,state.reviewPackage.checks?.map(check=>({id:check.id,command:check.command}))));
|
|
83
|
+
return {findings};
|
|
84
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Commander CLI. ledger and preflight only read. dispatch writes only the
|
|
3
|
+
// commander's own registry under the CM home; nothing here writes tasks.md or a
|
|
4
|
+
// journal, starts a run, or grants anything.
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {fileURLToPath} from 'node:url';
|
|
7
|
+
import {buildLedger} from '../runtime/js/commander/ledger.mjs';
|
|
8
|
+
import {addDispatch,finishDispatch,readRegistry,openDispatches,registryProblem} from '../runtime/js/commander/dispatch-registry.mjs';
|
|
9
|
+
import {commanderPreflight} from './cm-commander-preflight.mjs';
|
|
10
|
+
|
|
11
|
+
const USAGE=`用法:
|
|
12
|
+
node scripts/cm-commander.mjs ledger --specs {dir} --code-project {dir} [--json] [--now ISO时间]
|
|
13
|
+
只读:汇总 tasks.md、各运行记录、运行日志与派活登记,给出唯一的下一步
|
|
14
|
+
node scripts/cm-commander.mjs preflight --plan {PLAN.json} --operation {将要执行的驾驶步骤} [--json]
|
|
15
|
+
只读:派活前体检(开工体检 + 本步要用的应答是否超限或无改动、设备占用、完成复查的检查漂移);有 error 退出 1
|
|
16
|
+
node scripts/cm-commander.mjs dispatch add --specs {dir} --label {说明} --deadline-minutes {分钟} [--run-id {id}] [--device {UDID}]
|
|
17
|
+
node scripts/cm-commander.mjs dispatch done --specs {dir} --id {登记号} [--outcome done|failed|abandoned]
|
|
18
|
+
node scripts/cm-commander.mjs dispatch list --specs {dir} [--json]
|
|
19
|
+
派出的活先登记截止时间,结束时登记结果;登记只写在 CM 目录下,不进 specs。
|
|
20
|
+
|
|
21
|
+
账本与体检都不建运行、不授权;每个运行的精确待办仍以它自己的 status 为准。`;
|
|
22
|
+
|
|
23
|
+
const STATUS={todo:'待做',in_run:'在跑',stopped:'停住',done:'完成',dropped:'作废'};
|
|
24
|
+
|
|
25
|
+
export function renderLedger(ledger){
|
|
26
|
+
const lines=[`specs: ${ledger.specsDir}`,`生成时间: ${ledger.generatedAt}(只读汇总,以各运行记录为准)`,''];
|
|
27
|
+
for(const feature of ledger.features){
|
|
28
|
+
const count=status=>feature.tasks.filter(task=>task.status===status).length;
|
|
29
|
+
lines.push(`[${feature.name}] 完成 ${count('done')},在跑 ${count('in_run')},停住 ${count('stopped')},待做 ${count('todo')},作废 ${count('dropped')}`
|
|
30
|
+
+(feature.error?`(tasks.md 读不了:${feature.error})`:''));
|
|
31
|
+
for(const task of feature.tasks.filter(task=>['in_run','stopped'].includes(task.status)))
|
|
32
|
+
lines.push(` ${task.id} ${STATUS[task.status]}:运行 ${task.runIds.join('、')},${task.verified?`${task.runState}/${task.runCode??"-"},第 ${task.attempt} 轮`+(task.pending?`,正在执行 ${task.pending}`:''):"状态未校验(本版本回放不了它的记录)"}`
|
|
33
|
+
+(task.idleMinutes===null?',无日志活动':`,${task.idleMinutes} 分钟前有活动`));
|
|
34
|
+
}
|
|
35
|
+
if(ledger.inconsistencies.length){lines.push('','不一致(以运行记录为准,需人工核对):');
|
|
36
|
+
for(const item of ledger.inconsistencies)lines.push(` - ${item.kind}:${item.feature} ${item.task} ${item.runId??item.runs?.join(',')??''}`);}
|
|
37
|
+
const unverified=ledger.runs.filter(run=>!run.verified).length;
|
|
38
|
+
if(unverified)lines.push('',`本版本回放不了记录的运行 ${unverified} 个:只展示任务归属;取代关系只认结构核验过的,完成声明不作数。`);
|
|
39
|
+
if(ledger.runsError)lines.push('',`读不了运行目录:${ledger.runsError}`);
|
|
40
|
+
if(ledger.otherRuns.some(run=>run.kind==='unreadable'))
|
|
41
|
+
lines.push('',`读不了的运行:${ledger.otherRuns.filter(run=>run.kind==='unreadable').map(run=>`${run.runId}(${run.code})`).join(',')}`);
|
|
42
|
+
const n=ledger.next;
|
|
43
|
+
lines.push('','下一步:'+(n.kind==='attend_run'?`处理 ${n.feature} ${n.task} 的运行 ${n.runId}——${n.why}`
|
|
44
|
+
:n.kind==='wait_run'?`等 ${n.feature} ${n.task} 的运行 ${n.runId}——${n.why}`:n.kind==='start_task'?`开始 ${n.feature} ${n.task}——${n.why}`
|
|
45
|
+
:n.kind==='check_records'?`核对运行记录——${n.why}`:n.kind==='overdue_dispatch'?`核对超时的活——${n.why}`
|
|
46
|
+
:n.kind==='wait_dispatch'?`等派出的活——${n.why}`:n.why),` 做法:${n.how}`);
|
|
47
|
+
if(ledger.queue.length)lines.push(` 之后还要处理:${ledger.queue.map(t=>t.runId??t.kind).join(',')}`);
|
|
48
|
+
return lines.join('\n');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const DECISION={wait:'等待',spec_change:'规格变更(需用户批准)',human_sync:'人工同步(需用户)',escalate:'交维护者',read_status:'先读 status 再定'};
|
|
52
|
+
function renderNext(ledger,lines){
|
|
53
|
+
const n=ledger.next;
|
|
54
|
+
if(n.decision)lines.push(` 决策:${DECISION[n.decision.decision]}——${n.decision.why}`,...n.decision.steps.map(step=>` · ${step}`),
|
|
55
|
+
...(n.decision.candidates.length?[` 可能的出口:${n.decision.candidates.join(';')}`]:[]));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const FLAGS={ledger:['--specs','--code-project','--now'],preflight:['--plan','--operation'],
|
|
59
|
+
'dispatch add':['--specs','--label','--deadline-minutes','--run-id','--device'],'dispatch done':['--specs','--id','--outcome'],
|
|
60
|
+
'dispatch list':['--specs','--now']};
|
|
61
|
+
function parse(argv){
|
|
62
|
+
const command=argv[0]==='dispatch'?`dispatch ${argv[1]}`:argv[0],rest=argv.slice(argv[0]==='dispatch'?2:1);
|
|
63
|
+
if(!FLAGS[command])return null;
|
|
64
|
+
const options={command,devices:[]};
|
|
65
|
+
for(let i=0;i<rest.length;i++){
|
|
66
|
+
const key=rest[i];
|
|
67
|
+
if(key==='--json'){options.json=true;continue;}
|
|
68
|
+
if(!FLAGS[command].includes(key)||rest[i+1]===undefined)return null;
|
|
69
|
+
if(key==='--device')options.devices.push(rest[++i]);else options[key.slice(2)]=rest[++i];
|
|
70
|
+
}
|
|
71
|
+
const required={ledger:['specs','code-project'],preflight:['plan','operation'],'dispatch add':['specs','label','deadline-minutes'],
|
|
72
|
+
'dispatch done':['specs','id'],'dispatch list':['specs']}[command];
|
|
73
|
+
return required.every(key=>options[key])?options:null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function main(argv){
|
|
77
|
+
const options=parse(argv);
|
|
78
|
+
if(!options)return {code:2,text:USAGE};
|
|
79
|
+
if(options.command==='ledger'){
|
|
80
|
+
const ledger=buildLedger({specsDir:path.resolve(options.specs),codeProject:path.resolve(options['code-project']),
|
|
81
|
+
...(options.now?{now:options.now}:{})});
|
|
82
|
+
if(options.json)return {code:0,text:JSON.stringify(ledger,null,2)};
|
|
83
|
+
const lines=renderLedger(ledger).split('\n');renderNext(ledger,lines);
|
|
84
|
+
return {code:0,text:lines.join('\n')};
|
|
85
|
+
}
|
|
86
|
+
if(options.command==='preflight'){
|
|
87
|
+
const {findings}=commanderPreflight(path.resolve(options.plan),{operation:options.operation});
|
|
88
|
+
const count=level=>findings.filter(item=>item.level===level).length,errors=count('error'),warns=count('warn'),skipped=count('info');
|
|
89
|
+
const summary=errors+warns?`派活前体检:${errors} 个 error,${warns} 个 warn`+(skipped?`,另有 ${skipped} 项跳过`:'')
|
|
90
|
+
:skipped?`派活前体检完成:已核对的项目没有阻塞,但有 ${skipped} 项跳过,见上`:'派活前体检通过:没有发现可提前识别的阻塞';
|
|
91
|
+
const text=options.json?JSON.stringify({errors,warns,skipped,findings}):[...findings.map(item=>`[${item.level}] ${item.code}: ${item.message}`),summary].join('\n');
|
|
92
|
+
return {code:errors?1:0,text};
|
|
93
|
+
}
|
|
94
|
+
const specs=path.resolve(options.specs);
|
|
95
|
+
if(options.command==='dispatch add'){
|
|
96
|
+
const minutes=Number(options['deadline-minutes']);
|
|
97
|
+
const {id,deadline}=addDispatch(specs,{label:options.label,deadlineMinutes:Number.isInteger(minutes)?minutes:NaN,
|
|
98
|
+
runId:options['run-id']??null,resources:options.devices.map(device=>`device:${device}`)});
|
|
99
|
+
return {code:0,text:options.json?JSON.stringify({id,deadline}):`已登记 ${id},截止 ${deadline}`};
|
|
100
|
+
}
|
|
101
|
+
if(options.command==='dispatch done'){
|
|
102
|
+
finishDispatch(specs,{id:options.id,...(options.outcome?{outcome:options.outcome}:{})});
|
|
103
|
+
return {code:0,text:`已登记结束 ${options.id}`};
|
|
104
|
+
}
|
|
105
|
+
const registry=readRegistry(specs),open=openDispatches(registry,options.now??new Date().toISOString()),problem=registryProblem(registry);
|
|
106
|
+
if(options.json)return {code:problem?1:0,text:JSON.stringify({open,invalidLines:registry.invalid,torn:registry.torn,error:registry.error,problem})};
|
|
107
|
+
if(problem)return {code:1,text:`派活登记有问题(${problem}),下面只列出能读到的记录,不能当作完整:\n`
|
|
108
|
+
+(open.map(job=>`${job.overdue?'[超时]':'[进行]'} ${job.id} ${job.label},截止 ${job.deadline}`).join('\n')||'(没有能读到的未结束记录)')};
|
|
109
|
+
return {code:0,text:open.length?open.map(job=>`${job.overdue?'[超时]':'[进行]'} ${job.id} ${job.label},截止 ${job.deadline}`
|
|
110
|
+
+(job.resources.length?`,占用 ${job.resources.join('、')}`:'')).join('\n'):'没有未结束的登记'};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url)){
|
|
114
|
+
try{const {code,text}=main(process.argv.slice(2));(code===0?process.stdout:process.stderr).write(text+'\n');process.exitCode=code;}
|
|
115
|
+
catch(error){process.stderr.write(`cm-commander: ${error.code??error.message}\n`);process.exitCode=1;}
|
|
116
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// One lock per host config file, shared by every CM script that edits it
|
|
2
|
+
// (cm-announce-hook, cm-skill-hints enable). Re-reading, merging and replacing
|
|
3
|
+
// happen inside the lock, so two CM writers never overwrite each other. Writers
|
|
4
|
+
// outside CM do not take it; callers still compare bytes before replacing.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import crypto from 'node:crypto';
|
|
9
|
+
|
|
10
|
+
const STALE_MS=30000;
|
|
11
|
+
export const lockPath=(env,file)=>path.join(path.resolve(env.CM_WORKFLOW_HOME||path.join(env.HOME||os.homedir(),'.cm-workflow')),
|
|
12
|
+
'locks',`${crypto.createHash('sha256').update(path.resolve(file)).digest('hex').slice(0,16)}.lock`);
|
|
13
|
+
const pause=ms=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,ms);
|
|
14
|
+
|
|
15
|
+
export class LockBusy extends Error{}
|
|
16
|
+
|
|
17
|
+
// Runs fn while holding the lock; throws LockBusy after waitMs. A lock left by a
|
|
18
|
+
// crashed writer is taken over once it is older than STALE_MS.
|
|
19
|
+
export function withConfigLock(env,file,fn,{waitMs=3000,now=()=>Date.now()}={}){
|
|
20
|
+
const lock=lockPath(env,file);
|
|
21
|
+
fs.mkdirSync(path.dirname(lock),{recursive:true});
|
|
22
|
+
const deadline=now()+waitMs;
|
|
23
|
+
let fd;
|
|
24
|
+
for(;;){
|
|
25
|
+
try{fd=fs.openSync(lock,'wx',0o600);break;}
|
|
26
|
+
catch(error){
|
|
27
|
+
if(error.code!=='EEXIST')throw error;
|
|
28
|
+
try{if(now()-fs.lstatSync(lock).mtimeMs>STALE_MS){fs.unlinkSync(lock);continue;}}catch{/* 刚被释放 */}
|
|
29
|
+
if(now()>=deadline)throw new LockBusy();
|
|
30
|
+
pause(50);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
try{fs.writeSync(fd,String(process.pid));return fn();}
|
|
34
|
+
finally{fs.closeSync(fd);try{fs.unlinkSync(lock);}catch{/* 已被接管 */}}
|
|
35
|
+
}
|
|
@@ -312,16 +312,25 @@ test('structured review rejects missing fields, extra prose, duplicate keys, inv
|
|
|
312
312
|
JSON.stringify(valid)+'\nP2 remains unresolved.',
|
|
313
313
|
'Zero findings.\n'+JSON.stringify(valid),
|
|
314
314
|
'{"conclusion":"Zero findings.","findings":[],"findings":[],"resolved_findings":[]}',
|
|
315
|
+
// 通过通用门禁、但要由补正门禁拦下:结论必须逐字是 Zero findings.
|
|
316
|
+
{...valid,conclusion:'结论:零阻塞发现。'},
|
|
315
317
|
];
|
|
316
318
|
for(const body of malformed){
|
|
317
319
|
f.review(record.review,record.handoff,2,'approved',record.correction_sha256);
|
|
318
320
|
reviewBody(record.review,typeof body==='string'?body:JSON.stringify(body));
|
|
319
|
-
|
|
321
|
+
// 这两种正文第一行不是零阻塞结论,通用门禁先拒绝;其余由补正门禁拒绝。
|
|
322
|
+
const generic=[JSON.stringify(valid)+'\nP2 remains unresolved.',JSON.stringify({...valid,conclusion:'Zero findings. P2 remains unresolved.'})];
|
|
323
|
+
const expected=generic.includes(typeof body==='string'?body:JSON.stringify(body))?/explicitly state zero blocking findings/:/controlled correction/;
|
|
324
|
+
assert.throws(()=>publishControlledCorrectionReview(selected),expected,String(typeof body==='string'?body:JSON.stringify(body)));
|
|
320
325
|
}
|
|
321
326
|
f.review(record.review,record.handoff,2,'blocked',record.correction_sha256);
|
|
322
327
|
reviewBody(record.review,JSON.stringify({conclusion:'Blocking findings.',
|
|
323
328
|
findings:[{id:'P1-1',priority:'P1',evidence:'one'},{id:'P2-2',priority:'P2',evidence:'two'}],resolved_findings:[]}));
|
|
324
329
|
assert.throws(()=>publishControlledCorrectionReview(selected),/finding count/);
|
|
330
|
+
// blocked 不查零阻塞结论,严格 JSON 解析器的「JSON 后不得附带散文」检查在这里仍被覆盖。
|
|
331
|
+
f.review(record.review,record.handoff,2,'blocked',record.correction_sha256);
|
|
332
|
+
reviewBody(record.review,JSON.stringify({conclusion:'Blocking findings.',findings:[{id:'P2-1',priority:'P2',evidence:'one'}],resolved_findings:[]})+'\nP2 remains unresolved.');
|
|
333
|
+
assert.throws(()=>publishControlledCorrectionReview(selected),/strict structured findings JSON body/);
|
|
325
334
|
});
|
|
326
335
|
|
|
327
336
|
test('history, implementation, finalized handoff, record, review and receipt tampering invalidate completion',t=>{
|