@howaboua/pi-shepherdr 0.2.23 → 0.2.24
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 +7 -18
- package/README.md +63 -60
- package/biome.json +1 -1
- package/index.ts +2 -2
- package/package.json +14 -9
- package/src/agents-discovery.ts +41 -26
- package/src/agents-focus.ts +2 -2
- package/src/agents-reply.ts +1 -1
- package/src/agents-spawn.ts +2 -2
- package/src/agents-tool.ts +2 -2
- package/src/agents-work.ts +3 -3
- package/src/attachment-notes.ts +14 -2
- package/src/attachment-protocol.ts +21 -4
- package/src/attachment-routing.ts +1 -1
- package/src/attachment-target.ts +5 -2
- package/src/attachment.ts +2 -3
- package/src/board/host.ts +2 -2
- package/src/board/membership.ts +1 -1
- package/src/{control-panel-actions.ts → control-panel/actions.ts} +2 -2
- package/src/{control-panel.ts → control-panel/index.ts} +4 -4
- package/src/{control-panel-items.ts → control-panel/items.ts} +3 -3
- package/src/{control-panel-view.ts → control-panel/view.ts} +3 -3
- package/src/controller.ts +6 -3
- package/src/fleet/index.ts +384 -0
- package/src/fleet/inspection.ts +141 -0
- package/src/fleet/machine.ts +52 -0
- package/src/fleet/monitor.ts +71 -0
- package/src/fleet/persistence.ts +42 -0
- package/src/fleet/reconnect.ts +75 -0
- package/src/fleet/setup.ts +92 -0
- package/src/messages/attachments.ts +39 -0
- package/src/messages/attribution.ts +75 -0
- package/src/messages/event-details.ts +69 -0
- package/src/messages/events.ts +189 -0
- package/src/messages/focus.ts +38 -0
- package/src/messages/guidance.ts +83 -0
- package/src/messages/render.ts +89 -0
- package/src/messages/voice-announcements.ts +79 -0
- package/src/monitor.ts +2 -2
- package/src/peer-inbox.ts +2 -2
- package/src/remote/client.ts +127 -0
- package/src/remote/context-relay.ts +84 -0
- package/src/remote/deployment.ts +179 -0
- package/src/remote/focus-channels.ts +89 -0
- package/src/remote/transport.ts +369 -0
- package/src/settlement/collector.ts +122 -0
- package/src/settlement/delivery.ts +144 -0
- package/src/{settlement.ts → settlement/index.ts} +23 -233
- package/src/shared-context-host.ts +33 -11
- package/src/shared-context.ts +10 -4
- package/src/spawn-context.ts +20 -17
- package/src/voice-handoff.ts +1 -1
- package/src/worker-service.ts +2 -2
- package/src/fleet.ts +0 -702
- package/src/messages.ts +0 -637
- package/src/remote-client.ts +0 -761
|
@@ -6,51 +6,23 @@ import {
|
|
|
6
6
|
activityAttemptId,
|
|
7
7
|
activityExpectedUser,
|
|
8
8
|
activityTask,
|
|
9
|
-
|
|
10
|
-
} from "
|
|
11
|
-
import {
|
|
12
|
-
import type {
|
|
13
|
-
import { injectAgentEvent } from "./messages.js";
|
|
14
|
-
import type { MonitorState, WorkAttempt } from "./monitor-state.js";
|
|
15
|
-
import { type AssistantReader, SessionReader } from "./session-reader.js";
|
|
9
|
+
} from "../activity.js";
|
|
10
|
+
import type { HerdrConnection } from "../herdr-client.js";
|
|
11
|
+
import type { MonitorState, WorkAttempt } from "../monitor-state.js";
|
|
12
|
+
import type { AssistantReader } from "../session-reader.js";
|
|
16
13
|
import type {
|
|
17
|
-
ExtensionMessage,
|
|
18
14
|
ExtensionReply,
|
|
19
15
|
LatestAssistant,
|
|
20
16
|
MonitoredAgent,
|
|
21
17
|
PaneInfo,
|
|
22
18
|
SessionView,
|
|
23
19
|
SettledAgentStatus,
|
|
24
|
-
} from "
|
|
20
|
+
} from "../types.js";
|
|
21
|
+
import { blockedSettlement, SettlementCollector } from "./collector.js";
|
|
22
|
+
import { SettlementDelivery } from "./delivery.js";
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
workspace?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface CollectedSettlement {
|
|
32
|
-
agent: PaneInfo;
|
|
33
|
-
extensionMessages?: ExtensionMessage[];
|
|
34
|
-
labels: SettlementLabels;
|
|
35
|
-
reply?: LatestAssistant;
|
|
36
|
-
status: SettledAgentStatus;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface CollectedSettlementWithSession extends CollectedSettlement {
|
|
40
|
-
session: SessionView;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface ClaimedSettlement extends CollectedSettlement {
|
|
44
|
-
blockedMessage?: string;
|
|
45
|
-
record: MonitoredAgent;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface SettlementClaim {
|
|
49
|
-
replyingTo?: ExtensionReply;
|
|
50
|
-
cleanup(): void;
|
|
51
|
-
reject(error: Error): void;
|
|
52
|
-
resolve(settlement: ClaimedSettlement): void;
|
|
53
|
-
}
|
|
24
|
+
export type { ClaimedSettlement } from "./delivery.js";
|
|
25
|
+
export { SettlementCollector };
|
|
54
26
|
|
|
55
27
|
interface SettlementRetry {
|
|
56
28
|
attemptId: string | undefined;
|
|
@@ -66,26 +38,6 @@ function attemptKey(terminalId: string, attemptId: string | undefined): string {
|
|
|
66
38
|
return JSON.stringify([terminalId, attemptId ?? null]);
|
|
67
39
|
}
|
|
68
40
|
|
|
69
|
-
function blockedSettlement(
|
|
70
|
-
record: MonitoredAgent,
|
|
71
|
-
): CollectedSettlementWithSession {
|
|
72
|
-
return {
|
|
73
|
-
agent: {
|
|
74
|
-
agent: "pi",
|
|
75
|
-
agent_status: "blocked",
|
|
76
|
-
...(record.cwd ? { cwd: record.cwd } : {}),
|
|
77
|
-
...(record.name ? { name: record.name } : {}),
|
|
78
|
-
pane_id: record.paneId,
|
|
79
|
-
tab_id: record.tabId,
|
|
80
|
-
terminal_id: record.terminalId,
|
|
81
|
-
workspace_id: record.workspaceId,
|
|
82
|
-
},
|
|
83
|
-
labels: {},
|
|
84
|
-
session: {},
|
|
85
|
-
status: "blocked",
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
41
|
export interface SettlementRequest {
|
|
90
42
|
blockedMessage?: string;
|
|
91
43
|
record: MonitoredAgent;
|
|
@@ -106,91 +58,12 @@ interface PendingBlockedSettlement {
|
|
|
106
58
|
retry?: SettlementRetry;
|
|
107
59
|
}
|
|
108
60
|
|
|
109
|
-
export class SettlementCollector {
|
|
110
|
-
private readonly client: HerdrConnection;
|
|
111
|
-
private readonly reader: AssistantReader;
|
|
112
|
-
|
|
113
|
-
constructor(
|
|
114
|
-
client: HerdrConnection,
|
|
115
|
-
reader: AssistantReader = new SessionReader(),
|
|
116
|
-
) {
|
|
117
|
-
this.client = client;
|
|
118
|
-
this.reader = reader;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async latest(panel: PaneInfo): Promise<LatestAssistant | undefined> {
|
|
122
|
-
try {
|
|
123
|
-
return await this.reader.latest(sessionPath(panel));
|
|
124
|
-
} catch (error) {
|
|
125
|
-
if (panel.agent_status !== "blocked") throw error;
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
view(panel: PaneInfo): Promise<SessionView> {
|
|
131
|
-
return this.reader.view(sessionPath(panel));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async collect(
|
|
135
|
-
record: MonitoredAgent,
|
|
136
|
-
reportedStatus?: "blocked",
|
|
137
|
-
): Promise<CollectedSettlementWithSession | undefined> {
|
|
138
|
-
const [current, snapshot] = await Promise.all([
|
|
139
|
-
getAgent(this.client, record.paneId),
|
|
140
|
-
getSnapshot(this.client),
|
|
141
|
-
]);
|
|
142
|
-
if (current.terminal_id !== record.terminalId || current.agent !== "pi") {
|
|
143
|
-
return reportedStatus === "blocked"
|
|
144
|
-
? blockedSettlement(record)
|
|
145
|
-
: undefined;
|
|
146
|
-
}
|
|
147
|
-
const status =
|
|
148
|
-
reportedStatus ??
|
|
149
|
-
(isSettledStatus(current.agent_status)
|
|
150
|
-
? current.agent_status
|
|
151
|
-
: undefined);
|
|
152
|
-
if (!status) return undefined;
|
|
153
|
-
let view: SessionView;
|
|
154
|
-
try {
|
|
155
|
-
view = await this.reader.view(sessionPath(current));
|
|
156
|
-
} catch (error) {
|
|
157
|
-
if (status !== "blocked") throw error;
|
|
158
|
-
view = {};
|
|
159
|
-
}
|
|
160
|
-
const workspace = snapshot.workspaces.find(
|
|
161
|
-
(candidate) => candidate.workspace_id === current.workspace_id,
|
|
162
|
-
)?.label;
|
|
163
|
-
const tab = snapshot.tabs.find(
|
|
164
|
-
(candidate) => candidate.tab_id === current.tab_id,
|
|
165
|
-
)?.label;
|
|
166
|
-
return {
|
|
167
|
-
agent: current,
|
|
168
|
-
labels: {
|
|
169
|
-
...(workspace ? { workspace } : {}),
|
|
170
|
-
...(tab ? { tab } : {}),
|
|
171
|
-
},
|
|
172
|
-
...(view.assistant ? { reply: view.assistant } : {}),
|
|
173
|
-
...(view.extensionMessages
|
|
174
|
-
? { extensionMessages: view.extensionMessages }
|
|
175
|
-
: {}),
|
|
176
|
-
session: view,
|
|
177
|
-
status,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
61
|
export class SettlementReporter {
|
|
183
62
|
private readonly collector: SettlementCollector;
|
|
184
63
|
private readonly persist: () => void;
|
|
185
|
-
private readonly pi: ExtensionAPI;
|
|
186
|
-
private readonly origin: {
|
|
187
|
-
machine: string;
|
|
188
|
-
label: () => string;
|
|
189
|
-
operatorPrefix: string;
|
|
190
|
-
};
|
|
191
64
|
private readonly reporting = new Map<string, SettledAgentStatus>();
|
|
192
65
|
private readonly pendingBlocked = new Map<string, PendingBlockedSettlement>();
|
|
193
|
-
private readonly
|
|
66
|
+
private readonly delivery: SettlementDelivery;
|
|
194
67
|
private readonly retries = new Map<string, NodeJS.Timeout>();
|
|
195
68
|
private readonly state: MonitorState;
|
|
196
69
|
|
|
@@ -202,11 +75,10 @@ export class SettlementReporter {
|
|
|
202
75
|
reader: AssistantReader | undefined,
|
|
203
76
|
origin: { machine: string; label: () => string; operatorPrefix: string },
|
|
204
77
|
) {
|
|
205
|
-
this.
|
|
78
|
+
this.delivery = new SettlementDelivery(pi, origin);
|
|
206
79
|
this.collector = new SettlementCollector(client, reader);
|
|
207
80
|
this.state = state;
|
|
208
81
|
this.persist = persist;
|
|
209
|
-
this.origin = origin;
|
|
210
82
|
}
|
|
211
83
|
|
|
212
84
|
latest(panel: PaneInfo): Promise<LatestAssistant | undefined> {
|
|
@@ -220,11 +92,7 @@ export class SettlementReporter {
|
|
|
220
92
|
stop(): void {
|
|
221
93
|
this.reporting.clear();
|
|
222
94
|
this.pendingBlocked.clear();
|
|
223
|
-
|
|
224
|
-
claim.cleanup();
|
|
225
|
-
claim.reject(new Error("Shepherdr monitor stopped"));
|
|
226
|
-
}
|
|
227
|
-
this.claims.clear();
|
|
95
|
+
this.delivery.stop();
|
|
228
96
|
for (const timer of this.retries.values()) clearTimeout(timer);
|
|
229
97
|
this.retries.clear();
|
|
230
98
|
}
|
|
@@ -233,51 +101,15 @@ export class SettlementReporter {
|
|
|
233
101
|
attempt: WorkAttempt,
|
|
234
102
|
signal: AbortSignal,
|
|
235
103
|
replyingTo?: ExtensionReply,
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
// Updates share the worker's current settlement, without stealing its waiter.
|
|
239
|
-
if (this.claims.has(attempt.attemptId)) return;
|
|
240
|
-
return new Promise<ClaimedSettlement>((resolve, reject) => {
|
|
241
|
-
const abort = () => {
|
|
242
|
-
const claim = this.claims.get(attempt.attemptId);
|
|
243
|
-
if (!claim) return;
|
|
244
|
-
this.claims.delete(attempt.attemptId);
|
|
245
|
-
claim.cleanup();
|
|
246
|
-
reject(
|
|
247
|
-
signal.reason instanceof Error
|
|
248
|
-
? signal.reason
|
|
249
|
-
: new Error("Shepherdr wait aborted"),
|
|
250
|
-
);
|
|
251
|
-
};
|
|
252
|
-
const claim: SettlementClaim = {
|
|
253
|
-
...(replyingTo ? { replyingTo } : {}),
|
|
254
|
-
cleanup: () => signal.removeEventListener("abort", abort),
|
|
255
|
-
reject,
|
|
256
|
-
resolve,
|
|
257
|
-
};
|
|
258
|
-
this.claims.set(attempt.attemptId, claim);
|
|
259
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
releaseClaim(attempt: WorkAttempt | undefined, error: unknown): void {
|
|
264
|
-
if (!attempt) return;
|
|
265
|
-
this.releaseAttempt(attempt.attemptId, error);
|
|
104
|
+
) {
|
|
105
|
+
return this.delivery.claim(attempt, signal, replyingTo);
|
|
266
106
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const attemptId = activityAttemptId(record.activity);
|
|
270
|
-
if (attemptId) this.releaseAttempt(attemptId, error);
|
|
107
|
+
releaseClaim(attempt: WorkAttempt | undefined, error: unknown) {
|
|
108
|
+
this.delivery.releaseClaim(attempt, error);
|
|
271
109
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const claim = this.claims.get(attemptId);
|
|
275
|
-
if (!claim) return;
|
|
276
|
-
this.claims.delete(attemptId);
|
|
277
|
-
claim.cleanup();
|
|
278
|
-
claim.reject(error instanceof Error ? error : new Error(String(error)));
|
|
110
|
+
releaseAgentClaim(record: MonitoredAgent, error: unknown) {
|
|
111
|
+
this.delivery.releaseAgentClaim(record, error);
|
|
279
112
|
}
|
|
280
|
-
|
|
281
113
|
async report(
|
|
282
114
|
lifecycle: SettlementLifecycle,
|
|
283
115
|
request: SettlementRequest,
|
|
@@ -306,7 +138,7 @@ export class SettlementReporter {
|
|
|
306
138
|
this.reporting.set(key, request.status);
|
|
307
139
|
try {
|
|
308
140
|
const replyingTo = retryState.attemptId
|
|
309
|
-
? this.
|
|
141
|
+
? this.delivery.replyingTo(retryState.attemptId)
|
|
310
142
|
: undefined;
|
|
311
143
|
const settlement = await this.collector.collect(
|
|
312
144
|
request.record,
|
|
@@ -322,7 +154,7 @@ export class SettlementReporter {
|
|
|
322
154
|
) {
|
|
323
155
|
if (request.status !== "blocked") return;
|
|
324
156
|
this.clearRetry(request.record.terminalId, retryState.attemptId);
|
|
325
|
-
this.deliverSettlement(
|
|
157
|
+
this.delivery.deliverSettlement(
|
|
326
158
|
lifecycle,
|
|
327
159
|
request.record,
|
|
328
160
|
settlement,
|
|
@@ -405,7 +237,7 @@ export class SettlementReporter {
|
|
|
405
237
|
) {
|
|
406
238
|
this.clearRetry(current.terminalId, retryState.attemptId);
|
|
407
239
|
this.persist();
|
|
408
|
-
this.deliverSettlement(
|
|
240
|
+
this.delivery.deliverSettlement(
|
|
409
241
|
lifecycle,
|
|
410
242
|
current,
|
|
411
243
|
settlement,
|
|
@@ -430,7 +262,7 @@ export class SettlementReporter {
|
|
|
430
262
|
) {
|
|
431
263
|
this.persist();
|
|
432
264
|
}
|
|
433
|
-
this.deliverSettlement(
|
|
265
|
+
this.delivery.deliverSettlement(
|
|
434
266
|
lifecycle,
|
|
435
267
|
currentOwnsAttempt ? current : request.record,
|
|
436
268
|
blockedSettlement(current),
|
|
@@ -473,48 +305,6 @@ export class SettlementReporter {
|
|
|
473
305
|
}
|
|
474
306
|
}
|
|
475
307
|
|
|
476
|
-
private deliverSettlement(
|
|
477
|
-
lifecycle: SettlementLifecycle,
|
|
478
|
-
record: MonitoredAgent,
|
|
479
|
-
settlement: CollectedSettlementWithSession,
|
|
480
|
-
attemptId: string | undefined,
|
|
481
|
-
blockedMessage: string | undefined,
|
|
482
|
-
reply: LatestAssistant | undefined,
|
|
483
|
-
): void {
|
|
484
|
-
const claim = attemptId ? this.claims.get(attemptId) : undefined;
|
|
485
|
-
if (claim && attemptId) {
|
|
486
|
-
this.claims.delete(attemptId);
|
|
487
|
-
claim.cleanup();
|
|
488
|
-
const {
|
|
489
|
-
reply: _latestReply,
|
|
490
|
-
session: _session,
|
|
491
|
-
...claimedSettlement
|
|
492
|
-
} = settlement;
|
|
493
|
-
claim.resolve({
|
|
494
|
-
...claimedSettlement,
|
|
495
|
-
record,
|
|
496
|
-
...(blockedMessage ? { blockedMessage } : {}),
|
|
497
|
-
...(reply ? { reply } : {}),
|
|
498
|
-
});
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
injectAgentEvent(this.pi, lifecycle.context, {
|
|
502
|
-
agent: settlement.agent,
|
|
503
|
-
agentToolName: "agents",
|
|
504
|
-
...(settlement.extensionMessages
|
|
505
|
-
? { extensionMessages: settlement.extensionMessages }
|
|
506
|
-
: {}),
|
|
507
|
-
machine: this.origin.machine,
|
|
508
|
-
machineLabel: this.origin.label(),
|
|
509
|
-
operatorPrefix: this.origin.operatorPrefix,
|
|
510
|
-
...(blockedMessage ? { blockedMessage } : {}),
|
|
511
|
-
labels: settlement.labels,
|
|
512
|
-
record,
|
|
513
|
-
...(reply ? { reply } : {}),
|
|
514
|
-
status: settlement.status,
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
|
|
518
308
|
private clearRetry(terminalId: string, attemptId: string | undefined): void {
|
|
519
309
|
const key = attemptKey(terminalId, attemptId);
|
|
520
310
|
const retry = this.retries.get(key);
|
|
@@ -580,7 +370,7 @@ export class SettlementReporter {
|
|
|
580
370
|
" after " +
|
|
581
371
|
SETTLEMENT_RETRY_WINDOW_SECONDS +
|
|
582
372
|
" seconds";
|
|
583
|
-
if (attemptId) this.releaseAttempt(attemptId, new Error(message));
|
|
373
|
+
if (attemptId) this.delivery.releaseAttempt(attemptId, new Error(message));
|
|
584
374
|
lifecycle.context.ui.notify(message, "warning");
|
|
585
375
|
}
|
|
586
376
|
}
|
|
@@ -5,10 +5,10 @@ import type {
|
|
|
5
5
|
import type {
|
|
6
6
|
SharedContextRequest,
|
|
7
7
|
SharedContextResult,
|
|
8
|
-
} from "@howaboua/pi-
|
|
8
|
+
} from "@howaboua/pi-notes-compaction/context-sharing";
|
|
9
9
|
import { attachmentOwner, attachmentRoutes } from "./attachment-protocol.js";
|
|
10
10
|
import type { AgentBoard } from "./board/host.js";
|
|
11
|
-
import type { AgentFleet } from "./fleet.js";
|
|
11
|
+
import type { AgentFleet } from "./fleet/index.js";
|
|
12
12
|
import {
|
|
13
13
|
listenContext,
|
|
14
14
|
sessionContextPath,
|
|
@@ -21,37 +21,60 @@ export async function registerSharedAgentContext(
|
|
|
21
21
|
board: AgentBoard,
|
|
22
22
|
): Promise<SharedAgentContext> {
|
|
23
23
|
let api:
|
|
24
|
-
| typeof import("@howaboua/pi-
|
|
24
|
+
| typeof import("@howaboua/pi-notes-compaction/context-sharing")
|
|
25
25
|
| undefined;
|
|
26
26
|
try {
|
|
27
|
-
api = await import("@howaboua/pi-
|
|
27
|
+
api = await import("@howaboua/pi-notes-compaction/context-sharing");
|
|
28
28
|
} catch (error) {
|
|
29
29
|
const failure = error as { code?: string; message?: string };
|
|
30
30
|
const missing = failure.message?.match(
|
|
31
31
|
/Cannot find (?:package|module) ['"]([^'"]+)['"]/,
|
|
32
32
|
)?.[1];
|
|
33
|
-
const module = "@howaboua/pi-
|
|
33
|
+
const module = "@howaboua/pi-notes-compaction/context-sharing";
|
|
34
34
|
const unavailable =
|
|
35
35
|
((failure.code === "ERR_MODULE_NOT_FOUND" ||
|
|
36
36
|
failure.code === "MODULE_NOT_FOUND") &&
|
|
37
|
-
(missing === "@howaboua/pi-
|
|
37
|
+
(missing === "@howaboua/pi-notes-compaction" ||
|
|
38
38
|
missing === module ||
|
|
39
39
|
missing?.endsWith(`/${module}`))) ||
|
|
40
40
|
(failure.code === "ERR_PACKAGE_PATH_NOT_EXPORTED" &&
|
|
41
|
-
failure.message?.includes("@howaboua/pi-
|
|
41
|
+
failure.message?.includes("@howaboua/pi-notes-compaction") &&
|
|
42
42
|
failure.message.includes("./context-sharing"));
|
|
43
43
|
if (!unavailable)
|
|
44
44
|
throw new Error(
|
|
45
|
-
"Update pi-
|
|
45
|
+
"Update pi-notes-compaction to use shared agent context",
|
|
46
46
|
{ cause: error },
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
|
-
const connection = api?.
|
|
49
|
+
const connection = api?.connectNotesContextSharing(pi);
|
|
50
|
+
let relationships:
|
|
51
|
+
| ReturnType<
|
|
52
|
+
typeof import("@howaboua/pi-codex-conversion/agent-relationship")["connectCodexAgentRelationships"]
|
|
53
|
+
>
|
|
54
|
+
| undefined;
|
|
55
|
+
try {
|
|
56
|
+
const relationshipApi = await import(
|
|
57
|
+
"@howaboua/pi-codex-conversion/agent-relationship"
|
|
58
|
+
);
|
|
59
|
+
relationships = relationshipApi.connectCodexAgentRelationships(pi);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
const failure = error as { code?: string; message?: string };
|
|
62
|
+
if (
|
|
63
|
+
!(
|
|
64
|
+
(failure.code === "ERR_MODULE_NOT_FOUND" ||
|
|
65
|
+
failure.code === "MODULE_NOT_FOUND" ||
|
|
66
|
+
failure.code === "ERR_PACKAGE_PATH_NOT_EXPORTED") &&
|
|
67
|
+
failure.message?.includes("pi-codex-conversion")
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
50
72
|
const shared = new SharedAgentContext(
|
|
51
73
|
pi,
|
|
52
74
|
fleet,
|
|
53
75
|
() => connection?.service,
|
|
54
76
|
board,
|
|
77
|
+
() => relationships?.service,
|
|
55
78
|
);
|
|
56
79
|
let close: (() => Promise<void>) | undefined;
|
|
57
80
|
let unregister: (() => void) | undefined;
|
|
@@ -103,8 +126,6 @@ export async function registerSharedAgentContext(
|
|
|
103
126
|
signal,
|
|
104
127
|
);
|
|
105
128
|
if (attached) return attached;
|
|
106
|
-
if (connection?.service?.describe(context)?.storage === "remote")
|
|
107
|
-
return undefined;
|
|
108
129
|
return shared.handle(
|
|
109
130
|
context,
|
|
110
131
|
{ operation: "context", request, visited: [] },
|
|
@@ -129,6 +150,7 @@ export async function registerSharedAgentContext(
|
|
|
129
150
|
unregister?.();
|
|
130
151
|
await close?.();
|
|
131
152
|
connection?.dispose();
|
|
153
|
+
relationships?.dispose();
|
|
132
154
|
});
|
|
133
155
|
fleet.setContextRelay((ctx, request, signal) =>
|
|
134
156
|
shared.handle(ctx, request, signal),
|
package/src/shared-context.ts
CHANGED
|
@@ -4,16 +4,17 @@ import type {
|
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { binding, isBoardEnvelope } from "@howaboua/pi-agent-board/integration";
|
|
7
|
+
import type { CodexAgentRelationshipService } from "@howaboua/pi-codex-conversion/agent-relationship";
|
|
7
8
|
import type {
|
|
8
9
|
ContextSharingService,
|
|
9
10
|
SharedContextRequest,
|
|
10
11
|
SharedContextResult,
|
|
11
|
-
} from "@howaboua/pi-
|
|
12
|
+
} from "@howaboua/pi-notes-compaction/context-sharing";
|
|
12
13
|
import { Check } from "typebox/value";
|
|
13
14
|
import { AgentAttachment } from "./attachment.js";
|
|
14
15
|
import { Identity } from "./attachment-protocol.js";
|
|
15
16
|
import type { AgentBoard } from "./board/host.js";
|
|
16
|
-
import type { AgentFleet } from "./fleet.js";
|
|
17
|
+
import type { AgentFleet } from "./fleet/index.js";
|
|
17
18
|
import { sessionPath } from "./herdr.js";
|
|
18
19
|
import {
|
|
19
20
|
requestContext,
|
|
@@ -35,6 +36,9 @@ export class SharedAgentContext {
|
|
|
35
36
|
private readonly fleet: AgentFleet;
|
|
36
37
|
private readonly getService: () => ContextSharingService | undefined;
|
|
37
38
|
private readonly board: AgentBoard;
|
|
39
|
+
private readonly getRelationships: () =>
|
|
40
|
+
| CodexAgentRelationshipService
|
|
41
|
+
| undefined;
|
|
38
42
|
private running = false;
|
|
39
43
|
readonly attachment: AgentAttachment;
|
|
40
44
|
readonly spawns: SpawnContext;
|
|
@@ -44,12 +48,14 @@ export class SharedAgentContext {
|
|
|
44
48
|
fleet: AgentFleet,
|
|
45
49
|
getService: () => ContextSharingService | undefined,
|
|
46
50
|
board: AgentBoard,
|
|
51
|
+
getRelationships: () => CodexAgentRelationshipService | undefined,
|
|
47
52
|
) {
|
|
48
53
|
this.fleet = fleet;
|
|
49
54
|
this.getService = getService;
|
|
50
55
|
this.board = board;
|
|
56
|
+
this.getRelationships = getRelationships;
|
|
51
57
|
this.attachment = new AgentAttachment(pi, board, getService);
|
|
52
|
-
this.spawns = new SpawnContext(pi, getService);
|
|
58
|
+
this.spawns = new SpawnContext(pi, getService, getRelationships);
|
|
53
59
|
pi.on("before_agent_start", () => {
|
|
54
60
|
this.running = true;
|
|
55
61
|
});
|
|
@@ -149,7 +155,7 @@ export class SharedAgentContext {
|
|
|
149
155
|
}
|
|
150
156
|
if ("operation" in value && value.operation === "bind-relationship") {
|
|
151
157
|
return (
|
|
152
|
-
|
|
158
|
+
this.getRelationships()?.bind(
|
|
153
159
|
ctx,
|
|
154
160
|
"relationship" in value ? value.relationship : undefined,
|
|
155
161
|
) ?? null
|
package/src/spawn-context.ts
CHANGED
|
@@ -3,8 +3,9 @@ import type {
|
|
|
3
3
|
ExtensionAPI,
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
6
|
+
import type { CodexAgentRelationshipService } from "@howaboua/pi-codex-conversion/agent-relationship";
|
|
7
|
+
import type { ContextSharingService } from "@howaboua/pi-notes-compaction/context-sharing";
|
|
8
|
+
import type { ConnectedMachine } from "./fleet/index.js";
|
|
8
9
|
import { sessionPath } from "./herdr.js";
|
|
9
10
|
import { sessionContextPath } from "./remote/shepherdr-context.mjs";
|
|
10
11
|
import type { PaneInfo } from "./types.js";
|
|
@@ -21,14 +22,20 @@ interface Routing {
|
|
|
21
22
|
transport: "shepherdr";
|
|
22
23
|
parent: string;
|
|
23
24
|
}
|
|
25
|
+
|
|
24
26
|
export class SpawnContext {
|
|
25
27
|
private readonly pi: ExtensionAPI;
|
|
28
|
+
private readonly getRelationships: () =>
|
|
29
|
+
| CodexAgentRelationshipService
|
|
30
|
+
| undefined;
|
|
26
31
|
private readonly getService: () => ContextSharingService | undefined;
|
|
27
32
|
constructor(
|
|
28
33
|
pi: ExtensionAPI,
|
|
29
34
|
getService: () => ContextSharingService | undefined,
|
|
35
|
+
getRelationships: () => CodexAgentRelationshipService | undefined,
|
|
30
36
|
) {
|
|
31
37
|
this.pi = pi;
|
|
38
|
+
this.getRelationships = getRelationships;
|
|
32
39
|
this.getService = getService;
|
|
33
40
|
}
|
|
34
41
|
prepareRelationship(
|
|
@@ -36,8 +43,8 @@ export class SpawnContext {
|
|
|
36
43
|
runtime: ConnectedMachine,
|
|
37
44
|
args: readonly string[],
|
|
38
45
|
) {
|
|
39
|
-
const service = this.
|
|
40
|
-
if (!service
|
|
46
|
+
const service = this.getRelationships();
|
|
47
|
+
if (!service) return undefined;
|
|
41
48
|
// Session-selection profiles resume existing identities rather than creating workers.
|
|
42
49
|
if (
|
|
43
50
|
args.some((arg) =>
|
|
@@ -48,7 +55,7 @@ export class SpawnContext {
|
|
|
48
55
|
)
|
|
49
56
|
return undefined;
|
|
50
57
|
const parentThreadId = ctx.sessionManager.getSessionId();
|
|
51
|
-
const cacheAffinityId = service.cacheAffinityId
|
|
58
|
+
const cacheAffinityId = service.cacheAffinityId(ctx);
|
|
52
59
|
const linkage = { parentThreadId, subagentKind: "collab_spawn" };
|
|
53
60
|
const relationship = {
|
|
54
61
|
...linkage,
|
|
@@ -112,18 +119,15 @@ export class SpawnContext {
|
|
|
112
119
|
throw new Error(
|
|
113
120
|
"Shared context spawn requires a saved controller session",
|
|
114
121
|
);
|
|
115
|
-
const routing: Routing
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
: runtime.client.contextRelayPath(),
|
|
122
|
-
}
|
|
123
|
-
: undefined;
|
|
122
|
+
const routing: Routing = {
|
|
123
|
+
transport: "shepherdr",
|
|
124
|
+
parent: runtime.local
|
|
125
|
+
? sessionContextPath(parentFile)
|
|
126
|
+
: runtime.client.contextRelayPath(),
|
|
127
|
+
};
|
|
124
128
|
const { binding, adopt } = await service.createChild(ctx, {
|
|
125
129
|
name,
|
|
126
|
-
|
|
130
|
+
routing,
|
|
127
131
|
});
|
|
128
132
|
return {
|
|
129
133
|
accept: async (agent: PaneInfo) => {
|
|
@@ -136,8 +140,7 @@ export class SpawnContext {
|
|
|
136
140
|
);
|
|
137
141
|
if (!value)
|
|
138
142
|
return {
|
|
139
|
-
warning:
|
|
140
|
-
"Spawned without shared context: the target needs Codex conversion with notes-based continuity",
|
|
143
|
+
warning: "Spawned without shared context: the target needs Notes",
|
|
141
144
|
};
|
|
142
145
|
if (
|
|
143
146
|
typeof value !== "object" ||
|
package/src/voice-handoff.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { recordContextBriefing } from "@howaboua/pi-agent-board/integration";
|
|
7
|
-
import { voiceFocusContinuity, voiceFocusReport } from "./messages.js";
|
|
7
|
+
import { voiceFocusContinuity, voiceFocusReport } from "./messages/focus.js";
|
|
8
8
|
import { registerFocusChannelReceiver } from "./peer-channel.js";
|
|
9
9
|
import type { FocusRequest, PaneInfo, PeerChannel } from "./types.js";
|
|
10
10
|
|
package/src/worker-service.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
import { activityTask } from "./activity.js";
|
|
7
7
|
import { dispatchAgentWork, reserveAgentName } from "./agents-work.js";
|
|
8
8
|
import type { AgentBoard } from "./board/host.js";
|
|
9
|
-
import type { AgentFleet } from "./fleet.js";
|
|
9
|
+
import type { AgentFleet } from "./fleet/index.js";
|
|
10
10
|
import { getSnapshot, sessionPath } from "./herdr.js";
|
|
11
11
|
import {
|
|
12
12
|
RolledBackAgentLaunchError,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
startAgent,
|
|
15
15
|
UnstartedAgentLaunchError,
|
|
16
16
|
} from "./launch.js";
|
|
17
|
-
import { attributeAgentPrompt } from "./messages.js";
|
|
17
|
+
import { attributeAgentPrompt } from "./messages/attribution.js";
|
|
18
18
|
import { loadAgentProfiles, profileAgentArgs } from "./profiles.js";
|
|
19
19
|
import type { SharedAgentContext } from "./shared-context.js";
|
|
20
20
|
import type { PaneInfo } from "./types.js";
|