dsh-remote-vs 0.13.0 → 0.15.1

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 (128) hide show
  1. package/README.en.md +455 -443
  2. package/README.md +408 -396
  3. package/lib/client.js +8062 -2651
  4. package/lib/index.js +1058 -288
  5. package/lib/p2-router-fs.js +1 -1
  6. package/lib/p2-router-refs.js +89 -10
  7. package/lib/p2-router-spill.js +73 -1
  8. package/lib/p2-router-subprocess.js +18 -6
  9. package/lib/spill-retention-BwKEWrl5.js +115 -0
  10. package/lib/{ssh-proc-arI5lm4W.js → ssh-proc-VKWn_LZC.js} +17 -0
  11. package/lib/types/archive.d.ts +1 -1
  12. package/lib/types/changes/recorder.d.ts +34 -2
  13. package/lib/types/client/CodeEditor.d.ts +12 -0
  14. package/lib/types/client/ConnectionStatus.d.ts +17 -0
  15. package/lib/types/client/DirectoryFlow.d.ts +2 -0
  16. package/lib/types/client/DoctorPanel.d.ts +25 -0
  17. package/lib/types/client/QuickOpen.d.ts +17 -0
  18. package/lib/types/client/RemoteExplorer.d.ts +192 -1
  19. package/lib/types/client/RemoteRoot.d.ts +17 -0
  20. package/lib/types/client/SearchView.d.ts +55 -0
  21. package/lib/types/client/TerminalView.d.ts +38 -0
  22. package/lib/types/client/WorkspaceWizard.d.ts +17 -0
  23. package/lib/types/client/api.d.ts +54 -4
  24. package/lib/types/client/changes/undo-affordance.d.ts +16 -0
  25. package/lib/types/client/changes/undo-context.d.ts +14 -18
  26. package/lib/types/client/changes/undo-target.d.ts +78 -0
  27. package/lib/types/client/connection.d.ts +111 -0
  28. package/lib/types/client/doctor.d.ts +122 -0
  29. package/lib/types/client/download.d.ts +35 -5
  30. package/lib/types/client/downloads.d.ts +18 -1
  31. package/lib/types/client/file-open-probe.d.ts +64 -0
  32. package/lib/types/client/i18n.d.ts +1 -1
  33. package/lib/types/client/quickopen-model.d.ts +332 -0
  34. package/lib/types/client/scm/DiffView.d.ts +34 -0
  35. package/lib/types/client/scm/actions.d.ts +18 -0
  36. package/lib/types/client/scm/diff-model.d.ts +17 -1
  37. package/lib/types/client/scm/git-cache.d.ts +10 -2
  38. package/lib/types/client/scm/read-queue.d.ts +2 -1
  39. package/lib/types/client/scm/stage-queue.d.ts +13 -0
  40. package/lib/types/client/scm/status-map.d.ts +3 -1
  41. package/lib/types/client/store.d.ts +114 -5
  42. package/lib/types/client/vsc/FindWidget.d.ts +7 -0
  43. package/lib/types/client/vsc/save-shortcut.d.ts +57 -0
  44. package/lib/types/deploy.d.ts +44 -2
  45. package/lib/types/git-format.d.ts +15 -0
  46. package/lib/types/http.d.ts +44 -0
  47. package/lib/types/p2/file-refs.d.ts +39 -2
  48. package/lib/types/p2/helper-rpc.d.ts +26 -0
  49. package/lib/types/p2/router-spill.d.ts +19 -0
  50. package/lib/types/p2/router-subprocess.d.ts +2 -0
  51. package/lib/types/p2/spill-retention.d.ts +74 -0
  52. package/lib/types/p2/worlds.d.ts +11 -0
  53. package/lib/types/pool.d.ts +73 -11
  54. package/lib/types/protocol.d.ts +63 -0
  55. package/lib/types/routes.d.ts +18 -0
  56. package/lib/types/sftp.d.ts +114 -8
  57. package/lib/types/store.d.ts +34 -0
  58. package/lib/types/timeouts.d.ts +14 -0
  59. package/lib/{worlds-C6Xha1mQ.js → worlds-Be1YE2Ot.js} +727 -78
  60. package/package.json +1 -1
  61. package/src/archive.ts +41 -9
  62. package/src/changes/recorder.ts +227 -31
  63. package/src/changes/status.ts +37 -1
  64. package/src/client/CodeEditor.tsx +84 -2
  65. package/src/client/ConnectionStatus.tsx +130 -0
  66. package/src/client/DirectoryFlow.tsx +40 -5
  67. package/src/client/DoctorPanel.tsx +202 -0
  68. package/src/client/DownloadDock.tsx +13 -25
  69. package/src/client/EditorPane.tsx +291 -7
  70. package/src/client/HostsView.tsx +17 -8
  71. package/src/client/QuickOpen.tsx +371 -0
  72. package/src/client/RemoteDirectoryPicker.tsx +54 -3
  73. package/src/client/RemoteExplorer.tsx +879 -160
  74. package/src/client/RemoteRoot.tsx +178 -1
  75. package/src/client/SearchView.tsx +180 -6
  76. package/src/client/SettingsHosts.tsx +1 -1
  77. package/src/client/TerminalView.tsx +174 -9
  78. package/src/client/WorkspaceWizard.tsx +110 -16
  79. package/src/client/WorkspacesView.tsx +22 -6
  80. package/src/client/api.ts +197 -11
  81. package/src/client/changes/ChangesDock.tsx +35 -8
  82. package/src/client/changes/undo-affordance.ts +33 -0
  83. package/src/client/changes/undo-context.ts +14 -18
  84. package/src/client/changes/undo-target.ts +139 -0
  85. package/src/client/connection.ts +264 -0
  86. package/src/client/doctor.ts +441 -0
  87. package/src/client/download.ts +148 -12
  88. package/src/client/downloads.ts +43 -2
  89. package/src/client/file-open-probe.ts +83 -0
  90. package/src/client/i18n.ts +244 -0
  91. package/src/client/index.tsx +5 -2
  92. package/src/client/quickopen-model.ts +778 -0
  93. package/src/client/remote-file-open.ts +21 -33
  94. package/src/client/scm/DiffView.tsx +116 -6
  95. package/src/client/scm/ScmPanel.tsx +19 -0
  96. package/src/client/scm/actions.ts +34 -2
  97. package/src/client/scm/diff-model.ts +33 -37
  98. package/src/client/scm/git-cache.ts +61 -4
  99. package/src/client/scm/read-queue.ts +33 -2
  100. package/src/client/scm/stage-queue.ts +72 -1
  101. package/src/client/scm/status-map.ts +22 -1
  102. package/src/client/store.tsx +704 -21
  103. package/src/client/vsc/FindWidget.tsx +20 -0
  104. package/src/client/vsc/kit.tsx +115 -6
  105. package/src/client/vsc/reveal-line.ts +33 -14
  106. package/src/client/vsc/save-shortcut.ts +131 -0
  107. package/src/client/vsc/vsc.css +419 -0
  108. package/src/deploy.ts +185 -33
  109. package/src/git-format.ts +136 -22
  110. package/src/git-ops.ts +14 -6
  111. package/src/http.ts +80 -12
  112. package/src/importers.ts +80 -21
  113. package/src/index.ts +21 -1
  114. package/src/p2/file-refs.ts +112 -10
  115. package/src/p2/helper-rpc.ts +73 -36
  116. package/src/p2/router-spill.ts +96 -1
  117. package/src/p2/router-subprocess.ts +18 -5
  118. package/src/p2/spill-retention.ts +134 -0
  119. package/src/p2/ssh-proc.ts +22 -0
  120. package/src/p2/worlds.ts +24 -0
  121. package/src/pool.ts +329 -47
  122. package/src/protocol.ts +66 -0
  123. package/src/routes.ts +251 -43
  124. package/src/sftp.ts +486 -26
  125. package/src/store.ts +207 -85
  126. package/src/terminal.ts +38 -2
  127. package/src/timeouts.ts +14 -0
  128. package/src/tools.ts +14 -5
@@ -1,6 +1,14 @@
1
1
  import { type ClientChannel, type SFTPWrapper } from 'ssh2';
2
2
  import type { RemoteStore } from './store.ts';
3
- import type { RemoteExecResult } from './protocol.ts';
3
+ import { DeadlineError } from './timeouts.ts';
4
+ import type { RemoteConnectionStatus, RemoteExecResult } from './protocol.ts';
5
+ /**
6
+ * The budget-out type lives in `timeouts.ts` (both halves need it); re-exported
7
+ * here because existing callers and the browse gate import it from the pool.
8
+ */
9
+ export { DeadlineError };
10
+ /** Whether `error` is a transport-level failure worth showing as a link problem. */
11
+ export declare function isConnectionFailure(error: unknown): boolean;
4
12
  export interface ExecOptions {
5
13
  timeoutMs?: number;
6
14
  /**
@@ -45,12 +53,60 @@ export declare class RemotePool {
45
53
  private readonly slots;
46
54
  /** Per-alias BROWSE SFTP session (see withBrowseSftp). */
47
55
  private readonly browsed;
56
+ /** Per-alias connection health for the browser's status chip (see status). */
57
+ private readonly health;
48
58
  constructor(store: RemoteStore);
49
59
  /** Drop one pooled connection (call after host update/delete). */
50
60
  drop(alias: string): void;
51
61
  /** Close every pooled connection. */
52
62
  dispose(): void;
53
- /** Test a connection without disturbing the pool. */
63
+ /**
64
+ * Forget one alias's connection HEALTH (host edited/removed), not just its
65
+ * connection.
66
+ *
67
+ * `drop` is also the idle eviction path, so it must keep the health record
68
+ * (idle-closed is not an error). Only a host mutation discards what the pool
69
+ * learned about that alias.
70
+ */
71
+ forget(alias: string): void;
72
+ /**
73
+ * Per-alias connection health for the browser's status indicator.
74
+ *
75
+ * Read-only and dial-free: it reports what the pool already knows, so the
76
+ * indicator's poll never creates a connection as a side effect.
77
+ */
78
+ status(): RemoteConnectionStatus[];
79
+ /** Record a successful dial or transport-level operation. */
80
+ private markOk;
81
+ /** Record a connection-level failure the status chip should show. */
82
+ private markError;
83
+ /**
84
+ * Record one operation's failure, EXCEPT when the budget simply ran out.
85
+ *
86
+ * A deadline means "this request did not answer in time", not "the link is
87
+ * down": the connection can be perfectly healthy and merely slow (a huge
88
+ * directory, an 8 MiB read on a thin link, a cold filesystem). Painting the
89
+ * chip red used to flip the editor to read-only and block saving — a false
90
+ * alarm with a real cost. Real transport failures still arrive as transport
91
+ * errors (`close`, `No response from server`, a channel open failure), and
92
+ * those keep marking; the operation itself still fails either way.
93
+ */
94
+ private noteOpFailure;
95
+ /**
96
+ * Probe one connection and record the outcome for the status indicator.
97
+ *
98
+ * "Test" must PROVE the link, not report that a pooled Client object exists:
99
+ * the old version answered ok without any traffic, so a retry against a
100
+ * half-open link painted the host green until the next real request failed.
101
+ *
102
+ * It must also NOT disturb the pool: this is what host settings' "test" and
103
+ * the chip's retry run, and the host being tested is often the one the user is
104
+ * working on (a terminal open, a transfer running). So a live connection gets
105
+ * a real round trip on itself (a trivial bare command under the control
106
+ * deadline), and only a COLD alias dials. Tearing the connection down instead
107
+ * would end every channel on it, including the terminal that the user opened
108
+ * to debug the flaky host.
109
+ */
54
110
  test(alias: string): Promise<{
55
111
  ok: boolean;
56
112
  banner?: string;
@@ -133,6 +189,12 @@ export declare class RemotePool {
133
189
  * ssh2 has no channel-open timeout: a server that never answers leaves this
134
190
  * promise pending forever, which pins the connection's hold count and blocks
135
191
  * idle re-arming (the "SSH looks dead" symptom) while the HTTP request hangs.
192
+ *
193
+ * The deadline is spelled out here instead of wrapped around the promise
194
+ * because the ANSWER can arrive after it: `conn.sftp`'s callback is the only
195
+ * place that can still see the session, and a late one would otherwise leak a
196
+ * server-side channel that no slot or hold accounts for (the caller has long
197
+ * returned its own and moved on).
136
198
  */
137
199
  private openSession;
138
200
  /**
@@ -207,14 +269,14 @@ export declare class RemotePool {
207
269
  private hold;
208
270
  private release;
209
271
  private acquire;
272
+ /**
273
+ * The ssh2 client factory.
274
+ *
275
+ * A seam, not a preference: `dial` is the only place that has to react to
276
+ * "connect emitted close but never error", and a fake client is the only way a
277
+ * self-check can produce that shape without a real server. Production never
278
+ * overrides it.
279
+ */
280
+ private makeClient;
210
281
  private dial;
211
282
  }
212
- /**
213
- * An operation that ran out of its wall-clock budget.
214
- *
215
- * Tagged on purpose: callers have to tell "the remote never answered" from a real
216
- * remote failure (a missing path must not cost the session), and matching on the
217
- * message text would silently stop working the moment the template changed.
218
- */
219
- export declare class DeadlineError extends Error {
220
- }
@@ -7,6 +7,8 @@
7
7
  export declare const REMOTE_API: {
8
8
  readonly hosts: "/api/dsh-remote/hosts";
9
9
  readonly test: "/api/dsh-remote/test";
10
+ /** Per-alias SSH connection health for the client's status indicator. */
11
+ readonly status: "/api/dsh-remote/status";
10
12
  readonly keygen: "/api/dsh-remote/keygen";
11
13
  readonly exec: "/api/dsh-remote/exec";
12
14
  /** Streaming exec (server-sent events) for the long network verbs. */
@@ -127,6 +129,27 @@ export interface RemoteTimeouts {
127
129
  /** One SFTP file read (editor, diff sides, document preview). */
128
130
  readMs: number;
129
131
  }
132
+ /**
133
+ * Connection health for one host alias, as the Host's pool sees it.
134
+ *
135
+ * The browser never talks SSH itself, so it cannot know whether the link is up;
136
+ * this is the Host's answer. `idle` is NOT an error: a pooled connection is
137
+ * closed after 30 idle minutes, and the next operation dials again. `error`
138
+ * means the last connection-level event failed (dial error, unexpected close,
139
+ * or a transport-class operation failure) — the next operation will retry.
140
+ */
141
+ export interface RemoteConnectionStatus {
142
+ alias: string;
143
+ state: 'ok' | 'error' | 'idle';
144
+ /** A pooled SSH connection is open right now (not a health promise on its own). */
145
+ open: boolean;
146
+ /** Last successful dial / transport-level operation, epoch ms. */
147
+ okAt?: number;
148
+ /** Last connection-level failure, epoch ms. */
149
+ errorAt?: number;
150
+ /** Human-readable failure the client can show in the status chip. */
151
+ error?: string;
152
+ }
130
153
  /** Remote OS probe outcome. */
131
154
  export interface RemoteProbe {
132
155
  alias: string;
@@ -208,6 +231,17 @@ export interface RemoteFileEntry {
208
231
  export interface RemoteRead {
209
232
  /** File size in bytes. */
210
233
  size: number;
234
+ /**
235
+ * Modification time in ms — the optimistic-lock baseline for a save.
236
+ *
237
+ * Read with the bytes in the same SFTP round trip, so the pair describes ONE
238
+ * version of the file. The editor stores it and sends it back on save; the
239
+ * Host refuses the write when the remote file has a different mtime, because
240
+ * that means someone else (an agent through the transparent route, a
241
+ * terminal, another editor) wrote it after this buffer was loaded and
242
+ * accepting the save would destroy their work without a word.
243
+ */
244
+ mtime: number;
211
245
  /** True when the content is not UTF-8 text (base64 holds the bytes). */
212
246
  binary: boolean;
213
247
  text?: string | undefined;
@@ -215,6 +249,35 @@ export interface RemoteRead {
215
249
  /** True when size exceeded READ_CAP (content holds the first window). */
216
250
  truncated: boolean;
217
251
  }
252
+ /** Result of one remote file write, including the version it left behind. */
253
+ export interface RemoteWriteResult {
254
+ /** Bytes written. */
255
+ size: number;
256
+ /**
257
+ * mtime of the NEW content in ms: the baseline for the next save.
258
+ *
259
+ * `null` when the post-write stat could not be read. The save still SUCCEEDED
260
+ * (the bytes are in place), so this is not an error — it only means the next
261
+ * save has no baseline to check and must go through unguarded. Saying so is
262
+ * the whole point: a fabricated timestamp would make every later save of that
263
+ * tab conflict with itself.
264
+ */
265
+ mtime: number | null;
266
+ }
267
+ /**
268
+ * The remote file changed since the baseline the caller saved against.
269
+ *
270
+ * Deliberately its own shape (not a generic failure): the client has to offer
271
+ * "overwrite / reload / see the difference" instead of showing a red toast and
272
+ * dropping the user's edit. `mtime` and `size` describe what is there NOW, so
273
+ * the client can say "the file changed at … and is N bytes" without another
274
+ * round trip; both are null when the file is gone (an external delete is a
275
+ * conflict too — saving towards it would recreate a file someone removed).
276
+ */
277
+ export interface RemoteWriteConflict {
278
+ mtime: number | null;
279
+ size: number | null;
280
+ }
218
281
  /** Result of one non-interactive command execution. */
219
282
  export interface RemoteExecResult {
220
283
  success: boolean;
@@ -6,6 +6,24 @@ import type { RemotePool } from './pool.ts';
6
6
  import type { RemoteWorlds } from './p2/worlds.ts';
7
7
  import { TerminalSessionRegistry } from './terminal.ts';
8
8
  import type { SessionChanges } from './changes/recorder.ts';
9
+ /**
10
+ * Wrap one archive command in a remote-side deadline.
11
+ *
12
+ * The command is a single `tar` invocation with already-quoted operands
13
+ * (`archive.ts` builders), so prefixing is syntactically safe and makes tar the
14
+ * direct child of `timeout` — TERM (then KILL after 3 s) reaches tar itself, no
15
+ * process-group id is needed (2026-10 audit, A16-1). Hosts without GNU `timeout`
16
+ * (BSD/macOS) fall back to today's behaviour instead of failing the download.
17
+ */
18
+ export declare function archiveCommandWithDeadline(command: string): string;
19
+ /**
20
+ * Error for a failed archive stream.
21
+ *
22
+ * GNU `timeout` reports 124 when TERM sufficed and 137 when KILL was needed;
23
+ * both mean "the remote budget ran out", which is more actionable than
24
+ * `tar failed (124): no stderr`.
25
+ */
26
+ export declare function archiveFailureMessage(exitCode: number | null | undefined, stderr: string): Error;
9
27
  export interface RemoteRoutesDeps {
10
28
  store: RemoteStore;
11
29
  pool: RemotePool;
@@ -1,6 +1,6 @@
1
1
  import type { ServerResponse } from 'node:http';
2
2
  import type { RemotePool } from './pool.ts';
3
- import type { RemoteFileEntry, RemoteRead } from './protocol.ts';
3
+ import type { RemoteFileEntry, RemoteRead, RemoteWriteConflict, RemoteWriteResult } from './protocol.ts';
4
4
  /** Single-read cap (matches the fs-ssh 8 MiB window). */
5
5
  export declare const READ_CAP: number;
6
6
  /**
@@ -14,6 +14,27 @@ export declare const READ_CAP: number;
14
14
  export declare const LIST_ENTRY_CAP = 20000;
15
15
  /** Largest single upload accepted (matches the client-side planner cap). */
16
16
  export declare const UPLOAD_MAX_BYTES: number;
17
+ /**
18
+ * The remote file changed after the bytes the caller saved against were read.
19
+ *
20
+ * Carries what is there NOW so the route can answer 409 with the current
21
+ * version instead of a bare message — the client shows "changed at …, N bytes"
22
+ * and offers overwrite / reload / see-the-difference without a second round
23
+ * trip. A missing target is a conflict too (`mtime`/`size` null): the file this
24
+ * buffer was loaded from is gone, so writing would recreate something a person
25
+ * or another tool deliberately removed.
26
+ *
27
+ * The mtime comparison is SFTP's own (second granularity), so this narrows the
28
+ * window rather than closing it: two writes to the same inode inside one second
29
+ * share an mtime. `expectSize` covers the common "same second, different
30
+ * length" case and nothing more. It is a guard against silent loss, not a
31
+ * strong consistency protocol — the docs say so.
32
+ */
33
+ export declare class WriteConflictError extends Error {
34
+ readonly path: string;
35
+ readonly conflict: RemoteWriteConflict;
36
+ constructor(path: string, mtime: number | null, size: number | null);
37
+ }
17
38
  /**
18
39
  * How long one download stream may make no progress before it is failed.
19
40
  *
@@ -79,13 +100,57 @@ export declare class RemoteFiles {
79
100
  private readonly knownDirs;
80
101
  /** Listings already reported as truncated; the log line stays one per path. */
81
102
  private readonly capWarned;
103
+ /**
104
+ * Side files this process is still writing (`alias\0path`). A sweep skips them
105
+ * regardless of age — they are not orphans.
106
+ */
107
+ private readonly activePartials;
108
+ /**
109
+ * Side files this process CREATED and could not remove (`alias\0path`).
110
+ *
111
+ * This is the ONLY set a sweep may delete from. Deleting a name that merely
112
+ * LOOKS like a side file is a guess, and guessing wrong destroys the user's
113
+ * data (the audit's P2-N1: `foo.part-deadbeef` in a directory that once
114
+ * recorded an orphan, older than the age bound, was irreversibly removed).
115
+ * A leftover from a previous Host process is therefore never swept either:
116
+ * junk that stays is recoverable, a deleted user file is not.
117
+ */
118
+ private readonly ownedPartials;
119
+ /** alias -> directories that may hold an owned side file (sweep on next write). */
120
+ private readonly orphanDirs;
82
121
  constructor(pool: RemotePool);
83
122
  list(alias: string, dir: string): Promise<RemoteFileEntry[]>;
84
123
  stat(alias: string, file: string): Promise<RemoteFileEntry>;
85
124
  read(alias: string, file: string): Promise<RemoteRead>;
86
- write(alias: string, file: string, content: string, encoding?: 'utf8' | 'base64'): Promise<{
87
- size: number;
88
- }>;
125
+ /**
126
+ * Write one file whole (the remote editor's save / `remote_write`), atomically.
127
+ *
128
+ * Not `writeFile` on the target: that truncates it first, so an interrupted
129
+ * save (a dropped link, a Host restart, a full disk mid-write) left the
130
+ * previous content gone AND the new one half written. The bytes go to a SIDE
131
+ * file next to the target (`.dsh-rvs.part-<8 hex>`, see `PART_MARKER`) and are
132
+ * only moved into place once the body is complete.
133
+ *
134
+ * "Moved into place" must not delete the target first: the old unlink-then-
135
+ * rename pair had a window where a failed rename left NEITHER the old file nor
136
+ * the new one, and reported it as `no such file`. `replaceFile` therefore uses
137
+ * OpenSSH's atomic `posix-rename` when the server advertises it, and otherwise
138
+ * swaps the target aside with a rollback, so the previous bytes survive every
139
+ * failure with the real error attached.
140
+ *
141
+ * Two things a fresh inode would otherwise lose:
142
+ * - a symbolic link target: the side file lives next to the link's REAL
143
+ * target and the link itself is left alone (the old in-place write punched
144
+ * through it; replacing it with a plain file silently changed what the path
145
+ * means);
146
+ * - the permission bits: they are copied back with `setstat` after the swap.
147
+ * Owner/group cannot be preserved without a privileged chown, so a save
148
+ * keeps the bytes and the mode but takes the SSH user's ownership.
149
+ */
150
+ write(alias: string, file: string, content: string, encoding?: 'utf8' | 'base64', guard?: {
151
+ expectMtime?: number | undefined;
152
+ expectSize?: number | undefined;
153
+ }): Promise<RemoteWriteResult>;
89
154
  /**
90
155
  * Stream one upload into a remote file, atomically.
91
156
  *
@@ -95,12 +160,13 @@ export declare class RemoteFiles {
95
160
  * first — a drop can name a path several levels below the target — and the
96
161
  * source is piped straight into the SFTP write stream.
97
162
  *
98
- * The bytes go to a SIDE file (`.part-<id>` next to the target) and are
99
- * renamed into place only once the body ended cleanly. Writing the real path
163
+ * The bytes go to a SIDE file (`.dsh-rvs.part-<8 hex>` next to the target) and
164
+ * are renamed into place only once the body ended cleanly. Writing the real path
100
165
  * directly left a half file behind whenever the upload was cancelled, which
101
166
  * then looked like a complete file in the explorer (2026-10-20 user report).
102
- * On any failure the side file is removed, so a cancelled upload leaves the
103
- * remote folder exactly as it was.
167
+ * A cancelled upload removes its side file; when the CONNECTION is what failed
168
+ * the unlink cannot run, so the directory is recorded and the next successful
169
+ * write into it sweeps the orphan (see `sweepOrphanDirs`).
104
170
  *
105
171
  * @param alias - host alias.
106
172
  * @param file - absolute remote destination path.
@@ -156,6 +222,46 @@ export declare class RemoteFiles {
156
222
  * the directory walk.
157
223
  */
158
224
  private withDirRetry;
225
+ /**
226
+ * Remove a side file, remembering its directory when that is impossible.
227
+ *
228
+ * The only failure that leaves a side file behind is the failure it was
229
+ * cleaning up after: with the connection dead, `unlink` cannot run either.
230
+ * Recording the directory lets the NEXT successful write into it sweep the
231
+ * orphan — otherwise it stays in the remote directory forever, looking like a
232
+ * file the user created.
233
+ */
234
+ private discardPartial;
235
+ /** Register one side file as ours: in flight now, and sweepable after it fails. */
236
+ private trackPartial;
237
+ /** Add one owned side-file key, evicting the oldest when the set is full. */
238
+ private rememberOwned;
239
+ /** The side file reached its target (or was removed): no longer ours to sweep. */
240
+ private forgetPartial;
241
+ private markOrphanDir;
242
+ /**
243
+ * Remove the side files THIS process left behind in `dir`.
244
+ *
245
+ * Runs after a SUCCESSFUL write/upload into a directory that recorded an
246
+ * orphan, so the healthy path pays nothing. Two independent locks keep it off
247
+ * anything the user owns:
248
+ *
249
+ * 1. the name must match the plugin's reserved shape (`.dsh-rvs.part-<8 hex>`);
250
+ * 2. the exact path must be in `ownedPartials` — a set only `trackPartial`
251
+ * writes, i.e. a file this process itself created.
252
+ *
253
+ * The shape alone would still be a guess (the audit's P2-N1: a user file
254
+ * `foo.part-deadbeef` was deleted after the age bound), so the ownership check
255
+ * is the load-bearing one. A leftover from a PREVIOUS Host process carries the
256
+ * shape but is not owned, and is therefore never deleted either — including a
257
+ * side file left by a pre-marker release (`.part-<8 hex>`, which does not even
258
+ * match the current shape). Junk that stays is recoverable; a deleted user
259
+ * file is not.
260
+ *
261
+ * A sweep failure is never the caller's problem: the record simply survives
262
+ * for the next write.
263
+ */
264
+ private sweepOrphanDirs;
159
265
  /** Add one key to a bounded set, evicting the oldest entry when full. */
160
266
  private remember;
161
267
  /** Forget `dir`, its parents and everything remembered under it. */
@@ -47,11 +47,37 @@ export declare class RemoteStore {
47
47
  private stampOf;
48
48
  private loadDoc;
49
49
  private save;
50
+ /**
51
+ * Re-read, mutate, then write only while the file has not changed underneath.
52
+ *
53
+ * Every mutation here rewrites the WHOLE document, so a plain
54
+ * read-modify-write let the last writer win: desktop and `dsh web` share
55
+ * `$DSH_HOME/dsh-remote.json` by design, and one side's host edit could
56
+ * disappear without any error. Re-reading at the start plus a stamp re-check
57
+ * right before the write turns that into a replay on fresh content.
58
+ *
59
+ * `apply` must only touch `this.doc` and return a value (no I/O, no logging):
60
+ * a conflicting attempt is executed again against the reloaded document.
61
+ * The final rename window is still unguarded (a real lock needs blocking I/O);
62
+ * this narrows the lost-update window from a whole user edit to microseconds.
63
+ */
64
+ private mutate;
50
65
  list(): RemoteHostEntry[];
51
66
  get(alias: string): RemoteHostEntry | undefined;
52
67
  require(alias: string): RemoteHostEntry;
53
68
  create(payload: HostPayload): RemoteHostEntry;
54
69
  update(alias: string, patch: Partial<Omit<HostPayload, 'alias'>>): RemoteHostEntry;
70
+ /**
71
+ * Delete one host AND its workspace bindings.
72
+ *
73
+ * The cascade has to keep the tombstone contract (see `removeWorkspace`): a
74
+ * binding that disappears while its alias dir stays on disk is no longer
75
+ * routed, but DSH's workspace registry still lists that dir, so a session
76
+ * rooted there would quietly execute LOCALLY against an empty folder instead
77
+ * of failing closed. Every cascaded binding is therefore tombstoned in the
78
+ * SAME atomic write as the removal — there is no on-disk state where the
79
+ * binding is gone but its tombstone is missing.
80
+ */
55
81
  remove(alias: string): boolean;
56
82
  private normalize;
57
83
  /** Secret-free projection for browser/agent surfaces. */
@@ -60,6 +86,14 @@ export declare class RemoteStore {
60
86
  listWorkspaces(): RemoteWorkspaceBinding[];
61
87
  createWorkspace(payload: WorkspacePayload): RemoteWorkspaceBinding;
62
88
  removeWorkspace(id: string): boolean;
89
+ /**
90
+ * Record one tombstone without writing (idempotent).
91
+ *
92
+ * The caller owns `save()` so a change covering several bindings lands in ONE
93
+ * atomic write: a crash between two writes must never leave a binding removed
94
+ * while its tombstone is still missing.
95
+ */
96
+ private recordTombstone;
63
97
  /** Record a removed alias path (idempotent). */
64
98
  addTombstone(aliasPath: string): void;
65
99
  listTombstones(): string[];
@@ -17,6 +17,20 @@
17
17
  * explorer.
18
18
  */
19
19
  import type { RemoteTimeouts } from './protocol.ts';
20
+ /**
21
+ * An operation that ran out of its wall-clock budget.
22
+ *
23
+ * Tagged on purpose: callers have to tell "the remote never answered" from a real
24
+ * remote failure (a missing path must not cost the session), and matching on the
25
+ * message text would silently stop working the moment the template changed.
26
+ *
27
+ * It lives in this module because "a budget ran out" is a timeout fact, not a
28
+ * pool or an SFTP fact: both halves need the same type to keep the distinction
29
+ * (the Host decides not to paint the link red, and the client must not downgrade
30
+ * the editor to read-only for it).
31
+ */
32
+ export declare class DeadlineError extends Error {
33
+ }
20
34
  /** Smallest accepted timeout: below this, local work would start failing. */
21
35
  export declare const MIN_TIMEOUT_MS = 1000;
22
36
  /**