geneseed 6.0.3 → 6.0.4
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 +18 -0
- package/DESIGN.md +1 -1
- package/SHIPPED.md +1 -1
- package/adapters/opencode/plugins/geneseed-context.js +0 -42
- package/adapters/opencode/plugins/geneseed-learn.js +13 -4
- package/bin/geneseed-hook.mjs +5 -0
- package/docs/concepts/hooks.md +6 -6
- package/docs/guides/install-scripted.md +1 -1
- package/docs/reference/env-context.md +2 -1
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/profiles.md +1 -0
- package/docs/understand/a-day.md +1 -1
- package/docs/understand/machine-claude.md +1 -1
- package/docs/web-ui.md +2 -2
- package/harness.config.json +1 -1
- package/js/build/args.mjs +4 -3
- package/js/build/driver.mjs +8 -8
- package/js/build/emit-claude.mjs +59 -4
- package/js/build/generate.mjs +11 -2
- package/js/build/profile.mjs +10 -5
- package/js/build/render.mjs +3 -1
- package/js/build/source.mjs +12 -1
- package/js/cli-table.json +37 -0
- package/js/hosts/hooks-context.mjs +1 -56
- package/js/hosts/hooks-learn.mjs +435 -55
- package/js/hosts/installs.mjs +22 -2
- package/js/hosts/memory-files.mjs +89 -6
- package/js/hosts/native.mjs +23 -1
- package/js/hosts/settings.mjs +77 -4
- package/js/inspect/diff.mjs +3 -1
- package/js/inspect/doctor.mjs +37 -3
- package/js/inspect/status.mjs +38 -5
- package/js/inspect/validate.mjs +1 -1
- package/js/lib/proc.mjs +36 -0
- package/js/maintain/profiles.mjs +15 -4
- package/js/maintain/setup.mjs +31 -7
- package/js/maintain/update.mjs +1 -1
- package/js/web/actions.mjs +5 -3
- package/js/web/api.mjs +2 -2
- package/js/web/profiles-api.mjs +2 -2
- package/js/web/state.mjs +13 -2
- package/package.json +1 -1
- package/src/AGENT.md.tmpl +1 -1
- package/src/agents/memory-curator.md +3 -0
- package/src/doctrines/process.md +2 -2
- package/src/memory/README.md +24 -4
- package/src/skills/rule.md +9 -5
- package/web/dist/assets/{Activity-IAxWF2wK.js → Activity-BsMFA5Aa.js} +1 -1
- package/web/dist/assets/{ActivityDetail-CtC2DLvh.js → ActivityDetail-C66n3oul.js} +1 -1
- package/web/dist/assets/{Bonsai-BoKo68Kw.js → Bonsai-BCd-qt7W.js} +1 -1
- package/web/dist/assets/{CopyButton-C0VTiqmb.js → CopyButton-Dpl0PFja.js} +1 -1
- package/web/dist/assets/{Dashboard-CRGCp2cV.js → Dashboard-CQxdiv7F.js} +2 -2
- package/web/dist/assets/{Docs-DwOwzaD6.js → Docs-D0XlXuiA.js} +1 -1
- package/web/dist/assets/{Factories-DxHD2T-1.js → Factories-CPVBoWoA.js} +1 -1
- package/web/dist/assets/{GreenhouseView-D5VOmhmR.js → GreenhouseView-C_2auUA8.js} +1 -1
- package/web/dist/assets/Installs-CXqjmqms.js +3 -0
- package/web/dist/assets/{JournalView-gUSGysTm.js → JournalView-S-igd-Nv.js} +1 -1
- package/web/dist/assets/{Kits-DYQvykZ0.js → Kits-K6mu91rm.js} +1 -1
- package/web/dist/assets/{Laws-UVk0uojS.js → Laws-j5vKNwLT.js} +1 -1
- package/web/dist/assets/{LibRows-CwK63kjB.js → LibRows-1yTY0Kwn.js} +1 -1
- package/web/dist/assets/{Library-DdzyrwUK.js → Library-BQZnFdWs.js} +1 -1
- package/web/dist/assets/{Loops-yHga7xdr.js → Loops-B5DgxpLm.js} +1 -1
- package/web/dist/assets/Models-C-4Y4jvx.js +1 -0
- package/web/dist/assets/{OperatorHudView-D1lQF-ZY.js → OperatorHudView-_8NBAvkd.js} +1 -1
- package/web/dist/assets/Personal-Bf7zHDc6.js +2 -0
- package/web/dist/assets/{Settings-Brgec4M0.js → Settings-BTrA6MXv.js} +1 -1
- package/web/dist/assets/{Tabs-BHjxciOL.js → Tabs-BDhZImxa.js} +1 -1
- package/web/dist/assets/controls-CREglcUF.js +1 -0
- package/web/dist/assets/{index-BfyZCNu7.css → index-9iBqq7i2.css} +1 -1
- package/web/dist/assets/{index-BILaKHbH.js → index-BiKWWv7Z.js} +3 -3
- package/web/dist/index.html +2 -2
- package/web/dist/assets/Installs-B5hFSUeN.js +0 -3
- package/web/dist/assets/Models-DAgkQ4CE.js +0 -1
- package/web/dist/assets/Personal-DjhIfa9v.js +0 -2
- package/web/dist/assets/controls-CK7qHA8H.js +0 -1
package/js/hosts/hooks-learn.mjs
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `learn` — the Stop/SubagentStop/PreCompact verb: distil notes or a transcript into
|
|
3
|
-
* entries (a new fact, or an update or archive of a stored one) through the model CLI
|
|
4
|
-
* `$GENESEED_LLM` names. THE
|
|
2
|
+
* `learn` — the Stop/SubagentStop/PreCompact/SessionEnd verb: distil notes or a transcript into
|
|
3
|
+
* memory entries (a new fact, or an update or archive of a stored one) through the model CLI
|
|
4
|
+
* `$GENESEED_LLM` names. THE MODEL SPAWN in the hook entry's closure (ADR 0002 names it and its
|
|
5
|
+
* detached twin); the store's file format it writes through lives in `./memory-files.mjs`, which does
|
|
5
6
|
* not spawn and is what the CLI imports. See `js/hosts/hooks.mjs`'s header for the contract.
|
|
7
|
+
*
|
|
8
|
+
* WHEN THE MODEL RUNS (spec 2026-11-18-learn-model-row, D8/D12). A turn's Stop and a sub-agent's
|
|
9
|
+
* SubagentStop do their no-model work only (the spec-feedback copy, the done check, the change report,
|
|
10
|
+
* the outcome line) and return: a model call after every reply was the cost the spec ruled out. The
|
|
11
|
+
* distil runs on PreCompact and SessionEnd, once, in a DETACHED WORKER: a SessionEnd hook is killed
|
|
12
|
+
* when the session ends (S1b), and a compaction must not wait 5-10 s for a model, so the hook writes a
|
|
13
|
+
* small job file and starts `geneseed-hook learn-worker <job>` apart from itself (S1c). A sub-agent's
|
|
14
|
+
* lesson is queued at its SubagentStop and distilled by that worker, so a session pays for one run.
|
|
6
15
|
*/
|
|
16
|
+
import os from 'node:os';
|
|
7
17
|
import path from 'node:path';
|
|
8
|
-
import { spawnSync } from 'node:child_process';
|
|
18
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
19
|
+
import {
|
|
20
|
+
appendFileSync, closeSync, existsSync, mkdirSync, mkdtempSync, openSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, unlinkSync, writeFileSync,
|
|
21
|
+
} from 'node:fs';
|
|
9
22
|
import { readText, isDir, printOut as out, printErr as err } from '../lib/fs.mjs';
|
|
10
23
|
import { toPlatformPath } from '../lib/paths.mjs';
|
|
11
|
-
import { NO_WINDOW } from '../lib/proc.mjs';
|
|
24
|
+
import { NO_WINDOW, resolveCommand } from '../lib/proc.mjs';
|
|
12
25
|
import {
|
|
13
|
-
globalHookStandingDown, hookProjectDir, isGlobalInstall, resolveMemoryDir, sovereignBypass,
|
|
26
|
+
GLOBAL_MANIFEST, globalHookStandingDown, hookProjectDir, isGlobalInstall, resolveMemoryDir, sovereignBypass,
|
|
14
27
|
} from './hosts.mjs';
|
|
15
28
|
import { sharedPaths } from '../lib/machine-dir.mjs';
|
|
16
29
|
import { readStdin, splitLines, splitWords, tailReader } from './hooks-prims.mjs';
|
|
17
30
|
import { doneGate } from './hooks-done.mjs';
|
|
18
31
|
import { recordOwnWrites, storeReport } from './store-watch.mjs';
|
|
19
32
|
import {
|
|
20
|
-
existingSlugs, readFacts, writeMemories, consolidateMemory, appendAgentLesson,
|
|
33
|
+
existingSlugs, readFacts, writeMemories, consolidateMemory, appendAgentLesson, writeLearnLast,
|
|
21
34
|
} from './memory-files.mjs';
|
|
22
35
|
import { captureSpecFeedback, projectNotesDir, subagentReport, turnReply } from './spec-feedback.mjs';
|
|
23
36
|
import { gitRootOf } from './gitref.mjs';
|
|
@@ -243,9 +256,106 @@ function llmTimeoutSeconds() {
|
|
|
243
256
|
return Number.isFinite(n) && n > 0 ? n : LLM_TIMEOUT_S;
|
|
244
257
|
}
|
|
245
258
|
|
|
246
|
-
|
|
259
|
+
/**
|
|
260
|
+
* The lean child (D13, S1e). A bare `claude -p` loads the user's whole harness (CLAUDE.md, hooks,
|
|
261
|
+
* MCP servers: ~68k tokens, 8 s); with these flags it reads ~3k tokens and answers in 5 s, still on the
|
|
262
|
+
* subscription login. `--bare` is NOT among them: it reads Anthropic auth from an API key only, and
|
|
263
|
+
* the machine rule is subscription only. Appended only when the command's first word is `claude`, or
|
|
264
|
+
* `openclaude` AND its own `--help` lists the flag (a flag it does not know would end the call in a usage
|
|
265
|
+
* error). Any other command is used as given. A flag the user's command already names is left alone.
|
|
266
|
+
*
|
|
267
|
+
* ORDER MATTERS: `--tools` is variadic and would take the prompt as a tool name, so a flag follows it.
|
|
268
|
+
*/
|
|
269
|
+
const DISTIL_ROLE = 'You distil durable memories from notes. Follow the instructions in the user message '
|
|
270
|
+
+ 'exactly, and reply with only what they ask for.';
|
|
271
|
+
const LEAN_FLAGS = [
|
|
272
|
+
['--setting-sources', ''], ['--strict-mcp-config'], ['--tools', ''], ['--disable-slash-commands'],
|
|
273
|
+
['--no-session-persistence'], ['--system-prompt', DISTIL_ROLE],
|
|
274
|
+
];
|
|
275
|
+
const HELP_SECONDS = 20;
|
|
276
|
+
const helpCache = new Map();
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The command's name without its folder or Windows extension, lower case. `path.win32.basename` splits on `/`
|
|
280
|
+
* AND `\`, so a Windows path names the same command on every platform (`path.basename` on POSIX kept
|
|
281
|
+
* `C:\bin\Claude.EXE` whole and missed it).
|
|
282
|
+
*/
|
|
283
|
+
const binName = (word) => path.win32.basename(word).toLowerCase().replace(/[.](?:exe|cmd|bat)$/, '');
|
|
284
|
+
|
|
285
|
+
/** `<cli> --help`'s text, or '' when it will not run: the flags an `openclaude` of this machine knows. */
|
|
286
|
+
function helpOf(cli) {
|
|
287
|
+
if (!helpCache.has(cli)) {
|
|
288
|
+
const proc = runLlm(`${cli} --help`, null, { seconds: HELP_SECONDS, track: false });
|
|
289
|
+
helpCache.set(cli, proc.returncode === 0 ? proc.stdout : '');
|
|
290
|
+
}
|
|
291
|
+
return helpCache.get(cli);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Whether `--help` text lists `flag` as a flag of its own, not as the tail of a longer one (`--append-system-prompt`). */
|
|
295
|
+
const listsFlag = (help, flag) => new RegExp(`(^|[\\s,\\[])${flag}(?=[\\s,=\\]<]|$)`, 'm').test(help);
|
|
296
|
+
|
|
297
|
+
/** Exported for the unit tier: `help` is the probe, so a test names the `--help` text it reads. */
|
|
298
|
+
export function leanArgv(argv, help = helpOf) {
|
|
299
|
+
const bin = binName(argv[0] ?? '');
|
|
300
|
+
if (bin !== 'claude' && bin !== 'openclaude') return argv;
|
|
301
|
+
const known = bin === 'openclaude' ? help(argv[0]) : null;
|
|
302
|
+
const lean = [...argv];
|
|
303
|
+
for (const [flag, ...value] of LEAN_FLAGS) {
|
|
304
|
+
if (argv.includes(flag) || (known !== null && !listsFlag(known, flag))) continue;
|
|
305
|
+
lean.push(flag, ...value);
|
|
306
|
+
}
|
|
307
|
+
return lean;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* What to hand `spawnSync` for the words `words` and the prompt (F5) — pure, so a table states every row.
|
|
312
|
+
*
|
|
313
|
+
* Off Windows the OS resolves the word at spawn time and the words run as they are. On Windows a word that
|
|
314
|
+
* resolves to nothing on PATH refuses the call (S-F4: CreateProcess would look in the current folder first). On Windows `CreateProcess` runs only `.exe`, so
|
|
315
|
+
* an npm-installed CLI (`claude.cmd`) was "not found" and learning silently did nothing: the word is
|
|
316
|
+
* resolved against PATH and PATHEXT (`resolveCommand`, which `doctor` shares), an `.exe` is run directly,
|
|
317
|
+
* and a `.cmd`/`.bat` goes through `cmd.exe /d /s /c "<line>"` with every word double-quoted. THE PROMPT
|
|
318
|
+
* NEVER RIDES THAT LINE: it goes over stdin, so the notes of a session (anything a person or a web page
|
|
319
|
+
* typed) are never parsed by cmd.exe. What remains on the line is the command's own words and the fixed
|
|
320
|
+
* lean flags, and a word cmd.exe could still read inside quotes (`"`, `%`, a line break, a trailing
|
|
321
|
+
* backslash) refuses the call instead of being passed on.
|
|
322
|
+
*/
|
|
323
|
+
export function spawnPlan(words, prompt, { platform = process.platform, env = process.env, exists = undefined } = {}) {
|
|
324
|
+
// The prompt goes over stdin for `claude` and `openclaude` on every path (`claude -p` reads it there; spec S1):
|
|
325
|
+
// a Windows command line holds 32 767 characters, and a long session's notes overran it (ENOENT/E2BIG, silently).
|
|
326
|
+
// Any other command keeps it as the last argument, which is what `$GENESEED_LLM="llm -m x"` and the CLI cells expect.
|
|
327
|
+
const viaStdin = prompt !== null && ['claude', 'openclaude'].includes(binName(words[0] ?? ''));
|
|
328
|
+
const direct = { file: words[0], args: [...words.slice(1), ...(prompt === null || viaStdin ? [] : [prompt])],
|
|
329
|
+
input: viaStdin ? prompt : undefined, verbatim: false, refuse: null };
|
|
330
|
+
if (platform !== 'win32') return direct;
|
|
331
|
+
const found = resolveCommand(words[0], env, exists, platform);
|
|
332
|
+
// Nothing on PATH: the bare word would be handed to CreateProcess, which looks in the CURRENT folder first, and a
|
|
333
|
+
// `claude.exe` planted in a repository would then run at every session end. So nothing runs.
|
|
334
|
+
if (!found) return { ...direct, refuse: `could not run ${words[0]}: not found on PATH - nothing learned` };
|
|
335
|
+
if (!/[.](?:cmd|bat)$/i.test(found)) return { ...direct, file: found };
|
|
336
|
+
const parts = [found, ...words.slice(1)];
|
|
337
|
+
const bad = parts.find((a) => /["%\r\n\0]|[\\]$/.test(a));
|
|
338
|
+
if (bad !== undefined) {
|
|
339
|
+
return { ...direct, refuse: `${JSON.stringify(bad)} cannot be passed through cmd.exe safely - nothing learned` };
|
|
340
|
+
}
|
|
341
|
+
const shell = path.join(env.SystemRoot || env.windir || 'C:\\Windows', 'System32', 'cmd.exe');
|
|
342
|
+
return { file: shell, args: ['/d', '/s', '/c', `"${parts.map((a) => `"${a}"`).join(' ')}"`],
|
|
343
|
+
input: prompt === null ? undefined : prompt, verbatim: true, refuse: null };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* The run in flight (`runJob`): its first failure, and the facts it stored. null outside a run, so a manual
|
|
348
|
+
* `learn` and the `--help` probe record nothing. `runJob` writes it to `learn-last.json` when it ends.
|
|
349
|
+
*/
|
|
350
|
+
let run = null;
|
|
351
|
+
function noteFail(reason) { if (run && !run.fail) run.fail = reason; }
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* `prompt` null runs the words as they are (the `--help` probe above); a string is appended after the
|
|
355
|
+
* lean flags. The ONE `spawnSync` call site of this module: the test that pins it reads this line.
|
|
356
|
+
*/
|
|
357
|
+
function runLlm(llm, prompt, { seconds = llmTimeoutSeconds(), track = true } = {}) {
|
|
247
358
|
const argv = splitWords(llm);
|
|
248
|
-
const seconds = llmTimeoutSeconds();
|
|
249
359
|
// `NO_WINDOW` folds in `CREATE_NO_WINDOW`; a model CLI invoked from the windowless daemon
|
|
250
360
|
// otherwise pops a console for as long as it takes to answer.
|
|
251
361
|
//
|
|
@@ -254,10 +364,42 @@ function runLlm(llm, prompt) {
|
|
|
254
364
|
// `learn` — one recursion per nested session, stopped only by the host's 600 s timeout
|
|
255
365
|
// killing the outermost call. The marker rides in the child's own environment (inherited by
|
|
256
366
|
// every grandchild too), and `cmdLearn`'s first line stands down the instant it sees it.
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
367
|
+
const plan = spawnPlan(prompt === null ? argv : leanArgv(argv), prompt);
|
|
368
|
+
if (plan.refuse) {
|
|
369
|
+
if (track) noteFail(plan.refuse);
|
|
370
|
+
return { stdout: '', stderr: `[learn] ${plan.refuse}\n`, returncode: 1, error: null };
|
|
371
|
+
}
|
|
372
|
+
// The answer goes to FILES, not pipes. On the Windows `.cmd` path the timeout kills cmd.exe but not the node the
|
|
373
|
+
// shim started under it; that orphan keeps a pipe's write end open, and `spawnSync` waits for the pipe to close, so
|
|
374
|
+
// a hung CLI held the wait for as long as it lived (measured: 15.7 s for a 2 s timeout). A file has no reader to
|
|
375
|
+
// wait for: `spawnSync` returns when cmd.exe is gone. The prompt comes from a file for the same reason (an orphan
|
|
376
|
+
// would hold a stdin pipe too).
|
|
377
|
+
// The scratch folder holds the prompt (transcript text), so every exit, a throw included, removes it.
|
|
378
|
+
const scratch = mkdtempSync(path.join(os.tmpdir(), 'geneseed-learn-'));
|
|
379
|
+
const outFile = path.join(scratch, 'out');
|
|
380
|
+
const errFile = path.join(scratch, 'err');
|
|
381
|
+
const inFile = path.join(scratch, 'in');
|
|
382
|
+
const fds = [];
|
|
383
|
+
const closeAll = () => { for (const fd of fds.splice(0)) { try { closeSync(fd); } catch { /* already closed */ } } };
|
|
384
|
+
let proc;
|
|
385
|
+
try {
|
|
386
|
+
writeFileSync(inFile, plan.input ?? '');
|
|
387
|
+
fds.push(openSync(inFile, 'r'), openSync(outFile, 'w'), openSync(errFile, 'w'));
|
|
388
|
+
try {
|
|
389
|
+
proc = spawnSync(plan.file, plan.args,
|
|
390
|
+
{ windowsVerbatimArguments: plan.verbatim, stdio: [...fds], timeout: seconds * 1000, killSignal: 'SIGKILL',
|
|
391
|
+
env: { ...process.env, GENESEED_LEARN_CHILD: '1' }, ...NO_WINDOW });
|
|
392
|
+
} finally {
|
|
393
|
+
closeAll();
|
|
394
|
+
}
|
|
395
|
+
const slurp = (f) => { try { return readFileSync(f, 'utf8'); } catch { return ''; } };
|
|
396
|
+
proc = { ...proc, stdout: slurp(outFile), stderr: slurp(errFile) };
|
|
397
|
+
} finally {
|
|
398
|
+
closeAll();
|
|
399
|
+
try { rmSync(scratch, { recursive: true, force: true }); } catch { /* an orphan may still hold it open: the OS temp sweep gets it */ }
|
|
400
|
+
}
|
|
260
401
|
if (proc.error && /** @type {NodeJS.ErrnoException} */ (proc.error).code === 'ETIMEDOUT') {
|
|
402
|
+
if (track) noteFail(`${argv[0]} gave no answer in ${seconds} s and was stopped`);
|
|
261
403
|
err(`[learn] ${argv[0]} gave no answer in ${seconds} s and was stopped - nothing learned.\n`);
|
|
262
404
|
return { stdout: '', stderr: '', returncode: 0, error: null };
|
|
263
405
|
}
|
|
@@ -267,6 +409,11 @@ function runLlm(llm, prompt) {
|
|
|
267
409
|
// bytes, so without this the stored fact is written with `\r\r\n` on every line.
|
|
268
410
|
const universal = (s) => (s === null || s === undefined ? ''
|
|
269
411
|
: String(s).replaceAll('\r\n', '\n').replaceAll('\r', '\n'));
|
|
412
|
+
if (track && (proc.error || proc.status !== 0)) {
|
|
413
|
+
const said = universal(proc.stderr).split('\n').find((l) => l.trim()) || '';
|
|
414
|
+
noteFail(proc.error ? `could not run ${argv[0]}: ${proc.error.message}`
|
|
415
|
+
: `${argv[0]} exited ${proc.status === null ? 'by signal' : proc.status}${said ? `: ${said.trim()}` : ''}`);
|
|
416
|
+
}
|
|
270
417
|
return {
|
|
271
418
|
stdout: universal(proc.stdout),
|
|
272
419
|
stderr: proc.error ? `[learn] could not run ${argv[0]}: ${proc.error.message}\n`
|
|
@@ -279,40 +426,26 @@ function runLlm(llm, prompt) {
|
|
|
279
426
|
}
|
|
280
427
|
|
|
281
428
|
/**
|
|
282
|
-
* `_learn_agent_lesson` —
|
|
283
|
-
*
|
|
284
|
-
* parity of mechanism, degrading to a no-op, never a crash.
|
|
429
|
+
* `_learn_agent_lesson` — at most one per-agent lesson into `memory/agents/<name>.md`, from the notes
|
|
430
|
+
* of that agent's final turn. Run by the detached worker, once per queued agent (`runJob`).
|
|
285
431
|
*/
|
|
286
|
-
function learnAgentLesson(
|
|
287
|
-
const agent = subagentNameOf(meta);
|
|
288
|
-
if (!agent) return 0;
|
|
289
|
-
const memDir = resolveMemoryDir(args.memory);
|
|
290
|
-
if (!memDir) return 0;
|
|
432
|
+
function learnAgentLesson(agent, notes, memDir, llm) {
|
|
291
433
|
const prompt = [agentLessonPrompt(), '', 'NOTES:', notes].join('\n');
|
|
292
|
-
const llm = process.env.GENESEED_LLM;
|
|
293
|
-
// Unreachable through the hook path: `cmdLearn` already returned above when `$GENESEED_LLM`
|
|
294
|
-
// was unset, because a SubagentStop payload always names its own event. Left in as the same
|
|
295
|
-
// defensive no-op `resolveMemoryDir`'s check above is, should this ever be called directly.
|
|
296
|
-
if (!llm) {
|
|
297
|
-
err('[learn] $GENESEED_LLM unset \u2014 printing agent-lesson prompt.\n\n');
|
|
298
|
-
out(`${prompt}\n`);
|
|
299
|
-
return 0;
|
|
300
|
-
}
|
|
301
434
|
const proc = runLlm(llm, prompt);
|
|
302
|
-
|
|
435
|
+
// A model that failed (a lapsed login, a usage error) said nothing: what it printed is never a lesson.
|
|
436
|
+
const text = proc.returncode === 0 ? proc.stdout.trim() : '';
|
|
437
|
+
if (proc.returncode === 0 && !text) noteFail(`${splitWords(llm)[0]} returned an empty reply`);
|
|
303
438
|
if (text && text.toUpperCase() !== 'NOTHING') {
|
|
304
439
|
const lesson = splitLines(text)[0].replace(/^[-*]+/, '').trim();
|
|
305
440
|
const n = Array.from(lesson).length; // code points, as `len()` counts them
|
|
306
441
|
if (n >= 10 && n <= 300) {
|
|
307
442
|
const written = recordOwnWrites(path.dirname(memDir), () => appendAgentLesson(memDir, agent, lesson));
|
|
443
|
+
if (written && run) run.facts += 1;
|
|
308
444
|
err(written ? `[learn] agent lesson -> ${written}\n`
|
|
309
445
|
: `[learn] ${agent}'s lesson file is not UTF-8 - left as it is, lesson dropped\n`);
|
|
310
446
|
}
|
|
311
447
|
}
|
|
312
448
|
if (proc.returncode !== 0 && proc.stderr) err(proc.stderr);
|
|
313
|
-
// Only a SubagentStop hook reaches this, and the model CLI's code is not the hook's: exit 2
|
|
314
|
-
// there sends the subagent back to work. The failure is on stderr above.
|
|
315
|
-
return 0;
|
|
316
449
|
}
|
|
317
450
|
|
|
318
451
|
/** `--memory` of a global install's hook, swapped for the shared store when that exists. */
|
|
@@ -493,41 +626,70 @@ export function cmdLearn(args) {
|
|
|
493
626
|
|
|
494
627
|
// B3: a real hook call with `$GENESEED_LLM` unset has nothing to send a prompt to — stdout on
|
|
495
628
|
// Stop/SubagentStop/PreCompact reaches only the debug log, never the user (docs `hooks.md`) —
|
|
496
|
-
// so reading and flattening the transcript (a 2 MB tail or more
|
|
497
|
-
// is pure waste.
|
|
498
|
-
//
|
|
499
|
-
//
|
|
500
|
-
//
|
|
501
|
-
|
|
502
|
-
if (hookEvent && !
|
|
503
|
-
err('[learn] $GENESEED_LLM unset
|
|
629
|
+
// so reading and flattening the transcript (a 2 MB tail or more) just to print it nowhere
|
|
630
|
+
// is pure waste. A manual invocation keeps printing the prompt on an unset `$GENESEED_LLM` — that
|
|
631
|
+
// is the documented, deliberate behaviour (docs/reference/env-context.md) for someone running
|
|
632
|
+
// `learn` by hand to see what would have been sent, and `hookEvent` being unset is exactly what
|
|
633
|
+
// tells the two apart.
|
|
634
|
+
const llm = process.env.GENESEED_LLM;
|
|
635
|
+
if (hookEvent && !llm) {
|
|
636
|
+
err('[learn] $GENESEED_LLM unset — nothing to distil.\n');
|
|
504
637
|
return 0;
|
|
505
638
|
}
|
|
506
639
|
|
|
640
|
+
// D8: the model runs at the end of a session or before a compaction, never after a turn. A Stop
|
|
641
|
+
// has done its no-model work above; a sub-agent's stop queues its lesson for the session's one run.
|
|
642
|
+
if (hookEvent === 'Stop') return 0;
|
|
643
|
+
if (hookEvent === 'SubagentStop') {
|
|
644
|
+
queueAgentLesson(meta, args, install);
|
|
645
|
+
return 0;
|
|
646
|
+
}
|
|
647
|
+
if (hookEvent === 'PreCompact' || hookEvent === 'SessionEnd') {
|
|
648
|
+
return startDistil(meta, args, install, hookEvent, llm);
|
|
649
|
+
}
|
|
650
|
+
// Any other event name is no moment this verb knows to learn at.
|
|
651
|
+
if (hookEvent) return 0;
|
|
652
|
+
|
|
653
|
+
// A person running `learn` by hand: notes on stdin, a file or a transcript, distilled now, and the
|
|
654
|
+
// reply (or the prompt, with no model set) printed for them.
|
|
507
655
|
let notes = readNotes(raw, meta, read);
|
|
508
656
|
if (!notes.trim()) {
|
|
509
|
-
err('[learn] no notes or transcript content
|
|
657
|
+
err('[learn] no notes or transcript content — nothing to distil.\n');
|
|
510
658
|
return 0;
|
|
511
659
|
}
|
|
512
660
|
notes = tail(notes, MAX_NOTES_CHARS); // keep the tail: most recent, most durable
|
|
661
|
+
return distil(notes, resolveMemoryDir(args.memory), llm, null);
|
|
662
|
+
}
|
|
513
663
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
664
|
+
/**
|
|
665
|
+
* The distil itself: the prompt, the model CLI, and what it said into the store. `hookEvent` is the
|
|
666
|
+
* event the worker runs for, or null for a person at a terminal. On a hook run stdout is the host's
|
|
667
|
+
* and the model CLI's code is not the hook's (exit 2 would block a compaction), so it returns 0 and
|
|
668
|
+
* speaks on stderr; a manual run keeps the model's code, so a script can test it.
|
|
669
|
+
*/
|
|
670
|
+
function distil(notes, memDir, llm, hookEvent) {
|
|
517
671
|
const existing = memDir ? existingSlugs(memDir) : new Set();
|
|
518
672
|
const prompt = buildLearnPrompt(notes, memDir ? readFacts(memDir) : new Map());
|
|
519
|
-
|
|
520
|
-
const llm = process.env.GENESEED_LLM;
|
|
521
673
|
if (!llm) {
|
|
522
|
-
err('[learn] $GENESEED_LLM unset
|
|
674
|
+
err('[learn] $GENESEED_LLM unset — printing prompt instead.\n\n');
|
|
523
675
|
out(`${prompt}\n`);
|
|
524
676
|
return 0;
|
|
525
677
|
}
|
|
526
678
|
|
|
527
679
|
const proc = runLlm(llm, prompt);
|
|
528
|
-
|
|
680
|
+
// On a hook run a failed model said nothing (S1f: a lapsed login prints on stdout or stderr alike).
|
|
681
|
+
const output = hookEvent && proc.returncode !== 0 ? '' : proc.stdout;
|
|
682
|
+
const said = output.trim();
|
|
683
|
+
// A zero exit with nothing said is a lapsed login or a swallowed error, never an answer: NOTHING is the answer.
|
|
684
|
+
if (hookEvent && proc.returncode === 0 && !output.trim()) noteFail(`${splitWords(llm)[0]} returned an empty reply`);
|
|
529
685
|
if (memDir && output.trim() && output.trim().toUpperCase() !== 'NOTHING') {
|
|
530
686
|
const { created, updated, archived } = recordOwnWrites(path.dirname(memDir), () => writeMemories(output, memDir, existing));
|
|
687
|
+
if (run) run.facts += created.length + updated.length;
|
|
688
|
+
// Prose is no memory file: a model that answers "Please run /login" exited 0 and stored nothing. A reply with
|
|
689
|
+
// a name: line that merely repeats stored facts is a duplicate, not a failure.
|
|
690
|
+
if (hookEvent && !created.length && !updated.length && !archived.length && !/^name:\s*\S/m.test(output)) {
|
|
691
|
+
noteFail(`unparseable reply: ${said.split(/\r?\n/)[0].slice(0, 80)}`);
|
|
692
|
+
}
|
|
531
693
|
if (created.length) {
|
|
532
694
|
err(`[learn] wrote ${created.length} memory file(s) to `
|
|
533
695
|
+ `${memDir}: ${created.join(', ')}\n`);
|
|
@@ -544,14 +706,232 @@ export function cmdLearn(args) {
|
|
|
544
706
|
// A person running `learn` by hand with no store: the reply is what they asked to see.
|
|
545
707
|
out(output);
|
|
546
708
|
} else if (output.trim() && output.trim().toUpperCase() !== 'NOTHING') {
|
|
547
|
-
// On a hook
|
|
548
|
-
//
|
|
549
|
-
// so the report was lost. A bare NOTHING says nothing and is dropped.
|
|
709
|
+
// On a hook run stdout is the host's, so the model's words go to stderr; a bare NOTHING says
|
|
710
|
+
// nothing and is dropped.
|
|
550
711
|
err(output);
|
|
551
712
|
}
|
|
552
713
|
if (proc.returncode !== 0 && proc.stderr) err(proc.stderr);
|
|
553
|
-
// On a hook call the model CLI's code is not this hook's: exit 2 on Stop or PreCompact blocks
|
|
554
|
-
// the turn's end or the compaction, and any non-zero drops the JSON already on stdout. The
|
|
555
|
-
// failure is on stderr above. A manual run keeps the code, so a script can test it.
|
|
556
714
|
return hookEvent ? 0 : proc.returncode;
|
|
557
715
|
}
|
|
716
|
+
|
|
717
|
+
// ---- the job: what a hook hands the detached worker ------------------------------------------------
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Where the jobs and the queued lessons live: the machine tier's `cache/learn-jobs`, never an install's own
|
|
721
|
+
* folder (a project install's folder is the user's repo, and holds nothing of ours that uninstall would not
|
|
722
|
+
* take). A stale file there is swept after a week. null when the account has no home directory.
|
|
723
|
+
*/
|
|
724
|
+
const JOB_DIR = 'learn-jobs';
|
|
725
|
+
function jobDir() {
|
|
726
|
+
try { return path.join(sharedPaths().root, 'cache', JOB_DIR); } catch { return null; }
|
|
727
|
+
}
|
|
728
|
+
const JOB_MAX_AGE_MS = 7 * 24 * 3600 * 1000;
|
|
729
|
+
/** The most sub-agents one run asks a lesson of: each is one model call, and a session pays once. */
|
|
730
|
+
const MAX_LESSON_AGENTS = 3;
|
|
731
|
+
const MAX_QUEUED_LESSONS = 40;
|
|
732
|
+
const MAX_QUEUED_LINE_CHARS = 4000;
|
|
733
|
+
const MAX_QUEUED_REPLY_CHARS = 3000;
|
|
734
|
+
const sessionKey = (id) => (typeof id === 'string' && id ? id.replace(/[^A-Za-z0-9_-]/g, '_').slice(0, 64) : 'nosession');
|
|
735
|
+
|
|
736
|
+
function sweepJobs(dir) {
|
|
737
|
+
try {
|
|
738
|
+
for (const name of readdirSync(dir)) {
|
|
739
|
+
const file = path.join(dir, name);
|
|
740
|
+
if (Date.now() - statSync(file).mtimeMs > JOB_MAX_AGE_MS) unlinkSync(file);
|
|
741
|
+
}
|
|
742
|
+
} catch { /* a sweep is a favour */ }
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* SubagentStop: queue the finished sub-agent for the session's one run, no model. The agent's notes are
|
|
747
|
+
* read later, by the worker, from the paths kept here (its own transcript, never the parent's: B10).
|
|
748
|
+
*/
|
|
749
|
+
function queueAgentLesson(meta, args, install) {
|
|
750
|
+
const agent = subagentNameOf(meta);
|
|
751
|
+
const dir = jobDir();
|
|
752
|
+
if (!agent || !install || !dir) return;
|
|
753
|
+
const payload = {};
|
|
754
|
+
for (const k of ['agent_transcript_path', 'transcript_path', 'last_assistant_message']) {
|
|
755
|
+
if (typeof meta[k] === 'string' && meta[k]) payload[k] = meta[k];
|
|
756
|
+
}
|
|
757
|
+
if (!payload.agent_transcript_path && !payload.transcript_path && !payload.last_assistant_message) return;
|
|
758
|
+
// One queued line stays small (the tail of the report is what a lesson is about); a line still over the
|
|
759
|
+
// cap, a path too long to be one, is dropped rather than written.
|
|
760
|
+
if (payload.last_assistant_message) payload.last_assistant_message = tail(payload.last_assistant_message, MAX_QUEUED_REPLY_CHARS);
|
|
761
|
+
const line = JSON.stringify({ agent, payload });
|
|
762
|
+
if (line.length > MAX_QUEUED_LINE_CHARS) return;
|
|
763
|
+
try {
|
|
764
|
+
mkdirSync(dir, { recursive: true });
|
|
765
|
+
const file = path.join(dir, `agents-${sessionKey(meta.session_id)}.jsonl`);
|
|
766
|
+
appendFileSync(file, `${line}\n`);
|
|
767
|
+
} catch { /* a lesson is a favour, never a failed hook */ }
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* The queued lessons of a session: the latest per agent, at most `MAX_LESSON_AGENTS`, and the queue's file. The
|
|
772
|
+
* queue is NOT removed here: `startDistil` removes it once the job is written and started, so a failed write or
|
|
773
|
+
* start leaves the lessons for the next PreCompact or SessionEnd.
|
|
774
|
+
*/
|
|
775
|
+
function readQueuedLessons(session) {
|
|
776
|
+
const dir = jobDir();
|
|
777
|
+
if (!dir) return { agents: [], file: null };
|
|
778
|
+
const file = path.join(dir, `agents-${sessionKey(session)}.jsonl`);
|
|
779
|
+
let text;
|
|
780
|
+
try { text = readFileSync(file, 'utf8'); } catch { return { agents: [], file: null }; }
|
|
781
|
+
const latest = new Map();
|
|
782
|
+
for (const line of splitLines(text).slice(-MAX_QUEUED_LESSONS)) {
|
|
783
|
+
try {
|
|
784
|
+
const row = JSON.parse(line);
|
|
785
|
+
if (typeof row.agent === 'string' && row.payload && typeof row.payload === 'object') latest.set(row.agent, row);
|
|
786
|
+
} catch { /* a torn line is skipped */ }
|
|
787
|
+
}
|
|
788
|
+
return { agents: [...latest.values()].slice(-MAX_LESSON_AGENTS), file };
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* PreCompact and SessionEnd: write the job, start the worker apart from this process, return at once
|
|
793
|
+
* (D12, D14). Nothing here waits on the model, and nothing reads the transcript: a SessionEnd hook is
|
|
794
|
+
* killed when its session ends (S1b), and a compaction must not wait. `GENESEED_LEARN_INLINE=1` runs the
|
|
795
|
+
* same job in this process instead: for a test, or a person debugging the distil.
|
|
796
|
+
*/
|
|
797
|
+
function startDistil(meta, args, install, hookEvent, llm) {
|
|
798
|
+
const transcript = typeof meta.transcript_path === 'string' && meta.transcript_path ? meta.transcript_path : null;
|
|
799
|
+
const { agents, file: queue } = readQueuedLessons(meta.session_id);
|
|
800
|
+
if (!transcript && !agents.length) return 0;
|
|
801
|
+
const job = {
|
|
802
|
+
v: 1, event: hookEvent, host: args.host || 'claude', memory: args.memory ?? null, transcript, agents,
|
|
803
|
+
};
|
|
804
|
+
const dropQueue = () => { if (queue) { try { unlinkSync(queue); } catch { /* the sweep gets it */ } } };
|
|
805
|
+
const dir = jobDir();
|
|
806
|
+
if (process.env.GENESEED_LEARN_INLINE) {
|
|
807
|
+
runJob(job, llm);
|
|
808
|
+
dropQueue();
|
|
809
|
+
return 0;
|
|
810
|
+
}
|
|
811
|
+
// Never inline on a real hook event: it would hold the session on the model (D12). No folder to put the job
|
|
812
|
+
// in, or no install to name its store: skip, say so, and let status and doctor say so too.
|
|
813
|
+
if (!install || !dir) {
|
|
814
|
+
const why = !install ? 'no Geneseed install found for this hook' : 'no machine cache folder';
|
|
815
|
+
err(`[learn] ${why} - distil skipped.
|
|
816
|
+
`);
|
|
817
|
+
writeLearnLast(false, `${why}; distil skipped`);
|
|
818
|
+
return 0;
|
|
819
|
+
}
|
|
820
|
+
try {
|
|
821
|
+
mkdirSync(dir, { recursive: true });
|
|
822
|
+
sweepJobs(dir);
|
|
823
|
+
const file = path.join(dir, `job-${Date.now()}-${process.pid}.json`);
|
|
824
|
+
writeFileSync(file, `${JSON.stringify(job)}\n`);
|
|
825
|
+
spawnWorker(file);
|
|
826
|
+
dropQueue();
|
|
827
|
+
} catch (e) {
|
|
828
|
+
err(`[learn] could not start the distil worker: ${e instanceof Error ? e.message : e}\n`);
|
|
829
|
+
writeLearnLast(false, `could not start the distil worker: ${e instanceof Error ? e.message : e}`);
|
|
830
|
+
}
|
|
831
|
+
return 0;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* THE SECOND SPAWN on the hook path (ADR 0002): this process's own node, running this checkout's hook
|
|
836
|
+
* entry with one verb, detached and unref'd with no stdio, so it outlives the session's end (S1c). The
|
|
837
|
+
* argv is fixed: no `$GENESEED_LLM` word, no payload text, reaches it but the job file's path.
|
|
838
|
+
*/
|
|
839
|
+
function spawnWorker(jobFile) {
|
|
840
|
+
const child = spawn(process.execPath, [path.join(ROOT, 'bin', 'geneseed-hook.mjs'), 'learn-worker', jobFile],
|
|
841
|
+
{ detached: true, windowsHide: true, stdio: 'ignore' });
|
|
842
|
+
child.on('error', (e) => { writeLearnLast(false, `could not start the distil worker: ${e.message}`); });
|
|
843
|
+
child.unref();
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** The job's run: the transcript's distil, then each queued sub-agent's lesson. Always 0. */
|
|
847
|
+
function runJob(job, llm) {
|
|
848
|
+
if (!job) return 0;
|
|
849
|
+
if (typeof llm !== 'string' || !llm.trim()) {
|
|
850
|
+
writeLearnLast(false, '$GENESEED_LLM is not set for the distil worker');
|
|
851
|
+
return 0;
|
|
852
|
+
}
|
|
853
|
+
run = { fail: null, facts: 0 };
|
|
854
|
+
// Marked running BEFORE the model is called, with the latest time the run may end (every call can take the
|
|
855
|
+
// timeout): a hung CLI never reaches the line below, so this mark is what `status` finds.
|
|
856
|
+
writeLearnLast(null, '', 0, { runningFor: (1 + MAX_LESSON_AGENTS) * llmTimeoutSeconds() + 60 });
|
|
857
|
+
try { return runJobIn(job, llm); } finally {
|
|
858
|
+
const { fail, facts } = run;
|
|
859
|
+
run = null;
|
|
860
|
+
writeLearnLast(!fail, fail || '', facts);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function runJobIn(job, llm) {
|
|
865
|
+
const memDir = typeof job.memory === 'string' ? resolveMemoryDir(job.memory) : null;
|
|
866
|
+
try {
|
|
867
|
+
if (typeof job.transcript === 'string' && job.transcript) {
|
|
868
|
+
const payload = { transcript_path: job.transcript };
|
|
869
|
+
const notes = tail(readNotes(JSON.stringify(payload), payload), MAX_NOTES_CHARS);
|
|
870
|
+
if (notes.trim()) distil(notes, memDir, llm, job.event || 'SessionEnd');
|
|
871
|
+
}
|
|
872
|
+
for (const row of Array.isArray(job.agents) ? job.agents.slice(0, MAX_LESSON_AGENTS) : []) {
|
|
873
|
+
const agent = resolveAgentName(row?.agent);
|
|
874
|
+
if (!agent || !memDir || !row.payload) continue;
|
|
875
|
+
const notes = tail(readNotes(JSON.stringify(row.payload), row.payload), MAX_NOTES_CHARS);
|
|
876
|
+
if (notes.trim()) learnAgentLesson(agent, notes, memDir, llm);
|
|
877
|
+
}
|
|
878
|
+
} catch (e) {
|
|
879
|
+
err(`[learn] the distil stopped: ${e instanceof Error ? e.message : e}\n`);
|
|
880
|
+
noteFail(`the distil stopped: ${e instanceof Error ? e.message : e}`);
|
|
881
|
+
}
|
|
882
|
+
return 0;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/** `a` and `b` name one folder, symlinks and Windows short names resolved; false when either cannot be resolved. */
|
|
886
|
+
function sameDir(a, b) {
|
|
887
|
+
try { return realpathSync.native(a) === realpathSync.native(b); } catch { return false; }
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Whether `memory` is a store a job may write: the machine tier's `memory/`, or the `memory/` of a Geneseed
|
|
892
|
+
* install (its folder holds the install's manifest). A job names a write target, so it never names an arbitrary one.
|
|
893
|
+
*/
|
|
894
|
+
function allowedMemory(memory) {
|
|
895
|
+
try {
|
|
896
|
+
// The path as the hook was given it: an install's `memory/` may be a junction or a symlink to a folder of another
|
|
897
|
+
// name, and its name and manifest are those of the install, not of where it points. The real path is for the
|
|
898
|
+
// machine-tier comparison only.
|
|
899
|
+
const abs = path.resolve(memory);
|
|
900
|
+
if (path.basename(abs) !== 'memory' || !isDir(abs)) return false;
|
|
901
|
+
if (sameDir(abs, sharedPaths().memory)) return true;
|
|
902
|
+
return existsSync(path.join(path.dirname(abs), GLOBAL_MANIFEST));
|
|
903
|
+
} catch { return false; }
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* `learn-worker <job>` — the detached process's verb: run the job file a hook wrote, then delete it.
|
|
908
|
+
* Nothing it prints is read (stdio is ignored), and nothing here exits non-zero: no host waits on it.
|
|
909
|
+
*
|
|
910
|
+
* A JOB IS DATA, NEVER A COMMAND. The path arrives on an argv an agent could be talked into running, and a
|
|
911
|
+
* repository can ship a file of that name, so three things hold: the file sits in the machine cache's own
|
|
912
|
+
* learn-jobs folder (its real path equals `jobDir()`'s, so a folder merely NAMED learn-jobs does not count);
|
|
913
|
+
* the model command is this process's own `$GENESEED_LLM`, inherited from the hook that started it, and a job
|
|
914
|
+
* holds none; and the store it names is the machine tier's memory or an install's. A file outside that folder
|
|
915
|
+
* or not named job-*.json is left exactly as it is; a job inside it that names a foreign store is deleted without being run.
|
|
916
|
+
*/
|
|
917
|
+
export function cmdLearnWorker(args) {
|
|
918
|
+
if (process.env.GENESEED_LEARN_CHILD || !args.file) return 0;
|
|
919
|
+
const file = path.resolve(args.file);
|
|
920
|
+
const dir = jobDir();
|
|
921
|
+
if (!dir || !sameDir(path.dirname(file), dir) || !/^job-[\w.-]+\.json$/.test(path.basename(file))) return 0;
|
|
922
|
+
try {
|
|
923
|
+
const job = JSON.parse(readFileSync(file, 'utf8'));
|
|
924
|
+
if (!job || typeof job.memory !== 'string' || !allowedMemory(job.memory)) {
|
|
925
|
+
err('[learn] the job names no memory store of ours - refused.\n');
|
|
926
|
+
writeLearnLast(false, 'the job names no memory store of ours - refused');
|
|
927
|
+
} else {
|
|
928
|
+
runJob(job, process.env.GENESEED_LLM);
|
|
929
|
+
}
|
|
930
|
+
} catch (e) {
|
|
931
|
+
// An unreadable job is no job, but the last verdict must not go on saying the run before it was fine.
|
|
932
|
+
writeLearnLast(false, `the job could not be read: ${e instanceof Error ? e.message : e}`);
|
|
933
|
+
} finally {
|
|
934
|
+
try { if (existsSync(file)) unlinkSync(file); } catch { /* the sweep gets it */ }
|
|
935
|
+
}
|
|
936
|
+
return 0;
|
|
937
|
+
}
|
package/js/hosts/installs.mjs
CHANGED
|
@@ -35,7 +35,7 @@ import { existsSync, readdirSync } from 'node:fs';
|
|
|
35
35
|
import path from 'node:path';
|
|
36
36
|
|
|
37
37
|
import {
|
|
38
|
-
CONFIG, CONTEXT_WINDOWS, CONTEXT_WINDOW_MARKER, DEFAULT_CONTEXT_WINDOW, DEFAULT_TIERS, GATE_SWITCHES, PACK_ORDER,
|
|
38
|
+
CONFIG, CONTEXT_WINDOWS, CONTEXT_WINDOW_MARKER, DEFAULT_CONTEXT_WINDOW, DEFAULT_LEARN, DEFAULT_TIERS, GATE_SWITCHES, LEARN_CHOICES, LEARN_MARKER, PACK_ORDER,
|
|
39
39
|
RETIRED_KIT_IDS, TIERS_CHOICES, TIERS_MARKER, THEMES, WORKFLOW_PROVIDER_HEADING, discoverNames, linkedSkillIds, loadKits, resolveSkillNames,
|
|
40
40
|
} from '../build/source.mjs';
|
|
41
41
|
import {
|
|
@@ -557,6 +557,25 @@ export function tiersOfDir(d, host = null) {
|
|
|
557
557
|
}, DEFAULT_TIERS, host);
|
|
558
558
|
}
|
|
559
559
|
|
|
560
|
+
const LEARN_RE = new RegExp(`^${LEARN_MARKER}:[ \\t]*(\\S+?)[ \\t]*\\r?$`, 'm');
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* The learn model a DEPLOYED install was built with (`--learn`), read back so `rebuild-all`,
|
|
564
|
+
* `upgrade`, `diff` and the guard re-render it. A missing line is the default (`light`): the
|
|
565
|
+
* marker is only ever written off it, so an install older than the option is a default install.
|
|
566
|
+
* An unknown value reads as the default too, so a hand-edited line can never reach `--learn`
|
|
567
|
+
* and refuse a rebuild.
|
|
568
|
+
*/
|
|
569
|
+
export function learnOfDir(d, host = null) {
|
|
570
|
+
return firstCarrier(d, (carrierPath) => {
|
|
571
|
+
const text = readMaybe(carrierPath);
|
|
572
|
+
if (text === null) return undefined;
|
|
573
|
+
const m = LEARN_RE.exec(text);
|
|
574
|
+
if (!m) return undefined;
|
|
575
|
+
return LEARN_CHOICES.includes(m[1]) ? m[1] : DEFAULT_LEARN;
|
|
576
|
+
}, DEFAULT_LEARN, host);
|
|
577
|
+
}
|
|
578
|
+
|
|
560
579
|
/**
|
|
561
580
|
* Whether a DEPLOYED install keeps one law's hook gate armed — `true` (armed) or `false` (its
|
|
562
581
|
* `<marker>: off` line, written by a build with that gate's `--no-*-gate` flag; `GATE_SWITCHES`).
|
|
@@ -898,7 +917,7 @@ export function installedDefaults() {
|
|
|
898
917
|
const found = {
|
|
899
918
|
theme: null, posture: null, mode: null, emit: null, footprint: null, doctrines: null,
|
|
900
919
|
excludeRules: null, excludeSkills: null, kits: null, sharedTier: false,
|
|
901
|
-
contextWindow: DEFAULT_CONTEXT_WINDOW, tiers: DEFAULT_TIERS,
|
|
920
|
+
contextWindow: DEFAULT_CONTEXT_WINDOW, tiers: DEFAULT_TIERS, learn: DEFAULT_LEARN,
|
|
902
921
|
};
|
|
903
922
|
const candidates = [];
|
|
904
923
|
for (const { host, configDir } of HOSTS) {
|
|
@@ -952,6 +971,7 @@ export function installedDefaults() {
|
|
|
952
971
|
// otherwise speaks.
|
|
953
972
|
if (found.contextWindow === DEFAULT_CONTEXT_WINDOW) found.contextWindow = contextWindowOfDir(base);
|
|
954
973
|
if (found.tiers === DEFAULT_TIERS) found.tiers = tiersOfDir(base);
|
|
974
|
+
if (found.learn === DEFAULT_LEARN) found.learn = learnOfDir(base);
|
|
955
975
|
}
|
|
956
976
|
return found;
|
|
957
977
|
}
|