@evandu/super-pi 0.1.169 → 0.1.171
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.
- package/agents/super-pi-task/core.ts +1 -1
- package/agents/super-pi-task/index.ts +3 -1
- package/dist/client/.super-pi-client-sources.json +4 -4
- package/dist/client/assets/{CodeMirrorEditor-DArgTlD3.js → CodeMirrorEditor-CzUeGDdc.js} +2 -2
- package/dist/client/assets/{dist-D3E66dY7.js → dist-B26sLQy-.js} +1 -1
- package/dist/client/assets/{dist-DUQ9n5h9.js → dist-BCVQCJK1.js} +1 -1
- package/dist/client/assets/{dist-maPYW6Rs.js → dist-BOiPOwIz.js} +1 -1
- package/dist/client/assets/{dist-EyFCbD4n.js → dist-BlVF_BSL.js} +1 -1
- package/dist/client/assets/{dist-B-z8liQC.js → dist-BpnlFbvg.js} +1 -1
- package/dist/client/assets/{dist-BFaPEuXW.js → dist-C2Ih1t5h.js} +1 -1
- package/dist/client/assets/{dist-t2Ar76ug.js → dist-C2V8B6YE.js} +1 -1
- package/dist/client/assets/{dist-DN_OOAtP.js → dist-C2e4r6Qm.js} +1 -1
- package/dist/client/assets/{dist-DhpsFeLh.js → dist-CGpm7VDj.js} +1 -1
- package/dist/client/assets/{dist-NDu6lgDA.js → dist-CUbRB6Gb.js} +1 -1
- package/dist/client/assets/{dist-CvSvjAn3.js → dist-CZh-o5Ms.js} +1 -1
- package/dist/client/assets/{dist-DKB8S6yA.js → dist-CjSFpJ5l.js} +1 -1
- package/dist/client/assets/{dist-DN-9z_cD.js → dist-CtLhwtKR.js} +1 -1
- package/dist/client/assets/{dist-HsjzJlZ8.js → dist-DSclOmZU.js} +1 -1
- package/dist/client/assets/{dist-ChtaZGr2.js → dist-DWWeqjij.js} +1 -1
- package/dist/client/assets/{dist-CUbflO-e.js → dist-DWt_M7vb.js} +1 -1
- package/dist/client/assets/{dist-BrRu0IXM.js → dist-DiclZJGi.js} +1 -1
- package/dist/client/assets/{dist-C898Y-mu.js → dist-Dn_hEfpF.js} +1 -1
- package/dist/client/assets/{dist-D_aMYdFI.js → dist-DpgtEKyP.js} +1 -1
- package/dist/client/assets/{dist-DvtXvGUC.js → dist-DyBgPEEv.js} +1 -1
- package/dist/client/assets/{dist-J2qLs06H.js → dist-HVW2Jgge.js} +1 -1
- package/dist/client/assets/{dist-DyVwIwcR.js → dist-b302HMV6.js} +1 -1
- package/dist/client/assets/{index-mr3cD5bb.js → index-BqO2dVq8.js} +4 -4
- package/dist/client/assets/{index-bxZsZR4M.css → index-DUNPa0xu.css} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/application/project-service.d.ts +64 -0
- package/dist/server/application/project-service.js +184 -6
- package/dist/server/types.d.ts +24 -1
- package/package.json +6 -3
package/dist/client/index.html
CHANGED
|
@@ -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-
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
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 = {
|
|
@@ -292,9 +292,15 @@ export class ProjectService {
|
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
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);
|
|
295
300
|
const resources = this.resources(p);
|
|
296
301
|
return {
|
|
297
302
|
...p,
|
|
303
|
+
status: this.statusWithInterruptions(p),
|
|
298
304
|
resources,
|
|
299
305
|
suggestedMaxTokens: this.suggestedMaxTokens(p, resources.tokens),
|
|
300
306
|
tasks: p.tasks.map((t) => ProjectService.taskView(t, p)),
|
|
@@ -336,6 +342,11 @@ export class ProjectService {
|
|
|
336
342
|
const previous = this.queues.get(id) ?? Promise.resolve();
|
|
337
343
|
const pending = previous.catch(() => { }).then(async () => {
|
|
338
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);
|
|
339
350
|
const result = await work(p);
|
|
340
351
|
for (const t of p.tasks) {
|
|
341
352
|
delete t.effectiveExecutorProfile;
|
|
@@ -399,6 +410,110 @@ export class ProjectService {
|
|
|
399
410
|
}
|
|
400
411
|
leader(p, actor) { if (actor && actor !== p.ownerConversationId)
|
|
401
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
|
+
}
|
|
402
517
|
topLevelAuthor(p, actor) {
|
|
403
518
|
if (!actor)
|
|
404
519
|
return;
|
|
@@ -535,6 +650,12 @@ export class ProjectService {
|
|
|
535
650
|
const hasLeaderBlockedTask = p.tasks.some((t) => t.status === "blocked" && isLeader(t.blockedReportedByConversationId));
|
|
536
651
|
const lastLeaderProjectReport = [...p.reports].reverse().find((r) => !r.taskId && isLeader(r.authorConversationId));
|
|
537
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");
|
|
538
659
|
/* A PROJECT THAT HAS WORK REGISTERED BUT NO LEADER SESSION YET IS NOT RUNNING.
|
|
539
660
|
"active" used to mean "there is at least one task", so a project whose tasks were only
|
|
540
661
|
REGISTERED - nobody had started it, nobody was working on it - claimed on its card to be
|
|
@@ -548,7 +669,7 @@ export class ProjectService {
|
|
|
548
669
|
A project has a leader session only after `start`, so the leader is the signal - not the
|
|
549
670
|
task count, and not anything the client sends. */
|
|
550
671
|
p.status = openBoss.some((e) => e.severity === "high") ? "awaiting_approval"
|
|
551
|
-
: openBoss.length || hasLeaderBlockedTask || leaderProjectBlocked ? "blocked"
|
|
672
|
+
: openBoss.length || hasLeaderBlockedTask || leaderProjectBlocked || hasInterruptedTask ? "blocked"
|
|
552
673
|
: p.tasks.some((t) => t.status === "awaiting_review") ? "awaiting_review"
|
|
553
674
|
: p.tasks.length ? (p.ownerConversationId ? "active" : "awaiting_start") : "planning";
|
|
554
675
|
}
|
|
@@ -662,6 +783,13 @@ export class ProjectService {
|
|
|
662
783
|
The headline says what is true, in the same words the card uses. */
|
|
663
784
|
if (total > 0 && !p.ownerConversationId)
|
|
664
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
|
+
}
|
|
665
793
|
const inProgressTask = p.tasks.find((t) => t.status === "in_progress");
|
|
666
794
|
if (inProgressTask) {
|
|
667
795
|
return `${completed}/${total} 任务完成,正在执行${inProgressTask.title}`;
|
|
@@ -683,11 +811,15 @@ export class ProjectService {
|
|
|
683
811
|
return this.isMember(p, actor);
|
|
684
812
|
}
|
|
685
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);
|
|
686
818
|
const resources = this.resources(p);
|
|
687
819
|
return {
|
|
688
820
|
id: p.id,
|
|
689
821
|
name: p.title,
|
|
690
|
-
status: p
|
|
822
|
+
status: this.statusWithInterruptions(p),
|
|
691
823
|
mode: p.mode ?? "standard",
|
|
692
824
|
headline: this.headline(p, actor),
|
|
693
825
|
tasks: {
|
|
@@ -695,6 +827,7 @@ export class ProjectService {
|
|
|
695
827
|
completed: p.tasks.filter((t) => t.status === "completed").length,
|
|
696
828
|
inProgress: p.tasks.filter((t) => t.status === "in_progress").length,
|
|
697
829
|
blocked: p.tasks.filter((t) => t.status === "blocked").length,
|
|
830
|
+
interrupted: p.tasks.filter((t) => t.status === "interrupted").length,
|
|
698
831
|
},
|
|
699
832
|
activeWorkers: resources.activeWorkers,
|
|
700
833
|
tokens: resources.tokens,
|
|
@@ -745,6 +878,10 @@ export class ProjectService {
|
|
|
745
878
|
const p = workspaceId === undefined ? this.store.project(id) : this.raw(id, workspaceId);
|
|
746
879
|
if (!p)
|
|
747
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);
|
|
748
885
|
const store = this.store;
|
|
749
886
|
/** THE TITLE A PERSON CALLS A SESSION BY. The handle stays out of the report. */
|
|
750
887
|
const session = (conversationId) => {
|
|
@@ -803,6 +940,8 @@ export class ProjectService {
|
|
|
803
940
|
lines.push(`### ${index + 1}. ${oneLine(t.title)}`, "");
|
|
804
941
|
lines.push(`- 角色:${role(t)}`);
|
|
805
942
|
lines.push(`- 状态:${TASK_STATUS_TEXT[t.status] ?? t.status}`);
|
|
943
|
+
if (t.status === "interrupted")
|
|
944
|
+
lines.push(`- 中断原因:${oneLine(t.interruptedReason ?? "执行会话不在了")}`);
|
|
806
945
|
lines.push(`- 负责人:${t.ownerConversationId ? session(t.ownerConversationId) : "未派发"}`);
|
|
807
946
|
lines.push(`- 复核者:${t.reviewerConversationId ? session(t.reviewerConversationId) : "无"}`);
|
|
808
947
|
lines.push(`- 交付内容:${t.output ? truncate(oneLine(t.output), 200) : "无"}`);
|
|
@@ -1065,10 +1204,21 @@ export class ProjectService {
|
|
|
1065
1204
|
return this.change(id, workspaceId, async (p) => {
|
|
1066
1205
|
const t = this.task(p, taskId);
|
|
1067
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;
|
|
1068
1212
|
if (!dependenciesComplete(p, t))
|
|
1069
1213
|
throw new Error("任务的前置依赖尚未全部完成,不能开始执行");
|
|
1070
|
-
|
|
1071
|
-
|
|
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("仅待派发或已中断的任务可以启动");
|
|
1072
1222
|
this.admission(p, true, t.role === "leader");
|
|
1073
1223
|
if (t.role === "leader" && !t.ownerConversationId && p.tasks.filter((t) => t.role === "leader" && t.ownerConversationId).length >= 8)
|
|
1074
1224
|
throw new Error("分支 Leader 最多 8 个,请收敛组织层级");
|
|
@@ -1104,10 +1254,15 @@ export class ProjectService {
|
|
|
1104
1254
|
// it has taken on.
|
|
1105
1255
|
if (!lightweight(p) && busy(this.store.conversation(t.ownerConversationId)?.status))
|
|
1106
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 「已中断」. */
|
|
1107
1260
|
t.status = "in_progress";
|
|
1108
1261
|
t.updatedAt = stamp();
|
|
1262
|
+
t.dispatchedAt = t.updatedAt;
|
|
1109
1263
|
delete t.blockedReason;
|
|
1110
1264
|
delete t.blockedReportedByConversationId;
|
|
1265
|
+
delete t.interruptedReason;
|
|
1111
1266
|
this.event(p, "dispatched", `派发执行:${t.title}`, t.id, actor);
|
|
1112
1267
|
this.reconcile(p);
|
|
1113
1268
|
await this.store.setProject(p);
|
|
@@ -1116,7 +1271,30 @@ export class ProjectService {
|
|
|
1116
1271
|
no reviewer coming back, so the evidence that the reviewer would have demanded is the only
|
|
1117
1272
|
thing that stands behind the delivery. */
|
|
1118
1273
|
const modeNote = lightweight(p) ? "本项目是轻量项目:你就是唯一的执行会话,不会有独立复核人回来,完成后调用 project(action=submit, …) 提交即完成,交付证据必须附上。" : "";
|
|
1119
|
-
|
|
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
|
+
}
|
|
1120
1298
|
return ProjectService.taskView(t, p);
|
|
1121
1299
|
});
|
|
1122
1300
|
}
|
package/dist/server/types.d.ts
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "0.1.171",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"scripts/project-report-exception-title.test.mjs",
|
|
91
91
|
"scripts/project-api-scope.test.mjs",
|
|
92
92
|
"scripts/project-report-chain.test.mjs",
|
|
93
|
+
"scripts/project-tool-surface-parity.test.mjs",
|
|
93
94
|
"scripts/session-tree-collapse.test.mjs",
|
|
94
95
|
"scripts/archive-cascade.test.mjs",
|
|
95
96
|
"scripts/workspace-cwd.test.mjs",
|
|
@@ -235,7 +236,8 @@
|
|
|
235
236
|
"scripts/project-lifecycle-e2e.test.mjs",
|
|
236
237
|
"scripts/agent-tiers.test.mjs",
|
|
237
238
|
"scripts/design-principles.test.mjs",
|
|
238
|
-
"scripts/primary-employee-guard.test.mjs"
|
|
239
|
+
"scripts/primary-employee-guard.test.mjs",
|
|
240
|
+
"scripts/interrupted-task-recovery.test.mjs"
|
|
239
241
|
],
|
|
240
242
|
"check:browser": [
|
|
241
243
|
"scripts/interrupt-browser.test.mjs",
|
|
@@ -329,7 +331,8 @@
|
|
|
329
331
|
"scripts/session-origin-badge-browser.test.mjs",
|
|
330
332
|
"scripts/rail-ui-layout-browser.test.mjs",
|
|
331
333
|
"scripts/session-landing-browser.test.mjs",
|
|
332
|
-
"scripts/responsive-rail-drawer-browser.test.mjs"
|
|
334
|
+
"scripts/responsive-rail-drawer-browser.test.mjs",
|
|
335
|
+
"scripts/interrupted-task-recovery-browser.test.mjs"
|
|
333
336
|
],
|
|
334
337
|
"dependencies": {
|
|
335
338
|
"@codemirror/commands": "^6.11.1",
|