@v11g/agents-rock 1.0.7 → 1.0.8
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 +1 -1
- package/plugins/reasoning/.claude-plugin/plugin.json +1 -1
- 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/SKILL.md +7 -11
- package/plugins/reasoning/skills/problem-router/references/contract.md +6 -0
- package/plugins/reasoning/skills/problem-solving/README.md +4 -0
- package/plugins/reasoning/skills/problem-solving/SKILL.md +13 -3
- package/plugins/reasoning/skills/problem-solving/references/contract.md +6 -0
- package/plugins/reasoning/skills/problem-solving/references/interview.md +66 -0
- package/plugins/reasoning/skills/systemic-design/README.md +42 -0
- package/plugins/reasoning/skills/systemic-design/SKILL.md +182 -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 +110 -0
- package/plugins/reasoning/skills/systemic-design/references/interview.md +66 -0
- package/plugins/reasoning/skills/systems-thinking/README.md +10 -6
- package/plugins/reasoning/skills/systems-thinking/SKILL.md +16 -6
- package/plugins/reasoning/skills/systems-thinking/frameworks/causal-loop.md +5 -2
- package/plugins/reasoning/skills/systems-thinking/frameworks/leverage-points.md +1 -1
- package/plugins/reasoning/skills/systems-thinking/frameworks/system-map.md +4 -5
- package/plugins/reasoning/skills/systems-thinking/references/contract.md +6 -0
- package/plugins/reasoning/skills/systems-thinking/references/interview.md +66 -0
- 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/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/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/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/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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Evidence interview
|
|
2
|
+
|
|
3
|
+
When a framework's stopping rule does not fire, the evidence a human holds
|
|
4
|
+
is often what's missing. Ask for it before stopping short.
|
|
5
|
+
|
|
6
|
+
## Trigger
|
|
7
|
+
|
|
8
|
+
All three must hold for the interview to run.
|
|
9
|
+
|
|
10
|
+
1. The framework has run and its stopping rule (or test) has not fired,
|
|
11
|
+
or fired only by naming missing evidence — an empty level, an
|
|
12
|
+
unevidenced link, a `root_candidate`, a chain that stopped short.
|
|
13
|
+
2. You can name the specific gap blocking that rule — a field, layer, or
|
|
14
|
+
link, e.g. "`rca.contributing` is empty".
|
|
15
|
+
3. `AskUserQuestion` is available — the same test step 2 applies before
|
|
16
|
+
asking the human to pick a framework. If a call errors, the run is
|
|
17
|
+
headless from that point.
|
|
18
|
+
|
|
19
|
+
**Headless.** If 1 and 2 hold but 3 does not, stop short, and make the
|
|
20
|
+
first `open_questions` entry the question round 1 would have asked — the
|
|
21
|
+
question, its `Look in:` line, and its two options, without the fixed
|
|
22
|
+
exits. If 1 or 2 does not hold, emit as before.
|
|
23
|
+
|
|
24
|
+
## One round
|
|
25
|
+
|
|
26
|
+
Ask exactly one question with `AskUserQuestion`.
|
|
27
|
+
|
|
28
|
+
- **Question** — aimed at the one named gap, using this problem's details:
|
|
29
|
+
its figures, times, components. Not generic wording.
|
|
30
|
+
- **Source hint** — the question text's second line, `Look in: …`, naming
|
|
31
|
+
where the evidence lives: a log, dashboard, trace, ticket, or the person
|
|
32
|
+
who owns it. Never what to expect there. "Look in: the gateway access
|
|
33
|
+
log" passes. "Check whether the DB pool is exhausted" fails — it asserts
|
|
34
|
+
a cause.
|
|
35
|
+
- **Options** — two concrete options drawn from the input: dimensions to
|
|
36
|
+
discriminate along (transaction type, node, region), not guessed causes.
|
|
37
|
+
Then two fixed exits: `Don't know` and `Stop, analyze now`. Free text and
|
|
38
|
+
pasted logs arrive through the tool's built-in Other.
|
|
39
|
+
|
|
40
|
+
## Answers
|
|
41
|
+
|
|
42
|
+
| Answer | Record as | Then |
|
|
43
|
+
| ------ | --------- | ---- |
|
|
44
|
+
| Content | `evidence`, type `interview`, ref `round N` | re-run the framework from step 3 |
|
|
45
|
+
| Pasted log or figures | `evidence`, type `log` or `metric` | re-run |
|
|
46
|
+
| Picked option | `evidence`, type `interview`, ref `round N` | re-run |
|
|
47
|
+
| Confirms an assumption | that assumption's status becomes `confirmed` | re-run |
|
|
48
|
+
| Don't know | `open_questions` | never ask about that gap again |
|
|
49
|
+
| Stop | nothing | emit now, stating "stopped on request" |
|
|
50
|
+
|
|
51
|
+
A re-run is the same framework over more evidence, not a second framework.
|
|
52
|
+
|
|
53
|
+
| Situation | Handling |
|
|
54
|
+
| --------- | -------- |
|
|
55
|
+
| Answer contradicts existing evidence | Keep both, and name the contradiction in `open_questions`. |
|
|
56
|
+
| Answer meets another class's definition in `problem-router` — in `problem-solving`, recurrence (`complex`) or an actor adapting to fixes (`complex-adaptive`); in `systems-thinking`, only `complex-adaptive`; in `systemic-design`, `simple` or `ambiguous` | End the interview and emit. In `systems-thinking`, name `systemic-design` as the next run; elsewhere, recommend re-running `problem-router`. Do not start a second framework. |
|
|
57
|
+
| Human asserts "the cause is X" | Record as `interview` evidence: "the human believes X". It supports a cause only if an observation ties X to the symptom. |
|
|
58
|
+
| Human rejects the question to ask something | Answer in chat, then re-ask the same question. The round does not count. |
|
|
59
|
+
| Human rejects the question with no message | Treat as Stop. |
|
|
60
|
+
|
|
61
|
+
## End
|
|
62
|
+
|
|
63
|
+
The loop ends when the stopping rule fires, no askable gap remains, the
|
|
64
|
+
human picks Stop, an answer meets another class's definition, or round 6
|
|
65
|
+
completes. Say in the output which one ended
|
|
66
|
+
it.
|
|
@@ -14,7 +14,8 @@ served on localhost for review.
|
|
|
14
14
|
2. One home per fact — diagrams own topology, tables own properties, prose owns neither.
|
|
15
15
|
3. Unknowns render as honest absences (`Not applicable — <reason>`, `not estimated`, `Not provided`) — never placeholders, never `[TODO]`, never `0`.
|
|
16
16
|
4. Validation blocks rendering: `node scripts/validate.mjs` must exit 0 before the viewer is generated.
|
|
17
|
-
5.
|
|
17
|
+
5. Never overwrite what this skill did not write. A file already on disk with no entry in `architecture-state.json` is not ours and is never overwritten, while one with no entry and no file yet is this run's to create; a file whose hash moved has changed since the last run, and is asked about before anything is written (`references/rewriting.md`).
|
|
18
|
+
6. mattpocock files (`CONTEXT.md`, `CONTEXT-MAP.md`, `docs/adr/`) are written into their existing formats — never restructured. Invoke the `domain-modeling` skill for term work.
|
|
18
19
|
|
|
19
20
|
## Flow
|
|
20
21
|
|
|
@@ -22,7 +23,7 @@ served on localhost for review.
|
|
|
22
23
|
2. **Scan** (brownfield): `index_repository` if needed, then `get_architecture` — clusters seed §6 Core Components. Read `manage_adr` if present; never write it.
|
|
23
24
|
3. **Interview**: follow `references/interview.md`. Detect project type per `references/project-types.md`.
|
|
24
25
|
4. **Research**: run `workflows/research.js` per `references/research.md`. Surface dropped items before writing.
|
|
25
|
-
5. **Write**:
|
|
26
|
+
5. **Write**: on every run, `node scripts/drift.mjs` gates this step — before the first write, never after (`references/rewriting.md`). Then the model (`references/likec4.md`), then ARCHITECTURE.md and companions (`references/writing.md`). Last, once every document is on disk, record what was written: `node scripts/record.mjs --state ... --files ...`.
|
|
26
27
|
6. **Validate**: export the model with `node scripts/likec4-export.mjs --dir ... --out ...`, then `node scripts/validate.mjs --arch ... --model ...` (add `--mode brownfield --clusters ...` when applicable). Fix findings; re-run until clean.
|
|
27
28
|
7. **Render + serve**: follow `references/viewer.md`; report the URL.
|
|
28
29
|
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Rewriting — what is already on disk
|
|
2
|
+
|
|
3
|
+
Read before step 5 writes anything. The gate (§3) runs on every run, before the
|
|
4
|
+
first write; the recording (§5) closes every run. Only what they find differs —
|
|
5
|
+
a first run has no record to compare against, and the documents it finds
|
|
6
|
+
already on disk are, by that fact, not ours.
|
|
7
|
+
|
|
8
|
+
## 1. The rule
|
|
9
|
+
|
|
10
|
+
**Ask before the first write, or not at all.** A package half-written while a
|
|
11
|
+
question waits is worse than either answer: the reader cannot tell which
|
|
12
|
+
sections are theirs and which are ours.
|
|
13
|
+
|
|
14
|
+
## 2. What the state file knows, and what it does not
|
|
15
|
+
|
|
16
|
+
`architecture-state.json` sits beside `ARCHITECTURE.md` and records a hash per
|
|
17
|
+
generated file, plus a hash per spine section for `ARCHITECTURE.md`. It is
|
|
18
|
+
**written last**, after every document is on disk, through a temp file and a
|
|
19
|
+
rename — so a crash leaves it pointing at the previous consistent revision.
|
|
20
|
+
|
|
21
|
+
A hash says a file **changed since the last run**. It cannot say who changed
|
|
22
|
+
it: a formatter, a merge, a `git checkout`, another agent and a person all look
|
|
23
|
+
identical, and a hash cannot tell them apart — so what the run reports must
|
|
24
|
+
never claim to know an author. Write "this changed since the last run", not a
|
|
25
|
+
claim about who did it.
|
|
26
|
+
|
|
27
|
+
## 3. The gate
|
|
28
|
+
|
|
29
|
+
Before writing, run:
|
|
30
|
+
|
|
31
|
+
node scripts/drift.mjs --state <package>/architecture-state.json \
|
|
32
|
+
--files ARCHITECTURE.md docs/architecture/validation-plan.md …
|
|
33
|
+
|
|
34
|
+
List every file this run intends to write. Paths are relative to the state
|
|
35
|
+
file. Exit codes: `0` nothing drifted, `2` something drifted, `1` usage error.
|
|
36
|
+
|
|
37
|
+
| verdict | meaning | what to do |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `unchanged` | matches what we wrote | write it |
|
|
40
|
+
| `new` | we have never written it and it is not on disk | write it — nobody has one |
|
|
41
|
+
| `untracked` | we have never written it, but a file is there | **never write it** — it is not ours |
|
|
42
|
+
| `missing` | we wrote it, it is gone now | report it; never silently recreate it |
|
|
43
|
+
| `locked` | an ADR whose `## Status` on disk reads accepted | never rewrite; a new decision is a new ADR with `supersedes` |
|
|
44
|
+
| `drifted` | changed since we wrote it | ask, before writing anything |
|
|
45
|
+
|
|
46
|
+
## 4. Asking
|
|
47
|
+
|
|
48
|
+
One question, covering every drifted file at once, before the first write.
|
|
49
|
+
Show what the gate printed — the diff where git supplied one, the changed
|
|
50
|
+
section numbers where it did not. For each file offer exactly three answers:
|
|
51
|
+
|
|
52
|
+
- **keep the file on disk** — skip it; the rest of the run proceeds
|
|
53
|
+
- **overwrite it with the new revision** — the edit is lost, and they have been
|
|
54
|
+
shown what they are discarding
|
|
55
|
+
- **stop the run** — nothing is written, the state file is untouched
|
|
56
|
+
|
|
57
|
+
No merge. No three-way resolution. Detect, show, ask which wins, obey.
|
|
58
|
+
|
|
59
|
+
## 5. Recording what you wrote
|
|
60
|
+
|
|
61
|
+
The gate can only compare against a record, and nothing writes that record on
|
|
62
|
+
its own. **The last thing step 5 does**, once every document is on disk:
|
|
63
|
+
|
|
64
|
+
node scripts/record.mjs --state <package>/architecture-state.json \
|
|
65
|
+
--files ARCHITECTURE.md docs/architecture/validation-plan.md docs/adr/0001-….md
|
|
66
|
+
|
|
67
|
+
`--files` is every file this run actually wrote: the list the gate was given,
|
|
68
|
+
minus any file a drift answer told you to keep and minus anything the run
|
|
69
|
+
skipped. Paths are relative to the state file, as they are for the gate. A file
|
|
70
|
+
left out keeps whatever entry it already had.
|
|
71
|
+
|
|
72
|
+
`docVersion` is read from `ARCHITECTURE.md`'s frontmatter. Pass
|
|
73
|
+
`--doc-version <v>` only on a run that did not write that document.
|
|
74
|
+
|
|
75
|
+
The script hashes each file, adds a hash per spine section for
|
|
76
|
+
`ARCHITECTURE.md`, reads each ADR's `## Status`, and writes:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"_generated": "written by analyze-requirements — do not edit",
|
|
81
|
+
"revision": 3,
|
|
82
|
+
"updated": "2026-09-23T10:11:00.000Z",
|
|
83
|
+
"docVersion": "1.2.0",
|
|
84
|
+
"gitCommit": "3dcac90…",
|
|
85
|
+
"files": {
|
|
86
|
+
"ARCHITECTURE.md": { "hash": "sha256:9f2a…", "sections": { "1": "sha256:aa…" } },
|
|
87
|
+
"docs/adr/0001-postgres-job-queue.md": { "hash": "sha256:e4…", "status": "accepted" }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Never hand-write or hand-edit that file. A record that disagrees with what is
|
|
93
|
+
on disk is worse than no record at all: it reports drift nobody caused, and
|
|
94
|
+
people learn to answer "overwrite" without reading.
|
|
95
|
+
|
|
96
|
+
## 6. First runs and broken states
|
|
97
|
+
|
|
98
|
+
No state file means a first run: every file is still judged — untracked where
|
|
99
|
+
one is already on disk, `new` where none is — nothing is blocked, and the state
|
|
100
|
+
is written at the end.
|
|
101
|
+
|
|
102
|
+
A state file that will not parse is treated as absent, said out loud, and
|
|
103
|
+
**never deleted** — it is the only record of what the last run wrote. It is not
|
|
104
|
+
a first run, though: the file's existence says tracked documents are on disk,
|
|
105
|
+
and its corruption is what stops us telling which of them moved. Nothing on
|
|
106
|
+
disk can be verified against it, so nothing in that run is cleared for writing.
|
|
107
|
+
`record.mjs` refuses to run against one, because writing would rename over the
|
|
108
|
+
only record of the last run. Rename it by hand if you mean to start fresh.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { readState } from './lib/state.mjs';
|
|
4
|
+
import { classify, changedSections } from './lib/drift.mjs';
|
|
5
|
+
import { gitDiff } from './lib/git-diff.mjs';
|
|
6
|
+
|
|
7
|
+
// Same shape as validate.mjs: the list-consuming loop is extracted so the
|
|
8
|
+
// parser stays inside the two-level nesting limit.
|
|
9
|
+
function consumeFiles(argv, i, files) {
|
|
10
|
+
while (argv[i + 1] && !argv[i + 1].startsWith('--')) files.push(argv[++i]);
|
|
11
|
+
return i;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function parseArgs(argv) {
|
|
15
|
+
const args = { files: [] };
|
|
16
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
17
|
+
const flag = argv[i];
|
|
18
|
+
if (flag === '--files') i = consumeFiles(argv, i, args.files);
|
|
19
|
+
else if (flag.startsWith('--')) args[flag.slice(2)] = argv[++i];
|
|
20
|
+
}
|
|
21
|
+
return args;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function read(path) {
|
|
25
|
+
return existsSync(path) ? readFileSync(path, 'utf8') : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function detail(ctx, file) {
|
|
29
|
+
const text = read(join(ctx.root, file));
|
|
30
|
+
const diff = gitDiff({ root: ctx.root, file, since: ctx.state.gitCommit });
|
|
31
|
+
if (diff) return diff.split('\n').map((l) => ` ${l}`).join('\n');
|
|
32
|
+
const sections = changedSections(ctx.state.files[file], text);
|
|
33
|
+
return ` changed: ${sections.map((n) => `§${n}`).join(', ') || 'whole file'}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function report(ctx, file) {
|
|
37
|
+
const verdict = classify(ctx.state.files[file], read(join(ctx.root, file)));
|
|
38
|
+
console.log(`${file} ${verdict}`);
|
|
39
|
+
if (verdict === 'drifted') console.log(detail(ctx, file));
|
|
40
|
+
return verdict;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const args = parseArgs(process.argv.slice(2));
|
|
44
|
+
// An empty write set is a fumbled argument, never an all-clear: a mistyped
|
|
45
|
+
// --file would otherwise turn the gate into a clean bill of health.
|
|
46
|
+
if (!args.state || !args.files.length) {
|
|
47
|
+
console.error('usage: drift.mjs --state <architecture-state.json> --files <path> [<path> …]');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { state, error } = readState(args.state);
|
|
52
|
+
// A corrupt state file is evidence that tracked files are on disk and that we
|
|
53
|
+
// cannot tell which of them moved, so it never earns the first-run
|
|
54
|
+
// reassurance — and it is never deleted.
|
|
55
|
+
if (error) console.log(`state file ${error}`);
|
|
56
|
+
if (error) console.log('nothing on disk can be verified against it — treat every file as not ours');
|
|
57
|
+
// A first run is not halted, but it is still judged: with no entries every file
|
|
58
|
+
// already on disk reads as untracked, which is what keeps a hand-written
|
|
59
|
+
// package safe from the run that was pointed at it.
|
|
60
|
+
else if (!state) console.log('first run — no state recorded, nothing is at risk');
|
|
61
|
+
|
|
62
|
+
const ctx = { root: dirname(args.state), state: { gitCommit: null, files: {}, ...state } };
|
|
63
|
+
const verdicts = args.files.map((f) => report(ctx, f));
|
|
64
|
+
process.exit(verdicts.includes('drifted') ? 2 : 0);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { hashText, sectionHashes } from './state.mjs';
|
|
2
|
+
|
|
3
|
+
// An ADR's `## Status` section, as decisions.md formats it.
|
|
4
|
+
const STATUS = /^##\s+Status\b[^\n]*\n+\s*([A-Za-z][\w-]*)/m;
|
|
5
|
+
|
|
6
|
+
// The document outranks the record. The usual way an ADR becomes accepted is a
|
|
7
|
+
// person editing it after we wrote it `proposed`, so trusting what the last run
|
|
8
|
+
// recorded locks only the ADRs that were already accepted when we wrote them —
|
|
9
|
+
// the ones nobody needed protecting.
|
|
10
|
+
export function docStatus(text) {
|
|
11
|
+
return text?.match(STATUS)?.[1].toLowerCase() ?? null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// `locked` is not a hash verdict. decisions.md rules that an accepted ADR is
|
|
15
|
+
// superseded by a new record, never rewritten, so its hash is irrelevant.
|
|
16
|
+
export function classify(entry, text) {
|
|
17
|
+
// No entry says nothing on its own. A file on disk we never wrote is someone
|
|
18
|
+
// else's; no file at all is one this run is free to create.
|
|
19
|
+
if (!entry) return text === null ? 'new' : 'untracked';
|
|
20
|
+
if ((docStatus(text) ?? entry.status) === 'accepted') return 'locked';
|
|
21
|
+
if (text === null) return 'missing';
|
|
22
|
+
return entry.hash === hashText(text) ? 'unchanged' : 'drifted';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function changedSections(entry, text) {
|
|
26
|
+
const now = sectionHashes(text);
|
|
27
|
+
const before = entry?.sections ?? {};
|
|
28
|
+
const moved = Object.keys(now).filter((n) => before[n] !== now[n]);
|
|
29
|
+
const removed = Object.keys(before).filter((n) => !(n in now));
|
|
30
|
+
return [...moved, ...removed].sort((a, b) => Number(a) - Number(b));
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
// Returns null rather than throwing: no repo, no git, or no difference all mean
|
|
4
|
+
// "no diff available", and the caller falls back to naming changed sections.
|
|
5
|
+
function diff(root, range) {
|
|
6
|
+
try {
|
|
7
|
+
const out = execFileSync('git', ['diff', '--no-color', ...range], {
|
|
8
|
+
cwd: root,
|
|
9
|
+
encoding: 'utf8',
|
|
10
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
11
|
+
});
|
|
12
|
+
return out.trim() ? out : null;
|
|
13
|
+
} catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// The working tree against HEAD first — against HEAD rather than the index, so
|
|
19
|
+
// that staging an edit does not hide it. `since` is HEAD as it stood when the
|
|
20
|
+
// state file was written, before anyone committed what that run had just
|
|
21
|
+
// written, so reaching for it while an uncommitted change exists renders the
|
|
22
|
+
// whole regeneration and buries the one line a person has to judge.
|
|
23
|
+
export function gitDiff({ root, file, since = null }) {
|
|
24
|
+
const working = diff(root, ['HEAD', '--', file]);
|
|
25
|
+
if (working || !since) return working;
|
|
26
|
+
return diff(root, [since, '--', file]);
|
|
27
|
+
}
|
|
@@ -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
|
+
});
|