dsh-over-ssh 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +10 -10
  2. package/agents/agent-manifest.json +1 -1
  3. package/lib/client.js +363 -314
  4. package/lib/file-references.js +80 -35
  5. package/lib/fs.js +158 -75
  6. package/lib/index.js +4103 -3397
  7. package/lib/terminal-wrapper.js +9 -4
  8. package/lib/types/src/config.d.ts +80 -9
  9. package/lib/types/src/file-references.d.ts +0 -1
  10. package/lib/types/src/host/app/backend.d.ts +9 -1
  11. package/lib/types/src/host/app/recycle-bin/recycle-bin-contract.d.ts +0 -1
  12. package/lib/types/src/host/app/recycle-bin/recycle-bin-service.d.ts +0 -1
  13. package/lib/types/src/host/app/session-admin/session-admin-contract.d.ts +12 -1
  14. package/lib/types/src/host/app/session-admin/session-admin-service.d.ts +0 -1
  15. package/lib/types/src/host/app/transport/transport-selector.d.ts +0 -1
  16. package/lib/types/src/host/app/transport/transport-service.d.ts +0 -1
  17. package/lib/types/src/host/domain/capability.d.ts +0 -1
  18. package/lib/types/src/host/domain/errors.d.ts +0 -1
  19. package/lib/types/src/host/domain/roots/connection.d.ts +0 -1
  20. package/lib/types/src/host/domain/roots/root.d.ts +24 -9
  21. package/lib/types/src/host/domain/roots/session-roots.d.ts +0 -1
  22. package/lib/types/src/host/domain/roots/ssh-config.d.ts +0 -1
  23. package/lib/types/src/host/domain/session/session-admin.d.ts +0 -1
  24. package/lib/types/src/host/domain/transfer/recycle-bin.d.ts +0 -1
  25. package/lib/types/src/host/domain/transfer/transfer.d.ts +0 -1
  26. package/lib/types/src/host/infra/transport/agent/agent-installer.d.ts +0 -1
  27. package/lib/types/src/host/infra/transport/ssh/ssh2-transport.d.ts +0 -1
  28. package/lib/types/src/host/infra/transport/transport-base.d.ts +0 -1
  29. package/lib/types/src/host/infra/transport/transport.d.ts +16 -2
  30. package/lib/types/src/host/integration/agent/agent-preflight.d.ts +0 -1
  31. package/lib/types/src/host/integration/fs/file-reference-provider.d.ts +0 -1
  32. package/lib/types/src/host/integration/fs/fs-provider.d.ts +0 -2
  33. package/lib/types/src/host/integration/transfer/transfer-service.d.ts +0 -1
  34. package/lib/types/src/index.d.ts +23 -1
  35. package/lib/types/src/local-bridge-refs.d.ts +0 -1
  36. package/lib/types/src/local-bridge.d.ts +0 -1
  37. package/lib/types/src/shared/root-keys.d.ts +120 -0
  38. package/lib/types/src/wiring/helpers.d.ts +0 -1
  39. package/package.json +5 -3
  40. package/lib/types/src/client/controls.d.ts +0 -131
  41. package/lib/types/src/client/core/card-focus-trap.d.ts +0 -45
  42. package/lib/types/src/client/core/controls.d.ts +0 -164
  43. package/lib/types/src/client/core/latest.d.ts +0 -48
  44. package/lib/types/src/client/core/locale.d.ts +0 -38
  45. package/lib/types/src/client/core/message.d.ts +0 -37
  46. package/lib/types/src/client/core/panel-model.d.ts +0 -134
  47. package/lib/types/src/client/core/portal.d.ts +0 -266
  48. package/lib/types/src/client/core/remote.d.ts +0 -84
  49. package/lib/types/src/client/core/styles.d.ts +0 -458
  50. package/lib/types/src/client/file-tree-io.d.ts +0 -19
  51. package/lib/types/src/client/file-tree.d.ts +0 -271
  52. package/lib/types/src/client/flows/directory-browser.d.ts +0 -587
  53. package/lib/types/src/client/flows/session-directory.d.ts +0 -415
  54. package/lib/types/src/client/flows/workspace-directory-flow.d.ts +0 -480
  55. package/lib/types/src/client/locale.d.ts +0 -31
  56. package/lib/types/src/client/panel-model.d.ts +0 -37
  57. package/lib/types/src/client/panel.d.ts +0 -77
  58. package/lib/types/src/client/roots/connection-test.d.ts +0 -69
  59. package/lib/types/src/client/roots/roots-panel-state.d.ts +0 -307
  60. package/lib/types/src/client/roots/roots-panel-view.d.ts +0 -280
  61. package/lib/types/src/client/roots/roots-panel.d.ts +0 -364
  62. package/lib/types/src/client/roots/transfer-panel-view.d.ts +0 -35
  63. package/lib/types/src/client/roots/transfer-panel.d.ts +0 -241
  64. package/lib/types/src/client/roots/transfer-progress.d.ts +0 -67
  65. package/lib/types/src/client/roots-panel-view.d.ts +0 -236
  66. package/lib/types/src/client/roots-panel.d.ts +0 -347
  67. package/lib/types/src/client/session/session-panel-view.d.ts +0 -336
  68. package/lib/types/src/client/session/session-panel.d.ts +0 -322
  69. package/lib/types/src/client/session/session-remote-mark.d.ts +0 -110
  70. package/lib/types/src/client/session/session-row-actions.d.ts +0 -398
  71. package/lib/types/src/client/session-panel.d.ts +0 -152
  72. package/lib/types/src/client/styles.d.ts +0 -252
  73. package/lib/types/src/client/workspace-directory-flow.d.ts +0 -342
  74. package/lib/types/src/fs.d.ts +0 -46
  75. package/lib/types/src/host/app/recycle-bin/recycle-bin-move.d.ts +0 -18
  76. package/lib/types/src/host/app/recycle-bin/recycle-bin-world.d.ts +0 -38
  77. package/lib/types/src/host/app/recycle-bin-contract.d.ts +0 -215
  78. package/lib/types/src/host/app/recycle-bin-move.d.ts +0 -18
  79. package/lib/types/src/host/app/recycle-bin-service.d.ts +0 -45
  80. package/lib/types/src/host/app/recycle-bin-world.d.ts +0 -35
  81. package/lib/types/src/host/app/roots/roots-api-connections.d.ts +0 -49
  82. package/lib/types/src/host/app/roots/roots-api-contract.d.ts +0 -369
  83. package/lib/types/src/host/app/roots/roots-api-directories.d.ts +0 -13
  84. package/lib/types/src/host/app/roots/roots-api-http.d.ts +0 -77
  85. package/lib/types/src/host/app/roots/roots-api-long-poll.d.ts +0 -130
  86. package/lib/types/src/host/app/roots/roots-api-projections.d.ts +0 -102
  87. package/lib/types/src/host/app/roots/roots-api-roots.d.ts +0 -13
  88. package/lib/types/src/host/app/roots/roots-api-state.d.ts +0 -22
  89. package/lib/types/src/host/app/roots/roots-api-transfers.d.ts +0 -26
  90. package/lib/types/src/host/app/roots/roots-api.d.ts +0 -55
  91. package/lib/types/src/host/app/roots/user-roots.d.ts +0 -552
  92. package/lib/types/src/host/app/roots-api-connections.d.ts +0 -49
  93. package/lib/types/src/host/app/roots-api-contract.d.ts +0 -339
  94. package/lib/types/src/host/app/roots-api-directories.d.ts +0 -13
  95. package/lib/types/src/host/app/roots-api-http.d.ts +0 -77
  96. package/lib/types/src/host/app/roots-api-projections.d.ts +0 -102
  97. package/lib/types/src/host/app/roots-api-roots.d.ts +0 -13
  98. package/lib/types/src/host/app/roots-api-state.d.ts +0 -22
  99. package/lib/types/src/host/app/roots-api-support.d.ts +0 -182
  100. package/lib/types/src/host/app/roots-api-transfers.d.ts +0 -13
  101. package/lib/types/src/host/app/roots-api.d.ts +0 -55
  102. package/lib/types/src/host/app/routed-fs.d.ts +0 -239
  103. package/lib/types/src/host/app/serialize.d.ts +0 -37
  104. package/lib/types/src/host/app/session-admin/session-admin-context.d.ts +0 -36
  105. package/lib/types/src/host/app/session-admin/session-admin-delete.d.ts +0 -34
  106. package/lib/types/src/host/app/session-admin-context.d.ts +0 -36
  107. package/lib/types/src/host/app/session-admin-contract.d.ts +0 -214
  108. package/lib/types/src/host/app/session-admin-delete.d.ts +0 -34
  109. package/lib/types/src/host/app/session-admin-service.d.ts +0 -38
  110. package/lib/types/src/host/app/takeover/takeover-plan.d.ts +0 -227
  111. package/lib/types/src/host/app/takeover/takeover-rows.d.ts +0 -55
  112. package/lib/types/src/host/app/transport-selector.d.ts +0 -98
  113. package/lib/types/src/host/app/transport-service.d.ts +0 -75
  114. package/lib/types/src/host/app/user-roots.d.ts +0 -461
  115. package/lib/types/src/host/domain/bin-location.d.ts +0 -79
  116. package/lib/types/src/host/domain/connection.d.ts +0 -95
  117. package/lib/types/src/host/domain/glob-pattern.d.ts +0 -62
  118. package/lib/types/src/host/domain/literal-text.d.ts +0 -63
  119. package/lib/types/src/host/domain/path-grammar.d.ts +0 -84
  120. package/lib/types/src/host/domain/recycle-bin.d.ts +0 -337
  121. package/lib/types/src/host/domain/root.d.ts +0 -74
  122. package/lib/types/src/host/domain/roots/bin-location.d.ts +0 -91
  123. package/lib/types/src/host/domain/roots/route-table.d.ts +0 -102
  124. package/lib/types/src/host/domain/route-table.d.ts +0 -80
  125. package/lib/types/src/host/domain/session/terminal-target.d.ts +0 -136
  126. package/lib/types/src/host/domain/session-admin.d.ts +0 -330
  127. package/lib/types/src/host/domain/shell.d.ts +0 -47
  128. package/lib/types/src/host/domain/ssh-config.d.ts +0 -73
  129. package/lib/types/src/host/domain/terminal-target.d.ts +0 -132
  130. package/lib/types/src/host/domain/tool-requests.d.ts +0 -369
  131. package/lib/types/src/host/domain/transfer.d.ts +0 -260
  132. package/lib/types/src/host/infra/backend/local-backend.d.ts +0 -84
  133. package/lib/types/src/host/infra/backend/local-version.d.ts +0 -43
  134. package/lib/types/src/host/infra/backend/platform-local-backend.d.ts +0 -89
  135. package/lib/types/src/host/infra/backend/remote-backend.d.ts +0 -239
  136. package/lib/types/src/host/infra/cache/lru.d.ts +0 -52
  137. package/lib/types/src/host/infra/cache/versioned.d.ts +0 -77
  138. package/lib/types/src/host/infra/temp-name.d.ts +0 -19
  139. package/lib/types/src/host/infra/transport/agent/agent-protocol-client.d.ts +0 -132
  140. package/lib/types/src/host/infra/transport/agent/agent-protocol-codec.d.ts +0 -140
  141. package/lib/types/src/host/infra/transport/agent/agent-protocol-errors.d.ts +0 -41
  142. package/lib/types/src/host/infra/transport/agent/agent-protocol-frames.d.ts +0 -197
  143. package/lib/types/src/host/infra/transport/agent/agent-protocol-types.d.ts +0 -564
  144. package/lib/types/src/host/infra/transport/agent/agent-transport.d.ts +0 -418
  145. package/lib/types/src/host/infra/transport/agent-installer.d.ts +0 -121
  146. package/lib/types/src/host/infra/transport/agent-protocol-client.d.ts +0 -123
  147. package/lib/types/src/host/infra/transport/agent-protocol-codec.d.ts +0 -131
  148. package/lib/types/src/host/infra/transport/agent-protocol-errors.d.ts +0 -41
  149. package/lib/types/src/host/infra/transport/agent-protocol-frames.d.ts +0 -197
  150. package/lib/types/src/host/infra/transport/agent-protocol-types.d.ts +0 -509
  151. package/lib/types/src/host/infra/transport/agent-transport.d.ts +0 -353
  152. package/lib/types/src/host/infra/transport/alias-transport.d.ts +0 -206
  153. package/lib/types/src/host/infra/transport/askpass-fs.d.ts +0 -20
  154. package/lib/types/src/host/infra/transport/askpass.d.ts +0 -133
  155. package/lib/types/src/host/infra/transport/command-pool.d.ts +0 -61
  156. package/lib/types/src/host/infra/transport/fs-commands.d.ts +0 -140
  157. package/lib/types/src/host/infra/transport/git-status-route.d.ts +0 -63
  158. package/lib/types/src/host/infra/transport/git-status.d.ts +0 -101
  159. package/lib/types/src/host/infra/transport/node-spawn.d.ts +0 -26
  160. package/lib/types/src/host/infra/transport/session-window.d.ts +0 -51
  161. package/lib/types/src/host/infra/transport/shell-quote.d.ts +0 -59
  162. package/lib/types/src/host/infra/transport/ssh/alias-transport.d.ts +0 -206
  163. package/lib/types/src/host/infra/transport/ssh/askpass-fs.d.ts +0 -20
  164. package/lib/types/src/host/infra/transport/ssh/askpass.d.ts +0 -133
  165. package/lib/types/src/host/infra/transport/ssh/shell-quote.d.ts +0 -62
  166. package/lib/types/src/host/infra/transport/ssh/ssh-argv.d.ts +0 -43
  167. package/lib/types/src/host/infra/transport/ssh-argv.d.ts +0 -43
  168. package/lib/types/src/host/infra/transport/ssh2-transport.d.ts +0 -302
  169. package/lib/types/src/host/integration/agent/agent-install-io.d.ts +0 -33
  170. package/lib/types/src/host/integration/agent/askpass-registry.d.ts +0 -66
  171. package/lib/types/src/host/integration/agent-install-io.d.ts +0 -33
  172. package/lib/types/src/host/integration/agent-preflight.d.ts +0 -56
  173. package/lib/types/src/host/integration/anchor-directory.d.ts +0 -56
  174. package/lib/types/src/host/integration/askpass-registry.d.ts +0 -59
  175. package/lib/types/src/host/integration/bin-root-resolver.d.ts +0 -81
  176. package/lib/types/src/host/integration/connection-test.d.ts +0 -73
  177. package/lib/types/src/host/integration/file-reference-provider.d.ts +0 -115
  178. package/lib/types/src/host/integration/fs/git-status-wiring.d.ts +0 -21
  179. package/lib/types/src/host/integration/fs/platform-errors.d.ts +0 -94
  180. package/lib/types/src/host/integration/fs/remote-file-tools.d.ts +0 -369
  181. package/lib/types/src/host/integration/fs/remote-index.d.ts +0 -177
  182. package/lib/types/src/host/integration/fs-provider.d.ts +0 -226
  183. package/lib/types/src/host/integration/lsp/lsp-framing.d.ts +0 -38
  184. package/lib/types/src/host/integration/lsp/lsp-registry.d.ts +0 -67
  185. package/lib/types/src/host/integration/lsp/lsp-session.d.ts +0 -130
  186. package/lib/types/src/host/integration/management-tools.d.ts +0 -64
  187. package/lib/types/src/host/integration/recycle-bin-service.d.ts +0 -247
  188. package/lib/types/src/host/integration/remote/connection-test.d.ts +0 -73
  189. package/lib/types/src/host/integration/remote/remote-face.d.ts +0 -127
  190. package/lib/types/src/host/integration/remote/remote-tool-backend.d.ts +0 -108
  191. package/lib/types/src/host/integration/remote-face.d.ts +0 -127
  192. package/lib/types/src/host/integration/remote-file-tools.d.ts +0 -241
  193. package/lib/types/src/host/integration/remote-home.d.ts +0 -69
  194. package/lib/types/src/host/integration/remote-index.d.ts +0 -165
  195. package/lib/types/src/host/integration/remote-job-tools.d.ts +0 -295
  196. package/lib/types/src/host/integration/remote-tool-backend.d.ts +0 -97
  197. package/lib/types/src/host/integration/remote-tools.d.ts +0 -206
  198. package/lib/types/src/host/integration/root-registry.d.ts +0 -115
  199. package/lib/types/src/host/integration/roots/anchor-directory.d.ts +0 -56
  200. package/lib/types/src/host/integration/roots/bin-root-resolver.d.ts +0 -81
  201. package/lib/types/src/host/integration/roots/remote-home.d.ts +0 -69
  202. package/lib/types/src/host/integration/roots/root-registry.d.ts +0 -144
  203. package/lib/types/src/host/integration/roots/roots-wiring.d.ts +0 -219
  204. package/lib/types/src/host/integration/roots/session-root-index.d.ts +0 -52
  205. package/lib/types/src/host/integration/roots-api.d.ts +0 -407
  206. package/lib/types/src/host/integration/roots-wiring.d.ts +0 -211
  207. package/lib/types/src/host/integration/session/session-api.d.ts +0 -88
  208. package/lib/types/src/host/integration/session/session-bin-lock.d.ts +0 -80
  209. package/lib/types/src/host/integration/session/session-header.d.ts +0 -151
  210. package/lib/types/src/host/integration/session/session-labels.d.ts +0 -56
  211. package/lib/types/src/host/integration/session/session-route-wiring.d.ts +0 -50
  212. package/lib/types/src/host/integration/session-admin-service.d.ts +0 -236
  213. package/lib/types/src/host/integration/session-api.d.ts +0 -81
  214. package/lib/types/src/host/integration/session-bin-lock.d.ts +0 -80
  215. package/lib/types/src/host/integration/session-header.d.ts +0 -118
  216. package/lib/types/src/host/integration/session-labels.d.ts +0 -56
  217. package/lib/types/src/host/integration/session-route-wiring.d.ts +0 -50
  218. package/lib/types/src/host/integration/session-scope.d.ts +0 -113
  219. package/lib/types/src/host/integration/session-tools.d.ts +0 -44
  220. package/lib/types/src/host/integration/strict-arguments.d.ts +0 -79
  221. package/lib/types/src/host/integration/takeover/takeover-api.d.ts +0 -62
  222. package/lib/types/src/host/integration/takeover/takeover-route-wiring.d.ts +0 -60
  223. package/lib/types/src/host/integration/takeover/takeover-service.d.ts +0 -167
  224. package/lib/types/src/host/integration/terminal-manifest.d.ts +0 -94
  225. package/lib/types/src/host/integration/tools/management-tools.d.ts +0 -245
  226. package/lib/types/src/host/integration/tools/remote-job-tools.d.ts +0 -316
  227. package/lib/types/src/host/integration/tools/remote-lsp-tools.d.ts +0 -43
  228. package/lib/types/src/host/integration/tools/remote-tools.d.ts +0 -236
  229. package/lib/types/src/host/integration/tools/session-target.d.ts +0 -52
  230. package/lib/types/src/host/integration/tools/session-tools.d.ts +0 -46
  231. package/lib/types/src/host/integration/tools/strict-arguments.d.ts +0 -79
  232. package/lib/types/src/host/integration/tools/terminal-manifest.d.ts +0 -94
  233. package/lib/types/src/host/integration/transfer/remote-copy.d.ts +0 -66
  234. package/lib/types/src/host/integration/transfer/transfer-adapters.d.ts +0 -48
  235. package/lib/types/src/host/integration/transfer/transfer-tracker.d.ts +0 -106
  236. package/lib/types/src/host/integration/transfer-adapters.d.ts +0 -44
  237. package/lib/types/src/host/integration/transfer-service.d.ts +0 -164
  238. package/lib/types/src/host/integration/transfer-tracker.d.ts +0 -106
  239. package/lib/types/src/host/integration/user-roots.d.ts +0 -461
  240. package/lib/types/src/wiring/connections.d.ts +0 -189
  241. package/lib/types/src/wiring/fs.d.ts +0 -13
  242. package/lib/types/src/wiring/install-memo.d.ts +0 -32
  243. package/lib/types/src/wiring/legacy-dirs.d.ts +0 -62
  244. package/lib/types/src/wiring/package-paths.d.ts +0 -35
  245. package/lib/types/src/wiring/roots.d.ts +0 -21
  246. package/lib/types/src/wiring/state-dir.d.ts +0 -29
  247. package/lib/types/src/wiring/tools.d.ts +0 -35
@@ -1,41 +0,0 @@
1
- /**
2
- * 代理协议的**错误与截止层**:错误归一、请求取消/超时、致命失败判定。
3
- *
4
- * 从 `agent-protocol-client.ts` 拆出(审计 0079)。客户端与传输层都需要"这个失败还要不要继续",
5
- * 判定放在这里,避免两边各写一份。
6
- *
7
- * @module dsh-over-ssh/infra/transport/agent-protocol-errors
8
- */
9
- import { SshDevError } from '../../../domain/errors.ts';
10
- export declare function toSshDev(error: unknown, method: string): SshDevError;
11
- /** Internal marker: the caller's signal aborted while waiting. */
12
- export declare class RequestAbortedError extends Error {
13
- }
14
- /** Internal marker: the per-request deadline expired. */
15
- export declare class RequestTimeoutError extends Error {
16
- readonly timeoutMs: number;
17
- constructor(timeoutMs: number);
18
- }
19
- /**
20
- * Await `promise` under a deadline and an abort signal.
21
- *
22
- * The timer is always cleared and the abort listener always removed, so no path leaves a dangling
23
- * handle behind; the first settlement wins. `onTimeout` / `onAbort` let a caller name the error that
24
- * fits its context (a request deadline versus a missing blob frame).
25
- */
26
- export declare function withDeadlineAndAbort<T>(promise: Promise<T>, options: {
27
- readonly signal?: AbortSignal;
28
- readonly timeoutMs: number;
29
- readonly method: string;
30
- readonly onTimeout?: (timeoutMs: number) => Error;
31
- readonly onAbort?: () => Error;
32
- }): {
33
- readonly promise: Promise<T>;
34
- readonly cancel: () => void;
35
- };
36
- /** Largest server-side wait the agent accepts for `proc.status` / `proc.output` (`waitMs`).
37
- *
38
- * Distinct from `MAX_JOB_WAIT_MS` in `remote-job-tools.ts`: that one is the **client's** overall wait budget
39
- * (10 min); this one is the **server's** single-request cap (30 s). */
40
- export declare function isFatalAgentFailure(error: SshDevError): boolean;
41
- //# sourceMappingURL=agent-protocol-errors.d.ts.map
@@ -1,197 +0,0 @@
1
- /**
2
- * 代理协议的**帧层**:常量、错误类型、JSON/Blob 帧编解码、流式解析器与错误映射。
3
- *
4
- * 从 `agent-transport.ts` 拆出(审计 0077):这一层只关心字节与帧,不知道连接、会话或传输。
5
- * 边界由用户要求先定:**协议层(帧/类型/客户端)与传输适配层分开**。
6
- *
7
- * @module dsh-over-ssh/infra/transport/agent-protocol-frames
8
- */
9
- import { SshDevError } from '../../../domain/errors.ts';
10
- /**
11
- * The `agent` transport (Tier 2): the plugin side of the self-hosted Go remote agent.
12
- *
13
- * Why a third implementation exists at all: the zero-install floor (Tier 1: plain POSIX commands over
14
- * `ssh`) cannot provide native file watching, server-side indexing, or long tasks. The optional agent
15
- * binary adds them *without* becoming a requirement — when it is missing, outdated, or refuses the
16
- * handshake, the caller falls back to Tier 1 instead of degrading silently.
17
- *
18
- * Deployment constraints this module is written against:
19
- *
20
- * - the agent is an **optional** single static binary (`doc/02-platform/zero-install-boundaries.md`);
21
- * - it speaks only over the **stdio channel** of an `ssh` command (`ssh <alias> <agent> --stdio`),
22
- * listening on no port (`doc/02-platform/remote-footprint.md`);
23
- * - the wire protocol is a **single evolving spec** (`dsh-over-ssh-agent/doc/01-product/protocol.md`); there is no
24
- * frozen/next split, so the frame codec below follows that file field by field instead of inventing a
25
- * friendlier one — and when that file changes, this codec changes with it in the same round.
26
- *
27
- * Three consequences of the current wire shape are visible in this file and are **not** temporary
28
- * workarounds to be "cleaned up" later:
29
- *
30
- * 1. **there is no arbitrary command execution in the protocol's core surface.** The agent's method
31
- * dispatch serves `proc.exec` only when the capability bit says so (verified by reading
32
- * `internal/agent/server.go`), so {@link AgentTransport.exec} needs
33
- * an injected {@link AgentExecCommand}; without one it asks `proc.exec` and turns `E_METHOD` into
34
- * `REMOTE_UNSUPPORTED` with a message saying this agent version cannot run commands.
35
- * 2. **`fs.write` has `expectedVersion` but no digest.** The `Transport` contract's
36
- * `expectedSha256` is therefore honoured as a *version* guard (stat, compare, then write with the
37
- * same version as `expectedVersion`) — never as a digest guard — and that distinction is reported.
38
- * 3. **a control frame is paired with its blob by *order*, not by id.** ADR-0009 made the agent dispatch
39
- * requests concurrently, so responses may arrive out of order; what the agent still guarantees is
40
- * that a response and the blob it declared are written back-to-back inside one critical section. Blob
41
- * frames therefore arrive in the same order as the responses that declared them, which is what lets
42
- * this client pipeline up to {@link DEFAULT_AGENT_MAX_IN_FLIGHT} requests while pairing each blob with
43
- * its own request (see {@link AgentProtocolClient}).
44
- *
45
- * No third-party dependency is involved: the session is injected (`AgentLauncher`), so every unit test
46
- * runs against an in-memory fake and `node:child_process` is only reached by {@link defaultLauncher}.
47
- *
48
- * @module dsh-over-ssh/infra/transport/agent-transport
49
- */
50
- /** Protocol version this client speaks; must equal the agent's `protocol.ProtocolVersion`. */
51
- export declare const AGENT_PROTOCOL_VERSION = 1;
52
- /** Client identifier sent in `hello.params.client`; diagnostic only, the agent never branches on it. */
53
- export declare const AGENT_CLIENT_ID = "dsh-over-ssh/0.1.0";
54
- /** Single-frame payload ceiling, mirrored from the agent's `protocol.MaxFrameBytes` (16 MiB). */
55
- export declare const MAX_AGENT_FRAME_BYTES: number;
56
- /** Frame kind byte: control frame carrying one JSON request or one JSON response. */
57
- export declare const AGENT_KIND_JSON = 74;
58
- /** Frame kind byte: binary data frame (file content), sent only after a blob-declaring control frame. */
59
- export declare const AGENT_KIND_BLOB = 66;
60
- /**
61
- * The watcher name the agent uses when a caller omits `watcherId`.
62
- *
63
- * Mirrors the agent's `watch.DefaultWatcherID`. Kept client-side so a result from an agent that predates
64
- * the `watcherId` echo still reports which watcher it actually touched (that agent had exactly one).
65
- */
66
- export declare const DEFAULT_AGENT_WATCHER_ID = "default";
67
- /** Default per-request deadline used when the caller names none. */
68
- export declare const DEFAULT_AGENT_REQUEST_TIMEOUT_MS = 15000;
69
- /**
70
- * How many requests the client may keep in flight on one connection.
71
- *
72
- * Mirrors the agent's own `MaxInFlightRequests` (8): the agent acquires one slot per request *in its read
73
- * goroutine*, so sending more than that would stall its reads instead of buying throughput. Staying at the
74
- * agent's limit keeps the pipeline full without ever blocking the peer's reader.
75
- */
76
- export declare const DEFAULT_AGENT_MAX_IN_FLIGHT = 8;
77
- /**
78
- * Default agent mode flag.
79
- *
80
- * `--shared` lets one resident agent process serve many sessions (shared jobs / LSP / index snapshots)
81
- * and falls back to the in-process loop when a daemon is unavailable. `--stdio` pins the old
82
- * one-process-per-connection behaviour, which tests and diagnostics still use.
83
- */
84
- export declare const DEFAULT_AGENT_MODE = "--shared";
85
- /** The pinned in-process mode (one agent process per connection). */
86
- export declare const STDIO_AGENT_MODE = "--stdio";
87
- /** A structured failure reported by the agent (or synthesised by this client). */
88
- export declare class AgentProtocolError extends Error {
89
- readonly code: string;
90
- readonly details: Readonly<Record<string, unknown>>;
91
- constructor(code: string, message: string, details?: Readonly<Record<string, unknown>>);
92
- }
93
- /**
94
- * The narrow view of one agent session this module needs.
95
- *
96
- * Deliberately tiny so a fake is trivial and so the module never touches `node:child_process` itself:
97
- * `onData` delivers stdout bytes **in arrival order** (frame boundaries are not preserved), `onExit`
98
- * fires once when the remote process is gone.
99
- */
100
- export interface AgentFrame {
101
- /** Kind byte: {@link AGENT_KIND_JSON} or {@link AGENT_KIND_BLOB}. */
102
- readonly kind: number;
103
- /** Payload bytes, copied out of the transport buffer. */
104
- readonly payload: Uint8Array;
105
- }
106
- /** One encoded frame, split into its two written halves. */
107
- export interface EncodedFrame {
108
- /** The 5-byte `[kind][uint32 BE length]` header. */
109
- readonly header: Uint8Array;
110
- /** The payload (`header[4]` is its length). */
111
- readonly payload: Uint8Array;
112
- }
113
- /**
114
- * Encode one frame: `[1B kind][4B BE length][payload]`.
115
- *
116
- * @throws AgentProtocolError `E_PROTOCOL` for an unknown kind byte.
117
- * @throws AgentProtocolError `E_TOO_LARGE` when the payload exceeds {@link MAX_AGENT_FRAME_BYTES}.
118
- */
119
- export declare function encodeFrame(kind: number, payload: Uint8Array): EncodedFrame;
120
- /** Encode one complete frame (header immediately followed by payload). */
121
- export declare function encodeFrameBytes(kind: number, payload: Uint8Array): Uint8Array;
122
- /**
123
- * Decode exactly one frame from the head of `bytes`.
124
- *
125
- * @returns the frame plus `consumed` (header + payload) bytes, or `null` when the buffer holds only
126
- * part of a frame — callers keep the remainder and retry, which is how a chunked stream is framed.
127
- * @throws AgentProtocolError `E_PROTOCOL` for an illegal kind byte; `E_TOO_LARGE` when the declared
128
- * length exceeds the ceiling (rejected before allocating, exactly like the agent's own reader).
129
- */
130
- export declare function decodeFrame(bytes: Uint8Array): {
131
- readonly frame: AgentFrame;
132
- readonly consumed: number;
133
- } | null;
134
- /**
135
- * Incremental frame decoder over a byte stream that arrives in arbitrary chunks.
136
- *
137
- * **Why it keeps a read cursor instead of trimming the buffer on every frame.** The obvious implementation
138
- * (`buffer = concat(buffer, chunk)` then `buffer = buffer.slice(consumed)` per frame) re-copies the whole
139
- * remaining payload once per chunk *and* once per frame, so a body that arrives in many small pieces costs
140
- * O(bytes x pieces). Measured on this repository: an 8 MiB blob delivered in 64 KiB chunks spent **142 ms**
141
- * of synchronous main-thread time versus **5.1 ms** when it arrived in one piece (audit 0043) — and doubling
142
- * the number of chunks doubled the cost, which is the signature of the quadratic term. Every one of those
143
- * milliseconds is a stalled event loop, i.e. a stalled GUI.
144
- *
145
- * Two changes were needed, and the measurement is what proved the first one alone was **not** enough:
146
- *
147
- * 1. the frame loop reads through a window (`#start`/`#end` over one store) instead of copying the remainder
148
- * per frame;
149
- * 2. the store grows **geometrically** (doubling) instead of being reallocated at exactly `pending + chunk`
150
- * on every chunk.
151
- *
152
- * (1) alone still measured 126 ms: an exactly-sized `Uint8Array` per 64 KiB chunk copies the whole body every
153
- * time, so the cost stays O(bytes x chunks). With both, the same 8 MiB body measured **9.3 ms** and the cost
154
- * became flat in the chunk size (9.3 / 10.3 / 7.3 / 5.5 ms for 64 KiB … 8 MiB chunks) — linear, where before
155
- * doubling the chunk count doubled the time. Both changes matter; neither is sufficient alone.
156
- */
157
- export declare class AgentFrameParser {
158
- #private;
159
- /**
160
- * Feed one chunk; returns every frame that became complete, in arrival order.
161
- *
162
- * @param chunk - the bytes that just arrived; any split point is legal.
163
- * @returns the complete frames, in arrival order.
164
- */
165
- push(chunk: Uint8Array): readonly AgentFrame[];
166
- /** Bytes retained for an incomplete frame (0 when the stream is aligned). */
167
- get pendingBytes(): number;
168
- }
169
- /**
170
- * Map an agent error code onto a plugin error code.
171
- *
172
- * Centralised on purpose: this table is part of the contract with the agent, and every entry is
173
- * asserted by `tests/agent-transport.test.ts`.
174
- *
175
- * Two entries deserve their reasoning stated:
176
- *
177
- * - `E_HANDSHAKE` / `E_PROTOCOL` mean "this stream cannot be trusted" (wrong protocol version, frames
178
- * out of order), so they surface as `CONNECTION_LOST`: the connection is unusable, not the request.
179
- * - `E_TOO_LARGE` is **one code with two meanings**, so it is mapped by `details.scope`:
180
- * a **size** limit (`scope: "size"`, or absent on an older agent) becomes `REMOTE_UNSUPPORTED`
181
- * because v1 has no chunked read to fall back on — the request itself is too big;
182
- * a **capacity** limit (`scope: "session" | "job" | "lsp" | "watcher"`) becomes
183
- * `REMOTE_COMMAND_FAILED`, because nothing is wrong with the request — the remote is momentarily
184
- * full and retrying later is the right move.
185
- *
186
- * Why the split matters: mapping capacity exhaustion to `REMOTE_UNSUPPORTED` used to make it reach
187
- * the filesystem layer as `FS_NOT_REGULAR_FILE` ("this is not a regular file"), which points a
188
- * caller at the wrong thing entirely. Measured end to end (`.verify/stage8-too-large-conflation.mjs`):
189
- * 200 slow requests on one session ⇒ 128 rejected with `E_TOO_LARGE` + `scope: "session"` ⇒
190
- * surfaced as `FS_NOT_REGULAR_FILE`.
191
- *
192
- * An unrecognised code (a newer agent) is reported as `REMOTE_COMMAND_FAILED` with the original code
193
- * kept in `details.agentCode`, so a new agent error is never silently mistranslated into a known one.
194
- */
195
- export declare function agentErrorToSshDev(error: AgentProtocolError, connectionId: string): SshDevError;
196
- /** Client-side default for `index.scan` `maxEntries`; mirrors the agent's `index.DefaultMaxEntries`. */
197
- //# sourceMappingURL=agent-protocol-frames.d.ts.map