@evandu/super-pi 0.1.219 → 0.1.220

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 (44) hide show
  1. package/dist/client/.super-pi-client-sources.json +6 -6
  2. package/dist/client/assets/{CodeMirrorEditor-BoRBaVec.js → CodeMirrorEditor-DLESYIdU.js} +2 -2
  3. package/dist/client/assets/{dist-CiRgPe6t.js → dist-2Gv721yB.js} +1 -1
  4. package/dist/client/assets/{dist-Cp3XgqJR.js → dist-B-63MNT9.js} +1 -1
  5. package/dist/client/assets/{dist-CYpk6fXT.js → dist-B-ydE4PJ.js} +1 -1
  6. package/dist/client/assets/{dist-Digy2Mj0.js → dist-B6UYFWUo.js} +1 -1
  7. package/dist/client/assets/{dist-CMdO3YzL.js → dist-BG1xVEUu.js} +1 -1
  8. package/dist/client/assets/{dist-Dwsqs8C-.js → dist-BTUuXAFG.js} +1 -1
  9. package/dist/client/assets/{dist-mAA5Fw0-.js → dist-Bz37bm03.js} +1 -1
  10. package/dist/client/assets/{dist-BXOV_xtI.js → dist-CQAWuaHA.js} +1 -1
  11. package/dist/client/assets/{dist-DvWgfLRt.js → dist-CYEoLBJJ.js} +1 -1
  12. package/dist/client/assets/{dist-DUbHNa35.js → dist-CbixgvA8.js} +1 -1
  13. package/dist/client/assets/{dist-BOC9yjsN.js → dist-CoC8iHD1.js} +1 -1
  14. package/dist/client/assets/{dist-gRtmlyhZ.js → dist-CrtcsyOg.js} +1 -1
  15. package/dist/client/assets/{dist-xb23AFcT.js → dist-D0Mff5_O.js} +1 -1
  16. package/dist/client/assets/{dist-Bh20DSAa.js → dist-DKRxalqK.js} +1 -1
  17. package/dist/client/assets/{dist-DQ_C0DEU.js → dist-DPvgTEV_.js} +1 -1
  18. package/dist/client/assets/{dist-CPjKkcyd.js → dist-DhCNXN4F.js} +1 -1
  19. package/dist/client/assets/{dist-DLYLxwOe.js → dist-DmraLEb2.js} +1 -1
  20. package/dist/client/assets/{dist-D1hdxSH6.js → dist-DvJTvgiN.js} +1 -1
  21. package/dist/client/assets/{dist-CjhpwEGf.js → dist-YSB8UKj7.js} +1 -1
  22. package/dist/client/assets/{dist-BVVJTFYw.js → dist-aDKso4tk.js} +1 -1
  23. package/dist/client/assets/{dist-BOF4T7jI.js → dist-h8QFV1py.js} +1 -1
  24. package/dist/client/assets/{dist-CIv6vCdn.js → dist-hyn4QSU9.js} +1 -1
  25. package/dist/client/assets/index-B-h_KnC5.css +1 -0
  26. package/dist/client/assets/{index-DmxXnVfN.js → index-BMuvJCSx.js} +11 -11
  27. package/dist/client/index.html +2 -2
  28. package/dist/server/application/project-service.d.ts +45 -1
  29. package/dist/server/application/project-service.js +91 -2
  30. package/dist/server/application/run-service.d.ts +3 -1
  31. package/dist/server/application/run-service.js +20 -5
  32. package/dist/server/application/session-orchestrator-service.d.ts +62 -0
  33. package/dist/server/application/session-orchestrator-service.js +122 -1
  34. package/dist/server/application/session-reminder-service.js +1 -2
  35. package/dist/server/runtime.js +2 -2
  36. package/dist/server/store.d.ts +10 -3
  37. package/dist/server/store.js +46 -20
  38. package/dist/server/types.d.ts +7 -0
  39. package/dist/shared/project-overview.d.ts +12 -0
  40. package/dist/shared/project-overview.js +15 -0
  41. package/dist/shared/session-reporting.d.ts +32 -0
  42. package/dist/shared/session-reporting.js +29 -0
  43. package/package.json +5 -1
  44. package/dist/client/assets/index-Nu--gcBs.css +0 -1
@@ -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-DmxXnVfN.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-Nu--gcBs.css">
11
+ <script type="module" crossorigin src="/assets/index-BMuvJCSx.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index-B-h_KnC5.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="root"></div>
@@ -97,7 +97,7 @@ export declare class ProjectService {
97
97
  */
98
98
  private readonly agents?;
99
99
  private readonly queues;
100
- constructor(store: Store, orchestrator?: (Pick<SessionOrchestratorService, "spawn" | "dispatch"> & Partial<Pick<SessionOrchestratorService, "stopSubtree">>) | undefined,
100
+ constructor(store: Store, orchestrator?: (Pick<SessionOrchestratorService, "spawn" | "dispatch" | "notifyChildCompleted"> & Partial<Pick<SessionOrchestratorService, "stopSubtree">>) | undefined,
101
101
  /**
102
102
  * Optional on purpose: a service built without an agent directory cannot tell a subagent from a
103
103
  * custom agent, and it then behaves exactly as it did before this check existed. The real
@@ -107,6 +107,35 @@ export declare class ProjectService {
107
107
  private publishContext;
108
108
  shareContext(id: string, value: unknown, workspaceId: string, actor?: string): Promise<unknown>;
109
109
  messageTask(id: string, taskId: string, content: string, workspaceId: string, actor?: string, targetConversationId?: string, deliveryMode?: string): Promise<unknown>;
110
+ /**
111
+ * A SUPERVISOR'S MESSAGE IS THE ANSWER TO THE EXCEPTION - NOT A FORMAL RULING.
112
+ *
113
+ * The reader's complaint was that a session kept saying 「等上面拍板」 long after the question
114
+ * had been settled in a real conversation: the supervisor had talked it through with the member
115
+ * and sent the follow-up instruction, and the platform was still waiting for a ceremony nobody
116
+ * had asked for. Communication is higher than protocol - when the supervisor the case is
117
+ * addressed to writes back to the member who raised it, the case IS answered.
118
+ *
119
+ * TWO THINGS ARE KEPT APART ON PURPOSE.
120
+ * - THE RECORD STAYS. The exception keeps its place in `p.escalations` with the answer, who
121
+ * answered and when. A decision record must not disappear when the project is cancelled.
122
+ * - THE STATE CHANGES. The session no longer says 「等上面拍板」, because nobody is waiting for
123
+ * anything any more: the answer is already on the member's desk.
124
+ *
125
+ * WHAT IS NOT SETTLED HERE, AND WHY:
126
+ * - A BOSS-LEVEL EXCEPTION IS NEVER SETTLED BY A MESSAGE. That case asks the Boss himself, and
127
+ * no team member has the authority to answer it - `resolveEscalation` enforces the very same
128
+ * rule for the panel and the tool, and it must hold for a message too.
129
+ * - A RETURNED EXCEPTION IS NOT REVIVED BY A MESSAGE. A returned case means the member was
130
+ * asked for more material; that material comes back as a NEW exception, not as the old one
131
+ * coming back to life.
132
+ * - ONLY THE DESIGNATED DIRECT SUPERVISOR ANSWERS. `targetConversationId` is the supervisor
133
+ * the case is addressed to, so a message from anybody else is somebody else's business.
134
+ * - AND THE REPLY HAS TO REACH THE MEMBER WHO RAISED IT. A supervisor who writes to somebody
135
+ * else has not answered this case, and settling it would repeat the mistake this project
136
+ * already made once: one answer closing every case of that member at once.
137
+ */
138
+ private settleEscalationsByMessage;
110
139
  getContext(id: string | undefined, workspaceId: string, actor?: string, taskId?: string, contextIds?: unknown): unknown;
111
140
  private coordinationHints;
112
141
  private assertWriteScope;
@@ -327,6 +356,21 @@ export declare class ProjectService {
327
356
  summary?: string;
328
357
  evidenceRefs?: string[];
329
358
  }, workspaceId: string, actor?: string): Promise<ProjectTask>;
359
+ /**
360
+ * THE TASK IS DONE, SO THE LEADER IS WOKEN - AND IT IS NOT TOLD WHAT WAS DONE.
361
+ *
362
+ * The member's work is finished, and the member's direct parent - the Leader - has to hear
363
+ * about it: a Leader that is not told is a Leader that sits there with a finished employee.
364
+ *
365
+ * WHAT THE WAKE CARRIES IS THE TASK'S IDENTITY AND NOTHING ELSE. The delivery, the evidence and
366
+ * the review verdict stay where they are: in the project record and in the member's own
367
+ * session. A platform that wrote the summary here would be writing a report nobody checked, and
368
+ * the Leader is the one who is supposed to look and judge.
369
+ *
370
+ * THE COMPLETION IS THE UNIT, SO THE KNOCK HAPPENS ONCE. A task that is marked complete twice -
371
+ * a retried acceptance - is one piece of work, and the Leader is woken once for it.
372
+ */
373
+ private notifyTaskCompleted;
330
374
  updateTask(id: string, taskId: string, patch: Record<string, unknown> & {
331
375
  workspaceId?: string;
332
376
  }, actor?: string): Promise<ProjectTask>;
@@ -393,9 +393,65 @@ export class ProjectService {
393
393
  this.admission(p);
394
394
  const result = await this.dispatchContext(target, text(content, "补充指令"), { wait: false, mode: deliveryMode }, task.id);
395
395
  this.event(p, "task_message", `向「${task.title}」发送补充指令(${deliveryMode === "steer" ? "下一工具边界" : "排队"}),附带当前共享上下文`, task.id, actor);
396
+ /* THE REPLY IS THE ANSWER. The case was raised against this supervisor, and the supervisor
397
+ has just written to the member - so the case is answered, and the member's session must
398
+ stop saying that it is waiting for a decision. */
399
+ this.settleEscalationsByMessage(p, actor, target, text(content, "补充指令"));
396
400
  return result;
397
401
  });
398
402
  }
403
+ /**
404
+ * A SUPERVISOR'S MESSAGE IS THE ANSWER TO THE EXCEPTION - NOT A FORMAL RULING.
405
+ *
406
+ * The reader's complaint was that a session kept saying 「等上面拍板」 long after the question
407
+ * had been settled in a real conversation: the supervisor had talked it through with the member
408
+ * and sent the follow-up instruction, and the platform was still waiting for a ceremony nobody
409
+ * had asked for. Communication is higher than protocol - when the supervisor the case is
410
+ * addressed to writes back to the member who raised it, the case IS answered.
411
+ *
412
+ * TWO THINGS ARE KEPT APART ON PURPOSE.
413
+ * - THE RECORD STAYS. The exception keeps its place in `p.escalations` with the answer, who
414
+ * answered and when. A decision record must not disappear when the project is cancelled.
415
+ * - THE STATE CHANGES. The session no longer says 「等上面拍板」, because nobody is waiting for
416
+ * anything any more: the answer is already on the member's desk.
417
+ *
418
+ * WHAT IS NOT SETTLED HERE, AND WHY:
419
+ * - A BOSS-LEVEL EXCEPTION IS NEVER SETTLED BY A MESSAGE. That case asks the Boss himself, and
420
+ * no team member has the authority to answer it - `resolveEscalation` enforces the very same
421
+ * rule for the panel and the tool, and it must hold for a message too.
422
+ * - A RETURNED EXCEPTION IS NOT REVIVED BY A MESSAGE. A returned case means the member was
423
+ * asked for more material; that material comes back as a NEW exception, not as the old one
424
+ * coming back to life.
425
+ * - ONLY THE DESIGNATED DIRECT SUPERVISOR ANSWERS. `targetConversationId` is the supervisor
426
+ * the case is addressed to, so a message from anybody else is somebody else's business.
427
+ * - AND THE REPLY HAS TO REACH THE MEMBER WHO RAISED IT. A supervisor who writes to somebody
428
+ * else has not answered this case, and settling it would repeat the mistake this project
429
+ * already made once: one answer closing every case of that member at once.
430
+ */
431
+ settleEscalationsByMessage(p, actor, target, content) {
432
+ if (!actor)
433
+ return;
434
+ const answer = truncate(oneLine(content), 200);
435
+ let settled = 0;
436
+ for (const e of p.escalations ?? []) {
437
+ if (e.status !== "open")
438
+ continue;
439
+ if ((e.audience ?? "boss") !== "supervisor")
440
+ continue;
441
+ if (e.targetConversationId !== actor)
442
+ continue;
443
+ if (e.requestedByConversationId && e.requestedByConversationId !== target)
444
+ continue;
445
+ e.status = "resolved";
446
+ e.decision = answer;
447
+ e.resolvedAt = stamp();
448
+ e.resolvedByConversationId = actor;
449
+ this.event(p, "decision", `直接上级已答复例外(ID:${e.id}):${e.decision}`, e.taskId, actor);
450
+ settled += 1;
451
+ }
452
+ if (settled)
453
+ this.reconcile(p);
454
+ }
399
455
  getContext(id, workspaceId, actor, taskId, contextIds) {
400
456
  const p = id ? this.raw(id, workspaceId) : actor ? this.projectForSession(actor) : undefined;
401
457
  if (!p)
@@ -1662,7 +1718,8 @@ export class ProjectService {
1662
1718
  });
1663
1719
  }
1664
1720
  async submit(id, taskId, input, workspaceId, actor) {
1665
- return this.change(id, workspaceId, (p) => {
1721
+ let completedOwner;
1722
+ const task = await this.change(id, workspaceId, (p) => {
1666
1723
  this.live(p);
1667
1724
  const t = this.task(p, taskId);
1668
1725
  if (actor && actor !== t.ownerConversationId)
@@ -1687,6 +1744,7 @@ export class ProjectService {
1687
1744
  claim that somebody else checked it. */
1688
1745
  t.status = "completed";
1689
1746
  t.updatedAt = stamp();
1747
+ completedOwner = t.ownerConversationId;
1690
1748
  t.review = { verdict: "accepted", summary: "轻量项目:执行者自评交付,未做独立复核", evidenceRefs,
1691
1749
  reviewerConversationId: t.ownerConversationId, createdAt: stamp(), lightweight: true };
1692
1750
  this.syncDeliveryContext(p, t, actor);
@@ -1702,6 +1760,8 @@ export class ProjectService {
1702
1760
  this.reconcile(p);
1703
1761
  return ProjectService.taskView(t, p);
1704
1762
  });
1763
+ await this.notifyTaskCompleted(completedOwner, taskId);
1764
+ return task;
1705
1765
  }
1706
1766
  async requestReview(id, taskId, workspaceId, actor) {
1707
1767
  return this.change(id, workspaceId, async (p) => {
@@ -1736,7 +1796,8 @@ export class ProjectService {
1736
1796
  });
1737
1797
  }
1738
1798
  async review(id, taskId, input, workspaceId, actor) {
1739
- return this.change(id, workspaceId, (p) => {
1799
+ let completedOwner;
1800
+ const task = await this.change(id, workspaceId, (p) => {
1740
1801
  this.live(p);
1741
1802
  const t = this.task(p, taskId);
1742
1803
  if (!actor || actor !== t.reviewerConversationId || actor === t.ownerConversationId)
@@ -1751,11 +1812,39 @@ export class ProjectService {
1751
1812
  t.review = { verdict: input.verdict, summary: text(input.summary, "复核意见"), evidenceRefs, reviewerConversationId: actor, createdAt: stamp() };
1752
1813
  t.status = input.verdict === "accepted" ? "completed" : "ready";
1753
1814
  t.updatedAt = stamp();
1815
+ if (t.status === "completed")
1816
+ completedOwner = t.ownerConversationId;
1754
1817
  this.syncDeliveryContext(p, t, actor);
1755
1818
  this.event(p, "reviewed", `${input.verdict === "accepted" ? "验收通过" : "退回返工"}:${t.title};${t.review.summary}`, t.id, actor);
1756
1819
  this.reconcile(p);
1757
1820
  return ProjectService.taskView(t, p);
1758
1821
  });
1822
+ await this.notifyTaskCompleted(completedOwner, taskId);
1823
+ return task;
1824
+ }
1825
+ /**
1826
+ * THE TASK IS DONE, SO THE LEADER IS WOKEN - AND IT IS NOT TOLD WHAT WAS DONE.
1827
+ *
1828
+ * The member's work is finished, and the member's direct parent - the Leader - has to hear
1829
+ * about it: a Leader that is not told is a Leader that sits there with a finished employee.
1830
+ *
1831
+ * WHAT THE WAKE CARRIES IS THE TASK'S IDENTITY AND NOTHING ELSE. The delivery, the evidence and
1832
+ * the review verdict stay where they are: in the project record and in the member's own
1833
+ * session. A platform that wrote the summary here would be writing a report nobody checked, and
1834
+ * the Leader is the one who is supposed to look and judge.
1835
+ *
1836
+ * THE COMPLETION IS THE UNIT, SO THE KNOCK HAPPENS ONCE. A task that is marked complete twice -
1837
+ * a retried acceptance - is one piece of work, and the Leader is woken once for it.
1838
+ */
1839
+ async notifyTaskCompleted(ownerConversationId, taskId) {
1840
+ if (!ownerConversationId || !this.orchestrator)
1841
+ return;
1842
+ try {
1843
+ await this.orchestrator.notifyChildCompleted(ownerConversationId, { unit: `task:${taskId}` });
1844
+ }
1845
+ catch (error) {
1846
+ console.warn(`Super Pi: 任务 ${taskId} 已完成,但叫不醒直属上级:${error instanceof Error ? error.message : String(error)}`);
1847
+ }
1759
1848
  }
1760
1849
  async updateTask(id, taskId, patch, actor) {
1761
1850
  const result = await this.change(id, patch.workspaceId, async (p) => {
@@ -441,7 +441,9 @@ export declare class RunService {
441
441
  mode?: MessageDeliveryMode;
442
442
  onAccepted?: (messageId: string) => void;
443
443
  }): Promise<void>;
444
- enqueueAndRun(conversationId: string, content: string, images?: MessageImage[], attachments?: import("../types.js").MessageAttachments, clientId?: string, mode?: MessageDeliveryMode): Promise<void>;
444
+ enqueueAndRun(conversationId: string, content: string, images?: MessageImage[], attachments?: Message["attachments"], clientId?: string, mode?: MessageDeliveryMode): Promise<void>;
445
+ enqueueReminder(conversationId: string, note: string): Promise<void>;
446
+ private enqueueMessage;
445
447
  /**
446
448
  * Steers a queued message into the in-flight turn.
447
449
  */
@@ -40,7 +40,11 @@ async function expandAtReferences(store, workspace, content) {
40
40
  const found = state.conversations.find(c => c.id === key || c.title.toLocaleLowerCase().includes(key.toLocaleLowerCase()));
41
41
  if (!found)
42
42
  continue;
43
- const text = found.messages.filter(m => m.role === "user" || m.role === "assistant").slice(-12).map(m => `${m.role}: ${m.content}`).join("\n");
43
+ const text = found.messages
44
+ .filter(message => message.role === "user" || message.role === "assistant" || message.source === "session-reminder")
45
+ .slice(-12)
46
+ .map(message => `${message.source === "session-reminder" ? "定时提醒" : message.role}: ${message.content}`)
47
+ .join("\n");
44
48
  blocks.push(`\n[引用会话 ${found.title} (${found.id})]\n${text.slice(-12000)}\n[/引用会话]`);
45
49
  continue;
46
50
  }
@@ -88,6 +92,8 @@ async function expandAtReferences(store, workspace, content) {
88
92
  * answers about THAT - which is what a primary agent should do with a child's result.
89
93
  */
90
94
  function composePrompt(message) {
95
+ if (message.source === "session-reminder")
96
+ return `[定时提醒] ${message.content}`;
91
97
  if (message.role !== "tool")
92
98
  return message.content;
93
99
  const content = message.content;
@@ -1955,7 +1961,13 @@ export class RunService {
1955
1961
  this.broadcaster.broadcastState();
1956
1962
  }
1957
1963
  }
1958
- async enqueueAndRun(conversationId, content, images, attachments, clientId, mode) {
1964
+ enqueueAndRun(conversationId, content, images, attachments, clientId, mode) {
1965
+ return this.enqueueMessage(conversationId, content, { images, attachments, clientId, mode });
1966
+ }
1967
+ enqueueReminder(conversationId, note) {
1968
+ return this.enqueueMessage(conversationId, note, { source: "session-reminder" });
1969
+ }
1970
+ async enqueueMessage(conversationId, content, { images, attachments, clientId, mode, source }) {
1959
1971
  const deliveryMode = parseMessageDeliveryMode(mode);
1960
1972
  this.assertHistoryAvailable(conversationId);
1961
1973
  /**
@@ -1973,7 +1985,7 @@ export class RunService {
1973
1985
  if (clientId && this.store.hasMessage(conversationId, clientId))
1974
1986
  return;
1975
1987
  this.memory?.cancel(conversationId);
1976
- if (!isLengthContinuation(content)) {
1988
+ if (source || !isLengthContinuation(content)) {
1977
1989
  this.lengthContinuations.delete(conversationId);
1978
1990
  await this.store.setWarningReason(conversationId, undefined).catch(() => undefined);
1979
1991
  }
@@ -2019,7 +2031,10 @@ export class RunService {
2019
2031
  }
2020
2032
  let message;
2021
2033
  try {
2022
- message = await this.store.addUserMessage(conversationId, trimmed, validImages, attachments, { clientId, ...(queueOnly ? { delivery: "waiting" } : {}) });
2034
+ const delivery = queueOnly ? "waiting" : undefined;
2035
+ message = source
2036
+ ? await this.store.addAgentMessage(conversationId, trimmed, { source, delivery })
2037
+ : await this.store.addUserMessage(conversationId, trimmed, validImages, attachments, { clientId, delivery });
2023
2038
  }
2024
2039
  catch (error) {
2025
2040
  if (reservedController)
@@ -2054,7 +2069,7 @@ export class RunService {
2054
2069
  try {
2055
2070
  const currentConv = this.turnContext(conversationId).conversation;
2056
2071
  await this.assertModelSupportsImages(currentConv, Boolean(validImages?.length), message.id);
2057
- expanded = await expandAtReferences(this.store, workspace, trimmed);
2072
+ expanded = await expandAtReferences(this.store, workspace, composePrompt(message));
2058
2073
  }
2059
2074
  catch (error) {
2060
2075
  // EVERY REFUSAL ABOVE HAPPENS BEFORE A TURN EXISTS. The words are on screen and no model has seen
@@ -155,6 +155,19 @@ export declare class SessionOrchestratorService {
155
155
  * result is still its own.
156
156
  */
157
157
  private readonly reportedChildren;
158
+ /**
159
+ * THE COMPLETION NOTICES THAT HAVE ALREADY KNOCKED ON A PARENT'S DOOR.
160
+ *
161
+ * One entry per finished child per completion, and the completion is identified by the child's
162
+ * last answer - so a RETRY of the same finished turn knocks once, while the next turn the child
163
+ * runs is a different completion and knocks again.
164
+ *
165
+ * WHY THIS IS A SET AND NOT A FLAG. A flag would say "this child has been announced", and that
166
+ * is a different question from "THIS completion has been announced". A flag silences every
167
+ * later completion of the same child, and a child that works for three turns would be announced
168
+ * once - the parent would sit through two of the child's finishes without being told.
169
+ */
170
+ private readonly completionNotices;
158
171
  constructor(store: Store, conversationService: ConversationService, runService: RunService, ledger: SessionLedger, broadcaster?: EventBroadcaster | undefined, watchdog?: SessionWatchdog, uploadsDir?: string | undefined);
159
172
  /**
160
173
  * The watchdog timer fired: the child has been silent for longer than the parent declared.
@@ -170,15 +183,64 @@ export declare class SessionOrchestratorService {
170
183
  /**
171
184
  * Dispatches a message to an arbitrary session (server-to-server).
172
185
  * By default dispatches asynchronously so the orchestrator caller is not blocked.
186
+ *
187
+ * `silent` is for the platform's own housekeeping - the completion knock. A knock wakes a
188
+ * session and carries no result, so the turn it starts must not produce a result report of its
189
+ * own: a knock that made the woken session report up would turn one child's finish into a
190
+ * chain of knocks all the way to the top.
173
191
  */
174
192
  dispatch(conversationId: string, content: string, options?: {
175
193
  wait?: boolean;
176
194
  mode?: MessageDeliveryMode;
195
+ silent?: boolean;
177
196
  }): Promise<{
178
197
  conversationId: string;
179
198
  messageId?: string;
180
199
  mode: MessageDeliveryMode;
181
200
  }>;
201
+ /**
202
+ * THE PLATFORM KNOCKS ON THE PARENT'S DOOR WHEN A CHILD SESSION ENDS.
203
+ *
204
+ * A child that finished its work is a child the parent has to hear about, and the PLATFORM is the
205
+ * one that knows the turn ended: the child may forget to say so, and a parent that was not
206
+ * present for the turn cannot see that it happened. This is the platform's own housekeeping -
207
+ * it is not something the child is asked to do and not something the model has to remember.
208
+ *
209
+ * THE KNOCK CARRIES NO WORK. It says WHICH child session finished and nothing else: no output,
210
+ * no summary, no last message, no result, no task result. The parent reads the child's session
211
+ * itself, so a platform that summarized here would be writing the report the parent is supposed
212
+ * to write - and a summary written by the platform is a summary nobody verified.
213
+ *
214
+ * ONLY THE DIRECT PARENT IS TOLD. The parent wakes up and looks at its own child; the
215
+ * grandparent is not told about a grandchild's finish, because the parent is the one who has to
216
+ * decide what that means.
217
+ *
218
+ * A TOP-LEVEL SESSION HAS NOBODY TO TELL, so a session without a parent produces nothing - and
219
+ * the user's own session is one of those.
220
+ */
221
+ notifyChildCompleted(childConversationId: string, options?: {
222
+ unit?: string;
223
+ }): Promise<{
224
+ delivered: boolean;
225
+ parentConversationId?: string;
226
+ }>;
227
+ /**
228
+ * WHAT MAKES TWO COMPLETION REPORTS THE SAME COMPLETION.
229
+ *
230
+ * The child's last answer is the thing the completion is about, so two reports that arrive after
231
+ * the same answer are the same completion - a retry, a repeated settle, a second report about a
232
+ * turn that already ended. The next turn produces the next answer, and that is a new completion
233
+ * the parent has not been told about yet.
234
+ */
235
+ private completionUnit;
236
+ /**
237
+ * IS THIS SESSION ONE OF A PROJECT'S EMPLOYEES?
238
+ *
239
+ * A project member's turn ending is NOT its work being done: the delivery still has to be
240
+ * reviewed. The moment that counts is the task being completed, and the project announces that
241
+ * one - announcing both would wake the Leader twice for one piece of work.
242
+ */
243
+ private projectParticipant;
182
244
  /**
183
245
  * THE CHILD'S OUTPUT WAS CUT OFF. TELL IT TO CARRY ON, AND LET IT.
184
246
  *
@@ -66,6 +66,19 @@ export class SessionOrchestratorService {
66
66
  * result is still its own.
67
67
  */
68
68
  reportedChildren = new Map();
69
+ /**
70
+ * THE COMPLETION NOTICES THAT HAVE ALREADY KNOCKED ON A PARENT'S DOOR.
71
+ *
72
+ * One entry per finished child per completion, and the completion is identified by the child's
73
+ * last answer - so a RETRY of the same finished turn knocks once, while the next turn the child
74
+ * runs is a different completion and knocks again.
75
+ *
76
+ * WHY THIS IS A SET AND NOT A FLAG. A flag would say "this child has been announced", and that
77
+ * is a different question from "THIS completion has been announced". A flag silences every
78
+ * later completion of the same child, and a child that works for three turns would be announced
79
+ * once - the parent would sit through two of the child's finishes without being told.
80
+ */
81
+ completionNotices = new Set();
69
82
  constructor(store, conversationService, runService, ledger, broadcaster, watchdog, uploadsDir) {
70
83
  this.store = store;
71
84
  this.conversationService = conversationService;
@@ -217,9 +230,15 @@ export class SessionOrchestratorService {
217
230
  /**
218
231
  * Dispatches a message to an arbitrary session (server-to-server).
219
232
  * By default dispatches asynchronously so the orchestrator caller is not blocked.
233
+ *
234
+ * `silent` is for the platform's own housekeeping - the completion knock. A knock wakes a
235
+ * session and carries no result, so the turn it starts must not produce a result report of its
236
+ * own: a knock that made the woken session report up would turn one child's finish into a
237
+ * chain of knocks all the way to the top.
220
238
  */
221
239
  async dispatch(conversationId, content, options) {
222
240
  const mode = parseMessageDeliveryMode(options?.mode);
241
+ const silent = options?.silent === true;
223
242
  if (!content.trim()) {
224
243
  throw new Error("dispatch requires non-empty content");
225
244
  }
@@ -306,9 +325,14 @@ export class SessionOrchestratorService {
306
325
  // the failures was a real defect - it left a parent that had successfully delegated a task
307
326
  // staring at an empty transcript, and the child looking finished to everyone except the one
308
327
  // person waiting for it.
328
+ // DID THIS TURN REPORT ITSELF? A child that reported from inside its turn has already told
329
+ // the parent everything the knock would have said - and a knock on top of that report would
330
+ // make the parent hear about one finished turn twice. The knock exists for the child that
331
+ // FORGOT to report, so a child that did report is not knocked.
332
+ let reportedItself = false;
309
333
  try {
310
334
  const result = await this.persistSessionResult(conversationId, failure);
311
- if (result) {
335
+ if (result && !silent) {
312
336
  const current = this.store.conversation(conversationId);
313
337
  // THE REPORT GOES OUT ONLY WHEN THE CHILD'S TURN ENDED. The statuses that mean "the turn is
314
338
  // over" are `completed` and `failed`; `running` and `awaiting_background` mean work is still
@@ -326,6 +350,7 @@ export class SessionOrchestratorService {
326
350
  // one because of that would swallow a result the parent is still waiting for.
327
351
  const reportedAt = this.reportedChildren.get(conversationId);
328
352
  const alreadyReported = reportedAt !== undefined && reportedAt >= turnStartedAt;
353
+ reportedItself = alreadyReported;
329
354
  if (turnEnded && !alreadyReported) {
330
355
  await this.runService.enqueueSessionResult({
331
356
  conversationId,
@@ -355,6 +380,33 @@ export class SessionOrchestratorService {
355
380
  // turn that was running when it was made.
356
381
  this.reportedChildren.delete(conversationId);
357
382
  }
383
+ // THE PLATFORM KNOCKS ON THE PARENT'S DOOR. The turn is over, so the parent has to hear
384
+ // about it - whether the child remembered to say so or not. What the knock carries is the
385
+ // child's identity and nothing else: the parent reads the child's session itself.
386
+ //
387
+ // ONLY A FINISHED TURN KNOCKS. A turn that failed or was stopped did not finish its work,
388
+ // and the knock says 「完成」 - a broken turn is reported through the failure report, which
389
+ // carries the diagnosis.
390
+ //
391
+ // A PROJECT EMPLOYEE IS NOT ANNOUNCED HERE. Its turn ending is not its task being done, and
392
+ // the project announces the task's completion instead - one knock per piece of work.
393
+ //
394
+ // AND A CHILD THAT REPORTED ITSELF IS NOT KNOCKED. The knock exists for the child that
395
+ // FORGOT to report up; a child that did report has already said everything the knock would
396
+ // have said, and knocking as well would make the parent hear about one finished turn twice.
397
+ const finished = this.store.conversation(conversationId);
398
+ if (!silent
399
+ && !reportedItself
400
+ && finished?.status === "completed"
401
+ && finished.parentConversationId
402
+ && !this.projectParticipant(conversationId)) {
403
+ try {
404
+ await this.notifyChildCompleted(conversationId);
405
+ }
406
+ catch (error) {
407
+ console.warn(`Super Pi: 子会话 ${conversationId} 的完成通知失败:${error instanceof Error ? error.message : String(error)}`);
408
+ }
409
+ }
358
410
  if (failure !== undefined) {
359
411
  console.warn(`Super Pi: dispatch failed for conversation ${conversationId}:`, failure instanceof Error ? failure.message : String(failure));
360
412
  this.ledger.update(conversationId, { status: "failed" });
@@ -369,6 +421,75 @@ export class SessionOrchestratorService {
369
421
  }
370
422
  return { conversationId, ...(acceptedMessageId ? { messageId: acceptedMessageId } : {}), mode };
371
423
  }
424
+ /**
425
+ * THE PLATFORM KNOCKS ON THE PARENT'S DOOR WHEN A CHILD SESSION ENDS.
426
+ *
427
+ * A child that finished its work is a child the parent has to hear about, and the PLATFORM is the
428
+ * one that knows the turn ended: the child may forget to say so, and a parent that was not
429
+ * present for the turn cannot see that it happened. This is the platform's own housekeeping -
430
+ * it is not something the child is asked to do and not something the model has to remember.
431
+ *
432
+ * THE KNOCK CARRIES NO WORK. It says WHICH child session finished and nothing else: no output,
433
+ * no summary, no last message, no result, no task result. The parent reads the child's session
434
+ * itself, so a platform that summarized here would be writing the report the parent is supposed
435
+ * to write - and a summary written by the platform is a summary nobody verified.
436
+ *
437
+ * ONLY THE DIRECT PARENT IS TOLD. The parent wakes up and looks at its own child; the
438
+ * grandparent is not told about a grandchild's finish, because the parent is the one who has to
439
+ * decide what that means.
440
+ *
441
+ * A TOP-LEVEL SESSION HAS NOBODY TO TELL, so a session without a parent produces nothing - and
442
+ * the user's own session is one of those.
443
+ */
444
+ async notifyChildCompleted(childConversationId, options = {}) {
445
+ const child = this.store.conversation(childConversationId);
446
+ if (!child)
447
+ return { delivered: false };
448
+ const parentConversationId = child.parentConversationId;
449
+ if (!parentConversationId)
450
+ return { delivered: false };
451
+ const parent = this.store.conversation(parentConversationId);
452
+ if (!parent || parent.archivedAt)
453
+ return { delivered: false };
454
+ const unit = options.unit ?? this.completionUnit(child);
455
+ const key = `${childConversationId}:${unit}`;
456
+ // ONE COMPLETION, ONE KNOCK. A retry, or a second report about the same finished turn, must
457
+ // not knock twice - and the knock is remembered even if the delivery fails, so a parent that
458
+ // cannot be reached does not turn into a storm of retries.
459
+ if (this.completionNotices.has(key))
460
+ return { delivered: false, parentConversationId };
461
+ this.completionNotices.add(key);
462
+ const notice = `子会话已完成:${child.title || child.id}(${child.id})。`;
463
+ try {
464
+ await this.dispatch(parentConversationId, notice, { wait: false, silent: true });
465
+ }
466
+ catch (error) {
467
+ console.warn(`Super Pi: 子会话 ${childConversationId} 已完成,但叫不醒父会话 ${parentConversationId}:${error instanceof Error ? error.message : String(error)}`);
468
+ }
469
+ return { delivered: true, parentConversationId };
470
+ }
471
+ /**
472
+ * WHAT MAKES TWO COMPLETION REPORTS THE SAME COMPLETION.
473
+ *
474
+ * The child's last answer is the thing the completion is about, so two reports that arrive after
475
+ * the same answer are the same completion - a retry, a repeated settle, a second report about a
476
+ * turn that already ended. The next turn produces the next answer, and that is a new completion
477
+ * the parent has not been told about yet.
478
+ */
479
+ completionUnit(conversation) {
480
+ const lastAnswer = [...conversation.messages].reverse().find((message) => message.role === "assistant");
481
+ return lastAnswer?.id ?? conversation.messages.at(-1)?.id ?? "end";
482
+ }
483
+ /**
484
+ * IS THIS SESSION ONE OF A PROJECT'S EMPLOYEES?
485
+ *
486
+ * A project member's turn ending is NOT its work being done: the delivery still has to be
487
+ * reviewed. The moment that counts is the task being completed, and the project announces that
488
+ * one - announcing both would wake the Leader twice for one piece of work.
489
+ */
490
+ projectParticipant(conversationId) {
491
+ return this.store.projects().some(project => project.tasks.some(task => task.ownerConversationId === conversationId || task.reviewerConversationId === conversationId));
492
+ }
372
493
  /**
373
494
  * THE CHILD'S OUTPUT WAS CUT OFF. TELL IT TO CARRY ON, AND LET IT.
374
495
  *
@@ -110,9 +110,8 @@ export class SessionReminderService {
110
110
  if (!conversation || conversation.archivedAt) {
111
111
  return;
112
112
  }
113
- const message = `[定时提醒] ${note}`;
114
113
  try {
115
- await this.runService.enqueueAndRun(conversationId, message);
114
+ await this.runService.enqueueReminder(conversationId, note);
116
115
  }
117
116
  catch (error) {
118
117
  console.warn(`Super Pi: delivering session reminder to ${conversationId} failed:`, error instanceof Error ? error.message : String(error));
@@ -2434,8 +2434,8 @@ export class PiRpcRuntime {
2434
2434
  const deadline = Date.now() + TIMEOUT_MS;
2435
2435
  try {
2436
2436
  const transcript = conversation.messages
2437
- .filter((message) => (message.role === "user" || message.role === "assistant") && message.content.trim())
2438
- .map((message) => `${message.role === "user" ? "User" : "Assistant"}: ${message.content.trim()}`)
2437
+ .filter(message => (message.role === "user" || message.role === "assistant" || message.source === "session-reminder") && message.content.trim())
2438
+ .map(message => `${message.source === "session-reminder" ? "定时提醒" : message.role === "user" ? "User" : "Assistant"}: ${message.content.trim()}`)
2439
2439
  .join("\n");
2440
2440
  if (!transcript)
2441
2441
  throw new Error("这个会话还没有内容,无法据此生成标题");
@@ -149,6 +149,14 @@ export declare class Store {
149
149
  project(projectId: string): Project | undefined;
150
150
  /** Conversation IDs that currently have an unresolved escalation requested. */
151
151
  openEscalationConversationIds(): Set<string>;
152
+ /**
153
+ * 每条未决例外该谁拍板,按发起会话归拢。
154
+ *
155
+ * `supervisor` = 团队内部的事(会话在等自己的直属上级),`boss` = 到了顶层。
156
+ * 一个会话同时开着内部和顶层两条时,顶层那条赢:那是唯一需要用户听见的一条。
157
+ * 老记录没有 `audience`,按 `boss` 读 —— 宁可多让用户看见一次,也不要把该用户决定的事藏起来。
158
+ */
159
+ openEscalationAudiences(): Map<string, "supervisor" | "boss">;
152
160
  /** Child conversation IDs whose enqueued session result is still waiting or sending on a non-archived parent. */
153
161
  pendingResultConversationIds(): Set<string>;
154
162
  setProject(project: Project): Promise<Project>;
@@ -473,13 +481,12 @@ export declare class Store {
473
481
  * `composePrompt` in the run service). So the instruction reaches the model the same way, and the
474
482
  * reader sees who spoke.
475
483
  */
476
- addAgentMessage(conversationId: string, content: string, options?: {
477
- delivery?: Message["delivery"];
478
- }): Promise<Message>;
484
+ addAgentMessage(conversationId: string, content: string, options?: Pick<Message, "delivery" | "source">): Promise<Message>;
479
485
  addUserMessage(conversationId: string, content: string, images?: MessageImage[], attachments?: import("./types.js").MessageAttachments, options?: {
480
486
  clientId?: string;
481
487
  delivery?: Message["delivery"];
482
488
  }): Promise<Message>;
489
+ private persistIncomingTurn;
483
490
  /**
484
491
  * Takes the browser's id for its own optimistic message, when it is safe to.
485
492
  *