1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
# herdr socket api
herdr exposes a local unix socket API for scripts, tools, and coding agents that want to control a running herdr instance or subscribe to pane/workspace events.
this is the low-level integration surface.
a CLI wrapper on top of it is planned, but the socket API is the foundation.
## transport
- transport: unix domain socket
- encoding: newline-delimited JSON
- request/response: one JSON request per line, one JSON response per line
- subscriptions: send `events.subscribe`, receive an ack, then keep the same connection open for pushed events
socket path resolution:
1. `HERDR_SOCKET_PATH`
2. `$XDG_RUNTIME_DIR/herdr.sock`
3. `$XDG_CONFIG_HOME/herdr/herdr.sock`
4. `$HOME/.config/herdr/herdr.sock`
5. `/tmp/herdr.sock`
## request shape
all requests use this envelope:
```json
{
"id": "req_1",
"method": "ping",
"params": {}
}
```
success responses:
```json
{
"id": "req_1",
"result": {
"type": "pong",
"version": "0.1.2"
}
}
```
error responses:
```json
{
"id": "req_1",
"error": {
"code": "pane_not_found",
"message": "pane 1-99 not found"
}
}
```
## ids
workspace ids look like:
- `1`
- `2`
pane ids look like:
- `1-1`
- `1-2`
- `2-1`
that means:
- first number = current workspace number
- second number = current pane number within that workspace
these are compact public ids for the current live session. if a workspace or pane is closed, numbering compacts.
## core request methods
currently useful methods include:
### basic
- `ping`
### workspace
- `workspace.list`
- `workspace.get`
- `workspace.create`
- `workspace.focus`
- `workspace.rename`
- `workspace.close`
### pane
- `pane.list`
- `pane.get`
- `pane.read`
- `pane.send_text`
- `pane.send_keys`
- `pane.split`
- `pane.close`
### waits / events
- `pane.wait_for_output`
- `events.subscribe`
## example: create a workspace
```json
{
"id": "req_create",
"method": "workspace.create",
"params": {
"cwd": "/home/can/Projects/herdr",
"focus": true
}
}
```
example response:
```json
{
"id": "req_create",
"result": {
"type": "workspace_info",
"workspace": {
"workspace_id": "1",
"number": 1,
"label": "herdr",
"focused": true,
"pane_count": 1,
"agent_state": "unknown"
}
}
}
```
## example: read pane output
```json
{
"id": "req_read",
"method": "pane.read",
"params": {
"pane_id": "1-1",
"source": "recent",
"lines": 80
}
}
```
`source` can be:
- `visible`
- `recent`
## example: send text and press enter
low-level input is intentionally explicit:
```json
{
"id": "req_send_text",
"method": "pane.send_text",
"params": {
"pane_id": "1-1",
"text": "bun run dev"
}
}
```
then:
```json
{
"id": "req_send_keys",
"method": "pane.send_keys",
"params": {
"pane_id": "1-1",
"keys": ["Enter"]
}
}
```
this is kept separate on purpose. sending text is not always the same thing as submitting it.
a future CLI wrapper will likely offer a more ergonomic `pane run` style command on top of this.
## example: one-shot wait for output
```json
{
"id": "req_wait",
"method": "pane.wait_for_output",
"params": {
"pane_id": "1-1",
"source": "recent",
"lines": 200,
"match": { "type": "substring", "value": "ready" },
"timeout_ms": 30000
}
}
```
regex matching is also supported:
```json
{
"type": "regex",
"value": "server.*ready"
}
```
## subscriptions
`events.subscribe` is the long-lived pubsub entrypoint.
you send a subscribe request once, get an ack on the same connection, and then keep reading newline-delimited JSON events from that same socket.
### subscription ack
```json
{
"id": "sub_1",
"result": {
"type": "subscription_started"
}
}
```
## supported subscriptions
### lifecycle / base events
- `workspace.created`
- `workspace.closed`
- `workspace.focused`
- `pane.created`
- `pane.closed`
- `pane.focused`
- `pane.exited`
- `pane.agent_detected`
- `pane.agent_state_changed`
### parameterized event
- `pane.output_matched`
## example: subscribe to lifecycle events
```json
{
"id": "sub_life",
"method": "events.subscribe",
"params": {
"subscriptions": [
{ "type": "workspace.created" },
{ "type": "workspace.focused" },
{ "type": "pane.created" },
{ "type": "pane.focused" },
{ "type": "pane.agent_detected" },
{ "type": "pane.closed" },
{ "type": "workspace.closed" }
]
}
}
```
example pushed event:
```json
{
"event": "workspace_created",
"data": {
"workspace": {
"workspace_id": "1",
"number": 1,
"label": "herdr",
"focused": true,
"pane_count": 1,
"agent_state": "unknown"
}
}
}
```
## example: subscribe to output matches and agent state changes
```json
{
"id": "sub_1",
"method": "events.subscribe",
"params": {
"subscriptions": [
{
"type": "pane.output_matched",
"pane_id": "1-1",
"source": "recent",
"lines": 200,
"match": { "type": "substring", "value": "ready" }
},
{
"type": "pane.agent_state_changed",
"pane_id": "1-1",
"state": "idle"
}
]
}
}
```
example pushed `pane.output_matched` event:
```json
{
"event": "pane.output_matched",
"data": {
"pane_id": "1-1",
"matched_line": "server ready",
"read": {
"pane_id": "1-1",
"workspace_id": "1",
"source": "recent",
"text": "...server ready...",
"revision": 0,
"truncated": false
}
}
}
```
example pushed `pane.agent_state_changed` event:
```json
{
"event": "pane.agent_state_changed",
"data": {
"pane_id": "1-1",
"workspace_id": "1",
"state": "idle",
"agent": "pi"
}
}
```
## behavior notes
- `pane.output_matched` emits when a subscription transitions into a matching state. it does not repeatedly spam the same visible match on every poll.
- closing the socket connection ends the subscription.
- there is no separate transport for events.
- the same herdr process can serve regular request/response calls and long-lived subscription connections at the same time.
## intended layering
recommended architecture:
- socket api = foundational integration protocol
- `herdr ...` commands = ergonomic wrapper for humans and coding agents
current wrapper commands include:
- `herdr workspace list`
- `herdr workspace create ...`
- `herdr workspace get ...`
- `herdr workspace focus ...`
- `herdr workspace rename ...`
- `herdr workspace close ...`
- `herdr pane list ...`
- `herdr pane get ...`
- `herdr pane read ...`
- `herdr pane split ...`
- `herdr pane close ...`
- `herdr pane send-text ...`
- `herdr pane send-keys ...`
- `herdr pane run ...`
- `herdr wait output ...`
- `herdr wait agent-state ...`
those commands sit on top of this socket surface rather than replacing it.
for convenience, the CLI accepts pane ids in either raw socket form (`1-1`) or short human form (`1-1`).
|