dsh-remote-vs 0.13.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.en.md +455 -443
  2. package/README.md +408 -396
  3. package/lib/client.js +8062 -2651
  4. package/lib/index.js +1058 -288
  5. package/lib/p2-router-fs.js +1 -1
  6. package/lib/p2-router-refs.js +89 -10
  7. package/lib/p2-router-spill.js +73 -1
  8. package/lib/p2-router-subprocess.js +18 -6
  9. package/lib/spill-retention-BwKEWrl5.js +115 -0
  10. package/lib/{ssh-proc-arI5lm4W.js → ssh-proc-VKWn_LZC.js} +17 -0
  11. package/lib/types/archive.d.ts +1 -1
  12. package/lib/types/changes/recorder.d.ts +34 -2
  13. package/lib/types/client/CodeEditor.d.ts +12 -0
  14. package/lib/types/client/ConnectionStatus.d.ts +17 -0
  15. package/lib/types/client/DirectoryFlow.d.ts +2 -0
  16. package/lib/types/client/DoctorPanel.d.ts +25 -0
  17. package/lib/types/client/QuickOpen.d.ts +17 -0
  18. package/lib/types/client/RemoteExplorer.d.ts +192 -1
  19. package/lib/types/client/RemoteRoot.d.ts +17 -0
  20. package/lib/types/client/SearchView.d.ts +55 -0
  21. package/lib/types/client/TerminalView.d.ts +38 -0
  22. package/lib/types/client/WorkspaceWizard.d.ts +17 -0
  23. package/lib/types/client/api.d.ts +54 -4
  24. package/lib/types/client/changes/undo-affordance.d.ts +16 -0
  25. package/lib/types/client/changes/undo-context.d.ts +14 -18
  26. package/lib/types/client/changes/undo-target.d.ts +78 -0
  27. package/lib/types/client/connection.d.ts +111 -0
  28. package/lib/types/client/doctor.d.ts +122 -0
  29. package/lib/types/client/download.d.ts +35 -5
  30. package/lib/types/client/downloads.d.ts +18 -1
  31. package/lib/types/client/file-open-probe.d.ts +64 -0
  32. package/lib/types/client/i18n.d.ts +1 -1
  33. package/lib/types/client/quickopen-model.d.ts +332 -0
  34. package/lib/types/client/scm/DiffView.d.ts +34 -0
  35. package/lib/types/client/scm/actions.d.ts +18 -0
  36. package/lib/types/client/scm/diff-model.d.ts +17 -1
  37. package/lib/types/client/scm/git-cache.d.ts +10 -2
  38. package/lib/types/client/scm/read-queue.d.ts +2 -1
  39. package/lib/types/client/scm/stage-queue.d.ts +13 -0
  40. package/lib/types/client/scm/status-map.d.ts +3 -1
  41. package/lib/types/client/store.d.ts +114 -5
  42. package/lib/types/client/vsc/FindWidget.d.ts +7 -0
  43. package/lib/types/client/vsc/save-shortcut.d.ts +57 -0
  44. package/lib/types/deploy.d.ts +44 -2
  45. package/lib/types/git-format.d.ts +15 -0
  46. package/lib/types/http.d.ts +44 -0
  47. package/lib/types/p2/file-refs.d.ts +39 -2
  48. package/lib/types/p2/helper-rpc.d.ts +26 -0
  49. package/lib/types/p2/router-spill.d.ts +19 -0
  50. package/lib/types/p2/router-subprocess.d.ts +2 -0
  51. package/lib/types/p2/spill-retention.d.ts +74 -0
  52. package/lib/types/p2/worlds.d.ts +11 -0
  53. package/lib/types/pool.d.ts +73 -11
  54. package/lib/types/protocol.d.ts +63 -0
  55. package/lib/types/routes.d.ts +18 -0
  56. package/lib/types/sftp.d.ts +114 -8
  57. package/lib/types/store.d.ts +34 -0
  58. package/lib/types/timeouts.d.ts +14 -0
  59. package/lib/{worlds-C6Xha1mQ.js → worlds-Be1YE2Ot.js} +727 -78
  60. package/package.json +1 -1
  61. package/src/archive.ts +41 -9
  62. package/src/changes/recorder.ts +227 -31
  63. package/src/changes/status.ts +37 -1
  64. package/src/client/CodeEditor.tsx +84 -2
  65. package/src/client/ConnectionStatus.tsx +130 -0
  66. package/src/client/DirectoryFlow.tsx +40 -5
  67. package/src/client/DoctorPanel.tsx +202 -0
  68. package/src/client/DownloadDock.tsx +13 -25
  69. package/src/client/EditorPane.tsx +291 -7
  70. package/src/client/HostsView.tsx +17 -8
  71. package/src/client/QuickOpen.tsx +371 -0
  72. package/src/client/RemoteDirectoryPicker.tsx +54 -3
  73. package/src/client/RemoteExplorer.tsx +879 -160
  74. package/src/client/RemoteRoot.tsx +178 -1
  75. package/src/client/SearchView.tsx +180 -6
  76. package/src/client/SettingsHosts.tsx +1 -1
  77. package/src/client/TerminalView.tsx +174 -9
  78. package/src/client/WorkspaceWizard.tsx +110 -16
  79. package/src/client/WorkspacesView.tsx +22 -6
  80. package/src/client/api.ts +197 -11
  81. package/src/client/changes/ChangesDock.tsx +35 -8
  82. package/src/client/changes/undo-affordance.ts +33 -0
  83. package/src/client/changes/undo-context.ts +14 -18
  84. package/src/client/changes/undo-target.ts +139 -0
  85. package/src/client/connection.ts +264 -0
  86. package/src/client/doctor.ts +441 -0
  87. package/src/client/download.ts +148 -12
  88. package/src/client/downloads.ts +43 -2
  89. package/src/client/file-open-probe.ts +83 -0
  90. package/src/client/i18n.ts +244 -0
  91. package/src/client/index.tsx +5 -2
  92. package/src/client/quickopen-model.ts +778 -0
  93. package/src/client/remote-file-open.ts +21 -33
  94. package/src/client/scm/DiffView.tsx +116 -6
  95. package/src/client/scm/ScmPanel.tsx +19 -0
  96. package/src/client/scm/actions.ts +34 -2
  97. package/src/client/scm/diff-model.ts +33 -37
  98. package/src/client/scm/git-cache.ts +61 -4
  99. package/src/client/scm/read-queue.ts +33 -2
  100. package/src/client/scm/stage-queue.ts +72 -1
  101. package/src/client/scm/status-map.ts +22 -1
  102. package/src/client/store.tsx +704 -21
  103. package/src/client/vsc/FindWidget.tsx +20 -0
  104. package/src/client/vsc/kit.tsx +115 -6
  105. package/src/client/vsc/reveal-line.ts +33 -14
  106. package/src/client/vsc/save-shortcut.ts +131 -0
  107. package/src/client/vsc/vsc.css +419 -0
  108. package/src/deploy.ts +185 -33
  109. package/src/git-format.ts +136 -22
  110. package/src/git-ops.ts +14 -6
  111. package/src/http.ts +80 -12
  112. package/src/importers.ts +80 -21
  113. package/src/index.ts +21 -1
  114. package/src/p2/file-refs.ts +112 -10
  115. package/src/p2/helper-rpc.ts +73 -36
  116. package/src/p2/router-spill.ts +96 -1
  117. package/src/p2/router-subprocess.ts +18 -5
  118. package/src/p2/spill-retention.ts +134 -0
  119. package/src/p2/ssh-proc.ts +22 -0
  120. package/src/p2/worlds.ts +24 -0
  121. package/src/pool.ts +329 -47
  122. package/src/protocol.ts +66 -0
  123. package/src/routes.ts +251 -43
  124. package/src/sftp.ts +486 -26
  125. package/src/store.ts +207 -85
  126. package/src/terminal.ts +38 -2
  127. package/src/timeouts.ts +14 -0
  128. package/src/tools.ts +14 -5
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Ctrl+P quick open: the remote file index and its fuzzy matcher.
3
+ *
4
+ * Pure logic on purpose (no React, no store, no `api` import): the pixels live
5
+ * in `QuickOpen.tsx`, and everything that has to be provable in Node lives
6
+ * here — scoring, ranking, the index lifecycle, the remote command and its
7
+ * parser. The only I/O this module performs is the injected `exec`, so a gate
8
+ * can drive it with a stub and never touch a real host.
9
+ *
10
+ * The incident-index rules that shape every decision below:
11
+ *
12
+ * - **A failed listing is not an empty listing.** {@link buildFileIndex}
13
+ * REJECTS a run that did not produce a trustworthy listing: a timed-out or
14
+ * transport-broken command, a command that never entered the workspace root,
15
+ * and a listing TOOL that exited non-zero without listing anything. Returning
16
+ * `[]` there would make "the host failed" look exactly like "this tree has no
17
+ * files".
18
+ * - **A capped listing is a bounded PREFIX, never a complete index.** THREE
19
+ * separate caps are enforced on the remote and reported as three separate
20
+ * facts: entries, bytes, and the walk depth of the no-ripgrep fallback. A
21
+ * listing that was cut anywhere says so in the result; nothing is silently
22
+ * dropped and called complete. A tool that listed SOME files and then exited
23
+ * non-zero is a fourth, separate fact (`toolStatus`) — its prefix is still
24
+ * useful, so it is kept but marked incomplete instead of being thrown away.
25
+ * - **A late answer must not overwrite a newer screen.** The index records which
26
+ * workspace it is for; a result (or failure) that lands after the user
27
+ * switched workspaces is discarded, because its relative paths would be
28
+ * resolved against the wrong root (see {@link applyIndexResult}).
29
+ *
30
+ * Privacy: the index is memory-only. Nothing here stores file content, and
31
+ * nothing is written to IndexedDB. The single persisted item is the recent-file
32
+ * list — absolute paths only — under a `dsh-remote-vs.` key, the same
33
+ * trade-off the panel-layout prefs already make.
34
+ */
35
+ /** Cap on one listing's entries; precedent: `src/p2/file-refs.ts` (same 50k). */
36
+ export declare const QUICKOPEN_MAX_ENTRIES = 50000;
37
+ /**
38
+ * Byte ceiling for one listing.
39
+ *
40
+ * Deliberately BELOW the Host's per-stream exec cap (2 MiB, `src/pool.ts`):
41
+ * when the transport truncates it appends its own marker line, which would
42
+ * arrive as a half-written path and be indistinguishable from a real one.
43
+ * Staying under it means every truncation is OURS and is reported as one.
44
+ */
45
+ export declare const QUICKOPEN_MAX_BYTES = 1200000;
46
+ /**
47
+ * One listing command's budget. A cold `find` walk over a very large tree is
48
+ * the slow path (a few seconds with `rg`, minutes without it), and giving up
49
+ * too early turns "slow host" into "broken index".
50
+ */
51
+ export declare const QUICKOPEN_INDEX_TIMEOUT_MS = 120000;
52
+ /** Rows rendered in the result list. */
53
+ export declare const QUICKOPEN_RESULT_LIMIT = 50;
54
+ /** Recent files remembered per host — paths only, never content. */
55
+ export declare const QUICKOPEN_RECENT_LIMIT = 20;
56
+ /** localStorage key: `{ [alias]: string[] }`. Prefix kept for the panel's own data. */
57
+ export declare const QUICKOPEN_RECENT_KEY = "dsh-remote-vs.recentFiles";
58
+ /**
59
+ * How deep the `find` fallback walks. `rg --files` has no depth limit and is
60
+ * the preferred path; this only bounds the no-ripgrep case, where an uncapped
61
+ * walk on a multi-million-file tree never finishes. 40 is far past any sane
62
+ * source layout (the name search needed 12 to see a deep file, and its cap was
63
+ * raised for exactly that reason).
64
+ *
65
+ * The bound is DECLARED in the listing stream ({@link DEPTH_CAP_PREFIX}), so an
66
+ * index built without ripgrep is never presented as complete.
67
+ */
68
+ export declare const QUICKOPEN_FALLBACK_MAX_DEPTH = 40;
69
+ /**
70
+ * Score one path against one query, or `undefined` when it does not match.
71
+ *
72
+ * Greedy left-to-right subsequence matching (not optimal alignment): it is what
73
+ * every editor's quick open does, it is O(path length), and — most importantly
74
+ * here — it is DETERMINISTIC, so equal scores can be tie-broken by path and the
75
+ * list never reshuffles between identical inputs.
76
+ *
77
+ * Weighting, in the order it matters for a filename jump list:
78
+ * - each matched character scores 1;
79
+ * - a run of consecutive characters beats the same characters spread out;
80
+ * - a match inside the LAST path segment (the file name) scores higher than one
81
+ * inside directories — the query is almost always "the name I remember";
82
+ * - a match at a word boundary (`/`, `_`, `-`, `.`, camel hump) beats one in the
83
+ * middle of a word.
84
+ *
85
+ * Case-insensitive in both directions; an empty query scores 0 (it matches
86
+ * everything, which is how "recent files" reuses this path).
87
+ */
88
+ export declare function fuzzyScore(query: string, path: string): number | undefined;
89
+ /**
90
+ * Rank `paths` for one query.
91
+ *
92
+ * - Empty query: the caller's ORDER is the answer (that is what makes "recent
93
+ * files first" work without a second code path); the list is merely capped.
94
+ * - Otherwise: score descending, then path ascending. The path tie-break is not
95
+ * cosmetic — without it, equal-scoring matches would come out in whatever
96
+ * order the (remote-driven) input happened to have, and the list would jump
97
+ * around between two identical keystrokes.
98
+ *
99
+ * `truncated` here means "more matches than fit", which is a different fact
100
+ * from the index being truncated ({@link FileIndex.truncated}) — both are
101
+ * reported, and neither is swallowed.
102
+ */
103
+ export declare function rankFiles(query: string, paths: readonly string[], limit: number): {
104
+ hits: string[];
105
+ truncated: boolean;
106
+ };
107
+ /**
108
+ * Character offsets matched by `query` inside `text`, for highlighting.
109
+ *
110
+ * Only a match that fits ENTIRELY inside the file name produces offsets: a hit
111
+ * whose characters are split between a directory and the name would otherwise
112
+ * highlight a misleading subset of the name. Returns `[]` when the query does
113
+ * not fully match, so the caller can render the name plain.
114
+ */
115
+ export declare function matchPositions(query: string, text: string): number[];
116
+ /** Split a relative path into its directory part (trailing slash kept) and name. */
117
+ export declare function splitPath(path: string): {
118
+ dir: string;
119
+ name: string;
120
+ };
121
+ /** Absolute remote path for a workspace-relative one. */
122
+ export declare function absoluteFromRoot(root: string, relative: string): string;
123
+ /**
124
+ * Workspace-relative form of an absolute path, or `undefined` when it is not
125
+ * inside this workspace.
126
+ *
127
+ * Used for the recent list: an entry from ANOTHER workspace must not be shown
128
+ * as if it were reachable here — opening it would act on a path whose binding
129
+ * the user is no longer looking at (the "opened in the wrong host" class of
130
+ * incident).
131
+ */
132
+ export declare function relativeToRoot(root: string, absolute: string): string | undefined;
133
+ /** Render one thrown value as a readable reason. */
134
+ export declare function errorText(error: unknown): string;
135
+ /** Recently opened absolute paths for one host, newest first. */
136
+ export declare function loadRecentFiles(alias: string): string[];
137
+ /**
138
+ * Record one opened file and return the new list.
139
+ *
140
+ * Paths only — this is the one thing quick open persists, so the promise in the
141
+ * README ("remote source never lands on this device") stays literally true:
142
+ * what is stored is a location, not content.
143
+ */
144
+ export declare function rememberRecentFile(alias: string, absolutePath: string): string[];
145
+ export type IndexPhase = 'idle' | 'loading' | 'ready' | 'error';
146
+ /** One built listing. Immutable; replaced wholesale, never mutated in place. */
147
+ export interface FileIndex {
148
+ alias: string;
149
+ root: string;
150
+ /** Remote-write counter observed when the listing was requested. */
151
+ writeSeq: number;
152
+ /** Workspace-relative paths, sorted (deterministic order for equal scores). */
153
+ paths: readonly string[];
154
+ /** This is a bounded PREFIX in the entry/byte dimension: more files exist. */
155
+ truncated: boolean;
156
+ /**
157
+ * The no-ripgrep fallback only walked this deep, so deeper files may be
158
+ * missing. `undefined` means the listing had no depth bound (ripgrep).
159
+ */
160
+ depthCapped: number | undefined;
161
+ /**
162
+ * Exit status of the listing tool when it complained. The prefix is kept (a
163
+ * partial list is still useful) but it is NOT a complete index.
164
+ */
165
+ toolStatus: number | undefined;
166
+ /** Human-readable reasons the index is incomplete (tool status, stderr). */
167
+ warning: string | undefined;
168
+ }
169
+ /** Which workspace an index state is about. */
170
+ export interface IndexTarget {
171
+ alias: string;
172
+ root: string;
173
+ }
174
+ export interface IndexState {
175
+ phase: IndexPhase;
176
+ /**
177
+ * The workspace this state belongs to — for `loading`, the build in flight.
178
+ *
179
+ * Carried explicitly because "loading" alone was a lie: a build for workspace
180
+ * A that was still in flight when the user switched to B made
181
+ * `indexNeedsRebuild` answer "nothing to do" for B, and A's listing then
182
+ * landed as if it were B's — Enter would join B's root with A's relative
183
+ * paths (a file that is not there, or, worse, a same-named one that is not
184
+ * what the list showed).
185
+ */
186
+ target: IndexTarget | undefined;
187
+ index: FileIndex | undefined;
188
+ error: string | undefined;
189
+ }
190
+ export declare function createIndexState(): IndexState;
191
+ /** Cache identity: an index is only valid for the alias + root it came from. */
192
+ export declare function indexTargetKey(alias: string, root: string): string;
193
+ /** Is `left` the same workspace as `right`? A trailing slash is not another tree. */
194
+ export declare function isSameIndexTarget(left: IndexTarget | undefined, right: IndexTarget): boolean;
195
+ /**
196
+ * Does the cached state still answer for this target?
197
+ *
198
+ * Three independent invalidations, all cheap:
199
+ * - this state is about a DIFFERENT workspace — including a build still in
200
+ * flight for one. Switching is a rebuild, and the foreign answer is dropped
201
+ * when it arrives (see {@link applyIndexResult});
202
+ * - no index yet, or the last attempt FAILED (a transient failure deserves a
203
+ * retry on the next open, and an error state must never be reused as if it
204
+ * were a complete answer);
205
+ * - a remote WRITE happened since the build (see `api.ts`), which is exactly
206
+ * when the path set can change.
207
+ */
208
+ export declare function indexNeedsRebuild(state: IndexState, alias: string, root: string, writeSeq: number): boolean;
209
+ /**
210
+ * Enter the loading phase for `alias` + `root`.
211
+ *
212
+ * An index for the SAME target is kept while it is being replaced, so the list
213
+ * keeps answering (from a snapshot that may be one write old) instead of
214
+ * blanking on every reopen. A different target's index is dropped: its paths
215
+ * are wrong for the new workspace.
216
+ */
217
+ export declare function beginIndexBuild(state: IndexState, alias: string, root: string): IndexState;
218
+ /**
219
+ * Publish one finished build — but only for the workspace that is current NOW.
220
+ *
221
+ * A build can outlive its workspace: 50k paths over a thin link takes seconds,
222
+ * and switching while it runs is normal use. Publishing that answer would put
223
+ * workspace A's relative paths in front of workspace B, so a foreign result is
224
+ * DISCARDED: whatever state is current stays exactly as it is (the current
225
+ * workspace's own build, or its error).
226
+ */
227
+ export declare function applyIndexResult(state: IndexState, index: FileIndex): IndexState;
228
+ /**
229
+ * Record a FAILED build for `target`, with the same foreign-result guard.
230
+ *
231
+ * `phase` stays `error` — never `ready` with zero paths. That distinction is the
232
+ * whole point: the modal prints the reason and does not claim "no matching
233
+ * file". Any previously built index for the same target is preserved so the
234
+ * list keeps showing something usable while the reason sits in the footer.
235
+ */
236
+ export declare function applyIndexFailure(state: IndexState, reason: string, target: IndexTarget): IndexState;
237
+ /**
238
+ * An immediately-known LOCAL failure (nothing remote ran, so there is no target
239
+ * to guard and no build to drop): e.g. no workspace is selected.
240
+ */
241
+ export declare function failIndexNow(reason: string): IndexState;
242
+ export declare function quickOpenIndexState(): IndexState;
243
+ /** Subscribe to cache changes (the modal's view of the index). */
244
+ export declare function subscribeQuickOpenIndex(listener: () => void): () => void;
245
+ /** Replace the cached state and notify every subscriber. */
246
+ export declare function replaceQuickOpenIndexState(next: IndexState): void;
247
+ /** The slice of one remote command result this feature needs. */
248
+ export interface IndexExecResult {
249
+ success: boolean;
250
+ exitCode: number | null;
251
+ timedOut: boolean;
252
+ stdout: string;
253
+ stderr: string;
254
+ error?: string | undefined;
255
+ }
256
+ /** Injected I/O, so a gate can drive the whole build without a host. */
257
+ export interface FileIndexDeps {
258
+ exec: (alias: string, command: string, timeoutMs: number) => Promise<IndexExecResult>;
259
+ /** Monotonic remote-write counter (see `api.ts` `remoteWriteSequence`). */
260
+ writeSequence: () => number;
261
+ }
262
+ /** One POSIX shell word, quoted. */
263
+ export declare function shellQuote(value: string): string;
264
+ /**
265
+ * The remote listing command.
266
+ *
267
+ * Shape decisions, and what each one prevents:
268
+ * - `cd` instead of passing the root to the tools: both paths are printed
269
+ * relative to the working directory, which is what the index wants.
270
+ * - a failed `cd` exits 3 WITH a message on stderr. Listing nothing would turn
271
+ * "the workspace root is gone" into "this tree has no files".
272
+ * - `rg` when the host has it, `find` otherwise, decided ON THE HOST in one
273
+ * command: no probe round trip and no per-alias cache to invalidate.
274
+ * - `--no-ignore --hidden` keeps ignored and dotted files searchable (what the
275
+ * name search does); the exclusion globs only prune noise directories.
276
+ * - both caps are applied remotely (`head -n cap+1`, then `head -c bytes`), so a
277
+ * million-line tree never crosses the wire just to be cut on this side.
278
+ * - the sentinel after the listing is what makes a capped prefix observable
279
+ * (see {@link parseFileIndexOutput}).
280
+ * - `LC_ALL=C`: byte-wise ordering from the tools, so the parser sees one
281
+ * canonical form no matter the host locale.
282
+ */
283
+ export declare function fileIndexCommand(root: string, caps?: {
284
+ entries?: number;
285
+ bytes?: number;
286
+ }): string;
287
+ export interface FileIndexListing {
288
+ paths: string[];
289
+ truncated: boolean;
290
+ /** The find fallback declared a depth bound (deeper files may be missing). */
291
+ depthCapped: number | undefined;
292
+ }
293
+ /**
294
+ * Turn one listing's stdout into sorted workspace-relative paths.
295
+ *
296
+ * Truncation is DERIVED, never assumed:
297
+ * - the sentinel is missing → the prefix ended at a cap (or the transport cut
298
+ * it) → `truncated: true`, and the final line is dropped because it may be a
299
+ * half-written path;
300
+ * - more than `maxEntries` lines survived → `truncated: true`, keep the prefix;
301
+ * - the find fallback's depth marker survived → `depthCapped` (a THIRD, separate
302
+ * bound: more levels exist than were walked).
303
+ *
304
+ * The caller-visible promise is that a bounded listing NEVER looks complete:
305
+ * every cap is its own reported fact.
306
+ */
307
+ export declare function parseFileIndexOutput(stdout: string, options?: {
308
+ root: string;
309
+ maxEntries?: number;
310
+ }): FileIndexListing;
311
+ /**
312
+ * Fetch and parse one listing.
313
+ *
314
+ * Rejects — loudly — whenever the run did not produce a trustworthy listing:
315
+ * timed out, transport-broken, never entered the workspace root (exit 3), or the
316
+ * listing tool failed AND listed nothing. A successful run with zero paths is a
317
+ * legitimate empty index (a brand new repository) and resolves with `paths: []`;
318
+ * a run whose tool listed some files and then reported errors resolves with the
319
+ * usable prefix plus `toolStatus`/`warning` saying it is incomplete.
320
+ *
321
+ * The write counter is read BEFORE the command starts: a write that lands while
322
+ * the listing is in flight must leave the index stale (its `writeSeq` is older),
323
+ * otherwise the modal could show — and open — a path that no longer exists.
324
+ */
325
+ export declare function buildFileIndex(deps: FileIndexDeps, target: {
326
+ alias: string;
327
+ root: string;
328
+ }, options?: {
329
+ entries?: number;
330
+ bytes?: number;
331
+ timeoutMs?: number;
332
+ }): Promise<FileIndex>;
@@ -18,7 +18,41 @@
18
18
  */
19
19
  import { type ReactNode } from 'react';
20
20
  import type { EditorTab } from '../store.tsx';
21
+ /** Why one hunk action (stage / unstage / revert) cannot run for this tab. */
22
+ export type HunkBlockReason = 'offline' | 'truncated';
23
+ /**
24
+ * Whether a hunk action is refused, and why.
25
+ *
26
+ * A hunk action ships `model.hunks[].patch` to `git apply` on the host, and that
27
+ * patch was parsed out of a `git diff` the host caps (`GIT_CAP`, 2 MB): on a
28
+ * capped read the last hunk can be a HALF patch, which git refuses as corrupt
29
+ * and the user sees git's raw error instead of "the file is too big". The pane
30
+ * is already read-only for a capped read (the `truncated` tab flag, D3); hunk
31
+ * writes have to obey that same promise instead of being the one exception.
32
+ *
33
+ * Pure and exported so the gate can pin both halves (offline and truncated)
34
+ * without rendering CodeMirror.
35
+ */
36
+ export declare function hunkBlockReason(tab: Pick<EditorTab, 'truncated'>, offline: boolean): HunkBlockReason | undefined;
37
+ /**
38
+ * The text the editable "after" pane must mount with.
39
+ *
40
+ * Three sources, in order, and each exists for a different unmount:
41
+ * - `editBuffer` — this component's own handoff. A MODE switch (split/before/
42
+ * after) unmounts only the `CodeEditor`, so the pane keeps its state.
43
+ * - `tab.text` — a PREVIOUS mount's handoff, written by `onBuffer` when a tab
44
+ * switch or a surface flip unmounted the whole pane. Only trusted while the
45
+ * tab is dirty: once saved, the disk bytes are the truth (and a later reload
46
+ * must be able to show them).
47
+ * - the disk bytes — first mount, or a clean tab.
48
+ *
49
+ * Pure and exported for the same reason as `hunkBlockReason`: the handoff is
50
+ * exactly the kind of thing that looks right in review and silently drops text
51
+ * in practice.
52
+ */
53
+ export declare function diffAfterInitialText(editBuffer: string | undefined, tab: Pick<EditorTab, 'text' | 'dirty'>, newText: string | undefined): string;
21
54
  export declare function DiffView(props: {
22
55
  tab: EditorTab;
23
56
  visible: boolean;
57
+ offline?: boolean;
24
58
  }): ReactNode;
@@ -86,6 +86,24 @@ export interface DiffPayload {
86
86
  newText: string;
87
87
  /** True when either side is binary (the view refuses to render it). */
88
88
  unsupported: boolean;
89
+ /**
90
+ * True when the WORKING-TREE side hit the read cap (8 MiB), so `newText` is a
91
+ * prefix of the file. The after pane must then be read-only: saving it would
92
+ * write the truncated prefix back over the real file.
93
+ */
94
+ truncated?: boolean;
95
+ /**
96
+ * The working-tree VERSION `newText` was read from (mtime in ms + size).
97
+ *
98
+ * The after pane of a working-tree diff is editable and saving it writes the
99
+ * real file, so it needs the same save-conflict baseline the file editor gets.
100
+ * It has to come from the SAME read that produced `newText` — a separate stat
101
+ * would describe whatever the file became afterwards, and the guard would then
102
+ * accept bytes the user never saw (or refuse a version they did see).
103
+ * Absent for staged/commit diffs, which are read-only.
104
+ */
105
+ mtime?: number;
106
+ size?: number;
89
107
  }
90
108
  /** Load a file's diff with both full revisions. */
91
109
  export declare function loadDiff(alias: string, root: string, path: string, staged: boolean, untracked?: boolean): Promise<DiffPayload>;
@@ -6,7 +6,23 @@ interface Pair {
6
6
  oldNum: number | null;
7
7
  newNum: number | null;
8
8
  }
9
- /** Parse the unified diff body into old/new line pairs (git's pairing). */
9
+ /**
10
+ * Parse the unified diff body into old/new line pairs (git's pairing).
11
+ *
12
+ * CONTEXT IS THE WHOLE POINT: a deleted SQL/Lua/Haskell comment line (`-- note`)
13
+ * arrives as `--- note`, and an inserted C line `++ i;` arrives as `+++ i;` —
14
+ * so a flat "skip anything starting with `--- ` / `+++ `" rule silently eats
15
+ * real content lines. That dropped the line from the pairing, stopped the line
16
+ * counters from advancing, and every row after it shifted: the deleted comment
17
+ * was painted as a MODIFIED line, the rest of the file was flagged changed and
18
+ * the `+/−` totals were wrong (measured on the shipped module before this fix).
19
+ *
20
+ * So the scan is not flat: it walks the hunk structure `parseUnifiedDiff`
21
+ * already produced (`git-ops.ts`, the same context-aware parser the commit pane
22
+ * trusts), where a line is content exactly when a hunk is open. File-block
23
+ * headers can only appear BEFORE a hunk starts, which is why the ambiguity
24
+ * disappears instead of being guessed at.
25
+ */
10
26
  export declare function parsePairs(diff: string): Pair[];
11
27
  export interface DiffInput {
12
28
  /** The unified diff text (`git diff ... -- <path>`). */
@@ -70,8 +70,16 @@ export declare function readGitSnapshot(key: string): GitSnapshot | undefined;
70
70
  * An answer OLDER than the one already cached is dropped. Two reads of one
71
71
  * workspace can overlap when the repo picker changes the directory mid-read (the
72
72
  * settled directory is a second key, see the store's `readGit`), and the older
73
- * walk may finish last — letting it win would hand the user a change list that
73
+ * walk may finish LAST — letting it win would hand the user a change list that
74
74
  * predates the one already shown.
75
+ *
76
+ * "Older" is decided by ISSUE order, not by finish order: the read queue stamps
77
+ * each started read and `readStartId` reports it here while the read runs. The
78
+ * previous implementation compared `at` (the finish time) and therefore could
79
+ * never reject the case it documented — the older walk finishing last always
80
+ * carries the LATER timestamp, so it won. Both the pure gate case and a real
81
+ * store-driven case now exercise the issue-order path (see
82
+ * `scripts/check-git-cache.mjs`).
75
83
  */
76
84
  export declare function writeGitSnapshot(key: string, snapshot: GitSnapshot): void;
77
85
  /** Drop every snapshot whose workspace left the binding table. */
@@ -89,5 +97,5 @@ export declare function retainGitSnapshots(bindingIds: ReadonlySet<string>): voi
89
97
  export declare function patchCachedGitStatus(key: string, repoRoot: string | undefined, status: GitStatusDetail): void;
90
98
  /** Same write-through for the expanded untracked directories. */
91
99
  export declare function patchCachedUntrackedDirs(key: string, repoRoot: string | undefined, dirs: DirExpansions): void;
92
- /** Test hook: forget every snapshot (the cache gate drives this module alone). */
100
+ /** Test hook: forget every snapshot and its ordering state (the cache gate drives this module alone). */
93
101
  export declare function clearGitSnapshots(): void;
@@ -31,11 +31,12 @@
31
31
  */
32
32
  /** How a caller relates to a read that is already in flight. */
33
33
  export type ReadMode = 'join' | 'fresh';
34
+ /** The start order of the newest read for `key`, while it is in flight. */
35
+ export declare function readStartId(key: string): number | undefined;
34
36
  export declare class ReadQueue {
35
37
  private readonly onChange?;
36
38
  /** In-flight reads by key (insertion order is irrelevant here). */
37
39
  private readonly flights;
38
- private nextId;
39
40
  /**
40
41
  * @param onChange - called whenever a read starts or settles, so the owner can
41
42
  * derive a "busy" flag from `inflightKeys()` without polling.
@@ -46,6 +46,10 @@ export interface StageClock {
46
46
  }
47
47
  /** The debounce window: how long clicks keep merging into one probe. */
48
48
  export declare const DEFAULT_STAGE_WINDOW_MS = 250;
49
+ /** Called by the source-control panel whenever its repository changes. */
50
+ export declare function setVisibleStageRepository(target: ScmTarget | undefined): void;
51
+ /** The repository the coordinator may write local results back into. */
52
+ export declare function visibleStageRepository(): ScmTarget | undefined;
49
53
  /**
50
54
  * Coordinates optimistic stage/unstage with a debounced, path-limited check.
51
55
  *
@@ -87,6 +91,15 @@ export declare class StageCoordinator {
87
91
  flush(): Promise<void>;
88
92
  /** Drop the pending window (page teardown; the writes already went out). */
89
93
  dispose(): void;
94
+ /**
95
+ * May a result about `target` be written into the panel's local model?
96
+ *
97
+ * `true` while no panel has reported a repository (headless callers, local
98
+ * checks) and while the reported repository IS `target`. `false` once the
99
+ * panel has moved to another repository: the paths in the result are relative
100
+ * to `target`'s root and would land on the wrong rows (see `visibleRepository`).
101
+ */
102
+ private stillVisible;
90
103
  /** Queue one write behind the previous one for the same repository. */
91
104
  private enqueue;
92
105
  /** (Re)start the debounce window. */
@@ -87,7 +87,9 @@ export declare function stagedStateOf(detail: GitStatusDetail, path: string): bo
87
87
  * under "changes", so the record stays in the model);
88
88
  * - unstaging a staged RENAME leaves HEAD's path deleted in the INDEX — the
89
89
  * old path becomes `D ` and the new one untracked (measured, not assumed);
90
- * - staging a conflict resolves it into the index.
90
+ * - staging a conflict resolves it into the index (`D `/`A `/`M ` by conflict
91
+ * pair, never a `U` half — see `localStageEntry`, it used to keep `U` and
92
+ * the row then never left the conflict section);
91
93
  *
92
94
  * Pure, so the panel's instant feedback is assertable without a host: the
93
95
  * caller decides WHEN to apply it (and when to apply the inverse).