dsh-over-ssh 0.1.0 → 0.2.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 (250) hide show
  1. package/README.md +19 -17
  2. package/agents/agent-manifest.json +6 -6
  3. package/agents/linux-amd64/dsh-over-ssh-agent +0 -0
  4. package/agents/linux-arm64/dsh-over-ssh-agent +0 -0
  5. package/lib/client.js +422 -337
  6. package/lib/file-references.js +92 -35
  7. package/lib/fs.js +295 -113
  8. package/lib/index.js +6912 -4330
  9. package/lib/terminal-wrapper.js +9 -4
  10. package/lib/types/src/config.d.ts +156 -9
  11. package/lib/types/src/file-references.d.ts +0 -1
  12. package/lib/types/src/host/app/backend.d.ts +44 -3
  13. package/lib/types/src/host/app/recycle-bin/recycle-bin-contract.d.ts +0 -1
  14. package/lib/types/src/host/app/recycle-bin/recycle-bin-service.d.ts +0 -1
  15. package/lib/types/src/host/app/session-admin/session-admin-contract.d.ts +12 -1
  16. package/lib/types/src/host/app/session-admin/session-admin-service.d.ts +0 -1
  17. package/lib/types/src/host/app/transport/transport-selector.d.ts +0 -1
  18. package/lib/types/src/host/app/transport/transport-service.d.ts +0 -1
  19. package/lib/types/src/host/domain/capability.d.ts +0 -1
  20. package/lib/types/src/host/domain/errors.d.ts +0 -1
  21. package/lib/types/src/host/domain/roots/connection.d.ts +0 -1
  22. package/lib/types/src/host/domain/roots/root.d.ts +24 -9
  23. package/lib/types/src/host/domain/roots/session-roots.d.ts +23 -1
  24. package/lib/types/src/host/domain/roots/ssh-config.d.ts +0 -1
  25. package/lib/types/src/host/domain/session/session-admin.d.ts +0 -1
  26. package/lib/types/src/host/domain/transfer/recycle-bin.d.ts +0 -1
  27. package/lib/types/src/host/domain/transfer/transfer.d.ts +0 -1
  28. package/lib/types/src/host/infra/transport/agent/agent-installer.d.ts +0 -1
  29. package/lib/types/src/host/infra/transport/forward.d.ts +75 -0
  30. package/lib/types/src/host/infra/transport/ssh/ssh2-transport.d.ts +5 -1
  31. package/lib/types/src/host/infra/transport/transport-base.d.ts +0 -1
  32. package/lib/types/src/host/infra/transport/transport.d.ts +42 -2
  33. package/lib/types/src/host/integration/agent/agent-preflight.d.ts +0 -1
  34. package/lib/types/src/host/integration/fs/file-reference-provider.d.ts +0 -1
  35. package/lib/types/src/host/integration/fs/fs-provider.d.ts +18 -3
  36. package/lib/types/src/host/integration/transfer/transfer-service.d.ts +0 -1
  37. package/lib/types/src/index.d.ts +23 -1
  38. package/lib/types/src/local-bridge-refs.d.ts +0 -1
  39. package/lib/types/src/local-bridge.d.ts +0 -1
  40. package/lib/types/src/shared/root-keys.d.ts +120 -0
  41. package/lib/types/src/wiring/helpers.d.ts +0 -1
  42. package/package.json +5 -3
  43. package/lib/types/src/client/controls.d.ts +0 -131
  44. package/lib/types/src/client/core/card-focus-trap.d.ts +0 -45
  45. package/lib/types/src/client/core/controls.d.ts +0 -164
  46. package/lib/types/src/client/core/latest.d.ts +0 -48
  47. package/lib/types/src/client/core/locale.d.ts +0 -38
  48. package/lib/types/src/client/core/message.d.ts +0 -37
  49. package/lib/types/src/client/core/panel-model.d.ts +0 -134
  50. package/lib/types/src/client/core/portal.d.ts +0 -266
  51. package/lib/types/src/client/core/remote.d.ts +0 -84
  52. package/lib/types/src/client/core/styles.d.ts +0 -458
  53. package/lib/types/src/client/file-tree-io.d.ts +0 -19
  54. package/lib/types/src/client/file-tree.d.ts +0 -271
  55. package/lib/types/src/client/flows/directory-browser.d.ts +0 -587
  56. package/lib/types/src/client/flows/session-directory.d.ts +0 -415
  57. package/lib/types/src/client/flows/workspace-directory-flow.d.ts +0 -480
  58. package/lib/types/src/client/locale.d.ts +0 -31
  59. package/lib/types/src/client/panel-model.d.ts +0 -37
  60. package/lib/types/src/client/panel.d.ts +0 -77
  61. package/lib/types/src/client/roots/connection-test.d.ts +0 -69
  62. package/lib/types/src/client/roots/roots-panel-state.d.ts +0 -307
  63. package/lib/types/src/client/roots/roots-panel-view.d.ts +0 -280
  64. package/lib/types/src/client/roots/roots-panel.d.ts +0 -364
  65. package/lib/types/src/client/roots/transfer-panel-view.d.ts +0 -35
  66. package/lib/types/src/client/roots/transfer-panel.d.ts +0 -241
  67. package/lib/types/src/client/roots/transfer-progress.d.ts +0 -67
  68. package/lib/types/src/client/roots-panel-view.d.ts +0 -236
  69. package/lib/types/src/client/roots-panel.d.ts +0 -347
  70. package/lib/types/src/client/session/session-panel-view.d.ts +0 -336
  71. package/lib/types/src/client/session/session-panel.d.ts +0 -322
  72. package/lib/types/src/client/session/session-remote-mark.d.ts +0 -110
  73. package/lib/types/src/client/session/session-row-actions.d.ts +0 -398
  74. package/lib/types/src/client/session-panel.d.ts +0 -152
  75. package/lib/types/src/client/styles.d.ts +0 -252
  76. package/lib/types/src/client/workspace-directory-flow.d.ts +0 -342
  77. package/lib/types/src/fs.d.ts +0 -46
  78. package/lib/types/src/host/app/recycle-bin/recycle-bin-move.d.ts +0 -18
  79. package/lib/types/src/host/app/recycle-bin/recycle-bin-world.d.ts +0 -38
  80. package/lib/types/src/host/app/recycle-bin-contract.d.ts +0 -215
  81. package/lib/types/src/host/app/recycle-bin-move.d.ts +0 -18
  82. package/lib/types/src/host/app/recycle-bin-service.d.ts +0 -45
  83. package/lib/types/src/host/app/recycle-bin-world.d.ts +0 -35
  84. package/lib/types/src/host/app/roots/roots-api-connections.d.ts +0 -49
  85. package/lib/types/src/host/app/roots/roots-api-contract.d.ts +0 -369
  86. package/lib/types/src/host/app/roots/roots-api-directories.d.ts +0 -13
  87. package/lib/types/src/host/app/roots/roots-api-http.d.ts +0 -77
  88. package/lib/types/src/host/app/roots/roots-api-long-poll.d.ts +0 -130
  89. package/lib/types/src/host/app/roots/roots-api-projections.d.ts +0 -102
  90. package/lib/types/src/host/app/roots/roots-api-roots.d.ts +0 -13
  91. package/lib/types/src/host/app/roots/roots-api-state.d.ts +0 -22
  92. package/lib/types/src/host/app/roots/roots-api-transfers.d.ts +0 -26
  93. package/lib/types/src/host/app/roots/roots-api.d.ts +0 -55
  94. package/lib/types/src/host/app/roots/user-roots.d.ts +0 -552
  95. package/lib/types/src/host/app/roots-api-connections.d.ts +0 -49
  96. package/lib/types/src/host/app/roots-api-contract.d.ts +0 -339
  97. package/lib/types/src/host/app/roots-api-directories.d.ts +0 -13
  98. package/lib/types/src/host/app/roots-api-http.d.ts +0 -77
  99. package/lib/types/src/host/app/roots-api-projections.d.ts +0 -102
  100. package/lib/types/src/host/app/roots-api-roots.d.ts +0 -13
  101. package/lib/types/src/host/app/roots-api-state.d.ts +0 -22
  102. package/lib/types/src/host/app/roots-api-support.d.ts +0 -182
  103. package/lib/types/src/host/app/roots-api-transfers.d.ts +0 -13
  104. package/lib/types/src/host/app/roots-api.d.ts +0 -55
  105. package/lib/types/src/host/app/routed-fs.d.ts +0 -239
  106. package/lib/types/src/host/app/serialize.d.ts +0 -37
  107. package/lib/types/src/host/app/session-admin/session-admin-context.d.ts +0 -36
  108. package/lib/types/src/host/app/session-admin/session-admin-delete.d.ts +0 -34
  109. package/lib/types/src/host/app/session-admin-context.d.ts +0 -36
  110. package/lib/types/src/host/app/session-admin-contract.d.ts +0 -214
  111. package/lib/types/src/host/app/session-admin-delete.d.ts +0 -34
  112. package/lib/types/src/host/app/session-admin-service.d.ts +0 -38
  113. package/lib/types/src/host/app/takeover/takeover-plan.d.ts +0 -227
  114. package/lib/types/src/host/app/takeover/takeover-rows.d.ts +0 -55
  115. package/lib/types/src/host/app/transport-selector.d.ts +0 -98
  116. package/lib/types/src/host/app/transport-service.d.ts +0 -75
  117. package/lib/types/src/host/app/user-roots.d.ts +0 -461
  118. package/lib/types/src/host/domain/bin-location.d.ts +0 -79
  119. package/lib/types/src/host/domain/connection.d.ts +0 -95
  120. package/lib/types/src/host/domain/glob-pattern.d.ts +0 -62
  121. package/lib/types/src/host/domain/literal-text.d.ts +0 -63
  122. package/lib/types/src/host/domain/path-grammar.d.ts +0 -84
  123. package/lib/types/src/host/domain/recycle-bin.d.ts +0 -337
  124. package/lib/types/src/host/domain/root.d.ts +0 -74
  125. package/lib/types/src/host/domain/roots/bin-location.d.ts +0 -91
  126. package/lib/types/src/host/domain/roots/route-table.d.ts +0 -102
  127. package/lib/types/src/host/domain/route-table.d.ts +0 -80
  128. package/lib/types/src/host/domain/session/terminal-target.d.ts +0 -136
  129. package/lib/types/src/host/domain/session-admin.d.ts +0 -330
  130. package/lib/types/src/host/domain/shell.d.ts +0 -47
  131. package/lib/types/src/host/domain/ssh-config.d.ts +0 -73
  132. package/lib/types/src/host/domain/terminal-target.d.ts +0 -132
  133. package/lib/types/src/host/domain/tool-requests.d.ts +0 -369
  134. package/lib/types/src/host/domain/transfer.d.ts +0 -260
  135. package/lib/types/src/host/infra/backend/local-backend.d.ts +0 -84
  136. package/lib/types/src/host/infra/backend/local-version.d.ts +0 -43
  137. package/lib/types/src/host/infra/backend/platform-local-backend.d.ts +0 -89
  138. package/lib/types/src/host/infra/backend/remote-backend.d.ts +0 -239
  139. package/lib/types/src/host/infra/cache/lru.d.ts +0 -52
  140. package/lib/types/src/host/infra/cache/versioned.d.ts +0 -77
  141. package/lib/types/src/host/infra/temp-name.d.ts +0 -19
  142. package/lib/types/src/host/infra/transport/agent/agent-protocol-client.d.ts +0 -132
  143. package/lib/types/src/host/infra/transport/agent/agent-protocol-codec.d.ts +0 -140
  144. package/lib/types/src/host/infra/transport/agent/agent-protocol-errors.d.ts +0 -41
  145. package/lib/types/src/host/infra/transport/agent/agent-protocol-frames.d.ts +0 -197
  146. package/lib/types/src/host/infra/transport/agent/agent-protocol-types.d.ts +0 -564
  147. package/lib/types/src/host/infra/transport/agent/agent-transport.d.ts +0 -418
  148. package/lib/types/src/host/infra/transport/agent-installer.d.ts +0 -121
  149. package/lib/types/src/host/infra/transport/agent-protocol-client.d.ts +0 -123
  150. package/lib/types/src/host/infra/transport/agent-protocol-codec.d.ts +0 -131
  151. package/lib/types/src/host/infra/transport/agent-protocol-errors.d.ts +0 -41
  152. package/lib/types/src/host/infra/transport/agent-protocol-frames.d.ts +0 -197
  153. package/lib/types/src/host/infra/transport/agent-protocol-types.d.ts +0 -509
  154. package/lib/types/src/host/infra/transport/agent-transport.d.ts +0 -353
  155. package/lib/types/src/host/infra/transport/alias-transport.d.ts +0 -206
  156. package/lib/types/src/host/infra/transport/askpass-fs.d.ts +0 -20
  157. package/lib/types/src/host/infra/transport/askpass.d.ts +0 -133
  158. package/lib/types/src/host/infra/transport/command-pool.d.ts +0 -61
  159. package/lib/types/src/host/infra/transport/fs-commands.d.ts +0 -140
  160. package/lib/types/src/host/infra/transport/git-status-route.d.ts +0 -63
  161. package/lib/types/src/host/infra/transport/git-status.d.ts +0 -101
  162. package/lib/types/src/host/infra/transport/node-spawn.d.ts +0 -26
  163. package/lib/types/src/host/infra/transport/session-window.d.ts +0 -51
  164. package/lib/types/src/host/infra/transport/shell-quote.d.ts +0 -59
  165. package/lib/types/src/host/infra/transport/ssh/alias-transport.d.ts +0 -206
  166. package/lib/types/src/host/infra/transport/ssh/askpass-fs.d.ts +0 -20
  167. package/lib/types/src/host/infra/transport/ssh/askpass.d.ts +0 -133
  168. package/lib/types/src/host/infra/transport/ssh/shell-quote.d.ts +0 -62
  169. package/lib/types/src/host/infra/transport/ssh/ssh-argv.d.ts +0 -43
  170. package/lib/types/src/host/infra/transport/ssh-argv.d.ts +0 -43
  171. package/lib/types/src/host/infra/transport/ssh2-transport.d.ts +0 -302
  172. package/lib/types/src/host/integration/agent/agent-install-io.d.ts +0 -33
  173. package/lib/types/src/host/integration/agent/askpass-registry.d.ts +0 -66
  174. package/lib/types/src/host/integration/agent-install-io.d.ts +0 -33
  175. package/lib/types/src/host/integration/agent-preflight.d.ts +0 -56
  176. package/lib/types/src/host/integration/anchor-directory.d.ts +0 -56
  177. package/lib/types/src/host/integration/askpass-registry.d.ts +0 -59
  178. package/lib/types/src/host/integration/bin-root-resolver.d.ts +0 -81
  179. package/lib/types/src/host/integration/connection-test.d.ts +0 -73
  180. package/lib/types/src/host/integration/file-reference-provider.d.ts +0 -115
  181. package/lib/types/src/host/integration/fs/git-status-wiring.d.ts +0 -21
  182. package/lib/types/src/host/integration/fs/platform-errors.d.ts +0 -94
  183. package/lib/types/src/host/integration/fs/remote-file-tools.d.ts +0 -369
  184. package/lib/types/src/host/integration/fs/remote-index.d.ts +0 -177
  185. package/lib/types/src/host/integration/fs-provider.d.ts +0 -226
  186. package/lib/types/src/host/integration/lsp/lsp-framing.d.ts +0 -38
  187. package/lib/types/src/host/integration/lsp/lsp-registry.d.ts +0 -67
  188. package/lib/types/src/host/integration/lsp/lsp-session.d.ts +0 -130
  189. package/lib/types/src/host/integration/management-tools.d.ts +0 -64
  190. package/lib/types/src/host/integration/recycle-bin-service.d.ts +0 -247
  191. package/lib/types/src/host/integration/remote/connection-test.d.ts +0 -73
  192. package/lib/types/src/host/integration/remote/remote-face.d.ts +0 -127
  193. package/lib/types/src/host/integration/remote/remote-tool-backend.d.ts +0 -108
  194. package/lib/types/src/host/integration/remote-face.d.ts +0 -127
  195. package/lib/types/src/host/integration/remote-file-tools.d.ts +0 -241
  196. package/lib/types/src/host/integration/remote-home.d.ts +0 -69
  197. package/lib/types/src/host/integration/remote-index.d.ts +0 -165
  198. package/lib/types/src/host/integration/remote-job-tools.d.ts +0 -295
  199. package/lib/types/src/host/integration/remote-tool-backend.d.ts +0 -97
  200. package/lib/types/src/host/integration/remote-tools.d.ts +0 -206
  201. package/lib/types/src/host/integration/root-registry.d.ts +0 -115
  202. package/lib/types/src/host/integration/roots/anchor-directory.d.ts +0 -56
  203. package/lib/types/src/host/integration/roots/bin-root-resolver.d.ts +0 -81
  204. package/lib/types/src/host/integration/roots/remote-home.d.ts +0 -69
  205. package/lib/types/src/host/integration/roots/root-registry.d.ts +0 -144
  206. package/lib/types/src/host/integration/roots/roots-wiring.d.ts +0 -219
  207. package/lib/types/src/host/integration/roots/session-root-index.d.ts +0 -52
  208. package/lib/types/src/host/integration/roots-api.d.ts +0 -407
  209. package/lib/types/src/host/integration/roots-wiring.d.ts +0 -211
  210. package/lib/types/src/host/integration/session/session-api.d.ts +0 -88
  211. package/lib/types/src/host/integration/session/session-bin-lock.d.ts +0 -80
  212. package/lib/types/src/host/integration/session/session-header.d.ts +0 -151
  213. package/lib/types/src/host/integration/session/session-labels.d.ts +0 -56
  214. package/lib/types/src/host/integration/session/session-route-wiring.d.ts +0 -50
  215. package/lib/types/src/host/integration/session-admin-service.d.ts +0 -236
  216. package/lib/types/src/host/integration/session-api.d.ts +0 -81
  217. package/lib/types/src/host/integration/session-bin-lock.d.ts +0 -80
  218. package/lib/types/src/host/integration/session-header.d.ts +0 -118
  219. package/lib/types/src/host/integration/session-labels.d.ts +0 -56
  220. package/lib/types/src/host/integration/session-route-wiring.d.ts +0 -50
  221. package/lib/types/src/host/integration/session-scope.d.ts +0 -113
  222. package/lib/types/src/host/integration/session-tools.d.ts +0 -44
  223. package/lib/types/src/host/integration/strict-arguments.d.ts +0 -79
  224. package/lib/types/src/host/integration/takeover/takeover-api.d.ts +0 -62
  225. package/lib/types/src/host/integration/takeover/takeover-route-wiring.d.ts +0 -60
  226. package/lib/types/src/host/integration/takeover/takeover-service.d.ts +0 -167
  227. package/lib/types/src/host/integration/terminal-manifest.d.ts +0 -94
  228. package/lib/types/src/host/integration/tools/management-tools.d.ts +0 -245
  229. package/lib/types/src/host/integration/tools/remote-job-tools.d.ts +0 -316
  230. package/lib/types/src/host/integration/tools/remote-lsp-tools.d.ts +0 -43
  231. package/lib/types/src/host/integration/tools/remote-tools.d.ts +0 -236
  232. package/lib/types/src/host/integration/tools/session-target.d.ts +0 -52
  233. package/lib/types/src/host/integration/tools/session-tools.d.ts +0 -46
  234. package/lib/types/src/host/integration/tools/strict-arguments.d.ts +0 -79
  235. package/lib/types/src/host/integration/tools/terminal-manifest.d.ts +0 -94
  236. package/lib/types/src/host/integration/transfer/remote-copy.d.ts +0 -66
  237. package/lib/types/src/host/integration/transfer/transfer-adapters.d.ts +0 -48
  238. package/lib/types/src/host/integration/transfer/transfer-tracker.d.ts +0 -106
  239. package/lib/types/src/host/integration/transfer-adapters.d.ts +0 -44
  240. package/lib/types/src/host/integration/transfer-service.d.ts +0 -164
  241. package/lib/types/src/host/integration/transfer-tracker.d.ts +0 -106
  242. package/lib/types/src/host/integration/user-roots.d.ts +0 -461
  243. package/lib/types/src/wiring/connections.d.ts +0 -189
  244. package/lib/types/src/wiring/fs.d.ts +0 -13
  245. package/lib/types/src/wiring/install-memo.d.ts +0 -32
  246. package/lib/types/src/wiring/legacy-dirs.d.ts +0 -62
  247. package/lib/types/src/wiring/package-paths.d.ts +0 -35
  248. package/lib/types/src/wiring/roots.d.ts +0 -21
  249. package/lib/types/src/wiring/state-dir.d.ts +0 -29
  250. package/lib/types/src/wiring/tools.d.ts +0 -35
@@ -1,98 +0,0 @@
1
- /**
2
- * Transport selection: which implementation serves a connection, and why.
3
- *
4
- * The decision is **probe-driven**, never platform-guessed (ADR-0006): a mux failure measured on
5
- * this machine is remembered, and a later decision for the same connection changes accordingly.
6
- * Everything observable about the decision is returned as a structured record so the connection
7
- * UI can show *why* a connection is slower instead of hiding it.
8
- *
9
- * @module dsh-remote-workspace/app/transport-selector
10
- */
11
- import type { ConnectionProfile, TransportKind } from '../domain/connection.ts';
12
- import type { MultiplexingCache } from '../infra/transport/transport.ts';
13
- /** Stable reasons a transport was chosen. */
14
- export type TransportReason = 'explicit-ssh2' | 'explicit-alias' | 'explicit-agent' | 'agent-unavailable' | 'password-requires-ssh2' | 'no-multiplexing' | 'ssh2-unavailable' | 'alias-required' | 'default-alias';
15
- /** A non-fatal loss of quality the user should know about. */
16
- export interface TransportDegradation {
17
- /** Stable code for the UI to branch on. */
18
- readonly code: 'no-connection-reuse' | 'ssh2-unavailable' | 'alias-unavailable' | 'password-needs-key' | 'agent-unavailable';
19
- /** Actionable, user-facing sentence. */
20
- readonly hint: string;
21
- }
22
- /** The outcome of one selection. */
23
- export interface TransportDecision {
24
- readonly connectionId: string;
25
- readonly kind: TransportKind;
26
- readonly reason: TransportReason;
27
- /** One sentence for the UI/status badge. */
28
- readonly hint: string;
29
- readonly degradations: readonly TransportDegradation[];
30
- /** Whether commands can share one connection (`false` on Windows without ssh2, for example). */
31
- readonly reusesConnection: boolean;
32
- }
33
- /** Whether the optional Tier 2 agent can serve this connection right now. */
34
- export interface AgentAvailability {
35
- /**
36
- * `false` only when a previous ladder run already failed (the reason is then required).
37
- *
38
- * `true` and `undefined` both mean "the selector cannot know yet": an explicit agent choice is honoured
39
- * optimistically and the async preflight downgrades it after running the ladder.
40
- */
41
- readonly available: boolean;
42
- /** Why it is unavailable (the ladder's reason), for the UI. */
43
- readonly reason?: string;
44
- /** One sentence for the status badge. */
45
- readonly hint?: string;
46
- }
47
- /** Facts the selector needs. All of them are injected so this module stays testable offline. */
48
- export interface TransportSelectionInput {
49
- readonly profile: ConnectionProfile;
50
- /** Whether the `ssh2` dependency is loadable in this build. */
51
- readonly ssh2Available: boolean;
52
- /** Remembers hosts whose `ssh` client cannot multiplex. */
53
- readonly multiplexing: Pick<MultiplexingCache, 'isUnsupported' | 'reasonFor'>;
54
- /** `ssh` executable name, for the multiplexing cache key. */
55
- readonly sshBinary?: string;
56
- /** Tier 2 availability. Absent means "not considered", which keeps the agent strictly opt-in. */
57
- readonly agent?: AgentAvailability;
58
- }
59
- /**
60
- * Choose a transport for one connection.
61
- *
62
- * Order of concerns: an explicit user choice wins unless it cannot work at all (password auth on
63
- * the system client, a missing dependency); only then is another implementation substituted, and
64
- * the substitution is always reported as a degradation.
65
- *
66
- * @param input - profile plus injected environment facts.
67
- * @returns the decision, including every degradation.
68
- */
69
- export declare function selectTransport(input: TransportSelectionInput): TransportDecision;
70
- /** Records observed facts so later decisions reflect reality. */
71
- export declare class TransportSelector {
72
- #private;
73
- constructor(options: {
74
- readonly multiplexing: Pick<MultiplexingCache, 'isUnsupported' | 'reasonFor'> & Partial<Pick<MultiplexingCache, 'markUnsupported'>>;
75
- readonly ssh2Available: boolean;
76
- readonly sshBinary?: string;
77
- });
78
- /** Whether the `ssh2` dependency is currently loadable. */
79
- get ssh2Available(): boolean;
80
- /** Late-bound availability (the dependency is loaded lazily). */
81
- setSsh2Available(available: boolean): void;
82
- /**
83
- * Decide for one profile.
84
- *
85
- * @param profile - the saved connection.
86
- * @returns the decision.
87
- * @throws SshDevError `CONNECTION_INVALID` when no implementation can serve the connection.
88
- */
89
- decide(profile: ConnectionProfile): TransportDecision;
90
- /**
91
- * Record that this connection's `ssh` client could not multiplex.
92
- *
93
- * Called by the integration layer right after an {@link AliasTransport} connect attempt, so the
94
- * next decision (and every other connection sharing the same client+alias) picks ssh2.
95
- */
96
- noteMultiplexingFailure(profile: ConnectionProfile, reason: string): void;
97
- }
98
- //# sourceMappingURL=transport-selector.d.ts.map
@@ -1,75 +0,0 @@
1
- /**
2
- * Transport lifecycle: acquire, reuse, replace and release one transport per connection.
3
- *
4
- * The service owns three behaviours the rest of the plugin relies on:
5
- *
6
- * 1. **One transport per connection**, created lazily and shared by every caller (single flight).
7
- * 2. **Replacement on a changed decision**: when the selector's answer changes (for example after
8
- * a mux failure is recorded), the old transport is disposed and a new one built, so a stale
9
- * decision can never keep serving traffic.
10
- * 3. **Explicit release**, so shutting a connection down closes its process/connection rather
11
- * than leaving it to the garbage collector.
12
- *
13
- * The transport contract lives in `infra/transport/transport.ts` and is imported as a type only,
14
- * which keeps this module free of implementation and of the core packages.
15
- *
16
- * @module dsh-remote-workspace/app/transport-service
17
- */
18
- import type { ConnectionProfile } from '../domain/connection.ts';
19
- import type { Transport } from '../infra/transport/transport.ts';
20
- import type { TransportDecision } from './transport-selector.ts';
21
- import type { TransportSelector } from './transport-selector.ts';
22
- /** Creates the implementation chosen by the selector. */
23
- export interface TransportFactories {
24
- readonly createAlias: (profile: ConnectionProfile, decision: TransportDecision) => Transport;
25
- readonly createSsh2: (profile: ConnectionProfile, decision: TransportDecision) => Transport;
26
- /**
27
- * Creates the Tier 2 agent transport. Optional: a build without the agent (or without a shipped binary)
28
- * simply omits it, and the selector never chooses `agent` in that case.
29
- */
30
- readonly createAgent?: (profile: ConnectionProfile, decision: TransportDecision) => Transport;
31
- }
32
- /**
33
- * Optional asynchronous step between deciding and connecting.
34
- *
35
- * The synchronous selector cannot know whether the agent's install ladder succeeded — that requires
36
- * talking to the host. A preflight therefore gets the first decision and may revise it (for example
37
- * `agent` → `alias` once the ladder reported a reason), which is how "agent unavailable ⇒ fall back to
38
- * Tier 1" is enforced *before* a transport is built.
39
- */
40
- export type TransportPreflight = (profile: ConnectionProfile, decision: TransportDecision) => Promise<TransportDecision>;
41
- /** One acquired transport plus the decision that produced it. */
42
- export interface AcquiredTransport {
43
- readonly transport: Transport;
44
- readonly decision: TransportDecision;
45
- }
46
- /** Facts injected for testability. */
47
- export interface TransportServiceOptions {
48
- readonly selector: TransportSelector;
49
- readonly factories: TransportFactories;
50
- /** See {@link TransportPreflight}. Omitted means "no revision". */
51
- readonly preflight?: TransportPreflight;
52
- }
53
- /** Owns one transport instance per connection. */
54
- export declare class TransportService {
55
- #private;
56
- constructor(options: TransportServiceOptions);
57
- /**
58
- * Get a connected transport for a profile, creating it if needed.
59
- *
60
- * @param profile - the connection to serve.
61
- * @param signal - cancellation for the connect attempt.
62
- * @returns the transport and the decision behind it (after any preflight revision).
63
- * @throws SshDevError from the selector or from the transport's own connect.
64
- */
65
- acquire(profile: ConnectionProfile, signal?: AbortSignal): Promise<AcquiredTransport>;
66
- /** The cached transport for a connection, if any. */
67
- current(connectionId: string): AcquiredTransport | undefined;
68
- /** Decisions currently in force, for the connection status UI. */
69
- decisions(): readonly TransportDecision[];
70
- /** Dispose and forget one connection. */
71
- release(connectionId: string): Promise<void>;
72
- /** Dispose every connection (plugin unload, connection-service shutdown). */
73
- disposeAll(): Promise<void>;
74
- }
75
- //# sourceMappingURL=transport-service.d.ts.map
@@ -1,461 +0,0 @@
1
- /**
2
- * User-owned roots and connections, as the **panel** may edit them.
3
- *
4
- * Two files in the plugin state directory must never be confused:
5
- *
6
- * - `roots.json` — the terminal wrapper's manifest ({@link ./terminal-manifest.ts}). It is *derived*: the
7
- * host rewrites it from the live registry after every mutation, and it contains already-resolved ssh
8
- * argv. Nothing here touches it.
9
- * - `user-roots.json` — **this module**. It is the *input*: what the user asked for in the UI, kept across
10
- * restarts so a panel can list and edit roots without the host having to re-derive them from Config.
11
- *
12
- * Shape (version 1):
13
- *
14
- * ```json
15
- * {
16
- * "version": 1,
17
- * "roots": [{ "location": "remote", "connectionId": "gpu01", "path": "/srv/work", "writable": true }],
18
- * "connections": [{ "id": "gpu01", "host": "gpu01.example.net", "user": "root", "port": 22,
19
- * "authKind": "key", "keyPath": "~/.ssh/id_ed25519" }]
20
- * }
21
- * ```
22
- *
23
- * Non-negotiables this module owns:
24
- *
25
- * 1. **Atomic writes** — temp file + `rename`, so a reader never sees a half-written document. The temp name
26
- * is unique per write: a shared `${file}.tmp` let two overlapping writers truncate each other's scratch
27
- * file and race on the `rename`.
28
- * 2. **Bad JSON never throws at the caller** — {@link parseUserRoots} returns the empty state plus a
29
- * human-readable warning; a single corrupt entry is dropped, not fatal.
30
- * 3. **No secret value, ever** — a `password` or `passphrase` **field** is refused with an error that says so
31
- * (密码不入 UI 存储). Passwords belong in `ctx.credentials`. **`authKind: 'password'` itself is accepted**:
32
- * what is stored for it is only `credentialKey`, the *name* of the stored value, and the reference is
33
- * derived from the id when the caller supplies none. (This paragraph used to claim `authKind: 'password'`
34
- * was refused while the same file's {@link normalizeConnectionEntry} accepted it — audit 0043.)
35
- * 4. **Every mutation returns a new state** and persists it; nothing mutates a shared object in place.
36
- * 5. **A connection rename takes its roots with it** ({@link updateConnectionInState}): a remote root names
37
- * its connection in its key, so an id change that left the roots behind would break them silently.
38
- * 6. **Mutations are serialised within this process** ({@link createUserRootsStore}): each one is a
39
- * read-modify-write of one document, so overlapping requests would otherwise lose updates silently.
40
- *
41
- * This module deliberately imports **no** `@deepseek-ai/*` package: it is pure I/O plus validation, and the
42
- * file system is injected so tests never touch the developer's home directory.
43
- *
44
- * @module dsh-remote-workspace/integration/user-roots
45
- */
46
- /** The only format version this module reads or writes. */
47
- export declare const USER_ROOTS_VERSION = 1;
48
- /** File name inside the plugin state directory (`~/.dsh/ssh-dev` by default in the entry). */
49
- export declare const USER_ROOTS_FILE_NAME = "user-roots.json";
50
- /** Where a user root lives. */
51
- export type UserRootLocation = 'local' | 'remote';
52
- /**
53
- * Which authentication a panel-added connection may use.
54
- *
55
- * The **secret** is what may never appear here: the validator refuses a `password` or `passphrase` field
56
- * even when it arrives as raw JSON. `password` authentication is supported, but only as a
57
- * {@link UserConnectionRecord.credentialKey} **reference** into `ctx.credentials`.
58
- */
59
- export type UserConnectionAuthKind = 'agent' | 'key' | 'password';
60
- /**
61
- * Which transport a panel-added connection asks for.
62
- *
63
- * **Not the same thing as {@link UserConnectionAuthKind}'s `agent`**, and the two must never be conflated:
64
- * `authKind: 'agent'` names the **local** ssh-agent as a credential source, while `transport: 'agent'` names
65
- * the **remote** Tier 2 Go program this plugin uploads on first connect (ADR-0005/0007). The values mirror the
66
- * host's own `TransportKind` (`domain/connection.ts`); this module keeps its own copy because it validates the
67
- * file, and `transport` is what `toProfileInput` reads to build the profile.
68
- */
69
- export type UserConnectionTransport = 'alias' | 'ssh2' | 'agent';
70
- /** One root the user added. */
71
- export interface UserRootEntry {
72
- /** Local directory or remote directory. */
73
- readonly location: UserRootLocation;
74
- /** Non-empty local path, or a POSIX absolute path for a remote root. */
75
- readonly path: string;
76
- /** Connection id; required exactly for remote roots. */
77
- readonly connectionId?: string;
78
- /** Display label shown by the panel. */
79
- readonly label?: string;
80
- /** Whether writes under this root are allowed; the panel's default is `true`. */
81
- readonly writable?: boolean;
82
- /**
83
- * The workspaces this root was added **to** (canonical local paths).
84
- *
85
- * **Absent means "not added to any session yet"** - it does **not** mean "applies to every session". A
86
- * session lists only the roots whose `workspaces` names its own workspace path (`session-directory.ts`,
87
- * `loadRoots`), so an unscoped root is registered with the host but is listed by no session until one opts
88
- * in with 「添加目录」.
89
- *
90
- * Why it exists: the composer's 「添加目录」 reads as "add this directory to *this* conversation", and the
91
- * first version wrote every such root into one flat list - so a directory added in one workspace showed up
92
- * in the next one, which the user rightly called out. The requirement document already separates the two
93
- * (FR-1.7: extra roots live in the plugin's own storage, grouped per project), so the grouping is recorded
94
- * here.
95
- *
96
- * The settings panel adds **unscoped** roots because its form has no scope field at all
97
- * (`RootsPanelDrafts` carries no `workspaces` member): it registers a root with the host, and a session opts
98
- * in explicitly. An earlier revision of this comment justified listing unscoped roots in *every* session by
99
- * claiming that the panel's "own copy says those apply to every session" - **no such copy existed**; every
100
- * `roots*` string in both dictionaries is about paths, connections, testing and validation (audit 0056).
101
- * The silent global visibility that followed - a remote directory appearing in a session that had never
102
- * added it - is why the rule is now the other way round.
103
- *
104
- * Plural because identity is the **path** ({@link userRootKey}) and the same path can be added to more than
105
- * one workspace. The live registry and the router are plugin-wide (a path resolves by scheme/anchor, not by
106
- * workspace), so a remote root stays addressable from another workspace. Filtering is a view fact, not a
107
- * sandbox.
108
- */
109
- readonly workspaces?: readonly string[];
110
- /**
111
- * The local anchor directory this remote root stands on, when it has one.
112
- *
113
- * It is persisted because it is **identity at the platform level**: the platform creates a workspace on
114
- * this host path, so a root whose anchor is re-derived differently (a connection rename changes both the
115
- * `connectionId` segment and the digest) silently orphans the workspace that was created on the old one.
116
- * The first version derived it on every read and never stored it; a rename then moved every anchor and left
117
- * the user's remote workspaces pointing at paths no root covered (`ROOT_OUTSIDE`).
118
- *
119
- * Absent means "derive it from the connection id and path" (`index.ts`'s `toRoot`), which is what entries
120
- * written before this field existed do. Only remote roots may carry it; a local root is its own anchor.
121
- */
122
- readonly anchorPath?: string;
123
- }
124
- /** One connection the user added. Carries **no** credential. */
125
- export interface UserConnectionRecord {
126
- /** Slug, unique in the file. */
127
- readonly id: string;
128
- /** Host name or IP. */
129
- readonly host: string;
130
- /** Login user. */
131
- readonly user: string;
132
- /** TCP port; absent means the ssh default. */
133
- readonly port?: number;
134
- /** `agent` (ssh-agent / ssh config), `key` (identity file) or `password` (stored secret). */
135
- readonly authKind: UserConnectionAuthKind;
136
- /**
137
- * Transport the user chose in the panel; absent means the default the reader applies (`agent`, see
138
- * `toProfileInput` in the entry). Optional rather than defaulted here so an older file keeps loading: a
139
- * record written before the selector existed has no opinion, and inventing one on read would be a silent
140
- * migration. A **present** value is validated ({@link normalizeConnectionEntry}) and is always one of the
141
- * three, so a reader never has to guess whether a spelling is meaningful.
142
- */
143
- readonly transport?: UserConnectionTransport;
144
- /** Identity file path; only meaningful for `authKind: 'key'`. */
145
- readonly keyPath?: string;
146
- /**
147
- * Name of the stored secret, never the secret; only meaningful for `authKind: 'password'`.
148
- *
149
- * Derived from the id when a caller does not supply one (see `credentialRefFor`), because the platform's
150
- * reference grammar is a POSIX identifier and a user-chosen Chinese name is not one.
151
- */
152
- readonly credentialKey?: string;
153
- }
154
- /** The whole persisted document. */
155
- export interface UserRootsState {
156
- readonly version: typeof USER_ROOTS_VERSION;
157
- readonly roots: readonly UserRootEntry[];
158
- readonly connections: readonly UserConnectionRecord[];
159
- }
160
- /** One read of the file: the state plus everything that was wrong with it. */
161
- export interface UserRootsLoad {
162
- readonly state: UserRootsState;
163
- /** Non-fatal problems (missing file is **not** one: that is the pristine state). */
164
- readonly warnings: readonly string[];
165
- }
166
- /** File-system surface, injected so tests never touch the developer's home directory. */
167
- export interface UserRootsIo {
168
- readFile(path: string): Promise<string>;
169
- writeFile(path: string, data: string): Promise<void>;
170
- mkdir(path: string): Promise<void>;
171
- rename(from: string, to: string): Promise<void>;
172
- }
173
- /** Real file-system binding: UTF-8, owner-only, atomic. */
174
- export declare const nodeUserRootsIo: UserRootsIo;
175
- /** The pristine state: no roots, no connections. */
176
- export declare function emptyUserRootsState(): UserRootsState;
177
- /**
178
- * Stable identity of a user root, and the key `remove-root` accepts.
179
- *
180
- * Local paths are normalised for separators and trailing slashes but **keep the caller's case**; remote keys
181
- * are POSIX and therefore case-sensitive. `RootRegistry.rootKey` folds case on Windows, so
182
- * {@link removeRootFromState} retries once case-insensitively for `local:` keys — otherwise a root listed by
183
- * the UI as `D:/Work` could not be removed with the key `local:d:/work`.
184
- *
185
- * @param entry - a validated (or at least well-formed) root entry.
186
- * @returns `local:<path>` or `remote:<connectionId>:<path>`.
187
- */
188
- export declare function userRootKey(entry: UserRootEntry): string;
189
- /**
190
- * The persisted state as JSON text: UTF-8 without BOM, two-space indent, trailing newline.
191
- *
192
- * The BOM-free part is deliberate — a `\uFEFF` prefix makes `JSON.parse` fail in some readers and is exactly
193
- * what `Set-Content -Encoding UTF8` used to add to files in this repository.
194
- *
195
- * @param state - state to serialise.
196
- * @returns the file contents.
197
- */
198
- export declare function serializeUserRoots(state: UserRootsState): string;
199
- /**
200
- * Read the persisted state from text.
201
- *
202
- * **Never throws.** Every failure mode degrades to the empty state plus a warning that names the reason:
203
- * unreadable text is not distinguishable here (the caller catches the I/O error), but malformed JSON, a
204
- * foreign `version`, and individual corrupt entries all are.
205
- *
206
- * @param text - file contents, or `undefined` when the file does not exist.
207
- * @returns the usable state and the warnings collected on the way.
208
- */
209
- export declare function parseUserRoots(text: string | undefined): UserRootsLoad;
210
- /**
211
- * Normalise and validate one root entry.
212
- *
213
- * Rules: `location` must be `local` or `remote`; a local path must be non-empty; a remote path must be a
214
- * POSIX **absolute** path and must not be `/` (the whole remote filesystem is not a workspace root); a
215
- * remote root must name a valid connection id. Unknown keys are ignored by construction — only the fields
216
- * below are read.
217
- *
218
- * @param input - untrusted value (a JSON body or one entry of the file).
219
- * @returns a clean entry.
220
- * @throws SshDevError `ROOT_INVALID` when the entry is not usable.
221
- */
222
- export declare function normalizeRootEntry(input: unknown): UserRootEntry;
223
- /**
224
- * Normalise and validate one connection entry.
225
- *
226
- * **A secret is refused here**, with a message that says why: 密码不入 UI 存储 — a password in this file
227
- * would be readable by anything that can read the state directory, and the plugin's credential path is
228
- * `ctx.credentials`. A `password` or `passphrase` field is rejected outright. `authKind: 'password'` **is**
229
- * accepted, but the record then carries only `credentialKey` — the *name* of the stored value — which is
230
- * derived from the id when the caller does not supply one. `keyPath` is kept for `authKind: 'key'` and
231
- * dropped for the other two.
232
- *
233
- * `transport` is optional (absent means "the reader's default", see {@link UserConnectionRecord.transport}),
234
- * but a value that **is** present must be one of the three the union allows: an unknown spelling is refused as
235
- * `CONNECTION_INVALID` rather than stored, because a record the transport selector cannot read would silently
236
- * fall back to a transport the user did not choose.
237
- *
238
- * @param input - untrusted value.
239
- * @returns a clean record, never containing a credential.
240
- * @throws SshDevError `CONNECTION_INVALID` when the entry is not usable.
241
- */
242
- export declare function normalizeConnectionEntry(input: unknown): UserConnectionRecord;
243
- /** Find one persisted entry by key (case-folded like the registry), or `undefined`. */
244
- export declare function findRootInState(state: UserRootsState, key: string): UserRootEntry | undefined;
245
- /**
246
- * Union `workspaces` into the entry at `key`, keeping the file's own order and de-duplicating.
247
- *
248
- * The **union** is the point, not a replace: two workspaces that both added the same directory must not
249
- * un-list each other. Identity here is the path ({@link userRootKey}), and the live registry refuses the same
250
- * path twice - so one directory added in two workspaces is one root that two workspaces list.
251
- *
252
- * @param state - the persisted state to update.
253
- * @param key - key of the entry to update.
254
- * @param workspaces - the workspaces to add.
255
- * @returns a new state, or the same state when nothing changed.
256
- */
257
- export declare function withWorkspaces(state: UserRootsState, key: string, workspaces: readonly string[]): UserRootsState;
258
- /**
259
- * Append a root, returning a new state.
260
- *
261
- * @param state - current state.
262
- * @param input - untrusted entry.
263
- * @returns the next state (the input state is untouched).
264
- * @throws SshDevError `ROOT_INVALID` on an invalid entry or a duplicate key.
265
- */
266
- export declare function addRootToState(state: UserRootsState, input: unknown): UserRootsState;
267
- /**
268
- * Remove a root by key, returning a new state.
269
- *
270
- * @param state - current state.
271
- * @param key - key from {@link userRootKey} (or from a `GET` response).
272
- * @returns the next state.
273
- * @throws SshDevError `ROOT_INVALID` when no root matches — a silent no-op would make the panel report
274
- * success for a removal that never happened.
275
- */
276
- export declare function removeRootFromState(state: UserRootsState, key: string): UserRootsState;
277
- /**
278
- * Remove one root from **one** workspace, keeping it for the others.
279
- *
280
- * The add side is a union ({@link withWorkspaces}): one directory added to two workspaces is one root that
281
- * both list. The first removal implementation only had the global delete, so removing it in the workspace the
282
- * operator was looking at removed it from the other one too - the inverse of the union promise, and the reason
283
- * the scoped action exists.
284
- *
285
- * The root itself disappears only when the last workspace drops it; a root that no workspace lists is a root
286
- * no session can see, so keeping it would be a silently unusable entry.
287
- *
288
- * @param state - current state.
289
- * @param key - key from {@link userRootKey} (or from a `GET` response).
290
- * @param workspacePath - the workspace to remove it from (canonical local path, compared as stored).
291
- * @returns the next state.
292
- * @throws SshDevError `ROOT_INVALID` when no root matches, so a no-op cannot be reported as success.
293
- */
294
- export declare function removeRootFromWorkspace(state: UserRootsState, key: string, workspacePath: string): UserRootsState;
295
- /**
296
- * Stamp the given anchor paths onto the entries they name, returning a new state.
297
- *
298
- * Used by the connection-rename path: the anchor is read from the live registry **before** the roots are
299
- * re-keyed, so the new entries keep pointing at the directory the user's workspaces were created on.
300
- *
301
- * @param state - current state.
302
- * @param anchors - root key → anchor path for the entries to stamp.
303
- * @returns the next state, or the same object when nothing changed.
304
- */
305
- export declare function withAnchorPaths(state: UserRootsState, anchors: ReadonlyMap<string, string>): UserRootsState;
306
- /**
307
- * Append a connection, returning a new state.
308
- *
309
- * @param state - current state.
310
- * @param input - untrusted entry (must not carry a password).
311
- * @returns the next state.
312
- * @throws SshDevError `CONNECTION_INVALID` on an invalid entry, a duplicate id, or a password field.
313
- */
314
- export declare function addConnectionToState(state: UserRootsState, input: unknown): UserRootsState;
315
- /**
316
- * Remove a connection **and every remote root that pointed at it**, returning a new state.
317
- *
318
- * Dropping the roots is not optional: a remote root whose connection is gone makes
319
- * `RootRegistry.createRemoteBackend` throw `CONNECTION_NOT_FOUND` on the next use, so leaving it behind
320
- * would turn a deletion into a later crash.
321
- *
322
- * @param state - current state.
323
- * @param id - connection id.
324
- * @returns the next state.
325
- * @throws SshDevError `CONNECTION_INVALID` when no connection has that id.
326
- */
327
- export declare function removeConnectionFromState(state: UserRootsState, id: string): UserRootsState;
328
- /**
329
- * The fields `update-connection` may change. Absent means **keep what is there**.
330
- *
331
- * `password` is deliberately not here (it is not part of a record, exactly as in
332
- * {@link addConnectionToState}); `credentialKey` **is**, because a rename that keeps a password must be
333
- * able to keep - or deliberately re-point - the stored reference name.
334
- */
335
- export interface ConnectionPatch {
336
- /** New id (a rename). The value must pass {@link normalizeConnectionEntry}'s id rule. */
337
- readonly id?: string;
338
- readonly host?: string;
339
- readonly user?: string;
340
- /** A number, or `null`/`''` to drop the field (back to the ssh default). */
341
- readonly port?: number | null | '';
342
- readonly authKind?: UserConnectionAuthKind;
343
- readonly keyPath?: string;
344
- readonly transport?: UserConnectionTransport;
345
- readonly credentialKey?: string;
346
- }
347
- /**
348
- * Update one connection **in place**, returning a new state.
349
- *
350
- * Semantics, all of them deliberate:
351
- *
352
- * 1. **Absent means unchanged.** The patch is merged over the existing record, so a caller that only wants to
353
- * change the host does not have to restate the authentication - and cannot accidentally drop it.
354
- * 2. **A rename migrates the roots.** A remote root names its connection in its own key
355
- * (`remote:<connectionId>:<path>`), so leaving the old id behind would turn every root of that
356
- * connection into a dangling reference that throws `CONNECTION_NOT_FOUND` on next use. The rewrite
357
- * happens here, in the same pure transition, so the file can never hold the two halves out of step.
358
- * 3. **The stored secret's reference name survives a rename** unless the patch says otherwise. The reference
359
- * is a name in `ctx.credentials`, derived from the id only when nothing better is known; re-deriving it
360
- * from the new id would **orphan** the stored password (still in the store, no longer reachable) and could
361
- * silently hand it to a later connection whose derived name collides.
362
- * 4. **The position in the list is kept**, so the panel's rows do not jump when one is edited.
363
- *
364
- * @param state - current state.
365
- * @param id - id of the connection to update (the **current** id, before any rename).
366
- * @param patch - the fields to change; anything absent keeps its value.
367
- * @returns the next state.
368
- * @throws SshDevError `CONNECTION_INVALID` when the id is unknown, the merged record is invalid, or the new
369
- * id collides with another connection.
370
- */
371
- export declare function updateConnectionInState(state: UserRootsState, id: string, patch: ConnectionPatch): UserRootsState;
372
- /** What one store instance offers. Every mutation returns the new state **and** writes it. */
373
- export interface UserRootsStore {
374
- /** Absolute path of the state file. */
375
- readonly filePath: string;
376
- /** Read the file; never throws for content reasons (see {@link parseUserRoots}). */
377
- load(): Promise<UserRootsLoad>;
378
- /** Validate and persist a whole state. */
379
- save(next: UserRootsState): Promise<UserRootsState>;
380
- /** Resolves once every write queued so far has settled (both success and failure). */
381
- settled(): Promise<unknown>;
382
- /** Persist `state + entry` and return the new state. */
383
- addRoot(entry: unknown): Promise<UserRootsState>;
384
- /** Persist `state - key` and return the new state. */
385
- removeRoot(key: string): Promise<UserRootsState>;
386
- /** Persist `state + connection` and return the new state. */
387
- addConnection(entry: unknown): Promise<UserRootsState>;
388
- /** Persist `state - connection` (and its remote roots) and return the new state. */
389
- removeConnection(id: string): Promise<UserRootsState>;
390
- /**
391
- * Persist the patched connection (renaming its roots too when the id changes) and return the new state.
392
- *
393
- * @param id - the connection's current id.
394
- * @param patch - fields to change; anything absent keeps its value.
395
- */
396
- updateConnection(id: string, patch: ConnectionPatch): Promise<UserRootsState>;
397
- }
398
- /** Options for {@link createUserRootsStore}. */
399
- export interface UserRootsStoreOptions {
400
- /** Plugin state directory; the file is {@link USER_ROOTS_FILE_NAME} inside it. */
401
- readonly dir: string;
402
- /** File-system binding; defaults to the real one. */
403
- readonly io?: UserRootsIo;
404
- }
405
- /**
406
- * Build the store over one state directory.
407
- *
408
- * Deliberately **not** a class: every method is "read the current file, compute the next state purely, write
409
- * it", which is exactly the shape the HTTP handlers need and the shape a test can drive with an in-memory
410
- * `io`. There is no in-process cache, so two writers cannot disagree about what is on disk — the cost is
411
- * that concurrent writers can still lose an update (read-modify-write is not locked; see the audit's
412
- * unverified list).
413
- *
414
- * @param options - state directory plus an optional injected file system.
415
- * @returns the store.
416
- */
417
- export declare function createUserRootsStore(options: UserRootsStoreOptions): UserRootsStore;
418
- /**
419
- * Whether the state already contains the root `key` names.
420
- *
421
- * The HTTP layer needs this to make its write **idempotent**: it asks the live seam to register a root and
422
- * only then reconciles the file, so "already present" must not be treated as a duplicate error.
423
- *
424
- * @param state - current state.
425
- * @param key - key from {@link userRootKey}.
426
- * @returns whether a root with that key exists.
427
- */
428
- export declare function stateHasRoot(state: UserRootsState, key: string): boolean;
429
- /**
430
- * Whether the state already contains a connection with that id.
431
- *
432
- * @param state - current state.
433
- * @param id - connection id.
434
- * @returns whether the connection exists.
435
- */
436
- export declare function stateHasConnection(state: UserRootsState, id: string): boolean;
437
- /**
438
- * Validate a whole state that is about to be written.
439
- *
440
- * `save` runs this so a caller cannot persist an entry that {@link normalizeRootEntry} would have rejected —
441
- * otherwise the file would become a source of invalid state for every later reader.
442
- *
443
- * @param next - candidate state.
444
- * @returns the normalised state.
445
- * @throws SshDevError when any entry is invalid or duplicated.
446
- */
447
- export declare function validateState(next: UserRootsState): UserRootsState;
448
- /**
449
- * Public spelling of {@link sameRootKey} for the route layer.
450
- *
451
- * The route has to compare keys from three sources that fold differently: the live registry (Windows local
452
- * paths already lower-cased), the persisted file (case preserved), and the client (built from the `path` the
453
- * answer carried). Without one comparison rule, a Windows local root is listed with a key the host cannot
454
- * remove.
455
- *
456
- * @param left - one key.
457
- * @param right - the other key.
458
- * @returns whether they name the same root.
459
- */
460
- export declare function sameUserRootKey(left: string, right: string): boolean;
461
- //# sourceMappingURL=user-roots.d.ts.map