dsh-remote-vs 0.25.0 → 0.26.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 (85) hide show
  1. package/README.en.md +11 -7
  2. package/README.md +10 -7
  3. package/THIRD-PARTY-NOTICES.md +188 -0
  4. package/lib/client.js +6512 -79961
  5. package/lib/index.js +1283 -992
  6. package/lib/p2-router-fs.js +1 -1
  7. package/lib/types/client/CodeEditor.d.ts +8 -0
  8. package/lib/types/client/RemoteExplorer.d.ts +53 -0
  9. package/lib/types/client/api.d.ts +37 -2
  10. package/lib/types/client/changes/review-state.d.ts +19 -0
  11. package/lib/types/client/connection.d.ts +16 -0
  12. package/lib/types/client/request-gate.d.ts +110 -0
  13. package/lib/types/client/scm/DiffView.d.ts +45 -7
  14. package/lib/types/client/scm/actions.d.ts +31 -3
  15. package/lib/types/client/store.d.ts +53 -0
  16. package/lib/types/client/vsc/FindWidget.d.ts +6 -0
  17. package/lib/types/client/vsc/change-marks.d.ts +16 -6
  18. package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
  19. package/lib/types/client/vsc/kit.d.ts +11 -0
  20. package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
  21. package/lib/types/client/vsc/terminal-theme.d.ts +28 -2
  22. package/lib/types/forward.d.ts +12 -0
  23. package/lib/types/fs-ops.d.ts +42 -0
  24. package/lib/types/http.d.ts +2 -0
  25. package/lib/types/keygen.d.ts +9 -0
  26. package/lib/types/monitor.d.ts +8 -0
  27. package/lib/types/notices.d.ts +16 -1
  28. package/lib/types/p2/helper-rpc.d.ts +45 -0
  29. package/lib/types/routes.d.ts +2 -0
  30. package/lib/types/store.d.ts +7 -0
  31. package/lib/types/terminal.d.ts +8 -0
  32. package/lib/types/view-settings.d.ts +5 -0
  33. package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
  34. package/package.json +2 -1
  35. package/src/client/CodeEditor.tsx +151 -8
  36. package/src/client/DirectoryFlow.tsx +16 -0
  37. package/src/client/DoctorPanel.tsx +70 -7
  38. package/src/client/EditorPane.tsx +63 -14
  39. package/src/client/HostsView.tsx +12 -3
  40. package/src/client/RemoteDirectoryPicker.tsx +12 -0
  41. package/src/client/RemoteExplorer.tsx +929 -40
  42. package/src/client/RemoteRoot.tsx +147 -22
  43. package/src/client/SearchView.tsx +8 -0
  44. package/src/client/TerminalSnippets.tsx +83 -8
  45. package/src/client/api.ts +106 -13
  46. package/src/client/changes/ChangesDock.tsx +188 -6
  47. package/src/client/changes/changes.css +10 -3
  48. package/src/client/changes/review-state.ts +34 -0
  49. package/src/client/connection.ts +29 -0
  50. package/src/client/downloads.ts +49 -4
  51. package/src/client/i18n.ts +82 -8
  52. package/src/client/request-gate.ts +221 -0
  53. package/src/client/scm/CommitPane.tsx +20 -2
  54. package/src/client/scm/DiffView.tsx +343 -117
  55. package/src/client/scm/HistoryPanel.tsx +23 -2
  56. package/src/client/scm/RepoPicker.tsx +1 -1
  57. package/src/client/scm/ScmPanel.tsx +391 -87
  58. package/src/client/scm/actions.ts +95 -12
  59. package/src/client/store.tsx +372 -9
  60. package/src/client/ui.tsx +4 -0
  61. package/src/client/vsc/FindWidget.tsx +24 -9
  62. package/src/client/vsc/breadcrumb.tsx +91 -3
  63. package/src/client/vsc/change-marks.ts +93 -44
  64. package/src/client/vsc/editor-keymap.ts +59 -1
  65. package/src/client/vsc/file-icons.tsx +17 -3
  66. package/src/client/vsc/kit.tsx +26 -9
  67. package/src/client/vsc/save-shortcut.ts +47 -1
  68. package/src/client/vsc/terminal-theme.ts +44 -18
  69. package/src/client/vsc/vsc.css +411 -153
  70. package/src/forward.ts +47 -9
  71. package/src/fs-ops.ts +124 -4
  72. package/src/git-ops.ts +20 -3
  73. package/src/http.ts +35 -4
  74. package/src/keygen.ts +55 -4
  75. package/src/monitor.ts +13 -0
  76. package/src/notices.ts +23 -1
  77. package/src/p2/helper-rpc.ts +113 -7
  78. package/src/p2/worlds.ts +14 -1
  79. package/src/routes.ts +212 -43
  80. package/src/sftp.ts +51 -14
  81. package/src/store.ts +10 -0
  82. package/src/terminal.ts +73 -26
  83. package/src/view-settings.ts +50 -10
  84. package/lib/types/client/Dialog.d.ts +0 -14
  85. 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
  /**
@@ -63,6 +63,14 @@ export declare const CodeEditor: import("react").ForwardRefExoticComponent<{
63
63
  readOnly?: boolean;
64
64
  /** Parent sub-tab visibility (views stay mounted; remeasure on show). */
65
65
  visible?: boolean;
66
+ /**
67
+ * Translator for the editor's own chrome (find widget + change marks).
68
+ *
69
+ * Optional so callers that do not own the dictionary (diff panes) keep
70
+ * working: the fallback makes the same `detectLang()` choice the store does,
71
+ * so the copy matches the language of the rest of the pane.
72
+ */
73
+ t?: (key: string) => string;
66
74
  /**
67
75
  * Soft wrap long lines.
68
76
  *
@@ -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;
@@ -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
  *
@@ -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;
@@ -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
  /**
@@ -15,6 +15,25 @@ export declare class GitOpError extends Error {
15
15
  }
16
16
  /** Join a remote directory with a repo-relative path. */
17
17
  export declare function joinRemote(dir: string, rel: string): string;
18
+ /**
19
+ * Per-command options for {@link run} / {@link tryRun}.
20
+ *
21
+ * `background` puts the command on the request gate's git channel: it waits
22
+ * while a foreground request is in flight and only one such command runs at a
23
+ * time. ONLY the repository-wide READ paths use it (`probeRepoRoot`,
24
+ * `loadStatusDetail`, `loadHead`), because those are the walks a workspace
25
+ * switch starts and the ones that must never make the directory listing queue
26
+ * behind them. Every verb the user is waiting on (stage, commit, push, the
27
+ * bounded probes, the search) stays foreground and is unaffected.
28
+ *
29
+ * `signal` cancels the command: the HTTP request is aborted (and, while still
30
+ * queued, is taken out of the queue) — the store's `readGit` uses it to release
31
+ * the connections of a workspace the user just left.
32
+ */
33
+ export interface RunOptions {
34
+ background?: boolean;
35
+ signal?: AbortSignal;
36
+ }
18
37
  /** The repository that encloses a workspace directory (undefined when none). */
19
38
  export declare function resolveRepoRoot(alias: string, workspaceRoot: string): Promise<string | undefined>;
20
39
  /**
@@ -41,11 +60,11 @@ export type RepoRootProbe = {
41
60
  error: string;
42
61
  };
43
62
  /** The repository root, or WHY the probe could not answer. */
44
- export declare function probeRepoRoot(alias: string, workspaceRoot: string): Promise<RepoRootProbe>;
63
+ export declare function probeRepoRoot(alias: string, workspaceRoot: string, signal?: AbortSignal): Promise<RepoRootProbe>;
45
64
  /** Repositories under a workspace root (the workspace itself sorts first). */
46
65
  export declare function findRepos(alias: string, workspaceRoot: string): Promise<string[]>;
47
66
  /** Every changed path plus the ignored half. */
48
- export declare function loadStatusDetail(alias: string, root: string): Promise<GitStatusDetail>;
67
+ export declare function loadStatusDetail(alias: string, root: string, signal?: AbortSignal): Promise<GitStatusDetail>;
49
68
  /**
50
69
  * Pathspec-limited status probe: the raw `-z` stdout for JUST these paths.
51
70
  *
@@ -73,7 +92,7 @@ export declare function probeStatusPaths(alias: string, root: string, paths: rea
73
92
  */
74
93
  export declare function probeStatusDir(alias: string, root: string, dir: string): Promise<string>;
75
94
  /** Current branch with its ahead/behind counters (detached HEAD tolerated). */
76
- export declare function loadHead(alias: string, root: string): Promise<{
95
+ export declare function loadHead(alias: string, root: string, signal?: AbortSignal): Promise<{
77
96
  branch: string;
78
97
  detached: boolean;
79
98
  ahead: number;
@@ -143,6 +162,15 @@ export declare function loadBranches(alias: string, root: string, current: strin
143
162
  export declare function loadRemotes(alias: string, root: string): Promise<GitRemote[]>;
144
163
  /** The stash stack. */
145
164
  export declare function loadStashes(alias: string, root: string): Promise<GitStash[]>;
165
+ /**
166
+ * Initialize a repository in place (`git init`).
167
+ *
168
+ * The panel's "not a repository" state used to be a dead end (the only offer
169
+ * was "browse somewhere else") while the command builder had no caller at all.
170
+ * The caller refreshes the status afterwards — that read re-probes the
171
+ * directory, so the panel moves to the normal view without another discovery.
172
+ */
173
+ export declare function initRepo(alias: string, root: string): Promise<string>;
146
174
  /** Stage paths (additions, edits, deletions, renames). */
147
175
  export declare function stagePaths(alias: string, root: string, paths: readonly string[]): Promise<void>;
148
176
  /** Unstage paths without touching the worktree. */
@@ -328,6 +328,59 @@ export interface ExplorerValue {
328
328
  }
329
329
  /** Subscribe to the explorer store. */
330
330
  export declare function useExplorer(): ExplorerValue;
331
+ /**
332
+ * Shallow equality for selector results — one level deep, `Object.is` per field.
333
+ *
334
+ * Selectors naturally build a fresh `{ repoRoot, head, … }` object out of the
335
+ * snapshot, and a plain `Object.is` would then see a new reference on every
336
+ * publish and repaint the panel anyway (defeating the whole point). Passing this
337
+ * as `equal` compares the FIELDS, so "the snapshot was rebuilt but none of the
338
+ * fields I read changed" answers `true` and the previous value (and render) is
339
+ * kept. Arrays are compared as objects, i.e. by index.
340
+ *
341
+ * Shallow is deliberate: every selected field is either a primitive or a
342
+ * REFERENCE the store already owns (`status`, `buckets`, `tabs`, `untrackedDirs`
343
+ * …). Comparing those by reference is a real value check — the store only
344
+ * replaces them when they actually change.
345
+ */
346
+ export declare function shallowEqual(a: unknown, b: unknown): boolean;
347
+ /**
348
+ * Subscribe to ONE slice of the explorer store.
349
+ *
350
+ * Why this exists: `useExplorer()` hands out the whole `ExplorerValue`, and
351
+ * every `publish()` builds a NEW snapshot object — so every subscriber repaints
352
+ * on every mutation, including mutations its panel does not read (a save bumps
353
+ * the tab array, a git refresh replaces `status`, a rail switch changes `view`).
354
+ * With the panels kept MOUNTED, one publish therefore repainted every panel,
355
+ * and the SCM panel's change list (up to 4000 rows) was rebuilt for a change in
356
+ * an unrelated field.
357
+ *
358
+ * This hook re-renders its component ONLY when the selected value changes:
359
+ * - `publish()` still notifies every listener (that is how the store stays a
360
+ * single source of truth), but React asks this hook for a fresh value and
361
+ * `Object.is`-compares it with the last rendered one; equal means no render;
362
+ * - the selector runs at most once per (snapshot, selector) pair, and its
363
+ * result is kept in a per-hook cache, so an equal result keeps the PREVIOUS
364
+ * reference (downstream `useMemo`s keyed on it stay valid).
365
+ *
366
+ * Constraints, all from `useSyncExternalStore`:
367
+ * - the value returned for an UNCHANGED snapshot must be stable. This hook
368
+ * guarantees it (cache keyed on the snapshot identity), which is also why a
369
+ * selector may safely return a fresh object — with `shallowEqual` it is
370
+ * compared and the old reference is kept, and without `equal` it is cached
371
+ * and only recomputed when the snapshot itself changes;
372
+ * - `selector` must be PURE and should read only the snapshot. It may be an
373
+ * inline arrow (the hook tracks its identity, so a selector that closes over
374
+ * props is recomputed when it changes), but a module-level selector is
375
+ * cheaper: its identity is stable, so between publishes the cache answers
376
+ * without running it at all;
377
+ * - `selector` must not mutate the snapshot.
378
+ *
379
+ * @param selector - pure read of the fields this component needs.
380
+ * @param equal - comparison used to decide whether the new selection is the
381
+ * same value; defaults to `Object.is`. Pass `shallowEqual` for object slices.
382
+ */
383
+ export declare function useExplorerSelector<T>(selector: (snapshot: ExplorerValue) => T, equal?: (a: T, b: T) => boolean): T;
331
384
  /** The repo-relative path of an absolute remote path ('' when outside). */
332
385
  export declare function repoRelative(repoRoot: string | undefined, fullPath: string): string;
333
386
  /** Install the context and load hosts/workspaces once per page. */
@@ -59,6 +59,12 @@ export declare function stepFind(view: EditorView, forward: boolean, state?: Fin
59
59
  export declare function FindWidget(props: {
60
60
  view: EditorView | undefined;
61
61
  open: boolean;
62
+ /**
63
+ * The page's dictionary translator. Required, not defaulted: the widget has
64
+ * no language of its own, and a silent Chinese fallback is exactly the
65
+ * hardcoded copy this prop replaced.
66
+ */
67
+ t: (key: string) => string;
62
68
  /** A selection carried in by Ctrl+F (`id` bumps to re-trigger). */
63
69
  seed: {
64
70
  text: string;
@@ -22,6 +22,13 @@ import { StateField, type EditorState, type Extension } from '@codemirror/state'
22
22
  import { EditorView, ViewPlugin, type DecorationSet, type ViewUpdate } from '@codemirror/view';
23
23
  /** 改动点的三种形态。 */
24
24
  export type ChangeKind = 'add' | 'mod' | 'del';
25
+ /**
26
+ * 字典翻译函数,由调用方传入(`CodeEditor` 把页面语言解析好的那个 `t` 交下来)。
27
+ *
28
+ * 本模块自己不选语言:同样的 `t` 与同样的数据永远画出同样的 DOM,纯函数性得以
29
+ * 保持;语言变了由调用方重装扩展(`changeMarksExtension(t)`)。
30
+ */
31
+ export type Translate = (key: string) => string;
25
32
  /**
26
33
  * 新增/修改行里"真正变化的字符区间":相对所属行的列偏移,**0-based、半开区间**。
27
34
  *
@@ -145,23 +152,26 @@ export declare function changeBlockAt(state: EditorState, line: number): {
145
152
  declare class ChangeMarkHighlighter {
146
153
  decorations: DecorationSet;
147
154
  private readonly view;
148
- constructor(view: EditorView);
155
+ /** 解析标记文案的翻译函数;由 `changeMarkPlugin(t)` 装进来。 */
156
+ private readonly t;
157
+ constructor(view: EditorView, t: Translate);
149
158
  update(update: ViewUpdate): void;
150
159
  private rebuild;
151
160
  }
152
161
  /**
153
162
  * 视口内行装饰的 ViewPlugin。
154
163
  *
155
- * 导出是为了让自检脚本能直接读 `view.plugin(changeMarkPlugin).decorations.size`
156
- * —— "只装饰视口内的行"这件事在 DOM 上看不出来(CodeMirror 本来就让 DOM 只保留
157
- * 可见行),只有读这份 RangeSet 的条数才有判别力。
164
+ * 用工厂而不是模块级常量:标记与 chip 的文案由调用方的 `t` 解析。仍然导出是为了
165
+ * 让自检脚本能直接读 `view.plugin(changeMarkPlugin(t)).decorations.size` ——
166
+ * "只装饰视口内的行"这件事在 DOM 上看不出来(CodeMirror 本来就让 DOM 只保留可见
167
+ * 行),只有读这份 RangeSet 的条数才有判别力。
158
168
  */
159
- export declare const changeMarkPlugin: ViewPlugin<ChangeMarkHighlighter, undefined>;
169
+ export declare function changeMarkPlugin(t: Translate): ViewPlugin<ChangeMarkHighlighter>;
160
170
  /**
161
171
  * 编辑器侧的完整扩展:数据字段 + 作废标记 + 左侧 gutter + 行背景。
162
172
  *
163
173
  * `CodeEditor` 只在调用方真的传了 `changeSet` 时把它装进编辑器(Compartment),
164
174
  * 没传时不装 —— 这样"没有会话改动"的文件连一条 gutter 都不会多出来。
165
175
  */
166
- export declare const changeMarksExtension: Extension;
176
+ export declare function changeMarksExtension(t: Translate): Extension;
167
177
  export {};
@@ -22,7 +22,15 @@
22
22
  import type { EditorView, KeyBinding } from '@codemirror/view';
23
23
  /** The editor actions the key bindings dispatch into. */
24
24
  export interface EditorKeyHandlers {
25
- /** Ctrl/Cmd+S → the pane's save path. */
25
+ /**
26
+ * Ctrl/Cmd+S → the pane's save path.
27
+ *
28
+ * MUST be a no-op while a modal layer is open: `CodeEditor` (the only caller)
29
+ * checks `isModalLayerOpen()` before saving. The binding itself stays pure —
30
+ * this module imports no DOM — but because CodeMirror handles the key first and
31
+ * prevents the default, the window listener in `save-shortcut.ts` never gets to
32
+ * apply its own gate to this path.
33
+ */
26
34
  save(): void;
27
35
  /** Ctrl/Cmd+F → seed our find widget from the selection and open it. */
28
36
  openFindForSelection(view: EditorView): void;
@@ -32,7 +40,33 @@ export interface EditorKeyHandlers {
32
40
  stepHunk(delta: 1 | -1): boolean;
33
41
  /** Escape → close the find widget; false when it was not open. */
34
42
  closeFind(): boolean;
43
+ /**
44
+ * Ctrl/Cmd+G → ask for a line number and jump there.
45
+ *
46
+ * The prompt is the caller's (`promptDialog`), so this module stays free of
47
+ * DOM/React; the binding always claims the key (browsers use Ctrl+G for
48
+ * "find next", which has nothing to do inside a code editor).
49
+ */
50
+ gotoLine(view: EditorView): void;
51
+ /**
52
+ * Ctrl/Cmd+D → select the next occurrence of the current selection.
53
+ *
54
+ * Returns the command's own answer: `false` (nothing to expand, or a mixed
55
+ * selection) must fall through to the browser instead of being swallowed —
56
+ * the same rule the hunk bindings follow.
57
+ */
58
+ selectNextOccurrence(view: EditorView): boolean;
35
59
  }
60
+ /**
61
+ * Resolve the "go to line" answer to a 1-based line number inside `total`.
62
+ *
63
+ * Accepts what VS Code's box accepts for the LINE half: `42`, ` 42 `, `42:7`
64
+ * (the column half is ignored — this editor jumps to a line, the status bar
65
+ * reports the column). Anything else (empty, `0`, text) is `undefined`, and a
66
+ * number past the end CLAMPS to the last line instead of failing: the answer
67
+ * usually comes from a file the user is reading, not from its exact length.
68
+ */
69
+ export declare function parseGotoLine(text: string, total: number): number | undefined;
36
70
  /**
37
71
  * Build the editor keymap.
38
72
  *
@@ -182,6 +182,17 @@ export declare function toast(text: string, error?: boolean): void;
182
182
  * confirm dialog would paint twice.
183
183
  */
184
184
  export declare function DialogHost(): ReactNode;
185
+ /**
186
+ * Focusable elements inside one dialog, in DOM order.
187
+ *
188
+ * The modal is portaled to the END of `<body>`, so without a Tab trap a
189
+ * keyboard user tabs through the whole page to reach its buttons. Exported for
190
+ * the other portaled layers that need the same walk (the terminal snippet
191
+ * popover); `DoctorPanel` keeps its own copy because it deliberately does not
192
+ * import this module (its copy path must not use the silently-failing
193
+ * `copyText`, which `check-doctor.mjs` pins).
194
+ */
195
+ export declare function focusables(root: HTMLElement | null): HTMLElement[];
185
196
  export interface MenuEntry {
186
197
  label: string;
187
198
  onSelect: () => void;