dsh-remote-vs 0.26.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.
Files changed (75) hide show
  1. package/README.en.md +112 -28
  2. package/README.md +84 -25
  3. package/THIRD-PARTY-NOTICES.md +7 -2
  4. package/lib/client.js +1237 -254
  5. package/lib/index.js +821 -17
  6. package/lib/types/changes/recorder.d.ts +119 -2
  7. package/lib/types/client/CodeEditor.d.ts +29 -0
  8. package/lib/types/client/OutlinePanel.d.ts +22 -0
  9. package/lib/types/client/ProcessesSection.d.ts +19 -0
  10. package/lib/types/client/api.d.ts +22 -2
  11. package/lib/types/client/blame-model.d.ts +77 -0
  12. package/lib/types/client/changes/apply-failure.d.ts +41 -0
  13. package/lib/types/client/changes/block-confirm.d.ts +97 -0
  14. package/lib/types/client/changes/diff-outcome.d.ts +56 -0
  15. package/lib/types/client/changes/freshness.d.ts +51 -0
  16. package/lib/types/client/changes/model.d.ts +19 -1
  17. package/lib/types/client/changes/session-diff.d.ts +100 -0
  18. package/lib/types/client/changes/staleness.d.ts +98 -0
  19. package/lib/types/client/changes/turn-reverted.d.ts +82 -0
  20. package/lib/types/client/changes/turn-view.d.ts +131 -0
  21. package/lib/types/client/changes/undo-affordance.d.ts +44 -10
  22. package/lib/types/client/changes/undo-target.d.ts +12 -0
  23. package/lib/types/client/i18n.d.ts +1 -1
  24. package/lib/types/client/outline-model.d.ts +59 -0
  25. package/lib/types/client/scm/actions.d.ts +12 -1
  26. package/lib/types/client/store.d.ts +109 -1
  27. package/lib/types/client/vsc/blame.d.ts +19 -0
  28. package/lib/types/client/vsc/change-marks.d.ts +21 -0
  29. package/lib/types/client/vsc/kit.d.ts +0 -2
  30. package/lib/types/client/vsc/preview-document.d.ts +46 -0
  31. package/lib/types/client/vsc/preview-model.d.ts +31 -0
  32. package/lib/types/client/vsc/preview-services.d.ts +24 -0
  33. package/lib/types/git-ops.d.ts +18 -0
  34. package/lib/types/processes.d.ts +43 -0
  35. package/lib/types/protocol.d.ts +133 -1
  36. package/package.json +2 -1
  37. package/src/changes/recorder.ts +851 -8
  38. package/src/client/CodeEditor.tsx +86 -4
  39. package/src/client/EditorPane.tsx +581 -41
  40. package/src/client/MonitorView.tsx +16 -5
  41. package/src/client/OutlinePanel.tsx +287 -0
  42. package/src/client/ProcessesSection.tsx +292 -0
  43. package/src/client/api.ts +38 -3
  44. package/src/client/blame-model.ts +242 -0
  45. package/src/client/changes/ChangesDock.tsx +539 -54
  46. package/src/client/changes/apply-failure.ts +73 -0
  47. package/src/client/changes/block-confirm.ts +180 -0
  48. package/src/client/changes/changes.css +45 -0
  49. package/src/client/changes/diff-outcome.ts +97 -0
  50. package/src/client/changes/freshness.ts +68 -0
  51. package/src/client/changes/model.ts +56 -1
  52. package/src/client/changes/session-diff.ts +187 -0
  53. package/src/client/changes/staleness.ts +148 -0
  54. package/src/client/changes/turn-reverted.ts +254 -0
  55. package/src/client/changes/turn-view.ts +195 -0
  56. package/src/client/changes/undo-affordance.ts +295 -63
  57. package/src/client/changes/undo-target.ts +12 -0
  58. package/src/client/i18n.ts +294 -2
  59. package/src/client/index.tsx +4 -0
  60. package/src/client/outline-model.ts +775 -0
  61. package/src/client/scm/DiffView.tsx +32 -13
  62. package/src/client/scm/HistoryPanel.tsx +38 -1
  63. package/src/client/scm/actions.ts +55 -2
  64. package/src/client/store.tsx +446 -21
  65. package/src/client/vsc/blame.ts +147 -0
  66. package/src/client/vsc/change-marks.ts +21 -0
  67. package/src/client/vsc/kit.tsx +3 -11
  68. package/src/client/vsc/preview-document.tsx +326 -0
  69. package/src/client/vsc/preview-model.ts +216 -0
  70. package/src/client/vsc/preview-services.ts +118 -0
  71. package/src/client/vsc/vsc.css +965 -39
  72. package/src/git-ops.ts +34 -0
  73. package/src/processes.ts +177 -0
  74. package/src/protocol.ts +138 -1
  75. package/src/routes.ts +138 -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 `maxAgeMs`, re-scan — so a
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
- /** Recompute the panel's list from the scans currently known. */
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).
@@ -52,6 +52,7 @@ export interface CodeEditorHandle {
52
52
  getChangeStale: () => boolean;
53
53
  }
54
54
  import { type ChangeMark, type ChangeSet } from './vsc/change-marks.ts';
55
+ import type { BlameLine } from './blame-model.ts';
55
56
  /**
56
57
  * The editor surface is OPAQUE and scrolls in the editor's own palette
57
58
  * (`vsc/editor-theme.ts`): a code editor is not a translucent DSH panel, and
@@ -102,6 +103,19 @@ export declare const CodeEditor: import("react").ForwardRefExoticComponent<{
102
103
  * 加入本功能之前完全一致。
103
104
  */
104
105
  changeSet?: ChangeSet | null;
106
+ /**
107
+ * Line→commit map for the inline blame gutter. `undefined`/empty removes the
108
+ * gutter entirely, so diff panes and files without blame data keep their old
109
+ * layout.
110
+ */
111
+ blame?: ReadonlyMap<number, BlameLine> | null;
112
+ /** Clicking a blame cell asks the pane to reveal that commit. */
113
+ onOpenBlame?: (entry: BlameLine) => void;
114
+ /**
115
+ * Reports the visible 1-based line range. The pane uses it to fetch blame one
116
+ * window at a time; CodeMirror is the only code that knows the viewport.
117
+ */
118
+ onViewport?: (first: number, last: number) => void;
105
119
  /**
106
120
  * 用户在某一处改动上按下「撤销这处改动」时回调。
107
121
  *
@@ -112,6 +126,21 @@ export declare const CodeEditor: import("react").ForwardRefExoticComponent<{
112
126
  onUndoChange?: (mark: ChangeMark) => void;
113
127
  /** 悬浮按钮的文案(由调用方按 `kind` 给出它的 i18n 说法)。 */
114
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
+ };
115
144
  /** 改动点跳转的目标行(1-based),配合 `revealHunkNonce` 重跳同一行。 */
116
145
  revealHunkLine?: number;
117
146
  /** 改动点跳转的 nonce(同 `revealNonce` 的道理)。 */
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 符号大纲浮层:可筛选的符号列表 + ↑↓/Enter/点击跳转。
3
+ *
4
+ * 只在打开时挂载(父组件用 `undefined` 表示关闭),所以「关闭」就是卸载 —— 不会
5
+ * 留下第二个 `isOpen` 状态要同步,也不会在关闭后留一个偷键盘的监听器。条目由
6
+ * `outline-model.ts` 的纯函数产出;这里只负责像素、焦点和按键。
7
+ *
8
+ * PORTAL 到 `<body>`:编辑器有三种座位(侧栏 / 中间 / 浮窗),浮层若留在原 DOM
9
+ * 里会被祖先的 `overflow: hidden` 裁掉。`.rvs-portal` 负责声明 `--rvs-*` token
10
+ * 子集 —— portal 之后已经不在 `.rvs-root` 作用域内,缺了它颜色/边框全是空值。
11
+ */
12
+ import { type ReactNode } from 'react';
13
+ import { type OutlineEntry } from './outline-model.ts';
14
+ export declare function OutlinePanel(props: {
15
+ t: (key: string) => string;
16
+ /** 远端绝对路径(判断语言 + 标题)。 */
17
+ path: string;
18
+ /** 实时缓冲区全文:dirty 时必须来自编辑器,不是 `tab.text`。 */
19
+ text: string;
20
+ onPick: (entry: OutlineEntry) => void;
21
+ onClose: () => void;
22
+ }): ReactNode;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Remote process table shown on the monitor page.
3
+ *
4
+ * One bounded snapshot per selected host, polled only while the monitor page and
5
+ * the browser tab are both visible. Killing is always confirmed and always goes
6
+ * through the Host route (which validates the PID against its own snapshot), so
7
+ * the browser never builds a shell command from a process row.
8
+ */
9
+ import { type ReactNode } from 'react';
10
+ import type { RemoteHostSummary } from '../protocol.ts';
11
+ export declare const PROCESS_POLL_MS = 5000;
12
+ export declare function ProcessesSection(props: {
13
+ t: (key: string) => string;
14
+ hosts: RemoteHostSummary[];
15
+ aliases: string[];
16
+ visible: boolean;
17
+ paused: boolean;
18
+ intervalMs: number;
19
+ }): ReactNode;
@@ -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 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 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';
5
5
  export declare class RemoteApiError extends Error {
6
6
  readonly status: number;
7
7
  /**
@@ -249,8 +249,24 @@ export declare const api: {
249
249
  * is opened for review.
250
250
  */
251
251
  changes: {
252
- list: (sessionId: string, force?: boolean, repoSubdir?: string) => Promise<RemoteChangesSummary | null>;
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>;
@@ -295,6 +311,10 @@ export declare const api: {
295
311
  * found" (see `RemoteListenPortsResult`).
296
312
  */
297
313
  listenPorts: (alias: string) => Promise<RemoteListenPortsResult>;
314
+ /** One bounded remote process table (per-host cache on the Host side). */
315
+ processes: (alias: string, refresh?: boolean) => Promise<RemoteProcessesResult>;
316
+ /** Signal one PID from the latest snapshot; the route rejects unknown PIDs. */
317
+ killProcess: (alias: string, pid: number, signal: "TERM" | "KILL") => Promise<RemoteProcessKillResult>;
298
318
  /**
299
319
  * One host's live metrics sample.
300
320
  *
@@ -0,0 +1,77 @@
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
+ import type { GitCommit } from '../protocol.ts';
7
+ /** One blamed line: 1-based final line number plus the commit that owns it. */
8
+ export interface BlameLine {
9
+ line: number;
10
+ hash: string;
11
+ author: string;
12
+ email: string;
13
+ /** Author timestamp, seconds since the epoch (git's `author-time`). */
14
+ time: number;
15
+ summary: string;
16
+ }
17
+ /** A run of consecutive lines owned by the same commit. */
18
+ export interface BlameRun {
19
+ from: number;
20
+ to: number;
21
+ hash: string;
22
+ }
23
+ /** One `--follow` file-history row, plus the name the file had in that commit. */
24
+ export interface FileHistoryCommit extends GitCommit {
25
+ /** Path to show/diff for THIS commit (old name before a rename). */
26
+ path: string;
27
+ /** Rename source when this commit renamed the file. */
28
+ origPath?: string;
29
+ }
30
+ /**
31
+ * Parse `git blame --line-porcelain`.
32
+ *
33
+ * `--line-porcelain` repeats the commit header and metadata for every line (no
34
+ * previous-commit grouping), which keeps this parser stateless: a header starts
35
+ * a record, the metadata lines fill it, and the tab-prefixed content line ends
36
+ * it. Lines that do not match the shape are ignored rather than aborting the
37
+ * whole read — a partially understood blame is still useful.
38
+ */
39
+ export declare function parseBlamePorcelain(stdout: string): BlameLine[];
40
+ /** Group consecutive lines of one commit; non-adjacent runs stay separate. */
41
+ export declare function blameRuns(rows: readonly BlameLine[]): BlameRun[];
42
+ /** Short author name for the narrow blame gutter. */
43
+ export declare function shortAuthor(author: string): string;
44
+ /**
45
+ * Relative age labels, deliberately compact (`now`, `5m`, `3h`, `2d`, `4w`,
46
+ * `3mo`, `2y`) because this text lives in a gutter.
47
+ */
48
+ export declare function relativeBlameTime(timeSeconds: number, nowSeconds?: number): string;
49
+ /** One-line gutter label: author initials/name plus relative age. */
50
+ export declare function blameLabel(row: BlameLine, nowSeconds?: number): string;
51
+ /**
52
+ * Hover text: full attribution. The browser renders `title` as plain text, so
53
+ * no markup is needed (and no translator dependency leaks into the model).
54
+ */
55
+ export declare function blameTitle(row: BlameLine): string;
56
+ /** False for git's all-zero "not committed yet" pseudo-commit. */
57
+ export declare function isCommittedBlame(hash: string): boolean;
58
+ /**
59
+ * The next `-L` window to request, or undefined when the viewport is covered.
60
+ *
61
+ * Pure and exported so the gate can prove the "3000-line file only asks for
62
+ * the visible window" requirement without a browser. `overscan` keeps a small
63
+ * buffer above/below so a normal scroll does not immediately need a new call.
64
+ */
65
+ export declare function planBlameWindow(first: number, last: number, total: number, covered: ReadonlySet<number>, overscan?: number): {
66
+ from: number;
67
+ to: number;
68
+ } | undefined;
69
+ /**
70
+ * Parse `git log --follow --name-status -M` output into per-commit rows.
71
+ *
72
+ * `--follow` reports the file under its name AT THAT COMMIT. Starting from the
73
+ * current name and walking newest→oldest, each rename row supplies the next
74
+ * (older) name, so a click on an old history row opens the right path instead
75
+ * of an empty diff for the current name.
76
+ */
77
+ export declare function parseFileHistory(stdout: string, currentPath: string): FileHistoryCommit[];
@@ -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;