geneseed 5.4.0 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/README.md +31 -1
- package/SHIPPED.md +1 -1
- package/adapters/bob/README.md +12 -1
- package/adapters/opencode/README.md +2 -1
- package/adapters/opencode/plugins/geneseed-context.js +71 -10
- package/adapters/opencode/plugins/geneseed-guard.js +101 -19
- package/adapters/opencode/plugins/geneseed-learn.js +641 -6
- package/bin/geneseed-cli.mjs +3 -0
- package/bin/geneseed-hook.mjs +2 -1
- package/docs/concepts/agents.md +13 -1
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/foreman-mode.md +22 -3
- package/docs/concepts/hook-gates.md +1 -1
- package/docs/concepts/hooks.md +22 -5
- package/docs/concepts/host-matrix.md +2 -2
- package/docs/concepts/hosts.md +1 -1
- package/docs/concepts/shared-tier.md +1 -1
- package/docs/concepts/skills.md +21 -1
- package/docs/concepts/themes.md +1 -1
- package/docs/extending.md +11 -2
- package/docs/guides/install-clone.md +18 -0
- package/docs/guides/install-scripted.md +8 -2
- package/docs/guides/install.md +19 -1
- package/docs/guides/upgrade.md +1 -1
- package/docs/reference/env-context.md +1 -1
- package/docs/reference/environment.md +1 -1
- package/docs/reference/plugin-learn.md +4 -0
- package/docs/reference/profiles.md +226 -0
- package/docs/token-footprint.md +9 -4
- package/docs/understand/design-choices-engineering.md +1 -1
- package/docs/web-ui.md +3 -1
- package/harness.config.json +1 -1
- package/js/README.md +9 -2
- package/js/build/args.mjs +4 -3
- package/js/build/catalog.mjs +11 -1
- package/js/build/driver.mjs +42 -11
- package/js/build/emit-claude.mjs +24 -1
- package/js/build/emit-opencode.mjs +3 -0
- package/js/build/export.mjs +12 -17
- package/js/build/generate.mjs +2 -1
- package/js/build/notes-migrate.mjs +99 -0
- package/js/build/profile.mjs +14 -6
- package/js/build/render.mjs +34 -10
- package/js/build/source.mjs +85 -2
- package/js/cli-table.json +164 -4
- package/js/hosts/agent-runs.mjs +205 -0
- package/js/hosts/done-checks.mjs +3 -1
- package/js/hosts/hooks-done.mjs +91 -16
- package/js/hosts/hooks-learn.mjs +85 -0
- package/js/hosts/hooks-prims.mjs +39 -1
- package/js/hosts/hooks.mjs +10 -4
- package/js/hosts/hosts.mjs +10 -0
- package/js/hosts/installs.mjs +25 -1
- package/js/hosts/link.mjs +45 -10
- package/js/hosts/native.mjs +42 -5
- package/js/hosts/opencode.mjs +1 -1
- package/js/hosts/settings.mjs +72 -0
- package/js/hosts/spec-feedback.mjs +538 -0
- package/js/hosts/usage.mjs +67 -8
- package/js/inspect/agent-scores.mjs +118 -0
- package/js/inspect/checks-authoring.mjs +2 -1
- package/js/inspect/checks-build.mjs +20 -4
- package/js/inspect/checks-repo.mjs +27 -2
- package/js/inspect/cost.mjs +6 -5
- package/js/inspect/diff.mjs +25 -5
- package/js/inspect/doctor.mjs +4 -0
- package/js/inspect/status.mjs +3 -1
- package/js/inspect/validate.mjs +1 -0
- package/js/lib/machine-dir.mjs +8 -0
- package/js/lib/paths.mjs +4 -1
- package/js/maintain/profile-scope.mjs +145 -0
- package/js/maintain/profiles.mjs +486 -0
- package/js/maintain/setup.mjs +409 -15
- package/js/maintain/uninstall.mjs +4 -1
- package/js/maintain/update.mjs +1 -1
- package/js/web/actions.mjs +28 -38
- package/js/web/api.mjs +7 -2
- package/js/web/handler.mjs +8 -0
- package/js/web/jobs.mjs +5 -4
- package/js/web/profiles-api.mjs +201 -0
- package/js/web/routes.mjs +5 -0
- package/package.json +2 -1
- package/profiles/autonomous.json +14 -0
- package/profiles/corporate.json +14 -0
- package/profiles/guillaume-claude-global.json +16 -0
- package/profiles/mentor.json +13 -0
- package/profiles/minimal.json +15 -0
- package/profiles/starter.json +14 -0
- package/src/AGENT.md.tmpl +1 -1
- package/src/agents/_self-improvement.md +15 -7
- package/src/agents/_template.md +4 -2
- package/src/agents/advocate.md +1 -1
- package/src/agents/architect.md +1 -1
- package/src/agents/developer.md +10 -3
- package/src/agents/devops-engineer.md +7 -6
- package/src/agents/docker-expert.md +1 -1
- package/src/agents/docs.md +1 -1
- package/src/agents/empiricist.md +1 -1
- package/src/agents/explorer.md +4 -2
- package/src/agents/framer.md +1 -1
- package/src/agents/historian.md +1 -1
- package/src/agents/kubernetes-specialist.md +4 -2
- package/src/agents/memory-curator.md +1 -1
- package/src/agents/operator.md +1 -1
- package/src/agents/performance.md +1 -1
- package/src/agents/pragmatist.md +1 -1
- package/src/agents/react-engineer.md +1 -1
- package/src/agents/react-reviewer.md +1 -1
- package/src/agents/researcher.md +1 -1
- package/src/agents/reviewer.md +10 -3
- package/src/agents/security.md +1 -1
- package/src/agents/skeptic.md +1 -1
- package/src/agents/spring-boot-engineer.md +4 -4
- package/src/agents/spring-reviewer.md +5 -3
- package/src/agents/spring-security.md +1 -1
- package/src/agents/steward.md +1 -1
- package/src/agents/tester.md +4 -2
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/memory/README.md +12 -2
- package/src/modes/foreman.md +23 -10
- package/src/skill-descriptions.json +63 -0
- package/src/skills/_self-improvement.md +42 -26
- package/src/skills/_template.md +3 -1
- package/src/skills/brainstorm.md +35 -22
- package/src/skills/codebase-design.md +2 -2
- package/src/skills/daydream/VENDOR.md +6 -0
- package/src/skills/diagram-design/SKILL.md +12 -7
- package/src/skills/diagram-design/VENDOR.md +23 -14
- package/src/skills/diagram-design/references/layout-budget.md +7 -1
- package/src/skills/diagram-design/references/onboarding.md +1 -1
- package/src/skills/diagram-design/references/primitives-core.md +1 -1
- package/src/skills/diagram-design/references/semantic-patterns.md +1 -1
- package/src/skills/diagram-design/references/style-guide.md +1 -1
- package/src/skills/diagram-design/references/type-dependency.md +69 -0
- package/src/skills/diagram-design/references/type-event-modeling.md +36 -0
- package/src/skills/diagram-design/references/type-requirement-traceability.md +45 -0
- package/src/skills/diagram-design/references/type-sbgn.md +80 -0
- package/src/skills/diagram-design/references/type-scatter.md +1 -1
- package/src/skills/diagram-design/references/type-steps.md +180 -0
- package/src/skills/diagram-design/references/type-unit-grid.md +63 -0
- package/src/skills/explain-changes/VENDOR.md +5 -1
- package/src/skills/geneseed-code-review.md +2 -1
- package/src/skills/parallel-agents.md +12 -1
- package/src/skills/pipeline.md +3 -3
- package/src/skills/plan.md +5 -4
- package/src/skills/react-view-transitions/AGENTS.md +26 -26
- package/src/skills/react-view-transitions/SKILL.md +1 -1
- package/src/skills/react-view-transitions/VENDOR.md +19 -4
- package/src/skills/release.md +7 -2
- package/src/skills/rule/approve.md +2 -1
- package/src/skills/skill-forge.md +5 -3
- package/src/skills/spring-boot/cloud.md +19 -1
- package/src/skills/spring-boot/logging.md +5 -3
- package/src/skills/spring-boot/web.md +27 -2
- package/src/skills/spring-boot.md +4 -2
- package/src/skills/spring-data-jpa.md +18 -4
- package/src/skills/spring-testing.md +4 -0
- package/src/skills/token-report/VENDOR.md +5 -1
- package/src/upstreams.json +6 -6
- package/themes/README.md +3 -1
- package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
- package/web/dist/assets/{Activity-D2kOc3yi.js → Activity-bUSPM3Dl.js} +1 -1
- package/web/dist/assets/{ActivityDetail-By3xOr21.js → ActivityDetail-AHRoXeFN.js} +1 -1
- package/web/dist/assets/{Bonsai-CBWDTBA4.js → Bonsai-B5XY9pid.js} +1 -1
- package/web/dist/assets/{CopyButton-BVbpriMB.js → CopyButton-C0wwRR9H.js} +1 -1
- package/web/dist/assets/{Dashboard-CIJLPHM9.js → Dashboard-DPAA96EI.js} +2 -2
- package/web/dist/assets/{Docs-CiRRIELs.js → Docs-CpGDq165.js} +1 -1
- package/web/dist/assets/{Factories-DhyK0O8d.js → Factories-cNhETa5Q.js} +1 -1
- package/web/dist/assets/{GreenhouseView-DW3PgTPy.js → GreenhouseView-DO3ADmT9.js} +1 -1
- package/web/dist/assets/Installs-D3dDyq10.js +3 -0
- package/web/dist/assets/{JournalView-O65qEWfp.js → JournalView--W-Lw_V9.js} +1 -1
- package/web/dist/assets/{Kits-C5U-yT6Z.js → Kits-ChfehxY6.js} +1 -1
- package/web/dist/assets/Laws-CNxYmV36.js +4 -0
- package/web/dist/assets/{LibRows-D6-CVa3K.js → LibRows-CiPvsRYB.js} +1 -1
- package/web/dist/assets/{Library-CzPlerd6.js → Library-BxQvbwVU.js} +1 -1
- package/web/dist/assets/{Loops-CqNF_-nS.js → Loops-DAblKkyq.js} +1 -1
- package/web/dist/assets/{OperatorHudView-BNr8K5qj.js → OperatorHudView-QtSaSyYm.js} +1 -1
- package/web/dist/assets/{Personal-DeDb9e8O.js → Personal-DxSGv638.js} +1 -1
- package/web/dist/assets/{Settings-B8MPN_AD.js → Settings-CgTbhvRv.js} +1 -1
- package/web/dist/assets/{Tabs-DJzAez4h.js → Tabs-Cf4X1hdz.js} +1 -1
- package/web/dist/assets/api-CZ-x0iWG.js +1 -0
- package/web/dist/assets/{controls-D4wmg_pl.js → controls-CK7qHA8H.js} +1 -1
- package/web/dist/assets/{index-BL3P-9Rg.js → index-B_pTwZra.js} +4 -4
- package/web/dist/assets/index-CzfImiYb.css +1 -0
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Installs-B6nlo-Ly.js +0 -3
- package/web/dist/assets/Laws-CuTw_XNf.js +0 -4
- package/web/dist/assets/api-DLDVY3K-.js +0 -1
- package/web/dist/assets/index-CRWqKxfY.css +0 -1
package/js/hosts/hooks-learn.mjs
CHANGED
|
@@ -19,6 +19,9 @@ import { recordOwnWrites, storeReport } from './store-watch.mjs';
|
|
|
19
19
|
import {
|
|
20
20
|
existingSlugs, readFacts, writeMemories, consolidateMemory, appendAgentLesson,
|
|
21
21
|
} from './memory-files.mjs';
|
|
22
|
+
import { captureSpecFeedback, projectNotesDir, subagentReport, turnReply } from './spec-feedback.mjs';
|
|
23
|
+
import { gitRootOf } from './gitref.mjs';
|
|
24
|
+
import { recordAgentRun } from './agent-runs.mjs';
|
|
22
25
|
|
|
23
26
|
const ROOT = path.resolve(import.meta.dirname, '../..');
|
|
24
27
|
|
|
@@ -321,6 +324,71 @@ function sharedStoreFor(install, args) {
|
|
|
321
324
|
} catch { return args.memory; }
|
|
322
325
|
}
|
|
323
326
|
|
|
327
|
+
/**
|
|
328
|
+
* The two notes roots a line can go to (./spec-feedback.mjs `feedbackTargets`), as the render
|
|
329
|
+
* names them: MACHINE is the tier's `notes/` (`{{PATH_NOTES}}`) for every host and install kind;
|
|
330
|
+
* PROJECT is `<project>/notebook` (`{{PATH_PROJECT_NOTES}}`), one folder for every host.
|
|
331
|
+
*
|
|
332
|
+
* The project is the install's parent for a project install (`<repo>/.claude`, `.bob`,
|
|
333
|
+
* `.openclaude`), and for a global install the git root of the session's project
|
|
334
|
+
* (`hookProjectDir`); either way a linked worktree's main checkout, since a worktree and its notes
|
|
335
|
+
* go when it is removed. A global session outside any repo (home, a temp folder) has no project:
|
|
336
|
+
* its project lines are dropped, never sent to the machine notes, where every repo would read them.
|
|
337
|
+
*
|
|
338
|
+
* The machine notes need the tier's folder to exist; it does on any machine an emit has run on
|
|
339
|
+
* (the install registry lives there), and only `notes/<sub>/` is ever created under it, never
|
|
340
|
+
* `memory/`, whose presence is what `sharedStoreFor` reads as "the tier is seeded".
|
|
341
|
+
*/
|
|
342
|
+
export function notesRootsOf(install, host, payloadCwd) {
|
|
343
|
+
if (!install) return { machine: null, project: null };
|
|
344
|
+
let machine = null;
|
|
345
|
+
try { machine = sharedPaths().notes; } catch { /* no home directory: no tier */ }
|
|
346
|
+
let base = null;
|
|
347
|
+
try {
|
|
348
|
+
base = isGlobalInstall(host ?? null, install) ? gitRootOf(hookProjectDir(payloadCwd)) : path.dirname(install);
|
|
349
|
+
} catch { base = null; }
|
|
350
|
+
return { machine, project: projectNotesDir(base) };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* SubagentStop: the `spec-feedback:` lines of the sub-agent's final report into the notes its next
|
|
355
|
+
* dispatch reads (./spec-feedback.mjs). Stop: the `[skill:<name>]` lines of the main session's
|
|
356
|
+
* final reply into the notes that skill reads (`agent` null). Skill lines are checked against
|
|
357
|
+
* `<install>/skills/`. No model, so `$GENESEED_LLM` does not gate it. Silent on stdout, which an
|
|
358
|
+
* advisory verdict or the change report may hold, and a failure costs only the capture.
|
|
359
|
+
*/
|
|
360
|
+
function captureFeedback(agent, report, args, install, meta) {
|
|
361
|
+
// Most replies hold no feedback line: then the two roots are never resolved (two fs walks).
|
|
362
|
+
if (!/spec-feedback/i.test(report || '')) return;
|
|
363
|
+
try {
|
|
364
|
+
const skills = install ? path.join(install, 'skills') : null;
|
|
365
|
+
const written = captureSpecFeedback(agent, report, notesRootsOf(install, args.host, meta.cwd), undefined, skills);
|
|
366
|
+
if (written.length) err(`[learn] spec-feedback -> ${written.join(', ')}\n`);
|
|
367
|
+
} catch { /* a note never fails the hook */ }
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* SubagentStop: the report's feedback lines into the notes at every stop (`subagentFeedback`, a
|
|
372
|
+
* blocked one included), then, past the done gate, the turn's line into the outcome ledger
|
|
373
|
+
* (./agent-runs.mjs, `subagentEnded`), both off ONE read of the report. `done` is what
|
|
374
|
+
* the gate can say through its return (that file's header): null when it did not run, 'not-judged'
|
|
375
|
+
* when it had no transcript to judge, else 'ended'. Unnamed agents get neither. (Bob sends no
|
|
376
|
+
* SubagentStop, so no Bob case reaches this.)
|
|
377
|
+
*/
|
|
378
|
+
function subagentFeedback(meta, args, read, install) {
|
|
379
|
+
const agent = subagentNameOf(meta);
|
|
380
|
+
if (!agent) return null;
|
|
381
|
+
let report = '';
|
|
382
|
+
try { report = subagentReport(meta, read); } catch { /* no report: nothing to capture */ }
|
|
383
|
+
captureFeedback(agent, report, args, install, meta);
|
|
384
|
+
return { agent, report };
|
|
385
|
+
}
|
|
386
|
+
function subagentEnded(meta, args, read, install, { agent, report }) {
|
|
387
|
+
const ran = !args.file && !args.noDoneGate;
|
|
388
|
+
const judged = typeof meta.agent_transcript_path === 'string' && meta.agent_transcript_path;
|
|
389
|
+
recordAgentRun(install, agent, meta, { done: !ran ? null : judged ? 'ended' : 'not-judged', report, read });
|
|
390
|
+
}
|
|
391
|
+
|
|
324
392
|
export function cmdLearn(args) {
|
|
325
393
|
// B2: stand straight down inside a model-CLI child `runLlm` just spawned (see its comment).
|
|
326
394
|
// Checked before anything else — a child never gets as far as reading its own stdin, let
|
|
@@ -377,8 +445,25 @@ export function cmdLearn(args) {
|
|
|
377
445
|
// An advisory verdict already holds stdout: nothing below may print there after it.
|
|
378
446
|
const verdict = (hookEvent === 'Stop' || hookEvent === 'SubagentStop') && !args.file && !args.noDoneGate
|
|
379
447
|
? doneGate(meta, args, install, read) : null;
|
|
448
|
+
|
|
449
|
+
// The feedback lines are kept at EVERY stop, a blocked one included, model or none: the reply a
|
|
450
|
+
// block sends back to work is the one that carries the line, and the reply that finally ends the
|
|
451
|
+
// turn ("lint and suite green") does not repeat it, so capturing only after the block lost it for
|
|
452
|
+
// good. Silent on stdout, so the verdict stays the one document there; a line seen again at the
|
|
453
|
+
// next stop adds no note. A sub-agent's lines come from its report, a skill's `[skill:<name>]`
|
|
454
|
+
// lines (it runs in the main context) from the turn's final reply.
|
|
455
|
+
const sub = hookEvent === 'SubagentStop' ? subagentFeedback(meta, args, read, install) : null;
|
|
456
|
+
if (hookEvent === 'Stop') {
|
|
457
|
+
let reply = '';
|
|
458
|
+
try { reply = turnReply(meta, read); } catch { /* no reply: nothing to capture */ }
|
|
459
|
+
if (reply) captureFeedback(null, reply, args, install, meta);
|
|
460
|
+
}
|
|
380
461
|
if (verdict === 'block') return 0;
|
|
381
462
|
|
|
463
|
+
// The sub-agent's turn is over: its outcome line is written. A blocked turn returned above, so a
|
|
464
|
+
// ledger line is one finished turn.
|
|
465
|
+
if (sub) subagentEnded(meta, args, read, install, sub);
|
|
466
|
+
|
|
382
467
|
// The change report, at the turn's real end (./store-watch.mjs). One JSON document on stdout, so an
|
|
383
468
|
// advisory already there keeps it, and Bob reads no stdout here at all: those go to stderr.
|
|
384
469
|
if (hookEvent === 'Stop' && !args.file && install) {
|
package/js/hosts/hooks-prims.mjs
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { statSync, readFileSync, readdirSync } from 'node:fs';
|
|
12
12
|
import path from 'node:path';
|
|
13
|
+
import { isatty } from 'node:tty';
|
|
13
14
|
import { comparePaths } from '../lib/paths.mjs';
|
|
14
15
|
import { readTail } from '../lib/fs.mjs';
|
|
15
16
|
|
|
@@ -546,8 +547,45 @@ export function activityOn(root) {
|
|
|
546
547
|
* The `activity` verb, wired to the events no other verb runs on (UserPromptSubmit; SessionEnd
|
|
547
548
|
* on Claude and OpenClaude; SubagentStart runs `context` since the agent loadout). It decides nothing and prints nothing: the entry's
|
|
548
549
|
* `trackActivity` records the payload after every verb alike, this one included.
|
|
550
|
+
*
|
|
551
|
+
* Its one act of its own: a prompt typed as `/<skill>` is counted (`recordSlash`, ./usage.mjs).
|
|
552
|
+
* The test before the parse is a regex over the raw stdin, so a plain prompt costs no import;
|
|
553
|
+
* only a slash prompt loads the counter and `./hosts.mjs`. It stands down where the tool counter
|
|
554
|
+
* does: an excluded folder, a model-CLI child `learn` spawned, a terminal, and beside a live
|
|
555
|
+
* project install of the same host (`globalHookStandingDown` on `activity`, the verb that
|
|
556
|
+
* install's own UserPromptSubmit runs). Skills resolve in the install's `skills/`, the host's
|
|
557
|
+
* global config dir's `skills/`, and the project's own `<marker>/skills/`. Bob: its UserPromptSubmit payload is read as Claude's
|
|
558
|
+
* (`prompt`), unverified on a live Bob. Always 0: on UserPromptSubmit exit 2 erases the prompt.
|
|
549
559
|
*/
|
|
550
|
-
|
|
560
|
+
// Leading blanks as `slashSkillOf` takes them (`^\s*`), spelled as JSON spells them: a raw blank,
|
|
561
|
+
// or an escaped `\n`, `\r`, `\t`. Narrower than that and a prompt it would count is never parsed.
|
|
562
|
+
const SLASH_PROMPT_RE = /"prompt"\s*:\s*"(?:\s|\\[nrt])*\//;
|
|
563
|
+
export async function cmdActivity(args) {
|
|
564
|
+
try {
|
|
565
|
+
if (!args || !args.root || process.env.GENESEED_NO_USAGE || process.env.GENESEED_LEARN_CHILD
|
|
566
|
+
|| isatty(0)) return 0;
|
|
567
|
+
const raw = readStdin();
|
|
568
|
+
if (!SLASH_PROMPT_RE.test(raw)) return 0;
|
|
569
|
+
const payload = JSON.parse(raw);
|
|
570
|
+
if (payload.hook_event_name && payload.hook_event_name !== 'UserPromptSubmit') return 0;
|
|
571
|
+
const [{ recordSlash }, hosts] = await Promise.all([import('./usage.mjs'), import('./hosts.mjs')]);
|
|
572
|
+
if (hosts.sovereignBypass(args.root)) return 0;
|
|
573
|
+
const projectDir = hosts.hookProjectDir(payload.cwd);
|
|
574
|
+
const row = hosts.HOSTS.find((h) => h.host === (args.host || 'claude'));
|
|
575
|
+
const skillDirs = [path.join(args.root, 'skills')];
|
|
576
|
+
if (row) {
|
|
577
|
+
// The host's global skills too: beside a project install the global hook stands down, so a
|
|
578
|
+
// skill only the global holds (the user's own, say) would otherwise be counted by neither.
|
|
579
|
+
try { skillDirs.push(path.join(row.configDir(), 'skills')); } catch { /* no resolvable global */ }
|
|
580
|
+
skillDirs.push(path.join(projectDir, row.projectMarker, 'skills'));
|
|
581
|
+
}
|
|
582
|
+
recordSlash(args.root, payload, {
|
|
583
|
+
skillDirs,
|
|
584
|
+
standingDown: () => hosts.usageStandingDown(args.root, projectDir, args.host, 'activity'),
|
|
585
|
+
});
|
|
586
|
+
} catch { /* a counter never fails a prompt */ }
|
|
587
|
+
return 0;
|
|
588
|
+
}
|
|
551
589
|
|
|
552
590
|
// The two output funnels, with Python's newline translation reproduced, are `printOut`/`printErr`
|
|
553
591
|
// in `js/lib/fs.mjs` — they moved there in P5c, beside `writeText`, which is the same rule for
|
package/js/hosts/hooks.mjs
CHANGED
|
@@ -60,7 +60,7 @@ import { markerLines } from '../lib/managed-block.mjs';
|
|
|
60
60
|
import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
|
|
61
61
|
import {
|
|
62
62
|
GATE_LEDGER, HOSTS, carrierBlock, carrierName, globalHookStandingDown, hookProjectDir, isSharedCarrier,
|
|
63
|
-
resolvePath, sovereignBypass,
|
|
63
|
+
resolvePath, sovereignBypass, usageStandingDown,
|
|
64
64
|
} from './hosts.mjs';
|
|
65
65
|
import {
|
|
66
66
|
currentBranch, gitCommonDirOf, gitRootOf, loopLaunched, mainWorktreeOf, protectedBranches,
|
|
@@ -1583,8 +1583,11 @@ export const cmdRuleGate = guardGate(ruleGate, 'rule-gate');
|
|
|
1583
1583
|
* for PreToolUse), so `gitDecide`/`ruleDecide` keep reading the Claude shape unchanged and
|
|
1584
1584
|
* never learn Bob exists. A no-op for an already-Claude-shaped payload: every field it sets
|
|
1585
1585
|
* is only filled in when the Claude-named field is absent.
|
|
1586
|
+
*
|
|
1587
|
+
* Exported for the in-process loss-table rows of tests/unit/hook_gates.test.mjs, which hand
|
|
1588
|
+
* Bob's own payload shape to `gitDecide` without a spawn per row.
|
|
1586
1589
|
*/
|
|
1587
|
-
function normaliseBobPayload(payload) {
|
|
1590
|
+
export function normaliseBobPayload(payload) {
|
|
1588
1591
|
if (!payload || typeof payload !== 'object') return payload;
|
|
1589
1592
|
const out = { ...payload };
|
|
1590
1593
|
if (!out.tool_input && payload.input && typeof payload.input === 'object') {
|
|
@@ -1611,8 +1614,11 @@ function toolGate(args) {
|
|
|
1611
1614
|
if (sovereignBypass(args.root)) return 0;
|
|
1612
1615
|
const payload = normaliseBobPayload(readPayload());
|
|
1613
1616
|
// Count a skill or subagent call before judging it: Bob runs this verb on every tool and
|
|
1614
|
-
// Claude/OpenClaude route their `Skill|Agent|Task` matcher here (js/hosts/usage.mjs).
|
|
1615
|
-
|
|
1617
|
+
// Claude/OpenClaude route their `Skill|Agent|Task` matcher here (js/hosts/usage.mjs). Only the
|
|
1618
|
+
// COUNT stands down beside a live project install, whose own tool-gate counts the call; the
|
|
1619
|
+
// gates below still run once per install, as before.
|
|
1620
|
+
recordUse(args.root, payload, undefined, () => usageStandingDown(args.root,
|
|
1621
|
+
hookProjectDir(payload && payload.cwd), args.host, 'tool-gate'));
|
|
1616
1622
|
const ti = (payload && payload.tool_input) || {};
|
|
1617
1623
|
return typeof ti.command === 'string' ? gitDecide(args, payload) : ruleDecide(args, payload);
|
|
1618
1624
|
}
|
package/js/hosts/hosts.mjs
CHANGED
|
@@ -197,6 +197,16 @@ export function globalHookStandingDown(hookRoot, projectDir, host, verb) {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
/**
|
|
201
|
+
* The usage counter's stand-down (js/hosts/usage.mjs): the same test, for the COUNT only. Not a
|
|
202
|
+
* `globalHookStandingDown` call with a literal verb, so `STAND_DOWN_VERBS`
|
|
203
|
+
* (js/maintain/profile-scope.mjs) stays the verbs whose whole hook stands down: `tool-gate` still
|
|
204
|
+
* judges every call on Bob beside a project install, and `activity` still records the turn.
|
|
205
|
+
*/
|
|
206
|
+
export function usageStandingDown(hookRoot, projectDir, host, verb) {
|
|
207
|
+
return globalHookStandingDown(hookRoot, projectDir, host, verb);
|
|
208
|
+
}
|
|
209
|
+
|
|
200
210
|
// The marker lives in the shim's FILENAME, not its directory: GENESEED_HOME relocates the dir,
|
|
201
211
|
// and a relocated install's hooks must stay recognisable to `GENESEED_HOOK_SNIFF`. Declared here
|
|
202
212
|
// rather than in ./shim.mjs because `ownHookVerb` below reads it, and shim.mjs imports this module.
|
package/js/hosts/installs.mjs
CHANGED
|
@@ -35,7 +35,8 @@ import { existsSync, readdirSync } from 'node:fs';
|
|
|
35
35
|
import path from 'node:path';
|
|
36
36
|
|
|
37
37
|
import {
|
|
38
|
-
CONFIG,
|
|
38
|
+
CONFIG, CONTEXT_WINDOWS, CONTEXT_WINDOW_MARKER, DEFAULT_CONTEXT_WINDOW, GATE_SWITCHES, PACK_ORDER,
|
|
39
|
+
RETIRED_KIT_IDS, THEMES, discoverNames, loadKits, resolveSkillNames,
|
|
39
40
|
} from '../build/source.mjs';
|
|
40
41
|
import {
|
|
41
42
|
CARRIERS, CLAUDE_STYLE, DISABLED_STASH, GLOBAL_MANIFEST, HOSTS, SHARED_TIER_RE, carriersFor, gateCarrierText, isHostGlobalDir,
|
|
@@ -492,6 +493,25 @@ export function sharedTierOfDir(d, host = null) {
|
|
|
492
493
|
}, false, host);
|
|
493
494
|
}
|
|
494
495
|
|
|
496
|
+
const CONTEXT_WINDOW_RE = new RegExp(`^${CONTEXT_WINDOW_MARKER}:[ \\t]*(\\S+?)[ \\t]*\\r?$`, 'm');
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* The context window a DEPLOYED install was built for (`--context-window`), read back so
|
|
500
|
+
* `rebuild-all`, `upgrade`, `diff`, the wizard, profiles and the console re-render it. A missing
|
|
501
|
+
* line is the default: the marker is only ever written off it (the kits line's contract), and an
|
|
502
|
+
* install older than the option is a default install. A value this checkout does not know reads
|
|
503
|
+
* as the default too, so a hand-edited line can never reach `--context-window` and refuse a rebuild.
|
|
504
|
+
*/
|
|
505
|
+
export function contextWindowOfDir(d, host = null) {
|
|
506
|
+
return firstCarrier(d, (carrierPath) => {
|
|
507
|
+
const text = readMaybe(carrierPath);
|
|
508
|
+
if (text === null) return undefined;
|
|
509
|
+
const m = CONTEXT_WINDOW_RE.exec(text);
|
|
510
|
+
if (!m) return undefined;
|
|
511
|
+
return Object.hasOwn(CONTEXT_WINDOWS, m[1]) ? m[1] : DEFAULT_CONTEXT_WINDOW;
|
|
512
|
+
}, DEFAULT_CONTEXT_WINDOW, host);
|
|
513
|
+
}
|
|
514
|
+
|
|
495
515
|
/**
|
|
496
516
|
* Whether a DEPLOYED install keeps one law's hook gate armed — `true` (armed) or `false` (its
|
|
497
517
|
* `<marker>: off` line, written by a build with that gate's `--no-*-gate` flag; `GATE_SWITCHES`).
|
|
@@ -833,6 +853,7 @@ export function installedDefaults() {
|
|
|
833
853
|
const found = {
|
|
834
854
|
theme: null, posture: null, mode: null, emit: null, footprint: null, doctrines: null,
|
|
835
855
|
excludeRules: null, excludeSkills: null, kits: null, sharedTier: false,
|
|
856
|
+
contextWindow: DEFAULT_CONTEXT_WINDOW,
|
|
836
857
|
};
|
|
837
858
|
const candidates = [];
|
|
838
859
|
for (const { host, configDir } of HOSTS) {
|
|
@@ -882,6 +903,9 @@ export function installedDefaults() {
|
|
|
882
903
|
try { found.kits = kitsOfDir(base); } catch { found.kits = []; }
|
|
883
904
|
}
|
|
884
905
|
if (!found.sharedTier) found.sharedTier = sharedTierOfDir(base);
|
|
906
|
+
// Two states too: the default and no line read the same, so the first install that says
|
|
907
|
+
// otherwise speaks.
|
|
908
|
+
if (found.contextWindow === DEFAULT_CONTEXT_WINDOW) found.contextWindow = contextWindowOfDir(base);
|
|
885
909
|
}
|
|
886
910
|
return found;
|
|
887
911
|
}
|
package/js/hosts/link.mjs
CHANGED
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
* source-level: that file asserts the spawn's shape without running it.
|
|
73
73
|
*/
|
|
74
74
|
import {
|
|
75
|
-
chmodSync, existsSync, lstatSync, mkdirSync, readlinkSync, rmSync,
|
|
75
|
+
appendFileSync, chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, rmSync,
|
|
76
76
|
} from 'node:fs';
|
|
77
77
|
import { isatty } from 'node:tty';
|
|
78
78
|
import { spawnSync } from 'node:child_process';
|
|
@@ -140,23 +140,44 @@ export function withoutPathBlock(text) {
|
|
|
140
140
|
* `~/.local/bin`, so a linked `geneseed` was not found (reported 2026-10). Only in a terminal:
|
|
141
141
|
* the web console's button and every test run without one, and get the printed line instead,
|
|
142
142
|
* so no gate can edit the developer's own startup file. Returns whether it wrote.
|
|
143
|
+
*
|
|
144
|
+
* `unattended` is `setup --profile`'s: running the profile IS the consent (install profiles,
|
|
145
|
+
* D26), so it writes the block without asking and without a terminal, and records the file it
|
|
146
|
+
* changed in `report.rcFile` for the run's summary. Only that caller passes it. `rc` is the
|
|
147
|
+
* test's seam; every caller takes `shellRcFile()`.
|
|
148
|
+
*
|
|
149
|
+
* THE BLOCK IS APPENDED, NEVER THE FILE REWRITTEN: a rewrite of someone's startup file risks the
|
|
150
|
+
* whole file for the sake of three lines. The block takes the file's own line ending. Only a
|
|
151
|
+
* missing file reads as empty; any other read error (permissions, a directory) refuses the write,
|
|
152
|
+
* because writing over a file that could not be read is how a startup file gets lost.
|
|
143
153
|
*/
|
|
144
|
-
function offerShellPath(dir) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
export function offerShellPath(dir, { unattended = false, report = null, rc = shellRcFile() } = {}) {
|
|
155
|
+
if (!rc || (!unattended && !isatty(0))) return false;
|
|
156
|
+
let text;
|
|
157
|
+
try {
|
|
158
|
+
text = readFileSync(rc, 'utf8');
|
|
159
|
+
} catch (e) {
|
|
160
|
+
if (e && e.code !== 'ENOENT') {
|
|
161
|
+
printErr(`geneseed: could not read ${rc} (${asOsError(e)}) — leaving it unchanged\n`);
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
text = '';
|
|
165
|
+
}
|
|
148
166
|
if (text.includes(RC_BEGIN)) {
|
|
149
167
|
printOut(`geneseed: ${rc} already adds it — open a NEW terminal, then run 'geneseed'.\n`);
|
|
150
168
|
return true;
|
|
151
169
|
}
|
|
152
|
-
if (!confirm(`geneseed: add '${dir}' to your PATH in ${rc}?`, true)) return false;
|
|
170
|
+
if (!unattended && !confirm(`geneseed: add '${dir}' to your PATH in ${rc}?`, true)) return false;
|
|
171
|
+
const eol = text.includes('\r\n') ? '\r\n' : '\n';
|
|
172
|
+
const sep = text === '' || text.endsWith('\n') ? '' : eol;
|
|
153
173
|
try {
|
|
154
|
-
|
|
174
|
+
appendFileSync(rc, sep + withPathBlock('', dir).replaceAll('\n', eol), 'utf8');
|
|
155
175
|
} catch (e) {
|
|
156
176
|
printErr(`geneseed: could not write ${rc} (${asOsError(e)})\n`);
|
|
157
177
|
return false;
|
|
158
178
|
}
|
|
159
179
|
printOut(`geneseed: added it to ${rc} — open a NEW terminal, then run 'geneseed'.\n`);
|
|
180
|
+
if (report) report.rcFile = rc;
|
|
160
181
|
return true;
|
|
161
182
|
}
|
|
162
183
|
|
|
@@ -264,8 +285,15 @@ function isOurLauncher(f) {
|
|
|
264
285
|
return existsSync(f) && (readMaybe(f) ?? '').includes(SHIM_MARKER);
|
|
265
286
|
}
|
|
266
287
|
|
|
267
|
-
/**
|
|
268
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Put `geneseed` on PATH so it runs from any directory. `opts` is `setup --profile`'s (see
|
|
290
|
+
* `offerShellPath`): `unattended` writes the shell rc block without asking; `report` receives
|
|
291
|
+
* `rcFile` (the startup file it changed), `foreign` (a launcher it left alone), and `onPath`:
|
|
292
|
+
* false, with `pathDir`, when the launcher was written but its dir is not on PATH (PowerShell
|
|
293
|
+
* blocked, a shell whose startup file this cannot edit, an rc write that failed) — exit 0 all the
|
|
294
|
+
* same, so only `report` can tell the caller.
|
|
295
|
+
*/
|
|
296
|
+
export function cmdLink(args, opts = {}) {
|
|
269
297
|
const here = ROOT;
|
|
270
298
|
if (IS_WIN) {
|
|
271
299
|
const bindir = winBinDir();
|
|
@@ -284,8 +312,10 @@ export function cmdLink(args) {
|
|
|
284
312
|
printOut(`geneseed: wrote shim ${shim}\n`);
|
|
285
313
|
if (winPathHas(process.env.PATH || '', bindir) || winUserPath('add', bindir)) {
|
|
286
314
|
printOut(`geneseed: '${bindir}' is on your user PATH — open a NEW terminal, then run \`geneseed\`.\n`);
|
|
315
|
+
if (opts.report) opts.report.onPath = true;
|
|
287
316
|
} else {
|
|
288
317
|
printOut(`geneseed: add '${bindir}' to your PATH manually, then run \`geneseed\` from anywhere.\n`);
|
|
318
|
+
if (opts.report) Object.assign(opts.report, { onPath: false, pathDir: bindir });
|
|
289
319
|
}
|
|
290
320
|
return 0;
|
|
291
321
|
}
|
|
@@ -318,6 +348,7 @@ export function cmdLink(args) {
|
|
|
318
348
|
// judgement `cmdUnlink` makes about the same file.
|
|
319
349
|
if (isSymlink(dest) || existsSync(dest)) {
|
|
320
350
|
if (!isOurLauncher(dest)) {
|
|
351
|
+
if (opts.report) opts.report.foreign = dest;
|
|
321
352
|
printErr(`geneseed: ${dest} exists and is not a launcher geneseed wrote — leaving it `
|
|
322
353
|
+ 'alone. Remove it yourself, or pick another dir: geneseed link <dir>\n');
|
|
323
354
|
return 1;
|
|
@@ -339,9 +370,13 @@ export function cmdLink(args) {
|
|
|
339
370
|
printOut(`geneseed: linked ${dest} -> ${entry}\n`);
|
|
340
371
|
if ((process.env.PATH || '').split(path.delimiter).includes(targetDir)) {
|
|
341
372
|
printOut(`geneseed: '${targetDir}' is on PATH — run 'geneseed' from anywhere.\n`);
|
|
342
|
-
|
|
373
|
+
if (opts.report) opts.report.onPath = true;
|
|
374
|
+
} else if (!offerShellPath(targetDir, { unattended: opts.unattended, report: opts.report })) {
|
|
343
375
|
printOut(`geneseed: NOTE '${targetDir}' is not on your PATH. Add it, e.g.:\n`);
|
|
344
376
|
printOut(` echo 'export PATH="${targetDir}:$PATH"' >> ~/.zshrc # or ~/.bashrc\n`);
|
|
377
|
+
if (opts.report) Object.assign(opts.report, { onPath: false, pathDir: targetDir });
|
|
378
|
+
} else if (opts.report) {
|
|
379
|
+
opts.report.onPath = true;
|
|
345
380
|
}
|
|
346
381
|
return 0;
|
|
347
382
|
}
|
package/js/hosts/native.mjs
CHANGED
|
@@ -32,7 +32,7 @@ import path from 'node:path';
|
|
|
32
32
|
import { writeText, copyFile, readText } from '../lib/fs.mjs';
|
|
33
33
|
import { jsonDumps, parseJson, formatValue, formatRepr, isTruthy, isDict } from '../lib/json.mjs';
|
|
34
34
|
import { relPosix } from '../lib/text.mjs';
|
|
35
|
-
import { aliasesOf } from '../build/source.mjs';
|
|
35
|
+
import { aliasesOf, skillDescriptions } from '../build/source.mjs';
|
|
36
36
|
import { resolvePath } from './hosts.mjs';
|
|
37
37
|
import { claimLeaf, ownedState } from './owned.mjs';
|
|
38
38
|
// `lstripNewlines` on spec bodies is a no-op on every input the generator produces today
|
|
@@ -147,7 +147,8 @@ function triggerOf(text) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
* Purpose + the trigger's FIRST sentence
|
|
150
|
+
* Purpose + the trigger's FIRST sentence: the emitted `description:` of a skill that has no
|
|
151
|
+
* catalogue line (see below), and the form every skill had until 2026-11-15. Every
|
|
151
152
|
* description is always-on context on a host that catalogues natively: at the earlier
|
|
152
153
|
* 900-char cap the catalogue weighed 22k chars (~5.6k tokens) across 51 skills, three times
|
|
153
154
|
* the figure the footprint page quoted. The first sentence says WHEN; the later sentences
|
|
@@ -157,8 +158,44 @@ function triggerOf(text) {
|
|
|
157
158
|
* failure, so the cure is a shorter first trigger sentence in the source, never a wider cap.
|
|
158
159
|
*/
|
|
159
160
|
const DESCRIPTION_CAP = 320;
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
/**
|
|
162
|
+
* A skill with a line in `src/skill-descriptions.json` (`skillDescriptions`) gets that line,
|
|
163
|
+
* and every shipped skill has one (`catalogueLineProblems` refuses a gap); the purpose +
|
|
164
|
+
* trigger composition above is the fallback for a fixture tree or a skill not catalogued yet.
|
|
165
|
+
*/
|
|
166
|
+
export function skillDescription(text, stem = null, src = undefined) {
|
|
167
|
+
const line = stem === null ? undefined : skillDescriptions(src)[stem];
|
|
168
|
+
return typeof line === 'string' ? line : withWhen(firstBlockquote(text), triggerOf(text));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* A vendored skill's own SKILL.md with its frontmatter `description:` swapped for the
|
|
173
|
+
* catalogue line, the upstream description kept as the first body line, as a blockquote. The
|
|
174
|
+
* upstream lines ran to 600 characters and were the longest in the listing. Text with no
|
|
175
|
+
* catalogue line, no frontmatter or no `description:` key passes unchanged, and so does a
|
|
176
|
+
* value this cannot read whole: a block scalar (`>`, `|`), a plain scalar continued on an
|
|
177
|
+
* indented next line, or a quoted value that does not close on its line.
|
|
178
|
+
*/
|
|
179
|
+
export function vendoredWithCatalogueLine(text, stem, src = undefined) {
|
|
180
|
+
const line = skillDescriptions(src)[stem];
|
|
181
|
+
const m = /^---\r?\n([\s\S]*?\r?\n)?---\r?\n/.exec(text);
|
|
182
|
+
if (typeof line !== 'string' || !m) return text;
|
|
183
|
+
const eol = text.includes('\r\n') ? '\r\n' : '\n';
|
|
184
|
+
const lines = m[0].split(/\r?\n/);
|
|
185
|
+
const at = lines.findIndex((ln) => /^description:/.test(ln));
|
|
186
|
+
const raw = at < 0 ? '' : lines[at].replace(/^description:\s*/, '');
|
|
187
|
+
if (!raw || /^[>|]/.test(raw) || /^[ \t]/.test(lines[at + 1] ?? '')) return text;
|
|
188
|
+
let upstream = raw;
|
|
189
|
+
if (raw.startsWith('"')) {
|
|
190
|
+
try { upstream = parseJson(raw); } catch { return text; }
|
|
191
|
+
} else if (raw.startsWith("'")) {
|
|
192
|
+
// YAML single quotes: `''` is an escaped quote, and the value must close on its line.
|
|
193
|
+
if (!/^'(?:[^']|'')*'$/.test(raw)) return text;
|
|
194
|
+
upstream = raw.slice(1, -1).replaceAll("''", "'");
|
|
195
|
+
}
|
|
196
|
+
lines[at] = `description: ${jsonDumps(line)}`;
|
|
197
|
+
const body = text.slice(m[0].length).replace(/^(\r?\n)+/, '');
|
|
198
|
+
return `${lines.join(eol)}${eol}> ${upstream}${eol}${eol}${body}`;
|
|
162
199
|
}
|
|
163
200
|
|
|
164
201
|
/**
|
|
@@ -752,7 +789,7 @@ export function writeNativeLayer(items, agentsDir, skillsDir, overrides = null,
|
|
|
752
789
|
// ALIASES are the one case every non-Claude dialect shares: no alias skill via
|
|
753
790
|
// frontmatter exists for them either, so an alias skill there would land in the
|
|
754
791
|
// model's catalogue as a duplicate; it gets a command instead (`writeAliasCommands`).
|
|
755
|
-
fm = [`name: ${stem}`, `description: ${jsonDumps(skillDescription(text))}`];
|
|
792
|
+
fm = [`name: ${stem}`, `description: ${jsonDumps(skillDescription(text, stem, src))}`];
|
|
756
793
|
userOnly = isUserInvokedOnly(text);
|
|
757
794
|
if (userOnly && !bobDialect) fm.push('disable-model-invocation: true');
|
|
758
795
|
body = stripSkillBodyLinks(pointSideFiles(body, stem, skillDirOf ? skillDirOf(stem)
|
package/js/hosts/opencode.mjs
CHANGED
|
@@ -388,7 +388,7 @@ export function writeAliasCommands(cfg, items, commandDir, claim = (_dest) => tr
|
|
|
388
388
|
for (const name of names) {
|
|
389
389
|
const dest = path.join(commandDir, `${name}.md`);
|
|
390
390
|
if (!claim(dest)) continue;
|
|
391
|
-
writeCommandFile(dest, name === stem ? skillDescription(text) : `Alias of ${stem}.`, body);
|
|
391
|
+
writeCommandFile(dest, name === stem ? skillDescription(text, stem, cfg.src) : `Alias of ${stem}.`, body);
|
|
392
392
|
written.push(dest);
|
|
393
393
|
}
|
|
394
394
|
}
|
package/js/hosts/settings.mjs
CHANGED
|
@@ -1443,6 +1443,78 @@ export function unwireClaudeEnv(p, recorded) {
|
|
|
1443
1443
|
}
|
|
1444
1444
|
}
|
|
1445
1445
|
|
|
1446
|
+
/**
|
|
1447
|
+
* The skill-listing keys of `--context-window` (`CONTEXT_WINDOWS`, js/build/source.mjs), merged
|
|
1448
|
+
* into top-level settings keys one by one. Returns the `{key: value}` pairs Geneseed owns after
|
|
1449
|
+
* the merge, which the manifest records (`managed.settings_listing`).
|
|
1450
|
+
*
|
|
1451
|
+
* UNLIKE `wireClaudeEnv`, A VALUE GENESEED OWNS CAN CHANGE: `200k` -> `1m` turns 80 into 120 and
|
|
1452
|
+
* takes the fraction away. So ownership is the record, checked against the file:
|
|
1453
|
+
* - a key absent from the file is written and recorded;
|
|
1454
|
+
* - a key on file with exactly the recorded value is Geneseed's: updated to `want`, or removed
|
|
1455
|
+
* when `want` no longer names it;
|
|
1456
|
+
* - any other key on file is the user's, even one equal to `want` with no record, and it stays
|
|
1457
|
+
* untouched and unrecorded, so uninstall never takes it.
|
|
1458
|
+
* A commented file is never rewritten: the wanted changes are printed for a hand merge and the
|
|
1459
|
+
* keys already owned stay recorded as they are on file.
|
|
1460
|
+
*/
|
|
1461
|
+
export function wireClaudeListing(p, wanted = {}, recorded = {}) {
|
|
1462
|
+
// Parsed, so every number is the `JsonNumber` the renderers require (`jsonDumpsCompact` below).
|
|
1463
|
+
const want = parseJson(JSON.stringify(wanted));
|
|
1464
|
+
const prior = isDict(recorded) ? recorded : {};
|
|
1465
|
+
const loaded = readSettingsForMerge(p, 'Its skill-listing keys were not wired.');
|
|
1466
|
+
// A file that cannot be read changes nothing, so what this install owns stays on record.
|
|
1467
|
+
if (!loaded) return { ...prior };
|
|
1468
|
+
const [config, hadComments] = loaded;
|
|
1469
|
+
// `deepEquals`, never `===`: a parsed number is a `JsonNumber` wrapper (js/lib/json.mjs).
|
|
1470
|
+
const owned = (k) => has(prior, k) && has(config, k) && deepEquals(config[k], prior[k]);
|
|
1471
|
+
const next = { ...config };
|
|
1472
|
+
const record = {};
|
|
1473
|
+
for (const k of new Set([...Object.keys(prior), ...Object.keys(want)])) {
|
|
1474
|
+
if (has(want, k) && (!has(config, k) || owned(k))) {
|
|
1475
|
+
if (!has(config, k) || !deepEquals(config[k], want[k])) next[k] = want[k];
|
|
1476
|
+
record[k] = want[k];
|
|
1477
|
+
} else if (!has(want, k) && owned(k)) {
|
|
1478
|
+
delete next[k];
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
const changed = Object.keys({ ...config, ...next })
|
|
1482
|
+
.some((k) => has(config, k) !== has(next, k) || !deepEquals(config[k], next[k]));
|
|
1483
|
+
if (!changed) return record;
|
|
1484
|
+
if (hadComments) {
|
|
1485
|
+
const add = Object.fromEntries(Object.entries(record).filter(([k, v]) => !deepEquals(config[k], v)));
|
|
1486
|
+
const drop = Object.keys(config).filter((k) => !has(next, k));
|
|
1487
|
+
process.stderr.write(`[geneseed] ${path.basename(p)} has comments — not rewriting it `
|
|
1488
|
+
+ '(your edits are kept). Merge its skill-listing keys by hand: set '
|
|
1489
|
+
+ `${jsonDumpsCompact(add)}${drop.length ? `, remove ${drop.join(', ')}` : ''}\n`);
|
|
1490
|
+
return Object.fromEntries(Object.keys(prior).filter(owned).map((k) => [k, config[k]]));
|
|
1491
|
+
}
|
|
1492
|
+
try {
|
|
1493
|
+
atomicWriteJson(p, next);
|
|
1494
|
+
} catch (e) {
|
|
1495
|
+
if (!isOsError(e)) throw e;
|
|
1496
|
+
process.stderr.write(`[geneseed] WARN: could not write ${p} (${e.message}) — its `
|
|
1497
|
+
+ `skill-listing keys were not wired. Set them by hand: ${jsonDumpsCompact(want)}\n`);
|
|
1498
|
+
return Object.fromEntries(Object.keys(prior).filter(owned).map((k) => [k, config[k]]));
|
|
1499
|
+
}
|
|
1500
|
+
return record;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
/** Remove each recorded skill-listing key while it still holds the recorded value. */
|
|
1504
|
+
export function unwireClaudeListing(p, recorded) {
|
|
1505
|
+
if (!isDict(recorded) || !Object.keys(recorded).length) return;
|
|
1506
|
+
const { state, data: loaded, hadComments } = loadJsonObject(p);
|
|
1507
|
+
if (state !== 'ok' || hadComments) return;
|
|
1508
|
+
const gone = Object.keys(recorded).filter((k) => has(loaded, k) && deepEquals(loaded[k], recorded[k]));
|
|
1509
|
+
if (!gone.length) return;
|
|
1510
|
+
for (const k of gone) delete loaded[k];
|
|
1511
|
+
try {
|
|
1512
|
+
atomicWriteJson(p, loaded);
|
|
1513
|
+
} catch (e) {
|
|
1514
|
+
if (!isOsError(e)) throw e;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1446
1518
|
/** `_build_settings._unwire_claude_excludes`. */
|
|
1447
1519
|
export function unwireClaudeExcludes(p, excludes) {
|
|
1448
1520
|
if (!excludes || !excludes.length) return;
|