geneseed 3.1.0 → 3.1.2

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 (102) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/DESIGN.md +31 -20
  3. package/README.md +2 -2
  4. package/SETUP.md +30 -3
  5. package/SHIPPED.md +1 -1
  6. package/bin/{geneseed.mjs → build-driver.mjs} +88 -42
  7. package/bin/geneseed-cli.mjs +33 -32
  8. package/bin/geneseed-hook.mjs +7 -7
  9. package/docs/design-history.md +40 -40
  10. package/docs/extending.md +113 -85
  11. package/docs/web/rules.md +2 -0
  12. package/docs/web/setup-choices.md +13 -1
  13. package/harness.config.json +1 -1
  14. package/js/README.md +203 -0
  15. package/js/build/bundle.mjs +231 -0
  16. package/js/{catalog.mjs → build/catalog.mjs} +7 -7
  17. package/js/build/emit-claude.mjs +287 -0
  18. package/js/build/emit-common.mjs +255 -0
  19. package/js/build/emit-opencode.mjs +214 -0
  20. package/js/{generate.mjs → build/generate.mjs} +45 -31
  21. package/js/{render.mjs → build/render.mjs} +72 -11
  22. package/js/{checkout.mjs → build/source.mjs} +52 -11
  23. package/js/build/stubs.mjs +256 -0
  24. package/js/{themes.mjs → build/themes.mjs} +24 -24
  25. package/js/build/version.mjs +155 -0
  26. package/js/{hooks.mjs → hosts/hooks.mjs} +47 -44
  27. package/js/{hosts.mjs → hosts/hosts.mjs} +30 -28
  28. package/js/{installs.mjs → hosts/installs.mjs} +68 -16
  29. package/js/{link.mjs → hosts/link.mjs} +29 -28
  30. package/js/{mcp.mjs → hosts/mcp.mjs} +10 -9
  31. package/js/{native.mjs → hosts/native.mjs} +24 -22
  32. package/js/{opencode.mjs → hosts/opencode.mjs} +12 -7
  33. package/js/{settings.mjs → hosts/settings.mjs} +94 -69
  34. package/js/inspect/checks-authoring.mjs +761 -0
  35. package/js/inspect/checks-build.mjs +231 -0
  36. package/js/inspect/checks-repo.mjs +308 -0
  37. package/js/{diff.mjs → inspect/diff.mjs} +34 -31
  38. package/js/inspect/doctor.mjs +286 -0
  39. package/js/{excludes.mjs → inspect/excludes.mjs} +30 -33
  40. package/js/{inventory.mjs → inspect/inventory.mjs} +34 -20
  41. package/js/{registry.mjs → inspect/registry.mjs} +12 -10
  42. package/js/inspect/scan.mjs +125 -0
  43. package/js/{status.mjs → inspect/status.mjs} +27 -25
  44. package/js/inspect/validate.mjs +199 -0
  45. package/js/lib/fs.mjs +37 -759
  46. package/js/lib/json.mjs +344 -0
  47. package/js/lib/paths.mjs +242 -0
  48. package/js/lib/proc.mjs +3 -3
  49. package/js/lib/text.mjs +181 -0
  50. package/js/lib/udiff.mjs +1 -1
  51. package/js/{memory.mjs → maintain/memory.mjs} +10 -10
  52. package/js/{migrate.mjs → maintain/migrate.mjs} +28 -26
  53. package/js/{setup.mjs → maintain/setup.mjs} +49 -37
  54. package/js/{uninstall.mjs → maintain/uninstall.mjs} +62 -58
  55. package/js/{update.mjs → maintain/update.mjs} +51 -51
  56. package/js/{anim.mjs → ui/anim.mjs} +30 -28
  57. package/js/{cli.mjs → ui/cli.mjs} +10 -10
  58. package/js/{menu.mjs → ui/menu.mjs} +10 -9
  59. package/js/{tui.mjs → ui/tui.mjs} +36 -34
  60. package/js/web/actions.mjs +124 -89
  61. package/js/web/activity.mjs +22 -21
  62. package/js/web/api.mjs +88 -58
  63. package/js/web/daemon.mjs +319 -0
  64. package/js/web/docs.mjs +24 -21
  65. package/js/web/graph.mjs +0 -0
  66. package/js/web/handler.mjs +442 -0
  67. package/js/web/jobs.mjs +29 -21
  68. package/js/web/routes.mjs +223 -0
  69. package/js/web/server.mjs +56 -987
  70. package/package.json +11 -3
  71. package/src/AGENT.md.tmpl +1 -1
  72. package/src/doctrines/README.md +1 -1
  73. package/themes/opencode/README.md +1 -1
  74. package/web/dist/assets/{About-_MnJcwb_.js → About-CPvIFZGh.js} +1 -1
  75. package/web/dist/assets/{Activity-DpjqO-FR.js → Activity-z0uXdS7J.js} +1 -1
  76. package/web/dist/assets/{ActivityDetail-Bvrjv8oW.js → ActivityDetail-CEj5IJpF.js} +1 -1
  77. package/web/dist/assets/{Diff-DZ0IehBV.js → Diff-BMR8fPuG.js} +1 -1
  78. package/web/dist/assets/{Doctor-cu4krooO.js → Doctor-Bz5qE4r9.js} +1 -1
  79. package/web/dist/assets/{Graph-DUOPY65j.js → Graph-BV6a6t2l.js} +1 -1
  80. package/web/dist/assets/{Harnesses-B5Osg-BF.js → Harnesses-C5Ag5PaQ.js} +1 -1
  81. package/web/dist/assets/Laws-BK07NKw9.js +3 -0
  82. package/web/dist/assets/{Library-8y69I3_z.js → Library-CiXN9sC3.js} +1 -1
  83. package/web/dist/assets/{Markdown-Ds5GS1OD.js → Markdown-DG6FjUz-.js} +1 -1
  84. package/web/dist/assets/{Profile-7Jxa7ZUX.js → Profile-B2oSvdxH.js} +1 -1
  85. package/web/dist/assets/{Rules-UZ0jWkjg.js → Rules-DobVPd80.js} +1 -1
  86. package/web/dist/assets/{Skills-Bgkl0xLd.js → Skills-DQPsvsn9.js} +1 -1
  87. package/web/dist/assets/{StatusBadge-Cx4caF_2.js → StatusBadge-BhJ3HhdI.js} +1 -1
  88. package/web/dist/assets/{Themes-De8az7Sv.js → Themes-BP38FBU9.js} +1 -1
  89. package/web/dist/assets/{activity-VDAdVQ3q.js → activity-D9mfv7pY.js} +1 -1
  90. package/web/dist/assets/index-BE226Gv6.css +1 -0
  91. package/web/dist/assets/{index-BKrjBRV4.js → index-BZ7cPLMI.js} +1 -1
  92. package/web/dist/assets/index-BgIs5eIa.js +12 -0
  93. package/web/dist/assets/{index-wNiNzFFQ.js → index-DGM5j2hB.js} +1 -1
  94. package/web/dist/index.html +2 -2
  95. package/web/src/pages/Laws.jsx +135 -69
  96. package/docs/declined.md +0 -200
  97. package/docs/limits.md +0 -329
  98. package/js/doctor.mjs +0 -1712
  99. package/js/emit.mjs +0 -1410
  100. package/web/dist/assets/Laws-D8DJgTBp.js +0 -3
  101. package/web/dist/assets/index-1pPSz7Kl.css +0 -1
  102. package/web/dist/assets/index-C-gb-q-r.js +0 -12
@@ -0,0 +1,761 @@
1
+ /**
2
+ * The AUTHORING gates — whether the sources agree with themselves. Law and doctrine
3
+ * metadata, the constitution's numbering, the counts the README and the web UI quote back,
4
+ * and `authoringProblems`, which aggregates them and compiles the OpenCode plugins.
5
+ *
6
+ * Over half of the old `doctor.mjs` was this group, and it is the one with the most reasons
7
+ * to be read: adding a law, a doctrine or a skill moves numbers in files nobody edits by
8
+ * hand, and these are the assertions that say so. `tests/unit/authoring_gates.test.mjs` is
9
+ * its gate, and plants one fault per check.
10
+ *
11
+ * `authoringProblems` is why the doctor is the one verb allowed to spawn a process — it runs
12
+ * `node --check` over every OpenCode plugin. See `doctor.mjs` for what that allow-list costs.
13
+ */
14
+ import path from 'node:path';
15
+ import {
16
+ CONFIG, PACK_ORDER, PLUGIN_SRC, ROOT, SRC, THEMES, knownRuleIds,
17
+ } from '../build/source.mjs';
18
+ import { themeFiles } from '../hosts/installs.mjs';
19
+ import { descBlockProblem, firstBlockquote } from '../hosts/native.mjs';
20
+ import { readText } from '../lib/fs.mjs';
21
+ import { parseJson, formatRepr } from '../lib/json.mjs';
22
+ import { which } from '../lib/paths.mjs';
23
+ import { NO_WINDOW } from '../lib/proc.mjs';
24
+ import { registryProblems, secretProblems, vendorPinProblems } from './checks-repo.mjs';
25
+ import { LAW_CLASS, LAW_CLASSES, SKILL_CLASS } from './inventory.mjs';
26
+ import { NOTE, globSorted, has, isDir, isFile, rglob, srcStems } from './scan.mjs';
27
+ import { spawnSync } from 'node:child_process';
28
+ import { existsSync, readdirSync } from 'node:fs';
29
+
30
+ const ROMAN_VALUES = { I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000 };
31
+
32
+ /**
33
+ * `_harness_build._roman_to_int`. Law headings number in Roman and the web ledger keys its
34
+ * per-rule copy by the Arabic equivalent, so the gate has to bridge the two. 0 on an
35
+ * unparseable numeral, which surfaces as a gate problem rather than a crash.
36
+ */
37
+ export function romanToInt(num) {
38
+ let total = 0;
39
+ let prev = 0;
40
+ for (const ch of [...num.toUpperCase()].reverse()) {
41
+ const v = ROMAN_VALUES[ch];
42
+ if (v === undefined) return 0;
43
+ total += v < prev ? -v : v;
44
+ prev = Math.max(prev, v);
45
+ }
46
+ return total;
47
+ }
48
+
49
+ /**
50
+ * `_harness_build._LAW_META_ROW` — `<arabic>: ['<class>', '<principle>'],` in the web page.
51
+ *
52
+ * Either quote style, because a principle carrying an apostrophe is double-quoted. Every
53
+ * `\s*` spans newlines and the trailing comma before `]` is optional, so a row a prettier has
54
+ * reflowed across several lines still matches — a gate that only understood the one-line form
55
+ * silently lost it and left the law's Principle unguarded.
56
+ *
57
+ * `(?m)` is the `m` flag; JS has no inline form. The `.` inside the captures must NOT match a
58
+ * newline (Python has no `re.S` here), which is JS's default.
59
+ */
60
+ const LAW_META_ROW = /^[^\S\n]*(\d+):\s*\[\s*(['"])(.*?)\2\s*,\s*(['"])(.*?)\4\s*,?\s*\]\s*,?[^\S\n]*$/gm;
61
+
62
+ /**
63
+ * `_harness_build._law_meta_problems` — the web Laws ledger's per-rule copy stays complete.
64
+ *
65
+ * `LAW_META` holds each law's one-line Principle, copy that exists nowhere else in the tree,
66
+ * and a law with no row falls back to `['craft', '']`: the rule renders with a blank
67
+ * description and the wrong class chip, while everything upstream is fine. That is exactly
68
+ * how two laws shipped description-less.
69
+ */
70
+ export function lawMetaProblems(lawNums, lawClass, lawClasses) {
71
+ const page = path.join(ROOT, 'web', 'src', 'pages', 'Laws.jsx');
72
+ let text;
73
+ try { text = readText(page); } catch (e) {
74
+ return [`[authoring] web/src/pages/Laws.jsx unreadable: ${e.message}`];
75
+ }
76
+ const block = /^const LAW_META = \{$([\s\S]*?)^\}$/m.exec(text);
77
+ if (!block) {
78
+ return ['[authoring] LAW_META literal not found in web/src/pages/Laws.jsx — the web '
79
+ + 'Laws ledger\'s Principle column would have no gate'];
80
+ }
81
+ const meta = new Map();
82
+ for (const m of block[1].matchAll(LAW_META_ROW)) {
83
+ meta.set(Number(m[1]), [m[3], m[5]]);
84
+ }
85
+ const problems = [];
86
+ const seen = new Set();
87
+ for (const roman of lawNums) {
88
+ const n = romanToInt(roman);
89
+ seen.add(n);
90
+ if (!meta.has(n)) {
91
+ problems.push(`[authoring] laws/universal.md rule ${roman} (${n}) has no row in `
92
+ + 'LAW_META (web/src/pages/Laws.jsx) — the web Laws ledger would '
93
+ + 'render it with a blank Principle');
94
+ continue;
95
+ }
96
+ const [klass, principle] = meta.get(n);
97
+ if (!principle.trim()) {
98
+ problems.push(`[authoring] LAW_META[${n}] has an empty principle line — rule `
99
+ + `${roman} would render with a blank description`);
100
+ }
101
+ if (!lawClasses.includes(klass)) {
102
+ problems.push(`[authoring] LAW_META[${n}] class '${klass}' is not a known class `
103
+ + `${formatRepr(lawClasses)}`);
104
+ } else if (lawClass[roman] && klass !== lawClass[roman]) {
105
+ problems.push(`[authoring] LAW_META[${n}] classes rule ${roman} as '${klass}' but `
106
+ + `LAW_CLASS says '${lawClass[roman]}'`);
107
+ }
108
+ }
109
+ for (const n of [...meta.keys()].filter((k) => !seen.has(k)).sort((a, b) => a - b)) {
110
+ problems.push(`[authoring] LAW_META lists rule ${n} but laws/universal.md has no such rule`);
111
+ }
112
+ return problems;
113
+ }
114
+
115
+ /** `LAW_META_ROW`'s twin for a STRING key — `'<pack>.<n>': ['<pack>', '<principle>'],`. */
116
+ const DOCTRINE_META_ROW =
117
+ /^[^\S\n]*(['"])([a-z]+\.\d+)\1:\s*\[\s*(['"])(.*?)\3\s*,\s*(['"])(.*?)\5\s*,?\s*\]\s*,?[^\S\n]*$/gm;
118
+
119
+ /**
120
+ * `lawMetaProblems`' doctrine half — the console's per-rule Principle column stays complete.
121
+ *
122
+ * SAME DEFECT, ONE TIER OVER. `DOCTRINE_META` holds copy that exists nowhere else in the tree,
123
+ * and a rule with no row falls back to an empty principle: it renders with a blank description
124
+ * while every count upstream reads correct. Two invariants shipped exactly that way before
125
+ * `lawMetaProblems` existed, and 23 new rules is a much larger surface to lose one in.
126
+ *
127
+ * ⚠ THE CLASS ARM IS DIFFERENT FROM THE INVARIANTS'. An invariant's class is checked against
128
+ * `LAW_CLASSES`, a vocabulary of six; a doctrine rule has no second taxonomy — its class IS its
129
+ * pack — so the check is an EQUALITY against the pack in its own key. That catches the copy
130
+ * error a six-way vocabulary cannot: a row pasted from the pack above it, keeping the class of
131
+ * the pack it came from, which would colour the row and label its chip with the wrong pack.
132
+ */
133
+ export function doctrineMetaProblems(addrs) {
134
+ const page = path.join(ROOT, 'web', 'src', 'pages', 'Laws.jsx');
135
+ let text;
136
+ try { text = readText(page); } catch (e) {
137
+ return [`[authoring] web/src/pages/Laws.jsx unreadable: ${e.message}`];
138
+ }
139
+ const block = /^const DOCTRINE_META = \{$([\s\S]*?)^\}$/m.exec(text);
140
+ if (!block) {
141
+ return ['[authoring] DOCTRINE_META literal not found in web/src/pages/Laws.jsx — the '
142
+ + "console's doctrine rows would have no gate on their Principle column"];
143
+ }
144
+ const meta = new Map();
145
+ for (const m of block[1].matchAll(DOCTRINE_META_ROW)) meta.set(m[2], [m[4], m[6]]);
146
+ const problems = [];
147
+ const seen = new Set();
148
+ for (const addr of addrs) {
149
+ seen.add(addr);
150
+ if (!meta.has(addr)) {
151
+ problems.push(`[authoring] doctrine rule ${addr} has no row in DOCTRINE_META `
152
+ + '(web/src/pages/Laws.jsx) — the console would render it with a blank Principle');
153
+ continue;
154
+ }
155
+ const [klass, principle] = meta.get(addr);
156
+ if (!principle.trim()) {
157
+ problems.push(`[authoring] DOCTRINE_META['${addr}'] has an empty principle line — that `
158
+ + 'rule would render with a blank description');
159
+ }
160
+ const pack = addr.split('.')[0];
161
+ if (klass !== pack) {
162
+ problems.push(`[authoring] DOCTRINE_META['${addr}'] carries pack '${klass}' — a doctrine `
163
+ + `rule's class IS its pack, so this must read '${pack}'`);
164
+ }
165
+ }
166
+ for (const addr of [...meta.keys()].filter((k) => !seen.has(k)).sort()) {
167
+ problems.push(`[authoring] DOCTRINE_META lists ${addr} but no pack file defines it`);
168
+ }
169
+ return problems;
170
+ }
171
+
172
+ /**
173
+ * `_harness_build._prose_mirror_problems` — the human-readable count mirrors, the ones the
174
+ * badge regex never sees.
175
+ *
176
+ * The README "What you get" table and the web onboarding copy each restate the law / agent /
177
+ * skill counts in prose, and the README enumerates the skills by name. Nothing renders these,
178
+ * so they drift silently — they already had. Pure over its inputs, so the corpus can feed it
179
+ * crafted drift without touching the tree.
180
+ */
181
+ export function proseMirrorProblems(readme, web, counts, skillStems, shipped = '') {
182
+ const problems = [];
183
+ const { laws, agents, skills, plugins } = counts;
184
+
185
+ for (const m of readme.matchAll(/(\d+) universal laws/g)) {
186
+ if (Number(m[1]) !== laws) {
187
+ problems.push(`[authoring] README prose says '${m[1]} universal laws' but src has ${laws}`);
188
+ }
189
+ }
190
+ // The README plugin count. It had drifted — the overview sentence said six while seven
191
+ // shipped — because the project's other plugin count ({N_PLUGINS} in the web docs) reads
192
+ // a DEPLOYED plugins dir that a markdown file in this repository never has. `plugins` is
193
+ // optional in `counts` (Python's `.get`, undefined here) because the corpus predates it.
194
+ if (plugins !== undefined) {
195
+ for (const m of readme.matchAll(/(\d+) \*{0,2}plugins/g)) {
196
+ if (Number(m[1]) !== plugins) {
197
+ problems.push(`[authoring] README prose says '${m[1]} plugins' but `
198
+ + `adapters/opencode/plugins has ${plugins}`);
199
+ }
200
+ }
201
+ }
202
+ for (const [label, want] of [['Agents', agents], ['Skills', skills]]) {
203
+ const m = new RegExp(`${label}\\*\\*\\s*\\((\\d+)\\)`).exec(readme);
204
+ if (m && Number(m[1]) !== want) {
205
+ problems.push(`[authoring] README '${label} (${m[1]})' but src has ${want}`);
206
+ }
207
+ }
208
+ // The README Skills row must enumerate EXACTLY the source skills — a dropped name is
209
+ // invisible to the (N) count alone, which is the off-by-one this gate forbids.
210
+ const row = readme.split('\n').find((ln) => ln.includes('🛠') && ln.includes('Skills')) ?? '';
211
+ if (row.includes('workflows:')) {
212
+ const listed = new Set(row.split('workflows:').slice(1).join('workflows:').split('·')
213
+ .map((seg) => seg.replace(/[^a-z0-9-]/g, '')));
214
+ listed.delete('');
215
+ for (const missing of [...skillStems].filter((s) => !listed.has(s)).sort()) {
216
+ problems.push(`[authoring] README skills list omits '${missing}'`);
217
+ }
218
+ for (const orphan of [...listed].filter((s) => !skillStems.has(s)).sort()) {
219
+ problems.push(`[authoring] README skills list names '${orphan}' but no `
220
+ + `skills/${orphan}.md exists`);
221
+ }
222
+ }
223
+
224
+ for (const m of web.matchAll(/(\d+) universal (?:laws|Rules)/g)) {
225
+ if (Number(m[1]) !== laws) {
226
+ problems.push(`[authoring] _web_core prose says '${m[1]} universal laws/Rules' but `
227
+ + `src has ${laws}`);
228
+ }
229
+ }
230
+ for (const m of web.matchAll(/(\d+) capability specialists/g)) {
231
+ if (Number(m[1]) !== agents) {
232
+ problems.push(`[authoring] _web_core prose says '${m[1]} capability specialists' but `
233
+ + `src has ${agents}`);
234
+ }
235
+ }
236
+ // N is a curated-subset size, not the total, so it is gated against the wikilinks it
237
+ // introduces rather than against the skill count. `[\s\S]` is Python's `re.S` dot.
238
+ const m = /(\d+) repeatable workflows the agent can invoke by name([\s\S]*?)playbook under/
239
+ .exec(web);
240
+ if (m) {
241
+ const listedN = (m[2].match(/\[\[[^\]]+\]\]/g) ?? []).length;
242
+ if (Number(m[1]) !== listedN) {
243
+ problems.push(`[authoring] _web_core says '${m[1]} repeatable workflows' `
244
+ + `but its wikilink list has ${listedN}`);
245
+ }
246
+ }
247
+
248
+ // ⚠ THE ABSENCE OF THIS TRIPLE IS CHECKED BY THE CALLER, NOT HERE, AND THAT IS FORCED RATHER
249
+ // THAN CHOSEN. This arm is satisfiable by DELETING THE SENTENCE — no match, no problem, green
250
+ // — which is a gate failing open. The obvious fix is an `else` right here, and it cannot go
251
+ // here: `prose_mirror_problems` is one of the pure functions recorded in
252
+ // `tests/__snapshots__/primitives/`, the recording holds a case that passes an EMPTY `shipped`
253
+ // and expects `[]`, and there is no recorder left to re-bless it. So the presence check lives
254
+ // in `countTableProblems`, which is not recorded — beside the read that already knows whether
255
+ // the file could be opened at all, which is where it reads better anyway.
256
+ const s = /(\d+) laws, (\d+) agents, (\d+) skills/.exec(shipped);
257
+ if (s) {
258
+ for (const [got, want, label] of [[s[1], laws, 'laws'], [s[2], agents, 'agents'],
259
+ [s[3], skills, 'skills']]) {
260
+ if (Number(got) !== want) {
261
+ problems.push(`[authoring] SHIPPED.md says '${got} ${label}' but src has ${want}`);
262
+ }
263
+ }
264
+ }
265
+ return problems;
266
+ }
267
+
268
+ /** `_build_render._TMPL_SPEC_RE`, as the count gate spells it. */
269
+ const TMPL_SPEC_RE = /\{\{DIR_(AGENTS|SKILLS)\}\}\/([A-Za-z0-9_-]+)\.md/g;
270
+ const LAW_HEADING_RE = /^### \{\{LAW\}\} ([IVXLCDM]+)\b/gm;
271
+
272
+ // The doctrine twins of `LAW_HEADING_RE`, over the UNRENDERED source — `js/inspect/inventory.mjs`'s
273
+ // pair of the same names read the rendered form. A citation is the heading minus its `### `,
274
+ // so one regex cannot serve both: a heading is an anchored line, a citation is anywhere.
275
+ const DOCTRINE_HEADING_RE = /^### \{\{DOCTRINE\}\} ([a-z]+) (\d+)\b/gm;
276
+ const DOCTRINE_CITE_RE = /\{\{DOCTRINE\}\}\s+([a-z]+)\s+(\d+)/g;
277
+ // `\{\{DOCTRINE\}\}` and not `DOCTRINE`: `{{DOCTRINES}}` is the SECTION noun and is legal
278
+ // everywhere, including in an invariant that points at the tier as a whole.
279
+ const DOCTRINE_TOKEN_RE = /\{\{DOCTRINE\}\}/;
280
+ const DOC_TOKEN_RE = /\{\{(DOC_[A-Z0-9_]+)\}\}/g;
281
+
282
+ /**
283
+ * The three-tier constitution's own authoring gates — the doctrine twin of the `LAW_CLASS` /
284
+ * `LAW_META` family, plus the two purity rules the tiering rests on.
285
+ *
286
+ * IT LIVES BESIDE `countTableProblems` RATHER THAN INSIDE IT, and is called from
287
+ * `authoringProblems` beside `registry`/`secret`/`vendorPin`. `countTableProblems` opens by
288
+ * reading `AGENT.md.tmpl` and HARD-RETURNS if that read fails, so an arm placed inside it
289
+ * would go quiet on exactly the tree that is most broken. Nothing here needs the template's
290
+ * tables, and `proseMirrorProblems` — the frozen recording — is untouched either way.
291
+ *
292
+ * ⚠ THE VOCABULARY GATES ARE HERE BECAUSE `themeParityProblems` CANNOT SEE THEM. That check is
293
+ * presence-only and SYMMETRIC over the union of every theme's keys: a key missing from all
294
+ * fourteen is in parity, and a key whose VALUE breaks a parser is not its business at all. So
295
+ * `DOC_*` coverage, the `LEX_I..LEX_IX` equality and the single-word tier noun each need a gate
296
+ * that reads the SOURCE and asks what the source requires.
297
+ */
298
+ export function constitutionProblems() {
299
+ const problems = [];
300
+ const dir = path.join(SRC, 'doctrines');
301
+
302
+ // ---- the packs themselves: present, contiguous from 1, and filed where they say they are.
303
+ const rules = new Map(); // 'craft.1' -> title-less marker
304
+ for (const pack of PACK_ORDER) {
305
+ const file = path.join(dir, `${pack}.md`);
306
+ let text;
307
+ try { text = readText(file); } catch (e) {
308
+ problems.push(`[authoring] doctrines/${pack}.md is named in PACK_ORDER but unreadable: `
309
+ + `${e.message} — the build ships the whole catalogue, so a missing pack file breaks `
310
+ + 'every citation into it, active or not');
311
+ continue;
312
+ }
313
+ const found = [...text.matchAll(DOCTRINE_HEADING_RE)];
314
+ if (!found.length) {
315
+ problems.push(`[authoring] doctrines/${pack}.md carries no '### {{DOCTRINE}} ${pack} <n>' `
316
+ + 'heading — the pack would render as an empty section');
317
+ continue;
318
+ }
319
+ found.forEach(([, named, n], i) => {
320
+ if (named !== pack) {
321
+ problems.push(`[authoring] doctrines/${pack}.md holds a rule addressed to '${named} `
322
+ + `${n}' — a rule's pack is read from its heading, so this one is unreachable at `
323
+ + `'${pack}.${n}' and shadows whatever ${named}.md numbers ${n}`);
324
+ }
325
+ if (Number(n) !== i + 1) {
326
+ problems.push(`[authoring] doctrines/${pack}.md rule ${n} is at position ${i + 1} — `
327
+ + 'pack ids must run contiguously from 1, or a citation addresses a gap');
328
+ }
329
+ rules.set(`${named}.${Number(n)}`, true);
330
+ });
331
+ }
332
+
333
+ // The console's Principle column, keyed off the rules just parsed — so the gate is driven by
334
+ // the SOURCE and a rule added to a pack file is caught the same day, not when someone
335
+ // notices a blank description in the browser.
336
+ problems.push(...doctrineMetaProblems([...rules.keys()]));
337
+
338
+ // ---- `--exclude-rules` closes against the SAME rules this walk just found.
339
+ //
340
+ // `knownRuleIds` is what the CLI flag, the console's trust boundary and every wizard prompt
341
+ // validate an address against; the walk above is what the constitution actually renders.
342
+ // Two readers of one directory is the shape that lets a rule be authored, rendered, cited —
343
+ // and rejected by the only flag that can switch it off, with `invalid choice` naming a set
344
+ // that visibly contains it. An equality, not containment: a stale id in the enumerator is a
345
+ // rule the console offers a switch for and the build cannot drop.
346
+ const enumerated = knownRuleIds();
347
+ const walked = [...rules.keys()];
348
+ for (const id of enumerated.filter((i) => !walked.includes(i))) {
349
+ problems.push(`[authoring] knownRuleIds() offers '${id.replace('.', ' ')}', which no pack `
350
+ + 'file defines — --exclude-rules accepts an address the build cannot drop');
351
+ }
352
+ for (const id of walked.filter((i) => !enumerated.includes(i))) {
353
+ problems.push(`[authoring] doctrine ${id.replace('.', ' ')} is defined but knownRuleIds() `
354
+ + 'does not offer it — --exclude-rules refuses a rule that exists, and the console has '
355
+ + 'no switch for it');
356
+ }
357
+
358
+ // ---- the consent gate's address still names the consent rule.
359
+ //
360
+ // ⚠ THE ONE HARDCODED ADDRESS IN THE CODEBASE, and the one whose drift is silent AND unsafe.
361
+ // `js/hosts/settings.mjs` keys the git-gate hooks on `process.5` by literal; a renumber of the
362
+ // process pack moves that rule's neighbours under it, and the boundary would then follow
363
+ // whatever rule inherited the number while the prompt still said `process 5`. Checked
364
+ // against the pack file's own title token rather than against prose, so a reworded rule is
365
+ // not a false alarm and a MOVED one is not a silent pass.
366
+ const consentTitle = 'DOC_PROCESS_5';
367
+ let processText = '';
368
+ try { processText = readText(path.join(dir, 'process.md')); } catch { /* reported above */ }
369
+ if (processText && !new RegExp(`^### \\{\\{DOCTRINE\\}\\} process 5 — \\{\\{${consentTitle}\\}\\}`,
370
+ 'm').test(processText)) {
371
+ problems.push('[authoring] js/hosts/settings.mjs gates git commit/push on doctrine \'process 5\', '
372
+ + `but doctrines/process.md does not number {${consentTitle}} 5 — the tool boundary and `
373
+ + 'the prompt now name different rules');
374
+ }
375
+
376
+ // ---- every `{{DOCTRINE}} <pack> <n>` anywhere in src/ resolves to a rule that exists.
377
+ //
378
+ // The whole tree, not the template: a skill footer citing `process 9` is as broken as a
379
+ // template one, and it is the shape 339 rewired citations could have left behind.
380
+ const cited = new Map(); // 'process.5' -> [rel, …]
381
+ for (const p of rglob(SRC)) {
382
+ if (!isFile(p) || !(p.endsWith('.md') || p.endsWith('.tmpl'))) continue;
383
+ let text;
384
+ try { text = readText(p); } catch { continue; }
385
+ const rel = path.relative(SRC, p).split(path.sep).join('/');
386
+ // ⚠ AN ALWAYS-ON TIER MAY NEVER CITE A TOGGLEABLE ONE (D2). A `--doctrines craft` build
387
+ // ships invariants that point at rules its AGENT.md does not contain; the ontology is
388
+ // worse still, being the tier that states the order the others sit in. Doctrine->doctrine
389
+ // citations are fine and stay: the full catalogue ships in every bundle.
390
+ if ((rel.startsWith('ontology/') || rel.startsWith('laws/')) && DOCTRINE_TOKEN_RE.test(text)) {
391
+ problems.push(`[authoring] ${rel} cites {{DOCTRINE}} — an always-on tier may never `
392
+ + 'reference a toggleable one, or a pack-off build ships a rule pointing at text '
393
+ + 'that is not there. State the point directly instead');
394
+ }
395
+ for (const [, pack, n] of text.matchAll(DOCTRINE_CITE_RE)) {
396
+ const key = `${pack}.${Number(n)}`;
397
+ if (!cited.has(key)) cited.set(key, []);
398
+ cited.get(key).push(rel);
399
+ }
400
+ }
401
+ for (const [key, where] of [...cited].sort()) {
402
+ if (rules.has(key)) continue;
403
+ problems.push(`[authoring] ${where[0]} cites {{DOCTRINE}} ${key.replace('.', ' ')}, which `
404
+ + `no pack file defines${where.length > 1 ? ` (and ${where.length - 1} more)` : ''}`);
405
+ }
406
+
407
+ // ---- the vocabulary every theme owes the source.
408
+ const wanted = new Set();
409
+ for (const pack of PACK_ORDER) {
410
+ let text;
411
+ try { text = readText(path.join(dir, `${pack}.md`)); } catch { continue; }
412
+ for (const [, key] of text.matchAll(DOC_TOKEN_RE)) wanted.add(key);
413
+ }
414
+ const lexWant = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'].map((r) => `LEX_${r}`);
415
+ // `_TEMPLATE.json` is included — it is the file `--sync-themes` seeds a new theme from, so a
416
+ // stale key there propagates into every voice added afterwards. `themeFiles()` excludes it.
417
+ const files = [...themeFiles(), path.join(THEMES, '_TEMPLATE.json')];
418
+ for (const f of files) {
419
+ const name = path.basename(f);
420
+ let theme;
421
+ try { theme = parseJson(readText(f)); } catch (e) {
422
+ problems.push(`[authoring] ${name} unreadable: ${e.message}`);
423
+ continue;
424
+ }
425
+ if (!theme || typeof theme !== 'object' || Array.isArray(theme)) continue;
426
+ const keys = Object.keys(theme);
427
+ for (const key of [...wanted].sort()) {
428
+ if (!Object.hasOwn(theme, key)) {
429
+ problems.push(`[authoring] ${name} has no {${key}} — a doctrine file names it, and `
430
+ + 'theme parity cannot see a key that is missing from every theme at once');
431
+ }
432
+ }
433
+ for (const key of keys.filter((k) => k.startsWith('DOC_')).sort()) {
434
+ if (!wanted.has(key)) {
435
+ problems.push(`[authoring] ${name} defines {${key}}, which no doctrine file uses — a `
436
+ + 'dead voice key ships a title for a rule that does not exist');
437
+ }
438
+ }
439
+ // I1 — an EQUALITY, not a presence check. The renumber left `LEX_XXII`, `LEX_XXIII`,
440
+ // `LEX_XXIV` and `LEX_XXXVI` behind in all fifteen files, and parity was silent because
441
+ // they were absent from nowhere.
442
+ const lex = keys.filter((k) => k.startsWith('LEX_')).sort();
443
+ const stale = lex.filter((k) => !lexWant.includes(k));
444
+ const missing = lexWant.filter((k) => !lex.includes(k));
445
+ for (const k of stale) {
446
+ problems.push(`[authoring] ${name} still defines {${k}} — the invariants are I..IX and `
447
+ + 'nothing renders this key, so it is a title for a rule that no longer exists');
448
+ }
449
+ for (const k of missing) {
450
+ problems.push(`[authoring] ${name} has no {${k}} — one of the nine invariants would `
451
+ + 'render with an empty title');
452
+ }
453
+ // M10 — ⚠ BOTH HEADING PARSERS MATCH THE TIER NOUN WITH `\S+`. A two-word value does not
454
+ // error; the heading stops matching and the tier silently parses to nothing. `_TEMPLATE`'s
455
+ // values are descriptive placeholders, so only real voices are held to this.
456
+ if (name === '_TEMPLATE.json') continue;
457
+ for (const key of ['LAW', 'DOCTRINE']) {
458
+ const v = theme[key];
459
+ if (typeof v === 'string' && /\s/.test(v)) {
460
+ problems.push(`[authoring] ${name} spells {${key}} as ${formatRepr(v)} — the heading `
461
+ + 'parsers match the tier noun with \\S+, so a value with a space makes every '
462
+ + `${key === 'LAW' ? 'invariant' : 'doctrine rule'} parse to nothing, in silence`);
463
+ }
464
+ }
465
+ }
466
+
467
+ // ---- every `§N` in src/ addresses a section the template actually declares.
468
+ //
469
+ // ⚠ THIS GATE IS NARROW AND SAYS SO. Inserting `## 2. Doctrines` pushed every later section
470
+ // down one, and the sweep that fixed the template's own cross-references stopped at the
471
+ // template — four satellites under `src/skills/` and `src/agents/` kept pointing at the
472
+ // section that used to be there, and they RENDER INTO EVERY BUNDLE. A range check would not
473
+ // have caught those: §7 still existed, it had just stopped being the Wiki.
474
+ //
475
+ // What it does catch is the other half of a renumber — a pointer past the end, which is what
476
+ // REMOVING a section leaves behind — and it is nearly free. The half it cannot catch is a
477
+ // judgement about intent, and `docs/extending.md` carries the manual sweep for it. Naming
478
+ // that limit here is the point: a reader who assumes this gate is total will skip the sweep.
479
+ const declared = new Set();
480
+ // Read here rather than borrowing `countTableProblems`' copy: that function hard-returns when
481
+ // the template is unreadable, and this gate must not inherit a silence it did not choose.
482
+ let tmpl = '';
483
+ try { tmpl = readText(path.join(SRC, 'AGENT.md.tmpl')); } catch { tmpl = ''; }
484
+ for (const [, n] of tmpl.matchAll(/^## (\d+)\.\s/gm)) declared.add(Number(n));
485
+ if (declared.size) {
486
+ for (const p of rglob(SRC)) {
487
+ if (!isFile(p) || !(p.endsWith('.md') || p.endsWith('.tmpl'))) continue;
488
+ let text;
489
+ try { text = readText(p); } catch { continue; }
490
+ const rel = path.relative(SRC, p).split(path.sep).join('/');
491
+ for (const [, n] of text.matchAll(/§(\d+)/g)) {
492
+ if (declared.has(Number(n))) continue;
493
+ problems.push(`[authoring] ${rel} cites AGENT.md §${n}, and the template declares no `
494
+ + `such section ${formatRepr([...declared].sort((a, b) => a - b).map(String))} — a `
495
+ + 'renumber moved it, and this pointer renders into every bundle');
496
+ }
497
+ }
498
+ }
499
+
500
+ // ---- the build default names packs that exist.
501
+ let cfgDoctrines = null;
502
+ try {
503
+ const cfg = parseJson(readText(CONFIG));
504
+ if (cfg && typeof cfg === 'object' && Array.isArray(cfg.doctrines)) cfgDoctrines = cfg.doctrines;
505
+ } catch { /* no config, or unreadable — `configDefaults()` is forgiving here too */ }
506
+ if (cfgDoctrines) {
507
+ for (const pack of cfgDoctrines) {
508
+ if (!PACK_ORDER.includes(pack)) {
509
+ problems.push(`[authoring] harness.config.json names doctrine pack ${formatRepr(pack)}, `
510
+ + `which this checkout does not ship ${formatRepr([...PACK_ORDER])} — every build reading `
511
+ + 'that default would fail');
512
+ }
513
+ }
514
+ }
515
+
516
+ // ---- D5, a NOTE and not a problem: what a narrowed default leaves pointing at the shelf.
517
+ const on = cfgDoctrines ?? [...PACK_ORDER];
518
+ const dangling = [...cited].filter(([k]) => rules.has(k) && !on.includes(k.split('.')[0]));
519
+ if (dangling.length) {
520
+ const packs = [...new Set(dangling.map(([k]) => k.split('.')[0]))].sort();
521
+ problems.push(`${NOTE}harness.config.json builds ${formatRepr(on)}, and ${dangling.length} `
522
+ + `citation(s) in src/ point into ${packs.join(', ')}. Those rules still SHIP — every `
523
+ + 'pack file is in the bundle — so the reference resolves on disk; it is the rendered '
524
+ + 'AGENT.md that will not contain them. Legal, and recorded here so it is not silent');
525
+ }
526
+ return problems;
527
+ }
528
+
529
+ /**
530
+ * `_harness_build._count_table_problems` — the hand-authored AGENT.md tables and the README
531
+ * badges, against `src/`.
532
+ *
533
+ * The tables must list EXACTLY the spec files (no dead row, no orphaned spec) and each
534
+ * `agents`/`skills`/`laws`/`themes` badge must equal the real count. This is the
535
+ * authoring-time guarantee that lets tables, badges and prose stay hand-written without
536
+ * silently drifting from the source tree.
537
+ */
538
+ export function countTableProblems() {
539
+ const problems = [];
540
+ let ttext;
541
+ try { ttext = readText(path.join(SRC, 'AGENT.md.tmpl')); } catch (e) {
542
+ return [`[authoring] AGENT.md.tmpl unreadable: ${e.message}`];
543
+ }
544
+
545
+ const linked = { agents: new Set(), skills: new Set() };
546
+ for (const m of ttext.matchAll(TMPL_SPEC_RE)) {
547
+ if (m[2] !== '_template') linked[m[1] === 'AGENTS' ? 'agents' : 'skills'].add(m[2]);
548
+ }
549
+ for (const folder of ['agents', 'skills']) {
550
+ const files = srcStems(folder);
551
+ for (const missing of [...linked[folder]].filter((x) => !files.has(x)).sort()) {
552
+ problems.push(`[authoring] AGENT.md links ${folder}/${missing}.md but no such spec exists`);
553
+ }
554
+ for (const orphan of [...files].filter((x) => !linked[folder].has(x)).sort()) {
555
+ problems.push(`[authoring] ${folder}/${orphan}.md exists but the AGENT.md table omits it`);
556
+ }
557
+ }
558
+
559
+ const skillFiles = srcStems('skills');
560
+ for (const missing of [...skillFiles].filter((s) => !has(SKILL_CLASS, s)).sort()) {
561
+ problems.push(`[authoring] skills/${missing}.md has no category in SKILL_CLASS`);
562
+ }
563
+ for (const stale of Object.keys(SKILL_CLASS).filter((s) => !skillFiles.has(s)).sort()) {
564
+ problems.push(`[authoring] SKILL_CLASS lists '${stale}' but no skills/${stale}.md exists`);
565
+ }
566
+
567
+ const lawsMd = path.join(SRC, 'laws', 'universal.md');
568
+ const lawNums = isFile(lawsMd)
569
+ ? [...readText(lawsMd).matchAll(LAW_HEADING_RE)].map((m) => m[1]) : [];
570
+ for (const num of lawNums) {
571
+ if (!has(LAW_CLASS, num)) {
572
+ problems.push(`[authoring] laws/universal.md rule ${num} has no class in LAW_CLASS`);
573
+ }
574
+ }
575
+ // `sorted(LAW_CLASS.items())` — by the Roman numeral as a STRING, which is what Python
576
+ // sorts here; the messages are re-sorted by `doctorCollect` anyway, so only the set travels.
577
+ for (const num of Object.keys(LAW_CLASS).sort()) {
578
+ if (!LAW_CLASSES.includes(LAW_CLASS[num])) {
579
+ problems.push(`[authoring] LAW_CLASS['${num}'] = '${LAW_CLASS[num]}' is not a known `
580
+ + `class ${formatRepr(LAW_CLASSES)}`);
581
+ }
582
+ }
583
+ problems.push(...lawMetaProblems(lawNums, LAW_CLASS, LAW_CLASSES));
584
+
585
+ const counts = {
586
+ agents: srcStems('agents').size,
587
+ skills: srcStems('skills').size,
588
+ laws: lawNums.length,
589
+ themes: themeFiles().length,
590
+ // Last on purpose: the badge loop below walks this object in insertion order and the
591
+ // message sequence is compared byte for byte against the Python implementation.
592
+ plugins: existsSync(PLUGIN_SRC)
593
+ ? readdirSync(PLUGIN_SRC).filter((f) => f.startsWith('geneseed-') && f.endsWith('.js')).length
594
+ : 0,
595
+ };
596
+ let readme;
597
+ try { readme = readText(path.join(ROOT, 'README.md')); } catch { return problems; }
598
+ // ⚠ PRESENCE FIRST, THEN THE VALUE — the same absence arm the SHIPPED triple needed, for the
599
+ // same reason: `if (m && …)` is green when there is no badge, so deleting a badge silences its
600
+ // own gate. The `continue` keeps the loop's MESSAGE ORDER intact, which is load-bearing (see
601
+ // the `plugins`-is-last comment above): a missing badge reports in its own slot rather than
602
+ // reordering the ones after it.
603
+ for (const [key, n] of Object.entries(counts)) {
604
+ const m = new RegExp(`badge/${key}-(\\d+)`).exec(readme);
605
+ if (!m) {
606
+ problems.push(`[authoring] README has no ${key} badge — deleting one is how this gate `
607
+ + 'goes green while the reader is told nothing');
608
+ continue;
609
+ }
610
+ if (Number(m[1]) !== n) {
611
+ problems.push(`[authoring] README ${key} badge says ${m[1]} but src has ${n}`);
612
+ }
613
+ }
614
+
615
+ // WHERE THE ONBOARDING COPY LIVES, AND WHY THIS READ MOVED. It used to open the one module
616
+ // that held the web console's onboarding prose. That prose has since moved into
617
+ // `docs/web/*.md`, and the counts in it render from `{N_LAWS}` / `{N_AGENTS}` / `{N_SKILLS}`
618
+ // — so the read was still succeeding against a file the sentences had left, all three arms
619
+ // below scored zero, and the check looked healthy while gating nothing. A templated count
620
+ // cannot drift; what these arms still catch is a maintainer typing the NUMBER into a page
621
+ // instead of the token, which is the drift that reaches a reader.
622
+ //
623
+ // MEASURED BEFORE AND AFTER: zero problems either way on the shipped tree, so no recorded
624
+ // byte moves. `web` stays fail-soft — a missing docs tree is not an authoring fault.
625
+ let web = '';
626
+ try {
627
+ web = globSorted(path.join(ROOT, 'docs', 'web'), (n) => n.endsWith('.md'))
628
+ .map(readText).join('\n');
629
+ } catch { web = ''; }
630
+ // ⚠ NOT FAIL-SOFT, UNLIKE `web` ABOVE, AND THE ASYMMETRY IS THE POINT. A missing `docs/web`
631
+ // tree is not an authoring fault — a checkout can legitimately lack it. SHIPPED.md is a
632
+ // tracked, shipped file that this function asserts the CONTENT of, so an unreadable one is
633
+ // indistinguishable from a deleted claim: swallowing it into `''` used to hand the triple arm
634
+ // an empty string and turn a hard read failure into a silent pass.
635
+ // ⚠ NOT FAIL-SOFT, UNLIKE `web` ABOVE, AND THE ASYMMETRY IS THE POINT. A missing `docs/web`
636
+ // tree is not an authoring fault — a checkout can legitimately lack it. SHIPPED.md is a
637
+ // tracked, shipped file whose CONTENT this function asserts, so an unreadable one was
638
+ // indistinguishable from a deleted claim: swallowing it into `''` handed the triple arm an
639
+ // empty string and turned a hard read failure into a silent pass.
640
+ //
641
+ // AND THE PRESENCE OF THE TRIPLE IS CHECKED HERE rather than inside `proseMirrorProblems`,
642
+ // which is where it belongs by subject and cannot go by construction — that function is
643
+ // recorded in `tests/__snapshots__/primitives/` with a case that passes an empty `shipped` and
644
+ // expects `[]`, and nothing can re-bless a recording whose recorder is deleted. This is the
645
+ // caller, it is not recorded, and it already owns the question "could the file be read".
646
+ let shipped;
647
+ try {
648
+ shipped = readText(path.join(ROOT, 'SHIPPED.md'));
649
+ } catch (e) {
650
+ problems.push(`[authoring] SHIPPED.md is unreadable (${e.message}) — the counts it carries `
651
+ + 'cannot be checked, and a gate that cannot read its subject must say so');
652
+ shipped = '';
653
+ }
654
+ if (shipped && !/(\d+) laws, (\d+) agents, (\d+) skills/.test(shipped)) {
655
+ problems.push('[authoring] SHIPPED.md carries no \'N laws, N agents, N skills\' line — '
656
+ + 'deleting it is how that gate goes green while the count drifts');
657
+ }
658
+ problems.push(...proseMirrorProblems(readme, web, counts, skillFiles, shipped));
659
+ return problems;
660
+ }
661
+
662
+ /** `_harness_core.LEARN_PROMPT_HEAD`'s extraction regex — one owner, two readers. */
663
+ const LEARN_PROMPT_RE = /const LEARN_PROMPT_HEAD = `([\s\S]*?)`/;
664
+
665
+ /**
666
+ * `_harness_core._load_learn_prompt_head` — the distil instructions, read out of the plugin.
667
+ *
668
+ * The single source of truth is the OpenCode plugin, the artifact that ships to the primary
669
+ * runtime, so the CLI extracts it at load time rather than carrying a copy. Reproduced here
670
+ * rather than imported from `js/hosts/hooks.mjs`, which this entry may not reach: `learn` spawns the
671
+ * model CLI, and the allow-list below names ONE call site.
672
+ *
673
+ * The fallback matters as much as the extraction. It is what makes the drift arm of
674
+ * `_authoring_problems` unreachable — both the loaded copy and the checked literal come from
675
+ * one file through one regex, so a reference can never disagree with itself. A port that
676
+ * hardcoded the prompt WOULD disagree, which is what
677
+ * `doctor/the-loaded-copy-follows-the-plugin-rather-than-a-constant` exists to catch.
678
+ */
679
+ function loadLearnPromptHead() {
680
+ try {
681
+ const m = LEARN_PROMPT_RE.exec(readText(path.join(PLUGIN_SRC, 'geneseed-learn.js')));
682
+ if (m) return m[1];
683
+ } catch { /* OSError — fall through */ }
684
+ return 'Distil at most one durable, reusable memory from the notes below. '
685
+ + 'When in doubt, output exactly: NOTHING.';
686
+ }
687
+
688
+ /**
689
+ * `_harness_build._authoring_problems` — author-time gates on the source specs and plugins.
690
+ *
691
+ * Every agent/skill spec must carry a one-line `>` purpose blockquote as the FIRST content
692
+ * block after its title, or its `description:` on every host either renders empty or silently
693
+ * picks up the WRONG line; the learn-prompt literal must stay extractable; and, if node is on
694
+ * PATH, the plugins must pass `node --check`. Then three source-wide gates: the lifecycle
695
+ * registry describes exactly what `src/` provides, no credential ships, and every vendored
696
+ * folder carries an immutable upstream pin.
697
+ */
698
+ export function authoringProblems() {
699
+ const problems = [];
700
+ for (const folder of ['agents', 'skills']) {
701
+ const d = path.join(SRC, folder);
702
+ if (!isDir(d)) continue;
703
+ for (const spec of globSorted(d, (n) => n.endsWith('.md') && !n.startsWith('_'))) {
704
+ let text;
705
+ try { text = readText(spec); } catch (e) {
706
+ problems.push(`[authoring] ${folder}/${path.basename(spec)} unreadable: ${e.message}`);
707
+ continue;
708
+ }
709
+ if (!firstBlockquote(text)) {
710
+ problems.push(`[authoring] ${folder}/${path.basename(spec)} has no '>' purpose line `
711
+ + '(its OpenCode description would render empty)');
712
+ continue;
713
+ }
714
+ const reason = descBlockProblem(text);
715
+ if (reason) {
716
+ problems.push(`[authoring] ${folder}/${path.basename(spec)}: ${reason} — `
717
+ + 'desc_of() would silently extract the wrong description');
718
+ }
719
+ }
720
+ }
721
+ const plugin = path.join(PLUGIN_SRC, 'geneseed-learn.js');
722
+ let m = null;
723
+ try { m = LEARN_PROMPT_RE.exec(readText(plugin)); } catch { m = null; }
724
+ if (!m) {
725
+ // "the harness", not `harness.py`: both implementations load this literal, and the file
726
+ // the old wording named is the one this migration deletes. Moved on both sides at once —
727
+ // these two strings are byte-compared by the live doctor comparison.
728
+ problems.push('[authoring] LEARN_PROMPT_HEAD literal not found in '
729
+ + 'geneseed-learn.js — the harness would fall back (single source broken)');
730
+ } else if (m[1] !== loadLearnPromptHead()) {
731
+ problems.push('[authoring] LEARN_PROMPT_HEAD drifted between geneseed-learn.js '
732
+ + "and the harness's loaded copy");
733
+ }
734
+ const node = which('node');
735
+ if (node) {
736
+ for (const js of globSorted(PLUGIN_SRC, (n) => n.endsWith('.js'))) {
737
+ // THE ONE SPAWN. `node --check` and nothing else — see the module header, and
738
+ // the `inspect/checks-authoring.mjs` row of the spawn allow-list in
739
+ // `tests/unit/hook_cli.test.mjs`, which names this argv literally.
740
+ // `NO_WINDOW` because the reference's `run()` folds `CREATE_NO_WINDOW` into every
741
+ // CAPTURING spawn and this is one — and because this loop is the burst a user sees:
742
+ // one console window per plugin, every time the web daemon runs the doctor.
743
+ const r = spawnSync(node, ['--check', js], { encoding: 'utf-8', ...NO_WINDOW });
744
+ if (r.status !== 0) {
745
+ // `(stderr.strip().splitlines() or ["syntax error"])[-1]` — node's LAST line, which
746
+ // is its version banner rather than the SyntaxError. Faithful, and surprising enough
747
+ // that the cell asserts the prefix and never the version.
748
+ const lines = (r.stderr ?? '').trim().split('\n').filter((x) => x !== '');
749
+ const tail = lines.length ? lines[lines.length - 1] : 'syntax error';
750
+ problems.push(`[authoring] node --check failed for ${path.basename(js)}: ${tail}`);
751
+ }
752
+ }
753
+ }
754
+ problems.push(...registryProblems());
755
+ problems.push(...secretProblems());
756
+ problems.push(...vendorPinProblems());
757
+ problems.push(...constitutionProblems());
758
+ problems.push(...countTableProblems());
759
+ return problems;
760
+ }
761
+