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
@@ -1,4 +1,4 @@
1
- import { r as isWindowsAbsolute, x as aliasRoot } from "./worlds-B7gEDBzC.js";
1
+ import { S as aliasRoot, r as isWindowsAbsolute } from "./worlds-RG8K5eom.js";
2
2
  import { FileSystem, FsError } from "@deepseek-ai/dsh-fs";
3
3
  //#region src/p2/router-fs.ts
4
4
  /**
@@ -52,6 +52,7 @@ export interface CodeEditorHandle {
52
52
  getChangeStale: () => boolean;
53
53
  }
54
54
  import { type ChangeMark, type ChangeSet } from './vsc/change-marks.ts';
55
+ import type { BlameLine } from './blame-model.ts';
55
56
  /**
56
57
  * The editor surface is OPAQUE and scrolls in the editor's own palette
57
58
  * (`vsc/editor-theme.ts`): a code editor is not a translucent DSH panel, and
@@ -63,6 +64,14 @@ export declare const CodeEditor: import("react").ForwardRefExoticComponent<{
63
64
  readOnly?: boolean;
64
65
  /** Parent sub-tab visibility (views stay mounted; remeasure on show). */
65
66
  visible?: boolean;
67
+ /**
68
+ * Translator for the editor's own chrome (find widget + change marks).
69
+ *
70
+ * Optional so callers that do not own the dictionary (diff panes) keep
71
+ * working: the fallback makes the same `detectLang()` choice the store does,
72
+ * so the copy matches the language of the rest of the pane.
73
+ */
74
+ t?: (key: string) => string;
66
75
  /**
67
76
  * Soft wrap long lines.
68
77
  *
@@ -94,6 +103,19 @@ export declare const CodeEditor: import("react").ForwardRefExoticComponent<{
94
103
  * 加入本功能之前完全一致。
95
104
  */
96
105
  changeSet?: ChangeSet | null;
106
+ /**
107
+ * Line→commit map for the inline blame gutter. `undefined`/empty removes the
108
+ * gutter entirely, so diff panes and files without blame data keep their old
109
+ * layout.
110
+ */
111
+ blame?: ReadonlyMap<number, BlameLine> | null;
112
+ /** Clicking a blame cell asks the pane to reveal that commit. */
113
+ onOpenBlame?: (entry: BlameLine) => void;
114
+ /**
115
+ * Reports the visible 1-based line range. The pane uses it to fetch blame one
116
+ * window at a time; CodeMirror is the only code that knows the viewport.
117
+ */
118
+ onViewport?: (first: number, last: number) => void;
97
119
  /**
98
120
  * 用户在某一处改动上按下「撤销这处改动」时回调。
99
121
  *
@@ -0,0 +1,22 @@
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 { type ReactNode } from 'react';
13
+ import { type OutlineEntry } from './outline-model.ts';
14
+ export declare function OutlinePanel(props: {
15
+ t: (key: string) => string;
16
+ /** 远端绝对路径(判断语言 + 标题)。 */
17
+ path: string;
18
+ /** 实时缓冲区全文:dirty 时必须来自编辑器,不是 `tab.text`。 */
19
+ text: string;
20
+ onPick: (entry: OutlineEntry) => void;
21
+ onClose: () => void;
22
+ }): ReactNode;
@@ -0,0 +1,19 @@
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 { type ReactNode } from 'react';
10
+ import type { RemoteHostSummary } from '../protocol.ts';
11
+ export declare const PROCESS_POLL_MS = 5000;
12
+ export declare function ProcessesSection(props: {
13
+ t: (key: string) => string;
14
+ hosts: RemoteHostSummary[];
15
+ aliases: string[];
16
+ visible: boolean;
17
+ paused: boolean;
18
+ intervalMs: number;
19
+ }): ReactNode;
@@ -78,6 +78,52 @@ export declare function rekeyPaths(set: Set<string>, from: string, to: string):
78
78
  export declare function withoutListingPaths(listings: Record<string, RemoteFileEntry[]>, alias: string, removed: readonly string[]): Record<string, RemoteFileEntry[]>;
79
79
  /** Re-key cached listings after a rename/move (memo keys are `alias:path`). */
80
80
  export declare function rekeyListings(listings: Record<string, RemoteFileEntry[]>, alias: string, from: string, to: string): Record<string, RemoteFileEntry[]>;
81
+ /**
82
+ * Feed one streamed stdout chunk through a line buffer and hand out every
83
+ * COMPLETE marker line.
84
+ *
85
+ * The stream splits wherever the transport felt like it: a marker can arrive as
86
+ * `RV_DEL_`, then `OK 3\n` in the next chunk. Only complete lines are parsed,
87
+ * and the unfinished tail is returned so the next chunk can continue it; the
88
+ * caller flushes it with a final `'\n'` when the command ends.
89
+ *
90
+ * Exported because it is the one place where a cross-chunk parse bug would
91
+ * silently mis-count deletions; the local probe drives it directly.
92
+ */
93
+ export declare function drainDeleteMarkers(buffer: string, text: string, onMarker: (marker: {
94
+ kind: 'item' | 'ok' | 'fail';
95
+ index: number;
96
+ }) => void): string;
97
+ /** The half-open range of flat rows the tree paints, plus the spacers around it. */
98
+ export interface TreeWindow {
99
+ /** First painted row index into the flat row list. */
100
+ from: number;
101
+ /** One past the last painted row index. */
102
+ to: number;
103
+ /** Height of the rows above `from`, in px. */
104
+ before: number;
105
+ /** Height of the rows below `to`, in px. */
106
+ after: number;
107
+ }
108
+ /**
109
+ * Which flat rows to paint for one scroll position.
110
+ *
111
+ * Pure, so a gate or probe can pin the arithmetic without a layout engine: the
112
+ * tree is one flat pre-order list with a fixed row height, so the first visible
113
+ * row is `offset / height` and the painted count is
114
+ * `ceil(visible height / height) + overscan`. `scrollTop` is the scroller's
115
+ * offset; `headerHeight` is the block ABOVE the rows inside it (the workspace
116
+ * root label, the drop hint, `.rvs-tree`'s top padding), because the offset only
117
+ * starts indexing rows below that block.
118
+ *
119
+ * `viewportHeight <= headerHeight` means there is no room for rows at all
120
+ * (jsdom or a hidden panel): the fallback paints the whole tree while it is
121
+ * small and `TREE_WINDOW_FALLBACK` rows otherwise. The invariant
122
+ * `before + (to - from) * TREE_ROW_HEIGHT + after === total * TREE_ROW_HEIGHT`
123
+ * holds on every branch, which is what keeps the scroll range identical to the
124
+ * fully-mounted tree the window replaced.
125
+ */
126
+ export declare function computeTreeWindow(total: number, scrollTop: number, viewportHeight: number, headerHeight: number, overscan?: number): TreeWindow;
81
127
  /**
82
128
  * One rendered line of the flattened tree.
83
129
  *
@@ -179,6 +225,13 @@ export interface ExplorerRowActions {
179
225
  interface ExplorerRowProps {
180
226
  entry: RemoteFileEntry;
181
227
  depth: number;
228
+ /**
229
+ * ARIA position among the flattened visible rows. The tree is now WINDOWED, so
230
+ * the DOM sibling count is only the slice; without these two attributes a
231
+ * screen reader announces "5 of 26" for a row that is really "5005 of 20003".
232
+ */
233
+ posinset: number;
234
+ setsize: number;
182
235
  status: string | undefined;
183
236
  ignored: boolean;
184
237
  isSelected: boolean;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Typed fetch wrapper over the /api/dsh-remote JSON API (full P0 surface).
3
3
  */
4
- import { type GitBranch, type GitCommit, type GitShow, type GitStatus, type HelperAvailability, type ImportReport, type RemoteChangesDiff, type RemoteChangesSummary, type RemoteConnectionStatus, type RemoteDeployState, type RemoteExecResult, type RemoteFileEntry, type RemoteForwardRequest, type RemoteForwardState, type RemoteHostSummary, type RemoteListenPortsResult, type RemotePluginMeta, type RemoteProbe, type RemoteRead, type RemoteRoutingStatus, type RemoteTimeouts, type RemoteViewSettings, type RemoteWorkspaceBinding, type RemoteWriteConflict, type RemoteWriteResult } from '../protocol.ts';
4
+ import { type GitBranch, type GitCommit, type GitShow, type GitStatus, type HelperAvailability, type ImportReport, type RemoteChangesDiff, type RemoteChangesSummary, type RemoteConnectionStatus, type RemoteDeployState, type RemoteExecResult, type RemoteFileEntry, type RemoteForwardRequest, type RemoteForwardState, type RemoteHostSummary, type RemoteListenPortsResult, type RemoteProcessKillResult, type RemoteProcessesResult, type RemotePluginMeta, type RemoteProbe, type RemoteRead, type RemoteRoutingStatus, type RemoteTimeouts, type RemoteViewSettings, type RemoteWorkspaceBinding, type RemoteWriteConflict, type RemoteWriteResult } from '../protocol.ts';
5
5
  export declare class RemoteApiError extends Error {
6
6
  readonly status: number;
7
7
  /**
@@ -31,8 +31,38 @@ export declare class RemoteApiError extends Error {
31
31
  * happened (the Host successfully protected the file).
32
32
  */
33
33
  conflict?: RemoteWriteConflict;
34
+ /**
35
+ * The Host's own words, kept when the message was rewritten for the user.
36
+ *
37
+ * Today only the loopback fence's `403 forbidden: loopback-only` takes this
38
+ * path (see `loopbackFenceMessage`): the readable sentence explains what to do,
39
+ * while this keeps the exact server string for diagnostics and logs.
40
+ */
41
+ detail?: string;
34
42
  constructor(status: number, message: string);
35
43
  }
44
+ /**
45
+ * Per-request scheduling options (the channel lives in `request-gate.ts`).
46
+ *
47
+ * Every call site that does NOT pass them keeps the pre-gate behaviour: a
48
+ * foreground request that starts immediately and never waits.
49
+ */
50
+ export interface RequestOptions {
51
+ /**
52
+ * Run this request on the BACKGROUND channel.
53
+ *
54
+ * Only repository-wide git walks use it (see `scm/actions.ts`): they can take
55
+ * minutes on a large tree, and a workspace switch must not make the directory
56
+ * listing queue behind them for a connection. Background requests start only
57
+ * while no foreground request is in flight, one at a time.
58
+ */
59
+ background?: boolean;
60
+ /**
61
+ * Cancels the request: a queued background entry leaves the queue, and a
62
+ * request that already started is aborted at the fetch.
63
+ */
64
+ signal?: AbortSignal;
65
+ }
36
66
  /** Query for one remote terminal socket. */
37
67
  export interface TerminalSocketQuery {
38
68
  alias?: string;
@@ -130,7 +160,7 @@ export declare const api: {
130
160
  deleteHost: (alias: string) => Promise<{
131
161
  ok: boolean;
132
162
  }>;
133
- testHost: (alias: string) => Promise<{
163
+ testHost: (alias: string, opts?: RequestOptions) => Promise<{
134
164
  ok: boolean;
135
165
  error?: string;
136
166
  durationMs: number;
@@ -169,7 +199,12 @@ export declare const api: {
169
199
  ok: boolean;
170
200
  }>;
171
201
  };
172
- exec: (alias: string, command: string, timeoutMs?: number) => Promise<RemoteExecResult>;
202
+ /**
203
+ * One remote command (`/exec`), foreground unless `opts.background` asks for
204
+ * the git channel. Reads the SCM panel builds stay foreground; the
205
+ * repository-wide walks pass `{ background: true }` (see `scm/actions.ts`).
206
+ */
207
+ exec: (alias: string, command: string, timeoutMs?: number, opts?: RequestOptions) => Promise<RemoteExecResult>;
173
208
  /**
174
209
  * Streaming exec: the network verbs' live log.
175
210
  *
@@ -260,6 +295,10 @@ export declare const api: {
260
295
  * found" (see `RemoteListenPortsResult`).
261
296
  */
262
297
  listenPorts: (alias: string) => Promise<RemoteListenPortsResult>;
298
+ /** One bounded remote process table (per-host cache on the Host side). */
299
+ processes: (alias: string, refresh?: boolean) => Promise<RemoteProcessesResult>;
300
+ /** Signal one PID from the latest snapshot; the route rejects unknown PIDs. */
301
+ killProcess: (alias: string, pid: number, signal: "TERM" | "KILL") => Promise<RemoteProcessKillResult>;
263
302
  /**
264
303
  * One host's live metrics sample.
265
304
  *
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Pure parsing/formatting for `git blame` (and the shared vocabulary the
3
+ * editor UI uses for a line's provenance). No CodeMirror and no DOM here, so
4
+ * the gate can feed it real porcelain output.
5
+ */
6
+ import type { GitCommit } from '../protocol.ts';
7
+ /** One blamed line: 1-based final line number plus the commit that owns it. */
8
+ export interface BlameLine {
9
+ line: number;
10
+ hash: string;
11
+ author: string;
12
+ email: string;
13
+ /** Author timestamp, seconds since the epoch (git's `author-time`). */
14
+ time: number;
15
+ summary: string;
16
+ }
17
+ /** A run of consecutive lines owned by the same commit. */
18
+ export interface BlameRun {
19
+ from: number;
20
+ to: number;
21
+ hash: string;
22
+ }
23
+ /** One `--follow` file-history row, plus the name the file had in that commit. */
24
+ export interface FileHistoryCommit extends GitCommit {
25
+ /** Path to show/diff for THIS commit (old name before a rename). */
26
+ path: string;
27
+ /** Rename source when this commit renamed the file. */
28
+ origPath?: string;
29
+ }
30
+ /**
31
+ * Parse `git blame --line-porcelain`.
32
+ *
33
+ * `--line-porcelain` repeats the commit header and metadata for every line (no
34
+ * previous-commit grouping), which keeps this parser stateless: a header starts
35
+ * a record, the metadata lines fill it, and the tab-prefixed content line ends
36
+ * it. Lines that do not match the shape are ignored rather than aborting the
37
+ * whole read — a partially understood blame is still useful.
38
+ */
39
+ export declare function parseBlamePorcelain(stdout: string): BlameLine[];
40
+ /** Group consecutive lines of one commit; non-adjacent runs stay separate. */
41
+ export declare function blameRuns(rows: readonly BlameLine[]): BlameRun[];
42
+ /** Short author name for the narrow blame gutter. */
43
+ export declare function shortAuthor(author: string): string;
44
+ /**
45
+ * Relative age labels, deliberately compact (`now`, `5m`, `3h`, `2d`, `4w`,
46
+ * `3mo`, `2y`) because this text lives in a gutter.
47
+ */
48
+ export declare function relativeBlameTime(timeSeconds: number, nowSeconds?: number): string;
49
+ /** One-line gutter label: author initials/name plus relative age. */
50
+ export declare function blameLabel(row: BlameLine, nowSeconds?: number): string;
51
+ /**
52
+ * Hover text: full attribution. The browser renders `title` as plain text, so
53
+ * no markup is needed (and no translator dependency leaks into the model).
54
+ */
55
+ export declare function blameTitle(row: BlameLine): string;
56
+ /** False for git's all-zero "not committed yet" pseudo-commit. */
57
+ export declare function isCommittedBlame(hash: string): boolean;
58
+ /**
59
+ * The next `-L` window to request, or undefined when the viewport is covered.
60
+ *
61
+ * Pure and exported so the gate can prove the "3000-line file only asks for
62
+ * the visible window" requirement without a browser. `overscan` keeps a small
63
+ * buffer above/below so a normal scroll does not immediately need a new call.
64
+ */
65
+ export declare function planBlameWindow(first: number, last: number, total: number, covered: ReadonlySet<number>, overscan?: number): {
66
+ from: number;
67
+ to: number;
68
+ } | undefined;
69
+ /**
70
+ * Parse `git log --follow --name-status -M` output into per-commit rows.
71
+ *
72
+ * `--follow` reports the file under its name AT THAT COMMIT. Starting from the
73
+ * current name and walking newest→oldest, each rename row supplies the next
74
+ * (older) name, so a click on an old history row opens the right path instead
75
+ * of an empty diff for the current name.
76
+ */
77
+ export declare function parseFileHistory(stdout: string, currentPath: string): FileHistoryCommit[];
@@ -42,6 +42,25 @@ export declare function reviewKeyOf(file: ReviewSubject): string;
42
42
  export declare function isReviewed(file: ReviewSubject, reviewed: ReviewedMap): boolean;
43
43
  /** 已审阅的行数(只数当前列表里的,所以它永远 ≤ 列表长度)。 */
44
44
  export declare function reviewedCount(files: readonly ReviewSubject[], reviewed: ReviewedMap): number;
45
+ /**
46
+ * 从 `fromKey` 之后找第一个未审阅的行 —— 面板头部「跳到下一个未审阅」的取数。
47
+ *
48
+ * 顺序就是列表本身的顺序:从游标位置往**后**线性找,走到末尾回绕到开头,最多看
49
+ * 一圈,因此不会重复、也不会越界。跳过已审阅的行是它的职责;它本身不改任何状态,
50
+ * 也不负责打开文件(那是面板的事)。
51
+ *
52
+ * `fromKey` 缺失、或已经不在列表里(行被删了、文件又改了一次导致计数进键变化)时
53
+ * 从第一行开始:起点未知只会让这一跳从头枚举,绝不会漏掉任何一行。
54
+ *
55
+ * 返回值与入参同一行类型(`T extends ReviewSubject`),所以面板拿回的是它自己的
56
+ * `RemoteChangedFile`,不需要在调用处断言一次。
57
+ *
58
+ * @param files - 面板当前的行,数组顺序即导航顺序。
59
+ * @param reviewed - 已审阅集合(键见 {@link reviewKeyOf})。
60
+ * @param fromKey - 当前游标(`reviewKeyOf` 给出的键);空/未知表示从头开始。
61
+ * @returns 第一个未审阅的行;空列表或全部已审阅时 `undefined`。
62
+ */
63
+ export declare function nextUnreviewed<T extends ReviewSubject>(files: readonly T[], reviewed: ReviewedMap, fromKey?: string): T | undefined;
45
64
  /** 切换一行的标记,返回新表(输入不被修改)。 */
46
65
  export declare function toggleReviewed(files: readonly ReviewSubject[], reviewed: ReviewedMap, file: ReviewSubject): Record<string, 1>;
47
66
  /** 全标或全清。 */
@@ -77,6 +77,22 @@ export declare function noteConnectionFailure(alias: string, error: unknown): vo
77
77
  export declare function resetConnectionViews(): void;
78
78
  /** Record that an explicit retry just succeeded for `alias`. */
79
79
  export declare function markConnectionProbeOk(alias: string): void;
80
+ /**
81
+ * Forget the cached record of every alias the hosts table no longer holds.
82
+ *
83
+ * `views`/`probes` are module-level maps keyed by alias and nothing ever removed
84
+ * an entry: deleting or renaming a host in Settings left its view (and its
85
+ * explicit-retry probe) in page memory for the life of the tab. Callers pass the
86
+ * aliases the hosts table currently holds; everything else is stale.
87
+ *
88
+ * Only cache entries are removed — no connection state is transitioned. When the
89
+ * ACTIVE alias is pruned its snapshot becomes `undefined` ("no evidence yet",
90
+ * which every reader already treats as "not proven down") and subscribers are
91
+ * woken. `activeAlias` itself is deliberately KEPT: `setActiveConnectionAlias`
92
+ * early-returns on an unchanged alias, so clearing it here would leave a
93
+ * re-added host's chip blank until the user switched workspaces.
94
+ */
95
+ export declare function pruneConnections(aliases: Iterable<string>): void;
80
96
  /** Where the last observed state came from (see `isConnectionRecovery`). */
81
97
  export interface ConnectionTrace {
82
98
  alias: string;
@@ -11,7 +11,7 @@
11
11
  * them here keeps the check meaningful in both directions: every entry must
12
12
  * exist in both dictionaries, and nothing else may be unreferenced.
13
13
  */
14
- export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running", "downloads.indeterminate", "downloads.sizeUnknown", "downloads.handedOff", "term.disconnected", "term.closed", "term.copy", "term.paste", "term.selectAll", "connection.ok", "connection.error", "connection.idle", "connection.actionFailed", "doctor.state.ok", "doctor.state.missing", "doctor.state.unknown", "doctor.item.os", "doctor.item.libc", "doctor.item.git", "doctor.item.rg", "doctor.item.tar", "doctor.item.setsid", "doctor.item.disk", "doctor.item.nproc", "doctor.item.memory", "doctor.item.helpers", "doctor.item.sshd", "editor.crumbRoot", "editor.crumbLabel", "editor.crumbUp", "editor.crumbEmpty", "editor.imageHint", "editor.imageFitHint", "editor.imageFailedHint", "editor.imageTooLargeTitle", "editor.imageTooLargeHint"];
14
+ export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running", "downloads.indeterminate", "downloads.sizeUnknown", "downloads.handedOff", "term.disconnected", "term.closed", "term.copy", "term.paste", "term.selectAll", "connection.ok", "connection.error", "connection.idle", "connection.actionFailed", "doctor.state.ok", "doctor.state.missing", "doctor.state.unknown", "doctor.item.os", "doctor.item.libc", "doctor.item.git", "doctor.item.rg", "doctor.item.tar", "doctor.item.setsid", "doctor.item.disk", "doctor.item.nproc", "doctor.item.memory", "doctor.item.helpers", "doctor.item.sshd", "editor.crumbRoot", "editor.crumbLabel", "editor.crumbUp", "editor.crumbEmpty", "outline.kind.class", "outline.kind.interface", "outline.kind.struct", "outline.kind.enum", "outline.kind.trait", "outline.kind.impl", "outline.kind.namespace", "outline.kind.module", "outline.kind.function", "outline.kind.method", "outline.kind.constructor", "outline.kind.field", "outline.kind.variable", "outline.kind.type", "outline.kind.macro", "preview.officeUnavailableTitle", "preview.unavailableTitle", "preview.officeUnavailableHint", "preview.unavailableHint", "editor.imageHint", "editor.imageFitHint", "editor.imageFailedHint", "editor.imageTooLargeTitle", "editor.imageTooLargeHint"];
15
15
  export type Lang = 'zh' | 'en';
16
16
  export declare function detectLang(): Lang;
17
17
  export declare function makeT(lang: Lang): (key: string) => string;
@@ -0,0 +1,59 @@
1
+ export type OutlineLanguage = 'java' | 'c' | 'cpp' | 'go' | 'rust' | 'python' | 'javascript' | 'typescript' | 'unknown';
2
+ export type OutlineKind = 'class' | 'interface' | 'struct' | 'enum' | 'trait' | 'impl' | 'namespace' | 'module' | 'function' | 'method' | 'constructor' | 'field' | 'variable' | 'type' | 'macro';
3
+ export interface OutlineEntry {
4
+ name: string;
5
+ kind: OutlineKind;
6
+ /** 1-based 行号(与 `revealRange` 同一套语义)。 */
7
+ line: number;
8
+ /** 嵌套层数,0 = 顶层。用缩进表达嵌套,不暴露大括号深度。 */
9
+ depth: number;
10
+ /** 直接外层类型/命名空间的名字(没有就是顶层)。 */
11
+ container?: string;
12
+ }
13
+ export interface OutlineResult {
14
+ language: OutlineLanguage;
15
+ entries: OutlineEntry[];
16
+ /** 扫描到的符号总数;可能大于 `entries.length`(被上限截断)。 */
17
+ total: number;
18
+ truncated: boolean;
19
+ /** 语言未识别:条目是按缩进 + 关键字猜的,UI 必须标注。 */
20
+ guessed: boolean;
21
+ }
22
+ /**
23
+ * 单个文件最多列出的条目数。
24
+ *
25
+ * 20k 行的 Java 文件大约几百个符号,5000 已经远超真实代码;设上限是为了让病态
26
+ * 输入(生成代码、压缩成一行的 JSON 式脚本)不会把 DOM 拖垮,同时 `total` 仍然
27
+ * 报出真实数量,截断不撒谎。
28
+ */
29
+ export declare const OUTLINE_MAX_ENTRIES = 5000;
30
+ /** 面板一次渲染的候选上限(过滤后)。 */
31
+ export declare const OUTLINE_RESULT_LIMIT = 300;
32
+ /** 由远端路径判断语言;不认识就返回 `unknown`(走降级大纲)。 */
33
+ export declare function outlineLanguageOf(path: string): OutlineLanguage;
34
+ /**
35
+ * 把注释与字符串逐字符替换成空格(换行保留),返回按行切好的副本。
36
+ *
37
+ * 「长度不变」很重要:任何后续的行内偏移都还对得上原文件,行号也直接来自下标。
38
+ * 状态机是近似的(C++ 原始字符串、Java 文本块、JS 正则字面量不特殊处理),目标
39
+ * 是让「注释/字符串里的伪符号」不出现,不是做词法分析。
40
+ */
41
+ export declare function maskSource(text: string, language: OutlineLanguage): string[];
42
+ /**
43
+ * 从源文本生成大纲。
44
+ *
45
+ * `text` 必须是**实时缓冲区**(dirty 时不是 `tab.text`);行号 1-based 直接对应
46
+ * `CodeEditorHandle.revealRange`。
47
+ */
48
+ export declare function buildOutline(text: string, path: string): OutlineResult;
49
+ /**
50
+ * 按查询过滤并排序符号。
51
+ *
52
+ * 空查询 = 源码顺序(大纲的默认视图);有查询时复用 quick open 的 `fuzzyScore`
53
+ * 打分,同分按行号升序 —— 排序必须确定,否则两次相同的输入会闪出两种顺序。
54
+ * 名字不匹配但 `容器.名字` 匹配(用户常敲 `Foo.bar`)时也算命中。
55
+ */
56
+ export declare function rankOutline(query: string, entries: readonly OutlineEntry[], limit: number): {
57
+ hits: OutlineEntry[];
58
+ truncated: boolean;
59
+ };
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Request priority gate: a foreground request never waits, background ones yield.
3
+ *
4
+ * The symptom this exists for: switching the remote workspace made the tree
5
+ * crawl. The switch starts a full `git status` walk of the new repository
6
+ * (minutes on an AOSP monorepo) while the tree itself needs a handful of small
7
+ * foreground reads. A browser gives ONE origin six connections, so the walk —
8
+ * probe + status + branch header, three at once — filled the pool and the
9
+ * directory listing queued behind it. Measured on the reported trees: the git
10
+ * walk took 8–9 s (1.6–1.9 s with `-uno`), and during that window a purely
11
+ * in-memory Host route (`/status`, normally < 1 ms) answered in 2.7–4.6 s. The
12
+ * directory list itself was 175–180 ms; the rest was queueing.
13
+ *
14
+ * The contract is one sentence per direction:
15
+ *
16
+ * - FOREGROUND — every request somebody is waiting on (directory list, file
17
+ * read/write, session cwd, connection status, terminal exec): it never waits
18
+ * for a background slot. It only bumps a counter, so a background request that
19
+ * is already running cannot hold it up (that one still owns a TCP connection,
20
+ * which is what `maxBackground` and the abort in `store.readGit` are for).
21
+ * - BACKGROUND — repository-wide git walks: started only while NO foreground
22
+ * request is in flight and fewer than `maxBackground` background requests run.
23
+ * Otherwise queued (FIFO). `maxBackground: 1` is deliberate: the walk's own
24
+ * steps (probe, status, branch header) are work on ONE repository, and letting
25
+ * three of them hold three connections is exactly the pool exhaustion this
26
+ * gate exists to prevent.
27
+ *
28
+ * Aborting: a queued entry leaves the queue and rejects with `AbortError`. A
29
+ * request that already STARTED cannot be un-sent — its slot is released the
30
+ * moment its signal aborts (a cancelled fetch frees its connection right away,
31
+ * and the channel must not depend on the transport noticing), while the outcome
32
+ * of the underlying promise stays the transport's business: a real `fetch`
33
+ * rejects with `AbortError`, which is what the store sees. A signal that is
34
+ * ALREADY aborted when the request is handed over is passed to the transport
35
+ * unchanged — `fetch` refuses it at once, and deciding that here would swallow
36
+ * a step of a read that chose to keep going.
37
+ *
38
+ * Kept dependency-free (no store, no React, no fetch) on purpose: a node gate
39
+ * imports this class and proves the ordering with its own deferreds, and the
40
+ * store/api wiring is a one-liner at each call site.
41
+ */
42
+ /** What `pending()` reports: counts only, never the queued closures. */
43
+ export interface RequestGatePending {
44
+ /** Foreground requests in flight. */
45
+ foreground: number;
46
+ /** Background requests in flight. */
47
+ background: number;
48
+ /** Background requests waiting for a slot. */
49
+ queued: number;
50
+ }
51
+ /**
52
+ * The cancellation error a queued background request rejects with when its
53
+ * signal aborts (`AbortError`, the same name `fetch` uses for its own aborts).
54
+ */
55
+ export declare function requestAbortError(): Error;
56
+ /**
57
+ * True when `error` is an abort, not a failure.
58
+ *
59
+ * Callers that cancelled a request on purpose (a workspace switch) must not
60
+ * report it: "the read you superseded was cancelled" is not an error the user
61
+ * can act on.
62
+ */
63
+ export declare function isRequestAbort(error: unknown): boolean;
64
+ /**
65
+ * The gate itself.
66
+ *
67
+ * One instance per page is enough and is what `api.ts` uses; the class is
68
+ * exported so a gate can drive several independent instances with its own
69
+ * timings instead of sharing module state.
70
+ */
71
+ export declare class RequestGate {
72
+ private readonly maxBackground;
73
+ /** Foreground requests in flight. */
74
+ private foregroundCount;
75
+ /** Background requests in flight (a slot is held until it settles or aborts). */
76
+ private backgroundCount;
77
+ /** Background requests waiting for a slot, in arrival order (FIFO). */
78
+ private readonly queued;
79
+ /**
80
+ * @param maxBackground - how many background requests may run at once.
81
+ * `1` is the client's choice; see the module comment.
82
+ */
83
+ constructor(maxBackground?: number);
84
+ /** Run one foreground request. It never waits for a background slot. */
85
+ runForeground<T>(fn: () => Promise<T>): Promise<T>;
86
+ /**
87
+ * Run one background request, waiting for a slot.
88
+ *
89
+ * @param signal - a QUEUED request leaves the queue and rejects with
90
+ * `AbortError`; a request that already started releases its slot at once
91
+ * (its own `fetch` gets the same signal, so the transport is cancelled too).
92
+ * An already-aborted signal is handed to the transport, which refuses it.
93
+ */
94
+ runBackground<T>(fn: () => Promise<T>, signal?: AbortSignal): Promise<T>;
95
+ /** Snapshot of the counts (gates assert ordering with this). */
96
+ pending(): RequestGatePending;
97
+ /**
98
+ * Start as many queued background requests as the rule allows.
99
+ *
100
+ * Called when a foreground request finishes, when a background one settles and
101
+ * when a running one's signal aborts. A background request that is RUNNING is
102
+ * never recalled (a fetch cannot be un-sent), so a foreground request arriving
103
+ * mid-walk simply runs alongside it until it settles.
104
+ */
105
+ private pump;
106
+ }
107
+ /** The one gate the client uses (see `api.call`). */
108
+ export declare const requestGate: RequestGate;
109
+ /** Snapshot of {@link requestGate} — for gates that assert the wiring. */
110
+ export declare function pending(): RequestGatePending;
@@ -8,16 +8,54 @@
8
8
  * already-staged diff can only be un-staged. 变更后 switches to a real
9
9
  * CodeMirror buffer so the file can be edited in place.
10
10
  *
11
- * The row count is the WHOLE file, so the split mode is windowed (see
12
- * `useRowWindow`): before that, a 3000-line file put 9000 line containers and
13
- * ~2N tokenized lines in the DOM at once, and every store publish rebuilt all
14
- * of them. Note which element scrolls: the two panes only own their HORIZONTAL
15
- * scroll (`.rvs-diff-col`), while vertical scrolling belongs to `.rvs-diff-grid`
16
- * outside them — so ONE window serves all three columns and no column can
17
- * drift out of lockstep with another.
11
+ * The row count is the WHOLE file, so every pane is windowed (see
12
+ * `useScrollWindow`): before that, a 3000-line file put 9000 line containers and
13
+ * ~2N tokenized lines in the DOM at once, and every store publish rebuilt all of
14
+ * them — the "变更前 / 变更后" panes mounted every line of one side as well. In
15
+ * the split mode note which element scrolls: the two panes only own their
16
+ * HORIZONTAL scroll (`.rvs-diff-col`), while vertical scrolling belongs to
17
+ * `.rvs-diff-grid` outside them — so ONE window serves all three columns and no
18
+ * column can drift out of lockstep with another. The whole-file panes scroll
19
+ * their own `.rvs-code` box and take the same window from the same hook.
18
20
  */
19
21
  import { type ReactNode } from 'react';
20
22
  import type { EditorTab } from '../store.tsx';
23
+ /** The half-open line range a windowed pane paints, plus what it leaves blank. */
24
+ export interface LineWindow {
25
+ /** First rendered line index. */
26
+ from: number;
27
+ /** One past the last rendered line index. */
28
+ to: number;
29
+ /** Height of the lines above `from`, in px. */
30
+ before: number;
31
+ /** Height of the lines below `to`, in px. */
32
+ after: number;
33
+ }
34
+ /**
35
+ * The lines to paint for one scroll offset — arithmetic, not measurement,
36
+ * because every windowed row is a hard `ROW_HEIGHT`.
37
+ *
38
+ * `total` is the number of lines the FULL pane would have rendered, which is
39
+ * what the scroll range has to cover: `before + painted + after` is exactly
40
+ * `total * ROW_HEIGHT`, so the scrollbar behaves as it did when every line was
41
+ * mounted.
42
+ *
43
+ * `offset` is the scroller's own top padding (`CODE_PAD_TOP` on `.rvs-code`, 0
44
+ * on `.rvs-diff-grid`).
45
+ *
46
+ * The offset is clamped to the LAST line, not merely guarded against negatives:
47
+ * a reload can replace a 3000-line side with a 40-line one while the browser
48
+ * still holds the old offset (it re-clamps the scroller only once the new
49
+ * spacer height is in the DOM). An unclamped slice would ask for lines that no
50
+ * longer exist, `from` would exceed the text, and the two spacers would then add
51
+ * up to less than the file — the bottom of the new text would be unreachable.
52
+ * Clamping keeps `before + painted + after` exactly equal to
53
+ * `total * ROW_HEIGHT`, which is what the scroller's range was before this
54
+ * window existed.
55
+ *
56
+ * Pure and exported so a probe can pin the boundaries without a browser.
57
+ */
58
+ export declare function computeLineWindow(total: number, scrollTop: number, height: number, offset?: number, overscan?: number): LineWindow;
21
59
  /** Why one hunk action (stage / unstage / revert) cannot run for this tab. */
22
60
  export type HunkBlockReason = 'offline' | 'truncated';
23
61
  /**