@howaboua/pi-shepherdr 0.2.22 → 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.
Files changed (61) hide show
  1. package/CHANGELOG.md +16 -18
  2. package/README.md +79 -58
  3. package/biome.json +1 -1
  4. package/index.ts +7 -3
  5. package/package.json +14 -9
  6. package/src/agents-discovery.ts +42 -27
  7. package/src/agents-focus.ts +2 -2
  8. package/src/agents-reply.ts +1 -1
  9. package/src/agents-spawn.ts +143 -137
  10. package/src/agents-tool.ts +3 -3
  11. package/src/agents-work.ts +33 -9
  12. package/src/attachment-notes.ts +14 -2
  13. package/src/attachment-protocol.ts +21 -4
  14. package/src/attachment-routing.ts +1 -1
  15. package/src/attachment-target.ts +5 -2
  16. package/src/attachment.ts +2 -3
  17. package/src/board/host.ts +2 -2
  18. package/src/board/membership.ts +1 -1
  19. package/src/{control-panel-actions.ts → control-panel/actions.ts} +2 -2
  20. package/src/{control-panel.ts → control-panel/index.ts} +4 -4
  21. package/src/{control-panel-items.ts → control-panel/items.ts} +3 -3
  22. package/src/{control-panel-view.ts → control-panel/view.ts} +3 -3
  23. package/src/controller.ts +6 -3
  24. package/src/fleet/index.ts +384 -0
  25. package/src/fleet/inspection.ts +141 -0
  26. package/src/fleet/machine.ts +52 -0
  27. package/src/fleet/monitor.ts +71 -0
  28. package/src/fleet/persistence.ts +42 -0
  29. package/src/fleet/reconnect.ts +75 -0
  30. package/src/fleet/setup.ts +92 -0
  31. package/src/launch.ts +14 -2
  32. package/src/messages/attachments.ts +39 -0
  33. package/src/messages/attribution.ts +75 -0
  34. package/src/messages/event-details.ts +69 -0
  35. package/src/messages/events.ts +189 -0
  36. package/src/messages/focus.ts +38 -0
  37. package/src/messages/guidance.ts +83 -0
  38. package/src/messages/render.ts +89 -0
  39. package/src/messages/voice-announcements.ts +79 -0
  40. package/src/monitor-extension-messages.ts +14 -1
  41. package/src/monitor.ts +4 -2
  42. package/src/peer-inbox.ts +2 -2
  43. package/src/profile-prompt.ts +32 -0
  44. package/src/profiles.ts +5 -25
  45. package/src/remote/client.ts +127 -0
  46. package/src/remote/context-relay.ts +84 -0
  47. package/src/remote/deployment.ts +179 -0
  48. package/src/remote/focus-channels.ts +89 -0
  49. package/src/remote/transport.ts +369 -0
  50. package/src/settlement/collector.ts +122 -0
  51. package/src/settlement/delivery.ts +144 -0
  52. package/src/{settlement.ts → settlement/index.ts} +23 -233
  53. package/src/shared-context-host.ts +33 -11
  54. package/src/shared-context.ts +10 -4
  55. package/src/spawn-context.ts +20 -17
  56. package/src/voice-handoff.ts +1 -1
  57. package/src/worker-role.ts +83 -0
  58. package/src/worker-service.ts +74 -89
  59. package/src/fleet.ts +0 -702
  60. package/src/messages.ts +0 -629
  61. package/src/remote-client.ts +0 -751
@@ -5,10 +5,10 @@ import type {
5
5
  import type {
6
6
  SharedContextRequest,
7
7
  SharedContextResult,
8
- } from "@howaboua/pi-codex-conversion/context-sharing";
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-codex-conversion/context-sharing")
24
+ | typeof import("@howaboua/pi-notes-compaction/context-sharing")
25
25
  | undefined;
26
26
  try {
27
- api = await import("@howaboua/pi-codex-conversion/context-sharing");
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-codex-conversion/context-sharing";
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-codex-conversion" ||
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-codex-conversion") &&
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-codex-conversion to use shared agent context",
45
+ "Update pi-notes-compaction to use shared agent context",
46
46
  { cause: error },
47
47
  );
48
48
  }
49
- const connection = api?.connectCodexContextSharing(pi);
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),
@@ -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-codex-conversion/context-sharing";
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
- service?.bindRelationship?.(
158
+ this.getRelationships()?.bind(
153
159
  ctx,
154
160
  "relationship" in value ? value.relationship : undefined,
155
161
  ) ?? null
@@ -3,8 +3,9 @@ import type {
3
3
  ExtensionAPI,
4
4
  ExtensionContext,
5
5
  } from "@earendil-works/pi-coding-agent";
6
- import type { ContextSharingService } from "@howaboua/pi-codex-conversion/context-sharing";
7
- import type { ConnectedMachine } from "./fleet.js";
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.getService();
40
- if (!service?.bindRelationship) return undefined;
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?.(ctx);
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 | undefined =
116
- parent.storage === "session"
117
- ? {
118
- transport: "shepherdr",
119
- parent: runtime.local
120
- ? sessionContextPath(parentFile)
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
- ...(routing ? { routing } : {}),
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" ||
@@ -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
 
@@ -0,0 +1,83 @@
1
+ import type {
2
+ ExtensionAPI,
3
+ ExtensionContext,
4
+ } from "@earendil-works/pi-coding-agent";
5
+
6
+ export const WORKER_FLAG = "shepherdr-worker";
7
+ export const PULSE_WORKER_FLAG = "shepherdr-pulse-worker";
8
+ const WORKER_MARKER = "herdr-worker-v1";
9
+ const LEGACY_PULSE_MARKER = "herdr-pulse-worker-v1";
10
+ const WORKER_ROLE_CHANNEL = "shepherdr:worker-role:v1";
11
+
12
+ type SessionManager = ExtensionContext["sessionManager"];
13
+
14
+ /** Optional synchronous event request; consumers need no Shepherdr import. */
15
+ interface WorkerRoleRequest {
16
+ sessionManager: SessionManager;
17
+ reply: (worker: boolean) => void;
18
+ }
19
+
20
+ function markedWorker(manager: SessionManager, pulseOnly = false): boolean {
21
+ const sessionId = manager.getSessionId();
22
+ return manager.getEntries().some((entry) => {
23
+ if (
24
+ entry.type !== "custom" ||
25
+ (entry.customType !== WORKER_MARKER &&
26
+ entry.customType !== LEGACY_PULSE_MARKER)
27
+ )
28
+ return false;
29
+ const data = entry.data as
30
+ | { sessionId?: unknown; pulse?: unknown }
31
+ | undefined;
32
+ return (
33
+ data?.sessionId === sessionId &&
34
+ (!pulseOnly ||
35
+ entry.customType === LEGACY_PULSE_MARKER ||
36
+ data.pulse === true)
37
+ );
38
+ });
39
+ }
40
+
41
+ export function registerWorkerRole(pi: ExtensionAPI) {
42
+ pi.registerFlag(WORKER_FLAG, {
43
+ type: "boolean",
44
+ default: false,
45
+ description: "Run as a supervised Shepherdr worker",
46
+ });
47
+ pi.registerFlag(PULSE_WORKER_FLAG, {
48
+ type: "boolean",
49
+ default: false,
50
+ description: "Run as a detached pulse worker",
51
+ });
52
+ const isWorker = (manager: SessionManager) =>
53
+ pi.getFlag(WORKER_FLAG) === true ||
54
+ pi.getFlag(PULSE_WORKER_FLAG) === true ||
55
+ markedWorker(manager);
56
+ const isPulseWorker = (manager: SessionManager) =>
57
+ pi.getFlag(PULSE_WORKER_FLAG) === true || markedWorker(manager, true);
58
+ // Read the supplied native session directly, even before our session_start.
59
+ pi.events.on(WORKER_ROLE_CHANNEL, (request: unknown) => {
60
+ const value = request as Partial<WorkerRoleRequest> | undefined;
61
+ if (
62
+ typeof value?.reply === "function" &&
63
+ typeof value.sessionManager?.getSessionId === "function" &&
64
+ typeof value.sessionManager.getEntries === "function"
65
+ )
66
+ value.reply(isWorker(value.sessionManager));
67
+ });
68
+ pi.on("before_agent_start", (_event, ctx) => {
69
+ const pulse = pi.getFlag(PULSE_WORKER_FLAG) === true;
70
+ if (
71
+ (pi.getFlag(WORKER_FLAG) === true || pulse) &&
72
+ (!markedWorker(ctx.sessionManager) ||
73
+ (pulse && !markedWorker(ctx.sessionManager, true)))
74
+ ) {
75
+ // Startup entries would prevent fresh Notes family adoption before work.
76
+ pi.appendEntry(WORKER_MARKER, {
77
+ sessionId: ctx.sessionManager.getSessionId(),
78
+ ...(pulse ? { pulse: true } : {}),
79
+ });
80
+ }
81
+ });
82
+ return { isWorker, isPulseWorker };
83
+ }
@@ -4,9 +4,9 @@ import type {
4
4
  ExtensionContext,
5
5
  } from "@earendil-works/pi-coding-agent";
6
6
  import { activityTask } from "./activity.js";
7
- import { allocateAgentName, dispatchAgentWork } from "./agents-work.js";
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,14 +14,13 @@ 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";
21
+ import { PULSE_WORKER_FLAG, type registerWorkerRole } from "./worker-role.js";
21
22
 
22
23
  const ENTRY = "herdr-owned-worker-v1";
23
- const WORKER_MARKER = "herdr-pulse-worker-v1";
24
- const WORKER_FLAG = "shepherdr-pulse-worker";
25
24
  const RUNNER_PROTOCOL = "@howaboua/pi-pulses/runner/v1";
26
25
  // Structural implementation of Pulses' optional runner ABI, without a private-package dependency.
27
26
  interface PulseRun {
@@ -84,28 +83,12 @@ export function registerWorkerService(
84
83
  fleet: AgentFleet,
85
84
  shared: SharedAgentContext,
86
85
  board: AgentBoard,
86
+ workerRole: ReturnType<typeof registerWorkerRole>,
87
87
  ): void {
88
88
  let active: ExtensionContext | undefined;
89
89
  let busy = false;
90
- pi.registerFlag(WORKER_FLAG, {
91
- type: "boolean",
92
- default: false,
93
- description: "Run as a detached pulse worker",
94
- });
95
- const markedWorker = (ctx: ExtensionContext) =>
96
- ctx.sessionManager
97
- .getEntries()
98
- .some(
99
- (entry) =>
100
- entry.type === "custom" &&
101
- entry.customType === WORKER_MARKER &&
102
- (entry.data as { sessionId?: unknown } | undefined)?.sessionId ===
103
- ctx.sessionManager.getSessionId(),
104
- );
105
90
  const isController = (ctx: ExtensionContext) =>
106
- ctx.mode === "tui" &&
107
- pi.getFlag(WORKER_FLAG) !== true &&
108
- !markedWorker(ctx);
91
+ ctx.mode === "tui" && !workerRole.isPulseWorker(ctx.sessionManager);
109
92
  function assertContext(ctx: ExtensionContext) {
110
93
  if (!isController(ctx))
111
94
  throw new Error("Detached workers cannot claim or schedule pulses");
@@ -257,7 +240,6 @@ export function registerWorkerService(
257
240
  if (!profile)
258
241
  throw new Error("General worker profile is unavailable");
259
242
  const profileArgs = profileAgentArgs(profile, {
260
- targetLocal: true,
261
243
  includePrompt: false,
262
244
  });
263
245
  if (
@@ -272,70 +254,79 @@ export function registerWorkerService(
272
254
  );
273
255
  const args = [
274
256
  ...profileArgs,
275
- `--${WORKER_FLAG}`,
257
+ `--${PULSE_WORKER_FLAG}`,
276
258
  ...(worker ? ["--session", worker.sessionPath] : []),
277
259
  ];
278
- const name = await allocateAgentName(runtime, input.title);
279
- const relationship = worker
280
- ? undefined
281
- : shared.spawns.prepareRelationship(ctx, runtime, args);
282
- const sharing =
283
- worker || profile.shareContext === false
284
- ? undefined
285
- : await shared.spawns.prepare(ctx, runtime, name, args);
286
- const boardBinding = worker
287
- ? undefined
288
- : await board.prepare(ctx, runtime, name, args);
289
- const workspace = runtime.local
290
- ? process.env["HERDR_WORKSPACE_ID"]
291
- : undefined;
292
- stage = "launch";
293
- const started = await startAgent(
294
- runtime.client,
295
- {
296
- name,
297
- label: input.title,
298
- cwd: input.cwd,
299
- placement: workspace ? "new_tab" : "new_workspace",
300
- ...(workspace ? { workspace } : {}),
301
- },
302
- runtime.fallbackCwd,
303
- runtime.resolveDirectory,
304
- { agentArgs: args },
305
- );
260
+ const reservation = await reserveAgentName(runtime, input.title);
261
+ const { name } = reservation;
306
262
  try {
307
- const relationshipResult = await relationship?.accept(
308
- started.agent,
263
+ const relationship = worker
264
+ ? undefined
265
+ : shared.spawns.prepareRelationship(ctx, runtime, args);
266
+ const sharing =
267
+ worker || profile.shareContext === false
268
+ ? undefined
269
+ : await shared.spawns.prepare(ctx, runtime, name, args);
270
+ const boardBinding = worker
271
+ ? undefined
272
+ : await board.prepare(ctx, runtime, name, args);
273
+ const workspace = runtime.local
274
+ ? process.env["HERDR_WORKSPACE_ID"]
275
+ : undefined;
276
+ stage = "launch";
277
+ const started = await startAgent(
278
+ runtime.client,
279
+ {
280
+ name,
281
+ label: input.title,
282
+ cwd: input.cwd,
283
+ placement: workspace ? "new_tab" : "new_workspace",
284
+ ...(workspace ? { workspace } : {}),
285
+ },
286
+ runtime.fallbackCwd,
287
+ runtime.resolveDirectory,
288
+ { agentArgs: args },
309
289
  );
310
- await boardBinding?.accept(started.agent);
311
- const sharingResult = await sharing?.accept(started.agent);
312
- for (const warning of [
313
- relationshipResult?.warning,
314
- sharingResult?.warning,
315
- ])
316
- if (warning) ctx.ui.notify(warning, "warning");
317
- assertBranch();
318
- panel = started.agent;
319
- const file = sessionPath(panel);
320
- if (!file || (worker && file !== worker.sessionPath))
321
- throw new Error("Worker did not restore its saved session");
322
- const identity = await runtime.client.machineIdentity();
323
- worker = {
324
- workerId: worker?.workerId ?? crypto.randomUUID(),
325
- pulseId: input.taskId,
326
- runId: "",
327
- parent: ctx.sessionManager.getSessionFile()!,
328
- ...identity,
329
- target: panel.pane_id,
330
- terminal: panel.terminal_id,
331
- sessionPath: file,
332
- cwd: input.cwd,
333
- };
334
- pi.appendEntry(ENTRY, worker);
335
- } catch (error) {
336
- return await rollbackStartedAgent(runtime.client, started, error);
290
+ try {
291
+ const relationshipResult = await relationship?.accept(
292
+ started.agent,
293
+ );
294
+ await boardBinding?.accept(started.agent);
295
+ const sharingResult = await sharing?.accept(started.agent);
296
+ for (const warning of [
297
+ relationshipResult?.warning,
298
+ sharingResult?.warning,
299
+ ])
300
+ if (warning) ctx.ui.notify(warning, "warning");
301
+ assertBranch();
302
+ panel = started.agent;
303
+ const file = sessionPath(panel);
304
+ if (!file || (worker && file !== worker.sessionPath))
305
+ throw new Error("Worker did not restore its saved session");
306
+ const identity = await runtime.client.machineIdentity();
307
+ worker = {
308
+ workerId: worker?.workerId ?? crypto.randomUUID(),
309
+ pulseId: input.taskId,
310
+ runId: "",
311
+ parent: ctx.sessionManager.getSessionFile()!,
312
+ ...identity,
313
+ target: panel.pane_id,
314
+ terminal: panel.terminal_id,
315
+ sessionPath: file,
316
+ cwd: input.cwd,
317
+ };
318
+ pi.appendEntry(ENTRY, worker);
319
+ } catch (error) {
320
+ return await rollbackStartedAgent(
321
+ runtime.client,
322
+ started,
323
+ error,
324
+ );
325
+ }
326
+ stage = "preflight";
327
+ } finally {
328
+ reservation.release();
337
329
  }
338
- stage = "preflight";
339
330
  }
340
331
  if (!worker) throw new Error("Worker ownership is unavailable");
341
332
  const attributed = await attributeAgentPrompt(
@@ -397,12 +388,6 @@ export function registerWorkerService(
397
388
  pi.on("session_start", () => {
398
389
  active = undefined;
399
390
  });
400
- pi.on("before_agent_start", (_event, ctx) => {
401
- if (pi.getFlag(WORKER_FLAG) === true && !markedWorker(ctx))
402
- pi.appendEntry(WORKER_MARKER, {
403
- sessionId: ctx.sessionManager.getSessionId(),
404
- });
405
- });
406
391
  pi.on("resources_discover", (_event, ctx) => {
407
392
  active = ctx;
408
393
  });