geneseed 6.0.2 → 6.0.4

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 (99) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/DESIGN.md +1 -1
  3. package/SHIPPED.md +1 -1
  4. package/adapters/opencode/plugins/geneseed-context.js +11 -10
  5. package/adapters/opencode/plugins/geneseed-learn.js +24 -8
  6. package/bin/geneseed-hook.mjs +5 -0
  7. package/docs/concepts/hooks.md +6 -6
  8. package/docs/guides/install-scripted.md +1 -1
  9. package/docs/reference/env-context.md +2 -1
  10. package/docs/reference/plugin-activity.md +1 -1
  11. package/docs/reference/profiles.md +1 -0
  12. package/docs/understand/a-day.md +1 -1
  13. package/docs/understand/machine-claude.md +1 -1
  14. package/docs/web-ui.md +27 -2
  15. package/harness.config.json +1 -1
  16. package/js/build/args.mjs +4 -3
  17. package/js/build/bundle.mjs +2 -11
  18. package/js/build/driver.mjs +8 -8
  19. package/js/build/emit-claude.mjs +59 -4
  20. package/js/build/fold.mjs +3 -20
  21. package/js/build/generate.mjs +11 -2
  22. package/js/build/profile.mjs +10 -5
  23. package/js/build/render.mjs +3 -1
  24. package/js/build/source.mjs +12 -1
  25. package/js/build/stubs.mjs +42 -5
  26. package/js/cli-table.json +37 -0
  27. package/js/hosts/hooks-context.mjs +9 -8
  28. package/js/hosts/hooks-learn.mjs +435 -55
  29. package/js/hosts/installs.mjs +22 -2
  30. package/js/hosts/memory-files.mjs +249 -13
  31. package/js/hosts/native.mjs +23 -1
  32. package/js/hosts/settings.mjs +77 -4
  33. package/js/inspect/diff.mjs +3 -1
  34. package/js/inspect/doctor.mjs +37 -1
  35. package/js/inspect/status.mjs +40 -4
  36. package/js/inspect/validate.mjs +1 -1
  37. package/js/lib/proc.mjs +36 -0
  38. package/js/maintain/memory.mjs +2 -2
  39. package/js/maintain/profiles.mjs +15 -4
  40. package/js/maintain/setup.mjs +31 -7
  41. package/js/maintain/update.mjs +1 -1
  42. package/js/web/actions.mjs +5 -3
  43. package/js/web/api.mjs +2 -2
  44. package/js/web/catalog.mjs +5 -3
  45. package/js/web/profiles-api.mjs +2 -2
  46. package/js/web/state.mjs +13 -2
  47. package/package.json +1 -1
  48. package/src/AGENT.md.tmpl +1 -1
  49. package/src/agents/memory-curator.md +4 -1
  50. package/src/doctrines/process.md +2 -2
  51. package/src/memory/README.md +45 -6
  52. package/src/skills/rule/approve.md +3 -1
  53. package/src/skills/rule/consolidate.md +1 -1
  54. package/src/skills/rule.md +9 -5
  55. package/web/dist/assets/ActiveLoops-paFbiZyt.js +1 -0
  56. package/web/dist/assets/Activity-BsMFA5Aa.js +1 -0
  57. package/web/dist/assets/ActivityDetail-C66n3oul.js +1 -0
  58. package/web/dist/assets/{Bonsai-Bry-kOFb.js → Bonsai-BCd-qt7W.js} +1 -1
  59. package/web/dist/assets/{CopyButton-Cnnvjgkg.js → CopyButton-Dpl0PFja.js} +1 -1
  60. package/web/dist/assets/Dashboard-CQxdiv7F.js +2 -0
  61. package/web/dist/assets/{Docs-BJ23-fIx.js → Docs-D0XlXuiA.js} +2 -2
  62. package/web/dist/assets/Factories-CPVBoWoA.js +1 -0
  63. package/web/dist/assets/{GreenhouseView-VL_ZKJUR.js → GreenhouseView-C_2auUA8.js} +1 -1
  64. package/web/dist/assets/Installs-CXqjmqms.js +3 -0
  65. package/web/dist/assets/JournalView-S-igd-Nv.js +1 -0
  66. package/web/dist/assets/{Kits-DDSerkJk.js → Kits-K6mu91rm.js} +1 -1
  67. package/web/dist/assets/Laws-j5vKNwLT.js +4 -0
  68. package/web/dist/assets/{LibRows-QsUBjOF7.js → LibRows-1yTY0Kwn.js} +1 -1
  69. package/web/dist/assets/Library-BQZnFdWs.js +3 -0
  70. package/web/dist/assets/Loops-B5DgxpLm.js +2 -0
  71. package/web/dist/assets/Models-C-4Y4jvx.js +1 -0
  72. package/web/dist/assets/{OperatorHudView-Bdupodlc.js → OperatorHudView-_8NBAvkd.js} +1 -1
  73. package/web/dist/assets/Personal-Bf7zHDc6.js +2 -0
  74. package/web/dist/assets/Settings-BTrA6MXv.js +1 -0
  75. package/web/dist/assets/Tabs-BDhZImxa.js +1 -0
  76. package/web/dist/assets/controls-CREglcUF.js +1 -0
  77. package/web/dist/assets/index-9iBqq7i2.css +1 -0
  78. package/web/dist/assets/index-BiKWWv7Z.js +6 -0
  79. package/web/dist/assets/router-1EhRJy1C.js +1 -0
  80. package/web/dist/assets/useLocalStorage-54tkqXN7.js +1 -0
  81. package/web/dist/index.html +4 -2
  82. package/web/dist/assets/ActiveLoops-BWkImeYa.js +0 -1
  83. package/web/dist/assets/Activity-DJlPhk8q.js +0 -1
  84. package/web/dist/assets/ActivityDetail-Dk7UPnE_.js +0 -1
  85. package/web/dist/assets/Dashboard-CWhh_GSc.js +0 -2
  86. package/web/dist/assets/Factories-CjsIACyi.js +0 -1
  87. package/web/dist/assets/Installs-qcfOZNzF.js +0 -3
  88. package/web/dist/assets/JournalView-KrmFUC-X.js +0 -1
  89. package/web/dist/assets/Laws-DDffPs6O.js +0 -4
  90. package/web/dist/assets/Library-DzT3Mebh.js +0 -3
  91. package/web/dist/assets/Loops-CjsX3brz.js +0 -2
  92. package/web/dist/assets/Models-DPrAv3FG.js +0 -1
  93. package/web/dist/assets/Personal-D-dpCUU5.js +0 -2
  94. package/web/dist/assets/Settings-Dz33_Sys.js +0 -1
  95. package/web/dist/assets/Tabs-qY40S34V.js +0 -1
  96. package/web/dist/assets/controls-CK7qHA8H.js +0 -1
  97. package/web/dist/assets/index-BhT94v2q.js +0 -6
  98. package/web/dist/assets/index-DcusoHzF.css +0 -1
  99. package/web/dist/assets/usePoll-D5c_qIFZ.js +0 -1
@@ -7,16 +7,17 @@
7
7
  */
8
8
  import path from 'node:path';
9
9
  import { VERSION_MARKER } from '../hosts/hosts.mjs';
10
- import { claimer, loadAgentOverrides, loadTierMap, writeNativeLayer } from '../hosts/native.mjs';
10
+ import { claimer, learnModel, loadAgentOverrides, loadTierMap, writeNativeLayer } from '../hosts/native.mjs';
11
11
  import { ensureAgentOverridesStub, writeAliasCommands } from '../hosts/opencode.mjs';
12
12
  import {
13
- managedBlockRemove, managedBlockWrite, mergeClaudeSettings,
13
+ CLAUDE_ENV, managedBlockRemove, managedBlockWrite, mergeClaudeSettings,
14
14
  unwireClaudeEnv, unwireClaudeExcludes, unwireClaudeListing, unwireClaudeSettings, wireClaudeEnv,
15
15
  wireClaudeExcludes, wireClaudeListing,
16
16
  } from '../hosts/settings.mjs';
17
17
  import { CONTEXT_WINDOWS } from './source.mjs';
18
18
  import { get, isDict, isTruthy } from '../lib/json.mjs';
19
19
  import { relPosix } from '../lib/text.mjs';
20
+ import { claudeCfg, claudeReadManifest, installTargets } from '../hosts/installs.mjs';
20
21
  import { assertSourceComplete, phaseLog, ensureMemoryStore } from './bundle.mjs';
21
22
  import { foldOnEmit } from './fold.mjs';
22
23
  import { migrateProjectNotes } from './notes-migrate.mjs';
@@ -221,6 +222,36 @@ export function emitClaudeRender(cfg, job) {
221
222
  };
222
223
  }
223
224
 
225
+ /** Every `GENESEED_LLM` an install of a Claude-family host recorded (its manifest's `settings_env`), as a set. */
226
+ function recordedByAnyInstall() {
227
+ const found = new Set();
228
+ try {
229
+ for (const [host, scope, root] of installTargets()) {
230
+ if (host !== 'claude' && host !== 'openclaude') continue;
231
+ const cmd = claudeReadManifest(claudeCfg(root, scope, host)).managed?.settings_env?.[LEARN_ENV_KEY];
232
+ if (typeof cmd === 'string') found.add(cmd);
233
+ }
234
+ } catch { /* an unreadable machine registry: only this install's record counts */ }
235
+ return found;
236
+ }
237
+
238
+ /** The `env` key the hook's learn reads its model command from (`js/hosts/hooks-learn.mjs`). */
239
+ export const LEARN_ENV_KEY = 'GENESEED_LLM';
240
+
241
+ /**
242
+ * The command the emit writes into `env.GENESEED_LLM` for `learn` (spec 2026-11-18-learn-model-row, D4):
243
+ * `<cli> -p --model <model>`, or `<cli> -p` for `session` (the user's default model), with `<cli>` the
244
+ * host's own (`claude`, `openclaude`). null writes nothing: `off`, and Bob (`from: 'n/a'`). Pure.
245
+ * The lean flags are NOT here: learn appends them at run time, to a command whose first word is the CLI.
246
+ */
247
+ export function learnEnvCommand(learn, host, map = {}, env = {}) {
248
+ const cli = host === 'openclaude' ? 'openclaude' : host === 'claude' ? 'claude' : null;
249
+ const { model, from } = learnModel(learn, map, env, host);
250
+ if (!cli || from === 'off' || from === 'n/a') return null;
251
+ // `GENESEED_LLM` is split on whitespace: a model name holding one cannot ride in it.
252
+ return model && !/\s/.test(model) ?`${cli} -p --model ${model}` : `${cli} -p`;
253
+ }
254
+
224
255
  /**
225
256
  * `_build_global._claude_wire_py` — the files the Claude-shaped emits do NOT own: the
226
257
  * CLAUDE.md/AGENTS.md managed block and settings(.local).json.
@@ -312,10 +343,34 @@ function claudeWire(job, claudeMdText, hasAgentText, doctrines = null, excludeRu
312
343
  managed.settings_hooks = managedHooks;
313
344
  // The subagent depth cap, Claude Code only (`CLAUDE_ENV` says why). The record is what this
314
345
  // install wrote, prior plus new, so uninstall never takes a key the user set themselves.
315
- if (host === 'claude') {
346
+ if (host === 'claude' || host === 'openclaude') {
347
+ // Claude only for the depth cap; both hosts for the learn model (`learnEnvCommand`). The record is
348
+ // what Geneseed owns on file after the merge (`wireClaudeEnv`'s replace-if-ours form), so the model
349
+ // can change on a rebuild and a value the user set never lands in it.
316
350
  const priorEnv = oldSf === settingsName && isDict(get(old, 'settings_env')) ? old.settings_env : {};
317
- const env = { ...priorEnv, ...wireClaudeEnv(settingsPath) };
351
+ /** @type {Record<string, string>} */
352
+ const want = host === 'claude' ? { ...CLAUDE_ENV } : {};
353
+ const llm = learnEnvCommand(gates.learn, host, loadTierMap(cfgDir, () => {}), process.env);
354
+ // A shell that names a command of its own is the user's (D5): the settings `env` would override it in a
355
+ // session, so Geneseed stops managing the key, and removes its own value if it is still on file. A shell
356
+ // that holds a value some build recorded is only a session that inherited ours (the session's settings `env`
357
+ // reached it), and ours stays ours: a rebuild run from inside a session (the console, an agent, `rebuild-all`)
358
+ // must not give the key up, and a session of install A holds A's value while a rebuild reaches install B. The
359
+ // same for an install that has a record while the process runs inside Claude Code (`CLAUDECODE`, set by the app
360
+ // in every session: seen in a real session's environment), whatever the inherited value was.
361
+ const shellLlm = process.env.GENESEED_LLM;
362
+ const recordedLlm = Object.hasOwn(priorEnv, LEARN_ENV_KEY) ? priorEnv[LEARN_ENV_KEY] : null;
363
+ const shellIsUsers = Boolean(shellLlm) && shellLlm !== recordedLlm && !recordedByAnyInstall().has(shellLlm)
364
+ && !(recordedLlm !== null && process.env.CLAUDECODE);
365
+ if (llm && !shellIsUsers) want[LEARN_ENV_KEY] = llm;
366
+ if (shellIsUsers && recordedLlm !== null) {
367
+ process.stderr.write(`[geneseed] $GENESEED_LLM is set in your shell (${JSON.stringify(shellLlm)}): Geneseed stops managing `
368
+ + `env.GENESEED_LLM in ${settingsName} and removes its own value (${JSON.stringify(recordedLlm)}) if it is still there.\n`);
369
+ }
370
+ const env = wireClaudeEnv(settingsPath, want, priorEnv);
318
371
  if (Object.keys(env).length) managed.settings_env = env;
372
+ }
373
+ if (host === 'claude') {
319
374
  // The skill-listing budget of `--context-window` (`CONTEXT_WINDOWS` says why and why Claude
320
375
  // Code only). The record is what this install owns on file, so a value can change on a rebuild.
321
376
  const priorListing = oldSf === settingsName && isDict(get(old, 'settings_listing')) ? old.settings_listing : {};
package/js/build/fold.mjs CHANGED
@@ -27,8 +27,8 @@ import path from 'node:path';
27
27
  import { EXCLUDES_FILE, isCanonical } from '../hosts/hosts.mjs';
28
28
  import { LINE_BREAK, listDir, splitLines } from '../hosts/hooks-prims.mjs';
29
29
  import {
30
- archiveStore, consolidateMemory, draftChoiceHead, draftRuleHead, existingSlugs, indexNotes, MEMORY_SEED, parseRules,
31
- readFoldState,
30
+ archiveStore, consolidateMemory, draftChoiceHead, draftItem, draftRuleHead, existingSlugs, indexNotes, itemKey,
31
+ MEMORY_SEED, parseRules, readFoldState,
32
32
  } from '../hosts/memory-files.mjs';
33
33
  import { foldExcludes } from '../inspect/excludes.mjs';
34
34
  import { recordOwnWrites } from '../hosts/store-watch.mjs';
@@ -49,7 +49,6 @@ export const isWholeFileSeed = (bytes) => WHOLE_FILE_SEEDS.has(seedHash(bytes));
49
49
 
50
50
  /** A folded store keeps these: the re-seed restores them, and their text never says "not folded". */
51
51
  const STORE_KEEPS = ['README.md', '.gitignore', '.own-writes.json'];
52
- const DRAFT_HEAD = '# User rules — draft\n\nNot active. The rule Rite or the console applies decisions.\n';
53
52
 
54
53
  /**
55
54
  * Claim `dest` with the finished bytes, or throw EEXIST: a rename would replace a file another
@@ -297,23 +296,7 @@ function foldNotes(cfgDir, ctx) {
297
296
  }
298
297
  }
299
298
 
300
- export const itemKey = (kind, host, bytes) => createHash('sha256').update(`${kind}\0${host}\0`).update(bytes).digest('hex');
301
-
302
- /**
303
- * A block in the draft and a C7 record. The key names the host too, so two hosts holding the same
304
- * text are two decisions. Draft first: a stop between the writes leaves a block the next run
305
- * recognises, not a lost one.
306
- */
307
- function draftItem(kind, key, block, tally, { host, shared, dryRun, report }) {
308
- const state = readFoldState(shared);
309
- if (state.items[key]) return;
310
- report[tally] += 1;
311
- if (dryRun) return;
312
- const text = existsSync(shared.draft) ? readText(shared.draft) : DRAFT_HEAD;
313
- if (!text.includes(`sha256: ${key}`)) writeTextAtomic(shared.draft, `${text}\n${block}`);
314
- state.items[key] = { kind, host, state: 'pending' };
315
- writeTextAtomic(shared.foldState, `${jsonDumpsIndent(state)}\n`);
316
- }
299
+ export { itemKey };
317
300
 
318
301
  /** A pointer in the draft, never a copy (C9): each host's differing file gets its own decision. */
319
302
  function draftChoice(kind, hostFile, sharedFile, bytes, ctx) {
@@ -35,7 +35,7 @@ import path from 'node:path';
35
35
  import { main as driverMain } from './driver.mjs';
36
36
  import { GATE_SWITCHES, makeCfg } from './source.mjs';
37
37
  import { opencodeConfigDir, resolvePath } from '../hosts/hosts.mjs';
38
- import { installState, installTargets } from '../hosts/installs.mjs';
38
+ import { claudeCfg, claudeReadManifest, installState, installTargets } from '../hosts/installs.mjs';
39
39
  import { installProfile } from './profile.mjs';
40
40
  import { colorThemeFiles, colorThemeJson, PALETTE_ROLES } from '../hosts/opencode.mjs';
41
41
  import { renderAll } from './render.mjs';
@@ -92,7 +92,7 @@ const BUILD_FORWARD = [
92
92
  ['theme', '--theme'], ['emit', '--emit'], ['footprint', '--footprint'],
93
93
  ['posture', '--posture'], ['mode', '--mode'], ['trust', '--trust'], ['doctrines', '--doctrines'],
94
94
  ['excludeRules', '--exclude-rules'], ['excludeSkills', '--exclude-skills'], ['kits', '--kits'], ['sharedTier', '--shared-tier'],
95
- ['contextWindow', '--context-window'], ['tiers', '--tiers'], ['out', '--out'], ['root', '--root'],
95
+ ['contextWindow', '--context-window'], ['tiers', '--tiers'], ['learn', '--learn'], ['out', '--out'], ['root', '--root'],
96
96
  ['configDir', '--config-dir'],
97
97
  ];
98
98
 
@@ -160,6 +160,10 @@ export function rebuildAll() {
160
160
  return 0;
161
161
  }
162
162
  const failures = [];
163
+ // D10: which Claude-family installs hold no learn command now, so the ones that start learning are said once.
164
+ const learnCmd = ([host, scope, root]) => (host === 'claude' || host === 'openclaude'
165
+ ? claudeReadManifest(claudeCfg(root, scope, host)).managed?.settings_env?.GENESEED_LLM ?? null : null);
166
+ const before = new Map(targets.map((t) => [t, learnCmd(t)]));
163
167
  for (const [host, scope, root] of targets) {
164
168
  const label = `${host}:${scope} (${root})`;
165
169
  // The one replay that speaks when an excluded skill's name got older: status and the console
@@ -185,6 +189,11 @@ export function rebuildAll() {
185
189
  + `${failures.join(', ')}\n`);
186
190
  return 1;
187
191
  }
192
+ const started = targets.filter((t) => before.get(t) === null && learnCmd(t) !== null).map(([h, sc]) => `${h}:${sc}`);
193
+ if (started.length) {
194
+ printOut(`[rebuild-all] memory learning now runs on ${started.join(', ')} (the --learn setting, default light); `
195
+ + 'rebuild with --learn off to stop it.\n');
196
+ }
188
197
  printOut(`[rebuild-all] rebuilt ${targets.length} install(s).\n`);
189
198
  return 0;
190
199
  }
@@ -11,14 +11,14 @@
11
11
  import { existsSync } from 'node:fs';
12
12
  import path from 'node:path';
13
13
 
14
- import { DEFAULT_CONTEXT_WINDOW, DEFAULT_TIERS, GATE_SWITCHES, PACK_ORDER, loadKits } from './source.mjs';
14
+ import { DEFAULT_CONTEXT_WINDOW, DEFAULT_LEARN, DEFAULT_TIERS, GATE_SWITCHES, PACK_ORDER, loadKits } from './source.mjs';
15
15
  import { migrateSuperpowersKit } from '../maintain/kit-migration.mjs';
16
16
  import { DEFAULT_PRESET } from '../loop/score.mjs';
17
17
  import { CLAUDE_STYLE, GLOBAL_MANIFEST, HOSTS } from '../hosts/hosts.mjs';
18
18
  import {
19
19
  EMIT_FOR, EMIT_HOST_SCOPE, contextWindowOfDir, defaultMode, defaultPosture, defaultTheme, doctrinesForBuild,
20
20
  emitHostScopeOf, excludedRulesOfDir, excludedSkillsOfDir, footprintOfDir, kitAwareOfDir, kitsOfDir, sharedTierOfDir,
21
- gatesOfDir, installState, modeOfDir, postureOfDir, readMaybe, themeOfDir, tiersOfDir, trustOfDir,
21
+ gatesOfDir, installState, learnOfDir, modeOfDir, postureOfDir, readMaybe, themeOfDir, tiersOfDir, trustOfDir,
22
22
  } from '../hosts/installs.mjs';
23
23
 
24
24
  /**
@@ -57,7 +57,7 @@ import {
57
57
  export function setupBuildArgs(theme, emit, out = null, root = null, footprint = 'lean',
58
58
  posture = 'peer', mode = 'direct', doctrines = null, allPacks = PACK_ORDER,
59
59
  excludeRules = null, trust = DEFAULT_PRESET, excludeSkills = null, gates = {}, kits = null, sharedTier = false,
60
- contextWindow = DEFAULT_CONTEXT_WINDOW, tiers = DEFAULT_TIERS) {
60
+ contextWindow = DEFAULT_CONTEXT_WINDOW, tiers = DEFAULT_TIERS, learn = DEFAULT_LEARN) {
61
61
  const argv = ['--theme', theme, '--emit', emit];
62
62
  if (!emit.endsWith('-global')) {
63
63
  if (out) argv.push('--out', out);
@@ -101,6 +101,8 @@ export function setupBuildArgs(theme, emit, out = null, root = null, footprint =
101
101
  // The tier routing elides at its default, like the context window: only `auto` speaks, last, so
102
102
  // every argv with the routing off stays the bytes it was before the flag existed.
103
103
  if (tiers && tiers !== DEFAULT_TIERS) argv.push('--tiers', tiers);
104
+ // The learn model elides at its default (`light`) the same way: only a non-default value speaks, after the tiers.
105
+ if (learn && learn !== DEFAULT_LEARN) argv.push('--learn', learn);
104
106
  return argv;
105
107
  }
106
108
 
@@ -163,9 +165,11 @@ export function installProfile(host, scope, root, notify = null) {
163
165
  const contextWindow = contextWindowOfDir(root, host);
164
166
  // `Model tiers: auto` stays auto: a rebuild that forgot it would put every agent back on the parent's model.
165
167
  const tiers = tiersOfDir(root, host);
168
+ // `Learn model: off` stays off: a rebuild that forgot it would turn learning back on at the default.
169
+ const learn = learnOfDir(root, host);
166
170
  const out = scope === 'global' ? null : root;
167
171
  const argv = setupBuildArgs(theme, emit, out, out, footprint, posture, mode, doctrines,
168
- PACK_ORDER, excludeRules, trust, excludeSkills, gates, kits, sharedTier, contextWindow, tiers);
172
+ PACK_ORDER, excludeRules, trust, excludeSkills, gates, kits, sharedTier, contextWindow, tiers, learn);
169
173
  // A GLOBAL ROW NAMES ITS OWN DIR. `root` came from the host's config-dir resolver, which
170
174
  // honours env overrides (`OPENCODE_CONFIG_DIR`, `CLAUDE_CONFIG_DIR`…); without the flag the
171
175
  // same argv run from a shell lacking that variable re-emits into the DEFAULT dir — a second
@@ -174,7 +178,7 @@ export function installProfile(host, scope, root, notify = null) {
174
178
  return {
175
179
  host, scope, root, state: installState(root, host, scope),
176
180
  emit, theme, footprint, posture, mode, trust, doctrines, excludeRules, excludeSkills,
177
- kits, sharedTier, contextWindow, tiers, ...gates, argv,
181
+ kits, sharedTier, contextWindow, tiers, learn, ...gates, argv,
178
182
  };
179
183
  }
180
184
 
@@ -220,6 +224,7 @@ const GUARDED = [
220
224
  { name: 'context-window', given: 'contextWindow', flag: '--context-window',
221
225
  now: (a) => a.contextWindow ?? DEFAULT_CONTEXT_WINDOW, was: (p) => p.contextWindow },
222
226
  { name: 'tiers', given: 'tiers', flag: '--tiers', now: (a) => a.tiers ?? DEFAULT_TIERS, was: (p) => p.tiers },
227
+ { name: 'learn', given: 'learn', flag: '--learn', now: (a) => a.learn ?? DEFAULT_LEARN, was: (p) => p.learn },
223
228
  // A switch reads as its flag says. `--no-deletion-gate` given is `deletion-gate: off`;
224
229
  // `--strict-consent` (the one switch whose flag adds asks, so it is not `--no-*`) given is
225
230
  // `strict-consent: on`. Either way the flag given means the switch's key is `false`.
@@ -37,7 +37,7 @@ import { normcase, comparePaths } from '../lib/paths.mjs';
37
37
  import {
38
38
  CREDIT_RE, GATE_SWITCHES, PACK_ORDER, WORKFLOW_PROVIDER_HEADING, kitMembers, linkTargetOf, loadKits, readPackText, resolveCredits, resolveRuleIds, ruleCanon, titleKey, upstreamOf,
39
39
  } from './source.mjs';
40
- import { CONTEXT_WINDOW_MARKER, DEFAULT_CONTEXT_WINDOW, DEFAULT_TIERS, TIERS_MARKER, splitTier } from './source.mjs';
40
+ import { CONTEXT_WINDOW_MARKER, DEFAULT_CONTEXT_WINDOW, DEFAULT_LEARN, DEFAULT_TIERS, LEARN_MARKER, TIERS_MARKER, splitTier } from './source.mjs';
41
41
  import { SHARED_TIER_LINE } from '../hosts/hosts.mjs';
42
42
  import { PROJECT_NOTES_DIR } from '../hosts/spec-feedback.mjs';
43
43
  import { PORTABLE_MACHINE_DIR } from '../lib/machine-dir.mjs';
@@ -774,6 +774,8 @@ export function effectiveTheme(cfg, themeName, {
774
774
  ? `\n${CONTEXT_WINDOW_MARKER}: ${cfg.contextWindow}\n` : '';
775
775
  // `--tiers`, under the same contract (`tiersOfDir` reads it): a line only off the default.
776
776
  theme.TIERS_LINE = cfg.tiers && cfg.tiers !== DEFAULT_TIERS ? `\n${TIERS_MARKER}: ${cfg.tiers}\n` : '';
777
+ // `--learn`, under the same contract (`learnOfDir` reads it): a line only off the default (`light`).
778
+ theme.LEARN_LINE = cfg.learn && cfg.learn !== DEFAULT_LEARN ? `\n${LEARN_MARKER}: ${cfg.learn}\n` : '';
777
779
  // The gate switches (`GATE_SWITCHES`: Laws I, III, IV), under the same contract: a line is
778
780
  // written only when its gate is OFF, so a default build stays byte-identical and a missing
779
781
  // line reads back as armed (`gatesOfDir`). The OpenCode plugins read these lines at load, so
@@ -594,6 +594,15 @@ export const TIERS_CHOICES = Object.freeze(['auto', 'off']);
594
594
  export const DEFAULT_TIERS = 'off';
595
595
  /** The carrier marker, written only when the value is not the default (the kits line's contract). */
596
596
  export const TIERS_MARKER = 'Model tiers';
597
+ /**
598
+ * `--learn off|light|standard|session`: the model memory learning distils with (spec
599
+ * `2026-11-18-learn-model-row.md`, D1-D3, D11). `light`/`standard` name a sub-agent tier and resolve
600
+ * through `tierModel` (`learnModel`); `session` is the chat's own model; `off` distils nothing.
601
+ * The default is `light` (D2), so the marker line is written only off it, like the tiers line.
602
+ */
603
+ export const LEARN_CHOICES = Object.freeze(['off', 'light', 'standard', 'session']);
604
+ export const DEFAULT_LEARN = 'light';
605
+ export const LEARN_MARKER = 'Learn model';
597
606
  /** `{ text, tier }`: the spec without its tier line, and the tier it named (`standard` when none). */
598
607
  export function splitTier(text) {
599
608
  const m = TIER_MARKER_RE.exec(text);
@@ -768,7 +777,7 @@ export const CONTEXT_WINDOW_MARKER = 'Context window';
768
777
  export function makeCfg({
769
778
  posture = 'peer', mode = 'direct', trust = DEFAULT_PRESET, doctrines = PACK_ORDER,
770
779
  excludeRules = [], excludeSkills = [], kits = [], sharedTier = /** @type {boolean | string} */ (false),
771
- contextWindow = DEFAULT_CONTEXT_WINDOW, tiers = DEFAULT_TIERS, pruneGates = false, force = false, ...switches
780
+ contextWindow = DEFAULT_CONTEXT_WINDOW, tiers = DEFAULT_TIERS, learn = DEFAULT_LEARN, pruneGates = false, force = false, ...switches
772
781
  } = {}) {
773
782
  return {
774
783
  root: ROOT,
@@ -804,6 +813,8 @@ export function makeCfg({
804
813
  contextWindow: Object.hasOwn(CONTEXT_WINDOWS, contextWindow) ? contextWindow : DEFAULT_CONTEXT_WINDOW,
805
814
  // `--tiers auto|off`: only a literal `auto` turns the tier routing on; anything else is off.
806
815
  tiers: tiers === 'auto' ? 'auto' : DEFAULT_TIERS,
816
+ // `--learn off|light|standard|session`: anything unknown is the default.
817
+ learn: LEARN_CHOICES.includes(learn) ? learn : DEFAULT_LEARN,
807
818
  // `--force`, for this one build: only a literal `true` forces. Never an axis of the install.
808
819
  force: force === true,
809
820
  // The gate switches (`GATE_SWITCHES`: `secretsGate`, `doneGate`, `deletionGate`), each armed
@@ -5,9 +5,10 @@
5
5
  * Every stub is a literal here and an `ensure*` beside it, and the pairing is the contract:
6
6
  * the writer checks first and returns without writing when the file exists, because these are
7
7
  * the USER's files from the moment they exist. One exception: an emit also calls
8
- * `migrateMemoryIndex` on the memory store, which rewrites a FLAT MEMORY.md (and its
9
- * `topics/` files) into the two-level index once, losslessly, because a flat index overruns
10
- * the session-start budget. Fact files are never touched. A stub body is bytes a recorded
8
+ * `migrateMemoryIndex` on the memory store (an install's, and the machine tier's since D1), which
9
+ * rewrites a FLAT MEMORY.md (and its `topics/` files) into the two-level index once, losslessly,
10
+ * because a flat index overruns the session-start budget. On the tier it first drafts the standing
11
+ * rules that index loaded (D31, `ensureTierMemory`). Fact files are never touched. A stub body is bytes a recorded
11
12
  * corpus compares — changing one is a product change, not a tidy-up.
12
13
  */
13
14
  import path from 'node:path';
@@ -16,7 +17,8 @@ import { isDir } from '../lib/fs.mjs';
16
17
  import { jsonDumpsIndent } from '../lib/json.mjs';
17
18
  import { NOTES_DIRS, WIKI_NAMES, renderedSharedRoot, sharedPaths } from '../lib/machine-dir.mjs';
18
19
  import { EXCLUDES_FILE, isCanonical } from '../hosts/hosts.mjs';
19
- import { MEMORY_SEED } from '../hosts/memory-files.mjs';
20
+ import { recordOwnWrites } from '../hosts/store-watch.mjs';
21
+ import { MEMORY_SEED, alwaysOnCandidates, draftAlwaysOn, holdsFlatFacts, migrateMemoryIndex } from '../hosts/memory-files.mjs';
20
22
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
21
23
 
22
24
  // ---------------------------------------------------------------------------
@@ -325,7 +327,7 @@ export function ensureSharedTier() {
325
327
  const tier = sharedPaths();
326
328
  mkdirSync(tier.memory, { recursive: true });
327
329
  for (const sub of NOTES_DIRS) mkdirSync(path.join(tier.notes, sub), { recursive: true });
328
- ensureMemoryIndex(tier.memory);
330
+ ensureTierMemory(tier);
329
331
  ensureRulesStub(tier.root);
330
332
  ensureProfileStub(tier.root);
331
333
  ensureWikiStub(tier.root);
@@ -338,6 +340,31 @@ export function ensureSharedTier() {
338
340
  }
339
341
  }
340
342
 
343
+ /**
344
+ * The tier's memory store, brought to the shape an install store gets (D1): the seed, then a flat
345
+ * index moved to the topic map. The tier's was only seeded, so a hand-written flat index stayed flat
346
+ * and overran the session budget (F17). The standing rules a flat index loaded at every session are
347
+ * drafted FIRST (D31): the migration erases the index they were found in, and a draft written twice
348
+ * is a no-op, so a stop between the two steps is finished by the next emit. A failure here is
349
+ * a warning and never the tier's: the files stay as they are, and the next emit retries. The writes
350
+ * are logged as Geneseed's own, as the fold's are, so an open session's change report does not name
351
+ * the index and the draft this emit rewrote as changes nobody approved.
352
+ */
353
+ function ensureTierMemory(tier) {
354
+ try {
355
+ // Logged only when there is something to migrate: a seed or a topic map writes nothing, and a
356
+ // log entry for a no-op would make a second emit differ from the first.
357
+ const migrate = () => {
358
+ draftAlwaysOn(tier, alwaysOnCandidates(tier.memory));
359
+ ensureMemoryStore(tier.memory);
360
+ };
361
+ if (holdsFlatFacts(tier.memory)) recordOwnWrites(tier.root, migrate); else migrate();
362
+ } catch (e) {
363
+ process.stderr.write(`[geneseed] WARN could not migrate the shared memory index: ${e.message}; `
364
+ + 'the next emit retries\n');
365
+ }
366
+ }
367
+
341
368
  /**
342
369
  * The root a global emit renders. Rendering and creating are two decisions: every global emit
343
370
  * renders the same path, and only a canonical one creates the tier. null, so relative paths, only
@@ -367,6 +394,16 @@ export const ensureMemoryIndex = storeIndexWriter('MEMORY.md', MEMORY_INDEX);
367
394
  /** `_build_render.ensure_notebook_index`. */
368
395
  export const ensureNotebookIndex = storeIndexWriter('NOTEBOOK.md', NOTEBOOK_INDEX);
369
396
 
397
+ /**
398
+ * Seed the memory index, then move a flat one to topics — the pair every emit runs on its memory
399
+ * store, in that order, on an install's and on the tier's alike. Here, beside the seed it calls:
400
+ * `bundle.mjs` re-exports it for the emitters, and `memory-files.mjs` cannot import this file.
401
+ */
402
+ export function ensureMemoryStore(memDir) {
403
+ ensureMemoryIndex(memDir);
404
+ migrateMemoryIndex(memDir);
405
+ }
406
+
370
407
  /**
371
408
  * The seeds of the files the session-start injection reads (`SESSION_FILES` in
372
409
  * `js/hosts/hooks.mjs`, and its twin in the OpenCode context plugin). Both carry the SHA-256
package/js/cli-table.json CHANGED
@@ -265,6 +265,21 @@
265
265
  "type": null,
266
266
  "hidden": false
267
267
  },
268
+ {
269
+ "names": [
270
+ "--learn"
271
+ ],
272
+ "dest": "learn",
273
+ "metavar": null,
274
+ "help": "the model memory learning distils with: off|light|standard|session (default: light). light and standard use the sub-agent tier of that name (a Claude Code install: haiku or sonnet; elsewhere only a model the tiers map names, else the session model); session uses the chat's own model; off distils nothing. Recorded per install and kept by rebuild-all; it takes effect on hosts in later changes",
275
+ "choices": null,
276
+ "default": null,
277
+ "required": false,
278
+ "nargs": null,
279
+ "is_flag": false,
280
+ "type": null,
281
+ "hidden": false
282
+ },
268
283
  {
269
284
  "names": [
270
285
  "--out"
@@ -1218,6 +1233,28 @@
1218
1233
  ],
1219
1234
  "mutex": []
1220
1235
  },
1236
+ {
1237
+ "name": "learn-worker",
1238
+ "help": "the detached distil: run the job file a PreCompact/SessionEnd `learn` hook wrote (<machine dir>/cache/learn-jobs/job-*.json, nowhere else), with the model command from this process's own $GENESEED_LLM and a store of the machine tier or an install, then delete it. Started by `learn`, never wired in settings; prints nothing and always exits 0",
1239
+ "description": "",
1240
+ "positionals": [
1241
+ {
1242
+ "names": [],
1243
+ "dest": "file",
1244
+ "metavar": null,
1245
+ "help": "the job file `learn` wrote",
1246
+ "choices": null,
1247
+ "default": null,
1248
+ "required": false,
1249
+ "nargs": "?",
1250
+ "is_flag": false,
1251
+ "type": null,
1252
+ "hidden": false
1253
+ }
1254
+ ],
1255
+ "options": [],
1256
+ "mutex": []
1257
+ },
1221
1258
  {
1222
1259
  "name": "link",
1223
1260
  "help": "put `geneseed` on PATH so it runs from any directory",
@@ -178,22 +178,23 @@ export { SESSION_FILES, SEED_SHA256 };
178
178
 
179
179
  // A topic line of the memory map (`js/hosts/memory-files.mjs` writes it) and its fact count.
180
180
  const MAP_COUNT_RE = /^- \[([^\]]*)\]\(topics\/[^)]+\.md\) — (\d+) facts?$/;
181
- // Past this many facts a topic file stops being a quick read, and the curator splits it.
182
- const CURATE_TOPIC_MAX = 40;
183
- const CURATE_NUDGE = `[memory] A topic holds over ${CURATE_TOPIC_MAX} facts, or facts sit in misc: offer the user `
184
- + 'to dispatch the memory-curator agent to merge, re-topic and archive this store.';
185
- export { CURATE_TOPIC_MAX, CURATE_NUDGE };
181
+ const CURATE_NUDGE = '[memory] Facts sit in misc: offer the user to dispatch the memory-curator agent '
182
+ + 'to re-topic and archive them.';
183
+ export { CURATE_NUDGE };
186
184
 
187
185
  /**
188
186
  * The one-line curation nudge for a memory map, or ''. Read off the map's own counts, so it
189
- * costs no extra file read on the hook path. Both triggers are ones a curation pass clears; a
190
- * store that is merely LARGE is not one, since a curated large store would be nagged forever.
187
+ * costs no extra file read on the hook path. The one trigger is a fact filed under `misc`, which a
188
+ * curation pass clears. The size of a topic no longer fires it (D23): a migrated store files by
189
+ * `type`, so a 500-fact store holds topics of about 125 facts on its first day, and a user who did
190
+ * nothing would be nagged at once; search is the way into a large topic. A store document is never
191
+ * `misc` (`isReservedStem`), so `ARCHIVE-INDEX.md` cannot raise it either.
191
192
  * The OpenCode context plugin carries the same rule (parity gated in tests/unit/claude.test.mjs).
192
193
  */
193
194
  export function memoryNudge(map) {
194
195
  for (const line of map.split('\n')) {
195
196
  const m = MAP_COUNT_RE.exec(line.trim());
196
- if (m && (m[1] === 'misc' || Number(m[2]) > CURATE_TOPIC_MAX)) return CURATE_NUDGE;
197
+ if (m && m[1] === 'misc') return CURATE_NUDGE;
197
198
  }
198
199
  return '';
199
200
  }