peaks-loop 4.1.4 → 4.1.6
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/.claude-plugin/marketplace.json +7 -2
- package/CHANGELOG.md +148 -0
- package/README-en.md +47 -183
- package/README.md +24 -188
- package/dist/cli/cli-helpers.d.ts +20 -0
- package/dist/cli/cli-helpers.js +34 -0
- package/dist/cli/commands/_register.js +2 -0
- package/dist/cli/commands/best-practice-scan-command.d.ts +11 -6
- package/dist/cli/commands/best-practice-scan-command.js +35 -20
- package/dist/cli/commands/best-practice-scan-helpers.d.ts +47 -0
- package/dist/cli/commands/best-practice-scan-helpers.js +88 -5
- package/dist/cli/commands/best-practice-scan-lookup-results.d.ts +13 -0
- package/dist/cli/commands/best-practice-scan-lookup-results.js +237 -0
- package/dist/cli/commands/code-commands.d.ts +6 -4
- package/dist/cli/commands/code-commands.js +6 -4
- package/dist/cli/commands/code-gate-command.d.ts +5 -5
- package/dist/cli/commands/code-gate-command.js +49 -9
- package/dist/cli/commands/code-mode-gate-plan-command.d.ts +1 -1
- package/dist/cli/commands/code-mode-gate-plan-command.js +2 -2
- package/dist/cli/commands/core/memory-extract-command.js +10 -5
- package/dist/cli/commands/dispatch-cli-invocation-check.d.ts +108 -0
- package/dist/cli/commands/dispatch-cli-invocation-check.js +87 -0
- package/dist/cli/commands/dispatch-cli-invocation-scan.d.ts +66 -0
- package/dist/cli/commands/dispatch-cli-invocation-scan.js +162 -0
- package/dist/cli/commands/dispatch-command-spec.js +1 -1
- package/dist/cli/commands/dispatch-commands.js +12 -5
- package/dist/cli/commands/dispatch-isolation-lease.d.ts +1 -1
- package/dist/cli/commands/dispatch-isolation-lease.js +6 -53
- package/dist/cli/commands/dispatch-preflight.js +46 -0
- package/dist/cli/commands/dispatch-prompt-blocks.d.ts +1 -1
- package/dist/cli/commands/dispatch-prompt-composition.d.ts +7 -1
- package/dist/cli/commands/dispatch-prompt-composition.js +29 -7
- package/dist/cli/commands/dispatch-record-write.d.ts +1 -1
- package/dist/cli/commands/dispatch-tool-call.d.ts +1 -1
- package/dist/cli/commands/doc-commands.js +1 -1
- package/dist/cli/commands/feedback-commands-helpers.js +1 -1
- package/dist/cli/commands/final-review-prepare-command.js +22 -1
- package/dist/cli/commands/gate-commands-enforce.js +3 -3
- package/dist/cli/commands/hook-handle.js +41 -20
- package/dist/cli/commands/lint-commands.js +3 -1
- package/dist/cli/commands/loop-eval-capture-index.js +2 -4
- package/dist/cli/commands/openspec-command-shared.js +2 -2
- package/dist/cli/commands/perf-audit-commands.js +15 -5
- package/dist/cli/commands/project-commands.js +9 -6
- package/dist/cli/commands/race-commands.d.ts +15 -0
- package/dist/cli/commands/race-commands.js +65 -0
- package/dist/cli/commands/race-pilot-gate-record-command.d.ts +3 -0
- package/dist/cli/commands/race-pilot-gate-record-command.js +81 -0
- package/dist/cli/commands/request-command-options.d.ts +8 -0
- package/dist/cli/commands/request-commands.js +2 -0
- package/dist/cli/commands/request-init-command.js +67 -12
- package/dist/cli/commands/{vm-status-command.d.ts → request-retag-command.d.ts} +1 -1
- package/dist/cli/commands/request-retag-command.js +50 -0
- package/dist/cli/commands/request-show-command.d.ts +8 -0
- package/dist/cli/commands/request-show-command.js +14 -1
- package/dist/cli/commands/request-transition-command.js +12 -4
- package/dist/cli/commands/request-transition-failures.d.ts +14 -0
- package/dist/cli/commands/request-transition-failures.js +76 -7
- package/dist/cli/commands/request-transition-preflight.js +1 -1
- package/dist/cli/commands/scan-scope-commands.js +2 -2
- package/dist/cli/commands/security-audit-commands.js +26 -6
- package/dist/cli/commands/slice-decompose-artifacts.js +2 -1
- package/dist/cli/commands/verdict-aggregate-command.js +2 -1
- package/dist/cli/commands/workflow-gate-commands.js +4 -4
- package/dist/cli/commands/worktree-lease-gc-command.js +1 -1
- package/dist/cli/program.js +0 -2
- package/dist/services/artifacts/artifact-contract-block.d.ts +53 -0
- package/dist/services/artifacts/artifact-contract-block.js +231 -0
- package/dist/services/artifacts/artifact-prerequisites.d.ts +27 -19
- package/dist/services/artifacts/artifact-prerequisites.js +65 -135
- package/dist/services/artifacts/artifact-templates.d.ts +1 -1
- package/dist/services/artifacts/artifact-templates.js +17 -10
- package/dist/services/artifacts/prerequisite-checks.d.ts +87 -0
- package/dist/services/artifacts/prerequisite-checks.js +198 -0
- package/dist/services/artifacts/prerequisite-transition-event.d.ts +20 -0
- package/dist/services/artifacts/prerequisite-transition-event.js +27 -0
- package/dist/services/artifacts/rd-transition-gates.d.ts +33 -0
- package/dist/services/artifacts/rd-transition-gates.js +71 -0
- package/dist/services/artifacts/request-artifact-metadata.d.ts +31 -0
- package/dist/services/artifacts/request-artifact-metadata.js +44 -0
- package/dist/services/artifacts/request-artifact-service.d.ts +5 -0
- package/dist/services/artifacts/request-artifact-service.js +43 -69
- package/dist/services/artifacts/request-artifact-state-helpers.d.ts +21 -1
- package/dist/services/artifacts/request-artifact-state-helpers.js +34 -8
- package/dist/services/artifacts/request-retag-service.d.ts +68 -0
- package/dist/services/artifacts/request-retag-service.js +125 -0
- package/dist/services/artifacts/request-state-order.d.ts +38 -0
- package/dist/services/artifacts/request-state-order.js +99 -0
- package/dist/services/artifacts/request-type-demand.d.ts +44 -0
- package/dist/services/artifacts/request-type-demand.js +71 -0
- package/dist/services/audit/audit-goal-service.d.ts +7 -0
- package/dist/services/audit/enforcers/active-skill-resolver.d.ts +18 -0
- package/dist/services/audit/enforcers/active-skill-resolver.js +48 -1
- package/dist/services/audit/enforcers/code-ban.d.ts +11 -2
- package/dist/services/audit/enforcers/code-ban.js +21 -1
- package/dist/services/audit/red-line-catalog-p2-a-bee-runtime.d.ts +17 -0
- package/dist/services/audit/red-line-catalog-p2-a-bee-runtime.js +24 -7
- package/dist/services/audit-independent/handoff-missing-refusal.d.ts +26 -0
- package/dist/services/audit-independent/handoff-missing-refusal.js +109 -0
- package/dist/services/audit-independent/handoff-readers.d.ts +37 -0
- package/dist/services/audit-independent/handoff-readers.js +81 -0
- package/dist/services/audit-independent/index.d.ts +6 -1
- package/dist/services/audit-independent/index.js +6 -1
- package/dist/services/audit-independent/judged-declaration-build.d.ts +48 -0
- package/dist/services/audit-independent/judged-declaration-build.js +73 -0
- package/dist/services/audit-independent/judged-declaration-check.d.ts +80 -0
- package/dist/services/audit-independent/judged-declaration-check.js +216 -0
- package/dist/services/audit-independent/judged-declaration.d.ts +94 -0
- package/dist/services/audit-independent/judged-declaration.js +218 -0
- package/dist/services/audit-independent/perf-audit-service.js +12 -14
- package/dist/services/audit-independent/security-audit-artifact.d.ts +28 -0
- package/dist/services/audit-independent/security-audit-artifact.js +90 -0
- package/dist/services/audit-independent/security-audit-service.d.ts +6 -53
- package/dist/services/audit-independent/security-audit-service.js +34 -178
- package/dist/services/capability-guard-runner/contracts/J05.js +60 -14
- package/dist/services/codegraph/codegraph-index-integrity.js +2 -0
- package/dist/services/context/build-dispatch-system-prompt.d.ts +8 -12
- package/dist/services/context/build-dispatch-system-prompt.js +18 -18
- package/dist/services/context/collector.js +5 -1
- package/dist/services/context/post-compact-reinjection.js +1 -1
- package/dist/services/dispatch/active-dispatch-index.d.ts +36 -0
- package/dist/services/dispatch/active-dispatch-index.js +118 -0
- package/dist/services/dispatch/batch-counter.js +1 -2
- package/dist/services/dispatch/dispatch-record-writer.d.ts +29 -16
- package/dist/services/dispatch/dispatch-record-writer.js +58 -100
- package/dist/services/dispatch/dispatch-sub-agent.js +1 -1
- package/dist/services/dispatch/karpathy-block.d.ts +55 -0
- package/dist/services/dispatch/karpathy-block.js +101 -0
- package/dist/services/dispatch/ledger-reaper.d.ts +80 -0
- package/dist/services/dispatch/ledger-reaper.js +131 -0
- package/dist/services/dispatch/test-tool-detection.d.ts +17 -1
- package/dist/services/dispatch/test-tool-detection.js +12 -1
- package/dist/services/evidence/evidence-generator.js +23 -12
- package/dist/services/feedback/feedback-promotion-service.d.ts +8 -11
- package/dist/services/feedback/feedback-promotion-service.js +30 -35
- package/dist/services/feedback/promotion-artifact-json-evidence.d.ts +18 -0
- package/dist/services/feedback/promotion-artifact-missing.d.ts +22 -0
- package/dist/services/feedback/promotion-artifact-missing.js +63 -0
- package/dist/services/final-review/final-review-contract.d.ts +95 -4
- package/dist/services/final-review/final-review-contract.js +64 -0
- package/dist/services/final-review/final-review-delivery.d.ts +13 -0
- package/dist/services/final-review/final-review-delivery.js +26 -12
- package/dist/services/final-review/final-review-evidence-collect.js +8 -53
- package/dist/services/final-review/final-review-evidence-records.d.ts +21 -0
- package/dist/services/final-review/final-review-evidence-records.js +67 -0
- package/dist/services/final-review/final-review-evidence-sources.d.ts +22 -0
- package/dist/services/final-review/final-review-evidence-sources.js +28 -4
- package/dist/services/final-review/final-review-prompt.js +19 -6
- package/dist/services/final-review/final-review-runner.js +5 -0
- package/dist/services/final-review/final-review-service.d.ts +2 -2
- package/dist/services/final-review/index.d.ts +1 -1
- package/dist/services/final-review/pre-post-diff.d.ts +2 -75
- package/dist/services/final-review/pre-post-diff.js +60 -59
- package/dist/services/hooks/pre-tool-code-gate.d.ts +7 -1
- package/dist/services/hooks/pre-tool-code-gate.js +21 -2
- package/dist/services/hooks/worktree-authorization-gate.js +6 -31
- package/dist/services/hooks/worktree-refusal-messages.d.ts +74 -0
- package/dist/services/hooks/worktree-refusal-messages.js +102 -0
- package/dist/services/lint/eslint-runner-support.d.ts +1 -1
- package/dist/services/lint/eslint-runner-support.js +2 -1
- package/dist/services/lint/eslint-runner-types.d.ts +8 -0
- package/dist/services/lint/eslint-runner.js +17 -4
- package/dist/services/llm/anthropic-runner.js +24 -7
- package/dist/services/loop/loop-observability.d.ts +39 -0
- package/dist/services/loop/loop-observability.js +55 -0
- package/dist/services/loop/monotonic-guard.js +6 -9
- package/dist/services/loop/monotonic-runner.js +8 -7
- package/dist/services/loop/run-driver.js +18 -22
- package/dist/services/memory/project-memory-service/index/kind-dispatch.js +14 -1
- package/dist/services/memory/project-memory-service/index/project-memory-plan-exec.js +13 -2
- package/dist/services/memory/project-memory-service/index.d.ts +2 -2
- package/dist/services/memory/project-memory-service/index.js +1 -1
- package/dist/services/memory/project-memory-service/parsers/frontmatter-parse.d.ts +36 -0
- package/dist/services/memory/project-memory-service/parsers/frontmatter-parse.js +48 -2
- package/dist/services/memory/project-memory-service/parsers/markdown-pure.d.ts +23 -1
- package/dist/services/memory/project-memory-service/parsers/markdown-pure.js +37 -0
- package/dist/services/memory/project-memory-service/types.d.ts +32 -0
- package/dist/services/observability/observability-service.d.ts +7 -0
- package/dist/services/observability/observability-service.js +2 -1
- package/dist/services/openspec/coverage-evidence-reader.d.ts +9 -9
- package/dist/services/openspec/coverage-evidence-reader.js +8 -8
- package/dist/services/openspec/openspec-archive-service.d.ts +1 -1
- package/dist/services/openspec/openspec-archive-service.js +6 -6
- package/dist/services/prd/gate-evidence-derivation.d.ts +4 -3
- package/dist/services/prd/gate-evidence-derivation.js +4 -3
- package/dist/services/qa/bdd-test-style-verifier.js +22 -8
- package/dist/services/race/gate2-evaluator.d.ts +58 -0
- package/dist/services/race/gate2-evaluator.js +111 -0
- package/dist/services/race/gate2-policy.d.ts +17 -0
- package/dist/services/race/gate2-policy.js +31 -0
- package/dist/services/race/lane-phase.d.ts +19 -0
- package/dist/services/race/lane-phase.js +113 -0
- package/dist/services/race/pilot-gate-store.d.ts +67 -0
- package/dist/services/race/pilot-gate-store.js +227 -0
- package/dist/services/scan/file-size-baseline.d.ts +33 -0
- package/dist/services/scan/file-size-baseline.js +173 -0
- package/dist/services/scan/file-size-scan.d.ts +35 -3
- package/dist/services/scan/file-size-scan.js +63 -42
- package/dist/services/scan/type-corroboration.d.ts +32 -0
- package/dist/services/scan/type-corroboration.js +51 -0
- package/dist/services/scan/type-sanity-service.d.ts +14 -0
- package/dist/services/scan/type-sanity-service.js +23 -22
- package/dist/services/security/safe-settings-path.d.ts +5 -0
- package/dist/services/security/safe-settings-path.js +64 -8
- package/dist/services/skill/resume-detector.js +11 -11
- package/dist/services/skills/hooks-codegate-superpowers.d.ts +5 -6
- package/dist/services/skills/hooks-codegate-superpowers.js +7 -8
- package/dist/services/skills/hooks-settings-service.d.ts +1 -1
- package/dist/services/skills/hooks-settings-service.js +1 -1
- package/dist/services/skills/presence-lease-order.d.ts +13 -0
- package/dist/services/skills/presence-lease-order.js +24 -0
- package/dist/services/skills/skill-conformance-service.js +1 -0
- package/dist/services/skills/skill-statusline-service.js +4 -7
- package/dist/services/slice/slice-check-service.js +8 -8
- package/dist/services/workflow/pipeline-verify-gate-support.d.ts +24 -8
- package/dist/services/workflow/pipeline-verify-gate-support.js +34 -39
- package/dist/services/workflow/pipeline-verify-qa-phase.d.ts +102 -0
- package/dist/services/workflow/pipeline-verify-qa-phase.js +176 -0
- package/dist/services/workflow/pipeline-verify-service.js +27 -28
- package/dist/services/workflow/request-type-resolution.d.ts +99 -0
- package/dist/services/workflow/request-type-resolution.js +130 -0
- package/dist/services/workflow/workflow-skip-service.d.ts +1 -20
- package/dist/services/workflow/workflow-skip-service.js +22 -25
- package/dist/services/workflow/workflow-state-store.d.ts +9 -0
- package/dist/services/workflow/workflow-state-store.js +26 -1
- package/dist/services/workspace/claude-settings-retirements.d.ts +54 -0
- package/dist/services/workspace/claude-settings-retirements.js +112 -0
- package/dist/services/workspace/claude-settings-template-merge.d.ts +35 -15
- package/dist/services/workspace/claude-settings-template-merge.js +33 -53
- package/dist/services/workspace/claude-settings-template.d.ts +62 -12
- package/dist/services/workspace/claude-settings-template.js +58 -58
- package/dist/services/workspace/migrate-1-4-1-service.js +3 -0
- package/dist/services/workspace/reconcile-service.js +0 -1
- package/dist/shared/incrementing-number.d.ts +33 -2
- package/dist/shared/incrementing-number.js +72 -3
- package/package.json +5 -7
- package/skills/bee/peaks-perf-audit/SKILL.md +1 -1
- package/skills/bee/peaks-prd/SKILL.md +4 -3
- package/skills/bee/peaks-qa/SKILL.md +1 -1
- package/skills/bee/peaks-qa/references/qa-sub-agent-dispatch.md +2 -2
- package/skills/bee/peaks-qa/references/qa-transition-gates.md +1 -1
- package/skills/bee/peaks-rd/SKILL.md +2 -2
- package/skills/bee/peaks-rd/references/rd-fanout-contracts.md +1 -1
- package/skills/bee/peaks-rd/references/rd-sub-agent-dispatch.md +8 -4
- package/skills/bee/peaks-rd/references/rd-transition-gates.md +3 -3
- package/skills/bee/peaks-rd/references/v2-12-fanout-collapse.md +2 -2
- package/skills/bee/peaks-rd/references/writing-handoff-frontmatter.md +1 -1
- package/skills/bee/peaks-reviewer/SKILL.md +1 -1
- package/skills/bee/peaks-sc/SKILL.md +1 -1
- package/skills/bee/peaks-security-audit/SKILL.md +10 -2
- package/skills/bee/peaks-txt/SKILL.md +4 -3
- package/skills/bee/peaks-ui/SKILL.md +3 -3
- package/skills/peaks-audit/SKILL.md +29 -1
- package/skills/peaks-code/SKILL.md +37 -17
- package/skills/peaks-code/references/fast-lane-norm.md +42 -0
- package/skills/peaks-code/references/fast-mode.md +3 -2
- package/skills/peaks-code/references/local-artifact-workspace.md +3 -3
- package/skills/peaks-code/references/micro-cycle.md +3 -3
- package/skills/peaks-code/references/resume-detection.md +1 -1
- package/skills/peaks-code/references/runbook.md +12 -6
- package/skills/peaks-code/references/step-11-memory-sediment.md +4 -0
- package/skills/peaks-code/references/sub-agent-dispatch.md +1 -1
- package/skills/peaks-code/references/swarm-dispatch-contract.md +40 -16
- package/skills/peaks-code/references/workflow-gates-and-types.md +6 -6
- package/skills/peaks-code/references/worktree-governance.md +4 -4
- package/skills/peaks-content/SKILL.md +1 -1
- package/skills/peaks-doctor/SKILL.md +1 -1
- package/skills/peaks-final-review/SKILL.md +31 -11
- package/skills/peaks-ide/SKILL.md +1 -1
- package/skills/peaks-issue-fix-orchestrator/SKILL.md +1 -1
- package/skills/peaks-race-code/SKILL.md +185 -0
- package/skills/peaks-resume/SKILL.md +1 -1
- package/skills/peaks-slice-decompose/SKILL.md +1 -1
- package/skills/peaks-solo/SKILL.md +1 -1
- package/skills/peaks-sop/SKILL.md +1 -1
- package/skills/peaks-status/SKILL.md +1 -1
- package/skills/peaks-test/SKILL.md +7 -4
- package/dist/cli/commands/vm-command-shared.d.ts +0 -23
- package/dist/cli/commands/vm-command-shared.js +0 -23
- package/dist/cli/commands/vm-commands.d.ts +0 -3
- package/dist/cli/commands/vm-commands.js +0 -45
- package/dist/cli/commands/vm-hypervisor-probe.d.ts +0 -27
- package/dist/cli/commands/vm-hypervisor-probe.js +0 -78
- package/dist/cli/commands/vm-hypervisor-runtime.d.ts +0 -15
- package/dist/cli/commands/vm-hypervisor-runtime.js +0 -64
- package/dist/cli/commands/vm-release-command.d.ts +0 -5
- package/dist/cli/commands/vm-release-command.js +0 -101
- package/dist/cli/commands/vm-spawn-command.d.ts +0 -5
- package/dist/cli/commands/vm-spawn-command.js +0 -177
- package/dist/cli/commands/vm-status-command.js +0 -50
- package/dist/services/audit/enforcers/lint-peaks-skill-runtime.d.ts +0 -23
- package/dist/services/audit/enforcers/lint-peaks-skill-runtime.js +0 -64
- package/dist/services/vm/vm-lease.d.ts +0 -40
- package/dist/services/vm/vm-lease.js +0 -160
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* extracted from `best-practice-scan-command.ts` (file-size cap campaign).
|
|
3
|
-
*
|
|
4
|
-
* helper, and the synthetic-lookup refusal renderer.
|
|
3
|
+
* Partly a mechanical move: help-text constants, the artifact directory path
|
|
4
|
+
* helper, and the synthetic-lookup refusal renderer. Later additions (the
|
|
5
|
+
* refusal write-path rule, the fragments-free refusal) live here for the same
|
|
6
|
+
* file-size reason.
|
|
5
7
|
*/
|
|
6
|
-
import {
|
|
8
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { dirname, join, parse } from 'node:path';
|
|
10
|
+
import { fail } from 'peaks-loop-shared/result';
|
|
11
|
+
import { printResult } from '../cli-helpers.js';
|
|
7
12
|
export const CATCH_GATE_PROMPT = [
|
|
8
13
|
'⚠️ 任何跟你真实业务不一样,改 — LLM 推荐可能错。',
|
|
9
14
|
'回应 (默认 = 接受): 接受 / 接受方案 A|接受方案 B|接受方案 C / 拒绝 + 原因'
|
|
@@ -17,6 +22,18 @@ export const SYNTHETIC_SOURCE_MESSAGE = 'best-practice-scan: SKIPPED — the Con
|
|
|
17
22
|
export function bestPracticeDir(projectRoot) {
|
|
18
23
|
return join(projectRoot, 'best-practice');
|
|
19
24
|
}
|
|
25
|
+
/** `YYYY-MM-DD` is 10 characters, and the slug is capped at 32 so the filename
|
|
26
|
+
* stays a filename. Both are part of the pinned artifact path. */
|
|
27
|
+
const ISO_DATE_LENGTH = 10;
|
|
28
|
+
const SLUG_MAX_LENGTH = 32;
|
|
29
|
+
/** `<project>/best-practice/<date>-<slug>.md`. The slug is lossy by design:
|
|
30
|
+
* every character outside `[A-Za-z0-9_-]` collapses to `-` and the result is
|
|
31
|
+
* truncated to 32, so no intent can introduce a path separator. */
|
|
32
|
+
export function scanArtifactPath(projectRoot, slugSource) {
|
|
33
|
+
const dateStr = new Date().toISOString().slice(0, ISO_DATE_LENGTH);
|
|
34
|
+
const slug = slugSource.replace(/[^a-zA-Z0-9_-]+/g, '-').slice(0, SLUG_MAX_LENGTH) || 'intent';
|
|
35
|
+
return join(bestPracticeDir(projectRoot), `${dateStr}-${slug}.md`);
|
|
36
|
+
}
|
|
20
37
|
/** Refusal body for a synthetic scan. It is written to the artifact path so
|
|
21
38
|
* the skip survives the fire-and-forget caller (`best-practice-auto-trigger`
|
|
22
39
|
* spawns with `stdio: 'ignore'`, so stdout never reaches anyone). */
|
|
@@ -30,7 +47,73 @@ export function renderSyntheticRefusal(opts) {
|
|
|
30
47
|
'',
|
|
31
48
|
`- language: ${opts.language}`,
|
|
32
49
|
`- transport that answered: ${opts.source} (stub)`,
|
|
33
|
-
'- Step 2.5: recorded as skipped, reason "synthetic-lookup". Re-run this step
|
|
34
|
-
' lookup
|
|
50
|
+
'- Step 2.5: recorded as skipped, reason "synthetic-lookup". Re-run this step with',
|
|
51
|
+
' --lookup-results <file> once real lookup results are available; a gate cannot be',
|
|
52
|
+
' satisfied from a fabricated scan.'
|
|
35
53
|
].join('\n');
|
|
36
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* A refusal must never overwrite anything.
|
|
57
|
+
*
|
|
58
|
+
* The rendered table and the refusal are keyed on the same `(date, intent)`, and
|
|
59
|
+
* an auto-triggered scan runs with the same intent as the injected one, so a
|
|
60
|
+
* refusal landing second used to destroy a real recommendation. The rule is now
|
|
61
|
+
* unconditional — *any* existing file at the primary path wins — because the
|
|
62
|
+
* only way to tell a refusal from a recommendation without a forgeable content
|
|
63
|
+
* test is to not need the test at all. Refusals for an occupied path go to
|
|
64
|
+
* `best-practice/skipped/`, a directory no primary path can reach: the slug
|
|
65
|
+
* collapses every character outside `[A-Za-z0-9_-]`, so no intent can produce a
|
|
66
|
+
* separator. A fresh project still records its refusal at the primary path,
|
|
67
|
+
* which `tests/unit/cli/commands/best-practice-scan-command.test.ts` pins.
|
|
68
|
+
*
|
|
69
|
+
* Returns where the refusal landed.
|
|
70
|
+
*/
|
|
71
|
+
export function writeRefusal(projectRoot, intent, refusal) {
|
|
72
|
+
const primary = scanArtifactPath(projectRoot, intent);
|
|
73
|
+
const target = existsSync(primary)
|
|
74
|
+
? join(dirname(primary), 'skipped', parse(primary).base)
|
|
75
|
+
: primary;
|
|
76
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
77
|
+
writeFileSync(target, refusal + '\n', 'utf8');
|
|
78
|
+
return target;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Write the rendered table to `artifactPath` and return nothing.
|
|
82
|
+
*
|
|
83
|
+
* The artifact is the durable side effect and the envelope is not, so the
|
|
84
|
+
* payload is proved to serialise *before* anything is written: a payload the
|
|
85
|
+
* printer cannot render must not leave behind an artifact claiming a scan that
|
|
86
|
+
* never reported.
|
|
87
|
+
*/
|
|
88
|
+
export function writeRenderedArtifact(artifactPath, table, payload) {
|
|
89
|
+
JSON.stringify(payload);
|
|
90
|
+
mkdirSync(dirname(artifactPath), { recursive: true });
|
|
91
|
+
writeFileSync(artifactPath, table + '\n', 'utf8');
|
|
92
|
+
}
|
|
93
|
+
export const NO_FRAGMENTS_MESSAGE = 'best-practice-scan: NO FRAGMENTS — the lookups this scan resolved against returned no ' +
|
|
94
|
+
'documentation at all, so there is nothing to compare and no recommendation to make. ' +
|
|
95
|
+
'No comparison table, no ★ and no ⚠️ catch gate were produced, and no artifact was written.';
|
|
96
|
+
/**
|
|
97
|
+
* Refuse a scan that resolved against real lookups and still found nothing.
|
|
98
|
+
*
|
|
99
|
+
* This is not the synthetic path: no stub took part, so `scan.synthetic` is
|
|
100
|
+
* false, and the orchestrator is right to say so — it answers "was anything
|
|
101
|
+
* fabricated?", not "was anything found?". Without this refusal the empty
|
|
102
|
+
* fallback renders a full table with a `★` on it, from zero fragments, and exits
|
|
103
|
+
* 0. Writes nothing: an absent artifact is the honest record of an empty scan.
|
|
104
|
+
*/
|
|
105
|
+
export function emitNoFragmentsRefusal(io, asJson, scope) {
|
|
106
|
+
printResult(io, fail('best-practice.scan', 'BEST_PRACTICE_SCAN_NO_FRAGMENTS', NO_FRAGMENTS_MESSAGE, {
|
|
107
|
+
project: scope.project,
|
|
108
|
+
intent: scope.intent,
|
|
109
|
+
language: scope.language,
|
|
110
|
+
scanSource: scope.source,
|
|
111
|
+
fragments: 0,
|
|
112
|
+
synthetic: false,
|
|
113
|
+
step25: 'skipped-no-fragments',
|
|
114
|
+
artifactPath: null
|
|
115
|
+
}, [
|
|
116
|
+
'Supply a results file whose context7 or websearch entry declares ok: true with at least one fragment',
|
|
117
|
+
'Or rerun without --lookup-results to record the honest no-injection skip instead'
|
|
118
|
+
]), asJson);
|
|
119
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LookupFn } from '../../services/best-practice/scan-orchestrator.js';
|
|
2
|
+
import { type ProgramIO } from '../cli-helpers.js';
|
|
3
|
+
/** The scan seam's two optional lookups, ready to spread into `ScanOptions`. */
|
|
4
|
+
export type InjectedLookups = {
|
|
5
|
+
context7Lookup?: LookupFn;
|
|
6
|
+
webSearchLookup?: LookupFn;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Rule 1 plus the refusal. Returns the injected seam lookups, or `null` after
|
|
10
|
+
* emitting `BEST_PRACTICE_SCAN_INVALID_RESULTS` — in which case the caller must
|
|
11
|
+
* set a non-zero exit code and scan nothing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readLookupResultsOrFail(file: string, intent: string, io: ProgramIO, asJson: boolean): InjectedLookups | null;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reads and validates the `--lookup-results <file>` document that lets a
|
|
4
|
+
* caller — in practice the LLM, holding real Context7 / WebSearch results from
|
|
5
|
+
* its own MCP tool — inject real documentation fragments into
|
|
6
|
+
* `best-practice-scan`. The CLI itself never performs that lookup and never
|
|
7
|
+
* touches the network; this module is the only seam between the two.
|
|
8
|
+
*
|
|
9
|
+
* The document speaks the scan seam's own vocabulary: one optional key per
|
|
10
|
+
* priority, whose value is exactly `LookupFn`'s return type.
|
|
11
|
+
*
|
|
12
|
+
* { "intent": "<the same string that was passed to --intent>",
|
|
13
|
+
* "context7": { "ok": true, "results": [ { "title", "url", "snippet" } ] },
|
|
14
|
+
* "websearch": { "ok": true, "results": [ { "title", "url", "snippet" } ] } }
|
|
15
|
+
*
|
|
16
|
+
* One refusal code, `BEST_PRACTICE_SCAN_INVALID_RESULTS`. A file that breaks
|
|
17
|
+
* any rule performs no scan and writes no artifact — the caller is the LLM,
|
|
18
|
+
* which either produced a valid file or needs to be told which field is wrong.
|
|
19
|
+
*
|
|
20
|
+
* `ok: true` requires a non-empty `results` array: a claimed hit that carries
|
|
21
|
+
* nothing is the shape a fabrication would take, and it is refused rather than
|
|
22
|
+
* rendered. **The converse is not a miss.** `ok: false` does not end the scan —
|
|
23
|
+
* the orchestrator falls *through* a failed priority to the next one, and a
|
|
24
|
+
* chain in which no stub took part reports `synthetic: false` even when it found
|
|
25
|
+
* nothing. A document declaring `ok: false` on every seam it supplies is
|
|
26
|
+
* therefore valid *and* fragments-free; the CLI, not this module, refuses it.
|
|
27
|
+
*
|
|
28
|
+
* Unknown keys are refused at every level, not just the top: the document is
|
|
29
|
+
* the caller's, and a key this module would ignore is a key the caller believed
|
|
30
|
+
* it was sending. Refusing them also bounds the parsed structure, so nothing
|
|
31
|
+
* downstream can be handed an arbitrarily deep object.
|
|
32
|
+
*/
|
|
33
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
34
|
+
import { fail, redactSensitiveErrorMessage } from 'peaks-loop-shared/result';
|
|
35
|
+
import { getErrorMessage, printableWarningText, printResult } from '../cli-helpers.js';
|
|
36
|
+
/** The two seam keys a document may carry, named as the orchestrator names them. */
|
|
37
|
+
const SEAM_KEYS = ['context7', 'websearch'];
|
|
38
|
+
const ALLOWED_KEYS = ['intent', ...SEAM_KEYS];
|
|
39
|
+
const ALLOWED_SEAM_KEYS = ['ok', 'results'];
|
|
40
|
+
const ALLOWED_FRAGMENT_KEYS = ['title', 'url', 'snippet'];
|
|
41
|
+
const INVALID_RESULTS_CODE = 'BEST_PRACTICE_SCAN_INVALID_RESULTS';
|
|
42
|
+
/** A best-practice scan cites a handful of fragments; it does not ingest a corpus. */
|
|
43
|
+
const MAX_RESULTS_FILE_BYTES = 1_048_576;
|
|
44
|
+
const MAX_FRAGMENTS_PER_SEAM = 64;
|
|
45
|
+
const BOM_CODE_POINT = 0xfeff;
|
|
46
|
+
function isPlainObject(value) {
|
|
47
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The first key of `value` that is not in `allowed`, or `undefined`.
|
|
51
|
+
*
|
|
52
|
+
* The NAME comes back sanitised for echoing, and that is deliberate: every
|
|
53
|
+
* caller of this function puts the key into a refusal message, the key is the
|
|
54
|
+
* document's own text, and nothing stops it carrying an ESC sequence (which
|
|
55
|
+
* reaches a terminal raw) or a newline (which forges a line of this command's
|
|
56
|
+
* own output). Matching is done against the raw key first, so the allowance
|
|
57
|
+
* check is unaffected.
|
|
58
|
+
*/
|
|
59
|
+
function firstUnknownKey(value, allowed) {
|
|
60
|
+
const key = Object.keys(value).find((candidate) => !allowed.includes(candidate));
|
|
61
|
+
return key === undefined ? undefined : safeToEcho(key);
|
|
62
|
+
}
|
|
63
|
+
function isFragment(value) {
|
|
64
|
+
if (!isPlainObject(value))
|
|
65
|
+
return false;
|
|
66
|
+
if (firstUnknownKey(value, ALLOWED_FRAGMENT_KEYS) !== undefined)
|
|
67
|
+
return false;
|
|
68
|
+
return ALLOWED_FRAGMENT_KEYS.every((field) => {
|
|
69
|
+
const candidate = value[field];
|
|
70
|
+
return typeof candidate === 'string' && candidate.trim().length > 0;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** The first malformed fragment, as its refusal message; `null` when all are well formed. */
|
|
74
|
+
function firstBadFragment(key, results) {
|
|
75
|
+
for (let index = 0; index < results.length; index += 1) {
|
|
76
|
+
if (!isFragment(results[index])) {
|
|
77
|
+
return `"${key}".results[${index}] must have non-empty string title, url and snippet, and no other keys`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
/** `{ ok: boolean, results: unknown[] }`, the only seam value shape accepted. */
|
|
83
|
+
function isSeamShape(value) {
|
|
84
|
+
return isPlainObject(value) && typeof value.ok === 'boolean' && Array.isArray(value.results);
|
|
85
|
+
}
|
|
86
|
+
/** Rules 6-8: one seam value must be `{ ok: boolean, results: DocFragment[] }`. */
|
|
87
|
+
function parseSeam(key, value) {
|
|
88
|
+
if (!isSeamShape(value)) {
|
|
89
|
+
return {
|
|
90
|
+
ok: false,
|
|
91
|
+
message: `"${key}" must be an object with a boolean "ok" and an array "results"`
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const unknownKey = firstUnknownKey(value, ALLOWED_SEAM_KEYS);
|
|
95
|
+
if (unknownKey !== undefined) {
|
|
96
|
+
return {
|
|
97
|
+
ok: false,
|
|
98
|
+
message: `unknown key "${unknownKey}" in "${key}"; allowed keys are ${ALLOWED_SEAM_KEYS.join(', ')}`
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const results = value.results;
|
|
102
|
+
if (value.ok && results.length === 0) {
|
|
103
|
+
return {
|
|
104
|
+
ok: false,
|
|
105
|
+
message: `"${key}" declares ok: true but "results" is empty; a hit must carry at least one fragment`
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Kept deliberately (Karpathy V2 raised it as speculative): `ok: false` with a
|
|
109
|
+
// non-empty `results` is a document that contradicts itself, and the
|
|
110
|
+
// orchestrator would read `ok` and silently discard the fragments. A caller
|
|
111
|
+
// that meant `ok: true` and mistyped it must be told, not half-read.
|
|
112
|
+
if (!value.ok && results.length > 0) {
|
|
113
|
+
return {
|
|
114
|
+
ok: false,
|
|
115
|
+
message: `"${key}" declares ok: false but "results" is non-empty`
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (results.length > MAX_FRAGMENTS_PER_SEAM) {
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
message: `"${key}" carries ${results.length} fragments, over the cap of ${MAX_FRAGMENTS_PER_SEAM}; cite the few that matter`
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const bad = firstBadFragment(key, results);
|
|
125
|
+
if (bad !== null)
|
|
126
|
+
return { ok: false, message: bad };
|
|
127
|
+
return {
|
|
128
|
+
ok: true,
|
|
129
|
+
value: { ok: value.ok, results: results }
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** Rules 2-8 over an already-parsed JSON value. Pure: no fs, no io. */
|
|
133
|
+
function parseLookupResults(value, intent) {
|
|
134
|
+
if (!isPlainObject(value)) {
|
|
135
|
+
return {
|
|
136
|
+
ok: false,
|
|
137
|
+
message: `the top level must be a JSON object, not ${Array.isArray(value) ? 'an array' : typeof value}`
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const unknownKey = firstUnknownKey(value, ALLOWED_KEYS);
|
|
141
|
+
if (unknownKey !== undefined) {
|
|
142
|
+
return {
|
|
143
|
+
ok: false,
|
|
144
|
+
message: `unknown top-level key "${unknownKey}"; allowed keys are ${ALLOWED_KEYS.join(', ')}`
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const present = SEAM_KEYS.filter((key) => value[key] !== undefined);
|
|
148
|
+
if (present.length === 0) {
|
|
149
|
+
return { ok: false, message: 'at least one of "context7" or "websearch" must be present' };
|
|
150
|
+
}
|
|
151
|
+
if (value.intent !== intent) {
|
|
152
|
+
const declared = typeof value.intent === 'string' ? safeToEcho(value.intent) : value.intent;
|
|
153
|
+
return {
|
|
154
|
+
ok: false,
|
|
155
|
+
message: `intent mismatch: the file declares ${JSON.stringify(declared)} but --intent is ${JSON.stringify(safeToEcho(intent))}`
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const lookups = {};
|
|
159
|
+
for (const key of present) {
|
|
160
|
+
const parsed = parseSeam(key, value[key]);
|
|
161
|
+
if (!parsed.ok)
|
|
162
|
+
return { ok: false, message: parsed.message };
|
|
163
|
+
const seam = parsed.value;
|
|
164
|
+
// The return type is annotated because the `async` is a contract, not a
|
|
165
|
+
// convenience: `LookupFn` requires a Promise and `seam` is a plain object.
|
|
166
|
+
if (key === 'context7') {
|
|
167
|
+
lookups.context7Lookup = async () => seam;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
lookups.webSearchLookup = async () => seam;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return { ok: true, lookups };
|
|
174
|
+
}
|
|
175
|
+
/** A caller-supplied string is echoed into a refusal; make it safe to echo. */
|
|
176
|
+
function safeToEcho(value) {
|
|
177
|
+
return printableWarningText(redactSensitiveErrorMessage(value));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Rule 1 plus the refusal. Returns the injected seam lookups, or `null` after
|
|
181
|
+
* emitting `BEST_PRACTICE_SCAN_INVALID_RESULTS` — in which case the caller must
|
|
182
|
+
* set a non-zero exit code and scan nothing.
|
|
183
|
+
*/
|
|
184
|
+
export function readLookupResultsOrFail(file, intent, io, asJson) {
|
|
185
|
+
const read = readJsonOrFail(file);
|
|
186
|
+
const parsed = read.ok
|
|
187
|
+
? parseLookupResults(read.value, intent)
|
|
188
|
+
: { ok: false, message: read.message };
|
|
189
|
+
if (parsed.ok)
|
|
190
|
+
return parsed.lookups;
|
|
191
|
+
printResult(io, fail('best-practice.scan', INVALID_RESULTS_CODE, parsed.message, { lookupResults: safeToEcho(file), intent: safeToEcho(intent) }, ['Fix the lookup-results file, or rerun without --lookup-results to record the honest skip.']), asJson);
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
/** Rule 1: read the file and parse it as JSON, or say why not. */
|
|
195
|
+
function readJsonOrFail(file) {
|
|
196
|
+
const shown = safeToEcho(file);
|
|
197
|
+
// The size gate runs BEFORE the read so an oversized file is never read, and
|
|
198
|
+
// before the parse so it is never parsed.
|
|
199
|
+
let size;
|
|
200
|
+
try {
|
|
201
|
+
size = statSync(file).size;
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
return {
|
|
205
|
+
ok: false,
|
|
206
|
+
message: `cannot read lookup-results file at ${shown}: ${safeToEcho(getErrorMessage(err))}`
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
if (size > MAX_RESULTS_FILE_BYTES) {
|
|
210
|
+
return {
|
|
211
|
+
ok: false,
|
|
212
|
+
message: `${shown} is ${size} bytes, over the ${MAX_RESULTS_FILE_BYTES}-byte cap for a ` +
|
|
213
|
+
'lookup-results file; cite a handful of fragments, not a corpus'
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
let raw;
|
|
217
|
+
try {
|
|
218
|
+
raw = readFileSync(file, 'utf8');
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
return {
|
|
222
|
+
ok: false,
|
|
223
|
+
message: `cannot read lookup-results file at ${shown}: ${safeToEcho(getErrorMessage(err))}`
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
// Windows editors write a BOM and JSON.parse rejects it, so strip it.
|
|
227
|
+
const text = raw.charCodeAt(0) === BOM_CODE_POINT ? raw.slice(1) : raw;
|
|
228
|
+
try {
|
|
229
|
+
return { ok: true, value: JSON.parse(text) };
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
// Deliberately not echoing the parser's message: V8 quotes ~10 bytes of the
|
|
233
|
+
// file back, which leaks file content past `fail()`'s secret redaction, and
|
|
234
|
+
// copies control bytes to a terminal verbatim.
|
|
235
|
+
return { ok: false, message: `${shown} is not valid JSON` };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Slice 2 — `peaks code
|
|
2
|
+
* Slice 2 — `peaks code plan --fast <session-id>` (peaks-code fast mode).
|
|
3
3
|
*
|
|
4
4
|
* The `peaks-code` SKILL orchestrates an LLM-side workflow:
|
|
5
5
|
* load-memory -> standards-preflight -> rd-cycle -> qa-cycle -> emit-txt
|
|
6
6
|
*
|
|
7
7
|
* The CLI surface here is intentionally narrow: it builds a CodePlan and
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* prints it (`peaks code plan`). `runCodeFast` is exported below but has no
|
|
9
|
+
* caller in this repo — the orchestrating it describes is still LLM-side, so
|
|
10
|
+
* nothing actually runs a plan yet. Fast mode skips memory full-load,
|
|
11
|
+
* standards preflight, and the QA repair loop. Round-trip KPI: ≤ 30s.
|
|
10
12
|
*
|
|
11
13
|
* No new service layer — the orchestrator is the in-file `runCodeFast`
|
|
12
14
|
* function. Hooks are injected so tests can mock at the boundary.
|
|
@@ -78,7 +80,7 @@ export declare function runCodeFast(opts: {
|
|
|
78
80
|
hooks: CodeHooks;
|
|
79
81
|
}): Promise<CodeRunResult>;
|
|
80
82
|
/**
|
|
81
|
-
* Register the `peaks code
|
|
83
|
+
* Register the `peaks code plan --fast <session-id>` command. The actual
|
|
82
84
|
* LLM-side orchestration is driven by the SKILL.md (LLM-side), so this
|
|
83
85
|
* CLI command is a thin surface that builds the plan and emits a JSON
|
|
84
86
|
* envelope for downstream tooling.
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Slice 2 — `peaks code
|
|
2
|
+
* Slice 2 — `peaks code plan --fast <session-id>` (peaks-code fast mode).
|
|
3
3
|
*
|
|
4
4
|
* The `peaks-code` SKILL orchestrates an LLM-side workflow:
|
|
5
5
|
* load-memory -> standards-preflight -> rd-cycle -> qa-cycle -> emit-txt
|
|
6
6
|
*
|
|
7
7
|
* The CLI surface here is intentionally narrow: it builds a CodePlan and
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* prints it (`peaks code plan`). `runCodeFast` is exported below but has no
|
|
9
|
+
* caller in this repo — the orchestrating it describes is still LLM-side, so
|
|
10
|
+
* nothing actually runs a plan yet. Fast mode skips memory full-load,
|
|
11
|
+
* standards preflight, and the QA repair loop. Round-trip KPI: ≤ 30s.
|
|
10
12
|
*
|
|
11
13
|
* No new service layer — the orchestrator is the in-file `runCodeFast`
|
|
12
14
|
* function. Hooks are injected so tests can mock at the boundary.
|
|
@@ -100,7 +102,7 @@ export async function runCodeFast(opts) {
|
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
104
|
/**
|
|
103
|
-
* Register the `peaks code
|
|
105
|
+
* Register the `peaks code plan --fast <session-id>` command. The actual
|
|
104
106
|
* LLM-side orchestration is driven by the SKILL.md (LLM-side), so this
|
|
105
107
|
* CLI command is a thin surface that builds the plan and emits a JSON
|
|
106
108
|
* envelope for downstream tooling.
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
* Vendor-neutral PreToolUse hook entry. Reads the standard hook JSON
|
|
4
|
-
* payload from stdin
|
|
5
|
-
* (
|
|
6
|
-
* PEAKS_CODE_PROHIBITED_DIRECT_EDIT (deny).
|
|
4
|
+
* payload from stdin and either exits 0 (allow) or exits 2 with stderr
|
|
5
|
+
* containing PEAKS_CODE_PROHIBITED_DIRECT_EDIT (deny).
|
|
7
6
|
*
|
|
8
7
|
* This command is the runtime adapter for the shell-script sibling
|
|
9
8
|
* (`src/services/hooks/pre-tool-code-gate.sh`). Both share the same
|
|
@@ -11,8 +10,9 @@
|
|
|
11
10
|
* function (`decideGateAction`) the shell script encodes.
|
|
12
11
|
*
|
|
13
12
|
* Settings.json entry shape (vendor-neutral, registered by
|
|
14
|
-
* `peaks hooks install`):
|
|
15
|
-
*
|
|
13
|
+
* `peaks hooks install`): an `Edit|Write|MultiEdit` matcher whose command is
|
|
14
|
+
* `peaks code-gate`, carrying the adapter's own project-root env var and
|
|
15
|
+
* `--json`.
|
|
16
16
|
*
|
|
17
17
|
* The vendor-specific install code (`src/cli/commands/hooks-commands.ts`
|
|
18
18
|
* + `src/services/ide/adapters/*`) is the only place that knows how
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
* Vendor-neutral PreToolUse hook entry. Reads the standard hook JSON
|
|
4
|
-
* payload from stdin
|
|
5
|
-
* (
|
|
6
|
-
* PEAKS_CODE_PROHIBITED_DIRECT_EDIT (deny).
|
|
4
|
+
* payload from stdin and either exits 0 (allow) or exits 2 with stderr
|
|
5
|
+
* containing PEAKS_CODE_PROHIBITED_DIRECT_EDIT (deny).
|
|
7
6
|
*
|
|
8
7
|
* This command is the runtime adapter for the shell-script sibling
|
|
9
8
|
* (`src/services/hooks/pre-tool-code-gate.sh`). Both share the same
|
|
@@ -11,8 +10,9 @@
|
|
|
11
10
|
* function (`decideGateAction`) the shell script encodes.
|
|
12
11
|
*
|
|
13
12
|
* Settings.json entry shape (vendor-neutral, registered by
|
|
14
|
-
* `peaks hooks install`):
|
|
15
|
-
*
|
|
13
|
+
* `peaks hooks install`): an `Edit|Write|MultiEdit` matcher whose command is
|
|
14
|
+
* `peaks code-gate`, carrying the adapter's own project-root env var and
|
|
15
|
+
* `--json`.
|
|
16
16
|
*
|
|
17
17
|
* The vendor-specific install code (`src/cli/commands/hooks-commands.ts`
|
|
18
18
|
* + `src/services/ide/adapters/*`) is the only place that knows how
|
|
@@ -21,7 +21,44 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { addJsonOption, printResult } from '../cli-helpers.js';
|
|
23
23
|
import { decideGateAction, extractFilePath } from '../../services/hooks/pre-tool-code-gate.js';
|
|
24
|
+
import { hasLeaseForCaller, resolveActiveSkillForCaller } from '../../services/audit/enforcers/active-skill-resolver.js';
|
|
25
|
+
import { resolveCanonicalProjectRoot } from '../../services/config/config-service.js';
|
|
26
|
+
import { pluckObject, pluckString } from '../../services/ide/hook-translator.js';
|
|
24
27
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
28
|
+
/**
|
|
29
|
+
* Read the tool call's name from whichever spelling supplies it, or `''` when
|
|
30
|
+
* neither does. `tool_name` is the harness spelling; `tool` is the one this
|
|
31
|
+
* command's own header documents. The shell-script sibling accepts both and
|
|
32
|
+
* calls each key by name, and the two gates must not disagree about what a
|
|
33
|
+
* payload says.
|
|
34
|
+
*/
|
|
35
|
+
function readToolName(parsed) {
|
|
36
|
+
return pluckString(parsed, ['tool_name']) ?? pluckString(parsed, ['tool']) ?? '';
|
|
37
|
+
}
|
|
38
|
+
/** Read the tool call's arguments from whichever spelling supplies them. */
|
|
39
|
+
function readToolInput(parsed) {
|
|
40
|
+
return pluckObject(parsed, ['tool_input']) ?? pluckObject(parsed, ['input']) ?? {};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve which skill is driving this tool call, or `null` when that cannot be
|
|
44
|
+
* established.
|
|
45
|
+
*
|
|
46
|
+
* The identity comes from the payload rather than the environment: whether a
|
|
47
|
+
* hook subprocess inherits caller-identifying env is unverified, and the
|
|
48
|
+
* payload already carries the id. The lease lookup is scoped to that id — an id
|
|
49
|
+
* owning no lease is indistinguishable from an id that is not the lease's key,
|
|
50
|
+
* and an unscoped read would answer with whichever lease the directory listing
|
|
51
|
+
* yielded first, i.e. with another window's skill. Both cases resolve to
|
|
52
|
+
* `null`, which leaves `decideGateAction` on its two-argument behaviour.
|
|
53
|
+
*/
|
|
54
|
+
function resolveDriver(projectRoot, payload) {
|
|
55
|
+
const callerId = payload.caller_id ?? payload.session_id;
|
|
56
|
+
if (typeof callerId !== 'string' || callerId.length === 0)
|
|
57
|
+
return null;
|
|
58
|
+
if (!hasLeaseForCaller(projectRoot, callerId))
|
|
59
|
+
return null;
|
|
60
|
+
return resolveActiveSkillForCaller(projectRoot, { callerId }).skill;
|
|
61
|
+
}
|
|
25
62
|
export function registerCodeGateCommand(program, io) {
|
|
26
63
|
addJsonOption(program
|
|
27
64
|
.command('code-gate')
|
|
@@ -32,7 +69,8 @@ export function registerCodeGateCommand(program, io) {
|
|
|
32
69
|
'(src/, tests/unit/, tests/integration/, config/, bin/, scripts/) so the ' +
|
|
33
70
|
'orchestrator is forced to dispatch via `peaks sub-agent dispatch rd`. ' +
|
|
34
71
|
'Allow-listed paths (.peaks/**, skills/**, docs/**) are NOT gated.')
|
|
35
|
-
.option('--dry-run', 'emit JSON verdict to stdout instead of exit code; useful for tests')
|
|
72
|
+
.option('--dry-run', 'emit JSON verdict to stdout instead of exit code; useful for tests')
|
|
73
|
+
.option('--project <path>', 'project the driver lease is resolved against (default: current directory)')).action(async (opts) => {
|
|
36
74
|
let raw = '';
|
|
37
75
|
try {
|
|
38
76
|
raw = await readStdin();
|
|
@@ -57,15 +95,17 @@ export function registerCodeGateCommand(program, io) {
|
|
|
57
95
|
}
|
|
58
96
|
process.exit(0);
|
|
59
97
|
}
|
|
60
|
-
const
|
|
98
|
+
const tool = readToolName(parsed);
|
|
99
|
+
const input = readToolInput(parsed);
|
|
100
|
+
const verdict = decideGateAction(tool, input, resolveDriver(resolveCanonicalProjectRoot(opts.project ?? process.cwd()), parsed));
|
|
61
101
|
if (opts.dryRun === true) {
|
|
62
102
|
if (verdict.action === 'allow') {
|
|
63
|
-
printResult(io, ok('code.gate', { action: 'allow', tool
|
|
103
|
+
printResult(io, ok('code.gate', { action: 'allow', tool, filePath: extractFilePath(input) }, [], []), opts.json);
|
|
64
104
|
}
|
|
65
105
|
else {
|
|
66
106
|
printResult(io, fail('code.gate', 'PEAKS_CODE_PROHIBITED_DIRECT_EDIT', verdict.message, {
|
|
67
107
|
action: 'deny',
|
|
68
|
-
tool
|
|
108
|
+
tool,
|
|
69
109
|
filePath: verdict.filePath,
|
|
70
110
|
reason: verdict.reason
|
|
71
111
|
}, ['use peaks sub-agent dispatch rd']), opts.json);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Extracted VERBATIM from `code-mode-gate-commands.ts` (job
|
|
5
5
|
* strict-remediation-abc, slice c1-eslint-family-sweep, leaf c4w1-cli-b) so
|
|
6
6
|
* the registration file clears the 300-line cap. The description, the
|
|
7
|
-
* `<
|
|
7
|
+
* `<session-id>` argument, the `--fast` / `--json` options, the stdout
|
|
8
8
|
* formatting (`SKIP`/`RUN ` + `repair=on|off` for `qa-cycle`), and the
|
|
9
9
|
* JSON-envelope shape `{ ok: true, data: plan }` are the code that was already
|
|
10
10
|
* there. Nothing here swallows anything and no new error handling was
|
|
@@ -3,7 +3,7 @@ export function registerCodeModePlan(code) {
|
|
|
3
3
|
code
|
|
4
4
|
.command('plan')
|
|
5
5
|
.description('Build and print a CodePlan without executing it')
|
|
6
|
-
.argument('<
|
|
6
|
+
.argument('<session-id>', 'session id to plan against')
|
|
7
7
|
.option('--fast', 'fast mode: skip memory full-load, standards preflight, and QA repair loop', false)
|
|
8
8
|
.option('--json', 'emit JSON envelope')
|
|
9
9
|
.action((sessionId, opts) => {
|
|
@@ -12,7 +12,7 @@ export function registerCodeModePlan(code) {
|
|
|
12
12
|
process.stdout.write(JSON.stringify({ ok: true, data: plan }) + '\n');
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
process.stdout.write(`
|
|
15
|
+
process.stdout.write(`session-id: ${plan.sessionId}\n`);
|
|
16
16
|
for (const step of plan.steps) {
|
|
17
17
|
const flag = step.skipped ? 'SKIP' : 'RUN ';
|
|
18
18
|
const repair = step.id === 'qa-cycle' ? ` repair=${step.repairLoop === true ? 'on' : 'off'}` : '';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describeMemoryBlockDrops, executeProjectMemoryExtract, SENSITIVE_MEMORY_CHECKS, summarizeProjectMemoryExtractResult, UnsafeMemoryError } from '../../../services/memory/project-memory-service.js';
|
|
1
|
+
import { describeMemoryBlockDrops, describeMemoryWriteSkips, executeProjectMemoryExtract, SENSITIVE_MEMORY_CHECKS, summarizeProjectMemoryExtractResult, UnsafeMemoryError } from '../../../services/memory/project-memory-service.js';
|
|
2
2
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
3
3
|
import { addJsonOption, getErrorMessage, printResult } from '../../cli-helpers.js';
|
|
4
4
|
import { refuseBothFlags } from './memory-command-shared.js';
|
|
@@ -47,10 +47,15 @@ function runExtract(io, options) {
|
|
|
47
47
|
apply: options.apply === true
|
|
48
48
|
});
|
|
49
49
|
// A block that was found but not extracted must not vanish silently: the
|
|
50
|
-
// parser's rejection reasons
|
|
51
|
-
// channel (JSON: `warnings[]`; human:
|
|
52
|
-
// unchanged —
|
|
53
|
-
|
|
50
|
+
// parser's rejection reasons, and the writes the store already held, both ride
|
|
51
|
+
// the envelope's existing `warnings` channel (JSON: `warnings[]`; human:
|
|
52
|
+
// `warning: …` on stderr). `data` is unchanged — neither adds a field to the
|
|
53
|
+
// summary, and `writtenFiles` was already there to be compared against
|
|
54
|
+
// `plannedWrites`.
|
|
55
|
+
printResult(io, ok('memory.extract', summarizeProjectMemoryExtractResult(result), [
|
|
56
|
+
...describeMemoryBlockDrops(result.droppedBlocks),
|
|
57
|
+
...describeMemoryWriteSkips(result.skippedWrites, result.plannedWrites.length, result.writtenFiles.length)
|
|
58
|
+
]), options.json);
|
|
54
59
|
}
|
|
55
60
|
function emitExtractFailure(io, options, error) {
|
|
56
61
|
const refusal = error instanceof UnsafeMemoryError ? error : null;
|