pi-agent-swarm 0.1.0 → 0.3.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/LICENSE +1 -0
- package/README.md +28 -11
- 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 +372 -113
- package/dist/index.ts.map +4 -4
- package/package.json +1 -1
- package/src/auto-name.ts +169 -0
- package/src/color.ts +58 -8
- package/src/footer.ts +63 -0
- package/src/menu.ts +54 -320
- package/src/pi-agent-swarm.ts +24 -39
- package/src/settings.ts +33 -0
- package/src/swarm-controller.ts +209 -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/swarm-controller.ts
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { readFile, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
4
5
|
import type {
|
|
5
6
|
ExtensionAPI,
|
|
6
7
|
ExtensionContext,
|
|
7
8
|
SessionShutdownEvent,
|
|
8
9
|
SessionStartEvent,
|
|
9
10
|
} from "@earendil-works/pi-coding-agent";
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
AUTO_NAME_TIMEOUT_MS,
|
|
13
|
+
AutoNamer,
|
|
14
|
+
buildAutoNamePrompt,
|
|
15
|
+
collectAutoNameMessages,
|
|
16
|
+
completeSessionTitle as defaultCompleteSessionTitle,
|
|
17
|
+
isDefaultManagerName,
|
|
18
|
+
resolveAutoNameModel,
|
|
19
|
+
toAutoName,
|
|
20
|
+
} from "./auto-name.js";
|
|
21
|
+
import {
|
|
22
|
+
normalizeSwarmColor,
|
|
23
|
+
pickSwarmColor,
|
|
24
|
+
type SwarmColor,
|
|
25
|
+
type SwarmColorPaletteName,
|
|
26
|
+
swarmColorName,
|
|
27
|
+
swarmColorPalette,
|
|
28
|
+
} from "./color.js";
|
|
11
29
|
import { parseExternalCommand } from "./external.js";
|
|
30
|
+
import { buildRosterBadge, DEFAULT_TERMINAL_COLUMNS } from "./footer.js";
|
|
12
31
|
import { consumeLaunchEnvelope, launchEnvelopeEnvironment, type SwarmLaunchEnvelope } from "./launch-envelope.js";
|
|
13
32
|
import { createPiLauncher, type PiLauncher } from "./launcher.js";
|
|
14
33
|
import { type PiInvocation, resolvePiInvocation } from "./pi-invocation.js";
|
|
@@ -47,8 +66,6 @@ import {
|
|
|
47
66
|
|
|
48
67
|
const STATUS_KEY = "swarm";
|
|
49
68
|
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
69
|
const DEFAULT_LAUNCH_TIMEOUT_MS = 15_000;
|
|
53
70
|
const DEFAULT_POLL_INTERVAL_MS = 100;
|
|
54
71
|
const RELOAD_HANDOFF_TTL_MS = 30_000;
|
|
@@ -66,6 +83,7 @@ export interface SwarmTransportPort {
|
|
|
66
83
|
): Promise<SwarmDeliveryAck>;
|
|
67
84
|
setAcceptsRequests(value: boolean): void;
|
|
68
85
|
setColor(color: string): void;
|
|
86
|
+
setName(name: string): void;
|
|
69
87
|
readonly peerDescription: SwarmPeerDescription;
|
|
70
88
|
readonly endpointManifest:
|
|
71
89
|
| {
|
|
@@ -94,7 +112,16 @@ export interface SwarmControllerDependencies {
|
|
|
94
112
|
sleep(milliseconds: number, signal?: AbortSignal): Promise<void>;
|
|
95
113
|
launchTimeoutMs: number;
|
|
96
114
|
environment: NodeJS.ProcessEnv;
|
|
115
|
+
/** Visible terminal columns, or undefined when not attached to a TTY. */
|
|
116
|
+
terminalColumns?(): number | undefined;
|
|
97
117
|
runtimeBaseDirectory?: string;
|
|
118
|
+
/** One-shot title completion for session auto-naming; tests substitute a stub. */
|
|
119
|
+
completeSessionTitle?(
|
|
120
|
+
ctx: ExtensionContext,
|
|
121
|
+
model: Model<Api>,
|
|
122
|
+
prompt: string,
|
|
123
|
+
signal?: AbortSignal,
|
|
124
|
+
): Promise<string>;
|
|
98
125
|
}
|
|
99
126
|
|
|
100
127
|
export interface SwarmSnapshot {
|
|
@@ -152,6 +179,7 @@ export function defaultSwarmControllerDependencies(pi: ExtensionAPI): SwarmContr
|
|
|
152
179
|
sleep: abortableSleep,
|
|
153
180
|
launchTimeoutMs: DEFAULT_LAUNCH_TIMEOUT_MS,
|
|
154
181
|
environment: process.env,
|
|
182
|
+
terminalColumns: () => (process.stdout.isTTY ? process.stdout.columns : undefined),
|
|
155
183
|
};
|
|
156
184
|
}
|
|
157
185
|
|
|
@@ -168,7 +196,16 @@ export class SwarmController {
|
|
|
168
196
|
private leadSessionId: string | undefined;
|
|
169
197
|
/** A human-started session is the default lead of its own (not yet started) group. */
|
|
170
198
|
private defaultLead = false;
|
|
199
|
+
private readonly autoNamer = new AutoNamer();
|
|
200
|
+
/** Auto-naming applies only to human-started sessions, never to spawned children. */
|
|
201
|
+
private autoNameEligible = false;
|
|
202
|
+
/** Set while the auto-namer applies its own name so the change is not read as manual. */
|
|
203
|
+
private applyingAutoName: string | undefined;
|
|
204
|
+
|
|
205
|
+
private autoNameInFlight = false;
|
|
171
206
|
private leadWatcher: ReturnType<typeof setInterval> | undefined;
|
|
207
|
+
private readonly resizeListener = () => this.onTerminalResize();
|
|
208
|
+
private resizeWatching = false;
|
|
172
209
|
private readonly pendingKickoffIds = new Set<string>();
|
|
173
210
|
private relayChain: Promise<void> = Promise.resolve();
|
|
174
211
|
|
|
@@ -190,9 +227,14 @@ export class SwarmController {
|
|
|
190
227
|
this.parentSessionId = undefined;
|
|
191
228
|
this.leadSessionId = undefined;
|
|
192
229
|
this.defaultLead = false;
|
|
230
|
+
this.autoNamer.reset();
|
|
231
|
+
this.autoNameEligible = false;
|
|
232
|
+
this.applyingAutoName = undefined;
|
|
233
|
+
this.autoNameInFlight = false;
|
|
193
234
|
this.pendingKickoffIds.clear();
|
|
194
235
|
this.relayChain = Promise.resolve();
|
|
195
236
|
this.startLeadWatcher();
|
|
237
|
+
this.startResizeWatcher();
|
|
196
238
|
const owner = ctx.sessionManager;
|
|
197
239
|
const ownerGeneration = this.generation;
|
|
198
240
|
let envelope: SwarmLaunchEnvelope | undefined;
|
|
@@ -220,6 +262,7 @@ export class SwarmController {
|
|
|
220
262
|
this.pi.setSessionName(`MANAGER-${ctx.sessionManager.getSessionId().slice(0, 8)}`);
|
|
221
263
|
}
|
|
222
264
|
this.defaultLead = true;
|
|
265
|
+
this.autoNameEligible = true;
|
|
223
266
|
await this.renderFooterStatus(ctx);
|
|
224
267
|
return;
|
|
225
268
|
}
|
|
@@ -281,6 +324,7 @@ export class SwarmController {
|
|
|
281
324
|
async sessionShutdown(event: Pick<SessionShutdownEvent, "reason">, ctx: ExtensionContext): Promise<void> {
|
|
282
325
|
if (ctx.sessionManager !== this.activeSessionManager) return;
|
|
283
326
|
this.stopLeadWatcher();
|
|
327
|
+
this.stopResizeWatcher();
|
|
284
328
|
if (event.reason === "reload" && this.membership) {
|
|
285
329
|
const membership = this.membership;
|
|
286
330
|
const peerName = this.pi.getSessionName() ?? membership.transport.peerDescription.name;
|
|
@@ -518,7 +562,8 @@ export class SwarmController {
|
|
|
518
562
|
const launchId = this.deps.randomId("launch");
|
|
519
563
|
const kickoffCapability = this.deps.randomId("kickoff");
|
|
520
564
|
const name = normalizeOptionalText(input.name, "name", 200) ?? `Swarm ${launchId.slice(-6)}`;
|
|
521
|
-
const
|
|
565
|
+
const palette = this.activePalette();
|
|
566
|
+
const color = normalizeSwarmColor(input.color, palette) ?? pickSwarmColor(name, palette);
|
|
522
567
|
const modelSpec = normalizeOptionalText(input.model, "model", 200);
|
|
523
568
|
let childModel: SwarmLaunchEnvelope["model"];
|
|
524
569
|
if (modelSpec) {
|
|
@@ -735,7 +780,7 @@ export class SwarmController {
|
|
|
735
780
|
protocolVersion: SWARM_PROTOCOL_VERSION,
|
|
736
781
|
sessionId: ctx.sessionManager.getSessionId(),
|
|
737
782
|
...(this.pi.getSessionName() ? { name: this.pi.getSessionName() } : {}),
|
|
738
|
-
color: this.color ?? pickSwarmColor(ctx.sessionManager.getSessionId()),
|
|
783
|
+
color: this.color ?? pickSwarmColor(ctx.sessionManager.getSessionId(), this.activePalette()),
|
|
739
784
|
cwd: ctx.cwd,
|
|
740
785
|
pid: process.pid,
|
|
741
786
|
...(launchId ? { launchId } : {}),
|
|
@@ -910,12 +955,12 @@ export class SwarmController {
|
|
|
910
955
|
if (!this.isCurrent(ctx)) throw staleError();
|
|
911
956
|
}
|
|
912
957
|
|
|
913
|
-
private async cleanupActive(
|
|
958
|
+
private async cleanupActive(reloading: boolean): Promise<void> {
|
|
914
959
|
this.generation += 1;
|
|
915
960
|
this.controller.abort();
|
|
916
961
|
let cleanupError: unknown;
|
|
917
962
|
try {
|
|
918
|
-
await this.leaveGroupInternal();
|
|
963
|
+
await this.leaveGroupInternal(reloading);
|
|
919
964
|
} catch (error) {
|
|
920
965
|
cleanupError = error;
|
|
921
966
|
}
|
|
@@ -926,7 +971,7 @@ export class SwarmController {
|
|
|
926
971
|
if (cleanupError) throw cleanupError;
|
|
927
972
|
}
|
|
928
973
|
|
|
929
|
-
private leaveGroupInternal(): Promise<void> {
|
|
974
|
+
private leaveGroupInternal(reloading = false): Promise<void> {
|
|
930
975
|
return this.mutateMembership(async () => {
|
|
931
976
|
const membership = this.membership;
|
|
932
977
|
const directory = membership?.transport.endpointManifest?.directory;
|
|
@@ -941,8 +986,12 @@ export class SwarmController {
|
|
|
941
986
|
membership?.group.secret.fill(0);
|
|
942
987
|
}
|
|
943
988
|
// 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
|
-
|
|
989
|
+
// not outlive the session (the next lead overwrites it anyway). A reload
|
|
990
|
+
// keeps the record: the same session rejoins through the reload handoff and
|
|
991
|
+
// restores its role from it, and if it never returns the record is no worse
|
|
992
|
+
// than a crashed lead's. Re-asserting instead would clobber a lead change
|
|
993
|
+
// made during the reload gap.
|
|
994
|
+
if (!reloading && directory && self && this.leadSessionId === self.sessionId) {
|
|
946
995
|
await rm(join(directory, "lead.json"), { force: true }).catch(() => undefined);
|
|
947
996
|
}
|
|
948
997
|
this.leadSessionId = undefined;
|
|
@@ -1050,16 +1099,14 @@ export class SwarmController {
|
|
|
1050
1099
|
}
|
|
1051
1100
|
const sessionId = self?.sessionId ?? ctx.sessionManager.getSessionId();
|
|
1052
1101
|
const name = self?.name ?? this.pi.getSessionName();
|
|
1053
|
-
const color = this.color ?? self?.color ?? pickSwarmColor(sessionId);
|
|
1102
|
+
const color = this.color ?? self?.color ?? pickSwarmColor(sessionId, this.activePalette());
|
|
1054
1103
|
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");
|
|
1104
|
+
// The badge degrades through FULL / COMPACT / MINIMAL tiers based on the
|
|
1105
|
+
// terminal width (see footer.ts); the role badge always survives.
|
|
1106
|
+
const columns = this.deps.terminalColumns?.() ?? DEFAULT_TERMINAL_COLUMNS;
|
|
1107
|
+
const status = buildRosterBadge({ name, sessionId, color, role, columns });
|
|
1061
1108
|
try {
|
|
1062
|
-
ctx.ui.setStatus(ROSTER_STATUS_KEY,
|
|
1109
|
+
ctx.ui.setStatus(ROSTER_STATUS_KEY, status);
|
|
1063
1110
|
} catch {
|
|
1064
1111
|
// A replaced UI is allowed to reject best-effort status.
|
|
1065
1112
|
}
|
|
@@ -1096,13 +1143,132 @@ export class SwarmController {
|
|
|
1096
1143
|
await this.renderFooterStatus(ctx);
|
|
1097
1144
|
}
|
|
1098
1145
|
|
|
1099
|
-
|
|
1146
|
+
/** Resolve a palette name or #rrggbb hex against the active `colorPalette` setting. */
|
|
1147
|
+
normalizeColor(value: unknown): string | undefined {
|
|
1148
|
+
return normalizeSwarmColor(value, this.activePalette());
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
private activePalette(): readonly SwarmColor[] {
|
|
1152
|
+
return swarmColorPalette(this.settings.get().settings.colorPalette);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Persist the roster palette and keep this session on the same hue slot under
|
|
1157
|
+
* the new palette. Peers keep their announced colors; their own sessions decide
|
|
1158
|
+
* locally whether to follow a palette change.
|
|
1159
|
+
*/
|
|
1160
|
+
async setColorPalette(ctx: ExtensionContext, palette: SwarmColorPaletteName, signal?: AbortSignal): Promise<void> {
|
|
1161
|
+
this.assertCurrentContext(ctx);
|
|
1162
|
+
throwIfAborted(signal, "Pi Agent Swarm palette change aborted");
|
|
1163
|
+
await this.settings.update({ colorPalette: palette });
|
|
1164
|
+
this.assertCurrentContext(ctx);
|
|
1165
|
+
throwIfAborted(signal, "Pi Agent Swarm palette change aborted");
|
|
1166
|
+
const slot = this.color ? swarmColorName(this.color) : undefined;
|
|
1167
|
+
if (slot) {
|
|
1168
|
+
const next = this.activePalette().find((color) => color.name === slot);
|
|
1169
|
+
if (next && next.hex !== this.color) {
|
|
1170
|
+
this.color = next.hex;
|
|
1171
|
+
this.membership?.transport.setColor(next.hex);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
await this.renderFooterStatus(ctx);
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
async setOwnColor(ctx: ExtensionContext, color: string, signal?: AbortSignal): Promise<void> {
|
|
1100
1178
|
this.assertCurrentContext(ctx);
|
|
1179
|
+
throwIfAborted(signal, "Pi Agent Swarm color change aborted");
|
|
1101
1180
|
this.color = color;
|
|
1102
1181
|
this.membership?.transport.setColor(color);
|
|
1103
1182
|
await this.renderFooterStatus(ctx);
|
|
1104
1183
|
}
|
|
1105
1184
|
|
|
1185
|
+
async setOwnName(ctx: ExtensionContext, name: string, signal?: AbortSignal): Promise<void> {
|
|
1186
|
+
this.assertCurrentContext(ctx);
|
|
1187
|
+
throwIfAborted(signal, "Pi Agent Swarm rename aborted");
|
|
1188
|
+
const normalized = normalizeOptionalText(name, "name", 200);
|
|
1189
|
+
if (!normalized) throw new Error("Pi Agent Swarm session name must not be empty");
|
|
1190
|
+
this.pi.setSessionName(normalized);
|
|
1191
|
+
this.membership?.transport.setName(normalized);
|
|
1192
|
+
await this.renderFooterStatus(ctx);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* Count completed turns and start the one-shot auto-name attempt for a
|
|
1197
|
+
* human-started session. The attempt runs in the background as an owned task
|
|
1198
|
+
* so shutdown waits for it; it never blocks the turn_end event path. The
|
|
1199
|
+
* returned promise resolves when the attempt settles (tests await it).
|
|
1200
|
+
*/
|
|
1201
|
+
noteTurnEnd(ctx: ExtensionContext): Promise<void> {
|
|
1202
|
+
if (!this.isCurrent(ctx)) return Promise.resolve();
|
|
1203
|
+
if (!this.autoNameEligible) return Promise.resolve();
|
|
1204
|
+
if (this.autoNameInFlight) return Promise.resolve();
|
|
1205
|
+
if (!this.autoNamer.noteTurn(this.pi.getSessionName(), this.settings.get().settings.autoName)) {
|
|
1206
|
+
return Promise.resolve();
|
|
1207
|
+
}
|
|
1208
|
+
this.autoNameInFlight = true;
|
|
1209
|
+
const task = this.runAutoName(ctx, ctx.sessionManager, this.generation).finally(() => {
|
|
1210
|
+
this.autoNameInFlight = false;
|
|
1211
|
+
});
|
|
1212
|
+
return this.track(task);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* Keep the roster peer name and the footer badge in sync when the session
|
|
1217
|
+
* name changes outside the extension (for example `/name`), and treat a
|
|
1218
|
+
* custom name as the user taking over so auto-naming steps aside.
|
|
1219
|
+
*/
|
|
1220
|
+
async noteSessionInfoChanged(name: string | undefined, ctx: ExtensionContext): Promise<void> {
|
|
1221
|
+
if (!this.isCurrent(ctx)) return;
|
|
1222
|
+
if (name === undefined || name !== this.applyingAutoName) this.autoNamer.noteExternalName(name);
|
|
1223
|
+
if (name) this.membership?.transport.setName(name);
|
|
1224
|
+
await this.renderFooterStatus(ctx);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Best-effort naming: summarize the first turns into `MAN-<title>` with the
|
|
1229
|
+
* current (or configured) model. Any failure keeps the default MANAGER-<id>
|
|
1230
|
+
* name, is recorded as a session entry for diagnosis, and is retried on a
|
|
1231
|
+
* later turn until the attempt budget runs out. The session name is
|
|
1232
|
+
* re-checked right before applying so a rename that happened during the
|
|
1233
|
+
* completion always wins.
|
|
1234
|
+
*/
|
|
1235
|
+
private async runAutoName(ctx: ExtensionContext, owner: object, ownerGeneration: number): Promise<void> {
|
|
1236
|
+
try {
|
|
1237
|
+
const configured = this.settings.get().settings.autoNameModel;
|
|
1238
|
+
const model = resolveAutoNameModel(ctx, configured);
|
|
1239
|
+
if (!model) {
|
|
1240
|
+
if (configured) {
|
|
1241
|
+
this.notify(
|
|
1242
|
+
ctx,
|
|
1243
|
+
`Pi Agent Swarm could not resolve autoNameModel "${configured}"; keeping the default session name.`,
|
|
1244
|
+
"warning",
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
const messages = collectAutoNameMessages(ctx);
|
|
1250
|
+
if (messages.length === 0) return;
|
|
1251
|
+
const signal = AbortSignal.any([this.controller.signal, AbortSignal.timeout(AUTO_NAME_TIMEOUT_MS)]);
|
|
1252
|
+
const complete = this.deps.completeSessionTitle ?? defaultCompleteSessionTitle;
|
|
1253
|
+
const raw = await complete(ctx, model, buildAutoNamePrompt(messages), signal);
|
|
1254
|
+
if (!this.isCurrent(owner, ownerGeneration)) return;
|
|
1255
|
+
const name = toAutoName(raw);
|
|
1256
|
+
if (!name) return;
|
|
1257
|
+
const currentName = this.pi.getSessionName();
|
|
1258
|
+
if (currentName !== undefined && !isDefaultManagerName(currentName)) return;
|
|
1259
|
+
this.applyingAutoName = name;
|
|
1260
|
+
try {
|
|
1261
|
+
await this.setOwnName(ctx, name, signal);
|
|
1262
|
+
} finally {
|
|
1263
|
+
this.applyingAutoName = undefined;
|
|
1264
|
+
}
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
// Best-effort: any failure keeps the default MANAGER-<id> name and is
|
|
1267
|
+
// retried on a later turn; record it for offline diagnosis only.
|
|
1268
|
+
this.pi.appendEntry("pi-swarm-auto-name", { ok: false, error: safeTerminalLine(safeError(error)) });
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1106
1272
|
/**
|
|
1107
1273
|
* Best-effort, ordered relay of a direct user steer to the parent session so it
|
|
1108
1274
|
* stays aligned. This returns immediately: sends are chained so ordering is
|
|
@@ -1189,6 +1355,30 @@ export class SwarmController {
|
|
|
1189
1355
|
}
|
|
1190
1356
|
}
|
|
1191
1357
|
|
|
1358
|
+
// A resized terminal can cross a footer tier boundary, so re-render the badge with
|
|
1359
|
+
// the new width. The listener is TTY-only and session-owned: attached at session
|
|
1360
|
+
// start, detached at shutdown, and idempotent against repeated calls.
|
|
1361
|
+
private startResizeWatcher(): void {
|
|
1362
|
+
this.stopResizeWatcher();
|
|
1363
|
+
if (!process.stdout.isTTY || typeof process.stdout.on !== "function") return;
|
|
1364
|
+
process.stdout.on("resize", this.resizeListener);
|
|
1365
|
+
this.resizeWatching = true;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
private stopResizeWatcher(): void {
|
|
1369
|
+
if (this.resizeWatching) {
|
|
1370
|
+
process.stdout.off("resize", this.resizeListener);
|
|
1371
|
+
this.resizeWatching = false;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
private onTerminalResize(): void {
|
|
1376
|
+
if (this.controller.signal.aborted) return;
|
|
1377
|
+
const activeContext = this.activeContext;
|
|
1378
|
+
if (!activeContext) return;
|
|
1379
|
+
void this.renderFooterStatus(activeContext);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1192
1382
|
private notify(ctx: ExtensionContext, message: string, level: "info" | "warning" | "error"): void {
|
|
1193
1383
|
if (!ctx.hasUI) return;
|
|
1194
1384
|
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
|
-
}
|