@evandu/super-pi 0.1.218 → 0.1.219

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 (52) hide show
  1. package/agents/project-leader.md +1 -1
  2. package/agents/super-pi-task/core.ts +1 -1
  3. package/agents/super-pi-task/index.ts +4 -2
  4. package/dist/client/.super-pi-client-sources.json +6 -6
  5. package/dist/client/assets/{CodeMirrorEditor-CyESWKhO.js → CodeMirrorEditor-BoRBaVec.js} +2 -2
  6. package/dist/client/assets/{dist-DHh4-Br1.js → dist-BOC9yjsN.js} +1 -1
  7. package/dist/client/assets/{dist-DH6F4kKv.js → dist-BOF4T7jI.js} +1 -1
  8. package/dist/client/assets/{dist-1djw1Aua.js → dist-BVVJTFYw.js} +1 -1
  9. package/dist/client/assets/{dist-BwQiVXeZ.js → dist-BXOV_xtI.js} +1 -1
  10. package/dist/client/assets/{dist-BXMYNRiG.js → dist-Bh20DSAa.js} +1 -1
  11. package/dist/client/assets/{dist-DZGY_CNU.js → dist-CIv6vCdn.js} +1 -1
  12. package/dist/client/assets/{dist-GMozZ-IZ.js → dist-CMdO3YzL.js} +1 -1
  13. package/dist/client/assets/{dist-C9qNY2Kp.js → dist-CPjKkcyd.js} +1 -1
  14. package/dist/client/assets/{dist-BQ5yUYGI.js → dist-CYpk6fXT.js} +1 -1
  15. package/dist/client/assets/{dist-xAE0Sxu_.js → dist-CiRgPe6t.js} +1 -1
  16. package/dist/client/assets/{dist-C7y8W3IU.js → dist-CjhpwEGf.js} +1 -1
  17. package/dist/client/assets/{dist-CWLwzCNI.js → dist-Cp3XgqJR.js} +1 -1
  18. package/dist/client/assets/{dist-B33BwR-8.js → dist-D1hdxSH6.js} +1 -1
  19. package/dist/client/assets/{dist-BXq9HMCd.js → dist-DLYLxwOe.js} +1 -1
  20. package/dist/client/assets/{dist-Cgclz1Km.js → dist-DQ_C0DEU.js} +1 -1
  21. package/dist/client/assets/{dist-CkjmcyTq.js → dist-DUbHNa35.js} +1 -1
  22. package/dist/client/assets/{dist-BfAB10-T.js → dist-Digy2Mj0.js} +1 -1
  23. package/dist/client/assets/{dist-XNj0UVAT.js → dist-DvWgfLRt.js} +1 -1
  24. package/dist/client/assets/{dist-C6tiomV0.js → dist-Dwsqs8C-.js} +1 -1
  25. package/dist/client/assets/{dist-DtyV497P.js → dist-gRtmlyhZ.js} +1 -1
  26. package/dist/client/assets/{dist-Zl8KoipB.js → dist-mAA5Fw0-.js} +1 -1
  27. package/dist/client/assets/{dist-BlALlifb.js → dist-xb23AFcT.js} +1 -1
  28. package/dist/client/assets/{index-2k9h0zMt.js → index-DmxXnVfN.js} +11 -11
  29. package/dist/client/assets/index-Nu--gcBs.css +1 -0
  30. package/dist/client/index.html +2 -2
  31. package/dist/server/application/conversation-service.d.ts +7 -2
  32. package/dist/server/application/conversation-service.js +45 -5
  33. package/dist/server/application/project-service.d.ts +8 -4
  34. package/dist/server/application/project-service.js +76 -34
  35. package/dist/server/application/run-service.js +2 -0
  36. package/dist/server/application/session-orchestrator-service.d.ts +3 -0
  37. package/dist/server/application/session-orchestrator-service.js +53 -21
  38. package/dist/server/command-handler.d.ts +3 -1
  39. package/dist/server/command-handler.js +21 -1
  40. package/dist/server/index.js +2 -2
  41. package/dist/server/store.d.ts +7 -1
  42. package/dist/server/store.js +47 -8
  43. package/dist/server/types.d.ts +17 -1
  44. package/dist/server/upload.d.ts +2 -0
  45. package/dist/server/upload.js +19 -2
  46. package/dist/shared/project-overview.d.ts +9 -0
  47. package/dist/shared/project-overview.js +21 -7
  48. package/dist/shared/project-presentation.d.ts +3 -0
  49. package/dist/shared/project-presentation.js +13 -5
  50. package/dist/shared/team-context.d.ts +1 -1
  51. package/package.json +1 -1
  52. package/dist/client/assets/index-CwfAN5Vw.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-2k9h0zMt.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-CwfAN5Vw.css">
11
+ <script type="module" crossorigin src="/assets/index-DmxXnVfN.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index-Nu--gcBs.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="root"></div>
@@ -38,14 +38,16 @@ export declare class ConversationService {
38
38
  private readonly runService;
39
39
  private readonly extensionUiService;
40
40
  private agentsDir;
41
+ private readonly uploadsDir?;
41
42
  /** Conversations whose Pi transcript is being cut RIGHT NOW. Read by the send path, below. */
42
43
  private readonly reverting;
43
44
  /** Reverts for one conversation must never truncate the same Pi file concurrently. */
44
45
  private readonly revertOps;
45
46
  /** The memory store, so a revert can undo what that conversation taught it. Set by `setMemory`. */
46
47
  private memory?;
47
- constructor(store: Store, runtime: AgentRuntime, subagents: SubagentRunRecorder, broadcaster: EventBroadcaster, catalogService: CatalogService, runService: RunService, extensionUiService: ExtensionUiService, agentsDir: string | string[]);
48
+ constructor(store: Store, runtime: AgentRuntime, subagents: SubagentRunRecorder, broadcaster: EventBroadcaster, catalogService: CatalogService, runService: RunService, extensionUiService: ExtensionUiService, agentsDir: string | string[], uploadsDir?: string | undefined);
48
49
  setAgentsDir(dir: string | string[]): void;
50
+ isWarmSession(conversationId: string): boolean;
49
51
  /**
50
52
  * Creates a new conversation in a workspace.
51
53
  *
@@ -203,7 +205,10 @@ export declare class ConversationService {
203
205
  /**
204
206
  * Forks an existing conversation into a new parallel branch, cloning the Pi session.
205
207
  */
206
- forkConversation(conversationId: string): Promise<ForkConversationResult>;
208
+ forkConversation(conversationId: string, options?: {
209
+ parentConversationId?: string;
210
+ warmTitle?: string;
211
+ }): Promise<ForkConversationResult>;
207
212
  /**
208
213
  * Cancels pending UI/sub-agent work and clears active memory notes for a conversation about to
209
214
  * be permanently destroyed (runs while the conversation is still readable in the store).
@@ -2,6 +2,8 @@ import { assertModelAllowed } from "../model-filter.js";
2
2
  import { newConversationId } from "../store.js";
3
3
  import { normalizeSessionCwd, resolveSessionCwd } from "../session-cwd.js";
4
4
  import { isChildSession } from "../../shared/child-session-lock.js";
5
+ import { rm } from "node:fs/promises";
6
+ import { copyForkUploads, deleteConversationUploads } from "../upload.js";
5
7
  function isMissingPrimaryAgent(error, agentId) {
6
8
  const message = error instanceof Error ? error.message : String(error);
7
9
  const id = JSON.stringify(agentId);
@@ -21,6 +23,7 @@ export class ConversationService {
21
23
  runService;
22
24
  extensionUiService;
23
25
  agentsDir;
26
+ uploadsDir;
24
27
  /** Conversations whose Pi transcript is being cut RIGHT NOW. Read by the send path, below. */
25
28
  // This is a reference count rather than a Set. A revert is claimed at socket arrival and claimed a
26
29
  // second time when the service starts the cut. More than one socket can also click revert before the
@@ -31,7 +34,7 @@ export class ConversationService {
31
34
  revertOps = new Map();
32
35
  /** The memory store, so a revert can undo what that conversation taught it. Set by `setMemory`. */
33
36
  memory;
34
- constructor(store, runtime, subagents, broadcaster, catalogService, runService, extensionUiService, agentsDir) {
37
+ constructor(store, runtime, subagents, broadcaster, catalogService, runService, extensionUiService, agentsDir, uploadsDir) {
35
38
  this.store = store;
36
39
  this.runtime = runtime;
37
40
  this.subagents = subagents;
@@ -40,10 +43,14 @@ export class ConversationService {
40
43
  this.runService = runService;
41
44
  this.extensionUiService = extensionUiService;
42
45
  this.agentsDir = agentsDir;
46
+ this.uploadsDir = uploadsDir;
43
47
  }
44
48
  setAgentsDir(dir) {
45
49
  this.agentsDir = dir;
46
50
  }
51
+ isWarmSession(conversationId) {
52
+ return this.store.isWarmSession(conversationId);
53
+ }
47
54
  /**
48
55
  * Creates a new conversation in a workspace.
49
56
  *
@@ -513,28 +520,57 @@ export class ConversationService {
513
520
  /**
514
521
  * Forks an existing conversation into a new parallel branch, cloning the Pi session.
515
522
  */
516
- async forkConversation(conversationId) {
523
+ async forkConversation(conversationId, options = {}) {
517
524
  const conversation = this.store.conversation(conversationId);
518
525
  if (!conversation) {
519
526
  return { ok: false, message: "会话不存在" };
520
527
  }
521
- if (conversation.archivedAt) {
528
+ if (conversation.archivedAt && !(conversation.warmSession && options.parentConversationId && !options.warmTitle)) {
522
529
  return { ok: false, message: "已归档的会话无法分叉,请先恢复会话" };
523
530
  }
524
531
  const workspace = this.store.workspaceForConversation(conversationId);
525
532
  if (!workspace) {
526
533
  return { ok: false, message: `会话所属的工作区 ${conversation.workspaceId} 已不存在,拒绝分叉` };
527
534
  }
528
- if (this.runService.isRunning(conversationId)) {
535
+ if (this.runService.isRunning(conversationId) || ["running", "waiting", "awaiting_background"].includes(conversation.status)) {
529
536
  return { ok: false, message: "这个会话还有一轮任务在跑,等它结束(或先停止它)再分叉" };
530
537
  }
531
538
  if (!this.runtime.fork) {
532
539
  return { ok: false, message: "当前运行时没有 Pi 会话,无法分叉(只能复制可见的历史)" };
533
540
  }
541
+ let copiedFile;
542
+ let copiedUploads;
534
543
  try {
544
+ const warmTitle = options.warmTitle?.trim();
545
+ if (options.warmTitle !== undefined && (!warmTitle || warmTitle.length > 100))
546
+ throw new Error("预热会话名称须为 1–100 个字符");
547
+ if (warmTitle && !conversation.messages.some((message) => message.role === "assistant" && !message.delivery)) {
548
+ throw new Error("预热会话需要已有的对话历史");
549
+ }
550
+ const parent = options.parentConversationId;
551
+ if (parent && !conversation.warmSession && parent !== conversation.parentConversationId)
552
+ throw new Error("只能从同一直属上级下的会话分叉");
535
553
  const forkedId = newConversationId();
536
554
  const outcome = await this.runtime.fork({ conversation, cwd: await resolveSessionCwd(workspace.path, conversation.cwd), forkedConversationId: forkedId });
537
- const forked = await this.store.forkConversation(conversationId, forkedId);
555
+ copiedFile = outcome.sessionFile;
556
+ if ((parent || warmTitle) && conversation.messages.some((message) => !message.delivery) && !copiedFile) {
557
+ throw new Error("找不到来源会话的 Pi 记录,无法保留上下文分叉");
558
+ }
559
+ if (this.uploadsDir && (parent || warmTitle)) {
560
+ const images = conversation.messages.filter((message) => !message.delivery).flatMap((message) => message.images ?? []);
561
+ if (images.length) {
562
+ copiedUploads = forkedId;
563
+ await copyForkUploads(this.uploadsDir, conversationId, forkedId, images);
564
+ }
565
+ }
566
+ const latest = this.store.conversation(conversationId);
567
+ if (!latest || latest.updatedAt !== conversation.updatedAt || this.runService.isRunning(conversationId)
568
+ || latest.archivedAt !== conversation.archivedAt || JSON.stringify(latest.messages) !== JSON.stringify(conversation.messages)) {
569
+ throw new Error("来源会话在复制时发生变化,请等当前操作结束后重试");
570
+ }
571
+ const forked = await this.store.forkConversation(conversationId, forkedId, { parentConversationId: parent, warmTitle, piSessionFile: copiedFile });
572
+ copiedFile = undefined;
573
+ copiedUploads = undefined;
538
574
  console.log(`Super Pi: forked conversation ${conversation.id} into ${forked.id}: ` +
539
575
  `${forked.messages.length} message(s) copied in state.json` +
540
576
  `${outcome.sessionFile ? `, ${outcome.entriesCopied} Pi entry/entries copied to ${outcome.sessionFile}` : ", and this conversation had no Pi transcript to copy (no messages)"}.`);
@@ -548,6 +584,10 @@ export class ConversationService {
548
584
  };
549
585
  }
550
586
  catch (error) {
587
+ if (copiedFile)
588
+ await rm(copiedFile, { force: true }).catch(() => { });
589
+ if (copiedUploads && this.uploadsDir)
590
+ await deleteConversationUploads(this.uploadsDir, copiedUploads);
551
591
  const message = error instanceof Error ? error.message : `分叉失败:${String(error)}`;
552
592
  return { ok: false, message };
553
593
  }
@@ -19,8 +19,8 @@ import type { SessionOrchestratorService } from "./session-orchestrator-service.
19
19
  * leader has no subordinates at all, so it is told the second half only - it must not decide
20
20
  * alone either - and is never told about subordinates it does not have.
21
21
  */
22
- export declare const STANDARD_LEADER_PROMPT = "\u4F60\u662F\u76F4\u63A5\u5411 Boss \u8D1F\u8D23\u7684\u9879\u76EE Leader\uFF0C\u8D1F\u8D23\u654F\u6377\u5F00\u53D1\u4E0E\u5C0F\u6B65\u4EA4\u4ED8\u3002\u7528\u6237\u662F\u9876\u5C42\u51B3\u7B56\u8005\uFF0C\u4F60\u81EA\u884C\u5904\u7406\u5185\u90E8\u534F\u8C03\uFF0C\u53EA\u5411\u7528\u6237\u6C47\u603B\u8FDB\u5C55\u3001\u6210\u679C\u4E0E\u5FC5\u8981\u51B3\u7B56\u3002\u5F00\u7BC7\u4E0A\u4E0B\u6587\u5DF2\u7ED9\u51FA\u9879\u76EE\u76EE\u6807\u3001\u6A21\u5F0F\u3001\u5206\u5DE5\u4E0E\u5F53\u524D\u4EFB\u52A1\u6E05\u5355\uFF0C\u4E0D\u5FC5\u5148\u8C03\u7528 project(action=get) \u5C31\u80FD\u76F4\u63A5\u62C6\u89E3\u3001\u6D3E\u6D3B\u6216\u63A8\u8FDB\u3002\u5C0F\u9879\u76EE\u53EA\u62C6\u6700\u5C11\u5FC5\u8981\u4EFB\u52A1\uFF0C\u5927\u9879\u76EE\u6309\u4EA4\u4ED8\u8FB9\u754C\u5206\u5DE5\u3002\u7528 add_task \u767B\u8BB0\u4EFB\u52A1\uFF08\u660E\u786E\u76EE\u6807\u3001\u4EA4\u4ED8\u7269\u3001\u9A8C\u6536\u6807\u51C6\u3001\u4F9D\u8D56\uFF09\uFF1Badd_task / update_task \u65F6\u53EF\u4EE5\u5E26 executorProfile \u4E0E reviewerProfile\uFF08\u652F\u6301\u6307\u5B9A agentId\u3001cwd\u3001model\u3001thinkingLevel\u3001watchdogTimeoutSeconds\uFF09\uFF0C\u6309\u4EFB\u52A1\u6027\u8D28\u5C06\u6267\u884C\u4E0E\u590D\u6838\u59D4\u6D3E\u7ED9\u6700\u5408\u9002\u7684\u5458\u5DE5\uFF0C\u4E0D\u6307\u5B9A\u5219\u7EE7\u627F\u9879\u76EE\u9ED8\u8BA4\uFF1B\u9700\u8981\u7EE7\u7EED\u62C6\u89E3\u7684\u5DE5\u4F5C\u8BBE role=leader\uFF0C\u53F6\u5B50\u6267\u884C\u4EFB\u52A1\u8BBE role=executor\uFF0C\u5B50 Leader \u7528 parentTaskId \u767B\u8BB0\u81EA\u5DF1\u7684\u5B50\u4EFB\u52A1\uFF0Cdispatch \u7ACB\u5373\u542F\u52A8\u6267\u884C\u5B50\u4F1A\u8BDD\uFF1B\u4E0D\u8981\u7528 session_spawn/session_dispatch \u6216 task/workflow \u7ED5\u5F00\u9879\u76EE\u5206\u5DE5\u4E0E\u6C47\u62A5\u7EBF\u3002\u6536\u5230\u4EA4\u4ED8\u540E\u7528 request_review \u542F\u52A8\u72EC\u7ACB\u590D\u6838\u3002\u6D3E\u53D1\u540E\u5B50\u4F1A\u8BDD\u4F1A\u7ACB\u5373\u5F00\u59CB\u6267\u884C\u5E76\u5728\u5B8C\u6210\u540E\u81EA\u52A8\u56DE\u62A5\u7ED9\u4F60\uFF0C\u5C4A\u65F6\u7EE7\u7EED\u6D3E\u53D1 ready \u4EFB\u52A1\u3001\u590D\u6838\u5F85\u9A8C\u6536\u4EFB\u52A1\u6216\u6309 review.summary \u8FD4\u5DE5\uFF1B\u4E0D\u8981\u8F6E\u8BE2\u7B49\u5F85\uFF0C\u4E0D\u8981\u53CD\u590D\u65E0\u8FDB\u5C55\u91CD\u8BD5\uFF0C\u7B49\u5F85\u56DE\u62A5\u65F6\u76F4\u63A5\u7ED3\u675F\u5F53\u524D\u56DE\u590D\u3002\u7528 report \u767B\u8BB0\u5173\u952E\u8FDB\u5C55\u3002\u4F60\u7684\u4E0B\u5C5E\u7684\u5347\u7EA7\u5148\u5230\u4F60\u8FD9\u91CC\uFF1A\u4F60\u5728\u81EA\u5DF1\u8FD9\u4E00\u5C42\u5904\u7406\uFF0C\u80FD\u81EA\u5DF1\u89E3\u51B3\u7684\u81EA\u5DF1\u89E3\u51B3\uFF1B\u53EA\u6709\u786E\u5B9E\u9700\u8981 Boss \u51B3\u7B56\u7684\uFF08\u91CD\u5927\u504F\u5DEE\u3001\u6743\u9650\u6216\u8303\u56F4\u53D8\u66F4\uFF09\u624D\u7528 escalate \u4EA4\u7ED9 Boss\u3002\u4F60\u4E0D\u80FD\u66FF Boss \u505A\u51B3\u5B9A\uFF0C\u4E5F\u4E0D\u8981\u628A\u6CA1\u5904\u7406\u7684\u5347\u7EA7\u538B\u4E0B\u53BB\u4E0D\u7406\u3002\u6240\u6709\u4EFB\u52A1\u9A8C\u6536\u540E\uFF0C\u7528 complete \u63D0\u4EA4\u5E26\u8BC1\u636E\u7684\u6700\u7EC8\u4EA4\u4ED8\u603B\u7ED3\u3002\u4E0A\u4E0B\u6587\u6709\u9650\uFF0C\u660E\u786E\u5047\u8BBE\uFF0C\u4E3B\u52A8\u5BFB\u627E\u53CD\u8BC1\u3002\u53EA\u5728\u672C\u6B21\u89E6\u53D1\u8303\u56F4\u5185\u5DE5\u4F5C\u3002";
23
- export declare const LIGHTWEIGHT_LEADER_PROMPT = "\u4F60\u662F\u76F4\u63A5\u5411 Boss \u8D1F\u8D23\u7684\u9879\u76EE Leader\uFF0C\u8FD9\u662F\u4E00\u4E2A\u8F7B\u91CF\u9879\u76EE\uFF1A\u8FD9\u4E2A\u9879\u76EE\u7531\u4F60\u4EB2\u81EA\u5B8C\u6210\uFF0C\u4E0D\u8981\u62C6\u5B50\u4EFB\u52A1\u3001\u4E0D\u8981\u6D3E\u53D1\u7ED9\u522B\u4EBA\u3001\u4E5F\u6CA1\u6709\u72EC\u7ACB\u590D\u6838\u3002\u5F00\u7BC7\u4E0A\u4E0B\u6587\u5DF2\u7ED9\u51FA\u9879\u76EE\u76EE\u6807\u3001\u6A21\u5F0F\u4E0E\u5F53\u524D\u4EFB\u52A1\u6E05\u5355\uFF0C\u4E0D\u5FC5\u5148\u8C03\u7528 project(action=get) \u5C31\u80FD\u76F4\u63A5\u52A8\u624B\u3002\u7528 add_task \u767B\u8BB0\u4EFB\u52A1\uFF08\u660E\u786E\u76EE\u6807\u3001\u4EA4\u4ED8\u7269\u3001\u9A8C\u6536\u6807\u51C6\u3001\u4F9D\u8D56\uFF09\uFF0C\u4EFB\u52A1\u4E00\u5F8B\u767B\u8BB0\u4E3A\u6267\u884C\u4EFB\u52A1\uFF1Arole=leader \u6216\u5E26 parentTaskId \u90FD\u4F1A\u88AB\u62D2\u7EDD\u3002dispatch \u4F1A\u628A\u4EFB\u52A1\u4EA4\u56DE\u7ED9\u4F60\u81EA\u5DF1\uFF0C\u4F60\u4EB2\u81EA\u505A\u5B8C\uFF1B\u505A\u5B8C\u540E\u8C03\u7528 project(action=submit, projectId, taskId, output, evidenceRefs) \u63D0\u4EA4\u4EA4\u4ED8\uFF0C\u63D0\u4EA4\u5373\u5B8C\u6210\uFF0C\u4E0D\u4F1A\u6709\u4EBA\u56DE\u6765\u590D\u6838\uFF0C\u8BC1\u636E\u5FC5\u987B\u9644\u4E0A\u3002\u4E0D\u8981\u7528 session_spawn/session_dispatch \u6216 task/workflow \u7ED5\u5F00\u9879\u76EE\u804C\u8D23\u4E0E\u6C47\u62A5\u7EBF\u3002\u4E0D\u8981\u8F6E\u8BE2\u7B49\u5F85\uFF0C\u4E0D\u8981\u53CD\u590D\u65E0\u8FDB\u5C55\u91CD\u8BD5\u3002\u7528 report \u6C47\u603B\u5173\u952E\u8FDB\u5C55\u3002\u666E\u901A\u6280\u672F\u51B3\u7B56\u3001\u963B\u585E\u4E0E\u8FD4\u5DE5\u7531\u4F60\u81EA\u884C\u5904\u7406\uFF1B\u53EA\u6709\u786E\u5B9E\u9700\u8981\u7528\u6237\u51B3\u5B9A\u7684\u76EE\u6807\u53D6\u820D\u3001\u6743\u9650\u6216\u5916\u90E8\u8D44\u6E90\u624D\u7528 escalate \u4EA4\u7ED9 Boss\uFF0C\u4E0D\u5F97\u66FF Boss \u51B3\u5B9A\u8FD9\u4E9B\u4E8B\u9879\u3002\u6240\u6709\u4EFB\u52A1\u4EA4\u4ED8\u540E\uFF0C\u7528 complete \u63D0\u4EA4\u5E26\u8BC1\u636E\u7684\u6700\u7EC8\u4EA4\u4ED8\u603B\u7ED3\u3002\u4E0A\u4E0B\u6587\u6709\u9650\uFF0C\u660E\u786E\u5047\u8BBE\uFF0C\u4E3B\u52A8\u5BFB\u627E\u53CD\u8BC1\u3002\u53EA\u5728\u672C\u6B21\u89E6\u53D1\u8303\u56F4\u5185\u5DE5\u4F5C\u3002";
22
+ export declare const STANDARD_LEADER_PROMPT = "\u4F60\u662F\u76F4\u63A5\u5411 Boss \u8D1F\u8D23\u7684\u9879\u76EE Leader\uFF0C\u8D1F\u8D23\u654F\u6377\u5F00\u53D1\u4E0E\u5C0F\u6B65\u4EA4\u4ED8\u3002\u7528\u6237\u662F\u9876\u5C42\u51B3\u7B56\u8005\uFF0C\u4F60\u81EA\u884C\u5904\u7406\u5185\u90E8\u534F\u8C03\uFF0C\u53EA\u5411\u7528\u6237\u6C47\u603B\u8FDB\u5C55\u3001\u6210\u679C\u4E0E\u5FC5\u8981\u51B3\u7B56\u3002\u5F00\u7BC7\u4E0A\u4E0B\u6587\u5DF2\u7ED9\u51FA\u9879\u76EE\u76EE\u6807\u3001\u6A21\u5F0F\u3001\u5206\u5DE5\u4E0E\u5F53\u524D\u4EFB\u52A1\u6E05\u5355\uFF0C\u4E0D\u5FC5\u5148\u8C03\u7528 project(action=get) \u5C31\u80FD\u76F4\u63A5\u62C6\u89E3\u3001\u6D3E\u6D3B\u6216\u63A8\u8FDB\u3002\u5C0F\u9879\u76EE\u53EA\u62C6\u6700\u5C11\u5FC5\u8981\u4EFB\u52A1\uFF0C\u5927\u9879\u76EE\u6309\u4EA4\u4ED8\u8FB9\u754C\u5206\u5DE5\u3002\u7528 add_task \u767B\u8BB0\u4EFB\u52A1\uFF08\u660E\u786E\u76EE\u6807\u3001\u4EA4\u4ED8\u7269\u3001\u9A8C\u6536\u6807\u51C6\u3001\u4F9D\u8D56\uFF09\uFF1Badd_task / update_task \u65F6\u53EF\u4EE5\u5E26 executorProfile \u4E0E reviewerProfile\uFF08\u652F\u6301\u6307\u5B9A agentId\u3001cwd\u3001model\u3001thinkingLevel\u3001watchdogTimeoutSeconds\uFF09\uFF0C\u6309\u4EFB\u52A1\u6027\u8D28\u5C06\u6267\u884C\u4E0E\u590D\u6838\u59D4\u6D3E\u7ED9\u6700\u5408\u9002\u7684\u5458\u5DE5\uFF0C\u4E0D\u6307\u5B9A\u5219\u7EE7\u627F\u9879\u76EE\u9ED8\u8BA4\uFF1B\u9700\u8981\u7EE7\u7EED\u62C6\u89E3\u7684\u5DE5\u4F5C\u8BBE role=leader\uFF0C\u53F6\u5B50\u6267\u884C\u4EFB\u52A1\u8BBE role=executor\uFF0C\u5B50 Leader \u7528 parentTaskId \u767B\u8BB0\u81EA\u5DF1\u7684\u5B50\u4EFB\u52A1\uFF0Cdispatch \u7ACB\u5373\u542F\u52A8\u6267\u884C\u5B50\u4F1A\u8BDD\uFF1B\u4E0D\u8981\u7528 session_spawn/session_dispatch \u6216 task/workflow \u7ED5\u5F00\u9879\u76EE\u5206\u5DE5\u4E0E\u6C47\u62A5\u7EBF\u3002\u6536\u5230\u4EA4\u4ED8\u540E\u7528 request_review \u542F\u52A8\u72EC\u7ACB\u590D\u6838\u3002\u6D3E\u53D1\u540E\u5B50\u4F1A\u8BDD\u4F1A\u7ACB\u5373\u5F00\u59CB\u6267\u884C\u5E76\u5728\u5B8C\u6210\u540E\u81EA\u52A8\u56DE\u62A5\u7ED9\u4F60\uFF0C\u5C4A\u65F6\u7EE7\u7EED\u6D3E\u53D1 ready \u4EFB\u52A1\u3001\u590D\u6838\u5F85\u9A8C\u6536\u4EFB\u52A1\u6216\u6309 review.summary \u8FD4\u5DE5\uFF1B\u4E0D\u8981\u8F6E\u8BE2\u7B49\u5F85\uFF0C\u4E0D\u8981\u53CD\u590D\u65E0\u8FDB\u5C55\u91CD\u8BD5\uFF0C\u7B49\u5F85\u56DE\u62A5\u65F6\u76F4\u63A5\u7ED3\u675F\u5F53\u524D\u56DE\u590D\u3002\u7528 report \u767B\u8BB0\u5173\u952E\u8FDB\u5C55\u3002\u4F60\u7684\u4E0B\u5C5E\u7684\u5347\u7EA7\u5148\u5230\u4F60\u8FD9\u91CC\uFF1A\u4F60\u5728\u81EA\u5DF1\u8FD9\u4E00\u5C42\u5904\u7406\uFF0C\u80FD\u81EA\u5DF1\u89E3\u51B3\u7684\u81EA\u5DF1\u89E3\u51B3\uFF1B\u53EA\u6709\u786E\u5B9E\u9700\u8981 Boss \u51B3\u7B56\u7684\uFF08\u91CD\u5927\u504F\u5DEE\u3001\u6743\u9650\u6216\u8303\u56F4\u53D8\u66F4\uFF09\u624D\u7528 escalate \u4EA4\u7ED9 Boss\u3002\u4F60\u4E0D\u80FD\u66FF Boss \u505A\u51B3\u5B9A\uFF0C\u4E5F\u4E0D\u8981\u628A\u6CA1\u5904\u7406\u7684\u5347\u7EA7\u538B\u4E0B\u53BB\u4E0D\u7406\u3002\u6240\u6709\u4EFB\u52A1\u9A8C\u6536\u540E\uFF0C\u7528 deliver \u8BB0\u5F55\u5E26\u8BC1\u636E\u7684\u9636\u6BB5\u4EA4\u4ED8\uFF0C\u540E\u7EED\u53EF\u7EE7\u7EED\u6D3E\u53D1\u3002\u4E0A\u4E0B\u6587\u6709\u9650\uFF0C\u660E\u786E\u5047\u8BBE\uFF0C\u4E3B\u52A8\u5BFB\u627E\u53CD\u8BC1\u3002\u53EA\u5728\u672C\u6B21\u89E6\u53D1\u8303\u56F4\u5185\u5DE5\u4F5C\u3002";
23
+ export declare const LIGHTWEIGHT_LEADER_PROMPT = "\u4F60\u662F\u76F4\u63A5\u5411 Boss \u8D1F\u8D23\u7684\u9879\u76EE Leader\uFF0C\u8FD9\u662F\u4E00\u4E2A\u8F7B\u91CF\u9879\u76EE\uFF1A\u8FD9\u4E2A\u9879\u76EE\u7531\u4F60\u4EB2\u81EA\u5B8C\u6210\uFF0C\u4E0D\u8981\u62C6\u5B50\u4EFB\u52A1\u3001\u4E0D\u8981\u6D3E\u53D1\u7ED9\u522B\u4EBA\u3001\u4E5F\u6CA1\u6709\u72EC\u7ACB\u590D\u6838\u3002\u5F00\u7BC7\u4E0A\u4E0B\u6587\u5DF2\u7ED9\u51FA\u9879\u76EE\u76EE\u6807\u3001\u6A21\u5F0F\u4E0E\u5F53\u524D\u4EFB\u52A1\u6E05\u5355\uFF0C\u4E0D\u5FC5\u5148\u8C03\u7528 project(action=get) \u5C31\u80FD\u76F4\u63A5\u52A8\u624B\u3002\u7528 add_task \u767B\u8BB0\u4EFB\u52A1\uFF08\u660E\u786E\u76EE\u6807\u3001\u4EA4\u4ED8\u7269\u3001\u9A8C\u6536\u6807\u51C6\u3001\u4F9D\u8D56\uFF09\uFF0C\u4EFB\u52A1\u4E00\u5F8B\u767B\u8BB0\u4E3A\u6267\u884C\u4EFB\u52A1\uFF1Arole=leader \u6216\u5E26 parentTaskId \u90FD\u4F1A\u88AB\u62D2\u7EDD\u3002dispatch \u4F1A\u628A\u4EFB\u52A1\u4EA4\u56DE\u7ED9\u4F60\u81EA\u5DF1\uFF0C\u4F60\u4EB2\u81EA\u505A\u5B8C\uFF1B\u505A\u5B8C\u540E\u8C03\u7528 project(action=submit, projectId, taskId, output, evidenceRefs) \u63D0\u4EA4\u4EA4\u4ED8\uFF0C\u63D0\u4EA4\u5373\u5B8C\u6210\uFF0C\u4E0D\u4F1A\u6709\u4EBA\u56DE\u6765\u590D\u6838\uFF0C\u8BC1\u636E\u5FC5\u987B\u9644\u4E0A\u3002\u4E0D\u8981\u7528 session_spawn/session_dispatch \u6216 task/workflow \u7ED5\u5F00\u9879\u76EE\u804C\u8D23\u4E0E\u6C47\u62A5\u7EBF\u3002\u4E0D\u8981\u8F6E\u8BE2\u7B49\u5F85\uFF0C\u4E0D\u8981\u53CD\u590D\u65E0\u8FDB\u5C55\u91CD\u8BD5\u3002\u7528 report \u6C47\u603B\u5173\u952E\u8FDB\u5C55\u3002\u666E\u901A\u6280\u672F\u51B3\u7B56\u3001\u963B\u585E\u4E0E\u8FD4\u5DE5\u7531\u4F60\u81EA\u884C\u5904\u7406\uFF1B\u53EA\u6709\u786E\u5B9E\u9700\u8981\u7528\u6237\u51B3\u5B9A\u7684\u76EE\u6807\u53D6\u820D\u3001\u6743\u9650\u6216\u5916\u90E8\u8D44\u6E90\u624D\u7528 escalate \u4EA4\u7ED9 Boss\uFF0C\u4E0D\u5F97\u66FF Boss \u51B3\u5B9A\u8FD9\u4E9B\u4E8B\u9879\u3002\u6240\u6709\u4EFB\u52A1\u4EA4\u4ED8\u540E\uFF0C\u7528 deliver \u8BB0\u5F55\u5E26\u8BC1\u636E\u7684\u9636\u6BB5\u4EA4\u4ED8\uFF0C\u540E\u7EED\u53EF\u7EE7\u7EED\u6D3E\u53D1\u3002\u4E0A\u4E0B\u6587\u6709\u9650\uFF0C\u660E\u786E\u5047\u8BBE\uFF0C\u4E3B\u52A8\u5BFB\u627E\u53CD\u8BC1\u3002\u53EA\u5728\u672C\u6B21\u89E6\u53D1\u8303\u56F4\u5185\u5DE5\u4F5C\u3002";
24
24
  export declare const profile: (value: unknown, label: string) => SessionProfile | undefined;
25
25
  export declare const mergeProfile: (taskProfile?: SessionProfile, projectDefault?: SessionProfile) => SessionProfile | undefined;
26
26
  /**
@@ -312,7 +312,10 @@ export declare class ProjectService {
312
312
  private context;
313
313
  start(id: string, workspaceId: string, actor?: string): Promise<Project>;
314
314
  addTask(id: string, input: AddTaskInput, workspaceId?: string, actor?: string): Promise<ProjectTask>;
315
- dispatchTask(id: string, taskId: string, workspaceId: string, actor?: string): Promise<ProjectTask>;
315
+ dispatchTask(id: string, taskId: string, workspaceId: string, actor?: string, sourceContext?: {
316
+ id: string;
317
+ warm: boolean;
318
+ }): Promise<ProjectTask>;
316
319
  submit(id: string, taskId: string, input: {
317
320
  output?: string;
318
321
  evidenceRefs?: string[];
@@ -371,7 +374,8 @@ export declare class ProjectService {
371
374
  * next reader has to guess about.
372
375
  */
373
376
  resolveEscalation(id: string, escalationId: string, decision: string, status: "resolved" | "dismissed" | "returned", workspaceId?: string, actor?: string): Promise<ProjectEscalation>;
374
- complete(id: string, summary: string, evidenceRefs: unknown, workspaceId: string, actor?: string): Promise<Project>;
377
+ private deliveryTasks;
378
+ deliver(id: string, summary: string, evidenceRefs: unknown, workspaceId: string, actor?: string): Promise<Project>;
375
379
  /**
376
380
  * The tasks an initiator hands over with create. A dependency names the TITLE of another task in
377
381
  * the same batch, because the batch carries no task IDs yet - the service assigns them while it
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { deriveProjectActivity, deriveTaskActivity } from "../../shared/project-presentation.js";
3
+ import { deliveryCoversTasks, latestProjectDelivery } from "../../shared/project-overview.js";
3
4
  import { buildTeamHandoff, discoverTeamFiles, parseTeamContext, pathsOverlap, publishTeamContext, teamPaths } from "../team-context.js";
4
5
  import { deriveReportingState, deriveSessionState, sessionStateWord, } from "../../shared/session-reporting.js";
5
6
  const stamp = () => new Date().toISOString();
@@ -21,8 +22,8 @@ const stamp = () => new Date().toISOString();
21
22
  * leader has no subordinates at all, so it is told the second half only - it must not decide
22
23
  * alone either - and is never told about subordinates it does not have.
23
24
  */
24
- export const STANDARD_LEADER_PROMPT = "你是直接向 Boss 负责的项目 Leader,负责敏捷开发与小步交付。用户是顶层决策者,你自行处理内部协调,只向用户汇总进展、成果与必要决策。开篇上下文已给出项目目标、模式、分工与当前任务清单,不必先调用 project(action=get) 就能直接拆解、派活或推进。小项目只拆最少必要任务,大项目按交付边界分工。用 add_task 登记任务(明确目标、交付物、验收标准、依赖);add_task / update_task 时可以带 executorProfile 与 reviewerProfile(支持指定 agentId、cwd、model、thinkingLevel、watchdogTimeoutSeconds),按任务性质将执行与复核委派给最合适的员工,不指定则继承项目默认;需要继续拆解的工作设 role=leader,叶子执行任务设 role=executor,子 Leader 用 parentTaskId 登记自己的子任务,dispatch 立即启动执行子会话;不要用 session_spawn/session_dispatch 或 task/workflow 绕开项目分工与汇报线。收到交付后用 request_review 启动独立复核。派发后子会话会立即开始执行并在完成后自动回报给你,届时继续派发 ready 任务、复核待验收任务或按 review.summary 返工;不要轮询等待,不要反复无进展重试,等待回报时直接结束当前回复。用 report 登记关键进展。你的下属的升级先到你这里:你在自己这一层处理,能自己解决的自己解决;只有确实需要 Boss 决策的(重大偏差、权限或范围变更)才用 escalate 交给 Boss。你不能替 Boss 做决定,也不要把没处理的升级压下去不理。所有任务验收后,用 complete 提交带证据的最终交付总结。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
25
- export const LIGHTWEIGHT_LEADER_PROMPT = "你是直接向 Boss 负责的项目 Leader,这是一个轻量项目:这个项目由你亲自完成,不要拆子任务、不要派发给别人、也没有独立复核。开篇上下文已给出项目目标、模式与当前任务清单,不必先调用 project(action=get) 就能直接动手。用 add_task 登记任务(明确目标、交付物、验收标准、依赖),任务一律登记为执行任务:role=leader 或带 parentTaskId 都会被拒绝。dispatch 会把任务交回给你自己,你亲自做完;做完后调用 project(action=submit, projectId, taskId, output, evidenceRefs) 提交交付,提交即完成,不会有人回来复核,证据必须附上。不要用 session_spawn/session_dispatch 或 task/workflow 绕开项目职责与汇报线。不要轮询等待,不要反复无进展重试。用 report 汇总关键进展。普通技术决策、阻塞与返工由你自行处理;只有确实需要用户决定的目标取舍、权限或外部资源才用 escalate 交给 Boss,不得替 Boss 决定这些事项。所有任务交付后,用 complete 提交带证据的最终交付总结。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
25
+ export const STANDARD_LEADER_PROMPT = "你是直接向 Boss 负责的项目 Leader,负责敏捷开发与小步交付。用户是顶层决策者,你自行处理内部协调,只向用户汇总进展、成果与必要决策。开篇上下文已给出项目目标、模式、分工与当前任务清单,不必先调用 project(action=get) 就能直接拆解、派活或推进。小项目只拆最少必要任务,大项目按交付边界分工。用 add_task 登记任务(明确目标、交付物、验收标准、依赖);add_task / update_task 时可以带 executorProfile 与 reviewerProfile(支持指定 agentId、cwd、model、thinkingLevel、watchdogTimeoutSeconds),按任务性质将执行与复核委派给最合适的员工,不指定则继承项目默认;需要继续拆解的工作设 role=leader,叶子执行任务设 role=executor,子 Leader 用 parentTaskId 登记自己的子任务,dispatch 立即启动执行子会话;不要用 session_spawn/session_dispatch 或 task/workflow 绕开项目分工与汇报线。收到交付后用 request_review 启动独立复核。派发后子会话会立即开始执行并在完成后自动回报给你,届时继续派发 ready 任务、复核待验收任务或按 review.summary 返工;不要轮询等待,不要反复无进展重试,等待回报时直接结束当前回复。用 report 登记关键进展。你的下属的升级先到你这里:你在自己这一层处理,能自己解决的自己解决;只有确实需要 Boss 决策的(重大偏差、权限或范围变更)才用 escalate 交给 Boss。你不能替 Boss 做决定,也不要把没处理的升级压下去不理。所有任务验收后,用 deliver 记录带证据的阶段交付,后续可继续派发。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
26
+ export const LIGHTWEIGHT_LEADER_PROMPT = "你是直接向 Boss 负责的项目 Leader,这是一个轻量项目:这个项目由你亲自完成,不要拆子任务、不要派发给别人、也没有独立复核。开篇上下文已给出项目目标、模式与当前任务清单,不必先调用 project(action=get) 就能直接动手。用 add_task 登记任务(明确目标、交付物、验收标准、依赖),任务一律登记为执行任务:role=leader 或带 parentTaskId 都会被拒绝。dispatch 会把任务交回给你自己,你亲自做完;做完后调用 project(action=submit, projectId, taskId, output, evidenceRefs) 提交交付,提交即完成,不会有人回来复核,证据必须附上。不要用 session_spawn/session_dispatch 或 task/workflow 绕开项目职责与汇报线。不要轮询等待,不要反复无进展重试。用 report 汇总关键进展。普通技术决策、阻塞与返工由你自行处理;只有确实需要用户决定的目标取舍、权限或外部资源才用 escalate 交给 Boss,不得替 Boss 决定这些事项。所有任务交付后,用 deliver 记录带证据的阶段交付,后续可继续派发。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
26
27
  const text = (value, label) => {
27
28
  if (typeof value !== "string" || !value.trim())
28
29
  throw new Error(`${label} 不能为空`);
@@ -120,7 +121,7 @@ export const mergeProfile = (taskProfile, projectDefault) => {
120
121
  }
121
122
  return hasKey ? merged : undefined;
122
123
  };
123
- const closed = (p) => ["completed", "cancelled", "failed"].includes(p.status);
124
+ const closed = (p) => ["cancelled", "failed"].includes(p.status);
124
125
  const busy = (status) => ["running", "waiting", "awaiting_background"].includes(status ?? "");
125
126
  const dependenciesComplete = (p, t) => t.dependencies.every((id) => p.tasks.find((candidate) => candidate.id === id)?.status === "completed");
126
127
  // Usage accounting uses billing-equivalent tokens so the panel and report match provider bills,
@@ -162,7 +163,7 @@ const DECISION_CELL_LIMIT = 40;
162
163
  // state and every role is written the way a person would say it out loud.
163
164
  const PROJECT_STATUS_TEXT = {
164
165
  planning: "草稿", awaiting_start: "待启动", active: "进行中", blocked: "已阻塞", awaiting_approval: "等待审批",
165
- awaiting_review: "等待复核", completed: "已完成", cancelled: "已取消", failed: "失败",
166
+ awaiting_review: "等待复核", cancelled: "已取消", failed: "失败",
166
167
  };
167
168
  const TASK_STATUS_TEXT = {
168
169
  pending: "等待依赖", ready: "待派发", in_progress: "执行阶段", interrupted: "已中断", blocked: "已阻塞",
@@ -172,7 +173,7 @@ const EVENT_TEXT = {
172
173
  created: "创建项目", started: "启动执行", task_created: "登记任务", dispatched: "派发执行",
173
174
  submitted: "提交交付", reviewed: "复核", review_requested: "启动复核", task_updated: "任务更新", status: "状态变更",
174
175
  budget: "预算变更", report: "进展汇报", escalated: "例外升级", decision: "决定",
175
- completed: "项目完成", ready: "依赖就绪", unreachable: "转述对象不可达",
176
+ delivery: "阶段交付", completed: "历史交付", ready: "依赖就绪", unreachable: "转述对象不可达",
176
177
  // THE REPORT IS READ BY PEOPLE. Every other line of the timeline is printed in Chinese, so the
177
178
  // one warning that says "your leader landed on the workspace default agent" must not be the
178
179
  // only line a reader meets as an English identifier.
@@ -365,23 +366,30 @@ export class ProjectService {
365
366
  this.event(p, "context_published", `共享上下文更新到第 ${p.contextRevision} 版`, undefined, actor);
366
367
  }
367
368
  async shareContext(id, value, workspaceId, actor) {
368
- return this.change(id, workspaceId, p => { this.live(p); this.publishContext(p, value, actor); return { revision: p.contextRevision ?? 0, entries: p.sharedContext ?? [] }; });
369
+ return this.change(id, workspaceId, p => {
370
+ this.live(p);
371
+ this.publishContext(p, value, actor);
372
+ return { revision: p.contextRevision ?? 0, entries: p.sharedContext ?? [] };
373
+ });
369
374
  }
370
375
  async messageTask(id, taskId, content, workspaceId, actor, targetConversationId, deliveryMode = "queue") {
371
376
  return this.change(id, workspaceId, async (p) => {
372
377
  this.live(p);
373
378
  const task = this.task(p, taskId);
374
379
  this.manager(p, task, actor);
375
- if (!["in_progress", "awaiting_review", "blocked"].includes(task.status))
376
- throw new Error("补充指令只用于执行、复核或阻塞中的任务;新工作请登记任务,返工请重新派发原任务");
380
+ if (!["in_progress", "awaiting_review", "blocked", "completed"].includes(task.status))
381
+ throw new Error("补充指令只能发送到已有执行或复核记录的任务;新的交付请登记任务");
377
382
  if (!["queue", "steer"].includes(deliveryMode))
378
383
  throw new Error("deliveryMode 只能是 queue 或 steer");
379
384
  const target = targetConversationId ?? task.ownerConversationId;
380
385
  if (!target || ![task.ownerConversationId, task.reviewerConversationId].includes(target))
381
386
  throw new Error("补充指令只能发送给本任务已有的执行或复核会话");
387
+ const session = this.store.conversation(target);
388
+ if (!session || session.archivedAt || session.workspaceId !== workspaceId)
389
+ throw new Error("目标会话已归档或不存在");
382
390
  if (target === task.ownerConversationId)
383
391
  this.assertWriteScope(p, task);
384
- if (!busy(this.store.conversation(target)?.status))
392
+ if (!busy(session.status))
385
393
  this.admission(p);
386
394
  const result = await this.dispatchContext(target, text(content, "补充指令"), { wait: false, mode: deliveryMode }, task.id);
387
395
  this.event(p, "task_message", `向「${task.title}」发送补充指令(${deliveryMode === "steer" ? "下一工具边界" : "排队"}),附带当前共享上下文`, task.id, actor);
@@ -431,14 +439,17 @@ export class ProjectService {
431
439
  hints.push({ action: "message", taskId: task.id, reason: task.status === "blocked" ? "先排查并协调阻塞,给原执行者明确下一步;仅确需用户提供取舍或权限时才上收" : "本轮已结束但尚未交付,继续原会话或要求提交,不等待用户安排" });
432
440
  }
433
441
  }
434
- if (actor === p.ownerConversationId && p.tasks.length && this.requiredComplete(p) && !p.escalations.some(item => item.status === "open"))
435
- hints.push({ action: "complete", reason: "必需任务已验收,汇总成果与证据完成项目,不让用户替你收尾" });
442
+ const required = this.deliveryTasks(p);
443
+ if (actor === p.ownerConversationId && required.length && required.every(task => this.taskAccepted(task))
444
+ && !deliveryCoversTasks(latestProjectDelivery(p), required) && !p.escalations.some(item => item.status === "open")) {
445
+ hints.push({ action: "deliver", reason: "本阶段必需任务已验收,汇总成果与证据后继续安排工作" });
446
+ }
436
447
  return hints;
437
448
  }
438
449
  assertWriteScope(p, task) {
439
450
  if (task.readOnly || !task.ownedPaths?.length)
440
451
  return;
441
- const conflicts = p.tasks.filter(other => other.id !== task.id && !other.readOnly && other.status === "in_progress"
452
+ const conflicts = p.tasks.filter(other => other.id !== task.id && !other.readOnly
442
453
  && other.ownerConversationId && busy(this.store.conversation(other.ownerConversationId)?.status)
443
454
  && other.ownedPaths?.some(path => task.ownedPaths.some(own => pathsOverlap(path, own))));
444
455
  if (conflicts.length)
@@ -1069,9 +1080,6 @@ export class ProjectService {
1069
1080
  headline(p, actor, resources) {
1070
1081
  const total = p.tasks.length;
1071
1082
  const completed = p.tasks.filter((t) => t.status === "completed").length;
1072
- if (p.status === "completed") {
1073
- return total > 0 ? `项目已完成(${completed}/${total} 任务已验收)` : "项目已完成";
1074
- }
1075
1083
  if (p.status === "cancelled")
1076
1084
  return "项目已取消";
1077
1085
  if (p.status === "failed")
@@ -1229,7 +1237,7 @@ export class ProjectService {
1229
1237
  lines.push(`- 创建时间:${moment(p.createdAt)}`);
1230
1238
  lines.push(`- 最后更新时间:${moment(p.updatedAt)}`);
1231
1239
  if (p.closedAt)
1232
- lines.push(`- 完成时间:${moment(p.closedAt)}`);
1240
+ lines.push(`- 停止时间:${moment(p.closedAt)}`);
1233
1241
  const usage = this.resources(p);
1234
1242
  lines.push(`- 已用等效 Token:${usage.tokens}(口径:输入 + 输出 + 缓存写入×${CACHE_WRITE_WEIGHT} + 缓存读取×${CACHE_READ_WEIGHT},取整;含项目内的一次性调用(subagent))`);
1235
1243
  lines.push(`- 原始口径(1:1):${usage.rawTokens}(输入 ${usage.usage?.input ?? 0} + 输出 ${usage.usage?.output ?? 0} + 缓存写入 ${usage.usage?.cacheWrite ?? 0} + 缓存读取 ${usage.usage?.cacheRead ?? 0})`);
@@ -1527,7 +1535,7 @@ export class ProjectService {
1527
1535
  return ProjectService.taskView(t, p);
1528
1536
  });
1529
1537
  }
1530
- async dispatchTask(id, taskId, workspaceId, actor) {
1538
+ async dispatchTask(id, taskId, workspaceId, actor, sourceContext) {
1531
1539
  return this.change(id, workspaceId, async (p) => {
1532
1540
  const t = this.task(p, taskId);
1533
1541
  const manager = this.manager(p, t, actor);
@@ -1555,6 +1563,22 @@ export class ProjectService {
1555
1563
  if (t.parentTaskId && this.task(p, t.parentTaskId).status !== "in_progress")
1556
1564
  throw new Error("父任务未处于执行中");
1557
1565
  const effective = mergeProfile(t.executorProfile, p.defaultExecutorProfile);
1566
+ if (sourceContext) {
1567
+ if (lightweight(p) || t.ownerConversationId || wasInterrupted || !manager)
1568
+ throw new Error("分叉只用于标准项目中首次派发的任务");
1569
+ const source = this.store.conversation(sourceContext.id);
1570
+ if (sourceContext.warm) {
1571
+ if (!source?.warmSession || source.workspaceId !== workspaceId)
1572
+ throw new Error("预热会话不在此工作区或已移除");
1573
+ }
1574
+ else if (!source || source.warmSession || source.parentConversationId !== manager || source.workspaceId !== workspaceId
1575
+ || !p.tasks.some((task) => task.ownerConversationId === source.id)) {
1576
+ throw new Error("分叉来源必须是本项目下由你管理的执行会话");
1577
+ }
1578
+ else if (source.archivedAt || busy(source.status)) {
1579
+ throw new Error("请等待来源会话结束当前一轮后再分叉");
1580
+ }
1581
+ }
1558
1582
  if (!t.ownerConversationId) {
1559
1583
  if (lightweight(p)) {
1560
1584
  // THE LEADER IS THE WORKER. A lightweight project spawns no worker session, so the task's
@@ -1567,6 +1591,7 @@ export class ProjectService {
1567
1591
  else {
1568
1592
  t.ownerConversationId = (await this.orchestrator.spawn({
1569
1593
  workspaceId, parentConversationId: manager, title: `${t.role === "leader" ? "Leader" : "执行"} · ${t.title}`, task: t.objective, initialPrompt: "",
1594
+ ...(sourceContext ? { forkFromConversationId: sourceContext.id } : {}),
1570
1595
  ...(effective?.agentId ? { agentId: effective.agentId } : {}),
1571
1596
  ...(effective?.cwd !== undefined ? { cwd: effective.cwd } : {}),
1572
1597
  ...(effective?.model ? { model: effective.model } : {}),
@@ -1599,7 +1624,7 @@ export class ProjectService {
1599
1624
  delete t.blockedReason;
1600
1625
  delete t.blockedReportedByConversationId;
1601
1626
  delete t.interruptedReason;
1602
- this.captureHandoff(p, t, manager);
1627
+ this.captureHandoff(p, t, sourceContext?.id ?? manager);
1603
1628
  this.event(p, "dispatched", `派发执行:${t.title};交接 ${t.handoff?.entries.length ?? 0} 条共享记录`, t.id, actor);
1604
1629
  this.reconcile(p);
1605
1630
  await this.store.setProject(p);
@@ -1607,7 +1632,8 @@ export class ProjectService {
1607
1632
  /* THE LIGHTWEIGHT TASK SAYS WHAT IS DIFFERENT, because the difference is the point: there is
1608
1633
  no reviewer coming back, so the evidence that the reviewer would have demanded is the only
1609
1634
  thing that stands behind the delivery. */
1610
- const modeNote = lightweight(p) ? "本项目是轻量项目:你就是唯一的执行会话,不会有独立复核人回来,完成后调用 project(action=submit, …) 提交即完成,交付证据必须附上。" : "";
1635
+ const modeNote = lightweight(p) ? "本项目是轻量项目:你就是唯一的执行会话,不会有独立复核人回来,完成后调用 project(action=submit, …) 提交即完成,交付证据必须附上。"
1636
+ : sourceContext ? "\n复用已复制的历史背景,立即推进本条消息指定的新任务;历史里的任务、成员身份及验收均属于原会话。\n" : "";
1611
1637
  /* THE TASK THAT WAS INTERRUPTED IS TOLD WHAT HAPPENED. A worker that comes back to a task
1612
1638
  it was working on has no idea whether the work it half did is still wanted, and the
1613
1639
  default - carry on as if nothing happened - is the wrong one after a crash. */
@@ -1849,7 +1875,7 @@ export class ProjectService {
1849
1875
  const result = await this.change(id, workspaceId, (p) => {
1850
1876
  this.live(p);
1851
1877
  if (!["active", "cancelled", "failed"].includes(status))
1852
- throw new Error("项目完成必须提交最终交付,其他状态由任务和例外推导");
1878
+ throw new Error("阶段交付请使用 deliver,项目状态由任务和例外推导");
1853
1879
  if (status === "active" && p.escalations.some((e) => e.status === "open"))
1854
1880
  throw new Error("请先处理未解决的例外");
1855
1881
  /* A PROJECT WITH NO LEADER SESSION HAS NOTHING RUNNING IN IT. The status is derived from
@@ -2129,24 +2155,27 @@ export class ProjectService {
2129
2155
  }
2130
2156
  return result;
2131
2157
  }
2132
- async complete(id, summary, evidenceRefs, workspaceId, actor) {
2158
+ deliveryTasks(p) {
2159
+ return p.tasks.filter((task) => task.status !== "cancelled" || !task.blockedReason);
2160
+ }
2161
+ async deliver(id, summary, evidenceRefs, workspaceId, actor) {
2133
2162
  return this.change(id, workspaceId, (p) => {
2134
2163
  this.live(p);
2135
2164
  this.leader(p, actor);
2136
- const required = p.tasks.filter((t) => t.status !== "cancelled" || !t.blockedReason);
2165
+ const required = this.deliveryTasks(p);
2137
2166
  if (!required.length || required.some((t) => !this.taskAccepted(t))) {
2138
- throw new Error(lightweight(p) ? "所有任务必须完成交付后才能完成项目" : "所有任务必须经独立复核验收后才能完成项目");
2167
+ throw new Error(lightweight(p) ? "所有必需任务须先完成交付" : "所有必需任务须先经独立复核验收");
2139
2168
  }
2140
2169
  if (p.escalations.some((e) => e.status === "open"))
2141
2170
  throw new Error("尚有未处理例外");
2142
- const evidence = strings(evidenceRefs, "最终交付证据");
2171
+ const evidence = strings(evidenceRefs, "阶段交付证据");
2143
2172
  if (!evidence.length)
2144
- throw new Error("最终交付必须附证据");
2145
- const progress = text(summary, "最终交付总结");
2146
- p.reports.push({ id: randomUUID(), projectId: id, kind: "delivery", progress, evidenceRefs: evidence, authorConversationId: actor, createdAt: stamp() });
2147
- p.status = "completed";
2148
- p.closedAt = stamp();
2149
- this.event(p, "completed", progress, undefined, actor);
2173
+ throw new Error("阶段交付必须附证据");
2174
+ const progress = text(summary, "阶段交付总结");
2175
+ p.reports.push({ id: randomUUID(), projectId: id, kind: "delivery", progress, evidenceRefs: evidence,
2176
+ acceptedTaskIds: required.map(task => task.id), authorConversationId: actor ?? p.ownerConversationId, createdAt: stamp() });
2177
+ this.event(p, "delivery", progress, undefined, actor);
2178
+ this.reconcile(p);
2150
2179
  return p;
2151
2180
  });
2152
2181
  }
@@ -2289,7 +2318,11 @@ export class ProjectService {
2289
2318
  throw new Error("已经在项目里的会话不能另起项目:请专注当前项目分工。");
2290
2319
  if (conversation.parentConversationId)
2291
2320
  throw new Error("只有主对话可以创建项目:派发出来的会话不能另起项目。");
2292
- const running = this.store.projects().filter((p) => p.initiatorConversationId === actor && !closed(p));
2321
+ const running = this.store.projects().filter((p) => p.initiatorConversationId === actor && !closed(p)
2322
+ && (!deliveryCoversTasks(latestProjectDelivery(p), this.deliveryTasks(p))
2323
+ || this.deliveryTasks(p).some(task => !this.taskAccepted(task))
2324
+ || p.escalations.some(item => item.status === "open")
2325
+ || this.activitySessions(p).some(session => busy(session.status))));
2293
2326
  if (running.length >= 3)
2294
2327
  throw new Error("你同时进行的项目超过上限(3 个),先完成或停止一个再新建。");
2295
2328
  // ONLY TWO FIELDS ARE ASKED FOR, AND SAYING SO IS PART OF THE CONTRACT. The schema marks
@@ -2326,6 +2359,7 @@ export class ProjectService {
2326
2359
  this.member(rawProject, actor);
2327
2360
  switch (body.action) {
2328
2361
  case "get": return this.get(id, workspaceId, actor);
2362
+ case "list_warm_sessions": return { sessions: this.store.listWarmSessions(workspaceId) };
2329
2363
  case "export": return this.exportReport(id, workspaceId);
2330
2364
  case "start": return this.start(id, workspaceId, actor);
2331
2365
  case "add_task": return this.addTask(id, body, workspaceId, actor);
@@ -2337,20 +2371,27 @@ export class ProjectService {
2337
2371
  return this.messageTask(id, text(body.taskId, "taskId"), text(body.content, "content"), workspaceId, actor, typeof body.targetConversationId === "string" ? body.targetConversationId : undefined, body.deliveryMode);
2338
2372
  }
2339
2373
  case "dispatch": {
2374
+ const forkFromConversationId = body.forkFromConversationId === undefined
2375
+ ? undefined : text(body.forkFromConversationId, "forkFromConversationId");
2376
+ const warmSessionId = body.warmSessionId === undefined ? undefined : text(body.warmSessionId, "warmSessionId");
2377
+ if (forkFromConversationId && warmSessionId)
2378
+ throw new Error("请选择一个会话上下文来源");
2379
+ const sourceContext = warmSessionId ? { id: warmSessionId, warm: true }
2380
+ : forkFromConversationId ? { id: forkFromConversationId, warm: false } : undefined;
2340
2381
  if (body.sharedContext !== undefined)
2341
2382
  await this.shareContext(id, body.sharedContext, workspaceId, actor);
2342
2383
  if (body.taskIds === undefined) {
2343
2384
  const taskId = text(body.taskId, "taskId");
2344
2385
  if (body.handoffNote !== undefined)
2345
2386
  await this.updateTask(id, taskId, { workspaceId, handoffNote: body.handoffNote }, actor);
2346
- return this.dispatchReceipt(await this.dispatchTask(id, taskId, workspaceId, actor));
2387
+ return this.dispatchReceipt(await this.dispatchTask(id, taskId, workspaceId, actor, sourceContext));
2347
2388
  }
2348
2389
  if (!Array.isArray(body.taskIds) || !body.taskIds.length || body.taskIds.length > 32 || body.taskIds.some(taskId => typeof taskId !== "string"))
2349
2390
  throw new Error("taskIds 须为 1–32 项任务 id 数组");
2350
2391
  const started = [], failed = [];
2351
2392
  for (const taskId of [...new Set(body.taskIds)]) {
2352
2393
  try {
2353
- started.push(await this.dispatchTask(id, taskId, workspaceId, actor));
2394
+ started.push(await this.dispatchTask(id, taskId, workspaceId, actor, sourceContext));
2354
2395
  }
2355
2396
  catch (error) {
2356
2397
  failed.push({ taskId, error: error instanceof Error ? error.message : String(error) });
@@ -2368,7 +2409,8 @@ export class ProjectService {
2368
2409
  case "resolveEscalation":
2369
2410
  return this.resolveEscalation(id, text(body.escalationId, "escalationId"), text(body.decision, "decision"), body.status ?? "resolved", workspaceId, actor);
2370
2411
  case "correct": return this.correctMember(id, text(body.targetConversationId, "targetConversationId"), text(body.content, "content"), workspaceId, actor);
2371
- case "complete": return this.complete(id, body.summary, body.evidenceRefs, workspaceId, actor);
2412
+ case "deliver":
2413
+ case "complete": return this.deliver(id, body.summary, body.evidenceRefs, workspaceId, actor);
2372
2414
  case "cancel": return this.cancel(id, body, workspaceId, actor);
2373
2415
  default: throw new Error("未知的项目工具操作");
2374
2416
  }
@@ -716,6 +716,8 @@ export class RunService {
716
716
  throw new Error("会话不存在");
717
717
  throw new Error(`会话所属的工作区 ${conversation.workspaceId} 已不存在,拒绝运行`);
718
718
  }
719
+ if (context.conversation.warmSession)
720
+ throw new Error("预热快照只能通过项目派发使用");
719
721
  return context;
720
722
  }
721
723
  /**
@@ -56,6 +56,8 @@ export interface SpawnSessionOptions {
56
56
  * edge and the memory tree are two different things, and this flag touches only the second.
57
57
  */
58
58
  separateMemoryTree?: boolean;
59
+ /** Copy the settled history of another child of the same parent. */
60
+ forkFromConversationId?: string;
59
61
  }
60
62
  export interface ReportSessionOptions {
61
63
  /** The report content (milestone, findings, roadblock, or final output). */
@@ -295,6 +297,7 @@ export declare class SessionOrchestratorService {
295
297
  stoppedIds: string[];
296
298
  descendantCount: number;
297
299
  }>;
300
+ removeWarmSession(conversationId: string): Promise<void>;
298
301
  /**
299
302
  * Permanently destroys a direct child session and its entire descendant subtree (stopping any
300
303
  * running/queued turns first) and removes all transcripts, outputs, runs, and auxiliary state.