dsh-remote-vs 0.27.0 → 0.29.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 +159 -23
- package/README.md +123 -23
- package/lib/client.js +6906 -6619
- package/lib/index.js +2014 -67
- package/lib/types/changes/recorder.d.ts +119 -2
- package/lib/types/client/CodeEditor.d.ts +15 -0
- package/lib/types/client/HostsView.d.ts +139 -2
- package/lib/types/client/api.d.ts +42 -2
- package/lib/types/client/changes/apply-failure.d.ts +41 -0
- package/lib/types/client/changes/block-confirm.d.ts +97 -0
- package/lib/types/client/changes/diff-outcome.d.ts +56 -0
- package/lib/types/client/changes/freshness.d.ts +51 -0
- package/lib/types/client/changes/model.d.ts +19 -1
- package/lib/types/client/changes/session-diff.d.ts +100 -0
- package/lib/types/client/changes/staleness.d.ts +98 -0
- package/lib/types/client/changes/turn-reverted.d.ts +82 -0
- package/lib/types/client/changes/turn-view.d.ts +131 -0
- package/lib/types/client/changes/undo-affordance.d.ts +44 -10
- package/lib/types/client/changes/undo-target.d.ts +12 -0
- package/lib/types/client/connection.d.ts +28 -1
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/store.d.ts +91 -1
- package/lib/types/client/vsc/change-marks.d.ts +21 -0
- package/lib/types/forward.d.ts +11 -1
- package/lib/types/pool.d.ts +95 -1
- package/lib/types/protocol.d.ts +221 -1
- package/lib/types/proxy.d.ts +136 -0
- package/lib/types/store.d.ts +81 -1
- package/lib/types/tools.d.ts +3 -0
- package/package.json +1 -1
- package/src/changes/recorder.ts +851 -8
- package/src/client/CodeEditor.tsx +43 -3
- package/src/client/ConnectionStatus.tsx +19 -5
- package/src/client/EditorPane.tsx +64 -7
- package/src/client/HostsView.tsx +552 -11
- package/src/client/PortsView.tsx +16 -0
- package/src/client/SettingsHosts.tsx +132 -6
- package/src/client/api.ts +60 -3
- package/src/client/changes/ChangesDock.tsx +539 -54
- package/src/client/changes/apply-failure.ts +73 -0
- package/src/client/changes/block-confirm.ts +180 -0
- package/src/client/changes/changes.css +45 -0
- package/src/client/changes/diff-outcome.ts +97 -0
- package/src/client/changes/freshness.ts +68 -0
- package/src/client/changes/model.ts +56 -1
- package/src/client/changes/session-diff.ts +187 -0
- package/src/client/changes/staleness.ts +148 -0
- package/src/client/changes/turn-reverted.ts +254 -0
- package/src/client/changes/turn-view.ts +195 -0
- package/src/client/changes/undo-affordance.ts +295 -63
- package/src/client/changes/undo-target.ts +12 -0
- package/src/client/connection.ts +76 -2
- package/src/client/i18n.ts +204 -4
- package/src/client/scm/DiffView.tsx +32 -13
- package/src/client/store.tsx +392 -16
- package/src/client/vsc/change-marks.ts +21 -0
- package/src/client/vsc/preview-document.tsx +4 -1
- package/src/client/vsc/vsc.css +6747 -6509
- package/src/forward.ts +38 -2
- package/src/importers.ts +125 -13
- package/src/keygen.ts +8 -1
- package/src/pool.ts +422 -27
- package/src/protocol.ts +229 -1
- package/src/proxy.ts +673 -0
- package/src/routes.ts +93 -14
- package/src/store.ts +335 -0
- package/src/tools.ts +47 -2
|
@@ -69,7 +69,29 @@ export interface SessionChangesDeps {
|
|
|
69
69
|
* fire.
|
|
70
70
|
*/
|
|
71
71
|
execBudgetMs?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Memory budget for the cached per-turn hunks and reverse patches, in bytes.
|
|
74
|
+
*
|
|
75
|
+
* Overridable so a check can exercise the over-budget degradation without
|
|
76
|
+
* generating four megabytes of text; the real default is {@link MAX_TURN_PATCH_BYTES}.
|
|
77
|
+
*/
|
|
78
|
+
turnPatchBytes?: number;
|
|
72
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* How stale the ledger may get before a *poll* re-scans it.
|
|
82
|
+
*
|
|
83
|
+
* Self-tuning: the host has no idea whether this session sits in a 50-file
|
|
84
|
+
* repository or a monorepo, and the same 30s window is either 300x the scan cost
|
|
85
|
+
* (small tree: the user waits half a minute to see a manual edit) or about right
|
|
86
|
+
* (AOSP: still 17x). Four times the LAST tracked scan, clamped to
|
|
87
|
+
* [{@link SELF_HEAL_MIN_MS}, {@link SELF_HEAL_MAX_MS}].
|
|
88
|
+
*
|
|
89
|
+
* An unknown / failed measurement falls back to the old ceiling, so a Host that
|
|
90
|
+
* has not scanned anything yet behaves exactly as before.
|
|
91
|
+
*
|
|
92
|
+
* @param scanMs - Duration of the last successful tracked scan, in ms.
|
|
93
|
+
*/
|
|
94
|
+
export declare function selfHealMaxAge(scanMs?: number): number;
|
|
73
95
|
export declare class SessionChanges {
|
|
74
96
|
private readonly ledgers;
|
|
75
97
|
private readonly deps;
|
|
@@ -103,6 +125,25 @@ export declare class SessionChanges {
|
|
|
103
125
|
* @returns hunks for decorations, or null when the session/file is unknown.
|
|
104
126
|
*/
|
|
105
127
|
diff(sessionId: string, path: string): Promise<RemoteChangesDiff | null>;
|
|
128
|
+
/**
|
|
129
|
+
* One file's comparison for the most recent COMPLETED turn.
|
|
130
|
+
*
|
|
131
|
+
* Same shape as {@link diff} (the editor paints both the same way), but the
|
|
132
|
+
* "before" side is the previous turn's close instead of the session baseline.
|
|
133
|
+
* The hunks are served from the turn delta's cache, so this call costs NO
|
|
134
|
+
* remote work in the common case — but a cached comparison is only worth
|
|
135
|
+
* showing while it still describes the disk. That is why the `after` side is
|
|
136
|
+
* read back here and compared with the cached text FIRST: if the file moved on
|
|
137
|
+
* after the turn closed (a later save, a terminal command, an agent), the
|
|
138
|
+
* answer is `stale` and the client falls back to the session view instead of
|
|
139
|
+
* painting line numbers that no longer exist.
|
|
140
|
+
*
|
|
141
|
+
* @param sessionId - live session owning the ledger.
|
|
142
|
+
* @param path - the file's remote absolute path (as listed in `turnView.files`).
|
|
143
|
+
* @returns hunks for decorations, `unavailable`/`stale` with a reason, or null
|
|
144
|
+
* when the session itself is unknown.
|
|
145
|
+
*/
|
|
146
|
+
turnDiff(sessionId: string, path: string): Promise<RemoteChangesDiff | null>;
|
|
106
147
|
/** Resolve once every queued refresh has settled, including coalesced work. */
|
|
107
148
|
settled(): Promise<void>;
|
|
108
149
|
/** Drop one session's ledger. */
|
|
@@ -121,10 +162,18 @@ export declare class SessionChanges {
|
|
|
121
162
|
* Self-heal a ledger whose data has gone stale.
|
|
122
163
|
*
|
|
123
164
|
* The panel polls `list`, and a poll is the one moment we know a human is
|
|
124
|
-
* looking at the answer. If the data is older than
|
|
165
|
+
* looking at the answer. If the data is older than the window, re-scan — so a
|
|
125
166
|
* turn boundary this Host never delivered costs a few seconds of staleness
|
|
126
167
|
* instead of a manual refresh.
|
|
127
168
|
*
|
|
169
|
+
* The window is ADAPTIVE ({@link selfHealMaxAge}): four times the last tracked
|
|
170
|
+
* scan, clamped to 5–30s. A small repository therefore surfaces a manual edit
|
|
171
|
+
* (one with no turn event behind it) within seconds instead of the old fixed
|
|
172
|
+
* half minute, while a monorepo keeps the old ceiling. The two `false` paths —
|
|
173
|
+
* a scan already running, and data that is still fresh — are unchanged.
|
|
174
|
+
*
|
|
175
|
+
* @param maxAgeMs - explicit window; callers that know better (and the checks)
|
|
176
|
+
* override the adaptive default and keep the old semantics exactly.
|
|
128
177
|
* @returns whether a refresh was queued.
|
|
129
178
|
*/
|
|
130
179
|
touch(sessionId: string, maxAgeMs?: number): boolean;
|
|
@@ -187,8 +236,76 @@ export declare class SessionChanges {
|
|
|
187
236
|
* Phase one publishes, phase two adds the new files when (and if) it lands.
|
|
188
237
|
*/
|
|
189
238
|
private refresh;
|
|
190
|
-
/**
|
|
239
|
+
/**
|
|
240
|
+
* Recompute the panel's list from the scans currently known.
|
|
241
|
+
*
|
|
242
|
+
* @param fromSlowScan - this publish was triggered by the `git ls-files
|
|
243
|
+
* --others` walk. A turn delta closed before that walk landed is still
|
|
244
|
+
* provisional: this flag is what lets it be re-derived once the turn's new
|
|
245
|
+
* files are known (see `correctTurn`).
|
|
246
|
+
*/
|
|
191
247
|
private publish;
|
|
248
|
+
/**
|
|
249
|
+
* Close one turn: compute "what did it change" and remember this close as the
|
|
250
|
+
* next turn's starting point.
|
|
251
|
+
*
|
|
252
|
+
* The delta is defined against the PREVIOUS close, not the session baseline, so
|
|
253
|
+
* a file the session changed in turn 1 and left alone in turn 2 must not appear
|
|
254
|
+
* in turn 2's list — otherwise the view says the same work happened twice.
|
|
255
|
+
* That is what `turnAfter` is for: it holds every listed path's text at the
|
|
256
|
+
* moment the previous turn closed, and it is replaced (never merged) here.
|
|
257
|
+
*
|
|
258
|
+
* A failed `after` read leaves the boundary unconsumed, so the next publish
|
|
259
|
+
* retries instead of recording a turn against "nothing".
|
|
260
|
+
*/
|
|
261
|
+
private closeTurn;
|
|
262
|
+
/**
|
|
263
|
+
* Re-derive the CURRENT turn's delta once the slow scan behind it has landed.
|
|
264
|
+
*
|
|
265
|
+
* A turn's new files are discovered by `git ls-files --others`, which runs
|
|
266
|
+
* after the tracked scan by design and can land seconds later. Rebuilding the
|
|
267
|
+
* same turn from the SAME "before" snapshot (kept in `turnBefore`) is what
|
|
268
|
+
* makes those files appear in the turn they belong to instead of in the next
|
|
269
|
+
* one. Guarded against the two ways this could lie: a newer turn boundary
|
|
270
|
+
* (which supersedes this delta) and a root move.
|
|
271
|
+
*/
|
|
272
|
+
private correctTurn;
|
|
273
|
+
/** Remember one close's sides for the next boundary (see `TurnSideText`). */
|
|
274
|
+
private turnSnapshotOf;
|
|
275
|
+
/**
|
|
276
|
+
* The "after" side of one turn close, in `display` space.
|
|
277
|
+
*
|
|
278
|
+
* Starts from the publish's own reads (every listed path), then reads the paths
|
|
279
|
+
* the PREVIOUS close listed but this publish does not: those left the dirty
|
|
280
|
+
* list (reverted to their baseline, deleted, restored), and without reading
|
|
281
|
+
* them now the revert would be attributed to nobody — "the turn put the file
|
|
282
|
+
* back" would look like "the turn changed nothing".
|
|
283
|
+
*
|
|
284
|
+
* @returns `ok` with the sides; `retry` when a read failed (the caller keeps
|
|
285
|
+
* the turn boundary for the next publish); `superseded` when a root move or
|
|
286
|
+
* a newer publish already owns the observation.
|
|
287
|
+
*/
|
|
288
|
+
private collectTurnSides;
|
|
289
|
+
/**
|
|
290
|
+
* Compare one turn's before/after sides into panel rows plus cached hunks.
|
|
291
|
+
*
|
|
292
|
+
* The comparison rules are the ones the whole-session `publish` uses (binary
|
|
293
|
+
* and cap-withheld bytes carry 0/0 counts, a creation has no reverse patch,
|
|
294
|
+
* hunks come from the same Myers implementation), so a row means the same
|
|
295
|
+
* thing in both views.
|
|
296
|
+
*/
|
|
297
|
+
private buildTurnDelta;
|
|
298
|
+
/**
|
|
299
|
+
* Commit one built delta, degrading honestly when it blew the memory budget.
|
|
300
|
+
*
|
|
301
|
+
* Over budget the statistics are already computed and stay usable, but the
|
|
302
|
+
* per-file hunks and patches are dropped and this session stops computing turn
|
|
303
|
+
* views: keeping a half-filled snapshot would make the NEXT turn compare
|
|
304
|
+
* against texts that belong to an older boundary.
|
|
305
|
+
*/
|
|
306
|
+
private storeTurnDelta;
|
|
307
|
+
/** Stop computing turn views for this session, saying why (sticky). */
|
|
308
|
+
private disableTurn;
|
|
192
309
|
/**
|
|
193
310
|
* The cheap scan: tracked files whose working-tree bytes differ from the
|
|
194
311
|
* index (1.4s measured on the reference monorepo).
|
|
@@ -126,6 +126,21 @@ export declare const CodeEditor: import("react").ForwardRefExoticComponent<{
|
|
|
126
126
|
onUndoChange?: (mark: ChangeMark) => void;
|
|
127
127
|
/** 悬浮按钮的文案(由调用方按 `kind` 给出它的 i18n 说法)。 */
|
|
128
128
|
undoLabel?: (mark: ChangeMark) => string;
|
|
129
|
+
/** 行尾那枚 `⋯` 的说明(title / aria-label,调用方传 i18n)。 */
|
|
130
|
+
undoTriggerLabel?: () => string;
|
|
131
|
+
/**
|
|
132
|
+
* 悬浮栏的第二个动作:「确认保留」(块级本地笔记,见 `changes/block-confirm.ts`)。
|
|
133
|
+
*
|
|
134
|
+
* 不传 = 悬浮栏只有撤销一个动作(与没有这个功能时完全一致)。传了也只是把
|
|
135
|
+
* 读/切换交回去:存储、会话归属都在调用方那一侧,编辑器组件不持有这份状态,更
|
|
136
|
+
* 不会因为它写任何远端。
|
|
137
|
+
*/
|
|
138
|
+
blockConfirm?: {
|
|
139
|
+
isConfirmed: (mark: ChangeMark) => boolean;
|
|
140
|
+
onToggle: (mark: ChangeMark) => void;
|
|
141
|
+
label: (mark: ChangeMark) => string;
|
|
142
|
+
pressedLabel?: (mark: ChangeMark) => string;
|
|
143
|
+
};
|
|
129
144
|
/** 改动点跳转的目标行(1-based),配合 `revealHunkNonce` 重跳同一行。 */
|
|
130
145
|
revealHunkLine?: number;
|
|
131
146
|
/** 改动点跳转的 nonce(同 `revealNonce` 的道理)。 */
|
|
@@ -1,10 +1,147 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hosts view: list + add/edit form + test + key bootstrap + push + import.
|
|
3
|
+
*
|
|
4
|
+
* The form also owns the host's 「网络出口」 (egress: proxy / jump host) block.
|
|
5
|
+
* It is COLLAPSED by default, because most hosts go out directly and a wall of
|
|
6
|
+
* empty proxy fields reads as "you must fill this in"; the collapsed row still
|
|
7
|
+
* carries a read-only chip with the resulting route, so the answer to "how does
|
|
8
|
+
* this host get out" never needs a click. The profile-wide default that
|
|
9
|
+
* `跟随默认` resolves to lives in Settings (`SettingsHosts.tsx`).
|
|
3
10
|
*/
|
|
4
11
|
import { type ReactNode } from 'react';
|
|
5
|
-
import type { RemoteHostSummary } from '../protocol.ts';
|
|
12
|
+
import type { RemoteHostProxySetting, RemoteHostProxyView, RemoteHostSummary, RemoteProxyMode, RemoteProxySetting, RemoteProxySettingsView } from '../protocol.ts';
|
|
13
|
+
import { type HostForm } from './api.ts';
|
|
14
|
+
/** The translator shape this plugin's views pass around. */
|
|
15
|
+
type TFn = (key: string) => string;
|
|
16
|
+
/** Everything the egress controls edit, as form strings. */
|
|
17
|
+
export interface ProxyFormState {
|
|
18
|
+
mode: RemoteProxyMode;
|
|
19
|
+
kind: 'http' | 'socks5';
|
|
20
|
+
host: string;
|
|
21
|
+
port: string;
|
|
22
|
+
username: string;
|
|
23
|
+
password: string;
|
|
24
|
+
viaAlias: string;
|
|
25
|
+
}
|
|
26
|
+
/** A blank draft: `跟随默认`, HTTP, no address (i.e. a fresh host). */
|
|
27
|
+
export declare function emptyProxyState(): ProxyFormState;
|
|
28
|
+
/**
|
|
29
|
+
* Seed the controls from a stored (secret-free) host view.
|
|
30
|
+
*
|
|
31
|
+
* The password box stays EMPTY on purpose: the Host never echoes it back, and
|
|
32
|
+
* `proxySettingOf` expresses "keep the stored one" by omitting the field, so an
|
|
33
|
+
* untouched box cannot overwrite a working credential with an empty string.
|
|
34
|
+
*/
|
|
35
|
+
export declare function proxyStateOf(view: RemoteHostProxyView | undefined): ProxyFormState;
|
|
36
|
+
/** The profile default as a draft (it only knows `direct` / `proxy`). */
|
|
37
|
+
export declare function defaultProxyStateOf(view: RemoteProxySettingsView | undefined): ProxyFormState;
|
|
38
|
+
/**
|
|
39
|
+
* The endpoint half of a proxy decision.
|
|
40
|
+
*
|
|
41
|
+
* An empty password is OMITTED (not sent as `''`): that is the contract for
|
|
42
|
+
* "keep the stored secret", and it is the only reason the browser never has to
|
|
43
|
+
* see the password at all.
|
|
44
|
+
*/
|
|
45
|
+
export declare function proxyTargetOf(state: ProxyFormState): RemoteProxySetting;
|
|
46
|
+
/**
|
|
47
|
+
* The `proxy` field for one save, or `undefined` when it must be left out.
|
|
48
|
+
*
|
|
49
|
+
* `undefined` is the BACKWARD-COMPATIBLE answer: an old Host ignores the field,
|
|
50
|
+
* and on create an absent value simply inherits the profile default. An UPDATE
|
|
51
|
+
* that switches back to `跟随默认` is the one case an explicit
|
|
52
|
+
* `{ mode: 'inherit' }` has to be sent, or the stored proxy would never clear.
|
|
53
|
+
*/
|
|
54
|
+
export declare function proxySettingOf(state: ProxyFormState): RemoteHostProxySetting | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* What stops a save: an unusable proxy endpoint, or no jump host picked.
|
|
57
|
+
*
|
|
58
|
+
* `jumpChoices` is the list of aliases the save can legally name (every stored
|
|
59
|
+
* host except the one being edited). A stored jump host that has since been
|
|
60
|
+
* deleted is NOT saveable — the Host refuses a `viaAlias` it does not know — so
|
|
61
|
+
* the form has to say that in the user's language instead of forwarding a raw
|
|
62
|
+
* `unknown host alias` rejection for a field nobody touched.
|
|
63
|
+
*/
|
|
64
|
+
export declare function proxyFormProblem(state: ProxyFormState, jumpChoices?: string[]): 'target' | 'jump' | 'jumpGone' | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* One line saying where traffic goes — the collapsed chip's text.
|
|
67
|
+
*
|
|
68
|
+
* `跟随默认` is resolved against the profile default when it is known: the whole
|
|
69
|
+
* point of showing the chip while collapsed is that "follow the default" alone
|
|
70
|
+
* does not tell the user whether that means direct or a proxy. An unknown
|
|
71
|
+
* default (a Host without the route, or a failed read) degrades to the bare
|
|
72
|
+
* phrase rather than guessing "direct".
|
|
73
|
+
*/
|
|
74
|
+
export declare function proxySummary(t: TFn, state: ProxyFormState, fallback: RemoteProxySettingsView | undefined): string;
|
|
75
|
+
/** One rendered chip: its word, its hover text, and whether it is a problem. */
|
|
76
|
+
export interface ProxyChipModel {
|
|
77
|
+
mode: RemoteProxyMode;
|
|
78
|
+
label: string;
|
|
79
|
+
title: string;
|
|
80
|
+
problem: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The host ROW's chip: which way this host leaves the machine.
|
|
84
|
+
*
|
|
85
|
+
* Deliberately shorter than the form's summary (`代理`, not `经 HTTP 代理 h:p`) —
|
|
86
|
+
* a list row has one line of room and the full route is the `title`. A refused
|
|
87
|
+
* setting keeps its chip text and switches to the error colour, because the row
|
|
88
|
+
* still has to say what was configured; `problem` explains why it cannot work.
|
|
89
|
+
*
|
|
90
|
+
* `fallback` is the profile-wide default, so a `跟随默认` row resolves to what it
|
|
91
|
+
* actually does (the form's chip already does) — without it the row would say
|
|
92
|
+
* "follow default" while the same host's form says "follow default (via …)". An
|
|
93
|
+
* unknown default degrades to the bare phrase rather than guessing "direct".
|
|
94
|
+
*/
|
|
95
|
+
export declare function proxyChipOf(t: TFn, view: RemoteHostProxyView, fallback?: RemoteProxySettingsView): ProxyChipModel;
|
|
96
|
+
/** Read-only route chip (secondary outline, never a status colour). */
|
|
97
|
+
export declare function ProxyChip(props: {
|
|
98
|
+
chip: ProxyChipModel;
|
|
99
|
+
}): ReactNode;
|
|
100
|
+
/**
|
|
101
|
+
* Collapsible section header: a real `<button>` with `aria-expanded`.
|
|
102
|
+
*
|
|
103
|
+
* A `<details>` element was refused on purpose: its summary marker cannot be
|
|
104
|
+
* restyled without vendor pseudo-elements and it gives no place for the chip.
|
|
105
|
+
* A native button keeps Enter/Space, focus and the announced state for free.
|
|
106
|
+
*/
|
|
107
|
+
export declare function ProxySectionHeader(props: {
|
|
108
|
+
open: boolean;
|
|
109
|
+
label: string;
|
|
110
|
+
expandLabel: string;
|
|
111
|
+
collapseLabel: string;
|
|
112
|
+
chip: ProxyChipModel;
|
|
113
|
+
controls: string;
|
|
114
|
+
onToggle: () => void;
|
|
115
|
+
}): ReactNode;
|
|
116
|
+
/**
|
|
117
|
+
* The endpoint controls, shared by the per-host form and the profile default.
|
|
118
|
+
*
|
|
119
|
+
* Password semantics are identical in both places: `storedPassword` only
|
|
120
|
+
* switches the placeholder, and an empty box is omitted from the payload.
|
|
121
|
+
*/
|
|
122
|
+
export declare function ProxyFields(props: {
|
|
123
|
+
t: TFn;
|
|
124
|
+
state: ProxyFormState;
|
|
125
|
+
onChange: (next: ProxyFormState) => void;
|
|
126
|
+
storedPassword: boolean;
|
|
127
|
+
disabled?: boolean;
|
|
128
|
+
}): ReactNode;
|
|
129
|
+
export declare function HostFormView(props: {
|
|
130
|
+
t: TFn;
|
|
131
|
+
initial?: RemoteHostSummary;
|
|
132
|
+
busy: boolean;
|
|
133
|
+
/** Every stored host: the jump-host list (minus the one being edited). */
|
|
134
|
+
hosts: RemoteHostSummary[];
|
|
135
|
+
/** The profile-wide default, so `跟随默认` can be spelled out while collapsed. */
|
|
136
|
+
proxyDefault?: RemoteProxySettingsView;
|
|
137
|
+
onSave: (form: HostForm) => void;
|
|
138
|
+
onCancel: () => void;
|
|
139
|
+
}): ReactNode;
|
|
6
140
|
export declare function HostsView(props: {
|
|
7
|
-
t:
|
|
141
|
+
t: TFn;
|
|
8
142
|
hosts: RemoteHostSummary[];
|
|
143
|
+
/** Profile-wide egress default, so `跟随默认` chips can be resolved. */
|
|
144
|
+
proxyDefault?: RemoteProxySettingsView;
|
|
9
145
|
onChanged: () => void;
|
|
10
146
|
}): ReactNode;
|
|
147
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed fetch wrapper over the /api/dsh-remote JSON API (full P0 surface).
|
|
3
3
|
*/
|
|
4
|
-
import { type GitBranch, type GitCommit, type GitShow, type GitStatus, type HelperAvailability, type ImportReport, type RemoteChangesDiff, type RemoteChangesSummary, type RemoteConnectionStatus, type RemoteDeployState, type RemoteExecResult, type RemoteFileEntry, type RemoteForwardRequest, type RemoteForwardState, type RemoteHostSummary, type RemoteListenPortsResult, type RemoteProcessKillResult, type RemoteProcessesResult, type RemotePluginMeta, type RemoteProbe, type RemoteRead, type RemoteRoutingStatus, type RemoteTimeouts, type RemoteViewSettings, type RemoteWorkspaceBinding, type RemoteWriteConflict, type RemoteWriteResult } from '../protocol.ts';
|
|
4
|
+
import { type GitBranch, type GitCommit, type GitShow, type GitStatus, type HelperAvailability, type ImportReport, type RemoteChangesDiff, type RemoteChangesSummary, type RemoteConnectionStatus, type RemoteDeployState, type RemoteExecResult, type RemoteFileEntry, type RemoteForwardRequest, type RemoteForwardState, type RemoteHostProxySetting, type RemoteHostSummary, type RemoteListenPortsResult, type RemoteProcessKillResult, type RemoteProcessesResult, type RemotePluginMeta, type RemoteProbe, type RemoteProxySettingsPatch, type RemoteProxySettingsView, type RemoteRead, type RemoteRoutingStatus, type RemoteTimeouts, type RemoteViewSettings, type RemoteWorkspaceBinding, type RemoteWriteConflict, type RemoteWriteResult } from '../protocol.ts';
|
|
5
5
|
export declare class RemoteApiError extends Error {
|
|
6
6
|
readonly status: number;
|
|
7
7
|
/**
|
|
@@ -134,6 +134,14 @@ export interface HostForm {
|
|
|
134
134
|
};
|
|
135
135
|
description?: string;
|
|
136
136
|
tags?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* How this host reaches the network (see `RemoteHostProxySetting`).
|
|
139
|
+
*
|
|
140
|
+
* Absent means "no opinion": a create then keeps the profile default, and an
|
|
141
|
+
* update keeps whatever the host already had — which is what makes the field
|
|
142
|
+
* backward compatible with a Host that never heard of it.
|
|
143
|
+
*/
|
|
144
|
+
proxy?: RemoteHostProxySetting;
|
|
137
145
|
}
|
|
138
146
|
export interface PushReportView {
|
|
139
147
|
alias: string;
|
|
@@ -249,13 +257,45 @@ export declare const api: {
|
|
|
249
257
|
* is opened for review.
|
|
250
258
|
*/
|
|
251
259
|
changes: {
|
|
252
|
-
|
|
260
|
+
/**
|
|
261
|
+
* @param force - `⟳` semantics: tracked scan now AND re-arm the slow new-file
|
|
262
|
+
* walk (expensive; a deliberate click).
|
|
263
|
+
* @param trackedOnly - "user came back to the page": tracked files now, but the
|
|
264
|
+
* slow walk keeps its cadence/write-off (see `RemoteChangesListRequest`).
|
|
265
|
+
*/
|
|
266
|
+
list: (sessionId: string, force?: boolean, repoSubdir?: string, trackedOnly?: boolean) => Promise<RemoteChangesSummary | null>;
|
|
253
267
|
diff: (sessionId: string, path: string, repoSubdir?: string) => Promise<RemoteChangesDiff | null>;
|
|
268
|
+
/**
|
|
269
|
+
* The same comparison, but against the previous completed turn's close
|
|
270
|
+
* instead of the session baseline (the panel's 「本轮」 scope).
|
|
271
|
+
*
|
|
272
|
+
* Answers `unavailable` / `stale` (with a reason) instead of hunks when the
|
|
273
|
+
* host has no cached per-turn contents or the file moved on after the turn —
|
|
274
|
+
* the client must fall back to `diff` (session view) rather than paint lines
|
|
275
|
+
* that no longer exist.
|
|
276
|
+
*/
|
|
277
|
+
turnDiff: (sessionId: string, path: string, repoSubdir?: string) => Promise<RemoteChangesDiff | null>;
|
|
254
278
|
};
|
|
255
279
|
setRoutingMode: (mode: "off" | "shadow" | "enforce") => Promise<"off" | "shadow" | "enforce">;
|
|
256
280
|
getViewSettings: () => Promise<RemoteViewSettings>;
|
|
257
281
|
/** Flat patch: unknown keys are ignored, unusable values keep the stored one. */
|
|
258
282
|
setViewSettings: (patch: Partial<RemoteViewSettings>) => Promise<RemoteViewSettings>;
|
|
283
|
+
/**
|
|
284
|
+
* The default egress every `mode: 'inherit'` host follows.
|
|
285
|
+
*
|
|
286
|
+
* Answers the DEFAULTS on a fresh profile (`direct`), and a Host too old to
|
|
287
|
+
* know the route answers 404 — callers treat that as "direct" and keep the
|
|
288
|
+
* per-host form working (see `proxySummary`).
|
|
289
|
+
*/
|
|
290
|
+
getProxySettings: () => Promise<RemoteProxySettingsView>;
|
|
291
|
+
/**
|
|
292
|
+
* Patch the default egress.
|
|
293
|
+
*
|
|
294
|
+
* `target: null` clears the stored endpoint; omitting it keeps the stored one
|
|
295
|
+
* (so flipping to `direct` and back does not lose the address), and an empty
|
|
296
|
+
* password keeps the stored secret — the browser never sees it.
|
|
297
|
+
*/
|
|
298
|
+
patchProxySettings: (patch: RemoteProxySettingsPatch) => Promise<RemoteProxySettingsView>;
|
|
259
299
|
deployStatus: (alias: string) => Promise<{
|
|
260
300
|
deploy: RemoteDeployState;
|
|
261
301
|
helpers: HelperAvailability[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 撤销失败时说人话:把 `git apply` 的 stderr 归成几种**可操作**的原因。
|
|
3
|
+
*
|
|
4
|
+
* 这条路原来只有一句「这处改动的上下文已经变了」。可实际失败原因不止一种,而且
|
|
5
|
+
* 读法完全不同:
|
|
6
|
+
* - 上下文真的变了 → 重新点该行重算标记,再看一遍;
|
|
7
|
+
* - 文件已经不在仓库里 → 打开/重命名过,去列表里重新找;
|
|
8
|
+
* - 权限 / 只读文件系统 → 远端那头的问题,换条路(终端 / 另一个写入者);
|
|
9
|
+
* - 仓库所有权不对(git 的 `dubious ownership`)→ 去配 `safe.directory` 或修所有权,
|
|
10
|
+
* 换仓库目录解决不了它;
|
|
11
|
+
* - 补丁本身坏了(截断 / 手改)→ 重新取一次改动内容;
|
|
12
|
+
* - 其它 → 至少把 git 的原话留在后面。
|
|
13
|
+
*
|
|
14
|
+
* 样本来自 `git apply` 的真实 stderr 形状(git 2.55 / apply.c 与 setup.c 的消息;
|
|
15
|
+
* 2026-11-26 审核用真远端 git 复跑过):`patch failed: … / patch does not apply`、
|
|
16
|
+
* `already exists in working directory`、`No such file or directory`、
|
|
17
|
+
* `does not exist in index`、`Permission denied`、`unable to write new index file`、
|
|
18
|
+
* `detected dubious ownership in repository at …`、`corrupt patch at line N`、
|
|
19
|
+
* `patch fragment without header at line N`、`patch with only garbage at <file>:<line>`。
|
|
20
|
+
*
|
|
21
|
+
* **没有"不是 git 仓库"这一档**:`git apply` 不要求当前目录是仓库,跑在非仓库目录
|
|
22
|
+
* 得到的仍是文件级错误(实测是 `No such file or directory`,归 path-missing);
|
|
23
|
+
* 把那种情形报成"重选仓库目录"会把人引到错误的修法上(审核 S3)。
|
|
24
|
+
*
|
|
25
|
+
* 纯函数 + 一张样本表,`scripts/check-apply-failure.mjs` 用真实 stderr 驱动。
|
|
26
|
+
* 传输失败(socket/超时)不在这里:那是链路问题,调用方先用 `isConnectionFailure`
|
|
27
|
+
* 拦掉,报成"补丁上下文变了"会把人引到错误的修法上。
|
|
28
|
+
*/
|
|
29
|
+
/** 撤销失败的原因分类。 */
|
|
30
|
+
export type ApplyFailureKind = 'context-moved' | 'path-missing' | 'permission' | 'ownership' | 'corrupt' | 'other';
|
|
31
|
+
/** 一份 stderr 属于哪类原因。 */
|
|
32
|
+
export declare function classifyApplyFailure(detail: string): ApplyFailureKind;
|
|
33
|
+
/** 一份 stderr 对应的字典键。 */
|
|
34
|
+
export declare function applyFailureKey(detail: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* 失败提示的正文:分类那句话 + git 的原话(次要信息)。
|
|
37
|
+
*
|
|
38
|
+
* 原话一定留在后面:分类是我们对 stderr 的读法,读错了用户还能从原文看出来。
|
|
39
|
+
* `detail` 为空时返回 `undefined`,由调用方退回既有的兜底文案。
|
|
40
|
+
*/
|
|
41
|
+
export declare function applyFailureText(detail: string, t: (key: string) => string): string | undefined;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 编辑器里「这处改动我看过,保留」的块级本地笔记。
|
|
3
|
+
*
|
|
4
|
+
* 面板那一行上的 ✓ 是**文件级**人工标记(`review-state.ts`),回答的是"这个文件我
|
|
5
|
+
* 审过了"。但一处三十行的重构里,真正需要收敛的是"这**一块**我看过了、同意保留" ——
|
|
6
|
+
* 文件级 ✓ 要么在看完第一块时就被打上,要么看到最后才敢打。
|
|
7
|
+
*
|
|
8
|
+
* 所以这里补第二级:鼠标停在改动行上弹出的那条悬浮栏里,除了「撤销这处改动」,还有
|
|
9
|
+
* 一个切换式的「确认保留」。它**什么也不写**:不写远端、不发请求、不动 diff 数据
|
|
10
|
+
* (撤销是远端 `git apply -R`,确认只是给自己留个记号),状态存在 `localStorage`,
|
|
11
|
+
* 按会话分开 —— 它描述的是"我读到哪儿了",不是远端的任何事实。
|
|
12
|
+
*
|
|
13
|
+
* 块的身份用 `${远端绝对路径}|${oldStart}:${oldLines}:${newStart}:${newLines}`:行号
|
|
14
|
+
* 会随远端改动漂移,而 hunk 头的四个数字 + 文件的远端绝对路径才代表"同一处改动"
|
|
15
|
+
* (用绝对路径而不是会话相对的显示路径:两个仓库子目录可以给出同一个显示路径)。
|
|
16
|
+
* 文件被重新统计后 hunk 头变了,旧笔记自然不再命中 —— 这正是想要的(内容变过,值得
|
|
17
|
+
* 再看一眼),而且不需要监听任何事件。
|
|
18
|
+
*
|
|
19
|
+
* **已知限制(审核 N3)**:身份里没有**轴**也没有轮次号。同一文件的同一坐标若在
|
|
20
|
+
* 「会话累计」与「本轮」两份数据里都出现(例如同一轮就是首次改动、两份 hunk 头恰好
|
|
21
|
+
* 相同),那一处块确认是**共用的**;同理,隔着新一轮但 hunk 头四个数字完全没变的
|
|
22
|
+
* 另一处改动也会沿用旧笔记。不把轴/轮号并进身份是刻意的取舍:身份串会随轮次变化,
|
|
23
|
+
* 已确认状态在每次轮次关闭后全部失效;而"同一坐标、内容未变"沿用确认,正是这套
|
|
24
|
+
* 记号想要的收敛效果。真要区分只能连内容指纹一起入键,那需要为每块算一次哈希。
|
|
25
|
+
*
|
|
26
|
+
* 两级语义**不联动**:块确认不会自动打文件级 ✓,文件级 ✓ 也不代表每一块都点过。
|
|
27
|
+
* 纯函数 + 一个有上限的表,`scripts/check-block-confirm.mjs` 直接驱动真实判定,
|
|
28
|
+
* 并用 jsdom 里的真 CodeMirror 点一次真正的按钮。
|
|
29
|
+
*/
|
|
30
|
+
/** 一个会话最多记住这么多块(长命页面不能无限长)。 */
|
|
31
|
+
export declare const BLOCK_CONFIRM_CAP = 2000;
|
|
32
|
+
/** `localStorage` 键前缀(按会话分开;与面板的审阅标记同一套约定)。 */
|
|
33
|
+
export declare const BLOCK_CONFIRM_PREFIX = "rvs.changes.confirmed.";
|
|
34
|
+
/** 已确认的块:键 → 1(用对象是为了能直接 JSON 往返)。 */
|
|
35
|
+
export type ConfirmedBlocks = Readonly<Record<string, 1>>;
|
|
36
|
+
/** 只读存取的存储接口(真实实现是 `window.localStorage`;门禁用假表)。 */
|
|
37
|
+
export interface ConfirmStorage {
|
|
38
|
+
getItem(key: string): string | null;
|
|
39
|
+
setItem(key: string, value: string): void;
|
|
40
|
+
}
|
|
41
|
+
/** 一个 hunk 头里参与块身份的那四个数字。 */
|
|
42
|
+
export interface BlockHeader {
|
|
43
|
+
oldStart: number;
|
|
44
|
+
oldLines: number;
|
|
45
|
+
newStart: number;
|
|
46
|
+
newLines: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 块标识(见文件头;字段用 `|` 与 `:` 分隔,数字不会包含这两个字符)。
|
|
50
|
+
*
|
|
51
|
+
* @param path - 文件的**远端绝对路径**(不是显示路径)。
|
|
52
|
+
* @param hunk - 这个 hunk 头里的四个数字。
|
|
53
|
+
*/
|
|
54
|
+
export declare function blockIdOf(path: string, hunk: BlockHeader): string;
|
|
55
|
+
/**
|
|
56
|
+
* 一处改动(`ChangeMark`)对应的块标识。
|
|
57
|
+
*
|
|
58
|
+
* `mark.hunk` 是 `ChangeSet.patches` 的下标,`ChangeSet.blocks` 与它同序,所以这里
|
|
59
|
+
* 只是换个名字;没有大括号(`blocks` 省略、或 `hunk` 缺失)时返回 `undefined` ——
|
|
60
|
+
* 调用方据此不提供「确认保留」。
|
|
61
|
+
*/
|
|
62
|
+
export declare function blockIdForMark(blocks: readonly string[] | undefined, mark: {
|
|
63
|
+
hunk?: number;
|
|
64
|
+
}): string | undefined;
|
|
65
|
+
/** 这一块是否已被确认。 */
|
|
66
|
+
export declare function isBlockConfirmed(blocks: ConfirmedBlocks, id: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 切换一块的确认状态,返回新表(输入不被修改;超过上限时丢掉最早的那条)。
|
|
69
|
+
*
|
|
70
|
+
* 上限按 `Object.keys` 顺序(插入顺序)丢最旧的一条:块笔记是"我最近看过的",
|
|
71
|
+
* 丢掉最早看过的那条比拒绝新笔记更符合直觉。
|
|
72
|
+
*/
|
|
73
|
+
export declare function toggleConfirmedBlock(blocks: ConfirmedBlocks, id: string): Record<string, 1>;
|
|
74
|
+
/**
|
|
75
|
+
* 解析持久化的一串 JSON。
|
|
76
|
+
*
|
|
77
|
+
* 任何畸形输入都给空表而不是抛错:这份状态只是"看过没看过",读不出来最多重看一遍,
|
|
78
|
+
* 不值得让编辑器崩掉。键必须非空、值必须是 1,且受 {@link BLOCK_CONFIRM_CAP} 限制。
|
|
79
|
+
*/
|
|
80
|
+
export declare function parseConfirmedBlocks(raw: string | null | undefined): Record<string, 1>;
|
|
81
|
+
/** 序列化(键数量已受上限约束,所以这串不会无限长)。 */
|
|
82
|
+
export declare function serializeConfirmedBlocks(blocks: ConfirmedBlocks): string;
|
|
83
|
+
/** 这一会话的存储键。 */
|
|
84
|
+
export declare function confirmedStorageKey(sessionId: string): string;
|
|
85
|
+
/** 读一个会话的块笔记(存储拒绝回答时给空表:私有模式最多是不持久化)。 */
|
|
86
|
+
export declare function loadConfirmedBlocks(storage: ConfirmStorage, sessionId: string): Record<string, 1>;
|
|
87
|
+
/** 写一个会话的块笔记(存不下就算了,绝不能因此打断编辑)。 */
|
|
88
|
+
export declare function saveConfirmedBlocks(storage: ConfirmStorage, sessionId: string, blocks: ConfirmedBlocks): void;
|
|
89
|
+
/**
|
|
90
|
+
* 切换并落盘一块,返回切换后的状态。
|
|
91
|
+
*
|
|
92
|
+
* 一次调用完成"读 → 切 → 写":编辑器里的按钮可能连点,中间隔着一次 React 渲染,
|
|
93
|
+
* 拿旧表覆盖会把连点丢一半。
|
|
94
|
+
*/
|
|
95
|
+
export declare function toggleStoredBlock(storage: ConfirmStorage, sessionId: string, id: string): boolean;
|
|
96
|
+
/** 读一块的当前状态(每次现读:切换发生在 React 之外)。 */
|
|
97
|
+
export declare function isStoredBlockConfirmed(storage: ConfirmStorage, sessionId: string, id: string): boolean;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 点开一行时,Host 给的这份 diff 到底能画出什么 —— 以及必须当面说清的那几种情况。
|
|
3
|
+
*
|
|
4
|
+
* 面板原来只看 `kind === 'text'`:二进制与读不到的文件都落进"空标记集",
|
|
5
|
+
* 屏幕上什么也没有、也没说为什么(`changes/ChangesDock.tsx` 的旧写法)。
|
|
6
|
+
*
|
|
7
|
+
* 三种"不能画"的原因必须分开说,因为读法完全不同:
|
|
8
|
+
* - `truncated`:Host 的读取被字节上限扣下。注意它**不是**"只给了前 N 处":被扣的是
|
|
9
|
+
* 文件的 after 文本,hunk 是拿 before 对**空文本**算出来的,等于整篇都算改动,而且
|
|
10
|
+
* `reverse` 为空、每个 hunk 的 patch 都是 ''(`recorder.ts` 394-407)—— 撤销不可
|
|
11
|
+
* 能成功。所以这种 diff 一行标记都不建,只说"比较不完整、不能撤销";
|
|
12
|
+
* - `binary`:二进制/非 UTF-8,没有可画的文本行;
|
|
13
|
+
* - `oversized`:文件超过行级比较上限(或字节被扣下),行数本身就不可信,不做行级比较;
|
|
14
|
+
* - `missing`:Host 读不到那个文件(`kind: 'missing'`,或调用本身没拿到东西);
|
|
15
|
+
* - `empty`:两侧都读到了、也比较了,但**现在**没有差异(行还留在列表里,内容已被改回)。
|
|
16
|
+
*
|
|
17
|
+
* 这里把"这份 diff 属于哪种结局"收成一个纯判定,并顺手把 `ChangeSet` 建好,让
|
|
18
|
+
* 面板只剩"显示哪句话"一件事。纯函数,`scripts/check-diff-outcome.mjs` 直接驱动。
|
|
19
|
+
*/
|
|
20
|
+
import type { RemoteChangesDiff } from '../../protocol.ts';
|
|
21
|
+
import { type ChangeSet } from './model.ts';
|
|
22
|
+
/**
|
|
23
|
+
* 一份 diff 的可见结论。
|
|
24
|
+
*
|
|
25
|
+
* 顺序即判定优先级(见 {@link noticeOfDiff}):读不到 → 二进制 → 过大/截断 → 空比较。
|
|
26
|
+
*/
|
|
27
|
+
export type DiffNotice = 'truncated' | 'oversized' | 'binary' | 'missing' | 'empty';
|
|
28
|
+
/** 一份结论对应的字典键。 */
|
|
29
|
+
export declare function diffNoticeKey(notice: DiffNotice): string;
|
|
30
|
+
/** 面板拿到的这份 diff 属于哪种结论;`undefined` = 正常文本差异。 */
|
|
31
|
+
export declare function noticeOfDiff(diff: RemoteChangesDiff | null): DiffNotice | undefined;
|
|
32
|
+
/** 建一批标记时调用方手头知道的那些事实。 */
|
|
33
|
+
export interface DiffMeta {
|
|
34
|
+
/** 文件的远端绝对路径(块标识的前半段,见 `changes/block-confirm.ts`)。 */
|
|
35
|
+
path?: string;
|
|
36
|
+
/** 列表行的状态字母(`RemoteChangedFile.status`)。 */
|
|
37
|
+
status?: string;
|
|
38
|
+
}
|
|
39
|
+
/** 一次"点开一行"的完整结果。 */
|
|
40
|
+
export interface ChangeSetFromDiffResult {
|
|
41
|
+
set: ChangeSet;
|
|
42
|
+
/** 必须显示给用户的结论;`undefined` = 一切正常,不必出提示。 */
|
|
43
|
+
notice?: DiffNotice;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 把一份 diff 结论同时翻成"要画的标记"与"要说的话"。
|
|
47
|
+
*
|
|
48
|
+
* **`truncated` 一行标记都不建**(M2):那种 diff 的 hunk 是 before 对空文本算的
|
|
49
|
+
* 整篇假差异,照着画会把每个改动点都标成删除,撤销更不可能成立(patch 全为空)。
|
|
50
|
+
* 宁可不画,也不给一份"看着像真相"的假标记。
|
|
51
|
+
*
|
|
52
|
+
* @param diff - `api.changes.diff` 的答案(`null` = 没拿到)。
|
|
53
|
+
* @param stamp - 这份数据的身份(文件 + 统计时刻 + 轮次)。
|
|
54
|
+
* @param meta - 调用方手头知道的事实,见 {@link DiffMeta}。
|
|
55
|
+
*/
|
|
56
|
+
export declare function changeSetFromDiff(diff: RemoteChangesDiff | null, stamp: string, meta?: DiffMeta): ChangeSetFromDiffResult;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「回到页面/窗口时要不要强制刷新一次」的纯判定。
|
|
3
|
+
*
|
|
4
|
+
* 背景:宿主账本的自愈阈值是自适应的(`recorder.ts` 的 `selfHealMaxAge`,5–30s),
|
|
5
|
+
* 而面板在页面隐藏期间不轮询。用户切走再回来时,屏幕上那份统计可能已经落后一个
|
|
6
|
+
* 阈值;普通轮询读(`load(false)`)仍受阈值保护,所以"回来"这一刻要**强制刷新一次**
|
|
7
|
+
* (等价于点 ⟳,`force` 会绕过节流并立刻重扫)。
|
|
8
|
+
*
|
|
9
|
+
* 但"回来"会连环触发事件:切回标签页同时有 `visibilitychange` 与 `focus`;在窗口
|
|
10
|
+
* 之间点几下也会连续 `focus`。所以这里给三条门槛,任何一条不满足就不刷新:
|
|
11
|
+
* - 页面必须真的可见(隐藏期间不轮询,也不该偷偷 force);
|
|
12
|
+
* - 距上一次强制刷新至少 {@link FORCE_REFRESH_DEBOUNCE_MS}(5s);
|
|
13
|
+
* - 没有同类的 `list` 请求在飞(它马上就会带回新数据)。
|
|
14
|
+
*
|
|
15
|
+
* 纯函数 + 显式时钟入参,`scripts/check-change-freshness.mjs` 直接驱动。
|
|
16
|
+
*/
|
|
17
|
+
/** 两次强制刷新之间的最小间隔("点回窗口"的连环事件都落在这之内)。 */
|
|
18
|
+
export declare const FORCE_REFRESH_DEBOUNCE_MS = 5000;
|
|
19
|
+
/**
|
|
20
|
+
* 一个 `list` 请求最多算"在飞"多久(60s)。
|
|
21
|
+
*
|
|
22
|
+
* 传输层理论上不会永远不 settle,但一次挂住的 fetch(半开连接、Host 卡死)会让
|
|
23
|
+
* "在飞请求跳过"变成**永久**跳过——回到页面再也不强制刷新。超过这个时长就当作
|
|
24
|
+
* 那次请求已经失败(迟到的响应仍会自己 setData,重发的这次不会破坏什么)。
|
|
25
|
+
*/
|
|
26
|
+
export declare const LOAD_IN_FLIGHT_MAX_MS = 60000;
|
|
27
|
+
/**
|
|
28
|
+
* 这次 `list` 请求现在还算在飞吗?
|
|
29
|
+
*
|
|
30
|
+
* @param now - 当前时刻(毫秒)。
|
|
31
|
+
* @param startedAt - 那次请求开始的时刻;没有在飞的请求为 `undefined`。
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadStillInFlight(now: number, startedAt: number | undefined): boolean;
|
|
34
|
+
/** @see shouldForceRefresh */
|
|
35
|
+
export interface ForceRefreshInput {
|
|
36
|
+
/** 当前时刻(毫秒;真实调用是 `Date.now()`,门禁注入假时钟)。 */
|
|
37
|
+
now: number;
|
|
38
|
+
/** 上一次强制刷新的时刻;从未刷新过为 `undefined`。 */
|
|
39
|
+
lastForceAt: number | undefined;
|
|
40
|
+
/** 页面当前是否可见(`document.hidden === false`)。 */
|
|
41
|
+
visible: boolean;
|
|
42
|
+
/** 是否已有 `list` 请求在飞(那一次请求会带回最新数据)。 */
|
|
43
|
+
inFlight?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 这一刻要不要为了"用户回来了"强制刷新一次?
|
|
47
|
+
*
|
|
48
|
+
* @param input - 见 {@link ForceRefreshInput}。
|
|
49
|
+
* @returns true = 调用方应立刻 `load(true)` 并记下 `now`。
|
|
50
|
+
*/
|
|
51
|
+
export declare function shouldForceRefresh(input: ForceRefreshInput): boolean;
|