@howaboua/pi-shepherdr 0.2.27 → 0.2.28-core.12.1.gda85fa2e8a0f

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 (112) hide show
  1. package/README.md +48 -48
  2. package/index.ts +7 -1
  3. package/package.json +2 -9
  4. package/src/agent-identity.ts +3 -3
  5. package/src/agents-contract.ts +10 -14
  6. package/src/agents-discovery.ts +34 -54
  7. package/src/agents-focus.ts +23 -35
  8. package/src/agents-spawn.ts +24 -23
  9. package/src/agents-tool.ts +4 -19
  10. package/src/agents-work.ts +4 -3
  11. package/src/attachment-notes.ts +8 -7
  12. package/src/attachment-protocol.ts +3 -2
  13. package/src/attachment-routing.ts +1 -1
  14. package/src/attachment-target.ts +10 -18
  15. package/src/attachment.ts +14 -9
  16. package/src/board/discovery.ts +67 -0
  17. package/src/board/host.ts +93 -63
  18. package/src/board/membership.ts +16 -11
  19. package/src/board/records.ts +185 -0
  20. package/src/close-idle.ts +2 -9
  21. package/src/context-briefing.ts +230 -0
  22. package/src/context-routing.ts +1 -1
  23. package/src/control-panel/index.ts +2 -4
  24. package/src/control-panel/items.ts +1 -11
  25. package/src/control-panel/view.ts +3 -9
  26. package/src/controller.ts +50 -63
  27. package/src/core/AGENTS.md +7 -4
  28. package/src/core/admission-broker.mjs +235 -0
  29. package/src/core/admission-endpoint.ts +180 -0
  30. package/src/core/admission-owner.mjs +52 -0
  31. package/src/core/admission-startup.ts +130 -0
  32. package/src/core/admission.ts +181 -0
  33. package/src/core/agents.ts +102 -0
  34. package/src/core/backend.ts +110 -84
  35. package/src/core/client.ts +16 -0
  36. package/src/core/focus-channel-helper.mjs +6 -27
  37. package/src/core/focus-channel-wire.mjs +9 -6
  38. package/src/core/focus-channel.ts +5 -3
  39. package/src/core/focus-window.ts +15 -4
  40. package/src/core/helper-bootstrap.mjs +70 -0
  41. package/src/core/helper-context.mjs +98 -0
  42. package/src/core/helper-core.mjs +121 -0
  43. package/src/core/machines.ts +30 -0
  44. package/src/core/registration.ts +7 -2
  45. package/src/core/remote-endpoint.ts +80 -74
  46. package/src/core/remote-helper.ts +330 -0
  47. package/src/core/remote-reader.ts +3 -42
  48. package/src/core/remote-service.mjs +239 -0
  49. package/src/core/remote-transport.ts +290 -0
  50. package/src/core/spawn.ts +20 -20
  51. package/src/core/terminal-peer.mjs +57 -0
  52. package/src/core/terminal.ts +4 -2
  53. package/src/delivery.ts +39 -0
  54. package/src/fleet/catalog.ts +16 -58
  55. package/src/fleet/connection.ts +9 -18
  56. package/src/fleet/index.ts +38 -76
  57. package/src/fleet/inspection.ts +9 -22
  58. package/src/fleet/machine.ts +28 -12
  59. package/src/fleet/monitor.ts +8 -29
  60. package/src/fleet/persistence.ts +2 -2
  61. package/src/fleet/reconnect.ts +5 -3
  62. package/src/fleet/setup.ts +6 -16
  63. package/src/launch-contract.ts +0 -3
  64. package/src/launch-location.ts +4 -132
  65. package/src/launch.ts +18 -144
  66. package/src/messages/attachments.ts +1 -1
  67. package/src/messages/attribution.ts +9 -14
  68. package/src/messages/events.ts +5 -9
  69. package/src/messages/focus.ts +2 -7
  70. package/src/messages/guidance.ts +2 -43
  71. package/src/messages/peer-sharing.ts +133 -0
  72. package/src/monitor-events.ts +14 -43
  73. package/src/monitor-extension-messages.ts +5 -6
  74. package/src/monitor-record.ts +4 -0
  75. package/src/monitor-state.ts +1 -101
  76. package/src/monitor.ts +38 -66
  77. package/src/notes-discovery.ts +67 -0
  78. package/src/peer-inbox.ts +21 -27
  79. package/src/remote/context-relay.ts +25 -10
  80. package/src/remote/notes-reader.mjs +67 -0
  81. package/src/remote/shepherdr-channel.mjs +1 -1
  82. package/src/remote/shepherdr-checkpoints.mjs +49 -102
  83. package/src/remote/shepherdr-context.mjs +1 -1
  84. package/src/remote/shepherdr-peer.mjs +19 -24
  85. package/src/remote/shepherdr-session.mjs +18 -7
  86. package/src/saved-context.ts +62 -0
  87. package/src/settlement/collector.ts +29 -9
  88. package/src/settlement/index.ts +35 -6
  89. package/src/shared-context-host.ts +27 -33
  90. package/src/shared-context.ts +44 -15
  91. package/src/spawn-context.ts +11 -3
  92. package/src/spawn-ownership.ts +1 -1
  93. package/src/ssh-setup.ts +40 -73
  94. package/src/types.ts +4 -8
  95. package/src/voice-handoff.ts +1 -1
  96. package/src/widget.ts +7 -2
  97. package/src/worker-ownership.ts +2 -8
  98. package/src/worker-service.ts +6 -14
  99. package/src/core/context-relay.mjs +0 -111
  100. package/src/core/remote-exec.ts +0 -122
  101. package/src/core/remote-helper.mjs +0 -244
  102. package/src/core/remote-relay.ts +0 -191
  103. package/src/core/request.ts +0 -124
  104. package/src/herdr-client.ts +0 -364
  105. package/src/herdr.ts +0 -268
  106. package/src/machine-catalog.ts +0 -83
  107. package/src/monitor-event.ts +0 -84
  108. package/src/remote/client.ts +0 -127
  109. package/src/remote/deployment.ts +0 -179
  110. package/src/remote/focus-channels.ts +0 -89
  111. package/src/remote/shepherdr.mjs +0 -504
  112. package/src/remote/transport.ts +0 -369
package/src/board/host.ts CHANGED
@@ -2,46 +2,46 @@ import type {
2
2
  ExtensionAPI,
3
3
  ExtensionContext,
4
4
  } from "@earendil-works/pi-coding-agent";
5
- import {
6
- binding,
7
- children,
8
- parseBinding,
9
- rootBoardSetting,
10
- saveBinding,
11
- saveChild,
12
- } from "@howaboua/pi-agent-board/integration";
13
- import {
14
- type BoardRuntime,
15
- discoverBoard,
16
- } from "@howaboua/pi-agent-board/runtime";
5
+ import type { BoardRuntime } from "@howaboua/pi-agent-comms/runtime";
6
+ import { sessionPath } from "../core/agents.js";
17
7
  import type { AgentFleet, ConnectedMachine } from "../fleet/index.js";
18
- import { sessionPath } from "../herdr.js";
19
- import { boardBriefing, boardMigrationWarning } from "../messages/guidance.js";
8
+ import { boardMigrationWarning } from "../messages/guidance.js";
20
9
  import {
21
10
  requestContext,
22
11
  sessionContextPath,
23
12
  } from "../remote/shepherdr-context.mjs";
13
+ import { discoverBoard } from "./discovery.js";
24
14
  import { BoardMembership } from "./membership.js";
15
+ import {
16
+ binding,
17
+ children,
18
+ parseBinding,
19
+ saveBinding,
20
+ saveChild,
21
+ } from "./records.js";
25
22
 
26
23
  /** Private fleet adapter: spawning and attachment policy never enters the shared engine. */
27
24
  export class AgentBoard {
28
25
  readonly membership: BoardMembership;
29
26
  private readonly pi: ExtensionAPI;
30
27
  private runtime: BoardRuntime | undefined;
28
+ private failure: Error | undefined;
29
+ private context: ExtensionContext | undefined;
31
30
  private constructor(pi: ExtensionAPI, fleet: AgentFleet) {
32
31
  this.pi = pi;
33
32
  this.membership = new BoardMembership(
34
33
  pi,
35
34
  (ctx, request) => this.owner().toOwner(ctx, request),
36
35
  () => this.owner().active,
36
+ (ctx) => this.binding(ctx),
37
37
  );
38
38
  const warned = new Set<string>();
39
39
  pi.on("session_start", (_event, ctx) => {
40
+ this.context = ctx;
40
41
  const sessionId = ctx.sessionManager.getSessionId();
42
+ if (this.failure) ctx.ui.notify(this.failure.message, "error");
41
43
  if (this.runtime || warned.has(sessionId)) return;
42
44
  try {
43
- const setting = rootBoardSetting(ctx);
44
- if (setting.error) throw new Error(setting.error);
45
45
  if (binding(ctx).enabled) {
46
46
  warned.add(sessionId);
47
47
  ctx.ui.notify(boardMigrationWarning(), "warning");
@@ -53,59 +53,69 @@ export class AgentBoard {
53
53
  );
54
54
  }
55
55
  });
56
- discoverBoard(pi, (runtime) => {
57
- this.runtime = runtime;
58
- runtime.attach({
59
- briefing: (member, population) =>
60
- boardBriefing(member, population, runtime.gptPromptMode),
61
- request: requestContext,
62
- commitDirectory: (own, directory, caller, request) =>
63
- this.membership.commitDirectory(own, directory, caller, request),
64
- routeNotice: async (ctx, request, signal) => {
65
- const next = request.route?.[0] ?? request.sessionId;
66
- const child = children(ctx).find(
67
- (entry) => entry.binding.sessionId === next,
68
- );
69
- if (!child) return false;
70
- return fleet.connected(child.machine).client.requestContext(
71
- sessionContextPath(child.sessionFile),
72
- {
73
- ...request,
74
- ...(request.route ? { route: request.route.slice(1) } : {}),
75
- },
76
- signal,
77
- );
78
- },
79
- propagateEnabled: async (ctx, enabled) => {
80
- let boardId: string | undefined;
81
- await Promise.all(
82
- children(ctx).map(async (child) => {
83
- try {
84
- await fleet.connected(child.machine).client.requestContext(
85
- sessionContextPath(child.sessionFile),
86
- {
87
- operation: "board-enabled",
88
- boardId: (boardId ??= binding(ctx).boardId),
89
- enabled,
90
- },
91
- AbortSignal.timeout(750),
92
- );
93
- } catch {
94
- /* Resumed children reconcile before their next user turn. */
95
- }
96
- }),
97
- );
98
- },
99
- });
56
+ pi.on("session_shutdown", () => {
57
+ this.context = undefined;
100
58
  });
59
+ discoverBoard(
60
+ pi,
61
+ (runtime) => {
62
+ runtime.attach({
63
+ request: requestContext,
64
+ commitDirectory: (own, directory, caller, request) =>
65
+ this.membership.commitDirectory(own, directory, caller, request),
66
+ routeNotice: async (ctx, request, signal) => {
67
+ const next = request.route?.[0] ?? request.sessionId;
68
+ const child = children(ctx).find(
69
+ (entry) => entry.binding.sessionId === next,
70
+ );
71
+ if (!child) return false;
72
+ return fleet.connected(child.machine).client.requestContext(
73
+ sessionContextPath(child.sessionFile),
74
+ {
75
+ ...request,
76
+ ...(request.route ? { route: request.route.slice(1) } : {}),
77
+ },
78
+ signal,
79
+ );
80
+ },
81
+ propagateEnabled: async (ctx, enabled) => {
82
+ let boardId: string | undefined;
83
+ await Promise.all(
84
+ children(ctx).map(async (child) => {
85
+ try {
86
+ await fleet.connected(child.machine).client.requestContext(
87
+ sessionContextPath(child.sessionFile),
88
+ {
89
+ operation: "board-enabled",
90
+ boardId: (boardId ??= this.binding(ctx).boardId),
91
+ enabled,
92
+ },
93
+ AbortSignal.timeout(750),
94
+ );
95
+ } catch {
96
+ /* Resumed children reconcile before their next user turn. */
97
+ }
98
+ }),
99
+ );
100
+ },
101
+ });
102
+ this.runtime = runtime;
103
+ this.failure = undefined;
104
+ },
105
+ (error) => {
106
+ this.failure = error;
107
+ this.context?.ui.notify(error.message, "error");
108
+ },
109
+ );
101
110
  }
102
111
  static create(pi: ExtensionAPI, fleet: AgentFleet) {
103
112
  return new AgentBoard(pi, fleet);
104
113
  }
105
114
  private owner() {
115
+ if (this.failure) throw this.failure;
106
116
  if (!this.runtime)
107
117
  throw new Error(
108
- "Shared boards are unavailable; use agents for coordination",
118
+ "Shared boards are unavailable. Load Agent Comms or Agent Board and reload Pi. Other agent operations remain available.",
109
119
  );
110
120
  return this.runtime;
111
121
  }
@@ -115,6 +125,11 @@ export class AgentBoard {
115
125
  enabled(ctx: ExtensionContext | undefined) {
116
126
  return this.runtime?.enabled(ctx) ?? false;
117
127
  }
128
+ binding(ctx: ExtensionContext) {
129
+ const own = binding(ctx);
130
+ // Configuration/defaults belong to the loaded owner, not this protocol reader.
131
+ return own.upstream ? own : { ...own, enabled: this.enabled(ctx) };
132
+ }
118
133
  refresh(ctx: ExtensionContext) {
119
134
  return this.owner().refresh(ctx);
120
135
  }
@@ -122,6 +137,16 @@ export class AgentBoard {
122
137
  return this.owner().execute(ctx, input, requestId);
123
138
  }
124
139
  handle(ctx: ExtensionContext, value: unknown, signal?: AbortSignal) {
140
+ // Only a missing owner can decline a fresh bind without mutating state.
141
+ if (
142
+ !this.runtime &&
143
+ !this.failure &&
144
+ value &&
145
+ typeof value === "object" &&
146
+ "operation" in value &&
147
+ value.operation === "board-bind"
148
+ )
149
+ return null;
125
150
  return this.owner().handle(ctx, value, signal);
126
151
  }
127
152
  promptCatchup(ctx: ExtensionContext) {
@@ -137,7 +162,7 @@ export class AgentBoard {
137
162
  args: readonly string[],
138
163
  ) {
139
164
  if (!this.enabled(ctx)) return undefined;
140
- const own = { ...binding(ctx), enabled: true };
165
+ const own = { ...this.binding(ctx), enabled: true };
141
166
  if (
142
167
  args.some((arg) =>
143
168
  /^(?:--(?:session(?:-id)?|continue|resume|no-session|fork)(?:=|$)|-[cr]$)/.test(
@@ -169,6 +194,11 @@ export class AgentBoard {
169
194
  sessionContextPath(sessionFile),
170
195
  { operation: "board-bind", binding: prepared },
171
196
  );
197
+ if (result === null)
198
+ return {
199
+ warning:
200
+ "Spawned without shared Board: the target needs Agent Board or Agent Comms",
201
+ };
172
202
  const adopted = parseBinding(result);
173
203
  if (
174
204
  adopted.boardId !== own.boardId ||
@@ -193,7 +223,7 @@ export class AgentBoard {
193
223
  machine: runtime.machine,
194
224
  sessionFile,
195
225
  });
196
- return adopted.agentName;
226
+ return { agentName: adopted.agentName };
197
227
  },
198
228
  };
199
229
  }
@@ -3,10 +3,9 @@ import type {
3
3
  ExtensionAPI,
4
4
  ExtensionContext,
5
5
  } from "@earendil-works/pi-coding-agent";
6
- import type { BoardEnvelope } from "@howaboua/pi-agent-board/integration";
6
+ import type { BoardEnvelope } from "@howaboua/pi-agent-comms/integration";
7
7
  import {
8
8
  type BoardBinding,
9
- binding,
10
9
  children,
11
10
  members,
12
11
  parseBinding,
@@ -14,7 +13,7 @@ import {
14
13
  saveBinding,
15
14
  saveChild,
16
15
  saveMember,
17
- } from "@howaboua/pi-agent-board/integration";
16
+ } from "../board/records.js";
18
17
  import type { ConnectedMachine } from "../fleet/index.js";
19
18
 
20
19
  function sameMembership(left: BoardBinding, right: BoardBinding) {
@@ -38,6 +37,7 @@ export class BoardMembership {
38
37
  ctx: ExtensionContext,
39
38
  request: BoardEnvelope,
40
39
  ) => Promise<unknown>;
40
+ private readonly getBinding: (ctx: ExtensionContext) => BoardBinding;
41
41
  private readonly getActive: () => Map<string, unknown>;
42
42
  constructor(
43
43
  pi: ExtensionAPI,
@@ -46,14 +46,16 @@ export class BoardMembership {
46
46
  request: BoardEnvelope,
47
47
  ) => Promise<unknown>,
48
48
  getActive: () => Map<string, unknown>,
49
+ getBinding: (ctx: ExtensionContext) => BoardBinding,
49
50
  ) {
50
51
  this.pi = pi;
52
+ this.getBinding = getBinding;
51
53
  this.toOwner = toOwner;
52
54
  this.getActive = getActive;
53
55
  }
54
56
  inspectAttachment(ctx: ExtensionContext) {
55
57
  this.getActive();
56
- const own = binding(ctx);
58
+ const own = this.getBinding(ctx);
57
59
  if (own.upstream || children(ctx).length || members(ctx).length > 1)
58
60
  throw new Error("Target already owns or belongs to a board family");
59
61
  return own;
@@ -64,7 +66,7 @@ export class BoardMembership {
64
66
  targetSessionId: string,
65
67
  ) {
66
68
  this.getActive();
67
- const own = binding(ctx);
69
+ const own = this.getBinding(ctx);
68
70
  if (!own.enabled)
69
71
  throw new Error(
70
72
  "Enable the controller's board before attaching a member",
@@ -88,7 +90,7 @@ export class BoardMembership {
88
90
  this.getActive();
89
91
  if (!ctx.isIdle())
90
92
  throw new Error("Attach a board only after the target settles");
91
- const own = binding(ctx);
93
+ const own = this.getBinding(ctx);
92
94
  const adopted = adoptedBinding(desired, own.sessionId);
93
95
  if (isDeepStrictEqual(own, adopted)) return adopted;
94
96
  if (!sameMembership(this.inspectAttachment(ctx), expected))
@@ -106,7 +108,7 @@ export class BoardMembership {
106
108
  expected: BoardBinding,
107
109
  ) {
108
110
  this.getActive();
109
- if (!sameMembership(binding(ctx), expected))
111
+ if (!sameMembership(this.getBinding(ctx), expected))
110
112
  throw new Error("Controller board changed during attachment");
111
113
  saveBinding(this.pi, parseBinding(expected));
112
114
  await this.toOwner(ctx, {
@@ -114,7 +116,7 @@ export class BoardMembership {
114
116
  caller: parseBinding(expected),
115
117
  member: parseBinding({ ...adopted, parentSessionId: expected.sessionId }),
116
118
  });
117
- if (!sameMembership(binding(ctx), expected))
119
+ if (!sameMembership(this.getBinding(ctx), expected))
118
120
  throw new Error("Controller board changed during attachment");
119
121
  saveChild(this.pi, {
120
122
  parentSessionId: expected.sessionId,
@@ -137,7 +139,10 @@ export class BoardMembership {
137
139
  "Detach a board member only when it has no board children",
138
140
  );
139
141
  if (
140
- !sameMembership(binding(ctx), adoptedBinding(desired, previous.sessionId))
142
+ !sameMembership(
143
+ this.getBinding(ctx),
144
+ adoptedBinding(desired, previous.sessionId),
145
+ )
141
146
  )
142
147
  throw new Error("Target board changed before detach");
143
148
  saveBinding(this.pi, previous);
@@ -145,13 +150,13 @@ export class BoardMembership {
145
150
  }
146
151
  async unregisterAttachment(ctx: ExtensionContext, member: BoardBinding) {
147
152
  this.getActive();
148
- const own = binding(ctx);
153
+ const own = this.getBinding(ctx);
149
154
  await this.toOwner(ctx, {
150
155
  operation: "board-unregister",
151
156
  caller: own,
152
157
  member: parseBinding({ ...member, parentSessionId: own.sessionId }),
153
158
  });
154
- if (!sameMembership(binding(ctx), own))
159
+ if (!sameMembership(this.getBinding(ctx), own))
155
160
  throw new Error("Controller board changed during detach");
156
161
  removeMember(this.pi, member);
157
162
  }
@@ -0,0 +1,185 @@
1
+ import { resolve } from "node:path";
2
+ import type {
3
+ ExtensionAPI,
4
+ ExtensionContext,
5
+ } from "@earendil-works/pi-coding-agent";
6
+ import { type Static, Type } from "typebox";
7
+ import { Check } from "typebox/value";
8
+
9
+ // These are persisted transport records, not a Board engine or activation owner.
10
+
11
+ const nativeId = Type.String({ pattern: "^[a-zA-Z0-9_.-]+$" });
12
+ export const BindingSchema = Type.Object(
13
+ {
14
+ protocol: Type.Literal(1),
15
+ boardId: nativeId,
16
+ rootSessionId: nativeId,
17
+ sessionId: nativeId,
18
+ agentName: Type.String({
19
+ pattern: "^/[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_-]+)*$",
20
+ }),
21
+ legacyAgentName: Type.Optional(
22
+ Type.String({ pattern: "^/root(?:/[a-zA-Z0-9_-]+)*$" }),
23
+ ),
24
+ parentSessionId: Type.Optional(nativeId),
25
+ ownerFolder: Type.String({ minLength: 1 }),
26
+ databasePath: Type.String({ minLength: 1 }),
27
+ enabled: Type.Boolean(),
28
+ upstream: Type.Optional(Type.String({ minLength: 1 })),
29
+ },
30
+ { additionalProperties: false },
31
+ );
32
+ export type BoardBinding = Static<typeof BindingSchema>;
33
+ const ChildSchema = Type.Object({
34
+ parentSessionId: nativeId,
35
+ binding: BindingSchema,
36
+ machine: Type.String(),
37
+ sessionFile: Type.String({ minLength: 1 }),
38
+ });
39
+ export type BoardChild = Static<typeof ChildSchema>;
40
+ const BINDING = "shepherdr-board-binding";
41
+ const MEMBER = "shepherdr-board-member";
42
+ const CHILD = "shepherdr-board-child";
43
+ const SETTING = "shepherdr-board-setting";
44
+ const REMOVED = "shepherdr-board-removed";
45
+ const SettingSchema = Type.Object({
46
+ sessionId: nativeId,
47
+ enabled: Type.Union([Type.Boolean(), Type.Null()]),
48
+ });
49
+
50
+ function sessionBoardSetting(ctx: ExtensionContext): boolean | undefined {
51
+ let enabled: boolean | undefined;
52
+ for (const entry of ctx.sessionManager.getEntries()) {
53
+ if (entry.type !== "custom" || entry.customType !== SETTING) continue;
54
+ if (!Check(SettingSchema, entry.data))
55
+ throw new Error("Invalid saved board setting");
56
+ const value = entry.data as Static<typeof SettingSchema>;
57
+ if (value.sessionId === ctx.sessionManager.getSessionId())
58
+ enabled = value.enabled ?? undefined;
59
+ }
60
+ return enabled;
61
+ }
62
+
63
+ export function parseBinding(value: unknown): BoardBinding {
64
+ if (!Check(BindingSchema, value))
65
+ throw new Error("Invalid Shepherdr board binding");
66
+ const saved = value as BoardBinding;
67
+ assertSessionIdentity(saved.sessionId, saved.rootSessionId);
68
+ const agentName = `/${saved.sessionId}`;
69
+ if (saved.agentName !== agentName && !/^\/root(?:\/|$)/.test(saved.agentName))
70
+ throw new Error("Board agent reference does not match its native session");
71
+ return {
72
+ ...saved,
73
+ agentName,
74
+ ...(saved.agentName !== agentName && !saved.legacyAgentName
75
+ ? { legacyAgentName: saved.agentName }
76
+ : {}),
77
+ };
78
+ }
79
+ export function binding(ctx: ExtensionContext): BoardBinding {
80
+ const sessionId = ctx.sessionManager.getSessionId();
81
+ assertSessionIdentity(sessionId);
82
+ let saved: BoardBinding | undefined;
83
+ for (const entry of ctx.sessionManager.getEntries()) {
84
+ if (entry.type !== "custom" || entry.customType !== BINDING) continue;
85
+ const candidate = parseBinding(entry.data);
86
+ if (candidate.sessionId === sessionId) saved = candidate;
87
+ }
88
+ const ownerFolder = resolve(ctx.sessionManager.getCwd());
89
+ if (saved?.upstream) return saved;
90
+ return {
91
+ ...(saved ?? {
92
+ protocol: 1,
93
+ sessionId,
94
+ rootSessionId: sessionId,
95
+ boardId: sessionId,
96
+ agentName: `/${sessionId}`,
97
+ ownerFolder,
98
+ databasePath: resolve(ownerFolder, ".pi", "agent-message-board.sqlite"),
99
+ enabled: false,
100
+ }),
101
+ // The loaded Board owner supplies configuration/defaults through AgentBoard.binding.
102
+ enabled: sessionBoardSetting(ctx) ?? false,
103
+ };
104
+ }
105
+ function assertSessionIdentity(...ids: string[]) {
106
+ if (ids.includes("root"))
107
+ throw new Error(
108
+ "Pi session ID root conflicts with the legacy /root reference; start a session with another ID",
109
+ );
110
+ }
111
+ export function saveBinding(pi: ExtensionAPI, value: BoardBinding) {
112
+ pi.appendEntry(BINDING, value);
113
+ }
114
+ export function members(ctx: ExtensionContext): BoardBinding[] {
115
+ const own = binding(ctx);
116
+ const found = new Map([[own.sessionId, own]]);
117
+ for (const entry of ctx.sessionManager.getEntries()) {
118
+ if (entry.type === "custom" && entry.customType === REMOVED) {
119
+ const value = parseBinding(entry.data);
120
+ if (value.boardId === own.boardId) found.delete(value.sessionId);
121
+ continue;
122
+ }
123
+ if (entry.type !== "custom" || entry.customType !== MEMBER) continue;
124
+ const value = parseBinding(entry.data);
125
+ if (value.rootSessionId === own.sessionId && value.boardId === own.boardId)
126
+ found.set(value.sessionId, value);
127
+ }
128
+ const directory = [...found.values()];
129
+ return directory.map((member) => {
130
+ if (member.parentSessionId || !member.legacyAgentName) return member;
131
+ const path = member.legacyAgentName;
132
+ const parent = directory.find(
133
+ (entry) =>
134
+ (entry.legacyAgentName ??
135
+ (entry.sessionId === own.rootSessionId ? "/root" : undefined)) ===
136
+ path.slice(0, path.lastIndexOf("/")),
137
+ );
138
+ return parent ? { ...member, parentSessionId: parent.sessionId } : member;
139
+ });
140
+ }
141
+ export function saveMember(pi: ExtensionAPI, value: BoardBinding) {
142
+ pi.appendEntry(MEMBER, value);
143
+ }
144
+ export function children(ctx: ExtensionContext): BoardChild[] {
145
+ const own = binding(ctx);
146
+ const found = new Map<string, BoardChild>();
147
+ for (const entry of ctx.sessionManager.getEntries()) {
148
+ if (entry.type === "custom" && entry.customType === REMOVED) {
149
+ const value = parseBinding(entry.data);
150
+ if (value.boardId === own.boardId) found.delete(value.sessionId);
151
+ continue;
152
+ }
153
+ if (entry.type !== "custom" || entry.customType !== CHILD) continue;
154
+ if (!Check(ChildSchema, entry.data))
155
+ throw new Error("Invalid saved board child route");
156
+ const value = entry.data as BoardChild;
157
+ if (
158
+ value.parentSessionId === own.sessionId &&
159
+ value.binding.boardId === own.boardId
160
+ )
161
+ found.set(value.binding.sessionId, {
162
+ ...value,
163
+ binding: parseBinding(value.binding),
164
+ });
165
+ }
166
+ return [...found.values()];
167
+ }
168
+ export function saveChild(pi: ExtensionAPI, value: BoardChild) {
169
+ pi.appendEntry(CHILD, value);
170
+ }
171
+ export function removeMember(pi: ExtensionAPI, value: BoardBinding) {
172
+ pi.appendEntry(REMOVED, value);
173
+ }
174
+
175
+ export { parseBinding as canonicalBoardBinding };
176
+
177
+ export function isBoardEnvelope(value: unknown): boolean {
178
+ return (
179
+ !!value &&
180
+ typeof value === "object" &&
181
+ "operation" in value &&
182
+ typeof value.operation === "string" &&
183
+ value.operation.startsWith("board-")
184
+ );
185
+ }
package/src/close-idle.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import { CoreConnection } from "./core/backend.js";
2
+ import { getSnapshot, sessionPath } from "./core/agents.js";
3
3
  import type { AgentFleet } from "./fleet/index.js";
4
- import { getSnapshot, sessionPath } from "./herdr.js";
5
4
  import { spawnedChildren } from "./spawn-ownership.js";
6
5
 
7
6
  export async function closeIdleChildren(
@@ -46,13 +45,7 @@ export async function closeIdleChildren(
46
45
  panel.agent !== "pi" ||
47
46
  panel.terminal_id !== child.terminal ||
48
47
  sessionPath(panel) !== child.sessionFile ||
49
- (runtime.local &&
50
- panel.pane_id ===
51
- process.env[
52
- runtime.client instanceof CoreConnection
53
- ? "HC_TERMINAL_ID"
54
- : "HERDR_PANE_ID"
55
- ]) ||
48
+ (runtime.local && panel.pane_id === process.env["HC_TERMINAL_ID"]) ||
56
49
  snapshot.agents.some(
57
50
  (value) =>
58
51
  value.pane_id !== child.pane &&