dsh-remote-vs 0.29.0 → 0.31.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 (58) hide show
  1. package/README.en.md +53 -20
  2. package/README.md +41 -19
  3. package/THIRD-PARTY-NOTICES.md +6 -6
  4. package/cordis.patch.yml +31 -76
  5. package/lib/client.js +319 -91
  6. package/lib/index.js +845 -129
  7. package/lib/p2-router-fs.js +15 -1
  8. package/lib/types/changes/recorder.d.ts +65 -10
  9. package/lib/types/changes/status.d.ts +48 -3
  10. package/lib/types/client/ConnectionsSection.d.ts +73 -0
  11. package/lib/types/client/WorkspacesView.d.ts +2 -0
  12. package/lib/types/client/api.d.ts +41 -2
  13. package/lib/types/client/composer.d.ts +8 -1
  14. package/lib/types/client/scm/actions.d.ts +25 -1
  15. package/lib/types/client/selection-popup.d.ts +1 -1
  16. package/lib/types/client/ui.d.ts +7 -4
  17. package/lib/types/p2/helper-rpc.d.ts +48 -0
  18. package/lib/types/p2/router-fs.d.ts +9 -1
  19. package/lib/types/p2/worlds.d.ts +51 -0
  20. package/lib/types/pool.d.ts +245 -10
  21. package/lib/types/protocol.d.ts +96 -0
  22. package/lib/{worlds-RG8K5eom.js → worlds-BdxLeKul.js} +134 -7
  23. package/package.json +46 -46
  24. package/src/changes/recorder.ts +151 -15
  25. package/src/changes/status.ts +59 -4
  26. package/src/client/ConnectionsSection.tsx +359 -0
  27. package/src/client/DirectoryFlow.tsx +8 -0
  28. package/src/client/EditorPane.tsx +5 -1
  29. package/src/client/HostsView.tsx +2 -0
  30. package/src/client/MonitorView.tsx +14 -0
  31. package/src/client/RemoteExplorer.tsx +11 -2
  32. package/src/client/RemoteRoot.tsx +1 -0
  33. package/src/client/SettingsHosts.tsx +1 -0
  34. package/src/client/WorkspaceWizard.tsx +1 -0
  35. package/src/client/WorkspacesView.tsx +21 -1
  36. package/src/client/api.ts +72 -4
  37. package/src/client/composer.ts +8 -1
  38. package/src/client/i18n.ts +50 -2
  39. package/src/client/scm/DiffView.tsx +5 -2
  40. package/src/client/scm/actions.ts +63 -12
  41. package/src/client/selection-popup.ts +1 -1
  42. package/src/client/ui.tsx +9 -7
  43. package/src/client/vsc/vsc.css +231 -3
  44. package/src/index.ts +31 -0
  45. package/src/p2/helper-rpc.ts +73 -5
  46. package/src/p2/router-fs.ts +29 -1
  47. package/src/p2/worlds.ts +116 -1
  48. package/src/pool.ts +736 -111
  49. package/src/protocol.ts +100 -0
  50. package/src/routes.ts +85 -13
  51. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.3-alpha.3-linux-x64.helper.json +20 -0
  52. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.3-alpha.3-linux-x64.tar.gz +4 -0
  53. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.3-alpha.3-linux-x64.tar.gz.sha256 +1 -0
  54. package/vendor/dsh-remote-helpers/pkg-sea-bare-import.patch +30 -0
  55. package/vendor/dsh-remote-helpers/ssh-helper-runtime-deps.patch +4 -3
  56. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.helper.json +0 -19
  57. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.tar.gz +0 -4
  58. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.tar.gz.sha256 +0 -1
@@ -12,6 +12,54 @@
12
12
  * scheme gets the GitHub-Light set from the `body:not(...)` block below).
13
13
  */
14
14
 
15
+ /**
16
+ * Native `<select>` popups are painted by the browser from each `<option>`'s
17
+ * own computed colors. `Canvas`/`CanvasText` resolve against the PAGE's
18
+ * `color-scheme`, and DSH never switches that — it marks the theme on <body>
19
+ * (`body[data-ds-dark-theme]`) — so the open list stayed white in dark mode
20
+ * while the closed control was dark.
21
+ *
22
+ * The tokens live on <body>, NOT on `.rvs-root`, because the plugin also
23
+ * renders selects on the host Settings page (Remote hosts), outside the
24
+ * Workbench root. Values are OPAQUE on purpose — a popup cannot composite a
25
+ * translucent surface over the page — and measured with the WCAG formula:
26
+ * light #1f1f1f on #ffffff ≈ 15.7:1
27
+ * dark #cccccc on #3c3c3c ≈ 7.1:1
28
+ */
29
+ body {
30
+ --rvs-option-bg: #ffffff;
31
+ --rvs-option-fg: #1f1f1f;
32
+ }
33
+
34
+ body[data-ds-dark-theme] {
35
+ --rvs-option-bg: #3c3c3c;
36
+ --rvs-option-fg: #cccccc;
37
+ }
38
+
39
+ /**
40
+ * Selects whose popup needs theming: `.rvs-select` is the workbench's own
41
+ * dropdown, `.rvs-dropdown` marks the inline-styled native selects (Settings,
42
+ * host forms, workspace wizard). `color-scheme` is stated per theme so the
43
+ * popup's own chrome (scrollbar, focus ring) follows it too — `light dark`
44
+ * kept the UA on the page scheme, which never turns dark.
45
+ */
46
+ .rvs-select,
47
+ .rvs-dropdown {
48
+ color-scheme: light;
49
+ }
50
+
51
+ body[data-ds-dark-theme] .rvs-select,
52
+ body[data-ds-dark-theme] .rvs-dropdown {
53
+ color-scheme: dark;
54
+ }
55
+
56
+ .rvs-select option,
57
+ .rvs-dropdown option {
58
+ background-color: var(--rvs-option-bg);
59
+ color: var(--rvs-option-fg);
60
+ }
61
+
62
+
15
63
  .rvs-root {
16
64
  --rvs-fg: var(--dsw-alias-label-primary, #e6e6e6);
17
65
  --rvs-fg2: var(--dsw-alias-label-secondary, #b9b9b9);
@@ -1000,12 +1048,16 @@ body:not([data-ds-dark-theme]) .rvs-fi {
1000
1048
  font: inherit;
1001
1049
  font-size: 12px;
1002
1050
  outline: none;
1003
- color-scheme: light dark;
1051
+ color-scheme: light;
1052
+ }
1053
+
1054
+ body[data-ds-dark-theme] .rvs-select {
1055
+ color-scheme: dark;
1004
1056
  }
1005
1057
 
1006
1058
  .rvs-select option {
1007
- background: Canvas;
1008
- color: CanvasText;
1059
+ background-color: var(--rvs-option-bg);
1060
+ color: var(--rvs-option-fg);
1009
1061
  }
1010
1062
 
1011
1063
  /* ------------------------------------------------- conversation-view mount */
@@ -5271,6 +5323,12 @@ body[data-ds-dark-theme] .rvs-doctor {
5271
5323
  flex: 0 1 auto;
5272
5324
  }
5273
5325
 
5326
+ /* Same rule for the connection-pool section: whichever collapsible section is
5327
+ open gets the room, the metric cards keep their natural height. */
5328
+ .rvs-monitor-body:has(.rvs-pool.expanded) .rvs-monitor-content {
5329
+ flex: 0 1 auto;
5330
+ }
5331
+
5274
5332
  /* The rail title and the scope picker both wanted flex:1; the title yields so
5275
5333
  the picker keeps enough width for its own label at 230px. */
5276
5334
  .rvs-monitor-header .rvs-title {
@@ -6486,6 +6544,176 @@ body[data-ds-dark-theme] .rvs-doctor {
6486
6544
  }
6487
6545
  }
6488
6546
 
6547
+ /* === SSH connection-pool section (monitor page) =========================== */
6548
+
6549
+ /* Collapsed it is a single header row under the process section; expanded it
6550
+ takes the leftover height (basis:0, so the list scrolls instead of pushing
6551
+ the metric cards off the pane). Same shape as `.rvs-proc`. */
6552
+ .rvs-pool {
6553
+ flex: 0 0 auto;
6554
+ border-top: 1px solid var(--rvs-editor-chrome-border, var(--rvs-border));
6555
+ background: var(--rvs-layer3);
6556
+ }
6557
+
6558
+ .rvs-pool.expanded {
6559
+ display: flex;
6560
+ flex: 1 1 0;
6561
+ flex-direction: column;
6562
+ min-height: 120px;
6563
+ }
6564
+
6565
+ .rvs-pool-head {
6566
+ display: flex;
6567
+ align-items: center;
6568
+ gap: 4px;
6569
+ padding: 4px 8px;
6570
+ min-height: 26px;
6571
+ }
6572
+
6573
+ .rvs-pool-toggle {
6574
+ display: inline-flex;
6575
+ align-items: center;
6576
+ justify-content: center;
6577
+ width: 18px;
6578
+ height: 18px;
6579
+ padding: 0;
6580
+ border: 0;
6581
+ background: transparent;
6582
+ color: var(--rvs-fg2);
6583
+ cursor: pointer;
6584
+ }
6585
+
6586
+ .rvs-pool-title {
6587
+ flex: 0 0 auto;
6588
+ font-weight: 600;
6589
+ font-size: 11px;
6590
+ }
6591
+
6592
+ /* 台/条/排队 counts: tabular-nums keeps the header from twitching when a
6593
+ channel count changes on its own poll. */
6594
+ .rvs-pool-summary {
6595
+ flex: 1 1 auto;
6596
+ min-width: 0;
6597
+ overflow: hidden;
6598
+ text-overflow: ellipsis;
6599
+ white-space: nowrap;
6600
+ color: var(--rvs-fg3);
6601
+ font-size: 10px;
6602
+ font-variant-numeric: tabular-nums;
6603
+ }
6604
+
6605
+ .rvs-pool-collapsed {
6606
+ padding: 0 8px 5px;
6607
+ color: var(--rvs-fg3);
6608
+ font-size: 10px;
6609
+ }
6610
+
6611
+ /* The one-line degrade/loading/empty copy. Muted on purpose: "this Host does
6612
+ not report pool statistics" is information, not a failure of the link the
6613
+ metric cards above are already reporting on. */
6614
+ .rvs-pool-note {
6615
+ display: flex;
6616
+ align-items: center;
6617
+ gap: 4px;
6618
+ padding: 0 8px 5px;
6619
+ color: var(--rvs-fg3);
6620
+ font-size: 10px;
6621
+ }
6622
+
6623
+ /* A real request failure is the exception: it keeps the readable server text
6624
+ but colours it, because something IS wrong. */
6625
+ .rvs-pool-note.error {
6626
+ color: var(--rvs-danger-text);
6627
+ }
6628
+
6629
+ .rvs-pool-list {
6630
+ flex: 1 1 auto;
6631
+ min-height: 0;
6632
+ overflow: auto;
6633
+ scrollbar-width: thin;
6634
+ }
6635
+
6636
+ .rvs-pool-host {
6637
+ padding: 4px 8px 6px;
6638
+ border-bottom: 1px solid var(--rvs-border);
6639
+ }
6640
+
6641
+ .rvs-pool-host:last-child {
6642
+ border-bottom: 0;
6643
+ }
6644
+
6645
+ .rvs-pool-host-head {
6646
+ display: flex;
6647
+ align-items: center;
6648
+ gap: 6px;
6649
+ }
6650
+
6651
+ .rvs-pool-host-alias {
6652
+ flex: 1 1 auto;
6653
+ min-width: 0;
6654
+ overflow: hidden;
6655
+ text-overflow: ellipsis;
6656
+ white-space: nowrap;
6657
+ font-weight: 600;
6658
+ font-size: 11px;
6659
+ }
6660
+
6661
+ /* "排队 N" badge: the same signal the ordering uses, so the first row is the
6662
+ one with a queue and it is obvious WHY it is first. */
6663
+ .rvs-pool-queue {
6664
+ flex: none;
6665
+ padding: 0 4px;
6666
+ border: 1px solid var(--rvs-danger-text);
6667
+ border-radius: 3px;
6668
+ color: var(--rvs-danger-text);
6669
+ font-size: 9px;
6670
+ font-variant-numeric: tabular-nums;
6671
+ }
6672
+
6673
+ /* Name | state column, with the egress line spanning the second column under
6674
+ the shared lane it belongs to. */
6675
+ .rvs-pool-lane {
6676
+ display: grid;
6677
+ grid-template-columns: 56px minmax(0, 1fr);
6678
+ column-gap: 6px;
6679
+ align-items: baseline;
6680
+ font-size: 10px;
6681
+ }
6682
+
6683
+ .rvs-pool-lane-name {
6684
+ color: var(--rvs-fg3);
6685
+ }
6686
+
6687
+ .rvs-pool-lane-state {
6688
+ color: var(--rvs-fg2);
6689
+ font-variant-numeric: tabular-nums;
6690
+ }
6691
+
6692
+ /* A dialled lane is the fact the user came for; an idle one stays dim. */
6693
+ .rvs-pool-lane-state.open {
6694
+ color: var(--rvs-fg);
6695
+ }
6696
+
6697
+ /* Both the shared connection's route and the "files fell back to it" marker sit
6698
+ under the lane they belong to, in the second grid column. */
6699
+ .rvs-pool-egress,
6700
+ .rvs-pool-fallback {
6701
+ grid-column: 2;
6702
+ overflow: hidden;
6703
+ text-overflow: ellipsis;
6704
+ white-space: nowrap;
6705
+ color: var(--rvs-fg3);
6706
+ }
6707
+
6708
+ .rvs-pool-slots {
6709
+ display: flex;
6710
+ flex-wrap: wrap;
6711
+ gap: 0 10px;
6712
+ color: var(--rvs-fg3);
6713
+ font-size: 10px;
6714
+ font-variant-numeric: tabular-nums;
6715
+ }
6716
+
6489
6717
  /* ------------------------------------------------------ Ctrl+P quick open */
6490
6718
 
6491
6719
  .rvs-qo-mask {
package/src/index.ts CHANGED
@@ -334,6 +334,37 @@ export function apply(ctx: Context, config?: ResolvedConfig): void {
334
334
  })
335
335
  ctx.effect(() => () => { changes.dispose() }, 'dsh-remote-vs: changes ledger')
336
336
 
337
+ /**
338
+ * DSH's own sidebar can delete a Workspace. That is the user removing it
339
+ * outright, so the remote binding that named it must go too (tombstoned by
340
+ * `removeWorkspace`, keeping sessions readable). The REVERSE direction is
341
+ * deliberately asymmetric: unbinding from this plugin keeps the native
342
+ * Workspace record and only adds a fail-closed tombstone — the user asked for
343
+ * exactly that, so a tombstone never vanishes from DSH's workspace list.
344
+ *
345
+ * `domain/changed` is a host-internal event, hence the structural cast: it is
346
+ * not part of this plugin's inject surface, and a host without it simply keeps
347
+ * the old behaviour (the deletion stays local).
348
+ */
349
+ try {
350
+ (ctx as unknown as {
351
+ on(event: string, handler: (change: { domain?: string; table?: string; operation?: string; key?: string }) => void): void
352
+ }).on('domain/changed', (change) => {
353
+ try {
354
+ if (change.domain !== 'workspace' || change.table !== 'workspaces') return
355
+ if (change.operation !== 'deleted' || typeof change.key !== 'string') return
356
+ const removed = worlds.forgetNativeWorkspace(change.key)
357
+ if (removed !== undefined) {
358
+ ctx.logger.info(`[remote-vs] native workspace deleted: binding ${removed} unbound`)
359
+ }
360
+ } catch {
361
+ // A cascade failure must never break the host's domain notification.
362
+ }
363
+ })
364
+ } catch {
365
+ // Ignore: a host without the event keeps the deletion local.
366
+ }
367
+
337
368
  /**
338
369
  * Local port forwards (`ssh -L`) — resident listeners with their own
339
370
  * lifecycle, on purpose.
@@ -10,6 +10,7 @@ import { SshRpcPeer, SSH_PROTOCOL_VERSION } from '@deepseek-ai/dsh-ssh/protocol'
10
10
  import { helloSchema } from '@deepseek-ai/dsh-ssh/schemas'
11
11
  import { z } from 'zod'
12
12
  import type { RemoteHostEntry } from '../protocol.ts'
13
+ import type { RoutedDial } from '../pool.ts'
13
14
  import { InFlightGate } from './in-flight-gate.ts'
14
15
 
15
16
  export interface RpcDialOpts {
@@ -21,6 +22,26 @@ export interface RpcDialOpts {
21
22
  /** Remote default workspace for the hello handshake. */
22
23
  workspace: string
23
24
  leaseMs?: number
25
+ /**
26
+ * The HOST's routed transport for this alias (proxy tunnel / jump-host channel),
27
+ * optional so a caller without a pool still dials directly.
28
+ *
29
+ * Without it this transport is a BARE direct connection: a host reachable only
30
+ * through a proxy or jump host would answer exec/SFTP (the pool honours the
31
+ * route) and fail every file/Git fast path — the "some features work, some do
32
+ * not" report. The pool supplies it via `openRoutedSocket`; the returned
33
+ * `release` is called here (once) on failure, close, reconnect and dispose.
34
+ */
35
+ openSocket?: () => Promise<RoutedDial>
36
+ /**
37
+ * The ssh2 client factory.
38
+ *
39
+ * A seam, not a preference — the same one `RemotePool.makeClient` has: the only
40
+ * way a self-check can observe what this transport hands ssh2 (`{sock}` with no
41
+ * `host`/`port` for a routed dial, the reverse for a direct one) without a real
42
+ * server. Production never overrides it.
43
+ */
44
+ makeClient?: () => Client
24
45
  }
25
46
 
26
47
  export interface RpcHello {
@@ -174,6 +195,17 @@ export class RpcConnection {
174
195
  * grow host memory.
175
196
  */
176
197
  private stderrTail = ''
198
+ /**
199
+ * Teardown of the ROUTED transport this attempt rides (proxy socket / jump-host
200
+ * tunnel), or undefined for a direct dial.
201
+ *
202
+ * It lives on the instance because the release has to outlive the handshake: the
203
+ * tunnel must stay open exactly as long as the SSH connection rides it, so the
204
+ * call belongs in `teardownTransport` (dispose, reconnect, failed open) rather
205
+ * than in the dial promise. The pool's release is idempotent, so calling it from
206
+ * a failure path AND from the teardown is safe.
207
+ */
208
+ private releaseRoute: (() => void) | undefined
177
209
  /** Per-connection in-flight cap; see MAX_IN_FLIGHT. */
178
210
  private readonly gate = new InFlightGate(MAX_IN_FLIGHT)
179
211
 
@@ -189,6 +221,18 @@ export class RpcConnection {
189
221
  return this.stderrTail.trim()
190
222
  }
191
223
 
224
+ /**
225
+ * How many helper calls are in flight right now.
226
+ *
227
+ * Read-only diagnostics for the monitor: the helper caps itself at its own
228
+ * gate, so a saturated helper shows up as a number here instead of looking
229
+ * like an idle connection. It is NOT a queue — a call waits inside the gate
230
+ * before it counts, so this number never exceeds the gate's ceiling.
231
+ */
232
+ get inFlight(): number {
233
+ return this.gate.inFlight
234
+ }
235
+
192
236
  get ready(): Promise<RpcHello> {
193
237
  if (this.readyPromise === undefined) this.readyPromise = this.open()
194
238
  return this.readyPromise
@@ -327,10 +371,17 @@ export class RpcConnection {
327
371
  this.channel = undefined
328
372
  this.conn = undefined
329
373
  this.stderrTail = ''
374
+ // LAST: give the tunnel back after the connection riding it is closed (for a
375
+ // jump host this closes the channel and releases the hold; for a proxy it
376
+ // destroys the socket). Idempotent on the pool side, so a failure path that
377
+ // already released is fine.
378
+ const release = this.releaseRoute
379
+ this.releaseRoute = undefined
380
+ release?.()
330
381
  }
331
382
 
332
383
  private async open(): Promise<RpcHello> {
333
- const conn = new Client()
384
+ const conn = this.opts.makeClient?.() ?? new Client()
334
385
  this.conn = conn
335
386
  try {
336
387
  const hello = await this.dialAndHello(conn)
@@ -362,6 +413,19 @@ export class RpcConnection {
362
413
  // teardown is about a link nobody owns any more; the callbacks below compare
363
414
  // against the live value before touching `dead`/`stderrTail`.
364
415
  const generation = this.generation
416
+ /**
417
+ * The route the HOST resolves for this alias — a proxy tunnel socket or a
418
+ * jump-host channel — or nothing for a direct connection. It is acquired
419
+ * BEFORE the handshake so a route failure surfaces as itself (`proxy auth
420
+ * failed: …` / `jump host "x" failed: …`) instead of as a mysterious
421
+ * connection timeout.
422
+ *
423
+ * The release is stashed for `teardownTransport`, which runs on every way this
424
+ * attempt can end (ready-then-lost, failed open, reconnect, dispose). If the
425
+ * acquisition itself throws there is nothing to release.
426
+ */
427
+ const routed = this.opts.openSocket === undefined ? undefined : await this.opts.openSocket()
428
+ if (routed !== undefined) this.releaseRoute = routed.release
365
429
  await new Promise<void>((resolve, reject) => {
366
430
  let settled = false
367
431
  conn.on('ready', () => {
@@ -390,10 +454,15 @@ export class RpcConnection {
390
454
  if (generation === this.generation) this.invalidate(new Error('ssh connection closed'))
391
455
  })
392
456
  try {
457
+ // `{ sock }` and NOT `host`/`port`: a routed transport is the socket ssh2
458
+ // must ride, and passing both would let ssh2 pick between dialing the
459
+ // target itself and riding the tunnel (the same rule `pool.dial` follows).
460
+ const transport = routed?.sock === undefined
461
+ ? { host: entry.host, port: entry.port }
462
+ : { sock: routed.sock }
393
463
  if (entry.auth.kind === 'key') {
394
464
  conn.connect({
395
- host: entry.host,
396
- port: entry.port,
465
+ ...transport,
397
466
  username: entry.user,
398
467
  privateKey: readFileSync(entry.auth.keyPath as string),
399
468
  passphrase: entry.auth.passphrase,
@@ -403,8 +472,7 @@ export class RpcConnection {
403
472
  })
404
473
  } else {
405
474
  conn.connect({
406
- host: entry.host,
407
- port: entry.port,
475
+ ...transport,
408
476
  username: entry.user,
409
477
  password: entry.auth.password,
410
478
  readyTimeout: CONNECT_READY_TIMEOUT_MS,
@@ -15,6 +15,7 @@ import type {
15
15
  FsPathInfo,
16
16
  FsTarget,
17
17
  FsVersion,
18
+ FsWriteBytesOutcome,
18
19
  FsWriteIntent,
19
20
  FsWriteOutcome,
20
21
  } from '@deepseek-ai/dsh-fs'
@@ -225,8 +226,16 @@ export default class TransparentFileSystem extends FileSystem {
225
226
  if (pw.kind !== cw.kind) return false
226
227
  if (pw.kind === 'local') return this.localFs.contains(parent, child)
227
228
  if (pw.id !== (cw as Extract<WorldRoute, { kind: 'remote' }>).id) return false
228
- // Same remote binding: containment by remote path order.
229
+ // Same remote binding: let the remote provider answer. Comparing process
230
+ // paths here assumed both sides keep the same spelling, and since alpha.3
231
+ // the binding ROOT commits the alias spelling (the workspace record needs a
232
+ // path that exists on the Host) while its children stay remote-spelled —
233
+ // that pair shares no prefix. The provider owns its target identity, so its
234
+ // own containment is the correct answer; the path compare stays as the
235
+ // fallback for a provider view that is not cached yet.
229
236
  try {
237
+ const remoteFs = this.remote.cachedFs(pw.alias)
238
+ if (remoteFs !== undefined) return remoteFs.contains(parent, child)
230
239
  const left = this.processPath(parent)
231
240
  const right = this.processPath(child)
232
241
  return right === left || right.startsWith(left.endsWith('/') ? left : `${left}/`)
@@ -311,6 +320,25 @@ export default class TransparentFileSystem extends FileSystem {
311
320
  return fs.writeText(target, content, expected, signal, this.remote.rewritePolicy(sandboxPolicy, world))
312
321
  }
313
322
 
323
+ /**
324
+ * alpha.3's `FileSystem` gained verbatim byte writes. The base class rejects
325
+ * them, so a router that only forwards text silently turned every remote byte
326
+ * write (document-preview renders, attachment materialization) into a
327
+ * capability regression. Delegate like `writeText`; a provider from an older
328
+ * generation still fails as a typed `FsError` instead of a `TypeError`.
329
+ */
330
+ async writeBytes(
331
+ target: FsTarget,
332
+ data: Uint8Array,
333
+ expected?: FsWriteIntent,
334
+ signal?: AbortSignal,
335
+ sandboxPolicy?: SandboxExecutionPolicy,
336
+ ): Promise<FsWriteBytesOutcome> {
337
+ const { fs, world } = await this.backendOf(target)
338
+ if (typeof fs.writeBytes !== 'function') throw this.unsupportedRemote('writing bytes')
339
+ return fs.writeBytes(target, data, expected, signal, this.remote.rewritePolicy(sandboxPolicy, world))
340
+ }
341
+
314
342
  async editText(
315
343
  target: FsTarget,
316
344
  edit: FsEditRequest,
package/src/p2/worlds.ts CHANGED
@@ -82,7 +82,24 @@ const DIAL_IMMEDIATE_RETRIES = 2
82
82
 
83
83
  export class RemoteWorlds {
84
84
  private readonly rpcs = new Map<string, Promise<RpcConnection>>()
85
+ /**
86
+ * Aliases whose helper connection is still being dialed.
87
+ *
88
+ * `rpcs` holds the PROMISE, so a caller that awaits it waits for the whole
89
+ * dial (up to `CONNECT_READY_TIMEOUT_MS`, 45 s through a proxy or a jump host).
90
+ * The monitor polls `helperLane` every few seconds and must never inherit that
91
+ * wait — the route is read-only and would report the previous sample for the
92
+ * whole dial, or hold the client's single-flight guard. A name in this set is
93
+ * therefore "cannot say yet", which the client already renders as no row.
94
+ */
95
+ private readonly dialingRpc = new Map<string, Promise<RpcConnection>>()
85
96
  private readonly fsViews = new Map<string, Promise<FsView>>()
97
+ /**
98
+ * Native Workspace registration id -> alias dir, refreshed by every
99
+ * `syncWorkspaces()`. DSH reports a sidebar workspace deletion by its own id,
100
+ * which carries no path, so this is the only way back to the binding.
101
+ */
102
+ private readonly nativeWorkspaces = new Map<string, string>()
86
103
  private readonly fsReady = new Map<string, FsView>()
87
104
  private readonly procs = new Map<string, SshProcRuntime>()
88
105
  /** Consecutive dial failures per alias; while the cooldown is set, no dial is attempted. */
@@ -295,6 +312,15 @@ export class RemoteWorlds {
295
312
  */
296
313
  toSessionPath(route: Extract<WorldRoute, { kind: 'remote' }>, remoteAbsPath: string): string {
297
314
  if (!this.underRemoteBase(route, remoteAbsPath)) return remoteAbsPath
315
+ // alpha.3: a Session's cwd is now validated by the HOST filesystem when the
316
+ // Session is attached to (and indexed under) a Workspace — dsh-workspace
317
+ // realpaths the header spelling and requires it to equal the workspace
318
+ // record path. A remote spelling can never pass that local check, so the
319
+ // ROOT of a binding is always committed with its alias spelling (a real
320
+ // local directory, and exactly what the workspace record holds). Deeper
321
+ // remote paths keep the historical rule: they are only ever reached through
322
+ // this cwd, so their spelling does not become a workspace path.
323
+ if (remoteAbsPath === this.remoteRoot(route)) return route.aliasPath
298
324
  let routed: WorldRoute
299
325
  try {
300
326
  routed = this.routeDir(remoteAbsPath)
@@ -307,9 +333,15 @@ export class RemoteWorlds {
307
333
  return this.toAliasPath(route, remoteAbsPath)
308
334
  }
309
335
 
336
+ /** One binding's remote root, without a trailing slash (except `/` itself). */
337
+ private remoteRoot(route: Extract<WorldRoute, { kind: 'remote' }>): string {
338
+ const root = route.remotePath
339
+ return root.endsWith('/') && root !== '/' ? root.slice(0, -1) : root
340
+ }
341
+
310
342
  /** Inverse of {@link toRemotePath}: the alias spelling of a remote path. */
311
343
  toAliasPath(route: Extract<WorldRoute, { kind: 'remote' }>, remoteAbsPath: string): string {
312
- const base = route.remotePath.endsWith('/') && route.remotePath !== '/' ? route.remotePath.slice(0, -1) : route.remotePath
344
+ const base = this.remoteRoot(route)
313
345
  if (!this.containsRemote(base, remoteAbsPath)) return remoteAbsPath
314
346
  if (remoteAbsPath === base) return route.aliasPath
315
347
  // `containsRemote` already guarded the boundary, so the remainder is a
@@ -379,6 +411,7 @@ export class RemoteWorlds {
379
411
  | {
380
412
  resolveByPath(path: string): Promise<unknown>
381
413
  create(path: string, title?: string): Promise<unknown>
414
+ list?(): readonly { id: unknown; path: string; title?: string }[]
382
415
  }
383
416
  | undefined
384
417
  for (const binding of bindings) {
@@ -423,6 +456,51 @@ export class RemoteWorlds {
423
456
  }
424
457
  }
425
458
  }
459
+ // Remember which NATIVE Workspace record stands for which alias dir. This
460
+ // is the reverse mapping the deletion cascade needs: DSH reports a native
461
+ // workspace deletion by its own id, which is not our binding id.
462
+ this.nativeWorkspaces.clear()
463
+ if (registry === undefined || typeof registry.list !== 'function') return
464
+ let registered: readonly { id: unknown; path: string }[]
465
+ try {
466
+ registered = registry.list()
467
+ } catch {
468
+ return
469
+ }
470
+ for (const workspace of registered) {
471
+ try {
472
+ if (!this.contains(aliasRoot(), workspace.path)) continue
473
+ this.nativeWorkspaces.set(String(workspace.id), workspace.path)
474
+ } catch {
475
+ // Ignore one unreadable record; the rest still index.
476
+ }
477
+ }
478
+ }
479
+
480
+ /**
481
+ * A native Workspace under the alias root was deleted by the user (DSH's own
482
+ * sidebar): its binding follows — unbind + tombstone.
483
+ *
484
+ * The reverse direction is deliberately NOT symmetric: unbinding from this
485
+ * plugin keeps the native Workspace record (the user asked for exactly that —
486
+ * the workspace stays listed and only a fail-closed tombstone is added), while
487
+ * deleting the Workspace in DSH's sidebar is the user removing it outright, so
488
+ * the binding that named it goes with it. Without this, a deleted native
489
+ * workspace left a binding routing into an alias dir nobody can reach.
490
+ *
491
+ * @param nativeId - DSH's Workspace registration id.
492
+ * @returns the binding id that was removed, when one matched.
493
+ */
494
+ forgetNativeWorkspace(nativeId: string): string | undefined {
495
+ const path = this.nativeWorkspaces.get(nativeId)
496
+ if (path === undefined) return undefined
497
+ this.nativeWorkspaces.delete(nativeId)
498
+ if (!this.contains(aliasRoot(), path)) return undefined
499
+ const basename = path.replace(/[\\/]+$/u, '').split(/[\\/]/u).pop() ?? ''
500
+ if (basename === '') return undefined
501
+ const known = this.deps.store.listWorkspaces().some(binding => binding.id === basename)
502
+ if (!known) return undefined
503
+ return this.deps.store.removeWorkspace(basename) ? basename : undefined
426
504
  }
427
505
 
428
506
  // ------------------------------------------------------------ remote contexts
@@ -471,6 +549,30 @@ export class RemoteWorlds {
471
549
  }
472
550
  }
473
551
 
552
+ /**
553
+ * The helper connection of one alias, for the monitor's fifth lane.
554
+ *
555
+ * The helper dials its OWN SSH connection (see `RpcConnection`), so the pool
556
+ * cannot report it — this is the only place that knows. Read-only by
557
+ * contract: it awaits a record that already exists and never starts a dial, a
558
+ * deploy or a reconnect, because the monitor polls this every few seconds and
559
+ * a diagnostic must not be able to bring a helper up (or keep a dead one
560
+ * alive). `undefined` means "cannot say": no record, a record still dialing, or
561
+ * a record the router is about to replace — the client then omits the row
562
+ * rather than claiming the helper is closed.
563
+ */
564
+ async helperLane(alias: string): Promise<{ open: boolean; channels: number; held: number } | undefined> {
565
+ // A record that is still dialing is not an answer: awaiting it would make the
566
+ // monitor wait out the handshake (45 s worst case) for a read-only poll.
567
+ if (this.dialingRpc.has(alias)) return undefined
568
+ const pending = this.rpcs.get(alias)
569
+ if (pending === undefined) return undefined
570
+ const conn = await pending.catch(() => undefined)
571
+ if (conn === undefined || !conn.alive) return undefined
572
+ // One channel is the whole helper transport (exec + JSON-RPC frames).
573
+ return { open: true, channels: 1, held: conn.inFlight }
574
+ }
575
+
474
576
  /** Drop one host's RPC + fs view + proc runtime (call after host update/delete). */
475
577
  async dropHost(alias: string): Promise<void> {
476
578
  this.fsReady.delete(alias)
@@ -635,11 +737,18 @@ export class RemoteWorlds {
635
737
  if (pending === undefined) {
636
738
  pending = this.createRpc(alias)
637
739
  this.rpcs.set(alias, pending)
740
+ this.dialingRpc.set(alias, pending)
638
741
  void pending.then(
639
742
  () => {
743
+ // Identity guard: a host edit (`dropHost`) can start a SECOND dial while
744
+ // this one settles, and an unconditional delete would clear the new
745
+ // dial's mark — `helperLane` would then wait out that dial and the
746
+ // monitor would freeze for it, the exact thing this set prevents.
747
+ if (this.dialingRpc.get(alias) === pending) this.dialingRpc.delete(alias)
640
748
  this.dialFailures.delete(alias)
641
749
  },
642
750
  (error: unknown) => {
751
+ if (this.dialingRpc.get(alias) === pending) this.dialingRpc.delete(alias)
643
752
  if (this.rpcs.get(alias) === pending) this.rpcs.delete(alias)
644
753
  this.noteDialFailure(alias, error)
645
754
  },
@@ -803,6 +912,12 @@ export class RemoteWorlds {
803
912
  helperHash: helper.sha256,
804
913
  workspace: home,
805
914
  leaseMs: 60000,
915
+ // The helper dials its OWN ssh2 client, so it must be handed the route the
916
+ // pool would take (proxy tunnel / jump-host channel): without it a host
917
+ // reachable only through a hop answers exec and SFTP but fails every
918
+ // file/Git path that rides the helper. The pool owns the decision and the
919
+ // error layering; this transport releases the transport when it tears down.
920
+ openSocket: () => this.deps.pool.openRoutedSocket(alias),
806
921
  })
807
922
  try {
808
923
  await conn.ready