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/README.md +23 -10
- package/dist/chunks/chunk-77JHO3GV.ts +144 -0
- package/dist/chunks/chunk-77JHO3GV.ts.map +7 -0
- package/dist/chunks/menu-RH6GY6U4.ts +119 -0
- package/dist/chunks/menu-RH6GY6U4.ts.map +7 -0
- package/dist/index.ts +142 -103
- package/dist/index.ts.map +3 -3
- package/package.json +1 -1
- package/src/color.ts +58 -8
- package/src/footer.ts +63 -0
- package/src/menu.ts +54 -320
- package/src/pi-agent-swarm.ts +18 -39
- package/src/settings.ts +11 -0
- package/src/swarm-controller.ts +102 -19
- package/src/transport.ts +4 -0
- package/dist/chunks/chunk-XD4GFZPB.ts +0 -39
- package/dist/chunks/chunk-XD4GFZPB.ts.map +0 -7
- package/dist/chunks/menu-MZS6N2VS.ts +0 -348
- package/dist/chunks/menu-MZS6N2VS.ts.map +0 -7
package/src/pi-agent-swarm.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { normalizeSwarmColor } from "./color.js";
|
|
3
2
|
import type { SwarmMenuSource } from "./menu.js";
|
|
4
3
|
import { parseInvite } from "./protocol.js";
|
|
5
4
|
import { renderSwarmMessage, SWARM_MESSAGE_TYPE } from "./renderer.js";
|
|
6
5
|
import { createSwarmSettingsRuntime, type SwarmSettingsRuntime } from "./settings.js";
|
|
7
6
|
import { SwarmController, type SwarmControllerDependencies } from "./swarm-controller.js";
|
|
8
|
-
import {
|
|
7
|
+
import { safeTerminalLine } from "./text.js";
|
|
9
8
|
import { registerSwarmTools } from "./tools.js";
|
|
10
9
|
|
|
11
10
|
const USAGE = "Usage: /swarm, /swarm start, or /swarm <piagentswarm:v1:invite>";
|
|
@@ -39,7 +38,7 @@ export function createPiSwarmExtension(dependencies: PiSwarmDependencies = {}):
|
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
pi.registerCommand("swarm", {
|
|
42
|
-
description: "Spawn
|
|
41
|
+
description: "Spawn a worker Pi session, or start/join a local group",
|
|
43
42
|
handler: async (rawArgs, ctx) => {
|
|
44
43
|
const args = rawArgs.trim();
|
|
45
44
|
if (ctx.mode !== "tui" && ctx.mode !== "rpc") {
|
|
@@ -56,7 +55,7 @@ export function createPiSwarmExtension(dependencies: PiSwarmDependencies = {}):
|
|
|
56
55
|
const ownerSignal = controller.sessionSignal;
|
|
57
56
|
const menuModule = await loadMenu();
|
|
58
57
|
if (ownerSignal.aborted || !controller.isCurrent(ctx)) return;
|
|
59
|
-
await menuModule.showSwarmMenu(ctx, menuSource(controller
|
|
58
|
+
await menuModule.showSwarmMenu(ctx, menuSource(controller), {
|
|
60
59
|
signal: ownerSignal,
|
|
61
60
|
isCurrent: () => controller.isCurrent(ctx) && !ownerSignal.aborted,
|
|
62
61
|
});
|
|
@@ -79,7 +78,7 @@ export function createPiSwarmExtension(dependencies: PiSwarmDependencies = {}):
|
|
|
79
78
|
pi.registerCommand("color", {
|
|
80
79
|
description: "Set this session's color (palette name or #rrggbb)",
|
|
81
80
|
handler: async (rawArgs, ctx) => {
|
|
82
|
-
const color =
|
|
81
|
+
const color = controller.normalizeColor(rawArgs.trim());
|
|
83
82
|
if (!color) {
|
|
84
83
|
throw new Error("Usage: /color <red|orange|yellow|green|cyan|blue|magenta|purple|#rrggbb>");
|
|
85
84
|
}
|
|
@@ -123,17 +122,9 @@ async function startGroupDirectly(controller: SwarmController, ctx: ExtensionCom
|
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
function menuSource(
|
|
127
|
-
controller: SwarmController,
|
|
128
|
-
settings: SwarmSettingsRuntime,
|
|
129
|
-
ctx: ExtensionCommandContext,
|
|
130
|
-
): SwarmMenuSource {
|
|
125
|
+
function menuSource(controller: SwarmController): SwarmMenuSource {
|
|
131
126
|
return {
|
|
132
|
-
snapshot:
|
|
133
|
-
...(await controller.snapshot(signal)),
|
|
134
|
-
...settings.get(),
|
|
135
|
-
settingsPath: settings.getPath(),
|
|
136
|
-
}),
|
|
127
|
+
snapshot: (signal) => controller.snapshot(signal),
|
|
137
128
|
spawn: async (commandContext, input, signal) => {
|
|
138
129
|
const result = await controller.spawn(commandContext, input, signal);
|
|
139
130
|
if (controller.isCurrent(commandContext)) {
|
|
@@ -143,38 +134,26 @@ function menuSource(
|
|
|
143
134
|
);
|
|
144
135
|
}
|
|
145
136
|
},
|
|
146
|
-
|
|
147
|
-
await controller.
|
|
137
|
+
rename: async (commandContext, name, signal) => {
|
|
138
|
+
await controller.setOwnName(commandContext, name, signal);
|
|
148
139
|
if (controller.isCurrent(commandContext)) {
|
|
149
|
-
commandContext.ui.notify(
|
|
140
|
+
commandContext.ui.notify(`Session renamed to ${safeTerminalLine(name)}.`, "info");
|
|
150
141
|
}
|
|
151
142
|
},
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
143
|
+
setColor: async (commandContext, color, signal) => {
|
|
144
|
+
const normalized = controller.normalizeColor(color);
|
|
145
|
+
if (!normalized) throw new Error("Pi Agent Swarm color is invalid");
|
|
146
|
+
await controller.setOwnColor(commandContext, normalized, signal);
|
|
147
|
+
if (controller.isCurrent(commandContext)) {
|
|
148
|
+
commandContext.ui.notify(`Color set to ${normalized}.`, "info");
|
|
157
149
|
}
|
|
158
150
|
},
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (!result.acknowledgement.accepted) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
`Target rejected the message: ${safeTerminalLine(result.acknowledgement.error ?? "unknown reason")}`,
|
|
164
|
-
);
|
|
165
|
-
}
|
|
151
|
+
setPalette: async (commandContext, palette, signal) => {
|
|
152
|
+
await controller.setColorPalette(commandContext, palette, signal);
|
|
166
153
|
if (controller.isCurrent(commandContext)) {
|
|
167
|
-
commandContext.ui.notify(
|
|
168
|
-
`Target accepted ${safeTerminalLine(result.message.id)}. This does not prove task completion.`,
|
|
169
|
-
"info",
|
|
170
|
-
);
|
|
154
|
+
commandContext.ui.notify(`Theme set to ${palette}.`, "info");
|
|
171
155
|
}
|
|
172
156
|
},
|
|
173
|
-
updateSettings: async (patch) => {
|
|
174
|
-
await settings.update(patch);
|
|
175
|
-
},
|
|
176
|
-
setAcceptsRequests: (value) => controller.setAcceptsRequests(ctx, value),
|
|
177
|
-
leave: () => controller.leave(ctx),
|
|
178
157
|
};
|
|
179
158
|
}
|
|
180
159
|
|
package/src/settings.ts
CHANGED
|
@@ -3,16 +3,19 @@ import { constants } from "node:fs";
|
|
|
3
3
|
import { lstat, mkdir, open, rename, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { basename, dirname, join } from "node:path";
|
|
5
5
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import type { SwarmColorPaletteName } from "./color.js";
|
|
6
7
|
|
|
7
8
|
export const SWARM_SETTINGS_FILE = "pi-agent-swarm.json";
|
|
8
9
|
export const MAX_SWARM_SETTINGS_BYTES = 64 * 1024;
|
|
9
10
|
export const DEFAULT_SWARM_SETTINGS: Readonly<SwarmSettings> = Object.freeze({
|
|
11
|
+
colorPalette: "muted",
|
|
10
12
|
confirmSessionLaunch: true,
|
|
11
13
|
externalCommand: "alacritty -e",
|
|
12
14
|
pinToLeadWorkspace: false,
|
|
13
15
|
});
|
|
14
16
|
|
|
15
17
|
export interface SwarmSettings {
|
|
18
|
+
colorPalette: SwarmColorPaletteName;
|
|
16
19
|
confirmSessionLaunch: boolean;
|
|
17
20
|
externalCommand: string;
|
|
18
21
|
pinToLeadWorkspace: boolean;
|
|
@@ -73,6 +76,7 @@ export interface SwarmSettingsRuntimeOptions {
|
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
const SETTING_FIELDS = [
|
|
79
|
+
"colorPalette",
|
|
76
80
|
"confirmSessionLaunch",
|
|
77
81
|
"externalCommand",
|
|
78
82
|
"pinToLeadWorkspace",
|
|
@@ -88,6 +92,11 @@ export function normalizeSwarmSettingsDocument(value: unknown): NormalizedSwarmS
|
|
|
88
92
|
const settings: SwarmSettings = { ...DEFAULT_SWARM_SETTINGS };
|
|
89
93
|
const sources = builtInSources();
|
|
90
94
|
|
|
95
|
+
if (Object.hasOwn(value, "colorPalette")) {
|
|
96
|
+
if (value.colorPalette !== "muted" && value.colorPalette !== "bright") return undefined;
|
|
97
|
+
settings.colorPalette = value.colorPalette;
|
|
98
|
+
sources.colorPalette = "user";
|
|
99
|
+
}
|
|
91
100
|
if (Object.hasOwn(value, "confirmSessionLaunch")) {
|
|
92
101
|
if (typeof value.confirmSessionLaunch !== "boolean") return undefined;
|
|
93
102
|
settings.confirmSessionLaunch = value.confirmSessionLaunch;
|
|
@@ -157,6 +166,7 @@ export function createInMemorySwarmSettingsRuntime(): SwarmSettingsRuntime {
|
|
|
157
166
|
settings: { ...state.settings, ...canonical },
|
|
158
167
|
sources: {
|
|
159
168
|
...state.sources,
|
|
169
|
+
...(canonical.colorPalette !== undefined ? { colorPalette: "user" as const } : {}),
|
|
160
170
|
...(canonical.confirmSessionLaunch !== undefined ? { confirmSessionLaunch: "user" as const } : {}),
|
|
161
171
|
...(canonical.externalCommand ? { externalCommand: "user" as const } : {}),
|
|
162
172
|
...(canonical.pinToLeadWorkspace !== undefined ? { pinToLeadWorkspace: "user" as const } : {}),
|
|
@@ -331,6 +341,7 @@ function invalidLoad(path: string, reason: string): SwarmSettingsLoadResult {
|
|
|
331
341
|
|
|
332
342
|
function builtInSources(): Record<SwarmSettingsField, SwarmSettingsSource> {
|
|
333
343
|
return {
|
|
344
|
+
colorPalette: "built-in",
|
|
334
345
|
confirmSessionLaunch: "built-in",
|
|
335
346
|
externalCommand: "built-in",
|
|
336
347
|
pinToLeadWorkspace: "built-in",
|
package/src/swarm-controller.ts
CHANGED
|
@@ -7,8 +7,16 @@ import type {
|
|
|
7
7
|
SessionShutdownEvent,
|
|
8
8
|
SessionStartEvent,
|
|
9
9
|
} from "@earendil-works/pi-coding-agent";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
normalizeSwarmColor,
|
|
12
|
+
pickSwarmColor,
|
|
13
|
+
type SwarmColor,
|
|
14
|
+
type SwarmColorPaletteName,
|
|
15
|
+
swarmColorName,
|
|
16
|
+
swarmColorPalette,
|
|
17
|
+
} from "./color.js";
|
|
11
18
|
import { parseExternalCommand } from "./external.js";
|
|
19
|
+
import { buildRosterBadge, DEFAULT_TERMINAL_COLUMNS } from "./footer.js";
|
|
12
20
|
import { consumeLaunchEnvelope, launchEnvelopeEnvironment, type SwarmLaunchEnvelope } from "./launch-envelope.js";
|
|
13
21
|
import { createPiLauncher, type PiLauncher } from "./launcher.js";
|
|
14
22
|
import { type PiInvocation, resolvePiInvocation } from "./pi-invocation.js";
|
|
@@ -47,8 +55,6 @@ import {
|
|
|
47
55
|
|
|
48
56
|
const STATUS_KEY = "swarm";
|
|
49
57
|
const ROSTER_STATUS_KEY = "swarm-roster";
|
|
50
|
-
/** Uniform warning-cream background for the footer role badge (LEADER and WORKER alike). */
|
|
51
|
-
const ROLE_BADGE_BACKGROUND = "#ffc85a";
|
|
52
58
|
const DEFAULT_LAUNCH_TIMEOUT_MS = 15_000;
|
|
53
59
|
const DEFAULT_POLL_INTERVAL_MS = 100;
|
|
54
60
|
const RELOAD_HANDOFF_TTL_MS = 30_000;
|
|
@@ -66,6 +72,7 @@ export interface SwarmTransportPort {
|
|
|
66
72
|
): Promise<SwarmDeliveryAck>;
|
|
67
73
|
setAcceptsRequests(value: boolean): void;
|
|
68
74
|
setColor(color: string): void;
|
|
75
|
+
setName(name: string): void;
|
|
69
76
|
readonly peerDescription: SwarmPeerDescription;
|
|
70
77
|
readonly endpointManifest:
|
|
71
78
|
| {
|
|
@@ -94,6 +101,8 @@ export interface SwarmControllerDependencies {
|
|
|
94
101
|
sleep(milliseconds: number, signal?: AbortSignal): Promise<void>;
|
|
95
102
|
launchTimeoutMs: number;
|
|
96
103
|
environment: NodeJS.ProcessEnv;
|
|
104
|
+
/** Visible terminal columns, or undefined when not attached to a TTY. */
|
|
105
|
+
terminalColumns?(): number | undefined;
|
|
97
106
|
runtimeBaseDirectory?: string;
|
|
98
107
|
}
|
|
99
108
|
|
|
@@ -152,6 +161,7 @@ export function defaultSwarmControllerDependencies(pi: ExtensionAPI): SwarmContr
|
|
|
152
161
|
sleep: abortableSleep,
|
|
153
162
|
launchTimeoutMs: DEFAULT_LAUNCH_TIMEOUT_MS,
|
|
154
163
|
environment: process.env,
|
|
164
|
+
terminalColumns: () => (process.stdout.isTTY ? process.stdout.columns : undefined),
|
|
155
165
|
};
|
|
156
166
|
}
|
|
157
167
|
|
|
@@ -169,6 +179,8 @@ export class SwarmController {
|
|
|
169
179
|
/** A human-started session is the default lead of its own (not yet started) group. */
|
|
170
180
|
private defaultLead = false;
|
|
171
181
|
private leadWatcher: ReturnType<typeof setInterval> | undefined;
|
|
182
|
+
private readonly resizeListener = () => this.onTerminalResize();
|
|
183
|
+
private resizeWatching = false;
|
|
172
184
|
private readonly pendingKickoffIds = new Set<string>();
|
|
173
185
|
private relayChain: Promise<void> = Promise.resolve();
|
|
174
186
|
|
|
@@ -193,6 +205,7 @@ export class SwarmController {
|
|
|
193
205
|
this.pendingKickoffIds.clear();
|
|
194
206
|
this.relayChain = Promise.resolve();
|
|
195
207
|
this.startLeadWatcher();
|
|
208
|
+
this.startResizeWatcher();
|
|
196
209
|
const owner = ctx.sessionManager;
|
|
197
210
|
const ownerGeneration = this.generation;
|
|
198
211
|
let envelope: SwarmLaunchEnvelope | undefined;
|
|
@@ -281,6 +294,7 @@ export class SwarmController {
|
|
|
281
294
|
async sessionShutdown(event: Pick<SessionShutdownEvent, "reason">, ctx: ExtensionContext): Promise<void> {
|
|
282
295
|
if (ctx.sessionManager !== this.activeSessionManager) return;
|
|
283
296
|
this.stopLeadWatcher();
|
|
297
|
+
this.stopResizeWatcher();
|
|
284
298
|
if (event.reason === "reload" && this.membership) {
|
|
285
299
|
const membership = this.membership;
|
|
286
300
|
const peerName = this.pi.getSessionName() ?? membership.transport.peerDescription.name;
|
|
@@ -518,7 +532,8 @@ export class SwarmController {
|
|
|
518
532
|
const launchId = this.deps.randomId("launch");
|
|
519
533
|
const kickoffCapability = this.deps.randomId("kickoff");
|
|
520
534
|
const name = normalizeOptionalText(input.name, "name", 200) ?? `Swarm ${launchId.slice(-6)}`;
|
|
521
|
-
const
|
|
535
|
+
const palette = this.activePalette();
|
|
536
|
+
const color = normalizeSwarmColor(input.color, palette) ?? pickSwarmColor(name, palette);
|
|
522
537
|
const modelSpec = normalizeOptionalText(input.model, "model", 200);
|
|
523
538
|
let childModel: SwarmLaunchEnvelope["model"];
|
|
524
539
|
if (modelSpec) {
|
|
@@ -735,7 +750,7 @@ export class SwarmController {
|
|
|
735
750
|
protocolVersion: SWARM_PROTOCOL_VERSION,
|
|
736
751
|
sessionId: ctx.sessionManager.getSessionId(),
|
|
737
752
|
...(this.pi.getSessionName() ? { name: this.pi.getSessionName() } : {}),
|
|
738
|
-
color: this.color ?? pickSwarmColor(ctx.sessionManager.getSessionId()),
|
|
753
|
+
color: this.color ?? pickSwarmColor(ctx.sessionManager.getSessionId(), this.activePalette()),
|
|
739
754
|
cwd: ctx.cwd,
|
|
740
755
|
pid: process.pid,
|
|
741
756
|
...(launchId ? { launchId } : {}),
|
|
@@ -910,12 +925,12 @@ export class SwarmController {
|
|
|
910
925
|
if (!this.isCurrent(ctx)) throw staleError();
|
|
911
926
|
}
|
|
912
927
|
|
|
913
|
-
private async cleanupActive(
|
|
928
|
+
private async cleanupActive(reloading: boolean): Promise<void> {
|
|
914
929
|
this.generation += 1;
|
|
915
930
|
this.controller.abort();
|
|
916
931
|
let cleanupError: unknown;
|
|
917
932
|
try {
|
|
918
|
-
await this.leaveGroupInternal();
|
|
933
|
+
await this.leaveGroupInternal(reloading);
|
|
919
934
|
} catch (error) {
|
|
920
935
|
cleanupError = error;
|
|
921
936
|
}
|
|
@@ -926,7 +941,7 @@ export class SwarmController {
|
|
|
926
941
|
if (cleanupError) throw cleanupError;
|
|
927
942
|
}
|
|
928
943
|
|
|
929
|
-
private leaveGroupInternal(): Promise<void> {
|
|
944
|
+
private leaveGroupInternal(reloading = false): Promise<void> {
|
|
930
945
|
return this.mutateMembership(async () => {
|
|
931
946
|
const membership = this.membership;
|
|
932
947
|
const directory = membership?.transport.endpointManifest?.directory;
|
|
@@ -941,8 +956,12 @@ export class SwarmController {
|
|
|
941
956
|
membership?.group.secret.fill(0);
|
|
942
957
|
}
|
|
943
958
|
// A lead that leaves removes its own lead record so a stale lead.json does
|
|
944
|
-
// not outlive the session (the next lead overwrites it anyway).
|
|
945
|
-
|
|
959
|
+
// not outlive the session (the next lead overwrites it anyway). A reload
|
|
960
|
+
// keeps the record: the same session rejoins through the reload handoff and
|
|
961
|
+
// restores its role from it, and if it never returns the record is no worse
|
|
962
|
+
// than a crashed lead's. Re-asserting instead would clobber a lead change
|
|
963
|
+
// made during the reload gap.
|
|
964
|
+
if (!reloading && directory && self && this.leadSessionId === self.sessionId) {
|
|
946
965
|
await rm(join(directory, "lead.json"), { force: true }).catch(() => undefined);
|
|
947
966
|
}
|
|
948
967
|
this.leadSessionId = undefined;
|
|
@@ -1050,16 +1069,14 @@ export class SwarmController {
|
|
|
1050
1069
|
}
|
|
1051
1070
|
const sessionId = self?.sessionId ?? ctx.sessionManager.getSessionId();
|
|
1052
1071
|
const name = self?.name ?? this.pi.getSessionName();
|
|
1053
|
-
const color = this.color ?? self?.color ?? pickSwarmColor(sessionId);
|
|
1072
|
+
const color = this.color ?? self?.color ?? pickSwarmColor(sessionId, this.activePalette());
|
|
1054
1073
|
const role = this.leadSessionId === sessionId || (!self && this.defaultLead) ? "LEADER" : "WORKER";
|
|
1055
|
-
//
|
|
1056
|
-
//
|
|
1057
|
-
|
|
1058
|
-
const
|
|
1059
|
-
const idBadge = badge(` ${sessionId} `, "#ffffff", "#000000");
|
|
1060
|
-
const roleBadge = badge(` ${role} `, ROLE_BADGE_BACKGROUND, "#000000");
|
|
1074
|
+
// The badge degrades through FULL / COMPACT / MINIMAL tiers based on the
|
|
1075
|
+
// terminal width (see footer.ts); the role badge always survives.
|
|
1076
|
+
const columns = this.deps.terminalColumns?.() ?? DEFAULT_TERMINAL_COLUMNS;
|
|
1077
|
+
const status = buildRosterBadge({ name, sessionId, color, role, columns });
|
|
1061
1078
|
try {
|
|
1062
|
-
ctx.ui.setStatus(ROSTER_STATUS_KEY,
|
|
1079
|
+
ctx.ui.setStatus(ROSTER_STATUS_KEY, status);
|
|
1063
1080
|
} catch {
|
|
1064
1081
|
// A replaced UI is allowed to reject best-effort status.
|
|
1065
1082
|
}
|
|
@@ -1096,13 +1113,55 @@ export class SwarmController {
|
|
|
1096
1113
|
await this.renderFooterStatus(ctx);
|
|
1097
1114
|
}
|
|
1098
1115
|
|
|
1099
|
-
|
|
1116
|
+
/** Resolve a palette name or #rrggbb hex against the active `colorPalette` setting. */
|
|
1117
|
+
normalizeColor(value: unknown): string | undefined {
|
|
1118
|
+
return normalizeSwarmColor(value, this.activePalette());
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
private activePalette(): readonly SwarmColor[] {
|
|
1122
|
+
return swarmColorPalette(this.settings.get().settings.colorPalette);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* Persist the roster palette and keep this session on the same hue slot under
|
|
1127
|
+
* the new palette. Peers keep their announced colors; their own sessions decide
|
|
1128
|
+
* locally whether to follow a palette change.
|
|
1129
|
+
*/
|
|
1130
|
+
async setColorPalette(ctx: ExtensionContext, palette: SwarmColorPaletteName, signal?: AbortSignal): Promise<void> {
|
|
1100
1131
|
this.assertCurrentContext(ctx);
|
|
1132
|
+
throwIfAborted(signal, "Pi Agent Swarm palette change aborted");
|
|
1133
|
+
await this.settings.update({ colorPalette: palette });
|
|
1134
|
+
this.assertCurrentContext(ctx);
|
|
1135
|
+
throwIfAborted(signal, "Pi Agent Swarm palette change aborted");
|
|
1136
|
+
const slot = this.color ? swarmColorName(this.color) : undefined;
|
|
1137
|
+
if (slot) {
|
|
1138
|
+
const next = this.activePalette().find((color) => color.name === slot);
|
|
1139
|
+
if (next && next.hex !== this.color) {
|
|
1140
|
+
this.color = next.hex;
|
|
1141
|
+
this.membership?.transport.setColor(next.hex);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
await this.renderFooterStatus(ctx);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
async setOwnColor(ctx: ExtensionContext, color: string, signal?: AbortSignal): Promise<void> {
|
|
1148
|
+
this.assertCurrentContext(ctx);
|
|
1149
|
+
throwIfAborted(signal, "Pi Agent Swarm color change aborted");
|
|
1101
1150
|
this.color = color;
|
|
1102
1151
|
this.membership?.transport.setColor(color);
|
|
1103
1152
|
await this.renderFooterStatus(ctx);
|
|
1104
1153
|
}
|
|
1105
1154
|
|
|
1155
|
+
async setOwnName(ctx: ExtensionContext, name: string, signal?: AbortSignal): Promise<void> {
|
|
1156
|
+
this.assertCurrentContext(ctx);
|
|
1157
|
+
throwIfAborted(signal, "Pi Agent Swarm rename aborted");
|
|
1158
|
+
const normalized = normalizeOptionalText(name, "name", 200);
|
|
1159
|
+
if (!normalized) throw new Error("Pi Agent Swarm session name must not be empty");
|
|
1160
|
+
this.pi.setSessionName(normalized);
|
|
1161
|
+
this.membership?.transport.setName(normalized);
|
|
1162
|
+
await this.renderFooterStatus(ctx);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1106
1165
|
/**
|
|
1107
1166
|
* Best-effort, ordered relay of a direct user steer to the parent session so it
|
|
1108
1167
|
* stays aligned. This returns immediately: sends are chained so ordering is
|
|
@@ -1189,6 +1248,30 @@ export class SwarmController {
|
|
|
1189
1248
|
}
|
|
1190
1249
|
}
|
|
1191
1250
|
|
|
1251
|
+
// A resized terminal can cross a footer tier boundary, so re-render the badge with
|
|
1252
|
+
// the new width. The listener is TTY-only and session-owned: attached at session
|
|
1253
|
+
// start, detached at shutdown, and idempotent against repeated calls.
|
|
1254
|
+
private startResizeWatcher(): void {
|
|
1255
|
+
this.stopResizeWatcher();
|
|
1256
|
+
if (!process.stdout.isTTY || typeof process.stdout.on !== "function") return;
|
|
1257
|
+
process.stdout.on("resize", this.resizeListener);
|
|
1258
|
+
this.resizeWatching = true;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
private stopResizeWatcher(): void {
|
|
1262
|
+
if (this.resizeWatching) {
|
|
1263
|
+
process.stdout.off("resize", this.resizeListener);
|
|
1264
|
+
this.resizeWatching = false;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
private onTerminalResize(): void {
|
|
1269
|
+
if (this.controller.signal.aborted) return;
|
|
1270
|
+
const activeContext = this.activeContext;
|
|
1271
|
+
if (!activeContext) return;
|
|
1272
|
+
void this.renderFooterStatus(activeContext);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1192
1275
|
private notify(ctx: ExtensionContext, message: string, level: "info" | "warning" | "error"): void {
|
|
1193
1276
|
if (!ctx.hasUI) return;
|
|
1194
1277
|
try {
|
package/src/transport.ts
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
-
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
|
-
|
|
4
|
-
// src/text.ts
|
|
5
|
-
function safeTerminalText(value) {
|
|
6
|
-
let output = "";
|
|
7
|
-
for (const character of value) {
|
|
8
|
-
const codePoint = character.codePointAt(0) ?? 0;
|
|
9
|
-
if (isTerminalControl(codePoint)) continue;
|
|
10
|
-
output += character === " " ? " " : character;
|
|
11
|
-
}
|
|
12
|
-
return output;
|
|
13
|
-
}
|
|
14
|
-
function safeTerminalLine(value) {
|
|
15
|
-
return safeTerminalText(value).replace(/[\r\n]+/gu, " ").trim();
|
|
16
|
-
}
|
|
17
|
-
function safeError(error) {
|
|
18
|
-
return safeTerminalLine(error instanceof Error ? error.message : String(error));
|
|
19
|
-
}
|
|
20
|
-
function normalizeOptionalText(value, label, maxBytes) {
|
|
21
|
-
if (value === void 0) return void 0;
|
|
22
|
-
const normalized = value.trim();
|
|
23
|
-
if (!normalized) return void 0;
|
|
24
|
-
if (normalized.includes("\0") || Buffer.byteLength(normalized) > maxBytes) {
|
|
25
|
-
throw new Error(`Pi Agent Swarm ${label} is invalid or too large`);
|
|
26
|
-
}
|
|
27
|
-
return normalized;
|
|
28
|
-
}
|
|
29
|
-
function isTerminalControl(codePoint) {
|
|
30
|
-
return codePoint >= 0 && codePoint <= 8 || codePoint === 11 || codePoint === 12 || codePoint === 13 || codePoint >= 14 && codePoint <= 31 || codePoint >= 127 && codePoint <= 159 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
safeTerminalText,
|
|
35
|
-
safeTerminalLine,
|
|
36
|
-
safeError,
|
|
37
|
-
normalizeOptionalText
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=chunk-XD4GFZPB.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/text.ts"],
|
|
4
|
-
"sourcesContent": ["export function safeTerminalText(value: string): string {\n let output = \"\";\n for (const character of value) {\n const codePoint = character.codePointAt(0) ?? 0;\n if (isTerminalControl(codePoint)) continue;\n output += character === \"\\t\" ? \" \" : character;\n }\n return output;\n}\n\nexport function safeTerminalLine(value: string): string {\n return safeTerminalText(value)\n .replace(/[\\r\\n]+/gu, \" \")\n .trim();\n}\n\nexport function safeError(error: unknown): string {\n return safeTerminalLine(error instanceof Error ? error.message : String(error));\n}\n\nexport function normalizeOptionalText(value: string | undefined, label: string, maxBytes: number): string | undefined {\n if (value === undefined) return undefined;\n const normalized = value.trim();\n if (!normalized) return undefined;\n if (normalized.includes(\"\\0\") || Buffer.byteLength(normalized) > maxBytes) {\n throw new Error(`Pi Agent Swarm ${label} is invalid or too large`);\n }\n return normalized;\n}\n\nfunction isTerminalControl(codePoint: number): boolean {\n return (\n (codePoint >= 0x00 && codePoint <= 0x08) ||\n codePoint === 0x0b ||\n codePoint === 0x0c ||\n codePoint === 0x0d ||\n (codePoint >= 0x0e && codePoint <= 0x1f) ||\n (codePoint >= 0x7f && codePoint <= 0x9f) ||\n (codePoint >= 0x202a && codePoint <= 0x202e) ||\n (codePoint >= 0x2066 && codePoint <= 0x2069)\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAAO,SAAS,iBAAiB,OAAuB;AACtD,MAAI,SAAS;AACb,aAAW,aAAa,OAAO;AAC7B,UAAM,YAAY,UAAU,YAAY,CAAC,KAAK;AAC9C,QAAI,kBAAkB,SAAS,EAAG;AAClC,cAAU,cAAc,MAAO,SAAS;AAAA,EAC1C;AACA,SAAO;AACT;AAEO,SAAS,iBAAiB,OAAuB;AACtD,SAAO,iBAAiB,KAAK,EAC1B,QAAQ,aAAa,GAAG,EACxB,KAAK;AACV;AAEO,SAAS,UAAU,OAAwB;AAChD,SAAO,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAChF;AAEO,SAAS,sBAAsB,OAA2B,OAAe,UAAsC;AACpH,MAAI,UAAU,OAAW,QAAO;AAChC,QAAM,aAAa,MAAM,KAAK;AAC9B,MAAI,CAAC,WAAY,QAAO;AACxB,MAAI,WAAW,SAAS,IAAI,KAAK,OAAO,WAAW,UAAU,IAAI,UAAU;AACzE,UAAM,IAAI,MAAM,kBAAkB,KAAK,0BAA0B;AAAA,EACnE;AACA,SAAO;AACT;AAEA,SAAS,kBAAkB,WAA4B;AACrD,SACG,aAAa,KAAQ,aAAa,KACnC,cAAc,MACd,cAAc,MACd,cAAc,MACb,aAAa,MAAQ,aAAa,MAClC,aAAa,OAAQ,aAAa,OAClC,aAAa,QAAU,aAAa,QACpC,aAAa,QAAU,aAAa;AAEzC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|