geneseed 5.0.1 → 5.0.3
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 +1 -1
- package/SHIPPED.md +1 -1
- package/adapters/claude-code/README.md +6 -4
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +3 -0
- package/adapters/opencode/plugins/geneseed-context.js +12 -1
- package/adapters/opencode/plugins/geneseed-guard.js +594 -73
- package/adapters/opencode/plugins/geneseed-learn.js +1 -1
- package/bin/geneseed-hook.mjs +21 -7
- package/docs/concepts/enforcement-table.md +22 -3
- package/docs/concepts/exclusions.md +48 -2
- package/docs/concepts/foreman-mode.md +19 -4
- package/docs/concepts/hook-gates.md +1 -1
- package/docs/concepts/hooks.md +52 -11
- package/docs/concepts/host-matrix.md +4 -3
- package/docs/concepts/hosts.md +1 -1
- package/docs/concepts/kits.md +18 -0
- package/docs/concepts/shared-tier.md +1 -1
- package/docs/concepts/skills.md +1 -1
- package/docs/extending.md +3 -1
- package/docs/guides/autostart.md +27 -3
- package/docs/guides/choose-your-setup.md +1 -1
- package/docs/guides/migrate.md +1 -1
- package/docs/guides/uninstall.md +1 -1
- package/docs/reference/plugin-context.md +1 -1
- package/docs/reference/plugin-guard.md +24 -5
- package/docs/reference/troubleshoot-doctor.md +2 -2
- package/docs/understand/a-day.md +9 -5
- package/docs/web-ui.md +67 -16
- package/harness.config.json +1 -1
- package/js/README.md +1 -1
- package/js/build/emit-claude.mjs +9 -1
- package/js/build/emit-opencode.mjs +2 -1
- package/js/build/source.mjs +9 -3
- package/js/cli-table.json +121 -1
- package/js/hosts/geneseed-dir.mjs +1 -1
- package/js/hosts/hooks-context.mjs +8 -6
- package/js/hosts/hooks-done.mjs +3 -1
- package/js/hosts/hooks-learn.mjs +1 -1
- package/js/hosts/hooks-prims.mjs +270 -0
- package/js/hosts/hooks.mjs +409 -151
- package/js/hosts/hosts.mjs +22 -0
- package/js/hosts/installs.mjs +9 -5
- package/js/hosts/settings.mjs +123 -23
- package/js/hosts/shim.mjs +155 -7
- package/js/hosts/store-watch.mjs +36 -11
- package/js/inspect/diff.mjs +2 -1
- package/js/inspect/inventory.mjs +1 -0
- package/js/inspect/validate.mjs +1 -1
- package/js/maintain/migrate.mjs +2 -2
- package/js/maintain/uninstall.mjs +5 -1
- package/js/web/actions.mjs +17 -1
- package/js/web/api.mjs +9 -10
- package/js/web/routes.mjs +2 -1
- package/package.json +1 -1
- package/registry.json +21 -0
- package/src/AGENT.md.tmpl +17 -21
- package/src/agents/_self-improvement.md +7 -6
- package/src/agents/developer.md +3 -2
- package/src/agents/docker-expert.md +1 -0
- package/src/agents/memory-curator.md +3 -2
- package/src/doctrines/process.md +24 -19
- package/src/kits/ci-pipelines/rules.md +10 -0
- package/src/kits/ci-pipelines.json +14 -0
- package/src/kits/docker/rules.md +11 -0
- package/src/kits/docker.json +12 -0
- package/src/memory/README.md +5 -4
- package/src/modes/foreman.md +23 -10
- package/src/notebook/README.md +1 -1
- package/src/skills/_self-improvement.md +12 -9
- package/src/skills/compose-ops.md +58 -0
- package/src/skills/gitlab-ci.md +51 -0
- package/src/skills/jenkins-pipeline.md +56 -0
- package/src/skills/pipeline.md +2 -2
- package/src/skills/rule.md +24 -18
- package/src/skills/skill-forge.md +24 -6
- package/themes/_TEMPLATE.json +5 -2
- package/themes/biker.json +5 -2
- package/themes/commentator.json +5 -2
- package/themes/cyberpunk.json +5 -2
- package/themes/gamer.json +5 -2
- package/themes/imperial.json +5 -2
- package/themes/joker.json +5 -2
- package/themes/marvin.json +5 -2
- package/themes/mean.json +5 -2
- package/themes/military.json +5 -2
- package/themes/neutral.json +5 -2
- package/themes/pirate.json +5 -2
- package/themes/sports.json +5 -2
- package/themes/verstappen.json +5 -2
- package/themes/wizard.json +5 -2
- package/web/dist/assets/Activity-Ck_Xffpo.js +1 -0
- package/web/dist/assets/ActivityDetail-CBxVS4mU.js +1 -0
- package/web/dist/assets/{Bonsai-C1iBAt4v.js → Bonsai-BlOwsvW6.js} +1 -1
- package/web/dist/assets/{CopyButton-DJ3a4N88.js → CopyButton-DFMOIGbe.js} +1 -1
- package/web/dist/assets/Dashboard-BUdUTjbB.js +2 -0
- package/web/dist/assets/{Docs-Kffdg5uV.js → Docs-D_2Jt6gU.js} +3 -3
- package/web/dist/assets/{GreenhouseView-k56_cBSF.js → GreenhouseView-WalcX5bp.js} +1 -1
- package/web/dist/assets/{Installs-DtEKLC9h.js → Installs-UGiPDMDt.js} +3 -3
- package/web/dist/assets/{JournalView-RQnk5l7I.js → JournalView-CZtXQz-v.js} +1 -1
- package/web/dist/assets/Kits-XQHsazCN.js +1 -0
- package/web/dist/assets/Laws-B6A55S-2.js +4 -0
- package/web/dist/assets/Library-D7L0Wdbh.js +3 -0
- package/web/dist/assets/Loops-C0loS73u.js +2 -0
- package/web/dist/assets/{OperatorHudView-CM5jNPwL.js → OperatorHudView-CeDw5qMB.js} +1 -1
- package/web/dist/assets/Personal-PVmGA2-M.js +2 -0
- package/web/dist/assets/{RailCats-DQxxYBEP.js → RailCats-BGZnJ6fa.js} +1 -1
- package/web/dist/assets/Settings-DWuxwh4i.js +1 -0
- package/web/dist/assets/Tabs-d2RIRAKT.js +1 -0
- package/web/dist/assets/{api-D_r0Jtla.js → api-BMFDSXoB.js} +1 -1
- package/web/dist/assets/index-BEI5ugYQ.css +1 -0
- package/web/dist/assets/index-BNttaGQb.js +6 -0
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Activity-Ci4PZco3.js +0 -1
- package/web/dist/assets/ActivityDetail-C8hroCND.js +0 -1
- package/web/dist/assets/Dashboard-C_On4KXw.js +0 -2
- package/web/dist/assets/Kits-CXkEBpnf.js +0 -1
- package/web/dist/assets/Laws-DhhIVqmh.js +0 -3
- package/web/dist/assets/Library-CAUiEoJo.js +0 -3
- package/web/dist/assets/Loops-LKD8mF4E.js +0 -2
- package/web/dist/assets/Personal-B6Uoly3C.js +0 -2
- package/web/dist/assets/Settings-BTe6-wda.js +0 -1
- package/web/dist/assets/Tabs-CbdDWTp_.js +0 -1
- package/web/dist/assets/index-HfGmYXab.js +0 -3
- package/web/dist/assets/index-ao3M-Fhm.css +0 -1
|
@@ -53,7 +53,7 @@ const SEED_REL = '.geneseed/protected-checks.txt';
|
|
|
53
53
|
* What a project's checks live in. A string ending `/` is a folder, any other string a file; a
|
|
54
54
|
* regex matches file names at the root. Lockfiles are not listed: they move on every install.
|
|
55
55
|
*/
|
|
56
|
-
const CANDIDATES = [
|
|
56
|
+
export const CANDIDATES = [
|
|
57
57
|
'.github/workflows/', '.gitlab-ci.yml', 'Jenkinsfile', 'azure-pipelines.yml', '.circleci/',
|
|
58
58
|
/^eslint\.config\./, /^\.eslintrc/, 'biome.json', 'biome.jsonc', 'tsconfig.json',
|
|
59
59
|
/^jest\.config\./, /^vitest\.config\./, 'pytest.ini', 'ruff.toml', '.golangci.yml', 'checkstyle.xml',
|
|
@@ -12,7 +12,7 @@ import { LEGACY_WIKI_SEED, WIKI_NAMES, sharedPaths } from '../lib/machine-dir.mj
|
|
|
12
12
|
import { normcase, toPlatformPath } from '../lib/paths.mjs';
|
|
13
13
|
import { relPosix } from '../lib/text.mjs';
|
|
14
14
|
import {
|
|
15
|
-
SHARED_TIER_RE, carriersFor, globalHookStandingDown, hookProjectDir, isGlobalInstall, resolvePath, sovereignBypass,
|
|
15
|
+
SHARED_TIER_RE, carriersFor, gateCarrierText, globalHookStandingDown, hookProjectDir, isGlobalInstall, resolvePath, sovereignBypass,
|
|
16
16
|
} from './hosts.mjs';
|
|
17
17
|
import { isFile, isDir, sortPaths, listDir } from './hooks-prims.mjs';
|
|
18
18
|
import { gitRootOf } from './gitref.mjs';
|
|
@@ -658,15 +658,16 @@ function fitLines(lines, room, tailOf) {
|
|
|
658
658
|
* a project install keeps it in the repo, one level above the harness dir. The first candidate
|
|
659
659
|
* that exists answers, as `firstCarrier` does.
|
|
660
660
|
*/
|
|
661
|
-
function
|
|
661
|
+
function installCarrierFile(hookRoot, host) {
|
|
662
662
|
const base = readsTier(hookRoot, host) ? hookRoot : path.dirname(hookRoot);
|
|
663
663
|
// Last, a plain bundle or git-clone harness dir keeps its AGENT.md in the dir itself.
|
|
664
664
|
const found = [...carriersFor(host || 'claude').map((rel) => path.join(base, rel)), path.join(hookRoot, 'AGENT.md')];
|
|
665
665
|
for (const file of found) {
|
|
666
|
-
try { return readFileSync(file, 'utf8'); } catch { /* next candidate */ }
|
|
666
|
+
try { return [file, readFileSync(file, 'utf8')]; } catch { /* next candidate */ }
|
|
667
667
|
}
|
|
668
|
-
return '';
|
|
668
|
+
return ['', ''];
|
|
669
669
|
}
|
|
670
|
+
const installCarrier = (hookRoot, host) => installCarrierFile(hookRoot, host)[1];
|
|
670
671
|
|
|
671
672
|
/**
|
|
672
673
|
* The payload, what it spent against `OUTPUT_BUDGET`, and whether the budget `cut` content from it:
|
|
@@ -792,7 +793,7 @@ export function cmdContext(args) {
|
|
|
792
793
|
// The RAW `args.host`, never defaulted to claude, which would key an older
|
|
793
794
|
// OpenClaude emit's `~/.openclaude` (no `--host`) on `.claude` instead of its folder name.
|
|
794
795
|
if (globalHookStandingDown(hookRoot, root, args.host, 'context')) return 0;
|
|
795
|
-
const carrier = hookRoot ?
|
|
796
|
+
const [carrierFile, carrier] = hookRoot ? installCarrierFile(hookRoot, host) : ['', ''];
|
|
796
797
|
const session = hookRoot ? sessionFiles(hookRoot, host, carrier) : [];
|
|
797
798
|
// A session file discovery would also pick up (a `user-rules.md` at the repo root of an
|
|
798
799
|
// install whose harness dir IS the repo root) is injected once, in the session block.
|
|
@@ -807,7 +808,8 @@ export function cmdContext(args) {
|
|
|
807
808
|
// `--no-done-gate` carries `Done gate: off` in its AGENT.md and gets no line — the OpenCode
|
|
808
809
|
// context plugin's `doneGateOff` reads the same marker with the same pattern.
|
|
809
810
|
const gitRoot = gitRootOf(root);
|
|
810
|
-
const gateOff = (marker) => new RegExp(`^${marker}:[ \\t]*off[ \\t]*\\r?$`, 'm')
|
|
811
|
+
const gateOff = (marker) => new RegExp(`^${marker}:[ \\t]*off[ \\t]*\\r?$`, 'm')
|
|
812
|
+
.test(gateCarrierText(carrierFile, carrier));
|
|
811
813
|
// Bob's Stop carries no transcript, so the gate never judges a turn there (`hooks-done.mjs`).
|
|
812
814
|
const done = gitRoot && !gateOff('Done gate') ? doneLine(gitRoot, host !== 'bob') : null;
|
|
813
815
|
// The ownership decline reminder (`./ownership-gate.mjs`), under the same contract: an install
|
package/js/hosts/hooks-done.mjs
CHANGED
|
@@ -269,7 +269,9 @@ export function doneGate(meta, args, install, read = tailReader()) {
|
|
|
269
269
|
if (checks.length) err('[done-gate] transcript unreadable — turn not judged.\n');
|
|
270
270
|
return null;
|
|
271
271
|
}
|
|
272
|
-
const { missing
|
|
272
|
+
const { missing } = verdict;
|
|
273
|
+
// `--no-test-note`: the line goes, the done checks do not.
|
|
274
|
+
const weakened = args.noTestNote ? [] : verdict.weakened;
|
|
273
275
|
// One JSON document on stdout, whatever the advisories: Stop reads no second one.
|
|
274
276
|
const advise = (...said) => {
|
|
275
277
|
if (weakened.length) {
|
package/js/hosts/hooks-learn.mjs
CHANGED
|
@@ -357,7 +357,7 @@ export function cmdLearn(args) {
|
|
|
357
357
|
if (hookEvent === 'Stop' && !args.file && install) {
|
|
358
358
|
const said = storeReport(install, meta.session_id, {
|
|
359
359
|
transcript: typeof meta.transcript_path === 'string' ? meta.transcript_path : null,
|
|
360
|
-
cwd: meta.cwd, host: args.host || 'claude',
|
|
360
|
+
cwd: meta.cwd, host: args.host || 'claude', ruleStore: !args.noRuleStore,
|
|
361
361
|
});
|
|
362
362
|
if (said && (verdict === 'advisory' || args.host === 'bob')) err(`[geneseed] ${said}\n`);
|
|
363
363
|
else if (said) out(`${JSON.stringify({ systemMessage: said })}\n`);
|
package/js/hosts/hooks-prims.mjs
CHANGED
|
@@ -204,6 +204,276 @@ export function editPairs(ti, whole = '') {
|
|
|
204
204
|
return pairs;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
// ---- gate text twin: BEGIN — adapters/opencode/plugins/geneseed-guard.js carries everything down to
|
|
208
|
+
// the END marker verbatim, with `export ` dropped (tests/plugins/guard.test.mjs diffs the two).
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* What each protected check is, for a person who has not read the diff: the files, what they are,
|
|
212
|
+
* what an edit can do. Fixed text, so the governed agent cannot write its own case. A file is written
|
|
213
|
+
* as `CANDIDATES` (`./geneseed-dir.mjs`) writes it, so tests/unit/gate_text.test.mjs compares the
|
|
214
|
+
* two entry by entry, both ways: a string ending `/` is a folder, any other string a file, a regex
|
|
215
|
+
* a file name.
|
|
216
|
+
* @type {[(string | RegExp)[], string, string][]}
|
|
217
|
+
*/
|
|
218
|
+
export const GATE_FILES = [
|
|
219
|
+
[['.github/workflows/', '.gitlab-ci.yml', 'Jenkinsfile', 'azure-pipelines.yml', '.circleci/'],
|
|
220
|
+
'which defines the checks that run on every push',
|
|
221
|
+
'those checks can get weaker or stop running, and a failure could go unseen'],
|
|
222
|
+
[[/^eslint\.config\./, /^\.eslintrc/, 'biome.json', 'biome.jsonc', 'ruff.toml', '.golangci.yml', 'checkstyle.xml'],
|
|
223
|
+
'which sets the rules the linter enforces',
|
|
224
|
+
'those rules can get weaker, and bad code could pass unseen'],
|
|
225
|
+
[['tsconfig.json'],
|
|
226
|
+
'which sets how strictly types are checked',
|
|
227
|
+
'the type checks can get weaker, and a type error could pass unseen'],
|
|
228
|
+
[[/^jest\.config\./, /^vitest\.config\./, 'pytest.ini'],
|
|
229
|
+
'which decides how the tests run',
|
|
230
|
+
'tests can be skipped or loosened, and a failure could go unseen'],
|
|
231
|
+
[['package.json', 'pom.xml', 'build.gradle', 'build.gradle.kts', 'pyproject.toml', 'Cargo.toml', 'go.mod'],
|
|
232
|
+
'which names the commands that test this project',
|
|
233
|
+
'those commands can change, and a failing test could read as a pass'],
|
|
234
|
+
];
|
|
235
|
+
/**
|
|
236
|
+
* Protected by being the lists themselves, so they are in no seed and stay outside `GATE_FILES`. Read
|
|
237
|
+
* at the repo root only: a `packages/a/.geneseed/done-checks.txt` someone listed feeds no gate.
|
|
238
|
+
* @type {[string, string, string][]}
|
|
239
|
+
*/
|
|
240
|
+
const GATE_LISTS = [
|
|
241
|
+
['.geneseed/protected-checks.txt', 'which lists the files this gate protects',
|
|
242
|
+
'a check can lose its protection, and nothing would tell you'],
|
|
243
|
+
['.geneseed/done-checks.txt', 'which lists the checks that must pass before work counts as done',
|
|
244
|
+
'work could count as done without passing a check'],
|
|
245
|
+
];
|
|
246
|
+
// Matches at any depth: a user may list `packages/a/tsconfig.json`, and it is still a tsconfig.
|
|
247
|
+
const gateIs = (rel, file) => {
|
|
248
|
+
if (typeof file !== 'string') return file.test(rel.slice(rel.lastIndexOf('/') + 1));
|
|
249
|
+
return file.endsWith('/') ? `/${rel}`.includes(`/${file}`) : `/${rel}`.endsWith(`/${file}`);
|
|
250
|
+
};
|
|
251
|
+
const GATE_FILE_OTHER = [null, 'which this project lists as a protected check',
|
|
252
|
+
'that check can get weaker or stop running, and a failure could go unseen'];
|
|
253
|
+
|
|
254
|
+
// `ruleGateTarget`'s answers: name, what it is, what the safe line calls it, whose call it is, impact.
|
|
255
|
+
// Memory has none: it is written freely (owner decision, 2026-11-08).
|
|
256
|
+
const GATE_RULE = ['this rule', 'what becomes a rule'];
|
|
257
|
+
const GATE_STORES = {
|
|
258
|
+
'user-rules.md': ['user-rules.md', 'your standing rules, which the agent obeys in every session', ...GATE_RULE,
|
|
259
|
+
'the text binds every later session until you remove it'],
|
|
260
|
+
'the rule draft': ['the rule draft', 'which can become one of your standing rules', ...GATE_RULE,
|
|
261
|
+
'the text can become a rule that binds every later session'],
|
|
262
|
+
'a hard link': ['a second name of a rule file', 'which writes to your standing rules or the rule draft', ...GATE_RULE,
|
|
263
|
+
'the text can bind every later session until you remove it'],
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// Bidi and zero-width marks too (`\p{C}`): they make a name read as something it is not. A double
|
|
267
|
+
// quote of any shape turns to `'`, or a name could seem to close its own quotes.
|
|
268
|
+
const gateStrip = (v) => String(v ?? '').replace(/[\p{C}\p{Zl}\p{Zp}]/gu, '').replace(/["\u201C-\u201F\uFF02]/g, "'").trim();
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* An agent-supplied value in the human part. Clipped in the middle, because the end of a path names
|
|
272
|
+
* the file. Quotes mark a name; they do not stop one reading like a sentence. `...` is ASCII so that
|
|
273
|
+
* clipping alone does not force the quotes.
|
|
274
|
+
*/
|
|
275
|
+
export function gateName(value) {
|
|
276
|
+
const c = [...gateStrip(value)];
|
|
277
|
+
const text = c.length > 60 ? `${c.slice(0, 20).join('')}...${c.slice(-37).join('')}` : c.join('');
|
|
278
|
+
return /^[A-Za-z0-9._/-]+$/.test(text) ? text : `"${text}"`;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const gatePath = (p) => String(p ?? '').replace(/\\/g, '/');
|
|
282
|
+
// Every line end a viewer may honour: a line break that this missed would hide a line from the count.
|
|
283
|
+
const gateLines = (text) => {
|
|
284
|
+
const lines = text.split(/\r\n|[\r\n\u2028\u2029]/);
|
|
285
|
+
if (lines[lines.length - 1] === '') lines.pop();
|
|
286
|
+
return lines;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* ` (+3 lines, -1 line)` from `editPairs`, or nothing when no line differs. Each pair loses its common
|
|
291
|
+
* leading and trailing lines. Exact for one changed region; with several it overstates, and it
|
|
292
|
+
* never hides a change. A pair says nothing of how often it applies, so a caller whose input has
|
|
293
|
+
* `replace_all`, at the top or in an `edits` entry, passes no pairs and no count shows: the agent sets
|
|
294
|
+
* that flag, and a 40-place edit must not read as `+1 line, -1 line`.
|
|
295
|
+
*/
|
|
296
|
+
export function gateCount(pairs) {
|
|
297
|
+
let added = 0;
|
|
298
|
+
let removed = 0;
|
|
299
|
+
for (const [before, after] of pairs) {
|
|
300
|
+
const a = gateLines(before);
|
|
301
|
+
const b = gateLines(after);
|
|
302
|
+
const most = Math.min(a.length, b.length);
|
|
303
|
+
let head = 0;
|
|
304
|
+
while (head < most && a[head] === b[head]) head += 1;
|
|
305
|
+
let tail = 0;
|
|
306
|
+
while (tail < most - head && a[a.length - 1 - tail] === b[b.length - 1 - tail]) tail += 1;
|
|
307
|
+
removed += a.length - head - tail;
|
|
308
|
+
added += b.length - head - tail;
|
|
309
|
+
}
|
|
310
|
+
const n = (sign, v) => `${sign}${v} line${v === 1 ? '' : 's'}`;
|
|
311
|
+
const parts = [...(added ? [n('+', added)] : []), ...(removed ? [n('-', removed)] : [])];
|
|
312
|
+
return parts.length ? ` (${parts.join(', ')})` : '';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const gateEdit = (f, shown, what) => `${f.shell ? 'This command writes to' : 'This edit changes'} ${shown}`
|
|
316
|
+
+ `${f.pairs ? gateCount(f.pairs) : ''}, ${what}.`;
|
|
317
|
+
|
|
318
|
+
const GATE_ELSEWHERE = 'This command runs on another repository, through --git-dir or --work-tree, which the gate did not read.';
|
|
319
|
+
const GATE_DO_IT = 'You can make this change yourself, outside the agent.';
|
|
320
|
+
const GATE_RUN_IT = 'You can run this command yourself, outside the agent.';
|
|
321
|
+
const GATE_EXTERNAL = { rule: 'External Gate', safe: 'Deny, unless you asked for this change.',
|
|
322
|
+
tail: 'do not write this file another way', can: GATE_DO_IT };
|
|
323
|
+
const GATE_LOSS = { rule: 'Deletion Is Deliberate', quote: true, can: GATE_RUN_IT };
|
|
324
|
+
|
|
325
|
+
// `quote` marks the only asks that may carry the agent's words. External Gate, Sealed Secrets and
|
|
326
|
+
// Persist Insight never do: there the agent's opinion is the conflict of interest.
|
|
327
|
+
const GATE_ASKS = {
|
|
328
|
+
check: (f) => {
|
|
329
|
+
const rel = gatePath(f.name);
|
|
330
|
+
const [, what, impact] = GATE_LISTS.find(([list]) => list === rel)
|
|
331
|
+
?? GATE_FILES.find(([files]) => files.some((n) => gateIs(rel, n))) ?? GATE_FILE_OTHER;
|
|
332
|
+
return { ...GATE_EXTERNAL, line: gateEdit(f, gateName(rel), what), impact,
|
|
333
|
+
why: 'the agent\'s own work is judged by this file' };
|
|
334
|
+
},
|
|
335
|
+
config: (f) => ({ ...GATE_EXTERNAL, line: gateEdit(f, gateName(gatePath(f.name)), 'which controls the gates that watch the agent'),
|
|
336
|
+
why: 'a gate the agent can edit is a gate it can switch off',
|
|
337
|
+
impact: 'a gate can stop working, and nothing would tell you' }),
|
|
338
|
+
store: (f) => {
|
|
339
|
+
const [name, what, label, owner, impact] = GATE_STORES[f.name] ?? GATE_STORES['user-rules.md'];
|
|
340
|
+
return { rule: 'Persist Insight', line: gateEdit(f, name, what), safe: `Deny, unless you asked for ${label}.`,
|
|
341
|
+
why: `${owner} is your decision`, impact, tail: 'ask the user; do not write it another way', can: GATE_DO_IT };
|
|
342
|
+
},
|
|
343
|
+
secret: (f) => ({ rule: 'Sealed Secrets', line: `This edit puts a credential-shaped string in ${gateName(gatePath(f.name))}.`,
|
|
344
|
+
safe: 'Deny, then keep the value in .env or a secret manager.',
|
|
345
|
+
why: 'a secret in a tracked file reaches everyone who can read the repository',
|
|
346
|
+
impact: 'the secret can land in a commit, and then it must be rotated',
|
|
347
|
+
tail: 'keep the value in .env; do not write it another way',
|
|
348
|
+
can: 'You can put the value in .env or a secret manager yourself.' }),
|
|
349
|
+
'force-push': (f) => ({ ...GATE_LOSS, line: `This command force-pushes the protected branch ${gateName(f.name)} on the remote.`,
|
|
350
|
+
safe: 'Deny, then push without --force.', why: 'a force push replaces the remote history',
|
|
351
|
+
impact: 'commits that exist only on the remote can be lost for everyone',
|
|
352
|
+
can: 'You can push without --force, or run this command yourself.' }),
|
|
353
|
+
'branch-delete': (f) => ({ ...GATE_LOSS, line: `This command deletes the protected branch ${gateName(f.name)}.`,
|
|
354
|
+
safe: 'Deny, unless you mean to remove this branch.', why: 'the project depends on a protected branch',
|
|
355
|
+
impact: 'commits that only this branch holds can be lost for everyone' }),
|
|
356
|
+
'remote-branches': () => ({ ...GATE_LOSS, line: 'This command rewrites or deletes many remote branches, protected ones included.',
|
|
357
|
+
safe: 'Deny, then push one named branch.', why: 'it makes the remote match this repository, branch by branch',
|
|
358
|
+
impact: 'branches and commits that exist only on the remote can be lost for everyone' }),
|
|
359
|
+
'discard-work': () => ({ ...GATE_LOSS, line: 'This command discards uncommitted changes that git cannot bring back.',
|
|
360
|
+
safe: 'Deny, then commit or stash the work first.', why: 'uncommitted work exists nowhere else',
|
|
361
|
+
impact: 'those changes are gone for good' }),
|
|
362
|
+
'lose-commits': () => ({ ...GATE_LOSS, line: 'This command drops commits that no remote and no other branch holds.',
|
|
363
|
+
safe: 'Deny, then keep them on a branch first.', why: 'those commits exist only here',
|
|
364
|
+
impact: 'only the reflog can bring them back, and only for a while' }),
|
|
365
|
+
// Git's safety net itself, so `lose-commits`' reflog line would be false here.
|
|
366
|
+
'drop-recovery': () => ({ ...GATE_LOSS, line: 'This command deletes the history git uses to recover lost commits.',
|
|
367
|
+
safe: 'Deny, unless you mean to give up that recovery.', why: 'it is the last copy of work lost earlier',
|
|
368
|
+
impact: 'commits lost earlier can never come back' }),
|
|
369
|
+
'delete-files': () => ({ ...GATE_LOSS, line: 'This command deletes files that git cannot restore.',
|
|
370
|
+
safe: 'Deny, unless you know these files can go.', why: 'git holds no copy of them',
|
|
371
|
+
impact: 'those files are gone for good' }),
|
|
372
|
+
unverified: () => ({ ...GATE_LOSS, line: 'This command may lose data, and the gate could not work out what it removes.',
|
|
373
|
+
safe: 'Deny, unless you have checked the command yourself.', why: 'the gate cannot read what this command touches',
|
|
374
|
+
impact: 'data that nothing else holds could be lost' }),
|
|
375
|
+
catastrophic: (f) => ({ ...GATE_LOSS,
|
|
376
|
+
line: `This command, ${gateName(f.name)}, would destroy a filesystem root, a drive, the home directory or a whole disk.`,
|
|
377
|
+
safe: 'Deny.', why: 'nothing could restore what it removes', impact: 'everything under that path is gone for good',
|
|
378
|
+
can: 'You can check what this command was meant to remove.' }),
|
|
379
|
+
'root-scan': (f) => ({ rule: 'Commands Must Return', quote: true, line: `This command, ${gateName(f.name)}, scans a whole filesystem root.`,
|
|
380
|
+
safe: 'Deny, then search a specific directory.', why: 'a whole root spans every drive',
|
|
381
|
+
impact: 'the scan can run for hours', tail: 'search one named directory',
|
|
382
|
+
can: 'You can name the directory to search.' }),
|
|
383
|
+
// Routine and frequent, so one line: three more would train the user to stop reading all of them.
|
|
384
|
+
commit: () => ({ rule: 'Consent Before Push', quote: true, short: true,
|
|
385
|
+
line: 'This command commits or pushes with git, which needs your approval each time.',
|
|
386
|
+
why: 'every commit and push is your decision', can: GATE_RUN_IT }),
|
|
387
|
+
// The next four are the OpenCode guard's alone: no hook reads a key path, a stream, a wiki manifest
|
|
388
|
+
// or an unknown tool's arguments, and the guard only refuses them. `wiki` has no rule to name.
|
|
389
|
+
'secret-file': (f) => ({ rule: 'Sealed Secrets', line: `This edit writes to ${gateName(gatePath(f.name))}, a file that holds a secret or key.`,
|
|
390
|
+
safe: 'Deny, then change this file yourself.', why: 'a secret or key file is never for the agent to write',
|
|
391
|
+
impact: 'the agent can replace a key that grants access', tail: 'leave this file alone', can: GATE_DO_IT }),
|
|
392
|
+
stream: (f) => ({ ...GATE_EXTERNAL, line: `This edit names ${gateName(gatePath(f.name))}, an NTFS stream that writes through to the file it hangs on.`,
|
|
393
|
+
safe: 'Deny, then have the agent name the file itself.', why: 'a stream hides which file really changes',
|
|
394
|
+
impact: 'a file can change with no gate seeing its name', tail: 'name the file itself' }),
|
|
395
|
+
wiki: (f) => ({ line: `This edit changes the protected wiki folder ${gateName(f.name)}.`,
|
|
396
|
+
safe: 'Deny, unless you asked for this change.', why: 'you marked this folder as closed to the agent',
|
|
397
|
+
impact: 'notes you protected can change', tail: 'leave this folder alone', can: GATE_DO_IT }),
|
|
398
|
+
'deep-args': (f) => ({ rule: 'Persist Insight', line: `The arguments of ${gateName(f.name)} nest too deep to read, so a write to your rules cannot be ruled out.`,
|
|
399
|
+
safe: 'Deny, unless you know what this call writes.', why: 'what the gate cannot read, it cannot clear',
|
|
400
|
+
impact: 'the call can write to your rules unseen', tail: 'ask the user; do not write it another way', can: GATE_DO_IT }),
|
|
401
|
+
// It reports a crash, not a change, so it has no rule to name.
|
|
402
|
+
'gate-error': (f) => ({ line: `Geneseed gate error: the check failed with ${gateName(f.name)}, so nothing judged this call.`,
|
|
403
|
+
safe: 'Deny, then run geneseed doctor.', why: 'a gate that crashed cannot say this call is safe',
|
|
404
|
+
impact: 'this call runs with no check at all', can: 'You can run geneseed doctor to find the fault.' }),
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* The text a gate shows, one sentence per line, so it reads the same if a host folds the newlines.
|
|
409
|
+
* `mode` is `ask` (a person can answer), `refused` (nothing can be allowed and the model is the only
|
|
410
|
+
* reader, so it must relay the words) or `warned` (the call runs anyway). `facts` is `name` (the path,
|
|
411
|
+
* branch, command excerpt, error or `ruleGateTarget` answer), `pairs` (`editPairs`, for the count),
|
|
412
|
+
* `shell` (reached through a command, which has no count), `says` (the call's own `description`) and
|
|
413
|
+
* `redirected` (`gateLoss`'s: the loss the text names was read from a repository the command leaves).
|
|
414
|
+
* The safe choice is line 2, so it stays in the part of a dialog that shows without scrolling. The
|
|
415
|
+
* caller adds the host's wrapping: Bob's `[geneseed]` prefix and `BOB_FINAL` are not here.
|
|
416
|
+
*/
|
|
417
|
+
export function gateText(id, mode, facts = {}) {
|
|
418
|
+
const a = GATE_ASKS[id](facts);
|
|
419
|
+
const tag = a.rule ? ` (${a.rule})` : '';
|
|
420
|
+
// After the safe choice, so that it keeps its place in the part of a dialog that shows.
|
|
421
|
+
const far = facts.redirected ? [GATE_ELSEWHERE] : [];
|
|
422
|
+
if (mode === 'warned') return `${a.line}${tag}\nThis ran without a prompt, because Bob has no approval step.`;
|
|
423
|
+
if (mode === 'refused') {
|
|
424
|
+
return [`Tell the user this, word for word: ${a.line}`, ...far, `It was refused because ${a.why}.${tag}`, a.can,
|
|
425
|
+
...(a.tail ? [`Agent: ${a.tail}.`] : [])].join('\n');
|
|
426
|
+
}
|
|
427
|
+
const c = [...(a.quote ? gateStrip(facts.says) : '')];
|
|
428
|
+
return [...(a.short ? [`${a.line}${tag}`]
|
|
429
|
+
: [a.line, `Safe choice: ${a.safe}${tag}`, ...far, `It asks because ${a.why}.`, `If you allow it, ${a.impact}.`]),
|
|
430
|
+
...(c.length ? [`The agent says (not checked): "${c.length > 100 ? `${c.slice(0, 97).join('')}...` : c.join('')}"`] : []),
|
|
431
|
+
...(a.tail ? [`Agent: if refused, ${a.tail}.`] : [])].join('\n');
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// Said when `gateText` itself fails. It fits every mode, so nothing about it can fail.
|
|
435
|
+
const GATE_UNSAID = 'Geneseed could not describe this call. Check what it does before you trust it.';
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* `gateText` that cannot throw, and the only way a gate reaches it. Every catch around a gate is a
|
|
439
|
+
* pass or a lesser verdict (`guardGate`, a shell reader, the guard's own), so a bug in the words would
|
|
440
|
+
* otherwise change what the gate decides.
|
|
441
|
+
*/
|
|
442
|
+
export function gateSafe(id, mode, facts) {
|
|
443
|
+
try { return gateText(id, mode, facts); } catch { return GATE_UNSAID; }
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// `lossReason`'s sentences, by their fixed parts only: the rest is the agent's command, so a pattern
|
|
447
|
+
// anchored there could be steered. Order matters: `git clean` ends in an agent's path.
|
|
448
|
+
/** @type {[RegExp, string][]} */
|
|
449
|
+
const GATE_LOSS_REASONS = [
|
|
450
|
+
[/^the gate could not verify /, 'unverified'],
|
|
451
|
+
[/^`git push --(?:mirror|prune)` |^a forced `git push --all` /, 'remote-branches'],
|
|
452
|
+
[/^`git push` would force-push the protected branch (.+)$/, 'force-push'],
|
|
453
|
+
[/^`git (?:push|branch -D)\b.* (?:would delete|deletes) the protected branch (.+)$/, 'branch-delete'],
|
|
454
|
+
[/^`git clean` would delete untracked files | which (?:nothing could|git cannot) restore$| deletes git's own data$| deletes a whole repository or worktree$/, 'delete-files'],
|
|
455
|
+
[/ would discard uncommitted changes \(.*\)$| deletes stashed work$/, 'discard-work'],
|
|
456
|
+
[/ recovery depends on$/, 'drop-recovery'],
|
|
457
|
+
[/ holds$/, 'lose-commits'],
|
|
458
|
+
];
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* The `gateText` id, branch and `redirected` flag for a `lossReason` sentence. One this table does not
|
|
462
|
+
* know reads as `unverified`, the most cautious text; tests/unit/gate_text.test.mjs holds every
|
|
463
|
+
* sentence to an id.
|
|
464
|
+
*/
|
|
465
|
+
export function gateLoss(reason) {
|
|
466
|
+
const direct = reason.replace(/ \(and --git-dir\/--work-tree points it at a repository the gate did not read\)$/, '');
|
|
467
|
+
const redirected = direct !== reason;
|
|
468
|
+
const text = direct.replace(/ on the protected branch \S*$/, '');
|
|
469
|
+
for (const [re, id] of GATE_LOSS_REASONS) {
|
|
470
|
+
const m = re.exec(text);
|
|
471
|
+
if (m) return { id, name: m[1], redirected };
|
|
472
|
+
}
|
|
473
|
+
return { id: 'unverified', redirected };
|
|
474
|
+
}
|
|
475
|
+
// ---- gate text twin: END
|
|
476
|
+
|
|
207
477
|
const OFF = ['off', '0', 'false', 'no'];
|
|
208
478
|
|
|
209
479
|
/**
|