geneseed 5.2.0 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/README.md +4 -4
- package/SHIPPED.md +1 -1
- 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/plugins/geneseed-activity.js +20 -21
- package/adapters/opencode/plugins/geneseed-context.js +224 -71
- package/adapters/opencode/plugins/geneseed-guard.js +420 -203
- package/adapters/opencode/plugins/geneseed-workflow.js +3 -2
- package/adapters/opencode/workflows/_runtime.js +3 -2
- package/bin/geneseed-cli.mjs +61 -16
- package/bin/geneseed-hook.mjs +94 -12
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/exclusions.md +2 -2
- package/docs/concepts/factories.md +40 -6
- package/docs/concepts/footprint.md +11 -1
- package/docs/concepts/foreman-mode.md +2 -2
- package/docs/concepts/hook-gates.md +3 -3
- package/docs/concepts/host-matrix.md +22 -4
- package/docs/concepts/loop-gates.md +1 -1
- package/docs/concepts/loops.md +2 -2
- package/docs/concepts/shared-tier.md +1 -1
- package/docs/design-history.md +148 -0
- package/docs/extending.md +97 -163
- package/docs/guides/install-bob.md +2 -2
- package/docs/guides/install-openclaude.md +1 -1
- package/docs/guides/run-a-factory.md +15 -2
- package/docs/guides/upgrade.md +2 -2
- package/docs/guides/verify.md +12 -0
- package/docs/reference/environment.md +1 -0
- package/docs/reference/factory-actions.md +6 -5
- package/docs/reference/troubleshoot-doctor.md +1 -1
- package/docs/reference/troubleshoot-update.md +1 -1
- package/docs/token-footprint.md +66 -2
- 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 +1 -1
- package/docs/understand/machine-bob.md +1 -1
- package/docs/web-ui.md +21 -3
- package/harness.config.json +1 -1
- package/js/README.md +7 -5
- package/js/build/args.mjs +4 -4
- package/js/build/driver.mjs +1 -1
- package/js/build/emit-claude.mjs +1 -1
- package/js/build/generate.mjs +5 -14
- package/js/build/render.mjs +44 -24
- package/js/cli-table.json +135 -59
- package/js/factory/cli.mjs +24 -5
- package/js/factory/graph.mjs +13 -9
- package/js/factory/metrics.mjs +93 -0
- package/js/factory/registry.mjs +37 -12
- package/js/factory/state.mjs +25 -6
- 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 +30 -3
- package/js/hosts/hooks-learn.mjs +47 -16
- package/js/hosts/hooks-prims.mjs +52 -3
- package/js/hosts/hooks.mjs +69 -42
- package/js/hosts/hosts.mjs +80 -12
- package/js/hosts/installs.mjs +7 -0
- package/js/hosts/loss.mjs +6 -1
- package/js/hosts/native.mjs +14 -5
- package/js/hosts/owned.mjs +7 -6
- package/js/hosts/ownership-gate.mjs +14 -1
- package/js/hosts/settings.mjs +245 -103
- package/js/hosts/shim.mjs +4 -4
- package/js/hosts/usage.mjs +9 -3
- 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 +16 -1
- package/js/inspect/doctor.mjs +13 -4
- package/js/inspect/excludes.mjs +18 -6
- package/js/inspect/status.mjs +35 -7
- package/js/inspect/validate.mjs +44 -21
- package/js/lib/machine-dir.mjs +1 -1
- package/js/lib/node-floor.mjs +46 -6
- package/js/maintain/uninstall.mjs +70 -17
- package/js/maintain/update.mjs +31 -7
- package/js/ui/cli.mjs +34 -4
- package/js/ui/menu.mjs +1 -1
- package/js/ui/tui.mjs +11 -14
- package/js/web/actions.mjs +3 -9
- package/js/web/api.mjs +28 -10
- package/js/web/daemon.mjs +0 -1
- package/js/web/server.mjs +1 -0
- package/js/web/state.mjs +37 -16
- package/package.json +1 -1
- package/src/AGENT.md.tmpl +23 -17
- package/src/agents/_template.md +1 -1
- package/src/agents/advocate.md +1 -1
- package/src/agents/developer.md +12 -3
- package/src/agents/empiricist.md +1 -1
- package/src/agents/framer.md +1 -1
- package/src/agents/historian.md +1 -1
- package/src/agents/operator.md +1 -1
- package/src/agents/pragmatist.md +1 -1
- package/src/agents/researcher.md +1 -1
- package/src/agents/skeptic.md +1 -1
- package/src/agents/steward.md +1 -1
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/bricks/intake.md +10 -3
- package/src/bricks/retro.md +13 -3
- package/src/doctrines/comms.md +1 -1
- package/src/doctrines/ops.md +1 -1
- package/src/doctrines/process.md +7 -5
- package/src/factories/analysis-to-build.json +1 -0
- package/src/factories/bug-report-to-fix.json +1 -0
- package/src/factories/issue-to-pr.json +1 -0
- package/src/laws/universal.md +2 -2
- package/src/modes/foreman.md +8 -14
- package/src/skills/commit.md +7 -2
- package/src/skills/debug.md +1 -1
- package/src/skills/diagram-design/SKILL.md +1 -1
- package/src/skills/diagram-design/VENDOR.md +3 -1
- package/src/skills/factory-forge.md +5 -3
- package/src/skills/factory.md +22 -1
- package/src/skills/geneseed.md +1 -1
- package/src/skills/handoff.md +1 -1
- package/src/skills/parallel-agents.md +1 -1
- package/src/skills/pipeline.md +6 -6
- package/src/skills/plan.md +7 -3
- package/src/skills/spring-testing.md +1 -1
- package/themes/biker.json +78 -78
- package/themes/commentator.json +81 -81
- package/themes/cyberpunk.json +79 -79
- package/themes/gamer.json +77 -77
- package/themes/imperial.json +82 -82
- package/themes/joker.json +79 -79
- package/themes/marvin.json +82 -82
- package/themes/mean.json +82 -82
- package/themes/military.json +78 -78
- package/themes/neutral.json +78 -78
- package/themes/pirate.json +79 -79
- package/themes/sports.json +79 -79
- package/themes/verstappen.json +78 -78
- package/themes/wizard.json +79 -79
- package/web/dist/assets/ActiveLoops-BJJN3P-V.js +1 -0
- package/web/dist/assets/Activity-WQ3ykgxU.js +1 -0
- package/web/dist/assets/ActivityDetail-7rt04SkS.js +1 -0
- package/web/dist/assets/{Bonsai-DSwUbavu.js → Bonsai-BBl4XXqs.js} +1 -1
- package/web/dist/assets/{CopyButton-BzRQz7k2.js → CopyButton-Beven8yn.js} +1 -1
- package/web/dist/assets/Dashboard-BgLArtgu.js +2 -0
- package/web/dist/assets/Docs-B5aHp86J.js +5 -0
- package/web/dist/assets/Factories-BjqzXAw8.js +1 -0
- package/web/dist/assets/GreenhouseView-Bce212qd.js +1 -0
- package/web/dist/assets/Installs-B1OsrHXF.js +3 -0
- package/web/dist/assets/JournalView-CV4omyww.js +1 -0
- package/web/dist/assets/Kits-CW1e7xNa.js +1 -0
- package/web/dist/assets/Laws-1Ckf1lbs.js +4 -0
- package/web/dist/assets/LibRows-Dag1s0ZX.js +1 -0
- package/web/dist/assets/Library-B3FuFLel.js +3 -0
- package/web/dist/assets/Loops-CwqgnLNw.js +2 -0
- package/web/dist/assets/Markdown-CxkA7940.js +71 -0
- package/web/dist/assets/OperatorHudView-JmYY1pBR.js +1 -0
- package/web/dist/assets/Personal-DKLgLa7Z.js +2 -0
- package/web/dist/assets/Settings-BwErnh-R.js +1 -0
- package/web/dist/assets/Tabs-8zsyEPSK.js +1 -0
- package/web/dist/assets/index-CRWqKxfY.css +1 -0
- package/web/dist/assets/index-Ce6qF2nG.js +6 -0
- package/web/dist/assets/usePoll-D5c_qIFZ.js +1 -0
- package/web/dist/index.html +2 -2
- package/adapters/claude-code/settings.json +0 -52
- package/web/dist/assets/ActiveLoops-BTHIaRhn.js +0 -1
- package/web/dist/assets/Activity-DlQ30znB.js +0 -1
- package/web/dist/assets/ActivityDetail-CG0mn5fW.js +0 -1
- package/web/dist/assets/Dashboard-Ce3UOsxJ.js +0 -2
- package/web/dist/assets/Docs-CisVnYqv.js +0 -5
- package/web/dist/assets/Factories-Dq5oW4CU.js +0 -1
- package/web/dist/assets/GreenhouseView-y9WAfcc_.js +0 -1
- package/web/dist/assets/Installs-m4GElwFW.js +0 -3
- package/web/dist/assets/JournalView-DeBLRNGc.js +0 -1
- package/web/dist/assets/Kits-DJYVAnyE.js +0 -1
- package/web/dist/assets/Laws-CNpc_8ZV.js +0 -4
- package/web/dist/assets/LibRows-RO5bvXth.js +0 -1
- package/web/dist/assets/Library-Dg0ScciC.js +0 -3
- package/web/dist/assets/Loops-CjEdo-NG.js +0 -2
- package/web/dist/assets/Markdown-0ORz7tAc.js +0 -69
- package/web/dist/assets/OperatorHudView-2ujVMjq1.js +0 -1
- package/web/dist/assets/Personal-D0yS7ahT.js +0 -2
- package/web/dist/assets/Settings-DEN0U8QI.js +0 -1
- package/web/dist/assets/Tabs-But5R6_r.js +0 -1
- package/web/dist/assets/index-Ck42AbRX.js +0 -6
- package/web/dist/assets/index-PG_ukkh6.css +0 -1
- package/web/dist/assets/usePoll-o8ul-Sog.js +0 -1
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
|
/**
|
|
@@ -571,7 +577,7 @@ export function loadJsonObject(p, { strict = false } = {}) {
|
|
|
571
577
|
*
|
|
572
578
|
* `permission` is THREE-STATE, not a boolean: `'add'` for a file with no `permission` key,
|
|
573
579
|
* `'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 —
|
|
580
|
+
* neither. A commented file (`.json` or `.jsonc`) is never rewritten — that is what "your edits are kept" buys —
|
|
575
581
|
* so the only thing this branch can do about a stale block is SAY SO, and telling a file that
|
|
576
582
|
* already has a `permission` key to add one is not saying so. Any other truthy value is read as
|
|
577
583
|
* `'add'`, which is what the boolean callers this replaced meant.
|
|
@@ -646,7 +652,7 @@ export function atomicWriteJson(p, config) {
|
|
|
646
652
|
*
|
|
647
653
|
* `result.skillsAdded` is set to the `permission.skill` denies this call added ONLY when the
|
|
648
654
|
* 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
|
|
655
|
+
* every path that wrote nothing — unreadable, not an object, commented, write
|
|
650
656
|
* failure — so the caller keeps its previous record rather than claiming denies never written.
|
|
651
657
|
* `result.bashGates` (the next `bash_gates`, from `oldGates`) follows the same rule.
|
|
652
658
|
* `pruneGates` is `--prune-gates`: see `reconcileOpencodePermission`. */
|
|
@@ -771,7 +777,10 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
771
777
|
result.bashGates = [...gates];
|
|
772
778
|
return target;
|
|
773
779
|
}
|
|
774
|
-
|
|
780
|
+
// ⚠ THE COMMENTS DECIDE, NOT THE EXTENSION. OpenCode reads `opencode.json` as JSONC too, so a
|
|
781
|
+
// commented plain `.json` is as much the user's prose as a `.jsonc`; this once tested the
|
|
782
|
+
// extension as well, and such a file was rewritten with its comments dropped.
|
|
783
|
+
if (hadComments) {
|
|
775
784
|
// Named, since this branch cannot take them out; `bash_gates` keeps its old value (the
|
|
776
785
|
// caller's rule for a merge that wrote nothing), so they are still ours on the next emit.
|
|
777
786
|
if (gatesRemoved.length) {
|
|
@@ -787,7 +796,7 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
787
796
|
// whole one; `reconcile` = there is a block and it is missing gates this build wires, and
|
|
788
797
|
// this branch cannot write them because rewriting would drop the user's comments.
|
|
789
798
|
//
|
|
790
|
-
// DECIDED, NOT DEFERRED: a commented
|
|
799
|
+
// DECIDED, NOT DEFERRED: a commented file is never rewritten and never will be. A
|
|
791
800
|
// comment-preserving JSONC writer is a parser, an AST and a printer — a dependency-free
|
|
792
801
|
// one, since this package ships zero — to keep formatting nobody asked us to touch, in a
|
|
793
802
|
// file Geneseed co-owns rather than owns. The advice above is the whole remedy: the exact
|
|
@@ -817,6 +826,17 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
817
826
|
// gate does not drive a cell through a real fs failure — it exercises the branch with an
|
|
818
827
|
// injectable failure instead and compares everything except the OS's own wording.
|
|
819
828
|
|
|
829
|
+
/**
|
|
830
|
+
* What an OpenClaude gate prints when it could not start: the ask the gates themselves print
|
|
831
|
+
* (`askDecision`), with a fixed reason. It is written into a hook command between single quotes
|
|
832
|
+
* (`claudeHookGroups`), so the text may hold no `'`, and no `$` or backtick either, which a
|
|
833
|
+
* later edit to double quotes would expand. `tests/unit/hook_form.test.mjs` holds it to that.
|
|
834
|
+
*/
|
|
835
|
+
export const GATE_DOWN = askDecision('Geneseed gate error: the gate did not start, so nothing judged this call.\n'
|
|
836
|
+
+ 'Safe choice: Deny, then run geneseed doctor.\n'
|
|
837
|
+
+ 'It asks because a gate that did not run cannot say this call is safe.\n'
|
|
838
|
+
+ 'If you allow it, this call runs with no check at all.').trimEnd();
|
|
839
|
+
|
|
820
840
|
/**
|
|
821
841
|
* `_build_settings._claude_hook_groups` — Geneseed's Claude hooks, keyed by event.
|
|
822
842
|
*
|
|
@@ -828,8 +848,8 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
828
848
|
* and gains `--no-consent`, which skips only the process-5 branch. It once DROPPED the whole
|
|
829
849
|
* group instead, and Law IV went with it — on Claude only, since Bob carries it
|
|
830
850
|
* through `tool-gate`. The command changing is also what re-wires an existing install:
|
|
831
|
-
* `mergeClaudeSettings`
|
|
832
|
-
*
|
|
851
|
+
* `mergeClaudeSettings` replaces this install's handler in each slot with the one returned
|
|
852
|
+
* here, and removes a handler of ours that no slot here accounts for.
|
|
833
853
|
*
|
|
834
854
|
* ⚠ WHAT THIS DOES **NOT** CLAIM, because it was written here once and it was false: that the
|
|
835
855
|
* string `process 5` is absent from a pack-off bundle. It is not — 18 emitted files still cite
|
|
@@ -865,8 +885,8 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
865
885
|
// `git-gate` read it, `learn` reads `--memory`'s parent. `rule-gate` and Bob's `tool-gate`
|
|
866
886
|
// do not stand down: both still run once per install (host-compat B4 fixed only the three).
|
|
867
887
|
if (host === 'bob') {
|
|
868
|
-
// BOB'S OWN HOOK CONTRACT, per its hooks doc and 2.0.2 changelog
|
|
869
|
-
//
|
|
888
|
+
// BOB'S OWN HOOK CONTRACT, per its hooks doc and 2.0.2 changelog:
|
|
889
|
+
// FIVE events — SessionStart, UserPromptSubmit,
|
|
870
890
|
// PreToolUse, PostToolUse, Stop — Claude's names, but NOT Claude's protocol. stdout is
|
|
871
891
|
// read as context on SessionStart only; on PreToolUse it is ignored and the one way to
|
|
872
892
|
// refuse a call is EXIT CODE 2. The groups this emit wrote before were Claude's whole
|
|
@@ -874,18 +894,18 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
874
894
|
// here; the activity writer counts a compaction on SessionStart `compact`), and the gates answered with a
|
|
875
895
|
// stdout JSON Bob never reads — permissive on every call. `--host bob` makes the gates
|
|
876
896
|
// speak exit codes (js/hosts/hooks.mjs). DELIBERATELY no matcher on PreToolUse
|
|
877
|
-
// (host-compat O1, revisited):
|
|
897
|
+
// (host-compat O1, revisited): the tool list in Bob's docs is already stale against the
|
|
878
898
|
// changelog (`web_fetch`, the 2.1.0 Office/IBM-docs tools are undocumented there), so an
|
|
879
899
|
// allow-list matcher built from it fails OPEN on every tool Bob adds between one
|
|
880
900
|
// docs read and the next — the exact failure mode a gate must not have. A deny-list
|
|
881
901
|
// with a negative-lookahead was the other shape considered; it depends on an unverified
|
|
882
|
-
// regex DIALECT (
|
|
902
|
+
// regex DIALECT (Bob's docs never state whether their "regex on the tool name" supports
|
|
883
903
|
// 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
|
-
//
|
|
904
|
+
// merely skip spawning it. The matcher's upside is low,
|
|
905
|
+
// performance only — not worth either risk. So `tool-gate` reads the payload's shape
|
|
906
|
+
// instead. The gates read Claude's fields (`command`, `file_path`/`path`,
|
|
907
|
+
// `content`/`new_string`) and defer on anything else. What was checked against Bob itself:
|
|
908
|
+
// docs/concepts/host-matrix.md, "What is verified". Revisit a matcher only
|
|
889
909
|
// once a live Bob session can confirm both the current tool list and the regex dialect.
|
|
890
910
|
const b = ' --host bob';
|
|
891
911
|
// `--no-deletion-gate` only when the install switched Law IV's gate off, so an armed
|
|
@@ -900,15 +920,21 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
900
920
|
// External Gate's hook and the weakened-test note, the same contract.
|
|
901
921
|
const eg = externalGate === false ? ' --no-external-gate' : '';
|
|
902
922
|
const tn = testNote === false ? ' --no-test-note' : '';
|
|
923
|
+
const nc = consentRuleOn(doctrines, excluded) ? '' : ' --no-consent';
|
|
903
924
|
return {
|
|
904
925
|
SessionStart: [{ hooks: [{ type: 'command', command: `${run} context --root "${cfg}"${b} || exit 0` }] }],
|
|
905
|
-
// One group, both gates
|
|
906
|
-
//
|
|
907
|
-
//
|
|
908
|
-
//
|
|
909
|
-
//
|
|
910
|
-
//
|
|
911
|
-
|
|
926
|
+
// One group, both gates. `tool-gate` EXITS 2 for Laws I and IV (unless built
|
|
927
|
+
// `--no-secrets-gate` / `--no-deletion-gate`), a write to the rule store (process 1), a
|
|
928
|
+
// write under a project's own `.geneseed/protected-checks.txt` (the project opted in)
|
|
929
|
+
// and a recursive scan rooted at a whole filesystem (ops 2, the root-scan check).
|
|
930
|
+
// Process 5's consent is only a stderr line here, since Bob has no ask tier; with the
|
|
931
|
+
// rule off that line had no rule behind it, so `--no-consent` drops it as it drops
|
|
932
|
+
// Claude's ask. Only then: an armed install's command stays byte-identical, and an older
|
|
933
|
+
// shim, which refuses the flag on this verb, never sees it.
|
|
934
|
+
// NO LAUNCH-FAILURE TAIL, unlike OpenClaude's gates below. Bob ignores a PreToolUse hook's
|
|
935
|
+
// stdout, so a printed ask says nothing; the one refusal is exit 2, and a tail that exits
|
|
936
|
+
// 2 whenever the shim cannot start would lock out every tool with no prompt to lift it.
|
|
937
|
+
PreToolUse: [{ hooks: [{ type: 'command', command: `${run} tool-gate --root "${cfg}"${b}${nc}${sg}${dg}${og}${eg}${tn}${ruleFlags('tool-gate', doctrines, excluded)}` }] }],
|
|
912
938
|
// Bob's Stop payload never carries `transcript_path` (I2) — `learn` reads `--host bob`
|
|
913
939
|
// and returns immediately rather than wasting a model call on the bare envelope. KEPT
|
|
914
940
|
// rather than DROPPED: the stand-down costs nothing (no transcript read, no spawn), and
|
|
@@ -928,9 +954,20 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
928
954
|
// `--host` on `git-gate` but not on `learn`, which then exits 1 under `|| exit 0` and skips.
|
|
929
955
|
const h = host === 'openclaude' ? ' --host openclaude' : '';
|
|
930
956
|
const context = `${run} context --root "${cfg}"${h} || exit 0`;
|
|
957
|
+
// A GATE THAT CANNOT START MUST NOT READ AS "NOTHING TO SAY". Claude Code blocks on it
|
|
958
|
+
// (`onFailure` below). OpenClaude predates that field: a shim that is gone or a node that
|
|
959
|
+
// will not load exits non-zero with stdout empty, which it takes as a deferral, and every
|
|
960
|
+
// call goes through unjudged. So its two gates print a static ask in that case
|
|
961
|
+
// (`GATE_DOWN`). `||` and `printf` are safe to write because OpenClaude always runs its hooks
|
|
962
|
+
// under Git Bash or sh; a gate that ran has exited 0 on every path, so the tail never adds to
|
|
963
|
+
// a verdict. Never on Claude (byte-identical, and PowerShell 5.1 cannot parse `||`), never on
|
|
964
|
+
// the `Skill|Agent|Task` counter (a counter that cannot start must not ask), never on Bob
|
|
965
|
+
// (see its PreToolUse above).
|
|
966
|
+
const down = host === 'openclaude' ? ` || printf '%s' '${GATE_DOWN}'` : '';
|
|
931
967
|
const gate = `${run} git-gate --root "${cfg}"${h}${consentRuleOn(doctrines, excluded) ? '' : ' --no-consent'}`
|
|
932
968
|
+ (deletionGate === false ? ' --no-deletion-gate' : '')
|
|
933
|
-
+ (externalGate === false ? ' --no-external-gate' : '') + ruleFlags('git-gate', doctrines, excluded)
|
|
969
|
+
+ (externalGate === false ? ' --no-external-gate' : '') + ruleFlags('git-gate', doctrines, excluded)
|
|
970
|
+
+ down;
|
|
934
971
|
// `--no-secrets-gate` skips only rule-gate's credential scan (rigor 5 and process 1 still
|
|
935
972
|
// run); `--no-done-gate` only learn's done check, never the distillation. One `learn` string
|
|
936
973
|
// feeds Stop, SubagentStop and PreCompact, and the flag sits before `|| exit 0`.
|
|
@@ -940,7 +977,8 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
940
977
|
const ruleGate = `${run} rule-gate --root "${cfg}"${secretsGate === false ? ' --no-secrets-gate' : ''}`
|
|
941
978
|
+ (ownershipGate === false ? ' --no-ownership-gate' : '')
|
|
942
979
|
+ (externalGate === false ? ' --no-external-gate' : '')
|
|
943
|
-
+ (testNote === false ? ' --no-test-note' : '') + ruleFlags('rule-gate', doctrines, excluded)
|
|
980
|
+
+ (testNote === false ? ' --no-test-note' : '') + ruleFlags('rule-gate', doctrines, excluded)
|
|
981
|
+
+ down;
|
|
944
982
|
// `--no-rule-store` on learn: with process 1 off a rule write runs with no prompt, so the change
|
|
945
983
|
// report must not count it as approved (`storeReport`). Bob's learn reports every change already.
|
|
946
984
|
const learn = `${run} learn ${mem}${h}${doneGate === false ? ' --no-done-gate' : ''}`
|
|
@@ -960,9 +998,11 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
960
998
|
// `Bash|PowerShell`, not `Bash` alone (Claude verdict I1): docs `hooks.md` says a hook
|
|
961
999
|
// that matches only `Bash` never fires on the PowerShell tool, which is Windows' default
|
|
962
1000
|
// shell whenever Git Bash is absent — and on Windows without Git Bash, Bash is not even
|
|
963
|
-
// registered. `
|
|
964
|
-
//
|
|
965
|
-
|
|
1001
|
+
// registered. `|Monitor` because Claude Code's Monitor tool runs a shell `command` in the
|
|
1002
|
+
// background, and unmatched it was a shell no gate saw. `tool_input.command` is the same
|
|
1003
|
+
// field on all three, so `GIT_GATE_RE` needs no change; a host without the tool never
|
|
1004
|
+
// sends the name.
|
|
1005
|
+
{ matcher: 'Bash|PowerShell|Monitor', hooks: [{ type: 'command', command: gate, ...onFailureBlock }] },
|
|
966
1006
|
{
|
|
967
1007
|
// No `MultiEdit`: it is not in Claude Code's tool table (tools-reference.md) — a dead
|
|
968
1008
|
// matcher entry (Claude verdict R2).
|
|
@@ -971,8 +1011,9 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
|
|
|
971
1011
|
},
|
|
972
1012
|
// Usage counting (js/hosts/usage.mjs): `tool-gate` records a Skill or subagent call and
|
|
973
1013
|
// 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
|
-
|
|
1014
|
+
// `onFailure: 'block'`: a counter that cannot start must never stop a skill. `--host` on
|
|
1015
|
+
// OpenClaude, or the activity view files its skill and agent calls under Claude.
|
|
1016
|
+
{ matcher: 'Skill|Agent|Task', hooks: [{ type: 'command', command: `${run} tool-gate --root "${cfg}"${h}` }] },
|
|
976
1017
|
],
|
|
977
1018
|
// One matcher-less group, not a `startup|clear` / `resume|compact` split (Claude verdict
|
|
978
1019
|
// I4): every SessionStart source — `startup`, `resume`, `clear`, `compact` and `fork` —
|
|
@@ -1076,14 +1117,96 @@ function readSettingsForMerge(p, consequence) {
|
|
|
1076
1117
|
return [data, hadComments];
|
|
1077
1118
|
}
|
|
1078
1119
|
|
|
1120
|
+
/** Is this handler Geneseed's, for the install at `cfg`? `ownHookVerb` (./hosts.mjs) says how. */
|
|
1121
|
+
export function ownHandler(h, cfg) {
|
|
1122
|
+
return isDict(h) && ownHookVerb(get(h, 'command'), cfg) !== null;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/** A handler whose command names the shim, whatever root it carries. */
|
|
1126
|
+
const shimMarked = (h) => isDict(h) && typeof get(h, 'command') === 'string'
|
|
1127
|
+
&& h.command.includes(SHIM_MARK);
|
|
1128
|
+
|
|
1129
|
+
/** A group's handler list, or null for a value that is not a group. */
|
|
1130
|
+
const handlersOf = (g) => (isDict(g) && Array.isArray(get(g, 'hooks')) ? g.hooks : null);
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Take one RECORDED group out of `hooks`, found as the manifest recorded it. True when something
|
|
1134
|
+
* went.
|
|
1135
|
+
*
|
|
1136
|
+
* A claim is the group as it sat on file, so it can hold a handler the user put inside our
|
|
1137
|
+
* group. That one stays: only the handlers naming the shim go (minus those `keep` spares), and
|
|
1138
|
+
* the group goes when nothing is left. A recorded group with no shim handler at all is an older
|
|
1139
|
+
* form (a 1.x interpreter command) and goes whole, as the manifest says.
|
|
1140
|
+
*/
|
|
1141
|
+
function dropRecorded(hooks, rec, keep) {
|
|
1142
|
+
const event = get(rec, 'event');
|
|
1143
|
+
const arr = get(hooks, event);
|
|
1144
|
+
if (!Array.isArray(arr)) return false;
|
|
1145
|
+
const at = indexOfDeepEqual(arr, get(rec, 'group'));
|
|
1146
|
+
if (at < 0) return false;
|
|
1147
|
+
const hs = handlersOf(arr[at]);
|
|
1148
|
+
const left = hs && hs.some(shimMarked) ? hs.filter((h) => !shimMarked(h) || keep(h)) : [];
|
|
1149
|
+
if (left.length && left.length === hs.length) return false;
|
|
1150
|
+
if (left.length) arr[at].hooks = left;
|
|
1151
|
+
else arr.splice(at, 1);
|
|
1152
|
+
if (!arr.length) delete hooks[event];
|
|
1153
|
+
return true;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* Walk every handler of the install at `cfg` (`ownHandler`) and put `decide(event, group, h)` in
|
|
1158
|
+
* its place: the handler itself (unchanged), a replacement, or null to remove it. A group goes
|
|
1159
|
+
* only when this emptied it, an event only when its last group went. No other handler is read
|
|
1160
|
+
* past the ownership test, in our group or out of it. True when anything changed.
|
|
1161
|
+
*/
|
|
1162
|
+
function rewriteOwn(hooks, cfg, decide) {
|
|
1163
|
+
let changed = false;
|
|
1164
|
+
for (const [event, arr] of Object.entries(hooks)) {
|
|
1165
|
+
if (!Array.isArray(arr)) continue;
|
|
1166
|
+
const emptied = new Set();
|
|
1167
|
+
for (const g of arr) {
|
|
1168
|
+
const hs = handlersOf(g);
|
|
1169
|
+
if (!hs) continue;
|
|
1170
|
+
const next = [];
|
|
1171
|
+
for (const h of hs) {
|
|
1172
|
+
const to = ownHandler(h, cfg) ? decide(event, g, h) : h;
|
|
1173
|
+
if (to) next.push(to);
|
|
1174
|
+
if (to !== h) changed = true;
|
|
1175
|
+
}
|
|
1176
|
+
if (next.length === hs.length && next.every((h, i) => h === hs[i])) continue;
|
|
1177
|
+
g.hooks = next;
|
|
1178
|
+
if (!next.length) emptied.add(g);
|
|
1179
|
+
}
|
|
1180
|
+
if (!emptied.size) continue;
|
|
1181
|
+
const kept = arr.filter((g) => !emptied.has(g));
|
|
1182
|
+
if (kept.length) hooks[event] = kept;
|
|
1183
|
+
else delete hooks[event];
|
|
1184
|
+
}
|
|
1185
|
+
return changed;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1079
1188
|
/**
|
|
1080
1189
|
* `_build_settings._merge_claude_settings` — returns `[target, managed]`.
|
|
1081
1190
|
*
|
|
1082
|
-
* Surgical: every other key
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1086
|
-
* `
|
|
1191
|
+
* Surgical, and PER HANDLER: every other key, the user's own groups and a user's handler inside
|
|
1192
|
+
* one of our groups survive. Each canonical group is one slot (event, matcher, verb). The
|
|
1193
|
+
* handler of this install that fills a slot (`ownHandler`) is replaced where it sits, as
|
|
1194
|
+
* `{...existing, ...canonical}`, so a field the user added to it (`timeout`) stays; `shell` and
|
|
1195
|
+
* `onFailure` are ours and go when the canonical handler has none. A handler of ours that fills
|
|
1196
|
+
* no slot, or a slot already filled, is removed: that is what stops a re-emit with other gate
|
|
1197
|
+
* flags, a retired event or a widened matcher from leaving the old handler beside the new one,
|
|
1198
|
+
* with or without a manifest. A slot nothing fills is appended as the canonical group.
|
|
1199
|
+
*
|
|
1200
|
+
* `managed` is the claim set: every group that now holds one of our handlers, AS IT SITS ON FILE
|
|
1201
|
+
* after the merge, so a group that was already there is claimed too and unwire removes it.
|
|
1202
|
+
*
|
|
1203
|
+
* `priorHooks` is the manifest's previously-recorded groups. One no longer canonical and still
|
|
1204
|
+
* on file loses its shim handlers that are not this root's — a moved `--root`, which the
|
|
1205
|
+
* signature cannot see, since another root reads as another install.
|
|
1206
|
+
*
|
|
1207
|
+
* REFUSED, NEVER OVERWRITTEN: a `hooks` that is not an object, or a canonical event whose value
|
|
1208
|
+
* is not an array (`"Stop": {}`). Both are the user's, however wrong, and writing our groups
|
|
1209
|
+
* there would replace them — `readSettingsForMerge`'s rule, one level down.
|
|
1087
1210
|
*
|
|
1088
1211
|
* `cfgDir` is the install's own dir — what the hooks carry as `--root` and under which
|
|
1089
1212
|
* `memory/` lives. It is NOT always `dirname(p)`: Bob's global settings file is nested
|
|
@@ -1097,80 +1220,98 @@ export function mergeClaudeSettings(p, priorHooks = null, hookOpts = {},
|
|
|
1097
1220
|
const loaded = readSettingsForMerge(p, 'Hooks were not wired.');
|
|
1098
1221
|
if (!loaded) return [p, prior];
|
|
1099
1222
|
const [config, hadComments] = loaded;
|
|
1100
|
-
let hooks = get(config, 'hooks');
|
|
1101
|
-
if (!isDict(hooks)) hooks = {};
|
|
1102
1223
|
const canonical = claudeHookGroups(cfgDir, hookOpts, doctrines, excluded, host, gates);
|
|
1224
|
+
const refuse = (what) => {
|
|
1225
|
+
process.stderr.write(`[geneseed] ${what} in ${path.basename(p)} — NOT rewriting it `
|
|
1226
|
+
+ '(fix the file, then re-run). Hooks were not wired.\n');
|
|
1227
|
+
return [p, prior];
|
|
1228
|
+
};
|
|
1229
|
+
if (has(config, 'hooks') && !isDict(config.hooks)) return refuse('"hooks" is not an object');
|
|
1230
|
+
const hooks = has(config, 'hooks') ? config.hooks : {};
|
|
1231
|
+
const bad = Object.keys(canonical).find((e) => has(hooks, e) && !Array.isArray(hooks[e]));
|
|
1232
|
+
if (bad) return refuse(`"hooks.${bad}" is not an array`);
|
|
1233
|
+
|
|
1234
|
+
// One slot per canonical group: `claudeHookGroups` puts exactly one handler in each.
|
|
1235
|
+
const slots = [];
|
|
1103
1236
|
const canonFlat = [];
|
|
1104
1237
|
for (const [event, groups] of Object.entries(canonical)) {
|
|
1105
|
-
for (const g of groups)
|
|
1238
|
+
for (const g of groups) {
|
|
1239
|
+
canonFlat.push({ event, group: g });
|
|
1240
|
+
slots.push({ event, canon: g, matcher: get(g, 'matcher'), handler: g.hooks[0],
|
|
1241
|
+
verb: ownHookVerb(g.hooks[0].command, cfgDir), group: null });
|
|
1242
|
+
}
|
|
1106
1243
|
}
|
|
1107
|
-
let
|
|
1244
|
+
let changed = false;
|
|
1108
1245
|
for (const rec of prior) {
|
|
1109
1246
|
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
|
-
}
|
|
1247
|
+
if (dropRecorded(hooks, rec, (h) => ownHandler(h, cfgDir))) changed = true;
|
|
1121
1248
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1249
|
+
if (rewriteOwn(hooks, cfgDir, (event, g, h) => {
|
|
1250
|
+
const verb = ownHookVerb(h.command, cfgDir);
|
|
1251
|
+
const slot = slots.find((s) => !s.group && s.event === event && s.verb === verb
|
|
1252
|
+
&& s.matcher === get(g, 'matcher'));
|
|
1253
|
+
if (!slot) return null;
|
|
1254
|
+
slot.group = g;
|
|
1255
|
+
const merged = { ...h, ...slot.handler };
|
|
1256
|
+
for (const k of ['shell', 'onFailure']) if (!has(slot.handler, k)) delete merged[k];
|
|
1257
|
+
return deepEquals(merged, h) ? h : merged;
|
|
1258
|
+
})) changed = true;
|
|
1259
|
+
for (const s of slots) {
|
|
1260
|
+
if (s.group) continue;
|
|
1261
|
+
let arr = get(hooks, s.event);
|
|
1262
|
+
if (!Array.isArray(arr)) arr = hooks[s.event] = [];
|
|
1263
|
+
// A command the signature cannot read (no shim could be written and the fallback entry is
|
|
1264
|
+
// not named after it) is still found by equality, the old test.
|
|
1265
|
+
const at = s.verb ? -1 : indexOfDeepEqual(arr, s.canon);
|
|
1266
|
+
if (at < 0) {
|
|
1267
|
+
arr.push(s.canon);
|
|
1268
|
+
changed = true;
|
|
1130
1269
|
}
|
|
1131
|
-
|
|
1270
|
+
s.group = at < 0 ? s.canon : arr[at];
|
|
1132
1271
|
}
|
|
1133
|
-
const
|
|
1134
|
-
const managedNow =
|
|
1135
|
-
|
|
1272
|
+
const claimed = [...new Set(slots.map((s) => s.group))];
|
|
1273
|
+
const managedNow = claimed.map((group) => ({
|
|
1274
|
+
event: slots.find((s) => s.group === group).event, group }));
|
|
1275
|
+
if (!changed) return [p, managedNow];
|
|
1136
1276
|
if (hadComments) {
|
|
1277
|
+
// The exact groups, not a pointer to a sample: a sample cannot carry this install's shim
|
|
1278
|
+
// path, root or gate flags, and the one that shipped had drifted from the emitter.
|
|
1137
1279
|
process.stderr.write(`[geneseed] ${path.basename(p)} has comments — not rewriting it `
|
|
1138
|
-
+
|
|
1139
|
-
+
|
|
1280
|
+
+ '(your edits are kept). Merge this into it by hand:\n'
|
|
1281
|
+
+ `${JSON.stringify({ hooks: canonical }, null, 2)}\n`);
|
|
1140
1282
|
return [p, prior];
|
|
1141
1283
|
}
|
|
1142
|
-
// Never empty here: `canonical` always carries at least three events, and every one of them
|
|
1143
|
-
// was just written into `hooks`.
|
|
1144
1284
|
config.hooks = hooks;
|
|
1145
1285
|
atomicWriteJson(p, config);
|
|
1146
1286
|
return [p, managedNow];
|
|
1147
1287
|
}
|
|
1148
1288
|
|
|
1149
1289
|
/**
|
|
1150
|
-
* `_build_settings._unwire_claude_settings` — remove
|
|
1290
|
+
* `_build_settings._unwire_claude_settings` — remove the recorded groups (`dropRecorded`), then,
|
|
1291
|
+
* given the install's `cfg`, every handler of that install still on file (`ownHandler`).
|
|
1292
|
+
*
|
|
1293
|
+
* The second pass is what a manifest alone could not do: a handler the user gave a `timeout`
|
|
1294
|
+
* after the emit no longer equals its claim, and one wired by an emit whose manifest was lost
|
|
1295
|
+
* was never claimed. Both would keep running after an uninstall. A handler that is not ours
|
|
1296
|
+
* stays, in our group or out of it; a hook naming our shim with another root is another
|
|
1297
|
+
* install's. With nothing recorded and nothing of ours on file, the file is not rewritten.
|
|
1151
1298
|
*
|
|
1152
1299
|
* Returns true when the file was actually rewritten, false when it bailed, so uninstall
|
|
1153
1300
|
* can report reality instead of assuming success.
|
|
1154
1301
|
*/
|
|
1155
|
-
export function unwireClaudeSettings(p, added) {
|
|
1156
|
-
|
|
1302
|
+
export function unwireClaudeSettings(p, added, cfg = null) {
|
|
1303
|
+
const recs = (added || []).filter(isDict);
|
|
1304
|
+
if (!recs.length && !cfg) return false;
|
|
1157
1305
|
// Every state but a comment-free object declines: an unwire never rewrites what it could not
|
|
1158
1306
|
// read whole, and a commented file would lose its comments.
|
|
1159
1307
|
const { state, data: loaded, hadComments } = loadJsonObject(p);
|
|
1160
1308
|
if (state !== 'ok' || hadComments) return false;
|
|
1161
1309
|
const hooks = get(loaded, 'hooks');
|
|
1162
1310
|
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
|
-
}
|
|
1311
|
+
let changed = false;
|
|
1312
|
+
for (const rec of recs) if (dropRecorded(hooks, rec, () => false)) changed = true;
|
|
1313
|
+
if (cfg && rewriteOwn(hooks, cfg, () => null)) changed = true;
|
|
1314
|
+
if (!recs.length && !changed) return false;
|
|
1174
1315
|
if (!Object.keys(hooks).length) delete loaded.hooks;
|
|
1175
1316
|
try {
|
|
1176
1317
|
atomicWriteJson(p, loaded);
|
|
@@ -1350,18 +1491,25 @@ export function settingsIntegrityCheck(p, managed, expect = 'present') {
|
|
|
1350
1491
|
|
|
1351
1492
|
const presentGroups = settingsHookGroups(loaded);
|
|
1352
1493
|
const recordedHooks = (get(m, 'settings_hooks') || []).filter(isDict);
|
|
1353
|
-
//
|
|
1354
|
-
//
|
|
1355
|
-
//
|
|
1356
|
-
//
|
|
1494
|
+
// BY HANDLER, not by group: a recorded group is on file when each of its Geneseed handlers'
|
|
1495
|
+
// commands still runs under that event, whatever else the user did to the group (a `timeout`
|
|
1496
|
+
// on our handler, a hook of their own beside it). A recorded group naming no shim — an older
|
|
1497
|
+
// form — keeps the whole-group comparison.
|
|
1498
|
+
const key = (event, h) => `${formatRepr(event ?? null)}\u0000${h.command}`;
|
|
1499
|
+
const onFile = new Set(presentGroups.flatMap(([event, g]) => (handlersOf(g) || [])
|
|
1500
|
+
.filter((h) => isDict(h) && typeof get(h, 'command') === 'string').map((h) => key(event, h))));
|
|
1501
|
+
const recordedCommands = new Set();
|
|
1357
1502
|
for (const rec of recordedHooks) {
|
|
1358
1503
|
const event = get(rec, 'event');
|
|
1359
1504
|
const group = get(rec, 'group');
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1505
|
+
const ours = (handlersOf(group) || []).filter(shimMarked);
|
|
1506
|
+
for (const h of ours) recordedCommands.add(key(event, h));
|
|
1507
|
+
const whole = () => presentGroups.some(([e, g]) => deepEquals(e, event) && deepEquals(g, group));
|
|
1508
|
+
const live = ours.filter((h) => onFile.has(key(event, h))).length;
|
|
1509
|
+
if (expect === 'present' && !(ours.length ? live === ours.length : whole())) {
|
|
1362
1510
|
problems.push(`${p}: recorded hook group missing — event=${formatRepr(event ?? null)} `
|
|
1363
1511
|
+ `group=${jsonDumpsCompact(group ?? null)}`);
|
|
1364
|
-
} else if (expect === 'absent' &&
|
|
1512
|
+
} else if (expect === 'absent' && (ours.length ? live > 0 : whole())) {
|
|
1365
1513
|
problems.push(`${p}: recorded hook group still present after unwire — `
|
|
1366
1514
|
+ `event=${formatRepr(event ?? null)} group=${jsonDumpsCompact(group ?? null)}`);
|
|
1367
1515
|
}
|
|
@@ -1379,19 +1527,13 @@ export function settingsIntegrityCheck(p, managed, expect = 'present') {
|
|
|
1379
1527
|
}
|
|
1380
1528
|
}
|
|
1381
1529
|
|
|
1382
|
-
// Geneseed-PATTERN
|
|
1530
|
+
// Geneseed-PATTERN handlers present but not among the recorded commands — warn only, never
|
|
1383
1531
|
// auto-delete (they may be user-authored, or a claim this run legitimately did not
|
|
1384
1532
|
// 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
1533
|
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)))) {
|
|
1534
|
+
if ((handlersOf(group) || []).some((h) => isDict(h) && typeof get(h, 'command') === 'string'
|
|
1535
|
+
&& GENESEED_HOOK_SNIFF.some((mk) => h.command.includes(mk))
|
|
1536
|
+
&& !recordedCommands.has(key(event, h)))) {
|
|
1395
1537
|
problems.push(`${p}: Geneseed-pattern hook present but NOT recorded in the manifest `
|
|
1396
1538
|
+ `(event=${formatRepr(event)}) — possibly user-authored; left alone`);
|
|
1397
1539
|
}
|
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.
|
package/js/hosts/usage.mjs
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* must never block, slow or change a tool call. It rides `tool-gate`, the verb Bob already runs
|
|
12
12
|
* on every tool and Claude/OpenClaude route their `Skill|Agent|Task` matcher to, so no host pays
|
|
13
13
|
* an extra process for it. The OpenCode guard plugin carries the same rules inline (a plugin
|
|
14
|
-
* cannot import from here)
|
|
14
|
+
* cannot import from here): `NAME_RE` by `tests/twins.mjs`, `usageOf` by hand, since it reads
|
|
15
|
+
* no Bob shape. `tests/unit/usage.test.mjs` holds both to one table.
|
|
15
16
|
*
|
|
16
17
|
* Off when `GENESEED_NO_USAGE` is set or the install holds a `.usage-off` marker.
|
|
17
18
|
*/
|
|
@@ -27,8 +28,10 @@ const NAME_RE = /^[A-Za-z0-9][\w.:@/-]{0,99}$/;
|
|
|
27
28
|
* `{kind, name}` for a skill or subagent call, else null. Reads the Claude shape (`tool_name` /
|
|
28
29
|
* `tool_input`: `Skill` → `skill`, `Agent` or the older `Task` → `subagent_type`), OpenCode's
|
|
29
30
|
* (`skill` → `name`, `task` → `subagent_type`; V2 hooks see the pre-alias `subagent` → `agent`)
|
|
30
|
-
* and
|
|
31
|
-
* tool name is unverified, no Bob
|
|
31
|
+
* and Bob's (`tool` / `input`): `spawn_subagent` → `name`, `start_subtask` → `mode`, and,
|
|
32
|
+
* best-effort, any tool whose name contains "skill" (Bob's skill tool name is unverified, no Bob
|
|
33
|
+
* runs here). A subtask's `title` is never read: it is free text the agent wrote, and this
|
|
34
|
+
* ledger records no prompt. Its mode is the nearest thing Bob has to an agent's name.
|
|
32
35
|
*/
|
|
33
36
|
export function usageOf(payload) {
|
|
34
37
|
if (!payload || typeof payload !== 'object') return null;
|
|
@@ -42,6 +45,9 @@ export function usageOf(payload) {
|
|
|
42
45
|
} else if (tool === 'agent' || tool === 'task' || tool === 'subagent') {
|
|
43
46
|
kind = 'agent';
|
|
44
47
|
name = ti.subagent_type ?? ti.agent;
|
|
48
|
+
} else if (tool === 'spawn_subagent' || tool === 'start_subtask') {
|
|
49
|
+
kind = 'agent';
|
|
50
|
+
name = tool === 'spawn_subagent' ? ti.name : ti.mode;
|
|
45
51
|
}
|
|
46
52
|
if (!kind || typeof name !== 'string') return null;
|
|
47
53
|
name = name.trim().replace(/^\/+/, '');
|