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
@@ -7,7 +7,7 @@
7
7
  * A tab is refresh-safe: the server session id is persisted, so reloading the
8
8
  * GUI reattaches to the still-running shell instead of spawning a new one.
9
9
  */
10
- import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
10
+ import { useCallback, useEffect, useRef, useState, useSyncExternalStore, type ReactNode } from 'react'
11
11
  import type { RemoteHostSummary } from '../protocol.ts'
12
12
  import { RemoteApiError, api } from './api.ts'
13
13
  import { XTerm } from './XTerm.tsx'
@@ -97,6 +97,104 @@ function newId(): string {
97
97
  */
98
98
  let openedTerminalRequest = 0
99
99
 
100
+ /**
101
+ * Which mounted terminal surface owns the view (one at a time).
102
+ *
103
+ * The native right-sidebar fallback mounts a `RemoteRoot` per session that
104
+ * opened the remote page, so two `TerminalView`s can be alive at once. They
105
+ * share one localStorage tab list and one module-level request counter, so
106
+ * without an owner the hidden instance can steal an "open terminal here"
107
+ * request (its tab is invisible), and both instances keep XTerm sockets for the
108
+ * same stored session ids (duplicate input, last-writer-wins tabs). The owner is
109
+ * the surface on screen; only it renders the terminal UI and persists the tab
110
+ * list, so exactly one instance holds sockets for a given session.
111
+ */
112
+ let terminalOwner: symbol | undefined
113
+ const terminalOwnerListeners = new Set<() => void>()
114
+
115
+ function publishTerminalOwner(next: symbol): void {
116
+ if (terminalOwner === next) return
117
+ terminalOwner = next
118
+ for (const listener of [...terminalOwnerListeners]) listener()
119
+ }
120
+
121
+ function subscribeTerminalOwner(listener: () => void): () => void {
122
+ terminalOwnerListeners.add(listener)
123
+ return () => {
124
+ terminalOwnerListeners.delete(listener)
125
+ }
126
+ }
127
+
128
+ /** First mount claims the panel, so a single-surface profile renders at once. */
129
+ export function claimTerminalOwnerIfNone(id: symbol): void {
130
+ if (terminalOwner === undefined) publishTerminalOwner(id)
131
+ }
132
+
133
+ /** Whether `id` is the surface that currently owns the terminal panel. */
134
+ export function terminalSurfaceOwnedBy(owner: symbol | undefined, id: symbol): boolean {
135
+ return owner === id
136
+ }
137
+
138
+ /** Why a terminal connection ended — and therefore whether the shell may live on. */
139
+ export type TerminalExitKind =
140
+ /** The socket went away; the Host keeps the PTY for 10 minutes and can reattach. */
141
+ | 'reattach'
142
+ /** The remote shell really exited (or refused the connection at the shell level). */
143
+ | 'exited'
144
+ /** The Host no longer knows this session id: drop it and open a fresh shell. */
145
+ | 'expired'
146
+
147
+ /** Failures that are about the socket, not about the shell inside it. */
148
+ const SOCKET_LEVEL_MESSAGES = new Set(['websocket refused', 'websocket error'])
149
+
150
+ /**
151
+ * Classify one terminal exit report.
152
+ *
153
+ * `XTerm` reports the ssh channel's exit code and, for socket-level problems, a
154
+ * message with `code === null`. A socket that closes with neither (page reload,
155
+ * network blip, laptop sleep) must NOT destroy the tab's `session` id: the Host
156
+ * keeps the PTY for `EMPTY_SOCKET_TTL_MS`, so the right answer is "keep the id,
157
+ * offer a reattach". Only a real exit (a code, or a shell-level error message)
158
+ * ends the session.
159
+ */
160
+ export function classifyTerminalExit(code: number | null, message: string | undefined): TerminalExitKind {
161
+ if (message === 'terminal session expired') return 'expired'
162
+ if (code !== null) return 'exited'
163
+ if (message === undefined || SOCKET_LEVEL_MESSAGES.has(message)) return 'reattach'
164
+ return 'exited'
165
+ }
166
+
167
+ /** What one tab should look like after an exit report. */
168
+ export interface TerminalExitState {
169
+ connected: boolean
170
+ /** Kept for `reattach`, cleared for `exited`/`expired`. */
171
+ session: string | undefined
172
+ kind: TerminalExitKind
173
+ /** i18n key for the note, when the note is a fixed sentence. */
174
+ noteKey?: 'term.disconnected' | 'term.closed'
175
+ /** Literal note (exit code or a host message), when it is not a fixed sentence. */
176
+ noteText?: string
177
+ }
178
+
179
+ /** Apply {@link classifyTerminalExit} to one tab. Pure, so the gate can pin it. */
180
+ export function terminalExitState(
181
+ tab: { session?: string },
182
+ code: number | null,
183
+ message: string | undefined,
184
+ ): TerminalExitState {
185
+ const kind = classifyTerminalExit(code, message)
186
+ if (kind === 'expired') return { connected: false, session: undefined, kind }
187
+ if (kind === 'reattach') return { connected: false, session: tab.session, kind, noteKey: 'term.disconnected' }
188
+ return {
189
+ connected: false,
190
+ session: undefined,
191
+ kind,
192
+ ...(code === null
193
+ ? (message === undefined ? { noteKey: 'term.closed' as const } : { noteText: message })
194
+ : { noteText: `exit ${code}` }),
195
+ }
196
+ }
197
+
100
198
  export function TerminalView(props: {
101
199
  t: (key: string) => string
102
200
  hosts: RemoteHostSummary[]
@@ -105,6 +203,15 @@ export function TerminalView(props: {
105
203
  request?: TerminalRequest
106
204
  }): ReactNode {
107
205
  const t = props.t
206
+ /** This mounted surface's identity in the one-owner arbitration (see above). */
207
+ const surfaceId = useRef<symbol>(Symbol('terminal-surface'))
208
+ // First mount claims the panel before the first paint, so a profile with one
209
+ // surface (the normal better-sidebar case) renders immediately.
210
+ claimTerminalOwnerIfNone(surfaceId.current)
211
+ const owner = useSyncExternalStore(
212
+ subscribeTerminalOwner,
213
+ () => terminalSurfaceOwnedBy(terminalOwner, surfaceId.current),
214
+ )
108
215
  const [alias, setAlias] = useState<string>(readAlias)
109
216
  const [tabs, setTabs] = useState<TermTab[]>(() => readStoredTabs().map(row => ({
110
217
  id: row.id,
@@ -119,17 +226,50 @@ export function TerminalView(props: {
119
226
  ? alias
120
227
  : (props.hosts[0]?.alias ?? '')
121
228
 
229
+ // The surface on screen takes the panel over from a hidden one (per-session
230
+ // native pages mount several instances). Last-visible wins; the hidden one
231
+ // stops rendering (and closes its sockets) instead of writing the same
232
+ // localStorage tab list behind the owner's back.
233
+ const wasOwner = useRef(false)
122
234
  useEffect(() => {
235
+ if (!owner) {
236
+ wasOwner.current = false
237
+ return
238
+ }
239
+ // Regaining the panel: the sessions this surface knew about may still be
240
+ // alive on the Host (10-minute reattach window), and their sockets were
241
+ // closed when ownership left. Reattach them instead of making the user click
242
+ // "Reconnect" for every tab; a tab whose shell really exited has no session
243
+ // id and stays dead.
244
+ const reclaim = !wasOwner.current
245
+ wasOwner.current = true
246
+ if (!reclaim) return
247
+ setTabs(prev => prev.map(tab => (
248
+ !tab.connected && tab.session !== undefined
249
+ ? { ...tab, connected: true, nonce: tab.nonce + 1, note: undefined }
250
+ : tab
251
+ )))
252
+ }, [owner])
253
+
254
+ useEffect(() => {
255
+ if (props.visible) publishTerminalOwner(surfaceId.current)
256
+ }, [props.visible])
257
+
258
+ useEffect(() => {
259
+ if (!owner) return
123
260
  try {
124
261
  localStorage.setItem(ALIAS_KEY, effectiveAlias)
125
262
  } catch {
126
263
  // Ignore.
127
264
  }
128
- }, [effectiveAlias])
265
+ }, [effectiveAlias, owner])
129
266
 
130
267
  useEffect(() => {
268
+ // Only the owner persists: two instances writing one key is last-writer-wins
269
+ // and can resurrect a hidden surface's stale list over the visible one.
270
+ if (!owner) return
131
271
  persistTabs(tabs)
132
- }, [tabs])
272
+ }, [tabs, owner])
133
273
 
134
274
  // A restored tab whose host no longer exists cannot reattach.
135
275
  useEffect(() => {
@@ -173,6 +313,13 @@ export function TerminalView(props: {
173
313
  useEffect(() => {
174
314
  const request = props.request
175
315
  if (request === undefined || request.id === openedTerminalRequest) return
316
+ // Only the surface actually on screen may consume the request: with several
317
+ // per-session instances mounted, a hidden one consuming it opened the tab
318
+ // where nobody could see it while the visible panel stayed empty. The
319
+ // owner flag turns true together with `visible`, and this effect re-runs
320
+ // when either changes, so the request is not lost — it is just owned by the
321
+ // right surface.
322
+ if (!owner || props.visible !== true) return
176
323
  openedTerminalRequest = request.id
177
324
  const target = request.alias !== '' && props.hosts.some(host => host.alias === request.alias)
178
325
  ? request.alias
@@ -181,7 +328,7 @@ export function TerminalView(props: {
181
328
  // "+" continues on the same host.
182
329
  if (target !== alias) setAlias(target)
183
330
  openTab(target, cdCommand(request.dir))
184
- }, [props.request, props.hosts, effectiveAlias, alias, openTab])
331
+ }, [props.request, props.hosts, effectiveAlias, alias, openTab, owner, props.visible])
185
332
 
186
333
  const closeTab = useCallback(async (tab: TermTab): Promise<void> => {
187
334
  const ok = await confirmDialog({
@@ -234,6 +381,13 @@ export function TerminalView(props: {
234
381
  return siblings.length > 1 ? `${name} #${index}` : name
235
382
  }
236
383
 
384
+ if (!owner) {
385
+ // A hidden per-session surface: the visible one owns the terminal panel.
386
+ // Rendering here would mount a second XTerm per stored session (duplicate
387
+ // sockets/input) and its tab list would race the owner's on localStorage.
388
+ return null
389
+ }
390
+
237
391
  return (
238
392
  <div className="rvs-pane grow">
239
393
  <div className="rvs-header">
@@ -329,15 +483,20 @@ export function TerminalView(props: {
329
483
  {...(tab.initialCommand === undefined ? {} : { initialInput: tab.initialCommand })}
330
484
  onReady={(id) => patchTab(tab.id, { session: id, connected: true, note: undefined })}
331
485
  onExit={(code, message) => {
332
- if (message === 'terminal session expired') {
486
+ // A socket that goes away is NOT the shell exiting: the Host
487
+ // keeps the PTY for 10 minutes, so keeping `session` is what
488
+ // makes the reconnect a reattach instead of a new shell. Only
489
+ // a real exit (or an expired id) drops it.
490
+ const exitState = terminalExitState(tab, code, message)
491
+ if (exitState.kind === 'expired') {
333
492
  // Stale reattach: drop the id and retry once with a fresh shell.
334
493
  patchTab(tab.id, { session: undefined, nonce: tab.nonce + 1, connected: true, note: undefined })
335
494
  return
336
495
  }
337
496
  patchTab(tab.id, {
338
- connected: false,
339
- session: undefined,
340
- note: code === null ? (message ?? t('term.closed')) : `exit ${code}`,
497
+ connected: exitState.connected,
498
+ session: exitState.session,
499
+ note: exitState.noteText ?? (exitState.noteKey === undefined ? undefined : t(exitState.noteKey)),
341
500
  })
342
501
  }}
343
502
  />
@@ -345,7 +504,13 @@ export function TerminalView(props: {
345
504
  <div className="rvs-term-dead">
346
505
  {tab.note !== undefined && <div className="rvs-empty">{tab.note}</div>}
347
506
  <div className="rvs-commit-row" style={{ justifyContent: 'center' }}>
348
- <button type="button" className="rvs-chip primary" onClick={() => reconnect(tab.id, true)}>
507
+ <button
508
+ type="button"
509
+ className="rvs-chip primary"
510
+ // A tab that still knows its Host session id reattaches to
511
+ // the live shell; only a tab without one opens a fresh shell.
512
+ onClick={() => reconnect(tab.id, tab.session === undefined)}
513
+ >
349
514
  {t('term.reconnect')}
350
515
  </button>
351
516
  </div>
@@ -4,7 +4,7 @@
4
4
  * native directory-flow occupant: `onSaved` carries the materialized alias
5
5
  * path the owner adopts as a real workspace.
6
6
  */
7
- import { useState, type ReactNode } from 'react'
7
+ import { useEffect, useRef, useState, type ReactNode } from 'react'
8
8
  import type { RemoteHostSummary, RemoteWorkspaceBinding } from '../protocol.ts'
9
9
  import { RemoteApiError, api } from './api.ts'
10
10
  import { RemoteDirectoryPicker } from './RemoteDirectoryPicker.tsx'
@@ -14,6 +14,38 @@ function err(e: unknown): string {
14
14
  return e instanceof RemoteApiError ? e.message : String(e)
15
15
  }
16
16
 
17
+ /**
18
+ * Whether an async result belongs to a host/attempt the wizard has left.
19
+ *
20
+ * Every step is host-scoped (`testHost`, `deployPush`, `stat` all take the alias
21
+ * captured when the request started), so a result that arrives after the user
22
+ * switched hosts — or after a newer attempt in the same step — must be dropped:
23
+ * otherwise host B inherits "tested"/"pushed"/"path verified" from host A, and
24
+ * the bind step can save a path nobody checked on B. Pure so the gate can pin it.
25
+ */
26
+ export function isStaleWizardResult(
27
+ requestSequence: number,
28
+ currentSequence: number,
29
+ requestAlias: string,
30
+ currentAlias: string,
31
+ ): boolean {
32
+ return requestSequence !== currentSequence || requestAlias !== currentAlias
33
+ }
34
+
35
+ /**
36
+ * Whether the path may be considered verified for the host ON SCREEN.
37
+ *
38
+ * `pathOk` alone is not enough: it is set by whichever `stat` answered last, and
39
+ * a host switch (or a slower, older verify) can leave it true for another host.
40
+ */
41
+ export function wizardPathVerified(
42
+ pathOk: boolean,
43
+ verifiedAlias: string | undefined,
44
+ currentAlias: string,
45
+ ): boolean {
46
+ return pathOk && verifiedAlias !== undefined && verifiedAlias !== '' && verifiedAlias === currentAlias
47
+ }
48
+
17
49
  export function WorkspaceWizard(props: {
18
50
  t: (k: string) => string
19
51
  hosts: RemoteHostSummary[]
@@ -27,46 +59,81 @@ export function WorkspaceWizard(props: {
27
59
  const [tested, setTested] = useState(false)
28
60
  const [pushed, setPushed] = useState(false)
29
61
  const [pathOk, setPathOk] = useState(false)
62
+ /** Host the successful verify ran against; `pathOk` is meaningless without it. */
63
+ const [verifiedAlias, setVerifiedAlias] = useState<string | undefined>(undefined)
30
64
  const [remotePath, setRemotePath] = useState('')
31
65
  const [name, setName] = useState('')
32
66
  const [busy, setBusy] = useState<string | undefined>(undefined)
33
67
  const [notice, setNotice] = useState<string | undefined>(undefined)
34
68
  const [error, setError] = useState<string | undefined>(undefined)
35
69
  const [showPicker, setShowPicker] = useState(false)
70
+ /** Monotonic ticket: only the newest test/push/verify may write state. */
71
+ const actionSeq = useRef(0)
72
+ const aliasRef = useRef(alias)
73
+ aliasRef.current = alias
74
+ const alive = useRef(true)
75
+ useEffect(() => {
76
+ // Re-armed on every effect run (StrictMode remount runs setup→cleanup→setup).
77
+ alive.current = true
78
+ return () => {
79
+ alive.current = false
80
+ }
81
+ }, [])
82
+
83
+ const beginAction = (): { sequence: number; requestAlias: string } => ({
84
+ sequence: (actionSeq.current += 1),
85
+ requestAlias: alias,
86
+ })
87
+
88
+ const stale = (request: { sequence: number; requestAlias: string }): boolean =>
89
+ !alive.current || isStaleWizardResult(request.sequence, actionSeq.current, request.requestAlias, aliasRef.current)
36
90
 
37
91
  const pick = (next: string): void => {
38
92
  setAlias(next)
39
93
  setTested(false)
40
94
  setPushed(false)
95
+ // A path verified on the previous host proves nothing about this one.
96
+ setPathOk(false)
97
+ setVerifiedAlias(undefined)
41
98
  setNotice(undefined)
42
99
  setError(undefined)
43
100
  }
44
101
 
45
102
  const runTest = (): void => {
46
103
  if (alias === '') return
104
+ const request = beginAction()
47
105
  setBusy('test')
48
- api.testHost(alias).then(
106
+ api.testHost(request.requestAlias).then(
49
107
  (r) => {
108
+ if (stale(request)) return
50
109
  setBusy(undefined)
51
110
  if (r.ok) {
52
111
  setTested(true)
53
- setNotice(`${alias}: OK (${r.durationMs} ms)`)
112
+ setNotice(`${request.requestAlias}: OK (${r.durationMs} ms)`)
54
113
  setError(undefined)
55
114
  } else {
56
115
  setTested(false)
57
- setError(r.error ?? 'unknown')
116
+ setError(r.error ?? t('hosts.unknownError'))
58
117
  setNotice(undefined)
59
118
  }
60
119
  },
61
- (e: unknown) => { setBusy(undefined); setTested(false); setError(err(e)); setNotice(undefined) },
120
+ (e: unknown) => {
121
+ if (stale(request)) return
122
+ setBusy(undefined)
123
+ setTested(false)
124
+ setError(err(e))
125
+ setNotice(undefined)
126
+ },
62
127
  )
63
128
  }
64
129
 
65
130
  const runPush = (): void => {
66
131
  if (alias === '') return
132
+ const request = beginAction()
67
133
  setBusy('push')
68
- api.deployPush(alias).then(
134
+ api.deployPush(request.requestAlias).then(
69
135
  (r) => {
136
+ if (stale(request)) return
70
137
  setBusy(undefined)
71
138
  if (r.action === 'failed') {
72
139
  setPushed(false)
@@ -78,7 +145,13 @@ export function WorkspaceWizard(props: {
78
145
  setError(undefined)
79
146
  }
80
147
  },
81
- (e: unknown) => { setBusy(undefined); setPushed(false); setError(err(e)); setNotice(undefined) },
148
+ (e: unknown) => {
149
+ if (stale(request)) return
150
+ setBusy(undefined)
151
+ setPushed(false)
152
+ setError(err(e))
153
+ setNotice(undefined)
154
+ },
82
155
  )
83
156
  }
84
157
 
@@ -86,36 +159,56 @@ export function WorkspaceWizard(props: {
86
159
  const candidate = (target ?? remotePath).trim()
87
160
  if (alias === '' || candidate === '') return
88
161
  if (target !== undefined) setRemotePath(target)
162
+ const request = beginAction()
89
163
  setBusy('verify')
90
164
  api.fileOp
91
- .stat(alias, candidate)
165
+ .stat(request.requestAlias, candidate)
92
166
  .then(
93
167
  (entry) => {
168
+ if (stale(request)) return
94
169
  setBusy(undefined)
95
170
  if (!entry.isDir) {
96
171
  setPathOk(false)
97
- setError(`${candidate}: not a directory`)
172
+ setVerifiedAlias(undefined)
173
+ setError(t('ws.notDirectory').replace('{path}', candidate))
98
174
  setNotice(undefined)
99
175
  } else {
100
176
  setPathOk(true)
101
- setNotice(`${candidate}: directory OK`)
177
+ setVerifiedAlias(request.requestAlias)
178
+ setNotice(t('ws.directoryOk').replace('{path}', candidate))
102
179
  setError(undefined)
103
180
  }
104
181
  },
105
- (e: unknown) => { setBusy(undefined); setPathOk(false); setError(err(e)); setNotice(undefined) },
182
+ (e: unknown) => {
183
+ if (stale(request)) return
184
+ setBusy(undefined)
185
+ setPathOk(false)
186
+ setVerifiedAlias(undefined)
187
+ setError(err(e))
188
+ setNotice(undefined)
189
+ },
106
190
  )
107
191
  }
108
192
 
109
193
  const save = (): void => {
110
194
  if (alias === '' || name.trim() === '' || remotePath.trim() === '') return
195
+ // Last gate: never save a path that was not verified on THIS host.
196
+ if (!wizardPathVerified(pathOk, verifiedAlias, alias)) return
197
+ const request = beginAction()
111
198
  setBusy('save')
112
- api.createWorkspace({ name: name.trim(), alias, remotePath: remotePath.trim() }).then(
199
+ api.createWorkspace({ name: name.trim(), alias: request.requestAlias, remotePath: remotePath.trim() }).then(
113
200
  (r) => {
201
+ if (!alive.current) return
114
202
  setBusy(undefined)
115
203
  props.onSaved?.(r.workspace, r.aliasPath)
116
204
  props.onDone()
117
205
  },
118
- (e: unknown) => { setBusy(undefined); setError(err(e)); setNotice(undefined) },
206
+ (e: unknown) => {
207
+ if (!alive.current) return
208
+ setBusy(undefined)
209
+ setError(err(e))
210
+ setNotice(undefined)
211
+ },
119
212
  )
120
213
  }
121
214
 
@@ -153,7 +246,7 @@ export function WorkspaceWizard(props: {
153
246
  <input
154
247
  value={remotePath}
155
248
  disabled={disabled || !pushed}
156
- onChange={(e) => { setRemotePath(e.target.value); setPathOk(false) }}
249
+ onChange={(e) => { setRemotePath(e.target.value); setPathOk(false); setVerifiedAlias(undefined) }}
157
250
  placeholder="/home/user/project"
158
251
  style={inputStyle}
159
252
  />
@@ -161,7 +254,7 @@ export function WorkspaceWizard(props: {
161
254
  {t('ws.browse')}
162
255
  </Btn>
163
256
  <Btn onClick={() => runVerify()} disabled={disabled || !pushed || remotePath.trim() === ''}>
164
- {t('ws.verifyPath')} {pathOk ? '✓' : ''}
257
+ {t('ws.verifyPath')} {pathOk && verifiedAlias === alias ? '✓' : ''}
165
258
  </Btn>
166
259
  </div>
167
260
  </Field>
@@ -176,7 +269,7 @@ export function WorkspaceWizard(props: {
176
269
  </Field>
177
270
  {!pushed && <div style={{ fontSize: 12, opacity: 0.6, marginBottom: 8 }}>{t('ws.pushFirst')}</div>}
178
271
  <Row>
179
- <Btn kind="primary" onClick={save} disabled={disabled || !pushed || !pathOk || name.trim() === ''}>
272
+ <Btn kind="primary" onClick={save} disabled={disabled || !pushed || !wizardPathVerified(pathOk, verifiedAlias, alias) || name.trim() === ''}>
180
273
  {busy === 'save' ? t('common.loading') : t('ws.save')}
181
274
  </Btn>
182
275
  <Btn onClick={props.onCancel} disabled={disabled}>{t('hosts.cancel')}</Btn>
@@ -190,6 +283,7 @@ export function WorkspaceWizard(props: {
190
283
  onPick={(picked) => {
191
284
  setShowPicker(false)
192
285
  setPathOk(false)
286
+ setVerifiedAlias(undefined)
193
287
  runVerify(picked)
194
288
  }}
195
289
  onCancel={() => setShowPicker(false)}
@@ -6,6 +6,7 @@ import type { RemoteHostSummary, RemoteRoutingStatus, RemoteWorkspaceBinding } f
6
6
  import { RemoteApiError, api } from './api.ts'
7
7
  import { WorkspaceWizard } from './WorkspaceWizard.tsx'
8
8
  import { Btn, Notice, Row, hairline } from './ui.tsx'
9
+ import { confirmDialog } from './vsc/kit.tsx'
9
10
 
10
11
  function err(e: unknown): string {
11
12
  return e instanceof RemoteApiError ? e.message : String(e)
@@ -26,10 +27,25 @@ export function WorkspacesView(props: {
26
27
  const [error, setError] = useState<string | undefined>(undefined)
27
28
  const [busy, setBusy] = useState<string | undefined>(undefined)
28
29
 
29
- const remove = (id: string): void => {
30
- setBusy(id)
31
- api.deleteWorkspace(id).then(
32
- () => { setBusy(undefined); setNotice('binding removed'); setError(undefined); props.onChanged() },
30
+ /**
31
+ * Unbind one workspace, after a confirmation.
32
+ *
33
+ * This used to fire on a single click while deleting a HOST (the other
34
+ * destructive action on this screen) asks first; the binding removal also
35
+ * writes a fail-closed tombstone, so a stray click is not losslessly undone.
36
+ */
37
+ const remove = async (workspace: RemoteWorkspaceBinding): Promise<void> => {
38
+ const ok = await confirmDialog({
39
+ title: t('ws.unbindTitle'),
40
+ text: t('ws.unbindConfirm').replace('{name}', workspace.name),
41
+ danger: true,
42
+ okText: t('ws.delete'),
43
+ cancelText: t('common.cancel'),
44
+ })
45
+ if (!ok) return
46
+ setBusy(workspace.id)
47
+ api.deleteWorkspace(workspace.id).then(
48
+ () => { setBusy(undefined); setNotice(t('ws.removed')); setError(undefined); props.onChanged() },
33
49
  (e: unknown) => { setBusy(undefined); setError(err(e)); setNotice(undefined) },
34
50
  )
35
51
  }
@@ -75,7 +91,7 @@ export function WorkspacesView(props: {
75
91
  {props.onOpenFiles !== undefined && (
76
92
  <Btn kind="primary" onClick={() => props.onOpenFiles?.(w.id)}>{t('ws.open')}</Btn>
77
93
  )}
78
- <Btn kind="danger" onClick={() => remove(w.id)} disabled={busy !== undefined}>{t('ws.delete')}</Btn>
94
+ <Btn kind="danger" onClick={() => { void remove(w) }} disabled={busy !== undefined}>{t('ws.delete')}</Btn>
79
95
  </Row>
80
96
  </div>
81
97
  </div>
@@ -84,7 +100,7 @@ export function WorkspacesView(props: {
84
100
  <WorkspaceWizard
85
101
  t={t}
86
102
  hosts={props.hosts}
87
- onDone={() => { setWizard(false); setNotice('binding saved'); setError(undefined); props.onChanged() }}
103
+ onDone={() => { setWizard(false); setNotice(t('ws.saved')); setError(undefined); props.onChanged() }}
88
104
  onCancel={() => setWizard(false)}
89
105
  />
90
106
  )}