@howaboua/pi-shepherdr 0.2.6 → 0.2.7
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 +12 -0
- package/README.md +11 -1
- package/index.ts +3 -1
- package/package.json +6 -6
- package/src/agents-spawn.ts +35 -24
- package/src/agents-tool.ts +15 -9
- package/src/delivery.ts +14 -3
- package/src/fleet.ts +66 -10
- package/src/herdr-client.ts +17 -0
- package/src/launch.ts +19 -8
- package/src/messages.ts +30 -4
- package/src/peer-inbox.ts +10 -0
- package/src/remote/shepherdr-context.mjs +260 -0
- package/src/remote/shepherdr-peer.mjs +1 -1
- package/src/remote/shepherdr.mjs +94 -4
- package/src/remote-client.ts +123 -21
- package/src/shared-context.ts +283 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @howaboua/pi-shepherdr
|
|
2
2
|
|
|
3
|
+
## 0.2.7
|
|
4
|
+
|
|
5
|
+
- Added opt-in shared notes and history for spawned agents with Pi Codex Conversion.
|
|
6
|
+
|
|
7
|
+
- New and nested workers receive distinct, persistent context identities before their first task.
|
|
8
|
+
- Local and Tree context stays in its owning sessions and routes through live controllers and existing SSH connections. Remote storage sharing requires the same Codex account.
|
|
9
|
+
- Sharing follows **Share subagent context** under `/codex context` and affects new spawns only. Existing agents and ordinary delegation remain unchanged.
|
|
10
|
+
- Wakeups of existing agents now say “Continue, unless awaiting for user approval.” Fresh-agent startup is unchanged.
|
|
11
|
+
- Fixed spawned agents dispatching before their persistent Pi session is registered. Profiles using `--no-session` now fail before creating a tab or workspace.
|
|
12
|
+
- Delegated tasks now guide workers to finish or report blockage with an assistant reply, reserving peer messages for useful mid-run updates rather than waiting or taking over orchestration.
|
|
13
|
+
- Peer messages now reach the receiving agent's active voice as brief updates, alongside completion reports. Task dispatches and slash commands are not announced.
|
|
14
|
+
|
|
3
15
|
## 0.2.6
|
|
4
16
|
|
|
5
17
|
- Fixed exact Ask answer confirmation and retry reconciliation without resending input.
|
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ Shepherdr reads Herdr's existing machine profiles and connects enabled profiles
|
|
|
38
38
|
|
|
39
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
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
|
|
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 managed transport helpers under `~/.pi/agent` on each remote, runs them 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
42
|
|
|
43
43
|
### Migrating from separate Shepherdr machines
|
|
44
44
|
|
|
@@ -85,6 +85,16 @@ Idle messages start a prepared user turn. Messages arriving during a run use ste
|
|
|
85
85
|
|
|
86
86
|
For `answer` inside Code or Notebook Mode, update Pi Ask on workers together with Shepherdr on controllers.
|
|
87
87
|
|
|
88
|
+
## Shared notes and history
|
|
89
|
+
|
|
90
|
+
With Pi Codex Conversion 3.0.40 or newer and notes-based continuity, enable **Share subagent context** under `/codex context` in the controller. It is off by default. Shared `spawn` gives each child a unique context identity before its first turn; `contextAgent` in the result identifies its notes and history. Shared nested spawns stay in the same family. Turning sharing off affects new spawns only; existing identity survives resume. `assign` and independently started agents remain unchanged. Older compatible Conversion versions keep ordinary delegation without sharing.
|
|
91
|
+
|
|
92
|
+
Pi creates each worker session normally. The worker records its shared identity before Shepherdr delivers the first task; no pre-created session file or launch override is needed.
|
|
93
|
+
|
|
94
|
+
Remote sharing requires Remote storage and the same Codex account on both ends. Local and Tree route through the owning Pi sessions and existing SSH connections. Those owners and intermediate controllers must be running; unavailable routes fail explicitly. Resume the owner and use `/herdr connect` after a connection loss. No note store is copied or silently substituted.
|
|
95
|
+
|
|
96
|
+
Both extensions work independently. A target without active context support still starts, with a warning that its context is not shared. A conflicting storage mode or account rejects the shared spawn before task delivery. Profiles that select or resume an existing session cannot participate in shared `spawn`; use `assign` instead.
|
|
97
|
+
|
|
88
98
|
## Profiles
|
|
89
99
|
|
|
90
100
|
On first load, Shepherdr installs three editable profiles:
|
package/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { AgentFleet } from "./src/fleet.js";
|
|
|
8
8
|
import { registerAgentEventRenderer } from "./src/messages.js";
|
|
9
9
|
import { registerPeerInbox } from "./src/peer-inbox.js";
|
|
10
10
|
import { installAgentProfiles } from "./src/profiles.js";
|
|
11
|
+
import { registerSharedAgentContext } from "./src/shared-context.js";
|
|
11
12
|
|
|
12
13
|
const CODE_MODE_PACKAGE = "@howaboua/pi-codex-conversion";
|
|
13
14
|
const CODE_MODE_MODULE = `${CODE_MODE_PACKAGE}/code-mode`;
|
|
@@ -20,7 +21,8 @@ export default async function shepherdrExtension(
|
|
|
20
21
|
await registerDeveloperDelivery(pi);
|
|
21
22
|
registerPeerInbox(pi);
|
|
22
23
|
const fleet = new AgentFleet(pi);
|
|
23
|
-
const
|
|
24
|
+
const sharedContext = await registerSharedAgentContext(pi, fleet);
|
|
25
|
+
const tool = createAgentsTool(fleet, sharedContext);
|
|
24
26
|
|
|
25
27
|
registerAgentEventRenderer(pi);
|
|
26
28
|
pi.registerTool(tool);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-shepherdr",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
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.40",
|
|
47
47
|
"@earendil-works/pi-ai": ">=0.84.3",
|
|
48
48
|
"@earendil-works/pi-coding-agent": ">=0.84.4",
|
|
49
49
|
"@earendil-works/pi-tui": ">=0.84.3",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@howaboua/pi-codex-conversion": "3.0.
|
|
58
|
+
"@howaboua/pi-codex-conversion": "3.0.40",
|
|
59
59
|
"@biomejs/biome": "^2.5.10",
|
|
60
|
-
"@earendil-works/pi-ai": "0.
|
|
61
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
62
|
-
"@earendil-works/pi-tui": "0.
|
|
60
|
+
"@earendil-works/pi-ai": "0.99.1",
|
|
61
|
+
"@earendil-works/pi-coding-agent": "0.99.1",
|
|
62
|
+
"@earendil-works/pi-tui": "0.99.1",
|
|
63
63
|
"@types/node": "^26.2.0",
|
|
64
64
|
"typebox": "1.3.18",
|
|
65
65
|
"typescript": "^7.0.2"
|
package/src/agents-spawn.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AgentToolUpdateCallback,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
2
5
|
import {
|
|
3
6
|
type AgentsParams,
|
|
4
7
|
requiredAgentField as required,
|
|
@@ -24,6 +27,7 @@ import {
|
|
|
24
27
|
prepareProfileMessage,
|
|
25
28
|
profileAgentArgs,
|
|
26
29
|
} from "./profiles.js";
|
|
30
|
+
import type { SharedAgentContext } from "./shared-context.js";
|
|
27
31
|
|
|
28
32
|
function agentLabel(value: string | undefined): string {
|
|
29
33
|
const label = required(value, "label");
|
|
@@ -40,6 +44,8 @@ export async function spawnAgent(
|
|
|
40
44
|
params: AgentsParams,
|
|
41
45
|
signal: AbortSignal,
|
|
42
46
|
onUpdate: AgentToolUpdateCallback<Record<string, unknown>>,
|
|
47
|
+
sharedContext: SharedAgentContext,
|
|
48
|
+
ctx: ExtensionContext,
|
|
43
49
|
) {
|
|
44
50
|
const profiles = await loadAgentProfiles();
|
|
45
51
|
const profileName = required(params.agent_type, "agent_type");
|
|
@@ -91,29 +97,31 @@ export async function spawnAgent(
|
|
|
91
97
|
"task",
|
|
92
98
|
);
|
|
93
99
|
if (input.startsWith("/") && message !== input)
|
|
94
|
-
attributedMessage.context = message
|
|
100
|
+
attributedMessage.context = [attributedMessage.context, message]
|
|
101
|
+
.filter(Boolean)
|
|
102
|
+
.join("\n\n");
|
|
95
103
|
reportProgress(onUpdate, `Spawning ${label}`, {
|
|
96
104
|
machine: runtime.machine,
|
|
97
105
|
name,
|
|
98
106
|
profile: profile.name,
|
|
99
107
|
status: "starting",
|
|
100
108
|
});
|
|
109
|
+
const agentArgs = profileAgentArgs(profile, { targetLocal: runtime.local });
|
|
110
|
+
const sharing = await sharedContext.prepare(ctx, runtime, name, agentArgs);
|
|
101
111
|
const started = await startAgent(
|
|
102
112
|
runtime.client,
|
|
103
113
|
startParams,
|
|
104
114
|
runtime.fallbackCwd,
|
|
105
115
|
runtime.resolveDirectory,
|
|
106
|
-
{
|
|
107
|
-
agentArgs: profileAgentArgs(profile, {
|
|
108
|
-
targetLocal: runtime.local,
|
|
109
|
-
}),
|
|
110
|
-
},
|
|
116
|
+
{ agentArgs },
|
|
111
117
|
);
|
|
112
118
|
let promptSubmissionStarted = false;
|
|
113
119
|
let promptAccepted = false;
|
|
114
120
|
let dispatch;
|
|
121
|
+
let shared: { agentName?: string; warning?: string } | undefined;
|
|
115
122
|
const blocking = shouldBlockAgentSpawn(profile.name, params.blocking);
|
|
116
123
|
try {
|
|
124
|
+
shared = await sharing?.accept(started.agent);
|
|
117
125
|
dispatch = await dispatchAgentWork(
|
|
118
126
|
runtime,
|
|
119
127
|
started.agent,
|
|
@@ -142,27 +150,30 @@ export async function spawnAgent(
|
|
|
142
150
|
throw error;
|
|
143
151
|
}
|
|
144
152
|
return toolResult(
|
|
145
|
-
|
|
146
|
-
? {
|
|
147
|
-
|
|
148
|
-
commandSubmitted: true,
|
|
149
|
-
machine: runtime.machine,
|
|
150
|
-
target: started.id,
|
|
151
|
-
name,
|
|
152
|
-
}
|
|
153
|
-
: dispatch.settlement
|
|
153
|
+
{
|
|
154
|
+
...(shared?.agentName ? { contextAgent: shared.agentName } : {}),
|
|
155
|
+
...(dispatch.command
|
|
154
156
|
? {
|
|
155
157
|
spawned: true,
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
: {
|
|
159
|
-
spawned: true,
|
|
158
|
+
commandSubmitted: true,
|
|
160
159
|
machine: runtime.machine,
|
|
161
160
|
target: started.id,
|
|
162
161
|
name,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
}
|
|
163
|
+
: dispatch.settlement
|
|
164
|
+
? {
|
|
165
|
+
spawned: true,
|
|
166
|
+
...settlementResult(runtime.machine, dispatch.settlement),
|
|
167
|
+
}
|
|
168
|
+
: {
|
|
169
|
+
spawned: true,
|
|
170
|
+
machine: runtime.machine,
|
|
171
|
+
target: started.id,
|
|
172
|
+
name,
|
|
173
|
+
status: "working",
|
|
174
|
+
next: "Completion or blockage will be delivered automatically; do not poll",
|
|
175
|
+
}),
|
|
176
|
+
},
|
|
177
|
+
[dispatch.warning, shared?.warning].filter(Boolean).join("\n") || undefined,
|
|
167
178
|
);
|
|
168
179
|
}
|
package/src/agents-tool.ts
CHANGED
|
@@ -23,21 +23,19 @@ import {
|
|
|
23
23
|
import type { AgentFleet } from "./fleet.js";
|
|
24
24
|
import { resolvePiAgent } from "./herdr.js";
|
|
25
25
|
import { attributeAgentPrompt, modelAsk } from "./messages.js";
|
|
26
|
+
import type { SharedAgentContext } from "./shared-context.js";
|
|
26
27
|
|
|
27
|
-
export function createAgentsTool(
|
|
28
|
+
export function createAgentsTool(
|
|
29
|
+
fleet: AgentFleet,
|
|
30
|
+
sharedContext: SharedAgentContext,
|
|
31
|
+
) {
|
|
28
32
|
return defineTool({
|
|
29
33
|
name: "agents",
|
|
30
34
|
label: "Shepherdr",
|
|
31
35
|
description: "Delegate to persistent agents; call help first, alone",
|
|
32
36
|
parameters: AgentsParameters,
|
|
33
37
|
executionMode: "sequential",
|
|
34
|
-
async execute(
|
|
35
|
-
_toolCallId,
|
|
36
|
-
input: AgentsToolParams,
|
|
37
|
-
signal,
|
|
38
|
-
onUpdate,
|
|
39
|
-
_ctx,
|
|
40
|
-
) {
|
|
38
|
+
async execute(_toolCallId, input: AgentsToolParams, signal, onUpdate, ctx) {
|
|
41
39
|
const params = parseAgentsRequest(input);
|
|
42
40
|
const executionSignal = signal ?? new AbortController().signal;
|
|
43
41
|
const update = onUpdate ?? (() => undefined);
|
|
@@ -53,7 +51,15 @@ export function createAgentsTool(fleet: AgentFleet) {
|
|
|
53
51
|
|
|
54
52
|
const runtime = fleet.connected(params.machine);
|
|
55
53
|
if (params.action === "spawn") {
|
|
56
|
-
return spawnAgent(
|
|
54
|
+
return spawnAgent(
|
|
55
|
+
fleet,
|
|
56
|
+
runtime,
|
|
57
|
+
params,
|
|
58
|
+
executionSignal,
|
|
59
|
+
update,
|
|
60
|
+
sharedContext,
|
|
61
|
+
ctx,
|
|
62
|
+
);
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
const target = required(params.target, "target");
|
package/src/delivery.ts
CHANGED
|
@@ -91,16 +91,27 @@ export async function registerDeveloperDelivery(
|
|
|
91
91
|
|
|
92
92
|
export function startPreparedIdleTurn(
|
|
93
93
|
pi: ExtensionAPI,
|
|
94
|
-
ctx: Pick<ExtensionContext, "ui">,
|
|
94
|
+
ctx: Pick<ExtensionContext, "ui" | "sessionManager">,
|
|
95
95
|
start?: () => void,
|
|
96
96
|
): void {
|
|
97
|
+
// Session history survives tree cuts; a new active branch is not a fresh agent.
|
|
98
|
+
const prompt =
|
|
99
|
+
!start &&
|
|
100
|
+
ctx.sessionManager
|
|
101
|
+
.getEntries()
|
|
102
|
+
.some(
|
|
103
|
+
(entry) =>
|
|
104
|
+
entry.type === "message" && entry.message.role === "assistant",
|
|
105
|
+
)
|
|
106
|
+
? "Continue, unless awaiting for user approval."
|
|
107
|
+
: "Continue.";
|
|
97
108
|
if (start) {
|
|
98
109
|
if (preparedPrompts.get(pi)?.(pi, start)) return;
|
|
99
110
|
if (preparedKickoffs.has(pi) && !preparedPrompts.has(pi))
|
|
100
111
|
throw new Error(
|
|
101
112
|
"Update Pi Codex Conversion and reload before sending slash commands",
|
|
102
113
|
);
|
|
103
|
-
} else if (preparedKickoffs.get(pi)?.(pi, ctx)) return;
|
|
114
|
+
} else if (preparedKickoffs.get(pi)?.(pi, ctx, prompt)) return;
|
|
104
115
|
if (fallbackKickoffs.has(pi)) {
|
|
105
116
|
if (start)
|
|
106
117
|
throw new Error(
|
|
@@ -118,7 +129,7 @@ export function startPreparedIdleTurn(
|
|
|
118
129
|
fallbackKickoffs.set(pi, "preparing");
|
|
119
130
|
try {
|
|
120
131
|
if (start) start();
|
|
121
|
-
else pi.sendUserMessage(
|
|
132
|
+
else pi.sendUserMessage(prompt, { deliverAs: "steer" });
|
|
122
133
|
} catch (error) {
|
|
123
134
|
fallbackKickoffs.delete(pi);
|
|
124
135
|
throw error;
|
package/src/fleet.ts
CHANGED
|
@@ -27,6 +27,7 @@ interface Runtime {
|
|
|
27
27
|
attempting?: boolean;
|
|
28
28
|
client?: HerdrConnection;
|
|
29
29
|
config?: SshMachine;
|
|
30
|
+
contextRelayError?: string;
|
|
30
31
|
local: boolean;
|
|
31
32
|
monitor?: AgentMonitor;
|
|
32
33
|
monitoringIssue?: MonitoringIssue;
|
|
@@ -106,6 +107,22 @@ function groupSaved(values: unknown[]): Map<string, unknown[]> {
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
export class AgentFleet {
|
|
110
|
+
private contextRelay:
|
|
111
|
+
| ((
|
|
112
|
+
ctx: ExtensionContext,
|
|
113
|
+
request: unknown,
|
|
114
|
+
signal: AbortSignal,
|
|
115
|
+
) => Promise<unknown>)
|
|
116
|
+
| undefined;
|
|
117
|
+
setContextRelay(
|
|
118
|
+
handler: (
|
|
119
|
+
ctx: ExtensionContext,
|
|
120
|
+
request: unknown,
|
|
121
|
+
signal: AbortSignal,
|
|
122
|
+
) => Promise<unknown>,
|
|
123
|
+
): void {
|
|
124
|
+
this.contextRelay = handler;
|
|
125
|
+
}
|
|
109
126
|
private context: ExtensionContext | undefined;
|
|
110
127
|
private generation = 0;
|
|
111
128
|
private readonly pi: ExtensionAPI;
|
|
@@ -342,11 +359,14 @@ export class AgentFleet {
|
|
|
342
359
|
const runtime = this.runtimes.get(target);
|
|
343
360
|
if (!runtime)
|
|
344
361
|
throw new Error(`unknown Herdr machine ${JSON.stringify(target)}`);
|
|
345
|
-
if (
|
|
362
|
+
if (
|
|
363
|
+
runtime.status === "connected" &&
|
|
364
|
+
(runtime.monitoringIssue || runtime.contextRelayError)
|
|
365
|
+
) {
|
|
346
366
|
if (runtime.attempting)
|
|
347
|
-
return `Already retrying
|
|
348
|
-
void this.
|
|
349
|
-
return `Retrying
|
|
367
|
+
return `Already retrying connection setup on ${target}`;
|
|
368
|
+
void this.retrySetup(target, runtime);
|
|
369
|
+
return `Retrying connection setup on ${target}`;
|
|
350
370
|
}
|
|
351
371
|
if (runtime.local) {
|
|
352
372
|
return `${target} is the local machine and is already connected`;
|
|
@@ -364,11 +384,10 @@ export class AgentFleet {
|
|
|
364
384
|
const retries = [...this.runtimes.entries()].filter(
|
|
365
385
|
([, runtime]) =>
|
|
366
386
|
runtime.status === "connected" &&
|
|
367
|
-
runtime.monitoringIssue &&
|
|
387
|
+
(runtime.monitoringIssue || runtime.contextRelayError) &&
|
|
368
388
|
!runtime.attempting,
|
|
369
389
|
);
|
|
370
|
-
for (const [name, runtime] of retries)
|
|
371
|
-
void this.retryMonitoring(name, runtime);
|
|
390
|
+
for (const [name, runtime] of retries) void this.retrySetup(name, runtime);
|
|
372
391
|
const names = [...this.runtimes.entries()]
|
|
373
392
|
.filter(
|
|
374
393
|
([, runtime]) =>
|
|
@@ -383,7 +402,7 @@ export class AgentFleet {
|
|
|
383
402
|
if (names.length > 0 || retries.length > 0) {
|
|
384
403
|
return [
|
|
385
404
|
retries.length > 0
|
|
386
|
-
? `Retrying
|
|
405
|
+
? `Retrying connection setup on ${retries.map(([name]) => name).join(", ")}`
|
|
387
406
|
: "",
|
|
388
407
|
names.length > 0 ? `Connecting to ${names.join(", ")}` : "",
|
|
389
408
|
]
|
|
@@ -473,14 +492,49 @@ export class AgentFleet {
|
|
|
473
492
|
});
|
|
474
493
|
}
|
|
475
494
|
|
|
476
|
-
private async
|
|
495
|
+
private async prepareContextRelay(
|
|
496
|
+
name: string,
|
|
497
|
+
runtime: Runtime,
|
|
498
|
+
client: RemoteHerdrClient,
|
|
499
|
+
ctx: ExtensionContext,
|
|
500
|
+
): Promise<void> {
|
|
501
|
+
if (!this.contextRelay) return;
|
|
502
|
+
try {
|
|
503
|
+
await client.startContextRelay(
|
|
504
|
+
ctx.sessionManager.getSessionId(),
|
|
505
|
+
name,
|
|
506
|
+
(request, signal) => this.contextRelay!(ctx, request, signal),
|
|
507
|
+
);
|
|
508
|
+
if (this.context !== ctx || this.runtimes.get(name) !== runtime) return;
|
|
509
|
+
delete runtime.contextRelayError;
|
|
510
|
+
} catch (error) {
|
|
511
|
+
if (this.context !== ctx || this.runtimes.get(name) !== runtime) return;
|
|
512
|
+
runtime.contextRelayError = errorMessage(error);
|
|
513
|
+
ctx.ui.notify(
|
|
514
|
+
`Context sharing unavailable on ${name}: ${runtime.contextRelayError}\nRun /herdr connect ${name} to retry sharing.`,
|
|
515
|
+
"warning",
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
private async retrySetup(name: string, runtime: Runtime): Promise<void> {
|
|
477
521
|
const monitor = runtime.monitor;
|
|
478
522
|
const ctx = this.context;
|
|
479
523
|
const generation = this.generation;
|
|
480
524
|
if (!monitor || !ctx || runtime.attempting) return;
|
|
481
525
|
runtime.attempting = true;
|
|
482
526
|
try {
|
|
483
|
-
|
|
527
|
+
if (
|
|
528
|
+
runtime.contextRelayError &&
|
|
529
|
+
runtime.client instanceof RemoteHerdrClient
|
|
530
|
+
)
|
|
531
|
+
await this.prepareContextRelay(name, runtime, runtime.client, ctx);
|
|
532
|
+
if (
|
|
533
|
+
this.isCurrent(generation, ctx) &&
|
|
534
|
+
this.runtimes.get(name) === runtime &&
|
|
535
|
+
runtime.monitoringIssue
|
|
536
|
+
)
|
|
537
|
+
await monitor.retryMonitoring();
|
|
484
538
|
} catch (error) {
|
|
485
539
|
if (
|
|
486
540
|
this.isCurrent(generation, ctx) &&
|
|
@@ -526,6 +580,7 @@ export class AgentFleet {
|
|
|
526
580
|
if (runtime.client === client)
|
|
527
581
|
this.disconnected(name, runtime, error.message);
|
|
528
582
|
});
|
|
583
|
+
await this.prepareContextRelay(name, runtime, client, ctx);
|
|
529
584
|
if (
|
|
530
585
|
!this.isCurrent(generation, ctx) ||
|
|
531
586
|
this.runtimes.get(name) !== runtime
|
|
@@ -596,6 +651,7 @@ export class AgentFleet {
|
|
|
596
651
|
runtime.monitor?.deactivate();
|
|
597
652
|
if (runtime.client instanceof RemoteHerdrClient) runtime.client.close();
|
|
598
653
|
delete runtime.client;
|
|
654
|
+
delete runtime.contextRelayError;
|
|
599
655
|
delete runtime.monitoringIssue;
|
|
600
656
|
runtime.status = "unavailable";
|
|
601
657
|
delete runtime.attempting;
|
package/src/herdr-client.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createConnection } from "node:net";
|
|
2
|
+
import { requestContext } from "./remote/shepherdr-context.mjs";
|
|
2
3
|
import { sendPeerMessage } from "./remote/shepherdr-peer.mjs";
|
|
3
4
|
import type {
|
|
4
5
|
HerdrEvent,
|
|
@@ -55,6 +56,12 @@ export function isHerdrErrorCode(error: unknown, code: string): boolean {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
export interface HerdrConnection {
|
|
59
|
+
requestContext(
|
|
60
|
+
path: string,
|
|
61
|
+
request: unknown,
|
|
62
|
+
signal?: AbortSignal,
|
|
63
|
+
): Promise<unknown>;
|
|
64
|
+
contextRelayPath(): string;
|
|
58
65
|
request<T>(method: string, params?: object, timeoutMs?: number): Promise<T>;
|
|
59
66
|
sendMessage(agent: PaneInfo, message: PeerMessage): Promise<PeerDelivery>;
|
|
60
67
|
subscribe(
|
|
@@ -67,6 +74,16 @@ export interface HerdrConnection {
|
|
|
67
74
|
|
|
68
75
|
export class HerdrClient implements HerdrConnection {
|
|
69
76
|
readonly socketPath: string;
|
|
77
|
+
requestContext(
|
|
78
|
+
path: string,
|
|
79
|
+
request: unknown,
|
|
80
|
+
signal?: AbortSignal,
|
|
81
|
+
): Promise<unknown> {
|
|
82
|
+
return requestContext(path, request, signal);
|
|
83
|
+
}
|
|
84
|
+
contextRelayPath(): string {
|
|
85
|
+
throw new Error("Local context routes use the controller session");
|
|
86
|
+
}
|
|
70
87
|
|
|
71
88
|
constructor(socketPath = process.env["HERDR_SOCKET_PATH"]) {
|
|
72
89
|
if (!socketPath) {
|
package/src/launch.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
+
import { parseArgs } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
import {
|
|
4
5
|
getAgent,
|
|
5
6
|
getPane,
|
|
6
7
|
getSnapshot,
|
|
7
8
|
parsePaneInfo,
|
|
8
9
|
resolveWorkspace,
|
|
10
|
+
sessionPath,
|
|
9
11
|
} from "./herdr.js";
|
|
10
12
|
import { type HerdrConnection, isHerdrErrorCode } from "./herdr-client.js";
|
|
11
13
|
import type { PaneInfo } from "./types.js";
|
|
@@ -208,6 +210,12 @@ export async function startAgent(
|
|
|
208
210
|
throw new Error("name must match [a-z][a-z0-9_-]{0,31}");
|
|
209
211
|
}
|
|
210
212
|
const label = params.label?.trim() || name;
|
|
213
|
+
const args = ["--name", label, ...(options.agentArgs ?? [])];
|
|
214
|
+
if (parseArgs(args).noSession) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
"spawn requires a persistent Pi session; remove --no-session from profile pi_args",
|
|
217
|
+
);
|
|
218
|
+
}
|
|
211
219
|
if (params.placement === "pane" && params.cwd) {
|
|
212
220
|
throw new Error(
|
|
213
221
|
"cwd cannot change an existing pane; prepare the pane through Herdr",
|
|
@@ -225,7 +233,7 @@ export async function startAgent(
|
|
|
225
233
|
name,
|
|
226
234
|
kind: "pi",
|
|
227
235
|
pane_id: created.paneId,
|
|
228
|
-
args
|
|
236
|
+
args,
|
|
229
237
|
timeout_ms: 30_000,
|
|
230
238
|
});
|
|
231
239
|
} catch (error) {
|
|
@@ -303,6 +311,7 @@ async function startWhenShellReady(
|
|
|
303
311
|
);
|
|
304
312
|
const terminalId = started.agent.terminal_id;
|
|
305
313
|
const readyDeadline = Date.now() + 30_000;
|
|
314
|
+
let waitingForSession = false;
|
|
306
315
|
while (Date.now() < readyDeadline) {
|
|
307
316
|
let current: PaneInfo;
|
|
308
317
|
try {
|
|
@@ -321,14 +330,14 @@ async function startWhenShellReady(
|
|
|
321
330
|
if (current.agent_status === "blocked") {
|
|
322
331
|
throw new Error(`agent ${name} is blocked during startup`);
|
|
323
332
|
}
|
|
324
|
-
|
|
333
|
+
waitingForSession =
|
|
325
334
|
(current.agent_status === "idle" || current.agent_status === "done") &&
|
|
326
335
|
current.interactive_ready === true &&
|
|
327
|
-
current.agent === "pi"
|
|
328
|
-
) {
|
|
329
|
-
return current;
|
|
330
|
-
|
|
331
|
-
if (
|
|
336
|
+
current.agent === "pi";
|
|
337
|
+
if (waitingForSession) {
|
|
338
|
+
if (sessionPath(current)) return current;
|
|
339
|
+
// Herdr can finish launch before Pi reports its persistent session.
|
|
340
|
+
} else if (
|
|
332
341
|
(current.agent_status === "idle" || current.agent_status === "done") &&
|
|
333
342
|
current.launch_pending === false
|
|
334
343
|
) {
|
|
@@ -336,7 +345,9 @@ async function startWhenShellReady(
|
|
|
336
345
|
}
|
|
337
346
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
338
347
|
}
|
|
339
|
-
throw new Error(
|
|
348
|
+
throw new Error(
|
|
349
|
+
`timed out waiting for agent ${name} ${waitingForSession ? "to register its Pi session" : "to become interactive"}`,
|
|
350
|
+
);
|
|
340
351
|
}
|
|
341
352
|
|
|
342
353
|
async function resolveDuringStart(
|
package/src/messages.ts
CHANGED
|
@@ -22,6 +22,8 @@ const AGENT_EVENT_MESSAGE_TYPE = "herdr-agent-event";
|
|
|
22
22
|
const REALTIME_VOICE_PROMPT_CHANNEL =
|
|
23
23
|
"@howaboua/pi-codex-conversion/realtime-voice-prompt/v1";
|
|
24
24
|
const MAX_REALTIME_VOICE_PROMPT_BYTES = 8 * 1_024;
|
|
25
|
+
const DELEGATED_WORKER_GUIDANCE =
|
|
26
|
+
"When finished or blocked from progressing, end with an assistant reply. Use send only for useful mid-run updates while work can continue. Do not watch your parent or use messaging to wait for a reply.";
|
|
25
27
|
|
|
26
28
|
function xml(value: string): string {
|
|
27
29
|
return value
|
|
@@ -85,6 +87,7 @@ export async function attributeAgentPrompt(
|
|
|
85
87
|
return {
|
|
86
88
|
sender: `<herdr_sender ${sourceAttributes(source)} />`,
|
|
87
89
|
text: message,
|
|
90
|
+
...(kind === "task" ? { context: DELEGATED_WORKER_GUIDANCE } : {}),
|
|
88
91
|
};
|
|
89
92
|
}
|
|
90
93
|
|
|
@@ -213,18 +216,37 @@ function agentVoicePrompt(details: AgentEventDetails): string {
|
|
|
213
216
|
|
|
214
217
|
function announceAgentEvent(
|
|
215
218
|
pi: ExtensionAPI,
|
|
216
|
-
|
|
219
|
+
candidateId: string,
|
|
220
|
+
prompt: string,
|
|
217
221
|
): void {
|
|
218
|
-
const candidateId = `pi-shepherdr:${details.machine}:${details.paneId}`;
|
|
219
222
|
const id =
|
|
220
223
|
new TextEncoder().encode(candidateId).byteLength <= 160
|
|
221
224
|
? candidateId
|
|
222
225
|
: "pi-shepherdr:worker";
|
|
223
|
-
const prompt = agentVoicePrompt(details);
|
|
224
226
|
pi.events.emit(REALTIME_VOICE_PROMPT_CHANNEL, { id, active: true, prompt });
|
|
225
227
|
pi.events.emit(REALTIME_VOICE_PROMPT_CHANNEL, { id, active: false, prompt });
|
|
226
228
|
}
|
|
227
229
|
|
|
230
|
+
export function announcePeerMessage(
|
|
231
|
+
pi: ExtensionAPI,
|
|
232
|
+
message: PeerMessage,
|
|
233
|
+
): void {
|
|
234
|
+
const source = Object.fromEntries(
|
|
235
|
+
Array.from(
|
|
236
|
+
message.sender.matchAll(/ ([a-z_]+)="([^"]*)"/g),
|
|
237
|
+
([, key, value]) => [key, value],
|
|
238
|
+
),
|
|
239
|
+
);
|
|
240
|
+
if (source["kind"] !== "message" || message.text.startsWith("/")) return;
|
|
241
|
+
announceAgentEvent(
|
|
242
|
+
pi,
|
|
243
|
+
`pi-shepherdr:${source["host"] ?? "local"}:${source["pane"] ?? "peer"}`,
|
|
244
|
+
boundedVoicePrompt(
|
|
245
|
+
`Briefly tell the user the useful update from this peer.\n\nPeer: ${source["host"] ?? "local"} / ${source["name"] || source["pane"] || "unnamed"}\n\nUpdate:\n${message.text.trim()}`,
|
|
246
|
+
),
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
228
250
|
function operatorCommand(operatorPrefix: string, command: string): string {
|
|
229
251
|
return `\`${operatorPrefix} ${command}\``;
|
|
230
252
|
}
|
|
@@ -376,7 +398,11 @@ export function injectAgentEvent(
|
|
|
376
398
|
delivery,
|
|
377
399
|
);
|
|
378
400
|
if (idle) startPreparedIdleTurn(pi, ctx);
|
|
379
|
-
announceAgentEvent(
|
|
401
|
+
announceAgentEvent(
|
|
402
|
+
pi,
|
|
403
|
+
`pi-shepherdr:${message.details.machine}:${message.details.paneId}`,
|
|
404
|
+
agentVoicePrompt(message.details),
|
|
405
|
+
);
|
|
380
406
|
}
|
|
381
407
|
|
|
382
408
|
export function registerAgentEventRenderer(pi: ExtensionAPI): void {
|
package/src/peer-inbox.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
import { sendPolicyMessage, startPreparedIdleTurn } from "./delivery.js";
|
|
9
9
|
import { getCurrentPane } from "./herdr.js";
|
|
10
10
|
import { HerdrClient } from "./herdr-client.js";
|
|
11
|
+
import { announcePeerMessage } from "./messages.js";
|
|
11
12
|
import {
|
|
12
13
|
MAX_PEER_FRAME_BYTES,
|
|
13
14
|
peerInboxPath,
|
|
@@ -168,6 +169,15 @@ async function openInbox(
|
|
|
168
169
|
// Appending then claiming the shared kickoff also coalesces arrivals
|
|
169
170
|
// during async preparation, when Pi still reports itself idle.
|
|
170
171
|
if (idle) startPreparedIdleTurn(pi, ctx);
|
|
172
|
+
// Voice failure must not turn accepted delivery into a retry.
|
|
173
|
+
try {
|
|
174
|
+
announcePeerMessage(pi, { sender: request["sender"], text });
|
|
175
|
+
} catch (error) {
|
|
176
|
+
ctx.ui.notify(
|
|
177
|
+
`Peer voice update failed: ${String(error)}`,
|
|
178
|
+
"warning",
|
|
179
|
+
);
|
|
180
|
+
}
|
|
171
181
|
reply({ ok: true, command: false });
|
|
172
182
|
} catch (error) {
|
|
173
183
|
reply({
|