# Neurons A Herdr layout where your agents are living neurons. A thin sidebar (spaces and agents lists) sits on the left. On the right, a 300px "brain" strip shows one rounded region per space. Inside each region every agent is a branching neuron that glows and pulses while it works, with signal dots running along its dendrites. Sub-agents appear as small neurons wired to their parent and fade out when they finish. Below the brain is the active tab's terminal pane. ![Neurons](preview.png) ## What you see - **Left sidebar, 240px** (`chrome` colour `#111318`, not resizable): brand header 46px (`workspace-chrome`), then Spaces and Agents lists in equal halves (min 90px each), then a 69px footer (`workspace-chrome` with `footer: true`). - **Right column** (padding 8, gap 6): - **Brain, 300px** (min 160, max 900, radius 12, bg `#0b0d11`, draggable window area). One panel per space in a grid. Each panel has a faint white fill, a 1px border, a status dot, the name `space ยท branch` (11px), and a blue "N trabajando" counter when agents are working (the string is Spanish in the source; translate if you like). - **Tab bar, 42px** (`tabs` mod): the space's tabs as pills, plus a "+" button that opens Herdr's `new-menu` (terminal, any installed agent, new space, worktree). Without this bar there is no way to start an agent from the layout. - **Desks, remaining height**: the active tab's panes. Radius 10, 1px `#22262e` border, `#f59e0b` focus border, 30px `pane` header always visible, `lone: true`. - Theme: `graphite`, Geist 13px, accent `#f59e0b`, background `#14161c`, foreground `#e6e8ec`, no titlebar, traffic lights at 12,16, terminal padding 10x12. ## How it behaves - Each neuron gets a stable colour: hue = `(hash(address) * 137.508) % 360` at HSL 0.85 / 0.62, where `hash` is FNV-1a over the agent address. The colour never changes between redraws or restarts. Colour does not encode status. - Status is shown by intensity: - working: full energy, bright halo, fast breathing (about 380ms period), white signal dots running toward the body. - blocked: energy 0.9 plus a pulsing amber (`#f59e0b`) ring. - done: energy 0.5 plus a pulsing green (`#34d399`) ring. - idle/unknown: energy 0.15, dim and slow. - A space with no agent shows a dormant grey (`#475569`) cell, so every space stays visible. - Agents in the same space are linked by curved synapse wires. The wire turns blue (`#38bdf8`) with three travelling dots when either end is working. - Sub-agents are mini neurons (radius 5) orbiting their parent at about 70px, wired with a curve in the parent's colour. They grow in over 450ms and shrink and fade over 900ms after they finish. - Clicking a neuron runs `agent.focus {terminal: address}`. Clicking a dormant cell runs `space.select {id}`. - About 16 slow dust particles drift upward. Redraw runs every 110ms and only notifies when something is alive; idle redraws are about every 8th tick. ## Built from Layout `layouts/neurons.json`: root row, `titlebar: none`, then children `sidebar` (column, 240px) and `neurons-work` (column). `sidebar` holds blocks `brand`, a `sidebar-lists` column with `spaces` and `agents` blocks, and `sidebar-footer`. `neurons-work` holds block `neurons-brain` (`content: {mod: "neurons"}`), block `neurons-tabs` (42px, `content: {mod: "tabs"}`) and block `neurons-desks` (`content: {tab: "active", pane: {...}}`). Mods used: the shipped `workspace-chrome`, `spaces`, `agents`, `tabs`, `pane`, plus the custom `neurons`. Nothing else is referenced. `mods/neurons/` (`mod.json` is `{"place":"none"}`, so the layout places it; `main.js` is one `View` subclass): - Imports: `View, div, PathBuilder` from `gpui-kit`; `agents, spaces, terminals, run, exec, home` from `herdr`. - Data sources: - `agents()` for address, status, space, tab_name. - `spaces()` for id, name, branch, status, active. - `terminals()`: any non-exited terminal with a `parent` is a sub-agent of that parent address. - Self-reported agents: Herdr does not always recognise an agent started from the "+" menu (`reported: false`, no status). Hooks therefore also write `~/.config/herdr-app/data/neurons/main/.json` = `{terminal, app, status: "working"|"idle", t}`. The mod merges them with `agents()` (once per tick, not per frame) for terminals that are still live and not already in `agents()`. The space comes from the terminal label `herdr.space` (fall back to the `where` label `"Space / Tab"`, matching the tab name too because two unnamed spaces can share a folder name). A `working` entry older than 15 min counts as idle; any entry older than 30 min is deleted. - Hook files: `exec("ls"/"cat"/"rm")` on `~/.config/herdr-app/data/neurons/sub/*.json`, polled every 2s via `cx.timer.every`. Each file holds `{terminal, app, label, t}`. Files older than 6h are deleted. - Drawing: bodies, halos and dust are absolutely positioned `div`s (`rounded_full`, translucent `bg`). Dendrites and wires are `PathBuilder.stroke(w).move_to().curve_to().build()` passed to `window.paint_path(path, colour)`. Each neuron has 5-6 dendrites with two twigs each, all derived from the hash so the shape is stable. The view tracks its size with `on_size_change`. `neurons-hook.py` (usage `start|stop ` for sub-agents, `working|idle|end ` for the agent itself): reads the agent's hook JSON on stdin and the parent terminal from `HC_TERMINAL_ID`. On `start` it writes `data/neurons/sub/...json`; on `stop` it deletes it. `working`/`idle` write `data/neurons/main/.json`; `end` deletes it. It exits silently when `HC_TERMINAL_ID` is unset. ### Hook install Claude Code, in `~/.claude/settings.json` (merge into existing arrays): ```json { "hooks": { "SubagentStart": [{ "hooks": [{ "type": "command", "command": "python3 ~/.config/herdr-app/neurons-hook.py start claude", "async": true, "timeout": 5 }] }], "SubagentStop": [{ "hooks": [{ "type": "command", "command": "python3 ~/.config/herdr-app/neurons-hook.py stop claude", "async": true, "timeout": 5 }] }], "SessionStart": [{ "hooks": [{ "type": "command", "command": "python3 ~/.config/herdr-app/neurons-hook.py idle claude", "async": true, "timeout": 5 }] }], "UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "python3 ~/.config/herdr-app/neurons-hook.py working claude", "async": true, "timeout": 5 }] }], "Stop": [{ "hooks": [{ "type": "command", "command": "python3 ~/.config/herdr-app/neurons-hook.py idle claude", "async": true, "timeout": 5 }] }], "SessionEnd": [{ "hooks": [{ "type": "command", "command": "python3 ~/.config/herdr-app/neurons-hook.py end claude", "async": true, "timeout": 5 }] }] } } ``` Codex, in `~/.codex/hooks.json` (same shape under `"hooks"`, events `SubagentStart`/`SubagentStop` with `start`/`stop`, and `SessionStart`/`Stop` with `idle`, `UserPromptSubmit` with `working`; all with app `codex`. Codex has no `SessionEnd`, so a stale file is cleaned by the 30 min expiry). ## Watch out - Kimi and Ollama emit no sub-agent events. Their sub-agents never show up. - Sub-agents appear only if the agent started them with `hc run` (they are then terminals with a `parent`), or if a hook above is installed. - Claude Code reads its hooks at session start: sessions opened before installing them do not report. Codex asks the user to trust new hooks the first time (a prompt only the user can answer). - If a render exceeds the runtime budget Herdr shows "This view could not be re-rendered" and keeps the last good frame; keep per-frame work small (compute lists once per tick, few paths). - The hook only works inside a Herdr terminal (needs `HC_TERMINAL_ID`). A crashed agent can leave a file behind until the 6h stale cleanup. - The mod runs `ls`, `cat` and `rm` through `exec`, and reads only `~/.config/herdr-app/data/neurons/sub/`. No network. - The hook path in the snippets assumes `~/.config/herdr-app/`; adjust if `HERDR_APP_HOME` differs. - With many spaces the grid gets small; the brain strip is resizable (160-900px) but the sidebar is not. - The "trabajando" label is hard-coded Spanish. ## Done when 1. `herdr-app check` passes for `mods/neurons`, and `layout.switch {name: "neurons"}` shows the layout. 2. Every space has a panel; an agent-less space shows a dim dormant cell. 3. Starting an agent makes a neuron appear, and it brightens, pulses and sends signal dots while `working`. 4. The same neuron keeps the same colour across restarts. 5. Piping `{"agent_id":"a1"}` into `HC_TERMINAL_ID= neurons-hook.py start claude` makes a mini neuron appear on that agent within 2s. The same with `stop` makes it fade out within about 1s. 6. Clicking a neuron focuses its terminal.