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/dist/index.ts CHANGED
@@ -1,63 +1,17 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
2
  // @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
+ badge,
5
+ contrastTextColor,
4
6
  normalizeOptionalText,
7
+ normalizeSwarmColor,
8
+ pickSwarmColor,
5
9
  safeError,
6
10
  safeTerminalLine,
7
- safeTerminalText
8
- } from "./chunks/chunk-XD4GFZPB.ts";
9
-
10
- // src/color.ts
11
- import { getTerminalColorMode, parseColor, styleText } from "@earendil-works/pi-tui";
12
- var SWARM_COLORS = [
13
- { name: "red", hex: "#ef4444" },
14
- { name: "orange", hex: "#f97316" },
15
- { name: "yellow", hex: "#eab308" },
16
- { name: "green", hex: "#22c55e" },
17
- { name: "cyan", hex: "#06b6d4" },
18
- { name: "blue", hex: "#3b82f6" },
19
- { name: "magenta", hex: "#d946ef" },
20
- { name: "purple", hex: "#8b5cf6" }
21
- ];
22
- var HEX_RE = /^#[0-9a-f]{6}$/u;
23
- var NAME_TO_HEX = new Map(SWARM_COLORS.map((c) => [c.name, c.hex]));
24
- var HEX_TO_NAME = new Map(SWARM_COLORS.map((c) => [c.hex, c.name]));
25
- function normalizeSwarmColor(value) {
26
- if (typeof value !== "string") return void 0;
27
- const trimmed = value.trim().toLowerCase();
28
- const named = NAME_TO_HEX.get(trimmed);
29
- if (named) return named;
30
- if (HEX_RE.test(trimmed)) return trimmed;
31
- return void 0;
32
- }
33
- function pickSwarmColor(seed) {
34
- let hash = 0;
35
- for (let i = 0; i < seed.length; i += 1) hash = hash * 31 + seed.charCodeAt(i) >>> 0;
36
- return SWARM_COLORS[hash % SWARM_COLORS.length].hex;
37
- }
38
- function swarmColorName(hex) {
39
- return HEX_TO_NAME.get(hex.toLowerCase());
40
- }
41
- function contrastTextColor(bgHex) {
42
- const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/u.exec(bgHex.toLowerCase());
43
- if (!match) return "#ffffff";
44
- const [r, g, b] = match.slice(1).map((pair) => Number.parseInt(pair, 16));
45
- const channel = (value) => {
46
- const s = value / 255;
47
- return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
48
- };
49
- const luminance = 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
50
- const onBlack = (luminance + 0.05) / 0.05;
51
- const onWhite = 1.05 / (luminance + 0.05);
52
- return onBlack >= onWhite ? "#000000" : "#ffffff";
53
- }
54
- function badge(text, bgHex, fgHex) {
55
- try {
56
- return styleText(text, { fg: parseColor(fgHex), bg: parseColor(bgHex) }, getTerminalColorMode());
57
- } catch {
58
- return text;
59
- }
60
- }
11
+ safeTerminalText,
12
+ swarmColorName,
13
+ swarmColorPalette
14
+ } from "./chunks/chunk-77JHO3GV.ts";
61
15
 
62
16
  // src/protocol.ts
63
17
  import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
@@ -692,11 +646,13 @@ import { getAgentDir } from "@earendil-works/pi-coding-agent";
692
646
  var SWARM_SETTINGS_FILE = "pi-agent-swarm.json";
693
647
  var MAX_SWARM_SETTINGS_BYTES = 64 * 1024;
694
648
  var DEFAULT_SWARM_SETTINGS = Object.freeze({
649
+ colorPalette: "muted",
695
650
  confirmSessionLaunch: true,
696
651
  externalCommand: "alacritty -e",
697
652
  pinToLeadWorkspace: false
698
653
  });
699
654
  var SETTING_FIELDS = [
655
+ "colorPalette",
700
656
  "confirmSessionLaunch",
701
657
  "externalCommand",
702
658
  "pinToLeadWorkspace"
@@ -709,6 +665,11 @@ function normalizeSwarmSettingsDocument(value) {
709
665
  if (!isRecord2(value)) return void 0;
710
666
  const settings = { ...DEFAULT_SWARM_SETTINGS };
711
667
  const sources = builtInSources();
668
+ if (Object.hasOwn(value, "colorPalette")) {
669
+ if (value.colorPalette !== "muted" && value.colorPalette !== "bright") return void 0;
670
+ settings.colorPalette = value.colorPalette;
671
+ sources.colorPalette = "user";
672
+ }
712
673
  if (Object.hasOwn(value, "confirmSessionLaunch")) {
713
674
  if (typeof value.confirmSessionLaunch !== "boolean") return void 0;
714
675
  settings.confirmSessionLaunch = value.confirmSessionLaunch;
@@ -772,6 +733,7 @@ function createInMemorySwarmSettingsRuntime() {
772
733
  settings: { ...state.settings, ...canonical },
773
734
  sources: {
774
735
  ...state.sources,
736
+ ...canonical.colorPalette !== void 0 ? { colorPalette: "user" } : {},
775
737
  ...canonical.confirmSessionLaunch !== void 0 ? { confirmSessionLaunch: "user" } : {},
776
738
  ...canonical.externalCommand ? { externalCommand: "user" } : {},
777
739
  ...canonical.pinToLeadWorkspace !== void 0 ? { pinToLeadWorkspace: "user" } : {}
@@ -929,6 +891,7 @@ function invalidLoad(path2, reason) {
929
891
  }
930
892
  function builtInSources() {
931
893
  return {
894
+ colorPalette: "built-in",
932
895
  confirmSessionLaunch: "built-in",
933
896
  externalCommand: "built-in",
934
897
  pinToLeadWorkspace: "built-in"
@@ -1073,6 +1036,32 @@ function throwIfAborted2(signal, message) {
1073
1036
  throw error;
1074
1037
  }
1075
1038
 
1039
+ // src/footer.ts
1040
+ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
1041
+ var ROLE_BADGE_BACKGROUND = "#ffc85a";
1042
+ var FOOTER_WIDTH_FRACTION = 0.55;
1043
+ var SHORT_ID_LENGTH = 8;
1044
+ var DEFAULT_TERMINAL_COLUMNS = 80;
1045
+ var MIN_NAME_BUDGET = 8;
1046
+ var NAME_BADGE_OVERHEAD = 4;
1047
+ function buildRosterBadge(input) {
1048
+ const name = input.name ? safeTerminalLine(input.name) : "";
1049
+ const sessionId = safeTerminalLine(input.sessionId);
1050
+ const roleBadge = badge(` ${input.role} `, ROLE_BADGE_BACKGROUND, "#000000");
1051
+ const nameBadge = (value) => badge(value ? ` \u25CF ${value} ` : " \u25CF ", input.color, contrastTextColor(input.color));
1052
+ const available = Math.max(0, Math.floor(input.columns * FOOTER_WIDTH_FRACTION));
1053
+ const full = `${nameBadge(name)}${badge(` ${sessionId} `, "#ffffff", "#000000")}${roleBadge}`;
1054
+ if (visibleWidth(full) <= available) return full;
1055
+ const shortId = [...sessionId].slice(0, SHORT_ID_LENGTH).join("");
1056
+ const shortIdBadge = badge(` ${shortId} `, "#ffffff", "#000000");
1057
+ const nameBudget = available - visibleWidth(roleBadge) - visibleWidth(shortIdBadge) - NAME_BADGE_OVERHEAD;
1058
+ if (nameBudget >= MIN_NAME_BUDGET) {
1059
+ const truncated = visibleWidth(name) > nameBudget ? truncateToWidth(name, nameBudget, "\u2026") : name;
1060
+ return `${nameBadge(truncated)}${shortIdBadge}${roleBadge}`;
1061
+ }
1062
+ return `${nameBadge("")}${roleBadge}`;
1063
+ }
1064
+
1076
1065
  // src/launch-envelope.ts
1077
1066
  var SWARM_LAUNCH_ENV_KEYS = [
1078
1067
  "PI_SWARM_INVITE",
@@ -2038,6 +2027,9 @@ var SwarmTransport = class {
2038
2027
  setColor(color) {
2039
2028
  this.peer.color = color;
2040
2029
  }
2030
+ setName(name) {
2031
+ this.peer.name = name;
2032
+ }
2041
2033
  get peerDescription() {
2042
2034
  return { ...this.peer };
2043
2035
  }
@@ -2691,7 +2683,6 @@ function assertPositiveDuration2(value, label) {
2691
2683
  // src/swarm-controller.ts
2692
2684
  var STATUS_KEY = "swarm";
2693
2685
  var ROSTER_STATUS_KEY = "swarm-roster";
2694
- var ROLE_BADGE_BACKGROUND = "#ffc85a";
2695
2686
  var DEFAULT_LAUNCH_TIMEOUT_MS = 15e3;
2696
2687
  var DEFAULT_POLL_INTERVAL_MS2 = 100;
2697
2688
  var RELOAD_HANDOFF_TTL_MS = 3e4;
@@ -2707,7 +2698,8 @@ function defaultSwarmControllerDependencies(pi) {
2707
2698
  randomId: (prefix) => `${prefix}_${randomBytes5(16).toString("hex")}`,
2708
2699
  sleep: abortableSleep2,
2709
2700
  launchTimeoutMs: DEFAULT_LAUNCH_TIMEOUT_MS,
2710
- environment: process.env
2701
+ environment: process.env,
2702
+ terminalColumns: () => process.stdout.isTTY ? process.stdout.columns : void 0
2711
2703
  };
2712
2704
  }
2713
2705
  var SwarmController = class {
@@ -2732,6 +2724,8 @@ var SwarmController = class {
2732
2724
  /** A human-started session is the default lead of its own (not yet started) group. */
2733
2725
  defaultLead = false;
2734
2726
  leadWatcher;
2727
+ resizeListener = () => this.onTerminalResize();
2728
+ resizeWatching = false;
2735
2729
  pendingKickoffIds = /* @__PURE__ */ new Set();
2736
2730
  relayChain = Promise.resolve();
2737
2731
  async sessionStart(event, ctx) {
@@ -2749,6 +2743,7 @@ var SwarmController = class {
2749
2743
  this.pendingKickoffIds.clear();
2750
2744
  this.relayChain = Promise.resolve();
2751
2745
  this.startLeadWatcher();
2746
+ this.startResizeWatcher();
2752
2747
  const owner = ctx.sessionManager;
2753
2748
  const ownerGeneration = this.generation;
2754
2749
  let envelope;
@@ -2823,6 +2818,7 @@ var SwarmController = class {
2823
2818
  async sessionShutdown(event, ctx) {
2824
2819
  if (ctx.sessionManager !== this.activeSessionManager) return;
2825
2820
  this.stopLeadWatcher();
2821
+ this.stopResizeWatcher();
2826
2822
  if (event.reason === "reload" && this.membership) {
2827
2823
  const membership = this.membership;
2828
2824
  const peerName = this.pi.getSessionName() ?? membership.transport.peerDescription.name;
@@ -3018,7 +3014,8 @@ var SwarmController = class {
3018
3014
  const launchId = this.deps.randomId("launch");
3019
3015
  const kickoffCapability = this.deps.randomId("kickoff");
3020
3016
  const name = normalizeOptionalText(input.name, "name", 200) ?? `Swarm ${launchId.slice(-6)}`;
3021
- const color = normalizeSwarmColor(input.color) ?? pickSwarmColor(name);
3017
+ const palette = this.activePalette();
3018
+ const color = normalizeSwarmColor(input.color, palette) ?? pickSwarmColor(name, palette);
3022
3019
  const modelSpec = normalizeOptionalText(input.model, "model", 200);
3023
3020
  let childModel;
3024
3021
  if (modelSpec) {
@@ -3211,7 +3208,7 @@ var SwarmController = class {
3211
3208
  protocolVersion: SWARM_PROTOCOL_VERSION,
3212
3209
  sessionId: ctx.sessionManager.getSessionId(),
3213
3210
  ...this.pi.getSessionName() ? { name: this.pi.getSessionName() } : {},
3214
- color: this.color ?? pickSwarmColor(ctx.sessionManager.getSessionId()),
3211
+ color: this.color ?? pickSwarmColor(ctx.sessionManager.getSessionId(), this.activePalette()),
3215
3212
  cwd: ctx.cwd,
3216
3213
  pid: process.pid,
3217
3214
  ...launchId ? { launchId } : {},
@@ -3356,12 +3353,12 @@ Reply through session_bus action reply to session ${message.fromSessionId} with
3356
3353
  assertCurrentContext(ctx) {
3357
3354
  if (!this.isCurrent(ctx)) throw staleError();
3358
3355
  }
3359
- async cleanupActive(_reloading) {
3356
+ async cleanupActive(reloading) {
3360
3357
  this.generation += 1;
3361
3358
  this.controller.abort();
3362
3359
  let cleanupError;
3363
3360
  try {
3364
- await this.leaveGroupInternal();
3361
+ await this.leaveGroupInternal(reloading);
3365
3362
  } catch (error) {
3366
3363
  cleanupError = error;
3367
3364
  }
@@ -3371,7 +3368,7 @@ Reply through session_bus action reply to session ${message.fromSessionId} with
3371
3368
  this.activeSessionManager = void 0;
3372
3369
  if (cleanupError) throw cleanupError;
3373
3370
  }
3374
- leaveGroupInternal() {
3371
+ leaveGroupInternal(reloading = false) {
3375
3372
  return this.mutateMembership(async () => {
3376
3373
  const membership = this.membership;
3377
3374
  const directory = membership?.transport.endpointManifest?.directory;
@@ -3383,7 +3380,7 @@ Reply through session_bus action reply to session ${message.fromSessionId} with
3383
3380
  } finally {
3384
3381
  membership?.group.secret.fill(0);
3385
3382
  }
3386
- if (directory && self && this.leadSessionId === self.sessionId) {
3383
+ if (!reloading && directory && self && this.leadSessionId === self.sessionId) {
3387
3384
  await rm5(join7(directory, "lead.json"), { force: true }).catch(() => void 0);
3388
3385
  }
3389
3386
  this.leadSessionId = void 0;
@@ -3473,13 +3470,12 @@ Reply through session_bus action reply to session ${message.fromSessionId} with
3473
3470
  }
3474
3471
  const sessionId = self?.sessionId ?? ctx.sessionManager.getSessionId();
3475
3472
  const name = self?.name ?? this.pi.getSessionName();
3476
- const color = this.color ?? self?.color ?? pickSwarmColor(sessionId);
3473
+ const color = this.color ?? self?.color ?? pickSwarmColor(sessionId, this.activePalette());
3477
3474
  const role = this.leadSessionId === sessionId || !self && this.defaultLead ? "LEADER" : "WORKER";
3478
- const nameBadge = badge(name ? ` \u25CF ${name} ` : " \u25CF ", color, contrastTextColor(color));
3479
- const idBadge = badge(` ${sessionId} `, "#ffffff", "#000000");
3480
- const roleBadge = badge(` ${role} `, ROLE_BADGE_BACKGROUND, "#000000");
3475
+ const columns = this.deps.terminalColumns?.() ?? DEFAULT_TERMINAL_COLUMNS;
3476
+ const status = buildRosterBadge({ name, sessionId, color, role, columns });
3481
3477
  try {
3482
- ctx.ui.setStatus(ROSTER_STATUS_KEY, `${nameBadge}${idBadge}${roleBadge}`);
3478
+ ctx.ui.setStatus(ROSTER_STATUS_KEY, status);
3483
3479
  } catch {
3484
3480
  }
3485
3481
  }
@@ -3513,12 +3509,50 @@ Reply through session_bus action reply to session ${message.fromSessionId} with
3513
3509
  await this.broadcastLeadChange(target);
3514
3510
  await this.renderFooterStatus(ctx);
3515
3511
  }
3516
- async setOwnColor(ctx, color) {
3512
+ /** Resolve a palette name or #rrggbb hex against the active `colorPalette` setting. */
3513
+ normalizeColor(value) {
3514
+ return normalizeSwarmColor(value, this.activePalette());
3515
+ }
3516
+ activePalette() {
3517
+ return swarmColorPalette(this.settings.get().settings.colorPalette);
3518
+ }
3519
+ /**
3520
+ * Persist the roster palette and keep this session on the same hue slot under
3521
+ * the new palette. Peers keep their announced colors; their own sessions decide
3522
+ * locally whether to follow a palette change.
3523
+ */
3524
+ async setColorPalette(ctx, palette, signal) {
3525
+ this.assertCurrentContext(ctx);
3526
+ throwIfAborted5(signal, "Pi Agent Swarm palette change aborted");
3527
+ await this.settings.update({ colorPalette: palette });
3517
3528
  this.assertCurrentContext(ctx);
3529
+ throwIfAborted5(signal, "Pi Agent Swarm palette change aborted");
3530
+ const slot = this.color ? swarmColorName(this.color) : void 0;
3531
+ if (slot) {
3532
+ const next = this.activePalette().find((color) => color.name === slot);
3533
+ if (next && next.hex !== this.color) {
3534
+ this.color = next.hex;
3535
+ this.membership?.transport.setColor(next.hex);
3536
+ }
3537
+ }
3538
+ await this.renderFooterStatus(ctx);
3539
+ }
3540
+ async setOwnColor(ctx, color, signal) {
3541
+ this.assertCurrentContext(ctx);
3542
+ throwIfAborted5(signal, "Pi Agent Swarm color change aborted");
3518
3543
  this.color = color;
3519
3544
  this.membership?.transport.setColor(color);
3520
3545
  await this.renderFooterStatus(ctx);
3521
3546
  }
3547
+ async setOwnName(ctx, name, signal) {
3548
+ this.assertCurrentContext(ctx);
3549
+ throwIfAborted5(signal, "Pi Agent Swarm rename aborted");
3550
+ const normalized = normalizeOptionalText(name, "name", 200);
3551
+ if (!normalized) throw new Error("Pi Agent Swarm session name must not be empty");
3552
+ this.pi.setSessionName(normalized);
3553
+ this.membership?.transport.setName(normalized);
3554
+ await this.renderFooterStatus(ctx);
3555
+ }
3522
3556
  /**
3523
3557
  * Best-effort, ordered relay of a direct user steer to the parent session so it
3524
3558
  * stays aligned. This returns immediately: sends are chained so ordering is
@@ -3598,6 +3632,27 @@ Reply through session_bus action reply to session ${message.fromSessionId} with
3598
3632
  this.leadWatcher = void 0;
3599
3633
  }
3600
3634
  }
3635
+ // A resized terminal can cross a footer tier boundary, so re-render the badge with
3636
+ // the new width. The listener is TTY-only and session-owned: attached at session
3637
+ // start, detached at shutdown, and idempotent against repeated calls.
3638
+ startResizeWatcher() {
3639
+ this.stopResizeWatcher();
3640
+ if (!process.stdout.isTTY || typeof process.stdout.on !== "function") return;
3641
+ process.stdout.on("resize", this.resizeListener);
3642
+ this.resizeWatching = true;
3643
+ }
3644
+ stopResizeWatcher() {
3645
+ if (this.resizeWatching) {
3646
+ process.stdout.off("resize", this.resizeListener);
3647
+ this.resizeWatching = false;
3648
+ }
3649
+ }
3650
+ onTerminalResize() {
3651
+ if (this.controller.signal.aborted) return;
3652
+ const activeContext = this.activeContext;
3653
+ if (!activeContext) return;
3654
+ void this.renderFooterStatus(activeContext);
3655
+ }
3601
3656
  notify(ctx, message, level) {
3602
3657
  if (!ctx.hasUI) return;
3603
3658
  try {
@@ -3895,7 +3950,7 @@ function createPiSwarmExtension(dependencies = {}) {
3895
3950
  return function piSwarmExtension(pi) {
3896
3951
  const settings = dependencies.settingsRuntime ?? createSwarmSettingsRuntime();
3897
3952
  const controller = new SwarmController(pi, dependencies.controllerDependencies, settings);
3898
- const loadMenu = cachedModuleLoader(dependencies.loadMenu ?? (() => import("./chunks/menu-MZS6N2VS.ts")));
3953
+ const loadMenu = cachedModuleLoader(dependencies.loadMenu ?? (() => import("./chunks/menu-RH6GY6U4.ts")));
3899
3954
  pi.registerMessageRenderer(SWARM_MESSAGE_TYPE, renderSwarmMessage);
3900
3955
  registerSwarmTools(pi, controller);
3901
3956
  pi.on("session_start", async (event, ctx) => {
@@ -3909,7 +3964,7 @@ function createPiSwarmExtension(dependencies = {}) {
3909
3964
  void controller.relaySteerInput(event.text, ctx);
3910
3965
  });
3911
3966
  pi.registerCommand("swarm", {
3912
- description: "Spawn and connect local Pi sessions",
3967
+ description: "Spawn a worker Pi session, or start/join a local group",
3913
3968
  handler: async (rawArgs, ctx) => {
3914
3969
  const args = rawArgs.trim();
3915
3970
  if (ctx.mode !== "tui" && ctx.mode !== "rpc") {
@@ -3926,7 +3981,7 @@ function createPiSwarmExtension(dependencies = {}) {
3926
3981
  const ownerSignal = controller.sessionSignal;
3927
3982
  const menuModule = await loadMenu();
3928
3983
  if (ownerSignal.aborted || !controller.isCurrent(ctx)) return;
3929
- await menuModule.showSwarmMenu(ctx, menuSource(controller, settings, ctx), {
3984
+ await menuModule.showSwarmMenu(ctx, menuSource(controller), {
3930
3985
  signal: ownerSignal,
3931
3986
  isCurrent: () => controller.isCurrent(ctx) && !ownerSignal.aborted
3932
3987
  });
@@ -3947,7 +4002,7 @@ function createPiSwarmExtension(dependencies = {}) {
3947
4002
  pi.registerCommand("color", {
3948
4003
  description: "Set this session's color (palette name or #rrggbb)",
3949
4004
  handler: async (rawArgs, ctx) => {
3950
- const color = normalizeSwarmColor(rawArgs.trim());
4005
+ const color = controller.normalizeColor(rawArgs.trim());
3951
4006
  if (!color) {
3952
4007
  throw new Error("Usage: /color <red|orange|yellow|green|cyan|blue|magenta|purple|#rrggbb>");
3953
4008
  }
@@ -3984,13 +4039,9 @@ async function startGroupDirectly(controller, ctx) {
3984
4039
  ctx.ui.notify("Started a local Pi Agent Swarm group. You are its lead.", "info");
3985
4040
  }
3986
4041
  }
3987
- function menuSource(controller, settings, ctx) {
4042
+ function menuSource(controller) {
3988
4043
  return {
3989
- snapshot: async (signal) => ({
3990
- ...await controller.snapshot(signal),
3991
- ...settings.get(),
3992
- settingsPath: settings.getPath()
3993
- }),
4044
+ snapshot: (signal) => controller.snapshot(signal),
3994
4045
  spawn: async (commandContext, input, signal) => {
3995
4046
  const result = await controller.spawn(commandContext, input, signal);
3996
4047
  if (controller.isCurrent(commandContext)) {
@@ -4000,38 +4051,26 @@ function menuSource(controller, settings, ctx) {
4000
4051
  );
4001
4052
  }
4002
4053
  },
4003
- start: async (commandContext, signal) => {
4004
- await controller.startNewGroup(commandContext, false, signal);
4054
+ rename: async (commandContext, name, signal) => {
4055
+ await controller.setOwnName(commandContext, name, signal);
4005
4056
  if (controller.isCurrent(commandContext)) {
4006
- commandContext.ui.notify("Started a local Pi Agent Swarm group.", "info");
4057
+ commandContext.ui.notify(`Session renamed to ${safeTerminalLine(name)}.`, "info");
4007
4058
  }
4008
4059
  },
4009
- join: async (commandContext, invite, signal) => {
4010
- try {
4011
- await controller.joinInvite(commandContext, invite, false, signal);
4012
- } catch (error) {
4013
- throw new Error(`Could not join Pi Agent Swarm: ${safeError(error)}`);
4060
+ setColor: async (commandContext, color, signal) => {
4061
+ const normalized = controller.normalizeColor(color);
4062
+ if (!normalized) throw new Error("Pi Agent Swarm color is invalid");
4063
+ await controller.setOwnColor(commandContext, normalized, signal);
4064
+ if (controller.isCurrent(commandContext)) {
4065
+ commandContext.ui.notify(`Color set to ${normalized}.`, "info");
4014
4066
  }
4015
4067
  },
4016
- send: async (commandContext, options, signal) => {
4017
- const result = await controller.send(commandContext, options, signal);
4018
- if (!result.acknowledgement.accepted) {
4019
- throw new Error(
4020
- `Target rejected the message: ${safeTerminalLine(result.acknowledgement.error ?? "unknown reason")}`
4021
- );
4022
- }
4068
+ setPalette: async (commandContext, palette, signal) => {
4069
+ await controller.setColorPalette(commandContext, palette, signal);
4023
4070
  if (controller.isCurrent(commandContext)) {
4024
- commandContext.ui.notify(
4025
- `Target accepted ${safeTerminalLine(result.message.id)}. This does not prove task completion.`,
4026
- "info"
4027
- );
4071
+ commandContext.ui.notify(`Theme set to ${palette}.`, "info");
4028
4072
  }
4029
- },
4030
- updateSettings: async (patch) => {
4031
- await settings.update(patch);
4032
- },
4033
- setAcceptsRequests: (value) => controller.setAcceptsRequests(ctx, value),
4034
- leave: () => controller.leave(ctx)
4073
+ }
4035
4074
  };
4036
4075
  }
4037
4076
  function cachedModuleLoader(load) {