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

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 +248 -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 +392 -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 +448 -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,540 @@
1
+ import { spawn } from "node:child_process";
2
+ import { join } from "node:path";
3
+ import { KNOWN_APIS } from "./providers.js";
4
+ import { CHILD_SESSION_LOCK_REASON } from "../shared/child-session-lock.js";
5
+ import { claimUpdateSlot, packageUpdateArgs, releaseUpdateSlot, shellArgs } from "./update.js";
6
+ /**
7
+ * Routes client commands to appropriate application services and converts results or errors.
8
+ */
9
+ export class CommandHandler {
10
+ workspaceService;
11
+ conversationService;
12
+ runService;
13
+ extensionUiService;
14
+ catalogService;
15
+ rootDir;
16
+ providerService;
17
+ scheduledTaskService;
18
+ sessionOrchestratorService;
19
+ /**
20
+ * The built-in terminal service.
21
+ *
22
+ * The service still refuses commands when node-pty is unavailable or the peer is not trusted.
23
+ */
24
+ terminalService;
25
+ constructor(workspaceService, conversationService, runService, extensionUiService, catalogService, terminalService,
26
+ /** Path to the Super Pi repository root, used to spawn the restart script. */
27
+ rootDir,
28
+ /**
29
+ * The providers a person added through the settings window.
30
+ *
31
+ * Optional because the command handler is constructed by tests that do not care about providers,
32
+ * and a missing service has to say so rather than take the whole handler down.
33
+ */
34
+ providerService,
35
+ /**
36
+ * The scheduled tasks, and the clock behind them.
37
+ *
38
+ * Optional because the handler is constructed by tests that have no clock to give it, and a missing
39
+ * service has to say so rather than take the whole handler down - the same rule `providerService`
40
+ * follows.
41
+ */
42
+ scheduledTaskService, sessionOrchestratorService) {
43
+ this.workspaceService = workspaceService;
44
+ this.conversationService = conversationService;
45
+ this.runService = runService;
46
+ this.extensionUiService = extensionUiService;
47
+ this.catalogService = catalogService;
48
+ this.rootDir = rootDir;
49
+ this.providerService = providerService;
50
+ this.scheduledTaskService = scheduledTaskService;
51
+ this.sessionOrchestratorService = sessionOrchestratorService;
52
+ this.terminalService = terminalService;
53
+ }
54
+ /**
55
+ * Processes a client command.
56
+ *
57
+ * `remoteAddress` is passed for the terminal alone. Every other command is authorised by the socket
58
+ * itself, which was already admitted at upgrade; the terminal additionally needs to know WHERE the
59
+ * connection came from, because it is the one command family whose blast radius is the whole machine
60
+ * rather than one workspace. See `TerminalService.handle`.
61
+ */
62
+ /**
63
+ * Takes the reverting claim for a conversation from the moment the command is RECEIVED.
64
+ *
65
+ * A `message.send` runs outside this socket's command queue - deliberately, so a follow-up can be
66
+ * admitted while a turn streams - so it can be handled before a queued `message.revert` has started
67
+ * cutting anything. Calling `isReverting` from the send path then answers "no" to a send that is
68
+ * racing a cut in every sense that matters, and the message lands on a transcript the model still
69
+ * reads in full. The socket layer calls this the moment it parses the revert, which is the only point
70
+ * on this side of the service that is early enough; `releaseRevert` gives the claim back when the
71
+ * command finishes, so a revert that never reaches the service cannot hold the conversation shut.
72
+ */
73
+ claimRevert(conversationId) {
74
+ this.conversationService.claimRevert(conversationId);
75
+ }
76
+ /** The other half of `claimRevert`. Safe to call for a conversation nothing claimed. */
77
+ releaseRevert(conversationId) {
78
+ this.conversationService.releaseRevert(conversationId);
79
+ }
80
+ async handleCommand(command, sendToSocket, remoteAddress, browserAuthorized = false) {
81
+ if ("conversationId" in command && typeof command.conversationId === "string"
82
+ && command.type !== "conversation.warm.delete" && this.conversationService.isWarmSession?.(command.conversationId)) {
83
+ throw new Error("预热快照只能通过项目派发使用");
84
+ }
85
+ if (command.type === "terminal.shell.set") {
86
+ if (!this.terminalService || !(await this.terminalService.setShell(command.command, remoteAddress, browserAuthorized)))
87
+ return;
88
+ return;
89
+ }
90
+ if (command.type === "terminal.sync" || command.type === "terminal.detach" || command.type === "terminal.open" || command.type === "terminal.input" || command.type === "terminal.resize" || command.type === "terminal.close") {
91
+ if (!this.terminalService)
92
+ return;
93
+ await this.terminalService.handle(command, remoteAddress, sendToSocket ?? (() => { }), browserAuthorized);
94
+ return;
95
+ }
96
+ if (command.type === "model.rules.set") {
97
+ await this.catalogService.setModelRules(command.rules);
98
+ return;
99
+ }
100
+ if (command.type === "settings.defaultModel") {
101
+ await this.catalogService.setDefaultModel(command.model);
102
+ return;
103
+ }
104
+ // THE PROVIDERS A PERSON ADDED. The list is answered to the ASKING socket only - it is a panel's
105
+ // private list, and broadcasting it would put a provider's API address in every other tab's state
106
+ // for no gain. The set and the remove broadcast the new list themselves, because everybody who
107
+ // has the settings window open has to see the change.
108
+ if (command.type === "providers.set") {
109
+ if (!this.providerService)
110
+ throw new Error("供应商功能不可用");
111
+ await this.providerService.set(command.provider);
112
+ return;
113
+ }
114
+ if (command.type === "providers.remove") {
115
+ if (!this.providerService)
116
+ throw new Error("供应商功能不可用");
117
+ await this.providerService.remove(command.providerId);
118
+ return;
119
+ }
120
+ if (command.type === "providers.removeModel") {
121
+ if (!this.providerService)
122
+ throw new Error("供应商功能不可用");
123
+ await this.providerService.removeModel(command.providerId, command.modelId);
124
+ return;
125
+ }
126
+ // OFF AND ON. Separate from `providers.remove` because removing is FOREVER - it drops the key -
127
+ // while switching a provider off keeps everything needed to switch it back on. The lapsed
128
+ // subscription is the case this exists for: the provider has to leave the picker, and the person
129
+ // may well renew the plan next month.
130
+ if (command.type === "providers.disable") {
131
+ if (!this.providerService)
132
+ throw new Error("供应商功能不可用");
133
+ await this.providerService.disable(command.providerId);
134
+ return;
135
+ }
136
+ if (command.type === "providers.enable") {
137
+ if (!this.providerService)
138
+ throw new Error("供应商功能不可用");
139
+ await this.providerService.enable(command.providerId);
140
+ return;
141
+ }
142
+ if (command.type === "providers.repair") {
143
+ if (!this.providerService)
144
+ throw new Error("供应商功能不可用");
145
+ await this.providerService.repair();
146
+ return;
147
+ }
148
+ if (command.type === "providers.fetch") {
149
+ if (!this.providerService)
150
+ throw new Error("供应商功能不可用");
151
+ if (sendToSocket)
152
+ sendToSocket({ type: "providers.list", providers: await this.providerService.list(), apis: [...KNOWN_APIS] });
153
+ return;
154
+ }
155
+ if (command.type === "backgroundTask.stop") {
156
+ await this.runService.stopBackgroundTask(command.taskId);
157
+ return;
158
+ }
159
+ if (command.type === "workspace.create") {
160
+ return await this.workspaceService.createWorkspace(command.name, command.path);
161
+ }
162
+ if (command.type === "workspace.rename") {
163
+ await this.workspaceService.renameWorkspace(command.workspaceId, command.name);
164
+ return;
165
+ }
166
+ if (command.type === "workspace.delete") {
167
+ await this.workspaceService.deleteWorkspace(command.workspaceId);
168
+ this.terminalService?.removeWorkspace(command.workspaceId);
169
+ return;
170
+ }
171
+ if (command.type === "workspace.settings") {
172
+ await this.workspaceService.updateSettings(command.workspaceId, {
173
+ model: command.model,
174
+ thinkingLevel: command.thinkingLevel,
175
+ agentId: command.agentId,
176
+ });
177
+ return;
178
+ }
179
+ if (command.type === "workspaces.settings.bulk") {
180
+ await this.workspaceService.updateMountedWorkspaceSettings({
181
+ model: command.model,
182
+ thinkingLevel: command.thinkingLevel,
183
+ });
184
+ return;
185
+ }
186
+ if (command.type === "conversation.create") {
187
+ return await this.conversationService.createConversation(command.workspaceId, undefined, command.cwd);
188
+ }
189
+ if (command.type === "conversation.autoRename") {
190
+ // Answered on a pushed event rather than through the return value: this spends real model time, and
191
+ // `handleCommand`'s return only carries an id for the optimistic-ack path. Swallowing the failure
192
+ // here would turn a model timeout into a menu that closed and never spoke again, so the error goes
193
+ // back on the same channel the success would have used.
194
+ try {
195
+ const title = await this.conversationService.autoRenameConversation(command.conversationId);
196
+ sendToSocket?.({ type: "conversation.autoRename.result", conversationId: command.conversationId, ok: true, title });
197
+ }
198
+ catch (error) {
199
+ sendToSocket?.({ type: "conversation.autoRename.result", conversationId: command.conversationId, ok: false, error: error instanceof Error ? error.message : String(error) });
200
+ }
201
+ return;
202
+ }
203
+ if (command.type === "conversation.select") {
204
+ if (sendToSocket) {
205
+ try {
206
+ sendToSocket({ type: "model.catalog", catalog: await this.conversationService.getConversationCatalog(command.conversationId), conversationId: command.conversationId });
207
+ }
208
+ catch (error) {
209
+ // Keep the permitted choices available so an existing invalid session can be corrected.
210
+ sendToSocket({ type: "model.catalog", catalog: await this.catalogService.getCatalog(undefined, command.conversationId), conversationId: command.conversationId });
211
+ throw error;
212
+ }
213
+ }
214
+ else
215
+ await this.conversationService.selectConversation(command.conversationId);
216
+ return;
217
+ }
218
+ if (command.type === "conversation.collapse") {
219
+ await this.conversationService.setCollapsed(command.conversationId, command.collapsed);
220
+ return;
221
+ }
222
+ // THE LOCK ON A CHILD SESSION'S COMPOSER. The browser asks; the server answers. The state is
223
+ // the server's (`AppState.unlockedChildConversationIds`), so a second tab, a stale window or a
224
+ // hand-written frame all meet the same door.
225
+ if (command.type === "conversation.childLock") {
226
+ await this.conversationService.setChildLock(command.conversationId, command.unlocked);
227
+ return;
228
+ }
229
+ if (command.type === "conversation.archive") {
230
+ await this.conversationService.archiveConversation(command.conversationId);
231
+ return;
232
+ }
233
+ if (command.type === "conversation.unarchive") {
234
+ await this.conversationService.unarchiveConversation(command.conversationId);
235
+ return;
236
+ }
237
+ if (command.type === "conversation.rename") {
238
+ await this.conversationService.renameConversation(command.conversationId, command.name);
239
+ return;
240
+ }
241
+ if (command.type === "conversation.fork") {
242
+ const result = await this.conversationService.forkConversation(command.conversationId);
243
+ if (sendToSocket) {
244
+ sendToSocket({
245
+ type: "conversation.fork.result",
246
+ conversationId: command.conversationId,
247
+ ...result,
248
+ });
249
+ }
250
+ return;
251
+ }
252
+ if (command.type === "conversation.warm.save") {
253
+ if (typeof command.title !== "string")
254
+ throw new Error("请输入预热会话名称");
255
+ const result = await this.conversationService.forkConversation(command.conversationId, { warmTitle: command.title });
256
+ if (!result.ok)
257
+ throw new Error(result.message);
258
+ return;
259
+ }
260
+ if (command.type === "conversation.warm.delete") {
261
+ if (!this.sessionOrchestratorService)
262
+ throw new Error("会话编排服务未就绪");
263
+ await this.sessionOrchestratorService.removeWarmSession(command.conversationId);
264
+ return;
265
+ }
266
+ if (command.type === "conversation.model") {
267
+ await this.conversationService.setModel(command.conversationId, command.provider, command.modelId);
268
+ return;
269
+ }
270
+ if (command.type === "conversation.thinking") {
271
+ await this.conversationService.setThinking(command.conversationId, command.level);
272
+ return;
273
+ }
274
+ if (command.type === "conversation.agent") {
275
+ await this.conversationService.setAgent(command.conversationId, command.agentId);
276
+ return;
277
+ }
278
+ if (command.type === "message.send") {
279
+ const accepted = () => {
280
+ if (command.clientId)
281
+ sendToSocket?.({ type: "message.accepted", conversationId: command.conversationId, clientId: command.clientId });
282
+ };
283
+ if (await this.runService.acknowledgeAcceptedSend?.(command.conversationId, command.clientId)) {
284
+ accepted();
285
+ return;
286
+ }
287
+ // THE LOCK IS NOT ONLY A DRAWING. A child session's composer is locked in the interface, and
288
+ // this is the half that makes the lock real: the reporting line only runs upwards, one level
289
+ // at a time, so the reader does not talk to a child session directly - unless they deliberately
290
+ // opened that one session.
291
+ //
292
+ // The refusal is the server's own sentence, and it is the SAME sentence the lock shows
293
+ // (`src/shared/child-session-lock.ts`): the interface and the server must not disagree about
294
+ // what the rule is, because the reader is the one who has to live with both.
295
+ //
296
+ // The agent's own way up - `session_dispatch` - does NOT come through here: it goes through
297
+ // `enqueueAndRunAsAgent`, which is a different door. A lock on the reader is not a lock on the
298
+ // team.
299
+ if (this.conversationService.childLockState(command.conversationId) === "locked") {
300
+ throw new Error(CHILD_SESSION_LOCK_REASON);
301
+ }
302
+ // A send that races a revert would be appended to a history the model is still reading in full - the
303
+ // turn the person just withdrew would still be in its context, and the new answer would be built on
304
+ // top of it. Refusing with a sentence beats accepting a turn built on a cut that has not landed yet.
305
+ if (this.conversationService.isReverting(command.conversationId)) {
306
+ throw new Error("正在撤回上一条消息,Pi 的历史还没截断完成,请等撤回结束后再发送。");
307
+ }
308
+ // `attachments` was dropped here while the send path grew it, so a message carrying a skill
309
+ // attachment lost it on arrival - the browser drew the attachment, the transcript never had it, and
310
+ // the model was handed the bare prompt. Forwarded now because this is the one line that carries
311
+ // every field of the send.
312
+ await this.runService.enqueueAndRun(command.conversationId, command.content, command.images, command.attachments, command.clientId, command.mode, accepted);
313
+ return;
314
+ }
315
+ if (command.type === "message.steer") {
316
+ await this.runService.steer(command.conversationId, command.messageId);
317
+ return;
318
+ }
319
+ if (command.type === "message.interrupt") {
320
+ await this.runService.interruptQueued(command.conversationId, command.messageId);
321
+ return;
322
+ }
323
+ if (command.type === "message.sendQueued") {
324
+ await this.runService.sendQueued(command.conversationId, command.messageId);
325
+ return;
326
+ }
327
+ if (command.type === "message.cancel") {
328
+ await this.runService.cancelQueued(command.conversationId, command.messageId);
329
+ return;
330
+ }
331
+ if (command.type === "message.cancelMany") {
332
+ await this.runService.cancelQueuedMany(command.conversationId, command.messageIds, { actor: "user" });
333
+ return;
334
+ }
335
+ if (command.type === "message.edit") {
336
+ await this.runService.editQueued(command.conversationId, command.messageId, command.content);
337
+ return;
338
+ }
339
+ if (command.type === "message.reorder") {
340
+ await this.runService.reorderQueued(command.conversationId, command.messageId, command.toIndex);
341
+ return;
342
+ }
343
+ if (command.type === "message.revert") {
344
+ try {
345
+ const withdrawn = await this.conversationService.revertMessage(command.conversationId, command.messageId, command.withdraw);
346
+ sendToSocket?.({ type: "message.revert.result", conversationId: command.conversationId, ok: true, withdrawn });
347
+ }
348
+ catch (error) {
349
+ if (!sendToSocket)
350
+ throw error;
351
+ sendToSocket({ type: "message.revert.result", conversationId: command.conversationId, ok: false, message: error instanceof Error ? error.message : String(error) });
352
+ }
353
+ return;
354
+ }
355
+ if (command.type === "run.stop") {
356
+ await this.runService.stopRun(command.conversationId);
357
+ return;
358
+ }
359
+ if (command.type === "subagent.run") {
360
+ await this.runService.dispatchSubagent({
361
+ conversationId: command.conversationId,
362
+ agentId: command.agentId,
363
+ task: command.task,
364
+ });
365
+ return;
366
+ }
367
+ if (command.type === "subagent.stop") {
368
+ this.runService.stopSubagent(command.runId);
369
+ return;
370
+ }
371
+ if (command.type === "workflow.stop") {
372
+ this.runService.stopWorkflow(command.workflowId);
373
+ return;
374
+ }
375
+ // THE SCHEDULED TASKS, five commands over one list.
376
+ //
377
+ // They are all here rather than in a service of their own because they are all one verb applied to
378
+ // one collection: the service owns the schedule and the clock, and this is the routing table that
379
+ // says which of its methods a command reaches.
380
+ if (command.type === "scheduledTask.create") {
381
+ await this.requireScheduledTasks().create({
382
+ name: command.name,
383
+ prompt: command.prompt,
384
+ schedule: command.schedule,
385
+ workspaceId: command.workspaceId,
386
+ model: command.model,
387
+ agentId: command.agentId,
388
+ }, "user");
389
+ return;
390
+ }
391
+ if (command.type === "scheduledTask.update") {
392
+ await this.requireScheduledTasks().update(command.id, {
393
+ name: command.name,
394
+ prompt: command.prompt,
395
+ schedule: command.schedule,
396
+ model: command.model,
397
+ agentId: command.agentId,
398
+ });
399
+ return;
400
+ }
401
+ if (command.type === "scheduledTask.delete") {
402
+ await this.requireScheduledTasks().remove(command.id);
403
+ return;
404
+ }
405
+ if (command.type === "scheduledTask.trigger") {
406
+ await this.requireScheduledTasks().trigger(command.id);
407
+ return;
408
+ }
409
+ if (command.type === "scheduledTask.toggle") {
410
+ await this.requireScheduledTasks().setEnabled(command.id, command.enabled);
411
+ return;
412
+ }
413
+ if (command.type === "extension.ui.answer") {
414
+ const answer = command.cancelled
415
+ ? { cancelled: true }
416
+ : { value: command.value, confirmed: command.confirmed };
417
+ this.extensionUiService.answerUi(command.conversationId, command.requestId, answer);
418
+ return;
419
+ }
420
+ if (command.type === "question.answer") {
421
+ await this.runService.answerQuestion(command);
422
+ return;
423
+ }
424
+ if (command.type === "catalog.fetch") {
425
+ // THE CATALOG OF THE CONVERSATION BEING SHOWN, not of whatever Pi would default to.
426
+ //
427
+ // The THINKING LEVELS belong to the model in force: Pi computes them from the model itself, and a
428
+ // model that cannot reason offers only "off". This command used to ask for the catalog with NO
429
+ // selection, so the levels were always the DEFAULT model's - which means the picker offered the
430
+ // levels of a model the person was not using, and hid the ones they were. The model list is the
431
+ // same either way, so only the levels were wrong; the levels are the part a person reads.
432
+ //
433
+ // `conversation.select` already asked for it this way; this is the same answer, for the other
434
+ // way a client asks for it.
435
+ const selection = this.conversationService.modelSelectionFor(command.conversationId);
436
+ if (sendToSocket)
437
+ sendToSocket({ type: "model.catalog", conversationId: command.conversationId, catalog: await this.catalogService.getCatalog(selection, command.conversationId) });
438
+ else
439
+ await this.catalogService.broadcastCatalog(selection, command.conversationId);
440
+ return;
441
+ }
442
+ // The unfiltered catalog, for the settings window's model panel. Sent to the ASKING socket only:
443
+ // it is a panel's private list, and broadcasting it would overwrite every open conversation's
444
+ // filtered catalog with one that no workspace's rules apply to.
445
+ if (command.type === "catalog.fetchAll") {
446
+ if (sendToSocket)
447
+ sendToSocket({ type: "model.catalog.all", catalog: await this.catalogService.getAllCatalog() });
448
+ return;
449
+ }
450
+ if (command.type === "prompt.catalog.fetch") {
451
+ const catalog = await this.catalogService.promptCatalog(command.workspaceId);
452
+ if (sendToSocket)
453
+ sendToSocket({ type: "prompt.catalog", catalog });
454
+ return;
455
+ }
456
+ if (command.type === "agent.catalog.fetch") {
457
+ await this.catalogService.broadcastAgents();
458
+ return;
459
+ }
460
+ if (command.type === "subagent.catalog.fetch") {
461
+ await this.catalogService.broadcastSubagents();
462
+ return;
463
+ }
464
+ if (command.type === "agents.setCustomDirs") {
465
+ await this.catalogService.setCustomDirs(command.dirs);
466
+ return;
467
+ }
468
+ if (command.type === "agents.rescan") {
469
+ await this.catalogService.rescan();
470
+ return;
471
+ }
472
+ if (command.type === "super_pi.start") {
473
+ const port = Number(process.env.SUPER_PI_PORT ?? 3080);
474
+ const url = `http://127.0.0.1:${port}`;
475
+ const platform = process.platform;
476
+ if (platform === "darwin")
477
+ spawn("open", [url], { detached: true, stdio: "ignore" }).unref();
478
+ else if (platform === "win32")
479
+ spawn("cmd.exe", ["/c", "start", "", url], { detached: true, stdio: "ignore" }).unref();
480
+ else
481
+ spawn("xdg-open", [url], { detached: true, stdio: "ignore" }).unref();
482
+ return;
483
+ }
484
+ if (command.type === "super_pi.update") {
485
+ // npm install -g picks up the latest published version, then the same restart script the
486
+ // /api/update endpoint uses runs detached. The user sees npm's output stream in their
487
+ // terminal because stdio: inherit is what makes a CLI feel like a CLI.
488
+ //
489
+ // ONE UPDATE AT A TIME. The same slot the /api/update endpoint uses: this command and that
490
+ // endpoint install into the same global prefix, so a slash command that starts while a
491
+ // button-started update is still running would have the two npm processes fight over the
492
+ // same files. The refusal is a THROWN MESSAGE because that is what the client already knows
493
+ // how to show - a toast that says what happened, in the reader's language.
494
+ if (!claimUpdateSlot())
495
+ throw new Error("更新已经在进行中,请等它结束");
496
+ const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
497
+ const update = packageUpdateArgs(this.rootDir ?? import.meta.dirname);
498
+ const updater = spawn(npmCmd, shellArgs(update.args), { stdio: "inherit", shell: process.platform === "win32", env: process.env });
499
+ // EXACTLY ONE RELEASE PER CHILD, for the same reason the HTTP endpoint does it: a spawn that
500
+ // fails emits "error" and then "close", and releasing twice would free the slot out from
501
+ // under an update that had already claimed it.
502
+ let released = false;
503
+ const release = () => { if (released)
504
+ return; released = true; releaseUpdateSlot(); };
505
+ updater.on("error", (error) => { release(); console.error(`Super Pi: npm install failed: ${error instanceof Error ? error.message : "unknown error"}`); });
506
+ updater.on("close", (code) => {
507
+ release();
508
+ if (code !== 0) {
509
+ console.error(`Super Pi: npm install exited with code ${code}`);
510
+ return;
511
+ }
512
+ const cwd = this.rootDir ?? import.meta.dirname;
513
+ const restart = spawn(process.execPath, [join(cwd, "scripts", "restart-server.mjs")], { cwd, detached: true, stdio: "ignore", env: process.env });
514
+ restart.unref();
515
+ });
516
+ return;
517
+ }
518
+ if (command.type === "super_pi.restart") {
519
+ // Reuse the same restart script the in-app button and the terminal command use, so the
520
+ // three paths to 「重新加载磁盘上的新代码」 agree on how.
521
+ const cwd = this.rootDir ?? import.meta.dirname;
522
+ const restart = spawn(process.execPath, [join(cwd, "scripts", "restart-server.mjs")], { cwd, detached: true, stdio: "ignore", env: process.env });
523
+ restart.on("error", (error) => { console.warn(`Super Pi: restart spawn failed: ${error instanceof Error ? error.message : "unknown error"}`); });
524
+ restart.unref();
525
+ return;
526
+ }
527
+ throw new Error(`未知的命令类型:${JSON.stringify(command.type ?? null)}`);
528
+ }
529
+ /**
530
+ * The scheduled-task service, or a refusal.
531
+ *
532
+ * A refusal in the client's own words rather than a crash: the panel that sent the command shows
533
+ * the message, and a handler that threw a TypeError would show nothing but a failed operation.
534
+ */
535
+ requireScheduledTasks() {
536
+ if (!this.scheduledTaskService)
537
+ throw new Error("定时任务功能在这个实例上没有启用。");
538
+ return this.scheduledTaskService;
539
+ }
540
+ }
@@ -0,0 +1,16 @@
1
+ import type { ContentSearchHit, ContentSearchSummary } from "../shared/content-search.js";
2
+ export declare const MAX_CONTENT_RESULTS = 20000;
3
+ export type ContentSearchOptions = {
4
+ include?: string;
5
+ exclude?: string;
6
+ useIgnoreFiles?: boolean;
7
+ signal?: AbortSignal;
8
+ maxResults?: number;
9
+ onHits?: (hits: ContentSearchHit[]) => Promise<void>;
10
+ resolveRipgrep?: () => Promise<string | undefined>;
11
+ };
12
+ export declare function isProtectedSearchPath(path: string): boolean;
13
+ export declare function searchByContent(root: string, query: string, options?: ContentSearchOptions): Promise<ContentSearchSummary & {
14
+ hits: ContentSearchHit[];
15
+ skipped: string[];
16
+ }>;