@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,51 @@
1
+ /*
2
+ * 宿主工作区 API。
3
+ *
4
+ * 工作区是用户手动添加、供 Agent 与编辑器使用的目录;注册表由宿主统一维护
5
+ * (<dataDir>/workspaces.json),插件通过 `api.workspaces` 读写,不再解析
6
+ * 其它插件的数据目录。需要 hostApi: workspaces 权限。
7
+ */
8
+
9
+ /** 已添加的工作区;id 由目录路径派生,保持稳定 */
10
+ export interface HostWorkspaceEntry {
11
+ readonly id: string
12
+ readonly name: string
13
+ /** 规范化后的绝对路径 */
14
+ readonly root: string
15
+ readonly createdAt: number
16
+ readonly lastSeenAt: number
17
+ }
18
+
19
+ export interface HostWorkspaceListResult {
20
+ readonly workspaces: readonly HostWorkspaceEntry[]
21
+ }
22
+
23
+ export interface HostWorkspaceAddInput {
24
+ /** 绝对路径;必须已存在且是目录 */
25
+ readonly root: string
26
+ /** 默认取目录名 */
27
+ readonly name?: string
28
+ }
29
+
30
+ export interface HostWorkspaceAddResult {
31
+ readonly workspace: HostWorkspaceEntry
32
+ /** 同一目录重复添加时为 true(会刷新 lastSeenAt) */
33
+ readonly duplicate: boolean
34
+ }
35
+
36
+ export interface HostWorkspaceRemoveResult {
37
+ readonly removed: boolean
38
+ }
39
+
40
+ export interface HostWorkspacesApi {
41
+ /** 列出已添加的工作区;不会预置任何工作区 */
42
+ list(): Promise<HostWorkspaceListResult>
43
+ /** 添加目录;重复添加返回已有记录 */
44
+ add(input: HostWorkspaceAddInput): Promise<HostWorkspaceAddResult>
45
+ /** 移除工作区(只从注册表移除,不动目录本身) */
46
+ remove(id: string): Promise<HostWorkspaceRemoveResult>
47
+ /** 重命名;工作区不存在返回 null */
48
+ rename(id: string, name: string): Promise<HostWorkspaceEntry | null>
49
+ /** 刷新 lastSeenAt;工作区不存在返回 null */
50
+ touch(id: string): Promise<HostWorkspaceEntry | null>
51
+ }
@@ -0,0 +1,492 @@
1
+ /*
2
+ * wellspring-http 的消费者侧客户端。
3
+ *
4
+ * 依赖 wellspring-http 插件的插件用它注册服务器:
5
+ *
6
+ * const server = await registerHttpServer(eventBus, { name: "my-app", port: 8787 }, handler)
7
+ *
8
+ * helper 负责:订阅请求频道、发布注册请求、等待 ready/error、把每个请求派发给 handler、
9
+ * 把 handler 的响应 / 流式分片 / WebSocket 消息发回 wellspring-http。
10
+ * 使用者只需要处理 HttpRequest / HttpResponse,不需要关心事件总线细节。
11
+ *
12
+ * 注意:helper 与插件使用同一个 eventBus 实例(`wellspring/api/host` 导出的那个;
13
+ * sandbox 内自动桥接到宿主事件总线,跨插件投递)。
14
+ */
15
+
16
+ import type { EventBus } from "../host/events.ts"
17
+ import { EventEntity } from "../host/events.ts"
18
+ import type {
19
+ HttpHandler,
20
+ HttpRequest,
21
+ HttpResponse,
22
+ HttpStreamContext,
23
+ HttpTlsOptions,
24
+ } from "../host/http.ts"
25
+ import {
26
+ HTTP_BUS_MAX_BODY_BYTES,
27
+ HTTP_BUS_REGISTER,
28
+ HTTP_BUS_REGISTER_TIMEOUT_MS,
29
+ HTTP_BUS_UNREGISTER,
30
+ base64ByteLength,
31
+ httpRequestChannel,
32
+ httpResponseChannel,
33
+ isValidHttpServerName,
34
+ type HttpBusClientEvent,
35
+ type HttpBusReadyEvent,
36
+ type HttpBusRegisterRequest,
37
+ type HttpBusServerEvent,
38
+ type HttpBusUnregisterRequest,
39
+ } from "./http-protocol.ts"
40
+
41
+ export interface BusWebSocket {
42
+ readonly connectionId: string
43
+ send(data: string): void
44
+ close(code?: number, reason?: string): void
45
+ onMessage(handler: (data: string) => void): void
46
+ onClose(handler: (code: number, reason: string) => void): void
47
+ }
48
+
49
+ export type BusWebSocketHandler = (
50
+ socket: BusWebSocket,
51
+ request: HttpRequest,
52
+ ) => void | Promise<void>
53
+
54
+ export interface RegisterHttpServerOptions {
55
+ /** 服务器名:请求/响应频道都用它做后缀,必须唯一且符合插件 id 规则 */
56
+ readonly name: string
57
+ /** 默认 127.0.0.1 */
58
+ readonly host?: string
59
+ /** 默认 0(随机端口) */
60
+ readonly port?: number
61
+ readonly tls?: HttpTlsOptions
62
+ /** 启用 WebSocket 转发;提供时才会在升级请求上回调 */
63
+ readonly websocket?: BusWebSocketHandler
64
+ /** 单次请求等待上限,默认 120s */
65
+ readonly requestTimeoutMs?: number
66
+ /** 等待 wellspring-http 回 ready 的上限,默认 10s */
67
+ readonly registerTimeoutMs?: number
68
+ /** 启动成功后的运行期错误回调 */
69
+ readonly onError?: (error: { readonly code: string; readonly message: string }) => void
70
+ }
71
+
72
+ export interface HttpServerBusHandle {
73
+ readonly name: string
74
+ readonly host: string
75
+ readonly port: number
76
+ readonly secure: boolean
77
+ close(): Promise<void>
78
+ }
79
+
80
+ interface StreamState {
81
+ readonly requestId: string
82
+ published: boolean
83
+ ended: boolean
84
+ readonly buffered: string[]
85
+ timer: ReturnType<typeof setTimeout> | null
86
+ }
87
+
88
+ interface SocketState {
89
+ readonly connectionId: string
90
+ readonly messageHandlers: Array<(data: string) => void>
91
+ readonly closeHandlers: Array<(code: number, reason: string) => void>
92
+ closed: boolean
93
+ }
94
+
95
+ interface ServerRuntime {
96
+ readonly bus: EventBus
97
+ readonly options: RegisterHttpServerOptions
98
+ readonly handler: HttpHandler
99
+ readonly requestChannel: string
100
+ readonly responseChannel: string
101
+ readonly streams: Map<string, StreamState>
102
+ readonly sockets: Map<string, SocketState>
103
+ readonly timeoutMs: number
104
+ ready: boolean
105
+ closed: boolean
106
+ readyResolve?: (event: HttpBusReadyEvent) => void
107
+ readyReject?: (error: Error) => void
108
+ }
109
+
110
+ const DEFAULT_REQUEST_TIMEOUT_MS = 120_000
111
+
112
+ function errorMessageOf(error: unknown): string {
113
+ return error instanceof Error ? error.message : String(error)
114
+ }
115
+
116
+ function responseBodyBytes(response: HttpResponse): number {
117
+ const body = response.body
118
+ if (body === undefined) {
119
+ return 0
120
+ }
121
+ if (response.bodyEncoding === "base64") {
122
+ return base64ByteLength(body)
123
+ }
124
+ return Buffer.byteLength(body, "utf8")
125
+ }
126
+
127
+ /**
128
+ * 注册一个由 wellspring-http 托管的 HTTP(S) 服务器。
129
+ * 返回的 handle 带真实 host/port(port 传 0 时由系统分配)。
130
+ */
131
+ export async function registerHttpServer(
132
+ bus: EventBus,
133
+ options: RegisterHttpServerOptions,
134
+ handler: HttpHandler,
135
+ ): Promise<HttpServerBusHandle> {
136
+ const name = options.name
137
+ if (!isValidHttpServerName(name)) {
138
+ throw new Error(`HTTP 服务器名不合法:${name}`)
139
+ }
140
+ if (options.host !== undefined && (options.host.trim() === "" || /\s/.test(options.host))) {
141
+ throw new Error(`非法监听地址:${options.host}`)
142
+ }
143
+ if (
144
+ options.port !== undefined &&
145
+ (!Number.isInteger(options.port) || options.port < 0 || options.port > 65_535)
146
+ ) {
147
+ throw new Error(`非法端口:${String(options.port)}`)
148
+ }
149
+
150
+ const runtime: ServerRuntime = {
151
+ bus,
152
+ options,
153
+ handler,
154
+ requestChannel: httpRequestChannel(name),
155
+ responseChannel: httpResponseChannel(name),
156
+ streams: new Map(),
157
+ sockets: new Map(),
158
+ timeoutMs:
159
+ typeof options.requestTimeoutMs === "number" &&
160
+ Number.isInteger(options.requestTimeoutMs) &&
161
+ options.requestTimeoutMs > 0
162
+ ? options.requestTimeoutMs
163
+ : DEFAULT_REQUEST_TIMEOUT_MS,
164
+ ready: false,
165
+ closed: false,
166
+ }
167
+
168
+ const unsubscribe = bus.subscribe<HttpBusServerEvent>(runtime.requestChannel, (event) => {
169
+ dispatch(runtime, event.getData())
170
+ })
171
+
172
+ const registerTimeoutMs =
173
+ typeof options.registerTimeoutMs === "number" &&
174
+ Number.isInteger(options.registerTimeoutMs) &&
175
+ options.registerTimeoutMs > 0
176
+ ? options.registerTimeoutMs
177
+ : HTTP_BUS_REGISTER_TIMEOUT_MS
178
+ const ready = new Promise<HttpBusReadyEvent>((resolve, reject) => {
179
+ const timer = setTimeout(() => {
180
+ reject(
181
+ new Error(
182
+ `wellspring-http 注册超时(${registerTimeoutMs}ms):${name};请确认 wellspring-http 插件已启用`,
183
+ ),
184
+ )
185
+ }, registerTimeoutMs)
186
+ timer.unref()
187
+ runtime.readyResolve = (event) => {
188
+ clearTimeout(timer)
189
+ resolve(event)
190
+ }
191
+ runtime.readyReject = (error) => {
192
+ clearTimeout(timer)
193
+ reject(error)
194
+ }
195
+ })
196
+
197
+ const request: HttpBusRegisterRequest = {
198
+ name,
199
+ ...(options.host === undefined ? {} : { host: options.host }),
200
+ ...(options.port === undefined ? {} : { port: options.port }),
201
+ ...(options.tls === undefined ? {} : { tls: options.tls }),
202
+ ...(options.websocket === undefined ? {} : { websocket: true }),
203
+ ...(options.requestTimeoutMs === undefined
204
+ ? {}
205
+ : { requestTimeoutMs: options.requestTimeoutMs }),
206
+ }
207
+ bus.publish(HTTP_BUS_REGISTER, EventEntity.create(request))
208
+
209
+ let started: HttpBusReadyEvent
210
+ try {
211
+ started = await ready
212
+ } catch (error) {
213
+ unsubscribe()
214
+ throw error
215
+ }
216
+ runtime.ready = true
217
+
218
+ return {
219
+ name,
220
+ host: started.host,
221
+ port: started.port,
222
+ secure: started.secure,
223
+ close: async () => {
224
+ if (runtime.closed) {
225
+ return
226
+ }
227
+ runtime.closed = true
228
+ const unregister: HttpBusUnregisterRequest = { name }
229
+ bus.publish(HTTP_BUS_UNREGISTER, EventEntity.create(unregister))
230
+ unsubscribe()
231
+ for (const state of runtime.streams.values()) {
232
+ if (state.timer !== null) {
233
+ clearTimeout(state.timer)
234
+ }
235
+ }
236
+ runtime.streams.clear()
237
+ runtime.sockets.clear()
238
+ },
239
+ }
240
+ }
241
+
242
+ function publishResponse(runtime: ServerRuntime, event: HttpBusClientEvent): void {
243
+ runtime.bus.publish(runtime.responseChannel, EventEntity.create(event))
244
+ }
245
+
246
+ function dispatch(runtime: ServerRuntime, event: HttpBusServerEvent): void {
247
+ switch (event.type) {
248
+ case "ready":
249
+ runtime.readyResolve?.(event)
250
+ return
251
+ case "error":
252
+ if (!runtime.ready) {
253
+ runtime.readyReject?.(new Error(`${event.code}: ${event.message}`))
254
+ } else {
255
+ runtime.options.onError?.({ code: event.code, message: event.message })
256
+ }
257
+ return
258
+ case "stopped":
259
+ return
260
+ case "http-request":
261
+ void runRequest(runtime, event.requestId, event.request)
262
+ return
263
+ case "http-abort": {
264
+ const state = runtime.streams.get(event.requestId)
265
+ if (state === undefined) {
266
+ return
267
+ }
268
+ state.ended = true
269
+ finishStream(runtime, state)
270
+ return
271
+ }
272
+ case "websocket-open":
273
+ void runSocket(runtime, event.connectionId, event.request)
274
+ return
275
+ case "websocket-message": {
276
+ const socket = runtime.sockets.get(event.connectionId)
277
+ if (socket === undefined || socket.closed) {
278
+ return
279
+ }
280
+ for (const handler of socket.messageHandlers.slice()) {
281
+ handler(event.data)
282
+ }
283
+ return
284
+ }
285
+ case "websocket-close": {
286
+ const socket = runtime.sockets.get(event.connectionId)
287
+ if (socket === undefined || socket.closed) {
288
+ return
289
+ }
290
+ runtime.sockets.delete(event.connectionId)
291
+ socket.closed = true
292
+ for (const handler of socket.closeHandlers.slice()) {
293
+ handler(event.code, event.reason)
294
+ }
295
+ return
296
+ }
297
+ }
298
+ }
299
+
300
+ async function runRequest(
301
+ runtime: ServerRuntime,
302
+ requestId: string,
303
+ request: HttpRequest,
304
+ ): Promise<void> {
305
+ const name = runtime.options.name
306
+ if (request.body !== "" && base64ByteLength(request.body) > HTTP_BUS_MAX_BODY_BYTES) {
307
+ publishResponse(runtime, {
308
+ type: "http-response",
309
+ name,
310
+ requestId,
311
+ response: {
312
+ status: 413,
313
+ headers: { "content-type": "text/plain; charset=utf-8" },
314
+ body: `请求体超过 wellspring-http 事件转发上限(${HTTP_BUS_MAX_BODY_BYTES} 字节)`,
315
+ },
316
+ })
317
+ return
318
+ }
319
+
320
+ const state: StreamState = {
321
+ requestId,
322
+ published: false,
323
+ ended: false,
324
+ buffered: [],
325
+ timer: null,
326
+ }
327
+ runtime.streams.set(requestId, state)
328
+ const stream: HttpStreamContext = {
329
+ write(chunk: string) {
330
+ if (state.ended) {
331
+ return
332
+ }
333
+ if (state.published) {
334
+ publishResponse(runtime, { type: "http-chunk", name, requestId, chunk })
335
+ touchStream(runtime, state)
336
+ } else {
337
+ state.buffered.push(chunk)
338
+ }
339
+ },
340
+ end() {
341
+ if (state.ended) {
342
+ return
343
+ }
344
+ state.ended = true
345
+ if (state.published) {
346
+ publishResponse(runtime, { type: "http-end", name, requestId })
347
+ finishStream(runtime, state)
348
+ }
349
+ },
350
+ }
351
+
352
+ let response: HttpResponse
353
+ try {
354
+ response = await runtime.handler(request, stream)
355
+ } catch (error) {
356
+ finishStream(runtime, state)
357
+ publishResponse(runtime, {
358
+ type: "http-response",
359
+ name,
360
+ requestId,
361
+ response: {
362
+ status: 500,
363
+ headers: { "content-type": "text/plain; charset=utf-8" },
364
+ body: errorMessageOf(error),
365
+ },
366
+ })
367
+ return
368
+ }
369
+
370
+ const bytes = responseBodyBytes(response)
371
+ if (bytes > HTTP_BUS_MAX_BODY_BYTES) {
372
+ finishStream(runtime, state)
373
+ runtime.options.onError?.({
374
+ code: "response-too-large",
375
+ message: `响应体 ${bytes} 字节超过事件转发上限 ${HTTP_BUS_MAX_BODY_BYTES}`,
376
+ })
377
+ publishResponse(runtime, {
378
+ type: "http-response",
379
+ name,
380
+ requestId,
381
+ response: {
382
+ status: 502,
383
+ headers: { "content-type": "text/plain; charset=utf-8" },
384
+ body: "wellspring-http:响应体超过事件转发上限",
385
+ },
386
+ })
387
+ return
388
+ }
389
+
390
+ if (response.stream !== true) {
391
+ finishStream(runtime, state)
392
+ publishResponse(runtime, { type: "http-response", name, requestId, response })
393
+ return
394
+ }
395
+
396
+ state.published = true
397
+ publishResponse(runtime, { type: "http-response", name, requestId, response })
398
+ touchStream(runtime, state)
399
+ for (const chunk of state.buffered.splice(0)) {
400
+ publishResponse(runtime, { type: "http-chunk", name, requestId, chunk })
401
+ }
402
+ if (state.ended) {
403
+ publishResponse(runtime, { type: "http-end", name, requestId })
404
+ finishStream(runtime, state)
405
+ }
406
+ }
407
+
408
+ /** 流式响应超过上限没有新分片就主动放弃,避免事件总线里留下永远挂着的请求 */
409
+ function touchStream(runtime: ServerRuntime, state: StreamState): void {
410
+ if (state.timer !== null) {
411
+ clearTimeout(state.timer)
412
+ }
413
+ state.timer = setTimeout(() => {
414
+ if (state.ended) {
415
+ return
416
+ }
417
+ state.ended = true
418
+ publishResponse(runtime, {
419
+ type: "http-abort",
420
+ name: runtime.options.name,
421
+ requestId: state.requestId,
422
+ message: "流式响应超时",
423
+ })
424
+ finishStream(runtime, state)
425
+ }, runtime.timeoutMs)
426
+ state.timer.unref()
427
+ }
428
+
429
+ function finishStream(runtime: ServerRuntime, state: StreamState): void {
430
+ if (state.timer !== null) {
431
+ clearTimeout(state.timer)
432
+ state.timer = null
433
+ }
434
+ runtime.streams.delete(state.requestId)
435
+ }
436
+
437
+ async function runSocket(
438
+ runtime: ServerRuntime,
439
+ connectionId: string,
440
+ request: HttpRequest,
441
+ ): Promise<void> {
442
+ const name = runtime.options.name
443
+ const handler = runtime.options.websocket
444
+ if (handler === undefined) {
445
+ publishResponse(runtime, {
446
+ type: "websocket-reject",
447
+ name,
448
+ connectionId,
449
+ code: 1008,
450
+ message: "插件没有注册 WebSocket 处理函数",
451
+ })
452
+ return
453
+ }
454
+
455
+ const socketState: SocketState = {
456
+ connectionId,
457
+ messageHandlers: [],
458
+ closeHandlers: [],
459
+ closed: false,
460
+ }
461
+ runtime.sockets.set(connectionId, socketState)
462
+ const socket: BusWebSocket = {
463
+ connectionId,
464
+ send(data: string) {
465
+ if (socketState.closed) {
466
+ return
467
+ }
468
+ publishResponse(runtime, { type: "websocket-send", name, connectionId, data })
469
+ },
470
+ close(code = 1000, reason = "") {
471
+ if (socketState.closed) {
472
+ return
473
+ }
474
+ socketState.closed = true
475
+ runtime.sockets.delete(connectionId)
476
+ publishResponse(runtime, { type: "websocket-close", name, connectionId, code, reason })
477
+ },
478
+ onMessage(handler) {
479
+ socketState.messageHandlers.push(handler)
480
+ },
481
+ onClose(handler) {
482
+ socketState.closeHandlers.push(handler)
483
+ },
484
+ }
485
+ publishResponse(runtime, { type: "websocket-accept", name, connectionId })
486
+ try {
487
+ await handler(socket, request)
488
+ } catch (error) {
489
+ runtime.options.onError?.({ code: "websocket-handler", message: errorMessageOf(error) })
490
+ socket.close(1011, "handler error")
491
+ }
492
+ }