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
@@ -10,16 +10,20 @@
10
10
  */
11
11
  import type { Context } from '@deepseek-ai/cordis'
12
12
  import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
13
+ import { api } from './api.ts'
14
+ import { ConnectionStatusChip } from './ConnectionStatus.tsx'
15
+ import { applyConnectionStatuses, isConnectionRecovery, setActiveConnectionAlias, useConnectionStatus, type ConnectionTrace } from './connection.ts'
13
16
  import { EditorPane } from './EditorPane.tsx'
14
17
  import { FloatingEditorPlaceholder } from './FloatingPlaceholder.tsx'
15
18
  import { DownloadDock } from './DownloadDock.tsx'
19
+ import { QuickOpen } from './QuickOpen.tsx'
16
20
  import { RemoteExplorer } from './RemoteExplorer.tsx'
17
21
  import { SearchView } from './SearchView.tsx'
18
22
  import { HistoryPanel } from './scm/HistoryPanel.tsx'
19
23
  import { ScmPanel } from './scm/ScmPanel.tsx'
20
24
  import { TerminalView } from './TerminalView.tsx'
21
25
  import { WorkspacesView } from './WorkspacesView.tsx'
22
- import { useBootstrap, useExplorer, followSessionWorkspace, setFollowSession } from './store.tsx'
26
+ import { useBootstrap, useExplorer, followSessionWorkspace, refreshAfterReconnect, setFollowSession } from './store.tsx'
23
27
  import { useRemoteChatTarget } from './use-remote-chat-target.ts'
24
28
  import { DialogHost } from './vsc/kit.tsx'
25
29
  import {
@@ -38,6 +42,41 @@ type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal
38
42
  const SPLIT_KEY = 'dsh-remote-vs.split'
39
43
  const HIDDEN_KEY = 'dsh-remote-vs.showHidden'
40
44
 
45
+ /**
46
+ * How often the client asks the Host for connection health. A local JSON call
47
+ * into the same process (no SSH, no dial); 5 s keeps the chip truthful without
48
+ * being noticeable, and request failures update it sooner than that.
49
+ */
50
+ const CONNECTION_POLL_MS = 5_000
51
+
52
+ /**
53
+ * How long the link must stay up before the recovery refresh runs.
54
+ *
55
+ * Two poll intervals: one good sample can be a race (a retry's probe beating a
56
+ * still-failing dial); two in a row mean the link is actually back. Auto-retry
57
+ * makes flaps cheap to trigger, so the damping lives here.
58
+ */
59
+ const RECOVERY_SETTLE_MS = 10_000
60
+
61
+ /**
62
+ * Which tabs a recovered link must reload, and how many dirty tabs to warn about.
63
+ *
64
+ * Pure so the gate can drive it with a synthetic list: the recovery timer used
65
+ * to close over the tab array of the render that STARTED it (10 s earlier), so a
66
+ * tab opened or closed in that window was missed. Only clean file/diff tabs are
67
+ * reloaded; a dirty tab is the user's unsaved work and must never be replaced.
68
+ */
69
+ export function planRecoveryReload(
70
+ tabs: readonly { id: string; dirty: boolean; loading: boolean; kind: string }[],
71
+ ): { dirty: number; reload: string[] } {
72
+ return {
73
+ dirty: tabs.filter(tab => tab.dirty).length,
74
+ reload: tabs
75
+ .filter(tab => !tab.loading && !tab.dirty && (tab.kind === 'file' || tab.kind === 'diff'))
76
+ .map(tab => tab.id),
77
+ }
78
+ }
79
+
41
80
  export function RemoteRoot(props: { ctx: Context; visible?: boolean }): ReactNode {
42
81
  useBootstrap(props.ctx)
43
82
  return (
@@ -54,6 +93,9 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
54
93
  // The active panel lives in the shared store so other surfaces (the tree's
55
94
  // "Find in Folder…", the SCM panel's history shortcut) can switch it.
56
95
  const view = store.view
96
+ /** Latest committed tab list, for timers created by an earlier render. */
97
+ const tabsRef = useRef(store.tabs)
98
+ tabsRef.current = store.tabs
57
99
  const [showHidden, setShowHidden] = useState<boolean>(() => {
58
100
  try {
59
101
  return localStorage.getItem(HIDDEN_KEY) === '1'
@@ -113,10 +155,143 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
113
155
  const live = props.visible && onScreen
114
156
  const panelLive = (id: RailView): boolean => live && view === id
115
157
 
158
+ /**
159
+ * Ctrl+P / Cmd+P quick open.
160
+ *
161
+ * Fires only while THIS panel is genuinely on screen (`live`, the measured
162
+ * bit above) and the store has booted: a local conversation page must keep
163
+ * the browser's own Ctrl+P, and the better-sidebar mount passes no `visible`
164
+ * prop at all — a gate built on `props.visible` alone would be dead there.
165
+ *
166
+ * `preventDefault()` is the whole point of the handler: without it the
167
+ * browser opens its print dialog on top of the modal. The toggle keeps the
168
+ * "press it again to leave" habit.
169
+ *
170
+ * In the TERMINAL, ^P belongs to the shell (readline's "previous command", and
171
+ * vim/less have their own meanings). xterm has already sent the keystroke by
172
+ * the time it bubbles to `window`, so opening the modal here would fire two
173
+ * actions for one press — the shell gets ^P AND a modal appears. The terminal
174
+ * therefore keeps the key; `preventDefault()` still runs so the browser's
175
+ * print dialog cannot appear behind it.
176
+ */
177
+ const [quickOpen, setQuickOpen] = useState(false)
178
+ const storeReady = store.ready
179
+ useEffect(() => {
180
+ const onQuickOpenKey = (event: KeyboardEvent): void => {
181
+ if (!live || !storeReady) return
182
+ if (!(event.ctrlKey || event.metaKey)) return
183
+ if (event.altKey || event.shiftKey) return
184
+ if (event.key !== 'p' && event.key !== 'P') return
185
+ event.preventDefault()
186
+ // Auto-repeat would flash the modal on a held key.
187
+ if (event.repeat) return
188
+ const focused = document.activeElement
189
+ if (focused instanceof HTMLElement && focused.closest('.xterm') !== null) return
190
+ setQuickOpen(open => !open)
191
+ }
192
+ window.addEventListener('keydown', onQuickOpenKey)
193
+ return () => window.removeEventListener('keydown', onQuickOpenKey)
194
+ }, [live, storeReady])
195
+
196
+ /**
197
+ * Leaving the panel closes the modal.
198
+ *
199
+ * It is portaled to <body>, so nothing about the sidebar's own unmount/hide
200
+ * would take it off screen: without this it would keep floating over a
201
+ * completely different surface after the user switched tabs.
202
+ */
203
+ useEffect(() => {
204
+ if (!live) setQuickOpen(false)
205
+ }, [live])
206
+
116
207
  const go = useCallback((next: RailView): void => {
117
208
  store.setView(next)
118
209
  }, [store])
119
210
 
211
+ /**
212
+ * Connection status: point the client view at the workspace's host and poll
213
+ * the Host pool.
214
+ *
215
+ * The poll is a local HTTP call into the Host (no SSH dial, no wake-up), and it
216
+ * pauses while the page is hidden; the link state itself is only observable
217
+ * Host-side, so this is the one honest source. Request-level transport
218
+ * failures update the view immediately (see `api`), so the chip does not lag
219
+ * a failure by a full interval.
220
+ */
221
+ const connectionAlias = store.workspace?.alias ?? ''
222
+ const connection = useConnectionStatus()
223
+ useEffect(() => {
224
+ setActiveConnectionAlias(connectionAlias)
225
+ }, [connectionAlias])
226
+ useEffect(() => {
227
+ if (connectionAlias === '') return
228
+ let stopped = false
229
+ const tick = async (): Promise<void> => {
230
+ if (document.hidden) return
231
+ try {
232
+ const connections = await api.connectionStatus()
233
+ if (!stopped) applyConnectionStatuses(connections)
234
+ } catch {
235
+ // The local Host is unreachable; leave the last view alone — the
236
+ // request-level failure path already marks what it can.
237
+ }
238
+ }
239
+ void tick()
240
+ const timer = window.setInterval(() => { void tick() }, CONNECTION_POLL_MS)
241
+ return () => {
242
+ stopped = true
243
+ window.clearInterval(timer)
244
+ }
245
+ }, [connectionAlias])
246
+
247
+ /**
248
+ * Recovered link: refresh what the disconnect left stale.
249
+ *
250
+ * Directory listings, git status and CLEAN editor tabs were all read before
251
+ * the drop. Dirty tabs are deliberately not reloaded (that would throw the
252
+ * user's edits away) and the user is told so. Read-only DIFF tabs have no
253
+ * unsaved edits, so they are reloaded like clean file tabs.
254
+ *
255
+ * Deps are intentionally just the state: `store` identity changes on every
256
+ * publish, and re-running this on any publish would re-fire the refresh loop.
257
+ */
258
+ const lastConnection = useRef<ConnectionTrace | undefined>(undefined)
259
+ // Live mirrors for the settle timer below (it fires long after the effect ran).
260
+ const connectionRef = useRef(connection)
261
+ connectionRef.current = connection
262
+ const connectionAliasRef = useRef(connectionAlias)
263
+ connectionAliasRef.current = connectionAlias
264
+ useEffect(() => {
265
+ // A workspace switch is not a recovery: re-baseline the trace on the new
266
+ // alias (two already-errored hosts change the alias without changing the
267
+ // state, and the recovery must still fire for the second one).
268
+ lastConnection.current = { alias: connectionAlias, state: connection?.state }
269
+ // eslint-disable-next-line react-hooks/exhaustive-deps
270
+ }, [connectionAlias])
271
+ useEffect(() => {
272
+ const previous = lastConnection.current
273
+ lastConnection.current = { alias: connectionAlias, state: connection?.state }
274
+ if (!isConnectionRecovery(previous, connectionAlias, connection?.state)) return
275
+ // Require the link to STAY up for a couple of polls before refreshing: a
276
+ // flapping link would otherwise re-fire git + a full tree re-list + every
277
+ // tab reload on each flap. Auto-retry makes flaps cheap to trigger, so the
278
+ // damping has to live here rather than in "the user must click".
279
+ const timer = window.setTimeout(() => {
280
+ if (connectionRef.current?.state !== 'ok') return
281
+ if (connectionAliasRef.current !== connectionAlias) return
282
+ // Read the LATEST committed tabs: this timer fires 10 s after the
283
+ // effect ran, and a tab opened/closed/changed in between must be seen
284
+ // (the captured `store` snapshot only knows the list from that render).
285
+ const plan = planRecoveryReload(tabsRef.current)
286
+ refreshAfterReconnect()
287
+ for (const id of plan.reload) void store.reloadTab(id)
288
+ if (plan.dirty > 0) store.info(t('connection.recoveredDirty'))
289
+ else store.info(t('connection.recovered'))
290
+ }, RECOVERY_SETTLE_MS)
291
+ return () => window.clearTimeout(timer)
292
+ // eslint-disable-next-line react-hooks/exhaustive-deps
293
+ }, [connection?.state])
294
+
120
295
  // Panels are mounted on first visit and then kept alive (see panelFor).
121
296
  const [mounted, setMounted] = useState<Set<RailView>>(() => new Set<RailView>([store.view]))
122
297
  useEffect(() => {
@@ -330,6 +505,7 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
330
505
  return (
331
506
  <div className="rvs-root" ref={attachRoot}>
332
507
  <DownloadDock t={t} />
508
+ {quickOpen && live && <QuickOpen onClose={() => setQuickOpen(false)} />}
333
509
  <div className="rvs-rail">
334
510
  {railButton('explorer', t('tab.files'), <IconCode size={17} />)}
335
511
  {railButton('search', t('tab.search'), <IconSearch size={17} />)}
@@ -353,6 +529,7 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
353
529
  <option key={item.id} value={item.id}>{item.name} ({item.alias})</option>
354
530
  ))}
355
531
  </select>
532
+ <ConnectionStatusChip />
356
533
  {store.repoRoot !== undefined && store.head !== undefined && (
357
534
  <span className="rvs-pill" title={store.repoRoot}>
358
535
  ⑂ {store.head.detached ? t('scm.detached') : store.head.branch}
@@ -21,7 +21,8 @@ import {
21
21
  } from '../search-ops.ts'
22
22
  import { searchFiles, type SearchHit } from './scm/actions.ts'
23
23
  import { repoRelative, useExplorer } from './store.tsx'
24
- import { api } from './api.ts'
24
+ import { RemoteApiError, api } from './api.ts'
25
+ import type { RemoteExecResult } from '../protocol.ts'
25
26
  import { startDownload } from './downloads.ts'
26
27
  import {
27
28
  ContextMenu,
@@ -80,6 +81,111 @@ function relativeTo(root: string, full: string): string {
80
81
  return full
81
82
  }
82
83
 
84
+ /**
85
+ * Whether a scope still belongs to the workspace root it was entered under.
86
+ *
87
+ * The scope is an ABSOLUTE remote directory, so a workspace switch leaves it
88
+ * pointing at a tree the new host may not have: the next search would run
89
+ * `find`/`grep` in the OLD workspace's path against the NEW alias (wrong or
90
+ * empty results, and an error that names no cause). Callers reset the scope when
91
+ * this answers false.
92
+ */
93
+ export function scopeBelongsToRoot(scope: string, root: string): boolean {
94
+ if (scope === '') return true
95
+ const base = root.replace(/\/+$/, '')
96
+ if (base === '') return false
97
+ return scope === base || scope.startsWith(`${base}/`)
98
+ }
99
+
100
+ /**
101
+ * Which "truncated"/"lines clipped" banners may be shown RIGHT NOW.
102
+ *
103
+ * Both flags describe one answered search, so a banner left over from a cleared
104
+ * query, from the other mode, or from the previous workspace is a claim about a
105
+ * result the panel is no longer showing. Pure so the gate can pin the rules.
106
+ */
107
+ export function visibleSearchBanners(input: {
108
+ mode: 'name' | 'content'
109
+ ran: boolean
110
+ nameTruncated: boolean
111
+ contentTruncated: boolean
112
+ linesClipped: boolean
113
+ }): { nameTruncated: boolean; contentTruncated: boolean; linesClipped: boolean } {
114
+ const answeredContent = input.mode === 'content' && input.ran
115
+ return {
116
+ nameTruncated: input.mode === 'name' && input.ran && input.nameTruncated,
117
+ contentTruncated: answeredContent && input.contentTruncated,
118
+ linesClipped: answeredContent && input.linesClipped,
119
+ }
120
+ }
121
+
122
+ /** First non-empty warning line from a finished search, or undefined. */
123
+ export function stderrWarning(stderr: string, maxChars = 200): string | undefined {
124
+ for (const line of stderr.split('\n')) {
125
+ const trimmed = line.trim()
126
+ if (trimmed !== '') return trimmed.length > maxChars ? `${trimmed.slice(0, maxChars)}…` : trimmed
127
+ }
128
+ return undefined
129
+ }
130
+
131
+ /**
132
+ * What clicking one NAME result should do.
133
+ *
134
+ * `find` can report a DIRECTORY, and `store.openFile()` has no type guard: a
135
+ * click used to hand the directory path to the editor (the Host answered
136
+ * "not a file: … is a directory" and the surface was switched for nothing).
137
+ */
138
+ export function nameHitAction(hit: { isDir: boolean }): 'reveal' | 'open' {
139
+ return hit.isDir ? 'reveal' : 'open'
140
+ }
141
+
142
+ /** True when a rejection is a user cancel (not a failure to report). */
143
+ export function isSearchCancellation(error: unknown, signal: AbortSignal | undefined): boolean {
144
+ if (signal?.aborted === true) return true
145
+ return error instanceof Error && error.name === 'AbortError'
146
+ }
147
+
148
+ /** Set once the Host proved it has no exec-stream route (older Host fallback). */
149
+ let contentSearchStreamUnsupported = false
150
+ /** Cap for the streamed content-search output (the parser caps hits anyway). */
151
+ const CONTENT_STREAM_ACCUM_CAP = 8 * 1024 * 1024
152
+
153
+ /**
154
+ * One content search over the STREAMING exec route.
155
+ *
156
+ * `api.exec` cannot be cancelled: a replaced query left the remote `grep`
157
+ * running for its whole 120 s budget while the client ignored the answer.
158
+ * `execStream` carries an AbortSignal and the Host kills the remote process
159
+ * group when the response closes, so a cancelled search really stops. The
160
+ * route forwards output as SSE frames instead of `stdout`/`stderr`, so they are
161
+ * accumulated here and handed to the same parser as before. A Host without the
162
+ * route (404/405) is remembered and served by `api.exec` from then on.
163
+ */
164
+ export async function runContentSearch(alias: string, command: string, signal: AbortSignal): Promise<RemoteExecResult> {
165
+ if (contentSearchStreamUnsupported) return api.exec(alias, command, 120_000)
166
+ let stdout = ''
167
+ let stderr = ''
168
+ const append = (stream: 'out' | 'err', text: string): void => {
169
+ if (stdout.length + stderr.length >= CONTENT_STREAM_ACCUM_CAP) return
170
+ if (stream === 'out') stdout += text
171
+ else stderr += text
172
+ }
173
+ try {
174
+ const result = await api.execStream(alias, command, 120_000, {
175
+ signal,
176
+ onData: (stream, text) => append(stream === 'out' ? 'out' : 'err', text),
177
+ })
178
+ return { ...result, stdout, stderr }
179
+ } catch (error) {
180
+ if (isSearchCancellation(error, signal)) throw error
181
+ if (error instanceof RemoteApiError && (error.status === 404 || error.status === 405)) {
182
+ contentSearchStreamUnsupported = true
183
+ return api.exec(alias, command, 120_000)
184
+ }
185
+ throw error
186
+ }
187
+ }
188
+
83
189
  export function SearchView(): ReactNode {
84
190
  const store = useExplorer()
85
191
  const { t, alias, root, repoRoot } = store
@@ -97,9 +203,16 @@ export function SearchView(): ReactNode {
97
203
  const [busy, setBusy] = useState(false)
98
204
  const [ran, setRan] = useState(false)
99
205
  const [error, setError] = useState<string | undefined>(undefined)
206
+ /** Non-fatal stderr from the last answered content search. */
207
+ const [warning, setWarning] = useState<string | undefined>(undefined)
100
208
  const seq = useRef(0)
209
+ /** Aborts the in-flight content search when the query changes/clears. */
210
+ const runAbort = useRef<AbortController | undefined>(undefined)
101
211
  const menu = useContextMenu()
102
212
 
213
+ /** Nothing may keep streaming after the panel is gone. */
214
+ useEffect(() => () => { runAbort.current?.abort() }, [])
215
+
103
216
  const effectiveScope = scope === '' ? root : scope
104
217
  const scopeLabel = useMemo(() => {
105
218
  if (effectiveScope === '' || root === '') return ''
@@ -139,16 +252,37 @@ export function SearchView(): ReactNode {
139
252
  // its own ticket, and results for a query the user already cleared (or
140
253
  // for the previous workspace) get rendered into the empty panel.
141
254
  seq.current += 1
255
+ // Stop the remote grep instead of only ignoring its answer (it used to
256
+ // keep a channel busy for the whole 120 s budget).
257
+ runAbort.current?.abort()
258
+ runAbort.current = undefined
142
259
  setBusy(false)
143
260
  setNameHits([])
144
261
  setContentHits([])
145
262
  setRan(false)
146
263
  setError(undefined)
264
+ setWarning(undefined)
265
+ // The truncation banners describe the answer that just went away; left
266
+ // set, they would hang over an empty panel and read as a claim about the
267
+ // cleared query. `visibleSearchBanners` is the other half of this guard
268
+ // (it also keeps the content flags out of the name mode).
269
+ setNameTruncated(false)
270
+ setContentTruncated(false)
271
+ setLinesClipped(false)
147
272
  return
148
273
  }
149
274
  const ticket = ++seq.current
150
275
  setBusy(true)
151
276
  setError(undefined)
277
+ setWarning(undefined)
278
+ // A banner must never outlive the answer it describes: clear the ones this
279
+ // run is about to refresh, so switching modes/queries cannot show the
280
+ // previous answer's "truncated" while the new one is still on the wire.
281
+ if (activeMode === 'name') setNameTruncated(false)
282
+ else {
283
+ setContentTruncated(false)
284
+ setLinesClipped(false)
285
+ }
152
286
  try {
153
287
  if (activeMode === 'name') {
154
288
  const result = await searchFiles(alias, dir, trimmed)
@@ -163,7 +297,12 @@ export function SearchView(): ReactNode {
163
297
  wholeWord: opts.wholeWord,
164
298
  regex: opts.regex,
165
299
  })
166
- const result = await api.exec(alias, command, 120_000)
300
+ // Replace (not just ignore) the previous search: abort first so the
301
+ // remote process group stops, then run this one with its own controller.
302
+ runAbort.current?.abort()
303
+ const controller = new AbortController()
304
+ runAbort.current = controller
305
+ const result = await runContentSearch(alias, command, controller.signal)
167
306
  if (seq.current !== ticket) return
168
307
  if (!result.success && result.stdout.trim() === '' && result.stderr.trim() !== '') {
169
308
  // grep exits 1 when nothing matched — that is a result, not a failure,
@@ -184,11 +323,20 @@ export function SearchView(): ReactNode {
184
323
  setContentTruncated(parsed.truncated)
185
324
  setLinesClipped(parsed.linesClipped)
186
325
  setNameHits([])
326
+ // Warnings with hits used to be dropped on the floor by the `else`
327
+ // branch: keep them visible above the results.
328
+ setWarning(stderrWarning(result.stderr))
187
329
  }
330
+ if (runAbort.current === controller) runAbort.current = undefined
188
331
  }
189
332
  setRan(true)
190
333
  } catch (caught) {
191
334
  if (seq.current !== ticket) return
335
+ // A cancelled search is not an error: the ticket already moved on.
336
+ if (isSearchCancellation(caught, activeMode === 'content' ? runAbort.current?.signal : undefined)) {
337
+ setBusy(false)
338
+ return
339
+ }
192
340
  setError(caught instanceof Error ? caught.message : String(caught))
193
341
  setContentHits([])
194
342
  setNameHits([])
@@ -215,6 +363,20 @@ export function SearchView(): ReactNode {
215
363
  // eslint-disable-next-line react-hooks/exhaustive-deps
216
364
  }, [request?.id])
217
365
 
366
+ /**
367
+ * A workspace switch invalidates an absolute scope.
368
+ *
369
+ * The scope is an absolute remote path from the previous workspace; running
370
+ * `find`/`grep` with it against the NEW alias searches a tree that host may
371
+ * not have (or a different one at the same spelling). Reset to the workspace
372
+ * root instead of sending the stale path. The scope setter and this effect
373
+ * cannot fight: the request effect above runs first, and a scope that belongs
374
+ * to the new root is left alone.
375
+ */
376
+ useEffect(() => {
377
+ if (scope !== '' && !scopeBelongsToRoot(scope, root)) setScope('')
378
+ }, [scope, root, alias])
379
+
218
380
  /**
219
381
  * A hit ALWAYS opens the file.
220
382
  *
@@ -311,6 +473,9 @@ export function SearchView(): ReactNode {
311
473
  )
312
474
 
313
475
  const count = mode === 'name' ? nameHits.length : contentHits.length
476
+ // One rule for "may this banner be on screen": answered, in this mode, and
477
+ // the flag belongs to the answer that is actually visible.
478
+ const banners = visibleSearchBanners({ mode, ran, nameTruncated, contentTruncated, linesClipped })
314
479
 
315
480
  return (
316
481
  <div className="rvs-pane grow">
@@ -384,8 +549,9 @@ export function SearchView(): ReactNode {
384
549
  )}
385
550
 
386
551
  {error !== undefined && <div className="rvs-banner error">{error}</div>}
387
- {contentTruncated && <div className="rvs-banner warn">{t('search.truncated')}</div>}
388
- {linesClipped && <div className="rvs-banner warn">{t('search.linesClipped')}</div>}
552
+ {warning !== undefined && <div className="rvs-banner warn">{t('search.stderrWarn').replace('{detail}', warning)}</div>}
553
+ {banners.contentTruncated && <div className="rvs-banner warn">{t('search.truncated')}</div>}
554
+ {banners.linesClipped && <div className="rvs-banner warn">{t('search.linesClipped')}</div>}
389
555
 
390
556
  <div className="rvs-scroll">
391
557
  {!ran && query.trim() === '' && (
@@ -401,7 +567,15 @@ export function SearchView(): ReactNode {
401
567
  type="button"
402
568
  className="rvs-hit"
403
569
  title={hit.path}
404
- onClick={() => openHit(`${(effectiveScope === '' ? root : effectiveScope).replace(/\/+$/, '')}/${hit.path}`)}
570
+ onClick={() => {
571
+ // A `find` hit can be a DIRECTORY: opening it as a file asks
572
+ // the Host to read a directory and switches the surface for
573
+ // nothing. Reveal it in the explorer instead (same action the
574
+ // right-click menu offers for directories).
575
+ const { abs } = nameHitPaths(hit)
576
+ if (nameHitAction(hit) === 'reveal') store.revealInExplorer(abs)
577
+ else openHit(abs)
578
+ }}
405
579
  onContextMenu={(event) => { openHitMenu(event, hit) }}
406
580
  >
407
581
  <span className="rvs-node-icon">
@@ -411,7 +585,7 @@ export function SearchView(): ReactNode {
411
585
  {hit.dir !== '' && <span className="rvs-hit-dir">{hit.dir}</span>}
412
586
  </button>
413
587
  ))}
414
- {nameTruncated && <div className="rvs-empty">{t('search.truncated')}</div>}
588
+ {banners.nameTruncated && <div className="rvs-empty">{t('search.truncated')}</div>}
415
589
  </>
416
590
  )}
417
591
 
@@ -64,7 +64,7 @@ export function SettingsHostsSection(_props: SettingsSectionOwnerProps): ReactNo
64
64
  setSaving(true)
65
65
  setError(undefined)
66
66
  api.setRoutingMode(next).then(
67
- (live) => setMode(live),
67
+ (live) => { setMode(live); refreshSidebarStore() },
68
68
  (e: unknown) => setError(e instanceof RemoteApiError ? e.message : String(e)),
69
69
  ).finally(() => setSaving(false))
70
70
  }