geneseed 4.32.0 → 5.0.1

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 (246) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/DESIGN.md +2 -2
  3. package/README.md +6 -5
  4. package/SHIPPED.md +4 -3
  5. package/adapters/bob/README.md +6 -5
  6. package/adapters/claude-code/README.md +4 -3
  7. package/adapters/claude-code/skills/geneseed/SKILL.md +1 -1
  8. package/adapters/openclaude/README.md +4 -3
  9. package/adapters/opencode/GLOBAL-HARNESS-SPEC.md +3 -1
  10. package/adapters/opencode/HOW-OPENCODE-LOADS.md +2 -1
  11. package/adapters/opencode/README.md +18 -18
  12. package/adapters/opencode/plugins/geneseed-activity.js +57 -1
  13. package/adapters/opencode/plugins/geneseed-context.js +85 -18
  14. package/adapters/opencode/plugins/geneseed-guard.js +437 -76
  15. package/adapters/opencode/plugins/geneseed-learn.js +97 -23
  16. package/bin/geneseed-cli.mjs +17 -25
  17. package/bin/geneseed-hook.mjs +23 -8
  18. package/docs/DESIGN.md +175 -0
  19. package/docs/PRD.md +111 -0
  20. package/docs/README.md +3 -2
  21. package/docs/architecture.md +145 -0
  22. package/docs/concepts/agents.md +1 -1
  23. package/docs/concepts/collaboration.md +1 -1
  24. package/docs/concepts/enforcement-table.md +1 -1
  25. package/docs/concepts/exclusions.md +5 -5
  26. package/docs/concepts/footprint.md +1 -1
  27. package/docs/concepts/foreman-mode.md +2 -2
  28. package/docs/concepts/hooks.md +22 -8
  29. package/docs/concepts/host-matrix.md +2 -2
  30. package/docs/concepts/hosts.md +1 -1
  31. package/docs/concepts/kits.md +3 -1
  32. package/docs/concepts/ownership.md +1 -1
  33. package/docs/concepts/rules.md +15 -2
  34. package/docs/concepts/shared-tier.md +73 -0
  35. package/docs/concepts/skills.md +2 -2
  36. package/docs/concepts/themes.md +1 -1
  37. package/docs/extending.md +13 -12
  38. package/docs/guides/install-claude-code.md +1 -1
  39. package/docs/guides/install-opencode.md +1 -1
  40. package/docs/guides/migrate.md +8 -4
  41. package/docs/guides/project-context.md +2 -2
  42. package/docs/guides/setup-footprint.md +1 -1
  43. package/docs/guides/uninstall.md +2 -1
  44. package/docs/guides/upgrade-to-5.md +118 -0
  45. package/docs/guides/upgrade.md +21 -9
  46. package/docs/guides/wiki.md +3 -3
  47. package/docs/reference/env-context.md +5 -3
  48. package/docs/reference/environment.md +1 -1
  49. package/docs/reference/glossary.md +2 -0
  50. package/docs/reference/opencode-plugins.md +3 -3
  51. package/docs/reference/plugin-activity.md +1 -1
  52. package/docs/reference/plugin-context.md +1 -0
  53. package/docs/reference/plugin-guard.md +14 -6
  54. package/docs/reference/plugin-learn.md +13 -6
  55. package/docs/reference/troubleshoot-hooks.md +3 -3
  56. package/docs/reference/troubleshoot-update.md +14 -0
  57. package/docs/token-footprint.md +4 -3
  58. package/docs/understand/a-day.md +2 -2
  59. package/docs/understand/design-choices-install.md +2 -1
  60. package/docs/understand/enforced-vs-asked.md +1 -1
  61. package/docs/understand/machine-bob.md +2 -0
  62. package/docs/understand/machine-claude.md +7 -5
  63. package/docs/understand/machine-opencode.md +7 -5
  64. package/docs/understand/on-your-machine.md +4 -0
  65. package/docs/understand/take-it-out.md +1 -1
  66. package/docs/web-ui.md +135 -70
  67. package/harness.config.json +1 -1
  68. package/js/README.md +12 -7
  69. package/js/build/args.mjs +10 -8
  70. package/js/build/bundle.mjs +11 -13
  71. package/js/build/driver.mjs +66 -65
  72. package/js/build/emit-claude.mjs +22 -16
  73. package/js/build/emit-common.mjs +4 -5
  74. package/js/build/emit-opencode.mjs +22 -22
  75. package/js/build/fold.mjs +515 -0
  76. package/js/build/generate.mjs +41 -52
  77. package/js/build/render.mjs +115 -29
  78. package/js/build/rule-decide.mjs +273 -0
  79. package/js/build/source.mjs +4 -1
  80. package/js/build/stubs.mjs +70 -9
  81. package/js/build/version.mjs +10 -10
  82. package/js/cli-table.json +23 -83
  83. package/js/hosts/activity.mjs +2 -2
  84. package/js/hosts/geneseed-dir.mjs +1 -1
  85. package/js/hosts/hooks-context.mjs +389 -99
  86. package/js/hosts/hooks-learn.mjs +38 -7
  87. package/js/hosts/hooks-prims.mjs +4 -2
  88. package/js/hosts/hooks.mjs +114 -39
  89. package/js/hosts/hosts.mjs +150 -51
  90. package/js/hosts/installs.mjs +59 -171
  91. package/js/hosts/link.mjs +3 -5
  92. package/js/hosts/mcp.mjs +1 -1
  93. package/js/hosts/memory-files.mjs +219 -17
  94. package/js/hosts/ownership-gate.mjs +1 -1
  95. package/js/hosts/settings.mjs +18 -13
  96. package/js/hosts/shim.mjs +4 -33
  97. package/js/hosts/store-watch.mjs +191 -0
  98. package/js/inspect/checks-authoring.mjs +3 -3
  99. package/js/inspect/checks-build.mjs +45 -18
  100. package/js/inspect/checks-counts.mjs +4 -4
  101. package/js/inspect/checks-repo.mjs +13 -14
  102. package/js/inspect/cost.mjs +24 -2
  103. package/js/inspect/diff.mjs +123 -123
  104. package/js/inspect/doctor.mjs +22 -27
  105. package/js/inspect/excludes.mjs +181 -62
  106. package/js/inspect/inventory.mjs +22 -27
  107. package/js/inspect/registry.mjs +110 -32
  108. package/js/inspect/scan.mjs +5 -5
  109. package/js/inspect/status.mjs +141 -119
  110. package/js/inspect/validate.mjs +22 -24
  111. package/js/lib/fs.mjs +47 -50
  112. package/js/lib/json.mjs +10 -17
  113. package/js/lib/machine-dir.mjs +73 -0
  114. package/js/lib/paths.mjs +35 -33
  115. package/js/lib/proc.mjs +1 -1
  116. package/js/lib/prompt.mjs +19 -27
  117. package/js/lib/text.mjs +8 -12
  118. package/js/lib/udiff.mjs +11 -15
  119. package/js/loop/catalog.mjs +2 -3
  120. package/js/maintain/memory.mjs +17 -17
  121. package/js/maintain/migrate.mjs +120 -92
  122. package/js/maintain/setup.mjs +43 -32
  123. package/js/maintain/uninstall.mjs +43 -61
  124. package/js/maintain/update.mjs +200 -93
  125. package/js/ui/anim.mjs +21 -35
  126. package/js/ui/cli.mjs +36 -58
  127. package/js/ui/menu.mjs +22 -45
  128. package/js/ui/tui.mjs +27 -67
  129. package/js/web/actions.mjs +34 -34
  130. package/js/web/api.mjs +142 -79
  131. package/js/web/catalog.mjs +175 -46
  132. package/js/web/docs.mjs +33 -12
  133. package/js/web/doctor-worker.mjs +14 -0
  134. package/js/web/handler.mjs +16 -5
  135. package/js/web/routes.mjs +24 -22
  136. package/js/web/state.mjs +78 -19
  137. package/js/web/update-check.mjs +27 -12
  138. package/js/web/user-files.mjs +76 -104
  139. package/package.json +7 -4
  140. package/registry.json +48 -55
  141. package/src/AGENT.md.tmpl +13 -14
  142. package/src/agents/_self-improvement.md +1 -1
  143. package/src/agents/_template.md +1 -1
  144. package/src/agents/advocate.md +1 -1
  145. package/src/agents/architect.md +1 -1
  146. package/src/agents/developer.md +1 -1
  147. package/src/agents/devops-engineer.md +1 -1
  148. package/src/agents/docker-expert.md +1 -1
  149. package/src/agents/docs.md +1 -1
  150. package/src/agents/empiricist.md +1 -1
  151. package/src/agents/explorer.md +1 -1
  152. package/src/agents/framer.md +1 -1
  153. package/src/agents/historian.md +1 -1
  154. package/src/agents/kubernetes-specialist.md +1 -1
  155. package/src/agents/memory-curator.md +2 -2
  156. package/src/agents/operator.md +1 -1
  157. package/src/agents/performance.md +1 -1
  158. package/src/agents/pragmatist.md +1 -1
  159. package/src/agents/react-engineer.md +1 -1
  160. package/src/agents/react-reviewer.md +1 -1
  161. package/src/agents/researcher.md +1 -1
  162. package/src/agents/reviewer.md +1 -1
  163. package/src/agents/security.md +1 -1
  164. package/src/agents/skeptic.md +1 -1
  165. package/src/agents/spring-boot-engineer.md +1 -1
  166. package/src/agents/spring-reviewer.md +1 -1
  167. package/src/agents/spring-security.md +1 -1
  168. package/src/agents/steward.md +1 -1
  169. package/src/agents/tester.md +1 -1
  170. package/src/agents/user-advocate.md +1 -1
  171. package/src/agents/visionary.md +1 -1
  172. package/src/memory/README.md +1 -1
  173. package/src/skills/_self-improvement.md +2 -2
  174. package/src/skills/daydream/SKILL.md +2 -2
  175. package/src/skills/daydream/instructions.md +1 -1
  176. package/src/skills/geneseed.md +1 -1
  177. package/src/skills/learn-mode.md +1 -2
  178. package/src/skills/profile.md +2 -2
  179. package/src/skills/rule/approve.md +75 -0
  180. package/src/skills/rule/consolidate.md +3 -3
  181. package/src/skills/rule.md +14 -5
  182. package/src/skills/skill-forge.md +1 -1
  183. package/src/skills/teach.md +29 -12
  184. package/src/skills/wiki.md +1 -1
  185. package/themes/_TEMPLATE.json +1 -2
  186. package/themes/biker.json +1 -2
  187. package/themes/commentator.json +1 -2
  188. package/themes/cyberpunk.json +1 -2
  189. package/themes/gamer.json +1 -2
  190. package/themes/imperial.json +1 -2
  191. package/themes/joker.json +1 -2
  192. package/themes/marvin.json +1 -2
  193. package/themes/mean.json +1 -2
  194. package/themes/military.json +1 -2
  195. package/themes/neutral.json +1 -2
  196. package/themes/pirate.json +1 -2
  197. package/themes/sports.json +1 -2
  198. package/themes/verstappen.json +1 -2
  199. package/themes/wizard.json +1 -2
  200. package/web/dist/assets/Activity-Ci4PZco3.js +1 -0
  201. package/web/dist/assets/ActivityDetail-C8hroCND.js +1 -0
  202. package/web/dist/assets/AgentGlyph-k6o3gCM1.js +1 -0
  203. package/web/dist/assets/Bonsai-C1iBAt4v.js +1 -0
  204. package/web/dist/assets/{CopyButton-C5Li6awl.js → CopyButton-DJ3a4N88.js} +1 -1
  205. package/web/dist/assets/Dashboard-C_On4KXw.js +2 -0
  206. package/web/dist/assets/Docs-Kffdg5uV.js +5 -0
  207. package/web/dist/assets/GreenhouseView-k56_cBSF.js +1 -0
  208. package/web/dist/assets/Installs-DtEKLC9h.js +3 -0
  209. package/web/dist/assets/JournalView-RQnk5l7I.js +1 -0
  210. package/web/dist/assets/Kits-CXkEBpnf.js +1 -0
  211. package/web/dist/assets/Laws-DhhIVqmh.js +3 -0
  212. package/web/dist/assets/Library-CAUiEoJo.js +3 -0
  213. package/web/dist/assets/{Loops-CzitjxGV.js → Loops-LKD8mF4E.js} +2 -2
  214. package/web/dist/assets/{Markdown-C4S4tTA7.js → Markdown-0ORz7tAc.js} +21 -21
  215. package/web/dist/assets/OperatorHudView-CM5jNPwL.js +1 -0
  216. package/web/dist/assets/Personal-B6Uoly3C.js +2 -0
  217. package/web/dist/assets/{RailCats-D5weYPCS.js → RailCats-DQxxYBEP.js} +1 -1
  218. package/web/dist/assets/Settings-BTe6-wda.js +1 -0
  219. package/web/dist/assets/Tabs-CbdDWTp_.js +1 -0
  220. package/web/dist/assets/api-D_r0Jtla.js +1 -0
  221. package/web/dist/assets/controls-D4wmg_pl.js +1 -0
  222. package/web/dist/assets/index-HfGmYXab.js +3 -0
  223. package/web/dist/assets/index-ao3M-Fhm.css +1 -0
  224. package/web/dist/assets/motion-RlUl1osO.js +1 -0
  225. package/web/dist/assets/{sections-ChwaobfW.js → sections-CtFz7HFH.js} +1 -1
  226. package/web/dist/index.html +5 -5
  227. package/src/skills/quiz.md +0 -44
  228. package/web/dist/assets/Activity-Bjy64wHC.js +0 -1
  229. package/web/dist/assets/ActivityDetail-B0AaipP8.js +0 -1
  230. package/web/dist/assets/Bonsai-CJniRqaH.js +0 -1
  231. package/web/dist/assets/Dashboard-B-6DTmae.js +0 -2
  232. package/web/dist/assets/Docs-LRc30XL9.js +0 -5
  233. package/web/dist/assets/GreenhouseView-CcoYlaWo.js +0 -1
  234. package/web/dist/assets/Installs-dp1epTcE.js +0 -3
  235. package/web/dist/assets/JournalView-nFP4poCf.js +0 -1
  236. package/web/dist/assets/KitApply-DwyZUj57.js +0 -1
  237. package/web/dist/assets/Kits-C0IEdZXe.js +0 -1
  238. package/web/dist/assets/Laws-CkykmQWu.js +0 -3
  239. package/web/dist/assets/Library-Guh9HBZU.js +0 -2
  240. package/web/dist/assets/OperatorHudView-DLGNulIY.js +0 -1
  241. package/web/dist/assets/Personal-BMtberL8.js +0 -2
  242. package/web/dist/assets/Tabs-uYJqfuQt.js +0 -1
  243. package/web/dist/assets/api-BxjLd7Qd.js +0 -1
  244. package/web/dist/assets/index-DA7BiaE5.js +0 -3
  245. package/web/dist/assets/index-dbbDGFDq.css +0 -1
  246. package/web/dist/assets/motion-Bccx3zE8.js +0 -1
package/js/lib/text.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * String primitives — measuring, padding, stripping, decoding and reading an integer.
3
3
  *
4
- * These are definitions, not an adaptation of somebody else's; see `fs.mjs` for why the
5
- * measurements against CPython are recorded per function, and why NONE of these is the Node
6
- * default — the warning the retired `py` prefix used to carry now lives in each docblock.
4
+ * These are definitions, not an adaptation of somebody else's, and NONE of these is the
5
+ * Node default — each docblock says why.
7
6
  * Every function here is a place the Node default DIVERGES from the answer this tool needs:
8
7
  * `codePointLength` counts code points where `.length` counts units, `WHITESPACE` is a wider
9
8
  * set than `String.trim`'s, `parseIntStrict` accepts what `Number()` does not and rejects what
@@ -52,8 +51,7 @@ export const padEndToWidth = (s, width) => s + ' '.repeat(Math.max(0, width - co
52
51
  * raw environment value do it — `js/ui/cli.mjs`'s `helpWidth` and `js/web/activity.mjs` wrap
53
52
  * the argument in `stripWhitespace` first.
54
53
  *
55
- * Its own corpus retired with the Python suite — a primitive reproduction gets one owner and
56
- * a corpus, never a cell (P5c) — so what reaches it now is only its callers' gates:
54
+ * What reaches it is its callers' gates:
57
55
  * `tests/unit/wizard.test.mjs`'s choice corpus and `tests/unit/web_daemon.test.mjs`'s
58
56
  * non-integer port.
59
57
  */
@@ -116,9 +114,8 @@ export function stripWhitespace(s) {
116
114
  /**
117
115
  * `str.lstrip()` / `str.rstrip()` — the ONE-SIDED halves, over the same `WHITESPACE`.
118
116
  *
119
- * P2 added them for `_build_render._insert_theme_keys`, which uses all three spellings within
120
- * four lines (`lines[0].strip()`, `ln.lstrip().startswith('"')`,
121
- * `lines[pred].rstrip().endswith(",")`). They are here rather than in `js/build/themes.mjs` for the
117
+ * The theme-key insertion uses all three spellings within four lines. They are here rather
118
+ * than in `js/build/themes.mjs` for the
122
119
  * reason this file exists at all: `js/hosts/settings.mjs` already carries a private second copy of
123
120
  * the character class, and a THIRD one — in the module that decides where a comma goes in a
124
121
  * committed theme file — is how the three drift apart. One owner of the set, three views of it.
@@ -136,8 +133,8 @@ export function stripWhitespaceEnd(s) {
136
133
  *
137
134
  * The whole difference is what happens to a sequence that is not an escape.
138
135
  * `decodeURIComponent('a%ZZ')` throws a `URIError`, and so does a trailing bare `%`; the
139
- * web shell would answer both as a 500 where the reference answers a 404 naming the
140
- * literal text. `unquote` leaves them alone: CPython builds a table of every two-hex-digit
136
+ * web shell would answer both as a 500 where a 404 naming the
137
+ * literal text is wanted. `unquote` leaves them alone: CPython builds a table of every two-hex-digit
141
138
  * pair in both cases and treats a `KeyError` as "this was not an escape", emitting `%` and
142
139
  * the rest of the fragment verbatim.
143
140
  *
@@ -150,8 +147,7 @@ export function stripWhitespaceEnd(s) {
150
147
  * `Buffer.toString('utf-8')` substitutes U+FFFD for an undecodable sequence, which is
151
148
  * `errors='replace'`. The two decoders can disagree on HOW MANY replacement characters a
152
149
  * truncated multi-byte sequence yields — Python's maximal-subpart rule against WHATWG's —
153
- * and the former Python corpus is where that was measured rather than assumed; nothing
154
- * measures it now.
150
+ * and nothing measures it.
155
151
  */
156
152
  const HEX_PAIR = /^[0-9A-Fa-f]{2}$/;
157
153
 
package/js/lib/udiff.mjs CHANGED
@@ -4,9 +4,8 @@
4
4
  * WHY A HAND-WRITTEN MATCHER RATHER THAN A LIBRARY. The diff is the ENTIRE user-visible
5
5
  * payload of `geneseed diff`: the hunks in `--full` and in the exported improvements file
6
6
  * are this file's output and nothing else's. A generic JS diff would produce a CORRECT diff
7
- * and a DIFFERENT one, and the former Python suite's corpus compared the hunks character for
8
- * character, so "also a valid diff" failed every case (today only the `diff/--full-…` CLI cell
9
- * compares hunks, and only one; see `js/inspect/diff.mjs`). The alignment below IS the
7
+ * and a DIFFERENT one, so "also a valid diff" is not enough (only the `diff/--full-…` CLI
8
+ * cell compares hunks, and only one; see `js/inspect/diff.mjs`). The alignment below IS the
10
9
  * specification of what this tool prints, and three of its choices are choices no other
11
10
  * algorithm makes:
12
11
  *
@@ -19,13 +18,10 @@
19
18
  * `floor(len(b) / 100) + 1` times is deleted from the index and stops matching entirely.
20
19
  * On this tool's own files — hundreds of lines, many of them blank — that fires
21
20
  * constantly and changes the hunks. It is off by construction for anything shorter, so a
22
- * small fixture cannot see it at all; the recorded corpus is what carries inputs long
23
- * enough to trip it.
21
+ * small fixture cannot see it at all.
24
22
  *
25
- * PROVENANCE, not a contract with a live second party. Every rule above was measured from
26
- * CPython's `difflib`, which is why the odd ones are odd — `autojunk` in particular is a
27
- * heuristic no one would invent from scratch. That history explains the shape; it does not
28
- * govern it any more. The recording does, and the recording cannot be re-blessed.
23
+ * The rules above follow `difflib`, which is why the odd ones are odd — `autojunk` in
24
+ * particular is a heuristic no one would invent from scratch.
29
25
  *
30
26
  * No junk predicate is implemented: every call site is `opcodes(a, b)` with no `isjunk`, so
31
27
  * the junk set is empty and its test is constant false. That deletes two of the four
@@ -38,7 +34,7 @@
38
34
  * `SequenceMatcher.__chain_b` — b's element index, minus the popular elements.
39
35
  *
40
36
  * A `Map`, never an object: the elements are LINES, and a file whose first line is `0` would
41
- * have its index hoisted to the front of an object literal (the P3a hazard). Nothing here
37
+ * have its index hoisted to the front of an object literal. Nothing here
42
38
  * iterates `b2j`, so the hoist would be invisible until the day something did.
43
39
  */
44
40
  function chainB(b) {
@@ -61,7 +57,7 @@ function chainB(b) {
61
57
  /**
62
58
  * `SequenceMatcher.find_longest_match`, with `isbjunk` constant False.
63
59
  *
64
- * `j2len` is a `Map` keyed by INTEGER j, where the Python uses a dict. Nothing iterates it
60
+ * `j2len` is a `Map` keyed by INTEGER j. Nothing iterates it
65
61
  * either, so the key type is only about lookup; a plain object would coerce every key to a
66
62
  * string and work, and a Map says what the keys are.
67
63
  */
@@ -85,7 +81,7 @@ function findLongestMatch(a, b, b2j, alo, ahi, blo, bhi) {
85
81
  }
86
82
  // The two junk-free extension loops. The popular elements `chainB` dropped are NOT junk —
87
83
  // `bjunk` stays empty — so a popular line adjacent to a match is still extended over here
88
- // even though it could never have started one. That asymmetry is the Python's.
84
+ // even though it could never have started one. That asymmetry is `difflib`'s.
89
85
  while (besti > alo && bestj > blo && a[besti - 1] === b[bestj - 1]) {
90
86
  besti -= 1; bestj -= 1; bestsize += 1;
91
87
  }
@@ -103,7 +99,7 @@ function matchingBlocks(a, b, b2j) {
103
99
  const queue = [[0, la, 0, lb]];
104
100
  const blocks = [];
105
101
  while (queue.length) {
106
- // `queue.pop()` — LIFO, as the Python. The order reaches the output through the sort
102
+ // `queue.pop()` — LIFO, as `difflib`. The order reaches the output through the sort
107
103
  // below only when two blocks tie, which they cannot, so this is faithfulness rather
108
104
  // than necessity.
109
105
  const [alo, ahi, blo, bhi] = queue.pop();
@@ -157,7 +153,7 @@ function opcodes(a, b) {
157
153
  /**
158
154
  * `SequenceMatcher.get_grouped_opcodes` — the hunks, with `n` lines of context.
159
155
  *
160
- * Returns a list rather than a generator: the Python's caller is a `for` loop that consumes
156
+ * Returns a list rather than a generator: the caller is a `for` loop that consumes
161
157
  * it once, and a lazy JS equivalent would buy nothing but a second shape to reason about.
162
158
  */
163
159
  function groupedOpcodes(a, b, n = 3) {
@@ -203,7 +199,7 @@ function formatRangeUnified(start, stop) {
203
199
  * `difflib.unified_diff` — the lines, WITHOUT trailing newlines when `lineterm` is `""`.
204
200
  *
205
201
  * Every call site in this port passes `lineterm=""` and feeds it `splitlines()` output, which
206
- * is the form the Python's own caller uses; the parameter is kept so the shape is the
202
+ * is the form `difflib`'s own callers use; the parameter is kept so the shape is the
207
203
  * stdlib's rather than a specialisation that would have to be widened later.
208
204
  */
209
205
  export function unifiedDiff(a, b, {
@@ -16,16 +16,15 @@
16
16
  * user's file, so the int/float distinction `parseJson` preserves has nowhere to matter.
17
17
  */
18
18
  import { readdirSync } from 'node:fs';
19
- import os from 'node:os';
20
19
  import path from 'node:path';
21
20
  import { readText, isFile, isDir } from '../lib/fs.mjs';
22
21
  import { frontmatter } from '../hosts/memory-files.mjs';
23
22
  import { SRC, stripAuthorNotes } from '../build/source.mjs';
24
23
  import { checkGraph } from './graph.mjs';
24
+ import { machineDir } from '../lib/machine-dir.mjs';
25
25
 
26
26
  export function userLoopsDir() {
27
- const base = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config');
28
- return path.join(base, 'geneseed');
27
+ return machineDir();
29
28
  }
30
29
 
31
30
  const KEBAB = /^[a-z0-9][a-z0-9-]*$/;
@@ -13,8 +13,10 @@
13
13
  *
14
14
  * * THE STORE IS RESOLVED, NOT CONFIGURED. The endpoint is always `<target>/memory`,
15
15
  * because a server has a target. A CLI has a cwd, so this takes the resolver every other
16
- * terminal-side reader of the store already uses — `$GENESEED_MEMORY`, then a store
17
- * beside the cwd, then the global config dir — with `--memory` as the explicit override.
16
+ * terminal-side reader of the store already uses — `$GENESEED_MEMORY`, then
17
+ * `$GENESEED_HARNESS`, then a project install in the cwd, then the shared tier, then the
18
+ * OpenCode config store — with
19
+ * `--memory` as the explicit override, and the only way to a `memory/` no install owns.
18
20
  * `status` prints the answer of that same resolver, so the two agree about which store
19
21
  * is "the" store.
20
22
  * * THE RESERVED-NAME CHECK IS CASE-INSENSITIVE, and the web endpoints use this one. On a
@@ -34,21 +36,16 @@
34
36
  import { readdirSync, unlinkSync } from 'node:fs';
35
37
  import path from 'node:path';
36
38
 
37
- import { archiveFact, memoryDropIndex } from '../hosts/memory-files.mjs';
39
+ import { RESERVED_STEMS, archiveFact, memoryDropIndex } from '../hosts/memory-files.mjs';
40
+ import { recordOwnWrites } from '../hosts/store-watch.mjs';
38
41
  import { resolveMemoryDir } from '../hosts/hosts.mjs';
39
42
  import { printOut, printErr, isFile } from '../lib/fs.mjs';
40
43
 
41
- /**
42
- * The two names the store owns rather than holds: the index the agent reads at session
43
- * start, and the file that documents the store. `api_memory_delete` refuses both.
44
- */
45
- const RESERVED = ['memory', 'readme'];
46
-
47
44
  /** Whether `name` is a fact this verb may act on — the endpoint's rule, plus the case fold. */
48
45
  export function isFactName(name) {
49
46
  return Boolean(name) && !name.includes('/') && !name.includes('\\')
50
47
  && ![...name].some((c) => c.charCodeAt(0) < 0x20 || c.charCodeAt(0) === 0x7f)
51
- && !RESERVED.includes(name.toLowerCase());
48
+ && !RESERVED_STEMS.has(name.toLowerCase());
52
49
  }
53
50
 
54
51
  /**
@@ -73,11 +70,13 @@ export function memoryDelete(dir, name, purge = false) {
73
70
  if (!isFactName(name)) return null;
74
71
  const p = path.join(dir, `${name}.md`);
75
72
  if (!isFile(p)) return null;
76
- let dest = '';
77
- if (purge) unlinkSync(p);
78
- else dest = archiveFact(dir, name);
79
- memoryDropIndex(dir, name);
80
- return dest;
73
+ return recordOwnWrites(path.dirname(dir), () => {
74
+ let dest = '';
75
+ if (purge) unlinkSync(p);
76
+ else dest = archiveFact(dir, name);
77
+ memoryDropIndex(dir, name);
78
+ return dest;
79
+ });
81
80
  }
82
81
 
83
82
  /** Unlink `archive/<name>.md`. True when a file went. The archive has no index to update. */
@@ -95,8 +94,8 @@ export function cmdMemory(args) {
95
94
  if (dir === null) {
96
95
  // The resolver answers null for "no store anywhere on the chain", which is also what an
97
96
  // explicit `--memory` that is not a directory gives — so the message names both.
98
- printErr('[memory] no memory store found. Pass --memory <dir>, set $GENESEED_MEMORY, '
99
- + 'or run this from a directory with a memory/ store.\n');
97
+ printErr('[memory] no memory store found. Pass --memory <dir>, or run this from a project '
98
+ + 'install.\n');
100
99
  return 1;
101
100
  }
102
101
  const where = args.archived ? path.join(dir, 'archive') : dir;
@@ -128,6 +127,7 @@ export function cmdMemory(args) {
128
127
  printErr(`[memory] no such fact '${args.name}' in ${where}.\n`);
129
128
  return 1;
130
129
  }
130
+ printOut(`[memory] ${where}\n`);
131
131
  printOut(done ? `[memory] archived ${args.name} -> ${done}\n` : `[memory] deleted ${args.name}.\n`);
132
132
  return 0;
133
133
  }
@@ -1,13 +1,6 @@
1
1
  /**
2
2
  * `geneseed migrate` — move a machine from the git-checkout install shape to the npm one.
3
3
  *
4
- * P10d, AND IT IS NOT A PORT. Every other module here reproduces a Python original byte for
5
- * byte; this verb is new behaviour on both sides, written twice in the same change so that
6
- * the former Python CLI matrix — a CROSS-IMPLEMENTATION gate — had a reference side at all. A
7
- * Node-only verb would have had nothing to compare against, and that suite's `test_every_entry_
8
- * verb_is_a_real_harness_subcommand` plus `test_the_matrix_covers_every_verb_it_claims` would
9
- * both have failed it.
10
- *
11
4
  * WHAT IT IS NOT: `rebuild-all`. That was the first answer and it was checked before being
12
5
  * discarded, because the re-emit really is the same engine and is reused rather than rewritten
13
6
  * here. Four behaviours differ, and each is a cell:
@@ -22,32 +15,31 @@
22
15
  * install must not block the rest — and for a migration it is the half-migrated machine the
23
16
  * whole verb exists to prevent.
24
17
  *
25
- * THE TWO TRIGGERS, AND WHY IT TAKES BOTH. Work is needed when the machine's wiring is
26
- * `legacy` (see `migrateShape` — and note that shapes 2 and 3 differ only inside the shim
27
- * body, never in the settings file) OR when the stamp does not name this ROOT. Neither alone
28
- * was enough: an OpenCode-only machine wires no hooks at all, so its shape is permanently
29
- * `none` and a shape-only trigger would re-emit it on every run forever; and reinstalling the
30
- * old build flipped the shape back to `legacy` while the stamp still matched, which had to
31
- * migrate again. With the old build gone the second case can no longer arise, but the shape
32
- * read stays: it is what makes the verb idempotent rather than stamp-dependent. The stamp is
33
- * written only on success.
18
+ * IT RUNS FROM THE NPM PACKAGE OR NOT AT ALL. The re-emit bakes the ROOT of whatever Geneseed runs
19
+ * it into the shim, so a run from a clone or a bundle moves nothing and only writes the stamp. That
20
+ * refusal comes before the survey, because the survey's registry read can prune `installs.json`.
21
+ * `--dry-run` writes nothing and answers from anywhere.
22
+ *
23
+ * THE ONE TRIGGER IS THE STAMP: work is needed when `<GENESEED_HOME>/.migrated` does not name this
24
+ * ROOT, and the stamp is written only on success. That is what makes the verb idempotent, and it
25
+ * holds for an OpenCode-only machine too, which wires no hooks at all.
34
26
  */
35
- import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
27
+ import { copyFileSync, existsSync, mkdirSync, rmSync } from 'node:fs';
36
28
  import path from 'node:path';
37
29
 
38
30
  import { main as driverMain } from '../build/driver.mjs';
39
- import { ROOT } from '../build/source.mjs';
40
- import { CLAUDE_STYLE, settingsFile } from '../hosts/hosts.mjs';
31
+ import { foldHost, foldSummary } from '../build/fold.mjs';
32
+ import { RETIRED_SKILL_IDS, ROOT, knownSkillIds, skillAliases } from '../build/source.mjs';
33
+ import { CLAUDE_STYLE, isCanonical, settingsFile } from '../hosts/hosts.mjs';
41
34
  import {
42
35
  claudeCfg, claudeReadManifest, EMIT_HOST_SCOPE, installState, installTargets,
43
- legacyProcessCarrierOfDir, readMaybe,
36
+ readMaybe,
44
37
  } from '../hosts/installs.mjs';
45
38
  import { installProfile } from '../build/generate.mjs';
46
- import {
47
- autostartPaths, autostartStale, hookShimPath, migrateShape, shimHome,
48
- } from '../hosts/shim.mjs';
49
- import { loadJsonObject } from '../hosts/settings.mjs';
39
+ import { autostartPaths, autostartStale, hookShimPath, shimHome } from '../hosts/shim.mjs';
50
40
  import { writeText, printOut, printErr } from '../lib/fs.mjs';
41
+ import { sharedPaths } from '../lib/machine-dir.mjs';
42
+ import { isNpmPackageDir } from '../lib/paths.mjs';
51
43
 
52
44
  /** Every emit name the generator answers to — the set an unrecognised marker is NOT in. */
53
45
  const KNOWN_EMITS = new Set(EMIT_HOST_SCOPE.keys());
@@ -57,7 +49,7 @@ const KNOWN_EMITS = new Set(EMIT_HOST_SCOPE.keys());
57
49
  *
58
50
  * Only the Claude-style hosts carry hook commands. OpenCode's hooks are a PLUGIN
59
51
  * (`js/hosts/opencode.mjs` emits JS that runs in the host's own process and names neither the
60
- * shim nor `harness.py`), so it classifies as `none` and its whole migration is the re-emit —
52
+ * shim), so it has no settings file here and its whole migration is the re-emit —
61
53
  * the same re-emit, in the same change, on every host, which is what the project's
62
54
  * host-parity rule asks for.
63
55
  *
@@ -79,29 +71,6 @@ export function hookSettingsFile(root, host, scope) {
79
71
  return settingsFile(cfg, claudeReadManifest(cfg).managed);
80
72
  }
81
73
 
82
- /** Every hook command string in a settings file, or [] when it cannot be read or parsed. */
83
- function hookCommandsOf(file) {
84
- // `loadJsonObject` (JSONC), NOT `JSON.parse`. A hand-edited settings.json with comments and a
85
- // trailing comma is the one shape no machine in this project writes, and strict JSON rejects it —
86
- // which would classify a wired install as `none` and make `migrate` skip the machine
87
- // silently. `mergeClaudeSettings` already reads through comments for exactly this reason.
88
- // Found by the JSONC corpus fixture; a generated fixture would have hidden it.
89
- const { state, data: loaded } = loadJsonObject(file);
90
- if (state !== 'ok') return [];
91
- const hooks = loaded.hooks;
92
- if (!hooks || typeof hooks !== 'object') return [];
93
- const out = [];
94
- for (const groups of Object.values(hooks)) {
95
- if (!Array.isArray(groups)) continue;
96
- for (const g of groups) {
97
- for (const h of (g && Array.isArray(g.hooks) ? g.hooks : [])) {
98
- if (h && typeof h.command === 'string') out.push(h.command);
99
- }
100
- }
101
- }
102
- return out;
103
- }
104
-
105
74
  /** `<GENESEED_HOME>/.migrated` — the ROOT the last successful migration installed from. */
106
75
  function stampPath() { return path.join(shimHome(), '.migrated'); }
107
76
 
@@ -115,11 +84,10 @@ function stashDir() { return path.join(shimHome(), '.migrate-backup'); }
115
84
  * no rollback. That ordering is the cheapest atomicity there is and it is why the survey is a
116
85
  * separate pass rather than a check inside the loop.
117
86
  */
118
- function migrateSurvey() {
87
+ function migrateSurvey({ prune = true } = {}) {
119
88
  const rows = [];
120
- const commands = [];
121
89
  const unrecognised = [];
122
- for (const [host, scope, root] of installTargets()) {
90
+ for (const [host, scope, root] of installTargets({ prune })) {
123
91
  if (installState(root, host, scope) !== 'active') continue;
124
92
  const raw = readMaybe(path.join(root, '.geneseed-emit'));
125
93
  const marker = raw === null ? '' : raw.trim();
@@ -128,22 +96,12 @@ function migrateSurvey() {
128
96
  unrecognised.push({ host, scope, root, marker });
129
97
  continue;
130
98
  }
131
- const file = hookSettingsFile(root, host, scope);
132
- if (file) commands.push(...hookCommandsOf(file));
133
- rows.push({ host, scope, root, marker, file });
99
+ rows.push({ host, scope, root, marker, file: hookSettingsFile(root, host, scope) });
134
100
  }
135
- let shimBody = '';
136
- try { shimBody = readFileSync(hookShimPath(), 'utf8'); } catch { /* no shim yet */ }
137
- const shape = migrateShape(commands, shimBody);
138
- const stamped = (readMaybe(stampPath()) || '').trim();
139
- // THE TRIGGER IS THE STAMP, AND THE SHAPE IS REPORTED — the first draft had it the other
140
- // way round and the ref-vs-ref self-check killed it in one run. `shape === 'legacy'` cannot
141
- // be a trigger, because what "current" MEANS is "the shim body names the .mjs entry", and
142
- // the Python implementation bakes python + harness.py by design (`_hook_runner_entry`). So
143
- // a migration run from the reference can never reach `current`, its second run would
144
- // re-emit forever, and the two implementations would diverge on idempotence by
145
- // construction. The stamp is a value both sides write and read identically.
146
- return { rows, unrecognised, shape, stamped, needed: stamped !== ROOT };
101
+ // No home and no GENESEED_HOME: no stamp to read, so nothing says this machine has migrated.
102
+ let stamped = '';
103
+ try { stamped = (readMaybe(stampPath()) || '').trim(); } catch { /* the survey only reads */ }
104
+ return { rows, unrecognised, needed: stamped !== ROOT };
147
105
  }
148
106
 
149
107
  /** Hand-written login entries that still name some other checkout. Reported, never rewritten. */
@@ -156,12 +114,85 @@ function autostartFindings() {
156
114
  return out;
157
115
  }
158
116
 
117
+ /**
118
+ * What each global install's next emit would fold, stamped machine or not: the fold runs in every
119
+ * emit, so the stamp says nothing about it. Each host reads the tier as it stands, so two hosts
120
+ * holding the same new fact both count it here, and the second finds it a duplicate in the real run.
121
+ */
122
+ function foldPreview(rows) {
123
+ let shared;
124
+ try { shared = sharedPaths(); } catch { return []; } // no home: no tier to fold into
125
+ return rows.filter(({ host, scope, root }) => scope === 'global' && isCanonical(root, host))
126
+ .map(({ host, root }) => {
127
+ const report = foldHost({ host, cfgDir: root, shared, dryRun: true });
128
+ return { host, summary: foldSummary(report), failed: report.failed };
129
+ });
130
+ }
131
+
132
+ /**
133
+ * M5 — files no manifest owns, so no emit will ever prune them: the root `AGENT.md` and the folder
134
+ * of a skill that no longer ships under its own name. An earlier build likely wrote them, but an
135
+ * alias is a plain word and a folder under it may be the user's own, so nothing claims which.
136
+ * REPORTED, never moved: they go aside on the user's word.
137
+ *
138
+ * The candidate names come from what git history already settled and the source still records —
139
+ * `RETIRED_SKILL_IDS` and the `aliases:` markers — because the CLI may not spawn `git`. Each
140
+ * candidate is checked before it is listed: a live skill is never an orphan (`teach` is live,
141
+ * `quiz` is its alias), and a path the manifest owns is not one either — the next emit prunes it.
142
+ */
143
+ export function orphanFindings(cfg, owned, { live = knownSkillIds(), aliases = skillAliases() } = {}) {
144
+ const owns = (rel) => owned.some((o) => o === rel || o.startsWith(`${rel}/`));
145
+ const names = [...new Set([...aliases.keys(), ...Object.keys(RETIRED_SKILL_IDS)])].filter((n) => !live.includes(n));
146
+ return ['AGENT.md', ...names.map((n) => `skills/${n}`)]
147
+ .filter((rel) => !owns(rel) && existsSync(path.join(cfg, rel)))
148
+ .map((rel) => path.join(cfg, rel));
149
+ }
150
+
151
+ /** The `--dry-run` half of M5: the orphans of each global Claude-style install. */
152
+ function orphanPreview(rows) {
153
+ return rows.filter(({ host, scope, root }) => scope === 'global' && CLAUDE_STYLE.includes(host) && isCanonical(root, host))
154
+ .flatMap(({ root }) => {
155
+ const owned = claudeReadManifest(root).owned;
156
+ return orphanFindings(root, Array.isArray(owned) ? owned : []);
157
+ });
158
+ }
159
+
160
+ /** The fold and orphan half of `--dry-run`, as the CLI prints it. */
161
+ function printPreview(rows) {
162
+ for (const { host, summary, failed } of foldPreview(rows)) {
163
+ printOut(summary ? `[migrate] would fold ${host}: ${summary}\n` : `[migrate] ${host}: nothing to fold\n`);
164
+ for (const f of failed) printOut(`[migrate] ${host}: the fold would stop at ${f}\n`);
165
+ }
166
+ for (const p of orphanPreview(rows)) {
167
+ printOut(`[migrate] orphan: ${p} (no manifest owns it; an earlier build may have written it, or it may be yours). Nothing moves it: if it is not yours, move it by hand.\n`);
168
+ }
169
+ }
170
+
171
+ /**
172
+ * What the next rebuild would do, for the console: `{folds: [{host, summary, failed}], orphans}`.
173
+ * Writes nothing. A marker `migrate` refuses is in here too: `rebuild-all` coerces it, so that
174
+ * install still folds. No `would re-emit` plan: that is this verb's, and a clone has none to run.
175
+ */
176
+ export function migratePreview() {
177
+ const { rows, unrecognised } = migrateSurvey({ prune: false });
178
+ const all = [...rows, ...unrecognised];
179
+ return { folds: foldPreview(all), orphans: orphanPreview(all) };
180
+ }
181
+
159
182
  /** A stash key that cannot collide across drives, and is a legal file name on both platforms. */
160
183
  const stashKey = (p) => p.replace(/[\\/:]/g, '_');
161
184
 
162
- export function cmdMigrate(args = {}) {
185
+ export function cmdMigrate(args = {}, { root = ROOT } = {}) {
163
186
  const dryRun = Boolean(args.dryRun);
164
- const { rows, unrecognised, shape, needed } = migrateSurvey();
187
+ const isClone = existsSync(path.join(root, '.git'));
188
+ const outside = isClone || !isNpmPackageDir(root);
189
+ const shape = isClone ? 'a git clone' : 'a bundle';
190
+ if (!dryRun && outside) {
191
+ printErr(`[migrate] REFUSED — this Geneseed runs from ${shape}, so there is nothing to migrate. Use geneseed update.\n`);
192
+ printErr('[migrate] Nothing was changed.\n');
193
+ return 3;
194
+ }
195
+ const { rows, unrecognised, needed } = migrateSurvey({ prune: !dryRun });
165
196
 
166
197
  if (unrecognised.length) {
167
198
  // Refuse the WHOLE run. A migration that skipped the row it did not understand and
@@ -180,12 +211,20 @@ export function cmdMigrate(args = {}) {
180
211
  return 0;
181
212
  }
182
213
 
214
+ if (dryRun) printPreview(rows);
215
+
183
216
  if (!needed) {
184
217
  printOut(`[migrate] already on the npm shape (${rows.length} install(s)); nothing to do.\n`);
185
218
  return 0;
186
219
  }
187
220
 
188
- printOut(`[migrate] ${rows.length} install(s), wiring shape: ${shape}\n`);
221
+ if (dryRun && outside) {
222
+ printOut(`[migrate] this Geneseed runs from ${shape}, so a real run would refuse. Use geneseed update.\n`);
223
+ printOut('[migrate] --dry-run: nothing was written.\n');
224
+ return 0;
225
+ }
226
+
227
+ printOut(`[migrate] ${rows.length} install(s) to migrate.\n`);
189
228
  if (dryRun) {
190
229
  for (const r of rows) {
191
230
  printOut(`[migrate] would re-emit ${r.host}:${r.scope} (${r.root})\n`);
@@ -198,7 +237,15 @@ export function cmdMigrate(args = {}) {
198
237
  }
199
238
 
200
239
  // Step 2 — stash every file the re-emit can touch, so step 4 can put it all back.
201
- const stash = stashDir();
240
+ // Refused before the first write: with no home and no GENESEED_HOME there is nowhere to stage it.
241
+ let stash;
242
+ try {
243
+ stash = stashDir();
244
+ } catch {
245
+ printErr('[migrate] REFUSED — no home directory, so there is nowhere to stage a backup.\n');
246
+ printErr('[migrate] Nothing was changed. Set GENESEED_HOME, then re-run.\n');
247
+ return 3;
248
+ }
202
249
  const saved = [];
203
250
  try {
204
251
  rmSync(stash, { recursive: true, force: true });
@@ -228,22 +275,8 @@ export function cmdMigrate(args = {}) {
228
275
  // `process 5` among them) and dropped `--config-dir`, so a global found through
229
276
  // `CLAUDE_CONFIG_DIR`/`OPENCODE_CONFIG_DIR` re-emitted into the DEFAULT dir instead.
230
277
  //
231
- // A LEGACY CARRIER IS SKIPPED, NOT ROLLED BACK — the one exception to Step 4's ALL OR
232
- // NOTHING, same reasoning as `rebuild-all` (`js/build/generate.mjs`): `installProfile` would
233
- // read a pre-comms carrier exactly as written now (`comms` missing, `process 7`/`process 8`
234
- // unaddressed) and `driverMain` would write that back PERMANENTLY — the fresh carrier carries
235
- // no `process 8` text, so nothing could ever catch it again. Rolling back everything else on
236
- // the machine over an install that merely needs `geneseed setup` would be a worse outcome
237
- // than leaving it as it was found.
238
- const skipped = [];
239
278
  for (const r of rows) {
240
279
  const label = `${r.host}:${r.scope} (${r.root})`;
241
- if (legacyProcessCarrierOfDir(r.root, r.host)) {
242
- skipped.push(label);
243
- printOut(`[migrate] SKIPPED ${label}: pre-comms carrier (names 'process 8') — `
244
- + 'run `geneseed setup` for it.\n');
245
- continue;
246
- }
247
280
  const { emit, theme, argv } = installProfile(r.host, r.scope, r.root,
248
281
  (n) => printErr(`[migrate] ${label}: ${n}\n`));
249
282
  printOut(`[migrate] re-emitting ${label}: theme=${theme} emit=${emit}\n`);
@@ -254,7 +287,8 @@ export function cmdMigrate(args = {}) {
254
287
  // must not, or the machine is left half on each shape.
255
288
  printErr(`[migrate] FAILED ${label} (exit ${rc}) — rolling back.\n`);
256
289
  restore();
257
- printErr(`[migrate] rolled back ${saved.length} file(s); the install is unchanged.\n`);
290
+ printErr(`[migrate] rolled back ${saved.length} file(s); the wiring is as it was. `
291
+ + 'What an earlier row folded stays in the shared tier.\n');
258
292
  return 1;
259
293
  }
260
294
  }
@@ -265,13 +299,7 @@ export function cmdMigrate(args = {}) {
265
299
  writeText(stampPath(), `${ROOT}\n`);
266
300
  } catch { /* an unwritable stamp costs a redundant re-emit next run, never correctness */ }
267
301
 
268
- const migrated = rows.length - skipped.length;
269
- if (skipped.length) {
270
- printOut(`[migrate] migrated ${migrated} install(s), skipped ${skipped.length}: `
271
- + `${skipped.join(', ')}.\n`);
272
- } else {
273
- printOut(`[migrate] migrated ${rows.length} install(s).\n`);
274
- }
302
+ printOut(`[migrate] migrated ${rows.length} install(s).\n`);
275
303
 
276
304
  // Step 5 — what could NOT be fixed automatically. Reported, never rewritten: nothing in
277
305
  // this repository has ever written an autostart entry, so migrate does not own the file.