@zenera/cli 1.1.24 → 1.1.26

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 (199) hide show
  1. package/README.md +65 -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 +31 -1
  7. package/dist/catalog.js +140 -7
  8. package/dist/commands/index.js +2 -0
  9. package/dist/commands/inspect.d.ts +52 -2
  10. package/dist/commands/inspect.js +220 -31
  11. package/dist/commands/memory.js +156 -32
  12. package/dist/commands/meta.js +333 -24
  13. package/dist/commands/models.js +97 -12
  14. package/dist/commands/open.js +4 -4
  15. package/dist/commands/run.js +38 -4
  16. package/dist/commands/sandbox.js +148 -16
  17. package/dist/commands/view.d.ts +8 -0
  18. package/dist/commands/view.js +114 -0
  19. package/dist/engine.d.ts +8 -1
  20. package/dist/engine.js +7 -0
  21. package/dist/eventlog.d.ts +64 -0
  22. package/dist/eventlog.js +170 -0
  23. package/dist/liveness.d.ts +7 -0
  24. package/dist/liveness.js +35 -3
  25. package/dist/main.js +0 -0
  26. package/dist/meta/editor.d.ts +9 -0
  27. package/dist/meta/editor.js +43 -0
  28. package/dist/meta/finetune/analyze-brief.d.ts +26 -0
  29. package/dist/meta/finetune/analyze-brief.js +131 -0
  30. package/dist/meta/finetune/apply-brief.d.ts +23 -0
  31. package/dist/meta/finetune/apply-brief.js +247 -0
  32. package/dist/meta/finetune/brief.d.ts +45 -0
  33. package/dist/meta/finetune/brief.js +158 -0
  34. package/dist/meta/finetune/children.d.ts +8 -0
  35. package/dist/meta/finetune/children.js +76 -0
  36. package/dist/meta/finetune/command.d.ts +30 -0
  37. package/dist/meta/finetune/command.js +516 -0
  38. package/dist/meta/finetune/cost.d.ts +46 -0
  39. package/dist/meta/finetune/cost.js +105 -0
  40. package/dist/meta/finetune/dataset/anchors.d.ts +41 -0
  41. package/dist/meta/finetune/dataset/anchors.js +239 -0
  42. package/dist/meta/finetune/dataset/changes.d.ts +36 -0
  43. package/dist/meta/finetune/dataset/changes.js +319 -0
  44. package/dist/meta/finetune/dataset/command.d.ts +17 -0
  45. package/dist/meta/finetune/dataset/command.js +1011 -0
  46. package/dist/meta/finetune/dataset/drift.d.ts +33 -0
  47. package/dist/meta/finetune/dataset/drift.js +71 -0
  48. package/dist/meta/finetune/dataset/export.d.ts +26 -0
  49. package/dist/meta/finetune/dataset/export.js +51 -0
  50. package/dist/meta/finetune/dataset/index.d.ts +2 -0
  51. package/dist/meta/finetune/dataset/index.js +2 -0
  52. package/dist/meta/finetune/dataset/sample.d.ts +50 -0
  53. package/dist/meta/finetune/dataset/sample.js +197 -0
  54. package/dist/meta/finetune/dataset/schema.d.ts +33 -0
  55. package/dist/meta/finetune/dataset/schema.js +216 -0
  56. package/dist/meta/finetune/dataset/store.d.ts +35 -0
  57. package/dist/meta/finetune/dataset/store.js +177 -0
  58. package/dist/meta/finetune/dataset/types.d.ts +127 -0
  59. package/dist/meta/finetune/dataset/types.js +39 -0
  60. package/dist/meta/finetune/failure.d.ts +15 -0
  61. package/dist/meta/finetune/failure.js +26 -0
  62. package/dist/meta/finetune/feedback.d.ts +57 -0
  63. package/dist/meta/finetune/feedback.js +104 -0
  64. package/dist/meta/finetune/guard.d.ts +29 -0
  65. package/dist/meta/finetune/guard.js +104 -0
  66. package/dist/meta/finetune/improvements.d.ts +98 -0
  67. package/dist/meta/finetune/improvements.js +501 -0
  68. package/dist/meta/finetune/index.d.ts +2 -0
  69. package/dist/meta/finetune/index.js +2 -0
  70. package/dist/meta/finetune/journal.d.ts +35 -0
  71. package/dist/meta/finetune/journal.js +135 -0
  72. package/dist/meta/finetune/live.d.ts +84 -0
  73. package/dist/meta/finetune/live.js +272 -0
  74. package/dist/meta/finetune/loop.d.ts +3 -0
  75. package/dist/meta/finetune/loop.js +163 -0
  76. package/dist/meta/finetune/memories.d.ts +47 -0
  77. package/dist/meta/finetune/memories.js +154 -0
  78. package/dist/meta/finetune/recheck.d.ts +58 -0
  79. package/dist/meta/finetune/recheck.js +311 -0
  80. package/dist/meta/finetune/report.d.ts +40 -0
  81. package/dist/meta/finetune/report.js +1397 -0
  82. package/dist/meta/finetune/retry.d.ts +24 -0
  83. package/dist/meta/finetune/retry.js +96 -0
  84. package/dist/meta/finetune/sampler.d.ts +18 -0
  85. package/dist/meta/finetune/sampler.js +47 -0
  86. package/dist/meta/finetune/system.d.ts +27 -0
  87. package/dist/meta/finetune/system.js +132 -0
  88. package/dist/meta/finetune/train.d.ts +43 -0
  89. package/dist/meta/finetune/train.js +425 -0
  90. package/dist/meta/finetune/tui.d.ts +16 -0
  91. package/dist/meta/finetune/tui.js +316 -0
  92. package/dist/meta/finetune/tuning.d.ts +193 -0
  93. package/dist/meta/finetune/tuning.js +308 -0
  94. package/dist/meta/finetune/usage.d.ts +66 -0
  95. package/dist/meta/finetune/usage.js +260 -0
  96. package/dist/meta/finetune/view.d.ts +9 -0
  97. package/dist/meta/finetune/view.js +27 -0
  98. package/dist/meta/host.d.ts +15 -0
  99. package/dist/meta/host.js +21 -0
  100. package/dist/meta/index.d.ts +11 -0
  101. package/dist/meta/index.js +11 -0
  102. package/dist/meta/launch.d.ts +81 -0
  103. package/dist/meta/launch.js +286 -0
  104. package/dist/meta/model.d.ts +44 -0
  105. package/dist/meta/model.js +119 -0
  106. package/dist/meta/prompts.d.ts +18 -0
  107. package/dist/meta/prompts.js +61 -0
  108. package/dist/meta/relay.d.ts +20 -0
  109. package/dist/meta/relay.js +123 -0
  110. package/dist/meta/tokens.d.ts +52 -0
  111. package/dist/meta/tokens.js +226 -0
  112. package/dist/meta/window.d.ts +61 -0
  113. package/dist/meta/window.js +198 -0
  114. package/dist/meta/wire.d.ts +42 -0
  115. package/dist/meta/wire.js +129 -0
  116. package/dist/meta.d.ts +71 -1
  117. package/dist/meta.js +303 -6
  118. package/dist/modelref.d.ts +16 -0
  119. package/dist/modelref.js +41 -0
  120. package/dist/narrate.js +5 -2
  121. package/dist/podman.d.ts +26 -0
  122. package/dist/podman.js +83 -3
  123. package/dist/projects.d.ts +0 -5
  124. package/dist/projects.js +2 -15
  125. package/dist/resources.d.ts +215 -0
  126. package/dist/resources.js +856 -0
  127. package/dist/sandbox.d.ts +2 -0
  128. package/dist/sandbox.js +10 -3
  129. package/dist/scaffold.d.ts +15 -7
  130. package/dist/scaffold.js +24 -67
  131. package/dist/session.js +4 -29
  132. package/dist/term.d.ts +2 -0
  133. package/dist/term.js +11 -2
  134. package/dist/trace.d.ts +5 -0
  135. package/dist/trace.js +107 -7
  136. package/dist/tui/app.js +19 -5
  137. package/dist/tui/links.d.ts +27 -0
  138. package/dist/tui/links.js +142 -0
  139. package/dist/tui/models.d.ts +35 -0
  140. package/dist/tui/models.js +447 -0
  141. package/dist/tui/sandbox.d.ts +10 -0
  142. package/dist/tui/sandbox.js +131 -0
  143. package/dist/tui/wrap.d.ts +5 -0
  144. package/dist/tui/wrap.js +12 -0
  145. package/dist/usage.d.ts +78 -0
  146. package/dist/usage.js +51 -0
  147. package/package.json +4 -2
  148. package/templates/editor/.github/copilot-instructions.md +60 -145
  149. package/templates/editor/.github/prompts/analyze.prompt.md +33 -0
  150. package/templates/editor/.github/prompts/dataset.prompt.md +108 -0
  151. package/templates/editor/.github/prompts/finetune-apply.prompt.md +270 -0
  152. package/templates/editor/.github/prompts/finetune.prompt.md +691 -198
  153. package/templates/editor/.github/prompts/new-agent.prompt.md +3 -1
  154. package/templates/editor/.github/prompts/new-skill.prompt.md +2 -0
  155. package/templates/editor/.github/prompts/project-review.prompt.md +5 -4
  156. package/templates/editor/.github/skills/zen-analyze-run/SKILL.md +588 -0
  157. package/templates/editor/.github/skills/zen-cli/SKILL.md +9 -1
  158. package/templates/editor/.github/skills/zen-cli/references/dataset.md +34 -0
  159. package/templates/editor/.github/skills/zen-cli/references/finetune.md +137 -0
  160. package/templates/editor/.github/skills/zen-cli/references/inspect.md +63 -11
  161. package/templates/editor/.github/skills/zen-cli/references/memory.md +33 -10
  162. package/templates/editor/.github/skills/zen-cli/references/meta.md +61 -0
  163. package/templates/editor/.github/skills/zen-cli/references/models.md +5 -1
  164. package/templates/editor/.github/skills/zen-cli/references/projects.md +4 -6
  165. package/templates/editor/.github/skills/zen-cli/references/rag.md +24 -6
  166. package/templates/editor/.github/skills/zen-cli/references/sandbox.md +35 -14
  167. package/templates/editor/.github/skills/zen-code-python/SKILL.md +123 -0
  168. package/templates/editor/.github/skills/zen-code-python/references/code_python.md +48 -0
  169. package/templates/editor/.github/skills/zen-dataset/SKILL.md +253 -0
  170. package/templates/editor/.github/skills/zen-finetune/SKILL.md +1492 -660
  171. package/templates/editor/.github/skills/zen-finetune/references/readme-template.md +268 -0
  172. package/templates/editor/.github/skills/zen-finetune/scripts/batch.mjs +390 -0
  173. package/templates/editor/.github/skills/zen-finetune/scripts/difficult.mjs +243 -0
  174. package/templates/editor/.github/skills/zen-finetune/scripts/memory.mjs +280 -0
  175. package/templates/editor/.github/skills/zen-finetune/scripts/next.mjs +398 -0
  176. package/templates/editor/.github/skills/zen-finetune/scripts/report.mjs +797 -0
  177. package/templates/editor/.github/skills/zen-finetune/scripts/select.mjs +354 -0
  178. package/templates/editor/.github/skills/zen-finetune/scripts/usage.mjs +722 -0
  179. package/templates/editor/.github/skills/zen-inspect/SKILL.md +74 -26
  180. package/templates/editor/.github/skills/zen-inspect-ask/SKILL.md +271 -0
  181. package/templates/editor/.github/skills/zen-instructions/SKILL.md +4 -12
  182. package/templates/editor/.github/skills/zen-memory/SKILL.md +82 -53
  183. package/templates/editor/.github/skills/zen-rag-docs/SKILL.md +20 -8
  184. package/templates/editor/.github/skills/zen-review/SKILL.md +8 -31
  185. package/templates/editor/.github/skills/zen-review/scripts/check-paths.sh +5 -5
  186. package/templates/editor/.github/skills/zen-review/scripts/review.sh +3 -12
  187. package/templates/editor/.github/skills/zen-sandbox/SKILL.md +9 -4
  188. package/templates/editor/.github/skills/zen-sandbox-capacity/SKILL.md +2 -2
  189. package/templates/editor/.github/skills/zen-spec-sync/SKILL.md +2 -4
  190. package/templates/editor/.github/skills/zen-topology/SKILL.md +283 -0
  191. package/templates/editor/.vscode/settings.json +1 -0
  192. package/templates/project/agents/files-instructions.md +29 -20
  193. package/templates/project/agents/fork-instructions.md +78 -28
  194. package/templates/project/agents/memory-instructions.md +222 -494
  195. package/templates/project/agents/tools-instructions.md +14 -4
  196. package/templates/project/gitignore +2 -0
  197. package/templates/editor/.github/skills/zen-finetune/scripts/collect.sh +0 -432
  198. package/templates/editor/.github/skills/zen-finetune/scripts/sample.sh +0 -199
  199. package/templates/editor/.github/skills/zen-memory/scripts/check-instructions.sh +0 -116
@@ -0,0 +1,108 @@
1
+ ---
2
+ description: Build or refresh this project's dataset - every case read from its sources with a class, complexity, tags, a verbatim rubric and an anchor - re-reading only the sections that changed since the last revision. Name a source after the command to add it, `rebuild` to read everything again, or a case and what to fix.
3
+ ---
4
+
5
+ Keep `dataset/` in step with its sources. **Load the `zen-dataset` skill before
6
+ anything else**, and `zen-cli` for the command reference. The skill holds the
7
+ extraction rules and every verb; this prompt is the order of the work. If
8
+ loading a skill fails, read `.github/skills/<name>/SKILL.md` with your file tool
9
+ before going on.
10
+
11
+ You never run cases, never edit `agents/`, and never edit a source. Only
12
+ `zen meta dataset` writes `dataset/` - never a file tool, never a script.
13
+
14
+ This prompt is **reentrant**: the state on disk says what to do, so running it
15
+ twice in a row does nothing the second time.
16
+
17
+ ## 1. Where things stand
18
+
19
+ ```sh
20
+ zen meta dataset status
21
+ zen meta dataset drift
22
+ zen meta dataset ls --note rubric-suspect
23
+ ```
24
+
25
+ Say in three lines: the revision and case count, the sources, and how many
26
+ sections are `changed`, `gone` or `uncovered`.
27
+
28
+ ## 2. What to do
29
+
30
+ The last line of this prompt may hold words. Then read the table top down and
31
+ take the first row that fits:
32
+
33
+ | State | Do |
34
+ | ---------------------------------------- | --------------------------------------------------------------------- |
35
+ | the words name a case and a fix | that fix only, with `update`, `retire` or `reanchor` - then section 6 |
36
+ | the words say `rebuild` | read every source in full, as a whole proposal - section 3 |
37
+ | the words name a source file | read that file in full, add it as a `--partial` proposal - section 3 |
38
+ | no dataset, and no source named anywhere | **stop**: say which training set to name. The only stop |
39
+ | no dataset | read every source `SPECIFICATION.md` points at - section 3 |
40
+ | drift reports anything | read only the drifted sections - section 3 |
41
+ | drift is clean | nothing to do: report the status and stop |
42
+
43
+ Never ask a question mid-run - nobody is there to answer it. What you could not
44
+ decide goes into the report and onto the case as a note.
45
+
46
+ ## 3. Read the sections
47
+
48
+ Read each section yourself and write the cases out by the skill's rules: the
49
+ rubric **verbatim**, class from the source's own distinctions, complexity from
50
+ the trajectory the query demands, an anchor on every case, and **the id a case
51
+ already has** when you re-read its section. Write them to
52
+ `.tmp/dataset/proposal.json`.
53
+
54
+ On a refresh, the proposal holds only the cases of the drifted sections, and is
55
+ applied `--partial`. A case whose section changed but which still asks, expects
56
+ and is judged the same goes in unchanged - that is how its drift is settled.
57
+
58
+ ## 4. Settle what is gone and what is new
59
+
60
+ Every `gone` and `uncovered` line from step 1 gets an answer, or the next drift
61
+ check reports it again:
62
+
63
+ - **gone** - the section was deleted: `retire <id> --why "…"`. It was renamed
64
+ or moved: `reanchor <id> --heading "…" --why "…"`.
65
+ - **uncovered** - it holds queries: they are new cases in the proposal. It does
66
+ not (an introduction, a glossary): `ignore <file> --heading "…" --why "…"`.
67
+
68
+ ## 5. Apply
69
+
70
+ ```sh
71
+ zen meta dataset apply .tmp/dataset/proposal.json [--partial] --dry-run
72
+ ```
73
+
74
+ Check the dry run against what you meant before writing anything:
75
+
76
+ - nothing `retired` you did not intend - a whole proposal retires every case it
77
+ leaves out
78
+ - no id changed for a case you only re-read
79
+ - every `restarted` case is one whose input, rubric or expected answer really
80
+ changed in the source
81
+
82
+ Then the same command without `--dry-run`, with `--why` naming what changed in
83
+ the source.
84
+
85
+ ## 6. Check
86
+
87
+ ```sh
88
+ zen meta dataset drift
89
+ zen meta dataset status
90
+ ```
91
+
92
+ Drift must be clean. The count per class must match a count you take from the
93
+ source by hand. Every media path must exist - apply refuses one that does not,
94
+ so a refusal here is a path to fix, not a step to skip.
95
+
96
+ ## 7. Report
97
+
98
+ - the revision, and what changed: added, updated, retired, restored and
99
+ **restarted** cases, by id
100
+ - cases per class and per complexity, and how many have a rubric
101
+ - what restarted means for whoever runs the cases next: their earlier results
102
+ are about a different question - `zen meta dataset sample --restarted` lists
103
+ them
104
+ - every case with an open `rubric-suspect` note, and what the source would
105
+ need to say
106
+ - what you could not decide, each with the case or section it is about; leave
107
+ each one on its case as well:
108
+ `zen meta dataset note <id> --kind observation -m "…"`
@@ -0,0 +1,270 @@
1
+ ---
2
+ description: Apply a batch of improvement requests from the tuning loop to the project's prose - merge them into patterns, edit prompts, skills and policy files, tidy up every file touched, and record what was done with each. Run by `zen meta finetune`; the line after the prompt names the apply directory, and a brief follows it.
3
+ ---
4
+
5
+ The tuning loop has collected improvement requests from several cases and
6
+ wants them applied **together**. The line after this prompt names the apply
7
+ directory.
8
+
9
+ Every sentence you add is read by every later call of every agent that loads
10
+ it, so prose has a price even when it fixes the case in front of you. The loop
11
+ measures it: after you finish, an apply that grows the prose past its budget
12
+ is **undone** - all of it. Then a few cases that passed before run again on
13
+ your edit; one it broke comes back to the next apply as a request.
14
+
15
+ ## What you are given
16
+
17
+ A `## The brief` section after that line is what the loop already read and
18
+ worked out for you, from the files below. Work from it:
19
+
20
+ - Do not read a file the brief shows, and do not run a command it shows -
21
+ until you have edited that file yourself.
22
+ - Do not parse `inputs.json`, `deferred.json`, `budget.json` or `growth.json`
23
+ with a script: `Requests by file`, `The requests`, `Growth` and the
24
+ `budget.json` block are their content. Open one only for a field the brief
25
+ marks `(cut at ...)` or `(left out ...)`.
26
+ - Do not open other `finetune/applies/*` folders: `Earlier tries of these
27
+ cases` is what they hold about these cases.
28
+
29
+ The files behind it:
30
+
31
+ - `<apply dir>/inputs.json` - the requests: each has `id` (`<case>@<phase>-<attempt>`),
32
+ `case`, `phase` (`nomem` or `mem`), `summary`, `improvements` (each with `id`,
33
+ `kind`, `file`, `change`, `why`, `expect`), `file`, the feedback it came from,
34
+ and `missedSkills` - skills an earlier apply made for this case that its last
35
+ run never loaded. The analysis behind each is `analysis.md` beside that file -
36
+ read it when an improvement is unclear.
37
+ A request with `recheck` (id `<case>@recheck-<apply>`) is a **regression**: the
38
+ case passed before that apply and failed twice on it. Its analysis quotes the
39
+ hunk of that apply's `diff.patch` that did it. Narrow or revert that rule -
40
+ never stack an exception under it.
41
+ - `<apply dir>/deferred.json` - improvements earlier applies held back because
42
+ only one case asked for them, with their case and apply. They count as
43
+ evidence below.
44
+ - `<apply dir>/budget.json` - what the agents read, in bytes: `alwaysRead` per
45
+ agent (house rules, its prompt, preloaded skills, the skill index lines),
46
+ `skills` (each on-demand skill body), `visible` (skills each agent can see),
47
+ the same at the start of the tuning (`start`), and the limits: `budget` (the
48
+ most this apply may add to the always-read total), `ceiling` (above it, an
49
+ apply may add nothing), `skillCap`, `maxSkills`.
50
+ - `<apply dir>/growth.json` - per file under `agents/`: bytes at the start of
51
+ the tuning and now, how many applies changed it, and the latest of them.
52
+ - Earlier requests of the same cases, and what each apply decided about them -
53
+ the brief's `Earlier tries of these cases`. Do not re-apply a rule an
54
+ earlier apply added and a later run showed did not work; change it instead.
55
+ - From your previous attempt, if it was undone - the first files in the brief:
56
+ `check.log` (it failed `zen check`), `budget.md` (it grew the prose past a
57
+ limit - this attempt must cut) and `missing.md` (it ended without a decision
58
+ for every improvement).
59
+
60
+ ## Load the skills
61
+
62
+ A request says what a run did wrong; the rules for fixing it live in the editor
63
+ skills, not in the request. The brief's `Skills to load` lists the ones this
64
+ project's capabilities call for. Load every one of them now, before the first
65
+ edit. Load `zen-sandbox` too when any improvement is about the container,
66
+ installing packages, or a command that failed for want of a tool. No other
67
+ `zen-*` skill is needed.
68
+
69
+ An improvement that already sounds right is not a reason to skip its skill -
70
+ the skill is how you find out whether it is.
71
+
72
+ ## What to do
73
+
74
+ 1. **Merge before editing.** The brief's `Requests by file` has already put
75
+ the improvements - and the entries of `deferred.json` - under the file each
76
+ names, with the distinct cases behind each file. Now group them by the
77
+ behaviour they fix, across files too. Several cases asking for the
78
+ same thing in different words is one pattern. Two that contradict each
79
+ other: decide, and say why. Count the **distinct cases** behind each
80
+ pattern.
81
+ 2. **Hold each against its skill.** An improvement's `change` is one analyst's
82
+ guess at the fix. A change that breaks a skill's rule - shell `grep` over an
83
+ index, a paraphrase of a copied house rule, a one-off inline script, a
84
+ handoff with no way back - is rewritten to what the skill prescribes, or
85
+ rejected naming the rule. When the skill already states the rule, the agent
86
+ never saw it: fix how the skill is reached (its description, a load line in
87
+ the prompt), not a second copy of the rule.
88
+ 3. **Prove the owner and the absence**, for every pattern:
89
+ 1. State the obligation in one sentence of your own, not the wording of
90
+ any request.
91
+ 2. Name exactly which agents must obey it, and choose the narrowest place
92
+ that reaches all of them - see the table in step 6.
93
+ 3. Search every file those agents read for the same obligation: house
94
+ rules (`agents/instructions.md`, every `agents/*-instructions.md`),
95
+ their prompts, their preloaded skills and the skills they would load
96
+ for it. Search its distinctive verbs and nouns and obvious other
97
+ wordings, not one exact quote.
98
+ 4. Choose exactly one disposition: `edit existing`, `move and delete`,
99
+ `delete contradiction`, `extract to skill`, or `add because absent`.
100
+ Every location found goes in `changes.md`.
101
+
102
+ If several places say it, consolidate into the one owner and delete the
103
+ others in this apply. If a broad rule caused the failure, rewrite or
104
+ narrow that rule - never keep it and add an exception elsewhere.
105
+
106
+ 4. **Evidence.** `add because absent` and `extract to skill` need **two or
107
+ more distinct cases** behind the pattern, counting `deferred.json`. With
108
+ one case you may only `edit existing`, `move and delete` or
109
+ `delete contradiction`, and only if the always-read total does not grow.
110
+ Anything else from one case is `deferred` - not applied, not rejected: it
111
+ comes back in `deferred.json` until a second case asks for it.
112
+ 5. **Generalise.** Write each rule for a class of queries, not for a case -
113
+ it must hold for queries no case asked. Never write a case's answer, ids,
114
+ names, numbers or data into the prose, nor an example lifted from a case's
115
+ query. Keep a specific only when the rule cannot be stated without it - a
116
+ tool, a command, a file path of this project. Before you save, check every
117
+ sentence you added: a noun, number or quoted phrase that comes from a case
118
+ and appears nowhere else in the project is overfit - replace it with the
119
+ class it belongs to, or drop the rule. A request that only makes sense for
120
+ its one case is rejected.
121
+ 6. **Route by behaviour, not by phase.** A request from a run with memory goes
122
+ where its behaviour is owned, like any other.
123
+
124
+ | The obligation is… | It goes in |
125
+ | -------------------------------------------------------------------- | --------------------------------------------------------- |
126
+ | one agent's behaviour, on every request it gets | `agents/prompts/<agent>.md` |
127
+ | a procedure or facts only some kinds of request need | an on-demand skill under `agents/skills/` - see step 7 |
128
+ | a standing rule every agent must obey | `agents/instructions.md` |
129
+ | what to commit to memory, when to recall, what to trust from it | `agents/memory-policy-instructions.md` |
130
+ | a rule every user of one capability must obey | that capability's `agents/<topic>-policy-instructions.md` |
131
+ | the wrong agent had a tool, a skill binding, the dataset or a rubric | **structural** - record it, do not compensate with prose |
132
+
133
+ 7. **Skills.** `extract to skill` moves a procedure or a set of facts out of a
134
+ prompt or a policy into `agents/skills/<name>/SKILL.md`, which the agent
135
+ loads only when a request needs it. Its body costs nothing until then; its
136
+ index line costs on every call.
137
+ - The prompt keeps **one line** pointing at the skill: the condition and
138
+ the name. Delete the moved prose from where it was.
139
+ - The `description:` says **when** to load it - the condition, in words a
140
+ request would match - and must not overlap another skill's.
141
+ - Never make a skill for one case's data: what one case needs to know
142
+ about its own data is memory's job. Rejected.
143
+ - A skill in `missedSkills` was not loaded by the case it was written for:
144
+ its description is the defect. Rewrite the description - not more
145
+ prose. A skill missed twice goes back into its owner (`move and delete`)
146
+ or into a skill that is loaded.
147
+ - Keep each skill under `skillCap` and each agent under `maxSkills`: an
148
+ oversized skill is split by when it is needed, overlapping ones merged.
149
+ - You cannot preload a skill: that is `agents.yaml`, structural.
150
+ 8. **Never write:**
151
+ - an exception stacked under a general rule, or "this overrides X" -
152
+ rewrite X;
153
+ - a tool-call script ("call A first", "read lines 1-200") - write the
154
+ invariant it serves;
155
+ - a prohibition with an exemption the agent judges for itself ("unless
156
+ clearly needed") - that is a permission. Forbid it, or do not.
157
+ 9. **Stay inside the budget** in `budget.json`. Over `ceiling`, this apply must
158
+ not grow the always-read total at all: cut, move or extract to make room.
159
+ 10. **Edit** prompts under `agents/prompts/`, skills under `agents/skills/`,
160
+ `agents/instructions.md` and `agents/<topic>-policy-instructions.md`
161
+ (create a policy file only when step 3 proved the rule absent and every
162
+ agent with that capability must obey it).
163
+ 11. **Never edit** `agents.yaml`, `agents/memory-instructions.md`,
164
+ `agents/tools-instructions.md`, `agents/fork-instructions.md` or
165
+ `agents/files-instructions.md`, nor anything outside `agents/`.
166
+ 12. **Tidy up every file you touched** - the whole file, not only your lines.
167
+ For each obligation in it, search the files the same agents read, and pick
168
+ one move:
169
+ - `merge duplicates` - the same obligation twice for the same audience:
170
+ keep it in the owner, delete the rest;
171
+ - `delete contradiction` - two sentences that cannot both be obeyed: keep
172
+ the one the later `changes.md` chose;
173
+ - `narrow` - a general rule followed by its exceptions: rewrite the rule so
174
+ it needs none, delete the exceptions;
175
+ - `move and delete` - a rule in a file wider than the agents it binds;
176
+ - `split skill` / `merge skills` - a skill over `skillCap`, two whose
177
+ descriptions overlap, or an agent over `maxSkills`.
178
+
179
+ Never weaken an obligation: what an agent must do stays what it must do.
180
+ The bytes this frees count against your budget, so a crowded file is where
181
+ to make room. Then take the largest growth in `growth.json` you did not
182
+ touch: if it says one thing twice, merge it too.
183
+
184
+ 13. **Read it back.** Search again for each obligation's terms, and read each
185
+ affected agent's prompt in the order it is assembled - house rules first,
186
+ then its prompt. Every remaining copy must have a different audience, or
187
+ go.
188
+ 14. **Gate**: when your edits are done, run once
189
+ `zen meta finetune gate <apply dir>`. It judges the edit exactly as the
190
+ loop will after you: the bytes moved per agent, skill and file, any limit
191
+ broken, and `zen check`. On `gate: fail`, fix what it names and run it
192
+ again. Do not measure or diff files yourself and do not use git: the loop
193
+ never commits, so `git diff` mixes in earlier applies, and it records the
194
+ diff and the bytes of this apply after you finish.
195
+
196
+ ## What to write
197
+
198
+ - `<apply dir>/changes.md` - read by a person deciding whether to trust this
199
+ apply, so leave nothing out. One section per file you touched:
200
+
201
+ ```markdown
202
+ ## agents/prompts/default.md
203
+
204
+ **Answers:** plan-day@nomem-1 i1, long-list-3@nomem-1 i1 (merged)
205
+
206
+ **The pattern:** what the cases did wrong, in one paragraph, with the node
207
+ ids from their analyses - not a case's answer.
208
+
209
+ **Obligation:** the one sentence of step 3, and the agents it binds.
210
+
211
+ **Searched:** the terms you searched for, and every place they were found.
212
+
213
+ **Disposition:** `edit existing`, `move and delete`, `delete contradiction`,
214
+ `extract to skill` or `add because absent` - with the cases behind it.
215
+
216
+ **After:** the text as it is now, quoted.
217
+
218
+ **Checked against:** the skill and rule it was held to, or "no skill
219
+ covers this".
220
+
221
+ **Why it generalises:** which queries beyond these cases it changes, and
222
+ which it must not.
223
+
224
+ **Expect:** what the next run's graph should show if it worked - for a
225
+ skill, the `skills <name>` node before the step it covers.
226
+ ```
227
+
228
+ A section for a tidy-up move has **Move**, **Obligation** and **After**
229
+ only. The diff and the bytes moved are added by the loop - do not write
230
+ them.
231
+
232
+ Then a section **Not applied**: every rejected, deferred or structural
233
+ improvement, with why.
234
+
235
+ - `<apply dir>/decisions.json` - a decision for **every** improvement of every
236
+ request, nothing skipped. When you apply or merge an entry of
237
+ `deferred.json`, add it under its own request id too:
238
+
239
+ ```json
240
+ {
241
+ "plan-day@nomem-1": {
242
+ "i1": {
243
+ "decision": "applied",
244
+ "disposition": "extract to skill",
245
+ "skill": "calendar-planning",
246
+ "note": "agents/skills/calendar-planning - planning procedure moved out of the prompt"
247
+ },
248
+ "i2": { "decision": "merged", "note": "same rule as long-list-3@nomem-1 i1" }
249
+ },
250
+ "long-list-3@nomem-1": {
251
+ "i1": {
252
+ "decision": "applied",
253
+ "disposition": "edit existing",
254
+ "note": "agents/pagination-policy-instructions.md"
255
+ },
256
+ "i2": { "decision": "structural", "note": "needs a tool in agents.yaml" },
257
+ "i3": { "decision": "rejected", "note": "only true for this case's data" },
258
+ "i4": { "decision": "deferred", "note": "one case; waits for a second" }
259
+ }
260
+ }
261
+ ```
262
+
263
+ `decision` is one of `applied`, `merged`, `rejected`, `deferred`, `structural`.
264
+ `disposition` is the one from step 3, on every `applied`. `skill` names the
265
+ skill an improvement created or changed - the loop checks the case's next run
266
+ loads it. The note is one line a person reads in the case's FEEDBACK.md.
267
+
268
+ Your answer is a short summary: how many rules, which files, what the tidy-up
269
+ merged or cut, the net change in bytes `gate` printed, and anything structural
270
+ the user must decide.