@xyit/wellspring 0.0.0-stage → 1.1.0

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 (464) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +853 -2
  3. package/dist/agent/pending-asks.d.ts +20 -0
  4. package/dist/agent/pending-asks.js +70 -0
  5. package/dist/agent/pending-asks.js.map +1 -0
  6. package/dist/agent/task-registry.d.ts +14 -0
  7. package/dist/agent/task-registry.js +80 -0
  8. package/dist/agent/task-registry.js.map +1 -0
  9. package/dist/agent/tool-context.d.ts +30 -0
  10. package/dist/agent/tool-context.js +10 -0
  11. package/dist/agent/tool-context.js.map +1 -0
  12. package/dist/agent/usage.d.ts +40 -0
  13. package/dist/agent/usage.js +122 -0
  14. package/dist/agent/usage.js.map +1 -0
  15. package/dist/api/host/agent.d.ts +165 -0
  16. package/dist/api/host/agent.js +5 -0
  17. package/dist/api/host/agent.js.map +1 -0
  18. package/dist/api/host/events.d.ts +2 -0
  19. package/dist/api/host/events.js +6 -0
  20. package/dist/api/host/events.js.map +1 -0
  21. package/dist/api/host/exec.d.ts +36 -0
  22. package/dist/api/host/exec.js +10 -0
  23. package/dist/api/host/exec.js.map +1 -0
  24. package/dist/api/host/fs.d.ts +24 -0
  25. package/dist/api/host/fs.js +7 -0
  26. package/dist/api/host/fs.js.map +1 -0
  27. package/dist/api/host/hooks.d.ts +210 -0
  28. package/dist/api/host/hooks.js +401 -0
  29. package/dist/api/host/hooks.js.map +1 -0
  30. package/dist/api/host/host.d.ts +36 -0
  31. package/dist/api/host/host.js +53 -0
  32. package/dist/api/host/host.js.map +1 -0
  33. package/dist/api/host/http.d.ts +58 -0
  34. package/dist/api/host/http.js +6 -0
  35. package/dist/api/host/http.js.map +1 -0
  36. package/dist/api/host/index.d.ts +15 -0
  37. package/dist/api/host/index.js +20 -0
  38. package/dist/api/host/index.js.map +1 -0
  39. package/dist/api/host/models.d.ts +65 -0
  40. package/dist/api/host/models.js +8 -0
  41. package/dist/api/host/models.js.map +1 -0
  42. package/dist/api/host/network.d.ts +22 -0
  43. package/dist/api/host/network.js +7 -0
  44. package/dist/api/host/network.js.map +1 -0
  45. package/dist/api/host/plugin.d.ts +138 -0
  46. package/dist/api/host/plugin.js +6 -0
  47. package/dist/api/host/plugin.js.map +1 -0
  48. package/dist/api/host/plugins.d.ts +49 -0
  49. package/dist/api/host/plugins.js +6 -0
  50. package/dist/api/host/plugins.js.map +1 -0
  51. package/dist/api/host/pty.d.ts +55 -0
  52. package/dist/api/host/pty.js +21 -0
  53. package/dist/api/host/pty.js.map +1 -0
  54. package/dist/api/host/session.d.ts +5 -0
  55. package/dist/api/host/session.js +52 -0
  56. package/dist/api/host/session.js.map +1 -0
  57. package/dist/api/host/version.d.ts +2 -0
  58. package/dist/api/host/version.js +3 -0
  59. package/dist/api/host/version.js.map +1 -0
  60. package/dist/api/host/workspace.d.ts +38 -0
  61. package/dist/api/host/workspace.js +9 -0
  62. package/dist/api/host/workspace.js.map +1 -0
  63. package/dist/api/plugin/http-client.d.ts +42 -0
  64. package/dist/api/plugin/http-client.js +364 -0
  65. package/dist/api/plugin/http-client.js.map +1 -0
  66. package/dist/api/plugin/http-protocol.d.ts +152 -0
  67. package/dist/api/plugin/http-protocol.js +49 -0
  68. package/dist/api/plugin/http-protocol.js.map +1 -0
  69. package/dist/api/result/result.d.ts +16 -0
  70. package/dist/api/result/result.js +43 -0
  71. package/dist/api/result/result.js.map +1 -0
  72. package/dist/commands/agent-turn.d.ts +63 -0
  73. package/dist/commands/agent-turn.js +687 -0
  74. package/dist/commands/agent-turn.js.map +1 -0
  75. package/dist/commands/ask-prompt.d.ts +6 -0
  76. package/dist/commands/ask-prompt.js +49 -0
  77. package/dist/commands/ask-prompt.js.map +1 -0
  78. package/dist/commands/config.d.ts +2 -0
  79. package/dist/commands/config.js +283 -0
  80. package/dist/commands/config.js.map +1 -0
  81. package/dist/commands/conversation.d.ts +51 -0
  82. package/dist/commands/conversation.js +630 -0
  83. package/dist/commands/conversation.js.map +1 -0
  84. package/dist/commands/doctor.d.ts +2 -0
  85. package/dist/commands/doctor.js +77 -0
  86. package/dist/commands/doctor.js.map +1 -0
  87. package/dist/commands/exec-approval.d.ts +3 -0
  88. package/dist/commands/exec-approval.js +80 -0
  89. package/dist/commands/exec-approval.js.map +1 -0
  90. package/dist/commands/help.d.ts +2 -0
  91. package/dist/commands/help.js +35 -0
  92. package/dist/commands/help.js.map +1 -0
  93. package/dist/commands/key.d.ts +2 -0
  94. package/dist/commands/key.js +226 -0
  95. package/dist/commands/key.js.map +1 -0
  96. package/dist/commands/plugin.d.ts +2 -0
  97. package/dist/commands/plugin.js +190 -0
  98. package/dist/commands/plugin.js.map +1 -0
  99. package/dist/commands/session.d.ts +2 -0
  100. package/dist/commands/session.js +167 -0
  101. package/dist/commands/session.js.map +1 -0
  102. package/dist/commands/shared.d.ts +35 -0
  103. package/dist/commands/shared.js +66 -0
  104. package/dist/commands/shared.js.map +1 -0
  105. package/dist/commands/start.d.ts +2 -0
  106. package/dist/commands/start.js +75 -0
  107. package/dist/commands/start.js.map +1 -0
  108. package/dist/commands/stop.d.ts +2 -0
  109. package/dist/commands/stop.js +24 -0
  110. package/dist/commands/stop.js.map +1 -0
  111. package/dist/commands/version.d.ts +2 -0
  112. package/dist/commands/version.js +33 -0
  113. package/dist/commands/version.js.map +1 -0
  114. package/dist/config/codes.d.ts +13 -0
  115. package/dist/config/codes.js +15 -0
  116. package/dist/config/codes.js.map +1 -0
  117. package/dist/config/credentials.d.ts +67 -0
  118. package/dist/config/credentials.js +214 -0
  119. package/dist/config/credentials.js.map +1 -0
  120. package/dist/config/defaults.d.ts +5 -0
  121. package/dist/config/defaults.js +31 -0
  122. package/dist/config/defaults.js.map +1 -0
  123. package/dist/config/index.d.ts +5 -0
  124. package/dist/config/index.js +10 -0
  125. package/dist/config/index.js.map +1 -0
  126. package/dist/config/loader.d.ts +10 -0
  127. package/dist/config/loader.js +68 -0
  128. package/dist/config/loader.js.map +1 -0
  129. package/dist/config/providers.d.ts +30 -0
  130. package/dist/config/providers.js +97 -0
  131. package/dist/config/providers.js.map +1 -0
  132. package/dist/config/types.d.ts +75 -0
  133. package/dist/config/types.js +4 -0
  134. package/dist/config/types.js.map +1 -0
  135. package/dist/config/validate.d.ts +4 -0
  136. package/dist/config/validate.js +391 -0
  137. package/dist/config/validate.js.map +1 -0
  138. package/dist/display/markdown.d.ts +7 -0
  139. package/dist/display/markdown.js +116 -0
  140. package/dist/display/markdown.js.map +1 -0
  141. package/dist/display/tool-label.d.ts +6 -0
  142. package/dist/display/tool-label.js +81 -0
  143. package/dist/display/tool-label.js.map +1 -0
  144. package/dist/event/event.d.ts +27 -0
  145. package/dist/event/event.js +152 -0
  146. package/dist/event/event.js.map +1 -0
  147. package/dist/index.d.ts +2 -0
  148. package/dist/index.js +308 -0
  149. package/dist/index.js.map +1 -0
  150. package/dist/input/codes.d.ts +15 -0
  151. package/dist/input/codes.js +20 -0
  152. package/dist/input/codes.js.map +1 -0
  153. package/dist/input/commands.d.ts +10 -0
  154. package/dist/input/commands.js +65 -0
  155. package/dist/input/commands.js.map +1 -0
  156. package/dist/input/help.d.ts +8 -0
  157. package/dist/input/help.js +51 -0
  158. package/dist/input/help.js.map +1 -0
  159. package/dist/input/index.d.ts +6 -0
  160. package/dist/input/index.js +10 -0
  161. package/dist/input/index.js.map +1 -0
  162. package/dist/input/parse-options.d.ts +11 -0
  163. package/dist/input/parse-options.js +51 -0
  164. package/dist/input/parse-options.js.map +1 -0
  165. package/dist/input/parse.d.ts +3 -0
  166. package/dist/input/parse.js +119 -0
  167. package/dist/input/parse.js.map +1 -0
  168. package/dist/input/types.d.ts +17 -0
  169. package/dist/input/types.js +2 -0
  170. package/dist/input/types.js.map +1 -0
  171. package/dist/logger/elog4js.d.ts +65 -0
  172. package/dist/logger/elog4js.js +305 -0
  173. package/dist/logger/elog4js.js.map +1 -0
  174. package/dist/logger/logger.d.ts +37 -0
  175. package/dist/logger/logger.js +196 -0
  176. package/dist/logger/logger.js.map +1 -0
  177. package/dist/network/index.d.ts +2 -0
  178. package/dist/network/index.js +6 -0
  179. package/dist/network/index.js.map +1 -0
  180. package/dist/network/openai.d.ts +117 -0
  181. package/dist/network/openai.js +443 -0
  182. package/dist/network/openai.js.map +1 -0
  183. package/dist/network/proxy.d.ts +9 -0
  184. package/dist/network/proxy.js +72 -0
  185. package/dist/network/proxy.js.map +1 -0
  186. package/dist/network/web.d.ts +34 -0
  187. package/dist/network/web.js +152 -0
  188. package/dist/network/web.js.map +1 -0
  189. package/dist/platform/clipboard.d.ts +15 -0
  190. package/dist/platform/clipboard.js +82 -0
  191. package/dist/platform/clipboard.js.map +1 -0
  192. package/dist/platform/exec.d.ts +28 -0
  193. package/dist/platform/exec.js +95 -0
  194. package/dist/platform/exec.js.map +1 -0
  195. package/dist/platform/file.d.ts +38 -0
  196. package/dist/platform/file.js +197 -0
  197. package/dist/platform/file.js.map +1 -0
  198. package/dist/platform/index.d.ts +7 -0
  199. package/dist/platform/index.js +12 -0
  200. package/dist/platform/index.js.map +1 -0
  201. package/dist/platform/notification.d.ts +14 -0
  202. package/dist/platform/notification.js +82 -0
  203. package/dist/platform/notification.js.map +1 -0
  204. package/dist/platform/open-external.d.ts +10 -0
  205. package/dist/platform/open-external.js +105 -0
  206. package/dist/platform/open-external.js.map +1 -0
  207. package/dist/platform/os.d.ts +20 -0
  208. package/dist/platform/os.js +86 -0
  209. package/dist/platform/os.js.map +1 -0
  210. package/dist/platform/path.d.ts +32 -0
  211. package/dist/platform/path.js +154 -0
  212. package/dist/platform/path.js.map +1 -0
  213. package/dist/plugin/access-guard.d.ts +1 -0
  214. package/dist/plugin/access-guard.js +40 -0
  215. package/dist/plugin/access-guard.js.map +1 -0
  216. package/dist/plugin/agent-service.d.ts +25 -0
  217. package/dist/plugin/agent-service.js +809 -0
  218. package/dist/plugin/agent-service.js.map +1 -0
  219. package/dist/plugin/agent-tools.d.ts +12 -0
  220. package/dist/plugin/agent-tools.js +31 -0
  221. package/dist/plugin/agent-tools.js.map +1 -0
  222. package/dist/plugin/capabilities.d.ts +26 -0
  223. package/dist/plugin/capabilities.js +192 -0
  224. package/dist/plugin/capabilities.js.map +1 -0
  225. package/dist/plugin/console-guard.d.ts +2 -0
  226. package/dist/plugin/console-guard.js +52 -0
  227. package/dist/plugin/console-guard.js.map +1 -0
  228. package/dist/plugin/data-access.d.ts +15 -0
  229. package/dist/plugin/data-access.js +57 -0
  230. package/dist/plugin/data-access.js.map +1 -0
  231. package/dist/plugin/fs.d.ts +3 -0
  232. package/dist/plugin/fs.js +93 -0
  233. package/dist/plugin/fs.js.map +1 -0
  234. package/dist/plugin/host-alias.d.ts +2 -0
  235. package/dist/plugin/host-alias.js +57 -0
  236. package/dist/plugin/host-alias.js.map +1 -0
  237. package/dist/plugin/index.d.ts +7 -0
  238. package/dist/plugin/index.js +11 -0
  239. package/dist/plugin/index.js.map +1 -0
  240. package/dist/plugin/install.d.ts +17 -0
  241. package/dist/plugin/install.js +163 -0
  242. package/dist/plugin/install.js.map +1 -0
  243. package/dist/plugin/loader.d.ts +45 -0
  244. package/dist/plugin/loader.js +739 -0
  245. package/dist/plugin/loader.js.map +1 -0
  246. package/dist/plugin/manage.d.ts +31 -0
  247. package/dist/plugin/manage.js +271 -0
  248. package/dist/plugin/manage.js.map +1 -0
  249. package/dist/plugin/models-service.d.ts +15 -0
  250. package/dist/plugin/models-service.js +317 -0
  251. package/dist/plugin/models-service.js.map +1 -0
  252. package/dist/plugin/network-service.d.ts +10 -0
  253. package/dist/plugin/network-service.js +87 -0
  254. package/dist/plugin/network-service.js.map +1 -0
  255. package/dist/plugin/package-manager.d.ts +46 -0
  256. package/dist/plugin/package-manager.js +148 -0
  257. package/dist/plugin/package-manager.js.map +1 -0
  258. package/dist/plugin/paths.d.ts +6 -0
  259. package/dist/plugin/paths.js +15 -0
  260. package/dist/plugin/paths.js.map +1 -0
  261. package/dist/plugin/registry.d.ts +17 -0
  262. package/dist/plugin/registry.js +82 -0
  263. package/dist/plugin/registry.js.map +1 -0
  264. package/dist/plugin/runtime.d.ts +9 -0
  265. package/dist/plugin/runtime.js +43 -0
  266. package/dist/plugin/runtime.js.map +1 -0
  267. package/dist/plugin/scaffold.d.ts +13 -0
  268. package/dist/plugin/scaffold.js +132 -0
  269. package/dist/plugin/scaffold.js.map +1 -0
  270. package/dist/plugin/state.d.ts +6 -0
  271. package/dist/plugin/state.js +38 -0
  272. package/dist/plugin/state.js.map +1 -0
  273. package/dist/plugin/zip.d.ts +7 -0
  274. package/dist/plugin/zip.js +138 -0
  275. package/dist/plugin/zip.js.map +1 -0
  276. package/dist/sandbox/audit.d.ts +12 -0
  277. package/dist/sandbox/audit.js +20 -0
  278. package/dist/sandbox/audit.js.map +1 -0
  279. package/dist/sandbox/backends/bwrap.d.ts +28 -0
  280. package/dist/sandbox/backends/bwrap.js +197 -0
  281. package/dist/sandbox/backends/bwrap.js.map +1 -0
  282. package/dist/sandbox/backends/direct.d.ts +7 -0
  283. package/dist/sandbox/backends/direct.js +32 -0
  284. package/dist/sandbox/backends/direct.js.map +1 -0
  285. package/dist/sandbox/bridge-state.d.ts +13 -0
  286. package/dist/sandbox/bridge-state.js +12 -0
  287. package/dist/sandbox/bridge-state.js.map +1 -0
  288. package/dist/sandbox/index.d.ts +5 -0
  289. package/dist/sandbox/index.js +6 -0
  290. package/dist/sandbox/index.js.map +1 -0
  291. package/dist/sandbox/manager.d.ts +8 -0
  292. package/dist/sandbox/manager.js +325 -0
  293. package/dist/sandbox/manager.js.map +1 -0
  294. package/dist/sandbox/memory-limit.d.ts +44 -0
  295. package/dist/sandbox/memory-limit.js +193 -0
  296. package/dist/sandbox/memory-limit.js.map +1 -0
  297. package/dist/sandbox/plugin-client.d.ts +80 -0
  298. package/dist/sandbox/plugin-client.js +1601 -0
  299. package/dist/sandbox/plugin-client.js.map +1 -0
  300. package/dist/sandbox/plugin-host.d.ts +1 -0
  301. package/dist/sandbox/plugin-host.js +1001 -0
  302. package/dist/sandbox/plugin-host.js.map +1 -0
  303. package/dist/sandbox/protocol.d.ts +43 -0
  304. package/dist/sandbox/protocol.js +96 -0
  305. package/dist/sandbox/protocol.js.map +1 -0
  306. package/dist/sandbox/rpc-timeouts.d.ts +28 -0
  307. package/dist/sandbox/rpc-timeouts.js +15 -0
  308. package/dist/sandbox/rpc-timeouts.js.map +1 -0
  309. package/dist/sandbox/supervisor.d.ts +31 -0
  310. package/dist/sandbox/supervisor.js +114 -0
  311. package/dist/sandbox/supervisor.js.map +1 -0
  312. package/dist/sandbox/types.d.ts +124 -0
  313. package/dist/sandbox/types.js +17 -0
  314. package/dist/sandbox/types.js.map +1 -0
  315. package/dist/service/control.d.ts +32 -0
  316. package/dist/service/control.js +117 -0
  317. package/dist/service/control.js.map +1 -0
  318. package/dist/session/compress.d.ts +3 -0
  319. package/dist/session/compress.js +42 -0
  320. package/dist/session/compress.js.map +1 -0
  321. package/dist/session/index.d.ts +4 -0
  322. package/dist/session/index.js +8 -0
  323. package/dist/session/index.js.map +1 -0
  324. package/dist/session/registry.d.ts +4 -0
  325. package/dist/session/registry.js +12 -0
  326. package/dist/session/registry.js.map +1 -0
  327. package/dist/session/replay.d.ts +10 -0
  328. package/dist/session/replay.js +109 -0
  329. package/dist/session/replay.js.map +1 -0
  330. package/dist/session/session.d.ts +40 -0
  331. package/dist/session/session.js +108 -0
  332. package/dist/session/session.js.map +1 -0
  333. package/dist/session/store.d.ts +58 -0
  334. package/dist/session/store.js +382 -0
  335. package/dist/session/store.js.map +1 -0
  336. package/dist/session/types.d.ts +56 -0
  337. package/dist/session/types.js +3 -0
  338. package/dist/session/types.js.map +1 -0
  339. package/dist/workspace/index.d.ts +7 -0
  340. package/dist/workspace/index.js +17 -0
  341. package/dist/workspace/index.js.map +1 -0
  342. package/dist/workspace/registry.d.ts +25 -0
  343. package/dist/workspace/registry.js +293 -0
  344. package/dist/workspace/registry.js.map +1 -0
  345. package/package.json +73 -5
  346. package/scripts/build-node-pty.mjs +55 -0
  347. package/scripts/rewrite-dts.mjs +36 -0
  348. package/scripts/run-tests.mjs +41 -0
  349. package/scripts/verify-sandbox.ts +98 -0
  350. package/src/agent/pending-asks.ts +88 -0
  351. package/src/agent/task-registry.ts +108 -0
  352. package/src/agent/tool-context.ts +47 -0
  353. package/src/agent/usage.ts +170 -0
  354. package/src/api/host/agent.ts +162 -0
  355. package/src/api/host/events.ts +7 -0
  356. package/src/api/host/exec.ts +47 -0
  357. package/src/api/host/fs.ts +33 -0
  358. package/src/api/host/hooks.ts +635 -0
  359. package/src/api/host/host.ts +99 -0
  360. package/src/api/host/http.ts +79 -0
  361. package/src/api/host/index.ts +20 -0
  362. package/src/api/host/models.ts +81 -0
  363. package/src/api/host/network.ts +32 -0
  364. package/src/api/host/plugin.ts +158 -0
  365. package/src/api/host/plugins.ts +59 -0
  366. package/src/api/host/pty.ts +73 -0
  367. package/src/api/host/session.ts +61 -0
  368. package/src/api/host/version.ts +2 -0
  369. package/src/api/host/workspace.ts +51 -0
  370. package/src/api/plugin/http-client.ts +492 -0
  371. package/src/api/plugin/http-protocol.ts +231 -0
  372. package/src/api/result/result.ts +52 -0
  373. package/src/commands/agent-turn.ts +817 -0
  374. package/src/commands/ask-prompt.ts +52 -0
  375. package/src/commands/config.ts +306 -0
  376. package/src/commands/conversation.ts +777 -0
  377. package/src/commands/doctor.ts +92 -0
  378. package/src/commands/exec-approval.ts +91 -0
  379. package/src/commands/help.ts +41 -0
  380. package/src/commands/key.ts +281 -0
  381. package/src/commands/plugin.ts +222 -0
  382. package/src/commands/session.ts +179 -0
  383. package/src/commands/shared.ts +103 -0
  384. package/src/commands/start.ts +88 -0
  385. package/src/commands/stop.ts +24 -0
  386. package/src/commands/version.ts +40 -0
  387. package/src/config/codes.ts +17 -0
  388. package/src/config/credentials.ts +302 -0
  389. package/src/config/defaults.ts +32 -0
  390. package/src/config/index.ts +10 -0
  391. package/src/config/loader.ts +80 -0
  392. package/src/config/providers.ts +133 -0
  393. package/src/config/types.ts +88 -0
  394. package/src/config/validate.ts +458 -0
  395. package/src/display/markdown.ts +137 -0
  396. package/src/display/tool-label.ts +87 -0
  397. package/src/event/event.ts +171 -0
  398. package/src/index.ts +344 -0
  399. package/src/input/codes.ts +21 -0
  400. package/src/input/commands.ts +76 -0
  401. package/src/input/help.ts +60 -0
  402. package/src/input/index.ts +10 -0
  403. package/src/input/parse-options.ts +66 -0
  404. package/src/input/parse.ts +138 -0
  405. package/src/input/types.ts +19 -0
  406. package/src/logger/elog4js.ts +366 -0
  407. package/src/logger/logger.ts +251 -0
  408. package/src/network/index.ts +6 -0
  409. package/src/network/openai.ts +571 -0
  410. package/src/network/proxy.ts +80 -0
  411. package/src/network/web.ts +206 -0
  412. package/src/platform/clipboard.ts +107 -0
  413. package/src/platform/exec.ts +128 -0
  414. package/src/platform/file.ts +235 -0
  415. package/src/platform/index.ts +12 -0
  416. package/src/platform/notification.ts +108 -0
  417. package/src/platform/open-external.ts +132 -0
  418. package/src/platform/os.ts +101 -0
  419. package/src/platform/path.ts +214 -0
  420. package/src/plugin/access-guard.ts +46 -0
  421. package/src/plugin/agent-service.ts +969 -0
  422. package/src/plugin/agent-tools.ts +43 -0
  423. package/src/plugin/capabilities.ts +240 -0
  424. package/src/plugin/console-guard.ts +66 -0
  425. package/src/plugin/data-access.ts +70 -0
  426. package/src/plugin/fs.ts +109 -0
  427. package/src/plugin/host-alias.ts +61 -0
  428. package/src/plugin/index.ts +11 -0
  429. package/src/plugin/install.ts +213 -0
  430. package/src/plugin/loader.ts +952 -0
  431. package/src/plugin/manage.ts +338 -0
  432. package/src/plugin/models-service.ts +383 -0
  433. package/src/plugin/network-service.ts +102 -0
  434. package/src/plugin/package-manager.ts +214 -0
  435. package/src/plugin/paths.ts +19 -0
  436. package/src/plugin/registry.ts +103 -0
  437. package/src/plugin/runtime.ts +57 -0
  438. package/src/plugin/scaffold.ts +158 -0
  439. package/src/plugin/state.ts +52 -0
  440. package/src/plugin/zip.ts +156 -0
  441. package/src/sandbox/audit.ts +38 -0
  442. package/src/sandbox/backends/bwrap.ts +251 -0
  443. package/src/sandbox/backends/direct.ts +43 -0
  444. package/src/sandbox/bridge-state.ts +29 -0
  445. package/src/sandbox/index.ts +5 -0
  446. package/src/sandbox/manager.ts +406 -0
  447. package/src/sandbox/memory-limit.ts +245 -0
  448. package/src/sandbox/plugin-client.ts +1881 -0
  449. package/src/sandbox/plugin-host.ts +1282 -0
  450. package/src/sandbox/protocol.ts +142 -0
  451. package/src/sandbox/pty-bridge.py +154 -0
  452. package/src/sandbox/rpc-timeouts.ts +43 -0
  453. package/src/sandbox/supervisor.ts +172 -0
  454. package/src/sandbox/types.ts +149 -0
  455. package/src/service/control.ts +155 -0
  456. package/src/session/compress.ts +47 -0
  457. package/src/session/index.ts +8 -0
  458. package/src/session/registry.ts +17 -0
  459. package/src/session/replay.ts +132 -0
  460. package/src/session/session.ts +134 -0
  461. package/src/session/store.ts +468 -0
  462. package/src/session/types.ts +61 -0
  463. package/src/workspace/index.ts +21 -0
  464. package/src/workspace/registry.ts +356 -0
@@ -0,0 +1,88 @@
1
+ /*
2
+ * Agent 提问:ask 工具把问题交给界面,等待用户回答后把答案还回工具循环。
3
+ * 和提权审批一样是“一轮对话中途停下来等人”的机制,只是不需要权限判断。
4
+ */
5
+
6
+ import { randomUUID } from "node:crypto"
7
+
8
+ /** 等待用户回答的上限;超时后工具返回“没有回答”并继续 */
9
+ export const ASK_TIMEOUT_MS = 5 * 60_000
10
+
11
+ interface PendingAsk {
12
+ readonly sessionId: string
13
+ readonly resolve: (answer: string | null) => void
14
+ readonly timer: NodeJS.Timeout
15
+ }
16
+
17
+ const pending = new Map<string, PendingAsk>()
18
+
19
+ export function createAskId(): string {
20
+ return `ask_${randomUUID()}`
21
+ }
22
+
23
+ /**
24
+ * 登记一个等待回答的问题。answerAsk 先把 answer 交给这个 Promise;
25
+ * 超时兑现 null(用户没回答)。
26
+ */
27
+ export function waitForAsk(input: {
28
+ readonly askId: string
29
+ readonly sessionId: string
30
+ readonly timeoutMs?: number
31
+ }): Promise<string | null> {
32
+ return new Promise<string | null>((resolvePromise) => {
33
+ let settled = false
34
+ let timer: NodeJS.Timeout | null = null
35
+ const finish = (answer: string | null): void => {
36
+ if (settled) {
37
+ return
38
+ }
39
+ settled = true
40
+ if (timer !== null) {
41
+ clearTimeout(timer)
42
+ }
43
+ pending.delete(input.askId)
44
+ resolvePromise(answer)
45
+ }
46
+ timer = setTimeout(() => {
47
+ finish(null)
48
+ }, input.timeoutMs ?? ASK_TIMEOUT_MS)
49
+ pending.set(input.askId, {
50
+ sessionId: input.sessionId,
51
+ resolve: finish,
52
+ timer,
53
+ })
54
+ })
55
+ }
56
+
57
+ /** 用户回答;命中等待中的问题时返回 true */
58
+ export function answerAsk(askId: string, answer: string): boolean {
59
+ const entry = pending.get(askId)
60
+ if (entry === undefined) {
61
+ return false
62
+ }
63
+ entry.resolve(answer)
64
+ return true
65
+ }
66
+
67
+ /** 取消一次等待(工具循环收尾、异常退出时调用) */
68
+ export function cancelAsk(askId: string): void {
69
+ const entry = pending.get(askId)
70
+ if (entry === undefined) {
71
+ return
72
+ }
73
+ entry.resolve(null)
74
+ }
75
+
76
+ /** 会话结束时清掉遗留的等待 */
77
+ export function cancelSessionAsks(sessionId: string): void {
78
+ for (const [askId, entry] of [...pending]) {
79
+ if (entry.sessionId === sessionId) {
80
+ cancelAsk(askId)
81
+ }
82
+ }
83
+ }
84
+
85
+ /** 当前等待回答的数量(测试与诊断用) */
86
+ export function pendingAskCount(): number {
87
+ return pending.size
88
+ }
@@ -0,0 +1,108 @@
1
+ // 后台 execute_code 任务注册表
2
+
3
+ import type { AgentCodeResult, AgentCodeTaskHandle, StopMode } from "../sandbox/types.ts"
4
+
5
+ export interface AgentTaskInfo {
6
+ readonly taskId: string
7
+ readonly sandboxId: string
8
+ readonly status: "running" | "completed" | "failed" | "cancelled"
9
+ readonly startedAt: number
10
+ readonly stdout: string
11
+ readonly stderr: string
12
+ readonly result: AgentCodeResult | null
13
+ readonly error: string | null
14
+ }
15
+
16
+ interface TaskRecord {
17
+ readonly taskId: string
18
+ readonly handle: AgentCodeTaskHandle
19
+ readonly startedAt: number
20
+ status: "running" | "completed" | "failed" | "cancelled"
21
+ cancelled: boolean
22
+ result: AgentCodeResult | null
23
+ error: string | null
24
+ }
25
+
26
+ const tasks = new Map<string, TaskRecord>()
27
+ const order: string[] = []
28
+
29
+ export function registerBackgroundTask(handle: AgentCodeTaskHandle): AgentTaskInfo {
30
+ const taskId = handle.sandboxId
31
+ const record: TaskRecord = {
32
+ taskId,
33
+ handle,
34
+ startedAt: Date.now(),
35
+ status: "running",
36
+ cancelled: false,
37
+ result: null,
38
+ error: null,
39
+ }
40
+ tasks.set(taskId, record)
41
+ order.push(taskId)
42
+ while (order.length > 50) {
43
+ const oldest = order.shift()
44
+ if (oldest !== undefined) {
45
+ tasks.delete(oldest)
46
+ }
47
+ }
48
+ void handle
49
+ .wait()
50
+ .then((result) => {
51
+ record.status = record.cancelled ? "cancelled" : "completed"
52
+ record.result = result
53
+ })
54
+ .catch((error: unknown) => {
55
+ record.status = "failed"
56
+ record.error = error instanceof Error ? error.message : String(error)
57
+ })
58
+ return infoOf(record)
59
+ }
60
+
61
+ function infoOf(record: TaskRecord): AgentTaskInfo {
62
+ return {
63
+ taskId: record.taskId,
64
+ sandboxId: record.handle.sandboxId,
65
+ status:
66
+ record.status === "completed" &&
67
+ (record.result?.signal === "SIGINT" || record.result?.signal === "SIGKILL")
68
+ ? "cancelled"
69
+ : record.status,
70
+ startedAt: record.startedAt,
71
+ stdout: record.result?.stdout ?? record.handle.stdout,
72
+ stderr: record.result?.stderr ?? record.handle.stderr,
73
+ result: record.result,
74
+ error: record.error,
75
+ }
76
+ }
77
+
78
+ export function queryTask(taskId?: string): AgentTaskInfo | null {
79
+ if (taskId !== undefined && taskId !== "") {
80
+ const record = tasks.get(taskId)
81
+ return record === undefined ? null : infoOf(record)
82
+ }
83
+ for (let index = order.length - 1; index >= 0; index -= 1) {
84
+ const id = order[index]
85
+ if (id !== undefined) {
86
+ const record = tasks.get(id)
87
+ if (record !== undefined && record.status === "running") {
88
+ return infoOf(record)
89
+ }
90
+ }
91
+ }
92
+ const latest = order[order.length - 1]
93
+ return latest === undefined ? null : infoOf(tasks.get(latest)!)
94
+ }
95
+
96
+ export function stopTask(taskId: string | undefined, mode: StopMode): boolean {
97
+ const info = queryTask(taskId)
98
+ if (info === null) {
99
+ return false
100
+ }
101
+ const record = tasks.get(info.taskId)
102
+ if (record === undefined || record.status !== "running") {
103
+ return false
104
+ }
105
+ record.cancelled = true
106
+ record.handle.stop(mode)
107
+ return true
108
+ }
@@ -0,0 +1,47 @@
1
+ // 插件工具调用上下文:宿主能力在调用期间读取当前 Agent 权限
2
+
3
+ import { AsyncLocalStorage } from "node:async_hooks"
4
+
5
+ import type { SandboxAccess } from "../config/types.ts"
6
+ import type { Elog } from "../logger/elog4js.ts"
7
+
8
+ export interface AgentToolRequest {
9
+ readonly command: string
10
+ readonly argv: readonly string[]
11
+ readonly cwd: string
12
+ readonly currentPermission?: SandboxAccess
13
+ readonly requestedPermission?: SandboxAccess
14
+ readonly justification?: string
15
+ /** 请求联网:和提权是两件事,审阅时也要看到 */
16
+ readonly network?: boolean
17
+ /** 请求后台执行 */
18
+ readonly background?: boolean
19
+ /** 要喂给进程的标准输入(可能很大,界面截断显示) */
20
+ readonly stdin?: string
21
+ /** 请求的超时毫秒 */
22
+ readonly timeoutMs?: number
23
+ }
24
+
25
+ export interface AgentToolContext {
26
+ readonly sessionId: string
27
+ readonly turn: number
28
+ readonly step: number
29
+ readonly workspaceDir: string
30
+ readonly permission: SandboxAccess
31
+ readonly allowExec: boolean
32
+ readonly approveExec?: (request: AgentToolRequest) => Promise<boolean>
33
+ readonly elog: Elog
34
+ }
35
+
36
+ const storage = new AsyncLocalStorage<AgentToolContext>()
37
+
38
+ export async function withAgentToolContext<T>(
39
+ context: AgentToolContext,
40
+ task: () => Promise<T>,
41
+ ): Promise<T> {
42
+ return await storage.run(context, task)
43
+ }
44
+
45
+ export function getAgentToolContext(): AgentToolContext | null {
46
+ return storage.getStore() ?? null
47
+ }
@@ -0,0 +1,170 @@
1
+ /*
2
+ * Token 用量:模型报告的输出、缓存命中与上下文占用。
3
+ *
4
+ * `inputTokens` 统一成 prompt tokens 总数,缓存命中的部分也计算在内;
5
+ * `cacheReadTokens` / `cacheWriteTokens` 是其中的缓存读取与写入。
6
+ * 不同供应商口径由 parseProviderUsage 抹平:
7
+ * - DeepSeek / OpenAI:prompt_tokens(或 Responses 的 input_tokens)本身含缓存命中,
8
+ * 命中数在 prompt_cache_hit_tokens 或 prompt_tokens_details.cached_tokens;
9
+ * - 部分网关沿用 Anthropic 的 cache_read_input_tokens / cache_creation_input_tokens,
10
+ * 这时 input_tokens 只是未缓存部分,parse 会加上两段缓存凑成总数。
11
+ */
12
+
13
+ /** 一次模型调用报告的用量;供应商没返回的项为 null */
14
+ export interface ProviderUsage {
15
+ readonly inputTokens: number | null
16
+ readonly outputTokens: number | null
17
+ readonly cacheReadTokens: number | null
18
+ readonly cacheWriteTokens: number | null
19
+ readonly reasoningTokens: number | null
20
+ }
21
+
22
+ /** 界面几处共用的按需字段:空值不写进会话,旧数据格式保持不变 */
23
+ export interface TokenUsage {
24
+ readonly inputTokens: number | null
25
+ readonly outputTokens: number | null
26
+ readonly cacheReadTokens?: number | null
27
+ readonly cacheWriteTokens?: number | null
28
+ readonly reasoningTokens?: number | null
29
+ /** 这一轮最后一次请求的 prompt tokens,即收尾时占用的上下文 */
30
+ readonly contextTokens?: number | null
31
+ }
32
+
33
+ function countOf(value: unknown): number | null {
34
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
35
+ return null
36
+ }
37
+ return Math.floor(value)
38
+ }
39
+
40
+ function recordOf(value: unknown): Record<string, unknown> | null {
41
+ return value !== null && typeof value === "object" ? (value as Record<string, unknown>) : null
42
+ }
43
+
44
+ /** 把供应商的 usage 原样对象归一化成计数;一条可用字段都没有时返回 null */
45
+ export function parseProviderUsage(value: unknown): ProviderUsage | null {
46
+ const record = recordOf(value)
47
+ if (record === null) {
48
+ return null
49
+ }
50
+ const promptDetails = recordOf(record["prompt_tokens_details"])
51
+ const inputDetails = recordOf(record["input_tokens_details"])
52
+ const completionDetails = recordOf(record["completion_tokens_details"])
53
+ const outputDetails = recordOf(record["output_tokens_details"])
54
+ let input = countOf(record["prompt_tokens"]) ?? countOf(record["input_tokens"])
55
+ const output = countOf(record["completion_tokens"]) ?? countOf(record["output_tokens"])
56
+ const cacheRead =
57
+ countOf(record["prompt_cache_hit_tokens"]) ??
58
+ countOf(promptDetails?.["cached_tokens"]) ??
59
+ countOf(inputDetails?.["cached_tokens"]) ??
60
+ countOf(record["cache_read_input_tokens"])
61
+ const cacheWrite =
62
+ countOf(record["cache_creation_input_tokens"]) ??
63
+ countOf(promptDetails?.["cache_creation_tokens"]) ??
64
+ countOf(inputDetails?.["cache_creation_tokens"])
65
+ /*
66
+ * Anthropic 口径的 input_tokens 不含缓存读取/写入,补成 prompt 总数;
67
+ * 有 prompt_tokens 或 *_tokens_details 的 OpenAI 口径不能再加,否则重复计数。
68
+ */
69
+ const anthropicStyle =
70
+ record["prompt_tokens"] === undefined &&
71
+ promptDetails === null &&
72
+ inputDetails === null &&
73
+ (cacheRead !== null || cacheWrite !== null) &&
74
+ (record["cache_read_input_tokens"] !== undefined ||
75
+ record["cache_creation_input_tokens"] !== undefined)
76
+ if (anthropicStyle && input !== null) {
77
+ input += (cacheRead ?? 0) + (cacheWrite ?? 0)
78
+ }
79
+ const reasoning =
80
+ countOf(completionDetails?.["reasoning_tokens"]) ??
81
+ countOf(outputDetails?.["reasoning_tokens"])
82
+ if (input === null && output === null && cacheRead === null && cacheWrite === null) {
83
+ return null
84
+ }
85
+ return {
86
+ inputTokens: input,
87
+ outputTokens: output,
88
+ cacheReadTokens: cacheRead,
89
+ cacheWriteTokens: cacheWrite,
90
+ reasoningTokens: reasoning,
91
+ }
92
+ }
93
+
94
+ /**
95
+ * 缓存命中率(0-100 整数)
96
+ *
97
+ * 分母是 prompt tokens 总数;`cacheRead` 是其中的子集。
98
+ * 供应商没报告缓存或没有任何输入时返回 null。
99
+ */
100
+ export function cacheHitPercent(
101
+ cacheReadTokens: number | null | undefined,
102
+ promptTokens: number | null | undefined,
103
+ ): number | null {
104
+ if (typeof cacheReadTokens !== "number" || typeof promptTokens !== "number") {
105
+ return null
106
+ }
107
+ if (!Number.isFinite(cacheReadTokens) || !Number.isFinite(promptTokens) || promptTokens <= 0) {
108
+ return null
109
+ }
110
+ const percent = Math.round((cacheReadTokens / promptTokens) * 100)
111
+ return Math.min(100, Math.max(0, percent))
112
+ }
113
+
114
+ /** 未缓存输入:prompt tokens 减去缓存读取/写入,最小为 0 */
115
+ export function uncachedInputTokens(
116
+ inputTokens: number | null | undefined,
117
+ cacheReadTokens: number | null | undefined,
118
+ cacheWriteTokens?: number | null,
119
+ ): number | null {
120
+ if (typeof inputTokens !== "number" || !Number.isFinite(inputTokens) || inputTokens < 0) {
121
+ return null
122
+ }
123
+ const cacheRead =
124
+ typeof cacheReadTokens === "number" && Number.isFinite(cacheReadTokens)
125
+ ? cacheReadTokens
126
+ : 0
127
+ const cacheWrite =
128
+ typeof cacheWriteTokens === "number" && Number.isFinite(cacheWriteTokens)
129
+ ? cacheWriteTokens
130
+ : 0
131
+ return Math.max(0, Math.floor(inputTokens - cacheRead - cacheWrite))
132
+ }
133
+
134
+ /** 去掉空的可选字段:会话 JSON 里只留供应商真的报告过的项 */
135
+ export function compactUsage(usage: TokenUsage): TokenUsage {
136
+ return {
137
+ inputTokens: usage.inputTokens,
138
+ outputTokens: usage.outputTokens,
139
+ ...(typeof usage.cacheReadTokens === "number"
140
+ ? { cacheReadTokens: usage.cacheReadTokens }
141
+ : {}),
142
+ ...(typeof usage.cacheWriteTokens === "number"
143
+ ? { cacheWriteTokens: usage.cacheWriteTokens }
144
+ : {}),
145
+ ...(typeof usage.reasoningTokens === "number"
146
+ ? { reasoningTokens: usage.reasoningTokens }
147
+ : {}),
148
+ ...(typeof usage.contextTokens === "number" ? { contextTokens: usage.contextTokens } : {}),
149
+ }
150
+ }
151
+
152
+ /** 一次模型回复的结构化用量;inputTokens 默认就是这次请求占用的上下文 */
153
+ export interface UsageSource {
154
+ readonly inputTokens: number | null
155
+ readonly outputTokens: number | null
156
+ readonly cacheReadTokens?: number | null
157
+ readonly cacheWriteTokens?: number | null
158
+ readonly reasoningTokens?: number | null
159
+ }
160
+
161
+ export function usageOf(source: UsageSource, contextTokens?: number | null): TokenUsage {
162
+ return compactUsage({
163
+ inputTokens: source.inputTokens,
164
+ outputTokens: source.outputTokens,
165
+ cacheReadTokens: source.cacheReadTokens ?? null,
166
+ cacheWriteTokens: source.cacheWriteTokens ?? null,
167
+ reasoningTokens: source.reasoningTokens ?? null,
168
+ contextTokens: contextTokens === undefined ? source.inputTokens : contextTokens,
169
+ })
170
+ }
@@ -0,0 +1,162 @@
1
+ /*
2
+ * 宿主 Agent 能力:让 sandbox 插件与 Agent 会话交互。
3
+ */
4
+
5
+ import type { TokenUsage } from "../../agent/usage.ts"
6
+
7
+ /** Agent 运行时的 sandbox 权限;与 CLI 的 --permission 取值一致 */
8
+ export type HostAgentPermission = "read-only" | "workspace-write" | "danger-full-access"
9
+
10
+ export interface HostAgentChatInput {
11
+ /** 用户消息 */
12
+ readonly message: string
13
+ /** 已有会话 id;不传则创建新会话 */
14
+ readonly sessionId?: string
15
+ /** 覆盖本次使用的模型 */
16
+ readonly model?: string
17
+ /** 覆盖本次使用的供应商 id(内置为 openai) */
18
+ readonly provider?: string
19
+ /** 覆盖本次推理强度:off / low / high / max */
20
+ readonly reasoning?: string
21
+ /** 覆盖本次 system prompt */
22
+ readonly system?: string
23
+ /** 会话所在工作目录;不传使用宿主当前目录 */
24
+ readonly cwd?: string
25
+ /** 用户在输入框里用 @ 引用的工作区相对路径 */
26
+ readonly references?: readonly string[]
27
+ /** 覆盖本轮的 sandbox 权限;不传则使用宿主配置的 sandbox.access */
28
+ readonly permission?: HostAgentPermission
29
+ }
30
+
31
+ export interface HostAgentChatResult {
32
+ readonly sessionId: string
33
+ /** 会话内第几轮 */
34
+ readonly turn: number
35
+ /** 本轮执行的步数 */
36
+ readonly steps: number
37
+ readonly reply: string
38
+ readonly model: string
39
+ /** 本轮 token 用量:含缓存命中/写入、推理与收尾时的上下文占用 */
40
+ readonly usage: TokenUsage | null
41
+ }
42
+
43
+ export interface HostWorkspaceFileEntry {
44
+ /** 相对工作区根的路径,使用 / 分隔 */
45
+ readonly path: string
46
+ readonly name: string
47
+ readonly type: "file" | "directory"
48
+ }
49
+
50
+ export interface HostWorkspaceFilesResult {
51
+ readonly ok: boolean
52
+ readonly root: string
53
+ readonly entries: readonly HostWorkspaceFileEntry[]
54
+ readonly truncated: boolean
55
+ readonly error?: string
56
+ }
57
+
58
+ /** 工作目录校验结果:root 为规范化后的绝对路径 */
59
+ export interface HostWorkspaceCheck {
60
+ readonly ok: boolean
61
+ readonly root: string
62
+ readonly name: string
63
+ /** ok=false 时的原因 */
64
+ readonly error?: string
65
+ }
66
+
67
+ export interface HostAgentApprovalRequest {
68
+ readonly approvalId: string
69
+ readonly command: string
70
+ readonly argv: readonly string[]
71
+ readonly cwd: string
72
+ readonly currentPermission?: string
73
+ readonly requestedPermission?: string
74
+ readonly justification?: string
75
+ /** 请求联网 */
76
+ readonly network?: boolean
77
+ /** 请求后台执行 */
78
+ readonly background?: boolean
79
+ /** 标准输入;界面按长度截断显示 */
80
+ readonly stdin?: string
81
+ /** 请求的超时毫秒 */
82
+ readonly timeoutMs?: number
83
+ }
84
+
85
+ /** Agent 用 ask 工具向用户提问;界面回答后 Agent 继续 */
86
+ export interface HostAgentAskRequest {
87
+ readonly askId: string
88
+ readonly question: string
89
+ /** 候选答案;用户可以选,也可以自由输入 */
90
+ readonly options?: readonly string[]
91
+ }
92
+
93
+ /** 一次工具调用的生命周期事件;界面用来显示“正在调用什么工具” */
94
+ export interface HostAgentToolEvent {
95
+ readonly id: string
96
+ readonly name: string
97
+ readonly phase: "start" | "end"
98
+ /** start 时为模型的原始参数 JSON */
99
+ readonly arguments?: string
100
+ /** end 时是否执行成功 */
101
+ readonly ok?: boolean
102
+ /** end 时的工具输出(过长时截断) */
103
+ readonly result?: string
104
+ /** result 是否被截断 */
105
+ readonly truncated?: boolean
106
+ }
107
+
108
+ export type HostAgentStreamEvent =
109
+ /** 会话已创建/打开:客户端可先保存 sessionId,刷新后仍能续上同一会话 */
110
+ | { readonly type: "session"; readonly sessionId: string; readonly turn?: number }
111
+ | { readonly type: "delta"; readonly text: string }
112
+ /** 模型思考内容增量(reasoning_content) */
113
+ | { readonly type: "reasoning"; readonly text: string }
114
+ /** 工具调用开始/结束 */
115
+ | ({ readonly type: "tool" } & HostAgentToolEvent)
116
+ /** Agent 提问,等待用户回答 */
117
+ | { readonly type: "ask"; readonly request: HostAgentAskRequest }
118
+ /** 开始执行第 step 步;用于界面显示进度 */
119
+ | { readonly type: "step"; readonly turn: number; readonly step: number }
120
+ /** 工具请求提升权限,等待用户批准 */
121
+ | { readonly type: "approval"; readonly request: HostAgentApprovalRequest }
122
+
123
+ export interface HostAgentApi {
124
+ chat(input: HostAgentChatInput): Promise<HostAgentChatResult>
125
+ /** 流式执行;delta 通过回调推送,Promise 在完成时返回最终结果 */
126
+ stream(
127
+ input: HostAgentChatInput,
128
+ onEvent: (event: HostAgentStreamEvent) => void,
129
+ ): Promise<HostAgentChatResult>
130
+ /** 校验工作目录:必须是已存在的目录;返回规范化路径与目录名 */
131
+ validateWorkspace(path: string): Promise<HostWorkspaceCheck>
132
+ /** 打开宿主系统的原生文件夹选择对话框,返回选中的目录 */
133
+ pickDirectory(): Promise<HostWorkspaceCheck>
134
+ /**
135
+ * 在工作区里搜索文件与目录
136
+ *
137
+ * 空 query 列根目录一层;query 以 / 结尾且目录存在时列该目录一层
138
+ * 单关键字按文件名优先排序,其次路径段、路径包含、子序列
139
+ * 多段查询(a/b/c)按路径段链式匹配,前缀目录不必存在
140
+ * 跳过依赖/构建目录与符号链接;受扫描条目、深度与时间上限约束
141
+ */
142
+ searchWorkspaceFiles(root: string, query: string): Promise<HostWorkspaceFilesResult>
143
+ /**
144
+ * 向正在运行的会话插话
145
+ *
146
+ * 消息进入该会话的待注入队列,在 Agent 下一次模型调用前作为用户消息插入同一轮
147
+ * 会话不在运行中(尚未开始或已结束)返回 false,调用方按下一轮处理
148
+ */
149
+ interject(sessionId: string, message: string): Promise<boolean>
150
+ /**
151
+ * 停止正在运行的一轮
152
+ *
153
+ * 已发出的模型调用不会被切断:循环在当前步结束后收尾,
154
+ * 后续步骤、工具执行都不再发起。等待中的提问与提权请求按“跳过 / 拒绝”了结。
155
+ * 会话不在运行中返回 false
156
+ */
157
+ stop(sessionId: string): Promise<boolean>
158
+ /** 回复提权请求;返回是否命中待处理的请求 */
159
+ respondApproval(approvalId: string, approved: boolean): Promise<boolean>
160
+ /** 回答 Agent 的提问;返回是否命中待处理的提问 */
161
+ respondAsk(askId: string, answer: string): Promise<boolean>
162
+ }
@@ -0,0 +1,7 @@
1
+ /*
2
+ * 宿主事件总线。
3
+ * 插件可以通过 `import { event } from "wellspring/api/host/index.ts"` 订阅/发布事件。
4
+ */
5
+
6
+ export { EventEntity, EventBus, eventBus } from "../../event/event.ts"
7
+ export type { EventListener } from "../../event/event.ts"
@@ -0,0 +1,47 @@
1
+ /*
2
+ * 宿主进程执行 API。
3
+ * 插件被 access-guard 禁止直接 import node:child_process,需要跑命令时走这里。
4
+ * 执行与输出缓冲都在宿主侧,插件用 poll 拉增量,不为终端单独引入流式 RPC。
5
+ */
6
+
7
+ export interface HostExecRunOptions {
8
+ /** 交给 shell 解释的命令行 */
9
+ readonly command: string
10
+ /** 工作目录,必须落在允许的执行根内 */
11
+ readonly cwd: string
12
+ /** 追加的环境变量 */
13
+ readonly env?: Record<string, string>
14
+ /** 超时毫秒,到点终止整个进程组 */
15
+ readonly timeoutMs?: number
16
+ }
17
+
18
+ export interface HostExecSession {
19
+ readonly sessionId: string
20
+ readonly pid: number | null
21
+ readonly cwd: string
22
+ }
23
+
24
+ export interface HostExecChunk {
25
+ /** 自上次 poll 之后新增的输出 */
26
+ readonly chunk: string
27
+ /** 进程是否已结束 */
28
+ readonly done: boolean
29
+ /** 退出码;被信号终止时为 null */
30
+ readonly exitCode: number | null
31
+ /** 因超时被终止 */
32
+ readonly timedOut: boolean
33
+ /** 输出被上限截断 */
34
+ readonly truncated: boolean
35
+ }
36
+
37
+ export interface HostExecApi {
38
+ run(options: HostExecRunOptions): Promise<HostExecSession>
39
+ poll(sessionId: string): Promise<HostExecChunk>
40
+ stop(sessionId: string): Promise<void>
41
+ }
42
+
43
+ /** 单条会话的输出上限,超出即截断并终止 */
44
+ export const HOST_EXEC_MAX_OUTPUT_BYTES = 2 * 1024 * 1024
45
+
46
+ /** 未显式指定时的超时上限 */
47
+ export const HOST_EXEC_DEFAULT_TIMEOUT_MS = 120_000
@@ -0,0 +1,33 @@
1
+ /*
2
+ * 宿主文件 API。
3
+ * 插件通过 api.fs / ctx.fs(插件数据目录)或 api.workspaceFs / ctx.workspaceFs(当前工作目录)访问文件。
4
+ * 路径必须是相对路径,且不能逃出对应根目录。
5
+ */
6
+
7
+ export type HostFileType = "file" | "directory" | "other"
8
+
9
+ export interface HostFileStat {
10
+ readonly type: HostFileType
11
+ readonly size: number
12
+ readonly mtimeMs: number
13
+ }
14
+
15
+ export interface HostFileEntry extends HostFileStat {
16
+ readonly name: string
17
+ }
18
+
19
+ export interface HostFileApi {
20
+ /** 该 API 的根目录,仅用于展示/诊断 */
21
+ readonly root: string
22
+ readText(path: string): Promise<string | null>
23
+ readBytes(path: string): Promise<Uint8Array | null>
24
+ readJson<T = unknown>(path: string): Promise<T | null>
25
+ writeText(path: string, text: string): Promise<void>
26
+ writeBytes(path: string, bytes: Uint8Array): Promise<void>
27
+ writeJson(path: string, value: unknown): Promise<void>
28
+ list(path?: string): Promise<readonly HostFileEntry[]>
29
+ stat(path: string): Promise<HostFileStat | null>
30
+ mkdir(path: string): Promise<void>
31
+ remove(path: string): Promise<void>
32
+ exists(path: string): Promise<boolean>
33
+ }