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
@@ -19,9 +19,10 @@
19
19
  // the developer's personal `.geneseed/ownership.md` holds `Setup: declined <date>`.
20
20
  // High-confidence patterns only, so legitimate work is never caught. Borderline cases
21
21
  // (.env edits) are WARNED, not blocked. Every block is recorded in the gate
22
- // ledger (`<cfg>/notebook/gates.jsonl`) under the hook's rule key (`law-1`, `rigor-5`,
22
+ // ledger (the install's `notebook/gates.jsonl`, `notebookHome`) under the hook's rule key (`law-1`, `rigor-5`,
23
23
  // `law-4`, `ops-2`, `process-1`, `wiki`, `ownership`); every skill or subagent call, blocked or not, is
24
- // counted in `<cfg>/notebook/usage.jsonl` when that `notebook/` exists and `.usage-off` does not.
24
+ // counted in the install's `notebook/usage.jsonl` (`usageHome`) when that `notebook/` exists and
25
+ // `.usage-off` does not, and so is a V1 `/skill` command.
25
26
  //
26
27
  // GENESEED_GUARD=off disable entirely.
27
28
  // GENESEED_GUARD=warn downgrade every block to a warning (log, but allow).
@@ -210,13 +211,16 @@ function say(msg, level = "warn") {
210
211
  const log = (msg) => say(msg)
211
212
 
212
213
  // ---- the gate ledger ------------------------------------------------------------
213
- // The twin of `ledger()` in js/hosts/hooks.mjs: one JSON line per BLOCK into
214
- // `<cfg>/notebook/gates.jsonl`, the rule and never the content, so `geneseed status` can
215
- // count what the boundary actually caught on an OpenCode install too. Until this the
216
- // recommended install was the one with no gate evidence at all. A warning is not recorded
217
- // (nothing was refused) and neither is `GENESEED_GUARD=warn`. `notebook/` is never created
218
- // here — an install without one (or a test importing this file) records nothing. Capped
219
- // at the newest MAX_LEDGER_LINES like the hook's; never throws, never decides.
214
+ // The twin of `ledger()` in js/hosts/hooks.mjs: one JSON line per BLOCK into the install's
215
+ // `notebook/gates.jsonl` (`notebookHome`: `<cfg>/notebook` for a global install,
216
+ // `<repo>/notebook` for a project one), the rule and never the content, so `geneseed status`
217
+ // and the console can count what the boundary actually caught on an OpenCode install too. A
218
+ // warning is not recorded (nothing was refused) and neither is `GENESEED_GUARD=warn`.
219
+ // `notebook/` is never created here — an install without one (or a test importing this file)
220
+ // records nothing. Each loaded copy records its OWN refusals, with no stand-down: a global and a
221
+ // project copy judge a call each from its own carrier AGENT.md (gates, packs, excluded rules), so
222
+ // the copy that can record is not always the copy that refused. Capped at the newest
223
+ // MAX_LEDGER_LINES like the hook's; never throws, never decides.
220
224
  const MAX_LEDGER_LINES = 1000
221
225
  async function ledger(rule) {
222
226
  // `geneseed doctor --probe` blocks on purpose; its blocks are not the user's (the twin of
@@ -225,7 +229,8 @@ async function ledger(rule) {
225
229
  try {
226
230
  const bases = []
227
231
  if (process.env.GENESEED_HARNESS) bases.push(process.env.GENESEED_HARNESS)
228
- bases.push(path.dirname(PLUGIN_DIR))
232
+ const own = notebookHome()
233
+ if (own) bases.push(own)
229
234
  for (const base of bases) {
230
235
  const dir = path.join(base, "notebook")
231
236
  if (!(await isDir(dir))) continue
@@ -1254,9 +1259,11 @@ const GATE_ASKS = {
1254
1259
  impact: 'the scan can run for hours', tail: 'search one named directory',
1255
1260
  can: 'You can name the directory to search.' }),
1256
1261
  // Routine and frequent, so one line: three more would train the user to stop reading all of them.
1257
- commit: () => ({ rule: 'Consent Before Push', quote: true, short: true,
1258
- line: 'This command commits or pushes with git, which needs your approval each time.',
1259
- why: 'every commit and push is your decision', can: GATE_RUN_IT }),
1262
+ // `strict`: the install asks for every commit and push (`--strict-consent`), not only main's.
1263
+ commit: (f) => ({ rule: 'Consent Before Push', quote: true, short: true,
1264
+ line: f.strict ? 'This command commits or pushes with git, which needs your approval each time.'
1265
+ : 'This command commits or pushes onto the main branch, forces a push, or takes a form the gate cannot read, so it needs your approval.',
1266
+ why: f.strict ? 'every commit and push is your decision' : 'the main branch changes only through a pull request', can: GATE_RUN_IT }),
1260
1267
  // The next four are the OpenCode guard's alone: no hook reads a key path, a stream, a wiki manifest
1261
1268
  // or an unknown tool's arguments, and the guard only refuses them. `wiki` has no rule to name.
1262
1269
  'secret-file': (f) => ({ rule: 'Sealed Secrets', line: `This edit writes to ${gateName(gatePath(f.name))}, a file that holds a secret or key.`,
@@ -2486,7 +2493,7 @@ function argPaths(v, key = "", out = [], depth = 0) {
2486
2493
 
2487
2494
  // Usage counting: the same rules as js/hosts/usage.mjs, inline because a plugin cannot import
2488
2495
  // from the repo (V2 loads every .js in plugins/ as a plugin). One line per skill or subagent
2489
- // call, the day and the name only, under <cfg>/notebook/usage.jsonl. Silent and never throws:
2496
+ // call, the day and the name only, under the install's notebook/usage.jsonl. Silent and never throws:
2490
2497
  // a counter must not change, slow or fail a tool call. tests/unit/usage.test.mjs holds this
2491
2498
  // copy and the hook's to one table. `usageOf` is by hand (no Bob shapes here); `NAME_RE` is the
2492
2499
  // hook's line, kept by `node tests/twins.mjs --write`.
@@ -2502,18 +2509,88 @@ function usageOf(tool, args) {
2502
2509
  name = name.trim().replace(/^\/+/, "")
2503
2510
  return NAME_RE.test(name) ? { kind, name } : null
2504
2511
  }
2505
- async function recordUse(tool, args) {
2512
+ // WHERE EVERY LEDGER IS: the dir that holds the install's own `notebook/` (usage.jsonl,
2513
+ // gates.jsonl, agent-runs.jsonl, the agent notes). A global install keeps it beside plugins/
2514
+ // (`<cfg>/notebook`); a PROJECT install keeps its plugins in `<repo>/.opencode/plugins` and its
2515
+ // notebook at `<repo>/notebook`, where the bundle writes it (js/build/bundle.mjs) and the console
2516
+ // reads it (js/web/api.mjs `activeInstalls` -> the root). Only the first was tried once, and a
2517
+ // project install recorded nothing. null: no notebook. Sync and `statSync`-only, because
2518
+ // `countingCopy` asks it of other installs' dirs and geneseed-learn.js carries a copy.
2519
+ function notebookHome(cfg = path.dirname(PLUGIN_DIR)) {
2520
+ const isDirSync = (p) => { try { return statSync(p).isDirectory() } catch { return false } }
2521
+ if (isDirSync(path.join(cfg, "notebook"))) return cfg
2522
+ if (path.basename(cfg) === ".opencode" && isDirSync(path.join(path.dirname(cfg), "notebook"))) return path.dirname(cfg)
2523
+ return null
2524
+ }
2525
+ // The notebook home when counting is on there: null with no notebook, or `.usage-off` in it.
2526
+ function usageHome(cfg = path.dirname(PLUGIN_DIR)) {
2527
+ const home = notebookHome(cfg)
2528
+ return home && !existsSync(path.join(home, ".usage-off")) ? home : null
2529
+ }
2530
+ // The twin of `globalHookStandingDown` for the counter only. OpenCode loads the global plugins/
2531
+ // AND every project `.opencode/plugins/` from the session's directory up to its worktree (it
2532
+ // dedups npm plugins, not local files), so beside a project install several guards see each call,
2533
+ // and the console, which sums every install, would read it several times. ONE copy counts: the
2534
+ // guard of the NEAREST project dir, from `directory` up to `worktree`, that can count (a guard
2535
+ // file and a live `usageHome`). With none, every copy counts as before — the global alone, in the
2536
+ // usual case. Nearest, not "any other guard exists": with `repo/` and `repo/pkg/` both installed
2537
+ // and a session in pkg, that rule had every copy stand down and nothing counted. A project guard
2538
+ // that cannot count (no notebook, `.usage-off`) silences nothing, as a hook a project does not
2539
+ // wire silences nothing on the Claude side. `GENESEED_STACK_GLOBAL` stacks them, as for the hooks.
2540
+ function countingCopy(here) {
2541
+ const [directory, worktree] = here || []
2542
+ if (!directory) return null
2543
+ const start = path.resolve(directory)
2544
+ const top = worktree ? path.resolve(worktree) : start
2545
+ const rel = path.relative(top, start)
2546
+ // Nearest first. `directory` not under `worktree`: test the two and walk nothing.
2547
+ const dirs = [start]
2548
+ if (rel.startsWith("..") || path.isAbsolute(rel)) dirs.push(top)
2549
+ else for (let d = start; norm(d) !== norm(top) && path.dirname(d) !== d;) { d = path.dirname(d); dirs.push(d) }
2550
+ for (const dir of dirs) {
2551
+ const plugins = path.join(dir, ".opencode", "plugins")
2552
+ if (existsSync(path.join(plugins, "geneseed-guard.js")) && usageHome(path.join(dir, ".opencode"))) return norm(plugins)
2553
+ }
2554
+ return null
2555
+ }
2556
+ function anotherCopyCounts(here) {
2557
+ if (process.env.GENESEED_STACK_GLOBAL) return false
2558
+ try {
2559
+ const winner = countingCopy(here)
2560
+ return winner !== null && winner !== norm(PLUGIN_DIR)
2561
+ } catch { return false /* cannot tell: count */ }
2562
+ }
2563
+ async function appendUse(use, here) {
2564
+ const home = usageHome()
2565
+ if (!home || anotherCopyCounts(here)) return
2566
+ await fs.appendFile(path.join(home, "notebook", "usage.jsonl"),
2567
+ `${JSON.stringify({ ts: new Date().toISOString().slice(0, 10), ...use })}\n`)
2568
+ }
2569
+ async function recordUse(tool, args, here) {
2506
2570
  try {
2507
2571
  if (process.env.GENESEED_NO_USAGE) return
2508
2572
  const use = usageOf(tool, args)
2509
- if (!use) return
2510
- const cfg = path.dirname(PLUGIN_DIR)
2511
- if (existsSync(path.join(cfg, ".usage-off"))) return
2512
- if (!(await isDir(path.join(cfg, "notebook")))) return
2513
- await fs.appendFile(path.join(cfg, "notebook", "usage.jsonl"),
2514
- `${JSON.stringify({ ts: new Date().toISOString().slice(0, 10), ...use })}\n`)
2573
+ if (use) await appendUse(use, here)
2515
2574
  } catch { /* a counter never fails a tool call */ }
2516
2575
  }
2576
+ // A V1 slash command that runs an installed skill: `command.execute.before` names the command,
2577
+ // and it counts when `<layer>/skills/<name>/SKILL.md` exists — the plugin's own layer, the host's
2578
+ // global config dir, then the project's `.opencode/skills`. The twin of the hook's `recordSlash` (js/hosts/usage.mjs); a
2579
+ // command is a name, never its arguments. Not on V2: it has no command hook, and its prompt hook
2580
+ // sees the expanded template, with no name to count. A renamed command (`/code-review` runs
2581
+ // `geneseed-code-review`) or an alias counts only where a skill of that name exists.
2582
+ async function recordSlash(command, here) {
2583
+ try {
2584
+ if (process.env.GENESEED_NO_USAGE || typeof command !== "string") return
2585
+ const name = command.trim().replace(/^\/+/, "")
2586
+ if (/[/\\:]|\.\./.test(name) || !NAME_RE.test(name)) return
2587
+ // The host's global config too: beside a project install the global copy stands down, so a
2588
+ // skill only the global holds would otherwise be counted by neither.
2589
+ const layers = [path.dirname(PLUGIN_DIR), hostConfigDir(), ...(here || []).filter(Boolean).map((d) => path.join(d, ".opencode"))]
2590
+ if (!layers.some((l) => existsSync(path.join(l, "skills", name, "SKILL.md")))) return
2591
+ await appendUse({ kind: "skill", name, via: "slash" }, here)
2592
+ } catch { /* a counter never fails a command */ }
2593
+ }
2517
2594
 
2518
2595
  // ---- a gate that fails -----------------------------------------------------------
2519
2596
  // An error's text, from anything a gate can throw: reading it must not throw in turn.
@@ -2641,12 +2718,19 @@ export const GeneseedGuard = async (ctx) => {
2641
2718
  }
2642
2719
  } catch (err) { log(`change report error (ignored): ${err?.message ?? err}`) }
2643
2720
  },
2721
+ // V1 only (V2 has no command hook): a `/skill` command counts as the skill (`recordSlash`).
2722
+ "command.execute.before": async (input) => {
2723
+ try {
2724
+ if (await sovereignBypass(root())) return
2725
+ await recordSlash(input?.command, [ctx?.directory, ctx?.worktree])
2726
+ } catch { /* a counter never fails a command */ }
2727
+ },
2644
2728
  "tool.execute.before": async (input, output) => {
2645
2729
  // Bypass before counting, the order Claude's toolGate keeps: an excluded repo is
2646
2730
  // dormant, so nothing is written there. GENESEED_GUARD=off still counts — Claude's
2647
2731
  // hook has no such switch; GENESEED_NO_USAGE / .usage-off stop the counter.
2648
2732
  if (await sovereignBypass(root())) return
2649
- await recordUse(input?.tool || input?.name, output?.args || input?.args)
2733
+ await recordUse(input?.tool || input?.name, output?.args || input?.args, [ctx?.directory, ctx?.worktree])
2650
2734
  if (OFF) return
2651
2735
  // A session that predates this plugin never sent `session.created`. Once per session.
2652
2736
  try { await watch(input?.sessionID) } catch { /* the report never decides a tool call */ }