pi-agent-swarm 0.1.0 → 0.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-swarm",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Window-manager-native agent swarm for the Pi Coding Agent — every agent runs as a real terminal window under a tiling window manager.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/color.ts CHANGED
@@ -5,7 +5,48 @@ export interface SwarmColor {
5
5
  hex: string;
6
6
  }
7
7
 
8
- export const SWARM_COLORS: readonly SwarmColor[] = [
8
+ export type SwarmColorPaletteName = "muted" | "bright";
9
+
10
+ /**
11
+ * Roster palettes derived from GitHub Linguist language colors (the language bar on
12
+ * github.com), one language per hue slot (see scripts/color-draft.mjs for the visual
13
+ * draft). `muted` is the default low-saturation set; its yellow deliberately matches
14
+ * the footer's ROLE badge (ROLE_BADGE_BACKGROUND) so a yellow session reads as one
15
+ * warm block. `bright` keeps the same slots at GitHub's original vivid tones. Both
16
+ * palettes share slot order, so a seed or stored name keeps its hue when the
17
+ * `colorPalette` setting switches.
18
+ */
19
+ export const SWARM_COLOR_PALETTES: Record<SwarmColorPaletteName, readonly SwarmColor[]> = {
20
+ muted: [
21
+ { name: "red", hex: "#c22d40" }, // Scala
22
+ { name: "orange", hex: "#b07219" }, // Java
23
+ { name: "yellow", hex: "#ffc85a" }, // matches ROLE_BADGE_BACKGROUND in footer.ts
24
+ { name: "green", hex: "#41b883" }, // Vue
25
+ { name: "cyan", hex: "#4298b8" }, // Groovy
26
+ { name: "blue", hex: "#3178c6" }, // TypeScript
27
+ { name: "magenta", hex: "#b83998" }, // Erlang
28
+ { name: "purple", hex: "#8847b9" }, // Elixir
29
+ ],
30
+ bright: [
31
+ { name: "red", hex: "#db5855" }, // Clojure
32
+ { name: "orange", hex: "#dea584" }, // Rust
33
+ { name: "yellow", hex: "#f1e05a" }, // JavaScript
34
+ { name: "green", hex: "#89e051" }, // Shell
35
+ { name: "cyan", hex: "#00add8" }, // Go
36
+ { name: "blue", hex: "#3572a5" }, // Python
37
+ { name: "magenta", hex: "#f34b7d" }, // C++
38
+ { name: "purple", hex: "#a97bff" }, // Kotlin
39
+ ],
40
+ };
41
+
42
+ /** Default roster palette: the muted GitHub-derived set. */
43
+ export const SWARM_COLORS: readonly SwarmColor[] = SWARM_COLOR_PALETTES.muted;
44
+
45
+ /**
46
+ * Pre-palette Tailwind colors. Kept only so hexes assigned by older versions still
47
+ * resolve to a palette name in labels; never used for new assignments.
48
+ */
49
+ const LEGACY_SWARM_COLORS: readonly SwarmColor[] = [
9
50
  { name: "red", hex: "#ef4444" },
10
51
  { name: "orange", hex: "#f97316" },
11
52
  { name: "yellow", hex: "#eab308" },
@@ -16,25 +57,34 @@ export const SWARM_COLORS: readonly SwarmColor[] = [
16
57
  { name: "purple", hex: "#8b5cf6" },
17
58
  ];
18
59
 
60
+ /** The palette behind a `colorPalette` setting value. */
61
+ export function swarmColorPalette(name: SwarmColorPaletteName): readonly SwarmColor[] {
62
+ return SWARM_COLOR_PALETTES[name];
63
+ }
64
+
19
65
  const HEX_RE = /^#[0-9a-f]{6}$/u;
20
- const NAME_TO_HEX = new Map(SWARM_COLORS.map((c) => [c.name, c.hex]));
21
- const HEX_TO_NAME = new Map(SWARM_COLORS.map((c) => [c.hex, c.name]));
66
+ const HEX_TO_NAME = new Map<string, string>();
67
+ for (const palette of [SWARM_COLOR_PALETTES.muted, SWARM_COLOR_PALETTES.bright, LEGACY_SWARM_COLORS]) {
68
+ for (const color of palette) {
69
+ if (!HEX_TO_NAME.has(color.hex)) HEX_TO_NAME.set(color.hex, color.name);
70
+ }
71
+ }
22
72
 
23
73
  /** Accept a palette name or a #rrggbb hex; return a normalized #rrggbb hex, or undefined. */
24
- export function normalizeSwarmColor(value: unknown): string | undefined {
74
+ export function normalizeSwarmColor(value: unknown, palette: readonly SwarmColor[] = SWARM_COLORS): string | undefined {
25
75
  if (typeof value !== "string") return undefined;
26
76
  const trimmed = value.trim().toLowerCase();
27
- const named = NAME_TO_HEX.get(trimmed);
28
- if (named) return named;
77
+ const named = palette.find((color) => color.name === trimmed);
78
+ if (named) return named.hex;
29
79
  if (HEX_RE.test(trimmed)) return trimmed;
30
80
  return undefined;
31
81
  }
32
82
 
33
83
  /** Deterministic palette color from a seed string (stable, no coordination needed). */
34
- export function pickSwarmColor(seed: string): string {
84
+ export function pickSwarmColor(seed: string, palette: readonly SwarmColor[] = SWARM_COLORS): string {
35
85
  let hash = 0;
36
86
  for (let i = 0; i < seed.length; i += 1) hash = (hash * 31 + seed.charCodeAt(i)) >>> 0;
37
- return SWARM_COLORS[hash % SWARM_COLORS.length].hex;
87
+ return palette[hash % palette.length].hex;
38
88
  }
39
89
 
40
90
  /** Palette name for a hex, or undefined when the hex is off-palette. */
package/src/footer.ts ADDED
@@ -0,0 +1,63 @@
1
+ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
+ import { badge, contrastTextColor } from "./color.js";
3
+ import { safeTerminalLine } from "./text.js";
4
+
5
+ /** Uniform warning-cream background for the footer role badge (LEADER and WORKER alike). */
6
+ export const ROLE_BADGE_BACKGROUND = "#ffc85a";
7
+ /**
8
+ * Fraction of the terminal columns the roster badge may occupy. The built-in footer
9
+ * segments (cwd, git, model, context usage) take the rest; their width is not knowable
10
+ * from the extension API, so the budget scales with the window instead of a fixed reserve.
11
+ */
12
+ export const FOOTER_WIDTH_FRACTION = 0.55;
13
+ /** A short session id is the UUID prefix used by MANAGER-<id> naming and /lead matching. */
14
+ export const SHORT_ID_LENGTH = 8;
15
+ /** Column count assumed when the terminal does not report one (headless, piped output). */
16
+ export const DEFAULT_TERMINAL_COLUMNS = 80;
17
+ /** Below this a truncated name fragment carries no recognizable identity; drop to MINIMAL. */
18
+ const MIN_NAME_BUDGET = 8;
19
+ /** The ` ● ` prefix and trailing space around a non-empty name badge. */
20
+ const NAME_BADGE_OVERHEAD = 4;
21
+
22
+ export interface FooterBadgeInput {
23
+ name?: string;
24
+ sessionId: string;
25
+ color: string;
26
+ role: "LEADER" | "WORKER";
27
+ columns: number;
28
+ }
29
+
30
+ /**
31
+ * Build the roster footer badge, degrading through three width tiers:
32
+ * FULL (name + full id + role), COMPACT (name truncated with an ellipsis + 8-column
33
+ * short id + role), and MINIMAL (color dot + role). The role badge always survives:
34
+ * telling LEADER from WORKER at a glance is the badge's primary purpose. The short id
35
+ * is a first-class identifier (MANAGER-<prefix> naming and /lead prefix matching), so
36
+ * unlike a truncated name it carries no ellipsis.
37
+ */
38
+ export function buildRosterBadge(input: FooterBadgeInput): string {
39
+ const name = input.name ? safeTerminalLine(input.name) : "";
40
+ const sessionId = safeTerminalLine(input.sessionId);
41
+ const roleBadge = badge(` ${input.role} `, ROLE_BADGE_BACKGROUND, "#000000");
42
+ const nameBadge = (value: string) =>
43
+ badge(value ? ` ● ${value} ` : " ● ", input.color, contrastTextColor(input.color));
44
+ const available = Math.max(0, Math.floor(input.columns * FOOTER_WIDTH_FRACTION));
45
+
46
+ // FULL: the complete identifier set, unchanged from the original single-mode badge.
47
+ const full = `${nameBadge(name)}${badge(` ${sessionId} `, "#ffffff", "#000000")}${roleBadge}`;
48
+ if (visibleWidth(full) <= available) return full;
49
+
50
+ // COMPACT: shorten the id first (it is recoverable through /lead prefix matching),
51
+ // then give the name whatever budget remains.
52
+ const shortId = [...sessionId].slice(0, SHORT_ID_LENGTH).join("");
53
+ const shortIdBadge = badge(` ${shortId} `, "#ffffff", "#000000");
54
+ const nameBudget = available - visibleWidth(roleBadge) - visibleWidth(shortIdBadge) - NAME_BADGE_OVERHEAD;
55
+ if (nameBudget >= MIN_NAME_BUDGET) {
56
+ const truncated = visibleWidth(name) > nameBudget ? truncateToWidth(name, nameBudget, "…") : name;
57
+ return `${nameBadge(truncated)}${shortIdBadge}${roleBadge}`;
58
+ }
59
+
60
+ // MINIMAL: the swarm-colored dot is the identity; the full name and id stay
61
+ // available through the /swarm menu and message envelopes.
62
+ return `${nameBadge("")}${roleBadge}`;
63
+ }
package/src/menu.ts CHANGED
@@ -1,186 +1,60 @@
1
1
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
2
  import type { MenuDefinition } from "@narumitw/pi-tui-kit";
3
- import type { SwarmSettingsPatch, SwarmSettingsState } from "./settings.js";
3
+ import { SWARM_COLORS, type SwarmColorPaletteName } from "./color.js";
4
4
  import type { SpawnSessionInput, SwarmSnapshot } from "./swarm-controller.js";
5
- import { safeError, safeTerminalLine } from "./text.js";
5
+ import { safeError } from "./text.js";
6
6
 
7
- export interface SwarmMenuState extends SwarmSnapshot, SwarmSettingsState {
8
- settingsPath: string;
9
- }
7
+ export interface SwarmMenuState extends SwarmSnapshot {}
10
8
 
11
9
  export interface SwarmMenuSource {
12
10
  snapshot(signal?: AbortSignal): Promise<SwarmMenuState>;
13
11
  spawn(ctx: ExtensionCommandContext, input: SpawnSessionInput, signal?: AbortSignal): Promise<void>;
14
- start(ctx: ExtensionCommandContext, signal?: AbortSignal): Promise<void>;
15
- join(ctx: ExtensionCommandContext, invite: string, signal?: AbortSignal): Promise<void>;
16
- send(
17
- ctx: ExtensionCommandContext,
18
- options: { targetSessionId: string; text: string; mode: "notify" | "request" },
19
- signal?: AbortSignal,
20
- ): Promise<void>;
21
- updateSettings(patch: SwarmSettingsPatch, signal?: AbortSignal): Promise<void>;
22
- setAcceptsRequests(value: boolean): void;
23
- leave(): Promise<void>;
12
+ rename(ctx: ExtensionCommandContext, name: string, signal?: AbortSignal): Promise<void>;
13
+ setColor(ctx: ExtensionCommandContext, color: string, signal?: AbortSignal): Promise<void>;
14
+ setPalette(ctx: ExtensionCommandContext, palette: SwarmColorPaletteName, signal?: AbortSignal): Promise<void>;
24
15
  }
25
16
 
26
- type Screen =
27
- | "main"
28
- | "join"
29
- | "sessions"
30
- | "invite"
31
- | "requestPolicy"
32
- | "settings"
33
- | "settingsInvalid"
34
- | "status"
35
- | "help"
36
- | "leave";
37
- type Action = "spawn" | "start" | "join" | "send" | "setConfirmation" | "setPinToLeadWorkspace" | "setPolicy" | "leave";
17
+ type Screen = "main";
18
+ type Action = "spawn" | "rename" | "setColor" | "setTheme";
38
19
 
39
20
  const DIRECTION_OPTIONS = ["Right", "Down", "Left", "Up"] as const;
21
+ const PALETTE_OPTIONS = [
22
+ { label: "muted (default, low-saturation GitHub colors)", value: "muted" },
23
+ { label: "bright (vivid GitHub colors)", value: "bright" },
24
+ ] as const satisfies readonly { label: string; value: SwarmColorPaletteName }[];
40
25
 
41
26
  export function createSwarmMenu(source: SwarmMenuSource) {
42
27
  const getState = ({ signal }: { signal?: AbortSignal } = {}) => source.snapshot(signal);
43
28
  const menu: MenuDefinition<SwarmMenuState, Screen, Action> = {
44
29
  start: "main",
45
30
  screens: {
46
- main: ({ state }) => mainScreen(state),
47
- join: () => ({
48
- kind: "input",
49
- title: "Join Pi Agent Swarm",
50
- lines: [
51
- "Paste a local piagentswarm:v1 bearer invite.",
52
- "Anyone holding it can message this Pi session while both processes are running.",
53
- ],
54
- placeholder: "piagentswarm:v1:…",
55
- action: "join",
56
- hint: "back",
57
- }),
58
- sessions: ({ state }) => ({
59
- kind: "browse",
60
- title: "Pi Agent Swarm sessions",
61
- lines: state.peers.length
62
- ? ["Authenticated live sessions in this ephemeral local group."]
63
- : ["No other live sessions are currently authenticated."],
64
- items: state.peers.map((peer) => ({
65
- id: peer.sessionId,
66
- label: safeTerminalLine(peer.name ?? peer.sessionId),
67
- statusText: peer.acceptsRequests ? "requests allowed" : "messages only",
68
- description: safeTerminalLine(peer.cwd),
69
- details: [
70
- `Session: ${safeTerminalLine(peer.sessionId)}`,
71
- `Process: ${peer.pid}`,
72
- ...(peer.launchId ? [`Launch: ${safeTerminalLine(peer.launchId)}`] : []),
73
- ],
74
- })),
75
- viewportSize: "adaptive",
76
- hint: "back",
77
- }),
78
- invite: ({ state }) => ({
79
- kind: "review",
80
- title: "Pi Agent Swarm bearer invite",
81
- lines: [
82
- "Copy this only into another local Pi session you trust.",
83
- "Pi Agent Swarm does not save the invite, but any copied bearer remains usable until its holder discards it.",
84
- ],
85
- content: state.invite ?? "Invite is unavailable.",
86
- format: { kind: "text" },
87
- viewportSize: "adaptive",
88
- hint: "back",
89
- }),
90
- requestPolicy: ({ state }) => ({
91
- kind: "choice",
92
- title: "Incoming agent requests",
93
- lines: [
94
- "Messages always enter context without starting a turn.",
95
- "Allowed requests may spend model tokens and edit this workspace concurrently.",
96
- ],
97
- items: [
98
- { id: "block", label: "Messages only", description: "Do not start remote-request turns" },
99
- { id: "allow", label: "Allow requests", description: "Permit one turn per request" },
100
- ],
101
- action: "setPolicy",
102
- currentItemId: state.acceptsRequests ? "allow" : "block",
103
- initialItemId: state.acceptsRequests ? "allow" : "block",
104
- viewportSize: 4,
105
- hint: "back",
106
- }),
107
- settings: ({ state }) => ({
108
- kind: "settings",
109
- title: "Pi Agent Swarm Settings",
110
- lines: [`User settings · ${safeTerminalLine(state.settingsPath)}`],
31
+ main: () => ({
32
+ kind: "actions",
33
+ title: "Pi Agent Swarm",
34
+ lines: ["Spawn workers and manage this session's badge."],
111
35
  items: [
112
36
  {
113
- id: "confirmSessionLaunch",
114
- label: "Confirm new sessions",
115
- description: "Ask before a new Pi process may spend tokens or edit the workspace.",
116
- currentValue: state.settings.confirmSessionLaunch ? "Ask" : "Skip",
117
- values: ["Ask", "Skip"],
118
- action: "setConfirmation",
37
+ id: "spawn",
38
+ label: "Spawn",
39
+ action: "spawn",
119
40
  },
120
41
  {
121
- id: "pinToLeadWorkspace",
122
- label: "Pin new windows to lead workspace",
123
- description:
124
- "On i3, place new external windows on the lead session's workspace instead of the focused one.",
125
- currentValue: state.settings.pinToLeadWorkspace ? "On" : "Off",
126
- values: ["On", "Off"],
127
- action: "setPinToLeadWorkspace",
42
+ id: "rename",
43
+ label: "Rename",
44
+ action: "rename",
45
+ },
46
+ {
47
+ id: "color",
48
+ label: "Set color",
49
+ action: "setColor",
50
+ },
51
+ {
52
+ id: "theme",
53
+ label: "Set theme",
54
+ action: "setTheme",
128
55
  },
129
56
  ],
130
- }),
131
- settingsInvalid: ({ state }) => ({
132
- kind: "detail",
133
- title: "Pi Agent Swarm Settings · Read only",
134
- lines: [
135
- `Invalid settings file. Fix ${safeTerminalLine(state.settingsPath)} and run /reload. The file will not be overwritten.`,
136
- ...(state.issue ? [`Issue: ${safeTerminalLine(state.issue.message)}`] : []),
137
- ],
138
- hint: "back",
139
- }),
140
- status: ({ state }) => ({
141
- kind: "detail",
142
- title: "Pi Agent Swarm status",
143
- lines: state.connected
144
- ? [
145
- "State: connected",
146
- `Session: ${safeTerminalLine(state.self?.name ?? state.self?.sessionId ?? "unknown")}`,
147
- `Cwd: ${safeTerminalLine(state.self?.cwd ?? "unknown")}`,
148
- `Other live sessions: ${state.peers.length}`,
149
- `Incoming requests: ${state.acceptsRequests ? "allowed" : "blocked"}`,
150
- `Launch confirmation: ${state.settings.confirmSessionLaunch ? "Ask" : "Skip"}`,
151
- `Pin new windows to lead workspace: ${state.settings.pinToLeadWorkspace ? "On" : "Off"}`,
152
- "Delivery acknowledgement means extension acceptance, not remote task completion.",
153
- ]
154
- : [
155
- "State: disconnected",
156
- "No socket, group secret, or background discovery is active.",
157
- `Launch confirmation: ${state.settings.confirmSessionLaunch ? "Ask" : "Skip"}`,
158
- `Pin new windows to lead workspace: ${state.settings.pinToLeadWorkspace ? "On" : "Off"}`,
159
- ],
160
- hint: "back",
161
- }),
162
- help: () => ({
163
- kind: "detail",
164
- title: "Pi Agent Swarm help",
165
- lines: [
166
- "Pi Agent Swarm connects explicit sessions owned by one OS user.",
167
- "New Pi session creates a separate process in an external terminal window and preserves the parent.",
168
- "Notify messages do not start turns, requests require recipient permission, and replies do not auto-trigger another turn.",
169
- "Groups, invites, peer state, and message deduplication are ephemeral.",
170
- ],
171
- hint: "back",
172
- }),
173
- leave: ({ state }) => ({
174
- kind: "review",
175
- title: "Leave Pi Agent Swarm group?",
176
- lines: [
177
- `Other live sessions: ${state.peers.length}`,
178
- "Leaving closes this session's socket and forgets its in-memory bearer invite.",
179
- ],
180
- content: "Already delivered peer messages remain in each Pi session transcript.",
181
- format: { kind: "text" },
182
- confirm: { id: "leave", label: "Leave group", action: "leave" },
183
- hint: "back",
57
+ hint: "close",
184
58
  }),
185
59
  },
186
60
  actions: {
@@ -203,93 +77,34 @@ export function createSwarmMenu(source: SwarmMenuSource) {
203
77
  );
204
78
  return { kind: "close" };
205
79
  },
206
- start: async ({ ctx, signal }) => {
207
- const confirmed = await ctx.ui.confirm(
208
- "Start local Pi Agent Swarm group?",
209
- "This creates one owner-only Unix socket and an ephemeral bearer invite. Incoming requests start blocked.",
210
- { signal },
211
- );
212
- if (!confirmed || signal.aborted) return { kind: "stay" };
213
- await source.start(ctx, signal);
80
+ rename: async ({ ctx, signal, state }) => {
81
+ const name = await ctx.ui.input("Rename session", state.self?.name ?? "Enter a new session name", {
82
+ signal,
83
+ });
84
+ if (name === undefined || !name.trim() || signal.aborted) return { kind: "stay" };
85
+ await source.rename(ctx, name, signal);
214
86
  return { kind: "stay" };
215
87
  },
216
- join: async ({ ctx, signal, value }) => {
217
- if (!value) return { kind: "rejected", error: new Error("Pi Agent Swarm invite is required") };
218
- const confirmed = await ctx.ui.confirm(
219
- "Join local Pi Agent Swarm group?",
220
- "The bearer invite permits local peer messages. Incoming agent requests start blocked.",
221
- { signal },
222
- );
223
- if (!confirmed || signal.aborted) return { kind: "stay" };
224
- await source.join(ctx, value, signal);
225
- return { kind: "to", screen: "main" };
88
+ setColor: async ({ ctx, signal }) => {
89
+ const choice = await ctx.ui.select("Session color", [...SWARM_COLORS.map((color) => color.name)], {
90
+ signal,
91
+ });
92
+ if (!choice || signal.aborted) return { kind: "stay" };
93
+ await source.setColor(ctx, choice, signal);
94
+ return { kind: "stay" };
226
95
  },
227
- send: async ({ ctx, signal, state }) => {
228
- if (state.peers.length === 0) {
229
- return { kind: "rejected", error: new Error("No other live Pi Agent Swarm sessions") };
230
- }
231
- const labels = state.peers.map(
232
- (peer) => `${safeTerminalLine(peer.name ?? peer.sessionId)} · ${safeTerminalLine(peer.sessionId)}`,
233
- );
234
- const selected = await ctx.ui.select("Send to Pi session", labels, { signal });
235
- if (!selected || signal.aborted) return { kind: "stay" };
236
- const peer = state.peers[labels.indexOf(selected)];
237
- if (!peer) return { kind: "rejected", error: new Error("Selected peer is stale") };
238
- const modeLabel = await ctx.ui.select(
239
- "Delivery mode",
240
- ["Message only", "Agent request — may start a paid turn"],
96
+ setTheme: async ({ ctx, signal }) => {
97
+ const choice = await ctx.ui.select(
98
+ "Roster theme (badge palette)",
99
+ PALETTE_OPTIONS.map((option) => option.label),
241
100
  { signal },
242
101
  );
243
- if (!modeLabel || signal.aborted) return { kind: "stay" };
244
- const text = await ctx.ui.input("Message", "Type a bounded message", { signal });
245
- if (!text || signal.aborted) return { kind: "stay" };
246
- await source.send(
247
- ctx,
248
- {
249
- targetSessionId: peer.sessionId,
250
- text,
251
- mode: modeLabel.startsWith("Agent request") ? "request" : "notify",
252
- },
253
- signal,
254
- );
102
+ if (!choice || signal.aborted) return { kind: "stay" };
103
+ const palette = PALETTE_OPTIONS.find((option) => option.label === choice)?.value;
104
+ if (!palette) return { kind: "stay" };
105
+ await source.setPalette(ctx, palette, signal);
255
106
  return { kind: "stay" };
256
107
  },
257
- setConfirmation: ({ ctx, signal, value }) =>
258
- saveSettingsPatch(
259
- source,
260
- ctx,
261
- signal,
262
- { confirmSessionLaunch: value !== "Skip" },
263
- `Confirm new sessions: ${value}.`,
264
- ),
265
- setPinToLeadWorkspace: ({ ctx, signal, value }) =>
266
- saveSettingsPatch(
267
- source,
268
- ctx,
269
- signal,
270
- { pinToLeadWorkspace: value !== "Off" },
271
- `Pin new windows to lead workspace: ${value}.`,
272
- ),
273
- setPolicy: async ({ ctx, signal, itemId }) => {
274
- const allow = itemId === "allow";
275
- if (itemId !== "allow" && itemId !== "block") {
276
- return { kind: "rejected", error: new Error("Pi Agent Swarm request policy is invalid") };
277
- }
278
- if (allow) {
279
- const confirmed = await ctx.ui.confirm(
280
- "Allow incoming agent requests?",
281
- "A trusted invite holder may start paid model turns that can edit the current workspace.",
282
- { signal },
283
- );
284
- if (!confirmed || signal.aborted) return { kind: "stay" };
285
- }
286
- source.setAcceptsRequests(allow);
287
- return { kind: "to", screen: "requestPolicy" };
288
- },
289
- leave: async () => {
290
- await source.leave();
291
- return { kind: "to", screen: "main" };
292
- },
293
108
  },
294
109
  };
295
110
  return { menu, getState };
@@ -314,84 +129,3 @@ export async function showSwarmMenu(
314
129
  },
315
130
  });
316
131
  }
317
-
318
- async function saveSettingsPatch(
319
- source: SwarmMenuSource,
320
- ctx: ExtensionCommandContext,
321
- signal: AbortSignal,
322
- patch: SwarmSettingsPatch,
323
- successMessage: string,
324
- ) {
325
- if (signal.aborted) return { kind: "rejected" as const };
326
- try {
327
- await source.updateSettings(patch, signal);
328
- if (signal.aborted) return { kind: "rejected" as const };
329
- ctx.ui.notify(successMessage, "info");
330
- return { kind: "stay" as const };
331
- } catch (error) {
332
- if (!signal.aborted) {
333
- ctx.ui.notify(`Could not save Pi Agent Swarm settings; the previous value remains: ${safeError(error)}`, "error");
334
- }
335
- return { kind: "rejected" as const };
336
- }
337
- }
338
-
339
- function settingsMenuItem(state: SwarmMenuState) {
340
- return state.issue
341
- ? {
342
- id: "settings",
343
- label: "Settings",
344
- description: "Read-only until the invalid settings file is fixed.",
345
- to: "settingsInvalid" as const,
346
- }
347
- : { id: "settings", label: "Settings", to: "settings" as const };
348
- }
349
-
350
- function mainScreen(state: SwarmMenuState) {
351
- if (!state.connected) {
352
- return {
353
- kind: "actions" as const,
354
- title: "Pi Agent Swarm · disconnected",
355
- lines: ["Local Pi sessions with configured terminal launches and messaging."],
356
- items: [
357
- {
358
- id: "spawn",
359
- label: "New Pi session…",
360
- action: "spawn" as const,
361
- busyLabel: "Launching",
362
- },
363
- { id: "join", label: "Join with invite", to: "join" as const },
364
- { id: "start", label: "Start local group", action: "start" as const },
365
- settingsMenuItem(state),
366
- { id: "status", label: "Status", to: "status" as const },
367
- { id: "help", label: "Help", to: "help" as const },
368
- ],
369
- hint: "close" as const,
370
- };
371
- }
372
- return {
373
- kind: "actions" as const,
374
- title: `Pi Agent Swarm · ${safeTerminalLine(state.self?.name ?? state.self?.sessionId ?? "connected")}`,
375
- lines: [
376
- `${state.peers.length} other live session${state.peers.length === 1 ? "" : "s"} · incoming requests ${state.acceptsRequests ? "allowed" : "blocked"}`,
377
- "Delivery acknowledgement confirms extension acceptance only.",
378
- ],
379
- items: [
380
- {
381
- id: "spawn",
382
- label: "New Pi session…",
383
- action: "spawn" as const,
384
- busyLabel: "Launching",
385
- },
386
- { id: "send", label: "Send message", action: "send" as const },
387
- { id: "sessions", label: "Sessions", to: "sessions" as const },
388
- { id: "invite", label: "Invite another session", to: "invite" as const },
389
- { id: "policy", label: "Request policy", to: "requestPolicy" as const },
390
- settingsMenuItem(state),
391
- { id: "status", label: "Status", to: "status" as const },
392
- { id: "help", label: "Help", to: "help" as const },
393
- { id: "leave", label: "Leave group…", to: "leave" as const },
394
- ],
395
- hint: "close" as const,
396
- };
397
- }