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,120 @@
1
+ ---
2
+ name: nukadoko
3
+ description: Use when turning a requirement into a Gherkin scenario and the run that is its evidence, for a person to review, starting from whatever is on hand, whether that is raw prose with no stated acceptance criteria yet (a ticket, a request, a conversation), acceptance criteria that still need concrete scenarios, a scenario ready to write, a path already explored one `nuka do` call at a time and now worth fixing in a scenario, a browser app whose state cannot be repeated and has to be explored through a Playwright MCP server first, or a scenario a person wants to walk one step at a time, the run paused after each step while the agent explains its record and waits for the person's answer.
4
+ compatibility: Requires the nukadoko npm package installed in the project (a devDependency), whose nuka CLI is run as `npx nuka`; the loop below shells out to it (nuka init, nuka steps, nuka describe, nuka scaffold, nuka do, nuka check, nuka run, nuka step, nuka verdict, nuka judge).
5
+ license: MIT
6
+ ---
7
+
8
+ # nukadoko acceptance loop
9
+
10
+ A person approves a change by reading the feature file and the run
11
+ summary: the run is the evidence, and where the approval is recorded is
12
+ the team's process. The feature is written before the implementation it judges,
13
+ from the criteria and never from the program's output, which is what
14
+ makes a green run evidence rather than agreement. This file is the order
15
+ of work: open the reference a step names when you reach it.
16
+ `node_modules/nukadoko/llms.txt` names every command, flag, and code.
17
+
18
+ ## Before the first command
19
+
20
+ Say in two or three sentences what the loop is for and what it will
21
+ touch, then one line for each of these that applies:
22
+
23
+ - A `mutates: true` step that reaches past the project (a real service, a
24
+ shared database, a file outside `scratch`) gets a go-ahead before its first
25
+ `nuka do`, once, not on every retry. A step that writes only under `scratch`,
26
+ or only to a server a fixture or `nukadoko.program.ts` started, needs none
27
+ (`references/writing-steps.md`, "Asking before a step changes something").
28
+ - A step that needs `page`, `context`, `pageAs`, or `request` needs the project's
29
+ own `playwright`; `nuka check` reports `playwright-missing` with the
30
+ install line. Adding it is a dependency change: ask first. A `page` step
31
+ makes `nuka run` open a browser and take minutes. A project on e2e
32
+ drives it through e2e instead (`references/fixtures.md`, last section).
33
+ - A Playwright MCP server, when the loop explores a browser app whose
34
+ state cannot be repeated, drives the real application with whatever
35
+ login it holds. A click that submits something there needs the same
36
+ go-ahead (`references/exploring.md`).
37
+
38
+ Run-time output lands under `.nukadoko/`, gitignored, and can hold
39
+ credentials in plaintext. nukadoko makes no outbound calls of its own and
40
+ never commits, pushes, or publishes. Keep the narration short.
41
+
42
+ ## Where to start
43
+
44
+ Run `nuka` from the directory that holds the config, and `nuka init` first
45
+ when there is none (`references/running.md`, "Setting up"); an app to start
46
+ needs `nukadoko.program.ts` (`references/program.md`). A Ruby project
47
+ writes steps as the "Ruby" section of `llms.txt` says. Pick one line:
48
+
49
+ 1. **Prose only** (a ticket, a request, a conversation):
50
+ `references/from-prose.md`, then line 2.
51
+ 2. **Criteria sentences, no scenario yet**: `references/scenario-rules.md`
52
+ and `references/writing-the-feature.md`, then the loop.
53
+ 3. **A concrete scenario, or one you can write directly**: the loop.
54
+ 4. **A path already run** with `nuka do` or a Playwright MCP server:
55
+ write the scenario from what you ran (`references/exploring.md`, "Then
56
+ fix what you found"), then the loop at step 3.
57
+ 5. **A browser app whose state cannot be repeated** (an account that
58
+ opens once): drive it through the host's Playwright MCP server,
59
+ connected when its `browser_*` tools are listed; a Claude Code host
60
+ adds it with `claude mcp add playwright npx @playwright/mcp@latest`
61
+ once the person agrees. Then line 4 (`references/exploring.md`,
62
+ "Exploring state that cannot be repeated").
63
+ 6. **A scenario the person wants to check step by step with you**: walk
64
+ it with `nuka run <file>:<line> --step` (`references/reviewing.md`).
65
+
66
+ If none is true, ask what this is supposed to do before writing anything.
67
+
68
+ ## The loop
69
+
70
+ 1. **Feature first.** Write the `.feature` from the criteria, by
71
+ `references/scenario-rules.md`, and copy the criteria verbatim under
72
+ `Feature:` (`references/writing-the-feature.md`). Every expected value
73
+ is one the criteria state; a value they do not state is a question for
74
+ a person, not a guess and not a value read off the program.
75
+ 2. **Steps.** `nuka steps` lists the vocabulary, `nuka describe <step>` one
76
+ contract; reuse before scaffolding. `nuka scaffold --feature <file>` stubs
77
+ each undefined line and prints each stub's own `nuka scaffold ...
78
+ --replace` line. Redo the When that runs a program or sends a request, and
79
+ the Thens that read it, from those lines with `--description`, `--command
80
+ <entry point>` (`--cwd`, `--argv`) or `--request "<METHOD> <path>"`, and
81
+ `--from <step>.<key>` per value an earlier step returns (its producer has
82
+ to return that key already). A step that needs only what an earlier line
83
+ did `requires` the state that line's step `gives` (`references/states.md`).
84
+ A Then declares `claims`, never `run` (`references/checking-steps.md`). Run
85
+ each alone with `nuka do <step> --args '<json>'`
86
+ (`references/writing-steps.md`). Finished projects: `references/examples/`.
87
+ 3. **`nuka check <feature>`.** Fix every error and read every warning: a
88
+ warning is a question about intent, not noise. Each finding names its
89
+ file, a `fix:` (an edit) or `do:` (a command) line; apply or run it.
90
+ 4. **`nuka run <feature>`** until no table row is `failed`, reading the step
91
+ record a failure names first (`references/diagnosing.md`), then once more
92
+ with `--order shuffled` (`references/running.md`). A red Then, an
93
+ `unexpected-failure`, or a `held` row whose control passed
94
+ (`references/verdicts.md`) is fixed in the code or by asking the person,
95
+ never by weakening it or tagging it away. Read "What this run does not show",
96
+ `measured: none` (`references/reviewing.md`), `undeclared-write`, and each `judgment-` finding (`references/judgments.md`).
97
+ 5. **Commit before the run you report**, push, and open the pull request;
98
+ CI posts the summary of `nuka run --base <the base>` (`docs/ci.md`). Run
99
+ it first: `unproven`, `moved`, and `intent-` findings are red
100
+ (`references/verdicts.md`, and `INTENT.md` in `references/done.md`).
101
+ 6. **Decide where the feature lives**, in the same pull request: the
102
+ product's core path moves into `featuresDir`, which `nuka run` runs on
103
+ every commit; a feature for one change stays outside it, named in
104
+ `additionalFeatureDirs` (`references/maintenance.md`).
105
+
106
+ A lesson from a run becomes an example row, then a rule, then a finding
107
+ code (`references/scenario-rules.md`, "How this file grows").
108
+
109
+ ## What not to do
110
+
111
+ - Don't write a Then from what the program printed, or edit one after a red
112
+ run without the person's word: either is the implementation grading itself.
113
+ - Don't fill in a requirement the source never stated (`references/from-prose.md`).
114
+ - Don't run a step that reaches past the project without a go-ahead, and
115
+ don't keep fixing one step past three cycles: report where it stands. A
116
+ prompt that gives a different budget overrides the three.
117
+ - Don't hand-edit a step record or a run summary: it was measured, and
118
+ editing it turns it back into an unmeasured account.
119
+ - Don't act unasked on a note about a step you are not writing:
120
+ report it (`references/maintenance.md`).
@@ -0,0 +1,200 @@
1
+ # A Then that claims
2
+
3
+ ## The shape
4
+
5
+ A Then judges, never in code: its step declares `claims` in place of `run`,
6
+ naming the value it reads, how it compares it, and where its expected value
7
+ comes from. nukadoko compares, and the step record keeps each claim with both
8
+ values and their sources. A typed Then never calls `expect` or `node:assert`.
9
+ `defineStep` refuses a claim step that also declares `run`, `returns`,
10
+ `mutates`, or `parts`. `nuka check` refuses a Then bound to a step that runs
11
+ (`then-without-claims`) and a claim step in a Given or a When
12
+ (`claims-outside-then`): a step that reads a value for a later Then is a When.
13
+
14
+ ```ts
15
+ import { defineStep, z } from "nukadoko";
16
+ import runTally from "./run-tally.ts";
17
+
18
+ export default defineStep({
19
+ pattern: "it exits with {code:int}",
20
+ args: z.object({
21
+ code: z.number().describe("The expected exit code"),
22
+ exitCode: runTally.returns.shape.exitCode,
23
+ }),
24
+ from: { exitCode: [runTally, "exitCode"] },
25
+ claims: [{ actual: "exitCode", compare: "equal", expected: "code" }],
26
+ });
27
+ ```
28
+
29
+ A claim is `{ actual, view?, at?, count?, compare, expected, expected_view? }`.
30
+ `nuka scaffold --then --from <step>.<key>` writes this shape when the
31
+ line states one value (for a word such as `empty`, the literal of the
32
+ chained key's type); `examples/` has a finished Then for a CLI, an API,
33
+ and a workflow (`examples/workflow.md` claims a literal and a sentence
34
+ value in one step). Write claims as plain data (no getter, Proxy, class
35
+ instance, hole, or unknown key) and export what `defineStep` returned: it
36
+ validates one frozen copy, and a copy of the step (`{ ...step }`) fails.
37
+
38
+ ## Where the expected value comes from
39
+
40
+ Pick the source from the sentence; the record names it in `expected_from`.
41
+
42
+ - **The sentence states it** (a capture, the docstring, or the table):
43
+ `expected: "code"`, recorded as `sentence:code`. The key is required in
44
+ `args`, with no default, and its schema must not rewrite the value
45
+ (`z.coerce`, a transform, a pipe, `trim`, `catch`, a default inside, or a
46
+ refine on an object, an array, or the args object is refused; a schema that
47
+ still changes it leaves the claim `unjudged`). Read it as JSON, lines, or a
48
+ comma list with `expected_view` on a `z.string()` key. With no `observe`, a
49
+ claim reads each value the line states: an unread capture is refused, an
50
+ unread docstring or table `claim-sentence-unread`.
51
+ - **An earlier step returned it** ("the item count is unchanged"): `expected:
52
+ { from: "<from key>.<path>" }`, recorded as `from:<step>@<line>.<key>`.
53
+ - **The pattern's fixed words state it** ("is refused", "exits 0"):
54
+ `expected: { literal: "refused" }`, or `compare: "is-a", expected: {
55
+ literal: "UUID" }` for "the order id is a UUID". The literal is exactly the
56
+ pattern's own words, `zero` to `twelve` as a number word, `once`, or `twice`
57
+ (any compare), or `0`, `""`, or `[]` for `no`, `none`, `nothing`, or
58
+ `neither` (`0` for `never`, `""` or `[]` for `empty`) with `compare: "equal"`
59
+ only, or `"not-equal"` only right after the fixed word `not`, `neither`, or
60
+ `nor` ("is not empty"). A `neither` that a `nor` follows states nothing. Any
61
+ other literal is refused: `Then the command succeeds` cannot claim `0`.
62
+ - **A second reading** ("A is listed before B"): `expected: { observe:
63
+ "<path>" }`, a value `observe` returned beside the actual one.
64
+
65
+ ```ts
66
+ import { defineStep, z } from "nukadoko";
67
+ import countItems from "./count-items.ts";
68
+
69
+ export default defineStep({
70
+ pattern: "the item count is unchanged",
71
+ args: z.object({ before: countItems.returns.shape.count }),
72
+ from: { before: [countItems, "count"] },
73
+ async observe({ request }) {
74
+ return { items: await (await request.get("/items")).json() };
75
+ },
76
+ claims: [{ actual: "items", count: true, compare: "equal", expected: { from: "before" } }],
77
+ });
78
+ ```
79
+
80
+ ```ts
81
+ import { defineStep, z } from "nukadoko";
82
+
83
+ export default defineStep({
84
+ pattern: "{first:string} is listed before {second:string}",
85
+ args: z.object({
86
+ first: z.string().describe("The title expected first"),
87
+ second: z.string().describe("The title expected after it"),
88
+ }),
89
+ async observe({ page }, { first, second }) {
90
+ const titles = await page.locator(".result h2").allTextContents();
91
+ // A title that is not there is undefined, and an undefined value breaks the claim.
92
+ const at = (title: string) => (titles.includes(title) ? titles.indexOf(title) : undefined);
93
+ return { firstAt: at(first), secondAt: at(second) };
94
+ },
95
+ poll: { timeout_ms: 5000 },
96
+ claims: [{ actual: "firstAt", compare: "less-than", expected: { observe: "secondAt" } }],
97
+ });
98
+ ```
99
+
100
+ ## The actual value
101
+
102
+ `actual` is a path whose first segment is a `from` key or a key `observe`
103
+ returns, or an `events` key (`program.md`) or a `files` key (`parts.md`) alone,
104
+ never a key the sentence fills (a `from` key hides an `observe` key of its name,
105
+ so a step whose claims read no `observe` key is refused); a path reads own
106
+ properties only (not `constructor`, not a getter). `view: "text"` trims the end
107
+ (a program's last newline), `"lines"` also splits it into lines, `"json"` parses
108
+ it, and `"comma-list"` splits it at commas; `at` then takes a path inside the
109
+ viewed value, so parsing is data: `{ actual: "stdout", view: "json", at:
110
+ "sections.git.0.dirty_count", compare: "equal", expected: "count" }`. `count:
111
+ true` then compares the number of items of the array there, with a number
112
+ compare only (`at-least` the literal `1` for "at least one row"), and breaks on
113
+ a value that is not an array. `{ actual, each: { where?, claims } }` applies
114
+ item claims to every item of an array (paths inside are relative to the item),
115
+ and breaks when the array, or what `where` selects, is empty. A `where` claim
116
+ whose path starts an item claim's, or the reverse, is refused with `equal`,
117
+ `has-same-items`, `has-fields`, `lacks-field`, `fits-text`, `is-a`, `has-item`,
118
+ `matches`, `contains-text`, `starts-with-text`, or `ends-with-text`, and breaks
119
+ the claim where it implies it.
120
+
121
+ The compares: `equal` (structural), `not-equal`, `contains-text`,
122
+ `starts-with-text`, `ends-with-text`, `has-item`, `has-same-items` (in any
123
+ order), `has-fields` (the expected fields at any depth, each array whole),
124
+ `lacks-field` (no key of the expected name: "has no password field" is
125
+ `expected: { literal: "password" }`, and a field set to `null` is a key),
126
+ `fits-text` (line by line; a line `...` is any lines, `[..]` any text in its
127
+ line, `[..:id]` too, one text per name, no two alike), `is-a` (a kind: a JSON type, `integer`, `uuid`, `date`, `timestamp`,
128
+ `url`), `fits-aria-snapshot` (a page by role and name, below), `matches`,
129
+ `greater-than`, `at-least`, `less-than`, `at-most`, and `judged-as` for a
130
+ quality only a reader can judge (`judgments.md`). A JSON docstring (`expected_view: "json"`)
131
+ claims a whole response with `equal` (a field it leaves out breaks it, a `null` one too) or some of its fields with
132
+ `has-fields`; output that changes each run takes `fits-text`, never `{ from }`
133
+ or `{ observe }`. Two values of different JSON types break the claim (`is-a` and
134
+ `lacks-field` aside), and so does an expected value nearly every value holds (a
135
+ blank text or field name, a pattern matching `""`, an object with no field, only
136
+ stand-ins). Each side is a plain JSON copy, and `observe` gets a clone of
137
+ its inputs; a `Date`, a bigint, `NaN`, an `undefined` item, a `Proxy`, or
138
+ nesting past 256 levels leaves the claim `unjudged` (return an ISO string or a
139
+ number). Each claim or item the step's deadline cuts off, a running `matches`
140
+ included, is `unjudged`, with how many. So is a claim that a key `returns`
141
+ dropped could break. `nuka check` reports a `from` path `returns` lacks or
142
+ `args` drops (`claim-path-unknown`, `claim-args-dropped`), a `lacks-field`
143
+ on a field `returns` drops (`claim-field-stripped`), a count or `each` on a
144
+ non-array (`claim-not-an-array`), sides at one place (`claim-compares-itself`),
145
+ an `is-a` capture naming no kind (`claim-kind-unknown`), and a transformer on
146
+ an expected key (`claim-expected-transformed`).
147
+
148
+ ## Observe, poll, and a boolean
149
+
150
+ `observe(fixtures, args)` reads the world when no earlier step returned the
151
+ value. It gets every args key but the ones a claim compares with, or the `from`
152
+ key of an actual compared with `{ observe }`, and reading one, or calling
153
+ `resultOf`, throws: an earlier step's value reaches a claim through `from`
154
+ alone. A throw records `unobserved`. Return what you measured, never a verdict:
155
+ a text, a number, a list (a claim with `count: true` counts it, so return the
156
+ list, not its length). A boolean literal is refused when the actual value comes
157
+ from `observe`, since `{ visible: true }` is the judgment made in code. For a
158
+ yes or no in the sentence, return the word it uses
159
+ (`outcome: "accepted" | "refused"`, `examples/workflow.md`), or the measurement
160
+ behind it. Give every `args` and `returns` field of a step you write or rewrite
161
+ a `.describe()`, so `nuka describe` connects a criterion's wording to the field
162
+ that answers it; a note on a step you are not changing is a report.
163
+
164
+ `poll: { timeout_ms }` runs `observe` every 100 ms until every claim holds on
165
+ two readings in a row, then judges the last; `readings` keep what each read. A
166
+ Then whose `observe` reaches `page`, `context`, or `pageAs` states `poll` or
167
+ `poll: false` (`claim-poll-unstated`). A broken poll waits out its timeout,
168
+ unless `settled: [{ actual, compare, expected: { literal } }]` names a state the
169
+ page cannot leave once reached (no busy element): two readings in a row in it
170
+ with a claim broken stop the poll, and it never makes a claim hold.
171
+
172
+ **One step per claim, or the expected value in the line?** Let the sentence a
173
+ non-engineer agreed to decide: "the total is {expected:int}" carries its value,
174
+ so it is one step; "is in trial" and "is not in trial" are two steps.
175
+
176
+ ## A page by role and name
177
+
178
+ A When may still wait with Playwright's `expect` before it acts (outside
179
+ `playwright test`, on Playwright 1.61.1, a failing `expect.soft` throws at once,
180
+ and `toMatchAriaSnapshot`, `toHaveScreenshot`, and `toMatchSnapshot` throw
181
+ `"<name>() must be called during the test"`). For what a page shows, a Then
182
+ returns the page or a locator from `observe` and claims `fits-aria-snapshot`
183
+ against the docstring (the one required `args` key no capture or `from` fills);
184
+ nukadoko takes the ARIA snapshot, and the record keeps it whole:
185
+
186
+ ```ts
187
+ import { defineStep, z } from "nukadoko";
188
+
189
+ export default defineStep({
190
+ pattern: "the scores form shows",
191
+ args: z.object({ tree: z.string().describe("Part of the form's ARIA snapshot") }),
192
+ observe: ({ page }) => ({ form: page.getByRole("form", { name: "Scores" }) }),
193
+ poll: { timeout_ms: 5000 },
194
+ claims: [{ actual: "form", compare: "fits-aria-snapshot", expected: "tree" }],
195
+ });
196
+ ```
197
+
198
+ The docstring states part of the tree (`writing-the-feature.md`). A name between
199
+ slashes, `[active]`, and a tree that names nothing are refused
200
+ (`claim-aria-snapshot-unreadable`, `claim-aria-snapshot-names-nothing`).
@@ -0,0 +1,200 @@
1
+ # Diagnosing a failed run
2
+
3
+ ## A command that refused
4
+
5
+ A command that stopped before it ran anything exits 2, not 1, and prints one
6
+ `refused` finding with a code, such as
7
+ `refused\ttarget-not-found\t-\t<message>`; under `--json` it is in the
8
+ envelope's `findings`, and `verdict` is `refused`. Make the edit its `fix:` line
9
+ names, or run its `do:` line, before you guess at a fix: the `do:` is the step
10
+ list for an unknown step name, the install line for a missing package, or the
11
+ command's own `--help` for a flag it does not accept.
12
+
13
+ ## Work through the failed step first
14
+
15
+ `nuka run`'s stderr already names where to start: under the failed step's
16
+ `failed` line, the first line of its error and the path of its step record
17
+ (`record <stateDir>/runs/<run_id>/steps/<id>`), and after the summary, a
18
+ `failed\tscenario-failed\t<file>:<line>\t<name>: <error>` finding per
19
+ failed scenario, whose ` do:` line runs that scenario alone.
20
+ The same list is in the run's `run.json` (`nuka run --json` prints it):
21
+ each entry of `scenarios` with `status: "failed"` names its `do` command,
22
+ and its failed step names its `line`, its `error` (`kind`, `message`),
23
+ its step `record`, and the `used` results it read (a large one cut to a
24
+ preview marked `truncated`; the producer's `record` holds it whole).
25
+ When the failed step read from a step whose program exited nonzero, a
26
+ `used <step> exit <code> <first stderr line>` line sits between the
27
+ two: a Then that claimed against an empty stdout usually broke there, because
28
+ the program did not start (a missing build, a missing dependency, a `.js`
29
+ import of a `.ts` file under `node`), and the step that ran it passed.
30
+ When that program was Node and it crashed, the line shows the `Error:`
31
+ line, not the location Node printed above it. A program that wrote its
32
+ refusal on stdout and nothing on stderr (as under `--json`) shows
33
+ `stdout: ` and what it printed there.
34
+ A Then that failed with `claim_broken` prints its claim line: both
35
+ values and where each came from. Check that the actual value's source is
36
+ the thing the criterion means before you suspect the implementation; the
37
+ step record's `claims` give each claim's `measured`, the channel that
38
+ holds the raw value. `unobserved` means `observe` threw, so no claim was
39
+ judged. A claim step's `timeout` leaves each claim `unjudged`, beside the
40
+ readings read before the deadline. `claim_unjudged` means nukadoko itself failed while judging (its
41
+ reason names the failure): nothing is known about that criterion yet. Open that path's `record.json` rather than
42
+ searching the records directory.
43
+
44
+ Before repeating `nuka run <feature>`, read the failed step's own step
45
+ record in this order. The sections below are how to read the items that
46
+ need more than a glance.
47
+
48
+ 1. Its `used` entries: each carries the full validated `result` of the upstream
49
+ step it read from, sitting right on the step record that failed.
50
+ 2. `actions`, then the rest of the timeline ("Reading a step record as a
51
+ timeline"): every Playwright call this step made through the `page` fixture,
52
+ `expect` waits included, each with its own duration and outcome.
53
+ 3. `page_events`, if the step opened a browser: a console error, an
54
+ uncaught page error, or a failed request recorded there can explain a
55
+ failure nothing else on the step record mentions.
56
+ 4. `program-log.txt` beside the record, when `observed.program_log` names it,
57
+ and `program-log-late.txt` when the run summary names one: the lines the
58
+ program under test wrote for this step's own requests, such as the error
59
+ behind a 500, and `events.jsonl` when `observed.events` names it: each
60
+ statement, job, and call it made (`program.md`).
61
+ 5. `nuka do <step> --use <upstream-step-record-id>` when the record
62
+ sharpens a hypothesis rather than confirming it ("Testing a hypothesis
63
+ without a full re-run").
64
+ 6. Re-run the scenario last, with the `do:` line `nuka run` printed, once the
65
+ step itself passes under `do`, not as the first thing tried after a failure.
66
+
67
+ ## Reading a broken claim
68
+
69
+ ```text
70
+ claim broken: "food: 5.5\nrent: 100" (from:run-tally@16.stdout as text) equal "food: 5.5\nrent: 101" (sentence:expected); first difference at line 2: actual "rent: 100", expected "rent: 101"
71
+ ```
72
+
73
+ The actual value and its source, the compare, the expected value and its source,
74
+ then where the two part. A broken `has-same-items`, or `equal` on two lists with
75
+ an item inserted or removed, names the expected items that are missing and the
76
+ actual items that are extra, each with its index on its own side
77
+ (`; 1 actual item is extra: ["4","chair","2"] (item 3)`), so an inserted row is
78
+ one extra item, not a difference at every row after it. The step fails with
79
+ `claim_broken`, and the run summary lists every claim under "Claims" with its
80
+ outcome. A broken claim is fixed in the implementation or by asking the person,
81
+ never by a weaker compare.
82
+
83
+ A polled claim that broke says why its poll stopped. `; the poll stopped on
84
+ reading 4, before its 5000 ms timeout, since readings 3 and 4 settled (screen
85
+ equal "scoring")` means the page reached the state the step declares final;
86
+ `the poll read until its 5000 ms timeout, and no two consecutive readings
87
+ settled` means it never did. Each reading's `settled` in the record says which.
88
+
89
+ A claim on a count of execution events ends with what the count counted,
90
+ grouped by what each line reports, whatever the outcome:
91
+
92
+ ```text
93
+ claim broken: 1 (events:open-room@4 count db where op in [insert, update, delete, other], committed true) equal 0 (literal:nothing); counted 1 line: db insert into events
94
+ ```
95
+
96
+ `events_read.<key>.counted` in the step record lists every group, and
97
+ `events-read.jsonl` holds each line. A group the sentence does not mean is
98
+ a question for the person. A table the program writes for its own
99
+ bookkeeping (a telemetry row) or to run (a cache entry, a migration row) is
100
+ the program's to declare: a `lists.tables` command prints
101
+ `{"table":"events","holds":"bookkeeping"}` (or `"infrastructure"`) from
102
+ where the program already says it, never from a list in the program file,
103
+ and a `db` count that names no `table` then leaves those lines out. The
104
+ line ends `left out 1 line: db insert into events (bookkeeping)`, and
105
+ `events_read.<key>.left_out` names each group. Otherwise the implementation
106
+ stops the write, or the step's `count` names the tables the sentence means.
107
+ A held count is read the same way, since it may have counted the wrong
108
+ table or left out the one the sentence means. A tables list that was not
109
+ read (`program-list-unread`) leaves such a count `unjudged`
110
+ (`holds_unknown`): fix the command first.
111
+
112
+ The note `undeclared-write` (`nuka run`) names a step that declares
113
+ `mutates: false` whose trace holds a write the program committed to a
114
+ table that holds state, with the table and the op. The declaration or the
115
+ program is wrong; ask the person which before changing either.
116
+
117
+ ## Reading a step record as a timeline
118
+
119
+ Read the failed step's own step record as one timeline rather than a bag of
120
+ separate fields: `started_at`, `finished_at`, `sections[].at`, `polls[].at`,
121
+ `actions[].at`, and `evidence.screenshots[].at` all share one clock, so sorted
122
+ together they are an ordered account of what happened when.
123
+
124
+ ```sh
125
+ jq -r '([{at: .started_at, event: "started"}, {at: .finished_at, event: "finished"}]
126
+ + (.sections // [] | map({at, event: "section:\(.label)"}))
127
+ + (.polls // [] | map({at, event: "poll:\(.description // "poll")"}))
128
+ + (.actions // [] | map({at, event: "action:\(.method) (\(.ms)ms, \(.outcome))"}))
129
+ + (.evidence.screenshots // [] | map({at, event: "screenshot:\(.file)"})))
130
+ | sort_by(.at)[] | "\(.at) \(.event)"' record.json
131
+ ```
132
+
133
+ `actions` is every Playwright call this step made through the `page`
134
+ fixture, `expect` waits included, each with its own duration and outcome,
135
+ read straight off the step's own trace: an `expect` that timed out shows up
136
+ here with `outcome: "failed"` and a real `ms`, often enough to explain a
137
+ failure without opening the trace viewer at all.
138
+
139
+ If the step opened a browser (destructured `page`), also check `page_events` on
140
+ that step record: a console error, an uncaught page error, or a failed request
141
+ recorded there can explain a failure nothing else on the step record mentions,
142
+ since it comes from the page itself rather than anything the step declared.
143
+
144
+ ## The `final.png` and absence claims
145
+
146
+ If an absence claim turns up on that timeline, check whether its own moment
147
+ sits before whatever readiness evidence the step returned alongside it.
148
+ Earlier means the read landed before the page was ready to be read,
149
+ premature, not a state problem to go chase in the app. Don't trust
150
+ `final.png` to show the moment of failure either: it is taken at teardown,
151
+ the scenario's end (the step's under `nuka do`). A Then that read a page has
152
+ `judged_view` (`judged/page.png`, `judged/page.aria.yml`), taken right after
153
+ the reading its claims were judged on, each file with `after_reading_ms`
154
+ (the summary's `seen` links it): open that first. Reach for the
155
+ trace only when the DOM itself is what's in question: `npx playwright
156
+ show-trace <evidence.dir>/trace.zip`. That trace is this one step's own
157
+ window now, not the whole scenario's recording, so what it shows is exactly
158
+ this failure, nothing earlier in the scenario to scrub past first.
159
+ A `pageAs(name)` context records apart from the default one: its trace is
160
+ the `evidence.named_traces[]` entry whose `as` is that name, with `file`
161
+ naming `trace.<name>.zip`, and its screenshot is `final.<name>.png`.
162
+ A step that only called an API has no page to show. With `showRequests:
163
+ true` in `nukadoko.config.ts`, `evidence.requests_trace` names a trace
164
+ (`requests.zip`) whose screen shows each request the step sent and the
165
+ body that came back, redacted as http.jsonl is. http.jsonl holds the same
166
+ facts as text, and is quicker to read.
167
+
168
+ A Then that read a page while a request to the world was in flight says so on
169
+ its summary line (`read with a request in flight`, each request with the step
170
+ that sent it), and its record's `pages` name each page's `last_response` and
171
+ `in_flight` in `page_requests`, whose `span_id` finds the page's `http.jsonl`
172
+ line and the program's request line. A claim that broke there may have read the
173
+ page before the answer it needed: poll the Then (`checking-steps.md`), or have
174
+ the When wait for what it started. This is an order, never what the page drew.
175
+
176
+ ## A step that timed out
177
+
178
+ `error.kind: "timeout"` on a typed step means its `run` passed its
179
+ deadline: `stepTimeout` in `nukadoko.config.ts` (twenty minutes unless the
180
+ project sets it), or the step's own `defineStep({ timeout })`, which
181
+ `nuka describe <step>` shows when it is declared. The error message names
182
+ which one fired. Before raising either, read the timeline: the last
183
+ `sections` label says which stage the step was in when the deadline
184
+ passed. A wait on something that will never happen only fails slower
185
+ under a longer deadline. Raise the step's own `timeout` only when the step
186
+ is slow by design, and `stepTimeout` only when most steps are.
187
+
188
+ ## Testing a hypothesis without a full re-run
189
+
190
+ If a step record only sharpens a hypothesis rather than confirming it, test
191
+ the hypothesis with `nuka do <step> --use <upstream-step-record-id>`
192
+ instead of re-running the scenario. It executes the one step in question,
193
+ seconds, where a full `nuka run` costs minutes, and it still counts toward
194
+ the same three-fix-and-retry-cycles rule in `references/writing-steps.md`
195
+ ("When the vocabulary has no step for it").
196
+
197
+ Re-run the whole feature last, once the step itself passes under `do`, not
198
+ as the first thing tried after a failure. Repeating `nuka run` end to end
199
+ is the expensive way to learn what a single step record, or a single `do`
200
+ call, would already have told you.
@@ -0,0 +1,99 @@
1
+ # Before you say a change is done
2
+
3
+ Reading your own code is not the claim. The claim is a run of the tree
4
+ you have, or a named list of what no run judged.
5
+
6
+ ## nuka verdict
7
+
8
+ `nuka verdict` answers from records alone whether the newest run that
9
+ ended speaks for the working tree you have, and it never starts a run.
10
+ Every run records that tree as one git tree id, `commit.working_tree` in
11
+ run.json: tracked files as they are on disk and untracked files
12
+ `.gitignore` does not leave out, with the state directory left out. A
13
+ commit does not move it; any other edit does.
14
+
15
+ - Exit 0: the newest run judged exactly this tree, ran whole files (no
16
+ `:line`, `--tag`, or `--step`), and left no row `failed`, `unproven`, or
17
+ `moved`.
18
+ - Exit 1: `run-missing`, `run-stale` (the tree moved after the run
19
+ started), `run-partial`, or the run's own red findings, each with its
20
+ `do:` line. Run again, or end by naming each criterion that stays
21
+ unproven, failed, or not run, and why.
22
+
23
+ Run it last, after the run you will report and after any edit that
24
+ followed it. A `run-stale` after a run that changed nothing you did means
25
+ a step or the program writes a file git counts: leave that file out in
26
+ `.gitignore`, or every run will be stale.
27
+
28
+ ## What a pass does not say
29
+
30
+ A pass is narrower than "done". It does not say the change has a
31
+ criterion of its own: a change no scenario touches passes while the old
32
+ ones still hold. Under `--base`, `criteria-unchanged` notes a run in which
33
+ no criterion is new or changed; without it, `run-without-base` notes that
34
+ no new criterion was proven against a base. Whether the change needed a
35
+ criterion is a question for the person, and a change of behaviour does.
36
+ It does not say which feature files the run named either. Outside git, or
37
+ before the first commit, there is no tree id: `working-tree-unknown` notes
38
+ it, and the verdict is the newest run's own.
39
+
40
+ ## The change's intent
41
+
42
+ A pass does not say the change did only what it meant to either. Declare
43
+ that in `INTENT.md` at the repository's top, in the change's first commit,
44
+ before the code: one row per thing the change means to do differently,
45
+ `| Target | Observation | Before | After |`, where the observation is a
46
+ kind of execution event, and a row with Before and After empty says it
47
+ does not change (`docs/intent.md`). A refactor writes
48
+ `| | x_decision x_result | | |`. The person approves the rows; the run
49
+ compares them with what the program did. A `@tag` in the target only
50
+ narrows which scenarios a row covers: write the behavior as
51
+ `field<op>value` terms on the observed line (`x_input.plan=team`, with
52
+ the decision carrying its inputs), since a tool with no scenarios reports
53
+ a `@tag` row as `not_reached`. A value change that also changes the
54
+ count is two rows, one for the count and one for the value.
55
+
56
+ `nuka run --base` then reads the file when the base does not hold the same
57
+ text, and `run.json`'s `intent` lists each row's result: `as_intended`,
58
+ `not_happening`, or `not_reached` (no compared criterion is aimed at it).
59
+ `intent-unintended` names a criterion that did something no row and no
60
+ sentence declares, and `intent-not-happening` a row that did not happen
61
+ where its target aims; both fail the run, as `intent-unread` does when a
62
+ row or git cannot be read. Fix the code, or tell the person the intent
63
+ was wrong: a commit that changes the file after the first is a
64
+ change of intent, and the summary names it. Never widen a row to make a
65
+ difference you did not mean pass.
66
+
67
+ ## Asking for it from a Claude Code host
68
+
69
+ `scripts/claude-code-verdict-hook.mjs` beside `SKILL.md` is an example
70
+ hook, and nothing installs it: the Agent Skills format has no hooks, so a
71
+ project that wants it names it in its own `.claude/settings.json`:
72
+
73
+ ```json
74
+ {
75
+ "hooks": {
76
+ "UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/node_modules/nukadoko/skills/nukadoko/scripts/claude-code-verdict-hook.mjs\"" }] }],
77
+ "Stop": [{ "hooks": [{ "type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/node_modules/nukadoko/skills/nukadoko/scripts/claude-code-verdict-hook.mjs\"" }] }]
78
+ }
79
+ }
80
+ ```
81
+
82
+ On a prompt it keeps the tree id the turn started from, under the system
83
+ temp directory. On a stop it holds the turn once, with the open findings as
84
+ the reason, when the tree changed during the turn and `nuka verdict`
85
+ exits 1. A turn that changed nothing is not held, and the stop after a
86
+ hold goes through, so the agent can end by naming what stays unproven.
87
+ It runs the project's own `node_modules/.bin/nuka`, does nothing in a
88
+ project with no nukadoko config, and costs one `nuka verdict` (about
89
+ 0.3 s) per prompt and per stop. The fields it reads and writes are Claude
90
+ Code's hook fields as of 2.1.317 (`hook_event_name`, `session_id`, `cwd`,
91
+ `stop_hook_active`; `decision: "block"` with `reason`); check them against
92
+ the version you run.
93
+
94
+ ## When the reviewer asks how risky it is
95
+
96
+ A pass and a clean intent still leave the reviewer's own question: what
97
+ does this change touch, how hard is it to undo, and will its failures be
98
+ seen. Answer it from the `--base` run's record, not from the diff, with
99
+ `scripts/merge-risk.jq` beside `SKILL.md` (`references/merge-risk.md`).