@howaboua/pi-shepherdr 0.2.14 → 0.2.16

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 (51) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +40 -33
  3. package/index.ts +16 -26
  4. package/package.json +11 -11
  5. package/src/agents-contract.ts +11 -1
  6. package/src/agents-discovery.ts +21 -7
  7. package/src/agents-focus.ts +242 -0
  8. package/src/agents-spawn.ts +23 -0
  9. package/src/agents-tool.ts +34 -5
  10. package/src/attachment-protocol.ts +7 -3
  11. package/src/attachment-target.ts +3 -1
  12. package/src/attachment.ts +3 -1
  13. package/src/board/host.ts +98 -353
  14. package/src/board/membership.ts +14 -8
  15. package/src/command-config.ts +51 -0
  16. package/src/control-panel-actions.ts +0 -20
  17. package/src/control-panel-items.ts +8 -36
  18. package/src/control-panel-view.ts +2 -11
  19. package/src/control-panel.ts +2 -11
  20. package/src/controller.ts +5 -5
  21. package/src/delivery.ts +0 -33
  22. package/src/herdr-client.ts +39 -6
  23. package/src/messages.ts +61 -6
  24. package/src/monitor-events.ts +24 -2
  25. package/src/monitor-questions.ts +12 -3
  26. package/src/monitor.ts +2 -2
  27. package/src/peer-channel.ts +39 -0
  28. package/src/peer-commands.ts +173 -0
  29. package/src/peer-inbox.ts +218 -55
  30. package/src/remote/shepherdr-channel.mjs +225 -0
  31. package/src/remote/shepherdr-checkpoints.mjs +5 -3
  32. package/src/remote/shepherdr-peer.mjs +151 -22
  33. package/src/remote/shepherdr.mjs +56 -8
  34. package/src/remote-client.ts +115 -11
  35. package/src/settlement.ts +1 -0
  36. package/src/shared-context.ts +104 -1
  37. package/src/types.ts +23 -0
  38. package/src/voice-handoff.ts +177 -0
  39. package/src/board/archive.ts +0 -77
  40. package/src/board/awareness.ts +0 -115
  41. package/src/board/config.ts +0 -121
  42. package/src/board/contract.ts +0 -181
  43. package/src/board/identity.ts +0 -169
  44. package/src/board/paging.ts +0 -55
  45. package/src/board/protocol.ts +0 -73
  46. package/src/board/queries.ts +0 -176
  47. package/src/board/response.ts +0 -56
  48. package/src/board/store.ts +0 -327
  49. package/src/board/tool.ts +0 -23
  50. package/src/board/turns.ts +0 -100
  51. package/src/context-briefing.ts +0 -226
package/src/board/host.ts CHANGED
@@ -3,207 +3,130 @@ import type {
3
3
  ExtensionAPI,
4
4
  ExtensionContext,
5
5
  } from "@earendil-works/pi-coding-agent";
6
- import type { AgentFleet, ConnectedMachine } from "../fleet.js";
7
- import { sessionPath } from "../herdr.js";
8
- import {
9
- requestContext,
10
- sessionContextPath,
11
- } from "../remote/shepherdr-context.mjs";
12
- import { executeArchive } from "./archive.js";
13
- import { BoardAwareness } from "./awareness.js";
14
- import {
15
- type BoardScope,
16
- readBoardConfig,
17
- writeBoardConfig,
18
- } from "./config.js";
19
- import {
20
- agentPath,
21
- type BoardParams,
22
- boardHelp,
23
- parseBoardRequest,
24
- } from "./contract.js";
25
6
  import {
26
7
  binding,
27
8
  children,
28
- members,
29
9
  parseBinding,
30
10
  rootBoardSetting,
31
11
  saveBinding,
32
- saveBoardSetting,
33
12
  saveChild,
34
- sessionBoardSetting,
35
- } from "./identity.js";
13
+ } from "@howaboua/pi-agent-board/integration";
14
+ import {
15
+ type BoardRuntime,
16
+ discoverBoard,
17
+ } from "@howaboua/pi-agent-board/runtime";
18
+ import type { AgentFleet, ConnectedMachine } from "../fleet.js";
19
+ import { sessionPath } from "../herdr.js";
20
+ import { boardBriefing, boardMigrationWarning } from "../messages.js";
21
+ import {
22
+ requestContext,
23
+ sessionContextPath,
24
+ } from "../remote/shepherdr-context.mjs";
36
25
  import { BoardMembership } from "./membership.js";
37
- import { type BoardEnvelope, parseEnvelope } from "./protocol.js";
38
- import { BoardTurns } from "./turns.js";
39
26
 
27
+ /** Private fleet adapter: spawning and attachment policy never enters the shared engine. */
40
28
  export class AgentBoard {
41
- private readonly listeners = new Set<() => void>();
42
- subscribe(listener: () => void): () => void {
43
- this.listeners.add(listener);
44
- return () => {
45
- this.listeners.delete(listener);
46
- };
47
- }
48
- private changed() {
49
- for (const listener of this.listeners) listener();
50
- }
51
29
  readonly membership: BoardMembership;
52
30
  private readonly pi: ExtensionAPI;
53
- private readonly fleet: AgentFleet;
54
- private readonly turns: BoardTurns;
55
- private readonly awareness: BoardAwareness;
56
- private refreshTools: (() => void) | undefined;
57
- private lastSetting: { sessionId: string; enabled: boolean } | undefined;
58
- private configError: string | undefined;
59
- constructor(pi: ExtensionAPI, fleet: AgentFleet) {
31
+ private runtime: BoardRuntime | undefined;
32
+ private constructor(pi: ExtensionAPI, fleet: AgentFleet) {
60
33
  this.pi = pi;
61
- this.fleet = fleet;
62
- this.awareness = new BoardAwareness(pi, (ctx) => this.population(ctx));
63
- this.turns = new BoardTurns(pi, (ctx, request) =>
64
- this.toOwner(ctx, request),
65
- );
66
34
  this.membership = new BoardMembership(
67
35
  pi,
68
- (ctx, request) => this.toOwner(ctx, request),
69
- this.turns.active,
36
+ (ctx, request) => this.owner().toOwner(ctx, request),
37
+ () => this.owner().active,
70
38
  );
71
- pi.on("session_start", (_event, ctx) => this.refresh(ctx));
72
- pi.on("before_agent_start", async (_event, ctx) => {
73
- // Reconcile resumed/offline children before tool/prompt preparation.
74
- const own = binding(ctx);
75
- if (own.upstream) {
76
- try {
77
- const result = await this.toOwner(ctx, {
78
- operation: "board-call",
79
- caller: own,
80
- params: { action: "help" },
81
- requestId: "status",
82
- });
83
- if (
84
- typeof result === "object" &&
85
- result !== null &&
86
- "enabled" in result &&
87
- typeof result.enabled === "boolean" &&
88
- result.enabled !== own.enabled
89
- )
90
- saveBinding(pi, { ...own, enabled: result.enabled });
91
- } catch (error) {
92
- if (own.enabled)
93
- ctx.ui.notify(
94
- `Board owner unavailable: ${String(error)}`,
95
- "warning",
96
- );
39
+ const warned = new Set<string>();
40
+ pi.on("session_start", (_event, ctx) => {
41
+ const sessionId = ctx.sessionManager.getSessionId();
42
+ if (this.runtime || warned.has(sessionId)) return;
43
+ try {
44
+ const setting = rootBoardSetting(ctx);
45
+ if (setting.error) throw new Error(setting.error);
46
+ if (binding(ctx).enabled) {
47
+ warned.add(sessionId);
48
+ ctx.ui.notify(boardMigrationWarning(), "warning");
97
49
  }
50
+ } catch (error) {
51
+ ctx.ui.notify(
52
+ `Could not restore saved board settings: ${String(error)}`,
53
+ "error",
54
+ );
98
55
  }
99
- await this.refresh(ctx);
56
+ });
57
+ discoverBoard(pi, (runtime) => {
58
+ this.runtime = runtime;
59
+ runtime.attach({
60
+ briefing: boardBriefing,
61
+ request: requestContext,
62
+ commitDirectory: (own, directory, caller, request) =>
63
+ this.membership.commitDirectory(own, directory, caller, request),
64
+ routeNotice: (ctx, request, signal) => {
65
+ const child = children(ctx).find(
66
+ (entry) =>
67
+ request.target === entry.binding.agentName ||
68
+ request.target.startsWith(`${entry.binding.agentName}/`),
69
+ );
70
+ if (!child) return Promise.resolve(false);
71
+ return fleet
72
+ .connected(child.machine)
73
+ .client.requestContext(
74
+ sessionContextPath(child.sessionFile),
75
+ request,
76
+ signal,
77
+ );
78
+ },
79
+ propagateEnabled: async (ctx, enabled) => {
80
+ await Promise.all(
81
+ children(ctx).map(async (child) => {
82
+ try {
83
+ await fleet.connected(child.machine).client.requestContext(
84
+ sessionContextPath(child.sessionFile),
85
+ {
86
+ operation: "board-enabled",
87
+ boardId: binding(ctx).boardId,
88
+ enabled,
89
+ },
90
+ AbortSignal.timeout(750),
91
+ );
92
+ } catch {
93
+ /* Resumed children reconcile before their next user turn. */
94
+ }
95
+ }),
96
+ );
97
+ },
98
+ });
100
99
  });
101
100
  }
102
- setToolRefresh(refresh: () => void) {
103
- this.refreshTools = refresh;
101
+ static create(pi: ExtensionAPI, fleet: AgentFleet) {
102
+ return new AgentBoard(pi, fleet);
104
103
  }
105
- private async population(ctx: ExtensionContext) {
106
- const own = binding(ctx);
107
- if (own.upstream) {
108
- const status = await this.toOwner(
109
- ctx,
110
- {
111
- operation: "board-call",
112
- caller: own,
113
- params: { action: "help" },
114
- requestId: "briefing-status",
115
- },
116
- ctx.signal,
104
+ private owner() {
105
+ if (!this.runtime)
106
+ throw new Error(
107
+ "Shared boards are unavailable; use agents for coordination",
117
108
  );
118
- if (
119
- !status ||
120
- typeof status !== "object" ||
121
- !("enabled" in status) ||
122
- typeof status.enabled !== "boolean"
123
- )
124
- throw new Error("Board status unavailable");
125
- if (status.enabled !== own.enabled) {
126
- saveBinding(this.pi, { ...own, enabled: status.enabled });
127
- await this.refresh(ctx);
128
- }
129
- if (!status.enabled) return;
130
- }
131
- return this.execute(
132
- ctx,
133
- { action: "search_posts", limit: 1, max_chars_per_post: 1 },
134
- "briefing",
135
- );
109
+ return this.runtime;
110
+ }
111
+ requireAvailable() {
112
+ this.owner();
136
113
  }
137
114
  enabled(ctx: ExtensionContext | undefined) {
138
- return ctx ? binding(ctx).enabled : false;
115
+ return this.runtime?.enabled(ctx) ?? false;
139
116
  }
140
- async refresh(ctx: ExtensionContext) {
141
- const own = binding(ctx);
142
- this.awareness.refresh(ctx);
143
- const setting = own.upstream ? undefined : rootBoardSetting(ctx);
144
- if (setting?.error && setting.error !== this.configError)
145
- ctx.ui.notify(`Board disabled: ${setting.error}`, "error");
146
- this.configError = setting?.error;
147
- const active = this.pi.getActiveTools().filter((name) => name !== "board");
148
- if (own.enabled) active.push("board");
149
- this.pi.setActiveTools(active);
150
- this.refreshTools?.();
151
- if (!own.enabled) this.turns.active.clear();
152
- const changed =
153
- this.lastSetting?.sessionId !== own.sessionId ||
154
- this.lastSetting.enabled !== own.enabled;
155
- this.lastSetting = { sessionId: own.sessionId, enabled: own.enabled };
156
- this.changed();
157
- if (changed && !own.upstream) await this.propagateEnabled(ctx, own.enabled);
117
+ refresh(ctx: ExtensionContext) {
118
+ return this.owner().refresh(ctx);
158
119
  }
159
- settings(ctx: ExtensionContext) {
160
- const own = binding(ctx);
161
- if (own.upstream)
162
- throw new Error("Change the board setting in the owning root session");
163
- return {
164
- ...readBoardConfig(own.ownerFolder),
165
- session: sessionBoardSetting(ctx),
166
- };
120
+ execute(ctx: ExtensionContext, input: unknown, requestId: string) {
121
+ return this.owner().execute(ctx, input, requestId);
167
122
  }
168
- async setSetting(
169
- ctx: ExtensionContext,
170
- scope: BoardScope,
171
- enabled: boolean | undefined,
172
- ) {
173
- if (!ctx.isIdle())
174
- throw new Error("Change the board setting after this session settles");
175
- const own = binding(ctx);
176
- if (own.upstream)
177
- throw new Error("Change the board setting in the owning root session");
178
- if (scope === "session") saveBoardSetting(this.pi, ctx, enabled);
179
- else writeBoardConfig(own.ownerFolder, scope, enabled);
180
- await this.refresh(ctx);
181
- }
182
- status(ctx: ExtensionContext, includeArchive = true) {
183
- const own = binding(ctx);
184
- const setting = own.upstream ? undefined : rootBoardSetting(ctx);
185
- return `Board ${own.enabled ? "on" : "off"} (${setting?.source ?? "inherited from owner"})${includeArchive ? `. ${own.boardId}\nArchive: ${own.databasePath}` : ""}${setting?.error ? `\n${setting.error}` : ""}`;
123
+ handle(ctx: ExtensionContext, value: unknown, signal?: AbortSignal) {
124
+ return this.owner().handle(ctx, value, signal);
186
125
  }
187
- async execute(ctx: ExtensionContext, input: unknown, requestId: string) {
188
- const params = parseBoardRequest(input);
189
- const caller = binding(ctx);
190
- if (!caller.upstream) {
191
- const setting = rootBoardSetting(ctx);
192
- if (setting.error) throw new Error(setting.error);
193
- }
194
- if (!caller.enabled)
195
- throw new Error(
196
- "Board is off; the user can enable it in /herdr → Settings",
197
- );
198
- return this.toOwner(
199
- ctx,
200
- {
201
- operation: "board-call",
202
- caller,
203
- params,
204
- requestId,
205
- },
206
- ctx.signal,
126
+ promptCatchup(ctx: ExtensionContext) {
127
+ return (
128
+ this.runtime?.promptCatchup(ctx) ??
129
+ Promise.resolve({ content: "", accepted() {} })
207
130
  );
208
131
  }
209
132
  async prepare(
@@ -212,8 +135,8 @@ export class AgentBoard {
212
135
  name: string,
213
136
  args: readonly string[],
214
137
  ) {
138
+ if (!this.enabled(ctx)) return undefined;
215
139
  const own = binding(ctx);
216
- if (!own.enabled) return undefined;
217
140
  if (
218
141
  args.some((arg) =>
219
142
  /^(?:--(?:session(?:-id)?|continue|resume|no-session|fork)(?:=|$)|-[cr]$)/.test(
@@ -259,7 +182,7 @@ export class AgentBoard {
259
182
  throw new Error("Spawned agent did not adopt its board binding");
260
183
  if (ctx.sessionManager.getSessionId() !== own.sessionId)
261
184
  throw new Error("Controller session changed during board binding");
262
- await this.toOwner(ctx, {
185
+ await this.owner().toOwner(ctx, {
263
186
  operation: "board-register",
264
187
  caller: own,
265
188
  member: adopted,
@@ -274,182 +197,4 @@ export class AgentBoard {
274
197
  },
275
198
  };
276
199
  }
277
- async handle(
278
- ctx: ExtensionContext,
279
- value: unknown,
280
- signal?: AbortSignal,
281
- ): Promise<unknown> {
282
- const request = parseEnvelope(value);
283
- const own = binding(ctx);
284
- if (request.operation === "board-bind") {
285
- if (
286
- !ctx.isIdle() ||
287
- ctx.sessionManager
288
- .getEntries()
289
- .some(
290
- (entry) =>
291
- (entry.type === "message" &&
292
- ["user", "assistant"].includes(entry.message.role)) ||
293
- (entry.type === "custom" &&
294
- entry.customType === "shepherdr-board-binding"),
295
- )
296
- )
297
- throw new Error(
298
- "Bind board identity only in a fresh idle child before its first task",
299
- );
300
- const adopted = { ...request.binding, sessionId: own.sessionId };
301
- saveBinding(this.pi, adopted);
302
- await this.refresh(ctx);
303
- return adopted;
304
- }
305
- if (request.operation === "board-enabled") {
306
- if (!own.upstream || request.boardId !== own.boardId)
307
- throw new Error("Invalid board setting route");
308
- saveBinding(this.pi, { ...own, enabled: request.enabled });
309
- await this.refresh(ctx);
310
- await this.propagateEnabled(ctx, request.enabled);
311
- return true;
312
- }
313
- if (request.operation === "board-notify") {
314
- if (!own.enabled || request.boardId !== own.boardId) return false;
315
- if (request.target === own.agentName) return this.turns.deliver(request);
316
- return this.routeNotice(ctx, request, signal);
317
- }
318
- return this.toOwner(ctx, request, signal);
319
- }
320
- private async toOwner(
321
- ctx: ExtensionContext,
322
- request: BoardEnvelope,
323
- signal?: AbortSignal,
324
- ): Promise<unknown> {
325
- const own = binding(ctx);
326
- if (own.upstream) {
327
- try {
328
- return await requestContext(own.upstream, request, signal);
329
- } catch (error) {
330
- if (
331
- error instanceof Error &&
332
- error.message.startsWith("Shared context response was lost")
333
- )
334
- throw new Error(
335
- "Board response lost; a mutation may have completed. Read the channel/thread before retrying",
336
- { cause: error },
337
- );
338
- if (
339
- error instanceof Error &&
340
- error.message.startsWith("Shared context owner is unavailable")
341
- )
342
- throw new Error(
343
- "Board owner unavailable; resume its Pi session and reconnect its machine",
344
- { cause: error },
345
- );
346
- throw error;
347
- }
348
- }
349
- if (!("caller" in request)) throw new Error("Invalid board owner request");
350
- const directory = members(ctx);
351
- const caller = directory.find(
352
- (member) =>
353
- member.sessionId === request.caller.sessionId &&
354
- member.agentName === request.caller.agentName,
355
- );
356
- if (
357
- !caller ||
358
- request.caller.boardId !== own.boardId ||
359
- request.caller.databasePath !== own.databasePath
360
- )
361
- throw new Error("Caller not bound to this board");
362
- if (
363
- request.operation === "board-unregister" ||
364
- request.operation === "board-register"
365
- )
366
- return this.membership.commitDirectory(own, directory, caller, request);
367
- if (request.operation === "board-active") {
368
- if (own.enabled) this.turns.register(caller, request);
369
- return true;
370
- }
371
- if (request.operation !== "board-call")
372
- throw new Error("Invalid board owner operation");
373
- const params = parseBoardRequest(request.params);
374
- if (params.action === "help") return { ...boardHelp, enabled: own.enabled };
375
- if (!own.enabled)
376
- throw new Error(
377
- "Board is off; the user can enable it in /herdr → Settings",
378
- );
379
- const prepared: BoardParams =
380
- params.author === undefined
381
- ? params
382
- : { ...params, author: agentPath(params.author, caller.agentName) };
383
- const active = new Map(this.turns.active);
384
- const result = await executeArchive(
385
- { ...caller, enabled: own.enabled },
386
- directory.map((member) => member.agentName),
387
- prepared,
388
- request.requestId,
389
- );
390
- if ("notice" in result && result.notice) {
391
- for (let start = 0; start < result.recipients.length; start += 16) {
392
- await Promise.all(
393
- result.recipients.slice(start, start + 16).map(async (target) => {
394
- const turn = active.get(target);
395
- if (!turn) return;
396
- try {
397
- await this.handle(
398
- ctx,
399
- {
400
- operation: "board-notify",
401
- boardId: own.boardId,
402
- target,
403
- ...turn,
404
- notice: result.notice,
405
- },
406
- AbortSignal.timeout(750),
407
- );
408
- } catch {
409
- /* Committed posts succeed even when a running turn stops accepting. */
410
- }
411
- }),
412
- );
413
- }
414
- }
415
- return result.value;
416
- }
417
- private async routeNotice(
418
- ctx: ExtensionContext,
419
- request: Extract<BoardEnvelope, { operation: "board-notify" }>,
420
- signal?: AbortSignal,
421
- ) {
422
- const child = children(ctx).find(
423
- (entry) =>
424
- request.target === entry.binding.agentName ||
425
- request.target.startsWith(`${entry.binding.agentName}/`),
426
- );
427
- if (!child) return false;
428
- return this.fleet
429
- .connected(child.machine)
430
- .client.requestContext(
431
- sessionContextPath(child.sessionFile),
432
- request,
433
- signal,
434
- );
435
- }
436
- private async propagateEnabled(ctx: ExtensionContext, enabled: boolean) {
437
- await Promise.all(
438
- children(ctx).map(async (child) => {
439
- try {
440
- await this.fleet.connected(child.machine).client.requestContext(
441
- sessionContextPath(child.sessionFile),
442
- {
443
- operation: "board-enabled",
444
- boardId: binding(ctx).boardId,
445
- enabled,
446
- },
447
- AbortSignal.timeout(750),
448
- );
449
- } catch {
450
- /* Resumed children reconcile with their owner before the next user turn. */
451
- }
452
- }),
453
- );
454
- }
455
200
  }
@@ -3,7 +3,7 @@ import type {
3
3
  ExtensionAPI,
4
4
  ExtensionContext,
5
5
  } from "@earendil-works/pi-coding-agent";
6
- import type { ConnectedMachine } from "../fleet.js";
6
+ import type { BoardEnvelope } from "@howaboua/pi-agent-board/integration";
7
7
  import {
8
8
  type BoardBinding,
9
9
  binding,
@@ -13,8 +13,8 @@ import {
13
13
  saveBinding,
14
14
  saveChild,
15
15
  saveMember,
16
- } from "./identity.js";
17
- import type { BoardEnvelope } from "./protocol.js";
16
+ } from "@howaboua/pi-agent-board/integration";
17
+ import type { ConnectedMachine } from "../fleet.js";
18
18
 
19
19
  function sameMembership(left: BoardBinding, right: BoardBinding) {
20
20
  return isDeepStrictEqual(
@@ -30,26 +30,28 @@ export class BoardMembership {
30
30
  ctx: ExtensionContext,
31
31
  request: BoardEnvelope,
32
32
  ) => Promise<unknown>;
33
- private readonly active: Map<string, unknown>;
33
+ private readonly getActive: () => Map<string, unknown>;
34
34
  constructor(
35
35
  pi: ExtensionAPI,
36
36
  toOwner: (
37
37
  ctx: ExtensionContext,
38
38
  request: BoardEnvelope,
39
39
  ) => Promise<unknown>,
40
- active: Map<string, unknown>,
40
+ getActive: () => Map<string, unknown>,
41
41
  ) {
42
42
  this.pi = pi;
43
43
  this.toOwner = toOwner;
44
- this.active = active;
44
+ this.getActive = getActive;
45
45
  }
46
46
  inspectAttachment(ctx: ExtensionContext) {
47
+ this.getActive();
47
48
  const own = binding(ctx);
48
49
  if (own.upstream || children(ctx).length || members(ctx).length > 1)
49
50
  throw new Error("Target already owns or belongs to a board family");
50
51
  return own;
51
52
  }
52
53
  prepareAttachment(ctx: ExtensionContext, upstream: string, name: string) {
54
+ this.getActive();
53
55
  const own = binding(ctx);
54
56
  if (!own.enabled)
55
57
  throw new Error(
@@ -64,6 +66,7 @@ export class BoardMembership {
64
66
  expected: BoardBinding,
65
67
  desired: BoardBinding,
66
68
  ) {
69
+ this.getActive();
67
70
  if (!ctx.isIdle())
68
71
  throw new Error("Attach a board only after the target settles");
69
72
  const own = binding(ctx);
@@ -83,6 +86,7 @@ export class BoardMembership {
83
86
  adopted: BoardBinding,
84
87
  expected: BoardBinding,
85
88
  ) {
89
+ this.getActive();
86
90
  if (!isDeepStrictEqual(binding(ctx), expected))
87
91
  throw new Error("Controller board changed during attachment");
88
92
  saveBinding(this.pi, expected);
@@ -105,6 +109,7 @@ export class BoardMembership {
105
109
  desired: BoardBinding,
106
110
  previous: BoardBinding,
107
111
  ) {
112
+ this.getActive();
108
113
  if (children(ctx).length)
109
114
  throw new Error(
110
115
  "Detach a board member only when it has no board children",
@@ -117,9 +122,10 @@ export class BoardMembership {
117
122
  )
118
123
  throw new Error("Target board changed before detach");
119
124
  saveBinding(this.pi, previous);
120
- this.active.clear();
125
+ this.getActive().clear();
121
126
  }
122
127
  async unregisterAttachment(ctx: ExtensionContext, member: BoardBinding) {
128
+ this.getActive();
123
129
  const own = binding(ctx);
124
130
  await this.toOwner(ctx, {
125
131
  operation: "board-unregister",
@@ -161,7 +167,7 @@ export class BoardMembership {
161
167
  if (existing && !sameMembership(existing, member))
162
168
  throw new Error("Board member changed before detach");
163
169
  removeMember(this.pi, member);
164
- this.active.delete(member.agentName);
170
+ this.getActive().delete(member.agentName);
165
171
  return true;
166
172
  }
167
173
  if (request.operation === "board-register") {
@@ -0,0 +1,51 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
4
+
5
+ export function commandConfigPath(): string {
6
+ return resolve(getAgentDir(), "pi-shepherdr.json");
7
+ }
8
+
9
+ function object(value: unknown): value is Record<string, unknown> {
10
+ return typeof value === "object" && value !== null && !Array.isArray(value);
11
+ }
12
+
13
+ export function readExtensionCommands(): Record<string, string> {
14
+ const path = commandConfigPath();
15
+ let source: string;
16
+ try {
17
+ source = readFileSync(path, "utf8");
18
+ } catch (error) {
19
+ if (error instanceof Error && "code" in error && error.code === "ENOENT")
20
+ return {};
21
+ throw new Error(`Could not read ${path}: ${String(error)}`, {
22
+ cause: error,
23
+ });
24
+ }
25
+ try {
26
+ const document: unknown = JSON.parse(source);
27
+ if (!object(document)) throw new Error("configuration must be an object");
28
+ const commands = document["extensionCommands"];
29
+ if (commands === undefined) return {};
30
+ if (!object(commands))
31
+ throw new Error("extensionCommands must be an object");
32
+ const entries = Object.entries(commands);
33
+ const validated: [string, string][] = [];
34
+ for (const [name, description] of entries) {
35
+ if (!/^[^\s/]+$/.test(name))
36
+ throw new Error(
37
+ "extension command names must be nonempty, without slashes or whitespace",
38
+ );
39
+ if (typeof description !== "string" || !description.trim())
40
+ throw new Error(
41
+ `extensionCommands.${name} must be a nonempty description`,
42
+ );
43
+ validated.push([name, description]);
44
+ }
45
+ return Object.fromEntries(validated);
46
+ } catch (error) {
47
+ throw new Error(`Could not read ${path}: ${String(error)}`, {
48
+ cause: error,
49
+ });
50
+ }
51
+ }
@@ -1,4 +1,3 @@
1
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
1
  import type { PanelOwners } from "./control-panel-items.js";
3
2
  import { type SshSetupDraft, sshSetupArgs } from "./ssh-setup.js";
4
3
 
@@ -16,7 +15,6 @@ export class PanelActions {
16
15
  busy = false;
17
16
  message: string;
18
17
 
19
- private readonly ctx: ExtensionContext;
20
18
  private readonly options: PanelOptions;
21
19
  private readonly signal: AbortSignal;
22
20
  private readonly current: () => boolean;
@@ -26,7 +24,6 @@ export class PanelActions {
26
24
  private readonly finish: (result: "add" | undefined) => void;
27
25
 
28
26
  constructor(
29
- ctx: ExtensionContext,
30
27
  options: PanelOptions,
31
28
  signal: AbortSignal,
32
29
  message: string,
@@ -36,7 +33,6 @@ export class PanelActions {
36
33
  requestRender: () => void,
37
34
  finish: (result: "add" | undefined) => void,
38
35
  ) {
39
- this.ctx = ctx;
40
36
  this.options = options;
41
37
  this.signal = signal;
42
38
  this.current = current;
@@ -62,22 +58,6 @@ export class PanelActions {
62
58
  if (id === "orchestration") {
63
59
  await this.options.setOrchestration(value === "on", this.signal);
64
60
  this.message = "Guidance saved for this session.";
65
- } else if (
66
- id === "board:session" ||
67
- id === "board:folder" ||
68
- id === "board:global"
69
- ) {
70
- await this.options.board.setSetting(
71
- this.ctx,
72
- id === "board:session"
73
- ? "session"
74
- : id === "board:folder"
75
- ? "folder"
76
- : "global",
77
- value === "inherit" ? undefined : value === "on",
78
- );
79
- this.check();
80
- this.message = "Board setting saved.";
81
61
  } else if (id === "connect" || id.startsWith("machine:"))
82
62
  this.message = await this.options.reconnect(
83
63
  id === "connect" ? undefined : id.slice(8),