geneseed 4.25.1 → 4.26.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/SHIPPED.md +1 -1
  3. package/adapters/bob/README.md +25 -3
  4. package/adapters/claude-code/README.md +1 -1
  5. package/adapters/opencode/HOW-OPENCODE-LOADS.md +3 -1
  6. package/adapters/opencode/plugins/geneseed-activity.js +331 -31
  7. package/bin/geneseed-hook.mjs +4 -4
  8. package/docs/concepts/hook-gates.md +2 -1
  9. package/docs/concepts/hooks.md +10 -0
  10. package/docs/concepts/host-matrix.md +2 -2
  11. package/docs/reference/opencode-plugins.md +1 -1
  12. package/docs/reference/plugin-activity.md +4 -2
  13. package/docs/understand/machine-opencode.md +1 -1
  14. package/docs/web-ui.md +17 -0
  15. package/harness.config.json +1 -1
  16. package/js/hosts/activity.mjs +175 -30
  17. package/js/hosts/hooks-prims.mjs +2 -2
  18. package/js/hosts/settings.mjs +6 -1
  19. package/js/loop/registry.mjs +17 -0
  20. package/js/web/activity.mjs +116 -5
  21. package/package.json +1 -1
  22. package/web/dist/assets/Activity-Dq8_Xhxu.js +1 -0
  23. package/web/dist/assets/ActivityDetail-BIxt9mAe.js +1 -0
  24. package/web/dist/assets/Bonsai-CN4rRAHc.js +1 -0
  25. package/web/dist/assets/{CopyButton-B6myFV7a.js → CopyButton-DmXwAzBl.js} +1 -1
  26. package/web/dist/assets/{Dashboard-DEQCBcUW.js → Dashboard-BsevsUea.js} +2 -2
  27. package/web/dist/assets/Docs-BkipFlm8.js +5 -0
  28. package/web/dist/assets/{GreenhouseView-CV1squu6.js → GreenhouseView-BJmyqf49.js} +1 -1
  29. package/web/dist/assets/{Installs-C4TQVZ_-.js → Installs-CICECChj.js} +3 -3
  30. package/web/dist/assets/{JournalView-CpXsT_JD.js → JournalView-BOyq2Abk.js} +1 -1
  31. package/web/dist/assets/{KitApply-fYh_YjQA.js → KitApply-BRSZjM_N.js} +1 -1
  32. package/web/dist/assets/{Kits-BMuGOiTg.js → Kits-DPGxX2Vv.js} +1 -1
  33. package/web/dist/assets/Laws-CY0hBpkK.js +3 -0
  34. package/web/dist/assets/{Library-DiZqRFL5.js → Library-PzXbaBWz.js} +2 -2
  35. package/web/dist/assets/{Loops-DkwWkdPc.js → Loops-DflSj8Pz.js} +2 -2
  36. package/web/dist/assets/{OperatorHudView-CLmq0lNh.js → OperatorHudView-CjJlJqGm.js} +1 -1
  37. package/web/dist/assets/{Personal-C70XacpA.js → Personal-CC7cLkTe.js} +2 -2
  38. package/web/dist/assets/{Tabs-ChFhPGP6.js → Tabs-DCzA2Eop.js} +1 -1
  39. package/web/dist/assets/{index-Cqqs-PbJ.css → index-XTGBLKQr.css} +1 -1
  40. package/web/dist/assets/{index-DxCqnFPy.js → index-xjpstIKL.js} +2 -2
  41. package/web/dist/index.html +2 -2
  42. package/web/dist/assets/Activity-BdMwEnFN.js +0 -1
  43. package/web/dist/assets/ActivityDetail-BgUjDuxO.js +0 -1
  44. package/web/dist/assets/Docs-ChBYcQbT.js +0 -5
  45. package/web/dist/assets/Laws-ndHW7Onu.js +0 -3
@@ -34,11 +34,12 @@ The merge is surgical. Every other key and every hook of your own survive, and t
34
34
 
35
35
  **OpenClaude** is a Claude Code fork: it gets the same hooks and the same prompts, unchanged.
36
36
 
37
- **Bob** has its own contract. It uses Claude's event names but ignores a hook's output before a tool call — the only way to refuse is exit code 2 — and it has no tool matcher, `SubagentStop` or `PreCompact`. So Bob gets three hooks:
37
+ **Bob** has its own contract. It uses Claude's event names but ignores a hook's output before a tool call — the only way to refuse is exit code 2 — and it has no tool matcher or `SubagentStop`. Bob 2.2.3 does have `PreCompact` and `PostCompact`, but Geneseed does not wire them yet. So Bob gets four hooks:
38
38
 
39
39
  - `SessionStart` → `geneseed-hook context`.
40
40
  - `PreToolUse` → `geneseed-hook tool-gate`, the git gate and the rule gate fused into one command that decides from the shape of the call. It **blocks** (exit 2) only for the checks that admit no judgement call: secrets, destructive git, a recursive scan of a whole filesystem, and a write under a project's own protected-checks list. The commit/push and rule-or-memory checks become a warning line, because a hard block would leave Bob unable to commit at all.
41
41
  - `Stop` → `geneseed-hook learn`.
42
+ - `UserPromptSubmit` → `geneseed-hook activity`, which records the turn for the Activity view.
42
43
 
43
44
  Neither host has been verified live on the authoring machine. If a hook does not fire, the same rules still reach the agent through the instructions file.
44
45
 
@@ -24,9 +24,19 @@ Geneseed writes its hooks into the host's settings file. Every hook calls one pr
24
24
  | `PreCompact` | before auto-compaction | `geneseed-hook learn` | captures memory before the transcript is summarised | needs `GENESEED_LLM` |
25
25
  | `UserPromptSubmit` | you send a message | `geneseed-hook activity` | records the turn's start for the web console's Activity view; prints nothing | off with `GENESEED_ACTIVITY=off` |
26
26
  | `SessionEnd` | the session closes | `geneseed-hook activity` | marks the session ended and archives it | off with `GENESEED_ACTIVITY=off` |
27
+ | `SubagentStart` | a subagent starts | `geneseed-hook activity` | records the subagent as a branch of its session, even one that only reads | off with `GENESEED_ACTIVITY=off` |
27
28
 
28
29
  Every hook above also feeds the [Activity view](../reference/plugin-activity.md) after it has decided, unless tracking is off: one file per session under `activity/` beside the install. The gates' verdicts never wait on it.
29
30
 
31
+ What that file holds for the Activity garden:
32
+ - **Files.** Each changed file is stored relative to the session's git root, with `/` separators. A file outside the root, or a session outside any repo, gets no path (`path: null`) and keeps only its basename, so it never matches a file of the same name inside the repo. A path is never stored absolute. Each file also records who changed it: the session, or the subagent's `agent_id`.
33
+ - **Where the session runs.** `root` is the worktree's git root and `repo` is the main repository's root, so the linked worktrees of one repo can be grouped together. Only the session's own events set them; a subagent working in another worktree does not move them.
34
+ - **Subagents.** `agents` lists each subagent with its type and `running` or `done`.
35
+ - **Turns and context.** `turns` counts your prompts. `context` is the size of the context now, taken from the transcript's last assistant message. The window size is an estimate: 200k, or 1M once the context is past 200k.
36
+ - **Compactions.** `compactions`, `compacted_at` and `context_at_compaction` record each compaction (on `PreCompact`). After a compaction, `context` is unknown (`null`) until the next `Stop` reads it again. Claude Code's `<synthetic>` messages and messages with no input-side tokens never change it.
37
+
38
+ On Bob, a subagent's files cannot be told apart from its session's files (its hook payloads carry no subagent id), so the session is marked `attribution: false`. A compaction is counted on Bob's `SessionStart` with `source: "compact"`, and there is no context size.
39
+
30
40
  ## What each one does, and what you see
31
41
 
32
42
  **context.** Before your first message, the agent receives your own harness files — `user-rules.md`, `PROFILE.md`, the memory index, the notebook index, your wiki declaration — skipping any still untouched since install, then the repo's docs, discovered by convention or listed in a `context.json`. Each file is capped at 16 KB and the whole injection at 48 KB; what does not fit is listed for the agent to read on demand. You see nothing, except that the agent already knows your project. See [Project context](../guides/project-context.md).
@@ -14,7 +14,7 @@ Every [host](hosts.md) gets the same content. This table is what each one lets G
14
14
  | Agents · Skills · Memory · Notebook | ✅ | ✅ | ✅ | ✅ |
15
15
  | Project context loaded at session start | ⚙️ plugin | 🪝 hook | 🪝 hook¹ | 🪝 hook² |
16
16
  | Memory written back at session end (learn) | ⚙️ plugin | 🪝 hook | 🪝 hook¹ | 🪝 hook² |
17
- | Live sessions in the web console's [Activity view](../reference/plugin-activity.md) | ⚙️ plugin | 🪝 hook | 🪝 hook, per tool call only (no transcript)¹ | 🪝 hook² |
17
+ | Live sessions in the web console's [Activity view](../reference/plugin-activity.md) | ⚙️ plugin | 🪝 hook, files per subagent, context size | 🪝 hook, per tool call only (no transcript, no context size, subagent files not attributed)¹ | 🪝 hook, files per subagent, context size² |
18
18
  | Real data loss (force-push to `main`, discarding uncommitted work, `rm` of untracked files…) | ⚙️ block³ · 🔒 ask (reflog, gc) | 🪝 ask | 🪝 block¹ | 🪝 ask² |
19
19
  | Secrets kept out of files | ⚙️ block⁴ | 🪝 ask | 🪝 block¹ | 🪝 ask² |
20
20
  | Consent before every commit and push | 🔒 permission ask | 🪝 ask | 🪝 warning¹ | 🪝 ask² |
@@ -26,7 +26,7 @@ Every [host](hosts.md) gets the same content. This table is what each one lets G
26
26
 
27
27
  ✅ native · ⚙️ OpenCode plugin · 🔒 `permission` entry in `opencode.json` · 🪝 `settings.json` hook · ➖ no host mechanism (the rule still applies as prose).
28
28
 
29
- ¹ **Bob** has its own hook contract: Claude's event names, but it ignores a hook's output on `PreToolUse`, so the only way to refuse is exit code 2. Geneseed therefore blocks only the rules that admit no judgement call — secrets, real data loss, a recursive scan of a whole filesystem, and a write under a project's own protected-checks list — and turns the two consent checks into a logged warning. It has no `SubagentStop` or `PreCompact` event, so learn runs on `Stop` only. **Unverified live** — there is no Bob install on the authoring machine; the rules preamble still holds if a hook does not fire.
29
+ ¹ **Bob** has its own hook contract: Claude's event names, but it ignores a hook's output on `PreToolUse`, so the only way to refuse is exit code 2. Geneseed therefore blocks only the rules that admit no judgement call — secrets, real data loss, a recursive scan of a whole filesystem, and a write under a project's own protected-checks list — and turns the two consent checks into a logged warning. It has no `SubagentStop` event. Bob 2.2.3 does have `PreCompact` and `PostCompact`, but Geneseed does not wire them yet, so learn runs on `Stop` only. **What is verified:** the payload shape (Claude's keys plus `cwd`), the event list and the strict settings schema were read in Bob 2.2.3's shipped bundle on the authoring machine, and a live prompt on 2026-10-25 wrote an Activity snapshot from `UserPromptSubmit`. The gates' block-by-exit-code behaviour is Bob's documented contract, not yet observed live; the rules preamble still holds if a hook does not fire.
30
30
  ² **OpenClaude** is a Claude Code fork and gets Claude's hooks and verdicts verbatim, in `~/.openclaude/settings.json` (global) or `.openclaude/settings.local.json` (per repo). **Unverified live** for the same reason.
31
31
  ³ OpenCode's plugin hook can only allow or throw — there is no "ask the user" — so the rule-or-memory check stops the first such write once rather than prompting, and a real data loss is blocked outright (as on Bob) rather than asked; `GENESEED_GUARD=warn` turns the block into a logged warning.
32
32
  ⁴ The checks differ in shape: OpenCode's guard plugin blocks writes *to* private-key and credential files by path; the Claude-shaped hook looks at the *content* being written for credential-shaped strings (cloud keys, tokens, private-key blocks) and asks. A `.env` file is exempt on the hook side — that is where a secret is allowed to live.
@@ -19,7 +19,7 @@ Every plugin swallows its own errors — none can block or crash a session. Each
19
19
  The same files work on OpenCode 1 (1.3.4 or newer) and OpenCode 2. OpenCode 2 rewrote the plugin API, and each plugin carries both halves. You don't need to configure anything. Two differences show on OpenCode 2:
20
20
 
21
21
  - **A guard block shows up as a failed tool call.** The call never runs. The model gets an error that starts with `[geneseed-guard] blocked:` and gives the reason.
22
- - **The Activity view shows no todo list or files-touched count.** OpenCode 2 publishes no event for either.
22
+ - **The Activity view shows no todo list, and files touched have no line counts.** OpenCode 2 publishes no todo event. It names the files each step changed, but not how many lines, and an undo does not remove a file from the list.
23
23
 
24
24
  If a plugin seems silent on OpenCode 2, check that `~/.config/opencode/plugins/` holds the current files. Copies from before this change fail to load with *"Plugin must export a default definition with an id and an effect or setup function"*. Running `geneseed rebuild-all` replaces them.
25
25
 
@@ -10,12 +10,14 @@ One of the [OpenCode plugins](opencode-plugins.md). [Environment variables](envi
10
10
 
11
11
  **What it does.** Feeds the web console's **Activity** view: one small JSON file per session under `activity/` beside OpenCode's config, recording what the session is doing — phase, model, token and cost totals, files touched, plan, last error. The console only reads those files; the two only meet on disk, so a crash on either side never blocks a session.
12
12
 
13
- **When it runs.** On session events, for top-level sessions only (sub-agents and learn's sessions are skipped). A session whose process died, went stale (30 minutes untouched) or ended leaves the live list and is listed as ended; the reader never deletes a file.
13
+ **When it runs.** On session events. A sub-agent's child session (one with a `parentID`) is folded into its root session: it becomes an `agents[]` row (`{id, type, status: "running" | "done"}`, the child's id and agent), and its files join the root's `files` with `by` set to the child's id. Only learn's throwaway `geneseed-*` sessions are skipped. On OpenCode 2 the files come from `session.step.ended`, which carries no line counts, so those read `null`. A session whose process died, went stale (30 minutes untouched) or ended leaves the live list and is listed as ended; the reader never deletes a file.
14
14
 
15
- **Claude Code, OpenClaude and Bob.** Their hooks write the same files into `activity/` beside the install (`~/.claude/activity/`, `<repo>/.claude/activity/`, `~/.bob/activity/`). No hook is added per tool call: the writer runs after the hooks that already run — the gates, `context` and `learn` — plus `geneseed-hook activity` on `UserPromptSubmit` and, on Claude Code and OpenClaude, `SessionEnd`. So a Claude session's phase moves on the gated tools (`Bash`, `PowerShell`, `Write`, `Edit`, `NotebookEdit`, `Skill`, `Agent`, `Task`), and the rest of the turn — every tool call, the model, the token totals, the last reply — arrives at `Stop`, read from the transcript where the previous `Stop` left off (at most 2 MB per turn). Bob sends no transcript, so a Bob session shows only the calls its `tool-gate` sees, and leaves the live list by staleness alone (Bob has no `SessionEnd`). Bob's `SessionStart` is not recorded either — whether Bob pipes a payload there is unverified, and reading one that never closes would hold the session's start — so a Bob session first appears at its first prompt or tool call. These writers have no resident process, so their snapshots carry `pid: null` and stay live by staleness alone. Recorded: tool names, file basenames, line counts, todo text, and 240-character snippets of the prompt and the last reply — never a shell command, a file's content or an edit's text — and any credential the secrets gate would catch in a snippet is written as `[redacted]`. A project install's `activity/` gets its own `.gitignore` (`*`), and the writer never writes through, or sweeps, an `activity/` or `activity/archive/` that is a link. Nothing is recorded in a repo listed in `excludes.json`, or inside a model CLI that `learn` started.
15
+ **Claude Code, OpenClaude and Bob.** Their hooks write the same files into `activity/` beside the install (`~/.claude/activity/`, `<repo>/.claude/activity/`, `~/.bob/activity/`). No hook is added per tool call: the writer runs after the hooks that already run — the gates, `context` and `learn` — plus `geneseed-hook activity` on `UserPromptSubmit` and, on Claude Code and OpenClaude, `SessionEnd` and `SubagentStart`. So a Claude session's phase moves on the gated tools (`Bash`, `PowerShell`, `Write`, `Edit`, `NotebookEdit`, `Skill`, `Agent`, `Task`), and the rest of the turn — every tool call, the model, the token totals, the last reply — arrives at `Stop`, read from the transcript where the previous `Stop` left off (at most 2 MB per turn). Bob sends no transcript, so a Bob session shows only the calls its `tool-gate` sees, and leaves the live list by staleness alone (Bob has no `SessionEnd`). Bob's `SessionStart` is recorded only after a compaction (`source: "compact"`, counted as one): a startup or resume fires just before the first prompt, which records the session anyway. Bob 2.2.3 writes every hook's payload to stdin and closes it, so reading it there is safe. These writers have no resident process, so their snapshots carry `pid: null` and stay live by staleness alone. Recorded: tool names, each changed file's path relative to the session's git root (a file outside the root, or a session outside any repo, keeps its basename only; a path is never stored absolute; labels show basenames), who changed it (the session or a subagent's `agent_id`), the subagents, the prompt count, the context size and the compactions, line counts, todo text, and 240-character snippets of the prompt and the last reply — never a shell command, a file's content or an edit's text — and any credential the secrets gate would catch in a snippet is written as `[redacted]`. A project install's `activity/` gets its own `.gitignore` (`*`), and the writer never writes through, or sweeps, an `activity/` or `activity/archive/` that is a link. Nothing is recorded in a repo listed in `excludes.json`, or inside a model CLI that `learn` started.
16
16
 
17
17
  **Archive.** On `SessionStart` and `SessionEnd` the hook writer moves every snapshot that is no longer live into `activity/archive/`, keeping the newest 50 and none older than 7 days. `/api/activity` returns them, with the stale and dead ones still in `activity/`, in its `ended` list — capped there by the same rule, since the OpenCode plugin never sweeps.
18
18
 
19
+ **What `/api/activity` returns.** `activity` (the live sessions), `ended`, and `collisions`. Each session carries the snapshot as written, plus the v2 fields: `root` (the worktree's git root), `repo` (its main worktree), `agents` (`{id, type, status, started}`), `attribution` (`false` only on a Bob session that ran a sub-agent, else `null`), `turns`, `context` (`{used, window}`), `compactions`, `compacted_at` and `context_at_compaction` (either `context` field can be `null`, right after a compaction for one), and `repo_key`, the repo (else the root) case-folded on Windows, to group a repo's sessions whatever case each host spelled it in. A v1 snapshot reads `null` for those, `[]` for `agents` and `0` for the counts. A live session also gets `files_all`, the uncapped file rows from its detail file (`files` stays the capped summary), and `loops`: `{title, iteration, status}` for each loop registered on its `root`, a finished or unreadable loop left out. `collisions` lists each `{repo, path}` that two or more writers changed among the live sessions — a writer is a session or one of its sub-agents (`{sid, by, root}`) — with `kind: "same-worktree"` when two of them share a `root`, else `"cross-worktree"`. A file outside the root is stored with `path: null` (its `file` keeps the basename) and takes no part in a collision. Roots and paths compare case-folded on Windows, and a session root is resolved to its real path before the loop join, as the loop registry stores it. `/api/activity/<id>` returns the same fields for one session, an archived one included.
20
+
19
21
  **What you see.** A card per live session in **Activity** (`geneseed web`).
20
22
 
21
23
  **Switches.**
@@ -18,7 +18,7 @@ What an OpenCode install writes, piece by piece. The **Kind** words are explaine
18
18
  | context plugin | Puts your repo's README, CONTRIBUTING and a listing of `docs/` in front of the agent, with your rules, profile, memory index and wiki | automatic | Your docs, capped at 16 KB a file and 48 KB a session | `GENESEED_CONTEXT_INJECT=off` |
19
19
  | guard plugin | Blocks writes to key and credential files (`id_rsa`, `.pem`, `.ssh/`…), catastrophic commands (`rm -rf /`, formatting a disk), every other real data loss judged against the repository's state, a recursive scan of a whole filesystem (`find /`), and changes inside your wiki's protected folders. Refuses the first write to `user-rules.md` or memory once, so the choice is yours | enforced | No tokens | `GENESEED_GUARD=off`, or `GENESEED_GUARD=warn` to log instead of block |
20
20
  | learn plugin | Once a session has been quiet for 60 seconds, distils durable facts into `memory/` with the model the session already uses | automatic | One model call per quiet session | `geneseed exclude add <folder>` silences it in that folder |
21
- | activity plugin | Writes one small file per session that the web console's Activity view shows | automatic | No tokens | `GENESEED_ACTIVITY=off` |
21
+ | activity plugin | Writes one small file per session that the web console's Activity view shows: what the session does now, its sub-agents, the files each of them changed (by path inside the repository), its turns, how full its context is and its compactions | automatic | No tokens | `GENESEED_ACTIVITY=off` |
22
22
  | notify plugin | A desktop notification when a turn took longer than 30 seconds | automatic | No tokens | `GENESEED_NOTIFY=off` |
23
23
  | ponytail plugin | Minimal-code mode. `/ponytail lite`, `full` or `ultra` adds a short ruleset to every turn until you switch it off | on demand | 0 while off, which is the default | `/ponytail off` |
24
24
  | workflow plugin | Adds a `workflow` tool that runs saved orchestration scripts | on demand | Runs only when called | `geneseed uninstall` |
package/docs/web-ui.md CHANGED
@@ -187,6 +187,23 @@ streams the output of background jobs and keeps their history across reloads.
187
187
  the files it touched and its todo progress; open one for its detail. Sessions that ended in the last 7 days are listed under
188
188
  **Recently ended**, below the live ones. Every host records it:
189
189
  the OpenCode plugin, and `geneseed-hook activity` on Claude Code, OpenClaude and Bob.
190
+ A **List | Garden** switch (kept in the URL with the filters, which apply to both) shows the
191
+ live sessions as pixel bonsai instead: one shelf per repository (worktrees stand on their
192
+ repo's shelf, tagged ⎇), one tree per session. The pot's glaze is the host (clay Claude Code,
193
+ blue Bob, grey OpenCode, violet OpenClaude); the tree grows taller with turns, its crown
194
+ with context fill, and the tips yellow past 80 %. A compaction cuts the crown flat (it
195
+ regrows as context refills) and leaves a notch on the rim. A running sub-agent is a thick
196
+ branch with its own pad, coloured by agent type; a finished one is a pruned stub and a
197
+ fallen leaf. A cream blossom is a changed file, on the pad of the AI that changed it (Bob
198
+ cannot tell, so all its blossoms sit on the crown). An amber `!` means the session needs
199
+ you, a red `x` an error, a grey tree an idle session. Two sessions changing the same file
200
+ are tied together in red (same worktree) or dashed amber (two worktrees of the repo): tangled
201
+ roots in the moss when they stand side by side, a thread under the pots when they do not.
202
+ Hover a tree for its model, turns, context and compactions, or a pad for its author's files;
203
+ click it to open the session. Past ten trees, quiet shelves (no session working or waiting on
204
+ you) fold into chips, the largest first; the last standing shelf never folds. **Sakura** repaints the crowns pink, nothing more.
205
+ A session's detail page shows its tree too, live or ended, with the same pad hovers and a
206
+ legend of its turns, context, compactions and sub-agents; an ended session's tree stands still, without the `!`.
190
207
  - **Changes** (`#/diff`) — the diff between the deployed harness and the source: edited /
191
208
  added / missing files, and files only behind the source (unedited; a rebuild updates them)
192
209
  listed apart under **Behind source**, with per-file expansion and coloured unified-diff lines. Select
@@ -2,5 +2,5 @@
2
2
  "_comment": "version is a human-readable release label only; the canonical identity of an installed harness is the source fingerprint stamped in .geneseed-version (see `harness version`), not this string.",
3
3
  "theme": "neutral",
4
4
  "product": "Geneseed",
5
- "version": "4.25.1"
5
+ "version": "4.26.0"
6
6
  }
@@ -5,24 +5,41 @@
5
5
  * session into `<cfg>/activity/`; this module writes the same files for the hosts whose hooks are
6
6
  * processes rather than a resident plugin — Claude Code, OpenClaude and Bob. The web reader
7
7
  * (`js/web/activity.mjs`) cannot tell the two writers apart, and must not need to: the schema is
8
- * the plugin's, plus `writer: "hook"`, `host`, and the two private cursors below (`normalizeEntry`
9
- * never returns them).
8
+ * the plugin's, plus `writer: "hook"`, `host`, and the private fields below — the transcript
9
+ * cursors `transcript_offset`/`last_message_id`, and Bob's pending `subtask_prompts`
10
+ * (`normalizeEntry` never returns them).
10
11
  *
11
12
  * NOT A NEW HOOK ON EVERY TOOL CALL. `bin/geneseed-hook.mjs` calls `recordActivity` after the verb
12
13
  * the host ran anyway has decided (the gates, `context`, `learn`), plus the `activity` verb for
13
- * the two events no other verb is wired to (UserPromptSubmit, SessionEnd). So a Claude session's
14
- * live phase moves only on the gated tools (`Bash|PowerShell`, `Write|Edit|NotebookEdit`,
14
+ * the events no other verb is wired to (UserPromptSubmit, SessionEnd, SubagentStart). So a Claude
15
+ * session's live phase moves only on the gated tools (`Bash|PowerShell`, `Write|Edit|NotebookEdit`,
15
16
  * `Skill|Agent|Task`); the rest of the turn's tool calls arrive at Stop, read out of the
16
17
  * transcript from a stored byte offset (`readTranscriptDelta`). Bob sends no `transcript_path`,
17
18
  * so a Bob session shows only what its matcher-less `tool-gate` sees, call by call.
18
19
  *
20
+ * SNAPSHOT V2 (the Activity garden: docs/concepts/hooks.md). Each file row is keyed by
21
+ * `(path, by)`: `by` is the Claude/OpenClaude sub-agent's `agent_id`, or null for the session.
22
+ * `agents[]` grows a branch on the first event that carries an `agent_id` (SubagentStart, at
23
+ * launch) and closes it on SubagentStop. Bob's payloads carry no sub-agent id (its
24
+ * `spawn_subagent`/`start_subtask` calls fire the PARENT's hooks), so a Bob spawn is an id-less
25
+ * branch that the next root Stop closes, and the session says `attribution: false`. `turns`
26
+ * counts prompts; `context` is the last assistant message's input-side tokens; `compactions`,
27
+ * `compacted_at` and `context_at_compaction` come from PreCompact (Bob: SessionStart `compact`).
28
+ * `root`/`repo` come from the SESSION's cwd only — a worktree sub-agent's own cwd never moves them.
29
+ *
19
30
  * THIS MODULE IS NEVER LOADED WHEN TRACKING IS OFF — the entry checks the flag first, then imports
20
31
  * this file dynamically. It must never print: a hook's stdout is its verdict, and every write
21
32
  * here is best-effort (a hook that fails is a tool call that fails).
22
33
  *
23
- * WHAT IS RECORDED, AND WHAT NEVER IS. A tool's name, a file path's BASENAME, line counts, todo
24
- * text, a prompt snippet and the last assistant message snippet (240 characters each). Never a
25
- * shell command, a file's content or an edit's text: those are where secrets live.
34
+ * WHAT IS RECORDED, AND WHAT NEVER IS. A tool's name, a changed file's path RELATIVE TO THE
35
+ * SESSION'S GIT ROOT (`/`-separated; a file outside the root, or a session outside any repo, gets
36
+ * `path: null` and keeps its basename only, in `file` — a path is never stored absolute), the
37
+ * root and main-repo directories
38
+ * themselves, line counts, todo text, a prompt snippet and the last assistant message snippet
39
+ * (240 characters each). Timeline and phase labels stay basename-only. Never a shell command, a
40
+ * file's content or an edit's text: those are where secrets live. The relative path is the one
41
+ * thing the garden needs to place a file and to see two sessions touch the same one; it says
42
+ * no more than the repo's own tree does, and the directory is git-ignored and 0700.
26
43
  *
27
44
  * Liveness is owned here because two writers need it now. The hooks have no resident process,
28
45
  * so they record `pid: null` and are live by staleness alone; a plugin snapshot keeps its pid
@@ -34,8 +51,11 @@ import {
34
51
  closeSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readSync,
35
52
  renameSync, statSync, unlinkSync, writeFileSync,
36
53
  } from 'node:fs';
54
+ import os from 'node:os';
37
55
  import path from 'node:path';
38
56
  import { parseIntStrict, stripWhitespace } from '../lib/text.mjs';
57
+ // Neither is a new module on the hook path: `hosts.mjs` already imports both.
58
+ import { gitRootOf, mainWorktreeOf } from './gitref.mjs';
39
59
  import { SECRET_RE } from './hooks-prims.mjs';
40
60
  import { sovereignBypass } from './hosts.mjs';
41
61
 
@@ -66,6 +86,13 @@ const SNIPPET_LEN = 160;
66
86
  const SID_CAP = 128;
67
87
  // Edit tools count as touching a file only when they carry an edit, so a Read never counts.
68
88
  const EDIT_FIELDS = ['content', 'new_string', 'new_source', 'diff'];
89
+ // Bob 2.2.3's edit tools, by name: `search_and_replace` carries none of the fields above.
90
+ const BOB_EDITS = new Set(['write_file', 'apply_diff', 'insert_content', 'search_and_replace']);
91
+ // Bob's sub-agent tools. Their calls fire the parent's hooks with no sub-agent id (F17).
92
+ const BOB_SPAWNS = new Set(['spawn_subagent', 'start_subtask']);
93
+ // The context window is not in the transcript: past the 200k one, it can only be the 1M one.
94
+ const WINDOW = 200_000;
95
+ const WINDOW_1M = 1_000_000;
69
96
 
70
97
  /**
71
98
  * The plugin's safe-name scheme, capped: every separator, `..`-forming slash and drive colon
@@ -148,6 +175,26 @@ function isLink(p) {
148
175
  const lineCount = (s) => (typeof s === 'string' && s ? s.split('\n').length : 0);
149
176
  const baseOf = (p) => (typeof p === 'string' && p ? path.basename(p.replace(/\\/g, '/')) : null);
150
177
 
178
+ /**
179
+ * A tool's file path as stored: relative to `root`, `/`-separated, or `null` when there is no
180
+ * root or the file falls outside it (`..`, or another drive, where `path.relative` answers
181
+ * absolute) — the row then keeps only its basename in `file`, so a stray `README.md` outside the
182
+ * repo never reads as the repo's own. A relative path resolves against the session's cwd; Bob's
183
+ * own resolver also expands a leading `~` (F22), so this does too. `path.relative` compares
184
+ * case-insensitively on Windows, which is what Bob's lower-case drive letter (`c:\...`) needs.
185
+ */
186
+ function relPath(p, { cwd, root, host }) {
187
+ if (!baseOf(p) || !root || !cwd) return null;
188
+ try {
189
+ const abs = path.resolve(cwd, host === 'bob' ? p.replace(/^~/, os.homedir()) : p);
190
+ const rel = path.relative(root, abs);
191
+ if (!rel || rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) return null;
192
+ return rel.split(path.sep).join('/');
193
+ } catch {
194
+ return null;
195
+ }
196
+ }
197
+
151
198
  /**
152
199
  * The bytes of `file` written since `offset`, as parsed JSONL objects, and the offset to resume
153
200
  * from. Only COMPLETE lines are consumed, so a line the host is still writing is read next time.
@@ -195,8 +242,13 @@ function toolLabel(name, input) {
195
242
  return typeof named === 'string' && named ? `${name} ${snip(named, 60)}` : name;
196
243
  }
197
244
 
198
- /** Folds one tool call into the session's state: a timeline row, and its file or todo list. */
199
- function applyTool(st, name, input, t, id, status) {
245
+ /**
246
+ * Folds one tool call into the session's state: a timeline row, and its file or todo list.
247
+ * `where` is `{cwd, root, host, by}`: where a path resolves, and who made the edit (`by`: a
248
+ * sub-agent id, or null for the session). A file row is keyed by `(path, by)`; a row with no
249
+ * path (outside the root, or a v1 row) keys as `(file, by)`.
250
+ */
251
+ function applyTool(st, name, input, t, id, status, where) {
200
252
  if (typeof name !== 'string' || !name) return;
201
253
  const label = toolLabel(name, input);
202
254
  const kind = ['Agent', 'Task'].includes(name) ? 'subtask' : 'tool';
@@ -205,12 +257,17 @@ function applyTool(st, name, input, t, id, status) {
205
257
  row.status = status;
206
258
  } else {
207
259
  st.timeline.push({ t, kind, label, tool: name, status, ...(id ? { id } : {}) });
208
- const file = baseOf(input.file_path ?? input.path ?? input.notebook_path);
209
- if (file && EDIT_FIELDS.some((k) => typeof input[k] === 'string')) {
210
- let f = st.files.find((x) => x.file === file);
211
- if (!f) { f = { file, additions: 0, deletions: 0 }; st.files.push(f); }
212
- f.additions += lineCount(input.content ?? input.new_string ?? input.new_source);
213
- f.deletions += lineCount(input.old_string);
260
+ const raw = input.file_path ?? input.path ?? input.notebook_path;
261
+ const file = baseOf(raw);
262
+ if (file && (EDIT_FIELDS.some((k) => typeof input[k] === 'string') || BOB_EDITS.has(name))) {
263
+ const rel = relPath(raw, where);
264
+ const by = where.by;
265
+ let f = st.files.find((x) => (x.path ?? null) === rel && (rel !== null || x.file === file)
266
+ && (x.by ?? null) === by);
267
+ if (!f) { f = { file, path: rel, by, additions: 0, deletions: 0 }; st.files.push(f); }
268
+ // `replace`/`search`: Bob's search_and_replace. apply_diff's SEARCH/REPLACE body is not parsed.
269
+ f.additions += lineCount(input.content ?? input.new_string ?? input.new_source ?? input.replace);
270
+ f.deletions += lineCount(input.old_string ?? input.search);
214
271
  }
215
272
  }
216
273
  if (Array.isArray(input.todos)) {
@@ -220,10 +277,17 @@ function applyTool(st, name, input, t, id, status) {
220
277
  return label;
221
278
  }
222
279
 
223
- /** Folds a transcript delta (Claude's JSONL) in: model, token totals, tool calls, last reply. */
224
- function applyTranscript(st, entries, nowMs) {
280
+ /**
281
+ * Folds a transcript delta (Claude's JSONL) in: model, token totals, tool calls, last reply, and
282
+ * `context` — the input-side tokens (input + cache read + cache creation) of the LAST assistant
283
+ * message carrying usage, which is what the model saw on that call. `null` when the delta has
284
+ * none, so the caller keeps the previous reading. A sidechain line (an older Claude wrote
285
+ * sub-agent turns into the parent transcript) is a different context and never counts.
286
+ */
287
+ function applyTranscript(st, entries, nowMs, where) {
225
288
  const counted = new Set(st.last_message_id ? [st.last_message_id] : []);
226
289
  let reply = null;
290
+ let context = null;
227
291
  for (const e of entries) {
228
292
  const m = e.type === 'assistant' && e.message && typeof e.message === 'object' ? e.message : null;
229
293
  if (!m) continue;
@@ -233,16 +297,22 @@ function applyTranscript(st, entries, nowMs) {
233
297
  st.last_message_id = m.id;
234
298
  st.tokens += (Number(m.usage.input_tokens) || 0) + (Number(m.usage.output_tokens) || 0);
235
299
  }
300
+ // Claude Code's `<synthetic>` messages carry all-zero usage: no reading, never an overwrite.
301
+ if (m.usage && typeof m.usage === 'object' && e.isSidechain !== true && m.model !== '<synthetic>') {
302
+ const used = ['input_tokens', 'cache_read_input_tokens', 'cache_creation_input_tokens']
303
+ .reduce((a, k) => a + (Number(m.usage[k]) || 0), 0);
304
+ if (used > 0) context = { used, window: used > WINDOW ? WINDOW_1M : WINDOW };
305
+ }
236
306
  const t = Date.parse(e.timestamp) || nowMs;
237
307
  for (const b of Array.isArray(m.content) ? m.content : []) {
238
308
  if (b && b.type === 'tool_use') {
239
- applyTool(st, b.name, b.input && typeof b.input === 'object' ? b.input : {}, t, b.id, 'completed');
309
+ applyTool(st, b.name, b.input && typeof b.input === 'object' ? b.input : {}, t, b.id, 'completed', where);
240
310
  } else if (b && b.type === 'text' && typeof b.text === 'string' && b.text.trim()) {
241
311
  reply = { text: b.text, t };
242
312
  }
243
313
  }
244
314
  }
245
- return reply;
315
+ return { reply, context };
246
316
  }
247
317
 
248
318
  /** `{count, additions, deletions, items}` over a file list, `items` capped at `cap`. */
@@ -261,15 +331,19 @@ function todosSummary(items, cap) {
261
331
 
262
332
  const ROLL = { SessionStart: 'idle', UserPromptSubmit: 'busy', PreToolUse: 'busy',
263
333
  Stop: 'waiting-input', SessionEnd: 'ended' };
264
- const KNOWN = new Set([...Object.keys(ROLL), 'SubagentStop', 'PreCompact']);
334
+ const KNOWN = new Set([...Object.keys(ROLL), 'SubagentStart', 'SubagentStop', 'PreCompact']);
335
+ const str = (v) => (typeof v === 'string' && v ? v : null);
265
336
 
266
337
  /**
267
338
  * The previous snapshot and detail (or null), a hook payload, and the clock → the next
268
339
  * `{snap, detail}`, or `null` when the event is not one this writer records. NOT pure: the new
269
340
  * detail reuses, and updates in place, `prevDetail`'s lists — the caller writes the result and
270
341
  * discards the input, so a copy would only cost time on the hook path. `delta` is what
271
- * `readTranscriptDelta` returned for a Stop, or null. Claude-shaped and Bob-shaped payloads
272
- * (`{event, tool, input}`) are both read; a tool payload with no event name is a PreToolUse.
342
+ * `readTranscriptDelta` returned for a Stop or a PreCompact, or null. Claude-shaped payloads
343
+ * (Bob 2.2.3 sends them too) and the older Bob shape (`{event, tool, input}`) are both read; a
344
+ * tool payload with no event name is a PreToolUse. A Bob SessionStart is recorded only for a
345
+ * compaction (`source: "compact"`): its startup and resume fire just before the UserPromptSubmit
346
+ * that records the session anyway.
273
347
  */
274
348
  export function applyHookEvent(prev, prevDetail, payload, now, { host = 'claude', delta = null } = {}) {
275
349
  const p = payload;
@@ -278,12 +352,43 @@ export function applyHookEvent(prev, prevDetail, payload, now, { host = 'claude'
278
352
  : (typeof p.event === 'string' ? p.event : null);
279
353
  if (!ev && tool) ev = 'PreToolUse';
280
354
  if (!KNOWN.has(ev)) return null;
355
+ const compact = ev === 'SessionStart' && p.source === 'compact';
356
+ if (host === 'bob' && ev === 'SessionStart' && !compact) return null;
281
357
  const nowMs = Math.round(now * 1000);
282
358
  const det = prevDetail || {};
283
359
  const snap = prev ? { ...prev } : {
284
360
  session_id: p.session_id, agent: null, title: null, cwd: null, status: 'idle', pid: null,
285
361
  writer: 'hook', host,
286
362
  };
363
+ // v2 fields, defaulted so a v1 snapshot resumed across the upgrade grows them in place.
364
+ snap.agents = Array.isArray(snap.agents) ? snap.agents : [];
365
+ snap.turns = Number(snap.turns) || 0;
366
+ snap.context ??= null;
367
+ snap.compactions = Number(snap.compactions) || 0;
368
+ snap.compacted_at ??= null;
369
+ snap.context_at_compaction ??= null;
370
+ const agentId = str(p.agent_id)?.slice(0, SID_CAP) ?? null;
371
+ // Only the session's own events place it: a worktree sub-agent sends its own cwd.
372
+ if (!agentId && str(p.cwd) && p.cwd !== snap.cwd) {
373
+ snap.cwd = p.cwd;
374
+ snap.root = undefined;
375
+ }
376
+ if (snap.root === undefined) {
377
+ snap.root = snap.cwd ? gitRootOf(snap.cwd) : null;
378
+ snap.repo = snap.cwd ? (mainWorktreeOf(snap.cwd) ?? snap.root) : null;
379
+ }
380
+ const where = { cwd: snap.cwd, root: snap.root, host, by: agentId };
381
+ if (agentId) {
382
+ const type = str(p.agent_type) ? snip(p.agent_type, 60) : null;
383
+ let a = snap.agents.find((x) => x.id === agentId);
384
+ if (!a) {
385
+ a = { id: agentId, type, status: 'running', started: now };
386
+ snap.agents.push(a);
387
+ } else if (type) {
388
+ a.type = type;
389
+ }
390
+ if (ev === 'SubagentStop') a.status = 'done';
391
+ }
287
392
  const st = {
288
393
  timeline: Array.isArray(det.timeline) ? det.timeline : [],
289
394
  conversation: Array.isArray(det.conversation) ? det.conversation : [],
@@ -294,14 +399,39 @@ export function applyHookEvent(prev, prevDetail, payload, now, { host = 'claude'
294
399
  last_message_id: snap.last_message_id ?? null,
295
400
  };
296
401
  snap.updated_at = now;
297
- if (typeof p.cwd === 'string' && p.cwd) snap.cwd = p.cwd;
298
402
  if (typeof p.model === 'string' && p.model) st.model = p.model;
299
- if (ROLL[ev]) snap.status = ROLL[ev];
403
+ // A compaction's SessionStart fires mid-turn: it must not idle a busy session.
404
+ if (ROLL[ev] && !compact) snap.status = ROLL[ev];
405
+ // The transcript delta (Stop, PreCompact): its last usage is the context now.
406
+ const transcript = () => {
407
+ if (!delta) return null;
408
+ const r = applyTranscript(st, delta.entries, nowMs, { ...where, by: null });
409
+ snap.transcript_offset = delta.offset;
410
+ if (r.context) snap.context = r.context;
411
+ return r.reply;
412
+ };
413
+ const compacted = () => {
414
+ snap.compactions += 1;
415
+ snap.compacted_at = now;
416
+ snap.context_at_compaction = snap.context?.used ?? null;
417
+ // Unknown until the next Stop reads the regrown size: a /compact with no Stop after it must
418
+ // not read as still full.
419
+ snap.context = null;
420
+ };
300
421
  if (ev === 'SessionStart') {
301
422
  st.timeline.push({ t: nowMs, kind: 'step', label: `Session ${snip(p.source || 'start', 20)}`, status: 'completed' });
423
+ // Claude and OpenClaude count a compaction on PreCompact, which comes first; Bob has only this.
424
+ if (compact && host === 'bob') compacted();
302
425
  } else if (ev === 'UserPromptSubmit') {
303
426
  snap.turn_started_at = now;
304
427
  snap.phase = null;
428
+ // Bob's start_subtask re-enters Bob's input path with its message as the prompt (2.2.3
429
+ // bundle: `handleInputMessage` → `runTurn` → UserPromptSubmit on the root): not a user turn.
430
+ const pending = Array.isArray(snap.subtask_prompts) ? snap.subtask_prompts : [];
431
+ const mine = typeof p.prompt === 'string' ? pending.indexOf(snip(p.prompt.trim(), CONV_LEN)) : -1;
432
+ if (mine >= 0) pending.splice(mine, 1);
433
+ else snap.turns += 1;
434
+ if (pending.length) snap.subtask_prompts = pending; else delete snap.subtask_prompts;
305
435
  if (typeof p.prompt === 'string' && p.prompt.trim()) {
306
436
  if (!snap.title) snap.title = snip(p.prompt);
307
437
  st.conversation.push({ role: 'user', text: snip(p.prompt, CONV_LEN), t: nowMs });
@@ -309,20 +439,34 @@ export function applyHookEvent(prev, prevDetail, payload, now, { host = 'claude'
309
439
  } else if (ev === 'PreToolUse') {
310
440
  const input = (p.tool_input && typeof p.tool_input === 'object') ? p.tool_input
311
441
  : ((p.input && typeof p.input === 'object') ? p.input : {});
312
- const label = applyTool(st, tool, input, nowMs, typeof p.tool_use_id === 'string' ? p.tool_use_id : null, 'running');
442
+ const label = applyTool(st, tool, input, nowMs, typeof p.tool_use_id === 'string' ? p.tool_use_id : null, 'running', where);
313
443
  if (label) snap.phase = label;
444
+ if (host === 'bob' && BOB_SPAWNS.has(tool)) {
445
+ const named = str(input.name) ?? str(input.title);
446
+ snap.agents.push({ id: null, type: named ? snip(named, 60) : null, status: 'running', started: now });
447
+ snap.attribution = false;
448
+ // The prompt its turn will fire, redacted and cut like any prompt snippet; the next
449
+ // matching UserPromptSubmit consumes it. Capped, so a refused subtask cannot pile up.
450
+ if (tool === 'start_subtask' && str(input.message)) {
451
+ snap.subtask_prompts = [...(snap.subtask_prompts ?? []), snip(input.message.trim(), CONV_LEN)].slice(-TODO_CAP);
452
+ }
453
+ }
314
454
  } else if (ev === 'Stop') {
315
- const reply = delta ? applyTranscript(st, delta.entries, nowMs) : null;
316
- if (delta) snap.transcript_offset = delta.offset;
455
+ const reply = transcript();
317
456
  const last = typeof p.last_assistant_message === 'string' ? p.last_assistant_message : reply?.text;
318
457
  if (last && last.trim()) st.conversation.push({ role: 'assistant', text: snip(last, CONV_LEN), t: nowMs });
319
458
  for (const r of st.timeline) if (r.status === 'running') r.status = 'completed';
459
+ // Bob's id-less branches have no stop of their own: the root turn's end closes them.
460
+ for (const a of snap.agents) if (a.id === null && a.status === 'running') a.status = 'done';
320
461
  snap.phase = null;
321
462
  snap.turn_started_at = null;
322
- } else if (ev === 'SubagentStop') {
463
+ } else if (ev === 'SubagentStart' || ev === 'SubagentStop') {
323
464
  const who = typeof p.agent_type === 'string' && p.agent_type ? ` ${snip(p.agent_type, 60)}` : '';
324
- st.timeline.push({ t: nowMs, kind: 'subtask', label: `Subagent${who} done`, status: 'completed' });
465
+ st.timeline.push({ t: nowMs, kind: 'subtask', label: `Subagent${who} ${ev === 'SubagentStart' ? 'started' : 'done'}`,
466
+ status: 'completed' });
325
467
  } else if (ev === 'PreCompact') {
468
+ transcript();
469
+ compacted();
326
470
  st.timeline.push({ t: nowMs, kind: 'step', label: 'Compacting', status: 'completed' });
327
471
  } else if (ev === 'SessionEnd') {
328
472
  snap.phase = null;
@@ -335,6 +479,7 @@ export function applyHookEvent(prev, prevDetail, payload, now, { host = 'claude'
335
479
  snap.todos = todosSummary(st.todos, TODO_CAP);
336
480
  const detail = {
337
481
  files: filesSummary(st.files, Infinity),
482
+ agents: snap.agents,
338
483
  todos: todosSummary(st.todos, Infinity),
339
484
  conversation: st.conversation.slice(-CONV_CAP),
340
485
  timeline: st.timeline.slice(-LOG_CAP),
@@ -367,7 +512,7 @@ export function recordActivity(root, raw, { host = 'claude', now = Date.now() /
367
512
  if (prev) prevDet = readJson(path.join(dir, 'archive', `${stem}.detail.json`));
368
513
  }
369
514
  const ev = p.hook_event_name ?? p.event;
370
- const delta = ev === 'Stop' && typeof p.transcript_path === 'string'
515
+ const delta = (ev === 'Stop' || ev === 'PreCompact') && typeof p.transcript_path === 'string'
371
516
  ? readTranscriptDelta(p.transcript_path, prev ? Number(prev.transcript_offset) || 0 : 0) : null;
372
517
  const next = applyHookEvent(prev, prevDet, p, now, { host, delta });
373
518
  if (!next) return false;
@@ -151,8 +151,8 @@ export function activityOn(root) {
151
151
  }
152
152
 
153
153
  /**
154
- * The `activity` verb, wired to the two events no other verb runs on (UserPromptSubmit;
155
- * SessionEnd on Claude and OpenClaude). It decides nothing and prints nothing: the entry's
154
+ * The `activity` verb, wired to the events no other verb runs on (UserPromptSubmit; SessionEnd
155
+ * and SubagentStart on Claude and OpenClaude). It decides nothing and prints nothing: the entry's
156
156
  * `trackActivity` records the payload after every verb alike, this one included.
157
157
  */
158
158
  export const cmdActivity = () => 0;
@@ -742,7 +742,8 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
742
742
  // PreToolUse, PostToolUse, Stop — Claude's names, but NOT Claude's protocol. stdout is
743
743
  // read as context on SessionStart only; on PreToolUse it is ignored and the one way to
744
744
  // refuse a call is EXIT CODE 2. The groups this emit wrote before were Claude's whole
745
- // set: `SubagentStop`/`PreCompact` are not Bob events, and the gates answered with a
745
+ // set: `SubagentStop` is not a Bob event (2.2.3 has `PreCompact`/`PostCompact`, not wired
746
+ // here; the activity writer counts a compaction on SessionStart `compact`), and the gates answered with a
746
747
  // stdout JSON Bob never reads — permissive on every call. `--host bob` makes the gates
747
748
  // speak exit codes (js/hosts/hooks.mjs). DELIBERATELY no matcher on PreToolUse
748
749
  // (host-compat O1, revisited): bob-docs.md §2's tool list is already stale against the
@@ -858,6 +859,10 @@ export function claudeHookGroups(cfg, hookOpts, doctrines = null, excluded = [],
858
859
  // user's prompt, and the `activity` verb decides nothing.
859
860
  UserPromptSubmit: [{ hooks: [{ type: 'command', command: activity }] }],
860
861
  SessionEnd: [{ hooks: [{ type: 'command', command: activity }] }],
862
+ // A sub-agent's branch at launch (the Activity garden): a read-only sub-agent fires no gated
863
+ // hook, so without this it would never appear. Never on Bob (the early return above): Bob's
864
+ // hook schema is strict, and one unknown event key drops its whole hooks block.
865
+ SubagentStart: [{ hooks: [{ type: 'command', command: activity }] }],
861
866
  };
862
867
  // Claude Code only: OpenClaude always runs Git Bash on Windows (its `findGitBashPath` exits
863
868
  // without one), and Bob takes the early return above.
@@ -167,6 +167,23 @@ export function activeLoops({ now = new Date() } = {}) {
167
167
  return rows;
168
168
  }
169
169
 
170
+ /**
171
+ * The running rows only, READ-ONLY: the same `runningRow` projection as `activeLoops`, for every
172
+ * registered root whose `LOOP.md` exists and parses, and never a save. The Activity page polls
173
+ * every 2 s and only needs to know which loops run; letting that poll prune or stamp
174
+ * `finishedAt` would race `recordLoop` on the one `loops.json.tmp`. Finished, unreadable and
175
+ * vanished rows are simply absent; `activeLoops` stays their only writer.
176
+ */
177
+ export function runningLoops() {
178
+ const rows = [];
179
+ for (const entry of load()) {
180
+ const file = path.join(entry.root, LOOP_FILE);
181
+ if (!isFile(file)) continue;
182
+ try { rows.push(runningRow(entry, parseLoopFile(readText(file)))); } catch { /* unreadable */ }
183
+ }
184
+ return rows;
185
+ }
186
+
170
187
  /**
171
188
  * Rewrite `root`'s `LOOP.md` `preset` field and nothing else — the per-loop preset picker on
172
189
  * the Active tab. Refuses a `root` the registry does not know about (no arbitrary path