dsh-remote-vs 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +12 -15
- package/README.md +11 -12
- package/THIRD-PARTY-NOTICES.md +193 -0
- package/lib/client.js +7313 -79961
- package/lib/index.js +1529 -964
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +22 -0
- package/lib/types/client/OutlinePanel.d.ts +22 -0
- package/lib/types/client/ProcessesSection.d.ts +19 -0
- package/lib/types/client/RemoteExplorer.d.ts +53 -0
- package/lib/types/client/api.d.ts +42 -3
- package/lib/types/client/blame-model.d.ts +77 -0
- package/lib/types/client/changes/review-state.d.ts +19 -0
- package/lib/types/client/connection.d.ts +16 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/outline-model.d.ts +59 -0
- package/lib/types/client/request-gate.d.ts +110 -0
- package/lib/types/client/scm/DiffView.d.ts +45 -7
- package/lib/types/client/scm/actions.d.ts +43 -4
- package/lib/types/client/store.d.ts +71 -0
- package/lib/types/client/vsc/FindWidget.d.ts +6 -0
- package/lib/types/client/vsc/blame.d.ts +19 -0
- package/lib/types/client/vsc/change-marks.d.ts +16 -6
- package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
- package/lib/types/client/vsc/kit.d.ts +11 -2
- package/lib/types/client/vsc/preview-document.d.ts +46 -0
- package/lib/types/client/vsc/preview-model.d.ts +31 -0
- package/lib/types/client/vsc/preview-services.d.ts +24 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
- package/lib/types/client/vsc/terminal-theme.d.ts +28 -2
- package/lib/types/forward.d.ts +12 -0
- package/lib/types/fs-ops.d.ts +42 -0
- package/lib/types/git-ops.d.ts +18 -0
- package/lib/types/http.d.ts +2 -0
- package/lib/types/keygen.d.ts +9 -0
- package/lib/types/monitor.d.ts +8 -0
- package/lib/types/notices.d.ts +16 -1
- package/lib/types/p2/helper-rpc.d.ts +45 -0
- package/lib/types/processes.d.ts +43 -0
- package/lib/types/protocol.d.ts +34 -0
- package/lib/types/routes.d.ts +2 -0
- package/lib/types/store.d.ts +7 -0
- package/lib/types/terminal.d.ts +8 -0
- package/lib/types/view-settings.d.ts +5 -0
- package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
- package/package.json +3 -1
- package/src/client/CodeEditor.tsx +194 -9
- package/src/client/DirectoryFlow.tsx +16 -0
- package/src/client/DoctorPanel.tsx +70 -7
- package/src/client/EditorPane.tsx +574 -42
- package/src/client/HostsView.tsx +12 -3
- package/src/client/MonitorView.tsx +16 -5
- package/src/client/OutlinePanel.tsx +287 -0
- package/src/client/ProcessesSection.tsx +292 -0
- package/src/client/RemoteDirectoryPicker.tsx +12 -0
- package/src/client/RemoteExplorer.tsx +929 -40
- package/src/client/RemoteRoot.tsx +147 -22
- package/src/client/SearchView.tsx +8 -0
- package/src/client/TerminalSnippets.tsx +83 -8
- package/src/client/api.ts +114 -13
- package/src/client/blame-model.ts +242 -0
- package/src/client/changes/ChangesDock.tsx +188 -6
- package/src/client/changes/changes.css +10 -3
- package/src/client/changes/review-state.ts +34 -0
- package/src/client/connection.ts +29 -0
- package/src/client/downloads.ts +49 -4
- package/src/client/i18n.ts +276 -8
- package/src/client/index.tsx +4 -0
- package/src/client/outline-model.ts +775 -0
- package/src/client/request-gate.ts +221 -0
- package/src/client/scm/CommitPane.tsx +20 -2
- package/src/client/scm/DiffView.tsx +343 -117
- package/src/client/scm/HistoryPanel.tsx +61 -3
- package/src/client/scm/RepoPicker.tsx +1 -1
- package/src/client/scm/ScmPanel.tsx +391 -87
- package/src/client/scm/actions.ts +150 -14
- package/src/client/store.tsx +426 -14
- package/src/client/ui.tsx +4 -0
- package/src/client/vsc/FindWidget.tsx +24 -9
- package/src/client/vsc/blame.ts +147 -0
- package/src/client/vsc/breadcrumb.tsx +91 -3
- package/src/client/vsc/change-marks.ts +93 -44
- package/src/client/vsc/editor-keymap.ts +59 -1
- package/src/client/vsc/file-icons.tsx +17 -3
- package/src/client/vsc/kit.tsx +29 -20
- package/src/client/vsc/preview-document.tsx +323 -0
- package/src/client/vsc/preview-model.ts +216 -0
- package/src/client/vsc/preview-services.ts +118 -0
- package/src/client/vsc/save-shortcut.ts +47 -1
- package/src/client/vsc/terminal-theme.ts +44 -18
- package/src/client/vsc/vsc.css +6509 -5458
- package/src/forward.ts +47 -9
- package/src/fs-ops.ts +124 -4
- package/src/git-ops.ts +54 -3
- package/src/http.ts +35 -4
- package/src/keygen.ts +55 -4
- package/src/monitor.ts +13 -0
- package/src/notices.ts +23 -1
- package/src/p2/helper-rpc.ts +113 -7
- package/src/p2/worlds.ts +14 -1
- package/src/processes.ts +177 -0
- package/src/protocol.ts +37 -0
- package/src/routes.ts +330 -43
- package/src/sftp.ts +51 -14
- package/src/store.ts +10 -0
- package/src/terminal.ts +73 -26
- package/src/view-settings.ts +50 -10
- package/lib/types/client/Dialog.d.ts +0 -14
- package/src/client/Dialog.tsx +0 -76
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure parsing/formatting for `git blame` (and the shared vocabulary the
|
|
3
|
+
* editor UI uses for a line's provenance). No CodeMirror and no DOM here, so
|
|
4
|
+
* the gate can feed it real porcelain output.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { GitCommit } from '../protocol.ts'
|
|
8
|
+
import { unquoteGitPath } from '../git-format.ts'
|
|
9
|
+
|
|
10
|
+
/** One blamed line: 1-based final line number plus the commit that owns it. */
|
|
11
|
+
export interface BlameLine {
|
|
12
|
+
line: number
|
|
13
|
+
hash: string
|
|
14
|
+
author: string
|
|
15
|
+
email: string
|
|
16
|
+
/** Author timestamp, seconds since the epoch (git's `author-time`). */
|
|
17
|
+
time: number
|
|
18
|
+
summary: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A run of consecutive lines owned by the same commit. */
|
|
22
|
+
export interface BlameRun {
|
|
23
|
+
from: number
|
|
24
|
+
to: number
|
|
25
|
+
hash: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** One `--follow` file-history row, plus the name the file had in that commit. */
|
|
29
|
+
export interface FileHistoryCommit extends GitCommit {
|
|
30
|
+
/** Path to show/diff for THIS commit (old name before a rename). */
|
|
31
|
+
path: string
|
|
32
|
+
/** Rename source when this commit renamed the file. */
|
|
33
|
+
origPath?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const HEADER = /^([0-9a-f]{40,64}) \d+ (\d+)(?: \d+)?$/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parse `git blame --line-porcelain`.
|
|
40
|
+
*
|
|
41
|
+
* `--line-porcelain` repeats the commit header and metadata for every line (no
|
|
42
|
+
* previous-commit grouping), which keeps this parser stateless: a header starts
|
|
43
|
+
* a record, the metadata lines fill it, and the tab-prefixed content line ends
|
|
44
|
+
* it. Lines that do not match the shape are ignored rather than aborting the
|
|
45
|
+
* whole read — a partially understood blame is still useful.
|
|
46
|
+
*/
|
|
47
|
+
export function parseBlamePorcelain(stdout: string): BlameLine[] {
|
|
48
|
+
const rows: BlameLine[] = []
|
|
49
|
+
let current: {
|
|
50
|
+
hash: string
|
|
51
|
+
line: number
|
|
52
|
+
author?: string
|
|
53
|
+
email?: string
|
|
54
|
+
time?: number
|
|
55
|
+
summary?: string
|
|
56
|
+
} | undefined
|
|
57
|
+
for (const raw of stdout.split('\n')) {
|
|
58
|
+
const line = raw.endsWith('\r') ? raw.slice(0, -1) : raw
|
|
59
|
+
const header = HEADER.exec(line)
|
|
60
|
+
if (header !== null) {
|
|
61
|
+
current = { hash: header[1] as string, line: Number(header[2]) }
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
if (current === undefined) continue
|
|
65
|
+
if (line.startsWith('\t')) {
|
|
66
|
+
rows.push({
|
|
67
|
+
line: current.line,
|
|
68
|
+
hash: current.hash,
|
|
69
|
+
author: current.author ?? '',
|
|
70
|
+
email: current.email ?? '',
|
|
71
|
+
time: current.time ?? 0,
|
|
72
|
+
summary: current.summary ?? '',
|
|
73
|
+
})
|
|
74
|
+
current = undefined
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
const space = line.indexOf(' ')
|
|
78
|
+
if (space < 0) continue
|
|
79
|
+
const key = line.slice(0, space)
|
|
80
|
+
const value = line.slice(space + 1)
|
|
81
|
+
if (key === 'author') current.author = value
|
|
82
|
+
else if (key === 'author-mail') current.email = value.replace(/^<|>$/g, '')
|
|
83
|
+
else if (key === 'author-time') current.time = Number(value) || 0
|
|
84
|
+
else if (key === 'summary') current.summary = value
|
|
85
|
+
}
|
|
86
|
+
return rows
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Group consecutive lines of one commit; non-adjacent runs stay separate. */
|
|
90
|
+
export function blameRuns(rows: readonly BlameLine[]): BlameRun[] {
|
|
91
|
+
const runs: BlameRun[] = []
|
|
92
|
+
let previous: BlameLine | undefined
|
|
93
|
+
for (const row of rows) {
|
|
94
|
+
if (previous !== undefined && previous.hash === row.hash && previous.line + 1 === row.line) {
|
|
95
|
+
const run = runs[runs.length - 1]
|
|
96
|
+
if (run !== undefined) run.to = row.line
|
|
97
|
+
} else {
|
|
98
|
+
runs.push({ from: row.line, to: row.line, hash: row.hash })
|
|
99
|
+
}
|
|
100
|
+
previous = row
|
|
101
|
+
}
|
|
102
|
+
return runs
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Short author name for the narrow blame gutter. */
|
|
106
|
+
export function shortAuthor(author: string): string {
|
|
107
|
+
const name = author.trim()
|
|
108
|
+
if (name === '') return '?'
|
|
109
|
+
return name.length <= 10 ? name : `${name.slice(0, 9)}…`
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Relative age labels, deliberately compact (`now`, `5m`, `3h`, `2d`, `4w`,
|
|
114
|
+
* `3mo`, `2y`) because this text lives in a gutter.
|
|
115
|
+
*/
|
|
116
|
+
export function relativeBlameTime(timeSeconds: number, nowSeconds: number = Math.floor(Date.now() / 1000)): string {
|
|
117
|
+
if (!Number.isFinite(timeSeconds) || timeSeconds <= 0) return '?'
|
|
118
|
+
const diff = Math.max(0, nowSeconds - timeSeconds)
|
|
119
|
+
if (diff < 60) return 'now'
|
|
120
|
+
if (diff < 3600) return `${Math.floor(diff / 60)}m`
|
|
121
|
+
if (diff < 86_400) return `${Math.floor(diff / 3600)}h`
|
|
122
|
+
if (diff < 7 * 86_400) return `${Math.floor(diff / 86_400)}d`
|
|
123
|
+
if (diff < 30 * 86_400) return `${Math.floor(diff / (7 * 86_400))}w`
|
|
124
|
+
if (diff < 365 * 86_400) return `${Math.floor(diff / (30 * 86_400))}mo`
|
|
125
|
+
return `${Math.floor(diff / (365 * 86_400))}y`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** One-line gutter label: author initials/name plus relative age. */
|
|
129
|
+
export function blameLabel(row: BlameLine, nowSeconds: number = Math.floor(Date.now() / 1000)): string {
|
|
130
|
+
return `${shortAuthor(row.author)} · ${relativeBlameTime(row.time, nowSeconds)}`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Hover text: full attribution. The browser renders `title` as plain text, so
|
|
135
|
+
* no markup is needed (and no translator dependency leaks into the model).
|
|
136
|
+
*/
|
|
137
|
+
export function blameTitle(row: BlameLine): string {
|
|
138
|
+
const when = row.time > 0 ? new Date(row.time * 1000).toLocaleString() : 'unknown date'
|
|
139
|
+
const email = row.email === '' ? '' : `\n${row.email}`
|
|
140
|
+
return `${row.author || 'unknown author'}${email}\n${when}\n${row.hash}\n${row.summary}`.trim()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** False for git's all-zero "not committed yet" pseudo-commit. */
|
|
144
|
+
export function isCommittedBlame(hash: string): boolean {
|
|
145
|
+
return !/^0{40,64}$/.test(hash)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The next `-L` window to request, or undefined when the viewport is covered.
|
|
150
|
+
*
|
|
151
|
+
* Pure and exported so the gate can prove the "3000-line file only asks for
|
|
152
|
+
* the visible window" requirement without a browser. `overscan` keeps a small
|
|
153
|
+
* buffer above/below so a normal scroll does not immediately need a new call.
|
|
154
|
+
*/
|
|
155
|
+
export function planBlameWindow(
|
|
156
|
+
first: number,
|
|
157
|
+
last: number,
|
|
158
|
+
total: number,
|
|
159
|
+
covered: ReadonlySet<number>,
|
|
160
|
+
overscan = 40,
|
|
161
|
+
): { from: number; to: number } | undefined {
|
|
162
|
+
if (!Number.isFinite(first) || !Number.isFinite(last) || !Number.isFinite(total) || total < 1) return undefined
|
|
163
|
+
const from = Math.max(1, Math.min(first, total) - Math.max(0, Math.floor(overscan)))
|
|
164
|
+
const to = Math.min(total, Math.max(last, first) + Math.max(0, Math.floor(overscan)))
|
|
165
|
+
if (to < from) return undefined
|
|
166
|
+
for (let line = from; line <= to; line += 1) {
|
|
167
|
+
if (!covered.has(line)) return { from, to }
|
|
168
|
+
}
|
|
169
|
+
return undefined
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface NameStatusRow {
|
|
173
|
+
path: string
|
|
174
|
+
origPath?: string
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Parse one `--name-status` row; C/R rows carry an old path as well. */
|
|
178
|
+
function parseNameStatusRow(raw: string): NameStatusRow | undefined {
|
|
179
|
+
const fields = raw.split('\t')
|
|
180
|
+
if (fields.length < 2) return undefined
|
|
181
|
+
const status = fields[0] as string
|
|
182
|
+
const first = fields[1] as string
|
|
183
|
+
const second = fields[2] as string | undefined
|
|
184
|
+
const path = unquoteGitPath(second ?? first)
|
|
185
|
+
if (path === '') return undefined
|
|
186
|
+
const origPath = second === undefined ? undefined : unquoteGitPath(first)
|
|
187
|
+
return status.startsWith('R') || status.startsWith('C')
|
|
188
|
+
? { path, ...(origPath === undefined ? {} : { origPath }) }
|
|
189
|
+
: { path }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Parse `git log --follow --name-status -M` output into per-commit rows.
|
|
194
|
+
*
|
|
195
|
+
* `--follow` reports the file under its name AT THAT COMMIT. Starting from the
|
|
196
|
+
* current name and walking newest→oldest, each rename row supplies the next
|
|
197
|
+
* (older) name, so a click on an old history row opens the right path instead
|
|
198
|
+
* of an empty diff for the current name.
|
|
199
|
+
*/
|
|
200
|
+
export function parseFileHistory(stdout: string, currentPath: string): FileHistoryCommit[] {
|
|
201
|
+
const commits: FileHistoryCommit[] = []
|
|
202
|
+
let wanted = currentPath
|
|
203
|
+
for (const block of stdout.split('\0')) {
|
|
204
|
+
const lines = block.replace(/^\r?\n/, '').split(/\r?\n/).filter(line => line.trim() !== '')
|
|
205
|
+
if (lines.length === 0) continue
|
|
206
|
+
const [hash, parents, author, email, date, refs, subject] = (lines[0] as string).split('\x1f') as [
|
|
207
|
+
string, string, string, string, string, string, string,
|
|
208
|
+
]
|
|
209
|
+
if (!/^[0-9a-f]{4,64}$/.test((hash ?? '').trim())) continue
|
|
210
|
+
const statuses = lines.slice(1).flatMap(line => {
|
|
211
|
+
const row = parseNameStatusRow(line)
|
|
212
|
+
return row === undefined ? [] : [row]
|
|
213
|
+
})
|
|
214
|
+
let path = wanted
|
|
215
|
+
let origPath: string | undefined
|
|
216
|
+
const rename = statuses.find(row => row.path === wanted && row.origPath !== undefined)
|
|
217
|
+
if (rename !== undefined) {
|
|
218
|
+
path = wanted
|
|
219
|
+
origPath = rename.origPath
|
|
220
|
+
wanted = rename.origPath as string
|
|
221
|
+
} else if (statuses.some(row => row.path === wanted)) {
|
|
222
|
+
path = wanted
|
|
223
|
+
} else if (statuses.length === 1) {
|
|
224
|
+
// A path-limited log normally has one status row; trust it when the
|
|
225
|
+
// rename chain did not line up (e.g. a merge or an unusual rename).
|
|
226
|
+
path = (statuses[0] as NameStatusRow).path
|
|
227
|
+
origPath = (statuses[0] as NameStatusRow).origPath
|
|
228
|
+
}
|
|
229
|
+
commits.push({
|
|
230
|
+
hash: (hash as string).trim(),
|
|
231
|
+
parents: (parents ?? '').trim() === '' ? [] : (parents as string).trim().split(' '),
|
|
232
|
+
author: (author ?? '').trim(),
|
|
233
|
+
email: (email ?? '').trim(),
|
|
234
|
+
date: Number(date) || 0,
|
|
235
|
+
refs: (refs ?? '').split(',').map(item => item.trim()).filter(item => item !== ''),
|
|
236
|
+
subject: (subject ?? '').trim(),
|
|
237
|
+
path,
|
|
238
|
+
...(origPath === undefined ? {} : { origPath }),
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
return commits
|
|
242
|
+
}
|
|
@@ -45,8 +45,10 @@ import type { RemoteChangedFile, RemoteChangesSummary } from '../../protocol.ts'
|
|
|
45
45
|
import { EMPTY_CHANGE_SET, changeSetFromHunks, type ChangeSet } from './model.ts'
|
|
46
46
|
import {
|
|
47
47
|
isReviewed,
|
|
48
|
+
nextUnreviewed,
|
|
48
49
|
parseReviewed,
|
|
49
50
|
pruneReviewed,
|
|
51
|
+
reviewKeyOf,
|
|
50
52
|
reviewedCount,
|
|
51
53
|
serializeReviewed,
|
|
52
54
|
setAllReviewed,
|
|
@@ -60,6 +62,41 @@ import './changes.css'
|
|
|
60
62
|
/** How often an open panel re-reads the ledger (the host refreshes it per turn). */
|
|
61
63
|
const POLL_MS = 3000
|
|
62
64
|
|
|
65
|
+
/**
|
|
66
|
+
* While the list is FOLDED, read the ledger only every Nth poll (15 s).
|
|
67
|
+
*
|
|
68
|
+
* The folded panel still shows its header (file count, +/− totals, the
|
|
69
|
+
* "pending" badge), so the poll cannot simply stop: the header would then keep
|
|
70
|
+
* describing an older turn. A fifth of the cadence keeps it honest without
|
|
71
|
+
* paying a loopback POST (and, through the host's ledger `touch`, a tracked
|
|
72
|
+
* git scan every 30 s) four times a second-old counter does not need.
|
|
73
|
+
*
|
|
74
|
+
* A HIDDEN page is different and skips the tick entirely: nothing on screen can
|
|
75
|
+
* change, and `visibilitychange` catches up at once when it is shown again.
|
|
76
|
+
* Manual ⟳ (`load(true)`) and the first read are never gated.
|
|
77
|
+
*/
|
|
78
|
+
const FOLDED_POLL_SKIP = 5
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* While the panel renders NOTHING (`!visible` below and no error — no summary
|
|
82
|
+
* yet, or none of files/pending/unavailable), patrol the ledger only every Nth
|
|
83
|
+
* poll (60 s).
|
|
84
|
+
*
|
|
85
|
+
* It cannot simply stop: the panel's own visibility is DERIVED from the answer it
|
|
86
|
+
* polls for, so a stopped poll would never discover the first change of the next
|
|
87
|
+
* turn and the dock would never come back. The cadence is cut because a parked
|
|
88
|
+
* dock (another view in the sidebar, a session with no changes) must not pay a
|
|
89
|
+
* loopback POST plus the host's ledger touch every 15 s, while 60 s is still fast
|
|
90
|
+
* enough to surface new work without a manual refresh. The first read, the manual
|
|
91
|
+
* ⟳ and the fold/unfold re-read are not gated at all.
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* The dock is not rendered at all when there is nothing to show, but it must
|
|
95
|
+
* still notice the next change: one read every 30 s is the compromise between
|
|
96
|
+
* "a new change surfaces promptly" and "a hidden panel costs nothing".
|
|
97
|
+
*/
|
|
98
|
+
const INVISIBLE_POLL_SKIP = 10
|
|
99
|
+
|
|
63
100
|
/**
|
|
64
101
|
* Where the review marks are remembered, per session.
|
|
65
102
|
*
|
|
@@ -144,7 +181,23 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
144
181
|
const [busy, setBusy] = useState<string | undefined>(undefined)
|
|
145
182
|
/** This session's local review marks (see `review-state.ts`). */
|
|
146
183
|
const [reviewed, setReviewed] = useState<Record<string, 1>>(() => loadReviewed(sessionId))
|
|
184
|
+
/**
|
|
185
|
+
* 「只看未审阅」的过滤开关(纯组件状态)。
|
|
186
|
+
*
|
|
187
|
+
* It is a reading posture for THIS pass ("I only care about what is left"),
|
|
188
|
+
* not a fact about the remote tree, so it is neither persisted nor sent: a
|
|
189
|
+
* freshly mounted panel starts by showing the whole list.
|
|
190
|
+
*/
|
|
191
|
+
const [onlyUnreviewed, setOnlyUnreviewed] = useState(false)
|
|
192
|
+
/** 审阅游标:最近一次打开/跳到的行(`reviewKeyOf` 的键)。 */
|
|
193
|
+
const [cursorKey, setCursorKey] = useState<string | undefined>(undefined)
|
|
194
|
+
/** 行元素(键同游标),供「跳到下一个未审阅」把目标滚进视野。 */
|
|
195
|
+
const rowRefs = useRef(new Map<string, HTMLDivElement>())
|
|
147
196
|
const alive = useRef(true)
|
|
197
|
+
// Mirrors "the panel renders something" for the poll tick: adding that as an
|
|
198
|
+
// effect dependency would rebuild the interval (and pay a re-read) every time
|
|
199
|
+
// the panel appears or disappears, which is not what the cadence is about.
|
|
200
|
+
const visibleRef = useRef(false)
|
|
148
201
|
const currentSession = useRef(sessionId)
|
|
149
202
|
currentSession.current = sessionId
|
|
150
203
|
const rowMenu = useContextMenu()
|
|
@@ -184,18 +237,43 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
184
237
|
|
|
185
238
|
useEffect(() => {
|
|
186
239
|
alive.current = true
|
|
240
|
+
// The first read (and the manual ⟳, which calls `load(true)` directly) is
|
|
241
|
+
// deliberately NOT gated: it is what paints the panel after a session
|
|
242
|
+
// switch or a cold page.
|
|
187
243
|
void load()
|
|
188
|
-
|
|
244
|
+
let ticks = 0
|
|
245
|
+
const timer = window.setInterval(() => {
|
|
246
|
+
// A background tab costs a loopback POST every 3 s without any possible
|
|
247
|
+
// visible change; skip the tick outright. The listener below is what makes
|
|
248
|
+
// the panel catch up the moment it is shown again.
|
|
249
|
+
if (document.hidden) return
|
|
250
|
+
ticks += 1
|
|
251
|
+
// An unrendered panel is slower than a folded one: it still has to look for
|
|
252
|
+
// the next turn's changes (see INVISIBLE_POLL_SKIP), just not at the folded
|
|
253
|
+
// cadence. The first read, the fold re-read and the manual ⟳ stay outside
|
|
254
|
+
// this tick.
|
|
255
|
+
const skip = visibleRef.current ? (collapsed ? FOLDED_POLL_SKIP : 1) : INVISIBLE_POLL_SKIP
|
|
256
|
+
if (skip > 1 && ticks % skip !== 0) return
|
|
257
|
+
void load()
|
|
258
|
+
}, POLL_MS)
|
|
259
|
+
// Shown again, or unfolded: read at once instead of waiting for the next
|
|
260
|
+
// tick (a folded panel may be up to 15 s stale by design). `collapsed` is a
|
|
261
|
+
// dependency, so folding/unfolding also re-runs this effect and reloads.
|
|
262
|
+
const wake = (): void => { if (!document.hidden) void load() }
|
|
263
|
+
document.addEventListener('visibilitychange', wake)
|
|
189
264
|
return () => {
|
|
190
265
|
alive.current = false
|
|
191
266
|
window.clearInterval(timer)
|
|
267
|
+
document.removeEventListener('visibilitychange', wake)
|
|
192
268
|
}
|
|
193
|
-
}, [load])
|
|
269
|
+
}, [load, collapsed])
|
|
194
270
|
|
|
195
|
-
// A different conversation has different marks
|
|
196
|
-
// one session's ✓ onto another's
|
|
271
|
+
// A different conversation has different marks (and its own place in the
|
|
272
|
+
// list): reload instead of carrying one session's ✓ / cursor onto another's
|
|
273
|
+
// files.
|
|
197
274
|
useEffect(() => {
|
|
198
275
|
setReviewed(loadReviewed(sessionId))
|
|
276
|
+
setCursorKey(undefined)
|
|
199
277
|
}, [sessionId])
|
|
200
278
|
|
|
201
279
|
/**
|
|
@@ -303,6 +381,10 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
303
381
|
/** Open one listed file in the remote editor with its change marks. */
|
|
304
382
|
const openChanged = useCallback(async (file: RemoteChangedFile): Promise<void> => {
|
|
305
383
|
if (sessionId === undefined || summary === null) return
|
|
384
|
+
// Opening a row also moves the review cursor, so 「跳到下一个未审阅」continues
|
|
385
|
+
// from whatever the user just looked at (a click, a menu entry or a jump)
|
|
386
|
+
// instead of from wherever the last jump happened to stop.
|
|
387
|
+
setCursorKey(reviewKeyOf(file))
|
|
306
388
|
setBusy(file.path)
|
|
307
389
|
try {
|
|
308
390
|
const diff = await api.changes.diff(sessionId, file.path, repoSubdirOf())
|
|
@@ -392,14 +474,51 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
392
474
|
// Drop marks for rows that are gone (or whose counts changed). Without this a
|
|
393
475
|
// path that leaves and comes back would show a ✓ nobody gave it.
|
|
394
476
|
useEffect(() => {
|
|
477
|
+
// `files` is EMPTY until the first summary lands — that is "not loaded yet",
|
|
478
|
+
// not "the session changed nothing". Pruning on that frame wiped the marks
|
|
479
|
+
// just restored from localStorage (and wrote the empty map back).
|
|
480
|
+
if (summary === null) return
|
|
395
481
|
setReviewed(previous => {
|
|
396
482
|
const next = pruneReviewed(files, previous)
|
|
397
483
|
// A prune only ever removes entries, so equal length means "identical".
|
|
398
484
|
return Object.keys(next).length === Object.keys(previous).length ? previous : next
|
|
399
485
|
})
|
|
400
|
-
}, [files])
|
|
486
|
+
}, [files, summary])
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Bring the cursor's row into view.
|
|
490
|
+
*
|
|
491
|
+
* The jump can be pressed while the list is FOLDED, where the row does not
|
|
492
|
+
* exist yet in that commit: the effect runs after the unfold has landed, so
|
|
493
|
+
* the ref map has the row by then. `block: 'nearest'` means an already visible
|
|
494
|
+
* row does not move at all, which is what makes a plain row click (which also
|
|
495
|
+
* moves the cursor) a no-op here. Optional call: a DOM without `scrollIntoView`
|
|
496
|
+
* (tests) must cost only the scroll.
|
|
497
|
+
*/
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
if (cursorKey === undefined || collapsed) return
|
|
500
|
+
rowRefs.current.get(cursorKey)?.scrollIntoView?.({ block: 'nearest' })
|
|
501
|
+
}, [cursorKey, collapsed])
|
|
401
502
|
|
|
402
503
|
const done = reviewedCount(files, reviewed)
|
|
504
|
+
/**
|
|
505
|
+
* Rows the body renders: the whole list, or only the rows that are still
|
|
506
|
+
* unreviewed. The header's counters keep describing the whole list — the
|
|
507
|
+
* filter is a view, not a recount.
|
|
508
|
+
*/
|
|
509
|
+
const listed = useMemo(
|
|
510
|
+
() => (onlyUnreviewed ? files.filter(file => !isReviewed(file, reviewed)) : files),
|
|
511
|
+
[files, onlyUnreviewed, reviewed],
|
|
512
|
+
)
|
|
513
|
+
/**
|
|
514
|
+
* What 「跳到下一个未审阅」would open; `undefined` both when the list is empty
|
|
515
|
+
* and when every row is reviewed, which is exactly the button's disabled
|
|
516
|
+
* condition. `fromKey` is the cursor, so a second press continues the walk.
|
|
517
|
+
*/
|
|
518
|
+
const nextFile = useMemo(
|
|
519
|
+
() => nextUnreviewed(files, reviewed, cursorKey),
|
|
520
|
+
[files, reviewed, cursorKey],
|
|
521
|
+
)
|
|
403
522
|
|
|
404
523
|
const openRowMenu = useCallback((event: React.MouseEvent, file: RemoteChangedFile): void => {
|
|
405
524
|
event.preventDefault()
|
|
@@ -429,11 +548,30 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
429
548
|
])
|
|
430
549
|
}, [files, reviewMenu, t])
|
|
431
550
|
|
|
551
|
+
/**
|
|
552
|
+
* 「跳到下一个未审阅」:把下一行滚进视野并打开它。
|
|
553
|
+
*
|
|
554
|
+
* 这一跳不标记任何东西:打开就是它的全部动作,看过没有由用户按 ✓ 决定。折叠着
|
|
555
|
+
* 的列表先展开,否则只是换了个看不见的游标。打开走 `openChanged`(改动内容、
|
|
556
|
+
* 绑定解析与撤销来源都在那一条路上),它同时把游标移到目标行,所以连按两次是
|
|
557
|
+
* 继续往下走,而不是原地打转。
|
|
558
|
+
*/
|
|
559
|
+
const jumpToNextUnreviewed = useCallback((): void => {
|
|
560
|
+
if (nextFile === undefined) return
|
|
561
|
+
setCollapsed(false)
|
|
562
|
+
void openChanged(nextFile)
|
|
563
|
+
}, [nextFile, openChanged])
|
|
564
|
+
|
|
432
565
|
const activeTab = explorer.tabs.find(candidate => candidate.id === explorer.activeTabId)
|
|
433
566
|
const visible = useMemo(() => {
|
|
434
567
|
if (summary === null) return false
|
|
435
568
|
return files.length > 0 || summary.pending === true || summary.unavailable !== undefined
|
|
436
569
|
}, [files.length, summary])
|
|
570
|
+
// Published for the tick (see `visibleRef`): read at tick time, not captured at
|
|
571
|
+
// effect time, so the cadence follows the panel without restarting the timer.
|
|
572
|
+
// "Rendered" mirrors the early return below: an error is shown even without a
|
|
573
|
+
// summary, so a failed panel keeps the near cadence (its ⟳ is on screen).
|
|
574
|
+
visibleRef.current = visible || error !== undefined
|
|
437
575
|
|
|
438
576
|
if (sessionId === undefined || sessionId === '') return null
|
|
439
577
|
if (!visible && error === undefined) return null
|
|
@@ -470,6 +608,38 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
470
608
|
{t('changes.reviewCount').replace('{done}', String(done)).replace('{total}', String(files.length))}
|
|
471
609
|
</button>
|
|
472
610
|
)}
|
|
611
|
+
{files.length > 0 && (
|
|
612
|
+
<>
|
|
613
|
+
{/*
|
|
614
|
+
「只看未审阅」: the header's small-chip style (`rvs-changes-reviewed`)
|
|
615
|
+
is the one text button this panel's palette already carries. Its
|
|
616
|
+
"on" state is painted from the same two variables it reads, since
|
|
617
|
+
that chip rule only describes the idle look.
|
|
618
|
+
*/}
|
|
619
|
+
<button
|
|
620
|
+
type="button"
|
|
621
|
+
className="rvs-changes-reviewed"
|
|
622
|
+
aria-pressed={onlyUnreviewed}
|
|
623
|
+
title={t('changes.onlyUnreviewed')}
|
|
624
|
+
onClick={() => { setOnlyUnreviewed(value => !value) }}
|
|
625
|
+
style={onlyUnreviewed ? { backgroundColor: 'var(--rvs-chg-hover)', color: 'var(--rvs-chg-fg)' } : undefined}
|
|
626
|
+
>
|
|
627
|
+
{t('changes.onlyUnreviewed')}
|
|
628
|
+
</button>
|
|
629
|
+
{/* 跳到下一个未审阅: one glyph (the words live in the tooltip), disabled
|
|
630
|
+
when nothing is left. */}
|
|
631
|
+
<span className="rvs-changes-nav">
|
|
632
|
+
<button
|
|
633
|
+
type="button"
|
|
634
|
+
title={nextFile === undefined ? t('changes.allReviewed') : t('changes.nextUnreviewed')}
|
|
635
|
+
aria-label={t('changes.nextUnreviewed')}
|
|
636
|
+
disabled={nextFile === undefined}
|
|
637
|
+
onClick={jumpToNextUnreviewed}
|
|
638
|
+
style={nextFile === undefined ? { cursor: 'default', opacity: 0.4 } : undefined}
|
|
639
|
+
>↓</button>
|
|
640
|
+
</span>
|
|
641
|
+
</>
|
|
642
|
+
)}
|
|
473
643
|
{summary?.pending === true && <span className="rvs-changes-pending">{t('changes.pending')}</span>}
|
|
474
644
|
<span className="rvs-changes-spacer" />
|
|
475
645
|
{stale && <span className="rvs-changes-stale" title={t('changes.staleHint')}>{t('changes.stale')}</span>}
|
|
@@ -489,12 +659,24 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
489
659
|
{files.length === 0 && summary?.unavailable === undefined && summary?.pending !== true && (
|
|
490
660
|
<div className="rvs-changes-note">{t('changes.empty')}</div>
|
|
491
661
|
)}
|
|
492
|
-
{
|
|
662
|
+
{/*
|
|
663
|
+
The filter can hide every row; an empty body must then say WHY instead
|
|
664
|
+
of looking like a broken list.
|
|
665
|
+
*/}
|
|
666
|
+
{files.length > 0 && listed.length === 0 && (
|
|
667
|
+
<div className="rvs-changes-note">{t('changes.allReviewed')}</div>
|
|
668
|
+
)}
|
|
669
|
+
{listed.map(file => {
|
|
493
670
|
const { dir, name } = splitDisplay(file.display)
|
|
494
671
|
const marked = isReviewed(file, reviewed)
|
|
672
|
+
const key = reviewKeyOf(file)
|
|
495
673
|
return (
|
|
496
674
|
<div
|
|
497
675
|
key={file.path}
|
|
676
|
+
ref={(node) => {
|
|
677
|
+
if (node === null) rowRefs.current.delete(key)
|
|
678
|
+
else rowRefs.current.set(key, node)
|
|
679
|
+
}}
|
|
498
680
|
className={`rvs-chg-row${busy === file.path ? ' rvs-chg-loading' : ''}`}
|
|
499
681
|
data-reviewed={marked ? '1' : '0'}
|
|
500
682
|
>
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
--rvs-chg-hover: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .14));
|
|
17
17
|
--rvs-chg-surface: var(--dsw-alias-bg-layer-2, rgba(127, 127, 127, .07));
|
|
18
18
|
--rvs-chg-add: #4ec9b0;
|
|
19
|
-
|
|
19
|
+
/* #f14c4c on the dark surface is 3.90:1 / 3.79:1 — below AA for 11px counts.
|
|
20
|
+
One step lighter in the same hue family (6.18 / 6.02) without touching the
|
|
21
|
+
light value, which is already a GitHub-Light red. */
|
|
22
|
+
--rvs-chg-del: #ff8b8b;
|
|
20
23
|
--rvs-chg-mod: #e2b714;
|
|
21
24
|
--rvs-chg-info: #58a6ff;
|
|
22
25
|
|
|
@@ -313,9 +316,13 @@ body:not([data-ds-dark-theme]) .rvs-changes {
|
|
|
313
316
|
--rvs-chg-border: var(--dsw-alias-border-l1, rgba(31, 35, 40, .16));
|
|
314
317
|
--rvs-chg-hover: var(--dsw-alias-interactive-bg-hover, rgba(31, 35, 40, .07));
|
|
315
318
|
--rvs-chg-surface: var(--dsw-alias-bg-layer-2, rgba(31, 35, 40, .04));
|
|
316
|
-
|
|
319
|
+
/* Deeper than GitHub's #1a7f37: the skin's cream surface eats ~0.8:1 off it
|
|
320
|
+
(4.50:1 there, 5.08 on white), so the same hue one step down (5.79 / 6.53).
|
|
321
|
+
The amber "M" has the same island problem (4.32 vs 4.87) and takes the same
|
|
322
|
+
step (6.05 / 6.82). */
|
|
323
|
+
--rvs-chg-add: #146c2e;
|
|
317
324
|
--rvs-chg-del: #cf222e;
|
|
318
|
-
--rvs-chg-mod: #
|
|
325
|
+
--rvs-chg-mod: #7d5200;
|
|
319
326
|
--rvs-chg-info: #0969da;
|
|
320
327
|
}
|
|
321
328
|
|
|
@@ -57,6 +57,40 @@ export function reviewedCount(files: readonly ReviewSubject[], reviewed: Reviewe
|
|
|
57
57
|
return count
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* 从 `fromKey` 之后找第一个未审阅的行 —— 面板头部「跳到下一个未审阅」的取数。
|
|
62
|
+
*
|
|
63
|
+
* 顺序就是列表本身的顺序:从游标位置往**后**线性找,走到末尾回绕到开头,最多看
|
|
64
|
+
* 一圈,因此不会重复、也不会越界。跳过已审阅的行是它的职责;它本身不改任何状态,
|
|
65
|
+
* 也不负责打开文件(那是面板的事)。
|
|
66
|
+
*
|
|
67
|
+
* `fromKey` 缺失、或已经不在列表里(行被删了、文件又改了一次导致计数进键变化)时
|
|
68
|
+
* 从第一行开始:起点未知只会让这一跳从头枚举,绝不会漏掉任何一行。
|
|
69
|
+
*
|
|
70
|
+
* 返回值与入参同一行类型(`T extends ReviewSubject`),所以面板拿回的是它自己的
|
|
71
|
+
* `RemoteChangedFile`,不需要在调用处断言一次。
|
|
72
|
+
*
|
|
73
|
+
* @param files - 面板当前的行,数组顺序即导航顺序。
|
|
74
|
+
* @param reviewed - 已审阅集合(键见 {@link reviewKeyOf})。
|
|
75
|
+
* @param fromKey - 当前游标(`reviewKeyOf` 给出的键);空/未知表示从头开始。
|
|
76
|
+
* @returns 第一个未审阅的行;空列表或全部已审阅时 `undefined`。
|
|
77
|
+
*/
|
|
78
|
+
export function nextUnreviewed<T extends ReviewSubject>(
|
|
79
|
+
files: readonly T[],
|
|
80
|
+
reviewed: ReviewedMap,
|
|
81
|
+
fromKey?: string,
|
|
82
|
+
): T | undefined {
|
|
83
|
+
if (files.length === 0) return undefined
|
|
84
|
+
const current = fromKey === undefined || fromKey === '' ? -1 : files.findIndex(file => reviewKeyOf(file) === fromKey)
|
|
85
|
+
// One past the row the cursor is on; an unknown start means "from the top".
|
|
86
|
+
const start = current + 1
|
|
87
|
+
for (let offset = 0; offset < files.length; offset += 1) {
|
|
88
|
+
const file = files[(start + offset) % files.length]
|
|
89
|
+
if (!isReviewed(file, reviewed)) return file
|
|
90
|
+
}
|
|
91
|
+
return undefined
|
|
92
|
+
}
|
|
93
|
+
|
|
60
94
|
/** 切换一行的标记,返回新表(输入不被修改)。 */
|
|
61
95
|
export function toggleReviewed(files: readonly ReviewSubject[], reviewed: ReviewedMap, file: ReviewSubject): Record<string, 1> {
|
|
62
96
|
const key = reviewKeyOf(file)
|
package/src/client/connection.ts
CHANGED
|
@@ -206,6 +206,35 @@ export function markConnectionProbeOk(alias: string): void {
|
|
|
206
206
|
probes.set(alias, Date.now())
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Forget the cached record of every alias the hosts table no longer holds.
|
|
211
|
+
*
|
|
212
|
+
* `views`/`probes` are module-level maps keyed by alias and nothing ever removed
|
|
213
|
+
* an entry: deleting or renaming a host in Settings left its view (and its
|
|
214
|
+
* explicit-retry probe) in page memory for the life of the tab. Callers pass the
|
|
215
|
+
* aliases the hosts table currently holds; everything else is stale.
|
|
216
|
+
*
|
|
217
|
+
* Only cache entries are removed — no connection state is transitioned. When the
|
|
218
|
+
* ACTIVE alias is pruned its snapshot becomes `undefined` ("no evidence yet",
|
|
219
|
+
* which every reader already treats as "not proven down") and subscribers are
|
|
220
|
+
* woken. `activeAlias` itself is deliberately KEPT: `setActiveConnectionAlias`
|
|
221
|
+
* early-returns on an unchanged alias, so clearing it here would leave a
|
|
222
|
+
* re-added host's chip blank until the user switched workspaces.
|
|
223
|
+
*/
|
|
224
|
+
export function pruneConnections(aliases: Iterable<string>): void {
|
|
225
|
+
const keep = new Set(aliases)
|
|
226
|
+
let dropped = false
|
|
227
|
+
for (const alias of [...views.keys()]) {
|
|
228
|
+
if (keep.has(alias)) continue
|
|
229
|
+
views.delete(alias)
|
|
230
|
+
dropped = true
|
|
231
|
+
}
|
|
232
|
+
for (const alias of [...probes.keys()]) {
|
|
233
|
+
if (!keep.has(alias)) probes.delete(alias)
|
|
234
|
+
}
|
|
235
|
+
if (dropped) refreshSnapshot()
|
|
236
|
+
}
|
|
237
|
+
|
|
209
238
|
/** Where the last observed state came from (see `isConnectionRecovery`). */
|
|
210
239
|
export interface ConnectionTrace {
|
|
211
240
|
alias: string
|