geneseed 4.32.0 → 5.0.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 +85 -0
- package/DESIGN.md +2 -2
- package/README.md +6 -5
- package/SHIPPED.md +4 -3
- package/adapters/bob/README.md +6 -5
- package/adapters/claude-code/README.md +4 -3
- package/adapters/claude-code/skills/geneseed/SKILL.md +1 -1
- package/adapters/openclaude/README.md +4 -3
- package/adapters/opencode/GLOBAL-HARNESS-SPEC.md +3 -1
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +2 -1
- package/adapters/opencode/README.md +18 -18
- package/adapters/opencode/plugins/geneseed-activity.js +57 -1
- package/adapters/opencode/plugins/geneseed-context.js +85 -18
- package/adapters/opencode/plugins/geneseed-guard.js +437 -76
- package/adapters/opencode/plugins/geneseed-learn.js +97 -23
- package/bin/geneseed-cli.mjs +17 -25
- package/bin/geneseed-hook.mjs +23 -8
- package/docs/DESIGN.md +175 -0
- package/docs/PRD.md +111 -0
- package/docs/README.md +3 -2
- package/docs/architecture.md +145 -0
- package/docs/concepts/agents.md +1 -1
- package/docs/concepts/collaboration.md +1 -1
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/exclusions.md +5 -5
- package/docs/concepts/footprint.md +1 -1
- package/docs/concepts/foreman-mode.md +2 -2
- package/docs/concepts/hooks.md +22 -8
- package/docs/concepts/host-matrix.md +2 -2
- package/docs/concepts/hosts.md +1 -1
- package/docs/concepts/kits.md +3 -1
- package/docs/concepts/ownership.md +1 -1
- package/docs/concepts/rules.md +15 -2
- package/docs/concepts/shared-tier.md +73 -0
- package/docs/concepts/skills.md +2 -2
- package/docs/concepts/themes.md +1 -1
- package/docs/extending.md +13 -12
- package/docs/guides/install-claude-code.md +1 -1
- package/docs/guides/install-opencode.md +1 -1
- package/docs/guides/migrate.md +4 -2
- package/docs/guides/project-context.md +2 -2
- package/docs/guides/setup-footprint.md +1 -1
- package/docs/guides/uninstall.md +2 -1
- package/docs/guides/upgrade-to-5.md +116 -0
- package/docs/guides/upgrade.md +21 -9
- package/docs/guides/wiki.md +3 -3
- package/docs/reference/env-context.md +5 -3
- package/docs/reference/environment.md +1 -1
- package/docs/reference/glossary.md +2 -0
- package/docs/reference/opencode-plugins.md +3 -3
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/plugin-context.md +1 -0
- package/docs/reference/plugin-guard.md +14 -6
- package/docs/reference/plugin-learn.md +13 -6
- package/docs/reference/troubleshoot-hooks.md +3 -3
- package/docs/reference/troubleshoot-update.md +14 -0
- package/docs/token-footprint.md +4 -3
- package/docs/understand/a-day.md +2 -2
- package/docs/understand/design-choices-install.md +2 -1
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/understand/machine-bob.md +2 -0
- package/docs/understand/machine-claude.md +7 -5
- package/docs/understand/machine-opencode.md +7 -5
- package/docs/understand/on-your-machine.md +4 -0
- package/docs/understand/take-it-out.md +1 -1
- package/docs/web-ui.md +126 -68
- package/harness.config.json +1 -1
- package/js/README.md +10 -6
- package/js/build/args.mjs +10 -8
- package/js/build/bundle.mjs +11 -13
- package/js/build/driver.mjs +66 -65
- package/js/build/emit-claude.mjs +22 -16
- package/js/build/emit-common.mjs +4 -5
- package/js/build/emit-opencode.mjs +22 -22
- package/js/build/fold.mjs +515 -0
- package/js/build/generate.mjs +41 -52
- package/js/build/render.mjs +115 -29
- package/js/build/source.mjs +4 -1
- package/js/build/stubs.mjs +70 -9
- package/js/build/version.mjs +10 -10
- package/js/cli-table.json +23 -83
- package/js/hosts/activity.mjs +2 -2
- package/js/hosts/geneseed-dir.mjs +1 -1
- package/js/hosts/hooks-context.mjs +389 -99
- package/js/hosts/hooks-learn.mjs +38 -7
- package/js/hosts/hooks-prims.mjs +4 -2
- package/js/hosts/hooks.mjs +114 -39
- package/js/hosts/hosts.mjs +150 -51
- package/js/hosts/installs.mjs +55 -167
- package/js/hosts/link.mjs +3 -5
- package/js/hosts/mcp.mjs +1 -1
- package/js/hosts/memory-files.mjs +219 -17
- package/js/hosts/ownership-gate.mjs +1 -1
- package/js/hosts/settings.mjs +18 -13
- package/js/hosts/shim.mjs +4 -33
- package/js/hosts/store-watch.mjs +189 -0
- package/js/inspect/checks-authoring.mjs +3 -3
- package/js/inspect/checks-build.mjs +45 -18
- package/js/inspect/checks-counts.mjs +4 -4
- package/js/inspect/checks-repo.mjs +13 -14
- package/js/inspect/cost.mjs +24 -2
- package/js/inspect/diff.mjs +123 -123
- package/js/inspect/doctor.mjs +22 -27
- package/js/inspect/excludes.mjs +181 -62
- package/js/inspect/inventory.mjs +22 -27
- package/js/inspect/registry.mjs +106 -30
- package/js/inspect/scan.mjs +5 -5
- package/js/inspect/status.mjs +141 -119
- package/js/inspect/validate.mjs +22 -24
- package/js/lib/fs.mjs +47 -50
- package/js/lib/json.mjs +10 -17
- package/js/lib/machine-dir.mjs +73 -0
- package/js/lib/paths.mjs +22 -33
- package/js/lib/proc.mjs +1 -1
- package/js/lib/prompt.mjs +19 -27
- package/js/lib/text.mjs +8 -12
- package/js/lib/udiff.mjs +11 -15
- package/js/loop/catalog.mjs +2 -3
- package/js/maintain/memory.mjs +17 -17
- package/js/maintain/migrate.mjs +79 -89
- package/js/maintain/setup.mjs +43 -32
- package/js/maintain/uninstall.mjs +43 -61
- package/js/maintain/update.mjs +200 -93
- package/js/ui/anim.mjs +21 -35
- package/js/ui/cli.mjs +36 -58
- package/js/ui/menu.mjs +22 -45
- package/js/ui/tui.mjs +27 -67
- package/js/web/actions.mjs +34 -34
- package/js/web/api.mjs +130 -74
- package/js/web/catalog.mjs +175 -46
- package/js/web/docs.mjs +33 -12
- package/js/web/doctor-worker.mjs +14 -0
- package/js/web/handler.mjs +14 -5
- package/js/web/routes.mjs +17 -19
- package/js/web/state.mjs +78 -19
- package/js/web/update-check.mjs +25 -10
- package/js/web/user-files.mjs +50 -105
- package/package.json +7 -4
- package/registry.json +48 -55
- package/src/AGENT.md.tmpl +13 -14
- package/src/agents/_self-improvement.md +1 -1
- package/src/agents/_template.md +1 -1
- package/src/agents/advocate.md +1 -1
- package/src/agents/architect.md +1 -1
- package/src/agents/developer.md +1 -1
- 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 +1 -1
- 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 +2 -2
- 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 +1 -1
- 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 +1 -1
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/memory/README.md +1 -1
- package/src/skills/_self-improvement.md +2 -2
- package/src/skills/daydream/SKILL.md +2 -2
- package/src/skills/daydream/instructions.md +1 -1
- package/src/skills/geneseed.md +1 -1
- package/src/skills/learn-mode.md +1 -2
- package/src/skills/profile.md +2 -2
- package/src/skills/rule/approve.md +69 -0
- package/src/skills/rule/consolidate.md +3 -3
- package/src/skills/rule.md +13 -5
- package/src/skills/skill-forge.md +1 -1
- package/src/skills/teach.md +29 -12
- package/src/skills/wiki.md +1 -1
- package/themes/_TEMPLATE.json +1 -2
- package/themes/biker.json +1 -2
- package/themes/commentator.json +1 -2
- package/themes/cyberpunk.json +1 -2
- package/themes/gamer.json +1 -2
- package/themes/imperial.json +1 -2
- package/themes/joker.json +1 -2
- package/themes/marvin.json +1 -2
- package/themes/mean.json +1 -2
- package/themes/military.json +1 -2
- package/themes/neutral.json +1 -2
- package/themes/pirate.json +1 -2
- package/themes/sports.json +1 -2
- package/themes/verstappen.json +1 -2
- package/themes/wizard.json +1 -2
- package/web/dist/assets/Activity-D8G4eClY.js +1 -0
- package/web/dist/assets/ActivityDetail-BtOBYk3M.js +1 -0
- package/web/dist/assets/AgentGlyph-k6o3gCM1.js +1 -0
- package/web/dist/assets/Bonsai-B_y20b3i.js +1 -0
- package/web/dist/assets/{CopyButton-C5Li6awl.js → CopyButton-CHQte7Ap.js} +1 -1
- package/web/dist/assets/Dashboard-B8uXeJZ_.js +2 -0
- package/web/dist/assets/Docs-Dgv_MWfT.js +5 -0
- package/web/dist/assets/GreenhouseView-CSzTMSl_.js +1 -0
- package/web/dist/assets/Installs-BDk9lqBI.js +3 -0
- package/web/dist/assets/JournalView-CvRk1-m5.js +1 -0
- package/web/dist/assets/Kits-CoITzxWM.js +1 -0
- package/web/dist/assets/Laws-Ctf5r9rE.js +3 -0
- package/web/dist/assets/Library-DNwHYVXt.js +3 -0
- package/web/dist/assets/{Loops-CzitjxGV.js → Loops-S85PMQ8m.js} +2 -2
- package/web/dist/assets/{Markdown-C4S4tTA7.js → Markdown-0ORz7tAc.js} +21 -21
- package/web/dist/assets/OperatorHudView-DuGz_sTk.js +1 -0
- package/web/dist/assets/Personal-afJNwvRS.js +2 -0
- package/web/dist/assets/{RailCats-D5weYPCS.js → RailCats-AW92uhsX.js} +1 -1
- package/web/dist/assets/Settings-CGDFz-6j.js +1 -0
- package/web/dist/assets/Tabs-1qLrnqmn.js +1 -0
- package/web/dist/assets/api-C46vAuqp.js +1 -0
- package/web/dist/assets/controls-D4wmg_pl.js +1 -0
- package/web/dist/assets/index-COTd4TRZ.js +3 -0
- package/web/dist/assets/index-CtorA7uK.css +1 -0
- package/web/dist/assets/motion-RlUl1osO.js +1 -0
- package/web/dist/assets/{sections-ChwaobfW.js → sections-CtFz7HFH.js} +1 -1
- package/web/dist/index.html +5 -5
- package/src/skills/quiz.md +0 -44
- package/web/dist/assets/Activity-Bjy64wHC.js +0 -1
- package/web/dist/assets/ActivityDetail-B0AaipP8.js +0 -1
- package/web/dist/assets/Bonsai-CJniRqaH.js +0 -1
- package/web/dist/assets/Dashboard-B-6DTmae.js +0 -2
- package/web/dist/assets/Docs-LRc30XL9.js +0 -5
- package/web/dist/assets/GreenhouseView-CcoYlaWo.js +0 -1
- package/web/dist/assets/Installs-dp1epTcE.js +0 -3
- package/web/dist/assets/JournalView-nFP4poCf.js +0 -1
- package/web/dist/assets/KitApply-DwyZUj57.js +0 -1
- package/web/dist/assets/Kits-C0IEdZXe.js +0 -1
- package/web/dist/assets/Laws-CkykmQWu.js +0 -3
- package/web/dist/assets/Library-Guh9HBZU.js +0 -2
- package/web/dist/assets/OperatorHudView-DLGNulIY.js +0 -1
- package/web/dist/assets/Personal-BMtberL8.js +0 -2
- package/web/dist/assets/Tabs-uYJqfuQt.js +0 -1
- package/web/dist/assets/api-BxjLd7Qd.js +0 -1
- package/web/dist/assets/index-DA7BiaE5.js +0 -3
- package/web/dist/assets/index-dbbDGFDq.css +0 -1
- package/web/dist/assets/motion-Bccx3zE8.js +0 -1
package/js/hosts/hooks-learn.mjs
CHANGED
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { spawnSync } from 'node:child_process';
|
|
9
|
-
import { readText, printOut as out, printErr as err } from '../lib/fs.mjs';
|
|
9
|
+
import { readText, isDir, printOut as out, printErr as err } from '../lib/fs.mjs';
|
|
10
10
|
import { toPlatformPath } from '../lib/paths.mjs';
|
|
11
11
|
import { NO_WINDOW } from '../lib/proc.mjs';
|
|
12
12
|
import {
|
|
13
|
-
globalHookStandingDown, hookProjectDir, resolveMemoryDir, sovereignBypass,
|
|
13
|
+
globalHookStandingDown, hookProjectDir, isGlobalInstall, resolveMemoryDir, sovereignBypass,
|
|
14
14
|
} from './hosts.mjs';
|
|
15
|
+
import { sharedPaths } from '../lib/machine-dir.mjs';
|
|
15
16
|
import { readStdin, splitLines, splitWords, tailReader } from './hooks-prims.mjs';
|
|
16
17
|
import { doneGate } from './hooks-done.mjs';
|
|
18
|
+
import { recordOwnWrites, storeReport } from './store-watch.mjs';
|
|
17
19
|
import {
|
|
18
20
|
existingSlugs, readFacts, writeMemories, consolidateMemory, appendAgentLesson,
|
|
19
21
|
} from './memory-files.mjs';
|
|
@@ -217,8 +219,7 @@ export function buildLearnPrompt(notes, facts) {
|
|
|
217
219
|
*/
|
|
218
220
|
function runLlm(llm, prompt) {
|
|
219
221
|
const argv = splitWords(llm);
|
|
220
|
-
// `
|
|
221
|
-
// which folds in `CREATE_NO_WINDOW`; a model CLI invoked from the windowless daemon
|
|
222
|
+
// `NO_WINDOW` folds in `CREATE_NO_WINDOW`; a model CLI invoked from the windowless daemon
|
|
222
223
|
// otherwise pops a console for as long as it takes to answer.
|
|
223
224
|
//
|
|
224
225
|
// `GENESEED_LEARN_CHILD=1` (Claude B2): `$GENESEED_LLM="claude -p"` with hooks not disabled
|
|
@@ -276,13 +277,24 @@ function learnAgentLesson(meta, notes, args) {
|
|
|
276
277
|
const lesson = splitLines(text)[0].replace(/^[-*]+/, '').trim();
|
|
277
278
|
const n = Array.from(lesson).length; // code points, as `len()` counts them
|
|
278
279
|
if (n >= 10 && n <= 300) {
|
|
279
|
-
|
|
280
|
+
const written = recordOwnWrites(path.dirname(memDir), () => appendAgentLesson(memDir, agent, lesson));
|
|
281
|
+
err(written ? `[learn] agent lesson -> ${written}\n`
|
|
282
|
+
: `[learn] ${agent}'s lesson file is not UTF-8 - left as it is, lesson dropped\n`);
|
|
280
283
|
}
|
|
281
284
|
}
|
|
282
285
|
if (proc.returncode !== 0 && proc.stderr) err(proc.stderr);
|
|
283
286
|
return proc.returncode;
|
|
284
287
|
}
|
|
285
288
|
|
|
289
|
+
/** `--memory` of a global install's hook, swapped for the shared store when that exists. */
|
|
290
|
+
function sharedStoreFor(install, args) {
|
|
291
|
+
if (!install) return args.memory;
|
|
292
|
+
try {
|
|
293
|
+
const shared = sharedPaths().memory;
|
|
294
|
+
return isDir(shared) && isGlobalInstall(args.host ?? null, install) ? shared : args.memory;
|
|
295
|
+
} catch { return args.memory; }
|
|
296
|
+
}
|
|
297
|
+
|
|
286
298
|
export function cmdLearn(args) {
|
|
287
299
|
// B2: stand straight down inside a model-CLI child `runLlm` just spawned (see its comment).
|
|
288
300
|
// Checked before anything else — a child never gets as far as reading its own stdin, let
|
|
@@ -295,7 +307,7 @@ export function cmdLearn(args) {
|
|
|
295
307
|
err('[learn] no memory store found \u2014 nothing to consolidate.\n');
|
|
296
308
|
return 0;
|
|
297
309
|
}
|
|
298
|
-
const report = consolidateMemory(memDir);
|
|
310
|
+
const report = recordOwnWrites(path.dirname(memDir), () => consolidateMemory(memDir));
|
|
299
311
|
err(`[learn] consolidated ${memDir}: +${report.added.length} indexed, `
|
|
300
312
|
+ `-${report.pruned.length} pruned, `
|
|
301
313
|
+ `${report.duplicates.length} duplicate description(s)\n`);
|
|
@@ -321,6 +333,14 @@ export function cmdLearn(args) {
|
|
|
321
333
|
const hookEvent = typeof meta.hook_event_name === 'string' ? meta.hook_event_name
|
|
322
334
|
: (typeof meta.event === 'string' ? meta.event : null);
|
|
323
335
|
|
|
336
|
+
// A global install's hook passes its own host store; the shared store is where its facts live
|
|
337
|
+
// once it exists, or they land in the seeded host store and wait for the next fold. Only a hook
|
|
338
|
+
// call is redirected: it names its event or carries a transcript, and a person who typed
|
|
339
|
+
// `--memory` meant that store. Empty stdin is neither, and has no notes to write anywhere.
|
|
340
|
+
if (hookEvent || typeof meta.transcript_path === 'string') {
|
|
341
|
+
args = { ...args, memory: sharedStoreFor(install, args) };
|
|
342
|
+
}
|
|
343
|
+
|
|
324
344
|
// The done gate (#289) judges the turn BEFORE anything here spawns, and only on Stop. A block
|
|
325
345
|
// means the turn goes on, so there is nothing to distil yet: the next Stop will.
|
|
326
346
|
// `--no-done-gate` (the install switched Law III's gate off) skips the check, never the
|
|
@@ -332,6 +352,17 @@ export function cmdLearn(args) {
|
|
|
332
352
|
? doneGate(meta, args, install, read) : null;
|
|
333
353
|
if (verdict === 'block') return 0;
|
|
334
354
|
|
|
355
|
+
// The change report, at the turn's real end (./store-watch.mjs). One JSON document on stdout, so an
|
|
356
|
+
// advisory already there keeps it, and Bob reads no stdout here at all: those go to stderr.
|
|
357
|
+
if (hookEvent === 'Stop' && !args.file && install) {
|
|
358
|
+
const said = storeReport(install, meta.session_id, {
|
|
359
|
+
transcript: typeof meta.transcript_path === 'string' ? meta.transcript_path : null,
|
|
360
|
+
cwd: meta.cwd, host: args.host || 'claude',
|
|
361
|
+
});
|
|
362
|
+
if (said && (verdict === 'advisory' || args.host === 'bob')) err(`[geneseed] ${said}\n`);
|
|
363
|
+
else if (said) out(`${JSON.stringify({ systemMessage: said })}\n`);
|
|
364
|
+
}
|
|
365
|
+
|
|
335
366
|
// I2 (Bob): its Stop payload never carries `transcript_path`, so there is never a transcript
|
|
336
367
|
// to distil — and the bare envelope itself is not notes text (that would waste a model call
|
|
337
368
|
// on `{"event":"Stop","session_id":"s"}`). Scoped to `--host bob`: every other host's Stop/
|
|
@@ -384,7 +415,7 @@ export function cmdLearn(args) {
|
|
|
384
415
|
const proc = runLlm(llm, prompt);
|
|
385
416
|
const output = proc.stdout;
|
|
386
417
|
if (memDir && output.trim() && output.trim().toUpperCase() !== 'NOTHING') {
|
|
387
|
-
const { created, updated, archived } = writeMemories(output, memDir, existing);
|
|
418
|
+
const { created, updated, archived } = recordOwnWrites(path.dirname(memDir), () => writeMemories(output, memDir, existing));
|
|
388
419
|
if (created.length) {
|
|
389
420
|
err(`[learn] wrote ${created.length} memory file(s) to `
|
|
390
421
|
+ `${memDir}: ${created.join(', ')}\n`);
|
package/js/hosts/hooks-prims.mjs
CHANGED
|
@@ -70,15 +70,17 @@ export function selfAndParents(p) {
|
|
|
70
70
|
* the other. The trailing empty is dropped the way Python drops it (`"a\n"` is one line,
|
|
71
71
|
* `""` is none).
|
|
72
72
|
*/
|
|
73
|
+
export const LINE_BREAK = /\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]/;
|
|
74
|
+
|
|
73
75
|
export function splitLines(text) {
|
|
74
76
|
if (!text) return [];
|
|
75
|
-
const parts = text.split(
|
|
77
|
+
const parts = text.split(LINE_BREAK);
|
|
76
78
|
if (parts.length && parts[parts.length - 1] === '') parts.pop();
|
|
77
79
|
return parts;
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
/** The first window a Stop reads from a transcript's end; real transcripts reach 50 MB. */
|
|
81
|
-
|
|
83
|
+
const TAIL_BYTES = 2 * 1024 * 1024;
|
|
82
84
|
|
|
83
85
|
/**
|
|
84
86
|
* A transcript reader for ONE hook invocation: `read(file, judge)` hands `judge(text, whole)`
|
package/js/hosts/hooks.mjs
CHANGED
|
@@ -23,14 +23,11 @@
|
|
|
23
23
|
* this driver emits has no Python in its hook path at all — which is what let the interpreter
|
|
24
24
|
* discovery and its exit-4 refusal be deleted rather than merely bypassed.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* ~11,600 lines and the generator behind them. This module loads none of that, and that is
|
|
30
|
-
* deliberate rather than incidental: the Python originals already refuse to import `build`
|
|
31
|
-
* for the marker filenames they need ("literals keep the hook dependency-free"), and
|
|
26
|
+
* This module loads none of the generator behind `build`, and that is deliberate rather
|
|
27
|
+
* than incidental: it takes the marker filenames it needs as literals to stay
|
|
28
|
+
* dependency-free, and
|
|
32
29
|
* `bin/build-driver.mjs` could not be imported anyway, since its last statement runs the
|
|
33
|
-
* generator. What that
|
|
30
|
+
* generator. What that does NOT license is a second copy of a shared resolver under a
|
|
34
31
|
* different name — see `./hooks-prims.mjs`, where P5d found one that had silently diverged
|
|
35
32
|
* from its twin.
|
|
36
33
|
*
|
|
@@ -54,10 +51,11 @@
|
|
|
54
51
|
* and every file left behind. Absolute rather than compared is what let it survive the deletion
|
|
55
52
|
* of the implementation it was once compared against.
|
|
56
53
|
*/
|
|
57
|
-
import { readFileSync, appendFileSync, writeFileSync } from 'node:fs';
|
|
54
|
+
import { readFileSync, readlinkSync, appendFileSync, writeFileSync } from 'node:fs';
|
|
58
55
|
import path from 'node:path';
|
|
59
56
|
import { printOut as out, printErr as err, withDiscardableStderr } from '../lib/fs.mjs';
|
|
60
57
|
import { normcase } from '../lib/paths.mjs';
|
|
58
|
+
import { sharedPaths, machineDir } from '../lib/machine-dir.mjs';
|
|
61
59
|
import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
|
|
62
60
|
import {
|
|
63
61
|
GATE_LEDGER, globalHookStandingDown, hookProjectDir, resolvePath, sovereignBypass,
|
|
@@ -204,7 +202,7 @@ const asciiJson = (s) => JSON.stringify(s)
|
|
|
204
202
|
* `permissionDecision` defers, and the host puts the text next to the tool result (hooks.md,
|
|
205
203
|
* `additionalContext`; not seen live, no gate here runs a model turn).
|
|
206
204
|
*/
|
|
207
|
-
|
|
205
|
+
function contextNote(text) {
|
|
208
206
|
return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "additionalContext": ${asciiJson(text)}}}\n`;
|
|
209
207
|
}
|
|
210
208
|
|
|
@@ -212,7 +210,6 @@ export function contextNote(text) {
|
|
|
212
210
|
* The host reading this process's verdict — `--host` on the emitted command, `claude` when
|
|
213
211
|
* absent. Module state rather than a parameter because a hook process answers exactly one
|
|
214
212
|
* call: set once at the gate's entry (`guardGate`), read where the output dialect is chosen.
|
|
215
|
-
* `./hooks-context.mjs` keeps its own for the same reason.
|
|
216
213
|
*/
|
|
217
214
|
let HOST = 'claude';
|
|
218
215
|
const setHost = (args) => { HOST = (args && args.host) || 'claude'; };
|
|
@@ -243,14 +240,15 @@ const confirmTail = () => (HOST === 'bob' ? 'Leave the data in place.'
|
|
|
243
240
|
* credential in a tracked file and a history-discarding git act are wrong in every context,
|
|
244
241
|
* so refusing them costs nothing. rigor-5 (External Gate) joins them: a protected check the
|
|
245
242
|
* agent can edit is not a check, so it is as unconditional as the two Laws — NOT "Laws I/IV
|
|
246
|
-
* only", see bob-code.md B3.
|
|
247
|
-
*
|
|
248
|
-
*
|
|
243
|
+
* only", see bob-code.md B3. process-1 too (owner decision, 2026-11): with no prompt, a warning
|
|
244
|
+
* let the agent write the user's rules and memory on its own say. Process 5 is the USER's call
|
|
245
|
+
* as well, but a hard block would make Bob unable to commit at all, so it stays a warning the
|
|
246
|
+
* host logs. ops-2 (Commands Must Return, the root-scan check) is a block too: a warning would let a
|
|
249
247
|
* scan of every drive run for hours, and the agent loses nothing by re-targeting a directory.
|
|
250
248
|
* `gate-error` is a warning too: a crashed gate that blocked every tool call would be
|
|
251
249
|
* a lockout, not a safeguard, and there is no prompt through which the user could clear it.
|
|
252
250
|
*/
|
|
253
|
-
const BLOCK_RULES = new Set(['law-1', 'law-4', 'rigor-5', 'ops-2']);
|
|
251
|
+
const BLOCK_RULES = new Set(['law-1', 'law-4', 'rigor-5', 'ops-2', 'process-1']);
|
|
254
252
|
|
|
255
253
|
/**
|
|
256
254
|
* THE GATE LEDGER — one JSON line per ask, nothing per defer.
|
|
@@ -613,6 +611,27 @@ function shellWriteReason(args, command, payload) {
|
|
|
613
611
|
return null;
|
|
614
612
|
}
|
|
615
613
|
|
|
614
|
+
/**
|
|
615
|
+
* A parsed shell write that lands in a rule or memory store: the reason, or null. Asked on Claude
|
|
616
|
+
* and OpenClaude, and only a warning on Bob, whose one verdict is a hard block: shell is no boundary,
|
|
617
|
+
* and command text is no ground to refuse on. Fails open, like `shellWriteReason`.
|
|
618
|
+
*/
|
|
619
|
+
function shellStoreReason(args, command, payload) {
|
|
620
|
+
try {
|
|
621
|
+
const base = (payload && typeof payload.cwd === 'string' && payload.cwd) || process.cwd();
|
|
622
|
+
const own = payload && payload.tool_input && payload.tool_input.cwd;
|
|
623
|
+
const cwd = typeof own === 'string' && own ? path.resolve(base, own) : base;
|
|
624
|
+
for (const t of shellWriteTargets(command, cwd)) {
|
|
625
|
+
const store = ruleGateTarget(t, args.root, cwd);
|
|
626
|
+
if (store) {
|
|
627
|
+
return `Geneseed (Persist Insight) \u2014 writing to ${store} through a shell command: a standing `
|
|
628
|
+
+ 'rule, or a fact to remember? That choice is the user\'s.';
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
} catch { /* see above */ }
|
|
632
|
+
return null;
|
|
633
|
+
}
|
|
634
|
+
|
|
616
635
|
function gitDecide(args, payload) {
|
|
617
636
|
const command = ((payload && payload.tool_input) || {}).command;
|
|
618
637
|
if (typeof command !== 'string') return 0;
|
|
@@ -650,6 +669,9 @@ function gitDecide(args, payload) {
|
|
|
650
669
|
// target cannot be replayed from a command (`bobSettingsChange`), so it blocks.
|
|
651
670
|
const shellWrite = shellWriteReason(args, command, payload);
|
|
652
671
|
if (shellWrite) return ask(args, 'git-gate', 'rigor-5', shellWrite);
|
|
672
|
+
const shellStore = shellStoreReason(args, command, payload);
|
|
673
|
+
if (shellStore && HOST !== 'bob') return ask(args, 'git-gate', 'process-1', shellStore);
|
|
674
|
+
if (shellStore) err(`[geneseed] ${shellStore}\n`);
|
|
653
675
|
// `--no-consent`: the process pack (or process 5 alone) is off, so the commit/push ask has
|
|
654
676
|
// no rule behind it — but Law IV above is universal and has already run. Checked before
|
|
655
677
|
// `loopExempt` so a non-git command, or one with consent off, never pays for the whitelist.
|
|
@@ -670,32 +692,76 @@ export const cmdGitGate = guardGate(gitGate, 'git-gate');
|
|
|
670
692
|
* `_rule_gate_target` — name the store a write would land in, or null for ordinary work.
|
|
671
693
|
*
|
|
672
694
|
* A deployed install's folder and file names are theme-INDEPENDENT by design, so this
|
|
673
|
-
* matches literal names and needs no install lookup. `user-rules.md
|
|
674
|
-
* Geneseed's own coinage and match anywhere; any other markdown matches only
|
|
675
|
-
* install's `<root>/memory
|
|
695
|
+
* matches literal names and needs no install lookup. `user-rules.md`, `user-rules.draft.md` and
|
|
696
|
+
* `MEMORY.md` are Geneseed's own coinage and match anywhere; any other markdown matches only
|
|
697
|
+
* inside THIS install's `<root>/memory/` or the machine tier's `memory/`, or the store
|
|
698
|
+
* `$GENESEED_HARNESS` or `$GENESEED_MEMORY` names. Twin of the OpenCode guard's `ruleStoreTarget`.
|
|
699
|
+
*
|
|
700
|
+
* The test is on what the write LANDS on: as spelled, `..` and `//` folded, and with links followed,
|
|
701
|
+
* since a link from outside into a store and a store that links out are both real. On Windows a
|
|
702
|
+
* stream (`user-rules.md::$DATA`), trailing dots and spaces, a device path and this machine's admin
|
|
703
|
+
* share name the same file. A coined name matches by exact case outside a store: `docs/concepts/memory.md`
|
|
704
|
+
* is another file, on Windows too, and on Bob this is a hard block. A file that EXISTS under a coined
|
|
705
|
+
* name comes back in its true case through the link-followed form; a differently cased spelling
|
|
706
|
+
* of one that does not exist yet is not caught. `base` is the session's directory.
|
|
676
707
|
*/
|
|
677
|
-
// The close of the process-1 text
|
|
678
|
-
//
|
|
679
|
-
//
|
|
708
|
+
// The close of the process-1 text. On Claude this is a real prompt the host shows; the OpenCode
|
|
709
|
+
// guard has its own texts, because a re-issue releases nothing there. A weak model once took a
|
|
710
|
+
// refusal as leave to write the same file through a shell command, so the text names the one way
|
|
711
|
+
// forward and never a switch that turns the gate off.
|
|
680
712
|
export const PERSIST_ASK = 'Stop and ask the user now (the rule skill). If this edit was refused, '
|
|
681
713
|
+ 're-issue the same edit only after they answer; never write it another way (for example '
|
|
682
714
|
+ 'through a shell command).';
|
|
715
|
+
/** Bob's close instead: nothing there lifts the block, so nothing here may speak of re-issuing. */
|
|
716
|
+
const PERSIST_BOB = 'Tell the user what you wanted to write (the rule skill).';
|
|
683
717
|
|
|
684
|
-
function ruleGateTarget(p, root) {
|
|
718
|
+
function ruleGateTarget(p, root, base = null) {
|
|
685
719
|
if (typeof p !== 'string') return null;
|
|
720
|
+
const win = process.platform === 'win32';
|
|
686
721
|
// Split on BOTH separators rather than taking a basename: a payload carrying a Windows
|
|
687
722
|
// path reaches a POSIX host with its backslashes intact, and `path.basename` there
|
|
688
|
-
// returns the whole string — so the
|
|
723
|
+
// returns the whole string — so the coined names would go unrecognised exactly
|
|
689
724
|
// where they are meant to match on whichever host reads them.
|
|
690
|
-
const
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
725
|
+
const coined = (f) => {
|
|
726
|
+
const name = f.split(/[\\/]/).pop();
|
|
727
|
+
if (name === 'user-rules.md') return 'user-rules.md';
|
|
728
|
+
if (name === 'MEMORY.md') return 'the memory index';
|
|
729
|
+
if (name === 'user-rules.draft.md') return 'the rule draft';
|
|
730
|
+
return null;
|
|
731
|
+
};
|
|
732
|
+
const named = coined(p);
|
|
733
|
+
if (named) return named;
|
|
694
734
|
try {
|
|
695
|
-
const
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
? '
|
|
735
|
+
const forms = [];
|
|
736
|
+
if (p.startsWith('~')) forms.push(resolvePath(p));
|
|
737
|
+
else {
|
|
738
|
+
const spelled = !win ? p : p.replace(/^\/([a-zA-Z])(?=\/|$)/, '$1:').replace(/^[\\/]{2}[?.][\\/](?=[a-zA-Z]:)/, '')
|
|
739
|
+
.replace(/^[\\/]{2}(?:localhost|127\.0\.0\.1|\[?::1\]?)[\\/]([a-zA-Z])\$(?=[\\/]|$)/i, '$1:');
|
|
740
|
+
let abs = path.resolve(base || process.cwd(), spelled);
|
|
741
|
+
if (win) {
|
|
742
|
+
const drive = /^[a-zA-Z]:|^\\\\[^\\]+\\[^\\]+/.exec(abs)?.[0] ?? '';
|
|
743
|
+
abs = drive + abs.slice(drive.length).split('\\').map((s) => s.replace(/:.*$/, '').replace(/[. ]+$/, '')).join('\\');
|
|
744
|
+
}
|
|
745
|
+
forms.push(abs, resolvePath(abs));
|
|
746
|
+
// A dangling link has no realpath, and a write through it creates its target: follow it by
|
|
747
|
+
// hand, each hop through `resolvePath`, because a hop may pass a folder link. Links can loop.
|
|
748
|
+
for (let cur = forms[1], hop = 0; hop < 8; hop += 1) {
|
|
749
|
+
try { cur = resolvePath(path.resolve(path.dirname(cur), readlinkSync(cur))); forms.push(cur); } catch { break; }
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const hit = forms.map(coined).find(Boolean);
|
|
753
|
+
if (hit) return hit;
|
|
754
|
+
// This install's store, the machine tier's (`~/.config/geneseed/memory`) and the two a variable
|
|
755
|
+
// points at: a path compare, each store as written and with its links followed.
|
|
756
|
+
const stores = [];
|
|
757
|
+
if (root) stores.push(path.join(root, 'memory'));
|
|
758
|
+
try { stores.push(sharedPaths().memory); } catch { /* no home dir: no shared store to match */ }
|
|
759
|
+
if (process.env.GENESEED_HARNESS) stores.push(path.join(process.env.GENESEED_HARNESS, 'memory'));
|
|
760
|
+
if (process.env.GENESEED_MEMORY) stores.push(process.env.GENESEED_MEMORY);
|
|
761
|
+
const homes = stores.flatMap((s) => [path.resolve(s), resolvePath(s)]).map(normcase);
|
|
762
|
+
// `.slice(1)`, so the store dir itself is not one of its own ancestors.
|
|
763
|
+
return forms.some((f) => (win ? f.toLowerCase() : f).endsWith('.md')
|
|
764
|
+
&& selfAndParents(f).slice(1).some((a) => homes.includes(normcase(a)))) ? 'memory' : null;
|
|
699
765
|
} catch {
|
|
700
766
|
return null;
|
|
701
767
|
}
|
|
@@ -779,7 +845,8 @@ function gateConfig(p, root) {
|
|
|
779
845
|
if (bin && t.startsWith(bin + path.sep)) return true;
|
|
780
846
|
if (/^opencode\.jsonc?$/.test(path.basename(t))) return true;
|
|
781
847
|
const up = [path.dirname(target), path.dirname(path.dirname(target))];
|
|
782
|
-
|
|
848
|
+
// The machine tier is a home too, so the shared `excludes.json` is gated like a host's (a home, not a `.claude`-style marker).
|
|
849
|
+
const homes = [...roots, machineDir(), ...up.filter((d) => GATE_CONFIG_MARKERS.some((m) => normcase(m) === normcase(path.basename(d))))];
|
|
783
850
|
if (homes.some((h) => GATE_CONFIG_FILES.some((f) => normcase(path.join(h, f)) === t))) return true;
|
|
784
851
|
}
|
|
785
852
|
} catch { /* an unresolvable path is no hit, like `protectedIn` */ }
|
|
@@ -918,11 +985,15 @@ function diffReplaced(diff) {
|
|
|
918
985
|
return halves.length ? halves.join('\n') : diff;
|
|
919
986
|
}
|
|
920
987
|
|
|
988
|
+
const RULE_PATH_KEYS = ['file_path', 'path', 'notebook_path', 'target_file', 'target', 'file', 'filename', 'destination', 'dest',
|
|
989
|
+
'new_path', 'new_name', 'old_path', 'source', 'from', 'to'];
|
|
921
990
|
function ruleDecide(args, payload) {
|
|
922
991
|
const ti = (payload && payload.tool_input) || {};
|
|
923
|
-
// NotebookEdit names its target `notebook_path`; the settings matcher routes it here too.
|
|
924
|
-
|
|
925
|
-
|
|
992
|
+
// NotebookEdit names its target `notebook_path`; the settings matcher routes it here too. Every
|
|
993
|
+
// key is read, never the first found: Bob's move and rename tools carry two, and a harmless
|
|
994
|
+
// `path` beside the real target must not hide it from any gate below.
|
|
995
|
+
const paths = [...new Set(RULE_PATH_KEYS.map((k) => ti[k]).filter((v) => typeof v === 'string' && v))];
|
|
996
|
+
if (!paths.length) return 0;
|
|
926
997
|
// Write carries `content`, Edit `new_string`, NotebookEdit `new_source`, MultiEdit an
|
|
927
998
|
// `edits[]` of `new_string`s — every one can plant a credential, so every one is scanned.
|
|
928
999
|
// MultiEdit is no longer in Claude Code's own tool table (tools-reference.md) or the
|
|
@@ -938,8 +1009,9 @@ function ruleDecide(args, payload) {
|
|
|
938
1009
|
.filter((v) => typeof v === 'string').join('\n');
|
|
939
1010
|
// `--no-secrets-gate`: the install switched Law I's scan off (user decision 2026-10-18). Only
|
|
940
1011
|
// this check stands down; the protected checks and process 1 below still run.
|
|
941
|
-
|
|
942
|
-
|
|
1012
|
+
const carrier = paths.find((p) => !DOTENV_RE.test(p));
|
|
1013
|
+
if (!args.noSecretsGate && body && carrier && SECRET_RE.test(body)) {
|
|
1014
|
+
return ask(args, 'rule-gate', 'law-1', `Geneseed (Sealed Secrets) — ${carrier} would carry a `
|
|
943
1015
|
+ 'credential-shaped string. Secrets live in .env or a secret manager, never in a '
|
|
944
1016
|
+ 'tracked file.');
|
|
945
1017
|
}
|
|
@@ -947,9 +1019,11 @@ function ruleDecide(args, payload) {
|
|
|
947
1019
|
// shortcut: a write is told by its tool name, so a Bob write tool named outside WRITE_NAME_RE
|
|
948
1020
|
// passes both gates; switch to an allowlist of Bob's read tools if Bob adds or renames one.
|
|
949
1021
|
const bobRead = HOST === 'bob' && !WRITE_NAME_RE.test(String((payload && payload.tool_name) || ''));
|
|
950
|
-
const external = !bobRead && externalGate(args, p, payload);
|
|
1022
|
+
const external = !bobRead && paths.map((p) => externalGate(args, p, payload)).find(Boolean);
|
|
951
1023
|
if (external) return ask(args, 'rule-gate', 'rigor-5', external);
|
|
952
|
-
|
|
1024
|
+
// A read on Bob names the store too, and that is no write to refuse.
|
|
1025
|
+
const target = bobRead ? null : paths.map((p) => ruleGateTarget(p, args.root, payload && payload.cwd)).find(Boolean);
|
|
1026
|
+
const p = paths[0];
|
|
953
1027
|
if (!target) {
|
|
954
1028
|
// The ownership first-write gate (./ownership-gate.mjs), last: every rule above outranks it.
|
|
955
1029
|
// `--no-ownership-gate`: the install switched it off (D25).
|
|
@@ -960,7 +1034,8 @@ function ruleDecide(args, payload) {
|
|
|
960
1034
|
return 0;
|
|
961
1035
|
}
|
|
962
1036
|
return ask(args, 'rule-gate', 'process-1', `Geneseed (Persist Insight) \u2014 writing to `
|
|
963
|
-
+ `${target}: a standing rule, or a fact to remember? That choice is the user's.
|
|
1037
|
+
+ `${target}: a standing rule, or a fact to remember? That choice is the user's. `
|
|
1038
|
+
+ (HOST === 'bob' ? PERSIST_BOB : PERSIST_ASK));
|
|
964
1039
|
}
|
|
965
1040
|
export const cmdRuleGate = guardGate(ruleGate, 'rule-gate');
|
|
966
1041
|
|