geneseed 5.3.0 → 5.4.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 +95 -0
- package/README.md +23 -20
- package/SHIPPED.md +7 -7
- package/adapters/bob/README.md +31 -18
- package/adapters/claude-code/README.md +27 -22
- package/adapters/openclaude/README.md +18 -8
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +8 -3
- package/adapters/opencode/README.md +3 -2
- package/adapters/opencode/plugins/geneseed-activity.js +20 -21
- package/adapters/opencode/plugins/geneseed-context.js +175 -62
- package/adapters/opencode/plugins/geneseed-guard.js +419 -205
- package/adapters/opencode/plugins/geneseed-workflow.js +3 -2
- package/adapters/opencode/workflows/_runtime.js +3 -2
- package/bin/geneseed-cli.mjs +7 -0
- package/bin/geneseed-hook.mjs +59 -11
- package/docs/PRD.md +1 -1
- package/docs/README.md +1 -0
- package/docs/concepts/agents.md +1 -1
- package/docs/concepts/collaboration.md +2 -2
- package/docs/concepts/enforcement-table.md +5 -2
- package/docs/concepts/exclusions.md +18 -4
- package/docs/concepts/footprint.md +11 -1
- package/docs/concepts/foreman-mode.md +1 -1
- package/docs/concepts/hook-gates.md +5 -5
- package/docs/concepts/hooks.md +4 -3
- package/docs/concepts/host-matrix.md +24 -6
- 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/skills.md +1 -1
- package/docs/design-history.md +8 -0
- package/docs/extending.md +112 -35
- 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-bob.md +2 -2
- package/docs/guides/install-clone.md +1 -1
- package/docs/guides/install-openclaude.md +1 -1
- package/docs/guides/install.md +1 -1
- 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 +1 -1
- package/docs/guides/verify.md +12 -0
- package/docs/guides/worktree.md +1 -1
- package/docs/reference/environment.md +5 -2
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/plugin-guard.md +1 -1
- package/docs/reference/plugin-learn.md +1 -1
- package/docs/reference/plugin-workflow.md +1 -1
- package/docs/reference/troubleshoot-doctor.md +2 -2
- 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 +68 -4
- package/docs/understand/design-choices-hosts.md +1 -1
- package/docs/understand/design-choices-shape.md +1 -0
- package/docs/understand/enforced-vs-asked.md +2 -2
- package/docs/understand/machine-bob.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 +10 -5
- package/harness.config.json +1 -1
- package/js/README.md +5 -3
- package/js/build/args.mjs +13 -2
- package/js/build/driver.mjs +34 -7
- package/js/build/emit-claude.mjs +9 -5
- package/js/build/emit-opencode.mjs +13 -9
- package/js/build/generate.mjs +10 -165
- package/js/build/profile.mjs +318 -0
- package/js/build/render.mjs +81 -3
- package/js/build/retired-skills.mjs +60 -13
- package/js/build/source.mjs +15 -1
- package/js/build/stubs.mjs +4 -1
- package/js/cli-table.json +48 -3
- package/js/hosts/done-checks.mjs +6 -0
- package/js/hosts/geneseed-dir.mjs +3 -2
- package/js/hosts/gitref.mjs +5 -3
- package/js/hosts/hook-tap.mjs +104 -0
- package/js/hosts/hooks-context.mjs +4 -2
- package/js/hosts/hooks-done.mjs +345 -55
- package/js/hosts/hooks-learn.mjs +51 -19
- package/js/hosts/hooks-prims.mjs +5 -3
- package/js/hosts/hooks.mjs +172 -19
- package/js/hosts/hosts.mjs +80 -12
- package/js/hosts/installs.mjs +26 -1
- package/js/hosts/native.mjs +33 -7
- package/js/hosts/owned.mjs +7 -6
- package/js/hosts/ownership-gate.mjs +14 -1
- package/js/hosts/settings.mjs +273 -105
- package/js/hosts/shim.mjs +4 -4
- package/js/hosts/usage.mjs +9 -3
- package/js/inspect/checks-constitution.mjs +32 -0
- package/js/inspect/checks-probe.mjs +66 -5
- package/js/inspect/checks-repo.mjs +196 -2
- package/js/inspect/cost.mjs +34 -2
- package/js/inspect/diff.mjs +21 -3
- package/js/inspect/doctor.mjs +6 -1
- package/js/inspect/inventory.mjs +1 -1
- package/js/lib/machine-dir.mjs +1 -1
- package/js/lib/node-floor.mjs +46 -6
- package/js/maintain/setup.mjs +5 -1
- package/js/maintain/uninstall.mjs +42 -16
- package/js/maintain/update.mjs +4 -2
- package/js/web/actions.mjs +17 -12
- package/js/web/api.mjs +7 -2
- package/package.json +1 -1
- package/registry.json +14 -0
- package/src/AGENT.md.tmpl +15 -17
- 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/modes/foreman.md +6 -3
- package/src/skills/_self-improvement.md +9 -7
- package/src/skills/commit.md +17 -17
- package/src/skills/debug/ci.md +1 -1
- package/src/skills/dependencies.md +3 -3
- package/src/skills/document-project.md +3 -2
- 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/pipeline.md +1 -1
- package/src/skills/release.md +5 -8
- package/src/skills/review-response.md +4 -2
- package/src/skills/rule.md +27 -1
- package/src/skills/ship.md +54 -7
- package/src/skills/worktree.md +2 -2
- package/src/upstreams.json +7 -0
- 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/Activity-D2kOc3yi.js +1 -0
- package/web/dist/assets/ActivityDetail-By3xOr21.js +1 -0
- package/web/dist/assets/{Bonsai-Bfpb6W-1.js → Bonsai-CBWDTBA4.js} +1 -1
- package/web/dist/assets/{CopyButton-ByIntFtB.js → CopyButton-BVbpriMB.js} +1 -1
- package/web/dist/assets/Dashboard-CIJLPHM9.js +2 -0
- package/web/dist/assets/{Docs-DvlMJhpu.js → Docs-CiRRIELs.js} +3 -3
- package/web/dist/assets/Factories-DhyK0O8d.js +1 -0
- package/web/dist/assets/GreenhouseView-DW3PgTPy.js +1 -0
- package/web/dist/assets/Installs-B6nlo-Ly.js +3 -0
- package/web/dist/assets/JournalView-O65qEWfp.js +1 -0
- package/web/dist/assets/Kits-C5U-yT6Z.js +1 -0
- package/web/dist/assets/Laws-CuTw_XNf.js +4 -0
- package/web/dist/assets/{LibRows-DEHjIoD-.js → LibRows-D6-CVa3K.js} +1 -1
- package/web/dist/assets/Library-CzPlerd6.js +3 -0
- package/web/dist/assets/Loops-CqNF_-nS.js +2 -0
- package/web/dist/assets/Markdown-CxkA7940.js +71 -0
- package/web/dist/assets/OperatorHudView-BNr8K5qj.js +1 -0
- package/web/dist/assets/Personal-DeDb9e8O.js +2 -0
- package/web/dist/assets/Settings-B8MPN_AD.js +1 -0
- package/web/dist/assets/{Tabs-CWeQTADL.js → Tabs-DJzAez4h.js} +1 -1
- package/web/dist/assets/index-BL3P-9Rg.js +6 -0
- package/web/dist/assets/{index-CsAZq0BQ.css → index-CRWqKxfY.css} +1 -1
- package/web/dist/index.html +2 -2
- package/adapters/claude-code/settings.json +0 -52
- package/web/dist/assets/Activity-CqJiquEq.js +0 -1
- package/web/dist/assets/ActivityDetail-BSzevynX.js +0 -1
- package/web/dist/assets/Dashboard-DBOEi9lQ.js +0 -2
- package/web/dist/assets/Factories-Bpvv7L2H.js +0 -1
- package/web/dist/assets/GreenhouseView-GpBsYn50.js +0 -1
- package/web/dist/assets/Installs-BlGmVrFK.js +0 -3
- package/web/dist/assets/JournalView-iLuLrOxE.js +0 -1
- package/web/dist/assets/Kits-DRwpxC-J.js +0 -1
- package/web/dist/assets/Laws-CZkiNOWQ.js +0 -4
- package/web/dist/assets/Library-B4K-1iNF.js +0 -3
- package/web/dist/assets/Loops-BWSzaW8E.js +0 -2
- package/web/dist/assets/Markdown-0ORz7tAc.js +0 -69
- package/web/dist/assets/OperatorHudView-BAXwCEvY.js +0 -1
- package/web/dist/assets/Personal-Bp9nV4GR.js +0 -2
- package/web/dist/assets/Settings-CWWuaIp-.js +0 -1
- package/web/dist/assets/index-How7SzDZ.js +0 -6
package/js/hosts/settings.mjs
CHANGED
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
* STDOUT, every other message to stderr) is inherited from `_build_settings.py` and kept
|
|
21
21
|
* deliberately rather than tidied.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
* `
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* ONLY GENESEED'S OWN HANDLERS ARE EVER REWRITTEN. `mergeClaudeSettings` and
|
|
24
|
+
* `unwireClaudeSettings` know one by its signature (`ownHandler`: the shim, a hook verb, this
|
|
25
|
+
* install's root), replace or remove exactly those, and leave every other handler as found,
|
|
26
|
+
* even inside a group Geneseed wrote. `GENESEED_HOOK_SNIFF` recognises the shim form for the
|
|
27
|
+
* integrity check's warning. A 1.x install, wired before the shim, must rebuild first.
|
|
27
28
|
*
|
|
28
29
|
* ONE KNOWN DIVERGENCE, recorded rather than reproduced. JS objects order integer-like
|
|
29
30
|
* keys first, so a settings.json carrying a `"1"` or `"2"` at any level comes back from
|
|
@@ -42,8 +43,9 @@ import {
|
|
|
42
43
|
indexOfDeepEqual, get, has, isDict, readJsonc,
|
|
43
44
|
} from '../lib/json.mjs';
|
|
44
45
|
import { SHIM_MARK, claudeHookShell, hookPrefix, shimHome } from './shim.mjs';
|
|
45
|
-
import { GLOBAL_MANIFEST } from './hosts.mjs';
|
|
46
|
+
import { GLOBAL_MANIFEST, ownHookVerb } from './hosts.mjs';
|
|
46
47
|
import { gitRootOf } from './gitref.mjs';
|
|
48
|
+
import { askDecision } from './hooks-prims.mjs';
|
|
47
49
|
|
|
48
50
|
// `readJsonc` moved to ../lib/json.mjs so the hook path can parse a settings file (A2 L2).
|
|
49
51
|
export { readJsonc };
|
|
@@ -273,8 +275,12 @@ function defaultPermission(doctrines = null, excluded = [], deletionGate = true)
|
|
|
273
275
|
const OWNED_BASH = ['git commit*', 'git push*',
|
|
274
276
|
...PUSH_CHAIN.flatMap(([keys]) => keys)];
|
|
275
277
|
|
|
276
|
-
/**
|
|
277
|
-
|
|
278
|
+
/**
|
|
279
|
+
* The verdict Geneseed itself writes for each owned key — what "still reads as ours" means.
|
|
280
|
+
* Exported for `unmergeOpencodeJson`, which takes a recorded gate back at uninstall under the
|
|
281
|
+
* same two conditions a pack-off rebuild does: recorded, and still at this verdict.
|
|
282
|
+
*/
|
|
283
|
+
export const OWNED_VERDICT = new Map([['git commit*', 'ask'], ['git push*', 'ask']]);
|
|
278
284
|
for (const [keys, verdict] of PUSH_CHAIN) for (const k of /** @type {string[]} */ (keys)) OWNED_VERDICT.set(k, /** @type {string} */ (verdict));
|
|
279
285
|
|
|
280
286
|
/**
|
|
@@ -372,6 +378,30 @@ function reconcileOpencodePermission(perm, want, record = new Set(), pruneAll =
|
|
|
372
378
|
return [changed, stranded, null];
|
|
373
379
|
}
|
|
374
380
|
|
|
381
|
+
/**
|
|
382
|
+
* The gates a `--prune-gates` build of this selection would take out of `jsonPath`, read without
|
|
383
|
+
* writing — the console's notice and its "Remove stranded gates" button (Installs page).
|
|
384
|
+
*
|
|
385
|
+
* It runs `reconcileOpencodePermission` itself on a copy, so it cannot disagree with the build
|
|
386
|
+
* about what is stranded: the keys it declines to remove, minus the ones a user re-scoped (a
|
|
387
|
+
* value that is no longer `OWNED_VERDICT`), which `--prune-gates` keeps too. A recorded gate
|
|
388
|
+
* never shows here: a plain rebuild already takes it back. `commented` says the file has
|
|
389
|
+
* comments, where a build names the keys but cannot write — the console says "by hand" then.
|
|
390
|
+
* Nothing to read, no `permission`, or a shape the build cannot wire into: no keys.
|
|
391
|
+
* @returns {{ keys: string[], commented: boolean }}
|
|
392
|
+
*/
|
|
393
|
+
export function prunableGates(jsonPath, doctrines = null, excluded = [], deletionGate = true,
|
|
394
|
+
record = []) {
|
|
395
|
+
const { state, data, hadComments } = loadJsonObject(opencodeTarget(jsonPath));
|
|
396
|
+
if (state !== 'ok' || !has(data, 'permission')) return { keys: [], commented: false };
|
|
397
|
+
const perm = structuredClone(get(data, 'permission'));
|
|
398
|
+
const [, stranded] = reconcileOpencodePermission(perm,
|
|
399
|
+
defaultPermission(doctrines, excluded, deletionGate), new Set(record));
|
|
400
|
+
const bash = isDict(perm) && isDict(get(perm, 'bash')) ? get(perm, 'bash') : {};
|
|
401
|
+
const keys = stranded.filter((k) => bash[k] === OWNED_VERDICT.get(k));
|
|
402
|
+
return { keys, commented: keys.length > 0 && !!hadComments };
|
|
403
|
+
}
|
|
404
|
+
|
|
375
405
|
/**
|
|
376
406
|
* `permission.skill` rows for OpenCode's O-1 fix (opencode-verdict.md): a skill marked
|
|
377
407
|
* `<!-- invocation: user -->` is still model-invocable there (Claude Code's
|
|
@@ -571,7 +601,7 @@ export function loadJsonObject(p, { strict = false } = {}) {
|
|
|
571
601
|
*
|
|
572
602
|
* `permission` is THREE-STATE, not a boolean: `'add'` for a file with no `permission` key,
|
|
573
603
|
* `'reconcile'` for one that has a block this build would have wired gates into, and falsy for
|
|
574
|
-
* neither. A commented `.jsonc` is never rewritten — that is what "your edits are kept" buys —
|
|
604
|
+
* neither. A commented file (`.json` or `.jsonc`) is never rewritten — that is what "your edits are kept" buys —
|
|
575
605
|
* so the only thing this branch can do about a stale block is SAY SO, and telling a file that
|
|
576
606
|
* already has a `permission` key to add one is not saying so. Any other truthy value is read as
|
|
577
607
|
* `'add'`, which is what the boolean callers this replaced meant.
|
|
@@ -646,7 +676,7 @@ export function atomicWriteJson(p, config) {
|
|
|
646
676
|
*
|
|
647
677
|
* `result.skillsAdded` is set to the `permission.skill` denies this call added ONLY when the
|
|
648
678
|
* file on disk now matches what it computed (written, or nothing to change). Left unset on
|
|
649
|
-
* every path that wrote nothing — unreadable, not an object, commented
|
|
679
|
+
* every path that wrote nothing — unreadable, not an object, commented, write
|
|
650
680
|
* failure — so the caller keeps its previous record rather than claiming denies never written.
|
|
651
681
|
* `result.bashGates` (the next `bash_gates`, from `oldGates`) follows the same rule.
|
|
652
682
|
* `pruneGates` is `--prune-gates`: see `reconcileOpencodePermission`. */
|
|
@@ -771,7 +801,10 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
771
801
|
result.bashGates = [...gates];
|
|
772
802
|
return target;
|
|
773
803
|
}
|
|
774
|
-
|
|
804
|
+
// ⚠ THE COMMENTS DECIDE, NOT THE EXTENSION. OpenCode reads `opencode.json` as JSONC too, so a
|
|
805
|
+
// commented plain `.json` is as much the user's prose as a `.jsonc`; this once tested the
|
|
806
|
+
// extension as well, and such a file was rewritten with its comments dropped.
|
|
807
|
+
if (hadComments) {
|
|
775
808
|
// Named, since this branch cannot take them out; `bash_gates` keeps its old value (the
|
|
776
809
|
// caller's rule for a merge that wrote nothing), so they are still ours on the next emit.
|
|
777
810
|
if (gatesRemoved.length) {
|
|
@@ -787,7 +820,7 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
787
820
|
// whole one; `reconcile` = there is a block and it is missing gates this build wires, and
|
|
788
821
|
// this branch cannot write them because rewriting would drop the user's comments.
|
|
789
822
|
//
|
|
790
|
-
// DECIDED, NOT DEFERRED: a commented
|
|
823
|
+
// DECIDED, NOT DEFERRED: a commented file is never rewritten and never will be. A
|
|
791
824
|
// comment-preserving JSONC writer is a parser, an AST and a printer — a dependency-free
|
|
792
825
|
// one, since this package ships zero — to keep formatting nobody asked us to touch, in a
|
|
793
826
|
// file Geneseed co-owns rather than owns. The advice above is the whole remedy: the exact
|
|
@@ -817,6 +850,17 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
817
850
|
// gate does not drive a cell through a real fs failure — it exercises the branch with an
|
|
818
851
|
// injectable failure instead and compares everything except the OS's own wording.
|
|
819
852
|
|
|
853
|
+
/**
|
|
854
|
+
* What an OpenClaude gate prints when it could not start: the ask the gates themselves print
|
|
855
|
+
* (`askDecision`), with a fixed reason. It is written into a hook command between single quotes
|
|
856
|
+
* (`claudeHookGroups`), so the text may hold no `'`, and no `$` or backtick either, which a
|
|
857
|
+
* later edit to double quotes would expand. `tests/unit/hook_form.test.mjs` holds it to that.
|
|
858
|
+
*/
|
|
859
|
+
export const GATE_DOWN = askDecision('Geneseed gate error: the gate did not start, so nothing judged this call.\n'
|
|
860
|
+
+ 'Safe choice: Deny, then run geneseed doctor.\n'
|
|
861
|
+
+ 'It asks because a gate that did not run cannot say this call is safe.\n'
|
|
862
|
+
+ 'If you allow it, this call runs with no check at all.').trimEnd();
|
|
863
|
+
|
|
820
864
|
/**
|
|
821
865
|
* `_build_settings._claude_hook_groups` — Geneseed's Claude hooks, keyed by event.
|
|
822
866
|
*
|
|
@@ -828,8 +872,8 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
828
872
|
* and gains `--no-consent`, which skips only the process-5 branch. It once DROPPED the whole
|
|
829
873
|
* group instead, and Law IV went with it — on Claude only, since Bob carries it
|
|
830
874
|
* through `tool-gate`. The command changing is also what re-wires an existing install:
|
|
831
|
-
* `mergeClaudeSettings`
|
|
832
|
-
*
|
|
875
|
+
* `mergeClaudeSettings` replaces this install's handler in each slot with the one returned
|
|
876
|
+
* here, and removes a handler of ours that no slot here accounts for.
|
|
833
877
|
*
|
|
834
878
|
* ⚠ WHAT THIS DOES **NOT** CLAIM, because it was written here once and it was false: that the
|
|
835
879
|
* string `process 5` is absent from a pack-off bundle. It is not — 18 emitted files still cite
|
|
@@ -856,7 +900,7 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
856
900
|
gates = {}) {
|
|
857
901
|
// One object keyed as `GATE_SWITCHES` keys it; only an explicit `false` disarms a gate.
|
|
858
902
|
const { secretsGate = true, doneGate = true, deletionGate = true, ownershipGate = true,
|
|
859
|
-
externalGate = true, testNote = true } = gates ?? {};
|
|
903
|
+
externalGate = true, testNote = true, ownBranchPass = true } = gates ?? {};
|
|
860
904
|
const run = hookPrefix(hookOpts);
|
|
861
905
|
const mem = `--memory "${path.join(cfg, 'memory')}"`;
|
|
862
906
|
// --root carries the install's own dir so a GLOBAL hook can stand down when a live, wired
|
|
@@ -865,8 +909,8 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
865
909
|
// `git-gate` read it, `learn` reads `--memory`'s parent. `rule-gate` and Bob's `tool-gate`
|
|
866
910
|
// do not stand down: both still run once per install (host-compat B4 fixed only the three).
|
|
867
911
|
if (host === 'bob') {
|
|
868
|
-
// BOB'S OWN HOOK CONTRACT, per its hooks doc and 2.0.2 changelog
|
|
869
|
-
//
|
|
912
|
+
// BOB'S OWN HOOK CONTRACT, per its hooks doc and 2.0.2 changelog:
|
|
913
|
+
// FIVE events — SessionStart, UserPromptSubmit,
|
|
870
914
|
// PreToolUse, PostToolUse, Stop — Claude's names, but NOT Claude's protocol. stdout is
|
|
871
915
|
// read as context on SessionStart only; on PreToolUse it is ignored and the one way to
|
|
872
916
|
// refuse a call is EXIT CODE 2. The groups this emit wrote before were Claude's whole
|
|
@@ -874,18 +918,18 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
874
918
|
// here; the activity writer counts a compaction on SessionStart `compact`), and the gates answered with a
|
|
875
919
|
// stdout JSON Bob never reads — permissive on every call. `--host bob` makes the gates
|
|
876
920
|
// speak exit codes (js/hosts/hooks.mjs). DELIBERATELY no matcher on PreToolUse
|
|
877
|
-
// (host-compat O1, revisited):
|
|
921
|
+
// (host-compat O1, revisited): the tool list in Bob's docs is already stale against the
|
|
878
922
|
// changelog (`web_fetch`, the 2.1.0 Office/IBM-docs tools are undocumented there), so an
|
|
879
923
|
// allow-list matcher built from it fails OPEN on every tool Bob adds between one
|
|
880
924
|
// docs read and the next — the exact failure mode a gate must not have. A deny-list
|
|
881
925
|
// with a negative-lookahead was the other shape considered; it depends on an unverified
|
|
882
|
-
// regex DIALECT (
|
|
926
|
+
// regex DIALECT (Bob's docs never state whether their "regex on the tool name" supports
|
|
883
927
|
// lookahead at all), and a dialect mismatch there would silence the WHOLE gate rather than
|
|
884
|
-
// merely skip spawning it.
|
|
885
|
-
// performance only
|
|
886
|
-
// instead.
|
|
887
|
-
//
|
|
888
|
-
//
|
|
928
|
+
// merely skip spawning it. The matcher's upside is low,
|
|
929
|
+
// performance only — not worth either risk. So `tool-gate` reads the payload's shape
|
|
930
|
+
// instead. The gates read Claude's fields (`command`, `file_path`/`path`,
|
|
931
|
+
// `content`/`new_string`) and defer on anything else. What was checked against Bob itself:
|
|
932
|
+
// docs/concepts/host-matrix.md, "What is verified". Revisit a matcher only
|
|
889
933
|
// once a live Bob session can confirm both the current tool list and the regex dialect.
|
|
890
934
|
const b = ' --host bob';
|
|
891
935
|
// `--no-deletion-gate` only when the install switched Law IV's gate off, so an armed
|
|
@@ -900,15 +944,22 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
900
944
|
// External Gate's hook and the weakened-test note, the same contract.
|
|
901
945
|
const eg = externalGate === false ? ' --no-external-gate' : '';
|
|
902
946
|
const tn = testNote === false ? ' --no-test-note' : '';
|
|
947
|
+
// Strict consent (`ownBranchPass` off) rides only while the rule is on: off, nothing asks.
|
|
948
|
+
const nc = consentRuleOn(doctrines, excluded) ? (ownBranchPass === false ? ' --strict-consent' : '') : ' --no-consent';
|
|
903
949
|
return {
|
|
904
950
|
SessionStart: [{ hooks: [{ type: 'command', command: `${run} context --root "${cfg}"${b} || exit 0` }] }],
|
|
905
|
-
// One group, both gates
|
|
906
|
-
//
|
|
907
|
-
//
|
|
908
|
-
//
|
|
909
|
-
//
|
|
910
|
-
//
|
|
911
|
-
|
|
951
|
+
// One group, both gates. `tool-gate` EXITS 2 for Laws I and IV (unless built
|
|
952
|
+
// `--no-secrets-gate` / `--no-deletion-gate`), a write to the rule store (process 1), a
|
|
953
|
+
// write under a project's own `.geneseed/protected-checks.txt` (the project opted in)
|
|
954
|
+
// and a recursive scan rooted at a whole filesystem (ops 2, the root-scan check).
|
|
955
|
+
// Process 5's consent is only a stderr line here, since Bob has no ask tier; with the
|
|
956
|
+
// rule off that line had no rule behind it, so `--no-consent` drops it as it drops
|
|
957
|
+
// Claude's ask. Only then: an armed install's command stays byte-identical, and an older
|
|
958
|
+
// shim, which refuses the flag on this verb, never sees it.
|
|
959
|
+
// NO LAUNCH-FAILURE TAIL, unlike OpenClaude's gates below. Bob ignores a PreToolUse hook's
|
|
960
|
+
// stdout, so a printed ask says nothing; the one refusal is exit 2, and a tail that exits
|
|
961
|
+
// 2 whenever the shim cannot start would lock out every tool with no prompt to lift it.
|
|
962
|
+
PreToolUse: [{ hooks: [{ type: 'command', command: `${run} tool-gate --root "${cfg}"${b}${nc}${sg}${dg}${og}${eg}${tn}${ruleFlags('tool-gate', doctrines, excluded)}` }] }],
|
|
912
963
|
// Bob's Stop payload never carries `transcript_path` (I2) — `learn` reads `--host bob`
|
|
913
964
|
// and returns immediately rather than wasting a model call on the bare envelope. KEPT
|
|
914
965
|
// rather than DROPPED: the stand-down costs nothing (no transcript read, no spawn), and
|
|
@@ -928,9 +979,21 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
928
979
|
// `--host` on `git-gate` but not on `learn`, which then exits 1 under `|| exit 0` and skips.
|
|
929
980
|
const h = host === 'openclaude' ? ' --host openclaude' : '';
|
|
930
981
|
const context = `${run} context --root "${cfg}"${h} || exit 0`;
|
|
931
|
-
|
|
982
|
+
// A GATE THAT CANNOT START MUST NOT READ AS "NOTHING TO SAY". Claude Code blocks on it
|
|
983
|
+
// (`onFailure` below). OpenClaude predates that field: a shim that is gone or a node that
|
|
984
|
+
// will not load exits non-zero with stdout empty, which it takes as a deferral, and every
|
|
985
|
+
// call goes through unjudged. So its two gates print a static ask in that case
|
|
986
|
+
// (`GATE_DOWN`). `||` and `printf` are safe to write because OpenClaude always runs its hooks
|
|
987
|
+
// under Git Bash or sh; a gate that ran has exited 0 on every path, so the tail never adds to
|
|
988
|
+
// a verdict. Never on Claude (byte-identical, and PowerShell 5.1 cannot parse `||`), never on
|
|
989
|
+
// the `Skill|Agent|Task` counter (a counter that cannot start must not ask), never on Bob
|
|
990
|
+
// (see its PreToolUse above).
|
|
991
|
+
const down = host === 'openclaude' ? ` || printf '%s' '${GATE_DOWN}'` : '';
|
|
992
|
+
const consent = consentRuleOn(doctrines, excluded) ? (ownBranchPass === false ? ' --strict-consent' : '') : ' --no-consent';
|
|
993
|
+
const gate = `${run} git-gate --root "${cfg}"${h}${consent}`
|
|
932
994
|
+ (deletionGate === false ? ' --no-deletion-gate' : '')
|
|
933
|
-
+ (externalGate === false ? ' --no-external-gate' : '') + ruleFlags('git-gate', doctrines, excluded)
|
|
995
|
+
+ (externalGate === false ? ' --no-external-gate' : '') + ruleFlags('git-gate', doctrines, excluded)
|
|
996
|
+
+ down;
|
|
934
997
|
// `--no-secrets-gate` skips only rule-gate's credential scan (rigor 5 and process 1 still
|
|
935
998
|
// run); `--no-done-gate` only learn's done check, never the distillation. One `learn` string
|
|
936
999
|
// feeds Stop, SubagentStop and PreCompact, and the flag sits before `|| exit 0`.
|
|
@@ -940,7 +1003,8 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
940
1003
|
const ruleGate = `${run} rule-gate --root "${cfg}"${secretsGate === false ? ' --no-secrets-gate' : ''}`
|
|
941
1004
|
+ (ownershipGate === false ? ' --no-ownership-gate' : '')
|
|
942
1005
|
+ (externalGate === false ? ' --no-external-gate' : '')
|
|
943
|
-
+ (testNote === false ? ' --no-test-note' : '') + ruleFlags('rule-gate', doctrines, excluded)
|
|
1006
|
+
+ (testNote === false ? ' --no-test-note' : '') + ruleFlags('rule-gate', doctrines, excluded)
|
|
1007
|
+
+ down;
|
|
944
1008
|
// `--no-rule-store` on learn: with process 1 off a rule write runs with no prompt, so the change
|
|
945
1009
|
// report must not count it as approved (`storeReport`). Bob's learn reports every change already.
|
|
946
1010
|
const learn = `${run} learn ${mem}${h}${doneGate === false ? ' --no-done-gate' : ''}`
|
|
@@ -960,9 +1024,11 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
960
1024
|
// `Bash|PowerShell`, not `Bash` alone (Claude verdict I1): docs `hooks.md` says a hook
|
|
961
1025
|
// that matches only `Bash` never fires on the PowerShell tool, which is Windows' default
|
|
962
1026
|
// shell whenever Git Bash is absent — and on Windows without Git Bash, Bash is not even
|
|
963
|
-
// registered. `
|
|
964
|
-
//
|
|
965
|
-
|
|
1027
|
+
// registered. `|Monitor` because Claude Code's Monitor tool runs a shell `command` in the
|
|
1028
|
+
// background, and unmatched it was a shell no gate saw. `tool_input.command` is the same
|
|
1029
|
+
// field on all three, so `GIT_GATE_RE` needs no change; a host without the tool never
|
|
1030
|
+
// sends the name.
|
|
1031
|
+
{ matcher: 'Bash|PowerShell|Monitor', hooks: [{ type: 'command', command: gate, ...onFailureBlock }] },
|
|
966
1032
|
{
|
|
967
1033
|
// No `MultiEdit`: it is not in Claude Code's tool table (tools-reference.md) — a dead
|
|
968
1034
|
// matcher entry (Claude verdict R2).
|
|
@@ -971,8 +1037,9 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
971
1037
|
},
|
|
972
1038
|
// Usage counting (js/hosts/usage.mjs): `tool-gate` records a Skill or subagent call and
|
|
973
1039
|
// judges nothing else about it. `Task` is the subagent tool's older name. No
|
|
974
|
-
// `onFailure: 'block'`: a counter that cannot start must never stop a skill.
|
|
975
|
-
|
|
1040
|
+
// `onFailure: 'block'`: a counter that cannot start must never stop a skill. `--host` on
|
|
1041
|
+
// OpenClaude, or the activity view files its skill and agent calls under Claude.
|
|
1042
|
+
{ matcher: 'Skill|Agent|Task', hooks: [{ type: 'command', command: `${run} tool-gate --root "${cfg}"${h}` }] },
|
|
976
1043
|
],
|
|
977
1044
|
// One matcher-less group, not a `startup|clear` / `resume|compact` split (Claude verdict
|
|
978
1045
|
// I4): every SessionStart source — `startup`, `resume`, `clear`, `compact` and `fork` —
|
|
@@ -1076,14 +1143,96 @@ function readSettingsForMerge(p, consequence) {
|
|
|
1076
1143
|
return [data, hadComments];
|
|
1077
1144
|
}
|
|
1078
1145
|
|
|
1146
|
+
/** Is this handler Geneseed's, for the install at `cfg`? `ownHookVerb` (./hosts.mjs) says how. */
|
|
1147
|
+
export function ownHandler(h, cfg) {
|
|
1148
|
+
return isDict(h) && ownHookVerb(get(h, 'command'), cfg) !== null;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/** A handler whose command names the shim, whatever root it carries. */
|
|
1152
|
+
const shimMarked = (h) => isDict(h) && typeof get(h, 'command') === 'string'
|
|
1153
|
+
&& h.command.includes(SHIM_MARK);
|
|
1154
|
+
|
|
1155
|
+
/** A group's handler list, or null for a value that is not a group. */
|
|
1156
|
+
const handlersOf = (g) => (isDict(g) && Array.isArray(get(g, 'hooks')) ? g.hooks : null);
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* Take one RECORDED group out of `hooks`, found as the manifest recorded it. True when something
|
|
1160
|
+
* went.
|
|
1161
|
+
*
|
|
1162
|
+
* A claim is the group as it sat on file, so it can hold a handler the user put inside our
|
|
1163
|
+
* group. That one stays: only the handlers naming the shim go (minus those `keep` spares), and
|
|
1164
|
+
* the group goes when nothing is left. A recorded group with no shim handler at all is an older
|
|
1165
|
+
* form (a 1.x interpreter command) and goes whole, as the manifest says.
|
|
1166
|
+
*/
|
|
1167
|
+
function dropRecorded(hooks, rec, keep) {
|
|
1168
|
+
const event = get(rec, 'event');
|
|
1169
|
+
const arr = get(hooks, event);
|
|
1170
|
+
if (!Array.isArray(arr)) return false;
|
|
1171
|
+
const at = indexOfDeepEqual(arr, get(rec, 'group'));
|
|
1172
|
+
if (at < 0) return false;
|
|
1173
|
+
const hs = handlersOf(arr[at]);
|
|
1174
|
+
const left = hs && hs.some(shimMarked) ? hs.filter((h) => !shimMarked(h) || keep(h)) : [];
|
|
1175
|
+
if (left.length && left.length === hs.length) return false;
|
|
1176
|
+
if (left.length) arr[at].hooks = left;
|
|
1177
|
+
else arr.splice(at, 1);
|
|
1178
|
+
if (!arr.length) delete hooks[event];
|
|
1179
|
+
return true;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Walk every handler of the install at `cfg` (`ownHandler`) and put `decide(event, group, h)` in
|
|
1184
|
+
* its place: the handler itself (unchanged), a replacement, or null to remove it. A group goes
|
|
1185
|
+
* only when this emptied it, an event only when its last group went. No other handler is read
|
|
1186
|
+
* past the ownership test, in our group or out of it. True when anything changed.
|
|
1187
|
+
*/
|
|
1188
|
+
function rewriteOwn(hooks, cfg, decide) {
|
|
1189
|
+
let changed = false;
|
|
1190
|
+
for (const [event, arr] of Object.entries(hooks)) {
|
|
1191
|
+
if (!Array.isArray(arr)) continue;
|
|
1192
|
+
const emptied = new Set();
|
|
1193
|
+
for (const g of arr) {
|
|
1194
|
+
const hs = handlersOf(g);
|
|
1195
|
+
if (!hs) continue;
|
|
1196
|
+
const next = [];
|
|
1197
|
+
for (const h of hs) {
|
|
1198
|
+
const to = ownHandler(h, cfg) ? decide(event, g, h) : h;
|
|
1199
|
+
if (to) next.push(to);
|
|
1200
|
+
if (to !== h) changed = true;
|
|
1201
|
+
}
|
|
1202
|
+
if (next.length === hs.length && next.every((h, i) => h === hs[i])) continue;
|
|
1203
|
+
g.hooks = next;
|
|
1204
|
+
if (!next.length) emptied.add(g);
|
|
1205
|
+
}
|
|
1206
|
+
if (!emptied.size) continue;
|
|
1207
|
+
const kept = arr.filter((g) => !emptied.has(g));
|
|
1208
|
+
if (kept.length) hooks[event] = kept;
|
|
1209
|
+
else delete hooks[event];
|
|
1210
|
+
}
|
|
1211
|
+
return changed;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1079
1214
|
/**
|
|
1080
1215
|
* `_build_settings._merge_claude_settings` — returns `[target, managed]`.
|
|
1081
1216
|
*
|
|
1082
|
-
* Surgical: every other key
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1086
|
-
* `
|
|
1217
|
+
* Surgical, and PER HANDLER: every other key, the user's own groups and a user's handler inside
|
|
1218
|
+
* one of our groups survive. Each canonical group is one slot (event, matcher, verb). The
|
|
1219
|
+
* handler of this install that fills a slot (`ownHandler`) is replaced where it sits, as
|
|
1220
|
+
* `{...existing, ...canonical}`, so a field the user added to it (`timeout`) stays; `shell` and
|
|
1221
|
+
* `onFailure` are ours and go when the canonical handler has none. A handler of ours that fills
|
|
1222
|
+
* no slot, or a slot already filled, is removed: that is what stops a re-emit with other gate
|
|
1223
|
+
* flags, a retired event or a widened matcher from leaving the old handler beside the new one,
|
|
1224
|
+
* with or without a manifest. A slot nothing fills is appended as the canonical group.
|
|
1225
|
+
*
|
|
1226
|
+
* `managed` is the claim set: every group that now holds one of our handlers, AS IT SITS ON FILE
|
|
1227
|
+
* after the merge, so a group that was already there is claimed too and unwire removes it.
|
|
1228
|
+
*
|
|
1229
|
+
* `priorHooks` is the manifest's previously-recorded groups. One no longer canonical and still
|
|
1230
|
+
* on file loses its shim handlers that are not this root's — a moved `--root`, which the
|
|
1231
|
+
* signature cannot see, since another root reads as another install.
|
|
1232
|
+
*
|
|
1233
|
+
* REFUSED, NEVER OVERWRITTEN: a `hooks` that is not an object, or a canonical event whose value
|
|
1234
|
+
* is not an array (`"Stop": {}`). Both are the user's, however wrong, and writing our groups
|
|
1235
|
+
* there would replace them — `readSettingsForMerge`'s rule, one level down.
|
|
1087
1236
|
*
|
|
1088
1237
|
* `cfgDir` is the install's own dir — what the hooks carry as `--root` and under which
|
|
1089
1238
|
* `memory/` lives. It is NOT always `dirname(p)`: Bob's global settings file is nested
|
|
@@ -1097,80 +1246,98 @@ export function mergeClaudeSettings(p, priorHooks = null, hookOpts = {},
|
|
|
1097
1246
|
const loaded = readSettingsForMerge(p, 'Hooks were not wired.');
|
|
1098
1247
|
if (!loaded) return [p, prior];
|
|
1099
1248
|
const [config, hadComments] = loaded;
|
|
1100
|
-
let hooks = get(config, 'hooks');
|
|
1101
|
-
if (!isDict(hooks)) hooks = {};
|
|
1102
1249
|
const canonical = claudeHookGroups(cfgDir, hookOpts, doctrines, excluded, host, gates);
|
|
1250
|
+
const refuse = (what) => {
|
|
1251
|
+
process.stderr.write(`[geneseed] ${what} in ${path.basename(p)} — NOT rewriting it `
|
|
1252
|
+
+ '(fix the file, then re-run). Hooks were not wired.\n');
|
|
1253
|
+
return [p, prior];
|
|
1254
|
+
};
|
|
1255
|
+
if (has(config, 'hooks') && !isDict(config.hooks)) return refuse('"hooks" is not an object');
|
|
1256
|
+
const hooks = has(config, 'hooks') ? config.hooks : {};
|
|
1257
|
+
const bad = Object.keys(canonical).find((e) => has(hooks, e) && !Array.isArray(hooks[e]));
|
|
1258
|
+
if (bad) return refuse(`"hooks.${bad}" is not an array`);
|
|
1259
|
+
|
|
1260
|
+
// One slot per canonical group: `claudeHookGroups` puts exactly one handler in each.
|
|
1261
|
+
const slots = [];
|
|
1103
1262
|
const canonFlat = [];
|
|
1104
1263
|
for (const [event, groups] of Object.entries(canonical)) {
|
|
1105
|
-
for (const g of groups)
|
|
1264
|
+
for (const g of groups) {
|
|
1265
|
+
canonFlat.push({ event, group: g });
|
|
1266
|
+
slots.push({ event, canon: g, matcher: get(g, 'matcher'), handler: g.hooks[0],
|
|
1267
|
+
verb: ownHookVerb(g.hooks[0].command, cfgDir), group: null });
|
|
1268
|
+
}
|
|
1106
1269
|
}
|
|
1107
|
-
let
|
|
1270
|
+
let changed = false;
|
|
1108
1271
|
for (const rec of prior) {
|
|
1109
1272
|
if (indexOfDeepEqual(canonFlat, rec) >= 0) continue;
|
|
1110
|
-
|
|
1111
|
-
const group = get(rec, 'group');
|
|
1112
|
-
const arr = get(hooks, event);
|
|
1113
|
-
if (Array.isArray(arr)) {
|
|
1114
|
-
const at = indexOfDeepEqual(arr, group);
|
|
1115
|
-
if (at >= 0) {
|
|
1116
|
-
arr.splice(at, 1);
|
|
1117
|
-
pruned = true;
|
|
1118
|
-
if (!arr.length) delete hooks[event];
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1273
|
+
if (dropRecorded(hooks, rec, (h) => ownHandler(h, cfgDir))) changed = true;
|
|
1121
1274
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1275
|
+
if (rewriteOwn(hooks, cfgDir, (event, g, h) => {
|
|
1276
|
+
const verb = ownHookVerb(h.command, cfgDir);
|
|
1277
|
+
const slot = slots.find((s) => !s.group && s.event === event && s.verb === verb
|
|
1278
|
+
&& s.matcher === get(g, 'matcher'));
|
|
1279
|
+
if (!slot) return null;
|
|
1280
|
+
slot.group = g;
|
|
1281
|
+
const merged = { ...h, ...slot.handler };
|
|
1282
|
+
for (const k of ['shell', 'onFailure']) if (!has(slot.handler, k)) delete merged[k];
|
|
1283
|
+
return deepEquals(merged, h) ? h : merged;
|
|
1284
|
+
})) changed = true;
|
|
1285
|
+
for (const s of slots) {
|
|
1286
|
+
if (s.group) continue;
|
|
1287
|
+
let arr = get(hooks, s.event);
|
|
1288
|
+
if (!Array.isArray(arr)) arr = hooks[s.event] = [];
|
|
1289
|
+
// A command the signature cannot read (no shim could be written and the fallback entry is
|
|
1290
|
+
// not named after it) is still found by equality, the old test.
|
|
1291
|
+
const at = s.verb ? -1 : indexOfDeepEqual(arr, s.canon);
|
|
1292
|
+
if (at < 0) {
|
|
1293
|
+
arr.push(s.canon);
|
|
1294
|
+
changed = true;
|
|
1130
1295
|
}
|
|
1131
|
-
|
|
1296
|
+
s.group = at < 0 ? s.canon : arr[at];
|
|
1132
1297
|
}
|
|
1133
|
-
const
|
|
1134
|
-
const managedNow =
|
|
1135
|
-
|
|
1298
|
+
const claimed = [...new Set(slots.map((s) => s.group))];
|
|
1299
|
+
const managedNow = claimed.map((group) => ({
|
|
1300
|
+
event: slots.find((s) => s.group === group).event, group }));
|
|
1301
|
+
if (!changed) return [p, managedNow];
|
|
1136
1302
|
if (hadComments) {
|
|
1303
|
+
// The exact groups, not a pointer to a sample: a sample cannot carry this install's shim
|
|
1304
|
+
// path, root or gate flags, and the one that shipped had drifted from the emitter.
|
|
1137
1305
|
process.stderr.write(`[geneseed] ${path.basename(p)} has comments — not rewriting it `
|
|
1138
|
-
+
|
|
1139
|
-
+
|
|
1306
|
+
+ '(your edits are kept). Merge this into it by hand:\n'
|
|
1307
|
+
+ `${JSON.stringify({ hooks: canonical }, null, 2)}\n`);
|
|
1140
1308
|
return [p, prior];
|
|
1141
1309
|
}
|
|
1142
|
-
// Never empty here: `canonical` always carries at least three events, and every one of them
|
|
1143
|
-
// was just written into `hooks`.
|
|
1144
1310
|
config.hooks = hooks;
|
|
1145
1311
|
atomicWriteJson(p, config);
|
|
1146
1312
|
return [p, managedNow];
|
|
1147
1313
|
}
|
|
1148
1314
|
|
|
1149
1315
|
/**
|
|
1150
|
-
* `_build_settings._unwire_claude_settings` — remove
|
|
1316
|
+
* `_build_settings._unwire_claude_settings` — remove the recorded groups (`dropRecorded`), then,
|
|
1317
|
+
* given the install's `cfg`, every handler of that install still on file (`ownHandler`).
|
|
1318
|
+
*
|
|
1319
|
+
* The second pass is what a manifest alone could not do: a handler the user gave a `timeout`
|
|
1320
|
+
* after the emit no longer equals its claim, and one wired by an emit whose manifest was lost
|
|
1321
|
+
* was never claimed. Both would keep running after an uninstall. A handler that is not ours
|
|
1322
|
+
* stays, in our group or out of it; a hook naming our shim with another root is another
|
|
1323
|
+
* install's. With nothing recorded and nothing of ours on file, the file is not rewritten.
|
|
1151
1324
|
*
|
|
1152
1325
|
* Returns true when the file was actually rewritten, false when it bailed, so uninstall
|
|
1153
1326
|
* can report reality instead of assuming success.
|
|
1154
1327
|
*/
|
|
1155
|
-
export function unwireClaudeSettings(p, added) {
|
|
1156
|
-
|
|
1328
|
+
export function unwireClaudeSettings(p, added, cfg = null) {
|
|
1329
|
+
const recs = (added || []).filter(isDict);
|
|
1330
|
+
if (!recs.length && !cfg) return false;
|
|
1157
1331
|
// Every state but a comment-free object declines: an unwire never rewrites what it could not
|
|
1158
1332
|
// read whole, and a commented file would lose its comments.
|
|
1159
1333
|
const { state, data: loaded, hadComments } = loadJsonObject(p);
|
|
1160
1334
|
if (state !== 'ok' || hadComments) return false;
|
|
1161
1335
|
const hooks = get(loaded, 'hooks');
|
|
1162
1336
|
if (!isDict(hooks)) return false;
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
if (Array.isArray(arr)) {
|
|
1168
|
-
const at = indexOfDeepEqual(arr, group);
|
|
1169
|
-
if (at >= 0) arr.splice(at, 1);
|
|
1170
|
-
}
|
|
1171
|
-
arr = get(hooks, event);
|
|
1172
|
-
if (Array.isArray(arr) && !arr.length) delete hooks[event];
|
|
1173
|
-
}
|
|
1337
|
+
let changed = false;
|
|
1338
|
+
for (const rec of recs) if (dropRecorded(hooks, rec, () => false)) changed = true;
|
|
1339
|
+
if (cfg && rewriteOwn(hooks, cfg, () => null)) changed = true;
|
|
1340
|
+
if (!recs.length && !changed) return false;
|
|
1174
1341
|
if (!Object.keys(hooks).length) delete loaded.hooks;
|
|
1175
1342
|
try {
|
|
1176
1343
|
atomicWriteJson(p, loaded);
|
|
@@ -1350,18 +1517,25 @@ export function settingsIntegrityCheck(p, managed, expect = 'present') {
|
|
|
1350
1517
|
|
|
1351
1518
|
const presentGroups = settingsHookGroups(loaded);
|
|
1352
1519
|
const recordedHooks = (get(m, 'settings_hooks') || []).filter(isDict);
|
|
1353
|
-
//
|
|
1354
|
-
//
|
|
1355
|
-
//
|
|
1356
|
-
//
|
|
1520
|
+
// BY HANDLER, not by group: a recorded group is on file when each of its Geneseed handlers'
|
|
1521
|
+
// commands still runs under that event, whatever else the user did to the group (a `timeout`
|
|
1522
|
+
// on our handler, a hook of their own beside it). A recorded group naming no shim — an older
|
|
1523
|
+
// form — keeps the whole-group comparison.
|
|
1524
|
+
const key = (event, h) => `${formatRepr(event ?? null)}\u0000${h.command}`;
|
|
1525
|
+
const onFile = new Set(presentGroups.flatMap(([event, g]) => (handlersOf(g) || [])
|
|
1526
|
+
.filter((h) => isDict(h) && typeof get(h, 'command') === 'string').map((h) => key(event, h))));
|
|
1527
|
+
const recordedCommands = new Set();
|
|
1357
1528
|
for (const rec of recordedHooks) {
|
|
1358
1529
|
const event = get(rec, 'event');
|
|
1359
1530
|
const group = get(rec, 'group');
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1531
|
+
const ours = (handlersOf(group) || []).filter(shimMarked);
|
|
1532
|
+
for (const h of ours) recordedCommands.add(key(event, h));
|
|
1533
|
+
const whole = () => presentGroups.some(([e, g]) => deepEquals(e, event) && deepEquals(g, group));
|
|
1534
|
+
const live = ours.filter((h) => onFile.has(key(event, h))).length;
|
|
1535
|
+
if (expect === 'present' && !(ours.length ? live === ours.length : whole())) {
|
|
1362
1536
|
problems.push(`${p}: recorded hook group missing — event=${formatRepr(event ?? null)} `
|
|
1363
1537
|
+ `group=${jsonDumpsCompact(group ?? null)}`);
|
|
1364
|
-
} else if (expect === 'absent' &&
|
|
1538
|
+
} else if (expect === 'absent' && (ours.length ? live > 0 : whole())) {
|
|
1365
1539
|
problems.push(`${p}: recorded hook group still present after unwire — `
|
|
1366
1540
|
+ `event=${formatRepr(event ?? null)} group=${jsonDumpsCompact(group ?? null)}`);
|
|
1367
1541
|
}
|
|
@@ -1379,19 +1553,13 @@ export function settingsIntegrityCheck(p, managed, expect = 'present') {
|
|
|
1379
1553
|
}
|
|
1380
1554
|
}
|
|
1381
1555
|
|
|
1382
|
-
// Geneseed-PATTERN
|
|
1556
|
+
// Geneseed-PATTERN handlers present but not among the recorded commands — warn only, never
|
|
1383
1557
|
// auto-delete (they may be user-authored, or a claim this run legitimately did not
|
|
1384
1558
|
// inherit).
|
|
1385
|
-
const recordedSet = new Set(recordedHooks.map(
|
|
1386
|
-
(r) => `${formatRepr(get(r, 'event') ?? null)}\u0000`
|
|
1387
|
-
+ `${jsonDumpsCompact(get(r, 'group') ?? null, { sortKeys: true })}`));
|
|
1388
1559
|
for (const [event, group] of presentGroups) {
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
.map((h) => (has(h, 'command') ? h.command : ''));
|
|
1393
|
-
if (cmds.some((c) => typeof c === 'string'
|
|
1394
|
-
&& GENESEED_HOOK_SNIFF.some((mk) => c.includes(mk)))) {
|
|
1560
|
+
if ((handlersOf(group) || []).some((h) => isDict(h) && typeof get(h, 'command') === 'string'
|
|
1561
|
+
&& GENESEED_HOOK_SNIFF.some((mk) => h.command.includes(mk))
|
|
1562
|
+
&& !recordedCommands.has(key(event, h)))) {
|
|
1395
1563
|
problems.push(`${p}: Geneseed-pattern hook present but NOT recorded in the manifest `
|
|
1396
1564
|
+ `(event=${formatRepr(event)}) — possibly user-authored; left alone`);
|
|
1397
1565
|
}
|
package/js/hosts/shim.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import path from 'node:path';
|
|
21
21
|
import os from 'node:os';
|
|
22
22
|
import { readText, isOsError } from '../lib/fs.mjs';
|
|
23
|
-
import { expanduser } from './hosts.mjs';
|
|
23
|
+
import { SHIM_MARK, expanduser } from './hosts.mjs';
|
|
24
24
|
import { isFile } from './hooks-prims.mjs';
|
|
25
25
|
|
|
26
26
|
/** The checkout this module ships in — `js/build/source.mjs`'s `ROOT`, computed locally so the
|
|
@@ -34,9 +34,9 @@ const ROOT = path.resolve(import.meta.dirname, '../..');
|
|
|
34
34
|
// echo, a "created ~/.geneseed" notice — corrupts that JSON and the gate stops gating
|
|
35
35
|
// while still reporting success. Hence `@echo off`, and a shim that prints nothing.
|
|
36
36
|
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
export
|
|
37
|
+
// `SHIM_MARK` is declared in ./hosts.mjs, beside the handler test that reads it (`ownHookVerb`):
|
|
38
|
+
// this module imports hosts.mjs, never the reverse.
|
|
39
|
+
export { SHIM_MARK };
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* `_build_settings._SHIM_ARGV` — the tokens in a shim body that are NOT paths.
|