geneseed 6.0.1 → 6.0.3
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 +20 -0
- package/SHIPPED.md +1 -1
- package/adapters/opencode/plugins/geneseed-context.js +53 -10
- package/adapters/opencode/plugins/geneseed-learn.js +11 -4
- package/docs/concepts/agents.md +2 -2
- package/docs/web-ui.md +25 -0
- package/harness.config.json +1 -1
- package/js/README.md +2 -1
- package/js/build/bundle.mjs +2 -11
- package/js/build/emit-claude.mjs +2 -2
- package/js/build/emit-opencode.mjs +4 -2
- package/js/build/fold.mjs +3 -20
- package/js/build/source.mjs +1 -1
- package/js/build/stubs.mjs +42 -5
- package/js/cli-table.json +1 -1
- package/js/hosts/hooks-context.mjs +65 -9
- package/js/hosts/memory-files.mjs +166 -13
- package/js/hosts/native.mjs +48 -27
- package/js/hosts/opencode.mjs +3 -2
- package/js/inspect/checks-build.mjs +2 -2
- package/js/inspect/doctor.mjs +2 -0
- package/js/inspect/status.mjs +4 -1
- package/js/maintain/memory.mjs +2 -2
- package/js/web/agent-models-api.mjs +52 -17
- package/js/web/api.mjs +3 -0
- package/js/web/catalog.mjs +5 -3
- package/js/web/model-catalog.mjs +324 -0
- package/js/web/routes.mjs +5 -3
- package/package.json +1 -1
- package/src/agents/memory-curator.md +1 -1
- package/src/memory/README.md +24 -5
- package/src/skills/rule/approve.md +3 -1
- package/src/skills/rule/consolidate.md +1 -1
- package/web/dist/assets/ActiveLoops-paFbiZyt.js +1 -0
- package/web/dist/assets/Activity-IAxWF2wK.js +1 -0
- package/web/dist/assets/ActivityDetail-CtC2DLvh.js +1 -0
- package/web/dist/assets/{Bonsai-8NtlFrPO.js → Bonsai-BoKo68Kw.js} +1 -1
- package/web/dist/assets/{CopyButton-BHqKgdjJ.js → CopyButton-C0VTiqmb.js} +1 -1
- package/web/dist/assets/Dashboard-CRGCp2cV.js +2 -0
- package/web/dist/assets/{Docs-C1jzrFnD.js → Docs-DwOwzaD6.js} +2 -2
- package/web/dist/assets/Factories-DxHD2T-1.js +1 -0
- package/web/dist/assets/{GreenhouseView-ofAQ-V5h.js → GreenhouseView-D5VOmhmR.js} +1 -1
- package/web/dist/assets/Installs-B5hFSUeN.js +3 -0
- package/web/dist/assets/JournalView-gUSGysTm.js +1 -0
- package/web/dist/assets/{Kits-P4xspDuN.js → Kits-DYQvykZ0.js} +1 -1
- package/web/dist/assets/Laws-UVk0uojS.js +4 -0
- package/web/dist/assets/{LibRows-CGO25X3D.js → LibRows-CwK63kjB.js} +1 -1
- package/web/dist/assets/Library-DdzyrwUK.js +3 -0
- package/web/dist/assets/Loops-yHga7xdr.js +2 -0
- package/web/dist/assets/Models-DAgkQ4CE.js +1 -0
- package/web/dist/assets/{OperatorHudView-Cc8mlViW.js → OperatorHudView-D1lQF-ZY.js} +1 -1
- package/web/dist/assets/Personal-DjhIfa9v.js +2 -0
- package/web/dist/assets/Settings-Brgec4M0.js +1 -0
- package/web/dist/assets/Tabs-BHjxciOL.js +1 -0
- package/web/dist/assets/api-C8nMUU1i.js +1 -0
- package/web/dist/assets/index-BILaKHbH.js +6 -0
- package/web/dist/assets/index-BfyZCNu7.css +1 -0
- package/web/dist/assets/router-1EhRJy1C.js +1 -0
- package/web/dist/assets/useLocalStorage-54tkqXN7.js +1 -0
- package/web/dist/index.html +5 -3
- package/web/dist/assets/ActiveLoops-6p44eD86.js +0 -1
- package/web/dist/assets/Activity-CIgrq5R1.js +0 -1
- package/web/dist/assets/ActivityDetail-Brqv1u4f.js +0 -1
- package/web/dist/assets/Dashboard-CoveJ_-U.js +0 -2
- package/web/dist/assets/Factories-D5pLnt5S.js +0 -1
- package/web/dist/assets/Installs-DpWgyT5j.js +0 -3
- package/web/dist/assets/JournalView-CsuN3_B-.js +0 -1
- package/web/dist/assets/Laws-DK3OwGDl.js +0 -4
- package/web/dist/assets/Library-e-94YED6.js +0 -3
- package/web/dist/assets/Loops-C9DSBj-A.js +0 -2
- package/web/dist/assets/Personal-DVh2jYPO.js +0 -2
- package/web/dist/assets/Settings-CknBI-Fx.js +0 -1
- package/web/dist/assets/Tabs-C30JrkJH.js +0 -1
- package/web/dist/assets/api-DxwG8y94.js +0 -1
- package/web/dist/assets/index-CUJ8AaAF.css +0 -1
- package/web/dist/assets/index-MB7E-va_.js +0 -6
- package/web/dist/assets/usePoll-D5c_qIFZ.js +0 -1
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
* import `js/web` (spec C20).
|
|
16
16
|
*/
|
|
17
17
|
import { isUtf8 } from 'node:buffer';
|
|
18
|
+
import { createHash } from 'node:crypto';
|
|
18
19
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmdirSync, unlinkSync } from 'node:fs';
|
|
19
20
|
import path from 'node:path';
|
|
20
21
|
import { readText, writeText, writeTextAtomic } from '../lib/fs.mjs';
|
|
21
|
-
import { isDict } from '../lib/json.mjs';
|
|
22
|
+
import { isDict, jsonDumpsIndent } from '../lib/json.mjs';
|
|
22
23
|
import { normcase } from '../lib/paths.mjs';
|
|
23
24
|
import { WHITESPACE, stripWhitespace } from '../lib/text.mjs';
|
|
24
25
|
import { isFile, listDir, sortPaths, splitLines, splitWords } from './hooks-prims.mjs';
|
|
@@ -115,12 +116,25 @@ function globMd(dir) {
|
|
|
115
116
|
/** Stems that name the store's own files, never a fact — `MEMORY` is the index itself. */
|
|
116
117
|
export const RESERVED_STEMS = new Set(['memory', 'readme']);
|
|
117
118
|
|
|
119
|
+
/**
|
|
120
|
+
* IS THIS TOP-LEVEL STEM A STORE DOCUMENT RATHER THAN A FACT? (D2) `memory` and `readme` in any case,
|
|
121
|
+
* and any stem written wholly in capitals: `MEMORY`, `README`, `ARCHIVE-INDEX`. A person names the
|
|
122
|
+
* documents that describe a store in capitals, and a fact is a lower-case slug. Without
|
|
123
|
+
* this a hand-written `ARCHIVE-INDEX.md` was indexed as a fact under `misc`, listed to `learn`, and
|
|
124
|
+
* counted by the curation nudge. A stem with no letter in it (`2026`) is no document: it has no case.
|
|
125
|
+
*
|
|
126
|
+
* ONE PREDICATE, EVERY READER: the plugins carry a twin (`geneseed-learn.js`), the console's
|
|
127
|
+
* `isFurniture` and `geneseed memory rm` call this one, so a list and its count cannot disagree.
|
|
128
|
+
*/
|
|
129
|
+
export const isReservedStem = (stem) => RESERVED_STEMS.has(stem.toLowerCase())
|
|
130
|
+
|| (stem === stem.toUpperCase() && stem !== stem.toLowerCase());
|
|
131
|
+
|
|
118
132
|
/**
|
|
119
133
|
* `_existing_slugs` — slugs already stored. learn never CREATES one of these; it may only
|
|
120
134
|
* update or archive it by name (`writeMemories`).
|
|
121
135
|
*/
|
|
122
136
|
export function existingSlugs(memDir) {
|
|
123
|
-
return new Set(globMd(memDir).map(stem).filter((s) => !
|
|
137
|
+
return new Set(globMd(memDir).map(stem).filter((s) => !isReservedStem(s)));
|
|
124
138
|
}
|
|
125
139
|
|
|
126
140
|
/**
|
|
@@ -169,7 +183,7 @@ export function readFacts(memDir) {
|
|
|
169
183
|
const facts = new Map();
|
|
170
184
|
for (const name of sortPaths(globMd(memDir))) {
|
|
171
185
|
const s = stem(name);
|
|
172
|
-
if (
|
|
186
|
+
if (isReservedStem(s)) continue;
|
|
173
187
|
try {
|
|
174
188
|
const [fm] = frontmatter(readText(path.join(memDir, name)));
|
|
175
189
|
facts.set(s, { desc: fmGet(fm, 'description').trim(), topic: topicOf(fm) });
|
|
@@ -212,13 +226,14 @@ export function indexNotes(memDir, generated) {
|
|
|
212
226
|
* Rewrite MEMORY.md as the map: one line per topic file with its fact count.
|
|
213
227
|
*
|
|
214
228
|
* LINES THE MAP DID NOT GENERATE ARE CARRIED, so a note the user wrote into the index
|
|
215
|
-
* survives. `
|
|
216
|
-
*
|
|
217
|
-
*
|
|
229
|
+
* survives. `generated(slug)` says which legacy flat fact pointers a rebuild has just moved into
|
|
230
|
+
* topic files, and only those are dropped (D4): a pointer to a store document (`ARCHIVE-INDEX`) or
|
|
231
|
+
* to a fact that is not on disk is no fact line, so it stays like any other line a person wrote.
|
|
232
|
+
* With no topic and nothing carried, the file goes back to the seed.
|
|
218
233
|
*/
|
|
219
|
-
function writeMap(memDir,
|
|
234
|
+
function writeMap(memDir, generated) {
|
|
220
235
|
const idx = path.join(memDir, 'MEMORY.md');
|
|
221
|
-
const carried = indexNotes(memDir,
|
|
236
|
+
const carried = indexNotes(memDir, generated);
|
|
222
237
|
const tdir = path.join(memDir, TOPICS);
|
|
223
238
|
const topics = globMd(tdir).map(stem).sort().map((t) => {
|
|
224
239
|
const n = (readLines(path.join(tdir, `${t}.md`)) ?? [])
|
|
@@ -264,7 +279,12 @@ function rebuildIndex(memDir, refresh, fresh = new Set()) {
|
|
|
264
279
|
writeIfChanged(path.join(tdir, `${topic}.md`), `# ${topic}\n\n${lines.join('\n')}\n`);
|
|
265
280
|
}
|
|
266
281
|
if (!byTopic.size) pruneTopicsDir(memDir);
|
|
267
|
-
|
|
282
|
+
// A flat pointer is generated, and so dropped, unless it names a STORE DOCUMENT (`ARCHIVE-INDEX.md`):
|
|
283
|
+
// a fact's pointer has moved into a topic file, a dead one (no such file) is the old rule's, and
|
|
284
|
+
// a document is no fact, so its line is one a person wrote and stays (D4).
|
|
285
|
+
const known = new Set([...facts.keys()].map((slug) => slug.toLowerCase()));
|
|
286
|
+
const documents = new Set(globMd(memDir).map((n) => stem(n).toLowerCase()).filter((s) => !known.has(s)));
|
|
287
|
+
writeMap(memDir, (slug) => !documents.has(slug.toLowerCase()));
|
|
268
288
|
return { facts, old };
|
|
269
289
|
}
|
|
270
290
|
|
|
@@ -276,12 +296,27 @@ function rebuildIndex(memDir, refresh, fresh = new Set()) {
|
|
|
276
296
|
* `topics/*.md` only, never a fact file, and it keeps each pointer's own title and hook.
|
|
277
297
|
*/
|
|
278
298
|
export function migrateMemoryIndex(memDir) {
|
|
279
|
-
|
|
280
|
-
if (!lines?.some((l) => FACT_LINE_RE.test(l.trim())) || !existingSlugs(memDir).size) return false;
|
|
299
|
+
if (!holdsFlatFacts(memDir)) return false;
|
|
281
300
|
rebuildIndex(memDir, false);
|
|
282
301
|
return true;
|
|
283
302
|
}
|
|
284
303
|
|
|
304
|
+
/**
|
|
305
|
+
* Does MEMORY.md still hold a flat pointer to a STORED fact? The one test of "this index is flat",
|
|
306
|
+
* for the migration and for the pick of always-on candidates (`alwaysOnCandidates`). A pointer to a
|
|
307
|
+
* store document or to a fact that is gone is carried by the migration (D4) and is no fact to move,
|
|
308
|
+
* so a migrated index that carries one is not flat, and the next emit finds nothing to do.
|
|
309
|
+
*/
|
|
310
|
+
export function holdsFlatFacts(memDir) {
|
|
311
|
+
const lines = readLines(path.join(memDir, 'MEMORY.md'));
|
|
312
|
+
if (!lines) return false;
|
|
313
|
+
const slugs = new Set([...existingSlugs(memDir)].map((s) => s.toLowerCase()));
|
|
314
|
+
return lines.some((l) => {
|
|
315
|
+
const m = FACT_LINE_RE.exec(l.trim());
|
|
316
|
+
return m !== null && slugs.has(m[2].toLowerCase());
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
285
320
|
/** The chunk without its frontmatter `action:` line, which is an instruction, not the fact. */
|
|
286
321
|
function stripAction(chunk) {
|
|
287
322
|
const lines = chunk.split('\n');
|
|
@@ -350,7 +385,7 @@ export function writeMemories(modelOutput, memDir, existing) {
|
|
|
350
385
|
const name = fmGet(fm, 'name').trim();
|
|
351
386
|
const key = name.toLowerCase();
|
|
352
387
|
const action = fmGet(fm, 'action').trim().toLowerCase() || 'create';
|
|
353
|
-
if (!MEMORY_SLUG_RE.test(name) ||
|
|
388
|
+
if (!MEMORY_SLUG_RE.test(name) || isReservedStem(name) || done.has(key)) continue;
|
|
354
389
|
const slug = stored.get(key);
|
|
355
390
|
if (slug && action !== 'create' && hasForce(memDir, slug)) continue;
|
|
356
391
|
const body = `${stripAction(chunk).replace(/\n+$/, '')}\n`;
|
|
@@ -414,7 +449,7 @@ export function memoryDropIndex(memDir, name) {
|
|
|
414
449
|
}
|
|
415
450
|
if (!touched) return;
|
|
416
451
|
pruneTopicsDir(memDir);
|
|
417
|
-
try { writeMap(memDir, false); } catch { /* best-effort */ }
|
|
452
|
+
try { writeMap(memDir, () => false); } catch { /* best-effort */ }
|
|
418
453
|
}
|
|
419
454
|
|
|
420
455
|
/** Drop every line holding `needle`; the kept lines when something went, else null. */
|
|
@@ -618,3 +653,121 @@ export function readFoldState(shared) {
|
|
|
618
653
|
if (blank(state.items)) state.items = {};
|
|
619
654
|
return state;
|
|
620
655
|
}
|
|
656
|
+
|
|
657
|
+
export const itemKey = (kind, host, bytes) => createHash('sha256').update(`${kind}\0${host}\0`).update(bytes).digest('hex');
|
|
658
|
+
|
|
659
|
+
const DRAFT_HEAD = '# User rules — draft\n\nNot active. The rule Rite or the console applies decisions.\n';
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* A block in the draft and a C7 record. The key names the host too, so two hosts holding the same
|
|
663
|
+
* text are two decisions. Draft first: a stop between the writes leaves a block the next run
|
|
664
|
+
* recognises, not a lost one. `extra` rides on the ledger row (`fact`, for a memory candidate).
|
|
665
|
+
*
|
|
666
|
+
* HERE, NOT IN THE FOLD, since D31: the tier's memory step (`ensureSharedTier`, `stubs.mjs`) drafts too,
|
|
667
|
+
* and `fold.mjs` imports `stubs.mjs` for its seeds, so the fold's home for this would be a cycle.
|
|
668
|
+
*/
|
|
669
|
+
export function draftItem(kind, key, block, tally, { host, shared, dryRun, report }, extra = {}) {
|
|
670
|
+
const state = readFoldState(shared);
|
|
671
|
+
if (state.items[key]) return;
|
|
672
|
+
report[tally] += 1;
|
|
673
|
+
if (dryRun) return;
|
|
674
|
+
const text = existsSync(shared.draft) ? readText(shared.draft) : DRAFT_HEAD;
|
|
675
|
+
if (!text.includes(`sha256: ${key}`)) writeTextAtomic(shared.draft, `${text}\n${block}`);
|
|
676
|
+
state.items[key] = { kind, host, state: 'pending', ...extra };
|
|
677
|
+
writeTextAtomic(shared.foldState, `${jsonDumpsIndent(state)}\n`);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* The part of a flat MEMORY.md the session hook used to inject, in characters. Memory was the 4th
|
|
682
|
+
* of 5 session files, and what the 9 000-character payload left after the rules, profile and
|
|
683
|
+
* wiki was cut by position (`capToRoom`): 3 072 of 8 509 characters on the machine this was
|
|
684
|
+
* measured on (2026-11-18). A rule whose pointer sat inside that part was in force by ACCIDENT of
|
|
685
|
+
* its line number, which is exactly what a draft asks the user to turn into a decision.
|
|
686
|
+
*/
|
|
687
|
+
export const LEGACY_INJECT_CHARS = 3072;
|
|
688
|
+
/** At most this many candidates are drafted at one migration: a console of 100 drafts is noise. */
|
|
689
|
+
export const MAX_ALWAYS_ON = 30;
|
|
690
|
+
const ALWAYS_WORDS_RE = /\b(?:always|never|toujours|jamais)\b/i;
|
|
691
|
+
const DRAFT_BODY_MAX = 1500;
|
|
692
|
+
const DRAFT_TITLE_MAX = 100;
|
|
693
|
+
export const MEMORY_DRAFT_HOST = 'memory';
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Whether `learn` can run here (D12): it needs `$GENESEED_LLM`, and with it unset the Stop hook
|
|
697
|
+
* returns early and no fact is ever distilled, which nothing used to say. One wording for `status`
|
|
698
|
+
* and `doctor`.
|
|
699
|
+
*/
|
|
700
|
+
export const learnState = (env = process.env) => (env.GENESEED_LLM ? 'active' : 'dormant ($GENESEED_LLM unset)');
|
|
701
|
+
|
|
702
|
+
const oneLine = (text, max) => {
|
|
703
|
+
const t = text.replace(/\s+/g, ' ').trim();
|
|
704
|
+
return t.length > max ? `${t.slice(0, max - 1)}…` : t;
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* A fact's text as a rule body. A `## ` line would end the draft's block and open another, so it
|
|
709
|
+
* is demoted to `### `; a long fact is cut and says where the rest is. The description stands in
|
|
710
|
+
* for an empty body.
|
|
711
|
+
*/
|
|
712
|
+
function draftBody(body, desc) {
|
|
713
|
+
const text = stripWhitespace(body.replace(/^## /gm, '### ')) || desc;
|
|
714
|
+
return text.length > DRAFT_BODY_MAX ? `${text.slice(0, DRAFT_BODY_MAX)}…\n(cut: the whole fact is in memory/)` : text;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* The facts a FLAT index would have loaded at every session and that read as standing rules (D31),
|
|
719
|
+
* picked without a model: `force: constraint`, or a `feedback` fact whose pointer sat in the
|
|
720
|
+
* injected part (`LEGACY_INJECT_CHARS`), or a `feedback` fact whose description says always,
|
|
721
|
+
* never (or toujours, jamais). Priority in that order, then slug; `[]` for a store that is
|
|
722
|
+
* not flat, so a second emit picks nothing. Read BEFORE `migrateMemoryIndex`, which erases the
|
|
723
|
+
* flat index. Each is `{ slug, title, body, reason }`.
|
|
724
|
+
*/
|
|
725
|
+
export function alwaysOnCandidates(memDir) {
|
|
726
|
+
if (!holdsFlatFacts(memDir)) return [];
|
|
727
|
+
const lines = readLines(path.join(memDir, 'MEMORY.md'));
|
|
728
|
+
const injected = new Set();
|
|
729
|
+
let at = 0;
|
|
730
|
+
for (const line of lines) {
|
|
731
|
+
at += line.length + 1;
|
|
732
|
+
const m = FACT_LINE_RE.exec(line.trim());
|
|
733
|
+
if (m && at <= LEGACY_INJECT_CHARS) injected.add(m[2].toLowerCase());
|
|
734
|
+
}
|
|
735
|
+
const rank = { constraint: 0, injected: 1, described: 2 };
|
|
736
|
+
const found = [];
|
|
737
|
+
for (const slug of [...existingSlugs(memDir)].sort()) {
|
|
738
|
+
let fm; let body;
|
|
739
|
+
try { [fm, body] = frontmatter(readText(path.join(memDir, `${slug}.md`))); } catch { continue; }
|
|
740
|
+
const desc = fmGet(fm, 'description').trim();
|
|
741
|
+
// The TYPE, not the topic: `topic:` only files the fact, and a `type: feedback` fact filed under
|
|
742
|
+
// `topic: git` is still a rule about how to work. (A nested `metadata: type:` reads as `type`.)
|
|
743
|
+
const feedback = topicSlug(fmGet(fm, 'type')) === 'feedback';
|
|
744
|
+
const reason = fmGet(fm, 'force').trim().toLowerCase() === 'constraint' ? 'constraint'
|
|
745
|
+
: feedback && injected.has(slug.toLowerCase()) ? 'injected'
|
|
746
|
+
: feedback && ALWAYS_WORDS_RE.test(desc) ? 'described' : null;
|
|
747
|
+
if (!reason) continue;
|
|
748
|
+
found.push({ slug, reason, title: oneLine(desc || slug, DRAFT_TITLE_MAX), body: draftBody(body, desc) });
|
|
749
|
+
}
|
|
750
|
+
return found.sort((a, b) => rank[a.reason] - rank[b.reason]).slice(0, MAX_ALWAYS_ON);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Write each candidate as a draft through the fold's own path, one block and one ledger row, with
|
|
755
|
+
* the fact's slug on the row: the session hook reads it for the bridge slot (D31), and the row
|
|
756
|
+
* leaves the slot when the user decides. Idempotent: `draftItem` skips a key the ledger holds,
|
|
757
|
+
* decided or not. Never touches `user-rules.md`; approval is the console's or the Rite's.
|
|
758
|
+
*/
|
|
759
|
+
export function draftAlwaysOn(shared, candidates) {
|
|
760
|
+
const ctx = { host: MEMORY_DRAFT_HOST, shared, dryRun: false, report: { rules: 0 } };
|
|
761
|
+
let n = 0;
|
|
762
|
+
for (const c of candidates) {
|
|
763
|
+
// The key is the text the way `rule-decide.mjs` re-reads it, so the block can be decided.
|
|
764
|
+
const [rules] = parseRules(`## R0 — ${c.title}\n${c.body}\n`);
|
|
765
|
+
if (rules.length !== 1) continue;
|
|
766
|
+
n += 1;
|
|
767
|
+
const key = itemKey('rule', MEMORY_DRAFT_HOST, `${rules[0].title}\n${rules[0].body}`);
|
|
768
|
+
draftItem('rule', key, `${draftRuleHead(MEMORY_DRAFT_HOST, c.title)}\n`
|
|
769
|
+
+ `(source: ${path.join(shared.memory, `${c.slug}.md`)} | old: R${n} | sha256: ${key})\n`
|
|
770
|
+
+ `${c.body}\n`, 'rules', ctx, { fact: c.slug });
|
|
771
|
+
}
|
|
772
|
+
return ctx.report.rules;
|
|
773
|
+
}
|
package/js/hosts/native.mjs
CHANGED
|
@@ -419,7 +419,7 @@ const WEBFETCH_MARKER = '<!-- webfetch: allow -->';
|
|
|
419
419
|
*/
|
|
420
420
|
function claudeAgentFrontmatter(stem, text, model = null) {
|
|
421
421
|
const fm = [`name: ${stem}`, `description: ${jsonDumps(agentDescription(text))}`];
|
|
422
|
-
// `model` is `
|
|
422
|
+
// `model` is `agentModel(...).model`: the one precedence, resolved by the caller.
|
|
423
423
|
if (model) fm.push(`model: ${model}`);
|
|
424
424
|
if (isReadonly(text)) {
|
|
425
425
|
const list = ['Write', 'Edit', 'NotebookEdit', 'Agent', 'Task'];
|
|
@@ -453,11 +453,18 @@ function bobAgentFrontmatter(stem, text) {
|
|
|
453
453
|
return fm;
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
-
/**
|
|
457
|
-
|
|
456
|
+
/**
|
|
457
|
+
* `_build_emit._opencode_agent_frontmatter`. With `tiers` (`--tiers auto`) an agent the user did
|
|
458
|
+
* not pin gets its tier's model, `provider/model` (V2 may carry a `#variant` suffix, written
|
|
459
|
+
* verbatim; V1's `variant` stays its own key, which `pushOverrideLines` already writes). Without
|
|
460
|
+
* `tiers`, or with a pin, the lines are exactly the override's own: byte-identical to before.
|
|
461
|
+
*/
|
|
462
|
+
function opencodeAgentFrontmatter(stem, text, overrides, theme = null, tier = 'standard', tiers = null) {
|
|
458
463
|
const fm = [`description: ${jsonDumps(agentDescription(text))}`, 'mode: subagent'];
|
|
459
464
|
fm.push(`color: ${agentColor(stem, theme)}`);
|
|
460
|
-
|
|
465
|
+
const ov = agentOverride(overrides, stem);
|
|
466
|
+
const tm = tiers && !isTruthy(ov.model) ? agentModel(tier, null, tiers).model : null;
|
|
467
|
+
pushOverrideLines(fm, tm ? { ...ov, model: tm } : ov);
|
|
461
468
|
if (isReadonly(text)) {
|
|
462
469
|
fm.push('permission:', ' edit: deny',
|
|
463
470
|
` webfetch: ${text.includes(WEBFETCH_MARKER) ? 'allow' : 'deny'}`);
|
|
@@ -535,8 +542,18 @@ const CLAUDE_ALIAS_ENV = Object.freeze({
|
|
|
535
542
|
opus: 'ANTHROPIC_DEFAULT_OPUS_MODEL', sonnet: 'ANTHROPIC_DEFAULT_SONNET_MODEL',
|
|
536
543
|
haiku: 'ANTHROPIC_DEFAULT_HAIKU_MODEL',
|
|
537
544
|
});
|
|
538
|
-
/**
|
|
539
|
-
|
|
545
|
+
/**
|
|
546
|
+
* The model each non-strong tier gets when `tiers.<tier>` names none, per host: THE ONE TABLE of
|
|
547
|
+
* the defaults (spec D2, 2026-11-18 D1). Claude Code has its two aliases. OpenCode and OpenClaude
|
|
548
|
+
* have NONE (O12): a tier routes only once the user picks a model for it, because OpenCode has no
|
|
549
|
+
* alias at all and, on an OpenClaude provider that is not Anthropic, `sonnet`/`haiku` resolve to the
|
|
550
|
+
* parent's model, so a default there would promise a saving it does not give.
|
|
551
|
+
*/
|
|
552
|
+
export const TIER_DEFAULTS = Object.freeze({
|
|
553
|
+
claude: Object.freeze({ standard: 'sonnet', light: 'haiku' }),
|
|
554
|
+
opencode: Object.freeze({}),
|
|
555
|
+
openclaude: Object.freeze({}),
|
|
556
|
+
});
|
|
540
557
|
/** The tier-map keys that take a model; `strong` is the parent's model and takes none (D9). */
|
|
541
558
|
const TIER_MAP_KEYS = ['standard', 'light'];
|
|
542
559
|
|
|
@@ -547,13 +564,13 @@ function envOn(env, name) {
|
|
|
547
564
|
}
|
|
548
565
|
|
|
549
566
|
/**
|
|
550
|
-
* The model a tier gets on
|
|
551
|
-
* `tests/unit/tiers.test.mjs` states every row. `map` is the user's `tiers` map
|
|
567
|
+
* The model a tier gets on `host` (`claude`, `opencode` or `openclaude`), or null (inherit) — pure,
|
|
568
|
+
* so the table in `tests/unit/tiers.test.mjs` states every row. `map` is the user's `tiers` map
|
|
552
569
|
* (`loadTierMap`), `env` the environment.
|
|
553
570
|
*
|
|
554
571
|
* - `strong` never gets a line: it IS the parent's model.
|
|
555
|
-
* - A tier the map does not name gets the
|
|
556
|
-
* names with an empty value is the user choosing inherit.
|
|
572
|
+
* - A tier the map does not name gets the host's default (`TIER_DEFAULTS`: Claude's two aliases,
|
|
573
|
+
* none elsewhere); a tier the map names with an empty value is the user choosing inherit.
|
|
557
574
|
* - D11 (revised 2026-11-17): the alias is ALWAYS written. On Bedrock or Vertex without
|
|
558
575
|
* `ANTHROPIC_DEFAULT_<ALIAS>_MODEL`, Claude Code resolves it to its built-in model id (seen on
|
|
559
576
|
* 2.1.326, Vertex: `haiku` -> claude-haiku-4-5@20251001, and the sub-agent runs), which may not
|
|
@@ -561,14 +578,15 @@ function envOn(env, name) {
|
|
|
561
578
|
* pin it; the doctor prints it (`tierEnvNotes`), the build says nothing. Only the three aliases
|
|
562
579
|
* are checked: any other value is a model id the user wrote and owns.
|
|
563
580
|
*/
|
|
564
|
-
export function
|
|
581
|
+
export function tierModel(tier, map = {}, env = {}, host = 'claude') {
|
|
565
582
|
if (!TIER_MAP_KEYS.includes(tier)) return { model: null, warning: null };
|
|
566
583
|
const named = Object.hasOwn(map, tier);
|
|
567
|
-
const value = named ? map[tier] :
|
|
584
|
+
const value = named ? map[tier] : (Object.hasOwn(TIER_DEFAULTS, host) ? TIER_DEFAULTS[host][tier] : undefined);
|
|
568
585
|
if (!isTruthy(value)) return { model: null, warning: null };
|
|
569
586
|
const alias = String(value).trim().toLowerCase();
|
|
570
587
|
const cloud = ['CLAUDE_CODE_USE_BEDROCK', 'CLAUDE_CODE_USE_VERTEX'].find((n) => envOn(env, n));
|
|
571
|
-
|
|
588
|
+
// The cloud-alias advice is Claude Code's: no other host reads `ANTHROPIC_DEFAULT_*_MODEL` for a tier.
|
|
589
|
+
const need = host === 'claude' && Object.hasOwn(CLAUDE_ALIAS_ENV, alias) ? CLAUDE_ALIAS_ENV[alias] : null;
|
|
572
590
|
const warning = cloud && need && !String(env[need] ?? '').trim()
|
|
573
591
|
? `--tiers auto: ${cloud} is set but ${need} is not, so the ${tier} tier's '${alias}' alias `
|
|
574
592
|
+ `resolves to Claude Code's built-in model id, which may not exist in your cloud project — `
|
|
@@ -578,19 +596,21 @@ export function claudeTierModel(tier, map = {}, env = {}) {
|
|
|
578
596
|
}
|
|
579
597
|
|
|
580
598
|
/**
|
|
581
|
-
* The model one agent gets
|
|
582
|
-
* highest first: the user's pin (`agents.<name>.model`), then the `tiers` map, then the
|
|
583
|
-
* default
|
|
584
|
-
* (`writeNativeLayer`) and the console shows the same answer
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
* `
|
|
588
|
-
* `
|
|
599
|
+
* The model one agent gets, and why — THE ONE HOME of the precedence (spec D5), on every host,
|
|
600
|
+
* highest first: the user's pin (`agents.<name>.model`), then the `tiers` map, then the host's
|
|
601
|
+
* default for the tier (`TIER_DEFAULTS`), then inherit. The emit writes `model` into the agent's
|
|
602
|
+
* frontmatter (`writeNativeLayer`) and the console shows the same answer
|
|
603
|
+
* (`js/web/agent-models-api.mjs`).
|
|
604
|
+
*
|
|
605
|
+
* `tiers` is `{ map, env, host }` while `--tiers auto` is on, else null (a pin still applies);
|
|
606
|
+
* `host` defaults to `claude`. `from`: `pin`, `map` (the map names the tier, an empty value
|
|
607
|
+
* included), `default`, `inherit`.
|
|
608
|
+
* `warning` is `tierModel`'s, and only for a model the tier gave: a pinned agent has none.
|
|
589
609
|
*/
|
|
590
|
-
export function
|
|
610
|
+
export function agentModel(tier, pin, tiers = null) {
|
|
591
611
|
if (isTruthy(pin)) return { model: formatValue(pin), from: 'pin', warning: null };
|
|
592
612
|
if (!tiers) return { model: null, from: 'inherit', warning: null };
|
|
593
|
-
const { model, warning } =
|
|
613
|
+
const { model, warning } = tierModel(tier, tiers.map, tiers.env, tiers.host);
|
|
594
614
|
if (!model) return { model: null, from: 'inherit', warning: null };
|
|
595
615
|
return { model: formatValue(model), from: Object.hasOwn(tiers.map, tier) ? 'map' : 'default', warning };
|
|
596
616
|
}
|
|
@@ -801,14 +821,15 @@ export function writeNativeLayer(items, agentsDir, skillsDir, overrides = null,
|
|
|
801
821
|
// choice. The caller (`emit-claude.mjs`) routes the suppressed names through
|
|
802
822
|
// `writeAliasCommands(..., alsoUserOnly: true)` into `.bob/commands/*.md` instead (O2).
|
|
803
823
|
bobDialect = false,
|
|
804
|
-
// `--tiers auto
|
|
824
|
+
// `--tiers auto`: `{ map, env, host }` (`loadTierMap`, the build env, the real host: Claude Code,
|
|
825
|
+
// OpenClaude or OpenCode), else null — no tier line. Bob's agents take no model at all.
|
|
805
826
|
tiers = null,
|
|
806
827
|
} = {}) {
|
|
807
828
|
const ov = overrides || {};
|
|
808
829
|
if (bobDialect) warnBobIgnored(ov);
|
|
809
830
|
else if (host === 'claude') warnClaudeIgnored(ov);
|
|
810
831
|
// D11: the build never withholds the alias; the doctor warns about a cloud provider (`tierEnvNotes`).
|
|
811
|
-
const tiersHere = tiers &&
|
|
832
|
+
const tiersHere = tiers && !bobDialect ? tiers : null;
|
|
812
833
|
let nAgents = 0;
|
|
813
834
|
let nSkills = 0;
|
|
814
835
|
const written = [];
|
|
@@ -887,8 +908,8 @@ export function writeNativeLayer(items, agentsDir, skillsDir, overrides = null,
|
|
|
887
908
|
let userOnly = false;
|
|
888
909
|
if (folder === 'agents') {
|
|
889
910
|
if (bobDialect) fm = bobAgentFrontmatter(stem, text);
|
|
890
|
-
else if (host === 'claude') fm = claudeAgentFrontmatter(stem, text,
|
|
891
|
-
else fm = opencodeAgentFrontmatter(stem, text, ov, theme);
|
|
911
|
+
else if (host === 'claude') fm = claudeAgentFrontmatter(stem, text, agentModel(tier, agentOverride(ov, stem).model, tiersHere).model);
|
|
912
|
+
else fm = opencodeAgentFrontmatter(stem, text, ov, theme, tier, tiersHere);
|
|
892
913
|
dest = path.join(agentsDir, `${stem}.md`);
|
|
893
914
|
body = stripAgentSkillLinks(body);
|
|
894
915
|
kind = 'agent';
|
package/js/hosts/opencode.mjs
CHANGED
|
@@ -84,8 +84,9 @@ const AGENT_OVERRIDES_STUB = {
|
|
|
84
84
|
+ '"reviewer": {"model": "anthropic/claude-haiku-4-5", "temperature": 0.1, '
|
|
85
85
|
+ '"variant": "high", "steps": 20}. '
|
|
86
86
|
+ 'Tiers (build with --tiers auto): "tiers": {"standard": "<model>", "light": "<model>"} '
|
|
87
|
-
+ 'names the model each tier runs on; a tier you leave out gets its host default
|
|
88
|
-
+ 'sonnet and haiku;
|
|
87
|
+
+ 'names the model each tier runs on (OpenCode: provider/model); a tier you leave out gets its host default '
|
|
88
|
+
+ '(Claude Code: sonnet and haiku; OpenCode and OpenClaude inherit), an empty value means inherit, strong is '
|
|
89
|
+
+ 'always the session model. The console\'s Models page sets these. A '
|
|
89
90
|
+ 'per-agent entry in "agents" wins over its tier. '
|
|
90
91
|
+ 'Host-specific; git-ignored. A future TUI screen edits this — rebuild to apply.'
|
|
91
92
|
),
|
|
@@ -14,7 +14,7 @@ import { CLAUDE_STYLE, HOSTS, hostCatalogsNatively, resolvePath } from '../hosts
|
|
|
14
14
|
import {
|
|
15
15
|
EMIT_HOST_SCOPE, footprintOfDir, installState, installTargets, readMaybe, renderedTier, themeFiles, tiersOfDir,
|
|
16
16
|
} from '../hosts/installs.mjs';
|
|
17
|
-
import {
|
|
17
|
+
import { isVendoredPath, tierModel, loadAgentOverrides, loadTierMap } from '../hosts/native.mjs';
|
|
18
18
|
import { PALETTE_ROLES, colorThemeFiles } from '../hosts/opencode.mjs';
|
|
19
19
|
import { readText, withDiscardableStderr } from '../lib/fs.mjs';
|
|
20
20
|
import { parseJson, formatRepr } from '../lib/json.mjs';
|
|
@@ -262,7 +262,7 @@ export function tierEnvNotes(env = process.env) {
|
|
|
262
262
|
}
|
|
263
263
|
for (const tier of ['standard', 'light']) {
|
|
264
264
|
if (agents[tier].every((stem) => Object.hasOwn(pins, stem) && pins[stem]?.model)) continue;
|
|
265
|
-
const { warning } =
|
|
265
|
+
const { warning } = tierModel(tier, map, env, 'claude');
|
|
266
266
|
const where = scope === 'global' ? host : `${host} (project ${root})`;
|
|
267
267
|
if (warning) notes.push(`${NOTE}[tiers] ${where}: ${warning}`);
|
|
268
268
|
}
|
package/js/inspect/doctor.mjs
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
import { installProfile } from '../build/profile.mjs';
|
|
41
41
|
import { providerWarning } from '../maintain/kit-migration.mjs';
|
|
42
42
|
import { validateIsVendored } from '../hosts/native.mjs';
|
|
43
|
+
import { learnState } from '../hosts/memory-files.mjs';
|
|
43
44
|
import { printErr, printOut } from '../lib/fs.mjs';
|
|
44
45
|
import { authoringProblems, factoryProblems, loopProblems } from './checks-authoring.mjs';
|
|
45
46
|
import { gateProbe, guardProbe } from './checks-probe.mjs';
|
|
@@ -290,6 +291,7 @@ export function doctorCollect({
|
|
|
290
291
|
problems = problems.concat(ran('shared_paths', 'Rendered shared paths', renderedPathNotes()));
|
|
291
292
|
problems = problems.concat(ran('providers', 'Workflow provider', providerNotes()));
|
|
292
293
|
problems = problems.concat(ran('tier_env', 'Model tier aliases', tierEnvNotes()));
|
|
294
|
+
problems = problems.concat(ran('learn', 'Memory learning', [`${NOTE}learn: ${learnState()}`]));
|
|
293
295
|
problems = problems.concat(ran('map', 'Module map', moduleMapProblems()));
|
|
294
296
|
problems = problems.concat(ran('host_matrix', 'Host tables', hostMatrixProblems()));
|
|
295
297
|
problems = problems.concat(ran('host_claims', 'Host claims',
|
package/js/inspect/status.mjs
CHANGED
|
@@ -55,7 +55,7 @@ import { installProfile, rebuildCommand } from '../build/generate.mjs';
|
|
|
55
55
|
import { providerWarning } from '../maintain/kit-migration.mjs';
|
|
56
56
|
import { isDoctorNote } from './scan.mjs';
|
|
57
57
|
import { pendingDrafts } from '../hosts/hooks-context.mjs';
|
|
58
|
-
import { factCount } from '../hosts/memory-files.mjs';
|
|
58
|
+
import { factCount, learnState } from '../hosts/memory-files.mjs';
|
|
59
59
|
import { lastStoreReport } from '../hosts/store-watch.mjs';
|
|
60
60
|
import { hookShimPath, shimDead } from '../hosts/shim.mjs';
|
|
61
61
|
import { printErr, printOut } from '../lib/fs.mjs';
|
|
@@ -365,6 +365,7 @@ export function statusData() {
|
|
|
365
365
|
agent_md_present: Boolean(agentMd && existsSync(agentMd)),
|
|
366
366
|
gates: gateSummary([...(cfgDir ? [cfgDir] : []), ...otherCfg]),
|
|
367
367
|
drafts_pending: pendingDrafts(),
|
|
368
|
+
learn: learnState(),
|
|
368
369
|
store_report: lastStoreReport(),
|
|
369
370
|
opencode_shadow: opencodeShadowedInstall(),
|
|
370
371
|
openclaude_dual_harness: openclaudeDualHarnessRoots(),
|
|
@@ -477,6 +478,8 @@ export function statusLines(d, color = false, boxed = true) {
|
|
|
477
478
|
rows.push(['gates', `${armed} ${DOT} ${g.total} ask${g.total === 1 ? '' : 's'}`
|
|
478
479
|
+ (byRule ? ` (${byRule})` : '')]);
|
|
479
480
|
}
|
|
481
|
+
// Conditional for the recording reason again; says why no fact is ever distilled on a machine without a model (D12).
|
|
482
|
+
if (d.learn) rows.push(['learn', d.learn]);
|
|
480
483
|
if (d.drafts_pending) {
|
|
481
484
|
rows.push(['drafts', `${d.drafts_pending} in user-rules.draft.md wait${d.drafts_pending === 1 ? 's' : ''} for your decision`]);
|
|
482
485
|
}
|
package/js/maintain/memory.mjs
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
import { readdirSync, unlinkSync } from 'node:fs';
|
|
49
49
|
import path from 'node:path';
|
|
50
50
|
|
|
51
|
-
import {
|
|
51
|
+
import { archiveFact, consolidateMemory, isReservedStem, memoryDropIndex } from '../hosts/memory-files.mjs';
|
|
52
52
|
import { recordOwnWrites } from '../hosts/store-watch.mjs';
|
|
53
53
|
import { resolveMemoryDir } from '../hosts/hosts.mjs';
|
|
54
54
|
import { printOut, printErr, isFile } from '../lib/fs.mjs';
|
|
@@ -57,7 +57,7 @@ import { printOut, printErr, isFile } from '../lib/fs.mjs';
|
|
|
57
57
|
export function isFactName(name) {
|
|
58
58
|
return Boolean(name) && !name.includes('/') && !name.includes('\\')
|
|
59
59
|
&& ![...name].some((c) => c.charCodeAt(0) < 0x20 || c.charCodeAt(0) === 0x7f)
|
|
60
|
-
&& !
|
|
60
|
+
&& !isReservedStem(name);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The console's view of the sub-agent models — `GET`/`POST /api/agent-models`.
|
|
3
3
|
*
|
|
4
|
-
* What it reads and writes is `agent-overrides.json` of ONE Claude Code
|
|
5
|
-
* (`standard`, `light`) and each agent's
|
|
6
|
-
* the
|
|
4
|
+
* What it reads and writes is `agent-overrides.json` of ONE install (Claude Code, OpenCode or
|
|
5
|
+
* OpenClaude; Bob takes no model): the `tiers` map (`standard`, `light`) and each agent's
|
|
6
|
+
* `agents.<name>.model` pin. The precedence (pin > map > the host's tier default > inherit) is
|
|
7
|
+
* `agentModel` in `js/hosts/native.mjs`, the same function
|
|
7
8
|
* the emit writes agent frontmatter with, so this page can never promise a model the build will
|
|
8
9
|
* not write. The value validation is `overrideProblem` and the map reader `loadTierMap`, there too.
|
|
9
10
|
*
|
|
@@ -17,8 +18,11 @@
|
|
|
17
18
|
* `null` removes the key (back to the tier's default). A pin: a string sets it, `''` or `null`
|
|
18
19
|
* removes `model` and leaves the rest of the agent's entry alone.
|
|
19
20
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
21
|
+
* The GET also lists the models the install can run (`model-catalog.mjs`), and a save is validated
|
|
22
|
+
* per host: OpenCode takes `provider/model[#variant]`, the others any single-line string. The
|
|
23
|
+
* routing (`--tiers`) is not written here: the page sends it with the rebuild, through the existing
|
|
24
|
+
* `install` action (its `tiers` field), so one path rebuilds. A host with no per-agent model (Bob)
|
|
25
|
+
* answers each agent's tier and no model.
|
|
22
26
|
*/
|
|
23
27
|
import path from 'node:path';
|
|
24
28
|
|
|
@@ -26,8 +30,9 @@ import { renderAll } from '../build/render.mjs';
|
|
|
26
30
|
import { loadKits, makeCfg } from '../build/source.mjs';
|
|
27
31
|
import { EMIT_HOST_SCOPE, tiersOfDir } from '../hosts/installs.mjs';
|
|
28
32
|
import {
|
|
29
|
-
|
|
33
|
+
TIER_DEFAULTS, agentModel, loadAgentOverrides, loadTierMap, overrideProblem,
|
|
30
34
|
} from '../hosts/native.mjs';
|
|
35
|
+
import { readModelCatalog } from './model-catalog.mjs';
|
|
31
36
|
import { isFile, readText, writeTextAtomic } from '../lib/fs.mjs';
|
|
32
37
|
import { formatValue, isDict, isTruthy, jsonDumpsIndent, parseJson } from '../lib/json.mjs';
|
|
33
38
|
import { bget } from './actions.mjs';
|
|
@@ -67,10 +72,36 @@ function readOverrides(dir) {
|
|
|
67
72
|
return { file, exists: true, data, problem: null };
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
/** The
|
|
75
|
+
/** The hosts whose agents take a `model:` line: every host but Bob. */
|
|
76
|
+
const ROUTES = ['claude', 'opencode', 'openclaude'];
|
|
77
|
+
|
|
78
|
+
/** The view's host, scope and the install's directory; `claude` (routing supported) false only for Bob. */
|
|
71
79
|
function viewOf(state) {
|
|
72
|
-
const [host] = EMIT_HOST_SCOPE.get(state.emit || '') ?? ['opencode'];
|
|
73
|
-
return { host, claude: host
|
|
80
|
+
const [host, scope] = EMIT_HOST_SCOPE.get(state.emit || '') ?? ['opencode', 'global'];
|
|
81
|
+
return { host, scope, claude: ROUTES.includes(host), dir: state.target };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The model ids this install's `agent-overrides.json` holds: the tier map's values and the pins. */
|
|
85
|
+
function modelsInUse(dir) {
|
|
86
|
+
const { data, problem } = readOverrides(dir);
|
|
87
|
+
if (problem || !data) return [];
|
|
88
|
+
const out = [];
|
|
89
|
+
if (isDict(data.tiers)) for (const v of Object.values(data.tiers)) if (typeof v === 'string' && v.trim()) out.push(v.trim());
|
|
90
|
+
if (isDict(data.agents)) for (const e of Object.values(data.agents)) if (isDict(e) && typeof e.model === 'string' && e.model.trim()) out.push(e.model.trim());
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* `GET /api/agent-models`: the per-agent view (`apiAgentModels`) plus the install's `models` and
|
|
96
|
+
* `groups` (`readModelCatalog`: files and loopback probes, never a key). Async because of the probes.
|
|
97
|
+
* `opts` (`env`, `home`, `fetchFn`) lets a test plant the machine.
|
|
98
|
+
*/
|
|
99
|
+
export async function apiAgentModelsFull(state, opts = {}) {
|
|
100
|
+
const view = apiAgentModels(state, opts.env);
|
|
101
|
+
const { host, scope, dir } = viewOf(state);
|
|
102
|
+
if (!view.claude) return { ...view, models: [], groups: [] };
|
|
103
|
+
const cat = await readModelCatalog({ host, scope, dir, root: state.root ?? dir, inUse: modelsInUse(dir), ...opts });
|
|
104
|
+
return { ...view, ...cat };
|
|
74
105
|
}
|
|
75
106
|
|
|
76
107
|
export function apiAgentModels(state, env = process.env) {
|
|
@@ -86,23 +117,23 @@ export function apiAgentModels(state, env = process.env) {
|
|
|
86
117
|
const quiet = () => {};
|
|
87
118
|
const map = problem ? {} : loadTierMap(dir, quiet);
|
|
88
119
|
const pins = problem ? {} : loadAgentOverrides(dir, quiet);
|
|
89
|
-
const on = tiers === 'auto' ? { map, env } : null;
|
|
120
|
+
const on = tiers === 'auto' ? { map, env, host } : null;
|
|
90
121
|
const warnings = new Set();
|
|
91
122
|
const agents = names.map((name) => {
|
|
92
123
|
const tier = known.get(name) ?? null;
|
|
93
124
|
const pin = Object.hasOwn(pins, name) && isTruthy(pins[name]?.model) ? formatValue(pins[name].model) : null;
|
|
94
125
|
// A personal agent (no shipped source) is not Geneseed's to tier: only its pin counts.
|
|
95
|
-
const r =
|
|
126
|
+
const r = agentModel(tier ?? 'none', pin, tier ? on : null);
|
|
96
127
|
// The alias warning is the tier map's, whether or not the routing is installed yet: the
|
|
97
128
|
// console's editor shows with a picked `auto`, before the rebuild that turns it on.
|
|
98
|
-
const w = tier ?
|
|
129
|
+
const w = tier ? agentModel(tier, pin, { map, env, host }).warning : null;
|
|
99
130
|
if (w) warnings.add(w);
|
|
100
131
|
return { name, tier, pin, model: r.model, from: r.from };
|
|
101
132
|
});
|
|
102
133
|
return {
|
|
103
134
|
host, claude, tiers, file: { path: file, problem },
|
|
104
135
|
map: Object.fromEntries(Object.entries(map).map(([k, v]) => [k, formatValue(v)])),
|
|
105
|
-
defaults: { ...
|
|
136
|
+
defaults: { ...TIER_DEFAULTS[host] },
|
|
106
137
|
warnings: [...warnings], agents,
|
|
107
138
|
};
|
|
108
139
|
}
|
|
@@ -111,7 +142,7 @@ export function apiAgentModels(state, env = process.env) {
|
|
|
111
142
|
* Apply one edit to the parsed file in place; the problems found, none applied when there are some.
|
|
112
143
|
* `edit` is `{ tiers?: {standard?, light?}, agents?: {<name>: model} }`, `names` the installed agents.
|
|
113
144
|
*/
|
|
114
|
-
export function editOverrides(data, edit, names) {
|
|
145
|
+
export function editOverrides(data, edit, names, host = 'claude') {
|
|
115
146
|
const problems = [];
|
|
116
147
|
const asModel = (where, v) => {
|
|
117
148
|
if (v === null) return null;
|
|
@@ -119,6 +150,10 @@ export function editOverrides(data, edit, names) {
|
|
|
119
150
|
const s = v.trim();
|
|
120
151
|
const why = overrideProblem(s);
|
|
121
152
|
if (why) { problems.push(`${where} ${why}`); return undefined; }
|
|
153
|
+
// OpenCode names a model `provider/model[#variant]`: the provider ends at the first `/`.
|
|
154
|
+
if (host === 'opencode' && s && !/^[^\s/]+\/[^\s]+$/.test(s)) {
|
|
155
|
+
problems.push(`${where} must look like provider/model, with no whitespace`); return undefined;
|
|
156
|
+
}
|
|
122
157
|
if (s.length > MAX_MODEL) { problems.push(`${where} is longer than ${MAX_MODEL} characters`); return undefined; }
|
|
123
158
|
return s;
|
|
124
159
|
};
|
|
@@ -160,12 +195,12 @@ export function editOverrides(data, edit, names) {
|
|
|
160
195
|
|
|
161
196
|
/** `POST /api/agent-models`: `ok: false` (a 409) when nothing was written, with the reason. */
|
|
162
197
|
export function apiAgentModelsSave(state, body) {
|
|
163
|
-
const { claude, dir } = viewOf(state);
|
|
164
|
-
if (!claude) return { ok: false, error: '
|
|
198
|
+
const { host, claude, dir } = viewOf(state);
|
|
199
|
+
if (!claude) return { ok: false, error: 'This host takes no per-agent model (Bob), so there is nothing to save' };
|
|
165
200
|
const { file, data, problem } = readOverrides(dir);
|
|
166
201
|
if (problem) return { ok: false, error: problem };
|
|
167
202
|
const names = state.inventory.agents.map((a) => a.name);
|
|
168
|
-
const problems = editOverrides(data, { tiers: bget(body, 'tiers'), agents: bget(body, 'agents') }, names);
|
|
203
|
+
const problems = editOverrides(data, { tiers: bget(body, 'tiers'), agents: bget(body, 'agents') }, names, host);
|
|
169
204
|
if (problems.length) return { ok: false, error: problems.join('; ') };
|
|
170
205
|
writeTextAtomic(file, `${jsonDumpsIndent(data, { ensureAscii: false })}\n`);
|
|
171
206
|
return { ok: true, rebuild: true, ...apiAgentModels(state) };
|