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.
- package/README.en.md +455 -443
- package/README.md +408 -396
- package/lib/client.js +8062 -2651
- package/lib/index.js +1058 -288
- package/lib/p2-router-fs.js +1 -1
- package/lib/p2-router-refs.js +89 -10
- package/lib/p2-router-spill.js +73 -1
- package/lib/p2-router-subprocess.js +18 -6
- package/lib/spill-retention-BwKEWrl5.js +115 -0
- package/lib/{ssh-proc-arI5lm4W.js → ssh-proc-VKWn_LZC.js} +17 -0
- package/lib/types/archive.d.ts +1 -1
- package/lib/types/changes/recorder.d.ts +34 -2
- package/lib/types/client/CodeEditor.d.ts +12 -0
- package/lib/types/client/ConnectionStatus.d.ts +17 -0
- package/lib/types/client/DirectoryFlow.d.ts +2 -0
- package/lib/types/client/DoctorPanel.d.ts +25 -0
- package/lib/types/client/QuickOpen.d.ts +17 -0
- package/lib/types/client/RemoteExplorer.d.ts +192 -1
- package/lib/types/client/RemoteRoot.d.ts +17 -0
- package/lib/types/client/SearchView.d.ts +55 -0
- package/lib/types/client/TerminalView.d.ts +38 -0
- package/lib/types/client/WorkspaceWizard.d.ts +17 -0
- package/lib/types/client/api.d.ts +54 -4
- package/lib/types/client/changes/undo-affordance.d.ts +16 -0
- package/lib/types/client/changes/undo-context.d.ts +14 -18
- package/lib/types/client/changes/undo-target.d.ts +78 -0
- package/lib/types/client/connection.d.ts +111 -0
- package/lib/types/client/doctor.d.ts +122 -0
- package/lib/types/client/download.d.ts +35 -5
- package/lib/types/client/downloads.d.ts +18 -1
- package/lib/types/client/file-open-probe.d.ts +64 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/quickopen-model.d.ts +332 -0
- package/lib/types/client/scm/DiffView.d.ts +34 -0
- package/lib/types/client/scm/actions.d.ts +18 -0
- package/lib/types/client/scm/diff-model.d.ts +17 -1
- package/lib/types/client/scm/git-cache.d.ts +10 -2
- package/lib/types/client/scm/read-queue.d.ts +2 -1
- package/lib/types/client/scm/stage-queue.d.ts +13 -0
- package/lib/types/client/scm/status-map.d.ts +3 -1
- package/lib/types/client/store.d.ts +114 -5
- package/lib/types/client/vsc/FindWidget.d.ts +7 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +57 -0
- package/lib/types/deploy.d.ts +44 -2
- package/lib/types/git-format.d.ts +15 -0
- package/lib/types/http.d.ts +44 -0
- package/lib/types/p2/file-refs.d.ts +39 -2
- package/lib/types/p2/helper-rpc.d.ts +26 -0
- package/lib/types/p2/router-spill.d.ts +19 -0
- package/lib/types/p2/router-subprocess.d.ts +2 -0
- package/lib/types/p2/spill-retention.d.ts +74 -0
- package/lib/types/p2/worlds.d.ts +11 -0
- package/lib/types/pool.d.ts +73 -11
- package/lib/types/protocol.d.ts +63 -0
- package/lib/types/routes.d.ts +18 -0
- package/lib/types/sftp.d.ts +114 -8
- package/lib/types/store.d.ts +34 -0
- package/lib/types/timeouts.d.ts +14 -0
- package/lib/{worlds-C6Xha1mQ.js → worlds-Be1YE2Ot.js} +727 -78
- package/package.json +1 -1
- package/src/archive.ts +41 -9
- package/src/changes/recorder.ts +227 -31
- package/src/changes/status.ts +37 -1
- package/src/client/CodeEditor.tsx +84 -2
- package/src/client/ConnectionStatus.tsx +130 -0
- package/src/client/DirectoryFlow.tsx +40 -5
- package/src/client/DoctorPanel.tsx +202 -0
- package/src/client/DownloadDock.tsx +13 -25
- package/src/client/EditorPane.tsx +291 -7
- package/src/client/HostsView.tsx +17 -8
- package/src/client/QuickOpen.tsx +371 -0
- package/src/client/RemoteDirectoryPicker.tsx +54 -3
- package/src/client/RemoteExplorer.tsx +879 -160
- package/src/client/RemoteRoot.tsx +178 -1
- package/src/client/SearchView.tsx +180 -6
- package/src/client/SettingsHosts.tsx +1 -1
- package/src/client/TerminalView.tsx +174 -9
- package/src/client/WorkspaceWizard.tsx +110 -16
- package/src/client/WorkspacesView.tsx +22 -6
- package/src/client/api.ts +197 -11
- package/src/client/changes/ChangesDock.tsx +35 -8
- package/src/client/changes/undo-affordance.ts +33 -0
- package/src/client/changes/undo-context.ts +14 -18
- package/src/client/changes/undo-target.ts +139 -0
- package/src/client/connection.ts +264 -0
- package/src/client/doctor.ts +441 -0
- package/src/client/download.ts +148 -12
- package/src/client/downloads.ts +43 -2
- package/src/client/file-open-probe.ts +83 -0
- package/src/client/i18n.ts +244 -0
- package/src/client/index.tsx +5 -2
- package/src/client/quickopen-model.ts +778 -0
- package/src/client/remote-file-open.ts +21 -33
- package/src/client/scm/DiffView.tsx +116 -6
- package/src/client/scm/ScmPanel.tsx +19 -0
- package/src/client/scm/actions.ts +34 -2
- package/src/client/scm/diff-model.ts +33 -37
- package/src/client/scm/git-cache.ts +61 -4
- package/src/client/scm/read-queue.ts +33 -2
- package/src/client/scm/stage-queue.ts +72 -1
- package/src/client/scm/status-map.ts +22 -1
- package/src/client/store.tsx +704 -21
- package/src/client/vsc/FindWidget.tsx +20 -0
- package/src/client/vsc/kit.tsx +115 -6
- package/src/client/vsc/reveal-line.ts +33 -14
- package/src/client/vsc/save-shortcut.ts +131 -0
- package/src/client/vsc/vsc.css +419 -0
- package/src/deploy.ts +185 -33
- package/src/git-format.ts +136 -22
- package/src/git-ops.ts +14 -6
- package/src/http.ts +80 -12
- package/src/importers.ts +80 -21
- package/src/index.ts +21 -1
- package/src/p2/file-refs.ts +112 -10
- package/src/p2/helper-rpc.ts +73 -36
- package/src/p2/router-spill.ts +96 -1
- package/src/p2/router-subprocess.ts +18 -5
- package/src/p2/spill-retention.ts +134 -0
- package/src/p2/ssh-proc.ts +22 -0
- package/src/p2/worlds.ts +24 -0
- package/src/pool.ts +329 -47
- package/src/protocol.ts +66 -0
- package/src/routes.ts +251 -43
- package/src/sftp.ts +486 -26
- package/src/store.ts +207 -85
- package/src/terminal.ts +38 -2
- package/src/timeouts.ts +14 -0
- package/src/tools.ts +14 -5
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import type { Context } from '@deepseek-ai/cordis'
|
|
25
25
|
import { api } from './api.ts'
|
|
26
|
+
import { connectionStateOf, isConnectionFailure } from './connection.ts'
|
|
27
|
+
import { probeCandidates } from './file-open-probe.ts'
|
|
26
28
|
import {
|
|
27
29
|
parseFileAddress,
|
|
28
30
|
resolveRemoteOpenTarget,
|
|
@@ -71,35 +73,13 @@ function lineOf(options: unknown): number | undefined {
|
|
|
71
73
|
return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
/**
|
|
75
|
-
* Probe candidates in order and return the first one that exists.
|
|
76
|
-
*
|
|
77
|
-
* Every click pays at most one remote stat when the first candidate is right;
|
|
78
|
-
* the probe is skipped entirely only when the binding has a single candidate
|
|
79
|
-
* AND that candidate is the workspace-root spelling (the common, healthy
|
|
80
|
-
* case) — see the caller for the fallback search when every probe misses.
|
|
81
|
-
*
|
|
82
|
-
* @returns the chosen remote path, or `undefined` when none exists.
|
|
83
|
-
*/
|
|
84
|
-
async function firstExisting(
|
|
85
|
-
alias: string,
|
|
86
|
-
candidates: readonly string[],
|
|
87
|
-
): Promise<string | undefined> {
|
|
88
|
-
for (const candidate of candidates) {
|
|
89
|
-
const exists = await withDeadline(api.fileOp.stat(alias, candidate), EXIST_PROBE_MS).then(
|
|
90
|
-
() => true,
|
|
91
|
-
() => false,
|
|
92
|
-
)
|
|
93
|
-
if (exists === true) return candidate
|
|
94
|
-
}
|
|
95
|
-
return undefined
|
|
96
|
-
}
|
|
97
|
-
|
|
98
76
|
/**
|
|
99
77
|
* Last-resort lookup for a clicked PROJECT-relative path (the model `cd`ed
|
|
100
78
|
* inside individual shell commands, so the session cwd never moved): search
|
|
101
79
|
* the binding's remote tree for a unique file whose path ends with the
|
|
102
|
-
* clicked spelling. Only issued after every direct candidate
|
|
80
|
+
* clicked spelling. Only issued after every direct candidate said "missing" —
|
|
81
|
+
* a timeout or a dropped link is NOT "missing" (see `file-open-probe.ts`), so
|
|
82
|
+
* an unknown verdict never pays for this 7s search.
|
|
103
83
|
*/
|
|
104
84
|
async function searchSuffix(binding: RemoteOpenBinding, relative: string): Promise<string | undefined> {
|
|
105
85
|
const command = suffixFindCommand(binding.remotePath, relative)
|
|
@@ -148,22 +128,30 @@ function interceptSync(ctx: Context, parsed: ParsedFileAddress, address: string,
|
|
|
148
128
|
const open = (remotePath: string): void => {
|
|
149
129
|
openRemoteFileInBinding(target.binding.id, remotePath, line === undefined ? {} : { line })
|
|
150
130
|
}
|
|
151
|
-
const existing = await
|
|
152
|
-
|
|
153
|
-
|
|
131
|
+
const existing = await probeCandidates(target.binding.alias, target.candidates, {
|
|
132
|
+
stat: api.fileOp.stat,
|
|
133
|
+
deadline: withDeadline,
|
|
134
|
+
connection: connectionStateOf,
|
|
135
|
+
isLinkFailure: isConnectionFailure,
|
|
136
|
+
}, EXIST_PROBE_MS)
|
|
137
|
+
if (existing.kind === 'exists') {
|
|
138
|
+
open(existing.path)
|
|
154
139
|
return
|
|
155
140
|
}
|
|
156
|
-
// Nothing at the direct spellings: the model may
|
|
157
|
-
// project-relative path (its `cd` lived inside shell commands
|
|
158
|
-
|
|
141
|
+
// Nothing at the direct spellings that the host could ANSWER: the model may
|
|
142
|
+
// have quoted a project-relative path (its `cd` lived inside shell commands
|
|
143
|
+
// only). An unknown verdict (timeout / dropped link) says nothing about the
|
|
144
|
+
// spelling, so it must not pay for the search either.
|
|
145
|
+
if (existing.kind === 'missing' && relative !== undefined) {
|
|
159
146
|
const found = await searchSuffix(target.binding, relative)
|
|
160
147
|
if (found !== undefined) {
|
|
161
148
|
open(found)
|
|
162
149
|
return
|
|
163
150
|
}
|
|
164
151
|
}
|
|
165
|
-
//
|
|
166
|
-
//
|
|
152
|
+
// Otherwise open the primary spelling so the editor shows the remote read
|
|
153
|
+
// error (named against the remote workspace, not the empty alias) — with a
|
|
154
|
+
// dead link that is the offline read-only banner, not a dead click.
|
|
167
155
|
open(target.candidates[0])
|
|
168
156
|
})().catch((error: unknown) => {
|
|
169
157
|
// The editor open itself failed: keep the click a no-op rather than
|
|
@@ -259,7 +259,58 @@ const HUNK_TOAST_KEY: Record<'stage' | 'unstage' | 'revert', string> = {
|
|
|
259
259
|
revert: 'scm.hunkReverted',
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
/** Why one hunk action (stage / unstage / revert) cannot run for this tab. */
|
|
263
|
+
export type HunkBlockReason = 'offline' | 'truncated'
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Whether a hunk action is refused, and why.
|
|
267
|
+
*
|
|
268
|
+
* A hunk action ships `model.hunks[].patch` to `git apply` on the host, and that
|
|
269
|
+
* patch was parsed out of a `git diff` the host caps (`GIT_CAP`, 2 MB): on a
|
|
270
|
+
* capped read the last hunk can be a HALF patch, which git refuses as corrupt
|
|
271
|
+
* and the user sees git's raw error instead of "the file is too big". The pane
|
|
272
|
+
* is already read-only for a capped read (the `truncated` tab flag, D3); hunk
|
|
273
|
+
* writes have to obey that same promise instead of being the one exception.
|
|
274
|
+
*
|
|
275
|
+
* Pure and exported so the gate can pin both halves (offline and truncated)
|
|
276
|
+
* without rendering CodeMirror.
|
|
277
|
+
*/
|
|
278
|
+
export function hunkBlockReason(
|
|
279
|
+
tab: Pick<EditorTab, 'truncated'>,
|
|
280
|
+
offline: boolean,
|
|
281
|
+
): HunkBlockReason | undefined {
|
|
282
|
+
if (offline) return 'offline'
|
|
283
|
+
if (tab.truncated) return 'truncated'
|
|
284
|
+
return undefined
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* The text the editable "after" pane must mount with.
|
|
289
|
+
*
|
|
290
|
+
* Three sources, in order, and each exists for a different unmount:
|
|
291
|
+
* - `editBuffer` — this component's own handoff. A MODE switch (split/before/
|
|
292
|
+
* after) unmounts only the `CodeEditor`, so the pane keeps its state.
|
|
293
|
+
* - `tab.text` — a PREVIOUS mount's handoff, written by `onBuffer` when a tab
|
|
294
|
+
* switch or a surface flip unmounted the whole pane. Only trusted while the
|
|
295
|
+
* tab is dirty: once saved, the disk bytes are the truth (and a later reload
|
|
296
|
+
* must be able to show them).
|
|
297
|
+
* - the disk bytes — first mount, or a clean tab.
|
|
298
|
+
*
|
|
299
|
+
* Pure and exported for the same reason as `hunkBlockReason`: the handoff is
|
|
300
|
+
* exactly the kind of thing that looks right in review and silently drops text
|
|
301
|
+
* in practice.
|
|
302
|
+
*/
|
|
303
|
+
export function diffAfterInitialText(
|
|
304
|
+
editBuffer: string | undefined,
|
|
305
|
+
tab: Pick<EditorTab, 'text' | 'dirty'>,
|
|
306
|
+
newText: string | undefined,
|
|
307
|
+
): string {
|
|
308
|
+
if (editBuffer !== undefined) return editBuffer
|
|
309
|
+
if (tab.dirty && tab.text !== '') return tab.text
|
|
310
|
+
return newText ?? ''
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export function DiffView(props: { tab: EditorTab; visible: boolean; offline?: boolean }): ReactNode {
|
|
263
314
|
const store = useExplorer()
|
|
264
315
|
const { t, lang } = store
|
|
265
316
|
const tab = props.tab
|
|
@@ -399,6 +450,16 @@ export function DiffView(props: { tab: EditorTab; visible: boolean }): ReactNode
|
|
|
399
450
|
)
|
|
400
451
|
|
|
401
452
|
const runHunk = async (index: number, kind: 'stage' | 'unstage' | 'revert'): Promise<void> => {
|
|
453
|
+
// A hunk action is a remote write, and it ships a patch parsed out of a
|
|
454
|
+
// possibly CAPPED diff: offline it can only fail (and the first failure
|
|
455
|
+
// surfaces raw socket text), on a truncated tab it would send a half patch
|
|
456
|
+
// that git rejects as corrupt. Both are refused with the reason; the gutter
|
|
457
|
+
// buttons are disabled for the same two states.
|
|
458
|
+
const blocked = hunkBlockReason(tab, props.offline === true)
|
|
459
|
+
if (blocked !== undefined) {
|
|
460
|
+
toast(t(blocked === 'offline' ? 'connection.saveBlocked' : 'scm.hunkTruncated'), true)
|
|
461
|
+
return
|
|
462
|
+
}
|
|
402
463
|
const hunk = model?.hunks.find(item => item.index === index)
|
|
403
464
|
if (hunk === undefined || store.repoRoot === undefined) return
|
|
404
465
|
setHunkBusy(index)
|
|
@@ -421,6 +482,17 @@ export function DiffView(props: { tab: EditorTab; visible: boolean }): ReactNode
|
|
|
421
482
|
}
|
|
422
483
|
|
|
423
484
|
const saveAfter = async (): Promise<void> => {
|
|
485
|
+
if (props.offline === true) {
|
|
486
|
+
// The link is down: writing now can only fail (see the connection chip).
|
|
487
|
+
toast(t('connection.saveBlocked'), true)
|
|
488
|
+
return
|
|
489
|
+
}
|
|
490
|
+
if (tab.truncated) {
|
|
491
|
+
// `newText` is only the read cap's prefix: writing it would truncate the
|
|
492
|
+
// real file. The pane is read-only, but Ctrl+S must say why.
|
|
493
|
+
toast(t('editor.truncatedReadOnly'), true)
|
|
494
|
+
return
|
|
495
|
+
}
|
|
424
496
|
// The editable pane is a CodeMirror buffer: read it imperatively so the
|
|
425
497
|
// write carries the live text, then persist through the same route the
|
|
426
498
|
// file editor uses and reload the diff from the new working tree.
|
|
@@ -428,7 +500,17 @@ export function DiffView(props: { tab: EditorTab; visible: boolean }): ReactNode
|
|
|
428
500
|
if (text === undefined) return
|
|
429
501
|
setEditBuffer(text)
|
|
430
502
|
store.updateTab(tab.id, { text })
|
|
431
|
-
await store.saveTab(tab.id, text)
|
|
503
|
+
const saved = await store.saveTab(tab.id, text)
|
|
504
|
+
/**
|
|
505
|
+
* Only a LANDED write is followed by a reload.
|
|
506
|
+
*
|
|
507
|
+
* The old code reloaded on every outcome, so a permission error, a full disk
|
|
508
|
+
* or a dropped link replaced the buffer with the remote bytes and said
|
|
509
|
+
* nothing — the user's edit was gone without a confirmation. A refused save
|
|
510
|
+
* now shows its own banner (overwrite / reload / difference); any other
|
|
511
|
+
* failure shows its toast and keeps the buffer.
|
|
512
|
+
*/
|
|
513
|
+
if (!saved) return
|
|
432
514
|
await store.reloadTab(tab.id)
|
|
433
515
|
}
|
|
434
516
|
|
|
@@ -456,10 +538,18 @@ export function DiffView(props: { tab: EditorTab; visible: boolean }): ReactNode
|
|
|
456
538
|
)
|
|
457
539
|
}
|
|
458
540
|
|
|
459
|
-
const editable = mode === 'after' && !tab.staged
|
|
541
|
+
const editable = mode === 'after' && !tab.staged && props.offline !== true && !tab.truncated
|
|
542
|
+
/**
|
|
543
|
+
* The gutter hunk buttons obey the same refusal as `runHunk` (see
|
|
544
|
+
* `hunkBlockReason`), and a disabled button names the REAL reason when it has
|
|
545
|
+
* one — a silently greyed control reads as a bug.
|
|
546
|
+
*/
|
|
547
|
+
const hunkDisabled = props.offline === true || tab.truncated
|
|
548
|
+
const hunkDisabledTitle = tab.truncated ? t('scm.hunkTruncated') : undefined
|
|
460
549
|
|
|
461
550
|
return (
|
|
462
551
|
<div className="rvs-diff">
|
|
552
|
+
{tab.truncated && <div className="rvs-banner warn">{t('editor.truncatedReadOnly')}</div>}
|
|
463
553
|
<div className="rvs-diff-toolbar">
|
|
464
554
|
<Segmented<ViewMode>
|
|
465
555
|
value={mode}
|
|
@@ -556,7 +646,8 @@ export function DiffView(props: { tab: EditorTab; visible: boolean }): ReactNode
|
|
|
556
646
|
<button
|
|
557
647
|
type="button"
|
|
558
648
|
className="rvs-hunk-btn stage"
|
|
559
|
-
title={tab.staged ? t('scm.unstageHunk') : t('scm.stageHunk')}
|
|
649
|
+
title={hunkDisabledTitle ?? (tab.staged ? t('scm.unstageHunk') : t('scm.stageHunk'))}
|
|
650
|
+
disabled={hunkDisabled}
|
|
560
651
|
onClick={() => { void runHunk(hunk.index, tab.staged ? 'unstage' : 'stage') }}
|
|
561
652
|
>
|
|
562
653
|
{tab.staged ? '↧' : '⤒'}
|
|
@@ -565,7 +656,8 @@ export function DiffView(props: { tab: EditorTab; visible: boolean }): ReactNode
|
|
|
565
656
|
<button
|
|
566
657
|
type="button"
|
|
567
658
|
className="rvs-hunk-btn revert"
|
|
568
|
-
title={t('scm.revertHunk')}
|
|
659
|
+
title={hunkDisabledTitle ?? t('scm.revertHunk')}
|
|
660
|
+
disabled={hunkDisabled}
|
|
569
661
|
onClick={() => { void runHunk(hunk.index, 'revert') }}
|
|
570
662
|
>
|
|
571
663
|
↩
|
|
@@ -630,9 +722,16 @@ export function DiffView(props: { tab: EditorTab; visible: boolean }): ReactNode
|
|
|
630
722
|
<CodeEditor
|
|
631
723
|
key={`${tab.id}:edit`}
|
|
632
724
|
ref={editorRef}
|
|
633
|
-
initial={editBuffer
|
|
725
|
+
initial={diffAfterInitialText(editBuffer, tab, tab.diff?.newText)}
|
|
726
|
+
// The disk side of the dirty comparison, exactly like the file
|
|
727
|
+
// editor (`EditorPane` passes `activeTab.baseline`): without it a
|
|
728
|
+
// remount that carries the handoff text would be judged clean
|
|
729
|
+
// against itself and the tab's dot would drift from the buffer.
|
|
730
|
+
savedText={tab.diff?.newText}
|
|
634
731
|
path={tab.fullPath}
|
|
732
|
+
readOnly={props.offline === true || tab.truncated}
|
|
635
733
|
visible={props.visible}
|
|
734
|
+
tabId={tab.id}
|
|
636
735
|
ctx={store.ctx}
|
|
637
736
|
sessionId={chat.sessionId}
|
|
638
737
|
remoteRoot={store.repoRoot ?? store.root}
|
|
@@ -643,6 +742,17 @@ export function DiffView(props: { tab: EditorTab; visible: boolean }): ReactNode
|
|
|
643
742
|
store.updateTab(tab.id, { dirty })
|
|
644
743
|
forceRender(n => n + 1)
|
|
645
744
|
}}
|
|
745
|
+
/**
|
|
746
|
+
* The diff pane's half of the D1 handover. Its `CodeEditor` is
|
|
747
|
+
* unmounted BOTH by a mode switch (this component stays mounted)
|
|
748
|
+
* and by a tab switch / surface flip (everything unmounts), so the
|
|
749
|
+
* text has to land in both places: this mount's buffer for the
|
|
750
|
+
* first, the tab for the second.
|
|
751
|
+
*/
|
|
752
|
+
onBuffer={(id, text) => {
|
|
753
|
+
setEditBuffer(text)
|
|
754
|
+
store.updateTab(id, { text })
|
|
755
|
+
}}
|
|
646
756
|
/>
|
|
647
757
|
</div>
|
|
648
758
|
)
|
|
@@ -32,6 +32,7 @@ import { ExecPanel, type ExecPanelState } from './ExecPanel.tsx'
|
|
|
32
32
|
import type { ChangeEntry } from './status-map.ts'
|
|
33
33
|
import { rowVerb } from './status-map.ts'
|
|
34
34
|
import { ReadQueue } from './read-queue.ts'
|
|
35
|
+
import { setVisibleStageRepository } from './stage-queue.ts'
|
|
35
36
|
import { readScmExtras, repoCacheKey, writeScmExtras, type ScmExtrasSnapshot } from './panel-cache.ts'
|
|
36
37
|
import { RepoPicker } from './RepoPicker.tsx'
|
|
37
38
|
import {
|
|
@@ -145,6 +146,24 @@ export function ScmPanel(props: { onOpenHistory: () => void; visible: boolean })
|
|
|
145
146
|
|
|
146
147
|
const fold = (id: string): void => setFolded(prev => ({ ...prev, [id]: prev[id] !== true }))
|
|
147
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Tell the stage coordinator which repository this panel is showing.
|
|
151
|
+
*
|
|
152
|
+
* A stage click applies locally at once and is verified ~250 ms later (plus the
|
|
153
|
+
* write's own round trip). If the user switches repository inside that window,
|
|
154
|
+
* the correction names paths relative to the OLD root; `stage-queue.ts` drops
|
|
155
|
+
* such results instead of applying them to the wrong rows — but it can only do
|
|
156
|
+
* that if it knows what is on screen now, which is what this reports.
|
|
157
|
+
*
|
|
158
|
+
* Declared here (not in the coordinator) because the panel is the only surface
|
|
159
|
+
* that knows the visible repository; the store keeps its own selection state
|
|
160
|
+
* and must not grow a second source of truth for this guard.
|
|
161
|
+
*/
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
setVisibleStageRepository(repoRoot === undefined ? undefined : { alias, root: repoRoot })
|
|
164
|
+
return () => { setVisibleStageRepository(undefined) }
|
|
165
|
+
}, [alias, repoRoot])
|
|
166
|
+
|
|
148
167
|
useEffect(() => {
|
|
149
168
|
try {
|
|
150
169
|
localStorage.setItem(MSG_KEY, message)
|
|
@@ -235,6 +235,24 @@ export interface DiffPayload {
|
|
|
235
235
|
newText: string
|
|
236
236
|
/** True when either side is binary (the view refuses to render it). */
|
|
237
237
|
unsupported: boolean
|
|
238
|
+
/**
|
|
239
|
+
* True when the WORKING-TREE side hit the read cap (8 MiB), so `newText` is a
|
|
240
|
+
* prefix of the file. The after pane must then be read-only: saving it would
|
|
241
|
+
* write the truncated prefix back over the real file.
|
|
242
|
+
*/
|
|
243
|
+
truncated?: boolean
|
|
244
|
+
/**
|
|
245
|
+
* The working-tree VERSION `newText` was read from (mtime in ms + size).
|
|
246
|
+
*
|
|
247
|
+
* The after pane of a working-tree diff is editable and saving it writes the
|
|
248
|
+
* real file, so it needs the same save-conflict baseline the file editor gets.
|
|
249
|
+
* It has to come from the SAME read that produced `newText` — a separate stat
|
|
250
|
+
* would describe whatever the file became afterwards, and the guard would then
|
|
251
|
+
* accept bytes the user never saw (or refuse a version they did see).
|
|
252
|
+
* Absent for staged/commit diffs, which are read-only.
|
|
253
|
+
*/
|
|
254
|
+
mtime?: number
|
|
255
|
+
size?: number
|
|
238
256
|
}
|
|
239
257
|
|
|
240
258
|
/** Load a file's diff with both full revisions. */
|
|
@@ -242,7 +260,7 @@ export async function loadDiff(alias: string, root: string, path: string, staged
|
|
|
242
260
|
if (untracked) {
|
|
243
261
|
const read = await api.fileOp.read(alias, joinRemote(root, path))
|
|
244
262
|
if (read.binary) return { diff: '', oldText: '', newText: '', unsupported: true }
|
|
245
|
-
return { diff: '', oldText: '', newText: read.text ?? '', unsupported: false }
|
|
263
|
+
return { diff: '', oldText: '', newText: read.text ?? '', unsupported: false, truncated: read.truncated, mtime: read.mtime, size: read.size }
|
|
246
264
|
}
|
|
247
265
|
const diffOut = await run(alias, diffCommand(root, { staged, path }))
|
|
248
266
|
const diff = diffOut.stdout
|
|
@@ -252,6 +270,9 @@ export async function loadDiff(alias: string, root: string, path: string, staged
|
|
|
252
270
|
const oldRev = staged ? 'HEAD' : ':0'
|
|
253
271
|
const oldText = await tryRun(alias, fileAtRevCommand(root, oldRev, path))
|
|
254
272
|
let newText = ''
|
|
273
|
+
let truncated = false
|
|
274
|
+
let mtime: number | undefined
|
|
275
|
+
let size: number | undefined
|
|
255
276
|
if (staged) {
|
|
256
277
|
newText = await tryRun(alias, fileAtRevCommand(root, ':0', path))
|
|
257
278
|
} else {
|
|
@@ -259,13 +280,24 @@ export async function loadDiff(alias: string, root: string, path: string, staged
|
|
|
259
280
|
const read = await api.fileOp.read(alias, joinRemote(root, path))
|
|
260
281
|
if (read.binary) return { diff, oldText, newText: '', unsupported: true }
|
|
261
282
|
newText = read.text ?? ''
|
|
283
|
+
truncated = read.truncated
|
|
284
|
+
// The after pane's save baseline, from THIS read.
|
|
285
|
+
mtime = read.mtime
|
|
286
|
+
size = read.size
|
|
262
287
|
} catch {
|
|
263
288
|
// Deleted on the worktree: the right side is empty by definition.
|
|
264
289
|
newText = ''
|
|
265
290
|
}
|
|
266
291
|
}
|
|
267
292
|
// `git show` appends nothing; a missing blob means "new file" ('').
|
|
268
|
-
return {
|
|
293
|
+
return {
|
|
294
|
+
diff,
|
|
295
|
+
oldText: stripTrailingNewline(oldText),
|
|
296
|
+
newText: stripTrailingNewline(newText),
|
|
297
|
+
unsupported: false,
|
|
298
|
+
truncated,
|
|
299
|
+
...(mtime === undefined ? {} : { mtime, size }),
|
|
300
|
+
}
|
|
269
301
|
}
|
|
270
302
|
|
|
271
303
|
/** `git show` output keeps the trailing newline the file content does not need. */
|
|
@@ -28,46 +28,42 @@ function splitLines(text: string): string[] {
|
|
|
28
28
|
return lines
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Parse the unified diff body into old/new line pairs (git's pairing).
|
|
33
|
+
*
|
|
34
|
+
* CONTEXT IS THE WHOLE POINT: a deleted SQL/Lua/Haskell comment line (`-- note`)
|
|
35
|
+
* arrives as `--- note`, and an inserted C line `++ i;` arrives as `+++ i;` —
|
|
36
|
+
* so a flat "skip anything starting with `--- ` / `+++ `" rule silently eats
|
|
37
|
+
* real content lines. That dropped the line from the pairing, stopped the line
|
|
38
|
+
* counters from advancing, and every row after it shifted: the deleted comment
|
|
39
|
+
* was painted as a MODIFIED line, the rest of the file was flagged changed and
|
|
40
|
+
* the `+/−` totals were wrong (measured on the shipped module before this fix).
|
|
41
|
+
*
|
|
42
|
+
* So the scan is not flat: it walks the hunk structure `parseUnifiedDiff`
|
|
43
|
+
* already produced (`git-ops.ts`, the same context-aware parser the commit pane
|
|
44
|
+
* trusts), where a line is content exactly when a hunk is open. File-block
|
|
45
|
+
* headers can only appear BEFORE a hunk starts, which is why the ambiguity
|
|
46
|
+
* disappears instead of being guessed at.
|
|
47
|
+
*/
|
|
32
48
|
export function parsePairs(diff: string): Pair[] {
|
|
33
49
|
const pairs: Pair[] = []
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
line.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|| line.startsWith('copy to')
|
|
51
|
-
|| line.startsWith('\\')
|
|
52
|
-
) continue
|
|
53
|
-
if (line.startsWith('@@')) {
|
|
54
|
-
const match = /@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line)
|
|
55
|
-
if (match !== null) {
|
|
56
|
-
oldLine = Number(match[1])
|
|
57
|
-
newLine = Number(match[2])
|
|
50
|
+
for (const file of parseUnifiedDiff(diff)) {
|
|
51
|
+
for (const hunk of file.hunks) {
|
|
52
|
+
let oldLine = hunk.oldStart
|
|
53
|
+
let newLine = hunk.newStart
|
|
54
|
+
for (const line of hunk.lines) {
|
|
55
|
+
// `` carries no line of its own.
|
|
56
|
+
if (line.startsWith('\\')) continue
|
|
57
|
+
if (line.startsWith('+')) {
|
|
58
|
+
pairs.push({ old: '', new: line.slice(1), oldNum: null, newNum: newLine++ })
|
|
59
|
+
continue
|
|
60
|
+
}
|
|
61
|
+
if (line.startsWith('-')) {
|
|
62
|
+
pairs.push({ old: line.slice(1), new: '', oldNum: oldLine++, newNum: null })
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
pairs.push({ old: line.slice(1), new: line.slice(1), oldNum: oldLine++, newNum: newLine++ })
|
|
58
66
|
}
|
|
59
|
-
continue
|
|
60
|
-
}
|
|
61
|
-
if (line.startsWith('+')) {
|
|
62
|
-
pairs.push({ old: '', new: line.slice(1), oldNum: null, newNum: newLine++ })
|
|
63
|
-
continue
|
|
64
|
-
}
|
|
65
|
-
if (line.startsWith('-')) {
|
|
66
|
-
pairs.push({ old: line.slice(1), new: '', oldNum: oldLine++, newNum: null })
|
|
67
|
-
continue
|
|
68
|
-
}
|
|
69
|
-
if (line.startsWith(' ')) {
|
|
70
|
-
pairs.push({ old: line.slice(1), new: line.slice(1), oldNum: oldLine++, newNum: newLine++ })
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
69
|
return pairs
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* a second source of truth — every value in it was read by a real command.
|
|
23
23
|
*/
|
|
24
24
|
import type { GitStatusDetail } from '../../protocol.ts'
|
|
25
|
+
import { readStartId } from './read-queue.ts'
|
|
25
26
|
import type { DirExpansions } from './untracked-dirs.ts'
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -87,6 +88,39 @@ const SNAPSHOT_LIMIT = 12
|
|
|
87
88
|
/** Snapshots by cache key, in recency order (oldest insertion first). */
|
|
88
89
|
const snapshots = new Map<string, GitSnapshot>()
|
|
89
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Issue order of the read that produced the cached snapshot, per key.
|
|
93
|
+
*
|
|
94
|
+
* The sequence comes from the read queue (`read-queue.ts` `readStartId`), which
|
|
95
|
+
* stamps a read when it STARTS. That is the only clock that answers the question
|
|
96
|
+
* the guard below asks — "is this answer older than the one already cached?" —
|
|
97
|
+
* because two reads can finish in either order and a finish time therefore says
|
|
98
|
+
* nothing about which tree state is newer.
|
|
99
|
+
*/
|
|
100
|
+
const generations = new Map<string, number>()
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Finish-time fallback, for a write that did not come from a queued read.
|
|
104
|
+
*
|
|
105
|
+
* The queue removes a key's generation when its flight retires, so a direct
|
|
106
|
+
* caller (a local check, or a future code path that patches the cache by hand)
|
|
107
|
+
* keeps the old wall-clock rule. A key never mixes the two regimes in practice:
|
|
108
|
+
* every production write happens inside a queued read, and the fallback exists
|
|
109
|
+
* so the pure-layer behaviour stays compatible.
|
|
110
|
+
*/
|
|
111
|
+
const finishTimes = new Map<string, number>()
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Generation of one read PASS, by snapshot identity.
|
|
115
|
+
*
|
|
116
|
+
* `readGit` writes the same snapshot object under up to two keys: the directory
|
|
117
|
+
* git ran in, and the repository root it settled on. The queue only knows the
|
|
118
|
+
* first of those, so the second write inherits the pass's generation from this
|
|
119
|
+
* map instead of falling back to a finish time. The map is a WeakMap keyed by
|
|
120
|
+
* the snapshot object, so the bookkeeping disappears with the snapshot.
|
|
121
|
+
*/
|
|
122
|
+
const passGenerations = new WeakMap<GitSnapshot, number>()
|
|
123
|
+
|
|
90
124
|
/** The cached read for one (workspace, repository directory), if any. */
|
|
91
125
|
export function readGitSnapshot(key: string): GitSnapshot | undefined {
|
|
92
126
|
const snapshot = snapshots.get(key)
|
|
@@ -107,12 +141,33 @@ export function readGitSnapshot(key: string): GitSnapshot | undefined {
|
|
|
107
141
|
* An answer OLDER than the one already cached is dropped. Two reads of one
|
|
108
142
|
* workspace can overlap when the repo picker changes the directory mid-read (the
|
|
109
143
|
* settled directory is a second key, see the store's `readGit`), and the older
|
|
110
|
-
* walk may finish
|
|
144
|
+
* walk may finish LAST — letting it win would hand the user a change list that
|
|
111
145
|
* predates the one already shown.
|
|
146
|
+
*
|
|
147
|
+
* "Older" is decided by ISSUE order, not by finish order: the read queue stamps
|
|
148
|
+
* each started read and `readStartId` reports it here while the read runs. The
|
|
149
|
+
* previous implementation compared `at` (the finish time) and therefore could
|
|
150
|
+
* never reject the case it documented — the older walk finishing last always
|
|
151
|
+
* carries the LATER timestamp, so it won. Both the pure gate case and a real
|
|
152
|
+
* store-driven case now exercise the issue-order path (see
|
|
153
|
+
* `scripts/check-git-cache.mjs`).
|
|
112
154
|
*/
|
|
113
155
|
export function writeGitSnapshot(key: string, snapshot: GitSnapshot): void {
|
|
114
|
-
const
|
|
115
|
-
|
|
156
|
+
const inherited = passGenerations.get(snapshot)
|
|
157
|
+
const generation = inherited ?? readStartId(key)
|
|
158
|
+
if (generation !== undefined) {
|
|
159
|
+
// One pass, one generation: the settled root key learns it from the first
|
|
160
|
+
// write of the same object.
|
|
161
|
+
passGenerations.set(snapshot, generation)
|
|
162
|
+
const previous = generations.get(key)
|
|
163
|
+
if (previous !== undefined && previous > generation) return
|
|
164
|
+
generations.set(key, generation)
|
|
165
|
+
finishTimes.delete(key)
|
|
166
|
+
} else {
|
|
167
|
+
const previous = finishTimes.get(key)
|
|
168
|
+
if (previous !== undefined && previous > snapshot.at) return
|
|
169
|
+
finishTimes.set(key, snapshot.at)
|
|
170
|
+
}
|
|
116
171
|
snapshots.delete(key)
|
|
117
172
|
snapshots.set(key, snapshot)
|
|
118
173
|
while (snapshots.size > SNAPSHOT_LIMIT) {
|
|
@@ -153,7 +208,9 @@ export function patchCachedUntrackedDirs(key: string, repoRoot: string | undefin
|
|
|
153
208
|
snapshots.set(key, { ...snapshot, untrackedDirs: dirs })
|
|
154
209
|
}
|
|
155
210
|
|
|
156
|
-
/** Test hook: forget every snapshot (the cache gate drives this module alone). */
|
|
211
|
+
/** Test hook: forget every snapshot and its ordering state (the cache gate drives this module alone). */
|
|
157
212
|
export function clearGitSnapshots(): void {
|
|
158
213
|
snapshots.clear()
|
|
214
|
+
generations.clear()
|
|
215
|
+
finishTimes.clear()
|
|
159
216
|
}
|
|
@@ -72,10 +72,35 @@ function withSettleDeadline<T>(read: () => Promise<T>, ms: number): () => Promis
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* When each key's newest read STARTED, as a monotonic sequence.
|
|
77
|
+
*
|
|
78
|
+
* The snapshot cache needs this, and the queue is the only place that knows it:
|
|
79
|
+
* a completed read carries only its FINISH time, and "the older walk finished
|
|
80
|
+
* last" is exactly the case where finish order says the opposite of the truth
|
|
81
|
+
* (see `git-cache.ts` `writeGitSnapshot`). The id is assigned in `start()` —
|
|
82
|
+
* before the read is allowed to run — so two reads of one tree are ordered by
|
|
83
|
+
* when they were ISSUED, which is the order the panel cares about.
|
|
84
|
+
*
|
|
85
|
+
* One module-level counter for every queue instance: ids from `gitReads`,
|
|
86
|
+
* `extrasReads` and `logReads` are then comparable instead of each instance
|
|
87
|
+
* counting from 1 (a shared key would otherwise compare 2 against 2).
|
|
88
|
+
*
|
|
89
|
+
* Entries are removed when their flight retires, so a direct write that did not
|
|
90
|
+
* come from the queue falls back to the legacy wall-clock rule instead of
|
|
91
|
+
* inheriting an unrelated generation.
|
|
92
|
+
*/
|
|
93
|
+
const started = new Map<string, number>()
|
|
94
|
+
let nextReadId = 0
|
|
95
|
+
|
|
96
|
+
/** The start order of the newest read for `key`, while it is in flight. */
|
|
97
|
+
export function readStartId(key: string): number | undefined {
|
|
98
|
+
return started.get(key)
|
|
99
|
+
}
|
|
100
|
+
|
|
75
101
|
export class ReadQueue {
|
|
76
102
|
/** In-flight reads by key (insertion order is irrelevant here). */
|
|
77
103
|
private readonly flights = new Map<string, Flight>()
|
|
78
|
-
private nextId = 0
|
|
79
104
|
|
|
80
105
|
/**
|
|
81
106
|
* @param onChange - called whenever a read starts or settles, so the owner can
|
|
@@ -131,7 +156,10 @@ export class ReadQueue {
|
|
|
131
156
|
|
|
132
157
|
/** Register a flight and run `read`; a synchronous throw becomes a rejection. */
|
|
133
158
|
private start<T>(key: string, read: () => Promise<T>, settleMs: number): Promise<T> {
|
|
134
|
-
const id = ++
|
|
159
|
+
const id = ++nextReadId
|
|
160
|
+
// Recorded BEFORE the read is scheduled: a snapshot written by this read can
|
|
161
|
+
// then ask "which read produced me" and compare issue order (see `started`).
|
|
162
|
+
started.set(key, id)
|
|
135
163
|
// A deferred callback keeps two guarantees: a synchronous throw from `read`
|
|
136
164
|
// is reported as a rejection (callers all await), and the flight is
|
|
137
165
|
// registered BEFORE the read runs, so a second call in the same tick joins
|
|
@@ -142,6 +170,9 @@ export class ReadQueue {
|
|
|
142
170
|
.finally(() => {
|
|
143
171
|
const current = this.flights.get(key)
|
|
144
172
|
if (current !== undefined && current.id === id) this.flights.delete(key)
|
|
173
|
+
// Retire the generation with the flight: a later write that did NOT come
|
|
174
|
+
// from a queued read must not inherit this read's issue order.
|
|
175
|
+
if (started.get(key) === id) started.delete(key)
|
|
145
176
|
this.onChange?.()
|
|
146
177
|
})
|
|
147
178
|
this.flights.set(key, { id, promise })
|