@evandu/super-pi 0.1.184 → 0.1.187

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 (59) hide show
  1. package/agents/coder.md +1 -1
  2. package/agents/planner.md +1 -1
  3. package/agents/project-leader.md +2 -2
  4. package/agents/reviewer.md +1 -1
  5. package/agents/super-pi-task/core.ts +164 -7
  6. package/agents/super-pi-task/index.ts +41 -5
  7. package/dist/client/.super-pi-client-sources.json +7 -7
  8. package/dist/client/assets/{CodeMirrorEditor-v8j7qM-5.js → CodeMirrorEditor-Cmx7-z0f.js} +2 -2
  9. package/dist/client/assets/{dist-DFpSLAtp.js → dist-B8CAEuXW.js} +1 -1
  10. package/dist/client/assets/{dist-1PSYOzSn.js → dist-BKx3CpQJ.js} +1 -1
  11. package/dist/client/assets/{dist-XrYkL2Xu.js → dist-BMSVWA_A.js} +1 -1
  12. package/dist/client/assets/{dist-BtRpNdOI.js → dist-BdiInYmk.js} +1 -1
  13. package/dist/client/assets/{dist-Bvl-DsMt.js → dist-Bq7p17eF.js} +1 -1
  14. package/dist/client/assets/{dist-CJ4rSQ4N.js → dist-BzqUlzAf.js} +1 -1
  15. package/dist/client/assets/{dist-DF3hHXYK.js → dist-C0PMHwdm.js} +1 -1
  16. package/dist/client/assets/{dist-Bc6s4uHe.js → dist-C2ltv_8u.js} +1 -1
  17. package/dist/client/assets/{dist-BoSFlin7.js → dist-CDSDxXju.js} +1 -1
  18. package/dist/client/assets/{dist-BUHFKfEO.js → dist-CKZOnuRU.js} +1 -1
  19. package/dist/client/assets/{dist-BS72C5ep.js → dist-CWlI6qO0.js} +1 -1
  20. package/dist/client/assets/{dist-cgEoGcO1.js → dist-CXDhHY7N.js} +1 -1
  21. package/dist/client/assets/{dist-BKj3_VBI.js → dist-Cblc22Ag.js} +1 -1
  22. package/dist/client/assets/{dist-DsUX6SY5.js → dist-CcuBp_Kn.js} +1 -1
  23. package/dist/client/assets/{dist-D-MqsRQM.js → dist-DHFt0Hvo.js} +1 -1
  24. package/dist/client/assets/{dist-Bcw21qWX.js → dist-D_7x3oZt.js} +1 -1
  25. package/dist/client/assets/{dist-CIxW4sg_.js → dist-RHYiODih.js} +1 -1
  26. package/dist/client/assets/{dist-Bta_JEiJ.js → dist-V27Fcf8p.js} +1 -1
  27. package/dist/client/assets/{dist-CvM_6f5G.js → dist-WfagMkC4.js} +1 -1
  28. package/dist/client/assets/{dist-CPEKtCMg.js → dist-akJoBtjs.js} +1 -1
  29. package/dist/client/assets/{dist-Bpfwpwk8.js → dist-frBiV55p.js} +1 -1
  30. package/dist/client/assets/{dist-D4SHQTo9.js → dist-ibsGPa_S.js} +1 -1
  31. package/dist/client/assets/{index-DeTEc54b.css → index-BXQjUHV_.css} +1 -1
  32. package/dist/client/assets/{index-D_XU8eXm.js → index-Dx7HAZ5j.js} +14 -13
  33. package/dist/client/index.html +2 -2
  34. package/dist/server/agents.d.ts +1 -1
  35. package/dist/server/agents.js +1 -1
  36. package/dist/server/application/conversation-service.d.ts +13 -0
  37. package/dist/server/application/conversation-service.js +21 -0
  38. package/dist/server/application/project-service.d.ts +3 -71
  39. package/dist/server/application/project-service.js +36 -195
  40. package/dist/server/application/run-service.d.ts +39 -3
  41. package/dist/server/application/run-service.js +166 -18
  42. package/dist/server/application/session-orchestrator-service.d.ts +38 -5
  43. package/dist/server/application/session-orchestrator-service.js +167 -5
  44. package/dist/server/command-handler.js +5 -1
  45. package/dist/server/http-server.js +45 -18
  46. package/dist/server/index.js +1 -1
  47. package/dist/server/pi-session.d.ts +3 -2
  48. package/dist/server/runtime.js +9 -6
  49. package/dist/server/session-tree-scope.d.ts +1 -1
  50. package/dist/server/store.d.ts +24 -0
  51. package/dist/server/store.js +229 -4
  52. package/dist/server/task-tool.d.ts +5 -2
  53. package/dist/server/task-tool.js +25 -2
  54. package/dist/server/types.d.ts +36 -13
  55. package/dist/server/upload.d.ts +2 -6
  56. package/dist/server/upload.js +7 -5
  57. package/dist/shared/session-reporting.d.ts +2 -0
  58. package/dist/shared/session-reporting.js +9 -9
  59. package/package.json +8 -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-D_XU8eXm.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-DeTEc54b.css">
11
+ <script type="module" crossorigin src="/assets/index-Dx7HAZ5j.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index-BXQjUHV_.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="root"></div>
@@ -38,7 +38,7 @@ type Frontmatter = Record<string, unknown>;
38
38
  */
39
39
  export declare const PI_TOOL_NAMES: readonly ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls", "codemode", "tool_search", "list_mcp_resources", "list_mcp_resource_templates", "read_mcp_resource"];
40
40
  /** Tools shipped by this package. Authors must be able to explicitly deny host extras. */
41
- export declare const SUPER_PI_TOOL_NAMES: readonly ["task", "todowrite", "workflow", "run_async", "scheduled_task", "project", "question", "tool_register", "memory", "skill_manage", "session_search", "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "knowledge_search", "knowledge_import", "document_read", "document_write", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write"];
41
+ export declare const SUPER_PI_TOOL_NAMES: readonly ["task", "todowrite", "workflow", "run_async", "scheduled_task", "project", "question", "tool_register", "memory", "skill_manage", "session_search", "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove", "knowledge_search", "knowledge_import", "document_read", "document_write", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write"];
42
42
  /**
43
43
  * Whether a name can be a real Pi tool. A name is real if it is one of `PI_TOOL_NAMES`, an MCP
44
44
  * server tool, or a PATTERN.
@@ -41,7 +41,7 @@ export const PI_TOOL_NAMES = [
41
41
  export const SUPER_PI_TOOL_NAMES = [
42
42
  "task", "todowrite", "workflow", "run_async", "scheduled_task", "project", "question", "tool_register",
43
43
  "memory", "skill_manage", "session_search",
44
- "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree",
44
+ "session_spawn", "session_status", "session_dispatch", "session_stop", "session_report", "session_stop_subtree", "session_remove",
45
45
  "knowledge_search", "knowledge_import",
46
46
  "document_read", "document_write", "web_search", "web_fetch", "feishu_doc_read", "feishu_doc_write",
47
47
  ];
@@ -204,4 +204,17 @@ export declare class ConversationService {
204
204
  * Forks an existing conversation into a new parallel branch, cloning the Pi session.
205
205
  */
206
206
  forkConversation(conversationId: string): Promise<ForkConversationResult>;
207
+ /**
208
+ * Cancels pending UI/sub-agent work and clears active memory notes for a conversation about to
209
+ * be permanently destroyed (runs while the conversation is still readable in the store).
210
+ */
211
+ prepareDestroyConversation(conversationId: string): Promise<void>;
212
+ /**
213
+ * Removes a destroyed conversation's messages from the recall index and disposes any cached Pi
214
+ * session held in runtime memory.
215
+ */
216
+ cleanupDestroyedConversation(conversation: {
217
+ id: string;
218
+ messageIds: string[];
219
+ }): Promise<void>;
207
220
  }
@@ -552,4 +552,25 @@ export class ConversationService {
552
552
  return { ok: false, message };
553
553
  }
554
554
  }
555
+ /**
556
+ * Cancels pending UI/sub-agent work and clears active memory notes for a conversation about to
557
+ * be permanently destroyed (runs while the conversation is still readable in the store).
558
+ */
559
+ async prepareDestroyConversation(conversationId) {
560
+ this.extensionUiService.cancelPendingUi(conversationId, "aborted");
561
+ for (const run of this.store.snapshot().subagentRuns) {
562
+ if (run.conversationId === conversationId && run.status === "running") {
563
+ this.subagents.stop(run.id);
564
+ }
565
+ }
566
+ await this.memory?.forgetAfter(conversationId, "1970-01-01T00:00:00.000Z");
567
+ }
568
+ /**
569
+ * Removes a destroyed conversation's messages from the recall index and disposes any cached Pi
570
+ * session held in runtime memory.
571
+ */
572
+ async cleanupDestroyedConversation(conversation) {
573
+ this.memory?.removeFromIndex(conversation.messageIds);
574
+ await this.runtime.disposeSessions?.(conversation.id);
575
+ }
555
576
  }
@@ -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\u517C\u4EFB\u79D8\u4E66\u3002\u5148\u8C03\u7528 project(action=get, projectId) \u4E86\u89E3\u6700\u65B0\u72B6\u6001\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 \u542F\u52A8\u6267\u884C\u5B50\u4F1A\u8BDD\uFF1B\u4E0D\u8981\u7528 session_spawn/session_dispatch \u6216 task/workflow \u7ED5\u8FC7\u9879\u76EE\u8D44\u6E90\u9650\u5236\u3002\u6536\u5230\u4EA4\u4ED8\u540E\u7528 request_review \u542F\u52A8\u72EC\u7ACB\u590D\u6838\u3002\u5B50\u4F1A\u8BDD\u7ED3\u675F\u4F1A\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\u3002\u4E0D\u8981\u8F6E\u8BE2\u7B49\u5F85\uFF0C\u4E0D\u8981\u53CD\u590D\u65E0\u8FDB\u5C55\u91CD\u8BD5\uFF0C\u5E76\u53D1\u6EE1\u65F6\u7ED3\u675F\u5F53\u524D\u56DE\u590D\u7B49\u5F85\u56DE\u62A5\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\u9884\u7B97\u95EE\u9898\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\u5148\u8C03\u7528 project(action=get, projectId) \u4E86\u89E3\u6700\u65B0\u72B6\u6001\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\u8FC7\u9879\u76EE\u8D44\u6E90\u9650\u5236\u3002\u4E0D\u8981\u8F6E\u8BE2\u7B49\u5F85\uFF0C\u4E0D\u8981\u53CD\u590D\u65E0\u8FDB\u5C55\u91CD\u8BD5\u3002\u7528 report \u767B\u8BB0\u5173\u952E\u8FDB\u5C55\uFF0C\u7528 escalate \u5C06\u91CD\u5927\u504F\u5DEE\u3001\u6743\u9650\u6216\u9884\u7B97\u95EE\u9898\u4EA4\u7ED9 Boss\uFF0C\u4E0D\u5F97\u81EA\u884C\u89E3\u51B3\u5347\u7EA7\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\u517C\u4EFB\u79D8\u4E66\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 \u767B\u8BB0\u5173\u952E\u8FDB\u5C55\uFF0C\u7528 escalate \u5C06\u91CD\u5927\u504F\u5DEE\u3001\u6743\u9650\u6216\u8303\u56F4\u53D8\u66F4\u4EA4\u7ED9 Boss\uFF0C\u4E0D\u5F97\u81EA\u884C\u89E3\u51B3\u5347\u7EA7\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";
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
  /**
@@ -41,12 +41,8 @@ export type CreateProjectInput = {
41
41
  deliverables?: unknown;
42
42
  acceptanceCriteria?: unknown;
43
43
  constraints?: unknown;
44
- risk?: ProjectRisk;
44
+ risk?: ProjectRisk | (string & {});
45
45
  ownerConversationId?: string;
46
- budget?: {
47
- maxTokens?: number;
48
- maxConcurrent?: number;
49
- };
50
46
  defaultLeaderProfile?: unknown;
51
47
  defaultExecutorProfile?: unknown;
52
48
  defaultReviewerProfile?: unknown;
@@ -70,16 +66,6 @@ export type TopLevelTaskPlan = {
70
66
  priority?: ProjectTask["priority"];
71
67
  dependencies: string[];
72
68
  };
73
- /** What one click on 「提到 N Token 并继续」 produced. */
74
- export type BudgetRaiseResult = {
75
- project: Project;
76
- /** The cap before the raise, so the panel can say what changed. */
77
- previousMaxTokens: number;
78
- /** The cap the server raised it to - the number the one-click button promised. */
79
- suggestedMaxTokens: number;
80
- /** How many budget exceptions were closed by the raise. */
81
- resolvedEscalations: number;
82
- };
83
69
  /**
84
70
  * HOW THE SERVICE ASKS WHAT AN AGENT ID IS.
85
71
  *
@@ -133,39 +119,6 @@ export declare class ProjectService {
133
119
  static taskView(task: ProjectTask, project: Pick<Project, "defaultExecutorProfile" | "defaultReviewerProfile">): ProjectTask;
134
120
  private filterEscalations;
135
121
  private projectView;
136
- /**
137
- * THE NUMBER THE ONE-CLICK PATH OFFERS.
138
- *
139
- * The Boss does not type a budget when the budget runs out: a number typed in a hurry is a
140
- * number nobody predicted, and a budget that is guessed wrong is the failure this whole path
141
- * exists to remove. So the server suggests one instead - double what has already been spent,
142
- * because an agent run that needed twice its first budget will need twice its second one, and
143
- * never less than one token more than the current cap, so the offer always really raises it.
144
- */
145
- private suggestedMaxTokens;
146
- /**
147
- * THE BUDGET PARAGRAPH A BUDGET EXCEPTION CARRIES - AND ONLY A BUDGET EXCEPTION.
148
- *
149
- * WHY THE EXCEPTION TEXT NEEDS THIS. A budget exception used to reach the Boss as one line -
150
- * "请批准追加预算派发复核者" - and that line says nothing about WHO is at fault. The Boss reads
151
- * it as "the Boss did not approve enough", while the truth is often "the agent set the cap too
152
- * low when the project was created". Only one of those two readings leads to a fix, and the
153
- * wrong one leads to approving a budget that runs into the same wall one task later.
154
- *
155
- * SO THE SERVER WRITES THE NUMBERS, because only the server has them: the effective usage in
156
- * the §5 unit (输入 + 输出 + 缓存写入 × 1.25 + 缓存读取 × 0.1), the cap, and the number the
157
- * one-click raise would offer - the very number the panel shows, so the two can never disagree.
158
- *
159
- * AND IT SAYS THE UNCOMFORTABLE PART OUT LOUD - 「可能是我一开始把预算填小了」. The words are in
160
- * the project's own voice, because that is the voice an exception already speaks in, and an
161
- * exception that never names the possibility is a case written to be approved as it stands.
162
- *
163
- * ONLY A BUDGET CASE GETS THESE WORDS. An exception about permissions or about scope must not
164
- * carry budget numbers: a reader who sees a budget on a permission case stops reading the
165
- * case. `BUDGET_CASE` decides, and it is matched on the agent's own words - the agent that
166
- * says 「撞到上限了」 has said the same thing as one that says 「预算」.
167
- */
168
- private budgetExceptionNote;
169
122
  private raw;
170
123
  private workspace;
171
124
  private event;
@@ -374,27 +327,6 @@ export declare class ProjectService {
374
327
  * different decisions, and the timeline is where that difference has to show up.
375
328
  */
376
329
  cancel(id: string, body: Record<string, any>, workspaceId: string, actor: string): Promise<Project>;
377
- updateBudget(id: string, input: {
378
- maxTokens?: number;
379
- maxConcurrent?: number;
380
- }, workspaceId: string): Promise<Project>;
381
- /**
382
- * ONE CLICK: RAISE THE BUDGET AND LET THE WORK CONTINUE.
383
- *
384
- * Three things happen here, and they happen together: the cap goes up to a number the SERVER
385
- * computed, the budget exception that is waiting for a decision is closed, and the work that
386
- * was blocked is woken up again. Doing them apart is what made the old path painful - a Boss
387
- * had to open a form, type a number, press save, and then wake the leader by hand, and every
388
- * one of those steps was a chance to stop halfway.
389
- *
390
- * IT IS A BOSS OPERATION. A session may not raise the budget of its own project: the budget is
391
- * the Boss's stop, and an agent that could lift its own limit would not have one. The HTTP
392
- * layer refuses a request that carries a capability for the same reason.
393
- *
394
- * The manual `updateBudget` stays a SEPARATE intent: adjusting a number is not the same as
395
- * asking for the work to continue, so the manual path does not continue anything.
396
- */
397
- raiseBudgetAndContinue(id: string, workspaceId: string, callerConversationId?: string): Promise<BudgetRaiseResult>;
398
330
  addReport(id: string, input: Omit<ProjectReport, "id" | "projectId" | "createdAt">, workspaceId?: string, actor?: string): Promise<ProjectReport>;
399
331
  addEscalation(id: string, input: Pick<ProjectEscalation, "reason" | "severity" | "taskId" | "title">, workspaceId?: string, actor?: string): Promise<ProjectEscalation>;
400
332
  /**
@@ -19,8 +19,8 @@ const stamp = () => new Date().toISOString();
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 const STANDARD_LEADER_PROMPT = "你是直接向 Boss 负责的项目 Leader,兼任秘书。先调用 project(action=get, projectId) 了解最新状态。小项目只拆最少必要任务,大项目按交付边界分工。用 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 提交带证据的最终交付总结。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
23
- export const LIGHTWEIGHT_LEADER_PROMPT = "你是直接向 Boss 负责的项目 Leader,这是一个轻量项目:这个项目由你亲自完成,不要拆子任务、不要派发给别人、也没有独立复核。先调用 project(action=get, projectId) 了解最新状态。用 add_task 登记任务(明确目标、交付物、验收标准、依赖),任务一律登记为执行任务:role=leader 或带 parentTaskId 都会被拒绝。dispatch 会把任务交回给你自己,你亲自做完;做完后调用 project(action=submit, projectId, taskId, output, evidenceRefs) 提交交付,提交即完成,不会有人回来复核,证据必须附上。不要用 session_spawn/session_dispatch 或 task/workflow 绕过项目资源限制。不要轮询等待,不要反复无进展重试。用 report 登记关键进展,用 escalate 将重大偏差、权限或预算问题交给 Boss,不得自行解决升级事项。所有任务交付后,用 complete 提交带证据的最终交付总结。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
22
+ 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 提交带证据的最终交付总结。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
23
+ 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,不得自行解决升级事项。所有任务交付后,用 complete 提交带证据的最终交付总结。上下文有限,明确假设,主动寻找反证。只在本次触发范围内工作。";
24
24
  const text = (value, label) => {
25
25
  if (typeof value !== "string" || !value.trim())
26
26
  throw new Error(`${label} 不能为空`);
@@ -30,7 +30,7 @@ const text = (value, label) => {
30
30
  };
31
31
  const optional = (value, label) => value === undefined ? undefined : text(value, label);
32
32
  const strings = (value, label) => {
33
- if (value === undefined)
33
+ if (value === undefined || value === null)
34
34
  return [];
35
35
  if (!Array.isArray(value) || value.length > 100)
36
36
  throw new Error(`${label} 必须是最多 100 项的字符串数组`);
@@ -121,41 +121,11 @@ export const mergeProfile = (taskProfile, projectDefault) => {
121
121
  const closed = (p) => ["completed", "cancelled", "failed"].includes(p.status);
122
122
  const busy = (status) => ["running", "waiting", "awaiting_background"].includes(status ?? "");
123
123
  const dependenciesComplete = (p, t) => t.dependencies.every((id) => p.tasks.find((candidate) => candidate.id === id)?.status === "completed");
124
- // THE BUDGET IS COUNTED IN BILLING-EQUIVALENT TOKENS, NOT RAW TOKENS. A cache read costs a
125
- // fraction of a fresh input token (0.1x on every provider we know), and a cache write costs a
126
- // little more than one (1.25x). Counting them at 1:1 inflates an agent run by an order of
127
- // magnitude, so a budget written by intuition always blows up. The formula is:
128
- // input + output + cacheWrite * 1.25 + cacheRead * 0.1
129
- // and it is shown to the reader, because a budget nobody can predict is a budget nobody trusts.
124
+ // Usage accounting uses billing-equivalent tokens so the panel and report match provider bills,
125
+ // alongside the raw 1:1 components. There is no budget cap or admission gate.
130
126
  const CACHE_READ_WEIGHT = 0.1;
131
127
  const CACHE_WRITE_WEIGHT = 1.25;
132
128
  const tokens = (usage) => usage ? Math.round(usage.input + usage.output + usage.cacheWrite * CACHE_WRITE_WEIGHT + usage.cacheRead * CACHE_READ_WEIGHT) : 0;
133
- /**
134
- * THE BUDGET A PROJECT STARTS WITH, AND THE FALLBACK A BUDGETLESS PROJECT IS READ AT.
135
- *
136
- * 400,000 equivalent tokens, and the number is measured rather than guessed: one real project
137
- * with two tasks, each with an independent review, spent 378,424 equivalent tokens (1,448,095
138
- * raw) and stopped ONE REVIEW SHORT of done at exactly this kind of cap. A task with its review
139
- * costs about 190,000 equivalent tokens - roughly 20 turns at about 9,500 equivalent tokens a
140
- * turn - so 400,000 carries a simple project end to end.
141
- *
142
- * THE OLD 100,000 WAS NOT A BUDGET, IT WAS A WALL: it could not finish one task and its review,
143
- * and the project that hit it was closed as cancelled with the work already delivered. A cap that
144
- * is too low does not slow a project down, it kills it; a cap that is too high only means the
145
- * ceiling printed on the panel is higher than the spend. So the default is set from what a real
146
- * project actually costs, and the agent is told to compute its own number on top of it.
147
- */
148
- const DEFAULT_MAX_TOKENS = 400_000;
149
- /**
150
- * A REASON THAT SAYS "THIS IS ABOUT THE BUDGET".
151
- *
152
- * The word the escalation carries is what tells the reader (and the server) that the case in
153
- * front of them is a budget case and not a permission case or a scope case. It is matched in
154
- * both languages because the agent writes in both languages, and it is matched LOOSELY on
155
- * purpose: an agent that says "撞到上限了" or "tokens" has said the same thing as one that says
156
- * "预算".
157
- */
158
- const BUDGET_CASE = /(预算|budget|token|上限|额度)/i;
159
129
  /**
160
130
  * HOW MANY PROJECTS ONE LIST CALL MAY CARRY.
161
131
  *
@@ -343,9 +313,8 @@ const detailItem = (label, prose) => {
343
313
  * the project flow then exceeds the cost of the work.
344
314
  *
345
315
  * A lightweight project collapses the flow to the leader session: it IS the worker, and a
346
- * delivery is accepted on the executor's own evidence. Every guardrail is unchanged - the budget,
347
- * the concurrency cap, the mandatory evidence, the escalation path, the event timeline - because
348
- * what makes a project a project is the guardrails, not the number of sessions.
316
+ * delivery is accepted on the executor's own evidence. Mandatory evidence, the escalation path,
317
+ * and the event timeline stay the same.
349
318
  */
350
319
  const lightweight = (p) => p.mode === "lightweight";
351
320
  /** Persist explicit domain fields only; transport credentials never enter project records. */
@@ -425,54 +394,10 @@ export class ProjectService {
425
394
  ...p,
426
395
  status: this.statusWithInterruptions(p),
427
396
  resources,
428
- suggestedMaxTokens: this.suggestedMaxTokens(p, resources.tokens),
429
397
  tasks: p.tasks.map((t) => ProjectService.taskView(t, p)),
430
398
  escalations: this.filterEscalations(p.escalations ?? [], actor),
431
399
  };
432
400
  }
433
- /**
434
- * THE NUMBER THE ONE-CLICK PATH OFFERS.
435
- *
436
- * The Boss does not type a budget when the budget runs out: a number typed in a hurry is a
437
- * number nobody predicted, and a budget that is guessed wrong is the failure this whole path
438
- * exists to remove. So the server suggests one instead - double what has already been spent,
439
- * because an agent run that needed twice its first budget will need twice its second one, and
440
- * never less than one token more than the current cap, so the offer always really raises it.
441
- */
442
- suggestedMaxTokens(p, usedTokens) {
443
- const current = p.budget?.maxTokens ?? DEFAULT_MAX_TOKENS;
444
- return Math.max(current + 1, usedTokens * 2);
445
- }
446
- /**
447
- * THE BUDGET PARAGRAPH A BUDGET EXCEPTION CARRIES - AND ONLY A BUDGET EXCEPTION.
448
- *
449
- * WHY THE EXCEPTION TEXT NEEDS THIS. A budget exception used to reach the Boss as one line -
450
- * "请批准追加预算派发复核者" - and that line says nothing about WHO is at fault. The Boss reads
451
- * it as "the Boss did not approve enough", while the truth is often "the agent set the cap too
452
- * low when the project was created". Only one of those two readings leads to a fix, and the
453
- * wrong one leads to approving a budget that runs into the same wall one task later.
454
- *
455
- * SO THE SERVER WRITES THE NUMBERS, because only the server has them: the effective usage in
456
- * the §5 unit (输入 + 输出 + 缓存写入 × 1.25 + 缓存读取 × 0.1), the cap, and the number the
457
- * one-click raise would offer - the very number the panel shows, so the two can never disagree.
458
- *
459
- * AND IT SAYS THE UNCOMFORTABLE PART OUT LOUD - 「可能是我一开始把预算填小了」. The words are in
460
- * the project's own voice, because that is the voice an exception already speaks in, and an
461
- * exception that never names the possibility is a case written to be approved as it stands.
462
- *
463
- * ONLY A BUDGET CASE GETS THESE WORDS. An exception about permissions or about scope must not
464
- * carry budget numbers: a reader who sees a budget on a permission case stops reading the
465
- * case. `BUDGET_CASE` decides, and it is matched on the agent's own words - the agent that
466
- * says 「撞到上限了」 has said the same thing as one that says 「预算」.
467
- */
468
- budgetExceptionNote(p, reason) {
469
- if (!BUDGET_CASE.test(reason))
470
- return undefined;
471
- const used = this.resources(p).tokens;
472
- const cap = p.budget?.maxTokens ?? DEFAULT_MAX_TOKENS;
473
- const suggested = this.suggestedMaxTokens(p, used);
474
- return `【预算说明】当前有效用量 ${grouped(used)} 等效 Token,上限 ${grouped(cap)} 等效 Token;建议提到 ${grouped(suggested)} 等效 Token(面板上「提到 N Token 并继续」用的就是这一个数)。口径:输入 + 输出 + 缓存写入 × 1.25 + 缓存读取 × 0.1。可能是我一开始把预算填小了:请按「任务数 × 每任务轮数 × 每轮上下文」重新估算,一个任务连它的独立复核约 190,000 等效 Token,宁可多给 —— 预算不够时项目会被卡住,并以取消收口。`;
475
- }
476
401
  raw(id, workspaceId) {
477
402
  const scope = this.workspace(workspaceId);
478
403
  const p = this.store.project(id);
@@ -875,6 +800,7 @@ export class ProjectService {
875
800
  reportedToParentAt: c.reportedToParentAt,
876
801
  archivedAt: c.archivedAt,
877
802
  hasOpenEscalation: openEscalationRequesters.has(c.id),
803
+ ...(c.hasPendingResult ? { hasPendingResult: true } : {}),
878
804
  });
879
805
  }
880
806
  const sessions = memberConversations.map((c) => {
@@ -1129,14 +1055,6 @@ export class ProjectService {
1129
1055
  lines.push(`- 最后更新时间:${moment(p.updatedAt)}`);
1130
1056
  if (p.closedAt)
1131
1057
  lines.push(`- 完成时间:${moment(p.closedAt)}`);
1132
- lines.push(`- 预算上限:${p.budget?.maxTokens ?? DEFAULT_MAX_TOKENS} Token`);
1133
- // THE USAGE IS REPORTED IN THE SAME BILLING-EQUIVALENT UNITS THE BUDGET IS SPENT IN, and the
1134
- // formula is printed next to the number: a budget nobody can predict is a budget nobody trusts.
1135
- // The sentence after the formula says what the number INCLUDES - a one-shot call (a sub-agent)
1136
- // is part of it, so a reader who dispatches children can see what that cost them.
1137
- // THE RAW 1:1 FIGURE FOLLOWS IT, because the two differ by a factor of two and a half on a
1138
- // real run, and a reader who checks the project's cost against their own tooling needs to
1139
- // see both numbers and the parts they are made of.
1140
1058
  const usage = this.resources(p);
1141
1059
  lines.push(`- 已用等效 Token:${usage.tokens}(口径:输入 + 输出 + 缓存写入×${CACHE_WRITE_WEIGHT} + 缓存读取×${CACHE_READ_WEIGHT},取整;含项目内的一次性调用(subagent))`);
1142
1060
  lines.push(`- 原始口径(1:1):${usage.rawTokens}(输入 ${usage.usage?.input ?? 0} + 输出 ${usage.usage?.output ?? 0} + 缓存写入 ${usage.usage?.cacheWrite ?? 0} + 缓存读取 ${usage.usage?.cacheRead ?? 0})`);
@@ -1240,20 +1158,12 @@ export class ProjectService {
1240
1158
  const workspaceId = this.workspace(input.workspaceId);
1241
1159
  if (input.ownerConversationId !== undefined)
1242
1160
  throw new Error("项目负责人由启动操作创建独立会话");
1243
- if (input.risk !== undefined && !["low", "medium", "high"].includes(input.risk))
1244
- throw new Error("项目风险等级不合法");
1161
+ const rawRisk = typeof input.risk === "string" ? input.risk.trim().toLowerCase() : "";
1162
+ const risk = rawRisk === "medium" || rawRisk === "high" ? rawRisk : "low";
1245
1163
  // THE MODE IS CHOSEN ONCE, AT BIRTH, AND IT IS A CLOSED SET. A typo must not silently buy a
1246
1164
  // project the standard shape, because the standard shape is the one with the reviewer.
1247
1165
  if (input.mode !== undefined && input.mode !== "standard" && input.mode !== "lightweight")
1248
1166
  throw new Error("项目模式不合法:只能是 standard 或 lightweight");
1249
- if (input.budget !== undefined && (!input.budget || typeof input.budget !== "object" || Array.isArray(input.budget)))
1250
- throw new Error("资源预算不合法");
1251
- for (const [key, value] of Object.entries(input.budget ?? {})) {
1252
- if (value === undefined)
1253
- continue;
1254
- if (!["maxTokens", "maxConcurrent"].includes(key) || !Number.isSafeInteger(value) || value <= 0)
1255
- throw new Error("资源预算必须是正整数");
1256
- }
1257
1167
  const defaultLeaderProfile = profile(input.defaultLeaderProfile, "默认 Leader 配置");
1258
1168
  const defaultExecutorProfile = profile(input.defaultExecutorProfile, "默认执行配置");
1259
1169
  const defaultReviewerProfile = profile(input.defaultReviewerProfile, "默认复核配置");
@@ -1267,7 +1177,7 @@ export class ProjectService {
1267
1177
  const now = stamp();
1268
1178
  const p = { id: `project_${randomUUID()}`, workspaceId, title: text(input.title, "项目标题"), objective: text(input.objective, "项目目标"),
1269
1179
  deliverables: strings(input.deliverables, "交付物"), acceptanceCriteria: strings(input.acceptanceCriteria, "验收标准"), constraints: strings(input.constraints, "约束"),
1270
- risk: input.risk ?? "low", status: "planning", budget: { maxTokens: input.budget?.maxTokens ?? DEFAULT_MAX_TOKENS, maxConcurrent: input.budget?.maxConcurrent ?? 2 },
1180
+ risk, status: "planning",
1271
1181
  // A project without a mode is a standard project: the mode is written down only when it was
1272
1182
  // asked for, so every project that existed before the mode existed reads as standard.
1273
1183
  ...(input.mode ? { mode: input.mode } : {}),
@@ -1285,35 +1195,27 @@ export class ProjectService {
1285
1195
  const saved = await this.store.setProject(p);
1286
1196
  return this.projectView(saved);
1287
1197
  }
1288
- admission(p, checkConcurrency = true, coordinator = false) {
1198
+ admission(p) {
1289
1199
  this.live(p);
1290
1200
  if (p.escalations.some((e) => e.status === "open" && e.severity === "high" && (e.audience === "boss" || !e.audience)))
1291
1201
  throw new Error("等待 Boss 处理升级决策后才能继续派发");
1292
- const r = this.resources(p);
1293
- if (p.budget?.maxTokens && r.tokens >= p.budget.maxTokens)
1294
- throw new Error("已达到已报告 Token 预算,拒绝继续派发");
1295
- const reserved = p.tasks.filter((t) => {
1296
- if (t.status === "in_progress" && t.role === "leader")
1297
- return false;
1298
- const sessionId = t.status === "in_progress" ? t.ownerConversationId : t.status === "awaiting_review" ? t.reviewerConversationId : undefined;
1299
- const state = sessionId ? this.store.conversation(sessionId)?.status : undefined;
1300
- if (busy(state))
1301
- return true;
1302
- if (state !== "idle")
1303
- return false;
1304
- const last = p.events?.filter((e) => e.taskId === t.id && (e.kind === "dispatched" || e.kind === "review_requested")).at(-1);
1305
- return Boolean(last && Date.now() - Date.parse(last.createdAt) < 5000);
1306
- }).length;
1307
- if (checkConcurrency && !coordinator && p.budget?.maxConcurrent && Math.max(r.activeWorkers, reserved) >= p.budget.maxConcurrent)
1308
- throw new Error("项目执行并发已满,等待任务交付后重试");
1309
1202
  }
1310
1203
  context(p) {
1311
- return `项目 ${p.id}:${p.title}\n目标:${p.objective}\n交付物:${p.deliverables.join(";")}\n验收标准:${p.acceptanceCriteria.join(";")}\n约束:${p.constraints.join(";")}\n预算:${JSON.stringify(p.budget)}。预算是派发准入限制,运行中请求可能超额。`;
1204
+ const modeLabel = lightweight(p) ? "轻量(由你亲自完成,提交即完成,无独立复核)" : "标准(任务分工 + 独立复核 + 逐级汇报)";
1205
+ const taskLines = p.tasks.length
1206
+ ? p.tasks.map((t) => {
1207
+ const deps = t.dependencies.length ? `,依赖:${t.dependencies.join("、")}` : "";
1208
+ const owner = t.ownerConversationId ? `,执行会话:${t.ownerConversationId}` : "";
1209
+ const reviewer = t.reviewerConversationId ? `,复核会话:${t.reviewerConversationId}` : "";
1210
+ return `- ${t.id}|${t.title}|role=${t.role}|status=${t.status}${deps}${owner}${reviewer}`;
1211
+ }).join("\n")
1212
+ : "(暂无已登记任务,可直接用 add_task 拆解登记)";
1213
+ return `项目 ${p.id}:${p.title}\n模式:${modeLabel}\n目标:${p.objective}\n交付物:${p.deliverables.join(";")}\n验收标准:${p.acceptanceCriteria.join(";")}\n约束:${p.constraints.join(";")}\n当前任务分工:\n${taskLines}`;
1312
1214
  }
1313
1215
  async start(id, workspaceId, actor) {
1314
1216
  return this.change(id, workspaceId, async (p) => {
1315
1217
  this.topLevelAuthor(p, actor);
1316
- this.admission(p, false);
1218
+ this.admission(p);
1317
1219
  if (!this.orchestrator)
1318
1220
  throw new Error("会话编排服务未就绪");
1319
1221
  if (p.ownerConversationId && busy(this.store.conversation(p.ownerConversationId)?.status))
@@ -1344,6 +1246,11 @@ export class ProjectService {
1344
1246
  ...(effective?.watchdogTimeoutSeconds ? { watchdogTimeoutSeconds: effective.watchdogTimeoutSeconds } : {}),
1345
1247
  })).conversationId;
1346
1248
  }
1249
+ for (const task of p.tasks) {
1250
+ if (!task.parentTaskId && (!task.accountableConversationId || task.accountableConversationId === p.initiatorConversationId)) {
1251
+ task.accountableConversationId = p.ownerConversationId;
1252
+ }
1253
+ }
1347
1254
  this.event(p, "started", "项目负责人开始组织执行", undefined, actor);
1348
1255
  p.status = "active";
1349
1256
  await this.store.setProject(p);
@@ -1441,7 +1348,7 @@ export class ProjectService {
1441
1348
  operation accepts. */
1442
1349
  if (t.status !== "ready" && t.status !== "interrupted")
1443
1350
  throw new Error("仅待派发或已中断的任务可以启动");
1444
- this.admission(p, true, t.role === "leader");
1351
+ this.admission(p);
1445
1352
  if (t.role === "leader" && !t.ownerConversationId && p.tasks.filter((t) => t.role === "leader" && t.ownerConversationId).length >= 8)
1446
1353
  throw new Error("分支 Leader 最多 8 个,请收敛组织层级");
1447
1354
  if (!this.orchestrator || !p.ownerConversationId)
@@ -1488,7 +1395,7 @@ export class ProjectService {
1488
1395
  this.event(p, "dispatched", `派发执行:${t.title}`, t.id, actor);
1489
1396
  this.reconcile(p);
1490
1397
  await this.store.setProject(p);
1491
- const delegation = t.role === "leader" ? `你是分支 Leader,负责这项任务的拆解、委派、集成交付。用 project add_task 时必须带 parentTaskId="${t.id}";可按必要性指定 role="leader" 或 "executor";add_task / update_task 时可以带 executorProfile 与 reviewerProfile(支持指定 agentId、cwd、model、thinkingLevel、watchdogTimeoutSeconds),按任务性质将执行与复核委派给最合适的员工,不指定则继承项目默认。用 project dispatch / request_review 管理直属子任务,子会话结束自动回报给你,不要轮询;并发满时结束本轮等待回报。所有必需子任务独立验收后才能 submit 聚合交付,上级还会独立复核你的集成结果。最多 3 层 Leader、8 个分支 Leader;小任务不要继续拆层。你的下属的升级先到你这里;你决定是自己解决还是再向上级转述。` : "你是执行者,不得自行拆解子任务。";
1398
+ const delegation = t.role === "leader" ? `你是分支 Leader,负责这项任务的拆解、委派、集成交付。用 project add_task 时必须带 parentTaskId="${t.id}";可按必要性指定 role="leader" 或 "executor";add_task / update_task 时可以带 executorProfile 与 reviewerProfile(支持指定 agentId、cwd、model、thinkingLevel、watchdogTimeoutSeconds),按任务性质将执行与复核委派给最合适的员工,不指定则继承项目默认。用 project dispatch / request_review 管理直属子任务,派发后子会话立即开始执行并在完成后自动回报给你,不要轮询;等待回报时结束本轮即可。所有必需子任务独立验收后才能 submit 聚合交付,上级还会独立复核你的集成结果。最多 3 层 Leader、8 个分支 Leader;小任务不要继续拆层。你的下属的升级先到你这里;你决定是自己解决还是再向上级转述。` : `你是执行者,直接上级会话是 ${manager},不得自行拆解子任务。`;
1492
1399
  /* THE LIGHTWEIGHT TASK SAYS WHAT IS DIFFERENT, because the difference is the point: there is
1493
1400
  no reviewer coming back, so the evidence that the reviewer would have demanded is the only
1494
1401
  thing that stands behind the delivery. */
@@ -1787,69 +1694,6 @@ export class ProjectService {
1787
1694
  await this.orchestrator?.stopSubtree?.(result.ownerConversationId);
1788
1695
  return result;
1789
1696
  }
1790
- async updateBudget(id, input, workspaceId) {
1791
- return this.change(id, workspaceId, (p) => {
1792
- this.live(p);
1793
- for (const key of ["maxTokens", "maxConcurrent"])
1794
- if (input[key] !== undefined) {
1795
- if (!Number.isSafeInteger(input[key]) || input[key] <= 0)
1796
- throw new Error("资源预算必须是正整数");
1797
- (p.budget ??= {})[key] = input[key];
1798
- }
1799
- this.event(p, "budget", `Boss 调整派发预算:${p.budget?.maxTokens} Token,并发 ${p.budget?.maxConcurrent}`);
1800
- return p;
1801
- });
1802
- }
1803
- /**
1804
- * ONE CLICK: RAISE THE BUDGET AND LET THE WORK CONTINUE.
1805
- *
1806
- * Three things happen here, and they happen together: the cap goes up to a number the SERVER
1807
- * computed, the budget exception that is waiting for a decision is closed, and the work that
1808
- * was blocked is woken up again. Doing them apart is what made the old path painful - a Boss
1809
- * had to open a form, type a number, press save, and then wake the leader by hand, and every
1810
- * one of those steps was a chance to stop halfway.
1811
- *
1812
- * IT IS A BOSS OPERATION. A session may not raise the budget of its own project: the budget is
1813
- * the Boss's stop, and an agent that could lift its own limit would not have one. The HTTP
1814
- * layer refuses a request that carries a capability for the same reason.
1815
- *
1816
- * The manual `updateBudget` stays a SEPARATE intent: adjusting a number is not the same as
1817
- * asking for the work to continue, so the manual path does not continue anything.
1818
- */
1819
- async raiseBudgetAndContinue(id, workspaceId, callerConversationId) {
1820
- if (callerConversationId)
1821
- throw new Error("管理操作仅由 Boss 发起:Agent 不能提高预算,也不能替 Boss 让项目继续");
1822
- const raised = await this.change(id, workspaceId, (p) => {
1823
- this.live(p);
1824
- const previousMaxTokens = p.budget?.maxTokens ?? DEFAULT_MAX_TOKENS;
1825
- const usedTokens = this.resources(p).tokens;
1826
- const suggestedMaxTokens = Math.max(previousMaxTokens + 1, usedTokens * 2);
1827
- (p.budget ??= {}).maxTokens = suggestedMaxTokens;
1828
- const decision = `Boss 提高预算到 ${suggestedMaxTokens} Token 并继续`;
1829
- let resolvedEscalations = 0;
1830
- for (const e of p.escalations) {
1831
- if (e.status !== "open")
1832
- continue;
1833
- // ONLY THE BUDGET ONES. An exception about scope or permissions is not the Boss's to
1834
- // close with a budget decision, and closing it here would hide a question nobody answered.
1835
- if (!e.reason.includes("预算"))
1836
- continue;
1837
- e.status = "resolved";
1838
- e.decision = decision;
1839
- e.resolvedAt = stamp();
1840
- resolvedEscalations += 1;
1841
- }
1842
- this.event(p, "budget", `Boss 提高派发预算:${previousMaxTokens} → ${suggestedMaxTokens} Token,并继续执行(已处理 ${resolvedEscalations} 条预算例外)`);
1843
- this.reconcile(p);
1844
- return { previousMaxTokens, suggestedMaxTokens, resolvedEscalations };
1845
- });
1846
- // AND NOW LET IT MOVE. `start` is the existing way to wake the leader: it dispatches the
1847
- // leader session when the project has one, and creates one when it has not. Its refusal -
1848
- // "项目负责人正在执行,请勿重复启动" - is passed through unchanged: a busy leader is a fact
1849
- // the Boss has to see, not an error to swallow.
1850
- const project = await this.start(id, workspaceId);
1851
- return { ...raised, project };
1852
- }
1853
1697
  async addReport(id, input, workspaceId, actor) {
1854
1698
  let supervisorToWake;
1855
1699
  let taskForWake;
@@ -1925,16 +1769,11 @@ export class ProjectService {
1925
1769
  : "执行者";
1926
1770
  }
1927
1771
  const reason = text(input.reason, "升级原因");
1928
- /* THE BUDGET CASE GETS ITS NUMBERS HERE, WHERE THEY ARE KNOWN. A budget exception without
1929
- the usage, the cap and the suggested number leaves the reader to guess, and the guess is
1930
- always "the Boss did not approve enough". A non-budget exception gets no budget words at
1931
- all - see `budgetExceptionNote`. */
1932
- const budgetNote = this.budgetExceptionNote(p, reason);
1933
1772
  const e = {
1934
1773
  id: randomUUID(),
1935
1774
  projectId: id,
1936
1775
  taskId: t?.id,
1937
- reason: budgetNote ? `${reason}\n\n${budgetNote}` : reason,
1776
+ reason,
1938
1777
  /* THE QUESTION IS KEPT BESIDE THE CASE. The title is what the reader decides ON - one
1939
1778
  sentence, in the reader's terms - and the reason is the case for it. An escalation
1940
1779
  * without a title is still a valid escalation; it simply has to be read in full. */
@@ -2170,7 +2009,7 @@ export class ProjectService {
2170
2009
  if (body.action === "create") {
2171
2010
  // ONLY A ROOT CONVERSATION MAY OPEN A PROJECT. Every dispatched session - the leader, its
2172
2011
  // reviewers, the workers - holds the same tool, and a project opened from one of them would
2173
- // carry its own budget and concurrency guards while sitting outside the guard that dispatched it.
2012
+ // escape the parent project's delegation and reporting chain.
2174
2013
  const conversation = this.store.conversation(actor);
2175
2014
  if (!conversation)
2176
2015
  throw new Error("找不到这个会话。");
@@ -2182,9 +2021,9 @@ export class ProjectService {
2182
2021
  // membership, and the membership is the real reason. The set of sessions that may open a
2183
2022
  // project is the same either way: a session is refused if it is in a project OR has a parent.
2184
2023
  if (this.projectForSession(actor))
2185
- throw new Error("已经在项目里的会话不能另起项目:再开一个会绕开当前项目的预算与并发护栏。");
2024
+ throw new Error("已经在项目里的会话不能另起项目:请专注当前项目分工。");
2186
2025
  if (conversation.parentConversationId)
2187
- throw new Error("只有主对话可以创建项目:派发出来的会话不能另起项目,否则会绕过项目的预算与并发护栏。");
2026
+ throw new Error("只有主对话可以创建项目:派发出来的会话不能另起项目。");
2188
2027
  const running = this.store.projects().filter((p) => p.initiatorConversationId === actor && !closed(p));
2189
2028
  if (running.length >= 3)
2190
2029
  throw new Error("你同时进行的项目超过上限(3 个),先完成或停止一个再新建。");
@@ -2192,6 +2031,8 @@ export class ProjectService {
2192
2031
  const plan = this.planTopLevelTasks(batch);
2193
2032
  const project = await this.create({ ...input, workspaceId }, actor);
2194
2033
  await this.registerTopLevelTasks(project.id, plan, workspaceId, actor);
2034
+ if (this.orchestrator)
2035
+ await this.start(project.id, workspaceId, actor);
2195
2036
  return this.get(project.id, workspaceId);
2196
2037
  }
2197
2038
  if (body.action === "list") {