@jingyi0605/codingns4dsh 0.2.1-beta.11 → 0.2.1-beta.13

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 (542) hide show
  1. package/README.en.md +7 -5
  2. package/README.md +9 -5
  3. package/data/build/dist/bootstrap/dsh-connection-adapter.d.ts +1 -1
  4. package/data/build/dist/bootstrap/index.d.ts +1 -1
  5. package/data/build/dist/client/account-bar.d.ts.map +1 -1
  6. package/data/build/dist/client/account-bar.js +24 -70
  7. package/data/build/dist/client/account-bar.js.map +1 -1
  8. package/data/build/dist/client/adapter-catalog-watch.d.ts +1 -1
  9. package/data/build/dist/client/adapter-catalog-watch.d.ts.map +1 -1
  10. package/data/build/dist/client/adapter-catalog-watch.js +2 -2
  11. package/data/build/dist/client/adapter-catalog-watch.js.map +1 -1
  12. package/data/build/dist/client/bundle.js +35978 -21117
  13. package/data/build/dist/client/bundle.js.map +1 -1
  14. package/data/build/dist/client/cli-management-dialog.d.ts +21 -0
  15. package/data/build/dist/client/cli-management-dialog.d.ts.map +1 -0
  16. package/data/build/dist/client/cli-management-dialog.js +215 -0
  17. package/data/build/dist/client/cli-management-dialog.js.map +1 -0
  18. package/data/build/dist/client/cli-management-terminal.d.ts +9 -0
  19. package/data/build/dist/client/cli-management-terminal.d.ts.map +1 -0
  20. package/data/build/dist/client/cli-management-terminal.js +30 -0
  21. package/data/build/dist/client/cli-management-terminal.js.map +1 -0
  22. package/data/build/dist/client/cli-settings-dialog.d.ts +9 -0
  23. package/data/build/dist/client/cli-settings-dialog.d.ts.map +1 -0
  24. package/data/build/dist/client/cli-settings-dialog.js +45 -0
  25. package/data/build/dist/client/cli-settings-dialog.js.map +1 -0
  26. package/data/build/dist/client/cli-settings-rpc.js +1 -1
  27. package/data/build/dist/client/cli-settings-rpc.js.map +1 -1
  28. package/data/build/dist/client/cli-slots.d.ts +7 -2
  29. package/data/build/dist/client/cli-slots.d.ts.map +1 -1
  30. package/data/build/dist/client/cli-slots.js +44 -12
  31. package/data/build/dist/client/cli-slots.js.map +1 -1
  32. package/data/build/dist/client/client.assistant-configuration-view.js +5 -5
  33. package/data/build/dist/client/client.assistant-configuration-view.js.map +1 -1
  34. package/data/build/dist/client/client.editor-engine.js +4 -1
  35. package/data/build/dist/client/client.editor-engine.js.map +1 -1
  36. package/data/build/dist/client/client.moss-voice-output.js +0 -166
  37. package/data/build/dist/client/client.moss-voice-output.js.map +1 -1
  38. package/data/build/dist/client/client.native-workspace-store.js +4 -4
  39. package/data/build/dist/client/client.native-workspace-store.js.map +1 -1
  40. package/data/build/dist/client/client.primitives-adapter.js +53 -0
  41. package/data/build/dist/client/client.primitives-adapter.js.map +1 -1
  42. package/data/build/dist/client/client.react-dom.js +166 -0
  43. package/data/build/dist/client/client.react-dom.js.map +1 -1
  44. package/data/build/dist/client/client.session-translation.js +25 -1
  45. package/data/build/dist/client/client.session-translation.js.map +1 -1
  46. package/data/build/dist/client/client.transport.js +503 -42
  47. package/data/build/dist/client/client.transport.js.map +1 -1
  48. package/data/build/dist/client/conversation-translation-settings.d.ts +11 -0
  49. package/data/build/dist/client/conversation-translation-settings.d.ts.map +1 -0
  50. package/data/build/dist/client/conversation-translation-settings.js +54 -0
  51. package/data/build/dist/client/conversation-translation-settings.js.map +1 -0
  52. package/data/build/dist/client/desktop-assistant.js +967 -479
  53. package/data/build/dist/client/editor-engine.d.ts +1 -1
  54. package/data/build/dist/client/editor-engine.d.ts.map +1 -1
  55. package/data/build/dist/client/editor-engine.js +4 -1
  56. package/data/build/dist/client/editor-engine.js.map +1 -1
  57. package/data/build/dist/client/features/cli-adapters.d.ts +3 -1
  58. package/data/build/dist/client/features/cli-adapters.d.ts.map +1 -1
  59. package/data/build/dist/client/features/cli-adapters.js +182 -106
  60. package/data/build/dist/client/features/cli-adapters.js.map +1 -1
  61. package/data/build/dist/client/features/file-management.d.ts.map +1 -1
  62. package/data/build/dist/client/features/file-management.js +2 -0
  63. package/data/build/dist/client/features/file-management.js.map +1 -1
  64. package/data/build/dist/client/features/index.d.ts.map +1 -1
  65. package/data/build/dist/client/features/index.js +2 -0
  66. package/data/build/dist/client/features/index.js.map +1 -1
  67. package/data/build/dist/client/features/peer-host.d.ts.map +1 -1
  68. package/data/build/dist/client/features/peer-host.js +3 -0
  69. package/data/build/dist/client/features/peer-host.js.map +1 -1
  70. package/data/build/dist/client/features/quick-apps.d.ts +3 -0
  71. package/data/build/dist/client/features/quick-apps.d.ts.map +1 -0
  72. package/data/build/dist/client/features/quick-apps.js +14 -0
  73. package/data/build/dist/client/features/quick-apps.js.map +1 -0
  74. package/data/build/dist/client/features/session-translation.d.ts.map +1 -1
  75. package/data/build/dist/client/features/session-translation.js +7 -1
  76. package/data/build/dist/client/features/session-translation.js.map +1 -1
  77. package/data/build/dist/client/html-workspace-files.d.ts +4 -0
  78. package/data/build/dist/client/html-workspace-files.d.ts.map +1 -0
  79. package/data/build/dist/client/html-workspace-files.js +114 -0
  80. package/data/build/dist/client/html-workspace-files.js.map +1 -0
  81. package/data/build/dist/client/locale.d.ts.map +1 -1
  82. package/data/build/dist/client/locale.js +6 -0
  83. package/data/build/dist/client/locale.js.map +1 -1
  84. package/data/build/dist/client/locales/cliManagement.d.ts +3 -0
  85. package/data/build/dist/client/locales/cliManagement.d.ts.map +1 -0
  86. package/data/build/dist/client/locales/cliManagement.js +139 -0
  87. package/data/build/dist/client/locales/cliManagement.js.map +1 -0
  88. package/data/build/dist/client/locales/fileWorkspace.d.ts.map +1 -1
  89. package/data/build/dist/client/locales/fileWorkspace.js +4 -0
  90. package/data/build/dist/client/locales/fileWorkspace.js.map +1 -1
  91. package/data/build/dist/client/locales/panels.d.ts.map +1 -1
  92. package/data/build/dist/client/locales/panels.js +46 -0
  93. package/data/build/dist/client/locales/panels.js.map +1 -1
  94. package/data/build/dist/client/locales/quickApps.d.ts +130 -0
  95. package/data/build/dist/client/locales/quickApps.d.ts.map +1 -0
  96. package/data/build/dist/client/locales/quickApps.js +150 -0
  97. package/data/build/dist/client/locales/quickApps.js.map +1 -0
  98. package/data/build/dist/client/native-model-translation-menu.d.ts.map +1 -1
  99. package/data/build/dist/client/native-model-translation-menu.js +3 -1
  100. package/data/build/dist/client/native-model-translation-menu.js.map +1 -1
  101. package/data/build/dist/client/quick-apps/client.d.ts +29 -0
  102. package/data/build/dist/client/quick-apps/client.d.ts.map +1 -0
  103. package/data/build/dist/client/quick-apps/client.js +68 -0
  104. package/data/build/dist/client/quick-apps/client.js.map +1 -0
  105. package/data/build/dist/client/quick-apps/document.d.ts +26 -0
  106. package/data/build/dist/client/quick-apps/document.d.ts.map +1 -0
  107. package/data/build/dist/client/quick-apps/document.js +110 -0
  108. package/data/build/dist/client/quick-apps/document.js.map +1 -0
  109. package/data/build/dist/client/quick-apps/file-picker.d.ts +14 -0
  110. package/data/build/dist/client/quick-apps/file-picker.d.ts.map +1 -0
  111. package/data/build/dist/client/quick-apps/file-picker.js +51 -0
  112. package/data/build/dist/client/quick-apps/file-picker.js.map +1 -0
  113. package/data/build/dist/client/quick-apps/launcher.d.ts +7 -0
  114. package/data/build/dist/client/quick-apps/launcher.d.ts.map +1 -0
  115. package/data/build/dist/client/quick-apps/launcher.js +252 -0
  116. package/data/build/dist/client/quick-apps/launcher.js.map +1 -0
  117. package/data/build/dist/client/quick-apps/presentation.d.ts +16 -0
  118. package/data/build/dist/client/quick-apps/presentation.d.ts.map +1 -0
  119. package/data/build/dist/client/quick-apps/presentation.js +31 -0
  120. package/data/build/dist/client/quick-apps/presentation.js.map +1 -0
  121. package/data/build/dist/client/quick-apps/reorder-animation.d.ts +6 -0
  122. package/data/build/dist/client/quick-apps/reorder-animation.d.ts.map +1 -0
  123. package/data/build/dist/client/quick-apps/reorder-animation.js +50 -0
  124. package/data/build/dist/client/quick-apps/reorder-animation.js.map +1 -0
  125. package/data/build/dist/client/quick-apps/reorder.d.ts +26 -0
  126. package/data/build/dist/client/quick-apps/reorder.d.ts.map +1 -0
  127. package/data/build/dist/client/quick-apps/reorder.js +128 -0
  128. package/data/build/dist/client/quick-apps/reorder.js.map +1 -0
  129. package/data/build/dist/client/quick-apps/styles.d.ts +3 -0
  130. package/data/build/dist/client/quick-apps/styles.d.ts.map +1 -0
  131. package/data/build/dist/client/quick-apps/styles.js +143 -0
  132. package/data/build/dist/client/quick-apps/styles.js.map +1 -0
  133. package/data/build/dist/client/quick-apps/ui.d.ts +20 -0
  134. package/data/build/dist/client/quick-apps/ui.d.ts.map +1 -0
  135. package/data/build/dist/client/quick-apps/ui.js +21 -0
  136. package/data/build/dist/client/quick-apps/ui.js.map +1 -0
  137. package/data/build/dist/client/quick-apps/viewer.d.ts +16 -0
  138. package/data/build/dist/client/quick-apps/viewer.d.ts.map +1 -0
  139. package/data/build/dist/client/quick-apps/viewer.js +155 -0
  140. package/data/build/dist/client/quick-apps/viewer.js.map +1 -0
  141. package/data/build/dist/client/quick-apps/workspace-picker.d.ts +19 -0
  142. package/data/build/dist/client/quick-apps/workspace-picker.d.ts.map +1 -0
  143. package/data/build/dist/client/quick-apps/workspace-picker.js +30 -0
  144. package/data/build/dist/client/quick-apps/workspace-picker.js.map +1 -0
  145. package/data/build/dist/client/session-translation-chat.d.ts +10 -4
  146. package/data/build/dist/client/session-translation-chat.d.ts.map +1 -1
  147. package/data/build/dist/client/session-translation-chat.js +154 -52
  148. package/data/build/dist/client/session-translation-chat.js.map +1 -1
  149. package/data/build/dist/client/session-translation-pending-dom.d.ts +1 -1
  150. package/data/build/dist/client/session-translation-pending-dom.d.ts.map +1 -1
  151. package/data/build/dist/client/session-translation-pending-dom.js +4 -4
  152. package/data/build/dist/client/session-translation-pending-dom.js.map +1 -1
  153. package/data/build/dist/client/session-translation-retry.d.ts +16 -0
  154. package/data/build/dist/client/session-translation-retry.d.ts.map +1 -0
  155. package/data/build/dist/client/session-translation-retry.js +66 -0
  156. package/data/build/dist/client/session-translation-retry.js.map +1 -0
  157. package/data/build/dist/client/session-translation-rules.d.ts +13 -0
  158. package/data/build/dist/client/session-translation-rules.d.ts.map +1 -0
  159. package/data/build/dist/client/session-translation-rules.js +58 -0
  160. package/data/build/dist/client/session-translation-rules.js.map +1 -0
  161. package/data/build/dist/client/sidebar-footer-style.d.ts +13 -0
  162. package/data/build/dist/client/sidebar-footer-style.d.ts.map +1 -0
  163. package/data/build/dist/client/sidebar-footer-style.js +54 -0
  164. package/data/build/dist/client/sidebar-footer-style.js.map +1 -0
  165. package/data/build/dist/client/style.css +276 -276
  166. package/data/build/dist/client/terminal/model.d.ts.map +1 -1
  167. package/data/build/dist/client/terminal/model.js +2 -1
  168. package/data/build/dist/client/terminal/model.js.map +1 -1
  169. package/data/build/dist/dsh-capabilities/client/composer-slot-selectors.d.ts +4 -0
  170. package/data/build/dist/dsh-capabilities/client/composer-slot-selectors.d.ts.map +1 -0
  171. package/data/build/dist/dsh-capabilities/client/composer-slot-selectors.js +8 -0
  172. package/data/build/dist/dsh-capabilities/client/composer-slot-selectors.js.map +1 -0
  173. package/data/build/dist/dsh-capabilities/client/interaction-presentation-adapter.d.ts.map +1 -1
  174. package/data/build/dist/dsh-capabilities/client/interaction-presentation-adapter.js +4 -13
  175. package/data/build/dist/dsh-capabilities/client/interaction-presentation-adapter.js.map +1 -1
  176. package/data/build/dist/dsh-capabilities/client/interaction-text-dom.js +1 -1
  177. package/data/build/dist/dsh-capabilities/client/interaction-text-dom.js.map +1 -1
  178. package/data/build/dist/dsh-capabilities/client/message-presentation-adapter.d.ts +19 -0
  179. package/data/build/dist/dsh-capabilities/client/message-presentation-adapter.d.ts.map +1 -0
  180. package/data/build/dist/dsh-capabilities/client/message-presentation-adapter.js +39 -0
  181. package/data/build/dist/dsh-capabilities/client/message-presentation-adapter.js.map +1 -0
  182. package/data/build/dist/dsh-capabilities/client/primitives-adapter.d.ts +18 -0
  183. package/data/build/dist/dsh-capabilities/client/primitives-adapter.d.ts.map +1 -1
  184. package/data/build/dist/dsh-capabilities/client/primitives-adapter.js +21 -0
  185. package/data/build/dist/dsh-capabilities/client/primitives-adapter.js.map +1 -1
  186. package/data/build/dist/dsh-capabilities/client/quick-app-footer-adapter.d.ts +18 -0
  187. package/data/build/dist/dsh-capabilities/client/quick-app-footer-adapter.d.ts.map +1 -0
  188. package/data/build/dist/dsh-capabilities/client/quick-app-footer-adapter.js +11 -0
  189. package/data/build/dist/dsh-capabilities/client/quick-app-footer-adapter.js.map +1 -0
  190. package/data/build/dist/dsh-capabilities/client/session-performance-adapter.d.ts +8 -0
  191. package/data/build/dist/dsh-capabilities/client/session-performance-adapter.d.ts.map +1 -0
  192. package/data/build/dist/dsh-capabilities/client/session-performance-adapter.js +100 -0
  193. package/data/build/dist/dsh-capabilities/client/session-performance-adapter.js.map +1 -0
  194. package/data/build/dist/dsh-capabilities/client/sidebar-footer-icon-adapter.d.ts +3 -0
  195. package/data/build/dist/dsh-capabilities/client/sidebar-footer-icon-adapter.d.ts.map +1 -0
  196. package/data/build/dist/dsh-capabilities/client/sidebar-footer-icon-adapter.js +22 -0
  197. package/data/build/dist/dsh-capabilities/client/sidebar-footer-icon-adapter.js.map +1 -0
  198. package/data/build/dist/dsh-capabilities/client/slot-presentation-mirror.d.ts +2 -0
  199. package/data/build/dist/dsh-capabilities/client/slot-presentation-mirror.d.ts.map +1 -1
  200. package/data/build/dist/dsh-capabilities/client/slot-presentation-mirror.js +28 -0
  201. package/data/build/dist/dsh-capabilities/client/slot-presentation-mirror.js.map +1 -1
  202. package/data/build/dist/dsh-capabilities/host/connection-peer-adapter.d.ts +10 -0
  203. package/data/build/dist/dsh-capabilities/host/connection-peer-adapter.d.ts.map +1 -0
  204. package/data/build/dist/dsh-capabilities/host/connection-peer-adapter.js +34 -0
  205. package/data/build/dist/dsh-capabilities/host/connection-peer-adapter.js.map +1 -0
  206. package/data/build/dist/dsh-capabilities/host/native-dispatch-adapter.d.ts +21 -0
  207. package/data/build/dist/dsh-capabilities/host/native-dispatch-adapter.d.ts.map +1 -0
  208. package/data/build/dist/dsh-capabilities/host/native-dispatch-adapter.js +11 -0
  209. package/data/build/dist/dsh-capabilities/host/native-dispatch-adapter.js.map +1 -0
  210. package/data/build/dist/dsh-capabilities/host/quick-app-credentials.d.ts +11 -0
  211. package/data/build/dist/dsh-capabilities/host/quick-app-credentials.d.ts.map +1 -0
  212. package/data/build/dist/dsh-capabilities/host/quick-app-credentials.js +97 -0
  213. package/data/build/dist/dsh-capabilities/host/quick-app-credentials.js.map +1 -0
  214. package/data/build/dist/dsh-capabilities/host/quick-app-https-provider.d.ts +36 -0
  215. package/data/build/dist/dsh-capabilities/host/quick-app-https-provider.d.ts.map +1 -0
  216. package/data/build/dist/dsh-capabilities/host/quick-app-https-provider.js +164 -0
  217. package/data/build/dist/dsh-capabilities/host/quick-app-https-provider.js.map +1 -0
  218. package/data/build/dist/dsh-capabilities/host/quick-app-lan-ports.d.ts +44 -0
  219. package/data/build/dist/dsh-capabilities/host/quick-app-lan-ports.d.ts.map +1 -0
  220. package/data/build/dist/dsh-capabilities/host/quick-app-lan-ports.js +240 -0
  221. package/data/build/dist/dsh-capabilities/host/quick-app-lan-ports.js.map +1 -0
  222. package/data/build/dist/dsh-capabilities/host/quick-app-origin-adapter.d.ts +37 -0
  223. package/data/build/dist/dsh-capabilities/host/quick-app-origin-adapter.d.ts.map +1 -0
  224. package/data/build/dist/dsh-capabilities/host/quick-app-origin-adapter.js +35 -0
  225. package/data/build/dist/dsh-capabilities/host/quick-app-origin-adapter.js.map +1 -0
  226. package/data/build/dist/dsh-capabilities/host/quick-app-proxy-adapter.d.ts +13 -0
  227. package/data/build/dist/dsh-capabilities/host/quick-app-proxy-adapter.d.ts.map +1 -0
  228. package/data/build/dist/dsh-capabilities/host/quick-app-proxy-adapter.js +30 -0
  229. package/data/build/dist/dsh-capabilities/host/quick-app-proxy-adapter.js.map +1 -0
  230. package/data/build/dist/dsh-capabilities/host/quick-app-proxy-provider.d.ts +21 -0
  231. package/data/build/dist/dsh-capabilities/host/quick-app-proxy-provider.d.ts.map +1 -0
  232. package/data/build/dist/dsh-capabilities/host/quick-app-proxy-provider.js +132 -0
  233. package/data/build/dist/dsh-capabilities/host/quick-app-proxy-provider.js.map +1 -0
  234. package/data/build/dist/dsh-capabilities/host/quick-app-transport.d.ts +10 -0
  235. package/data/build/dist/dsh-capabilities/host/quick-app-transport.d.ts.map +1 -0
  236. package/data/build/dist/dsh-capabilities/host/quick-app-transport.js +33 -0
  237. package/data/build/dist/dsh-capabilities/host/quick-app-transport.js.map +1 -0
  238. package/data/build/dist/dsh-capabilities/host/session-activation-adapter.d.ts +17 -0
  239. package/data/build/dist/dsh-capabilities/host/session-activation-adapter.d.ts.map +1 -0
  240. package/data/build/dist/dsh-capabilities/host/session-activation-adapter.js +37 -0
  241. package/data/build/dist/dsh-capabilities/host/session-activation-adapter.js.map +1 -0
  242. package/data/build/dist/dsh-capabilities/host/session-model-selection-adapter.d.ts +17 -0
  243. package/data/build/dist/dsh-capabilities/host/session-model-selection-adapter.d.ts.map +1 -0
  244. package/data/build/dist/dsh-capabilities/host/session-model-selection-adapter.js +45 -0
  245. package/data/build/dist/dsh-capabilities/host/session-model-selection-adapter.js.map +1 -0
  246. package/data/build/dist/dsh-capabilities/host/session-performance-adapter.d.ts +7 -0
  247. package/data/build/dist/dsh-capabilities/host/session-performance-adapter.d.ts.map +1 -0
  248. package/data/build/dist/dsh-capabilities/host/session-performance-adapter.js +18 -0
  249. package/data/build/dist/dsh-capabilities/host/session-performance-adapter.js.map +1 -0
  250. package/data/build/dist/dsh-capabilities/host/session-prompt-adapter.d.ts +28 -0
  251. package/data/build/dist/dsh-capabilities/host/session-prompt-adapter.d.ts.map +1 -0
  252. package/data/build/dist/dsh-capabilities/host/session-prompt-adapter.js +31 -0
  253. package/data/build/dist/dsh-capabilities/host/session-prompt-adapter.js.map +1 -0
  254. package/data/build/dist/dsh-capabilities/host/workspace-directory-adapter.d.ts +13 -0
  255. package/data/build/dist/dsh-capabilities/host/workspace-directory-adapter.d.ts.map +1 -0
  256. package/data/build/dist/dsh-capabilities/host/workspace-directory-adapter.js +24 -0
  257. package/data/build/dist/dsh-capabilities/host/workspace-directory-adapter.js.map +1 -0
  258. package/data/build/dist/dsh-capabilities/matrix.d.ts.map +1 -1
  259. package/data/build/dist/dsh-capabilities/matrix.js +19 -5
  260. package/data/build/dist/dsh-capabilities/matrix.js.map +1 -1
  261. package/data/build/dist/dsh-capabilities/routes.d.ts +1 -0
  262. package/data/build/dist/dsh-capabilities/routes.d.ts.map +1 -1
  263. package/data/build/dist/dsh-capabilities/routes.js +41 -5
  264. package/data/build/dist/dsh-capabilities/routes.js.map +1 -1
  265. package/data/build/dist/dsh-capabilities/types.d.ts +1 -1
  266. package/data/build/dist/dsh-capabilities/types.d.ts.map +1 -1
  267. package/data/build/dist/dsh-capabilities/types.js.map +1 -1
  268. package/data/build/dist/host/cli-adapters/antigravity-driver.js +1 -1
  269. package/data/build/dist/host/cli-adapters/antigravity-driver.js.map +1 -1
  270. package/data/build/dist/host/cli-adapters/attachment-utils.d.ts +4 -3
  271. package/data/build/dist/host/cli-adapters/attachment-utils.d.ts.map +1 -1
  272. package/data/build/dist/host/cli-adapters/attachment-utils.js +9 -8
  273. package/data/build/dist/host/cli-adapters/attachment-utils.js.map +1 -1
  274. package/data/build/dist/host/cli-adapters/binary-detection.d.ts.map +1 -1
  275. package/data/build/dist/host/cli-adapters/binary-detection.js +7 -3
  276. package/data/build/dist/host/cli-adapters/binary-detection.js.map +1 -1
  277. package/data/build/dist/host/cli-adapters/claude-driver.d.ts +1 -0
  278. package/data/build/dist/host/cli-adapters/claude-driver.d.ts.map +1 -1
  279. package/data/build/dist/host/cli-adapters/claude-driver.js +180 -21
  280. package/data/build/dist/host/cli-adapters/claude-driver.js.map +1 -1
  281. package/data/build/dist/host/cli-adapters/codex-driver.d.ts +18 -0
  282. package/data/build/dist/host/cli-adapters/codex-driver.d.ts.map +1 -1
  283. package/data/build/dist/host/cli-adapters/codex-driver.js +97 -5
  284. package/data/build/dist/host/cli-adapters/codex-driver.js.map +1 -1
  285. package/data/build/dist/host/cli-adapters/codex-performance-projection.d.ts +91 -0
  286. package/data/build/dist/host/cli-adapters/codex-performance-projection.d.ts.map +1 -0
  287. package/data/build/dist/host/cli-adapters/codex-performance-projection.js +8 -0
  288. package/data/build/dist/host/cli-adapters/codex-performance-projection.js.map +1 -0
  289. package/data/build/dist/host/cli-adapters/codex-performance.d.ts +16 -0
  290. package/data/build/dist/host/cli-adapters/codex-performance.d.ts.map +1 -0
  291. package/data/build/dist/host/cli-adapters/codex-performance.js +81 -0
  292. package/data/build/dist/host/cli-adapters/codex-performance.js.map +1 -0
  293. package/data/build/dist/host/cli-adapters/command-code-driver.js +1 -1
  294. package/data/build/dist/host/cli-adapters/command-code-driver.js.map +1 -1
  295. package/data/build/dist/host/cli-adapters/driver.d.ts +2 -0
  296. package/data/build/dist/host/cli-adapters/driver.d.ts.map +1 -1
  297. package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts +2 -0
  298. package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts.map +1 -1
  299. package/data/build/dist/host/cli-adapters/dsh-message-projector.js +28 -7
  300. package/data/build/dist/host/cli-adapters/dsh-message-projector.js.map +1 -1
  301. package/data/build/dist/host/cli-adapters/feature.d.ts +2 -0
  302. package/data/build/dist/host/cli-adapters/feature.d.ts.map +1 -1
  303. package/data/build/dist/host/cli-adapters/feature.js +186 -71
  304. package/data/build/dist/host/cli-adapters/feature.js.map +1 -1
  305. package/data/build/dist/host/cli-adapters/gemini-driver.js +1 -1
  306. package/data/build/dist/host/cli-adapters/gemini-driver.js.map +1 -1
  307. package/data/build/dist/host/cli-adapters/grok-driver.d.ts +3 -0
  308. package/data/build/dist/host/cli-adapters/grok-driver.d.ts.map +1 -1
  309. package/data/build/dist/host/cli-adapters/grok-driver.js +277 -53
  310. package/data/build/dist/host/cli-adapters/grok-driver.js.map +1 -1
  311. package/data/build/dist/host/cli-adapters/grok-performance-projection.d.ts +123 -0
  312. package/data/build/dist/host/cli-adapters/grok-performance-projection.d.ts.map +1 -0
  313. package/data/build/dist/host/cli-adapters/grok-performance-projection.js +47 -0
  314. package/data/build/dist/host/cli-adapters/grok-performance-projection.js.map +1 -0
  315. package/data/build/dist/host/cli-adapters/grok-usage.d.ts +45 -0
  316. package/data/build/dist/host/cli-adapters/grok-usage.d.ts.map +1 -0
  317. package/data/build/dist/host/cli-adapters/grok-usage.js +197 -0
  318. package/data/build/dist/host/cli-adapters/grok-usage.js.map +1 -0
  319. package/data/build/dist/host/cli-adapters/kimi-driver.js +2 -2
  320. package/data/build/dist/host/cli-adapters/kimi-driver.js.map +1 -1
  321. package/data/build/dist/host/cli-adapters/management-installation.d.ts +5 -0
  322. package/data/build/dist/host/cli-adapters/management-installation.d.ts.map +1 -0
  323. package/data/build/dist/host/cli-adapters/management-installation.js +131 -0
  324. package/data/build/dist/host/cli-adapters/management-installation.js.map +1 -0
  325. package/data/build/dist/host/cli-adapters/management-methods.d.ts +32 -0
  326. package/data/build/dist/host/cli-adapters/management-methods.d.ts.map +1 -0
  327. package/data/build/dist/host/cli-adapters/management-methods.js +135 -0
  328. package/data/build/dist/host/cli-adapters/management-methods.js.map +1 -0
  329. package/data/build/dist/host/cli-adapters/management-process.d.ts +7 -0
  330. package/data/build/dist/host/cli-adapters/management-process.d.ts.map +1 -0
  331. package/data/build/dist/host/cli-adapters/management-process.js +51 -0
  332. package/data/build/dist/host/cli-adapters/management-process.js.map +1 -0
  333. package/data/build/dist/host/cli-adapters/management.d.ts +32 -0
  334. package/data/build/dist/host/cli-adapters/management.d.ts.map +1 -0
  335. package/data/build/dist/host/cli-adapters/management.js +172 -0
  336. package/data/build/dist/host/cli-adapters/management.js.map +1 -0
  337. package/data/build/dist/host/cli-adapters/mcode-driver.js +1 -1
  338. package/data/build/dist/host/cli-adapters/mcode-driver.js.map +1 -1
  339. package/data/build/dist/host/cli-adapters/model-catalog.d.ts +1 -0
  340. package/data/build/dist/host/cli-adapters/model-catalog.d.ts.map +1 -1
  341. package/data/build/dist/host/cli-adapters/model-catalog.js +62 -0
  342. package/data/build/dist/host/cli-adapters/model-catalog.js.map +1 -1
  343. package/data/build/dist/host/cli-adapters/native-team-subagent.d.ts.map +1 -1
  344. package/data/build/dist/host/cli-adapters/native-team-subagent.js +2 -1
  345. package/data/build/dist/host/cli-adapters/native-team-subagent.js.map +1 -1
  346. package/data/build/dist/host/cli-adapters/opencode-driver.d.ts +22 -0
  347. package/data/build/dist/host/cli-adapters/opencode-driver.d.ts.map +1 -1
  348. package/data/build/dist/host/cli-adapters/opencode-driver.js +105 -17
  349. package/data/build/dist/host/cli-adapters/opencode-driver.js.map +1 -1
  350. package/data/build/dist/host/cli-adapters/pi-driver.js +1 -1
  351. package/data/build/dist/host/cli-adapters/pi-driver.js.map +1 -1
  352. package/data/build/dist/host/cli-adapters/process-utils.d.ts +2 -0
  353. package/data/build/dist/host/cli-adapters/process-utils.d.ts.map +1 -1
  354. package/data/build/dist/host/cli-adapters/process-utils.js +16 -11
  355. package/data/build/dist/host/cli-adapters/process-utils.js.map +1 -1
  356. package/data/build/dist/host/cli-adapters/registry.d.ts +3 -0
  357. package/data/build/dist/host/cli-adapters/registry.d.ts.map +1 -1
  358. package/data/build/dist/host/cli-adapters/registry.js +56 -21
  359. package/data/build/dist/host/cli-adapters/registry.js.map +1 -1
  360. package/data/build/dist/host/cli-adapters/session-performance-projection.d.ts +74 -0
  361. package/data/build/dist/host/cli-adapters/session-performance-projection.d.ts.map +1 -0
  362. package/data/build/dist/host/cli-adapters/session-performance-projection.js +83 -0
  363. package/data/build/dist/host/cli-adapters/session-performance-projection.js.map +1 -0
  364. package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts +3 -1
  365. package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts.map +1 -1
  366. package/data/build/dist/host/cli-adapters/stream-normalizer.js +2 -0
  367. package/data/build/dist/host/cli-adapters/stream-normalizer.js.map +1 -1
  368. package/data/build/dist/host/cli-adapters/update-check.d.ts +34 -0
  369. package/data/build/dist/host/cli-adapters/update-check.d.ts.map +1 -0
  370. package/data/build/dist/host/cli-adapters/update-check.js +263 -0
  371. package/data/build/dist/host/cli-adapters/update-check.js.map +1 -0
  372. package/data/build/dist/host/cli-adapters/zcode-driver.js +1 -1
  373. package/data/build/dist/host/cli-adapters/zcode-driver.js.map +1 -1
  374. package/data/build/dist/host/features/file-management.d.ts.map +1 -1
  375. package/data/build/dist/host/features/file-management.js +8 -0
  376. package/data/build/dist/host/features/file-management.js.map +1 -1
  377. package/data/build/dist/host/features/global-voice-rpc.d.ts.map +1 -1
  378. package/data/build/dist/host/features/global-voice-rpc.js +2 -3
  379. package/data/build/dist/host/features/global-voice-rpc.js.map +1 -1
  380. package/data/build/dist/host/features/index.d.ts.map +1 -1
  381. package/data/build/dist/host/features/index.js +2 -0
  382. package/data/build/dist/host/features/index.js.map +1 -1
  383. package/data/build/dist/host/features/lan-access-dsh.js +1 -1
  384. package/data/build/dist/host/features/lan-access-dsh.js.map +1 -1
  385. package/data/build/dist/host/features/peer-host.d.ts.map +1 -1
  386. package/data/build/dist/host/features/peer-host.js +13 -6
  387. package/data/build/dist/host/features/peer-host.js.map +1 -1
  388. package/data/build/dist/host/features/quick-apps.d.ts +4 -0
  389. package/data/build/dist/host/features/quick-apps.d.ts.map +1 -0
  390. package/data/build/dist/host/features/quick-apps.js +158 -0
  391. package/data/build/dist/host/features/quick-apps.js.map +1 -0
  392. package/data/build/dist/host/features/session-prompt-translation.d.ts +10 -0
  393. package/data/build/dist/host/features/session-prompt-translation.d.ts.map +1 -0
  394. package/data/build/dist/host/features/session-prompt-translation.js +198 -0
  395. package/data/build/dist/host/features/session-prompt-translation.js.map +1 -0
  396. package/data/build/dist/host/features/session-translation-protection.d.ts +12 -1
  397. package/data/build/dist/host/features/session-translation-protection.d.ts.map +1 -1
  398. package/data/build/dist/host/features/session-translation-protection.js +44 -5
  399. package/data/build/dist/host/features/session-translation-protection.js.map +1 -1
  400. package/data/build/dist/host/features/session-translation-recovery.d.ts +21 -0
  401. package/data/build/dist/host/features/session-translation-recovery.d.ts.map +1 -0
  402. package/data/build/dist/host/features/session-translation-recovery.js +125 -0
  403. package/data/build/dist/host/features/session-translation-recovery.js.map +1 -0
  404. package/data/build/dist/host/features/session-translation-service.d.ts +8 -2
  405. package/data/build/dist/host/features/session-translation-service.d.ts.map +1 -1
  406. package/data/build/dist/host/features/session-translation-service.js +69 -19
  407. package/data/build/dist/host/features/session-translation-service.js.map +1 -1
  408. package/data/build/dist/host/features/session-translation.d.ts.map +1 -1
  409. package/data/build/dist/host/features/session-translation.js +4 -1
  410. package/data/build/dist/host/features/session-translation.js.map +1 -1
  411. package/data/build/dist/host/features/types.d.ts +10 -0
  412. package/data/build/dist/host/features/types.d.ts.map +1 -1
  413. package/data/build/dist/host/html-workspace-files.d.ts +3 -0
  414. package/data/build/dist/host/html-workspace-files.d.ts.map +1 -0
  415. package/data/build/dist/host/html-workspace-files.js +135 -0
  416. package/data/build/dist/host/html-workspace-files.js.map +1 -0
  417. package/data/build/dist/host/index.d.ts.map +1 -1
  418. package/data/build/dist/host/index.js +27 -2
  419. package/data/build/dist/host/index.js.map +1 -1
  420. package/data/build/dist/host/lan-access-dsh.d.ts +5 -1
  421. package/data/build/dist/host/lan-access-dsh.d.ts.map +1 -1
  422. package/data/build/dist/host/lan-access-dsh.js +43 -2
  423. package/data/build/dist/host/lan-access-dsh.js.map +1 -1
  424. package/data/build/dist/host/modules/peer-host/peer-host-native-dispatch.d.ts +2 -2
  425. package/data/build/dist/host/modules/peer-host/peer-host-native-dispatch.d.ts.map +1 -1
  426. package/data/build/dist/host/modules/peer-host/peer-host-native-dispatch.js +10 -9
  427. package/data/build/dist/host/modules/peer-host/peer-host-native-dispatch.js.map +1 -1
  428. package/data/build/dist/host/modules/peer-host/peer-host-native-streams.d.ts +3 -3
  429. package/data/build/dist/host/modules/peer-host/peer-host-native-streams.d.ts.map +1 -1
  430. package/data/build/dist/host/modules/peer-host/peer-host-native-streams.js +26 -14
  431. package/data/build/dist/host/modules/peer-host/peer-host-native-streams.js.map +1 -1
  432. package/data/build/dist/host/modules/peer-host/quick-app-gateway.d.ts +5 -0
  433. package/data/build/dist/host/modules/peer-host/quick-app-gateway.d.ts.map +1 -0
  434. package/data/build/dist/host/modules/peer-host/quick-app-gateway.js +27 -0
  435. package/data/build/dist/host/modules/peer-host/quick-app-gateway.js.map +1 -0
  436. package/data/build/dist/host/modules/quick-apps/browse.d.ts +5 -0
  437. package/data/build/dist/host/modules/quick-apps/browse.d.ts.map +1 -0
  438. package/data/build/dist/host/modules/quick-apps/browse.js +37 -0
  439. package/data/build/dist/host/modules/quick-apps/browse.js.map +1 -0
  440. package/data/build/dist/host/modules/quick-apps/code-revision.d.ts +4 -0
  441. package/data/build/dist/host/modules/quick-apps/code-revision.d.ts.map +1 -0
  442. package/data/build/dist/host/modules/quick-apps/code-revision.js +39 -0
  443. package/data/build/dist/host/modules/quick-apps/code-revision.js.map +1 -0
  444. package/data/build/dist/host/modules/quick-apps/documents.d.ts +14 -0
  445. package/data/build/dist/host/modules/quick-apps/documents.d.ts.map +1 -0
  446. package/data/build/dist/host/modules/quick-apps/documents.js +87 -0
  447. package/data/build/dist/host/modules/quick-apps/documents.js.map +1 -0
  448. package/data/build/dist/host/modules/quick-apps/errors.d.ts +8 -0
  449. package/data/build/dist/host/modules/quick-apps/errors.d.ts.map +1 -0
  450. package/data/build/dist/host/modules/quick-apps/errors.js +15 -0
  451. package/data/build/dist/host/modules/quick-apps/errors.js.map +1 -0
  452. package/data/build/dist/host/modules/quick-apps/file-api.d.ts +30 -0
  453. package/data/build/dist/host/modules/quick-apps/file-api.d.ts.map +1 -0
  454. package/data/build/dist/host/modules/quick-apps/file-api.js +149 -0
  455. package/data/build/dist/host/modules/quick-apps/file-api.js.map +1 -0
  456. package/data/build/dist/host/modules/quick-apps/launches.d.ts +35 -0
  457. package/data/build/dist/host/modules/quick-apps/launches.d.ts.map +1 -0
  458. package/data/build/dist/host/modules/quick-apps/launches.js +80 -0
  459. package/data/build/dist/host/modules/quick-apps/launches.js.map +1 -0
  460. package/data/build/dist/host/modules/quick-apps/paths.d.ts +14 -0
  461. package/data/build/dist/host/modules/quick-apps/paths.d.ts.map +1 -0
  462. package/data/build/dist/host/modules/quick-apps/paths.js +72 -0
  463. package/data/build/dist/host/modules/quick-apps/paths.js.map +1 -0
  464. package/data/build/dist/host/modules/quick-apps/registry.d.ts +30 -0
  465. package/data/build/dist/host/modules/quick-apps/registry.d.ts.map +1 -0
  466. package/data/build/dist/host/modules/quick-apps/registry.js +186 -0
  467. package/data/build/dist/host/modules/quick-apps/registry.js.map +1 -0
  468. package/data/build/dist/host/modules/quick-apps/remote.d.ts +38 -0
  469. package/data/build/dist/host/modules/quick-apps/remote.d.ts.map +1 -0
  470. package/data/build/dist/host/modules/quick-apps/remote.js +237 -0
  471. package/data/build/dist/host/modules/quick-apps/remote.js.map +1 -0
  472. package/data/build/dist/host/modules/quick-apps/service.d.ts +27 -0
  473. package/data/build/dist/host/modules/quick-apps/service.d.ts.map +1 -0
  474. package/data/build/dist/host/modules/quick-apps/service.js +170 -0
  475. package/data/build/dist/host/modules/quick-apps/service.js.map +1 -0
  476. package/data/build/dist/host/modules/quick-apps/static-handler.d.ts +8 -0
  477. package/data/build/dist/host/modules/quick-apps/static-handler.d.ts.map +1 -0
  478. package/data/build/dist/host/modules/quick-apps/static-handler.js +181 -0
  479. package/data/build/dist/host/modules/quick-apps/static-handler.js.map +1 -0
  480. package/data/build/dist/host/native-session-bridge.d.ts +7 -1
  481. package/data/build/dist/host/native-session-bridge.d.ts.map +1 -1
  482. package/data/build/dist/host/native-session-bridge.js +8 -13
  483. package/data/build/dist/host/native-session-bridge.js.map +1 -1
  484. package/data/build/dist/host/rpc.d.ts.map +1 -1
  485. package/data/build/dist/host/rpc.js +21 -10
  486. package/data/build/dist/host/rpc.js.map +1 -1
  487. package/data/build/dist/host/settings.d.ts.map +1 -1
  488. package/data/build/dist/host/settings.js +18 -1
  489. package/data/build/dist/host/settings.js.map +1 -1
  490. package/data/build/dist/host/workspace-file-mutations.d.ts +2 -0
  491. package/data/build/dist/host/workspace-file-mutations.d.ts.map +1 -0
  492. package/data/build/dist/host/workspace-file-mutations.js +15 -0
  493. package/data/build/dist/host/workspace-file-mutations.js.map +1 -0
  494. package/data/build/dist/shared/attachment-prompts.d.ts +11 -0
  495. package/data/build/dist/shared/attachment-prompts.d.ts.map +1 -0
  496. package/data/build/dist/shared/attachment-prompts.js +17 -0
  497. package/data/build/dist/shared/attachment-prompts.js.map +1 -0
  498. package/data/build/dist/shared/codex-performance.d.ts +3 -0
  499. package/data/build/dist/shared/codex-performance.d.ts.map +1 -0
  500. package/data/build/dist/shared/codex-performance.js +2 -0
  501. package/data/build/dist/shared/codex-performance.js.map +1 -0
  502. package/data/build/dist/shared/contracts/cli-adapter.d.ts +33 -1
  503. package/data/build/dist/shared/contracts/cli-adapter.d.ts.map +1 -1
  504. package/data/build/dist/shared/contracts/cli-management.d.ts +29 -0
  505. package/data/build/dist/shared/contracts/cli-management.d.ts.map +1 -0
  506. package/data/build/dist/shared/contracts/cli-management.js +2 -0
  507. package/data/build/dist/shared/contracts/cli-management.js.map +1 -0
  508. package/data/build/dist/shared/contracts/config.d.ts +2 -0
  509. package/data/build/dist/shared/contracts/config.d.ts.map +1 -1
  510. package/data/build/dist/shared/contracts/config.js.map +1 -1
  511. package/data/build/dist/shared/contracts/errors.d.ts +2 -2
  512. package/data/build/dist/shared/contracts/quick-apps.d.ts +68 -0
  513. package/data/build/dist/shared/contracts/quick-apps.d.ts.map +1 -0
  514. package/data/build/dist/shared/contracts/quick-apps.js +4 -0
  515. package/data/build/dist/shared/contracts/quick-apps.js.map +1 -0
  516. package/data/build/dist/shared/contracts/session-translation.d.ts +20 -2
  517. package/data/build/dist/shared/contracts/session-translation.d.ts.map +1 -1
  518. package/data/build/dist/shared/contracts/session-translation.js +24 -0
  519. package/data/build/dist/shared/contracts/session-translation.js.map +1 -1
  520. package/data/build/dist/shared/contracts/version.d.ts +4 -4
  521. package/data/build/dist/shared/contracts/version.js +3 -3
  522. package/data/build/dist/shared/peer-host-http-routes.d.ts +4 -0
  523. package/data/build/dist/shared/peer-host-http-routes.d.ts.map +1 -1
  524. package/data/build/dist/shared/peer-host-http-routes.js +4 -0
  525. package/data/build/dist/shared/peer-host-http-routes.js.map +1 -1
  526. package/data/build/dist/shared/quick-app-proxy-path.d.ts +6 -0
  527. package/data/build/dist/shared/quick-app-proxy-path.d.ts.map +1 -0
  528. package/data/build/dist/shared/quick-app-proxy-path.js +18 -0
  529. package/data/build/dist/shared/quick-app-proxy-path.js.map +1 -0
  530. package/data/build/dist/shared/quick-apps-bootstrap-locale.d.ts +7 -0
  531. package/data/build/dist/shared/quick-apps-bootstrap-locale.d.ts.map +1 -0
  532. package/data/build/dist/shared/quick-apps-bootstrap-locale.js +10 -0
  533. package/data/build/dist/shared/quick-apps-bootstrap-locale.js.map +1 -0
  534. package/data/build/dist/shared/request-performance.d.ts +15 -0
  535. package/data/build/dist/shared/request-performance.d.ts.map +1 -0
  536. package/data/build/dist/shared/request-performance.js +3 -0
  537. package/data/build/dist/shared/request-performance.js.map +1 -0
  538. package/package.json +35 -34
  539. package/profile/README.md +2 -2
  540. package/profile/package.json +3 -3
  541. package/profile/version.json +3 -3
  542. package/version.json +3 -3
@@ -1,5 +1,6 @@
1
1
  import { runAsyncCommand } from './process-utils.js';
2
2
  import { spawn, spawnSync } from 'node:child_process';
3
+ import { randomUUID } from 'node:crypto';
3
4
  import { homedir } from 'node:os';
4
5
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
5
6
  import { JsonRpcProcess } from './json-rpc-process.js';
@@ -14,13 +15,17 @@ import { ACP_FORM_CLIENT_CAPABILITIES, acpElicitationResponse, readAcpElicitatio
14
15
  import { readAgentQuestions } from './interaction-events.js';
15
16
  import { commandEnvironment, WINDOWS } from './process-utils.js';
16
17
  import { imageArtifactPathsFromValue, stripImageMarkdown } from '../image-artifact-store.js';
18
+ import { advanceCodingNsSegment, createCodingNsSegmentState, decorateCodingNsSegmentEvent } from './stream-normalizer.js';
19
+ import { GrokContextUsage, GrokPromptUsage } from './grok-usage.js';
17
20
  /** Grok Build 的 ACP stdio 驱动。ACP 会话和权限细节只在 Host 进程内处理。 */
18
21
  export class GrokBuildDriver {
19
22
  descriptor = { id: 'grok', name: 'Grok Build', protocol: 'acp', capabilities: ['models', 'skills', 'stream', 'tool-events', 'reasoning', 'usage', 'permission', 'questions'] };
23
+ supportsStreamStepSplitting = true;
20
24
  binaries;
21
25
  runSpawnSync;
22
26
  runSpawn;
23
27
  sessionRoots;
28
+ now;
24
29
  cachedBinary = null;
25
30
  processes = new Set();
26
31
  sessions = new Map();
@@ -28,6 +33,7 @@ export class GrokBuildDriver {
28
33
  this.binaries = options.binaries ?? ['grok', 'grok-build'];
29
34
  this.runSpawnSync = options.spawnSync ?? spawnSync;
30
35
  this.runSpawn = options.spawn ?? spawn;
36
+ this.now = options.now ?? Date.now;
31
37
  this.sessionRoots = options.sessionRoots ?? [join(process.env.GROK_HOME ?? join(homedir(), '.grok'), 'sessions')];
32
38
  }
33
39
  async detect() {
@@ -106,26 +112,45 @@ export class GrokBuildDriver {
106
112
  const rpc = state.rpc;
107
113
  let providerSessionId = state.providerSessionId;
108
114
  let stream;
115
+ let reusable = false;
116
+ const promptId = randomUUID();
117
+ const segmentState = createCodingNsSegmentState();
118
+ let stepPhase;
119
+ let stepStreamId;
120
+ const activeTools = new Map();
121
+ const streamedToolInputs = new Map();
109
122
  try {
110
123
  if (providerSessionId === '') {
111
124
  const session = await rpc.request('session/new', {
112
125
  cwd: input.cwd ?? process.cwd(),
113
126
  mcpServers: acpBridgeMcpServers(input.sessionId, this.descriptor.id),
114
- ...(!isProviderDefaultModel(input.modelId) ? { model: input.modelId } : {}),
115
127
  }, { signal: input.signal });
116
128
  providerSessionId = readSessionId(session) ?? input.sessionId;
129
+ state.contextUsage.observe(session);
117
130
  state.providerSessionId = providerSessionId;
118
131
  this.sessions.set(input.sessionId, state);
119
132
  this.sessions.set(providerSessionId, state);
120
133
  }
121
134
  yield { type: 'session-binding', providerSessionId };
135
+ // Grok 1.0.52 ignores the model field on session/new. Apply explicit
136
+ // selections after both creation and restoration, including reused sessions.
137
+ if (input.modelId && !isProviderDefaultModel(input.modelId)) {
138
+ const selected = await rpc.request('session/set_model', { sessionId: providerSessionId, modelId: input.modelId }, { signal: input.signal });
139
+ state.contextUsage.modelId = input.modelId;
140
+ state.contextUsage.observe(selected);
141
+ }
142
+ if (input.effortId) {
143
+ await rpc.request('session/set_config_option', { sessionId: providerSessionId, configId: 'reasoning_effort', value: input.effortId }, { signal: input.signal });
144
+ }
122
145
  // Skill 斜杠命令由 Grok 在用户输入开头解析,不能把普通提示插到命令前。
123
146
  const nativeCommand = /^\s*\/[A-Za-z0-9][A-Za-z0-9._:-]*(?:\s|$)/u.test(input.prompt);
124
147
  const prompt = [
125
148
  ...(nativeCommand ? [] : [{ type: 'text', text: GROK_QUESTION_GUIDANCE }]),
126
149
  ...await buildAcpPromptBlocks(input.prompt, input.attachments ?? []),
127
150
  ];
128
- stream = streamGrokPrompt(rpc, providerSessionId, prompt, input.signal, (notification) => {
151
+ const usage = new GrokPromptUsage(promptId, state.contextUsage, this.now);
152
+ stream = streamGrokPrompt(rpc, providerSessionId, promptId, prompt, input.signal, (notification) => {
153
+ usage.observe(notification);
129
154
  const elicitation = readAcpElicitationRequest(notification);
130
155
  if (elicitation !== null)
131
156
  state.questions.set(elicitation.requestId, elicitation);
@@ -136,8 +161,9 @@ export class GrokBuildDriver {
136
161
  // 已回答的问题被重新登记。tool_call 可以先显示问题卡并暂存用户答案。
137
162
  const requestId = interactionRequestId(notification);
138
163
  if (requestId !== null && notification.id !== undefined && notification.id !== null)
139
- state.requests.set(requestId, { rpcId: notification.id, ...permissionOptions(notification) });
140
- });
164
+ state.requests.set(requestId, { rpcId: notification.id, callId: permissionCallId(notification), ...permissionOptions(notification) });
165
+ return usage.takeObservation();
166
+ }, response => { usage.observeResponse(response); return usage.takeObservation(); });
141
167
  let finishResult;
142
168
  while (true) {
143
169
  const item = await stream.next();
@@ -145,12 +171,25 @@ export class GrokBuildDriver {
145
171
  finishResult = item.value;
146
172
  break;
147
173
  }
148
- for (const rawChunk of acpMessageToChunks(item.value)) {
149
- const chunk = rawChunk.type === 'image-artifact'
174
+ if (item.value.codingnsGrokObservation !== undefined)
175
+ yield item.value.codingnsGrokObservation;
176
+ const streamId = grokStreamId(item.value);
177
+ for (const rawChunk of grokToolInputChunks(item.value, streamedToolInputs) ?? acpMessageToChunks(item.value)) {
178
+ // Settle native turn accounting once, after the terminal drain. Per-call
179
+ // usage is retained by the RPC observer solely for timing and fallback.
180
+ if (rawChunk.type === 'usage')
181
+ continue;
182
+ let resolved = rawChunk.type === 'image-artifact'
150
183
  ? await resolveGrokImageArtifact(rawChunk, state, this.sessionRoots)
151
184
  : rawChunk;
152
- if (chunk === null)
185
+ if (resolved === null)
153
186
  continue;
187
+ if (resolved.type === 'tool-event' && resolved.status === 'failed' && resolved.callId) {
188
+ const denial = state.permissionDenials.get(resolved.callId);
189
+ if (denial !== undefined)
190
+ resolved = { ...resolved, error: denial, output: denial, outputMode: 'snapshot' };
191
+ }
192
+ const chunk = decorateCodingNsSegmentEvent(resolved, input, segmentState, this.descriptor.id);
154
193
  if (chunk.type === 'question-request' && state.grokQuestionCallIds.has(chunk.requestId)) {
155
194
  if (state.grokQuestionEventIds.has(chunk.requestId))
156
195
  continue;
@@ -160,15 +199,56 @@ export class GrokBuildDriver {
160
199
  // 工具记录,否则历史里会重新出现空参数或重复的问题调用。
161
200
  if (chunk.type === 'tool-event' && chunk.callId !== undefined && state.grokQuestionCallIds.has(chunk.callId))
162
201
  continue;
202
+ const phase = grokStepPhase(chunk);
203
+ if (phase !== undefined) {
204
+ // DSH persists assistant content only at step settlement. End the content
205
+ // step before native tools are appended, and keep unfinished parallel calls
206
+ // together so their results cannot be finalized by an intermediate step.
207
+ if (input.splitToolSteps && stepPhase !== undefined && activeTools.size === 0
208
+ && (phase !== stepPhase || (streamId !== undefined && stepStreamId !== undefined && streamId !== stepStreamId))) {
209
+ yield { type: 'step-boundary' };
210
+ }
211
+ stepPhase = phase;
212
+ if (streamId !== undefined)
213
+ stepStreamId = streamId;
214
+ }
215
+ if (chunk.type === 'tool-event') {
216
+ const callId = chunk.callId ?? chunk.toolName;
217
+ if (chunk.status === 'completed' || chunk.status === 'failed')
218
+ activeTools.delete(callId);
219
+ else
220
+ activeTools.set(callId, chunk.toolName === 'tool' ? activeTools.get(callId) ?? chunk.toolName : chunk.toolName);
221
+ }
163
222
  yield chunk;
223
+ advanceCodingNsSegment(chunk, segmentState);
224
+ if (chunk.type === 'question-request')
225
+ segmentState.segment += 1;
164
226
  }
165
227
  }
166
- if (finishResult.reason === 'cancel') {
167
- try {
168
- await rpc.request('session/cancel', { sessionId: providerSessionId }, { killOnAbort: false });
228
+ const settledUsage = usage.finish();
229
+ if (settledUsage !== undefined) {
230
+ const { requestPerformance: _observed, ...accounting } = settledUsage;
231
+ yield accounting;
232
+ }
233
+ if (finishResult.failure?.code === 'PERMISSION_DENIED') {
234
+ const denial = [...state.permissionDenials.values()].at(-1);
235
+ if (denial !== undefined)
236
+ finishResult = { ...finishResult, failure: { message: denial, code: 'PERMISSION_DENIED' } };
237
+ }
238
+ // A normal prompt stop does not confirm pending tool execution. Keep the
239
+ // observed arguments and make the unknown outcome explicit without retrying.
240
+ if (activeTools.size > 0) {
241
+ for (const [callId, toolName] of activeTools) {
242
+ const error = 'Grok ended the turn without reporting a final result for this tool; its outcome is unconfirmed.';
243
+ yield decorateCodingNsSegmentEvent({ type: 'tool-event', callId, toolName, status: 'failed', error, output: error, outputMode: 'snapshot' }, input, segmentState, this.descriptor.id);
169
244
  }
170
- catch { /* 不同 ACP 版本的取消方法可能不同,请求级取消已经先行发出。 */ }
245
+ if (finishResult.reason === 'stop')
246
+ finishResult = {
247
+ reason: 'error',
248
+ failure: { message: 'Grok ended the turn before all tool results were confirmed.', code: 'INCOMPLETE_TOOL_RESULT' },
249
+ };
171
250
  }
251
+ reusable = finishResult.reason === 'stop' && !input.signal?.aborted;
172
252
  yield { type: 'finish', reason: finishResult.reason, ...(finishResult.failure === undefined ? {} : { failure: finishResult.failure }) };
173
253
  }
174
254
  finally {
@@ -182,7 +262,15 @@ export class GrokBuildDriver {
182
262
  state.grokQuestions.clear();
183
263
  state.grokQuestionCallIds.clear();
184
264
  state.grokQuestionEventIds.clear();
185
- // ACP 进程和会话跨轮复用,统一由 dispose() 回收。
265
+ state.questions.clear();
266
+ state.requests.clear();
267
+ state.permissionDenials.clear();
268
+ if (!reusable) {
269
+ // An abandoned prompt can keep producing updates without prompt metadata.
270
+ // Reload its persisted session on a fresh transport before accepting new input.
271
+ await rpc.disposeAndWait();
272
+ this.processes.delete(rpc);
273
+ }
186
274
  }
187
275
  }
188
276
  respondPermission(sessionId, response) {
@@ -194,7 +282,10 @@ export class GrokBuildDriver {
194
282
  throw new Error('The Grok permission request does not exist');
195
283
  state.requests.delete(response.requestId);
196
284
  const optionId = response.approved ? pending.allowOptionId : pending.rejectOptionId;
197
- state.rpc.respond(pending.rpcId, { outcome: { outcome: 'selected', optionId } });
285
+ if (!response.approved || optionId === undefined) {
286
+ state.permissionDenials.set(pending.callId ?? response.requestId, response.reason ?? (response.approved ? 'Grok did not offer a one-time approval option.' : 'Grok tool execution was denied.'));
287
+ }
288
+ state.rpc.respond(pending.rpcId, { outcome: optionId === undefined ? { outcome: 'cancelled' } : { outcome: 'selected', optionId } });
198
289
  }
199
290
  respondQuestion(sessionId, response) {
200
291
  const state = this.sessions.get(sessionId);
@@ -216,25 +307,39 @@ export class GrokBuildDriver {
216
307
  dispose() { for (const process of this.processes)
217
308
  process.dispose(); this.processes.clear(); this.sessions.clear(); this.cachedBinary = null; }
218
309
  async getSession(input, command) {
310
+ const alwaysApprove = input.permission?.sandboxMode === 'danger-full-access' && input.permission.approvalPolicy === 'never';
219
311
  const previous = this.sessions.get(input.sessionId);
220
- if (previous !== undefined && previous.cwd === input.cwd)
312
+ if (previous !== undefined && previous.cwd === input.cwd && previous.alwaysApprove === alwaysApprove && !previous.rpc.isClosed)
221
313
  return previous;
222
- previous?.rpc.dispose();
223
- const rpc = new JsonRpcProcess({ command, args: ['agent', '--no-leader', 'stdio'], cwd: input.cwd, env: grokRuntimeEnvironment(), spawn: this.runSpawn });
314
+ if (previous !== undefined) {
315
+ await previous.rpc.disposeAndWait();
316
+ this.processes.delete(previous.rpc);
317
+ }
318
+ const resumeId = input.providerSessionId ?? (previous?.cwd === input.cwd ? previous?.providerSessionId : undefined);
319
+ const rpc = new JsonRpcProcess({ command, args: ['agent', '--no-leader', ...(alwaysApprove ? ['--always-approve'] : []), 'stdio'], cwd: input.cwd, env: grokRuntimeEnvironment(), spawn: this.runSpawn });
224
320
  this.processes.add(rpc);
225
- const state = { rpc, cwd: input.cwd, rawStoreRef: input.rawStoreRef, providerSessionId: '', requests: new Map(), questions: new Map(), grokQuestions: new Map(), grokQuestionCallIds: new Set(), grokQuestionEventIds: new Set() };
226
- await rpc.request('initialize', {
321
+ const state = { rpc, contextUsage: new GrokContextUsage(), cwd: input.cwd, rawStoreRef: input.rawStoreRef, alwaysApprove, providerSessionId: '', requests: new Map(), permissionDenials: new Map(), questions: new Map(), grokQuestions: new Map(), grokQuestionCallIds: new Set(), grokQuestionEventIds: new Set() };
322
+ rpc.addNotificationListener(message => {
323
+ const params = isRecord(message.params) ? message.params : {};
324
+ const owner = state.providerSessionId || resumeId;
325
+ if (owner && typeof params.sessionId === 'string' && params.sessionId !== owner)
326
+ return;
327
+ state.contextUsage.observe(message);
328
+ });
329
+ const initialized = await rpc.request('initialize', {
227
330
  protocolVersion: 1,
228
331
  clientInfo: { name: 'codingns4dsh', version: '0.1.1' },
229
332
  // 旧版 Grok 读取 capabilities;标准 ACP 读取 clientCapabilities。
230
333
  capabilities: ACP_FORM_CLIENT_CAPABILITIES,
231
334
  clientCapabilities: ACP_FORM_CLIENT_CAPABILITIES,
232
335
  });
336
+ state.contextUsage.observe(initialized);
233
337
  rpc.notify('initialized', {});
234
- if (input.providerSessionId) {
338
+ if (resumeId) {
235
339
  try {
236
- const loaded = await rpc.request('session/load', { sessionId: input.providerSessionId, cwd: input.cwd ?? process.cwd(), mcpServers: acpBridgeMcpServers(input.sessionId, this.descriptor.id) });
237
- state.providerSessionId = readSessionId(loaded) ?? input.providerSessionId;
340
+ const loaded = await rpc.request('session/load', { sessionId: resumeId, cwd: input.cwd ?? process.cwd(), mcpServers: acpBridgeMcpServers(input.sessionId, this.descriptor.id) });
341
+ state.contextUsage.observe(loaded);
342
+ state.providerSessionId = readSessionId(loaded) ?? resumeId;
238
343
  }
239
344
  catch { /* 旧版 ACP 没有 load,下一轮在同一进程创建新会话 */ }
240
345
  }
@@ -263,7 +368,7 @@ export class GrokBuildDriver {
263
368
  const requestId = interactionRequestId(message);
264
369
  if (requestId === null || message.id === undefined || message.id === null)
265
370
  return { outcome: { outcome: 'cancelled' } };
266
- state.requests.set(requestId, { rpcId: message.id, ...permissionOptions(message) });
371
+ state.requests.set(requestId, { rpcId: message.id, callId: permissionCallId(message), ...permissionOptions(message) });
267
372
  return new Promise(() => undefined);
268
373
  });
269
374
  this.sessions.set(input.sessionId, state);
@@ -293,13 +398,14 @@ const GROK_QUESTION_GUIDANCE = [
293
398
  * Grok 可能先返回 prompt 响应,再补发最后一批 session/update。
294
399
  * 响应或终态任一先到都会启动固定排空窗口,窗口内的文本和错误仍会被消费。
295
400
  */
296
- async function* streamGrokPrompt(rpc, sessionId, prompt, signal, onNotification) {
401
+ async function* streamGrokPrompt(rpc, sessionId, promptId, prompt, signal, onNotification, onResponse) {
297
402
  const queue = [];
298
403
  const requestController = new AbortController();
299
404
  let wake;
300
405
  let drainDeadline = null;
301
406
  let terminalReason = null;
302
407
  let failure;
408
+ let completed = false;
303
409
  const notify = () => { wake?.(); wake = undefined; };
304
410
  const beginDrain = () => {
305
411
  if (drainDeadline === null)
@@ -307,8 +413,10 @@ async function* streamGrokPrompt(rpc, sessionId, prompt, signal, onNotification)
307
413
  notify();
308
414
  };
309
415
  const listener = (message) => {
310
- queue.push(message);
311
- onNotification(message);
416
+ if (!isGrokPromptMessage(message, sessionId, promptId))
417
+ return;
418
+ const observation = onNotification(message);
419
+ queue.push(observation === undefined ? message : { ...message, codingnsGrokObservation: observation });
312
420
  const notificationReason = grokNotificationReason(message);
313
421
  if (notificationReason === null) {
314
422
  notify();
@@ -320,8 +428,6 @@ async function* streamGrokPrompt(rpc, sessionId, prompt, signal, onNotification)
320
428
  if (detail !== undefined)
321
429
  failure = detail;
322
430
  }
323
- // 部分 Grok 版本只发终态通知而不回复 prompt,主动取消可清理待处理请求。
324
- requestController.abort();
325
431
  beginDrain();
326
432
  };
327
433
  const removeListener = rpc.addNotificationListener(listener);
@@ -336,19 +442,29 @@ async function* streamGrokPrompt(rpc, sessionId, prompt, signal, onNotification)
336
442
  onAbort();
337
443
  else
338
444
  signal?.addEventListener('abort', onAbort, { once: true });
339
- void rpc.request('session/prompt', {
340
- sessionId,
341
- prompt,
342
- }, { signal: requestController.signal, killOnAbort: false }).then((response) => {
343
- const responseReason = grokPromptReason(response);
344
- if (responseReason !== null)
345
- terminalReason = mergeGrokReason(terminalReason, responseReason);
346
- beginDrain();
347
- }, () => {
348
- if (terminalReason === null)
349
- terminalReason = signal?.aborted ? 'cancel' : 'error';
350
- beginDrain();
351
- });
445
+ if (!signal?.aborted)
446
+ void rpc.request('session/prompt', {
447
+ sessionId,
448
+ prompt,
449
+ _meta: { promptId },
450
+ }, { signal: requestController.signal, killOnAbort: false }).then((response) => {
451
+ if (signal?.aborted)
452
+ return;
453
+ const observation = onResponse(response);
454
+ if (observation !== undefined)
455
+ queue.push({ method: 'codingns/grok-observation', codingnsGrokObservation: observation });
456
+ const responseReason = grokPromptReason(response);
457
+ if (responseReason !== null)
458
+ terminalReason = mergeGrokReason(terminalReason, responseReason);
459
+ failure ??= grokPermissionFailure(response);
460
+ beginDrain();
461
+ }, () => {
462
+ if (requestController.signal.aborted)
463
+ return;
464
+ if (terminalReason === null)
465
+ terminalReason = signal?.aborted ? 'cancel' : 'error';
466
+ beginDrain();
467
+ });
352
468
  try {
353
469
  while (true) {
354
470
  if (queue.length > 0) {
@@ -368,18 +484,81 @@ async function* streamGrokPrompt(rpc, sessionId, prompt, signal, onNotification)
368
484
  ]);
369
485
  wake = undefined;
370
486
  }
487
+ completed = true;
371
488
  return { reason: terminalReason ?? 'stop', ...(failure === undefined ? {} : { failure }) };
372
489
  }
373
490
  finally {
374
491
  signal?.removeEventListener('abort', onAbort);
375
492
  removeListener();
493
+ if (!completed || signal?.aborted) {
494
+ // ACP cancellation is a notification; waiting for an RPC response can hang.
495
+ try {
496
+ rpc.notify('session/cancel', { sessionId });
497
+ }
498
+ catch { /* The process may already have exited. */ }
499
+ }
500
+ // Terminal-only providers and consumers that close the iterator both need cleanup.
501
+ requestController.abort();
376
502
  }
377
503
  }
504
+ function isGrokPromptMessage(message, sessionId, promptId) {
505
+ const params = isRecord(message.params) ? message.params : message;
506
+ if (typeof params.sessionId === 'string' && params.sessionId !== sessionId)
507
+ return false;
508
+ const update = isRecord(params.update) ? params.update : params;
509
+ const meta = isRecord(params._meta) ? params._meta : {};
510
+ if (meta.isReplay === true)
511
+ return false;
512
+ const owner = firstToolText(update.prompt_id, update.promptId, meta.promptId);
513
+ return owner === undefined || owner === promptId;
514
+ }
515
+ function grokToolInputChunks(message, inputs) {
516
+ const params = isRecord(message.params) ? message.params : message;
517
+ const update = isRecord(params.update) ? params.update : params;
518
+ if (update.sessionUpdate !== 'tool_call_delta_chunk' || !Number.isInteger(update.tool_index))
519
+ return null;
520
+ const index = update.tool_index;
521
+ const callId = firstToolText(update.tool_call_id, update.toolCallId);
522
+ // Argument fragments omit the call id; a new id resets a reused model-call index.
523
+ let pending = inputs.get(index);
524
+ const started = callId !== undefined && pending?.callId !== callId;
525
+ if (started) {
526
+ pending = { callId, toolName: firstToolText(update.name, update.title) ?? 'tool', arguments: '' };
527
+ inputs.set(index, pending);
528
+ }
529
+ if (pending === undefined)
530
+ return [];
531
+ if (typeof update.arguments_delta === 'string')
532
+ pending.arguments += update.arguments_delta;
533
+ let input;
534
+ try {
535
+ const parsed = JSON.parse(pending.arguments);
536
+ if (isRecord(parsed))
537
+ input = JSON.stringify(parsed);
538
+ }
539
+ catch { /* Do not persist incomplete JSON as a tool's final arguments. */ }
540
+ if (!started && input === undefined)
541
+ return [];
542
+ return [{
543
+ type: 'tool-event', callId: pending.callId, toolName: pending.toolName, status: 'running',
544
+ ...(input === undefined ? {} : { input }),
545
+ }];
546
+ }
378
547
  function grokPromptReason(value) {
379
- if (!isRecord(value) || typeof value.stopReason !== 'string')
548
+ if (!isRecord(value))
380
549
  return null;
381
- const reason = value.stopReason.toLowerCase();
382
- return reason === 'cancelled' || reason === 'error' || reason === 'failed' ? 'error' : 'stop';
550
+ const reason = firstToolText(value.stopReason, value.stop_reason)?.toLowerCase();
551
+ if (reason === undefined)
552
+ return null;
553
+ if (reason === 'cancelled' || reason === 'canceled')
554
+ return grokPermissionFailure(value) === undefined ? 'cancel' : 'error';
555
+ return reason === 'error' || reason === 'failed' ? 'error' : 'stop';
556
+ }
557
+ function grokPermissionFailure(value) {
558
+ if (!isRecord(value) || !isRecord(value._meta) || value._meta.cancellationCategory !== 'PermissionRejected')
559
+ return undefined;
560
+ const context = isRecord(value._meta.cancellationContext) ? value._meta.cancellationContext : {};
561
+ return { message: firstToolText(context.reason) ?? 'Grok tool execution was denied.', code: 'PERMISSION_DENIED' };
383
562
  }
384
563
  function mergeGrokReason(current, next) {
385
564
  if (current === 'error' || next === 'error')
@@ -396,15 +575,20 @@ function grokNotificationReason(message) {
396
575
  : typeof update.type === 'string'
397
576
  ? update.type.toLowerCase()
398
577
  : '';
399
- if (type.includes('error') || type.includes('failed'))
578
+ if (['turn_error', 'turn_failed', 'error', 'failed'].includes(type))
400
579
  return 'error';
401
- if (type.includes('turn_completed') || type.includes('turn_complete') || type === 'completed' || type === 'done')
402
- return 'stop';
580
+ if (['turn_completed', 'turn_complete', 'prompt_complete', 'completed', 'done'].includes(type)) {
581
+ const reason = grokPromptReason(update) ?? 'stop';
582
+ return reason === 'cancel' && grokPermissionFailure(params) !== undefined ? 'error' : reason;
583
+ }
403
584
  return null;
404
585
  }
405
586
  function grokFailure(message) {
406
587
  const params = isRecord(message.params) ? message.params : message;
407
588
  const update = isRecord(params.update) ? params.update : params;
589
+ const permissionFailure = grokPermissionFailure(update) ?? grokPermissionFailure(params);
590
+ if (permissionFailure !== undefined)
591
+ return permissionFailure;
408
592
  const error = isRecord(update.error) ? update.error : update;
409
593
  const detail = firstToolText(error.message, error.errorMessage, error.error_message, error.detail, error.reason);
410
594
  if (detail === undefined)
@@ -481,6 +665,23 @@ function grokQuestionResponse(pending, response) {
481
665
  ...(Object.keys(annotations).length === 0 ? {} : { annotations }),
482
666
  };
483
667
  }
668
+ function grokStreamId(message) {
669
+ const params = isRecord(message.params) ? message.params : message;
670
+ const meta = isRecord(params._meta) ? params._meta : {};
671
+ return typeof meta.streamStartMs === 'number' && Number.isFinite(meta.streamStartMs)
672
+ ? `grok-stream-${meta.streamStartMs}` : undefined;
673
+ }
674
+ function grokStepPhase(event) {
675
+ switch (event.type) {
676
+ case 'text-delta':
677
+ case 'reasoning-delta': return event.text.length > 0 ? 'message' : undefined;
678
+ case 'image-artifact': return 'message';
679
+ case 'tool-event':
680
+ case 'question-request':
681
+ case 'permission-request': return 'tools';
682
+ default: return undefined;
683
+ }
684
+ }
484
685
  function acpMessageToChunks(message) {
485
686
  const params = isRecord(message.params) ? message.params : message;
486
687
  const update = isRecord(params.update) ? params.update : params;
@@ -506,9 +707,12 @@ function acpMessageToChunks(message) {
506
707
  const markdownPaths = imageArtifactPathsFromValue(text ?? '');
507
708
  const imagePaths = [...new Set([...artifactPaths, ...markdownPaths])];
508
709
  const imageEvents = imagePaths.map((path) => ({ type: 'image-artifact', path }));
710
+ // Grok identifies each model call independently of the enclosing user prompt.
711
+ const messageId = grokStreamId(message);
712
+ const identity = messageId === undefined ? {} : { messageId };
509
713
  const reasoning = reasoningText(update);
510
714
  if (reasoning !== null)
511
- return [...imageEvents, { type: 'reasoning-delta', text: reasoning }];
715
+ return [...imageEvents, { type: 'reasoning-delta', text: reasoning, ...identity }];
512
716
  if (type.includes('permission')) {
513
717
  const requestId = permissionRequestId(message) ?? (typeof update.requestId === 'string' ? update.requestId : typeof update.id === 'string' ? update.id : null);
514
718
  if (requestId !== null) {
@@ -520,13 +724,13 @@ function acpMessageToChunks(message) {
520
724
  }
521
725
  if (type.includes('agent_message') || type.includes('text') || type === 'message') {
522
726
  const visible = text === null ? '' : stripImageMarkdown(text, markdownPaths);
523
- const textEvent = visible === '' ? undefined : { type: 'text-delta', text: visible };
727
+ const textEvent = visible === '' ? undefined : { type: 'text-delta', text: visible, ...identity };
524
728
  return [...imageEvents, ...(textEvent === undefined ? [] : [textEvent])];
525
729
  }
526
730
  if (type.includes('image') || type.includes('artifact') || type.includes('generated'))
527
731
  return imageEvents;
528
732
  if (type.includes('thought') || type.includes('reason'))
529
- return text ? [{ type: 'reasoning-delta', text }] : [];
733
+ return text ? [{ type: 'reasoning-delta', text, ...identity }] : [];
530
734
  if (type.includes('tool') || type.includes('command')) {
531
735
  const tool = isToolRecord(update.toolCall) ? update.toolCall : isToolRecord(update.tool_call) ? update.tool_call : update;
532
736
  const name = firstToolText(tool.name, tool.toolName, tool.tool_name, tool.title, update.name, update.toolName, update.title);
@@ -534,13 +738,19 @@ function acpMessageToChunks(message) {
534
738
  if (!name && !callId)
535
739
  return [];
536
740
  const input = serializeToolValue(tool.rawInput ?? tool.input ?? tool.arguments ?? tool.args ?? update.rawInput);
537
- const output = serializeToolValue(tool.rawOutput ?? tool.output ?? tool.result ?? update.rawOutput);
741
+ // ACP tool results can contain nested text blocks without a rawOutput field.
742
+ const content = tool.content ?? update.content;
743
+ const contentText = Array.isArray(content)
744
+ ? content.flatMap((block) => isRecord(block) ? textValue(block.content ?? block) ?? [] : []).join('\n') || undefined
745
+ : undefined;
746
+ const rawOutput = serializeToolValue(tool.rawOutput ?? tool.output ?? tool.result ?? update.rawOutput);
747
+ const output = rawOutput ?? contentText;
538
748
  const error = serializeToolValue(tool.error ?? update.error);
539
749
  const agentId = firstToolText(tool.agentId, tool.agent_id, update.agentId, update.agent_id);
540
750
  const detail = serializeToolValue(tool.detail ?? update.detail ?? update.content);
541
751
  const fallback = error !== undefined || type.includes('error') || type.includes('fail')
542
752
  ? 'failed'
543
- : output !== undefined || type.includes('result') || type.includes('complete')
753
+ : rawOutput !== undefined || type.includes('result') || type.includes('complete')
544
754
  ? 'completed'
545
755
  : 'running';
546
756
  return [...imageEvents, {
@@ -599,6 +809,12 @@ function permissionRequestId(message) {
599
809
  function interactionRequestId(message) {
600
810
  return permissionRequestId(message);
601
811
  }
812
+ function permissionCallId(message) {
813
+ const params = isRecord(message.params) ? message.params : message;
814
+ const update = isRecord(params.update) ? params.update : params;
815
+ const tool = isRecord(update.toolCall) ? update.toolCall : isRecord(update.tool_call) ? update.tool_call : update;
816
+ return firstToolText(tool.toolCallId, tool.tool_call_id, tool.callId, tool.call_id);
817
+ }
602
818
  function permissionOptions(message) {
603
819
  const params = isRecord(message.params) ? message.params : {};
604
820
  const options = Array.isArray(params.options) ? params.options : [];
@@ -610,9 +826,17 @@ function permissionOptions(message) {
610
826
  return [];
611
827
  return [{ id, kind: firstToolText(option.kind, option.type)?.toLowerCase() ?? '' }];
612
828
  });
829
+ if (ids.length === 0)
830
+ return { allowOptionId: 'allow-once', rejectOptionId: 'reject-once' };
831
+ // Grok lists allow_always before allow_once. A DSH one-time approval must
832
+ // never become a persistent grant merely because of provider option order.
613
833
  return {
614
- allowOptionId: ids.find((option) => /allow|approve|accept/u.test(option.kind))?.id ?? ids[0]?.id ?? 'allow-once',
615
- rejectOptionId: ids.find((option) => /reject|deny|decline|cancel/u.test(option.kind))?.id ?? ids[1]?.id ?? 'reject-once',
834
+ allowOptionId: ids.find((option) => option.kind === 'allow_once')?.id
835
+ ?? ids.find((option) => /^(allow|approve|accept)$/u.test(option.kind))?.id
836
+ ?? (ids[0]?.kind === '' ? ids[0].id : undefined),
837
+ rejectOptionId: ids.find((option) => option.kind === 'reject_once')?.id
838
+ ?? ids.find((option) => /^(reject|deny|decline|cancel)$/u.test(option.kind))?.id
839
+ ?? (ids[1]?.kind === '' ? ids[1].id : undefined),
616
840
  };
617
841
  }
618
842
  function readSessionId(value) {