geneseed 5.0.3 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +3 -3
  3. package/SHIPPED.md +2 -2
  4. package/adapters/claude-code/README.md +5 -1
  5. package/adapters/openclaude/README.md +3 -1
  6. package/adapters/opencode/plugins/geneseed-workflow.js +1 -1
  7. package/adapters/opencode/workflows/_runtime.js +1 -1
  8. package/bin/geneseed-cli.mjs +3 -0
  9. package/bin/geneseed-hook.mjs +10 -2
  10. package/docs/PRD.md +1 -1
  11. package/docs/README.md +4 -1
  12. package/docs/concepts/enforcement-table.md +1 -1
  13. package/docs/concepts/exclusions.md +1 -1
  14. package/docs/concepts/factories.md +203 -0
  15. package/docs/concepts/hooks.md +1 -1
  16. package/docs/concepts/host-matrix.md +1 -0
  17. package/docs/concepts/loop-gates.md +6 -0
  18. package/docs/concepts/loops.md +1 -0
  19. package/docs/concepts/rules.md +1 -1
  20. package/docs/concepts/shared-tier.md +14 -0
  21. package/docs/extending.md +5 -1
  22. package/docs/guides/autostart.md +2 -0
  23. package/docs/guides/migrate.md +1 -1
  24. package/docs/guides/run-a-factory.md +116 -0
  25. package/docs/guides/set-up-ownership.md +1 -0
  26. package/docs/guides/upgrade-to-5.md +2 -2
  27. package/docs/reference/factory-actions.md +22 -0
  28. package/docs/reference/loop-actions.md +1 -1
  29. package/docs/reference/plugin-activity.md +1 -1
  30. package/docs/web-ui.md +47 -2
  31. package/harness.config.json +1 -1
  32. package/js/README.md +21 -2
  33. package/js/build/args.mjs +44 -12
  34. package/js/build/emit-claude.mjs +3 -0
  35. package/js/build/emit-opencode.mjs +4 -0
  36. package/js/build/retired-skills.mjs +158 -0
  37. package/js/build/source.mjs +41 -2
  38. package/js/cli-table.json +193 -3
  39. package/js/factory/cli.mjs +194 -0
  40. package/js/factory/graph.mjs +309 -0
  41. package/js/factory/registry.mjs +71 -0
  42. package/js/factory/state.mjs +511 -0
  43. package/js/hosts/activity.mjs +3 -3
  44. package/js/hosts/done-checks.mjs +3 -2
  45. package/js/hosts/geneseed-dir.mjs +1 -1
  46. package/js/hosts/gitref.mjs +21 -0
  47. package/js/hosts/hooks-context.mjs +63 -9
  48. package/js/hosts/hooks-prims.mjs +1 -1
  49. package/js/hosts/memory-files.mjs +4 -2
  50. package/js/hosts/settings.mjs +5 -4
  51. package/js/inspect/checks-authoring.mjs +11 -1
  52. package/js/inspect/cost.mjs +91 -5
  53. package/js/inspect/doctor.mjs +2 -1
  54. package/js/inspect/inventory.mjs +1 -1
  55. package/js/loop/catalog.mjs +30 -12
  56. package/js/loop/cli.mjs +27 -15
  57. package/js/loop/graph.mjs +13 -4
  58. package/js/loop/registry.mjs +65 -28
  59. package/js/loop/state.mjs +18 -8
  60. package/js/maintain/migrate.mjs +39 -25
  61. package/js/web/api.mjs +43 -1
  62. package/js/web/catalog.mjs +38 -2
  63. package/js/web/daemon.mjs +191 -6
  64. package/js/web/handler.mjs +27 -5
  65. package/js/web/routes.mjs +10 -3
  66. package/js/web/server.mjs +4 -1
  67. package/package.json +1 -1
  68. package/registry.json +14 -0
  69. package/src/AGENT.md.tmpl +5 -7
  70. package/src/bricks/checks.md +62 -0
  71. package/src/bricks/docs-update.md +5 -0
  72. package/src/bricks/holdout-write.md +23 -0
  73. package/src/bricks/holdout.md +25 -0
  74. package/src/bricks/intake.md +27 -0
  75. package/src/bricks/merge-gate.md +31 -0
  76. package/src/bricks/pr-open.md +21 -0
  77. package/src/bricks/retro.md +22 -0
  78. package/src/bricks/review-panel.md +43 -0
  79. package/src/bricks/spec.md +20 -6
  80. package/src/bricks/test.md +4 -1
  81. package/src/bricks/triage.md +19 -0
  82. package/src/doctrines/comms.md +29 -41
  83. package/src/doctrines/craft.md +3 -10
  84. package/src/doctrines/ops.md +4 -15
  85. package/src/doctrines/rigor.md +1 -5
  86. package/src/factories/analysis-to-build.json +52 -0
  87. package/src/factories/bug-report-to-fix.json +50 -0
  88. package/src/factories/issue-to-pr.json +67 -0
  89. package/src/skills/_checkpoints.md +1 -0
  90. package/src/skills/adhd.md +1 -1
  91. package/src/skills/factory-forge.md +115 -0
  92. package/src/skills/factory.md +196 -0
  93. package/src/skills/loop.md +3 -2
  94. package/src/skills/parallel-agents.md +1 -1
  95. package/src/skills/workflow.md +2 -1
  96. package/themes/_TEMPLATE.json +4 -2
  97. package/themes/biker.json +4 -2
  98. package/themes/commentator.json +4 -2
  99. package/themes/cyberpunk.json +4 -2
  100. package/themes/gamer.json +4 -2
  101. package/themes/imperial.json +4 -2
  102. package/themes/joker.json +4 -2
  103. package/themes/marvin.json +4 -2
  104. package/themes/mean.json +4 -2
  105. package/themes/military.json +4 -2
  106. package/themes/neutral.json +4 -2
  107. package/themes/pirate.json +4 -2
  108. package/themes/sports.json +4 -2
  109. package/themes/verstappen.json +4 -2
  110. package/themes/wizard.json +4 -2
  111. package/web/dist/assets/ActiveLoops-BTHIaRhn.js +1 -0
  112. package/web/dist/assets/{Activity-Ck_Xffpo.js → Activity-CpkBwpu7.js} +1 -1
  113. package/web/dist/assets/{ActivityDetail-CBxVS4mU.js → ActivityDetail-DTPziZWM.js} +1 -1
  114. package/web/dist/assets/{Bonsai-BlOwsvW6.js → Bonsai-hiG_gGNU.js} +1 -1
  115. package/web/dist/assets/{CopyButton-DFMOIGbe.js → CopyButton-DUIUfNp6.js} +1 -1
  116. package/web/dist/assets/Dashboard-Dnw6EyX7.js +2 -0
  117. package/web/dist/assets/{Docs-D_2Jt6gU.js → Docs-BEET_l16.js} +2 -2
  118. package/web/dist/assets/Factories-D6KXkfWw.js +1 -0
  119. package/web/dist/assets/{GreenhouseView-WalcX5bp.js → GreenhouseView-BKxy5apE.js} +1 -1
  120. package/web/dist/assets/{Installs-UGiPDMDt.js → Installs-CnFVlVD0.js} +3 -3
  121. package/web/dist/assets/{JournalView-CZtXQz-v.js → JournalView-ChFitHjo.js} +1 -1
  122. package/web/dist/assets/{Kits-XQHsazCN.js → Kits-CcR-OlwQ.js} +1 -1
  123. package/web/dist/assets/Laws-B1s5idOg.js +4 -0
  124. package/web/dist/assets/LibRows-BZgdbI1l.js +1 -0
  125. package/web/dist/assets/Library-x6TkkEVF.js +3 -0
  126. package/web/dist/assets/Loops-BH93KKxn.js +2 -0
  127. package/web/dist/assets/{OperatorHudView-CeDw5qMB.js → OperatorHudView-BO0aIKPL.js} +1 -1
  128. package/web/dist/assets/{Personal-PVmGA2-M.js → Personal-CE_0Vhh0.js} +2 -2
  129. package/web/dist/assets/{Settings-DWuxwh4i.js → Settings-CbpZvVN_.js} +1 -1
  130. package/web/dist/assets/{Tabs-d2RIRAKT.js → Tabs-C2oW7oEj.js} +1 -1
  131. package/web/dist/assets/api-DLDVY3K-.js +1 -0
  132. package/web/dist/assets/{index-BNttaGQb.js → index-BQwOmbor.js} +3 -3
  133. package/web/dist/assets/index-CuIop_pO.css +1 -0
  134. package/web/dist/index.html +3 -3
  135. package/web/dist/assets/Dashboard-BUdUTjbB.js +0 -2
  136. package/web/dist/assets/Laws-B6A55S-2.js +0 -4
  137. package/web/dist/assets/Library-D7L0Wdbh.js +0 -3
  138. package/web/dist/assets/Loops-C0loS73u.js +0 -2
  139. package/web/dist/assets/RailCats-BGZnJ6fa.js +0 -1
  140. package/web/dist/assets/api-BMFDSXoB.js +0 -1
  141. package/web/dist/assets/index-BEI5ugYQ.css +0 -1
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * The loop registry — `<userLoopsDir()>/loops.json` — the list of worktrees `geneseed loop init`
3
3
  * has launched a loop in. `LOOP.md` stays the only source of loop STATE; this file stores
4
- * identity only (root, branch, title, started, finishedAt), so the Active tab can discover a
5
- * loop without scanning every worktree on the machine.
4
+ * identity only (root, branch, title, started, initAt, finishedAt, and `factory` for a loop that
5
+ * is a factory stage), so the Active tab can discover
6
+ * a loop without scanning every worktree on the machine.
6
7
  *
7
8
  * WRITER CONVENTIONS, mirrored from `js/inspect/registry.mjs` (`installs.json`'s own registry)
8
9
  * on purpose rather than invented fresh: `jsonDumpsIndent` because these rows are absolute
@@ -51,32 +52,39 @@ export function registryPath() {
51
52
  return path.join(userLoopsDir(), 'loops.json');
52
53
  }
53
54
 
54
- function load() {
55
+ /**
56
+ * The rows under `key` in the registry `file`, `[]` when it is missing or corrupt. Exported with
57
+ * `saveRows`, `normalize`, `sameRoot` and `sweepRows` for `js/factory/registry.mjs`: its
58
+ * `factories.json` follows every convention of this file, so the two share the code, not a copy.
59
+ */
60
+ export function loadRows(file, key) {
55
61
  try {
56
- const data = parseJson(readFileSync(registryPath(), 'utf8'));
57
- return Array.isArray(data?.loops) ? data.loops.filter((l) => l && typeof l.root === 'string') : [];
62
+ const data = parseJson(readFileSync(file, 'utf8'));
63
+ return Array.isArray(data?.[key]) ? data[key].filter((l) => l && typeof l.root === 'string') : [];
58
64
  } catch {
59
65
  return [];
60
66
  }
61
67
  }
62
68
 
63
- function save(loops) {
69
+ export function saveRows(file, key, rows) {
64
70
  try {
65
- const file = registryPath();
66
71
  mkdirSync(path.dirname(file), { recursive: true });
67
72
  const tmp = `${file}.tmp`;
68
- writeText(tmp, `${jsonDumpsIndent({ loops })}\n`);
73
+ writeText(tmp, `${jsonDumpsIndent({ [key]: rows })}\n`);
69
74
  renameWithRetry(tmp, file);
70
75
  } catch {
71
76
  /* best-effort: a registry hiccup must never fail init or a read */
72
77
  }
73
78
  }
74
79
 
75
- function normalize(dir) {
80
+ const load = () => loadRows(registryPath(), 'loops');
81
+ const save = (loops) => saveRows(registryPath(), 'loops', loops);
82
+
83
+ export function normalize(dir) {
76
84
  try { return realpathSync.native(dir); } catch { return path.resolve(dir); }
77
85
  }
78
86
 
79
- const sameRoot = (a, b) => normcase(a) === normcase(b);
87
+ export const sameRoot = (a, b) => normcase(a) === normcase(b);
80
88
 
81
89
  function runningRow(entry, state) {
82
90
  return {
@@ -89,27 +97,43 @@ function runningRow(entry, state) {
89
97
 
90
98
  /**
91
99
  * Upsert `root`'s identity row. Called by `geneseed loop init` right after `LOOP.md` is
92
- * written — `started` is set once, on insert, and never moved by a later call. An update never
100
+ * written — `started` is set once, on insert, and never moved by a later call. `initAt` is set on
101
+ * EVERY call: `init` refuses while a LOOP.md exists, so each call starts a fresh loop, and
102
+ * `initAt` is the time of the latest one (`loopInitAt`, the factory's R2 evidence). An update never
93
103
  * touches `finishedAt` either way: `activeLoops` is the only writer of that field, and it will
94
104
  * clear it on the very next poll once it sees LOOP.md present again. Never throws: an `init`
95
105
  * must succeed even when the registry itself cannot be written.
96
106
  */
97
- export function recordLoop({ root, branch, title, now = new Date() }) {
107
+ export function recordLoop({ root, branch, title, factory = null, now = new Date() }) {
98
108
  try {
99
109
  const key = normalize(root);
100
110
  const loops = load();
101
111
  const idx = loops.findIndex((l) => sameRoot(l.root, key));
102
- if (idx >= 0) {
103
- loops[idx] = { ...loops[idx], root: key, branch, title };
104
- } else {
105
- loops.push({ root: key, branch, title, started: now.toISOString() });
106
- }
112
+ const initAt = now.toISOString();
113
+ const row = idx >= 0
114
+ ? { ...loops[idx], root: key, branch, title, initAt }
115
+ : { root: key, branch, title, started: initAt, initAt };
116
+ // The factory run this loop is a stage of (`loop init --factory <slug>`). A later plain
117
+ // `loop init` in the same worktree is a stage of no run, so the field drops.
118
+ if (factory) row.factory = factory; else delete row.factory;
119
+ if (idx >= 0) loops[idx] = row; else loops.push(row);
107
120
  save(loops);
108
121
  } catch {
109
122
  /* a registry hiccup must never fail loop init */
110
123
  }
111
124
  }
112
125
 
126
+ /**
127
+ * The `initAt` of `root`'s row, or null (no row, a row from before the field, an unreadable
128
+ * registry). READ-ONLY, unlike `activeLoops`: `geneseed factory record` calls it, and a record
129
+ * must not prune or stamp rows.
130
+ */
131
+ export function loopInitAt(root) {
132
+ const key = normalize(root);
133
+ const row = load().find((l) => sameRoot(l.root, key));
134
+ return typeof row?.initAt === 'string' ? row.initAt : null;
135
+ }
136
+
113
137
  /**
114
138
  * The rows the Active tab renders, read fresh off every registered worktree's `LOOP.md` —
115
139
  * never off the registry's own stale copy of a loop's state. Four outcomes per row; the
@@ -128,19 +152,33 @@ export function recordLoop({ root, branch, title, now = new Date() }) {
128
152
  * that frozen `finishedAt`, at which point the row is dropped (and the drop is saved).
129
153
  */
130
154
  export function activeLoops({ now = new Date() } = {}) {
131
- const loops = load();
155
+ const { kept, rows, changed } = sweepRows(load(), {
156
+ stateFile: LOOP_FILE, parse: parseLoopFile, project: runningRow, now,
157
+ identity: (e) => ({ root: e.root, branch: e.branch, title: e.title, started: e.started }),
158
+ });
159
+ if (changed) save(kept);
160
+ return rows;
161
+ }
162
+
163
+ /**
164
+ * `activeLoops`' four outcomes, over any registry whose rows name a state file at their root:
165
+ * `parse` reads that file, `project(entry, state)` builds a running row, `identity(entry)` the row
166
+ * of an unreadable or finished one. Returns the rows, the entries to keep, and whether keeping
167
+ * them differs from what was loaded — the only case in which the caller saves.
168
+ */
169
+ export function sweepRows(entries, { stateFile, parse, project, identity, now }) {
132
170
  const kept = [];
133
171
  const rows = [];
134
172
  let changed = false;
135
- for (const entry of loops) {
173
+ for (const entry of entries) {
136
174
  if (!isDir(entry.root)) { changed = true; continue; }
137
- const file = path.join(entry.root, LOOP_FILE);
138
- const identity = { root: entry.root, branch: entry.branch, title: entry.title, started: entry.started };
175
+ const file = path.join(entry.root, stateFile);
176
+ const id = identity(entry);
139
177
  if (isFile(file)) {
140
178
  let state;
141
- try { state = parseLoopFile(readText(file)); } catch {
179
+ try { state = parse(readText(file)); } catch {
142
180
  kept.push(entry);
143
- rows.push({ ...identity, status: 'unreadable' });
181
+ rows.push({ ...id, status: 'unreadable' });
144
182
  continue;
145
183
  }
146
184
  let next = entry;
@@ -148,23 +186,22 @@ export function activeLoops({ now = new Date() } = {}) {
148
186
  next = { ...entry }; delete next.finishedAt; changed = true;
149
187
  }
150
188
  kept.push(next);
151
- rows.push(runningRow(next, state));
189
+ rows.push(project(next, state));
152
190
  continue;
153
191
  }
154
192
  if (entry.finishedAt === undefined) {
155
193
  const next = { ...entry, finishedAt: now.toISOString() };
156
194
  changed = true;
157
195
  kept.push(next);
158
- rows.push({ ...identity, status: 'finished' });
196
+ rows.push({ ...id, status: 'finished' });
159
197
  continue;
160
198
  }
161
199
  const age = now.getTime() - new Date(entry.finishedAt).getTime();
162
200
  if (age > SEVEN_DAYS_MS) { changed = true; continue; }
163
201
  kept.push(entry);
164
- rows.push({ ...identity, status: 'finished' });
202
+ rows.push({ ...id, status: 'finished' });
165
203
  }
166
- if (changed) save(kept);
167
- return rows;
204
+ return { kept, rows, changed };
168
205
  }
169
206
 
170
207
  /**
package/js/loop/state.mjs CHANGED
@@ -35,6 +35,12 @@
35
35
  * that window is the one case it lingers), and `LOOP_FILE_TMP` joins `LOOP_FILE` in both
36
36
  * `filterPorcelain` and `scoreDiff`'s exclusion below for exactly that case: a lingering
37
37
  * `LOOP.md.tmp` is the engine's own bookkeeping too, never scored work.
38
+ *
39
+ * `ENGINE_FILES` is that exclusion, one list for both filters, and it holds `FACTORY.md` (and its
40
+ * `.tmp`) too: a factory run keeps its own state file beside LOOP.md in the same worktree
41
+ * (`js/factory/state.mjs`), rewritten by every `geneseed factory` action, so to a child loop it is
42
+ * bookkeeping exactly as LOOP.md is: scoring it would charge every loop unit for the factory's
43
+ * transitions, and a read brick would "write" whenever the factory moved.
38
44
  */
39
45
  import { renameSync, unlinkSync } from 'node:fs';
40
46
  import { writeText } from '../lib/fs.mjs';
@@ -46,6 +52,7 @@ const END = '<!-- loop-state:end -->';
46
52
  const VERIFY_COMMAND = 'git add -A && git diff --cached --numstat | geneseed loop score --diff';
47
53
  export const LOOP_FILE = 'LOOP.md';
48
54
  const LOOP_FILE_TMP = `${LOOP_FILE}.tmp`;
55
+ export const ENGINE_FILES = new Set([LOOP_FILE, LOOP_FILE_TMP, 'FACTORY.md', 'FACTORY.md.tmp']);
49
56
  const slash = (p) => String(p).replaceAll('\\', '/');
50
57
 
51
58
  export function renderLoopFile(state) {
@@ -104,9 +111,10 @@ const fmt = (n) => Number(n).toFixed(1);
104
111
  /**
105
112
  * `contracts`: extra globs (`loop init --contracts`), appended after the graph's own. Every
106
113
  * field the engine ever writes is listed here, `gateAmends` included (`decideGate` still reads
107
- * it with `?.`, for a LOOP.md written before it was listed).
114
+ * it with `?.`, for a LOOP.md written before it was listed). `notes`: the notes the loop starts
115
+ * with, for a loop a factory re-enters after a failure (its `carry`, D16) — empty otherwise.
108
116
  */
109
- export function initState({ title, requirement, graph, preset = DEFAULT_PRESET, contracts = [] }) {
117
+ export function initState({ title, requirement, graph, preset = DEFAULT_PRESET, contracts = [], notes = [] }) {
110
118
  if (!Object.hasOwn(PRESETS, preset)) throw new Error(`unknown preset ${JSON.stringify(preset)}`);
111
119
  const loop = iterationLoop(graph);
112
120
  const state = {
@@ -115,7 +123,7 @@ export function initState({ title, requirement, graph, preset = DEFAULT_PRESET,
115
123
  iteration: loop.nodes.includes(graph.start) ? 1 : 0,
116
124
  card: null, validated: false, pendingVerify: false, closing: false, counters: {},
117
125
  resplit: false, emptyStreak: 0, snapshot: '', visited: [], tests: 'n/a', current: {},
118
- notes: [], history: [], gateAmends: {},
126
+ notes: [...notes], history: [], gateAmends: {},
119
127
  };
120
128
  if (preset === 'prudent') { state.status = 'awaiting'; state.awaiting = { kind: 'launch' }; }
121
129
  return state;
@@ -237,7 +245,7 @@ export function scoreDiff(state, files) {
237
245
  if (!Array.isArray(state.contracts) || state.contracts.some((c) => typeof c !== 'string')) {
238
246
  throw new Error('LOOP.md: contracts must be a list of file paths or globs');
239
247
  }
240
- const scored = files.filter((f) => slash(f.file) !== LOOP_FILE && slash(f.file) !== LOOP_FILE_TMP);
248
+ const scored = files.filter((f) => !ENGINE_FILES.has(slash(f.file)));
241
249
  if (!scored.length) {
242
250
  // A closing unit (reached $close with a mutate already visited) finishes as done even
243
251
  // when this is its second empty diff in a row: there is nothing left to retry into.
@@ -305,13 +313,15 @@ function repairRing(graph, from, to) {
305
313
  }
306
314
 
307
315
  // Porcelain lines are `XY <path>`; strip the 2-char status + space, slash-normalise, drop
308
- // LOOP.md rows (the engine rewrites it on every action — it is never part of the scored work)
309
- // and a lingering LOOP.md.tmp (the atomic writer's own sibling — see `writeLoopFile`'s docblock).
310
- function filterPorcelain(porcelain) {
316
+ // the `ENGINE_FILES` rows: LOOP.md (the engine rewrites it on every action — it is never part of
317
+ // the scored work), a lingering LOOP.md.tmp (the atomic writer's own sibling — see
318
+ // `writeLoopFile`'s docblock) and the factory's FACTORY.md pair. Exported: the factory engine's
319
+ // clean-tree check (J5) filters with this same list, never a copy of it.
320
+ export function filterPorcelain(porcelain) {
311
321
  const lines = porcelain.split(/\r?\n/).filter((line) => {
312
322
  if (!line) return false;
313
323
  const path = line.slice(3).replace(/^"|"$/g, '');
314
- return slash(path) !== LOOP_FILE && slash(path) !== LOOP_FILE_TMP;
324
+ return !ENGINE_FILES.has(slash(path));
315
325
  });
316
326
  return lines.join('\n').trimEnd();
317
327
  }
@@ -29,7 +29,8 @@ import path from 'node:path';
29
29
 
30
30
  import { main as driverMain } from '../build/driver.mjs';
31
31
  import { foldHost, foldSummary } from '../build/fold.mjs';
32
- import { RETIRED_SKILL_IDS, ROOT, knownSkillIds, skillAliases } from '../build/source.mjs';
32
+ import { ROOT } from '../build/source.mjs';
33
+ import { ownsRel, retiredArchiveOf, retiredSkillFolders } from '../build/retired-skills.mjs';
33
34
  import { CLAUDE_STYLE, isCanonical, settingsFile } from '../hosts/hosts.mjs';
34
35
  import {
35
36
  claudeCfg, claudeReadManifest, EMIT_HOST_SCOPE, installState, installTargets,
@@ -130,31 +131,39 @@ function foldPreview(rows) {
130
131
  }
131
132
 
132
133
  /**
133
- * M5 — files no manifest owns, so no emit will ever prune them: the root `AGENT.md` and the folder
134
- * of a skill that no longer ships under its own name. An earlier build likely wrote them, but an
135
- * alias is a plain word and a folder under it may be the user's own, so nothing claims which.
136
- * REPORTED, never moved: they go aside on the user's word.
134
+ * M5 — files no manifest owns, so no emit's ordinary prune will ever reach them: the root
135
+ * `AGENT.md` and the folder of a skill that no longer ships under its own name. The skill
136
+ * folders split the way the next canonical emit treats them (`retiredSkillFolders`,
137
+ * `js/build/retired-skills.mjs`): `prunes`, a plain Geneseed render it moves aside, and
138
+ * `orphans`, everything it leaves — `AGENT.md`, a link, a folder without the render's
139
+ * fingerprint — because an alias is a plain word and such a folder may be the user's own.
137
140
  *
138
141
  * The candidate names come from what git history already settled and the source still records —
139
- * `RETIRED_SKILL_IDS` and the `aliases:` markers — because the CLI may not spawn `git`. Each
140
- * candidate is checked before it is listed: a live skill is never an orphan (`teach` is live,
141
- * `quiz` is its alias), and a path the manifest owns is not one either — the next emit prunes it.
142
+ * `RETIRED_SKILL_IDS` and the `aliases:` markers — because the CLI may not spawn `git`. A live
143
+ * skill is never a candidate (`teach` is live, `quiz` is its alias), and a path the manifest
144
+ * owns is not one either — the ordinary prune handles it.
142
145
  */
143
- export function orphanFindings(cfg, owned, { live = knownSkillIds(), aliases = skillAliases() } = {}) {
144
- const owns = (rel) => owned.some((o) => o === rel || o.startsWith(`${rel}/`));
145
- const names = [...new Set([...aliases.keys(), ...Object.keys(RETIRED_SKILL_IDS)])].filter((n) => !live.includes(n));
146
- return ['AGENT.md', ...names.map((n) => `skills/${n}`)]
147
- .filter((rel) => !owns(rel) && existsSync(path.join(cfg, rel)))
148
- .map((rel) => path.join(cfg, rel));
146
+ export function orphanFindings(cfg, owned, opts = {}) {
147
+ return orphanSplit(cfg, owned, opts).orphans;
149
148
  }
150
149
 
151
- /** The `--dry-run` half of M5: the orphans of each global Claude-style install. */
150
+ function orphanSplit(cfg, owned, opts = {}) {
151
+ const { prune, keep } = retiredSkillFolders(cfg, owned, opts);
152
+ const agent = !ownsRel(owned, 'AGENT.md') && existsSync(path.join(cfg, 'AGENT.md')) ? [path.join(cfg, 'AGENT.md')] : [];
153
+ return { prunes: prune, orphans: [...agent, ...keep] };
154
+ }
155
+
156
+ /** The `--dry-run` half of M5, for each canonical global install of every host. */
152
157
  function orphanPreview(rows) {
153
- return rows.filter(({ host, scope, root }) => scope === 'global' && CLAUDE_STYLE.includes(host) && isCanonical(root, host))
154
- .flatMap(({ root }) => {
155
- const owned = claudeReadManifest(root).owned;
156
- return orphanFindings(root, Array.isArray(owned) ? owned : []);
157
- });
158
+ const out = { prunes: [], orphans: [] };
159
+ for (const { host, scope, root } of rows) {
160
+ if (scope !== 'global' || !isCanonical(root, host)) continue;
161
+ const owned = claudeReadManifest(root).owned;
162
+ const { prunes, orphans } = orphanSplit(root, Array.isArray(owned) ? owned : []);
163
+ out.prunes.push(...prunes);
164
+ out.orphans.push(...orphans);
165
+ }
166
+ return out;
158
167
  }
159
168
 
160
169
  /** The fold and orphan half of `--dry-run`, as the CLI prints it. */
@@ -163,20 +172,25 @@ function printPreview(rows) {
163
172
  printOut(summary ? `[migrate] would fold ${host}: ${summary}\n` : `[migrate] ${host}: nothing to fold\n`);
164
173
  for (const f of failed) printOut(`[migrate] ${host}: the fold would stop at ${f}\n`);
165
174
  }
166
- for (const p of orphanPreview(rows)) {
175
+ const { prunes, orphans } = orphanPreview(rows);
176
+ for (const p of prunes) {
177
+ printOut(`[migrate] would prune: ${p} (Geneseed rendered it and no longer ships it; the next emit moves it to `
178
+ + `${retiredArchiveOf(path.dirname(path.dirname(p)), path.basename(p))})\n`);
179
+ }
180
+ for (const p of orphans) {
167
181
  printOut(`[migrate] orphan: ${p} (no manifest owns it; an earlier build may have written it, or it may be yours). Nothing moves it: if it is not yours, move it by hand.\n`);
168
182
  }
169
183
  }
170
184
 
171
185
  /**
172
- * What the next rebuild would do, for the console: `{folds: [{host, summary, failed}], orphans}`.
173
- * Writes nothing. A marker `migrate` refuses is in here too: `rebuild-all` coerces it, so that
174
- * install still folds. No `would re-emit` plan: that is this verb's, and a clone has none to run.
186
+ * What the next rebuild would do, for the console: `{folds: [{host, summary, failed}], prunes,
187
+ * orphans}`. Writes nothing. A marker `migrate` refuses is in here too: `rebuild-all` coerces it,
188
+ * so that install still folds. No `would re-emit` plan: that is this verb's, and a clone has none.
175
189
  */
176
190
  export function migratePreview() {
177
191
  const { rows, unrecognised } = migrateSurvey({ prune: false });
178
192
  const all = [...rows, ...unrecognised];
179
- return { folds: foldPreview(all), orphans: orphanPreview(all) };
193
+ return { folds: foldPreview(all), ...orphanPreview(all) };
180
194
  }
181
195
 
182
196
  /** A stash key that cannot collide across drives, and is a legal file name on both platforms. */
package/js/web/api.mjs CHANGED
@@ -29,7 +29,9 @@ import {
29
29
  } from '../hosts/installs.mjs';
30
30
  import { PRESETS } from '../loop/score.mjs';
31
31
  import { loadCatalog, catalogProblems } from '../loop/catalog.mjs';
32
- import { activeLoops } from '../loop/registry.mjs';
32
+ import { activeLoops, runningLoops, sameRoot } from '../loop/registry.mjs';
33
+ import { activeFactories } from '../factory/registry.mjs';
34
+ import { factoryCatalogProblems, loopOf } from '../factory/graph.mjs';
33
35
  import { EMIT_OPTIONS, themeOptions } from '../maintain/setup.mjs';
34
36
  import { accentFor, keptKitFiles, statusData } from '../inspect/status.mjs';
35
37
  import { writeTextAtomic } from '../lib/fs.mjs';
@@ -612,6 +614,46 @@ export function apiLoopsActive() {
612
614
  return { loops: activeLoops() };
613
615
  }
614
616
 
617
+ /**
618
+ * The Factories page's catalogue: every factory the install ROOT resolves (shipped, global,
619
+ * project, as `geneseed factory check` reads them), with the whole brick list — the graph draws a
620
+ * brick's `gate: human` badge and the mini ring places its ⛨ gate from `effect` — and the graph
621
+ * of every loop template a factory names (a `loop:<t>` stage, a fork's lanes included), so a
622
+ * `loop:` block can draw its ring. Read-only, like `apiLoops`.
623
+ */
624
+ export function apiFactoriesCatalog(state) {
625
+ const catalog = loadCatalog({ projectRoot: state.root });
626
+ /** @type {(x: [string, any], y: [string, any]) => number} */
627
+ const byName = ([a], [b]) => (a < b ? -1 : 1);
628
+ const factories = [...catalog.factories].sort(byName).map(([name, { origin, ...factory }]) => ({
629
+ name, description: factory.description || '', origin, factory,
630
+ }));
631
+ const named = new Set(factories.flatMap(({ factory: f }) => (Array.isArray(f.stages) ? f.stages : []).map(loopOf).filter(Boolean)));
632
+ return {
633
+ factories,
634
+ bricks: [...catalog.bricks].sort(byName).map(([, b]) => ({ reason: null, ...b })),
635
+ loops: [...catalog.templates].filter(([n]) => named.has(n)).sort(byName)
636
+ .map(([name, { origin, ...graph }]) => ({ name, origin, graph })),
637
+ problems: factoryCatalogProblems(catalog),
638
+ };
639
+ }
640
+
641
+ /**
642
+ * The Factories › Active read: every run `geneseed factory init` registered (machine-wide, like
643
+ * `apiLoopsActive`), each with the loop running in its worktree as `loop` (the root is the join
644
+ * key, `js/factory/registry.mjs`), or null. `runningLoops`, not `activeLoops`: it is read-only,
645
+ * so this poll never prunes or stamps `loops.json` behind the Loops page's back.
646
+ */
647
+ export function apiFactoriesActive() {
648
+ const loops = runningLoops();
649
+ return {
650
+ factories: activeFactories().map((run) => {
651
+ const l = loops.find((x) => sameRoot(x.root, run.root));
652
+ return { ...run, loop: l ? { title: l.title, status: l.status, node: l.node, iteration: l.iteration, graph: l.graph } : null };
653
+ }),
654
+ };
655
+ }
656
+
615
657
  /**
616
658
  * Is a newer release on npm than the source this console serves, and how would this copy take
617
659
  * it? See update-check.mjs.
@@ -16,8 +16,10 @@ import { existsSync, readdirSync } from 'node:fs';
16
16
  import path from 'node:path';
17
17
 
18
18
  import { GLOBAL_MANIFEST, isGlobalInstall, resolvePath } from '../hosts/hosts.mjs';
19
- import { doctrinesForBuild, excludedRulesOfDir, readMaybe } from '../hosts/installs.mjs';
20
- import { frontmatter, readFacts } from '../hosts/memory-files.mjs';
19
+ import { EMIT_HOST_SCOPE, doctrinesForBuild, excludedRulesOfDir, readMaybe } from '../hosts/installs.mjs';
20
+ import { frontmatter, parseRules, readFacts } from '../hosts/memory-files.mjs';
21
+ import { emittedHost, sessionFiles } from '../hosts/hooks-context.mjs';
22
+ import { agentLoadout } from '../inspect/cost.mjs';
21
23
  import {
22
24
  SKILL_CLASS, entityStatus, loadRegistry, tuiInventory,
23
25
  } from '../inspect/inventory.mjs';
@@ -801,3 +803,37 @@ export function apiItem(state, type, name, fleet = [{ install: null, state }]) {
801
803
  }
802
804
  throw new NotFound(type);
803
805
  }
806
+
807
+ /**
808
+ * `GET /api/loadout` (the primary) and `/api/loadout/<agent>`: what one agent of the named install
809
+ * loads, and the rules it follows (spec 2026-11-08, agent loadout). The blocks are `agentLoadout`'s,
810
+ * the one writer of those figures (js/inspect/cost.mjs); this adds what only the install's
811
+ * inventory knows. `rules`: the Dictates, the doctrine rules built in (pack on, rule not excluded),
812
+ * and each user-rules layer's rules by their `R<n>` ids, as `/api/rules` parses them. An Adept's
813
+ * `citedBySpec` marks a rule its rendered spec cites: the render writes a citation as `*<Principle>*`,
814
+ * matched against this install's own rule names, so an unmatched name marks nothing. `noun` is the
815
+ * theme's name for the primary agent. An agent the install lacks, or no carrier, is a 404.
816
+ */
817
+ export function apiLoadout(state, agent = 'primary') {
818
+ // The catalogue is the allowlist: the name becomes a path, and this GET carries no token.
819
+ if (agent !== 'primary' && !state.inventory.agents.some((a) => a.name === agent)) throw new NotFound(agent);
820
+ const [host] = EMIT_HOST_SCOPE.get(state.emit || '') ?? ['opencode'];
821
+ const loadout = agentLoadout({ host, root: state.root ?? state.target, dir: state.target, agent });
822
+ if (!loadout) throw new NotFound(agent);
823
+ const inv = state.inventory;
824
+ const body = agent === 'primary' ? '' : (inv.agents.find((a) => a.name === agent)?.body ?? '');
825
+ const cited = (title) => Boolean(body) && body.includes(`*${title.split(' \u00b7 ').pop()}*`);
826
+ const rules = [
827
+ ...inv.laws.map((l) => ({ kind: 'dictate', id: l.num, title: l.title, citedBySpec: cited(l.title) })),
828
+ ...(inv.doctrines ?? []).filter((p) => p.active).flatMap((p) => p.rules.filter((r) => r.active !== false)
829
+ .map((r) => ({ kind: 'doctrine', id: `${r.pack}.${r.n}`, title: r.title, citedBySpec: cited(r.title) }))),
830
+ ];
831
+ let layers = [];
832
+ try { layers = sessionFiles(state.target, emittedHost(host)).filter((s) => s.rel === 'user-rules.md'); } catch { /* none */ }
833
+ for (const s of layers) {
834
+ for (const r of parseRules(s.text)[0]) {
835
+ rules.push({ kind: 'user', id: `R${r.id}`, title: r.title, layer: s.label || 'install', citedBySpec: false });
836
+ }
837
+ }
838
+ return { ...loadout, rules, noun: loadTheme(makeCfg(), state.theme).PRIMARY_AGENT ?? 'Primary agent' };
839
+ }