@zenera/cli 1.1.24 → 1.1.25

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 (167) hide show
  1. package/README.md +53 -0
  2. package/dist/ask.js +28 -5
  3. package/dist/banner.js +2 -2
  4. package/dist/batch.d.ts +6 -0
  5. package/dist/batch.js +76 -1
  6. package/dist/catalog.d.ts +11 -1
  7. package/dist/catalog.js +80 -7
  8. package/dist/commands/inspect.d.ts +47 -1
  9. package/dist/commands/inspect.js +167 -18
  10. package/dist/commands/memory.js +128 -29
  11. package/dist/commands/meta.js +311 -21
  12. package/dist/commands/models.js +96 -12
  13. package/dist/commands/open.js +4 -4
  14. package/dist/commands/run.js +38 -4
  15. package/dist/commands/sandbox.js +76 -14
  16. package/dist/engine.d.ts +5 -0
  17. package/dist/engine.js +1 -0
  18. package/dist/eventlog.d.ts +59 -0
  19. package/dist/eventlog.js +146 -0
  20. package/dist/liveness.d.ts +7 -0
  21. package/dist/liveness.js +15 -1
  22. package/dist/meta/editor.d.ts +9 -0
  23. package/dist/meta/editor.js +60 -0
  24. package/dist/meta/finetune/children.d.ts +8 -0
  25. package/dist/meta/finetune/children.js +76 -0
  26. package/dist/meta/finetune/command.d.ts +30 -0
  27. package/dist/meta/finetune/command.js +338 -0
  28. package/dist/meta/finetune/dataset/anchors.d.ts +41 -0
  29. package/dist/meta/finetune/dataset/anchors.js +239 -0
  30. package/dist/meta/finetune/dataset/changes.d.ts +36 -0
  31. package/dist/meta/finetune/dataset/changes.js +319 -0
  32. package/dist/meta/finetune/dataset/command.d.ts +17 -0
  33. package/dist/meta/finetune/dataset/command.js +1011 -0
  34. package/dist/meta/finetune/dataset/drift.d.ts +33 -0
  35. package/dist/meta/finetune/dataset/drift.js +71 -0
  36. package/dist/meta/finetune/dataset/export.d.ts +26 -0
  37. package/dist/meta/finetune/dataset/export.js +51 -0
  38. package/dist/meta/finetune/dataset/index.d.ts +2 -0
  39. package/dist/meta/finetune/dataset/index.js +2 -0
  40. package/dist/meta/finetune/dataset/sample.d.ts +50 -0
  41. package/dist/meta/finetune/dataset/sample.js +197 -0
  42. package/dist/meta/finetune/dataset/schema.d.ts +33 -0
  43. package/dist/meta/finetune/dataset/schema.js +216 -0
  44. package/dist/meta/finetune/dataset/store.d.ts +35 -0
  45. package/dist/meta/finetune/dataset/store.js +177 -0
  46. package/dist/meta/finetune/dataset/types.d.ts +125 -0
  47. package/dist/meta/finetune/dataset/types.js +39 -0
  48. package/dist/meta/finetune/failure.d.ts +15 -0
  49. package/dist/meta/finetune/failure.js +26 -0
  50. package/dist/meta/finetune/feedback.d.ts +45 -0
  51. package/dist/meta/finetune/feedback.js +85 -0
  52. package/dist/meta/finetune/improvements.d.ts +51 -0
  53. package/dist/meta/finetune/improvements.js +244 -0
  54. package/dist/meta/finetune/index.d.ts +2 -0
  55. package/dist/meta/finetune/index.js +2 -0
  56. package/dist/meta/finetune/journal.d.ts +35 -0
  57. package/dist/meta/finetune/journal.js +135 -0
  58. package/dist/meta/finetune/live.d.ts +74 -0
  59. package/dist/meta/finetune/live.js +226 -0
  60. package/dist/meta/finetune/loop.d.ts +3 -0
  61. package/dist/meta/finetune/loop.js +114 -0
  62. package/dist/meta/finetune/memories.d.ts +47 -0
  63. package/dist/meta/finetune/memories.js +154 -0
  64. package/dist/meta/finetune/report.d.ts +33 -0
  65. package/dist/meta/finetune/report.js +1284 -0
  66. package/dist/meta/finetune/retry.d.ts +24 -0
  67. package/dist/meta/finetune/retry.js +96 -0
  68. package/dist/meta/finetune/sampler.d.ts +18 -0
  69. package/dist/meta/finetune/sampler.js +41 -0
  70. package/dist/meta/finetune/system.d.ts +27 -0
  71. package/dist/meta/finetune/system.js +132 -0
  72. package/dist/meta/finetune/train.d.ts +39 -0
  73. package/dist/meta/finetune/train.js +391 -0
  74. package/dist/meta/finetune/tui.d.ts +16 -0
  75. package/dist/meta/finetune/tui.js +291 -0
  76. package/dist/meta/finetune/tuning.d.ts +167 -0
  77. package/dist/meta/finetune/tuning.js +289 -0
  78. package/dist/meta/finetune/usage.d.ts +62 -0
  79. package/dist/meta/finetune/usage.js +225 -0
  80. package/dist/meta/host.d.ts +14 -0
  81. package/dist/meta/host.js +20 -0
  82. package/dist/meta/index.d.ts +11 -0
  83. package/dist/meta/index.js +11 -0
  84. package/dist/meta/launch.d.ts +81 -0
  85. package/dist/meta/launch.js +286 -0
  86. package/dist/meta/model.d.ts +44 -0
  87. package/dist/meta/model.js +119 -0
  88. package/dist/meta/prompts.d.ts +18 -0
  89. package/dist/meta/prompts.js +61 -0
  90. package/dist/meta/relay.d.ts +20 -0
  91. package/dist/meta/relay.js +123 -0
  92. package/dist/meta/tokens.d.ts +52 -0
  93. package/dist/meta/tokens.js +226 -0
  94. package/dist/meta/window.d.ts +61 -0
  95. package/dist/meta/window.js +198 -0
  96. package/dist/meta/wire.d.ts +42 -0
  97. package/dist/meta/wire.js +129 -0
  98. package/dist/modelref.d.ts +16 -0
  99. package/dist/modelref.js +41 -0
  100. package/dist/narrate.js +5 -2
  101. package/dist/podman.d.ts +26 -0
  102. package/dist/podman.js +83 -3
  103. package/dist/projects.d.ts +0 -5
  104. package/dist/projects.js +2 -15
  105. package/dist/sandbox.d.ts +2 -0
  106. package/dist/sandbox.js +10 -3
  107. package/dist/scaffold.d.ts +15 -6
  108. package/dist/scaffold.js +5 -60
  109. package/dist/session.js +4 -29
  110. package/dist/term.d.ts +2 -0
  111. package/dist/term.js +11 -2
  112. package/dist/trace.js +53 -2
  113. package/dist/tui/models.d.ts +33 -0
  114. package/dist/tui/models.js +389 -0
  115. package/dist/tui/wrap.d.ts +5 -0
  116. package/dist/tui/wrap.js +12 -0
  117. package/dist/usage.d.ts +78 -0
  118. package/dist/usage.js +51 -0
  119. package/package.json +3 -2
  120. package/templates/editor/.github/copilot-instructions.md +31 -102
  121. package/templates/editor/.github/prompts/analyze.prompt.md +31 -0
  122. package/templates/editor/.github/prompts/dataset.prompt.md +108 -0
  123. package/templates/editor/.github/prompts/finetune-apply.prompt.md +91 -0
  124. package/templates/editor/.github/prompts/finetune.prompt.md +691 -198
  125. package/templates/editor/.github/prompts/new-agent.prompt.md +3 -1
  126. package/templates/editor/.github/prompts/new-skill.prompt.md +2 -0
  127. package/templates/editor/.github/prompts/project-review.prompt.md +4 -3
  128. package/templates/editor/.github/skills/zen-analyze-run/SKILL.md +483 -0
  129. package/templates/editor/.github/skills/zen-cli/SKILL.md +9 -1
  130. package/templates/editor/.github/skills/zen-cli/references/dataset.md +34 -0
  131. package/templates/editor/.github/skills/zen-cli/references/finetune.md +77 -0
  132. package/templates/editor/.github/skills/zen-cli/references/inspect.md +47 -9
  133. package/templates/editor/.github/skills/zen-cli/references/memory.md +33 -10
  134. package/templates/editor/.github/skills/zen-cli/references/meta.md +61 -0
  135. package/templates/editor/.github/skills/zen-cli/references/models.md +5 -1
  136. package/templates/editor/.github/skills/zen-cli/references/rag.md +24 -6
  137. package/templates/editor/.github/skills/zen-cli/references/sandbox.md +10 -1
  138. package/templates/editor/.github/skills/zen-code-python/SKILL.md +123 -0
  139. package/templates/editor/.github/skills/zen-code-python/references/code_python.md +48 -0
  140. package/templates/editor/.github/skills/zen-dataset/SKILL.md +253 -0
  141. package/templates/editor/.github/skills/zen-finetune/SKILL.md +1449 -658
  142. package/templates/editor/.github/skills/zen-finetune/references/readme-template.md +268 -0
  143. package/templates/editor/.github/skills/zen-finetune/scripts/batch.mjs +390 -0
  144. package/templates/editor/.github/skills/zen-finetune/scripts/difficult.mjs +243 -0
  145. package/templates/editor/.github/skills/zen-finetune/scripts/memory.mjs +280 -0
  146. package/templates/editor/.github/skills/zen-finetune/scripts/next.mjs +398 -0
  147. package/templates/editor/.github/skills/zen-finetune/scripts/report.mjs +797 -0
  148. package/templates/editor/.github/skills/zen-finetune/scripts/select.mjs +354 -0
  149. package/templates/editor/.github/skills/zen-finetune/scripts/usage.mjs +722 -0
  150. package/templates/editor/.github/skills/zen-inspect/SKILL.md +60 -25
  151. package/templates/editor/.github/skills/zen-inspect-ask/SKILL.md +270 -0
  152. package/templates/editor/.github/skills/zen-memory/SKILL.md +18 -14
  153. package/templates/editor/.github/skills/zen-rag-docs/SKILL.md +20 -8
  154. package/templates/editor/.github/skills/zen-review/SKILL.md +5 -3
  155. package/templates/editor/.github/skills/zen-review/scripts/check-paths.sh +5 -4
  156. package/templates/editor/.github/skills/zen-sandbox/SKILL.md +7 -3
  157. package/templates/editor/.github/skills/zen-sandbox-capacity/SKILL.md +2 -2
  158. package/templates/editor/.github/skills/zen-topology/SKILL.md +283 -0
  159. package/templates/editor/.vscode/settings.json +1 -0
  160. package/templates/project/agents/files-instructions.md +29 -20
  161. package/templates/project/agents/memory-instructions.md +31 -32
  162. package/templates/project/agents/tools-instructions.md +7 -4
  163. package/templates/project/gitignore +2 -0
  164. package/dist/meta.d.ts +0 -221
  165. package/dist/meta.js +0 -684
  166. package/templates/editor/.github/skills/zen-finetune/scripts/collect.sh +0 -432
  167. package/templates/editor/.github/skills/zen-finetune/scripts/sample.sh +0 -199
@@ -1,20 +1,30 @@
1
1
  ---
2
2
  name: zen-inspect
3
- description: Diagnosing a run you did not watch - the `zen inspect graph` → read → `zen inspect node` loop, how to name the run (`--dir`, `--run`, `--session`, and why `node` takes ids only), how to read every part of the graph format (the `%%` header rows and what each count is evidence of, the anatomy of a node line, the label each node kind produces, shapes and colours, the `flow`/`branches`/`calls` edge blocks, branch subgraphs, and what `hidden by` and `ERROR` mean), how to open individual nodes by id or range and read the `===`/`--- part` framing, which payload parts and facts each kind carries, how `zen inspect ask` replays one `llm_call` to a model with a question when reading the node did not settle why it acted, and recipes for the usual faults - a loop, a failing tool, a prompt that was assembled differently from how it reads, a hand-off that fired early, a skill that never activated, a branch that failed, tokens spent where you did not expect. Load before reading any run trajectory, before answering "why did the agent do that", and whenever a run directory is all you have.
3
+ description: 'Use when an LLM agent must diagnose a recorded Zenera run non-interactively: read `zen inspect graph`, open selected nodes, replay an `llm_call` with `zen inspect ask`, identify loops, failed tools, wrong prompts, missed skills, early hand-offs, failed branches, compaction, latency, or token waste. Requires explicit run, node, and question arguments so commands remain deterministic and never prompt.'
4
4
  ---
5
5
 
6
- # Reading a run
6
+ # Diagnose a run non-interactively
7
7
 
8
8
  A run leaves behind everything it did, and that is the problem: a trajectory of
9
9
  a few hundred nodes is far too big to read and far too repetitive to need to.
10
10
  `zen inspect` answers it in two halves.
11
11
 
12
- | Command | For | Gives |
13
- | ----------------------- | ------- | ----------------------------------------------- |
14
- | `zen inspect report` | a human | `report.html` - every message, payload and cost |
15
- | `zen inspect graph` | you | the whole run as one Mermaid flowchart |
16
- | `zen inspect node <id>` | you | those nodes in full, payloads resolved |
17
- | `zen inspect ask <id>` | you | that call replayed to a model, with a question |
12
+ This skill is for an agent process without a TTY. Every invocation must be
13
+ fully specified. Never run bare `zen inspect` or `zen inspect node`: without a
14
+ run named they read whichever run is newest. Never run `zen inspect ask`
15
+ without a question: that is the interactive mode, for a person, and it fails
16
+ without a terminal. With a question it is one-shot - no banner, no prompt,
17
+ only the answer on stdout.
18
+
19
+ For a whole-run audit - health, memory, delegation, forking, tool use, and
20
+ what to change in the instructions - load **zen-analyze-run**, which drives
21
+ this skill end to end.
22
+
23
+ | Command | Gives |
24
+ | ---------------------------------------------------------- | --------------------------------------------- |
25
+ | `zen inspect graph --dir <run-dir>` | the whole run as one model-readable flowchart |
26
+ | `zen inspect node <id...> --dir <run-dir>` | selected nodes, payloads resolved |
27
+ | `zen inspect ask <id> --question-file <f> --dir <run-dir>` | one replay answer on stdout, then exit |
18
28
 
19
29
  **`graph` and `node` are the pair you use.** The graph is an index: one line per
20
30
  node, short sequential ids, the whole run in a few hundred lines. `node` is the
@@ -26,8 +36,26 @@ pay for what you open.
26
36
  run's own model why it did what it did. Open the node first - most questions are
27
37
  answered by reading what it was given.
28
38
 
29
- `report` is for a person with a browser. Print its path and hand it over; do not
30
- try to read the HTML.
39
+ To get one answer without prompts, pass all three inputs:
40
+
41
+ ```sh
42
+ zen inspect ask <llm-node-id> --question-file <question file> --dir <run-dir>
43
+ ```
44
+
45
+ - `<llm-node-id>` is an `nN` id from `zen inspect graph` whose label starts
46
+ with `llm`.
47
+ - `<question file>` holds the complete question, written with your
48
+ file-editing tool to `.tmp/ask/<run-id>/<node>-<topic>.md`. The shell never
49
+ parses it, so quotes, backticks and `$` arrive as written. Never pass the
50
+ question as a quoted argument, a heredoc or `$(cat ...)`, and never wrap
51
+ `zen` in a script.
52
+ - `--dir <run-dir>` identifies the run. Instead, a caller may use `--run
53
+ <run-id>` with `--session <session-id>` and, when outside the project,
54
+ `--project <name-or-dir>`.
55
+
56
+ Exactly one raw Markdown answer is written to stdout, then the command exits.
57
+ Omit `--model` to use the model that made the recorded call; pass `--model
58
+ <ref>` only for a second opinion.
31
59
 
32
60
  ## The loop
33
61
 
@@ -39,7 +67,8 @@ zen inspect graph --dir <run dir>
39
67
  zen inspect node n13 n17..n19 --dir <run dir>
40
68
 
41
69
  # 3. only if reading them did not settle it, ask the model itself
42
- zen inspect ask n17 "why run python -c when the skill says npm test?" --dir <run dir>
70
+ # (.tmp/ask/<run-id>/n17-tests.md: "Why run python -c when the skill says npm test?")
71
+ zen inspect ask n17 --question-file .tmp/ask/<run-id>/n17-tests.md --dir <run dir>
43
72
  ```
44
73
 
45
74
  That is the whole method. Never start by opening nodes - without the header
@@ -48,26 +77,26 @@ at a time is the failure the graph exists to prevent.
48
77
 
49
78
  ### Naming the run
50
79
 
51
- | You have | Use |
52
- | ----------------------- | ------------------------------------------------------ |
53
- | a run directory | `--dir <dir>` - the handle a program holds |
54
- | `zen run --json` output | `--dir "$(… \| jq -r .run.dir)"` |
55
- | a run id | `zen inspect graph <run-id>` or `--run <id>` |
56
- | nothing | omit everything: the newest run that actually recorded |
57
- | a session | `--session <id>`, listed by `zen list --sessions` |
80
+ | You have | Use |
81
+ | ----------------------- | ------------------------------------------------- |
82
+ | a run directory | `--dir <dir>` - the handle a program holds |
83
+ | `zen run --json` output | `--dir "$(… \| jq -r .run.dir)"` |
84
+ | a run id | `zen inspect graph <run-id>` or `--run <id>` |
85
+ | a session | `--session <id>`, listed by `zen list --sessions` |
86
+
87
+ Always identify the run. Prefer `--dir`, because `zen run --json` returns it
88
+ without requiring the caller to reconstruct project, session and run ids. If
89
+ the task supplies no run handle, obtain one before inspecting; do not rely on
90
+ the newest run implicitly.
58
91
 
59
92
  **`node` has no room for a run.** Every positional it takes is a node id, so
60
93
  name the run with `--dir`, `--run` or `--session`. `zen inspect node <run-id> n13`
61
- reads the run id as an id and fails. `ask` is the same: one node id, then the
62
- question.
94
+ reads the run id as an id and fails. Explicit `ask` arguments are the same: one
95
+ node id, then the question.
63
96
 
64
97
  For `graph` the positional is a run id unless it contains a `/`, in which case
65
98
  it is a directory - a run id is a stamp and never has a separator.
66
99
 
67
- With nothing to ask on - a script, `--json`, an agent - `zen inspect` takes the
68
- newest run of the newest session **that recorded one**. A session exists before
69
- its first run, so the literally newest session is routinely empty.
70
-
71
100
  ### Reading it cheaply
72
101
 
73
102
  `--no-style` drops the colour statements and `--no-timing` drops the clock;
@@ -121,6 +150,8 @@ diagram would make you count by eye.
121
150
  | `dir` | the run directory | paste into `--dir`, no reconstruction needed |
122
151
  | `workspace` | the files the run worked on | where to go and check what actually changed |
123
152
  | `memory` | the memory graph the run read | absent when the run read none |
153
+ | | recall · search · grep · load · commit, zeros kept | `commit 0` is nothing saved, whatever the answer says |
154
+ | | `nothing committed after N workspace file writes` | a script or file that worked and was not kept |
124
155
  | `agent` | the agent it ended on · the one it started as | two different names means a hand-off happened |
125
156
  | `phase` | `done`, or the phase and the error | an error here is the verdict; the graph is the story |
126
157
  | `nodes` | total · llm · tool calls · forks | the shape and the size of what follows |
@@ -304,7 +335,7 @@ bug in the node.
304
335
  ## Asking the model
305
336
 
306
337
  ```sh
307
- zen inspect ask n17 "which instruction made you avoid the test command?" --dir <run dir>
338
+ zen inspect ask n17 --question-file .tmp/ask/<run-id>/n17-tests.md --dir <run dir>
308
339
  ```
309
340
 
310
341
  One `llm_call`, replayed: its recorded system prompt, its messages and its tool
@@ -331,6 +362,10 @@ The questions it is good at are the ones about intent, where the node shows what
331
362
  happened but not why: which of two instructions won, why a skill that was
332
363
  loaded was not followed, why a tool was used the way it was.
333
364
 
365
+ Before writing the question, load skill **zen-inspect-ask**: which node to ask, what
366
+ to rule out first, and how to word a "why did you not..." question so the answer
367
+ quotes the instruction that blocked the better behaviour.
368
+
334
369
  ## Diagnosing
335
370
 
336
371
  Match the symptom to the row of the header, then open the two or three nodes
@@ -0,0 +1,270 @@
1
+ ---
2
+ name: zen-inspect-ask
3
+ description: 'Use when formulating a question for `zen inspect ask` about an `llm_call` node of a recorded Zenera run - especially a "why did you NOT do X" question (why no `memory_search` first, why no `fork` for independent research branches, why no skill, why no test run). Covers choosing the node, ruling out missing tools before asking, wording the counterfactual so the answer quotes the instruction that blocked the better behaviour, and verifying that quote against the recorded request.'
4
+ ---
5
+
6
+ # Asking a run why it did not do the better thing
7
+
8
+ `zen inspect ask` replays one recorded `llm_call` - its system prompt, messages
9
+ and tool schemas, byte for byte - with tool calling off and a preamble that
10
+ permits the model to quote its own instructions. Load **zen-inspect** for the
11
+ mechanics (graph, node, flags). This skill is about the one thing that decides
12
+ whether the call is worth its cost: **the question**.
13
+
14
+ The goal of every question here is the same: **find the sentence in the
15
+ assembled prompt that prevented the good behaviour**, or prove that no sentence
16
+ asked for it. That sentence is what you are about to edit. An answer that does
17
+ not name one is a wasted call.
18
+
19
+ Non-interactive rule, as in zen-inspect: always pass the node, the question and
20
+ the run. The question is always a file (section 3):
21
+
22
+ ```sh
23
+ zen inspect ask <llm-node-id> --question-file <question file> --dir <run-dir>
24
+ ```
25
+
26
+ Each non-interactive call is a **fresh replay**. It does not remember your
27
+ previous question. A follow-up must restate what it builds on.
28
+
29
+ ## 1. Rule out the cheap causes first
30
+
31
+ A "why didn't you" question is only about instructions if the model could have
32
+ done it. Check these from the graph and the node before spending a model call -
33
+ each one is a finding on its own, and asking the model about it produces an
34
+ invented rationale.
35
+
36
+ | Check | How | If it fails, the cause is |
37
+ | -------------------------------------- | --------------------------------------------------------------------------------------- | -------------------------------------------------- |
38
+ | The tool was offered on that call | grep the recorded request for its schema (below) | `agents.yaml` - tool not granted, or depth cap hit |
39
+ | The instruction file was in the prompt | the `system_prompt` label lists files: `fork-instructions.md`, `memory-instructions.md` | missing file, or its `requires:` not met |
40
+ | The skill was loaded | a `load_skills` node naming it, or the skill index in `request` | binding in `agents.yaml` (`skills:`) |
41
+ | Memory was already recalled for it | a `memory_recall` node before the call; `recall 0 nodes` | memory content, not behaviour |
42
+ | The context still held what it needed | no `compaction` before the node, or the item is not `hidden by` one | compaction, not instructions |
43
+
44
+ ```sh
45
+ zen inspect node n9 --part request --dir <run-dir> | grep -oE '"name": *"(fork|memory_search|memory_grep)"' | sort -u
46
+ ```
47
+
48
+ Only when every row passes is the question "which instruction stopped you".
49
+
50
+ ## 2. Pick the node where the decision was made
51
+
52
+ The replay ends at the chosen node: the model sees everything up to and
53
+ including that call's own answer, and **nothing after it**. So ask the call that
54
+ made the choice, not the one where the consequence showed up.
55
+
56
+ | Missing behaviour | Ask the `llm_call` that... |
57
+ | ------------------------------- | ----------------------------------------------------------------------------------- |
58
+ | never searched memory | issued the first tool call of the task (usually the first `llm` after `user input`) |
59
+ | ran independent work in series | issued the **first** of the sequential calls - it already had the whole plan |
60
+ | never loaded / followed a skill | chose the substitute action (the `python -c`, the hand-rolled grep) |
61
+ | handed off too early | carries `calls transfer_to_<name>` |
62
+ | gave up / answered too early | the last `llm` before `final output` |
63
+ | repeated a failed call | the one right after the first `ERROR` result |
64
+
65
+ If the choice repeated (four serial searches), ask **once**, not per step. Ask
66
+ the first call when the question is why it started that way - it already had
67
+ the whole plan. Ask the last call of the sequence when the question is about
68
+ the sequence as a whole - its replay holds every step. Never ask a middle one:
69
+ that gets "I was continuing the pattern I had started", which names no
70
+ instruction.
71
+
72
+ ## 3. Formulate the question
73
+
74
+ ### What the replayed model can see
75
+
76
+ The model you are asking sees **only its own raw context** at that call: the
77
+ system prompt, the messages up to that point, the tool descriptions, and the
78
+ answer it gave - its text and its tool calls. That is all. So:
79
+
80
+ - **No node ids, no graph words.** `n7`, `llm_call`, `tool_result`, "branch
81
+ n12" are your index, not its world. Name what it did by its content: "you
82
+ ran `grep -rn invoice /workspace/src`", "your first tool call was
83
+ `read_file` on `src/export.ts`".
84
+ - **Refer to earlier steps by what they were**, as it saw them in its
85
+ messages: "after `memory_search` returned the export node", "after the
86
+ third `run_command` failed with exit code 1".
87
+ - **Describe anything after the call yourself, in plain words.** The replay
88
+ ends at that call; it cannot see what followed. "You then searched three
89
+ more topics one after another" is something it can only learn from you.
90
+
91
+ ### What the preamble already does
92
+
93
+ `ask` puts a preamble in front of the replayed system prompt, and it already
94
+ makes the model do the following:
95
+
96
+ - cite every reason as `[<kind>: <name> › <heading or parameter>] "<verbatim quote>"`,
97
+ where kind is system prompt, skill, tool description or message
98
+ - trace the decision: the options it could see, which one it took, and which
99
+ text tipped it
100
+ - say which instruction it followed, which it missed, which two conflicted, and
101
+ any exception it judged to apply
102
+ - write "no instruction — my own default" instead of making up a source
103
+ - use the answer format the question asks for
104
+
105
+ **Do not restate any of that in the question.** Asking again for verbatim
106
+ quotes or sources adds a second, differently worded copy of the rule, and the
107
+ model follows whichever it read last.
108
+
109
+ ### The three parts
110
+
111
+ The question supplies only what the preamble cannot know. Leave a part out and
112
+ the answer drifts to a generic apology.
113
+
114
+ 1. **What it did, by content.** The action as it appears in its own answer,
115
+ stated as a fact, not an accusation.
116
+ 2. **Why not the better action - asked directly.** "Why didn't you use
117
+ `memory_search` to look up the invoice export first?" Name the action
118
+ concretely - the tool as it appears in its tool list, and the arguments or
119
+ branches it could have used - and say it was available. Never ask "did you
120
+ consider...": its own answer already shows it did not take that path, and
121
+ the question invites a yes that explains nothing.
122
+ 3. **A fixed answer shape.** So answers can be compared across calls and
123
+ runs, and so an answer without a citation is visibly empty. The shape uses
124
+ the preamble's citation form.
125
+
126
+ Write the question to a file with your file-editing tool, then hand `zen` the
127
+ file. The shell never parses the question, so quotes, apostrophes, backticks and
128
+ `$` arrive as written. End the file with this shape, verbatim:
129
+
130
+ ```text
131
+ <the question>
132
+
133
+ Answer in this shape:
134
+ options: <what you could see at that point, and which one you took>
135
+ steered-by: [<kind>: <name> › <heading or parameter>] "<quote>" (one per line, or: no instruction — my own default)
136
+ should-have-applied: [<kind>: <name> › <heading or parameter>] "<quote>" (or: none found)
137
+ exception: [<kind>: <name> › <heading or parameter>] "<quote>" (or: none)
138
+ conflict: <the two citations that pulled in different directions, or: none>
139
+ missing: <the sentence that, added where, would have made you do it>
140
+ ```
141
+
142
+ ```sh
143
+ zen inspect ask n9 --question-file .tmp/ask/<run-id>/n9-memory.md --dir <run-dir>
144
+ ```
145
+
146
+ - One file per question, at `.tmp/ask/<run-id>/<node>-<topic>.md`. `.tmp/` is
147
+ the project's git-ignored scratch.
148
+ - `--question-file` is the only way the question reaches `zen`. Never a quoted
149
+ argument, a heredoc, `$(cat ...)`, or a Python or Node script around `zen`.
150
+ - A retry (section 5, step 1) or a second opinion (step 4) reuses the same
151
+ file: add `--model <ref>` and change nothing else.
152
+
153
+ ### Wording rules
154
+
155
+ - **Ask why not, directly.** "Why didn't you fork the four lookups?" - not
156
+ "did you consider forking?", not "would forking have been better?".
157
+ - **Do not lead.** "Didn't fork-instructions tell you to parallelise?" gets
158
+ "yes, I should have" - agreement, not a cause. Name the action, never the
159
+ instruction you suspect.
160
+ - **Do not ask what it should have done.** That produces a lecture on best
161
+ practice written from general knowledge, not from its prompt.
162
+ - **One behaviour per question.** Memory and forking in one question get one
163
+ shallow answer each. Ask twice.
164
+ - **Name the alternative as an action, not a virtue.** "Why didn't you
165
+ `memory_search` for 'invoice export endpoint'?" - not "why weren't you more
166
+ efficient?".
167
+ - **Keep the exception line.** A rule with an escape hatch ("unless...", "only
168
+ when...", "for simple tasks...") is the most common blocker. The preamble asks
169
+ for exceptions, but a model will not volunteer that it granted itself one
170
+ unless an empty `exception:` line is waiting for it.
171
+
172
+ ## 4. Templates
173
+
174
+ The question bodies below replace `<the question>` in the file of section 3.
175
+ Replace every command, tool argument and topic with the run's own. None of them
176
+ mentions a node id: the id goes on the command line, never in the question.
177
+
178
+ ### Did not use memory
179
+
180
+ ```text
181
+ Your first step for this task was run_command `grep -rn 'export' /workspace/src`.
182
+ Why didn't you use memory_search or memory_grep to look up the invoice export
183
+ endpoint first? Both are in your tool list, and an earlier run may already have
184
+ worked it out. What in your instructions, or missing from them, made the
185
+ workspace the first place to look?
186
+ ```
187
+
188
+ ### Recalled memory, then redid the work
189
+
190
+ ```text
191
+ memory_search returned a node describing the invoice export endpoint and where
192
+ it is implemented. Your next step was to grep the workspace for the same
193
+ endpoint. Why didn't you use what memory returned, or memory_load that node to
194
+ read it whole? What made the recalled text not enough?
195
+ ```
196
+
197
+ ### Did not save what it learned
198
+
199
+ ```text
200
+ To answer this you read eleven files and ran four commands, and your answer
201
+ names facts a later run would need again. memory_commit is in your tool list.
202
+ Why didn't you commit what you worked out before answering?
203
+ ```
204
+
205
+ ### Did not fork independent research
206
+
207
+ ```text
208
+ From this point you researched four things one after another: (A) the auth
209
+ flow, (B) the billing schema, (C) the retry policy, (D) the webhook format.
210
+ None of the later lookups used an earlier result. Why didn't you call fork once
211
+ with a branch for each of A-D? fork is in your tool list.
212
+ ```
213
+
214
+ ### Did not follow a loaded skill
215
+
216
+ ```text
217
+ You called run_command with `python3 -c` to check the output. The skill
218
+ run-tests is in your context and says to run `npm test`. Why didn't you run
219
+ `npm test`? What made the inline script look acceptable here?
220
+ ```
221
+
222
+ ### Misused a tool
223
+
224
+ ```text
225
+ You called memory_commit three times with a `refs` array naming nodes from an
226
+ earlier commit, and each call failed. Why did you expect refs to reach nodes
227
+ committed earlier? Which words in the memory_commit description led you there,
228
+ or what was missing from it?
229
+ ```
230
+
231
+ The same skeleton covers any missing behaviour: **what it did, by content ->
232
+ why not the better action, available -> shape.** The preamble does the rest.
233
+
234
+ ## 5. Verify the answer
235
+
236
+ The answer is testimony. It is useful because it points at a sentence; it is
237
+ only a finding once the sentence is confirmed.
238
+
239
+ 1. **Grep each quote in the recorded request** - the text between the double
240
+ quotes of each `[...] "..."` citation.
241
+ ```sh
242
+ zen inspect node n9 --part request --dir <run-dir> | grep -F 'Do not fork a sequence'
243
+ ```
244
+ A quote that is not there is invented - discard the answer, not just the
245
+ quote. Ask once more; if it invents again, ask another model (step 4).
246
+ 2. **Find every copy.** The blocker often exists twice - once in a house rule,
247
+ once in a skill with a softer tail. Grep the whole request for a distinctive
248
+ phrase of it, then grep the project's `agents/` tree for the file to edit.
249
+ 3. **Check it is the project's file.** `fork-instructions.md`,
250
+ `memory-instructions.md`, `tools-instructions.md` are zen's own copies; load
251
+ **zen-instructions** before changing where that rule lives.
252
+ 4. **Second opinion when the self-report is thin.** The model that made the
253
+ call rationalises; another model reading the same replay often names the
254
+ conflict more plainly: `--model <ref>`. Ask the identical question: the same
255
+ question file.
256
+ 5. **Reproduce.** After the edit, rerun the case and check the graph: the
257
+ `tools` header row shows `fork x1` or `memory_search x1` where it did not
258
+ before. The answer predicted a fix; the graph confirms it.
259
+
260
+ ## 6. Reading the answer
261
+
262
+ | Answer says | Means | Fix |
263
+ | ---------------------------------------------------------- | ------------------------------------------- | ----------------------------------------------------------------- |
264
+ | `should-have-applied: none found` | nothing asked for it | add a mechanical rule at the point of decision |
265
+ | `steered-by: no instruction — my own default` | the model's habit filled a gap | add a mechanical rule at the point of decision |
266
+ | a rule quoted as `should-have-applied`, nothing against it | the rule is there but not reachable in time | move it earlier, or into the skill loaded for that task |
267
+ | a `steered-by` quote that argues against the better action | an instruction argued against it | narrow or remove the blocker, do not add a counter-rule beside it |
268
+ | `conflict:` names two rules | two instructions disagree | delete one; two copies of a rule is how drift starts |
269
+ | an exception is quoted as applying | a self-judged escape hatch | remove the hatch or make its condition checkable |
270
+ | no citation at all, general reasoning only | the question was too open, or led | rewrite with the three parts; do not act on it |
@@ -648,20 +648,24 @@ ranker, the same walk, the same block a model would have been given, scores and
648
648
  all. It is the only one that embeds, and the only one that can distinguish a
649
649
  memory that is missing from a memory that is merely ranked sixth.
650
650
 
651
- | Question | Command |
652
- | ---------------------------------------- | ------------------------------------ |
653
- | Is memory even on, and is it embedded? | `zen memory stats` |
654
- | What has this project learned? | `zen memory export --open` |
655
- | Is this host/flag/path in there at all? | `zen memory grep <pattern>` |
656
- | Everywhere a thing is mentioned | `zen memory grep <pattern> --all` |
657
- | What would an agent recall for this? | `zen memory search <query>` |
658
- | Why did it _not_ recall that? | `zen memory search <q> --audience a` |
659
- | What is in one private slice? | `zen memory ls --audience audit` |
660
- | What has been corrected? | `zen memory ls --stale` |
661
- | What files are being kept? | `zen memory ls --files` |
662
- | One node in full, with what it links to | `zen memory show <id>` |
663
- | Fold parallel warmup graphs into one | `zen memory merge <dir...>` |
664
- | That should never have been written down | `zen memory forget <id>` |
651
+ | Question | Command |
652
+ | ---------------------------------------- | ------------------------------------- |
653
+ | Is memory even on, and is it embedded? | `zen memory stats` |
654
+ | What has this project learned? | `zen memory export --open` |
655
+ | Is this host/flag/path in there at all? | `zen memory grep <pattern>` |
656
+ | Everywhere a thing is mentioned | `zen memory grep <pattern> --all` |
657
+ | What would an agent recall for this? | `zen memory search <query>` |
658
+ | Why did it _not_ recall that? | `zen memory search <q> --audience a` |
659
+ | What is in one private slice? | `zen memory ls --audience audit` |
660
+ | What has been corrected? | `zen memory ls --stale` |
661
+ | What files are being kept? | `zen memory ls --files` |
662
+ | One node in full, with what it links to | `zen memory show <id>` |
663
+ | What did a run add to its copy, or read? | `zen memory diff <base> --dir <copy>` |
664
+ | Fold parallel warmup graphs into one | `zen memory merge <dir...>` |
665
+ | That should never have been written down | `zen memory forget <id>` |
666
+
667
+ Never read a memory's `graph.json` or `manifest.json` with code: every question
668
+ above has a command, and `--json` on any of them is the stable shape.
665
669
 
666
670
  The directory is not fixed. `zen run --memory <dir>` sends one run's memory
667
671
  somewhere else - a scratch graph for a trial, one per branch, or a shared one
@@ -387,6 +387,7 @@ outline and the copies on disk.
387
387
  zen rag docs list <files|sections|tables> [-d <dir>] [filters…]
388
388
  zen rag docs grep <pattern> [-d <dir>] [filters…]
389
389
  zen rag docs show <file> [--section <name>] [--lines <from-to>]
390
+ zen rag docs show <target>... [--max-lines <n>]
390
391
  zen rag docs stats
391
392
  ```
392
393
 
@@ -411,6 +412,7 @@ zen rag docs grep "Retry-After" # every matching line, and its sec
411
412
  zen rag docs grep "X-RateLimit-\w+" --regex --file "api/**"
412
413
  zen rag docs show api/routing.md --section "Rate limits"
413
414
  zen rag docs show api/routing.md --lines 40-80
415
+ zen rag docs show "api/routing.md:24-31" "api/errors.md#Retries" # several, one call
414
416
  zen rag docs stats
415
417
  ```
416
418
 
@@ -431,6 +433,14 @@ the whole point of it.
431
433
  line-number gutter (`--no-numbers` to drop it). It is the natural follow-up to
432
434
  every search: find the passage, then read what is actually around it.
433
435
 
436
+ **Read every passage you will cite in one `show`.** It takes any number of
437
+ targets written the way a citation is - `<document>:<a>-<b>`, `<document>:<a>`,
438
+ `<document>#<heading>`, or a bare name - and prints each under a header that is
439
+ itself a target, in the order given. Overlapping ranges print once; a missing
440
+ document or heading is reported in place while the rest still print. The
441
+ `--max-lines` budget (default 400) is shared fairly, and a cut block ends with
442
+ the target that continues it. One call per passage costs a whole turn each.
443
+
434
444
  `stats` says what is in an index and what built it - the documents, the counts,
435
445
  the embedding model. It is the fastest way to answer "is this index the one I
436
446
  think it is?".
@@ -443,6 +453,7 @@ think it is?".
443
453
  | _anything you would have run `grep` for_ | `grep` / `list` - never the shell |
444
454
  | "does `X-Request-Id` appear anywhere?" | `grep X-Request-Id` |
445
455
  | "what does the rate-limits section actually say?" | `show <file> --section "Rate limits"` |
456
+ | "read the four passages the search turned up" | `show <doc>:<a>-<b> <doc>:<a>-<b> ...` - once |
446
457
  | "which documents are even in here?" | `list files` |
447
458
  | "what is the shape of this manual?" | `list sections --depth 2` |
448
459
  | "where is the table of per-route limits?" | `list tables --file "api/**"` |
@@ -470,6 +481,7 @@ Add `-d <dir>` when the index is not the nearest one, or name it once with
470
481
  | `grep '^#' file.md` | `zen rag docs list sections --file file.md` |
471
482
  | `sed -n '40,80p' file.md` | `zen rag docs show file.md --lines 40-80` |
472
483
  | `cat file.md` (to find one section) | `zen rag docs show file.md --section "Rate limits"` |
484
+ | a `sed`/`show` per passage | `zen rag docs show a.md:40-80 b.md:12-30` |
473
485
  | `ls` the index directory | `zen rag docs stats` |
474
486
 
475
487
  ```sh
@@ -497,12 +509,12 @@ const index = await docs.DocsIndex.open(
497
509
  const project = await loadProject('./my-project', { tools: docs.docsTools(index) });
498
510
  ```
499
511
 
500
- | Tool | For |
501
- | ------------- | ------------------------------------------------------------ |
502
- | `search_docs` | the passages that match, quoted with their line numbers |
503
- | `list_docs` | the documents, their headings, or their tables - no search |
504
- | `grep_docs` | every matching line, counted in full - no search |
505
- | `read_docs` | a section or a line range, verbatim and with nothing omitted |
512
+ | Tool | For |
513
+ | ------------- | ------------------------------------------------------------------------------------------ |
514
+ | `search_docs` | the passages that match, quoted with their line numbers |
515
+ | `list_docs` | the documents, their headings, or their tables - no search |
516
+ | `grep_docs` | every matching line, counted in full - no search |
517
+ | `read_docs` | a section or a line range, verbatim and with nothing omitted; several at once with `reads` |
506
518
 
507
519
  Only `search_docs` ranks; the other three are exact, because a model told "no
508
520
  results" by a vector search has learned nothing - a ranking returns the top of a
@@ -602,8 +614,8 @@ reference and `guides/` for the task documentation.
602
614
  - Does X exist, how is it spelled, how many are there → `grep_docs`. It is
603
615
  complete; a search is not, and cannot prove absence.
604
616
  - Limits and defaults are in tables → add `kind: ["table_row"]`.
605
- - Then `read_docs` the lines around the hit before answering. Never answer from
606
- the excerpt alone.
617
+ - Then `read_docs` the lines around every hit before answering, all of them in
618
+ one call with `reads`. Never answer from the excerpt alone.
607
619
  - Never `grep`/`rg`/`cat` the tree - the tools above are local and exact.
608
620
 
609
621
  Worked: per-route rate limits are the table under "Rate limits" in
@@ -58,9 +58,11 @@ to open a file that is not there.
58
58
 
59
59
  It exits `1` whenever it prints a candidate, because the list is meant to be
60
60
  emptied or explained rather than skimmed. It strips urls before tokenising, skips
61
- a handful of English constructions that contain a slash, and leaves
62
- `agents/memory-instructions.md` out entirely - that file is worked examples by
63
- design, and `check-instructions.sh` is the check it actually needs.
61
+ a handful of English constructions that contain a slash, and leaves the four
62
+ copies `zen` ships (`agents/{files,fork,memory,tools}-instructions.md`) out
63
+ entirely - they are worked examples by design, `zen check` keeps them
64
+ byte-identical (`rules.stale`), and `check-instructions.sh` is the check memory
65
+ actually needs.
64
66
 
65
67
  Everything it does print is either noise the script has not learned yet or a
66
68
  real finding. There is no third case. A candidate that is genuinely noise is a
@@ -43,9 +43,10 @@ strip_urls() {
43
43
  # The three trees §2.5 names, prose only: a skill's own script is code the
44
44
  # sandbox runs, not text rendered into a prompt, and its paths are its own.
45
45
  #
46
- # `agents/memory-instructions.md` is left out on purpose. It is a copy of the
47
- # reference, full of worked examples, so it fails this sweep by design and
48
- # every run of it — and it has a check of its own that a sweep cannot make:
46
+ # The four copies `zen` ships (files-, fork-, memory-, tools-instructions.md)
47
+ # are left out on purpose. They are full of worked examples, so they fail this
48
+ # sweep by design, and the project cannot edit them anyway: `zen check` reports
49
+ # any byte that differs as `rules.stale`. Memory has a check of its own too:
49
50
  # .github/skills/zen-memory/scripts/check-instructions.sh
50
51
  files() {
51
52
  {
@@ -54,7 +55,7 @@ files() {
54
55
  for file in agents/*instructions.md; do
55
56
  if [ -f "$file" ]; then echo "$file"; fi
56
57
  done
57
- } | grep -v '^agents/memory-instructions\.md$' | sort -u
58
+ } | grep -Ev '^agents/(files|fork|memory|tools)-instructions\.md$' | sort -u
58
59
  }
59
60
 
60
61
  # Every token in those files, urls removed first, and a sentence's full stop
@@ -195,7 +195,8 @@ an exit 124 that looks like a slow index.
195
195
  One container is rarely the problem. Before running several at once — a
196
196
  `zen run batch` with `--concurrency` above 1 — load **zen-sandbox-capacity** and
197
197
  run its `preflight_sandbox.sh`, which measures the VM, the container cap and the
198
- index and says whether the arithmetic fits.
198
+ index and says whether the arithmetic fits. A `zen-finetune` run is the
199
+ exception: it starts at `min(maxBatch + recheck, 16)` and halves on OOM instead.
199
200
 
200
201
  ---
201
202
 
@@ -261,7 +262,8 @@ Use the `zen sandbox` commands via terminal to inspect and manage container stat
261
262
  zen sandbox status # Check podman version, machine status, and active containers
262
263
  zen sandbox up # Start VM (macOS) and pull or build the required image
263
264
  zen sandbox pull # Re-pull base image or force build of sandbox/Dockerfile
264
- zen sandbox clean # Force remove all zn-* containers created by this project
265
+ zen sandbox clean # Force remove all zn-* containers created by this CLI
266
+ zen sandbox clean --idle # Only what no live run uses: stopped and orphaned ones
265
267
  zen sandbox disk # Inspect disk space consumed by images, containers, and volumes
266
268
  ```
267
269
 
@@ -273,4 +275,6 @@ zen sandbox disk # Inspect disk space consumed by images, containers,
273
275
  - **Permission Denied in `/workspace`:**
274
276
  - In `strict` mode without `user:`, rootless Podman uses `keep-id` to preserve host UID. If using custom `user:`, verify host directory permissions allow that UID.
275
277
  - **Disk Space Pressure:**
276
- - Run `zen sandbox clean` to prune stopped session containers.
278
+ - Run `zen sandbox clean --idle` to prune stopped and orphaned session containers.
279
+ - **`could not create container … exceeded num_locks`:**
280
+ - Every container holds one engine lock (2048 by default), stopped ones included. Run `zen sandbox clean --idle`.
@@ -240,14 +240,14 @@ do with the machine.
240
240
 
241
241
  ## A machine spec is part of a round
242
242
 
243
- Record it into the round directory, next to the findings:
243
+ Record it into the run directory, next to the findings:
244
244
 
245
245
  ```sh
246
246
  {
247
247
  echo "host $(($(sysctl -n hw.memsize) / 1073741824)) GiB"
248
248
  podman info --format json | jq -r '.host | "vm \(.memTotal / 1073741824 | floor) GiB · swap \(.swapTotal) · \(.cpus) cpus"'
249
249
  echo "batch --concurrency 8"
250
- } > .finetune/rounds/r5/machine.txt
250
+ } > finetune/runs/batch01-nomem-run1/machine.txt
251
251
  ```
252
252
 
253
253
  The consequence is not bookkeeping, it is validity: **token counts and