@waq666/pneuma 0.0.0-stage → 0.7.1

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 (708) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +206 -3
  3. package/bin/dsc.js +91 -0
  4. package/bin/headless.cjs +40 -0
  5. package/lib/adapter/core-runtime.d.ts +11 -0
  6. package/lib/adapter/core-runtime.js +259 -0
  7. package/lib/adapter/host.d.ts +18 -0
  8. package/lib/adapter/host.js +14 -0
  9. package/lib/adapter/runtime.d.ts +15 -0
  10. package/lib/adapter/runtime.js +290 -0
  11. package/lib/adapter/transcript.d.ts +184 -0
  12. package/lib/adapter/transcript.js +605 -0
  13. package/lib/app/AgentsOverlay.d.ts +18 -0
  14. package/lib/app/AgentsOverlay.js +63 -0
  15. package/lib/app/App.d.ts +15 -0
  16. package/lib/app/App.js +1650 -0
  17. package/lib/app/App.js.nv-backup +1650 -0
  18. package/lib/app/ApprovalCard.d.ts +12 -0
  19. package/lib/app/ApprovalCard.js +76 -0
  20. package/lib/app/AskCard.d.ts +20 -0
  21. package/lib/app/AskCard.js +45 -0
  22. package/lib/app/ChatView.d.ts +63 -0
  23. package/lib/app/ChatView.js +310 -0
  24. package/lib/app/Composer.d.ts +50 -0
  25. package/lib/app/Composer.js +282 -0
  26. package/lib/app/DiffBlock.d.ts +6 -0
  27. package/lib/app/DiffBlock.js +37 -0
  28. package/lib/app/MarkdownView.d.ts +6 -0
  29. package/lib/app/MarkdownView.js +99 -0
  30. package/lib/app/ModelPicker.d.ts +7 -0
  31. package/lib/app/ModelPicker.js +18 -0
  32. package/lib/app/PlanReviewCard.d.ts +13 -0
  33. package/lib/app/PlanReviewCard.js +54 -0
  34. package/lib/app/PresetPicker.d.ts +11 -0
  35. package/lib/app/PresetPicker.js +19 -0
  36. package/lib/app/PreviewOverlay.d.ts +14 -0
  37. package/lib/app/PreviewOverlay.js +22 -0
  38. package/lib/app/SessionPicker.d.ts +43 -0
  39. package/lib/app/SessionPicker.js +56 -0
  40. package/lib/app/SettingsOverlay.d.ts +32 -0
  41. package/lib/app/SettingsOverlay.js +157 -0
  42. package/lib/app/SkillsPicker.d.ts +7 -0
  43. package/lib/app/SkillsPicker.js +19 -0
  44. package/lib/app/StatusBar.d.ts +22 -0
  45. package/lib/app/StatusBar.js +201 -0
  46. package/lib/app/TaskStrips.d.ts +13 -0
  47. package/lib/app/TaskStrips.js +40 -0
  48. package/lib/app/TimelineRail.d.ts +22 -0
  49. package/lib/app/TimelineRail.js +160 -0
  50. package/lib/app/TimelineRail.js.negbak +98 -0
  51. package/lib/app/TimelineRail.js.nv-backup +160 -0
  52. package/lib/app/ToolCard.d.ts +11 -0
  53. package/lib/app/ToolCard.js +64 -0
  54. package/lib/app/ToolCard.js.nv-backup +64 -0
  55. package/lib/app/TranscriptOverlay.d.ts +27 -0
  56. package/lib/app/TranscriptOverlay.js +36 -0
  57. package/lib/app/TranscriptViewport.d.ts +78 -0
  58. package/lib/app/TranscriptViewport.js +218 -0
  59. package/lib/app/Welcome.d.ts +6 -0
  60. package/lib/app/Welcome.js +71 -0
  61. package/lib/app/attach.d.ts +16 -0
  62. package/lib/app/attach.js +58 -0
  63. package/lib/app/click.d.ts +40 -0
  64. package/lib/app/click.js +103 -0
  65. package/lib/app/clipboard-image.d.ts +11 -0
  66. package/lib/app/clipboard-image.js +66 -0
  67. package/lib/app/cursor.d.ts +4 -0
  68. package/lib/app/cursor.js +24 -0
  69. package/lib/app/hello.d.ts +11 -0
  70. package/lib/app/hello.js +8 -0
  71. package/lib/app/history-store.d.ts +4 -0
  72. package/lib/app/history-store.js +41 -0
  73. package/lib/app/image-blocks.d.ts +12 -0
  74. package/lib/app/image-blocks.js +125 -0
  75. package/lib/app/keymap.d.ts +56 -0
  76. package/lib/app/keymap.js +56 -0
  77. package/lib/app/markdown.d.ts +54 -0
  78. package/lib/app/markdown.js +189 -0
  79. package/lib/app/mouse.d.ts +33 -0
  80. package/lib/app/mouse.js +35 -0
  81. package/lib/app/pointer.d.ts +16 -0
  82. package/lib/app/pointer.js +60 -0
  83. package/lib/app/scroll-model.d.ts +240 -0
  84. package/lib/app/scroll-model.js +347 -0
  85. package/lib/app/settings-model.d.ts +69 -0
  86. package/lib/app/settings-model.js +114 -0
  87. package/lib/app/snapshot-subscribe.d.ts +34 -0
  88. package/lib/app/snapshot-subscribe.js +110 -0
  89. package/lib/app/theme.d.ts +194 -0
  90. package/lib/app/theme.js +186 -0
  91. package/lib/app/ticker.d.ts +7 -0
  92. package/lib/app/ticker.js +53 -0
  93. package/lib/boot.d.ts +1 -0
  94. package/lib/boot.js +34 -0
  95. package/lib/commands.d.ts +49 -0
  96. package/lib/commands.js +115 -0
  97. package/lib/contract.d.ts +1973 -0
  98. package/lib/contract.js +36 -0
  99. package/lib/core/agent-roles.d.ts +52 -0
  100. package/lib/core/agent-roles.js +274 -0
  101. package/lib/core/approval-floor.d.ts +183 -0
  102. package/lib/core/approval-floor.js +679 -0
  103. package/lib/core/approval.d.ts +42 -0
  104. package/lib/core/approval.js +8 -0
  105. package/lib/core/audit.d.ts +61 -0
  106. package/lib/core/audit.js +59 -0
  107. package/lib/core/boot-notices.d.ts +6 -0
  108. package/lib/core/boot-notices.js +61 -0
  109. package/lib/core/cdp/actions.d.ts +182 -0
  110. package/lib/core/cdp/actions.js +649 -0
  111. package/lib/core/cdp/launch.d.ts +192 -0
  112. package/lib/core/cdp/launch.js +491 -0
  113. package/lib/core/cdp/snapshot.d.ts +139 -0
  114. package/lib/core/cdp/snapshot.js +316 -0
  115. package/lib/core/cdp/transport.d.ts +160 -0
  116. package/lib/core/cdp/transport.js +359 -0
  117. package/lib/core/command-policy.d.ts +108 -0
  118. package/lib/core/command-policy.js +580 -0
  119. package/lib/core/commands-completion.d.ts +78 -0
  120. package/lib/core/commands-completion.js +167 -0
  121. package/lib/core/compact-anchors.d.ts +76 -0
  122. package/lib/core/compact-anchors.js +284 -0
  123. package/lib/core/compact.d.ts +110 -0
  124. package/lib/core/compact.js +210 -0
  125. package/lib/core/config-store.d.ts +38 -0
  126. package/lib/core/config-store.js +307 -0
  127. package/lib/core/config.d.ts +36 -0
  128. package/lib/core/config.js +124 -0
  129. package/lib/core/connection-test.d.ts +60 -0
  130. package/lib/core/connection-test.js +84 -0
  131. package/lib/core/desktop-control.d.ts +298 -0
  132. package/lib/core/desktop-control.js +1311 -0
  133. package/lib/core/diff-text.d.ts +74 -0
  134. package/lib/core/diff-text.js +257 -0
  135. package/lib/core/dock-browser.d.ts +137 -0
  136. package/lib/core/dock-browser.js +146 -0
  137. package/lib/core/dock-ops.d.ts +59 -0
  138. package/lib/core/dock-ops.js +104 -0
  139. package/lib/core/dock-session.d.ts +39 -0
  140. package/lib/core/dock-session.js +28 -0
  141. package/lib/core/dsh-compat/hook.d.ts +18 -0
  142. package/lib/core/dsh-compat/hook.js +52 -0
  143. package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
  144. package/lib/core/dsh-compat/resolve-hook.js +59 -0
  145. package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
  146. package/lib/core/dsh-compat/tools-facade.js +108 -0
  147. package/lib/core/err-text.d.ts +13 -0
  148. package/lib/core/err-text.js +15 -0
  149. package/lib/core/events.d.ts +149 -0
  150. package/lib/core/events.js +1 -0
  151. package/lib/core/git-exec.d.ts +23 -0
  152. package/lib/core/git-exec.js +72 -0
  153. package/lib/core/git-info.d.ts +47 -0
  154. package/lib/core/git-info.js +157 -0
  155. package/lib/core/goal.d.ts +89 -0
  156. package/lib/core/goal.js +189 -0
  157. package/lib/core/hooks.d.ts +272 -0
  158. package/lib/core/hooks.js +818 -0
  159. package/lib/core/host-browser-link.d.ts +59 -0
  160. package/lib/core/host-browser-link.js +9 -0
  161. package/lib/core/host-methods.d.ts +25 -0
  162. package/lib/core/host-methods.js +103 -0
  163. package/lib/core/image-diet.d.ts +77 -0
  164. package/lib/core/image-diet.js +127 -0
  165. package/lib/core/learnings/ledger.d.ts +73 -0
  166. package/lib/core/learnings/ledger.js +273 -0
  167. package/lib/core/learnings/skill-write.d.ts +250 -0
  168. package/lib/core/learnings/skill-write.js +854 -0
  169. package/lib/core/learnings/store.d.ts +102 -0
  170. package/lib/core/learnings/store.js +266 -0
  171. package/lib/core/lifecycle-hooks.d.ts +189 -0
  172. package/lib/core/lifecycle-hooks.js +576 -0
  173. package/lib/core/llm.d.ts +283 -0
  174. package/lib/core/llm.js +565 -0
  175. package/lib/core/lockfile.d.ts +17 -0
  176. package/lib/core/lockfile.js +110 -0
  177. package/lib/core/loop.d.ts +185 -0
  178. package/lib/core/loop.js +587 -0
  179. package/lib/core/lsp/client.d.ts +189 -0
  180. package/lib/core/lsp/client.js +690 -0
  181. package/lib/core/lsp/framing.d.ts +84 -0
  182. package/lib/core/lsp/framing.js +181 -0
  183. package/lib/core/lsp/line-shift.d.ts +28 -0
  184. package/lib/core/lsp/line-shift.js +127 -0
  185. package/lib/core/lsp/manager.d.ts +93 -0
  186. package/lib/core/lsp/manager.js +418 -0
  187. package/lib/core/lsp/normalize.d.ts +32 -0
  188. package/lib/core/lsp/normalize.js +139 -0
  189. package/lib/core/lsp/servers.d.ts +106 -0
  190. package/lib/core/lsp/servers.js +352 -0
  191. package/lib/core/lsp/uri.d.ts +76 -0
  192. package/lib/core/lsp/uri.js +179 -0
  193. package/lib/core/market.d.ts +51 -0
  194. package/lib/core/market.js +358 -0
  195. package/lib/core/mcp.d.ts +201 -0
  196. package/lib/core/mcp.js +836 -0
  197. package/lib/core/memory-eval.d.ts +158 -0
  198. package/lib/core/memory-eval.js +215 -0
  199. package/lib/core/memory.d.ts +266 -0
  200. package/lib/core/memory.js +703 -0
  201. package/lib/core/mention.d.ts +57 -0
  202. package/lib/core/mention.js +129 -0
  203. package/lib/core/microcompact.d.ts +48 -0
  204. package/lib/core/microcompact.js +79 -0
  205. package/lib/core/migrate.d.ts +56 -0
  206. package/lib/core/migrate.js +134 -0
  207. package/lib/core/model-caps.d.ts +83 -0
  208. package/lib/core/model-caps.js +150 -0
  209. package/lib/core/model-discovery.d.ts +19 -0
  210. package/lib/core/model-discovery.js +69 -0
  211. package/lib/core/modes.d.ts +72 -0
  212. package/lib/core/modes.js +152 -0
  213. package/lib/core/native-bridge.d.ts +135 -0
  214. package/lib/core/native-bridge.js +563 -0
  215. package/lib/core/path-policy.d.ts +32 -0
  216. package/lib/core/path-policy.js +248 -0
  217. package/lib/core/permission-presets.d.ts +67 -0
  218. package/lib/core/permission-presets.js +75 -0
  219. package/lib/core/plugin-loader.d.ts +36 -0
  220. package/lib/core/plugin-loader.js +294 -0
  221. package/lib/core/plugin-registry.d.ts +113 -0
  222. package/lib/core/plugin-registry.js +256 -0
  223. package/lib/core/prefs.d.ts +82 -0
  224. package/lib/core/prefs.js +372 -0
  225. package/lib/core/presets.d.ts +80 -0
  226. package/lib/core/presets.js +373 -0
  227. package/lib/core/pricing.d.ts +90 -0
  228. package/lib/core/pricing.js +126 -0
  229. package/lib/core/prompt.d.ts +92 -0
  230. package/lib/core/prompt.js +339 -0
  231. package/lib/core/ptc.d.ts +66 -0
  232. package/lib/core/ptc.js +70 -0
  233. package/lib/core/remote/frames.d.ts +91 -0
  234. package/lib/core/remote/frames.js +174 -0
  235. package/lib/core/remote/notify.d.ts +54 -0
  236. package/lib/core/remote/notify.js +77 -0
  237. package/lib/core/remote/owner.d.ts +32 -0
  238. package/lib/core/remote/owner.js +75 -0
  239. package/lib/core/remote/pairing.d.ts +104 -0
  240. package/lib/core/remote/pairing.js +261 -0
  241. package/lib/core/remote/push.d.ts +80 -0
  242. package/lib/core/remote/push.js +222 -0
  243. package/lib/core/remote/store.d.ts +18 -0
  244. package/lib/core/remote/store.js +59 -0
  245. package/lib/core/remote/tickets.d.ts +20 -0
  246. package/lib/core/remote/tickets.js +49 -0
  247. package/lib/core/remote/uploads.d.ts +63 -0
  248. package/lib/core/remote/uploads.js +161 -0
  249. package/lib/core/request-attribution.d.ts +26 -0
  250. package/lib/core/request-attribution.js +86 -0
  251. package/lib/core/request-invariant.d.ts +61 -0
  252. package/lib/core/request-invariant.js +199 -0
  253. package/lib/core/sandbox/backends.d.ts +64 -0
  254. package/lib/core/sandbox/backends.js +194 -0
  255. package/lib/core/sandbox/execpolicy.d.ts +93 -0
  256. package/lib/core/sandbox/execpolicy.js +452 -0
  257. package/lib/core/sandbox/net-proxy.d.ts +31 -0
  258. package/lib/core/sandbox/net-proxy.js +162 -0
  259. package/lib/core/sandbox/policy.d.ts +211 -0
  260. package/lib/core/sandbox/policy.js +559 -0
  261. package/lib/core/sandbox/win/abi.d.ts +161 -0
  262. package/lib/core/sandbox/win/abi.js +169 -0
  263. package/lib/core/sandbox/win/account.d.ts +71 -0
  264. package/lib/core/sandbox/win/account.js +206 -0
  265. package/lib/core/sandbox/win/acl.d.ts +54 -0
  266. package/lib/core/sandbox/win/acl.js +339 -0
  267. package/lib/core/sandbox/win/backend.d.ts +61 -0
  268. package/lib/core/sandbox/win/backend.js +249 -0
  269. package/lib/core/sandbox/win/doctor.d.ts +24 -0
  270. package/lib/core/sandbox/win/doctor.js +272 -0
  271. package/lib/core/sandbox/win/ffi.d.ts +107 -0
  272. package/lib/core/sandbox/win/ffi.js +166 -0
  273. package/lib/core/sandbox/win/net-abi.d.ts +154 -0
  274. package/lib/core/sandbox/win/net-abi.js +316 -0
  275. package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
  276. package/lib/core/sandbox/win/runner-entry.js +391 -0
  277. package/lib/core/sandbox/win/setup.d.ts +60 -0
  278. package/lib/core/sandbox/win/setup.js +986 -0
  279. package/lib/core/sandbox/win/token.d.ts +35 -0
  280. package/lib/core/sandbox/win/token.js +238 -0
  281. package/lib/core/sandbox/win/wfp.d.ts +41 -0
  282. package/lib/core/sandbox/win/wfp.js +200 -0
  283. package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
  284. package/lib/core/sandbox/win/workspace-sid.js +45 -0
  285. package/lib/core/schedule/rule.d.ts +184 -0
  286. package/lib/core/schedule/rule.js +745 -0
  287. package/lib/core/schedule/runner.d.ts +185 -0
  288. package/lib/core/schedule/runner.js +678 -0
  289. package/lib/core/schedule/store.d.ts +182 -0
  290. package/lib/core/schedule/store.js +455 -0
  291. package/lib/core/secrets.d.ts +41 -0
  292. package/lib/core/secrets.js +150 -0
  293. package/lib/core/session-export.d.ts +18 -0
  294. package/lib/core/session-export.js +73 -0
  295. package/lib/core/session-index.d.ts +159 -0
  296. package/lib/core/session-index.js +683 -0
  297. package/lib/core/session-meta.d.ts +41 -0
  298. package/lib/core/session-meta.js +97 -0
  299. package/lib/core/session.d.ts +356 -0
  300. package/lib/core/session.js +998 -0
  301. package/lib/core/skills.d.ts +60 -0
  302. package/lib/core/skills.js +171 -0
  303. package/lib/core/spill.d.ts +159 -0
  304. package/lib/core/spill.js +329 -0
  305. package/lib/core/surface-registry.d.ts +45 -0
  306. package/lib/core/surface-registry.js +67 -0
  307. package/lib/core/team-board.d.ts +95 -0
  308. package/lib/core/team-board.js +316 -0
  309. package/lib/core/throughput.d.ts +46 -0
  310. package/lib/core/throughput.js +40 -0
  311. package/lib/core/todo-reminder.d.ts +44 -0
  312. package/lib/core/todo-reminder.js +55 -0
  313. package/lib/core/todo.d.ts +81 -0
  314. package/lib/core/todo.js +222 -0
  315. package/lib/core/token-estimate.d.ts +55 -0
  316. package/lib/core/token-estimate.js +82 -0
  317. package/lib/core/tool-guards.d.ts +103 -0
  318. package/lib/core/tool-guards.js +77 -0
  319. package/lib/core/tool-search.d.ts +152 -0
  320. package/lib/core/tool-search.js +311 -0
  321. package/lib/core/tools/bash.d.ts +281 -0
  322. package/lib/core/tools/bash.js +871 -0
  323. package/lib/core/tools/command-runner.d.ts +84 -0
  324. package/lib/core/tools/command-runner.js +68 -0
  325. package/lib/core/tools/fs-tools.d.ts +23 -0
  326. package/lib/core/tools/fs-tools.js +247 -0
  327. package/lib/core/tools/index.d.ts +8 -0
  328. package/lib/core/tools/index.js +4 -0
  329. package/lib/core/tools/sandbox-args.d.ts +51 -0
  330. package/lib/core/tools/sandbox-args.js +90 -0
  331. package/lib/core/tools/search-tools.d.ts +3 -0
  332. package/lib/core/tools/search-tools.js +153 -0
  333. package/lib/core/tools.d.ts +96 -0
  334. package/lib/core/tools.js +53 -0
  335. package/lib/core/ui-boot-source.d.ts +71 -0
  336. package/lib/core/ui-boot-source.js +121 -0
  337. package/lib/core/ui-bundles.d.ts +249 -0
  338. package/lib/core/ui-bundles.js +830 -0
  339. package/lib/core/ui-combo.d.ts +49 -0
  340. package/lib/core/ui-combo.js +55 -0
  341. package/lib/core/ui-events.d.ts +81 -0
  342. package/lib/core/ui-events.js +364 -0
  343. package/lib/core/ui-hmr.d.ts +36 -0
  344. package/lib/core/ui-hmr.js +128 -0
  345. package/lib/core/ui-methods.d.ts +69 -0
  346. package/lib/core/ui-methods.js +341 -0
  347. package/lib/core/ui-route.d.ts +69 -0
  348. package/lib/core/ui-route.js +122 -0
  349. package/lib/core/ui-server.d.ts +75 -0
  350. package/lib/core/ui-server.js +369 -0
  351. package/lib/core/ui-trust.d.ts +47 -0
  352. package/lib/core/ui-trust.js +164 -0
  353. package/lib/core/untrusted.d.ts +30 -0
  354. package/lib/core/untrusted.js +48 -0
  355. package/lib/core/update-check.d.ts +81 -0
  356. package/lib/core/update-check.js +177 -0
  357. package/lib/core/usage-log.d.ts +82 -0
  358. package/lib/core/usage-log.js +306 -0
  359. package/lib/core/version.d.ts +1 -0
  360. package/lib/core/version.js +37 -0
  361. package/lib/core/web-http.d.ts +57 -0
  362. package/lib/core/web-http.js +137 -0
  363. package/lib/core/web-static.d.ts +31 -0
  364. package/lib/core/web-static.js +75 -0
  365. package/lib/headless.d.ts +1 -0
  366. package/lib/headless.js +31 -0
  367. package/lib/host/kernel.d.ts +33 -0
  368. package/lib/host/kernel.js +451 -0
  369. package/lib/index.d.ts +41 -0
  370. package/lib/index.js +35 -0
  371. package/lib/plugins/agent.d.ts +2 -0
  372. package/lib/plugins/agent.js +274 -0
  373. package/lib/plugins/approval-floor.d.ts +2 -0
  374. package/lib/plugins/approval-floor.js +223 -0
  375. package/lib/plugins/approval.d.ts +16 -0
  376. package/lib/plugins/approval.js +674 -0
  377. package/lib/plugins/ask.d.ts +2 -0
  378. package/lib/plugins/ask.js +245 -0
  379. package/lib/plugins/browser.d.ts +68 -0
  380. package/lib/plugins/browser.js +1341 -0
  381. package/lib/plugins/commands.d.ts +23 -0
  382. package/lib/plugins/commands.js +498 -0
  383. package/lib/plugins/compact.d.ts +21 -0
  384. package/lib/plugins/compact.js +274 -0
  385. package/lib/plugins/computer-use.d.ts +47 -0
  386. package/lib/plugins/computer-use.js +539 -0
  387. package/lib/plugins/desktop-dock.d.ts +2 -0
  388. package/lib/plugins/desktop-dock.js +626 -0
  389. package/lib/plugins/dock-browser.d.ts +34 -0
  390. package/lib/plugins/dock-browser.js +765 -0
  391. package/lib/plugins/dsh-compat.d.ts +25 -0
  392. package/lib/plugins/dsh-compat.js +37 -0
  393. package/lib/plugins/file-review.d.ts +108 -0
  394. package/lib/plugins/file-review.js +393 -0
  395. package/lib/plugins/git.d.ts +26 -0
  396. package/lib/plugins/git.js +132 -0
  397. package/lib/plugins/goal.d.ts +20 -0
  398. package/lib/plugins/goal.js +245 -0
  399. package/lib/plugins/guards.d.ts +14 -0
  400. package/lib/plugins/guards.js +18 -0
  401. package/lib/plugins/hooks.d.ts +19 -0
  402. package/lib/plugins/hooks.js +583 -0
  403. package/lib/plugins/host-stdio.d.ts +88 -0
  404. package/lib/plugins/host-stdio.js +317 -0
  405. package/lib/plugins/image-diet.d.ts +17 -0
  406. package/lib/plugins/image-diet.js +85 -0
  407. package/lib/plugins/lifecycle-hooks.d.ts +26 -0
  408. package/lib/plugins/lifecycle-hooks.js +338 -0
  409. package/lib/plugins/llm.d.ts +13 -0
  410. package/lib/plugins/llm.js +215 -0
  411. package/lib/plugins/lsp.d.ts +54 -0
  412. package/lib/plugins/lsp.js +608 -0
  413. package/lib/plugins/mcp.d.ts +16 -0
  414. package/lib/plugins/mcp.js +673 -0
  415. package/lib/plugins/memory.d.ts +17 -0
  416. package/lib/plugins/memory.js +858 -0
  417. package/lib/plugins/microcompact.d.ts +18 -0
  418. package/lib/plugins/microcompact.js +119 -0
  419. package/lib/plugins/mode.d.ts +18 -0
  420. package/lib/plugins/mode.js +115 -0
  421. package/lib/plugins/permission-presets.d.ts +18 -0
  422. package/lib/plugins/permission-presets.js +135 -0
  423. package/lib/plugins/plan.d.ts +2 -0
  424. package/lib/plugins/plan.js +192 -0
  425. package/lib/plugins/plugin-manager.d.ts +2 -0
  426. package/lib/plugins/plugin-manager.js +165 -0
  427. package/lib/plugins/presets.d.ts +2 -0
  428. package/lib/plugins/presets.js +182 -0
  429. package/lib/plugins/prompt.d.ts +2 -0
  430. package/lib/plugins/prompt.js +264 -0
  431. package/lib/plugins/ptc.d.ts +2 -0
  432. package/lib/plugins/ptc.js +272 -0
  433. package/lib/plugins/remote/http.d.ts +11 -0
  434. package/lib/plugins/remote/http.js +11 -0
  435. package/lib/plugins/remote/routes.d.ts +24 -0
  436. package/lib/plugins/remote/routes.js +384 -0
  437. package/lib/plugins/remote/types.d.ts +135 -0
  438. package/lib/plugins/remote/types.js +87 -0
  439. package/lib/plugins/remote.d.ts +17 -0
  440. package/lib/plugins/remote.js +1028 -0
  441. package/lib/plugins/runtime-api.d.ts +16 -0
  442. package/lib/plugins/runtime-api.js +99 -0
  443. package/lib/plugins/runtime.d.ts +10 -0
  444. package/lib/plugins/runtime.js +451 -0
  445. package/lib/plugins/sandbox.d.ts +2 -0
  446. package/lib/plugins/sandbox.js +761 -0
  447. package/lib/plugins/schedule.d.ts +26 -0
  448. package/lib/plugins/schedule.js +538 -0
  449. package/lib/plugins/self-improve.d.ts +61 -0
  450. package/lib/plugins/self-improve.js +953 -0
  451. package/lib/plugins/session-search.d.ts +16 -0
  452. package/lib/plugins/session-search.js +308 -0
  453. package/lib/plugins/session-title.d.ts +19 -0
  454. package/lib/plugins/session-title.js +109 -0
  455. package/lib/plugins/session.d.ts +7 -0
  456. package/lib/plugins/session.js +296 -0
  457. package/lib/plugins/settings.d.ts +3 -0
  458. package/lib/plugins/settings.js +705 -0
  459. package/lib/plugins/skills.d.ts +2 -0
  460. package/lib/plugins/skills.js +360 -0
  461. package/lib/plugins/spill.d.ts +16 -0
  462. package/lib/plugins/spill.js +200 -0
  463. package/lib/plugins/subagent.d.ts +2 -0
  464. package/lib/plugins/subagent.js +896 -0
  465. package/lib/plugins/surfaces.d.ts +11 -0
  466. package/lib/plugins/surfaces.js +20 -0
  467. package/lib/plugins/team.d.ts +16 -0
  468. package/lib/plugins/team.js +149 -0
  469. package/lib/plugins/todo.d.ts +19 -0
  470. package/lib/plugins/todo.js +188 -0
  471. package/lib/plugins/tool-search.d.ts +2 -0
  472. package/lib/plugins/tool-search.js +434 -0
  473. package/lib/plugins/tool-search.js.nv-backup +434 -0
  474. package/lib/plugins/tools-default.d.ts +12 -0
  475. package/lib/plugins/tools-default.js +275 -0
  476. package/lib/plugins/tools.d.ts +16 -0
  477. package/lib/plugins/tools.js +62 -0
  478. package/lib/plugins/transcript.d.ts +15 -0
  479. package/lib/plugins/transcript.js +311 -0
  480. package/lib/plugins/tui.d.ts +2 -0
  481. package/lib/plugins/tui.js +98 -0
  482. package/lib/plugins/waiting.d.ts +12 -0
  483. package/lib/plugins/waiting.js +34 -0
  484. package/lib/plugins/web-search.d.ts +14 -0
  485. package/lib/plugins/web-search.js +263 -0
  486. package/lib/plugins/webserver.d.ts +48 -0
  487. package/lib/plugins/webserver.js +228 -0
  488. package/lib/remote/assets/app-DAcUCOEn.js +14 -0
  489. package/lib/remote/assets/icon-192.png +0 -0
  490. package/lib/remote/assets/icon-512.png +0 -0
  491. package/lib/remote/assets/index.html +34 -0
  492. package/lib/remote/assets/manifest.json +27 -0
  493. package/lib/remote/assets/style-DIB6729x.css +1 -0
  494. package/lib/remote/assets/sw.js +66 -0
  495. package/lib/services/types.d.ts +1228 -0
  496. package/lib/services/types.js +1 -0
  497. package/lib/tools/config-cli.d.ts +1 -0
  498. package/lib/tools/config-cli.js +89 -0
  499. package/lib/ui/arrival.d.ts +72 -0
  500. package/lib/ui/arrival.js +105 -0
  501. package/lib/ui/assets/app-B70nVIKd.js +69 -0
  502. package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
  503. package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
  504. package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
  505. package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
  506. package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
  507. package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
  508. package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
  509. package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
  510. package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
  511. package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
  512. package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
  513. package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
  514. package/lib/ui/assets/chunk-BajyYBss.js +10 -0
  515. package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
  516. package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
  517. package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
  518. package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
  519. package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
  520. package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
  521. package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
  522. package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
  523. package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
  524. package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
  525. package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
  526. package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
  527. package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
  528. package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
  529. package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
  530. package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
  531. package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
  532. package/lib/ui/assets/chunk-CickPsom.js +1 -0
  533. package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
  534. package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
  535. package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
  536. package/lib/ui/assets/chunk-CqE71os6.js +1 -0
  537. package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
  538. package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
  539. package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
  540. package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
  541. package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
  542. package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
  543. package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
  544. package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
  545. package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
  546. package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
  547. package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
  548. package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
  549. package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
  550. package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
  551. package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
  552. package/lib/ui/assets/chunk-De0Btta0.js +1 -0
  553. package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
  554. package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
  555. package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
  556. package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
  557. package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
  558. package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
  559. package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
  560. package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
  561. package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
  562. package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
  563. package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
  564. package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
  565. package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
  566. package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
  567. package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
  568. package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
  569. package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
  570. package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
  571. package/lib/ui/assets/icon.png +0 -0
  572. package/lib/ui/assets/index.html +14 -0
  573. package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
  574. package/lib/ui/assets/style-Bq01xH_b.css +1 -0
  575. package/lib/ui/frames.d.ts +67 -0
  576. package/lib/ui/frames.js +146 -0
  577. package/lib/ui/index.d.ts +59 -0
  578. package/lib/ui/index.js +50 -0
  579. package/lib/ui/manifest.d.ts +172 -0
  580. package/lib/ui/manifest.js +158 -0
  581. package/lib/ui/plugin.d.ts +161 -0
  582. package/lib/ui/plugin.js +7 -0
  583. package/lib/ui/plugins/browser/client.js +290 -0
  584. package/lib/ui/plugins/browser/icon.png +0 -0
  585. package/lib/ui/plugins/composer/client.js +1843 -0
  586. package/lib/ui/plugins/composer/icon.png +0 -0
  587. package/lib/ui/plugins/files/client.js +646 -0
  588. package/lib/ui/plugins/files/icon.png +0 -0
  589. package/lib/ui/plugins/manifest.json +107 -0
  590. package/lib/ui/plugins/plugins/client.js +682 -0
  591. package/lib/ui/plugins/plugins/icon.png +0 -0
  592. package/lib/ui/plugins/preview/client.js +197 -0
  593. package/lib/ui/plugins/preview/icon.png +0 -0
  594. package/lib/ui/plugins/prompt/client.js +653 -0
  595. package/lib/ui/plugins/prompt/icon.png +0 -0
  596. package/lib/ui/plugins/sessions/client.js +1577 -0
  597. package/lib/ui/plugins/sessions/icon.png +0 -0
  598. package/lib/ui/plugins/settings/client.js +5470 -0
  599. package/lib/ui/plugins/settings/icon.png +0 -0
  600. package/lib/ui/plugins/skills/client.js +485 -0
  601. package/lib/ui/plugins/skills/icon.png +0 -0
  602. package/lib/ui/plugins/status/client.js +1420 -0
  603. package/lib/ui/plugins/status/icon.png +0 -0
  604. package/lib/ui/plugins/statusbar/client.js +504 -0
  605. package/lib/ui/plugins/statusbar/icon.png +0 -0
  606. package/lib/ui/plugins/tasks/client.js +52 -0
  607. package/lib/ui/plugins/tasks/icon.png +0 -0
  608. package/lib/ui/plugins/team/client.js +527 -0
  609. package/lib/ui/plugins/team/icon.png +0 -0
  610. package/lib/ui/plugins/terminal/client.js +232 -0
  611. package/lib/ui/plugins/terminal/icon.png +0 -0
  612. package/lib/ui/plugins/trace/client.js +1376 -0
  613. package/lib/ui/plugins/trace/icon.png +0 -0
  614. package/lib/ui/plugins/transcript/client.js +2661 -0
  615. package/lib/ui/plugins/transcript/icon.png +0 -0
  616. package/lib/ui/scoped-slots.d.ts +20 -0
  617. package/lib/ui/scoped-slots.js +21 -0
  618. package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
  619. package/lib/ui/sdk/@dsc/ui/package.json +16 -0
  620. package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
  621. package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
  622. package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
  623. package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
  624. package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
  625. package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
  626. package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
  627. package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
  628. package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
  629. package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
  630. package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
  631. package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
  632. package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
  633. package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
  634. package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
  635. package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
  636. package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
  637. package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
  638. package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
  639. package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
  640. package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
  641. package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
  642. package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
  643. package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
  644. package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
  645. package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
  646. package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
  647. package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
  648. package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
  649. package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
  650. package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
  651. package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
  652. package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
  653. package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
  654. package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
  655. package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
  656. package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
  657. package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
  658. package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
  659. package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
  660. package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
  661. package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
  662. package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
  663. package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
  664. package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
  665. package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
  666. package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
  667. package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
  668. package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
  669. package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
  670. package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
  671. package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
  672. package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
  673. package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
  674. package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
  675. package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
  676. package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
  677. package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
  678. package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
  679. package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
  680. package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
  681. package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
  682. package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
  683. package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
  684. package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
  685. package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
  686. package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
  687. package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
  688. package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
  689. package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
  690. package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
  691. package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
  692. package/lib/ui/services-react.d.ts +27 -0
  693. package/lib/ui/services-react.js +32 -0
  694. package/lib/ui/services.d.ts +63 -0
  695. package/lib/ui/services.js +121 -0
  696. package/lib/ui/slots-ink.d.ts +26 -0
  697. package/lib/ui/slots-ink.js +78 -0
  698. package/lib/ui/slots-react.d.ts +28 -0
  699. package/lib/ui/slots-react.js +88 -0
  700. package/lib/ui/slots.d.ts +481 -0
  701. package/lib/ui/slots.js +550 -0
  702. package/lib/ui/store.d.ts +89 -0
  703. package/lib/ui/store.js +62 -0
  704. package/lib/ui/tui-plugin-api.d.ts +23 -0
  705. package/lib/ui/tui-plugin-api.js +23 -0
  706. package/lib/ui/tui-plugins.d.ts +47 -0
  707. package/lib/ui/tui-plugins.js +220 -0
  708. package/package.json +58 -6
@@ -0,0 +1,871 @@
1
+ /**
2
+ * bash 工具:在会话目录里执行 shell 命令。win32 走 PowerShell(缺省
3
+ * powershell.exe),POSIX 走 sh;stdout/stderr 合并返回,超时与长度封顶。
4
+ *
5
+ * 工具自己这一层做三件事(审批层做的是「要不要问」,不是这三件):
6
+ * 1. 硬地板:策略引擎判成 deny 的命令在任何权限模式下都不执行;
7
+ * 2. 子进程环境脱敏:dsc 自己的 API key 与各种 *_TOKEN 不传进去;
8
+ * 3. 输出遮红:命令输出里密钥形状的字符串换成占位。
9
+ *
10
+ * @module dsc/core/tools/bash
11
+ */
12
+ import { spawn } from 'node:child_process';
13
+ import { classifyCommand } from '../command-policy.js';
14
+ import { redact, scrubChildEnv } from '../secrets.js';
15
+ import { wrapUntrusted } from '../untrusted.js';
16
+ import { finishCommand, planCommand } from './command-runner.js';
17
+ import { sandboxPermissionProperties } from './sandbox-args.js';
18
+ const isWin = process.platform === 'win32';
19
+ /** 缺省预算(配置没给值时用)。 */
20
+ export const BASH_DEFAULT_BUDGETS = {
21
+ timeoutMs: 30_000,
22
+ maxTimeoutMs: 120_000,
23
+ outputChars: 8_000,
24
+ };
25
+ /** 会从网上拉内容的命令:输出是外部数据,进对话前必须过围栏(网页里的「指令」不是给你的)。 */
26
+ export const NETWORK_FETCH_RE = /\b(curl|wget|invoke-webrequest|invoke-restmethod|iwr|irm)(\.exe)?\b/i;
27
+ /**
28
+ * 收掉一整棵进程树(2026-09-29):`child.kill` 只杀直系子进程——
29
+ * Windows 上 powershell.exe 被杀后里面跑的构建工具会变孤儿继续跑;
30
+ * POSIX 上 `sh -c` 收到 SIGKILL 也不会转发给孙进程。
31
+ * Windows 用 taskkill /T;POSIX 用 detached 进程组负数 pid 全组杀。
32
+ * T15 后台作业的 job_kill 复用这一份。
33
+ */
34
+ export function killTree(child) {
35
+ if (child.pid === undefined)
36
+ return;
37
+ if (process.platform === 'win32') {
38
+ spawn('taskkill', ['/PID', String(child.pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true });
39
+ }
40
+ else {
41
+ try {
42
+ process.kill(-child.pid, 'SIGKILL');
43
+ }
44
+ catch {
45
+ child.kill('SIGKILL');
46
+ }
47
+ }
48
+ }
49
+ /** 优雅终止后的宽限期(T36):到点还没自己退,才上强杀。 */
50
+ const KILL_GRACE_MS = 3_000;
51
+ /** 强杀之后还没等到 close 的最后兜底(T36):再等不到就把已收输出直接交回。 */
52
+ const FORCE_FAILSAFE_MS = 2_000;
53
+ /**
54
+ * 第一档终止(T36):礼貌地请进程退——构建工具能跑完清理逻辑、缓存能落盘。
55
+ * POSIX 对 detached 的进程组发 SIGTERM(负数 pid 整组收到)。Windows 没有不依赖
56
+ * 外部进程的优雅通道(taskkill 不带 /F 那条路被安全门的命令选项注入检查拦着,
57
+ * 不为它新开 spawn),所以 Windows 这一档直接走 {@link killTree} 强杀——糙一点,
58
+ * 但一定杀得掉,已收输出也照样交回。
59
+ */
60
+ function terminateTree(child) {
61
+ if (process.platform === 'win32') {
62
+ killTree(child);
63
+ return;
64
+ }
65
+ if (child.pid === undefined)
66
+ return;
67
+ try {
68
+ process.kill(-child.pid, 'SIGTERM');
69
+ }
70
+ catch {
71
+ child.kill('SIGTERM');
72
+ }
73
+ }
74
+ /**
75
+ * T15:后台作业进程的登记表与整树收尾。收尾只拿字符串键进来——
76
+ * 进程对象不过作业表的手,整树机制(taskkill /T /F 或组强杀)留在本文件。
77
+ */
78
+ const backgroundChildren = new Map();
79
+ /** T15/T20:登记一个常驻进程(后台作业经 trackKey 走 spawnShell 内的同一张表)。 */
80
+ export function trackBackgroundChild(key, child) {
81
+ backgroundChildren.set(key, child);
82
+ }
83
+ /** T20:摘掉登记(进程自然退出或已收尾时调,防表里留死键)。 */
84
+ export function untrackBackgroundChild(key) {
85
+ backgroundChildren.delete(key);
86
+ }
87
+ /** T20:查一个登记过的进程(终端会话往输入口写字要用它);键不存在返回 undefined。 */
88
+ export function trackedBackgroundChild(key) {
89
+ return backgroundChildren.get(key);
90
+ }
91
+ /** 收掉登记过的后台作业进程(整树);键不存在返回 false。 */
92
+ export function stopBackgroundChild(key) {
93
+ const child = backgroundChildren.get(key);
94
+ if (child === undefined)
95
+ return false;
96
+ backgroundChildren.delete(key);
97
+ killTree(child);
98
+ return true;
99
+ }
100
+ /** T15:内核收摊时收掉全部还在跑的后台作业(tools-default 的卸载钩子调)。 */
101
+ export function stopAllBackgroundChildren() {
102
+ for (const child of backgroundChildren.values())
103
+ killTree(child);
104
+ backgroundChildren.clear();
105
+ }
106
+ /**
107
+ * 真正 spawn 并收输出。执行计划可能被沙箱的执行器缝改写
108
+ * (容器后端会把 shell 换成 `docker run`),所以这里不认死 `powershell.exe`。
109
+ *
110
+ * T15:后台作业复用这一份——不挂 meaningful 超时(给一天的描述值)、
111
+ * 不接取消信号,靠 onChunk 收增量、onExit 收退出码、trackKey 进登记表。
112
+ */
113
+ export function spawnShell(plan, timeoutMs, outputLimit, signal, options) {
114
+ return new Promise((resolvePromise, rejectPromise) => {
115
+ // 执行计划带了自定义 spawn(受限令牌这类 node spawn 表达不了的)就走它;
116
+ // 默认路径与加这条缝之前完全一致。
117
+ const child = plan.spawn
118
+ ? plan.spawn()
119
+ : spawn(plan.file, plan.args, {
120
+ cwd: plan.cwd,
121
+ env: plan.env,
122
+ // stdin 直接关掉:等输入的命令立即失败退出,好过挂到超时才死;
123
+ // POSIX 上 detached 让子命令自成进程组,超时能整组收掉。
124
+ stdio: ['ignore', 'pipe', 'pipe'],
125
+ windowsHide: true,
126
+ detached: process.platform !== 'win32',
127
+ });
128
+ if (options?.trackKey !== undefined)
129
+ backgroundChildren.set(options.trackKey, child);
130
+ const untrack = () => {
131
+ if (options?.trackKey !== undefined)
132
+ backgroundChildren.delete(options.trackKey);
133
+ };
134
+ let output = '';
135
+ const append = (chunk) => {
136
+ const text = String(chunk);
137
+ if (output.length < outputLimit * 2)
138
+ output += text;
139
+ options?.onChunk?.(text);
140
+ };
141
+ child.stdout?.on('data', append);
142
+ child.stderr?.on('data', append);
143
+ // T36:超时/取消不再把输出丢掉——先礼貌终止(POSIX SIGTERM,宽限 3 秒,到点强杀),
144
+ // 等进程真正退出后把已收到的输出连同终止说明一起交回。编译错误印在前 20 秒、
145
+ // 31 秒超时的场景,模型现在拿得到那 20 秒里说过的每句话。
146
+ let done = false;
147
+ let reason = null;
148
+ let grace;
149
+ let failsafe;
150
+ const finish = (code) => {
151
+ if (done)
152
+ return;
153
+ done = true;
154
+ clearTimeout(timer);
155
+ if (grace !== undefined)
156
+ clearTimeout(grace);
157
+ if (failsafe !== undefined)
158
+ clearTimeout(failsafe);
159
+ signal.removeEventListener('abort', onAbort);
160
+ untrack();
161
+ options?.onExit?.(code);
162
+ const truncated = output.length > outputLimit ? `${output.slice(0, outputLimit)}…(已截断)` : output;
163
+ const body = truncated.trim();
164
+ const lines = [];
165
+ if (reason !== null)
166
+ lines.push(reason);
167
+ if (code !== 0 && reason === null)
168
+ lines.push(`退出码 ${String(code)}`);
169
+ lines.push(body === '' ? (reason === null ? '(无输出)' : '(进程被终止,没有收到输出)') : body);
170
+ resolvePromise(redact(lines.join('\n')));
171
+ };
172
+ const arm = (why) => {
173
+ reason = why;
174
+ terminateTree(child);
175
+ // 宽限到点还没退就强杀;强杀后再等不到 close(极端:句柄被别的进程攥着)
176
+ // 就把已收输出直接交回,不让整轮挂在僵尸进程上。
177
+ grace = setTimeout(() => {
178
+ killTree(child);
179
+ failsafe = setTimeout(() => finish(null), FORCE_FAILSAFE_MS);
180
+ failsafe.unref();
181
+ }, KILL_GRACE_MS);
182
+ grace.unref();
183
+ };
184
+ const timer = setTimeout(() => arm(`命令超时(${String(timeoutMs)}ms),已终止进程`), timeoutMs);
185
+ const onAbort = () => {
186
+ clearTimeout(timer);
187
+ arm('命令被用户取消');
188
+ };
189
+ if (signal.aborted)
190
+ onAbort();
191
+ else
192
+ signal.addEventListener('abort', onAbort, { once: true });
193
+ child.on('error', (error) => {
194
+ if (done)
195
+ return;
196
+ done = true;
197
+ clearTimeout(timer);
198
+ if (grace !== undefined)
199
+ clearTimeout(grace);
200
+ if (failsafe !== undefined)
201
+ clearTimeout(failsafe);
202
+ signal.removeEventListener('abort', onAbort);
203
+ untrack();
204
+ rejectPromise(error);
205
+ });
206
+ child.on('close', finish);
207
+ });
208
+ }
209
+ /**
210
+ * 执行一条命令:先问执行器缝拿最终执行计划,再 spawn,最后让改写过的那几位收尾。
211
+ * 没有沙箱插件注册执行器时,计划就是上面的默认那份,行为与以前完全一致。
212
+ * T15:`background` 旁路给后台作业用——同一套计划缝与环境脱敏,回调收增量与退出。
213
+ */
214
+ async function runShell(command, cwd, timeoutMs, outputLimit, signal, background) {
215
+ const { env } = scrubChildEnv(process.env);
216
+ const base = isWin
217
+ ? {
218
+ file: 'powershell.exe',
219
+ // T15 探针抓出来的老毛病:PowerShell -Command 不透传原生命令的退出码
220
+ //(powershell.exe 自己只回 0/1)。命令末尾补一句显式 exit,把最后一条
221
+ // 原生命令的退出码带出来;纯 cmdlet 命令没有 $LASTEXITCODE,行为不变。
222
+ // 用换行而不是分号追加:command 以注释结尾时语句不会被注释吞掉。
223
+ args: ['-NoProfile', '-Command', `${command}\nif ($LASTEXITCODE -ne $null) { exit $LASTEXITCODE }`],
224
+ env,
225
+ cwd,
226
+ }
227
+ : { file: 'sh', args: ['-c', command], env, cwd };
228
+ const run = { command, cwd, timeoutMs, signal };
229
+ const { plan, changed } = await planCommand(run, base);
230
+ try {
231
+ return await spawnShell(plan, timeoutMs, outputLimit, signal, background);
232
+ }
233
+ finally {
234
+ await finishCommand(run, plan, changed);
235
+ }
236
+ }
237
+ /**
238
+ * T15:后台跑一条命令。与 {@link runShell} 同一套执行计划缝、环境脱敏与登记表,
239
+ * 不占回合、不挂有效超时;增量输出与退出码经回调交回作业表,spawn 失败经 onError。
240
+ */
241
+ export function runShellBackground(command, cwd, outputLimit, background) {
242
+ void runShell(command, cwd, 86_400_000, outputLimit, new AbortController().signal, background).catch((error) => {
243
+ background.onError?.(error instanceof Error ? error.message : String(error));
244
+ });
245
+ }
246
+ /**
247
+ * T20:起一个长命交互 shell(终端会话的进程原语)。shell 与参数都是固定字面量,
248
+ * 不拼任何外部输入;环境与前台命令同一份脱敏。没有 tty(管道模式)——全屏程序
249
+ * 跑不了,这是终端降级版的已知边界。进程原语不出本文件。
250
+ */
251
+ export function spawnTerminalShell(cwd) {
252
+ const { env } = scrubChildEnv(process.env);
253
+ const options = {
254
+ stdio: ['pipe', 'pipe', 'pipe'],
255
+ windowsHide: true,
256
+ env,
257
+ };
258
+ if (cwd !== '')
259
+ options.cwd = cwd;
260
+ if (isWin) {
261
+ return spawn('powershell.exe', ['-NoProfile', '-Command', '-'], options);
262
+ }
263
+ options.detached = true;
264
+ return spawn('bash', ['--noprofile', '--norc'], options);
265
+ }
266
+ /**
267
+ * 造一个 bash 工具。预算由 tools-default 插件从配置取值传入(缺省 {@link BASH_DEFAULT_BUDGETS}),
268
+ * 参数说明里的数值随预算走——模型看到的承诺与实际执行的一致。
269
+ * T15:给了 `background` 旁路,bash 就带 `run_in_background` 参数——立即返回 job id,
270
+ * 输出与终止走 job_output / job_list / job_kill。
271
+ */
272
+ export function createBashTool(budgets = BASH_DEFAULT_BUDGETS, background) {
273
+ return {
274
+ name: 'bash',
275
+ description: isWin
276
+ ? '执行 PowerShell 命令(工作目录 = 会话目录)。只留给「非 shell 不可」的事:构建、安装、git、跑测试、查进程。' +
277
+ '不要用 cat/head/tail 读文件(用 read),不要用 grep/rg/Get-ChildItem -Recurse 找代码(用 grep/glob),' +
278
+ '不要用 echo 重定向或 heredoc 造文件(用 write),不要用 sed/awk 改文件(用 edit)。' +
279
+ '一条命令里有 | ; && 时会被切成几段分别判定,任何一段危险整条就要问用户;带重定向或变量赋值的段不给走已授权规则。' +
280
+ '耗时命令设 timeoutMs;构建/测试/起服务这类更长的活传 run_in_background 转后台,立即返回 job id。'
281
+ : '执行 shell 命令(工作目录 = 会话目录)。只留给构建、安装、git、跑测试这类必须用 shell 的事;' +
282
+ '读文件用 read,找代码用 grep/glob,改文件用 edit/write。' +
283
+ '一条命令里有 | ; && 时会被切成几段分别判定,任何一段危险整条就要问用户。耗时命令设 timeoutMs;' +
284
+ '更长的活传 run_in_background 转后台,立即返回 job id。',
285
+ parameters: {
286
+ type: 'object',
287
+ properties: {
288
+ command: { type: 'string', description: '要执行的命令' },
289
+ timeoutMs: {
290
+ type: 'number',
291
+ description: `超时毫秒数(默认 ${budgets.timeoutMs},上限 ${budgets.maxTimeoutMs})`,
292
+ },
293
+ ...(background !== undefined
294
+ ? {
295
+ run_in_background: {
296
+ type: 'boolean',
297
+ description: 'true = 转入后台:立即返回 job id 不占回合,输出用 job_output 读,完成时自动通知',
298
+ },
299
+ }
300
+ : {}),
301
+ ...sandboxPermissionProperties,
302
+ },
303
+ required: ['command'],
304
+ },
305
+ risk: 'exec',
306
+ async run(args, ctx) {
307
+ if (typeof args.command !== 'string' || args.command.trim() === '')
308
+ throw new Error('command 必须是非空字符串');
309
+ // 硬地板在工具自己这一层再过一遍:审批层被绕开(无头队友、脚本调用)也执行不了灾难命令。
310
+ const verdict = classifyCommand(args.command);
311
+ if (verdict.decision === 'deny')
312
+ throw new Error(`命令被安全策略拒绝执行:${verdict.reason}`);
313
+ // T15:后台旁路——同一道命令、同一套审批与硬地板,只是不占住回合。
314
+ // 命令不带超时(那是后台的意义所在),取消信号也不接(打断回合不打断构建)。
315
+ if (args.run_in_background === true) {
316
+ if (background === undefined)
317
+ throw new Error('后台作业表不可用(内置工具插件没带 background 旁路)');
318
+ const id = await background.launch(args.command, ctx.cwd, ctx.sessionId);
319
+ return `已转入后台:${id}\n输出用 job_output(job_id="${id}") 读(增量),job_list 清点,完成时会自动收到通知。`;
320
+ }
321
+ const requested = typeof args.timeoutMs === 'number' ? Math.floor(args.timeoutMs) : budgets.timeoutMs;
322
+ const timeoutMs = Math.min(Math.max(requested, 1000), budgets.maxTimeoutMs);
323
+ const output = await runShell(args.command, ctx.cwd, timeoutMs, budgets.outputChars, ctx.signal);
324
+ // 下载类命令的输出是外部内容:包裹围栏再进对话(先遮红后包裹,遮红在 spawnShell 里已完成)。
325
+ if (NETWORK_FETCH_RE.test(args.command))
326
+ return wrapUntrusted('bash', output);
327
+ return output;
328
+ },
329
+ };
330
+ }
331
+ // ── T15:后台作业表与三件工具 ─────────────────────────────────────────────────
332
+ //
333
+ // 与 bash 工具同住一个文件的原因:作业的启动(runShellBackground)与收尾
334
+ // (stopBackgroundChild)和前台命令共用同一批进程原语,安全审计的进程边界
335
+ // 就在本文件收口——新文件里任何「命令 → shell」的通路都过不了候选扫描。
336
+ /** 单个作业的输出缓冲上限(字符):超出从头部丢,日志类输出尾巴才是有用的那截。 */
337
+ export const JOB_OUTPUT_CAP = 100_000;
338
+ /** job_output 不带 offset 时默认看的尾部窗口(字符)。 */
339
+ export const JOB_VIEW_CHARS = 4_000;
340
+ /** 作业数上限:后台不是漏水的桶,超了就拒绝新作业。 */
341
+ export const JOB_MAX_COUNT = 50;
342
+ /**
343
+ * 后台作业表。一次 launch = 把命令交给 {@link runShellBackground}(与前台 bash
344
+ * 同一条计划缝、同一份环境脱敏、同一张登记表)→ onChunk 收进缓冲 →
345
+ * onExit/onError 定状态并通知。
346
+ */
347
+ export class JobTable {
348
+ options;
349
+ jobs = new Map();
350
+ counter = 0;
351
+ constructor(options) {
352
+ this.options = options;
353
+ }
354
+ /** 当前作业数(含已结束的:读输出的依据都在表里)。 */
355
+ get size() {
356
+ return this.jobs.size;
357
+ }
358
+ /** 仍在跑的作业 id(job_kill / 收摊清点用)。 */
359
+ runningIds() {
360
+ const ids = [];
361
+ for (const job of this.jobs.values())
362
+ if (job.status === 'running')
363
+ ids.push(job.id);
364
+ return ids;
365
+ }
366
+ /**
367
+ * 启动一个后台作业,立即返回 job id(不等进程结束)。
368
+ * 命令分类与审批在 bash 工具入口已完成,这里不再判一遍(同一道命令,不同的等法)。
369
+ * `owner` = 发起作业的会话 id:完成通知按它归属投递(0.6.48)。
370
+ */
371
+ launch(command, cwd, owner) {
372
+ if (this.jobs.size >= JOB_MAX_COUNT) {
373
+ throw new Error(`后台作业已到 ${String(JOB_MAX_COUNT)} 个上限,先用 job_kill 收掉几个,或 job_list 清点`);
374
+ }
375
+ this.counter += 1;
376
+ const id = `job-${String(this.counter)}`;
377
+ const job = {
378
+ id,
379
+ command,
380
+ cwd,
381
+ status: 'running',
382
+ exitCode: null,
383
+ startedAt: Date.now(),
384
+ output: '',
385
+ dropped: 0,
386
+ lastRead: 0,
387
+ networkFetch: NETWORK_FETCH_RE.test(command),
388
+ ...(owner === undefined ? {} : { owner }),
389
+ };
390
+ this.jobs.set(id, job);
391
+ const append = (chunk) => {
392
+ if (job.status !== 'running')
393
+ return;
394
+ job.output += chunk;
395
+ if (job.output.length > JOB_OUTPUT_CAP) {
396
+ const drop = job.output.length - JOB_OUTPUT_CAP;
397
+ job.output = job.output.slice(drop);
398
+ job.dropped += drop;
399
+ }
400
+ };
401
+ // 后台没有超时(那是后台的意义所在),也不接取消信号——打断回合不打断构建
402
+ runShellBackground(command, cwd, JOB_OUTPUT_CAP, {
403
+ trackKey: id,
404
+ onChunk: append,
405
+ onExit: (code) => {
406
+ if (job.status !== 'running')
407
+ return;
408
+ job.exitCode = code;
409
+ job.finishedAt = Date.now();
410
+ job.status = code === 0 ? 'completed' : 'failed';
411
+ this.options.notify(`后台作业 ${id}(${command.slice(0, 60)}${command.length > 60 ? '…' : ''})${code === 0 ? '成功完成' : `失败(退出码 ${String(code)})`}。用 job_output(job_id="${id}") 查看输出,job_list 清点全部作业。`, owner);
412
+ },
413
+ onError: (message) => {
414
+ if (job.status !== 'running')
415
+ return;
416
+ job.status = 'failed';
417
+ job.finishedAt = Date.now();
418
+ job.output += `\n[启动失败:${message}]`;
419
+ this.options.notify(`后台作业 ${id} 启动失败:${message}`, owner);
420
+ },
421
+ });
422
+ return id;
423
+ }
424
+ /** 读一个作业的输出:offset 省略时从上次读到的位置续读(首次且输出短就从头给)。 */
425
+ output(jobId, offset) {
426
+ const job = this.require(jobId);
427
+ const total = job.dropped + job.output.length;
428
+ let from;
429
+ if (typeof offset === 'number' && Number.isFinite(offset) && offset >= 0) {
430
+ from = Math.floor(offset);
431
+ }
432
+ else if (job.lastRead > 0 || total <= JOB_VIEW_CHARS) {
433
+ from = job.lastRead;
434
+ }
435
+ else {
436
+ from = total - JOB_VIEW_CHARS;
437
+ }
438
+ if (from < job.dropped)
439
+ from = job.dropped;
440
+ if (from > total)
441
+ from = total;
442
+ const local = from - job.dropped;
443
+ const slice = job.output.slice(local, local + JOB_VIEW_CHARS);
444
+ job.lastRead = Math.max(job.lastRead, from + slice.length);
445
+ const atEnd = from + slice.length >= total;
446
+ let text = slice;
447
+ if (!atEnd)
448
+ text = `${text}\n…(后面还有 ${String(total - from - slice.length)} 字符,用 offset=${String(job.lastRead)} 续读)`;
449
+ text = redact(text);
450
+ if (job.networkFetch && text.trim() !== '')
451
+ text = wrapUntrusted('job-output', text);
452
+ return {
453
+ id: job.id,
454
+ status: job.status,
455
+ exitCode: job.exitCode,
456
+ text,
457
+ totalChars: total,
458
+ from,
459
+ droppedChars: job.dropped,
460
+ atEnd,
461
+ };
462
+ }
463
+ /**
464
+ * 只读快照:取**现存输出的尾部窗口**,返回形状与 {@link output} 相同。
465
+ *
466
+ * 与 output() 的唯一区别:**不动 `lastRead` 游标**。状态面板的「终端」区点开输出面
467
+ * 后会按秒轮询这里(只读展示),如果走 output() 就会把模型下一次 `job_output` 的增量
468
+ * 读位置顶到末尾、让模型读不到后续输出——展示与模型的读口必须是两条互不干扰的游标。
469
+ */
470
+ peek(jobId, maxChars = JOB_VIEW_CHARS) {
471
+ const job = this.require(jobId);
472
+ const total = job.dropped + job.output.length;
473
+ let from = total - maxChars;
474
+ if (from < job.dropped)
475
+ from = job.dropped;
476
+ if (from < 0)
477
+ from = 0;
478
+ const local = from - job.dropped;
479
+ const slice = job.output.slice(local, local + maxChars);
480
+ const atEnd = from + slice.length >= total;
481
+ let text = redact(slice);
482
+ if (job.networkFetch && text.trim() !== '')
483
+ text = wrapUntrusted('job-output', text);
484
+ return {
485
+ id: job.id,
486
+ status: job.status,
487
+ exitCode: job.exitCode,
488
+ text,
489
+ totalChars: total,
490
+ from,
491
+ droppedChars: job.dropped,
492
+ atEnd,
493
+ };
494
+ }
495
+ /** 全部作业的清单(job_list 的数据源)。 */
496
+ list() {
497
+ return [...this.jobs.values()].sort((a, b) => a.startedAt - b.startedAt);
498
+ }
499
+ get(id) {
500
+ return this.jobs.get(id);
501
+ }
502
+ /** 把作业记为被终止(纯簿记;进程收尾由调用方调 {@link stopBackgroundChild})。 */
503
+ markKilled(jobId) {
504
+ const job = this.jobs.get(jobId);
505
+ if (job === undefined || job.status !== 'running')
506
+ return job;
507
+ job.status = 'killed';
508
+ job.finishedAt = Date.now();
509
+ return job;
510
+ }
511
+ require(jobId) {
512
+ const job = this.jobs.get(jobId);
513
+ if (job === undefined) {
514
+ const known = [...this.jobs.keys()].slice(-5).join(', ');
515
+ throw new Error(`没有这个后台作业:${jobId}${known === '' ? '(还没有任何作业)' : `(最近的作业:${known})`}`);
516
+ }
517
+ return job;
518
+ }
519
+ }
520
+ /**
521
+ * job_output / job_list / job_kill 三件工具(T15)。kill 的进程收尾走
522
+ * {@link stopBackgroundChild}(登记表整树收尾),簿记走 {@link JobTable.markKilled}。
523
+ */
524
+ export function createJobTools(table) {
525
+ return [
526
+ {
527
+ name: 'job_output',
528
+ description: '读一个后台作业的输出(增量续读)。不带 offset 从上次读到的位置继续;'
529
+ + '作业结束(完成/失败/被终止)后会附带退出码。',
530
+ parameters: {
531
+ type: 'object',
532
+ properties: {
533
+ job_id: { type: 'string', description: 'job_list 里的作业 id,例如 job-1' },
534
+ offset: { type: 'number', description: '从输出的第几个字符开始读(续读用回包里的提示值)' },
535
+ },
536
+ required: ['job_id'],
537
+ },
538
+ risk: 'read',
539
+ async run(args) {
540
+ const jobId = typeof args.job_id === 'string' ? args.job_id : '';
541
+ if (jobId === '')
542
+ throw new Error('job_id 必须是非空字符串');
543
+ const view = table.output(jobId, typeof args.offset === 'number' ? args.offset : undefined);
544
+ const status = view.status === 'running'
545
+ ? '运行中'
546
+ : view.status === 'completed'
547
+ ? '已完成'
548
+ : view.status === 'killed'
549
+ ? '被终止'
550
+ : `失败(退出码 ${String(view.exitCode ?? '?')})`;
551
+ const body = view.text.trim() === '' ? '(还没有输出)' : view.text;
552
+ return `[${view.id}] ${status}\n\n${body}`;
553
+ },
554
+ },
555
+ {
556
+ name: 'job_list',
557
+ description: '清点全部后台作业:id、状态、已运行时长、命令。',
558
+ parameters: { type: 'object', properties: {} },
559
+ risk: 'read',
560
+ async run() {
561
+ const jobs = table.list();
562
+ if (jobs.length === 0)
563
+ return '(没有后台作业。启动:bash 带 run_in_background=true)';
564
+ return jobs
565
+ .map((job) => {
566
+ const seconds = Math.round(((job.finishedAt ?? Date.now()) - job.startedAt) / 1000);
567
+ const state = job.status === 'running'
568
+ ? '运行中'
569
+ : job.status === 'completed'
570
+ ? '已完成'
571
+ : job.status === 'killed'
572
+ ? '被终止'
573
+ : `失败(退出码 ${String(job.exitCode ?? '?')})`;
574
+ return `${job.id} [${state}] ${String(seconds)}s ${job.command.slice(0, 80)}`;
575
+ })
576
+ .join('\n');
577
+ },
578
+ },
579
+ {
580
+ name: 'job_kill',
581
+ description: '终止一个还在跑的后台作业(整树收尾,已收输出保留,还能用 job_output 读)。',
582
+ parameters: {
583
+ type: 'object',
584
+ properties: {
585
+ job_id: { type: 'string', description: 'job_list 里的作业 id,例如 job-1' },
586
+ },
587
+ required: ['job_id'],
588
+ },
589
+ risk: 'exec',
590
+ async run(args) {
591
+ const jobId = typeof args.job_id === 'string' ? args.job_id : '';
592
+ if (jobId === '')
593
+ throw new Error('job_id 必须是非空字符串');
594
+ const job = table.get(jobId);
595
+ if (job === undefined)
596
+ throw new Error(`没有这个后台作业:${jobId}(job_list 先清点)`);
597
+ if (job.status !== 'running')
598
+ return `${jobId} 已经是 ${job.status},不用再收`;
599
+ table.markKilled(jobId);
600
+ const stopped = stopBackgroundChild(jobId);
601
+ return stopped
602
+ ? `${jobId} 正在终止(整树收尾,已收输出保留,可用 job_output 读到)`
603
+ : `${jobId} 的进程已经不在了,作业记为被终止`;
604
+ },
605
+ },
606
+ ];
607
+ }
608
+ // ── T20:持久终端会话(降级版:管道会话 + 读写分离) ─────────────────────────
609
+ //
610
+ // 与作业表同住本文件的原因与 T15 一致:终端会话也是「模型可控输入 → shell 进程」
611
+ // 的通路,进程原语({@link spawnTerminalShell} / 登记表 / 整树收尾)不出 bash.ts,
612
+ // 安全审计的进程边界在本文件收口。没有 PTY——全屏程序(vim / htop)跑不了,
613
+ // 这是降级版的已知边界;也没有中途打断(dsh 的 signal 动作)——管道模式下
614
+ // Windows 收不到 Ctrl+C,长命令要么等完要么 close 收掉整个会话重开。
615
+ /** 单个终端会话的输出缓冲上限(字符):与后台作业同一量级。 */
616
+ export const TERM_OUTPUT_CAP = 100_000;
617
+ /** terminal read 不带 offset 时默认看的尾部窗口(字符)。 */
618
+ export const TERM_VIEW_CHARS = 4_000;
619
+ /** 会话数上限:终端页签不是无限开的,超了先收旧的。 */
620
+ export const TERM_MAX_COUNT = 8;
621
+ /**
622
+ * 终端会话表。open 起一个长命交互 shell(stdin 打开、无超时),send 往里写、
623
+ * read 增量读、close 走 {@link stopBackgroundChild} 整树收尾——进程登记与
624
+ * 收尾原语完全复用 T15 那一套,本表只管簿记。
625
+ *
626
+ * 会话不接受模型指定的起始目录(工作目录进会话后 send 一句 cd 就行)——
627
+ * 起 shell 的输入面越窄越好。
628
+ */
629
+ export class TerminalTable {
630
+ options;
631
+ sessions = new Map();
632
+ counter = 0;
633
+ /**
634
+ * @param options.onExit - 会话自己退出(进程 close / 起不来)时的回调:宿主拿它
635
+ * 抖一帧快照(状态面板的「终端」区要立刻把这一行撤掉,不等下一次别的变化)。
636
+ * 经工具收掉的走工具结果那条路,不重复回调。
637
+ */
638
+ constructor(options = {}) {
639
+ this.options = options;
640
+ }
641
+ get size() {
642
+ return this.sessions.size;
643
+ }
644
+ /**
645
+ * 开一个新会话,立即返回会话 id。shell 就地起(它不是一条命令,不经过 planCommand 缝)。
646
+ * `owner` = 开会话的会话 id:面板「终端」区按它筛当前查看会话的活(作业的 owner 同义)。
647
+ * `cwd` = 起进程的目录:给会话自己的目录(会话的 cwd 是它的数据,见 `Session.meta.cwd`)——
648
+ * 多工作区并用之后,「进程目录」已经没有用户意义了,落到那儿等于落到一个随机的工作区。
649
+ */
650
+ open(owner, cwd) {
651
+ if (this.sessions.size >= TERM_MAX_COUNT) {
652
+ throw new Error(`终端会话已到 ${String(TERM_MAX_COUNT)} 个上限,先用 terminal close 收掉几个,或 list 清点`);
653
+ }
654
+ this.counter += 1;
655
+ const id = `term-${String(this.counter)}`;
656
+ const record = {
657
+ id,
658
+ cwd: cwd ?? '',
659
+ status: 'running',
660
+ exitCode: null,
661
+ startedAt: Date.now(),
662
+ lastSent: '',
663
+ output: '',
664
+ dropped: 0,
665
+ lastRead: 0,
666
+ ...(owner === undefined ? {} : { owner }),
667
+ };
668
+ this.sessions.set(id, record);
669
+ // 不给模型指定起进程参数的面(开了会话想换目录自己 cd):起进程的目录由调用方给
670
+ // ——工具那条路给的是**会话自己的** cwd。
671
+ const child = spawnTerminalShell(cwd ?? '');
672
+ trackBackgroundChild(id, child);
673
+ const append = (chunk) => {
674
+ if (record.status !== 'running')
675
+ return;
676
+ record.output += String(chunk);
677
+ if (record.output.length > TERM_OUTPUT_CAP) {
678
+ const drop = record.output.length - TERM_OUTPUT_CAP;
679
+ record.output = record.output.slice(drop);
680
+ record.dropped += drop;
681
+ }
682
+ };
683
+ child.stdout?.on('data', append);
684
+ child.stderr?.on('data', append);
685
+ child.on('error', (error) => {
686
+ record.status = 'closed';
687
+ record.finishedAt = Date.now();
688
+ record.output += `\n[启动失败:${error.message}]`;
689
+ untrackBackgroundChild(id);
690
+ this.options.onExit?.(id);
691
+ });
692
+ child.on('close', (code) => {
693
+ if (record.status !== 'running')
694
+ return;
695
+ record.status = 'closed';
696
+ record.exitCode = code;
697
+ record.finishedAt = Date.now();
698
+ untrackBackgroundChild(id);
699
+ this.options.onExit?.(id);
700
+ });
701
+ return id;
702
+ }
703
+ /** 读会话输出:offset 省略时从上次读到的位置续读(语义与 job_output 一致)。 */
704
+ read(sessionId, offset) {
705
+ const record = this.require(sessionId);
706
+ const total = record.dropped + record.output.length;
707
+ let from;
708
+ if (typeof offset === 'number' && Number.isFinite(offset) && offset >= 0) {
709
+ from = Math.floor(offset);
710
+ }
711
+ else if (record.lastRead > 0 || total <= TERM_VIEW_CHARS) {
712
+ from = record.lastRead;
713
+ }
714
+ else {
715
+ from = total - TERM_VIEW_CHARS;
716
+ }
717
+ if (from < record.dropped)
718
+ from = record.dropped;
719
+ if (from > total)
720
+ from = total;
721
+ const local = from - record.dropped;
722
+ const slice = record.output.slice(local, local + TERM_VIEW_CHARS);
723
+ record.lastRead = Math.max(record.lastRead, from + slice.length);
724
+ const atEnd = from + slice.length >= total;
725
+ let text = slice;
726
+ if (!atEnd)
727
+ text = `${text}\n…(后面还有 ${String(total - from - slice.length)} 字符,用 offset=${String(record.lastRead)} 续读)`;
728
+ text = redact(text);
729
+ return {
730
+ id: record.id,
731
+ status: record.status,
732
+ exitCode: record.exitCode,
733
+ text,
734
+ totalChars: total,
735
+ from,
736
+ droppedChars: record.dropped,
737
+ atEnd,
738
+ };
739
+ }
740
+ /**
741
+ * 只读快照:取**现存输出的尾部窗口**,返回形状与 {@link read} 相同。
742
+ *
743
+ * 与 read() 的唯一区别:**不动 `lastRead` 游标**(理由与 {@link JobTable.peek} 同一件事:
744
+ * 状态面板按秒轮询展示,不能顶掉模型下一次 `terminal read` 的增量读位置)。
745
+ */
746
+ peek(sessionId, maxChars = TERM_VIEW_CHARS) {
747
+ const record = this.require(sessionId);
748
+ const total = record.dropped + record.output.length;
749
+ let from = total - maxChars;
750
+ if (from < record.dropped)
751
+ from = record.dropped;
752
+ if (from < 0)
753
+ from = 0;
754
+ const local = from - record.dropped;
755
+ const slice = record.output.slice(local, local + maxChars);
756
+ const atEnd = from + slice.length >= total;
757
+ return {
758
+ id: record.id,
759
+ status: record.status,
760
+ exitCode: record.exitCode,
761
+ text: redact(slice),
762
+ totalChars: total,
763
+ from,
764
+ droppedChars: record.dropped,
765
+ atEnd,
766
+ };
767
+ }
768
+ /**
769
+ * 往会话 stdin 写一段文本;要执行的命令自己带换行。
770
+ * 这里就是终端工具的本体语义:模型输入 → 长命 shell 的输入口(与 bash 工具的
771
+ * 「命令 → spawn」同一本质,只是执行环境常驻)。写入前不判内容——判与放行
772
+ * 都在工具层的守卫链上做,本表只管把字节送进管道。
773
+ */
774
+ send(sessionId, data) {
775
+ const record = this.require(sessionId);
776
+ if (record.status !== 'running') {
777
+ throw new Error(`终端会话 ${sessionId} 已经结束(exitCode ${String(record.exitCode)}),开个新的再发`);
778
+ }
779
+ const session = trackedBackgroundChild(sessionId);
780
+ const stdin = session?.stdin ?? null;
781
+ if (stdin === null || stdin.destroyed) {
782
+ throw new Error(`终端会话 ${sessionId} 的输入口已经关了`);
783
+ }
784
+ stdin.write(data);
785
+ // 写成功了才记(写失败那条不算「这个会话在干什么」):状态面板的行标题用它。
786
+ record.lastSent = data;
787
+ }
788
+ /** 收掉一个会话(整树);簿记走 close 状态。返回给模型看的一句话。 */
789
+ close(sessionId) {
790
+ const record = this.require(sessionId);
791
+ if (record.status !== 'running')
792
+ return `终端会话 ${sessionId} 本来就已经结束`;
793
+ stopBackgroundChild(sessionId);
794
+ record.status = 'closed';
795
+ record.finishedAt = Date.now();
796
+ return `终端会话 ${sessionId} 已收掉`;
797
+ }
798
+ /** 全部会话的清单。 */
799
+ list() {
800
+ return [...this.sessions.values()].sort((a, b) => a.startedAt - b.startedAt);
801
+ }
802
+ require(sessionId) {
803
+ const record = this.sessions.get(sessionId);
804
+ if (record === undefined) {
805
+ const known = [...this.sessions.keys()].slice(-5).join(', ');
806
+ throw new Error(`没有这个终端会话:${sessionId}${known === '' ? '(还没有任何会话)' : `(现有的会话:${known})`}`);
807
+ }
808
+ return record;
809
+ }
810
+ }
811
+ /**
812
+ * terminal 单件工具(T20):open / read / send / close / list 五个动作。
813
+ * 没挂 PTY(降级版):全屏程序跑不了;也没有中途打断——长命令等完或 close 重开。
814
+ */
815
+ export function createTerminalTool(table) {
816
+ return {
817
+ name: 'terminal',
818
+ description: isWin
819
+ ? '开一个持久的交互 PowerShell 会话(没有 tty:vim/htop 这类全屏程序跑不了)。' +
820
+ '适合「先激活环境、再连续跑几条命令」的场景——环境在会话里留着,一次不用重设。' +
821
+ 'open 开会话,send 写命令(自带换行才执行),read 读输出(增量),close 收掉,list 清点。' +
822
+ '没有中途打断:跑歪了的命令等它结束,或 close 收掉会话重开。'
823
+ : '开一个持久的交互 bash 会话(没有 tty:vim/htop 这类全屏程序跑不了)。' +
824
+ '适合「先激活环境、再连续跑几条命令」的场景。open 开会话,send 写命令(自带换行才执行),' +
825
+ 'read 读输出(增量),close 收掉,list 清点。没有中途打断:跑歪了的命令等它结束,或 close 收掉会话重开。',
826
+ parameters: {
827
+ type: 'object',
828
+ properties: {
829
+ action: { type: 'string', enum: ['open', 'read', 'send', 'close', 'list'], description: '要做什么' },
830
+ session_id: { type: 'string', description: '会话 id,例如 term-1;read/send/close 必填' },
831
+ data: { type: 'string', description: 'send 必填:写进会话的文本;要执行的命令自带换行' },
832
+ offset: { type: 'number', description: 'read 可选:从输出的第几个字符开始读(续读用回包里的提示值)' },
833
+ },
834
+ required: ['action'],
835
+ },
836
+ risk: 'exec',
837
+ async run(args, ctx) {
838
+ const action = String(args.action ?? '');
839
+ switch (action) {
840
+ case 'open': {
841
+ const id = table.open(ctx.sessionId, ctx.cwd);
842
+ return `已开终端会话 ${id}。用 send(data="…\n") 发命令(自带换行才执行),read 读输出(启动需要一两秒,读空了稍等再读)。`;
843
+ }
844
+ case 'read': {
845
+ const view = table.read(String(args.session_id ?? ''), typeof args.offset === 'number' ? args.offset : undefined);
846
+ const head = view.status === 'closed' ? `(会话已结束,exitCode ${String(view.exitCode)})` : '';
847
+ return `会话 ${view.id}${head}:\n${view.text}${view.atEnd ? '' : `\n(offset=${String(view.from + view.text.length)} 续读)`}`;
848
+ }
849
+ case 'send': {
850
+ const data = args.data;
851
+ if (typeof data !== 'string' || data === '')
852
+ throw new Error('send 要带上 data(写进会话的文本,要执行的命令自带换行)');
853
+ table.send(String(args.session_id ?? ''), data);
854
+ return `已写进 ${String(args.session_id)}。用 read 读输出。`;
855
+ }
856
+ case 'close':
857
+ return table.close(String(args.session_id ?? ''));
858
+ case 'list': {
859
+ const sessions = table.list();
860
+ if (sessions.length === 0)
861
+ return '(还没有任何终端会话)';
862
+ return sessions
863
+ .map((session) => `- ${session.id}(${session.status}${session.status === 'closed' ? `,exitCode ${String(session.exitCode)}` : ''})`)
864
+ .join('\n');
865
+ }
866
+ default:
867
+ throw new Error(`不认识的 action「${action}」。要用的值:open / read / send / close / list`);
868
+ }
869
+ },
870
+ };
871
+ }