geneseed 5.3.1 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/README.md +51 -18
- package/SHIPPED.md +7 -7
- package/adapters/bob/README.md +12 -1
- package/adapters/opencode/README.md +5 -3
- package/adapters/opencode/plugins/geneseed-context.js +77 -10
- package/adapters/opencode/plugins/geneseed-guard.js +106 -22
- package/adapters/opencode/plugins/geneseed-learn.js +641 -6
- package/bin/geneseed-cli.mjs +10 -0
- package/bin/geneseed-hook.mjs +5 -4
- package/docs/PRD.md +1 -1
- package/docs/README.md +1 -0
- package/docs/concepts/agents.md +14 -2
- package/docs/concepts/collaboration.md +2 -2
- package/docs/concepts/enforcement-table.md +5 -2
- package/docs/concepts/exclusions.md +16 -2
- package/docs/concepts/footprint.md +1 -1
- package/docs/concepts/foreman-mode.md +23 -4
- package/docs/concepts/hook-gates.md +4 -4
- package/docs/concepts/hooks.md +25 -7
- package/docs/concepts/host-matrix.md +4 -4
- package/docs/concepts/hosts.md +1 -1
- package/docs/concepts/kits.md +12 -2
- package/docs/concepts/loop-bricks.md +3 -3
- package/docs/concepts/loops.md +6 -4
- package/docs/concepts/ownership.md +1 -1
- package/docs/concepts/rules.md +2 -2
- 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 +73 -29
- package/docs/guides/auto-merge.md +100 -0
- package/docs/guides/choose-your-setup.md +1 -1
- package/docs/guides/headless.md +1 -1
- package/docs/guides/install-clone.md +19 -1
- package/docs/guides/install-scripted.md +8 -2
- package/docs/guides/install.md +20 -2
- package/docs/guides/loop-finish.md +3 -3
- package/docs/guides/loop-running.md +4 -4
- package/docs/guides/project-context.md +1 -1
- package/docs/guides/run-a-factory.md +2 -2
- package/docs/guides/setup-doctrines.md +2 -2
- package/docs/guides/setup-footprint.md +1 -1
- package/docs/guides/uninstall.md +3 -3
- package/docs/guides/upgrade.md +2 -2
- package/docs/guides/worktree.md +1 -1
- package/docs/reference/env-context.md +1 -1
- package/docs/reference/environment.md +4 -2
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/plugin-guard.md +1 -1
- package/docs/reference/plugin-learn.md +5 -1
- package/docs/reference/plugin-workflow.md +1 -1
- package/docs/reference/profiles.md +142 -0
- package/docs/reference/troubleshoot-doctor.md +1 -1
- package/docs/reference/troubleshoot-hooks.md +2 -2
- package/docs/reference/troubleshoot-install.md +3 -3
- package/docs/reference/troubleshoot-tools.md +1 -1
- package/docs/token-footprint.md +11 -6
- package/docs/understand/design-choices-engineering.md +1 -1
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/understand/machine-claude.md +2 -2
- package/docs/understand/on-your-machine.md +1 -1
- package/docs/web-ui.md +8 -6
- package/harness.config.json +1 -1
- package/js/README.md +11 -3
- package/js/build/args.mjs +16 -4
- package/js/build/catalog.mjs +11 -1
- package/js/build/driver.mjs +74 -16
- package/js/build/emit-claude.mjs +32 -5
- package/js/build/emit-opencode.mjs +16 -9
- package/js/build/export.mjs +1 -1
- package/js/build/generate.mjs +12 -157
- package/js/build/notes-migrate.mjs +99 -0
- package/js/build/profile.mjs +326 -0
- package/js/build/render.mjs +110 -8
- package/js/build/retired-skills.mjs +60 -13
- package/js/build/source.mjs +100 -3
- package/js/build/stubs.mjs +4 -1
- package/js/cli-table.json +212 -7
- package/js/hosts/agent-runs.mjs +205 -0
- package/js/hosts/done-checks.mjs +3 -1
- package/js/hosts/hooks-done.mjs +428 -63
- package/js/hosts/hooks-learn.mjs +89 -3
- package/js/hosts/hooks-prims.mjs +44 -4
- package/js/hosts/hooks.mjs +159 -9
- package/js/hosts/hosts.mjs +10 -0
- package/js/hosts/installs.mjs +44 -2
- package/js/hosts/link.mjs +45 -10
- package/js/hosts/native.mjs +61 -7
- package/js/hosts/opencode.mjs +1 -1
- package/js/hosts/settings.mjs +101 -3
- 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-constitution.mjs +32 -0
- package/js/inspect/checks-repo.mjs +27 -2
- package/js/inspect/cost.mjs +6 -5
- package/js/inspect/diff.mjs +46 -8
- package/js/inspect/doctor.mjs +4 -0
- package/js/inspect/inventory.mjs +1 -1
- 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 +413 -15
- package/js/maintain/uninstall.mjs +4 -1
- package/js/maintain/update.mjs +4 -2
- package/js/web/actions.mjs +44 -41
- package/js/web/api.mjs +13 -3
- 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/guillaume-claude-global.json +16 -0
- package/profiles/starter.json +14 -0
- package/registry.json +14 -0
- package/src/AGENT.md.tmpl +16 -18
- 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 +1 -1
- package/src/agents/docker-expert.md +1 -1
- package/src/agents/docs.md +1 -1
- package/src/agents/empiricist.md +1 -1
- package/src/agents/explorer.md +4 -2
- package/src/agents/framer.md +1 -1
- package/src/agents/historian.md +1 -1
- package/src/agents/kubernetes-specialist.md +1 -1
- package/src/agents/memory-curator.md +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 +1 -1
- package/src/agents/spring-reviewer.md +1 -1
- package/src/agents/spring-security.md +1 -1
- package/src/agents/steward.md +1 -1
- package/src/agents/tester.md +4 -2
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/bricks/pr-open.md +3 -2
- package/src/doctrines/ops.md +2 -2
- package/src/doctrines/process.md +40 -36
- package/src/factories/analysis-to-build.json +1 -1
- package/src/factories/bug-report-to-fix.json +1 -1
- package/src/factories/issue-to-pr.json +1 -1
- package/src/kits/terminal-tools/rules.md +10 -0
- package/src/kits/terminal-tools.json +13 -0
- package/src/licenses/herdr.txt +201 -0
- package/src/memory/README.md +12 -2
- package/src/modes/foreman.md +25 -9
- package/src/skill-descriptions.json +63 -0
- package/src/skills/_self-improvement.md +42 -24
- package/src/skills/_template.md +3 -1
- package/src/skills/brainstorm.md +35 -22
- package/src/skills/commit.md +17 -17
- package/src/skills/daydream/VENDOR.md +6 -0
- package/src/skills/debug/ci.md +1 -1
- package/src/skills/dependencies.md +3 -3
- package/src/skills/diagram-design/VENDOR.md +4 -0
- package/src/skills/document-project.md +3 -2
- package/src/skills/explain-changes/VENDOR.md +5 -1
- package/src/skills/factory.md +13 -4
- package/src/skills/geneseed.md +4 -2
- package/src/skills/git-history.md +5 -7
- package/src/skills/herdr.md +135 -0
- package/src/skills/loop.md +3 -2
- package/src/skills/opencode-cli.md +84 -0
- package/src/skills/parallel-agents.md +11 -0
- package/src/skills/pipeline.md +3 -3
- package/src/skills/plan.md +5 -4
- package/src/skills/react-view-transitions/VENDOR.md +7 -1
- package/src/skills/release.md +11 -9
- package/src/skills/review-response.md +4 -2
- package/src/skills/rule/approve.md +2 -1
- package/src/skills/rule.md +27 -1
- package/src/skills/ship.md +54 -7
- package/src/skills/skill-forge.md +5 -3
- package/src/skills/token-report/VENDOR.md +5 -1
- package/src/skills/worktree.md +2 -2
- package/src/upstreams.json +9 -2
- package/themes/README.md +3 -1
- package/themes/_TEMPLATE.json +2 -0
- package/themes/biker.json +2 -0
- package/themes/commentator.json +2 -0
- package/themes/cyberpunk.json +2 -0
- package/themes/gamer.json +2 -0
- package/themes/imperial.json +2 -0
- package/themes/joker.json +2 -0
- package/themes/marvin.json +2 -0
- package/themes/mean.json +2 -0
- package/themes/military.json +2 -0
- package/themes/neutral.json +2 -0
- package/themes/pirate.json +2 -0
- package/themes/sports.json +2 -0
- package/themes/verstappen.json +2 -0
- package/themes/wizard.json +2 -0
- package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
- package/web/dist/assets/Activity-LKsDzsnK.js +1 -0
- package/web/dist/assets/ActivityDetail-DhwTfPm6.js +1 -0
- package/web/dist/assets/{Bonsai-BBl4XXqs.js → Bonsai-CePMLrpr.js} +1 -1
- package/web/dist/assets/{CopyButton-Beven8yn.js → CopyButton-CuoaJ6k7.js} +1 -1
- package/web/dist/assets/Dashboard-D1VKuvLe.js +2 -0
- package/web/dist/assets/Docs-CUrHJKaU.js +5 -0
- package/web/dist/assets/Factories-Ci1XfmSy.js +1 -0
- package/web/dist/assets/{GreenhouseView-Bce212qd.js → GreenhouseView-CNfH2lPK.js} +1 -1
- package/web/dist/assets/Installs-ZHQZM1iS.js +3 -0
- package/web/dist/assets/{JournalView-CV4omyww.js → JournalView-CMsWahkS.js} +1 -1
- package/web/dist/assets/Kits-CkliyK0n.js +1 -0
- package/web/dist/assets/Laws-hh4O3HZ4.js +4 -0
- package/web/dist/assets/{LibRows-Dag1s0ZX.js → LibRows-Brv0Hmkr.js} +1 -1
- package/web/dist/assets/Library-BYmiLjJr.js +3 -0
- package/web/dist/assets/Loops-ytm-xJ68.js +2 -0
- package/web/dist/assets/{OperatorHudView-JmYY1pBR.js → OperatorHudView-KaqCx_HP.js} +1 -1
- package/web/dist/assets/Personal-CmcnRKYE.js +2 -0
- package/web/dist/assets/Settings-tUrpdOfq.js +1 -0
- package/web/dist/assets/{Tabs-8zsyEPSK.js → Tabs-CD7etcGD.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-CRWqKxfY.css → index-Ba_Kg3Af.css} +1 -1
- package/web/dist/assets/index-COKbhFNo.js +6 -0
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Activity-WQ3ykgxU.js +0 -1
- package/web/dist/assets/ActivityDetail-7rt04SkS.js +0 -1
- package/web/dist/assets/Dashboard-BgLArtgu.js +0 -2
- package/web/dist/assets/Docs-B5aHp86J.js +0 -5
- package/web/dist/assets/Factories-BjqzXAw8.js +0 -1
- package/web/dist/assets/Installs-B1OsrHXF.js +0 -3
- package/web/dist/assets/Kits-CW1e7xNa.js +0 -1
- package/web/dist/assets/Laws-1Ckf1lbs.js +0 -4
- package/web/dist/assets/Library-B3FuFLel.js +0 -3
- package/web/dist/assets/Loops-CwqgnLNw.js +0 -2
- package/web/dist/assets/Personal-DKLgLa7Z.js +0 -2
- package/web/dist/assets/Settings-BwErnh-R.js +0 -1
- package/web/dist/assets/api-DLDVY3K-.js +0 -1
- package/web/dist/assets/index-Ce6qF2nG.js +0 -6
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
|
|
@@ -367,17 +435,35 @@ export function cmdLearn(args) {
|
|
|
367
435
|
args = { ...args, memory: sharedStoreFor(install, args) };
|
|
368
436
|
}
|
|
369
437
|
|
|
370
|
-
// The done gate (#289) judges the turn BEFORE anything here spawns,
|
|
371
|
-
// means the turn goes on, so there is nothing to distil
|
|
438
|
+
// The done gate (#289) judges the turn BEFORE anything here spawns, on Stop and on SubagentStop
|
|
439
|
+
// (the sub-agent's own turn). A block means the turn goes on, so there is nothing to distil
|
|
440
|
+
// yet, and no agent lesson either: the next Stop will.
|
|
372
441
|
// `--no-done-gate` (the install switched Law III's gate off) skips the check, never the
|
|
373
442
|
// distillation below.
|
|
374
443
|
// One reader for this Stop: an allowed turn's distillation reuses the windows the gate read.
|
|
375
444
|
const read = tailReader();
|
|
376
445
|
// An advisory verdict already holds stdout: nothing below may print there after it.
|
|
377
|
-
const verdict = hookEvent === 'Stop' && !args.file && !args.noDoneGate
|
|
446
|
+
const verdict = (hookEvent === 'Stop' || hookEvent === 'SubagentStop') && !args.file && !args.noDoneGate
|
|
378
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
|
+
}
|
|
379
461
|
if (verdict === 'block') return 0;
|
|
380
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
|
+
|
|
381
467
|
// The change report, at the turn's real end (./store-watch.mjs). One JSON document on stdout, so an
|
|
382
468
|
// advisory already there keeps it, and Bob reads no stdout here at all: those go to stderr.
|
|
383
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
|
|
|
@@ -410,9 +411,11 @@ const GATE_ASKS = {
|
|
|
410
411
|
impact: 'the scan can run for hours', tail: 'search one named directory',
|
|
411
412
|
can: 'You can name the directory to search.' }),
|
|
412
413
|
// Routine and frequent, so one line: three more would train the user to stop reading all of them.
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
414
|
+
// `strict`: the install asks for every commit and push (`--strict-consent`), not only main's.
|
|
415
|
+
commit: (f) => ({ rule: 'Consent Before Push', quote: true, short: true,
|
|
416
|
+
line: f.strict ? 'This command commits or pushes with git, which needs your approval each time.'
|
|
417
|
+
: 'This command commits or pushes onto the main branch, forces a push, or takes a form the gate cannot read, so it needs your approval.',
|
|
418
|
+
why: f.strict ? 'every commit and push is your decision' : 'the main branch changes only through a pull request', can: GATE_RUN_IT }),
|
|
416
419
|
// The next four are the OpenCode guard's alone: no hook reads a key path, a stream, a wiki manifest
|
|
417
420
|
// or an unknown tool's arguments, and the guard only refuses them. `wiki` has no rule to name.
|
|
418
421
|
'secret-file': (f) => ({ rule: 'Sealed Secrets', line: `This edit writes to ${gateName(gatePath(f.name))}, a file that holds a secret or key.`,
|
|
@@ -544,8 +547,45 @@ export function activityOn(root) {
|
|
|
544
547
|
* The `activity` verb, wired to the events no other verb runs on (UserPromptSubmit; SessionEnd
|
|
545
548
|
* on Claude and OpenClaude; SubagentStart runs `context` since the agent loadout). It decides nothing and prints nothing: the entry's
|
|
546
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.
|
|
547
559
|
*/
|
|
548
|
-
|
|
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
|
+
}
|
|
549
589
|
|
|
550
590
|
// The two output funnels, with Python's newline translation reproduced, are `printOut`/`printErr`
|
|
551
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,
|
|
@@ -254,6 +254,148 @@ export function worktreeExempt(command, cwd, agentId) {
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
// A plain push of one named branch: `[-u|--set-upstream] <remote> <ref>`, nothing else. The
|
|
258
|
+
// remote's first character is alphanumeric so a flag (`-f`, `--all`, `--delete`) is never read
|
|
259
|
+
// as one, and `<ref>` is checked against the current branch by `ownBranchExempt`; a forced push
|
|
260
|
+
// (`-f`, `--force*`, a `+ref`) or a deletion (`:ref`) matches nothing and asks.
|
|
261
|
+
const SEG_PUSH_RE = new RegExp(`^git\\s+push(?:\\s+(?:-u|--set-upstream))?\\s+([A-Za-z0-9][A-Za-z0-9._-]*)\\s+(${ARG_RE})$`);
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Whether the repository's own config can send a push of `<branch>` (no `:<dst>`) somewhere
|
|
265
|
+
* else: a `push =` refspec on a remote, a `[branch "<b>"]` whose `merge` names another branch, or
|
|
266
|
+
* an `[include]`/`[includeIf]` this read does not follow. Each one asks. An explicit
|
|
267
|
+
* `HEAD:<branch>` refspec needs none of this: git ignores the config once a destination is given.
|
|
268
|
+
* The user's global and system config are not read; a remote push refspec there is the one
|
|
269
|
+
* redirect this check cannot see.
|
|
270
|
+
*/
|
|
271
|
+
function pushRedirected(common, branch) {
|
|
272
|
+
let text = '';
|
|
273
|
+
try { text = readFileSync(path.join(common, 'config'), 'utf8'); } catch (e) { if (e.code !== 'ENOENT') return true; }
|
|
274
|
+
if (/^\s*\[include/im.test(text) || /^\s*push\s*=/im.test(text)) return true;
|
|
275
|
+
let section = '';
|
|
276
|
+
for (const line of text.split(/\r?\n/)) {
|
|
277
|
+
const head = /^\s*\[\s*([^\]]*?)\s*\]/.exec(line);
|
|
278
|
+
if (head) { section = head[1]; continue; }
|
|
279
|
+
const merge = /^\s*merge\s*=\s*(\S+)/i.exec(line);
|
|
280
|
+
if (merge && section === `branch "${branch}"` && merge[1] !== `refs/heads/${branch}`) return true;
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Whether every remote names its default branch: at least one `[remote "<r>"]`, each with a
|
|
287
|
+
* readable `refs/remotes/<r>/HEAD` symref (`git clone` writes it; `git remote add` does not, and
|
|
288
|
+
* `git remote set-head <r> --auto` repairs it). Without it, the default branch may be any name
|
|
289
|
+
* (`trunk`), and the own-branch pass cannot tell it from the session's own branch, so it asks
|
|
290
|
+
* (review F1: "when unsure, treat it as main"). An `[include]` may add a remote: asks too.
|
|
291
|
+
*/
|
|
292
|
+
function defaultBranchKnown(common) {
|
|
293
|
+
let text = '';
|
|
294
|
+
try { text = readFileSync(path.join(common, 'config'), 'utf8'); } catch { return false; }
|
|
295
|
+
if (/^\s*\[include/im.test(text)) return false;
|
|
296
|
+
const remotes = [...text.matchAll(/^\s*\[\s*remote\s+"([^"]+)"\s*\]/gim)].map((m) => m[1]);
|
|
297
|
+
if (!remotes.length) return false;
|
|
298
|
+
return remotes.every((r) => {
|
|
299
|
+
try {
|
|
300
|
+
return /^ref:\s*refs\/remotes\//.test(readFileSync(path.join(common, 'refs', 'remotes', ...r.split('/'), 'HEAD'), 'utf8'));
|
|
301
|
+
} catch {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// One commit message, quoted, after `-m`/`-am`/`--message`, masked before the character checks so
|
|
308
|
+
// a Conventional Commits subject (`fix(hooks): x`) or an `@` does not ask (review F3). Single quotes
|
|
309
|
+
// are literal in bash and PowerShell alike. Inside double quotes both shells still expand `$` (and
|
|
310
|
+
// `$(`), a backtick, and bash a `\`: the class refuses those, so such a message keeps the ask.
|
|
311
|
+
const QUOTED_MSG_RE = /(\s(?:-[a-zA-Z]*m|--message)\s+)(?:'[^'\n]*'|"[^"$`\\\n]*")/g;
|
|
312
|
+
// A bash heredoc message: `git commit -F - <<'EOF'` … `EOF`, last in the command. Only a QUOTED
|
|
313
|
+
// delimiter, which leaves the body literal; and no body line may equal the delimiter, or the shell
|
|
314
|
+
// would end the heredoc there and run the rest as commands.
|
|
315
|
+
const HEREDOC_RE = /\s<<-?[ \t]*(['"])([A-Za-z_][A-Za-z0-9_]*)\1[ \t]*\n([\s\S]*)\n\t*\2[ \t]*\n?$/;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* The command with what cannot run anything masked out — quoted messages always, a quoted-
|
|
319
|
+
* delimiter heredoc feeding `git commit -F -` under bash only — or null when a heredoc is there
|
|
320
|
+
* but not that safe shape. The masked text is what the character checks and the segment
|
|
321
|
+
* whitelist then read.
|
|
322
|
+
*/
|
|
323
|
+
function maskMessages(command, shell) {
|
|
324
|
+
let text = command;
|
|
325
|
+
const doc = HEREDOC_RE.exec(text);
|
|
326
|
+
if (doc) {
|
|
327
|
+
const head = text.slice(0, doc.index);
|
|
328
|
+
if (shell !== 'bash' || head.includes('<<') || !/\bgit\s+commit\b[^\n]*\s-F\s+-$/.test(head)) return null;
|
|
329
|
+
if (doc[3].split('\n').some((l) => l.replace(/^\t+/, '').trimEnd() === doc[2])) return null;
|
|
330
|
+
text = head;
|
|
331
|
+
}
|
|
332
|
+
return text.replace(QUOTED_MSG_RE, "$1'M'");
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Consent Before Push's own-branch pass (user decision 2026-11-13): the main branch changes only
|
|
337
|
+
* through a pull request, so every other branch is the session's own, and its commits, local
|
|
338
|
+
* merges and plain pushes go through without a prompt. Every clause must hold, or the ask stands:
|
|
339
|
+
* - No `agentId`: a sub-agent never pushes, and its local commits are `worktreeExempt`'s to judge.
|
|
340
|
+
* - The command, with its messages masked (`maskMessages`): none of `UNSAFE_CHARS_RE` or
|
|
341
|
+
* `SUBSHELL_CHARS_RE`; every segment an add, a
|
|
342
|
+
* read-only look, a plain commit or merge (`SEG_LOCAL_RE`, or the loop's `-F` commit), or a
|
|
343
|
+
* plain push (`SEG_PUSH_RE`) of THIS branch, spelled `<branch>`, `HEAD:<branch>` or
|
|
344
|
+
* `HEAD:refs/heads/<branch>`; after at most one leading `cd <path>`. Bare `git push` asks:
|
|
345
|
+
* `push.default` and the global config decide where it goes, and this read cannot see them.
|
|
346
|
+
* - The repository: every remote names its default branch (`defaultBranchKnown`); no remote, or
|
|
347
|
+
* one with no HEAD symref, asks for everything.
|
|
348
|
+
* - The branch: known, not a symref, and, compared case-insensitively, none of `main`, `master`,
|
|
349
|
+
* a remote's default (`protectedBranches`), or the branch the main worktree holds when `cwd` is
|
|
350
|
+
* a linked worktree. In the main checkout itself the checked-out branch is judged by name, as
|
|
351
|
+
* the doctrine says ("in a linked worktree, the branch the main checkout holds"). A bare
|
|
352
|
+
* `<branch>` refspec also needs `pushRedirected` to be false.
|
|
353
|
+
*/
|
|
354
|
+
export function ownBranchExempt(command, cwd, agentId, shell = null) {
|
|
355
|
+
if (typeof agentId === 'string' && agentId) return false;
|
|
356
|
+
if (typeof command !== 'string') return false;
|
|
357
|
+
const masked = maskMessages(command, shell);
|
|
358
|
+
if (masked === null || UNSAFE_CHARS_RE.test(masked) || SUBSHELL_CHARS_RE.test(masked)) return false;
|
|
359
|
+
const segments = masked.split(/&&|\|\||[;|]/).map((x) => x.trim()).filter(Boolean);
|
|
360
|
+
try {
|
|
361
|
+
let dir = realpathSync(cwd);
|
|
362
|
+
const cd = segments.length ? SEG_CD_RE.exec(segments[0]) : null;
|
|
363
|
+
if (cd) {
|
|
364
|
+
if (cd[1] === '-' || cd[1].startsWith('~')) return false;
|
|
365
|
+
dir = realpathSync(path.resolve(dir, cd[1]));
|
|
366
|
+
segments.shift();
|
|
367
|
+
}
|
|
368
|
+
if (!segments.length) return false;
|
|
369
|
+
const root = gitRootOf(dir);
|
|
370
|
+
const branch = root && currentBranch(dir);
|
|
371
|
+
if (!branch || branch.includes('..')) return false;
|
|
372
|
+
const common = gitCommonDirOf(root);
|
|
373
|
+
if (!defaultBranchKnown(common)) return false;
|
|
374
|
+
// The branch may itself be a symref (`git symbolic-ref refs/heads/sym refs/heads/main`), and a
|
|
375
|
+
// commit then moves its target: as in `worktreeExempt`, a loose ref starting `ref:` asks.
|
|
376
|
+
let loose = '';
|
|
377
|
+
try {
|
|
378
|
+
loose = readFileSync(path.join(common, 'refs', 'heads', ...branch.split('/')), 'utf8');
|
|
379
|
+
} catch (e) {
|
|
380
|
+
if (e.code !== 'ENOENT') return false;
|
|
381
|
+
}
|
|
382
|
+
if (/^\s*ref:/.test(loose)) return false;
|
|
383
|
+
const main = mainWorktreeOf(dir);
|
|
384
|
+
const taken = [...protectedBranches(root), main && currentBranch(main)].filter(Boolean);
|
|
385
|
+
if (taken.some((b) => b.toLowerCase() === branch.toLowerCase())) return false;
|
|
386
|
+
return segments.every((seg) => {
|
|
387
|
+
if (SEG_ADD_RE.test(seg) || SEG_READONLY_RE.test(seg) || SEG_LOCAL_RE.test(seg) || SEG_COMMIT_RE.test(seg)) return true;
|
|
388
|
+
const push = SEG_PUSH_RE.exec(seg);
|
|
389
|
+
if (!push) return false;
|
|
390
|
+
const ref = push[2];
|
|
391
|
+
if (ref === `HEAD:${branch}` || ref === `HEAD:refs/heads/${branch}`) return true;
|
|
392
|
+
return ref === branch && !pushRedirected(common, branch);
|
|
393
|
+
});
|
|
394
|
+
} catch {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
257
399
|
// `askDecision` lives in `./hooks-prims.mjs`, so the entry can ask when THIS module fails to load.
|
|
258
400
|
export { askDecision };
|
|
259
401
|
|
|
@@ -908,7 +1050,8 @@ export function gitDecide(args, payload) {
|
|
|
908
1050
|
return ask(args, 'git-gate', 'law-4', 'unverified', {});
|
|
909
1051
|
}
|
|
910
1052
|
const tool = payload && payload.tool_name;
|
|
911
|
-
const
|
|
1053
|
+
const shell = tool === 'Bash' ? 'bash' : tool === 'PowerShell' ? 'powershell' : null;
|
|
1054
|
+
const command = shellReading(ti.command, shell);
|
|
912
1055
|
// The agent's own words, for the asks where they are no conflict of interest (`gateText`'s `quote`).
|
|
913
1056
|
const says = typeof ti.description === 'string' ? ti.description : '';
|
|
914
1057
|
// Law IV's catastrophic class (a root, a drive, the home dir, a disk): no state makes it safe,
|
|
@@ -946,12 +1089,16 @@ export function gitDecide(args, payload) {
|
|
|
946
1089
|
// no rule behind it — but Law IV above is universal and has already run. Checked before
|
|
947
1090
|
// `loopExempt` so a non-git command, or one with consent off, never pays for the whitelist.
|
|
948
1091
|
if (args.noConsent || !GIT_GATE_RE.test(command) || consentBenign(command)) return 0;
|
|
949
|
-
|
|
950
|
-
//
|
|
951
|
-
|
|
1092
|
+
const cwd = (payload && payload.cwd) || process.cwd();
|
|
1093
|
+
// Consent Before Push: off the main branch, commits, local merges and plain pushes are the
|
|
1094
|
+
// session's own. `--strict-consent` turns this pass off, and every commit and push asks again.
|
|
1095
|
+
if (!args.strictConsent && ownBranchExempt(command, cwd, payload && payload.agent_id, shell)) return 0;
|
|
1096
|
+
// Strict consent keeps the narrower passes: a loop launched on its own `loop/*` branch is a
|
|
1097
|
+
// named batch for a fixed set of commit/push forms on that branch only.
|
|
1098
|
+
if (loopExempt(command, cwd)) return 0;
|
|
952
1099
|
// A worker's own worktree branch is a named batch for local commits and merges, never a push.
|
|
953
|
-
if (worktreeExempt(command,
|
|
954
|
-
return ask(args, 'git-gate', 'process-5', 'commit', { says });
|
|
1100
|
+
if (worktreeExempt(command, cwd, payload && payload.agent_id)) return 0;
|
|
1101
|
+
return ask(args, 'git-gate', 'process-5', 'commit', { says, strict: args.strictConsent === true });
|
|
955
1102
|
}
|
|
956
1103
|
export const cmdGitGate = guardGate(gitGate, 'git-gate');
|
|
957
1104
|
|
|
@@ -1464,8 +1611,11 @@ function toolGate(args) {
|
|
|
1464
1611
|
if (sovereignBypass(args.root)) return 0;
|
|
1465
1612
|
const payload = normaliseBobPayload(readPayload());
|
|
1466
1613
|
// Count a skill or subagent call before judging it: Bob runs this verb on every tool and
|
|
1467
|
-
// Claude/OpenClaude route their `Skill|Agent|Task` matcher here (js/hosts/usage.mjs).
|
|
1468
|
-
|
|
1614
|
+
// Claude/OpenClaude route their `Skill|Agent|Task` matcher here (js/hosts/usage.mjs). Only the
|
|
1615
|
+
// COUNT stands down beside a live project install, whose own tool-gate counts the call; the
|
|
1616
|
+
// gates below still run once per install, as before.
|
|
1617
|
+
recordUse(args.root, payload, undefined, () => usageStandingDown(args.root,
|
|
1618
|
+
hookProjectDir(payload && payload.cwd), args.host, 'tool-gate'));
|
|
1469
1619
|
const ti = (payload && payload.tool_input) || {};
|
|
1470
1620
|
return typeof ti.command === 'string' ? gitDecide(args, payload) : ruleDecide(args, payload);
|
|
1471
1621
|
}
|
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,
|
|
@@ -45,7 +46,8 @@ import { registryRoots } from '../inspect/registry.mjs';
|
|
|
45
46
|
import { printErr, readText, isFile, isDir } from '../lib/fs.mjs';
|
|
46
47
|
import { formatRepr, isDict } from '../lib/json.mjs';
|
|
47
48
|
import { comparePaths } from '../lib/paths.mjs';
|
|
48
|
-
import { bundleLeftovers, ownedWithin } from './owned.mjs';
|
|
49
|
+
import { bundleLeftovers, ownedWithin, recordedGates } from './owned.mjs';
|
|
50
|
+
import { prunableGates } from './settings.mjs';
|
|
49
51
|
import { claudeHookShell, hookShimPath } from './shim.mjs';
|
|
50
52
|
|
|
51
53
|
export { carriersFor };
|
|
@@ -491,6 +493,25 @@ export function sharedTierOfDir(d, host = null) {
|
|
|
491
493
|
}, false, host);
|
|
492
494
|
}
|
|
493
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
|
+
|
|
494
515
|
/**
|
|
495
516
|
* Whether a DEPLOYED install keeps one law's hook gate armed — `true` (armed) or `false` (its
|
|
496
517
|
* `<marker>: off` line, written by a build with that gate's `--no-*-gate` flag; `GATE_SWITCHES`).
|
|
@@ -621,6 +642,23 @@ export function leftoversOf(root, host = 'opencode', scope = 'global') {
|
|
|
621
642
|
return { kept: kept.sort(), stale };
|
|
622
643
|
}
|
|
623
644
|
|
|
645
|
+
/**
|
|
646
|
+
* The `permission.bash` gates a `--prune-gates` rebuild of this OpenCode install would remove:
|
|
647
|
+
* owned keys whose rule this install has off, still at Geneseed's verdict, and absent from its
|
|
648
|
+
* `bash_gates` record (an `opencode.json` written before 5.2.0). The console shows them beside
|
|
649
|
+
* the leftovers and offers that rebuild. Read with the install's OWN choices — packs, excluded
|
|
650
|
+
* rules, the deletion gate — so it names what the console's prune would take, not a guess.
|
|
651
|
+
* Every other host has no such block: `{ keys: [] }`.
|
|
652
|
+
*/
|
|
653
|
+
export function strandedGatesOf(root, host = 'opencode', scope = 'global') {
|
|
654
|
+
if (host !== 'opencode') return { keys: [], commented: false };
|
|
655
|
+
const manifest = scope === 'project' ? path.join(root, '.opencode', GLOBAL_MANIFEST)
|
|
656
|
+
: path.join(root, GLOBAL_MANIFEST);
|
|
657
|
+
return prunableGates(path.join(root, 'opencode.json'), doctrinesForBuild(root, host),
|
|
658
|
+
excludedRulesOfDir(root, host), gatesOfDir(root, host).deletionGate,
|
|
659
|
+
recordedGates(readJsonMaybe(manifest)));
|
|
660
|
+
}
|
|
661
|
+
|
|
624
662
|
/** 'active' | 'disabled' | 'absent'. */
|
|
625
663
|
export function installState(root, host = 'opencode', scope = 'global') {
|
|
626
664
|
if (CLAUDE_STYLE.includes(host)) return claudeState(root, scope, host);
|
|
@@ -815,6 +853,7 @@ export function installedDefaults() {
|
|
|
815
853
|
const found = {
|
|
816
854
|
theme: null, posture: null, mode: null, emit: null, footprint: null, doctrines: null,
|
|
817
855
|
excludeRules: null, excludeSkills: null, kits: null, sharedTier: false,
|
|
856
|
+
contextWindow: DEFAULT_CONTEXT_WINDOW,
|
|
818
857
|
};
|
|
819
858
|
const candidates = [];
|
|
820
859
|
for (const { host, configDir } of HOSTS) {
|
|
@@ -864,6 +903,9 @@ export function installedDefaults() {
|
|
|
864
903
|
try { found.kits = kitsOfDir(base); } catch { found.kits = []; }
|
|
865
904
|
}
|
|
866
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);
|
|
867
909
|
}
|
|
868
910
|
return found;
|
|
869
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
|
}
|