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,7 +1,7 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process';
|
|
2
1
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
3
2
|
import { join } from 'node:path';
|
|
4
3
|
import { countRawLines, fileSizeCapFor, isPolicyMeasuredFile } from './file-size-policy.js';
|
|
4
|
+
import { readBaseLineCount, readChangedFiles } from './file-size-baseline.js';
|
|
5
5
|
/**
|
|
6
6
|
* Paths exempt from the file-size cap. The cap is Karpathy's "Simplicity
|
|
7
7
|
* First": it exists to make a human *simplify* an over-long file. A path is
|
|
@@ -59,30 +59,37 @@ export function isSizeCapExempt(file) {
|
|
|
59
59
|
const normalized = file.replace(/\\/g, '/');
|
|
60
60
|
return SIZE_CAP_EXEMPT_PATTERNS.some((pattern) => exemptPatternToRegExp(pattern).test(normalized));
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function countLines(filePath) {
|
|
63
|
+
return countRawLines(readFileSync(filePath, 'utf8'));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Pre-#015: `readFileSync` threw ENOENT for a path in `git diff` that no longer
|
|
67
|
+
* exists on disk, aborting the whole `request transition rd → implemented` flow.
|
|
68
|
+
* A deleted path has no lines to count, so it is reported in `deletedFiles` and
|
|
69
|
+
* skipped. `readChangedFiles` already excludes `--diff-filter=D`.
|
|
70
|
+
*/
|
|
71
|
+
function classifyPath(absolute) {
|
|
72
|
+
if (existsSync(absolute))
|
|
73
|
+
return 'present';
|
|
63
74
|
try {
|
|
64
|
-
|
|
65
|
-
// (--diff-filter=D) are intentionally excluded: they have no on-disk
|
|
66
|
-
// body to count, and a refactor that deletes large files is exactly
|
|
67
|
-
// when the gate should NOT block. Slice #015 fix.
|
|
68
|
-
const trackedRaw = execFileSync('git', ['-C', projectRoot, 'diff', '--name-only', '--diff-filter=AM', baseRef], { encoding: 'utf8', windowsHide: true });
|
|
69
|
-
const tracked = trackedRaw
|
|
70
|
-
.split(/\r?\n/)
|
|
71
|
-
.map((line) => line.trim())
|
|
72
|
-
.filter(Boolean);
|
|
73
|
-
const untrackedRaw = execFileSync('git', ['-C', projectRoot, 'ls-files', '--others', '--exclude-standard'], { encoding: 'utf8', windowsHide: true });
|
|
74
|
-
const untracked = untrackedRaw
|
|
75
|
-
.split(/\r?\n/)
|
|
76
|
-
.map((line) => line.trim())
|
|
77
|
-
.filter(Boolean);
|
|
78
|
-
return Array.from(new Set([...tracked, ...untracked]));
|
|
75
|
+
return statSync(absolute).isFile() ? 'present' : 'not-a-file';
|
|
79
76
|
}
|
|
80
77
|
catch {
|
|
81
|
-
return
|
|
78
|
+
return 'deleted';
|
|
82
79
|
}
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
/**
|
|
82
|
+
* A file over its cap is a violation only when THIS change enlarged it. One
|
|
83
|
+
* already that large at `baseRef` — or larger — is the accepted quantity the
|
|
84
|
+
* whole-tree `fileSizeOverCap` row counts, so touching it passes; growth past
|
|
85
|
+
* the cap, or creation over it, is refused. `baselinePath` is the path the size
|
|
86
|
+
* is read from: the file itself, or its pre-rename name when it moved.
|
|
87
|
+
*/
|
|
88
|
+
function overCapVerdict(projectRoot, baseRef, baselinePath, lines) {
|
|
89
|
+
const previousLines = readBaseLineCount(projectRoot, baseRef, baselinePath);
|
|
90
|
+
if (previousLines !== null && lines <= previousLines)
|
|
91
|
+
return { regressed: false };
|
|
92
|
+
return { regressed: true, previousLines };
|
|
86
93
|
}
|
|
87
94
|
/**
|
|
88
95
|
* The number a changed file is measured against, or `null` when the policy has no
|
|
@@ -104,43 +111,48 @@ function policyCapFor(file, override) {
|
|
|
104
111
|
return override;
|
|
105
112
|
return isPolicyMeasuredFile(file) ? fileSizeCapFor(file) : null;
|
|
106
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* The diff-scoped scan, judged as a RATCHET: a changed file is a violation only
|
|
116
|
+
* when THIS change enlarged it — it grew past its cap, or was created over it.
|
|
117
|
+
* A file that is over its cap but no larger than its own state at `baseRef`
|
|
118
|
+
* passes, because the baseline already carries it as an accepted over-cap
|
|
119
|
+
* quantity (`ceilings.fileSizeOverCap`) and `request transition rd →
|
|
120
|
+
* implemented` refusing to touch any of those files is the contradiction that
|
|
121
|
+
* blocked two consecutive slices. A rename is judged against the size the file
|
|
122
|
+
* had before it moved, so moving a file is not itself growth.
|
|
123
|
+
*
|
|
124
|
+
* THROWS `GitReadFailedError` when git cannot enumerate the changed files (an
|
|
125
|
+
* unresolvable `baseRef`, a non-repo path) — an empty list must mean "nothing
|
|
126
|
+
* changed", never "the read failed". `readChangedFiles` owns that refusal.
|
|
127
|
+
*/
|
|
128
|
+
/** The change set: the caller's already-read one, or one enumeration. Kept out
|
|
129
|
+
* of `scanFileSize` so the `??` does not push the scan past its complexity cap. */
|
|
130
|
+
function changesFor(options, baseRef) {
|
|
131
|
+
return options.changedFiles ?? readChangedFiles(options.projectRoot, baseRef, options.files);
|
|
132
|
+
}
|
|
107
133
|
export function scanFileSize(options) {
|
|
108
134
|
const baseRef = options.baseRef ?? 'HEAD';
|
|
109
135
|
// `null` here means "the policy decides, per file" — the cap is a property of
|
|
110
136
|
// the path (300 raw lines; 500 under root `tests/`), not of the run.
|
|
111
137
|
const override = options.threshold ?? null;
|
|
112
|
-
const
|
|
138
|
+
const changed = changesFor(options, baseRef);
|
|
113
139
|
const violations = [];
|
|
114
140
|
const deletedFiles = [];
|
|
115
141
|
const exemptFiles = [];
|
|
142
|
+
const acceptedOverCapFiles = [];
|
|
116
143
|
const outOfScopeFiles = [];
|
|
117
144
|
let checkedFiles = 0;
|
|
118
|
-
for (const file of
|
|
145
|
+
for (const file of changed.paths) {
|
|
119
146
|
if (isSizeCapExempt(file)) {
|
|
120
147
|
exemptFiles.push(file);
|
|
121
148
|
continue;
|
|
122
149
|
}
|
|
123
150
|
const absolute = join(options.projectRoot, file);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// `peaks request transition rd → implemented` flow with
|
|
128
|
-
// `code: PREREQUISITES_MISSING`. Now we skip missing paths — a
|
|
129
|
-
// deleted file has no lines to count. Belt-and-braces: the
|
|
130
|
-
// `getChangedFiles` filter above already excludes `--diff-filter=D`,
|
|
131
|
-
// but a manually-passed `baseRef` (tests) or a path that was
|
|
132
|
-
// untracked-then-deleted still flows through here, so the
|
|
133
|
-
// existsSync guard stays as a second line of defense.
|
|
134
|
-
if (!existsSync(absolute)) {
|
|
135
|
-
try {
|
|
136
|
-
const st = statSync(absolute);
|
|
137
|
-
if (!st.isFile())
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
catch {
|
|
151
|
+
const pathVerdict = classifyPath(absolute);
|
|
152
|
+
if (pathVerdict !== 'present') {
|
|
153
|
+
if (pathVerdict === 'deleted')
|
|
141
154
|
deletedFiles.push(file);
|
|
142
|
-
|
|
143
|
-
}
|
|
155
|
+
continue;
|
|
144
156
|
}
|
|
145
157
|
// The cap is decided BEFORE the file is counted, because for a path outside the
|
|
146
158
|
// policy there is no cap to decide: it is reported in `outOfScopeFiles` instead
|
|
@@ -154,7 +166,15 @@ export function scanFileSize(options) {
|
|
|
154
166
|
checkedFiles += 1;
|
|
155
167
|
const lines = countLines(absolute);
|
|
156
168
|
if (lines > cap) {
|
|
157
|
-
|
|
169
|
+
// A renamed file is measured against the size it had BEFORE the move.
|
|
170
|
+
const baselinePath = changed.baselinePathFor(file);
|
|
171
|
+
const verdict = overCapVerdict(options.projectRoot, baseRef, baselinePath, lines);
|
|
172
|
+
if (verdict.regressed) {
|
|
173
|
+
violations.push({ file, lines, cap, previousLines: verdict.previousLines });
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
acceptedOverCapFiles.push(file);
|
|
177
|
+
}
|
|
158
178
|
}
|
|
159
179
|
}
|
|
160
180
|
return {
|
|
@@ -163,6 +183,7 @@ export function scanFileSize(options) {
|
|
|
163
183
|
checkedFiles,
|
|
164
184
|
exemptFiles,
|
|
165
185
|
deletedFiles,
|
|
186
|
+
acceptedOverCapFiles,
|
|
166
187
|
outOfScopeFiles,
|
|
167
188
|
violations
|
|
168
189
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `corroborateDeclaredType` — the declared request type judged against what the
|
|
3
|
+
* change actually touches. A `docs | chore | config` rid selects a reduced
|
|
4
|
+
* prerequisite table, so it may not carry product source.
|
|
5
|
+
*
|
|
6
|
+
* Split out of `type-sanity-service.ts` when that file reached its 300-line cap.
|
|
7
|
+
* It reuses `tryGitDiffFiles` (the SAME enumeration `checkTypeSanity` reads), so
|
|
8
|
+
* the two rules cannot drift; unlike `checkTypeSanity`, it FAILS CLOSED when git
|
|
9
|
+
* cannot enumerate.
|
|
10
|
+
*/
|
|
11
|
+
import type { RequestType } from '../artifacts/artifact-prerequisites.js';
|
|
12
|
+
import { type TypeSanityOptions } from './type-sanity-service.js';
|
|
13
|
+
/** True when the path is product source by the repository's own boundary. */
|
|
14
|
+
export declare function isProductSourcePath(filePath: string): boolean;
|
|
15
|
+
/** True for the three types this rule judges (and bypasses are recorded for). */
|
|
16
|
+
export declare function isToolingOnlyDeclaredType(declaredType: RequestType): boolean;
|
|
17
|
+
export type TypeCorroboration = {
|
|
18
|
+
ok: true;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
kind: 'source-touched' | 'diff-unavailable';
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
export type TypeCorroborationOptions = TypeSanityOptions & {
|
|
25
|
+
/** A change set the caller already enumerated; skips the git read. */
|
|
26
|
+
changedPaths?: readonly string[];
|
|
27
|
+
};
|
|
28
|
+
/** The fail-closed verdict, shared with the transition gate's own read. */
|
|
29
|
+
export declare function diffUnavailableVerdict(declaredType: RequestType, baseRef?: string): Extract<TypeCorroboration, {
|
|
30
|
+
ok: false;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function corroborateDeclaredType(options: TypeCorroborationOptions): TypeCorroboration;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { normalizePath } from '../../shared/path-utils.js';
|
|
2
|
+
import { isArtifactWorkspaceFile, tryGitDiffFiles } from './type-sanity-service.js';
|
|
3
|
+
const TOOLING_ONLY_DECLARED_TYPES = new Set(['docs', 'chore', 'config']);
|
|
4
|
+
/** `src/**` + `packages/<name>/src/**` — the rule `.husky/lint-scope.mjs` owns.
|
|
5
|
+
* `tests/unit/lint/lint-scope-rule.test.ts` binds this copy to that module. */
|
|
6
|
+
const PACKAGE_SOURCE_RE = /^packages\/[^/]+\/src\//;
|
|
7
|
+
/** True when the path is product source by the repository's own boundary. */
|
|
8
|
+
export function isProductSourcePath(filePath) {
|
|
9
|
+
const normalized = normalizePath(filePath);
|
|
10
|
+
return normalized.startsWith('src/') || PACKAGE_SOURCE_RE.test(normalized);
|
|
11
|
+
}
|
|
12
|
+
/** True for the three types this rule judges (and bypasses are recorded for). */
|
|
13
|
+
export function isToolingOnlyDeclaredType(declaredType) {
|
|
14
|
+
return TOOLING_ONLY_DECLARED_TYPES.has(declaredType);
|
|
15
|
+
}
|
|
16
|
+
/** The fail-closed verdict, shared with the transition gate's own read. */
|
|
17
|
+
export function diffUnavailableVerdict(declaredType, baseRef = 'HEAD') {
|
|
18
|
+
return {
|
|
19
|
+
ok: false,
|
|
20
|
+
kind: 'diff-unavailable',
|
|
21
|
+
message: `Declared type '${declaredType}' could not be corroborated: git could not enumerate ` +
|
|
22
|
+
`the changed files against '${baseRef}' (not a repo, or the ref is unreadable). ` +
|
|
23
|
+
'This gate fails closed — an unreadable diff is not an empty diff.'
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function corroborateDeclaredType(options) {
|
|
27
|
+
if (!isToolingOnlyDeclaredType(options.declaredType))
|
|
28
|
+
return { ok: true };
|
|
29
|
+
const baseRef = options.baseRef ?? 'HEAD';
|
|
30
|
+
let files;
|
|
31
|
+
if (options.changedPaths !== undefined) {
|
|
32
|
+
files = options.changedPaths.filter((file) => !isArtifactWorkspaceFile(file));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const read = tryGitDiffFiles(options.projectRoot, baseRef);
|
|
36
|
+
if (!read.ok)
|
|
37
|
+
return diffUnavailableVerdict(options.declaredType, baseRef);
|
|
38
|
+
files = read.files;
|
|
39
|
+
}
|
|
40
|
+
const offendingPaths = files.filter(isProductSourcePath);
|
|
41
|
+
if (offendingPaths.length === 0)
|
|
42
|
+
return { ok: true };
|
|
43
|
+
return {
|
|
44
|
+
ok: false,
|
|
45
|
+
kind: 'source-touched',
|
|
46
|
+
message: `Declared type '${options.declaredType}' cannot change product source: ${offendingPaths.join(', ')}. ` +
|
|
47
|
+
'A docs/chore/config request selects a reduced prerequisite table, so it may not carry ' +
|
|
48
|
+
'src/** or packages/<name>/src/** changes. Declare feature, bugfix or refactor (which carry ' +
|
|
49
|
+
'the full QA evidence), or move the change out of product source.'
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -20,4 +20,18 @@ export type TypeSanityOptions = {
|
|
|
20
20
|
/** Compare working tree against this ref. Default 'HEAD' (covers staged + unstaged). */
|
|
21
21
|
baseRef?: string;
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Peaks' own artifact workspace. Changes here (PRD/RD/QA markdown, session
|
|
25
|
+
* state) are never the "code change" a request type describes, so they must be
|
|
26
|
+
* excluded from the diff — otherwise a PRD-planning-phase handoff that only
|
|
27
|
+
* wrote `.peaks/**` markdown would be misclassified as a docs change.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isArtifactWorkspaceFile(filePath: string): boolean;
|
|
30
|
+
/** The ONE git enumeration: tracked changes vs `baseRef` plus untracked files.
|
|
31
|
+
* `readGitChangeSet` is NUL-safe and `--relative`, so non-ASCII names and a
|
|
32
|
+
* nested project root are both read correctly. */
|
|
33
|
+
export declare function tryGitDiffFiles(projectRoot: string, baseRef: string): {
|
|
34
|
+
ok: boolean;
|
|
35
|
+
files: string[];
|
|
36
|
+
};
|
|
23
37
|
export declare function checkTypeSanity(options: TypeSanityOptions): TypeSanityReport;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process';
|
|
2
1
|
import { extname, basename } from 'node:path';
|
|
3
2
|
import { normalizePath } from '../../shared/path-utils.js';
|
|
3
|
+
import { readGitChangeSet } from './file-size-baseline.js';
|
|
4
4
|
const SOURCE_EXTENSIONS = new Set([
|
|
5
5
|
'.ts',
|
|
6
6
|
'.tsx',
|
|
@@ -75,6 +75,18 @@ const CONFIG_NAMES = new Set([
|
|
|
75
75
|
'nx.json'
|
|
76
76
|
]);
|
|
77
77
|
const CONFIG_EXTENSIONS = new Set(['.toml', '.ini', '.cfg', '.env']);
|
|
78
|
+
/**
|
|
79
|
+
* Directory conventions that make every file beneath them a test file. Anchored
|
|
80
|
+
* to WHOLE PATH SEGMENTS, never substrings: `src/services/test-cache/` is an
|
|
81
|
+
* ordinary source directory whose name merely begins with the word, and a
|
|
82
|
+
* word-boundary test cannot tell the two apart — `\b` is satisfied by `-`, so
|
|
83
|
+
* `\btest\b` fired inside `test-cache`. The five words are the five the
|
|
84
|
+
* substring test was reaching for, matched exactly; `cross-pass-edge-static-scan-support.ts`
|
|
85
|
+
* already anchors them the same way.
|
|
86
|
+
*/
|
|
87
|
+
const TEST_DIR_RE = /(^|[\\/])(?:test|tests|__tests__|__mocks__|spec)[\\/]/;
|
|
88
|
+
/** The filename convention — the file itself declares it is a test. */
|
|
89
|
+
const TEST_FILENAME_RE = /\.(test|spec)\.[a-z]+$/i;
|
|
78
90
|
function classifyFile(filePath) {
|
|
79
91
|
const name = basename(filePath);
|
|
80
92
|
const ext = extname(filePath).toLowerCase();
|
|
@@ -92,9 +104,7 @@ function classifyFile(filePath) {
|
|
|
92
104
|
return 'config';
|
|
93
105
|
if (DOCS_EXTENSIONS.has(ext))
|
|
94
106
|
return 'docs';
|
|
95
|
-
|
|
96
|
-
if (/\b(?:tests?|__tests__|__mocks__|spec)\b/.test(filePath) ||
|
|
97
|
-
/\.(test|spec)\.[a-z]+$/i.test(name))
|
|
107
|
+
if (TEST_DIR_RE.test(filePath) || TEST_FILENAME_RE.test(name))
|
|
98
108
|
return 'test';
|
|
99
109
|
if (SOURCE_EXTENSIONS.has(ext))
|
|
100
110
|
return 'source';
|
|
@@ -106,28 +116,19 @@ function classifyFile(filePath) {
|
|
|
106
116
|
* excluded from the diff — otherwise a PRD-planning-phase handoff that only
|
|
107
117
|
* wrote `.peaks/**` markdown would be misclassified as a docs change.
|
|
108
118
|
*/
|
|
109
|
-
function isArtifactWorkspaceFile(filePath) {
|
|
119
|
+
export function isArtifactWorkspaceFile(filePath) {
|
|
110
120
|
const normalized = normalizePath(filePath);
|
|
111
121
|
return normalized === '.peaks' || normalized.startsWith('.peaks/');
|
|
112
122
|
}
|
|
113
|
-
|
|
123
|
+
/** The ONE git enumeration: tracked changes vs `baseRef` plus untracked files.
|
|
124
|
+
* `readGitChangeSet` is NUL-safe and `--relative`, so non-ASCII names and a
|
|
125
|
+
* nested project root are both read correctly. */
|
|
126
|
+
export function tryGitDiffFiles(projectRoot, baseRef) {
|
|
114
127
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
const tracked = trackedRaw
|
|
121
|
-
.split(/\r?\n/)
|
|
122
|
-
.map((line) => line.trim())
|
|
123
|
-
.filter(Boolean);
|
|
124
|
-
const untrackedRaw = execFileSync('git', ['-C', projectRoot, 'ls-files', '--others', '--exclude-standard'], { encoding: 'utf8', windowsHide: true });
|
|
125
|
-
const untracked = untrackedRaw
|
|
126
|
-
.split(/\r?\n/)
|
|
127
|
-
.map((line) => line.trim())
|
|
128
|
-
.filter(Boolean);
|
|
129
|
-
const merged = Array.from(new Set([...tracked, ...untracked])).filter((file) => !isArtifactWorkspaceFile(file));
|
|
130
|
-
return { ok: true, files: merged };
|
|
128
|
+
return {
|
|
129
|
+
ok: true,
|
|
130
|
+
files: readGitChangeSet(projectRoot, baseRef).changedPaths.filter((file) => !isArtifactWorkspaceFile(file))
|
|
131
|
+
};
|
|
131
132
|
}
|
|
132
133
|
catch {
|
|
133
134
|
return { ok: false, files: [] };
|
|
@@ -6,6 +6,11 @@ export declare function dispatchRecordsDir(projectRoot: string, sid: string): st
|
|
|
6
6
|
* Assert that `recordPath` lives under `projectRoot/.peaks/_sub_agents/<sid>/`.
|
|
7
7
|
* Rejects symlink/junction escapes and `..` segments.
|
|
8
8
|
*
|
|
9
|
+
* `projectRoot` and `recordPath` may be two spellings of the same directory —
|
|
10
|
+
* macOS resolves `/var` (and `/tmp`) into `/private`, so `os.tmpdir()` and the
|
|
11
|
+
* kernel disagree — and that is accepted, not refused. See the comparison
|
|
12
|
+
* below.
|
|
13
|
+
*
|
|
9
14
|
* Throws an Error with `.code = 'INVALID_RECORD_PATH'` on rejection so
|
|
10
15
|
* the CLI can map to `{ok: false, code: "INVALID_RECORD_PATH"}`.
|
|
11
16
|
*/
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { realpathSync } from 'node:fs';
|
|
18
18
|
import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';
|
|
19
|
+
import { stablePath } from '../../shared/path-utils.js';
|
|
19
20
|
const SUB_AGENTS_DIR = '_sub_agents';
|
|
20
21
|
/** Build the canonical record path for a given session/rid/timestamp. */
|
|
21
22
|
export function dispatchRecordPath(projectRoot, sid, rid, ts = new Date()) {
|
|
@@ -33,6 +34,11 @@ export function dispatchRecordsDir(projectRoot, sid) {
|
|
|
33
34
|
* Assert that `recordPath` lives under `projectRoot/.peaks/_sub_agents/<sid>/`.
|
|
34
35
|
* Rejects symlink/junction escapes and `..` segments.
|
|
35
36
|
*
|
|
37
|
+
* `projectRoot` and `recordPath` may be two spellings of the same directory —
|
|
38
|
+
* macOS resolves `/var` (and `/tmp`) into `/private`, so `os.tmpdir()` and the
|
|
39
|
+
* kernel disagree — and that is accepted, not refused. See the comparison
|
|
40
|
+
* below.
|
|
41
|
+
*
|
|
36
42
|
* Throws an Error with `.code = 'INVALID_RECORD_PATH'` on rejection so
|
|
37
43
|
* the CLI can map to `{ok: false, code: "INVALID_RECORD_PATH"}`.
|
|
38
44
|
*/
|
|
@@ -48,8 +54,22 @@ export function assertSafeDispatchRecordPath(recordPath, projectRoot) {
|
|
|
48
54
|
if (rawSegments.includes('..')) {
|
|
49
55
|
throw invalidPathError(recordPath, 'must not contain .. segments');
|
|
50
56
|
}
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
// Compare the two on their CANONICAL spellings, not on the caller's, because
|
|
58
|
+
// they are routinely two spellings of ONE directory: macOS resolves `/var`
|
|
59
|
+
// into `/private/var` while `os.tmpdir()` hands out the unresolved form, and
|
|
60
|
+
// any caller can reach its project through a junction. Compared raw, the two
|
|
61
|
+
// share no leading segment, `relative()` walks to the project root and a
|
|
62
|
+
// legitimate record is refused as though it had escaped the ledger.
|
|
63
|
+
// `stablePath` is preferred here because it resolves the deepest EXISTING
|
|
64
|
+
// ancestor and re-appends the missing tail — the common case, since the
|
|
65
|
+
// record usually does not exist yet. It is NOT the primitive
|
|
66
|
+
// `projectRootCompareKey` is built from; that key uses `stableRealPath`,
|
|
67
|
+
// which does not walk up and adds separator and Windows-only case folding.
|
|
68
|
+
// They are siblings with different behaviour. Nor swap it for a bare
|
|
69
|
+
// `realpathSync`, whose `.native` variant also rewrites Windows 8.3 short
|
|
70
|
+
// names (see `projectRootCompareKey`'s doc-comment) and is not a drop-in.
|
|
71
|
+
const expected = resolve(canonicalSpelling(projectRoot), '.peaks', SUB_AGENTS_DIR);
|
|
72
|
+
const rel = relative(expected, canonicalSpelling(recordPath));
|
|
53
73
|
if (rel.startsWith('..') || isAbsolute(rel)) {
|
|
54
74
|
throw invalidPathError(recordPath, 'must be under .peaks/_sub_agents/');
|
|
55
75
|
}
|
|
@@ -71,12 +91,15 @@ export function assertSafeDispatchRecordPath(recordPath, projectRoot) {
|
|
|
71
91
|
// canonical projectRoot — the write will then create the file,
|
|
72
92
|
// and any symlink in the parent will be caught on the next read.
|
|
73
93
|
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
// the
|
|
79
|
-
//
|
|
94
|
+
// What this branch returns is the record path rebuilt under the CANONICAL
|
|
95
|
+
// projectRoot, so the caller writes, indexes and hands back a stable
|
|
96
|
+
// spelling. The alias tolerance that GETS here belongs to the canonical
|
|
97
|
+
// comparison above; this branch does NOT inherit it. `fallback` is built
|
|
98
|
+
// from the caller's `projectRoot`, and `recordPath` is compared here as the
|
|
99
|
+
// caller spelled it, so an aliased root beside a canonical record and a
|
|
100
|
+
// not-yet-created parent is still REFUSED by the comparison below — the
|
|
101
|
+
// same alias defect this change repairs, surviving in this one branch. It
|
|
102
|
+
// is fail-closed: it refuses a legitimate record; it never admits an escape.
|
|
80
103
|
const fallback = resolve(projectRoot, '.peaks', SUB_AGENTS_DIR);
|
|
81
104
|
const rel2 = relative(fallback, recordPath);
|
|
82
105
|
if (rel2.startsWith('..') || isAbsolute(rel2)) {
|
|
@@ -101,6 +124,39 @@ export function assertSafeDispatchRecordPath(recordPath, projectRoot) {
|
|
|
101
124
|
}
|
|
102
125
|
return realRecord;
|
|
103
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* `path` with its existing prefix symlink-resolved, or the raw spelling when
|
|
129
|
+
* the filesystem will not resolve it (a locked or vanishing ancestor).
|
|
130
|
+
*
|
|
131
|
+
* The fallback is what keeps this guard's contract intact: it promises to
|
|
132
|
+
* REJECT with `INVALID_RECORD_PATH`, and a raw `realpathSync` that threw here
|
|
133
|
+
* would surface as a crash on the dispatch write path instead. Its cost is
|
|
134
|
+
* stronger than a different refusal shape, though: the throw reverts the
|
|
135
|
+
* comparison to the pre-fix one, so on an aliased root the bug returns for that
|
|
136
|
+
* call — a legitimate record refused, not merely refused differently.
|
|
137
|
+
*
|
|
138
|
+
* The swallow is NOT fail-closed, which an earlier draft of this comment
|
|
139
|
+
* claimed. Measured in scratch copies of this guard: reverting the recordPath
|
|
140
|
+
* side of the comparison above to its raw spelling, ALONE, re-admits all three
|
|
141
|
+
* escape shapes that comparison closes — a `_sub_agents` junction pointing
|
|
142
|
+
* outside with the session dir missing, the in-repo sibling junction, and an
|
|
143
|
+
* existing leaf file-symlink pointing outside. Reverting both sides reproduces
|
|
144
|
+
* the pre-fix guard. A throw here therefore GROWS the admitted set rather than
|
|
145
|
+
* shrinking it. Nothing known makes `stablePath` throw on this input — a
|
|
146
|
+
* self-referential or deep junction, and every dangling link, make `existsSync`
|
|
147
|
+
* false so the peel loop runs instead — so the path is unverified, not cleared.
|
|
148
|
+
* The swallow stays anyway: refusing it trades this guard's refusal contract
|
|
149
|
+
* for a crash on the dispatch write path, and `stablePath` does not throw for a
|
|
150
|
+
* `projectRoot` that does not exist (verified by reading it).
|
|
151
|
+
*/
|
|
152
|
+
function canonicalSpelling(path) {
|
|
153
|
+
try {
|
|
154
|
+
return stablePath(path);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return path;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
104
160
|
function sanitizeSegment(segment, label) {
|
|
105
161
|
if (typeof segment !== 'string' || segment.length === 0) {
|
|
106
162
|
throw new Error(`Invalid ${label}: empty`);
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
33
33
|
import { join } from 'node:path';
|
|
34
|
+
import { requestIdFromFileName } from '../../shared/incrementing-number.js';
|
|
34
35
|
import { readArtifactState } from '../artifacts/request-artifact-state-helpers.js';
|
|
35
36
|
const MID_IMPL_RD_STATES = new Set([
|
|
36
37
|
'spec-locked',
|
|
@@ -192,15 +193,15 @@ function classifyTerminalGates(sessionDir, ctx) {
|
|
|
192
193
|
// RD qa-handoff → deepest gate is C. If the review artifacts are
|
|
193
194
|
// missing the state is inconsistent; fall back to rd-review-fanout.
|
|
194
195
|
if (ctx.primaryRd !== null && ctx.primaryRd.state === 'qa-handoff') {
|
|
195
|
-
// the pre-rid names behind it
|
|
196
|
-
// resolves
|
|
197
|
-
// never ran, not that it wrote to a name this reader does not know.
|
|
196
|
+
// the pre-rid names behind it, in the same order the transition gate
|
|
197
|
+
// resolves: an inconsistent-looking slice here means the fan-out never ran.
|
|
198
198
|
const rid = ridOf(ctx.primaryRd.filename);
|
|
199
199
|
const missing = [];
|
|
200
200
|
const codeReviewCandidates = [`rd/code-review-${rid}.md`, 'rd/code-review.md'];
|
|
201
201
|
const securityCandidates = [
|
|
202
202
|
`audit/security-${rid}.md`,
|
|
203
203
|
'audit/security.md',
|
|
204
|
+
`rd/security-review-${rid}.md`,
|
|
204
205
|
'rd/security-review.md'
|
|
205
206
|
];
|
|
206
207
|
if (!codeReviewCandidates.some((rel) => existsSync(join(sessionDir, rel)))) {
|
|
@@ -330,16 +331,15 @@ function extractState(content) {
|
|
|
330
331
|
return readArtifactState(content) ?? '';
|
|
331
332
|
}
|
|
332
333
|
/**
|
|
333
|
-
* The `<rid>`
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* itself date-shaped (`2026-09-14-<slug>`).
|
|
334
|
+
* The `<rid>` a request filename carries: the `.md` suffix and the `<NNN>-` prefix
|
|
335
|
+
* `request init` writes, both dropped by the reader that owns them — so this
|
|
336
|
+
* module cannot be left behind by a writer that moves the family. It used to spell
|
|
337
|
+
* its own `^0\d{2}-` here, which agreed with that reader only until the family was
|
|
338
|
+
* widened, and then reported a different id for the same file. A looser `^\d+-`
|
|
339
|
+
* would instead eat the leading year of every real rid, which is date-shaped.
|
|
340
340
|
*/
|
|
341
341
|
function ridOf(filename) {
|
|
342
|
-
return filename
|
|
342
|
+
return requestIdFromFileName(filename) ?? filename.replace(/\.md$/, '');
|
|
343
343
|
}
|
|
344
344
|
function hasAbandonedTransitionNote(content) {
|
|
345
345
|
return /user-requested-abandon/.test(content);
|
|
@@ -12,6 +12,7 @@ export declare const HOOK_ENFORCE_SENTINEL = "peaks gate enforce";
|
|
|
12
12
|
*/
|
|
13
13
|
interface ResolvedHookSpec {
|
|
14
14
|
readonly hookEnforceCommand: string;
|
|
15
|
+
readonly hookCodeGateCommand: string;
|
|
15
16
|
readonly hookEnforceSentinel: string;
|
|
16
17
|
readonly hookEnforceMatcher: string;
|
|
17
18
|
readonly hookEnforceEvent: string;
|
|
@@ -73,16 +74,14 @@ export type PeaksHookEntry = {
|
|
|
73
74
|
shell?: string;
|
|
74
75
|
};
|
|
75
76
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* encodes the same logic for non-Node harnesses.
|
|
77
|
+
* The code-gate entry's CLI adapter is `src/cli/commands/code-gate-command.ts`,
|
|
78
|
+
* its decision logic is `src/services/hooks/pre-tool-code-gate.ts`, and the
|
|
79
|
+
* shell-script sibling `src/services/hooks/pre-tool-code-gate.sh` encodes the
|
|
80
|
+
* same logic for non-Node harnesses.
|
|
81
81
|
*/
|
|
82
82
|
export declare const HOOK_CODE_GATE_SENTINEL = "peaks code-gate";
|
|
83
83
|
export declare const HOOK_CODE_GATE_MATCHER = "Edit|Write|MultiEdit";
|
|
84
84
|
export declare const HOOK_CODE_GATE_EVENT = "PreToolUse";
|
|
85
|
-
export declare const HOOK_CODE_GATE_COMMAND = "peaks code-gate --json";
|
|
86
85
|
export declare function resolveHookEntries(ide: IdeId, _skipProgress?: boolean): PeaksHookEntry[];
|
|
87
86
|
export declare function resolveLegacySentinels(ide: IdeId): ReadonlyArray<string>;
|
|
88
87
|
/**
|
|
@@ -85,6 +85,7 @@ export function resolveHookSpec(ide) {
|
|
|
85
85
|
const jsonFlag = isClaudeCode ? ' --json' : '';
|
|
86
86
|
return {
|
|
87
87
|
hookEnforceCommand: `${spec.command} --project "\${${adapter.envVar}}"${jsonFlag}`,
|
|
88
|
+
hookCodeGateCommand: `peaks code-gate --project "\${${adapter.envVar}}"${jsonFlag}`,
|
|
88
89
|
hookEnforceSentinel: spec.sentinel,
|
|
89
90
|
hookEnforceMatcher: adapter.toolMatcher,
|
|
90
91
|
hookEnforceEvent: adapter.hookEvent,
|
|
@@ -97,16 +98,14 @@ export function resolveHookSpec(ide) {
|
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* encodes the same logic for non-Node harnesses.
|
|
101
|
+
* The code-gate entry's CLI adapter is `src/cli/commands/code-gate-command.ts`,
|
|
102
|
+
* its decision logic is `src/services/hooks/pre-tool-code-gate.ts`, and the
|
|
103
|
+
* shell-script sibling `src/services/hooks/pre-tool-code-gate.sh` encodes the
|
|
104
|
+
* same logic for non-Node harnesses.
|
|
105
105
|
*/
|
|
106
106
|
export const HOOK_CODE_GATE_SENTINEL = 'peaks code-gate';
|
|
107
107
|
export const HOOK_CODE_GATE_MATCHER = 'Edit|Write|MultiEdit';
|
|
108
108
|
export const HOOK_CODE_GATE_EVENT = 'PreToolUse';
|
|
109
|
-
export const HOOK_CODE_GATE_COMMAND = `peaks code-gate --json`;
|
|
110
109
|
/**
|
|
111
110
|
* The read-only MCP surface as a hook entry: the same command under the
|
|
112
111
|
* adapter's MCP matcher, or `undefined` for a harness that declares no MCP
|
|
@@ -195,13 +194,13 @@ export function resolveHookEntries(ide, _skipProgress = false) {
|
|
|
195
194
|
event: HOOK_WORKSPACE_INIT_EVENT
|
|
196
195
|
});
|
|
197
196
|
// Edit|Write|MultiEdit matcher. Vendor-neutral command
|
|
198
|
-
// (`peaks code-gate
|
|
197
|
+
// (`peaks code-gate`); the CLI adapter lives in
|
|
199
198
|
// `src/cli/commands/code-gate-command.ts` and the underlying
|
|
200
199
|
// decision logic is in `src/services/hooks/pre-tool-code-gate.ts`.
|
|
201
200
|
entries.push({
|
|
202
201
|
sentinel: HOOK_CODE_GATE_SENTINEL,
|
|
203
202
|
matcher: HOOK_CODE_GATE_MATCHER,
|
|
204
|
-
command:
|
|
203
|
+
command: spec.hookCodeGateCommand,
|
|
205
204
|
event: HOOK_CODE_GATE_EVENT
|
|
206
205
|
});
|
|
207
206
|
// rid 2026-09-13-a2-post-compact-reinject: the post-compaction
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HookScope } from '../ide/shared/safe-path.js';
|
|
2
2
|
import { type PeaksHookEntry } from './hooks-codegate-superpowers.js';
|
|
3
|
-
export { HOOK_ENFORCE_SENTINEL, HOOK_CODE_GATE_SENTINEL, HOOK_CODE_GATE_MATCHER, HOOK_CODE_GATE_EVENT,
|
|
3
|
+
export { HOOK_ENFORCE_SENTINEL, HOOK_CODE_GATE_SENTINEL, HOOK_CODE_GATE_MATCHER, HOOK_CODE_GATE_EVENT, SUPERPOWERS_DENIED_SKILLS, type PeaksHookEntry } from './hooks-codegate-superpowers.js';
|
|
4
4
|
/**
|
|
5
5
|
* Install (and remove) the Peaks-managed hooks in an IDE's settings.json.
|
|
6
6
|
*
|
|
@@ -3,7 +3,7 @@ import { homedir } from 'node:os';
|
|
|
3
3
|
import { atomicWriteJson } from '../ide/shared/atomic-json.js';
|
|
4
4
|
import { getAdapter } from '../ide/ide-registry.js';
|
|
5
5
|
import { resolveHookSpec, resolveHookEntries, hasHookSpec, resolveLegacySentinels, hasExternalGateExemptions, withExternalGateExemptions } from './hooks-codegate-superpowers.js';
|
|
6
|
-
export { HOOK_ENFORCE_SENTINEL, HOOK_CODE_GATE_SENTINEL, HOOK_CODE_GATE_MATCHER, HOOK_CODE_GATE_EVENT,
|
|
6
|
+
export { HOOK_ENFORCE_SENTINEL, HOOK_CODE_GATE_SENTINEL, HOOK_CODE_GATE_MATCHER, HOOK_CODE_GATE_EVENT, SUPERPOWERS_DENIED_SKILLS } from './hooks-codegate-superpowers.js';
|
|
7
7
|
export { readInstalledEntriesFromSettings } from './hooks-settings-read-installed.js';
|
|
8
8
|
export { TRIGGER_PHRASES, listSuperpowersDenyEntries, withSuperpowersSkillDenylist, withTriggeredDenyList, withoutSuperpowersSkillDenylist, withoutTriggeredDenyList } from './hooks-settings-deny-list.js';
|
|
9
9
|
import { assertSafeSettingsPathCompat, resolveLocalSettingsPath, resolveSettingsRoot } from './hooks-settings-paths.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SkillPresenceLease } from './presence-lease-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Most recent lease first: `lastHeartbeat` desc, `startedAt` desc as the
|
|
4
|
+
* tie-break.
|
|
5
|
+
*
|
|
6
|
+
* The tie-break is not decorative. Nothing refreshes the on-disk heartbeat
|
|
7
|
+
* today — no caller runs `setPresenceLease` on a cadence — so `lastHeartbeat`
|
|
8
|
+
* frequently equals `startedAt`, and two leases written in the same millisecond
|
|
9
|
+
* tie on heartbeat alone. That tie then falls through to `Array.prototype.sort`
|
|
10
|
+
* stability, i.e. `readdirSync` order, which is the input this ordering exists
|
|
11
|
+
* to stop depending on.
|
|
12
|
+
*/
|
|
13
|
+
export declare function comparePresenceLeases(a: SkillPresenceLease, b: SkillPresenceLease): number;
|