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.
- package/README.en.md +455 -443
- package/README.md +408 -396
- package/lib/client.js +8062 -2651
- package/lib/index.js +1058 -288
- package/lib/p2-router-fs.js +1 -1
- package/lib/p2-router-refs.js +89 -10
- package/lib/p2-router-spill.js +73 -1
- package/lib/p2-router-subprocess.js +18 -6
- package/lib/spill-retention-BwKEWrl5.js +115 -0
- package/lib/{ssh-proc-arI5lm4W.js → ssh-proc-VKWn_LZC.js} +17 -0
- package/lib/types/archive.d.ts +1 -1
- package/lib/types/changes/recorder.d.ts +34 -2
- package/lib/types/client/CodeEditor.d.ts +12 -0
- package/lib/types/client/ConnectionStatus.d.ts +17 -0
- package/lib/types/client/DirectoryFlow.d.ts +2 -0
- package/lib/types/client/DoctorPanel.d.ts +25 -0
- package/lib/types/client/QuickOpen.d.ts +17 -0
- package/lib/types/client/RemoteExplorer.d.ts +192 -1
- package/lib/types/client/RemoteRoot.d.ts +17 -0
- package/lib/types/client/SearchView.d.ts +55 -0
- package/lib/types/client/TerminalView.d.ts +38 -0
- package/lib/types/client/WorkspaceWizard.d.ts +17 -0
- package/lib/types/client/api.d.ts +54 -4
- package/lib/types/client/changes/undo-affordance.d.ts +16 -0
- package/lib/types/client/changes/undo-context.d.ts +14 -18
- package/lib/types/client/changes/undo-target.d.ts +78 -0
- package/lib/types/client/connection.d.ts +111 -0
- package/lib/types/client/doctor.d.ts +122 -0
- package/lib/types/client/download.d.ts +35 -5
- package/lib/types/client/downloads.d.ts +18 -1
- package/lib/types/client/file-open-probe.d.ts +64 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/quickopen-model.d.ts +332 -0
- package/lib/types/client/scm/DiffView.d.ts +34 -0
- package/lib/types/client/scm/actions.d.ts +18 -0
- package/lib/types/client/scm/diff-model.d.ts +17 -1
- package/lib/types/client/scm/git-cache.d.ts +10 -2
- package/lib/types/client/scm/read-queue.d.ts +2 -1
- package/lib/types/client/scm/stage-queue.d.ts +13 -0
- package/lib/types/client/scm/status-map.d.ts +3 -1
- package/lib/types/client/store.d.ts +114 -5
- package/lib/types/client/vsc/FindWidget.d.ts +7 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +57 -0
- package/lib/types/deploy.d.ts +44 -2
- package/lib/types/git-format.d.ts +15 -0
- package/lib/types/http.d.ts +44 -0
- package/lib/types/p2/file-refs.d.ts +39 -2
- package/lib/types/p2/helper-rpc.d.ts +26 -0
- package/lib/types/p2/router-spill.d.ts +19 -0
- package/lib/types/p2/router-subprocess.d.ts +2 -0
- package/lib/types/p2/spill-retention.d.ts +74 -0
- package/lib/types/p2/worlds.d.ts +11 -0
- package/lib/types/pool.d.ts +73 -11
- package/lib/types/protocol.d.ts +63 -0
- package/lib/types/routes.d.ts +18 -0
- package/lib/types/sftp.d.ts +114 -8
- package/lib/types/store.d.ts +34 -0
- package/lib/types/timeouts.d.ts +14 -0
- package/lib/{worlds-C6Xha1mQ.js → worlds-Be1YE2Ot.js} +727 -78
- package/package.json +1 -1
- package/src/archive.ts +41 -9
- package/src/changes/recorder.ts +227 -31
- package/src/changes/status.ts +37 -1
- package/src/client/CodeEditor.tsx +84 -2
- package/src/client/ConnectionStatus.tsx +130 -0
- package/src/client/DirectoryFlow.tsx +40 -5
- package/src/client/DoctorPanel.tsx +202 -0
- package/src/client/DownloadDock.tsx +13 -25
- package/src/client/EditorPane.tsx +291 -7
- package/src/client/HostsView.tsx +17 -8
- package/src/client/QuickOpen.tsx +371 -0
- package/src/client/RemoteDirectoryPicker.tsx +54 -3
- package/src/client/RemoteExplorer.tsx +879 -160
- package/src/client/RemoteRoot.tsx +178 -1
- package/src/client/SearchView.tsx +180 -6
- package/src/client/SettingsHosts.tsx +1 -1
- package/src/client/TerminalView.tsx +174 -9
- package/src/client/WorkspaceWizard.tsx +110 -16
- package/src/client/WorkspacesView.tsx +22 -6
- package/src/client/api.ts +197 -11
- package/src/client/changes/ChangesDock.tsx +35 -8
- package/src/client/changes/undo-affordance.ts +33 -0
- package/src/client/changes/undo-context.ts +14 -18
- package/src/client/changes/undo-target.ts +139 -0
- package/src/client/connection.ts +264 -0
- package/src/client/doctor.ts +441 -0
- package/src/client/download.ts +148 -12
- package/src/client/downloads.ts +43 -2
- package/src/client/file-open-probe.ts +83 -0
- package/src/client/i18n.ts +244 -0
- package/src/client/index.tsx +5 -2
- package/src/client/quickopen-model.ts +778 -0
- package/src/client/remote-file-open.ts +21 -33
- package/src/client/scm/DiffView.tsx +116 -6
- package/src/client/scm/ScmPanel.tsx +19 -0
- package/src/client/scm/actions.ts +34 -2
- package/src/client/scm/diff-model.ts +33 -37
- package/src/client/scm/git-cache.ts +61 -4
- package/src/client/scm/read-queue.ts +33 -2
- package/src/client/scm/stage-queue.ts +72 -1
- package/src/client/scm/status-map.ts +22 -1
- package/src/client/store.tsx +704 -21
- package/src/client/vsc/FindWidget.tsx +20 -0
- package/src/client/vsc/kit.tsx +115 -6
- package/src/client/vsc/reveal-line.ts +33 -14
- package/src/client/vsc/save-shortcut.ts +131 -0
- package/src/client/vsc/vsc.css +419 -0
- package/src/deploy.ts +185 -33
- package/src/git-format.ts +136 -22
- package/src/git-ops.ts +14 -6
- package/src/http.ts +80 -12
- package/src/importers.ts +80 -21
- package/src/index.ts +21 -1
- package/src/p2/file-refs.ts +112 -10
- package/src/p2/helper-rpc.ts +73 -36
- package/src/p2/router-spill.ts +96 -1
- package/src/p2/router-subprocess.ts +18 -5
- package/src/p2/spill-retention.ts +134 -0
- package/src/p2/ssh-proc.ts +22 -0
- package/src/p2/worlds.ts +24 -0
- package/src/pool.ts +329 -47
- package/src/protocol.ts +66 -0
- package/src/routes.ts +251 -43
- package/src/sftp.ts +486 -26
- package/src/store.ts +207 -85
- package/src/terminal.ts +38 -2
- package/src/timeouts.ts +14 -0
- package/src/tools.ts +14 -5
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side view of the Host's per-alias SSH connection health.
|
|
3
|
+
*
|
|
4
|
+
* The browser never speaks SSH: every remote call is an HTTP request to the
|
|
5
|
+
* local Host, which fails (or succeeds) on its own. So the Host's pool is the
|
|
6
|
+
* only place that knows whether the link is up, and this module polls it at a
|
|
7
|
+
* low rate. An operation that fails with a TRANSPORT error is applied locally as
|
|
8
|
+
* well, so the UI reacts immediately instead of waiting for the next poll.
|
|
9
|
+
*
|
|
10
|
+
* The two things this module must get right (and the gate pins):
|
|
11
|
+
* - a BUSINESS error (no such file, permission denied) is not a link problem;
|
|
12
|
+
* only transport-class messages move the state to `error`;
|
|
13
|
+
* - `idle` is not `error`: the pool is lazy and closes a connection after 30
|
|
14
|
+
* idle minutes, and the next operation dials again.
|
|
15
|
+
*/
|
|
16
|
+
import { useSyncExternalStore } from 'react'
|
|
17
|
+
import type { RemoteConnectionStatus } from '../protocol.ts'
|
|
18
|
+
|
|
19
|
+
export type ConnectionState = 'ok' | 'error' | 'idle'
|
|
20
|
+
|
|
21
|
+
/** Automatic-retry cadence for an errored link (one dial per tick). */
|
|
22
|
+
export const AUTO_RETRY_MS = 30_000
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Automatic attempts allowed per error episode.
|
|
26
|
+
*
|
|
27
|
+
* Not endless on purpose: each attempt is a real SSH dial, and repeated dials
|
|
28
|
+
* against a password-auth host can count towards a lockout. After the budget
|
|
29
|
+
* the chip stays a manual retry control.
|
|
30
|
+
*/
|
|
31
|
+
export const AUTO_RETRY_MAX_ATTEMPTS = 3
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Decide one automatic-retry tick.
|
|
35
|
+
*
|
|
36
|
+
* Pure so the budget can be pinned without a browser: ok/idle reset the
|
|
37
|
+
* count, rror consumes one attempt until the budget is spent.
|
|
38
|
+
*/
|
|
39
|
+
export function consumeAutoRetry(
|
|
40
|
+
state: ConnectionState,
|
|
41
|
+
attempts: number,
|
|
42
|
+
): { run: boolean; attempts: number } {
|
|
43
|
+
if (state !== 'error') return { run: false, attempts: 0 }
|
|
44
|
+
if (attempts >= AUTO_RETRY_MAX_ATTEMPTS) return { run: false, attempts }
|
|
45
|
+
return { run: true, attempts: attempts + 1 }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The i18n key for a state's label.
|
|
50
|
+
*
|
|
51
|
+
* Kept here (not inside the chip) so the gate can assert the MAPPING without a
|
|
52
|
+
* browser: rendering the pool's normal lazy state as "not connected" was a real
|
|
53
|
+
* UX defect — idle means "nothing to report yet / connects on demand", not a
|
|
54
|
+
* broken link.
|
|
55
|
+
*/
|
|
56
|
+
export function connectionLabelKey(state: ConnectionState): string {
|
|
57
|
+
if (state === 'ok') return 'connection.ok'
|
|
58
|
+
if (state === 'error') return 'connection.error'
|
|
59
|
+
return 'connection.idle'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** What the UI renders for one alias. */
|
|
63
|
+
export interface ConnectionView {
|
|
64
|
+
alias: string
|
|
65
|
+
state: ConnectionState
|
|
66
|
+
/** Last transport error message (only while state === 'error'). */
|
|
67
|
+
error?: string
|
|
68
|
+
/** When the Host last saw a transport error, epoch ms. */
|
|
69
|
+
errorAt?: number
|
|
70
|
+
/** When the Host last completed a dial / transport-level operation. */
|
|
71
|
+
okAt?: number
|
|
72
|
+
/** A pooled SSH connection is open right now (diagnostic detail only). */
|
|
73
|
+
open: boolean
|
|
74
|
+
/**
|
|
75
|
+
* Client time of the last locally noted failure. A poll that still reports
|
|
76
|
+
* the older success must not clear an error the page just saw.
|
|
77
|
+
*/
|
|
78
|
+
notedAt?: number
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Transport-level failures, mirroring the Host's classifier (src/pool.ts). Kept
|
|
83
|
+
* in sync deliberately: the client applies the same rule only to turn an
|
|
84
|
+
* operation failure into an immediate indicator update.
|
|
85
|
+
*/
|
|
86
|
+
const CONNECTION_ERROR_RE = /not connected|no response from server|connection lost|connection refused|socket hang up|channel open fail(?:ed|ure)|connection closed|stalled|timed out|ECONNRESET|ECONNREFUSED|ETIMEDOUT|EHOSTUNREACH|ENETUNREACH|EHOSTDOWN|EPIPE|host .* was disconnected/i
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Whether `error` (or its message) is a transport-level failure.
|
|
90
|
+
*
|
|
91
|
+
* The flags are honoured first: a repeat failure's message is REWRITTEN to a
|
|
92
|
+
* localized sentence before it is thrown (see `api.call`), and downstream guards
|
|
93
|
+
* (toast quieting, the offline banner) must still see a link error.
|
|
94
|
+
*
|
|
95
|
+
* `deadline` wins over the text: a budget that ran out is an operation result,
|
|
96
|
+
* not a link failure. Its message contains "timed out", so the text rule alone
|
|
97
|
+
* would classify it as transport — and that is exactly what used to turn one
|
|
98
|
+
* slow listing into a red chip and a read-only editor.
|
|
99
|
+
*/
|
|
100
|
+
export function isConnectionFailure(error: unknown): boolean {
|
|
101
|
+
if (typeof error === 'object' && error !== null) {
|
|
102
|
+
if ((error as { transport?: unknown }).transport === true) return true
|
|
103
|
+
if ((error as { deadline?: unknown }).deadline === true) return false
|
|
104
|
+
}
|
|
105
|
+
const message = error instanceof Error ? error.message : String(error ?? '')
|
|
106
|
+
return message !== '' && CONNECTION_ERROR_RE.test(message)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let activeAlias = ''
|
|
110
|
+
const views = new Map<string, ConnectionView>()
|
|
111
|
+
/** Explicit-retry successes (epoch ms): a stale poll error must not undo them. */
|
|
112
|
+
const probes = new Map<string, number>()
|
|
113
|
+
const listeners = new Set<() => void>()
|
|
114
|
+
/** Last value handed to `useSyncExternalStore` — a new object only on change. */
|
|
115
|
+
let snapshot: ConnectionView | undefined
|
|
116
|
+
|
|
117
|
+
function notify(): void {
|
|
118
|
+
for (const listener of listeners) listener()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Recompute the snapshot for the ACTIVE alias and wake subscribers. */
|
|
122
|
+
function refreshSnapshot(): void {
|
|
123
|
+
const next = activeAlias === '' ? undefined : views.get(activeAlias)
|
|
124
|
+
const same = next === snapshot
|
|
125
|
+
|| (next !== undefined && snapshot !== undefined
|
|
126
|
+
&& next.alias === snapshot.alias && next.state === snapshot.state
|
|
127
|
+
&& next.error === snapshot.error && next.errorAt === snapshot.errorAt
|
|
128
|
+
&& next.okAt === snapshot.okAt && next.open === snapshot.open && next.notedAt === snapshot.notedAt)
|
|
129
|
+
if (same) return
|
|
130
|
+
snapshot = next
|
|
131
|
+
notify()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Point the view at the workspace the user is looking at. */
|
|
135
|
+
export function setActiveConnectionAlias(alias: string): void {
|
|
136
|
+
if (alias === activeAlias) return
|
|
137
|
+
activeAlias = alias
|
|
138
|
+
refreshSnapshot()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The alias the surface currently belongs to ('' when none). */
|
|
142
|
+
export function activeConnectionAlias(): string {
|
|
143
|
+
return activeAlias
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Apply the Host's status list. A host-reported success clears an error only
|
|
148
|
+
* when it is NEWER than the local failure note: otherwise a poll that raced the
|
|
149
|
+
* failing operation would flip the chip back to green while the toast still
|
|
150
|
+
* says the request failed.
|
|
151
|
+
*/
|
|
152
|
+
export function applyConnectionStatuses(list: readonly RemoteConnectionStatus[]): void {
|
|
153
|
+
for (const item of list) {
|
|
154
|
+
const prev = views.get(item.alias)
|
|
155
|
+
// A poll response generated BEFORE a successful manual retry can land after
|
|
156
|
+
// it; a failure older than that probe must not repaint the chip red.
|
|
157
|
+
const probedAt = probes.get(item.alias) ?? 0
|
|
158
|
+
if (item.state === 'error' && probedAt > (item.errorAt ?? 0)) continue
|
|
159
|
+
const keepLocalError = prev?.state === 'error' && item.state === 'ok'
|
|
160
|
+
&& prev.notedAt !== undefined && (item.okAt === undefined || item.okAt < prev.notedAt)
|
|
161
|
+
if (keepLocalError) continue
|
|
162
|
+
views.set(item.alias, {
|
|
163
|
+
alias: item.alias,
|
|
164
|
+
state: item.state,
|
|
165
|
+
...(item.error === undefined ? {} : { error: item.error }),
|
|
166
|
+
...(item.errorAt === undefined ? {} : { errorAt: item.errorAt }),
|
|
167
|
+
...(item.okAt === undefined ? {} : { okAt: item.okAt }),
|
|
168
|
+
open: item.open,
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
refreshSnapshot()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Record a transport failure the page just observed on `alias`. */
|
|
175
|
+
export function noteConnectionFailure(alias: string, error: unknown): void {
|
|
176
|
+
if (alias === '') return
|
|
177
|
+
// The ERROR, not its message: the `deadline` / `transport` flags live on the
|
|
178
|
+
// object, and a deadline must not paint the alias red.
|
|
179
|
+
if (!isConnectionFailure(error)) return
|
|
180
|
+
const message = error instanceof Error ? error.message : String(error ?? '')
|
|
181
|
+
const prev = views.get(alias)
|
|
182
|
+
views.set(alias, {
|
|
183
|
+
alias,
|
|
184
|
+
state: 'error',
|
|
185
|
+
error: message,
|
|
186
|
+
errorAt: Date.now(),
|
|
187
|
+
...(prev?.okAt === undefined ? {} : { okAt: prev.okAt }),
|
|
188
|
+
open: prev?.open ?? false,
|
|
189
|
+
notedAt: Date.now(),
|
|
190
|
+
})
|
|
191
|
+
refreshSnapshot()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
/** Drop every cached view — tests only (a live page keeps its map). */
|
|
196
|
+
export function resetConnectionViews(): void {
|
|
197
|
+
views.clear()
|
|
198
|
+
probes.clear()
|
|
199
|
+
snapshot = undefined
|
|
200
|
+
activeAlias = ''
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Record that an explicit retry just succeeded for `alias`. */
|
|
204
|
+
export function markConnectionProbeOk(alias: string): void {
|
|
205
|
+
if (alias === '') return
|
|
206
|
+
probes.set(alias, Date.now())
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Where the last observed state came from (see `isConnectionRecovery`). */
|
|
210
|
+
export interface ConnectionTrace {
|
|
211
|
+
alias: string
|
|
212
|
+
state: string | undefined
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Whether this is the LINK recovering, as opposed to a workspace switch.
|
|
217
|
+
*
|
|
218
|
+
* Between two already-errored hosts the alias changes while the state does not;
|
|
219
|
+
* counting that as a recovery would refresh the wrong workspace. The caller
|
|
220
|
+
* keeps a trace keyed by alias, so by the time the new host recovers this sees
|
|
221
|
+
* `(b, error) → (b, ok)`.
|
|
222
|
+
*/
|
|
223
|
+
export function isConnectionRecovery(
|
|
224
|
+
previous: ConnectionTrace | undefined,
|
|
225
|
+
alias: string,
|
|
226
|
+
state: string | undefined,
|
|
227
|
+
): boolean {
|
|
228
|
+
if (previous === undefined || previous.alias !== alias) return false
|
|
229
|
+
return previous.state === 'error' && state === 'ok'
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Current view of the active alias (the hook is the UI path; this is for gates). */
|
|
233
|
+
export function currentConnection(): ConnectionView | undefined {
|
|
234
|
+
return snapshot
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The cached health of ONE alias (`undefined` = never observed).
|
|
239
|
+
*
|
|
240
|
+
* `currentConnection()` answers for the alias the user is LOOKING at; an action
|
|
241
|
+
* that carries its own alias must ask by that alias instead. The undo path is
|
|
242
|
+
* the case in point: its coordinates come from `undoContext()` (the change
|
|
243
|
+
* panel), which can point at a different workspace than the visible one, and
|
|
244
|
+
* reading the visible alias' state there would block (or allow) the wrong host.
|
|
245
|
+
*
|
|
246
|
+
* A cached `error` is exactly what the save path already refuses on
|
|
247
|
+
* (`EditorPane` offline), and an unknown alias means "no evidence" — callers
|
|
248
|
+
* must treat `undefined` as "not proven down", never as healthy.
|
|
249
|
+
*/
|
|
250
|
+
export function connectionStateOf(alias: string): ConnectionState | undefined {
|
|
251
|
+
if (alias === '') return undefined
|
|
252
|
+
return views.get(alias)?.state
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Subscribe to the active alias's connection view (undefined when none). */
|
|
256
|
+
export function useConnectionStatus(): ConnectionView | undefined {
|
|
257
|
+
return useSyncExternalStore(
|
|
258
|
+
(listener) => {
|
|
259
|
+
listeners.add(listener)
|
|
260
|
+
return () => listeners.delete(listener)
|
|
261
|
+
},
|
|
262
|
+
() => snapshot,
|
|
263
|
+
)
|
|
264
|
+
}
|