@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,43 @@
1
+ import { spawn, spawnSync } from 'node:child_process';
2
+ import type { CodingNsCliModelCatalog, CodingNsAgentEvent, CodingNsCliTurnInput } from '../../shared/contracts/cli-adapter.js';
3
+ import type { CodingNsCliDriver, CodingNsCliSessionProbeInput, CodingNsCliSessionProbeResult } from './driver.js';
4
+ export interface PiAgentDriverOptions {
5
+ readonly binaries?: readonly string[];
6
+ readonly sessionRoots?: readonly string[];
7
+ readonly spawnSync?: typeof spawnSync;
8
+ readonly spawn?: typeof spawn;
9
+ }
10
+ /** Pi Agent 的 --mode rpc 适配器。Pi 的长期 RPC 细节被限制在本文件和标准进程层内。 */
11
+ export declare class PiAgentDriver implements CodingNsCliDriver {
12
+ readonly descriptor: {
13
+ readonly id: "pi";
14
+ readonly name: "Pi Agent";
15
+ readonly protocol: "json-rpc";
16
+ readonly capabilities: readonly ["models", "stream", "resume", "interrupt", "tool-events", "reasoning", "usage", "steer"];
17
+ };
18
+ private readonly binaries;
19
+ private readonly runSpawnSync;
20
+ private readonly runSpawn;
21
+ private readonly sessionRoots;
22
+ private cachedBinary;
23
+ private readonly processes;
24
+ private readonly sessions;
25
+ constructor(options?: PiAgentDriverOptions);
26
+ detect(): Promise<{
27
+ installed: boolean;
28
+ version: string | null;
29
+ command: string | null;
30
+ }>;
31
+ listModels(): Promise<CodingNsCliModelCatalog>;
32
+ probeSession(input: CodingNsCliSessionProbeInput): Promise<CodingNsCliSessionProbeResult>;
33
+ executeTurn(input: CodingNsCliTurnInput): AsyncIterable<CodingNsAgentEvent>;
34
+ /** 向运行中的 Pi 会话发送 steering,当前 turn 会立即改变方向。 */
35
+ steer(sessionId: string, prompt: string): Promise<void>;
36
+ /** 向运行中的 Pi 会话追加 follow-up。 */
37
+ followUp(sessionId: string, prompt: string): Promise<void>;
38
+ /** 中断当前 turn,但保留 Pi 进程供同一会话继续使用。 */
39
+ interrupt(sessionId: string): Promise<void>;
40
+ dispose(): void;
41
+ private getSession;
42
+ }
43
+ //# sourceMappingURL=pi-driver.d.ts.map
@@ -0,0 +1,312 @@
1
+ import { spawn, spawnSync } from 'node:child_process';
2
+ import { homedir } from 'node:os';
3
+ import { basename, join } from 'node:path';
4
+ import { JsonRpcProcess } from './json-rpc-process.js';
5
+ import { detectBinary, emptyCatalog, isRecord, textValue, usageChunk } from './rpc-driver-utils.js';
6
+ import { PI_CATALOG, isProviderDefaultModel } from './model-catalog.js';
7
+ import { probeStoredSession, readFirstJsonRecord } from './session-probe.js';
8
+ import { firstToolText, isToolRecord, normalizeToolStatus, serializeToolValue } from './tool-observation.js';
9
+ import { WINDOWS } from './process-utils.js';
10
+ /** Pi Agent 的 --mode rpc 适配器。Pi 的长期 RPC 细节被限制在本文件和标准进程层内。 */
11
+ export class PiAgentDriver {
12
+ descriptor = { id: 'pi', name: 'Pi Agent', protocol: 'json-rpc', capabilities: ['models', 'stream', 'resume', 'interrupt', 'tool-events', 'reasoning', 'usage', 'steer'] };
13
+ binaries;
14
+ runSpawnSync;
15
+ runSpawn;
16
+ sessionRoots;
17
+ cachedBinary = null;
18
+ processes = new Set();
19
+ sessions = new Map();
20
+ constructor(options = {}) {
21
+ this.binaries = options.binaries ?? ['pi', 'pi-agent'];
22
+ this.runSpawnSync = options.spawnSync ?? spawnSync;
23
+ this.runSpawn = options.spawn ?? spawn;
24
+ const configDirectory = process.env.PI_CODING_AGENT_DIR ?? join(homedir(), '.pi', 'agent');
25
+ this.sessionRoots = options.sessionRoots ?? [process.env.PI_CODING_AGENT_SESSION_DIR ?? join(configDirectory, 'sessions')];
26
+ }
27
+ async detect() {
28
+ const result = await detectBinary({ binaries: this.binaries, spawnSync: this.runSpawnSync });
29
+ if (result.installed)
30
+ this.cachedBinary = result.command;
31
+ return result;
32
+ }
33
+ async listModels() {
34
+ const detection = await this.detect();
35
+ if (!detection.installed)
36
+ return emptyCatalog();
37
+ // Pi 的 RPC 目录包含每个模型精确的 thinkingLevelMap;表格接口只有 yes/no,
38
+ // 不能用来判断具体档位,因此只能作为旧版本的降级路径。
39
+ const rpc = new JsonRpcProcess({ command: detection.command, args: ['--mode', 'rpc'], spawn: this.runSpawn });
40
+ const controller = new AbortController();
41
+ const timer = setTimeout(() => controller.abort(), 12_000);
42
+ try {
43
+ const response = await rpc.request('get_available_models', {}, { signal: controller.signal });
44
+ const catalog = parsePiCatalog(response);
45
+ if (catalog.groups.length > 0)
46
+ return catalog;
47
+ }
48
+ catch { /* 旧版 Pi 没有模型 RPC 时继续读取表格。 */ }
49
+ finally {
50
+ clearTimeout(timer);
51
+ rpc.dispose();
52
+ }
53
+ try {
54
+ const result = this.runSpawnSync(detection.command, ['--list-models'], { encoding: 'utf8', timeout: 12_000, windowsHide: true, shell: WINDOWS });
55
+ const catalog = parsePiCliCatalog(`${result.stdout ?? ''}\n${result.stderr ?? ''}`);
56
+ if (catalog.groups.length > 0)
57
+ return catalog;
58
+ }
59
+ catch { /* 旧版 Pi 没有 --list-models。 */ }
60
+ return PI_CATALOG;
61
+ }
62
+ async probeSession(input) {
63
+ return probeStoredSession(input, {
64
+ roots: this.sessionRoots,
65
+ matches: (path, entry, id) => entry.isFile() && basename(path).endsWith(`${id}.jsonl`),
66
+ validate: async (path, id) => {
67
+ const record = await readFirstJsonRecord(path);
68
+ return record?.type === 'session' && record.id === id;
69
+ },
70
+ });
71
+ }
72
+ async *executeTurn(input) {
73
+ const command = this.cachedBinary ?? (await this.detect()).command;
74
+ if (command === null)
75
+ throw new Error('Pi Agent 未安装');
76
+ const session = this.getSession(input.sessionId, command, input.cwd, input.providerSessionId);
77
+ const rpc = session.rpc;
78
+ try {
79
+ // 新版 Pi 接受可选模型设置;旧版会以错误响应结束,随后仍可使用默认模型。
80
+ if (session.needsResume && input.providerSessionId) {
81
+ try {
82
+ await rpc.request('resume', { sessionId: input.providerSessionId }, { signal: input.signal, killOnAbort: false });
83
+ session.providerSessionId = input.providerSessionId;
84
+ }
85
+ catch { /* 旧版 Pi 没有显式 resume,继续复用当前进程 */ }
86
+ session.needsResume = false;
87
+ }
88
+ if (!isProviderDefaultModel(input.modelId)) {
89
+ try {
90
+ await rpc.request('set_model', { model: input.modelId }, { signal: input.signal, killOnAbort: false });
91
+ }
92
+ catch { /* 兼容旧版 */ }
93
+ }
94
+ yield { type: 'session-binding', providerSessionId: session.providerSessionId };
95
+ const stream = streamPiPrompt(rpc, input.prompt, input.signal);
96
+ let finishReason;
97
+ while (true) {
98
+ const item = await stream.next();
99
+ if (item.done) {
100
+ finishReason = item.value;
101
+ break;
102
+ }
103
+ const discoveredId = readSessionId(item.value);
104
+ if (discoveredId && discoveredId !== session.providerSessionId) {
105
+ session.providerSessionId = discoveredId;
106
+ yield { type: 'session-binding', providerSessionId: discoveredId };
107
+ }
108
+ const chunk = piMessageToChunk(item.value);
109
+ if (chunk !== null)
110
+ yield chunk;
111
+ }
112
+ if (finishReason === 'cancel') {
113
+ await this.interrupt(input.sessionId);
114
+ }
115
+ yield { type: 'finish', reason: finishReason };
116
+ }
117
+ finally { /* 跨轮复用:仅 dispose() 才回收长期进程。 */ }
118
+ }
119
+ /** 向运行中的 Pi 会话发送 steering,当前 turn 会立即改变方向。 */
120
+ async steer(sessionId, prompt) {
121
+ const session = this.sessions.get(sessionId);
122
+ if (session === undefined)
123
+ throw new Error('Pi 会话不存在');
124
+ await session.rpc.request('steer', { message: prompt }, { killOnAbort: false });
125
+ }
126
+ /** 向运行中的 Pi 会话追加 follow-up。 */
127
+ async followUp(sessionId, prompt) {
128
+ const session = this.sessions.get(sessionId);
129
+ if (session === undefined)
130
+ throw new Error('Pi 会话不存在');
131
+ await session.rpc.request('follow_up', { message: prompt }, { killOnAbort: false });
132
+ }
133
+ /** 中断当前 turn,但保留 Pi 进程供同一会话继续使用。 */
134
+ async interrupt(sessionId) {
135
+ const session = this.sessions.get(sessionId);
136
+ if (session === undefined)
137
+ return;
138
+ try {
139
+ await session.rpc.request('interrupt', {}, { killOnAbort: false });
140
+ }
141
+ catch {
142
+ try {
143
+ session.rpc.notify('abort', {});
144
+ }
145
+ catch { /* 进程可能已退出 */ }
146
+ }
147
+ }
148
+ dispose() {
149
+ for (const session of this.sessions.values())
150
+ session.rpc.dispose();
151
+ this.sessions.clear();
152
+ this.processes.clear();
153
+ this.cachedBinary = null;
154
+ }
155
+ getSession(sessionId, command, cwd, providerSessionId) {
156
+ const previous = this.sessions.get(sessionId);
157
+ if (previous !== undefined && previous.cwd === cwd)
158
+ return previous;
159
+ previous?.rpc.dispose();
160
+ const rpc = new JsonRpcProcess({ command, args: ['--mode', 'rpc'], cwd, spawn: this.runSpawn });
161
+ this.processes.add(rpc);
162
+ const session = {
163
+ rpc,
164
+ cwd,
165
+ providerSessionId: providerSessionId ?? sessionId,
166
+ needsResume: providerSessionId !== undefined,
167
+ };
168
+ this.sessions.set(sessionId, session);
169
+ return session;
170
+ }
171
+ }
172
+ /**
173
+ * Pi 的 prompt 响应只表示已接受,不能作为轮次终态。
174
+ * 监听器必须先于请求注册,并一直保留到 agent_settled、失败或取消。
175
+ */
176
+ async function* streamPiPrompt(rpc, prompt, signal) {
177
+ const queue = [];
178
+ let wake;
179
+ let promptSettled = false;
180
+ let terminalReason = null;
181
+ const notify = () => { wake?.(); wake = undefined; };
182
+ const listener = (message) => {
183
+ queue.push(message);
184
+ const type = piEventType(message);
185
+ if (type === 'agent_settled')
186
+ terminalReason = 'stop';
187
+ else if (type === 'error' || type === 'agent_error' || type === 'agent_failed')
188
+ terminalReason = 'error';
189
+ notify();
190
+ };
191
+ const removeListener = rpc.addNotificationListener(listener);
192
+ const onAbort = () => { terminalReason = 'cancel'; notify(); };
193
+ if (signal?.aborted)
194
+ onAbort();
195
+ else
196
+ signal?.addEventListener('abort', onAbort, { once: true });
197
+ void rpc.request('prompt', { message: prompt }, { signal, killOnAbort: false }).then(() => { promptSettled = true; notify(); }, () => {
198
+ promptSettled = true;
199
+ terminalReason = signal?.aborted ? 'cancel' : 'error';
200
+ notify();
201
+ });
202
+ try {
203
+ while (queue.length > 0 || !promptSettled || terminalReason === null) {
204
+ if (queue.length > 0) {
205
+ yield queue.shift();
206
+ continue;
207
+ }
208
+ await new Promise((resolve) => { wake = resolve; });
209
+ }
210
+ return terminalReason;
211
+ }
212
+ finally {
213
+ signal?.removeEventListener('abort', onAbort);
214
+ removeListener();
215
+ }
216
+ }
217
+ function piEventType(message) {
218
+ const params = isRecord(message.params) ? message.params : message;
219
+ return typeof params.type === 'string' ? params.type.toLowerCase() : '';
220
+ }
221
+ function parsePiCliCatalog(output) {
222
+ const models = [];
223
+ const levels = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
224
+ for (const line of output.split(/\r?\n/u)) {
225
+ const match = line.trim().match(/^(\S+)\s+(\S+)\s+\S+\s+\S+\s+(yes|no)(?:\s+|$)/iu);
226
+ if (!match)
227
+ continue;
228
+ const provider = match[1];
229
+ const model = match[2];
230
+ const id = `${provider}/${model}`;
231
+ if (models.some((item) => item.id === id))
232
+ continue;
233
+ models.push({ id, name: model, efforts: match[3].toLowerCase() === 'yes' ? levels : ['off'] });
234
+ }
235
+ if (models.length === 0)
236
+ return emptyCatalog();
237
+ return { groups: [{ id: 'pi', name: 'Pi', models }], currentModel: null, currentEffort: null };
238
+ }
239
+ function parsePiCatalog(value) {
240
+ const payload = isRecord(value) && isRecord(value.data) ? value.data : value;
241
+ const models = Array.isArray(payload) ? payload : isRecord(payload) && Array.isArray(payload.models) ? payload.models : [];
242
+ const items = models.flatMap((entry) => {
243
+ if (!isRecord(entry))
244
+ return [];
245
+ const provider = typeof entry.provider === 'string' ? entry.provider.trim() : '';
246
+ const id = typeof entry.id === 'string' ? entry.id.trim() : typeof entry.modelId === 'string' ? entry.modelId.trim() : '';
247
+ if (!id)
248
+ return [];
249
+ const modelId = provider ? `${provider}/${id}` : id;
250
+ const map = isRecord(entry.thinkingLevelMap) ? entry.thinkingLevelMap : null;
251
+ const reasoning = entry.reasoning === true;
252
+ const levels = !reasoning
253
+ ? ['off']
254
+ : map === null
255
+ ? ['off', 'minimal', 'low', 'medium', 'high']
256
+ : ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'].filter((level) => typeof map[level] === 'string' && map[level].trim() !== '');
257
+ return [{ id: modelId, name: typeof entry.name === 'string' && entry.name.trim() ? entry.name : id, efforts: levels }];
258
+ });
259
+ if (items.length === 0)
260
+ return emptyCatalog();
261
+ return { groups: [{ id: 'pi', name: 'Pi', models: [...new Map(items.map((item) => [item.id, item])).values()] }], currentModel: null, currentEffort: null };
262
+ }
263
+ function piMessageToChunk(message) {
264
+ const params = isRecord(message.params) ? message.params : message;
265
+ const event = isRecord(params.item) ? params.item : params;
266
+ const assistantEvent = isRecord(params.assistantMessageEvent) ? params.assistantMessageEvent : null;
267
+ const completedMessage = isRecord(params.message) ? params.message : null;
268
+ const rootType = typeof event.type === 'string' ? event.type : typeof params.event === 'string' ? params.event : '';
269
+ if (rootType === 'agent_settled' || rootType === 'agent_end' || rootType === 'turn_end')
270
+ return null;
271
+ const type = assistantEvent !== null && typeof assistantEvent.type === 'string' ? assistantEvent.type : rootType;
272
+ const text = textValue(assistantEvent?.delta ?? params.delta ?? params.text ?? params.content ?? params.message);
273
+ if (type.includes('text_delta') || type === 'text-delta' || type === 'assistant_message_event' && text)
274
+ return text ? { type: 'text-delta', text } : null;
275
+ if (type.includes('thinking') || type.includes('reasoning'))
276
+ return text ? { type: 'reasoning-delta', text } : null;
277
+ const toolResultMessage = completedMessage?.role === 'toolResult' ? completedMessage : null;
278
+ const toolCall = isToolRecord(assistantEvent?.toolCall) ? assistantEvent.toolCall : null;
279
+ if (type.includes('tool') || type.includes('agent') || toolResultMessage !== null) {
280
+ const source = toolResultMessage ?? assistantEvent ?? event;
281
+ const toolName = firstToolText(source.toolName, source.name, toolCall?.name, params.toolName, params.name) ?? (type.includes('agent') ? 'subagent' : 'tool');
282
+ const callId = firstToolText(source.toolCallId, source.callId, source.id, toolCall?.id, params.toolCallId, params.callId);
283
+ const input = serializeToolValue(source.args ?? source.arguments ?? toolCall?.arguments ?? params.args);
284
+ const failed = source.isError === true || params.isError === true || type.includes('failed') || type.includes('error');
285
+ const resultValue = source.partialResult ?? source.result ?? (toolResultMessage === null ? source.output : source.content);
286
+ const result = serializeToolValue(resultValue);
287
+ const agentId = firstToolText(source.agentId, params.agentId, type.includes('agent') ? source.sessionId ?? params.sessionId : undefined);
288
+ const detail = serializeToolValue(source.detail ?? params.detail);
289
+ const status = normalizeToolStatus(source.status ?? source.state ?? params.status ?? params.state, failed ? 'failed' : type.includes('end') || type.includes('completed') || toolResultMessage !== null ? 'completed' : 'running');
290
+ return {
291
+ type: 'tool-event',
292
+ toolName,
293
+ status,
294
+ ...(callId ? { callId } : {}),
295
+ ...(input !== undefined ? { input } : {}),
296
+ ...(failed ? (result === undefined ? {} : { error: result }) : (result === undefined ? {} : { output: result })),
297
+ ...(!failed && result !== undefined ? { outputMode: 'snapshot' } : {}),
298
+ ...(agentId ? { agentId } : {}),
299
+ ...(detail !== undefined ? { detail } : {}),
300
+ };
301
+ }
302
+ const usage = usageChunk(params);
303
+ return usage ?? null;
304
+ }
305
+ function readSessionId(message) {
306
+ const params = isRecord(message.params) ? message.params : message;
307
+ for (const key of ['sessionId', 'session_id', 'providerSessionId'])
308
+ if (typeof params[key] === 'string' && params[key].trim())
309
+ return params[key].trim();
310
+ return null;
311
+ }
312
+ //# sourceMappingURL=pi-driver.js.map
@@ -0,0 +1,16 @@
1
+ interface KillableChild {
2
+ readonly pid?: number | null;
3
+ kill(signal?: string): boolean;
4
+ }
5
+ /** Windows 的 npm CLI 通常是 .cmd 包装器,必须经由 shell 才能启动。 */
6
+ export declare const WINDOWS: boolean;
7
+ /**
8
+ * 结束 CLI 进程及其子进程树。
9
+ *
10
+ * Windows 没有 POSIX 进程组信号;仅调用 child.kill() 往往只结束 cmd.exe
11
+ * 包装器,真正的 Node/CLI 子进程仍会占用端口。taskkill /T 是系统自带的
12
+ * 最小进程树清理手段,失败时再回退到 Node 自身的 kill。
13
+ */
14
+ export declare function terminateChildProcess(child: KillableChild, signal?: NodeJS.Signals): void;
15
+ export {};
16
+ //# sourceMappingURL=process-utils.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ /** Windows 的 npm CLI 通常是 .cmd 包装器,必须经由 shell 才能启动。 */
3
+ export const WINDOWS = process.platform === 'win32';
4
+ /**
5
+ * 结束 CLI 进程及其子进程树。
6
+ *
7
+ * Windows 没有 POSIX 进程组信号;仅调用 child.kill() 往往只结束 cmd.exe
8
+ * 包装器,真正的 Node/CLI 子进程仍会占用端口。taskkill /T 是系统自带的
9
+ * 最小进程树清理手段,失败时再回退到 Node 自身的 kill。
10
+ */
11
+ export function terminateChildProcess(child, signal = 'SIGTERM') {
12
+ if (WINDOWS && typeof child.pid === 'number' && child.pid > 0) {
13
+ try {
14
+ spawnSync('taskkill', ['/PID', String(child.pid), '/T', '/F'], {
15
+ windowsHide: true,
16
+ });
17
+ }
18
+ catch {
19
+ // taskkill 不可用时继续尝试 Node 的兼容终止路径。
20
+ }
21
+ }
22
+ try {
23
+ child.kill(signal);
24
+ }
25
+ catch { /* 进程可能已经退出 */ }
26
+ }
27
+ //# sourceMappingURL=process-utils.js.map
@@ -0,0 +1,82 @@
1
+ import { spawn, spawnSync } from 'node:child_process';
2
+ import type { CliSubscriptionUsage } from '../../shared/contracts/subscription.js';
3
+ type FetchLike = typeof fetch;
4
+ /** 统一读取 Codex、Claude Code、OpenCode 订阅摘要。所有原始凭据都留在 Host。 */
5
+ export declare class ProviderSubscriptionService {
6
+ readonly commandCode: SubscriptionReader | undefined;
7
+ readonly codex: CodexSubscriptionService;
8
+ readonly claudeCode: ClaudeCodeSubscriptionService;
9
+ readonly opencode: OpenCodeSubscriptionService;
10
+ readonly sub2api: Sub2ApiUsageService;
11
+ constructor(options?: ProviderSubscriptionOptions);
12
+ read(adapterId: string): Promise<CliSubscriptionUsage | null>;
13
+ private readSub2ApiFirst;
14
+ }
15
+ export interface ProviderSubscriptionOptions {
16
+ readonly commandCode?: SubscriptionReader;
17
+ readonly codex?: CodexSubscriptionOptions;
18
+ readonly claudeCode?: ClaudeCodeSubscriptionOptions;
19
+ readonly opencode?: OpenCodeSubscriptionOptions;
20
+ readonly sub2api?: Sub2ApiUsageOptions;
21
+ }
22
+ export interface SubscriptionReader {
23
+ read(): Promise<CliSubscriptionUsage | null>;
24
+ }
25
+ export interface Sub2ApiSource {
26
+ readonly baseUrl: string;
27
+ readonly apiKey: string;
28
+ }
29
+ export interface Sub2ApiUsageOptions {
30
+ readonly fetch?: FetchLike;
31
+ readonly timeoutMs?: number;
32
+ readonly sources?: Partial<Record<'codex' | 'claude-code' | 'dsh' | 'grok' | 'opencode', Sub2ApiSource | readonly Sub2ApiSource[]>>;
33
+ }
34
+ /** 通过 Provider 的上游 base URL 检测 Sub2API;只返回脱敏后的统计摘要。 */
35
+ export declare class Sub2ApiUsageService {
36
+ private readonly request;
37
+ private readonly timeoutMs;
38
+ private readonly configuredSources;
39
+ constructor(options?: Sub2ApiUsageOptions);
40
+ hasSource(adapterId: string): boolean;
41
+ read(adapterId: string): Promise<CliSubscriptionUsage | null>;
42
+ private readSource;
43
+ }
44
+ export interface CodexSubscriptionOptions {
45
+ readonly homeDirectory?: string;
46
+ readonly binaries?: readonly string[];
47
+ readonly spawnSync?: typeof spawnSync;
48
+ readonly spawn?: typeof spawn;
49
+ readonly timeoutMs?: number;
50
+ }
51
+ export declare class CodexSubscriptionService implements SubscriptionReader {
52
+ private readonly binaries;
53
+ private readonly runSpawnSync;
54
+ private readonly runSpawn;
55
+ private readonly timeoutMs;
56
+ private readonly homeDirectory;
57
+ private command;
58
+ constructor(options?: CodexSubscriptionOptions);
59
+ read(): Promise<CliSubscriptionUsage | null>;
60
+ }
61
+ export interface ClaudeCodeSubscriptionOptions {
62
+ readonly homeDirectory?: string;
63
+ readonly fetch?: FetchLike;
64
+ readonly timeoutMs?: number;
65
+ }
66
+ export declare class ClaudeCodeSubscriptionService implements SubscriptionReader {
67
+ private readonly homeDirectory;
68
+ private readonly request;
69
+ private readonly timeoutMs;
70
+ constructor(options?: ClaudeCodeSubscriptionOptions);
71
+ read(): Promise<CliSubscriptionUsage | null>;
72
+ }
73
+ export interface OpenCodeSubscriptionOptions {
74
+ readonly homeDirectory?: string;
75
+ }
76
+ export declare class OpenCodeSubscriptionService implements SubscriptionReader {
77
+ private readonly homeDirectory;
78
+ constructor(options?: OpenCodeSubscriptionOptions);
79
+ read(): Promise<CliSubscriptionUsage | null>;
80
+ }
81
+ export {};
82
+ //# sourceMappingURL=provider-subscription.d.ts.map