geneseed 4.30.1 → 4.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/SHIPPED.md +1 -1
- package/docs/concepts/footprint.md +1 -1
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/web-ui.md +70 -21
- package/harness.config.json +1 -1
- package/js/README.md +3 -3
- package/js/web/actions.mjs +13 -23
- package/js/web/activity.mjs +139 -23
- package/js/web/api.mjs +29 -11
- package/js/web/catalog.mjs +108 -23
- package/js/web/handler.mjs +4 -3
- package/js/web/routes.mjs +47 -14
- package/js/web/server.mjs +14 -13
- package/js/web/state.mjs +36 -15
- package/js/web/usage-api.mjs +7 -3
- package/package.json +1 -1
- package/web/dist/assets/Activity-B7cFtS00.js +1 -0
- package/web/dist/assets/ActivityDetail-C-GbMmuW.js +1 -0
- package/web/dist/assets/{Bonsai-CN4rRAHc.js → Bonsai-_YyexVC5.js} +1 -1
- package/web/dist/assets/{CopyButton-CYljsnLo.js → CopyButton-IXnXzH4Y.js} +1 -1
- package/web/dist/assets/{Dashboard-DkUm4XMu.js → Dashboard-sCfEjowQ.js} +2 -2
- package/web/dist/assets/{Docs-DE04qOKj.js → Docs-w3Y7M5Ts.js} +2 -2
- package/web/dist/assets/{GreenhouseView-DPwhFO_j.js → GreenhouseView-BWWbMKmg.js} +1 -1
- package/web/dist/assets/Installs-CnkdJ-VA.js +3 -0
- package/web/dist/assets/{JournalView-DQlDC-7i.js → JournalView-C7bPD3fZ.js} +1 -1
- package/web/dist/assets/{KitApply-BN2Az7dc.js → KitApply-CQQbnThf.js} +1 -1
- package/web/dist/assets/{Kits-C9qVd466.js → Kits-aj07N7mT.js} +1 -1
- package/web/dist/assets/Laws-DZ38nl_H.js +3 -0
- package/web/dist/assets/Library-QCGXPV5h.js +2 -0
- package/web/dist/assets/Loops-C5u7fQOR.js +2 -0
- package/web/dist/assets/{OperatorHudView-CLN6Qn25.js → OperatorHudView-Blu1lqiZ.js} +1 -1
- package/web/dist/assets/Personal-ox_MktWO.js +2 -0
- package/web/dist/assets/Tabs-CIPyMAX-.js +1 -0
- package/web/dist/assets/api-BxjLd7Qd.js +1 -0
- package/web/dist/assets/index-0GCxkY7m.css +1 -0
- package/web/dist/assets/index-CzDi9JpF.js +3 -0
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Activity-C8pQvnos.js +0 -1
- package/web/dist/assets/ActivityDetail-D_8Bx-QO.js +0 -1
- package/web/dist/assets/Installs-DmPzD4BW.js +0 -3
- package/web/dist/assets/Laws-T2wbwMmB.js +0 -3
- package/web/dist/assets/Library-t3KocV0-.js +0 -2
- package/web/dist/assets/Loops-6lNY-9uR.js +0 -2
- package/web/dist/assets/Personal-xjoSqCzr.js +0 -2
- package/web/dist/assets/Tabs-DaExAgql.js +0 -1
- package/web/dist/assets/api-LvBC0CnK.js +0 -1
- package/web/dist/assets/index-DhNNxhfg.js +0 -3
- package/web/dist/assets/index-XTGBLKQr.css +0 -1
package/js/web/api.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import { alwaysOnCost } from '../inspect/cost.mjs';
|
|
|
18
18
|
import { installProfile } from '../build/generate.mjs';
|
|
19
19
|
import { diffCollect, renderMemo } from '../inspect/diff.mjs';
|
|
20
20
|
import { excludesSnapshot } from '../inspect/excludes.mjs';
|
|
21
|
-
import { VERSION_MARKER
|
|
21
|
+
import { VERSION_MARKER } from '../hosts/hosts.mjs';
|
|
22
22
|
import { autostartPaths } from '../hosts/shim.mjs';
|
|
23
23
|
import {
|
|
24
24
|
footprintOfDir, gatesOfDir, installState, installTargets, legacyProcessCarrierOfDir, modeOfDir,
|
|
@@ -31,11 +31,11 @@ import { activeLoops } from '../loop/registry.mjs';
|
|
|
31
31
|
import { EMIT_OPTIONS, themeOptions } from '../maintain/setup.mjs';
|
|
32
32
|
import { accentFor, keptKitFiles, statusData } from '../inspect/status.mjs';
|
|
33
33
|
import { isFile } from '../lib/fs.mjs';
|
|
34
|
-
import { comparePaths
|
|
34
|
+
import { comparePaths } from '../lib/paths.mjs';
|
|
35
35
|
import {
|
|
36
36
|
configItems, deployed, dget, memoryItems, notebookItems, wikiItems,
|
|
37
37
|
} from './catalog.mjs';
|
|
38
|
-
import { stampMinute, viewCfg } from './state.mjs';
|
|
38
|
+
import { defaultView, samePath, stampMinute, viewCfg } from './state.mjs';
|
|
39
39
|
import { MANUAL_UPDATE, gitBehind, installKind, updateStatus } from './update-check.mjs';
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -44,9 +44,6 @@ import { MANUAL_UPDATE, gitBehind, installKind, updateStatus } from './update-ch
|
|
|
44
44
|
*/
|
|
45
45
|
export { NotFound, deployed, resolveLinks } from './catalog.mjs';
|
|
46
46
|
|
|
47
|
-
/** Two resolved paths, compared case-folded on Windows. */
|
|
48
|
-
const samePath = (a, b) => normcase(resolvePath(a)) === normcase(resolvePath(b));
|
|
49
|
-
|
|
50
47
|
// ---- the eight endpoints -------------------------------------------------------------
|
|
51
48
|
|
|
52
49
|
/** `buildOverride` in `actions.mjs` is a third reader of this. */
|
|
@@ -156,6 +153,19 @@ const driftCounts = (files) => ({
|
|
|
156
153
|
stale: files.filter((f) => f.status === 'stale').length,
|
|
157
154
|
});
|
|
158
155
|
|
|
156
|
+
/**
|
|
157
|
+
* How many memory facts an install's data dir holds: the `.md` files of `<dir>/memory` (where
|
|
158
|
+
* `memoryItems` reads them), minus its index and README (the console's furniture), any case.
|
|
159
|
+
* No folder is no facts (0); a folder that cannot be listed is null, so a row says "not read"
|
|
160
|
+
* rather than "no facts".
|
|
161
|
+
*/
|
|
162
|
+
export function memoryFactCount(dir) {
|
|
163
|
+
try {
|
|
164
|
+
return readdirSync(path.join(dir, 'memory'))
|
|
165
|
+
.filter((f) => /\.md$/i.test(f) && !/^(memory|readme)\.md$/i.test(f)).length;
|
|
166
|
+
} catch (e) { return e?.code === 'ENOENT' ? 0 : null; }
|
|
167
|
+
}
|
|
168
|
+
|
|
159
169
|
/**
|
|
160
170
|
* The fields every install row opens with, in this order. Theme is narrowed to this row's own
|
|
161
171
|
* host (host-compat B1): a shared repo otherwise answers every row with whichever host's
|
|
@@ -176,13 +186,19 @@ const installRowBase = (host, scope, root, state) => ({
|
|
|
176
186
|
*/
|
|
177
187
|
export function apiInstalls(state) {
|
|
178
188
|
const out = [];
|
|
179
|
-
|
|
189
|
+
const targets = installTargets();
|
|
190
|
+
const def = defaultView(targets);
|
|
191
|
+
// The row marked `default` must be the install an unnamed request reads, so the daemon state
|
|
192
|
+
// follows the marker here, where the console reads it, rather than only on a full refresh.
|
|
193
|
+
if (def && state?.selectView && !state.pinned && !samePath(def[0], state.target)) state.selectView(...def);
|
|
194
|
+
for (const [host, scope, root] of targets) {
|
|
180
195
|
out.push({
|
|
181
196
|
...installRowBase(host, scope, root, installState(root, host, scope)),
|
|
182
197
|
posture: postureOfDir(root, host),
|
|
183
198
|
mode: modeOfDir(root, host),
|
|
184
199
|
trust: trustOfDir(root, host),
|
|
185
|
-
|
|
200
|
+
// The install a request naming none reads (`defaultView`): the console's pickers start on it.
|
|
201
|
+
default: !!def && samePath(viewCfg(host, scope, root), def[0]),
|
|
186
202
|
});
|
|
187
203
|
}
|
|
188
204
|
return { installs: out, postures: discoverNames('postures', 'peer'),
|
|
@@ -232,9 +248,11 @@ export function apiFleet(state) {
|
|
|
232
248
|
diffable: drift !== null,
|
|
233
249
|
drift,
|
|
234
250
|
built_epoch: built,
|
|
235
|
-
//
|
|
236
|
-
|
|
237
|
-
|
|
251
|
+
// Each install's own settings, on its row: the Overview has no viewed install to read them off.
|
|
252
|
+
posture: postureOfDir(root, host),
|
|
253
|
+
mode: modeOfDir(root, host),
|
|
254
|
+
// Its memory facts: one directory listing (`memoryFactCount`), no file read.
|
|
255
|
+
facts: memoryFactCount(dir),
|
|
238
256
|
// What this install injects every session, by part (characters); null when its carrier
|
|
239
257
|
// is missing, so the console says "not measured" rather than drawing an empty bar.
|
|
240
258
|
cost: alwaysOnCost({ host, root, dir, footprint: footprintOfDir(root) }),
|
package/js/web/catalog.mjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* The Library's READ MODEL — what the console lists and opens: the agent/skill inventory (read
|
|
3
3
|
* off the deployed install, else rendered from source), the constitution's three tiers, and the
|
|
4
4
|
* hand-written stores beside the install (memory, notebook, wiki, the two setup manifests).
|
|
5
|
-
* `apiCatalog` and `apiItem` are its two endpoints; `routes.mjs` binds them to paths.
|
|
5
|
+
* `apiCatalog` and `apiItem` are its two endpoints; `routes.mjs` binds them to paths. Skills and
|
|
6
|
+
* agents are read across every active install (`FLEET_SECTIONS`, the fleet `routes.mjs` builds);
|
|
7
|
+
* the other sections, one install's.
|
|
6
8
|
*
|
|
7
9
|
* `NotFound` lives here because this is where it is raised most, and because `state.mjs` imports
|
|
8
10
|
* this file (for the inventory it caches) and nothing here imports `state.mjs` back.
|
|
@@ -36,10 +38,25 @@ export class BadRequest extends Error {}
|
|
|
36
38
|
/** `??` would also swallow an explicit `null` the file declared; this does not. */
|
|
37
39
|
export const dget = (obj, key, dflt) => (Object.hasOwn(obj, key) ? obj[key] : dflt);
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The dir holding the viewed install's manifest — its host layer — or null when none is deployed.
|
|
43
|
+
*
|
|
44
|
+
* `state.target` itself for a global install and a Claude-style project one (whose target IS
|
|
45
|
+
* `<repo>/.claude|.bob|.openclaude`). An OpenCode PROJECT install is viewed at the repo root,
|
|
46
|
+
* where its memory, rules and markers live, but writes its manifest and the layer the host loads
|
|
47
|
+
* (`skills/<name>/SKILL.md`, `agents/`) under `<repo>/.opencode/`; the root `skills/` is the
|
|
48
|
+
* plain bundle's flat `<name>.md`. Checking the target alone read every such install as "not
|
|
49
|
+
* deployed" and listed the source render instead of what it has.
|
|
50
|
+
*/
|
|
51
|
+
export function deployedLayer(state) {
|
|
52
|
+
for (const dir of [state.target, path.join(state.target, '.opencode')]) {
|
|
53
|
+
if (existsSync(path.join(dir, GLOBAL_MANIFEST))) return dir;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
41
56
|
}
|
|
42
57
|
|
|
58
|
+
export const deployed = (state) => deployedLayer(state) !== null;
|
|
59
|
+
|
|
43
60
|
/**
|
|
44
61
|
* A deployed spec's one-line purpose.
|
|
45
62
|
*
|
|
@@ -94,7 +111,8 @@ function specEntries(root, nested) {
|
|
|
94
111
|
}
|
|
95
112
|
|
|
96
113
|
/**
|
|
97
|
-
* The agents and skills actually installed
|
|
114
|
+
* The agents and skills actually installed in the install's host layer (`deployedLayer`), not
|
|
115
|
+
* a fresh render of `src/`.
|
|
98
116
|
*
|
|
99
117
|
* All three constitutional tiers still come from the render: once deployed they live inside
|
|
100
118
|
* AGENT.md rather than as separate files, so the deployed arm replaces the two ENTITY rosters
|
|
@@ -114,13 +132,14 @@ function deployedInventory(state) {
|
|
|
114
132
|
const render = tuiInventory(state.theme, doctrinesForBuild(state.target),
|
|
115
133
|
excludedRulesOfDir(state.target));
|
|
116
134
|
const registry = loadRegistry();
|
|
117
|
-
const
|
|
135
|
+
const layer = deployedLayer(state);
|
|
136
|
+
const skills = specEntries(path.join(layer, 'skills'), true);
|
|
118
137
|
for (const e of skills) {
|
|
119
138
|
e.status = entityStatus(registry, `skills/${e.name}`);
|
|
120
139
|
e.klass = e.status === 'personal' ? 'personal'
|
|
121
140
|
: (Object.hasOwn(SKILL_CLASS, e.name) ? SKILL_CLASS[e.name] : 'build');
|
|
122
141
|
}
|
|
123
|
-
const agents = specEntries(path.join(
|
|
142
|
+
const agents = specEntries(path.join(layer, 'agents'), false);
|
|
124
143
|
for (const e of agents) e.status = entityStatus(registry, `agents/${e.name}`);
|
|
125
144
|
return { agents,
|
|
126
145
|
skills,
|
|
@@ -509,23 +528,71 @@ function tierNouns(theme) {
|
|
|
509
528
|
return { ontology: t.ONTOLOGY, law: t.LAW, laws: t.LAWS, doctrines: t.DOCTRINES };
|
|
510
529
|
}
|
|
511
530
|
|
|
512
|
-
|
|
531
|
+
/**
|
|
532
|
+
* The sections listed across every install (`fleet`), not off one: skills, agents, and the
|
|
533
|
+
* personal memory and notebook (each entry tagged with the installs that hold it, so a forget or
|
|
534
|
+
* a promote names its own). The other sections are one install's own wiki manifest, config or
|
|
535
|
+
* constitution.
|
|
536
|
+
*/
|
|
537
|
+
export const FLEET_SECTIONS = ['agents', 'skills', 'memory', 'notebook'];
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* A per-install item list (`read(state)`) over `fleet`, one row per name with the `installs` that
|
|
541
|
+
* hold it, in fleet order; the row's own fields are the FIRST holder's (`apiItem` serves the
|
|
542
|
+
* others). A name a later install adds lands after the first install's rows.
|
|
543
|
+
*/
|
|
544
|
+
function fleetItems(fleet, read) {
|
|
545
|
+
const rows = new Map();
|
|
546
|
+
for (const { install, state } of fleet) {
|
|
547
|
+
for (const it of read(state)) {
|
|
548
|
+
let r = rows.get(it.name);
|
|
549
|
+
if (r === undefined) rows.set(it.name, r = { ...it, installs: [] });
|
|
550
|
+
if (install !== null) r.installs.push(install);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return [...rows.values()];
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* One row per name over `fleet` — `[{install, state}]`, `install` the usage ledger's
|
|
558
|
+
* `host:scope:root` key (`usage-api.mjs`), or `null` for a lone state that is no detected
|
|
559
|
+
* install — with the keys of the installs that have it, in fleet order. A name only some
|
|
560
|
+
* installs have lists only those, so an exclusion stays visible. The row's own fields
|
|
561
|
+
* (description, source) are the FIRST install's: each install renders in its own theme, and
|
|
562
|
+
* `apiItem` serves the other copies.
|
|
563
|
+
*/
|
|
564
|
+
function fleetEntries(fleet, section) {
|
|
565
|
+
const rows = new Map();
|
|
566
|
+
for (const { install, state } of fleet) {
|
|
567
|
+
for (const e of state.inventory[section]) {
|
|
568
|
+
let r = rows.get(e.name);
|
|
569
|
+
if (r === undefined) rows.set(e.name, r = { e, installs: [] });
|
|
570
|
+
if (install !== null) r.installs.push(install);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return [...rows.values()].sort((a, b) => (a.e.name < b.e.name ? -1 : a.e.name > b.e.name ? 1 : 0));
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* `fleet` defaults to `state` alone, which answers as one install did before the console
|
|
578
|
+
* listed the fleet; the `/api/catalog/` route passes every active install for `FLEET_SECTIONS`.
|
|
579
|
+
*/
|
|
580
|
+
export function apiCatalog(state, section, fleet = [{ install: null, state }]) {
|
|
513
581
|
if (!SECTIONS.includes(section)) throw new NotFound(section);
|
|
514
|
-
const inv = state.inventory;
|
|
515
582
|
let items;
|
|
516
583
|
const owner = kitOwners();
|
|
517
584
|
if (section === 'agents') {
|
|
518
|
-
items =
|
|
519
|
-
source: e.source ?? null, status: e.status ?? 'unknown', kit: owner.get(`agent:${e.name}`) ?? null }));
|
|
585
|
+
items = fleetEntries(fleet, 'agents').map(({ e, installs }) => ({ name: e.name, title: e.name, desc: e.desc,
|
|
586
|
+
source: e.source ?? null, status: e.status ?? 'unknown', kit: owner.get(`agent:${e.name}`) ?? null, installs }));
|
|
520
587
|
} else if (section === 'skills') {
|
|
521
|
-
items =
|
|
522
|
-
source: e.source ?? null, klass: e.klass ?? 'build', status: e.status ?? 'unknown', kit: owner.get(`skill:${e.name}`) ?? null }));
|
|
588
|
+
items = fleetEntries(fleet, 'skills').map(({ e, installs }) => ({ name: e.name, title: e.name, desc: e.desc,
|
|
589
|
+
source: e.source ?? null, klass: e.klass ?? 'build', status: e.status ?? 'unknown', kit: owner.get(`skill:${e.name}`) ?? null, installs }));
|
|
523
590
|
} else if (section === 'laws') {
|
|
524
|
-
return { section, items: constitutionItems(
|
|
591
|
+
return { section, items: constitutionItems(state.inventory), nouns: tierNouns(state.theme) };
|
|
525
592
|
} else if (section === 'memory') {
|
|
526
|
-
items = memoryItems
|
|
593
|
+
items = fleetItems(fleet, memoryItems);
|
|
527
594
|
} else if (section === 'notebook') {
|
|
528
|
-
items = notebookItems
|
|
595
|
+
items = fleetItems(fleet, notebookItems);
|
|
529
596
|
} else if (section === 'wiki') {
|
|
530
597
|
items = wikiItems(state);
|
|
531
598
|
} else {
|
|
@@ -534,18 +601,32 @@ export function apiCatalog(state, section) {
|
|
|
534
601
|
return { section, items };
|
|
535
602
|
}
|
|
536
603
|
|
|
537
|
-
|
|
538
|
-
|
|
604
|
+
/**
|
|
605
|
+
* One entry. A skill or agent is served from ONE install's copy, since each install renders in
|
|
606
|
+
* its own theme and footprint: the install the request named (`state` is then its view, found
|
|
607
|
+
* in `fleet` by identity, and an id that install lacks is a 404 even when another has it), else
|
|
608
|
+
* the first install in `fleet` order that has the id. `install` says whose copy this is and
|
|
609
|
+
* `installs` every install that has the id, so the reader can offer the others. `fleet` defaults
|
|
610
|
+
* to `state` alone, which answers as one install did before.
|
|
611
|
+
*/
|
|
612
|
+
export function apiItem(state, type, name, fleet = [{ install: null, state }]) {
|
|
539
613
|
if (type === 'agent' || type === 'skill') {
|
|
540
|
-
const
|
|
614
|
+
const sec = type === 'agent' ? 'agents' : 'skills';
|
|
615
|
+
const has = fleet.filter((v) => v.state.inventory[sec].some((x) => x.name === name));
|
|
616
|
+
// A named install that is not active is not in the fleet: it answers for itself.
|
|
617
|
+
const from = fleet.find((v) => v.state === state) ?? (state.pinned ? { install: null, state } : has[0]);
|
|
618
|
+
const e = from?.state.inventory[sec].find((x) => x.name === name);
|
|
541
619
|
if (!e) throw new NotFound(name);
|
|
542
620
|
const out = { type, name, title: name, desc: e.desc, body: e.body,
|
|
543
|
-
links: resolveLinks(state, e.body), source: e.source ?? null };
|
|
621
|
+
links: resolveLinks(from.state, e.body), source: e.source ?? null };
|
|
544
622
|
if (type === 'skill') out.klass = e.klass ?? 'build';
|
|
545
623
|
out.status = e.status ?? 'unknown';
|
|
546
624
|
out.kit = kitOwners().get(`${type}:${name}`) ?? null;
|
|
625
|
+
out.install = from.install;
|
|
626
|
+
out.installs = has.map((v) => v.install).filter((k) => k !== null);
|
|
547
627
|
return out;
|
|
548
628
|
}
|
|
629
|
+
const inv = state.inventory;
|
|
549
630
|
if (type === 'law') {
|
|
550
631
|
// ONE ARM FOR THREE TIERS, resolved off the same list the catalogue publishes — so a name
|
|
551
632
|
// that appears in `/api/catalog/laws` always opens, and one that does not always 404s.
|
|
@@ -565,12 +646,16 @@ export function apiItem(state, type, name) {
|
|
|
565
646
|
}
|
|
566
647
|
if (type === 'memory' || type === 'notebook') {
|
|
567
648
|
flatName(name);
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
649
|
+
const fileOf = (st) => path.join(type === 'notebook' ? notebookDir(st) : memoryDir(st), `${name}.md`);
|
|
650
|
+
// 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)));
|
|
652
|
+
const from = fleet.find((v) => v.state === state) ?? (state.pinned ? { install: null, state } : has[0]);
|
|
653
|
+
const p = from ? fileOf(from.state) : null;
|
|
654
|
+
if (!p || !isFile(p)) throw new NotFound(name);
|
|
571
655
|
const body = readMaybe(p) ?? '';
|
|
572
656
|
return { type, name, title: name, desc: '', body,
|
|
573
|
-
links: resolveLinks(state, body), source: resolvePath(p)
|
|
657
|
+
links: resolveLinks(from.state, body), source: resolvePath(p),
|
|
658
|
+
install: from.install, installs: has.map((v) => v.install).filter((k) => k !== null) };
|
|
574
659
|
}
|
|
575
660
|
if (type === 'wiki') return apiWikiItem(state, name);
|
|
576
661
|
if (type === 'config') {
|
package/js/web/handler.mjs
CHANGED
|
@@ -201,7 +201,8 @@ export function makeHandler(state, jm, token, dist, holder = null) {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
function doGet(req, res, path, ae) {
|
|
204
|
-
// The install the request names (`?host=&path=`), else the daemon's
|
|
204
|
+
// The install the request names (`?host=&path=`), else the daemon's state (the default
|
|
205
|
+
// install, `defaultView`); an unknown pair
|
|
205
206
|
// throws `NotFound` here, before any route reads a dir. Not for ping, jobs, static files or
|
|
206
207
|
// the machine-wide reads (`MACHINE_GETS`), which ignore the pair.
|
|
207
208
|
const st = (path.startsWith('/api/') && path !== '/api/ping' && !path.startsWith('/api/jobs')
|
|
@@ -214,7 +215,7 @@ export function makeHandler(state, jm, token, dist, holder = null) {
|
|
|
214
215
|
return sendJson(res, { ok: true, theme: state.theme, pid: process.pid }, 200, ae);
|
|
215
216
|
}
|
|
216
217
|
for (const [prefix, handler] of PREFIX_ROUTES) {
|
|
217
|
-
if (path.startsWith(prefix)) return sendJson(res, handler(st, path), 200, ae);
|
|
218
|
+
if (path.startsWith(prefix)) return sendJson(res, handler(st, path, state), 200, ae);
|
|
218
219
|
}
|
|
219
220
|
if (path === '/api/docs') {
|
|
220
221
|
return sendJson(res, apiDocs(st, harnessParam(req.url)), 200, ae);
|
|
@@ -468,7 +469,7 @@ export function makeHandler(state, jm, token, dist, holder = null) {
|
|
|
468
469
|
try {
|
|
469
470
|
return doPost(req, res, path, ae, buf);
|
|
470
471
|
} catch (e) {
|
|
471
|
-
// `
|
|
472
|
+
// `installView`, `apiMemoryDelete`, `apiRulesMutate` and `apiRulesPromote` all
|
|
472
473
|
// raise `NotFound` for an unknown target, mapped to 404
|
|
473
474
|
// here; anything else falls to the generic 500 (`SERVER_FAULT`, below).
|
|
474
475
|
if (e instanceof NotFound) {
|
package/js/web/routes.mjs
CHANGED
|
@@ -16,16 +16,18 @@
|
|
|
16
16
|
* Split out of `server.mjs` because it is the half a reader consults to answer "does the console
|
|
17
17
|
* expose X?", which has nothing to do with sockets, daemons or gzip.
|
|
18
18
|
*/
|
|
19
|
+
import { installTargets } from '../hosts/installs.mjs';
|
|
19
20
|
import { formatValue, isTruthy, parseJson } from '../lib/json.mjs';
|
|
20
21
|
import { percentDecode } from '../lib/text.mjs';
|
|
21
|
-
import { apiExcludesMutate, apiInstallToggle, apiLoopsPresetMutate, apiMcp, apiMemoryDelete,
|
|
22
|
+
import { apiExcludesMutate, apiInstallToggle, apiLoopsPresetMutate, apiMcp, apiMemoryDelete, targetView } from './actions.mjs';
|
|
22
23
|
import { apiActivity, apiActivityDetail, apiActivityToggle } from './activity.mjs';
|
|
23
24
|
import {
|
|
24
25
|
apiDiff, apiDoctor, apiExcludes, apiFleet, apiInstalls, apiKits, apiLoops, apiLoopsActive, apiOverview,
|
|
25
|
-
apiRecent, apiSetup, apiThemes, apiUpdate,
|
|
26
|
+
apiRecent, apiSetup, apiThemes, activeInstalls, apiUpdate,
|
|
26
27
|
} from './api.mjs';
|
|
27
|
-
import { NotFound, apiCatalog, apiItem } from './catalog.mjs';
|
|
28
|
+
import { FLEET_SECTIONS, NotFound, apiCatalog, apiItem } from './catalog.mjs';
|
|
28
29
|
import { apiUsage } from './usage-api.mjs';
|
|
30
|
+
import { fleetSort } from './state.mjs';
|
|
29
31
|
import { apiGates } from './gates-api.mjs';
|
|
30
32
|
import { apiProfile, apiProfileSave, apiRules, apiRulesMutate, apiRulesPromote } from './user-files.mjs';
|
|
31
33
|
|
|
@@ -47,7 +49,6 @@ import { apiProfile, apiProfileSave, apiRules, apiRulesMutate, apiRulesPromote }
|
|
|
47
49
|
export const POST_ROUTES = new Map([
|
|
48
50
|
['/api/install', [apiInstallToggle, true]],
|
|
49
51
|
['/api/excludes', [apiExcludesMutate, true]],
|
|
50
|
-
['/api/view', [apiSelectView, true]],
|
|
51
52
|
['/api/activity', [apiActivityToggle, false]],
|
|
52
53
|
// The dispatch wrapper resolves `name` from the body itself; `apiMemoryDelete` takes a bare
|
|
53
54
|
// slug string, not the body object, unlike the other routes here.
|
|
@@ -64,10 +65,10 @@ export const POST_ROUTES = new Map([
|
|
|
64
65
|
|
|
65
66
|
/**
|
|
66
67
|
* The POSTs whose body `{host, path}` names the install they act on (`installView`), opt-in
|
|
67
|
-
* rather than every POST: in `/api/
|
|
68
|
+
* rather than every POST: in `/api/install` and `/api/actions/install` the pair is
|
|
68
69
|
* the target the route resolves itself, and in `/api/actions/deploy`, `/api/excludes` and
|
|
69
70
|
* `/api/reveal` a `path` is a folder or a config file, not an install. The two `actions/` rows
|
|
70
|
-
* are the only actions that read the
|
|
71
|
+
* are the only actions that read the request's install.
|
|
71
72
|
*/
|
|
72
73
|
export const VIEW_POSTS = new Set(['/api/activity', '/api/memory/delete', '/api/rules',
|
|
73
74
|
'/api/rules/promote', '/api/profile', '/api/actions/restore', '/api/actions/build']);
|
|
@@ -77,11 +78,18 @@ export const VIEW_POSTS = new Set(['/api/activity', '/api/memory/delete', '/api/
|
|
|
77
78
|
* pair (it is neither checked nor used) and always read the daemon's state. Ignored rather
|
|
78
79
|
* than refused, so a client may send its install on every read. On the daemon's state, not a
|
|
79
80
|
* view, because `/api/update` keeps its daily check and the `.git`-lock guard
|
|
80
|
-
* (`_behind.inflight`) there, and the update job checks only that one.
|
|
81
|
-
*
|
|
81
|
+
* (`_behind.inflight`) there, and the update job checks only that one. `/api/activity` merges
|
|
82
|
+
* every active install's sessions; its detail (`/api/activity/<sid>`, a prefix route) and its
|
|
83
|
+
* toggle (a `VIEW_POSTS` write) still take the pair. Every other `/api/*` GET, ping and jobs
|
|
84
|
+
* aside, takes the pair and refuses an unknown one.
|
|
85
|
+
*
|
|
86
|
+
* The Library's fleet lists (`/api/catalog/skills|agents|memory|notebook`) are here because they
|
|
87
|
+
* read every active install (`fleetOf`), which caches one view per install on the daemon state;
|
|
88
|
+
* the other catalog sections, and `/api/item/`, stay install-scoped (`PREFIX_ROUTES`).
|
|
82
89
|
*/
|
|
83
90
|
export const MACHINE_GETS = new Set(['/api/update', '/api/installs', '/api/fleet', '/api/kits',
|
|
84
|
-
'/api/usage', '/api/gates', '/api/excludes', '/api/mcp', '/api/loops/active'
|
|
91
|
+
'/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']);
|
|
85
93
|
|
|
86
94
|
/**
|
|
87
95
|
* The 409 column, exported so a test can assert it directly. Giving `/api/activity` the 409
|
|
@@ -135,20 +143,45 @@ export function readJsonBody(buf) {
|
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
/**
|
|
138
|
-
*
|
|
146
|
+
* Every ACTIVE install as `{install, state}`, the Library's fleet lists' source (skills, agents,
|
|
147
|
+
* memory, notebook: `FLEET_SECTIONS`): `install`
|
|
148
|
+
* is the usage ledger's `host:scope:root` key, `state` the install's cached view off the daemon
|
|
149
|
+
* state `base` (`targetView`), so each install keeps its own inventory cache. ONE
|
|
150
|
+
* `installTargets()` scan: the targets it yields are the allowlist, so no view re-checks its
|
|
151
|
+
* pair the way a request-named one must (`installView`). In the console's install order
|
|
152
|
+
* (`fleetSort`), not as `installTargets` yields, which puts the cwd's projects first. No active
|
|
153
|
+
* install leaves `base` alone, keyless, as one install answered.
|
|
154
|
+
*/
|
|
155
|
+
function fleetOf(base) {
|
|
156
|
+
const views = fleetSort([...activeInstalls(installTargets())], (t) => [t[0], t[1]])
|
|
157
|
+
.map(([host, scope, root]) => ({ install: `${host}:${scope}:${root}`,
|
|
158
|
+
state: targetView(base, [host, scope, root]) }));
|
|
159
|
+
return views.length ? views : [{ install: null, state: base }];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The prefix routes — path in, response out. `base` is the daemon's own state, which `state`
|
|
164
|
+
* is when the request named no install: the fleet's views are cached there, never on a view.
|
|
139
165
|
*
|
|
140
166
|
* `percentDecode` and not `decodeURIComponent`: the JS builtin throws a `URIError` on a `%`
|
|
141
167
|
* that is not an escape, where this shell instead answers a 404 naming the literal text.
|
|
142
168
|
*/
|
|
143
|
-
/** @type {Array<[string, (state: any, path: string) => any]>} */
|
|
169
|
+
/** @type {Array<[string, (state: any, path: string, base: any) => any]>} */
|
|
144
170
|
export const PREFIX_ROUTES = [
|
|
145
|
-
|
|
171
|
+
// The `FLEET_SECTIONS` list every install (`MACHINE_GETS`); the other sections the named one.
|
|
172
|
+
['/api/catalog/', (state, p, base) => {
|
|
173
|
+
const sec = p.split('/').pop();
|
|
174
|
+
return apiCatalog(state, sec, FLEET_SECTIONS.includes(sec) ? fleetOf(base) : undefined);
|
|
175
|
+
}],
|
|
146
176
|
// /api/item/<type>/<name> — TYPE has no slash, the NAME keeps its slashes so a wiki
|
|
147
177
|
// page's relpath survives. A missing name is a 404 here rather than a 500 two frames down.
|
|
148
|
-
|
|
178
|
+
// Install-scoped: a skill, agent, memory or notebook entry is the named install's copy, else
|
|
179
|
+
// the fleet's first.
|
|
180
|
+
['/api/item/', (state, p, base) => {
|
|
149
181
|
const m = /^\/api\/item\/([^/]+)\/(.+)$/.exec(p);
|
|
150
182
|
if (!m) throw new NotFound(p);
|
|
151
|
-
|
|
183
|
+
const fleet = ['skill', 'agent', 'memory', 'notebook'].includes(m[1]) ? fleetOf(base) : undefined;
|
|
184
|
+
return apiItem(state, m[1], percentDecode(m[2]), fleet);
|
|
152
185
|
}],
|
|
153
186
|
// The sid is passed through unquoted — `apiActivityDetail`'s safe-name scheme is what
|
|
154
187
|
// makes the lookup safe, rather than a check out here.
|
package/js/web/server.mjs
CHANGED
|
@@ -22,22 +22,22 @@
|
|
|
22
22
|
* port's NOT_PORTED / DECLINED partition emptied for good and was retired — the declared
|
|
23
23
|
* surface now lives in `js/web/routes.mjs` and `tests/unit/web_server.test.mjs`.
|
|
24
24
|
*/
|
|
25
|
-
import {
|
|
25
|
+
import { resolvePath } from '../hosts/hosts.mjs';
|
|
26
26
|
import { isFile, printOut } from '../lib/fs.mjs';
|
|
27
27
|
import { which } from '../lib/paths.mjs';
|
|
28
28
|
import { parseIntStrict } from '../lib/text.mjs';
|
|
29
29
|
import { promptLine } from '../lib/prompt.mjs';
|
|
30
|
-
import {
|
|
30
|
+
import { deployed } from './catalog.mjs';
|
|
31
|
+
import { defaultView, warmDoctor, webState } from './state.mjs';
|
|
31
32
|
import { clearDaemon, codeStamp, openUrl, readDaemon, restartDaemon, startDaemon, statusDaemon, stopDaemon, writeDaemon } from './daemon.mjs';
|
|
32
33
|
import { makeHandler } from './handler.mjs';
|
|
33
34
|
import { JobManager } from './jobs.mjs';
|
|
34
35
|
import { spawnSync } from 'node:child_process';
|
|
35
36
|
import { randomBytes } from 'node:crypto';
|
|
36
|
-
import { existsSync } from 'node:fs';
|
|
37
37
|
import { createServer } from 'node:http';
|
|
38
38
|
import { join, resolve as pathResolve } from 'node:path';
|
|
39
39
|
import { fileURLToPath } from 'node:url';
|
|
40
|
-
import {
|
|
40
|
+
import { sweepInstalls } from './activity.mjs';
|
|
41
41
|
|
|
42
42
|
const ROOT = pathResolve(import.meta.dirname, '..', '..');
|
|
43
43
|
|
|
@@ -133,13 +133,13 @@ export async function serve({ theme = null, port = 4747, openBrowser = true,
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
const state = webState(theme);
|
|
136
|
-
// The daemon record and the job file stay at the
|
|
137
|
-
// moves: `geneseed web stop`/`status` find them through
|
|
138
|
-
// moves, and a
|
|
136
|
+
// The daemon record and the job file stay at the FIRST target, captured before the state
|
|
137
|
+
// moves to the default install: `geneseed web stop`/`status` find them through
|
|
138
|
+
// `webState(theme).target`, which never moves, and a state on a Bob-only ~/.bob would hide it.
|
|
139
139
|
const home = state.target;
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
if (!
|
|
140
|
+
const def = defaultView();
|
|
141
|
+
if (def) state.selectView(...def);
|
|
142
|
+
if (!deployed(state)) {
|
|
143
143
|
printOut(`[web] no deployed harness at ${state.target}.\n`);
|
|
144
144
|
printOut(' Run `geneseed setup` first — serving anyway (read-only UI).\n');
|
|
145
145
|
}
|
|
@@ -154,9 +154,10 @@ export async function serve({ theme = null, port = 4747, openBrowser = true,
|
|
|
154
154
|
// Read by `/api/update`, whose background `git fetch` must not race a running update's pull.
|
|
155
155
|
state.jobBusy = () => jm.busy;
|
|
156
156
|
const srv = createServer(makeHandler(state, jm, token, dist, holder));
|
|
157
|
-
// A GET only reads, and the OpenCode plugin never sweeps: ended sessions are archived here,
|
|
158
|
-
// once at start and every 10 minutes. Best-effort — a sweep failure never
|
|
159
|
-
|
|
157
|
+
// A GET only reads, and the OpenCode plugin never sweeps: ended sessions are archived here, in
|
|
158
|
+
// every active install, once at start and every 10 minutes. Best-effort — a sweep failure never
|
|
159
|
+
// stops the console.
|
|
160
|
+
const sweep = () => { try { sweepInstalls(); } catch { /* best-effort */ } };
|
|
160
161
|
sweep();
|
|
161
162
|
setInterval(sweep, 600_000).unref();
|
|
162
163
|
// A client trickling headers or a body (slowloris) would hold a socket forever otherwise; every
|
package/js/web/state.mjs
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
import { existsSync } from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
|
|
11
|
-
import { CLAUDE_STYLE,
|
|
11
|
+
import { CLAUDE_STYLE, HOSTS, opencodeConfigDir, resolvePath } from '../hosts/hosts.mjs';
|
|
12
|
+
import { normcase } from '../lib/paths.mjs';
|
|
12
13
|
import {
|
|
13
14
|
EMIT_HOST_SCOPE, footprintOfDir, installState, installTargets, installedDefaults, modeOfDir,
|
|
14
15
|
postureOfDir, themeOfDir, trustOfDir,
|
|
@@ -30,22 +31,42 @@ export function viewCfg(host, scope, root) {
|
|
|
30
31
|
return root;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/** Two paths name the same folder: resolved, and case-folded where the filesystem folds case. */
|
|
35
|
+
export const samePath = (a, b) => normcase(resolvePath(a)) === normcase(resolvePath(b));
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The console's ONE install order, for every fleet-wide answer (the Library's lists, the Activity
|
|
39
|
+
* garden): host order (`HOSTS`), then global before project, then the input's own order — the
|
|
40
|
+
* sort is stable. `of(item)` gives `[host, scope]`. Sorts `list` in place and returns it. Here
|
|
41
|
+
* beside `viewCfg`, the other per-install rule both callers use, because `activity.mjs` and
|
|
42
|
+
* `routes.mjs` both import this module and it imports neither.
|
|
43
|
+
*/
|
|
44
|
+
export function fleetSort(list, of) {
|
|
45
|
+
const rank = (it) => {
|
|
46
|
+
const [host, scope] = of(it);
|
|
47
|
+
return HOSTS.findIndex((h) => h.host === host) * 2 + (scope === 'global' ? 0 : 1);
|
|
48
|
+
};
|
|
49
|
+
return list.sort((a, b) => rank(a) - rank(b));
|
|
50
|
+
}
|
|
51
|
+
|
|
33
52
|
/**
|
|
34
|
-
* `[target, root]`
|
|
35
|
-
* when
|
|
53
|
+
* `[target, root]` of THE DEFAULT INSTALL — the one a request that names no install reads — or
|
|
54
|
+
* null when no install is active.
|
|
36
55
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
56
|
+
* It is the first ACTIVE install in the console's one install order (`fleetSort`): host order
|
|
57
|
+
* (opencode, claude, bob, openclaude), then global before project, then the order
|
|
58
|
+
* `installTargets` found them.
|
|
59
|
+
* There is no viewed install to pick any more (the topbar selector and `POST /api/view` are
|
|
60
|
+
* gone): a page that wants another install names it on the request. The console once opened
|
|
61
|
+
* on the OpenCode global dir unconditionally, and on a Bob-only machine (reported 2026-10) it
|
|
62
|
+
* showed the onboarding form over a working `~/.bob`; this order cannot. The console's own
|
|
63
|
+
* pickers take their default from the row `/api/installs` marks `default`, which is this one.
|
|
42
64
|
*/
|
|
43
|
-
export function
|
|
44
|
-
if (existsSync(path.join(current, GLOBAL_MANIFEST))) return null;
|
|
65
|
+
export function defaultView(targets = installTargets()) {
|
|
45
66
|
const active = targets.filter(([host, scope, root]) => {
|
|
46
67
|
try { return installState(root, host, scope) === 'active'; } catch { return false; }
|
|
47
68
|
});
|
|
48
|
-
const pick = active
|
|
69
|
+
const pick = fleetSort(active, ([host, scope]) => [host, scope])[0];
|
|
49
70
|
return pick ? [viewCfg(...pick), pick[2]] : null;
|
|
50
71
|
}
|
|
51
72
|
|
|
@@ -195,12 +216,12 @@ export function webState(theme = null, target = null) {
|
|
|
195
216
|
};
|
|
196
217
|
/** This state alone. `refresh` below is what callers use: it also reaches every view. */
|
|
197
218
|
st.refreshOwn = ({ doctor = true } = {}) => {
|
|
198
|
-
// A job may have deployed the first install
|
|
199
|
-
//
|
|
219
|
+
// A job may have deployed the first install, or switched off or removed the default, so
|
|
220
|
+
// the daemon's own state moves to whatever the default install is now (`defaultView`).
|
|
200
221
|
// Only on a full refresh: `{ doctor: false }` marks a mutation that cannot change installs.
|
|
201
222
|
// Never for a pinned view: it answers for the install its request named, or is refused.
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
223
|
+
const def = doctor && !st.pinned ? defaultView() : null;
|
|
224
|
+
if (def && !samePath(def[0], st.target)) { st.selectView(...def); return; }
|
|
204
225
|
st._inv = null;
|
|
205
226
|
if (doctor) st._doctor = null;
|
|
206
227
|
st.emit = st.detectEmit() || st.emit;
|
package/js/web/usage-api.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import path from 'node:path';
|
|
|
28
28
|
import { USAGE_LEDGER, USAGE_OFF } from '../hosts/usage.mjs';
|
|
29
29
|
import { installTargets } from '../hosts/installs.mjs';
|
|
30
30
|
import { activeInstalls, lastDays } from './api.mjs';
|
|
31
|
+
import { deployedLayer } from './catalog.mjs';
|
|
31
32
|
|
|
32
33
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
33
34
|
const WINDOW = 30;
|
|
@@ -88,12 +89,15 @@ export function usageSummary({ now = Date.now(), targets = installTargets() } =
|
|
|
88
89
|
counts.set(key, (counts.get(key) || 0) + 1);
|
|
89
90
|
fired.add(`${e.kind}\u0000${e.name}`);
|
|
90
91
|
}
|
|
91
|
-
for
|
|
92
|
-
|
|
92
|
+
// The specs the host loads: for an OpenCode project install that is `<repo>/.opencode`, not
|
|
93
|
+
// the root's flat bundle (the ledger above stays in the root's notebook/).
|
|
94
|
+
const layer = deployedLayer({ target: dir }) ?? dir;
|
|
95
|
+
for (const name of listOr(path.join(layer, 'skills'))) {
|
|
96
|
+
if (existsSync(path.join(layer, 'skills', name, 'SKILL.md')) && !fired.has(`skill\u0000${name}`)) {
|
|
93
97
|
never.push({ install, kind: 'skill', name });
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
|
-
for (const f of listOr(path.join(
|
|
100
|
+
for (const f of listOr(path.join(layer, 'agents'))) {
|
|
97
101
|
const name = f.endsWith('.md') ? f.slice(0, -3) : null;
|
|
98
102
|
if (name && !fired.has(`agent\u0000${name}`)) never.push({ install, kind: 'agent', name });
|
|
99
103
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"//": "Every field here is argued and gated in tests/unit/package_manifest.test.mjs. `files`, `bin` and `engines` each have a test that fails when reality drifts from this file; `version` mirrors harness.config.json and is gated too. Read that docblock before editing this one.",
|
|
3
3
|
"name": "geneseed",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.31.0",
|
|
5
5
|
"description": "A portable, theme-able harness you implant once and use everywhere to grow a disciplined AI coding agent.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"ai",
|