dsh-remote-vs 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.en.md +12 -15
  2. package/README.md +11 -12
  3. package/THIRD-PARTY-NOTICES.md +193 -0
  4. package/lib/client.js +7313 -79961
  5. package/lib/index.js +1529 -964
  6. package/lib/p2-router-fs.js +1 -1
  7. package/lib/types/client/CodeEditor.d.ts +22 -0
  8. package/lib/types/client/OutlinePanel.d.ts +22 -0
  9. package/lib/types/client/ProcessesSection.d.ts +19 -0
  10. package/lib/types/client/RemoteExplorer.d.ts +53 -0
  11. package/lib/types/client/api.d.ts +42 -3
  12. package/lib/types/client/blame-model.d.ts +77 -0
  13. package/lib/types/client/changes/review-state.d.ts +19 -0
  14. package/lib/types/client/connection.d.ts +16 -0
  15. package/lib/types/client/i18n.d.ts +1 -1
  16. package/lib/types/client/outline-model.d.ts +59 -0
  17. package/lib/types/client/request-gate.d.ts +110 -0
  18. package/lib/types/client/scm/DiffView.d.ts +45 -7
  19. package/lib/types/client/scm/actions.d.ts +43 -4
  20. package/lib/types/client/store.d.ts +71 -0
  21. package/lib/types/client/vsc/FindWidget.d.ts +6 -0
  22. package/lib/types/client/vsc/blame.d.ts +19 -0
  23. package/lib/types/client/vsc/change-marks.d.ts +16 -6
  24. package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
  25. package/lib/types/client/vsc/kit.d.ts +11 -2
  26. package/lib/types/client/vsc/preview-document.d.ts +46 -0
  27. package/lib/types/client/vsc/preview-model.d.ts +31 -0
  28. package/lib/types/client/vsc/preview-services.d.ts +24 -0
  29. package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
  30. package/lib/types/client/vsc/terminal-theme.d.ts +28 -2
  31. package/lib/types/forward.d.ts +12 -0
  32. package/lib/types/fs-ops.d.ts +42 -0
  33. package/lib/types/git-ops.d.ts +18 -0
  34. package/lib/types/http.d.ts +2 -0
  35. package/lib/types/keygen.d.ts +9 -0
  36. package/lib/types/monitor.d.ts +8 -0
  37. package/lib/types/notices.d.ts +16 -1
  38. package/lib/types/p2/helper-rpc.d.ts +45 -0
  39. package/lib/types/processes.d.ts +43 -0
  40. package/lib/types/protocol.d.ts +34 -0
  41. package/lib/types/routes.d.ts +2 -0
  42. package/lib/types/store.d.ts +7 -0
  43. package/lib/types/terminal.d.ts +8 -0
  44. package/lib/types/view-settings.d.ts +5 -0
  45. package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
  46. package/package.json +3 -1
  47. package/src/client/CodeEditor.tsx +194 -9
  48. package/src/client/DirectoryFlow.tsx +16 -0
  49. package/src/client/DoctorPanel.tsx +70 -7
  50. package/src/client/EditorPane.tsx +574 -42
  51. package/src/client/HostsView.tsx +12 -3
  52. package/src/client/MonitorView.tsx +16 -5
  53. package/src/client/OutlinePanel.tsx +287 -0
  54. package/src/client/ProcessesSection.tsx +292 -0
  55. package/src/client/RemoteDirectoryPicker.tsx +12 -0
  56. package/src/client/RemoteExplorer.tsx +929 -40
  57. package/src/client/RemoteRoot.tsx +147 -22
  58. package/src/client/SearchView.tsx +8 -0
  59. package/src/client/TerminalSnippets.tsx +83 -8
  60. package/src/client/api.ts +114 -13
  61. package/src/client/blame-model.ts +242 -0
  62. package/src/client/changes/ChangesDock.tsx +188 -6
  63. package/src/client/changes/changes.css +10 -3
  64. package/src/client/changes/review-state.ts +34 -0
  65. package/src/client/connection.ts +29 -0
  66. package/src/client/downloads.ts +49 -4
  67. package/src/client/i18n.ts +276 -8
  68. package/src/client/index.tsx +4 -0
  69. package/src/client/outline-model.ts +775 -0
  70. package/src/client/request-gate.ts +221 -0
  71. package/src/client/scm/CommitPane.tsx +20 -2
  72. package/src/client/scm/DiffView.tsx +343 -117
  73. package/src/client/scm/HistoryPanel.tsx +61 -3
  74. package/src/client/scm/RepoPicker.tsx +1 -1
  75. package/src/client/scm/ScmPanel.tsx +391 -87
  76. package/src/client/scm/actions.ts +150 -14
  77. package/src/client/store.tsx +426 -14
  78. package/src/client/ui.tsx +4 -0
  79. package/src/client/vsc/FindWidget.tsx +24 -9
  80. package/src/client/vsc/blame.ts +147 -0
  81. package/src/client/vsc/breadcrumb.tsx +91 -3
  82. package/src/client/vsc/change-marks.ts +93 -44
  83. package/src/client/vsc/editor-keymap.ts +59 -1
  84. package/src/client/vsc/file-icons.tsx +17 -3
  85. package/src/client/vsc/kit.tsx +29 -20
  86. package/src/client/vsc/preview-document.tsx +323 -0
  87. package/src/client/vsc/preview-model.ts +216 -0
  88. package/src/client/vsc/preview-services.ts +118 -0
  89. package/src/client/vsc/save-shortcut.ts +47 -1
  90. package/src/client/vsc/terminal-theme.ts +44 -18
  91. package/src/client/vsc/vsc.css +6509 -5458
  92. package/src/forward.ts +47 -9
  93. package/src/fs-ops.ts +124 -4
  94. package/src/git-ops.ts +54 -3
  95. package/src/http.ts +35 -4
  96. package/src/keygen.ts +55 -4
  97. package/src/monitor.ts +13 -0
  98. package/src/notices.ts +23 -1
  99. package/src/p2/helper-rpc.ts +113 -7
  100. package/src/p2/worlds.ts +14 -1
  101. package/src/processes.ts +177 -0
  102. package/src/protocol.ts +37 -0
  103. package/src/routes.ts +330 -43
  104. package/src/sftp.ts +51 -14
  105. package/src/store.ts +10 -0
  106. package/src/terminal.ts +73 -26
  107. package/src/view-settings.ts +50 -10
  108. package/lib/types/client/Dialog.d.ts +0 -14
  109. package/src/client/Dialog.tsx +0 -76
@@ -6,6 +6,7 @@ import type { RemoteDeployState, RemoteHostSummary } from '../protocol.ts'
6
6
  import { RemoteApiError, api, type HostForm } from './api.ts'
7
7
  import { DoctorPanel } from './DoctorPanel.tsx'
8
8
  import { Btn, Field, Notice, Row, hairline, inputStyle } 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)
@@ -204,8 +205,16 @@ export function HostsView(props: {
204
205
  )
205
206
  }
206
207
 
207
- const runDelete = (alias: string): void => {
208
- if (!window.confirm(t('hosts.confirmDelete'))) return
208
+ const runDelete = async (alias: string): Promise<void> => {
209
+ // Themed confirm instead of `window.confirm`: the native one ignores the
210
+ // plugin theme, is not keyboard-trapped with the rest of the UI and cannot
211
+ // mark the action as destructive.
212
+ const ok = await confirmDialog({
213
+ title: t('hosts.confirmDelete'),
214
+ danger: true,
215
+ okText: t('hosts.delete'),
216
+ })
217
+ if (!ok) return
209
218
  setBusy(`del:${alias}`)
210
219
  api.deleteHost(alias).then(
211
220
  () => { setBusy(undefined); say(t('hosts.deleted').replace('{alias}', alias)); props.onChanged() },
@@ -303,7 +312,7 @@ export function HostsView(props: {
303
312
  <Btn onClick={() => { setEditing(editing === h.alias ? null : h.alias); setNotice(undefined); setError(undefined) }} disabled={disabled}>
304
313
  {t('hosts.edit')}
305
314
  </Btn>
306
- <Btn kind="danger" onClick={() => runDelete(h.alias)} disabled={disabled}>{t('hosts.delete')}</Btn>
315
+ <Btn kind="danger" onClick={() => { void runDelete(h.alias) }} disabled={disabled}>{t('hosts.delete')}</Btn>
307
316
  </Row>
308
317
  {editing === h.alias && (
309
318
  <HostFormView t={t} initial={h} busy={disabled} onSave={saveForm} onCancel={() => setEditing(null)} />
@@ -30,6 +30,7 @@ import {
30
30
  import { useExplorer } from './store.tsx'
31
31
  import { optionStyle } from './ui.tsx'
32
32
  import { IconButton, IconRefresh, MiniSpinner, Segmented } from './vsc/kit.tsx'
33
+ import { ProcessesSection } from './ProcessesSection.tsx'
33
34
 
34
35
  /** Visible-panel poll cadence. The Host's own reuse window is shorter (3 s). */
35
36
  export const MONITOR_POLL_MS = 5_000
@@ -625,11 +626,21 @@ export function MonitorView(props: {
625
626
  </div>
626
627
  )}
627
628
  <div className="rvs-monitor-body">
628
- {props.hosts.length === 0 && <div className="rvs-banner warn">{t('monitor.noHosts')}</div>}
629
- {props.hosts.length > 0 && aliases.length === 0 && <div className="rvs-empty">{t('monitor.noHost')}</div>}
630
- {paused && <div className="rvs-banner info">{t('monitor.paused')}</div>}
631
- {single !== undefined && renderDetail(single)}
632
- {single === undefined && aliases.length > 1 && renderAll(aliases)}
629
+ <div className="rvs-monitor-content rvs-scroll">
630
+ {props.hosts.length === 0 && <div className="rvs-banner warn">{t('monitor.noHosts')}</div>}
631
+ {props.hosts.length > 0 && aliases.length === 0 && <div className="rvs-empty">{t('monitor.noHost')}</div>}
632
+ {paused && <div className="rvs-banner info">{t('monitor.paused')}</div>}
633
+ {single !== undefined && renderDetail(single)}
634
+ {single === undefined && aliases.length > 1 && renderAll(aliases)}
635
+ </div>
636
+ <ProcessesSection
637
+ t={t}
638
+ hosts={props.hosts}
639
+ aliases={aliases}
640
+ visible={props.visible}
641
+ paused={paused}
642
+ intervalMs={intervalMs}
643
+ />
633
644
  </div>
634
645
  </div>
635
646
  )
@@ -0,0 +1,287 @@
1
+ /**
2
+ * 符号大纲浮层:可筛选的符号列表 + ↑↓/Enter/点击跳转。
3
+ *
4
+ * 只在打开时挂载(父组件用 `undefined` 表示关闭),所以「关闭」就是卸载 —— 不会
5
+ * 留下第二个 `isOpen` 状态要同步,也不会在关闭后留一个偷键盘的监听器。条目由
6
+ * `outline-model.ts` 的纯函数产出;这里只负责像素、焦点和按键。
7
+ *
8
+ * PORTAL 到 `<body>`:编辑器有三种座位(侧栏 / 中间 / 浮窗),浮层若留在原 DOM
9
+ * 里会被祖先的 `overflow: hidden` 裁掉。`.rvs-portal` 负责声明 `--rvs-*` token
10
+ * 子集 —— portal 之后已经不在 `.rvs-root` 作用域内,缺了它颜色/边框全是空值。
11
+ */
12
+ import { useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react'
13
+ import { createPortal } from 'react-dom'
14
+ import { matchPositions } from './quickopen-model.ts'
15
+ import {
16
+ OUTLINE_RESULT_LIMIT,
17
+ buildOutline,
18
+ rankOutline,
19
+ type OutlineEntry,
20
+ } from './outline-model.ts'
21
+
22
+ /** 一行:kind 徽标 + 缩进过的名字 + 行号。 */
23
+ function Row(props: {
24
+ entry: OutlineEntry
25
+ query: string
26
+ active: boolean
27
+ index: number
28
+ id: string
29
+ t: (key: string) => string
30
+ onPick: () => void
31
+ onHover: () => void
32
+ }): ReactNode {
33
+ const { entry } = props
34
+ // 高亮的位置来自 quickopen 的 `matchPositions`:与过滤用的是同一套贪心匹配,
35
+ // 所以「为什么这行算命中」和「高亮哪几个字符」永远一致。
36
+ const positions = useMemo(() => new Set(matchPositions(props.query, entry.name)), [props.query, entry.name])
37
+ return (
38
+ <div
39
+ className={props.active ? 'rvs-outline-row active' : 'rvs-outline-row'}
40
+ role="option"
41
+ aria-selected={props.active}
42
+ id={props.id}
43
+ data-outline-index={props.index}
44
+ data-outline-depth={entry.depth}
45
+ data-outline-kind={entry.kind}
46
+ // mousedown 而不是 click:列表不能在跳转前先丢焦点,而重排后的 click 可能
47
+ // 落到用户没指的那一行上。
48
+ onMouseDown={(event) => {
49
+ event.preventDefault()
50
+ props.onPick()
51
+ }}
52
+ onMouseEnter={props.onHover}
53
+ >
54
+ <span className="rvs-outline-kind" data-kind={entry.kind}>{props.t(`outline.kind.${entry.kind}`)}</span>
55
+ <span
56
+ className="rvs-outline-name"
57
+ style={{ paddingLeft: `${entry.depth * 14}px` }}
58
+ title={entry.container === undefined ? entry.name : `${entry.container} › ${entry.name}`}
59
+ >
60
+ {entry.name.split('').map((character, at) => (
61
+ positions.has(at)
62
+ ? <mark key={at} className="rvs-outline-hit">{character}</mark>
63
+ : <span key={at}>{character}</span>
64
+ ))}
65
+ </span>
66
+ <span className="rvs-outline-line">{entry.line}</span>
67
+ </div>
68
+ )
69
+ }
70
+
71
+ export function OutlinePanel(props: {
72
+ t: (key: string) => string
73
+ /** 远端绝对路径(判断语言 + 标题)。 */
74
+ path: string
75
+ /** 实时缓冲区全文:dirty 时必须来自编辑器,不是 `tab.text`。 */
76
+ text: string
77
+ onPick: (entry: OutlineEntry) => void
78
+ onClose: () => void
79
+ }): ReactNode {
80
+ // Two editor seats can keep an outline open at once; DOM ids must not collide.
81
+ const listId = useId()
82
+ const optionId = (index: number): string => `${listId}-option-${index}`
83
+ const t = props.t
84
+ const outline = useMemo(() => buildOutline(props.text, props.path), [props.text, props.path])
85
+ const [query, setQuery] = useState('')
86
+ const [active, setActive] = useState(0)
87
+ const inputRef = useRef<HTMLInputElement>(null)
88
+ const listRef = useRef<HTMLDivElement>(null)
89
+ const boxRef = useRef<HTMLDivElement>(null)
90
+
91
+ /** 最新的关闭回调:window 监听只装一次,不能跟着每次渲染重装。 */
92
+ const closeRef = useRef(props.onClose)
93
+ closeRef.current = props.onClose
94
+
95
+ /** 关闭时把焦点还给打开它的那个元素(portal 自身不会恢复)。 */
96
+ const openerRef = useRef<HTMLElement | null>(
97
+ typeof document === 'undefined' ? null : (document.activeElement as HTMLElement | null),
98
+ )
99
+
100
+ useEffect(() => {
101
+ inputRef.current?.focus()
102
+ return () => {
103
+ const opener = openerRef.current
104
+ if (opener !== null && document.body.contains(opener)) opener.focus()
105
+ }
106
+ }, [])
107
+
108
+ const ranked = useMemo(() => rankOutline(query, outline.entries, OUTLINE_RESULT_LIMIT), [query, outline])
109
+ const count = ranked.hits.length
110
+ const current = count === 0 ? -1 : Math.min(active, count - 1)
111
+
112
+ // 新查询从第一行开始,绝不停在上一轮的旧行上。
113
+ useEffect(() => {
114
+ setActive(0)
115
+ }, [query])
116
+
117
+ useEffect(() => {
118
+ if (current < 0) return
119
+ listRef.current?.querySelector<HTMLElement>(`[data-outline-index="${current}"]`)
120
+ ?.scrollIntoView?.({ block: 'nearest' })
121
+ }, [current])
122
+
123
+ const pick = (entry: OutlineEntry): void => {
124
+ props.onPick(entry)
125
+ }
126
+
127
+ const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {
128
+ // 输入法候选窗用 Enter/方向键选字:此时按 Enter 就跳走等于打断中文输入。
129
+ if (event.nativeEvent.isComposing === true || event.keyCode === 229) return
130
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
131
+ event.preventDefault()
132
+ if (count === 0) return
133
+ setActive((previous) => {
134
+ const at = Math.min(previous, count - 1)
135
+ if (event.key === 'ArrowDown') return (at + 1) % count
136
+ return at <= 0 ? count - 1 : at - 1
137
+ })
138
+ return
139
+ }
140
+ if (event.key === 'Enter') {
141
+ event.preventDefault()
142
+ const target = current >= 0 ? ranked.hits[current] : undefined
143
+ if (target !== undefined) pick(target)
144
+ }
145
+ }
146
+
147
+ /** Tab 不许离开浮层:列表行不是焦点元素,Tab 会落到后面的页面元素上。 */
148
+ const onDialogKeyDown = (event: React.KeyboardEvent<HTMLDivElement>): void => {
149
+ if (event.key !== 'Tab') return
150
+ const box = boxRef.current
151
+ if (box === null) return
152
+ const items = Array.from(box.querySelectorAll<HTMLElement>(
153
+ 'input:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])',
154
+ ))
155
+ if (items.length === 0) return
156
+ const first = items[0]
157
+ const last = items[items.length - 1]
158
+ const at = document.activeElement
159
+ const inside = at !== null && box.contains(at)
160
+ if (!inside) {
161
+ event.preventDefault()
162
+ first?.focus()
163
+ return
164
+ }
165
+ if (event.shiftKey && at === first) {
166
+ event.preventDefault()
167
+ last?.focus()
168
+ return
169
+ }
170
+ if (!event.shiftKey && at === last) {
171
+ event.preventDefault()
172
+ first?.focus()
173
+ }
174
+ }
175
+
176
+ useEffect(() => {
177
+ const onKey = (event: KeyboardEvent): void => {
178
+ if (event.key !== 'Escape') return
179
+ event.preventDefault()
180
+ event.stopPropagation()
181
+ closeRef.current()
182
+ }
183
+ window.addEventListener('keydown', onKey, true)
184
+ return () => window.removeEventListener('keydown', onKey, true)
185
+ }, [])
186
+
187
+ /**
188
+ * 状态行。
189
+ *
190
+ * 「猜的大纲」与「被截断」是两条独立的常驻警告:它们说的是「这份列表不完整」,
191
+ * 不能被「没有匹配」替换掉 —— 那个是查询的结果,不是数据的性质。
192
+ */
193
+ const foot = (): ReactNode => {
194
+ if (count === 0) {
195
+ return (
196
+ <span className="rvs-outline-note" role="status">
197
+ {outline.entries.length === 0 ? t('outline.empty') : t('outline.noResults')}
198
+ </span>
199
+ )
200
+ }
201
+ return (
202
+ <span className="rvs-outline-note">
203
+ {ranked.truncated
204
+ ? t('outline.more').replace('{count}', String(count)).replace('{total}', String(outline.total))
205
+ : `${count} / ${outline.total}`}
206
+ </span>
207
+ )
208
+ }
209
+
210
+ if (typeof document === 'undefined') return null
211
+ return createPortal(
212
+ <div className="rvs-portal">
213
+ <div
214
+ className="rvs-outline-mask"
215
+ onMouseDown={(event) => { if (event.target === event.currentTarget) props.onClose() }}
216
+ >
217
+ <div
218
+ className="rvs-outline"
219
+ role="dialog"
220
+ aria-modal="true"
221
+ aria-label={t('outline.title')}
222
+ ref={boxRef}
223
+ onKeyDown={onDialogKeyDown}
224
+ >
225
+ <div className="rvs-outline-head">
226
+ <span className="rvs-outline-title">{t('outline.title')}</span>
227
+ <span className="rvs-outline-path" title={props.path}>{props.path}</span>
228
+ <button
229
+ type="button"
230
+ className="rvs-outline-close"
231
+ title={t('common.close')}
232
+ aria-label={t('common.close')}
233
+ onClick={props.onClose}
234
+ >
235
+ ×
236
+ </button>
237
+ </div>
238
+ <div className="rvs-outline-bar">
239
+ <input
240
+ ref={inputRef}
241
+ className="rvs-outline-input"
242
+ type="text"
243
+ value={query}
244
+ placeholder={t('outline.placeholder')}
245
+ spellCheck={false}
246
+ autoComplete="off"
247
+ role="combobox"
248
+ aria-expanded
249
+ aria-controls={listId}
250
+ aria-activedescendant={current >= 0 ? optionId(current) : undefined}
251
+ onChange={(event) => setQuery(event.target.value)}
252
+ onKeyDown={onInputKeyDown}
253
+ />
254
+ <span className="rvs-outline-hint">{t('outline.hint')}</span>
255
+ </div>
256
+ <div className="rvs-outline-list" id={listId} role="listbox" ref={listRef}>
257
+ {ranked.hits.map((entry, index) => (
258
+ <Row
259
+ key={`${entry.line}:${entry.name}:${index}`}
260
+ entry={entry}
261
+ query={query}
262
+ active={index === current}
263
+ index={index}
264
+ id={optionId(index)}
265
+ t={t}
266
+ onPick={() => pick(entry)}
267
+ onHover={() => setActive(index)}
268
+ />
269
+ ))}
270
+ </div>
271
+ <div className="rvs-outline-foot">
272
+ {foot()}
273
+ {outline.guessed && (
274
+ <span className="rvs-outline-note warn" role="status">{t('outline.guessed')}</span>
275
+ )}
276
+ {outline.truncated && (
277
+ <span className="rvs-outline-note warn" role="status">
278
+ {t('outline.truncated').replace('{count}', String(outline.entries.length))}
279
+ </span>
280
+ )}
281
+ </div>
282
+ </div>
283
+ </div>
284
+ </div>,
285
+ document.body,
286
+ )
287
+ }
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Remote process table shown on the monitor page.
3
+ *
4
+ * One bounded snapshot per selected host, polled only while the monitor page and
5
+ * the browser tab are both visible. Killing is always confirmed and always goes
6
+ * through the Host route (which validates the PID against its own snapshot), so
7
+ * the browser never builds a shell command from a process row.
8
+ */
9
+ import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
10
+ import type { RemoteHostSummary, RemoteProcess, RemoteProcessesResult } from '../protocol.ts'
11
+ import { api, RemoteApiError } from './api.ts'
12
+ import { IconButton, IconRefresh, MiniSpinner, confirmDialog, toast } from './vsc/kit.tsx'
13
+
14
+ export const PROCESS_POLL_MS = 5_000
15
+
16
+ type SortKey = 'cpu' | 'mem' | 'pid'
17
+
18
+ function formatElapsed(seconds: number | null, t: (key: string) => string): string {
19
+ if (seconds === null || !Number.isFinite(seconds) || seconds < 0) return t('proc.unknown')
20
+ const days = Math.floor(seconds / 86_400)
21
+ const hours = Math.floor((seconds % 86_400) / 3_600)
22
+ const minutes = Math.floor((seconds % 3_600) / 60)
23
+ if (days > 0) return `${days}d ${hours}h`
24
+ if (hours > 0) return `${hours}h ${minutes}m`
25
+ if (minutes > 0) return `${minutes}m`
26
+ return `${Math.max(1, Math.floor(seconds))}s`
27
+ }
28
+
29
+ function percent(value: number): string {
30
+ return `${value.toFixed(1)}%`
31
+ }
32
+
33
+ function sortRows(rows: readonly RemoteProcess[], key: SortKey): RemoteProcess[] {
34
+ const copy = [...rows]
35
+ if (key === 'pid') copy.sort((left, right) => left.pid - right.pid)
36
+ else {
37
+ const field = key === 'cpu' ? 'cpuPercent' : 'memPercent'
38
+ copy.sort((left, right) => right[field] - left[field] || left.pid - right.pid)
39
+ }
40
+ return copy
41
+ }
42
+
43
+ export function ProcessesSection(props: {
44
+ t: (key: string) => string
45
+ hosts: RemoteHostSummary[]
46
+ aliases: string[]
47
+ visible: boolean
48
+ paused: boolean
49
+ intervalMs: number
50
+ }): ReactNode {
51
+ const t = props.t
52
+ const [alias, setAlias] = useState(props.aliases[0] ?? '')
53
+ const [expanded, setExpanded] = useState(false)
54
+ const [result, setResult] = useState<RemoteProcessesResult | undefined>(undefined)
55
+ const [loading, setLoading] = useState(false)
56
+ const [error, setError] = useState<string | undefined>(undefined)
57
+ const [filter, setFilter] = useState('')
58
+ const [sortKey, setSortKey] = useState<SortKey>('cpu')
59
+ const [killing, setKilling] = useState<number | undefined>(undefined)
60
+ const [forcePid, setForcePid] = useState<number | undefined>(undefined)
61
+ const inFlight = useRef<Set<string>>(new Set())
62
+ const aliasRef = useRef(alias)
63
+ aliasRef.current = alias
64
+ const alive = useRef(true)
65
+
66
+ useEffect(() => {
67
+ alive.current = true
68
+ return () => { alive.current = false }
69
+ }, [])
70
+
71
+ // The scope can change from "all hosts" to one host, or disappear entirely.
72
+ useEffect(() => {
73
+ if (props.aliases.includes(alias)) return
74
+ setAlias(props.aliases[0] ?? '')
75
+ setResult(undefined)
76
+ setError(undefined)
77
+ }, [props.aliases, alias])
78
+
79
+ const load = useCallback(async (force = false, manual = false): Promise<void> => {
80
+ const requested = alias
81
+ if (requested === '' || inFlight.current.has(requested)) return
82
+ inFlight.current.add(requested)
83
+ if (manual) setLoading(true)
84
+ try {
85
+ const next = await api.processes(requested, force)
86
+ // The user may have switched hosts while this request was in flight: an
87
+ // old host's table must never paint under (or be killed from) the new one.
88
+ if (!alive.current || requested !== aliasRef.current) return
89
+ setResult(next)
90
+ setError(next.error)
91
+ } catch (caught) {
92
+ if (!alive.current) return
93
+ setError(
94
+ caught instanceof RemoteApiError && caught.status === 404
95
+ ? t('proc.hostTooOld')
96
+ : caught instanceof RemoteApiError ? caught.message : String(caught),
97
+ )
98
+ } finally {
99
+ inFlight.current.delete(requested)
100
+ if (manual && alive.current && requested === aliasRef.current) setLoading(false)
101
+ }
102
+ }, [alias])
103
+
104
+ useEffect(() => {
105
+ if (!expanded || !props.visible || props.paused || alias === '') return
106
+ const tick = (): void => {
107
+ if (document.hidden) return
108
+ void load(false, false)
109
+ }
110
+ tick()
111
+ const timer = window.setInterval(tick, Math.max(2_000, props.intervalMs || PROCESS_POLL_MS))
112
+ return () => window.clearInterval(timer)
113
+ }, [expanded, props.visible, props.paused, alias, load, props.intervalMs])
114
+
115
+ useEffect(() => {
116
+ if (!expanded || !props.visible || props.paused) return
117
+ const onVisible = (): void => {
118
+ if (!document.hidden) void load(false, false)
119
+ }
120
+ document.addEventListener('visibilitychange', onVisible)
121
+ return () => document.removeEventListener('visibilitychange', onVisible)
122
+ }, [expanded, props.visible, props.paused, load])
123
+
124
+ const rows = useMemo(() => {
125
+ const needle = filter.trim().toLowerCase()
126
+ const source = result?.processes ?? []
127
+ const filtered = needle === ''
128
+ ? source
129
+ : source.filter(row => row.command.toLowerCase().includes(needle)
130
+ || row.user.toLowerCase().includes(needle)
131
+ || String(row.pid).includes(needle))
132
+ return sortRows(filtered, sortKey)
133
+ }, [result, filter, sortKey])
134
+
135
+ const kill = async (row: RemoteProcess): Promise<void> => {
136
+ const ok = await confirmDialog({
137
+ title: t('proc.killTitle'),
138
+ text: t('proc.killText')
139
+ .replace('{host}', alias)
140
+ .replace('{pid}', String(row.pid))
141
+ .replace('{command}', row.command.slice(0, 120)),
142
+ danger: true,
143
+ okText: t('proc.kill'),
144
+ cancelText: t('common.cancel'),
145
+ })
146
+ if (!ok) return
147
+ setKilling(row.pid)
148
+ try {
149
+ await api.killProcess(alias, row.pid, 'TERM')
150
+ toast(t('proc.killSent').replace('{pid}', String(row.pid)))
151
+ await load(true, false)
152
+ } catch (caught) {
153
+ toast(caught instanceof RemoteApiError ? caught.message : String(caught), true)
154
+ // TERM may be ignored (or the file may still be flushing): offer KILL as
155
+ // a second, deliberately re-confirmed action instead of escalating
156
+ // silently.
157
+ setForcePid(row.pid)
158
+ } finally {
159
+ if (alive.current) setKilling(undefined)
160
+ }
161
+ }
162
+
163
+ const forceKill = async (row: RemoteProcess): Promise<void> => {
164
+ const ok = await confirmDialog({
165
+ title: t('proc.killForceTitle'),
166
+ text: t('proc.killForceText')
167
+ .replace('{host}', alias)
168
+ .replace('{pid}', String(row.pid))
169
+ .replace('{command}', row.command.slice(0, 120)),
170
+ danger: true,
171
+ okText: t('proc.killForce'),
172
+ cancelText: t('common.cancel'),
173
+ })
174
+ if (!ok) return
175
+ setKilling(row.pid)
176
+ try {
177
+ await api.killProcess(alias, row.pid, 'KILL')
178
+ toast(t('proc.killForceSent').replace('{pid}', String(row.pid)))
179
+ setForcePid(undefined)
180
+ await load(true, false)
181
+ } catch (caught) {
182
+ toast(caught instanceof RemoteApiError ? caught.message : String(caught), true)
183
+ } finally {
184
+ if (alive.current) setKilling(undefined)
185
+ }
186
+ }
187
+
188
+ const host = props.hosts.find(item => item.alias === alias)
189
+ const toolUnknown = result !== undefined && result.tool === 'unknown'
190
+
191
+ return (
192
+ <section className={expanded ? 'rvs-proc expanded' : 'rvs-proc'} aria-label={t('proc.title')}>
193
+ <div className="rvs-proc-head">
194
+ <button
195
+ type="button"
196
+ className="rvs-proc-toggle"
197
+ aria-expanded={expanded}
198
+ onClick={() => { setExpanded(value => !value) }}
199
+ title={expanded ? t('proc.collapse') : t('proc.expand')}
200
+ >
201
+ <span aria-hidden="true">{expanded ? '▾' : '▸'}</span>
202
+ </button>
203
+ <span className="rvs-proc-title">{t('proc.title')}</span>
204
+ {props.aliases.length > 1 && (
205
+ <select
206
+ className="rvs-select rvs-proc-host"
207
+ value={alias}
208
+ onChange={(event) => { setAlias(event.target.value); setResult(undefined); setError(undefined) }}
209
+ aria-label={t('proc.host')}
210
+ >
211
+ {props.aliases.map(item => <option key={item} value={item}>{item}</option>)}
212
+ </select>
213
+ )}
214
+ {props.aliases.length === 1 && host !== undefined && (
215
+ <span className="rvs-proc-host-label">{host.alias}</span>
216
+ )}
217
+ {expanded && (
218
+ <>
219
+ <input
220
+ className="rvs-input rvs-proc-filter"
221
+ value={filter}
222
+ onChange={(event) => { setFilter(event.target.value) }}
223
+ placeholder={t('proc.filter')}
224
+ aria-label={t('proc.filter')}
225
+ />
226
+ <select
227
+ className="rvs-select rvs-proc-sort"
228
+ value={sortKey}
229
+ onChange={(event) => { setSortKey(event.target.value as SortKey) }}
230
+ aria-label={t('proc.sort')}
231
+ >
232
+ <option value="cpu">{t('proc.sortCpu')}</option>
233
+ <option value="mem">{t('proc.sortMem')}</option>
234
+ <option value="pid">{t('proc.sortPid')}</option>
235
+ </select>
236
+ <IconButton title={t('proc.refresh')} onClick={() => { void load(true, true) }} disabled={loading || alias === ''}>
237
+ {loading ? <MiniSpinner /> : <IconRefresh size={13} />}
238
+ </IconButton>
239
+ </>
240
+ )}
241
+ </div>
242
+ {!expanded && <div className="rvs-proc-collapsed">{t('proc.collapsedHint')}</div>}
243
+ {expanded && error !== undefined && <div className="rvs-banner warn rvs-proc-banner">{toolUnknown ? t('proc.cannotEnumerate') : error}</div>}
244
+ {expanded && result?.tool === 'none' && <div className="rvs-banner warn rvs-proc-banner">{t('proc.noPs')}</div>}
245
+ {expanded && result?.truncated === true && (
246
+ <div className="rvs-banner info rvs-proc-banner">{t('proc.truncated').replace('{count}', String(result.processes.length))}</div>
247
+ )}
248
+ {expanded && alias === '' && <div className="rvs-empty">{t('proc.noHost')}</div>}
249
+ {expanded && alias !== '' && rows.length === 0 && !loading && error === undefined
250
+ && result !== undefined && result.tool !== 'none' && result.tool !== 'unknown' && (
251
+ <div className="rvs-empty">{t('proc.empty')}</div>
252
+ )}
253
+ {expanded && rows.length > 0 && (
254
+ <div className="rvs-proc-table rvs-scroll" role="table" aria-label={t('proc.title')} aria-live="polite">
255
+ <div className="rvs-proc-row rvs-proc-row-head" role="row">
256
+ <span role="columnheader">PID</span>
257
+ <span role="columnheader">PPID</span>
258
+ <span role="columnheader">USER</span>
259
+ <span role="columnheader" title={t('proc.cpuHint')}>CPU</span>
260
+ <span role="columnheader">MEM</span>
261
+ <span role="columnheader">{t('proc.elapsed')}</span>
262
+ <span role="columnheader">{t('proc.command')}</span>
263
+ <span aria-hidden="true" />
264
+ </div>
265
+ {rows.map(row => (
266
+ <div className="rvs-proc-row" role="row" key={row.pid}>
267
+ <span role="cell" className="rvs-proc-pid">{row.pid}</span>
268
+ <span role="cell" className="rvs-proc-pid">{row.ppid === 0 ? '—' : row.ppid}</span>
269
+ <span role="cell" className="rvs-proc-user" title={row.user}>{row.user}</span>
270
+ <span role="cell" className="rvs-proc-num">{percent(row.cpuPercent)}</span>
271
+ <span role="cell" className="rvs-proc-num">{percent(row.memPercent)}</span>
272
+ <span role="cell" className="rvs-proc-elapsed">{formatElapsed(row.elapsedSeconds, t)}</span>
273
+ <span role="cell" className="rvs-proc-command" title={row.command}>{row.command}</span>
274
+ <span role="cell">
275
+ <button
276
+ type="button"
277
+ className={forcePid === row.pid ? 'rvs-proc-kill danger' : 'rvs-proc-kill'}
278
+ title={forcePid === row.pid ? t('proc.killForceTitle') : t('proc.killTitle')}
279
+ aria-label={`${forcePid === row.pid ? t('proc.killForceTitle') : t('proc.killTitle')} PID ${row.pid}`}
280
+ disabled={killing === row.pid}
281
+ onClick={() => { void (forcePid === row.pid ? forceKill(row) : kill(row)) }}
282
+ >
283
+ {killing === row.pid ? <MiniSpinner /> : (forcePid === row.pid ? t('proc.killForce') : t('proc.kill'))}
284
+ </button>
285
+ </span>
286
+ </div>
287
+ ))}
288
+ </div>
289
+ )}
290
+ </section>
291
+ )
292
+ }
@@ -157,6 +157,8 @@ export function RemoteDirectoryPicker(props: {
157
157
  value={draft}
158
158
  onChange={(e) => setDraft(e.target.value)}
159
159
  onKeyDown={(e) => {
160
+ // IME candidate Enter must not navigate to a half-composed path.
161
+ if (e.nativeEvent.isComposing === true || e.keyCode === 229) return
160
162
  if (e.key === 'Enter') go()
161
163
  }}
162
164
  placeholder="/home/user/project"
@@ -174,7 +176,17 @@ export function RemoteDirectoryPicker(props: {
174
176
  {entries.map((entry) => (
175
177
  <div
176
178
  key={entry.path}
179
+ // A directory row was pointer-only: keyboard users could not enter
180
+ // it at all (audit I-10). Role + tabIndex + Enter/Space make it a
181
+ // real button without changing how it looks.
182
+ role="button"
183
+ tabIndex={0}
177
184
  onClick={() => void browse(entry.path)}
185
+ onKeyDown={(e) => {
186
+ if (e.key !== 'Enter' && e.key !== ' ') return
187
+ e.preventDefault()
188
+ void browse(entry.path)
189
+ }}
178
190
  title={entry.path}
179
191
  style={{ display: 'flex', gap: 6, alignItems: 'center', padding: '3px 8px', borderRadius: 4, cursor: 'pointer', fontSize: 13 }}
180
192
  onMouseEnter={(e) => {