geneseed 5.1.1 → 5.3.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 +52 -0
- package/README.md +2 -2
- package/SHIPPED.md +1 -1
- package/adapters/opencode/README.md +4 -3
- package/adapters/opencode/plugins/geneseed-context.js +82 -29
- package/adapters/opencode/plugins/geneseed-guard.js +118 -8
- package/bin/geneseed-cli.mjs +64 -16
- package/bin/geneseed-hook.mjs +37 -3
- package/docs/concepts/exclusions.md +1 -1
- package/docs/concepts/factories.md +40 -6
- package/docs/concepts/footprint.md +1 -1
- package/docs/concepts/foreman-mode.md +2 -2
- package/docs/concepts/host-matrix.md +1 -1
- 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 +140 -0
- package/docs/extending.md +54 -162
- package/docs/guides/run-a-factory.md +15 -2
- package/docs/guides/setup-doctrines.md +1 -1
- package/docs/guides/upgrade.md +2 -2
- package/docs/reference/factory-actions.md +6 -5
- package/docs/reference/troubleshoot-update.md +1 -1
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/web-ui.md +16 -3
- package/harness.config.json +1 -1
- package/js/README.md +10 -7
- package/js/build/args.mjs +10 -4
- package/js/build/bundle.mjs +122 -23
- package/js/build/driver.mjs +32 -12
- package/js/build/emit-claude.mjs +2 -1
- package/js/build/emit-common.mjs +2 -2
- package/js/build/emit-opencode.mjs +22 -10
- package/js/build/export.mjs +431 -0
- package/js/build/generate.mjs +3 -0
- package/js/build/render.mjs +44 -24
- package/js/build/source.mjs +6 -1
- package/js/cli-table.json +232 -57
- 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/hooks-context.mjs +26 -1
- package/js/hosts/hooks-done.mjs +8 -2
- package/js/hosts/hooks-prims.mjs +52 -3
- package/js/hosts/hooks.mjs +155 -33
- package/js/hosts/hosts.mjs +2 -4
- package/js/hosts/installs.mjs +28 -0
- package/js/hosts/loss.mjs +25 -3
- package/js/hosts/native.mjs +30 -2
- package/js/hosts/owned.mjs +55 -1
- package/js/hosts/ownership-gate.mjs +5 -5
- package/js/hosts/settings.mjs +83 -33
- package/js/inspect/diff.mjs +16 -1
- package/js/inspect/doctor.mjs +7 -3
- package/js/inspect/excludes.mjs +18 -6
- package/js/inspect/status.mjs +35 -7
- package/js/inspect/validate.mjs +44 -21
- package/js/lib/managed-block.mjs +74 -0
- package/js/maintain/uninstall.mjs +85 -15
- 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 +5 -0
- package/js/web/api.mjs +32 -11
- 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-CqJiquEq.js +1 -0
- package/web/dist/assets/ActivityDetail-BSzevynX.js +1 -0
- package/web/dist/assets/{Bonsai-hiG_gGNU.js → Bonsai-Bfpb6W-1.js} +1 -1
- package/web/dist/assets/{CopyButton-DUIUfNp6.js → CopyButton-ByIntFtB.js} +1 -1
- package/web/dist/assets/Dashboard-DBOEi9lQ.js +2 -0
- package/web/dist/assets/Docs-DvlMJhpu.js +5 -0
- package/web/dist/assets/Factories-Bpvv7L2H.js +1 -0
- package/web/dist/assets/{GreenhouseView-BKxy5apE.js → GreenhouseView-GpBsYn50.js} +1 -1
- package/web/dist/assets/Installs-BlGmVrFK.js +3 -0
- package/web/dist/assets/{JournalView-ChFitHjo.js → JournalView-iLuLrOxE.js} +1 -1
- package/web/dist/assets/Kits-DRwpxC-J.js +1 -0
- package/web/dist/assets/Laws-CZkiNOWQ.js +4 -0
- package/web/dist/assets/LibRows-DEHjIoD-.js +1 -0
- package/web/dist/assets/Library-B4K-1iNF.js +3 -0
- package/web/dist/assets/Loops-BWSzaW8E.js +2 -0
- package/web/dist/assets/{OperatorHudView-BO0aIKPL.js → OperatorHudView-BAXwCEvY.js} +1 -1
- package/web/dist/assets/Personal-Bp9nV4GR.js +2 -0
- package/web/dist/assets/Settings-CWWuaIp-.js +1 -0
- package/web/dist/assets/Tabs-CWeQTADL.js +1 -0
- package/web/dist/assets/index-CsAZq0BQ.css +1 -0
- package/web/dist/assets/index-How7SzDZ.js +6 -0
- package/web/dist/assets/usePoll-D5c_qIFZ.js +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/ActiveLoops-BTHIaRhn.js +0 -1
- package/web/dist/assets/Activity-CpkBwpu7.js +0 -1
- package/web/dist/assets/ActivityDetail-DTPziZWM.js +0 -1
- package/web/dist/assets/Dashboard-Dnw6EyX7.js +0 -2
- package/web/dist/assets/Docs-BEET_l16.js +0 -5
- package/web/dist/assets/Factories-D6KXkfWw.js +0 -1
- package/web/dist/assets/Installs-CnFVlVD0.js +0 -3
- package/web/dist/assets/Kits-CcR-OlwQ.js +0 -1
- package/web/dist/assets/Laws-B1s5idOg.js +0 -4
- package/web/dist/assets/LibRows-BZgdbI1l.js +0 -1
- package/web/dist/assets/Library-x6TkkEVF.js +0 -3
- package/web/dist/assets/Loops-BH93KKxn.js +0 -2
- package/web/dist/assets/Personal-CE_0Vhh0.js +0 -2
- package/web/dist/assets/Settings-CbpZvVN_.js +0 -1
- package/web/dist/assets/Tabs-C2oW7oEj.js +0 -1
- package/web/dist/assets/index-BQwOmbor.js +0 -6
- package/web/dist/assets/index-CuIop_pO.css +0 -1
- package/web/dist/assets/usePoll-o8ul-Sog.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,58 @@ label. For the capability ↔ spec map, see [SHIPPED.md](SHIPPED.md).
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [5.3.0] — 2026-11-11
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- **A factory run records its times, and `geneseed factory report` prints its numbers.** `init` stamps `started`, and `record` and `decide` stamp `at` on their history entry. `record --tokens <n>` stores the token count the host reported for the stage's agent; nothing estimates one, and there is no cost in money. `report` is read-only and prints one JSON object: per stage its runs, its reworks (an outcome that spent a cycle), its work time and its tokens, and for the run its work time, the time it waited at human gates, its tokens and its transitions. A number nobody recorded is `null`, never 0, so a `FACTORY.md` written before this release still validates and still runs. The `retro` brick and the Rite's stop report copy those numbers, and `retro` adds how many rounds each `review-panel` seat failed.
|
|
15
|
+
- **The factory queue.** Ask the agent for the queue, or name no work item: the `factory` Rite lists the open issues that carry the label `factory` (or the label you name) and you pick one, several or all. Several picks run in sequence, each as its own run in its own worktree with its own merge question; a run that holds a gate holds the queue. No config file, and nothing starts a run by itself.
|
|
16
|
+
- **`intake` can refuse a work item.** The new outcome `reject` holds the gate when the item is already done, a duplicate, or against a rule the project states, with the reason and its evidence: `ok` accepts the refusal and stops the run, `amend` re-runs `intake` with your reason to build it, `no` stops. The three shipped factories route `reject` to `$stop`. A factory with no `reject` edge still passes `check` and stops the same way, so a factory of your own, and a run already in flight, need no change. `reject` names no lane: `intake` stays a plain stage.
|
|
17
|
+
- **Factories › Active is a board.** With no run selected, the console shows every registered run as a card in three columns: **Waits for you** (a held gate, or a `FACTORY.md` that cannot be read), **Running**, and **Ended**. A card gives, on one line, where the run stands (a held gate as `stage · outcome`), its task as `i/n`, its work time, the wait still open at its gate, and each cycle spent above 0 as `name n/max`; the list rows carry the same line, and the list's header names an open run by its title, not its root path. `geneseed factory report` and the board add `openWaitMs`, the wait still open at a held gate, measured to the time of the call or the poll. A card opens the run, which gains a timeline: each history entry with its outcome or your answer, its time, its duration and a rework mark, and for a held run the gate's stage, outcome and the path of its note. `GET /api/factories/active` adds `metrics` to each live run. The board is read-only: you answer a gate in the agent's session. Its poll no longer writes `factories.json` either (it used to stamp a closed run and drop old rows every 5 s, and could race a `factory init`): `geneseed factory init` now does that tidying, dropping a run whose worktree is gone and a closed run 7 days after an init first saw it closed.
|
|
18
|
+
- **`geneseed --version`, `help [verb]`, and a nearest match for a mistyped verb.** `geneseed stauts` answers `unknown command 'stauts'. Did you mean 'status'?`. `build --help` and `validate --help` list every flag with its choices, read from the generator instead of a copy. A verb's long help moved to a `description` its own `--help` and the console's CLI page show; top-level help is one line per verb.
|
|
19
|
+
- **`doctor` prints one progress line per theme on stderr during a sweep.** stdout is unchanged.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- **The always-on catalogue is about 1 500 tokens lighter.** Every theme's skill and agent purpose line is about 40-60 characters, followed by the unchanged "Use when" trigger; the ten council seats are one line each. Measured on a Claude emit, imperial: 17 964 -> about 12 100 characters.
|
|
23
|
+
- **The lean root is lighter and says one thing about commits.** Consent Before Push gains a batch for a dispatched worker, crew or slice: it commits in its own worktree, never pushes, never merges outside its own branch. The commit, pipeline and parallel-agents Rites, the developer spec and Foreman mode now agree, and a Rite never loosens a Doctrina. Repeated always-on text is trimmed, and three clauses the lean text had lost are back.
|
|
24
|
+
- **Lean drops the Latin rule names and the section epigraphs.** `### Dictate I — Sealed Secrets` instead of `— Arcana Sigillata · Sealed Secrets`; the full footprint and the on-disk `laws/` and `doctrines/` keep the voice. The two "given in brief" notes are one. About -400 tokens on the imperial theme.
|
|
25
|
+
- **SessionStart and SubagentStart no longer send the untouched `user-rules.md` seed explanation** above your first rule (1 690 -> 315 bytes for a seed with two rules), on Claude Code and in the OpenCode context plugin. Text you wrote above your rules is still sent.
|
|
26
|
+
- **`status` piped or redirected prints no box and no padding** (4 783 -> 1 378 bytes on a typical machine).
|
|
27
|
+
- **`version`, `diff` and `uninstall` default to the one install there is.** With several global installs and no `--target`, `uninstall` refuses with exit 2 and lists the targets, also with `--yes`. On a machine with only a Claude install, `uninstall --yes` now removes it (it used to aim at an empty OpenCode folder and exit 1).
|
|
28
|
+
- **`tui` is retired and `bootstrap` is `upgrade --setup`.** Both still work for one release: `tui` points at `geneseed menu`, `bootstrap` prints a deprecation line and runs the same flow. `upgrade --theme NAME` is added.
|
|
29
|
+
- CI runs the Ubuntu suite once under c8 instead of a separate coverage job, and a new `suite-count` job requires the Windows shards' summed test count to reach the whole-suite floor.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
- **A very long command no longer outruns the hook gates.** Two gate regexes were quadratic: a 540 KB command took about 80 s, past the host's hook time-out, and the call went through unguarded. Both are linear with the same verdicts, and a command over 64 KB makes the gate ask before it reads it. The OpenCode guard gets the same regex.
|
|
33
|
+
- **A large `apply_diff` (Bob) no longer outruns the secrets gate.** The diff is read in one pass, and a diff over 64 KB asks.
|
|
34
|
+
- **A gate whose module fails to load asks instead of letting the call through.** A non-gate verb that fails writes one line on stderr and stays silent on stdout.
|
|
35
|
+
- **The console no longer freezes for about 12 s after a job.** The doctor runs on a worker thread for the daemon and for every per-install view (the Doctor page), and a worker that dies records a failed verdict instead of respawning on every poll.
|
|
36
|
+
- Console: truncated labels show their full text on hover; a failed Ledger read says why and offers a Retry that keeps focus; polls that return the same data no longer re-render; a Popover closes when Tab leaves it; the Loops jump respects reduced motion; a failed profile read says so.
|
|
37
|
+
|
|
38
|
+
## [5.2.0] — 2026-11-10
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
- **OpenCode: a gate whose rule you switch off is removed from `opencode.json`.** The install manifest now records the `permission.bash` entries Geneseed itself added (`bash_gates`). A rebuild with the process pack off, with *Consent Before Push* excluded or with `--no-deletion-gate` removes the recorded entries that still read as Geneseed wrote them. An entry that was already in the file, or that you changed, stays and is named in the warning. A commented `opencode.jsonc` is still never rewritten: the build names the entries to remove.
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
- **`geneseed export --out <folder> [--profile <file>]`** writes the skills, the agents and the constitution as catalogue entities for a shared library that is not a Geneseed install: one folder each, with `SKILL.md` or `AGENT.md` (frontmatter `name` and `description` only) and a `metadata.yaml` (type, owner, maintainer, version, status, compatible tools, licence and origin of a credited port, `requires`). A reference to another exported entity takes its exported name and becomes a requirement; a skill's side files move under `references/`; the constitution is one `laws` entity that every citing entity requires, written as one file per category (`ontology.md`, `laws.md`, `doctrines-<pack>.md`) behind a `LAWS.md` index. The profile, a JSON file, carries the library's own values (name prefix, owner, maintainer, folder names, `only`/`exclude`); a git checkout's `export.profile.json` is the default, `--profile none` ignores it, and the npm package does not carry it. One way: `src/` stays the source. Vendored folder skills and aliases are not exported, and are named.
|
|
45
|
+
- **`geneseed build --force`** takes Geneseed's copy of every file it ships, for that one build. It replaces a shipped file you edited and a file of yours at a shipped name, removes a retired file you edited, and removes retired skills an older build left in a bundle. Every file is named. A skill or agent under a name Geneseed does not ship is never touched, nor are memory, the notebook, your rules or your profile. To keep your own file at a shipped name for good, use `--exclude-skills`.
|
|
46
|
+
- **The console says when an install holds files a rebuild keeps.** Each emit records them (`kept` in the manifest, `kept` and `stale` in a bundle's `.geneseed-srcdirs.json`), `/api/installs` returns them as `leftovers`, and the install's panel lists them with a **Replace with Geneseed's copies…** button that runs the forced rebuild behind a confirm naming each file.
|
|
47
|
+
- **`geneseed build --prune-gates`**, for an install made before this release, which has the gates and no record. For that one build it removes every such entry still set as Geneseed writes it; an entry you changed stays. No rebuild replays it. Take the install's `rebuild` command from `geneseed status --json` and add the flag.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
- **OpenCode: the change report is posted once, however many projects are open.** One `opencode serve` loads the guard plugin once per opened project and every instance hears every session, so a rule or memory change was reported once per project: four projects, four identical messages. The instances now share a marker per change, and the first to claim it reports.
|
|
51
|
+
- **A destructive command hidden behind an escaped quote or a line continuation is read as what it is.** `echo 'it'\''s done' && rm -rf /` and `rm -rf \⏎ /` passed every gate, because the gates' lexers treat a backslash as an ordinary character. Every Bash gate, on Claude, Bob and OpenCode, now reads one normalised form of the command (`shellReading`): continuations joined, an escaped quote or separator made inert. PowerShell commands keep their backslashes.
|
|
52
|
+
- **The loss gate no longer looks in the wrong folder after `popd` or a `cd` inside `( … )`.** The directory is unknown from there on, so a relative removal asks.
|
|
53
|
+
- **Consent Before Push asks for a commit or a push, not for the words.** `git log | grep push`, `cat .git/hooks/pre-commit.sample`, `git stash push` and `git diff -- docs/commit-style.md` no longer ask. The ask stands unless every segment is a program that only reads or `git` with a read verb.
|
|
54
|
+
- **The done gate no longer accepts `npm test; echo "exit: $?"`,** a check run in the background (`npm test &`), or one behind `||`.
|
|
55
|
+
- **The managed block is found the same way by every reader.** The hook-side readers and the OpenCode plugins still matched a marker anywhere in a line after the writer stopped doing so; one module now defines it.
|
|
56
|
+
- `tests/mutate.mjs` requires a mode and refuses anything else (`--help` used to start the matrix, which edits product files), and restores a file an interrupted run left mutated.
|
|
57
|
+
- **An OpenCode project install no longer deletes the user's own `agents/`, `skills/`, `laws/` or `AGENT.md` at the repository root.** The bundle now records each file it writes (in `.geneseed-srcdirs.json`) and owns only those: a file already there is kept and named in a warning, a rebuild prunes only recorded files, and uninstall removes only recorded files. Before, the second emit wiped those folders and uninstall deleted them whole. A bundle built by an older version has no record: the next build overwrites what it ships, removes nothing, starts the record, and names any retired skill it left behind (`--force` removes those).
|
|
58
|
+
- **`geneseed uninstall` on an OpenCode project no longer deletes `.opencode/` on a retry.** A file of the user's under `.opencode/` made the first pass report INCOMPLETE with the manifest already removed, and the retry it advised then removed the whole folder. The uninstall now completes in one pass and leaves the user's files, and the whole-folder removal kept for pre-manifest installs runs only where the root still carries a bundle marker.
|
|
59
|
+
- **The managed block in `CLAUDE.md` / `AGENTS.md` is found by whole-line markers.** A sentence that mentioned `<!-- BEGIN GENESEED -->` was taken for the block's start, and the next emit silently deleted everything from that sentence to the real block.
|
|
60
|
+
- **Editing a shipped `SKILL.md` no longer makes the next emit delete that skill's side files and licence files.**
|
|
61
|
+
- `tests/unit/sandbox.test.mjs` no longer fails when run as root.
|
|
62
|
+
|
|
11
63
|
## [5.1.1] — 2026-11-10
|
|
12
64
|
|
|
13
65
|
### Added
|
package/README.md
CHANGED
|
@@ -166,7 +166,7 @@ Full reference — every view, the launch/daemon/PWA surface, the security model
|
|
|
166
166
|
|
|
167
167
|
### ⌨️ Terminal — `geneseed`
|
|
168
168
|
|
|
169
|
-
No browser? Every action the console offers is also a verb: `build`, `doctor`, `diff`, `rebuild-all`, `status`, `memory`, `catalog`, `exclude`, `mcp`, `link`/`unlink`, `uninstall` (global **or** per-repo). `geneseed setup` runs the install wizard — plain text prompts, every console, every OS; see [Setup](#-2--setup) above for the walkthrough. `geneseed --help` lists every command, and bare `geneseed` (or `./geneseed`) opens the web console when it can, else prints the command list. There is no full-screen panel: `
|
|
169
|
+
No browser? Every action the console offers is also a verb: `build`, `doctor`, `diff`, `rebuild-all`, `status`, `memory`, `catalog`, `exclude`, `mcp`, `link`/`unlink`, `uninstall` (global **or** per-repo). `geneseed setup` runs the install wizard — plain text prompts, every console, every OS; see [Setup](#-2--setup) above for the walkthrough. `geneseed --help` lists every command, and bare `geneseed` (or `./geneseed`) opens the web console when it can, else prints the command list. There is no full-screen panel: `menu` prints the command list (`tui` is retired, and says so).
|
|
170
170
|
|
|
171
171
|
---
|
|
172
172
|
|
|
@@ -336,7 +336,7 @@ geneseed rebuild-all # re-render every registered install in its own theme + m
|
|
|
336
336
|
|
|
337
337
|
```bash
|
|
338
338
|
./geneseed update # everything in one: refresh the scripts + content, then rebuild
|
|
339
|
-
./geneseed
|
|
339
|
+
./geneseed upgrade --setup # update everything, then drop into the setup wizard (was: bootstrap)
|
|
340
340
|
./geneseed upgrade # just the content refresh (remembers theme + emit mode)
|
|
341
341
|
```
|
|
342
342
|
|
package/SHIPPED.md
CHANGED
|
@@ -20,7 +20,7 @@ historical references, not files distributed with the repo.
|
|
|
20
20
|
> **On version numbers.** [`harness.config.json`](harness.config.json)'s `version` is a
|
|
21
21
|
> human-readable label only. The canonical identity of an installed harness is the
|
|
22
22
|
> **source fingerprint** stamped in `.geneseed-version` (see `geneseed version`), not the
|
|
23
|
-
> string. Current label: **5.
|
|
23
|
+
> string. Current label: **5.3.0**.
|
|
24
24
|
|
|
25
25
|
## Capabilities
|
|
26
26
|
|
|
@@ -412,9 +412,10 @@ behaviour** — nothing changes the machine's current agent/model unless you opt
|
|
|
412
412
|
agent never records or shares code unprompted, on any branch). Build with
|
|
413
413
|
`--doctrines` leaving `process` out and those two entries are simply not written.
|
|
414
414
|
The whole block is added only when you have no `permission` key; an existing policy is
|
|
415
|
-
reconciled key by key — Geneseed adds back what a returning pack wants and
|
|
416
|
-
|
|
417
|
-
rebuild leaves a `git commit*` you
|
|
415
|
+
reconciled key by key — Geneseed adds back what a returning pack wants and removes
|
|
416
|
+
**only what the manifest records it adding** (`bash_gates`) and that still reads as it
|
|
417
|
+
wrote it. A pack-off rebuild leaves a `git commit*` you typed, or one from an install made
|
|
418
|
+
before 5.2.0, in place and reports it; `--prune-gates` on one build removes the latter. Routine local work
|
|
418
419
|
(edits, builds, tests) is unaffected; to allow frictionless commits/pushes, set
|
|
419
420
|
`"git commit*"` / `"git push*"` to `"allow"` in your own `permission.bash` map. (Note:
|
|
420
421
|
OpenCode lets a user pick "always allow" for the session, which makes the gate
|
|
@@ -284,12 +284,38 @@ async function draftLine() {
|
|
|
284
284
|
} catch { return null }
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
// ---- rules preamble twin: BEGIN — adapters/opencode/plugins/geneseed-context.js carries everything
|
|
288
|
+
// down to the END marker verbatim, with `export ` dropped (node tests/twins.mjs --write keeps it).
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* SHA-256 of the `user-rules.md` seed with its trailing newlines trimmed: the explanation every
|
|
292
|
+
* rules file starts with, until its owner edits it. Hashed, not imported, for `SEED_SHA256`'s
|
|
293
|
+
* reason; tests/unit/claude.test.mjs derives it from `SESSION_SEEDS`.
|
|
294
|
+
*/
|
|
295
|
+
const RULES_PREAMBLE_SHA256 = 'd6973e837c9bf25b50ce068832ceef0a5e5ed2b5931c2c488428ad68aad758c3';
|
|
296
|
+
// A rule's heading, at column 0: the seed's own example (` ## R1 — …`) is indented.
|
|
297
|
+
const RULE_HEADING_RE = /^## R\d+\b/m;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* `text` from its first rule on, when the text above that rule is still the seed's, byte for byte
|
|
301
|
+
* once CRLF is folded: the seed explains the file to its owner, and it cost 1 331 of 4 474
|
|
302
|
+
* characters at every session and sub-agent start. Any prose the owner wrote above the rules stays.
|
|
303
|
+
*/
|
|
304
|
+
function withoutRulesPreamble(text) {
|
|
305
|
+
const rule = RULE_HEADING_RE.exec(text);
|
|
306
|
+
const head = rule ? text.slice(0, rule.index).replace(/\n+$/, '') : null;
|
|
307
|
+
return head !== null && createHash('sha256').update(head).digest('hex') === RULES_PREAMBLE_SHA256
|
|
308
|
+
? text.slice(rule.index) : text;
|
|
309
|
+
}
|
|
310
|
+
// ---- rules preamble twin: END
|
|
311
|
+
|
|
287
312
|
// A session file's text, CRLF-folded and trimmed; null when missing, unreadable or still its seed.
|
|
313
|
+
// A rules file's seed explanation above its first rule is dropped, as on the hook.
|
|
288
314
|
async function sessionText(abs) {
|
|
289
315
|
let text
|
|
290
316
|
try { text = (await fs.readFile(abs, "utf8")).replace(/\r\n/g, "\n") } catch { return null }
|
|
291
317
|
if (SEED_SHA256.has(createHash("sha256").update(text).digest("hex"))) return null
|
|
292
|
-
return text.replace(/\n+$/, "")
|
|
318
|
+
return withoutRulesPreamble(text).replace(/\n+$/, "")
|
|
293
319
|
}
|
|
294
320
|
|
|
295
321
|
// Session files in force for the harness dir, changed from their seed: [{ rel, abs, text, label }],
|
|
@@ -947,6 +973,22 @@ async function cachedBlockText(root, cache) {
|
|
|
947
973
|
return text
|
|
948
974
|
}
|
|
949
975
|
|
|
976
|
+
// Per INSTANCE, as `cache` above, and keyed by directory: `sovereignBypass` (two JSON reads)
|
|
977
|
+
// and `doneChecksOf` (manifest reads) ran on EVERY request while the block they gate is cached
|
|
978
|
+
// for BLOCK_TTL_MS, so they get the same TTL. A rejection is not kept: the next call retries.
|
|
979
|
+
function ttlMemo(fn) {
|
|
980
|
+
const hits = new Map()
|
|
981
|
+
return (key) => {
|
|
982
|
+
const now = Date.now()
|
|
983
|
+
const hit = hits.get(key)
|
|
984
|
+
if (hit && now - hit.at < BLOCK_TTL_MS) return hit.p
|
|
985
|
+
const p = Promise.resolve().then(() => fn(key))
|
|
986
|
+
hits.set(key, { p, at: now })
|
|
987
|
+
p.catch(() => { if (hits.get(key)?.p === p) hits.delete(key) })
|
|
988
|
+
return p
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
950
992
|
// ---- cross-instance idempotency ----------------------------------------------
|
|
951
993
|
async function alreadyInjected(client, sid) {
|
|
952
994
|
try {
|
|
@@ -1192,7 +1234,8 @@ async function doneLine(dir, judged = true) {
|
|
|
1192
1234
|
const OWN_MANIFESTS = new Set(["package.json", "pom.xml", "pyproject.toml", "go.mod", "Cargo.toml",
|
|
1193
1235
|
"composer.json", "Gemfile"])
|
|
1194
1236
|
const isOwnManifest = (n) => OWN_MANIFESTS.has(n) || n.startsWith("build.gradle") || n.endsWith(".csproj")
|
|
1195
|
-
|
|
1237
|
+
// Whole-line markers: js/lib/managed-block.mjs BLOCK_RE_SOURCE, by value (a plugin imports nothing).
|
|
1238
|
+
const OWN_BLOCK_RE = /^<!-- BEGIN GENESEED -->[ \t]*\r?\n[\s\S]*?^<!-- END GENESEED -->[ \t]*\r?$/gm
|
|
1196
1239
|
const OWN_SECTION_RE = /^## Ownership[ \t]*\r?$/m
|
|
1197
1240
|
const OWN_DECLINED_RE = /^Setup:[ \t]*declined[ \t]+(\d{4}-\d{2}-\d{2})[ \t]*\r?$/m
|
|
1198
1241
|
let ownershipGateOffOnce = null
|
|
@@ -1230,30 +1273,36 @@ async function runtimeFloorLine(dir) {
|
|
|
1230
1273
|
}
|
|
1231
1274
|
|
|
1232
1275
|
function runsUnpiped(command, line) {
|
|
1233
|
-
const cmd = String(command).replace(/[ \t]+/g,
|
|
1276
|
+
const cmd = String(command).replace(/[ \t]+/g, ' ');
|
|
1234
1277
|
for (let i = cmd.indexOf(line); i !== -1; i = cmd.indexOf(line, i + 1)) {
|
|
1235
|
-
const next = cmd[i + line.length]
|
|
1236
|
-
if (next !== undefined && !/[\s;&|]/.test(next)) continue
|
|
1237
|
-
const head = cmd.slice(0, i)
|
|
1238
|
-
|
|
1239
|
-
|
|
1278
|
+
const next = cmd[i + line.length];
|
|
1279
|
+
if (next !== undefined && !/[\s;&|]/.test(next)) continue;
|
|
1280
|
+
const head = cmd.slice(0, i);
|
|
1281
|
+
// Not after `||`: `true || npm test` never runs the check.
|
|
1282
|
+
if (!/(^|&&|(?<!\|)\|(?!\|)|;|\n) ?$/.test(head.replace(/\|\| ?$/, '\u0000'))) continue;
|
|
1283
|
+
let quote = '', esc = false;
|
|
1240
1284
|
for (const ch of head) {
|
|
1241
|
-
if (esc) esc = false
|
|
1242
|
-
else if (ch ===
|
|
1243
|
-
else if (quote) { if (ch === quote) quote =
|
|
1244
|
-
else if (ch === '"' || ch === "'") quote = ch
|
|
1285
|
+
if (esc) esc = false;
|
|
1286
|
+
else if (ch === '\\' && quote !== "'") esc = true;
|
|
1287
|
+
else if (quote) { if (ch === quote) quote = ''; }
|
|
1288
|
+
else if (ch === '"' || ch === "'") quote = ch;
|
|
1245
1289
|
}
|
|
1246
|
-
if (quote) continue
|
|
1247
|
-
const rest = cmd.slice(i + line.length)
|
|
1248
|
-
let piped = false
|
|
1290
|
+
if (quote) continue;
|
|
1291
|
+
const rest = cmd.slice(i + line.length);
|
|
1292
|
+
let piped = false;
|
|
1249
1293
|
for (let j = 0; j < rest.length; j += 1) {
|
|
1250
|
-
const two = rest.slice(j, j + 2)
|
|
1251
|
-
if (two ===
|
|
1252
|
-
if (rest[j] ===
|
|
1294
|
+
const two = rest.slice(j, j + 2);
|
|
1295
|
+
if (two === '&&' || two === '||' || rest[j] === ';' || rest[j] === '\n') break;
|
|
1296
|
+
if (rest[j] === '|') { piped = true; break; }
|
|
1253
1297
|
}
|
|
1254
|
-
|
|
1298
|
+
// MASKED when the line's exit status is not the check's: a `||` after it; behind `;` or a
|
|
1299
|
+
// newline, a command that always succeeds (`true`, `:`, `exit`, and `echo`/`printf`, as in
|
|
1300
|
+
// the common `npm test; echo "exit: $?"`, which exits 0 on a red suite); or a trailing lone
|
|
1301
|
+
// `&`, which backgrounds the check. A real next command is not a mask, and `&&` keeps the status.
|
|
1302
|
+
const masked = /\|\||[;\n] ?(?:true|:|exit(?: 0)?|(?:echo|printf)(?: [^;&|\n]*)?)(?= ?(?:$|[;&|\n]))|(?<!&)& ?$/.test(rest);
|
|
1303
|
+
if (!piped && !masked) return true;
|
|
1255
1304
|
}
|
|
1256
|
-
return false
|
|
1305
|
+
return false;
|
|
1257
1306
|
}
|
|
1258
1307
|
|
|
1259
1308
|
// The twin of hooks-done.mjs's `groupPasses`: a form runs unpiped, and no flag in `refuse`
|
|
@@ -1365,6 +1414,8 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1365
1414
|
const done = new Set()
|
|
1366
1415
|
const root = repoRoot(ctx)
|
|
1367
1416
|
const blockCache = { text: null, at: 0 }
|
|
1417
|
+
const bypassed = ttlMemo(sovereignBypass)
|
|
1418
|
+
const doneChecks = ttlMemo(doneChecksOf)
|
|
1368
1419
|
|
|
1369
1420
|
// Visible delivery — post the block as a noReply session message. Used when
|
|
1370
1421
|
// GENESEED_CONTEXT_VISIBLE forces it, and by the transform fallback below.
|
|
@@ -1423,7 +1474,7 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1423
1474
|
|
|
1424
1475
|
event: async ({ event }) => {
|
|
1425
1476
|
if (!event || INJECT_OFF) return
|
|
1426
|
-
if (await
|
|
1477
|
+
if (await bypassed(root)) return
|
|
1427
1478
|
const sid =
|
|
1428
1479
|
event.properties?.sessionID ?? event.payload?.sessionID ??
|
|
1429
1480
|
event.properties?.info?.id ?? event.payload?.info?.id
|
|
@@ -1452,7 +1503,7 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1452
1503
|
// OpenCode hook; if it is absent in a build this key is simply never called.
|
|
1453
1504
|
"experimental.session.compacting": async (_input, output) => {
|
|
1454
1505
|
if (INJECT_OFF || (TRANSFORM && !fallbackVisible)) return
|
|
1455
|
-
if (await
|
|
1506
|
+
if (await bypassed(root)) return
|
|
1456
1507
|
try {
|
|
1457
1508
|
const { block } = await resolveBlock(root)
|
|
1458
1509
|
if (block && output && Array.isArray(output.context)) {
|
|
@@ -1475,13 +1526,13 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1475
1526
|
// both end on an empty request, an excluded repo, or a skipped session.
|
|
1476
1527
|
if (!output || !Array.isArray(output.messages) || !output.messages.length) return
|
|
1477
1528
|
const sid = output.messages[0]?.info?.sessionID
|
|
1478
|
-
if (await
|
|
1529
|
+
if (await bypassed(root) || await skipSession(sid)) return
|
|
1479
1530
|
// The done gate's reminder: FIRST, and independent of the context block:
|
|
1480
1531
|
// INJECT_OFF and the visible delivery leave it on, and no early return below can skip it.
|
|
1481
1532
|
// Its own function, so its early returns end the reminder, never the context injection.
|
|
1482
1533
|
await (async () => {
|
|
1483
1534
|
if (await doneGateOff()) return
|
|
1484
|
-
const { root: gitRoot, source, blocking, checks } = await
|
|
1535
|
+
const { root: gitRoot, source, blocking, checks } = await doneChecks(root)
|
|
1485
1536
|
if (!checks.length) return
|
|
1486
1537
|
const owed = doneOwed(output.messages, checks, gitRoot)
|
|
1487
1538
|
if (!owed.length) return
|
|
@@ -1555,6 +1606,8 @@ async function setupV2(ctx) {
|
|
|
1555
1606
|
const root = repoRoot({ worktree: ctx?.location?.project?.directory, directory: ctx?.location?.directory })
|
|
1556
1607
|
// `judged: false`: OpenCode 2 never judges a turn, so the done line claims no verdict.
|
|
1557
1608
|
const blockCache = { text: null, at: 0, judged: false }
|
|
1609
|
+
const bypassed = ttlMemo(sovereignBypass)
|
|
1610
|
+
const doneChecks = ttlMemo(doneChecksOf)
|
|
1558
1611
|
// Same scope rule as V1's skipSession. V2's info names the parent `parentID` only, so only
|
|
1559
1612
|
// that and the title are passed on.
|
|
1560
1613
|
const skipSession = sessionSkipper(async (sid) => {
|
|
@@ -1564,7 +1617,7 @@ async function setupV2(ctx) {
|
|
|
1564
1617
|
|
|
1565
1618
|
// The done gate is not judged on OpenCode 2 (see `doneOwed`): said once, where its log goes.
|
|
1566
1619
|
// The listed gate only: an inferred one would log in every repo with a manifest.
|
|
1567
|
-
if (!(await doneGateOff()) && await
|
|
1620
|
+
if (!(await doneGateOff()) && await doneChecks(root).then((d) => d.blocking && d.checks.length, () => false)) {
|
|
1568
1621
|
console.error(`[geneseed-context] done gate: ${DONE_LIST} found, but OpenCode 2 turns are not judged.`)
|
|
1569
1622
|
}
|
|
1570
1623
|
|
|
@@ -1575,7 +1628,7 @@ async function setupV2(ctx) {
|
|
|
1575
1628
|
})
|
|
1576
1629
|
const remindWeakened = async (event) => {
|
|
1577
1630
|
try {
|
|
1578
|
-
if (!Array.isArray(event?.messages) || await
|
|
1631
|
+
if (!Array.isArray(event?.messages) || await bypassed(root) || await doneGateOff()) return
|
|
1579
1632
|
if (await skipSession(event.sessionID)) return
|
|
1580
1633
|
const weakened = takeWeakened(event.sessionID)
|
|
1581
1634
|
if (weakened) event.messages.unshift(v2UserMessage(event.messages, weakened))
|
|
@@ -1591,7 +1644,7 @@ async function setupV2(ctx) {
|
|
|
1591
1644
|
await remindWeakened(event)
|
|
1592
1645
|
if (INJECT_OFF) return
|
|
1593
1646
|
try {
|
|
1594
|
-
if (await
|
|
1647
|
+
if (await bypassed(root)) return
|
|
1595
1648
|
if (!Array.isArray(event?.messages) || v2HasMarker(event.messages)) return
|
|
1596
1649
|
if (await skipSession(event.sessionID)) return
|
|
1597
1650
|
const cached = await cachedBlockText(root, blockCache)
|
|
@@ -1610,7 +1663,7 @@ async function setupV2(ctx) {
|
|
|
1610
1663
|
await ctx.session.hook("compaction", async (event) => {
|
|
1611
1664
|
if (INJECT_OFF) return
|
|
1612
1665
|
try {
|
|
1613
|
-
if (await
|
|
1666
|
+
if (await bypassed(root)) return
|
|
1614
1667
|
if (!Array.isArray(event?.messages) || await skipSession(event.sessionID)) return
|
|
1615
1668
|
const { block } = await resolveBlock(root, false)
|
|
1616
1669
|
if (block) event.messages.unshift(v2UserMessage(event.messages, block.text))
|
|
@@ -1625,7 +1678,7 @@ async function setupV2(ctx) {
|
|
|
1625
1678
|
const d = ev.data ?? {}
|
|
1626
1679
|
try {
|
|
1627
1680
|
if (isSkippedSession({ parentID: d.parentID, title: d.title })) continue
|
|
1628
|
-
if (await
|
|
1681
|
+
if (await bypassed(root)) continue
|
|
1629
1682
|
const { block } = await resolveBlock(root, false)
|
|
1630
1683
|
if (!block) continue
|
|
1631
1684
|
await ctx.session.synthetic({
|
|
@@ -52,11 +52,12 @@
|
|
|
52
52
|
// upgrade path there is still a session-level `permission` ruleset set by the loop launcher
|
|
53
53
|
// when it creates the loop session (`session.create` accepts one).
|
|
54
54
|
|
|
55
|
-
import { promises as fs, realpathSync, existsSync, readFileSync, readdirSync, readlinkSync, statSync, lstatSync, writeFileSync } from "node:fs"
|
|
55
|
+
import { promises as fs, realpathSync, existsSync, readFileSync, readdirSync, readlinkSync, statSync, lstatSync, writeFileSync, mkdirSync, unlinkSync } from "node:fs"
|
|
56
56
|
import { spawnSync } from "node:child_process"
|
|
57
57
|
import * as path from "node:path"
|
|
58
58
|
import { fileURLToPath } from "node:url"
|
|
59
|
-
import { homedir } from "node:os"
|
|
59
|
+
import { homedir, tmpdir } from "node:os"
|
|
60
|
+
import { createHash } from "node:crypto"
|
|
60
61
|
|
|
61
62
|
const PLUGIN_DIR = path.dirname(fileURLToPath(import.meta.url))
|
|
62
63
|
|
|
@@ -355,9 +356,14 @@ function stashExists(root) {
|
|
|
355
356
|
* a spawn. A git destructive VERB anywhere after `git` on the same line, or a removal program
|
|
356
357
|
* as a word at a command boundary. Deliberately loose — the parse decides; this only has to be
|
|
357
358
|
* a superset of what the parse acts on.
|
|
359
|
+
*
|
|
360
|
+
* The git half is LINEAR: it starts only at the input's start or a `\n` and tries the line's
|
|
361
|
+
* first `git` alone, which matches whenever any later `git` would. `\bgit\b[^\n]*\b(?:…)` from
|
|
362
|
+
* every `git` was quadratic: a 270 KB `git -C x …` took seconds, and a hook past its timeout
|
|
363
|
+
* lets the call through. `(?<![\s\S])`, not `^`: under `m`, `^` also starts after `\r`.
|
|
358
364
|
*/
|
|
359
365
|
const LOSS_CANDIDATE_RE =
|
|
360
|
-
|
|
366
|
+
/(?:(?<![\s\S])|\n)(?:(?!\bgit\b)[^\n])*\bgit\b[^\n]*\b(?:reset|clean|branch|checkout|switch|restore|stash|reflog|gc|push)\b|(?:^|[\s;&|("'`])(?:rm|rmdir|unlink|del|erase|remove-item|ri|rd)(?:\.exe)?(?=[\s;&|)"'`]|$)|(?:^|\s)-delete(?=\s|$)/im;
|
|
361
367
|
|
|
362
368
|
class Unverified extends Error {}
|
|
363
369
|
const unverified = (why) => { throw new Unverified(why); };
|
|
@@ -891,7 +897,16 @@ function lossReason(segments, cwd, { always = true, split } = {}) {
|
|
|
891
897
|
/** The first loss among `segs`, run from `start`; a substitution body is judged as a command. */
|
|
892
898
|
const judge = (segs, start, depth = 0) => {
|
|
893
899
|
let dir = start;
|
|
894
|
-
|
|
900
|
+
// A `cd` inside `( … )` ends with the subshell, and `popd` goes back somewhere this reader
|
|
901
|
+
// never recorded. Both used to leave `dir` where the `cd` put it, so a removal after them
|
|
902
|
+
// was looked for in the wrong folder, found absent, and passed. Now the directory is
|
|
903
|
+
// unknown from there on, which asks for a relative path.
|
|
904
|
+
let nest = 0;
|
|
905
|
+
let cdInside = false;
|
|
906
|
+
for (const [n, raw] of segs.map(stripStructure).entries()) {
|
|
907
|
+
const bare = segs[n].filter((t) => !/^["']/.test(t));
|
|
908
|
+
const opens = bare.filter((t) => /^\(/.test(t)).length;
|
|
909
|
+
const closes = bare.filter((t) => /\)$/.test(t) && !/\$\(/.test(t)).length;
|
|
895
910
|
const text = raw.join(' ');
|
|
896
911
|
const named = LOSS_CANDIDATE_RE.test(text);
|
|
897
912
|
for (const body of named ? substitutions(text) : []) {
|
|
@@ -907,12 +922,19 @@ function lossReason(segments, cwd, { always = true, split } = {}) {
|
|
|
907
922
|
w = /^\w+=/.test(w[0]) ? w.slice(1) : pastWrapper(wrapper, w.slice(1));
|
|
908
923
|
if (!w && named) unverified(`\`${wrapper}\` takes a flag the gate does not know`);
|
|
909
924
|
}
|
|
910
|
-
|
|
925
|
+
const leave = () => {
|
|
926
|
+
nest = Math.max(0, nest + opens - closes);
|
|
927
|
+
if (nest === 0 && cdInside) { dir = null; cdInside = false; }
|
|
928
|
+
};
|
|
929
|
+
if (!w || !w.length) { leave(); continue; }
|
|
911
930
|
const prog = progOf(w[0]);
|
|
912
931
|
const args = w.slice(1);
|
|
932
|
+
if (prog === 'popd' || prog === 'pop-location') { dir = null; leave(); continue; }
|
|
913
933
|
if (CD_PROGS.has(prog)) {
|
|
914
934
|
const target = args.find((a) => !a.startsWith('-') && !/^\/d$/i.test(a));
|
|
915
935
|
try { dir = target && target !== '-' ? resolveIn(dir, target) : null; } catch { dir = null; }
|
|
936
|
+
if (nest + opens > 0) cdInside = true;
|
|
937
|
+
leave();
|
|
916
938
|
continue;
|
|
917
939
|
}
|
|
918
940
|
let verdict = null;
|
|
@@ -927,6 +949,7 @@ function lossReason(segments, cwd, { always = true, split } = {}) {
|
|
|
927
949
|
unverified(`\`${w[0].replace(OPAQUE, '')}\` is not a program the gate reads, and a removal follows it`);
|
|
928
950
|
}
|
|
929
951
|
if (verdict) return verdict;
|
|
952
|
+
leave();
|
|
930
953
|
}
|
|
931
954
|
return null;
|
|
932
955
|
};
|
|
@@ -1768,6 +1791,27 @@ const storeLine = (files) => {
|
|
|
1768
1791
|
return `Geneseed change report: ${files.length} rule or memory file${files.length === 1 ? "" : "s"} ` +
|
|
1769
1792
|
`changed outside this session's approved writes (another session, or a decision of yours in the web console, may have made it): ${shown}${more}. This detects a change; it prevented nothing.`
|
|
1770
1793
|
}
|
|
1794
|
+
// ONE REPORT PER CHANGE, however many plugin instances saw it. One `opencode serve` loads this
|
|
1795
|
+
// plugin once per opened project, and every instance hears every session's turn edges. Each kept
|
|
1796
|
+
// its own baseline of the same machine-wide stores, found the same change at the same turn end,
|
|
1797
|
+
// and posted its own message: four projects open, four identical reports (2026-11-10). The
|
|
1798
|
+
// instances share no memory, so the first to create the marker for (session, files, their new
|
|
1799
|
+
// stamps) reports and the rest stay silent. A file, because that is the one thing instances of
|
|
1800
|
+
// one process and separate OpenCode processes both see. A marker it cannot write does not
|
|
1801
|
+
// silence a report: saying it twice is the smaller fault. Markers older than a day are swept.
|
|
1802
|
+
const REPORT_MARKS = path.join(tmpdir(), "geneseed-change-reports")
|
|
1803
|
+
function claimReport(sid, files, now) {
|
|
1804
|
+
const key = createHash("sha1").update([sid, ...files.map((f) => `${f}=${now[f] ?? "gone"}`)].join("\n")).digest("hex")
|
|
1805
|
+
try {
|
|
1806
|
+
mkdirSync(REPORT_MARKS, { recursive: true })
|
|
1807
|
+
for (const name of readdirSync(REPORT_MARKS)) {
|
|
1808
|
+
const p = path.join(REPORT_MARKS, name)
|
|
1809
|
+
try { if (Date.now() - statSync(p).mtimeMs > 86400000) unlinkSync(p) } catch { /* another instance swept it */ }
|
|
1810
|
+
}
|
|
1811
|
+
writeFileSync(path.join(REPORT_MARKS, key), "", { flag: "wx" })
|
|
1812
|
+
return true
|
|
1813
|
+
} catch (err) { return err?.code !== "EEXIST" }
|
|
1814
|
+
}
|
|
1771
1815
|
function noteForStatus(files) {
|
|
1772
1816
|
try {
|
|
1773
1817
|
if (existsSync(machineDir())) writeFileSync(path.join(machineDir(), ".store-report.json"), JSON.stringify({ at: new Date().toISOString(), host: "opencode", files }))
|
|
@@ -1908,7 +1952,8 @@ function gateConfig(p) {
|
|
|
1908
1952
|
// when neither the file nor the patch holds the opening delimiter, since a line patch cannot form one.
|
|
1909
1953
|
const CARRIER_BEGIN = "<!-- BEGIN GENESEED -->"
|
|
1910
1954
|
const CARRIER_REPLAY_CAP = 1024 * 1024
|
|
1911
|
-
|
|
1955
|
+
// Whole-line markers: js/lib/managed-block.mjs BLOCK_RE_SOURCE, by value (a plugin imports nothing).
|
|
1956
|
+
const carrierBlockOf = (text) => /^<!-- BEGIN GENESEED -->[ \t]*\r?\n[\s\S]*?^<!-- END GENESEED -->[ \t]*\r?$/m.exec(text)?.[0] ?? ""
|
|
1912
1957
|
function carrierName(file) {
|
|
1913
1958
|
const s = String(file)
|
|
1914
1959
|
const at = Math.max(s.lastIndexOf("/"), s.lastIndexOf("\\")) + 1
|
|
@@ -2174,6 +2219,68 @@ function shellWriteTargets(command, cwd, ps = false) {
|
|
|
2174
2219
|
}
|
|
2175
2220
|
return [...found];
|
|
2176
2221
|
}
|
|
2222
|
+
/**
|
|
2223
|
+
* THE ONE READING OF A COMMAND every gate below is handed. The lexers here are non-POSIX on
|
|
2224
|
+
* purpose (`SCAN_TOKEN_RE`: a backslash is never an escape, so PowerShell's `"C:\"` closes), and
|
|
2225
|
+
* that is wrong for the shell most commands run in. In bash:
|
|
2226
|
+
* - a backslash-newline joins two lines, so `rm -rf \⏎ /` is one command. Read as two, the
|
|
2227
|
+
* operand landed in a segment with no program and every gate passed it;
|
|
2228
|
+
* - `\'` and `\"` outside single quotes are a literal quote, not a delimiter. Read as one, the
|
|
2229
|
+
* everyday `'it'\''s'` left the quote state inverted and hid the rest of the line as data,
|
|
2230
|
+
* `&& rm -rf /` included.
|
|
2231
|
+
* So for a bash-like shell the continuation is joined and an escaped quote or separator is
|
|
2232
|
+
* replaced by `_`, which is inert to every lexer and keeps every other character where it was.
|
|
2233
|
+
* For PowerShell only its own continuation, a backtick-newline, is joined, and nothing else
|
|
2234
|
+
* changes: there the backslash is a path separator.
|
|
2235
|
+
*
|
|
2236
|
+
* `shell` is what the caller knows: `'bash'` (Claude's `Bash` tool, Git Bash on Windows too),
|
|
2237
|
+
* `'powershell'`, or null. Unknown is read as bash unless the platform is Windows or a
|
|
2238
|
+
* `Verb-Noun` word says PowerShell.
|
|
2239
|
+
*/
|
|
2240
|
+
function shellReading(command, shell = null) {
|
|
2241
|
+
const bashLike = shell === 'bash'
|
|
2242
|
+
|| (shell !== 'powershell' && process.platform !== 'win32' && !PS_CUE_RE.test(command));
|
|
2243
|
+
if (!bashLike) return command.replace(/`\r?\n/g, '');
|
|
2244
|
+
if (!command.includes('\\')) return command;
|
|
2245
|
+
let out = '';
|
|
2246
|
+
let quote = '';
|
|
2247
|
+
const tags = []; // heredocs opened on this line: `[stripTabs, tag]`
|
|
2248
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
2249
|
+
const ch = command[i];
|
|
2250
|
+
const next = command[i + 1];
|
|
2251
|
+
// A heredoc body is copied as it is: under a quoted tag a backslash is literal, and the
|
|
2252
|
+
// gates read a body as data or, for `bash <<EOF`, as the command it is.
|
|
2253
|
+
if (!quote && ch === '<' && next === '<' && command[i + 2] !== '<' && command[i - 1] !== '<') {
|
|
2254
|
+
const m = /^<<(-?)[ \t]*(["']?)([A-Za-z_]\w*)\2/.exec(command.slice(i));
|
|
2255
|
+
if (m) { tags.push([m[1], m[3]]); out += m[0]; i += m[0].length - 1; continue; }
|
|
2256
|
+
}
|
|
2257
|
+
if (!quote && ch === '\n' && tags.length) {
|
|
2258
|
+
out += ch;
|
|
2259
|
+
while (tags.length) {
|
|
2260
|
+
const end = command.indexOf('\n', i + 1);
|
|
2261
|
+
const line = command.slice(i + 1, end < 0 ? command.length : end);
|
|
2262
|
+
out += line + (end < 0 ? '' : '\n');
|
|
2263
|
+
i = end < 0 ? command.length : end;
|
|
2264
|
+
const bare = line.replace(/\r$/, '');
|
|
2265
|
+
if ((tags[0][0] ? bare.replace(/^\t+/, '') : bare) === tags[0][1]) tags.shift();
|
|
2266
|
+
if (end < 0) break;
|
|
2267
|
+
}
|
|
2268
|
+
continue;
|
|
2269
|
+
}
|
|
2270
|
+
if (ch === '\\' && quote !== "'" && next !== undefined) {
|
|
2271
|
+
const eol = next === '\n' ? 1 : (next === '\r' && command[i + 2] === '\n' ? 2 : 0);
|
|
2272
|
+
if (eol) { i += eol; continue; }
|
|
2273
|
+
// In double quotes only `\"` matters to a lexer; outside, a quote or a separator does.
|
|
2274
|
+
out += ch + ((quote ? next === '"' : /["';|&]/.test(next)) ? '_' : next);
|
|
2275
|
+
i += 1;
|
|
2276
|
+
continue;
|
|
2277
|
+
}
|
|
2278
|
+
if (quote) { if (ch === quote) quote = ''; } else if (ch === '"' || ch === "'") quote = ch;
|
|
2279
|
+
out += ch;
|
|
2280
|
+
}
|
|
2281
|
+
return out;
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2177
2284
|
// ---- shell-write twin: END
|
|
2178
2285
|
|
|
2179
2286
|
// A segment that is only a redirect: `> f`, or `A=1 > f`. V2's shell tool asserts only when its parser
|
|
@@ -2193,7 +2300,7 @@ const OWNERSHIP_SEEN = new Set()
|
|
|
2193
2300
|
const OWNERSHIP_MANIFESTS = new Set(["package.json", "pom.xml", "pyproject.toml", "go.mod", "Cargo.toml",
|
|
2194
2301
|
"composer.json", "Gemfile"])
|
|
2195
2302
|
const isManifest = (n) => OWNERSHIP_MANIFESTS.has(n) || n.startsWith("build.gradle") || n.endsWith(".csproj")
|
|
2196
|
-
const MANAGED_BLOCK_RE =
|
|
2303
|
+
const MANAGED_BLOCK_RE = /^<!-- BEGIN GENESEED -->[ \t]*\r?\n[\s\S]*?^<!-- END GENESEED -->[ \t]*\r?$/gm
|
|
2197
2304
|
const OWNERSHIP_SECTION_RE = /^## Ownership[ \t]*\r?$/m
|
|
2198
2305
|
const OWNERSHIP_TAIL = "Opt out per repo: `## Ownership` with `mode: off` in the root `AGENTS.md`; per " +
|
|
2199
2306
|
"install: rebuild with `--no-ownership-gate`. Offer the full documentation " +
|
|
@@ -2370,6 +2477,7 @@ export const GeneseedGuard = async (ctx) => {
|
|
|
2370
2477
|
const own = ownWrites()
|
|
2371
2478
|
const files = changed.filter((f) => own[f] !== (now[f] ?? "gone"))
|
|
2372
2479
|
if (!files.length) return
|
|
2480
|
+
if (!claimReport(sid, files, now)) return
|
|
2373
2481
|
const line = storeLine(files)
|
|
2374
2482
|
log(line)
|
|
2375
2483
|
noteForStatus(files)
|
|
@@ -2515,7 +2623,9 @@ export const GeneseedGuard = async (ctx) => {
|
|
|
2515
2623
|
if (hasAny(tool, SHELL_TOOLS)) {
|
|
2516
2624
|
// OpenCode's bash tool may run in `workdir`, resolved against the session directory.
|
|
2517
2625
|
const wd = typeof args.workdir === "string" && args.workdir ? path.resolve(cwd, args.workdir) : cwd
|
|
2518
|
-
|
|
2626
|
+
// One reading for every check below: continuations joined, escaped quotes inert (`shellReading`).
|
|
2627
|
+
const picked = pickCommand(args)
|
|
2628
|
+
const c = typeof picked === "string" && picked ? shellReading(picked, /powershell|pwsh/i.test(tool) ? "powershell" : null) : picked
|
|
2519
2629
|
const cut = (t) => scanSegments(t).map((seg) => seg.match(SCAN_TOKEN_RE) || [])
|
|
2520
2630
|
if (c && (SHELL_BLOCK_RE.some((re) => re.test(c)) || catastrophic(c, cut))) { await deny(refused("catastrophic", { name: c }), "law-4"); return }
|
|
2521
2631
|
const scan = c && !ROOT_SCAN_OFF && rootScan(c)
|