dsh-remote-vs 0.27.0 → 0.29.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 (67) hide show
  1. package/README.en.md +159 -23
  2. package/README.md +123 -23
  3. package/lib/client.js +6906 -6619
  4. package/lib/index.js +2014 -67
  5. package/lib/types/changes/recorder.d.ts +119 -2
  6. package/lib/types/client/CodeEditor.d.ts +15 -0
  7. package/lib/types/client/HostsView.d.ts +139 -2
  8. package/lib/types/client/api.d.ts +42 -2
  9. package/lib/types/client/changes/apply-failure.d.ts +41 -0
  10. package/lib/types/client/changes/block-confirm.d.ts +97 -0
  11. package/lib/types/client/changes/diff-outcome.d.ts +56 -0
  12. package/lib/types/client/changes/freshness.d.ts +51 -0
  13. package/lib/types/client/changes/model.d.ts +19 -1
  14. package/lib/types/client/changes/session-diff.d.ts +100 -0
  15. package/lib/types/client/changes/staleness.d.ts +98 -0
  16. package/lib/types/client/changes/turn-reverted.d.ts +82 -0
  17. package/lib/types/client/changes/turn-view.d.ts +131 -0
  18. package/lib/types/client/changes/undo-affordance.d.ts +44 -10
  19. package/lib/types/client/changes/undo-target.d.ts +12 -0
  20. package/lib/types/client/connection.d.ts +28 -1
  21. package/lib/types/client/i18n.d.ts +1 -1
  22. package/lib/types/client/store.d.ts +91 -1
  23. package/lib/types/client/vsc/change-marks.d.ts +21 -0
  24. package/lib/types/forward.d.ts +11 -1
  25. package/lib/types/pool.d.ts +95 -1
  26. package/lib/types/protocol.d.ts +221 -1
  27. package/lib/types/proxy.d.ts +136 -0
  28. package/lib/types/store.d.ts +81 -1
  29. package/lib/types/tools.d.ts +3 -0
  30. package/package.json +1 -1
  31. package/src/changes/recorder.ts +851 -8
  32. package/src/client/CodeEditor.tsx +43 -3
  33. package/src/client/ConnectionStatus.tsx +19 -5
  34. package/src/client/EditorPane.tsx +64 -7
  35. package/src/client/HostsView.tsx +552 -11
  36. package/src/client/PortsView.tsx +16 -0
  37. package/src/client/SettingsHosts.tsx +132 -6
  38. package/src/client/api.ts +60 -3
  39. package/src/client/changes/ChangesDock.tsx +539 -54
  40. package/src/client/changes/apply-failure.ts +73 -0
  41. package/src/client/changes/block-confirm.ts +180 -0
  42. package/src/client/changes/changes.css +45 -0
  43. package/src/client/changes/diff-outcome.ts +97 -0
  44. package/src/client/changes/freshness.ts +68 -0
  45. package/src/client/changes/model.ts +56 -1
  46. package/src/client/changes/session-diff.ts +187 -0
  47. package/src/client/changes/staleness.ts +148 -0
  48. package/src/client/changes/turn-reverted.ts +254 -0
  49. package/src/client/changes/turn-view.ts +195 -0
  50. package/src/client/changes/undo-affordance.ts +295 -63
  51. package/src/client/changes/undo-target.ts +12 -0
  52. package/src/client/connection.ts +76 -2
  53. package/src/client/i18n.ts +204 -4
  54. package/src/client/scm/DiffView.tsx +32 -13
  55. package/src/client/store.tsx +392 -16
  56. package/src/client/vsc/change-marks.ts +21 -0
  57. package/src/client/vsc/preview-document.tsx +4 -1
  58. package/src/client/vsc/vsc.css +6747 -6509
  59. package/src/forward.ts +38 -2
  60. package/src/importers.ts +125 -13
  61. package/src/keygen.ts +8 -1
  62. package/src/pool.ts +422 -27
  63. package/src/protocol.ts +229 -1
  64. package/src/proxy.ts +673 -0
  65. package/src/routes.ts +93 -14
  66. package/src/store.ts +335 -0
  67. package/src/tools.ts +47 -2
package/src/forward.ts CHANGED
@@ -45,7 +45,18 @@ const LOOPBACK = '127.0.0.1'
45
45
  * the manager never reaches into the pool beyond one call.
46
46
  */
47
47
  export interface ForwardPoolLike {
48
- forwardOut(alias: string, dstHost: string, dstPort: number, srcPort?: number): Promise<ClientChannel>
48
+ /**
49
+ * Open one direct-tcpip channel. `opts.dedicated` asks for the host's dedicated
50
+ * forward connection; the answer carries which connection was actually used, so
51
+ * the rule can SAY "shared" after a fallback instead of pretending.
52
+ */
53
+ forwardOut(
54
+ alias: string,
55
+ dstHost: string,
56
+ dstPort: number,
57
+ srcPort?: number,
58
+ opts?: { dedicated?: boolean },
59
+ ): Promise<{ channel: ClientChannel; dedicated: boolean }>
49
60
  }
50
61
 
51
62
  export interface ForwardManagerDeps {
@@ -147,6 +158,14 @@ interface Forward {
147
158
  bytesIn: number
148
159
  bytesOut: number
149
160
  lastError: string | undefined
161
+ /**
162
+ * Which SSH connection the last successful channel used.
163
+ *
164
+ * `dedicated` = the host's own forward connection (the normal case); `shared` =
165
+ * the server refused that extra connection and the channel rode the shared one.
166
+ * `undefined` until a connection has succeeded at least once (no data to show).
167
+ */
168
+ transport: 'dedicated' | 'shared' | undefined
150
169
  startedAt: number
151
170
  }
152
171
 
@@ -316,6 +335,7 @@ export class ForwardManager {
316
335
  bytesIn: 0,
317
336
  bytesOut: 0,
318
337
  lastError: undefined,
338
+ transport: undefined,
319
339
  startedAt: Date.now(),
320
340
  }
321
341
  server.on('connection', (socket) => { this.accept(forward, socket) })
@@ -384,7 +404,22 @@ export class ForwardManager {
384
404
  private async connect(forward: Forward, socket: Socket): Promise<void> {
385
405
  let channel: ClientChannel
386
406
  try {
387
- channel = await this.deps.pool.forwardOut(forward.alias, forward.remoteHost, forward.remotePort)
407
+ /**
408
+ * Ask for the host's DEDICATED forward connection: forwarding traffic is
409
+ * long-lived and heavy, and multiplexed onto the shared connection it would
410
+ * queue ahead of exec/SFTP channels. The pool falls back on its own when the
411
+ * server refuses the extra connection, and tells us which one was used so
412
+ * the row can say so.
413
+ */
414
+ const opened = await this.deps.pool.forwardOut(
415
+ forward.alias,
416
+ forward.remoteHost,
417
+ forward.remotePort,
418
+ 0,
419
+ { dedicated: true },
420
+ )
421
+ channel = opened.channel
422
+ forward.transport = opened.dedicated ? 'dedicated' : 'shared'
388
423
  } catch (error) {
389
424
  forward.lastError = messageOf(error)
390
425
  this.log('warn', `forward ${forward.id} -> ${forward.remoteHost}:${forward.remotePort} failed: ${forward.lastError}`)
@@ -469,6 +504,7 @@ export class ForwardManager {
469
504
  bytesIn: forward.bytesIn,
470
505
  bytesOut: forward.bytesOut,
471
506
  ...(forward.lastError === undefined ? {} : { lastError: forward.lastError }),
507
+ ...(forward.transport === undefined ? {} : { transport: forward.transport }),
472
508
  startedAt: forward.startedAt,
473
509
  }
474
510
  }
package/src/importers.ts CHANGED
@@ -1,15 +1,20 @@
1
1
  /**
2
2
  * One-shot importers: ~/.ssh/config and the existing dsh-ssh.json. Both only
3
3
  * READ the source and produce payloads for our own store — no runtime coupling.
4
- * P0 supports direct key/password hosts only; jump/proxy/agent entries are
5
- * reported as skipped with reasons.
4
+ * Hosts are direct key hosts; the egress half of a `Host` block (`ProxyJump` /
5
+ * `ProxyCommand`) is mapped onto the store's `proxy` field when it names
6
+ * something this import actually produces, and refused BY NAME when it names a
7
+ * form this plugin cannot dial (multi-hop, a shell command, a jump host that is
8
+ * not part of the config). A silent skip used to be the answer to all of them;
9
+ * "one hop, from this same config" is the honest boundary.
6
10
  */
7
11
  import { existsSync, readFileSync } from 'node:fs'
8
12
  import { homedir } from 'node:os'
9
13
  import { join } from 'node:path'
10
14
  import { dshHome } from './paths.ts'
11
15
  import type { HostPayload } from './store.ts'
12
- import type { ImportReport } from './protocol.ts'
16
+ import type { ImportReport, RemoteHostProxySetting } from './protocol.ts'
17
+ import { parseProxyCommand, parseProxyJump } from './proxy.ts'
13
18
 
14
19
  export interface ParsedImport {
15
20
  payloads: HostPayload[]
@@ -36,9 +41,93 @@ function validPort(value: string | number): number | undefined {
36
41
  return port
37
42
  }
38
43
 
44
+ /** One host block that WILL be imported once its egress decision is known. */
45
+ interface CandidateHost {
46
+ alias: string
47
+ hostname: string
48
+ port: number
49
+ user: string
50
+ identityFile: string
51
+ fields: Map<string, string>
52
+ }
53
+
54
+ /** What resolving one block's `ProxyJump`/`ProxyCommand` produced. */
55
+ type ProxyResolution =
56
+ | { ok: true; proxy?: RemoteHostProxySetting }
57
+ | { ok: false; reason: string }
58
+
59
+ /** `ProxyJump none` / `ProxyCommand none` is OpenSSH for "explicitly no proxy". */
60
+ function isNone(value: string): boolean {
61
+ return value.trim().toLowerCase() === 'none'
62
+ }
63
+
64
+ /**
65
+ * Index every name an imported host answers to: its alias and its `HostName`.
66
+ *
67
+ * `ProxyJump bastion` may name the `Host bastion` alias or the literal hostname
68
+ * it resolves to, so both are accepted; a name with no host behind it in THIS
69
+ * config cannot become a `viaAlias` (the stored setting would dangle).
70
+ */
71
+ function nameIndex(candidates: CandidateHost[]): Map<string, string> {
72
+ const index = new Map<string, string>()
73
+ for (const candidate of candidates) {
74
+ index.set(candidate.alias, candidate.alias)
75
+ index.set(candidate.alias.toLowerCase(), candidate.alias)
76
+ index.set(candidate.hostname, candidate.alias)
77
+ index.set(candidate.hostname.toLowerCase(), candidate.alias)
78
+ }
79
+ return index
80
+ }
81
+
82
+ /** Resolve one jump host name against the hosts this import creates. */
83
+ function resolveJump(self: string, name: string, index: Map<string, string>): ProxyResolution {
84
+ const viaAlias = index.get(name) ?? index.get(name.toLowerCase())
85
+ if (viaAlias === undefined) {
86
+ return {
87
+ ok: false,
88
+ reason: `jump host '${name}' is not imported by this config — a jump host must be one of its Host entries`,
89
+ }
90
+ }
91
+ if (viaAlias === self) return { ok: false, reason: `jump host '${name}' is this host itself` }
92
+ return { ok: true, proxy: { mode: 'jump', jump: { viaAlias } } }
93
+ }
94
+
95
+ /**
96
+ * Turn one block's egress directive into the store's proxy decision.
97
+ *
98
+ * Precedence matches OpenSSH (a set `ProxyJump` wins over `ProxyCommand`), and
99
+ * everything unusable keeps the PARSER's own reason so the report says what to
100
+ * fix ("only one hop", "not supported program") instead of a generic skip.
101
+ */
102
+ function resolveProxy(self: string, fields: Map<string, string>, index: Map<string, string>): ProxyResolution {
103
+ const jump = fields.get('proxyjump')
104
+ if (jump !== undefined) {
105
+ if (isNone(jump)) return { ok: true }
106
+ const parsed = parseProxyJump(jump)
107
+ if (!parsed.ok) return { ok: false, reason: parsed.reason }
108
+ return resolveJump(self, parsed.target.host, index)
109
+ }
110
+ const command = fields.get('proxycommand')
111
+ if (command !== undefined) {
112
+ if (isNone(command)) return { ok: true }
113
+ const plan = parseProxyCommand(command)
114
+ if (plan.kind === 'proxy') {
115
+ // The parsed plan carries no credentials on purpose: an nc/ncat command
116
+ // line may name a proxy but never its password, and guessing one would
117
+ // produce a host that fails with "the proxy rejected the credentials".
118
+ return {
119
+ ok: true,
120
+ proxy: { mode: 'proxy', proxy: { kind: plan.proxy.kind, host: plan.proxy.host, port: plan.proxy.port } },
121
+ }
122
+ }
123
+ if (plan.kind === 'jump') return resolveJump(self, plan.target.host, index)
124
+ return { ok: false, reason: plan.reason }
125
+ }
126
+ return { ok: true }
127
+ }
128
+
39
129
  /** Parse OpenSSH client config text into host payloads. */
40
130
  export function parseSshConfig(text: string): ParsedImport {
41
- const payloads: HostPayload[] = []
42
131
  const skipped: { alias: string; reason: string }[] = []
43
132
  interface Block { patterns: string[]; fields: Map<string, string> }
44
133
  const blocks: Block[] = []
@@ -67,6 +156,11 @@ export function parseSshConfig(text: string): ParsedImport {
67
156
  current.fields.set(key, value)
68
157
  }
69
158
  }
159
+ // Pass 1: which names become hosts at all. The proxy decision is resolved in
160
+ // pass 2 because `ProxyJump` may name a block that appears LATER in the file —
161
+ // and because a jump host that is itself skipped (no IdentityFile) must not be
162
+ // recorded as a live alias.
163
+ const candidates: CandidateHost[] = []
70
164
  for (const block of blocks) {
71
165
  // A `Host a b` line declares TWO names with the same fields: import each
72
166
  // concrete pattern instead of silently dropping everything after the first.
@@ -79,10 +173,6 @@ export function parseSshConfig(text: string): ParsedImport {
79
173
  if (special.length === 0) skipped.push({ alias: '(empty)', reason: 'Host line has no pattern' })
80
174
  continue
81
175
  }
82
- if (block.fields.has('proxyjump') || block.fields.has('proxycommand')) {
83
- for (const alias of concrete) skipped.push({ alias, reason: 'proxyJump/proxyCommand needs P1 (direct hosts only in P0)' })
84
- continue
85
- }
86
176
  const rawPort = block.fields.get('port')
87
177
  const port = rawPort === undefined ? 22 : validPort(rawPort)
88
178
  const identityFile = block.fields.get('identityfile')?.split(/\s+/)[0]
@@ -102,16 +192,35 @@ export function parseSshConfig(text: string): ParsedImport {
102
192
  skipped.push({ alias, reason: 'no IdentityFile in ssh_config — add the key or password after import' })
103
193
  continue
104
194
  }
105
- payloads.push({
195
+ candidates.push({
106
196
  alias,
107
- host: block.fields.get('hostname') ?? alias,
197
+ hostname: block.fields.get('hostname') ?? alias,
108
198
  port,
109
199
  user,
110
- auth: { kind: 'key', keyPath: expandHome(identityFile) },
111
- tags: ['imported:ssh-config'],
200
+ identityFile,
201
+ fields: block.fields,
112
202
  })
113
203
  }
114
204
  }
205
+ // Pass 2: the egress decision, against the names pass 1 will actually create.
206
+ const index = nameIndex(candidates)
207
+ const payloads: HostPayload[] = []
208
+ for (const candidate of candidates) {
209
+ const resolution = resolveProxy(candidate.alias, candidate.fields, index)
210
+ if (!resolution.ok) {
211
+ skipped.push({ alias: candidate.alias, reason: resolution.reason })
212
+ continue
213
+ }
214
+ payloads.push({
215
+ alias: candidate.alias,
216
+ host: candidate.hostname,
217
+ port: candidate.port,
218
+ user: candidate.user,
219
+ auth: { kind: 'key', keyPath: expandHome(candidate.identityFile) },
220
+ tags: ['imported:ssh-config'],
221
+ ...(resolution.proxy === undefined ? {} : { proxy: resolution.proxy }),
222
+ })
223
+ }
115
224
  return { payloads, skipped }
116
225
  }
117
226
 
@@ -148,7 +257,10 @@ export function migrateDshSsh(home: string = dshHome()): ParsedImport {
148
257
  continue
149
258
  }
150
259
  if (hasProxy) {
151
- skipped.push({ alias, reason: 'proxyJump/proxyCommand needs P1 (direct hosts only in P0)' })
260
+ // dsh-ssh.json stores the SAME two directives in its own shape; mapping
261
+ // them would mean a second parser with no cfg sample to verify against, so
262
+ // this path keeps refusing and says where the mapping DOES exist.
263
+ skipped.push({ alias, reason: "proxyJump/proxyCommand in dsh-ssh.json is not mapped — import from ~/.ssh/config instead" })
152
264
  continue
153
265
  }
154
266
  if (kind === 'key' && (typeof auth.keyPath !== 'string' || auth.keyPath.trim() === '')) {
package/src/keygen.ts CHANGED
@@ -117,8 +117,15 @@ export async function bootstrap(pool: RemotePool, store: RemoteStore, alias: str
117
117
  if (!result.success) {
118
118
  throw new Error(`key install failed [exit code: ${result.exitCode}]: ${result.stderr || result.stdout || result.error || 'unknown'}`)
119
119
  }
120
+ // Order matters and matches the host PATCH route: flip the entry FIRST, then
121
+ // drop the connection, so a dial racing this request cannot slip in a
122
+ // password-auth connection that nobody tears down afterwards.
120
123
  store.update(alias, { auth: { kind: 'key', keyPath: privatePath } })
121
- pool.drop(alias)
124
+ // `forget`, not `drop`: the old auth attempt's verdict ("password rejected",
125
+ // "key not installed yet") describes a credential this entry no longer uses,
126
+ // so it must not survive to colour the chip. The `test()` below records the
127
+ // new verdict against the key.
128
+ pool.forget(alias)
122
129
  // Verify the new key actually works before declaring victory.
123
130
  const check = await pool.test(alias)
124
131
  if (!check.ok) {