@aibyzero/cm-workflow 0.17.0 → 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 +27 -0
- package/CHANGELOG.md +230 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +21 -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 +40 -13
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +153 -16
- 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 +94 -21
- 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 +24 -6
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +236 -34
- 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 +14 -6
- 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 +42 -9
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +22 -9
- 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 +63 -30
- 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 +247 -41
- 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 +38 -17
- 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 +12 -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 +27 -14
- 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 +483 -63
- 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 +82 -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-bootstrap-rules.test.mjs +3 -2
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +37 -5
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host-fixture.mjs +9 -6
- package/scripts/cm-ai-host-protected.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-host.test.mjs +15 -0
- 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 +71 -0
- 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-review-timeout.test.mjs +20 -0
- 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 +2 -2
- package/scripts/cm-check-host.test.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-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +49 -0
- package/scripts/cm-claude-worker.test.mjs +16 -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-drive-liveness.test.mjs +83 -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 +12 -9
- 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-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-host-stage-observer.test.mjs +41 -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 +625 -75
- 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 +46 -2
- 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 +16 -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-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +55 -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 +3 -15
- 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-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -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/host-diagnostic.mjs +33 -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 +89 -17
- 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,265 @@
|
|
|
1
|
+
// Commander phase 1: a read-only campaign ledger. It summarizes tasks.md, every
|
|
2
|
+
// run journal and the project log into one table and one next step. Each run's
|
|
3
|
+
// own journal stays the authority: nothing here writes, locks, dispatches or
|
|
4
|
+
// grants. Live-only status (pendingAction) is not recomputed; the ledger names
|
|
5
|
+
// the run and says to read its status through the run's own driver.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import {readExecutionSnapshot} from '../cm-ai/execution-snapshot.mjs';
|
|
9
|
+
import {readRunnerHistory} from '../cm-ai/durable-runner-state.mjs';
|
|
10
|
+
import {inspectCmAiAdmission,parseFeatureTaskText,validDependencies} from '../cm-ai/cm-ai-admission.mjs';
|
|
11
|
+
import {approvedTaskGrammar} from '../spec-task-line.mjs';
|
|
12
|
+
import {readEvidenceSupersession} from '../cm-ai/reviewed-evidence-supersession-record.mjs';
|
|
13
|
+
import {readRegistry,openDispatches,registryProblem} from './dispatch-registry.mjs';
|
|
14
|
+
import {decideRecovery} from './decision.mjs';
|
|
15
|
+
|
|
16
|
+
export const LEDGER_VERSION=1;
|
|
17
|
+
export const IDLE_MINUTES=45;
|
|
18
|
+
const LOG_LIMIT=64*1024*1024;
|
|
19
|
+
const STOPPED=['blocked','unknown','cancelled'];
|
|
20
|
+
const slug=feature=>feature.replace(/^\d+\./,'');
|
|
21
|
+
const at=value=>{const t=Date.parse(value);return Number.isFinite(t)?t:null;};
|
|
22
|
+
|
|
23
|
+
// Last event per run_id. A malformed line is counted, never guessed at.
|
|
24
|
+
export function readLogEvents(specsDir){
|
|
25
|
+
const file=path.join(specsDir,'运行日志.jsonl'),runs=new Map();let invalid=0;
|
|
26
|
+
let stat;try{stat=fs.lstatSync(file);}catch{return {runs,invalid,present:false};}
|
|
27
|
+
if(!stat.isFile()||stat.size>LOG_LIMIT)return {runs,invalid,present:false,unreadable:true};
|
|
28
|
+
for(const line of fs.readFileSync(file,'utf8').split('\n')){
|
|
29
|
+
if(!line.trim())continue;
|
|
30
|
+
let row;try{row=JSON.parse(line);}catch{invalid++;continue;}
|
|
31
|
+
if(typeof row?.run_id!=='string'||at(row.at)===null){invalid++;continue;}
|
|
32
|
+
const prior=runs.get(row.run_id);
|
|
33
|
+
const entry={at:row.at,event:row.event??null,detail:typeof row.detail==='string'?row.detail.slice(0,200):null,
|
|
34
|
+
workflow:row.workflow??null,feature:row.feature??null,task:row.task??null,
|
|
35
|
+
runDone:Boolean(prior?.runDone)||row.event==='run_done'};
|
|
36
|
+
if(!prior||at(row.at)>=at(prior.at))runs.set(row.run_id,entry);else if(entry.runDone)prior.runDone=true;
|
|
37
|
+
}
|
|
38
|
+
return {runs,invalid,present:true};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Hints from the records: which task a run belongs to, whom it claims to have
|
|
42
|
+
// superseded and whether it journaled a task commit. For a run this runtime
|
|
43
|
+
// cannot replay they are display only, never a basis for a decision.
|
|
44
|
+
export function rawHints(records){
|
|
45
|
+
const first=records[0]?.payload??{},config=first.config??{};
|
|
46
|
+
const tasksPath=config.completion?.owner?.tasksPath;
|
|
47
|
+
const superseded=records.find(r=>r?.payload?.type==='evidence-superseded')?.payload?.record?.previousRunIds;
|
|
48
|
+
return {feature:typeof tasksPath==='string'?path.basename(path.dirname(tasksPath)):config.taskLearning?.feature??null,
|
|
49
|
+
taskId:config.identity?.taskId??null,previousRunIds:Array.isArray(superseded)?superseded.filter(id=>typeof id==='string'):[],
|
|
50
|
+
committed:records.some(r=>r?.payload?.type==='task-commit-result')};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// A run whose hash chain verifies but whose later records this runtime cannot
|
|
54
|
+
// replay may still prove its supersession: the record must sit where replay
|
|
55
|
+
// requires it (the second record), pass the shared record validator, and name
|
|
56
|
+
// this run and its own feature and task. Anything less proves nothing.
|
|
57
|
+
export function checkedSupersession(records,runId,hints){
|
|
58
|
+
const record=records[1]?.payload;
|
|
59
|
+
if(record?.type!=='evidence-superseded'||records[1].kind!=='result')return [];
|
|
60
|
+
try{
|
|
61
|
+
const value=readEvidenceSupersession(record.record,{feature:hints.feature,taskId:hints.taskId,newRunId:runId});
|
|
62
|
+
return [...value.previousRunIds];
|
|
63
|
+
}catch{return [];}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The start of a run must bind together before any of its later records is
|
|
67
|
+
// believed: the validated snapshot identity, the init identity, and one feature
|
|
68
|
+
// named by both the task path and the learning binding.
|
|
69
|
+
export function originBound(records,snapshot,runId){
|
|
70
|
+
const first=records[0],config=first?.payload?.config;
|
|
71
|
+
const tasksPath=config?.completion?.owner?.tasksPath,feature=config?.taskLearning?.feature;
|
|
72
|
+
return first?.kind==='result'&&first.payload.version===3&&first.payload.type==='init'
|
|
73
|
+
&&snapshot?.identity?.runId===runId&&config?.identity?.runId===runId
|
|
74
|
+
&&config.identity.repositoryId===snapshot.identity.repositoryId&&typeof config.identity.taskId==='string'
|
|
75
|
+
&&typeof tasksPath==='string'&&typeof feature==='string'&&path.basename(path.dirname(tasksPath))===feature;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// One summary per run directory. Unreadable or unknown runs are kept, and they
|
|
79
|
+
// stop the ledger from claiming that no run is in flight.
|
|
80
|
+
export function readRuns(specsDir){
|
|
81
|
+
const root=path.join(specsDir,'.reviews','.execution'),runs=[];
|
|
82
|
+
let names;
|
|
83
|
+
try{names=fs.readdirSync(root,{withFileTypes:true}).filter(e=>e.isDirectory()).map(e=>e.name).sort();}
|
|
84
|
+
catch(error){return {runs,error:error.code==='ENOENT'?null:(error.code??'read_failed')};}
|
|
85
|
+
for(const runId of names){
|
|
86
|
+
const file=path.join(root,runId,'state.json');
|
|
87
|
+
// Only a confirmed ENOENT is an empty residue; EACCES, EIO and the like are
|
|
88
|
+
// unknown, so they must not read as "no run here".
|
|
89
|
+
try{fs.lstatSync(file);}catch(error){
|
|
90
|
+
runs.push(error.code==='ENOENT'?{runId,kind:'empty'}:{runId,kind:'unreadable',code:error.code??'read_failed'});continue;}
|
|
91
|
+
let raw;
|
|
92
|
+
try{raw=JSON.parse(fs.readFileSync(file,'utf8'));}catch{runs.push({runId,kind:'unreadable',code:'store_corrupt'});continue;}
|
|
93
|
+
let snapshot=null,integrity=null;
|
|
94
|
+
try{snapshot=readExecutionSnapshot({specsRoot:specsDir,identity:{repositoryId:raw?.identity?.repositoryId,runId}});}
|
|
95
|
+
catch(error){integrity=typeof error.code==='string'?error.code:'read_failed';}
|
|
96
|
+
const records=snapshot?snapshot.records:Array.isArray(raw?.records)?raw.records:[],first=records[0]?.payload;
|
|
97
|
+
if(first?.workflow==='cm-fix-stages-v1'&&snapshot){runs.push({runId,kind:'cm-fix',records:records.length});continue;}
|
|
98
|
+
if(first?.protocol!=='cm-task-runner'||first.type!=='init'||!snapshot&&first?.workflow){
|
|
99
|
+
runs.push({runId,kind:'unreadable',code:integrity??'unknown_workflow'});continue;}
|
|
100
|
+
const hints=rawHints(records);
|
|
101
|
+
if(snapshot)try{
|
|
102
|
+
const history=readRunnerHistory(records,first.config,first.version);
|
|
103
|
+
runs.push({runId,kind:'cm-ai',verified:true,feature:hints.feature,taskId:hints.taskId,state:history.state.state,
|
|
104
|
+
code:history.state.code??null,attempt:history.state.attempt,pending:history.pending?.kind??null,
|
|
105
|
+
committed:history.state.taskCommit!=null||hints.committed,trustedPrevious:history.supersession?.previousRunIds??[],
|
|
106
|
+
claimedPrevious:hints.previousRunIds,records:records.length});
|
|
107
|
+
continue;
|
|
108
|
+
}catch(error){integrity=null;runs.push({runId,kind:'cm-ai',verified:false,chainVerified:true,feature:hints.feature,taskId:hints.taskId,
|
|
109
|
+
state:null,code:null,attempt:null,pending:null,committed:false,committedClaim:hints.committed,
|
|
110
|
+
trustedPrevious:originBound(records,snapshot,runId)?checkedSupersession(records,runId,hints):[],claimedPrevious:hints.previousRunIds,records:records.length,
|
|
111
|
+
unverifiedReason:typeof error.code==='string'?error.code:'read_failed'});continue;}
|
|
112
|
+
runs.push({runId,kind:'cm-ai',verified:false,chainVerified:false,feature:hints.feature,taskId:hints.taskId,state:null,code:null,
|
|
113
|
+
attempt:null,pending:null,committed:false,committedClaim:hints.committed,trustedPrevious:[],claimedPrevious:hints.previousRunIds,
|
|
114
|
+
records:records.length,unverifiedReason:integrity});
|
|
115
|
+
}
|
|
116
|
+
return {runs,error:null};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function readFeatureTasks(specsDir,names){
|
|
120
|
+
const grammar=approvedTaskGrammar(specsDir);
|
|
121
|
+
return names.map(name=>{
|
|
122
|
+
let text;try{text=fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8');}
|
|
123
|
+
catch{return {name,error:'tasks_missing',tasks:[]};}
|
|
124
|
+
const parsed=parseFeatureTaskText(text,{allowDependencyPunctuation:true,grammar});
|
|
125
|
+
if(parsed.error)return {name,error:parsed.error,tasks:[]};
|
|
126
|
+
if(!validDependencies(parsed.tasks,parsed.dependencies))return {name,error:'dependencies_invalid',tasks:[]};
|
|
127
|
+
return {name,tasks:parsed.tasks.map(task=>({id:task.id,completed:task.completed,dropped:task.dropped,
|
|
128
|
+
dependsOn:parsed.dependencies.get(task.id)??[]}))};
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Phases. pending means an effect is journaled but not yet checkpointed: the
|
|
133
|
+
// run is executing, not stopped, even though replay projects it as unknown.
|
|
134
|
+
const runPhase=run=>!run.verified?'unverified':run.committed?'committed':run.pending?'executing'
|
|
135
|
+
:STOPPED.includes(run.state)?'stopped':run.state==='fixture_completed'?'finishing':'in_progress';
|
|
136
|
+
const OPEN=['executing','in_progress','stopped','unverified'];
|
|
137
|
+
const sameTask=(a,b)=>slug(a.feature??'')===slug(b.feature??'')&&a.taskId===b.taskId;
|
|
138
|
+
|
|
139
|
+
// Pure composition, so every rule is testable without a disk fixture.
|
|
140
|
+
export function composeLedger({specsDir,admission,features,runs,runsError=null,log,now,dispatches=[],registryError=null}){
|
|
141
|
+
const nowMs=at(now);if(nowMs===null)throw Object.assign(new Error('invalid_now'),{code:'invalid_now'});
|
|
142
|
+
const inconsistencies=[],byId=new Map(runs.filter(r=>r.kind==='cm-ai').map(r=>[r.runId,r]));
|
|
143
|
+
// Only a replayed or structurally checked supersession retires a run, and only
|
|
144
|
+
// when the predecessor is a run of the same task.
|
|
145
|
+
const supersededBy=new Map();
|
|
146
|
+
for(const run of byId.values()){
|
|
147
|
+
for(const previous of run.trustedPrevious??[]){
|
|
148
|
+
const prior=byId.get(previous);
|
|
149
|
+
if(prior&&!sameTask(prior,run)){inconsistencies.push({kind:'supersession_task_mismatch',runId:run.runId,previous});continue;}
|
|
150
|
+
supersededBy.set(previous,run.runId);
|
|
151
|
+
}
|
|
152
|
+
for(const previous of run.claimedPrevious??[])if(!(run.trustedPrevious??[]).includes(previous)&&byId.has(previous))
|
|
153
|
+
inconsistencies.push({kind:'unverified_supersession',feature:run.feature,task:run.taskId,runId:run.runId,previous});
|
|
154
|
+
}
|
|
155
|
+
const taskOf=new Map(features.flatMap(f=>f.tasks.map(t=>[`${slug(f.name)}/${t.id}`,{feature:f.name,...t}])));
|
|
156
|
+
const ai=[...byId.values()].map(run=>{
|
|
157
|
+
const last=log.runs.get(run.runId)??null;
|
|
158
|
+
return {...run,phase:runPhase(run),supersededBy:supersededBy.get(run.runId)??null,
|
|
159
|
+
lastEventAt:last?.at??null,lastEvent:last?.detail??last?.event??null,runDone:last?.runDone??false,
|
|
160
|
+
idleMinutes:last?Math.floor((nowMs-at(last.at))/60000):null};
|
|
161
|
+
});
|
|
162
|
+
// Open runs: every run not retired by a trusted supersession whose phase is
|
|
163
|
+
// still open. Whether one on a checked task is history is decided below, on
|
|
164
|
+
// evidence only, never on the checkmark or log age alone.
|
|
165
|
+
const open=ai.filter(run=>run.supersededBy===null&&OPEN.includes(run.phase));
|
|
166
|
+
// A run of a checked or dropped task is history only with evidence that
|
|
167
|
+
// nothing is in flight and no activity is recent: a verified terminal state
|
|
168
|
+
// with no journaled-but-unfinished effect, or an intact chain that journaled
|
|
169
|
+
// the task commit. Pending effects, recent activity and anything unproven stay
|
|
170
|
+
// open, so they are waited on or checked.
|
|
171
|
+
const quiet=run=>run.idleMinutes===null||run.idleMinutes>=IDLE_MINUTES;
|
|
172
|
+
const history=run=>{
|
|
173
|
+
const task=taskOf.get(`${slug(run.feature??'')}/${run.taskId}`);
|
|
174
|
+
if(!task||!(task.completed||task.dropped)||!quiet(run))return false;
|
|
175
|
+
return run.verified?run.phase==='stopped':run.chainVerified===true&&run.committedClaim===true;
|
|
176
|
+
};
|
|
177
|
+
for(const run of open){
|
|
178
|
+
const task=taskOf.get(`${slug(run.feature??'')}/${run.taskId}`);
|
|
179
|
+
if(task?.completed&&run.verified)inconsistencies.push({kind:'checked_with_open_run',feature:task.feature,task:task.id,runId:run.runId});
|
|
180
|
+
}
|
|
181
|
+
const settledHistory=new Set(open.filter(history).map(run=>run.runId));
|
|
182
|
+
const table=features.map(feature=>({name:feature.name,error:feature.error??null,tasks:feature.tasks.map(task=>{
|
|
183
|
+
const mine=open.filter(run=>!settledHistory.has(run.runId)&&sameTask(run,{feature:feature.name,taskId:task.id}));
|
|
184
|
+
if(mine.length>1)inconsistencies.push({kind:'multiple_open_runs',feature:feature.name,task:task.id,runs:mine.map(r=>r.runId)});
|
|
185
|
+
const committed=ai.find(run=>run.supersededBy===null&&run.verified&&run.committed&&sameTask(run,{feature:feature.name,taskId:task.id}));
|
|
186
|
+
if(!task.completed&&!task.dropped&&committed)
|
|
187
|
+
inconsistencies.push({kind:'commit_without_check',feature:feature.name,task:task.id,runId:committed.runId});
|
|
188
|
+
const shown=[...mine].sort((a,b)=>(at(b.lastEventAt)??0)-(at(a.lastEventAt)??0))[0]??null;
|
|
189
|
+
const status=task.dropped?'dropped':task.completed?'done':mine.some(r=>r.phase==='stopped')?'stopped':mine.length?'in_run':'todo';
|
|
190
|
+
return {id:task.id,status,dependsOn:task.dependsOn,runIds:mine.map(r=>r.runId),runId:shown?.runId??null,
|
|
191
|
+
verified:shown?.verified??null,runState:shown?.state??null,runCode:shown?.code??null,attempt:shown?.attempt??null,
|
|
192
|
+
pending:shown?.pending??null,lastEventAt:shown?.lastEventAt??null,idleMinutes:shown?.idleMinutes??null};
|
|
193
|
+
})}));
|
|
194
|
+
// One queue over all open runs and unknown records, then a single next step.
|
|
195
|
+
const how='用该运行的原 PLAN 执行 cm-ai-drive.mjs status,按返回的 pendingAction 处理;账本不重算待办';
|
|
196
|
+
const note=run=>run.verified?'':'(本版本回放不了它的记录,状态未校验)';
|
|
197
|
+
const queue=[];
|
|
198
|
+
for(const run of open){
|
|
199
|
+
const task=taskOf.get(`${slug(run.feature??'')}/${run.taskId}`);
|
|
200
|
+
const base={kind:'attend_run',feature:run.feature,task:run.taskId,runId:run.runId,how,decision:decideRecovery(run)};
|
|
201
|
+
if(settledHistory.has(run.runId))continue;
|
|
202
|
+
if(task?.completed||task?.dropped){
|
|
203
|
+
queue.push({rank:0,...base,why:`任务已${task.completed?'勾选':'作废'},但运行`+(run.pending?`留着未结的 ${run.pending}`
|
|
204
|
+
:!quiet(run)?` ${run.idleMinutes} 分钟前还有活动`:'没有可核验的结束记录')+note(run)});
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if(run.phase==='stopped')queue.push({rank:0,...base,why:`运行停在 ${run.state}/${run.code}`});
|
|
208
|
+
else if(run.idleMinutes===null)queue.push({rank:2,...base,why:'运行没有日志活动记录'+note(run)});
|
|
209
|
+
else if(run.idleMinutes>=IDLE_MINUTES)queue.push({rank:2,...base,idle:run.idleMinutes,
|
|
210
|
+
why:`运行${run.pending?`有未结的 ${run.pending},`:''} ${run.idleMinutes} 分钟没有新日志`+note(run)});
|
|
211
|
+
else queue.push({rank:3,kind:'wait_run',feature:run.feature,task:run.taskId,runId:run.runId,idle:run.idleMinutes,
|
|
212
|
+
why:`运行${run.pending?`正在执行 ${run.pending},`:''} ${run.idleMinutes} 分钟前还有活动`+note(run),
|
|
213
|
+
how:`等它推进;超过 ${IDLE_MINUTES} 分钟没有新日志再处理`});
|
|
214
|
+
}
|
|
215
|
+
const unknown=runs.filter(run=>run.kind==='unreadable');
|
|
216
|
+
if(runsError)queue.push({rank:1,kind:'check_records',why:`读不了运行目录(${runsError}),不能确认有没有在途运行`,
|
|
217
|
+
how:'先查 .reviews/.execution 的权限与内容;确认前不建新运行'});
|
|
218
|
+
for(const run of unknown)queue.push({rank:1,kind:'check_records',runId:run.runId,
|
|
219
|
+
why:`运行 ${run.runId} 的记录读不了(${run.code}),不能确认它是否在途`,how:'先人工核对该运行记录;确认前不建新运行'});
|
|
220
|
+
for(const item of inconsistencies.filter(i=>i.kind==='unverified_supersession'))queue.push({rank:1,kind:'check_records',
|
|
221
|
+
runId:item.runId,feature:item.feature,task:item.task,why:`${item.runId} 声称取代 ${item.previous},但这条取代没法核验`,
|
|
222
|
+
how:'人工核对两条运行记录;核对前两者都视为在途'});
|
|
223
|
+
// Registered jobs: past its deadline a job is checked first, since whatever it
|
|
224
|
+
// was waiting on may have hung; an unreadable registry is never "no jobs".
|
|
225
|
+
for(const job of dispatches.filter(job=>job.overdue))queue.push({rank:0,kind:'overdue_dispatch',dispatchId:job.id,runId:job.runId,
|
|
226
|
+
why:`派出的活「${job.label}」已超过截止时间 ${job.overdueMinutes} 分钟,仍未登记结束`,
|
|
227
|
+
how:'看它的输出或进程:结束了就 dispatch done 登记结果;卡住了先停掉再决定是否重派'});
|
|
228
|
+
if(registryError)queue.push({rank:1,kind:'check_records',why:`派活登记读不了(${registryError}),不能确认有没有在途的活`,
|
|
229
|
+
how:'先核对 CM 目录下的 commander 登记文件;确认前不派新活'});
|
|
230
|
+
for(const job of dispatches.filter(job=>!job.overdue))queue.push({rank:3,kind:'wait_dispatch',dispatchId:job.id,runId:job.runId,
|
|
231
|
+
idle:0,why:`派出的活「${job.label}」还没到截止时间(${job.deadline})`,how:'等它结束;到期仍未结束再处理'});
|
|
232
|
+
queue.sort((a,b)=>a.rank-b.rank||(a.rank===3?(a.idle??0)-(b.idle??0):(b.idle??0)-(a.idle??0)));
|
|
233
|
+
const reason=admission.reason??admission.code??null;
|
|
234
|
+
let next;
|
|
235
|
+
if(queue.length){const {rank,idle,...first}=queue[0];next=first;}
|
|
236
|
+
else if(admission.state==='ready')next={kind:'start_task',feature:admission.nextTask.feature,task:admission.nextTask.id,
|
|
237
|
+
why:'没有在途运行;admission 选出的下一个任务',how:'按 cm-ai 流程为该任务建运行'};
|
|
238
|
+
else if(admission.state==='complete')next={kind:'finish',why:'全部任务已完成或作废',how:'按 cm-ai 收尾流程处理 QA 与 run_done'};
|
|
239
|
+
else next={kind:'admission_blocked',reason,why:`admission 返回 ${admission.state}/${reason}`,
|
|
240
|
+
how:'先按 admission 的原因处理(规格审批、漂移、依赖等)'};
|
|
241
|
+
const others=runs.filter(run=>run.kind!=='cm-ai').map(run=>({runId:run.runId,kind:run.kind,...(run.code?{code:run.code}:{})}));
|
|
242
|
+
return {version:LEDGER_VERSION,specsDir,generatedAt:new Date(nowMs).toISOString(),authority:'journal',
|
|
243
|
+
admission:{state:admission.state,reason,nextTask:admission.nextTask??null,...(admission.detail?{detail:admission.detail}:{}),
|
|
244
|
+
warnings:admission.warnings??[]},
|
|
245
|
+
features:table,runs:ai,otherRuns:others,runsError,inconsistencies,dispatches,registryError,
|
|
246
|
+
queue:queue.slice(1).map(({rank,idle,...item})=>item),log:{present:log.present,invalidLines:log.invalid},next};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// The registry as the ledger sees it: open jobs, and any health problem, which
|
|
250
|
+
// keeps the ledger from reading a torn or partly unreadable registry as empty.
|
|
251
|
+
export function registryInput(specsDir,now){
|
|
252
|
+
const registry=readRegistry(specsDir);
|
|
253
|
+
return {dispatches:openDispatches(registry,now),registryError:registryProblem(registry)};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function buildLedger({specsDir,codeProject,now=new Date().toISOString()}){
|
|
257
|
+
const root=fs.realpathSync(specsDir);
|
|
258
|
+
const admission=inspectCmAiAdmission({specsDir:root,codeProject});
|
|
259
|
+
const names=fs.readdirSync(root,{withFileTypes:true}).filter(e=>e.isDirectory()&&/^\d+\.[A-Za-z0-9]/.test(e.name)
|
|
260
|
+
&&fs.existsSync(path.join(root,e.name,'tasks.md'))).map(e=>e.name)
|
|
261
|
+
.sort((a,b)=>Number(a.split('.')[0])-Number(b.split('.')[0])||(a<b?-1:1));
|
|
262
|
+
const {runs,error}=readRuns(root);
|
|
263
|
+
return composeLedger({specsDir:root,admission,features:readFeatureTasks(root,names),runs,runsError:error,
|
|
264
|
+
log:readLogEvents(root),now,...registryInput(root,now)});
|
|
265
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Commander phase 2: checks run before a job is dispatched, for the failures the
|
|
2
|
+
// aihot reopen record showed were knowable in advance and that neither the
|
|
3
|
+
// driver's own preflight nor cm-start-check catches yet:
|
|
4
|
+
// - a develop answer over a bound (application.note, retrospective fields)
|
|
5
|
+
// that the host would refuse only after dispatch;
|
|
6
|
+
// - a develop answer that changes nothing, which the runner only reports as
|
|
7
|
+
// develop_empty_changes after the delivery and checks have run;
|
|
8
|
+
// - a simulator already held by another registered job, or one check that
|
|
9
|
+
// drives several simulators in parallel;
|
|
10
|
+
// - resume checks that differ from the checks recorded for the reviewed
|
|
11
|
+
// package, which completion refuses as a package mismatch.
|
|
12
|
+
// Every function here only reads; a finding is advice, the runner stays the authority.
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import {createCmAiTaskLearningApplication,createCmAiTaskLearningRetrospective} from '../cm-ai/cm-ai-context-refresh.mjs';
|
|
16
|
+
|
|
17
|
+
const finding=(level,code,message,extra={})=>({level,code,message,...extra});
|
|
18
|
+
const fileBytes=file=>{try{return fs.readFileSync(file);}catch{return null;}};
|
|
19
|
+
|
|
20
|
+
// The answer bounds, applied with the same constructors the host uses. The
|
|
21
|
+
// binding is a stand-in: only the answer's own fields are being judged.
|
|
22
|
+
export function answerValueFindings(answer,{feature,identity}){
|
|
23
|
+
if(answer?.status!=='succeeded'||answer.value?.outcome!=='implemented')return [];
|
|
24
|
+
const binding={feature,identity:{...identity,attempt:identity.attempt??1},learningDigest:'0'.repeat(64)};
|
|
25
|
+
const findings=[];
|
|
26
|
+
for(const [part,make] of [['application',createCmAiTaskLearningApplication],['retrospective',createCmAiTaskLearningRetrospective]]){
|
|
27
|
+
if(!Object.hasOwn(answer.value,part))continue;
|
|
28
|
+
try{make({...binding,...answer.value[part]});}
|
|
29
|
+
catch(error){
|
|
30
|
+
const note=answer.value.application?.note;
|
|
31
|
+
const detail=part==='application'&&typeof note==='string'&¬e.length>512
|
|
32
|
+
?`application.note 有 ${note.length} 个字符(UTF-16 计,emoji 算 2),上限 512`:`${part} 不符合宿主的字段与长度规则(${error.code??error.message})`;
|
|
33
|
+
findings.push(finding('error','develop_answer_invalid',`开发应答会在派出后被判无效:${detail}。先改应答再派活`,{part}));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return findings;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Each edit compared with the code root as it is now. Only when every edit is a
|
|
40
|
+
// no-op is the whole answer reported: a partial no-op is still a delivery.
|
|
41
|
+
export function answerChangeFindings(answer,{answersDir,codeProject}){
|
|
42
|
+
const edits=answer?.status==='succeeded'?answer.edits:null;
|
|
43
|
+
if(edits===null||typeof edits!=='object'||Array.isArray(edits))return [];
|
|
44
|
+
// A lesson candidate's Learning writeback changes AGENTS.md, so even an answer
|
|
45
|
+
// with no code edit is a delivery (cm-ai-develop-driver-gaps, lesson-only).
|
|
46
|
+
if(answer.value?.retrospective?.status==='lesson_candidate')return [];
|
|
47
|
+
const entries=Object.entries(edits);
|
|
48
|
+
if(!entries.length)return [finding('error','develop_no_change','开发应答没有任何 edits;交付后会是 develop_empty_changes,白跑一轮')];
|
|
49
|
+
const unchanged=entries.every(([target,entry])=>{
|
|
50
|
+
const file=path.join(codeProject,target),current=fileBytes(file);
|
|
51
|
+
if(typeof entry==='string'||typeof entry?.file==='string'){
|
|
52
|
+
const source=fileBytes(path.join(answersDir,typeof entry==='string'?entry:entry.file));
|
|
53
|
+
if(current===null||source===null||!current.equals(source))return false;
|
|
54
|
+
if(typeof entry?.mode!=='string')return true;
|
|
55
|
+
try{return (fs.statSync(file).mode&0o777)===Number.parseInt(entry.mode,8);}catch{return false;}
|
|
56
|
+
}
|
|
57
|
+
if(entry?.delete===true)return current===null;
|
|
58
|
+
if(typeof entry?.mode==='string'){try{return (fs.statSync(file).mode&0o777)===Number.parseInt(entry.mode,8);}catch{return false;}}
|
|
59
|
+
return false;
|
|
60
|
+
});
|
|
61
|
+
return unchanged?[finding('error','develop_no_change',
|
|
62
|
+
`开发应答的 ${entries.length} 处改动与代码根现状完全相同;交付后会是 develop_empty_changes,白跑一轮。确认应答写的是新内容`)]:[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Simulators named in check commands: only where a device is addressed — an
|
|
66
|
+
// xcodebuild -destination with id=, or a simctl subcommand's device argument —
|
|
67
|
+
// so an unrelated UUID (a record id, a request id) is never taken for one. The
|
|
68
|
+
// text form also covers commands wrapped in sh -c.
|
|
69
|
+
const DESTINATION=/-destination\s+["']?[^"'\n]*?\bid=([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})/gi;
|
|
70
|
+
const SIMCTL=/\bsimctl\s+[a-z-]+\s+(?:[a-z-]+\s+)?([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi;
|
|
71
|
+
export function checkDevices(checks){
|
|
72
|
+
const devices=new Set(),parallel=[],multiple=[];
|
|
73
|
+
for(const check of Array.isArray(checks)?checks:[]){
|
|
74
|
+
const tokens=Array.isArray(check?.command)?check.command.filter(token=>typeof token==='string'):[];
|
|
75
|
+
const text=tokens.join(' '),own=new Set();
|
|
76
|
+
for(const pattern of [DESTINATION,SIMCTL])for(const match of text.matchAll(pattern))own.add(match[1].toUpperCase());
|
|
77
|
+
own.forEach(id=>devices.add(id));
|
|
78
|
+
const workers=tokens.indexOf('-parallel-testing-worker-count'),enabled=tokens.indexOf('-parallel-testing-enabled');
|
|
79
|
+
const destinations=(text.match(/-destination\b/g)??[]).length;
|
|
80
|
+
if(own.size>1||(workers>=0&&Number(tokens[workers+1])>1)||(enabled>=0&&/^(YES|true|1)$/i.test(tokens[enabled+1]??'')))parallel.push(check.id??'?');
|
|
81
|
+
else if(destinations>1)multiple.push(check.id??'?');
|
|
82
|
+
}
|
|
83
|
+
return {devices:[...devices],parallel,multiple};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function deviceFindings(checks,openJobs,{runId=null}={}){
|
|
87
|
+
const {devices,parallel,multiple}=checkDevices(checks),findings=[];
|
|
88
|
+
for(const device of devices){
|
|
89
|
+
const holders=openJobs.filter(job=>job.resources.some(resource=>resource.toUpperCase()===`DEVICE:${device}`)&&!(runId&&job.runId===runId));
|
|
90
|
+
if(holders.length)findings.push(finding('error','device_busy',
|
|
91
|
+
`模拟器 ${device} 正被已登记的活占用:${holders.map(job=>job.label).join('、')}。等它结束(dispatch done)再派,避免两边检查互相干扰`,{device}));
|
|
92
|
+
}
|
|
93
|
+
if(parallel.length)findings.push(finding('warn','parallel_simulators',
|
|
94
|
+
`检查 ${parallel.join('、')} 明确会同时驱动多台模拟器(并行参数或多台设备);负载高时容易超时。改成单台串行,或拆成多次检查`,{ids:parallel}));
|
|
95
|
+
if(multiple.length)findings.push(finding('warn','multiple_destinations',
|
|
96
|
+
`检查 ${multiple.join('、')} 给了多个目的地,是否并行要看 xcodebuild 版本与参数;负载高时同样容易超时,确认是有意为之`,{ids:multiple}));
|
|
97
|
+
return findings;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The checks a resume would send against the checks the reviewed package was
|
|
101
|
+
// built with. Ids and commands must match exactly, in order.
|
|
102
|
+
export function checksDriftFindings(planChecks,recordedChecks){
|
|
103
|
+
if(!Array.isArray(recordedChecks)||!recordedChecks.length||!Array.isArray(planChecks))return [];
|
|
104
|
+
const shape=list=>JSON.stringify(list.map(check=>({id:check?.id??null,command:check?.command??null})));
|
|
105
|
+
return shape(planChecks)===shape(recordedChecks)?[]:[finding('error','checks_changed_since_review',
|
|
106
|
+
'本 PLAN 的检查(id 与命令)与已审查交付记录的检查不一致;完成时会被判包不匹配。PLAN.checks 应原样沿用交审时的那一组')];
|
|
107
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Detached waiter for notify.mjs notifyLater(). Sleeps the given delay, then
|
|
2
|
+
// sends the deferred notice only if its token is still the session's pending
|
|
3
|
+
// stop (notify() checks that under the state lock): progress, a new step, a
|
|
4
|
+
// newer stop or an immediate notice in the meantime cancels it. The workflow
|
|
5
|
+
// that started this process never waits for it; a killed waiter sends nothing.
|
|
6
|
+
import {sendPendingNotice,NOTIFY_LATER_MAX_MS} from './notify.mjs';
|
|
7
|
+
|
|
8
|
+
let job=null;
|
|
9
|
+
try{job=JSON.parse(process.env.CM_NOTIFY_LATER??'null');}catch{}
|
|
10
|
+
const env={...process.env};delete env.CM_NOTIFY_LATER;
|
|
11
|
+
if(!job||typeof job.token!=='string'||!job.fields||typeof job.fields!=='object'
|
|
12
|
+
||!Number.isSafeInteger(job.delayMs)||job.delayMs<1||job.delayMs>NOTIFY_LATER_MAX_MS)process.exit(0);
|
|
13
|
+
setTimeout(()=>{sendPendingNotice(job.fields,job.token,{env}).catch(()=>{}).finally(()=>process.exit(0));},job.delayMs);
|
|
@@ -177,14 +177,18 @@ export async function readSecret(home,channel,fileOptions={}){
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
const chars=(text,max)=>Array.from(text).slice(0,max).join('');
|
|
180
|
+
const BARK_LEVELS=new Set(['active','timeSensitive','passive']);
|
|
180
181
|
export async function buildRequest(channel,{home,env=process.env,dry=false,fileOptions={}}){
|
|
181
182
|
const title=chars(env.CM_NOTIFY_TITLE||'CM 提醒',100),body=chars(env.CM_NOTIFY_BODY||'(无正文)',1000);
|
|
183
|
+
const subtitle=chars(env.CM_NOTIFY_SUBTITLE||'',100);
|
|
182
184
|
if(channel==='bark'){
|
|
183
185
|
const {key,server}=dry?{key:'<已隐藏>',server:BARK_DEFAULT_SERVER}:await readSecret(home,'bark',fileOptions);
|
|
184
|
-
|
|
186
|
+
// Bark folds one group together on the phone: one group per project. A finished run does not ring.
|
|
187
|
+
const group=chars(env.CM_NOTIFY_GROUP||'CM',48),level=BARK_LEVELS.has(env.CM_NOTIFY_LEVEL)?env.CM_NOTIFY_LEVEL:'active';
|
|
188
|
+
return {url:`${server}/push`,payload:{device_key:key,title,...(subtitle?{subtitle}:{}),body,group,level}};
|
|
185
189
|
}
|
|
186
190
|
const {token}=dry?{token:'<已隐藏>'}:await readSecret(home,'pushplus',fileOptions);
|
|
187
|
-
return {url:PUSHPLUS_URL,payload:{token,title,content:body,template:'txt',channel:'wechat'}};
|
|
191
|
+
return {url:PUSHPLUS_URL,payload:{token,title,content:subtitle?`${subtitle}\n${body}`:body,template:'txt',channel:'wechat'}};
|
|
188
192
|
}
|
|
189
193
|
|
|
190
194
|
// Node 24.5+ routes https.Agent through HTTPS_PROXY/NO_PROXY when given
|