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/routes.mjs
CHANGED
|
@@ -8,10 +8,8 @@
|
|
|
8
8
|
* test, and probes the real handler, because a declaration is not a dispatcher — a route can be
|
|
9
9
|
* declared here and missing from the dispatch, and nothing but a probe notices.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* (see git history); an unmatched GET falls through to `serveStatic`'s SPA fallback and an
|
|
14
|
-
* unmatched POST answers 404, which is what the empty sets already produced.
|
|
11
|
+
* An unmatched GET falls through to `serveStatic`'s SPA fallback and an unmatched POST
|
|
12
|
+
* answers 404.
|
|
15
13
|
*
|
|
16
14
|
* Split out of `server.mjs` because it is the half a reader consults to answer "does the console
|
|
17
15
|
* expose X?", which has nothing to do with sockets, daemons or gzip.
|
|
@@ -22,14 +20,15 @@ import { percentDecode } from '../lib/text.mjs';
|
|
|
22
20
|
import { apiExcludesMutate, apiInstallToggle, apiLoopsPresetMutate, apiMcp, apiMemoryDelete, targetView } from './actions.mjs';
|
|
23
21
|
import { apiActivity, apiActivityDetail, apiActivityToggle } from './activity.mjs';
|
|
24
22
|
import {
|
|
25
|
-
apiDiff, apiDoctor, apiExcludes, apiFleet, apiInstalls, apiKits, apiLoops, apiLoopsActive, apiOverview,
|
|
23
|
+
apiDefaultInstallSet, apiDiff, apiDoctor, apiExcludes, apiFleet, apiInstalls, apiKits, apiLoops, apiLoopsActive, apiOverview, memoCounts,
|
|
26
24
|
apiRecent, apiSetup, apiThemes, activeInstalls, apiUpdate,
|
|
27
25
|
} from './api.mjs';
|
|
28
26
|
import { FLEET_SECTIONS, NotFound, apiCatalog, apiItem } from './catalog.mjs';
|
|
29
27
|
import { apiUsage } from './usage-api.mjs';
|
|
30
28
|
import { fleetSort } from './state.mjs';
|
|
31
29
|
import { apiGates } from './gates-api.mjs';
|
|
32
|
-
import {
|
|
30
|
+
import { migratePreview } from '../maintain/migrate.mjs';
|
|
31
|
+
import { apiProfile, apiProfileSave, apiRules, apiRulesDecide, apiRulesMutate, apiRulesPromote } from './user-files.mjs';
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* The POSTs this daemon answers — and this table IS the dispatch, not a declaration beside
|
|
@@ -48,6 +47,7 @@ import { apiProfile, apiProfileSave, apiRules, apiRulesMutate, apiRulesPromote }
|
|
|
48
47
|
/** @type {Map<string, [(state: any, body: any) => any, boolean]>} */
|
|
49
48
|
export const POST_ROUTES = new Map([
|
|
50
49
|
['/api/install', [apiInstallToggle, true]],
|
|
50
|
+
['/api/default-install', [apiDefaultInstallSet, true]],
|
|
51
51
|
['/api/excludes', [apiExcludesMutate, true]],
|
|
52
52
|
['/api/activity', [apiActivityToggle, false]],
|
|
53
53
|
// The dispatch wrapper resolves `name` from the body itself; `apiMemoryDelete` takes a bare
|
|
@@ -56,6 +56,7 @@ export const POST_ROUTES = new Map([
|
|
|
56
56
|
[(state, b) => apiMemoryDelete(state, isTruthy(b.name) ? formatValue(b.name) : ''), false]],
|
|
57
57
|
['/api/rules', [apiRulesMutate, true]],
|
|
58
58
|
['/api/rules/promote', [apiRulesPromote, true]],
|
|
59
|
+
['/api/rules/decide', [apiRulesDecide, true]],
|
|
59
60
|
['/api/profile', [apiProfileSave, true]],
|
|
60
61
|
// No `ok: false` arm: success returns `{ok: true, loop}`, and both refusals (unknown root,
|
|
61
62
|
// unknown preset) throw `NotFound`, which `doPost`'s catch answers 404 before this column is
|
|
@@ -65,13 +66,13 @@ export const POST_ROUTES = new Map([
|
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
68
|
* The POSTs whose body `{host, path}` names the install they act on (`installView`), opt-in
|
|
68
|
-
* rather than every POST: in `/api/install` and `/api/actions/install` the
|
|
69
|
-
* the target the route resolves itself, and in `/api/actions/deploy`, `/api/excludes` and
|
|
69
|
+
* rather than every POST: in `/api/install`, `/api/default-install` and `/api/actions/install` the
|
|
70
|
+
* pair is the target the route resolves itself, and in `/api/actions/deploy`, `/api/excludes` and
|
|
70
71
|
* `/api/reveal` a `path` is a folder or a config file, not an install. The two `actions/` rows
|
|
71
72
|
* are the only actions that read the request's install.
|
|
72
73
|
*/
|
|
73
74
|
export const VIEW_POSTS = new Set(['/api/activity', '/api/memory/delete', '/api/rules',
|
|
74
|
-
'/api/rules/promote', '/api/profile', '/api/actions/restore', '/api/actions/build']);
|
|
75
|
+
'/api/rules/promote', '/api/rules/decide', '/api/profile', '/api/actions/restore', '/api/actions/build']);
|
|
75
76
|
|
|
76
77
|
/**
|
|
77
78
|
* The GETs that answer for the whole machine, not one install: they IGNORE a `?host=&path=`
|
|
@@ -83,13 +84,14 @@ export const VIEW_POSTS = new Set(['/api/activity', '/api/memory/delete', '/api/
|
|
|
83
84
|
* toggle (a `VIEW_POSTS` write) still take the pair. Every other `/api/*` GET, ping and jobs
|
|
84
85
|
* aside, takes the pair and refuses an unknown one.
|
|
85
86
|
*
|
|
86
|
-
* The Library's fleet lists (`/api/catalog
|
|
87
|
-
*
|
|
88
|
-
*
|
|
87
|
+
* The Library's fleet lists (`/api/catalog/<FLEET_SECTIONS>`) are here because they read every
|
|
88
|
+
* active install (`fleetOf`), which caches one view per install on the daemon state; the laws
|
|
89
|
+
* section, and `/api/item/`, stay install-scoped (`PREFIX_ROUTES`).
|
|
89
90
|
*/
|
|
90
|
-
export const MACHINE_GETS = new Set(['/api/update', '/api/installs', '/api/fleet', '/api/kits',
|
|
91
|
+
export const MACHINE_GETS = new Set(['/api/update', '/api/installs', '/api/fleet', '/api/migrate/preview', '/api/kits',
|
|
91
92
|
'/api/usage', '/api/gates', '/api/excludes', '/api/mcp', '/api/loops/active', '/api/activity',
|
|
92
|
-
'/api/catalog/skills', '/api/catalog/agents', '/api/catalog/memory', '/api/catalog/notebook'
|
|
93
|
+
'/api/catalog/skills', '/api/catalog/agents', '/api/catalog/memory', '/api/catalog/notebook',
|
|
94
|
+
'/api/catalog/wiki', '/api/catalog/config']);
|
|
93
95
|
|
|
94
96
|
/**
|
|
95
97
|
* The 409 column, exported so a test can assert it directly. Giving `/api/activity` the 409
|
|
@@ -143,9 +145,8 @@ export function readJsonBody(buf) {
|
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
/**
|
|
146
|
-
* Every ACTIVE install as `{install, state}`, the Library's fleet lists
|
|
147
|
-
*
|
|
148
|
-
* is the usage ledger's `host:scope:root` key, `state` the install's cached view off the daemon
|
|
148
|
+
* Every ACTIVE install as `{install, state}`, the source of the Library's fleet lists
|
|
149
|
+
* (`FLEET_SECTIONS`) and of the overview's counts: `install` is the usage ledger's `host:scope:root` key, `state` the install's cached view off the daemon
|
|
149
150
|
* state `base` (`targetView`), so each install keeps its own inventory cache. ONE
|
|
150
151
|
* `installTargets()` scan: the targets it yields are the allowlist, so no view re-checks its
|
|
151
152
|
* pair the way a request-named one must (`installView`). In the console's install order
|
|
@@ -175,12 +176,11 @@ export const PREFIX_ROUTES = [
|
|
|
175
176
|
}],
|
|
176
177
|
// /api/item/<type>/<name> — TYPE has no slash, the NAME keeps its slashes so a wiki
|
|
177
178
|
// page's relpath survives. A missing name is a 404 here rather than a 500 two frames down.
|
|
178
|
-
// Install-scoped: a
|
|
179
|
-
// the fleet's first.
|
|
179
|
+
// Install-scoped: a Library entry is the named install's copy, else the fleet's first.
|
|
180
180
|
['/api/item/', (state, p, base) => {
|
|
181
181
|
const m = /^\/api\/item\/([^/]+)\/(.+)$/.exec(p);
|
|
182
182
|
if (!m) throw new NotFound(p);
|
|
183
|
-
const fleet = [
|
|
183
|
+
const fleet = m[1] !== 'law' ? fleetOf(base) : undefined;
|
|
184
184
|
return apiItem(state, m[1], percentDecode(m[2]), fleet);
|
|
185
185
|
}],
|
|
186
186
|
// The sid is passed through unquoted — `apiActivityDetail`'s safe-name scheme is what
|
|
@@ -196,7 +196,7 @@ export const PREFIX_ROUTES = [
|
|
|
196
196
|
* test, so a route cannot appear or vanish unenumerated.
|
|
197
197
|
*/
|
|
198
198
|
export const STATE_ROUTES = {
|
|
199
|
-
'/api/overview': apiOverview,
|
|
199
|
+
'/api/overview': (state, url, base) => apiOverview(state, memoCounts(base, () => fleetOf(base))),
|
|
200
200
|
'/api/recent': apiRecent,
|
|
201
201
|
'/api/themes': apiThemes,
|
|
202
202
|
'/api/setup': apiSetup,
|
|
@@ -204,7 +204,9 @@ export const STATE_ROUTES = {
|
|
|
204
204
|
'/api/doctor': (state, url) => apiDoctor(state,
|
|
205
205
|
new URL(url || '', 'http://x').searchParams.has('fresh')),
|
|
206
206
|
'/api/installs': apiInstalls,
|
|
207
|
-
'/api/fleet': apiFleet,
|
|
207
|
+
'/api/fleet': (state) => apiFleet(state),
|
|
208
|
+
// Reads every global install, and writes nothing: the console's view of `migrate --dry-run`.
|
|
209
|
+
'/api/migrate/preview': () => migratePreview(),
|
|
208
210
|
'/api/kits': apiKits,
|
|
209
211
|
'/api/update': apiUpdate,
|
|
210
212
|
'/api/usage': apiUsage,
|
package/js/web/state.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { existsSync } from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
+
import { Worker } from 'node:worker_threads';
|
|
10
11
|
|
|
11
12
|
import { CLAUDE_STYLE, HOSTS, opencodeConfigDir, resolvePath } from '../hosts/hosts.mjs';
|
|
12
13
|
import { normcase } from '../lib/paths.mjs';
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
postureOfDir, themeOfDir, trustOfDir,
|
|
16
17
|
} from '../hosts/installs.mjs';
|
|
17
18
|
import { doctorCollect } from '../inspect/doctor.mjs';
|
|
19
|
+
import { emitOf, pickedInstall } from '../inspect/status.mjs';
|
|
18
20
|
import { DEFAULT_PRESET } from '../loop/score.mjs';
|
|
19
21
|
import { readText, isFile } from '../lib/fs.mjs';
|
|
20
22
|
import { stripWhitespace } from '../lib/text.mjs';
|
|
@@ -50,12 +52,14 @@ export function fleetSort(list, of) {
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
|
-
* `[target, root]` of THE DEFAULT INSTALL — the one a request that names no install reads —
|
|
54
|
-
* null when no install is active.
|
|
55
|
+
* `[target, root, emit]` of THE DEFAULT INSTALL — the one a request that names no install reads —
|
|
56
|
+
* or null when no install is active. The three are `selectView`'s arguments: the emit travels
|
|
57
|
+
* because a repo with two project installs has one root marker, the last emit's.
|
|
55
58
|
*
|
|
56
|
-
* It is the
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
+
* It is the install the user chose (`POST /api/default-install`, `pickedInstall`) while that one is
|
|
60
|
+
* still active, else the first ACTIVE install in the console's one install order (`fleetSort`):
|
|
61
|
+
* host order (opencode, claude, bob, openclaude), then global before project, then the order
|
|
62
|
+
* `installTargets` found them. A stale pick falls through in silence: it never breaks the console.
|
|
59
63
|
* There is no viewed install to pick any more (the topbar selector and `POST /api/view` are
|
|
60
64
|
* gone): a page that wants another install names it on the request. The console once opened
|
|
61
65
|
* on the OpenCode global dir unconditionally, and on a Bob-only machine (reported 2026-10) it
|
|
@@ -66,8 +70,8 @@ export function defaultView(targets = installTargets()) {
|
|
|
66
70
|
const active = targets.filter(([host, scope, root]) => {
|
|
67
71
|
try { return installState(root, host, scope) === 'active'; } catch { return false; }
|
|
68
72
|
});
|
|
69
|
-
const pick = fleetSort(active, ([host, scope]) => [host, scope])[0];
|
|
70
|
-
return pick ? [viewCfg(...pick), pick[2]] : null;
|
|
73
|
+
const pick = pickedInstall(active) ?? fleetSort(active, ([host, scope]) => [host, scope])[0];
|
|
74
|
+
return pick ? [viewCfg(...pick), pick[2], emitOf(pick[0], pick[1])] : null;
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
/**
|
|
@@ -118,9 +122,17 @@ export function webState(theme = null, target = null) {
|
|
|
118
122
|
// beside it rather than inside so `/api/overview` (fetched after every mutation) does not
|
|
119
123
|
// carry every group.
|
|
120
124
|
_doctorRun: null,
|
|
125
|
+
// The warm-up run still in flight, a promise settled when its thread ends (`warmDoctor`).
|
|
126
|
+
_doctorJob: null,
|
|
121
127
|
// `diffCollect`'s memo of `expected` renders, made on first use by `api.mjs` (`memoOf`);
|
|
122
128
|
// it re-renders on its own key change, so `refresh()` leaves it alone.
|
|
123
129
|
renderMemo: null,
|
|
130
|
+
// `apiFleet`'s per-install reads, made on first use; dropped with `_inv`, or aged out there.
|
|
131
|
+
_fleetReads: null,
|
|
132
|
+
// `memoCounts`' last answer, on the daemon's state; every refresh and re-point drops it.
|
|
133
|
+
_counts: null,
|
|
134
|
+
// The emit `selectView` was told, which outranks any marker; null reads the markers.
|
|
135
|
+
_knownEmit: null,
|
|
124
136
|
// True for a per-install view (`installView` in actions.mjs): `refresh` must never re-point
|
|
125
137
|
// it at another install, since the request named THIS one.
|
|
126
138
|
pinned: false,
|
|
@@ -157,8 +169,10 @@ export function webState(theme = null, target = null) {
|
|
|
157
169
|
},
|
|
158
170
|
});
|
|
159
171
|
Object.defineProperty(st, 'doctor', {
|
|
172
|
+
// NULL WHILE THE WARM-UP RUNS, and only then: a pending verdict, which the console draws as
|
|
173
|
+
// "checking" and asks again for. Blocking here would put the run back on the event loop.
|
|
160
174
|
get() {
|
|
161
|
-
if (st._doctor === null) st.runDoctor();
|
|
175
|
+
if (st._doctor === null && st._doctorJob === null) st.runDoctor();
|
|
162
176
|
return st._doctor;
|
|
163
177
|
},
|
|
164
178
|
});
|
|
@@ -169,6 +183,7 @@ export function webState(theme = null, target = null) {
|
|
|
169
183
|
st.stampDoctor(problems, themes, groups);
|
|
170
184
|
};
|
|
171
185
|
st.stampDoctor = (problems, themes = [], groups = []) => {
|
|
186
|
+
st._doctorJob = null; // a run still in flight started earlier: this verdict is the newer one
|
|
172
187
|
st._doctor = { ok: !problems.length, problems, checked_at: stampMinute(Date.now()) };
|
|
173
188
|
st._doctorRun = { themes, groups };
|
|
174
189
|
};
|
|
@@ -181,6 +196,7 @@ export function webState(theme = null, target = null) {
|
|
|
181
196
|
* `installedDefaults()`.
|
|
182
197
|
*/
|
|
183
198
|
st.detectEmit = () => {
|
|
199
|
+
if (st._knownEmit) return st._knownEmit;
|
|
184
200
|
for (const d of [st.root, st.target]) {
|
|
185
201
|
try {
|
|
186
202
|
const em = path.join(d, '.geneseed-emit');
|
|
@@ -202,17 +218,22 @@ export function webState(theme = null, target = null) {
|
|
|
202
218
|
* and a Diff or a Restore would then overwrite it in the wrong dialect. The theme/posture/mode
|
|
203
219
|
* SIGILS are different: for claude/bob they live in the ROOT carrier (`themeOfDir` scans it);
|
|
204
220
|
* for openclaude they live ONLY in the data dir's nested `.openclaude/CLAUDE.md`, since its
|
|
205
|
-
* root carrier is deliberately left untouched (host-compat B1/I1).
|
|
221
|
+
* root carrier is deliberately left untouched (host-compat B1/I1). `emit`, when the caller knows
|
|
222
|
+
* which install this is, settles the dialect; the root's marker cannot when two hosts share it.
|
|
206
223
|
*/
|
|
207
|
-
st.selectView = (target, root = null) => {
|
|
224
|
+
st.selectView = (target, root = null, emit = null) => {
|
|
208
225
|
st.target = target;
|
|
209
226
|
st.root = root || target;
|
|
227
|
+
st._knownEmit = emit;
|
|
210
228
|
st.emit = st.detectEmit();
|
|
211
229
|
const host = hostOf();
|
|
212
230
|
st.theme = themeOfDir(st.root, host) || themeOfDir(st.target, host) || 'neutral';
|
|
213
231
|
readMarkers(host);
|
|
214
232
|
st._inv = null;
|
|
233
|
+
st._fleetReads = null;
|
|
234
|
+
st._counts = null;
|
|
215
235
|
st._doctor = null;
|
|
236
|
+
st._doctorJob = null;
|
|
216
237
|
};
|
|
217
238
|
/** This state alone. `refresh` below is what callers use: it also reaches every view. */
|
|
218
239
|
st.refreshOwn = ({ doctor = true } = {}) => {
|
|
@@ -223,7 +244,10 @@ export function webState(theme = null, target = null) {
|
|
|
223
244
|
const def = doctor && !st.pinned ? defaultView() : null;
|
|
224
245
|
if (def && !samePath(def[0], st.target)) { st.selectView(...def); return; }
|
|
225
246
|
st._inv = null;
|
|
226
|
-
|
|
247
|
+
st._fleetReads = null;
|
|
248
|
+
st._counts = null;
|
|
249
|
+
// The job goes too: what it read may be what this mutation changed, so its answer is dropped.
|
|
250
|
+
if (doctor) { st._doctor = null; st._doctorJob = null; }
|
|
227
251
|
st.emit = st.detectEmit() || st.emit;
|
|
228
252
|
const host = hostOf();
|
|
229
253
|
st.theme = themeOfDir(st.root, host) || themeOfDir(st.target, host) || st.theme;
|
|
@@ -240,15 +264,50 @@ export function webState(theme = null, target = null) {
|
|
|
240
264
|
return st;
|
|
241
265
|
}
|
|
242
266
|
|
|
267
|
+
// Several times the slowest run seen on a loaded machine: a run past this has hung.
|
|
268
|
+
const WARM_DOCTOR_LIMIT_MS = 180_000;
|
|
269
|
+
|
|
243
270
|
/**
|
|
244
|
-
* Run the doctor once
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
271
|
+
* Run the doctor once right after the server binds, ON ITS OWN THREAD. On the event loop this run
|
|
272
|
+
* held every request of a cold daemon for 13-24 s, past `BootSplash`'s stall at 8 s. Until it
|
|
273
|
+
* lands `st.doctor` is null and `/api/doctor` waits on the promise this returns.
|
|
274
|
+
*
|
|
275
|
+
* A verdict is stamped only while its job is still the current one: `refresh`, `selectView` and a
|
|
276
|
+
* newer run all clear `_doctorJob`, and the daemon must not serve what a mutation made stale. A
|
|
277
|
+
* failed warm-up, like the old one, just leaves the cache cold: the next ask runs in line. The
|
|
278
|
+
* `error` listener is not optional, an unheard worker error is uncaught and kills the daemon.
|
|
279
|
+
* `unref`: a stopping daemon does not wait for it.
|
|
280
|
+
*
|
|
281
|
+
* A HUNG run would leave `/api/doctor` unanswered and the console polling for good, so past
|
|
282
|
+
* `limitMs` it is stopped and stamped as a FAILED verdict: unknown is never a green. Re-run clears it.
|
|
249
283
|
*/
|
|
250
|
-
export function warmDoctor(st) {
|
|
251
|
-
|
|
252
|
-
|
|
284
|
+
export function warmDoctor(st, limitMs = WARM_DOCTOR_LIMIT_MS) {
|
|
285
|
+
if (st._doctor !== null || st._doctorJob !== null) return st._doctorJob;
|
|
286
|
+
let worker;
|
|
287
|
+
try {
|
|
288
|
+
worker = new Worker(new URL('./doctor-worker.mjs', import.meta.url),
|
|
289
|
+
{ workerData: { theme: st.theme } });
|
|
290
|
+
} catch { return null; }
|
|
291
|
+
worker.unref();
|
|
292
|
+
const job = new Promise((done) => {
|
|
293
|
+
const limit = setTimeout(() => {
|
|
294
|
+
if (st._doctorJob === job) {
|
|
295
|
+
const said = `[doctor] the warm-up run did not finish in ${limitMs / 1000} s, so nothing was checked`;
|
|
296
|
+
st.stampDoctor([said], [], [{ check: 'warm_up', label: 'Warm-up run', problems: [said] }]);
|
|
297
|
+
}
|
|
298
|
+
worker.terminate();
|
|
299
|
+
}, limitMs);
|
|
300
|
+
limit.unref();
|
|
301
|
+
worker.once('message', (r) => {
|
|
302
|
+
if (st._doctorJob === job) st.stampDoctor(r.problems, r.themes, r.groups);
|
|
303
|
+
});
|
|
304
|
+
worker.once('error', () => { /* cold cache, computed on demand */ });
|
|
305
|
+
worker.once('exit', () => {
|
|
306
|
+
clearTimeout(limit);
|
|
307
|
+
if (st._doctorJob === job) st._doctorJob = null;
|
|
308
|
+
done();
|
|
309
|
+
});
|
|
253
310
|
});
|
|
311
|
+
st._doctorJob = job;
|
|
312
|
+
return job;
|
|
254
313
|
}
|
package/js/web/update-check.mjs
CHANGED
|
@@ -23,8 +23,8 @@ import { existsSync, realpathSync } from 'node:fs';
|
|
|
23
23
|
import path from 'node:path';
|
|
24
24
|
|
|
25
25
|
import { ROOT } from '../build/source.mjs';
|
|
26
|
-
import { measureUpstream } from '../maintain/update.mjs';
|
|
27
|
-
import { normcase, which } from '../lib/paths.mjs';
|
|
26
|
+
import { measureUpstream, preflight } from '../maintain/update.mjs';
|
|
27
|
+
import { inNodeModules, normcase, which } from '../lib/paths.mjs';
|
|
28
28
|
|
|
29
29
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
30
30
|
/** A failed ask is retried sooner than a good answer is refreshed: a proxy hiccup is not a day. */
|
|
@@ -68,12 +68,13 @@ export function updateStatus(state, current, { fetcher = npmLatest, now = Date.n
|
|
|
68
68
|
/**
|
|
69
69
|
* The once-a-day cache both checks share: answer from `state[slot]` at once and, when that is
|
|
70
70
|
* missing or stale, start ONE background ask whose answer the next poll reads. A null answer
|
|
71
|
-
* (every failure) is re-asked after RETRY_MS, a
|
|
71
|
+
* (every failure) is re-asked after RETRY_MS, and so is `false` (a pull that cannot run), which a
|
|
72
|
+
* `git checkout main` can end at any moment. A good one is re-asked after DAY_MS.
|
|
72
73
|
*/
|
|
73
74
|
function daily(state, slot, ask, now, off) {
|
|
74
75
|
const c = state[slot] || (state[slot] = { value: null, checked_at: null, inflight: false });
|
|
75
76
|
const stale = c.checked_at === null
|
|
76
|
-
|| now - c.checked_at > (c.value === null ? RETRY_MS : DAY_MS);
|
|
77
|
+
|| now - c.checked_at > (c.value === null || c.value === false ? RETRY_MS : DAY_MS);
|
|
77
78
|
if (stale && !c.inflight && !off && !process.env.GENESEED_NO_UPDATE_CHECK) {
|
|
78
79
|
c.inflight = true;
|
|
79
80
|
Promise.resolve()
|
|
@@ -84,18 +85,32 @@ function daily(state, slot, ask, now, off) {
|
|
|
84
85
|
return c;
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
/**
|
|
89
|
+
* `measureUpstream`'s verdict: 0 up to date, N to pull, null when the remote gave no answer, false
|
|
90
|
+
* when it did and `upgrade` would refuse to pull (no upstream, diverged, unrelated history).
|
|
91
|
+
*/
|
|
92
|
+
export function behindOf(code, behind) {
|
|
90
93
|
if (code === 'uptodate') return 0;
|
|
91
|
-
|
|
94
|
+
if (code === 'ready') return behind;
|
|
95
|
+
return code === 'fetch_failed' ? null : false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* `upgrade`'s two gates in its own order. The local one comes first, so a checkout that could
|
|
100
|
+
* never pull (local changes, a detached HEAD, no upstream) answers `false` with no fetch at all,
|
|
101
|
+
* and so offline too. `pre` and `measure` are injectable for the tests.
|
|
102
|
+
*/
|
|
103
|
+
export async function fetchBehind({ pre = preflight, measure = measureUpstream } = {}) {
|
|
104
|
+
if (!pre().ok) return false;
|
|
105
|
+
const [code, behind] = await measure();
|
|
106
|
+
return behindOf(code, behind);
|
|
92
107
|
}
|
|
93
108
|
|
|
94
109
|
/**
|
|
95
110
|
* Commits the clone's upstream holds that it does not: `upgrade`'s own `git fetch` (timeboxed by
|
|
96
111
|
* `GENESEED_NET_TIMEOUT`, 120 s by default) then a count, once a day, in the background. Null
|
|
97
|
-
* until the first answer lands and on
|
|
98
|
-
*
|
|
112
|
+
* until the first answer lands and on an unreachable remote, and the console then keeps its "a
|
|
113
|
+
* clone can always pull" button; false for a pull that cannot run, and the console drops it.
|
|
99
114
|
*
|
|
100
115
|
* `busy` skips the ask while a job runs: a fetch beside the update job's own pull would race it
|
|
101
116
|
* for `.git` locks. `measure` and `now` are injectable for the tests.
|
|
@@ -109,7 +124,7 @@ export function gitBehind(state, { measure = fetchBehind, now = Date.now(), busy
|
|
|
109
124
|
export const MANUAL_UPDATE = 'npm install -g geneseed@latest';
|
|
110
125
|
|
|
111
126
|
/** `npm root -g`, or null when npm is absent or does not answer. Asked once per daemon. */
|
|
112
|
-
|
|
127
|
+
function npmGlobalRoot() {
|
|
113
128
|
const npm = which('npm');
|
|
114
129
|
if (!npm) return null;
|
|
115
130
|
const win = process.platform === 'win32';
|
|
@@ -147,7 +162,7 @@ export function installKind({ root = ROOT, npmRoot = npmGlobalRoot } = {}) {
|
|
|
147
162
|
let kind = 'other';
|
|
148
163
|
let unanswered = false;
|
|
149
164
|
if (existsSync(path.join(root, '.git'))) kind = 'git';
|
|
150
|
-
else if (
|
|
165
|
+
else if (inNodeModules(root)) {
|
|
151
166
|
const g = npmRoot();
|
|
152
167
|
unanswered = !g;
|
|
153
168
|
if (g && real(g) === real(path.dirname(root))) kind = 'npm-global';
|