@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,181 @@
|
|
|
1
|
+
// Jev judge for the skill hints hook: asks TypeSafe's Jev which author skill, if any,
|
|
2
|
+
// the user's message is asking for. The hook uses it for the few rules that start a
|
|
3
|
+
// skill (`invoke` in cm-skill-hints.json); keywords stay the fallback.
|
|
4
|
+
//
|
|
5
|
+
// Decided 2026-10-25 (方案-技能自动调用): only with a TypeSafe key (env or the macOS
|
|
6
|
+
// keychain); only the first SEND_CHARS characters leave the machine, and a message
|
|
7
|
+
// that looks like it holds a secret is never sent. At most BUDGET_MS in all and at most
|
|
8
|
+
// two requests: the second goes out at once when the first fails, or alongside it when
|
|
9
|
+
// the first has not answered within HEDGE_MS. Measured 2026-10-25 from fresh processes
|
|
10
|
+
// (as the hook runs): answers take 0.7–1.5 s, but about a quarter of new connections
|
|
11
|
+
// hang without ever answering, so waiting longer on one request does not help. Any
|
|
12
|
+
// failure returns {error}, so the caller falls back to keywords and the message is
|
|
13
|
+
// never held up.
|
|
14
|
+
// The key is never logged or printed; errors carry a category, never the response text.
|
|
15
|
+
import {execFileSync} from 'node:child_process';
|
|
16
|
+
|
|
17
|
+
export const JEV_URL='https://api.typesafe.ai/v1/systemone';
|
|
18
|
+
export const JEV_MODEL='jev-latest';
|
|
19
|
+
export const SEND_CHARS=500;
|
|
20
|
+
export const BUDGET_MS=3000;
|
|
21
|
+
export const HEDGE_MS=1000;
|
|
22
|
+
export const THRESHOLD=0.5;
|
|
23
|
+
export const NONE='none';
|
|
24
|
+
const KEY_NAME='TYPESAFE_API_KEY';
|
|
25
|
+
|
|
26
|
+
// What stays local (decided 2026-10-25 after five review rounds): any message that
|
|
27
|
+
// names a credential at all (password, token, key, 密码, 密钥 …), whatever follows it,
|
|
28
|
+
// and any message holding a known key shape or a long mixed-case run. Earlier versions
|
|
29
|
+
// tried to tell a labelled value ("密码是 x") from a description ("token 是什么"); every
|
|
30
|
+
// round found another way to write a value that slipped through (a value starting like
|
|
31
|
+
// a description, punctuation, quotes around the word). Not sending any message that
|
|
32
|
+
// mentions a credential has no such gap. It costs little: such a message only falls back
|
|
33
|
+
// to keywords, and none of the 50 exam phrasings mentions one. A credential pasted with
|
|
34
|
+
// no recognisable shape and no credential word can still pass, which the docs say.
|
|
35
|
+
// Matched on a folded copy of the message, built one character at a time:
|
|
36
|
+
// - a letter or digit (other than a modifier letter or an invisible Hangul filler)
|
|
37
|
+
// becomes its NFKD letters and digits: full-width and other compatibility forms
|
|
38
|
+
// turn plain, accents split off, ligatures open up ("API key", "fi");
|
|
39
|
+
// - a symbol stays only when NFKD turns it into exactly one letter or digit, so a
|
|
40
|
+
// circled letter counts and "№" (two letters, "No") goes;
|
|
41
|
+
// - everything else goes: spaces, punctuation, control and zero-width characters,
|
|
42
|
+
// combining marks, modifier letters (U+02BC looks like an apostrophe), the fillers.
|
|
43
|
+
// So "API key", "api_key", "pass word", "API\u200Bkey" and "ⓐⓟⓘ№key" all read as
|
|
44
|
+
// the word. Dropping characters can join two words into a credential word by accident;
|
|
45
|
+
// that only costs the Jev call.
|
|
46
|
+
// Known limits, stated in the docs (review round 8 listed them): look-alike letters
|
|
47
|
+
// from other scripts ("pаssword" with a Cyrillic a), letters with no decomposition
|
|
48
|
+
// ("tøken"), extra or swapped letters and digits ("passXword", "t0ken"), escapes and
|
|
49
|
+
// encodings ("pass%77ord"), reordering through bidirectional controls, and wording
|
|
50
|
+
// outside the word list. Traditional Chinese forms of the listed words are included.
|
|
51
|
+
const CREDENTIAL_WORD=/apikey|secret|token|passwd|password|pwd|passcode|accesskey|privatekey|credential|密钥|秘钥|密码|口令|令牌|凭证|凭据|密鑰|祕鑰|秘鑰|密碼|憑證|憑據/;
|
|
52
|
+
const FILLERS=new Set(['\u115F','\u1160','\u3164','\uFFA0']);
|
|
53
|
+
const KEEP=/[\p{L}\p{N}]/u,MODIFIER=/\p{Lm}/u,SYMBOL=/\p{S}/u;
|
|
54
|
+
const plain=text=>Array.from(text.normalize('NFKD')).filter(ch=>KEEP.test(ch)&&!MODIFIER.test(ch)&&!FILLERS.has(ch)).join('');
|
|
55
|
+
export const fold=text=>Array.from(text).map(ch=>{
|
|
56
|
+
if(KEEP.test(ch)&&!MODIFIER.test(ch)&&!FILLERS.has(ch))return plain(ch);
|
|
57
|
+
if(SYMBOL.test(ch)){const out=plain(ch);return Array.from(out).length===1?out:'';}
|
|
58
|
+
return '';
|
|
59
|
+
}).join('').toLowerCase();
|
|
60
|
+
const SECRET_PATTERNS=[
|
|
61
|
+
/\bsk-[A-Za-z0-9_-]{16,}/,
|
|
62
|
+
/\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}|\bgithub_pat_[A-Za-z0-9_]{20,}/,
|
|
63
|
+
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/,
|
|
64
|
+
/\bxox[abprs]-[A-Za-z0-9-]{10,}/,
|
|
65
|
+
/\bAIza[0-9A-Za-z_-]{30,}/,
|
|
66
|
+
/-----BEGIN [A-Z ]*PRIVATE KEY-----/,
|
|
67
|
+
/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/,
|
|
68
|
+
/\bBearer\s+[A-Za-z0-9._~+/-]{16,}/i,
|
|
69
|
+
];
|
|
70
|
+
// A long run of letters and digits mixing cases and digits looks like a token; plain hex
|
|
71
|
+
// (commit ids, hashes) does not.
|
|
72
|
+
const tokenLike=word=>word.length>=32&&!/^[0-9a-f]+$/i.test(word)&&/[a-z]/.test(word)&&/[A-Z]/.test(word)&&/\d/.test(word);
|
|
73
|
+
export const hasSecret=text=>CREDENTIAL_WORD.test(fold(text))
|
|
74
|
+
||SECRET_PATTERNS.some(pattern=>pattern.test(text))
|
|
75
|
+
||(text.match(/[A-Za-z0-9_+/=-]{32,}/g)??[]).some(tokenLike);
|
|
76
|
+
|
|
77
|
+
// The key comes from TYPESAFE_API_KEY, else (macOS only) the login keychain, the same
|
|
78
|
+
// place jev-mcp reads. Empty when neither has it.
|
|
79
|
+
export function apiKey(env=process.env,{platform=process.platform,run=execFileSync,timeoutMs=1000}={}){
|
|
80
|
+
const fromEnv=String(env[KEY_NAME]??'').trim();
|
|
81
|
+
if(fromEnv)return fromEnv;
|
|
82
|
+
// Without USER the lookup would match any account's item, so it is not tried.
|
|
83
|
+
if(platform!=='darwin'||!env.USER)return '';
|
|
84
|
+
try{
|
|
85
|
+
return String(run('security',['find-generic-password','-a',env.USER,'-s',KEY_NAME,'-w'],
|
|
86
|
+
{encoding:'utf8',timeout:timeoutMs,stdio:['ignore','pipe','ignore']})).trim();
|
|
87
|
+
}catch{return '';}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// First SEND_CHARS characters, counted by code point so a CJK or emoji is never split.
|
|
91
|
+
export const clip=text=>Array.from(text).slice(0,SEND_CHARS).join('');
|
|
92
|
+
|
|
93
|
+
// A choice may carry `near`: the look-alike situation that is not it. It becomes its own
|
|
94
|
+
// option, so Jev has somewhere to put the near miss; picking it counts as none.
|
|
95
|
+
export const nearLabel=skill=>`${skill}~near`;
|
|
96
|
+
export function question(choices){
|
|
97
|
+
const criteria={};
|
|
98
|
+
for(const choice of choices){
|
|
99
|
+
criteria[choice.skill]=choice.when;
|
|
100
|
+
if(choice.near)criteria[nearLabel(choice.skill)]=choice.near;
|
|
101
|
+
}
|
|
102
|
+
criteria[NONE]='以上都不是:用户在问别的事、在讨论或执行具体任务,或只是顺带提到这些词';
|
|
103
|
+
return {type:'choice',instructions:'用户这条消息是在请求下面哪一件事?只看用户本人此刻要做什么。',criteria};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Exactly what is sent; the exam's recordings are keyed by its hash.
|
|
107
|
+
export const requestBody=(prompt,choices)=>JSON.stringify({model:JEV_MODEL,state:clip(prompt),questions:{skill:question(choices)}});
|
|
108
|
+
|
|
109
|
+
// {skill, probability} when Jev answered (skill null = none of them), else {error}.
|
|
110
|
+
// `choices` is [{skill, when, near?}]; `when` describes the situation in the user's words.
|
|
111
|
+
export async function judge({prompt,choices,env=process.env,fetchImpl=globalThis.fetch,key,
|
|
112
|
+
budgetMs=BUDGET_MS,hedgeMs=HEDGE_MS,now=Date.now}){
|
|
113
|
+
if(!choices?.length)return {error:'no-choices'};
|
|
114
|
+
if(hasSecret(prompt))return {error:'secret'};
|
|
115
|
+
const started=now();
|
|
116
|
+
const token=key??apiKey(env);
|
|
117
|
+
if(!token)return {error:'no-key'};
|
|
118
|
+
// The key in use is the one credential known for sure: a message holding it stays local.
|
|
119
|
+
if(prompt.includes(token))return {error:'secret'};
|
|
120
|
+
const left=budgetMs-(now()-started);
|
|
121
|
+
if(left<=50)return {error:'timeout'};
|
|
122
|
+
const body=requestBody(prompt,choices);
|
|
123
|
+
return new Promise(resolve=>{
|
|
124
|
+
const controllers=[];
|
|
125
|
+
let settled=false;
|
|
126
|
+
let pending=0;
|
|
127
|
+
let error='timeout';
|
|
128
|
+
const finish=value=>{
|
|
129
|
+
if(settled)return;
|
|
130
|
+
settled=true;
|
|
131
|
+
clearTimeout(hedge);
|
|
132
|
+
clearTimeout(deadline);
|
|
133
|
+
for(const controller of controllers)controller.abort();
|
|
134
|
+
resolve(value);
|
|
135
|
+
};
|
|
136
|
+
const send=()=>{
|
|
137
|
+
if(settled||controllers.length>=2)return;
|
|
138
|
+
const controller=new AbortController();
|
|
139
|
+
controllers.push(controller);
|
|
140
|
+
pending++;
|
|
141
|
+
fetchImpl(JEV_URL,{method:'POST',signal:controller.signal,
|
|
142
|
+
headers:{Authorization:`Bearer ${token}`,'Content-Type':'application/json'},body})
|
|
143
|
+
.then(async response=>{
|
|
144
|
+
// Overloaded or rate-limited is worth the second request; other client errors are not.
|
|
145
|
+
if(response.status>=500||response.status===429)throw Object.assign(new Error('server'),{category:`http-${response.status===429?'429':'5xx'}`});
|
|
146
|
+
if(!response.ok)return finish({error:'http-4xx'});
|
|
147
|
+
let reply;
|
|
148
|
+
try{reply=await response.json();}catch{return finish({error:'bad-reply'});}
|
|
149
|
+
finish(read(reply,choices));
|
|
150
|
+
})
|
|
151
|
+
.catch(caught=>{
|
|
152
|
+
pending--;
|
|
153
|
+
if(settled)return;
|
|
154
|
+
error=caught?.category??(caught?.name==='AbortError'?'timeout':'network');
|
|
155
|
+
if(controllers.length<2)send();
|
|
156
|
+
else if(!pending)finish({error});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
const hedge=setTimeout(send,Math.min(hedgeMs,left));
|
|
160
|
+
const deadline=setTimeout(()=>finish({error:'timeout'}),left);
|
|
161
|
+
send();
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// A reply counts only when it gives a probability in [0, 1] for every option asked;
|
|
166
|
+
// anything else is bad-reply, so the caller falls back to keywords instead of taking
|
|
167
|
+
// a malformed answer as "none" or as a skill.
|
|
168
|
+
function read(reply,choices){
|
|
169
|
+
const probabilities=reply?.answers?.skill?.probabilities;
|
|
170
|
+
if(!probabilities||typeof probabilities!=='object'||Array.isArray(probabilities))return {error:'bad-reply'};
|
|
171
|
+
const asked=Object.keys(question(choices).criteria);
|
|
172
|
+
const valid=label=>typeof probabilities[label]==='number'&&probabilities[label]>=0&&probabilities[label]<=1;
|
|
173
|
+
if(!asked.every(valid))return {error:'bad-reply'};
|
|
174
|
+
let best=null;
|
|
175
|
+
for(const choice of choices){
|
|
176
|
+
const p=probabilities[choice.skill];
|
|
177
|
+
if(!best||p>best.probability)best={skill:choice.skill,probability:p};
|
|
178
|
+
}
|
|
179
|
+
if(best.probability<THRESHOLD)return {skill:null,probability:probabilities[NONE]};
|
|
180
|
+
return best;
|
|
181
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {judge,hasSecret,apiKey,clip,question,nearLabel,JEV_URL,SEND_CHARS,NONE} from './cm-skill-judge.mjs';
|
|
4
|
+
import {readExam,runExam,replayFetch,score,invokeChoices,expectedRequest,TARGET} from './cm-skill-hints-exam.mjs';
|
|
5
|
+
import {opensWithCommand} from './cm-skill-hints.mjs';
|
|
6
|
+
|
|
7
|
+
// Never a real call: every test hands judge() its own fetch.
|
|
8
|
+
const CHOICES=[{skill:'handoff',when:'写交接'},{skill:'wayfinder',when:'拆决策票',near:'只是排个计划'}];
|
|
9
|
+
// Full answers: a probability for each option asked (two skills, one look-alike, none).
|
|
10
|
+
const HANDOFF={handoff:0.97,wayfinder:0.01,'wayfinder~near':0.01,none:0.01};
|
|
11
|
+
const WAYFINDER={handoff:0.01,wayfinder:0.97,'wayfinder~near':0.01,none:0.01};
|
|
12
|
+
const reply=(probabilities,status=200)=>new Response(JSON.stringify({answers:{skill:{type:'choice',probabilities}}}),{status});
|
|
13
|
+
function recorder(...steps){
|
|
14
|
+
const calls=[];
|
|
15
|
+
const fetchImpl=async(url,options)=>{
|
|
16
|
+
calls.push({url,options,body:JSON.parse(options.body)});
|
|
17
|
+
const step=steps[Math.min(calls.length-1,steps.length-1)];
|
|
18
|
+
return typeof step==='function'?step(options):step;
|
|
19
|
+
};
|
|
20
|
+
return {calls,fetchImpl};
|
|
21
|
+
}
|
|
22
|
+
// Credential-shaped strings are built at run time so the repository scan never sees one.
|
|
23
|
+
const fake={
|
|
24
|
+
openai:'sk-'+'a1B2'.repeat(6),
|
|
25
|
+
github:'ghp_'+'Z9y8'.repeat(6),
|
|
26
|
+
aws:'AKIA'+'ABCDEFGH12345678',
|
|
27
|
+
slack:'xoxb-'+'1234-5678-abcdef',
|
|
28
|
+
pem:'-----BEGIN RSA '+'PRIVATE KEY-----',
|
|
29
|
+
jwt:'eyJ'+'hbGciOiJIUzI1'+'.'+'eyJzdWIiOiIxMjM0'+'.'+'SflKxwRJSMeKKF2QT4',
|
|
30
|
+
assign:'api_key'+' = '+'q7w8e9r0t1',
|
|
31
|
+
chinese:'密码'+':'+'hunter22',
|
|
32
|
+
bare:'Ab3'+'x9Kq2LmN8pQr4StU6vWx0YzA1bC3dE5f',
|
|
33
|
+
// In words, and a bare hex key next to a credential word.
|
|
34
|
+
words:'TypeSafe 密钥'+'是 '+'a1'.repeat(32),
|
|
35
|
+
english:'my pass'+'word is hunter22',
|
|
36
|
+
hex:'API key'+': '+'0f'.repeat(16),
|
|
37
|
+
// No separator and plain hex: only the credential word nearby gives it away.
|
|
38
|
+
near:'这是 TypeSafe 的 api key '+'0f'.repeat(16)+' 帮我配上',
|
|
39
|
+
// A labelled value counts however short.
|
|
40
|
+
shortWords:'密码'+'是 1234',
|
|
41
|
+
shortEnglish:'my pass'+'word is abcde',
|
|
42
|
+
shortAssign:'token'+'=xyz',
|
|
43
|
+
// Round 3: a value that starts like a description, and one or two characters.
|
|
44
|
+
descriptionPrefix:'my pass'+'word is correct123',
|
|
45
|
+
requiredPrefix:'token'+'=required123',
|
|
46
|
+
twoChars:'密码'+'是 12',
|
|
47
|
+
oneChar:'密码'+'是1',
|
|
48
|
+
// Round 4: a value that starts with punctuation or a quote.
|
|
49
|
+
bang:'密码'+'是 !Ab12',
|
|
50
|
+
quotedBang:'pass'+'word = "!Ab12"',
|
|
51
|
+
dot:'token'+'=.abc123',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
test('a message that looks like it holds a credential is never sent to Jev',async()=>{
|
|
55
|
+
for(const [name,secret] of Object.entries(fake)){
|
|
56
|
+
assert.ok(hasSecret(`帮我看看 ${secret} 这个配置`),name);
|
|
57
|
+
const {calls,fetchImpl}=recorder(reply(HANDOFF));
|
|
58
|
+
assert.deepEqual(await judge({prompt:`写个交接,配置里有 ${secret}`,choices:CHOICES,key:'k',fetchImpl}),{error:'secret'},name);
|
|
59
|
+
assert.equal(calls.length,0,name);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('commit ids, hashes and ordinary text are not taken for credentials',()=>{
|
|
64
|
+
for(const text of ['回滚到 0ddd39e5c3a1b2f4e6d8a0b1c2d3e4f5a6b7c8d9','sha256 是 e0a0932e42188fde6a8a93314616ca3ede14c6ddf029e98c10cb2c8b9fb6a425',
|
|
65
|
+
'上下文快满了,写个交接吧','这个仓库越写越乱了,帮我看看架构哪里值得改'])
|
|
66
|
+
assert.equal(hasSecret(text),false,text);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Decided 2026-10-25 after review round 5: a message that names a credential at all
|
|
70
|
+
// stays local, descriptions included, because telling a labelled value from a
|
|
71
|
+
// description kept leaking. These only fall back to keywords; nothing is blocked.
|
|
72
|
+
test('any message naming a credential stays local, however it is written',async()=>{
|
|
73
|
+
const named=['token 是什么意思','the password is required','密码是多少位比较安全','密码是必填项','password is not set',
|
|
74
|
+
'把 token 过期时间改成 2 小时','密码输错三次要锁定账号','the password field should be masked','密码:','api key 怎么配',
|
|
75
|
+
// Round 5: the word inside Chinese quotes or backticks.
|
|
76
|
+
'写个交接,配置为 “密'+'码”=!Ab12','写个交接,配置为 `tok'+'en`=.abc123',
|
|
77
|
+
// Round 6: separators and full-width forms inside a compound word.
|
|
78
|
+
'写个交接,API '+'key=!Ab12','写个交接,api\tkey=!Ab12','API key'+'=!Ab12','my pass '+'word is x','access-'+'-key: x','private.'+'key=x',
|
|
79
|
+
// Round 7: invisible characters inside the word.
|
|
80
|
+
'API\u200B'+'key=!Ab12','pass\u2060'+'word=!Ab12','API\u00AD'+'key=!Ab12','API\u0085'+'key=!Ab12','pa\u0301ss'+'word=x',
|
|
81
|
+
// Round 8: Hangul fillers, a modifier letter, a symbol NFKD expands, traditional Chinese.
|
|
82
|
+
'API\u115F'+'key=!Ab12','API\u1160'+'key=!Ab12','API\u3164'+'key=!Ab12','API\uFFA0'+'key=!Ab12',
|
|
83
|
+
'API\u02BC'+'key=!Ab12','API\u2116'+'key=!Ab12','ⓟⓐⓢⓢⓦⓞⓡⓓ=x','密'+'碼是 1','密'+'鑰:x','憑'+'證=x',
|
|
84
|
+
// Round 9: compatibility letters and an expanding symbol together; a ligature.
|
|
85
|
+
'写个交接,ⓐⓟⓘ№'+'key=!Ab12','ⓐⓟⓘ\u200B'+'key=x','pass'+'word=x','api™'+'key=x'];
|
|
86
|
+
for(const text of named){
|
|
87
|
+
assert.equal(hasSecret(text),true,text);
|
|
88
|
+
const {calls,fetchImpl}=recorder(reply(HANDOFF));
|
|
89
|
+
assert.deepEqual(await judge({prompt:text,choices:CHOICES,key:'k',fetchImpl}),{error:'secret'},text);
|
|
90
|
+
assert.equal(calls.length,0,text);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('only the first 500 characters are sent, counted by character not byte',async()=>{
|
|
95
|
+
const prompt='交'.repeat(SEND_CHARS)+'这部分不该发出去😀';
|
|
96
|
+
const {calls,fetchImpl}=recorder(reply(HANDOFF));
|
|
97
|
+
await judge({prompt,choices:CHOICES,key:'k',fetchImpl});
|
|
98
|
+
assert.equal(calls[0].body.state,'交'.repeat(SEND_CHARS));
|
|
99
|
+
assert.equal(Array.from(clip('😀'.repeat(SEND_CHARS+3))).length,SEND_CHARS);
|
|
100
|
+
assert.equal(calls[0].url,JEV_URL);
|
|
101
|
+
assert.equal(calls[0].options.headers.Authorization,'Bearer k');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('a message holding the key in use is never sent, whatever its shape',async()=>{
|
|
105
|
+
const {calls,fetchImpl}=recorder(reply(HANDOFF));
|
|
106
|
+
assert.deepEqual(await judge({prompt:'配置里写的是 plainkey123 吗',choices:CHOICES,key:'plainkey123',fetchImpl}),{error:'secret'});
|
|
107
|
+
assert.equal(calls.length,0);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('without a key nothing is sent',async()=>{
|
|
111
|
+
const {calls,fetchImpl}=recorder(reply(HANDOFF));
|
|
112
|
+
assert.deepEqual(await judge({prompt:'写个交接',choices:CHOICES,env:{},fetchImpl}),{error:'no-key'});
|
|
113
|
+
assert.equal(calls.length,0);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('the key comes from the environment, else the macOS keychain, never without USER',()=>{
|
|
117
|
+
const seen=[];
|
|
118
|
+
const run=(command,args)=>{seen.push([command,...args]);return 'from-keychain\n';};
|
|
119
|
+
assert.equal(apiKey({TYPESAFE_API_KEY:' env-key ',USER:'u'},{platform:'darwin',run}),'env-key');
|
|
120
|
+
assert.equal(seen.length,0);
|
|
121
|
+
assert.equal(apiKey({USER:'u'},{platform:'darwin',run}),'from-keychain');
|
|
122
|
+
assert.deepEqual(seen.at(-1),['security','find-generic-password','-a','u','-s','TYPESAFE_API_KEY','-w']);
|
|
123
|
+
assert.equal(apiKey({},{platform:'darwin',run}),'');
|
|
124
|
+
assert.equal(apiKey({USER:'u'},{platform:'linux',run}),'');
|
|
125
|
+
assert.equal(seen.length,1);
|
|
126
|
+
assert.equal(apiKey({USER:'u'},{platform:'darwin',run:()=>{throw new Error('denied');}}),'');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('the question lists each skill, its look-alike and a none option',()=>{
|
|
130
|
+
const asked=question(CHOICES);
|
|
131
|
+
assert.equal(asked.type,'choice');
|
|
132
|
+
assert.deepEqual(Object.keys(asked.criteria),['handoff','wayfinder',nearLabel('wayfinder'),NONE]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('Jev\'s best skill above the threshold is the verdict; below it, or a look-alike, is none',async()=>{
|
|
136
|
+
const ask=async probabilities=>judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:recorder(reply(probabilities)).fetchImpl});
|
|
137
|
+
assert.deepEqual(await ask({handoff:0.9,wayfinder:0.05,[nearLabel('wayfinder')]:0,none:0.05}),{skill:'handoff',probability:0.9});
|
|
138
|
+
assert.equal((await ask({handoff:0.4,wayfinder:0.1,[nearLabel('wayfinder')]:0,none:0.5})).skill,null);
|
|
139
|
+
assert.equal((await ask({handoff:0.1,wayfinder:0.3,[nearLabel('wayfinder')]:0.6,none:0})).skill,null);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('a reply without a valid probability for every option asked is bad-reply, never none or a skill',async()=>{
|
|
143
|
+
const ask=async probabilities=>judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:recorder(reply(probabilities)).fetchImpl});
|
|
144
|
+
const full={handoff:0.1,wayfinder:0.1,[nearLabel('wayfinder')]:0.1,none:0.7};
|
|
145
|
+
for(const bad of [{},[],{...full,handoff:true},{...full,handoff:2},{...full,wayfinder:-0.1},{...full,none:'0.7'},
|
|
146
|
+
{handoff:0.9,wayfinder:0.05,none:0.05}])
|
|
147
|
+
assert.deepEqual(await ask(bad),{error:'bad-reply'},JSON.stringify(bad));
|
|
148
|
+
assert.deepEqual(await ask(full),{skill:null,probability:0.7});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('a dropped connection or server error is retried once',async()=>{
|
|
152
|
+
let r=recorder(()=>{throw new TypeError('fetch failed');},reply(HANDOFF));
|
|
153
|
+
assert.equal((await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl})).skill,'handoff');
|
|
154
|
+
assert.equal(r.calls.length,2);
|
|
155
|
+
r=recorder(new Response('busy',{status:503}),reply(WAYFINDER));
|
|
156
|
+
assert.equal((await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl})).skill,'wayfinder');
|
|
157
|
+
r=recorder(new Response('slow down',{status:429}),reply(WAYFINDER));
|
|
158
|
+
assert.equal((await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl})).skill,'wayfinder');
|
|
159
|
+
r=recorder(()=>{throw new TypeError('fetch failed');});
|
|
160
|
+
assert.deepEqual(await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl}),{error:'network'});
|
|
161
|
+
assert.equal(r.calls.length,2);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('a client error or unreadable reply is not retried and never echoes the key or reply',async()=>{
|
|
165
|
+
let r=recorder(new Response('bad key k-secret',{status:401}));
|
|
166
|
+
assert.deepEqual(await judge({prompt:'x',choices:CHOICES,key:'k-secret',fetchImpl:r.fetchImpl}),{error:'http-4xx'});
|
|
167
|
+
assert.equal(r.calls.length,1);
|
|
168
|
+
r=recorder(new Response('not json',{status:200}));
|
|
169
|
+
assert.deepEqual(await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl}),{error:'bad-reply'});
|
|
170
|
+
r=recorder(new Response('{"answers":{}}',{status:200}));
|
|
171
|
+
assert.deepEqual(await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl}),{error:'bad-reply'});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const hang=options=>new Promise((resolve,reject)=>options.signal.addEventListener('abort',()=>reject(Object.assign(new Error('aborted'),{name:'AbortError'}))));
|
|
175
|
+
const later=(ms,response)=>()=>new Promise(resolve=>setTimeout(()=>resolve(response),ms));
|
|
176
|
+
|
|
177
|
+
test('a hanging Jev is cut off within the budget, the second request included',async()=>{
|
|
178
|
+
const r=recorder(hang);
|
|
179
|
+
const started=Date.now();
|
|
180
|
+
assert.deepEqual(await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl,budgetMs:400,hedgeMs:200}),{error:'timeout'});
|
|
181
|
+
const took=Date.now()-started;
|
|
182
|
+
assert.ok(took>=350&&took<700,`took ${took}ms`);
|
|
183
|
+
assert.equal(r.calls.length,2);
|
|
184
|
+
assert.ok(r.calls.every(call=>call.options.signal.aborted),'both requests are aborted at the deadline');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('a first request that has not answered by the hedge time gets a second alongside; the first answer wins',async()=>{
|
|
188
|
+
const r=recorder(hang,later(50,reply(WAYFINDER)));
|
|
189
|
+
const started=Date.now();
|
|
190
|
+
assert.equal((await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl,budgetMs:2000,hedgeMs:100})).skill,'wayfinder');
|
|
191
|
+
assert.ok(Date.now()-started<500);
|
|
192
|
+
assert.equal(r.calls.length,2);
|
|
193
|
+
assert.ok(r.calls[0].options.signal.aborted,'the hung request is aborted once an answer arrives');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('a prompt answer sends only one request',async()=>{
|
|
197
|
+
const r=recorder(reply(HANDOFF));
|
|
198
|
+
assert.equal((await judge({prompt:'x',choices:CHOICES,key:'k',fetchImpl:r.fetchImpl,hedgeMs:100})).skill,'handoff');
|
|
199
|
+
await new Promise(resolve=>setTimeout(resolve,200));
|
|
200
|
+
assert.equal(r.calls.length,1);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// ---- the exam (方案-技能自动调用 第 8–9 条) ----
|
|
204
|
+
|
|
205
|
+
test('exam: 50 phrasings, 30 should start a skill and 20 should not, the 17 from 2026-10-24 included',()=>{
|
|
206
|
+
const {cases}=readExam();
|
|
207
|
+
assert.equal(cases.length,50);
|
|
208
|
+
assert.equal(cases.filter(item=>item.expect!==null).length,30);
|
|
209
|
+
assert.equal(cases.filter(item=>item.source==='2026-10-24').length,17);
|
|
210
|
+
assert.equal(new Set(cases.map(item=>item.id)).size,50);
|
|
211
|
+
const skills=new Set(invokeChoices().map(choice=>choice.skill));
|
|
212
|
+
for(const item of cases)assert.ok(item.expect===null||skills.has(item.expect),item.id);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('exam: every judged phrasing has a recorded answer for the exact request it sends today',()=>{
|
|
216
|
+
const choices=invokeChoices();
|
|
217
|
+
for(const item of readExam().cases){
|
|
218
|
+
if(opensWithCommand(item.prompt)){assert.equal(item.jev,undefined,item.id);continue;}
|
|
219
|
+
assert.equal(item.jev?.request,expectedRequest(item,choices),
|
|
220
|
+
`${item.id}:考题原文或规则的 when/near 改了,录下的 Jev 回答已过期;运行 node scripts/cm-skill-hints-exam.mjs --record 重录`);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('exam: a changed phrasing no longer matches its recording',async()=>{
|
|
225
|
+
const exam=readExam();
|
|
226
|
+
const fake=replayFetch(exam);
|
|
227
|
+
// A phrasing the keyword fallback misses, so only a (wrongly) replayed answer could pass it.
|
|
228
|
+
const item=exam.cases.find(entry=>entry.id==='handoff-3');
|
|
229
|
+
const changed={...exam,cases:[{...item,prompt:item.prompt+'。'}]};
|
|
230
|
+
const [result]=await runExam({exam:changed,fetchImpl:fake});
|
|
231
|
+
assert.equal(result.pass,false);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('exam: command cases cannot dilute the judged rates',()=>{
|
|
235
|
+
const negative=(id,pass,command)=>({id,expect:null,pass,command});
|
|
236
|
+
const results=[{id:'p',expect:'handoff',pass:true,command:false},negative('bad',false,false),
|
|
237
|
+
...Array.from({length:15},(_,i)=>negative(`n${i}`,true,false)),...Array.from({length:4},(_,i)=>negative(`c${i}`,true,true))];
|
|
238
|
+
const result=score(results);
|
|
239
|
+
assert.equal(result.falseTrigger,1/20);
|
|
240
|
+
assert.equal(result.judged.falseTrigger,1/16);
|
|
241
|
+
assert.equal(result.ok,false);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('exam: the hook meets the target with the recorded Jev answers',async()=>{
|
|
245
|
+
const exam=readExam();
|
|
246
|
+
const result=score(await runExam({exam,fetchImpl:replayFetch(exam)}));
|
|
247
|
+
assert.ok(result.hit>=TARGET.hit,`命中 ${result.hit},未过:${result.failed.map(item=>item.id).join('、')}`);
|
|
248
|
+
assert.ok(result.falseTrigger<=TARGET.falseTrigger,`误触发 ${result.falseTrigger},未过:${result.failed.map(item=>item.id).join('、')}`);
|
|
249
|
+
assert.ok(result.judged.ok,`经判断的:命中 ${result.judged.hit},误触发 ${result.judged.falseTrigger}`);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test('exam: the keyword fallback alone never triggers on more than 5% of should-not phrasings, command cases left out',async()=>{
|
|
253
|
+
const result=score(await runExam({keywordsOnly:true}));
|
|
254
|
+
assert.ok(result.judged.falseTrigger<=TARGET.falseTrigger,`误触发 ${result.judged.falseTrigger}:${result.judged.failed.map(item=>item.id).join('、')}`);
|
|
255
|
+
});
|
|
@@ -82,12 +82,14 @@ test('revision digest is optional, validated, and retained by shared status stor
|
|
|
82
82
|
assert.equal(Object.hasOwn(f.value(),'revisionDigest'),false);
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
test('task grammar is
|
|
85
|
+
test('task grammar is version 2 or 3 and is carried through awaiting review',t=>{
|
|
86
86
|
const f=fixture(t),expected=f.initial(),approved={...expected,status:'approved',approval:{response:'开始',at:expected.at}};
|
|
87
87
|
assert.deepEqual(writeSpecsStatus(f.specs,{...approved,taskGrammar:2}),{...approved,taskGrammar:2});
|
|
88
88
|
assert.equal(readSpecsStatus(f.specs).value.taskGrammar,2);
|
|
89
89
|
assert.deepEqual(writeSpecsStatus(f.specs,{...expected,taskGrammar:2}),{...expected,taskGrammar:2});
|
|
90
|
-
|
|
90
|
+
assert.deepEqual(writeSpecsStatus(f.specs,{...approved,taskGrammar:3}),{...approved,taskGrammar:3});
|
|
91
|
+
assert.deepEqual(writeSpecsStatus(f.specs,{...expected,taskGrammar:3}),{...expected,taskGrammar:3});
|
|
92
|
+
for(const invalid of [{...approved,taskGrammar:1},{...approved,taskGrammar:'2'},{...approved,taskGrammar:'3'},{...expected,taskGrammar:4}])
|
|
91
93
|
assert.throws(()=>writeSpecsStatus(f.specs,invalid),/spec_status_invalid/);
|
|
92
94
|
});
|
|
93
95
|
|