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/web/routes.mjs CHANGED
@@ -8,10 +8,8 @@
8
8
  * test, and probes the real handler, because a declaration is not a dispatcher — a route can be
9
9
  * declared here and missing from the dispatch, and nothing but a probe notices.
10
10
  *
11
- * This file used to also carry the Python→Node port's NOT_PORTED / DECLINED partition — five
12
- * sets, all empty once the port finished. They were deleted when the port bookkeeping retired
13
- * (see git history); an unmatched GET falls through to `serveStatic`'s SPA fallback and an
14
- * unmatched POST answers 404, which is what the empty sets already produced.
11
+ * An unmatched GET falls through to `serveStatic`'s SPA fallback and an unmatched POST
12
+ * answers 404.
15
13
  *
16
14
  * Split out of `server.mjs` because it is the half a reader consults to answer "does the console
17
15
  * expose X?", which has nothing to do with sockets, daemons or gzip.
@@ -22,14 +20,15 @@ import { percentDecode } from '../lib/text.mjs';
22
20
  import { apiExcludesMutate, apiInstallToggle, apiLoopsPresetMutate, apiMcp, apiMemoryDelete, targetView } from './actions.mjs';
23
21
  import { apiActivity, apiActivityDetail, apiActivityToggle } from './activity.mjs';
24
22
  import {
25
- apiDiff, apiDoctor, apiExcludes, apiFleet, apiInstalls, apiKits, apiLoops, apiLoopsActive, apiOverview,
23
+ apiDefaultInstallSet, apiDiff, apiDoctor, apiExcludes, apiFleet, apiInstalls, apiKits, apiLoops, apiLoopsActive, apiOverview, memoCounts,
26
24
  apiRecent, apiSetup, apiThemes, activeInstalls, apiUpdate,
27
25
  } from './api.mjs';
28
26
  import { FLEET_SECTIONS, NotFound, apiCatalog, apiItem } from './catalog.mjs';
29
27
  import { apiUsage } from './usage-api.mjs';
30
28
  import { fleetSort } from './state.mjs';
31
29
  import { apiGates } from './gates-api.mjs';
32
- import { apiProfile, apiProfileSave, apiRules, apiRulesMutate, apiRulesPromote } from './user-files.mjs';
30
+ import { migratePreview } from '../maintain/migrate.mjs';
31
+ import { apiProfile, apiProfileSave, apiRules, apiRulesDecide, apiRulesMutate, apiRulesPromote } from './user-files.mjs';
33
32
 
34
33
  /**
35
34
  * The POSTs this daemon answers — and this table IS the dispatch, not a declaration beside
@@ -48,6 +47,7 @@ import { apiProfile, apiProfileSave, apiRules, apiRulesMutate, apiRulesPromote }
48
47
  /** @type {Map<string, [(state: any, body: any) => any, boolean]>} */
49
48
  export const POST_ROUTES = new Map([
50
49
  ['/api/install', [apiInstallToggle, true]],
50
+ ['/api/default-install', [apiDefaultInstallSet, true]],
51
51
  ['/api/excludes', [apiExcludesMutate, true]],
52
52
  ['/api/activity', [apiActivityToggle, false]],
53
53
  // The dispatch wrapper resolves `name` from the body itself; `apiMemoryDelete` takes a bare
@@ -56,6 +56,7 @@ export const POST_ROUTES = new Map([
56
56
  [(state, b) => apiMemoryDelete(state, isTruthy(b.name) ? formatValue(b.name) : ''), false]],
57
57
  ['/api/rules', [apiRulesMutate, true]],
58
58
  ['/api/rules/promote', [apiRulesPromote, true]],
59
+ ['/api/rules/decide', [apiRulesDecide, true]],
59
60
  ['/api/profile', [apiProfileSave, true]],
60
61
  // No `ok: false` arm: success returns `{ok: true, loop}`, and both refusals (unknown root,
61
62
  // unknown preset) throw `NotFound`, which `doPost`'s catch answers 404 before this column is
@@ -65,13 +66,13 @@ export const POST_ROUTES = new Map([
65
66
 
66
67
  /**
67
68
  * The POSTs whose body `{host, path}` names the install they act on (`installView`), opt-in
68
- * rather than every POST: in `/api/install` and `/api/actions/install` the pair is
69
- * the target the route resolves itself, and in `/api/actions/deploy`, `/api/excludes` and
69
+ * rather than every POST: in `/api/install`, `/api/default-install` and `/api/actions/install` the
70
+ * pair is the target the route resolves itself, and in `/api/actions/deploy`, `/api/excludes` and
70
71
  * `/api/reveal` a `path` is a folder or a config file, not an install. The two `actions/` rows
71
72
  * are the only actions that read the request's install.
72
73
  */
73
74
  export const VIEW_POSTS = new Set(['/api/activity', '/api/memory/delete', '/api/rules',
74
- '/api/rules/promote', '/api/profile', '/api/actions/restore', '/api/actions/build']);
75
+ '/api/rules/promote', '/api/rules/decide', '/api/profile', '/api/actions/restore', '/api/actions/build']);
75
76
 
76
77
  /**
77
78
  * The GETs that answer for the whole machine, not one install: they IGNORE a `?host=&path=`
@@ -83,13 +84,14 @@ export const VIEW_POSTS = new Set(['/api/activity', '/api/memory/delete', '/api/
83
84
  * toggle (a `VIEW_POSTS` write) still take the pair. Every other `/api/*` GET, ping and jobs
84
85
  * aside, takes the pair and refuses an unknown one.
85
86
  *
86
- * The Library's fleet lists (`/api/catalog/skills|agents|memory|notebook`) are here because they
87
- * read every active install (`fleetOf`), which caches one view per install on the daemon state;
88
- * the other catalog sections, and `/api/item/`, stay install-scoped (`PREFIX_ROUTES`).
87
+ * The Library's fleet lists (`/api/catalog/<FLEET_SECTIONS>`) are here because they read every
88
+ * active install (`fleetOf`), which caches one view per install on the daemon state; the laws
89
+ * section, and `/api/item/`, stay install-scoped (`PREFIX_ROUTES`).
89
90
  */
90
- export const MACHINE_GETS = new Set(['/api/update', '/api/installs', '/api/fleet', '/api/kits',
91
+ export const MACHINE_GETS = new Set(['/api/update', '/api/installs', '/api/fleet', '/api/migrate/preview', '/api/kits',
91
92
  '/api/usage', '/api/gates', '/api/excludes', '/api/mcp', '/api/loops/active', '/api/activity',
92
- '/api/catalog/skills', '/api/catalog/agents', '/api/catalog/memory', '/api/catalog/notebook']);
93
+ '/api/catalog/skills', '/api/catalog/agents', '/api/catalog/memory', '/api/catalog/notebook',
94
+ '/api/catalog/wiki', '/api/catalog/config']);
93
95
 
94
96
  /**
95
97
  * The 409 column, exported so a test can assert it directly. Giving `/api/activity` the 409
@@ -143,9 +145,8 @@ export function readJsonBody(buf) {
143
145
  }
144
146
 
145
147
  /**
146
- * Every ACTIVE install as `{install, state}`, the Library's fleet lists' source (skills, agents,
147
- * memory, notebook: `FLEET_SECTIONS`): `install`
148
- * is the usage ledger's `host:scope:root` key, `state` the install's cached view off the daemon
148
+ * Every ACTIVE install as `{install, state}`, the source of the Library's fleet lists
149
+ * (`FLEET_SECTIONS`) and of the overview's counts: `install` is the usage ledger's `host:scope:root` key, `state` the install's cached view off the daemon
149
150
  * state `base` (`targetView`), so each install keeps its own inventory cache. ONE
150
151
  * `installTargets()` scan: the targets it yields are the allowlist, so no view re-checks its
151
152
  * pair the way a request-named one must (`installView`). In the console's install order
@@ -175,12 +176,11 @@ export const PREFIX_ROUTES = [
175
176
  }],
176
177
  // /api/item/<type>/<name> — TYPE has no slash, the NAME keeps its slashes so a wiki
177
178
  // page's relpath survives. A missing name is a 404 here rather than a 500 two frames down.
178
- // Install-scoped: a skill, agent, memory or notebook entry is the named install's copy, else
179
- // the fleet's first.
179
+ // Install-scoped: a Library entry is the named install's copy, else the fleet's first.
180
180
  ['/api/item/', (state, p, base) => {
181
181
  const m = /^\/api\/item\/([^/]+)\/(.+)$/.exec(p);
182
182
  if (!m) throw new NotFound(p);
183
- const fleet = ['skill', 'agent', 'memory', 'notebook'].includes(m[1]) ? fleetOf(base) : undefined;
183
+ const fleet = m[1] !== 'law' ? fleetOf(base) : undefined;
184
184
  return apiItem(state, m[1], percentDecode(m[2]), fleet);
185
185
  }],
186
186
  // The sid is passed through unquoted — `apiActivityDetail`'s safe-name scheme is what
@@ -196,7 +196,7 @@ export const PREFIX_ROUTES = [
196
196
  * test, so a route cannot appear or vanish unenumerated.
197
197
  */
198
198
  export const STATE_ROUTES = {
199
- '/api/overview': apiOverview,
199
+ '/api/overview': (state, url, base) => apiOverview(state, memoCounts(base, () => fleetOf(base))),
200
200
  '/api/recent': apiRecent,
201
201
  '/api/themes': apiThemes,
202
202
  '/api/setup': apiSetup,
@@ -204,7 +204,9 @@ export const STATE_ROUTES = {
204
204
  '/api/doctor': (state, url) => apiDoctor(state,
205
205
  new URL(url || '', 'http://x').searchParams.has('fresh')),
206
206
  '/api/installs': apiInstalls,
207
- '/api/fleet': apiFleet,
207
+ '/api/fleet': (state) => apiFleet(state),
208
+ // Reads every global install, and writes nothing: the console's view of `migrate --dry-run`.
209
+ '/api/migrate/preview': () => migratePreview(),
208
210
  '/api/kits': apiKits,
209
211
  '/api/update': apiUpdate,
210
212
  '/api/usage': apiUsage,
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,8 +23,8 @@ 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';
27
- import { normcase, which } from '../lib/paths.mjs';
26
+ import { measureUpstream, preflight } from '../maintain/update.mjs';
27
+ import { inNodeModules, normcase, which } from '../lib/paths.mjs';
28
28
 
29
29
  const DAY_MS = 24 * 60 * 60 * 1000;
30
30
  /** A failed ask is retried sooner than a good answer is refreshed: a proxy hiccup is not a day. */
@@ -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';
@@ -147,7 +162,7 @@ export function installKind({ root = ROOT, npmRoot = npmGlobalRoot } = {}) {
147
162
  let kind = 'other';
148
163
  let unanswered = false;
149
164
  if (existsSync(path.join(root, '.git'))) kind = 'git';
150
- else if (path.basename(path.dirname(root)).toLowerCase() === 'node_modules') {
165
+ else if (inNodeModules(root)) {
151
166
  const g = npmRoot();
152
167
  unanswered = !g;
153
168
  if (g && real(g) === real(path.dirname(root))) kind = 'npm-global';