geneseed 4.32.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +101 -0
- package/DESIGN.md +2 -2
- package/README.md +6 -5
- package/SHIPPED.md +4 -3
- package/adapters/bob/README.md +6 -5
- package/adapters/claude-code/README.md +4 -3
- package/adapters/claude-code/skills/geneseed/SKILL.md +1 -1
- package/adapters/openclaude/README.md +4 -3
- package/adapters/opencode/GLOBAL-HARNESS-SPEC.md +3 -1
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +2 -1
- package/adapters/opencode/README.md +18 -18
- package/adapters/opencode/plugins/geneseed-activity.js +57 -1
- package/adapters/opencode/plugins/geneseed-context.js +85 -18
- package/adapters/opencode/plugins/geneseed-guard.js +437 -76
- package/adapters/opencode/plugins/geneseed-learn.js +97 -23
- package/bin/geneseed-cli.mjs +17 -25
- package/bin/geneseed-hook.mjs +23 -8
- package/docs/DESIGN.md +175 -0
- package/docs/PRD.md +111 -0
- package/docs/README.md +3 -2
- package/docs/architecture.md +145 -0
- package/docs/concepts/agents.md +1 -1
- package/docs/concepts/collaboration.md +1 -1
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/exclusions.md +5 -5
- package/docs/concepts/footprint.md +1 -1
- package/docs/concepts/foreman-mode.md +2 -2
- package/docs/concepts/hooks.md +22 -8
- package/docs/concepts/host-matrix.md +2 -2
- package/docs/concepts/hosts.md +1 -1
- package/docs/concepts/kits.md +3 -1
- package/docs/concepts/ownership.md +1 -1
- package/docs/concepts/rules.md +15 -2
- package/docs/concepts/shared-tier.md +73 -0
- package/docs/concepts/skills.md +2 -2
- package/docs/concepts/themes.md +1 -1
- package/docs/extending.md +13 -12
- package/docs/guides/install-claude-code.md +1 -1
- package/docs/guides/install-opencode.md +1 -1
- package/docs/guides/migrate.md +8 -4
- package/docs/guides/project-context.md +2 -2
- package/docs/guides/setup-footprint.md +1 -1
- package/docs/guides/uninstall.md +2 -1
- package/docs/guides/upgrade-to-5.md +118 -0
- package/docs/guides/upgrade.md +21 -9
- package/docs/guides/wiki.md +3 -3
- package/docs/reference/env-context.md +5 -3
- package/docs/reference/environment.md +1 -1
- package/docs/reference/glossary.md +2 -0
- package/docs/reference/opencode-plugins.md +3 -3
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/plugin-context.md +1 -0
- package/docs/reference/plugin-guard.md +14 -6
- package/docs/reference/plugin-learn.md +13 -6
- package/docs/reference/troubleshoot-hooks.md +3 -3
- package/docs/reference/troubleshoot-update.md +14 -0
- package/docs/token-footprint.md +4 -3
- package/docs/understand/a-day.md +2 -2
- package/docs/understand/design-choices-install.md +2 -1
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/understand/machine-bob.md +2 -0
- package/docs/understand/machine-claude.md +7 -5
- package/docs/understand/machine-opencode.md +7 -5
- package/docs/understand/on-your-machine.md +4 -0
- package/docs/understand/take-it-out.md +1 -1
- package/docs/web-ui.md +135 -70
- package/harness.config.json +1 -1
- package/js/README.md +12 -7
- package/js/build/args.mjs +10 -8
- package/js/build/bundle.mjs +11 -13
- package/js/build/driver.mjs +66 -65
- package/js/build/emit-claude.mjs +22 -16
- package/js/build/emit-common.mjs +4 -5
- package/js/build/emit-opencode.mjs +22 -22
- package/js/build/fold.mjs +515 -0
- package/js/build/generate.mjs +41 -52
- package/js/build/render.mjs +115 -29
- package/js/build/rule-decide.mjs +273 -0
- package/js/build/source.mjs +4 -1
- package/js/build/stubs.mjs +70 -9
- package/js/build/version.mjs +10 -10
- package/js/cli-table.json +23 -83
- package/js/hosts/activity.mjs +2 -2
- package/js/hosts/geneseed-dir.mjs +1 -1
- package/js/hosts/hooks-context.mjs +389 -99
- package/js/hosts/hooks-learn.mjs +38 -7
- package/js/hosts/hooks-prims.mjs +4 -2
- package/js/hosts/hooks.mjs +114 -39
- package/js/hosts/hosts.mjs +150 -51
- package/js/hosts/installs.mjs +59 -171
- package/js/hosts/link.mjs +3 -5
- package/js/hosts/mcp.mjs +1 -1
- package/js/hosts/memory-files.mjs +219 -17
- package/js/hosts/ownership-gate.mjs +1 -1
- package/js/hosts/settings.mjs +18 -13
- package/js/hosts/shim.mjs +4 -33
- package/js/hosts/store-watch.mjs +191 -0
- package/js/inspect/checks-authoring.mjs +3 -3
- package/js/inspect/checks-build.mjs +45 -18
- package/js/inspect/checks-counts.mjs +4 -4
- package/js/inspect/checks-repo.mjs +13 -14
- package/js/inspect/cost.mjs +24 -2
- package/js/inspect/diff.mjs +123 -123
- package/js/inspect/doctor.mjs +22 -27
- package/js/inspect/excludes.mjs +181 -62
- package/js/inspect/inventory.mjs +22 -27
- package/js/inspect/registry.mjs +110 -32
- package/js/inspect/scan.mjs +5 -5
- package/js/inspect/status.mjs +141 -119
- package/js/inspect/validate.mjs +22 -24
- package/js/lib/fs.mjs +47 -50
- package/js/lib/json.mjs +10 -17
- package/js/lib/machine-dir.mjs +73 -0
- package/js/lib/paths.mjs +35 -33
- package/js/lib/proc.mjs +1 -1
- package/js/lib/prompt.mjs +19 -27
- package/js/lib/text.mjs +8 -12
- package/js/lib/udiff.mjs +11 -15
- package/js/loop/catalog.mjs +2 -3
- package/js/maintain/memory.mjs +17 -17
- package/js/maintain/migrate.mjs +120 -92
- package/js/maintain/setup.mjs +43 -32
- package/js/maintain/uninstall.mjs +43 -61
- package/js/maintain/update.mjs +200 -93
- package/js/ui/anim.mjs +21 -35
- package/js/ui/cli.mjs +36 -58
- package/js/ui/menu.mjs +22 -45
- package/js/ui/tui.mjs +27 -67
- package/js/web/actions.mjs +34 -34
- package/js/web/api.mjs +142 -79
- package/js/web/catalog.mjs +175 -46
- package/js/web/docs.mjs +33 -12
- package/js/web/doctor-worker.mjs +14 -0
- package/js/web/handler.mjs +16 -5
- package/js/web/routes.mjs +24 -22
- package/js/web/state.mjs +78 -19
- package/js/web/update-check.mjs +27 -12
- package/js/web/user-files.mjs +76 -104
- package/package.json +7 -4
- package/registry.json +48 -55
- package/src/AGENT.md.tmpl +13 -14
- package/src/agents/_self-improvement.md +1 -1
- package/src/agents/_template.md +1 -1
- package/src/agents/advocate.md +1 -1
- package/src/agents/architect.md +1 -1
- package/src/agents/developer.md +1 -1
- package/src/agents/devops-engineer.md +1 -1
- package/src/agents/docker-expert.md +1 -1
- package/src/agents/docs.md +1 -1
- package/src/agents/empiricist.md +1 -1
- package/src/agents/explorer.md +1 -1
- package/src/agents/framer.md +1 -1
- package/src/agents/historian.md +1 -1
- package/src/agents/kubernetes-specialist.md +1 -1
- package/src/agents/memory-curator.md +2 -2
- package/src/agents/operator.md +1 -1
- package/src/agents/performance.md +1 -1
- package/src/agents/pragmatist.md +1 -1
- package/src/agents/react-engineer.md +1 -1
- package/src/agents/react-reviewer.md +1 -1
- package/src/agents/researcher.md +1 -1
- package/src/agents/reviewer.md +1 -1
- package/src/agents/security.md +1 -1
- package/src/agents/skeptic.md +1 -1
- package/src/agents/spring-boot-engineer.md +1 -1
- package/src/agents/spring-reviewer.md +1 -1
- package/src/agents/spring-security.md +1 -1
- package/src/agents/steward.md +1 -1
- package/src/agents/tester.md +1 -1
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/memory/README.md +1 -1
- package/src/skills/_self-improvement.md +2 -2
- package/src/skills/daydream/SKILL.md +2 -2
- package/src/skills/daydream/instructions.md +1 -1
- package/src/skills/geneseed.md +1 -1
- package/src/skills/learn-mode.md +1 -2
- package/src/skills/profile.md +2 -2
- package/src/skills/rule/approve.md +75 -0
- package/src/skills/rule/consolidate.md +3 -3
- package/src/skills/rule.md +14 -5
- package/src/skills/skill-forge.md +1 -1
- package/src/skills/teach.md +29 -12
- package/src/skills/wiki.md +1 -1
- package/themes/_TEMPLATE.json +1 -2
- package/themes/biker.json +1 -2
- package/themes/commentator.json +1 -2
- package/themes/cyberpunk.json +1 -2
- package/themes/gamer.json +1 -2
- package/themes/imperial.json +1 -2
- package/themes/joker.json +1 -2
- package/themes/marvin.json +1 -2
- package/themes/mean.json +1 -2
- package/themes/military.json +1 -2
- package/themes/neutral.json +1 -2
- package/themes/pirate.json +1 -2
- package/themes/sports.json +1 -2
- package/themes/verstappen.json +1 -2
- package/themes/wizard.json +1 -2
- package/web/dist/assets/Activity-Ci4PZco3.js +1 -0
- package/web/dist/assets/ActivityDetail-C8hroCND.js +1 -0
- package/web/dist/assets/AgentGlyph-k6o3gCM1.js +1 -0
- package/web/dist/assets/Bonsai-C1iBAt4v.js +1 -0
- package/web/dist/assets/{CopyButton-C5Li6awl.js → CopyButton-DJ3a4N88.js} +1 -1
- package/web/dist/assets/Dashboard-C_On4KXw.js +2 -0
- package/web/dist/assets/Docs-Kffdg5uV.js +5 -0
- package/web/dist/assets/GreenhouseView-k56_cBSF.js +1 -0
- package/web/dist/assets/Installs-DtEKLC9h.js +3 -0
- package/web/dist/assets/JournalView-RQnk5l7I.js +1 -0
- package/web/dist/assets/Kits-CXkEBpnf.js +1 -0
- package/web/dist/assets/Laws-DhhIVqmh.js +3 -0
- package/web/dist/assets/Library-CAUiEoJo.js +3 -0
- package/web/dist/assets/{Loops-CzitjxGV.js → Loops-LKD8mF4E.js} +2 -2
- package/web/dist/assets/{Markdown-C4S4tTA7.js → Markdown-0ORz7tAc.js} +21 -21
- package/web/dist/assets/OperatorHudView-CM5jNPwL.js +1 -0
- package/web/dist/assets/Personal-B6Uoly3C.js +2 -0
- package/web/dist/assets/{RailCats-D5weYPCS.js → RailCats-DQxxYBEP.js} +1 -1
- package/web/dist/assets/Settings-BTe6-wda.js +1 -0
- package/web/dist/assets/Tabs-CbdDWTp_.js +1 -0
- package/web/dist/assets/api-D_r0Jtla.js +1 -0
- package/web/dist/assets/controls-D4wmg_pl.js +1 -0
- package/web/dist/assets/index-HfGmYXab.js +3 -0
- package/web/dist/assets/index-ao3M-Fhm.css +1 -0
- package/web/dist/assets/motion-RlUl1osO.js +1 -0
- package/web/dist/assets/{sections-ChwaobfW.js → sections-CtFz7HFH.js} +1 -1
- package/web/dist/index.html +5 -5
- package/src/skills/quiz.md +0 -44
- package/web/dist/assets/Activity-Bjy64wHC.js +0 -1
- package/web/dist/assets/ActivityDetail-B0AaipP8.js +0 -1
- package/web/dist/assets/Bonsai-CJniRqaH.js +0 -1
- package/web/dist/assets/Dashboard-B-6DTmae.js +0 -2
- package/web/dist/assets/Docs-LRc30XL9.js +0 -5
- package/web/dist/assets/GreenhouseView-CcoYlaWo.js +0 -1
- package/web/dist/assets/Installs-dp1epTcE.js +0 -3
- package/web/dist/assets/JournalView-nFP4poCf.js +0 -1
- package/web/dist/assets/KitApply-DwyZUj57.js +0 -1
- package/web/dist/assets/Kits-C0IEdZXe.js +0 -1
- package/web/dist/assets/Laws-CkykmQWu.js +0 -3
- package/web/dist/assets/Library-Guh9HBZU.js +0 -2
- package/web/dist/assets/OperatorHudView-DLGNulIY.js +0 -1
- package/web/dist/assets/Personal-BMtberL8.js +0 -2
- package/web/dist/assets/Tabs-uYJqfuQt.js +0 -1
- package/web/dist/assets/api-BxjLd7Qd.js +0 -1
- package/web/dist/assets/index-DA7BiaE5.js +0 -3
- package/web/dist/assets/index-dbbDGFDq.css +0 -1
- package/web/dist/assets/motion-Bccx3zE8.js +0 -1
package/js/web/catalog.mjs
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { existsSync, readdirSync } from 'node:fs';
|
|
16
16
|
import path from 'node:path';
|
|
17
17
|
|
|
18
|
-
import { GLOBAL_MANIFEST, resolvePath } from '../hosts/hosts.mjs';
|
|
18
|
+
import { GLOBAL_MANIFEST, isGlobalInstall, resolvePath } from '../hosts/hosts.mjs';
|
|
19
19
|
import { doctrinesForBuild, excludedRulesOfDir, readMaybe } from '../hosts/installs.mjs';
|
|
20
20
|
import { frontmatter, readFacts } from '../hosts/memory-files.mjs';
|
|
21
21
|
import {
|
|
@@ -23,10 +23,12 @@ import {
|
|
|
23
23
|
} from '../inspect/inventory.mjs';
|
|
24
24
|
import { firstBlockquote } from '../hosts/native.mjs';
|
|
25
25
|
import { readText, withDiscardableStderr, isDir, isFile } from '../lib/fs.mjs';
|
|
26
|
+
import { WIKI_NAMES, sharedPaths } from '../lib/machine-dir.mjs';
|
|
26
27
|
import { comparePaths, normcase, within } from '../lib/paths.mjs';
|
|
27
28
|
import { stripWhitespace } from '../lib/text.mjs';
|
|
28
29
|
import { readJsonc } from '../hosts/settings.mjs';
|
|
29
30
|
import { SRC, loadKits, makeCfg, ruleCanon, ruleSummaries } from '../build/source.mjs';
|
|
31
|
+
import { RESERVED_STEMS } from '../hosts/memory-files.mjs';
|
|
30
32
|
import { loadTheme } from '../build/render.mjs';
|
|
31
33
|
|
|
32
34
|
/** A requested catalog section or item that does not exist. */
|
|
@@ -157,10 +159,30 @@ export function inventoryFor(state) {
|
|
|
157
159
|
// ---- the catalog stores overview counts ---------------------------------------------------
|
|
158
160
|
|
|
159
161
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
+
* The shared tier's paths when `state` is a GLOBAL install and the tier exists, else `null`.
|
|
163
|
+
* A global install reads the tier (hooks-context does the same); editing a host seed the hook
|
|
164
|
+
* layers beneath the shared file would change nothing the agent sees. A project install, or an
|
|
165
|
+
* account with no home directory, stays on its own files. THE ONE PREDICATE: memory, rules,
|
|
166
|
+
* profile and the wiki manifest all ask here.
|
|
167
|
+
*
|
|
168
|
+
* THE TIER IS WHAT IT HOLDS, never the folder around it: a 4.x machine has that folder for
|
|
169
|
+
* `installs.json`, `bricks/` and `loops/`, and `default-install.json` can create it. `memory/` is
|
|
170
|
+
* `sharedStoreFor`'s test (js/hosts/hooks-learn.mjs); a session file counts too, because the context
|
|
171
|
+
* hook reads each one that exists, and rules with no `memory/` still bind.
|
|
162
172
|
*/
|
|
163
|
-
export
|
|
173
|
+
export function tierOf(state) {
|
|
174
|
+
try {
|
|
175
|
+
if (!isGlobalInstall(null, state.target)) return null;
|
|
176
|
+
const tier = sharedPaths();
|
|
177
|
+
return isDir(tier.memory) || [tier.rules, tier.profile, tier.wiki].some(isFile) ? tier : null;
|
|
178
|
+
} catch { return null; }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Always `<target>/memory` (a global install: the tier's) — never the CWD-scanning resolver. The ONE
|
|
183
|
+
* copy: `actions.mjs` and `user-files.mjs` delete and promote facts in the same directory this lists.
|
|
184
|
+
*/
|
|
185
|
+
export const memoryDir = (state, tier = tierOf(state)) => tier?.memory ?? path.join(state.target, 'memory');
|
|
164
186
|
const notebookDir = (state) => path.join(state.target, 'notebook');
|
|
165
187
|
|
|
166
188
|
/**
|
|
@@ -183,16 +205,26 @@ function globMd(dir) {
|
|
|
183
205
|
/** Filename without its extension — single owner, imported by `js/web/activity.mjs` too. */
|
|
184
206
|
export const stemOf = (name) => name.slice(0, name.length - path.extname(name).length);
|
|
185
207
|
|
|
208
|
+
/**
|
|
209
|
+
* THE ONE ANSWER TO "IS THIS FILE AN ENTRY": a folder's index (`MEMORY.md`, `NOTEBOOK.md`) and its
|
|
210
|
+
* README, any case, are its furniture. They stay readable by name (`apiItem`; Personal reads the
|
|
211
|
+
* map) but no list holds them, so a list and its count cannot disagree.
|
|
212
|
+
*/
|
|
213
|
+
export const isFurniture = (file, index) => {
|
|
214
|
+
const stem = stemOf(file).toLowerCase();
|
|
215
|
+
return stem === index || (stem !== 'memory' && RESERVED_STEMS.has(stem));
|
|
216
|
+
};
|
|
217
|
+
|
|
186
218
|
/**
|
|
187
219
|
* Each fact row carries the `topic` the store files it under, so the console can group the list.
|
|
188
220
|
* Read through `readFacts`, the store's own reader, so the slug rule (`topic:`, else `type:`,
|
|
189
|
-
* else `misc`) has one home.
|
|
221
|
+
* else `misc`) has one home.
|
|
190
222
|
*/
|
|
191
223
|
export function memoryItems(state) {
|
|
192
224
|
const d = memoryDir(state);
|
|
193
225
|
if (!isDir(d)) return [];
|
|
194
226
|
const facts = readFacts(d);
|
|
195
|
-
return globMd(d).map((n) => {
|
|
227
|
+
return globMd(d).filter((n) => !isFurniture(n, 'memory')).map((n) => {
|
|
196
228
|
const p = path.join(d, n);
|
|
197
229
|
const [fm] = frontmatter(readMaybe(p) ?? '');
|
|
198
230
|
const stem = stemOf(n);
|
|
@@ -209,34 +241,39 @@ export function memoryItems(state) {
|
|
|
209
241
|
export function notebookItems(state) {
|
|
210
242
|
const d = notebookDir(state);
|
|
211
243
|
if (!isDir(d)) return [];
|
|
212
|
-
return globMd(d).map((n) => ({
|
|
244
|
+
return globMd(d).filter((n) => !isFurniture(n, 'notebook')).map((n) => ({
|
|
213
245
|
name: stemOf(n), title: stemOf(n), desc: '', source: resolvePath(path.join(d, n)),
|
|
214
246
|
}));
|
|
215
247
|
}
|
|
216
248
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
* prefix: the build renames it on the next emit, and until then it is still read (no end date; see `LEGACY_WIKI_FILES`).
|
|
220
|
-
*/
|
|
221
|
-
const WIKI_NAMES = ['geneseed-wiki.jsonc', 'wiki.jsonc'];
|
|
249
|
+
// The wiki manifest's names come from `WIKI_NAMES` (machine-dir.mjs), the one list every reader
|
|
250
|
+
// shares: this one used to stop at `wiki.jsonc`, so a `wiki.json` install showed no wiki (B5).
|
|
222
251
|
const WIKI_META = ['Wiki manifest', 'your machine-wide knowledge base(s)'];
|
|
223
252
|
|
|
224
253
|
/** The two setup manifests, in listing order (the wiki under either of its names). */
|
|
225
254
|
const CONFIG_META = {
|
|
226
255
|
'context.json': ['Project context', 'what the agent loads for this project'],
|
|
227
|
-
|
|
228
|
-
'wiki.jsonc': WIKI_META,
|
|
256
|
+
...Object.fromEntries(WIKI_NAMES.map((n) => [n, WIKI_META])),
|
|
229
257
|
};
|
|
230
258
|
|
|
231
|
-
/**
|
|
232
|
-
|
|
259
|
+
/**
|
|
260
|
+
* The wiki manifest's file, under whichever name it has, or `null`: the tier's when a global
|
|
261
|
+
* install has one, else the one beside the bundle.
|
|
262
|
+
*/
|
|
263
|
+
function wikiFile(state) {
|
|
264
|
+
for (const dir of [tierOf(state)?.root, state.target]) {
|
|
265
|
+
const hit = dir && WIKI_NAMES.find((n) => isFile(path.join(dir, n)));
|
|
266
|
+
if (hit) return path.join(dir, hit);
|
|
267
|
+
}
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
233
270
|
|
|
234
271
|
export function configItems(state) {
|
|
235
272
|
const out = [];
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
273
|
+
const wiki = wikiFile(state);
|
|
274
|
+
for (const p of [path.join(state.target, 'context.json'), wiki]) {
|
|
275
|
+
if (!p || !isFile(p)) continue;
|
|
276
|
+
const fname = path.basename(p);
|
|
240
277
|
const [title, desc] = CONFIG_META[fname] ?? [fname, ''];
|
|
241
278
|
out.push({ name: fname, title, desc, type: 'config', kind: 'manifest',
|
|
242
279
|
source: resolvePath(p) });
|
|
@@ -283,8 +320,7 @@ function wikiPath(p) {
|
|
|
283
320
|
*/
|
|
284
321
|
function wikiManifest(state) {
|
|
285
322
|
const cand = process.env.GENESEED_WIKI;
|
|
286
|
-
const
|
|
287
|
-
const p = cand ? wikiPath(cand) : name && path.join(state.target, name);
|
|
323
|
+
const p = cand ? wikiPath(cand) : wikiFile(state);
|
|
288
324
|
if (!p || !isFile(p)) return [];
|
|
289
325
|
const cfg = mcpLoad(p);
|
|
290
326
|
const wikis = cfg.wikis;
|
|
@@ -476,10 +512,7 @@ export const SECTIONS = ['agents', 'skills', 'laws', 'memory', 'notebook', 'wiki
|
|
|
476
512
|
* address the canon renders now (`ruleSummaries`, `js/build/source.mjs`). `desc` stays empty:
|
|
477
513
|
* the search index reads `desc`, and the summary is display copy, not a description to match.
|
|
478
514
|
*/
|
|
479
|
-
function constitutionItems(inv) {
|
|
480
|
-
const said = ruleSummaries(SRC);
|
|
481
|
-
const summary = new Map(ruleCanon(SRC).rules.map((r) => [
|
|
482
|
-
r.kind === 'LAW' ? r.label : `${r.pack}.${r.n}`, said.get(r.id) ?? '']));
|
|
515
|
+
function constitutionItems(inv, summary = ruleSummaryMap()) {
|
|
483
516
|
return [
|
|
484
517
|
...(inv.ontology ?? []).map((e) => ({ name: `ont:${e.id}`, title: e.title, desc: '',
|
|
485
518
|
tier: 'ontology' })),
|
|
@@ -505,6 +538,13 @@ function constitutionItems(inv) {
|
|
|
505
538
|
];
|
|
506
539
|
}
|
|
507
540
|
|
|
541
|
+
/** Each rule's address to its summary line: read off `src/`, so a loop over installs reads it once. */
|
|
542
|
+
function ruleSummaryMap() {
|
|
543
|
+
const said = ruleSummaries(SRC);
|
|
544
|
+
return new Map(ruleCanon(SRC).rules.map((r) => [
|
|
545
|
+
r.kind === 'LAW' ? r.label : `${r.pack}.${r.n}`, said.get(r.id) ?? '']));
|
|
546
|
+
}
|
|
547
|
+
|
|
508
548
|
/** `Map<'skills/x' | 'agents/y', kit>` from the shipped manifests; a broken manifest means no badges, not a 500. */
|
|
509
549
|
function kitOwners() {
|
|
510
550
|
const owner = new Map();
|
|
@@ -529,12 +569,24 @@ function tierNouns(theme) {
|
|
|
529
569
|
}
|
|
530
570
|
|
|
531
571
|
/**
|
|
532
|
-
* The sections listed across every install (`fleet`), not off one: skills, agents,
|
|
533
|
-
*
|
|
534
|
-
* a promote names its own).
|
|
535
|
-
*
|
|
572
|
+
* The sections listed across every install (`fleet`), not off one: skills, agents, the personal
|
|
573
|
+
* memory and notebook, the wiki and the setup files (each entry tagged with the installs that
|
|
574
|
+
* hold it, so a forget or a promote names its own). Only the constitution stays one install's:
|
|
575
|
+
* its page is a set of switches on the picked install.
|
|
536
576
|
*/
|
|
537
|
-
export const FLEET_SECTIONS = ['agents', 'skills', 'memory', 'notebook'];
|
|
577
|
+
export const FLEET_SECTIONS = ['agents', 'skills', 'memory', 'notebook', 'wiki', 'config'];
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* What one install of a fleet reads, or nothing when it cannot be read: a retired theme or a broken
|
|
581
|
+
* manifest on one install must not take every list and count down with it. A lone state (`install`
|
|
582
|
+
* null) has no others to protect, so its failure stays the request's.
|
|
583
|
+
*/
|
|
584
|
+
export function orSkip(v, read) {
|
|
585
|
+
try { return read(); } catch (e) {
|
|
586
|
+
if (v.install === null) throw e;
|
|
587
|
+
return [];
|
|
588
|
+
}
|
|
589
|
+
}
|
|
538
590
|
|
|
539
591
|
/**
|
|
540
592
|
* A per-install item list (`read(state)`) over `fleet`, one row per name with the `installs` that
|
|
@@ -543,8 +595,9 @@ export const FLEET_SECTIONS = ['agents', 'skills', 'memory', 'notebook'];
|
|
|
543
595
|
*/
|
|
544
596
|
function fleetItems(fleet, read) {
|
|
545
597
|
const rows = new Map();
|
|
546
|
-
for (const
|
|
547
|
-
|
|
598
|
+
for (const v of fleet) {
|
|
599
|
+
const { install, state } = v;
|
|
600
|
+
for (const it of orSkip(v, () => read(state))) {
|
|
548
601
|
let r = rows.get(it.name);
|
|
549
602
|
if (r === undefined) rows.set(it.name, r = { ...it, installs: [] });
|
|
550
603
|
if (install !== null) r.installs.push(install);
|
|
@@ -563,8 +616,9 @@ function fleetItems(fleet, read) {
|
|
|
563
616
|
*/
|
|
564
617
|
function fleetEntries(fleet, section) {
|
|
565
618
|
const rows = new Map();
|
|
566
|
-
for (const
|
|
567
|
-
|
|
619
|
+
for (const v of fleet) {
|
|
620
|
+
const { install, state } = v;
|
|
621
|
+
for (const e of orSkip(v, () => state.inventory[section])) {
|
|
568
622
|
let r = rows.get(e.name);
|
|
569
623
|
if (r === undefined) rows.set(e.name, r = { e, installs: [] });
|
|
570
624
|
if (install !== null) r.installs.push(install);
|
|
@@ -573,14 +627,39 @@ function fleetEntries(fleet, section) {
|
|
|
573
627
|
return [...rows.values()].sort((a, b) => (a.e.name < b.e.name ? -1 : a.e.name > b.e.name ? 1 : 0));
|
|
574
628
|
}
|
|
575
629
|
|
|
630
|
+
/** The fleet keys of the installs that read the shared tier: their memory is one store. */
|
|
631
|
+
const sharedInstalls = (fleet) => fleet
|
|
632
|
+
.filter((v) => v.install !== null && tierOf(v.state) !== null).map((v) => v.install);
|
|
633
|
+
|
|
634
|
+
/** `fleet` with the tier's readers folded into the first: one store is listed once, not per host. */
|
|
635
|
+
function memoryFleet(fleet) {
|
|
636
|
+
const [, ...merged] = sharedInstalls(fleet);
|
|
637
|
+
return fleet.filter((v) => !merged.includes(v.install));
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** `fleet` with one view per wiki manifest: the machine's shared one is walked once, not per host. */
|
|
641
|
+
function wikiFleet(fleet) {
|
|
642
|
+
const seen = new Set();
|
|
643
|
+
return fleet.filter((v) => {
|
|
644
|
+
const f = String(wikiFile(v.state));
|
|
645
|
+
return !seen.has(f) && seen.add(f);
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** The fleet keys of the installs whose wiki manifest is the shared tier's. */
|
|
650
|
+
const sharedWiki = (fleet) => fleet.filter((v) => {
|
|
651
|
+
const tier = v.install !== null ? tierOf(v.state) : null;
|
|
652
|
+
const file = tier && wikiFile(v.state);
|
|
653
|
+
return Boolean(file) && path.dirname(file) === tier.root;
|
|
654
|
+
}).map((v) => v.install);
|
|
655
|
+
|
|
576
656
|
/**
|
|
577
657
|
* `fleet` defaults to `state` alone, which answers as one install did before the console
|
|
578
658
|
* listed the fleet; the `/api/catalog/` route passes every active install for `FLEET_SECTIONS`.
|
|
579
659
|
*/
|
|
580
|
-
export function apiCatalog(state, section, fleet = [{ install: null, state }]) {
|
|
660
|
+
export function apiCatalog(state, section, fleet = [{ install: null, state }], owner = kitOwners()) {
|
|
581
661
|
if (!SECTIONS.includes(section)) throw new NotFound(section);
|
|
582
662
|
let items;
|
|
583
|
-
const owner = kitOwners();
|
|
584
663
|
if (section === 'agents') {
|
|
585
664
|
items = fleetEntries(fleet, 'agents').map(({ e, installs }) => ({ name: e.name, title: e.name, desc: e.desc,
|
|
586
665
|
source: e.source ?? null, status: e.status ?? 'unknown', kit: owner.get(`agent:${e.name}`) ?? null, installs }));
|
|
@@ -590,17 +669,50 @@ export function apiCatalog(state, section, fleet = [{ install: null, state }]) {
|
|
|
590
669
|
} else if (section === 'laws') {
|
|
591
670
|
return { section, items: constitutionItems(state.inventory), nouns: tierNouns(state.theme) };
|
|
592
671
|
} else if (section === 'memory') {
|
|
593
|
-
items
|
|
672
|
+
return { section, items: fleetItems(memoryFleet(fleet), memoryItems),
|
|
673
|
+
sharedInstalls: sharedInstalls(fleet) };
|
|
594
674
|
} else if (section === 'notebook') {
|
|
595
675
|
items = fleetItems(fleet, notebookItems);
|
|
596
676
|
} else if (section === 'wiki') {
|
|
597
|
-
items
|
|
677
|
+
return { section, items: fleetItems(wikiFleet(fleet), wikiItems), sharedInstalls: sharedWiki(fleet) };
|
|
598
678
|
} else {
|
|
599
|
-
items = configItems
|
|
679
|
+
items = fleetItems(fleet, configItems);
|
|
600
680
|
}
|
|
601
681
|
return { section, items };
|
|
602
682
|
}
|
|
603
683
|
|
|
684
|
+
/**
|
|
685
|
+
* THE ONE DEFINITION OF EVERY COUNT THE CONSOLE PRINTS: each is the size of the list its page
|
|
686
|
+
* shows, over every install, deduped by name. Read off `apiCatalog` itself, so a list and its count
|
|
687
|
+
* cannot part; `tests/unit/web_counts.test.mjs` holds them together. `laws` stays the invariants.
|
|
688
|
+
* The constitution counts what its page lists, on or off: a rule one install excludes is still a
|
|
689
|
+
* row there, with its switch. `doctrines.active` is the packs any install built in. An install that
|
|
690
|
+
* cannot be read is skipped (`orSkip`), so the rest still count.
|
|
691
|
+
*/
|
|
692
|
+
export function fleetCounts(state, fleet = [{ install: null, state }]) {
|
|
693
|
+
const owner = kitOwners();
|
|
694
|
+
const listed = (sec) => apiCatalog(state, sec, fleet, owner).items.length;
|
|
695
|
+
const summary = ruleSummaryMap();
|
|
696
|
+
const items = fleet.flatMap((v) => orSkip(v, () => constitutionItems(v.state.inventory, summary)));
|
|
697
|
+
const named = (tier) => new Set(items.filter((it) => it.tier === tier).map((it) => it.name)).size;
|
|
698
|
+
const packs = fleet.flatMap((v) => orSkip(v, () => v.state.inventory.doctrines ?? []));
|
|
699
|
+
return {
|
|
700
|
+
agents: listed('agents'),
|
|
701
|
+
skills: listed('skills'),
|
|
702
|
+
laws: named('invariant'),
|
|
703
|
+
ontology: named('ontology'),
|
|
704
|
+
doctrines: {
|
|
705
|
+
active: new Set(packs.filter((p) => p.active).map((p) => p.pack)).size,
|
|
706
|
+
total: new Set(packs.map((p) => p.pack)).size,
|
|
707
|
+
rules: named('doctrine'),
|
|
708
|
+
},
|
|
709
|
+
memory: listed('memory'),
|
|
710
|
+
notebook: listed('notebook'),
|
|
711
|
+
wiki: listed('wiki'),
|
|
712
|
+
config: listed('config'),
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
|
|
604
716
|
/**
|
|
605
717
|
* One entry. A skill or agent is served from ONE install's copy, since each install renders in
|
|
606
718
|
* its own theme and footprint: the install the request named (`state` is then its view, found
|
|
@@ -648,27 +760,44 @@ export function apiItem(state, type, name, fleet = [{ install: null, state }]) {
|
|
|
648
760
|
flatName(name);
|
|
649
761
|
const fileOf = (st) => path.join(type === 'notebook' ? notebookDir(st) : memoryDir(st), `${name}.md`);
|
|
650
762
|
// As a skill: the named install's copy, else the first holder in fleet order.
|
|
651
|
-
const has = fleet.filter((v) => isFile(fileOf(v.state)));
|
|
763
|
+
const has = (type === 'memory' ? memoryFleet(fleet) : fleet).filter((v) => isFile(fileOf(v.state)));
|
|
652
764
|
const from = fleet.find((v) => v.state === state) ?? (state.pinned ? { install: null, state } : has[0]);
|
|
653
765
|
const p = from ? fileOf(from.state) : null;
|
|
654
766
|
if (!p || !isFile(p)) throw new NotFound(name);
|
|
655
767
|
const body = readMaybe(p) ?? '';
|
|
656
768
|
return { type, name, title: name, desc: '', body,
|
|
657
769
|
links: resolveLinks(from.state, body), source: resolvePath(p),
|
|
658
|
-
install: from.install, installs: has.map((v) => v.install).filter((k) => k !== null)
|
|
770
|
+
install: from.install, installs: has.map((v) => v.install).filter((k) => k !== null),
|
|
771
|
+
shared: type === 'memory' && tierOf(from.state) !== null };
|
|
772
|
+
}
|
|
773
|
+
if (type === 'wiki') {
|
|
774
|
+
// As a skill: the named install's copy, else the first manifest that has the page.
|
|
775
|
+
const named = fleet.find((v) => v.state === state) ?? (state.pinned ? { state } : null);
|
|
776
|
+
for (const v of named ? [named] : wikiFleet(fleet)) {
|
|
777
|
+
try { return apiWikiItem(v.state, name); } catch (e) { if (!(e instanceof NotFound)) throw e; }
|
|
778
|
+
}
|
|
779
|
+
throw new NotFound(name);
|
|
659
780
|
}
|
|
660
|
-
if (type === 'wiki') return apiWikiItem(state, name);
|
|
661
781
|
if (type === 'config') {
|
|
662
782
|
// THE ALLOWLIST, NOT `flatName`: a flat name still reached every top-level file of the
|
|
663
783
|
// install — `.geneseed-web.json` (this daemon's own CSRF token) and `settings.json` among
|
|
664
784
|
// them — over a GET that carries no token. Only the manifests the catalogue lists can open.
|
|
665
785
|
if (!Object.hasOwn(CONFIG_META, name)) throw new NotFound(name);
|
|
666
|
-
const
|
|
667
|
-
|
|
786
|
+
const fileOf = (st) => (WIKI_NAMES.includes(name) ? wikiFile(st) : path.join(st.target, name));
|
|
787
|
+
const holds = (st) => {
|
|
788
|
+
const f = fileOf(st);
|
|
789
|
+
return Boolean(f) && isFile(f) && path.basename(f) === name;
|
|
790
|
+
};
|
|
791
|
+
// As a skill: the named install's copy, else the first holder in fleet order.
|
|
792
|
+
const has = fleet.filter((v) => holds(v.state));
|
|
793
|
+
const from = fleet.find((v) => v.state === state) ?? (state.pinned ? { install: null, state } : has[0]);
|
|
794
|
+
if (!from || !holds(from.state)) throw new NotFound(name);
|
|
795
|
+
const p = fileOf(from.state);
|
|
668
796
|
const raw = readMaybe(p) ?? '';
|
|
669
797
|
const [title, desc] = CONFIG_META[name];
|
|
670
798
|
return { type, name, title, desc, manifest: configManifest(name, p),
|
|
671
|
-
body: `\`\`\`json\n${raw}\n\`\`\``, links: [], source: resolvePath(p)
|
|
799
|
+
body: `\`\`\`json\n${raw}\n\`\`\``, links: [], source: resolvePath(p),
|
|
800
|
+
install: from.install, installs: has.map((v) => v.install).filter((k) => k !== null) };
|
|
672
801
|
}
|
|
673
802
|
throw new NotFound(type);
|
|
674
803
|
}
|
package/js/web/docs.mjs
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
import { readdirSync } from 'node:fs';
|
|
19
19
|
import path from 'node:path';
|
|
20
20
|
|
|
21
|
-
import { DOCS, DOC_FOLDERS, ROOT, THEMES, resolveRuleIds } from '../build/source.mjs';
|
|
22
|
-
import { STRUCTURE, substitute } from '../build/render.mjs';
|
|
21
|
+
import { DOCS, DOC_FOLDERS, ROOT, THEMES, makeCfg, resolveRuleIds } from '../build/source.mjs';
|
|
22
|
+
import { STRUCTURE, effectiveTheme, pathTokens, substitute } from '../build/render.mjs';
|
|
23
23
|
import { cliReference } from '../ui/cli.mjs';
|
|
24
24
|
import { readJsonMaybe, readMaybe } from '../hosts/installs.mjs';
|
|
25
25
|
import { resolvePath } from '../hosts/hosts.mjs';
|
|
@@ -30,6 +30,7 @@ import { WHITESPACE, stripWhitespace } from '../lib/text.mjs';
|
|
|
30
30
|
import { statusData } from '../inspect/status.mjs';
|
|
31
31
|
import { originDisplay } from '../maintain/update.mjs';
|
|
32
32
|
import { NotFound, deployed, resolveLinks } from './api.mjs';
|
|
33
|
+
import { tierOf } from './catalog.mjs';
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* A docs page split into its frontmatter map and its body.
|
|
@@ -124,7 +125,7 @@ export function docGroups() {
|
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
/** The heading a page without a `section:` is listed under, inside its part. */
|
|
127
|
-
|
|
128
|
+
const GENERAL_SECTION = 'General';
|
|
128
129
|
|
|
129
130
|
/**
|
|
130
131
|
* A page's `section:` frontmatter, or `General`. Anything but a non-empty string falls back
|
|
@@ -168,7 +169,7 @@ function tableCells(line) {
|
|
|
168
169
|
* its richer view from the same rows rather than from a second copy that could drift. A row
|
|
169
170
|
* with the wrong number of cells is a malformed table, so the whole answer is `null`.
|
|
170
171
|
*/
|
|
171
|
-
|
|
172
|
+
function tableRows(body, head) {
|
|
172
173
|
const lines = body.split('\n');
|
|
173
174
|
for (let i = 0; i + 1 < lines.length; i += 1) {
|
|
174
175
|
if (!lines[i].trim().startsWith('|')) continue;
|
|
@@ -186,7 +187,7 @@ export function tableRows(body, head) {
|
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
const MAP_HEAD = ['piece', 'what it does for you', 'kind', 'cost', 'turn it off'];
|
|
189
|
-
|
|
190
|
+
const MAP_KINDS = ['enforced', 'automatic', 'asked', 'on demand'];
|
|
190
191
|
|
|
191
192
|
/** The "what lands on your machine" table as rows, or `null` when absent or malformed. */
|
|
192
193
|
export function parseMapTable(body) {
|
|
@@ -413,6 +414,16 @@ function splitLines(s) {
|
|
|
413
414
|
return parts;
|
|
414
415
|
}
|
|
415
416
|
|
|
417
|
+
/**
|
|
418
|
+
* Whether the host changes what this page says: a page-level tag, or a host block in its text. The
|
|
419
|
+
* console shows its host switch only on these pages, since anywhere else it would switch nothing.
|
|
420
|
+
*/
|
|
421
|
+
const pageVaries = (p) => Boolean(p.harness)
|
|
422
|
+
|| HARNESS_HINT_RE.test(p.source ? readDocSource(p.source) : p.body ?? '');
|
|
423
|
+
|
|
424
|
+
/** `?harness=all`: the Docs page's own menu, every host's pages, each row naming its `hosts`. */
|
|
425
|
+
const ALL_HOSTS = 'all';
|
|
426
|
+
|
|
416
427
|
/** Pure; the registry is never mutated. */
|
|
417
428
|
function visibleGroups(harnessName) {
|
|
418
429
|
const groups = [];
|
|
@@ -469,15 +480,23 @@ function themeWords(theme) {
|
|
|
469
480
|
}
|
|
470
481
|
|
|
471
482
|
/**
|
|
472
|
-
* A `src/` file as
|
|
483
|
+
* A `src/` file as this install would render it: rule citations named, then the deployed theme's
|
|
473
484
|
* words (neutral underneath, for a key the theme lacks) and the fixed STRUCTURE substituted —
|
|
474
485
|
* the build's own functions, so the page cannot drift from what lands on disk. Only string
|
|
475
486
|
* words go in: `substitute` throws on any other value, and a theme's AGENT_COLORS is a dict.
|
|
487
|
+
* The tier's paths and note come from the same render a global emit runs: a page read on a
|
|
488
|
+
* machine with no tier, or from a project install, stays relative and carries no note.
|
|
476
489
|
*/
|
|
477
|
-
function renderSource(text,
|
|
478
|
-
const words = Object.entries({ ...themeWords('neutral'), ...themeWords(theme) })
|
|
490
|
+
function renderSource(text, state) {
|
|
491
|
+
const words = Object.entries({ ...themeWords('neutral'), ...themeWords(state.theme) })
|
|
479
492
|
.filter(([, v]) => typeof v === 'string');
|
|
480
|
-
|
|
493
|
+
const root = tierOf(state)?.root;
|
|
494
|
+
const sharedRoot = root ? String(root).split(path.sep).join('/') : null;
|
|
495
|
+
return substitute(resolveRuleIds(text), {
|
|
496
|
+
...Object.fromEntries(words), ...STRUCTURE, ...pathTokens(STRUCTURE, sharedRoot),
|
|
497
|
+
SHARED_STORE_NOTE: sharedRoot
|
|
498
|
+
? effectiveTheme(makeCfg(), 'neutral', { sharedRoot }).SHARED_STORE_NOTE : '',
|
|
499
|
+
});
|
|
481
500
|
}
|
|
482
501
|
|
|
483
502
|
/** The deployed theme's words beside the neutral ones, from `docs/reference/glossary.md`. */
|
|
@@ -540,11 +559,13 @@ function about(state) {
|
|
|
540
559
|
}
|
|
541
560
|
|
|
542
561
|
export function apiDocs(state, harnessName = null) {
|
|
543
|
-
const
|
|
544
|
-
const
|
|
562
|
+
const all = harnessName === ALL_HOSTS;
|
|
563
|
+
const hn = normHarness(all ? null : harnessName, state);
|
|
564
|
+
const groups = (all ? docGroups() : visibleGroups(hn)).map((g) => ({
|
|
545
565
|
id: g.id,
|
|
546
566
|
label: g.label,
|
|
547
567
|
pages: g.pages.map((p) => ({ id: p.id, title: p.title, kind: p.kind, section: p.section,
|
|
568
|
+
varies: pageVaries(p), hosts: HARNESSES.filter((h) => harnessShows(p.harness, h)),
|
|
548
569
|
...(typeof p.description === 'string' ? { description: p.description } : {}) })),
|
|
549
570
|
}));
|
|
550
571
|
return { groups, harness: hn };
|
|
@@ -574,7 +595,7 @@ export function apiDocsPage(state, pageId, harnessName = null) {
|
|
|
574
595
|
const KIND_ROUTES = {
|
|
575
596
|
// The body's own H1 goes: MarkdownPage prints the page title as the H1, and a page has one.
|
|
576
597
|
markdown: (state, pageId, page, hn) => {
|
|
577
|
-
const text = renderSource(stripHarnessBlocks(readDocSource(page.source), hn), state
|
|
598
|
+
const text = renderSource(stripHarnessBlocks(readDocSource(page.source), hn), state)
|
|
578
599
|
.replace(/^# [^\n]*(?:\r?\n)+/, '');
|
|
579
600
|
const body = rewriteDocLinks(text, page.source, idsByRel());
|
|
580
601
|
return { id: pageId, title: page.title, kind: 'markdown', body,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The console's warm-up doctor, on its own thread (`warmDoctor` in `state.mjs`).
|
|
3
|
+
*
|
|
4
|
+
* A thread and not a child process: the CLI graph may not grow a spawn, and one message out is the
|
|
5
|
+
* whole protocol. `jobs.mjs` argues the opposite for jobs, which need stdout and an exit code.
|
|
6
|
+
* Its `process.stdout` is this thread's own, so the doctor's swallow cannot touch the daemon's.
|
|
7
|
+
*/
|
|
8
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
9
|
+
|
|
10
|
+
import { doctorCollect } from '../inspect/doctor.mjs';
|
|
11
|
+
|
|
12
|
+
const groups = [];
|
|
13
|
+
const [themes, problems] = doctorCollect({ theme: workerData.theme, groups });
|
|
14
|
+
parentPort.postMessage({ themes, problems, groups });
|
package/js/web/handler.mjs
CHANGED
|
@@ -109,7 +109,7 @@ const GZIP_MIN = 1024;
|
|
|
109
109
|
* a path); without a cap any web page could `no-cors` POST an arbitrary blob and this process
|
|
110
110
|
* would buffer all of it before the token check refused it.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
const MAX_BODY = 1024 * 1024;
|
|
113
113
|
|
|
114
114
|
const BUSY = { error: 'a job is running — wait for it to finish (or cancel it) first' };
|
|
115
115
|
|
|
@@ -208,7 +208,17 @@ export function makeHandler(state, jm, token, dist, holder = null) {
|
|
|
208
208
|
const st = (path.startsWith('/api/') && path !== '/api/ping' && !path.startsWith('/api/jobs')
|
|
209
209
|
&& !MACHINE_GETS.has(path)) ? installView(state, installParams(req.url)) : state;
|
|
210
210
|
const route = STATE_ROUTES[path];
|
|
211
|
-
if (route !== undefined)
|
|
211
|
+
if (route !== undefined) {
|
|
212
|
+
const answer = route(st, req.url, state);
|
|
213
|
+
// Only `/api/doctor`, during the warm-up. A rejection here is past the handler's own catch.
|
|
214
|
+
if (answer instanceof Promise) {
|
|
215
|
+
return answer.then((a) => sendJson(res, a, 200, ae)).catch((e) => {
|
|
216
|
+
logFault(req, path, e);
|
|
217
|
+
sendJson(res, SERVER_FAULT, 500, ae);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return sendJson(res, answer, 200, ae);
|
|
221
|
+
}
|
|
212
222
|
// `pid` is what a restarting client waits on: the OLD server keeps answering this ping for
|
|
213
223
|
// a moment after `/api/restart` returns, and a reload onto it fetches the old token.
|
|
214
224
|
if (path === '/api/ping') {
|
|
@@ -299,6 +309,8 @@ export function makeHandler(state, jm, token, dist, holder = null) {
|
|
|
299
309
|
apiPickFolder((result) => sendJson(res, result, 200, ae));
|
|
300
310
|
return;
|
|
301
311
|
}
|
|
312
|
+
// A rebuild's fold writes the same draft and ledger, so a decision waits for it.
|
|
313
|
+
if (path === '/api/rules/decide' && jm.busy) return sendJson(res, BUSY, 409, ae);
|
|
302
314
|
// The install a body `{host, path}` names, on the routes that read one (`VIEW_POSTS`).
|
|
303
315
|
// An action is looked up on the SAME segment `doAction` dispatches on (the last), so
|
|
304
316
|
// `/api/actions/x/restore` cannot run a restore on the daemon's install instead.
|
|
@@ -370,7 +382,7 @@ export function makeHandler(state, jm, token, dist, holder = null) {
|
|
|
370
382
|
// the new code on disk, so an axis or marker the pull added would be dropped. build-all
|
|
371
383
|
// spawns the new CLI, which builds every profile with the new code; this path cannot.
|
|
372
384
|
if (state.daemonStale?.()) {
|
|
373
|
-
return sendJson(res, { error: 'the console is running older code than the disk — restart it first (
|
|
385
|
+
return sendJson(res, { error: 'the console is running older code than the disk — restart it first (Settings › Server › Restart), then rebuild' }, 422, ae);
|
|
374
386
|
}
|
|
375
387
|
return startJob(res, 'rebuild', plan.cmds, ae);
|
|
376
388
|
}
|
|
@@ -512,8 +524,7 @@ function logFault(req, path, e) {
|
|
|
512
524
|
* needs and no further: values unquoted with `+` meaning a space, and a BLANK value dropped
|
|
513
525
|
* (`keep_blank_values=False`), so `?harness=` resolves to the installed default rather than
|
|
514
526
|
* to the empty string — `'' || null` is what drops it below. The first occurrence wins,
|
|
515
|
-
* because `
|
|
516
|
-
* `URLSearchParams.get`.
|
|
527
|
+
* because `URLSearchParams.get` takes the first.
|
|
517
528
|
*
|
|
518
529
|
* `new URL(url, 'http://x')` rather than a hand-split on `&`/`=`: the base is a throwaway,
|
|
519
530
|
* needed only because `URL` refuses a bare path-plus-query with no scheme. One measured
|