nukadoko 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +291 -0
  3. data/README.ja.md +58 -5
  4. data/README.md +15 -3
  5. data/exe/nuka +8 -0
  6. data/lib/nukadoko/aria_snapshot.rb +1008 -0
  7. data/lib/nukadoko/aria_tree.rb +150 -0
  8. data/lib/nukadoko/base.rb +274 -0
  9. data/lib/nukadoko/check.rb +669 -22
  10. data/lib/nukadoko/claim_check.rb +177 -0
  11. data/lib/nukadoko/claim_check_run.rb +293 -0
  12. data/lib/nukadoko/claim_line.rb +381 -0
  13. data/lib/nukadoko/claim_rules.rb +519 -0
  14. data/lib/nukadoko/claims.rb +407 -30
  15. data/lib/nukadoko/cli.rb +802 -19
  16. data/lib/nukadoko/codes.json +942 -0
  17. data/lib/nukadoko/codes.rb +19 -0
  18. data/lib/nukadoko/command.rb +214 -12
  19. data/lib/nukadoko/criteria.rb +172 -0
  20. data/lib/nukadoko/definition.rb +33 -41
  21. data/lib/nukadoko/env_check.rb +90 -0
  22. data/lib/nukadoko/features.rb +80 -10
  23. data/lib/nukadoko/fixtures.rb +296 -10
  24. data/lib/nukadoko/http_recording.rb +68 -0
  25. data/lib/nukadoko/init.rb +130 -0
  26. data/lib/nukadoko/judge.rb +221 -0
  27. data/lib/nukadoko/judgment_file.rb +78 -0
  28. data/lib/nukadoko/judgments.rb +256 -0
  29. data/lib/nukadoko/literal.rb +129 -0
  30. data/lib/nukadoko/measured.rb +105 -0
  31. data/lib/nukadoko/order.rb +84 -0
  32. data/lib/nukadoko/parts.rb +42 -21
  33. data/lib/nukadoko/pattern.rb +11 -1
  34. data/lib/nukadoko/poll.rb +17 -6
  35. data/lib/nukadoko/program.rb +105 -17
  36. data/lib/nukadoko/project_fixtures.rb +17 -2
  37. data/lib/nukadoko/report_allure.rb +751 -0
  38. data/lib/nukadoko/report_messages.rb +167 -0
  39. data/lib/nukadoko/report_run.rb +169 -0
  40. data/lib/nukadoko/run.rb +865 -88
  41. data/lib/nukadoko/run_record.rb +532 -0
  42. data/lib/nukadoko/scaffold.rb +1015 -0
  43. data/lib/nukadoko/schema.rb +61 -4
  44. data/lib/nukadoko/secrets.rb +359 -0
  45. data/lib/nukadoko/selection.rb +163 -0
  46. data/lib/nukadoko/signature.rb +4 -1
  47. data/lib/nukadoko/skill.rb +36 -0
  48. data/lib/nukadoko/step.rb +62 -21
  49. data/lib/nukadoko/summary.rb +662 -0
  50. data/lib/nukadoko/table.rb +34 -2
  51. data/lib/nukadoko/text_fit.rb +179 -0
  52. data/lib/nukadoko/trace.rb +244 -0
  53. data/lib/nukadoko/trace_actions.rb +116 -0
  54. data/lib/nukadoko/tree_passes.rb +119 -0
  55. data/lib/nukadoko/verdict.rb +128 -0
  56. data/lib/nukadoko/version.rb +2 -1
  57. data/lib/nukadoko/vocabulary.rb +6 -0
  58. data/lib/nukadoko/walk.rb +305 -0
  59. data/lib/nukadoko/walk_files.rb +473 -0
  60. data/lib/nukadoko/walk_step.rb +149 -0
  61. data/lib/nukadoko.rb +36 -0
  62. data/llms.txt +296 -0
  63. data/sig/generated/nukadoko/aria_snapshot.rbs +331 -0
  64. data/sig/generated/nukadoko/aria_tree.rbs +142 -0
  65. data/sig/generated/nukadoko/base.rbs +136 -0
  66. data/sig/generated/nukadoko/check.rbs +255 -0
  67. data/sig/generated/nukadoko/claim_check.rbs +118 -0
  68. data/sig/generated/nukadoko/claim_check_run.rbs +88 -0
  69. data/sig/generated/nukadoko/claim_line.rbs +158 -0
  70. data/sig/generated/nukadoko/claim_rules.rbs +172 -0
  71. data/sig/generated/nukadoko/claims.rbs +165 -0
  72. data/sig/generated/nukadoko/cli.rbs +182 -0
  73. data/sig/generated/nukadoko/codes.rbs +16 -0
  74. data/sig/generated/nukadoko/command.rbs +109 -0
  75. data/sig/generated/nukadoko/criteria.rbs +83 -0
  76. data/sig/generated/nukadoko/definition.rbs +30 -0
  77. data/sig/generated/nukadoko/env_check.rbs +38 -0
  78. data/sig/generated/nukadoko/features.rbs +101 -0
  79. data/sig/generated/nukadoko/fixtures.rbs +152 -0
  80. data/sig/generated/nukadoko/http_recording.rbs +29 -0
  81. data/sig/generated/nukadoko/init.rbs +66 -0
  82. data/sig/generated/nukadoko/judge.rbs +64 -0
  83. data/sig/generated/nukadoko/judgment_file.rbs +39 -0
  84. data/sig/generated/nukadoko/judgments.rbs +120 -0
  85. data/sig/generated/nukadoko/literal.rbs +71 -0
  86. data/sig/generated/nukadoko/measured.rbs +42 -0
  87. data/sig/generated/nukadoko/order.rbs +54 -0
  88. data/sig/generated/nukadoko/parts.rbs +35 -0
  89. data/sig/generated/nukadoko/pattern.rbs +28 -0
  90. data/sig/generated/nukadoko/poll.rbs +40 -0
  91. data/sig/generated/nukadoko/program.rbs +101 -0
  92. data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
  93. data/sig/generated/nukadoko/report_allure.rbs +268 -0
  94. data/sig/generated/nukadoko/report_messages.rbs +68 -0
  95. data/sig/generated/nukadoko/report_run.rbs +102 -0
  96. data/sig/generated/nukadoko/run.rbs +257 -0
  97. data/sig/generated/nukadoko/run_record.rbs +174 -0
  98. data/sig/generated/nukadoko/scaffold.rbs +328 -0
  99. data/sig/generated/nukadoko/schema.rbs +137 -0
  100. data/sig/generated/nukadoko/secrets.rbs +157 -0
  101. data/sig/generated/nukadoko/selection.rbs +73 -0
  102. data/sig/generated/nukadoko/signature.rbs +17 -0
  103. data/sig/generated/nukadoko/skill.rbs +20 -0
  104. data/sig/generated/nukadoko/step.rbs +115 -0
  105. data/sig/generated/nukadoko/summary.rbs +204 -0
  106. data/sig/generated/nukadoko/table.rbs +43 -0
  107. data/sig/generated/nukadoko/text_fit.rbs +70 -0
  108. data/sig/generated/nukadoko/trace.rbs +127 -0
  109. data/sig/generated/nukadoko/trace_actions.rbs +40 -0
  110. data/sig/generated/nukadoko/tree_passes.rbs +48 -0
  111. data/sig/generated/nukadoko/verdict.rbs +56 -0
  112. data/sig/generated/nukadoko/version.rbs +5 -0
  113. data/sig/generated/nukadoko/vocabulary.rbs +25 -0
  114. data/sig/generated/nukadoko/walk.rbs +139 -0
  115. data/sig/generated/nukadoko/walk_files.rbs +189 -0
  116. data/sig/generated/nukadoko/walk_step.rbs +50 -0
  117. data/sig/generated/nukadoko.rbs +15 -0
  118. data/sig/nukadoko.rbs +5 -48
  119. data/skills/nukadoko/SKILL.md +120 -0
  120. data/skills/nukadoko/references/checking-steps.md +200 -0
  121. data/skills/nukadoko/references/diagnosing.md +200 -0
  122. data/skills/nukadoko/references/done.md +99 -0
  123. data/skills/nukadoko/references/evidence.md +124 -0
  124. data/skills/nukadoko/references/examples/cli.md +230 -0
  125. data/skills/nukadoko/references/examples/http-api.md +339 -0
  126. data/skills/nukadoko/references/examples/workflow.md +173 -0
  127. data/skills/nukadoko/references/exploring.md +184 -0
  128. data/skills/nukadoko/references/fixtures.md +198 -0
  129. data/skills/nukadoko/references/from-prose.md +51 -0
  130. data/skills/nukadoko/references/judgments.md +95 -0
  131. data/skills/nukadoko/references/maintenance.md +97 -0
  132. data/skills/nukadoko/references/merge-risk.md +74 -0
  133. data/skills/nukadoko/references/parts.md +152 -0
  134. data/skills/nukadoko/references/perturbed-worlds.md +107 -0
  135. data/skills/nukadoko/references/program.md +200 -0
  136. data/skills/nukadoko/references/reviewing.md +200 -0
  137. data/skills/nukadoko/references/running.md +200 -0
  138. data/skills/nukadoko/references/scenario-rules.md +188 -0
  139. data/skills/nukadoko/references/states.md +66 -0
  140. data/skills/nukadoko/references/step-files.md +200 -0
  141. data/skills/nukadoko/references/verdicts.md +200 -0
  142. data/skills/nukadoko/references/writing-steps.md +200 -0
  143. data/skills/nukadoko/references/writing-the-feature.md +165 -0
  144. data/skills/nukadoko/scripts/claude-code-verdict-hook.mjs +99 -0
  145. data/skills/nukadoko/scripts/merge-risk.jq +56 -0
  146. data/skills/nukadoko-verification/SKILL.md +263 -0
  147. metadata +121 -1
@@ -0,0 +1,165 @@
1
+ # Writing the feature
2
+
3
+ If you can reach the tracker at all (an MCP server, `gh issue view`, a Jira
4
+ CLI, or just the ticket pasted into the prompt), carry across its id, URL,
5
+ title, and acceptance criteria in the reviewer's own words, unparaphrased.
6
+ How you reached it doesn't matter and isn't worth recording; that the
7
+ feature can be traced back to what it was written for does.
8
+
9
+ nukadoko has no concept of a ticket, so the feature file is the only place
10
+ that link is recorded, and the reviewer reads it in the pull request's diff
11
+ next to the run summary. Don't write a field you couldn't fill: an
12
+ empty `Ticket:` line is worse than no line at all, because it reads as a
13
+ link that was lost rather than one that was never available.
14
+
15
+ Each scenario is those criteria translated into the vocabulary
16
+ (`references/writing-steps.md`, "Reading the vocabulary"), whether they
17
+ arrived straight from a ticket or through the requirements stage below.
18
+ Where that translation is a judgment call, the judgment is what review of
19
+ the feature is for. `scenario-rules.md` is what makes a scenario able to
20
+ fail for the right reason: a Then that claims a value, an expected value
21
+ taken from the criteria, a sentence that names what a user sees.
22
+
23
+ ```gherkin
24
+ @PROJ-123
25
+ Feature: Sign in with valid credentials
26
+
27
+ Ticket: https://example.atlassian.net/browse/PROJ-123
28
+ Title: A user can sign in with a correct email and password
29
+
30
+ Acceptance criteria (verbatim from the ticket):
31
+ - Signing in with a correct email and password lands on the dashboard
32
+ - A wrong password shows an error and does not sign the user in
33
+
34
+ Scenario: ...
35
+ ```
36
+
37
+ The tag carries the id in a form something can grep for; the free text
38
+ under `Feature:` carries what a person needs. Follow whatever tag shape the
39
+ project already uses (`@PROJ-123`, `@issue-456`). A bare `@#456` parses
40
+ as a tag, but `#` reads as a comment to most readers and tools, so give
41
+ an issue number a prefix.
42
+
43
+ With no tracker to carry across, drop the tag and the `Ticket:` line and
44
+ keep the free text. That block is the place for anything a reader needs
45
+ that no line of the scenario establishes, a premise the scenario takes as
46
+ already true included. Do not turn such a premise into a step unless the
47
+ scenario really does establish it: a step is a claim that something ran.
48
+
49
+ ## From requirements to scenarios
50
+
51
+ This is where information gets added that no requirement sentence stated:
52
+ concrete values, boundaries, negative paths. Turning "a discount code
53
+ applies to eligible orders" into a scenario means picking an actual code,
54
+ an actual order total, and an actual eligibility rule to test against, and
55
+ none of those came from the requirement itself. This is real information,
56
+ not implied by the requirement, so it has to be visible, not silently
57
+ assumed.
58
+
59
+ - **Surface every assumption.** State beside the scenario what was chosen
60
+ and why (a comment, a linked table, or the PR description), rather than
61
+ leaving a literal value to speak for itself. A reviewer who can't see
62
+ what was assumed can't tell whether it was the right assumption.
63
+ - **Keep the trace.** Which requirement sentence produced which scenario
64
+ should be readable later, not just at the moment of writing. The
65
+ ticket-verbatim convention under `Feature:` (see above) already carries
66
+ this for a scenario sourced from a ticket; keep the same discipline for
67
+ one whose trace target is a requirement sentence rather than a ticket.
68
+ - **Know when a single scenario stops being the right tool.** A rule with
69
+ several combining conditions doesn't resolve sentence by sentence; reach
70
+ for a decision table or a state model instead of writing one scenario
71
+ per case and hoping the combinations stay covered. What decides whether
72
+ to reach for one is the number of conditions the rule combines, not how
73
+ large the project is: a two-person tool with one four-condition rule
74
+ needs the table as much as a large one does.
75
+
76
+ A model drafting this translation is not the problem this stage guards
77
+ against; drafting is fine, and it can happen before any of it is fixed.
78
+ What gets fixed is the moment a person reads the draft, sees the
79
+ assumptions it made, and accepts them: that happens before any
80
+ implementation is generated from the scenario, which is the whole point of
81
+ doing it here rather than after. What the stage forbids is a draft whose
82
+ assumptions never surface at all, not the act of drafting one.
83
+
84
+ ## Scenario Outline and Background
85
+
86
+ Gherkin compiles a feature into pickles before nukadoko ever runs it: a
87
+ Scenario Outline's `Examples` table produces one independent pickle per
88
+ row, never one pickle covering the whole table, and a Background's own
89
+ steps are folded into every pickle in that feature, run ahead of that
90
+ scenario's steps. Writing an Outline row per case, rather than one
91
+ scenario asserting several values in a row, is what keeps each case its
92
+ own step records and its own pass or fail, never two cases sharing one
93
+ verdict because they happened to share a scenario. Put a column in the
94
+ Outline's name (`Scenario Outline: greets <name>`): with several rows and
95
+ no column there, every row has the same name in the run summary, and
96
+ `nuka check` warns `outline-rows-share-name`. Use an Outline when the
97
+ rows differ only in values and share every sentence, and separate
98
+ scenarios when a row needs a sentence of its own. A Background holds a
99
+ Given that every scenario of the file shares, and nothing else.
100
+
101
+ ## Choosing Given, When, or Then
102
+
103
+ Pick the keyword for what the line does for its reader. Given is what is
104
+ already true, When is the action under test, Then is what has to be
105
+ observable afterwards. Matching does not depend on the keyword at all: a
106
+ line binds by its pattern alone, so the keyword is a claim to the reader
107
+ rather than an instruction to the tool. The same step can be the When of
108
+ one scenario and a Given of another: a registration is the action under
109
+ test in "a short password" and the setup in "sign in before confirming".
110
+ A step that can be refused returns the outcome instead of throwing, so a
111
+ Then can claim the refusal (`examples/workflow.md`).
112
+
113
+ The keyword meets a step's contract in one place: a Then binds a claim
114
+ step, and only a Then does. A Then bound to a step that runs is the
115
+ `then-without-claims` error, and a claim step in Given or When position
116
+ the `claims-outside-then` error. A Then line that acts is a Then doing
117
+ the When's job, and a Given that judges would make a broken setup read as
118
+ a failed criterion.
119
+
120
+ `And` and `But` take the position of the primary keyword above them,
121
+ which is gherkin's own rule rather than a nukadoko choice, so an `And`
122
+ under `Then` sits in Then position too. A `*` line has no position, so
123
+ it is never a Then. A scenario with steps of its own and no Then, in it
124
+ or in the Background (a scenario of only `*` lines included), passes
125
+ whenever its steps run, and so does one whose Then lines bind no claim
126
+ step, so `nuka check` warns `scenario-without-then`, and run.json marks
127
+ a scenario in which no Then claim was judged with `judged_by`. Add the Then line that names
128
+ what the reader must observe afterwards; a step that checks something
129
+ but sits under Given or When belongs under Then instead.
130
+
131
+ A Then that says something is absent ("no message to Ben holds the card
132
+ "8"") binds a claim step whose claim is an `each` over what was read, with
133
+ the item claim `not-equal` the captured value (`checking-steps.md`). An
134
+ `each` breaks on an empty array, so the Then cannot hold on a reading that
135
+ saw nothing at all, which a plain "is not in the list" would.
136
+
137
+ ## A Then about a page
138
+
139
+ State what a page shows by role and name, in a docstring written as an ARIA
140
+ snapshot (the YAML `ariaSnapshot()` prints for an accessibility tree), cut to
141
+ what the criterion names; the step claims it with `fits-aria-snapshot`
142
+ (`checking-steps.md`, "A page by role and name"):
143
+
144
+ ```gherkin
145
+ Then the page shows
146
+ """
147
+ - heading "Room 7" [level=1]
148
+ - form "Scores":
149
+ - button "Score"
150
+ """
151
+ ```
152
+
153
+ Each node is found at any depth, its children in their order with others
154
+ between (a `- /children: equal` line asks for exactly those), and a node with
155
+ no name (`- button`) fits any name. What the tree leaves out is not asked, so
156
+ the page may show more. Write the tree from the criterion, never from the
157
+ page's printed snapshot: a tree copied from the page holds whatever the page
158
+ shows. When the project keeps UI strings out of its features, leave the
159
+ name off a node whose name is a UI string (`- slider`), name a node only by
160
+ what the sentence already states as data (an act or a person, `- heading
161
+ "Alpha"`), and let the step choose a named region with its locator, where UI
162
+ strings may live. A broken claim names the first expected line that fits
163
+ nothing and the nearest node (`expected line 2 (button "Submit") fits no
164
+ child of form "Scores" (actual line 3); nearest: button "Skip" [disabled]
165
+ (actual line 7)`).
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ // Responsibility: an example Claude Code hook, opt-in, that holds an agent
3
+ // back once from ending a turn that changed the working tree while
4
+ // `nuka verdict` says no run speaks for that tree, or the newest run left
5
+ // something red. It reads the answer through `nuka verdict --json` and
6
+ // never starts a run: a run can take minutes, and which features and which
7
+ // base to run is the agent's call. Nothing installs it; a project that
8
+ // wants it names it in its own .claude/settings.json
9
+ // (references/done.md).
10
+ //
11
+ // Two events, one script:
12
+ // - UserPromptSubmit keeps the working tree id the turn started from, so
13
+ // Stop can tell a turn that changed nothing (a question, a review) from
14
+ // one that changed files. Without it, every turn in an unjudged tree
15
+ // would be held.
16
+ // - Stop asks `nuka verdict`. It holds the turn only when the tree moved
17
+ // during the turn and the verdict is failed, and never when
18
+ // `stop_hook_active` is true: the stop after a hold goes through, so the
19
+ // agent can end by saying what stays unproven instead of being looped.
20
+ //
21
+ // The input fields read (`hook_event_name`, `session_id`, `cwd`,
22
+ // `stop_hook_active`) and the output (`decision: "block"` with `reason`,
23
+ // which Stop reads as the instruction to continue) are Claude Code's hook
24
+ // contract as of 2.1.317. A host or a version that names them otherwise
25
+ // gets no hold: every unreadable case exits 0 with nothing on stdout.
26
+ //
27
+ // Plain JavaScript, not TypeScript: Node refuses to strip types from a
28
+ // file under node_modules, where this script is read from.
29
+ import { spawnSync } from "node:child_process";
30
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
31
+ import { tmpdir } from "node:os";
32
+ import path from "node:path";
33
+
34
+ function readInput() {
35
+ try {
36
+ return JSON.parse(readFileSync(0, "utf8") || "{}");
37
+ } catch {
38
+ return {};
39
+ }
40
+ }
41
+
42
+ const input = readInput();
43
+ // Hooks may start outside the project; Claude Code names it in the
44
+ // environment, and `cwd` on stdin is where the session is.
45
+ const projectDir = process.env.CLAUDE_PROJECT_DIR || input.cwd || process.cwd();
46
+ const sessionId = String(input.session_id ?? "unknown").replace(/[^A-Za-z0-9_-]/g, "_");
47
+ // Under the system temp directory, not the project: a file the hook left
48
+ // in the project would be a change git counts, and would move the very
49
+ // tree the verdict compares.
50
+ const startFile = path.join(tmpdir(), "nukadoko-verdict-hook", `${sessionId}.tree`);
51
+
52
+ // Only the project's own installed nuka: `npx nuka` without one would
53
+ // fetch a package from the registry inside a hook.
54
+ const nuka = path.join(projectDir, "node_modules", ".bin", process.platform === "win32" ? "nuka.cmd" : "nuka");
55
+ const configured = ["ts", "mts", "js", "mjs"].some((ext) => existsSync(path.join(projectDir, `nukadoko.config.${ext}`)));
56
+ if (!configured || !existsSync(nuka)) process.exit(0);
57
+
58
+ function verdict() {
59
+ const result = spawnSync(nuka, ["verdict", "--json"], { cwd: projectDir, encoding: "utf8", shell: process.platform === "win32" });
60
+ try {
61
+ return JSON.parse(result.stdout);
62
+ } catch {
63
+ return null;
64
+ }
65
+ }
66
+
67
+ if (input.hook_event_name === "UserPromptSubmit") {
68
+ const answer = verdict();
69
+ if (typeof answer?.working_tree === "string") {
70
+ mkdirSync(path.dirname(startFile), { recursive: true });
71
+ writeFileSync(startFile, answer.working_tree);
72
+ }
73
+ process.exit(0);
74
+ }
75
+
76
+ if (input.hook_event_name !== "Stop" || input.stop_hook_active === true) process.exit(0);
77
+
78
+ const answer = verdict();
79
+ // `refused` is a project nuka cannot read (a config that does not load):
80
+ // a hold would ask for something no run can give.
81
+ if (answer === null || answer.verdict !== "failed") process.exit(0);
82
+ const startTree = existsSync(startFile) ? readFileSync(startFile, "utf8").trim() : null;
83
+ if (startTree !== null && startTree === answer.working_tree) process.exit(0);
84
+
85
+ const open = (answer.findings ?? [])
86
+ .filter((finding) => finding.severity === "failed" || finding.severity === "error")
87
+ .map((finding) => {
88
+ const where = finding.file === undefined ? "" : ` ${finding.file}${finding.line === undefined ? "" : `:${finding.line}`}`;
89
+ return `- ${finding.code}${where}: ${finding.message}${finding.do === undefined ? "" : ` (do: ${finding.do})`}`;
90
+ });
91
+ const reason = [
92
+ startTree === null
93
+ ? "`nuka verdict` says no run speaks for this working tree yet:"
94
+ : "This turn changed the working tree, and `nuka verdict` says no run speaks for it yet:",
95
+ ...open,
96
+ "Before you say the change is done, run the criteria it touches and read the verdict table.",
97
+ "If you cannot run them, or a row stays red, end by naming each criterion that is unproven, failed, or not run, and why.",
98
+ ].join("\n");
99
+ process.stdout.write(`${JSON.stringify({ decision: "block", reason })}\n`);
@@ -0,0 +1,56 @@
1
+ # Answers a reviewer's five merge-risk questions from one run.json of
2
+ # `nuka run --base`, with what the run measured and nothing it guessed.
3
+ # references/merge-risk.md says how to read each answer and what stays
4
+ # unanswered.
5
+ #
6
+ # jq -r --argjson sensitive '["payments", "/admin/:id"]' \
7
+ # -f merge-risk.jq .nukadoko/runs/<run_id>/run.json
8
+ #
9
+ # `sensitive` is optional: the tables and routes this project treats as
10
+ # sensitive. nukadoko never guesses them from a name.
11
+
12
+ def sensitive: $ARGS.named.sensitive // [];
13
+ def base_paths: [.paths[]? | select(.between.kind == "base")];
14
+ # Every difference between the base and head, whatever explains it: a new
15
+ # criterion explains its own difference, which says nothing about its risk.
16
+ def changed: [base_paths[] | .criteria[] | . as $c | .steps[] | .changed[]
17
+ | . + {criterion: "\($c.feature):\($c.line)", explained_by: $c.explained_by}];
18
+ def new_at_head: select((.b.at_least // 0) > 0);
19
+ def plain: del(.a, .b, .criterion, .explained_by, .intent);
20
+ def listed(prefix; none): if length > 0 then prefix + join(", ") else none end;
21
+
22
+ if (base_paths | length) == 0 then
23
+ "This run has no paths against a base. Run `nuka run --base <ref>` and read its run.json."
24
+ else
25
+ "## Verification",
26
+ (.table.rows[] | "- \(.feature):\(.line) \(.name): \(.verdict)"),
27
+ (.limits[]? | select(.kind == "no-claim") | "- \(.feature):\(.line) judges no claim on a Then, so its verdict proves no outcome"),
28
+ "",
29
+ "## Alignment",
30
+ (.intent.rows[]? | "- INTENT.md row \(.row) (\(.target) | \(.observation) | \(.before) -> \(.after)): \(.result)"),
31
+ (changed | map(select(.explained_by == null and .kind != "request"))
32
+ | group_by(.criterion)[]
33
+ | "- declared nowhere, at \(.[0].criterion): " + (map(plain | tostring) | unique | join(", "))),
34
+ "",
35
+ "## Impact",
36
+ (changed | map(select(.kind == "db") | new_at_head | "\(.table) \(.op)") | unique
37
+ | listed("- tables touched differently at head: "; "- no table touched differently at head")),
38
+ (changed | map(select(.kind == "request") | new_at_head | "\(.method) \(.route)") | unique
39
+ | listed("- routes answered differently at head: "; "- no route answered differently at head")),
40
+ (changed | map(select((.table // .route) as $name | $name != null and (sensitive | index($name)) != null)
41
+ | "\(.table // "\(.method) \(.route)") \(.op // .status) at \(.criterion)") | unique
42
+ | listed("- sensitive: "; if (sensitive | length) == 0 then "- sensitive: no list given" else "- sensitive: none of the listed tables or routes" end)),
43
+ "",
44
+ "## Rollback cost",
45
+ (changed | map(select(.kind == "db" and (.op == "delete" or .op == "update")) | new_at_head
46
+ | "\(.table) \(.op) at \(.criterion)") | unique
47
+ | listed("- deletes and updates new at head: "; "- no delete or update new at head")),
48
+ "- not measured: schema changes, backfills, and effects outside the program's execution events",
49
+ "",
50
+ "## Error detection",
51
+ (.findings[]? | select(.code == "unexpected-failure") | "- unexpected failure at \(.file):\(.line)"),
52
+ (changed | map(select(.kind == "error" and .handled == false) | new_at_head | "\(.class) at \(.criterion)") | unique
53
+ | listed("- unhandled errors new at head: "; empty)),
54
+ (changed | map(select(.kind == "error" and .handled == true) | new_at_head | "\(.class) at \(.criterion)") | unique
55
+ | listed("- errors caught and passed over, new at head (whether each reached monitoring is not measured): "; empty))
56
+ end
@@ -0,0 +1,263 @@
1
+ ---
2
+ name: nukadoko-verification
3
+ description: Use when a project has, or is getting, a verification skill (a control CLI that drives the running app, plus a feature map of what the app does and how a user reaches it) and its claims need evidence that can be run again; when a bug report has to be reproduced before it is fixed; or when prototypes or the steps of a plan need one yardstick fixed before they are built. Adds nukadoko scenarios as the proof layer under the map. It does not replace the control CLI or the map.
4
+ compatibility: Requires the nukadoko npm package installed in the project (a devDependency), whose nuka CLI is run as `npx nuka`. Works beside a verification skill generated by pstack's create-verification-skill, or a hand-written one with launch, doctor, drive, evidence, and cleanup sections.
5
+ license: MIT
6
+ ---
7
+
8
+ # nukadoko under a verification skill
9
+
10
+ A verification skill lets an agent check its own work against the real
11
+ app. It has three parts, and nukadoko is one of them:
12
+
13
+ - **The control CLI** drives one long-lived instance of the app: doctor,
14
+ navigate, snapshot, screenshot, trace, flip a flag. It is for exploring
15
+ and debugging, and it keeps state between commands.
16
+ - **The feature map** is the project's memory of what the app does, how a
17
+ user reaches each feature, and what goes wrong there. Much of it is not
18
+ pass or fail (a tab hidden behind an entitlement, a focus trap), so it
19
+ stays prose.
20
+ - **The proof** is a nukadoko scenario for each claim that can pass or
21
+ fail, and the run that is its evidence, bound to a commit.
22
+
23
+ Write and run scenarios by the nukadoko skill (`nukadoko/` beside this
24
+ one, under `nuka skill path`). This file says where scenarios attach to
25
+ the map, how the control CLI and the steps share code, and when to reach
26
+ for a scenario at all.
27
+
28
+ ## 1. Where an expected value comes from
29
+
30
+ The map is written by walking the app, and that is right for the map. A
31
+ Then is different: written from what the program printed, it grades the
32
+ implementation against itself.
33
+
34
+ - Take every expected value in a Then from a promise the project already
35
+ made: the README, the docs, help text, wording a design document fixes,
36
+ or the report being reproduced.
37
+ - A value no source states goes in the map's gotchas as unsettled, and
38
+ becomes a question for a person. It never becomes a Then.
39
+ - The map's own "what you see" lines may be corrected from what the app
40
+ does. A Then may not.
41
+ - A Then declares claims, and its step record names where each expected
42
+ value came from (`sentence:`, `from:`, `literal:`, or `observe:`).
43
+ Every `sentence:` and `literal:` value traces to one of the sources
44
+ above.
45
+ - A failure the program shows underneath a step is judged too: a 5xx
46
+ response, an uncaught page error, or an `error` it reports with
47
+ `handled: false` turns a passed scenario's cell `broke`
48
+ (`unexpected-failure`). A scenario of an error path a source promises
49
+ (a maintenance page, a declined card) names the failure it causes with
50
+ `@expects:status=<500-599>`, `@expects:page-error=<name>`, or
51
+ `@expects:error=<class>`, from that source, never from what the run saw.
52
+ - One exception: when the requirement is "behave exactly as before" (a
53
+ migration that must keep every behavior, bugs included), the earlier
54
+ behavior is the source. Say so in the `Feature:` description, so a
55
+ reader knows why a Then was written from output.
56
+
57
+ ## 2. Linking the map to scenarios
58
+
59
+ Keep the map's own sections. End each sub-feature line with the scenario
60
+ that proves it, or with `no scenario`:
61
+
62
+ ```markdown
63
+ - `create-save` persists a title and body. Proof: `features/notes.feature:12`
64
+ - `create-cancel` discards an unfinished draft. Proof: no scenario
65
+ ```
66
+
67
+ A link is a `<file>:<line>` that `nuka run` accepts, so a reader can run
68
+ the proof the line names. `no scenario` is an honest gap: those
69
+ sub-features are the ones a person or an agent still drives by hand.
70
+
71
+ Scenarios for the product's core path live in `featuresDir` and run on
72
+ every commit. A scenario written for one change stays in a directory named
73
+ in `additionalFeatureDirs` until someone decides it is core.
74
+
75
+ ## 3. The control CLI and the steps
76
+
77
+ Write each action and each read once, as a function in a library the steps
78
+ already import (for example `features/steps/lib/`). A step declares its
79
+ contract and calls one function; the control CLI calls the same function.
80
+ A Then's `observe` calls a read, and its claims judge what the read
81
+ returned; the CLI prints what the same read returns.
82
+ For what a page shows, the read returns the locator (or the page), and the
83
+ Then claims `fits-aria-snapshot` on it against a docstring that names roles
84
+ and names, so nukadoko takes the ARIA snapshot; the CLI's `snapshot` command
85
+ prints the same locator's `ariaSnapshot()`. That print is output, so it
86
+ explores the page and never becomes the expected tree (section 1).
87
+ Keep the library under the features tree and let the CLI import it: steps
88
+ that import from the agent's skill directory make the acceptance suite
89
+ depend on it.
90
+
91
+ How a step reaches the CLI's instance depends on its handle:
92
+
93
+ - **The handle is a value** (a project directory, a URL with its own data,
94
+ a record id). Pass it in `--args`, and `nuka do <step> --args '<json>'`
95
+ runs one step against the state the CLI built; `--use` chains the next
96
+ step from that record. The CLI needs no table of commands that mirrors
97
+ the steps: one pass-through command (`cli <instance> -- <argv>`) is
98
+ enough.
99
+ - **The handle is live** (a browser with open tabs and half-typed input).
100
+ `nuka do` starts clean on every call, so it cannot reach it. The CLI
101
+ owns the browser: start it with a remote debugging port and reconnect
102
+ over CDP for each command. Name the CLI's commands after the steps that
103
+ call the same functions, and prove per-connection settings (scripts
104
+ turned off) with a scenario, since they do not survive a reconnect.
105
+
106
+ Either way, run whole scenarios against the CLI's instance: read `url`
107
+ in `nukadoko.program.ts` from an environment variable whose name no
108
+ production tool reads, and have the CLI's `scenario` command set it and
109
+ run `nuka run --json`. A program each run may start fresh goes in `serve`
110
+ there instead, with its state under `{dir}`.
111
+
112
+ A library function that starts a program calls `runCommand` from
113
+ `nukadoko`. Inside a step the process lands on the step record
114
+ (`observed.processes`); called from the CLI it runs the same way,
115
+ unrecorded. Inside a step on POSIX it also runs in a process group and a
116
+ session of its own, so a tool that prompts on the terminal has none there,
117
+ and the step's events are whole only once nothing of its group still runs.
118
+ A program the library starts through `node:child_process`
119
+ instead is only named in the step's `observed.unmeasured`, by its
120
+ program and argument count, with nothing of what it printed or changed. `runCommand` records the full argv, and
121
+ only values loaded from env files or named in `redact` are redacted, so
122
+ pass a token through `env`, never as an argument. The record names every
123
+ variable in `env` but shows a value only when it is an absolute path that
124
+ exists, a decimal integer, or `true` or `false`. When the run has a
125
+ world, the process also gets `TRACEPARENT`, the step's trace context
126
+ (its entry's `traceparent`), unless the step set its own: a tool that
127
+ copies it into the `traceparent` header of its requests makes the
128
+ program's log lines and execution events for them the step's.
129
+
130
+ ## 4. Doctor and readiness
131
+
132
+ `serve.ready` in `nukadoko.program.ts` treats a server as ready once one
133
+ path answers 2xx, and nothing more. Usable is the control CLI's `doctor`: the
134
+ port is ours, the build is the expected one, the data is seeded. For a
135
+ command-line tool, usable is the tool's own startup check (`--version`
136
+ exits 0 on this runtime) and a checkout that has not changed since the
137
+ instance was built. Call the same check from the environment's `version`
138
+ probe, so a run against an instance that is up but not usable fails before
139
+ its first step, with the reason.
140
+
141
+ ## 5. Evidence that outlives cleanup
142
+
143
+ Retention removes old run directories (the newest `retention.runs` stay),
144
+ and `nuka clean` removes all of them. Evidence for a pull request leaves
145
+ the run directory:
146
+
147
+ ```sh
148
+ npx nuka report "$(npx nuka run --json | jq -r .run_dir)" --format markdown --out <evidence dir>/summary.md
149
+ ```
150
+
151
+ `run_dir` in run.json is the run directory; `environments[].base_url`
152
+ names the instance the run judged, so the evidence says which one it was.
153
+ The summary's `seen` links (such as `steps/<id>/judged/page.png`, a Then's
154
+ page right after the reading it judged) are relative to the run directory:
155
+ copy each file they name into the evidence directory at the same path, or
156
+ they lead nowhere there.
157
+
158
+ or reaches the pull request through CI's run summary (`docs/ci.md` in the
159
+ package). The control CLI's own evidence goes beside it: screenshots and
160
+ accessibility snapshots for a web app; for a command-line tool, a
161
+ transcript of argv, exit code, stdout, and stderr, and a diff of the files
162
+ each command wrote. A step that runs the tool through `runCommand`
163
+ gets that diff measured: each process lists the files added, changed,
164
+ and removed under its working directory (`observed.processes[].files`),
165
+ and the step's `observed.files` lists what changed in its scratch
166
+ directories, with the content. A scenario that claims what the tool wrote
167
+ ("writes nothing", "changed no file under src/") reads that list through a
168
+ claim step's `files` (`skills/nukadoko/references/parts.md`), never
169
+ through a list the step returns. Confirm the evidence exists after the verification skill's cleanup
170
+ has run.
171
+
172
+ ## 6. Reproducing a report
173
+
174
+ 1. Restate the report as requirements
175
+ (`skills/nukadoko/references/from-prose.md`). An unstated slot is a
176
+ question back to the reporter, not a guess.
177
+ 2. Write the scenario from those requirements, before any fix.
178
+ 3. Run it on the base branch. Red reproduces the report; for a report of
179
+ a server error or a page that throws, red can be an
180
+ `unexpected-failure` over claims that all held. Green means the
181
+ scenario does not say what the report says, or the report is about
182
+ something else: ask. Do not edit the Then until it goes red.
183
+ 4. Fix, run again, and open the pull request with
184
+ `nuka run --base <base>`: the new criterion runs against the base's
185
+ code too, and its row is `proven` when its Then fails there in each of
186
+ `--proof-runs` runs. When the program writes execution events, the
187
+ summary's "Changed paths" says under `base → head` what the program
188
+ did differently at head, step by step, and lists first each unchanged
189
+ criterion that did something else, which no sentence asks for: read
190
+ those before calling the fix contained. Before you call it fixed,
191
+ `nuka verdict` says whether that run judged the tree you have and left
192
+ nothing red (`skills/nukadoko/references/done.md`).
193
+ 5. Link the scenario from the map's sub-feature.
194
+
195
+ When the scenario and the program file live in the product's repository,
196
+ `nuka run --base <the commit before the fix>` shows red before and green
197
+ after in one run: the base world builds the base's code from its program
198
+ file. When the scenario lives outside the product's repository, `--base`
199
+ compares the scenario project's commits, not the product's, so showing
200
+ both takes two checkouts: put the commit before the fix and the fix commit
201
+ in separate worktrees and run the same scenario against each. The run's
202
+ `commit` is then the scenario project's; bind the evidence to the product
203
+ by returning the product's `git rev-parse HEAD` from the environment's
204
+ `version` probe, which the summary shows as the target version.
205
+
206
+ When the fix sits behind a switch the program reads (a flag, a setting),
207
+ one run shows both sides instead: declare the switch in `conditions` on
208
+ two environments of `nukadoko.program.ts` and tag the scenario
209
+ `@with:<switch>`, so the side without the fix is a control. The verdict
210
+ table reads `proven` when the Then breaks there at the same line in each
211
+ of `--proof-runs` runs, and `held` when it passes there, which says what
212
+ green on the base branch says: the scenario does not say what the report
213
+ says (`skills/nukadoko/references/verdicts.md`). When the program writes
214
+ `flag` execution events, run.json's `flags` names the side each cell's
215
+ steps got: a control listed only under the side with the fix never ran the
216
+ side without it. When the two environments' `conditions` differ in that one
217
+ switch alone, run.json's `paths` and the summary's "Changed paths" say what
218
+ the program did differently, step by step, on the side with the fix.
219
+
220
+ ## 7. Prototypes and plan steps
221
+
222
+ - Before two or three prototypes are built, write the scenarios they must
223
+ all pass, and run the same scenarios against each. The run decides which
224
+ meet the criteria; the control CLI's screenshots and traces compare the
225
+ rest. Criteria written per prototype after the fact measure each one
226
+ with its own ruler.
227
+ - A plan whose steps each end in a check can name a scenario as the check.
228
+ The step is done when its scenario is green on the commit that lands it.
229
+
230
+ ## 8. Keeping the map honest
231
+
232
+ - `nuka check`: a step or a binding broke, a line needs a state no
233
+ earlier line leaves (`state-missing`), and, with no target, notes on
234
+ steps and fixtures that are rotting.
235
+ - `nuka run`: a sub-feature with a scenario no longer does what the map
236
+ says. Red is map drift or a product regression; decide which before
237
+ editing anything, and never edit a Then to match the product. A `held`
238
+ row whose control passed is a scenario that no longer tells its switch
239
+ apart.
240
+ - `nuka run --order shuffled`: a scenario that passes only on what an
241
+ earlier scenario left in the instance they share. A red one's `do:` line
242
+ replays the scenarios that ran before it in that order. Red again there
243
+ is an order dependence, fixed by a scenario that stands alone, never by a
244
+ fixed order.
245
+ - `nuka run --base <ref>`: which criteria changed since the map was last
246
+ checked, and, when the steps changed, whether an unchanged one still
247
+ means what it meant (a `moved` row says it does not).
248
+ - `nuka run` with `lists` in the program file: the routes the program
249
+ has that no scenario requested ("Routes" in the summary, `routes` in
250
+ run.json; `skills/nukadoko/references/verdicts.md`). A route no
251
+ scenario requested is a place the map may be missing; a requested one
252
+ is not yet a checked one.
253
+ - `nuka run` with a `tables` list in the program file: a count of
254
+ writes that names no table counts the tables that hold state, and its
255
+ line names the bookkeeping and infrastructure writes it left out; the
256
+ note `undeclared-write` names a step declared `mutates: false` whose
257
+ trace the program says wrote state
258
+ (`skills/nukadoko/references/diagnosing.md`). Either is a question for
259
+ the person, not a Then to edit.
260
+
261
+ What remains for a pass that drives the app by hand is the sub-features
262
+ marked `no scenario`, the routes no scenario requested, and features
263
+ missing from the map.