dotfiles

andersuno
git clone git://git.andersuno.nu/dotfiles.git
Log | Files | Refs | README

SKILL.md (13867B)


      1 ---
      2 name: herdr
      3 description: "Control Herdr, a terminal multiplexer for coding agents. Use only when the user explicitly mentions Herdr or asks to use Herdr to inspect or control panes, tabs, workspaces, commands, or another agent. Do not use merely because a task could benefit from a background terminal, delegation, or parallel work. Requires HERDR_ENV=1."
      4 ---
      5 
      6 # Herdr
      7 
      8 Herdr organizes terminals into workspaces, tabs, and panes, recognizes coding agents running inside panes, and exposes the current session through the `herdr` CLI.
      9 
     10 Before issuing any control command, verify that this agent is running inside a Herdr-managed pane:
     11 
     12 ```bash
     13 test "${HERDR_ENV:-}" = 1
     14 ```
     15 
     16 If the check fails, say that you are not running inside Herdr and stop. Do not inspect or control the focused Herdr session from outside Herdr.
     17 
     18 When the check passes, the `herdr` binary in `PATH` talks to the current session. Use it to inspect neighboring work, create terminal layout, start agents and commands, read output, and wait for state changes.
     19 
     20 ## Learn the current CLI
     21 
     22 The installed binary is the authority for command syntax. Start with:
     23 
     24 ```bash
     25 herdr --help
     26 ```
     27 
     28 Then print the relevant command group by running the group without a subcommand:
     29 
     30 ```bash
     31 herdr agent
     32 herdr pane
     33 herdr workspace
     34 herdr tab
     35 herdr worktree
     36 herdr terminal
     37 herdr notification
     38 herdr integration
     39 herdr session
     40 herdr machine
     41 ```
     42 
     43 Do not run bare `herdr` for discovery; it launches or attaches the TUI. Do not probe a mutating nested command by omitting arguments. Commands such as `herdr workspace create` are valid with defaults and will execute.
     44 
     45 Most control commands return JSON. Read identifiers and state from those responses instead of predicting them.
     46 
     47 ## Understand layout, panes, and agents
     48 
     49 Choose the primitive that matches the job:
     50 
     51 - Workspace, tab, and pane topology organize terminal locations.
     52 - Pane commands control raw terminals, shells, tests, servers, input, and output.
     53 - Agent commands control the recognized coding agent currently occupying a pane.
     54 
     55 A pane exists whether or not it contains an agent. `agent start` requires an existing available shell pane and never creates, splits, or moves layout. Use pane commands for ordinary processes. Use agent commands when Herdr must validate agent identity or interpret `idle`, `working`, `blocked`, `done`, and `unknown` lifecycle states.
     56 
     57 Agent commands accept either a unique live agent name or the pane ID currently hosting that agent. They do not accept terminal IDs or bare agent-kind labels. Names must match `[a-z][a-z0-9_-]{0,31}` and be unique among live agents. A name follows the current pane occupant and is cleared when that agent exits, is released, or is replaced.
     58 
     59 `idle` and `done` both mean the agent is ready for input. The CLI/API uses the server's seen state to distinguish them; explicit focus commands mark the target seen, while reads do not. Each TUI client tracks viewed completions independently, so its Done badge can differ from the CLI or another client's badge. `blocked` means Herdr recognized an approval or question UI. `unknown` means an agent is present but Herdr cannot classify it confidently; it does not prove completion.
     60 
     61 ## Use IDs and caller context
     62 
     63 Public IDs are opaque stable handles:
     64 
     65 - workspace: `w1`
     66 - tab: `w1:t1`
     67 - pane: `w1:p1`
     68 
     69 Closed tab and pane IDs are not reused. A pane moved into another workspace receives a new workspace-qualified pane ID. After `pane move`, continue with `.result.move_result.pane.pane_id` or the live agent name. The old value is reported as `.result.move_result.previous_pane_id`; only the moved process's inherited caller context keeps resolving that old ID, so do not use it as a general agent target.
     70 
     71 Herdr injects the caller's context into each managed pane:
     72 
     73 ```bash
     74 printf '%s\n' "$HERDR_WORKSPACE_ID" "$HERDR_TAB_ID" "$HERDR_PANE_ID"
     75 ```
     76 
     77 Prefer `--current` when a pane command should target the calling pane. An omitted `pane split` target uses the calling pane when `HERDR_PANE_ID` is available, otherwise the focused pane. Other commands may use the UI-focused pane, which can belong to the user or another client.
     78 
     79 Discover live state with:
     80 
     81 ```bash
     82 herdr workspace list
     83 herdr tab list --workspace "$HERDR_WORKSPACE_ID"
     84 herdr pane current --current
     85 herdr pane list --workspace "$HERDR_WORKSPACE_ID"
     86 herdr agent list
     87 ```
     88 
     89 Creation responses expose the IDs to use next. `workspace create` returns `.result.workspace`, `.result.tab`, and `.result.root_pane`. `tab create` returns `.result.tab` and `.result.root_pane`. `pane split` returns the new pane as `.result.pane`.
     90 
     91 IDs and live agent names are scoped to one server. Two saved SSH machines can both have `w1:p1` or an agent named `reviewer`. Selecting a machine in the TUI does not retarget commands running in your pane: without `--machine`, they still use the inherited session and socket context.
     92 
     93 To control a saved SSH machine, use the same global prefix for discovery and every later command:
     94 
     95 ```bash
     96 herdr --machine <label-or-id> agent list
     97 herdr --machine <label-or-id> pane list
     98 herdr --machine <label-or-id> agent prompt <remote-agent-name> "Reply with your current status." --wait --timeout 120000
     99 ```
    100 
    101 The selector must be an enabled saved profile ID or a unique, case-sensitive label, not an arbitrary SSH hostname. Commands use that profile's remote session without an open TUI. Do not combine `--machine` with `--session` or `--remote`. Discover IDs on that machine; inherited local IDs and `--current` do not identify remote panes.
    102 
    103 Both installations must support machine API forwarding, and the remote server must already be running and API-compatible. Forwarding never installs, starts, or restarts a server and never falls back to Local. Local configuration, session management, installation commands, and interactive attachment are not forwarded. Remote worktree paths must be absolute, `~`, or start with `~/`; plugin link paths must be absolute. A connection failure does not prove a mutation was not applied: inspect remote state before retrying.
    104 
    105 `herdr machine list` lists saved connection profiles, not a cross-machine pane inventory; add `--json` for scripts. Only add, remove, enable, or disable profiles when the user asks. Removing a profile disconnects the client but does not stop remote sessions. Adding a machine uses the remote default session unless `--remote-session` is explicitly supplied. Setup asks before stopping an incompatible server and defaults to No; do not approve replacement without the user's consent. Experimental handoff is not part of `machine add`.
    106 
    107 ## Start and coordinate an agent
    108 
    109 Default to a sibling pane in the current tab and the current working directory. Do not create a workspace, tab, worktree, or different cwd unless the user explicitly requests that topology or location.
    110 
    111 Honor a direction requested by the user. Otherwise inspect the caller pane:
    112 
    113 ```bash
    114 herdr pane layout --pane "$HERDR_PANE_ID"
    115 ```
    116 
    117 Split a wide pane to the right and a narrow or tall pane down. Avoid repeated same-direction splits that create unusably narrow columns or short rows. Keep the user's focus in the calling pane and explicitly preserve the caller's working directory:
    118 
    119 ```bash
    120 herdr pane split --current --direction right --cwd "$PWD" --no-focus
    121 ```
    122 
    123 Replace `right` with `down` when appropriate. Read the new pane ID from `.result.pane.pane_id`.
    124 
    125 An available shell pane must be at its interactive prompt, with the shell itself in the foreground and no foreground command, editor, or agent running. Start a supported agent in that pane with a useful unique name:
    126 
    127 ```bash
    128 herdr agent start reviewer --kind codex --pane <returned-pane-id>
    129 ```
    130 
    131 Use the kind requested by the user. Run `herdr agent` to inspect the installed kind list and options. Pass native agent arguments only after `--`:
    132 
    133 ```bash
    134 herdr agent start reviewer --kind codex --pane <returned-pane-id> -- <agent-args...>
    135 ```
    136 
    137 A successful `agent start` returns only after Herdr detects the expected agent in the same pane and considers it ready for interactive input. If the agent is blocked during startup, the command returns `agent_not_ready` immediately but keeps the name available for `agent read` and `agent send-keys`. Wait until the agent becomes idle before prompting it. Startup defaults to a 30-second timeout.
    138 
    139 Submit work through the agent surface:
    140 
    141 ```bash
    142 herdr agent prompt reviewer "Review the current diff and report only actionable findings." --wait --timeout 120000
    143 ```
    144 
    145 `agent prompt` honors the pane's live bracketed-paste mode and sends text followed by encoded Enter as one ordered submission. It reports successful submission only after both have been written; that alone does not prove the agent started a turn. For Codex on Windows, Herdr sends a paste boundary before Enter so submission does not depend on prompt size. It rejects an agent already waiting at an approval or question dialog with `agent_blocked` before sending any input. Inspect the blocked UI and ask the user before answering it. For normal agent work, `--wait` is enough: it waits for the first settled `idle`, `done`, or `blocked` state. Do not repeat those defaults with `--until`.
    146 
    147 With `--wait`, a prompt sent from a non-working state must produce observed `working` or `blocked` activity. After submission, Herdr waits up to five seconds for that activity; unrelated `idle`, `done`, or session changes do not satisfy this gate. It returns `agent_prompt_stalled` if no activity is observed, or `timeout` if the caller's timeout expires first. The caller timeout includes submission time. Without a timeout, the settled-state wait is indefinite after activity is observed. This wait tracks lifecycle state, not an individual turn; if the agent is already working, completion of the active turn may satisfy it.
    148 
    149 Use `--until` only for a state-specific workflow, such as waiting for an already-running agent to request input:
    150 
    151 ```bash
    152 herdr agent wait reviewer --until blocked --timeout 120000
    153 ```
    154 
    155 Without `--until`, standalone `agent wait` uses the same settled-state defaults as `agent prompt --wait`.
    156 
    157 Use logical keys for interactive agent UI controls:
    158 
    159 ```bash
    160 herdr agent send-keys reviewer esc
    161 herdr agent send-keys reviewer ctrl+c
    162 ```
    163 
    164 Herdr validates all keys before writing any bytes. Read the result through the resolved agent:
    165 
    166 ```bash
    167 herdr agent get reviewer
    168 herdr agent read reviewer --source recent-unwrapped --lines 120
    169 ```
    170 
    171 If a wait fails or returns `blocked`, inspect `agent get` and `agent read` before deciding what input to send. A timeout or stalled response does not prove the prompt was never delivered; do not blindly submit it again. Use the pane surface only when raw terminal control is intentional.
    172 
    173 ## Run an ordinary command in another pane
    174 
    175 Create a sibling pane with the same geometry rule, preserve the caller's working directory, and keep user focus unchanged:
    176 
    177 ```bash
    178 herdr pane split --current --direction right --cwd "$PWD" --no-focus
    179 ```
    180 
    181 Read the new pane ID from `.result.pane.pane_id`, then run and inspect the command:
    182 
    183 ```bash
    184 herdr pane run <returned-pane-id> "just test"
    185 herdr pane wait-output <returned-pane-id> --match "test result" --timeout 120000
    186 herdr pane read <returned-pane-id> --source recent-unwrapped --lines 120
    187 ```
    188 
    189 `pane run` atomically sends command text and Enter. `pane wait-output` searches the selected snapshot immediately, so output that already exists can match. Use `--match <text>` for a literal substring or `--regex <pattern>` for a Rust regular expression. Omitting `--timeout` allows an indefinite wait.
    190 
    191 Use the read source that matches the task:
    192 
    193 - `visible`: the currently rendered viewport.
    194 - `recent`: recent rendered output, including soft wraps.
    195 - `recent-unwrapped`: recent output with soft wraps joined; prefer it for logs and transcripts.
    196 - `detection`: the plain-text bottom-buffer snapshot used for agent detection.
    197 
    198 Use `--format ansi` when colors and terminal styling are evidence. Otherwise use text.
    199 
    200 `--lines` asks Herdr for more rows from the pane's available screen and host scrollback. Alternate-screen rows do not enter ordinary host scrollback. For supported idle agents, Herdr can collect application-owned history and restore the viewport afterward, but not every application or response can be recovered this way.
    201 
    202 If a larger recent read still does not reveal the completed response, ask the agent to write it as Markdown in a temporary directory and reply only with the file path, then read that file on the same machine. Use this only as a fallback; do not request file output in the initial prompt.
    203 
    204 ## Safety and coordination rules
    205 
    206 - Use `--no-focus` for background work unless the user asked to switch context.
    207 - Use `--current`, an explicit pane ID, or a unique agent name. Do not rely on another client's focused pane.
    208 - Parse IDs from JSON responses. Do not derive them from sidebar order or examples.
    209 - Do not close workspaces, tabs, panes, or sessions you did not create unless the user explicitly asked. `workspace close --group` closes the primary workspace and its linked worktree workspaces; never add it merely to bypass `workspace_group_close_required`.
    210 - Use `--trust-repository` only after the user has verified the repository. It grants per-request Git trust; it is not a routine retry for a failed worktree command.
    211 - Client and server versions can differ after an update. Check `herdr status` before relying on new server features. A missing method is not permission to stop or upgrade a server.
    212 - Never run `herdr server stop` from an active session unless the user explicitly intends to stop the server and its pane processes.
    213 - Never kill the main Herdr process. Use named test sessions for experiments that need an isolated server.
    214 - CLI server errors are JSON on stderr with exit status 1. CLI syntax errors exit with status 2.