@evandu/super-pi 0.1.240 → 0.1.242

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 (50) hide show
  1. package/agents/code-auditor.md +52 -0
  2. package/agents/code-designer.md +52 -0
  3. package/agents/document-organizer.md +42 -0
  4. package/agents/solution-designer.md +52 -0
  5. package/agents/super-pi-memory/index.ts +3 -2
  6. package/dist/client/.super-pi-client-sources.json +8 -6
  7. package/dist/client/assets/{CodeMirrorEditor-CQea8mRO.js → CodeMirrorEditor-BXlGF-8I.js} +1 -1
  8. package/dist/client/assets/{GitDiffEditor-DZDcD4zI.js → GitDiffEditor-zWN38BGh.js} +1 -1
  9. package/dist/client/assets/index-BbMji0nU.css +1 -0
  10. package/dist/client/assets/{index-DxjIxdVK.js → index-D8M5Jjzq.js} +32 -25
  11. package/dist/client/index.html +2 -2
  12. package/dist/server/active-memory.d.ts +37 -5
  13. package/dist/server/active-memory.js +191 -10
  14. package/dist/server/agents.d.ts +1 -1
  15. package/dist/server/agents.js +1 -1
  16. package/dist/server/application/extension-ui-service.d.ts +3 -1
  17. package/dist/server/application/extension-ui-service.js +20 -7
  18. package/dist/server/application/group-chat-service.d.ts +55 -0
  19. package/dist/server/application/group-chat-service.js +547 -0
  20. package/dist/server/application/run-service.d.ts +16 -12
  21. package/dist/server/application/run-service.js +203 -158
  22. package/dist/server/application/workspace-service.js +1 -1
  23. package/dist/server/engineering-learning.d.ts +30 -0
  24. package/dist/server/engineering-learning.js +106 -0
  25. package/dist/server/exec-service.d.ts +14 -7
  26. package/dist/server/exec-service.js +66 -40
  27. package/dist/server/http-server.js +63 -7
  28. package/dist/server/index.js +11 -7
  29. package/dist/server/memory-recall.d.ts +16 -1
  30. package/dist/server/memory-recall.js +22 -8
  31. package/dist/server/memory.d.ts +10 -1
  32. package/dist/server/memory.js +11 -6
  33. package/dist/server/runtime.d.ts +12 -12
  34. package/dist/server/runtime.js +68 -11
  35. package/dist/server/server-context.d.ts +1 -0
  36. package/dist/server/store.d.ts +7 -1
  37. package/dist/server/store.js +72 -35
  38. package/dist/server/subagent-runs.d.ts +3 -2
  39. package/dist/server/subagent-runs.js +45 -33
  40. package/dist/server/subagents.d.ts +1 -0
  41. package/dist/server/subagents.js +30 -12
  42. package/dist/server/types.d.ts +13 -11
  43. package/dist/server/ws-server.d.ts +3 -0
  44. package/dist/server/ws-server.js +40 -6
  45. package/dist/shared/background-task.d.ts +22 -0
  46. package/dist/shared/background-task.js +5 -0
  47. package/dist/shared/group-chat.d.ts +62 -0
  48. package/dist/shared/group-chat.js +1 -0
  49. package/package.json +4 -1
  50. package/dist/client/assets/index-BGbZwftQ.css +0 -1
@@ -7,7 +7,7 @@ import { resolvePiCommand, shellQuote } from "./pi-command.js";
7
7
  import { buildExtensionUiResponse, describeExtensionUiRequest, killTree, } from "./runtime.js";
8
8
  import { RpcChannel } from "./rpc-channel.js";
9
9
  import { InlineThinkingSplitter, stripInlineThinking } from "./inline-thinking.js";
10
- import { describeToolCall, TOOL_DETAIL_CAP } from "./tool-calls.js";
10
+ import { describeToolCall, extractPartialResultText, TOOL_DETAIL_CAP } from "./tool-calls.js";
11
11
  /**
12
12
  * The tool-call derivation now lives in `tool-calls.js`, because the primary agent's runtime needs the
13
13
  * identical mapping and `subagents.ts` already imports `runtime.ts` - so the shared definition has to sit
@@ -224,7 +224,7 @@ export class SubagentSupervisor {
224
224
  * this costs nothing and removes the whole class of bug.
225
225
  */
226
226
  async run(input) {
227
- const { conversationId, agentId, task, cwd, model, host, signal, onTextDelta, onToolCall, onToolEnd, onThinking, onStage } = input;
227
+ const { conversationId, agentId, task, cwd, model, host, signal, onTextDelta, onToolCall, onToolUpdate, onToolEnd, onThinking, onStage } = input;
228
228
  // Refused here, with the reason, rather than handed to the spawn: an ENOENT from `spawn` reads as
229
229
  // "the app is broken" and hides the one fact that matters, which is where it looked for Pi.
230
230
  if (!this.pi.found)
@@ -304,6 +304,14 @@ export class SubagentSupervisor {
304
304
  const usage = { ...NO_USAGE };
305
305
  /** Set rather than thrown so a child's own failure is reported AFTER its output has been drained. */
306
306
  let failed;
307
+ const noteOutcome = (message, reason) => {
308
+ const status = message?.stopReason ?? reason;
309
+ if (!status)
310
+ return;
311
+ failed = status === "error" || status === "aborted"
312
+ ? `sub-agent ${agentId} (${id}) stopped with reason ${status}: ${message?.errorMessage?.trim() || stripInlineThinking(assistantText(message)) || "no detail from Pi"}`
313
+ : undefined;
314
+ };
307
315
  /**
308
316
  * Which phase the child is in, for a caller that has to say where a run died.
309
317
  *
@@ -471,12 +479,10 @@ export class SubagentSupervisor {
471
479
  finalText = current;
472
480
  addUsage(usage, record.usage);
473
481
  enter("turn");
474
- const reason = event.message?.stopReason ?? event.reason;
475
- if (reason === "error" || reason === "aborted")
476
- failed ??= `sub-agent ${agentId} (${id}) stopped with reason ${reason}: ${stripInlineThinking(assistantText(event.message)) || "no output"}`;
482
+ noteOutcome(event.message, event.reason);
477
483
  }
478
484
  else if (event?.type === "error") {
479
- failed ??= `sub-agent ${agentId} (${id}) reported ${event.reason ?? "an error"}: ${stripInlineThinking(assistantText(event.message)) || "no detail from Pi"}`;
485
+ noteOutcome(event.message, "error");
480
486
  }
481
487
  else if (event?.type === "thinking_delta") {
482
488
  // CONSUMED, not discarded. A reasoning model spends the first seconds of every turn here,
@@ -504,17 +510,21 @@ export class SubagentSupervisor {
504
510
  onToolCall?.({ id: record.toolCallId ?? "", name: record.toolName ?? "unknown", detail: describeToolCall(record.toolName ?? "unknown", record.args) });
505
511
  continue;
506
512
  }
507
- if (record.type === "tool_execution_end") {
513
+ if (record.type === "tool_execution_update" || record.type === "tool_execution_end") {
514
+ const final = record.type === "tool_execution_end";
515
+ if (onToolUpdate && record.toolCallId && /^(bash|powershell|shell|command)$/i.test(record.toolName ?? "")) {
516
+ const output = extractPartialResultText(final ? record.result : record.partialResult);
517
+ if (output)
518
+ onToolUpdate(record.toolCallId, output, final);
519
+ }
520
+ if (!final)
521
+ continue;
508
522
  // THE OTHER HALF OF THE SAME CALL, and the half that makes a row mean something. Until Pi
509
523
  // started sending this, a `read` row could only ever say that a `read` happened: not whether
510
524
  // it found the file, not how long a slow call had been running, and - for a card whose child
511
525
  // is still working - not whether the row was even finished yet.
512
526
  //
513
- // ONLY `isError` AND `durationMs` CROSS OVER. `result` is deliberately not read: for a `read`
514
- // it is the file's contents, and a card row is persisted in a file that is serialized on
515
- // every single broadcast. `durationMs` is Pi's own number off a monotonic clock, so it is
516
- // the one outcome fact available for EVERY tool rather than only for result shapes this code
517
- // would have to guess at.
527
+ // Every tool reports timing and success. Only shell tools expose captured output.
518
528
  enter("turn");
519
529
  onToolEnd?.({
520
530
  id: record.toolCallId ?? "",
@@ -528,6 +538,14 @@ export class SubagentSupervisor {
528
538
  await handleExtensionUi(record);
529
539
  continue;
530
540
  }
541
+ if (record.type === "agent_end") {
542
+ if (!record.willRetry) {
543
+ const message = record.messages && [...record.messages].reverse().find(item => item.role === "assistant");
544
+ if (message)
545
+ noteOutcome(message);
546
+ }
547
+ continue;
548
+ }
531
549
  // Pi caught this inside its own extension host, so it never becomes a thrown failure there. Every
532
550
  // run is a fresh process, so any extension_error seen while draining belongs to the task in
533
551
  // flight - and a sub-agent whose extension failed has not really done the job.
@@ -5,6 +5,7 @@ export type ModelFilterRule = {
5
5
  label?: string;
6
6
  };
7
7
  import type { WorkflowRun } from "./workflow.js";
8
+ import type { BackgroundTaskDetails } from "../shared/background-task.js";
8
9
  import type { ScheduledTask } from "./scheduled-tasks.js";
9
10
  import type { ThinkingLevelMap } from "../shared/thinking-levels.js";
10
11
  import type { TerminalCommand, TerminalEvent } from "../shared/terminal-protocol.js";
@@ -111,6 +112,7 @@ export type ToolCallQuestion = {
111
112
  answers?: QuestionAnswer[];
112
113
  };
113
114
  export type Message = {
115
+ backgroundTask?: BackgroundTaskSummary;
114
116
  id: string;
115
117
  role: MessageRole;
116
118
  source?: "session-reminder";
@@ -272,12 +274,7 @@ export type ToolCallBlock = {
272
274
  * null means outside reasoning; absence is an older record with offsets only. */
273
275
  thinkingBlock?: number | null;
274
276
  /** A background command keeps its dispatch position and settled output after the active task is removed. */
275
- backgroundTask?: {
276
- id: string;
277
- status: "running" | "completed" | "failed";
278
- output?: string;
279
- exitCode?: number;
280
- };
277
+ backgroundTask?: BackgroundTaskDetails;
281
278
  question?: ToolCallQuestion;
282
279
  };
283
280
  /**
@@ -793,6 +790,8 @@ export type ConversationContextUsage = {
793
790
  */
794
791
  export type SubagentToolCall = {
795
792
  label: string;
793
+ output?: string;
794
+ outputTruncated?: boolean;
796
795
  status?: "ok" | "error";
797
796
  detail?: string;
798
797
  durationMs?: number;
@@ -898,6 +897,7 @@ export type SubagentRun = {
898
897
  finishedAt?: string;
899
898
  /** The last assistant message. Absent while running is only for a run that has produced none yet. */
900
899
  output?: string;
900
+ partialOutput?: string;
901
901
  /**
902
902
  * Every tool the child started, oldest first, appended as the run streams. Same rule as `output`:
903
903
  * short labels go here and to the card, the child's full turn stays in Pi's session directory.
@@ -955,14 +955,13 @@ export type SubagentRun = {
955
955
  * `sessionId` is the one identity field allowed to move, and only because a run's id and Pi's session id
956
956
  * happen to coincide today rather than by definition.
957
957
  */
958
- export type SubagentRunUpdate = Partial<Pick<SubagentRun, "status" | "output" | "outputTruncated" | "toolCalls" | "usage" | "error" | "finishedAt" | "sessionId" | "durationMs" | "activity" | "failure">>;
959
- export type BackgroundTaskSummary = {
960
- id: string;
958
+ export type SubagentRunUpdate = Partial<Pick<SubagentRun, "status" | "output" | "partialOutput" | "outputTruncated" | "toolCalls" | "usage" | "error" | "finishedAt" | "sessionId" | "durationMs" | "activity" | "failure">>;
959
+ export type BackgroundTaskSummary = BackgroundTaskDetails & {
961
960
  conversationId: string;
962
961
  title: string;
963
962
  agentId: string;
964
- status: "running" | "completed" | "failed";
965
963
  startedAt: string;
964
+ finishedAt?: string;
966
965
  resultBlockId: string;
967
966
  /** The same call-position anchor a `SubagentRun` carries, and for the same reason: a background command
968
967
  * asked for inside a turn belongs at that call, not wherever its output happened to land. Absent when
@@ -2270,6 +2269,8 @@ export type ServerEvent = {
2270
2269
  conversationId?: string;
2271
2270
  data: string;
2272
2271
  replace?: boolean;
2272
+ offset?: number;
2273
+ truncated?: boolean;
2273
2274
  }
2274
2275
  /**
2275
2276
  * A background exec session ended. `stdout` and `stderr` are the collected output; the exec service
@@ -2278,7 +2279,8 @@ export type ServerEvent = {
2278
2279
  | {
2279
2280
  type: "exec.exit";
2280
2281
  sessionId: string;
2281
- exitCode: number;
2282
+ conversationId?: string;
2283
+ exitCode?: number;
2282
2284
  stdout: string;
2283
2285
  stderr: string;
2284
2286
  }
@@ -50,6 +50,7 @@ export declare class WsBroadcaster implements EventBroadcaster {
50
50
  private readonly fileIndexScopes;
51
51
  private readonly coalescedSockets;
52
52
  private readonly pendingStreams;
53
+ private readonly pendingRuntimeReplays;
53
54
  /**
54
55
  * DIAGNOSTIC ONLY - sends every requested state frame immediately instead of merging them.
55
56
  *
@@ -74,6 +75,8 @@ export declare class WsBroadcaster implements EventBroadcaster {
74
75
  unregister(socket: WebSocket): void;
75
76
  subscribe(socket: WebSocket, conversationId?: string): void;
76
77
  sendState(socket: WebSocket): void;
78
+ private scheduleRuntimeReplay;
79
+ private clearRuntimeReplay;
77
80
  subscribeFileIndex(socket: WebSocket, workspaceId?: string, cwd?: string): void;
78
81
  private receives;
79
82
  configureStreaming(socket: WebSocket, coalesce: boolean): void;
@@ -74,6 +74,7 @@ export class WsBroadcaster {
74
74
  fileIndexScopes = new Map();
75
75
  coalescedSockets = new Set();
76
76
  pendingStreams = new Map();
77
+ pendingRuntimeReplays = new Map();
77
78
  /**
78
79
  * DIAGNOSTIC ONLY - sends every requested state frame immediately instead of merging them.
79
80
  *
@@ -101,6 +102,7 @@ export class WsBroadcaster {
101
102
  if (pending)
102
103
  clearTimeout(pending.timer);
103
104
  this.pendingStreams.delete(socket);
105
+ this.clearRuntimeReplay(socket);
104
106
  this.scopes.delete(socket);
105
107
  this.fileIndexScopes.delete(socket);
106
108
  this.sockets.delete(socket);
@@ -115,13 +117,37 @@ export class WsBroadcaster {
115
117
  sendState(socket) {
116
118
  if (socket.readyState !== WebSocket.OPEN)
117
119
  return;
120
+ if (socket.bufferedAmount > MAX_WS_BUFFERED_BYTES) {
121
+ this.scheduleRuntimeReplay(socket);
122
+ return;
123
+ }
118
124
  this.flushStreaming(socket);
119
125
  const scope = this.scopes.get(socket);
120
126
  const state = this.getState(scope);
121
- if (!safeSend(socket, JSON.stringify({ type: "state", state })))
127
+ this.clearRuntimeReplay(socket);
128
+ // Replay compact logs first so a large transcript cannot starve them on every retry.
129
+ for (const event of this.replay?.(state, scope) ?? []) {
130
+ if (!safeSend(socket, JSON.stringify(event)))
131
+ this.scheduleRuntimeReplay(socket);
132
+ }
133
+ if (!safeSend(socket, JSON.stringify({ type: "state", state }))) {
134
+ this.scheduleRuntimeReplay(socket);
135
+ }
136
+ }
137
+ scheduleRuntimeReplay(socket) {
138
+ if (this.pendingRuntimeReplays.has(socket) || socket.readyState !== WebSocket.OPEN)
122
139
  return;
123
- for (const event of this.replay?.(state, scope) ?? [])
124
- safeSend(socket, JSON.stringify(event));
140
+ this.pendingRuntimeReplays.set(socket, setTimeout(() => {
141
+ this.pendingRuntimeReplays.delete(socket);
142
+ if (this.sockets.has(socket))
143
+ this.sendState(socket);
144
+ }, 100).unref());
145
+ }
146
+ clearRuntimeReplay(socket) {
147
+ const timer = this.pendingRuntimeReplays.get(socket);
148
+ if (timer)
149
+ clearTimeout(timer);
150
+ this.pendingRuntimeReplays.delete(socket);
125
151
  }
126
152
  subscribeFileIndex(socket, workspaceId, cwd = "") {
127
153
  if (workspaceId)
@@ -143,6 +169,7 @@ export class WsBroadcaster {
143
169
  case "message.tools":
144
170
  return event.conversationId === scope.conversationId;
145
171
  case "exec.output":
172
+ case "exec.exit":
146
173
  return !event.conversationId || event.conversationId === scope.conversationId;
147
174
  case "subagent.event":
148
175
  return event.run.conversationId === scope.conversationId;
@@ -167,8 +194,11 @@ export class WsBroadcaster {
167
194
  return;
168
195
  clearTimeout(pending.timer);
169
196
  this.pendingStreams.delete(socket);
170
- for (const event of pending.events.values())
171
- safeSend(socket, JSON.stringify(event));
197
+ for (const event of pending.events.values()) {
198
+ if (!safeSend(socket, JSON.stringify(event)) && event.type === "subagent.event") {
199
+ this.scheduleRuntimeReplay(socket);
200
+ }
201
+ }
172
202
  }
173
203
  enqueueStreaming(socket, event) {
174
204
  let pending = this.pendingStreams.get(socket);
@@ -222,7 +252,9 @@ export class WsBroadcaster {
222
252
  // A state/tool/lifecycle event is a transcript boundary. Flush its preceding text first.
223
253
  this.flushStreaming(socket);
224
254
  payload ??= JSON.stringify(event);
225
- safeSend(socket, payload);
255
+ if (!safeSend(socket, payload) && (event.type === "exec.output" || event.type === "exec.exit" || event.type === "subagent.event")) {
256
+ this.scheduleRuntimeReplay(socket);
257
+ }
226
258
  }
227
259
  }
228
260
  }
@@ -310,6 +342,8 @@ export class WsBroadcaster {
310
342
  */
311
343
  dispose() {
312
344
  this.stateFlushScheduled = false;
345
+ for (const socket of this.pendingRuntimeReplays.keys())
346
+ this.clearRuntimeReplay(socket);
313
347
  }
314
348
  getStateSnapshot(scope) {
315
349
  return this.getState(scope);
@@ -0,0 +1,22 @@
1
+ export type BackgroundTaskStatus = "running" | "completed" | "failed" | "cancelled" | "interrupted";
2
+ export type BackgroundTaskDetails = {
3
+ id: string;
4
+ status: BackgroundTaskStatus;
5
+ output?: string;
6
+ outputOffset?: number;
7
+ outputTruncated?: boolean;
8
+ exitCode?: number;
9
+ signal?: number;
10
+ reason?: string;
11
+ };
12
+ export declare const BACKGROUND_LOG_LIMIT = 128000;
13
+ export type BackgroundCompletion = Omit<BackgroundTaskDetails, "id" | "status"> & {
14
+ status: Exclude<BackgroundTaskStatus, "running">;
15
+ };
16
+ export declare function subagentProgress(run: {
17
+ output?: string;
18
+ partialOutput?: string;
19
+ toolCalls?: readonly {
20
+ output?: string;
21
+ }[];
22
+ }): string;
@@ -0,0 +1,5 @@
1
+ export const BACKGROUND_LOG_LIMIT = 128_000;
2
+ export function subagentProgress(run) {
3
+ return [run.partialOutput ?? run.output, ...(run.toolCalls ?? []).map(call => call.output)]
4
+ .filter(Boolean).join("\n\n");
5
+ }
@@ -0,0 +1,62 @@
1
+ export type GroupModel = {
2
+ provider: string;
3
+ modelId: string;
4
+ label: string;
5
+ };
6
+ export type GroupModerator = {
7
+ model?: GroupModel;
8
+ prompt: string;
9
+ };
10
+ export declare const DEFAULT_GROUP_MEMBER_IDS: readonly ["solution-designer", "code-designer", "code-auditor", "document-organizer"];
11
+ export type GroupMember = {
12
+ id: string;
13
+ name: string;
14
+ description: string;
15
+ };
16
+ export type GroupStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "interrupted";
17
+ type GroupPost = {
18
+ id: string;
19
+ content: string;
20
+ createdAt: string;
21
+ status: GroupStatus;
22
+ error?: string;
23
+ };
24
+ export type GroupFileReference = {
25
+ path: string;
26
+ excerpt: string;
27
+ };
28
+ export type GroupUserPost = GroupPost & {
29
+ role: "user";
30
+ memberIds: string[];
31
+ replyTo?: string;
32
+ clientId: string;
33
+ files?: GroupFileReference[];
34
+ memoryNotice?: string;
35
+ };
36
+ export type GroupReply = GroupPost & {
37
+ role: "assistant";
38
+ memberId: string;
39
+ memberName?: string;
40
+ topicId: string;
41
+ replyTo: string;
42
+ assignment?: string;
43
+ routeReason?: string;
44
+ background?: boolean;
45
+ };
46
+ export type GroupMessage = GroupUserPost | GroupReply;
47
+ export type GroupSummary = {
48
+ id: string;
49
+ workspaceId: string;
50
+ title: string;
51
+ updatedAt: string;
52
+ };
53
+ export type GroupRoom = GroupSummary & {
54
+ members: GroupMember[];
55
+ moderator: GroupModerator;
56
+ revision: number;
57
+ messages: GroupMessage[];
58
+ };
59
+ export type GroupSnapshot = Omit<GroupRoom, "revision"> & {
60
+ revision: string;
61
+ };
62
+ export {};
@@ -0,0 +1 @@
1
+ export const DEFAULT_GROUP_MEMBER_IDS = ["solution-designer", "code-designer", "code-auditor", "document-organizer"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.240",
3
+ "version": "0.1.242",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -64,6 +64,7 @@
64
64
  "scripts/stream-transport.test.mjs",
65
65
  "scripts/remote-transport.test.mjs",
66
66
  "scripts/browser-safe-port.test.mjs",
67
+ "scripts/server-ready.test.mjs",
67
68
  "scripts/agent-order.test.mjs",
68
69
  "scripts/agent-picker-order.test.mjs",
69
70
  "scripts/inline-thinking.test.mjs",
@@ -175,6 +176,7 @@
175
176
  "scripts/revert-session-file.test.mjs",
176
177
  "scripts/revert-real-pi.test.mjs",
177
178
  "scripts/bg-task.test.mjs",
179
+ "scripts/group-chat.test.mjs",
178
180
  "scripts/todo-tool.test.mjs",
179
181
  "scripts/tool-calls.test.mjs",
180
182
  "scripts/files-api.test.mjs",
@@ -326,6 +328,7 @@
326
328
  "scripts/md-render-browser.test.mjs",
327
329
  "scripts/right-sidebar-browser.test.mjs",
328
330
  "scripts/background-task-output-browser.test.mjs",
331
+ "scripts/group-chat-browser.test.mjs",
329
332
  "scripts/rail-workspace-follows-session-browser.test.mjs",
330
333
  "scripts/git-tab-browser.test.mjs",
331
334
  "scripts/workspace-reopen-browser.test.mjs",