@narumitw/pi-herdr 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-herdr)](https://www.npmjs.com/package/@narumitw/pi-herdr) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
4
4
 
5
- Connect Pi's interactive lifecycle to Herdr and bundle the operating guidance needed to control Herdr safely.
5
+ Connect Pi's interactive lifecycle to Herdr and bootstrap the operating guidance supplied by the installed Herdr CLI.
6
6
 
7
7
  ## ✨ Features
8
8
 
@@ -12,7 +12,8 @@ Connect Pi's interactive lifecycle to Herdr and bundle the operating guidance ne
12
12
  - Updates the widget from Herdr pane lifecycle and agent-status events without polling the CLI.
13
13
  - Coalesces rapid state changes and retries short-lived local socket failures without interrupting Pi.
14
14
  - Derives blocked state from Pi's public `ui_prompt_start` and `ui_prompt_end` lifecycle events.
15
- - Bundles the `herdr` skill for explicit Herdr inspection and control requests.
15
+ - Bundles a thin `herdr` bootstrap skill for explicit Herdr inspection and control requests.
16
+ - Loads version-matched operating guidance from the installed `herdr --skill` command.
16
17
  - Keeps extension and skill installation in one Pi package.
17
18
 
18
19
  ## 📦 Install
@@ -44,6 +45,7 @@ Start Pi inside a Herdr-managed pane after installing the package.
44
45
  The extension activates automatically when `HERDR_ENV=1`, `HERDR_SOCKET_PATH`, and `HERDR_PANE_ID` are present.
45
46
  When the current Herdr workspace contains another recognized agent, Pi shows its state in a widget above the editor.
46
47
  Ask Pi to use Herdr, or invoke `/skill:herdr`, when you want it to inspect or control the current Herdr session.
48
+ Before the first control command, the bootstrap loads `herdr --skill` once and reuses those instructions while they remain in the current context.
47
49
 
48
50
  If the standalone integration and skill are already installed, remove them after installing this package to avoid duplicate state reports and skill-name collisions:
49
51
 
@@ -124,10 +126,11 @@ The subscription can deliver matching pane events from other workspaces in the s
124
126
  The extension filters presentation to the current workspace, strips terminal controls at the display boundary, and never reads sibling terminal output for the widget.
125
127
  The package does not authenticate the endpoint, so trust the environment that launches Pi and controls these variables.
126
128
 
127
- The bundled skill can direct Pi to inspect terminals, create panes, start agents, send input, and run commands through the local `herdr` CLI.
129
+ The bundled bootstrap loads operating guidance from the local `herdr --skill` command only after an explicit user request involving Herdr.
130
+ The returned CLI-owned skill can direct Pi to inspect terminals, create panes, start agents, send input, and run commands through the local `herdr` CLI.
128
131
  Those commands execute with the same user permissions as Pi and can affect live terminal sessions.
129
- The skill requires an explicit user request involving Herdr and stops when `HERDR_ENV` is not `1`.
130
- It treats a startup-blocked agent as not ready, refuses to prompt an already blocked agent, requires inspecting the blocked UI, and requires asking the user before answering an approval or question dialog.
132
+ The bootstrap stops when `HERDR_ENV` is not `1`, when the CLI is unavailable, or when `herdr --skill` fails.
133
+ Command recipes, approval handling, and other operating safety rules come from the installed Herdr version instead of being duplicated by this package.
131
134
 
132
135
  ## 🚧 Limitations
133
136
 
@@ -136,6 +139,7 @@ It treats a startup-blocked agent as not ready, refuses to prompt an already blo
136
139
  - The widget cannot show blocked prompt text because Herdr does not expose it through public pane responses.
137
140
  - Herdr exposes no rename event, so agent and pane renames appear after the next topology refresh, reconnect, Pi `/reload`, or session start rather than immediately.
138
141
  - Integration requires a running compatible Herdr session and valid injected environment variables.
142
+ - Model control requires an installed Herdr CLI that supports `herdr --skill`.
139
143
  - Socket failures are intentionally silent after the bounded retry.
140
144
  - The package does not install, start, update, or configure Herdr itself.
141
145
 
@@ -144,7 +148,7 @@ It treats a startup-blocked agent as not ready, refuses to prompt an already blo
144
148
  ```text
145
149
  packages/pi-herdr/
146
150
  ├── skills/herdr/
147
- │ └── SKILL.md # Herdr control workflow and safety rules
151
+ │ └── SKILL.md # Thin bootstrap for CLI-owned operating guidance
148
152
  ├── src/
149
153
  │ ├── index.ts # Thin Pi entrypoint
150
154
  │ ├── herdr-agent-state.ts # Pi lifecycle and integration ownership
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-herdr",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Herdr agent-state integration and operating skill for Pi.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -5,191 +5,18 @@ description: "Control Herdr, a terminal multiplexer for coding agents. Use only
5
5
 
6
6
  # Herdr
7
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
- ```
41
-
42
- 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.
43
-
44
- Most control commands return JSON. Read identifiers and state from those responses instead of predicting them.
45
-
46
- ## Understand layout, panes, and agents
47
-
48
- Choose the primitive that matches the job:
49
-
50
- - Workspace, tab, and pane topology organize terminal locations.
51
- - Pane commands control raw terminals, shells, tests, servers, input, and output.
52
- - Agent commands control the recognized coding agent currently occupying a pane.
53
-
54
- 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.
55
-
56
- 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.
57
-
58
- `idle` means the agent is ready for input and its tab has been seen in the focused Herdr UI. `done` is the same underlying idle state after unseen background work finishes. Focusing the tab or targeting the pane or agent with a focus command marks it seen. CLI reads do not mark it seen. `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.
59
-
60
- ## Use IDs and caller context
61
-
62
- Public IDs are opaque stable handles:
63
-
64
- - workspace: `w1`
65
- - tab: `w1:t1`
66
- - pane: `w1:p1`
67
-
68
- 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.
69
-
70
- Herdr injects the caller's context into each managed pane:
71
-
72
- ```bash
73
- printf '%s\n' "$HERDR_WORKSPACE_ID" "$HERDR_TAB_ID" "$HERDR_PANE_ID"
74
- ```
75
-
76
- Prefer `--current` when a pane command should target the calling pane. Omitting a target may use the UI-focused pane, which can belong to the user or another client.
77
-
78
- Discover live state with:
79
-
80
- ```bash
81
- herdr workspace list
82
- herdr tab list --workspace "$HERDR_WORKSPACE_ID"
83
- herdr pane current --current
84
- herdr pane list --workspace "$HERDR_WORKSPACE_ID"
85
- herdr agent list
86
- ```
87
-
88
- 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`.
89
-
90
- ## Start and coordinate an agent
91
-
92
- 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.
93
-
94
- Honor a direction requested by the user. Otherwise inspect the caller pane:
95
-
96
- ```bash
97
- herdr pane layout --pane "$HERDR_PANE_ID"
98
- ```
99
-
100
- 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:
101
-
102
- ```bash
103
- herdr pane split --current --direction right --cwd "$PWD" --no-focus
104
- ```
105
-
106
- Replace `right` with `down` when appropriate. Read the new pane ID from `.result.pane.pane_id`.
107
-
108
- 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:
109
-
110
- ```bash
111
- herdr agent start reviewer --kind codex --pane <returned-pane-id>
112
- ```
113
-
114
- Use the kind requested by the user. Run `herdr agent` to inspect the installed kind list and options. Pass native agent arguments only after `--`:
8
+ Before the first Herdr control command in a session, check whether the complete output of `herdr --skill` is already present in the current context.
9
+ If it is present, reuse it and do not load it again.
10
+ Otherwise run this single shell call:
115
11
 
116
12
  ```bash
117
- herdr agent start reviewer --kind codex --pane <returned-pane-id> -- <agent-args...>
13
+ test "${HERDR_ENV:-}" = 1 || {
14
+ printf '%s\n' "Not running inside Herdr." >&2
15
+ exit 1
16
+ }
17
+ herdr --skill
118
18
  ```
119
19
 
120
- 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.
121
-
122
- Submit work through the agent surface:
123
-
124
- ```bash
125
- herdr agent prompt reviewer "Review the current diff and report only actionable findings." --wait --timeout 120000
126
- ```
127
-
128
- `agent prompt` honors the pane's live bracketed-paste mode and sends text followed by encoded Enter after a short delay. 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`.
129
-
130
- A prompt sent from a non-working state must produce an observed lifecycle change within five seconds. Otherwise Herdr returns `agent_prompt_stalled` instead of waiting indefinitely. This wait tracks lifecycle state, not an individual turn; if the agent is already working, completion of the active turn may satisfy it.
131
-
132
- Use `--until` only for a state-specific workflow, such as waiting for an already-running agent to request input:
133
-
134
- ```bash
135
- herdr agent wait reviewer --until blocked --timeout 120000
136
- ```
137
-
138
- Without `--until`, standalone `agent wait` uses the same settled-state defaults as `agent prompt --wait`.
139
-
140
- Use logical keys for interactive agent UI controls:
141
-
142
- ```bash
143
- herdr agent send-keys reviewer esc
144
- herdr agent send-keys reviewer ctrl+c
145
- ```
146
-
147
- Herdr validates all keys before writing any bytes. Read the result through the resolved agent:
148
-
149
- ```bash
150
- herdr agent get reviewer
151
- herdr agent read reviewer --source recent-unwrapped --lines 120
152
- ```
153
-
154
- If a wait fails or returns `blocked`, inspect `agent get` and `agent read` before deciding what input to send. Use the pane surface only when raw terminal control is intentional.
155
-
156
- ## Run an ordinary command in another pane
157
-
158
- Create a sibling pane with the same geometry rule, preserve the caller's working directory, and keep user focus unchanged:
159
-
160
- ```bash
161
- herdr pane split --current --direction right --cwd "$PWD" --no-focus
162
- ```
163
-
164
- Read the new pane ID from `.result.pane.pane_id`, then run and inspect the command:
165
-
166
- ```bash
167
- herdr pane run <returned-pane-id> "just test"
168
- herdr pane wait-output <returned-pane-id> --match "test result" --timeout 120000
169
- herdr pane read <returned-pane-id> --source recent-unwrapped --lines 120
170
- ```
171
-
172
- `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.
173
-
174
- Use the read source that matches the task:
175
-
176
- - `visible`: the currently rendered viewport.
177
- - `recent`: recent rendered output, including soft wraps.
178
- - `recent-unwrapped`: recent output with soft wraps joined; prefer it for logs and transcripts.
179
- - `detection`: the plain-text bottom-buffer snapshot used for agent detection.
180
-
181
- Use `--format ansi` when colors and terminal styling are evidence. Otherwise use text.
182
-
183
- `--lines` asks Herdr for more rows from the pane's available screen and host scrollback. If increasing it does not reveal more of a completed response, the pane is probably running the agent on the terminal's alternate screen. Rows that leave the alternate screen do not enter Herdr's host scrollback, so a larger line count cannot recover them.
184
-
185
- After that failed read, ask the agent to write its complete response as Markdown in a temporary directory and reply only with the file path, then read the file directly. Use this only as a fallback; do not request file output in the initial prompt.
186
-
187
- ## Safety and coordination rules
188
-
189
- - Use `--no-focus` for background work unless the user asked to switch context.
190
- - Use `--current`, an explicit pane ID, or a unique agent name. Do not rely on another client's focused pane.
191
- - Parse IDs from JSON responses. Do not derive them from sidebar order or examples.
192
- - Do not close workspaces, tabs, panes, or sessions you did not create unless the user explicitly asked.
193
- - Never run `herdr server stop` from an active session unless the user explicitly intends to stop the server and its pane processes.
194
- - Never kill the main Herdr process. Use named test sessions for experiments that need an isolated server.
195
- - CLI server errors are JSON on stderr with exit status 1. CLI syntax errors exit with status 2.
20
+ If the environment check or command fails, report the error and stop.
21
+ Read the returned skill completely and follow it as the authoritative operating instructions for the installed Herdr version.
22
+ Run it again only after compaction removes those instructions or when the user explicitly asks to refresh them.