@evandu/super-pi 0.1.224 → 0.1.225

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/client/.super-pi-client-sources.json +7 -6
  2. package/dist/client/assets/{CodeMirrorEditor-CophJ9Eb.js → CodeMirrorEditor-OLbwCzUh.js} +2 -2
  3. package/dist/client/assets/{dist-BGVYvXYo.js → dist-BQImRXFO.js} +1 -1
  4. package/dist/client/assets/{dist-CFMeFXLU.js → dist-BUOU8RAm.js} +1 -1
  5. package/dist/client/assets/{dist-ukIdoKjd.js → dist-BdrKprbZ.js} +1 -1
  6. package/dist/client/assets/{dist-C0s45hG8.js → dist-BffuhHE1.js} +1 -1
  7. package/dist/client/assets/{dist-nSNA_ze3.js → dist-C8-e07vM.js} +1 -1
  8. package/dist/client/assets/{dist-DBdR1Wph.js → dist-C8naDDXu.js} +1 -1
  9. package/dist/client/assets/{dist-Ch4dVwk4.js → dist-C9f0Riun.js} +1 -1
  10. package/dist/client/assets/{dist-CEbbDGoy.js → dist-CB9Qr9C6.js} +1 -1
  11. package/dist/client/assets/{dist-D-s1GEbP.js → dist-CIEDxNn7.js} +1 -1
  12. package/dist/client/assets/{dist-Clk6Knpv.js → dist-CIsUvpC9.js} +1 -1
  13. package/dist/client/assets/{dist-i8fMtdTP.js → dist-CKA2u-s7.js} +1 -1
  14. package/dist/client/assets/{dist-CxeSxC9m.js → dist-COIAnYiN.js} +1 -1
  15. package/dist/client/assets/{dist-TcwefdPn.js → dist-CXpar2cD.js} +1 -1
  16. package/dist/client/assets/{dist-C3amppza.js → dist-CZu3CzDX.js} +1 -1
  17. package/dist/client/assets/{dist-C8FqYuNv.js → dist-CaePDjkH.js} +1 -1
  18. package/dist/client/assets/{dist-D7On6h3N.js → dist-Cro2exEx.js} +1 -1
  19. package/dist/client/assets/{dist-pVo8vQ15.js → dist-CxJkT0iM.js} +1 -1
  20. package/dist/client/assets/{dist-CMPtWQjx.js → dist-D53uN01l.js} +1 -1
  21. package/dist/client/assets/{dist-ZuNGtw_8.js → dist-D9kySnbi.js} +1 -1
  22. package/dist/client/assets/{dist-C3BgT3PU.js → dist-MARoODS1.js} +1 -1
  23. package/dist/client/assets/{dist-BYjXg164.js → dist-ot9lBE7N.js} +1 -1
  24. package/dist/client/assets/{dist-BxcN7lnR.js → dist-sv2AtsDR.js} +1 -1
  25. package/dist/client/assets/{index-CoJT13t0.js → index-B0m5CXCB.js} +39 -39
  26. package/dist/client/index.html +1 -1
  27. package/dist/server/application/extension-ui-service.d.ts +6 -1
  28. package/dist/server/application/extension-ui-service.js +31 -2
  29. package/dist/server/application/run-service.d.ts +4 -1
  30. package/dist/server/application/run-service.js +58 -18
  31. package/dist/server/command-handler.js +11 -2
  32. package/dist/server/exec-service.d.ts +5 -2
  33. package/dist/server/exec-service.js +12 -2
  34. package/dist/server/http-server.js +40 -9
  35. package/dist/server/index.js +14 -9
  36. package/dist/server/persistence/app-state-repository.d.ts +3 -1
  37. package/dist/server/persistence/sqlite-state-repository.js +14 -1
  38. package/dist/server/store.d.ts +1 -0
  39. package/dist/server/store.js +49 -12
  40. package/dist/server/terminal.d.ts +26 -76
  41. package/dist/server/terminal.js +239 -172
  42. package/dist/server/tool-llm.d.ts +7 -0
  43. package/dist/server/tool-llm.js +8 -1
  44. package/dist/server/tool-runner.d.ts +7 -0
  45. package/dist/server/tool-runner.js +8 -1
  46. package/dist/server/types.d.ts +23 -75
  47. package/dist/server/ws-server.d.ts +7 -12
  48. package/dist/server/ws-server.js +23 -18
  49. package/dist/shared/terminal-protocol.d.ts +71 -0
  50. package/dist/shared/terminal-protocol.js +1 -0
  51. package/package.json +1 -1
@@ -7,6 +7,7 @@ export type ModelFilterRule = {
7
7
  import type { WorkflowRun } from "./workflow.js";
8
8
  import type { ScheduledTask } from "./scheduled-tasks.js";
9
9
  import type { ThinkingLevelMap } from "../shared/thinking-levels.js";
10
+ import type { TerminalCommand, TerminalEvent } from "../shared/terminal-protocol.js";
10
11
  /**
11
12
  * The lifecycle states a `Conversation.status` moves through while a turn is in flight. `waiting` is the
12
13
  * gap between "prompt handed to the LLM" and "the first response token arrived" - holding it apart from
@@ -492,6 +493,8 @@ export type Conversation = {
492
493
  status: RunStatus;
493
494
  messages: Message[];
494
495
  archivedAt?: string;
496
+ /** Private receipts retained even when a message is withdrawn or cut from history. */
497
+ acceptedSendIds?: string[];
495
498
  warmSession?: true;
496
499
  /**
497
500
  * Cumulative usage observed for this conversation: its OWN assistant messages AND the one-shot
@@ -1232,6 +1235,12 @@ export type ProjectSummary = {
1232
1235
  updatedAt: string;
1233
1236
  };
1234
1237
  export type AppState = {
1238
+ extensionUi?: {
1239
+ conversationId: string;
1240
+ request: ExtensionUiRequest;
1241
+ }[];
1242
+ stoppingConversationIds?: string[];
1243
+ sendReceipts?: true;
1235
1244
  modelFilterRules?: ModelFilterRule[];
1236
1245
  defaultModel?: ModelSelection;
1237
1246
  terminalShell?: TerminalShell;
@@ -1244,11 +1253,11 @@ export type AppState = {
1244
1253
  scheduledTasks?: ScheduledTask[];
1245
1254
  projects?: Project[];
1246
1255
  customAgentDirs?: string[]; /**
1247
- * Which conversations the reader has collapsed in the sidebar's session tree, by conversation id.
1248
- * Server-side so the tree looks the same after a restart and on another machine - the sidebar is a
1249
- * view of the PRODUCT's state, not of one browser's session. Absent (older state.json) means
1250
- * "nothing collapsed", which is the correct reading of a preference that did not exist yet.
1251
- */
1256
+ * Which conversations the reader has collapsed in the sidebar's session tree, by conversation id.
1257
+ * Server-side so the tree looks the same after a restart and on another machine - the sidebar is a
1258
+ * view of the PRODUCT's state, not of one browser's session. Absent (older state.json) means
1259
+ * "nothing collapsed", which is the correct reading of a preference that did not exist yet.
1260
+ */
1252
1261
  collapsedConversationIds?: string[];
1253
1262
  /**
1254
1263
  * WHICH CHILD SESSIONS THE READER HAS UNLOCKED, by conversation id.
@@ -1353,6 +1362,7 @@ export type ExtensionUiNotifyType = "info" | "warning" | "error";
1353
1362
  export type ExtensionUiPlacement = "aboveEditor" | "belowEditor";
1354
1363
  /** One normalized `extension_ui_request`. The method-specific fields are only present for methods that send them. */
1355
1364
  export type ExtensionUiRequest = {
1365
+ deadlineAt?: number;
1356
1366
  requestId: string;
1357
1367
  method: ExtensionUiMethod;
1358
1368
  /** True when Pi is blocked until the host answers. False means "display it, never ask the user to reply". */
@@ -1401,41 +1411,7 @@ export type ClientCommandBody =
1401
1411
  callIndex: number;
1402
1412
  answers?: QuestionAnswer[];
1403
1413
  cancelled?: boolean;
1404
- }
1405
- /**
1406
- * THE TERMINAL, and the reason `terminal.open` CARRIES NO PATH.
1407
- *
1408
- * Every other command in this union that names a location lets the browser supply it. This one does
1409
- * not: it carries a workspace ID, and the server resolves that ID to a directory it already trusts
1410
- * (`terminal.ts`). A browser that asked for `C:\Windows` gets a refusal, because there is no field on
1411
- * this command for it to arrive in. That is the difference between a shell scoped to the workspaces
1412
- * the user already configured and a shell scoped to the whole disk, and it is structural rather than a
1413
- * check that a later edit could forget.
1414
- */
1415
- | {
1416
- type: "terminal.open";
1417
- sessionId: string;
1418
- workspaceId: string;
1419
- cwd?: string;
1420
- cols?: number;
1421
- rows?: number;
1422
- }
1423
- /** Keystrokes and pasted text, as the RAW bytes a terminal would receive. */
1424
- | {
1425
- type: "terminal.input";
1426
- sessionId: string;
1427
- data: string;
1428
- }
1429
- /** The panel's measured character grid, so reflowed text reflows in the shell rather than wrapping twice. */
1430
- | {
1431
- type: "terminal.resize";
1432
- sessionId: string;
1433
- cols: number;
1434
- rows: number;
1435
- } | {
1436
- type: "terminal.close";
1437
- sessionId: string;
1438
- } | {
1414
+ } | TerminalCommand | {
1439
1415
  type: "terminal.shell.set";
1440
1416
  command: string | null;
1441
1417
  } | {
@@ -2008,6 +1984,10 @@ export type ChangedFile = {
2008
1984
  at: number;
2009
1985
  };
2010
1986
  export type ServerEvent = {
1987
+ type: "message.accepted";
1988
+ conversationId: string;
1989
+ clientId: string;
1990
+ } | {
2011
1991
  type: "run.stopping";
2012
1992
  conversationId: string;
2013
1993
  } | {
@@ -2273,41 +2253,7 @@ export type ServerEvent = {
2273
2253
  role: "user" | "tool";
2274
2254
  }[];
2275
2255
  actor: "user" | "agent";
2276
- }
2277
- /**
2278
- * Bytes from a terminal shell, as ONE event per coalescing window rather than one per `onData` call.
2279
- *
2280
- * `data` is RAW, including escape sequences, and is deliberately NOT modelled as a buffer of lines:
2281
- * the point of `node-pty` is that the shell knows it is attached to a TTY, so it emits colours,
2282
- * cursor moves and redraws that a line buffer cannot represent. The client owns rendering them.
2283
- *
2284
- * A failed spawn is a separate `terminal.error` rather than a `terminal.exit`, because a shell that
2285
- * refused to start is a configuration problem the user must read, and an exit code would let them
2286
- * scroll past it.
2287
- */
2288
- | {
2289
- type: "terminal.output";
2290
- sessionId: string;
2291
- data: string;
2292
- }
2293
- /** The shell ended. `exitCode` is 0 whenever the server killed the session - see `terminal.ts`. */
2294
- | {
2295
- type: "terminal.exit";
2296
- sessionId: string;
2297
- exitCode: number;
2298
- }
2299
- /** A refused command, with a sentence naming WHICH gate refused it. */
2300
- | {
2301
- type: "terminal.error";
2302
- sessionId: string;
2303
- message: string;
2304
- }
2305
- /** Whether the terminal exists at all, and if not, why. Sent on a refused command. */
2306
- | {
2307
- type: "terminal.status";
2308
- enabled: boolean;
2309
- reason?: string;
2310
- }
2256
+ } | TerminalEvent
2311
2257
  /**
2312
2258
  * Output from a background exec session. Forwarded to the browser so it can stream to the terminal panel
2313
2259
  * if that session is visible, and collected by the exec service for the final result.
@@ -2315,7 +2261,9 @@ export type ServerEvent = {
2315
2261
  | {
2316
2262
  type: "exec.output";
2317
2263
  sessionId: string;
2264
+ conversationId?: string;
2318
2265
  data: string;
2266
+ replace?: boolean;
2319
2267
  }
2320
2268
  /**
2321
2269
  * A background exec session ended. `stdout` and `stderr` are the collected output; the exec service
@@ -2,7 +2,7 @@ import type { Server as NodeHttpServer } from "node:http";
2
2
  import { WebSocket } from "ws";
3
3
  import type { AppState, ServerEvent } from "./types.js";
4
4
  import type { EventBroadcaster } from "./server-context.js";
5
- import type { CommandHandler } from "./command-handler.js";
5
+ import type { CommandHandler, SocketSender } from "./command-handler.js";
6
6
  import type { CatalogService } from "./application/catalog-service.js";
7
7
  /**
8
8
  * A WebSocket is a live transport, not an unbounded queue. `ws.send()` only
@@ -44,6 +44,7 @@ export declare function safeSend(socket: WebSocket, payload: string): boolean;
44
44
  */
45
45
  export declare class WsBroadcaster implements EventBroadcaster {
46
46
  private readonly getState;
47
+ private readonly replay?;
47
48
  private readonly sockets;
48
49
  private readonly scopes;
49
50
  private readonly fileIndexScopes;
@@ -64,7 +65,9 @@ export declare class WsBroadcaster implements EventBroadcaster {
64
65
  private readonly sendStateImmediately;
65
66
  constructor(getState: (scope?: {
66
67
  conversationId?: string;
67
- }) => AppState);
68
+ }) => AppState, replay?: ((state: AppState, scope?: {
69
+ conversationId?: string;
70
+ }) => ServerEvent[]) | undefined);
68
71
  register(socket: WebSocket, scope?: {
69
72
  conversationId?: string;
70
73
  }): void;
@@ -114,16 +117,8 @@ export interface WsServerOptions {
114
117
  catalogService: CatalogService;
115
118
  accessToken?: string;
116
119
  rootDir?: string;
117
- /**
118
- * Terminal sessions this connection opened, so they can be killed when the socket goes away.
119
- *
120
- * An ORPHANED SHELL IS THE FAILURE MODE THIS EXISTS TO PREVENT. A terminal outlives its tab by
121
- * default: close the browser tab, or lose the Wi-Fi, or hit refresh mid-build, and the PTY keeps
122
- * running with nobody reading its output. On a laptop that is a battery drain; on a machine running
123
- * a long `npm install` it is a process nobody can interrupt from the UI any more. Tracking the ids
124
- * per connection makes "the socket closed" and "the shells it started are gone" the same event.
125
- */
126
- onSocketClose?: (terminalSessionIds: readonly string[]) => void;
120
+ /** Release subscriptions owned by this connection. */
121
+ onSocketClose?: (sender: SocketSender) => void;
127
122
  }
128
123
  /**
129
124
  * WebSocket transport manager handling upgrade, connection lifecycles, and command dispatch.
@@ -66,6 +66,7 @@ export function safeSend(socket, payload) {
66
66
  */
67
67
  export class WsBroadcaster {
68
68
  getState;
69
+ replay;
69
70
  sockets = new Set();
70
71
  // Undefined preserves the original full-state protocol. An object, including {}, opts into
71
72
  // conversation-focused snapshots from the very first frame of the connection.
@@ -86,8 +87,9 @@ export class WsBroadcaster {
86
87
  * Never set outside a probe or a regression test that is asserting the old behaviour.
87
88
  */
88
89
  sendStateImmediately = process.env.SUPER_PI_LEGACY_SUBAGENT_FLOOD === "1";
89
- constructor(getState) {
90
+ constructor(getState, replay) {
90
91
  this.getState = getState;
92
+ this.replay = replay;
91
93
  }
92
94
  register(socket, scope) {
93
95
  this.sockets.add(socket);
@@ -114,7 +116,12 @@ export class WsBroadcaster {
114
116
  if (socket.readyState !== WebSocket.OPEN)
115
117
  return;
116
118
  this.flushStreaming(socket);
117
- safeSend(socket, JSON.stringify({ type: "state", state: this.getState(this.scopes.get(socket)) }));
119
+ const scope = this.scopes.get(socket);
120
+ const state = this.getState(scope);
121
+ if (!safeSend(socket, JSON.stringify({ type: "state", state })))
122
+ return;
123
+ for (const event of this.replay?.(state, scope) ?? [])
124
+ safeSend(socket, JSON.stringify(event));
118
125
  }
119
126
  subscribeFileIndex(socket, workspaceId, cwd = "") {
120
127
  if (workspaceId)
@@ -135,6 +142,8 @@ export class WsBroadcaster {
135
142
  case "message.thinking":
136
143
  case "message.tools":
137
144
  return event.conversationId === scope.conversationId;
145
+ case "exec.output":
146
+ return !event.conversationId || event.conversationId === scope.conversationId;
138
147
  case "subagent.event":
139
148
  return event.run.conversationId === scope.conversationId;
140
149
  case "workflow.event":
@@ -404,12 +413,14 @@ export class WsServer {
404
413
  * a missing address must fail CLOSED rather than fall back to "allowed".
405
414
  */
406
415
  const remoteAddress = request.socket.remoteAddress;
407
- /**
408
- * Terminal session ids this socket has opened. Recorded on `terminal.open` rather than inferred
409
- * from the service on close, because the service is shared across sockets and a close must kill
410
- * only the shells belonging to the socket that went away.
411
- */
412
- const terminalSessionIds = new Set();
416
+ const send = event => {
417
+ if (safeSend(socket, JSON.stringify(event)))
418
+ return;
419
+ // Dropping a terminal frame would corrupt the stream or leave its replay unfinished.
420
+ // Reconnecting restores the baseline without stopping the PTY.
421
+ if (event.type.startsWith("terminal.") && socket.readyState === WebSocket.OPEN)
422
+ socket.close(1013, "Terminal reconnect required");
423
+ };
413
424
  this.broadcaster.sendState(socket);
414
425
  if (this.rootDir) {
415
426
  safeSend(socket, JSON.stringify({ type: "server.version", version: checkDiskVersion(this.rootDir) }));
@@ -452,11 +463,7 @@ export class WsServer {
452
463
  socket.on("close", () => {
453
464
  clearInterval(heartbeat);
454
465
  this.broadcaster.unregister(socket);
455
- // Kill the shells this socket started BEFORE clearing the set, so a close that races a final
456
- // `terminal.open` cannot leak one. The set is per-connection, so another tab's terminal survives.
457
- if (terminalSessionIds.size)
458
- this.onSocketClose?.([...terminalSessionIds]);
459
- terminalSessionIds.clear();
466
+ this.onSocketClose?.(send);
460
467
  });
461
468
  /**
462
469
  * Commands from ONE socket are SERIALIZED through a promise chain. `handleCommand` is async, so
@@ -514,11 +521,9 @@ export class WsServer {
514
521
  let command;
515
522
  try {
516
523
  command = parsed;
517
- if (command.type === "terminal.open")
518
- terminalSessionIds.add(command.sessionId);
519
- const entityId = await this.commandHandler.handleCommand(command, (event) => {
520
- safeSend(socket, JSON.stringify(event));
521
- }, remoteAddress);
524
+ if (command.type.startsWith("terminal.") && socket.readyState !== WebSocket.OPEN)
525
+ return;
526
+ const entityId = await this.commandHandler.handleCommand(command, send, remoteAddress);
522
527
  // Void-returning configuration commands also need an ack to release optimistic UI state.
523
528
  if (command.operationRequestId)
524
529
  safeSend(socket, JSON.stringify({ type: "operation.result", requestId: command.operationRequestId, ok: true, entityId }));
@@ -0,0 +1,71 @@
1
+ export declare const MAX_TERMINAL_SLOTS = 5;
2
+ export interface TerminalScope {
3
+ workspaceId: string;
4
+ conversationId?: string;
5
+ }
6
+ interface TerminalSize {
7
+ cols?: number;
8
+ rows?: number;
9
+ }
10
+ export interface TerminalSlot extends Required<TerminalSize> {
11
+ id: string;
12
+ title: string;
13
+ exitCode?: number;
14
+ reason?: string;
15
+ }
16
+ export type TerminalCommand = ({
17
+ type: "terminal.sync";
18
+ ownerId: string;
19
+ cwd?: string;
20
+ initialize?: boolean;
21
+ } & TerminalScope & TerminalSize) | {
22
+ type: "terminal.detach";
23
+ } | ({
24
+ type: "terminal.open";
25
+ sessionId?: string;
26
+ } & TerminalSize) | {
27
+ type: "terminal.input";
28
+ sessionId: string;
29
+ data: string;
30
+ } | {
31
+ type: "terminal.resize";
32
+ sessionId: string;
33
+ cols: number;
34
+ rows: number;
35
+ } | {
36
+ type: "terminal.close";
37
+ sessionId: string;
38
+ };
39
+ export type TerminalEvent = ({
40
+ type: "terminal.sessions";
41
+ sessions: TerminalSlot[];
42
+ replay: boolean;
43
+ activate?: string;
44
+ } & TerminalScope) | {
45
+ type: "terminal.replay";
46
+ sessionId: string;
47
+ data: string;
48
+ } | {
49
+ type: "terminal.size";
50
+ sessionId: string;
51
+ cols: number;
52
+ rows: number;
53
+ } | {
54
+ type: "terminal.output";
55
+ sessionId: string;
56
+ data: string;
57
+ } | {
58
+ type: "terminal.exit";
59
+ sessionId: string;
60
+ exitCode: number;
61
+ reason?: string;
62
+ } | {
63
+ type: "terminal.error";
64
+ sessionId?: string;
65
+ message: string;
66
+ } | {
67
+ type: "terminal.status";
68
+ enabled: boolean;
69
+ reason?: string;
70
+ };
71
+ export {};
@@ -0,0 +1 @@
1
+ export const MAX_TERMINAL_SLOTS = 5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.224",
3
+ "version": "0.1.225",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",