geneseed 5.3.1 → 5.5.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 (248) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +51 -18
  3. package/SHIPPED.md +7 -7
  4. package/adapters/bob/README.md +12 -1
  5. package/adapters/opencode/README.md +5 -3
  6. package/adapters/opencode/plugins/geneseed-context.js +77 -10
  7. package/adapters/opencode/plugins/geneseed-guard.js +106 -22
  8. package/adapters/opencode/plugins/geneseed-learn.js +641 -6
  9. package/bin/geneseed-cli.mjs +10 -0
  10. package/bin/geneseed-hook.mjs +5 -4
  11. package/docs/PRD.md +1 -1
  12. package/docs/README.md +1 -0
  13. package/docs/concepts/agents.md +14 -2
  14. package/docs/concepts/collaboration.md +2 -2
  15. package/docs/concepts/enforcement-table.md +5 -2
  16. package/docs/concepts/exclusions.md +16 -2
  17. package/docs/concepts/footprint.md +1 -1
  18. package/docs/concepts/foreman-mode.md +23 -4
  19. package/docs/concepts/hook-gates.md +4 -4
  20. package/docs/concepts/hooks.md +25 -7
  21. package/docs/concepts/host-matrix.md +4 -4
  22. package/docs/concepts/hosts.md +1 -1
  23. package/docs/concepts/kits.md +12 -2
  24. package/docs/concepts/loop-bricks.md +3 -3
  25. package/docs/concepts/loops.md +6 -4
  26. package/docs/concepts/ownership.md +1 -1
  27. package/docs/concepts/rules.md +2 -2
  28. package/docs/concepts/shared-tier.md +1 -1
  29. package/docs/concepts/skills.md +21 -1
  30. package/docs/concepts/themes.md +1 -1
  31. package/docs/extending.md +73 -29
  32. package/docs/guides/auto-merge.md +100 -0
  33. package/docs/guides/choose-your-setup.md +1 -1
  34. package/docs/guides/headless.md +1 -1
  35. package/docs/guides/install-clone.md +19 -1
  36. package/docs/guides/install-scripted.md +8 -2
  37. package/docs/guides/install.md +20 -2
  38. package/docs/guides/loop-finish.md +3 -3
  39. package/docs/guides/loop-running.md +4 -4
  40. package/docs/guides/project-context.md +1 -1
  41. package/docs/guides/run-a-factory.md +2 -2
  42. package/docs/guides/setup-doctrines.md +2 -2
  43. package/docs/guides/setup-footprint.md +1 -1
  44. package/docs/guides/uninstall.md +3 -3
  45. package/docs/guides/upgrade.md +2 -2
  46. package/docs/guides/worktree.md +1 -1
  47. package/docs/reference/env-context.md +1 -1
  48. package/docs/reference/environment.md +4 -2
  49. package/docs/reference/plugin-activity.md +1 -1
  50. package/docs/reference/plugin-guard.md +1 -1
  51. package/docs/reference/plugin-learn.md +5 -1
  52. package/docs/reference/plugin-workflow.md +1 -1
  53. package/docs/reference/profiles.md +142 -0
  54. package/docs/reference/troubleshoot-doctor.md +1 -1
  55. package/docs/reference/troubleshoot-hooks.md +2 -2
  56. package/docs/reference/troubleshoot-install.md +3 -3
  57. package/docs/reference/troubleshoot-tools.md +1 -1
  58. package/docs/token-footprint.md +11 -6
  59. package/docs/understand/design-choices-engineering.md +1 -1
  60. package/docs/understand/enforced-vs-asked.md +1 -1
  61. package/docs/understand/machine-claude.md +2 -2
  62. package/docs/understand/on-your-machine.md +1 -1
  63. package/docs/web-ui.md +8 -6
  64. package/harness.config.json +1 -1
  65. package/js/README.md +11 -3
  66. package/js/build/args.mjs +16 -4
  67. package/js/build/catalog.mjs +11 -1
  68. package/js/build/driver.mjs +74 -16
  69. package/js/build/emit-claude.mjs +32 -5
  70. package/js/build/emit-opencode.mjs +16 -9
  71. package/js/build/export.mjs +1 -1
  72. package/js/build/generate.mjs +12 -157
  73. package/js/build/notes-migrate.mjs +99 -0
  74. package/js/build/profile.mjs +326 -0
  75. package/js/build/render.mjs +110 -8
  76. package/js/build/retired-skills.mjs +60 -13
  77. package/js/build/source.mjs +100 -3
  78. package/js/build/stubs.mjs +4 -1
  79. package/js/cli-table.json +212 -7
  80. package/js/hosts/agent-runs.mjs +205 -0
  81. package/js/hosts/done-checks.mjs +3 -1
  82. package/js/hosts/hooks-done.mjs +428 -63
  83. package/js/hosts/hooks-learn.mjs +89 -3
  84. package/js/hosts/hooks-prims.mjs +44 -4
  85. package/js/hosts/hooks.mjs +159 -9
  86. package/js/hosts/hosts.mjs +10 -0
  87. package/js/hosts/installs.mjs +44 -2
  88. package/js/hosts/link.mjs +45 -10
  89. package/js/hosts/native.mjs +61 -7
  90. package/js/hosts/opencode.mjs +1 -1
  91. package/js/hosts/settings.mjs +101 -3
  92. package/js/hosts/spec-feedback.mjs +538 -0
  93. package/js/hosts/usage.mjs +67 -8
  94. package/js/inspect/agent-scores.mjs +118 -0
  95. package/js/inspect/checks-authoring.mjs +2 -1
  96. package/js/inspect/checks-build.mjs +20 -4
  97. package/js/inspect/checks-constitution.mjs +32 -0
  98. package/js/inspect/checks-repo.mjs +27 -2
  99. package/js/inspect/cost.mjs +6 -5
  100. package/js/inspect/diff.mjs +46 -8
  101. package/js/inspect/doctor.mjs +4 -0
  102. package/js/inspect/inventory.mjs +1 -1
  103. package/js/inspect/status.mjs +3 -1
  104. package/js/inspect/validate.mjs +1 -0
  105. package/js/lib/machine-dir.mjs +8 -0
  106. package/js/lib/paths.mjs +4 -1
  107. package/js/maintain/profile-scope.mjs +145 -0
  108. package/js/maintain/profiles.mjs +486 -0
  109. package/js/maintain/setup.mjs +413 -15
  110. package/js/maintain/uninstall.mjs +4 -1
  111. package/js/maintain/update.mjs +4 -2
  112. package/js/web/actions.mjs +44 -41
  113. package/js/web/api.mjs +13 -3
  114. package/js/web/handler.mjs +8 -0
  115. package/js/web/jobs.mjs +5 -4
  116. package/js/web/profiles-api.mjs +201 -0
  117. package/js/web/routes.mjs +5 -0
  118. package/package.json +2 -1
  119. package/profiles/guillaume-claude-global.json +16 -0
  120. package/profiles/starter.json +14 -0
  121. package/registry.json +14 -0
  122. package/src/AGENT.md.tmpl +16 -18
  123. package/src/agents/_self-improvement.md +15 -7
  124. package/src/agents/_template.md +4 -2
  125. package/src/agents/advocate.md +1 -1
  126. package/src/agents/architect.md +1 -1
  127. package/src/agents/developer.md +10 -3
  128. package/src/agents/devops-engineer.md +1 -1
  129. package/src/agents/docker-expert.md +1 -1
  130. package/src/agents/docs.md +1 -1
  131. package/src/agents/empiricist.md +1 -1
  132. package/src/agents/explorer.md +4 -2
  133. package/src/agents/framer.md +1 -1
  134. package/src/agents/historian.md +1 -1
  135. package/src/agents/kubernetes-specialist.md +1 -1
  136. package/src/agents/memory-curator.md +1 -1
  137. package/src/agents/operator.md +1 -1
  138. package/src/agents/performance.md +1 -1
  139. package/src/agents/pragmatist.md +1 -1
  140. package/src/agents/react-engineer.md +1 -1
  141. package/src/agents/react-reviewer.md +1 -1
  142. package/src/agents/researcher.md +1 -1
  143. package/src/agents/reviewer.md +10 -3
  144. package/src/agents/security.md +1 -1
  145. package/src/agents/skeptic.md +1 -1
  146. package/src/agents/spring-boot-engineer.md +1 -1
  147. package/src/agents/spring-reviewer.md +1 -1
  148. package/src/agents/spring-security.md +1 -1
  149. package/src/agents/steward.md +1 -1
  150. package/src/agents/tester.md +4 -2
  151. package/src/agents/user-advocate.md +1 -1
  152. package/src/agents/visionary.md +1 -1
  153. package/src/bricks/pr-open.md +3 -2
  154. package/src/doctrines/ops.md +2 -2
  155. package/src/doctrines/process.md +40 -36
  156. package/src/factories/analysis-to-build.json +1 -1
  157. package/src/factories/bug-report-to-fix.json +1 -1
  158. package/src/factories/issue-to-pr.json +1 -1
  159. package/src/kits/terminal-tools/rules.md +10 -0
  160. package/src/kits/terminal-tools.json +13 -0
  161. package/src/licenses/herdr.txt +201 -0
  162. package/src/memory/README.md +12 -2
  163. package/src/modes/foreman.md +25 -9
  164. package/src/skill-descriptions.json +63 -0
  165. package/src/skills/_self-improvement.md +42 -24
  166. package/src/skills/_template.md +3 -1
  167. package/src/skills/brainstorm.md +35 -22
  168. package/src/skills/commit.md +17 -17
  169. package/src/skills/daydream/VENDOR.md +6 -0
  170. package/src/skills/debug/ci.md +1 -1
  171. package/src/skills/dependencies.md +3 -3
  172. package/src/skills/diagram-design/VENDOR.md +4 -0
  173. package/src/skills/document-project.md +3 -2
  174. package/src/skills/explain-changes/VENDOR.md +5 -1
  175. package/src/skills/factory.md +13 -4
  176. package/src/skills/geneseed.md +4 -2
  177. package/src/skills/git-history.md +5 -7
  178. package/src/skills/herdr.md +135 -0
  179. package/src/skills/loop.md +3 -2
  180. package/src/skills/opencode-cli.md +84 -0
  181. package/src/skills/parallel-agents.md +11 -0
  182. package/src/skills/pipeline.md +3 -3
  183. package/src/skills/plan.md +5 -4
  184. package/src/skills/react-view-transitions/VENDOR.md +7 -1
  185. package/src/skills/release.md +11 -9
  186. package/src/skills/review-response.md +4 -2
  187. package/src/skills/rule/approve.md +2 -1
  188. package/src/skills/rule.md +27 -1
  189. package/src/skills/ship.md +54 -7
  190. package/src/skills/skill-forge.md +5 -3
  191. package/src/skills/token-report/VENDOR.md +5 -1
  192. package/src/skills/worktree.md +2 -2
  193. package/src/upstreams.json +9 -2
  194. package/themes/README.md +3 -1
  195. package/themes/_TEMPLATE.json +2 -0
  196. package/themes/biker.json +2 -0
  197. package/themes/commentator.json +2 -0
  198. package/themes/cyberpunk.json +2 -0
  199. package/themes/gamer.json +2 -0
  200. package/themes/imperial.json +2 -0
  201. package/themes/joker.json +2 -0
  202. package/themes/marvin.json +2 -0
  203. package/themes/mean.json +2 -0
  204. package/themes/military.json +2 -0
  205. package/themes/neutral.json +2 -0
  206. package/themes/pirate.json +2 -0
  207. package/themes/sports.json +2 -0
  208. package/themes/verstappen.json +2 -0
  209. package/themes/wizard.json +2 -0
  210. package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
  211. package/web/dist/assets/Activity-LKsDzsnK.js +1 -0
  212. package/web/dist/assets/ActivityDetail-DhwTfPm6.js +1 -0
  213. package/web/dist/assets/{Bonsai-BBl4XXqs.js → Bonsai-CePMLrpr.js} +1 -1
  214. package/web/dist/assets/{CopyButton-Beven8yn.js → CopyButton-CuoaJ6k7.js} +1 -1
  215. package/web/dist/assets/Dashboard-D1VKuvLe.js +2 -0
  216. package/web/dist/assets/Docs-CUrHJKaU.js +5 -0
  217. package/web/dist/assets/Factories-Ci1XfmSy.js +1 -0
  218. package/web/dist/assets/{GreenhouseView-Bce212qd.js → GreenhouseView-CNfH2lPK.js} +1 -1
  219. package/web/dist/assets/Installs-ZHQZM1iS.js +3 -0
  220. package/web/dist/assets/{JournalView-CV4omyww.js → JournalView-CMsWahkS.js} +1 -1
  221. package/web/dist/assets/Kits-CkliyK0n.js +1 -0
  222. package/web/dist/assets/Laws-hh4O3HZ4.js +4 -0
  223. package/web/dist/assets/{LibRows-Dag1s0ZX.js → LibRows-Brv0Hmkr.js} +1 -1
  224. package/web/dist/assets/Library-BYmiLjJr.js +3 -0
  225. package/web/dist/assets/Loops-ytm-xJ68.js +2 -0
  226. package/web/dist/assets/{OperatorHudView-JmYY1pBR.js → OperatorHudView-KaqCx_HP.js} +1 -1
  227. package/web/dist/assets/Personal-CmcnRKYE.js +2 -0
  228. package/web/dist/assets/Settings-tUrpdOfq.js +1 -0
  229. package/web/dist/assets/{Tabs-8zsyEPSK.js → Tabs-CD7etcGD.js} +1 -1
  230. package/web/dist/assets/api-CZ-x0iWG.js +1 -0
  231. package/web/dist/assets/{controls-D4wmg_pl.js → controls-CK7qHA8H.js} +1 -1
  232. package/web/dist/assets/{index-CRWqKxfY.css → index-Ba_Kg3Af.css} +1 -1
  233. package/web/dist/assets/index-COKbhFNo.js +6 -0
  234. package/web/dist/index.html +3 -3
  235. package/web/dist/assets/Activity-WQ3ykgxU.js +0 -1
  236. package/web/dist/assets/ActivityDetail-7rt04SkS.js +0 -1
  237. package/web/dist/assets/Dashboard-BgLArtgu.js +0 -2
  238. package/web/dist/assets/Docs-B5aHp86J.js +0 -5
  239. package/web/dist/assets/Factories-BjqzXAw8.js +0 -1
  240. package/web/dist/assets/Installs-B1OsrHXF.js +0 -3
  241. package/web/dist/assets/Kits-CW1e7xNa.js +0 -1
  242. package/web/dist/assets/Laws-1Ckf1lbs.js +0 -4
  243. package/web/dist/assets/Library-B3FuFLel.js +0 -3
  244. package/web/dist/assets/Loops-CwqgnLNw.js +0 -2
  245. package/web/dist/assets/Personal-DKLgLa7Z.js +0 -2
  246. package/web/dist/assets/Settings-BwErnh-R.js +0 -1
  247. package/web/dist/assets/api-DLDVY3K-.js +0 -1
  248. package/web/dist/assets/index-Ce6qF2nG.js +0 -6
@@ -0,0 +1,205 @@
1
+ /**
2
+ * THE AGENT OUTCOME LEDGER — did a spec refinement make an agent better? One line per finished
3
+ * sub-agent, appended to `<install>/notebook/agent-runs.jsonl` beside `usage.jsonl`:
4
+ * `{"ts":"2026-11-14","agent":"developer","spec":"56510da85fb8","done":"ended","blocks":0,
5
+ * "tools":42,"refused":1,"feedback":0,"report":true}`. `spec` is a short hash of the agent's
6
+ * rendered spec, so the runs before and after a spec edit fall into two rows of
7
+ * `geneseed catalog agents --scores` (js/inspect/agent-scores.mjs).
8
+ *
9
+ * MECHANICAL ONLY (user decision 2026-11-14, "v1 mechanical only"). Every field is a fact the hook
10
+ * reads off the transcript, the install or the done gate's own state, never a score the agent gives
11
+ * itself, and nothing waits on a model remembering a step: that is what kept the spec-feedback loop
12
+ * empty until the hook captured it (./spec-feedback.mjs).
13
+ *
14
+ * WHAT `done` CAN SAY. On SubagentStop, `doneGate` (./hooks-done.mjs) returns 'block' or null, and
15
+ * a block returns before this runs, so a line is written only for a stop that ended the turn.
16
+ * Pass, advisory, cap reached and a skipped gate all return null, so they cannot be told apart
17
+ * here: `done` is "ended" (the gate ran over a transcript and let the turn end), "not-judged" (the
18
+ * gate ran with no transcript to read, or on Bob) or null (the gate did not run: switched off, or a
19
+ * manual `--file` run). `blocks` is how many times the gate blocked this turn before it ended, read
20
+ * from the cap state the gate itself wrote (`blocksOf`). A richer verdict needs a richer `doneGate`
21
+ * return, which is that file's change to make.
22
+ *
23
+ * The same privacy rules as `usage.jsonl` (./usage.mjs): counts only, the day not the instant,
24
+ * never a prompt, an argument or a path. Off when `GENESEED_NO_USAGE` is set or `.usage-off` exists,
25
+ * and only when `<install>/notebook` exists (never created here).
26
+ *
27
+ * ON THE HOOK PATH: builtins and sibling hook modules only, no spawn, nothing printed, and every
28
+ * error swallowed. Parallel sub-agents end together; each line is one `appendFileSync` of well
29
+ * under a page, as `usage.jsonl` is written, so each lands whole without a lock.
30
+ */
31
+ import { createHash } from 'node:crypto';
32
+ import { appendFileSync, existsSync, readFileSync, statSync } from 'node:fs';
33
+ import path from 'node:path';
34
+ import { GLOBAL_MANIFEST } from './hosts.mjs';
35
+ import { SECRET_RE, splitLines } from './hooks-prims.mjs';
36
+ import { specFeedbackOf } from './spec-feedback.mjs';
37
+ import { capFile, isPrompt } from './hooks-done.mjs';
38
+ import { RUNS_LEDGER, USAGE_OFF } from './usage.mjs';
39
+
40
+ export { RUNS_LEDGER };
41
+
42
+ // ---- agent-runs twin: BEGIN — adapters/opencode/plugins/geneseed-learn.js carries everything down
43
+ // to the END marker verbatim, with `export ` dropped (`node tests/twins.mjs --write` after a change).
44
+
45
+ /**
46
+ * A refused tool call: the result text a host or a gate gives a call it did not run. Only the
47
+ * result's FIRST line is read, and every marker is anchored at its start (a host prefix of at most
48
+ * 80 characters allowed for Geneseed's own words): a red test or a search that QUOTES a gate's text
49
+ * further down its output is an error, not a refusal. One row each, with where its text comes from:
50
+ * - Geneseed's own refusal (`gateText` mode `refused`, js/hosts/hooks-prims.mjs), and the text
51
+ * said when that text fails (`GATE_UNSAID`), behind a host's prefix ("PreToolUse:Bash hook …").
52
+ * - The OpenCode guard: V1 throws `[geneseed-guard] blocked: …`; V2 renames the call, and core
53
+ * answers `No tool named "BLOCKED, not a missing tool: …"` (geneseed-guard.js, seen on 2.2.6).
54
+ * - Claude Code's auto-mode classifier, seen live 2026-11-14: "Permission for this action was
55
+ * denied by the Claude Code auto mode classifier."
56
+ * - Claude Code's worktree isolation, seen live 2026-11-14: "This agent is isolated in the
57
+ * worktree …, but this command … Refusing to run it — …".
58
+ * - Claude Code's permission rule deny and a user's "no" to an ask: UNVERIFIED wording.
59
+ */
60
+ export const REFUSAL_MARKERS = [
61
+ /^.{0,80}?Tell the user this, word for word:/,
62
+ /^.{0,80}?Geneseed could not describe this call\./,
63
+ /^\[geneseed-guard\] blocked:/,
64
+ /^No tool named "BLOCKED, not a missing tool:/,
65
+ /^Permission for this action was denied\b/,
66
+ /^This agent is isolated in the worktree .{1,600}? Refusing to run it\b/,
67
+ /^Permission to use \S.{0,300}? has been denied\b/,
68
+ /^The user doesn't want to (?:proceed with|take) this/,
69
+ ];
70
+
71
+ /**
72
+ * True when the first line of `text` (a tool result) says the call was refused. Each marker is
73
+ * anchored with `^` (no `m` flag) and its `.` never crosses a line break, so a marker can only
74
+ * match on the first line.
75
+ */
76
+ export function isRefusal(text) {
77
+ const t = String(text ?? '').trimStart();
78
+ return REFUSAL_MARKERS.some((re) => re.test(t));
79
+ }
80
+
81
+ /** The short hash of a rendered spec: sha256 of its text with line endings folded to LF, 12 hex. */
82
+ export function specHashOf(text) {
83
+ return createHash('sha256').update(String(text).replace(/\r\n?/g, '\n'), 'utf8').digest('hex').slice(0, 12);
84
+ }
85
+
86
+ /** The ledger line, field order fixed. `ts` is the UTC day, as `usage.jsonl` stamps it. */
87
+ export function agentRunLine(run, now = new Date()) {
88
+ return `${JSON.stringify({
89
+ ts: now.toISOString().slice(0, 10), agent: run.agent, spec: run.spec ?? null, done: run.done ?? null,
90
+ blocks: run.blocks ?? null, tools: run.tools ?? null, refused: run.refused ?? null,
91
+ feedback: run.feedback ?? 0, report: Boolean(run.report),
92
+ })}\n`;
93
+ }
94
+ // ---- agent-runs twin: END
95
+
96
+ /**
97
+ * `<install>/agents/<agent>.md`'s hash when Geneseed ships it there (its manifest's `owned` names
98
+ * it), else null: general-purpose, Explore and a user's own agent have no rendered spec to compare.
99
+ */
100
+ export function specOf(install, agent) {
101
+ try {
102
+ const owned = JSON.parse(readFileSync(path.join(install, GLOBAL_MANIFEST), 'utf8')).owned;
103
+ const rel = `agents/${agent}.md`;
104
+ if (!Array.isArray(owned) || !owned.includes(rel)) return null;
105
+ return specHashOf(readFileSync(path.join(install, 'agents', `${agent}.md`), 'utf8'));
106
+ } catch { return null; }
107
+ }
108
+
109
+ /** A tool result's text: a string, or its text blocks joined. */
110
+ function resultText(b) {
111
+ if (typeof b.content === 'string') return b.content;
112
+ if (!Array.isArray(b.content)) return '';
113
+ return b.content.filter((x) => x && x.type === 'text' && typeof x.text === 'string').map((x) => x.text).join('\n');
114
+ }
115
+
116
+ /**
117
+ * `{ tools, refused, opening }` for the current turn of a sub-agent transcript's TEXT, or null when
118
+ * `whole` is false and the text holds no prompt (the tail reader then reads further back).
119
+ * `opening` is the gate's key for the turn (`turnOf`): the prompt line's `uuid`, else its content.
120
+ */
121
+ export function runCounts(raw, whole = true) {
122
+ const entries = [];
123
+ for (const line of splitLines(raw)) {
124
+ if (!line.trim()) continue;
125
+ try { entries.push(JSON.parse(line)); } catch { /* a torn line is no call */ }
126
+ }
127
+ let start = -1;
128
+ // The gate's own rule (./hooks-done.mjs `isPrompt`, sidechain mode). A resumed sub-agent appends
129
+ // its next turn to the same file, so the counts are the CURRENT turn's, as the gate judges it.
130
+ for (let i = entries.length - 1; i >= 0; i -= 1) if (entries[i] && isPrompt(entries[i], true)) { start = i + 1; break; }
131
+ if (start === -1) {
132
+ if (!whole) return null;
133
+ start = 0;
134
+ }
135
+ const first = entries[start - 1];
136
+ const opening = !first ? '' : typeof first.uuid === 'string' ? first.uuid
137
+ : JSON.stringify(first.message && first.message.content).slice(0, 300);
138
+ let tools = 0;
139
+ let refused = 0;
140
+ for (const obj of entries.slice(start)) {
141
+ const content = obj.message && obj.message.content;
142
+ if (!Array.isArray(content)) continue;
143
+ for (const b of content) {
144
+ if (!b || typeof b !== 'object') continue;
145
+ if (b.type === 'tool_use') tools += 1;
146
+ else if (b.type === 'tool_result' && b.is_error === true && isRefusal(resultText(b))) refused += 1;
147
+ }
148
+ }
149
+ return { tools, refused, opening };
150
+ }
151
+
152
+ /**
153
+ * How many times the done gate blocked this sub-agent's turn: `total` in the cap state it saved
154
+ * (./hooks-done.mjs `capFile`), when that state is this turn's (same `opening`); 0 with no state,
155
+ * or another turn's.
156
+ */
157
+ export function blocksOf(install, meta, opening) {
158
+ const file = install ? capFile(install, { ...meta, hook_event_name: 'SubagentStop' }) : null;
159
+ if (!file) return 0;
160
+ try {
161
+ const state = JSON.parse(readFileSync(file, 'utf8'));
162
+ if (!state || state.opening !== opening) return 0;
163
+ return Number.isInteger(state.total) ? state.total : Number.isInteger(state.blocks) ? state.blocks : 0;
164
+ } catch { return 0; }
165
+ }
166
+
167
+ /** True when the ledger is switched off for `install`, or has nowhere to go. */
168
+ function ledgerOff(install) {
169
+ if (!install || process.env.GENESEED_NO_USAGE) return true;
170
+ if (existsSync(path.join(install, USAGE_OFF))) return true;
171
+ try { return !statSync(path.join(install, 'notebook')).isDirectory(); } catch { return true; }
172
+ }
173
+
174
+ /**
175
+ * The SubagentStop write: one line for `agent`'s finished turn. `done` is `cmdLearn`'s reading of
176
+ * the gate (see the header), `report` the sub-agent's final report text (`subagentReport`), `read`
177
+ * the Stop's shared transcript reader. Returns the line written, or null. Never throws.
178
+ * @param {string | null} install
179
+ * @param {string | null} agent
180
+ * @param {Record<string, any>} meta
181
+ * @param {{ done?: string | null, report?: string, read?: Function | null }} [opts]
182
+ * @param {Date} [now]
183
+ */
184
+ export function recordAgentRun(install, agent, meta, { done = null, report = '', read } = {}, now = new Date()) {
185
+ try {
186
+ if (!agent || ledgerOff(install)) return null;
187
+ const tp = typeof meta.agent_transcript_path === 'string' && meta.agent_transcript_path ? meta.agent_transcript_path : null;
188
+ let counts = null;
189
+ if (tp && read) {
190
+ try { counts = read(tp, (raw, whole) => runCounts(raw, whole)); } catch { counts = null; }
191
+ }
192
+ const line = agentRunLine({
193
+ agent, spec: specOf(install, agent), done,
194
+ blocks: done === 'ended' && counts ? blocksOf(install, meta, counts.opening) : null,
195
+ tools: counts ? counts.tools : null, refused: counts ? counts.refused : null,
196
+ // The agent's own lines: a `[skill:…]` line it relays is about a skill, not its spec.
197
+ feedback: specFeedbackOf(report, SECRET_RE).filter((f) => !f.skill).length, report: Boolean(String(report || '').trim()),
198
+ }, now);
199
+ const file = path.join(install, RUNS_LEDGER);
200
+ // One line in one `appendFileSync` (O_APPEND), as usage.jsonl is written: parallel stops each
201
+ // land a whole line, so there is no lock to wait on.
202
+ appendFileSync(file, line);
203
+ return line;
204
+ } catch { return null; }
205
+ }
@@ -82,7 +82,9 @@ export const INFERRED_FROM = ['package.json', ...MANIFEST_CHECKS.map(([f]) => /*
82
82
  * - the git root's manifests only — a monorepo's subprojects (`pnpm -r test`,
83
83
  * `./gradlew :app:test`, `mvn -pl core test`) are neither inferred nor matched;
84
84
  * - a sibling script (`npm run test:unit`) or a runner called directly (`npx vitest`);
85
- * - a prefix before the command (`CI=1 npm test`, `mvn -q test`): forms match verbatim.
85
+ * - a prefix before the command (`CI=1 npm test`, `mvn -q test`): forms match verbatim, save
86
+ * for `npm --prefix <project>`, `git -C <project>` and `--test-concurrency N`, which
87
+ * `normalizeRun` (`./hooks-done.mjs`) takes off both sides.
86
88
  */
87
89
  export function inferDoneChecks(root) {
88
90
  const has = (f) => existsSync(path.join(root, f));