dsh-over-ssh 0.0.0-stage → 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 (254) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -2
  3. package/agents/agent-manifest.json +20 -0
  4. package/agents/linux-amd64/dsh-over-ssh-agent +0 -0
  5. package/agents/linux-arm64/dsh-over-ssh-agent +0 -0
  6. package/cordis.patch.yml +84 -0
  7. package/lib/client.js +6611 -0
  8. package/lib/file-references.js +366 -0
  9. package/lib/fs.js +1368 -0
  10. package/lib/index.js +19034 -0
  11. package/lib/local-bridge-refs.js +16 -0
  12. package/lib/local-bridge.js +16 -0
  13. package/lib/terminal-wrapper.js +294 -0
  14. package/lib/types/src/client/controls.d.ts +131 -0
  15. package/lib/types/src/client/core/card-focus-trap.d.ts +45 -0
  16. package/lib/types/src/client/core/controls.d.ts +164 -0
  17. package/lib/types/src/client/core/latest.d.ts +48 -0
  18. package/lib/types/src/client/core/locale.d.ts +38 -0
  19. package/lib/types/src/client/core/message.d.ts +37 -0
  20. package/lib/types/src/client/core/panel-model.d.ts +134 -0
  21. package/lib/types/src/client/core/portal.d.ts +266 -0
  22. package/lib/types/src/client/core/remote.d.ts +84 -0
  23. package/lib/types/src/client/core/styles.d.ts +458 -0
  24. package/lib/types/src/client/file-tree-io.d.ts +19 -0
  25. package/lib/types/src/client/file-tree.d.ts +271 -0
  26. package/lib/types/src/client/flows/directory-browser.d.ts +587 -0
  27. package/lib/types/src/client/flows/session-directory.d.ts +415 -0
  28. package/lib/types/src/client/flows/workspace-directory-flow.d.ts +480 -0
  29. package/lib/types/src/client/index.d.ts +49 -0
  30. package/lib/types/src/client/locale.d.ts +31 -0
  31. package/lib/types/src/client/panel-model.d.ts +37 -0
  32. package/lib/types/src/client/panel.d.ts +77 -0
  33. package/lib/types/src/client/roots/connection-test.d.ts +69 -0
  34. package/lib/types/src/client/roots/roots-panel-state.d.ts +307 -0
  35. package/lib/types/src/client/roots/roots-panel-view.d.ts +280 -0
  36. package/lib/types/src/client/roots/roots-panel.d.ts +364 -0
  37. package/lib/types/src/client/roots/transfer-panel-view.d.ts +35 -0
  38. package/lib/types/src/client/roots/transfer-panel.d.ts +241 -0
  39. package/lib/types/src/client/roots/transfer-progress.d.ts +67 -0
  40. package/lib/types/src/client/roots-panel-view.d.ts +236 -0
  41. package/lib/types/src/client/roots-panel.d.ts +347 -0
  42. package/lib/types/src/client/session/session-panel-view.d.ts +336 -0
  43. package/lib/types/src/client/session/session-panel.d.ts +322 -0
  44. package/lib/types/src/client/session/session-remote-mark.d.ts +110 -0
  45. package/lib/types/src/client/session/session-row-actions.d.ts +398 -0
  46. package/lib/types/src/client/session-panel.d.ts +152 -0
  47. package/lib/types/src/client/styles.d.ts +252 -0
  48. package/lib/types/src/client/workspace-directory-flow.d.ts +342 -0
  49. package/lib/types/src/config.d.ts +312 -0
  50. package/lib/types/src/file-references.d.ts +25 -0
  51. package/lib/types/src/fs.d.ts +46 -0
  52. package/lib/types/src/host/app/backend.d.ts +170 -0
  53. package/lib/types/src/host/app/recycle-bin/recycle-bin-contract.d.ts +247 -0
  54. package/lib/types/src/host/app/recycle-bin/recycle-bin-move.d.ts +18 -0
  55. package/lib/types/src/host/app/recycle-bin/recycle-bin-service.d.ts +45 -0
  56. package/lib/types/src/host/app/recycle-bin/recycle-bin-world.d.ts +38 -0
  57. package/lib/types/src/host/app/recycle-bin-contract.d.ts +215 -0
  58. package/lib/types/src/host/app/recycle-bin-move.d.ts +18 -0
  59. package/lib/types/src/host/app/recycle-bin-service.d.ts +45 -0
  60. package/lib/types/src/host/app/recycle-bin-world.d.ts +35 -0
  61. package/lib/types/src/host/app/roots/roots-api-connections.d.ts +49 -0
  62. package/lib/types/src/host/app/roots/roots-api-contract.d.ts +369 -0
  63. package/lib/types/src/host/app/roots/roots-api-directories.d.ts +13 -0
  64. package/lib/types/src/host/app/roots/roots-api-http.d.ts +77 -0
  65. package/lib/types/src/host/app/roots/roots-api-long-poll.d.ts +130 -0
  66. package/lib/types/src/host/app/roots/roots-api-projections.d.ts +102 -0
  67. package/lib/types/src/host/app/roots/roots-api-roots.d.ts +13 -0
  68. package/lib/types/src/host/app/roots/roots-api-state.d.ts +22 -0
  69. package/lib/types/src/host/app/roots/roots-api-transfers.d.ts +26 -0
  70. package/lib/types/src/host/app/roots/roots-api.d.ts +55 -0
  71. package/lib/types/src/host/app/roots/user-roots.d.ts +552 -0
  72. package/lib/types/src/host/app/roots-api-connections.d.ts +49 -0
  73. package/lib/types/src/host/app/roots-api-contract.d.ts +339 -0
  74. package/lib/types/src/host/app/roots-api-directories.d.ts +13 -0
  75. package/lib/types/src/host/app/roots-api-http.d.ts +77 -0
  76. package/lib/types/src/host/app/roots-api-projections.d.ts +102 -0
  77. package/lib/types/src/host/app/roots-api-roots.d.ts +13 -0
  78. package/lib/types/src/host/app/roots-api-state.d.ts +22 -0
  79. package/lib/types/src/host/app/roots-api-support.d.ts +182 -0
  80. package/lib/types/src/host/app/roots-api-transfers.d.ts +13 -0
  81. package/lib/types/src/host/app/roots-api.d.ts +55 -0
  82. package/lib/types/src/host/app/routed-fs.d.ts +239 -0
  83. package/lib/types/src/host/app/serialize.d.ts +37 -0
  84. package/lib/types/src/host/app/session-admin/session-admin-context.d.ts +36 -0
  85. package/lib/types/src/host/app/session-admin/session-admin-contract.d.ts +221 -0
  86. package/lib/types/src/host/app/session-admin/session-admin-delete.d.ts +34 -0
  87. package/lib/types/src/host/app/session-admin/session-admin-service.d.ts +40 -0
  88. package/lib/types/src/host/app/session-admin-context.d.ts +36 -0
  89. package/lib/types/src/host/app/session-admin-contract.d.ts +214 -0
  90. package/lib/types/src/host/app/session-admin-delete.d.ts +34 -0
  91. package/lib/types/src/host/app/session-admin-service.d.ts +38 -0
  92. package/lib/types/src/host/app/takeover/takeover-plan.d.ts +227 -0
  93. package/lib/types/src/host/app/takeover/takeover-rows.d.ts +55 -0
  94. package/lib/types/src/host/app/transport/transport-selector.d.ts +98 -0
  95. package/lib/types/src/host/app/transport/transport-service.d.ts +82 -0
  96. package/lib/types/src/host/app/transport-selector.d.ts +98 -0
  97. package/lib/types/src/host/app/transport-service.d.ts +75 -0
  98. package/lib/types/src/host/app/user-roots.d.ts +461 -0
  99. package/lib/types/src/host/domain/bin-location.d.ts +79 -0
  100. package/lib/types/src/host/domain/capability.d.ts +78 -0
  101. package/lib/types/src/host/domain/connection.d.ts +95 -0
  102. package/lib/types/src/host/domain/errors.d.ts +55 -0
  103. package/lib/types/src/host/domain/glob-pattern.d.ts +62 -0
  104. package/lib/types/src/host/domain/literal-text.d.ts +63 -0
  105. package/lib/types/src/host/domain/path-grammar.d.ts +84 -0
  106. package/lib/types/src/host/domain/recycle-bin.d.ts +337 -0
  107. package/lib/types/src/host/domain/root.d.ts +74 -0
  108. package/lib/types/src/host/domain/roots/bin-location.d.ts +91 -0
  109. package/lib/types/src/host/domain/roots/connection.d.ts +106 -0
  110. package/lib/types/src/host/domain/roots/root.d.ts +108 -0
  111. package/lib/types/src/host/domain/roots/route-table.d.ts +102 -0
  112. package/lib/types/src/host/domain/roots/session-roots.d.ts +151 -0
  113. package/lib/types/src/host/domain/roots/ssh-config.d.ts +73 -0
  114. package/lib/types/src/host/domain/route-table.d.ts +80 -0
  115. package/lib/types/src/host/domain/session/session-admin.d.ts +345 -0
  116. package/lib/types/src/host/domain/session/terminal-target.d.ts +136 -0
  117. package/lib/types/src/host/domain/session-admin.d.ts +330 -0
  118. package/lib/types/src/host/domain/shell.d.ts +47 -0
  119. package/lib/types/src/host/domain/ssh-config.d.ts +73 -0
  120. package/lib/types/src/host/domain/terminal-target.d.ts +132 -0
  121. package/lib/types/src/host/domain/tool-requests.d.ts +369 -0
  122. package/lib/types/src/host/domain/transfer/recycle-bin.d.ts +337 -0
  123. package/lib/types/src/host/domain/transfer/transfer.d.ts +260 -0
  124. package/lib/types/src/host/domain/transfer.d.ts +260 -0
  125. package/lib/types/src/host/infra/backend/local-backend.d.ts +84 -0
  126. package/lib/types/src/host/infra/backend/local-version.d.ts +43 -0
  127. package/lib/types/src/host/infra/backend/platform-local-backend.d.ts +89 -0
  128. package/lib/types/src/host/infra/backend/remote-backend.d.ts +239 -0
  129. package/lib/types/src/host/infra/cache/lru.d.ts +52 -0
  130. package/lib/types/src/host/infra/cache/versioned.d.ts +77 -0
  131. package/lib/types/src/host/infra/temp-name.d.ts +19 -0
  132. package/lib/types/src/host/infra/transport/agent/agent-installer.d.ts +121 -0
  133. package/lib/types/src/host/infra/transport/agent/agent-protocol-client.d.ts +132 -0
  134. package/lib/types/src/host/infra/transport/agent/agent-protocol-codec.d.ts +140 -0
  135. package/lib/types/src/host/infra/transport/agent/agent-protocol-errors.d.ts +41 -0
  136. package/lib/types/src/host/infra/transport/agent/agent-protocol-frames.d.ts +197 -0
  137. package/lib/types/src/host/infra/transport/agent/agent-protocol-types.d.ts +564 -0
  138. package/lib/types/src/host/infra/transport/agent/agent-transport.d.ts +418 -0
  139. package/lib/types/src/host/infra/transport/agent-installer.d.ts +121 -0
  140. package/lib/types/src/host/infra/transport/agent-protocol-client.d.ts +123 -0
  141. package/lib/types/src/host/infra/transport/agent-protocol-codec.d.ts +131 -0
  142. package/lib/types/src/host/infra/transport/agent-protocol-errors.d.ts +41 -0
  143. package/lib/types/src/host/infra/transport/agent-protocol-frames.d.ts +197 -0
  144. package/lib/types/src/host/infra/transport/agent-protocol-types.d.ts +509 -0
  145. package/lib/types/src/host/infra/transport/agent-transport.d.ts +353 -0
  146. package/lib/types/src/host/infra/transport/alias-transport.d.ts +206 -0
  147. package/lib/types/src/host/infra/transport/askpass-fs.d.ts +20 -0
  148. package/lib/types/src/host/infra/transport/askpass.d.ts +133 -0
  149. package/lib/types/src/host/infra/transport/command-pool.d.ts +61 -0
  150. package/lib/types/src/host/infra/transport/fs-commands.d.ts +140 -0
  151. package/lib/types/src/host/infra/transport/git-status-route.d.ts +63 -0
  152. package/lib/types/src/host/infra/transport/git-status.d.ts +101 -0
  153. package/lib/types/src/host/infra/transport/node-spawn.d.ts +26 -0
  154. package/lib/types/src/host/infra/transport/session-window.d.ts +51 -0
  155. package/lib/types/src/host/infra/transport/shell-quote.d.ts +59 -0
  156. package/lib/types/src/host/infra/transport/ssh/alias-transport.d.ts +206 -0
  157. package/lib/types/src/host/infra/transport/ssh/askpass-fs.d.ts +20 -0
  158. package/lib/types/src/host/infra/transport/ssh/askpass.d.ts +133 -0
  159. package/lib/types/src/host/infra/transport/ssh/shell-quote.d.ts +62 -0
  160. package/lib/types/src/host/infra/transport/ssh/ssh-argv.d.ts +43 -0
  161. package/lib/types/src/host/infra/transport/ssh/ssh2-transport.d.ts +328 -0
  162. package/lib/types/src/host/infra/transport/ssh-argv.d.ts +43 -0
  163. package/lib/types/src/host/infra/transport/ssh2-transport.d.ts +302 -0
  164. package/lib/types/src/host/infra/transport/transport-base.d.ts +34 -0
  165. package/lib/types/src/host/infra/transport/transport.d.ts +527 -0
  166. package/lib/types/src/host/integration/agent/agent-install-io.d.ts +33 -0
  167. package/lib/types/src/host/integration/agent/agent-preflight.d.ts +56 -0
  168. package/lib/types/src/host/integration/agent/askpass-registry.d.ts +66 -0
  169. package/lib/types/src/host/integration/agent-install-io.d.ts +33 -0
  170. package/lib/types/src/host/integration/agent-preflight.d.ts +56 -0
  171. package/lib/types/src/host/integration/anchor-directory.d.ts +56 -0
  172. package/lib/types/src/host/integration/askpass-registry.d.ts +59 -0
  173. package/lib/types/src/host/integration/bin-root-resolver.d.ts +81 -0
  174. package/lib/types/src/host/integration/connection-test.d.ts +73 -0
  175. package/lib/types/src/host/integration/file-reference-provider.d.ts +115 -0
  176. package/lib/types/src/host/integration/fs/file-reference-provider.d.ts +142 -0
  177. package/lib/types/src/host/integration/fs/fs-provider.d.ts +368 -0
  178. package/lib/types/src/host/integration/fs/git-status-wiring.d.ts +21 -0
  179. package/lib/types/src/host/integration/fs/platform-errors.d.ts +94 -0
  180. package/lib/types/src/host/integration/fs/remote-file-tools.d.ts +369 -0
  181. package/lib/types/src/host/integration/fs/remote-index.d.ts +177 -0
  182. package/lib/types/src/host/integration/fs-provider.d.ts +226 -0
  183. package/lib/types/src/host/integration/lsp/lsp-framing.d.ts +38 -0
  184. package/lib/types/src/host/integration/lsp/lsp-registry.d.ts +67 -0
  185. package/lib/types/src/host/integration/lsp/lsp-session.d.ts +130 -0
  186. package/lib/types/src/host/integration/management-tools.d.ts +64 -0
  187. package/lib/types/src/host/integration/recycle-bin-service.d.ts +247 -0
  188. package/lib/types/src/host/integration/remote/connection-test.d.ts +73 -0
  189. package/lib/types/src/host/integration/remote/remote-face.d.ts +127 -0
  190. package/lib/types/src/host/integration/remote/remote-tool-backend.d.ts +108 -0
  191. package/lib/types/src/host/integration/remote-face.d.ts +127 -0
  192. package/lib/types/src/host/integration/remote-file-tools.d.ts +241 -0
  193. package/lib/types/src/host/integration/remote-home.d.ts +69 -0
  194. package/lib/types/src/host/integration/remote-index.d.ts +165 -0
  195. package/lib/types/src/host/integration/remote-job-tools.d.ts +295 -0
  196. package/lib/types/src/host/integration/remote-tool-backend.d.ts +97 -0
  197. package/lib/types/src/host/integration/remote-tools.d.ts +206 -0
  198. package/lib/types/src/host/integration/root-registry.d.ts +115 -0
  199. package/lib/types/src/host/integration/roots/anchor-directory.d.ts +56 -0
  200. package/lib/types/src/host/integration/roots/bin-root-resolver.d.ts +81 -0
  201. package/lib/types/src/host/integration/roots/remote-home.d.ts +69 -0
  202. package/lib/types/src/host/integration/roots/root-registry.d.ts +144 -0
  203. package/lib/types/src/host/integration/roots/roots-wiring.d.ts +219 -0
  204. package/lib/types/src/host/integration/roots/session-root-index.d.ts +52 -0
  205. package/lib/types/src/host/integration/roots-api.d.ts +407 -0
  206. package/lib/types/src/host/integration/roots-wiring.d.ts +211 -0
  207. package/lib/types/src/host/integration/session/session-api.d.ts +88 -0
  208. package/lib/types/src/host/integration/session/session-bin-lock.d.ts +80 -0
  209. package/lib/types/src/host/integration/session/session-header.d.ts +151 -0
  210. package/lib/types/src/host/integration/session/session-labels.d.ts +56 -0
  211. package/lib/types/src/host/integration/session/session-route-wiring.d.ts +50 -0
  212. package/lib/types/src/host/integration/session-admin-service.d.ts +236 -0
  213. package/lib/types/src/host/integration/session-api.d.ts +81 -0
  214. package/lib/types/src/host/integration/session-bin-lock.d.ts +80 -0
  215. package/lib/types/src/host/integration/session-header.d.ts +118 -0
  216. package/lib/types/src/host/integration/session-labels.d.ts +56 -0
  217. package/lib/types/src/host/integration/session-route-wiring.d.ts +50 -0
  218. package/lib/types/src/host/integration/session-scope.d.ts +113 -0
  219. package/lib/types/src/host/integration/session-tools.d.ts +44 -0
  220. package/lib/types/src/host/integration/strict-arguments.d.ts +79 -0
  221. package/lib/types/src/host/integration/takeover/takeover-api.d.ts +62 -0
  222. package/lib/types/src/host/integration/takeover/takeover-route-wiring.d.ts +60 -0
  223. package/lib/types/src/host/integration/takeover/takeover-service.d.ts +167 -0
  224. package/lib/types/src/host/integration/terminal-manifest.d.ts +94 -0
  225. package/lib/types/src/host/integration/tools/management-tools.d.ts +245 -0
  226. package/lib/types/src/host/integration/tools/remote-job-tools.d.ts +316 -0
  227. package/lib/types/src/host/integration/tools/remote-lsp-tools.d.ts +43 -0
  228. package/lib/types/src/host/integration/tools/remote-tools.d.ts +236 -0
  229. package/lib/types/src/host/integration/tools/session-target.d.ts +52 -0
  230. package/lib/types/src/host/integration/tools/session-tools.d.ts +46 -0
  231. package/lib/types/src/host/integration/tools/strict-arguments.d.ts +79 -0
  232. package/lib/types/src/host/integration/tools/terminal-manifest.d.ts +94 -0
  233. package/lib/types/src/host/integration/transfer/remote-copy.d.ts +66 -0
  234. package/lib/types/src/host/integration/transfer/transfer-adapters.d.ts +48 -0
  235. package/lib/types/src/host/integration/transfer/transfer-service.d.ts +212 -0
  236. package/lib/types/src/host/integration/transfer/transfer-tracker.d.ts +106 -0
  237. package/lib/types/src/host/integration/transfer-adapters.d.ts +44 -0
  238. package/lib/types/src/host/integration/transfer-service.d.ts +164 -0
  239. package/lib/types/src/host/integration/transfer-tracker.d.ts +106 -0
  240. package/lib/types/src/host/integration/user-roots.d.ts +461 -0
  241. package/lib/types/src/index.d.ts +66 -0
  242. package/lib/types/src/local-bridge-refs.d.ts +26 -0
  243. package/lib/types/src/local-bridge.d.ts +36 -0
  244. package/lib/types/src/shared/format.d.ts +13 -0
  245. package/lib/types/src/wiring/connections.d.ts +189 -0
  246. package/lib/types/src/wiring/fs.d.ts +13 -0
  247. package/lib/types/src/wiring/helpers.d.ts +144 -0
  248. package/lib/types/src/wiring/install-memo.d.ts +32 -0
  249. package/lib/types/src/wiring/legacy-dirs.d.ts +62 -0
  250. package/lib/types/src/wiring/package-paths.d.ts +35 -0
  251. package/lib/types/src/wiring/roots.d.ts +21 -0
  252. package/lib/types/src/wiring/state-dir.d.ts +29 -0
  253. package/lib/types/src/wiring/tools.d.ts +35 -0
  254. package/package.json +120 -4
@@ -0,0 +1,552 @@
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-over-ssh/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/over-ssh` 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 **sessions** (conversation ids) that added this root - the strict identity behind
112
+ * {@link workspaces}, and the field ADR-0013 decides by.
113
+ *
114
+ * `workspaces` cannot separate two conversations opened on the same directory; this can. Written by the
115
+ * 「添加目录」 card (it knows its `sessionId`) and unioned on re-add, exactly like `workspaces`. **Absent
116
+ * means "written before ADR-0013"**: such an entry keeps the workspace-level rule, so an upgrade does not
117
+ * silently take a directory away from the session that added it.
118
+ */
119
+ readonly sessions?: readonly string[];
120
+ /**
121
+ * The local anchor directory this remote root stands on, when it has one.
122
+ *
123
+ * It is persisted because it is **identity at the platform level**: the platform creates a workspace on
124
+ * this host path, so a root whose anchor is re-derived differently (a connection rename changes both the
125
+ * `connectionId` segment and the digest) silently orphans the workspace that was created on the old one.
126
+ * The first version derived it on every read and never stored it; a rename then moved every anchor and left
127
+ * the user's remote workspaces pointing at paths no root covered (`ROOT_OUTSIDE`).
128
+ *
129
+ * Absent means "derive it from the connection id and path" (`index.ts`'s `toRoot`), which is what entries
130
+ * written before this field existed do. Only remote roots may carry it; a local root is its own anchor.
131
+ */
132
+ readonly anchorPath?: string;
133
+ }
134
+ /** One connection the user added. Carries **no** credential. */
135
+ export interface UserConnectionRecord {
136
+ /** Slug, unique in the file. */
137
+ readonly id: string;
138
+ /** Host name or IP. */
139
+ readonly host: string;
140
+ /** Login user. */
141
+ readonly user: string;
142
+ /** TCP port; absent means the ssh default. */
143
+ readonly port?: number;
144
+ /** `agent` (ssh-agent / ssh config), `key` (identity file) or `password` (stored secret). */
145
+ readonly authKind: UserConnectionAuthKind;
146
+ /**
147
+ * Transport the user chose in the panel; absent means the default the reader applies (`agent`, see
148
+ * `toProfileInput` in the entry). Optional rather than defaulted here so an older file keeps loading: a
149
+ * record written before the selector existed has no opinion, and inventing one on read would be a silent
150
+ * migration. A **present** value is validated ({@link normalizeConnectionEntry}) and is always one of the
151
+ * three, so a reader never has to guess whether a spelling is meaningful.
152
+ */
153
+ readonly transport?: UserConnectionTransport;
154
+ /** Identity file path; only meaningful for `authKind: 'key'`. */
155
+ readonly keyPath?: string;
156
+ /**
157
+ * Name of the stored secret, never the secret; only meaningful for `authKind: 'password'`.
158
+ *
159
+ * Derived from the id when a caller does not supply one (see `credentialRefFor`), because the platform's
160
+ * reference grammar is a POSIX identifier and a user-chosen Chinese name is not one.
161
+ */
162
+ readonly credentialKey?: string;
163
+ }
164
+ /** The whole persisted document. */
165
+ export interface UserRootsState {
166
+ readonly version: typeof USER_ROOTS_VERSION;
167
+ readonly roots: readonly UserRootEntry[];
168
+ readonly connections: readonly UserConnectionRecord[];
169
+ }
170
+ /** One read of the file: the state plus everything that was wrong with it. */
171
+ export interface UserRootsLoad {
172
+ readonly state: UserRootsState;
173
+ /** Non-fatal problems (missing file is **not** one: that is the pristine state). */
174
+ readonly warnings: readonly string[];
175
+ /**
176
+ * Whether `state` is a **fallback**, not what the file says.
177
+ *
178
+ * `true` means this read could not understand the document (unparsable JSON, a foreign `version`, an I/O
179
+ * error) and substituted {@link emptyUserRootsState}. Writing that fallback back is data loss — every root
180
+ * and connection the file held disappears — so every write path refuses while this is set
181
+ * ({@link assertUserRootsWritable}). A **missing** file is not degraded: that is the pristine state, and
182
+ * creating it is the intended first write.
183
+ */
184
+ readonly degraded: boolean;
185
+ }
186
+ /**
187
+ * The part of a read the write guards look at.
188
+ *
189
+ * Structural on purpose: the HTTP layer's `loadUserState` seam hands back `{ state, warnings }` from any
190
+ * wiring (including a test double that predates this field), so the guards must not require a full
191
+ * {@link UserRootsLoad}. An **absent** `degraded` means "this wiring never degrades" — true for an in-memory
192
+ * double, and the safe reading for one that does not implement the check.
193
+ */
194
+ export interface UserRootsDegradedRead {
195
+ readonly warnings: readonly string[];
196
+ readonly degraded?: boolean;
197
+ }
198
+ /**
199
+ * The refusal a write gets while the file cannot be read (see {@link UserRootsLoad.degraded}).
200
+ *
201
+ * Deliberately **not** an `SshDevError`: none of the plugin's codes describes "the plugin's own state file is
202
+ * unreadable", and inventing one would put a value in the code table that `doc/07-reference/error-codes.md`
203
+ * (the single owner of that table) does not list. The HTTP layer maps a non-plugin error to 500 and passes
204
+ * `details.reason` through as its own field, so a client can branch on `reason: 'user-roots-unreadable'`
205
+ * without matching prose.
206
+ */
207
+ export declare class UserRootsUnreadableError extends Error {
208
+ readonly details: {
209
+ readonly reason: 'user-roots-unreadable';
210
+ readonly warnings: readonly string[];
211
+ };
212
+ constructor(load: UserRootsDegradedRead);
213
+ }
214
+ /**
215
+ * Refuse a write whose base state is a fallback rather than the file's content.
216
+ *
217
+ * Called by every write path (`mutate`, `save`, and the HTTP layer's `reconcile`) so the rule has one
218
+ * implementation and a new caller cannot forget it.
219
+ *
220
+ * @param loaded - the read the write is about to be based on.
221
+ * @throws UserRootsUnreadableError when `loaded.degraded` is set.
222
+ */
223
+ export declare function assertUserRootsWritable(loaded: UserRootsDegradedRead): void;
224
+ /** File-system surface, injected so tests never touch the developer's home directory. */
225
+ export interface UserRootsIo {
226
+ readFile(path: string): Promise<string>;
227
+ writeFile(path: string, data: string): Promise<void>;
228
+ mkdir(path: string): Promise<void>;
229
+ rename(from: string, to: string): Promise<void>;
230
+ }
231
+ /** Real file-system binding: UTF-8, owner-only, atomic. */
232
+ export declare const nodeUserRootsIo: UserRootsIo;
233
+ /** The pristine state: no roots, no connections. */
234
+ export declare function emptyUserRootsState(): UserRootsState;
235
+ /**
236
+ * Stable identity of a user root, and the key `remove-root` accepts.
237
+ *
238
+ * Local paths are normalised for separators and trailing slashes but **keep the caller's case**; remote keys
239
+ * are POSIX and therefore case-sensitive. `RootRegistry.rootKey` folds case on Windows, so
240
+ * {@link removeRootFromState} retries once case-insensitively for `local:` keys — otherwise a root listed by
241
+ * the UI as `D:/Work` could not be removed with the key `local:d:/work`.
242
+ *
243
+ * @param entry - a validated (or at least well-formed) root entry.
244
+ * @returns `local:<path>` or `remote:<connectionId>:<path>`.
245
+ */
246
+ export declare function userRootKey(entry: UserRootEntry): string;
247
+ /**
248
+ * The persisted state as JSON text: UTF-8 without BOM, two-space indent, trailing newline.
249
+ *
250
+ * The BOM-free part is deliberate — a `\uFEFF` prefix makes `JSON.parse` fail in some readers and is exactly
251
+ * what `Set-Content -Encoding UTF8` used to add to files in this repository.
252
+ *
253
+ * @param state - state to serialise.
254
+ * @returns the file contents.
255
+ */
256
+ export declare function serializeUserRoots(state: UserRootsState): string;
257
+ /**
258
+ * Read the persisted state from text.
259
+ *
260
+ * **Never throws.** Every failure mode degrades to the empty state plus a warning that names the reason:
261
+ * unreadable text is not distinguishable here (the caller catches the I/O error), but malformed JSON, a
262
+ * foreign `version`, and individual corrupt entries all are.
263
+ *
264
+ * @param text - file contents, or `undefined` when the file does not exist.
265
+ * @returns the usable state and the warnings collected on the way.
266
+ */
267
+ export declare function parseUserRoots(text: string | undefined): UserRootsLoad;
268
+ /**
269
+ * Normalise and validate one root entry.
270
+ *
271
+ * Rules: `location` must be `local` or `remote`; a local path must be non-empty; a remote path must be a
272
+ * POSIX **absolute** path and must not be `/` (the whole remote filesystem is not a workspace root); a
273
+ * remote root must name a valid connection id. Unknown keys are ignored by construction — only the fields
274
+ * below are read.
275
+ *
276
+ * @param input - untrusted value (a JSON body or one entry of the file).
277
+ * @returns a clean entry.
278
+ * @throws SshDevError `ROOT_INVALID` when the entry is not usable.
279
+ */
280
+ export declare function normalizeRootEntry(input: unknown): UserRootEntry;
281
+ /**
282
+ * Normalise and validate one connection entry.
283
+ *
284
+ * **A secret is refused here**, with a message that says why: 密码不入 UI 存储 — a password in this file
285
+ * would be readable by anything that can read the state directory, and the plugin's credential path is
286
+ * `ctx.credentials`. A `password` or `passphrase` field is rejected outright. `authKind: 'password'` **is**
287
+ * accepted, but the record then carries only `credentialKey` — the *name* of the stored value — which is
288
+ * derived from the id when the caller does not supply one. `keyPath` is kept for `authKind: 'key'` and
289
+ * dropped for the other two.
290
+ *
291
+ * `transport` is optional (absent means "the reader's default", see {@link UserConnectionRecord.transport}),
292
+ * but a value that **is** present must be one of the three the union allows: an unknown spelling is refused as
293
+ * `CONNECTION_INVALID` rather than stored, because a record the transport selector cannot read would silently
294
+ * fall back to a transport the user did not choose.
295
+ *
296
+ * @param input - untrusted value.
297
+ * @returns a clean record, never containing a credential.
298
+ * @throws SshDevError `CONNECTION_INVALID` when the entry is not usable.
299
+ */
300
+ export declare function normalizeConnectionEntry(input: unknown): UserConnectionRecord;
301
+ /** Find one persisted entry by key (case-folded like the registry), or `undefined`. */
302
+ export declare function findRootInState(state: UserRootsState, key: string): UserRootEntry | undefined;
303
+ /**
304
+ * Union `workspaces` into the entry at `key`, keeping the file's own order and de-duplicating.
305
+ *
306
+ * The **union** is the point, not a replace: two workspaces that both added the same directory must not
307
+ * un-list each other. Identity here is the path ({@link userRootKey}), and the live registry refuses the same
308
+ * path twice - so one directory added in two workspaces is one root that two workspaces list.
309
+ *
310
+ * @param state - the persisted state to update.
311
+ * @param key - key of the entry to update.
312
+ * @param workspaces - the workspaces to add.
313
+ * @returns a new state, or the same state when nothing changed.
314
+ */
315
+ export declare function withWorkspaces(state: UserRootsState, key: string, workspaces: readonly string[]): UserRootsState;
316
+ /**
317
+ * Union `sessions` into the entry at `key`, keeping the file's own order and de-duplicating.
318
+ *
319
+ * The same union as {@link withWorkspaces} and for the same reason: one directory added by two conversations
320
+ * is one root that both list, and the second add must not un-list the first. Called only for entries that
321
+ * already exist; a new entry carries its `sessions` from the request.
322
+ *
323
+ * @param state - the persisted state to update.
324
+ * @param key - key of the entry to update.
325
+ * @param sessions - the sessions to add.
326
+ * @returns a new state, or the same state when nothing changed.
327
+ */
328
+ export declare function withSessions(state: UserRootsState, key: string, sessions: readonly string[]): UserRootsState;
329
+ /**
330
+ * Append a root, returning a new state.
331
+ *
332
+ * @param state - current state.
333
+ * @param input - untrusted entry.
334
+ * @returns the next state (the input state is untouched).
335
+ * @throws SshDevError `ROOT_INVALID` on an invalid entry or a duplicate key.
336
+ */
337
+ export declare function addRootToState(state: UserRootsState, input: unknown): UserRootsState;
338
+ /**
339
+ * Remove a root by key, returning a new state.
340
+ *
341
+ * @param state - current state.
342
+ * @param key - key from {@link userRootKey} (or from a `GET` response).
343
+ * @returns the next state.
344
+ * @throws SshDevError `ROOT_INVALID` when no root matches — a silent no-op would make the panel report
345
+ * success for a removal that never happened.
346
+ */
347
+ export declare function removeRootFromState(state: UserRootsState, key: string): UserRootsState;
348
+ /**
349
+ * Remove one root from **one** workspace, keeping it for the others.
350
+ *
351
+ * The add side is a union ({@link withWorkspaces}): one directory added to two workspaces is one root that
352
+ * both list. The first removal implementation only had the global delete, so removing it in the workspace the
353
+ * operator was looking at removed it from the other one too - the inverse of the union promise, and the reason
354
+ * the scoped action exists.
355
+ *
356
+ * The root itself disappears only when the last workspace drops it; a root that no workspace lists is a root
357
+ * no session can see, so keeping it would be a silently unusable entry.
358
+ *
359
+ * @param state - current state.
360
+ * @param key - key from {@link userRootKey} (or from a `GET` response).
361
+ * @param workspacePath - the workspace to remove it from (canonical local path, compared as stored).
362
+ * @returns the next state.
363
+ * @throws SshDevError `ROOT_INVALID` when no root matches, so a no-op cannot be reported as success.
364
+ */
365
+ export declare function removeRootFromWorkspace(state: UserRootsState, key: string, workspacePath: string): UserRootsState;
366
+ /**
367
+ * Remove one root from **one session**, keeping it for the others.
368
+ *
369
+ * The scoped-removal twin of {@link removeRootFromWorkspace}, for the identity ADR-0013 made decisive. A card
370
+ * that lists a root because *this conversation* added it must be able to drop it without touching the
371
+ * conversation next door - which is exactly what the workspace-scoped removal cannot express when both
372
+ * conversations sit in the same workspace.
373
+ *
374
+ * The entry disappears when its `sessions` list empties: a root that no session lists is a root no session can
375
+ * see, so keeping it would be a silently unusable entry. `workspaces` is left untouched on the surviving path
376
+ * - it is inert while `sessions` is non-empty (the session rule wins), and rewriting it would erase the record
377
+ * the legacy path still uses.
378
+ *
379
+ * @param state - current state.
380
+ * @param key - key from {@link userRootKey} (or from a `GET` response).
381
+ * @param sessionId - the session to remove it from.
382
+ * @returns the next state.
383
+ * @throws SshDevError `ROOT_INVALID` when no root matches or the root was not added by that session.
384
+ */
385
+ export declare function removeRootFromSession(state: UserRootsState, key: string, sessionId: string): UserRootsState;
386
+ /**
387
+ * Stamp the given anchor paths onto the entries they name, returning a new state.
388
+ *
389
+ * Used by the connection-rename path: the anchor is read from the live registry **before** the roots are
390
+ * re-keyed, so the new entries keep pointing at the directory the user's workspaces were created on.
391
+ *
392
+ * @param state - current state.
393
+ * @param anchors - root key → anchor path for the entries to stamp.
394
+ * @returns the next state, or the same object when nothing changed.
395
+ */
396
+ export declare function withAnchorPaths(state: UserRootsState, anchors: ReadonlyMap<string, string>): UserRootsState;
397
+ /**
398
+ * Append a connection, returning a new state.
399
+ *
400
+ * @param state - current state.
401
+ * @param input - untrusted entry (must not carry a password).
402
+ * @returns the next state.
403
+ * @throws SshDevError `CONNECTION_INVALID` on an invalid entry, a duplicate id, or a password field.
404
+ */
405
+ export declare function addConnectionToState(state: UserRootsState, input: unknown): UserRootsState;
406
+ /**
407
+ * Remove a connection **and every remote root that pointed at it**, returning a new state.
408
+ *
409
+ * Dropping the roots is not optional: a remote root whose connection is gone makes
410
+ * `RootRegistry.createRemoteBackend` throw `CONNECTION_NOT_FOUND` on the next use, so leaving it behind
411
+ * would turn a deletion into a later crash.
412
+ *
413
+ * @param state - current state.
414
+ * @param id - connection id.
415
+ * @returns the next state.
416
+ * @throws SshDevError `CONNECTION_INVALID` when no connection has that id.
417
+ */
418
+ export declare function removeConnectionFromState(state: UserRootsState, id: string): UserRootsState;
419
+ /**
420
+ * The fields `update-connection` may change. Absent means **keep what is there**.
421
+ *
422
+ * `password` is deliberately not here (it is not part of a record, exactly as in
423
+ * {@link addConnectionToState}); `credentialKey` **is**, because a rename that keeps a password must be
424
+ * able to keep - or deliberately re-point - the stored reference name.
425
+ */
426
+ export interface ConnectionPatch {
427
+ /** New id (a rename). The value must pass {@link normalizeConnectionEntry}'s id rule. */
428
+ readonly id?: string;
429
+ readonly host?: string;
430
+ readonly user?: string;
431
+ /** A number, or `null`/`''` to drop the field (back to the ssh default). */
432
+ readonly port?: number | null | '';
433
+ readonly authKind?: UserConnectionAuthKind;
434
+ readonly keyPath?: string;
435
+ readonly transport?: UserConnectionTransport;
436
+ readonly credentialKey?: string;
437
+ }
438
+ /**
439
+ * Update one connection **in place**, returning a new state.
440
+ *
441
+ * Semantics, all of them deliberate:
442
+ *
443
+ * 1. **Absent means unchanged.** The patch is merged over the existing record, so a caller that only wants to
444
+ * change the host does not have to restate the authentication - and cannot accidentally drop it.
445
+ * 2. **A rename migrates the roots.** A remote root names its connection in its own key
446
+ * (`remote:<connectionId>:<path>`), so leaving the old id behind would turn every root of that
447
+ * connection into a dangling reference that throws `CONNECTION_NOT_FOUND` on next use. The rewrite
448
+ * happens here, in the same pure transition, so the file can never hold the two halves out of step.
449
+ * 3. **The stored secret's reference name survives a rename** unless the patch says otherwise. The reference
450
+ * is a name in `ctx.credentials`, derived from the id only when nothing better is known; re-deriving it
451
+ * from the new id would **orphan** the stored password (still in the store, no longer reachable) and could
452
+ * silently hand it to a later connection whose derived name collides.
453
+ * 4. **The position in the list is kept**, so the panel's rows do not jump when one is edited.
454
+ *
455
+ * @param state - current state.
456
+ * @param id - id of the connection to update (the **current** id, before any rename).
457
+ * @param patch - the fields to change; anything absent keeps its value.
458
+ * @returns the next state.
459
+ * @throws SshDevError `CONNECTION_INVALID` when the id is unknown, the merged record is invalid, or the new
460
+ * id collides with another connection.
461
+ */
462
+ export declare function updateConnectionInState(state: UserRootsState, id: string, patch: ConnectionPatch): UserRootsState;
463
+ /** What one store instance offers. Every mutation returns the new state **and** writes it. */
464
+ export interface UserRootsStore {
465
+ /** Absolute path of the state file. */
466
+ readonly filePath: string;
467
+ /** Read the file; never throws for content reasons (see {@link parseUserRoots}). */
468
+ load(): Promise<UserRootsLoad>;
469
+ /** Validate and persist a whole state. */
470
+ save(next: UserRootsState): Promise<UserRootsState>;
471
+ /** Resolves once every write queued so far has settled (both success and failure). */
472
+ settled(): Promise<unknown>;
473
+ /** Persist `state + entry` and return the new state. */
474
+ addRoot(entry: unknown): Promise<UserRootsState>;
475
+ /** Persist `state - key` and return the new state. */
476
+ removeRoot(key: string): Promise<UserRootsState>;
477
+ /** Persist `state + connection` and return the new state. */
478
+ addConnection(entry: unknown): Promise<UserRootsState>;
479
+ /** Persist `state - connection` (and its remote roots) and return the new state. */
480
+ removeConnection(id: string): Promise<UserRootsState>;
481
+ /**
482
+ * Persist the patched connection (renaming its roots too when the id changes) and return the new state.
483
+ *
484
+ * @param id - the connection's current id.
485
+ * @param patch - fields to change; anything absent keeps its value.
486
+ */
487
+ updateConnection(id: string, patch: ConnectionPatch): Promise<UserRootsState>;
488
+ }
489
+ /** Options for {@link createUserRootsStore}. */
490
+ export interface UserRootsStoreOptions {
491
+ /** Plugin state directory; the file is {@link USER_ROOTS_FILE_NAME} inside it. */
492
+ readonly dir: string;
493
+ /** File-system binding; defaults to the real one. */
494
+ readonly io?: UserRootsIo;
495
+ }
496
+ /**
497
+ * Build the store over one state directory.
498
+ *
499
+ * Deliberately **not** a class: every method is "read the current file, compute the next state purely, write
500
+ * it", which is exactly the shape the HTTP handlers need and the shape a test can drive with an in-memory
501
+ * `io`. There is no in-process cache, so two writers cannot disagree about what is on disk — the cost is
502
+ * that concurrent writers can still lose an update (read-modify-write is not locked; see the audit's
503
+ * unverified list).
504
+ *
505
+ * @param options - state directory plus an optional injected file system.
506
+ * @returns the store.
507
+ */
508
+ export declare function createUserRootsStore(options: UserRootsStoreOptions): UserRootsStore;
509
+ /**
510
+ * Whether the state already contains the root `key` names.
511
+ *
512
+ * The HTTP layer needs this to make its write **idempotent**: it asks the live seam to register a root and
513
+ * only then reconciles the file, so "already present" must not be treated as a duplicate error.
514
+ *
515
+ * @param state - current state.
516
+ * @param key - key from {@link userRootKey}.
517
+ * @returns whether a root with that key exists.
518
+ */
519
+ export declare function stateHasRoot(state: UserRootsState, key: string): boolean;
520
+ /**
521
+ * Whether the state already contains a connection with that id.
522
+ *
523
+ * @param state - current state.
524
+ * @param id - connection id.
525
+ * @returns whether the connection exists.
526
+ */
527
+ export declare function stateHasConnection(state: UserRootsState, id: string): boolean;
528
+ /**
529
+ * Validate a whole state that is about to be written.
530
+ *
531
+ * `save` runs this so a caller cannot persist an entry that {@link normalizeRootEntry} would have rejected —
532
+ * otherwise the file would become a source of invalid state for every later reader.
533
+ *
534
+ * @param next - candidate state.
535
+ * @returns the normalised state.
536
+ * @throws SshDevError when any entry is invalid or duplicated.
537
+ */
538
+ export declare function validateState(next: UserRootsState): UserRootsState;
539
+ /**
540
+ * Public spelling of {@link sameRootKey} for the route layer.
541
+ *
542
+ * The route has to compare keys from three sources that fold differently: the live registry (Windows local
543
+ * paths already lower-cased), the persisted file (case preserved), and the client (built from the `path` the
544
+ * answer carried). Without one comparison rule, a Windows local root is listed with a key the host cannot
545
+ * remove.
546
+ *
547
+ * @param left - one key.
548
+ * @param right - the other key.
549
+ * @returns whether they name the same root.
550
+ */
551
+ export declare function sameUserRootKey(left: string, right: string): boolean;
552
+ //# sourceMappingURL=user-roots.d.ts.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * roots-api-connections
3
+ *
4
+ * 连接的 6 个 action:ssh-config 发现/导入、增删改连接、连接自检。
5
+ *
6
+ * 从 `roots-api-roots.ts` 拆出(审计 0077):根与连接是两套独立的状态机,
7
+ * 原先共处一个 switch,各自的辅助函数也互不相干。
8
+ *
9
+ * @module dsh-remote-workspace/app/roots-api-connections
10
+ */
11
+ import type { RootsApiRequest, RootsApiResponse, RootsApiDeps } from './roots-api-contract.ts';
12
+ export declare function handleConnectionActions(action: string, body: Record<string, unknown>, req: RootsApiRequest, res: RootsApiResponse, deps: RootsApiDeps): Promise<boolean>;
13
+ /**
14
+ * Importable `~/.ssh/config` aliases, and what the flow refuses.
15
+ *
16
+ * The refusal list is the point, not a nicety: a wildcard `Host *` or an alias already imported is skipped
17
+ * **with its reason and line number**, so the dialog can say why a host the user can see in the file is not on
18
+ * the list. Silently importing a subset is how a user concludes the feature is broken.
19
+ */
20
+ export interface SshConfigCandidates {
21
+ /** Aliases the user may import, already filtered. */
22
+ readonly candidates: readonly SshConfigCandidate[];
23
+ /** Patterns that were refused, each with its reason. */
24
+ readonly skipped: readonly {
25
+ readonly pattern: string;
26
+ readonly reason: string;
27
+ readonly line: number;
28
+ }[];
29
+ /** Absolute path the text was read from, when the wiring knows it. */
30
+ readonly path?: string;
31
+ }
32
+ /** One importable alias, projected to what the dialog renders. */
33
+ export interface SshConfigCandidate {
34
+ /** The literal alias; also the `ssh` target. */
35
+ readonly alias: string;
36
+ /** Resolved host name (falls back to the alias). */
37
+ readonly host: string;
38
+ /** Login user when the block named one. */
39
+ readonly user?: string;
40
+ /** Port when the block named a numeric one. */
41
+ readonly port?: number;
42
+ /** Whether the block named an identity file (the path itself is not sent: see the route's invariant 1). */
43
+ readonly hasIdentityFile: boolean;
44
+ /** Whether the block named a ProxyJump. */
45
+ readonly hasProxyJump: boolean;
46
+ /** The id this import would create, so the dialog can show and edit it before committing. */
47
+ readonly suggestedId: string;
48
+ }
49
+ //# sourceMappingURL=roots-api-connections.d.ts.map