architecture-harness 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -22
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +74 -5
- package/src/cli/budget-guard.test.mjs +185 -2
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +8 -5
- package/src/cli/check-commands.mjs +123 -11
- package/src/cli/check-commands.test.mjs +360 -6
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +137 -4
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +304 -0
- package/src/cli/ci-failures.test.mjs +615 -0
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +25 -29
- package/src/cli/ci-state.test.mjs +174 -2
- package/src/cli/ci-template.test.mjs +86 -0
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/codex-implement.mjs +580 -47
- package/src/cli/codex-implement.test.mjs +1946 -29
- package/src/cli/codex-limit.mjs +85 -0
- package/src/cli/codex-limit.test.mjs +179 -0
- package/src/cli/codex-reset.mjs +78 -0
- package/src/cli/codex-reset.test.mjs +192 -0
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +809 -0
- package/src/cli/context-budgets.mjs +47 -0
- package/src/cli/context-budgets.test.mjs +96 -0
- package/src/cli/context-watch.mjs +116 -0
- package/src/cli/context-watch.test.mjs +395 -0
- package/src/cli/contract-history.mjs +1 -1
- package/src/cli/controller-guard.mjs +38 -0
- package/src/cli/controller-guard.test.mjs +66 -2
- package/src/cli/cost-stop.mjs +5 -1
- package/src/cli/cost-stop.test.mjs +26 -0
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/direct-lane.mjs +32 -19
- package/src/cli/direct-lane.test.mjs +21 -3
- package/src/cli/dispatch-guard.mjs +11 -0
- package/src/cli/dispatch-guard.test.mjs +145 -10
- package/src/cli/dispatch-reminder.mjs +23 -10
- package/src/cli/dispatch-reminder.test.mjs +63 -11
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +96 -31
- package/src/cli/gh-merge-command.test.mjs +74 -0
- package/src/cli/gh-run.mjs +64 -3
- package/src/cli/gh-run.test.mjs +66 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +143 -40
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +62 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/lint-changed.mjs +59 -10
- package/src/cli/lint-changed.test.mjs +112 -1
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +234 -62
- package/src/cli/merge-guard.test.mjs +768 -39
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/pause.mjs +93 -0
- package/src/cli/pause.test.mjs +109 -0
- package/src/cli/plan-check.mjs +84 -12
- package/src/cli/plan-check.test.mjs +152 -2
- package/src/cli/plan-stop.mjs +7 -4
- package/src/cli/plan-stop.test.mjs +87 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +160 -27
- package/src/cli/qc.test.mjs +93 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/review-gate.mjs +24 -6
- package/src/cli/review-gate.test.mjs +116 -0
- package/src/cli/review-promotion.mjs +107 -0
- package/src/cli/review-promotion.test.mjs +251 -0
- package/src/cli/role-budget.mjs +50 -0
- package/src/cli/role-budget.test.mjs +91 -0
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/secret-patterns.mjs +16 -0
- package/src/cli/secret-patterns.test.mjs +73 -0
- package/src/cli/setup-block.mjs +24 -0
- package/src/cli/setup-block.test.mjs +96 -0
- package/src/cli/setup-checks.mjs +65 -0
- package/src/cli/setup-checks.test.mjs +158 -0
- package/src/cli/setup-compaction.mjs +55 -0
- package/src/cli/setup-compaction.test.mjs +115 -0
- package/src/cli/setup-skills.mjs +65 -0
- package/src/cli/setup-skills.test.mjs +171 -0
- package/src/cli/setup.mjs +107 -0
- package/src/cli/setup.test.mjs +275 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- package/src/cli/task-gate-review.test.mjs +21 -2
- package/src/cli/task-gate.mjs +25 -12
- package/src/cli/task-gate.test.mjs +43 -5
- package/src/cli/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/user-config-package.mjs +1 -1
- package/src/cli/user-config-toml.mjs +63 -7
- package/src/cli/user-config.mjs +39 -7
- package/src/cli/user-config.test.mjs +238 -5
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +80 -35
- package/src/cli/watch.test.mjs +233 -27
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +18 -4
- package/src/cli/workflow-settings.mjs +44 -8
- package/src/cli/workflow-settings.test.mjs +124 -1
- package/src/cli/worktree.mjs +14 -1
- package/src/cli/worktree.test.mjs +20 -1
- package/src/config.mjs +174 -7
- package/src/config.test.mjs +327 -5
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +54 -0
- package/src/descriptions.mjs +2 -0
- package/src/eslint/index.mjs +12 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +26 -2
- package/src/eslint/preset.test.mjs +104 -2
- package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
- package/src/eslint/rules/no-literal-color.mjs +94 -0
- package/src/eslint/rules/no-static-inline-style.mjs +41 -0
- package/src/eslint/rules/one-component-per-file.mjs +70 -0
- package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +189 -0
- package/src/eslint/ui-regressions.test.mjs +39 -0
- package/src/gates/contract-operations.mjs +3 -3
- package/src/gates/contract-operations.test.mjs +28 -0
- package/src/gates/feature-switches.mjs +19 -0
- package/src/gates/feature-switches.test.mjs +55 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/gates/runtime-imports.test.mjs +114 -0
- package/src/gates/saga-key.test.mjs +1 -1
- package/src/global-skills.mjs +9 -0
- package/src/global-skills.test.mjs +53 -0
- package/src/plugin.test.mjs +3 -2
- package/src/ui/class-sites.mjs +38 -6
- package/src/ui/codemod.mjs +4 -1
- package/src/ui/codemod.test.mjs +52 -0
- package/src/ui/components.mjs +5 -3
- package/src/ui/components.test.mjs +8 -0
- package/src/ui/dupes.test.mjs +18 -0
- package/templates/docs/enforcement.md +12 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +1 -0
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +57 -3
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +41 -1
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -84
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -127
- package/src/cli/throwaway-db.test.mjs +0 -83
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -175
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -40
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -137
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -78
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -106
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -40
- package/src/stack/supervisor.mjs +0 -30
package/src/cli/plan-check.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { reviewDefaults } from "../config.mjs";
|
|
7
|
+
import { pathMatcher } from "../glob.mjs";
|
|
7
8
|
import { reviewSettings } from "./workflow-settings.mjs";
|
|
8
9
|
|
|
9
10
|
const TASK_HEADING = /^###[ \t]+Task[ \t]+(\d+)[ \t]*:[ \t]*(.*)$/;
|
|
@@ -12,6 +13,7 @@ const FILE_LINE = /^[ \t]*[-*][ \t]+(?:Create|Modify|Test|Delete|Rename):[ \t]*\
|
|
|
12
13
|
const STEP_LINE = /^[ \t]*[-*][ \t]+\[[ xX]\][ \t]+\*\*(.+?)\*\*/;
|
|
13
14
|
const ESTIMATE_LINE = /^[ \t]*\*\*Estimate:\*\*[ \t]*(\d+)(?:[ \t]*(?:-|–|—|to)[ \t]*(\d+))?/i;
|
|
14
15
|
const FENCE = /^[ \t]*(`{3,}|~{3,})/;
|
|
16
|
+
const RISK_LINE = /^[ \t]*(?:[-*+][ \t]+)?\*\*Risk:\*\*[ \t]*\S/i;
|
|
15
17
|
const GIT_COMMIT = /\bgit[ \t]+commit\b/;
|
|
16
18
|
const TEST_WORD = /\btests?\b/i;
|
|
17
19
|
const COMMIT_WORD = /\bcommit\b/i;
|
|
@@ -26,8 +28,8 @@ const NO_TEST_SPELLING = "`Test: none — <reason>`";
|
|
|
26
28
|
|
|
27
29
|
const tidy = (word) => word.replace(/^[(["']+/, "").replace(/[)\]"',;.]+$/, "").replace(/:\d+(?:-\d+)?$/, "");
|
|
28
30
|
|
|
29
|
-
/**
|
|
30
|
-
function
|
|
31
|
+
/** The fragment that reads every path a Create, Modify, Test, Delete, or Rename line names. */
|
|
32
|
+
function filesOf(line) {
|
|
31
33
|
const rest = line.replace(/^[^:]*:/, "");
|
|
32
34
|
const found = [/^\s*`([^`\s]+)`/.exec(rest)?.[1]];
|
|
33
35
|
for (const [, span] of rest.matchAll(/`([^`\s]+)`/g)) found.push(span);
|
|
@@ -36,7 +38,7 @@ function sourceFilesOf(line) {
|
|
|
36
38
|
const paths = found.filter((word) => word).map(tidy).filter((word) => word !== "" && !NOT_A_PATH.test(word));
|
|
37
39
|
const first = found[0] ? tidy(found[0]) : null;
|
|
38
40
|
const isPath = (word) => word === first || named(word);
|
|
39
|
-
return [...new Set(paths.filter(isPath).
|
|
41
|
+
return [...new Set(paths.filter(isPath).map((word) => word.replace(/\\/g, "/")))];
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/** The tasks of a plan, with their file lines, step titles, commit evidence, and estimate. Fenced code is not structure. */
|
|
@@ -44,9 +46,11 @@ export function parsePlan(markdown) {
|
|
|
44
46
|
const tasks = [];
|
|
45
47
|
let task = null;
|
|
46
48
|
let fence = null;
|
|
49
|
+
let testStep = null;
|
|
47
50
|
markdown.split(/\r?\n/).forEach((line, index) => {
|
|
48
51
|
const marker = FENCE.exec(line)?.[1];
|
|
49
52
|
if (fence) {
|
|
53
|
+
if (task && testStep && !marker) testStep.push(line);
|
|
50
54
|
if (marker && marker[0] === fence[0] && marker.length >= fence.length && line.trim() === marker) fence = null;
|
|
51
55
|
else if (task && GIT_COMMIT.test(line)) task.commitCommand = true;
|
|
52
56
|
return;
|
|
@@ -57,15 +61,19 @@ export function parsePlan(markdown) {
|
|
|
57
61
|
}
|
|
58
62
|
const heading = TASK_HEADING.exec(line);
|
|
59
63
|
if (heading) {
|
|
64
|
+
testStep = null;
|
|
60
65
|
task = {
|
|
61
66
|
number: Number(heading[1]),
|
|
62
67
|
title: heading[2].trim(),
|
|
63
68
|
line: index + 1,
|
|
64
69
|
files: 0,
|
|
65
70
|
steps: [],
|
|
71
|
+
testSteps: [],
|
|
66
72
|
commitCommand: false,
|
|
67
73
|
estimate: null,
|
|
68
74
|
sourceFiles: [],
|
|
75
|
+
filePaths: [],
|
|
76
|
+
risk: false,
|
|
69
77
|
noTest: null,
|
|
70
78
|
};
|
|
71
79
|
tasks.push(task);
|
|
@@ -73,6 +81,7 @@ export function parsePlan(markdown) {
|
|
|
73
81
|
}
|
|
74
82
|
if (SECTION_END.test(line)) {
|
|
75
83
|
task = null;
|
|
84
|
+
testStep = null;
|
|
76
85
|
return;
|
|
77
86
|
}
|
|
78
87
|
if (!task) return;
|
|
@@ -82,10 +91,19 @@ export function parsePlan(markdown) {
|
|
|
82
91
|
task.noTest = { reason, words: reason === "" ? 0 : reason.split(/\s+/).length };
|
|
83
92
|
return;
|
|
84
93
|
}
|
|
85
|
-
if (PATH_LINE.test(line))
|
|
94
|
+
if (PATH_LINE.test(line)) {
|
|
95
|
+
const files = filesOf(line);
|
|
96
|
+
task.filePaths.push(...files);
|
|
97
|
+
task.sourceFiles.push(...files.filter((file) => !DOC_FILE.test(file.split("/").pop())));
|
|
98
|
+
}
|
|
99
|
+
if (RISK_LINE.test(line)) task.risk = true;
|
|
86
100
|
if (FILE_LINE.test(line)) task.files += 1;
|
|
87
101
|
const step = STEP_LINE.exec(line)?.[1];
|
|
88
|
-
if (step)
|
|
102
|
+
if (step) {
|
|
103
|
+
task.steps.push(step);
|
|
104
|
+
testStep = TEST_WORD.test(step) ? [line] : null;
|
|
105
|
+
if (testStep) task.testSteps.push(testStep);
|
|
106
|
+
} else if (testStep && !RISK_LINE.test(line)) testStep.push(line);
|
|
89
107
|
const estimate = ESTIMATE_LINE.exec(line);
|
|
90
108
|
if (estimate) task.estimate = Number(estimate[2] ?? estimate[1]);
|
|
91
109
|
});
|
|
@@ -93,12 +111,26 @@ export function parsePlan(markdown) {
|
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
/** @returns each way the plan breaks the format, one entry per task and problem. */
|
|
96
|
-
export function checkPlan(markdown, { maxTaskCalls = reviewDefaults.maxTaskCalls } = {}) {
|
|
114
|
+
export function checkPlan(markdown, { maxTaskCalls = reviewDefaults.maxTaskCalls, riskPaths = reviewDefaults.riskPaths, cases = reviewDefaults.cases } = {}) {
|
|
97
115
|
const tasks = parsePlan(markdown);
|
|
98
116
|
if (tasks.length === 0) return [{ task: null, detail: "the plan has no `### Task N:` heading" }];
|
|
99
117
|
const problems = [];
|
|
118
|
+
const risky = pathMatcher(riskPaths);
|
|
119
|
+
const caseRules = Object.entries(cases).map(([glob, words]) => ({
|
|
120
|
+
matches: pathMatcher([glob]),
|
|
121
|
+
words: words.map((word) => ({ word, pattern: new RegExp(`(?<!\\w)${word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?!\\w)`, "i") })),
|
|
122
|
+
}));
|
|
100
123
|
for (const task of tasks) {
|
|
101
124
|
const add = (detail) => problems.push({ task: task.number, detail });
|
|
125
|
+
if (task.filePaths.some(risky) && !task.risk) add("missing **Risk:** line: name the failure condition, how it shows, and how to reverse it");
|
|
126
|
+
const missing = new Set();
|
|
127
|
+
for (const rule of caseRules) {
|
|
128
|
+
if (!task.filePaths.some(rule.matches)) continue;
|
|
129
|
+
for (const { word, pattern } of rule.words) {
|
|
130
|
+
if (!task.testSteps.some((step) => pattern.test(step.join("\n")))) missing.add(word);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (missing.size) add(`missing cases in the test step: ${[...missing].join(", ")}`);
|
|
102
134
|
if (task.files === 0) add("names no file: list each as `- Create:`, `- Modify:` or `- Test:` with its path");
|
|
103
135
|
if (task.noTest) {
|
|
104
136
|
if (task.noTest.words < NO_TEST_WORDS) {
|
|
@@ -120,6 +152,48 @@ export function checkPlan(markdown, { maxTaskCalls = reviewDefaults.maxTaskCalls
|
|
|
120
152
|
return problems;
|
|
121
153
|
}
|
|
122
154
|
|
|
155
|
+
/** A branch that refuses open questions without their own source pointer. */
|
|
156
|
+
export function questionProblems(markdown) {
|
|
157
|
+
const questions = [];
|
|
158
|
+
let depth = null;
|
|
159
|
+
let question = "";
|
|
160
|
+
let fence = null;
|
|
161
|
+
const finish = () => { if (question.trim()) questions.push(question.trim()); question = ""; };
|
|
162
|
+
for (const line of markdown.split(/\r?\n/)) {
|
|
163
|
+
const marker = /^[ \t]*(`{3,}|~{3,})/.exec(line)?.[1];
|
|
164
|
+
if (fence) {
|
|
165
|
+
if (marker?.[0] === fence[0] && marker.length >= fence.length && line.trim() === marker) fence = null;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (marker) { fence = marker; continue; }
|
|
169
|
+
const heading = /^(#{1,6})[ \t]+(.+?)[ \t]*#*[ \t]*$/.exec(line);
|
|
170
|
+
if (heading && depth !== null && heading[1].length <= depth) { finish(); depth = null; }
|
|
171
|
+
if (heading && /^Open questions\b/i.test(heading[2])) { depth = heading[1].length; continue; }
|
|
172
|
+
if (depth === null) continue;
|
|
173
|
+
const listed = /^(?:[-*+]|\d+[.)])[ \t]+/.exec(line);
|
|
174
|
+
if (heading || line.trim() === "") { finish(); continue; }
|
|
175
|
+
if (!question && questions.length === 0 && line.trimEnd().endsWith(":")) continue;
|
|
176
|
+
const asks = line.includes("?");
|
|
177
|
+
const continues = question && /^(?:Source:|Recommendation:|Recommend\b)/.test(line);
|
|
178
|
+
const starts = listed || (!continues && !/^[ \t]/.test(line) && asks);
|
|
179
|
+
if (starts) finish();
|
|
180
|
+
if (starts || question) question += `${listed ? line.slice(listed[0].length) : line}\n`;
|
|
181
|
+
}
|
|
182
|
+
finish();
|
|
183
|
+
return questions.filter((entry) => !/^(?:[-*+]\s*)?(?:none|no open questions)[.!]?$/i.test(entry))
|
|
184
|
+
.filter((entry) => {
|
|
185
|
+
const source = /\bSource:\*{0,2}[ \t]*([^\n]+)/i.exec(entry)?.[1];
|
|
186
|
+
if (!source) return true;
|
|
187
|
+
if (/(?:^|[\s`(])(?:[A-Za-z]:[\\/])?[\w./\\-]*[./\\][\w./\\-]*:[1-9]\d*\b/.test(source)) return false;
|
|
188
|
+
return ![...source.matchAll(/https?:\/\/[^\s`<>)]+/g)].some(([url]) => {
|
|
189
|
+
try { return /[a-z0-9]/i.test(new URL(url).hostname); } catch { return false; }
|
|
190
|
+
});
|
|
191
|
+
}).map((entry) => {
|
|
192
|
+
const words = entry.split(/(?<=\?)\s|\n/)[0].trim().split(/\s+/).slice(0, 6).join(" ");
|
|
193
|
+
return `question ${JSON.stringify(words)} needs its own Source: with a file:line or URL`;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
123
197
|
/** `qc plan-check <plan.md>`. @returns the exit code */
|
|
124
198
|
export function runPlanCheck(config, [file] = []) {
|
|
125
199
|
if (!file) {
|
|
@@ -133,19 +207,17 @@ export function runPlanCheck(config, [file] = []) {
|
|
|
133
207
|
console.error(`FAIL plan-check ${file}: cannot read it (${error.message})`);
|
|
134
208
|
return 1;
|
|
135
209
|
}
|
|
136
|
-
let
|
|
210
|
+
let settings;
|
|
137
211
|
try {
|
|
138
|
-
|
|
212
|
+
settings = reviewSettings(config.swarm) ?? reviewSettings({ ...config.swarm, dispatch: {} });
|
|
139
213
|
} catch (error) {
|
|
140
214
|
console.error(error.message);
|
|
141
215
|
return 1;
|
|
142
216
|
}
|
|
143
|
-
const problems = checkPlan(markdown, {
|
|
144
|
-
for (const problem of problems) {
|
|
217
|
+
const problems = [...checkPlan(markdown, settings), ...questionProblems(markdown).map((detail) => ({ task: null, detail }))];
|
|
218
|
+
for (const problem of problems.slice(0, 3)) {
|
|
145
219
|
console.error(`FAIL plan-check ${problem.task === null ? file : `Task ${problem.task}`}: ${problem.detail}`);
|
|
146
220
|
}
|
|
147
221
|
if (problems.length > 0) return 1;
|
|
148
|
-
const count = parsePlan(markdown).length;
|
|
149
|
-
console.log(`OK plan-check ${file}: ${count} task${count === 1 ? "" : "s"}`);
|
|
150
222
|
return 0;
|
|
151
223
|
}
|
|
@@ -5,9 +5,38 @@ import os from "node:os";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { test } from "node:test";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
import { checkPlan, parsePlan } from "./plan-check.mjs";
|
|
8
|
+
import { checkPlan, parsePlan, questionProblems } from "./plan-check.mjs";
|
|
9
|
+
import { reviewDefaults } from "../config.mjs";
|
|
10
|
+
import { reviewSettings } from "./workflow-settings.mjs";
|
|
9
11
|
|
|
10
12
|
const QC = fileURLToPath(new URL("./qc.mjs", import.meta.url));
|
|
13
|
+
|
|
14
|
+
test("an unindented follow-up question needs its own source", () => {
|
|
15
|
+
assert.deepEqual(questionProblems("## Open questions\nWhich store?\nSource: storage.mjs:12. Recommend SQLite.\nWhich region?"), [
|
|
16
|
+
'question "Which region?" needs its own Source: with a file:line or URL',
|
|
17
|
+
]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("indented list items continue their question", () => {
|
|
21
|
+
assert.deepEqual(questionProblems("## Open questions\n- Which store?\n - Recommendation: SQLite.\n - Source: storage.mjs:12"), []);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("a colon ends an introduction even when it contains a question mark", () => {
|
|
25
|
+
assert.deepEqual(questionProblems("## Open questions\nAnswer these first (why?):\n- Which store? Source: storage.mjs:12"), []);
|
|
26
|
+
});
|
|
27
|
+
test("a colon after the first question starts a question after a blank line", () => {
|
|
28
|
+
assert.deepEqual(questionProblems("## Open questions\nWhich store? Source: storage.mjs:12\n\nWhich region? Options:\n - Europe\n - Asia"), [
|
|
29
|
+
'question "Which region?" needs its own Source: with a file:line or URL',
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("unindented source and recommendation lines continue an open question with question marks", () => {
|
|
34
|
+
for (const continuation of ["Source: https://example.com/docs?region=eu", "Recommendation: Europe?", "Recommend Europe?"]) {
|
|
35
|
+
const source = continuation.startsWith("Source:") ? "" : "\nSource: regions.mjs:12";
|
|
36
|
+
assert.deepEqual(questionProblems(`## Open questions\nWhich region?\n${continuation}${source}`), []);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
11
40
|
const FENCE = "`".repeat(3);
|
|
12
41
|
|
|
13
42
|
const task = (n, { files = true, fileLines = null, exempt = null, testStep = true, commit = true, estimate = null, extra = [] } = {}) =>
|
|
@@ -66,7 +95,7 @@ test("qc plan-check exits 0 on a good plan and 1 on a bad one, reading the budge
|
|
|
66
95
|
writeFileSync(path.join(dir, "bad.md"), plan(task(1, { estimate: 20 })));
|
|
67
96
|
const good = spawnSync(process.execPath, [QC, "plan-check", "good.md"], { cwd: dir, encoding: "utf8" });
|
|
68
97
|
assert.equal(good.status, 0, good.stderr);
|
|
69
|
-
assert.
|
|
98
|
+
assert.equal(good.stdout, "");
|
|
70
99
|
const bad = spawnSync(process.execPath, [QC, "plan-check", "bad.md"], { cwd: dir, encoding: "utf8" });
|
|
71
100
|
assert.equal(bad.status, 1);
|
|
72
101
|
assert.match(bad.stderr, /FAIL {2}plan-check {2}Task 1: estimates 20 tool calls, over swarm\.review\.maxTaskCalls \(10\)/);
|
|
@@ -74,6 +103,127 @@ test("qc plan-check exits 0 on a good plan and 1 on a bad one, reading the budge
|
|
|
74
103
|
assert.equal(missing.status, 1);
|
|
75
104
|
});
|
|
76
105
|
|
|
106
|
+
test("risky paths require a non-empty Risk line on their own task", () => {
|
|
107
|
+
assert.deepEqual(reviewDefaults.riskPaths, ["**/migrations/**", "schemas/**"]);
|
|
108
|
+
for (const file of ["migrations/001.sql", "db/migrations/001.sql", "schemas/api.yaml", "schemas\\api.json"]) {
|
|
109
|
+
const risky = task(2, { fileLines: [`- Modify: \`${file}\``] });
|
|
110
|
+
const problems = checkPlan(plan(task(1, { extra: ["**Risk:** A write fails; logs show it; revert the migration."] }), risky));
|
|
111
|
+
assert.equal(problems.length, 1, file);
|
|
112
|
+
assert.equal(problems[0].task, 2);
|
|
113
|
+
assert.match(problems[0].detail, /missing.*\*\*Risk:\*\*/);
|
|
114
|
+
assert.deepEqual(checkPlan(plan(risky), { riskPaths: [] }), []);
|
|
115
|
+
assert.deepEqual(checkPlan(plan(risky.replace("**Files:**", "**Risk:** A write fails; logs show it; revert the migration.\n**Files:**"))), []);
|
|
116
|
+
for (const extra of [["**Risk:** "], [FENCE, "**Risk:** A write fails; logs show it; revert.", FENCE]]) {
|
|
117
|
+
assert.equal(checkPlan(plan(task(1, { fileLines: [`- Modify: \`${file}\``], extra }))).length, 1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
assert.deepEqual(checkPlan(plan(task(1))), []);
|
|
121
|
+
assert.equal(checkPlan(plan(task(1)), { riskPaths: ["src/**"] }).length, 1);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("a bulleted Risk line satisfies the task risk requirement", () => {
|
|
125
|
+
const risky = task(1, { fileLines: ["- Modify: `schemas/api.json`"], extra: ["- **Risk:** Writes fail; errors appear; revert the change."] });
|
|
126
|
+
assert.deepEqual(checkPlan(plan(risky)), []);
|
|
127
|
+
assert.equal(checkPlan(plan(risky.replace("Writes fail; errors appear; revert the change.", " "))).length, 1);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("the CLI caps five problems at three lines and checks open question sources", (t) => {
|
|
131
|
+
const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-plan-cap-")));
|
|
132
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
133
|
+
writeFileSync(path.join(dir, "qc.config.json"), "{}");
|
|
134
|
+
const badTask = (n) => task(n, { fileLines: ["- Modify: `schemas/api.json`"], commit: false });
|
|
135
|
+
const bad = plan(badTask(1), badTask(2)) + "\n## Open questions\n- Which store?\n";
|
|
136
|
+
assert.equal(checkPlan(bad).length, 4);
|
|
137
|
+
writeFileSync(path.join(dir, "plan.md"), bad);
|
|
138
|
+
const run = () => spawnSync(process.execPath, [QC, "plan-check", "plan.md"], { cwd: dir, encoding: "utf8" });
|
|
139
|
+
const capped = run();
|
|
140
|
+
assert.equal(capped.status, 1);
|
|
141
|
+
assert.equal(capped.stdout, "");
|
|
142
|
+
assert.equal(capped.stderr.trim().split(/\r?\n/).length, 3);
|
|
143
|
+
for (const source of ["", " Source: step:2", " Source: the user at 10:30"]) {
|
|
144
|
+
writeFileSync(path.join(dir, "plan.md"), plan(task(1)) + `\n## Open questions\nThe spec leaves a question open.\n- Which storage engine should this service use?${source}\n`);
|
|
145
|
+
const result = run();
|
|
146
|
+
assert.equal(result.status, 1);
|
|
147
|
+
assert.match(result.stderr, /"Which storage engine should this service".*Source:/);
|
|
148
|
+
}
|
|
149
|
+
for (const source of ["storage.mjs:12", "src/storage:12", "C:/repo/storage.mjs:12", "https://example.com/storage"]) {
|
|
150
|
+
writeFileSync(path.join(dir, "plan.md"), plan(task(1)) + `\n## Open questions\nThe spec leaves a question open.\n- Which store? Source: ${source}\n`);
|
|
151
|
+
const result = run();
|
|
152
|
+
assert.equal(result.status, 0, result.stderr);
|
|
153
|
+
assert.equal(result.stdout + result.stderr, "");
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("the CLI validates review settings with dispatch off and reports one line", (t) => {
|
|
158
|
+
const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-plan-config-")));
|
|
159
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
160
|
+
writeFileSync(path.join(dir, "plan.md"), plan(task(1)));
|
|
161
|
+
for (const review of [{ cases: { "src/**": "loading" } }, { riskPaths: "src/**" }, { maxTaskCalls: "many" }, { cases: null }]) {
|
|
162
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { review } }));
|
|
163
|
+
const result = spawnSync(process.execPath, [QC, "plan-check", "plan.md"], { cwd: dir, encoding: "utf8" });
|
|
164
|
+
assert.equal(result.status, 1);
|
|
165
|
+
assert.equal(result.stdout, "");
|
|
166
|
+
assert.equal(result.stderr.trim().split(/\r?\n/).length, 1, result.stderr);
|
|
167
|
+
assert.match(result.stderr, /swarm\.review\./);
|
|
168
|
+
assert.doesNotMatch(result.stderr, /TypeError| at /);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("review settings accept riskPaths and reject malformed glob lists", () => {
|
|
173
|
+
assert.deepEqual(reviewSettings({ dispatch: {}, review: { riskPaths: [] } }).riskPaths, []);
|
|
174
|
+
assert.deepEqual(reviewSettings({ dispatch: {} }).riskPaths, reviewDefaults.riskPaths);
|
|
175
|
+
for (const riskPaths of [null, false, "schemas/**", [1], [""]]) {
|
|
176
|
+
assert.throws(() => reviewSettings({ dispatch: {}, review: { riskPaths } }), /riskPaths/);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("configured acceptance cases match whole words anywhere in a task's test step", () => {
|
|
181
|
+
assert.deepEqual(reviewDefaults.cases, {});
|
|
182
|
+
const cases = { "src/**": ["loading", "error", "empty", "success"] };
|
|
183
|
+
const complete = task(1, { extra: ["Verify LOADING, Error, empty, and success."] });
|
|
184
|
+
assert.deepEqual(checkPlan(plan(complete), { cases }), []);
|
|
185
|
+
assert.deepEqual(checkPlan(plan(task(1, { extra: [FENCE + "js", "test('loading, error, empty, success', run)", FENCE] })), { cases }), []);
|
|
186
|
+
const missing = checkPlan(plan(task(2, { extra: ["Test unloading, errors, nonempty, and successful."] })), { cases });
|
|
187
|
+
assert.equal(missing.length, 1);
|
|
188
|
+
assert.equal(missing[0].task, 2);
|
|
189
|
+
assert.match(missing[0].detail, /missing.*test step.*loading, error, empty, success/);
|
|
190
|
+
assert.deepEqual(checkPlan(plan(task(1))), []);
|
|
191
|
+
assert.deepEqual(checkPlan(plan(task(1)), { cases: { "ui/**": ["loading"] } }), []);
|
|
192
|
+
const outside = task(1).replace("**Files:**", "loading error empty success\n**Files:**") + "- [ ] **Commit: loading error empty success**\n";
|
|
193
|
+
assert.equal(checkPlan(plan(outside), { cases }).length, 1);
|
|
194
|
+
assert.equal(checkPlan(plan(complete, task(2)), { cases }).length, 1, "cases stay within their task");
|
|
195
|
+
const overlap = { "src/**": ["loading"], "**/*.mjs": ["error"] };
|
|
196
|
+
assert.match(checkPlan(plan(task(1, { extra: ["loading"] })), { cases: overlap })[0].detail, /error/);
|
|
197
|
+
assert.deepEqual(checkPlan(plan(task(1, { extra: ["Test c++ and a.b"] })), { cases: { "src/**": ["c++", "a.b"] } }), []);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("review settings accept case maps and reject malformed case lists", () => {
|
|
201
|
+
const cases = { "ui/**": ["loading", "error", "empty", "success"] };
|
|
202
|
+
assert.deepEqual(reviewSettings({ dispatch: {}, review: { cases } }).cases, cases);
|
|
203
|
+
assert.deepEqual(reviewSettings({ dispatch: {} }).cases, {});
|
|
204
|
+
for (const cases of [null, [], false, "ui/**", { "": ["error"] }, { "ui/**": "error" }, { "ui/**": [1] }, { "ui/**": [""] }]) {
|
|
205
|
+
assert.throws(() => reviewSettings({ dispatch: {}, review: { cases } }), /cases/);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("the CLI reads risk and case configuration and bounds refusals", (t) => {
|
|
210
|
+
const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-plan-safety-")));
|
|
211
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
212
|
+
const review = { riskPaths: ["src/**"], cases: { "src/**": ["loading", "error"] } };
|
|
213
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, review } }));
|
|
214
|
+
writeFileSync(path.join(dir, "plan.md"), plan(task(4)));
|
|
215
|
+
const bad = spawnSync(process.execPath, [QC, "plan-check", "plan.md"], { cwd: dir, encoding: "utf8" });
|
|
216
|
+
assert.equal(bad.status, 1);
|
|
217
|
+
assert.equal(bad.stdout, "");
|
|
218
|
+
assert.match(bad.stderr, /Task 4: missing \*\*Risk:\*\*/);
|
|
219
|
+
assert.match(bad.stderr, /Task 4: missing.*test step.*loading, error/);
|
|
220
|
+
assert.ok(bad.stderr.trim().split("\n").length <= 3);
|
|
221
|
+
writeFileSync(path.join(dir, "plan.md"), plan(task(4, { extra: ["Check loading and error.", "**Risk:** Writes fail; errors appear; revert the change."] })));
|
|
222
|
+
const good = spawnSync(process.execPath, [QC, "plan-check", "plan.md"], { cwd: dir, encoding: "utf8" });
|
|
223
|
+
assert.equal(good.status, 0, good.stderr);
|
|
224
|
+
assert.equal(good.stdout + good.stderr, "");
|
|
225
|
+
});
|
|
226
|
+
|
|
77
227
|
const DOC_FILES = ["- Modify: `README.md` (the table)", "- Modify: `packages/pkg/package.json` (`version` bump)", "- Modify: `CHANGELOG.md`"];
|
|
78
228
|
|
|
79
229
|
test("a task with no code may carry the Test: none line in place of a test step", () => {
|
package/src/cli/plan-stop.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import os from "node:os";
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { appendRecord } from "./ledger.mjs";
|
|
10
|
-
import { checkPlan } from "./plan-check.mjs";
|
|
10
|
+
import { checkPlan, questionProblems } from "./plan-check.mjs";
|
|
11
11
|
import { dropReport, keepReport, reportOf } from "./report-stash.mjs";
|
|
12
12
|
import { nativePath } from "./workflow-place.mjs";
|
|
13
13
|
import { workflowOf } from "./workflow-settings.mjs";
|
|
@@ -24,7 +24,7 @@ const block = (reason) => ({ decision: "block", reason });
|
|
|
24
24
|
export const planPathOf = (text) => PLAN_LINE.exec(String(text))?.[1]?.replace(QUOTES, "") ?? null;
|
|
25
25
|
|
|
26
26
|
/** @returns what the planner must fix before its report goes through; empty when the plan passes. */
|
|
27
|
-
export function planProblems(text, cwd, maxTaskCalls) {
|
|
27
|
+
export function planProblems(text, cwd, maxTaskCalls, { riskPaths, cases } = {}) {
|
|
28
28
|
const named = planPathOf(text);
|
|
29
29
|
if (!named) return ["a line that starts `PLAN:` with the plan's absolute path"];
|
|
30
30
|
const file = path.resolve(cwd, nativePath(named));
|
|
@@ -34,7 +34,10 @@ export function planProblems(text, cwd, maxTaskCalls) {
|
|
|
34
34
|
} catch {
|
|
35
35
|
return [`a plan at ${file}, which cannot be read`];
|
|
36
36
|
}
|
|
37
|
-
return
|
|
37
|
+
return [
|
|
38
|
+
...checkPlan(markdown, { maxTaskCalls, riskPaths, cases }).map((problem) => (problem.task === null ? problem.detail : `Task ${problem.task} ${problem.detail}`)),
|
|
39
|
+
...questionProblems(markdown),
|
|
40
|
+
].slice(0, 3);
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
const refusal = (problems) => `Plan check: fix these, then send the report again. ${problems.map((problem, i) => `${i + 1}) ${problem}.`).join(" ")}`;
|
|
@@ -67,7 +70,7 @@ export function decide(call, tmp = os.tmpdir()) {
|
|
|
67
70
|
}
|
|
68
71
|
const text = event === "PreToolUse" ? String(call.tool_input?.message ?? "") : reportOf(call, tmp);
|
|
69
72
|
const cwd = call.cwd ?? process.cwd();
|
|
70
|
-
const problems = planProblems(text, cwd, workflow.review.maxTaskCalls);
|
|
73
|
+
const problems = planProblems(text, cwd, workflow.review.maxTaskCalls, workflow.review);
|
|
71
74
|
if (problems.length > 0) {
|
|
72
75
|
if (event === "PreToolUse") return deny(refusal(problems));
|
|
73
76
|
return call.stop_hook_active === true ? held(problems) : block(refusal(problems));
|
|
@@ -93,10 +93,97 @@ test("a planner stop with no hand-back is judged on its last message", (t) => {
|
|
|
93
93
|
assert.equal(decide(stop(ws.on, `PLAN: ${path.join(ws.plans, "good.md")}`), ws.tmp), null);
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
+
test("open questions need their own Source with a file line or URL before hand-back and stop", (t) => {
|
|
97
|
+
const ws = workspace(t);
|
|
98
|
+
const file = path.join(ws.plans, "questions.md");
|
|
99
|
+
const message = `PLAN: ${file}`;
|
|
100
|
+
for (const question of [
|
|
101
|
+
"- Which store? Recommend SQLite.",
|
|
102
|
+
"- Which store? Source: storage.mjs. Recommend SQLite.",
|
|
103
|
+
"- Which store? Source: storage.mjs:0. Recommend SQLite.",
|
|
104
|
+
"- Which store? Source: https://. Recommend SQLite.",
|
|
105
|
+
"- Which store? Source: storage.mjs:12. Recommend SQLite.\n- Which region? Recommend EU.",
|
|
106
|
+
"Which store?\nSource: storage.mjs:12. Recommend SQLite.\n\nWhich region?",
|
|
107
|
+
"Which region? Recommend EU.",
|
|
108
|
+
"Which store?\nSource: storage.mjs:12. Recommend SQLite.\nWhich region?",
|
|
109
|
+
]) {
|
|
110
|
+
writeFileSync(file, `${GOOD}\n## Open questions\n${question}\n`);
|
|
111
|
+
assert.match(denied(decide(handback(ws.on, message), ws.tmp)) ?? "", /Source:/);
|
|
112
|
+
assert.match(decide(stop(ws.on, message), ws.tmp)?.reason ?? "", /Source:/);
|
|
113
|
+
assert.equal(existsSync(ws.ledger), false);
|
|
114
|
+
}
|
|
115
|
+
for (const question of [
|
|
116
|
+
"- Which store? Recommend SQLite. Source: `storage.mjs:12`.",
|
|
117
|
+
"1. Which store? Recommend SQLite. **Source:** https://example.com/storage",
|
|
118
|
+
"- Which store?\n Recommend SQLite.\n Source: C:/repo/storage.mjs:12",
|
|
119
|
+
"- Which store should hold the cache,\n given the expected load?\n Source: src/a.mjs:1",
|
|
120
|
+
"- Which store? Recommend SQLite.\n Does it need WAL?\n Source: src/a.mjs:1",
|
|
121
|
+
"- None.",
|
|
122
|
+
"- Which store?\n - Recommendation: SQLite.\n - Source: storage.mjs:12",
|
|
123
|
+
"Answer these first (why?):\n- Which store? Source: storage.mjs:12",
|
|
124
|
+
]) {
|
|
125
|
+
writeFileSync(file, `${GOOD}\n## Open questions\n${question}\n## Product decisions\n- Use SQLite.\n`);
|
|
126
|
+
assert.equal(decide(handback(ws.on, message), ws.tmp), null, question);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("question refusals quote six words and reject times and step numbers as sources", (t) => {
|
|
131
|
+
const ws = workspace(t);
|
|
132
|
+
const file = path.join(ws.plans, "questions.md");
|
|
133
|
+
for (const source of ["the user at 10:30", "step:2"]) {
|
|
134
|
+
writeFileSync(file, `${GOOD}\n## Open questions\n- Which storage engine should this service use? Source: ${source}\n`);
|
|
135
|
+
const reason = denied(decide(handback(ws.on, `PLAN: ${file}`), ws.tmp));
|
|
136
|
+
assert.match(reason ?? "", /"Which storage engine should this service"/);
|
|
137
|
+
assert.match(reason ?? "", /Source:/);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("open question introductions pass while bare questions still need a source", (t) => {
|
|
142
|
+
const ws = workspace(t);
|
|
143
|
+
const file = path.join(ws.plans, "questions.md");
|
|
144
|
+
const intro = "The spec leaves two questions open.";
|
|
145
|
+
writeFileSync(file, `${GOOD}\n## Open questions\n${intro}\n- Which store? Source: storage.mjs:12\n`);
|
|
146
|
+
assert.equal(decide(handback(ws.on, `PLAN: ${file}`), ws.tmp), null);
|
|
147
|
+
writeFileSync(file, `${GOOD}\n## Open questions\n${intro}\nWhich region should the storage service use?\n`);
|
|
148
|
+
assert.match(denied(decide(handback(ws.on, `PLAN: ${file}`), ws.tmp)) ?? "", /"Which region should the storage service"/);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("the hook caps five plan and question problems at three", (t) => {
|
|
152
|
+
const ws = workspace(t);
|
|
153
|
+
const file = path.join(ws.plans, "many.md");
|
|
154
|
+
const bad = GOOD.replace("a.mjs", "schemas/api.json").replace("- [ ] **Step 2: Commit**", "");
|
|
155
|
+
writeFileSync(file, `${bad}\n${bad.replace("Task 1:", "Task 2:")}\n## Open questions\n- Which store?\n`);
|
|
156
|
+
const message = `PLAN: ${file}`;
|
|
157
|
+
for (const reason of [denied(decide(handback(ws.on, message), ws.tmp)), decide(stop(ws.on, message), ws.tmp)?.reason]) {
|
|
158
|
+
assert.deepEqual(reason.match(/\d\)/g), ["1)", "2)", "3)"]);
|
|
159
|
+
assert.match(reason, /Task 1 missing \*\*Risk:\*\*/);
|
|
160
|
+
assert.match(reason, /Task 2 missing \*\*Risk:\*\*/);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
96
164
|
test("the planner definition asks for the PLAN: line and the estimate line", () => {
|
|
97
165
|
const text = readFileSync(PLANNER, "utf8");
|
|
98
166
|
assert.match(text, /`PLAN: <absolute path of the plan>`/);
|
|
99
167
|
assert.match(text, /`\*\*Estimate:\*\* <n> tool calls`/);
|
|
168
|
+
assert.match(text, /swarm\.review\.riskPaths/);
|
|
169
|
+
assert.match(text, /swarm\.review\.cases/);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("the planner hook forwards configured risk paths and acceptance cases", (t) => {
|
|
173
|
+
const ws = workspace(t);
|
|
174
|
+
const review = { riskPaths: ["*.mjs"], cases: { "*.mjs": ["loading", "error"] } };
|
|
175
|
+
writeFileSync(path.join(ws.on, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, review } }));
|
|
176
|
+
const file = path.join(ws.plans, "good.md");
|
|
177
|
+
const message = `PLAN: ${file}`;
|
|
178
|
+
const reason = denied(decide(handback(ws.on, message), ws.tmp));
|
|
179
|
+
assert.match(reason ?? "", /Task 1 missing \*\*Risk:\*\*/);
|
|
180
|
+
assert.match(reason ?? "", /Task 1 missing cases.*loading, error/);
|
|
181
|
+
assert.equal(decide(stop(ws.on, message), ws.tmp)?.decision, "block");
|
|
182
|
+
writeFileSync(file, GOOD.replace("**Estimate:**", "**Risk:** Writes fail; errors appear; revert the change.\n**Estimate:**").replace("failing test", "loading and error test"));
|
|
183
|
+
assert.equal(decide(handback(ws.on, message), ws.tmp), null);
|
|
184
|
+
writeFileSync(path.join(ws.on, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, review: { riskPaths: [] } } }));
|
|
185
|
+
writeFileSync(file, GOOD.replace("a.mjs", "schemas/api.json"));
|
|
186
|
+
assert.equal(decide(handback(ws.on, message), ws.tmp), null);
|
|
100
187
|
});
|
|
101
188
|
|
|
102
189
|
test("the hook process is silent in a checkout without the checks", (t) => {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// A branch scans added lines and file metadata for platform risks.
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
const CODE_FILE = /\.(?:[cm]?[jt]sx?|sh|bash|zsh|ps1|psm1|bat|cmd|py|go|rs|java|cs|[ch]|[ch]pp|rb|php|swift|kt|kts|scala|sql|tf|hcl|lua|ex|exs|vue|svelte|css|scss)$|(?:^|\/)(?:Dockerfile|Makefile)$/i;
|
|
5
|
+
|
|
6
|
+
const patterns = [
|
|
7
|
+
["fixed port", /\b(?:listen|connect)\s*\(\s*[1-9]\d{0,4}\b|\bport\s*[:=]\s*[1-9]\d{0,4}\b|https?:\/\/[^\s'"`]+:[1-9]\d{0,4}\b/i],
|
|
8
|
+
["hard-coded path separator", /["'`][^"'`\n]*(?:\/|\\\\)[^"'`\n]*["'`]/],
|
|
9
|
+
["CRLF", /\\r\\n|\r$/],
|
|
10
|
+
["EPERM", /\bEPERM\b/],
|
|
11
|
+
["process.platform", /\bprocess\s*\.\s*platform\b/],
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export function riskHits(diff) {
|
|
15
|
+
const hits = [];
|
|
16
|
+
let file = "";
|
|
17
|
+
let line = 1;
|
|
18
|
+
let renamedFrom = "";
|
|
19
|
+
const add = (reason) => { if (CODE_FILE.test(file)) hits.push({ file, line, reason }); };
|
|
20
|
+
for (const text of diff.split("\n")) {
|
|
21
|
+
if (text.startsWith("diff --git ")) {
|
|
22
|
+
file = text.slice(text.lastIndexOf(" b/") + 3);
|
|
23
|
+
line = 1;
|
|
24
|
+
renamedFrom = "";
|
|
25
|
+
} else if (text.startsWith("+++ b/")) file = text.slice(6);
|
|
26
|
+
else if (text.startsWith("rename from ")) renamedFrom = text.slice(12);
|
|
27
|
+
else if (text.startsWith("rename to ")) {
|
|
28
|
+
file = text.slice(10);
|
|
29
|
+
add("rename");
|
|
30
|
+
if (renamedFrom !== file && renamedFrom.toLowerCase() === file.toLowerCase()) add("path case change");
|
|
31
|
+
} else if (/^(?:new file mode|old mode|new mode) 120000$/.test(text)) add("symlink");
|
|
32
|
+
else if (text.startsWith("@@")) line = Number(/\+(\d+)/.exec(text)?.[1] ?? 1);
|
|
33
|
+
else if (text.startsWith("+") && !text.startsWith("+++")) {
|
|
34
|
+
if (CODE_FILE.test(file)) for (const [reason, pattern] of patterns) if (pattern.test(text.slice(1))) add(reason);
|
|
35
|
+
line += 1;
|
|
36
|
+
} else if (text.startsWith(" ")) line += 1;
|
|
37
|
+
}
|
|
38
|
+
return hits;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function platformRisk(root, base = "origin/main", head = "HEAD") {
|
|
42
|
+
const diff = execFileSync("git", ["-c", "core.quotePath=false", "diff", "--no-ext-diff", "--no-textconv", "--find-renames", "--unified=0", `${base}...${head}`, "--"], {
|
|
43
|
+
cwd: root, encoding: "utf8", maxBuffer: 64 * 1024 * 1024,
|
|
44
|
+
});
|
|
45
|
+
return riskHits(diff);
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { riskHits } from "./platform-risk.mjs";
|
|
4
|
+
|
|
5
|
+
for (const source of ['listen(3000)', 'listen(7)', 'const port = 8080', '"foo/bar"', '"foo\\\\bar"', '"/tmp"', 'split("/")', '"\\r\\n"', 'EPERM', 'process.platform']) {
|
|
6
|
+
test(`flags added platform risk: ${source}`, () => {
|
|
7
|
+
assert.equal(riskHits(`diff --git a/a.js b/a.js\n+++ b/a.js\n@@ -1 +7 @@\n+${source}\n`)[0].file, 'a.js');
|
|
8
|
+
assert.equal(riskHits(`+++ b/a.js\n@@ -1 +7 @@\n+${source}\n`)[0].line, 7);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
test('ignores removed lines and context', () => {
|
|
12
|
+
assert.deepEqual(riskHits('+++ b/a.js\n@@ -1,2 +1 @@\n-EPERM\n process.platform\n+const x = 1;\n'), []);
|
|
13
|
+
});
|
|
14
|
+
test('port zero requests a free port', () => {
|
|
15
|
+
assert.deepEqual(riskHits('+++ b/a.js\n@@ -0,0 +1 @@\n+server.listen(0);\n'), []);
|
|
16
|
+
});
|
|
17
|
+
test('uses new-file line numbers across multiple hunks and files', () => {
|
|
18
|
+
const hits = riskHits('+++ b/first.js\n@@ -1 +4 @@\n+EPERM\n@@ -10 +15 @@\n+process.platform\n+++ b/second.js\n@@ -0,0 +1 @@\n+listen(80)\n');
|
|
19
|
+
assert.deepEqual(hits.map(({ file, line }) => [file, line]), [['first.js', 4], ['first.js', 15], ['second.js', 1]]);
|
|
20
|
+
});
|
|
21
|
+
test('flags renames, path case changes, and symlinks', () => {
|
|
22
|
+
assert.ok(riskHits('diff --git a/Foo.js b/foo.js\nrename from Foo.js\nrename to foo.js\n').some((hit) => hit.reason === 'path case change'));
|
|
23
|
+
assert.ok(riskHits('diff --git a/a.js b/b.js\nrename from a.js\nrename to b.js\n').some((hit) => hit.reason === 'rename'));
|
|
24
|
+
assert.ok(riskHits('diff --git a/link.js b/link.js\nnew file mode 120000\n').some((hit) => hit.reason === 'symlink'));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('ignores prose content, renames, case changes, and symlinks', () => {
|
|
28
|
+
for (const extension of ['md', 'mdx', 'txt', 'rst', 'adoc', 'html', 'svg', 'json', 'yaml', 'yml']) {
|
|
29
|
+
assert.deepEqual(riskHits(`diff --git a/Guide.${extension} b/guide.${extension}\nrename from Guide.${extension}\nrename to guide.${extension}\nnew file mode 120000\n+++ b/guide.${extension}\n@@ -0,0 +1 @@\n+listen(3000); "foo/bar"; "\\r\\n"; EPERM; process.platform\n`), []);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('scans code files after a prose file', () => {
|
|
34
|
+
for (const extension of ['js', 'mjs', 'cjs', 'jsx', 'ts', 'mts', 'cts', 'tsx', 'sh', 'bash', 'ps1', 'py', 'go', 'rs', 'java', 'cs', 'c', 'cpp', 'rb', 'php']) {
|
|
35
|
+
const hits = riskHits(`+++ b/guide.md\n@@ -0,0 +1 @@\n+process.platform\n+++ b/code.${extension}\n@@ -0,0 +3 @@\n+EPERM\n`);
|
|
36
|
+
assert.deepEqual(hits, [{ file: `code.${extension}`, line: 3, reason: 'EPERM' }]);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { test } from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const SKILLS = fileURLToPath(new URL("../../../../skills/", import.meta.url));
|
|
8
|
+
const FIELDS = new Set([
|
|
9
|
+
"name", "description", "argument-hint", "disable-model-invocation", "user-invocable",
|
|
10
|
+
"allowed-tools", "model", "context", "agent", "hooks",
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
for (const folder of readdirSync(SKILLS, { withFileTypes: true }).filter((entry) => entry.isDirectory())) {
|
|
14
|
+
test(`${folder.name} has bounded skill metadata with a use clause and known fields`, () => {
|
|
15
|
+
const text = readFileSync(path.join(SKILLS, folder.name, "SKILL.md"), "utf8");
|
|
16
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
|
|
17
|
+
assert.ok(match, "skill has frontmatter");
|
|
18
|
+
const fields = Object.fromEntries([...match[1].matchAll(/^([\w-]+):\s*(.*)$/gm)]
|
|
19
|
+
.map(([, key, value]) => [key, value.trim().replace(/^(["'])(.*)\1$/, "$2")]));
|
|
20
|
+
assert.equal(fields.name, folder.name);
|
|
21
|
+
assert.ok(fields.description?.length <= 600, "description has at most 600 characters");
|
|
22
|
+
assert.match(fields.description, /\bUse (?:when|only)\b/);
|
|
23
|
+
for (const key of Object.keys(fields)) assert.ok(FIELDS.has(key), `unknown field: ${key}`);
|
|
24
|
+
});
|
|
25
|
+
}
|