dsh-remote-vs 0.25.0 → 0.26.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 (85) hide show
  1. package/README.en.md +11 -7
  2. package/README.md +10 -7
  3. package/THIRD-PARTY-NOTICES.md +188 -0
  4. package/lib/client.js +6512 -79961
  5. package/lib/index.js +1283 -992
  6. package/lib/p2-router-fs.js +1 -1
  7. package/lib/types/client/CodeEditor.d.ts +8 -0
  8. package/lib/types/client/RemoteExplorer.d.ts +53 -0
  9. package/lib/types/client/api.d.ts +37 -2
  10. package/lib/types/client/changes/review-state.d.ts +19 -0
  11. package/lib/types/client/connection.d.ts +16 -0
  12. package/lib/types/client/request-gate.d.ts +110 -0
  13. package/lib/types/client/scm/DiffView.d.ts +45 -7
  14. package/lib/types/client/scm/actions.d.ts +31 -3
  15. package/lib/types/client/store.d.ts +53 -0
  16. package/lib/types/client/vsc/FindWidget.d.ts +6 -0
  17. package/lib/types/client/vsc/change-marks.d.ts +16 -6
  18. package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
  19. package/lib/types/client/vsc/kit.d.ts +11 -0
  20. package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
  21. package/lib/types/client/vsc/terminal-theme.d.ts +28 -2
  22. package/lib/types/forward.d.ts +12 -0
  23. package/lib/types/fs-ops.d.ts +42 -0
  24. package/lib/types/http.d.ts +2 -0
  25. package/lib/types/keygen.d.ts +9 -0
  26. package/lib/types/monitor.d.ts +8 -0
  27. package/lib/types/notices.d.ts +16 -1
  28. package/lib/types/p2/helper-rpc.d.ts +45 -0
  29. package/lib/types/routes.d.ts +2 -0
  30. package/lib/types/store.d.ts +7 -0
  31. package/lib/types/terminal.d.ts +8 -0
  32. package/lib/types/view-settings.d.ts +5 -0
  33. package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
  34. package/package.json +2 -1
  35. package/src/client/CodeEditor.tsx +151 -8
  36. package/src/client/DirectoryFlow.tsx +16 -0
  37. package/src/client/DoctorPanel.tsx +70 -7
  38. package/src/client/EditorPane.tsx +63 -14
  39. package/src/client/HostsView.tsx +12 -3
  40. package/src/client/RemoteDirectoryPicker.tsx +12 -0
  41. package/src/client/RemoteExplorer.tsx +929 -40
  42. package/src/client/RemoteRoot.tsx +147 -22
  43. package/src/client/SearchView.tsx +8 -0
  44. package/src/client/TerminalSnippets.tsx +83 -8
  45. package/src/client/api.ts +106 -13
  46. package/src/client/changes/ChangesDock.tsx +188 -6
  47. package/src/client/changes/changes.css +10 -3
  48. package/src/client/changes/review-state.ts +34 -0
  49. package/src/client/connection.ts +29 -0
  50. package/src/client/downloads.ts +49 -4
  51. package/src/client/i18n.ts +82 -8
  52. package/src/client/request-gate.ts +221 -0
  53. package/src/client/scm/CommitPane.tsx +20 -2
  54. package/src/client/scm/DiffView.tsx +343 -117
  55. package/src/client/scm/HistoryPanel.tsx +23 -2
  56. package/src/client/scm/RepoPicker.tsx +1 -1
  57. package/src/client/scm/ScmPanel.tsx +391 -87
  58. package/src/client/scm/actions.ts +95 -12
  59. package/src/client/store.tsx +372 -9
  60. package/src/client/ui.tsx +4 -0
  61. package/src/client/vsc/FindWidget.tsx +24 -9
  62. package/src/client/vsc/breadcrumb.tsx +91 -3
  63. package/src/client/vsc/change-marks.ts +93 -44
  64. package/src/client/vsc/editor-keymap.ts +59 -1
  65. package/src/client/vsc/file-icons.tsx +17 -3
  66. package/src/client/vsc/kit.tsx +26 -9
  67. package/src/client/vsc/save-shortcut.ts +47 -1
  68. package/src/client/vsc/terminal-theme.ts +44 -18
  69. package/src/client/vsc/vsc.css +411 -153
  70. package/src/forward.ts +47 -9
  71. package/src/fs-ops.ts +124 -4
  72. package/src/git-ops.ts +20 -3
  73. package/src/http.ts +35 -4
  74. package/src/keygen.ts +55 -4
  75. package/src/monitor.ts +13 -0
  76. package/src/notices.ts +23 -1
  77. package/src/p2/helper-rpc.ts +113 -7
  78. package/src/p2/worlds.ts +14 -1
  79. package/src/routes.ts +212 -43
  80. package/src/sftp.ts +51 -14
  81. package/src/store.ts +10 -0
  82. package/src/terminal.ts +73 -26
  83. package/src/view-settings.ts +50 -10
  84. package/lib/types/client/Dialog.d.ts +0 -14
  85. package/src/client/Dialog.tsx +0 -76
@@ -32,6 +32,18 @@ export interface SaveShortcutEvent {
32
32
  defaultPrevented: boolean;
33
33
  target: EventTarget | null;
34
34
  }
35
+ /**
36
+ * Areas where Ctrl+S belongs to somebody else.
37
+ *
38
+ * A terminal (xterm) forwards keys to the remote shell and a themed dialog's
39
+ * input is mid-edit; hijacking the key there would be a surprise, and for the
40
+ * shell it would also steal a control character (`^S`).
41
+ *
42
+ * Exported so the plugin's OTHER window-level shortcut (Ctrl+P in `RemoteRoot`)
43
+ * draws the same line instead of re-inventing a narrower one — it used to
44
+ * exclude only `.xterm` and hijacked the host's chat composer.
45
+ */
46
+ export declare const FOREIGN_TARGET = ".xterm, textarea, input, [contenteditable=\"true\"]";
35
47
  /**
36
48
  * Is this the save shortcut this module should act on?
37
49
  *
@@ -41,6 +53,15 @@ export interface SaveShortcutEvent {
41
53
  export declare function isSaveShortcut(event: SaveShortcutEvent): boolean;
42
54
  /** A registered save target: `undefined` = this surface has nothing to save. */
43
55
  export type SaveShortcutResolver = () => (() => void) | undefined;
56
+ /**
57
+ * Is a modal layer (host approval / settings, our own dialog, an open menu) on
58
+ * screen right now?
59
+ *
60
+ * Called from the DOM listener entry points only: `isSaveShortcut` stays a pure
61
+ * predicate on the event. Without it Ctrl+S silently saved the remote file
62
+ * underneath a pending host approval dialog — a write the user never confirmed.
63
+ */
64
+ export declare function isModalLayerOpen(): boolean;
44
65
  /**
45
66
  * Install the window-level save shortcut for one surface.
46
67
  *
@@ -14,9 +14,35 @@
14
14
  * the gate (`@xterm/xterm`'s entry pulls CSS/UMD code).
15
15
  */
16
16
  import type { ITheme } from '@xterm/xterm';
17
- /** The dark scheme palette. */
17
+ /**
18
+ * The dark scheme palette.
19
+ *
20
+ * Contrast is measured against `background` (#0e0e13): the VS Code Dark+ ANSI
21
+ * set, with red / blue / magenta / brightBlack lifted just past 4.5:1 (`black`
22
+ * is left at #000000 on purpose — ANSI black is a background-fill colour by
23
+ * convention and is not read as text; 1.09:1). `brightCyan` is lifted off the
24
+ * plain cyan (#29b8db sat only ΔE76 6.0 from #11a8cd — the pair read as one
25
+ * colour) to #4dd0e1: ΔE76 18.5, 10.5:1 on the terminal surface.
26
+ */
18
27
  export declare const DARK_TERMINAL_THEME: ITheme;
19
- /** The light scheme palette. */
28
+ /**
29
+ * The light scheme palette.
30
+ *
31
+ * Re-taken for a WHITE background (2026-11-23): the Dark+ ANSI set this used to
32
+ * copy measured 1.0–3.6:1 on #ffffff (brightWhite was white-on-white = 1.00,
33
+ * brightYellow 1.17). Text here is targeted at ≥4.5:1, and every colour is.
34
+ *
35
+ * "Bright" cannot mean "lighter" on white, so the bright group is the more
36
+ * saturated sibling of its hue rather than a lighter one; where a hue had to be
37
+ * re-picked the normal/bright pair keeps a visible difference. `brightWhite` is
38
+ * the one colour that has no readable white-ish form: it is #767676, the
39
+ * lightest neutral of the ramp, which keeps "bright white" distinguishable from
40
+ * `white`/`brightBlack` while reaching 4.54:1 (VS Code Light+ ships #e5e5e5,
41
+ * 1.05:1 — unreadable). `black` stays #000000 (ANSI background-fill convention).
42
+ * `brightCyan` moves to the teal step #0f766e: the previous #0e7490 sat ΔE76
43
+ * 4.0 from `cyan` (#0b6d84) and read as the same colour; the new value is ΔE76
44
+ * 20.5 away at 5.47:1.
45
+ */
20
46
  export declare const LIGHT_TERMINAL_THEME: ITheme;
21
47
  /** The palette for one scheme. */
22
48
  export declare function terminalTheme(dark: boolean): ITheme;
@@ -61,6 +61,18 @@ export declare class ForwardManager {
61
61
  * first listener orphaned — unreachable from the panel and never closed.
62
62
  */
63
63
  private readonly starting;
64
+ /**
65
+ * Rules stopped while their listener was still BINDING.
66
+ *
67
+ * A pending bind is not in `forwards` yet, so `stop()`, `stopAlias()`,
68
+ * `stopAll()` and `dispose()` used to see nothing to close: the listener the
69
+ * OS was about to hand out stayed bound with no panel row left to stop it
70
+ * (click a forward, immediately disable the plugin or delete the host, and
71
+ * `127.0.0.1:<port>` stayed taken until the Host restarted). The id sits here
72
+ * until the bind settles; a settling bind that finds its id records itself as
73
+ * stopped and closes the fresh listener instead of entering `forwards`.
74
+ */
75
+ private readonly stoppedWhileBinding;
64
76
  /** Set on unload so a bind that settles afterwards closes itself. */
65
77
  private disposed;
66
78
  constructor(deps: ForwardManagerDeps);
@@ -6,3 +6,45 @@ export declare function joinAbs(dir: string, name: string): string;
6
6
  export declare function copyIntoCommand(from: string, intoDir: string, name?: string): string;
7
7
  /** Move one path into a directory (`mv`), optionally under a new name. */
8
8
  export declare function moveToCommand(from: string, intoDir: string, name?: string): string;
9
+ /**
10
+ * Validate one removal target: absolute, no `..`, no control characters, and
11
+ * never the filesystem root.
12
+ *
13
+ * `assertAbsPath` legitimately accepts `/` (one character away from `rm -rf -- /`)
14
+ * and rewrites `\` to `/` for Windows-shaped input. A remote POSIX name may
15
+ * legitimately contain a literal backslash, and rewriting it would delete a
16
+ * DIFFERENT path, so removal validation keeps every character as-is and only
17
+ * rejects what cannot be deleted safely.
18
+ */
19
+ export declare function assertRemovablePath(path: string): string;
20
+ /**
21
+ * Build the POSIX sh script that removes `paths`, in order.
22
+ *
23
+ * Each entry prints an indexed marker before and after its own `rm`, so the
24
+ * client can show which path is on the wire, count settled entries and retry
25
+ * exactly the ones that failed. The script ends with `exit 0` on purpose: one
26
+ * failed path is not a failed batch — the markers own the per-path truth (see
27
+ * `parseDeleteMarker`), and the caller falls back to the per-entry route for
28
+ * whatever they report as FAIL.
29
+ */
30
+ export declare function batchRemoveScript(paths: string[]): string;
31
+ /**
32
+ * Split one multi-selection into bounded batches, dropping duplicate paths.
33
+ *
34
+ * Order is preserved (markers are index-based within a batch); the inputs are
35
+ * validated here, before anything touches the remote, so an unquotable path
36
+ * rejects the whole delete instead of starting a half-executed batch.
37
+ */
38
+ export declare function splitBatchRemovePaths(paths: string[]): string[][];
39
+ /**
40
+ * Parse one marker line printed by `batchRemoveScript`.
41
+ *
42
+ * Strict on purpose: remote `rm` diagnostics ("rm: cannot remove …") and a
43
+ * mangled marker must never be mistaken for a settled entry. The index is a
44
+ * plain non-negative integer (no sign, no decimal) because it indexes the
45
+ * batch's path list.
46
+ */
47
+ export declare function parseDeleteMarker(line: string): {
48
+ kind: 'item' | 'ok' | 'fail';
49
+ index: number;
50
+ } | undefined;
@@ -44,6 +44,8 @@ export declare function readJsonBody(req: IncomingMessage, opts?: {
44
44
  maxBytes?: number;
45
45
  objectOnly?: boolean;
46
46
  }): Promise<unknown | null>;
47
+ /** Declare which host the response being written concerns (`null` = no host). */
48
+ export declare function scopeHostNotices(res: ServerResponse, alias: string | null): void;
47
49
  /** Write one JSON response. */
48
50
  export declare function writeJson(res: ServerResponse, status: number, body: unknown, headers?: OutgoingHttpHeaders): void;
49
51
  /**
@@ -7,6 +7,15 @@ export interface BootstrapResult {
7
7
  flipped: boolean;
8
8
  detail: string;
9
9
  }
10
+ /**
11
+ * Normalize one `.pub` line to `ssh-ed25519 <base64> dsh-remote-vs/<alias>`.
12
+ *
13
+ * Throws when the line is not a well-formed ed25519 public key, so the caller
14
+ * sees a clear "this file is not a key" error instead of a remote login that
15
+ * fails later. The returned text is the only form that may enter the shell
16
+ * command: its comment is ours, and both remaining fields are shell-inert.
17
+ */
18
+ export declare function formatPublicKey(raw: string, alias: string): string;
10
19
  /** Ensure the managed keypair exists; return the private key path. */
11
20
  export declare function ensureKeypair(alias: string, dir?: string): Promise<{
12
21
  privatePath: string;
@@ -53,5 +53,13 @@ export declare class HostMonitor {
53
53
  sample(alias: string, force?: boolean): Promise<RemoteHostMetrics>;
54
54
  /** Drop everything known about one alias (host edited or deleted). */
55
55
  forget(alias: string): void;
56
+ /**
57
+ * Snapshots already in the cache, without dialing anything.
58
+ *
59
+ * A GET must not have a dial side effect: listing what the Host knows is the
60
+ * read-only shape, and only an explicit per-host request (or the opt-in batch
61
+ * flag) may wake a sleeping host.
62
+ */
63
+ cached(): RemoteHostMetrics[];
56
64
  private probe;
57
65
  }
@@ -18,5 +18,20 @@ export interface HostNotice {
18
18
  }
19
19
  /** Queue one notice for the next JSON response. */
20
20
  export declare function pushHostNotice(notice: HostNotice): void;
21
- /** Take everything queued; the caller attaches it and the queue starts over. */
21
+ /**
22
+ * Take the notices queued for ONE host alias.
23
+ *
24
+ * A response only reports news about the host it is about. Draining the whole
25
+ * queue from whichever response was written first delivered host A's helper
26
+ * push into a window looking at host B — and consumed it, so A never saw it.
27
+ * Notices for other aliases stay queued for a response about their host.
28
+ */
29
+ export declare function takeHostNotices(alias: string): HostNotice[];
30
+ /**
31
+ * Take everything queued (no host filtering).
32
+ *
33
+ * Kept for callers that own the whole queue — the offline probes reset it, and
34
+ * a response written OUTSIDE the route table has no host to filter by
35
+ * (`src/http.ts` keeps that historical drain-all answer).
36
+ */
22
37
  export declare function drainHostNotices(): HostNotice[];
@@ -38,6 +38,21 @@ export declare class RpcConnection {
38
38
  private heartbeat;
39
39
  private dead;
40
40
  private disposed;
41
+ /**
42
+ * Transport generation, bumped by every teardown.
43
+ *
44
+ * ssh2 does not close synchronously: `Channel.close()` is a PROTOCOL message
45
+ * and `Client.end()`'s socket 'close' arrives later. Those late
46
+ * 'close'/'error' events used to call `invalidate()` after `reconnect()` had
47
+ * already cleared `dead`, marking the BRAND-NEW dial dead: `open()` then
48
+ * released the fresh transport and the retry rejected with the OLD
49
+ * transport's error (probe T6 measured exactly this — a close 5 ms late, a
50
+ * new dial 20 ms). Every transport callback therefore captures the generation
51
+ * it was created under and compares it before acting; a teardown invalidates
52
+ * every callback of the transport it releases, without removing listeners
53
+ * (ssh2 offers no per-callback unsubscribe that would survive a destroy).
54
+ */
55
+ private generation;
41
56
  /**
42
57
  * The helper's own error output, kept so its reason survives.
43
58
  *
@@ -80,10 +95,40 @@ export declare class RpcConnection {
80
95
  * `stderrTail` is cleared too: it describes the connection being torn down, and
81
96
  * keeping it would attribute the NEXT failure to the previous transport's error
82
97
  * output.
98
+ *
99
+ * The generation bump comes FIRST: the close calls below can emit their events
100
+ * synchronously, and anything this transport has queued must already count as
101
+ * stale by then.
83
102
  */
84
103
  private teardownTransport;
85
104
  private open;
86
105
  /** The part of {@link open} that runs once the socket object exists. */
87
106
  private dialAndHello;
107
+ /**
108
+ * Mark the connection dead AND release its transport.
109
+ *
110
+ * Closing the peer alone was not enough: `SshRpcPeer.close()` destroys the
111
+ * exec streams, and ssh2's `Channel.destroy()` does not end the `Client` that
112
+ * carries them — so the session stayed open (30s keepalive and all) while its
113
+ * owner had already written it off as dead. One leaked socket per invalidation,
114
+ * until the process exits. `teardownTransport()` is the only path that ends the
115
+ * Client, so an invalidated connection goes through it too; that is safe to
116
+ * repeat because each field is cleared as it is closed and `closeQuietly`
117
+ * ignores a second close — a later `dispose()`, `reconnect()` or failed
118
+ * `open()` teardown therefore finds nothing left to release.
119
+ *
120
+ * Ordering is deliberate: the peer is closed FIRST so in-flight requests reject
121
+ * with THIS error (the teardown's own close would raise a generic
122
+ * "channel closed" instead), and `stderrTail` is captured BEFORE the teardown,
123
+ * which clears it — otherwise `diagnostics` in the dial path would always
124
+ * report "the helper wrote nothing to stderr".
125
+ *
126
+ * Only an ESTABLISHED transport is released here. While `open()` is still
127
+ * dialing, `conn` is alive and `channel`/`peer` are not, and ending that Client
128
+ * would strand the handshake: ssh2 clears its own ready timer when the socket
129
+ * closes and emits 'close' without an 'error', so the promise `open()` awaits
130
+ * would never settle. `open()` itself releases the attempt instead, once it has
131
+ * a definitive outcome.
132
+ */
88
133
  private invalidate;
89
134
  }
@@ -56,4 +56,6 @@ export declare function makeRoutes(deps: RemoteRoutesDeps): {
56
56
  routes: WebRoute[];
57
57
  upgrade: WebUpgradeRoute;
58
58
  terminalSessions: TerminalSessionRegistry;
59
+ /** Close the terminal upgrade server (plugin unload); idempotent. */
60
+ close: () => void;
59
61
  };
@@ -25,6 +25,13 @@ export declare class RemoteStore {
25
25
  /** File identity when `doc` was read from disk (undefined = `doc` is not known fresh). */
26
26
  private stamp;
27
27
  constructor(file?: string);
28
+ /**
29
+ * Absolute path of the JSON document.
30
+ *
31
+ * Diagnostics only: a corrupt file must name itself in the error a surface
32
+ * shows, otherwise the user only sees "the request failed".
33
+ */
34
+ get filePath(): string;
28
35
  /**
29
36
  * Reload from disk (picks up external edits).
30
37
  *
@@ -72,4 +72,12 @@ export declare class TerminalSessionRegistry {
72
72
  private setPaused;
73
73
  private send;
74
74
  private broadcast;
75
+ /**
76
+ * Send one already-stringified `out` frame to ONE socket with accounting.
77
+ *
78
+ * Shared by `broadcast` and by the replay on `attach`; the byte count must be
79
+ * counted once per socket so the session's brake reflects every socket's
80
+ * backlog (see `Session.pending`).
81
+ */
82
+ private sendOutTo;
75
83
  }
@@ -21,6 +21,11 @@ export declare class RemoteViewSettingsStore {
21
21
  * @returns the settings as stored.
22
22
  */
23
23
  patch(patch: Record<string, unknown>): RemoteViewSettings;
24
+ /**
25
+ * File identity right now; `null` when the file is absent (or cannot be
26
+ * statted — `get()` fails loud on that case anyway).
27
+ */
28
+ private stampOf;
24
29
  /** Write one document atomically: a crash never leaves a half-written file. */
25
30
  private save;
26
31
  }
@@ -17333,8 +17333,14 @@ var RemoteFiles = class {
17333
17333
  });
17334
17334
  this.trackPartial(alias, partial);
17335
17335
  const size = await streamIntoFile(sftp, partial, source, maxBytes);
17336
- if (overwrite) await unlinkAsync(sftp, path).catch(() => void 0);
17337
- await renameAsync(sftp, partial, path);
17336
+ if (overwrite) {
17337
+ const targetStat = await lstatAsync(sftp, path).catch((error) => {
17338
+ if (error.code === SFTP_NO_SUCH_FILE) return void 0;
17339
+ throw error;
17340
+ });
17341
+ if (targetStat !== void 0 && (typeof targetStat.isDirectory === "function" ? targetStat.isDirectory() : (targetStat.mode & 61440) === 16384)) throw new Error(`not a file: ${path} is a directory`);
17342
+ await replaceFile(sftp, partial, path);
17343
+ } else await renameAsync(sftp, partial, path);
17338
17344
  this.forgetPartial(alias, partial);
17339
17345
  this.remember(this.knownDirs, dirKey(alias, dir));
17340
17346
  await this.sweepOrphanDirs(sftp, alias, dir);
@@ -17477,8 +17483,8 @@ var RemoteFiles = class {
17477
17483
  await mkdirAsync(sftp, path);
17478
17484
  } catch (error) {
17479
17485
  const code = error.code;
17480
- if (code !== 4 && code !== void 0) throw error;
17481
- if (code === void 0) try {
17486
+ if (code !== SFTP_FAILURE && code !== void 0) throw error;
17487
+ try {
17482
17488
  await lstatAsync(sftp, path);
17483
17489
  } catch {
17484
17490
  throw error;
@@ -17692,7 +17698,10 @@ async function explainSftpFailure(sftp, path, wanted, cause) {
17692
17698
  const code = cause?.code;
17693
17699
  if (code !== SFTP_NO_SUCH_FILE && code !== SFTP_FAILURE) return void 0;
17694
17700
  const kind = await pathKind(sftp, path);
17695
- if (kind.kind === "missing") return /* @__PURE__ */ new Error(wanted === "directory" ? `no such directory: ${path}` : `no such file: ${path}`);
17701
+ if (kind.kind === "missing") {
17702
+ const hint = code === SFTP_FAILURE ? " (the server reported only status 4: this can also be a permission or disk-space problem)" : "";
17703
+ return /* @__PURE__ */ new Error(wanted === "directory" ? `no such directory: ${path}${hint}` : `no such file: ${path}${hint}`);
17704
+ }
17696
17705
  if (wanted === "directory" && kind.kind !== "dir") return /* @__PURE__ */ new Error(`not a directory: ${path} is ${describeKind(kind)}`);
17697
17706
  if (wanted === "file" && kind.kind === "dir") return /* @__PURE__ */ new Error(`not a file: ${path} is a directory`);
17698
17707
  }
@@ -19006,7 +19015,28 @@ function pushHostNotice(notice) {
19006
19015
  if (pending.length >= MAX_PENDING$1) return;
19007
19016
  pending = [...pending, notice];
19008
19017
  }
19009
- /** Take everything queued; the caller attaches it and the queue starts over. */
19018
+ /**
19019
+ * Take the notices queued for ONE host alias.
19020
+ *
19021
+ * A response only reports news about the host it is about. Draining the whole
19022
+ * queue from whichever response was written first delivered host A's helper
19023
+ * push into a window looking at host B — and consumed it, so A never saw it.
19024
+ * Notices for other aliases stay queued for a response about their host.
19025
+ */
19026
+ function takeHostNotices(alias) {
19027
+ if (pending.length === 0) return [];
19028
+ const taken = pending.filter((notice) => notice.alias === alias);
19029
+ if (taken.length === 0) return [];
19030
+ pending = pending.filter((notice) => notice.alias !== alias);
19031
+ return taken;
19032
+ }
19033
+ /**
19034
+ * Take everything queued (no host filtering).
19035
+ *
19036
+ * Kept for callers that own the whole queue — the offline probes reset it, and
19037
+ * a response written OUTSIDE the route table has no host to filter by
19038
+ * (`src/http.ts` keeps that historical drain-all answer).
19039
+ */
19010
19040
  function drainHostNotices() {
19011
19041
  if (pending.length === 0) return [];
19012
19042
  const drained = pending;
@@ -19191,6 +19221,21 @@ var RpcConnection = class {
19191
19221
  dead;
19192
19222
  disposed = false;
19193
19223
  /**
19224
+ * Transport generation, bumped by every teardown.
19225
+ *
19226
+ * ssh2 does not close synchronously: `Channel.close()` is a PROTOCOL message
19227
+ * and `Client.end()`'s socket 'close' arrives later. Those late
19228
+ * 'close'/'error' events used to call `invalidate()` after `reconnect()` had
19229
+ * already cleared `dead`, marking the BRAND-NEW dial dead: `open()` then
19230
+ * released the fresh transport and the retry rejected with the OLD
19231
+ * transport's error (probe T6 measured exactly this — a close 5 ms late, a
19232
+ * new dial 20 ms). Every transport callback therefore captures the generation
19233
+ * it was created under and compares it before acting; a teardown invalidates
19234
+ * every callback of the transport it releases, without removing listeners
19235
+ * (ssh2 offers no per-callback unsubscribe that would survive a destroy).
19236
+ */
19237
+ generation = 0;
19238
+ /**
19194
19239
  * The helper's own error output, kept so its reason survives.
19195
19240
  *
19196
19241
  * Nothing read this stream before, so a helper that died on startup took its
@@ -19223,11 +19268,13 @@ var RpcConnection = class {
19223
19268
  let attempt = 0;
19224
19269
  for (;;) {
19225
19270
  const peer = await this.peerReady();
19271
+ const generation = this.generation;
19226
19272
  await this.gate.acquire(signal);
19227
19273
  try {
19228
19274
  return await this.withDeadline(peer.request(method, params, schema, signal), method, mutating);
19229
19275
  } catch (error) {
19230
19276
  if (!(error instanceof HelperTimeoutError)) throw error;
19277
+ if (generation !== this.generation) throw error;
19231
19278
  this.invalidate(error);
19232
19279
  if (mutating || attempt >= 1) throw error;
19233
19280
  attempt += 1;
@@ -19273,6 +19320,7 @@ var RpcConnection = class {
19273
19320
  async dispose() {
19274
19321
  if (this.disposed) return;
19275
19322
  this.disposed = true;
19323
+ if (this.peer === void 0 && this.channel === void 0 && this.conn !== void 0) return;
19276
19324
  this.teardownTransport();
19277
19325
  }
19278
19326
  async peerReady() {
@@ -19290,8 +19338,13 @@ var RpcConnection = class {
19290
19338
  * `stderrTail` is cleared too: it describes the connection being torn down, and
19291
19339
  * keeping it would attribute the NEXT failure to the previous transport's error
19292
19340
  * output.
19341
+ *
19342
+ * The generation bump comes FIRST: the close calls below can emit their events
19343
+ * synchronously, and anything this transport has queued must already count as
19344
+ * stale by then.
19293
19345
  */
19294
19346
  teardownTransport() {
19347
+ this.generation += 1;
19295
19348
  if (this.heartbeat !== void 0) {
19296
19349
  clearTimeout(this.heartbeat);
19297
19350
  this.heartbeat = void 0;
@@ -19310,7 +19363,12 @@ var RpcConnection = class {
19310
19363
  const conn = new import_lib.Client();
19311
19364
  this.conn = conn;
19312
19365
  try {
19313
- return await this.dialAndHello(conn);
19366
+ const hello = await this.dialAndHello(conn);
19367
+ if (this.dead !== void 0 || this.disposed) {
19368
+ this.teardownTransport();
19369
+ throw this.dead ?? /* @__PURE__ */ new Error("helper RPC was disposed");
19370
+ }
19371
+ return hello;
19314
19372
  } catch (error) {
19315
19373
  this.teardownTransport();
19316
19374
  throw error;
@@ -19319,6 +19377,7 @@ var RpcConnection = class {
19319
19377
  /** The part of {@link open} that runs once the socket object exists. */
19320
19378
  async dialAndHello(conn) {
19321
19379
  const { entry } = this.opts;
19380
+ const generation = this.generation;
19322
19381
  await new Promise((resolve, reject) => {
19323
19382
  let settled = false;
19324
19383
  conn.on("ready", () => {
@@ -19331,10 +19390,14 @@ var RpcConnection = class {
19331
19390
  if (!settled) {
19332
19391
  settled = true;
19333
19392
  reject(error);
19334
- } else this.invalidate(error);
19393
+ } else if (generation === this.generation) this.invalidate(error);
19335
19394
  });
19336
19395
  conn.on("close", () => {
19337
- this.invalidate(/* @__PURE__ */ new Error("ssh connection closed"));
19396
+ if (!settled) {
19397
+ settled = true;
19398
+ reject(/* @__PURE__ */ new Error("ssh connection closed before it became ready"));
19399
+ }
19400
+ if (generation === this.generation) this.invalidate(/* @__PURE__ */ new Error("ssh connection closed"));
19338
19401
  });
19339
19402
  try {
19340
19403
  if (entry.auth.kind === "key") conn.connect({
@@ -19369,13 +19432,14 @@ var RpcConnection = class {
19369
19432
  });
19370
19433
  this.channel = channel;
19371
19434
  channel.stderr.on("data", (chunk) => {
19435
+ if (generation !== this.generation) return;
19372
19436
  this.stderrTail = (this.stderrTail + chunk.toString("utf8")).slice(-2e3);
19373
19437
  });
19374
19438
  channel.on("close", () => {
19375
- this.invalidate(/* @__PURE__ */ new Error("helper channel closed"));
19439
+ if (generation === this.generation) this.invalidate(/* @__PURE__ */ new Error("helper channel closed"));
19376
19440
  });
19377
19441
  channel.on("error", (error) => {
19378
- this.invalidate(error);
19442
+ if (generation === this.generation) this.invalidate(error);
19379
19443
  });
19380
19444
  const leaseMs = this.opts.leaseMs ?? 3e4;
19381
19445
  const peer = new SshRpcPeer(channel, channel, MAX_FRAME, MAX_PENDING);
@@ -19390,9 +19454,10 @@ var RpcConnection = class {
19390
19454
  if (hello.hash !== this.opts.helperHash) throw new Error("helper digest differs from the deployed artifact");
19391
19455
  if (hello.bootstrapHash !== void 0) throw new Error("helper reported an unexpected PTC bootstrap digest");
19392
19456
  const beat = () => {
19393
- if (this.disposed || this.dead !== void 0) return;
19457
+ if (this.disposed || generation !== this.generation || this.dead !== void 0) return;
19394
19458
  this.heartbeat = setTimeout(() => {
19395
19459
  peer.request("heartbeat", {}, z.null(), AbortSignal.timeout(Math.floor(leaseMs / 2))).catch((error) => {
19460
+ if (generation !== this.generation) return;
19396
19461
  this.invalidate(error instanceof Error ? error : new Error(String(error)));
19397
19462
  }).finally(beat);
19398
19463
  }, Math.floor(leaseMs / 3));
@@ -19407,13 +19472,45 @@ var RpcConnection = class {
19407
19472
  nodeVersion: hello.nodeVersion
19408
19473
  };
19409
19474
  }
19475
+ /**
19476
+ * Mark the connection dead AND release its transport.
19477
+ *
19478
+ * Closing the peer alone was not enough: `SshRpcPeer.close()` destroys the
19479
+ * exec streams, and ssh2's `Channel.destroy()` does not end the `Client` that
19480
+ * carries them — so the session stayed open (30s keepalive and all) while its
19481
+ * owner had already written it off as dead. One leaked socket per invalidation,
19482
+ * until the process exits. `teardownTransport()` is the only path that ends the
19483
+ * Client, so an invalidated connection goes through it too; that is safe to
19484
+ * repeat because each field is cleared as it is closed and `closeQuietly`
19485
+ * ignores a second close — a later `dispose()`, `reconnect()` or failed
19486
+ * `open()` teardown therefore finds nothing left to release.
19487
+ *
19488
+ * Ordering is deliberate: the peer is closed FIRST so in-flight requests reject
19489
+ * with THIS error (the teardown's own close would raise a generic
19490
+ * "channel closed" instead), and `stderrTail` is captured BEFORE the teardown,
19491
+ * which clears it — otherwise `diagnostics` in the dial path would always
19492
+ * report "the helper wrote nothing to stderr".
19493
+ *
19494
+ * Only an ESTABLISHED transport is released here. While `open()` is still
19495
+ * dialing, `conn` is alive and `channel`/`peer` are not, and ending that Client
19496
+ * would strand the handshake: ssh2 clears its own ready timer when the socket
19497
+ * closes and emits 'close' without an 'error', so the promise `open()` awaits
19498
+ * would never settle. `open()` itself releases the attempt instead, once it has
19499
+ * a definitive outcome.
19500
+ */
19410
19501
  invalidate(error) {
19411
19502
  if (this.dead !== void 0 || this.disposed) return;
19412
19503
  this.dead = error;
19413
- if (this.heartbeat !== void 0) clearTimeout(this.heartbeat);
19504
+ if (this.heartbeat !== void 0) {
19505
+ clearTimeout(this.heartbeat);
19506
+ this.heartbeat = void 0;
19507
+ }
19508
+ const tail = this.stderrTail;
19414
19509
  try {
19415
19510
  this.peer?.close(error);
19416
19511
  } catch {}
19512
+ if (this.peer !== void 0 || this.channel !== void 0) this.teardownTransport();
19513
+ this.stderrTail = tail;
19417
19514
  }
19418
19515
  };
19419
19516
  //#endregion
@@ -19953,9 +20050,10 @@ var RemoteWorlds = class {
19953
20050
  }
19954
20051
  const conn = await pending;
19955
20052
  if (!conn.alive) {
20053
+ const detail = conn.diagnostics;
20054
+ conn.dispose().catch(() => void 0);
19956
20055
  this.rpcs.delete(alias);
19957
20056
  if (attempt < DIAL_IMMEDIATE_RETRIES) return this.dial(alias, attempt + 1);
19958
- const detail = conn.diagnostics;
19959
20057
  const reason = "helper connection closed right after dialing" + (detail === "" ? " (the helper wrote nothing to stderr)" : ` — helper stderr: ${detail}`);
19960
20058
  this.noteDialFailure(alias, new Error(reason));
19961
20059
  throw new Error(`helper RPC for ${alias} is unavailable after ${attempt + 1} attempt(s): ${reason}`);
@@ -20051,4 +20149,4 @@ var RemoteWorlds = class {
20051
20149
  }
20052
20150
  };
20053
20151
  //#endregion
20054
- export { ensurePrivateDir as C, viewSettingsPath as E, dshHome as S, storePath as T, MIN_TIMEOUT_MS as _, helperAvailability as a, require_lib as b, seedHelperCache as c, attachmentHeader as d, DEFAULT_GIT_TIMEOUT_MS as f, MAX_TIMEOUT_MS as g, DeadlineError as h, drainHostNotices as i, RemoteFiles as l, DEFAULT_TIMEOUTS as m, TombstonedError as n, probe as o, DEFAULT_READ_TIMEOUT_MS as p, isWindowsAbsolute as r, pushPipeline as s, RemoteWorlds as t, WriteConflictError as u, clampExecTimeout as v, keysDir as w, aliasRoot as x, resolveTimeouts as y };
20152
+ export { dshHome as C, viewSettingsPath as D, storePath as E, aliasRoot as S, keysDir as T, MAX_TIMEOUT_MS as _, takeHostNotices as a, resolveTimeouts as b, pushPipeline as c, WriteConflictError as d, attachmentHeader as f, DeadlineError as g, DEFAULT_TIMEOUTS as h, drainHostNotices as i, seedHelperCache as l, DEFAULT_READ_TIMEOUT_MS as m, TombstonedError as n, helperAvailability as o, DEFAULT_GIT_TIMEOUT_MS as p, isWindowsAbsolute as r, probe as s, RemoteWorlds as t, RemoteFiles as u, MIN_TIMEOUT_MS as v, ensurePrivateDir as w, require_lib as x, clampExecTimeout as y };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-remote-vs",
3
3
  "description": "VSCode-style remote development for DSH: SSH host manager (key/password), helper deploy pipeline with version check, remote file explorer + editor + terminal in dsh-better-sidebar.",
4
- "version": "0.25.0",
4
+ "version": "0.26.0",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
7
7
  "dsh",
@@ -83,6 +83,7 @@
83
83
  "cordis.patch.yml",
84
84
  "README.md",
85
85
  "README.en.md",
86
+ "THIRD-PARTY-NOTICES.md",
86
87
  "LICENSE",
87
88
  "icon.svg",
88
89
  "locale/*.json"