@howaboua/pi-shepherdr 0.1.5 → 0.2.0
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 +20 -0
- package/README.md +24 -5
- package/package.json +3 -3
- package/profiles/general/prompt.md +1 -1
- package/src/agents-contract.ts +19 -3
- package/src/agents-operations.ts +54 -15
- package/src/agents-tool.ts +35 -19
- package/src/controller.ts +4 -8
- package/src/delivery.ts +24 -0
- package/src/fleet.ts +154 -79
- package/src/herdr-client.ts +24 -7
- package/src/herdr.ts +17 -1
- package/src/launch.ts +0 -25
- package/src/machine-catalog.ts +60 -0
- package/src/messages.ts +66 -11
- package/src/monitor-events.ts +173 -83
- package/src/monitor-record.ts +6 -19
- package/src/monitor-state.ts +50 -6
- package/src/monitor.ts +27 -15
- package/src/remote/shepherdr.mjs +70 -30
- package/src/remote-client.ts +32 -25
- package/src/session-reader.ts +44 -13
- package/src/settlement.ts +214 -73
- package/src/types.ts +15 -4
- package/src/widget.ts +26 -5
- package/src/machine-menu.ts +0 -161
- package/src/machines-config.ts +0 -148
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @howaboua/pi-shepherdr
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
|
|
7
|
+
- Agent prompts and reports identify their source workspace, tab and pane, including current names.
|
|
8
|
+
- Attributed messages to running Pi Codex agents use developer steering. Idle tasks retain normal user kickoff and extension preparation.
|
|
9
|
+
- `send` delivers peer messages without blocking or subscribing; use `assign` to delegate work to an existing agent.
|
|
10
|
+
- Automatic task watches end on completion or failure. Only explicit `watch` subscriptions persist; legacy watches are cleared with a notice.
|
|
11
|
+
|
|
12
|
+
## 0.1.6
|
|
13
|
+
|
|
14
|
+
- Deliver blocked-agent handoffs even when transcripts are unavailable.
|
|
15
|
+
|
|
16
|
+
- Reviewer spawns wait for their result before the controller continues.
|
|
17
|
+
- Implementation subagents are instructed to work directly rather than delegate implementation again.
|
|
18
|
+
- Discover and answer Pi Ask questions called inside Code and Notebook Mode.
|
|
19
|
+
- Retain working local and remote monitoring during connection updates, distinguish incomplete coverage from disconnection, and report recovery.
|
|
20
|
+
- Worker states now show their last-known status during incomplete monitoring. `/herdr connect` retries without replacing a working remote connection.
|
|
21
|
+
- Catch worker completions during reconnect setup and cancel obsolete or stopped monitoring connections.
|
|
22
|
+
|
|
3
23
|
## 0.1.5
|
|
4
24
|
|
|
5
25
|
- Make the agents tool always available and start fleet monitoring automatically. `/herdr` now toggles only orchestration guidance, not tool availability.
|
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.
|
|
17
|
+
Requires Pi 0.84.3 or newer, Herdr 0.9 or newer and the Herdr Pi integration:
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
herdr integration install pi
|
|
@@ -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
|
-
|
|
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
|
-
|
|
39
|
+
Profiles belong to the host running Pi, not the laptop or desktop displaying its terminal. Each profile targets one remote session. Agent calls use the opaque profile ID returned by `list`; `local` means Pi's current server. 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,18 +54,31 @@ 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
|
|
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`, `
|
|
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.
|
|
69
|
+
|
|
70
|
+
Reviewer spawns always block, even when `blocking: false` is supplied. The controller waits for the review before continuing work on its scope.
|
|
58
71
|
|
|
59
72
|
Every `spawn` needs an `agent_type` and a concise two- or three-word `label`. The label names both the Herdr tab and Pi session; the routing `name` remains optional and is derived from it when omitted.
|
|
60
73
|
|
|
61
74
|
Cancelling a blocking call does not kill its worker. The waiter detaches and the eventual result returns through normal asynchronous delivery.
|
|
62
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
|
+
Idle task prompts retain Pi's normal user kickoff and extension preparation. When the receiving agent is already running and Pi Codex developer delivery is active, Shepherdr routes attributed messages into that prepared run as developer steering. Without it, messages remain normal prompts. Install Shepherdr on receiving agents as well as controllers for this delivery.
|
|
79
|
+
|
|
80
|
+
For `answer` inside Code or Notebook Mode, update Pi Ask on workers together with Shepherdr on controllers.
|
|
81
|
+
|
|
63
82
|
## Profiles
|
|
64
83
|
|
|
65
84
|
On first load, Shepherdr installs three editable profiles:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-shepherdr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Persistent blocking and asynchronous Pi agents through Herdr.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"pack:dry": "npm pack --dry-run"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@howaboua/pi-codex-conversion": ">=3.0.
|
|
46
|
+
"@howaboua/pi-codex-conversion": ">=3.0.31",
|
|
47
47
|
"@earendil-works/pi-ai": ">=0.84.3",
|
|
48
48
|
"@earendil-works/pi-coding-agent": ">=0.84.3",
|
|
49
49
|
"@earendil-works/pi-tui": ">=0.84.3",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@howaboua/pi-codex-conversion": "3.0.
|
|
58
|
+
"@howaboua/pi-codex-conversion": "3.0.31",
|
|
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",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
You are
|
|
1
|
+
You are the implementation subagent. Treat the task as the complete brief. Complete it in the given directory, validate your work, and report the result. Do not spawn implementation subagents.
|
package/src/agents-contract.ts
CHANGED
|
@@ -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", "
|
|
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"
|
|
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
|
};
|
|
@@ -79,7 +81,7 @@ const AgentsRequest = Type.Object(
|
|
|
79
81
|
blocking: Type.Optional(
|
|
80
82
|
Type.Boolean({
|
|
81
83
|
description:
|
|
82
|
-
"
|
|
84
|
+
"Delegation only; defaults true. False pushes task settlement later",
|
|
83
85
|
}),
|
|
84
86
|
),
|
|
85
87
|
query: Type.Optional(Type.String()),
|
|
@@ -118,6 +120,11 @@ export function parseAgentsRequest(input: unknown): AgentsParams {
|
|
|
118
120
|
if (typeof action !== "string" || !Object.hasOwn(ACTION_FIELDS, action)) {
|
|
119
121
|
throw new Error(`agents action must be one of: ${ACTIONS.join(", ")}`);
|
|
120
122
|
}
|
|
123
|
+
if (action === "send" && "blocking" in value) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
"send is message-only; omit blocking. Use assign to delegate work",
|
|
126
|
+
);
|
|
127
|
+
}
|
|
121
128
|
const unknown = Object.keys(value).filter(
|
|
122
129
|
(key) => !ACTION_FIELDS[action as keyof typeof ACTION_FIELDS].has(key),
|
|
123
130
|
);
|
|
@@ -135,8 +142,17 @@ export function parseAgentsRequest(input: unknown): AgentsParams {
|
|
|
135
142
|
export function isBlockingAgentsCall(input: unknown): boolean {
|
|
136
143
|
try {
|
|
137
144
|
const value = parseAgentsRequest(input);
|
|
145
|
+
if (value.action === "spawn")
|
|
146
|
+
return shouldBlockAgentSpawn(value.agent_type, value.blocking);
|
|
138
147
|
return BLOCKING_ACTIONS.has(value.action) && value.blocking !== false;
|
|
139
148
|
} catch {
|
|
140
149
|
return false;
|
|
141
150
|
}
|
|
142
151
|
}
|
|
152
|
+
|
|
153
|
+
export function shouldBlockAgentSpawn(
|
|
154
|
+
agentType: string | undefined,
|
|
155
|
+
blocking: boolean | undefined,
|
|
156
|
+
): boolean {
|
|
157
|
+
return agentType?.trim() === "reviewer" || blocking !== false;
|
|
158
|
+
}
|
package/src/agents-operations.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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 { isHerdrResponseError } 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
11
|
import type { AgentStatus, PaneInfo, SessionSnapshot } from "./types.js";
|
|
@@ -38,16 +42,22 @@ export async function agentsHelp(): Promise<Record<string, unknown>> {
|
|
|
38
42
|
"agent_type label message name? machine? placement? workspace? pane? cwd? base? blocking?",
|
|
39
43
|
watch: "target machine?",
|
|
40
44
|
unwatch: "target machine?",
|
|
41
|
-
send: "target message machine?
|
|
45
|
+
send: "target message machine?",
|
|
46
|
+
assign: "target message machine? blocking?",
|
|
42
47
|
read: "target machine? source? lines?",
|
|
43
48
|
answer: "target answers machine? blocking?",
|
|
44
49
|
},
|
|
45
50
|
rules: {
|
|
51
|
+
machine: "Herdr profile ID from list; local = current server",
|
|
46
52
|
target: "Use spawn/find target exactly",
|
|
47
53
|
label: "2-3 words; tab/session",
|
|
48
54
|
answers: "[{selections?:string[],other?:string,comment?:string}]",
|
|
55
|
+
send: "Peer questions, updates, replies; submission only, no wait or watch",
|
|
56
|
+
assign: "Delegate a task to an existing agent",
|
|
49
57
|
blocking:
|
|
50
|
-
"
|
|
58
|
+
"spawn/assign/answer default true; false pushes task settlement; reviewers always wait; never poll",
|
|
59
|
+
watch:
|
|
60
|
+
"Explicit watch persists until unwatch; automatic task watches end on finish/failure, not blockage",
|
|
51
61
|
prompt:
|
|
52
62
|
"Only task + inaccessible context; no method/evidence/reporting boilerplate",
|
|
53
63
|
reuse:
|
|
@@ -135,7 +145,7 @@ export async function listFleetAgents(
|
|
|
135
145
|
compactAgent(
|
|
136
146
|
agent,
|
|
137
147
|
machine.snapshot!,
|
|
138
|
-
machine.
|
|
148
|
+
machine.id,
|
|
139
149
|
machine.monitoredPaneIds?.has(agent.pane_id) ?? false,
|
|
140
150
|
),
|
|
141
151
|
)
|
|
@@ -143,7 +153,7 @@ export async function listFleetAgents(
|
|
|
143
153
|
});
|
|
144
154
|
const workspaces = machines.flatMap((machine) =>
|
|
145
155
|
(machine.snapshot?.workspaces ?? []).map((workspace) => ({
|
|
146
|
-
machine: machine.
|
|
156
|
+
machine: machine.id,
|
|
147
157
|
id: workspace.workspace_id,
|
|
148
158
|
label: workspace.label,
|
|
149
159
|
})),
|
|
@@ -224,10 +234,15 @@ export function settlementResult(
|
|
|
224
234
|
`${settlement.agent.pane_id} assistant stopped with an error`,
|
|
225
235
|
);
|
|
226
236
|
}
|
|
237
|
+
const { pane, name, ...source } = agentSource(
|
|
238
|
+
settlement.agent,
|
|
239
|
+
settlement.labels,
|
|
240
|
+
);
|
|
227
241
|
return {
|
|
228
242
|
machine,
|
|
229
|
-
target:
|
|
230
|
-
...(
|
|
243
|
+
target: pane,
|
|
244
|
+
...(name ? { name } : {}),
|
|
245
|
+
source,
|
|
231
246
|
status: settlement.status,
|
|
232
247
|
...(settlement.reply ? { reply: settlement.reply.text } : {}),
|
|
233
248
|
...(settlement.ask
|
|
@@ -263,18 +278,27 @@ export async function dispatchAgentWork(
|
|
|
263
278
|
options: { expectUserMessage?: boolean } = {},
|
|
264
279
|
): Promise<ClaimedSettlement | undefined> {
|
|
265
280
|
signal.throwIfAborted();
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (!attempt) throw new Error(`${panel.pane_id} is not monitored`);
|
|
281
|
+
const addedWatch = !runtime.monitor
|
|
282
|
+
.list()
|
|
283
|
+
.some(
|
|
284
|
+
(record) =>
|
|
285
|
+
record.terminalId === panel.terminal_id ||
|
|
286
|
+
record.paneId === panel.pane_id,
|
|
287
|
+
);
|
|
288
|
+
let attempt: WorkAttempt | undefined;
|
|
275
289
|
let settlement: Promise<ClaimedSettlement> | undefined;
|
|
276
290
|
let sendStarted = false;
|
|
277
291
|
try {
|
|
292
|
+
await runtime.monitor.track(panel);
|
|
293
|
+
const baseline = options.expectUserMessage
|
|
294
|
+
? await runtime.monitor.view(panel)
|
|
295
|
+
: undefined;
|
|
296
|
+
attempt = runtime.monitor.beginWork(
|
|
297
|
+
panel.pane_id,
|
|
298
|
+
task,
|
|
299
|
+
options.expectUserMessage ? (baseline?.input?.id ?? null) : undefined,
|
|
300
|
+
);
|
|
301
|
+
if (!attempt) throw new Error(`${panel.pane_id} is not monitored`);
|
|
278
302
|
settlement = blocking
|
|
279
303
|
? runtime.monitor.claimWork(attempt, signal)
|
|
280
304
|
: undefined;
|
|
@@ -287,6 +311,21 @@ export async function dispatchAgentWork(
|
|
|
287
311
|
runtime.monitor.releaseWorkClaim(attempt, error);
|
|
288
312
|
if (sendStarted) await runtime.monitor.handleWorkFailure(attempt, error);
|
|
289
313
|
else runtime.monitor.rejectWork(attempt);
|
|
314
|
+
if (addedWatch && (!sendStarted || isHerdrResponseError(error))) {
|
|
315
|
+
const record = runtime.monitor
|
|
316
|
+
.list()
|
|
317
|
+
.find((record) => record.terminalId === panel.terminal_id);
|
|
318
|
+
try {
|
|
319
|
+
if (record?.scope === "task" && !activityTask(record.activity)) {
|
|
320
|
+
await runtime.monitor.unwatch(record.paneId);
|
|
321
|
+
}
|
|
322
|
+
} catch (cleanupError) {
|
|
323
|
+
throw new AggregateError(
|
|
324
|
+
[error, cleanupError],
|
|
325
|
+
"Delegation failed; temporary watch cleanup also failed",
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
290
329
|
throw error;
|
|
291
330
|
}
|
|
292
331
|
if (!blocking) return undefined;
|
package/src/agents-tool.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type AgentsParams,
|
|
6
6
|
type AgentsToolParams,
|
|
7
7
|
parseAgentsRequest,
|
|
8
|
+
shouldBlockAgentSpawn,
|
|
8
9
|
} from "./agents-contract.js";
|
|
9
10
|
import {
|
|
10
11
|
agentsHelp,
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
rollbackStartedAgent,
|
|
27
28
|
startAgent,
|
|
28
29
|
} from "./launch.js";
|
|
30
|
+
import { attributeAgentPrompt } from "./messages.js";
|
|
29
31
|
import {
|
|
30
32
|
loadAgentProfiles,
|
|
31
33
|
prepareProfileMessage,
|
|
@@ -54,7 +56,7 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
54
56
|
parameters: AgentsParameters,
|
|
55
57
|
promptSnippet: "Load agents help before first use.",
|
|
56
58
|
promptGuidelines: [
|
|
57
|
-
"agents:
|
|
59
|
+
"agents: send messages to peers; assign delegates work. Reviewer spawns always block; await review before working its scope.",
|
|
58
60
|
"agents: Specialists know their job. Give only the concrete task and inaccessible context; never append generic method, evidence, or reporting instructions.",
|
|
59
61
|
"agents: Reuse specialists only for the same investigation. Keep reviews independent. New scope gets a new agent.",
|
|
60
62
|
"agents: For advanced Herdr workspace, pane, process or layout control, run herdr --skill.",
|
|
@@ -126,6 +128,11 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
126
128
|
},
|
|
127
129
|
{ targetLocal: runtime.local },
|
|
128
130
|
);
|
|
131
|
+
const attributedMessage = await attributeAgentPrompt(
|
|
132
|
+
fleet.connected().client,
|
|
133
|
+
message,
|
|
134
|
+
"task",
|
|
135
|
+
);
|
|
129
136
|
reportProgress(update, `Spawning ${label}`, {
|
|
130
137
|
machine: runtime.machine,
|
|
131
138
|
name,
|
|
@@ -134,7 +141,6 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
134
141
|
});
|
|
135
142
|
const started = await startAgent(
|
|
136
143
|
runtime.client,
|
|
137
|
-
runtime.monitor,
|
|
138
144
|
startParams,
|
|
139
145
|
runtime.fallbackCwd,
|
|
140
146
|
runtime.resolveDirectory,
|
|
@@ -147,19 +153,20 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
147
153
|
let promptSubmissionStarted = false;
|
|
148
154
|
let promptAccepted = false;
|
|
149
155
|
let settlement;
|
|
156
|
+
const blocking = shouldBlockAgentSpawn(profile.name, params.blocking);
|
|
150
157
|
try {
|
|
151
158
|
settlement = await dispatchAgentWork(
|
|
152
159
|
runtime,
|
|
153
160
|
started.agent,
|
|
154
161
|
message,
|
|
155
|
-
|
|
162
|
+
blocking,
|
|
156
163
|
executionSignal,
|
|
157
164
|
update,
|
|
158
165
|
async () => {
|
|
159
166
|
promptSubmissionStarted = true;
|
|
160
167
|
await runtime.client.request("agent.prompt", {
|
|
161
168
|
target: started.id,
|
|
162
|
-
text:
|
|
169
|
+
text: attributedMessage,
|
|
163
170
|
});
|
|
164
171
|
promptAccepted = true;
|
|
165
172
|
},
|
|
@@ -170,12 +177,7 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
170
177
|
!promptAccepted &&
|
|
171
178
|
(!promptSubmissionStarted || isHerdrResponseError(error))
|
|
172
179
|
) {
|
|
173
|
-
return rollbackStartedAgent(
|
|
174
|
-
runtime.client,
|
|
175
|
-
runtime.monitor,
|
|
176
|
-
started,
|
|
177
|
-
error,
|
|
178
|
-
);
|
|
180
|
+
return rollbackStartedAgent(runtime.client, started, error);
|
|
179
181
|
}
|
|
180
182
|
throw error;
|
|
181
183
|
}
|
|
@@ -255,7 +257,7 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
255
257
|
: {}),
|
|
256
258
|
});
|
|
257
259
|
}
|
|
258
|
-
if (params.action === "send") {
|
|
260
|
+
if (params.action === "send" || params.action === "assign") {
|
|
259
261
|
if (panel.agent_status === "blocked") {
|
|
260
262
|
const view = await runtime.monitor.view(panel);
|
|
261
263
|
throw new Error(
|
|
@@ -263,8 +265,22 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
263
265
|
);
|
|
264
266
|
}
|
|
265
267
|
const message = required(params.message, "message");
|
|
266
|
-
|
|
267
|
-
|
|
268
|
+
const attributedMessage = await attributeAgentPrompt(
|
|
269
|
+
fleet.connected().client,
|
|
270
|
+
message,
|
|
271
|
+
params.action === "send" ? "message" : "task",
|
|
272
|
+
);
|
|
273
|
+
if (params.action === "send") {
|
|
274
|
+
executionSignal.throwIfAborted();
|
|
275
|
+
await runtime.client.request("agent.prompt", {
|
|
276
|
+
target: panel.pane_id,
|
|
277
|
+
text: attributedMessage,
|
|
278
|
+
});
|
|
279
|
+
return toolResult({
|
|
280
|
+
sent: true,
|
|
281
|
+
machine: runtime.machine,
|
|
282
|
+
target: panel.pane_id,
|
|
283
|
+
});
|
|
268
284
|
}
|
|
269
285
|
const settlement = await dispatchAgentWork(
|
|
270
286
|
runtime,
|
|
@@ -276,15 +292,18 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
276
292
|
() =>
|
|
277
293
|
runtime.client.request("agent.prompt", {
|
|
278
294
|
target: panel.pane_id,
|
|
279
|
-
text:
|
|
295
|
+
text: attributedMessage,
|
|
280
296
|
}),
|
|
281
297
|
{ expectUserMessage: true },
|
|
282
298
|
);
|
|
283
299
|
return toolResult(
|
|
284
300
|
settlement
|
|
285
|
-
? {
|
|
301
|
+
? {
|
|
302
|
+
assigned: true,
|
|
303
|
+
...settlementResult(runtime.machine, settlement),
|
|
304
|
+
}
|
|
286
305
|
: {
|
|
287
|
-
|
|
306
|
+
assigned: true,
|
|
288
307
|
machine: runtime.machine,
|
|
289
308
|
target: panel.pane_id,
|
|
290
309
|
status: "working",
|
|
@@ -293,9 +312,6 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
293
312
|
);
|
|
294
313
|
}
|
|
295
314
|
if (params.action === "answer") {
|
|
296
|
-
if (!runtime.monitor.isMonitored(panel.pane_id)) {
|
|
297
|
-
await runtime.monitor.track(panel);
|
|
298
|
-
}
|
|
299
315
|
const prepared = await prepareAskAnswer(
|
|
300
316
|
runtime.client,
|
|
301
317
|
runtime.monitor,
|
package/src/controller.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
} from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { sendPolicyMessage } from "./delivery.js";
|
|
6
6
|
import type { AgentFleet } from "./fleet.js";
|
|
7
|
-
import { showMachineMenu } from "./machine-menu.js";
|
|
8
7
|
import { loadAgentProfiles } from "./profiles.js";
|
|
9
8
|
|
|
10
9
|
const ORCHESTRATION_STATE_TYPE = "pi-shepherdr-orchestration-state";
|
|
@@ -20,9 +19,9 @@ export function registerAgentController(
|
|
|
20
19
|
): void {
|
|
21
20
|
let orchestrationEnabled = false;
|
|
22
21
|
pi.registerCommand("herdr", {
|
|
23
|
-
description: "Toggle agent orchestration or
|
|
22
|
+
description: "Toggle agent orchestration or reconnect machines",
|
|
24
23
|
getArgumentCompletions: (prefix) =>
|
|
25
|
-
["
|
|
24
|
+
["connect"]
|
|
26
25
|
.filter((action) => action.startsWith(prefix.trim().toLowerCase()))
|
|
27
26
|
.map((value) => ({ label: value, value })),
|
|
28
27
|
handler: async (args, ctx) => {
|
|
@@ -51,16 +50,13 @@ export function registerAgentController(
|
|
|
51
50
|
);
|
|
52
51
|
return;
|
|
53
52
|
}
|
|
54
|
-
if (action === "machines") {
|
|
55
|
-
await showMachineMenu(fleet, ctx);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
53
|
if (action === "connect") {
|
|
59
54
|
if (!fleet.isActive()) {
|
|
60
55
|
await activateController(fleet, ctx);
|
|
61
56
|
if (!fleet.isActive()) return;
|
|
62
57
|
}
|
|
63
58
|
try {
|
|
59
|
+
await fleet.reload();
|
|
64
60
|
ctx.ui.notify(fleet.connect(rest[0]), "info");
|
|
65
61
|
} catch (error) {
|
|
66
62
|
ctx.ui.notify(
|
|
@@ -70,7 +66,7 @@ export function registerAgentController(
|
|
|
70
66
|
}
|
|
71
67
|
return;
|
|
72
68
|
}
|
|
73
|
-
ctx.ui.notify("Usage: /herdr [
|
|
69
|
+
ctx.ui.notify("Usage: /herdr [connect [machine]]", "warning");
|
|
74
70
|
},
|
|
75
71
|
});
|
|
76
72
|
|
package/src/delivery.ts
CHANGED
|
@@ -24,6 +24,30 @@ export async function registerDeveloperDelivery(
|
|
|
24
24
|
} catch (error) {
|
|
25
25
|
if (!isUnavailable(error)) throw error;
|
|
26
26
|
}
|
|
27
|
+
pi.on("input", (event, ctx) => {
|
|
28
|
+
// Idle prompts must run Pi's complete before_agent_start preparation chain.
|
|
29
|
+
if (
|
|
30
|
+
ctx.isIdle() ||
|
|
31
|
+
event.streamingBehavior === undefined ||
|
|
32
|
+
event.images?.length ||
|
|
33
|
+
!/^<herdr_sender [^\n]+ \/>\n/.test(event.text)
|
|
34
|
+
)
|
|
35
|
+
return;
|
|
36
|
+
if (
|
|
37
|
+
senders.get(pi)?.(
|
|
38
|
+
pi,
|
|
39
|
+
{
|
|
40
|
+
customType: "herdr-agent-message",
|
|
41
|
+
content: event.text,
|
|
42
|
+
display: true,
|
|
43
|
+
},
|
|
44
|
+
{ deliverAs: event.streamingBehavior },
|
|
45
|
+
)
|
|
46
|
+
) {
|
|
47
|
+
return { action: "handled" };
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
});
|
|
27
51
|
}
|
|
28
52
|
|
|
29
53
|
export function sendPolicyMessage(
|