@v11g/agents-rock 1.0.7 → 1.0.9
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/README.md +1 -1
- package/package.json +1 -1
- package/plugins/reasoning/.claude-plugin/plugin.json +1 -1
- package/plugins/reasoning/evals/format-handoff-folder/graders/folder-named.md +8 -0
- package/plugins/reasoning/evals/format-handoff-folder/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/format-handoff-folder/prompt.md +9 -0
- package/plugins/reasoning/evals/format-ids-and-supports/graders/ids-in-chat.md +8 -0
- package/plugins/reasoning/evals/format-ids-and-supports/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/format-ids-and-supports/graders/supports-resolve.md +11 -0
- package/plugins/reasoning/evals/format-ids-and-supports/prompt.md +8 -0
- package/plugins/reasoning/evals/format-root-candidate-status/graders/candidate-status.md +11 -0
- package/plugins/reasoning/evals/format-root-candidate-status/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/format-root-candidate-status/prompt.md +8 -0
- package/plugins/reasoning/evals/format-unsaved-continues/graders/analysis-completes.md +9 -0
- package/plugins/reasoning/evals/format-unsaved-continues/graders/not-saved-stated.md +9 -0
- package/plugins/reasoning/evals/format-unsaved-continues/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/format-unsaved-continues/prompt.md +8 -0
- package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/names-closest-available.md +5 -6
- package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/no-improvised-levels.md +4 -6
- package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/skill-fired.md +1 -1
- package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/states-unavailable.md +4 -5
- package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/systemic-design-fired.md +10 -0
- package/plugins/reasoning/evals/guardrail-unavailable-framework/prompt.md +2 -2
- package/plugins/reasoning/evals/ps-interview-first-question/graders/look-in-present.md +10 -0
- package/plugins/reasoning/evals/ps-interview-first-question/graders/no-fixed-exits.md +11 -0
- package/plugins/reasoning/evals/ps-interview-first-question/graders/options-from-input.md +15 -0
- package/plugins/reasoning/evals/ps-interview-first-question/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/ps-interview-first-question/graders/source-hint.md +11 -0
- package/plugins/reasoning/evals/ps-interview-first-question/graders/targets-gap.md +13 -0
- package/plugins/reasoning/evals/ps-interview-first-question/prompt.md +8 -0
- package/plugins/reasoning/evals/ps-interview-five-whys/graders/look-in-present.md +10 -0
- package/plugins/reasoning/evals/ps-interview-five-whys/graders/no-fixed-exits.md +11 -0
- package/plugins/reasoning/evals/ps-interview-five-whys/graders/options-from-input.md +11 -0
- package/plugins/reasoning/evals/ps-interview-five-whys/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/ps-interview-five-whys/graders/source-hint.md +11 -0
- package/plugins/reasoning/evals/ps-interview-five-whys/graders/targets-gap.md +15 -0
- package/plugins/reasoning/evals/ps-interview-five-whys/prompt.md +8 -0
- package/plugins/reasoning/evals/ps-router-handoff/graders/no-reselection.md +11 -0
- package/plugins/reasoning/evals/ps-router-handoff/graders/runs-rca.md +8 -0
- package/plugins/reasoning/evals/ps-router-handoff/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/ps-router-handoff/prompt.md +11 -0
- package/plugins/reasoning/evals/routing-adaptive-discriminator/graders/confidence-single-word.md +10 -0
- package/plugins/reasoning/evals/routing-ambiguous-feature-request/graders/confidence-single-word.md +10 -0
- package/plugins/reasoning/evals/routing-classify-only/graders/confidence-single-word.md +10 -0
- package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/confidence-single-word.md +10 -0
- package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/no-unavailability-claim.md +10 -0
- package/plugins/reasoning/evals/routing-complex-delivery-slowdown/graders/confidence-single-word.md +10 -0
- package/plugins/reasoning/evals/routing-simple-null-pointer/graders/confidence-single-word.md +10 -0
- package/plugins/reasoning/evals/routing-thin-input-provisional/graders/confidence-single-word.md +10 -0
- package/plugins/reasoning/evals/sd-default-selection/graders/dates-traced.md +15 -0
- package/plugins/reasoning/evals/sd-default-selection/graders/interventions-cite-entries.md +12 -0
- package/plugins/reasoning/evals/sd-default-selection/graders/owners-from-input.md +8 -0
- package/plugins/reasoning/evals/sd-default-selection/graders/plan-steps-complete.md +21 -0
- package/plugins/reasoning/evals/sd-default-selection/graders/selects-systemic-design.md +12 -0
- package/plugins/reasoning/evals/sd-default-selection/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/sd-default-selection/graders/systemic-design-fired.md +10 -0
- package/plugins/reasoning/evals/sd-default-selection/prompt.md +11 -0
- package/plugins/reasoning/evals/sd-named-framework-software/graders/names-no-skill.md +11 -0
- package/plugins/reasoning/evals/sd-named-framework-software/graders/no-systemic-block.md +10 -0
- package/plugins/reasoning/evals/sd-named-framework-software/graders/systemic-design-fired.md +10 -0
- package/plugins/reasoning/evals/sd-named-framework-software/prompt.md +8 -0
- package/plugins/reasoning/evals/sd-not-software/graders/no-systemic-block.md +10 -0
- package/plugins/reasoning/evals/sd-not-software/graders/says-out-of-scope.md +10 -0
- package/plugins/reasoning/evals/sd-not-software/prompt.md +8 -0
- package/plugins/reasoning/evals/sd-raw-input/graders/first-question-targets-model.md +11 -0
- package/plugins/reasoning/evals/sd-raw-input/graders/look-in-present.md +10 -0
- package/plugins/reasoning/evals/sd-raw-input/graders/model-gap-blocks-stop.md +14 -0
- package/plugins/reasoning/evals/sd-raw-input/graders/model-in-assumptions.md +13 -0
- package/plugins/reasoning/evals/sd-raw-input/graders/no-fixed-exits.md +11 -0
- package/plugins/reasoning/evals/sd-raw-input/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/sd-raw-input/graders/systemic-design-fired.md +10 -0
- package/plugins/reasoning/evals/sd-raw-input/prompt.md +8 -0
- package/plugins/reasoning/evals/sd-theory-of-change/graders/links-carry-assumptions.md +9 -0
- package/plugins/reasoning/evals/sd-theory-of-change/graders/no-dates.md +8 -0
- package/plugins/reasoning/evals/sd-theory-of-change/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/sd-theory-of-change/graders/systemic-design-fired.md +10 -0
- package/plugins/reasoning/evals/sd-theory-of-change/graders/toc-block.md +10 -0
- package/plugins/reasoning/evals/sd-theory-of-change/prompt.md +8 -0
- package/plugins/reasoning/evals/sd-three-horizons/graders/dates-are-assumptions.md +11 -0
- package/plugins/reasoning/evals/sd-three-horizons/graders/owners-are-roles.md +8 -0
- package/plugins/reasoning/evals/sd-three-horizons/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/sd-three-horizons/graders/systemic-design-fired.md +10 -0
- package/plugins/reasoning/evals/sd-three-horizons/graders/three-horizons-block.md +10 -0
- package/plugins/reasoning/evals/sd-three-horizons/prompt.md +9 -0
- package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/edges-carry-support-labels.md +2 -2
- package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/no-invented-delays.md +7 -4
- package/plugins/reasoning/evals/st-interview-first-question/graders/look-in-present.md +10 -0
- package/plugins/reasoning/evals/st-interview-first-question/graders/no-fixed-exits.md +11 -0
- package/plugins/reasoning/evals/st-interview-first-question/graders/options-from-input.md +11 -0
- package/plugins/reasoning/evals/st-interview-first-question/graders/skill-fired.md +7 -0
- package/plugins/reasoning/evals/st-interview-first-question/graders/source-hint.md +11 -0
- package/plugins/reasoning/evals/st-interview-first-question/graders/targets-gap.md +13 -0
- package/plugins/reasoning/evals/st-interview-first-question/prompt.md +8 -0
- package/plugins/reasoning/evals/st-selection-boundary/graders/one-block-only.md +9 -6
- package/plugins/reasoning/skills/problem-router/README.md +6 -0
- package/plugins/reasoning/skills/problem-router/SKILL.md +11 -11
- package/plugins/reasoning/skills/problem-router/references/contract.md +117 -16
- package/plugins/reasoning/skills/problem-solving/README.md +10 -0
- package/plugins/reasoning/skills/problem-solving/SKILL.md +15 -3
- package/plugins/reasoning/skills/problem-solving/references/contract.md +117 -16
- package/plugins/reasoning/skills/problem-solving/references/interview.md +68 -0
- package/plugins/reasoning/skills/systemic-design/README.md +45 -0
- package/plugins/reasoning/skills/systemic-design/SKILL.md +184 -0
- package/plugins/reasoning/skills/systemic-design/frameworks/systemic-design.md +39 -0
- package/plugins/reasoning/skills/systemic-design/frameworks/theory-of-change.md +34 -0
- package/plugins/reasoning/skills/systemic-design/frameworks/three-horizons.md +28 -0
- package/plugins/reasoning/skills/systemic-design/references/contract.md +205 -0
- package/plugins/reasoning/skills/systemic-design/references/interview.md +68 -0
- package/plugins/reasoning/skills/systems-thinking/README.md +13 -6
- package/plugins/reasoning/skills/systems-thinking/SKILL.md +18 -6
- package/plugins/reasoning/skills/systems-thinking/frameworks/causal-loop.md +5 -2
- package/plugins/reasoning/skills/systems-thinking/frameworks/leverage-points.md +16 -7
- package/plugins/reasoning/skills/systems-thinking/frameworks/system-map.md +4 -5
- package/plugins/reasoning/skills/systems-thinking/references/contract.md +117 -16
- package/plugins/reasoning/skills/systems-thinking/references/interview.md +68 -0
- package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
- package/plugins/solution-architect/skills/analyze-requirements/SKILL.md +3 -2
- package/plugins/solution-architect/skills/analyze-requirements/references/rewriting.md +108 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/drift.mjs +64 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/cdp.mjs +4 -1
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/drift.mjs +31 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/git-diff.mjs +27 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/quality-gate.mjs +16 -1
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/state.mjs +52 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/record.mjs +87 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/drift-cli.test.mjs +178 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/drift.test.mjs +76 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/git-diff.test.mjs +62 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/quality-gate.test.mjs +9 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/record-cli.test.mjs +136 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/rerun-safety.test.mjs +53 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/rewriting.test.mjs +80 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/state.test.mjs +123 -0
- package/plugins/solution-architect/skills/estimate/README.md +20 -15
- package/plugins/solution-architect/skills/estimate/SKILL.md +10 -6
- package/plugins/solution-architect/skills/estimate/assets/estimate-template-agentic.html +111 -138
- package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +361 -247
- package/plugins/solution-architect/skills/estimate/assets/scores-review-template.html +5 -4
- package/plugins/solution-architect/skills/estimate/evals/evals.json +7 -7
- package/plugins/solution-architect/skills/estimate/references/agentic-estimation.md +4 -2
- package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +38 -82
- package/plugins/solution-architect/skills/estimate/references/interview.md +56 -35
- package/plugins/solution-architect/skills/estimate/references/scoring-guide.md +40 -4
- package/plugins/solution-architect/skills/estimate/references/techniques.md +29 -21
- package/plugins/solution-architect/skills/estimate/references/writing.md +75 -43
- package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +37 -5
- package/plugins/solution-architect/skills/estimate/scripts/lib/context-schema.mjs +35 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/estimate-math.mjs +17 -75
- package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +5 -5
- package/plugins/solution-architect/skills/estimate/scripts/lib/pricing.mjs +78 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/project-price.mjs +96 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +67 -19
- package/plugins/solution-architect/skills/estimate/scripts/lib/roadmap.mjs +4 -5
- package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +48 -73
- package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +28 -13
- package/plugins/solution-architect/skills/estimate/scripts/lib/score-csv.mjs +2 -2
- package/plugins/solution-architect/skills/estimate/scripts/lib/score-html.mjs +1 -1
- package/plugins/solution-architect/skills/estimate/scripts/lib/scoring.mjs +2 -2
- package/plugins/solution-architect/skills/estimate/scripts/render.mjs +1 -1
- package/plugins/solution-architect/skills/estimate/scripts/score-review.mjs +1 -1
- package/plugins/solution-architect/skills/estimate/scripts/test/browser-agentic.test.mjs +143 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +209 -50
- package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +57 -32
- package/plugins/solution-architect/skills/estimate/scripts/test/e2e.test.mjs +52 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/estimate-math.test.mjs +25 -112
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-estimation-fail.md +0 -10
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-estimation-pass.md +0 -10
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-inputs.json +1 -7
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/booking-inputs.json +11 -10
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-fail.md +6 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-pass.md +17 -21
- package/plugins/solution-architect/skills/estimate/scripts/test/pricing.test.mjs +88 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/project-price.test.mjs +93 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +86 -24
- package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +185 -31
- package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +114 -61
- package/plugins/solution-architect/skills/estimate/scripts/test/score-review.test.mjs +34 -1
- package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +103 -9
- package/plugins/solution-architect/skills/estimate/scripts/test/xlsx-export.test.mjs +292 -71
- package/plugins/solution-architect/skills/new-lead/SKILL.md +4 -3
- package/plugins/solution-architect/skills/proposal/README.md +9 -7
- package/plugins/solution-architect/skills/proposal/SKILL.md +10 -7
- package/plugins/solution-architect/skills/proposal/evals/evals.json +29 -11
- package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-unpriced-harborline/ARCHITECTURE.md +65 -0
- package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-unpriced-harborline/brief.md +21 -0
- package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-unpriced-harborline/estimation-inputs.json +126 -0
- package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-unpriced-harborline/estimation.json +215 -0
- package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation-inputs.json +224 -34
- package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation.json +103 -114
- package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation.md +48 -22
- package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation-inputs.json +211 -33
- package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation.json +102 -117
- package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation.md +48 -25
- package/plugins/solution-architect/skills/proposal/references/interview.md +3 -6
- package/plugins/solution-architect/skills/proposal/references/review.md +5 -4
- package/plugins/solution-architect/skills/proposal/references/writing.md +33 -31
- package/plugins/solution-architect/skills/proposal/scripts/derive.mjs +1 -1
- package/plugins/solution-architect/skills/proposal/scripts/lib/checks-client.mjs +5 -22
- package/plugins/solution-architect/skills/proposal/scripts/lib/checks-doc.mjs +18 -8
- package/plugins/solution-architect/skills/proposal/scripts/lib/checks.mjs +6 -2
- package/plugins/solution-architect/skills/proposal/scripts/lib/figures.mjs +24 -33
- package/plugins/solution-architect/skills/proposal/scripts/lib/sections.mjs +1 -1
- package/plugins/solution-architect/skills/proposal/scripts/test/checks-client.test.mjs +50 -47
- package/plugins/solution-architect/skills/proposal/scripts/test/checks-doc.test.mjs +99 -40
- package/plugins/solution-architect/skills/proposal/scripts/test/docs.test.mjs +11 -5
- package/plugins/solution-architect/skills/proposal/scripts/test/e2e.test.mjs +1 -1
- package/plugins/solution-architect/skills/proposal/scripts/test/evals-fixtures.test.mjs +39 -0
- package/plugins/solution-architect/skills/proposal/scripts/test/figures.test.mjs +67 -54
- package/plugins/solution-architect/skills/proposal/scripts/test/fixtures/proposal-fail.md +6 -1
- package/plugins/solution-architect/skills/proposal/scripts/test/fixtures/proposal-pass.md +8 -12
- package/plugins/solution-architect/skills/proposal/scripts/test/render.test.mjs +1 -1
- package/plugins/solution-architect/skills/proposal/scripts/test/validate.test.mjs +3 -2
- package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/names-owning-skill.md +0 -9
- package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/states-systemic-design-unavailable.md +0 -15
- package/plugins/solution-architect/skills/estimate/scripts/lib/scenario-schema.mjs +0 -39
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync, renameSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
// Three rules, deliberately. Every extra normalisation rule is a way for a real
|
|
5
|
+
// edit to hash as unchanged, and that is the failure nobody sees.
|
|
6
|
+
export function normalise(text) {
|
|
7
|
+
const body = text.replace(/\r\n/g, '\n')
|
|
8
|
+
.split('\n')
|
|
9
|
+
.map((line) => line.replace(/[ \t]+$/, ''))
|
|
10
|
+
.join('\n')
|
|
11
|
+
.replace(/\n+$/, '');
|
|
12
|
+
return `${body}\n`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function hashText(text) {
|
|
16
|
+
return `sha256:${createHash('sha256').update(normalise(text)).digest('hex')}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Only ARCHITECTURE.md gets these — it is the only file with a spine to cut on.
|
|
20
|
+
export function sectionHashes(md) {
|
|
21
|
+
const out = {};
|
|
22
|
+
let key = null;
|
|
23
|
+
let buf = [];
|
|
24
|
+
const flush = () => { if (key) out[key] = hashText(buf.join('\n')); };
|
|
25
|
+
for (const line of md.split('\n')) {
|
|
26
|
+
const heading = line.match(/^##\s+(\d+)\s/);
|
|
27
|
+
if (heading) flush();
|
|
28
|
+
if (heading) { key = heading[1]; buf = []; }
|
|
29
|
+
if (key) buf.push(line);
|
|
30
|
+
}
|
|
31
|
+
flush();
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function readState(path) {
|
|
36
|
+
if (!existsSync(path)) return { state: null };
|
|
37
|
+
try {
|
|
38
|
+
return { state: JSON.parse(readFileSync(path, 'utf8')) };
|
|
39
|
+
} catch (err) {
|
|
40
|
+
// Never deleted: a corrupt state file is still the only record of what the
|
|
41
|
+
// last run wrote, and a person may be able to read it even if we cannot.
|
|
42
|
+
return { state: null, error: `unreadable (${err.message}) — treated as a first run` };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Temp then rename, so a crash mid-write leaves the previous revision in place.
|
|
47
|
+
// The caller writes this LAST, after every document is on disk.
|
|
48
|
+
export function writeState(path, state) {
|
|
49
|
+
const tmp = `${path}.tmp`;
|
|
50
|
+
writeFileSync(tmp, `${JSON.stringify(state, null, 2)}\n`);
|
|
51
|
+
renameSync(tmp, path);
|
|
52
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { hashText, sectionHashes, readState, writeState } from './lib/state.mjs';
|
|
5
|
+
import { docStatus } from './lib/drift.mjs';
|
|
6
|
+
import { parseFrontmatter } from './lib/frontmatter.mjs';
|
|
7
|
+
|
|
8
|
+
// Same shape as drift.mjs: the list-consuming loop is extracted so the parser
|
|
9
|
+
// stays inside the two-level nesting limit.
|
|
10
|
+
function consumeFiles(argv, i, files) {
|
|
11
|
+
while (argv[i + 1] && !argv[i + 1].startsWith('--')) files.push(argv[++i]);
|
|
12
|
+
return i;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function parseArgs(argv) {
|
|
16
|
+
const args = { files: [] };
|
|
17
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
18
|
+
const flag = argv[i];
|
|
19
|
+
if (flag === '--files') i = consumeFiles(argv, i, args.files);
|
|
20
|
+
else if (flag.startsWith('--')) args[flag.slice(2)] = argv[++i];
|
|
21
|
+
}
|
|
22
|
+
return args;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Null outside a repository: it is what tells the next run whether the git path
|
|
26
|
+
// is available at all.
|
|
27
|
+
function head(root) {
|
|
28
|
+
try {
|
|
29
|
+
const opts = { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] };
|
|
30
|
+
return execFileSync('git', ['rev-parse', 'HEAD'], opts).trim();
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Sections only for ARCHITECTURE.md — it is the only file with a spine to cut
|
|
37
|
+
// on. An ADR carries the status that exempts it from being rewritten instead.
|
|
38
|
+
function entryFor(root, file) {
|
|
39
|
+
const text = readFileSync(join(root, file), 'utf8');
|
|
40
|
+
const entry = { hash: hashText(text) };
|
|
41
|
+
if (file === 'ARCHITECTURE.md') entry.sections = sectionHashes(text);
|
|
42
|
+
const status = /(^|\/)docs\/adr\//.test(file) ? docStatus(text) : null;
|
|
43
|
+
if (status) entry.status = status;
|
|
44
|
+
return entry;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Taken from the package itself, so the record can never disagree with the
|
|
48
|
+
// document. --doc-version covers a run that did not rewrite ARCHITECTURE.md.
|
|
49
|
+
function docVersion(root, flag) {
|
|
50
|
+
const arch = join(root, 'ARCHITECTURE.md');
|
|
51
|
+
if (flag || !existsSync(arch)) return flag ?? null;
|
|
52
|
+
return parseFrontmatter(readFileSync(arch, 'utf8')).data?.docVersion ?? null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const args = parseArgs(process.argv.slice(2));
|
|
56
|
+
if (!args.state || !args.files.length) {
|
|
57
|
+
console.error('usage: record.mjs --state <architecture-state.json> --files <path> [<path> …] [--doc-version <v>]');
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const root = dirname(args.state);
|
|
62
|
+
const { state, error } = readState(args.state);
|
|
63
|
+
// Refuse rather than rename over it: a corrupt state file is still the only
|
|
64
|
+
// record of what the last run wrote, and writing would reset the revision and
|
|
65
|
+
// take those bytes with it. Moving it aside would be a second guess about what
|
|
66
|
+
// the person wants; they can rename it themselves.
|
|
67
|
+
if (error) {
|
|
68
|
+
console.error(`state file ${error.replace(' — treated as a first run', '')} — refusing to overwrite it`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
const revision = (state?.revision ?? 0) + 1;
|
|
72
|
+
const written = Object.fromEntries(args.files.map((f) => [f, entryFor(root, f)]));
|
|
73
|
+
|
|
74
|
+
// Run this LAST, once every document is on disk: temp file then rename, so a
|
|
75
|
+
// crash leaves the state pointing at the previous consistent revision. Earlier
|
|
76
|
+
// entries are kept — the record covers everything this skill has written, not
|
|
77
|
+
// only the files this run rewrote.
|
|
78
|
+
writeState(args.state, {
|
|
79
|
+
_generated: 'written by analyze-requirements — do not edit',
|
|
80
|
+
revision,
|
|
81
|
+
updated: new Date().toISOString(),
|
|
82
|
+
docVersion: docVersion(root, args['doc-version']),
|
|
83
|
+
gitCommit: head(root),
|
|
84
|
+
files: { ...state?.files, ...written },
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
console.log(`recorded revision ${revision} — ${args.files.length} file(s)`);
|
package/plugins/solution-architect/skills/analyze-requirements/scripts/test/drift-cli.test.mjs
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { spawnSync, execFileSync } from 'node:child_process';
|
|
4
|
+
import { mkdtempSync, writeFileSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { hashText, sectionHashes } from '../lib/state.mjs';
|
|
8
|
+
|
|
9
|
+
const CLI = 'plugins/solution-architect/skills/analyze-requirements/scripts/drift.mjs';
|
|
10
|
+
const ARCH = '## 1 Goals and Scope\n\na\n\n## 13 Quality Requirements and SLOs\n\nb\n';
|
|
11
|
+
|
|
12
|
+
// spawnSync never throws on a non-zero exit and always hands back both
|
|
13
|
+
// streams, so the usage test can assert on stderr instead of only inferring
|
|
14
|
+
// "some" failure from the exit code. stdio is explicit so the usage text is
|
|
15
|
+
// captured rather than leaking into the suite's own output.
|
|
16
|
+
function run(args) {
|
|
17
|
+
const { status, stdout, stderr } = spawnSync('node', [CLI, ...args], {
|
|
18
|
+
encoding: 'utf8',
|
|
19
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
20
|
+
});
|
|
21
|
+
return { code: status, stdout, stderr };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function packageDir(archText) {
|
|
25
|
+
const dir = mkdtempSync(join(tmpdir(), 'rerun-safety-cli-'));
|
|
26
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), archText);
|
|
27
|
+
writeFileSync(join(dir, 'architecture-state.json'), JSON.stringify({
|
|
28
|
+
revision: 1,
|
|
29
|
+
files: { 'ARCHITECTURE.md': { hash: hashText(ARCH), sections: sectionHashes(ARCH) } },
|
|
30
|
+
}));
|
|
31
|
+
return dir;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// `gitCommit` is HEAD as it stood when run 1 finished — before anyone committed
|
|
35
|
+
// what run 1 had just written. Diffing against it renders the whole generated
|
|
36
|
+
// package as additions, and the one line a person must judge is lost in it.
|
|
37
|
+
function committedPackage() {
|
|
38
|
+
const dir = packageDir(ARCH);
|
|
39
|
+
const git = (...args) => execFileSync('git', args, { cwd: dir, stdio: 'ignore' });
|
|
40
|
+
git('init', '-q');
|
|
41
|
+
git('config', 'user.email', 'test@example.com');
|
|
42
|
+
git('config', 'user.name', 'Test');
|
|
43
|
+
writeFileSync(join(dir, 'README.md'), 'seed\n');
|
|
44
|
+
git('add', 'README.md');
|
|
45
|
+
git('commit', '-qm', 'seed');
|
|
46
|
+
const head = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir, encoding: 'utf8' }).trim();
|
|
47
|
+
writeFileSync(join(dir, 'architecture-state.json'), JSON.stringify({
|
|
48
|
+
revision: 1,
|
|
49
|
+
gitCommit: head,
|
|
50
|
+
files: { 'ARCHITECTURE.md': { hash: hashText(ARCH), sections: sectionHashes(ARCH) } },
|
|
51
|
+
}));
|
|
52
|
+
git('add', 'ARCHITECTURE.md');
|
|
53
|
+
git('commit', '-qm', 'the generated package');
|
|
54
|
+
return dir;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
test('the diff shows the hand edit, not the whole generated package', () => {
|
|
58
|
+
const dir = committedPackage();
|
|
59
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), ARCH.replace('\nb\n', '\nedited by hand\n'));
|
|
60
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'ARCHITECTURE.md']);
|
|
61
|
+
assert.equal(code, 2);
|
|
62
|
+
assert.match(stdout, /^\s*\+edited by hand$/m);
|
|
63
|
+
assert.doesNotMatch(stdout, /^\s*\+## 1 Goals and Scope$/m);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// `git add` is not a decision about the document, and it must not change what
|
|
67
|
+
// the reader is shown: a staged edit compared against the index looks clean,
|
|
68
|
+
// and the whole regeneration comes back from the recorded commit instead.
|
|
69
|
+
test('a staged hand edit is shown as the edit, not the whole package', () => {
|
|
70
|
+
const dir = committedPackage();
|
|
71
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), ARCH.replace('\nb\n', '\nedited by hand\n'));
|
|
72
|
+
execFileSync('git', ['add', 'ARCHITECTURE.md'], { cwd: dir, stdio: 'ignore' });
|
|
73
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'ARCHITECTURE.md']);
|
|
74
|
+
assert.equal(code, 2);
|
|
75
|
+
assert.match(stdout, /^\s*\+edited by hand$/m);
|
|
76
|
+
assert.doesNotMatch(stdout, /^\s*\+## 1 Goals and Scope$/m);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// The spec's other git row: a repository whose package was never committed has
|
|
80
|
+
// no old bytes to show, so the section numbers are all the reader gets.
|
|
81
|
+
test('an uncommitted package falls back to section numbers', () => {
|
|
82
|
+
const dir = committedPackage();
|
|
83
|
+
execFileSync('git', ['rm', '-q', '--cached', 'ARCHITECTURE.md'], { cwd: dir, stdio: 'ignore' });
|
|
84
|
+
execFileSync('git', ['commit', '-qm', 'drop it'], { cwd: dir, stdio: 'ignore' });
|
|
85
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), ARCH.replace('\nb\n', '\nedited by hand\n'));
|
|
86
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'ARCHITECTURE.md']);
|
|
87
|
+
assert.equal(code, 2);
|
|
88
|
+
assert.match(stdout, /changed: §13/);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('an untouched package exits zero and says so', () => {
|
|
92
|
+
const dir = packageDir(ARCH);
|
|
93
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'ARCHITECTURE.md']);
|
|
94
|
+
assert.equal(code, 0);
|
|
95
|
+
assert.match(stdout, /ARCHITECTURE\.md\s+unchanged/);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// The exit code carries the signal: an agent that only checks it must still
|
|
99
|
+
// stop, because the whole point is that nothing is written before the question.
|
|
100
|
+
test('drift exits 2 and names the changed sections', () => {
|
|
101
|
+
const dir = packageDir(ARCH.replace('\nb\n', '\nedited by hand\n'));
|
|
102
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'ARCHITECTURE.md']);
|
|
103
|
+
assert.equal(code, 2);
|
|
104
|
+
assert.match(stdout, /ARCHITECTURE\.md\s+drifted/);
|
|
105
|
+
assert.match(stdout, /changed: §13/);
|
|
106
|
+
assert.doesNotMatch(stdout, /§1\b/);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('a file with no state entry is untracked and does not fail the run', () => {
|
|
110
|
+
const dir = packageDir(ARCH);
|
|
111
|
+
writeFileSync(join(dir, 'notes.md'), 'hand written\n');
|
|
112
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'notes.md']);
|
|
113
|
+
assert.equal(code, 0);
|
|
114
|
+
assert.match(stdout, /notes\.md\s+untracked/);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('a missing state file is a first run, not a failure', () => {
|
|
118
|
+
const dir = mkdtempSync(join(tmpdir(), 'rerun-safety-first-'));
|
|
119
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), ARCH);
|
|
120
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'ARCHITECTURE.md']);
|
|
121
|
+
assert.equal(code, 0);
|
|
122
|
+
assert.match(stdout, /first run/);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// A new ADR on run 2 has no entry and no file. It is not "not ours" — nobody
|
|
126
|
+
// has one — so the gate must not hand the agent a verdict that forbids it.
|
|
127
|
+
test('a file that does not exist yet is new, not untracked', () => {
|
|
128
|
+
const dir = packageDir(ARCH);
|
|
129
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'docs/adr/0002-new.md']);
|
|
130
|
+
assert.equal(code, 0);
|
|
131
|
+
assert.match(stdout, /0002-new\.md\s+new/);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// "nothing blocked" means the run is not halted, not that nothing is judged.
|
|
135
|
+
// Point the skill at a directory that already holds a hand-written package and
|
|
136
|
+
// every file in it must still come back untracked — that is the property that
|
|
137
|
+
// makes a first run against someone else's documents safe.
|
|
138
|
+
test('a first run still classifies the files it was given', () => {
|
|
139
|
+
const dir = mkdtempSync(join(tmpdir(), 'rerun-safety-first-'));
|
|
140
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), ARCH);
|
|
141
|
+
const { code, stdout } = run(['--state', join(dir, 'architecture-state.json'), '--files', 'ARCHITECTURE.md']);
|
|
142
|
+
assert.equal(code, 0);
|
|
143
|
+
assert.match(stdout, /ARCHITECTURE\.md\s+untracked/);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// The reassurance is false exactly when it prints: a state file exists, so
|
|
147
|
+
// tracked files are on disk, and its corruption is what stops us telling which
|
|
148
|
+
// of them moved. It is also the more actionable line, so it is the one acted on.
|
|
149
|
+
test('a corrupt state file warns without clearing anything', () => {
|
|
150
|
+
const dir = mkdtempSync(join(tmpdir(), 'rerun-safety-corrupt-'));
|
|
151
|
+
const statePath = join(dir, 'architecture-state.json');
|
|
152
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), ARCH);
|
|
153
|
+
writeFileSync(statePath, '{ not json');
|
|
154
|
+
const { code, stdout } = run(['--state', statePath, '--files', 'ARCHITECTURE.md']);
|
|
155
|
+
assert.equal(code, 0);
|
|
156
|
+
assert.match(stdout, /unreadable/);
|
|
157
|
+
assert.match(stdout, /nothing on disk can be verified/);
|
|
158
|
+
assert.doesNotMatch(stdout, /nothing is at risk/);
|
|
159
|
+
assert.equal(readFileSync(statePath, 'utf8'), '{ not json', 'never deleted');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('no --state is a usage error', () => {
|
|
163
|
+
const { code, stderr } = run(['--files', 'ARCHITECTURE.md']);
|
|
164
|
+
assert.equal(code, 1);
|
|
165
|
+
assert.match(stderr, /^usage:/m);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// A gate that a typo turns into a clean bill of health fails the wrong way: an
|
|
169
|
+
// empty write set prints nothing and exits 0, which reads as "all clear".
|
|
170
|
+
test('an empty file list is a usage error, not a clean bill of health', () => {
|
|
171
|
+
const dir = packageDir(ARCH);
|
|
172
|
+
const state = join(dir, 'architecture-state.json');
|
|
173
|
+
for (const argv of [['--state', state], ['--state', state, '--files'], ['--state', state, '--file', 'ARCHITECTURE.md']]) {
|
|
174
|
+
const { code, stderr } = run(argv);
|
|
175
|
+
assert.equal(code, 1, argv.join(' '));
|
|
176
|
+
assert.match(stderr, /^usage:/m);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { classify, changedSections } from '../lib/drift.mjs';
|
|
4
|
+
import { hashText, sectionHashes } from '../lib/state.mjs';
|
|
5
|
+
|
|
6
|
+
const BODY = '# Doc\n\nbody\n';
|
|
7
|
+
const entryFor = (text) => ({ hash: hashText(text) });
|
|
8
|
+
|
|
9
|
+
// A file the skill has never written is never overwritten and never questioned.
|
|
10
|
+
// This is what makes the first run against a hand-written package safe.
|
|
11
|
+
test('a file with no entry is untracked, never ours', () => {
|
|
12
|
+
assert.equal(classify(undefined, BODY), 'untracked');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// The other half of "no entry": a file this run means to create has no entry
|
|
16
|
+
// either. Calling it untracked would tell the agent never to write it, and no
|
|
17
|
+
// new ADR or companion could ever be added after run 1.
|
|
18
|
+
test('a file with no entry and nothing on disk is new, safe to write', () => {
|
|
19
|
+
assert.equal(classify(undefined, null), 'new');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('a matching hash is unchanged', () => {
|
|
23
|
+
assert.equal(classify(entryFor(BODY), BODY), 'unchanged');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('a differing hash is drifted', () => {
|
|
27
|
+
assert.equal(classify(entryFor(BODY), '# Doc\n\nedited\n'), 'drifted');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Deleting a generated file can be deliberate. Recreating it silently would
|
|
31
|
+
// undo a decision nobody was asked about.
|
|
32
|
+
test('a tracked file missing from disk is reported, not recreated', () => {
|
|
33
|
+
assert.equal(classify(entryFor(BODY), null), 'missing');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// decisions.md already rules: an accepted ADR is superseded, never rewritten.
|
|
37
|
+
// The status in state is what lets a run tell an accepted record from a
|
|
38
|
+
// proposed draft it is free to regenerate.
|
|
39
|
+
test('an accepted ADR is locked whatever its hash says', () => {
|
|
40
|
+
assert.equal(classify({ hash: hashText(BODY), status: 'accepted' }, BODY), 'locked');
|
|
41
|
+
assert.equal(classify({ hash: 'sha256:stale', status: 'accepted' }, BODY), 'locked');
|
|
42
|
+
assert.equal(classify({ hash: 'sha256:stale', status: 'proposed' }, BODY), 'drifted');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// The ordinary way an ADR becomes accepted: we wrote it `proposed`, a person
|
|
46
|
+
// accepted it afterwards. State still says `proposed`, so reading state alone
|
|
47
|
+
// offers "overwrite it" for a record the spec says can only be superseded.
|
|
48
|
+
const ADR = '# ADR 0001: Use Stripe\n\n## Status\n\nAccepted\n\n## Context\n\nc\n';
|
|
49
|
+
|
|
50
|
+
test('an ADR accepted on disk is locked whatever state recorded', () => {
|
|
51
|
+
assert.equal(classify({ hash: hashText(ADR), status: 'proposed' }, ADR), 'locked');
|
|
52
|
+
assert.equal(classify({ hash: 'sha256:stale', status: 'proposed' }, ADR), 'locked');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('a document with no status falls back to the recorded one', () => {
|
|
56
|
+
assert.equal(classify({ hash: 'sha256:stale', status: 'accepted' }, BODY), 'locked');
|
|
57
|
+
assert.equal(classify({ hash: 'sha256:stale', status: 'proposed' }, BODY), 'drifted');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const ARCH = '## 1 Goals and Scope\n\na\n\n## 13 Quality Requirements and SLOs\n\nb\n';
|
|
61
|
+
|
|
62
|
+
test('changed sections are named, ascending', () => {
|
|
63
|
+
const entry = { hash: hashText(ARCH), sections: sectionHashes(ARCH) };
|
|
64
|
+
assert.deepEqual(changedSections(entry, ARCH.replace('\nb\n', '\nedited\n')), ['13']);
|
|
65
|
+
assert.deepEqual(changedSections(entry, ARCH), []);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// A section deleted wholesale is a change the reader most needs to see.
|
|
69
|
+
test('a removed section counts as changed', () => {
|
|
70
|
+
const entry = { hash: hashText(ARCH), sections: sectionHashes(ARCH) };
|
|
71
|
+
assert.deepEqual(changedSections(entry, '## 1 Goals and Scope\n\na\n'), ['13']);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('with no recorded sections every present section reads as changed', () => {
|
|
75
|
+
assert.deepEqual(changedSections({ hash: 'sha256:x' }, ARCH), ['1', '13']);
|
|
76
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { mkdtempSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { gitDiff } from '../lib/git-diff.mjs';
|
|
8
|
+
|
|
9
|
+
function repoWithCommit() {
|
|
10
|
+
const root = mkdtempSync(join(tmpdir(), 'rerun-safety-git-'));
|
|
11
|
+
const run = (...args) => execFileSync('git', args, { cwd: root, stdio: 'ignore' });
|
|
12
|
+
run('init', '-q');
|
|
13
|
+
run('config', 'user.email', 'test@example.com');
|
|
14
|
+
run('config', 'user.name', 'Test');
|
|
15
|
+
writeFileSync(join(root, 'ARCHITECTURE.md'), '# Doc\n\nbody\n');
|
|
16
|
+
run('add', 'ARCHITECTURE.md');
|
|
17
|
+
run('commit', '-qm', 'seed');
|
|
18
|
+
return root;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
test('an uncommitted edit comes back as a diff', () => {
|
|
22
|
+
const root = repoWithCommit();
|
|
23
|
+
writeFileSync(join(root, 'ARCHITECTURE.md'), '# Doc\n\nedited\n');
|
|
24
|
+
const out = gitDiff({ root, file: 'ARCHITECTURE.md' });
|
|
25
|
+
assert.match(out, /^-body$/m);
|
|
26
|
+
assert.match(out, /^\+edited$/m);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Staging is not a decision about the document. Compared against the index a
|
|
30
|
+
// staged edit reads as clean, so the working tree has to be compared to HEAD.
|
|
31
|
+
test('a staged edit comes back as a diff', () => {
|
|
32
|
+
const root = repoWithCommit();
|
|
33
|
+
writeFileSync(join(root, 'ARCHITECTURE.md'), '# Doc\n\nedited\n');
|
|
34
|
+
execFileSync('git', ['add', 'ARCHITECTURE.md'], { cwd: root, stdio: 'ignore' });
|
|
35
|
+
const out = gitDiff({ root, file: 'ARCHITECTURE.md' });
|
|
36
|
+
assert.match(out, /^-body$/m);
|
|
37
|
+
assert.match(out, /^\+edited$/m);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// The file is committed, so `git diff` alone reports nothing. Diffing against
|
|
41
|
+
// the commit the state file recorded is what surfaces the change.
|
|
42
|
+
test('a committed edit is found by diffing against the recorded commit', () => {
|
|
43
|
+
const root = repoWithCommit();
|
|
44
|
+
const head = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8' }).trim();
|
|
45
|
+
writeFileSync(join(root, 'ARCHITECTURE.md'), '# Doc\n\nedited\n');
|
|
46
|
+
execFileSync('git', ['commit', '-aqm', 'edit'], { cwd: root, stdio: 'ignore' });
|
|
47
|
+
assert.equal(gitDiff({ root, file: 'ARCHITECTURE.md' }), null);
|
|
48
|
+
assert.match(gitDiff({ root, file: 'ARCHITECTURE.md', since: head }), /^\+edited$/m);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Outside a repo the caller must fall back to section hashes, so this has to
|
|
52
|
+
// return null rather than throw.
|
|
53
|
+
test('no repository yields null, never an exception', () => {
|
|
54
|
+
const root = mkdtempSync(join(tmpdir(), 'rerun-safety-norepo-'));
|
|
55
|
+
writeFileSync(join(root, 'ARCHITECTURE.md'), '# Doc\n');
|
|
56
|
+
assert.equal(gitDiff({ root, file: 'ARCHITECTURE.md' }), null);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('an unchanged file yields null', () => {
|
|
60
|
+
const root = repoWithCommit();
|
|
61
|
+
assert.equal(gitDiff({ root, file: 'ARCHITECTURE.md' }), null);
|
|
62
|
+
});
|
package/plugins/solution-architect/skills/analyze-requirements/scripts/test/quality-gate.test.mjs
CHANGED
|
@@ -74,6 +74,15 @@ test('a genuinely long function is still reported', () => {
|
|
|
74
74
|
assert.deepEqual(violations(src, { functionLines: 22 }), ['function of 32 lines (max 22)']);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
+
// The body opener is found as the first `{` after `function NAME`. When the
|
|
78
|
+
// first parameter is object-destructured, that `{` belongs to the parameter
|
|
79
|
+
// list, not the body — the brace-depth walk then closes on the parameter list
|
|
80
|
+
// and the real body is never measured.
|
|
81
|
+
test('a destructured first parameter does not truncate the measured body', () => {
|
|
82
|
+
const src = ['function long({ a, b }) {', ...Array(25).fill(' const x = 1;'), '}'].join('\n');
|
|
83
|
+
assert.deepEqual(violations(src, { functionLines: 22 }), ['function of 27 lines (max 22)']);
|
|
84
|
+
});
|
|
85
|
+
|
|
77
86
|
test('an omitted limit skips its check', () => {
|
|
78
87
|
const src = ['function f(a, b, c, d) {', ' return a + b + c + d;', '}'].join('\n');
|
|
79
88
|
assert.deepEqual(violations(src, { functionLines: 22 }), [], 'params not checked when absent');
|
package/plugins/solution-architect/skills/analyze-requirements/scripts/test/record-cli.test.mjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { spawnSync, execFileSync } from 'node:child_process';
|
|
4
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
const BIN = 'plugins/solution-architect/skills/analyze-requirements/scripts';
|
|
9
|
+
const ARCH = `---
|
|
10
|
+
name: atlas
|
|
11
|
+
docVersion: 1.2.0
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Atlas Architecture
|
|
15
|
+
|
|
16
|
+
## 1 Goals and Scope
|
|
17
|
+
|
|
18
|
+
Assign jobs to drivers.
|
|
19
|
+
|
|
20
|
+
## 13 Quality Requirements and SLOs
|
|
21
|
+
|
|
22
|
+
p99 under 200 ms.
|
|
23
|
+
`;
|
|
24
|
+
const ADR = '# ADR 0001: Use Stripe\n\n## Status\n\nAccepted\n\n## Context\n\nCheckout needs a processor.\n';
|
|
25
|
+
const FILES = ['ARCHITECTURE.md', 'docs/adr/0001-stripe.md'];
|
|
26
|
+
|
|
27
|
+
function run(script, args) {
|
|
28
|
+
const { status, stdout, stderr } = spawnSync('node', [`${BIN}/${script}`, ...args], {
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
31
|
+
});
|
|
32
|
+
return { code: status, stdout, stderr };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// What step 5 leaves on disk: the package, and nothing recorded about it yet.
|
|
36
|
+
function packageDir() {
|
|
37
|
+
const dir = mkdtempSync(join(tmpdir(), 'rerun-safety-record-'));
|
|
38
|
+
mkdirSync(join(dir, 'docs', 'adr'), { recursive: true });
|
|
39
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), ARCH);
|
|
40
|
+
writeFileSync(join(dir, 'docs', 'adr', '0001-stripe.md'), ADR);
|
|
41
|
+
return dir;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const record = (dir, files = FILES) => run('record.mjs', ['--state', join(dir, 'architecture-state.json'), '--files', ...files]);
|
|
45
|
+
const gate = (dir, files = FILES) => run('drift.mjs', ['--state', join(dir, 'architecture-state.json'), '--files', ...files]);
|
|
46
|
+
const stateOf = (dir) => JSON.parse(readFileSync(join(dir, 'architecture-state.json'), 'utf8'));
|
|
47
|
+
|
|
48
|
+
// The round trip the whole feature rests on: run 1 records, run 2 recognises
|
|
49
|
+
// its own output. Without the writer, run 2 sees no state at all.
|
|
50
|
+
test('a recorded package comes back unchanged', () => {
|
|
51
|
+
const dir = packageDir();
|
|
52
|
+
assert.equal(record(dir).code, 0);
|
|
53
|
+
const { code, stdout } = gate(dir, ['ARCHITECTURE.md']);
|
|
54
|
+
assert.equal(code, 0);
|
|
55
|
+
assert.match(stdout, /ARCHITECTURE\.md\s+unchanged/);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// The bug the branch exists for, with the writing end attached: before this
|
|
59
|
+
// script, run 1 recorded nothing and run 2 cleared the hand edit for overwrite.
|
|
60
|
+
test('recording is what makes a later hand edit report drifted', () => {
|
|
61
|
+
const dir = packageDir();
|
|
62
|
+
record(dir);
|
|
63
|
+
writeFileSync(join(dir, 'ARCHITECTURE.md'), ARCH.replace('200 ms', '150 ms'));
|
|
64
|
+
const { code, stdout } = gate(dir, ['ARCHITECTURE.md']);
|
|
65
|
+
assert.equal(code, 2);
|
|
66
|
+
assert.match(stdout, /ARCHITECTURE\.md\s+drifted/);
|
|
67
|
+
assert.match(stdout, /changed: §13/);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('the record carries every field the next run reads', () => {
|
|
71
|
+
const dir = packageDir();
|
|
72
|
+
record(dir);
|
|
73
|
+
const state = stateOf(dir);
|
|
74
|
+
assert.match(state._generated, /do not edit/);
|
|
75
|
+
assert.equal(state.revision, 1);
|
|
76
|
+
assert.match(state.updated, /^\d{4}-\d{2}-\d{2}T[\d:.]+Z$/);
|
|
77
|
+
assert.equal(state.docVersion, '1.2.0');
|
|
78
|
+
assert.equal(state.gitCommit, null, 'outside a repository there is no commit');
|
|
79
|
+
assert.deepEqual(Object.keys(state.files), FILES);
|
|
80
|
+
assert.match(state.files['ARCHITECTURE.md'].hash, /^sha256:[0-9a-f]{64}$/);
|
|
81
|
+
assert.deepEqual(Object.keys(state.files['ARCHITECTURE.md'].sections), ['1', '13']);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Only ARCHITECTURE.md has a spine to cut on; an ADR carries a status instead,
|
|
85
|
+
// and that status is what exempts it from being rewritten.
|
|
86
|
+
test('an ADR records the status its document declares', () => {
|
|
87
|
+
const dir = packageDir();
|
|
88
|
+
record(dir);
|
|
89
|
+
const entry = stateOf(dir).files['docs/adr/0001-stripe.md'];
|
|
90
|
+
assert.equal(entry.status, 'accepted');
|
|
91
|
+
assert.equal(entry.sections, undefined);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('each run bumps the revision and keeps earlier files recorded', () => {
|
|
95
|
+
const dir = packageDir();
|
|
96
|
+
record(dir);
|
|
97
|
+
assert.equal(record(dir, ['ARCHITECTURE.md']).code, 0);
|
|
98
|
+
const state = stateOf(dir);
|
|
99
|
+
assert.equal(state.revision, 2);
|
|
100
|
+
assert.deepEqual(Object.keys(state.files), FILES);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('inside a repository the commit is recorded', () => {
|
|
104
|
+
const dir = packageDir();
|
|
105
|
+
const git = (...args) => execFileSync('git', args, { cwd: dir, stdio: 'ignore' });
|
|
106
|
+
git('init', '-q');
|
|
107
|
+
git('config', 'user.email', 'test@example.com');
|
|
108
|
+
git('config', 'user.name', 'Test');
|
|
109
|
+
git('add', 'ARCHITECTURE.md');
|
|
110
|
+
git('commit', '-qm', 'seed');
|
|
111
|
+
record(dir);
|
|
112
|
+
assert.equal(stateOf(dir).gitCommit, execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir, encoding: 'utf8' }).trim());
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// The one record of what the last run wrote. Renaming over it resets the
|
|
116
|
+
// revision and takes the bytes with it; drift.mjs already refuses to treat a
|
|
117
|
+
// corrupt file as absent-and-forgotten, and the writer is where that rule can
|
|
118
|
+
// be enforced in code rather than prose.
|
|
119
|
+
test('a corrupt state file is refused, not overwritten', () => {
|
|
120
|
+
const dir = packageDir();
|
|
121
|
+
const statePath = join(dir, 'architecture-state.json');
|
|
122
|
+
writeFileSync(statePath, '{ not json');
|
|
123
|
+
const { code, stderr } = record(dir);
|
|
124
|
+
assert.notEqual(code, 0);
|
|
125
|
+
assert.match(stderr, /unreadable/);
|
|
126
|
+
assert.equal(readFileSync(statePath, 'utf8'), '{ not json', 'never deleted');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('recording nothing is a usage error', () => {
|
|
130
|
+
const dir = packageDir();
|
|
131
|
+
for (const argv of [['--files', 'ARCHITECTURE.md'], ['--state', join(dir, 'architecture-state.json')]]) {
|
|
132
|
+
const { code, stderr } = run('record.mjs', argv);
|
|
133
|
+
assert.equal(code, 1, argv.join(' '));
|
|
134
|
+
assert.match(stderr, /^usage:/m);
|
|
135
|
+
}
|
|
136
|
+
});
|
package/plugins/solution-architect/skills/analyze-requirements/scripts/test/rerun-safety.test.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { mkdtempSync, writeFileSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { hashText, sectionHashes, writeState } from '../lib/state.mjs';
|
|
8
|
+
|
|
9
|
+
const CLI = 'plugins/solution-architect/skills/analyze-requirements/scripts/drift.mjs';
|
|
10
|
+
|
|
11
|
+
const GENERATED = `## 1 Goals and Scope
|
|
12
|
+
|
|
13
|
+
Assign delivery jobs to drivers. \`stated\`
|
|
14
|
+
|
|
15
|
+
## 7 Runtime Behaviour
|
|
16
|
+
|
|
17
|
+
Job created → row written ready → worker claims it. \`stated\`
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
// The bug, end to end: run 1 writes and records, a person edits §7, run 2 must
|
|
21
|
+
// see it. Before this feature existed, run 2 overwrote it with no diff and no
|
|
22
|
+
// warning, and the edit was unrecoverable unless it had been committed.
|
|
23
|
+
test('a hand edit survives the next run', () => {
|
|
24
|
+
const dir = mkdtempSync(join(tmpdir(), 'rerun-safety-regression-'));
|
|
25
|
+
const arch = join(dir, 'ARCHITECTURE.md');
|
|
26
|
+
const statePath = join(dir, 'architecture-state.json');
|
|
27
|
+
|
|
28
|
+
// Run 1 — the skill writes the package and records what it wrote, last.
|
|
29
|
+
writeFileSync(arch, GENERATED);
|
|
30
|
+
writeState(statePath, {
|
|
31
|
+
revision: 1,
|
|
32
|
+
gitCommit: null,
|
|
33
|
+
files: { 'ARCHITECTURE.md': { hash: hashText(GENERATED), sections: sectionHashes(GENERATED) } },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// A person rewrites §7 by hand.
|
|
37
|
+
const edited = GENERATED.replace('worker claims it', 'worker claims it under a 60 s lease');
|
|
38
|
+
writeFileSync(arch, edited);
|
|
39
|
+
|
|
40
|
+
// Run 2 — the pre-write gate.
|
|
41
|
+
let code = 0;
|
|
42
|
+
let stdout = '';
|
|
43
|
+
try {
|
|
44
|
+
stdout = execFileSync('node', [CLI, '--state', statePath, '--files', 'ARCHITECTURE.md'], { encoding: 'utf8' });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
code = err.status;
|
|
47
|
+
stdout = err.stdout;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
assert.equal(code, 2, 'run 2 must stop rather than write');
|
|
51
|
+
assert.match(stdout, /changed: §7/);
|
|
52
|
+
assert.equal(readFileSync(arch, 'utf8'), edited, 'the edit must still be on disk');
|
|
53
|
+
});
|