geneseed 4.28.0 → 4.29.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 +41 -0
- package/README.md +4 -2
- package/SHIPPED.md +2 -2
- package/adapters/bob/README.md +1 -1
- package/adapters/claude-code/README.md +4 -2
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +2 -2
- package/adapters/opencode/README.md +18 -2
- package/adapters/opencode/plugins/geneseed-context.js +155 -18
- package/adapters/opencode/plugins/geneseed-guard.js +59 -8
- package/adapters/opencode/plugins/geneseed-workflow.js +18 -1
- package/adapters/opencode/workflows/_runtime.js +14 -3
- package/docs/concepts/enforcement-table.md +5 -4
- package/docs/concepts/exclusions.md +3 -3
- package/docs/concepts/hooks.md +11 -3
- package/docs/concepts/ownership.md +7 -6
- package/docs/concepts/skills.md +1 -0
- package/docs/guides/set-up-ownership.md +22 -6
- package/docs/reference/environment.md +1 -0
- package/docs/reference/plugin-context.md +3 -1
- package/docs/reference/plugin-guard.md +1 -1
- package/docs/understand/enforced-vs-asked.md +3 -3
- package/docs/understand/machine-bob.md +1 -1
- package/docs/understand/machine-claude.md +1 -1
- package/docs/understand/machine-opencode.md +1 -1
- package/harness.config.json +1 -1
- package/js/README.md +3 -1
- package/js/build/driver.mjs +29 -9
- package/js/build/emit-opencode.mjs +12 -10
- package/js/build/render.mjs +9 -0
- package/js/hosts/done-checks.mjs +134 -0
- package/js/hosts/geneseed-dir.mjs +116 -0
- package/js/hosts/hooks-context.mjs +19 -0
- package/js/hosts/hooks-done.mjs +82 -38
- package/js/hosts/hooks-learn.mjs +9 -2
- package/js/hosts/hooks-prims.mjs +4 -0
- package/js/hosts/hooks.mjs +139 -6
- package/js/hosts/hosts.mjs +6 -0
- package/js/hosts/native.mjs +1 -1
- package/js/hosts/owned.mjs +19 -0
- package/js/hosts/ownership-gate.mjs +64 -10
- package/js/hosts/settings.mjs +115 -74
- package/js/inspect/checks-constitution.mjs +5 -1
- package/js/inspect/cost.mjs +1 -1
- package/js/inspect/doctor.mjs +2 -1
- package/js/inspect/inventory.mjs +1 -1
- package/js/inspect/status.mjs +2 -1
- package/js/inspect/validate.mjs +2 -1
- package/js/lib/json.mjs +70 -0
- package/js/maintain/uninstall.mjs +18 -5
- package/js/web/gates-api.mjs +2 -2
- package/package.json +1 -1
- package/registry.json +14 -0
- package/src/AGENT.md.tmpl +2 -2
- package/src/licenses/i-have-adhd.txt +21 -0
- package/src/skills/_checkpoints.md +15 -2
- package/src/skills/adhd.md +40 -0
- package/src/skills/diagram-design/LICENSE +21 -0
- package/src/skills/diagram-design/SKILL.md +392 -0
- package/src/skills/diagram-design/THIRD_PARTY_LICENSES.md +134 -0
- package/src/skills/diagram-design/VENDOR.md +81 -0
- package/src/skills/diagram-design/assets/example-architecture.html +183 -0
- package/src/skills/diagram-design/assets/example-venn.html +110 -0
- package/src/skills/diagram-design/assets/template-dark.html +99 -0
- package/src/skills/diagram-design/assets/template-full.html +421 -0
- package/src/skills/diagram-design/assets/template-motion.html +448 -0
- package/src/skills/diagram-design/assets/template-terminal.html +188 -0
- package/src/skills/diagram-design/assets/template.html +100 -0
- package/src/skills/diagram-design/references/animation.md +135 -0
- package/src/skills/diagram-design/references/layout-budget.md +97 -0
- package/src/skills/diagram-design/references/onboarding.md +368 -0
- package/src/skills/diagram-design/references/output-spec.md +277 -0
- package/src/skills/diagram-design/references/primitive-annotation.md +36 -0
- package/src/skills/diagram-design/references/primitive-icons.md +782 -0
- package/src/skills/diagram-design/references/primitive-sketchy.md +43 -0
- package/src/skills/diagram-design/references/primitive-terminal.md +76 -0
- package/src/skills/diagram-design/references/primitives-core.md +144 -0
- package/src/skills/diagram-design/references/profiles.md +183 -0
- package/src/skills/diagram-design/references/semantic-patterns.md +154 -0
- package/src/skills/diagram-design/references/style-guide.md +232 -0
- package/src/skills/diagram-design/references/type-architecture-delta.md +143 -0
- package/src/skills/diagram-design/references/type-architecture.md +117 -0
- package/src/skills/diagram-design/references/type-axonometric-plan.md +83 -0
- package/src/skills/diagram-design/references/type-bar.md +108 -0
- package/src/skills/diagram-design/references/type-data-flow.md +371 -0
- package/src/skills/diagram-design/references/type-db-schema.md +48 -0
- package/src/skills/diagram-design/references/type-dependency.md +44 -0
- package/src/skills/diagram-design/references/type-deployment.md +45 -0
- package/src/skills/diagram-design/references/type-dp-integration.md +407 -0
- package/src/skills/diagram-design/references/type-dp-security-matrix.md +379 -0
- package/src/skills/diagram-design/references/type-er.md +25 -0
- package/src/skills/diagram-design/references/type-exploded.md +115 -0
- package/src/skills/diagram-design/references/type-fishbone.md +75 -0
- package/src/skills/diagram-design/references/type-flowchart.md +23 -0
- package/src/skills/diagram-design/references/type-gantt.md +45 -0
- package/src/skills/diagram-design/references/type-heatmap.md +80 -0
- package/src/skills/diagram-design/references/type-high-level.md +470 -0
- package/src/skills/diagram-design/references/type-it-state.md +468 -0
- package/src/skills/diagram-design/references/type-journey.md +55 -0
- package/src/skills/diagram-design/references/type-kanban.md +49 -0
- package/src/skills/diagram-design/references/type-layers.md +26 -0
- package/src/skills/diagram-design/references/type-line.md +337 -0
- package/src/skills/diagram-design/references/type-loop.md +223 -0
- package/src/skills/diagram-design/references/type-medallion.md +356 -0
- package/src/skills/diagram-design/references/type-nested.md +22 -0
- package/src/skills/diagram-design/references/type-org-chart.md +44 -0
- package/src/skills/diagram-design/references/type-polar.md +136 -0
- package/src/skills/diagram-design/references/type-process.md +490 -0
- package/src/skills/diagram-design/references/type-pyramid.md +33 -0
- package/src/skills/diagram-design/references/type-quadrant.md +81 -0
- package/src/skills/diagram-design/references/type-radar.md +82 -0
- package/src/skills/diagram-design/references/type-sankey.md +75 -0
- package/src/skills/diagram-design/references/type-scatter.md +276 -0
- package/src/skills/diagram-design/references/type-sequence.md +130 -0
- package/src/skills/diagram-design/references/type-service-blueprint.md +103 -0
- package/src/skills/diagram-design/references/type-state.md +30 -0
- package/src/skills/diagram-design/references/type-story-map.md +46 -0
- package/src/skills/diagram-design/references/type-swimlane.md +22 -0
- package/src/skills/diagram-design/references/type-timeline.md +20 -0
- package/src/skills/diagram-design/references/type-tree.md +24 -0
- package/src/skills/diagram-design/references/type-treemap.md +137 -0
- package/src/skills/diagram-design/references/type-uml-class.md +65 -0
- package/src/skills/diagram-design/references/type-venn.md +26 -0
- package/src/skills/diagram-design/references/type-wardley.md +39 -0
- package/src/skills/diagram-design/references/type-waterfall.md +75 -0
- package/src/skills/document-project.md +4 -1
- package/src/skills/ownership.md +26 -4
- package/src/upstreams.json +14 -0
- package/themes/_TEMPLATE.json +1 -0
- package/themes/biker.json +1 -0
- package/themes/commentator.json +1 -0
- package/themes/cyberpunk.json +1 -0
- package/themes/gamer.json +1 -0
- package/themes/imperial.json +1 -0
- package/themes/joker.json +1 -0
- package/themes/marvin.json +1 -0
- package/themes/mean.json +1 -0
- package/themes/military.json +1 -0
- package/themes/neutral.json +1 -0
- package/themes/pirate.json +1 -0
- package/themes/sports.json +1 -0
- package/themes/verstappen.json +1 -0
- package/themes/wizard.json +1 -0
package/js/hosts/hooks-prims.mjs
CHANGED
|
@@ -123,6 +123,10 @@ export function readStdin() {
|
|
|
123
123
|
return stdinText;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// The done gate's own list (#289): `./done-checks.mjs` reads it, `./hooks.mjs`'s rule-gate
|
|
127
|
+
// protects it. Here because both need it and only this module is in both closures.
|
|
128
|
+
export const DONE_LIST = '.geneseed/done-checks.txt';
|
|
129
|
+
|
|
126
130
|
// Law I's boundary half — rule-gate's credential scan, and the activity writer's redaction of
|
|
127
131
|
// every snippet it puts on disk. Here, not in `./hooks.mjs`, so the writer reads the one copy
|
|
128
132
|
// without loading the gates. High-precision vendor prefixes only — a generic "looks like
|
package/js/hosts/hooks.mjs
CHANGED
|
@@ -56,16 +56,17 @@
|
|
|
56
56
|
*/
|
|
57
57
|
import { readFileSync, appendFileSync, writeFileSync } from 'node:fs';
|
|
58
58
|
import path from 'node:path';
|
|
59
|
-
import { printOut as out, printErr as err } from '../lib/fs.mjs';
|
|
59
|
+
import { printOut as out, printErr as err, withDiscardableStderr } from '../lib/fs.mjs';
|
|
60
60
|
import { normcase } from '../lib/paths.mjs';
|
|
61
|
+
import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
|
|
61
62
|
import {
|
|
62
63
|
GATE_LEDGER, globalHookStandingDown, hookProjectDir, resolvePath, sovereignBypass,
|
|
63
64
|
} from './hosts.mjs';
|
|
64
65
|
import { currentBranch, gitRootOf, loopLaunched } from './gitref.mjs';
|
|
65
66
|
import { LOSS_CANDIDATE_RE, catastrophic, lossReason, stripStructure } from './loss.mjs';
|
|
66
|
-
import { selfAndParents, readStdin, SECRET_RE } from './hooks-prims.mjs';
|
|
67
|
+
import { selfAndParents, readStdin, SECRET_RE, DONE_LIST } from './hooks-prims.mjs';
|
|
67
68
|
import { recordUse } from './usage.mjs';
|
|
68
|
-
import { ownershipBlock } from './ownership-gate.mjs';
|
|
69
|
+
import { WRITE_NAME_RE, ownershipBlock } from './ownership-gate.mjs';
|
|
69
70
|
|
|
70
71
|
// ======================================================================================
|
|
71
72
|
// git-gate — Doctrine process 5's tool-boundary backstop
|
|
@@ -576,9 +577,8 @@ function ruleGateTarget(p, root) {
|
|
|
576
577
|
const DOTENV_RE = /(^|[\\/])\.env(\.[^\\/]*)?$/;
|
|
577
578
|
|
|
578
579
|
export const SENSOR_LIST = '.geneseed/protected-checks.txt';
|
|
579
|
-
// The done gate's list (`./hooks-
|
|
580
|
-
// protected-checks list: emptying it would disarm the gate it feeds.
|
|
581
|
-
export const DONE_LIST = '.geneseed/done-checks.txt';
|
|
580
|
+
// The done gate's list (`DONE_LIST`, `./hooks-prims.mjs`; #289) protects itself too, with or
|
|
581
|
+
// without a protected-checks list: emptying it would disarm the gate it feeds.
|
|
582
582
|
/**
|
|
583
583
|
* External Gate's boundary half: the checks an agent is judged by must sit outside what it can
|
|
584
584
|
* edit, or a failing check is one edit away from a passing one. A project opts in by listing
|
|
@@ -611,6 +611,126 @@ function protectedIn(target) {
|
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
613
|
|
|
614
|
+
/**
|
|
615
|
+
* External Gate's other half: the GATES' OWN configuration. A file the agent can edit that turns
|
|
616
|
+
* a gate off is a gate the agent can switch off, so a write to one asks like a protected check
|
|
617
|
+
* (audit 2026-10-28, R4/C5). Three anchors, each matched by exact name, never by folder prefix:
|
|
618
|
+
* * the install root (`--root`): the hook wiring (`settings.json`, `settings.local.json`, Bob
|
|
619
|
+
* global's `settings/settings.json` — `claudeWire`), `excludes.json` (`sovereignBypass`), the
|
|
620
|
+
* `AGENT.md` gate markers (`Done gate: off`, read by `cmdContext`; every marker is read back
|
|
621
|
+
* by a rebuild), and `.geneseed-manifest.json` / `.geneseed-emit` (`globalHookStandingDown`);
|
|
622
|
+
* * any host project dir the target sits in (`<dir>/.claude/settings.json` and kin, found by
|
|
623
|
+
* the parent's — or for `settings/settings.json` the grandparent's — folder name, so a
|
|
624
|
+
* monorepo subpackage or a dir with no `.git` is covered): Claude reads project settings
|
|
625
|
+
* from the session's own dir (`globalHookStandingDown`), the team file can set
|
|
626
|
+
* `disableAllHooks`, which Claude applies live, and a forged project manifest + settings makes
|
|
627
|
+
* a global gate stand down; and any `opencode.json(c)`, a name only OpenCode's config wears
|
|
628
|
+
* (OpenCode reads it from every dir up to the git root);
|
|
629
|
+
* * the machine-wide hook shim dir (`$GENESEED_HOME/bin`, `shimHome` in `./shim.mjs`, inlined
|
|
630
|
+
* because that module is not on this path) — every Claude/Bob hook command runs through it.
|
|
631
|
+
* Read twice like `protectedCheck`, so a link into one of these never loosens the gate. On Bob
|
|
632
|
+
* the ask is a block, except for a hook-settings file (`bobSettingsChange` below). The OpenCode
|
|
633
|
+
* guard holds these lists minus the hook settings and OpenCode's own files, which OpenCode asks about natively
|
|
634
|
+
* (`opencodeEditAsks` in ./settings.mjs; tests/plugins/guard.test.mjs pins the difference). The CLI
|
|
635
|
+
* (`geneseed exclude`, an emit) writes these with `fs`, never through a write tool, so it is
|
|
636
|
+
* not gated. shortcut: write tools only, like `protectedCheck` — a shell redirect is not seen.
|
|
637
|
+
*/
|
|
638
|
+
const GATE_CONFIG_FILES = ['settings.json', 'settings.local.json', 'settings/settings.json', 'excludes.json', 'AGENT.md', '.geneseed-manifest.json', '.geneseed-emit', 'opencode.json', 'opencode.jsonc'];
|
|
639
|
+
const GATE_CONFIG_MARKERS = ['.claude', '.openclaude', '.bob', '.opencode'];
|
|
640
|
+
export const GATE_CONFIG_ASK = 'is a gate\'s own configuration (the hook wiring, the exclusion list, a gate switch or the hook shim). Editing it could switch a check off: fix the code, not the gate, unless the user asks for this edit. Stop and ask the user now; never write it another way (for example through a shell command).';
|
|
641
|
+
function gateConfig(p, root) {
|
|
642
|
+
let bin = null;
|
|
643
|
+
try {
|
|
644
|
+
bin = normcase(path.join(withDiscardableStderr(() => resolvePath(process.env.GENESEED_HOME || '~/.geneseed')), 'bin'));
|
|
645
|
+
} catch { /* a `~user` GENESEED_HOME: no shim dir to compare, the other anchors still run */ }
|
|
646
|
+
try {
|
|
647
|
+
const roots = root ? [path.resolve(root), resolvePath(root)] : [];
|
|
648
|
+
for (const target of [path.resolve(p), resolvePath(p)]) {
|
|
649
|
+
const t = normcase(target);
|
|
650
|
+
if (bin && t.startsWith(bin + path.sep)) return true;
|
|
651
|
+
if (/^opencode\.jsonc?$/.test(path.basename(t))) return true;
|
|
652
|
+
const up = [path.dirname(target), path.dirname(path.dirname(target))];
|
|
653
|
+
const homes = [...roots, ...up.filter((d) => GATE_CONFIG_MARKERS.some((m) => normcase(m) === normcase(path.basename(d))))];
|
|
654
|
+
if (homes.some((h) => GATE_CONFIG_FILES.some((f) => normcase(path.join(h, f)) === t))) return true;
|
|
655
|
+
}
|
|
656
|
+
} catch { /* an unresolvable path is no hit, like `protectedIn` */ }
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Bob's half of External Gate on its own settings (A2 L2). Bob has no ask tier and no native
|
|
662
|
+
* per-path approval (bob.ibm.com approval settings work per tool group), so an ask there is a
|
|
663
|
+
* block — and blocking every edit of the user's shared `settings.json` was rejected. So on Bob a
|
|
664
|
+
* hook-settings file passes unless the write CHANGES Geneseed's own wiring: the after-text is
|
|
665
|
+
* rebuilt from the tool call, both sides are parsed, and the write is blocked when the set of
|
|
666
|
+
* `event|matcher|hook` entries whose command names `geneseed-hook` differs, `disableAllHooks`
|
|
667
|
+
* turns on, or an env value the hook reads changes (`GENESEED_*`, `*_CONFIG_DIR`, `NODE_OPTIONS`).
|
|
668
|
+
* Fail closed: a tool we cannot replay (a regex, case-folded or line-ranged search, a diff of more
|
|
669
|
+
* than one block), a search not found exactly once, or an after-text Bob might not parse (JSONC
|
|
670
|
+
* where the file was strict JSON) returns a reason, never a pass.
|
|
671
|
+
* @returns {string | null} why the write is refused, or null when Geneseed's wiring is untouched
|
|
672
|
+
*/
|
|
673
|
+
const SETTINGS_RE = /(^|[\\/])(settings\.json|settings\.local\.json)$/i;
|
|
674
|
+
function settingsAfter(before, payload) {
|
|
675
|
+
const ti = payload.tool_input || {};
|
|
676
|
+
const tool = payload.tool_name;
|
|
677
|
+
if (tool === 'write_file' || tool === 'write_to_file' || tool === 'Write') {
|
|
678
|
+
return typeof ti.content === 'string' ? ti.content : null;
|
|
679
|
+
}
|
|
680
|
+
const line = Number(ti.line); // Roo-lineage tools may send it as a string
|
|
681
|
+
if (tool === 'insert_content' && typeof ti.content === 'string' && Number.isInteger(line) && line >= 0) {
|
|
682
|
+
const lines = before.split('\n');
|
|
683
|
+
lines.splice(line === 0 ? lines.length : line - 1, 0, ...ti.content.split('\n'));
|
|
684
|
+
return lines.join('\n');
|
|
685
|
+
}
|
|
686
|
+
const once = (text, search, replace) => (typeof search === 'string' && search && typeof replace === 'string'
|
|
687
|
+
&& text.split(search).length === 2 ? text.replace(search, () => replace) : null);
|
|
688
|
+
if (tool === 'search_and_replace') {
|
|
689
|
+
const ranged = ti.use_regex || ti.ignore_case || ti.start_line != null || ti.end_line != null;
|
|
690
|
+
return ranged ? null : once(before, ti.search, ti.replace);
|
|
691
|
+
}
|
|
692
|
+
if (tool === 'apply_diff' && typeof ti.diff === 'string') {
|
|
693
|
+
const blocks = [...ti.diff.matchAll(/<<<<<<< SEARCH\r?\n(?::start_line:\s*\d+\r?\n)?(?:-------\r?\n)?([\s\S]*?)\r?\n?=======\r?\n([\s\S]*?)\r?\n?>>>>>>> REPLACE/g)];
|
|
694
|
+
let text = before;
|
|
695
|
+
for (const [, search, replace] of blocks) if ((text = once(text, search, replace)) === null) return null;
|
|
696
|
+
// One block only: with several, Bob may apply some and refuse others (its start-line window).
|
|
697
|
+
return blocks.length === 1 ? text : null;
|
|
698
|
+
}
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
function geneseedWiring(data) {
|
|
702
|
+
const keys = [];
|
|
703
|
+
const hooks = isDict(data.hooks) ? data.hooks : {};
|
|
704
|
+
for (const [event, groups] of Object.entries(hooks)) {
|
|
705
|
+
for (const g of Array.isArray(groups) ? groups : []) {
|
|
706
|
+
for (const h of (g && Array.isArray(g.hooks)) ? g.hooks : []) {
|
|
707
|
+
if (h && typeof h.command === 'string' && h.command.includes('geneseed-hook')) {
|
|
708
|
+
keys.push(JSON.stringify([event, g.matcher ?? null, h]));
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
const env = isDict(data.env) ? data.env : {};
|
|
714
|
+
for (const [k, v] of Object.entries(env)) {
|
|
715
|
+
if (/^GENESEED_|_CONFIG_DIR$|^NODE_OPTIONS$/i.test(k)) keys.push(JSON.stringify(['env', k, v]));
|
|
716
|
+
}
|
|
717
|
+
return keys.sort().join('\n');
|
|
718
|
+
}
|
|
719
|
+
function bobSettingsChange(p, payload) {
|
|
720
|
+
let before = '';
|
|
721
|
+
const file = path.resolve(typeof payload.cwd === 'string' ? payload.cwd : '.', p);
|
|
722
|
+
try { before = readFileSync(file, 'utf8'); } catch (e) { if (e.code !== 'ENOENT') return 'it could not be read'; }
|
|
723
|
+
const after = settingsAfter(before, payload);
|
|
724
|
+
if (after === null) return 'the edit could not be replayed to check it';
|
|
725
|
+
const [a] = readJsonc(before.trim() ? before : '{}');
|
|
726
|
+
const [b] = readJsonc(after.trim() ? after : '{}');
|
|
727
|
+
if (!isDict(a) || !isDict(b)) return 'a side of the edit is not a JSON object';
|
|
728
|
+
const strict = (t) => { try { parseJson(t.trim() ? t : '{}'); return true; } catch { return false; } };
|
|
729
|
+
if (strict(before) && !strict(after)) return 'it turns strict JSON into JSONC, which Bob may refuse to read';
|
|
730
|
+
if (isTruthy(b.disableAllHooks) && !isTruthy(a.disableAllHooks)) return 'it turns on disableAllHooks';
|
|
731
|
+
return geneseedWiring(a) === geneseedWiring(b) ? null : 'it changes Geneseed\'s own hook entries';
|
|
732
|
+
}
|
|
733
|
+
|
|
614
734
|
function ruleGate(args) {
|
|
615
735
|
if (sovereignBypass(args.root)) return 0;
|
|
616
736
|
return ruleDecide(args, readPayload());
|
|
@@ -656,6 +776,19 @@ function ruleDecide(args, payload) {
|
|
|
656
776
|
: `${sensor}, listed in ${SENSOR_LIST}`}). A check the agent can edit is not a `
|
|
657
777
|
+ 'check: fix the code, not the check, unless the user asks for this edit.');
|
|
658
778
|
}
|
|
779
|
+
// Bob routes reads here too (`read_file` carries a path): only a write is this gate's business.
|
|
780
|
+
// Bob never reads `opencode.json(c)`, OpenCode's whole host config: it is not gated from Bob.
|
|
781
|
+
const bobWrite = HOST !== 'bob' || (WRITE_NAME_RE.test(String((payload && payload.tool_name) || ''))
|
|
782
|
+
&& !/^opencode\.jsonc?$/i.test(path.basename(p)));
|
|
783
|
+
if (bobWrite && gateConfig(p, args.root)) {
|
|
784
|
+
// Bob: a hook-settings file is the user's shared host config — refused only when the write
|
|
785
|
+
// touches Geneseed's wiring (`bobSettingsChange`); a pass falls through to the checks below.
|
|
786
|
+
const why = HOST === 'bob' && SETTINGS_RE.test(p) ? bobSettingsChange(p, payload) : '';
|
|
787
|
+
if (why !== null) {
|
|
788
|
+
return ask(args, 'rule-gate', 'rigor-5', `Geneseed (External Gate) — ${p} ${GATE_CONFIG_ASK}`
|
|
789
|
+
+ (why ? ` On Bob this write is refused because ${why}.` : ''));
|
|
790
|
+
}
|
|
791
|
+
}
|
|
659
792
|
const target = ruleGateTarget(p, args.root);
|
|
660
793
|
if (!target) {
|
|
661
794
|
// The ownership first-write gate (./ownership-gate.mjs), last: every rule above outranks it.
|
package/js/hosts/hosts.mjs
CHANGED
|
@@ -29,6 +29,12 @@ export const EXCLUDES_FILE = 'excludes.json';
|
|
|
29
29
|
|
|
30
30
|
/** The gate ledger inside an install: the hooks append to it, `status` counts it. */
|
|
31
31
|
export const GATE_LEDGER = path.join('notebook', 'gates.jsonl');
|
|
32
|
+
/**
|
|
33
|
+
* The ledger verb of the done gate's ADVISORY (inferred checks, `hooks-done.mjs`): recorded so
|
|
34
|
+
* it can be found, but it asked nothing of anyone, so the ask counts (`status`, `/api/gates`)
|
|
35
|
+
* skip it — an advisory fires on almost every editing turn and would drown the real asks.
|
|
36
|
+
*/
|
|
37
|
+
export const ADVISORY_VERB = 'done-gate-advisory';
|
|
32
38
|
|
|
33
39
|
/**
|
|
34
40
|
* `sovereign_bypass` — the user's own excludes.json, read on EVERY hook call so an edit
|
package/js/hosts/native.mjs
CHANGED
|
@@ -45,7 +45,7 @@ import { lstripNewlines } from './settings.mjs';
|
|
|
45
45
|
const SKILL_DIR_PLACEHOLDER = '<this-skill-directory>';
|
|
46
46
|
|
|
47
47
|
/** Mirrors `_build_core.VENDORED_SKILL_DIRS`. */
|
|
48
|
-
export const VENDORED_SKILL_DIRS = new Set(['react-view-transitions', 'daydream', 'token-report', 'explain-changes']);
|
|
48
|
+
export const VENDORED_SKILL_DIRS = new Set(['react-view-transitions', 'daydream', 'token-report', 'explain-changes', 'diagram-design']);
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* `PurePath(rel).parts` — split on EITHER separator, empties dropped.
|
package/js/hosts/owned.mjs
CHANGED
|
@@ -185,6 +185,25 @@ export function recordedDenies(doc) {
|
|
|
185
185
|
return Array.isArray(d) ? d.filter((n) => typeof n === 'string') : [];
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
/**
|
|
189
|
+
* An OpenCode manifest's `permission.edit` record — `edit_asks`, the gate-config ask keys
|
|
190
|
+
* Geneseed itself added, and `edit_shorthand`, the user's blanket `"allow"` it widened to an
|
|
191
|
+
* object — as `{ asks, shorthand }`. Absent or malformed reads as nothing owned, like
|
|
192
|
+
* `recordedDenies`, and for the same reason: rebuild and uninstall must agree on what is ours.
|
|
193
|
+
*/
|
|
194
|
+
export function recordedEdit(doc) {
|
|
195
|
+
const a = doc && doc.edit_asks;
|
|
196
|
+
return {
|
|
197
|
+
asks: Array.isArray(a) ? a.filter((k) => typeof k === 'string') : [],
|
|
198
|
+
shorthand: doc && doc.edit_shorthand === 'allow' ? 'allow' : null,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** The manifest keys for an edit record; none when Geneseed owns nothing there. */
|
|
203
|
+
export function editRecordKeys(rec) {
|
|
204
|
+
return rec.asks.length ? { edit_asks: rec.asks, ...(rec.shorthand ? { edit_shorthand: rec.shorthand } : {}) } : {};
|
|
205
|
+
}
|
|
206
|
+
|
|
188
207
|
/**
|
|
189
208
|
* Where one owned file stands against its recorded hash — the table rebuild, prune and
|
|
190
209
|
* uninstall branch on so none of them clobbers a user's edit to a Geneseed-owned file.
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* never sees the developer's answer, so "once" is a marker: the root is recorded per session
|
|
8
8
|
* BEFORE the refusal, and every later write in that (session, repo) passes. The `AGENT.md`
|
|
9
9
|
* pointer line carries the rest, shell writes included (this gate sees Write|Edit|NotebookEdit,
|
|
10
|
-
* and Bob's write tools, only).
|
|
10
|
+
* and Bob's write tools, only). A developer's personal `Setup: declined <date>` line in
|
|
11
|
+
* `.geneseed/ownership.md` defers it in that repo with no expiry (`DECLINED_RE`), and
|
|
12
|
+
* `ownershipLine` turns the same line into a SessionStart reminder.
|
|
11
13
|
*
|
|
12
14
|
* ON THE HOOK PATH, so builtins plus `gitRootOf` and `normcase` only — both already loaded by
|
|
13
15
|
* `./hooks.mjs`. `managedBlockWrite`'s delimiters are inlined, not imported: `settings.mjs` is a
|
|
@@ -21,7 +23,7 @@ import { appendFileSync, mkdirSync, readFileSync, readdirSync } from 'node:fs';
|
|
|
21
23
|
import os from 'node:os';
|
|
22
24
|
import path from 'node:path';
|
|
23
25
|
import { normcase } from '../lib/paths.mjs';
|
|
24
|
-
import { gitRootOf } from './gitref.mjs';
|
|
26
|
+
import { gitRootOf, mainWorktreeOf } from './gitref.mjs';
|
|
25
27
|
|
|
26
28
|
// D5: the build manifests that make a git root an "application". Exact names, plus two families.
|
|
27
29
|
const MANIFESTS = new Set(['package.json', 'pom.xml', 'pyproject.toml', 'go.mod', 'Cargo.toml',
|
|
@@ -35,7 +37,7 @@ const MANAGED_BLOCK_RE = /<!-- BEGIN GENESEED -->[\s\S]*?<!-- END GENESEED -->/g
|
|
|
35
37
|
const SECTION_RE = /^## Ownership[ \t]*\r?$/m;
|
|
36
38
|
|
|
37
39
|
// Write-shaped tool names (Bob's `tool-gate` also routes reads here: `read_file` carries a path).
|
|
38
|
-
const WRITE_NAME_RE = /write|edit|diff|replace|insert/i;
|
|
40
|
+
export const WRITE_NAME_RE = /write|edit|diff|replace|insert/i;
|
|
39
41
|
|
|
40
42
|
// js/hosts/activity.mjs `safeStem`, copied (that module is not on the gate path): a hostile
|
|
41
43
|
// session id can never steer the marker join out of its directory.
|
|
@@ -53,12 +55,65 @@ const TAIL = 'Opt out per repo: `## Ownership` with `mode: off` in the root `AGE
|
|
|
53
55
|
+ 'install: rebuild with `--no-ownership-gate`. Offer the full documentation '
|
|
54
56
|
+ '(`/document-project`) as yes / later. Stop and ask the developer now; re-issue the write only '
|
|
55
57
|
+ 'after they answer. This gate fires once per session and repo.';
|
|
58
|
+
// D5: three answers. Only the third writes anything — the durable, personal decline below.
|
|
59
|
+
const SKIP = 'skip this session; or skip in this repo until they ask — only on that third answer, '
|
|
60
|
+
+ 'write the line `Setup: declined <YYYY-MM-DD>` (today) into `.geneseed/ownership.md` at the '
|
|
61
|
+
+ 'MAIN worktree\'s root (in a linked git worktree, the main checkout\'s, so it outlives this '
|
|
62
|
+
+ 'worktree), which is personal and never committed (if `.geneseed/.gitignore` is absent there, '
|
|
63
|
+
+ 'create it first, as the ownership skill\'s checkpoint rules say)';
|
|
56
64
|
const REASON_NONE = 'Geneseed (Ownership) — this application has no `AGENTS.md` with '
|
|
57
|
-
+ '`## Ownership`. Before writing, propose to the developer: set it up
|
|
58
|
-
+ `
|
|
65
|
+
+ '`## Ownership`. Before writing, propose three answers to the developer: set it up now '
|
|
66
|
+
+ `(ownership skill); ${SKIP}. ${TAIL}`;
|
|
59
67
|
const REASON_NO_SECTION = 'Geneseed (Ownership) — this application\'s `AGENTS.md` has no '
|
|
60
|
-
+ '`## Ownership` section. Before writing, ask the developer: add the Ownership section '
|
|
61
|
-
+ `(ownership skill)
|
|
68
|
+
+ '`## Ownership` section. Before writing, ask the developer: add the Ownership section now '
|
|
69
|
+
+ `(ownership skill); ${SKIP}? ${TAIL}`;
|
|
70
|
+
|
|
71
|
+
// D2: the developer's durable, personal, per-repo decline, in `.geneseed/ownership.md`. It holds
|
|
72
|
+
// until the line is deleted or the setup runs (which removes it); a `## Ownership` section in
|
|
73
|
+
// `AGENTS.md`, on or off, outranks it. The OpenCode twins (geneseed-guard.js,
|
|
74
|
+
// geneseed-context.js) carry this same pattern, so the gate defers exactly where the reminder
|
|
75
|
+
// prints. A malformed line matches nothing, and the gate behaves as before.
|
|
76
|
+
//
|
|
77
|
+
// The line lives in the MAIN worktree (user ruling 2026-10-29): Claude Desktop opens a fresh
|
|
78
|
+
// linked worktree per session, so a decline kept in one would die with it. Only this lookup
|
|
79
|
+
// moves; the section, the manifest test and the session marker stay on the current git root.
|
|
80
|
+
// `mainWorktreeOf` is null for a main worktree, a bare common dir or a malformed link, and the
|
|
81
|
+
// lookup then falls back to the current root.
|
|
82
|
+
export const DECLINED_RE = /^Setup:[ \t]*declined[ \t]+(\d{4}-\d{2}-\d{2})[ \t]*\r?$/m;
|
|
83
|
+
|
|
84
|
+
/** The decline's date, or null (no file, no line, unreadable). Never throws. */
|
|
85
|
+
function declinedSince(root) {
|
|
86
|
+
try {
|
|
87
|
+
const home = mainWorktreeOf(root) ?? root;
|
|
88
|
+
// A leading BOM (some editors write one) would hide a first-line `Setup:` from `^`.
|
|
89
|
+
const text = readFileSync(path.join(home, '.geneseed', 'ownership.md'), 'utf8').replace(/^\uFEFF/, '');
|
|
90
|
+
return DECLINED_RE.exec(text)?.[1] ?? null;
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The root `AGENTS.md` outside Geneseed's managed block; '' when there is none. */
|
|
97
|
+
function ownAgentsText(root) {
|
|
98
|
+
let text = null;
|
|
99
|
+
try { text = readFileSync(path.join(root, 'AGENTS.md'), 'utf8'); } catch { /* none */ }
|
|
100
|
+
return text === null ? '' : text.replace(MANAGED_BLOCK_RE, '');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* D4: the one SessionStart line for a declined repo (`./hooks-context.mjs` prints it beside
|
|
105
|
+
* `doneLine`), or null: not an application, a `## Ownership` section present, or no decline.
|
|
106
|
+
* Never throws.
|
|
107
|
+
*/
|
|
108
|
+
export function ownershipLine(root) {
|
|
109
|
+
try {
|
|
110
|
+
if (!root || !readdirSync(root).some(isManifest) || SECTION_RE.test(ownAgentsText(root))) return null;
|
|
111
|
+
const since = declinedSince(root);
|
|
112
|
+
return since ? `Ownership: setup declined since ${since} — not set up; say "set up ownership" to run it` : null;
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
62
117
|
|
|
63
118
|
/**
|
|
64
119
|
* The refusal reason for this write, or null to defer. `p` is the write target as the payload
|
|
@@ -82,10 +137,9 @@ export function ownershipBlock(p, payload, body, installRoot = null) {
|
|
|
82
137
|
const inInstall = path.relative(path.resolve(installRoot), target);
|
|
83
138
|
if (!inInstall.startsWith('..') && !path.isAbsolute(inInstall)) return null;
|
|
84
139
|
}
|
|
85
|
-
|
|
86
|
-
try { text = readFileSync(path.join(root, 'AGENTS.md'), 'utf8'); } catch { /* none: gate */ }
|
|
87
|
-
const own = text === null ? '' : text.replace(MANAGED_BLOCK_RE, '');
|
|
140
|
+
const own = ownAgentsText(root);
|
|
88
141
|
if (SECTION_RE.test(own)) return null; // on or off, the team has decided
|
|
142
|
+
if (declinedSince(root)) return null; // D2: the developer declined it in this repo
|
|
89
143
|
// shortcut: one small marker file per session, never pruned (the OS temp cleaner owns it);
|
|
90
144
|
// prune here if the folder is ever seen to grow past a few thousand files.
|
|
91
145
|
const dir = path.join(os.tmpdir(), `geneseed-ownership-${userTag()}`);
|
package/js/hosts/settings.mjs
CHANGED
|
@@ -39,9 +39,14 @@ import path from 'node:path';
|
|
|
39
39
|
import { readText, writeText, isOsError } from '../lib/fs.mjs';
|
|
40
40
|
import {
|
|
41
41
|
jsonDumps, jsonDumpsCompact, jsonDumpsIndent, parseJson, deepEquals, formatRepr,
|
|
42
|
-
indexOfDeepEqual, get, has, isDict,
|
|
42
|
+
indexOfDeepEqual, get, has, isDict, readJsonc,
|
|
43
43
|
} from '../lib/json.mjs';
|
|
44
|
-
import { SHIM_MARK, claudeHookShell, hookPrefix } from './shim.mjs';
|
|
44
|
+
import { SHIM_MARK, claudeHookShell, hookPrefix, shimHome } from './shim.mjs';
|
|
45
|
+
import { GLOBAL_MANIFEST } from './hosts.mjs';
|
|
46
|
+
import { gitRootOf } from './gitref.mjs';
|
|
47
|
+
|
|
48
|
+
// `readJsonc` moved to ../lib/json.mjs so the hook path can parse a settings file (A2 L2).
|
|
49
|
+
export { readJsonc };
|
|
45
50
|
import { stripWhitespace, stripWhitespaceEnd } from '../lib/text.mjs';
|
|
46
51
|
|
|
47
52
|
const OPENCODE_SCHEMA = 'https://opencode.ai/config.json';
|
|
@@ -375,82 +380,97 @@ function reconcileOpencodeSkillPermission(perm, names, staleNames = [], added =
|
|
|
375
380
|
return [changed, null];
|
|
376
381
|
}
|
|
377
382
|
|
|
378
|
-
/**
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
+
/**
|
|
384
|
+
* External Gate on OpenCode (A2 L1): the `permission.edit` keys that make OpenCode itself ASK
|
|
385
|
+
* before a write tool touches a file that can switch a gate off — every `opencode.json(c)`
|
|
386
|
+
* (OpenCode reads one from every dir up to the git root, `config/paths.ts`), the global
|
|
387
|
+
* `config.json` it also reads (`config.ts` `globalConfigFile`), the install's `AGENT.md` (its gate
|
|
388
|
+
* markers; a project install writes it at `agentRel`, the global one in `cfgDir`), the install
|
|
389
|
+
* dir's `excludes.json`, manifest, emit marker and `plugins/geneseed-*.js`, the other hosts' hook
|
|
390
|
+
* settings (`.claude/`, `.openclaude/`, `.bob/`), and the hook shim dir. An ask, never a deny: the
|
|
391
|
+
* user rejected a guard that refuses a host's shared config.
|
|
392
|
+
*
|
|
393
|
+
* Each tail is emitted bare and `*\/`-prefixed. Verified against OpenCode's source (v1.3.4,
|
|
394
|
+
* v1.19.0, v2.2.1) and live (`debug agent`, 1.19.5 and 2.2.1): the edit, write and apply_patch
|
|
395
|
+
* tools ask with the path relative to the worktree (1.x) or the session dir (2.x, absolute when
|
|
396
|
+
* outside), `\` folded to `/`; `*` is `.*` and crosses `/`, case-insensitive on Windows; the LAST
|
|
397
|
+
* matching rule wins and user config rules come after the built-in agent defaults. So the bare
|
|
398
|
+
* form catches a path at the root, the prefixed one a path below it, a `../` path or an absolute
|
|
399
|
+
* one. A project `AGENT.md` gets narrow keys only — `*\/AGENT.md` would ask about every one in the
|
|
400
|
+
* repo: relative to the install root (`agentRel`), to the git root (1.x matches from there, so a
|
|
401
|
+
* monorepo subpackage install needs it), and `*../` for a 2.x session started in a subdir (a path
|
|
402
|
+
* inside the project is relative to the session dir there, `file-access.ts` `resolve`). Never the
|
|
403
|
+
* absolute path: a project opencode.json is often committed, and teammates do not share it.
|
|
404
|
+
*/
|
|
405
|
+
export function opencodeEditAsks(cfgDir, global, agentRel = null) {
|
|
406
|
+
const cfg = path.basename(cfgDir);
|
|
407
|
+
const tails = ['opencode.json', 'opencode.jsonc', ...['excludes.json', GLOBAL_MANIFEST, '.geneseed-emit',
|
|
408
|
+
'plugins/geneseed-*.js', ...(global ? ['AGENT.md', 'config.json'] : [])].map((f) => `${cfg}/${f}`),
|
|
409
|
+
...['.claude', '.openclaude', '.bob'].flatMap((m) => [`${m}/settings.json`, `${m}/settings.local.json`]),
|
|
410
|
+
'.bob/settings/settings.json'];
|
|
411
|
+
const keys = [];
|
|
412
|
+
if (agentRel) {
|
|
413
|
+
const abs = path.resolve(path.dirname(cfgDir), agentRel);
|
|
414
|
+
const git = gitRootOf(path.dirname(abs));
|
|
415
|
+
const gitRel = git ? path.relative(git, abs).split(path.sep).join('/') : agentRel;
|
|
416
|
+
keys.push(...new Set([agentRel, gitRel, `*../${agentRel}`,
|
|
417
|
+
...(agentRel.includes('/') ? [`*/${agentRel}`] : [])]));
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
const home = shimHome();
|
|
421
|
+
// The default `~/.geneseed` is a name no project folder wears; any other home is matched
|
|
422
|
+
// only absolutely (2.x), since `*/tools/bin/*` would ask about every repo's `tools/bin`.
|
|
423
|
+
if (path.basename(home) === '.geneseed') tails.push('.geneseed/bin/*');
|
|
424
|
+
else keys.push(`${path.resolve(home).split(path.sep).join('/')}/bin/*`);
|
|
425
|
+
} catch { /* a `~user` GENESEED_HOME has no shim dir to name; the rest still ask */ }
|
|
426
|
+
return [...tails.flatMap((t) => [t, `*/${t}`]), ...keys];
|
|
383
427
|
}
|
|
384
428
|
|
|
385
429
|
/**
|
|
386
|
-
* `
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
* not parse.
|
|
430
|
+
* Wire `keys` into `perm.edit` as `"ask"`, and record what was Geneseed's doing — the `edit` twin
|
|
431
|
+
* of `reconcileOpencodeSkillPermission`. `record` is the previous manifest's `{ asks, shorthand }`
|
|
432
|
+
* and is updated in place: `asks` gains each key this call added (a key already there, any value,
|
|
433
|
+
* is the user's and is never claimed), `shorthand` keeps the user's blanket `"allow"` that this
|
|
434
|
+
* call widened into `{ "*": "allow", …ours }` so uninstall can put it back. A blanket `"ask"` or
|
|
435
|
+
* `"deny"` already covers our files, so it is left alone. Anything else is reported opaque.
|
|
436
|
+
* A recorded key this build no longer wants (the key list changed) is swept while it still reads
|
|
437
|
+
* `"ask"`, as `reconcileOpencodeSkillPermission` sweeps a stale deny.
|
|
438
|
+
* @returns {[boolean, string | null]}
|
|
396
439
|
*/
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
let
|
|
400
|
-
let
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const ch = text[i];
|
|
405
|
-
if (inStr) {
|
|
406
|
-
out.push(ch);
|
|
407
|
-
if (ch === '\\' && i + 1 < n) {
|
|
408
|
-
out.push(text[i + 1]);
|
|
409
|
-
i += 2;
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
if (ch === '"') inStr = false;
|
|
413
|
-
i += 1;
|
|
414
|
-
continue;
|
|
440
|
+
function reconcileOpencodeEditPermission(perm, keys, record) {
|
|
441
|
+
if (!keys.length) return [false, null];
|
|
442
|
+
let edit = get(perm, 'edit');
|
|
443
|
+
let swept = false;
|
|
444
|
+
if (isDict(edit)) {
|
|
445
|
+
for (const k of record.asks.filter((r) => !keys.includes(r))) {
|
|
446
|
+
if (edit[k] === 'ask') { delete edit[k]; swept = true; }
|
|
415
447
|
}
|
|
416
|
-
if (ch === '"') {
|
|
417
|
-
inStr = true;
|
|
418
|
-
out.push(ch);
|
|
419
|
-
i += 1;
|
|
420
|
-
continue;
|
|
421
|
-
}
|
|
422
|
-
if (ch === '/' && i + 1 < n && text[i + 1] === '/') {
|
|
423
|
-
hadComments = true;
|
|
424
|
-
i += 2;
|
|
425
|
-
while (i < n && text[i] !== '\n' && text[i] !== '\r') i += 1;
|
|
426
|
-
continue;
|
|
427
|
-
}
|
|
428
|
-
if (ch === '/' && i + 1 < n && text[i + 1] === '*') {
|
|
429
|
-
hadComments = true;
|
|
430
|
-
i += 2;
|
|
431
|
-
while (i + 1 < n && !(text[i] === '*' && text[i + 1] === '/')) i += 1;
|
|
432
|
-
i += 2;
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
if (ch === '}' || ch === ']') {
|
|
436
|
-
while (out.length && ' \t\r\n'.includes(out[out.length - 1])) out.pop();
|
|
437
|
-
if (out.length && out[out.length - 1] === ',') out.pop();
|
|
438
|
-
out.push(ch);
|
|
439
|
-
i += 1;
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
out.push(ch);
|
|
443
|
-
i += 1;
|
|
444
448
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
449
|
+
record.asks = record.asks.filter((r) => keys.includes(r));
|
|
450
|
+
if (edit === 'ask' || edit === 'deny') return [false, null];
|
|
451
|
+
let changed = swept;
|
|
452
|
+
if (edit === 'allow') {
|
|
453
|
+
record.shorthand = 'allow';
|
|
454
|
+
edit = perm.edit = { '*': 'allow' };
|
|
455
|
+
changed = true;
|
|
456
|
+
} else if (!has(perm, 'edit')) {
|
|
457
|
+
edit = perm.edit = {};
|
|
458
|
+
} else if (!isDict(edit)) {
|
|
459
|
+
return [false, 'has an "edit" that is neither an action nor an object'];
|
|
453
460
|
}
|
|
461
|
+
const kept = [];
|
|
462
|
+
for (const k of keys) {
|
|
463
|
+
if (!has(edit, k)) { edit[k] = 'ask'; changed = true; record.asks.push(k); } else if (edit[k] !== 'ask') kept.push(k);
|
|
464
|
+
}
|
|
465
|
+
record.asks = [...new Set(record.asks)].sort();
|
|
466
|
+
return [changed, kept.length ? `keeps your own ${kept.map((k) => jsonDumps(k)).join(', ')}` : null];
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** `_build_settings._opencode_target`. Only caller of a `.json` -> `.jsonc` suffix swap. */
|
|
470
|
+
export function opencodeTarget(jsonPath) {
|
|
471
|
+
const ext = path.extname(jsonPath);
|
|
472
|
+
const jsonc = (ext ? jsonPath.slice(0, jsonPath.length - ext.length) : jsonPath) + '.jsonc';
|
|
473
|
+
return existsSync(jsonc) ? jsonc : jsonPath;
|
|
454
474
|
}
|
|
455
475
|
|
|
456
476
|
/**
|
|
@@ -505,7 +525,7 @@ export function loadJsonObject(p, { strict = false } = {}) {
|
|
|
505
525
|
*/
|
|
506
526
|
function warnCommentedJsonc(target, agentPath, permission,
|
|
507
527
|
includeLsp = false, prefix = 'geneseed', doctrines = null, excluded = [], skillNames = [],
|
|
508
|
-
deletionGate = true) {
|
|
528
|
+
deletionGate = true, editAsks = []) {
|
|
509
529
|
process.stdout.write(`[${prefix}] ${path.basename(target)} has comments — not rewriting `
|
|
510
530
|
+ 'it (your edits are kept). Add this to its "instructions" array by hand:\n');
|
|
511
531
|
process.stdout.write(`[${prefix}] ${jsonDumps(agentPath)}\n`);
|
|
@@ -524,6 +544,13 @@ function warnCommentedJsonc(target, agentPath, permission,
|
|
|
524
544
|
process.stdout.write(`[${prefix}] ${line}\n`);
|
|
525
545
|
}
|
|
526
546
|
}
|
|
547
|
+
if (editAsks.length) {
|
|
548
|
+
process.stdout.write(`[${prefix}] and, so a write to a gate's own configuration asks first, `
|
|
549
|
+
+ 'these keys in "permission"."edit" (after any "*" key):\n');
|
|
550
|
+
for (const line of jsonDumpsIndent(Object.fromEntries(editAsks.map((k) => [k, 'ask']))).split('\n')) {
|
|
551
|
+
process.stdout.write(`[${prefix}] ${line}\n`);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
527
554
|
}
|
|
528
555
|
if (includeLsp) {
|
|
529
556
|
process.stdout.write(`[${prefix}] and, to enable code intelligence, a top-level `
|
|
@@ -565,7 +592,7 @@ export function atomicWriteJson(p, config) {
|
|
|
565
592
|
* every path that wrote nothing — unreadable, not an object, commented `.jsonc`, write
|
|
566
593
|
* failure — so the caller keeps its previous record rather than claiming denies never written. */
|
|
567
594
|
export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [], skillNames = [],
|
|
568
|
-
staleSkillNames = [], result = {}, deletionGate = true) {
|
|
595
|
+
staleSkillNames = [], result = {}, deletionGate = true, editAsks = [], oldEdit = null) {
|
|
569
596
|
const target = opencodeTarget(p);
|
|
570
597
|
let config = { $schema: OPENCODE_SCHEMA, instructions: [] };
|
|
571
598
|
const { state, data, hadComments, error } = loadJsonObject(target);
|
|
@@ -599,12 +626,16 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
599
626
|
let skillOpaque = null;
|
|
600
627
|
let permIsObject = true;
|
|
601
628
|
const added = [];
|
|
629
|
+
// The edit record is a copy, filled in place, and handed back only on the paths that wrote.
|
|
630
|
+
const edit = { asks: [...((oldEdit && oldEdit.asks) || [])], shorthand: (oldEdit && oldEdit.shorthand) || null };
|
|
631
|
+
let editNote = null;
|
|
602
632
|
if (addPerm) {
|
|
603
633
|
config.permission = defaultPermission(doctrines, excluded, deletionGate);
|
|
604
634
|
if (skillNames.length) {
|
|
605
635
|
config.permission.skill = defaultSkillPermission(skillNames);
|
|
606
636
|
added.push(...skillNames);
|
|
607
637
|
}
|
|
638
|
+
reconcileOpencodeEditPermission(config.permission, editAsks, edit);
|
|
608
639
|
} else {
|
|
609
640
|
const perm = get(config, 'permission');
|
|
610
641
|
permIsObject = isDict(perm);
|
|
@@ -617,6 +648,9 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
617
648
|
[skillChanged, skillOpaque] = reconcileOpencodeSkillPermission(perm, skillNames, staleSkillNames,
|
|
618
649
|
added);
|
|
619
650
|
permChanged = permChanged || skillChanged;
|
|
651
|
+
let editChanged;
|
|
652
|
+
[editChanged, editNote] = reconcileOpencodeEditPermission(perm, editAsks, edit);
|
|
653
|
+
permChanged = permChanged || editChanged;
|
|
620
654
|
}
|
|
621
655
|
}
|
|
622
656
|
// The shape said no. This is the direction the residue warning above is NOT — a rule stated
|
|
@@ -653,10 +687,16 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
653
687
|
+ 'Geneseed cannot tell its own entry from one you wrote, so it removes neither. Delete '
|
|
654
688
|
+ 'them by hand if you want them gone.\n');
|
|
655
689
|
}
|
|
690
|
+
if (editNote) {
|
|
691
|
+
process.stderr.write(`[geneseed] WARN: "permission"."edit" in ${path.basename(target)} `
|
|
692
|
+
+ `${editNote}, so a write to a gate's own configuration there may not ask. Your policy is `
|
|
693
|
+
+ 'left exactly as written.\n');
|
|
694
|
+
}
|
|
656
695
|
const addLsp = !has(config, 'lsp');
|
|
657
696
|
if (addLsp) config.lsp = true;
|
|
658
697
|
if (!addInstr && !permChanged && !addLsp) {
|
|
659
698
|
result.skillsAdded = added;
|
|
699
|
+
result.editRecord = edit;
|
|
660
700
|
return target;
|
|
661
701
|
}
|
|
662
702
|
if (path.extname(target) === '.jsonc' && hadComments) {
|
|
@@ -672,12 +712,13 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
|
|
|
672
712
|
// block to paste, split by which of the two situations the reader is actually in. It is
|
|
673
713
|
// stdout, not stderr, because on this path the paste-in IS the output.
|
|
674
714
|
warnCommentedJsonc(target, agentPath, addPerm ? 'add' : (permChanged && 'reconcile'),
|
|
675
|
-
addLsp, 'geneseed', doctrines, excluded, skillNames, deletionGate);
|
|
715
|
+
addLsp, 'geneseed', doctrines, excluded, skillNames, deletionGate, editAsks);
|
|
676
716
|
return target;
|
|
677
717
|
}
|
|
678
718
|
try {
|
|
679
719
|
atomicWriteJson(target, config);
|
|
680
720
|
result.skillsAdded = added;
|
|
721
|
+
result.editRecord = edit;
|
|
681
722
|
} catch (e) {
|
|
682
723
|
if (!isOsError(e)) throw e;
|
|
683
724
|
process.stderr.write(`[geneseed] WARN: could not write ${target} (${e.message}) — `
|