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,19 +6,21 @@
6
6
  * local viewer's twin — see selection-popup.ts); the payload is a fenced
7
7
  * `rel:lines` block inserted into the on-screen session's composer draft.
8
8
  */
9
- import { forwardRef, useEffect, useImperativeHandle, useRef, useState, type ReactNode } from 'react'
9
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, type ReactNode } from 'react'
10
10
  import { createPortal } from 'react-dom'
11
11
  import type { Context } from '@deepseek-ai/cordis'
12
12
  import { EditorSelection, EditorState, StateEffect, StateField, Compartment, type Extension, type Text } from '@codemirror/state'
13
- import { Decoration, EditorView, highlightActiveLine, keymap, lineNumbers, type DecorationSet } from '@codemirror/view'
13
+ import { Decoration, EditorView, drawSelection, highlightActiveLine, keymap, lineNumbers, type DecorationSet } from '@codemirror/view'
14
14
  import { history } from '@codemirror/commands'
15
15
  import { bracketMatching, ensureSyntaxTree, indentOnInput } from '@codemirror/language'
16
16
  import { closeBrackets } from '@codemirror/autocomplete'
17
- import { search } from '@codemirror/search'
17
+ import { search, selectNextOccurrence } from '@codemirror/search'
18
18
  import { syntaxHighlighting } from '@codemirror/language'
19
19
  import { vscodeHighlightStyle } from './vsc/editor-palette.ts'
20
20
  import { FindWidget, clearFindMarks, findMatchHighlight, stepFind } from './vsc/FindWidget.tsx'
21
- import { editorKeymap } from './vsc/editor-keymap.ts'
21
+ import { editorKeymap, parseGotoLine } from './vsc/editor-keymap.ts'
22
+ import { promptDialog, toast } from './vsc/kit.tsx'
23
+ import { isModalLayerOpen } from './vsc/save-shortcut.ts'
22
24
  import { javascript } from '@codemirror/lang-javascript'
23
25
  import { python } from '@codemirror/lang-python'
24
26
  import { json } from '@codemirror/lang-json'
@@ -38,6 +40,7 @@ import { diff } from '@codemirror/legacy-modes/mode/diff'
38
40
  import { buildRemoteSelectionInsert, insertReferenceOrText, type PendingReference } from './composer.ts'
39
41
  import { useSelectionPopup } from './selection-popup.ts'
40
42
  import { initialEditorTheme, watchEditorScheme } from './vsc/editor-theme.ts'
43
+ import { detectLang, makeT } from './i18n.ts'
41
44
 
42
45
  /**
43
46
  * The bits of an editor's view state that must survive an unmount.
@@ -126,6 +129,9 @@ const wrapCompartment = new Compartment()
126
129
  */
127
130
  const changeMarksCompartment = new Compartment()
128
131
 
132
+ /** Compartment holding the inline blame gutter; empty until the pane has data. */
133
+ const blameCompartment = new Compartment()
134
+
129
135
  /** True while CodeMirror's own highlighter has produced token spans. */
130
136
  function primaryColored(host: Element): boolean {
131
137
  return host.querySelector('[class*="rvs-ck-"]') !== null
@@ -145,6 +151,8 @@ import {
145
151
  type ChangeMark,
146
152
  type ChangeSet,
147
153
  } from './vsc/change-marks.ts'
154
+ import { blameExtension, blameViewportReporter } from './vsc/blame.ts'
155
+ import type { BlameLine } from './blame-model.ts'
148
156
  import { DEFAULT_UNDO_LABEL, undoAffordance } from './changes/undo-affordance.ts'
149
157
 
150
158
  /**
@@ -158,6 +166,14 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
158
166
  readOnly?: boolean
159
167
  /** Parent sub-tab visibility (views stay mounted; remeasure on show). */
160
168
  visible?: boolean
169
+ /**
170
+ * Translator for the editor's own chrome (find widget + change marks).
171
+ *
172
+ * Optional so callers that do not own the dictionary (diff panes) keep
173
+ * working: the fallback makes the same `detectLang()` choice the store does,
174
+ * so the copy matches the language of the rest of the pane.
175
+ */
176
+ t?: (key: string) => string
161
177
  /**
162
178
  * Soft wrap long lines.
163
179
  *
@@ -189,6 +205,19 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
189
205
  * 加入本功能之前完全一致。
190
206
  */
191
207
  changeSet?: ChangeSet | null
208
+ /**
209
+ * Line→commit map for the inline blame gutter. `undefined`/empty removes the
210
+ * gutter entirely, so diff panes and files without blame data keep their old
211
+ * layout.
212
+ */
213
+ blame?: ReadonlyMap<number, BlameLine> | null
214
+ /** Clicking a blame cell asks the pane to reveal that commit. */
215
+ onOpenBlame?: (entry: BlameLine) => void
216
+ /**
217
+ * Reports the visible 1-based line range. The pane uses it to fetch blame one
218
+ * window at a time; CodeMirror is the only code that knows the viewport.
219
+ */
220
+ onViewport?: (first: number, last: number) => void
192
221
  /**
193
222
  * 用户在某一处改动上按下「撤销这处改动」时回调。
194
223
  *
@@ -280,6 +309,10 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
280
309
  const dirtyRef = useRef<boolean>(false)
281
310
  const propsRef = useRef(props)
282
311
  propsRef.current = props
312
+ // Resolved once per mount: `detectLang()` is a page-level decision (the same
313
+ // one the store makes), so the identity is stable and safe in effect deps.
314
+ const fallbackT = useMemo(() => makeT(detectLang()), [])
315
+ const t = props.t ?? fallbackT
283
316
  // The CodeMirror selection listener lives for the mount's lifetime; the
284
317
  // chat target may change underneath it (session switches don't remount
285
318
  // the editor), so it reads through refs, never captured props.
@@ -373,10 +406,19 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
373
406
  */
374
407
  const armedRef = useRef('')
375
408
  const pushedSetRef = useRef<ChangeSet | null | undefined>(undefined)
409
+ /**
410
+ * `changeMarksExtension` 的 gutter/chip 文案在安装时按 `t` 解析,所以语言换了
411
+ * 要和「能力翻转」一样重装一次 compartment。
412
+ */
413
+ const labelsRef = useRef(t)
376
414
  const undoArmed = props.onUndoChange !== undefined
377
415
  useEffect(() => {
378
416
  const current = viewRef.current
379
417
  if (current === undefined) return
418
+ if (labelsRef.current !== t) {
419
+ labelsRef.current = t
420
+ armedRef.current = ''
421
+ }
380
422
  const set = props.changeSet
381
423
  const marks = set !== undefined
382
424
  const armed = `${marks ? 'm' : ''}${undoArmed ? 'u' : ''}`
@@ -385,7 +427,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
385
427
  // 重装扩展会重建字段,之前下发过的数据随之消失,必须再喂一次。
386
428
  pushedSetRef.current = undefined
387
429
  const extension: Extension = [
388
- ...(marks ? [changeMarksExtension] : []),
430
+ ...(marks ? [changeMarksExtension(t)] : []),
389
431
  ...(undoArmed
390
432
  ? [undoAffordance({
391
433
  onUndo: (mark) => { propsRef.current.onUndoChange?.(mark) },
@@ -407,7 +449,28 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
407
449
  } catch {
408
450
  // Disposed.
409
451
  }
410
- }, [props.changeSet, undoArmed, view])
452
+ }, [props.changeSet, undoArmed, view, t])
453
+
454
+ /**
455
+ * Blame gutter: install/replace it when the pane hands over a new window.
456
+ *
457
+ * The map identity changes as viewport windows land, so comparing it is the
458
+ * only cheap "same data" test; the extension itself is small and rebuilding
459
+ * it costs one compartment transaction, not a document change.
460
+ */
461
+ useEffect(() => {
462
+ const current = viewRef.current
463
+ if (current === undefined) return
464
+ const entries = props.blame
465
+ const extension = entries !== undefined && entries !== null && entries.size > 0
466
+ ? blameExtension(entries, entry => { propsRef.current.onOpenBlame?.(entry) })
467
+ : []
468
+ try {
469
+ current.dispatch({ effects: blameCompartment.reconfigure(extension) })
470
+ } catch {
471
+ // Disposed.
472
+ }
473
+ }, [props.blame])
411
474
 
412
475
  /**
413
476
  * 跳到某个改动点。
@@ -454,6 +517,14 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
454
517
  const host = hostRef.current
455
518
  if (host === null) return
456
519
  const rect = host.getBoundingClientRect()
520
+ // The surface can disappear while the widget is open (the preview swap
521
+ // hides the editor host with `display:none`). Close BEFORE positioning:
522
+ // a zero box would otherwise compute `right = innerWidth + 18` and shove
523
+ // the box out of the viewport, where Esc can no longer reach it.
524
+ if (rect.width === 0 || rect.height === 0) {
525
+ setFindOpen(false)
526
+ return
527
+ }
457
528
  const next = {
458
529
  top: Math.max(4, rect.top + 6),
459
530
  right: Math.max(8, window.innerWidth - rect.right + 18),
@@ -478,6 +549,49 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
478
549
  }
479
550
  }, [findOpen])
480
551
 
552
+ /**
553
+ * Find widget lifecycle follows the editor surface.
554
+ *
555
+ * The widget is a `document.body` portal, so it does NOT live in the editor's
556
+ * DOM tree: when the surface it belongs to goes away (a Markdown/HTML preview
557
+ * swap, a hidden pane, a surface that left the viewport entirely) the box used
558
+ * to survive on screen with its 350 ms anchor poll still running — and Esc
559
+ * only works while its input has focus, so the user had to switch back to
560
+ * source just to close it.
561
+ *
562
+ * Closing is the same state flip Esc and the ✕ use (`setFindOpen(false)`), so
563
+ * the effect above drops the match marks and clears the poll through their
564
+ * existing path. Nothing here reopens it: when the surface comes back the user
565
+ * gets Ctrl+F again, but a widget they left behind does not pop up by itself.
566
+ */
567
+ useEffect(() => {
568
+ if (!findOpen) return
569
+ // The parent's own answer for "this surface is mounted but not shown".
570
+ if (props.visible === false) {
571
+ setFindOpen(false)
572
+ return
573
+ }
574
+ const host = hostRef.current
575
+ if (host === null) return
576
+ // Geometry the parent cannot see: the preview swap puts `display:none` on
577
+ // the editor host without touching `visible`.
578
+ const rect = host.getBoundingClientRect()
579
+ if (rect.width === 0 || rect.height === 0) {
580
+ setFindOpen(false)
581
+ return
582
+ }
583
+ // Catch layout changes that emit no scroll/resize event (the preview swap,
584
+ // an ancestor collapsing). Absent in the jsdom harnesses, hence the guard.
585
+ if (typeof IntersectionObserver === 'undefined') return
586
+ const observer = new IntersectionObserver((entries) => {
587
+ if (entries.some(entry => !entry.isIntersecting)) setFindOpen(false)
588
+ })
589
+ observer.observe(host)
590
+ return () => {
591
+ observer.disconnect()
592
+ }
593
+ }, [findOpen, props.visible])
594
+
481
595
  /**
482
596
  * Note on the SCROLL report: it is wired up INSIDE the mount effect below,
483
597
  * where the view is created — not in an effect of its own. An earlier version
@@ -550,7 +664,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
550
664
  revealRange: (from, to) => {
551
665
  const current = viewRef.current
552
666
  if (current === undefined) return
553
- revealRange(current, from, to)
667
+ revealRange(current, from, to, setLitPosition)
554
668
  },
555
669
  getChangeStale: () => viewRef.current?.state.field(changeStaleField, false) === true,
556
670
  }), [])
@@ -631,8 +745,32 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
631
745
  if (host === null) return
632
746
  const extensions: Extension[] = [
633
747
  history(),
634
- keymap.of(editorKeymap({
635
- save: () => { propsRef.current.onSave() },
748
+ /**
749
+ * Multi-range selections (Ctrl/Cmd+D's repeated "select next occurrence",
750
+ * and the stock Mod-Alt-Arrow cursor commands).
751
+ *
752
+ * Required, not cosmetic: without this facet `Transaction.state` collapses
753
+ * EVERY selection to its main range (`EditorSelection.asSingle`), so
754
+ * `selectNextOccurrence` reports success while nothing visible is added —
755
+ * the shortcut would look broken. The tab view-state code already carries
756
+ * multiple ranges across a remount, so this is the same model, enabled.
757
+ */
758
+ EditorState.allowMultipleSelections.of(true),
759
+ // The facet above keeps the RANGES; `drawSelection` is what paints every
760
+ // secondary cursor and every non-main selection. Without it Ctrl+D changes
761
+ // the document on ranges the user cannot see (jsdom probes: the selection
762
+ // layer was null and one keystroke edited three ranges at once).
763
+ drawSelection(),
764
+ keymap.of(editorKeymap({
765
+ // The SAME modal gate the window-level listener applies (`save-shortcut.ts`):
766
+ // CodeMirror handles Mod-s first and prevents the default, so this callback —
767
+ // not that listener — is the one that decides while the editor has focus. A
768
+ // modal layer (host approval/settings, our confirm card, a menu) must not be
769
+ // written through; see editor-keymap's `EditorKeyHandlers.save` contract.
770
+ save: () => {
771
+ if (isModalLayerOpen()) return
772
+ propsRef.current.onSave()
773
+ },
636
774
  openFindForSelection: (view) => {
637
775
  const sel = view.state.selection.main
638
776
  if (!sel.empty) {
@@ -657,6 +795,49 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
657
795
  setFindOpen(false)
658
796
  return true
659
797
  },
798
+ /**
799
+ * Ctrl/Cmd+G: the prompt is ours (see `editor-keymap.ts`), because the
800
+ * stock `gotoLine` command renders CodeMirror's own search panel and
801
+ * this editor never mounts it. The jump reuses the same reveal helper a
802
+ * search hit uses: clamp to the document, put the caret there, light the
803
+ * landing line.
804
+ */
805
+ gotoLine: (view) => {
806
+ void (async () => {
807
+ // Named with the `T` suffix the i18n key scanner accepts: the lookup
808
+ // must stay VISIBLE to `.spike/i18n-check`, or the three keys would
809
+ // later read as "defined but unreferenced" once they are added.
810
+ const editorT = propsRef.current.t ?? fallbackT
811
+ const total = view.state.doc.lines
812
+ const current = view.state.doc.lineAt(view.state.selection.main.head).number
813
+ const answer = await promptDialog({
814
+ title: editorT('editor.gotoLine'),
815
+ text: editorT('editor.gotoLineText').replace('{total}', String(total)),
816
+ initial: String(current),
817
+ })
818
+ if (answer === undefined) return
819
+ const target = parseGotoLine(answer, total)
820
+ if (target === undefined) {
821
+ toast(editorT('editor.gotoLineInvalid'), true)
822
+ return
823
+ }
824
+ // The prompt is async: the tab may have switched (or the surface
825
+ // unmounted) while it was open, and a disposed view must not be
826
+ // dispatched into.
827
+ if (viewRef.current !== view) return
828
+ revealLine(view, target, setLitPosition)
829
+ })()
830
+ },
831
+ /**
832
+ * Ctrl/Cmd+D: `@codemirror/search`'s command, verbatim. It only moves
833
+ * selections (never the document), so it is safe in the read-only views
834
+ * the diff panes mount; its false answer is returned so the key can fall
835
+ * through instead of being swallowed (see `editor-keymap.ts`).
836
+ */
837
+ selectNextOccurrence: (view) => selectNextOccurrence({
838
+ state: view.state,
839
+ dispatch: transaction => view.dispatch(transaction),
840
+ }),
660
841
  })),
661
842
  lineNumbers(),
662
843
  highlightActiveLine(),
@@ -682,6 +863,9 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
682
863
  // Session-change marks, off until a `changeSet` prop arrives (see
683
864
  // `changeMarksCompartment`).
684
865
  changeMarksCompartment.of([]),
866
+ // Inline blame, off until the pane has fetched a window.
867
+ blameCompartment.of([]),
868
+ blameViewportReporter((first, last) => { propsRef.current.onViewport?.(first, last) }),
685
869
  wrapCompartment.of(propsRef.current.wrap === false ? [] : EditorView.lineWrapping),
686
870
  readOnlyCompartment.of(EditorState.readOnly.of(propsRef.current.readOnly === true)),
687
871
  ...langFor(propsRef.current.path),
@@ -1067,6 +1251,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
1067
1251
  <FindWidget
1068
1252
  view={view}
1069
1253
  open={findOpen}
1254
+ t={t}
1070
1255
  seed={findSeed}
1071
1256
  tick={findTick}
1072
1257
  anchor={anchor}
@@ -237,6 +237,8 @@ function LocalLeg(props: {
237
237
  value={draft}
238
238
  onChange={(e) => setDraft(e.target.value)}
239
239
  onKeyDown={(e) => {
240
+ // IME candidate Enter must not navigate to a half-composed path.
241
+ if (e.nativeEvent.isComposing === true || e.keyCode === 229) return
240
242
  if (e.key === 'Enter') go()
241
243
  }}
242
244
  disabled={blocked}
@@ -254,7 +256,19 @@ function LocalLeg(props: {
254
256
  {(listing?.entries ?? []).filter((e) => !e.hidden).map((entry) => (
255
257
  <div
256
258
  key={entry.path}
259
+ // Same fix as the standalone picker (audit I-10): Enter/Space enter
260
+ // the directory. While a browse is in flight the row is inert, so it
261
+ // is taken out of the tab order instead of silently doing nothing.
262
+ role="button"
263
+ tabIndex={blocked ? -1 : 0}
264
+ aria-disabled={blocked === true ? true : undefined}
257
265
  onClick={() => { if (!blocked) void browse(entry.path) }}
266
+ onKeyDown={(e) => {
267
+ if (blocked) return
268
+ if (e.key !== 'Enter' && e.key !== ' ') return
269
+ e.preventDefault()
270
+ void browse(entry.path)
271
+ }}
258
272
  title={entry.path}
259
273
  style={{ display: 'flex', gap: 6, alignItems: 'center', padding: '3px 8px', borderRadius: 4, cursor: blocked ? 'default' : 'pointer', fontSize: 13 }}
260
274
  onMouseEnter={(e) => {
@@ -284,6 +298,8 @@ function LocalLeg(props: {
284
298
  value={mkdirName}
285
299
  onChange={(e) => setMkdirName(e.target.value)}
286
300
  onKeyDown={(e) => {
301
+ // IME candidate Enter must not create a folder from a half-composed name.
302
+ if (e.nativeEvent.isComposing === true || e.keyCode === 229) return
287
303
  if (e.key === 'Enter') mkdir()
288
304
  }}
289
305
  placeholder={t('flow.mkdirName')}
@@ -94,6 +94,20 @@ async function copyReport(text: string): Promise<boolean> {
94
94
  }
95
95
  }
96
96
 
97
+ /**
98
+ * Focusable controls inside this layer, in DOM order.
99
+ *
100
+ * Same rule as `vsc/kit.tsx`'s `focusables`, inlined instead of imported: this
101
+ * panel deliberately does not import the kit (its copy path must not use the
102
+ * silently-failing `copyText`), and `check-doctor.mjs` pins that.
103
+ */
104
+ const FOCUSABLE = 'button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
105
+
106
+ function focusables(root: HTMLElement | null): HTMLElement[] {
107
+ if (root === null) return []
108
+ return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE))
109
+ }
110
+
97
111
  export function DoctorPanel(props: {
98
112
  t: (key: string) => string
99
113
  alias: string
@@ -103,6 +117,10 @@ export function DoctorPanel(props: {
103
117
  /** `undefined` = the probe is still running. */
104
118
  const [items, setItems] = useState<DoctorItem[] | undefined>(undefined)
105
119
  const [copyState, setCopyState] = useState<'idle' | 'copied' | 'failed'>('idle')
120
+ /** The card, so the Tab trap below has one root to walk. */
121
+ const cardRef = useRef<HTMLDivElement>(null)
122
+ /** Where focus came from (the "环境自检" button); handed back on close. */
123
+ const openerRef = useRef<HTMLElement | null>(null)
106
124
  const alive = useRef(true)
107
125
  // Re-armed on every setup: a StrictMode/replay remount runs setup → cleanup →
108
126
  // setup, and a flag that only ever got set to false would freeze the panel on
@@ -124,14 +142,59 @@ export function DoctorPanel(props: {
124
142
  run()
125
143
  }, [run])
126
144
 
145
+ /**
146
+ * The layer takes the keyboard on open and gives it back on close.
147
+ *
148
+ * The panel declared `role="dialog" aria-modal="true"` but nothing moved the
149
+ * focus into it, so Tab walked straight out into the DSH Settings form behind
150
+ * the overlay while a screen reader had been told that form is inert. It lives
151
+ * INSIDE the host Settings dialog, hence both halves: keep the keyboard here,
152
+ * and give it back to the button that opened this layer.
153
+ */
154
+ useEffect(() => {
155
+ openerRef.current = typeof document === 'undefined' ? null : (document.activeElement as HTMLElement | null)
156
+ // First paint first: the copy button is still disabled while the probe runs,
157
+ // so this settles on the close button — a safe, always-present target.
158
+ const focusTimer = window.setTimeout(() => { focusables(cardRef.current)[0]?.focus() }, 0)
159
+ return () => {
160
+ window.clearTimeout(focusTimer)
161
+ const opener = openerRef.current
162
+ if (opener !== null && document.body.contains(opener)) opener.focus()
163
+ }
164
+ }, [])
165
+
127
166
  useEffect(() => {
128
167
  const onKey = (e: KeyboardEvent): void => {
129
- if (e.key !== 'Escape') return
130
- // CAPTURE phase + stop: the panel lives inside the DSH Settings dialog,
131
- // whose own Escape handler would otherwise close the whole dialog (and the
132
- // report) together with this layer.
133
- e.stopPropagation()
134
- props.onClose()
168
+ if (e.key === 'Escape') {
169
+ // CAPTURE phase + stop: the panel lives inside the DSH Settings dialog,
170
+ // whose own Escape handler would otherwise close the whole dialog (and the
171
+ // report) together with this layer.
172
+ e.stopPropagation()
173
+ props.onClose()
174
+ return
175
+ }
176
+ if (e.key !== 'Tab') return
177
+ // Tab trap, first <-> last (same shape as the kit's ModalCard).
178
+ const controls = focusables(cardRef.current)
179
+ if (controls.length === 0) return
180
+ const first = controls[0] as HTMLElement
181
+ const last = controls[controls.length - 1] as HTMLElement
182
+ const active = document.activeElement
183
+ const inside = cardRef.current?.contains(active) === true
184
+ // Focus outside the card: a plain Tab used to walk straight into the DSH
185
+ // Settings form behind the overlay (only Shift+Tab was pulled back, so the
186
+ // trap was not a closed loop). Both directions now return to the card.
187
+ if (!inside) {
188
+ e.preventDefault()
189
+ if (e.shiftKey) last.focus()
190
+ else first.focus()
191
+ } else if (e.shiftKey && active === first) {
192
+ e.preventDefault()
193
+ last.focus()
194
+ } else if (!e.shiftKey && active === last) {
195
+ e.preventDefault()
196
+ first.focus()
197
+ }
135
198
  }
136
199
  document.addEventListener('keydown', onKey, true)
137
200
  return () => document.removeEventListener('keydown', onKey, true)
@@ -160,7 +223,7 @@ export function DoctorPanel(props: {
160
223
  aria-label={title}
161
224
  onClick={props.onClose}
162
225
  >
163
- <div className="rvs-doctor-card" onClick={(e) => e.stopPropagation()}>
226
+ <div ref={cardRef} className="rvs-doctor-card" onClick={(e) => e.stopPropagation()}>
164
227
  <div className="rvs-doctor-head">
165
228
  <span className="rvs-doctor-title">{title}</span>
166
229
  <span style={{ flex: 1 }} />