@aibyzero/cm-workflow 0.10.5
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 +30 -0
- package/AGENTS.md +74 -0
- package/CONTRIBUTING.md +62 -0
- package/LICENSE +21 -0
- package/README.md +263 -0
- package/SECURITY.md +49 -0
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/VERSION +1 -0
- package/agents/cm-backend-agent.md +34 -0
- package/agents/cm-contract-agent.md +34 -0
- package/agents/cm-database-agent.md +34 -0
- package/agents/cm-frontend-agent.md +33 -0
- package/agents/cm-miniprogram-agent.md +33 -0
- package/agents/cm-ui-agent.md +34 -0
- package/assets/docs/command-picker-mobile.svg +56 -0
- package/assets/docs/command-picker.svg +56 -0
- package/assets/docs/user-guide-hero-mobile.svg +35 -0
- package/assets/docs/user-guide-hero.svg +36 -0
- package/assets/readme/delivery-flow.svg +86 -0
- package/assets/readme/hero.svg +77 -0
- package/assets/readme/recovery-record.svg +73 -0
- package/assets/readme/test-evidence.svg +64 -0
- package/compat/claude-commands/cm-ai.md +3 -0
- package/compat/claude-commands/cm-check.md +3 -0
- package/compat/claude-commands/cm-fix.md +3 -0
- package/compat/claude-commands/cm-idea.md +3 -0
- package/compat/claude-commands/cm-init.md +3 -0
- package/compat/claude-commands/cm-prd.md +3 -0
- package/compat/claude-commands/cm-refactor.md +3 -0
- package/compat/claude-commands/cm-test.md +3 -0
- package/docs/architecture.md +155 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-a1-handoff.json +57 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-a2-handoff.json +58 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-r1.md +121 -0
- package/docs/fixes/.reviews/fix-cancel-throw-v2-T-FIX-cancel-throw-v2-a1-handoff.json +56 -0
- package/docs/fixes/.reviews/fix-cancel-throw-v2-T-FIX-cancel-throw-v2-r1.md +100 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-a1-handoff.json +61 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-a2-handoff.json +63 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-r1.md +58 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-r2.md +55 -0
- package/docs/fixes/.reviews/fix-f01-dual-failure-terminal-T-FIX-f01-dual-failure-terminal-a1-handoff.json +65 -0
- package/docs/fixes/.reviews/fix-f01-dual-failure-terminal-T-FIX-f01-dual-failure-terminal-r1.md +88 -0
- package/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r1.md +33 -0
- package/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r2.md +31 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a1-handoff.json +56 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a2-handoff.json +85 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r1.md +53 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r2.md +80 -0
- package/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-a1-handoff.json +35 -0
- package/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-r1.md +33 -0
- package/docs/fixes/.reviews/fix-windows-cp1252-log-output-r1.md +30 -0
- package/docs/fixes/.reviews/fix-windows-cp1252-log-output-r2.md +16 -0
- package/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-a1-handoff.json +40 -0
- package/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-r1.md +30 -0
- package/docs/fixes/20260729-windows-cp1252-log-output.md +65 -0
- package/docs/fixes/20260804-manifest-runtime-checkbox-drift.md +67 -0
- package/docs/fixes/20260806-model-call-boundary-identity.md +80 -0
- package/docs/fixes/20260807-prelanding-integrity.md +58 -0
- package/docs/fixes/20260826-openai-compatible-depth-fixture.md +39 -0
- package/docs/fixes/20260903-cm-js-n1n2-admission-r1.md +64 -0
- package/docs/fixes/20260903-cm-js-n1n2-admission-successor.md +83 -0
- package/docs/fixes/20260903-s4c1b-v3-cancel-throw.md +89 -0
- package/docs/fixes/20260904-f01-codex-dual-failure-terminal.md +89 -0
- package/docs/fixes/20260907-wip-triage-log.md +44 -0
- package/docs/installation.md +202 -0
- package/docs/js-workflow-control.md +1010 -0
- package/docs/sample-prd/prd-funding-rate-alert.md +42 -0
- package/docs/sample-specs/docs//351/234/200/346/261/202/347/244/272/344/276/213.md +24 -0
- package/docs/user-guide.md +526 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/README.md +19 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.excalidraw +3650 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.mp4 +0 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.png +0 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.spec.json +223 -0
- package/install-codex.sh +184 -0
- package/install.ps1 +206 -0
- package/install.sh +244 -0
- package/package.json +58 -0
- package/runtime/external-expert.md +302 -0
- package/runtime/js/cm-ai/accepted-fix.mjs +28 -0
- package/runtime/js/cm-ai/claude-developer-adapter.mjs +6 -0
- package/runtime/js/cm-ai/claude-review-adapter.mjs +16 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +53 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +107 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +353 -0
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +217 -0
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +538 -0
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +119 -0
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +172 -0
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +320 -0
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +107 -0
- package/runtime/js/cm-ai/code-projects.mjs +85 -0
- package/runtime/js/cm-ai/codex-config.mjs +48 -0
- package/runtime/js/cm-ai/codex-developer-adapter.mjs +5 -0
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +6 -0
- package/runtime/js/cm-ai/codex-developer-output.schema.json +37 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +73 -0
- package/runtime/js/cm-ai/contracts.mjs +156 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +93 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +504 -0
- package/runtime/js/cm-ai/effect-contract.mjs +102 -0
- package/runtime/js/cm-ai/execution-platform.mjs +7 -0
- package/runtime/js/cm-ai/execution-store.mjs +211 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +40 -0
- package/runtime/js/cm-ai/gate-bridge.mjs +25 -0
- package/runtime/js/cm-ai/host-bootstrap.mjs +170 -0
- package/runtime/js/cm-ai/host-check.mjs +89 -0
- package/runtime/js/cm-ai/host-conversation-execution.mjs +125 -0
- package/runtime/js/cm-ai/host-documentation.mjs +40 -0
- package/runtime/js/cm-ai/host-handoff.mjs +71 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +58 -0
- package/runtime/js/cm-ai/host-qa-executor.mjs +238 -0
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +131 -0
- package/runtime/js/cm-ai/host-qa-fix.mjs +30 -0
- package/runtime/js/cm-ai/host-qa-policy.mjs +70 -0
- package/runtime/js/cm-ai/host-review-authority.mjs +36 -0
- package/runtime/js/cm-ai/host-review-file.mjs +56 -0
- package/runtime/js/cm-ai/host-role-routing.mjs +41 -0
- package/runtime/js/cm-ai/host-session.mjs +96 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +53 -0
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +45 -0
- package/runtime/js/cm-ai/host.mjs +20 -0
- package/runtime/js/cm-ai/index.mjs +7 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +86 -0
- package/runtime/js/cm-ai/qa-fix-definition.mjs +21 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +38 -0
- package/runtime/js/cm-ai/review-package.mjs +426 -0
- package/runtime/js/cm-ai/review-result.schema.json +40 -0
- package/runtime/js/cm-ai/review-runner.mjs +35 -0
- package/runtime/js/cm-ai/task-commit-codec.mjs +54 -0
- package/runtime/js/cm-ai/task-commit.mjs +201 -0
- package/runtime/js/cm-ai/task-owner.mjs +97 -0
- package/runtime/js/cm-ai/task-runner.mjs +766 -0
- package/runtime/js/cm-ai/tool-preview.mjs +205 -0
- package/runtime/js/cm-ai/worker-claude.mjs +104 -0
- package/runtime/js/cm-ai/worker-codex-developer.mjs +124 -0
- package/runtime/js/cm-ai/worker-codex.mjs +143 -0
- package/runtime/js/cm-check/host.mjs +101 -0
- package/runtime/js/cm-fix/baseline.mjs +70 -0
- package/runtime/js/cm-fix/cause-evidence.mjs +24 -0
- package/runtime/js/cm-fix/cause-invocation.mjs +40 -0
- package/runtime/js/cm-fix/cause-package.mjs +68 -0
- package/runtime/js/cm-fix/dossier.mjs +140 -0
- package/runtime/js/cm-fix/execution.mjs +1549 -0
- package/runtime/js/cm-fix/final-review-evidence.mjs +20 -0
- package/runtime/js/cm-fix/final-review.mjs +156 -0
- package/runtime/js/cm-fix/finish.mjs +124 -0
- package/runtime/js/cm-fix/handoff.mjs +64 -0
- package/runtime/js/cm-fix/host-review.mjs +38 -0
- package/runtime/js/cm-fix/host.mjs +96 -0
- package/runtime/js/cm-fix/investigation.mjs +25 -0
- package/runtime/js/cm-fix/layout.mjs +17 -0
- package/runtime/js/cm-fix/learning-writeback.mjs +86 -0
- package/runtime/js/cm-fix/learning.mjs +31 -0
- package/runtime/js/cm-fix/metrics.mjs +75 -0
- package/runtime/js/cm-fix/progress.mjs +64 -0
- package/runtime/js/cm-fix/protected-edits.mjs +95 -0
- package/runtime/js/cm-fix/qa-source.mjs +58 -0
- package/runtime/js/cm-fix/red-test.mjs +92 -0
- package/runtime/js/cm-fix/regression-evidence.mjs +64 -0
- package/runtime/js/cm-fix/regression.mjs +41 -0
- package/runtime/js/cm-fix/repair.mjs +95 -0
- package/runtime/js/cm-fix/reproduce.mjs +54 -0
- package/runtime/js/cm-fix/retrospective.mjs +41 -0
- package/runtime/js/cm-fix/review-baseline.mjs +47 -0
- package/runtime/js/cm-fix/start.mjs +49 -0
- package/runtime/js/cm-fix/test-author.mjs +63 -0
- package/runtime/js/cm-fix/visual.mjs +72 -0
- package/runtime/js/cm-fix/walkthrough.mjs +126 -0
- package/runtime/js/cm-idea/session.mjs +79 -0
- package/runtime/js/cm-init/draft-generation.mjs +66 -0
- package/runtime/js/cm-init/draft-inspection.mjs +70 -0
- package/runtime/js/cm-init/project-analysis.mjs +60 -0
- package/runtime/js/cm-init/project-scan.mjs +55 -0
- package/runtime/js/cm-init/review-evidence.mjs +80 -0
- package/runtime/js/cm-prd/accepted-design.mjs +46 -0
- package/runtime/js/cm-prd/analysis.mjs +260 -0
- package/runtime/js/cm-prd/change.mjs +268 -0
- package/runtime/js/cm-prd/correction-check.mjs +49 -0
- package/runtime/js/cm-prd/design-risk.mjs +30 -0
- package/runtime/js/cm-prd/disposition-plan.mjs +33 -0
- package/runtime/js/cm-prd/draft-save.mjs +122 -0
- package/runtime/js/cm-prd/draft.mjs +70 -0
- package/runtime/js/cm-prd/materials.mjs +48 -0
- package/runtime/js/cm-prd/review-correction.mjs +158 -0
- package/runtime/js/cm-prd/review-disposition.mjs +96 -0
- package/runtime/js/cm-prd/review-findings.mjs +36 -0
- package/runtime/js/cm-prd/review-host.mjs +48 -0
- package/runtime/js/cm-prd/review-preparation.mjs +49 -0
- package/runtime/js/cm-prd/review-publication.mjs +56 -0
- package/runtime/js/cm-prd/self-check.mjs +75 -0
- package/runtime/js/cm-prd/session.mjs +74 -0
- package/runtime/js/cm-prd/summary.mjs +133 -0
- package/runtime/js/cm-refactor/host.mjs +2 -0
- package/runtime/js/cm-refactor/records.mjs +86 -0
- package/runtime/js/cm-refactor/workflow.mjs +478 -0
- package/runtime/js/cm-test/declared-command.mjs +32 -0
- package/runtime/js/cm-test/host.mjs +319 -0
- package/runtime/js/cm-test/logic-results.mjs +39 -0
- package/runtime/js/cm-test/recovery.mjs +58 -0
- package/runtime/js/cm-test/session.mjs +56 -0
- package/runtime/js/cm-test/source-snapshot.mjs +136 -0
- package/runtime/logging.md +207 -0
- package/runtime/model-efficiency.md +201 -0
- package/runtime/orchestration.md +113 -0
- package/runtime/project-context.md +43 -0
- package/runtime/project-learning.md +49 -0
- package/runtime/review.md +140 -0
- package/runtime/steelman-review.md +111 -0
- package/runtime/task-gates.md +283 -0
- package/runtime/task-handoff.schema.json +103 -0
- package/runtime/test-contract.md +212 -0
- package/runtime/workflow-config.md +118 -0
- package/runtime/workflow-routing.md +82 -0
- package/scripts/cm-ai-admission.mjs +50 -0
- package/scripts/cm-ai-admission.test.mjs +38 -0
- package/scripts/cm-ai-batch-host.mjs +77 -0
- package/scripts/cm-ai-batch-host.test.mjs +155 -0
- package/scripts/cm-ai-batch-run.mjs +136 -0
- package/scripts/cm-ai-batch-run.test.mjs +128 -0
- package/scripts/cm-ai-bootstrap.test.mjs +228 -0
- package/scripts/cm-ai-fix-integration.test.mjs +233 -0
- package/scripts/cm-ai-host.mjs +175 -0
- package/scripts/cm-ai-host.test.mjs +368 -0
- package/scripts/cm-ai-multi-root.test.mjs +289 -0
- package/scripts/cm-ai-nested-execution.test.mjs +313 -0
- package/scripts/cm-ai-run.mjs +293 -0
- package/scripts/cm-ai-run.test.mjs +336 -0
- package/scripts/cm-check-entry.mjs +120 -0
- package/scripts/cm-check-host.mjs +29 -0
- package/scripts/cm-check-host.test.mjs +71 -0
- package/scripts/cm-check-runtime.ps1 +69 -0
- package/scripts/cm-check-runtime.sh +910 -0
- package/scripts/cm-claude-probe.test.mjs +54 -0
- package/scripts/cm-claude-review-stream.test.mjs +45 -0
- package/scripts/cm-claude-worker.test.mjs +92 -0
- package/scripts/cm-codex-developer-adapter.test.mjs +85 -0
- package/scripts/cm-codex-developer-worker.test.mjs +128 -0
- package/scripts/cm-codex-review-progress.test.mjs +96 -0
- package/scripts/cm-execution-platform.test.mjs +47 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +72 -0
- package/scripts/cm-fix-cause-package.test.mjs +68 -0
- package/scripts/cm-fix-code-association.test.mjs +55 -0
- package/scripts/cm-fix-entry.mjs +132 -0
- package/scripts/cm-fix-execution.test.mjs +63 -0
- package/scripts/cm-fix-final-review.test.mjs +124 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +34 -0
- package/scripts/cm-fix-host-review.test.mjs +261 -0
- package/scripts/cm-fix-host-sequence.test.mjs +26 -0
- package/scripts/cm-fix-host.mjs +89 -0
- package/scripts/cm-fix-host.test.mjs +105 -0
- package/scripts/cm-fix-learning-writeback.test.mjs +73 -0
- package/scripts/cm-fix-learning.test.mjs +66 -0
- package/scripts/cm-fix-metrics.test.mjs +58 -0
- package/scripts/cm-fix-no-existing-tests.test.mjs +92 -0
- package/scripts/cm-fix-observation-dossier.test.mjs +452 -0
- package/scripts/cm-fix-progress.test.mjs +45 -0
- package/scripts/cm-fix-protected-edits.test.mjs +54 -0
- package/scripts/cm-fix-qa-source.test.mjs +206 -0
- package/scripts/cm-fix-red-owner.test.mjs +143 -0
- package/scripts/cm-fix-red-test.test.mjs +38 -0
- package/scripts/cm-fix-regression.test.mjs +57 -0
- package/scripts/cm-fix-repair-owner.test.mjs +370 -0
- package/scripts/cm-fix-repair.test.mjs +68 -0
- package/scripts/cm-fix-reproduce.test.mjs +31 -0
- package/scripts/cm-fix-retrospective.test.mjs +46 -0
- package/scripts/cm-fix-review-baseline.test.mjs +54 -0
- package/scripts/cm-fix-review-recovery.test.mjs +197 -0
- package/scripts/cm-fix-test-author.test.mjs +105 -0
- package/scripts/cm-fix-visual-bare.test.mjs +171 -0
- package/scripts/cm-fix-walkthrough.test.mjs +45 -0
- package/scripts/cm-host-check.test.mjs +113 -0
- package/scripts/cm-host-documentation.test.mjs +45 -0
- package/scripts/cm-host-handoff.test.mjs +58 -0
- package/scripts/cm-host-qa-executor.test.mjs +156 -0
- package/scripts/cm-host-qa-policy.test.mjs +59 -0
- package/scripts/cm-host-review-authority.test.mjs +60 -0
- package/scripts/cm-host-role-routing.test.mjs +33 -0
- package/scripts/cm-idea-entry.mjs +104 -0
- package/scripts/cm-idea-host.mjs +144 -0
- package/scripts/cm-idea-host.test.mjs +75 -0
- package/scripts/cm-idea-recovery.test.mjs +90 -0
- package/scripts/cm-init-analysis-host.test.mjs +50 -0
- package/scripts/cm-init-draft-generation.test.mjs +52 -0
- package/scripts/cm-init-draft-inspection.test.mjs +41 -0
- package/scripts/cm-init-entry.mjs +170 -0
- package/scripts/cm-init-host.mjs +284 -0
- package/scripts/cm-init-host.test.mjs +231 -0
- package/scripts/cm-init-project-analysis.test.mjs +47 -0
- package/scripts/cm-init-project-scan.test.mjs +41 -0
- package/scripts/cm-init-revision-host.test.mjs +61 -0
- package/scripts/cm-init-session.test.mjs +122 -0
- package/scripts/cm-log-event.mjs +538 -0
- package/scripts/cm-log-event.py +133 -0
- package/scripts/cm-log-event.test.mjs +70 -0
- package/scripts/cm-openai-compatible-call.py +661 -0
- package/scripts/cm-prd-analysis.test.mjs +67 -0
- package/scripts/cm-prd-completion.test.mjs +190 -0
- package/scripts/cm-prd-design-phase.test.mjs +296 -0
- package/scripts/cm-prd-draft-save.test.mjs +63 -0
- package/scripts/cm-prd-draft.test.mjs +39 -0
- package/scripts/cm-prd-entry.mjs +245 -0
- package/scripts/cm-prd-host.mjs +273 -0
- package/scripts/cm-prd-host.test.mjs +169 -0
- package/scripts/cm-prd-materials.test.mjs +41 -0
- package/scripts/cm-prd-review-claim.test.mjs +42 -0
- package/scripts/cm-prd-review-disposition.test.mjs +196 -0
- package/scripts/cm-prd-review-gate.mjs +194 -0
- package/scripts/cm-prd-review-gate.py +26 -0
- package/scripts/cm-prd-review-host.test.mjs +30 -0
- package/scripts/cm-prd-review-preparation.test.mjs +69 -0
- package/scripts/cm-prd-review-publication.test.mjs +95 -0
- package/scripts/cm-prd-revision.test.mjs +32 -0
- package/scripts/cm-prd-self-check.test.mjs +23 -0
- package/scripts/cm-prd-sources.test.mjs +76 -0
- package/scripts/cm-prd-timing.py +272 -0
- package/scripts/cm-refactor-entry.mjs +145 -0
- package/scripts/cm-refactor-host.mjs +26 -0
- package/scripts/cm-refactor-host.test.mjs +201 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +67 -0
- package/scripts/cm-review-inventory.test.mjs +109 -0
- package/scripts/cm-spec-manifest.mjs +104 -0
- package/scripts/cm-spec-manifest.py +26 -0
- package/scripts/cm-task-gate.mjs +879 -0
- package/scripts/cm-task-gate.py +312 -0
- package/scripts/cm-task-gate.test.mjs +202 -0
- package/scripts/cm-test-declared-command.test.mjs +18 -0
- package/scripts/cm-test-entry.mjs +231 -0
- package/scripts/cm-test-host.mjs +40 -0
- package/scripts/cm-test-host.test.mjs +169 -0
- package/scripts/cm-test-logic-results.test.mjs +26 -0
- package/scripts/cm-test-session.test.mjs +138 -0
- package/scripts/cm-usage-report.py +516 -0
- package/scripts/cm-workflow-config.mjs +463 -0
- package/scripts/cm-workflow-config.test.mjs +181 -0
- package/scripts/cm-workflow.mjs +36 -0
- package/scripts/cm-workflow.test.mjs +51 -0
- package/scripts/cm_workflow_config.py +52 -0
- package/scripts/fixtures/claude-review-process.mjs +35 -0
- package/scripts/fixtures/codex-review-process.mjs +22 -0
- package/scripts/fixtures/prd-review-gate-python-oracle.py +320 -0
- package/scripts/fixtures/spec-manifest-python-oracle.py +172 -0
- package/scripts/scan-public-safety.py +117 -0
- package/scripts/test-cm-log-event.py +1213 -0
- package/scripts/test-cm-openai-compatible-call.py +1185 -0
- package/scripts/test-cm-prd-review-gate.py +272 -0
- package/scripts/test-cm-prd-timing.py +168 -0
- package/scripts/test-cm-usage-report.py +584 -0
- package/scripts/test-npm-install.py +171 -0
- package/scripts/test-scan-public-safety.py +76 -0
- package/scripts/test-shell-compat.sh +365 -0
- package/scripts/test-spec-manifest.py +263 -0
- package/scripts/test-task-gate.py +46 -0
- package/scripts/test-workflow-config.py +30 -0
- package/scripts/validate-public-repo.py +245 -0
- package/scripts/validate-test-cases.mjs +71 -0
- package/scripts/validate-test-cases.py +27 -0
- package/scripts/validate-test-cases.test.mjs +36 -0
- package/skills/cm-ai/SKILL.md +137 -0
- package/skills/cm-ai/references/N1-init.md +108 -0
- package/skills/cm-ai/references/N2-enter-feature.md +38 -0
- package/skills/cm-ai/references/N3-execute-task.md +123 -0
- package/skills/cm-ai/references/N4-review.md +103 -0
- package/skills/cm-ai/references/N5-mark-done.md +117 -0
- package/skills/cm-ai/references/N6-qa-eval.md +102 -0
- package/skills/cm-ai/references/N7-context.md +23 -0
- package/skills/cm-ai/references/N8-finish.md +103 -0
- package/skills/cm-ai/references/js-host.md +126 -0
- package/skills/cm-backend-engineer/SKILL.md +100 -0
- package/skills/cm-check/SKILL.md +52 -0
- package/skills/cm-check/references/js-host.md +44 -0
- package/skills/cm-contract-engineer/SKILL.md +136 -0
- package/skills/cm-database-engineer/SKILL.md +89 -0
- package/skills/cm-devops-engineer/SKILL.md +137 -0
- package/skills/cm-doc-syncer/SKILL.md +150 -0
- package/skills/cm-finance-expert/SKILL.md +85 -0
- package/skills/cm-fix/SKILL.md +199 -0
- package/skills/cm-fix/references/cross-boundary-debugging.md +44 -0
- package/skills/cm-fix/references/js-host.md +135 -0
- package/skills/cm-frontend-engineer/SKILL.md +127 -0
- package/skills/cm-idea/SKILL.md +55 -0
- package/skills/cm-idea/references/domains/trading.md +97 -0
- package/skills/cm-idea/references/example-prd.md +92 -0
- package/skills/cm-idea/references/idea-to-prd.md +282 -0
- package/skills/cm-idea/references/js-host.md +63 -0
- package/skills/cm-init/SKILL.md +191 -0
- package/skills/cm-init/references/js-host.md +123 -0
- package/skills/cm-miniprogram-engineer/SKILL.md +141 -0
- package/skills/cm-miniprogram-engineer/references/platform-readiness.md +58 -0
- package/skills/cm-miniprogram-engineer/references/release-checklist.md +59 -0
- package/skills/cm-prd/SKILL.md +548 -0
- package/skills/cm-prd/references/brownfield.md +13 -0
- package/skills/cm-prd/references/change-mode.md +145 -0
- package/skills/cm-prd/references/context-scope.md +62 -0
- package/skills/cm-prd/references/greenfield.md +80 -0
- package/skills/cm-prd/references/js-change-recovery.md +57 -0
- package/skills/cm-prd/references/js-host.md +98 -0
- package/skills/cm-prd/references/phase-timing.md +68 -0
- package/skills/cm-prd/references/spec-self-check.md +22 -0
- package/skills/cm-product-manager/SKILL.md +83 -0
- package/skills/cm-qa-engineer/SKILL.md +142 -0
- package/skills/cm-refactor/SKILL.md +236 -0
- package/skills/cm-refactor/references/js-batch.md +75 -0
- package/skills/cm-refactor/references/js-host.md +78 -0
- package/skills/cm-test/SKILL.md +288 -0
- package/skills/cm-test/references/js-host.md +118 -0
- package/skills/cm-ui-engineer/SKILL.md +105 -0
- package/skills/codebase-context/SKILL.md +489 -0
- package/skills/darwin-skill/NOTICE.md +26 -0
- package/skills/darwin-skill/README.md +272 -0
- package/skills/darwin-skill/SKILL.md +492 -0
- package/skills/darwin-skill/references/runtime-neutrality.md +68 -0
- package/skills/darwin-skill/references/skilllens-evidence.md +142 -0
- package/skills/darwin-skill/scripts/screenshot.mjs +71 -0
- package/skills/darwin-skill/templates/result-card-dark.html +698 -0
- package/skills/darwin-skill/templates/result-card-white.html +444 -0
- package/skills/darwin-skill/templates/result-card.html +616 -0
- package/skills/external-expert/SKILL.md +250 -0
- package/templates/arch-reference.md +68 -0
- package/templates/auto-update/cm-announce.sh +19 -0
- package/templates/auto-update/cm-update.sh +274 -0
- package/templates/cm-workflow.yml +52 -0
- package/templates/dashboard/dashboard.html +153 -0
- package/templates/dashboard/serve.sh +10 -0
- package/templates/hooks/pre-commit-cm-task-check +67 -0
- package/templates/pixel/cm-pixel.html +388 -0
- package/templates/pixel/cm-pixel.sh +212 -0
- package/templates/pixel/dev/README.md +20 -0
- package/templates/pixel/dev/atlas-preview.png +0 -0
- package/templates/pixel/dev/build.py +55 -0
- package/templates/pixel/dev/sheets/roguelikeChar_transparent.png +0 -0
- package/templates/pixel/dev/sheets/roguelikeCity_tilemap.png +0 -0
- package/templates/pixel/dev/sheets/roguelikeIndoor_transparent.png +0 -0
- package/templates/pixel/dev/template.html +388 -0
- package/templates/pixel/serve.sh +12 -0
- package/templates/refactor/cm-refactor-denies.json +14 -0
- package/templates/rules/backend-api.md +36 -0
- package/templates/rules/coding-style.md +44 -0
- package/templates/rules/database.md +27 -0
- package/templates/rules/finance.md +32 -0
- package/templates/rules/frontend.md +32 -0
- package/templates/rules/git-workflow.md +25 -0
- package/templates/rules/miniprogram.md +31 -0
- package/templates/rules/security.md +31 -0
- package/templates/rules/smart-contract.md +28 -0
- package/templates/rules/testing.md +36 -0
- package/templates/statusline/cm-statusline.sh +73 -0
- package/templates/ui-lens/cm-ui-lens-extract.mjs +55 -0
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// JavaScript authority for CM log-event validation and state decisions.
|
|
3
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
|
|
9
|
+
const IDENTIFIER=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/;
|
|
10
|
+
const RESOURCE_ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
11
|
+
const RUN_ID=/^[A-Za-z0-9][A-Za-z0-9._-]{7,127}$/;
|
|
12
|
+
const SENSITIVE_KEY=/(api[_-]?key|authorization|cookie|password|passwd|private[_-]?key|recovery[_-]?code|secret|token)/i;
|
|
13
|
+
const RESERVED_FIELDS=new Set(['schema_version','event_id','run_id','at','workflow','event','phase','runtime','project','project_path','specs_path','detail']);
|
|
14
|
+
export const TERMINAL_EVENTS=new Set(['done','run_done']);
|
|
15
|
+
export const RESOURCE_GUARDED_EVENTS=new Set([...TERMINAL_EVENTS,'task_done']);
|
|
16
|
+
const RESOURCE_PHASES=new Set(['acquired','released','cleanup_failed']);
|
|
17
|
+
const TEST_RUN_GUARDED_EVENTS=new Set([...TERMINAL_EVENTS,'task_done']);
|
|
18
|
+
const TEST_RUN_PHASES=new Set(['start','case_start','case_complete','case_blocked','complete']);
|
|
19
|
+
const MODEL_USAGE_TOKEN_FIELDS=new Set(['input_tokens','output_tokens','cache_read_tokens','cache_write_tokens']);
|
|
20
|
+
const MODEL_USAGE_STATES=new Set(['observed','unavailable']);
|
|
21
|
+
const MODEL_USAGE_OUTCOMES=new Set(['success','error','blocked','cancelled']);
|
|
22
|
+
const MODEL_USAGE_ALLOWED_FIELDS=new Set([...MODEL_USAGE_TOKEN_FIELDS,'call_id','role','adapter','requested_model',
|
|
23
|
+
'effective_model','provider','source','purpose','stage','node','feature','task','usage_state','duration_ms','outcome','attempt']);
|
|
24
|
+
const MODEL_CALL_ALLOWED_FIELDS=new Set(['call_id','stage','role','adapter','requested_model','source','purpose']);
|
|
25
|
+
const MODEL_CALL_IDENTITY_FIELDS=['workflow','runtime','stage','role','adapter','requested_model','source','purpose'];
|
|
26
|
+
|
|
27
|
+
export class UsageError extends Error {
|
|
28
|
+
constructor(message){super(message);this.name='UsageError';}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function validateIdentifier(label,value,{optional=false}={}){
|
|
32
|
+
if((value===null||value===undefined)&&optional)return value;
|
|
33
|
+
if(typeof value!=='string'||!IDENTIFIER.test(value))
|
|
34
|
+
throw new UsageError(`${label} must match ${IDENTIFIER}; got ${JSON.stringify(value)}`);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function validateDetail(detail){
|
|
39
|
+
if(typeof detail!=='string'||!detail.trim())throw new UsageError('--detail cannot be empty');
|
|
40
|
+
if([...detail].length>500)throw new UsageError('--detail cannot exceed 500 characters');
|
|
41
|
+
if(/[\n\r\0]/.test(detail))throw new UsageError('--detail cannot contain control-line characters');
|
|
42
|
+
return detail;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function rejectSensitiveKeys(value,location='data',allowedSensitiveKeys=new Set()){
|
|
46
|
+
if(Array.isArray(value))value.forEach((child,index)=>rejectSensitiveKeys(child,`${location}[${index}]`,allowedSensitiveKeys));
|
|
47
|
+
else if(value!==null&&typeof value==='object')for(const [key,child] of Object.entries(value)){
|
|
48
|
+
if(SENSITIVE_KEY.test(key)&&!(location==='data'&&allowedSensitiveKeys.has(key)))
|
|
49
|
+
throw new UsageError(`sensitive log field is forbidden: ${location}.${key}`);
|
|
50
|
+
rejectSensitiveKeys(child,`${location}.${key}`,allowedSensitiveKeys);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function parseData(raw,event=null){
|
|
55
|
+
if(typeof raw!=='string'||Buffer.byteLength(raw)>8192)throw new UsageError('--data-json cannot exceed 8192 UTF-8 bytes');
|
|
56
|
+
let value;
|
|
57
|
+
try{value=JSON.parse(raw);}catch{throw new UsageError('--data-json must be a JSON object');}
|
|
58
|
+
if(value===null||typeof value!=='object'||Array.isArray(value))throw new UsageError('--data-json must be a JSON object');
|
|
59
|
+
const overlap=Object.keys(value).filter(key=>RESERVED_FIELDS.has(key)).sort();
|
|
60
|
+
if(overlap.length)throw new UsageError(`--data-json cannot override reserved fields: ${overlap.join(', ')}`);
|
|
61
|
+
rejectSensitiveKeys(value,'data',event==='model_usage'?MODEL_USAGE_TOKEN_FIELDS:new Set());return value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function validateShortText(label,value,{required=false}={}){
|
|
65
|
+
if((value===null||value===undefined)&&!required)return;
|
|
66
|
+
if(typeof value!=='string'||!value.trim())throw new UsageError(`model event requires a non-empty ${label}`);
|
|
67
|
+
if([...value].length>160||/[\n\r\0]/.test(value))
|
|
68
|
+
throw new UsageError(`model event ${label} must be one line and at most 160 characters`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function validateModelUsageEvent(event,phase,data){
|
|
72
|
+
if(event!=='model_usage')return;
|
|
73
|
+
const unknown=Object.keys(data).filter(key=>!MODEL_USAGE_ALLOWED_FIELDS.has(key)).sort();
|
|
74
|
+
if(unknown.length)throw new UsageError(`model_usage contains unsupported fields: ${unknown.join(', ')}`);
|
|
75
|
+
if(phase!=='complete')throw new UsageError('model_usage events require phase complete');
|
|
76
|
+
if(typeof data.call_id!=='string'||!RESOURCE_ID.test(data.call_id))throw new UsageError('model_usage requires a valid call_id');
|
|
77
|
+
if(typeof data.role!=='string'||!IDENTIFIER.test(data.role))throw new UsageError('model_usage requires a valid role');
|
|
78
|
+
if(!MODEL_USAGE_STATES.has(data.usage_state))throw new UsageError('model_usage usage_state must be observed or unavailable');
|
|
79
|
+
if(!MODEL_USAGE_OUTCOMES.has(data.outcome))
|
|
80
|
+
throw new UsageError('model_usage outcome must be success, error, blocked, or cancelled');
|
|
81
|
+
for(const field of ['adapter','requested_model','source','purpose','stage'])validateShortText(field,data[field],{required:true});
|
|
82
|
+
for(const field of ['effective_model','provider','node','feature','task'])validateShortText(field,data[field]);
|
|
83
|
+
if(data.attempt!==undefined&&(!Number.isInteger(data.attempt)||data.attempt<1))
|
|
84
|
+
throw new UsageError('model_usage attempt must be a positive integer');
|
|
85
|
+
if(data.usage_state==='unavailable'&&[...MODEL_USAGE_TOKEN_FIELDS].some(field=>Object.hasOwn(data,field)))
|
|
86
|
+
throw new UsageError('unavailable model_usage cannot contain token counts');
|
|
87
|
+
if(data.usage_state==='observed')for(const field of ['input_tokens','output_tokens'])
|
|
88
|
+
if(!Object.hasOwn(data,field))throw new UsageError(`observed model_usage requires ${field}`);
|
|
89
|
+
for(const field of [...MODEL_USAGE_TOKEN_FIELDS,'duration_ms'])if(Object.hasOwn(data,field)){
|
|
90
|
+
const value=data[field];
|
|
91
|
+
if(!Number.isInteger(value)||value<0)throw new UsageError(`model_usage ${field} must be a non-negative integer`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function validateModelCallEvent(event,phase,data){
|
|
96
|
+
if(event!=='model_call')return;
|
|
97
|
+
const unknown=Object.keys(data).filter(key=>!MODEL_CALL_ALLOWED_FIELDS.has(key)).sort();
|
|
98
|
+
if(unknown.length)throw new UsageError(`model_call contains unsupported fields: ${unknown.join(', ')}`);
|
|
99
|
+
if(phase!=='claimed')throw new UsageError('model_call events require phase claimed');
|
|
100
|
+
if(typeof data.call_id!=='string'||!RESOURCE_ID.test(data.call_id))throw new UsageError('model_call requires a valid call_id');
|
|
101
|
+
if(typeof data.role!=='string'||!IDENTIFIER.test(data.role))throw new UsageError('model_call requires a valid role');
|
|
102
|
+
for(const field of ['stage','adapter','requested_model','source','purpose'])validateShortText(field,data[field],{required:true});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function validateResourceEvent(event,phase,data){
|
|
106
|
+
if(event!=='resource')return;
|
|
107
|
+
if(!RESOURCE_PHASES.has(phase))throw new UsageError('resource events require phase acquired, released, or cleanup_failed');
|
|
108
|
+
if(typeof data.resource_id!=='string'||!RESOURCE_ID.test(data.resource_id))
|
|
109
|
+
throw new UsageError('resource events require a valid resource_id');
|
|
110
|
+
if(typeof data.resource_kind!=='string'||!IDENTIFIER.test(data.resource_kind))
|
|
111
|
+
throw new UsageError('resource events require a valid resource_kind');
|
|
112
|
+
if(phase==='acquired'&&data.cleanup_required!==true)
|
|
113
|
+
throw new UsageError('resource acquisition requires cleanup_required: true');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function validateTestRunEvent(event,phase,data){
|
|
117
|
+
if(event!=='test_run'||phase===null||phase===undefined)return;
|
|
118
|
+
if(!TEST_RUN_PHASES.has(phase))
|
|
119
|
+
throw new UsageError('test_run events require phase start, case_start, case_complete, case_blocked, or complete');
|
|
120
|
+
if(phase.startsWith('case_')&&(typeof data.case_id!=='string'||!RESOURCE_ID.test(data.case_id)))
|
|
121
|
+
throw new UsageError('test_run case events require a valid case_id');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function localIsoSeconds(date){
|
|
125
|
+
const pad=value=>String(value).padStart(2,'0'),offset=-date.getTimezoneOffset(),sign=offset>=0?'+':'-';
|
|
126
|
+
const absolute=Math.abs(offset);
|
|
127
|
+
return `${date.getFullYear()}-${pad(date.getMonth()+1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}${sign}${pad(Math.floor(absolute/60))}:${pad(absolute%60)}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function parseTimestamp(raw,now=new Date()){
|
|
131
|
+
if(raw===null||raw===undefined)return {at:localIsoSeconds(now),parsedAt:new Date(now)};
|
|
132
|
+
if(typeof raw!=='string'||!/(?:Z|[+-]\d{2}:?\d{2})$/.test(raw)||Number.isNaN(Date.parse(raw)))
|
|
133
|
+
throw new UsageError('--at must be an ISO-8601 timestamp with a timezone offset');
|
|
134
|
+
const match=raw.match(/^(\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2})(?::(\d{2}))?(?:\.\d+)?(Z|[+-]\d{2}:?\d{2})$/);
|
|
135
|
+
if(!match)throw new UsageError('--at must be an ISO-8601 timestamp');
|
|
136
|
+
const offset=match[4]==='Z'?'+00:00':match[4].replace(/^([+-]\d{2})(\d{2})$/,'$1:$2');
|
|
137
|
+
return {at:`${match[1]}T${match[2]}:${match[3]??'00'}${offset}`,parsedAt:new Date(raw)};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function generatedRunId(now=new Date(),uuid=randomUUID()){
|
|
141
|
+
const stamp=now.toISOString().replace(/[-:]/g,'').replace(/\.\d{3}Z$/,'Z');
|
|
142
|
+
return `${stamp}-${uuid.replaceAll('-','').slice(0,8)}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function selectRunId({explicit,event,pointer,latestProjectRun,projectStates,now,uuid}){
|
|
146
|
+
if(explicit!==null&&explicit!==undefined){
|
|
147
|
+
if(typeof explicit!=='string'||!RUN_ID.test(explicit))throw new UsageError('invalid --run-id');
|
|
148
|
+
return {runId:explicit,newRun:event==='run_start'};
|
|
149
|
+
}
|
|
150
|
+
if(pointer?.status==='running'&&projectStates[pointer.run_id]!=='done')return {runId:pointer.run_id,newRun:false};
|
|
151
|
+
if(pointer?.status==='done'&&TERMINAL_EVENTS.has(event))return {runId:pointer.run_id,newRun:false};
|
|
152
|
+
if(latestProjectRun&&projectStates[latestProjectRun]==='running')return {runId:latestProjectRun,newRun:false};
|
|
153
|
+
if(latestProjectRun&&projectStates[latestProjectRun]==='done'&&TERMINAL_EVENTS.has(event))
|
|
154
|
+
return {runId:latestProjectRun,newRun:false};
|
|
155
|
+
return {runId:generatedRunId(now,uuid),newRun:true};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function canonical(value){
|
|
159
|
+
if(value===null||['string','boolean','number'].includes(typeof value))return JSON.stringify(value);
|
|
160
|
+
if(Array.isArray(value))return `[${value.map(canonical).join(',')}]`;
|
|
161
|
+
return `{${Object.keys(value).sort().map(key=>`${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function uuid5(name){
|
|
165
|
+
const namespace=Buffer.from('6ba7b8119dad11d180b400c04fd430c8','hex');
|
|
166
|
+
const bytes=createHash('sha1').update(namespace).update(name).digest().subarray(0,16);
|
|
167
|
+
bytes[6]=(bytes[6]&0x0f)|0x50;bytes[8]=(bytes[8]&0x3f)|0x80;
|
|
168
|
+
const hex=bytes.toString('hex');
|
|
169
|
+
return `${hex.slice(0,8)}-${hex.slice(8,12)}-${hex.slice(12,16)}-${hex.slice(16,20)}-${hex.slice(20)}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function deterministicEventId(value){
|
|
173
|
+
const identity={...value};delete identity.at;delete identity.event_id;
|
|
174
|
+
return uuid5(canonical(identity));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function applyResourceTransition(states,resourceId,resourceKind,phase){
|
|
178
|
+
const previous=states.get(resourceId);
|
|
179
|
+
if(previous===undefined){
|
|
180
|
+
if(phase!=='acquired')throw new UsageError('resource terminal phase has no acquisition');
|
|
181
|
+
states.set(resourceId,[phase,resourceKind]);return;
|
|
182
|
+
}
|
|
183
|
+
const [previousPhase,previousKind]=previous;
|
|
184
|
+
if(previousKind!==resourceKind)throw new UsageError('resource_kind does not match its acquisition');
|
|
185
|
+
if(phase==='acquired'){
|
|
186
|
+
if(previousPhase!=='acquired')throw new UsageError('released resource_id cannot be reused; acquire a new resource_id');
|
|
187
|
+
throw new UsageError('active resource_id already has an acquisition; acquire a new resource_id');
|
|
188
|
+
}
|
|
189
|
+
if(phase==='cleanup_failed'&&previousPhase==='released')throw new UsageError('released resource cannot fail cleanup');
|
|
190
|
+
states.set(resourceId,[phase,resourceKind]);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function unclosedResources(states){
|
|
194
|
+
return [...states].filter(([,value])=>['acquired','cleanup_failed'].includes(value[0])).map(([key])=>key).sort();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function applyTestRunTransition(active,openCases,phase,caseId){
|
|
198
|
+
if(phase==='start'){
|
|
199
|
+
if(active)throw new UsageError('test_run start has no preceding complete');
|
|
200
|
+
if(openCases.size)throw new UsageError('test_run state contains cases without an active run');
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
if(phase==='case_start'){
|
|
204
|
+
if(!active)throw new UsageError('test_run case_start has no active test run');
|
|
205
|
+
if(openCases.has(caseId))throw new UsageError('test_run case already has an active case_start');
|
|
206
|
+
openCases.add(caseId);return active;
|
|
207
|
+
}
|
|
208
|
+
if(phase==='case_complete'||phase==='case_blocked'){
|
|
209
|
+
if(!active)throw new UsageError('test_run case terminal phase has no active test run');
|
|
210
|
+
if(!openCases.has(caseId))throw new UsageError('test_run case terminal phase has no case_start');
|
|
211
|
+
openCases.delete(caseId);return active;
|
|
212
|
+
}
|
|
213
|
+
if(!active)throw new UsageError('test_run complete has no active test run');
|
|
214
|
+
if(openCases.size)throw new UsageError('test_run complete has unfinished cases');
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function buildEvent(input,state={}){
|
|
219
|
+
const workflow=validateIdentifier('--workflow',input.workflow);
|
|
220
|
+
const event=validateIdentifier('--event',input.event);
|
|
221
|
+
const phase=validateIdentifier('--phase',input.phase??null,{optional:true});
|
|
222
|
+
const runtime=validateIdentifier('--runtime',input.runtime);
|
|
223
|
+
const detail=validateDetail(input.detail),data=parseData(input.dataJson??'{}',event);
|
|
224
|
+
validateResourceEvent(event,phase,data);
|
|
225
|
+
validateTestRunEvent(event,phase,data);validateModelUsageEvent(event,phase,data);validateModelCallEvent(event,phase,data);
|
|
226
|
+
const {at,parsedAt}=parseTimestamp(input.at??null,state.now);
|
|
227
|
+
const projectRoot=input.projectRoot?path.resolve(input.projectRoot):null;
|
|
228
|
+
const specsDir=input.specsDir?path.resolve(input.specsDir):null;
|
|
229
|
+
const project=input.project??(projectRoot?path.basename(projectRoot):'unscoped');
|
|
230
|
+
if(typeof project!=='string'||[...project].length>120||/[\n\r\0]/.test(project))
|
|
231
|
+
throw new UsageError('--project must be one line and at most 120 characters');
|
|
232
|
+
const selection=selectRunId({explicit:input.runId??null,event,pointer:state.pointer??null,
|
|
233
|
+
latestProjectRun:state.latestProjectRun??null,projectStates:state.projectStates??{},now:state.now,uuid:state.uuid});
|
|
234
|
+
const value={schema_version:1,run_id:selection.runId,at,workflow,event,runtime,project,detail};
|
|
235
|
+
if(phase)value.phase=phase;if(projectRoot)value.project_path=projectRoot;if(specsDir)value.specs_path=specsDir;
|
|
236
|
+
Object.assign(value,data);value.event_id=deterministicEventId(value);
|
|
237
|
+
return {event:value,parsedAt, ...selection};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function expandUser(value){
|
|
241
|
+
if(value==='~')return os.homedir();
|
|
242
|
+
if(value.startsWith('~/'))return path.join(os.homedir(),value.slice(2));
|
|
243
|
+
return value;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function resolveDirectory(label,value){
|
|
247
|
+
if(value===null||value===undefined)return null;
|
|
248
|
+
let resolved;
|
|
249
|
+
try{resolved=fs.realpathSync(expandUser(value));}
|
|
250
|
+
catch{throw new UsageError(`${label} is not an existing directory: ${path.resolve(expandUser(value))}`);}
|
|
251
|
+
if(!fs.statSync(resolved).isDirectory())throw new UsageError(`${label} is not an existing directory: ${resolved}`);
|
|
252
|
+
return resolved;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function parseJsonLine(line){try{return JSON.parse(line);}catch{return null;}}
|
|
256
|
+
|
|
257
|
+
function loadPointer(file){
|
|
258
|
+
if(!file||!fs.existsSync(file)||!fs.statSync(file).isFile())return null;
|
|
259
|
+
try{
|
|
260
|
+
const value=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
261
|
+
return value&&typeof value==='object'&&!Array.isArray(value)&&typeof value.run_id==='string'&&RUN_ID.test(value.run_id)?value:null;
|
|
262
|
+
}catch{return null;}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function readJsonLines(file,{strict=false}={}){
|
|
266
|
+
if(!file||!fs.existsSync(file)||!fs.statSync(file).isFile())return [];
|
|
267
|
+
const rows=[];
|
|
268
|
+
for(const line of fs.readFileSync(file,'utf8').split(/\r?\n/)){
|
|
269
|
+
if(!line)continue;
|
|
270
|
+
const value=parseJsonLine(line);
|
|
271
|
+
if(value===null){if(strict)throw new UsageError('resource state log contains invalid JSON');continue;}
|
|
272
|
+
rows.push(value);
|
|
273
|
+
}
|
|
274
|
+
return rows;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function loadProjectRunState(file){
|
|
278
|
+
let latestProjectRun=null;const projectStates={};
|
|
279
|
+
try{
|
|
280
|
+
for(const value of readJsonLines(file)){
|
|
281
|
+
if(!value||typeof value!=='object'||typeof value.run_id!=='string'||!RUN_ID.test(value.run_id)||typeof value.event!=='string')continue;
|
|
282
|
+
latestProjectRun=value.run_id;
|
|
283
|
+
if(value.event==='run_start'||value.event==='resume')projectStates[value.run_id]='running';
|
|
284
|
+
else if(TERMINAL_EVENTS.has(value.event))projectStates[value.run_id]='done';
|
|
285
|
+
else if(!Object.hasOwn(projectStates,value.run_id))projectStates[value.run_id]='running';
|
|
286
|
+
}
|
|
287
|
+
}catch{return {latestProjectRun:null,projectStates:{}};}
|
|
288
|
+
return {latestProjectRun,projectStates};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function findJsonlEvent(file,eventId){
|
|
292
|
+
try{return readJsonLines(file).find(value=>value&&typeof value==='object'&&value.event_id===eventId)??null;}
|
|
293
|
+
catch{return null;}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function findModelEvent(file,runId,event,callId){
|
|
297
|
+
try{return readJsonLines(file).find(value=>value&&typeof value==='object'&&value.run_id===runId
|
|
298
|
+
&&value.event===event&&value.call_id===callId&&(event!=='model_call'||value.phase==='claimed'))??null;}
|
|
299
|
+
catch{return null;}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function modelCallIdentity(event){return MODEL_CALL_IDENTITY_FIELDS.map(field=>String(event[field]??''));}
|
|
303
|
+
|
|
304
|
+
function loadResourceStates(file,runId){
|
|
305
|
+
const states=new Map();
|
|
306
|
+
for(const value of readJsonLines(file,{strict:true})){
|
|
307
|
+
if(!value||typeof value!=='object'||value.run_id!==runId||value.event!=='resource')continue;
|
|
308
|
+
if(typeof value.resource_id!=='string'||!RESOURCE_ID.test(value.resource_id)
|
|
309
|
+
||typeof value.resource_kind!=='string'||!IDENTIFIER.test(value.resource_kind)||!RESOURCE_PHASES.has(value.phase))
|
|
310
|
+
throw new UsageError('resource state log contains a malformed event');
|
|
311
|
+
if(value.phase==='acquired'&&value.cleanup_required!==true)
|
|
312
|
+
throw new UsageError('resource acquisition is missing cleanup_required');
|
|
313
|
+
applyResourceTransition(states,value.resource_id,value.resource_kind,value.phase);
|
|
314
|
+
}
|
|
315
|
+
return states;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function loadTestRunState(file,runId){
|
|
319
|
+
let active=false;const openCases=new Set();
|
|
320
|
+
for(const value of readJsonLines(file,{strict:true})){
|
|
321
|
+
if(!value||typeof value!=='object'||value.run_id!==runId||value.event!=='test_run'||value.phase===null||value.phase===undefined)continue;
|
|
322
|
+
const phase=value.phase,caseId=value.case_id;
|
|
323
|
+
if(!TEST_RUN_PHASES.has(phase))throw new UsageError('test_run state log contains a malformed event');
|
|
324
|
+
if(phase.startsWith('case_')&&(typeof caseId!=='string'||!RESOURCE_ID.test(caseId)))
|
|
325
|
+
throw new UsageError('test_run state log contains a malformed case event');
|
|
326
|
+
if(phase==='complete'&&!active&&!openCases.size)continue;
|
|
327
|
+
active=applyTestRunTransition(active,openCases,phase,typeof caseId==='string'?caseId:null);
|
|
328
|
+
}
|
|
329
|
+
return {active,openCases};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Read-only reuse of the writer's existing resource/test lifecycle guards by
|
|
333
|
+
// the batch coordinator. No new terminal event or task completion authority.
|
|
334
|
+
export function inspectRunClosure(file,runId){
|
|
335
|
+
const resources=unclosedResources(loadResourceStates(file,runId)),tests=loadTestRunState(file,runId);
|
|
336
|
+
return {closed:resources.length===0&&!tests.active&&tests.openCases.size===0};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function compactJson(value){return `${JSON.stringify(value)}\n`;}
|
|
340
|
+
function ensureDirectory(directory,mode){fs.mkdirSync(directory,{recursive:true,mode});if(process.platform!=='win32')fs.chmodSync(directory,mode);}
|
|
341
|
+
function appendLine(file,value,{privateFile=false}={}){
|
|
342
|
+
fs.mkdirSync(path.dirname(file),{recursive:true});
|
|
343
|
+
const descriptor=fs.openSync(file,fs.constants.O_APPEND|fs.constants.O_CREAT|fs.constants.O_WRONLY,privateFile?0o600:0o644);
|
|
344
|
+
try{fs.writeFileSync(descriptor,compactJson(value));fs.fsyncSync(descriptor);}finally{fs.closeSync(descriptor);}
|
|
345
|
+
if(privateFile&&process.platform!=='win32')fs.chmodSync(file,0o600);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function writePointer(file,value){
|
|
349
|
+
const temporary=path.join(path.dirname(file),`${path.basename(file)}.tmp.${process.pid}.${randomUUID().replaceAll('-','')}`);
|
|
350
|
+
try{fs.writeFileSync(temporary,compactJson(value),{encoding:'utf8',mode:0o644});fs.renameSync(temporary,file);}
|
|
351
|
+
finally{try{fs.unlinkSync(temporary);}catch(error){if(error.code!=='ENOENT')throw error;}}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function indexHasStatus(file,runId,status){
|
|
355
|
+
try{return readJsonLines(file).some(value=>value&&typeof value==='object'&&value.run_id===runId&&value.status===status);}
|
|
356
|
+
catch{return false;}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function pointerGlobalLog(pointer,globalHome,runId){
|
|
360
|
+
if(!pointer||pointer.run_id!==runId||typeof pointer.global_log!=='string')return null;
|
|
361
|
+
const candidate=path.resolve(expandUser(pointer.global_log)),relative=path.relative(globalHome,candidate),parts=relative.split(path.sep);
|
|
362
|
+
if(relative.startsWith(`..${path.sep}`)||path.isAbsolute(relative)||parts.length!==3||parts[0]!=='runs'
|
|
363
|
+
||!/^\d{4}-\d{2}$/.test(parts[1])||parts[2]!==`${runId}.jsonl`)return null;
|
|
364
|
+
return candidate;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function selectGlobalLog({globalHome,runId,at,pointer}){
|
|
368
|
+
const pointed=pointerGlobalLog(pointer,globalHome,runId);if(pointed)return pointed;
|
|
369
|
+
const runs=path.join(globalHome,'runs'),matches=[];
|
|
370
|
+
if(fs.existsSync(runs))for(const month of fs.readdirSync(runs)){
|
|
371
|
+
const candidate=path.join(runs,month,`${runId}.jsonl`);
|
|
372
|
+
if(fs.existsSync(candidate))matches.push(path.resolve(candidate));
|
|
373
|
+
}
|
|
374
|
+
matches.sort();
|
|
375
|
+
if(matches.length>1)throw new UsageError(`multiple global log files found for run_id ${runId}; repair the local mirror before continuing`);
|
|
376
|
+
return matches[0]??path.join(runs,at.slice(0,7),`${runId}.jsonl`);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function degradeEvent({runId,at,workflow,runtime,project,projectRoot,specsDir,phase,detail,errorType}){
|
|
380
|
+
const value={schema_version:1,run_id:runId,at,workflow,event:'degrade',phase,runtime,project,detail,error_type:errorType};
|
|
381
|
+
if(projectRoot)value.project_path=projectRoot;if(specsDir)value.specs_path=specsDir;
|
|
382
|
+
value.event_id=deterministicEventId(value);return value;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function samePhysicalPath(left,right){
|
|
386
|
+
try{
|
|
387
|
+
const key=value=>{
|
|
388
|
+
const resolved=path.normalize(fs.realpathSync.native(value));
|
|
389
|
+
return process.platform==='win32'?resolved.toLowerCase():resolved;
|
|
390
|
+
};
|
|
391
|
+
return typeof left==='string'&&typeof right==='string'&&key(left)===key(right);
|
|
392
|
+
}catch{return false;}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function requireLockAdapter({specsDir,globalHome},environment){
|
|
396
|
+
if(environment.CM_LOG_LOCK_ADAPTER!=='1'||Number(environment.CM_LOG_LOCK_PARENT_PID)!==process.ppid)
|
|
397
|
+
throw new UsageError('cm-log-event writes require the platform lock adapter');
|
|
398
|
+
if(specsDir&&!samePhysicalPath(environment.CM_LOG_PROJECT_LOCK,path.join(specsDir,'.cm-run.lock')))
|
|
399
|
+
throw new UsageError('project log lock is not held for this specs directory');
|
|
400
|
+
if(environment.CM_LOG_GLOBAL_LOCKED==='1'&&!samePhysicalPath(environment.CM_LOG_GLOBAL_LOCK,path.join(globalHome,'.cm-write.lock')))
|
|
401
|
+
throw new UsageError('global log lock is not held for this log home');
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function prepareInput(input){
|
|
405
|
+
const projectRoot=resolveDirectory('--project-root',input.projectRoot??null);
|
|
406
|
+
const specsDir=resolveDirectory('--specs-dir',input.specsDir??null);
|
|
407
|
+
buildEvent({...input,projectRoot,specsDir},{now:new Date(),uuid:'00000000-0000-4000-8000-000000000000'});
|
|
408
|
+
return {...input,projectRoot,specsDir};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export function writeLogEvent(rawInput,{environment=process.env,now=new Date(),uuid=randomUUID()}={}){
|
|
412
|
+
const input=prepareInput(rawInput),globalHome=fs.realpathSync(path.resolve(expandUser(environment.CM_WORKFLOW_LOG_HOME??'~/.cm-workflow/logs')));
|
|
413
|
+
requireLockAdapter({specsDir:input.specsDir,globalHome},environment);
|
|
414
|
+
const pointerPath=input.specsDir?path.join(input.specsDir,'.cm-run.json'):null;
|
|
415
|
+
const projectLog=input.specsDir?path.join(input.specsDir,'运行日志.jsonl'):null;
|
|
416
|
+
const pointer=loadPointer(pointerPath),runState=loadProjectRunState(projectLog);
|
|
417
|
+
let built=buildEvent(input,{pointer,...runState,now,uuid}),event=built.event,{at}=event;
|
|
418
|
+
const terminal=TERMINAL_EVENTS.has(event.event),globalLocked=environment.CM_LOG_GLOBAL_LOCKED==='1';
|
|
419
|
+
let globalLog=projectLog?null:selectGlobalLog({globalHome,runId:built.runId,at,pointer});
|
|
420
|
+
const authoritativeLog=projectLog??globalLog;
|
|
421
|
+
if(event.event==='model_usage'){
|
|
422
|
+
const existingUsage=findModelEvent(authoritativeLog,built.runId,'model_usage',event.call_id);
|
|
423
|
+
if(existingUsage!==null&&existingUsage.event_id!==event.event_id)
|
|
424
|
+
throw new UsageError('model_usage call_id already used with different payload');
|
|
425
|
+
const existingClaim=findModelEvent(authoritativeLog,built.runId,'model_call',event.call_id);
|
|
426
|
+
if(event.adapter==='openai-compatible'&&existingClaim===null)
|
|
427
|
+
throw new UsageError('managed model_usage requires a prior model_call claim');
|
|
428
|
+
if(existingClaim!==null&&modelCallIdentity(existingClaim).some((value,index)=>value!==modelCallIdentity(event)[index]))
|
|
429
|
+
throw new UsageError('model_usage identity does not match model_call claim');
|
|
430
|
+
}
|
|
431
|
+
if(event.event==='model_call'){
|
|
432
|
+
if(findModelEvent(authoritativeLog,built.runId,'model_usage',event.call_id)!==null)
|
|
433
|
+
throw new UsageError('model_call call_id already completed');
|
|
434
|
+
const existingClaim=findModelEvent(authoritativeLog,built.runId,'model_call',event.call_id);
|
|
435
|
+
if(existingClaim!==null&&existingClaim.event_id!==event.event_id)
|
|
436
|
+
throw new UsageError('model_call call_id already claimed with different payload');
|
|
437
|
+
}
|
|
438
|
+
let existing=['resource','test_run',...RESOURCE_GUARDED_EVENTS,...TEST_RUN_GUARDED_EVENTS].includes(event.event)
|
|
439
|
+
?findJsonlEvent(authoritativeLog,event.event_id):null;
|
|
440
|
+
let resourceStates=new Map();
|
|
441
|
+
if(existing===null&&(event.event==='resource'||RESOURCE_GUARDED_EVENTS.has(event.event)))try{
|
|
442
|
+
resourceStates=loadResourceStates(authoritativeLog,built.runId);
|
|
443
|
+
}catch(error){throw new UsageError(`resource state cannot be verified: ${error.name}`);}
|
|
444
|
+
if(existing===null&&RESOURCE_GUARDED_EVENTS.has(event.event)){
|
|
445
|
+
const pending=unclosedResources(resourceStates);
|
|
446
|
+
if(pending.length)throw new UsageError(`completion blocked by unclosed resources: ${pending.join(', ')}`);
|
|
447
|
+
}
|
|
448
|
+
if(existing===null&&event.event==='resource')applyResourceTransition(resourceStates,event.resource_id,event.resource_kind,event.phase);
|
|
449
|
+
|
|
450
|
+
let testRun={active:false,openCases:new Set()};
|
|
451
|
+
if(existing===null&&((event.event==='test_run'&&event.phase!==undefined)||TEST_RUN_GUARDED_EVENTS.has(event.event)))try{
|
|
452
|
+
testRun=loadTestRunState(authoritativeLog,built.runId);
|
|
453
|
+
}catch(error){throw new UsageError(`test_run state cannot be verified: ${error.name}`);}
|
|
454
|
+
if(existing===null&&TEST_RUN_GUARDED_EVENTS.has(event.event)&&(testRun.active||testRun.openCases.size)){
|
|
455
|
+
const detail=[];
|
|
456
|
+
if(testRun.active)detail.push('active invocation');
|
|
457
|
+
if(testRun.openCases.size)detail.push(`open cases: ${[...testRun.openCases].sort().join(', ')}`);
|
|
458
|
+
throw new UsageError(`completion blocked by incomplete test_run: ${detail.join('; ')}`);
|
|
459
|
+
}
|
|
460
|
+
if(existing===null&&event.event==='test_run'&&event.phase!==undefined)
|
|
461
|
+
applyTestRunTransition(testRun.active,testRun.openCases,event.phase,event.case_id??null);
|
|
462
|
+
|
|
463
|
+
let projectDuplicate=false;
|
|
464
|
+
if(projectLog){
|
|
465
|
+
const projectExisting=findJsonlEvent(projectLog,event.event_id);projectDuplicate=projectExisting!==null;
|
|
466
|
+
if(projectExisting){event=projectExisting;at=event.at;built={...built,parsedAt:parseTimestamp(at).parsedAt};}
|
|
467
|
+
else appendLine(projectLog,event);
|
|
468
|
+
}
|
|
469
|
+
if(globalLog===null)globalLog=selectGlobalLog({globalHome,runId:built.runId,at,pointer});
|
|
470
|
+
let globalWritten=false,degraded=false,globalDuplicate=false;
|
|
471
|
+
try{
|
|
472
|
+
if(!globalLocked){const error=new Error(environment.CM_LOG_GLOBAL_LOCK_ERROR??'global lock unavailable');error.name=environment.CM_LOG_GLOBAL_LOCK_ERROR_TYPE??'OSError';throw error;}
|
|
473
|
+
ensureDirectory(globalHome,0o700);ensureDirectory(path.join(globalHome,'runs'),0o700);ensureDirectory(path.dirname(globalLog),0o700);
|
|
474
|
+
globalDuplicate=findJsonlEvent(globalLog,event.event_id)!==null;
|
|
475
|
+
if(!globalDuplicate)appendLine(globalLog,event,{privateFile:true});
|
|
476
|
+
const index=path.join(globalHome,'index.jsonl');
|
|
477
|
+
if(built.newRun&&!indexHasStatus(index,built.runId,'running'))appendLine(index,{schema_version:1,at,run_id:built.runId,status:'running',
|
|
478
|
+
workflow:event.workflow,runtime:event.runtime,project:event.project,project_path:input.projectRoot??null,
|
|
479
|
+
specs_path:input.specsDir??null,log_file:path.relative(globalHome,globalLog)},{privateFile:true});
|
|
480
|
+
if(terminal&&!indexHasStatus(index,built.runId,'done'))appendLine(index,{schema_version:1,at,run_id:built.runId,status:'done',
|
|
481
|
+
workflow:event.workflow,runtime:event.runtime,project:event.project,log_file:path.relative(globalHome,globalLog)},{privateFile:true});
|
|
482
|
+
globalWritten=true;
|
|
483
|
+
}catch(error){
|
|
484
|
+
if(!projectLog)throw error;
|
|
485
|
+
degraded=true;
|
|
486
|
+
const degradation=degradeEvent({runId:built.runId,at,workflow:event.workflow,runtime:event.runtime,project:event.project,
|
|
487
|
+
projectRoot:input.projectRoot,specsDir:input.specsDir,phase:'global_log',detail:'全局日志镜像写入失败,项目日志继续作为权威来源',errorType:error.name});
|
|
488
|
+
if(!findJsonlEvent(projectLog,degradation.event_id))appendLine(projectLog,degradation);
|
|
489
|
+
process.stderr.write('cm-log-event: global mirror unavailable; project log retained\n');
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
let pointerWritten=null;
|
|
493
|
+
if(pointerPath){
|
|
494
|
+
try{
|
|
495
|
+
const currentStatus=loadProjectRunState(projectLog).projectStates[built.runId]??(terminal?'done':'running');
|
|
496
|
+
writePointer(pointerPath,{schema_version:1,run_id:built.runId,workflow:event.workflow,status:currentStatus,
|
|
497
|
+
global_log:globalLog,global_written:globalWritten,updated_at:at});pointerWritten=true;
|
|
498
|
+
}catch(error){
|
|
499
|
+
pointerWritten=false;degraded=true;
|
|
500
|
+
const degradation=degradeEvent({runId:built.runId,at,workflow:event.workflow,runtime:event.runtime,project:event.project,
|
|
501
|
+
projectRoot:input.projectRoot,specsDir:input.specsDir,phase:'run_pointer',detail:'运行指针写入失败,将从权威项目日志恢复',errorType:error.name});
|
|
502
|
+
if(!findJsonlEvent(projectLog,degradation.event_id))appendLine(projectLog,degradation);
|
|
503
|
+
if(globalWritten)try{if(!findJsonlEvent(globalLog,degradation.event_id))appendLine(globalLog,degradation,{privateFile:true});}catch{}
|
|
504
|
+
process.stderr.write('cm-log-event: active-run pointer unavailable; project log recovery retained\n');
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return {event_id:event.event_id,run_id:built.runId,project_log:projectLog,global_log:globalLog,global_written:globalWritten,
|
|
508
|
+
pointer_written:pointerWritten,deduplicated:projectLog?projectDuplicate:globalDuplicate,degraded};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function parseCli(argv){
|
|
512
|
+
if(argv.includes('--help')||argv.includes('-h'))return {help:true};
|
|
513
|
+
const names=new Map([['--workflow','workflow'],['--event','event'],['--phase','phase'],['--runtime','runtime'],['--project','project'],
|
|
514
|
+
['--project-root','projectRoot'],['--specs-dir','specsDir'],['--run-id','runId'],['--at','at'],['--detail','detail'],['--data-json','dataJson']]);
|
|
515
|
+
const result={dataJson:'{}'};
|
|
516
|
+
for(let index=0;index<argv.length;index+=2){
|
|
517
|
+
const key=names.get(argv[index]),value=argv[index+1];if(!key||value===undefined)throw new UsageError('invalid arguments');result[key]=value;
|
|
518
|
+
}
|
|
519
|
+
for(const key of ['workflow','event','runtime','detail'])if(!Object.hasOwn(result,key))throw new UsageError(`--${key.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`)} is required`);
|
|
520
|
+
return result;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function asciiJson(value){return JSON.stringify(value).replace(/[\u007f-\uffff]/g,character=>`\\u${character.charCodeAt(0).toString(16).padStart(4,'0')}`);}
|
|
524
|
+
function usage(){return 'usage: cm-log-event.py --workflow NAME --event NAME --runtime NAME --detail TEXT [options]';}
|
|
525
|
+
|
|
526
|
+
export function main(argv=process.argv.slice(2),environment=process.env){
|
|
527
|
+
try{
|
|
528
|
+
const input=parseCli(argv);if(input.help){process.stdout.write(`${usage()}\n`);return 0;}
|
|
529
|
+
if(environment.CM_LOG_PREFLIGHT==='1'){prepareInput(input);return 0;}
|
|
530
|
+
const result=writeLogEvent(input,{environment});process.stdout.write(`${asciiJson(result)}\n`);return 0;
|
|
531
|
+
}catch(error){process.stderr.write(`cm-log-event: ${error.message}\n`);return error instanceof UsageError?2:1;}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function isMain(entry){
|
|
535
|
+
if(!entry)return false;
|
|
536
|
+
try{return fs.realpathSync(entry)===fileURLToPath(import.meta.url);}catch{return path.resolve(entry)===fileURLToPath(import.meta.url);}
|
|
537
|
+
}
|
|
538
|
+
if(isMain(process.argv[1]))process.exitCode=main();
|