--- name: hc-agent description: "Manage AI agent fleets in the Herdr desktop app via hc and herdr-app: split workers beside root, prompt/wait/read, fleet status, steer, teardown; `help` lists all. Don't use for the Herdr TUI (herdr-agent), tmux, or Rex." license: MIT compatibility: "Requires the Herdr desktop app's hc (herdr-core) and herdr-app CLIs on PATH and a session inside one of the app's terminals (HC_TERMINAL_ID set) for every operation except `help`, which runs no command. Observed with hc 0.1.20 and Herdr.app 0.1.15 on macOS; workers must report OSC 7501 status." effort: medium metadata: version: 1.0.0 author: "Luong NGUYEN " --- # hc Agent Build and control an AI-agent fleet in the root agent's tab of the **Herdr desktop app**. Keep the **root pane** as orchestrator; add each **worker** as a split to the right running the main agent's own launch profile; then prompt, wait, read, monitor, steer, or tear down through `hc` (herdr-core, which runs the terminals) and `herdr-app` (which arranges the window), wrapped by this skill's scripts. The app is not the Herdr TUI: its terminals set `HC_TERMINAL_ID`, not `HERDR_ENV`, and the `herdr` CLI on PATH there reaches a separate TUI server. This skill never calls `herdr`. A worker's **name** is its `hc-agent.name` label, and its **status** is the OSC 7501 state its CLI reports (`hc get`). Relay reply deltas, not whole screens, to protect the context and token budget. ## Choose the Workflow | Request | Follow | |---|---| | `help`, or what this does and how to drive it | Help in `references/help-request.md` — answer and stop | | Spawn workers beside root | Phases 1–2, then 4–6 if assigning work | | Message an existing agent | Phases 3–5 | | Give several workers different tasks | Phases 3 and 7 (`dispatch`) | | Read without sending | Phase 3, then Phase 5 read only | | Check what the fleet is doing | Phase 6 | | Broadcast to a fleet | Phases 3 and 7 | | Focus/steer a pane | Phase 3, then Phase 7 | | Close workers | Phase 7 teardown | | Main agent's own context is filling up | Phase 8 HANDOFF | Read only the reference needed by that branch: - See `references/app-vs-tui.md` for every herdr-agent operation and how it behaves here (same, different, or unavailable), the observed versions, and what is still unverified. - See `references/hc-recipes.md` for the scripts resolver, spawn waves, what `--start` runs, steering, teardown, and edge cases. - See `references/launch-profile.md` for where a worker's kind, model, thinking level, flags and wrapper come from, and what never carries over. - See `references/delivery-and-waiting.md` for the status table, the prompt contract and exit codes, reading replies, the file fallback, and fleet monitoring. - See `references/context-succession.md` for the main agent's context gate, HANDOFF procedure, and handoff brief template. - See `references/final-report.md` for the closing report's status words, required parts, and examples. ## Answer a Help Request Resolve this branch **before** Prerequisites: someone asking how this works may not have the app installed yet. Take it on `help`, `--help`, `/hc-agent help`, or any plain question about what the skill does. Print the text in `references/help-request.md`, or for a narrower question (how to broadcast, what differs from herdr-agent) answer from that one phase or from `references/app-vs-tui.md` and name it. Run no `hc` or `herdr-app` command, change nothing, and emit no completion report. **Done when:** the user has the summary or their specific answer, and no command ran. ## Check Prerequisites 1. **Route the TUI away.** If `HERDR_ENV=1`, this is a Herdr TUI pane: stop and use `herdr-agent`. If neither `HERDR_ENV` nor `HC_TERMINAL_ID` is set, this is not a Herdr terminal at all: stop, `BLOCKED`. 2. Set `here` to the `scripts/` directory beside this SKILL.md. When the harness does not show the skill's base directory, use the resolver in `references/hc-recipes.md`. 3. Run `python3 "$here/agent.py" check`. It confirms `hc` and `herdr-app` are on PATH (`command -v hc herdr-app`), that `hc get $HC_TERMINAL_ID` resolves with `herdr.space` and `herdr.tab` labels (so the window shows this terminal), and that `herdr-app ls` lists its pane in that tab. On any failure it prints the fix, and the run ends `BLOCKED`. Never act on whatever the window happens to show. 4. Treat the installed CLIs as authoritative: check an uncertain command with `hc --help` or `herdr-app commands`. Never run bare `herdr-app`, which opens the person's window. ## Follow Non-Negotiable Rules 1. **Keep root as a role.** Never replace or close the root pane during fleet work. The one exception is a Phase 8 HANDOFF, where the orchestrator role migrates to a ready successor pane; even then the outgoing pane is retired to read-only, never closed without Rule 8 confirmation. 2. **Run exactly one orchestrator.** Only the current main agent writes to fleet terminals. After a HANDOFF `GO`, the outgoing agent issues no further prompts, splits, or closes. 3. **Never call `herdr`, and spawn only with an explicit split.** Workers come from `herdr-app do pane.split --pane ` through `launch_profile.py --start`. Never use `terminal.open` or `terminal.keep`, which place relative to the focused pane, and never `hc run`, whose children die with their parent and stay hidden from the window. 4. **Address terminals, not names.** Resolve a worker by its exact `hc-agent.name` label in the root's tab, then pass its `t…` address to every `hc` call. hc resolves bare words against its own `--name` namespace, so a label name could reach a different terminal. 5. **Fail closed before writes.** Refuse a `working`, `blocked`, unverifiable (no status), agent-less, or finished target, and never write to your own terminal. A missing status is never idle. 6. **Wait before follow-ups.** Never prompt while an agent is working. Every follow-up is its own `agent.py prompt` cycle. 7. **Surface blockers.** A trust, auth, or permission prompt needs a human. Show the agent with `agent.py focus` and tell the user; never answer the dialog for them, and never send with hc's `--force`. 8. **Confirm destruction.** Closing panes, tabs, or spaces can lose work. Obtain explicit approval and preserve the orchestrator pane unless the user says otherwise. Never stop, signal or restart the person's app or the hc core. 9. **Gate your own context.** Self-check at every Phase 8 gate point; at or above the threshold, HANDOFF instead of continuing to fill this window. 10. **Mirror the main agent.** Start every worker, including a HANDOFF successor, on the **inherited launch profile**: the main agent's harness kind, model, thinking level, setup flags, and launch wrapper. Change only what the user names concretely (a kind, model, thinking level, or flag) or a calling skill's launch contract requires; ask when a request is vague ("something cheaper"). A worker of another kind inherits nothing else. Unreadable same-kind setup flags abort the launch unless `--without flags` opts out. ## Phase 1 — Resolve Root Context Record `root` (`terminal`), `root_pane`, `space`, `tab`, and `project_dir` (`cwd`) from the `check` output. Every script defaults its root to `$HC_TERMINAL_ID`, which persists between tool calls even when shell variables do not. **Done when:** `agent.py check` exited 0 and concrete `root`, `root_pane`, `space`, `tab`, `project_dir`, and `here` values are recorded. ## Phase 2 — Spawn and Ready the Fleet Before spawning, define each worker's unique name, task, and expected deliverable. Names must match `[a-z][a-z0-9_-]{0,31}` and must not look like an address (`t7`); a name already used in the tab gets an epoch suffix. Resolve the inherited launch profile once per spawn wave, as its own tool call, so the user sees it before any agent starts: ```bash python3 "$here/launch_profile.py" --main-model "$main_model" --main-thinking "$main_thinking" >/dev/null ``` Set `main_model` and `main_thinking` to your own model ID and thinking level, and leave either one empty rather than guess. On Claude Code, leave `main_thinking` empty, because the script reads `CLAUDE_EFFORT`. Relay the summary line to the user before the first spawn, including any `⚠` or `warning:` line. If the user already declined bypass for this run, pass `--without bypass` on every worker. `references/launch-profile.md` has the source order, the wrapper rule, and what never carries over. Then start each worker with one `--start` call per worker: ```bash python3 "$here/launch_profile.py" --main-model "$main_model" --main-thinking "$main_thinking" \ --start reviewer --cwd "$project_dir" ``` Each start splits the newest worker pane (or root's) to the right, labels the new terminal, puts focus back where it was, and waits for an `idle` or `done` status; the app sizes the columns. Details and exit codes: `references/hc-recipes.md` → _What `--start` runs_. Use the `name` and `terminal` each start printed for every later call. Confirm the fleet with `python3 "$here/agent.py" fleet --fail-on-blocked` before assigning work. If the user asked only for spawning, still send each worker the worker preamble (Phase 4) as its first prompt. **Done when:** the launch-profile summary reached the user, and every start printed `"outcome": "ready"` and `"focus_restored": true` with a unique name and a terminal in the root's tab, while root remained in its pane. ## Phase 3 — Resolve One Exact Target Run `python3 "$here/agent.py" get `. It matches the exact `hc-agent.name` label or a `t…` address in the root's tab and prints the terminal, pane, kind, and status. If a name is missing or ambiguous, list the fleet with `agent.py fleet` and ask; never silently retarget. Record the name and terminal address and use that address for every later call. **Done when:** one existing target resolves uniquely, and its name, terminal address, and current status are recorded. ## Phase 4 — Prompt Safely ```bash python3 "$here/agent.py" prompt "$target" - --timeout 180 <<'EOF' EOF ``` One call refuses an unsafe target before typing, appends a turn tag `(hc-agent turn )`, sends with `hc send --if idle` (plain `hc send` for `done` or `error`), and waits for **this** turn to settle; its JSON carries the `turn` ID. `hc send` can wait 60 seconds for a person's unfinished draft, so give the shell call a timeout above `--timeout` plus 60 (250000 ms for `--timeout 180`). Exit codes: `0` settled, `3` blocked, `4` unverifiable, `5` no agent, `6` working, `7` stalled, `8` timeout, `9` exited; `references/delivery-and-waiting.md` has the full contract, `--raw`, and the response to each code. Start each worker's **first** task with the worker preamble: `You are , a worker in an hc-agent fleet. The orchestrator owns this tab and its layout: do not create, close, or type into other terminals, and do not start sub-agents unless asked.` **Done when:** the prompt printed `"outcome": "settled"`, or a named outcome was propagated. ## Phase 5 — Read and Verify Map the failure first: `blocked` needs a human, `stalled` was submitted with no newer status after it (inspect, never blindly resend), and `timeout` found no settled state inside the budget. Propagate each; never report it as a reply. On success, read the lines after that turn's echo and relay only the relevant delta: ```bash python3 "$here/agent.py" read "$target" --turn "$turn" ``` It prints what follows the turn tag in the screen plus 400 history lines (`hc read`). Exit 4 means the tag is not there: raise `--lines`, or use the file fallback in `references/delivery-and-waiting.md`. **Done when:** the reply delta came from `agent.py read` after a settled outcome, or the blocked/stalled/timeout outcome is reported and nothing more was sent. ## Phase 6 — Monitor and Report ```bash python3 "$here/agent.py" fleet ``` It lists every terminal in the root's tab with role (`worker`, `main`, `other`, `root`), status, kind, and message, blocked first. It polls one `hc get` per terminal, so report it as "polled at