@evandu/super-pi 0.1.168 → 0.1.170

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 (31) hide show
  1. package/dist/client/.super-pi-client-sources.json +4 -4
  2. package/dist/client/assets/{CodeMirrorEditor-DWEFdLq1.js → CodeMirrorEditor-CzUeGDdc.js} +2 -2
  3. package/dist/client/assets/{dist-XSVtuaKi.js → dist-B26sLQy-.js} +1 -1
  4. package/dist/client/assets/{dist-Bh9F9CwL.js → dist-BCVQCJK1.js} +1 -1
  5. package/dist/client/assets/{dist-DTYN3KZG.js → dist-BOiPOwIz.js} +1 -1
  6. package/dist/client/assets/{dist-DR3gLDod.js → dist-BlVF_BSL.js} +1 -1
  7. package/dist/client/assets/{dist-H7kWZ7Cr.js → dist-BpnlFbvg.js} +1 -1
  8. package/dist/client/assets/{dist-3mX68Ead.js → dist-C2Ih1t5h.js} +1 -1
  9. package/dist/client/assets/{dist-CXIdy9EI.js → dist-C2V8B6YE.js} +1 -1
  10. package/dist/client/assets/{dist-BsaizV0U.js → dist-C2e4r6Qm.js} +1 -1
  11. package/dist/client/assets/{dist-ei0l0QpD.js → dist-CGpm7VDj.js} +1 -1
  12. package/dist/client/assets/{dist-0cjcfZm8.js → dist-CUbRB6Gb.js} +1 -1
  13. package/dist/client/assets/{dist-BiVenLEE.js → dist-CZh-o5Ms.js} +1 -1
  14. package/dist/client/assets/{dist-Co6-VsRy.js → dist-CjSFpJ5l.js} +1 -1
  15. package/dist/client/assets/{dist-B19er0Hr.js → dist-CtLhwtKR.js} +1 -1
  16. package/dist/client/assets/{dist-D5SNpvpB.js → dist-DSclOmZU.js} +1 -1
  17. package/dist/client/assets/{dist-BygS3RZC.js → dist-DWWeqjij.js} +1 -1
  18. package/dist/client/assets/{dist-ELtcJv97.js → dist-DWt_M7vb.js} +1 -1
  19. package/dist/client/assets/{dist-D9UIUBjg.js → dist-DiclZJGi.js} +1 -1
  20. package/dist/client/assets/{dist-i063EgJc.js → dist-Dn_hEfpF.js} +1 -1
  21. package/dist/client/assets/{dist-BWN1gFkd.js → dist-DpgtEKyP.js} +1 -1
  22. package/dist/client/assets/{dist-CPZVRFqI.js → dist-DyBgPEEv.js} +1 -1
  23. package/dist/client/assets/{dist-84wmy0xb.js → dist-HVW2Jgge.js} +1 -1
  24. package/dist/client/assets/{dist-Bp858rkg.js → dist-b302HMV6.js} +1 -1
  25. package/dist/client/assets/{index-C4d7l2t8.js → index-BqO2dVq8.js} +10 -10
  26. package/dist/client/assets/{index-C3ETe3EL.css → index-DUNPa0xu.css} +1 -1
  27. package/dist/client/index.html +2 -2
  28. package/dist/server/application/project-service.d.ts +64 -0
  29. package/dist/server/application/project-service.js +228 -7
  30. package/dist/server/types.d.ts +24 -1
  31. package/package.json +7 -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-C4d7l2t8.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-C3ETe3EL.css">
11
+ <script type="module" crossorigin src="/assets/index-BqO2dVq8.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index-DUNPa0xu.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="root"></div>
@@ -168,6 +168,70 @@ export declare class ProjectService {
168
168
  * record that was already saved. */
169
169
  private noteUnreachable;
170
170
  private leader;
171
+ /**
172
+ * IS THE SESSION THAT WAS SUPPOSED TO BE RUNNING A TASK STILL THERE?
173
+ *
174
+ * "Still there" means three things, and all three are checked against the SESSION'S OWN RECORD,
175
+ * never against a message the project service was handed:
176
+ *
177
+ * - the record is gone: the session was deleted, or it never existed;
178
+ * - the record says `failed`: the turn died (an unhandled error, or the server was killed
179
+ * mid-turn and the startup sweep marked the record failed);
180
+ * - the record says `stopped`: the session was stopped.
181
+ *
182
+ * WHAT IS NOT "GONE" IS AS IMPORTANT. A session that is `idle` or `completed` is ALIVE: it
183
+ * finished its turn and it can be dispatched again, and in the project flow the leader is woken
184
+ * by exactly that report. Calling an alive session "gone" would light up the whole panel for a
185
+ * worker that is simply between turns.
186
+ *
187
+ * The moment the session died is returned with the verdict, because that moment is what tells a
188
+ * death BEFORE the task was dispatched from a death AFTER it. Only the second one interrupted
189
+ * the task.
190
+ */
191
+ private goneSession;
192
+ /**
193
+ * ONE SENTENCE THAT SAYS WHAT HAPPENED, for the reader of the panel.
194
+ *
195
+ * The session's own failure reason is the most specific thing there is - the startup sweep
196
+ * writes "the server died while this task was running, it has been marked failed" into it - so
197
+ * the first sentence of that reason is used when there is one. Otherwise the verdict alone is
198
+ * said, in the same words the reader has seen everywhere else.
199
+ */
200
+ private interruptedReason;
201
+ /**
202
+ * THE PROJECT IS TOLD THE TRUTH ABOUT ITS OWN TASKS.
203
+ *
204
+ * A task says 「执行中」 only while there is something running for it. When the execution session
205
+ * is gone - the process was killed, the session failed, the session was stopped - the task can
206
+ * never advance on its own, and nobody will ever report back on it. So the task is marked
207
+ * `interrupted`, with the reason attached, and the Boss is handed a way to send it out again.
208
+ *
209
+ * WHY THIS IS DONE WHILE READING, AND NOT WHEN THE SESSION DIES. The runtime could tell the
210
+ * project service that a session ended - but only for the deaths it witnessed. The console was
211
+ * killed by the OS at 05:41 with no shutdown log at all: there was no event to receive, no
212
+ * callback to fire, no chance to be told. Reconciling on READ covers EVERY cause of death -
213
+ * the kill, the network cut, the watchdog, the crash - because it asks the one question that is
214
+ * still answerable afterwards: is the session that was running this task still there?
215
+ *
216
+ * THE DEATH HAS TO HAVE HAPPENED AFTER THE DISPATCH. The moment a task is dispatched, its
217
+ * session is restarted - it goes from `failed` back to `running` a moment later. A task
218
+ * dispatched at T2 while its session died at T1 is a task whose session is on its way back, not
219
+ * a task that was interrupted, so the two moments are compared before the task is marked. The
220
+ * session's own record carries the moment it died; the task carries the moment it was sent out.
221
+ */
222
+ private reconcileInterrupted;
223
+ /**
224
+ * THE STATUS A PROJECT SHOWS WHEN ONE OF ITS TASKS HAS BEEN INTERRUPTED.
225
+ *
226
+ * A project with an interrupted task is not "running": the work that is not finished there is
227
+ * work nobody is doing, and it will stay that way until somebody restarts it. So the project
228
+ * says 「已阻塞」 - the word the panel already uses for "this needs a decision from you" - instead
229
+ * of 「执行中」, which would be a claim that something is running.
230
+ *
231
+ * Only a project that says 「执行中」 is moved: a project that has already been closed, or that is
232
+ * waiting for a review, is saying something else and stays truthful.
233
+ */
234
+ private statusWithInterruptions;
171
235
  private topLevelAuthor;
172
236
  private manager;
173
237
  /**
@@ -162,7 +162,7 @@ const PROJECT_STATUS_TEXT = {
162
162
  awaiting_review: "等待复核", completed: "已完成", cancelled: "已取消", failed: "失败",
163
163
  };
164
164
  const TASK_STATUS_TEXT = {
165
- pending: "等待依赖", ready: "待派发", in_progress: "执行中", blocked: "已阻塞",
165
+ pending: "等待依赖", ready: "待派发", in_progress: "执行中", interrupted: "已中断", blocked: "已阻塞",
166
166
  awaiting_review: "待复核", completed: "已完成", failed: "失败", cancelled: "已取消",
167
167
  };
168
168
  const EVENT_TEXT = {
@@ -184,6 +184,33 @@ const cell = (value) => oneLine(value).replace(/\|/g, "\\|");
184
184
  const truncate = (value, limit) => value.length > limit ? `${value.slice(0, limit)}…(已截断)` : value;
185
185
  /** A timestamp a person can read at a glance, and a missing one that says so. */
186
186
  const moment = (value) => value ? value.replace("T", " ").replace(/\.\d+Z$/, "") : "无";
187
+ /**
188
+ * THE FIRST SENTENCE OF A PROSE.
189
+ *
190
+ * The sentence boundary is where a Chinese reader's eye stops, so the first sentence is the part
191
+ * that can stand alone in a table cell. A case with no sentence mark at all is returned whole -
192
+ * there is nothing to cut it at, and cutting it anywhere else would be guessing.
193
+ */
194
+ const firstSentence = (value) => {
195
+ const text = oneLine(value).trim();
196
+ const index = text.search(/[。!?!?]/);
197
+ if (index < 0)
198
+ return text;
199
+ return text.slice(0, index + 1).trim();
200
+ };
201
+ /**
202
+ * THE QUESTION AN EXCEPTION ASKS, in one line.
203
+ *
204
+ * The reader decides on the question, and the case for it is a paragraph - so the table carries
205
+ * the question and the paragraph goes below the table. An exception raised before the title
206
+ * existed falls back to the first sentence of its case, which is the closest thing it has.
207
+ */
208
+ const exceptionTitle = (exception) => {
209
+ const title = exception.title?.trim();
210
+ if (title)
211
+ return oneLine(title);
212
+ return firstSentence(exception.reason ?? "") || "(未命名)";
213
+ };
187
214
  /**
188
215
  * THE TWO SHAPES A PROJECT CAN HAVE.
189
216
  *
@@ -265,9 +292,15 @@ export class ProjectService {
265
292
  });
266
293
  }
267
294
  projectView(p, actor) {
295
+ /* THE PROJECT IS READ AS IT REALLY IS. The reconciliation runs on the way out, so a task
296
+ whose execution session is gone says 「已中断」 in the payload - the panel, the agent tool
297
+ and the exported report all read the same corrected project, and none of them has to know
298
+ that the correction happened at all. */
299
+ this.reconcileInterrupted(p);
268
300
  const resources = this.resources(p);
269
301
  return {
270
302
  ...p,
303
+ status: this.statusWithInterruptions(p),
271
304
  resources,
272
305
  suggestedMaxTokens: this.suggestedMaxTokens(p, resources.tokens),
273
306
  tasks: p.tasks.map((t) => ProjectService.taskView(t, p)),
@@ -309,6 +342,11 @@ export class ProjectService {
309
342
  const previous = this.queues.get(id) ?? Promise.resolve();
310
343
  const pending = previous.catch(() => { }).then(async () => {
311
344
  const p = this.raw(id, workspaceId);
345
+ /* THE PROJECT REPAIRS ITSELF ON THE NEXT WRITE. The reconciliation runs before the work, so
346
+ a write of any kind leaves the record saying 「已中断」 instead of 「执行中」 for a task
347
+ whose execution session is gone - and the event says it happened, so the timeline explains
348
+ the change instead of the status quietly moving under the reader. */
349
+ this.reconcileInterrupted(p, true);
312
350
  const result = await work(p);
313
351
  for (const t of p.tasks) {
314
352
  delete t.effectiveExecutorProfile;
@@ -372,6 +410,110 @@ export class ProjectService {
372
410
  }
373
411
  leader(p, actor) { if (actor && actor !== p.ownerConversationId)
374
412
  throw new Error("仅项目负责人可以执行此操作"); }
413
+ /**
414
+ * IS THE SESSION THAT WAS SUPPOSED TO BE RUNNING A TASK STILL THERE?
415
+ *
416
+ * "Still there" means three things, and all three are checked against the SESSION'S OWN RECORD,
417
+ * never against a message the project service was handed:
418
+ *
419
+ * - the record is gone: the session was deleted, or it never existed;
420
+ * - the record says `failed`: the turn died (an unhandled error, or the server was killed
421
+ * mid-turn and the startup sweep marked the record failed);
422
+ * - the record says `stopped`: the session was stopped.
423
+ *
424
+ * WHAT IS NOT "GONE" IS AS IMPORTANT. A session that is `idle` or `completed` is ALIVE: it
425
+ * finished its turn and it can be dispatched again, and in the project flow the leader is woken
426
+ * by exactly that report. Calling an alive session "gone" would light up the whole panel for a
427
+ * worker that is simply between turns.
428
+ *
429
+ * The moment the session died is returned with the verdict, because that moment is what tells a
430
+ * death BEFORE the task was dispatched from a death AFTER it. Only the second one interrupted
431
+ * the task.
432
+ */
433
+ goneSession(conversationId) {
434
+ if (!conversationId)
435
+ return { gone: false };
436
+ const conversation = this.store.conversation(conversationId);
437
+ if (!conversation)
438
+ return { gone: true, why: "会话记录已经不存在" };
439
+ if (conversation.status === "failed")
440
+ return { gone: true, since: conversation.updatedAt, title: conversation.title, why: "会话已失败", error: conversation.error };
441
+ if (conversation.status === "stopped")
442
+ return { gone: true, since: conversation.updatedAt, title: conversation.title, why: "会话已被停止", error: conversation.error };
443
+ return { gone: false };
444
+ }
445
+ /**
446
+ * ONE SENTENCE THAT SAYS WHAT HAPPENED, for the reader of the panel.
447
+ *
448
+ * The session's own failure reason is the most specific thing there is - the startup sweep
449
+ * writes "the server died while this task was running, it has been marked failed" into it - so
450
+ * the first sentence of that reason is used when there is one. Otherwise the verdict alone is
451
+ * said, in the same words the reader has seen everywhere else.
452
+ */
453
+ interruptedReason(session) {
454
+ const who = session.title ? `执行会话「${session.title}」` : "执行会话";
455
+ /* THE SESSION'S OWN REASON IS THE MOST SPECIFIC THING THERE IS - the startup sweep writes
456
+ "the server died while this task was running, it has been marked failed" into it - so its
457
+ first sentence is used when there is one, with the sentence mark taken off: the reason
458
+ continues after it. */
459
+ const detail = (session.error ? firstSentence(session.error) : "").replace(/[。..!!??]+$/, "");
460
+ const why = detail || session.why || "会话记录已经不存在";
461
+ return `${who}已经不在了(${why}),这个任务不会自己继续了。`;
462
+ }
463
+ /**
464
+ * THE PROJECT IS TOLD THE TRUTH ABOUT ITS OWN TASKS.
465
+ *
466
+ * A task says 「执行中」 only while there is something running for it. When the execution session
467
+ * is gone - the process was killed, the session failed, the session was stopped - the task can
468
+ * never advance on its own, and nobody will ever report back on it. So the task is marked
469
+ * `interrupted`, with the reason attached, and the Boss is handed a way to send it out again.
470
+ *
471
+ * WHY THIS IS DONE WHILE READING, AND NOT WHEN THE SESSION DIES. The runtime could tell the
472
+ * project service that a session ended - but only for the deaths it witnessed. The console was
473
+ * killed by the OS at 05:41 with no shutdown log at all: there was no event to receive, no
474
+ * callback to fire, no chance to be told. Reconciling on READ covers EVERY cause of death -
475
+ * the kill, the network cut, the watchdog, the crash - because it asks the one question that is
476
+ * still answerable afterwards: is the session that was running this task still there?
477
+ *
478
+ * THE DEATH HAS TO HAVE HAPPENED AFTER THE DISPATCH. The moment a task is dispatched, its
479
+ * session is restarted - it goes from `failed` back to `running` a moment later. A task
480
+ * dispatched at T2 while its session died at T1 is a task whose session is on its way back, not
481
+ * a task that was interrupted, so the two moments are compared before the task is marked. The
482
+ * session's own record carries the moment it died; the task carries the moment it was sent out.
483
+ */
484
+ reconcileInterrupted(p, record = false) {
485
+ for (const t of p.tasks) {
486
+ if (t.status !== "in_progress")
487
+ continue;
488
+ const session = this.goneSession(t.ownerConversationId);
489
+ if (!session.gone)
490
+ continue;
491
+ const dispatchedAt = t.dispatchedAt ?? t.updatedAt;
492
+ if (session.since && dispatchedAt && Date.parse(session.since) < Date.parse(dispatchedAt))
493
+ continue;
494
+ t.status = "interrupted";
495
+ t.interruptedReason = this.interruptedReason(session);
496
+ t.updatedAt = stamp();
497
+ if (record)
498
+ this.event(p, "task_updated", `执行会话已中断:${t.title}`, t.id);
499
+ }
500
+ }
501
+ /**
502
+ * THE STATUS A PROJECT SHOWS WHEN ONE OF ITS TASKS HAS BEEN INTERRUPTED.
503
+ *
504
+ * A project with an interrupted task is not "running": the work that is not finished there is
505
+ * work nobody is doing, and it will stay that way until somebody restarts it. So the project
506
+ * says 「已阻塞」 - the word the panel already uses for "this needs a decision from you" - instead
507
+ * of 「执行中」, which would be a claim that something is running.
508
+ *
509
+ * Only a project that says 「执行中」 is moved: a project that has already been closed, or that is
510
+ * waiting for a review, is saying something else and stays truthful.
511
+ */
512
+ statusWithInterruptions(p) {
513
+ if (p.status === "active" && p.tasks.some((t) => t.status === "interrupted"))
514
+ return "blocked";
515
+ return p.status;
516
+ }
375
517
  topLevelAuthor(p, actor) {
376
518
  if (!actor)
377
519
  return;
@@ -508,6 +650,12 @@ export class ProjectService {
508
650
  const hasLeaderBlockedTask = p.tasks.some((t) => t.status === "blocked" && isLeader(t.blockedReportedByConversationId));
509
651
  const lastLeaderProjectReport = [...p.reports].reverse().find((r) => !r.taskId && isLeader(r.authorConversationId));
510
652
  const leaderProjectBlocked = lastLeaderProjectReport?.kind === "blocked";
653
+ /* AN INTERRUPTED TASK BLOCKS THE PROJECT. Its execution session is gone, so nobody is working
654
+ on it and nobody will report back on it: the project is not "running", it is waiting for a
655
+ person to put that task back out. Saying 「执行中」 here would be the same lie one level up
656
+ from the task row - the row says 「已中断」 and the card says 「执行中」, and the reader has
657
+ no way to tell which one to believe. */
658
+ const hasInterruptedTask = p.tasks.some((t) => t.status === "interrupted");
511
659
  /* A PROJECT THAT HAS WORK REGISTERED BUT NO LEADER SESSION YET IS NOT RUNNING.
512
660
  "active" used to mean "there is at least one task", so a project whose tasks were only
513
661
  REGISTERED - nobody had started it, nobody was working on it - claimed on its card to be
@@ -521,7 +669,7 @@ export class ProjectService {
521
669
  A project has a leader session only after `start`, so the leader is the signal - not the
522
670
  task count, and not anything the client sends. */
523
671
  p.status = openBoss.some((e) => e.severity === "high") ? "awaiting_approval"
524
- : openBoss.length || hasLeaderBlockedTask || leaderProjectBlocked ? "blocked"
672
+ : openBoss.length || hasLeaderBlockedTask || leaderProjectBlocked || hasInterruptedTask ? "blocked"
525
673
  : p.tasks.some((t) => t.status === "awaiting_review") ? "awaiting_review"
526
674
  : p.tasks.length ? (p.ownerConversationId ? "active" : "awaiting_start") : "planning";
527
675
  }
@@ -635,6 +783,13 @@ export class ProjectService {
635
783
  The headline says what is true, in the same words the card uses. */
636
784
  if (total > 0 && !p.ownerConversationId)
637
785
  return `已登记 ${total} 个任务,项目待启动`;
786
+ /* A TASK WHOSE EXECUTION SESSION IS GONE. Nothing is running for it and nobody will report
787
+ back on it, so the headline must not say 「正在执行」 - the reader would wait for a turn that
788
+ is never coming. It says the task is interrupted and needs to be put back out. */
789
+ const interruptedTask = p.tasks.find((t) => t.status === "interrupted");
790
+ if (interruptedTask) {
791
+ return `${completed}/${total} 任务完成,${interruptedTask.title} 已中断(执行会话不在了),等待恢复`;
792
+ }
638
793
  const inProgressTask = p.tasks.find((t) => t.status === "in_progress");
639
794
  if (inProgressTask) {
640
795
  return `${completed}/${total} 任务完成,正在执行${inProgressTask.title}`;
@@ -656,11 +811,15 @@ export class ProjectService {
656
811
  return this.isMember(p, actor);
657
812
  }
658
813
  projectSummary(p, actor) {
814
+ /* THE AGENT'S OWN LIST IS CORRECTED TOO. An agent that reads 「执行中」 for a task whose
815
+ session is gone will wait for a report that is never coming, and it has no way to tell the
816
+ difference - so the summary counts the interrupted tasks separately instead. */
817
+ this.reconcileInterrupted(p);
659
818
  const resources = this.resources(p);
660
819
  return {
661
820
  id: p.id,
662
821
  name: p.title,
663
- status: p.status,
822
+ status: this.statusWithInterruptions(p),
664
823
  mode: p.mode ?? "standard",
665
824
  headline: this.headline(p, actor),
666
825
  tasks: {
@@ -668,6 +827,7 @@ export class ProjectService {
668
827
  completed: p.tasks.filter((t) => t.status === "completed").length,
669
828
  inProgress: p.tasks.filter((t) => t.status === "in_progress").length,
670
829
  blocked: p.tasks.filter((t) => t.status === "blocked").length,
830
+ interrupted: p.tasks.filter((t) => t.status === "interrupted").length,
671
831
  },
672
832
  activeWorkers: resources.activeWorkers,
673
833
  tokens: resources.tokens,
@@ -718,6 +878,10 @@ export class ProjectService {
718
878
  const p = workspaceId === undefined ? this.store.project(id) : this.raw(id, workspaceId);
719
879
  if (!p)
720
880
  throw new Error("项目不存在或不属于当前工作区");
881
+ /* THE REPORT READS THE CORRECTED PROJECT. A report that called an interrupted task
882
+ 「执行中」 would be a document of lies - and the report is the thing that gets pasted into
883
+ a weekly note, so it has to survive being read by somebody who was not there. */
884
+ this.reconcileInterrupted(p);
721
885
  const store = this.store;
722
886
  /** THE TITLE A PERSON CALLS A SESSION BY. The handle stays out of the report. */
723
887
  const session = (conversationId) => {
@@ -776,6 +940,8 @@ export class ProjectService {
776
940
  lines.push(`### ${index + 1}. ${oneLine(t.title)}`, "");
777
941
  lines.push(`- 角色:${role(t)}`);
778
942
  lines.push(`- 状态:${TASK_STATUS_TEXT[t.status] ?? t.status}`);
943
+ if (t.status === "interrupted")
944
+ lines.push(`- 中断原因:${oneLine(t.interruptedReason ?? "执行会话不在了")}`);
779
945
  lines.push(`- 负责人:${t.ownerConversationId ? session(t.ownerConversationId) : "未派发"}`);
780
946
  lines.push(`- 复核者:${t.reviewerConversationId ? session(t.reviewerConversationId) : "无"}`);
781
947
  lines.push(`- 交付内容:${t.output ? truncate(oneLine(t.output), 200) : "无"}`);
@@ -792,9 +958,25 @@ export class ProjectService {
792
958
  if (!p.escalations.length)
793
959
  lines.push("无");
794
960
  else {
961
+ /* THE TABLE IS FOR COMPARING, so the cell is a TITLE - the question the reader decides on -
962
+ and the case goes under the table. A whole paragraph in one cell makes the table
963
+ unreadable, and a table that cannot be scanned is not a table any more. */
795
964
  lines.push("| 例外 | 严重程度 | 状态 | 决定 | 解决时间 |", "| --- | --- | --- | --- | --- |");
796
965
  for (const e of p.escalations) {
797
- lines.push(`| ${cell(e.reason)} | ${SEVERITY_TEXT[e.severity] ?? e.severity} | ${ESCALATION_STATUS_TEXT[e.status] ?? e.status} | ${cell(e.decision ?? "无")} | ${e.resolvedAt ? moment(e.resolvedAt) : "无"} |`);
966
+ 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) : "无"} |`);
967
+ }
968
+ /* AND THE CASE IS NOT LOST. The title is what the reader compares; the reason is WHY, and it
969
+ is a paragraph - so it is printed in full below the table, where a paragraph belongs. */
970
+ const cases = p.escalations.filter((e) => (e.reason ?? "").trim());
971
+ if (cases.length) {
972
+ lines.push("", "例外详情:", "");
973
+ for (const e of cases) {
974
+ /* AN EXCEPTION WITH A TITLE is named by it; one without has only its case, and the case
975
+ is already the whole line - repeating its first sentence in front of it would say the
976
+ same thing twice. */
977
+ const title = e.title?.trim();
978
+ lines.push(title ? `- ${oneLine(title)}:${oneLine(e.reason)}` : `- ${oneLine(e.reason)}`);
979
+ }
798
980
  }
799
981
  }
800
982
  lines.push("", "## 时间线", "");
@@ -1022,10 +1204,21 @@ export class ProjectService {
1022
1204
  return this.change(id, workspaceId, async (p) => {
1023
1205
  const t = this.task(p, taskId);
1024
1206
  const manager = this.manager(p, t, actor);
1207
+ /* WAS THIS TASK INTERRUPTED? It is remembered before the status moves on, because both the
1208
+ worker and the reader need to know that this is a task coming back from a dead session,
1209
+ not a task that is being started for the first time. */
1210
+ const wasInterrupted = t.status === "interrupted";
1211
+ const interruptedNote = t.interruptedReason;
1025
1212
  if (!dependenciesComplete(p, t))
1026
1213
  throw new Error("任务的前置依赖尚未全部完成,不能开始执行");
1027
- if (t.status !== "ready")
1028
- throw new Error("仅待派发任务可以启动");
1214
+ /* AN INTERRUPTED TASK CAN BE SENT OUT AGAIN. It used to be impossible: the task was stuck
1215
+ at `in_progress` with a session that no longer existed, and `dispatchTask` refused
1216
+ anything that was not `ready` - so a task whose execution session had died could never be
1217
+ dispatched again, and the only way out was two buttons in the wrong order. `interrupted` is
1218
+ the state that says "the execution is gone, put it back out", so it is a state this
1219
+ operation accepts. */
1220
+ if (t.status !== "ready" && t.status !== "interrupted")
1221
+ throw new Error("仅待派发或已中断的任务可以启动");
1029
1222
  this.admission(p, true, t.role === "leader");
1030
1223
  if (t.role === "leader" && !t.ownerConversationId && p.tasks.filter((t) => t.role === "leader" && t.ownerConversationId).length >= 8)
1031
1224
  throw new Error("分支 Leader 最多 8 个,请收敛组织层级");
@@ -1061,10 +1254,15 @@ export class ProjectService {
1061
1254
  // it has taken on.
1062
1255
  if (!lightweight(p) && busy(this.store.conversation(t.ownerConversationId)?.status))
1063
1256
  throw new Error("执行会话尚未结束,请等待完成回报后派发");
1257
+ /* THE MOMENT THE TASK WENT OUT IS WRITTEN DOWN. It is what tells a session that died BEFORE
1258
+ this dispatch from one that died AFTER it: only the second one interrupted the task, and
1259
+ only the second one may turn it into 「已中断」. */
1064
1260
  t.status = "in_progress";
1065
1261
  t.updatedAt = stamp();
1262
+ t.dispatchedAt = t.updatedAt;
1066
1263
  delete t.blockedReason;
1067
1264
  delete t.blockedReportedByConversationId;
1265
+ delete t.interruptedReason;
1068
1266
  this.event(p, "dispatched", `派发执行:${t.title}`, t.id, actor);
1069
1267
  this.reconcile(p);
1070
1268
  await this.store.setProject(p);
@@ -1073,7 +1271,30 @@ export class ProjectService {
1073
1271
  no reviewer coming back, so the evidence that the reviewer would have demanded is the only
1074
1272
  thing that stands behind the delivery. */
1075
1273
  const modeNote = lightweight(p) ? "本项目是轻量项目:你就是唯一的执行会话,不会有独立复核人回来,完成后调用 project(action=submit, …) 提交即完成,交付证据必须附上。" : "";
1076
- await this.orchestrator.dispatch(t.ownerConversationId, `${this.context(p)}\n${delegation}\n你负责执行任务 ${t.id}:${t.title}\n目标:${t.objective}\n交付物:${t.deliverables.join(";")}\n验收:${t.acceptanceCriteria.join(";")}\n上次复核意见与验证证据:${JSON.stringify(t.review ?? null)}\n已验收前置产物:${JSON.stringify(p.tasks.filter((d) => t.dependencies.includes(d.id)).map((d) => ({ title: d.title, output: d.output, evidenceRefs: d.evidenceRefs })))}\n你不是唯一执行者,遵守分工边界。${modeNote}完成后必须调用 project(action=submit, projectId="${p.id}", taskId="${t.id}", output="交付总结", evidenceRefs=["产物路径或验证记录"]),不能自行标记已完成。复核退回时修复后重新 submit。遇到阻塞用 report(阻塞) 或 escalate 上报给你的直接上级,不要直接找 Boss,保留证据、假设和未解决问题。不要自行创建其他执行会话或 task/workflow。`, { wait: false });
1274
+ /* THE TASK THAT WAS INTERRUPTED IS TOLD WHAT HAPPENED. A worker that comes back to a task
1275
+ it was working on has no idea whether the work it half did is still wanted, and the
1276
+ default - carry on as if nothing happened - is the wrong one after a crash. */
1277
+ const recoveryNote = wasInterrupted
1278
+ ? `\n注意:这个任务上一次执行被中断了(${oneLine(interruptedNote ?? "执行会话不在了")})。请先确认当前状态,再继续完成交付;不要假设上一次的工作已经完成。`
1279
+ : "";
1280
+ try {
1281
+ await this.orchestrator.dispatch(t.ownerConversationId, `${this.context(p)}\n${delegation}\n你负责执行任务 ${t.id}:${t.title}\n目标:${t.objective}\n交付物:${t.deliverables.join(";")}\n验收:${t.acceptanceCriteria.join(";")}\n上次复核意见与验证证据:${JSON.stringify(t.review ?? null)}\n已验收前置产物:${JSON.stringify(p.tasks.filter((d) => t.dependencies.includes(d.id)).map((d) => ({ title: d.title, output: d.output, evidenceRefs: d.evidenceRefs })))}\n你不是唯一执行者,遵守分工边界。${modeNote}${recoveryNote}完成后必须调用 project(action=submit, projectId="${p.id}", taskId="${t.id}", output="交付总结", evidenceRefs=["产物路径或验证记录"]),不能自行标记已完成。复核退回时修复后重新 submit。遇到阻塞用 report(阻塞) 或 escalate 上报给你的直接上级,不要直接找 Boss,保留证据、假设和未解决问题。不要自行创建其他执行会话或 task/workflow。`, { wait: false });
1282
+ }
1283
+ catch (error) {
1284
+ /* A DISPATCH THAT DID NOT HAPPEN MUST NOT LEAVE THE TASK SAYING 「执行中」. The status was
1285
+ already written down before the dispatch - that ordering is deliberate, so a reader can
1286
+ never see a task that is executing while the session was never told to run - but it means
1287
+ a failed dispatch has to correct the record itself. The task goes back to 「已中断」 with
1288
+ the reason, because that is exactly what it is: the work is not running, and nobody is
1289
+ going to report back on it. */
1290
+ const message = error instanceof Error ? error.message : String(error);
1291
+ t.status = "interrupted";
1292
+ t.interruptedReason = `重新派发没有成功:${message}`;
1293
+ t.updatedAt = stamp();
1294
+ this.event(p, "task_updated", `重新派发失败,任务已中断:${t.title}`, t.id, actor);
1295
+ await this.store.setProject(p);
1296
+ throw error;
1297
+ }
1077
1298
  return ProjectService.taskView(t, p);
1078
1299
  });
1079
1300
  }
@@ -940,7 +940,20 @@ export type TerminalShell = {
940
940
  args: string[];
941
941
  };
942
942
  export type ProjectStatus = "planning" | "awaiting_start" | "active" | "blocked" | "awaiting_approval" | "awaiting_review" | "completed" | "failed" | "cancelled";
943
- export type ProjectTaskStatus = "pending" | "ready" | "in_progress" | "blocked" | "awaiting_review" | "completed" | "failed" | "cancelled";
943
+ /**
944
+ * THE STATES A TASK CAN BE IN.
945
+ *
946
+ * `interrupted` is the one that says the EXECUTION IS GONE: the session that was supposed to be
947
+ * running this task is no longer there - it failed, it was stopped, or its record disappeared with
948
+ * the process that held it. It is NOT `failed` (that is the executor reporting its own failure, in
949
+ * its own words, with its own evidence) and it is NOT `ready` (a ready task is one that has never
950
+ * been started, or that was sent back for rework and is waiting to be picked up again).
951
+ *
952
+ * A task in `interrupted` cannot advance on its own: nobody will ever report back on it. That is
953
+ * exactly why it needs its own state - the Boss has to be able to see it AND be able to send it
954
+ * back out again, and neither "failed" nor "ready" says both.
955
+ */
956
+ export type ProjectTaskStatus = "pending" | "ready" | "in_progress" | "interrupted" | "blocked" | "awaiting_review" | "completed" | "failed" | "cancelled";
944
957
  export type ProjectRisk = "low" | "medium" | "high";
945
958
  /**
946
959
  * HOW A PROJECT RUNS.
@@ -989,6 +1002,13 @@ export type ProjectTask = {
989
1002
  dueAt?: string;
990
1003
  blockedReason?: string;
991
1004
  blockedReportedByConversationId?: string;
1005
+ /** WHY THIS TASK IS INTERRUPTED, in one sentence, for the reader. It says what happened to the
1006
+ * execution session - the fact that makes the task's own state impossible to keep. */
1007
+ interruptedReason?: string;
1008
+ /** WHEN THIS TASK WAS LAST DISPATCHED. It is what tells a session that died BEFORE the dispatch
1009
+ * from one that died AFTER it: only the second one interrupted the task. Absent on a task that
1010
+ * was registered before dispatch times were written down. */
1011
+ dispatchedAt?: string;
992
1012
  output?: string;
993
1013
  evidenceRefs?: string[];
994
1014
  /** The acceptance of this task. `lightweight: true` means the executor accepted its own
@@ -1140,11 +1160,14 @@ export type ProjectSummary = {
1140
1160
  status: string;
1141
1161
  mode: "standard" | "lightweight";
1142
1162
  headline: string;
1163
+ /** `interrupted` counts the tasks whose execution session is gone: they are not running, and
1164
+ * they are not done either - they are waiting to be sent out again. */
1143
1165
  tasks: {
1144
1166
  total: number;
1145
1167
  completed: number;
1146
1168
  inProgress: number;
1147
1169
  blocked: number;
1170
+ interrupted?: number;
1148
1171
  };
1149
1172
  activeWorkers: number;
1150
1173
  tokens: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.168",
3
+ "version": "0.1.170",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -87,6 +87,7 @@
87
87
  "scripts/session-result-callback-e2e.test.mjs",
88
88
  "scripts/session-orchestrator-tools.test.mjs",
89
89
  "scripts/project-service.test.mjs",
90
+ "scripts/project-report-exception-title.test.mjs",
90
91
  "scripts/project-api-scope.test.mjs",
91
92
  "scripts/project-report-chain.test.mjs",
92
93
  "scripts/session-tree-collapse.test.mjs",
@@ -234,7 +235,8 @@
234
235
  "scripts/project-lifecycle-e2e.test.mjs",
235
236
  "scripts/agent-tiers.test.mjs",
236
237
  "scripts/design-principles.test.mjs",
237
- "scripts/primary-employee-guard.test.mjs"
238
+ "scripts/primary-employee-guard.test.mjs",
239
+ "scripts/interrupted-task-recovery.test.mjs"
238
240
  ],
239
241
  "check:browser": [
240
242
  "scripts/interrupt-browser.test.mjs",
@@ -272,6 +274,7 @@
272
274
  "scripts/project-evidence-panel-browser.test.mjs",
273
275
  "scripts/project-panel-fixes-browser.test.mjs",
274
276
  "scripts/boss-approval-readability-browser.test.mjs",
277
+ "scripts/prose-tidying-browser.test.mjs",
275
278
  "scripts/builtin-agents-project-browser.test.mjs",
276
279
  "scripts/tool-runtime-browser.test.mjs",
277
280
  "scripts/session-context-menu-browser.test.mjs",
@@ -327,7 +330,8 @@
327
330
  "scripts/session-origin-badge-browser.test.mjs",
328
331
  "scripts/rail-ui-layout-browser.test.mjs",
329
332
  "scripts/session-landing-browser.test.mjs",
330
- "scripts/responsive-rail-drawer-browser.test.mjs"
333
+ "scripts/responsive-rail-drawer-browser.test.mjs",
334
+ "scripts/interrupted-task-recovery-browser.test.mjs"
331
335
  ],
332
336
  "dependencies": {
333
337
  "@codemirror/commands": "^6.11.1",