geneseed 6.0.2 → 6.0.3

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 (63) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/SHIPPED.md +1 -1
  3. package/adapters/opencode/plugins/geneseed-context.js +53 -10
  4. package/adapters/opencode/plugins/geneseed-learn.js +11 -4
  5. package/docs/web-ui.md +25 -0
  6. package/harness.config.json +1 -1
  7. package/js/build/bundle.mjs +2 -11
  8. package/js/build/fold.mjs +3 -20
  9. package/js/build/stubs.mjs +42 -5
  10. package/js/hosts/hooks-context.mjs +65 -9
  11. package/js/hosts/memory-files.mjs +166 -13
  12. package/js/inspect/doctor.mjs +2 -0
  13. package/js/inspect/status.mjs +4 -1
  14. package/js/maintain/memory.mjs +2 -2
  15. package/js/web/catalog.mjs +5 -3
  16. package/package.json +1 -1
  17. package/src/agents/memory-curator.md +1 -1
  18. package/src/memory/README.md +24 -5
  19. package/src/skills/rule/approve.md +3 -1
  20. package/src/skills/rule/consolidate.md +1 -1
  21. package/web/dist/assets/ActiveLoops-paFbiZyt.js +1 -0
  22. package/web/dist/assets/Activity-IAxWF2wK.js +1 -0
  23. package/web/dist/assets/ActivityDetail-CtC2DLvh.js +1 -0
  24. package/web/dist/assets/{Bonsai-Bry-kOFb.js → Bonsai-BoKo68Kw.js} +1 -1
  25. package/web/dist/assets/{CopyButton-Cnnvjgkg.js → CopyButton-C0VTiqmb.js} +1 -1
  26. package/web/dist/assets/Dashboard-CRGCp2cV.js +2 -0
  27. package/web/dist/assets/{Docs-BJ23-fIx.js → Docs-DwOwzaD6.js} +2 -2
  28. package/web/dist/assets/Factories-DxHD2T-1.js +1 -0
  29. package/web/dist/assets/{GreenhouseView-VL_ZKJUR.js → GreenhouseView-D5VOmhmR.js} +1 -1
  30. package/web/dist/assets/Installs-B5hFSUeN.js +3 -0
  31. package/web/dist/assets/JournalView-gUSGysTm.js +1 -0
  32. package/web/dist/assets/{Kits-DDSerkJk.js → Kits-DYQvykZ0.js} +1 -1
  33. package/web/dist/assets/Laws-UVk0uojS.js +4 -0
  34. package/web/dist/assets/{LibRows-QsUBjOF7.js → LibRows-CwK63kjB.js} +1 -1
  35. package/web/dist/assets/Library-DdzyrwUK.js +3 -0
  36. package/web/dist/assets/Loops-yHga7xdr.js +2 -0
  37. package/web/dist/assets/Models-DAgkQ4CE.js +1 -0
  38. package/web/dist/assets/{OperatorHudView-Bdupodlc.js → OperatorHudView-D1lQF-ZY.js} +1 -1
  39. package/web/dist/assets/Personal-DjhIfa9v.js +2 -0
  40. package/web/dist/assets/Settings-Brgec4M0.js +1 -0
  41. package/web/dist/assets/Tabs-BHjxciOL.js +1 -0
  42. package/web/dist/assets/index-BILaKHbH.js +6 -0
  43. package/web/dist/assets/index-BfyZCNu7.css +1 -0
  44. package/web/dist/assets/router-1EhRJy1C.js +1 -0
  45. package/web/dist/assets/useLocalStorage-54tkqXN7.js +1 -0
  46. package/web/dist/index.html +4 -2
  47. package/web/dist/assets/ActiveLoops-BWkImeYa.js +0 -1
  48. package/web/dist/assets/Activity-DJlPhk8q.js +0 -1
  49. package/web/dist/assets/ActivityDetail-Dk7UPnE_.js +0 -1
  50. package/web/dist/assets/Dashboard-CWhh_GSc.js +0 -2
  51. package/web/dist/assets/Factories-CjsIACyi.js +0 -1
  52. package/web/dist/assets/Installs-qcfOZNzF.js +0 -3
  53. package/web/dist/assets/JournalView-KrmFUC-X.js +0 -1
  54. package/web/dist/assets/Laws-DDffPs6O.js +0 -4
  55. package/web/dist/assets/Library-DzT3Mebh.js +0 -3
  56. package/web/dist/assets/Loops-CjsX3brz.js +0 -2
  57. package/web/dist/assets/Models-DPrAv3FG.js +0 -1
  58. package/web/dist/assets/Personal-D-dpCUU5.js +0 -2
  59. package/web/dist/assets/Settings-Dz33_Sys.js +0 -1
  60. package/web/dist/assets/Tabs-qY40S34V.js +0 -1
  61. package/web/dist/assets/index-BhT94v2q.js +0 -6
  62. package/web/dist/assets/index-DcusoHzF.css +0 -1
  63. package/web/dist/assets/usePoll-D5c_qIFZ.js +0 -1
package/CHANGELOG.md CHANGED
@@ -8,6 +8,16 @@ label. For the capability ↔ spec map, see [SHIPPED.md](SHIPPED.md).
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [6.0.3] — 2026-11-18
12
+
13
+ ### Added
14
+
15
+ - **View levels in the web console: Essentials, Standard and Power.** A new browser starts on Essentials: Overview, Library (Skills, Agents), Installs (Hosts, Doctor), Personal (Rules, Profile), Docs and Settings. Standard adds Kits, Activity, Constitution, Memory and install profiles; Power shows everything, Models, Loops, Factories, the Wiki and Setup files and the Danger zone included. Switch it in the Appearance popover or in *Settings › Machine*; the choice is this browser's alone. A hidden part keeps working: a link, a bookmark or a search result still opens it with a "This is a Power view" banner, search tags such results with their level, and the rail foot names running loops and factory runs the level hides. One table, `web/src/lib/tiers.js`, decides every level.
16
+
17
+ ### Changed
18
+
19
+ - Memory: a top-level file whose name is all capitals (`ARCHIVE-INDEX.md`, `README.md`, `MEMORY.md`) is a store document, not a fact: it leaves the index, `learn`'s list and the curation count. The next emit also moves the machine tier's flat `MEMORY.md` to the topic map, drafts the standing rules that index loaded (`user-rules.draft.md`, loaded until you decide them), and the curation nudge no longer fires on topic size.
20
+
11
21
  ## [6.0.2] — 2026-11-18
12
22
 
13
23
  ### Added
package/SHIPPED.md CHANGED
@@ -20,7 +20,7 @@ historical references, not files distributed with the repo.
20
20
  > **On version numbers.** [`harness.config.json`](harness.config.json)'s `version` is a
21
21
  > human-readable label only. The canonical identity of an installed harness is the
22
22
  > **source fingerprint** stamped in `.geneseed-version` (see `geneseed version`), not the
23
- > string. Current label: **6.0.2**.
23
+ > string. Current label: **6.0.3**.
24
24
 
25
25
  ## Capabilities
26
26
 
@@ -330,36 +330,79 @@ async function sessionFiles(dir) {
330
330
  const found = []
331
331
  if (!dir) return found
332
332
  const tier = await tierFor(dir)
333
- const entry = (rel, abs, text, label) => {
334
- const nudge = rel === "memory/MEMORY.md" ? memoryNudge(text) : ""
335
- found.push({ rel, abs, label, text: nudge ? `${text}\n${nudge}` : text })
333
+ const entry = (rel, abs, text, label, slot = "") => {
334
+ const extra = rel === "memory/MEMORY.md" ? [memoryNudge(text), slot].filter(Boolean) : []
335
+ found.push({ rel, abs, label, text: [text, ...extra].join("\n") })
336
336
  }
337
337
  for (const rel of SESSION_FILES) {
338
338
  const abs = path.join(dir, rel)
339
339
  const host = await sessionText(abs)
340
340
  const sharedAbs = tier && rel !== "notebook/NOTEBOOK.md" ? path.join(machineDir(), rel) : null
341
341
  const shared = sharedAbs ? await sessionText(sharedAbs) : null
342
- if (shared !== null && !(host !== null && rel === "PROFILE.md")) entry(rel, sharedAbs, shared, "shared")
342
+ if (shared !== null && !(host !== null && rel === "PROFILE.md")) {
343
+ entry(rel, sharedAbs, shared, "shared")
344
+ }
343
345
  if (host !== null) entry(rel, abs, host, shared === null ? "" : "host: opencode")
346
+ // The bridge slot is its own entry right after the rules, as in the hook (BRIDGE_REL there).
347
+ if (rel === "user-rules.md" && tier) {
348
+ const slot = await bridgeSlot()
349
+ if (slot) found.push({ rel: "user-rules.draft.md", abs: path.join(machineDir(), "user-rules.draft.md"), label: "shared", text: slot })
350
+ }
344
351
  }
345
352
  return found
346
353
  }
347
354
 
348
- // The memory map's curation nudge: same rule, threshold and text as memoryNudge in
355
+ // The memory map's curation nudge: same rule and text as memoryNudge in
349
356
  // js/hosts/hooks-context.mjs (tests/unit/claude.test.mjs gates the copy). Read off the map's
350
- // own counts; a large but curated store is never nagged.
357
+ // own counts; only a fact filed under misc fires it, never the size of a topic (D23).
351
358
  const MAP_COUNT_RE = /^- \[([^\]]*)\]\(topics\/[^)]+\.md\) — (\d+) facts?$/
352
- const CURATE_TOPIC_MAX = 40
353
- const CURATE_NUDGE = "[memory] A topic holds over 40 facts, or facts sit in misc: offer the user "
354
- + "to dispatch the memory-curator agent to merge, re-topic and archive this store."
359
+ const CURATE_NUDGE = "[memory] Facts sit in misc: offer the user to dispatch the memory-curator agent "
360
+ + "to re-topic and archive them."
355
361
  function memoryNudge(map) {
356
362
  for (const line of map.split("\n")) {
357
363
  const m = MAP_COUNT_RE.exec(line.trim())
358
- if (m && (m[1] === "misc" || Number(m[2]) > CURATE_TOPIC_MAX)) return CURATE_NUDGE
364
+ if (m && m[1] === "misc") return CURATE_NUDGE
359
365
  }
360
366
  return ""
361
367
  }
362
368
 
369
+ // The bridge slot (D31), a hand twin of bridgeSlot in js/hosts/hooks-context.mjs (same constants,
370
+ // same text; tests/unit/claude.test.mjs holds the two equal on one store): the facts a migration
371
+ // drafted as standing rules keep loading, as an entry of their own after user-rules.md, until their draft is decided.
372
+ const BRIDGE_CAP = 1800
373
+ const BRIDGE_FACT_MAX = 300
374
+ const BRIDGE_HEAD = "[memory] Standing rules from your old index, drafted in user-rules.draft.md and "
375
+ + "loaded until you decide them:"
376
+ const BRIDGE_SLUG_RE = /^[^/\\.\u0000-\u001f][^/\\\u0000-\u001f]*$/
377
+ async function bridgeSlot() {
378
+ let items
379
+ try { ({ items } = JSON.parse(await fs.readFile(path.join(machineDir(), ".fold-state.json"), "utf8"))) } catch { return "" }
380
+ // The hook counts a line as its characters plus a terminator of two (+1 per inner break).
381
+ const cost = (s) => s.length + (s.match(/\n/g) || []).length + 2
382
+ const lines = []
383
+ for (const row of Object.values(items ?? {})) {
384
+ if (row?.state !== "pending" || row.host !== "memory" || typeof row.fact !== "string" || !BRIDGE_SLUG_RE.test(row.fact)) continue
385
+ let text
386
+ try { text = (await fs.readFile(path.join(machineDir(), "memory", `${row.fact}.md`), "utf8")).replace(/\r\n/g, "\n") } catch { continue }
387
+ const m = /^\s*---\s*\n([\s\S]*?)\n---\s*\n?([\s\S]*)$/.exec(text)
388
+ const desc = m ? (m[1].split("\n").map((l) => /^\s*description\s*:(.*)$/.exec(l)).find(Boolean)?.[1] ?? "").trim().replace(/^"+|"+$/g, "") : ""
389
+ const rule = ((m ? m[2] : text).trim() || desc).replace(/\s+/g, " ")
390
+ lines.push(`- ${row.fact}: ${rule.length > BRIDGE_FACT_MAX ? `${rule.slice(0, BRIDGE_FACT_MAX)}…` : rule}`)
391
+ }
392
+ if (!lines.length) return ""
393
+ const tail = (n) => `- … ${n} more drafted rule${n === 1 ? "" : "s"} not shown (read them in memory/)`
394
+ const room = BRIDGE_CAP - cost(BRIDGE_HEAD)
395
+ const kept = []
396
+ let used = 0
397
+ for (const [i, l] of lines.entries()) {
398
+ const t = tail(lines.length - i)
399
+ if (used + cost(l) + (i < lines.length - 1 ? cost(t) : 0) > room) { kept.push(t); break }
400
+ kept.push(l)
401
+ used += cost(l)
402
+ }
403
+ return [BRIDGE_HEAD, ...kept].join("\n")
404
+ }
405
+
363
406
  async function readJson(p) {
364
407
  try { return JSON.parse(await fs.readFile(p, "utf8")) } catch { return null }
365
408
  }
@@ -900,9 +900,11 @@ function envModel() {
900
900
  // Stems that name the store's own files, never a fact: `MEMORY` is the index, so a model
901
901
  // that emitted `name: MEMORY` would overwrite it.
902
902
  const RESERVED_STEMS = new Set(["memory", "readme"])
903
+ // A twin of isReservedStem in js/hosts/memory-files.mjs (D2): a stem written wholly in capitals is a store document too.
904
+ const isReservedStem = (stem) => RESERVED_STEMS.has(stem.toLowerCase()) || (stem === stem.toUpperCase() && stem !== stem.toLowerCase())
903
905
 
904
906
  async function existingSlugs(memDir) {
905
- return new Set((await listMd(memDir)).map((f) => f.slice(0, -3)).filter((s) => !RESERVED_STEMS.has(s.toLowerCase())))
907
+ return new Set((await listMd(memDir)).map((f) => f.slice(0, -3)).filter((s) => !isReservedStem(s)))
906
908
  }
907
909
 
908
910
  // The stored facts' lines are capped at MAX_STORED_CHARS, a twin of buildLearnPrompt in
@@ -988,7 +990,7 @@ async function writeMemories(output, memDir, existing) {
988
990
  const name = (fm.name || "").trim()
989
991
  const key = name.toLowerCase()
990
992
  const action = (fm.action || "").trim().toLowerCase() || "create"
991
- if (!MEMORY_SLUG_RE.test(name) || RESERVED_STEMS.has(key) || done.has(key)) continue
993
+ if (!MEMORY_SLUG_RE.test(name) || isReservedStem(name) || done.has(key)) continue
992
994
  const slug = stored.get(key)
993
995
  if (slug && action !== "create" && (await hasForce(memDir, slug))) continue
994
996
  const body = stripAction(chunk).replace(/\n+$/, "") + "\n"
@@ -1053,7 +1055,7 @@ async function readFacts(memDir) {
1053
1055
  const facts = new Map()
1054
1056
  for (const f of await listMd(memDir)) {
1055
1057
  const slug = f.slice(0, -3)
1056
- if (RESERVED_STEMS.has(slug.toLowerCase())) continue
1058
+ if (isReservedStem(slug)) continue
1057
1059
  let fm
1058
1060
  try { fm = parseFrontmatter((await fs.readFile(path.join(memDir, f), "utf8")).replace(/\r\n/g, "\n")) } catch { continue }
1059
1061
  facts.set(slug, { desc: (fm.description || "").trim(), topic: topicOf(fm) })
@@ -1072,7 +1074,9 @@ async function rebuildIndex(memDir, fresh = new Set()) {
1072
1074
  }
1073
1075
  }
1074
1076
  const byTopic = new Map()
1077
+ const known = new Set()
1075
1078
  for (const [slug, { desc, topic }] of await readFacts(memDir)) {
1079
+ known.add(slug.toLowerCase())
1076
1080
  const o = fresh.has(slug) ? null : old.get(slug)
1077
1081
  const line = o ? `- [${o.title}](../${slug}.md)${o.rest}` : `- [${slug}](../${slug}.md)` + (desc ? ` — ${desc}` : "")
1078
1082
  if (!byTopic.has(topic)) byTopic.set(topic, [])
@@ -1090,9 +1094,12 @@ async function rebuildIndex(memDir, fresh = new Set()) {
1090
1094
  mapLines.push(`- [${topic}](topics/${topic}.md) — ${lines.length} fact${lines.length === 1 ? "" : "s"}`)
1091
1095
  }
1092
1096
  const index = path.join(memDir, "MEMORY.md")
1097
+ // A flat pointer is dropped unless it names a store document (D4): a fact's has moved into its topic file.
1098
+ const documents = new Set((await listMd(memDir)).map((f) => f.slice(0, -3).toLowerCase()).filter((s) => !known.has(s)))
1093
1099
  const carried = ((await readLines(index)) ?? []).filter((l) => {
1094
1100
  const t = l.trim()
1095
- return t && t !== MEMORY_SEED.trim() && t !== MAP_HINT && !MAP_LINE_RE.test(t) && !FACT_LINE_RE.test(t)
1101
+ const flat = FACT_LINE_RE.exec(t)
1102
+ return t && t !== MEMORY_SEED.trim() && t !== MAP_HINT && !MAP_LINE_RE.test(t) && !(flat && !documents.has(flat[2].toLowerCase()))
1096
1103
  })
1097
1104
  const body = [...(mapLines.length ? ["", MAP_HINT, "", ...mapLines] : []), ...(carried.length ? ["", ...carried] : [])]
1098
1105
  await writeIfChanged(index, body.length ? MEMORY_SEED + body.join("\n") + "\n" : MEMORY_SEED)
package/docs/web-ui.md CHANGED
@@ -223,6 +223,31 @@ output**. **Full log** shows the raw output unchanged, for the picked run only.
223
223
  `web/src/lib/runPhases.js`, and the prefixes it knows are listed at its top. On a narrow
224
224
  screen the run list stacks above the detail.
225
225
 
226
+ ## View levels
227
+
228
+ The console shows three view levels. A level shows every part at or below its own, so each level holds the one before it.
229
+
230
+ - **Essentials** — the default. The pages most readers need to see and fix their harness.
231
+ - **Standard** — adds the pages and tabs for kits, activity, laws, memory and profiles.
232
+ - **Power** — adds everything else. That is models, loops, factories, the notebook, local edits, the wiki, setup files and the danger zone.
233
+
234
+ | Part | Level |
235
+ | --- | --- |
236
+ | Pages: Overview, Library, Installs, Personal, Docs, Settings | Essentials |
237
+ | Tabs: Personal / Rules and Profile; Installs / Hosts and Doctor | Essentials |
238
+ | Library sections: Skills and Agents | Essentials |
239
+ | Settings sections: Machine, Server and About | Essentials |
240
+ | Pages: Kits, Activity, Constitution | Standard |
241
+ | Tabs: Personal / Memory; Installs / Profiles | Standard |
242
+ | Pages: Models, Loops, Factories | Power |
243
+ | Tabs: Loops (all three); Factories (both); Personal / Notebook; Installs / Local edits | Power |
244
+ | Library sections: Wiki and Setup files | Power |
245
+ | Settings section: Danger zone | Power |
246
+
247
+ Change the level in the **Appearance** popover in the topbar, or in **Settings › Machine**. The choice is kept in this browser.
248
+
249
+ A hidden part is not off. It keeps working, and a link, a bookmark or a search result still opens it. A page above your level opens with a banner that names the level it needs. The search results mark such a page with that level. The foot of the rail names a running loop or factory that your level hides. This way you do not lose track of it. The Overview "New here?" card also says which view is on, until you choose Power.
250
+
226
251
  ## Views
227
252
 
228
253
  ### Dashboard
@@ -2,5 +2,5 @@
2
2
  "_comment": "version is a human-readable release label only; the canonical identity of an installed harness is the source fingerprint stamped in .geneseed-version (see `harness version`), not this string.",
3
3
  "theme": "neutral",
4
4
  "product": "Geneseed",
5
- "version": "6.0.2"
5
+ "version": "6.0.3"
6
6
  }
@@ -13,13 +13,12 @@
13
13
  import path from 'node:path';
14
14
  import { VERSION_MARKER } from '../hosts/hosts.mjs';
15
15
  import { BUNDLE_FILES_KEY, bundleFiles, ownedWithin } from '../hosts/owned.mjs';
16
- import { migrateMemoryIndex } from '../hosts/memory-files.mjs';
17
16
  import { copyFile, isFile, readText, writeText } from '../lib/fs.mjs';
18
17
  import { jsonDumpsIndent, parseJson, formatReprAscii, isTruthy } from '../lib/json.mjs';
19
18
  import { OWNED_SRC_DIRS, SRC_DIRS_MARKER, TMPL_SPEC_RE } from './emit-common.mjs';
20
19
  import { SRC_DIR_TOKENS, renderAll } from './render.mjs';
21
20
  import {
22
- ensureBundleGitignore, ensureContextStub, ensureMemoryIndex, ensureNotebookIndex,
21
+ ensureBundleGitignore, ensureContextStub, ensureMemoryStore, ensureNotebookIndex,
23
22
  ensureProfileStub, ensureRulesStub, ensureWikiStub,
24
23
  } from './stubs.mjs';
25
24
  import { retiredSkillNames, skillLabels } from './retired-skills.mjs';
@@ -29,15 +28,7 @@ import {
29
28
  existsSync, mkdirSync, readdirSync, renameSync, rmdirSync, unlinkSync,
30
29
  } from 'node:fs';
31
30
 
32
- /**
33
- * Seed the memory index, then move a flat one to topics — the pair every emit runs on its
34
- * memory store, in that order. Here and not in `js/hosts/memory-files.mjs`: `stubs.mjs`
35
- * imports that module, so the reverse import would be a cycle.
36
- */
37
- export function ensureMemoryStore(memDir) {
38
- ensureMemoryIndex(memDir);
39
- migrateMemoryIndex(memDir);
40
- }
31
+ export { ensureMemoryStore };
41
32
 
42
33
  // ---------------------------------------------------------------------------
43
34
  // Source completeness
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) {
@@ -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
@@ -16,6 +16,7 @@ import {
16
16
  } from './hosts.mjs';
17
17
  import { isFile, isDir, sortPaths, listDir } from './hooks-prims.mjs';
18
18
  import { gitRootOf } from './gitref.mjs';
19
+ import { frontmatter } from './memory-files.mjs';
19
20
  import { doneLine } from './done-checks.mjs';
20
21
  import { ownershipLine } from './ownership-gate.mjs';
21
22
 
@@ -178,26 +179,77 @@ export { SESSION_FILES, SEED_SHA256 };
178
179
 
179
180
  // A topic line of the memory map (`js/hosts/memory-files.mjs` writes it) and its fact count.
180
181
  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 };
182
+ const CURATE_NUDGE = '[memory] Facts sit in misc: offer the user to dispatch the memory-curator agent '
183
+ + 'to re-topic and archive them.';
184
+ export { CURATE_NUDGE };
186
185
 
187
186
  /**
188
187
  * 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.
188
+ * costs no extra file read on the hook path. The one trigger is a fact filed under `misc`, which a
189
+ * curation pass clears. The size of a topic no longer fires it (D23): a migrated store files by
190
+ * `type`, so a 500-fact store holds topics of about 125 facts on its first day, and a user who did
191
+ * nothing would be nagged at once; search is the way into a large topic. A store document is never
192
+ * `misc` (`isReservedStem`), so `ARCHIVE-INDEX.md` cannot raise it either.
191
193
  * The OpenCode context plugin carries the same rule (parity gated in tests/unit/claude.test.mjs).
192
194
  */
193
195
  export function memoryNudge(map) {
194
196
  for (const line of map.split('\n')) {
195
197
  const m = MAP_COUNT_RE.exec(line.trim());
196
- if (m && (m[1] === 'misc' || Number(m[2]) > CURATE_TOPIC_MAX)) return CURATE_NUDGE;
198
+ if (m && m[1] === 'misc') return CURATE_NUDGE;
197
199
  }
198
200
  return '';
199
201
  }
200
202
 
203
+ // The bridge slot (D31): the facts a migration drafted as standing rules keep loading, in this much
204
+ // room, until their draft is decided (an entry of its own after user-rules.md: see BRIDGE_REL).
205
+ // 1 800 is about the 3 072 characters memory used to get, less what the map now takes; a fact is cut
206
+ // at BRIDGE_FACT_MAX and the rest are counted.
207
+ // The OpenCode context plugin carries the same constants (parity gated in tests/unit/claude.test.mjs).
208
+ const BRIDGE_CAP = 1800;
209
+ const BRIDGE_FACT_MAX = 300;
210
+ const BRIDGE_HEAD = '[memory] Standing rules from your old index, drafted in user-rules.draft.md and '
211
+ + 'loaded until you decide them:';
212
+ // A slug is a file name the ledger holds: data, so no path may ride in it.
213
+ const BRIDGE_SLUG_RE = /^[^/\\.\u0000-\u001f][^/\\\u0000-\u001f]*$/;
214
+
215
+ // THE SLOT IS ITS OWN SESSION ENTRY, right after `user-rules.md`, and `renderPayload` budgets it as a
216
+ // rule. As a tail of the memory map it was the first thing the budget cut, or went whole with the map
217
+ // when the rules, profile and wiki left the 4th file no room: an undecided standing rule would then
218
+ // stop loading silently, which is what the bridge exists to prevent. As a rule it answers only to the
219
+ // rules' own size, so the profile and the wiki cannot push it out. Its rel names the draft it comes
220
+ // from; `rel === 'user-rules.md'` consumers (a sub-agent's rules, the console) do not see it.
221
+ export const BRIDGE_REL = 'user-rules.draft.md';
222
+ function bridgeAbs() {
223
+ try { return sharedPaths().draft; } catch { return BRIDGE_REL; }
224
+ }
225
+
226
+ /**
227
+ * The slot's text for the tier's pending memory drafts, or ''. A draft the user has decided is not
228
+ * `pending` in the ledger, so it leaves on its own. A fact that is gone, or unreadable, is skipped.
229
+ * Both the ledger row and the file are the user's data, and nothing here writes either.
230
+ */
231
+ export function bridgeSlot() {
232
+ let tier;
233
+ let items;
234
+ try {
235
+ tier = sharedPaths();
236
+ ({ items } = JSON.parse(readFileSync(tier.foldState, 'utf8')));
237
+ } catch { return ''; }
238
+ const lines = [];
239
+ for (const row of Object.values(items ?? {})) {
240
+ if (row?.state !== 'pending' || row.host !== 'memory' || typeof row.fact !== 'string'
241
+ || !BRIDGE_SLUG_RE.test(row.fact)) continue;
242
+ let text;
243
+ try { text = readFileSync(path.join(tier.memory, `${row.fact}.md`), 'utf8').replace(/\r\n/g, '\n'); } catch { continue; }
244
+ const [fm, body] = frontmatter(text);
245
+ const rule = (body.trim() || (fm.get('description') ?? '')).replace(/\s+/g, ' ');
246
+ lines.push(`- ${row.fact}: ${rule.length > BRIDGE_FACT_MAX ? `${rule.slice(0, BRIDGE_FACT_MAX)}…` : rule}`);
247
+ }
248
+ if (!lines.length) return '';
249
+ const tail = (n) => `- … ${n} more drafted rule${n === 1 ? '' : 's'} not shown (read them in memory/)`;
250
+ return [BRIDGE_HEAD, ...fitLines(lines, BRIDGE_CAP - cost(BRIDGE_HEAD), tail)].join('\n');
251
+ }
252
+
201
253
  // The one context line for a project that names no runtime; the OpenCode context plugin carries
202
254
  // the same text (tests/plugins/context_done.test.mjs holds the two equal).
203
255
  const FLOOR_LINE = 'Runtime floor: package.json declares no engines — name the supported runtime before you '
@@ -451,6 +503,10 @@ export function sessionFiles(hookRoot, host = null, carrier = installCarrier(hoo
451
503
  found.push(sessionEntry(rel, sharedAbs, shared, 'shared'));
452
504
  }
453
505
  if (own !== null) found.push(sessionEntry(rel, hostAbs, own, shared === null ? '' : `host: ${host || 'claude'}`));
506
+ if (rel === 'user-rules.md' && tier && rels.includes('memory/MEMORY.md')) {
507
+ const slot = bridgeSlot();
508
+ if (slot) found.push({ rel: BRIDGE_REL, abs: bridgeAbs(), label: 'shared', text: slot });
509
+ }
454
510
  }
455
511
  return found.filter(Boolean);
456
512
  }
@@ -722,7 +778,7 @@ function renderPayload({ heads, session, eager, lazy, source, root, title = SESS
722
778
  const left = [];
723
779
  for (const s of session) {
724
780
  const head = `----- ${s.rel}${s.label ? ` (${s.label})` : ''} -----`;
725
- const rules = s.rel === 'user-rules.md';
781
+ const rules = s.rel === 'user-rules.md' || s.rel === BRIDGE_REL;
726
782
  const room = budget - LAZY_RESERVE - (rules ? rulesSpent : spent) - cost(head) - cost('');
727
783
  const where = `${s.abs} on demand`;
728
784
  if (room <= 0) {