@aibyzero/cm-workflow 0.17.1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +23 -0
- package/CHANGELOG.md +224 -0
- package/README.md +14 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/VERSION +1 -1
- package/compat/claude-commands/cm-challenge.md +3 -0
- package/docs/architecture.md +11 -0
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +150 -15
- package/docs/live-evidence-drivers.md +28 -4
- package/docs/out-of-scope/README.md +25 -0
- package/docs/out-of-scope/background-supervisor.md +32 -0
- package/docs/reviewed-integration.md +48 -0
- package/docs/user-guide.md +50 -21
- package/install-codex.sh +331 -18
- package/install.ps1 +28 -2
- package/install.sh +321 -17
- package/package.json +2 -1
- package/runtime/js/cm-ai/batch-location.mjs +55 -0
- package/runtime/js/cm-ai/batch-plan.mjs +242 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
- package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -2
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
- package/runtime/js/cm-ai/control-policy.mjs +21 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +114 -11
- package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
- package/runtime/js/cm-ai/effect-contract.mjs +11 -2
- package/runtime/js/cm-ai/execution-policy.mjs +3 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
- package/runtime/js/cm-ai/execution-store.mjs +60 -17
- package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
- package/runtime/js/cm-ai/host-check.mjs +11 -5
- package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
- package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
- package/runtime/js/cm-ai/host-replay.mjs +148 -0
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
- package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
- package/runtime/js/cm-ai/live-evidence.mjs +28 -6
- package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
- package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
- package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
- package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
- package/runtime/js/cm-ai/review-package.mjs +79 -7
- package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
- package/runtime/js/cm-ai/review-presentation.mjs +177 -8
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
- package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
- package/runtime/js/cm-ai/scope-revision.mjs +38 -0
- package/runtime/js/cm-ai/specification-material.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +242 -39
- package/runtime/js/cm-ai/verification-auto.mjs +38 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
- package/runtime/js/cm-ai/worker-claude.mjs +35 -13
- package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
- package/runtime/js/cm-ai/worker-codex.mjs +41 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
- package/runtime/js/cm-fix/cause-package.mjs +46 -1
- package/runtime/js/cm-fix/command-correction.mjs +37 -0
- package/runtime/js/cm-fix/cooperative.mjs +12 -0
- package/runtime/js/cm-fix/dossier.mjs +8 -2
- package/runtime/js/cm-fix/execution.mjs +578 -100
- package/runtime/js/cm-fix/final-review.mjs +39 -8
- package/runtime/js/cm-fix/finish.mjs +15 -11
- package/runtime/js/cm-fix/host-review.mjs +65 -10
- package/runtime/js/cm-fix/host.mjs +35 -12
- package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
- package/runtime/js/cm-fix/metrics.mjs +18 -5
- package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
- package/runtime/js/cm-fix/regression.mjs +16 -7
- package/runtime/js/cm-fix/repair.mjs +29 -8
- package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
- package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
- package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
- package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
- package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
- package/runtime/js/cm-fix/review-verification.mjs +214 -0
- package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
- package/runtime/js/cm-fix/start.mjs +6 -3
- package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
- package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
- package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
- package/runtime/js/cm-prd/accepted-design.mjs +8 -0
- package/runtime/js/cm-prd/analysis.mjs +13 -9
- package/runtime/js/cm-prd/change.mjs +37 -16
- package/runtime/js/cm-prd/draft-save.mjs +13 -6
- package/runtime/js/cm-prd/draft.mjs +31 -3
- package/runtime/js/cm-prd/failed-correction.mjs +19 -3
- package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
- package/runtime/js/cm-prd/review-correction.mjs +6 -4
- package/runtime/js/cm-prd/review-disposition.mjs +7 -1
- package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
- package/runtime/js/cm-prd/self-check.mjs +125 -6
- package/runtime/js/cm-prd/session.mjs +30 -1
- package/runtime/js/cm-prd/summary.mjs +11 -5
- package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
- package/runtime/js/cm-prd/tree-digest.mjs +34 -0
- package/runtime/js/cm-prd/validation-reason.mjs +8 -4
- package/runtime/js/cm-security/scan.mjs +1 -1
- package/runtime/js/commander/decision.mjs +44 -0
- package/runtime/js/commander/dispatch-registry.mjs +110 -0
- package/runtime/js/commander/ledger.mjs +265 -0
- package/runtime/js/commander/preflight.mjs +107 -0
- package/runtime/js/notify-later.mjs +13 -0
- package/runtime/js/notify-send.mjs +6 -2
- package/runtime/js/notify.mjs +570 -63
- package/runtime/js/review-findings.mjs +38 -0
- package/runtime/js/session-boundary.mjs +56 -0
- package/runtime/js/session-handoff.mjs +68 -0
- package/runtime/js/spec-task-line.mjs +27 -13
- package/runtime/js/specs-status.mjs +1 -1
- package/runtime/js/task-scope.mjs +197 -0
- package/runtime/logging.md +6 -1
- package/runtime/model-efficiency.md +69 -10
- package/runtime/orchestration.md +3 -1
- package/runtime/project-learning.md +2 -0
- package/runtime/review.md +3 -2
- package/runtime/test-contract.md +1 -0
- package/scripts/ci-test-weights.json +3 -0
- package/scripts/cm-ai-admission.mjs +11 -5
- package/scripts/cm-ai-admission.test.mjs +23 -2
- package/scripts/cm-ai-batch-drive.mjs +79 -18
- package/scripts/cm-ai-batch-drive.test.mjs +169 -3
- package/scripts/cm-ai-batch-host.mjs +38 -9
- package/scripts/cm-ai-batch-host.test.mjs +6 -5
- package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
- package/scripts/cm-ai-batch-location.test.mjs +57 -0
- package/scripts/cm-ai-batch-plan.mjs +52 -0
- package/scripts/cm-ai-batch-plan.test.mjs +397 -0
- package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
- package/scripts/cm-ai-batch-run.mjs +471 -57
- package/scripts/cm-ai-batch-run.test.mjs +23 -4
- package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
- package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
- package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
- package/scripts/cm-ai-control-launch.test.mjs +21 -0
- package/scripts/cm-ai-control-policy.test.mjs +14 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
- package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
- package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
- package/scripts/cm-ai-development-rework.test.mjs +423 -0
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +34 -2
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
- package/scripts/cm-ai-integration-independence.test.mjs +23 -0
- package/scripts/cm-ai-integration-launch.test.mjs +240 -0
- package/scripts/cm-ai-integration-preview.mjs +41 -0
- package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
- package/scripts/cm-ai-nested-execution.test.mjs +29 -1
- package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
- package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
- package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
- package/scripts/cm-ai-review-failure.test.mjs +150 -5
- package/scripts/cm-ai-run.mjs +88 -21
- package/scripts/cm-ai-scope-revision.test.mjs +341 -0
- package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
- package/scripts/cm-ai-supersede.test.mjs +28 -0
- package/scripts/cm-ai-verification-auto.test.mjs +99 -0
- package/scripts/cm-announce-hook.mjs +35 -8
- package/scripts/cm-announce-hook.test.mjs +25 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +58 -1
- package/scripts/cm-claude-developer-worker.test.mjs +56 -7
- package/scripts/cm-claude-install-layout.test.mjs +1 -1
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +13 -0
- package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
- package/scripts/cm-codex-developer-worker.test.mjs +120 -0
- package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
- package/scripts/cm-codex-prompt-input.test.mjs +153 -0
- package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
- package/scripts/cm-commander-ledger.test.mjs +260 -0
- package/scripts/cm-commander-p2.test.mjs +295 -0
- package/scripts/cm-commander-preflight.mjs +84 -0
- package/scripts/cm-commander.mjs +116 -0
- package/scripts/cm-config-lock.mjs +35 -0
- package/scripts/cm-controlled-correction.test.mjs +10 -1
- package/scripts/cm-developer-failure-code.test.mjs +62 -0
- package/scripts/cm-display-task-id.test.mjs +41 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
- package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
- package/scripts/cm-external-batch-host.test.mjs +4 -3
- package/scripts/cm-external-process-cleanup.test.mjs +128 -0
- package/scripts/cm-external-qa-fix.test.mjs +89 -7
- package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
- package/scripts/cm-failover.mjs +48 -10
- package/scripts/cm-failover.test.mjs +46 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
- package/scripts/cm-fix-command-correction.mjs +17 -0
- package/scripts/cm-fix-command-correction.test.mjs +211 -0
- package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
- package/scripts/cm-fix-drive.mjs +33 -5
- package/scripts/cm-fix-drive.test.mjs +49 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
- package/scripts/cm-fix-host-review.test.mjs +21 -9
- package/scripts/cm-fix-host.mjs +26 -8
- package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
- package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
- package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
- package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
- package/scripts/cm-fix-review-preflight.mjs +24 -0
- package/scripts/cm-fix-review-storage.test.mjs +233 -0
- package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
- package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
- package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
- package/scripts/cm-fix-review-verification.test.mjs +146 -0
- package/scripts/cm-fix-revision-transport.test.mjs +81 -0
- package/scripts/cm-fix-source-correction.test.mjs +296 -0
- package/scripts/cm-fix-test-type-correction.mjs +18 -0
- package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
- package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
- package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
- package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
- package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
- package/scripts/cm-fix-verification-recovery.mjs +33 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
- package/scripts/cm-install-manifest.sh +351 -0
- package/scripts/cm-live-evidence.test.mjs +59 -1
- package/scripts/cm-log-event.mjs +61 -10
- package/scripts/cm-log-event.test.mjs +121 -1
- package/scripts/cm-matt-skills.mjs +576 -0
- package/scripts/cm-matt-skills.test.mjs +550 -0
- package/scripts/cm-notify-command.test.mjs +42 -10
- package/scripts/cm-notify.mjs +14 -10
- package/scripts/cm-notify.test.mjs +575 -59
- package/scripts/cm-patrol.mjs +4 -1
- package/scripts/cm-patrol.test.mjs +23 -5
- package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
- package/scripts/cm-prd-completion.test.mjs +56 -13
- package/scripts/cm-prd-design-phase.test.mjs +78 -8
- package/scripts/cm-prd-draft-save.test.mjs +12 -0
- package/scripts/cm-prd-draft.test.mjs +1 -1
- package/scripts/cm-prd-drive.mjs +13 -6
- package/scripts/cm-prd-drive.test.mjs +45 -1
- package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
- package/scripts/cm-prd-host.mjs +10 -5
- package/scripts/cm-prd-host.test.mjs +4 -2
- package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
- package/scripts/cm-prd-review-disposition.test.mjs +124 -8
- package/scripts/cm-prd-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
- package/scripts/cm-prd-self-check.test.mjs +105 -5
- package/scripts/cm-prd-summary.test.mjs +24 -3
- package/scripts/cm-prd-task-grouping.test.mjs +6 -6
- package/scripts/cm-prd-tree-digest.test.mjs +74 -0
- package/scripts/cm-refactor-drive.mjs +2 -1
- package/scripts/cm-refactor-drive.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +1 -1
- package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
- package/scripts/cm-skill-hints-exam.mjs +149 -0
- package/scripts/cm-skill-hints-install.test.mjs +168 -0
- package/scripts/cm-skill-hints.exam.json +706 -0
- package/scripts/cm-skill-hints.json +119 -0
- package/scripts/cm-skill-hints.mjs +669 -0
- package/scripts/cm-skill-hints.test.mjs +831 -0
- package/scripts/cm-skill-judge.mjs +181 -0
- package/scripts/cm-skill-judge.test.mjs +255 -0
- package/scripts/cm-specs-status.test.mjs +4 -2
- package/scripts/cm-start-check.mjs +208 -0
- package/scripts/cm-start-check.test.mjs +321 -0
- package/scripts/cm-task-gate.mjs +150 -29
- package/scripts/cm-task-gate.test.mjs +73 -1
- package/scripts/cm-task-id-grammar.test.mjs +66 -0
- package/scripts/cm-task-scope.test.mjs +308 -0
- package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
- package/scripts/cm-upgrade-compat.test.mjs +239 -0
- package/scripts/cm-workflow-config.mjs +12 -2
- package/scripts/fixtures/fix-verification-claude.mjs +44 -0
- package/scripts/fixtures/reviewed-integration.mjs +202 -0
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/session-boundary.test.mjs +170 -0
- package/scripts/test-npm-install.py +14 -3
- package/scripts/test-shell-compat.sh +2 -0
- package/scripts/validate-public-repo.py +1 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N4-review.md +2 -1
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/N8-finish.md +22 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
- package/skills/cm-ai/references/js-host-recovery.md +79 -3
- package/skills/cm-ai/references/js-host.md +56 -16
- package/skills/cm-challenge/SKILL.md +65 -0
- package/skills/cm-challenge/evals/README.md +18 -0
- package/skills/cm-challenge/evals/trigger-cases.json +20 -0
- package/skills/cm-challenge/evals/trigger-config.json +28 -0
- package/skills/cm-challenge/references/examples.md +15 -0
- package/skills/cm-check/SKILL.md +5 -0
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +12 -3
- package/skills/cm-fix/references/command-correction.md +67 -0
- package/skills/cm-fix/references/isolated-review.md +54 -0
- package/skills/cm-fix/references/js-host.md +62 -2
- package/skills/cm-fix/references/test-type-correction.md +72 -0
- package/skills/cm-fix/references/verification-recovery.md +114 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-notify/SKILL.md +2 -0
- package/skills/cm-prd/SKILL.md +12 -8
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +6 -0
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-host.md +4 -2
- package/skills/cm-prd/references/spec-self-check.md +5 -1
- package/skills/cm-refactor/SKILL.md +8 -0
- package/skills/cm-refactor/references/js-host.md +2 -0
- package/skills/cm-test/SKILL.md +4 -0
- package/templates/dashboard/dashboard.html +2 -2
- package/templates/pixel/cm-pixel.html +1 -1
- package/templates/pixel/cm-pixel.sh +1 -1
- package/templates/pixel/dev/template.html +1 -1
- package/templates/statusline/cm-statusline.sh +1 -1
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
// Install-time default for skill hints (decided 2026-10-25): every install wires the
|
|
2
|
+
// hint hook for its own host, unless the user said no (--no-skill-hints,
|
|
3
|
+
// CM_SKILL_HINTS_INSTALL=off, "enabled": false) or removed the hook after it was there.
|
|
4
|
+
// Every case runs in a disposable HOME; no real config, key or Jev is touched.
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import {withConfigLock} from './cm-config-lock.mjs';
|
|
11
|
+
import {
|
|
12
|
+
install,enable,main,hook,statusText,hasHintHook,hookCommand,settledHosts,
|
|
13
|
+
loadRules,localPath,installDir,autoPath,claudeSettingsPath,codexHooksPath,SCRIPT_NAME,
|
|
14
|
+
} from './cm-skill-hints.mjs';
|
|
15
|
+
|
|
16
|
+
const NODE='/usr/bin/node';
|
|
17
|
+
|
|
18
|
+
function box(t){
|
|
19
|
+
const home=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-skill-hints-auto-')));
|
|
20
|
+
t.after(()=>fs.rmSync(home,{recursive:true,force:true}));
|
|
21
|
+
const env={HOME:home,CLAUDE_HOME:path.join(home,'.claude'),CODEX_HOME:path.join(home,'.codex'),
|
|
22
|
+
CM_WORKFLOW_HOME:path.join(home,'.cm-workflow'),CM_WORKFLOW_LOG_HOME:path.join(home,'.cm-workflow','logs')};
|
|
23
|
+
const file=host=>host==='codex'?codexHooksPath(env):claudeSettingsPath(env);
|
|
24
|
+
const read=host=>{try{return JSON.parse(fs.readFileSync(file(host),'utf8'));}catch{return undefined;}};
|
|
25
|
+
const wired=host=>hasHintHook(read(host),env,host);
|
|
26
|
+
const ours=host=>(read(host)?.hooks?.UserPromptSubmit??[]).filter(group=>hasHintHook({hooks:{UserPromptSubmit:[group]}},env,host)).length;
|
|
27
|
+
const run=async(host,options={})=>{
|
|
28
|
+
let out='';
|
|
29
|
+
const code=await install({env,host,node:NODE,write:text=>{out+=text;},...options});
|
|
30
|
+
return {code,out};
|
|
31
|
+
};
|
|
32
|
+
const writeConfig=(host,value)=>{
|
|
33
|
+
fs.mkdirSync(path.dirname(file(host)),{recursive:true});
|
|
34
|
+
fs.writeFileSync(file(host),typeof value==='string'?value:JSON.stringify(value,null,2)+'\n');
|
|
35
|
+
};
|
|
36
|
+
return {home,env,file,read,wired,ours,run,writeConfig};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
test('first install wires only its own host, records it and says how to turn it off',async t=>{
|
|
40
|
+
const b=box(t);
|
|
41
|
+
const claude=await b.run('claude');
|
|
42
|
+
assert.equal(claude.code,0,claude.out);
|
|
43
|
+
assert.ok(b.wired('claude'));
|
|
44
|
+
assert.ok(!fs.existsSync(b.file('codex')),'the Claude install must not touch Codex');
|
|
45
|
+
assert.ok(fs.existsSync(path.join(installDir(b.env),SCRIPT_NAME)));
|
|
46
|
+
assert.deepEqual(settledHosts(b.env).hosts,['claude']);
|
|
47
|
+
assert.match(claude.out,/已给 Claude 挂上技能提醒钩子/);
|
|
48
|
+
assert.match(claude.out,/"enabled": false/);
|
|
49
|
+
// Turning hints off is "enabled": false; --no-skill-hints only stops an install from adding the hook.
|
|
50
|
+
assert.match(claude.out,/关掉提醒:在 .* 写 \{"enabled": false\}/);
|
|
51
|
+
assert.match(claude.out,/--no-skill-hints 只是不自动挂,不会摘掉已挂的钩子/);
|
|
52
|
+
assert.doesNotMatch(claude.out,/或重装时加 --no-skill-hints/);
|
|
53
|
+
assert.match(claude.out,/TypeSafe.*500/);
|
|
54
|
+
assert.doesNotMatch(claude.out,/信任/);
|
|
55
|
+
|
|
56
|
+
const codex=await b.run('codex');
|
|
57
|
+
assert.equal(codex.code,0,codex.out);
|
|
58
|
+
assert.ok(b.wired('codex'));
|
|
59
|
+
assert.match(b.read('codex').hooks.UserPromptSubmit[0].hooks[0].command,/--host codex$/);
|
|
60
|
+
assert.match(codex.out,/Codex 首次运行这条钩子时会请你确认信任/);
|
|
61
|
+
assert.deepEqual(settledHosts(b.env).hosts.sort(),['claude','codex']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('a repeated install keeps one hook and leaves the config bytes alone',async t=>{
|
|
65
|
+
const b=box(t);
|
|
66
|
+
b.writeConfig('claude',{statusLine:{command:'x'},hooks:{UserPromptSubmit:[{hooks:[{type:'command',command:'other'}]}]}});
|
|
67
|
+
assert.equal((await b.run('claude')).code,0);
|
|
68
|
+
const after=fs.readFileSync(b.file('claude'),'utf8');
|
|
69
|
+
assert.equal(b.read('claude').statusLine.command,'x');
|
|
70
|
+
assert.equal(b.read('claude').hooks.UserPromptSubmit.length,2);
|
|
71
|
+
const again=await b.run('claude');
|
|
72
|
+
assert.equal(again.code,0,again.out);
|
|
73
|
+
assert.equal(fs.readFileSync(b.file('claude'),'utf8'),after);
|
|
74
|
+
assert.equal(b.ours('claude'),1);
|
|
75
|
+
assert.doesNotMatch(again.out,/已给 Claude 挂上/);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
for(const [label,options,env,local,settles] of [
|
|
79
|
+
['the --no-skill-hints flag',{skip:true},{},undefined,false],
|
|
80
|
+
['CM_SKILL_HINTS_INSTALL=off',{},{CM_SKILL_HINTS_INSTALL:'off'},undefined,false],
|
|
81
|
+
['"enabled": false in the local file',{},{},{enabled:false},false],
|
|
82
|
+
]){
|
|
83
|
+
test(`${label} keeps a fresh install from wiring anything`,async t=>{
|
|
84
|
+
const b=box(t);
|
|
85
|
+
if(local){fs.mkdirSync(b.env.CM_WORKFLOW_HOME,{recursive:true});fs.writeFileSync(localPath(b.env),JSON.stringify(local));}
|
|
86
|
+
Object.assign(b.env,env);
|
|
87
|
+
for(const host of ['claude','codex']){
|
|
88
|
+
const result=await b.run(host,options);
|
|
89
|
+
assert.equal(result.code,0,result.out);
|
|
90
|
+
assert.match(result.out,/没给 (Claude|Codex) 挂/);
|
|
91
|
+
assert.ok(!fs.existsSync(b.file(host)));
|
|
92
|
+
}
|
|
93
|
+
assert.ok(!fs.existsSync(installDir(b.env)));
|
|
94
|
+
// The flag and the variable are for this run only, and "enabled": false is a switch of
|
|
95
|
+
// its own: none of them settles a host.
|
|
96
|
+
assert.deepEqual(settledHosts(b.env).hosts.sort(),settles?['claude','codex']:[]);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
test('an opt-out by flag or variable covers that run only: a later plain install wires the host',async t=>{
|
|
101
|
+
const b=box(t);
|
|
102
|
+
const skipped=await b.run('claude',{skip:true});
|
|
103
|
+
assert.match(skipped.out,/只管这一次/);
|
|
104
|
+
assert.doesNotMatch(skipped.out,/以后安装也不会自动挂/);
|
|
105
|
+
const off=await install({env:{...b.env,CM_SKILL_HINTS_INSTALL:'off'},host:'claude',node:NODE,write:()=>{}});
|
|
106
|
+
assert.equal(off,0);
|
|
107
|
+
assert.ok(!fs.existsSync(b.file('claude')));
|
|
108
|
+
const plain=await b.run('claude');
|
|
109
|
+
assert.equal(plain.code,0,plain.out);
|
|
110
|
+
assert.ok(b.wired('claude'));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('an opt-out run keeps an existing hook and says how to really turn hints off',async t=>{
|
|
114
|
+
const b=box(t);
|
|
115
|
+
await b.run('claude');
|
|
116
|
+
const result=await b.run('claude',{skip:true});
|
|
117
|
+
assert.equal(result.code,0,result.out);
|
|
118
|
+
assert.ok(b.wired('claude'));
|
|
119
|
+
assert.match(result.out,/已挂着的钩子不受影响.*"enabled": false/);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('an opted-out run still refreshes the copy of a user who already has hints',async t=>{
|
|
123
|
+
const b=box(t);
|
|
124
|
+
await b.run('claude');
|
|
125
|
+
fs.writeFileSync(path.join(installDir(b.env),SCRIPT_NAME),'// old version\n');
|
|
126
|
+
const result=await b.run('claude',{skip:true});
|
|
127
|
+
assert.equal(result.code,0,result.out);
|
|
128
|
+
assert.notEqual(fs.readFileSync(path.join(installDir(b.env),SCRIPT_NAME),'utf8'),'// old version\n');
|
|
129
|
+
assert.ok(b.wired('claude'),'opting out of the install default never removes a hook');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('a hook the user removed is not added back by a later install',async t=>{
|
|
133
|
+
const b=box(t);
|
|
134
|
+
b.writeConfig('claude',{model:'opus'});
|
|
135
|
+
await b.run('claude');
|
|
136
|
+
// The user takes our hook out again, keeping the rest.
|
|
137
|
+
b.writeConfig('claude',{model:'opus',hooks:{UserPromptSubmit:[]}});
|
|
138
|
+
const before=fs.readFileSync(b.file('claude'),'utf8');
|
|
139
|
+
const result=await b.run('claude');
|
|
140
|
+
assert.equal(result.code,0,result.out);
|
|
141
|
+
assert.equal(fs.readFileSync(b.file('claude'),'utf8'),before);
|
|
142
|
+
assert.match(result.out,/之前挂过后被移除/);
|
|
143
|
+
assert.match(result.out,/enable --claude/);
|
|
144
|
+
// Explicit enable still works and the next install leaves it in place.
|
|
145
|
+
assert.equal(await enable({env:b.env,hosts:['claude'],node:NODE,write:()=>{}}),0);
|
|
146
|
+
assert.ok(b.wired('claude'));
|
|
147
|
+
assert.equal((await b.run('claude')).code,0);
|
|
148
|
+
assert.equal(b.ours('claude'),1);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('enabling one host by hand does not count as removing the other',async t=>{
|
|
152
|
+
const b=box(t);
|
|
153
|
+
assert.equal(await enable({env:b.env,hosts:['claude'],node:NODE,write:()=>{}}),0);
|
|
154
|
+
assert.ok(fs.existsSync(installDir(b.env)));
|
|
155
|
+
const result=await b.run('codex');
|
|
156
|
+
assert.equal(result.code,0,result.out);
|
|
157
|
+
assert.ok(b.wired('codex'));
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('a copy made before this record existed counts as the user\'s own choice for both hosts',async t=>{
|
|
161
|
+
const b=box(t);
|
|
162
|
+
// An earlier `enable --claude`: copy directory and Claude hook, no record.
|
|
163
|
+
fs.mkdirSync(installDir(b.env),{recursive:true});
|
|
164
|
+
b.writeConfig('claude',{hooks:{UserPromptSubmit:[{hooks:[{type:'command',command:hookCommand(b.env,'claude',NODE)}]}]}});
|
|
165
|
+
const codex=await b.run('codex');
|
|
166
|
+
assert.equal(codex.code,0,codex.out);
|
|
167
|
+
assert.ok(!fs.existsSync(b.file('codex')));
|
|
168
|
+
assert.match(codex.out,/没给 Codex 挂/);
|
|
169
|
+
assert.equal((await b.run('claude')).code,0);
|
|
170
|
+
assert.ok(b.wired('claude'));
|
|
171
|
+
assert.deepEqual(settledHosts(b.env).hosts.sort(),['claude','codex']);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('a config that cannot be read or has the wrong shape is left alone and retried next time',async t=>{
|
|
175
|
+
const b=box(t);
|
|
176
|
+
b.writeConfig('claude','{broken');
|
|
177
|
+
const broken=await b.run('claude');
|
|
178
|
+
assert.equal(broken.code,1);
|
|
179
|
+
assert.equal(fs.readFileSync(b.file('claude'),'utf8'),'{broken');
|
|
180
|
+
assert.match(broken.out,/未改动/);
|
|
181
|
+
assert.ok(!settledHosts(b.env).hosts.includes('claude'));
|
|
182
|
+
b.writeConfig('codex',{hooks:{UserPromptSubmit:{}}});
|
|
183
|
+
const shaped=await b.run('codex');
|
|
184
|
+
assert.equal(shaped.code,1);
|
|
185
|
+
assert.match(shaped.out,/格式异常/);
|
|
186
|
+
// Once the user fixes the file, the next install wires it.
|
|
187
|
+
b.writeConfig('claude',{});
|
|
188
|
+
assert.equal((await b.run('claude')).code,0);
|
|
189
|
+
assert.ok(b.wired('claude'));
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('a local file that cannot be read keeps the install from wiring, with a warning',async t=>{
|
|
193
|
+
const b=box(t);
|
|
194
|
+
fs.mkdirSync(b.env.CM_WORKFLOW_HOME,{recursive:true});
|
|
195
|
+
fs.writeFileSync(localPath(b.env),'{"enabled": fals');
|
|
196
|
+
const result=await b.run('claude');
|
|
197
|
+
assert.equal(result.code,0);
|
|
198
|
+
assert.match(result.out,/⚠.*读取失败.*没给 Claude 挂/);
|
|
199
|
+
assert.ok(!fs.existsSync(b.file('claude')));
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('a failure only warns: a linked copy directory is never written through',async t=>{
|
|
203
|
+
const b=box(t);
|
|
204
|
+
const elsewhere=path.join(b.home,'elsewhere');
|
|
205
|
+
fs.mkdirSync(elsewhere);
|
|
206
|
+
fs.mkdirSync(b.env.CM_WORKFLOW_HOME,{recursive:true});
|
|
207
|
+
fs.symlinkSync(elsewhere,installDir(b.env));
|
|
208
|
+
const result=await b.run('claude');
|
|
209
|
+
assert.equal(result.code,1);
|
|
210
|
+
assert.match(result.out,/✗|⚠/);
|
|
211
|
+
assert.deepEqual(fs.readdirSync(elsewhere),[]);
|
|
212
|
+
assert.ok(!b.wired('claude'));
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('main install takes --host and --no-skill-hints; a bad host is a usage error',async t=>{
|
|
216
|
+
const b=box(t);
|
|
217
|
+
const quiet={env:b.env,write:()=>{},error:()=>{}};
|
|
218
|
+
assert.equal(await main(['install','--host','codex','--no-skill-hints'],quiet),0);
|
|
219
|
+
assert.ok(!fs.existsSync(b.file('codex')));
|
|
220
|
+
assert.equal(await main(['install','--host','claude'],quiet),0);
|
|
221
|
+
assert.ok(b.wired('claude'));
|
|
222
|
+
assert.equal(await main(['install','--host','other'],quiet),2);
|
|
223
|
+
assert.equal(await main(['install'],quiet),2);
|
|
224
|
+
assert.equal(await main(['install','--host','claude','--extra'],quiet),2);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// ---- review round 1 ----
|
|
228
|
+
|
|
229
|
+
const recordText=b=>fs.existsSync(autoPath(b.env))?fs.readFileSync(autoPath(b.env),'utf8'):null;
|
|
230
|
+
const writeRecord=(b,text)=>{fs.mkdirSync(b.env.CM_WORKFLOW_HOME,{recursive:true});fs.writeFileSync(autoPath(b.env),text);};
|
|
231
|
+
|
|
232
|
+
test('the record is re-read and merged under the lock: another installer\'s host is not lost',async t=>{
|
|
233
|
+
const b=box(t);
|
|
234
|
+
await b.run('claude');
|
|
235
|
+
fs.rmSync(autoPath(b.env));
|
|
236
|
+
writeRecord(b,'{"version":1,"hosts":[]}\n');
|
|
237
|
+
// Claude is wired. The Codex installer records codex after anything this install could
|
|
238
|
+
// have read and right before this install gets the lock: only a read under the lock sees it.
|
|
239
|
+
const lockRecord=(env,file,fn,options)=>{
|
|
240
|
+
writeRecord(b,'{"version":1,"hosts":["codex"]}\n');
|
|
241
|
+
return withConfigLock(env,file,fn,options);
|
|
242
|
+
};
|
|
243
|
+
const result=await b.run('claude',{lockRecord});
|
|
244
|
+
assert.equal(result.code,0,result.out);
|
|
245
|
+
assert.deepEqual(settledHosts(b.env).hosts.sort(),['claude','codex']);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test('a record changed between read and replace is not overwritten',async t=>{
|
|
249
|
+
const b=box(t);
|
|
250
|
+
await b.run('claude');
|
|
251
|
+
writeRecord(b,'{"version":1,"hosts":[]}\n');
|
|
252
|
+
const result=await b.run('claude',{beforeRecordReplace:()=>writeRecord(b,'{"version":1,"hosts":["codex"]}\n')});
|
|
253
|
+
assert.equal(result.code,1);
|
|
254
|
+
assert.match(result.out,/⚠.*未能记下/);
|
|
255
|
+
assert.equal(recordText(b),'{"version":1,"hosts":["codex"]}\n');
|
|
256
|
+
assert.ok(b.wired('claude'));
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
for(const [label,text] of [
|
|
260
|
+
['an empty object','{}'],
|
|
261
|
+
['hosts as a string','{"version":1,"hosts":"claude"}'],
|
|
262
|
+
['an unknown version','{"version":2,"hosts":[]}'],
|
|
263
|
+
['an unknown host','{"version":1,"hosts":["vim"]}'],
|
|
264
|
+
['broken JSON','{"version":1,'],
|
|
265
|
+
]){
|
|
266
|
+
test(`a record with ${label} is kept as is, nothing is wired and the install warns`,async t=>{
|
|
267
|
+
const b=box(t);
|
|
268
|
+
writeRecord(b,text);
|
|
269
|
+
const fresh=await b.run('codex');
|
|
270
|
+
assert.equal(fresh.code,1);
|
|
271
|
+
assert.match(fresh.out,/⚠.*skill-hints\.auto\.json.*异常.*没给 Codex 挂/);
|
|
272
|
+
assert.ok(!fs.existsSync(b.file('codex')));
|
|
273
|
+
// A wired host does not overwrite it either.
|
|
274
|
+
b.writeConfig('claude',{hooks:{UserPromptSubmit:[{hooks:[{type:'command',command:hookCommand(b.env,'claude',NODE)}]}]}});
|
|
275
|
+
const wired=await b.run('claude');
|
|
276
|
+
assert.equal(wired.code,1);
|
|
277
|
+
assert.match(wired.out,/⚠.*异常/);
|
|
278
|
+
assert.equal(recordText(b),text);
|
|
279
|
+
// Status names the pause.
|
|
280
|
+
assert.match(statusText({env:b.env}),/安装时自动挂:暂停(.*skill-hints\.auto\.json.*异常/);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
for(const [label,text] of [['a list','[]'],['null','null'],['enabled as a string','{"enabled":"false"}'],
|
|
285
|
+
['judge as a string','{"judge":"false"}'],['rules as an object','{"rules":{}}'],['disable as a string','{"disable":"fix-bug"}'],
|
|
286
|
+
['disable with a number','{"disable":["fix-bug",1]}']]){
|
|
287
|
+
test(`a local file holding ${label} keeps the install from wiring, with a warning`,async t=>{
|
|
288
|
+
const b=box(t);
|
|
289
|
+
fs.mkdirSync(b.env.CM_WORKFLOW_HOME,{recursive:true});
|
|
290
|
+
fs.writeFileSync(localPath(b.env),text);
|
|
291
|
+
const result=await b.run('claude');
|
|
292
|
+
assert.match(result.out,/⚠.*格式异常.*没给 Claude 挂/);
|
|
293
|
+
assert.ok(!fs.existsSync(b.file('claude')));
|
|
294
|
+
assert.ok(!fs.existsSync(installDir(b.env)));
|
|
295
|
+
assert.equal(fs.readFileSync(localPath(b.env),'utf8'),text);
|
|
296
|
+
assert.match(statusText({env:b.env}),/安装时自动挂:暂停/);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
test('a first copy that fails half way is retried by the next install, not taken for an old enable',async t=>{
|
|
301
|
+
const b=box(t);
|
|
302
|
+
const failed=await b.run('claude',{copyFiles:env=>{fs.mkdirSync(installDir(env),{recursive:true});throw new Error('disk full');}});
|
|
303
|
+
assert.equal(failed.code,1);
|
|
304
|
+
assert.ok(fs.existsSync(installDir(b.env)));
|
|
305
|
+
const again=await b.run('claude');
|
|
306
|
+
assert.equal(again.code,0,again.out);
|
|
307
|
+
assert.ok(b.wired('claude'));
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('an install that finds the hook wired warns when the record cannot be written',async t=>{
|
|
311
|
+
const b=box(t);
|
|
312
|
+
const {lockPath}=await import('./cm-config-lock.mjs');
|
|
313
|
+
b.writeConfig('claude',{hooks:{UserPromptSubmit:[{hooks:[{type:'command',command:hookCommand(b.env,'claude',NODE)}]}]}});
|
|
314
|
+
const lock=lockPath(b.env,autoPath(b.env));
|
|
315
|
+
fs.mkdirSync(path.dirname(lock),{recursive:true});
|
|
316
|
+
fs.writeFileSync(lock,'other');
|
|
317
|
+
const result=await b.run('claude',{lockWaitMs:100});
|
|
318
|
+
assert.equal(result.code,1);
|
|
319
|
+
assert.match(result.out,/⚠.*未能记下/);
|
|
320
|
+
assert.ok(!fs.existsSync(autoPath(b.env)));
|
|
321
|
+
assert.ok(b.wired('claude'));
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Decided 2026-10-25 (review round 3): a local file with any problem pauses hints as a whole,
|
|
325
|
+
// so a valid "enabled": false next to a broken field is never lost.
|
|
326
|
+
test('at run time a local file with any problem pauses hints: no hint, no skill started, nothing sent to Jev',async t=>{
|
|
327
|
+
const b=box(t);
|
|
328
|
+
const rulesFile=path.join(b.home,'rules.json');
|
|
329
|
+
fs.writeFileSync(rulesFile,JSON.stringify({version:1,rules:[{id:'fix-bug',skill:'cm-fix',keywords:['修这个 bug'],reason:'先复现'}]}));
|
|
330
|
+
fs.mkdirSync(b.env.CM_WORKFLOW_HOME,{recursive:true});
|
|
331
|
+
const send=async session=>hook({prompt:'修这个 bug',session_id:session},{env:b.env,host:'claude',rulesFile,
|
|
332
|
+
loadJudgeModule:async()=>{throw new Error('Jev must not be loaded');}});
|
|
333
|
+
fs.writeFileSync(localPath(b.env),'{"judge":true,"enabled":true,"rules":[],"disable":["x"]}');
|
|
334
|
+
assert.match(JSON.parse(await send('ok')).systemMessage,/cm-fix/);
|
|
335
|
+
assert.equal(loadRules({env:b.env,rulesFile}).localError,null);
|
|
336
|
+
for(const text of ['{"enabled": false, "rules": {}}','{oops','{"judge":"false"}','{"disable":"fix-bug"}','{"enabled":"false"}','[]','null','',' \n\t ']){
|
|
337
|
+
fs.writeFileSync(localPath(b.env),text);
|
|
338
|
+
assert.equal(await send(`s-${text}`),'',text);
|
|
339
|
+
const loaded=loadRules({env:b.env,rulesFile});
|
|
340
|
+
assert.equal(loaded.enabled,false,text);
|
|
341
|
+
assert.ok(loaded.localError,text);
|
|
342
|
+
}
|
|
343
|
+
fs.writeFileSync(localPath(b.env),'{"enabled": false, "rules": {}}');
|
|
344
|
+
assert.match(statusText({env:b.env,rulesFile}),/本地配置格式异常,提醒已暂停(.*rules 应为列表)/);
|
|
345
|
+
fs.writeFileSync(localPath(b.env),'{oops');
|
|
346
|
+
assert.match(statusText({env:b.env,rulesFile}),/本地配置格式异常,提醒已暂停(.*读取失败(parse))/);
|
|
347
|
+
fs.writeFileSync(localPath(b.env),'');
|
|
348
|
+
assert.match(statusText({env:b.env,rulesFile}),/本地配置格式异常,提醒已暂停(.*读取失败(empty))/);
|
|
349
|
+
// A valid empty object is still a usable file.
|
|
350
|
+
fs.writeFileSync(localPath(b.env),'{}');
|
|
351
|
+
assert.match(JSON.parse(await send('empty-object')).systemMessage,/cm-fix/);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
for(const [label,text] of [['zero bytes',''],['only whitespace',' \n\t ']]){
|
|
355
|
+
test(`a local file of ${label} pauses the install default too`,async t=>{
|
|
356
|
+
const b=box(t);
|
|
357
|
+
fs.mkdirSync(b.env.CM_WORKFLOW_HOME,{recursive:true});
|
|
358
|
+
fs.writeFileSync(localPath(b.env),text);
|
|
359
|
+
const result=await b.run('claude');
|
|
360
|
+
assert.match(result.out,/⚠.*读取失败(empty).*没给 Claude 挂/);
|
|
361
|
+
assert.ok(!fs.existsSync(b.file('claude')));
|
|
362
|
+
assert.equal(fs.readFileSync(localPath(b.env),'utf8'),text);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
test('an empty CM table is reported by status instead of counting as zero rules',async t=>{
|
|
367
|
+
const b=box(t);
|
|
368
|
+
const rulesFile=path.join(b.home,'rules.json');
|
|
369
|
+
fs.writeFileSync(rulesFile,'');
|
|
370
|
+
assert.match(statusText({env:b.env,rulesFile}),/CM 自带 读取失败(empty)/);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
test('a local file that cannot be read pauses the install default in status',async t=>{
|
|
374
|
+
const b=box(t);
|
|
375
|
+
fs.mkdirSync(b.env.CM_WORKFLOW_HOME,{recursive:true});
|
|
376
|
+
fs.writeFileSync(localPath(b.env),'{"enabled": fals');
|
|
377
|
+
assert.match(statusText({env:b.env}),/安装时自动挂:暂停(.*读取失败/);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test('status says whether installs wire the hook and which hosts are settled',async t=>{
|
|
381
|
+
const b=box(t);
|
|
382
|
+
assert.match(statusText({env:b.env}),/安装时自动挂:开;已处理过:无/);
|
|
383
|
+
await b.run('claude');
|
|
384
|
+
assert.match(statusText({env:b.env}),/安装时自动挂:开;已处理过:Claude(这些端不会再被自动挂上)/);
|
|
385
|
+
assert.match(statusText({env:{...b.env,CM_SKILL_HINTS_INSTALL:'off'}}),/安装时自动挂:已关闭(CM_SKILL_HINTS_INSTALL=off)/);
|
|
386
|
+
fs.writeFileSync(localPath(b.env),JSON.stringify({enabled:false}));
|
|
387
|
+
assert.match(statusText({env:b.env}),/安装时自动挂:已关闭(.*enabled 为 false)/);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
test('the hook still fails quietly and exits 0',async t=>{
|
|
391
|
+
const b=box(t);
|
|
392
|
+
await b.run('claude');
|
|
393
|
+
assert.equal(await main(['hook','--host','claude'],{env:b.env,readInput:()=>'{not json',write:()=>{assert.fail('no output');}}),0);
|
|
394
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The auto-invoke exam (方案-技能自动调用 第 8–9 条): 50 phrasings in
|
|
3
|
+
// cm-skill-hints.exam.json, 30 that should start an author skill and 20 that should
|
|
4
|
+
// not. Scored through the real hook, with every invoke skill counted as installed.
|
|
5
|
+
//
|
|
6
|
+
// node scripts/cm-skill-hints-exam.mjs score with real Jev (needs a TypeSafe key)
|
|
7
|
+
// node scripts/cm-skill-hints-exam.mjs --record same, and save Jev's answers into the exam file
|
|
8
|
+
// node scripts/cm-skill-hints-exam.mjs --keywords score the keyword fallback alone, no network
|
|
9
|
+
//
|
|
10
|
+
// The repository test replays the recorded answers through a fake Jev, so every change
|
|
11
|
+
// is scored without calling Jev. Each answer is keyed by the hash of the exact request
|
|
12
|
+
// it answered (model, clipped message, question), so changing a phrasing or a rule's
|
|
13
|
+
// `when`/`near` text leaves it unmatched and the test fails until it is re-recorded.
|
|
14
|
+
// Target: hit rate >= 95% on the should-use cases, false triggers <= 5% on the others,
|
|
15
|
+
// both for all 50 and for the 43 that reach Jev (7 open with a command the host runs).
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import os from 'node:os';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import crypto from 'node:crypto';
|
|
20
|
+
import {fileURLToPath} from 'node:url';
|
|
21
|
+
import {hook,loadRules,defaultRulesPath,opensWithCommand,typed} from './cm-skill-hints.mjs';
|
|
22
|
+
import {apiKey,requestBody} from './cm-skill-judge.mjs';
|
|
23
|
+
|
|
24
|
+
export const EXAM_NAME='cm-skill-hints.exam.json';
|
|
25
|
+
export const examPath=()=>path.join(path.dirname(fileURLToPath(import.meta.url)),EXAM_NAME);
|
|
26
|
+
export const TARGET={hit:0.95,falseTrigger:0.05};
|
|
27
|
+
|
|
28
|
+
export function readExam(file=examPath()){return JSON.parse(fs.readFileSync(file,'utf8'));}
|
|
29
|
+
export function invokeChoices(rulesFile=defaultRulesPath()){
|
|
30
|
+
const {rules}=loadRules({env:{HOME:'/nonexistent',CM_WORKFLOW_HOME:'/nonexistent/.cm'},rulesFile});
|
|
31
|
+
return rules.filter(rule=>rule.invoke).map(rule=>({skill:rule.skill,when:rule.invoke.when,near:rule.invoke.near}));
|
|
32
|
+
}
|
|
33
|
+
export const bodyHash=body=>crypto.createHash('sha256').update(body).digest('hex').slice(0,16);
|
|
34
|
+
// The request this case sends today; a recording made for any other request does not apply.
|
|
35
|
+
export const expectedRequest=(item,choices=invokeChoices())=>bodyHash(requestBody(item.prompt,choices));
|
|
36
|
+
|
|
37
|
+
// Every invoke skill counts as the installed author version; roots point at /srv paths
|
|
38
|
+
// that are never read.
|
|
39
|
+
export const installedCheck=skills=>({skills:skills.map(name=>({name,files:{}})),license:'',
|
|
40
|
+
skillState:()=>'author',skillRoots:()=>[{runtime:'claude',root:'/srv/skills'},{runtime:'codex',root:'/srv/agents-skills'}]});
|
|
41
|
+
|
|
42
|
+
// Which skill the hook started for this output, or null.
|
|
43
|
+
export function startedSkill(output){
|
|
44
|
+
if(!output)return null;
|
|
45
|
+
const parsed=JSON.parse(output);
|
|
46
|
+
const context=parsed.hookSpecificOutput?.additionalContext;
|
|
47
|
+
return context?/作者技能 ([\w.:-]+)/.exec(context)?.[1]??null:null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// A should-use case passes when the hook started that skill, or when the user typed
|
|
51
|
+
// the command themself (the host runs it, the hook stays out). A should-not case
|
|
52
|
+
// passes when the hook started nothing.
|
|
53
|
+
export function passed(item,started,host='claude'){
|
|
54
|
+
if(item.expect===null)return started===null;
|
|
55
|
+
if(started===item.expect)return true;
|
|
56
|
+
return started===null&&opensWithCommand(item.prompt)&&typed(item.prompt,item.expect,host);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function rates(results){
|
|
60
|
+
const should=results.filter(item=>item.expect!==null);
|
|
61
|
+
const shouldNot=results.filter(item=>item.expect===null);
|
|
62
|
+
const hit=should.filter(item=>item.pass).length/should.length;
|
|
63
|
+
const falseTrigger=shouldNot.filter(item=>!item.pass).length/shouldNot.length;
|
|
64
|
+
return {hit,falseTrigger,should:should.length,shouldNot:shouldNot.length,
|
|
65
|
+
ok:hit>=TARGET.hit&&falseTrigger<=TARGET.falseTrigger,failed:results.filter(item=>!item.pass)};
|
|
66
|
+
}
|
|
67
|
+
// All 50, and separately the ones judged at all (a command-led message never is), so
|
|
68
|
+
// the command cases cannot dilute either rate.
|
|
69
|
+
export function score(results){
|
|
70
|
+
const all=rates(results);
|
|
71
|
+
const judged=rates(results.filter(item=>!item.command));
|
|
72
|
+
return {...all,judged,ok:all.ok&&judged.ok};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Runs every case through hook(). `fetchImpl` is the Jev transport (real or fake);
|
|
76
|
+
// with `keywordsOnly` Jev is switched off. Each case gets its own temporary CM home.
|
|
77
|
+
export async function runExam({exam=readExam(),fetchImpl,key='exam-key',keywordsOnly=false,host='claude',onReply}={}){
|
|
78
|
+
const skills=invokeChoices().map(choice=>choice.skill);
|
|
79
|
+
const results=[];
|
|
80
|
+
for(const item of exam.cases){
|
|
81
|
+
const home=fs.mkdtempSync(path.join(os.tmpdir(),'cm-skill-exam-'));
|
|
82
|
+
try{
|
|
83
|
+
if(keywordsOnly)fs.writeFileSync(path.join(home,'skill-hints.local.json'),JSON.stringify({judge:false}));
|
|
84
|
+
const env={HOME:home,CM_WORKFLOW_HOME:home,CM_WORKFLOW_LOG_HOME:path.join(home,'logs')};
|
|
85
|
+
const transport=fetchImpl&&(async(url,options)=>{
|
|
86
|
+
const response=await fetchImpl(url,options);
|
|
87
|
+
if(!onReply)return response;
|
|
88
|
+
const text=await response.text();
|
|
89
|
+
if(response.ok)onReply(item,JSON.parse(text),options.body);
|
|
90
|
+
return new Response(text,{status:response.status,headers:{'Content-Type':'application/json'}});
|
|
91
|
+
});
|
|
92
|
+
const started=Date.now();
|
|
93
|
+
const output=await hook({prompt:item.prompt,session_id:item.id},{env,host,
|
|
94
|
+
loadAuthor:async()=>installedCheck(skills),judgeOptions:{key,fetchImpl:transport}});
|
|
95
|
+
const skill=startedSkill(output);
|
|
96
|
+
results.push({id:item.id,expect:item.expect,started:skill,pass:passed(item,skill,host),command:opensWithCommand(item.prompt),ms:Date.now()-started});
|
|
97
|
+
}finally{fs.rmSync(home,{recursive:true,force:true});}
|
|
98
|
+
}
|
|
99
|
+
return results;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// A fake Jev that answers from the exam's recording, keyed by the hash of the exact
|
|
103
|
+
// request body; an unrecorded request gets a 400, so the hook falls back to keywords.
|
|
104
|
+
export function replayFetch(exam){
|
|
105
|
+
const byRequest=new Map(exam.cases.filter(item=>item.jev).map(item=>[item.jev.request,item.jev.probabilities]));
|
|
106
|
+
return async(url,options)=>{
|
|
107
|
+
const probabilities=byRequest.get(bodyHash(options.body));
|
|
108
|
+
if(!probabilities)return new Response('{"error":"not recorded"}',{status:400});
|
|
109
|
+
return new Response(JSON.stringify({answers:{skill:{type:'choice',probabilities}}}),{status:200});
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const percent=value=>`${(value*100).toFixed(1)}%`;
|
|
114
|
+
async function cli(argv){
|
|
115
|
+
const record=argv.includes('--record');
|
|
116
|
+
const keywordsOnly=argv.includes('--keywords');
|
|
117
|
+
const exam=readExam();
|
|
118
|
+
let key='exam-key';
|
|
119
|
+
if(!keywordsOnly){
|
|
120
|
+
key=apiKey(process.env);
|
|
121
|
+
if(!key){process.stderr.write('没有 TypeSafe 密钥(TYPESAFE_API_KEY 或钥匙串),无法跑真实 Jev;可用 --keywords 只考关键词。\n');return 2;}
|
|
122
|
+
}
|
|
123
|
+
let tokens={input:0,output:0,calls:0};
|
|
124
|
+
const replies=new Map();
|
|
125
|
+
const started=Date.now();
|
|
126
|
+
const results=await runExam({exam,keywordsOnly,key,fetchImpl:keywordsOnly?undefined:globalThis.fetch,onReply:(item,reply,body)=>{
|
|
127
|
+
replies.set(item.id,{request:bodyHash(body),probabilities:reply?.answers?.skill?.probabilities});
|
|
128
|
+
tokens={input:tokens.input+(reply?.usage?.input_tokens??0),output:tokens.output+(reply?.usage?.output_tokens??0),calls:tokens.calls+1};
|
|
129
|
+
}});
|
|
130
|
+
const result=score(results);
|
|
131
|
+
for(const item of results)process.stdout.write(`${item.pass?'ok':'XX'} ${item.id} 期望=${item.expect??'无'} 实际=${item.started??'无'} ${item.ms}ms\n`);
|
|
132
|
+
process.stdout.write(`\n全部:该用命中 ${percent(result.hit)}(${result.should} 句),不该用误触发 ${percent(result.falseTrigger)}(${result.shouldNot} 句)。\n`
|
|
133
|
+
+`经判断的(去掉 ${results.filter(item=>item.command).length} 句命令开头):该用命中 ${percent(result.judged.hit)}(${result.judged.should} 句),`
|
|
134
|
+
+`不该用误触发 ${percent(result.judged.falseTrigger)}(${result.judged.shouldNot} 句)。\n${result.ok?'达标':'未达标'}。用时 ${((Date.now()-started)/1000).toFixed(1)} 秒`
|
|
135
|
+
+(keywordsOnly?',只用关键词。\n':`,Jev 调用 ${tokens.calls} 次,输入 ${tokens.input} / 输出 ${tokens.output} token。\n`));
|
|
136
|
+
if(record&&!keywordsOnly){
|
|
137
|
+
const missing=exam.cases.filter(item=>!opensWithCommand(item.prompt)&&!replies.get(item.id));
|
|
138
|
+
if(missing.length){process.stderr.write(`有 ${missing.length} 句没拿到 Jev 回答(${missing.map(item=>item.id).join('、')}),未保存;请重跑。\n`);return 1;}
|
|
139
|
+
exam.recorded={date:new Date().toISOString().slice(0,10)};
|
|
140
|
+
for(const item of exam.cases){const reply=replies.get(item.id);if(reply)item.jev=reply;else delete item.jev;}
|
|
141
|
+
fs.writeFileSync(examPath(),JSON.stringify(exam,null,2)+'\n');
|
|
142
|
+
process.stdout.write(`已保存 Jev 回答到 ${examPath()}。\n`);
|
|
143
|
+
}
|
|
144
|
+
return result.ok?0:1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fs.realpathSync(fileURLToPath(import.meta.url))){
|
|
148
|
+
process.exitCode=await cli(process.argv.slice(2));
|
|
149
|
+
}
|