@jingyi0605/codingns4dsh 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/README.md +1114 -0
  2. package/assets/provider-icons/claude-code.png +0 -0
  3. package/assets/provider-icons/codex.png +0 -0
  4. package/assets/provider-icons/command-code.svg +5 -0
  5. package/assets/provider-icons/deepseek-harness.svg +9 -0
  6. package/assets/provider-icons/gemini.png +0 -0
  7. package/assets/provider-icons/grok.png +0 -0
  8. package/assets/provider-icons/kimi.png +0 -0
  9. package/assets/provider-icons/opencode.png +0 -0
  10. package/assets/provider-icons/pi.svg +7 -0
  11. package/data/build/dist/bootstrap/dsh-connection-adapter.d.ts +97 -0
  12. package/data/build/dist/bootstrap/dsh-connection-adapter.js +169 -0
  13. package/data/build/dist/bootstrap/index.d.ts +38 -0
  14. package/data/build/dist/bootstrap/index.js +44 -0
  15. package/data/build/dist/client/account-bar.d.ts +9 -0
  16. package/data/build/dist/client/account-bar.js +398 -0
  17. package/data/build/dist/client/bundle.js +26167 -0
  18. package/data/build/dist/client/cli-catalog.d.ts +24 -0
  19. package/data/build/dist/client/cli-catalog.js +108 -0
  20. package/data/build/dist/client/cli-slots.d.ts +38 -0
  21. package/data/build/dist/client/cli-slots.js +297 -0
  22. package/data/build/dist/client/debug/ui.d.ts +12 -0
  23. package/data/build/dist/client/debug/ui.js +451 -0
  24. package/data/build/dist/client/dsh-h5-bootstrap.d.ts +64 -0
  25. package/data/build/dist/client/dsh-h5-bootstrap.js +293 -0
  26. package/data/build/dist/client/dsh-runtime-version.d.ts +3 -0
  27. package/data/build/dist/client/dsh-runtime-version.js +11 -0
  28. package/data/build/dist/client/external-tool-stream.d.ts +24 -0
  29. package/data/build/dist/client/external-tool-stream.js +114 -0
  30. package/data/build/dist/client/features/cli-adapters.d.ts +7 -0
  31. package/data/build/dist/client/features/cli-adapters.js +215 -0
  32. package/data/build/dist/client/features/debug.d.ts +4 -0
  33. package/data/build/dist/client/features/debug.js +24 -0
  34. package/data/build/dist/client/features/index.d.ts +33 -0
  35. package/data/build/dist/client/features/index.js +44 -0
  36. package/data/build/dist/client/features/lan-access-panel.d.ts +5 -0
  37. package/data/build/dist/client/features/lan-access-panel.js +146 -0
  38. package/data/build/dist/client/features/lan-access.d.ts +9 -0
  39. package/data/build/dist/client/features/lan-access.js +30 -0
  40. package/data/build/dist/client/features/login-protection-panel.d.ts +5 -0
  41. package/data/build/dist/client/features/login-protection-panel.js +91 -0
  42. package/data/build/dist/client/features/login-protection-session.d.ts +6 -0
  43. package/data/build/dist/client/features/login-protection-session.js +25 -0
  44. package/data/build/dist/client/features/login-protection.d.ts +4 -0
  45. package/data/build/dist/client/features/login-protection.js +23 -0
  46. package/data/build/dist/client/features/reverse-proxy-panel.d.ts +9 -0
  47. package/data/build/dist/client/features/reverse-proxy-panel.js +159 -0
  48. package/data/build/dist/client/features/reverse-proxy.d.ts +12 -0
  49. package/data/build/dist/client/features/reverse-proxy.js +112 -0
  50. package/data/build/dist/client/features/terminal-enhancement-panel.d.ts +5 -0
  51. package/data/build/dist/client/features/terminal-enhancement-panel.js +160 -0
  52. package/data/build/dist/client/features/terminal-enhancement.d.ts +4 -0
  53. package/data/build/dist/client/features/terminal-enhancement.js +24 -0
  54. package/data/build/dist/client/features/types.d.ts +58 -0
  55. package/data/build/dist/client/features/types.js +2 -0
  56. package/data/build/dist/client/features/workspace-session-enhancement-panel.d.ts +5 -0
  57. package/data/build/dist/client/features/workspace-session-enhancement-panel.js +66 -0
  58. package/data/build/dist/client/features/workspace-session-enhancement.d.ts +4 -0
  59. package/data/build/dist/client/features/workspace-session-enhancement.js +101 -0
  60. package/data/build/dist/client/h5-bootstrap-entry.d.ts +2 -0
  61. package/data/build/dist/client/h5-bootstrap-entry.js +17 -0
  62. package/data/build/dist/client/index.d.ts +31 -0
  63. package/data/build/dist/client/index.js +98 -0
  64. package/data/build/dist/client/lan-access.d.ts +28 -0
  65. package/data/build/dist/client/lan-access.js +68 -0
  66. package/data/build/dist/client/locale.d.ts +20 -0
  67. package/data/build/dist/client/locale.js +393 -0
  68. package/data/build/dist/client/provider-icon-assets.d.ts +2 -0
  69. package/data/build/dist/client/provider-icon-assets.js +23 -0
  70. package/data/build/dist/client/provider-icons.d.ts +19 -0
  71. package/data/build/dist/client/provider-icons.js +39 -0
  72. package/data/build/dist/client/remote-web-context.d.ts +57 -0
  73. package/data/build/dist/client/remote-web-context.js +939 -0
  74. package/data/build/dist/client/session-adapter-cache.d.ts +18 -0
  75. package/data/build/dist/client/session-adapter-cache.js +84 -0
  76. package/data/build/dist/client/settings-bridge.d.ts +32 -0
  77. package/data/build/dist/client/settings-bridge.js +126 -0
  78. package/data/build/dist/client/settings-section.d.ts +30 -0
  79. package/data/build/dist/client/settings-section.js +93 -0
  80. package/data/build/dist/client/subscription-slot.d.ts +18 -0
  81. package/data/build/dist/client/subscription-slot.js +223 -0
  82. package/data/build/dist/client/terminal/index.d.ts +4 -0
  83. package/data/build/dist/client/terminal/index.js +3 -0
  84. package/data/build/dist/client/terminal/model.d.ts +116 -0
  85. package/data/build/dist/client/terminal/model.js +435 -0
  86. package/data/build/dist/client/terminal/styles.d.ts +21 -0
  87. package/data/build/dist/client/terminal/styles.js +51 -0
  88. package/data/build/dist/client/terminal/ui.d.ts +19 -0
  89. package/data/build/dist/client/terminal/ui.js +257 -0
  90. package/data/build/dist/client/terminal/xterm-view.d.ts +13 -0
  91. package/data/build/dist/client/terminal/xterm-view.js +213 -0
  92. package/data/build/dist/client/theme.d.ts +56 -0
  93. package/data/build/dist/client/theme.js +186 -0
  94. package/data/build/dist/client/workspace-session-archive-dom.d.ts +29 -0
  95. package/data/build/dist/client/workspace-session-archive-dom.js +525 -0
  96. package/data/build/dist/client/workspace-session-fiber.d.ts +3 -0
  97. package/data/build/dist/client/workspace-session-fiber.js +33 -0
  98. package/data/build/dist/client/workspace-session-logo-dom.d.ts +26 -0
  99. package/data/build/dist/client/workspace-session-logo-dom.js +128 -0
  100. package/data/build/dist/features/index.d.ts +3 -0
  101. package/data/build/dist/features/index.js +2 -0
  102. package/data/build/dist/features/registry.d.ts +74 -0
  103. package/data/build/dist/features/registry.js +382 -0
  104. package/data/build/dist/features/resource-scope/index.d.ts +39 -0
  105. package/data/build/dist/features/resource-scope/index.js +161 -0
  106. package/data/build/dist/host/auth-session.d.ts +42 -0
  107. package/data/build/dist/host/auth-session.js +186 -0
  108. package/data/build/dist/host/cli-adapters/claude-driver.d.ts +14 -0
  109. package/data/build/dist/host/cli-adapters/claude-driver.js +103 -0
  110. package/data/build/dist/host/cli-adapters/codex-driver.d.ts +45 -0
  111. package/data/build/dist/host/cli-adapters/codex-driver.js +534 -0
  112. package/data/build/dist/host/cli-adapters/command-code-driver.d.ts +38 -0
  113. package/data/build/dist/host/cli-adapters/command-code-driver.js +394 -0
  114. package/data/build/dist/host/cli-adapters/command-code-subscription.d.ts +19 -0
  115. package/data/build/dist/host/cli-adapters/command-code-subscription.js +126 -0
  116. package/data/build/dist/host/cli-adapters/driver.d.ts +41 -0
  117. package/data/build/dist/host/cli-adapters/driver.js +2 -0
  118. package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts +37 -0
  119. package/data/build/dist/host/cli-adapters/dsh-message-projector.js +180 -0
  120. package/data/build/dist/host/cli-adapters/dsh-tool-history.d.ts +48 -0
  121. package/data/build/dist/host/cli-adapters/dsh-tool-history.js +373 -0
  122. package/data/build/dist/host/cli-adapters/feature.d.ts +7 -0
  123. package/data/build/dist/host/cli-adapters/feature.js +335 -0
  124. package/data/build/dist/host/cli-adapters/gemini-driver.d.ts +24 -0
  125. package/data/build/dist/host/cli-adapters/gemini-driver.js +427 -0
  126. package/data/build/dist/host/cli-adapters/grok-driver.d.ts +38 -0
  127. package/data/build/dist/host/cli-adapters/grok-driver.js +372 -0
  128. package/data/build/dist/host/cli-adapters/http-sse-client.d.ts +22 -0
  129. package/data/build/dist/host/cli-adapters/http-sse-client.js +99 -0
  130. package/data/build/dist/host/cli-adapters/interaction-events.d.ts +11 -0
  131. package/data/build/dist/host/cli-adapters/interaction-events.js +80 -0
  132. package/data/build/dist/host/cli-adapters/json-rpc-process.d.ts +65 -0
  133. package/data/build/dist/host/cli-adapters/json-rpc-process.js +256 -0
  134. package/data/build/dist/host/cli-adapters/kimi-driver.d.ts +21 -0
  135. package/data/build/dist/host/cli-adapters/kimi-driver.js +382 -0
  136. package/data/build/dist/host/cli-adapters/model-catalog.d.ts +22 -0
  137. package/data/build/dist/host/cli-adapters/model-catalog.js +89 -0
  138. package/data/build/dist/host/cli-adapters/opencode-driver.d.ts +55 -0
  139. package/data/build/dist/host/cli-adapters/opencode-driver.js +728 -0
  140. package/data/build/dist/host/cli-adapters/pi-driver.d.ts +43 -0
  141. package/data/build/dist/host/cli-adapters/pi-driver.js +312 -0
  142. package/data/build/dist/host/cli-adapters/process-utils.d.ts +16 -0
  143. package/data/build/dist/host/cli-adapters/process-utils.js +27 -0
  144. package/data/build/dist/host/cli-adapters/provider-subscription.d.ts +82 -0
  145. package/data/build/dist/host/cli-adapters/provider-subscription.js +610 -0
  146. package/data/build/dist/host/cli-adapters/registry.d.ts +95 -0
  147. package/data/build/dist/host/cli-adapters/registry.js +659 -0
  148. package/data/build/dist/host/cli-adapters/rpc-driver-utils.d.ts +24 -0
  149. package/data/build/dist/host/cli-adapters/rpc-driver-utils.js +119 -0
  150. package/data/build/dist/host/cli-adapters/session-probe.d.ts +20 -0
  151. package/data/build/dist/host/cli-adapters/session-probe.js +139 -0
  152. package/data/build/dist/host/cli-adapters/session-store.d.ts +68 -0
  153. package/data/build/dist/host/cli-adapters/session-store.js +180 -0
  154. package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts +45 -0
  155. package/data/build/dist/host/cli-adapters/standard-stream-driver.js +205 -0
  156. package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts +25 -0
  157. package/data/build/dist/host/cli-adapters/stream-normalizer.js +83 -0
  158. package/data/build/dist/host/cli-adapters/tool-observation.d.ts +9 -0
  159. package/data/build/dist/host/cli-adapters/tool-observation.js +39 -0
  160. package/data/build/dist/host/control-api-client.d.ts +84 -0
  161. package/data/build/dist/host/control-api-client.js +130 -0
  162. package/data/build/dist/host/credential-store.d.ts +54 -0
  163. package/data/build/dist/host/credential-store.js +114 -0
  164. package/data/build/dist/host/debug.d.ts +79 -0
  165. package/data/build/dist/host/debug.js +295 -0
  166. package/data/build/dist/host/dsh-device-runtime.d.ts +39 -0
  167. package/data/build/dist/host/dsh-device-runtime.js +118 -0
  168. package/data/build/dist/host/dsh-gateway-feature.d.ts +5 -0
  169. package/data/build/dist/host/dsh-gateway-feature.js +55 -0
  170. package/data/build/dist/host/dsh-runtime-version.d.ts +12 -0
  171. package/data/build/dist/host/dsh-runtime-version.js +69 -0
  172. package/data/build/dist/host/features/auth.d.ts +11 -0
  173. package/data/build/dist/host/features/auth.js +273 -0
  174. package/data/build/dist/host/features/debug.d.ts +5 -0
  175. package/data/build/dist/host/features/debug.js +90 -0
  176. package/data/build/dist/host/features/host-status.d.ts +12 -0
  177. package/data/build/dist/host/features/host-status.js +54 -0
  178. package/data/build/dist/host/features/index.d.ts +19 -0
  179. package/data/build/dist/host/features/index.js +29 -0
  180. package/data/build/dist/host/features/lan-access-dsh.d.ts +8 -0
  181. package/data/build/dist/host/features/lan-access-dsh.js +45 -0
  182. package/data/build/dist/host/features/terminal-process.d.ts +5 -0
  183. package/data/build/dist/host/features/terminal-process.js +110 -0
  184. package/data/build/dist/host/features/terminal-status.d.ts +18 -0
  185. package/data/build/dist/host/features/terminal-status.js +56 -0
  186. package/data/build/dist/host/features/types.d.ts +41 -0
  187. package/data/build/dist/host/features/types.js +2 -0
  188. package/data/build/dist/host/index.d.ts +43 -0
  189. package/data/build/dist/host/index.js +135 -0
  190. package/data/build/dist/host/lan-access-dsh.d.ts +83 -0
  191. package/data/build/dist/host/lan-access-dsh.js +831 -0
  192. package/data/build/dist/host/native-session-bridge.d.ts +130 -0
  193. package/data/build/dist/host/native-session-bridge.js +317 -0
  194. package/data/build/dist/host/relay-tunnel-runtime.d.ts +97 -0
  195. package/data/build/dist/host/relay-tunnel-runtime.js +361 -0
  196. package/data/build/dist/host/remote-web-runtime.d.ts +78 -0
  197. package/data/build/dist/host/remote-web-runtime.js +559 -0
  198. package/data/build/dist/host/rpc-table.d.ts +32 -0
  199. package/data/build/dist/host/rpc-table.js +47 -0
  200. package/data/build/dist/host/rpc.d.ts +18 -0
  201. package/data/build/dist/host/rpc.js +248 -0
  202. package/data/build/dist/host/settings.d.ts +19 -0
  203. package/data/build/dist/host/settings.js +80 -0
  204. package/data/build/dist/host/terminal/attachment-registry.d.ts +17 -0
  205. package/data/build/dist/host/terminal/attachment-registry.js +49 -0
  206. package/data/build/dist/host/terminal/backends/conpty-backend.d.ts +39 -0
  207. package/data/build/dist/host/terminal/backends/conpty-backend.js +160 -0
  208. package/data/build/dist/host/terminal/backends/local-pty-backend.d.ts +36 -0
  209. package/data/build/dist/host/terminal/backends/local-pty-backend.js +178 -0
  210. package/data/build/dist/host/terminal/backends/tmux-backend.d.ts +40 -0
  211. package/data/build/dist/host/terminal/backends/tmux-backend.js +191 -0
  212. package/data/build/dist/host/terminal/broker/conpty-broker-client.d.ts +27 -0
  213. package/data/build/dist/host/terminal/broker/conpty-broker-client.js +154 -0
  214. package/data/build/dist/host/terminal/broker/conpty-broker-process.d.ts +10 -0
  215. package/data/build/dist/host/terminal/broker/conpty-broker-process.js +147 -0
  216. package/data/build/dist/host/terminal/broker/conpty-broker-protocol.d.ts +92 -0
  217. package/data/build/dist/host/terminal/broker/conpty-broker-protocol.js +134 -0
  218. package/data/build/dist/host/terminal/controller-factory.d.ts +37 -0
  219. package/data/build/dist/host/terminal/controller-factory.js +82 -0
  220. package/data/build/dist/host/terminal/index.d.ts +17 -0
  221. package/data/build/dist/host/terminal/index.js +17 -0
  222. package/data/build/dist/host/terminal/runtime-adapter.d.ts +77 -0
  223. package/data/build/dist/host/terminal/runtime-adapter.js +18 -0
  224. package/data/build/dist/host/terminal/runtime-manager.d.ts +41 -0
  225. package/data/build/dist/host/terminal/runtime-manager.js +179 -0
  226. package/data/build/dist/host/terminal/shell-detection.d.ts +23 -0
  227. package/data/build/dist/host/terminal/shell-detection.js +105 -0
  228. package/data/build/dist/host/terminal/startup.d.ts +33 -0
  229. package/data/build/dist/host/terminal/startup.js +100 -0
  230. package/data/build/dist/host/terminal/terminal-controller.d.ts +78 -0
  231. package/data/build/dist/host/terminal/terminal-controller.js +324 -0
  232. package/data/build/dist/host/terminal/terminal-process-service.d.ts +30 -0
  233. package/data/build/dist/host/terminal/terminal-process-service.js +194 -0
  234. package/data/build/dist/host/terminal/terminal-process-store.d.ts +45 -0
  235. package/data/build/dist/host/terminal/terminal-process-store.js +183 -0
  236. package/data/build/dist/host/terminal/terminal-service.d.ts +87 -0
  237. package/data/build/dist/host/terminal/terminal-service.js +528 -0
  238. package/data/build/dist/host/terminal/terminal-store.d.ts +49 -0
  239. package/data/build/dist/host/terminal/terminal-store.js +242 -0
  240. package/data/build/dist/index.d.ts +37 -0
  241. package/data/build/dist/index.js +26 -0
  242. package/data/build/dist/shared/contracts/auth.d.ts +122 -0
  243. package/data/build/dist/shared/contracts/auth.js +8 -0
  244. package/data/build/dist/shared/contracts/cli-adapter.d.ts +192 -0
  245. package/data/build/dist/shared/contracts/cli-adapter.js +2 -0
  246. package/data/build/dist/shared/contracts/command-code.d.ts +5 -0
  247. package/data/build/dist/shared/contracts/command-code.js +2 -0
  248. package/data/build/dist/shared/contracts/config.d.ts +113 -0
  249. package/data/build/dist/shared/contracts/config.js +86 -0
  250. package/data/build/dist/shared/contracts/debug-config.d.ts +28 -0
  251. package/data/build/dist/shared/contracts/debug-config.js +78 -0
  252. package/data/build/dist/shared/contracts/debug.d.ts +75 -0
  253. package/data/build/dist/shared/contracts/debug.js +121 -0
  254. package/data/build/dist/shared/contracts/dsh-device.d.ts +72 -0
  255. package/data/build/dist/shared/contracts/dsh-device.js +2 -0
  256. package/data/build/dist/shared/contracts/errors.d.ts +33 -0
  257. package/data/build/dist/shared/contracts/errors.js +41 -0
  258. package/data/build/dist/shared/contracts/feature.d.ts +71 -0
  259. package/data/build/dist/shared/contracts/feature.js +2 -0
  260. package/data/build/dist/shared/contracts/host-status.d.ts +14 -0
  261. package/data/build/dist/shared/contracts/host-status.js +2 -0
  262. package/data/build/dist/shared/contracts/lan-access-dsh.d.ts +30 -0
  263. package/data/build/dist/shared/contracts/lan-access-dsh.js +2 -0
  264. package/data/build/dist/shared/contracts/peer-host.d.ts +37 -0
  265. package/data/build/dist/shared/contracts/peer-host.js +9 -0
  266. package/data/build/dist/shared/contracts/signaling.d.ts +67 -0
  267. package/data/build/dist/shared/contracts/signaling.js +2 -0
  268. package/data/build/dist/shared/contracts/subscription.d.ts +69 -0
  269. package/data/build/dist/shared/contracts/subscription.js +2 -0
  270. package/data/build/dist/shared/contracts/terminal-process.d.ts +65 -0
  271. package/data/build/dist/shared/contracts/terminal-process.js +2 -0
  272. package/data/build/dist/shared/contracts/terminal.d.ts +127 -0
  273. package/data/build/dist/shared/contracts/terminal.js +2 -0
  274. package/data/build/dist/shared/contracts/transport.d.ts +45 -0
  275. package/data/build/dist/shared/contracts/transport.js +3 -0
  276. package/data/build/dist/shared/contracts/version.d.ts +19 -0
  277. package/data/build/dist/shared/contracts/version.js +74 -0
  278. package/data/build/dist/shared/index.d.ts +22 -0
  279. package/data/build/dist/shared/index.js +9 -0
  280. package/data/build/dist/transport/carrier.d.ts +38 -0
  281. package/data/build/dist/transport/carrier.js +268 -0
  282. package/data/build/dist/transport/debug.d.ts +22 -0
  283. package/data/build/dist/transport/debug.js +57 -0
  284. package/data/build/dist/transport/dsh-envelope.d.ts +41 -0
  285. package/data/build/dist/transport/dsh-envelope.js +107 -0
  286. package/data/build/dist/transport/dsh-gateway.d.ts +64 -0
  287. package/data/build/dist/transport/dsh-gateway.js +254 -0
  288. package/data/build/dist/transport/dsh-session.d.ts +55 -0
  289. package/data/build/dist/transport/dsh-session.js +256 -0
  290. package/data/build/dist/transport/dsh-transport.d.ts +57 -0
  291. package/data/build/dist/transport/dsh-transport.js +125 -0
  292. package/data/build/dist/transport/frame.d.ts +132 -0
  293. package/data/build/dist/transport/frame.js +168 -0
  294. package/data/build/dist/transport/index.d.ts +11 -0
  295. package/data/build/dist/transport/index.js +11 -0
  296. package/data/build/dist/transport/multiplexer.d.ts +63 -0
  297. package/data/build/dist/transport/multiplexer.js +323 -0
  298. package/data/build/dist/transport/webrtc-client.d.ts +65 -0
  299. package/data/build/dist/transport/webrtc-client.js +255 -0
  300. package/data/build/dist/transport/webrtc-host.d.ts +58 -0
  301. package/data/build/dist/transport/webrtc-host.js +252 -0
  302. package/data/build/dist/typert.host.d.ts +25 -0
  303. package/data/build/dist/typert.host.js +150 -0
  304. package/dsh.bundle.patch +12 -0
  305. package/package.json +135 -0
  306. package/profile/README.md +27 -0
  307. package/profile/cordis.patch.yml +2 -0
  308. package/profile/package.json +20 -0
  309. package/profile/scripts/check-dsh-install.mjs +71 -0
  310. package/profile/version.json +5 -0
  311. package/scripts/check-dsh-install.mjs +88 -0
  312. package/version.json +6 -0
@@ -0,0 +1,394 @@
1
+ import { spawn, spawnSync } from 'node:child_process';
2
+ import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { homedir, tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import readline from 'node:readline';
6
+ import { firstToolText, serializeToolValue } from './tool-observation.js';
7
+ import { usageChunk } from './rpc-driver-utils.js';
8
+ import { terminateChildProcess } from './process-utils.js';
9
+ const WINDOWS = process.platform === 'win32';
10
+ const COMMAND_CODE_BINARIES = WINDOWS
11
+ ? ['command-code', 'commandcode', 'cmdc']
12
+ : ['command-code', 'commandcode', 'cmdc', 'cmd'];
13
+ const VALID_EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
14
+ const CATALOG_EFFORTS = new Map([
15
+ ['deepseek/deepseek-v4-flash-vision-exp', ['high', 'max']],
16
+ ['deepseek/deepseek-v4-pro', ['high', 'max']],
17
+ ['deepseek/deepseek-v4-flash', ['high', 'max']],
18
+ ['deepseek/deepseek-v4.1-flash', ['low', 'high', 'max']],
19
+ ['deepseek/deepseek-v4-flash-fast', ['low', 'high', 'max']],
20
+ ['moonshotai/kimi-k3', ['low', 'high', 'max']],
21
+ ['moonshotai/kimi-k2.7-code', []],
22
+ ['moonshotai/kimi-k2.7-code-highspeed', []],
23
+ ['moonshotai/kimi-k2.6', []],
24
+ ['moonshotai/kimi-k2.5', []],
25
+ ['z-ai/glm-5.3-flash', ['low', 'high', 'max']],
26
+ ['z-ai/glm-5.3-flashx', ['low', 'high', 'max']],
27
+ ['zai-org/glm-5.3', ['low', 'high', 'max']],
28
+ ['zai-org/glm-5.2', ['high', 'max']],
29
+ ['zai-org/glm-5.2-fast', []],
30
+ ['zai-org/glm-5.1', []],
31
+ ['zai-org/glm-5', []],
32
+ ['minimaxai/minimax-m3', ['low', 'medium', 'high']],
33
+ ['minimaxai/minimax-m2.7', []],
34
+ ['minimaxai/minimax-m2.5', []],
35
+ ['xiaomi/mimo-v2.6-pro', []],
36
+ ['xiaomi/mimo-v2.6-pro-ultraspeed', []],
37
+ ['xiaomi/mimo-v2.6-flash', []],
38
+ ['xiaomi/mimo-v2.5-pro', []],
39
+ ['xiaomi/mimo-v2.5', []],
40
+ ['qwen/qwen3.8-omni-flash', ['low', 'medium', 'xhigh']],
41
+ ['qwen/qwen3.8-max-0902', ['low', 'medium', 'xhigh']],
42
+ ['qwen/qwen3.8-max', ['low', 'medium', 'xhigh']],
43
+ ['qwen/qwen3.8-27b', ['low', 'medium', 'xhigh']],
44
+ ['qwen/qwen3.8-flash', ['low', 'medium', 'xhigh']],
45
+ ['qwen/qwen3.7-max', []],
46
+ ['qwen/qwen3.7-plus', []],
47
+ ['qwen/qwen3.7-flash', []],
48
+ ['qwen/qwen3.6-max-preview', []],
49
+ ['qwen/qwen3.6-plus', []],
50
+ ['meituan/longcat-2.0', []],
51
+ ['stepfun/step-5-preview', []],
52
+ ['stepfun/step-3.7-flash', []],
53
+ ['stepfun/step-3.5-flash', []],
54
+ ['tencent/hy3-paid', []],
55
+ ['tencent/hy4-preview', ['low', 'medium', 'high']],
56
+ ['nvidia/nemotron-3-ultra-550b-a55b', []],
57
+ ['thinkingmachines/inkling', []],
58
+ ['thinkingmachines/inkling-small', []],
59
+ ['poolside/laguna-s-2.1-free', []],
60
+ ['inclusionai/ling-3.0-flash-sante:free', []],
61
+ ['sakana/fugu-ultra', ['high', 'xhigh']],
62
+ ['claude-sonnet-5', ['low', 'medium', 'high', 'xhigh', 'max']],
63
+ ['claude-sonnet-4-6', ['low', 'medium', 'high', 'xhigh', 'max']],
64
+ ['claude-fable-5-1', ['low', 'medium', 'high', 'xhigh', 'max']],
65
+ ['claude-fable-5', ['low', 'medium', 'high', 'xhigh', 'max']],
66
+ ['claude-opus-5', ['low', 'medium', 'high', 'xhigh', 'max']],
67
+ ['claude-opus-4-8', ['low', 'medium', 'high', 'xhigh', 'max']],
68
+ ['claude-opus-4-7', ['low', 'medium', 'high', 'xhigh', 'max']],
69
+ ['claude-haiku-4-5', []],
70
+ ['gpt-6-astra', ['low', 'medium', 'high', 'xhigh', 'max']],
71
+ ['gpt-5.6-sol', ['low', 'medium', 'high', 'xhigh', 'max']],
72
+ ['gpt-5.6-terra', ['low', 'medium', 'high', 'xhigh', 'max']],
73
+ ['gpt-5.6-luna', ['low', 'medium', 'high', 'xhigh', 'max']],
74
+ ['gpt-5.5', ['low', 'medium', 'high', 'xhigh']],
75
+ ['gpt-5.4', ['low', 'medium', 'high', 'xhigh']],
76
+ ['gpt-5.3-codex', ['low', 'medium', 'high', 'xhigh']],
77
+ ['gpt-5.4-mini', ['low', 'medium', 'high']],
78
+ ['google/gemini-3.8-flash', ['low', 'medium', 'high']],
79
+ ['google/gemini-3.7-flash', ['low', 'medium', 'high']],
80
+ ['google/gemini-3.6-flash', ['low', 'medium', 'high']],
81
+ ['google/gemini-3.5-flash', ['low', 'medium', 'high']],
82
+ ['google/gemini-3.5-flash-lite', ['low', 'medium', 'high']],
83
+ ['google/gemini-3.1-flash-lite', ['low', 'medium', 'high']],
84
+ ['meta/muse-spark-1.1', ['low', 'medium', 'high', 'xhigh']],
85
+ ['meta/muse-spark-1.2', ['low', 'medium', 'high', 'xhigh']],
86
+ ['meta/muse-spark-1.2-contributor', ['low', 'medium', 'high', 'xhigh']],
87
+ ['meta/muse-spark-1.3', ['low', 'medium', 'high', 'xhigh', 'max']],
88
+ ['meta/muse-spark-1.3-contributor', ['low', 'medium', 'high', 'xhigh']],
89
+ ['xai/grok-4.6', ['low', 'medium', 'high', 'xhigh']],
90
+ ['xai/grok-4.5', ['low', 'medium', 'high']],
91
+ ['xai/grok-4.7', ['low', 'medium', 'high', 'xhigh']],
92
+ ]);
93
+ /**
94
+ * Command Code 驱动:沿用附件中的 `--session + -p + --output-format json` 方式。
95
+ * 它只负责 CLI 进程和事件转换,不把 Command Code 私有事件泄漏给上层。
96
+ */
97
+ export class CommandCodeDriver {
98
+ descriptor = {
99
+ id: 'command-code',
100
+ name: 'Command Code',
101
+ protocol: 'command',
102
+ capabilities: ['models', 'stream', 'resume', 'interrupt', 'tool-events', 'reasoning', 'usage'],
103
+ };
104
+ homeDirectory;
105
+ binaries;
106
+ runSpawnSync;
107
+ runSpawn;
108
+ cachedBinary = null;
109
+ processes = new Set();
110
+ constructor(options = {}) {
111
+ this.homeDirectory = options.homeDirectory ?? join(homedir(), '.commandcode');
112
+ this.binaries = options.binaries ?? COMMAND_CODE_BINARIES;
113
+ this.runSpawnSync = options.spawnSync ?? spawnSync;
114
+ this.runSpawn = options.spawn ?? spawn;
115
+ }
116
+ async detect() {
117
+ for (const command of this.binaries) {
118
+ try {
119
+ const result = this.runSpawnSync(command, ['--version'], { encoding: 'utf8', timeout: 3_000, windowsHide: true, shell: WINDOWS });
120
+ const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim();
121
+ const version = output.match(/\d+\.\d+\.\d+/u)?.[0] ?? null;
122
+ if (result.status === 0 && version !== null) {
123
+ this.cachedBinary = command;
124
+ return { installed: true, version, command };
125
+ }
126
+ }
127
+ catch {
128
+ // PATH 中不存在候选命令属于正常的未安装状态。
129
+ }
130
+ }
131
+ return { installed: false, version: null, command: null };
132
+ }
133
+ async listModels() {
134
+ const detection = await this.detect();
135
+ if (!detection.installed || detection.command === null)
136
+ return emptyCatalog();
137
+ let stdout = '';
138
+ try {
139
+ const result = this.runSpawnSync(detection.command, ['--list-models'], { encoding: 'utf8', timeout: 12_000, windowsHide: true, shell: WINDOWS });
140
+ stdout = result.stdout ?? '';
141
+ }
142
+ catch {
143
+ return emptyCatalog();
144
+ }
145
+ const groups = [];
146
+ let currentGroup;
147
+ for (const rawLine of stdout.split(/\r?\n/u)) {
148
+ const line = rawLine.trim();
149
+ if (!line || line.startsWith('Available models') || line.startsWith('Pass the full id') || line.startsWith('cmd --') || line.startsWith('Docs:'))
150
+ continue;
151
+ if (!/\s{2,}/u.test(line) && !line.includes(' · ')) {
152
+ currentGroup = { id: line.toLowerCase().replace(/[^a-z0-9]+/gu, '-'), name: line, models: [] };
153
+ groups.push(currentGroup);
154
+ continue;
155
+ }
156
+ const match = line.match(/^(\S+)\s{2,}(.*)$/u);
157
+ if (!match || currentGroup === undefined)
158
+ continue;
159
+ const id = match[1];
160
+ const description = match[2].trim();
161
+ currentGroup.models.push({ id, name: id, ...(description ? { description } : {}), efforts: CATALOG_EFFORTS.get(id.toLowerCase()) ?? [] });
162
+ }
163
+ const config = readJson(join(this.homeDirectory, 'config.json'));
164
+ const currentModel = typeof config?.model === 'string' ? config.model : null;
165
+ const configuredEffort = currentModel !== null && isRecord(config?.reasoningEffort) ? config.reasoningEffort[currentModel] : undefined;
166
+ const currentEffort = typeof configuredEffort === 'string' && VALID_EFFORTS.has(configuredEffort) ? configuredEffort : null;
167
+ const result = { groups, currentModel, currentEffort };
168
+ return result;
169
+ }
170
+ async probeSession(_input) {
171
+ return {
172
+ state: 'ephemeral',
173
+ reason: 'Command Code 当前使用单轮临时 transcript,不存在可恢复的 Provider 原始会话',
174
+ };
175
+ }
176
+ async *executeTurn(input) {
177
+ const binary = this.cachedBinary ?? (await this.detect()).command;
178
+ if (binary === null)
179
+ throw new Error('Command Code 未安装');
180
+ const transcriptPath = join(tmpdir(), `codingns4dsh-cc-${safeId(input.sessionId)}.jsonl`);
181
+ writeTranscript(transcriptPath, input);
182
+ const args = ['--session', transcriptPath, '-p', input.prompt, '--output-format', 'json', '--tools-all', '--yolo'];
183
+ if (input.modelId)
184
+ args.push('-m', input.modelId);
185
+ if (input.effortId && input.effortId !== 'default' && input.effortId !== 'Default')
186
+ args.push('--effort', input.effortId);
187
+ const child = this.runSpawn(binary, args, { cwd: input.cwd ?? process.cwd(), env: { ...process.env }, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true, shell: WINDOWS });
188
+ this.processes.add(child);
189
+ let finished = false;
190
+ const onAbort = () => { terminateChildProcess(child); };
191
+ input.signal?.addEventListener('abort', onAbort, { once: true });
192
+ // 必须消费 stderr,错误内容不能回传给 DSH,避免泄露命令参数或文件片段。
193
+ child.stderr.on('data', () => undefined);
194
+ try {
195
+ const lines = readline.createInterface({ input: child.stdout });
196
+ try {
197
+ for await (const line of lines) {
198
+ if (!line.trim())
199
+ continue;
200
+ const item = parseJson(line);
201
+ if (item === null)
202
+ continue;
203
+ const event = item.type === 'event' && isRecord(item.event) ? item.event : item;
204
+ const eventType = textValue(event.type).toLowerCase();
205
+ const chunks = commandCodeEventChunks(event, input.signal?.aborted ?? false);
206
+ for (const chunk of chunks) {
207
+ if (chunk.type === 'finish')
208
+ finished = true;
209
+ yield chunk;
210
+ }
211
+ if (eventType === 'result' && !finished)
212
+ finished = true;
213
+ }
214
+ }
215
+ finally {
216
+ lines.close();
217
+ }
218
+ if (!finished) {
219
+ if (input.signal?.aborted)
220
+ yield { type: 'finish', reason: 'cancel' };
221
+ else
222
+ throw new Error('Command Code 执行失败');
223
+ }
224
+ }
225
+ finally {
226
+ input.signal?.removeEventListener('abort', onAbort);
227
+ this.processes.delete(child);
228
+ terminateChildProcess(child);
229
+ try {
230
+ rmSync(transcriptPath, { force: true });
231
+ }
232
+ catch { /* 临时文件清理尽力而为 */ }
233
+ }
234
+ }
235
+ dispose() {
236
+ for (const child of this.processes)
237
+ terminateChildProcess(child);
238
+ this.processes.clear();
239
+ this.cachedBinary = null;
240
+ }
241
+ }
242
+ function commandCodeEventChunks(event, cancelled) {
243
+ const chunks = [];
244
+ const type = textValue(event.type).trim().toLowerCase();
245
+ const sessionId = textValue(event.sessionId ?? event.session_id ?? recordValue(event.session)?.id ?? recordValue(event.result)?.sessionId).trim();
246
+ if (sessionId)
247
+ chunks.push({ type: 'session-binding', providerSessionId: sessionId });
248
+ if (type === 'thinking_delta' || type === 'thinking-delta') {
249
+ const text = textValue(event.delta ?? event.thinking ?? event.content);
250
+ if (text)
251
+ chunks.push({ type: 'reasoning-delta', text });
252
+ }
253
+ else if (type === 'text_delta' || type === 'text-delta') {
254
+ const text = textValue(event.delta ?? event.text ?? event.content);
255
+ if (text)
256
+ chunks.push({ type: 'text-delta', text });
257
+ }
258
+ else if (type === 'message' || type === 'message_update' || type === 'message-update') {
259
+ appendMessageSnapshots(chunks, event);
260
+ }
261
+ if (isToolStart(type)) {
262
+ const tool = readToolChunk(event, type === 'tool_queued' || type === 'tool_started' ? 'started' : 'running');
263
+ if (tool !== null)
264
+ chunks.push(tool);
265
+ }
266
+ else if (isToolResult(type)) {
267
+ const tool = readToolChunk(event, type.includes('error') || type.includes('fail') || type.includes('denied') ? 'failed' : 'completed');
268
+ if (tool !== null)
269
+ chunks.push(tool);
270
+ }
271
+ const resultRecord = recordValue(event.result);
272
+ const usage = recordValue(event.usage) ?? recordValue(resultRecord?.usage);
273
+ const usageEvent = usageChunk(usage);
274
+ if (usageEvent !== null)
275
+ chunks.push(usageEvent);
276
+ if (type === 'result') {
277
+ const finalText = textValue(event.finalText ?? resultRecord?.finalText ?? (typeof event.result === 'string' ? event.result : undefined) ?? event.output ?? event.text);
278
+ if (finalText)
279
+ chunks.push({ type: 'text-snapshot', text: finalText });
280
+ chunks.push({ type: 'finish', reason: cancelled ? 'cancel' : 'stop' });
281
+ }
282
+ return chunks;
283
+ }
284
+ function appendMessageSnapshots(chunks, event) {
285
+ const payload = recordValue(event.message ?? event.data) ?? event;
286
+ if (Array.isArray(payload.content)) {
287
+ const snapshots = new Map();
288
+ for (const block of payload.content) {
289
+ const value = recordValue(block);
290
+ if (value === null)
291
+ continue;
292
+ const blockType = textValue(value.type).toLowerCase();
293
+ const channel = blockType.includes('thinking') || blockType.includes('reasoning') ? 'reasoning' : 'text';
294
+ const text = channel === 'reasoning'
295
+ ? textValue(value.thinking ?? value.reasoning ?? value.text ?? value.content)
296
+ : textValue(value.text ?? value.content);
297
+ if (!text)
298
+ continue;
299
+ const values = snapshots.get(channel) ?? [];
300
+ values.push(text);
301
+ snapshots.set(channel, values);
302
+ }
303
+ for (const [channel, values] of snapshots)
304
+ chunks.push({ type: `${channel}-snapshot`, text: values.join('') });
305
+ return;
306
+ }
307
+ const reasoning = textValue(payload.thinking ?? payload.reasoning);
308
+ if (reasoning)
309
+ chunks.push({ type: 'reasoning-snapshot', text: reasoning });
310
+ const text = textValue(payload.text ?? payload.content ?? event.text ?? event.content);
311
+ if (text)
312
+ chunks.push({ type: 'text-snapshot', text });
313
+ }
314
+ function readToolChunk(event, status) {
315
+ const callId = textValue(event.callId ?? event.call_id ?? event.toolUseId ?? event.tool_use_id ?? event.id);
316
+ const fn = recordValue(event.function);
317
+ const toolName = textValue(event.name ?? event.toolName ?? event.tool ?? fn?.name) || 'tool';
318
+ const error = textValue(event.error ?? event.reason);
319
+ const output = textValue(event.output ?? event.result ?? event.content);
320
+ const input = event.input ?? fn?.arguments ?? event.arguments;
321
+ const agentId = firstToolText(event.agentId, event.agent_id);
322
+ const detail = serializeToolValue(event.detail ?? event.metadata);
323
+ if (!callId && !toolName)
324
+ return null;
325
+ return {
326
+ type: 'tool-event',
327
+ toolName,
328
+ ...(callId ? { callId } : {}),
329
+ ...(input !== undefined ? { input: structuredText(input) } : {}),
330
+ ...(output ? { output } : {}),
331
+ ...(output ? { outputMode: 'snapshot' } : {}),
332
+ ...(error ? { error } : {}),
333
+ ...(agentId ? { agentId } : {}),
334
+ ...(detail !== undefined ? { detail } : {}),
335
+ status,
336
+ };
337
+ }
338
+ function isToolStart(type) {
339
+ return ['tool_queued', 'tool_started', 'tool_running', 'tool_use', 'tool_call', 'function_call'].includes(type);
340
+ }
341
+ function isToolResult(type) {
342
+ return ['tool_completed', 'tool_result', 'tool_return', 'tool_failed', 'tool_error', 'tool_denied', 'function_result'].includes(type);
343
+ }
344
+ function textValue(value) {
345
+ return typeof value === 'string' ? value : value === undefined || value === null ? '' : structuredText(value);
346
+ }
347
+ function structuredText(value) {
348
+ if (typeof value === 'string')
349
+ return value;
350
+ try {
351
+ return JSON.stringify(value) ?? '';
352
+ }
353
+ catch {
354
+ return String(value);
355
+ }
356
+ }
357
+ function recordValue(value) {
358
+ return isRecord(value) ? value : null;
359
+ }
360
+ function writeTranscript(path, input) {
361
+ const history = input.messages.length > 0 ? input.messages.slice(0, -1) : [];
362
+ let parentId = null;
363
+ const lines = [JSON.stringify({ type: 'session', version: 3, id: input.sessionId, timestamp: new Date().toISOString(), cwd: input.cwd ?? process.cwd() })];
364
+ history.forEach((message, index) => {
365
+ if (message.role !== 'user' && message.role !== 'assistant')
366
+ return;
367
+ const id = message.id ?? `message-${index}`;
368
+ lines.push(JSON.stringify({ type: 'message', id, parentId, timestamp: new Date().toISOString(), message: { role: message.role, content: [{ type: 'text', text: extractText(message.content) }] } }));
369
+ parentId = id;
370
+ });
371
+ writeFileSync(path, `${lines.join('\n')}\n`, 'utf8');
372
+ }
373
+ function extractText(content) { if (typeof content === 'string')
374
+ return content; if (!Array.isArray(content))
375
+ return ''; return content.filter(isRecord).map((part) => typeof part.text === 'string' ? part.text : '').join('\n').trim(); }
376
+ function safeId(value) { return value.replace(/[^a-zA-Z0-9._-]+/gu, '_').slice(0, 96) || 'default'; }
377
+ function parseJson(value) { try {
378
+ const parsed = JSON.parse(value);
379
+ return isRecord(parsed) ? parsed : null;
380
+ }
381
+ catch {
382
+ return null;
383
+ } }
384
+ function readJson(path) { if (!existsSync(path))
385
+ return null; try {
386
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
387
+ return isRecord(parsed) ? parsed : null;
388
+ }
389
+ catch {
390
+ return null;
391
+ } }
392
+ function isRecord(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); }
393
+ function emptyCatalog() { return { groups: [], currentModel: null, currentEffort: null }; }
394
+ //# sourceMappingURL=command-code-driver.js.map
@@ -0,0 +1,19 @@
1
+ import type { CommandCodeSubscriptionUsage } from '../../shared/contracts/command-code.js';
2
+ /**
3
+ * 读取 Command Code 官方订阅余量。
4
+ *
5
+ * API key 只在 Host 进程中读取和使用,返回值不包含 key,也不把响应原文透传给浏览器。
6
+ */
7
+ export declare class CommandCodeSubscriptionService {
8
+ private readonly homeDirectory;
9
+ private readonly request;
10
+ private readonly timeoutMs;
11
+ constructor(options?: {
12
+ readonly homeDirectory?: string;
13
+ readonly fetch?: typeof fetch;
14
+ readonly timeoutMs?: number;
15
+ });
16
+ read(): Promise<CommandCodeSubscriptionUsage | null>;
17
+ }
18
+ export declare function readCommandCodeApiKey(homeDirectory: string): string | null;
19
+ //# sourceMappingURL=command-code-subscription.d.ts.map
@@ -0,0 +1,126 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ /**
5
+ * 读取 Command Code 官方订阅余量。
6
+ *
7
+ * API key 只在 Host 进程中读取和使用,返回值不包含 key,也不把响应原文透传给浏览器。
8
+ */
9
+ export class CommandCodeSubscriptionService {
10
+ homeDirectory;
11
+ request;
12
+ timeoutMs;
13
+ constructor(options = {}) {
14
+ this.homeDirectory = options.homeDirectory ?? join(homedir(), '.commandcode');
15
+ this.request = options.fetch ?? fetch;
16
+ this.timeoutMs = options.timeoutMs ?? 8_000;
17
+ }
18
+ async read() {
19
+ const apiKey = readCommandCodeApiKey(this.homeDirectory);
20
+ if (!apiKey)
21
+ return null;
22
+ const controller = new AbortController();
23
+ const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
24
+ try {
25
+ const headers = { Authorization: `Bearer ${apiKey}`, Accept: 'application/json' };
26
+ const [creditsResponse, subscriptionResponse] = await Promise.all([
27
+ this.request('https://api.commandcode.ai/alpha/billing/credits', { headers, signal: controller.signal }),
28
+ this.request('https://api.commandcode.ai/alpha/billing/subscriptions', { headers, signal: controller.signal }),
29
+ ]);
30
+ if (!creditsResponse.ok)
31
+ return null;
32
+ const credits = await jsonRecord(creditsResponse);
33
+ const subscription = subscriptionResponse.ok ? await jsonRecord(subscriptionResponse) : null;
34
+ const windows = recordValue(credits?.windowLimits);
35
+ const subscriptionData = recordValue(subscription?.data);
36
+ const planType = textValue(subscriptionData?.planId);
37
+ const monthlyRemaining = numberValue(recordValue(credits?.credits)?.monthlyCredits);
38
+ const monthlyTotal = resolveMonthlyCreditLimit(planType);
39
+ return {
40
+ authenticated: true,
41
+ planType,
42
+ primary: normalizeWindow(windows?.fiveHour),
43
+ secondary: normalizeWindow(windows?.weekly),
44
+ monthly: monthlyRemaining === null
45
+ ? null
46
+ : normalizeMonthlyWindow(monthlyRemaining, monthlyTotal, timestampValue(subscriptionData?.currentPeriodEnd)),
47
+ rateLimitReachedType: textValue(windows?.exceeded),
48
+ resetCredits: null,
49
+ capturedAt: new Date().toISOString(),
50
+ };
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ finally {
56
+ clearTimeout(timeout);
57
+ }
58
+ }
59
+ }
60
+ export function readCommandCodeApiKey(homeDirectory) {
61
+ const path = join(homeDirectory, 'auth.json');
62
+ if (!existsSync(path))
63
+ return null;
64
+ try {
65
+ const auth = JSON.parse(readFileSync(path, 'utf8'));
66
+ return textValue(recordValue(auth)?.apiKey) || textValue(process.env.COMMANDCODE_API_KEY);
67
+ }
68
+ catch {
69
+ return textValue(process.env.COMMANDCODE_API_KEY);
70
+ }
71
+ }
72
+ function normalizeWindow(value) {
73
+ const source = recordValue(value);
74
+ if (source === null)
75
+ return null;
76
+ const used = numberValue(source.used);
77
+ const cap = numberValue(source.cap);
78
+ if (used === null || cap === null || cap <= 0)
79
+ return null;
80
+ const usedPercent = clampPercent(used / cap * 100);
81
+ return { usedPercent, remainingPercent: 100 - usedPercent, windowDurationMins: null, resetsAt: normalizeResetTimestamp(numberValue(source.resetAt)) };
82
+ }
83
+ function normalizeMonthlyWindow(remainingCredits, totalCredits, resetAt) {
84
+ const remainingPercent = totalCredits !== null && totalCredits > 0 ? clampPercent(remainingCredits / totalCredits * 100) : 0;
85
+ return {
86
+ usedPercent: totalCredits !== null && totalCredits > 0 ? 100 - remainingPercent : 0,
87
+ remainingPercent,
88
+ windowDurationMins: null,
89
+ resetsAt: normalizeResetTimestamp(resetAt),
90
+ remainingCredits,
91
+ ...(totalCredits === null ? {} : { totalCredits }),
92
+ };
93
+ }
94
+ function resolveMonthlyCreditLimit(planId) {
95
+ const normalized = planId?.trim().toLowerCase() ?? '';
96
+ if (normalized.endsWith('-go') || normalized === 'go')
97
+ return 10;
98
+ if (normalized.endsWith('-goat') || normalized === 'goat')
99
+ return 70;
100
+ if (normalized.endsWith('-max') || normalized === 'max')
101
+ return 150;
102
+ return null;
103
+ }
104
+ function normalizeResetTimestamp(value) {
105
+ if (value === null)
106
+ return null;
107
+ return value > 10_000_000_000 ? Math.round(value / 1000) : Math.round(value);
108
+ }
109
+ function clampPercent(value) { return Math.max(0, Math.min(100, value)); }
110
+ function recordValue(value) { return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : null; }
111
+ function textValue(value) { return typeof value === 'string' && value.trim() ? value.trim() : null; }
112
+ function numberValue(value) { const parsed = typeof value === 'number' ? value : Number(value); return Number.isFinite(parsed) ? parsed : null; }
113
+ function timestampValue(value) {
114
+ const numeric = numberValue(value);
115
+ if (numeric !== null)
116
+ return numeric;
117
+ if (typeof value !== 'string')
118
+ return null;
119
+ const parsed = Date.parse(value);
120
+ return Number.isFinite(parsed) ? parsed : null;
121
+ }
122
+ async function jsonRecord(response) {
123
+ const value = await response.json();
124
+ return recordValue(value);
125
+ }
126
+ //# sourceMappingURL=command-code-subscription.js.map
@@ -0,0 +1,41 @@
1
+ import type { CodingNsCliAdapterDescriptor, CodingNsAgentEvent, CodingNsAgentQuestionResponse, CodingNsCliModelCatalog, CodingNsCliTurnInput, CodingNsAgentPermissionResponse } from '../../shared/contracts/cli-adapter.js';
2
+ /** 外部 Provider 原始会话的只读存在性状态。 */
3
+ export type CodingNsCliSessionProbeState = 'available' | 'missing' | 'corrupt' | 'unreachable' | 'unknown' | 'ephemeral';
4
+ /**
5
+ * 会话探测只接收恢复所需的 Host 私有索引,不得通过 resume/load/prompt 探测,
6
+ * 因为这些协议调用可能修改 Provider 状态或意外创建新会话。
7
+ */
8
+ export interface CodingNsCliSessionProbeInput {
9
+ readonly providerSessionId?: string;
10
+ readonly rawStoreRef?: string;
11
+ readonly cwd?: string;
12
+ /** 由 Registry 的探测超时控制器提供;网络型驱动应向下传递。 */
13
+ readonly signal?: AbortSignal;
14
+ }
15
+ export interface CodingNsCliSessionProbeResult {
16
+ readonly state: CodingNsCliSessionProbeState;
17
+ readonly reason: string;
18
+ /** 探测确认的原始存储位置,只能留在 Host。 */
19
+ readonly rawStoreRef?: string;
20
+ }
21
+ /**
22
+ * Host 内部的标准 Agent 运行时边界。
23
+ *
24
+ * 各适配器可以使用自己的 CLI、JSON-RPC、ACP 或 HTTP/SSE 协议,但对上层只返回
25
+ * 统一的模型目录、会话绑定、文本/推理/工具/用量/完成事件。凭据、原始协议和
26
+ * 进程句柄永远留在 Host 侧,Client 只消费 descriptor 与标准流。
27
+ */
28
+ export interface CodingNsCliDriver {
29
+ readonly descriptor: Omit<CodingNsCliAdapterDescriptor, 'installed' | 'enabled' | 'version' | 'command'>;
30
+ detect(): Promise<Pick<CodingNsCliAdapterDescriptor, 'installed' | 'version' | 'command'>>;
31
+ listModels(): Promise<CodingNsCliModelCatalog>;
32
+ probeSession?(input: CodingNsCliSessionProbeInput): Promise<CodingNsCliSessionProbeResult>;
33
+ executeTurn(input: CodingNsCliTurnInput): AsyncIterable<CodingNsAgentEvent>;
34
+ respondPermission?(sessionId: string, response: CodingNsAgentPermissionResponse): Promise<void> | void;
35
+ respondQuestion?(sessionId: string, response: CodingNsAgentQuestionResponse): Promise<void> | void;
36
+ steer?(sessionId: string, prompt: string): Promise<void> | void;
37
+ followUp?(sessionId: string, prompt: string): Promise<void> | void;
38
+ interrupt?(sessionId: string): Promise<void> | void;
39
+ dispose?(): Promise<void> | void;
40
+ }
41
+ //# sourceMappingURL=driver.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=driver.js.map
@@ -0,0 +1,37 @@
1
+ import type { CodingNsAgentEvent, CodingNsAgentQuestionResponse, CodingNsAgentPermissionResponse } from '../../shared/contracts/cli-adapter.js';
2
+ import type { CodingNsNativeSessionBridge } from '../native-session-bridge.js';
3
+ export interface CodingNsDshMessageProjectorOptions {
4
+ readonly adapterId: string;
5
+ readonly sessionId: string;
6
+ readonly modelId?: string;
7
+ readonly nativeSessions?: CodingNsNativeSessionBridge;
8
+ readonly signal?: AbortSignal;
9
+ readonly respondPermission?: (response: CodingNsAgentPermissionResponse) => Promise<void> | void;
10
+ readonly respondQuestion?: (response: CodingNsAgentQuestionResponse) => Promise<void> | void;
11
+ }
12
+ /** DSH `llm/stream` 接受的最小结构;具体协议只允许在本文件构造。 */
13
+ export type CodingNsDshStreamChunk = Readonly<Record<string, unknown>>;
14
+ /**
15
+ * 所有外部 Agent 共用的 DSH 消息投影器。
16
+ *
17
+ * 驱动只产生 CodingNsAgentEvent。本类统一完成快照去重、通道索引、工具历史、
18
+ * 原生权限/问题交互、usage 和终态映射,调用方不再按 Provider 或消息类型分支。
19
+ */
20
+ export declare class CodingNsDshMessageProjector {
21
+ private readonly options;
22
+ private readonly normalizer;
23
+ private readonly toolHistory;
24
+ private finished;
25
+ constructor(options: CodingNsDshMessageProjectorOptions);
26
+ get isFinished(): boolean;
27
+ push(event: CodingNsAgentEvent): Promise<readonly CodingNsDshStreamChunk[]>;
28
+ /** Provider 未发送 finish 时补齐 usage 和正常终态。 */
29
+ complete(reason?: 'stop' | 'cancel'): Promise<readonly CodingNsDshStreamChunk[]>;
30
+ /** 把执行异常也交给同一投影层,确保错误正文和终态结构一致。 */
31
+ fail(message: string, cancelled?: boolean): Promise<readonly CodingNsDshStreamChunk[]>;
32
+ private flushUsage;
33
+ private project;
34
+ private requestPermission;
35
+ private requestQuestions;
36
+ }
37
+ //# sourceMappingURL=dsh-message-projector.d.ts.map