@evandu/super-pi-server 0.0.0-stage → 0.1.260

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 (370) hide show
  1. package/README.md +250 -3
  2. package/agents/code-auditor.md +64 -0
  3. package/agents/code-designer.md +64 -0
  4. package/agents/coder.md +24 -0
  5. package/agents/critic.md +24 -0
  6. package/agents/document-organizer.md +48 -0
  7. package/agents/patcher.md +27 -0
  8. package/agents/planner.md +30 -0
  9. package/agents/project-leader.md +28 -0
  10. package/agents/reviewer.md +27 -0
  11. package/agents/scout.md +27 -0
  12. package/agents/solution-designer.md +62 -0
  13. package/agents/super-pi-documents/index.ts +92 -0
  14. package/agents/super-pi-feishu/index.ts +88 -0
  15. package/agents/super-pi-knowledge/index.ts +70 -0
  16. package/agents/super-pi-managed-model/index.ts +9 -0
  17. package/agents/super-pi-memory/index.ts +75 -0
  18. package/agents/super-pi-native-tools/index.ts +1 -0
  19. package/agents/super-pi-task/core.ts +2262 -0
  20. package/agents/super-pi-task/index.ts +814 -0
  21. package/agents/super-pi-task/workflow-schema.ts +34 -0
  22. package/agents/super-pi-web/index.ts +32 -0
  23. package/agents/verifier.md +25 -0
  24. package/assets/fonts/LICENSE +92 -0
  25. package/assets/fonts/NotoSansSC-Bold.otf +0 -0
  26. package/assets/fonts/NotoSansSC-Regular.otf +0 -0
  27. package/assets/knowledge-model/README.md +37 -0
  28. package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/config.json +31 -0
  29. package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/onnx/model_quantized.onnx +0 -0
  30. package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/special_tokens_map.json +7 -0
  31. package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer.json +21278 -0
  32. package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer_config.json +15 -0
  33. package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/vocab.txt +21128 -0
  34. package/bin/npm-prefix.d.ts +1 -0
  35. package/bin/npm-prefix.js +10 -0
  36. package/bin/super-pi.js +349 -0
  37. package/dist/client/.super-pi-client-sources.json +82 -0
  38. package/dist/client/assets/CodeMirrorEditor-mi9rGUce.js +2 -0
  39. package/dist/client/assets/GitDiffEditor-CpoDDQrA.css +1 -0
  40. package/dist/client/assets/GitDiffEditor-FQBfGxOY.js +29 -0
  41. package/dist/client/assets/diff-ChtP43wD.js +1 -0
  42. package/dist/client/assets/dist-AW5lyI3I.js +1 -0
  43. package/dist/client/assets/dist-B3-a6uF0.js +7 -0
  44. package/dist/client/assets/dist-BGxkyh6e.js +1 -0
  45. package/dist/client/assets/dist-BJxfd7yb.js +11 -0
  46. package/dist/client/assets/dist-BRVQKlcp.js +1 -0
  47. package/dist/client/assets/dist-BV64A9Ji.js +1 -0
  48. package/dist/client/assets/dist-BXAOrsjq.js +1 -0
  49. package/dist/client/assets/dist-CKF2Jksy.js +1 -0
  50. package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
  51. package/dist/client/assets/dist-Cus6_oaF.js +2 -0
  52. package/dist/client/assets/dist-Cx00EZKR.js +23 -0
  53. package/dist/client/assets/dist-D71y2EI1.js +1 -0
  54. package/dist/client/assets/dist-D978o95T.js +5 -0
  55. package/dist/client/assets/dist-Dc1MBGAG.js +1 -0
  56. package/dist/client/assets/dist-Dds-qLxY.js +9 -0
  57. package/dist/client/assets/dist-DeD9copn.js +1 -0
  58. package/dist/client/assets/dist-DuvGReu-.js +6 -0
  59. package/dist/client/assets/dist-Dvb0SqcK.js +2 -0
  60. package/dist/client/assets/dist-J6XWqRpB.js +3 -0
  61. package/dist/client/assets/dist-QzbOCAU6.js +1 -0
  62. package/dist/client/assets/dist-moiMRpw_.js +1 -0
  63. package/dist/client/assets/dist-scBkrwv-.js +2 -0
  64. package/dist/client/assets/dockerfile-BDePf5PZ.js +1 -0
  65. package/dist/client/assets/index-Cn7hdrDw.js +350 -0
  66. package/dist/client/assets/index-UfzqdECL.css +1 -0
  67. package/dist/client/assets/powershell-D8WpQPaX.js +1 -0
  68. package/dist/client/assets/properties-C357ku5U.js +1 -0
  69. package/dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  70. package/dist/client/assets/ruby-ChfNwlCY.js +1 -0
  71. package/dist/client/assets/shell-DwuoZtxw.js +1 -0
  72. package/dist/client/assets/swift-DKB6_1j6.js +1 -0
  73. package/dist/client/assets/toml-BPTmHmyx.js +1 -0
  74. package/dist/client/favicon.ico +0 -0
  75. package/dist/client/favicon.png +0 -0
  76. package/dist/client/favicon.svg +10 -0
  77. package/dist/client/index.html +18 -0
  78. package/dist/extension.d.ts +15 -0
  79. package/dist/extension.js +126 -0
  80. package/dist/server/active-memory.d.ts +247 -0
  81. package/dist/server/active-memory.js +669 -0
  82. package/dist/server/agents.d.ts +245 -0
  83. package/dist/server/agents.js +701 -0
  84. package/dist/server/application/catalog-service.d.ts +98 -0
  85. package/dist/server/application/catalog-service.js +245 -0
  86. package/dist/server/application/conversation-service.d.ts +245 -0
  87. package/dist/server/application/conversation-service.js +654 -0
  88. package/dist/server/application/document-service.d.ts +68 -0
  89. package/dist/server/application/document-service.js +120 -0
  90. package/dist/server/application/extension-ui-service.d.ts +44 -0
  91. package/dist/server/application/extension-ui-service.js +135 -0
  92. package/dist/server/application/feishu-service.d.ts +179 -0
  93. package/dist/server/application/feishu-service.js +358 -0
  94. package/dist/server/application/group-chat-service.d.ts +75 -0
  95. package/dist/server/application/group-chat-service.js +953 -0
  96. package/dist/server/application/group-execution.d.ts +15 -0
  97. package/dist/server/application/group-execution.js +77 -0
  98. package/dist/server/application/project-service.d.ts +464 -0
  99. package/dist/server/application/project-service.js +2523 -0
  100. package/dist/server/application/provider-service.d.ts +174 -0
  101. package/dist/server/application/provider-service.js +510 -0
  102. package/dist/server/application/run-service.d.ts +547 -0
  103. package/dist/server/application/run-service.js +2683 -0
  104. package/dist/server/application/scheduled-task-service.d.ts +184 -0
  105. package/dist/server/application/scheduled-task-service.js +391 -0
  106. package/dist/server/application/session-orchestrator-service.d.ts +388 -0
  107. package/dist/server/application/session-orchestrator-service.js +1146 -0
  108. package/dist/server/application/session-reminder-service.d.ts +59 -0
  109. package/dist/server/application/session-reminder-service.js +141 -0
  110. package/dist/server/application/session-watchdog.d.ts +171 -0
  111. package/dist/server/application/session-watchdog.js +284 -0
  112. package/dist/server/application/workspace-service.d.ts +52 -0
  113. package/dist/server/application/workspace-service.js +186 -0
  114. package/dist/server/application/worktree-service.d.ts +13 -0
  115. package/dist/server/application/worktree-service.js +76 -0
  116. package/dist/server/browser-access.d.ts +34 -0
  117. package/dist/server/browser-access.js +89 -0
  118. package/dist/server/capability.d.ts +105 -0
  119. package/dist/server/capability.js +170 -0
  120. package/dist/server/command-handler.d.ts +93 -0
  121. package/dist/server/command-handler.js +540 -0
  122. package/dist/server/content-search.d.ts +16 -0
  123. package/dist/server/content-search.js +235 -0
  124. package/dist/server/conversation-usage.d.ts +22 -0
  125. package/dist/server/conversation-usage.js +43 -0
  126. package/dist/server/documents.d.ts +152 -0
  127. package/dist/server/documents.js +998 -0
  128. package/dist/server/engineering-learning.d.ts +30 -0
  129. package/dist/server/engineering-learning.js +106 -0
  130. package/dist/server/exec-service.d.ts +45 -0
  131. package/dist/server/exec-service.js +167 -0
  132. package/dist/server/explicit-file-open.d.ts +34 -0
  133. package/dist/server/explicit-file-open.js +105 -0
  134. package/dist/server/failure-text.d.ts +18 -0
  135. package/dist/server/failure-text.js +44 -0
  136. package/dist/server/feishu-cli.d.ts +223 -0
  137. package/dist/server/feishu-cli.js +464 -0
  138. package/dist/server/file-changes.d.ts +119 -0
  139. package/dist/server/file-changes.js +280 -0
  140. package/dist/server/file-diff.d.ts +41 -0
  141. package/dist/server/file-diff.js +97 -0
  142. package/dist/server/file-index.d.ts +100 -0
  143. package/dist/server/file-index.js +296 -0
  144. package/dist/server/file-name-index.d.ts +160 -0
  145. package/dist/server/file-name-index.js +411 -0
  146. package/dist/server/files.d.ts +269 -0
  147. package/dist/server/files.js +748 -0
  148. package/dist/server/git.d.ts +245 -0
  149. package/dist/server/git.js +903 -0
  150. package/dist/server/http-server.d.ts +45 -0
  151. package/dist/server/http-server.js +3830 -0
  152. package/dist/server/index.d.ts +1 -0
  153. package/dist/server/index.js +485 -0
  154. package/dist/server/inline-thinking.d.ts +90 -0
  155. package/dist/server/inline-thinking.js +181 -0
  156. package/dist/server/json-comments.d.ts +14 -0
  157. package/dist/server/json-comments.js +71 -0
  158. package/dist/server/knowledge-embedding-worker.d.ts +1 -0
  159. package/dist/server/knowledge-embedding-worker.js +27 -0
  160. package/dist/server/knowledge-vectors.d.ts +150 -0
  161. package/dist/server/knowledge-vectors.js +385 -0
  162. package/dist/server/knowledge.d.ts +273 -0
  163. package/dist/server/knowledge.js +848 -0
  164. package/dist/server/length-continuation.d.ts +83 -0
  165. package/dist/server/length-continuation.js +118 -0
  166. package/dist/server/logging.d.ts +32 -0
  167. package/dist/server/logging.js +185 -0
  168. package/dist/server/managed-http-tunnel.d.ts +6 -0
  169. package/dist/server/managed-http-tunnel.js +85 -0
  170. package/dist/server/managed-http.d.ts +4 -0
  171. package/dist/server/managed-http.js +85 -0
  172. package/dist/server/managed-model-adapter.d.ts +17 -0
  173. package/dist/server/managed-model-adapter.js +75 -0
  174. package/dist/server/managed-model-gateway.d.ts +49 -0
  175. package/dist/server/managed-model-gateway.js +73 -0
  176. package/dist/server/managed-servers.d.ts +55 -0
  177. package/dist/server/managed-servers.js +396 -0
  178. package/dist/server/managed-ssh.d.ts +26 -0
  179. package/dist/server/managed-ssh.js +73 -0
  180. package/dist/server/manager-vault.d.ts +11 -0
  181. package/dist/server/manager-vault.js +67 -0
  182. package/dist/server/memory-recall.d.ts +25 -0
  183. package/dist/server/memory-recall.js +45 -0
  184. package/dist/server/memory.d.ts +67 -0
  185. package/dist/server/memory.js +216 -0
  186. package/dist/server/message-media.d.ts +7 -0
  187. package/dist/server/message-media.js +54 -0
  188. package/dist/server/model-context-window.d.ts +186 -0
  189. package/dist/server/model-context-window.js +444 -0
  190. package/dist/server/model-filter.d.ts +23 -0
  191. package/dist/server/model-filter.js +48 -0
  192. package/dist/server/models-store.d.ts +36 -0
  193. package/dist/server/models-store.js +132 -0
  194. package/dist/server/native-tool-settings.d.ts +25 -0
  195. package/dist/server/native-tool-settings.js +41 -0
  196. package/dist/server/native-tools-extension.d.ts +2 -0
  197. package/dist/server/native-tools-extension.js +39 -0
  198. package/dist/server/native-tools-service.d.ts +39 -0
  199. package/dist/server/native-tools-service.js +240 -0
  200. package/dist/server/persistence/app-state-repository.d.ts +65 -0
  201. package/dist/server/persistence/app-state-repository.js +1 -0
  202. package/dist/server/persistence/json-state-repository.d.ts +14 -0
  203. package/dist/server/persistence/json-state-repository.js +43 -0
  204. package/dist/server/persistence/open-state-store.d.ts +3 -0
  205. package/dist/server/persistence/open-state-store.js +35 -0
  206. package/dist/server/persistence/rename.d.ts +22 -0
  207. package/dist/server/persistence/rename.js +44 -0
  208. package/dist/server/persistence/sqlite-state-repository.d.ts +12 -0
  209. package/dist/server/persistence/sqlite-state-repository.js +264 -0
  210. package/dist/server/pi-command.d.ts +94 -0
  211. package/dist/server/pi-command.js +265 -0
  212. package/dist/server/pi-native.d.ts +12 -0
  213. package/dist/server/pi-native.js +16 -0
  214. package/dist/server/pi-session-events.d.ts +158 -0
  215. package/dist/server/pi-session-events.js +373 -0
  216. package/dist/server/pi-session-pool.d.ts +233 -0
  217. package/dist/server/pi-session-pool.js +382 -0
  218. package/dist/server/pi-session.d.ts +642 -0
  219. package/dist/server/pi-session.js +655 -0
  220. package/dist/server/presentations/schema.d.ts +120 -0
  221. package/dist/server/presentations/schema.js +128 -0
  222. package/dist/server/provider-network.d.ts +16 -0
  223. package/dist/server/provider-network.js +106 -0
  224. package/dist/server/provider-proxy.d.ts +18 -0
  225. package/dist/server/provider-proxy.js +200 -0
  226. package/dist/server/providers.d.ts +333 -0
  227. package/dist/server/providers.js +989 -0
  228. package/dist/server/remote-bootstrap.d.ts +17 -0
  229. package/dist/server/remote-bootstrap.js +119 -0
  230. package/dist/server/rpc-channel.d.ts +131 -0
  231. package/dist/server/rpc-channel.js +135 -0
  232. package/dist/server/runtime.d.ts +1393 -0
  233. package/dist/server/runtime.js +3286 -0
  234. package/dist/server/scheduled-tasks.d.ts +101 -0
  235. package/dist/server/scheduled-tasks.js +138 -0
  236. package/dist/server/server-context.d.ts +119 -0
  237. package/dist/server/server-context.js +1 -0
  238. package/dist/server/session-cwd.d.ts +19 -0
  239. package/dist/server/session-cwd.js +58 -0
  240. package/dist/server/session-ledger.d.ts +67 -0
  241. package/dist/server/session-ledger.js +76 -0
  242. package/dist/server/session-memory-scope.d.ts +4 -0
  243. package/dist/server/session-memory-scope.js +30 -0
  244. package/dist/server/session-repository.d.ts +100 -0
  245. package/dist/server/session-repository.js +246 -0
  246. package/dist/server/session-tree-scope.d.ts +125 -0
  247. package/dist/server/session-tree-scope.js +337 -0
  248. package/dist/server/skills.d.ts +23 -0
  249. package/dist/server/skills.js +190 -0
  250. package/dist/server/store.d.ts +1062 -0
  251. package/dist/server/store.js +3305 -0
  252. package/dist/server/subagent-runs.d.ts +185 -0
  253. package/dist/server/subagent-runs.js +383 -0
  254. package/dist/server/subagents.d.ts +200 -0
  255. package/dist/server/subagents.js +619 -0
  256. package/dist/server/task-tool.d.ts +282 -0
  257. package/dist/server/task-tool.js +507 -0
  258. package/dist/server/tavily.d.ts +32 -0
  259. package/dist/server/tavily.js +136 -0
  260. package/dist/server/team-context.d.ts +12 -0
  261. package/dist/server/team-context.js +180 -0
  262. package/dist/server/terminal.d.ts +163 -0
  263. package/dist/server/terminal.js +557 -0
  264. package/dist/server/thinking-level-discovery.d.ts +38 -0
  265. package/dist/server/thinking-level-discovery.js +183 -0
  266. package/dist/server/time-zone.d.ts +20 -0
  267. package/dist/server/time-zone.js +32 -0
  268. package/dist/server/tool-calls.d.ts +130 -0
  269. package/dist/server/tool-calls.js +341 -0
  270. package/dist/server/tool-llm.d.ts +72 -0
  271. package/dist/server/tool-llm.js +146 -0
  272. package/dist/server/tool-registry.d.ts +129 -0
  273. package/dist/server/tool-registry.js +249 -0
  274. package/dist/server/tool-runner.d.ts +112 -0
  275. package/dist/server/tool-runner.js +306 -0
  276. package/dist/server/turn-failure.d.ts +48 -0
  277. package/dist/server/turn-failure.js +148 -0
  278. package/dist/server/types.d.ts +2315 -0
  279. package/dist/server/types.js +11 -0
  280. package/dist/server/update-status.d.ts +14 -0
  281. package/dist/server/update-status.js +69 -0
  282. package/dist/server/update.d.ts +46 -0
  283. package/dist/server/update.js +104 -0
  284. package/dist/server/upload.d.ts +35 -0
  285. package/dist/server/upload.js +177 -0
  286. package/dist/server/version.d.ts +33 -0
  287. package/dist/server/version.js +111 -0
  288. package/dist/server/web.d.ts +27 -0
  289. package/dist/server/web.js +183 -0
  290. package/dist/server/workflow-engine.d.ts +47 -0
  291. package/dist/server/workflow-engine.js +255 -0
  292. package/dist/server/workflow.d.ts +329 -0
  293. package/dist/server/workflow.js +469 -0
  294. package/dist/server/workspace-file-indexes.d.ts +2 -0
  295. package/dist/server/workspace-file-indexes.js +61 -0
  296. package/dist/server/workspace-file-operations.d.ts +36 -0
  297. package/dist/server/workspace-file-operations.js +281 -0
  298. package/dist/server/workspace-file-response.d.ts +7 -0
  299. package/dist/server/workspace-file-response.js +79 -0
  300. package/dist/server/ws-server.d.ts +149 -0
  301. package/dist/server/ws-server.js +640 -0
  302. package/dist/shared/agent-order.d.ts +44 -0
  303. package/dist/shared/agent-order.js +50 -0
  304. package/dist/shared/archive-decisions.d.ts +44 -0
  305. package/dist/shared/archive-decisions.js +98 -0
  306. package/dist/shared/background-task.d.ts +25 -0
  307. package/dist/shared/background-task.js +183 -0
  308. package/dist/shared/child-session-lock.d.ts +37 -0
  309. package/dist/shared/child-session-lock.js +59 -0
  310. package/dist/shared/content-search.d.ts +22 -0
  311. package/dist/shared/content-search.js +1 -0
  312. package/dist/shared/conversation-title.d.ts +4 -0
  313. package/dist/shared/conversation-title.js +4 -0
  314. package/dist/shared/file-mentions.d.ts +17 -0
  315. package/dist/shared/file-mentions.js +91 -0
  316. package/dist/shared/git-commit.d.ts +11 -0
  317. package/dist/shared/git-commit.js +1 -0
  318. package/dist/shared/git-graph.d.ts +42 -0
  319. package/dist/shared/git-graph.js +30 -0
  320. package/dist/shared/group-chat.d.ts +132 -0
  321. package/dist/shared/group-chat.js +6 -0
  322. package/dist/shared/managed-servers.d.ts +36 -0
  323. package/dist/shared/managed-servers.js +1 -0
  324. package/dist/shared/message-media.d.ts +12 -0
  325. package/dist/shared/message-media.js +27 -0
  326. package/dist/shared/model-window-label.d.ts +39 -0
  327. package/dist/shared/model-window-label.js +55 -0
  328. package/dist/shared/native-tools.d.ts +43 -0
  329. package/dist/shared/native-tools.js +1 -0
  330. package/dist/shared/pi-cache-warming.d.ts +9 -0
  331. package/dist/shared/pi-cache-warming.js +4 -0
  332. package/dist/shared/project-overview.d.ts +107 -0
  333. package/dist/shared/project-overview.js +92 -0
  334. package/dist/shared/project-presentation.d.ts +55 -0
  335. package/dist/shared/project-presentation.js +111 -0
  336. package/dist/shared/provider-network.d.ts +30 -0
  337. package/dist/shared/provider-network.js +1 -0
  338. package/dist/shared/session-reporting.d.ts +40 -0
  339. package/dist/shared/session-reporting.js +97 -0
  340. package/dist/shared/session-search.d.ts +14 -0
  341. package/dist/shared/session-search.js +1 -0
  342. package/dist/shared/team-context-view.d.ts +33 -0
  343. package/dist/shared/team-context-view.js +49 -0
  344. package/dist/shared/team-context.d.ts +59 -0
  345. package/dist/shared/team-context.js +3 -0
  346. package/dist/shared/terminal-protocol.d.ts +71 -0
  347. package/dist/shared/terminal-protocol.js +1 -0
  348. package/dist/shared/thinking-levels.d.ts +53 -0
  349. package/dist/shared/thinking-levels.js +85 -0
  350. package/dist/shared/tool-glyph.d.ts +7 -0
  351. package/dist/shared/tool-glyph.js +19 -0
  352. package/dist/shared/transcript-order.d.ts +7 -0
  353. package/dist/shared/transcript-order.js +12 -0
  354. package/dist/shared/update-status.d.ts +28 -0
  355. package/dist/shared/update-status.js +1 -0
  356. package/dist/shared/workspace-file-preview.d.ts +4 -0
  357. package/dist/shared/workspace-file-preview.js +28 -0
  358. package/package.json +450 -4
  359. package/scripts/diagnose.mjs +603 -0
  360. package/scripts/patch-brace-expansion.mjs +260 -0
  361. package/scripts/restart-server.mjs +104 -0
  362. package/skills/presentation/SKILL.md +30 -0
  363. package/skills/presentation/references/data.md +10 -0
  364. package/skills/presentation/references/quality.md +12 -0
  365. package/skills/presentation/references/story.md +12 -0
  366. package/skills/presentation/references/templates-and-editing.md +11 -0
  367. package/skills/presentation/references/visual-system.md +10 -0
  368. package/skills/super-pi-agent-development/SKILL.md +25 -0
  369. package/skills/super-pi-development/SKILL.md +31 -0
  370. package/skills/super-pi-tool-development/SKILL.md +39 -0
@@ -0,0 +1,15 @@
1
+ import type { GroupExecutionActivity, GroupExecutionTrace } from "../../shared/group-chat.js";
2
+ import type { IsolatedExecutionEvent } from "../runtime.js";
3
+ export declare function finishGroupExecution(trace: GroupExecutionTrace): GroupExecutionTrace;
4
+ export declare class GroupExecutionRecorder {
5
+ private sequence;
6
+ private thinkingChars;
7
+ private currentThinking?;
8
+ private changed;
9
+ readonly trace: GroupExecutionTrace;
10
+ get revision(): number;
11
+ get activity(): GroupExecutionActivity | undefined;
12
+ private add;
13
+ private endThinking;
14
+ record(event: IsolatedExecutionEvent): boolean;
15
+ }
@@ -0,0 +1,77 @@
1
+ const MAX_STEPS = 48;
2
+ const MAX_THINKING_CHARS = 8000;
3
+ export function finishGroupExecution(trace) {
4
+ return { ...trace, steps: trace.steps.map(step => step.status === "running" ? { ...step, status: "interrupted" } : step) };
5
+ }
6
+ export class GroupExecutionRecorder {
7
+ sequence = 0;
8
+ thinkingChars = 0;
9
+ currentThinking;
10
+ changed = 0;
11
+ trace = { steps: [] };
12
+ get revision() { return this.changed; }
13
+ get activity() {
14
+ const tool = this.trace.steps.filter(step => step.kind === "tool" && step.status === "running").at(-1);
15
+ if (tool?.kind === "tool")
16
+ return { kind: "tool", name: tool.name, detail: tool.detail };
17
+ return this.currentThinking ? { kind: "thinking" } : undefined;
18
+ }
19
+ add(step) {
20
+ if (this.trace.steps.length === MAX_STEPS) {
21
+ const settled = this.trace.steps.findIndex(item => item.status !== "running");
22
+ this.trace.steps.splice(Math.max(settled, 0), 1);
23
+ this.trace.truncated = true;
24
+ }
25
+ this.trace.steps.push(step);
26
+ }
27
+ endThinking() {
28
+ if (!this.currentThinking)
29
+ return false;
30
+ this.currentThinking.status = "completed";
31
+ this.currentThinking = undefined;
32
+ return true;
33
+ }
34
+ record(event) {
35
+ if (event.kind === "thinking" && event.phase === "end") {
36
+ if (!this.endThinking())
37
+ return false;
38
+ }
39
+ else if (event.kind === "thinking") {
40
+ if (!this.currentThinking) {
41
+ this.currentThinking = { kind: "thinking", id: `thinking:${++this.sequence}`, startedAt: new Date().toISOString(), text: "", status: "running" };
42
+ this.add(this.currentThinking);
43
+ }
44
+ if (event.delta) {
45
+ const retained = event.delta.slice(0, MAX_THINKING_CHARS - this.thinkingChars);
46
+ if (!retained && this.trace.truncated)
47
+ return false;
48
+ this.currentThinking.text += retained;
49
+ this.thinkingChars += retained.length;
50
+ if (retained.length !== event.delta.length)
51
+ this.trace.truncated = true;
52
+ }
53
+ }
54
+ else {
55
+ const { name, detail, status, durationMs } = event.call;
56
+ const id = `tool:${event.call.id}`;
57
+ let step = this.trace.steps.find((item) => item.kind === "tool" && item.id === id);
58
+ const at = new Date().toISOString();
59
+ if (event.phase === "start")
60
+ this.endThinking();
61
+ if (!step) {
62
+ step = { kind: "tool", id, name, detail, startedAt: at, status: "running" };
63
+ this.add(step);
64
+ }
65
+ if (detail)
66
+ step.detail = detail;
67
+ if (event.phase === "update")
68
+ step.lastUpdateAt = at;
69
+ if (event.phase === "end") {
70
+ step.status = status === "error" ? "failed" : "completed";
71
+ step.durationMs = durationMs;
72
+ }
73
+ }
74
+ this.changed += 1;
75
+ return true;
76
+ }
77
+ }
@@ -0,0 +1,464 @@
1
+ import type { Store } from "../store.js";
2
+ import type { Project, ProjectEscalation, ProjectMode, ProjectReport, ProjectRisk, ProjectSummary, ProjectTask, SessionProfile } from "../types.js";
3
+ import type { SessionOrchestratorService } from "./session-orchestrator-service.js";
4
+ /**
5
+ * WHAT THE PROJECT LEADER IS TOLD WHEN IT STARTS.
6
+ *
7
+ * The two prompts are kept apart on purpose. The standard one is the shape the project flow has
8
+ * always had - decompose, delegate, review. The lightweight one is a different set of
9
+ * instructions about a different shape: one session, no decomposition, no reviewer. Writing one
10
+ * prompt with holes in it would mean every sentence had to carry a condition, and the model would
11
+ * have to work out which shape it was in.
12
+ *
13
+ * THE ESCALATION RULE IS SAID ONCE, IN ONE VOICE. The standard leader used to be told two
14
+ * opposite things about the same event - "your subordinates' escalations come to you first, you
15
+ * decide whether to handle them yourself or report them up" AND "you must not resolve escalations
16
+ * yourself" - and a model reading both has no way to pick, so it hesitates between them. The
17
+ * rule is now one sentence with three parts: handle it at your own level, escalate only what
18
+ * really needs the Boss, and never decide for the Boss or drop an escalation. The lightweight
19
+ * leader has no subordinates at all, so it is told the second half only - it must not decide
20
+ * alone either - and is never told about subordinates it does not have.
21
+ */
22
+ export declare const STANDARD_LEADER_PROMPT = "\u4F60\u662F\u8D1F\u8D23\u9879\u76EE\u534F\u8C03\u7684 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\u6CBF\u6C47\u62A5\u7EBF\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\u672C\u5C42\u89E3\u51B3\u4E0D\u4E86\u7684\u95EE\u9898\u624D\u7528 escalate\uFF1A\u6709\u7236\u4F1A\u8BDD\u5C31\u4EA4\u7ED9\u76F4\u5C5E\u7236\u4F1A\u8BDD\uFF0C\u7531\u5B83\u5224\u65AD\u548C\u8F6C\u8FF0\uFF1B\u53EA\u6709\u9876\u5C42\u4F1A\u8BDD\u624D\u628A\u786E\u9700\u7528\u6237\u51B3\u5B9A\u7684\u95EE\u9898\u4EA4\u7ED9\u7528\u6237\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\u8D1F\u8D23\u9879\u76EE\u534F\u8C03\u7684 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\u672C\u5C42\u89E3\u51B3\u4E0D\u4E86\u7684\u4E8B\u624D\u7528 escalate\uFF1A\u6709\u7236\u4F1A\u8BDD\u5C31\u4EA4\u7ED9\u76F4\u5C5E\u7236\u4F1A\u8BDD\uFF0C\u7531\u5B83\u5224\u65AD\u548C\u8F6C\u8FF0\uFF1B\u53EA\u6709\u9876\u5C42\u4F1A\u8BDD\u624D\u628A\u786E\u9700\u7528\u6237\u51B3\u5B9A\u7684\u95EE\u9898\u4EA4\u7ED9\u7528\u6237\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
+ export declare const profile: (value: unknown, label: string) => SessionProfile | undefined;
25
+ export declare const mergeProfile: (taskProfile?: SessionProfile, projectDefault?: SessionProfile) => SessionProfile | undefined;
26
+ /**
27
+ * THE PROJECTS ONE LIST CALL ANSWERS WITH, AND HOW MANY THERE REALLY ARE.
28
+ *
29
+ * `projects` is the capped list, newest update first. `total` is how many projects the session
30
+ * is related to, counted BEFORE the cap, and `returned` is how many of them are in the list.
31
+ */
32
+ export type ProjectListPage = {
33
+ projects: ProjectSummary[];
34
+ total: number;
35
+ returned: number;
36
+ };
37
+ export type CreateProjectInput = {
38
+ sharedContext?: unknown;
39
+ workspaceId: string;
40
+ title: string;
41
+ objective: string;
42
+ deliverables?: unknown;
43
+ acceptanceCriteria?: unknown;
44
+ constraints?: unknown;
45
+ risk?: ProjectRisk | (string & {});
46
+ ownerConversationId?: string;
47
+ defaultLeaderProfile?: unknown;
48
+ defaultExecutorProfile?: unknown;
49
+ defaultReviewerProfile?: unknown;
50
+ initiatorConversationId?: string;
51
+ /** "standard" (the default) or "lightweight" - the small project's shape, where the project
52
+ * leader session does the work itself and no independent reviewer session exists. */
53
+ mode?: ProjectMode;
54
+ };
55
+ export type AddTaskInput = Partial<ProjectTask> & {
56
+ sharedContext?: unknown;
57
+ title: string;
58
+ objective: string;
59
+ executorProfile?: unknown;
60
+ reviewerProfile?: unknown;
61
+ };
62
+ /** A top-level task an initiator hands over with create, before the service gives it an ID. */
63
+ export type TopLevelTaskPlan = {
64
+ title: string;
65
+ objective: string;
66
+ deliverables?: string[];
67
+ acceptanceCriteria?: string[];
68
+ priority?: ProjectTask["priority"];
69
+ dependencies: string[];
70
+ ownedPaths?: string[];
71
+ readOnly?: boolean;
72
+ handoffNote?: string;
73
+ };
74
+ /**
75
+ * HOW THE SERVICE ASKS WHAT AN AGENT ID IS.
76
+ *
77
+ * The employee rule is a fact about the agent DIRECTORY, so the directory is read through the one
78
+ * reader the server already has (`readAgents`, through `agentModeOf`), and the question is asked of
79
+ * whoever owns those directories. The service deliberately does not know where the definitions
80
+ * live: the directories change when the user adds one, and a service that kept its own copy of the
81
+ * path would answer about a directory that is no longer there.
82
+ *
83
+ * `undefined` means "no such agent" - NOT "not primary". An id that is in no directory is a custom
84
+ * agent, and §3 keeps custom agents legal.
85
+ */
86
+ export type AgentModeLookup = {
87
+ agentModeOf(agentId: string): Promise<"primary" | "subagent" | undefined>;
88
+ };
89
+ /** Persist explicit domain fields only; transport credentials never enter project records. */
90
+ export declare class ProjectService {
91
+ private readonly store;
92
+ private readonly orchestrator?;
93
+ /**
94
+ * Optional on purpose: a service built without an agent directory cannot tell a subagent from a
95
+ * custom agent, and it then behaves exactly as it did before this check existed. The real
96
+ * server always passes one.
97
+ */
98
+ private readonly agents?;
99
+ private readonly queues;
100
+ constructor(store: Store, orchestrator?: (Pick<SessionOrchestratorService, "spawn" | "dispatch" | "notifyChildCompleted"> & Partial<Pick<SessionOrchestratorService, "stopSubtree">>) | undefined,
101
+ /**
102
+ * Optional on purpose: a service built without an agent directory cannot tell a subagent from a
103
+ * custom agent, and it then behaves exactly as it did before this check existed. The real
104
+ * server always passes one.
105
+ */
106
+ agents?: AgentModeLookup | undefined);
107
+ private publishContext;
108
+ shareContext(id: string, value: unknown, workspaceId: string, actor?: string): Promise<unknown>;
109
+ messageTask(id: string, taskId: string, content: string, workspaceId: string, actor?: string, targetConversationId?: string, deliveryMode?: string): Promise<unknown>;
110
+ /**
111
+ * A SUPERVISOR'S MESSAGE IS THE ANSWER TO THE EXCEPTION - NOT A FORMAL RULING.
112
+ *
113
+ * The reader's complaint was that a session kept saying 「等上面拍板」 long after the question
114
+ * had been settled in a real conversation: the supervisor had talked it through with the member
115
+ * and sent the follow-up instruction, and the platform was still waiting for a ceremony nobody
116
+ * had asked for. Communication is higher than protocol - when the supervisor the case is
117
+ * addressed to writes back to the member who raised it, the case IS answered.
118
+ *
119
+ * TWO THINGS ARE KEPT APART ON PURPOSE.
120
+ * - THE RECORD STAYS. The exception keeps its place in `p.escalations` with the answer, who
121
+ * answered and when. A decision record must not disappear when the project is cancelled.
122
+ * - THE STATE CHANGES. The session no longer says 「等上面拍板」, because nobody is waiting for
123
+ * anything any more: the answer is already on the member's desk.
124
+ *
125
+ * WHAT IS NOT SETTLED HERE, AND WHY:
126
+ * - A BOSS-LEVEL EXCEPTION IS NEVER SETTLED BY A MESSAGE. That case asks the Boss himself, and
127
+ * no team member has the authority to answer it - `resolveEscalation` enforces the very same
128
+ * rule for the panel and the tool, and it must hold for a message too.
129
+ * - A RETURNED EXCEPTION IS NOT REVIVED BY A MESSAGE. A returned case means the member was
130
+ * asked for more material; that material comes back as a NEW exception, not as the old one
131
+ * coming back to life.
132
+ * - ONLY THE DESIGNATED DIRECT SUPERVISOR ANSWERS. `targetConversationId` is the supervisor
133
+ * the case is addressed to, so a message from anybody else is somebody else's business.
134
+ * - AND THE REPLY HAS TO REACH THE MEMBER WHO RAISED IT. A supervisor who writes to somebody
135
+ * else has not answered this case, and settling it would repeat the mistake this project
136
+ * already made once: one answer closing every case of that member at once.
137
+ */
138
+ private settleEscalationsByMessage;
139
+ getContext(id: string | undefined, workspaceId: string, actor?: string, taskId?: string, contextIds?: unknown): unknown;
140
+ private coordinationHints;
141
+ private assertWriteScope;
142
+ private taskCoordination;
143
+ private captureHandoff;
144
+ private dispatchContext;
145
+ private syncDeliveryContext;
146
+ private dispatchReceipt;
147
+ /**
148
+ * A PROJECT EMPLOYEE MUST BE A PRIMARY AGENT.
149
+ *
150
+ * §1 says a subagent cannot be a project employee: a subagent is a tool-level, one-shot,
151
+ * invisible call, and a project that leans on one leans on a role the user can never see and
152
+ * never interrupt. The client only offers primary agents in the candidate list, but a candidate
153
+ * list is a SUGGESTION - the server is the constraint, and the refusal belongs at the moment the
154
+ * profile is written, while the reader is still looking at the form. Refusing later (when the
155
+ * task is dispatched) teaches the reader that the panel accepted something the project cannot
156
+ * use.
157
+ *
158
+ * WHAT IS REFUSED, AND WHAT IS NOT. An agent that EXISTS and is a subagent is refused, and the
159
+ * message names the slot and the agent, so the reader knows WHICH employee to change. An id that
160
+ * is in NO directory is a custom agent, and §3 keeps custom agents legal - so it is accepted here,
161
+ * exactly as it was before this check existed.
162
+ */
163
+ private assertEmployee;
164
+ static taskView(task: ProjectTask, project: Pick<Project, "defaultExecutorProfile" | "defaultReviewerProfile">): ProjectTask;
165
+ private filterEscalations;
166
+ private projectView;
167
+ private raw;
168
+ private workspace;
169
+ private event;
170
+ private change;
171
+ private live;
172
+ /**
173
+ * WAKING THE OTHER SIDE MUST NOT TAKE THE REPORT DOWN WITH IT.
174
+ *
175
+ * The report, the escalation or the decision is already written to the store by the time the
176
+ * other side is woken, so a dispatch that fails - a session that was archived, stopped or never
177
+ * existed - must NOT fail the request. It would: the caller would be told the whole thing
178
+ * failed although it succeeded, it would try again, and the same report would be written twice.
179
+ *
180
+ * So the wake is wrapped, the failure is written down, and the record is returned as the
181
+ * success it is.
182
+ *
183
+ * AND THE FAILURE IS NOT SILENT. A report nobody was told about is a report nobody will ever
184
+ * handle, so the project's own timeline gets an event saying exactly that, and the log line
185
+ * names the project and the escalation so the case can be found again later.
186
+ */
187
+ private wake;
188
+ /** THE TIMELINE SAYS THAT NOBODY COULD BE TOLD. Written after the fact, so it never loses the
189
+ * record that was already saved. */
190
+ private noteUnreachable;
191
+ private leader;
192
+ /**
193
+ * IS THE SESSION THAT WAS SUPPOSED TO BE RUNNING A TASK STILL THERE?
194
+ *
195
+ * "Still there" means three things, and all three are checked against the SESSION'S OWN RECORD,
196
+ * never against a message the project service was handed:
197
+ *
198
+ * - the record is gone: the session was deleted, or it never existed;
199
+ * - the record says `failed`: the turn died (an unhandled error, or the server was killed
200
+ * mid-turn and the startup sweep marked the record failed);
201
+ * - the record says `stopped`: the session was stopped.
202
+ *
203
+ * WHAT IS NOT "GONE" IS AS IMPORTANT. A session that is `idle` or `completed` is ALIVE: it
204
+ * finished its turn and it can be dispatched again, and in the project flow the leader is woken
205
+ * by exactly that report. Calling an alive session "gone" would light up the whole panel for a
206
+ * worker that is simply between turns.
207
+ *
208
+ * The moment the session died is returned with the verdict, because that moment is what tells a
209
+ * death BEFORE the task was dispatched from a death AFTER it. Only the second one interrupted
210
+ * the task.
211
+ */
212
+ private goneSession;
213
+ /**
214
+ * ONE SENTENCE THAT SAYS WHAT HAPPENED, for the reader of the panel.
215
+ *
216
+ * The session's own failure reason is the most specific thing there is - the startup sweep
217
+ * writes "the server died while this task was running, it has been marked failed" into it - so
218
+ * the first sentence of that reason is used when there is one. Otherwise the verdict alone is
219
+ * said, in the same words the reader has seen everywhere else.
220
+ */
221
+ private interruptedReason;
222
+ /**
223
+ * THE PROJECT IS TOLD THE TRUTH ABOUT ITS OWN TASKS.
224
+ *
225
+ * A task says 「执行中」 only while there is something running for it. When the execution session
226
+ * is gone - the process was killed, the session failed, the session was stopped - the task can
227
+ * never advance on its own, and nobody will ever report back on it. So the task is marked
228
+ * `interrupted`, with the reason attached, and the Boss is handed a way to send it out again.
229
+ *
230
+ * WHY THIS IS DONE WHILE READING, AND NOT WHEN THE SESSION DIES. The runtime could tell the
231
+ * project service that a session ended - but only for the deaths it witnessed. The console was
232
+ * killed by the OS at 05:41 with no shutdown log at all: there was no event to receive, no
233
+ * callback to fire, no chance to be told. Reconciling on READ covers EVERY cause of death -
234
+ * the kill, the network cut, the watchdog, the crash - because it asks the one question that is
235
+ * still answerable afterwards: is the session that was running this task still there?
236
+ *
237
+ * THE DEATH HAS TO HAVE HAPPENED AFTER THE DISPATCH. The moment a task is dispatched, its
238
+ * session is restarted - it goes from `failed` back to `running` a moment later. A task
239
+ * dispatched at T2 while its session died at T1 is a task whose session is on its way back, not
240
+ * a task that was interrupted, so the two moments are compared before the task is marked. The
241
+ * session's own record carries the moment it died; the task carries the moment it was sent out.
242
+ */
243
+ private reconcileInterrupted;
244
+ /**
245
+ * THE STATUS A PROJECT SHOWS WHEN ONE OF ITS TASKS HAS BEEN INTERRUPTED.
246
+ *
247
+ * A project with an interrupted task is not "running": the work that is not finished there is
248
+ * work nobody is doing, and it will stay that way until somebody restarts it. So the project
249
+ * says 「已阻塞」 - the word the panel already uses for "this needs a decision from you" - instead
250
+ * of 「执行中」, which would be a claim that something is running.
251
+ *
252
+ * Only a project that says 「执行中」 is moved: a project that has already been closed, or that is
253
+ * waiting for a review, is saying something else and stays truthful.
254
+ */
255
+ private statusWithInterruptions;
256
+ private topLevelAuthor;
257
+ private manager;
258
+ /**
259
+ * DOES THIS TASK COUNT AS ACCEPTED?
260
+ *
261
+ * In a STANDARD project, acceptance means another session reviewed this delivery: the reviewer
262
+ * of the review must be the session that was spawned to review, and it must NOT be the session
263
+ * that did the work. Those conditions are the whole point of an independent review, so they
264
+ * stand exactly as they were.
265
+ *
266
+ * In a LIGHTWEIGHT project there is no reviewer session at all - the leader session does the
267
+ * work itself - so a delivery is accepted on the executor's own evidence. The flag that says so
268
+ * is written by `submit` and nowhere else, and it names the session that made the call, so a
269
+ * task with no accepted review at all still counts for nothing.
270
+ */
271
+ private taskAccepted;
272
+ private requiredComplete;
273
+ private task;
274
+ private member;
275
+ private canAddressUser;
276
+ isMember(p: Project, actor?: string): boolean;
277
+ directSupervisor(p: Project, actor?: string, taskId?: string): string | undefined;
278
+ /**
279
+ * THE PROJECT A SESSION BELONGS TO RIGHT NOW.
280
+ *
281
+ * `projectForSession` answers a different question - "which project is this session part of" -
282
+ * and it counts the finished projects too, because the history of a project has to stay visible
283
+ * to the people who worked on it. This method answers the narrower question the QUESTION path
284
+ * needs: "is this session inside a project that is still running".
285
+ *
286
+ * WHY THAT DISTINCTION MATTERS. A conversation that took part in a project which has since been
287
+ * completed is not a project member any more - it is a conversation that happens to have a
288
+ * finished project in its history. The old lookup mixed the two, so asking the Boss a question
289
+ * from such a conversation was refused with "a project member may not ask the Boss directly",
290
+ * which is not what was true: the project was over, and nobody was being bypassed. The finished
291
+ * project is still found and still visible in the history; it just does not block the question.
292
+ *
293
+ * A session that is in a running project AND in a finished one belongs to the running one - it
294
+ * is the one that is still in charge of it.
295
+ */
296
+ private liveProjectForSession;
297
+ canAskQuestion(conversationId: string): {
298
+ ok: boolean;
299
+ reason?: string;
300
+ };
301
+ private reconcile;
302
+ private resources;
303
+ list(workspaceId?: string, view?: "current" | "history"): Project[];
304
+ /**
305
+ * IS THE OWNER SESSION IN THE ARCHIVE? A project whose leader was archived has nobody left to
306
+ * run it. The server is the one that knows what is archived, so it computes the answer and
307
+ * hands the client the same fact in the project payload (`ownerArchived`).
308
+ */
309
+ private ownerArchived;
310
+ headline(p: Project, actor?: string, resources?: Project["resources"]): string;
311
+ private activitySessions;
312
+ private isActorRelated;
313
+ private projectSummary;
314
+ /**
315
+ * THE PROJECTS AN ACTOR IS PART OF, AND HOW MANY OF THEM THERE ARE.
316
+ *
317
+ * The list is capped, because the list is what goes into an agent's context: a workspace that
318
+ * has been alive for a year has hundreds of finished projects, and handing all of them over
319
+ * answers the question "how are my projects doing" with a wall of history. The cap is on the
320
+ * RECENT ones - the same order the list has always had, newest update first - so what the
321
+ * agent reads first is what actually changed.
322
+ *
323
+ * AND THE COUNT IS TOLD, NOT IMPLIED. `total` is how many projects the session is really
324
+ * related to, counted BEFORE the cut, and `returned` is how many came back. An agent that sees
325
+ * total 57 and returned 20 knows the workspace has more history than it was shown, and says so
326
+ * instead of telling the Boss the workspace only has 20 projects. A silently truncated list
327
+ * would be a lie the agent could not see through.
328
+ */
329
+ listForActor(workspaceId: string, actor: string, limit?: number): ProjectListPage;
330
+ get(id: string, workspaceId?: string, actor?: string): Project;
331
+ /**
332
+ * THE PROJECT AS A REPORT A HUMAN CAN READ.
333
+ *
334
+ * Everything the panel shows in pieces - the objective, the tasks and who did them, the
335
+ * deliveries and their evidence, the reviews that accepted them, the exceptions and how they
336
+ * were decided - in one piece of Markdown, in reading order.
337
+ *
338
+ * TWO THINGS THIS REPORT REFUSES TO DO. It prints no session handle: a conversation id is a
339
+ * machine address, and a report full of addresses is not something a person can read or paste
340
+ * into a weekly note - the session's own title is used instead. And it prints no credential of
341
+ * any kind: the CONTENT of the tasks, events, reports and exceptions is the report, and a
342
+ * capability or a token that happens to live in a session profile is not content.
343
+ */
344
+ exportReport(id: string, workspaceId?: string): Promise<string>;
345
+ projectForSession(conversationId: string): Project | undefined;
346
+ create(input: CreateProjectInput, initiatorConversationId?: string): Promise<Project>;
347
+ private admission;
348
+ private context;
349
+ start(id: string, workspaceId: string, actor?: string): Promise<Project>;
350
+ addTask(id: string, input: AddTaskInput, workspaceId?: string, actor?: string): Promise<ProjectTask>;
351
+ dispatchTask(id: string, taskId: string, workspaceId: string, actor?: string, sourceContext?: {
352
+ id: string;
353
+ warm: boolean;
354
+ }): Promise<ProjectTask>;
355
+ submit(id: string, taskId: string, input: {
356
+ output?: string;
357
+ evidenceRefs?: string[];
358
+ sharedContext?: unknown;
359
+ }, workspaceId: string, actor?: string): Promise<ProjectTask>;
360
+ requestReview(id: string, taskId: string, workspaceId: string, actor?: string): Promise<ProjectTask>;
361
+ review(id: string, taskId: string, input: {
362
+ verdict?: string;
363
+ summary?: string;
364
+ evidenceRefs?: string[];
365
+ }, workspaceId: string, actor?: string): Promise<ProjectTask>;
366
+ /**
367
+ * THE TASK IS DONE, SO THE LEADER IS WOKEN - AND IT IS NOT TOLD WHAT WAS DONE.
368
+ *
369
+ * The member's work is finished, and the member's direct parent - the Leader - has to hear
370
+ * about it: a Leader that is not told is a Leader that sits there with a finished employee.
371
+ *
372
+ * WHAT THE WAKE CARRIES IS THE TASK'S IDENTITY AND NOTHING ELSE. The delivery, the evidence and
373
+ * the review verdict stay where they are: in the project record and in the member's own
374
+ * session. A platform that wrote the summary here would be writing a report nobody checked, and
375
+ * the Leader is the one who is supposed to look and judge.
376
+ *
377
+ * THE COMPLETION IS THE UNIT, SO THE KNOCK HAPPENS ONCE. A task that is marked complete twice -
378
+ * a retried acceptance - is one piece of work, and the Leader is woken once for it.
379
+ */
380
+ private notifyTaskCompleted;
381
+ updateTask(id: string, taskId: string, patch: Record<string, unknown> & {
382
+ workspaceId?: string;
383
+ }, actor?: string): Promise<ProjectTask>;
384
+ updateStatus(id: string, status: Project["status"], workspaceId?: string): Promise<Project>;
385
+ /**
386
+ * THE SESSION THAT OPENED THE PROJECT MAY CANCEL IT.
387
+ *
388
+ * There is no delete here, and that is deliberate. The project record, its tasks, its events and
389
+ * its evidence references are the trail of what was tried; a project that went nowhere is
390
+ * evidence too. Cancelling stops the work and marks the project cancelled - the record stays,
391
+ * readable, with the reason attached.
392
+ *
393
+ * Only the session that opened the project may do this. A worker or a reviewer that could
394
+ * cancel the project it belongs to would have a way to make its own budget and concurrency
395
+ * guards disappear, and those guards are the only thing between a runaway agent and an
396
+ * unbounded bill. The human path - the panel's stop button - is unchanged and stays the Boss's.
397
+ *
398
+ * A reason is required: "we changed our minds" and "the customer shipped it last night" are
399
+ * different decisions, and the timeline is where that difference has to show up.
400
+ */
401
+ cancel(id: string, body: Record<string, any>, workspaceId: string, actor: string): Promise<Project>;
402
+ addReport(id: string, input: Omit<ProjectReport, "id" | "projectId" | "createdAt"> & {
403
+ sharedContext?: unknown;
404
+ }, workspaceId?: string, actor?: string): Promise<ProjectReport>;
405
+ addEscalation(id: string, input: Pick<ProjectEscalation, "reason" | "severity" | "taskId" | "title">, workspaceId?: string, actor?: string): Promise<ProjectEscalation>;
406
+ /**
407
+ * A DECISION ON A CLOSED PROJECT IS STILL A RECORD - AND A CLOSED PROJECT HAS NOBODY TO WAKE.
408
+ *
409
+ * THE TO-DO MUST NOT BE A DEAD END. `live()` refuses every write on a project that is
410
+ * completed, cancelled or failed, and that guard is right for the paths it protects - it stops
411
+ * a finished project from being quietly worked on again. But a decision is not a change to the
412
+ * work: it is the RECORD of what the reader decided ABOUT the work. The exception is still
413
+ * open, the question it asks is still unanswered, and the answer is worth keeping even when
414
+ * the project itself is over - the reader's own words ("授权我以现有两份独立实测记录结案")
415
+ * are exactly the thing the record is missing.
416
+ *
417
+ * So this path tells the two cases apart EXPLICITLY instead of bumping into the general guard:
418
+ *
419
+ * - the project is over: the decision is written into the exception (status, decision,
420
+ * resolvedAt) and into the timeline, and NOBODY is woken - the whole session tree has
421
+ * stopped, so waking is a gesture at an empty room;
422
+ * - the project is live: everything happens as it always did, including the wake.
423
+ *
424
+ * THE TIMELINE SAYS WHY NOBODY WAS WOKEN. A record that silently skips a step is a record the
425
+ * next reader has to guess about.
426
+ */
427
+ resolveEscalation(id: string, escalationId: string, decision: string, status: "resolved" | "dismissed" | "returned", workspaceId?: string, actor?: string): Promise<ProjectEscalation>;
428
+ private deliveryTasks;
429
+ deliver(id: string, summary: string, evidenceRefs: unknown, workspaceId: string, actor?: string): Promise<Project>;
430
+ /**
431
+ * The tasks an initiator hands over with create. A dependency names the TITLE of another task in
432
+ * the same batch, because the batch carries no task IDs yet - the service assigns them while it
433
+ * registers the batch. The plan comes back in dependency order, so the plain add_task rules
434
+ * (title, objective, priority, sibling dependencies) can be reused unchanged.
435
+ */
436
+ private planTopLevelTasks;
437
+ private registerTopLevelTasks;
438
+ /**
439
+ * THE INITIATOR'S LIMITED CORRECTION RIGHT.
440
+ *
441
+ * The person who opened the project gets exactly two things the Leader's chain does not give
442
+ * them: READ-ONLY SUPERVISION of the whole project (the project's own read surface already
443
+ * shows every member's status to every member), and ONE message to any session inside the
444
+ * project tree - a single correction, delivered to that session directly, without having to go
445
+ * through the Leader and wait for it to be relayed.
446
+ *
447
+ * WHY IT IS BOUNDED BY THREE RULES, AND NOT BY "THE INITIATOR CAN DO WHATEVER":
448
+ *
449
+ * 1. ONLY THE INITIATOR. Every other session in the project keeps the reporting line: a member
450
+ * still reaches its direct supervisor, and the Leader still answers to the initiator. If every
451
+ * member could correct every other member, the tree would stop being a tree.
452
+ * 2. ONLY INSIDE THE PROJECT TREE. The target must be one of this project's sessions - the
453
+ * Leader, a branch Leader, a worker, a reviewer. A session that is not in this project is
454
+ * somebody else's department, and this right says nothing about it.
455
+ * 3. ONE MESSAGE, NOT A CHANNEL. This sends a message; it does not open a line. The reporting
456
+ * line, the escalation path and the parent's dispatch rules are untouched by it.
457
+ */
458
+ correctMember(id: string, targetConversationId: string, content: string, workspaceId: string, actor?: string): Promise<{
459
+ ok: true;
460
+ conversationId: string;
461
+ delivered: true;
462
+ }>;
463
+ tool(body: Record<string, any>, workspaceId: string, actor: string): Promise<unknown>;
464
+ }