@evandu/super-pi 0.1.173 → 0.1.175

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 (42) hide show
  1. package/agents/super-pi-task/core.ts +16 -4
  2. package/agents/super-pi-task/index.ts +1 -1
  3. package/dist/client/.super-pi-client-sources.json +5 -5
  4. package/dist/client/assets/{CodeMirrorEditor-D16PhUtl.js → CodeMirrorEditor-DwtVhvhP.js} +2 -2
  5. package/dist/client/assets/{dist-Cvd_HNHQ.js → dist-B5HaTMDn.js} +1 -1
  6. package/dist/client/assets/{dist-DpheD_fI.js → dist-BfwhoJ2c.js} +1 -1
  7. package/dist/client/assets/{dist-DkSDmm10.js → dist-Bs2J7cm7.js} +1 -1
  8. package/dist/client/assets/{dist-Bqf4AFSG.js → dist-BvjjidDY.js} +1 -1
  9. package/dist/client/assets/{dist-DbB7ZidH.js → dist-CHLXZD6Z.js} +1 -1
  10. package/dist/client/assets/{dist-1GXRvDR1.js → dist-C_3vxg18.js} +1 -1
  11. package/dist/client/assets/{dist-C_SXdpNv.js → dist-CaVt9IMZ.js} +1 -1
  12. package/dist/client/assets/{dist-CL1Ki8GP.js → dist-Ce50Y3kx.js} +1 -1
  13. package/dist/client/assets/{dist-D48gpXNQ.js → dist-CnQpZpXf.js} +1 -1
  14. package/dist/client/assets/{dist-CadBK3NN.js → dist-CxcCl9nU.js} +1 -1
  15. package/dist/client/assets/{dist-D24sIKu3.js → dist-DKu5ZQPe.js} +1 -1
  16. package/dist/client/assets/{dist-EJz8fe04.js → dist-DUlq1w0J.js} +1 -1
  17. package/dist/client/assets/{dist-Dacz4073.js → dist-DjKLhP2P.js} +1 -1
  18. package/dist/client/assets/{dist-CYGR8bra.js → dist-EJoljryk.js} +1 -1
  19. package/dist/client/assets/{dist-3gpHQ0_V.js → dist-G3kXm5bB.js} +1 -1
  20. package/dist/client/assets/{dist-JdUqjNld.js → dist-LjIserDZ.js} +1 -1
  21. package/dist/client/assets/{dist-CaZSp208.js → dist-Oz3xTF4n.js} +1 -1
  22. package/dist/client/assets/{dist-CFRmrXZ1.js → dist-aLwW7rgW.js} +1 -1
  23. package/dist/client/assets/{dist-BV4WeHxm.js → dist-bRSb7mNW.js} +1 -1
  24. package/dist/client/assets/{dist-kc6GTRR3.js → dist-ddEYIZIm.js} +1 -1
  25. package/dist/client/assets/{dist-7cS5OlwM.js → dist-gOkylN4I.js} +1 -1
  26. package/dist/client/assets/{dist-DSqCJ-sB.js → dist-rsaX54pd.js} +1 -1
  27. package/dist/client/assets/{index-Gp-tvzLo.css → index-DAKtgLA9.css} +1 -1
  28. package/dist/client/assets/{index-BneDTUV6.js → index-ZnFnQvel.js} +14 -14
  29. package/dist/client/index.html +2 -2
  30. package/dist/server/application/conversation-service.d.ts +38 -0
  31. package/dist/server/application/conversation-service.js +40 -0
  32. package/dist/server/application/project-service.js +111 -7
  33. package/dist/server/command-handler.js +23 -0
  34. package/dist/server/http-server.js +13 -1
  35. package/dist/server/store.d.ts +31 -0
  36. package/dist/server/store.js +55 -0
  37. package/dist/server/task-tool.d.ts +1 -1
  38. package/dist/server/task-tool.js +1 -1
  39. package/dist/server/types.d.ts +30 -1
  40. package/dist/shared/child-session-lock.d.ts +29 -0
  41. package/dist/shared/child-session-lock.js +51 -0
  42. package/package.json +10 -3
@@ -8,8 +8,8 @@
8
8
  <link rel="alternate icon" href="/favicon.ico" />
9
9
  <link rel="apple-touch-icon" href="/favicon.svg" />
10
10
  <title>Super Pi</title>
11
- <script type="module" crossorigin src="/assets/index-BneDTUV6.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-Gp-tvzLo.css">
11
+ <script type="module" crossorigin src="/assets/index-ZnFnQvel.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index-DAKtgLA9.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="root"></div>
@@ -16,6 +16,15 @@ export type ForkConversationResult = {
16
16
  ok: false;
17
17
  message: string;
18
18
  };
19
+ /**
20
+ * THE LOCK STATE OF ONE CONVERSATION'S COMPOSER.
21
+ *
22
+ * "top" - a top-level session. The reader talks to it directly, and always could.
23
+ * "locked" - a child session whose parent is still alive: the reporting line only runs
24
+ * upwards, so the reader does not talk to it directly.
25
+ * "unlocked" - a child session the reader deliberately opened.
26
+ */
27
+ export type ChildLockState = "top" | "locked" | "unlocked";
19
28
  /**
20
29
  * Service managing conversation lifecycle: creation, selection, archiving,
21
30
  * model/thinking/agent configuration, message reversion, and session forking.
@@ -62,6 +71,35 @@ export declare class ConversationService {
62
71
  * a log and in a retry.
63
72
  */
64
73
  autoRenameConversation(conversationId: string): Promise<string>;
74
+ /**
75
+ * THE LOCK STATE OF ONE CONVERSATION'S COMPOSER.
76
+ *
77
+ * "top" - a top-level session: the reader talks to it directly, and always could.
78
+ * "locked" - a child session whose parent is still alive. The reader may not talk to it
79
+ * directly; the reporting line runs upwards, one level at a time.
80
+ * "unlocked" - a child session the reader deliberately opened.
81
+ *
82
+ * THE ORPHAN IS "top". A conversation whose parent was archived and left behind has nobody
83
+ * above it to report to, so there is no reporting line for it to bypass - and locking it would
84
+ * lock a conversation that the rules do not cover.
85
+ *
86
+ * The judgement itself lives in `src/shared/child-session-lock.ts` because the browser draws
87
+ * the very same lock: two implementations of "what is a child session" would eventually
88
+ * disagree, and the two ways to disagree are both bad (a lock the server does not honour, and a
89
+ * refusal the interface never explained).
90
+ */
91
+ childLockState(conversationId: string): ChildLockState;
92
+ /**
93
+ * Opens (or re-closes) ONE child session's composer.
94
+ *
95
+ * The server owns this state, because the server is what refuses the message. The browser keeps
96
+ * a copy per conversation in localStorage so the choice survives a reload, but that copy is a
97
+ * mirror: the server's answer is the one that decides.
98
+ *
99
+ * Re-locking is a real door, not a one-way street: `unlocked: false` puts the lock back, and a
100
+ * lock that could only be opened would not be a lock.
101
+ */
102
+ setChildLock(conversationId: string, unlocked: boolean): Promise<void>;
65
103
  /**
66
104
  * The model a conversation has selected, or undefined when it follows Pi's default.
67
105
  *
@@ -1,6 +1,7 @@
1
1
  import { assertModelAllowed } from "../model-filter.js";
2
2
  import { newConversationId } from "../store.js";
3
3
  import { normalizeSessionCwd, resolveSessionCwd } from "../session-cwd.js";
4
+ import { isChildSession } from "../../shared/child-session-lock.js";
4
5
  function isMissingPrimaryAgent(error, agentId) {
5
6
  const message = error instanceof Error ? error.message : String(error);
6
7
  const id = JSON.stringify(agentId);
@@ -158,6 +159,45 @@ export class ConversationService {
158
159
  throw new Error("当前没有可用的 Pi 进程,无法生成标题");
159
160
  return this.runtime.summarizeConversation(conversation, workspace.path);
160
161
  }
162
+ /**
163
+ * THE LOCK STATE OF ONE CONVERSATION'S COMPOSER.
164
+ *
165
+ * "top" - a top-level session: the reader talks to it directly, and always could.
166
+ * "locked" - a child session whose parent is still alive. The reader may not talk to it
167
+ * directly; the reporting line runs upwards, one level at a time.
168
+ * "unlocked" - a child session the reader deliberately opened.
169
+ *
170
+ * THE ORPHAN IS "top". A conversation whose parent was archived and left behind has nobody
171
+ * above it to report to, so there is no reporting line for it to bypass - and locking it would
172
+ * lock a conversation that the rules do not cover.
173
+ *
174
+ * The judgement itself lives in `src/shared/child-session-lock.ts` because the browser draws
175
+ * the very same lock: two implementations of "what is a child session" would eventually
176
+ * disagree, and the two ways to disagree are both bad (a lock the server does not honour, and a
177
+ * refusal the interface never explained).
178
+ */
179
+ childLockState(conversationId) {
180
+ const facts = this.store.childSessionFacts(conversationId);
181
+ if (!isChildSession(facts.parentConversationId, facts.parent))
182
+ return "top";
183
+ return this.store.childLockUnlocked(conversationId) ? "unlocked" : "locked";
184
+ }
185
+ /**
186
+ * Opens (or re-closes) ONE child session's composer.
187
+ *
188
+ * The server owns this state, because the server is what refuses the message. The browser keeps
189
+ * a copy per conversation in localStorage so the choice survives a reload, but that copy is a
190
+ * mirror: the server's answer is the one that decides.
191
+ *
192
+ * Re-locking is a real door, not a one-way street: `unlocked: false` puts the lock back, and a
193
+ * lock that could only be opened would not be a lock.
194
+ */
195
+ async setChildLock(conversationId, unlocked) {
196
+ if (!this.store.conversation(conversationId))
197
+ throw new Error("找不到这个会话。");
198
+ await this.store.setChildLockUnlocked(conversationId, unlocked);
199
+ this.broadcaster.broadcastState();
200
+ }
161
201
  /**
162
202
  * The model a conversation has selected, or undefined when it follows Pi's default.
163
203
  *
@@ -179,6 +179,12 @@ const PROJECT_LIST_LIMIT = 20;
179
179
  * one, because dropping any of them would drop the answer to "what did this project do".
180
180
  */
181
181
  const REPORT_EVENT_LIMIT = 200;
182
+ /**
183
+ * HOW LONG A CELL MAY BE. The table is read down a column, so a cell has to stay short enough to
184
+ * be read without scrolling sideways - and when a cell is cut, the cut says so, because a silent
185
+ * cut reads as the whole truth. The full text is never lost: it is printed below the table.
186
+ */
187
+ const DECISION_CELL_LIMIT = 40;
182
188
  // THE WORDS THE REPORT SPEAKS IN. A reader of the report is a person, not a console, so every
183
189
  // state and every role is written the way a person would say it out loud.
184
190
  const PROJECT_STATUS_TEXT = {
@@ -243,6 +249,90 @@ const exceptionTitle = (exception) => {
243
249
  return oneLine(title);
244
250
  return firstSentence(exception.reason ?? "") || "(未命名)";
245
251
  };
252
+ /**
253
+ * THE DECISION IN ONE LINE - OR THE WORD THAT SAYS THERE IS NONE.
254
+ *
255
+ * A decision is the Boss's own words about an exception, and his words are a paragraph: why he
256
+ * decided that, what he accepts, what happens next. The cell in the table is a column to read
257
+ * DOWN, not a paragraph to read - a paragraph in a cell makes the row as tall as the longest
258
+ * case, and a table whose rows are all tall is a list with borders. So the cell carries the FIRST
259
+ * SENTENCE of the decision - the part that stands on its own - and the whole decision is printed
260
+ * below the table, where a paragraph belongs.
261
+ *
262
+ * An exception nobody has answered yet says 「无」, and keeps saying it until somebody answers.
263
+ */
264
+ const decisionCell = (decision) => {
265
+ const text = (decision ?? "").trim();
266
+ if (!text)
267
+ return "无";
268
+ return truncate(firstSentence(text), DECISION_CELL_LIMIT);
269
+ };
270
+ /**
271
+ * A PROSE, PRINTED AS THE PROSE IS.
272
+ *
273
+ * The complaint this answers: a case that arrived with its line breaks in it was printed as ONE
274
+ * line - the newline was flattened into a space. Not one word was lost, but the SHAPE was: three
275
+ * sentences the writer had deliberately put on three lines came out as one long string, and a
276
+ * reader could no longer see where one thought ended and the next began. That is the "报告文学
277
+ * 有点混乱" the exported report was blamed for.
278
+ *
279
+ * So the line breaks are kept, and they are kept as MARKDOWN line breaks: a blank line in the
280
+ * source stays a blank line - a paragraph of its own - and a single line break inside a paragraph
281
+ * is written as a HARD break (two trailing spaces). A soft break is a space in half the Markdown
282
+ * readers in the world, and this report is read by people.
283
+ *
284
+ * The lines are indented, because they sit inside a list item, and a list item's content that is
285
+ * not indented has already left the item.
286
+ */
287
+ const proseBlock = (value, indent) => {
288
+ const normalized = value.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
289
+ const out = [];
290
+ for (const paragraph of normalized.split(/\n{2,}/)) {
291
+ const lines = paragraph.split("\n");
292
+ if (!lines.some((line) => line.trim()))
293
+ continue;
294
+ if (out.length)
295
+ out.push("");
296
+ lines.forEach((line, index) => {
297
+ if (!line.trim()) {
298
+ out.push("");
299
+ return;
300
+ }
301
+ /* THE HARD BREAK goes on the line BEFORE the break, because that is where Markdown looks
302
+ for it: two spaces at the end of a line mean "the next line starts a new line". */
303
+ const next = lines[index + 1];
304
+ const hard = next !== undefined && next.trim() ? " " : "";
305
+ out.push(`${indent}${line.replace(/\s+$/, "")}${hard}`);
306
+ });
307
+ }
308
+ while (out.length && !out[0].trim())
309
+ out.shift();
310
+ return out;
311
+ };
312
+ /**
313
+ * ONE DETAIL ITEM: THE QUESTION ON THE BULLET, THE CASE UNDER IT.
314
+ *
315
+ * The bullet carries the question - one line, the thing the reader decides on - and the case,
316
+ * which is a paragraph, is printed under it with its own paragraphs. The blank line between the
317
+ * two is what makes them two paragraphs instead of one run-on line.
318
+ *
319
+ * AN EXCEPTION WITHOUT A TITLE has no question to put on the bullet, so the case starts on the
320
+ * bullet itself - the way it has always been printed - and the rest of it is indented under it.
321
+ * Nothing is said twice: an exception is not labelled with the first sentence of its own case and
322
+ * then printed with that case all over again.
323
+ */
324
+ const detailItem = (label, prose) => {
325
+ /* THE NAME IS NOT `body` ON PURPOSE: a local called `body` reads like a read off the request
326
+ body, and the tool-surface gate reads it as one. */
327
+ const block = proseBlock(prose, " ");
328
+ if (label === undefined) {
329
+ if (!block.length)
330
+ return [];
331
+ const [first, ...rest] = block;
332
+ return [`- ${first.replace(/^\s+/, "")}`, ...rest];
333
+ }
334
+ return ["- " + label, "", ...block];
335
+ };
246
336
  /**
247
337
  * THE TWO SHAPES A PROJECT CAN HAVE.
248
338
  *
@@ -1022,24 +1112,38 @@ export class ProjectService {
1022
1112
  else {
1023
1113
  /* THE TABLE IS FOR COMPARING, so the cell is a TITLE - the question the reader decides on -
1024
1114
  and the case goes under the table. A whole paragraph in one cell makes the table
1025
- unreadable, and a table that cannot be scanned is not a table any more. */
1115
+ unreadable, and a table that cannot be scanned is not a table any more. THE SAME RULE
1116
+ GOVERNS THE DECISION COLUMN: a decision is the Boss's paragraph, so the cell carries its
1117
+ first sentence and the paragraph itself is printed below the table. */
1026
1118
  lines.push("| 例外 | 严重程度 | 状态 | 决定 | 解决时间 |", "| --- | --- | --- | --- | --- |");
1027
1119
  for (const e of p.escalations) {
1028
- lines.push(`| ${cell(exceptionTitle(e))} | ${SEVERITY_TEXT[e.severity] ?? e.severity} | ${ESCALATION_STATUS_TEXT[e.status] ?? e.status} | ${cell(e.decision ?? "无")} | ${e.resolvedAt ? moment(e.resolvedAt) : "无"} |`);
1120
+ lines.push(`| ${cell(exceptionTitle(e))} | ${SEVERITY_TEXT[e.severity] ?? e.severity} | ${ESCALATION_STATUS_TEXT[e.status] ?? e.status} | ${cell(decisionCell(e.decision))} | ${e.resolvedAt ? moment(e.resolvedAt) : "无"} |`);
1029
1121
  }
1030
1122
  /* AND THE CASE IS NOT LOST. The title is what the reader compares; the reason is WHY, and it
1031
- is a paragraph - so it is printed in full below the table, where a paragraph belongs. */
1123
+ is a paragraph - so it is printed in full below the table, where a paragraph belongs. AND
1124
+ IT KEEPS ITS PARAGRAPHS: the line breaks the writer put in it are line breaks here too,
1125
+ because a case flattened into one long line is the "报告文学有点混乱" the report was
1126
+ blamed for. */
1032
1127
  const cases = p.escalations.filter((e) => (e.reason ?? "").trim());
1033
1128
  if (cases.length) {
1034
1129
  lines.push("", "例外详情:", "");
1035
1130
  for (const e of cases) {
1036
1131
  /* AN EXCEPTION WITH A TITLE is named by it; one without has only its case, and the case
1037
- is already the whole line - repeating its first sentence in front of it would say the
1038
- same thing twice. */
1039
- const title = e.title?.trim();
1040
- lines.push(title ? `- ${oneLine(title)}:${oneLine(e.reason)}` : `- ${oneLine(e.reason)}`);
1132
+ starts on the bullet itself - so the case is not printed twice under a label that is
1133
+ its own first sentence. */
1134
+ const label = e.title?.trim();
1135
+ lines.push(...detailItem(label ? label : undefined, e.reason ?? ""));
1041
1136
  }
1042
1137
  }
1138
+ /* AND NEITHER IS THE DECISION. The column carries the first sentence; the Boss's whole
1139
+ paragraph - why he decided that, and what he accepts - is printed here, below the table,
1140
+ next to the case it answers. */
1141
+ const decided = p.escalations.filter((e) => (e.decision ?? "").trim());
1142
+ if (decided.length) {
1143
+ lines.push("", "决定详情:", "");
1144
+ for (const e of decided)
1145
+ lines.push(...detailItem(exceptionTitle(e), e.decision ?? ""));
1146
+ }
1043
1147
  }
1044
1148
  lines.push("", "## 时间线", "");
1045
1149
  const events = [...(p.events ?? [])].sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
@@ -1,6 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { join } from "node:path";
3
3
  import { KNOWN_APIS } from "./providers.js";
4
+ import { CHILD_SESSION_LOCK_REASON } from "../shared/child-session-lock.js";
4
5
  import { packageUpdateArgs } from "./update.js";
5
6
  /**
6
7
  * Routes client commands to appropriate application services and converts results or errors.
@@ -204,6 +205,13 @@ export class CommandHandler {
204
205
  await this.conversationService.setCollapsed(command.conversationId, command.collapsed);
205
206
  return;
206
207
  }
208
+ // THE LOCK ON A CHILD SESSION'S COMPOSER. The browser asks; the server answers. The state is
209
+ // the server's (`AppState.unlockedChildConversationIds`), so a second tab, a stale window or a
210
+ // hand-written frame all meet the same door.
211
+ if (command.type === "conversation.childLock") {
212
+ await this.conversationService.setChildLock(command.conversationId, command.unlocked);
213
+ return;
214
+ }
207
215
  if (command.type === "conversation.archive") {
208
216
  await this.conversationService.archiveConversation(command.conversationId);
209
217
  return;
@@ -240,6 +248,21 @@ export class CommandHandler {
240
248
  return;
241
249
  }
242
250
  if (command.type === "message.send") {
251
+ // THE LOCK IS NOT ONLY A DRAWING. A child session's composer is locked in the interface, and
252
+ // this is the half that makes the lock real: the reporting line only runs upwards, one level
253
+ // at a time, so the reader does not talk to a child session directly - unless they deliberately
254
+ // opened that one session.
255
+ //
256
+ // The refusal is the server's own sentence, and it is the SAME sentence the lock shows
257
+ // (`src/shared/child-session-lock.ts`): the interface and the server must not disagree about
258
+ // what the rule is, because the reader is the one who has to live with both.
259
+ //
260
+ // The agent's own way up - `session_dispatch` - does NOT come through here: it goes through
261
+ // `enqueueAndRunAsAgent`, which is a different door. A lock on the reader is not a lock on the
262
+ // team.
263
+ if (this.conversationService.childLockState(command.conversationId) === "locked") {
264
+ throw new Error(CHILD_SESSION_LOCK_REASON);
265
+ }
243
266
  // A send that races a revert would be appended to a history the model is still reading in full - the
244
267
  // turn the person just withdrew would still be in its context, and the new answer would be built on
245
268
  // top of it. Refusing with a sentence beats accepting a turn built on a cut that has not landed yet.
@@ -1736,7 +1736,19 @@ export function createHttpServer(options) {
1736
1736
  cwd: body.cwd,
1737
1737
  watchdogTimeoutSeconds: body.watchdogTimeoutSeconds ?? body.watchdog_timeout_seconds ?? body.watchdogSeconds,
1738
1738
  });
1739
- json(200, { ok: true, ...result });
1739
+ // THE ANSWER CARRIES THE CHILD'S REAL STATE, NOT A LITERAL.
1740
+ //
1741
+ // This is the child's first appearance in the world, and the state that goes with it is
1742
+ // read out of the store AT THIS INSTANT rather than written down here. A literal would be
1743
+ // a claim: the child may already have finished its turn, or may not have started one yet,
1744
+ // and neither of those is "running" by the time anybody reads the answer.
1745
+ //
1746
+ // WHAT IT IS, EXACTLY: a snapshot of one moment. An asynchronous spawn races its own
1747
+ // child - the state here is whatever the store holds when this line runs, and the child
1748
+ // keeps moving after it. So the caller that renders this must not treat it as a promise;
1749
+ // `session_status` is how anybody asks for the present.
1750
+ const spawnedStatus = context.store.conversationStatus(result.conversationId);
1751
+ json(200, { ok: true, ...result, status: spawnedStatus });
1740
1752
  return;
1741
1753
  }
1742
1754
  // THE SCOPE RULE, IN ONE PLACE, FOR EVERY ACTION THAT TOUCHES ANOTHER SESSION.
@@ -291,6 +291,37 @@ export declare class Store {
291
291
  * screen and the disk disagreeing.
292
292
  */
293
293
  setConversationCollapsed(conversationId: string, collapsed: boolean): Promise<void>;
294
+ /**
295
+ * Whether the reader has opened one child session's composer.
296
+ *
297
+ * THE SERVER OWNS THIS FACT. The browser keeps a copy per conversation (so the choice survives a
298
+ * reload), but the copy is a mirror: what the server says is what happens. A browser that owned
299
+ * it could unlock a session the server still refuses, and the reader would be told 「发送失败」
300
+ * for a message that was never allowed to be sent.
301
+ */
302
+ childLockUnlocked(conversationId: string): boolean;
303
+ /**
304
+ * Opens (or re-closes) one child session's composer, and persists it.
305
+ *
306
+ * The assign -> persist -> rollback pattern `setConversationCollapsed` established: the in-memory
307
+ * value is the previous value again the moment persistence fails, so a rejected write can never
308
+ * leave the screen and the disk disagreeing about whether the door is open.
309
+ */
310
+ setChildLockUnlocked(conversationId: string, unlocked: boolean): Promise<void>;
311
+ /**
312
+ * THE CHILD-SESSION FACTS OF ONE CONVERSATION: its own parent edge, and the parent's row.
313
+ *
314
+ * Narrow on purpose: the send path asks this on EVERY message, and `store.conversation()` clones
315
+ * the whole transcript - a long conversation would pay for its entire history to answer one
316
+ * yes/no question. Two rows, read in place, and nothing copied.
317
+ */
318
+ childSessionFacts(conversationId: string): {
319
+ parentConversationId?: string;
320
+ parent?: {
321
+ id: string;
322
+ archivedAt?: string;
323
+ };
324
+ };
294
325
  /**
295
326
  * Copies a conversation into a NEW one, under an id the caller has already minted.
296
327
  *
@@ -1259,6 +1259,61 @@ export class Store {
1259
1259
  throw error;
1260
1260
  }
1261
1261
  }
1262
+ /**
1263
+ * Whether the reader has opened one child session's composer.
1264
+ *
1265
+ * THE SERVER OWNS THIS FACT. The browser keeps a copy per conversation (so the choice survives a
1266
+ * reload), but the copy is a mirror: what the server says is what happens. A browser that owned
1267
+ * it could unlock a session the server still refuses, and the reader would be told 「发送失败」
1268
+ * for a message that was never allowed to be sent.
1269
+ */
1270
+ childLockUnlocked(conversationId) {
1271
+ return Boolean(this.state.unlockedChildConversationIds?.includes(conversationId));
1272
+ }
1273
+ /**
1274
+ * Opens (or re-closes) one child session's composer, and persists it.
1275
+ *
1276
+ * The assign -> persist -> rollback pattern `setConversationCollapsed` established: the in-memory
1277
+ * value is the previous value again the moment persistence fails, so a rejected write can never
1278
+ * leave the screen and the disk disagreeing about whether the door is open.
1279
+ */
1280
+ async setChildLockUnlocked(conversationId, unlocked) {
1281
+ const previous = this.state.unlockedChildConversationIds;
1282
+ const next = new Set(previous ?? []);
1283
+ if (unlocked)
1284
+ next.add(conversationId);
1285
+ else
1286
+ next.delete(conversationId);
1287
+ if (next.size === 0)
1288
+ delete this.state.unlockedChildConversationIds;
1289
+ else
1290
+ this.state.unlockedChildConversationIds = [...next];
1291
+ try {
1292
+ await this.persist();
1293
+ }
1294
+ catch (error) {
1295
+ if (previous === undefined)
1296
+ delete this.state.unlockedChildConversationIds;
1297
+ else
1298
+ this.state.unlockedChildConversationIds = previous;
1299
+ throw error;
1300
+ }
1301
+ }
1302
+ /**
1303
+ * THE CHILD-SESSION FACTS OF ONE CONVERSATION: its own parent edge, and the parent's row.
1304
+ *
1305
+ * Narrow on purpose: the send path asks this on EVERY message, and `store.conversation()` clones
1306
+ * the whole transcript - a long conversation would pay for its entire history to answer one
1307
+ * yes/no question. Two rows, read in place, and nothing copied.
1308
+ */
1309
+ childSessionFacts(conversationId) {
1310
+ const conversation = this.state.conversations.find((item) => item.id === conversationId);
1311
+ const parentConversationId = conversation?.parentConversationId;
1312
+ if (!parentConversationId)
1313
+ return {};
1314
+ const parent = this.state.conversations.find((item) => item.id === parentConversationId);
1315
+ return { parentConversationId, ...(parent ? { parent: { id: parent.id, archivedAt: parent.archivedAt } } : {}) };
1316
+ }
1262
1317
  /**
1263
1318
  * Copies a conversation into a NEW one, under an id the caller has already minted.
1264
1319
  *
@@ -262,7 +262,7 @@ export declare const SESSION_STOP_TOOL_NAME = "session_stop";
262
262
  export declare const SESSION_REPORT_TOOL_NAME = "session_report";
263
263
  export declare const SESSION_STOP_SUBTREE_TOOL_NAME = "session_stop_subtree";
264
264
  /** Model-facing description for session_spawn. */
265
- export declare const SESSION_SPAWN_DESCRIPTION = "Create a child conversation in the current workspace and immediately dispatch its initial task. You can specify a primary agent as the child's role.\n\nDIFFERENCE FROM THE 'task' TOOL:\n- The 'task' tool delegates to a transient, one-shot subagent process (scout, critic, patcher) that runs once, returns its final text, and terminates. It has no conversation history and does not appear in the workspace sidebar.\n- 'session_spawn' creates a real, persistent child CONVERSATION in Super Pi. It appears in the sidebar, retains multi-turn message history, can receive follow-up messages via session_dispatch, can be inspected via session_status, and can be stopped via session_stop. The user can also switch to it in the Web UI.\n\nWHEN TO USE THIS:\n- Long-running, multi-phase tracks of work that require ongoing context, multiple turns of dialogue, or independent user visibility.\n- Multi-phase or complex work where the user needs each step to be visible and available for inspection or intervention: create a child session with session_spawn.\n- Parallel work streams (e.g., Track A: backend refactor, Track B: frontend component update) where both need full conversational capabilities.\n- When the user asks you to act as an orchestrator/manager who delegates to multiple sessions.\n\nWHEN NOT TO USE THIS:\n- For one-off, focused delegation with a single answer: use 'task' (with scout/critic/patcher). It is faster, cheaper, and returns directly to your transcript.\n- For running shell commands or build watchers: use 'run_async'.\n- For a single one-off delegation with a single answer: use 'task'.\n\nUsage notes:\n1. Spawning is ASYNCHRONOUS by default: it creates the conversation, enqueues the initial task, and returns the new conversationId immediately. The sibling session runs in the background.\n2. The initial task should provide clear context and goals since the new session starts with a fresh conversation history.\n3. Use session_status with the returned conversationId to check progress, or session_dispatch to send further messages.\n4. The new session reports completion to its DIRECT parent automatically. 'parentConversationId' optionally selects that parent; by default it is the calling session.\n5. The new session always belongs to the calling session's workspace. Pass 'cwd' as a workspace-relative subdirectory (for example, 'packages/a') when it should work below the workspace root; absolute paths and traversal are rejected.\n6. Optionally pass 'model' to choose which model the NEW session runs on: {\"provider\":\"...\",\"modelId\":\"...\"} - the same \"provider/modelId\" pair the model picker shows, and BOTH halves are required. Leave 'model' out and the new session starts on the workspace default model.\n7. Optionally pass 'watchdogTimeoutSeconds' to declare how long YOU are willing to wait for a report before you want to be reminded: a positive number of seconds. If the new session stays silent that long, you receive a '[Watchdog \u63D0\u9192]' message naming it. A report from the child (session_report) restarts the clock; the watchdog never stops the child. Leave it out to run without a watchdog.";
265
+ export declare const SESSION_SPAWN_DESCRIPTION = "Create a child conversation in the current workspace and immediately dispatch its initial task. You can specify a primary agent as the child's role.\n\nDIFFERENCE FROM THE 'task' TOOL:\n- The 'task' tool delegates to a transient, one-shot subagent process (scout, critic, patcher) that runs once, returns its final text, and terminates. It has no conversation history and does not appear in the workspace sidebar.\n- 'session_spawn' creates a real, persistent child CONVERSATION in Super Pi. It appears in the sidebar, retains multi-turn message history, can receive follow-up messages via session_dispatch, can be inspected via session_status, and can be stopped via session_stop. The user can also switch to it in the Web UI.\n\nWHEN TO USE THIS:\n- Long-running, multi-phase tracks of work that require ongoing context, multiple turns of dialogue, or independent user visibility.\n- Multi-phase or complex work where the user needs each step to be visible and available for inspection or intervention: create a child session with session_spawn.\n- Parallel work streams (e.g., Track A: backend refactor, Track B: frontend component update) where both need full conversational capabilities.\n- When the user asks you to act as an orchestrator/manager who delegates to multiple sessions.\n\nWHEN NOT TO USE THIS:\n- For one-off, focused delegation with a single answer: use 'task' (with scout/critic/patcher). It is faster, cheaper, and returns directly to your transcript.\n- For running shell commands or build watchers: use 'run_async'.\n- For a single one-off delegation with a single answer: use 'task'.\n\nUsage notes:\n1. Spawning is ASYNCHRONOUS by default: it creates the conversation, enqueues the initial task, and returns the new conversationId immediately. The sibling session runs in the background.\n2. The initial task should provide clear context and goals since the new session starts with a fresh conversation history.\n3. Use session_status with the returned conversationId to check progress, or session_dispatch to send further messages.\n4. The new session reports completion to its DIRECT parent automatically, and that parent is always the calling session. 'parentConversationId' may only repeat the calling session's own id - the server refuses (403) any other session as the parent and creates nothing.\n5. The new session always belongs to the calling session's workspace. Pass 'cwd' as a workspace-relative subdirectory (for example, 'packages/a') when it should work below the workspace root; absolute paths and traversal are rejected.\n6. Optionally pass 'model' to choose which model the NEW session runs on: {\"provider\":\"...\",\"modelId\":\"...\"} - the same \"provider/modelId\" pair the model picker shows, and BOTH halves are required. Leave 'model' out and the new session starts on the workspace default model.\n7. Optionally pass 'watchdogTimeoutSeconds' to declare how long YOU are willing to wait for a report before you want to be reminded: a positive number of seconds. If the new session stays silent that long, you receive a '[Watchdog \u63D0\u9192]' message naming it. A report from the child (session_report) restarts the clock; the watchdog never stops the child. Leave it out to run without a watchdog.";
266
266
  /** Model-facing description for session_status. */
267
267
  export declare const SESSION_STATUS_DESCRIPTION = "Inspect the progress, run state, and latest activity of sibling conversations created by the orchestrator.\n\nWHEN TO USE THIS:\n- To check whether a spawned sibling conversation is still running, has finished (idle), is stopped, or encountered an error.\n- To read the latest assistant progress snippet without bloating your context with the session's entire raw message transcript.\n- To list all sibling conversations under your coordination when conversationId is omitted.\n\nUsage notes:\n1. When 'conversationId' is provided: returns a compact summary for that specific session, including its run status ('idle', 'running', 'waiting', 'stopped', 'failed'), messageCount, turnCount, lastAssistantSnippet, lastUserSnippet, activeTool, and error (if any).\n2. When 'conversationId' is omitted: returns a summary list of sibling conversations whose direct parent is 'parentConversationId' (the calling session by default).\n3. By default it never returns full transcripts; concise summaries keep your context window lean. Set 'includeOutput' with a conversationId to read the final output from its result file, capped to the last 64Ki characters with an explicit truncation notice.";
268
268
  /** Model-facing description for session_dispatch. */
@@ -388,7 +388,7 @@ Usage notes:
388
388
  1. Spawning is ASYNCHRONOUS by default: it creates the conversation, enqueues the initial task, and returns the new conversationId immediately. The sibling session runs in the background.
389
389
  2. The initial task should provide clear context and goals since the new session starts with a fresh conversation history.
390
390
  3. Use session_status with the returned conversationId to check progress, or session_dispatch to send further messages.
391
- 4. The new session reports completion to its DIRECT parent automatically. 'parentConversationId' optionally selects that parent; by default it is the calling session.
391
+ 4. The new session reports completion to its DIRECT parent automatically, and that parent is always the calling session. 'parentConversationId' may only repeat the calling session's own id - the server refuses (403) any other session as the parent and creates nothing.
392
392
  5. The new session always belongs to the calling session's workspace. Pass 'cwd' as a workspace-relative subdirectory (for example, 'packages/a') when it should work below the workspace root; absolute paths and traversal are rejected.
393
393
  6. Optionally pass 'model' to choose which model the NEW session runs on: {"provider":"...","modelId":"..."} - the same "provider/modelId" pair the model picker shows, and BOTH halves are required. Leave 'model' out and the new session starts on the workspace default model.
394
394
  7. Optionally pass 'watchdogTimeoutSeconds' to declare how long YOU are willing to wait for a report before you want to be reminded: a positive number of seconds. If the new session stays silent that long, you receive a '[Watchdog 提醒]' message naming it. A report from the child (session_report) restarts the clock; the watchdog never stops the child. Leave it out to run without a watchdog.`;
@@ -1192,9 +1192,22 @@ export type AppState = {
1192
1192
  * "nothing collapsed", which is the correct reading of a preference that did not exist yet.
1193
1193
  */
1194
1194
  collapsedConversationIds?: string[];
1195
+ /**
1196
+ * WHICH CHILD SESSIONS THE READER HAS UNLOCKED, by conversation id.
1197
+ *
1198
+ * A child session's composer is locked by default (the reporting line only runs upwards, so the
1199
+ * reader does not talk to a child session directly), and the reader may open ONE of them when
1200
+ * there is a real reason to. The server owns that state: it is the server that refuses the
1201
+ * message, so it has to be the server that knows whether the door is open - otherwise the
1202
+ * browser and the server would be two authorities for one fact.
1203
+ *
1204
+ * Absent (an older state.json) means "nothing unlocked", which is the correct reading of a
1205
+ * decision nobody has made yet.
1206
+ */
1207
+ unlockedChildConversationIds?: string[];
1195
1208
  /**
1196
1209
  * THE CLOCK THIS SERVER SCHEDULES BY. A scheduled task's 「每天 09:00」 is the SERVER's wall clock,
1197
- * and the panel has to say so, because the browser rendering 「下次」 may be on a different clock
1210
+ * and the panel has to say so, because browser rendering 「下次」 may be on a different clock
1198
1211
  * entirely. Without this the two lines in one row quietly mean two different things.
1199
1212
  */
1200
1213
  serverTimeZone?: string;
@@ -1508,6 +1521,22 @@ export type ClientCommandBody =
1508
1521
  type: "conversation.collapse";
1509
1522
  conversationId: string;
1510
1523
  collapsed: boolean;
1524
+ }
1525
+ /**
1526
+ * OPENS (OR RE-CLOSES) ONE CHILD SESSION'S COMPOSER.
1527
+ *
1528
+ * The state lives SERVER-SIDE (`AppState.unlockedChildConversationIds`), not in the browser: the
1529
+ * server is what refuses the message, so the server is what has to know whether the door is
1530
+ * open. A browser that kept the only copy would be a browser that could unlock a session the
1531
+ * server still refuses - and the reader would be told 「发送失败」 for a message that was never
1532
+ * allowed to be sent in the first place.
1533
+ *
1534
+ * `unlocked: false` is the way back. A lock that could only be opened would not be a lock.
1535
+ */
1536
+ | {
1537
+ type: "conversation.childLock";
1538
+ conversationId: string;
1539
+ unlocked: boolean;
1511
1540
  } | {
1512
1541
  type: "conversation.rename";
1513
1542
  conversationId: string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * THE SENTENCE. The lock says it, and the server refuses with it.
3
+ *
4
+ * IT SAYS THE RULE, NOT 「禁止」. A refusal that only says "forbidden" leaves the reader with
5
+ * nothing to do; a refusal that names the rule and the way out is something the reader can act
6
+ * on. This is why the sentence is one sentence and why it is shared: the interface and the
7
+ * server must not disagree about what the rule is.
8
+ */
9
+ export declare const CHILD_SESSION_LOCK_REASON = "\u6C47\u62A5\u7EBF\u53EA\u5141\u8BB8\u9010\u7EA7\u4E0A\u5347\uFF0C\u5B50\u4F1A\u8BDD\u9ED8\u8BA4\u4E0D\u80FD\u76F4\u63A5\u5BF9\u8BDD\uFF1B\u786E\u6709\u7279\u6B8A\u60C5\u51B5\u53EF\u89E3\u9501\u3002";
10
+ /** The minimum a parent row has to expose for the judgement to be made. */
11
+ export type ChildSessionRow = {
12
+ id: string;
13
+ archivedAt?: string;
14
+ };
15
+ /**
16
+ * Whether a conversation is a CHILD SESSION: it hangs under a parent that is still ALIVE.
17
+ *
18
+ * A conversation with no parent at all is top-level, and so is an ORPHAN - one whose parent was
19
+ * archived and left behind. Both of them can talk to the reader directly, because there is no
20
+ * reporting line above them to bypass.
21
+ *
22
+ * `parentConversationId` is the conversation's own edge, and `parent` is the parent's row (or
23
+ * undefined when there is no such row any more). Both sides answer the question from their own
24
+ * rows - the client from `state.conversations`, the server from its store - and neither of them
25
+ * has to hand this function a whole conversation: the server's send path asks this on EVERY
26
+ * message, and a long conversation must not pay for its entire transcript to answer one yes/no
27
+ * question.
28
+ */
29
+ export declare function isChildSession(parentConversationId: string | undefined, parent: ChildSessionRow | undefined): boolean;
@@ -0,0 +1,51 @@
1
+ // 子会话的输入框默认上锁 —— 两边共用的两件东西:那句话,和「什么是子会话」这个判据。
2
+ //
3
+ // WHY THIS FILE EXISTS.
4
+ //
5
+ // 一条规矩被写了两遍,就会有两遍的规矩。锁要挡的东西有两半:一半在界面上(画一把看得见的
6
+ // 锁),一半在服务端(拒绝这条用户消息)。这两半必须说同一句话 —— 界面上写着「汇报线只允许
7
+ // 逐级上升」,服务端回一句「禁止发送」,读者看到的是两套规矩,而且不知道该信哪一套。
8
+ //
9
+ // 所以那句话写在这里,两边各自 import,谁都不许自己写一份。
10
+ //
11
+ // 而「什么是子会话」这个判据更不能写两遍:客户端画锁要判断一次,服务端拒绝消息又要判断一次。
12
+ // 两个判断只要有一个偏了,就会出现「界面锁着但服务端放行」或者「界面没锁但服务端拒绝」——
13
+ // 前者让人以为有规矩其实没有,后者让人莫名其妙发不出去。
14
+ //
15
+ // THE ORPHAN, AND WHY 「父会话还活着」 MEANS 「父会话没有归档」.
16
+ //
17
+ // 父会话被归档之后留下的孤儿会话,在树上已经没有了上级,实际上就是一个顶层会话:它没有可
18
+ // 汇报的上级,也就无所谓「越过汇报线」。把它锁住,等于把一个没有对象的规矩套上去。所以判据是
19
+ // 「父会话这一行存在 **而且没有归档**」,而不是「父会话这一行存在」。
20
+ //
21
+ // 这个区别不是咬文嚼字:归档一棵树的时候,父会话和它的子孙是一起归档的;所以一个「父会话
22
+ // 已归档、子会话还活着」的局面,只可能出现在归档没有覆盖到它的地方 —— 而那里恰恰是最需要
23
+ // 读者能说话的地方。
24
+ /**
25
+ * THE SENTENCE. The lock says it, and the server refuses with it.
26
+ *
27
+ * IT SAYS THE RULE, NOT 「禁止」. A refusal that only says "forbidden" leaves the reader with
28
+ * nothing to do; a refusal that names the rule and the way out is something the reader can act
29
+ * on. This is why the sentence is one sentence and why it is shared: the interface and the
30
+ * server must not disagree about what the rule is.
31
+ */
32
+ export const CHILD_SESSION_LOCK_REASON = "汇报线只允许逐级上升,子会话默认不能直接对话;确有特殊情况可解锁。";
33
+ /**
34
+ * Whether a conversation is a CHILD SESSION: it hangs under a parent that is still ALIVE.
35
+ *
36
+ * A conversation with no parent at all is top-level, and so is an ORPHAN - one whose parent was
37
+ * archived and left behind. Both of them can talk to the reader directly, because there is no
38
+ * reporting line above them to bypass.
39
+ *
40
+ * `parentConversationId` is the conversation's own edge, and `parent` is the parent's row (or
41
+ * undefined when there is no such row any more). Both sides answer the question from their own
42
+ * rows - the client from `state.conversations`, the server from its store - and neither of them
43
+ * has to hand this function a whole conversation: the server's send path asks this on EVERY
44
+ * message, and a long conversation must not pay for its entire transcript to answer one yes/no
45
+ * question.
46
+ */
47
+ export function isChildSession(parentConversationId, parent) {
48
+ if (!parentConversationId)
49
+ return false;
50
+ return Boolean(parent && parent.id === parentConversationId && !parent.archivedAt);
51
+ }