@evandu/super-pi 0.1.239 → 0.1.241

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 (33) hide show
  1. package/dist/client/.super-pi-client-sources.json +8 -8
  2. package/dist/client/assets/{CodeMirrorEditor-CtzPSOsS.js → CodeMirrorEditor-CiOKD-_q.js} +1 -1
  3. package/dist/client/assets/{GitDiffEditor-iNVZVVMb.js → GitDiffEditor-D5VMi7K-.js} +1 -1
  4. package/dist/client/assets/index-CwH7sttH.css +1 -0
  5. package/dist/client/assets/index-oUDSLOqG.js +347 -0
  6. package/dist/client/index.html +2 -2
  7. package/dist/server/application/extension-ui-service.d.ts +3 -1
  8. package/dist/server/application/extension-ui-service.js +20 -7
  9. package/dist/server/application/run-service.d.ts +19 -61
  10. package/dist/server/application/run-service.js +221 -372
  11. package/dist/server/application/workspace-service.js +1 -1
  12. package/dist/server/content-search.d.ts +13 -39
  13. package/dist/server/content-search.js +202 -219
  14. package/dist/server/exec-service.d.ts +14 -7
  15. package/dist/server/exec-service.js +66 -40
  16. package/dist/server/http-server.js +69 -31
  17. package/dist/server/index.js +6 -6
  18. package/dist/server/store.d.ts +11 -24
  19. package/dist/server/store.js +88 -62
  20. package/dist/server/subagent-runs.d.ts +3 -2
  21. package/dist/server/subagent-runs.js +45 -33
  22. package/dist/server/subagents.d.ts +1 -0
  23. package/dist/server/subagents.js +30 -12
  24. package/dist/server/types.d.ts +13 -11
  25. package/dist/server/ws-server.d.ts +3 -0
  26. package/dist/server/ws-server.js +40 -6
  27. package/dist/shared/background-task.d.ts +22 -0
  28. package/dist/shared/background-task.js +5 -0
  29. package/dist/shared/content-search.d.ts +22 -0
  30. package/dist/shared/content-search.js +1 -0
  31. package/package.json +1 -1
  32. package/dist/client/assets/index-C5kxyPTT.js +0 -340
  33. package/dist/client/assets/index-DN0oBG6l.css +0 -1
@@ -6,6 +6,7 @@
6
6
  * bash commands without going through the subagent dispatch machinery.
7
7
  */
8
8
  import { createRequire } from "node:module";
9
+ import { BACKGROUND_LOG_LIMIT } from "../shared/background-task.js";
9
10
  let ptyModule;
10
11
  let ptyLoadFailure;
11
12
  function loadPty() {
@@ -27,13 +28,15 @@ function ptyLoadError() {
27
28
  loadPty(); // ensure the failure is populated
28
29
  return ptyLoadFailure;
29
30
  }
30
- const FLUSH_INTERVAL_MS = 16;
31
- const MAX_BACKLOG_BYTES = 4 * 1024 * 1024;
31
+ const CHECKPOINT_INTERVAL_MS = 500;
32
+ const STOP_TIMEOUT_MS = 2000;
32
33
  export class ExecService {
34
+ onCheckpoint;
33
35
  sessions = new Map();
34
36
  broadcast;
35
37
  onComplete;
36
- constructor(broadcast, onComplete) {
38
+ constructor(broadcast, onComplete, onCheckpoint) {
39
+ this.onCheckpoint = onCheckpoint;
37
40
  this.broadcast = broadcast;
38
41
  this.onComplete = onComplete;
39
42
  }
@@ -49,6 +52,8 @@ export class ExecService {
49
52
  throw new Error("node-pty is not available");
50
53
  // Determine shell to run the command.
51
54
  const shell = defaultShell();
55
+ let resolveEnd;
56
+ const ended = new Promise(resolve => { resolveEnd = resolve; });
52
57
  const active = {
53
58
  conversationId,
54
59
  pty: pty.spawn(shell.file, [...shell.args, "-c", cmd], {
@@ -58,28 +63,30 @@ export class ExecService {
58
63
  cwd,
59
64
  env: { ...process.env, TERM: "xterm-256color" },
60
65
  }),
61
- stdout: "",
62
- stderr: "",
63
- killed: false,
66
+ output: "",
67
+ offset: 0,
68
+ checkpoint: undefined,
69
+ ended,
70
+ resolveEnd,
64
71
  };
72
+ this.sessions.set(id, active);
65
73
  active.pty.onData((data) => {
66
- active.stdout += data;
67
- if (active.stdout.length > MAX_BACKLOG_BYTES)
68
- active.stdout = active.stdout.slice(-MAX_BACKLOG_BYTES);
69
- this.broadcast({ type: "exec.output", sessionId: id, conversationId, data });
70
- });
71
- // Flush stderr via a periodic timer rather than a separate channel.
72
- // node-pty on Windows multiplexes both streams; on Unix they are separate.
73
- // We treat all output as stdout for simplicity.
74
- active.timer = setInterval(() => this.flushStderr(id, active), FLUSH_INTERVAL_MS);
75
- active.pty.onExit(({ exitCode }) => {
76
- if (active.timer)
77
- clearInterval(active.timer);
78
- const code = active.killed ? 0 : (exitCode ?? 0);
79
- this.sessions.delete(id);
80
- this.onComplete(id, code, active.stdout, active.stderr);
74
+ if (this.sessions.get(id) !== active)
75
+ return;
76
+ active.offset += data.length;
77
+ active.output = (active.output + data).slice(-BACKGROUND_LOG_LIMIT);
78
+ this.broadcast({ type: "exec.output", sessionId: id, conversationId, data, offset: active.offset, truncated: active.offset > active.output.length });
79
+ if (this.onCheckpoint && !active.checkpoint) {
80
+ active.checkpoint = setTimeout(() => {
81
+ active.checkpoint = undefined;
82
+ void this.onCheckpoint?.(id, active.output, active.offset).catch(error => {
83
+ console.warn("Super Pi: could not checkpoint background output:", error);
84
+ });
85
+ }, CHECKPOINT_INTERVAL_MS);
86
+ active.checkpoint.unref();
87
+ }
81
88
  });
82
- this.sessions.set(id, active);
89
+ active.pty.onExit(({ exitCode, signal }) => this.finish(id, active, exitCode ?? 1, signal));
83
90
  return {
84
91
  id,
85
92
  pid: active.pty.pid,
@@ -93,37 +100,56 @@ export class ExecService {
93
100
  outputSnapshots(state, scope) {
94
101
  const visible = new Set(state.conversations.map(conversation => conversation.id));
95
102
  const ids = state.backgroundTasks.filter(task => visible.has(task.conversationId) && (!scope || task.conversationId === scope.conversationId)).map(task => task.id);
96
- const maxPerTask = Math.min(128_000, Math.max(1, Math.floor(512_000 / Math.max(ids.length, 1))));
103
+ const maxPerTask = Math.min(BACKGROUND_LOG_LIMIT, Math.max(1, Math.floor(512_000 / Math.max(ids.length, 1))));
97
104
  return ids.flatMap(id => {
98
105
  const session = this.sessions.get(id);
99
- return session ? [{ type: "exec.output", sessionId: id, conversationId: session.conversationId, data: session.stdout.slice(-maxPerTask), replace: true }] : [];
106
+ if (!session)
107
+ return [];
108
+ const data = session.output.slice(-maxPerTask);
109
+ return [{ type: "exec.output", sessionId: id, conversationId: session.conversationId, data, replace: true, offset: session.offset, truncated: session.offset > data.length }];
100
110
  });
101
111
  }
102
- kill(id) {
112
+ kill(id, cancellation = "cancelled") {
103
113
  const session = this.sessions.get(id);
104
- if (!session || session.killed)
114
+ if (!session)
105
115
  return;
106
- session.killed = true;
116
+ session.cancellation ??= cancellation;
107
117
  try {
108
118
  session.pty.kill();
109
119
  }
110
120
  catch { /* already gone */ }
111
121
  }
112
- closeAll() {
113
- for (const [id, session] of this.sessions) {
114
- session.killed = true;
115
- if (session.timer)
116
- clearInterval(session.timer);
117
- try {
118
- session.pty.kill();
119
- }
120
- catch { /* already gone */ }
121
- this.sessions.delete(id);
122
+ async stop(id, cancellation = "cancelled") {
123
+ const session = this.sessions.get(id);
124
+ if (!session)
125
+ return false;
126
+ this.kill(id, cancellation);
127
+ let timer;
128
+ await Promise.race([session.ended, new Promise(resolve => { timer = setTimeout(resolve, STOP_TIMEOUT_MS); })]);
129
+ clearTimeout(timer);
130
+ if (this.sessions.get(id) === session)
131
+ throw new Error("后台命令尚未退出,可以重试终止。");
132
+ return true;
133
+ }
134
+ async closeAll() {
135
+ const results = await Promise.allSettled([...this.sessions.keys()].map(id => this.stop(id, "interrupted")));
136
+ for (const result of results) {
137
+ if (result.status === "rejected")
138
+ console.warn("Super Pi: a background command did not exit at shutdown:", result.reason);
122
139
  }
123
140
  }
124
- flushStderr(_id, _session) {
125
- // Currently all output goes to stdout. If we add a separate stderr channel in future,
126
- // this is where it would be broadcast.
141
+ finish(id, session, exitCode, signal) {
142
+ if (this.sessions.get(id) !== session)
143
+ return;
144
+ this.sessions.delete(id);
145
+ clearTimeout(session.checkpoint);
146
+ // A PTY delivers one stream, including error diagnostics.
147
+ try {
148
+ this.onComplete(id, exitCode, session.output, "", { status: session.cancellation ?? "exited", signal, offset: session.offset });
149
+ }
150
+ finally {
151
+ session.resolveEnd();
152
+ }
127
153
  }
128
154
  }
129
155
  function defaultShell() {
@@ -2,7 +2,8 @@ import { createReadStream, existsSync } from "node:fs";
2
2
  import { matchPathMentions } from "../shared/file-mentions.js";
3
3
  import { spawn } from "node:child_process";
4
4
  import { randomUUID } from "node:crypto";
5
- import { readdir, rm, stat } from "node:fs/promises";
5
+ import { once } from "node:events";
6
+ import { readdir, realpath, rm, stat } from "node:fs/promises";
6
7
  import { createServer } from "node:http";
7
8
  import { gzip } from "node:zlib";
8
9
  import { promisify } from "node:util";
@@ -36,7 +37,7 @@ import { readMessageMedia } from "./message-media.js";
36
37
  import { MESSAGE_FRAME_CSP, MESSAGE_HTML_CSP } from "../shared/message-media.js";
37
38
  import { verifyDirectChildScope, verifyListParentScope, verifyReportTargetScope, verifySpawnParentScope } from "./session-tree-scope.js";
38
39
  import { CHILD_SESSION_LOCK_REASON } from "../shared/child-session-lock.js";
39
- import { MAX_CONTENT_DEPTH, MAX_CONTENT_FILE_BYTES, MAX_CONTENT_RESULTS, searchByContent } from "./content-search.js";
40
+ import { isProtectedSearchPath, MAX_CONTENT_RESULTS, searchByContent } from "./content-search.js";
40
41
  import { getAvailableSkills, readSkill } from "./skills.js";
41
42
  /**
42
43
  * THE NAME INDEX FOR ONE WORKSPACE, created on first use and then kept.
@@ -1589,6 +1590,7 @@ export function createHttpServer(options) {
1589
1590
  json(403, { error: result.message });
1590
1591
  return;
1591
1592
  }
1593
+ const foreground = runService.foregroundSignal(conversationId);
1592
1594
  // The `cwd` here is the directory the Pi child was launched in - which is the conversation's
1593
1595
  // workspace, already authenticated by the per-conversation capability check above. Validating it
1594
1596
  // against the workspace list looked cheap, but Windows path normalization (8.3 short names, UNC
@@ -1604,6 +1606,10 @@ export function createHttpServer(options) {
1604
1606
  // inside a turn belongs at that call. Resolved AFTER the capability check above, because a position
1605
1607
  // is worth reading only from a caller already inside the turn.
1606
1608
  const origin = await runService.waitForToolCall(conversationId, toolCallId);
1609
+ if (!runService.canAdmitBackgroundTask(foreground)) {
1610
+ json(409, { error: "原回合已停止,命令未启动。" });
1611
+ return;
1612
+ }
1607
1613
  await store.setBackgroundTask({
1608
1614
  id: sessionId,
1609
1615
  conversationId,
@@ -1619,18 +1625,19 @@ export function createHttpServer(options) {
1619
1625
  broadcaster.broadcast({ type: "message.tools", conversationId, messageId: origin.originMessageId, toolCalls });
1620
1626
  }
1621
1627
  broadcaster.broadcastState();
1628
+ if (!runService.canAdmitBackgroundTask(foreground) || !store.backgroundTask(sessionId)) {
1629
+ await runService.failBackgroundTaskStart(sessionId, "原回合已停止,命令未启动。", true);
1630
+ json(409, { error: "原回合已停止,命令未启动。" });
1631
+ return;
1632
+ }
1622
1633
  try {
1623
1634
  execService.spawn(sessionId, cmd, cwd, conversationId);
1624
1635
  json(202, { sessionId, status: "running" });
1625
1636
  }
1626
1637
  catch (error) {
1627
- if (origin) {
1628
- const toolCalls = await store.updateToolCall(conversationId, origin.originMessageId, origin.originCallRow, { backgroundTask: { id: sessionId, status: "failed", output: error instanceof Error ? error.message : "spawn failed" } });
1629
- broadcaster.broadcast({ type: "message.tools", conversationId, messageId: origin.originMessageId, toolCalls });
1630
- }
1631
- await store.removeBackgroundTask(sessionId);
1632
- broadcaster.broadcastState();
1633
- json(500, { error: error instanceof Error ? error.message : "spawn failed" });
1638
+ const reason = error instanceof Error ? error.message : "后台命令启动失败。";
1639
+ await runService.failBackgroundTaskStart(sessionId, reason);
1640
+ json(500, { error: reason });
1634
1641
  }
1635
1642
  return;
1636
1643
  }
@@ -2818,6 +2825,22 @@ export function createHttpServer(options) {
2818
2825
  }
2819
2826
  if (url.pathname === "/api/files/search") {
2820
2827
  const json = (status, body) => { response.writeHead(status, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(body)); };
2828
+ const controller = new AbortController();
2829
+ const cancel = () => controller.abort();
2830
+ response.once("close", cancel);
2831
+ const send = async (event) => {
2832
+ controller.signal.throwIfAborted();
2833
+ if (!response.write(JSON.stringify(event) + "\n")) {
2834
+ try {
2835
+ await once(response, "drain", { signal: AbortSignal.any([controller.signal, AbortSignal.timeout(15000)]) });
2836
+ }
2837
+ catch (error) {
2838
+ cancel();
2839
+ response.destroy();
2840
+ throw error;
2841
+ }
2842
+ }
2843
+ };
2821
2844
  try {
2822
2845
  if (request.method !== "GET") {
2823
2846
  json(405, { error: "内容搜索需要 GET 请求。", code: "method" });
@@ -2826,41 +2849,56 @@ export function createHttpServer(options) {
2826
2849
  const workspaceId = url.searchParams.get("workspaceId")?.trim();
2827
2850
  const query = url.searchParams.get("q")?.trim() ?? "";
2828
2851
  const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
2829
- if (!workspaceId || !workspace) {
2830
- json(404, { error: "找不到这个工作区——它可能已经被删除。", code: "no_workspace" });
2852
+ if (!workspaceId || !workspace || workspace.closedAt) {
2853
+ json(404, { error: "找不到这个工作区——它可能已经被关闭或删除。", code: "no_workspace" });
2831
2854
  return;
2832
2855
  }
2833
2856
  const root = await resolveFileCwd(workspace.path, url.searchParams.get("cwd"));
2834
2857
  await explorerPath(workspace.path, root, "", true);
2835
- const cwd = relative(resolve(workspace.path), root).replaceAll("\\", "/");
2836
- const indexKey = sessionScopeKey(workspaceId, cwd);
2837
- if (query.length > 256 || /[\r\n]/.test(query)) {
2858
+ const cwd = toRelative(resolve(workspace.path), root);
2859
+ const canonicalCwd = toRelative(await realpath(workspace.path), await realpath(root));
2860
+ if (isProtectedSearchPath(cwd) || isProtectedSearchPath(canonicalCwd))
2861
+ throw new FilesError(403, "不能搜索应用或 Git 内部目录。", "protected_path");
2862
+ if (query.length > 256 || /[\0\r\n]/u.test(query)) {
2838
2863
  json(400, { error: "搜索词只能是一行,且不超过 256 个字符。", code: "bad_query" });
2839
2864
  return;
2840
2865
  }
2841
- if (!query) {
2842
- json(200, { mode: "content", query, hits: [], truncated: false, skipped: [], complete: true, reasons: [], maxResults: MAX_CONTENT_RESULTS, maxFileBytes: MAX_CONTENT_FILE_BYTES, maxDepth: MAX_CONTENT_DEPTH });
2866
+ const include = url.searchParams.get("include")?.trim();
2867
+ const exclude = url.searchParams.get("exclude")?.trim();
2868
+ if ([include, exclude].some((glob) => glob && (glob.length > 512 || /^[!]/u.test(glob) || /[\0\r\n]/u.test(glob)))) {
2869
+ throw new FilesError(400, "文件筛选规则须为单行 glob,且不超过 512 个字符。", "bad_glob");
2870
+ }
2871
+ const stream = url.searchParams.get("stream") === "1";
2872
+ if (controller.signal.aborted)
2843
2873
  return;
2874
+ if (stream) {
2875
+ response.writeHead(200, { "content-type": "application/x-ndjson; charset=utf-8", "cache-control": "no-store", "x-accel-buffering": "no" });
2876
+ response.flushHeaders();
2844
2877
  }
2845
- const indexes = context.fileIndexes ?? new Map();
2846
- if (!context.fileIndexes)
2847
- context.fileIndexes = indexes;
2848
- let index = indexes.get(indexKey);
2849
- if (!index) {
2850
- index = new FileIndex(workspaceId, (event) => broadcaster.broadcast(event), cwd);
2851
- indexes.set(indexKey, index);
2878
+ const { hits, skipped, ...summary } = await searchByContent(root, query, {
2879
+ include, exclude, useIgnoreFiles: url.searchParams.get("ignore") !== "0", signal: controller.signal,
2880
+ onHits: stream ? (hits) => send({ type: "matches", hits }) : undefined,
2881
+ });
2882
+ if (controller.signal.aborted)
2883
+ return;
2884
+ if (stream) {
2885
+ await send({ type: "done", summary });
2886
+ response.end();
2852
2887
  }
2853
- index.start(root);
2854
- const deadline = Date.now() + 4500;
2855
- while (!index.builtAt && Date.now() < deadline)
2856
- await new Promise((resolve) => setTimeout(resolve, 25));
2857
- const snapshot = index.snapshot();
2858
- const result = await searchByContent(root, [...index.entries.values()], query, snapshot);
2859
- json(200, { mode: "content", query, ...result, maxResults: MAX_CONTENT_RESULTS, maxFileBytes: MAX_CONTENT_FILE_BYTES, maxDepth: MAX_CONTENT_DEPTH });
2888
+ else
2889
+ json(200, { mode: "content", query, hits, skipped, ...summary, maxResults: MAX_CONTENT_RESULTS });
2860
2890
  }
2861
2891
  catch (error) {
2892
+ if (controller.signal.aborted)
2893
+ return;
2862
2894
  const described = describeFilesError(error);
2863
- json(described.status, described.body);
2895
+ if (response.headersSent)
2896
+ response.end(JSON.stringify({ type: "error", error: described.body.error }) + "\n");
2897
+ else
2898
+ json(described.status, described.body);
2899
+ }
2900
+ finally {
2901
+ response.removeListener("close", cancel);
2864
2902
  }
2865
2903
  return;
2866
2904
  }
@@ -216,11 +216,12 @@ const subagents = new SubagentRunRecorder(supervisor, {
216
216
  broadcaster.broadcastState();
217
217
  },
218
218
  // The full state broadcast moved from "every delta" to "on settle": a browser that reloads mid-run
219
- // rebuilds the card from the store (written per delta); the settle frame is what puts the FINAL
219
+ // rebuilds the card from the current store snapshot; the settle frame puts the final
220
220
  // record into `state` so a reload after the finish sees it too.
221
221
  onSettled: legacySubagentFlood ? undefined : () => broadcaster.broadcastState(),
222
222
  liveTailCap: legacySubagentFlood ? Number.POSITIVE_INFINITY : undefined,
223
223
  host: (conversationId, runId) => extensionUiService.createHost(conversationId, runId),
224
+ closeHost: (conversationId, runId) => extensionUiService.cancelPendingUi(conversationId, "aborted", { runId }),
224
225
  });
225
226
  /**
226
227
  * The orchestration engine: walks a whole plan the primary agent declared, dispatching each step through
@@ -305,8 +306,8 @@ const terminalService = new TerminalService({
305
306
  * Background command execution, independent from subagents. Uses node-pty to run shell commands
306
307
  * and delivers results via WebSocket + injected conversation message.
307
308
  */
308
- const execService = new ExecService((event) => broadcaster.broadcast(event), (sessionId, exitCode, stdout, stderr) => runService.enqueueExecResult(sessionId, exitCode, stdout, stderr));
309
- runService.setExecService(execService);
309
+ const execService = new ExecService((event) => broadcaster.broadcast(event), (sessionId, exitCode, stdout, stderr, completion) => runService.enqueueExecResult(sessionId, exitCode, stdout, stderr, completion), (sessionId, output, offset) => store.checkpointBackgroundOutput(sessionId, output, offset));
310
+ runService.setExecService(execService, join(dataDir, "background-logs"));
310
311
  replayRuntime = (state, scope) => execService.outputSnapshots(state, scope);
311
312
  projectRuntime = state => {
312
313
  const visible = new Set(state.conversations.map(conversation => conversation.id));
@@ -393,7 +394,7 @@ async function shutdown(reason) {
393
394
  const httpClosed = closeHttpServer();
394
395
  // Kill every shell BEFORE the sockets close, so a PTY is never outlived by the server that owns it.
395
396
  terminalService.closeAll();
396
- execService.closeAll();
397
+ const execClosed = execService.closeAll();
397
398
  runService.abortAll();
398
399
  workflows.abortAll();
399
400
  // The scheduler stops BEFORE the runs are waited for, so no new task starts while the server is
@@ -404,6 +405,7 @@ async function shutdown(reason) {
404
405
  extensionUiService.cancelPendingUi(c.id, "aborted");
405
406
  }
406
407
  await sessionOrchestratorService.watchdog.dispose();
408
+ await execClosed;
407
409
  await Promise.all([runService.waitForIdle(), workflows.waitForIdle()]);
408
410
  // THE LIVE SESSIONS GO NEXT, AND THEY HAVE TO GO EXPLICITLY. `runService.abortAll()` stops the
409
411
  // TURNS, and a stopped turn is not a stopped session: a session with nothing running on it is idle,
@@ -415,8 +417,6 @@ async function shutdown(reason) {
415
417
  // The capabilities die AFTER the sessions that carry them: a session that is still alive could
416
418
  // otherwise use a credential the server has already forgotten about.
417
419
  releaseAllCapabilities();
418
- // Clean up background tasks so the flushed state never freezes running zombies on disk.
419
- await store.clearBackgroundTasks();
420
420
  await store.flush();
421
421
  wsServer.close();
422
422
  httpServer.closeAllConnections();
@@ -3,7 +3,8 @@ import type { AppStateRepository } from "./persistence/app-state-repository.js";
3
3
  import { defaultJsonStatePath } from "./persistence/json-state-repository.js";
4
4
  import type { ScheduledTask } from "./scheduled-tasks.js";
5
5
  import type { WorkflowRun } from "./workflow.js";
6
- import type { AppState, Conversation, Message, MessageDelivery, MessageImage, ModelSelection, Project, SubagentRun, SubagentRunUpdate, TodoItem, ToolCallQuestion, ToolCallArg, ToolCallBlock, ToolResultSummary, Workspace } from "./types.js";
6
+ import type { AppState, BackgroundTaskSummary, Conversation, Message, MessageDelivery, MessageImage, ModelSelection, Project, SubagentRun, SubagentRunUpdate, TodoItem, ToolCallQuestion, ToolCallArg, ToolCallBlock, ToolResultSummary, Workspace } from "./types.js";
7
+ import { type BackgroundCompletion } from "../shared/background-task.js";
7
8
  import type { TurnUsageReadout } from "./conversation-usage.js";
8
9
  /** Mints the id a forked conversation will have, BEFORE its Pi transcript exists.
9
10
  *
@@ -512,6 +513,7 @@ export declare class Store {
512
513
  */
513
514
  addToolMessage(conversationId: string, content: string, options?: {
514
515
  delivery?: MessageDelivery;
516
+ prioritizeWaiting?: boolean;
515
517
  }): Promise<Message>;
516
518
  /**
517
519
  * Records the model a conversation runs on. `updatedAt` is deliberately NOT touched, for the same
@@ -842,30 +844,10 @@ export declare class Store {
842
844
  * already decided, so it is refused instead.
843
845
  */
844
846
  reorderWaitingMessage(conversationId: string, messageId: string, toIndex: number): Promise<Message>;
847
+ private moveWaitingMessage;
845
848
  /**
846
- * Pi has just delivered one steered message: unmark it and open the answer to it, in ONE write.
847
- *
848
- * Oldest rather than matched on text, and that is forced on us by Pi rather than chosen: Pi identifies
849
- * its own queued entry by `indexOf` on the message text (`agent-session.ts:1123`), so two identical
850
- * steered messages are ONE entry to it and no host-side matching could do better. Position is sufficient
851
- * anyway because Pi's steering queue is FIFO and Super Pi only ever steers from the front of the waiting
852
- * group.
853
- *
854
- * ONE WRITE, because the reader must never see the intermediate: a message that has stopped waiting but
855
- * has no answer under it yet is the exact broken state this refactor exists to remove, and a browser
856
- * that broadcast between the two halves would put it right back on screen.
857
- *
858
- * WHAT IS DIFFERENT FROM BEFORE, and is the whole point: the message used to be DELETED here. It is now
859
- * merely unmarked, with an assistant message spliced in after it. It was on screen the whole time - it
860
- * was written into the transcript when the user pressed send, long before Pi ever saw it - and it stays
861
- * exactly where it was, now with the agent answering it. Deleting it is what made a steered reply appear
862
- * with no question above it.
863
- *
864
- * `messageId` says WHICH message Pi picked up, for the case where position cannot answer it. A message
865
- * handed to Pi's follow-up queue was never CLAIMED here - it is still `waiting`, because Super Pi keeps
866
- * it in its own list so the user can still withdraw it - and a conversation can hold a `waiting` message
867
- * and a `sending` one at the same time. The caller resolves the delivery by the text Pi announced,
868
- * which is the same text Pi itself matched on.
849
+ * Open the reply to a Pi steer and clear its delivery state in one write.
850
+ * The text match and the FIFO fallback both require a claimed `sending` row.
869
851
  */
870
852
  deliverWaitingMessage(conversationId: string, agentIdentity?: Message["agentIdentity"], messageId?: string): Promise<{
871
853
  user: Message;
@@ -961,6 +943,9 @@ export declare class Store {
961
943
  */
962
944
  setWorkflow(plan: WorkflowRun): Promise<WorkflowRun>;
963
945
  setBackgroundTask(summary: AppState["backgroundTasks"][number]): Promise<void>;
946
+ backgroundTask(id: string): BackgroundTaskSummary | undefined;
947
+ checkpointBackgroundOutput(id: string, output: string, offset: number): Promise<void>;
948
+ finishBackgroundTask(taskId: string, outcome: BackgroundCompletion, content: string, deliver: boolean): Promise<Message | undefined>;
964
949
  removeBackgroundTask(id: string): Promise<void>;
965
950
  clearBackgroundTasks(): Promise<void>;
966
951
  /**
@@ -998,6 +983,8 @@ export declare class Store {
998
983
  * as durable as the conversation it belongs to.
999
984
  */
1000
985
  setSubagentRun(runId: string, changes: SubagentRunUpdate): Promise<SubagentRun>;
986
+ updateSubagentProgress(runId: string, changes: SubagentRunUpdate): void;
987
+ checkpointSubagentProgress(runId: string): Promise<void>;
1001
988
  /**
1002
989
  * Adds ONE settled run's usage to the ledger of the conversation that dispatched it.
1003
990
  *