dsh-remote-vs 0.27.0 → 0.28.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 +110 -19
- package/README.md +82 -19
- package/lib/client.js +6789 -6607
- package/lib/index.js +546 -16
- package/lib/types/changes/recorder.d.ts +119 -2
- package/lib/types/client/CodeEditor.d.ts +15 -0
- package/lib/types/client/api.d.ts +17 -1
- 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/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/protocol.d.ts +99 -1
- package/package.json +1 -1
- package/src/changes/recorder.ts +851 -8
- package/src/client/CodeEditor.tsx +43 -3
- package/src/client/EditorPane.tsx +64 -7
- package/src/client/api.ts +30 -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/i18n.ts +102 -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 +6642 -6509
- package/src/protocol.ts +101 -1
- package/src/routes.ts +20 -9
|
@@ -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` 的道理)。 */
|
|
@@ -249,8 +249,24 @@ export declare const api: {
|
|
|
249
249
|
* is opened for review.
|
|
250
250
|
*/
|
|
251
251
|
changes: {
|
|
252
|
-
|
|
252
|
+
/**
|
|
253
|
+
* @param force - `⟳` semantics: tracked scan now AND re-arm the slow new-file
|
|
254
|
+
* walk (expensive; a deliberate click).
|
|
255
|
+
* @param trackedOnly - "user came back to the page": tracked files now, but the
|
|
256
|
+
* slow walk keeps its cadence/write-off (see `RemoteChangesListRequest`).
|
|
257
|
+
*/
|
|
258
|
+
list: (sessionId: string, force?: boolean, repoSubdir?: string, trackedOnly?: boolean) => Promise<RemoteChangesSummary | null>;
|
|
253
259
|
diff: (sessionId: string, path: string, repoSubdir?: string) => Promise<RemoteChangesDiff | null>;
|
|
260
|
+
/**
|
|
261
|
+
* The same comparison, but against the previous completed turn's close
|
|
262
|
+
* instead of the session baseline (the panel's 「本轮」 scope).
|
|
263
|
+
*
|
|
264
|
+
* Answers `unavailable` / `stale` (with a reason) instead of hunks when the
|
|
265
|
+
* host has no cached per-turn contents or the file moved on after the turn —
|
|
266
|
+
* the client must fall back to `diff` (session view) rather than paint lines
|
|
267
|
+
* that no longer exist.
|
|
268
|
+
*/
|
|
269
|
+
turnDiff: (sessionId: string, path: string, repoSubdir?: string) => Promise<RemoteChangesDiff | null>;
|
|
254
270
|
};
|
|
255
271
|
setRoutingMode: (mode: "off" | "shadow" | "enforce") => Promise<"off" | "shadow" | "enforce">;
|
|
256
272
|
getViewSettings: () => Promise<RemoteViewSettings>;
|
|
@@ -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;
|
|
@@ -26,6 +26,23 @@ import type { ChangeMark, ChangeSet, InlineRange, RemovedChip } from '../vsc/cha
|
|
|
26
26
|
export type { ChangeMark, ChangeSet, InlineRange, RemovedChip };
|
|
27
27
|
/** An empty set (a file that ended up unchanged). */
|
|
28
28
|
export declare const EMPTY_CHANGE_SET: ChangeSet;
|
|
29
|
+
/**
|
|
30
|
+
* 建立这批标记时随数据一起带下来的元信息(都可省略)。
|
|
31
|
+
*
|
|
32
|
+
* 两者各自服务一个上层判断,而且都**只能在这一层算**:块标识要用 hunk 头的四个
|
|
33
|
+
* 数字 + 文件身份;状态来自列表行。行数统计也在这里算(面板的过期判定要用)。
|
|
34
|
+
*/
|
|
35
|
+
export interface ChangeSetMeta {
|
|
36
|
+
/**
|
|
37
|
+
* 文件的**远端绝对路径**(块标识的前半段,见 `changes/block-confirm.ts`)。
|
|
38
|
+
*
|
|
39
|
+
* 用绝对路径而不是显示路径:显示路径是相对会话根的,两个绑定/两个仓库子目录
|
|
40
|
+
* 可以有相同的显示路径 + 相同的 hunk 头,那样它们的块会被认成同一块。
|
|
41
|
+
*/
|
|
42
|
+
path?: string;
|
|
43
|
+
/** 列表行的状态字母(`RemoteChangedFile.status`)。 */
|
|
44
|
+
status?: string;
|
|
45
|
+
}
|
|
29
46
|
/**
|
|
30
47
|
* Build the editable set for one file.
|
|
31
48
|
*
|
|
@@ -33,6 +50,7 @@ export declare const EMPTY_CHANGE_SET: ChangeSet;
|
|
|
33
50
|
* @param stamp - identity of the comparison (file + baseline + turn).
|
|
34
51
|
* @param filePatch - the host's whole-file reverse patch, when it served one
|
|
35
52
|
* (see `ChangeSet.filePatch`); '' / missing = nothing to revert as a whole.
|
|
53
|
+
* @param meta - 行数 / 状态 / 块标识的来处(见 {@link ChangeSetMeta})。
|
|
36
54
|
* @returns the mark set the editor paints, or {@link EMPTY_CHANGE_SET}.
|
|
37
55
|
*/
|
|
38
|
-
export declare function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string, filePatch?: string): ChangeSet;
|
|
56
|
+
export declare function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string, filePatch?: string, meta?: ChangeSetMeta): ChangeSet;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 面板一行 → 一份**只读**的并排 diff(数据来源是会话账本,不是 git 工作区)。
|
|
3
|
+
*
|
|
4
|
+
* 面板原来只能"打开文件 + 就地画标记":看这一处改动的上下文,得先打开文件、再靠
|
|
5
|
+
* 行背景去读。SCM 的并排 diff(`scm/DiffView.tsx`)能给出"改前 / 改后"两栏,但它
|
|
6
|
+
* 读的是 `git diff`(工作区对索引/HEAD),与会话账本**不是同一个基线**:账本比的是
|
|
7
|
+
* 会话起点,工作区里可能还有会话开始之前就存在的未提交改动。
|
|
8
|
+
*
|
|
9
|
+
* 于是这里补的是账本这一侧的两块材料,让并排渲染器能直接复用:
|
|
10
|
+
* 1. **改前全文**:Host 只给 hunk(`RemoteChangesDiff.hunks`),不给基线内容。但
|
|
11
|
+
* "改后"全文能读(`fileOp.read`),而 unified hunk 已经说清了每一次删除/新增 ——
|
|
12
|
+
* 把删除行填回去、把新增行跳过,就**精确**还原出改前全文(纯函数,可断言);
|
|
13
|
+
* 2. **一份完整的 unified patch 文本**:hunk 里带着 `@@` 头与逐行内容,拼起来就是
|
|
14
|
+
* `parseUnifiedDiff` / `buildDiffModel` 要的输入。**不**用 `diff.patch`:整文件
|
|
15
|
+
* 反向补丁在"新建文件"和"字节截断"两种情况下是空的,而 hunk 永远在。
|
|
16
|
+
*
|
|
17
|
+
* 两栏都只能**看**:这是会话的历史比较,不是可编辑的工作区副本(DiffView 按
|
|
18
|
+
* `EditorTab.sessionDiff` 关掉编辑与 hunk 写操作)。
|
|
19
|
+
*/
|
|
20
|
+
import type { RemoteChangedFile, RemoteChangesDiff, UnifiedHunk } from '../../protocol.ts';
|
|
21
|
+
import type { DiffPayload } from '../scm/actions.ts';
|
|
22
|
+
import { type DiffNotice } from './diff-outcome.ts';
|
|
23
|
+
/**
|
|
24
|
+
* 这一行能不能给出会话 diff。
|
|
25
|
+
*
|
|
26
|
+
* 二进制/非 UTF-8 文件没有可读的文本 hunk,超大文件连字节都被 Host 扣下 —— 这两种
|
|
27
|
+
* 行"查看差异"只会得到一个空视图,所以菜单项直接不出现(回到"打开文件")。
|
|
28
|
+
*/
|
|
29
|
+
export declare function canShowChangeDiff(file: Pick<RemoteChangedFile, 'binary' | 'oversized'>): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 由"改后全文"与 hunk 还原"改前全文"。
|
|
32
|
+
*
|
|
33
|
+
* 依据是 unified diff 的定义:hunk 之外两侧相同,hunk 内 `-` 行只存在于改前、`+` 行
|
|
34
|
+
* 只存在于改后、` ` 行两边都有。所以沿改后文件走一遍,遇到 `-` 就把该行填进改前,
|
|
35
|
+
* 遇到 `+` 就跳过,其余照抄即可 —— 不需要基线内容,也不需要浏览器端再算一次 diff。
|
|
36
|
+
*
|
|
37
|
+
* 防御:hunk 头给出的 `newStart` 若落后于游标(重叠 / 乱序的坏数据),按游标继续,
|
|
38
|
+
* 绝不回退(回退会重复输出行,把并排视图整体错位)。
|
|
39
|
+
*
|
|
40
|
+
* @param newText - 改后全文(远端当前内容;读不到时传 '')。
|
|
41
|
+
* @param hunks - Host 给的 hunk(按行号升序)。
|
|
42
|
+
* @returns 改前全文(行之间用 `\n`,末尾不带换行;`''` = 改前没有内容)。
|
|
43
|
+
*/
|
|
44
|
+
export declare function beforeTextOf(newText: string, hunks: readonly UnifiedHunk[]): string;
|
|
45
|
+
/**
|
|
46
|
+
* 把 hunk 拼成一份完整的 unified patch 文本(`buildDiffModel` 的输入)。
|
|
47
|
+
*
|
|
48
|
+
* 用 `diff --git` 开头:`parseUnifiedDiff` 以它为文件块的起点,缺了就一个 hunk 都
|
|
49
|
+
* 解析不出来(面板会显示"没有差异")。hunk 头按 Host 给的四个数字原样写回。
|
|
50
|
+
*
|
|
51
|
+
* @param display - 文件显示路径(写进 `a/` `b/` 两行;只用于展示与解析配对)。
|
|
52
|
+
* @param hunks - Host 给的 hunk。
|
|
53
|
+
* @returns patch 文本;没有 hunk 时 `''`。
|
|
54
|
+
*/
|
|
55
|
+
export declare function unifiedPatchOf(display: string, hunks: readonly UnifiedHunk[]): string;
|
|
56
|
+
/**
|
|
57
|
+
* 会话 diff 的完整载荷(`DiffPayload`,`scm/DiffView.tsx` 的入参)。
|
|
58
|
+
*
|
|
59
|
+
* 没有 hunk、或连路径都拼不出来时返回 `undefined`(调用方据此说"没有可显示的差异"),
|
|
60
|
+
* 而不是给一张会被渲染成"整篇都改了"的空表。
|
|
61
|
+
*
|
|
62
|
+
* @param diff - 账本给出的这份文件比较(必须是 `kind: 'text'`)。
|
|
63
|
+
* @param newText - 远端当前内容(读不到时传 '':改后一栏为空,仍然能看改前)。
|
|
64
|
+
* @param display - 面板给的显示路径(用来在 `diff.display` 为空时兜底)。
|
|
65
|
+
* @returns 载荷;没有 hunk / 没有可用路径时 `undefined`。
|
|
66
|
+
*/
|
|
67
|
+
export declare function sessionDiffPayload(diff: RemoteChangesDiff, newText: string, display?: string): DiffPayload | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* 账本 diff + 一次"改后"读取的**可见结论**。
|
|
70
|
+
*
|
|
71
|
+
* 为什么需要它(审核 M2/S4):两种"数据不全"会让并排视图变成假的:
|
|
72
|
+
* 1. `diff.truncated` —— Host 的 after 文本被字节上限扣下,hunk 是 before 对空文本
|
|
73
|
+
* 算出来的(整篇假差异),撤销也不可能成立;
|
|
74
|
+
* 2. `read.truncated` —— 改后一栏的读取本身被截断(8 MiB 上限),`beforeTextOf`
|
|
75
|
+
* 会拿"完整基线"去对"前缀正文",两栏整体错位。
|
|
76
|
+
* 两种情形都不打开,只给一句说明。二进制读取同理(没有可读文本可比)。
|
|
77
|
+
*/
|
|
78
|
+
export interface SessionDiffRead {
|
|
79
|
+
/** 远端当前内容(读失败时传 '',改后一栏空着、改前仍可看)。 */
|
|
80
|
+
text: string;
|
|
81
|
+
/** 读取撞上了 8 MiB 上限:`text` 只是前缀。 */
|
|
82
|
+
truncated?: true;
|
|
83
|
+
/** 读取判定为二进制。 */
|
|
84
|
+
binary?: true;
|
|
85
|
+
}
|
|
86
|
+
export type SessionDiffOutcome = {
|
|
87
|
+
ok: true;
|
|
88
|
+
payload: DiffPayload;
|
|
89
|
+
} | {
|
|
90
|
+
ok: false;
|
|
91
|
+
notice: DiffNotice;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* 把"账本 diff + 改后读取"翻成"能打开的两栏"或"必须说明的结论"。
|
|
95
|
+
*
|
|
96
|
+
* @param diff - 账本给出的这份比较(`null` = 没拿到)。
|
|
97
|
+
* @param read - 改后一栏的读取结果。
|
|
98
|
+
* @param display - 面板给的显示路径(账本行偶尔给 '')。
|
|
99
|
+
*/
|
|
100
|
+
export declare function sessionDiffOutcome(diff: RemoteChangesDiff | null, read: SessionDiffRead, display?: string): SessionDiffOutcome;
|