geneseed 4.32.0 → 5.0.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 (245) hide show
  1. package/CHANGELOG.md +85 -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 +4 -2
  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 +116 -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 +126 -68
  67. package/harness.config.json +1 -1
  68. package/js/README.md +10 -6
  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/source.mjs +4 -1
  79. package/js/build/stubs.mjs +70 -9
  80. package/js/build/version.mjs +10 -10
  81. package/js/cli-table.json +23 -83
  82. package/js/hosts/activity.mjs +2 -2
  83. package/js/hosts/geneseed-dir.mjs +1 -1
  84. package/js/hosts/hooks-context.mjs +389 -99
  85. package/js/hosts/hooks-learn.mjs +38 -7
  86. package/js/hosts/hooks-prims.mjs +4 -2
  87. package/js/hosts/hooks.mjs +114 -39
  88. package/js/hosts/hosts.mjs +150 -51
  89. package/js/hosts/installs.mjs +55 -167
  90. package/js/hosts/link.mjs +3 -5
  91. package/js/hosts/mcp.mjs +1 -1
  92. package/js/hosts/memory-files.mjs +219 -17
  93. package/js/hosts/ownership-gate.mjs +1 -1
  94. package/js/hosts/settings.mjs +18 -13
  95. package/js/hosts/shim.mjs +4 -33
  96. package/js/hosts/store-watch.mjs +189 -0
  97. package/js/inspect/checks-authoring.mjs +3 -3
  98. package/js/inspect/checks-build.mjs +45 -18
  99. package/js/inspect/checks-counts.mjs +4 -4
  100. package/js/inspect/checks-repo.mjs +13 -14
  101. package/js/inspect/cost.mjs +24 -2
  102. package/js/inspect/diff.mjs +123 -123
  103. package/js/inspect/doctor.mjs +22 -27
  104. package/js/inspect/excludes.mjs +181 -62
  105. package/js/inspect/inventory.mjs +22 -27
  106. package/js/inspect/registry.mjs +106 -30
  107. package/js/inspect/scan.mjs +5 -5
  108. package/js/inspect/status.mjs +141 -119
  109. package/js/inspect/validate.mjs +22 -24
  110. package/js/lib/fs.mjs +47 -50
  111. package/js/lib/json.mjs +10 -17
  112. package/js/lib/machine-dir.mjs +73 -0
  113. package/js/lib/paths.mjs +22 -33
  114. package/js/lib/proc.mjs +1 -1
  115. package/js/lib/prompt.mjs +19 -27
  116. package/js/lib/text.mjs +8 -12
  117. package/js/lib/udiff.mjs +11 -15
  118. package/js/loop/catalog.mjs +2 -3
  119. package/js/maintain/memory.mjs +17 -17
  120. package/js/maintain/migrate.mjs +79 -89
  121. package/js/maintain/setup.mjs +43 -32
  122. package/js/maintain/uninstall.mjs +43 -61
  123. package/js/maintain/update.mjs +200 -93
  124. package/js/ui/anim.mjs +21 -35
  125. package/js/ui/cli.mjs +36 -58
  126. package/js/ui/menu.mjs +22 -45
  127. package/js/ui/tui.mjs +27 -67
  128. package/js/web/actions.mjs +34 -34
  129. package/js/web/api.mjs +130 -74
  130. package/js/web/catalog.mjs +175 -46
  131. package/js/web/docs.mjs +33 -12
  132. package/js/web/doctor-worker.mjs +14 -0
  133. package/js/web/handler.mjs +14 -5
  134. package/js/web/routes.mjs +17 -19
  135. package/js/web/state.mjs +78 -19
  136. package/js/web/update-check.mjs +25 -10
  137. package/js/web/user-files.mjs +50 -105
  138. package/package.json +7 -4
  139. package/registry.json +48 -55
  140. package/src/AGENT.md.tmpl +13 -14
  141. package/src/agents/_self-improvement.md +1 -1
  142. package/src/agents/_template.md +1 -1
  143. package/src/agents/advocate.md +1 -1
  144. package/src/agents/architect.md +1 -1
  145. package/src/agents/developer.md +1 -1
  146. package/src/agents/devops-engineer.md +1 -1
  147. package/src/agents/docker-expert.md +1 -1
  148. package/src/agents/docs.md +1 -1
  149. package/src/agents/empiricist.md +1 -1
  150. package/src/agents/explorer.md +1 -1
  151. package/src/agents/framer.md +1 -1
  152. package/src/agents/historian.md +1 -1
  153. package/src/agents/kubernetes-specialist.md +1 -1
  154. package/src/agents/memory-curator.md +2 -2
  155. package/src/agents/operator.md +1 -1
  156. package/src/agents/performance.md +1 -1
  157. package/src/agents/pragmatist.md +1 -1
  158. package/src/agents/react-engineer.md +1 -1
  159. package/src/agents/react-reviewer.md +1 -1
  160. package/src/agents/researcher.md +1 -1
  161. package/src/agents/reviewer.md +1 -1
  162. package/src/agents/security.md +1 -1
  163. package/src/agents/skeptic.md +1 -1
  164. package/src/agents/spring-boot-engineer.md +1 -1
  165. package/src/agents/spring-reviewer.md +1 -1
  166. package/src/agents/spring-security.md +1 -1
  167. package/src/agents/steward.md +1 -1
  168. package/src/agents/tester.md +1 -1
  169. package/src/agents/user-advocate.md +1 -1
  170. package/src/agents/visionary.md +1 -1
  171. package/src/memory/README.md +1 -1
  172. package/src/skills/_self-improvement.md +2 -2
  173. package/src/skills/daydream/SKILL.md +2 -2
  174. package/src/skills/daydream/instructions.md +1 -1
  175. package/src/skills/geneseed.md +1 -1
  176. package/src/skills/learn-mode.md +1 -2
  177. package/src/skills/profile.md +2 -2
  178. package/src/skills/rule/approve.md +69 -0
  179. package/src/skills/rule/consolidate.md +3 -3
  180. package/src/skills/rule.md +13 -5
  181. package/src/skills/skill-forge.md +1 -1
  182. package/src/skills/teach.md +29 -12
  183. package/src/skills/wiki.md +1 -1
  184. package/themes/_TEMPLATE.json +1 -2
  185. package/themes/biker.json +1 -2
  186. package/themes/commentator.json +1 -2
  187. package/themes/cyberpunk.json +1 -2
  188. package/themes/gamer.json +1 -2
  189. package/themes/imperial.json +1 -2
  190. package/themes/joker.json +1 -2
  191. package/themes/marvin.json +1 -2
  192. package/themes/mean.json +1 -2
  193. package/themes/military.json +1 -2
  194. package/themes/neutral.json +1 -2
  195. package/themes/pirate.json +1 -2
  196. package/themes/sports.json +1 -2
  197. package/themes/verstappen.json +1 -2
  198. package/themes/wizard.json +1 -2
  199. package/web/dist/assets/Activity-D8G4eClY.js +1 -0
  200. package/web/dist/assets/ActivityDetail-BtOBYk3M.js +1 -0
  201. package/web/dist/assets/AgentGlyph-k6o3gCM1.js +1 -0
  202. package/web/dist/assets/Bonsai-B_y20b3i.js +1 -0
  203. package/web/dist/assets/{CopyButton-C5Li6awl.js → CopyButton-CHQte7Ap.js} +1 -1
  204. package/web/dist/assets/Dashboard-B8uXeJZ_.js +2 -0
  205. package/web/dist/assets/Docs-Dgv_MWfT.js +5 -0
  206. package/web/dist/assets/GreenhouseView-CSzTMSl_.js +1 -0
  207. package/web/dist/assets/Installs-BDk9lqBI.js +3 -0
  208. package/web/dist/assets/JournalView-CvRk1-m5.js +1 -0
  209. package/web/dist/assets/Kits-CoITzxWM.js +1 -0
  210. package/web/dist/assets/Laws-Ctf5r9rE.js +3 -0
  211. package/web/dist/assets/Library-DNwHYVXt.js +3 -0
  212. package/web/dist/assets/{Loops-CzitjxGV.js → Loops-S85PMQ8m.js} +2 -2
  213. package/web/dist/assets/{Markdown-C4S4tTA7.js → Markdown-0ORz7tAc.js} +21 -21
  214. package/web/dist/assets/OperatorHudView-DuGz_sTk.js +1 -0
  215. package/web/dist/assets/Personal-afJNwvRS.js +2 -0
  216. package/web/dist/assets/{RailCats-D5weYPCS.js → RailCats-AW92uhsX.js} +1 -1
  217. package/web/dist/assets/Settings-CGDFz-6j.js +1 -0
  218. package/web/dist/assets/Tabs-1qLrnqmn.js +1 -0
  219. package/web/dist/assets/api-C46vAuqp.js +1 -0
  220. package/web/dist/assets/controls-D4wmg_pl.js +1 -0
  221. package/web/dist/assets/index-COTd4TRZ.js +3 -0
  222. package/web/dist/assets/index-CtorA7uK.css +1 -0
  223. package/web/dist/assets/motion-RlUl1osO.js +1 -0
  224. package/web/dist/assets/{sections-ChwaobfW.js → sections-CtFz7HFH.js} +1 -1
  225. package/web/dist/index.html +5 -5
  226. package/src/skills/quiz.md +0 -44
  227. package/web/dist/assets/Activity-Bjy64wHC.js +0 -1
  228. package/web/dist/assets/ActivityDetail-B0AaipP8.js +0 -1
  229. package/web/dist/assets/Bonsai-CJniRqaH.js +0 -1
  230. package/web/dist/assets/Dashboard-B-6DTmae.js +0 -2
  231. package/web/dist/assets/Docs-LRc30XL9.js +0 -5
  232. package/web/dist/assets/GreenhouseView-CcoYlaWo.js +0 -1
  233. package/web/dist/assets/Installs-dp1epTcE.js +0 -3
  234. package/web/dist/assets/JournalView-nFP4poCf.js +0 -1
  235. package/web/dist/assets/KitApply-DwyZUj57.js +0 -1
  236. package/web/dist/assets/Kits-C0IEdZXe.js +0 -1
  237. package/web/dist/assets/Laws-CkykmQWu.js +0 -3
  238. package/web/dist/assets/Library-Guh9HBZU.js +0 -2
  239. package/web/dist/assets/OperatorHudView-DLGNulIY.js +0 -1
  240. package/web/dist/assets/Personal-BMtberL8.js +0 -2
  241. package/web/dist/assets/Tabs-uYJqfuQt.js +0 -1
  242. package/web/dist/assets/api-BxjLd7Qd.js +0 -1
  243. package/web/dist/assets/index-DA7BiaE5.js +0 -3
  244. package/web/dist/assets/index-dbbDGFDq.css +0 -1
  245. package/web/dist/assets/motion-Bccx3zE8.js +0 -1
package/js/web/state.mjs CHANGED
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { existsSync } from 'node:fs';
9
9
  import path from 'node:path';
10
+ import { Worker } from 'node:worker_threads';
10
11
 
11
12
  import { CLAUDE_STYLE, HOSTS, opencodeConfigDir, resolvePath } from '../hosts/hosts.mjs';
12
13
  import { normcase } from '../lib/paths.mjs';
@@ -15,6 +16,7 @@ import {
15
16
  postureOfDir, themeOfDir, trustOfDir,
16
17
  } from '../hosts/installs.mjs';
17
18
  import { doctorCollect } from '../inspect/doctor.mjs';
19
+ import { emitOf, pickedInstall } from '../inspect/status.mjs';
18
20
  import { DEFAULT_PRESET } from '../loop/score.mjs';
19
21
  import { readText, isFile } from '../lib/fs.mjs';
20
22
  import { stripWhitespace } from '../lib/text.mjs';
@@ -50,12 +52,14 @@ export function fleetSort(list, of) {
50
52
  }
51
53
 
52
54
  /**
53
- * `[target, root]` of THE DEFAULT INSTALL — the one a request that names no install reads — or
54
- * null when no install is active.
55
+ * `[target, root, emit]` of THE DEFAULT INSTALL — the one a request that names no install reads —
56
+ * or null when no install is active. The three are `selectView`'s arguments: the emit travels
57
+ * because a repo with two project installs has one root marker, the last emit's.
55
58
  *
56
- * It is the first ACTIVE install in the console's one install order (`fleetSort`): host order
57
- * (opencode, claude, bob, openclaude), then global before project, then the order
58
- * `installTargets` found them.
59
+ * It is the install the user chose (`POST /api/default-install`, `pickedInstall`) while that one is
60
+ * still active, else the first ACTIVE install in the console's one install order (`fleetSort`):
61
+ * host order (opencode, claude, bob, openclaude), then global before project, then the order
62
+ * `installTargets` found them. A stale pick falls through in silence: it never breaks the console.
59
63
  * There is no viewed install to pick any more (the topbar selector and `POST /api/view` are
60
64
  * gone): a page that wants another install names it on the request. The console once opened
61
65
  * on the OpenCode global dir unconditionally, and on a Bob-only machine (reported 2026-10) it
@@ -66,8 +70,8 @@ export function defaultView(targets = installTargets()) {
66
70
  const active = targets.filter(([host, scope, root]) => {
67
71
  try { return installState(root, host, scope) === 'active'; } catch { return false; }
68
72
  });
69
- const pick = fleetSort(active, ([host, scope]) => [host, scope])[0];
70
- return pick ? [viewCfg(...pick), pick[2]] : null;
73
+ const pick = pickedInstall(active) ?? fleetSort(active, ([host, scope]) => [host, scope])[0];
74
+ return pick ? [viewCfg(...pick), pick[2], emitOf(pick[0], pick[1])] : null;
71
75
  }
72
76
 
73
77
  /**
@@ -118,9 +122,17 @@ export function webState(theme = null, target = null) {
118
122
  // beside it rather than inside so `/api/overview` (fetched after every mutation) does not
119
123
  // carry every group.
120
124
  _doctorRun: null,
125
+ // The warm-up run still in flight, a promise settled when its thread ends (`warmDoctor`).
126
+ _doctorJob: null,
121
127
  // `diffCollect`'s memo of `expected` renders, made on first use by `api.mjs` (`memoOf`);
122
128
  // it re-renders on its own key change, so `refresh()` leaves it alone.
123
129
  renderMemo: null,
130
+ // `apiFleet`'s per-install reads, made on first use; dropped with `_inv`, or aged out there.
131
+ _fleetReads: null,
132
+ // `memoCounts`' last answer, on the daemon's state; every refresh and re-point drops it.
133
+ _counts: null,
134
+ // The emit `selectView` was told, which outranks any marker; null reads the markers.
135
+ _knownEmit: null,
124
136
  // True for a per-install view (`installView` in actions.mjs): `refresh` must never re-point
125
137
  // it at another install, since the request named THIS one.
126
138
  pinned: false,
@@ -157,8 +169,10 @@ export function webState(theme = null, target = null) {
157
169
  },
158
170
  });
159
171
  Object.defineProperty(st, 'doctor', {
172
+ // NULL WHILE THE WARM-UP RUNS, and only then: a pending verdict, which the console draws as
173
+ // "checking" and asks again for. Blocking here would put the run back on the event loop.
160
174
  get() {
161
- if (st._doctor === null) st.runDoctor();
175
+ if (st._doctor === null && st._doctorJob === null) st.runDoctor();
162
176
  return st._doctor;
163
177
  },
164
178
  });
@@ -169,6 +183,7 @@ export function webState(theme = null, target = null) {
169
183
  st.stampDoctor(problems, themes, groups);
170
184
  };
171
185
  st.stampDoctor = (problems, themes = [], groups = []) => {
186
+ st._doctorJob = null; // a run still in flight started earlier: this verdict is the newer one
172
187
  st._doctor = { ok: !problems.length, problems, checked_at: stampMinute(Date.now()) };
173
188
  st._doctorRun = { themes, groups };
174
189
  };
@@ -181,6 +196,7 @@ export function webState(theme = null, target = null) {
181
196
  * `installedDefaults()`.
182
197
  */
183
198
  st.detectEmit = () => {
199
+ if (st._knownEmit) return st._knownEmit;
184
200
  for (const d of [st.root, st.target]) {
185
201
  try {
186
202
  const em = path.join(d, '.geneseed-emit');
@@ -202,17 +218,22 @@ export function webState(theme = null, target = null) {
202
218
  * and a Diff or a Restore would then overwrite it in the wrong dialect. The theme/posture/mode
203
219
  * SIGILS are different: for claude/bob they live in the ROOT carrier (`themeOfDir` scans it);
204
220
  * for openclaude they live ONLY in the data dir's nested `.openclaude/CLAUDE.md`, since its
205
- * root carrier is deliberately left untouched (host-compat B1/I1).
221
+ * root carrier is deliberately left untouched (host-compat B1/I1). `emit`, when the caller knows
222
+ * which install this is, settles the dialect; the root's marker cannot when two hosts share it.
206
223
  */
207
- st.selectView = (target, root = null) => {
224
+ st.selectView = (target, root = null, emit = null) => {
208
225
  st.target = target;
209
226
  st.root = root || target;
227
+ st._knownEmit = emit;
210
228
  st.emit = st.detectEmit();
211
229
  const host = hostOf();
212
230
  st.theme = themeOfDir(st.root, host) || themeOfDir(st.target, host) || 'neutral';
213
231
  readMarkers(host);
214
232
  st._inv = null;
233
+ st._fleetReads = null;
234
+ st._counts = null;
215
235
  st._doctor = null;
236
+ st._doctorJob = null;
216
237
  };
217
238
  /** This state alone. `refresh` below is what callers use: it also reaches every view. */
218
239
  st.refreshOwn = ({ doctor = true } = {}) => {
@@ -223,7 +244,10 @@ export function webState(theme = null, target = null) {
223
244
  const def = doctor && !st.pinned ? defaultView() : null;
224
245
  if (def && !samePath(def[0], st.target)) { st.selectView(...def); return; }
225
246
  st._inv = null;
226
- if (doctor) st._doctor = null;
247
+ st._fleetReads = null;
248
+ st._counts = null;
249
+ // The job goes too: what it read may be what this mutation changed, so its answer is dropped.
250
+ if (doctor) { st._doctor = null; st._doctorJob = null; }
227
251
  st.emit = st.detectEmit() || st.emit;
228
252
  const host = hostOf();
229
253
  st.theme = themeOfDir(st.root, host) || themeOfDir(st.target, host) || st.theme;
@@ -240,15 +264,50 @@ export function webState(theme = null, target = null) {
240
264
  return st;
241
265
  }
242
266
 
267
+ // Several times the slowest run seen on a loaded machine: a run past this has hung.
268
+ const WARM_DOCTOR_LIMIT_MS = 180_000;
269
+
243
270
  /**
244
- * Run the doctor once in the background, right after the server binds, so the first
245
- * `/api/overview` finds a verdict instead of paying the ~3.6 s itself. Still synchronous once it
246
- * starts — the event loop is blocked for that run — so a request landing mid-run waits for it,
247
- * no longer than it would have. The catch is not optional: a throw inside `setImmediate` is
248
- * uncaught and would kill the daemon; a failed warm-up just leaves the cache cold.
271
+ * Run the doctor once right after the server binds, ON ITS OWN THREAD. On the event loop this run
272
+ * held every request of a cold daemon for 13-24 s, past `BootSplash`'s stall at 8 s. Until it
273
+ * lands `st.doctor` is null and `/api/doctor` waits on the promise this returns.
274
+ *
275
+ * A verdict is stamped only while its job is still the current one: `refresh`, `selectView` and a
276
+ * newer run all clear `_doctorJob`, and the daemon must not serve what a mutation made stale. A
277
+ * failed warm-up, like the old one, just leaves the cache cold: the next ask runs in line. The
278
+ * `error` listener is not optional, an unheard worker error is uncaught and kills the daemon.
279
+ * `unref`: a stopping daemon does not wait for it.
280
+ *
281
+ * A HUNG run would leave `/api/doctor` unanswered and the console polling for good, so past
282
+ * `limitMs` it is stopped and stamped as a FAILED verdict: unknown is never a green. Re-run clears it.
249
283
  */
250
- export function warmDoctor(st) {
251
- setImmediate(() => {
252
- try { if (st._doctor === null) st.runDoctor(); } catch { /* cold cache, computed on demand */ }
284
+ export function warmDoctor(st, limitMs = WARM_DOCTOR_LIMIT_MS) {
285
+ if (st._doctor !== null || st._doctorJob !== null) return st._doctorJob;
286
+ let worker;
287
+ try {
288
+ worker = new Worker(new URL('./doctor-worker.mjs', import.meta.url),
289
+ { workerData: { theme: st.theme } });
290
+ } catch { return null; }
291
+ worker.unref();
292
+ const job = new Promise((done) => {
293
+ const limit = setTimeout(() => {
294
+ if (st._doctorJob === job) {
295
+ const said = `[doctor] the warm-up run did not finish in ${limitMs / 1000} s, so nothing was checked`;
296
+ st.stampDoctor([said], [], [{ check: 'warm_up', label: 'Warm-up run', problems: [said] }]);
297
+ }
298
+ worker.terminate();
299
+ }, limitMs);
300
+ limit.unref();
301
+ worker.once('message', (r) => {
302
+ if (st._doctorJob === job) st.stampDoctor(r.problems, r.themes, r.groups);
303
+ });
304
+ worker.once('error', () => { /* cold cache, computed on demand */ });
305
+ worker.once('exit', () => {
306
+ clearTimeout(limit);
307
+ if (st._doctorJob === job) st._doctorJob = null;
308
+ done();
309
+ });
253
310
  });
311
+ st._doctorJob = job;
312
+ return job;
254
313
  }
@@ -23,7 +23,7 @@ import { existsSync, realpathSync } from 'node:fs';
23
23
  import path from 'node:path';
24
24
 
25
25
  import { ROOT } from '../build/source.mjs';
26
- import { measureUpstream } from '../maintain/update.mjs';
26
+ import { measureUpstream, preflight } from '../maintain/update.mjs';
27
27
  import { normcase, which } from '../lib/paths.mjs';
28
28
 
29
29
  const DAY_MS = 24 * 60 * 60 * 1000;
@@ -68,12 +68,13 @@ export function updateStatus(state, current, { fetcher = npmLatest, now = Date.n
68
68
  /**
69
69
  * The once-a-day cache both checks share: answer from `state[slot]` at once and, when that is
70
70
  * missing or stale, start ONE background ask whose answer the next poll reads. A null answer
71
- * (every failure) is re-asked after RETRY_MS, a good one after DAY_MS.
71
+ * (every failure) is re-asked after RETRY_MS, and so is `false` (a pull that cannot run), which a
72
+ * `git checkout main` can end at any moment. A good one is re-asked after DAY_MS.
72
73
  */
73
74
  function daily(state, slot, ask, now, off) {
74
75
  const c = state[slot] || (state[slot] = { value: null, checked_at: null, inflight: false });
75
76
  const stale = c.checked_at === null
76
- || now - c.checked_at > (c.value === null ? RETRY_MS : DAY_MS);
77
+ || now - c.checked_at > (c.value === null || c.value === false ? RETRY_MS : DAY_MS);
77
78
  if (stale && !c.inflight && !off && !process.env.GENESEED_NO_UPDATE_CHECK) {
78
79
  c.inflight = true;
79
80
  Promise.resolve()
@@ -84,18 +85,32 @@ function daily(state, slot, ask, now, off) {
84
85
  return c;
85
86
  }
86
87
 
87
- /** `measureUpstream`'s verdict as a count: 0 up to date, N to pull, null when unknown. */
88
- async function fetchBehind() {
89
- const [code, behind] = await measureUpstream();
88
+ /**
89
+ * `measureUpstream`'s verdict: 0 up to date, N to pull, null when the remote gave no answer, false
90
+ * when it did and `upgrade` would refuse to pull (no upstream, diverged, unrelated history).
91
+ */
92
+ export function behindOf(code, behind) {
90
93
  if (code === 'uptodate') return 0;
91
- return code === 'ready' ? behind : null;
94
+ if (code === 'ready') return behind;
95
+ return code === 'fetch_failed' ? null : false;
96
+ }
97
+
98
+ /**
99
+ * `upgrade`'s two gates in its own order. The local one comes first, so a checkout that could
100
+ * never pull (local changes, a detached HEAD, no upstream) answers `false` with no fetch at all,
101
+ * and so offline too. `pre` and `measure` are injectable for the tests.
102
+ */
103
+ export async function fetchBehind({ pre = preflight, measure = measureUpstream } = {}) {
104
+ if (!pre().ok) return false;
105
+ const [code, behind] = await measure();
106
+ return behindOf(code, behind);
92
107
  }
93
108
 
94
109
  /**
95
110
  * Commits the clone's upstream holds that it does not: `upgrade`'s own `git fetch` (timeboxed by
96
111
  * `GENESEED_NET_TIMEOUT`, 120 s by default) then a count, once a day, in the background. Null
97
- * until the first answer lands and on every failure — an unreachable remote, no upstream, a
98
- * branch that diverged — and the console then keeps its "a clone can always pull" button.
112
+ * until the first answer lands and on an unreachable remote, and the console then keeps its "a
113
+ * clone can always pull" button; false for a pull that cannot run, and the console drops it.
99
114
  *
100
115
  * `busy` skips the ask while a job runs: a fetch beside the update job's own pull would race it
101
116
  * for `.git` locks. `measure` and `now` are injectable for the tests.
@@ -109,7 +124,7 @@ export function gitBehind(state, { measure = fetchBehind, now = Date.now(), busy
109
124
  export const MANUAL_UPDATE = 'npm install -g geneseed@latest';
110
125
 
111
126
  /** `npm root -g`, or null when npm is absent or does not answer. Asked once per daemon. */
112
- export function npmGlobalRoot() {
127
+ function npmGlobalRoot() {
113
128
  const npm = which('npm');
114
129
  if (!npm) return null;
115
130
  const win = process.platform === 'win32';
@@ -12,14 +12,14 @@ import path from 'node:path';
12
12
 
13
13
  import { PROFILE_STUB } from '../build/stubs.mjs';
14
14
  import { readMaybe } from '../hosts/installs.mjs';
15
- import { frontmatter } from '../hosts/memory-files.mjs';
15
+ import { splitLines } from '../hosts/hooks-prims.mjs';
16
+ import { frontmatter, isRuleEdge, parseDraft, parseRules, readFoldState } from '../hosts/memory-files.mjs';
16
17
  import { writeText, isFile, isDir } from '../lib/fs.mjs';
17
18
  import { formatRepr, isTruthy } from '../lib/json.mjs';
18
19
  import { WHITESPACE, codePointLength, stripWhitespace } from '../lib/text.mjs';
19
- import { splitLines } from '../lib/udiff.mjs';
20
20
  import { isFactName } from '../maintain/memory.mjs';
21
21
  import { apiMemoryDelete, bget, strOr } from './actions.mjs';
22
- import { BadRequest, NotFound, memoryDir } from './catalog.mjs';
22
+ import { BadRequest, NotFound, memoryDir, tierOf } from './catalog.mjs';
23
23
 
24
24
  /** Splits on runs of `WHITESPACE` (not `\s`), dropping empty strings. */
25
25
  const splitWords = (s) => s.split(new RegExp(`[${WHITESPACE}]+`)).filter(Boolean);
@@ -59,122 +59,64 @@ const fpMatches = (got, want) => typeof got === 'string' && got === want;
59
59
  // ---- user rules (user-rules.md) ----------------------------------------------------------
60
60
 
61
61
  export const RULES_FILE = 'user-rules.md';
62
- const rulesPath = (state) => path.join(state.target, RULES_FILE);
62
+ /** The folder of the two hand-written files: the tier for a global install, else the bundle. */
63
+ const userDir = (state, tier = tierOf(state)) => tier?.root ?? state.target;
64
+ const rulesPath = (state, tier) => path.join(userDir(state, tier), RULES_FILE);
63
65
 
64
66
  /**
65
- * `## R<n> — Title`, anchored at column 0 so a rule body's fenced code and the stub's
66
- * indented format example never parse as rules.
67
- *
68
- * The whitespace classes are `WHITESPACE`, not `\s`: this pattern runs over a HAND-EDITED
69
- * file, which is where a non-breaking space actually turns up. `\S` is its complement for
70
- * the same reason.
71
- *
72
- * `\d` IS LEFT ASCII, and that is a declared divergence rather than an oversight, unlike
73
- * `ruleFields` below which uses `\p{Nd}`. No theme seeds a non-ASCII rule id, no build
74
- * writes one, and the web editor cannot produce one either — it writes `R<n>` itself from
75
- * `max(ids) + 1`. Widening this to match would only move the gap one line down, to whatever
76
- * parses the captured digits back into a number.
77
- */
78
- const RULE_HEAD_RE = new RegExp(
79
- `^##[${WHITESPACE}]+R(\\d+)[${WHITESPACE}]*[—–-]+[${WHITESPACE}]*`
80
- + `([^${WHITESPACE}].*?)[${WHITESPACE}]*$`,
81
- );
82
-
83
- /**
84
- * A line `parseRules` reads as the edge of a rule: `## ` ends the current block, and a
85
- * `RULE_HEAD_RE` line opens one (a non-breaking space after `##` does the second, not the first).
86
- * ONE predicate for both the parser and `ruleFields`, so a body the writer accepts can never
87
- * split or forge a rule when read back.
67
+ * The blocks the fold left in `<tier>/user-rules.draft.md`, as `{title, host, body}`, in file
68
+ * order (`parseDraft` reads the format). The console only SHOWS them: the rule Rite is the only
69
+ * draft writer (C15), so no verb here decides one. A block the ledger already holds as decided is
70
+ * left over from a stopped Rite write, so it is not pending; a block with no row, or a ledger that
71
+ * does not parse, still shows. Empty for a project install and for a missing draft.
88
72
  */
89
- const isRuleEdge = (line) => line.startsWith('## ') || RULE_HEAD_RE.test(line);
90
-
91
- /** Advisory only; nothing blocks past it. */
92
- const RULES_BUDGET = { max_rules: 15, max_tokens: 1500 };
93
-
94
- const META_RE = new RegExp(`^\\((.+)\\)[${WHITESPACE}]*$`);
95
-
96
- /** `{}` when the line is body rather than metadata. */
97
- function parseRuleMeta(line) {
98
- const m = META_RE.exec(stripWhitespace(line));
99
- if (!m) return {};
100
- const meta = {};
101
- for (const part of m[1].split('|')) {
102
- const at = part.indexOf(':');
103
- if (at < 0) continue; // `partition` with no separator — not a pair
104
- const key = stripWhitespace(part.slice(0, at)).toLowerCase().replaceAll(' ', '_');
105
- if (['scope', 'source', 'trial_until'].includes(key)) {
106
- meta[key] = stripWhitespace(part.slice(at + 1));
107
- }
108
- }
109
- return meta;
73
+ function ruleDrafts(tier) {
74
+ if (tier === null) return [];
75
+ let ledger = {};
76
+ try { ledger = readFoldState(tier).items; } catch { /* shows all */ }
77
+ const decided = ({ key }) => {
78
+ const row = ledger[key];
79
+ return row != null && row.state !== 'pending';
80
+ };
81
+ return parseDraft(readMaybe(tier.draft) ?? '').filter((d) => !decided(d))
82
+ .map(({ title, host, body }) => ({ title, host, body }));
110
83
  }
111
84
 
112
85
  /**
113
- * `user-rules.md` parsed to `[rules, warnings]`.
114
- *
115
- * Every rule carries its `start`/`end` LINE INDICES, which is what lets `apiRulesMutate`
116
- * splice exactly one block and leave every other byte of the user's file — prose,
117
- * formatting, hand-written sections — untouched.
118
- * @returns {[Array<{id: number, start: number, end: number} & Record<string, any>>, string[]]}
86
+ * The estimate of what a text costs in the context, each turn. CODE POINTS, not `String.length`
87
+ * (UTF-16 units): an emoji in a rule body would otherwise put it off.
119
88
  */
120
- export function parseRules(text) {
121
- const lines = splitLines(text);
122
- const rules = [];
123
- const warnings = [];
124
- const seen = new Set();
125
- for (let idx = 0; idx < lines.length; idx += 1) {
126
- const m = RULE_HEAD_RE.exec(lines[idx]);
127
- if (!m) continue;
128
- let end = lines.length;
129
- for (let j = idx + 1; j < lines.length; j += 1) {
130
- if (isRuleEdge(lines[j])) { end = j; break; }
131
- }
132
- const rid = Number(m[1]);
133
- if (seen.has(rid)) warnings.push(`duplicate rule id R${rid}`);
134
- seen.add(rid);
135
- let k = idx + 1;
136
- while (k < end && !stripWhitespace(lines[k])) k += 1;
137
- const meta = k < end ? parseRuleMeta(lines[k]) : {};
138
- if (Object.keys(meta).length) k += 1;
139
- rules.push({
140
- id: rid,
141
- title: m[2],
142
- scope: Object.hasOwn(meta, 'scope') ? meta.scope : 'project',
143
- source: Object.hasOwn(meta, 'source') ? meta.source : '',
144
- trial_until: Object.hasOwn(meta, 'trial_until') ? meta.trial_until : '',
145
- body: stripWhitespace(lines.slice(k, end).join('\n')),
146
- start: idx,
147
- end,
148
- });
149
- }
150
- return [rules, warnings];
151
- }
89
+ const tokensOf = (text) => Math.floor(codePointLength(text) / 4);
152
90
 
153
91
  export function apiRules(state) {
154
- const p = rulesPath(state);
92
+ const tier = tierOf(state);
93
+ const p = rulesPath(state, tier);
94
+ const shared = tier !== null;
95
+ const drafts = ruleDrafts(tier);
155
96
  if (!isFile(p)) {
156
- return { exists: false, path: p, rules: [], warnings: [], fingerprint: '',
157
- stats: { rules: 0, lines: 0, tokens: 0, ...RULES_BUDGET } };
97
+ return { exists: false, path: p, rules: [], warnings: [], fingerprint: '', shared, drafts,
98
+ stats: { rules: 0, lines: 0, tokens: 0 } };
158
99
  }
159
100
  const text = readMaybe(p) ?? '';
160
101
  const [rules, warnings] = parseRules(text);
161
102
  const today = todayIso();
103
+ const lines = splitLines(text);
162
104
  const out = rules.map((r) => ({
163
105
  id: r.id, title: r.title, scope: r.scope, source: r.source,
164
106
  trial_until: r.trial_until,
165
107
  status: r.trial_until ? 'trial' : 'active',
166
108
  overdue: Boolean(r.trial_until) && r.trial_until < today,
167
109
  body: r.body,
110
+ // The rule's whole block, heading and metadata too: that is what the agent reads.
111
+ tokens: tokensOf(stripWhitespace(lines.slice(r.start, r.end).join('\n'))),
168
112
  }));
169
- return { exists: true, path: p, rules: out, warnings, fingerprint: fingerprint(text),
170
- // CODE POINTS, not `String.length` (UTF-16 units) — an emoji in a rule body would
171
- // otherwise put the token estimate off.
172
- stats: { rules: rules.length, lines: splitLines(text).length,
173
- tokens: Math.floor(codePointLength(text) / 4), ...RULES_BUDGET } };
113
+ return { exists: true, path: p, rules: out, warnings, fingerprint: fingerprint(text), shared, drafts,
114
+ // The whole file, so it holds its header too: more than the rules' own tokens added up.
115
+ stats: { rules: rules.length, lines: lines.length, tokens: tokensOf(text) } };
174
116
  }
175
117
 
176
- function rulesRead(state) {
177
- const p = rulesPath(state);
118
+ function rulesRead(state, tier) {
119
+ const p = rulesPath(state, tier);
178
120
  return [p, isFile(p) ? (readMaybe(p) ?? '') : ''];
179
121
  }
180
122
 
@@ -189,7 +131,7 @@ function ruleBlock(rid, title, scope, source, trialUntil, body) {
189
131
  * Validate and normalise a rule's writable fields. Throws `BadRequest` (→ the shell's 400,
190
132
  * carrying the message) on an unusable rule.
191
133
  *
192
- * `\p{Nd}` here and not `\d`, unlike `RULE_HEAD_RE` above: this is a pure predicate over a
134
+ * `\p{Nd}` here and not `\d`, unlike `RULE_HEAD_RE` in ../hosts/memory-files.mjs: this is a pure predicate over a
193
135
  * string that stays a string, so accepting any Unicode decimal digit costs nothing and
194
136
  * needs no numeric parse afterward.
195
137
  *
@@ -244,7 +186,7 @@ function ruleId(v) {
244
186
  * mistake; it exists so a retire never loses the text. Like user-rules.md it is the user's: no
245
187
  * install manifest claims it, so no uninstall deletes it.
246
188
  */
247
- export const RETIRED_RULES_FILE = 'user-rules-retired.md';
189
+ const RETIRED_RULES_FILE = 'user-rules-retired.md';
248
190
  const RETIRED_HEADER = '# Retired rules — not in force, never loaded into any session.\n';
249
191
  const isBlank = (line) => !stripWhitespace(line);
250
192
 
@@ -263,14 +205,15 @@ export function apiRulesMutate(state, body) {
263
205
  if (op !== 'add' && op !== 'update' && op !== 'delete') {
264
206
  throw new NotFound(`rules op ${formatRepr(op)}`);
265
207
  }
266
- const [p, original] = rulesRead(state);
208
+ const tier = tierOf(state);
209
+ const [p, original] = rulesRead(state, tier);
267
210
  let text = original;
268
211
  if (!fpMatches(bget(body, 'fingerprint', ''), fingerprint(text))) {
269
212
  return { ok: false, error: 'conflict',
270
213
  detail: 'user-rules.md changed since you loaded it — reloading' };
271
214
  }
272
215
  const [rules] = parseRules(text);
273
- const retiredPath = path.join(state.target, RETIRED_RULES_FILE);
216
+ const retiredPath = path.join(userDir(state, tier), RETIRED_RULES_FILE);
274
217
  let rid;
275
218
  let next;
276
219
  if (op === 'add') {
@@ -348,19 +291,21 @@ export function apiRulesPromote(state, body) {
348
291
 
349
292
  // ---- PROFILE.md --------------------------------------------------------------------------
350
293
 
351
- /** Beside the deployed AGENT.md. */
294
+ /** In `userDir`: the tier for a global install, else beside the deployed AGENT.md. */
352
295
  export const PROFILE_FILE = 'PROFILE.md';
353
- const profilePath = (state) => path.join(state.target, PROFILE_FILE);
296
+ const profilePath = (state, tier) => path.join(userDir(state, tier), PROFILE_FILE);
354
297
 
355
298
  export function apiProfile(state) {
356
- const p = profilePath(state);
357
- if (!isFile(p)) return { exists: false, path: p, text: '', fingerprint: '' };
299
+ const tier = tierOf(state);
300
+ const p = profilePath(state, tier);
301
+ const shared = tier !== null;
302
+ if (!isFile(p)) return { exists: false, path: p, text: '', fingerprint: '', shared };
358
303
  const text = readMaybe(p) ?? '';
359
304
  // `seeded`: the file is still the template the build wrote once and never touched since.
360
305
  // `readMaybe` normalises line endings, so a CRLF copy (the emit writes the platform's, and
361
306
  // an editor may re-save either way) still compares equal to the LF literal.
362
307
  const seeded = text === PROFILE_STUB;
363
- return { exists: true, path: p, text, fingerprint: fingerprint(text), seeded };
308
+ return { exists: true, path: p, text, fingerprint: fingerprint(text), seeded, shared };
364
309
  }
365
310
 
366
311
  /** The whole file, fingerprint-guarded like the rules above. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
- "//": "Every field here is argued and gated in tests/unit/package_manifest.test.mjs. `files`, `bin` and `engines` each have a test that fails when reality drifts from this file; `version` mirrors harness.config.json and is gated too. Read that docblock before editing this one.",
2
+ "//": "Every field here is argued and gated in tests/unit/package_manifest.test.mjs. `files`, `bin`, `exports` and `engines` each have a test that fails when reality drifts from this file; `version` mirrors harness.config.json and is gated too. Read that docblock before editing this one.",
3
3
  "name": "geneseed",
4
- "version": "4.32.0",
4
+ "version": "5.0.0",
5
5
  "description": "A portable, theme-able harness you implant once and use everywhere to grow a disciplined AI coding agent.",
6
6
  "keywords": [
7
7
  "ai",
@@ -31,6 +31,9 @@
31
31
  "geneseed-hook": "bin/geneseed-hook.mjs",
32
32
  "geneseed-build": "bin/build-driver.mjs"
33
33
  },
34
+ "exports": {
35
+ "./package.json": "./package.json"
36
+ },
34
37
  "files": [
35
38
  "bin/",
36
39
  "js/",
@@ -65,7 +68,7 @@
65
68
  "typescript": "^5.9.3"
66
69
  },
67
70
  "scripts": {
68
- "lint": "eslint js bin tests adapters fuzz",
69
- "typecheck": "tsc -p ."
71
+ "lint": "eslint --cache --cache-location node_modules/.cache/eslint/ js bin tests adapters fuzz",
72
+ "typecheck": "tsc -p . --incremental --tsBuildInfoFile node_modules/.cache/tsc/tsbuildinfo"
70
73
  }
71
74
  }