@howaboua/pi-shepherdr 0.1.6 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @howaboua/pi-shepherdr
2
2
 
3
+ ## 0.2.1
4
+
5
+ - Deliver peer messages directly to Pi without submitting unsent human drafts.
6
+
7
+ - Preserve slash-command arguments and use the target session's skill and prompt-template expansion.
8
+ - Return submission-only acknowledgements for registered extension commands instead of waiting for an assistant reply.
9
+
10
+ Requires Pi 0.84.4 or newer. Update and reload Shepherdr on both controllers and workers, and Pi Codex Conversion where installed.
11
+
12
+ - Fixed idle agent reports and manual checkpoint requests to preserve prompt preparation, coalesce concurrent continuations, and process reports arriving during turn settlement.
13
+
14
+ - Manual Compact reuses notes saved in the last completed turn for Local, Tree, and Remote notes-only windows, avoiding a redundant checkpoint turn. Explicit compaction instructions still request a checkpoint.
15
+ - Compact tool output now offers Off, On, and Minimal. Minimal keeps nested tool results and an expand hint while hiding the trailing Code / Notebook text preview until expanded. Existing Off and On settings keep their behavior.
16
+ - Shepherdr help makes local routing explicit: agent calls default to the host running Pi, while unfiltered discovery searches all machines. Remote calls use profile IDs, not machine labels or hostnames.
17
+ - Fixed Shepherdr startup after a Herdr executable replacement leaves a stale ` (deleted)` path. Recovery silently uses the replacement at the same location. Command failures remain visible and no longer imply that Herdr is outdated.
18
+
19
+ ## 0.2.0
20
+
21
+ - Shepherdr now reads existing Herdr machine profiles and requires Herdr 0.9 or newer. Manage profiles in Herdr; `shepherdr.json`, old machine aliases and their saved watches are no longer used.
22
+
23
+ - Agent prompts and reports identify their source workspace, tab and pane, including current names.
24
+ - Attributed messages to running Pi Codex agents use developer steering. Idle tasks retain normal user kickoff and extension preparation.
25
+ - `send` delivers peer messages without blocking or subscribing; use `assign` to delegate work to an existing agent.
26
+ - Automatic task watches end on completion or failure. Only explicit `watch` subscriptions persist; legacy watches are cleared with a notice.
27
+
3
28
  ## 0.1.6
4
29
 
5
30
  - Deliver blocked-agent handoffs even when transcripts are unavailable.
package/README.md CHANGED
@@ -14,7 +14,7 @@ With Pi Codex's compatible custom developer-message API active, asynchronous wor
14
14
  pi install npm:@howaboua/pi-shepherdr
15
15
  ```
16
16
 
17
- Requires Pi 0.84.3 or newer, Herdr 0.8.x and the Herdr Pi integration:
17
+ Requires Pi 0.84.4 or newer, Herdr 0.9 or newer and the Herdr Pi integration:
18
18
 
19
19
  ```bash
20
20
  herdr integration install pi
@@ -22,7 +22,7 @@ herdr integration install pi
22
22
 
23
23
  Do not load Pi Codex's example `agents.toml` custom tool alongside Shepherdr; they own the same agent surface.
24
24
 
25
- Pi Codex 3.0.25 or newer is optional. Without it, Shepherdr remains a normal Pi extension.
25
+ Pi Codex is optional. Without it, Shepherdr remains a normal Pi extension.
26
26
 
27
27
  ## Enable orchestration
28
28
 
@@ -34,9 +34,15 @@ The agent tool is always available in Pi, Code Mode and Notebook Mode. Run Pi in
34
34
 
35
35
  The command only records one visible guidance message without triggering a turn. Run `/herdr` again to return to normal guidance. Resumed sessions restore their last mode; new sessions start with normal guidance. Tool availability and monitoring do not depend on this mode.
36
36
 
37
- `/herdr machines` opens the Add/Remove Machine interface. Settings live at `<pi-agent-directory>/shepherdr.json`, where the directory defaults to `~/.pi/agent` and `PI_CODING_AGENT_DIR` overrides it. `/herdr connect [machine]` retries failed connections or incomplete monitoring without dropping a working remote connection.
37
+ Shepherdr reads Herdr's existing machine profiles and connects enabled profiles at session startup. Manage profiles in Herdr. `/herdr connect [profile-id]` refreshes the catalog and retries failed connections or incomplete monitoring without dropping working connections. A catalog refresh stops watches for disabled or removed profiles without stopping remote agents.
38
38
 
39
- Remote machines connect over noninteractive SSH. The target needs Node, Herdr 0.8.x, the Herdr Pi integration and a running Herdr session. Shepherdr installs one helper at `~/.pi/agent/shepherdr.mjs` on each remote, runs it only for the connection lifetime and leaves no remote daemon behind.
39
+ Profiles belong to the host running Pi, not the machine displaying its terminal. Omit `machine` for local agent calls. `list` and `find` search all machines unless filtered. Explicit `local` also means the host running Pi. For remote calls, use the opaque profile ID returned by `list`, not its label or hostname. Renaming a profile changes its label, not its routing identity.
40
+
41
+ Remote machines connect over noninteractive SSH. The target needs `node` on its SSH PATH, Herdr 0.9 or newer, the Herdr Pi integration and a running Herdr session. Shepherdr installs one helper at `~/.pi/agent/shepherdr.mjs` on each remote, runs it only for the connection lifetime and leaves no remote daemon behind. Herdr's multi-machine UI does not expose a cross-machine automation socket, so Shepherdr still owns its remote transport and Pi transcript reads.
42
+
43
+ ### Migrating from separate Shepherdr machines
44
+
45
+ `shepherdr.json` is no longer read. Existing Herdr profiles are used directly. Configure any missing profiles in Herdr on the host running Pi. Old machine aliases are not migrated. Legacy watches, including local watches, are cleared with a notice because they cannot distinguish explicit subscriptions from accidental ones. Re-select any ongoing watches explicitly.
40
46
 
41
47
  ## Agent calls
42
48
 
@@ -48,13 +54,18 @@ Call the `agents` tool with `action: "help"` before first use, then send flat re
48
54
  | `list` | Profiles, machines and matching Pi agents |
49
55
  | `find` | Agents matching a query or status |
50
56
  | `spawn` | Spawn a profiled Pi agent and send its initial task |
51
- | `send` | Send work or a follow-up to an existing agent |
57
+ | `send` | Send a peer message without waiting or subscribing |
58
+ | `assign` | Delegate a task to an existing agent |
52
59
  | `read` | Read the latest assistant reply or bounded terminal output |
53
60
  | `answer` | Answer a worker blocked on Pi Ask |
54
61
  | `watch` | Push future settlement from an existing Pi agent |
55
62
  | `unwatch` | Stop reporting an agent |
56
63
 
57
- `spawn`, `send` and `answer` block by default. Set `blocking: false` only when the controller should continue other work immediately. Completion and blockage are then delivered automatically.
64
+ `spawn`, `assign` and `answer` block by default. Set `blocking: false` when the controller should continue other work immediately. Task completion and blockage are then delivered automatically.
65
+
66
+ Questions, status updates and replies use `send`. It returns after submission, does not accept `blocking`, and never creates or changes a watch or task. Use `assign` only to delegate work whose result you need, not to exchange coordination messages.
67
+
68
+ Automatic delegation watches end when the task finishes or fails. Blocked tasks stay watched until resolved. Only an explicit `watch` keeps reporting subsequent work until `unwatch`. Sending an update to your worker preserves its existing task watch without replacing the task.
58
69
 
59
70
  Reviewer spawns always block, even when `blocking: false` is supplied. The controller waits for the review before continuing work on its scope.
60
71
 
@@ -62,6 +73,14 @@ Every `spawn` needs an `agent_type` and a concise two- or three-word `label`. Th
62
73
 
63
74
  Cancelling a blocking call does not kill its worker. The waiter detaches and the eventual result returns through normal asynchronous delivery.
64
75
 
76
+ Prompts sent through `agents` identify peer messages versus delegated tasks and include the sender's host, session, workspace, tab and pane identity, with current names. Reports include source workspace and tab names too. Raw `herdr agent prompt` calls bypass this attribution. These are runtime locations, not the desktop window showing a pane.
77
+
78
+ Messages sent through `agents` bypass the receiving Pi editor, preserving unsent drafts. Update and reload Shepherdr on receiving agents as well as controllers. If a receiver is unavailable, delivery fails without pasting into its terminal. Raw `herdr agent prompt` still uses terminal input and does not provide this protection.
79
+
80
+ Messages beginning with `/` use the target Pi session's command, skill and prompt-template expansion, with sender attribution kept out of the arguments. Skills and templates retain normal task waiting. Registered extension commands return `commandSubmitted: true` without waiting or adding a task watch, even through `spawn` or `assign`; submission does not confirm command success. TUI-only commands such as `/model` and `/settings` are not available through this route. When Pi Codex Conversion is installed, update and reload it too.
81
+
82
+ Idle messages start a prepared user turn. Messages arriving during a run use steering, promoted to developer messages when Pi Codex developer delivery is active. Otherwise they remain ordinary Pi custom messages.
83
+
65
84
  For `answer` inside Code or Notebook Mode, update Pi Ask on workers together with Shepherdr on controllers.
66
85
 
67
86
  ## Profiles
package/index.ts CHANGED
@@ -6,6 +6,7 @@ import { registerAgentController } from "./src/controller.js";
6
6
  import { registerDeveloperDelivery } from "./src/delivery.js";
7
7
  import { AgentFleet } from "./src/fleet.js";
8
8
  import { registerAgentEventRenderer } from "./src/messages.js";
9
+ import { registerPeerInbox } from "./src/peer-inbox.js";
9
10
  import { installAgentProfiles } from "./src/profiles.js";
10
11
 
11
12
  const CODE_MODE_PACKAGE = "@howaboua/pi-codex-conversion";
@@ -17,6 +18,7 @@ export default async function shepherdrExtension(
17
18
  registerPackageChangelog(pi);
18
19
  await installAgentProfiles();
19
20
  await registerDeveloperDelivery(pi);
21
+ registerPeerInbox(pi);
20
22
  const fleet = new AgentFleet(pi);
21
23
  const tool = createAgentsTool(fleet);
22
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-shepherdr",
3
- "version": "0.1.6",
3
+ "version": "0.2.1",
4
4
  "description": "Persistent blocking and asynchronous Pi agents through Herdr.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -43,9 +43,9 @@
43
43
  "pack:dry": "npm pack --dry-run"
44
44
  },
45
45
  "peerDependencies": {
46
- "@howaboua/pi-codex-conversion": ">=3.0.30",
46
+ "@howaboua/pi-codex-conversion": ">=3.0.32",
47
47
  "@earendil-works/pi-ai": ">=0.84.3",
48
- "@earendil-works/pi-coding-agent": ">=0.84.3",
48
+ "@earendil-works/pi-coding-agent": ">=0.84.4",
49
49
  "@earendil-works/pi-tui": ">=0.84.3",
50
50
  "typebox": "*"
51
51
  },
@@ -55,7 +55,7 @@
55
55
  }
56
56
  },
57
57
  "devDependencies": {
58
- "@howaboua/pi-codex-conversion": "3.0.30",
58
+ "@howaboua/pi-codex-conversion": "3.0.32",
59
59
  "@biomejs/biome": "^2.5.10",
60
60
  "@earendil-works/pi-ai": "0.85.1",
61
61
  "@earendil-works/pi-coding-agent": "0.85.1",
@@ -11,10 +11,11 @@ const ACTIONS = [
11
11
  "watch",
12
12
  "unwatch",
13
13
  "send",
14
+ "assign",
14
15
  "read",
15
16
  "answer",
16
17
  ] as const;
17
- const BLOCKING_ACTIONS = new Set<string>(["spawn", "send", "answer"]);
18
+ const BLOCKING_ACTIONS = new Set<string>(["spawn", "assign", "answer"]);
18
19
  export const READ_SOURCES = ["latest", "visible", "recent"] as const;
19
20
  const STATUSES = ["idle", "working", "blocked", "done", "unknown"] as const;
20
21
 
@@ -38,7 +39,8 @@ const ACTION_FIELDS: Record<(typeof ACTIONS)[number], ReadonlySet<string>> = {
38
39
  ]),
39
40
  watch: new Set(["action", "machine", "target"]),
40
41
  unwatch: new Set(["action", "machine", "target"]),
41
- send: new Set(["action", "machine", "target", "message", "blocking"]),
42
+ send: new Set(["action", "machine", "target", "message"]),
43
+ assign: new Set(["action", "machine", "target", "message", "blocking"]),
42
44
  read: new Set(["action", "machine", "target", "source", "lines"]),
43
45
  answer: new Set(["action", "machine", "target", "answers", "blocking"]),
44
46
  };
@@ -55,9 +57,7 @@ const AskAnswerParameters = Type.Object(
55
57
  const AgentsRequest = Type.Object(
56
58
  {
57
59
  action: StringEnum(ACTIONS),
58
- machine: Type.Optional(
59
- Type.String({ description: "Configured machine; defaults to local" }),
60
- ),
60
+ machine: Type.Optional(Type.String()),
61
61
  target: Type.Optional(
62
62
  Type.String({ description: "Agent name or pane ID" }),
63
63
  ),
@@ -79,7 +79,7 @@ const AgentsRequest = Type.Object(
79
79
  blocking: Type.Optional(
80
80
  Type.Boolean({
81
81
  description:
82
- "Wait for this work; defaults true. False returns now and pushes settlement later",
82
+ "Delegation only; defaults true. False pushes task settlement later",
83
83
  }),
84
84
  ),
85
85
  query: Type.Optional(Type.String()),
@@ -118,6 +118,11 @@ export function parseAgentsRequest(input: unknown): AgentsParams {
118
118
  if (typeof action !== "string" || !Object.hasOwn(ACTION_FIELDS, action)) {
119
119
  throw new Error(`agents action must be one of: ${ACTIONS.join(", ")}`);
120
120
  }
121
+ if (action === "send" && "blocking" in value) {
122
+ throw new Error(
123
+ "send is message-only; omit blocking. Use assign to delegate work",
124
+ );
125
+ }
121
126
  const unknown = Object.keys(value).filter(
122
127
  (key) => !ACTION_FIELDS[action as keyof typeof ACTION_FIELDS].has(key),
123
128
  );
@@ -1,15 +1,25 @@
1
1
  import type { AgentToolUpdateCallback } from "@earendil-works/pi-coding-agent";
2
+ import { activityTask } from "./activity.js";
2
3
  import type { AgentsParams, READ_SOURCES } from "./agents-contract.js";
3
4
  import type { AgentFleet, ConnectedMachine } from "./fleet.js";
4
5
  import { getSnapshot } from "./herdr.js";
6
+ import { isDispatchRejected } from "./herdr-client.js";
7
+ import { agentSource } from "./messages.js";
8
+ import type { WorkAttempt } from "./monitor-state.js";
5
9
  import { loadAgentProfiles } from "./profiles.js";
6
10
  import type { ClaimedSettlement } from "./settlement.js";
7
- import type { AgentStatus, PaneInfo, SessionSnapshot } from "./types.js";
11
+ import type {
12
+ AgentStatus,
13
+ PaneInfo,
14
+ PeerDelivery,
15
+ SessionSnapshot,
16
+ } from "./types.js";
8
17
 
9
18
  const MAX_LIST_ITEMS = 30;
10
19
  const MAX_TERMINAL_READ_CHARS = 36_000;
11
20
 
12
- export function toolResult(value: Record<string, unknown>) {
21
+ export function toolResult(value: Record<string, unknown>, warning?: string) {
22
+ if (warning) value = { ...value, next: warning };
13
23
  return {
14
24
  content: [{ type: "text" as const, text: JSON.stringify(value) }],
15
25
  details: value,
@@ -38,18 +48,27 @@ export async function agentsHelp(): Promise<Record<string, unknown>> {
38
48
  "agent_type label message name? machine? placement? workspace? pane? cwd? base? blocking?",
39
49
  watch: "target machine?",
40
50
  unwatch: "target machine?",
41
- send: "target message machine? blocking?",
51
+ send: "target message machine?",
52
+ assign: "target message machine? blocking?",
42
53
  read: "target machine? source? lines?",
43
54
  answer: "target answers machine? blocking?",
44
55
  },
45
56
  rules: {
57
+ machine:
58
+ "Omit for local (host running Pi); list/find omit for all machines. Remote: profile ID from list, not label/hostname",
46
59
  target: "Use spawn/find target exactly",
47
60
  label: "2-3 words; tab/session",
48
61
  answers: "[{selections?:string[],other?:string,comment?:string}]",
62
+ send: "Peer questions, updates, replies; submission only, no wait or watch",
63
+ assign: "Delegate a task to an existing agent",
49
64
  blocking:
50
- "reviewers always wait; otherwise false only for independent work; async results push, never poll",
65
+ "spawn/assign/answer default true; false pushes task settlement; reviewers always wait; never poll",
66
+ watch:
67
+ "Explicit watch persists until unwatch; automatic task watches end on finish/failure, not blockage",
51
68
  prompt:
52
69
  "Only task + inaccessible context; no method/evidence/reporting boilerplate",
70
+ slash:
71
+ "Leading / uses target Pi commands/skills/templates; extension commands are submission-only, even with assign/spawn; TUI-only commands unavailable",
53
72
  reuse:
54
73
  "Reuse only same investigation; reviews independent; new scope = new agent",
55
74
  ...(profiles.has("general")
@@ -135,7 +154,7 @@ export async function listFleetAgents(
135
154
  compactAgent(
136
155
  agent,
137
156
  machine.snapshot!,
138
- machine.name,
157
+ machine.id,
139
158
  machine.monitoredPaneIds?.has(agent.pane_id) ?? false,
140
159
  ),
141
160
  )
@@ -143,7 +162,7 @@ export async function listFleetAgents(
143
162
  });
144
163
  const workspaces = machines.flatMap((machine) =>
145
164
  (machine.snapshot?.workspaces ?? []).map((workspace) => ({
146
- machine: machine.name,
165
+ machine: machine.id,
147
166
  id: workspace.workspace_id,
148
167
  label: workspace.label,
149
168
  })),
@@ -224,10 +243,15 @@ export function settlementResult(
224
243
  `${settlement.agent.pane_id} assistant stopped with an error`,
225
244
  );
226
245
  }
246
+ const { pane, name, ...source } = agentSource(
247
+ settlement.agent,
248
+ settlement.labels,
249
+ );
227
250
  return {
228
251
  machine,
229
- target: settlement.agent.pane_id,
230
- ...(settlement.agent.name ? { name: settlement.agent.name } : {}),
252
+ target: pane,
253
+ ...(name ? { name } : {}),
254
+ source,
231
255
  status: settlement.status,
232
256
  ...(settlement.reply ? { reply: settlement.reply.text } : {}),
233
257
  ...(settlement.ask
@@ -259,43 +283,95 @@ export async function dispatchAgentWork(
259
283
  blocking: boolean,
260
284
  signal: AbortSignal,
261
285
  onUpdate: AgentToolUpdateCallback<Record<string, unknown>>,
262
- send: () => Promise<void>,
286
+ send: () => Promise<PeerDelivery | void>,
263
287
  options: { expectUserMessage?: boolean } = {},
264
- ): Promise<ClaimedSettlement | undefined> {
288
+ ): Promise<{
289
+ settlement?: ClaimedSettlement;
290
+ command?: true;
291
+ warning?: string;
292
+ }> {
265
293
  signal.throwIfAborted();
266
- const baseline = options.expectUserMessage
267
- ? await runtime.monitor.view(panel)
268
- : undefined;
269
- const attempt = runtime.monitor.beginWork(
270
- panel.pane_id,
271
- task,
272
- options.expectUserMessage ? (baseline?.user?.id ?? null) : undefined,
273
- );
274
- if (!attempt) throw new Error(`${panel.pane_id} is not monitored`);
294
+ const addedWatch = !runtime.monitor
295
+ .list()
296
+ .some(
297
+ (record) =>
298
+ record.terminalId === panel.terminal_id ||
299
+ record.paneId === panel.pane_id,
300
+ );
301
+ let attempt: WorkAttempt | undefined;
275
302
  let settlement: Promise<ClaimedSettlement> | undefined;
303
+ let receipt: PeerDelivery | void;
276
304
  let sendStarted = false;
277
305
  try {
306
+ await runtime.monitor.track(panel);
307
+ const baseline = options.expectUserMessage
308
+ ? await runtime.monitor.view(panel)
309
+ : undefined;
310
+ attempt = runtime.monitor.beginWork(
311
+ panel.pane_id,
312
+ task,
313
+ options.expectUserMessage ? (baseline?.input?.id ?? null) : undefined,
314
+ );
315
+ if (!attempt) throw new Error(`${panel.pane_id} is not monitored`);
278
316
  settlement = blocking
279
317
  ? runtime.monitor.claimWork(attempt, signal)
280
318
  : undefined;
281
319
  void settlement?.catch(() => undefined);
282
320
  signal.throwIfAborted();
283
321
  sendStarted = true;
284
- await send();
285
- runtime.monitor.acceptWork(attempt);
322
+ receipt = await send();
286
323
  } catch (error) {
287
324
  runtime.monitor.releaseWorkClaim(attempt, error);
288
325
  if (sendStarted) await runtime.monitor.handleWorkFailure(attempt, error);
289
326
  else runtime.monitor.rejectWork(attempt);
327
+ if (addedWatch && (!sendStarted || isDispatchRejected(error))) {
328
+ const record = runtime.monitor
329
+ .list()
330
+ .find((record) => record.terminalId === panel.terminal_id);
331
+ try {
332
+ if (record?.scope === "task" && !activityTask(record.activity)) {
333
+ await runtime.monitor.unwatch(record.paneId);
334
+ }
335
+ } catch (cleanupError) {
336
+ throw new AggregateError(
337
+ [error, cleanupError],
338
+ "Delegation failed; temporary watch cleanup also failed",
339
+ );
340
+ }
341
+ }
290
342
  throw error;
291
343
  }
292
- if (!blocking) return undefined;
344
+ try {
345
+ if (receipt?.command) {
346
+ runtime.monitor.releaseWorkClaim(
347
+ attempt,
348
+ new Error("Command submitted without task waiting"),
349
+ );
350
+ runtime.monitor.rejectWork(attempt);
351
+ if (addedWatch) {
352
+ const record = runtime.monitor
353
+ .list()
354
+ .find((record) => record.terminalId === panel.terminal_id);
355
+ if (record?.scope === "task" && !activityTask(record.activity))
356
+ await runtime.monitor.unwatch(record.paneId);
357
+ }
358
+ } else runtime.monitor.acceptWork(attempt);
359
+ await runtime.monitor.reconcileNow();
360
+ } catch (error) {
361
+ runtime.monitor.releaseWorkClaim(attempt, error);
362
+ return {
363
+ ...(receipt?.command ? { command: true } : {}),
364
+ warning: `Submitted, but monitoring refresh failed: ${error instanceof Error ? error.message : String(error)}. Inspect the target before resubmitting`,
365
+ };
366
+ }
367
+ if (receipt?.command) return { command: true };
368
+ if (!blocking) return {};
293
369
  reportProgress(onUpdate, `Waiting for ${panel.name ?? panel.pane_id}`, {
294
370
  machine: runtime.machine,
295
371
  target: panel.pane_id,
296
372
  status: "working",
297
373
  });
298
- return await settlement!;
374
+ return { settlement: await settlement! };
299
375
  }
300
376
 
301
377
  export async function readAgentTerminal(
@@ -21,12 +21,13 @@ import {
21
21
  import { type AskAnswer, prepareAskAnswer } from "./ask-answer.js";
22
22
  import type { AgentFleet } from "./fleet.js";
23
23
  import { resolvePiAgent } from "./herdr.js";
24
- import { isHerdrResponseError } from "./herdr-client.js";
24
+ import { isDispatchRejected } from "./herdr-client.js";
25
25
  import {
26
26
  resolvePreparationDirectory,
27
27
  rollbackStartedAgent,
28
28
  startAgent,
29
29
  } from "./launch.js";
30
+ import { attributeAgentPrompt } from "./messages.js";
30
31
  import {
31
32
  loadAgentProfiles,
32
33
  prepareProfileMessage,
@@ -55,7 +56,7 @@ export function createAgentsTool(fleet: AgentFleet) {
55
56
  parameters: AgentsParameters,
56
57
  promptSnippet: "Load agents help before first use.",
57
58
  promptGuidelines: [
58
- "agents: Reviewer spawns always block. Await the review before continuing work on its scope. Set blocking false only for independent work.",
59
+ "agents: send messages to peers; assign delegates work. Reviewer spawns always block; await review before working its scope.",
59
60
  "agents: Specialists know their job. Give only the concrete task and inaccessible context; never append generic method, evidence, or reporting instructions.",
60
61
  "agents: Reuse specialists only for the same investigation. Keep reviews independent. New scope gets a new agent.",
61
62
  "agents: For advanced Herdr workspace, pane, process or layout control, run herdr --skill.",
@@ -118,15 +119,23 @@ export function createAgentsTool(fleet: AgentFleet) {
118
119
  runtime.fallbackCwd,
119
120
  runtime.resolveDirectory,
120
121
  );
122
+ const input = required(params.message, "message");
121
123
  const message = await prepareProfileMessage(
122
124
  profile,
123
125
  {
124
126
  cwd,
125
- message: required(params.message, "message"),
127
+ message: input,
126
128
  ...(params.base ? { base: params.base } : {}),
127
129
  },
128
130
  { targetLocal: runtime.local },
129
131
  );
132
+ const attributedMessage = await attributeAgentPrompt(
133
+ fleet.connected().client,
134
+ input.startsWith("/") ? input : message,
135
+ "task",
136
+ );
137
+ if (input.startsWith("/") && message !== input)
138
+ attributedMessage.context = message;
130
139
  reportProgress(update, `Spawning ${label}`, {
131
140
  machine: runtime.machine,
132
141
  name,
@@ -135,7 +144,6 @@ export function createAgentsTool(fleet: AgentFleet) {
135
144
  });
136
145
  const started = await startAgent(
137
146
  runtime.client,
138
- runtime.monitor,
139
147
  startParams,
140
148
  runtime.fallbackCwd,
141
149
  runtime.resolveDirectory,
@@ -147,10 +155,10 @@ export function createAgentsTool(fleet: AgentFleet) {
147
155
  );
148
156
  let promptSubmissionStarted = false;
149
157
  let promptAccepted = false;
150
- let settlement;
158
+ let dispatch;
151
159
  const blocking = shouldBlockAgentSpawn(profile.name, params.blocking);
152
160
  try {
153
- settlement = await dispatchAgentWork(
161
+ dispatch = await dispatchAgentWork(
154
162
  runtime,
155
163
  started.agent,
156
164
  message,
@@ -159,42 +167,47 @@ export function createAgentsTool(fleet: AgentFleet) {
159
167
  update,
160
168
  async () => {
161
169
  promptSubmissionStarted = true;
162
- await runtime.client.request("agent.prompt", {
163
- target: started.id,
164
- text: message,
165
- });
170
+ const receipt = await runtime.client.sendMessage(
171
+ started.agent,
172
+ attributedMessage,
173
+ );
166
174
  promptAccepted = true;
175
+ return receipt;
167
176
  },
168
177
  { expectUserMessage: true },
169
178
  );
170
179
  } catch (error) {
171
180
  if (
172
181
  !promptAccepted &&
173
- (!promptSubmissionStarted || isHerdrResponseError(error))
182
+ (!promptSubmissionStarted || isDispatchRejected(error))
174
183
  ) {
175
- return rollbackStartedAgent(
176
- runtime.client,
177
- runtime.monitor,
178
- started,
179
- error,
180
- );
184
+ return rollbackStartedAgent(runtime.client, started, error);
181
185
  }
182
186
  throw error;
183
187
  }
184
188
  return toolResult(
185
- settlement
189
+ dispatch.command
186
190
  ? {
187
191
  spawned: true,
188
- ...settlementResult(runtime.machine, settlement),
189
- }
190
- : {
191
- spawned: true,
192
+ commandSubmitted: true,
192
193
  machine: runtime.machine,
193
194
  target: started.id,
194
195
  name,
195
- status: "working",
196
- next: "Completion or blockage will be delivered automatically; do not poll",
197
- },
196
+ }
197
+ : dispatch.settlement
198
+ ? {
199
+ spawned: true,
200
+ ...settlementResult(runtime.machine, dispatch.settlement),
201
+ }
202
+ : {
203
+ spawned: true,
204
+ machine: runtime.machine,
205
+ target: started.id,
206
+ name,
207
+ status: "working",
208
+ next: "Completion or blockage will be delivered automatically; do not poll",
209
+ },
210
+ dispatch.warning,
198
211
  );
199
212
  }
200
213
 
@@ -257,7 +270,7 @@ export function createAgentsTool(fleet: AgentFleet) {
257
270
  : {}),
258
271
  });
259
272
  }
260
- if (params.action === "send") {
273
+ if (params.action === "send" || params.action === "assign") {
261
274
  if (panel.agent_status === "blocked") {
262
275
  const view = await runtime.monitor.view(panel);
263
276
  throw new Error(
@@ -265,39 +278,57 @@ export function createAgentsTool(fleet: AgentFleet) {
265
278
  );
266
279
  }
267
280
  const message = required(params.message, "message");
268
- if (!runtime.monitor.isMonitored(panel.pane_id)) {
269
- await runtime.monitor.track(panel);
281
+ const attributedMessage = await attributeAgentPrompt(
282
+ fleet.connected().client,
283
+ message,
284
+ params.action === "send" ? "message" : "task",
285
+ );
286
+ if (params.action === "send") {
287
+ executionSignal.throwIfAborted();
288
+ const receipt = await runtime.client.sendMessage(
289
+ panel,
290
+ attributedMessage,
291
+ );
292
+ return toolResult({
293
+ sent: true,
294
+ ...(receipt.command ? { commandSubmitted: true } : {}),
295
+ machine: runtime.machine,
296
+ target: panel.pane_id,
297
+ });
270
298
  }
271
- const settlement = await dispatchAgentWork(
299
+ const dispatch = await dispatchAgentWork(
272
300
  runtime,
273
301
  panel,
274
302
  message,
275
303
  params.blocking !== false,
276
304
  executionSignal,
277
305
  update,
278
- () =>
279
- runtime.client.request("agent.prompt", {
280
- target: panel.pane_id,
281
- text: message,
282
- }),
306
+ () => runtime.client.sendMessage(panel, attributedMessage),
283
307
  { expectUserMessage: true },
284
308
  );
285
309
  return toolResult(
286
- settlement
287
- ? { sent: true, ...settlementResult(runtime.machine, settlement) }
288
- : {
289
- sent: true,
310
+ dispatch.command
311
+ ? {
312
+ commandSubmitted: true,
290
313
  machine: runtime.machine,
291
314
  target: panel.pane_id,
292
- status: "working",
293
- next: "Completion or blockage will be delivered automatically; do not poll",
294
- },
315
+ }
316
+ : dispatch.settlement
317
+ ? {
318
+ assigned: true,
319
+ ...settlementResult(runtime.machine, dispatch.settlement),
320
+ }
321
+ : {
322
+ assigned: true,
323
+ machine: runtime.machine,
324
+ target: panel.pane_id,
325
+ status: "working",
326
+ next: "Completion or blockage will be delivered automatically; do not poll",
327
+ },
328
+ dispatch.warning,
295
329
  );
296
330
  }
297
331
  if (params.action === "answer") {
298
- if (!runtime.monitor.isMonitored(panel.pane_id)) {
299
- await runtime.monitor.track(panel);
300
- }
301
332
  const prepared = await prepareAskAnswer(
302
333
  runtime.client,
303
334
  runtime.monitor,
@@ -308,7 +339,7 @@ export function createAgentsTool(fleet: AgentFleet) {
308
339
  const task = `Answer: ${prepared.ask.prompts
309
340
  .map((prompt) => prompt.title)
310
341
  .join(", ")}`;
311
- const settlement = await dispatchAgentWork(
342
+ const { settlement, warning } = await dispatchAgentWork(
312
343
  runtime,
313
344
  panel,
314
345
  task,
@@ -330,6 +361,7 @@ export function createAgentsTool(fleet: AgentFleet) {
330
361
  status: "working",
331
362
  next: "Completion or blockage will be delivered automatically; do not poll",
332
363
  },
364
+ warning,
333
365
  );
334
366
  }
335
367
  throw new Error(`unsupported action ${params.action}`);