@waq666/pneuma 0.7.1 → 0.8.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 (416) hide show
  1. package/README.md +242 -206
  2. package/bin/dsc.js +9 -3
  3. package/bin/headless.cjs +1 -1
  4. package/lib/adapter/transcript.d.ts +19 -2
  5. package/lib/adapter/transcript.js +71 -14
  6. package/lib/app/AgentsOverlay.js +7 -6
  7. package/lib/app/App.js +1 -1
  8. package/lib/app/ApprovalCard.js +15 -9
  9. package/lib/app/ChatView.d.ts +3 -1
  10. package/lib/app/ChatView.js +21 -17
  11. package/lib/app/Composer.js +22 -4
  12. package/lib/app/MarkdownView.js +2 -1
  13. package/lib/app/ModelPicker.js +7 -6
  14. package/lib/app/PickerFrame.d.ts +4 -0
  15. package/lib/app/PickerFrame.js +18 -0
  16. package/lib/app/PlanReviewCard.js +2 -1
  17. package/lib/app/PresetPicker.js +8 -7
  18. package/lib/app/SessionPicker.js +21 -20
  19. package/lib/app/SettingsOverlay.js +1 -1
  20. package/lib/app/SkillsPicker.js +7 -6
  21. package/lib/app/StatusBar.js +3 -15
  22. package/lib/app/TaskStrips.js +1 -4
  23. package/lib/app/TimelineRail.js +2 -1
  24. package/lib/app/ToolCard.js +2 -6
  25. package/lib/app/Welcome.d.ts +1 -0
  26. package/lib/app/Welcome.js +1 -4
  27. package/lib/app/click.d.ts +0 -2
  28. package/lib/app/click.js +2 -21
  29. package/lib/app/display-width.d.ts +16 -0
  30. package/lib/app/display-width.js +33 -0
  31. package/lib/app/markdown.d.ts +1 -3
  32. package/lib/app/markdown.js +2 -19
  33. package/lib/app/scroll-model.js +1 -1
  34. package/lib/contract/approval.d.ts +91 -0
  35. package/lib/contract/approval.js +1 -0
  36. package/lib/contract/mode.d.ts +69 -0
  37. package/lib/contract/mode.js +1 -0
  38. package/lib/contract/plugin.d.ts +240 -0
  39. package/lib/contract/plugin.js +1 -0
  40. package/lib/contract/runtime.d.ts +282 -0
  41. package/lib/contract/runtime.js +1 -0
  42. package/lib/contract/session.d.ts +208 -0
  43. package/lib/contract/session.js +36 -0
  44. package/lib/contract/settings.d.ts +242 -0
  45. package/lib/contract/settings.js +1 -0
  46. package/lib/contract/snapshot.d.ts +453 -0
  47. package/lib/contract/snapshot.js +1 -0
  48. package/lib/contract/task.d.ts +189 -0
  49. package/lib/contract/task.js +10 -0
  50. package/lib/contract/transcript.d.ts +358 -0
  51. package/lib/contract/transcript.js +1 -0
  52. package/lib/contract/usage.d.ts +132 -0
  53. package/lib/contract/usage.js +10 -0
  54. package/lib/contract.d.ts +20 -1968
  55. package/lib/contract.js +19 -30
  56. package/lib/core/agent-roles.d.ts +1 -1
  57. package/lib/core/agent-roles.js +6 -5
  58. package/lib/core/approval-floor.d.ts +9 -0
  59. package/lib/core/approval-floor.js +152 -25
  60. package/lib/core/attachments.d.ts +185 -0
  61. package/lib/core/attachments.js +425 -0
  62. package/lib/core/bytes.d.ts +14 -0
  63. package/lib/core/bytes.js +28 -0
  64. package/lib/core/call-meaning.d.ts +20 -0
  65. package/lib/core/call-meaning.js +347 -0
  66. package/lib/core/cdp/actions.js +6 -0
  67. package/lib/core/cdp/launch.js +2 -2
  68. package/lib/core/cdp/report.d.ts +27 -0
  69. package/lib/core/cdp/report.js +50 -0
  70. package/lib/core/cdp/ring-buffer.d.ts +25 -0
  71. package/lib/core/cdp/ring-buffer.js +44 -0
  72. package/lib/core/cdp/snapshot.js +5 -9
  73. package/lib/core/cdp/transport.js +1 -1
  74. package/lib/core/clamp.d.ts +20 -0
  75. package/lib/core/clamp.js +24 -0
  76. package/lib/core/clock.d.ts +16 -0
  77. package/lib/core/clock.js +20 -0
  78. package/lib/core/command-policy.js +33 -1
  79. package/lib/core/commands-completion.d.ts +28 -0
  80. package/lib/core/commands-completion.js +108 -30
  81. package/lib/core/compact.d.ts +36 -6
  82. package/lib/core/compact.js +89 -17
  83. package/lib/core/desktop-control.js +1 -3
  84. package/lib/core/dsh-compat/llm-usage-event.d.ts +78 -0
  85. package/lib/core/dsh-compat/llm-usage-event.js +91 -0
  86. package/lib/core/dsh-compat/presentation.d.ts +84 -0
  87. package/lib/core/dsh-compat/presentation.js +105 -0
  88. package/lib/core/dsh-compat/resolve-hook.d.ts +3 -3
  89. package/lib/core/dsh-compat/resolve-hook.js +41 -13
  90. package/lib/core/dsh-compat/service-map.d.ts +52 -0
  91. package/lib/core/dsh-compat/service-map.js +87 -0
  92. package/lib/core/dsh-compat/session-bridge.d.ts +107 -0
  93. package/lib/core/dsh-compat/session-bridge.js +376 -0
  94. package/lib/core/dsh-compat/session-events.d.ts +54 -0
  95. package/lib/core/dsh-compat/session-events.js +297 -0
  96. package/lib/core/dsh-compat/shims/credentials.d.ts +62 -0
  97. package/lib/core/dsh-compat/shims/credentials.js +86 -0
  98. package/lib/core/dsh-compat/shims/home-paths.d.ts +77 -0
  99. package/lib/core/dsh-compat/shims/home-paths.js +143 -0
  100. package/lib/core/dsh-compat/tools-facade.d.ts +31 -1
  101. package/lib/core/dsh-compat/tools-facade.js +207 -3
  102. package/lib/core/err-text.d.ts +5 -0
  103. package/lib/core/err-text.js +5 -0
  104. package/lib/core/events.d.ts +31 -2
  105. package/lib/core/git-info.d.ts +127 -15
  106. package/lib/core/git-info.js +315 -34
  107. package/lib/core/git-surface.d.ts +17 -0
  108. package/lib/core/git-surface.js +7 -0
  109. package/lib/core/hooks.d.ts +19 -2
  110. package/lib/core/hooks.js +57 -13
  111. package/lib/core/host-methods.d.ts +1 -1
  112. package/lib/core/host-methods.js +4 -0
  113. package/lib/core/image-diet.js +1 -4
  114. package/lib/core/json-text.d.ts +11 -0
  115. package/lib/core/json-text.js +18 -0
  116. package/lib/core/learnings/skill-write.d.ts +1 -7
  117. package/lib/core/learnings/skill-write.js +3 -37
  118. package/lib/core/lifecycle-hooks.d.ts +11 -3
  119. package/lib/core/lifecycle-hooks.js +33 -42
  120. package/lib/core/llm.d.ts +42 -0
  121. package/lib/core/llm.js +40 -25
  122. package/lib/core/loop.d.ts +11 -1
  123. package/lib/core/loop.js +95 -28
  124. package/lib/core/lsp/client.js +30 -17
  125. package/lib/core/lsp/normalize.d.ts +0 -2
  126. package/lib/core/lsp/normalize.js +1 -6
  127. package/lib/core/lsp/servers.js +1 -4
  128. package/lib/core/mcp.d.ts +18 -0
  129. package/lib/core/mcp.js +60 -16
  130. package/lib/core/microcompact.d.ts +45 -0
  131. package/lib/core/microcompact.js +128 -0
  132. package/lib/core/native-bridge.js +2 -10
  133. package/lib/core/path-policy.d.ts +13 -1
  134. package/lib/core/path-policy.js +87 -18
  135. package/lib/core/permission-presets.d.ts +9 -5
  136. package/lib/core/permission-presets.js +14 -7
  137. package/lib/core/permission-scope.d.ts +65 -0
  138. package/lib/core/permission-scope.js +109 -0
  139. package/lib/core/plugin-bundle.d.ts +95 -0
  140. package/lib/core/plugin-bundle.js +137 -0
  141. package/lib/core/plugin-loader.d.ts +36 -1
  142. package/lib/core/plugin-loader.js +336 -12
  143. package/lib/core/plugin-patch.d.ts +64 -0
  144. package/lib/core/plugin-patch.js +146 -0
  145. package/lib/core/plugin-registry.d.ts +14 -0
  146. package/lib/core/plugin-registry.js +2 -0
  147. package/lib/core/prefs.js +40 -2
  148. package/lib/core/presets.d.ts +11 -0
  149. package/lib/core/presets.js +61 -22
  150. package/lib/core/profile-dir.d.ts +5 -0
  151. package/lib/core/profile-dir.js +40 -0
  152. package/lib/core/prompt.js +55 -19
  153. package/lib/core/ptc.d.ts +8 -2
  154. package/lib/core/ptc.js +18 -4
  155. package/lib/core/records.d.ts +16 -0
  156. package/lib/core/records.js +22 -0
  157. package/lib/core/remote/notify.js +1 -3
  158. package/lib/core/remote/push.js +2 -6
  159. package/lib/core/sandbox/execpolicy.js +27 -3
  160. package/lib/core/sandbox/net-proxy.js +2 -2
  161. package/lib/core/sandbox/policy.d.ts +1 -1
  162. package/lib/core/sandbox/policy.js +21 -15
  163. package/lib/core/sandbox/win/account.js +1 -4
  164. package/lib/core/sandbox/win/acl.js +1 -6
  165. package/lib/core/sandbox/win/backend.d.ts +24 -3
  166. package/lib/core/sandbox/win/backend.js +73 -23
  167. package/lib/core/sandbox/win/doctor.js +1 -4
  168. package/lib/core/sandbox/win/runner-entry.js +1 -6
  169. package/lib/core/sandbox/win/setup.js +1 -4
  170. package/lib/core/sandbox/win/utf16.d.ts +11 -0
  171. package/lib/core/sandbox/win/utf16.js +15 -0
  172. package/lib/core/sandbox/win/wfp.js +1 -4
  173. package/lib/core/schedule/rule.d.ts +0 -17
  174. package/lib/core/schedule/rule.js +1 -3
  175. package/lib/core/schedule/runner.d.ts +5 -2
  176. package/lib/core/schedule/runner.js +32 -9
  177. package/lib/core/schedule/store.d.ts +0 -2
  178. package/lib/core/schedule/store.js +2 -9
  179. package/lib/core/session-index.d.ts +50 -0
  180. package/lib/core/session-index.js +169 -3
  181. package/lib/core/session.d.ts +89 -13
  182. package/lib/core/session.js +385 -32
  183. package/lib/core/shell-quote.d.ts +21 -0
  184. package/lib/core/shell-quote.js +24 -0
  185. package/lib/core/side-ask.d.ts +52 -0
  186. package/lib/core/side-ask.js +89 -0
  187. package/lib/core/skills.d.ts +16 -0
  188. package/lib/core/skills.js +45 -8
  189. package/lib/core/snapshot-throttle.d.ts +8 -0
  190. package/lib/core/snapshot-throttle.js +24 -0
  191. package/lib/core/spill.d.ts +11 -5
  192. package/lib/core/spill.js +35 -36
  193. package/lib/core/strings.d.ts +21 -0
  194. package/lib/core/strings.js +33 -0
  195. package/lib/core/terminal-env.d.ts +61 -0
  196. package/lib/core/terminal-env.js +327 -0
  197. package/lib/core/text-format.d.ts +17 -0
  198. package/lib/core/text-format.js +26 -0
  199. package/lib/core/todo-reminder.d.ts +19 -14
  200. package/lib/core/todo-reminder.js +14 -23
  201. package/lib/core/token-estimate.d.ts +18 -2
  202. package/lib/core/token-estimate.js +10 -2
  203. package/lib/core/tool-result-prune.d.ts +42 -0
  204. package/lib/core/tool-result-prune.js +47 -0
  205. package/lib/core/tool-search.d.ts +3 -2
  206. package/lib/core/tool-search.js +3 -2
  207. package/lib/core/tools/bash.d.ts +35 -3
  208. package/lib/core/tools/bash.js +168 -41
  209. package/lib/core/tools/fs-tools.js +18 -17
  210. package/lib/core/tools/image-tool.d.ts +2 -0
  211. package/lib/core/tools/image-tool.js +59 -0
  212. package/lib/core/tools/path-args.d.ts +4 -0
  213. package/lib/core/tools/path-args.js +22 -0
  214. package/lib/core/tools/search-tools.d.ts +30 -0
  215. package/lib/core/tools/search-tools.js +321 -34
  216. package/lib/core/tools.d.ts +82 -0
  217. package/lib/core/tools.js +21 -0
  218. package/lib/core/transcript-text.d.ts +19 -0
  219. package/lib/core/transcript-text.js +44 -0
  220. package/lib/core/ui-boot-source.d.ts +5 -0
  221. package/lib/core/ui-boot-source.js +10 -3
  222. package/lib/core/ui-bundles.d.ts +80 -6
  223. package/lib/core/ui-bundles.js +700 -76
  224. package/lib/core/ui-events.d.ts +10 -0
  225. package/lib/core/ui-events.js +25 -0
  226. package/lib/core/ui-methods.d.ts +1 -1
  227. package/lib/core/ui-methods.js +42 -13
  228. package/lib/core/ui-route.js +11 -7
  229. package/lib/core/ui-server.d.ts +6 -0
  230. package/lib/core/ui-server.js +106 -1
  231. package/lib/core/unified-diff.d.ts +35 -0
  232. package/lib/core/unified-diff.js +86 -0
  233. package/lib/core/usage-log.js +39 -0
  234. package/lib/core/web-http.d.ts +1 -1
  235. package/lib/core/web-http.js +1 -3
  236. package/lib/host/kernel.js +57 -41
  237. package/lib/plugins/agent.js +101 -20
  238. package/lib/plugins/approval-floor.js +12 -8
  239. package/lib/plugins/approval.js +252 -80
  240. package/lib/plugins/ask.js +60 -8
  241. package/lib/plugins/browser.js +32 -84
  242. package/lib/plugins/commands.js +167 -57
  243. package/lib/plugins/compact.d.ts +2 -2
  244. package/lib/plugins/compact.js +200 -30
  245. package/lib/plugins/computer-use.js +34 -18
  246. package/lib/plugins/dock-browser.js +24 -65
  247. package/lib/plugins/dsh-compat.js +7 -0
  248. package/lib/plugins/file-review.js +59 -15
  249. package/lib/plugins/git.js +16 -8
  250. package/lib/plugins/goal.js +9 -8
  251. package/lib/plugins/hooks.js +4 -2
  252. package/lib/plugins/host-stdio.js +14 -16
  253. package/lib/plugins/lifecycle-hooks.d.ts +5 -4
  254. package/lib/plugins/lifecycle-hooks.js +12 -10
  255. package/lib/plugins/llm.js +74 -33
  256. package/lib/plugins/lsp.js +22 -27
  257. package/lib/plugins/mcp.js +16 -17
  258. package/lib/plugins/memory.js +3 -24
  259. package/lib/plugins/microcompact.d.ts +4 -1
  260. package/lib/plugins/microcompact.js +117 -19
  261. package/lib/plugins/mode.js +30 -11
  262. package/lib/plugins/permission-presets.d.ts +2 -1
  263. package/lib/plugins/permission-presets.js +55 -35
  264. package/lib/plugins/plugin-manager.js +4 -6
  265. package/lib/plugins/presets.js +56 -27
  266. package/lib/plugins/prompt.js +54 -11
  267. package/lib/plugins/ptc.d.ts +13 -0
  268. package/lib/plugins/ptc.js +121 -24
  269. package/lib/plugins/remote/types.d.ts +1 -1
  270. package/lib/plugins/remote/types.js +11 -0
  271. package/lib/plugins/remote.js +14 -15
  272. package/lib/plugins/runtime.js +91 -14
  273. package/lib/plugins/sandbox.js +181 -60
  274. package/lib/plugins/schedule.js +12 -11
  275. package/lib/plugins/self-improve.js +28 -18
  276. package/lib/plugins/session-search.js +18 -13
  277. package/lib/plugins/session-title.js +1 -1
  278. package/lib/plugins/session.js +103 -25
  279. package/lib/plugins/settings.js +16 -40
  280. package/lib/plugins/skills.js +18 -1
  281. package/lib/plugins/spill.js +18 -11
  282. package/lib/plugins/subagent.js +208 -42
  283. package/lib/plugins/team.js +11 -5
  284. package/lib/plugins/todo.d.ts +1 -1
  285. package/lib/plugins/todo.js +25 -19
  286. package/lib/plugins/tool-search.js +47 -28
  287. package/lib/plugins/tools-default.js +89 -5
  288. package/lib/plugins/tools.js +3 -3
  289. package/lib/plugins/transcript.js +116 -9
  290. package/lib/plugins/web-search.d.ts +1 -1
  291. package/lib/plugins/web-search.js +25 -16
  292. package/lib/plugins/webserver.js +40 -7
  293. package/lib/remote/assets/app-B3Id1EBq.js +14 -0
  294. package/lib/remote/assets/index.html +2 -2
  295. package/lib/remote/assets/{style-DIB6729x.css → style-NtlpbKOI.css} +1 -1
  296. package/lib/services/types.d.ts +247 -29
  297. package/lib/tools/plugin-cli.d.ts +1 -0
  298. package/lib/tools/plugin-cli.js +209 -0
  299. package/lib/ui/assets/app-B-Jx5dnh.js +90 -0
  300. package/lib/ui/assets/{chunk-BajyYBss.js → chunk-Bfdlo8Me.js} +1 -1
  301. package/lib/ui/assets/chunk-DGX-i4eb.js +12 -0
  302. package/lib/ui/assets/index.html +62 -14
  303. package/lib/ui/assets/style-WzxwEPaE.css +1 -0
  304. package/lib/ui/frames.js +1 -3
  305. package/lib/ui/index.d.ts +30 -1
  306. package/lib/ui/index.js +29 -0
  307. package/lib/ui/manifest.d.ts +24 -6
  308. package/lib/ui/manifest.js +3 -2
  309. package/lib/ui/plugins/actions/bundle.json +8 -0
  310. package/lib/ui/plugins/actions/client.js +43 -0
  311. package/lib/ui/plugins/ask/bundle.json +8 -0
  312. package/lib/ui/plugins/ask/client.js +415 -0
  313. package/lib/ui/plugins/browser/bundle.json +8 -0
  314. package/lib/ui/plugins/composer/bundle.json +9 -0
  315. package/lib/ui/plugins/composer/client.js +1806 -1087
  316. package/lib/ui/plugins/files/bundle.json +8 -0
  317. package/lib/ui/plugins/files/client.js +13 -98
  318. package/lib/ui/plugins/manifest.json +1 -104
  319. package/lib/ui/plugins/palette/bundle.json +8 -0
  320. package/lib/ui/plugins/palette/client.js +360 -0
  321. package/lib/ui/plugins/plugins/bundle.json +8 -0
  322. package/lib/ui/plugins/plugins/client.js +116 -38
  323. package/lib/ui/plugins/preview/bundle.json +8 -0
  324. package/lib/ui/plugins/preview/client.js +6 -16
  325. package/lib/ui/plugins/prompt/bundle.json +8 -0
  326. package/lib/ui/plugins/prompt/client.js +81 -47
  327. package/lib/ui/plugins/sessions/bundle.json +8 -0
  328. package/lib/ui/plugins/sessions/client.js +157 -111
  329. package/lib/ui/plugins/settings/bundle.json +8 -0
  330. package/lib/ui/plugins/settings/client.js +184 -170
  331. package/lib/ui/plugins/skills/bundle.json +8 -0
  332. package/lib/ui/plugins/skills/client.js +161 -79
  333. package/lib/ui/plugins/status/bundle.json +8 -0
  334. package/lib/ui/plugins/status/client.js +165 -26
  335. package/lib/ui/plugins/statusbar/bundle.json +9 -0
  336. package/lib/ui/plugins/statusbar/client.js +100 -144
  337. package/lib/ui/plugins/tasks/bundle.json +8 -0
  338. package/lib/ui/plugins/team/bundle.json +8 -0
  339. package/lib/ui/plugins/team/client.js +60 -58
  340. package/lib/ui/plugins/terminal/bundle.json +8 -0
  341. package/lib/ui/plugins/terminal/client.js +1 -7
  342. package/lib/ui/plugins/trace/bundle.json +11 -0
  343. package/lib/ui/plugins/trace/client.js +86 -179
  344. package/lib/ui/plugins/transcript/bundle.json +8 -0
  345. package/lib/ui/plugins/transcript/client.js +1608 -1243
  346. package/lib/ui/sdk/@dsc/ui/index.d.ts +54 -16
  347. package/lib/ui/sdk/@dsc/ui/package.json +1 -1
  348. package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +20 -1968
  349. package/lib/ui/sdk/@dsc/ui-core/core/attachments.d.ts +185 -0
  350. package/lib/ui/sdk/@dsc/ui-core/core/bytes.d.ts +14 -0
  351. package/lib/ui/sdk/@dsc/ui-core/core/err-text.d.ts +18 -0
  352. package/lib/ui/sdk/@dsc/ui-core/core/git-surface.d.ts +17 -0
  353. package/lib/ui/sdk/@dsc/ui-core/core/json-text.d.ts +11 -0
  354. package/lib/ui/sdk/@dsc/ui-core/core/path-policy.d.ts +44 -0
  355. package/lib/ui/sdk/@dsc/ui-core/core/records.d.ts +16 -0
  356. package/lib/ui/sdk/@dsc/ui-core/core/throughput.d.ts +46 -0
  357. package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +18 -2
  358. package/lib/ui/sdk/@dsc/ui-core/core/unified-diff.d.ts +35 -0
  359. package/lib/ui/sdk/@dsc/ui-core/package.json +1 -1
  360. package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +30 -1
  361. package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +24 -6
  362. package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +19 -8
  363. package/lib/ui/sdk/@dsc/ui-core/ui/signal.d.ts +49 -0
  364. package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +17 -3
  365. package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +1 -1
  366. package/lib/ui/sdk/@dsc/ui-dockkit/package.json +1 -1
  367. package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +4 -0
  368. package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +6 -1
  369. package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +21 -0
  370. package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +1 -0
  371. package/lib/ui/sdk/@dsc/ui-layout/package.json +1 -1
  372. package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +1 -1
  373. package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +10 -1
  374. package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +1 -1
  375. package/lib/ui/sdk/@dsc/ui-layout/usage-today.d.ts +11 -0
  376. package/lib/ui/sdk/@dsc/ui-primitives/dialog-focus.d.ts +30 -0
  377. package/lib/ui/sdk/@dsc/ui-primitives/error-text.d.ts +12 -0
  378. package/lib/ui/sdk/@dsc/ui-primitives/git-surface.d.ts +9 -0
  379. package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +23 -0
  380. package/lib/ui/sdk/@dsc/ui-primitives/humanize-error.d.ts +35 -0
  381. package/lib/ui/sdk/@dsc/ui-primitives/icons-workspace.d.ts +33 -0
  382. package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +21 -3
  383. package/lib/ui/sdk/@dsc/ui-primitives/image-lightbox.d.ts +21 -0
  384. package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +16 -0
  385. package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +10 -14
  386. package/lib/ui/sdk/@dsc/ui-primitives/package.json +1 -1
  387. package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +31 -8
  388. package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +2 -0
  389. package/lib/ui/sdk/@dsc/ui-primitives/review-findings-card.d.ts +25 -0
  390. package/lib/ui/sdk/@dsc/ui-primitives/review-findings.d.ts +64 -0
  391. package/lib/ui/sdk/@dsc/ui-primitives/review-notice-card.d.ts +27 -0
  392. package/lib/ui/sdk/@dsc/ui-primitives/review-notice.d.ts +80 -0
  393. package/lib/ui/sdk/@dsc/ui-primitives/signal.d.ts +9 -0
  394. package/lib/ui/sdk/@dsc/ui-primitives/sizes.d.ts +15 -0
  395. package/lib/ui/sdk/@dsc/ui-primitives/skeleton.d.ts +39 -0
  396. package/lib/ui/sdk/@dsc/ui-primitives/snapshot.d.ts +46 -0
  397. package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +3 -3
  398. package/lib/ui/sdk/@dsc/ui-primitives/throughput.d.ts +13 -0
  399. package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +9 -0
  400. package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +1 -1
  401. package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +30 -6
  402. package/lib/ui/sdk/@dsc/ui-primitives/unified-diff.d.ts +10 -0
  403. package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +10 -1
  404. package/lib/ui/sdk/@dsc/ui-renderer/cordis-host.d.ts +113 -0
  405. package/lib/ui/sdk/@dsc/ui-renderer/package.json +1 -1
  406. package/lib/ui/sdk/@dsc/ui-slots/package.json +1 -1
  407. package/lib/ui/services.d.ts +19 -8
  408. package/lib/ui/services.js +20 -12
  409. package/lib/ui/signal.d.ts +49 -0
  410. package/lib/ui/signal.js +57 -0
  411. package/lib/ui/tui-plugins.js +36 -16
  412. package/package.json +71 -58
  413. package/lib/remote/assets/app-DAcUCOEn.js +0 -14
  414. package/lib/ui/assets/app-B70nVIKd.js +0 -69
  415. package/lib/ui/assets/chunk-BGcgwlCI.js +0 -12
  416. package/lib/ui/assets/style-Bq01xH_b.css +0 -1
@@ -22,15 +22,21 @@
22
22
  *
23
23
  * @module dsc/plugins/file-review
24
24
  */
25
- import { readFileSync } from 'node:fs';
25
+ import { closeSync, existsSync, openSync, readFileSync, readSync, statSync } from 'node:fs';
26
26
  import { relative } from 'node:path';
27
27
  import { diffLines, renderHunk, } from '../core/diff-text.js';
28
28
  import { resolvePluginConfig, writePluginConfig } from '../core/plugin-registry.js';
29
29
  import { callFacts } from '../core/tools.js';
30
+ import { clampIntIn as clampInt } from '../core/clamp.js';
31
+ import { readBlockReason } from '../core/path-policy.js';
30
32
  /** 插件在条目树(`~/.dsc/plugins.json`)里的键;同时是设置分区 id。 */
31
33
  export const FILE_REVIEW_CONFIG_KEY = 'file-review';
32
34
  /** 走这套预览的工具:只认会落盘的那两个(bash 里的写没法在动手前知道结果,不在这一位管)。 */
33
35
  const REVIEWED_TOOLS = new Set(['write', 'edit']);
36
+ /** 预览最多读多大的旧文件:再大就不是「改哪几行」,而是整篇贴进对话。 */
37
+ const MAX_PREVIEW_BYTES = 2 * 1024 * 1024;
38
+ /** 嗅探二进制的前若干字节:含 NUL 就按二进制处理,不读全文。 */
39
+ const BINARY_SNIFF_BYTES = 8192;
34
40
  /** 可调值的区间:设置页的 min/max 与这里的夹取共用一份,免得两处对不上。 */
35
41
  export const FILE_REVIEW_RANGES = {
36
42
  /** diff 最多显示几行(含 hunk 头)。 */
@@ -47,11 +53,6 @@ export const FILE_REVIEW_DEFAULTS = {
47
53
  maxLines: 120,
48
54
  contextLines: 3,
49
55
  };
50
- /** 夹到区间内的整数;认不出的值退回缺省。 */
51
- function clampInt(value, range, fallback) {
52
- const num = Number(value);
53
- return Number.isFinite(num) ? Math.min(Math.max(Math.round(num), range.min), range.max) : fallback;
54
- }
55
56
  /**
56
57
  * 逐项夹到 {@link FILE_REVIEW_RANGES} 的范围里,写错类型就用缺省值。
57
58
  * 单个值越界不该让整条工具链停下,所以这里不抛错;真有问题在设置页上看得见。
@@ -91,6 +92,23 @@ function targetPathOf(input) {
91
92
  return null;
92
93
  return callFacts(input.args, input.cwd).target ?? input.target ?? null;
93
94
  }
95
+ /** 前 8KB 里有没有 NUL:有就当二进制,不把整篇当文本 diff。 */
96
+ function looksBinary(path) {
97
+ let fd = null;
98
+ try {
99
+ fd = openSync(path, 'r');
100
+ const buffer = Buffer.alloc(BINARY_SNIFF_BYTES);
101
+ const read = readSync(fd, buffer, 0, BINARY_SNIFF_BYTES, 0);
102
+ return buffer.subarray(0, read).includes(0);
103
+ }
104
+ catch {
105
+ return false;
106
+ }
107
+ finally {
108
+ if (fd !== null)
109
+ closeSync(fd);
110
+ }
111
+ }
94
112
  /** 读旧内容。文件不存在 = 新建(读失败与不存在要分开,读失败得说一句)。 */
95
113
  function readBefore(path) {
96
114
  try {
@@ -119,6 +137,31 @@ export function buildPreview(input, config) {
119
137
  const path = targetPathOf(input);
120
138
  if (path === null)
121
139
  return null;
140
+ // 读禁先行:预览读的是「改之前的旧内容」,和 read 工具读的是同一份东西。
141
+ // 少了这一道,写 ~/.ssh/id_rsa、.env 时旧密钥会以删除行的形式贴进对话与会话日志,
142
+ // 等于借预览绕过 path-policy 的读禁(写硬拒并不覆盖 .ssh)。
143
+ if (existsSync(path)) {
144
+ const blocked = readBlockReason(path);
145
+ if (blocked !== null) {
146
+ return noteOnly(input.toolName, input.cwd, path, `旧内容按读禁规则不能读(${blocked});这里不显示改前内容,这次写入是否放行仍由审批卡决定`);
147
+ }
148
+ // 大文件与二进制不做逐行 diff:同步读整篇会卡住守卫链,二进制转成 utf8 只是一屏乱码。
149
+ // 两者都退成一句摘要,审批照常进行。stat 失败(刚好被删)就按「不预览」走,
150
+ // 绝不能让守卫抛错——守卫链抛错会被按拒处理,等于因为预览失败拦下一次写。
151
+ let size = 0;
152
+ try {
153
+ size = statSync(path).size;
154
+ }
155
+ catch {
156
+ return noteOnly(input.toolName, input.cwd, path, '旧文件读数失败(可能刚被删除),这里不显示改前内容');
157
+ }
158
+ if (size > MAX_PREVIEW_BYTES) {
159
+ return noteOnly(input.toolName, input.cwd, path, `旧文件有 ${String(size)} 字节(超过 ${String(MAX_PREVIEW_BYTES)}),预览不读全文;这次写入是否放行仍由审批卡决定`);
160
+ }
161
+ if (looksBinary(path)) {
162
+ return noteOnly(input.toolName, input.cwd, path, '旧文件看起来是二进制(前 8KB 含 NUL),预览不做逐行 diff;这次写入是否放行仍由审批卡决定');
163
+ }
164
+ }
122
165
  const before = readBefore(path);
123
166
  let after = '';
124
167
  let action = before.missing ? 'create' : 'update';
@@ -211,7 +254,7 @@ export function renderReview(preview, config, note) {
211
254
  const counts = diff.ok
212
255
  ? `+${String(diff.added)} 行 / -${String(diff.removed)} 行`
213
256
  : '逐行 diff 未给出';
214
- const head = [`【文件更改预览·尚未落盘】${verb} ${preview.displayPath}(${counts})`];
257
+ const head = [`【改动前预览·尚未落盘】${verb} ${preview.displayPath}(${counts})`];
215
258
  const body = [];
216
259
  if (diff.identical) {
217
260
  body.push('(内容与磁盘上现在这份完全一样,这次写入不会改动任何一行)');
@@ -270,7 +313,7 @@ export const fileReviewPlugin = {
270
313
  catch (error) {
271
314
  // 守卫链上抛错按拒处理(core/tool-guards.ts:104-109)。预览是锦上添花的东西,
272
315
  // 没有资格因为自己算不动就把一次写操作拦下来,所以这里自己吞掉,只留一句提示。
273
- ctx.emit('dsc/notice', `文件更改预览算不出来(不影响这次调用):${error instanceof Error ? error.message : String(error)}`);
316
+ ctx.emit('dsc/notice', `改动前预览算不出来(不影响这次调用):${error instanceof Error ? error.message : String(error)}`, undefined, input.sessionPath);
274
317
  return { action: 'defer' };
275
318
  }
276
319
  if (preview === null)
@@ -280,8 +323,9 @@ export const fileReviewPlugin = {
280
323
  if (rendered.omitted > 0)
281
324
  truncated += 1;
282
325
  remember(preview.summary);
283
- // 先落进对话流:审批卡(order 30)随即会弹在它下面,用户是先看见改动、再决定放不放行
284
- ctx.emit('dsc/notice', rendered.text);
326
+ // 先落进对话流:审批卡(order 30)随即会弹在它下面,用户是先看见改动、再决定放不放行。
327
+ // 带会话归属:后台 agent 写文件时,diff 预览不该画到用户正在看的会话里(0.6.68)。
328
+ ctx.emit('dsc/notice', rendered.text, undefined, input.sessionPath);
285
329
  return { action: 'defer' };
286
330
  },
287
331
  };
@@ -290,7 +334,7 @@ export const fileReviewPlugin = {
290
334
  const describe = () => {
291
335
  const cfg = config();
292
336
  const lines = [];
293
- lines.push(`文件更改预览:${cfg.enabled ? '开着' : '关着'}|守卫链 order 25(模式 10、安全钩子 20、本插件 25、审批 30)`);
337
+ lines.push(`改动前预览:${cfg.enabled ? '开着' : '关着'}|守卫链 order 25(模式 10、安全钩子 20、本插件 25、审批 30)`);
294
338
  lines.push(`一条预览最多显示 ${String(cfg.maxLines)} 行|每个 hunk 前后留 ${String(cfg.contextLines)} 行上下文`);
295
339
  lines.push(`这次挂载以来发过 ${String(emitted)} 条预览(其中 ${String(truncated)} 条被截断)`);
296
340
  lines.push('配置文件:~/.dsc/plugins.json 的 file-review 条目(设置页也能改)');
@@ -300,12 +344,12 @@ export const fileReviewPlugin = {
300
344
  const offCommand = ctx.commands.register(
301
345
  // 不叫 /review:那是内置的「审查工作区未提交改动」命令,同名注册会把它顶掉
302
346
  // (registry 是 Map.set 覆盖语义,file-review 默认启用,曾把 /review 劫走)。
303
- { name: 'file-review', args: '', description: '看文件更改预览的状态与最近几次预览' }, ({ ui }) => ui.notice(describe()));
347
+ { name: 'file-review', args: '', description: '看改动前预览的状态与最近几次预览' }, ({ ui }) => ui.notice(describe()));
304
348
  // ── 设置分区 ──────────────────────────────────────────────────────────────
305
349
  const section = {
306
350
  id: FILE_REVIEW_CONFIG_KEY,
307
- title: '文件更改预览',
308
- subtitle: 'edit / write 落盘前先把 unified diff 摆进对话流,改哪几行看得见',
351
+ title: '改动前预览',
352
+ subtitle: '写文件、改文件之前,先把改哪几行摆出来',
309
353
  // 排在大输出溢出(37)前面:这一档管的是「改之前看见」,比事后截断更靠前
310
354
  order: 36,
311
355
  fields() {
@@ -314,7 +358,7 @@ export const fileReviewPlugin = {
314
358
  {
315
359
  type: 'switch',
316
360
  key: 'enabled',
317
- label: '启用文件更改预览',
361
+ label: '启用改动前预览',
318
362
  help: '关掉之后不再往对话流贴 diff,工具照常执行、审批照常问。',
319
363
  },
320
364
  {
@@ -1,4 +1,5 @@
1
1
  import { git, parsePorcelainZ, repoPrefix, toWorkspacePath } from '../core/git-exec.js';
2
+ import { sameGitSurface as sameGit } from '../core/git-surface.js';
2
3
  /** 空读数(不是仓库 / 还没读到):界面按「整块不画」处理。 */
3
4
  const EMPTY_GIT = { repo: false, branch: '', detached: false, dirtyFileCount: 0 };
4
5
  /** 三档节奏(毫秒):与状态面板同一套(有改动最勤,不是仓库最松)。 */
@@ -28,6 +29,14 @@ export const gitPlugin = {
28
29
  let dueAt = 0;
29
30
  /** 一拍还在跑时不再起第二拍(git 慢的时候)。 */
30
31
  let busy = false;
32
+ /**
33
+ * 手上这份 {@link cache} 属于哪个工作目录(null = 还没读过)。
34
+ *
35
+ * 用来回答「这次换会话要不要重拍」:读数只有一份、跟着当前会话的目录走,
36
+ * 同一个工作区里换会话读到的还是同一份,重拍纯属白拉三个 git 子进程
37
+ * (2026-11-03 量到每次切会话约 30–50ms 的进程创建开销)。
38
+ */
39
+ let cacheCwd = null;
31
40
  const schedule = (ms) => {
32
41
  const at = Date.now() + ms;
33
42
  if (timer !== null && at >= dueAt)
@@ -43,6 +52,7 @@ export const gitPlugin = {
43
52
  /** 读一拍:分支名 + 改动条数。读不动(不是仓库 / git 不在 / 目录没了)按空读数记。 */
44
53
  const read = async () => {
45
54
  const cwd = ctx.session.current().meta.cwd;
55
+ cacheCwd = cwd;
46
56
  let next;
47
57
  try {
48
58
  // 先问一句「这儿是不是仓库」:不然「不是仓库」与「空仓库(还没提交过)」
@@ -120,13 +130,11 @@ export const gitPlugin = {
120
130
  // 三处催拍:回合收工(这一轮可能落了文件/切了分支)、换会话(换了工作区)、
121
131
  // 以及写类 git op 自己调 refresh()(那条在 desktop-dock 里)。
122
132
  ctx.on('dsc/turn-end', refresh);
123
- ctx.on('dsc/session-open', refresh);
133
+ // 换会话只在**工作目录真的变了**时才重拍:同一个工作区里的会话共用一个仓库读数,
134
+ // 每切一次就拉三个 git 子进程是纯浪费(读数本身由巡检按 12s/30s 的节奏保鲜)。
135
+ ctx.on('dsc/session-open', ({ session }) => {
136
+ if (session.meta.cwd !== cacheCwd)
137
+ refresh();
138
+ });
124
139
  },
125
140
  };
126
- /** 两份读数是不是同一份(变了才推帧,免得干净仓库每 30 秒白推一帧)。 */
127
- function sameGit(left, right) {
128
- return (left.repo === right.repo &&
129
- left.branch === right.branch &&
130
- left.detached === right.detached &&
131
- left.dirtyFileCount === right.dirtyFileCount);
132
- }
@@ -1,5 +1,6 @@
1
1
  import { DEFAULT_MAX_GOAL_ROUNDS, GoalStore } from '../core/goal.js';
2
2
  import { resolvePluginConfig, writePluginConfig } from '../core/plugin-registry.js';
3
+ import { clampInt as clamp } from '../core/clamp.js';
3
4
  /** 配置键(`~/.dsc/plugins.json` 条目树里 `file` 等于这个名字那一项的 `config`)。 */
4
5
  const CONFIG_KEY = 'goal';
5
6
  const DEFAULTS = { defaultMaxRounds: DEFAULT_MAX_GOAL_ROUNDS, extendRoundsBy: 8 };
@@ -9,10 +10,6 @@ const DEFAULTS = { defaultMaxRounds: DEFAULT_MAX_GOAL_ROUNDS, extendRoundsBy: 8
9
10
  */
10
11
  function readConfig(passed) {
11
12
  const raw = resolvePluginConfig(CONFIG_KEY, passed);
12
- const clamp = (value, min, max, fallback) => {
13
- const num = Number(value);
14
- return Number.isFinite(num) ? Math.min(Math.max(Math.round(num), min), max) : fallback;
15
- };
16
13
  return {
17
14
  // 上限 256 与 core/goal.ts 的硬顶一致:配置只能在这个范围内放开,不能取消上限。
18
15
  defaultMaxRounds: clamp(raw.defaultMaxRounds, 1, 256, DEFAULTS.defaultMaxRounds),
@@ -36,11 +33,15 @@ export const goalPlugin = {
36
33
  if (restored !== undefined)
37
34
  goals.restore(restored);
38
35
  const touch = () => ctx.emit('dsc/changed');
39
- /** 把当前目标快照写进会话日志(恢复会话时靠它)并让快照失效。 */
36
+ /**
37
+ * 把当前目标快照写进会话日志(恢复会话时靠它)并让快照失效。
38
+ *
39
+ * **空目标也要写**:用户点 ✕ 清空之后快照是 null,得追加一条 `goal = null` 盖掉
40
+ * 日志里上一条真目标;不写的话日志最后一条仍是清空前那份,重启重放又把它读回来
41
+ * (2026-11-02 报障「目标关闭后重启又会出现」)。
42
+ */
40
43
  const persist = () => {
41
- const snapshot = goals.snapshot;
42
- if (snapshot !== null)
43
- ctx.session.current().appendState('goal', snapshot);
44
+ ctx.session.current().appendState('goal', goals.snapshot);
44
45
  touch();
45
46
  };
46
47
  const service = {
@@ -159,8 +159,10 @@ export const hooksPlugin = {
159
159
  return { action: 'defer' };
160
160
  if (best.action === 'note') {
161
161
  auditHook(best, input);
162
- if (best.message !== '')
163
- ctx.emit('dsc/notice', `安全钩子留了一句:${best.message}`);
162
+ // 带会话归属:后台会话的工具调用触发的钩子留言,不该写进正在看的视图(0.6.68)
163
+ if (best.message !== '') {
164
+ ctx.emit('dsc/notice', `安全钩子留了一句:${best.message}`, undefined, input.sessionPath);
165
+ }
164
166
  return { action: 'defer' };
165
167
  }
166
168
  if (best.action === 'block') {
@@ -4,22 +4,9 @@ import { createDockSession } from '../core/dock-session.js';
4
4
  import { DockBrowserUnavailableError, HOST_BROWSER_SERVICE } from '../core/host-browser-link.js';
5
5
  import { isInvokableMethod } from '../core/host-methods.js';
6
6
  import { resolvePluginConfig } from '../core/plugin-registry.js';
7
+ import { snapshotThrottleMs } from '../core/snapshot-throttle.js';
7
8
  /** 配置键(`~/.dsc/plugins.json` 条目树里 `file` 等于这个名字那一项的 `config`)。 */
8
9
  const CONFIG_KEY = 'host-stdio';
9
- /** 快照推送节流间隔的缺省值(配置没给时用;界面靠它决定最多多久刷一帧)。 */
10
- const DEFAULT_SNAPSHOT_THROTTLE_MS = 80;
11
- /**
12
- * 取快照推送节流间隔:夹在 16 毫秒到 1 秒之间。
13
- * 再小就是一帧一帧追着渲染器跑(白烧 CPU),再大就是点完按钮半天没反应。
14
- * @param passed - 装配时直接传进来的配置(内核挂载时的第二参数)。
15
- */
16
- function readThrottle(passed) {
17
- const raw = resolvePluginConfig(CONFIG_KEY, passed);
18
- const num = Number(raw.snapshotThrottleMs);
19
- if (!Number.isFinite(num))
20
- return DEFAULT_SNAPSHOT_THROTTLE_MS;
21
- return Math.min(Math.max(Math.round(num), 16), 1_000);
22
- }
23
10
  /**
24
11
  * 协议版本(破坏性变更时递增,宿主据此拒绝)。
25
12
  *
@@ -109,26 +96,37 @@ export const hostStdioPlugin = {
109
96
  inject: ['ui'],
110
97
  apply(ctx, passed) {
111
98
  const runtime = ctx.ui;
112
- const throttleMs = readThrottle(passed);
99
+ // 快照推送节流:区间与缺省值见 `core/snapshot-throttle.ts`(与 remote 同一份)。
100
+ const throttleMs = snapshotThrottleMs(resolvePluginConfig(CONFIG_KEY, passed).snapshotThrottleMs);
113
101
  const transport = pickTransport();
114
102
  // ---- 界面可达性 ----
115
103
  // 宿主那头还有人(stdio 的 stdin 没关 / parentPort 还在)就登记成「有人能回答审批卡」,
116
104
  // 审批插件据此决定是弹卡还是立刻按拒,不再白等一次审批超时。
117
105
  const offInteractive = ctx.provide('interactive', { kind: 'host', reachable: () => transport.reachable() });
118
106
  // ---- 快照节流推送 ----
107
+ //
108
+ // 节流的口径是「一帧最密的间隔」,不是「每次变化都先等一个窗口」(2026-11-03):
109
+ // 旧写法第一处变化就 setTimeout(throttleMs),于是「点一下会话」这类**用户刚做完的
110
+ // 动作**永远要多等 60–80ms 才出现在界面上——量到的正是这段(宿主 30ms 就干完了,
111
+ // 界面 95ms 才看到)。现在退化成标准的 leading-edge:距上一帧已经超过窗口就立刻推,
112
+ // 窗口内的连续变化仍旧合并成一帧,密度上限不变。
119
113
  let pendingSnapshot = false;
120
114
  let timer = null;
115
+ /** 上一帧推出去的时刻(0 = 还没推过)。 */
116
+ let lastSentAt = 0;
121
117
  const scheduleSnapshot = () => {
122
118
  pendingSnapshot = true;
123
119
  if (timer !== null)
124
120
  return;
121
+ const wait = Math.max(0, throttleMs - (Date.now() - lastSentAt));
125
122
  timer = setTimeout(() => {
126
123
  timer = null;
127
124
  if (!pendingSnapshot)
128
125
  return;
129
126
  pendingSnapshot = false;
127
+ lastSentAt = Date.now();
130
128
  transport.send({ type: 'snapshot', snapshot: runtime.getSnapshot() });
131
- }, throttleMs);
129
+ }, wait);
132
130
  };
133
131
  const unsubscribe = runtime.subscribe(scheduleSnapshot);
134
132
  // ---- 请求处理 ----
@@ -1,8 +1,8 @@
1
1
  /**
2
- * lifecycle-hooks 插件(官方可开关):把 codex 那十二个生命周期事件名接到 dsc 的扩展点上。
2
+ * lifecycle-hooks 插件(官方可开关):把 codex 那十四个生命周期事件名接到 dsc 的扩展点上。
3
3
  *
4
4
  * 与内置的「安全钩子」(`plugins/hooks.ts`,读 `~/.dsc/hooks.json`)是两回事:
5
- * 那个是 dsc 自己的四个事件,这个是 codex 的十二个名字,配置在
5
+ * 那个是 dsc 自己的四个事件,这个是 codex 的十四个名字(其中六个在 Pneuma 未接通),配置在
6
6
  * `~/.dsc/lifecycle-hooks.json`,**两份配置各读各的**。两者会同时挂在守卫链上(安全钩子 20、
7
7
  * 这里 25,都在审批 30 之前),互不认识。
8
8
  *
@@ -14,8 +14,9 @@
14
14
  * PostCompact → `dsc/compacted`;
15
15
  * Stop / Interrupt → `dsc/turn-end` 的 completed / aborted;
16
16
  * SessionEnd → `dsc/exit`(退出不等钩子跑完);
17
- * 其余四个(PermissionRequest / PreCompact / SubagentStart / SubagentStop)dsc 没有对应扩展点,
18
- * 配了也不执行,只把原因写进能力清单的 problems。
17
+ * 其余六个(PreModelRequest / PostModelRequest / PermissionRequest / PreCompact /
18
+ * SubagentStart / SubagentStop)dsc 没有对应扩展点,配了也不执行,只把原因写进能力清单的
19
+ * problems。
19
20
  *
20
21
  * 钩子脚本的话进模型之前一律过 `wrapUntrusted`(来源 `hook:<事件名>`),
21
22
  * 它说的话是数据,不是指令。
@@ -1,14 +1,12 @@
1
1
  import { HOOK_TIMEOUT_MAX, HOOK_TIMEOUT_MIN } from '../core/hooks.js';
2
2
  import { commandAllowed, denyReasonFor, judgeBlockedByAllowlist, judgeLifecycleRun, lifecycleReport, readLifecycleDoc, resolveLifecycleConfig, runLifecycleCommand, subjectHits, wrapHookOutput, } from '../core/lifecycle-hooks.js';
3
+ import { errText } from '../core/err-text.js';
3
4
  import { contentText } from '../core/llm.js';
4
5
  import { writePluginConfig } from '../core/plugin-registry.js';
5
6
  /** 插件在条目树里的键,也是设置分区 id。 */
6
7
  const CONFIG_KEY = 'lifecycle-hooks';
7
8
  /** 事件档位在界面上的说法。 */
8
9
  const TIER_LABELS = { wired: '已接通', partial: '部分接通', unwired: '未接通' };
9
- function errText(error) {
10
- return error instanceof Error ? error.message : String(error);
11
- }
12
10
  export const lifecycleHooksPlugin = {
13
11
  name: 'lifecycle-hooks',
14
12
  inject: ['session', 'llm', 'approval', 'guards', 'prompt', 'settings', 'commands'],
@@ -28,7 +26,8 @@ export const lifecycleHooksPlugin = {
28
26
  if (announced.has(key))
29
27
  return;
30
28
  announced.add(key);
31
- ctx.emit('dsc/notice', text);
29
+ // 带上会话归属:后台会话的钩子提示不能画到你正在看的会话里。
30
+ ctx.emit('dsc/notice', text, undefined, ctx.session.current().filePath);
32
31
  };
33
32
  /** 载荷的公共字段,字段名照 codex。 */
34
33
  const basePayload = (event, cwd) => ({
@@ -197,6 +196,8 @@ export const lifecycleHooksPlugin = {
197
196
  const fields = () => {
198
197
  const cfg = config();
199
198
  const report = lifecycleReport(cfg.configPath);
199
+ // 未接通的条数现数,不写死:事件表一加,这里的标题跟着变,免得跟下面那张清单打架。
200
+ const unwired = report.capabilities.filter((item) => item.tier === 'unwired').length;
200
201
  const list = [
201
202
  {
202
203
  type: 'switch',
@@ -225,7 +226,7 @@ export const lifecycleHooksPlugin = {
225
226
  type: 'switch',
226
227
  key: 'failClosed',
227
228
  label: '钩子没跑成就算拦',
228
- help: '超时、命令起不来、输出看不懂、退出码非 0 时按「拦下来」处理。关掉就退回「跑不成当没这条钩子」——出了事更难查,建议留着。',
229
+ help: '默认关,与 codex 一致:钩子只有明确用退出码 2(并在 stderr 写原因)才挡下本次操作;超时、起不来、退出码非 0 只记一条提示。打开后这些情况也一律拦——脚本有个小毛病就会把整轮工具调用掐死,只在你确定钩子稳的时候开。',
229
230
  },
230
231
  {
231
232
  type: 'text',
@@ -233,11 +234,11 @@ export const lifecycleHooksPlugin = {
233
234
  label: '命令白名单',
234
235
  mono: true,
235
236
  placeholder: '留空 = 不限制;例如 node, uv',
236
- help: '填了之后只有入口在白名单里的钩子会执行,按命令的第一个词比(`node` 放行 `node guard.js`,不放行 `nodejs-evil`)。被挡下的钩子按「没跑成」处理。',
237
+ help: '填了之后只有入口在白名单里的钩子会执行,按命令的第一个词比(`node` 放行 `node guard.js`,不放行 `nodejs-evil`)。被挡下的钩子算「没跑成」,拦不拦由上面那个开关决定。',
237
238
  },
238
239
  {
239
240
  type: 'info',
240
- label: '十二个事件的接通情况',
241
+ label: `十四个事件的接通情况(${String(unwired)} 个未接通)`,
241
242
  mono: true,
242
243
  text: report.capabilities.map((item) => `${item.event}|${TIER_LABELS[item.tier]}|${item.extension}`).join('\n'),
243
244
  help: '「未接通」的事件 dsc 现在没有可挂的扩展点,配了钩子也不会执行,原因见下面那条。',
@@ -266,8 +267,8 @@ export const lifecycleHooksPlugin = {
266
267
  };
267
268
  const section = {
268
269
  id: CONFIG_KEY,
269
- title: '生命周期钩子',
270
- subtitle: '按 codex 的事件名跑外部命令钩子',
270
+ title: '外部命令钩子',
271
+ subtitle: '模型动手前后运行你的脚本(沿用 codex 的事件名)',
271
272
  order: 36,
272
273
  fields,
273
274
  values() {
@@ -315,9 +316,10 @@ export const lifecycleHooksPlugin = {
315
316
  offs.push(ctx.commands.register({ name: 'lifecycle-hooks', args: '', description: '看生命周期钩子的能力清单与已加载的钩子' }, ({ ui }) => {
316
317
  const cfg = config();
317
318
  const report = lifecycleReport(cfg.configPath);
319
+ const unwired = report.capabilities.filter((item) => item.tier === 'unwired').length;
318
320
  const lines = [
319
321
  `生命周期钩子:${cfg.enabled ? '开着' : '关着'}|配置文件 ${cfg.configPath}`,
320
- `十二个事件(${report.capabilities.length} 个):`,
322
+ `十四个事件(${String(report.capabilities.length)} 个,其中 ${String(unwired)} 个在 Pneuma 未接通):`,
321
323
  ];
322
324
  for (const item of report.capabilities)
323
325
  lines.push(` ${item.event}|${TIER_LABELS[item.tier]}|${item.extension}`);
@@ -37,28 +37,42 @@ export const llmPlugin = {
37
37
  inject: ['session'],
38
38
  provide: 'llm',
39
39
  apply(ctx, config) {
40
- let currentProvider = config.defaultProvider;
41
- let currentModel = config.defaultModel;
42
- // 'default' = 不发思考字段(跟随端点默认行为)
43
- let currentEffort = 'default';
44
- // T39:会话里记过模型选择就先恢复它(/model 切过的不丢);没记过才用配置默认。
45
- const remembered = ctx.session.current().state('model');
46
- if (remembered !== undefined && findModel(remembered.provider, remembered.model) !== undefined) {
47
- currentProvider = remembered.provider;
48
- currentModel = remembered.model;
40
+ /**
41
+ * 模型与思考档位**按会话**存(2026-10-28,与权限同一批):值在会话 `model` 状态条目里,
42
+ * 不再有进程级 currentProvider/currentModel。后台 agent 用自己的会话取路由,
43
+ * 不会因为用户看着别的会话就换模型。
44
+ *
45
+ * `lastSelected` 只服务一件事:新建会话没记过模型时沿用「上一次选的那一组」,
46
+ * 保持 /model 热切换的老手感;恢复老会话没有记录时按配置默认走。
47
+ */
48
+ let lastSelected = {
49
+ provider: config.defaultProvider,
50
+ model: config.defaultModel,
51
+ // 'default' = 不发思考字段(跟随端点默认行为)
52
+ effort: 'default',
53
+ };
54
+ // T39:启动会话记过模型就先恢复它;没记过才用配置默认。
55
+ const startupSaved = ctx.session.current().state('model');
56
+ if (startupSaved !== undefined && findModel(startupSaved.provider, startupSaved.model) !== undefined) {
57
+ lastSelected = {
58
+ provider: startupSaved.provider,
59
+ model: startupSaved.model,
60
+ effort: clampEffort(capsFor(startupSaved.provider, startupSaved.model), startupSaved.effort ?? 'default'),
61
+ };
49
62
  }
50
- // 切会话跟着切模型:新会话记过谁就用谁,没记过保持当前选择(与 /model 的
51
- // 进程级热切换同一手感)。配置里已经没有的模型不恢复,静默留在当前选择上。
52
- ctx.on('dsc/session-open', ({ session }) => {
53
- const recalled = session.state('model');
54
- if (recalled === undefined || findModel(recalled.provider, recalled.model) === undefined)
63
+ // 新建会话(没有 filePath)没记过模型时,把上一次选的写进去;恢复老会话只在有记录时用记录。
64
+ ctx.on('dsc/session-open', ({ session, filePath }) => {
65
+ if (session.state('model') !== undefined) {
66
+ ctx.emit('dsc/changed');
55
67
  return;
56
- if (recalled.provider === currentProvider && recalled.model === currentModel)
68
+ }
69
+ if (filePath !== undefined)
57
70
  return;
58
- currentProvider = recalled.provider;
59
- currentModel = recalled.model;
60
- // 原来选的档位在新模型上未必存在,退回「默认」比留着发不出去的值强
61
- currentEffort = clampEffort(capsFor(currentProvider, currentModel), currentEffort);
71
+ // 没选过档位时用偏好的新会话默认(设置里改「思考强度」会同时记成默认)
72
+ const effort = lastSelected.effort === 'default'
73
+ ? (ctx.get('settings')?.prefs().defaultEffort ?? 'default')
74
+ : lastSelected.effort;
75
+ session.appendState('model', { provider: lastSelected.provider, model: lastSelected.model, effort });
62
76
  ctx.emit('dsc/changed');
63
77
  });
64
78
  /** 协议适配器表:id → 适配器。内置 openai-completions 预注册,插件可补新的协议。 */
@@ -98,24 +112,49 @@ export const llmPlugin = {
98
112
  ...(provider.cacheControl === true ? { cacheControl: true } : {}),
99
113
  };
100
114
  }
115
+ const effectiveOf = (session) => {
116
+ // 最小假会话(探针)没有 state:按配置默认算,别把一次判定炸掉。
117
+ const saved = typeof session.state === 'function' ? session.state('model') : undefined;
118
+ const provider = saved !== undefined && findModel(saved.provider, saved.model) !== undefined ? saved.provider : config.defaultProvider;
119
+ const model = saved !== undefined && findModel(saved.provider, saved.model) !== undefined ? saved.model : config.defaultModel;
120
+ const fallbackEffort = (ctx.get('settings')?.prefs().defaultEffort ?? 'default');
121
+ const effort = clampEffort(capsFor(provider, model), saved?.effort ?? fallbackEffort);
122
+ return { provider, model, effort };
123
+ };
124
+ const windowOf = (effective) => findModel(effective.provider, effective.model)?.contextWindow ?? 128_000;
101
125
  const service = {
102
126
  get provider() {
103
- return currentProvider;
127
+ return effectiveOf(ctx.session.current()).provider;
104
128
  },
105
129
  get model() {
106
- return currentModel;
130
+ return effectiveOf(ctx.session.current()).model;
107
131
  },
108
132
  get effort() {
109
- return currentEffort;
133
+ return effectiveOf(ctx.session.current()).effort;
110
134
  },
111
135
  get contextWindow() {
112
- return findModel(currentProvider, currentModel)?.contextWindow ?? 128_000;
136
+ return windowOf(effectiveOf(ctx.session.current()));
113
137
  },
114
138
  get inputModalities() {
115
- return capsFor(currentProvider, currentModel).modalities;
139
+ const effective = effectiveOf(ctx.session.current());
140
+ return capsFor(effective.provider, effective.model).modalities;
116
141
  },
117
142
  route() {
118
- return routeFor(currentProvider, currentModel, currentEffort);
143
+ const effective = effectiveOf(ctx.session.current());
144
+ return routeFor(effective.provider, effective.model, effective.effort);
145
+ },
146
+ routeForSession(session) {
147
+ const effective = effectiveOf(session);
148
+ return routeFor(effective.provider, effective.model, effective.effort);
149
+ },
150
+ providerOf(session) {
151
+ return effectiveOf(session).provider;
152
+ },
153
+ modelOf(session) {
154
+ return effectiveOf(session).model;
155
+ },
156
+ contextWindowOf(session) {
157
+ return windowOf(effectiveOf(session));
119
158
  },
120
159
  routeTo(provider, model, effort) {
121
160
  return routeFor(provider, model, effort);
@@ -144,7 +183,9 @@ export const llmPlugin = {
144
183
  return adapter.stream({ ...request, sessionId: request.sessionId ?? currentSessionId(ctx) }, { ...handlers, onSanitize: (report) => noticeSanitize(ctx, report) });
145
184
  },
146
185
  setEffort(effort) {
147
- const caps = capsFor(currentProvider, currentModel);
186
+ const session = ctx.session.current();
187
+ const current = effectiveOf(session);
188
+ const caps = capsFor(current.provider, current.model);
148
189
  if (!hasEffortLevel(caps, effort)) {
149
190
  const declared = caps.thinkingLevels.length === 0
150
191
  ? '这个模型没声明思考能力,只有「默认」可选'
@@ -152,7 +193,8 @@ export const llmPlugin = {
152
193
  const wanted = effort === 'default' ? '默认' : THINKING_LEVEL_LABELS[effort];
153
194
  throw new Error(`思考档位「${wanted}」用不了 —— ${declared}(在设置 → 模型里给它勾上)`);
154
195
  }
155
- currentEffort = effort;
196
+ session.appendState('model', { provider: current.provider, model: current.model, effort });
197
+ lastSelected = { provider: current.provider, model: current.model, effort };
156
198
  ctx.emit('dsc/changed');
157
199
  },
158
200
  setModel(provider, model) {
@@ -163,12 +205,11 @@ export const llmPlugin = {
163
205
  if (!target.models.some((entry) => entry.id === model)) {
164
206
  throw new Error(`端点 ${provider} 没有模型 ${model};可用:${target.models.map((entry) => entry.id).join('、')}`);
165
207
  }
166
- currentProvider = provider;
167
- currentModel = model;
168
208
  // 原来选的档位在新模型上未必存在,退回「默认」比留着发不出去的值强
169
- currentEffort = clampEffort(capsFor(provider, model), currentEffort);
170
- // T39:记进当前会话——恢复会话时优先用它,重启/重开不再回落配置默认
171
- ctx.session.current().appendState('model', { provider, model });
209
+ const effort = clampEffort(capsFor(provider, model), effectiveOf(ctx.session.current()).effort);
210
+ // 记进当前会话——恢复会话时优先用它,后台 agent 也按自己的记录取路由
211
+ ctx.session.current().appendState('model', { provider, model, effort });
212
+ lastSelected = { provider, model, effort };
172
213
  ctx.emit('dsc/changed');
173
214
  },
174
215
  parseModelRef(ref) {
@@ -179,7 +220,7 @@ export const llmPlugin = {
179
220
  if (ref.startsWith(`${name}/`))
180
221
  return { provider: name, model: ref.slice(name.length + 1) };
181
222
  }
182
- return { provider: currentProvider, model: ref };
223
+ return { provider: effectiveOf(ctx.session.current()).provider, model: ref };
183
224
  },
184
225
  listModels() {
185
226
  const choices = [];