@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,52 @@
1
+ import type { Store } from "../store.js";
2
+ import type { AgentRuntime } from "../runtime.js";
3
+ import type { EventBroadcaster } from "../server-context.js";
4
+ import type { CatalogService } from "./catalog-service.js";
5
+ import type { RunService } from "./run-service.js";
6
+ import type { ExtensionUiService } from "./extension-ui-service.js";
7
+ export interface WorkspaceSettingsUpdate {
8
+ model?: {
9
+ provider: string;
10
+ modelId: string;
11
+ } | null;
12
+ thinkingLevel?: string | null;
13
+ agentId?: string | null;
14
+ }
15
+ /**
16
+ * Service managing workspaces: creation, rename, cascade deletion, and defaults configuration.
17
+ */
18
+ export declare class WorkspaceService {
19
+ private readonly store;
20
+ private readonly runtime;
21
+ private readonly broadcaster;
22
+ private readonly catalogService;
23
+ private readonly runService;
24
+ private readonly extensionUiService;
25
+ private agentsDir;
26
+ constructor(store: Store, runtime: AgentRuntime, broadcaster: EventBroadcaster, catalogService: CatalogService, runService: RunService, extensionUiService: ExtensionUiService, agentsDir: string | string[]);
27
+ setAgentsDir(dir: string | string[]): void;
28
+ /**
29
+ * Creates a new workspace.
30
+ */
31
+ createWorkspace(name: string, path?: string): Promise<string>;
32
+ /**
33
+ * Renames an existing workspace.
34
+ */
35
+ renameWorkspace(workspaceId: string, name: string): Promise<void>;
36
+ /**
37
+ * Takes a workspace out of the sidebar. NOTHING IS DELETED.
38
+ *
39
+ * The conversations under it, the uploads attached to them and the workspace's own defaults all
40
+ * stay on disk: removing a workspace from the list is a soft unmount, and adding the same
41
+ * folder back brings the whole history with it. What does stop is the WORK: a turn that was still
42
+ * running cannot keep a model session alive behind a workspace the user can no longer see, and a
43
+ * pending question would wait for an answer the sidebar can no longer reach.
44
+ */
45
+ deleteWorkspace(workspaceId: string): Promise<void>;
46
+ /**
47
+ * Updates workspace default settings (model, thinking level, default agent).
48
+ */
49
+ updateSettings(workspaceId: string, settings: WorkspaceSettingsUpdate): Promise<void>;
50
+ /** Validates once for every mounted workspace, then persists the shared defaults in one write. */
51
+ updateMountedWorkspaceSettings(settings: Pick<WorkspaceSettingsUpdate, "model" | "thinkingLevel">): Promise<number>;
52
+ }
@@ -0,0 +1,186 @@
1
+ import { assertModelAllowed } from "../model-filter.js";
2
+ /**
3
+ * Service managing workspaces: creation, rename, cascade deletion, and defaults configuration.
4
+ */
5
+ export class WorkspaceService {
6
+ store;
7
+ runtime;
8
+ broadcaster;
9
+ catalogService;
10
+ runService;
11
+ extensionUiService;
12
+ agentsDir;
13
+ constructor(store, runtime, broadcaster, catalogService, runService, extensionUiService, agentsDir) {
14
+ this.store = store;
15
+ this.runtime = runtime;
16
+ this.broadcaster = broadcaster;
17
+ this.catalogService = catalogService;
18
+ this.runService = runService;
19
+ this.extensionUiService = extensionUiService;
20
+ this.agentsDir = agentsDir;
21
+ }
22
+ setAgentsDir(dir) {
23
+ this.agentsDir = dir;
24
+ }
25
+ /**
26
+ * Creates a new workspace.
27
+ */
28
+ async createWorkspace(name, path) {
29
+ const created = await this.store.createWorkspace(name, path);
30
+ this.broadcaster.broadcastState();
31
+ return created.id;
32
+ }
33
+ /**
34
+ * Renames an existing workspace.
35
+ */
36
+ async renameWorkspace(workspaceId, name) {
37
+ await this.store.renameWorkspace(workspaceId, name);
38
+ this.broadcaster.broadcastState();
39
+ }
40
+ /**
41
+ * Takes a workspace out of the sidebar. NOTHING IS DELETED.
42
+ *
43
+ * The conversations under it, the uploads attached to them and the workspace's own defaults all
44
+ * stay on disk: removing a workspace from the list is a soft unmount, and adding the same
45
+ * folder back brings the whole history with it. What does stop is the WORK: a turn that was still
46
+ * running cannot keep a model session alive behind a workspace the user can no longer see, and a
47
+ * pending question would wait for an answer the sidebar can no longer reach.
48
+ */
49
+ async deleteWorkspace(workspaceId) {
50
+ const snapshot = this.store.snapshot();
51
+ const affected = snapshot.conversations.filter((c) => c.workspaceId === workspaceId);
52
+ for (const c of affected) {
53
+ this.extensionUiService.cancelPendingUi(c.id, "aborted");
54
+ if (this.runService.isRunning(c.id) || snapshot.backgroundTasks.some(task => task.conversationId === c.id)) {
55
+ await this.runService.stopRun(c.id);
56
+ }
57
+ this.runService.stopConversationSubagents(c.id);
58
+ }
59
+ await this.store.deleteWorkspace(workspaceId);
60
+ this.broadcaster.broadcastState();
61
+ }
62
+ /**
63
+ * Updates workspace default settings (model, thinking level, default agent).
64
+ */
65
+ async updateSettings(workspaceId, settings) {
66
+ const workspace = this.store.snapshot().workspaces.find((item) => item.id === workspaceId);
67
+ if (!workspace)
68
+ throw new Error("找不到这个工作区。");
69
+ let selection;
70
+ const requested = settings.model;
71
+ if (requested) {
72
+ const catalog = await this.runtime.catalog();
73
+ const option = catalog.source === "pi"
74
+ ? catalog.models.find((model) => model.provider === requested.provider && model.modelId === requested.modelId)
75
+ : undefined;
76
+ if (catalog.source === "pi" && !option) {
77
+ throw this.catalogService.notOffered(`模型 ${requested.provider}/${requested.modelId}`, catalog);
78
+ }
79
+ selection = option
80
+ ? { provider: option.provider, modelId: option.modelId, label: option.label }
81
+ : { provider: requested.provider, modelId: requested.modelId, label: requested.modelId };
82
+ }
83
+ let thinkingLevel = settings.thinkingLevel ?? undefined;
84
+ if (thinkingLevel) {
85
+ const modelChanged = settings.model !== undefined && (selection?.provider !== workspace.defaultModel?.provider ||
86
+ selection?.modelId !== workspace.defaultModel?.modelId);
87
+ const targetModel = settings.model === null ? undefined : selection ?? workspace.defaultModel;
88
+ const catalog = await this.runtime.catalog(targetModel);
89
+ if (catalog.source === "pi" && !catalog.levels.includes(thinkingLevel)) {
90
+ if (modelChanged) {
91
+ // A saved thinking level belongs to its model; switching models follows Pi's own default.
92
+ thinkingLevel = undefined;
93
+ }
94
+ else {
95
+ throw this.catalogService.notOffered(`思考等级 ${thinkingLevel}`, catalog);
96
+ }
97
+ }
98
+ }
99
+ let agentToStore;
100
+ if (settings.agentId !== undefined) {
101
+ if (settings.agentId === null) {
102
+ agentToStore = null;
103
+ }
104
+ else {
105
+ if (!this.runtime.agentFor) {
106
+ throw new Error("当前运行时没有 agent 机制,无法设置默认 agent");
107
+ }
108
+ const agent = await this.runtime.agentFor({ id: workspaceId, agentId: settings.agentId });
109
+ if (!agent) {
110
+ const dirsLabel = Array.isArray(this.agentsDir) ? this.agentsDir.join(", ") : this.agentsDir;
111
+ throw new Error(`Agent ${JSON.stringify(settings.agentId)} 不存在或不是可用的 primary agent(目录:${dirsLabel})`);
112
+ }
113
+ if (agent.model) {
114
+ const catalog = await this.runtime.catalog();
115
+ const model = catalog.models.find(item => item.provider === agent.model?.provider && item.modelId === agent.model?.modelId);
116
+ assertModelAllowed(this.store.snapshot().modelFilterRules, workspace, model ?? { ...agent.model, label: agent.model.modelId });
117
+ }
118
+ agentToStore = agent.id;
119
+ }
120
+ }
121
+ // THE MODEL RULES HOLD THE MODEL THE USER JUST SET. The check is on `selection` ALONE, and
122
+ // `selection` is undefined when the update did not touch the model at all - which is a
123
+ // DIFFERENT thing from 「the model is Pi's default」.
124
+ //
125
+ // It used to read `selection ?? (await this.runtime.catalog()).defaultModel`, so changing the
126
+ // THINKING LEVEL - a setting that has nothing to do with models - was checked against Pi's own
127
+ // default model, and a workspace whose rules allow only its own default could not change its
128
+ // thinking level at all. The refusal even named a model the user had never chosen: 「当前模型
129
+ // 「Pi 默认 (prov/model-zzz)」不匹配允许的模型正则」.
130
+ //
131
+ // What the rules have to hold is the model this workspace's conversations will RUN ON, and the
132
+ // only model the user could have set here is `selection`. When the update does not name a model,
133
+ // the workspace's existing default (or the absence of one) is what stands, and that is checked
134
+ // where it is stamped onto a conversation - at birth, in `conversation-service.ts`.
135
+ if (selection)
136
+ assertModelAllowed(this.store.modelFilterRules(), workspace, selection);
137
+ await this.store.setWorkspaceDefaults(workspaceId, {
138
+ model: selection,
139
+ thinkingLevel,
140
+ agentId: agentToStore,
141
+ });
142
+ this.broadcaster.broadcastState();
143
+ }
144
+ /** Validates once for every mounted workspace, then persists the shared defaults in one write. */
145
+ async updateMountedWorkspaceSettings(settings) {
146
+ const workspaces = this.store.snapshot().workspaces.filter((item) => !item.closedAt);
147
+ if (!workspaces.length)
148
+ throw new Error("没有可更新的工作区。");
149
+ let selection;
150
+ if (settings.model) {
151
+ const available = await this.runtime.catalog();
152
+ const option = available.source === "pi"
153
+ ? available.models.find((model) => model.provider === settings.model?.provider && model.modelId === settings.model?.modelId)
154
+ : undefined;
155
+ if (available.source === "pi" && !option) {
156
+ throw this.catalogService.notOffered(`模型 ${settings.model.provider}/${settings.model.modelId}`, available);
157
+ }
158
+ selection = option
159
+ ? { provider: option.provider, modelId: option.modelId, label: option.label }
160
+ : { provider: settings.model.provider, modelId: settings.model.modelId, label: settings.model.modelId };
161
+ }
162
+ const thinkingLevel = settings.thinkingLevel ?? undefined;
163
+ if (thinkingLevel) {
164
+ if (!selection)
165
+ throw new Error("请先选择具体模型,再设置思考等级。");
166
+ const modelCatalog = await this.runtime.catalog(selection);
167
+ if (modelCatalog.source === "pi" && !modelCatalog.levels.includes(thinkingLevel)) {
168
+ throw this.catalogService.notOffered(`思考等级 ${thinkingLevel}`, modelCatalog);
169
+ }
170
+ }
171
+ if (selection) {
172
+ for (const workspace of workspaces) {
173
+ try {
174
+ assertModelAllowed(this.store.snapshot().modelFilterRules, workspace, selection);
175
+ }
176
+ catch (error) {
177
+ const detail = error instanceof Error ? error.message : String(error);
178
+ throw new Error(`无法批量修改:工作区「${workspace.name}」不允许该模型。${detail}`);
179
+ }
180
+ }
181
+ }
182
+ const updated = await this.store.setMountedWorkspaceDefaults({ model: selection, thinkingLevel });
183
+ this.broadcaster.broadcastState();
184
+ return updated;
185
+ }
186
+ }
@@ -0,0 +1,13 @@
1
+ import type { ServerContext } from "../server-context.js";
2
+ import type { Workspace } from "../types.js";
3
+ type WorktreeCommand = {
4
+ action?: unknown;
5
+ requestId?: unknown;
6
+ worktreeId?: unknown;
7
+ branch?: unknown;
8
+ base?: unknown;
9
+ task?: unknown;
10
+ conversationId?: unknown;
11
+ };
12
+ export declare function createWorktreeService(context: ServerContext): (source: Workspace, command: WorktreeCommand, callerId?: string) => Promise<unknown>;
13
+ export {};
@@ -0,0 +1,76 @@
1
+ import { join } from "node:path";
2
+ import { createGitWorktree, gitWorktrees, resolveGitWorktree } from "../git.js";
3
+ function inputText(value, maximum) {
4
+ if (value === undefined)
5
+ return "";
6
+ if (typeof value !== "string" || value.includes("\0") || value.trim().length > maximum) {
7
+ throw Object.assign(new Error("工作树操作参数无效"), { code: "bad_message" });
8
+ }
9
+ return value.trim();
10
+ }
11
+ export function createWorktreeService(context) {
12
+ const operations = new Map();
13
+ const { store, paths, broadcaster, conversationService, runService } = context;
14
+ async function perform(source, command, callerId) {
15
+ const project = source.worktreeOf ? store.workspace(source.worktreeOf) : source;
16
+ if (!project || project.closedAt || source.closedAt) {
17
+ throw Object.assign(new Error("请先打开这个工作树所属的项目"), { code: "bad_message" });
18
+ }
19
+ const action = inputText(command.action, 16);
20
+ if (action === "list")
21
+ return { worktrees: (await gitWorktrees(source.path)).worktrees };
22
+ const requestId = inputText(command.requestId, 200);
23
+ if (!requestId || !["create", "follow", "open"].includes(action)) {
24
+ throw Object.assign(new Error("请指定有效的工作树操作"), { code: "bad_message" });
25
+ }
26
+ const task = callerId ? inputText(command.task, 12_000) : "";
27
+ const followConversation = callerId ?? inputText(command.conversationId, 200);
28
+ const sourceConversation = followConversation ? store.conversation(followConversation) : undefined;
29
+ if (followConversation && (!sourceConversation || sourceConversation.workspaceId !== source.id || sourceConversation.archivedAt)) {
30
+ throw Object.assign(new Error("此会话不在所选检出上"), { code: "bad_message" });
31
+ }
32
+ if (task && context.projectService?.projectForSession?.(followConversation)) {
33
+ throw Object.assign(new Error("项目内的执行任务须由项目派发,可以单独创建并跟踪工作树"), { code: "bad_message" });
34
+ }
35
+ const branch = inputText(command.branch, 180);
36
+ const base = inputText(command.base, 180);
37
+ const targetId = inputText(command.worktreeId, 64);
38
+ const key = JSON.stringify([source.id, callerId, requestId, action, followConversation, branch, base, targetId, task]);
39
+ const previous = operations.get(key);
40
+ if (previous)
41
+ return previous;
42
+ const operation = (async () => {
43
+ const entry = action === "create"
44
+ ? await createGitWorktree(source.path, join(paths.dataDir, "worktrees"), key, { branch, base })
45
+ : (await resolveGitWorktree(project.path, targetId)).entry;
46
+ const checkout = await resolveGitWorktree(project.path, entry.id);
47
+ if (followConversation)
48
+ await store.followConversationWorktree(followConversation, entry.id);
49
+ if (action !== "open" && !task) {
50
+ broadcaster.broadcastState();
51
+ return { worktree: checkout.entry };
52
+ }
53
+ const workspace = await store.createWorkspace((entry.branch ?? "工作树 " + entry.head.slice(0, 8)).slice(0, 80), checkout.path, entry.primary ? undefined : project);
54
+ const conversationId = await conversationService.createConversation(workspace.id);
55
+ await store.renameConversation(conversationId, (entry.branch ?? "工作树 " + entry.head.slice(0, 8)).slice(0, 80));
56
+ broadcaster.broadcastState();
57
+ if (task) {
58
+ await new Promise((accept, refuse) => {
59
+ void runService.enqueueAndRunAsAgent(conversationId, task, { onAccepted: () => accept() }).catch(refuse);
60
+ });
61
+ }
62
+ return { worktree: checkout.entry, workspaceId: workspace.id, conversationId };
63
+ })();
64
+ operations.set(key, operation);
65
+ if (operations.size > 128)
66
+ operations.delete(operations.keys().next().value);
67
+ try {
68
+ return await operation;
69
+ }
70
+ catch (error) {
71
+ operations.delete(key);
72
+ throw error;
73
+ }
74
+ }
75
+ return perform;
76
+ }
@@ -0,0 +1,34 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ export declare const isBrowserAuthorized: (request: object) => boolean;
3
+ /** Owner-issued browser access is separate from per-turn agent capabilities. */
4
+ export declare class BrowserAccess {
5
+ private readonly path;
6
+ private id;
7
+ private key?;
8
+ private readonly leases;
9
+ private readonly revoked;
10
+ onRevoke(listener: () => void): () => boolean;
11
+ private invalidate;
12
+ constructor(path: string);
13
+ private save;
14
+ private matches;
15
+ status(): {
16
+ id: `${string}-${string}-${string}-${string}-${string}`;
17
+ protocol: number;
18
+ enabled: boolean;
19
+ };
20
+ rotate(): {
21
+ id: `${string}-${string}-${string}-${string}-${string}`;
22
+ protocol: number;
23
+ enabled: boolean;
24
+ key: string;
25
+ };
26
+ revoke(): {
27
+ id: `${string}-${string}-${string}-${string}-${string}`;
28
+ protocol: number;
29
+ enabled: boolean;
30
+ };
31
+ lease(origin: string): string;
32
+ authorize(request: IncomingMessage, websocket?: boolean): boolean;
33
+ cors(request: IncomingMessage, response: ServerResponse): "local" | "allowed" | "denied" | "preflight";
34
+ }
@@ -0,0 +1,89 @@
1
+ import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
2
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
+ const authorized = new WeakSet();
4
+ export const isBrowserAuthorized = (request) => authorized.has(request);
5
+ const assetPath = (path) => /^\/api\/files\/(?:open-)?asset$/.test(path) || path === "/api/message-artifact" || path.startsWith("/api/upload/");
6
+ /** Owner-issued browser access is separate from per-turn agent capabilities. */
7
+ export class BrowserAccess {
8
+ path;
9
+ id = randomUUID();
10
+ key;
11
+ leases = new Map();
12
+ revoked = new Set();
13
+ onRevoke(listener) { this.revoked.add(listener); return () => this.revoked.delete(listener); }
14
+ invalidate() { this.leases.clear(); for (const listener of this.revoked)
15
+ listener(); }
16
+ constructor(path) {
17
+ this.path = path;
18
+ if (existsSync(path)) {
19
+ const stored = JSON.parse(readFileSync(path, "utf8"));
20
+ if (typeof stored.id === "string")
21
+ this.id = stored.id;
22
+ if (typeof stored.key === "string")
23
+ this.key = stored.key;
24
+ }
25
+ else
26
+ this.save();
27
+ }
28
+ save() { writeFileSync(this.path, JSON.stringify({ id: this.id, key: this.key }), { mode: 0o600 }); }
29
+ matches(key) {
30
+ if (!key || !this.key)
31
+ return false;
32
+ const a = Buffer.from(key), b = Buffer.from(this.key);
33
+ return a.length === b.length && timingSafeEqual(a, b);
34
+ }
35
+ status() { return { id: this.id, protocol: 1, enabled: Boolean(this.key) }; }
36
+ rotate() { this.key = randomBytes(32).toString("base64url"); this.invalidate(); this.save(); return { ...this.status(), key: this.key }; }
37
+ revoke() { this.key = undefined; this.invalidate(); this.save(); return this.status(); }
38
+ lease(origin) {
39
+ for (const [key, entry] of this.leases)
40
+ if (entry.expires < Date.now())
41
+ this.leases.delete(key);
42
+ if (this.leases.size >= 128)
43
+ this.leases.delete(this.leases.keys().next().value);
44
+ const ticket = randomBytes(24).toString("base64url");
45
+ this.leases.set(ticket, { origin, expires: Date.now() + 30 * 60_000 });
46
+ return ticket;
47
+ }
48
+ authorize(request, websocket = false) {
49
+ let key = request.headers.authorization?.replace(/^Bearer /, "");
50
+ if (websocket) {
51
+ const protocol = request.headers["sec-websocket-protocol"]?.split(",").map(item => item.trim()).find(item => item.startsWith("super-pi-key."));
52
+ if (protocol)
53
+ key = protocol.slice("super-pi-key.".length);
54
+ }
55
+ if (!this.matches(key)) {
56
+ const url = new URL(request.url ?? "/", "http://localhost");
57
+ const lease = this.leases.get(url.searchParams.get("browserAsset") ?? "");
58
+ if (websocket || request.method !== "GET" || !assetPath(url.pathname) || !lease || lease.expires < Date.now())
59
+ return false;
60
+ }
61
+ authorized.add(request);
62
+ return true;
63
+ }
64
+ cors(request, response) {
65
+ const origin = request.headers.origin;
66
+ if (!origin || origin === "null")
67
+ return "local";
68
+ let parsed;
69
+ try {
70
+ parsed = new URL(origin);
71
+ }
72
+ catch {
73
+ return "denied";
74
+ }
75
+ if (!["http:", "https:"].includes(parsed.protocol))
76
+ return "denied";
77
+ if (parsed.host === request.headers.host)
78
+ return "local";
79
+ response.setHeader("access-control-allow-origin", parsed.origin);
80
+ response.setHeader("vary", "Origin");
81
+ response.setHeader("access-control-expose-headers", "etag, content-disposition, content-length, last-modified, x-request-id");
82
+ if (request.method === "OPTIONS") {
83
+ response.setHeader("access-control-allow-methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS");
84
+ response.setHeader("access-control-allow-headers", "authorization, content-type, x-request-id, if-match, if-none-match, range");
85
+ return "preflight";
86
+ }
87
+ return this.authorize(request) ? "allowed" : "denied";
88
+ }
89
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Proving that a dispatch request came from THIS server's primary agent, rather than from anything else on
3
+ * the machine that can open a socket to localhost.
4
+ *
5
+ * WHY THIS EXISTS, since the dispatch endpoint already looks like it authenticates. It does not. It
6
+ * validates ANCESTRY - that a claimed `parentRunId` names a real run belonging to the right conversation -
7
+ * and `docs/AGENT_LOOP_DESIGN.md` states the limit in as many words: "The current HTTP boundary validates
8
+ * supplied ancestry, not caller identity. A local process that omits both parentRunId and depth is
9
+ * indistinguishable from a primary caller." That is true, and it was tolerable while the only reachable
10
+ * primitive was a single dispatch. It stops being tolerable the moment an endpoint can trigger a SEQUENCE
11
+ * of dispatches: one unauthenticated POST becomes an unattended pipeline of sub-agents writing to the
12
+ * user's workspace, which is a far larger lever for the same missing check.
13
+ *
14
+ * WHY A CAPABILITY RATHER THAN A SHARED SECRET. `SUPER_PI_ACCESS_TOKEN` already exists and every endpoint
15
+ * already checks it - but it is SERVER-WIDE and optional: unset is the default, and when unset the whole
16
+ * server runs open on loopback, which is a reasonable choice for an app meant to be run by the person
17
+ * sitting at the machine. A dispatch capability is narrower and non-optional in the way that matters: it
18
+ * exists only for the duration of one turn, for one conversation, and only the primary agent's environment
19
+ * ever holds it. `SubagentSupervisor` passes no `env` to a child at all (`subagents.ts:371-380`), so a
20
+ * sub-agent - whose whole threat is that a model controls its inputs and therefore its shell commands -
21
+ * structurally cannot read it back out of its own environment and post it.
22
+ *
23
+ * WHAT THIS DOES NOT CLAIM. It is not defence against a compromised primary agent, which can read its own
24
+ * environment and would simply forward the capability. It is defence against the two neighbours of the
25
+ * primary that are NOT it: an unrelated local process, and a sub-agent that escaped its read-only
26
+ * allowlist. Neither is the primary, and neither is handed the token.
27
+ */
28
+ /**
29
+ * The environment variable the capability travels in.
30
+ *
31
+ * Named on both sides of the wire rather than imported by the extension, for the reason every one of
32
+ * these names is written out twice: `agents/` is loaded by Pi's module loader and `src/` by tsc, so a
33
+ * relative import across the two would resolve differently under each. `scripts/task-tool.test.mjs`
34
+ * asserts the two copies agree, because a rename on one side would otherwise fail at dispatch time with a
35
+ * message nobody reads.
36
+ */
37
+ export declare const TASK_CAPABILITY_ENV = "SUPER_PI_TASK_CAPABILITY";
38
+ /**
39
+ * Mints the capability for one conversation's primary session, and returns it for the extension's
40
+ * environment.
41
+ *
42
+ * CALLED WHEN THE SESSION IS CREATED, so the value is decided before the session exists and cannot be
43
+ * changed underneath it. A session that is never created mints nothing, which is correct: there is
44
+ * nothing to hand it to.
45
+ *
46
+ * ROTATED EVERY SESSION, and that is the property the duration would not give on its own. A token valid
47
+ * for the whole server lifetime would still be a token an unrelated process could not guess - but a token
48
+ * valid only while its holder is alive is a token that stops being a credential the moment the session
49
+ * ends, so there is no window in which a leaked value is still live.
50
+ *
51
+ * WHY IT IS THE SESSION AND NOT THE TURN. The capability travels in the extension's ENVIRONMENT, and an
52
+ * extension reads its environment when it is LOADED. A session that outlives its turns loads its
53
+ * extension once, so a per-turn token would have to be re-read from an environment that cannot change -
54
+ * and the second turn of a conversation would carry the FIRST turn's token, which the server would
55
+ * (correctly) refuse. The session is therefore the unit the credential belongs to, and the server
56
+ * enforces the turn separately. The application service owns the authoritative active-turn map, and
57
+ * passes that fact to `verifyCapability` at each protected endpoint. A stolen token is therefore worth
58
+ * nothing to a caller that cannot also start a turn.
59
+ */
60
+ export declare function mintCapability(conversationId: string): string;
61
+ /**
62
+ * Forgets a conversation's capability, when its session ends.
63
+ *
64
+ * CALLED WHEN THE SESSION IS DESTROYED, so it runs on every exit - a session that was evicted as idle, a
65
+ * session that was thrown away by a revert, a session that was replaced because the conversation's
66
+ * configuration changed, and a session that was disposed at shutdown. A capability that outlived its
67
+ * session would keep working for a session that no longer exists, which is precisely the shape of a
68
+ * credential with no owner.
69
+ */
70
+ export declare function releaseCapability(conversationId: string): void;
71
+ /** Forgets every capability. Called on shutdown, so nothing survives the process that minted it. */
72
+ export declare function releaseAllCapabilities(): void;
73
+ /**
74
+ /**
75
+ * The capability currently valid for a conversation, or `undefined` when no primary turn is running.
76
+ *
77
+ * Exported for the endpoint's own diagnostics and for a test that needs to assert the lifecycle without
78
+ * reading a primary turn's environment. Not exported as a way to READ a conversation's capability and use
79
+ * it - a caller in this process is already inside the trust boundary it protects.
80
+ */
81
+ export declare function capabilityFor(conversationId: string): string | undefined;
82
+ /** The outcome of a check, with a message written for whoever the refusal will be shown to. */
83
+ export type CapabilityVerdict = {
84
+ ok: true;
85
+ } | {
86
+ ok: false;
87
+ message: string;
88
+ };
89
+ /**
90
+ * Checks a presented capability against the one this conversation's turn was given.
91
+ *
92
+ * `timingSafeEqual` rather than `===`, because `===` on a token short-circuits at the first differing byte
93
+ * and turns the comparison into a timing oracle for the value itself. The length check runs first because
94
+ * `timingSafeEqual` throws on mismatched lengths rather than returning false.
95
+ *
96
+ * THE MESSAGE NAMES BOTH HALVES OF THE PROBLEM, because the reader is a model about to retry and there
97
+ * are two genuinely different failures here. A conversation with no live capability is being dispatched
98
+ * from OUTSIDE a turn - the request never came from a primary agent. A conversation with one, and the
99
+ * presented value does not match it, is a turn whose value was not carried through. An extension that
100
+ * silently omitted the header would otherwise be indistinguishable from an attacker, and would keep
101
+ * retrying forever.
102
+ */
103
+ export declare function verifyCapability(conversationId: string, presented: unknown, options?: {
104
+ running?: boolean;
105
+ }): CapabilityVerdict;