@spzxg/cli-ui 0.6.13 → 0.6.18
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/CHANGELOG.md +108 -2
- package/README.md +140 -7
- package/dist/{cli-ui-embed-CXaGT9e4.js → cli-ui-embed-Dsw7A8BQ.js} +20333 -19872
- package/dist/{cli-ui-index-bMQJjEBW.js → cli-ui-index-CHFgaDHY.js} +2 -2
- package/dist/{cli-ui-jszip.min-D_w3a6AF.js → cli-ui-jszip.min-DDRprLiN.js} +1 -1
- package/dist/{cli-ui-jszip.min-AMeWMDT5.js → cli-ui-jszip.min-Dw9DMuD5.js} +2 -2
- package/dist/{cli-ui-xlsx-DMzew4IO.js → cli-ui-xlsx-BUG2_Azh.js} +1 -1
- package/dist/cli-ui.css +1 -1
- package/dist/cli-ui.js +1 -1
- package/package.json +1 -1
- package/src/board/BrowserPane.tsx +93 -30
- package/src/board/ChangesPane.tsx +86 -62
- package/src/board/CliBoard.tsx +65 -30
- package/src/board/FileViewer.tsx +49 -13
- package/src/board/context.ts +38 -7
- package/src/board/diffLines.ts +46 -0
- package/src/board/diffRefresh.ts +63 -0
- package/src/board/fileDiff.tsx +117 -0
- package/src/board/fileKind.ts +5 -3
- package/src/board/fileScope.ts +4 -2
- package/src/board/fileWatch.ts +59 -9
- package/src/board/linkage.ts +68 -0
- package/src/board/pathResolve.ts +108 -0
- package/src/board/useBoardUpload.tsx +7 -7
- package/src/board/workspace.ts +7 -1
- package/src/chat/CliChat.tsx +197 -216
- package/src/chat/Composer.tsx +10 -9
- package/src/chat/queueEdit.ts +27 -0
- package/src/components.tsx +2 -2
- package/src/core/blocks.ts +4 -1
- package/src/core/client.ts +86 -9
- package/src/core/config.ts +1 -1
- package/src/core/conversation.ts +23 -5
- package/src/core/documentUpload.ts +22 -5
- package/src/core/provider.tsx +14 -8
- package/src/core/store.ts +307 -63
- package/src/core/types.ts +49 -0
- package/src/elements.tsx +8 -5
- package/src/msglist/CliMsgList.tsx +30 -9
- package/src/operator/node/AgentConnect.tsx +28 -29
- package/src/operator/node/AppearancePanel.tsx +1 -1
- package/src/operator/node/BranchHistory.tsx +11 -7
- package/src/operator/node/BranchNavigator.tsx +1 -1
- package/src/operator/node/BrowserPane.tsx +7 -7
- package/src/operator/node/Chat.tsx +53 -272
- package/src/operator/node/CommandPalette.tsx +1 -1
- package/src/operator/node/Composer.tsx +13 -6
- package/src/operator/node/Layout.tsx +1 -1
- package/src/operator/node/Markdown.tsx +6 -36
- package/src/operator/node/Modal.tsx +1 -1
- package/src/operator/node/OnboardingWizard.tsx +11 -9
- package/src/operator/node/Orchestrator.tsx +18 -8
- package/src/operator/node/ProjectLanding.tsx +1 -1
- package/src/operator/node/ProjectsColumn.tsx +1 -1
- package/src/operator/node/ProviderAuth.tsx +16 -16
- package/src/operator/node/RunSwitch.tsx +1 -1
- package/src/operator/node/Services.tsx +1 -1
- package/src/operator/node/SessionRail.tsx +55 -19
- package/src/operator/node/SessionView.tsx +18 -16
- package/src/operator/node/SettingsView.tsx +1 -1
- package/src/operator/node/TaskBoard.tsx +1 -1
- package/src/operator/node/TaskChanges.tsx +83 -108
- package/src/operator/node/TaskHero.tsx +5 -5
- package/src/operator/node/TasksColumn.tsx +1 -1
- package/src/operator/node/Transcript.tsx +15 -250
- package/src/operator/node/Welcome.tsx +1 -1
- package/src/operator/node/WorktreePrune.tsx +1 -1
- package/src/operator/node/api.ts +17 -0
- package/src/operator/node/boardBackend.ts +4 -1
- package/src/operator/node/boardEvents.ts +17 -3
- package/src/operator/node/boardInteraction.ts +7 -4
- package/src/operator/node/boardState.ts +23 -14
- package/src/operator/node/composerDraft.ts +22 -0
- package/src/operator/node/fileLinks.ts +4 -38
- package/src/operator/node/format.ts +13 -104
- package/src/operator/node/github.tsx +14 -14
- package/src/operator/node/liveStream.ts +47 -6
- package/src/operator/node/modals.tsx +59 -22
- package/src/operator/node/recheckOnReturn.ts +28 -0
- package/src/operator/node/shared.tsx +10 -50
- package/src/operator/node/types.ts +9 -0
- package/src/operator/node/useOrchestrator.ts +9 -8
- package/src/operator/node/useRecaps.ts +15 -4
- package/src/operator/node/useTaskStream.ts +2 -2
- package/src/operator.base.css +9 -4
- package/src/operator.css +9 -4
- package/src/styles.css +22 -8
- package/src/ui/Markdown.tsx +42 -21
- package/src/ui/Popover.tsx +1 -1
- package/src/ui/QueuedMessages.tsx +58 -15
- package/src/ui/SubagentChat.tsx +42 -6
- package/src/ui/Transcript.tsx +19 -14
- package/src/ui/fileLinks.ts +6 -3
- package/src/ui/format.ts +27 -9
- package/src/ui/icons.tsx +2 -0
- package/src/ui/shared.tsx +11 -7
- package/src/ui/transcriptModel.ts +40 -9
- package/src/ui/useTranscriptWindow.ts +253 -0
- package/src/operator/node/icons.tsx +0 -88
- package/src/operator/node/transcriptModel.ts +0 -129
package/dist/cli-ui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as a, b as i, d as r, e as t, f as o, h as C, i as l, j as n, k as m, m as d, l as u, n as w, o as B, p as f } from "./cli-ui-embed-
|
|
1
|
+
import { C as a, b as i, d as r, e as t, f as o, h as C, i as l, j as n, k as m, m as d, l as u, n as w, o as B, p as f } from "./cli-ui-embed-Dsw7A8BQ.js";
|
|
2
2
|
export {
|
|
3
3
|
a as CliBoard,
|
|
4
4
|
i as CliBrowserView,
|
package/package.json
CHANGED
|
@@ -31,6 +31,9 @@ const SPECIAL_KEYS: Record<string, number> = {
|
|
|
31
31
|
Home: 36, End: 35, PageUp: 33, PageDown: 34,
|
|
32
32
|
};
|
|
33
33
|
const MOUSE_BUTTONS = ["left", "middle", "right"] as const;
|
|
34
|
+
/** 本机算连击的间隔和距离(与常见系统默认相近)。 */
|
|
35
|
+
const DOUBLE_CLICK_MS = 500;
|
|
36
|
+
const DOUBLE_CLICK_PX = 5;
|
|
34
37
|
const RETRY_MS = [1_000, 3_000, 8_000, 15_000];
|
|
35
38
|
const retryDelay = (attempt: number) => jitter(RETRY_MS[Math.min(attempt, RETRY_MS.length - 1)]);
|
|
36
39
|
/** 看的人满了(中枢回 429):别人退出才有位置,隔久一点再试。 */
|
|
@@ -39,6 +42,13 @@ const FULL_RETRY_MS = 20_000;
|
|
|
39
42
|
const nextTry = (err: { status?: number } | null | undefined, attempt: number) =>
|
|
40
43
|
err?.status === 409 ? Math.round(3_000 * (0.7 + Math.random() * 0.3)) : err && (err.status === 401 || err.status === 403) ? jitter(30_000) : err?.status === 429 ? jitter(FULL_RETRY_MS) : retryDelay(attempt);
|
|
41
44
|
|
|
45
|
+
/**
|
|
46
|
+
* 连续失败这么多次就停下,不再定时重试(约 1.5 分钟;人满约 2.5 分钟):显示「重试」,
|
|
47
|
+
* 网络恢复、页面回到前台、窗口重新获得焦点时自动再连。
|
|
48
|
+
*/
|
|
49
|
+
const MAX_TRIES = 8;
|
|
50
|
+
const GAVE_UP = "连接多次失败,已停止自动重试;网络恢复、回到页面或点「重试」时再连";
|
|
51
|
+
|
|
42
52
|
/** 接管时发了操作、这么久画面一点没变:提示「画面没有响应」,给重连。 */
|
|
43
53
|
const UNRESPONSIVE_MS = 8_000;
|
|
44
54
|
/** 输入队列最多攒这么多(请求卡住时不无限堆积;先丢鼠标移动)。 */
|
|
@@ -90,6 +100,7 @@ async function writeClipboard(text: string): Promise<boolean> {
|
|
|
90
100
|
interface BrowserFeed {
|
|
91
101
|
status: BrowserStatus | null;
|
|
92
102
|
setStatus: (s: BrowserStatus) => void;
|
|
103
|
+
statusSnapshot: MutableRefObject<{ revision: number; status: BrowserStatus | null }>;
|
|
93
104
|
/** 连接出了问题(正在重连)。 */
|
|
94
105
|
streamError: string | null;
|
|
95
106
|
/** 不会自动重连了(节点拒绝、没有权限):显示原因和「重试」。 */
|
|
@@ -115,7 +126,12 @@ interface BrowserFeed {
|
|
|
115
126
|
function useBrowserFeed(backend: BoardBackend, jobId: string, sink: MutableRefObject<((m: BrowserMessage) => void) | null>): BrowserFeed {
|
|
116
127
|
const visible = usePageVisible();
|
|
117
128
|
const [mode, setMode] = useState<"live" | "legacy">(backend.browserLive ? "live" : "legacy");
|
|
118
|
-
const [status,
|
|
129
|
+
const [status, saveStatus] = useState<BrowserStatus | null>(null);
|
|
130
|
+
const statusSnapshot = useRef<{ revision: number; status: BrowserStatus | null }>({ revision: 0, status: null });
|
|
131
|
+
const setStatus = useCallback((next: BrowserStatus) => {
|
|
132
|
+
statusSnapshot.current = { revision: statusSnapshot.current.revision + 1, status: next };
|
|
133
|
+
saveStatus(next);
|
|
134
|
+
}, []);
|
|
119
135
|
const [streamError, setStreamError] = useState<string | null>(null);
|
|
120
136
|
const [ended, setEnded] = useState<string | null>(null);
|
|
121
137
|
const [viewer, setViewer] = useState<string | null>(null);
|
|
@@ -123,7 +139,17 @@ function useBrowserFeed(backend: BoardBackend, jobId: string, sink: MutableRefOb
|
|
|
123
139
|
const [generation, setGeneration] = useState(0);
|
|
124
140
|
const [frames, setFrames] = useState<BrowserFramesState>({ state: "idle" });
|
|
125
141
|
const [retry, setRetry] = useState(0);
|
|
126
|
-
|
|
142
|
+
// 重试用完后停下:等网络恢复 / 回到页面 / 获得焦点再连(不定时重试)。
|
|
143
|
+
const gaveUp = useRef(false);
|
|
144
|
+
const reconnect = useCallback(() => { gaveUp.current = false; setEnded(null); setRetry((n) => n + 1); }, []);
|
|
145
|
+
const giveUp = useCallback(() => { gaveUp.current = true; setEnded(GAVE_UP); }, []);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
const wake = () => { if (gaveUp.current && document.visibilityState !== "hidden") reconnect(); };
|
|
148
|
+
window.addEventListener("online", wake);
|
|
149
|
+
window.addEventListener("focus", wake);
|
|
150
|
+
document.addEventListener("visibilitychange", wake);
|
|
151
|
+
return () => { window.removeEventListener("online", wake); window.removeEventListener("focus", wake); document.removeEventListener("visibilitychange", wake); };
|
|
152
|
+
}, [reconnect]);
|
|
127
153
|
const latest = useRef<BrowserFeed["latest"]["current"]>({ generation: 0, protocol: false });
|
|
128
154
|
const beginViewer = useCallback(() => {
|
|
129
155
|
const previous = latest.current;
|
|
@@ -200,6 +226,7 @@ function useBrowserFeed(backend: BoardBackend, jobId: string, sink: MutableRefOb
|
|
|
200
226
|
if (err) setStreamError(err.message);
|
|
201
227
|
// 409 还没派发:隔几秒再问;401 / 403 多半是宿主会话过期,30 秒后再试(续上会话就自己恢复);
|
|
202
228
|
// 其余(断线、中枢重启、人太多)按退避重连。
|
|
229
|
+
if (attempt >= MAX_TRIES) { giveUp(); return; }
|
|
203
230
|
timer = setTimeout(connect, nextTry(err, attempt++));
|
|
204
231
|
},
|
|
205
232
|
});
|
|
@@ -208,7 +235,7 @@ function useBrowserFeed(backend: BoardBackend, jobId: string, sink: MutableRefOb
|
|
|
208
235
|
};
|
|
209
236
|
connect();
|
|
210
237
|
return () => { alive = false; stop?.(); if (timer) clearTimeout(timer); };
|
|
211
|
-
}, [backend, jobId, mode, visible, retry, deliver, beginViewer]);
|
|
238
|
+
}, [backend, jobId, mode, visible, retry, deliver, beginViewer, giveUp, setStatus]);
|
|
212
239
|
|
|
213
240
|
// ── 旧版:状态一条(页面在后台时也断开,切回来再连:人多时少占中枢和节点的连接) ──
|
|
214
241
|
useEffect(() => {
|
|
@@ -230,6 +257,7 @@ function useBrowserFeed(backend: BoardBackend, jobId: string, sink: MutableRefOb
|
|
|
230
257
|
stopThis?.();
|
|
231
258
|
if (err && [400,404,405,410,501].includes(err.status)) { setEnded(err.message); return; }
|
|
232
259
|
if (err) setStreamError(err.message);
|
|
260
|
+
if (attempt >= MAX_TRIES) { giveUp(); return; }
|
|
233
261
|
timer = setTimeout(connect, nextTry(err, attempt++));
|
|
234
262
|
},
|
|
235
263
|
});
|
|
@@ -238,7 +266,7 @@ function useBrowserFeed(backend: BoardBackend, jobId: string, sink: MutableRefOb
|
|
|
238
266
|
};
|
|
239
267
|
connect();
|
|
240
268
|
return () => { alive = false; stop?.(); if (timer) clearTimeout(timer); };
|
|
241
|
-
}, [backend, jobId, mode, visible, retry]);
|
|
269
|
+
}, [backend, jobId, mode, visible, retry, giveUp, setStatus]);
|
|
242
270
|
|
|
243
271
|
// ── 旧版:画面一条(浏览器开着、页面可见时) ──
|
|
244
272
|
const legacyRunning = mode === "legacy" && visible && status?.state === "running";
|
|
@@ -260,6 +288,7 @@ function useBrowserFeed(backend: BoardBackend, jobId: string, sink: MutableRefOb
|
|
|
260
288
|
stopThis?.();
|
|
261
289
|
setViewer(null);
|
|
262
290
|
setReady(false);
|
|
291
|
+
if (attempt >= MAX_TRIES) { setFrames({ state: "idle" }); giveUp(); return; }
|
|
263
292
|
setFrames({ state: "retrying", ...(detail ? { detail } : {}) });
|
|
264
293
|
timer = setTimeout(connect, retryDelay(attempt++));
|
|
265
294
|
};
|
|
@@ -283,13 +312,13 @@ function useBrowserFeed(backend: BoardBackend, jobId: string, sink: MutableRefOb
|
|
|
283
312
|
};
|
|
284
313
|
connect();
|
|
285
314
|
return () => { alive = false; stop?.(); if (timer) clearTimeout(timer); };
|
|
286
|
-
}, [backend, jobId, legacyRunning, retry, deliver, beginViewer]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
315
|
+
}, [backend, jobId, legacyRunning, retry, deliver, beginViewer, giveUp]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
287
316
|
|
|
288
317
|
// 浏览器关了:上一个页面的地址、弹窗、画面都作废,重新打开时不先闪一下旧画面。
|
|
289
318
|
const running = status?.state === "running";
|
|
290
319
|
useEffect(() => { if (status && !running) latest.current = { generation: latest.current.generation, protocol: false }; }, [running, status]);
|
|
291
320
|
|
|
292
|
-
return { status, setStatus, streamError, ended, viewer, ready, generation, frames, paused: !visible, reconnect, latest };
|
|
321
|
+
return { status, setStatus, statusSnapshot, streamError, ended, viewer, ready, generation, frames, paused: !visible, reconnect, latest };
|
|
293
322
|
}
|
|
294
323
|
|
|
295
324
|
interface ScreenHandle { draw(base64: string, meta: FrameMeta | null): void; clear(): void }
|
|
@@ -319,10 +348,39 @@ const Screen = forwardRef<ScreenHandle, { human: boolean; inputEpoch: number; hi
|
|
|
319
348
|
const [fallback] = useState(() => typeof createImageBitmap !== "function");
|
|
320
349
|
const [fallbackFrame, setFallbackFrame] = useState<{src:string;meta:FrameMeta|null} | null>(null);
|
|
321
350
|
|
|
351
|
+
// 解码跟不上时只留最新的一帧等着:正在解一帧时来的新帧覆盖掉还没开始解的那帧,不为过期帧解码。
|
|
352
|
+
const decoding = useRef(false);
|
|
353
|
+
const pendingFrame = useRef<{ data: string; meta: FrameMeta | null } | null>(null);
|
|
354
|
+
const decode = useCallback((data: string, frameMeta: FrameMeta | null) => {
|
|
355
|
+
const type = data.startsWith("iVBOR") ? "image/png" : "image/jpeg";
|
|
356
|
+
const n = ++seq.current.next;
|
|
357
|
+
const generation = imageGeneration.current;
|
|
358
|
+
let bytes: Uint8Array;
|
|
359
|
+
try { bytes = decodeBase64(data); } catch { return; }
|
|
360
|
+
decoding.current = true;
|
|
361
|
+
const next = () => {
|
|
362
|
+
decoding.current = false;
|
|
363
|
+
const waiting = pendingFrame.current;
|
|
364
|
+
pendingFrame.current = null;
|
|
365
|
+
// clear 已丢弃旧页的待解码帧;这里留下的是清屏后新到的当前页帧。
|
|
366
|
+
if (waiting) decode(waiting.data, waiting.meta);
|
|
367
|
+
};
|
|
368
|
+
createImageBitmap(new Blob([bytes as BlobPart], { type })).then((bitmap) => {
|
|
369
|
+
const canvas = canvasRef.current;
|
|
370
|
+
if (!canvas || generation !== imageGeneration.current || n < seq.current.drawn) { bitmap.close(); return; }
|
|
371
|
+
seq.current.drawn = n;
|
|
372
|
+
meta.current = frameMeta;
|
|
373
|
+
if (canvas.width !== bitmap.width || canvas.height !== bitmap.height) { canvas.width = bitmap.width; canvas.height = bitmap.height; }
|
|
374
|
+
canvas.getContext("2d")?.drawImage(bitmap, 0, 0);
|
|
375
|
+
bitmap.close();
|
|
376
|
+
}, () => undefined).finally(next);
|
|
377
|
+
}, []);
|
|
378
|
+
|
|
322
379
|
useImperativeHandle(ref, () => ({
|
|
323
380
|
clear() {
|
|
324
381
|
imageGeneration.current++;
|
|
325
382
|
seq.current = { next: 0, drawn: 0 };
|
|
383
|
+
pendingFrame.current = null;
|
|
326
384
|
meta.current = null;
|
|
327
385
|
setFallbackFrame(null);
|
|
328
386
|
const canvas = canvasRef.current;
|
|
@@ -330,23 +388,11 @@ const Screen = forwardRef<ScreenHandle, { human: boolean; inputEpoch: number; hi
|
|
|
330
388
|
if (canvas) canvas.width = canvas.width;
|
|
331
389
|
},
|
|
332
390
|
draw(data, frameMeta) {
|
|
333
|
-
const type = data.startsWith("iVBOR") ? "image/png" : "image/jpeg";
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
const generation = imageGeneration.current;
|
|
337
|
-
let bytes: Uint8Array;
|
|
338
|
-
try { bytes = decodeBase64(data); } catch { return; }
|
|
339
|
-
createImageBitmap(new Blob([bytes as BlobPart], { type })).then((bitmap) => {
|
|
340
|
-
const canvas = canvasRef.current;
|
|
341
|
-
if (!canvas || generation !== imageGeneration.current || n < seq.current.drawn) { bitmap.close(); return; }
|
|
342
|
-
seq.current.drawn = n;
|
|
343
|
-
meta.current = frameMeta;
|
|
344
|
-
if (canvas.width !== bitmap.width || canvas.height !== bitmap.height) { canvas.width = bitmap.width; canvas.height = bitmap.height; }
|
|
345
|
-
canvas.getContext("2d")?.drawImage(bitmap, 0, 0);
|
|
346
|
-
bitmap.close();
|
|
347
|
-
}, () => undefined);
|
|
391
|
+
if (fallback) { const type = data.startsWith("iVBOR") ? "image/png" : "image/jpeg"; setFallbackFrame({src:`data:${type};base64,${data}`,meta:frameMeta}); return; }
|
|
392
|
+
if (decoding.current) { pendingFrame.current = { data, meta: frameMeta }; return; }
|
|
393
|
+
decode(data, frameMeta);
|
|
348
394
|
},
|
|
349
|
-
}), [fallback]);
|
|
395
|
+
}), [fallback, decode]);
|
|
350
396
|
|
|
351
397
|
// Identical image bytes may accompany updated CSS viewport metadata and
|
|
352
398
|
// need not trigger another load event in the fallback image element.
|
|
@@ -374,6 +420,15 @@ const Screen = forwardRef<ScreenHandle, { human: boolean; inputEpoch: number; hi
|
|
|
374
420
|
const lastMove = useRef(0);
|
|
375
421
|
// 按住的鼠标键:按住拖动时移动事件要带上它,网页里选中文字、拖滑块、拖拽才生效(CDP 按 button 判断是不是在拖)。
|
|
376
422
|
const pressed = useRef<(typeof MOUSE_BUTTONS)[number] | null>(null);
|
|
423
|
+
// 连击次数自己数:指针事件的 detail 在 Chromium 里恒为 0,照搬过去远端永远是单击,双击选词、双击打开都不生效。
|
|
424
|
+
// 同一个键、DOUBLE_CLICK_MS 内、相距不超过 DOUBLE_CLICK_PX 算连击(最多 3 次:三击选整段);松开带同样的次数。
|
|
425
|
+
const clicks = useRef<{ button: string; at: number; x: number; y: number; count: number } | null>(null);
|
|
426
|
+
const clickCount = (button: string, clientX: number, clientY: number) => {
|
|
427
|
+
const now = Date.now(), prev = clicks.current;
|
|
428
|
+
const count = prev && prev.button === button && now - prev.at <= DOUBLE_CLICK_MS && Math.abs(prev.x - clientX) <= DOUBLE_CLICK_PX && Math.abs(prev.y - clientY) <= DOUBLE_CLICK_PX ? Math.min(prev.count + 1, 3) : 1;
|
|
429
|
+
clicks.current = { button, at: now, x: clientX, y: clientY, count };
|
|
430
|
+
return count;
|
|
431
|
+
};
|
|
377
432
|
const lastPoint = useRef<{ clientX: number; clientY: number } | null>(null);
|
|
378
433
|
|
|
379
434
|
const mouse = (event: string, e: { clientX: number; clientY: number; altKey: boolean; ctrlKey: boolean; metaKey: boolean; shiftKey: boolean }, extra: Record<string, unknown> = {}) => {
|
|
@@ -392,7 +447,7 @@ const Screen = forwardRef<ScreenHandle, { human: boolean; inputEpoch: number; hi
|
|
|
392
447
|
onFocusKeys();
|
|
393
448
|
(e.currentTarget as Element).setPointerCapture?.(e.pointerId);
|
|
394
449
|
pressed.current = MOUSE_BUTTONS[e.button] ?? "left";
|
|
395
|
-
mouse("mousePressed", e, { button: pressed.current, clickCount: e.
|
|
450
|
+
mouse("mousePressed", e, { button: pressed.current, clickCount: clickCount(pressed.current, e.clientX, e.clientY) });
|
|
396
451
|
};
|
|
397
452
|
const onPointerMove = (e: React.PointerEvent) => {
|
|
398
453
|
if (!human) return;
|
|
@@ -422,19 +477,20 @@ const Screen = forwardRef<ScreenHandle, { human: boolean; inputEpoch: number; hi
|
|
|
422
477
|
if (!t.moved && point(e.clientX, e.clientY)) {
|
|
423
478
|
// Send before focusing: the mobile keyboard can resize/reposition the frame.
|
|
424
479
|
// 触屏点一下 = 鼠标点击
|
|
425
|
-
|
|
426
|
-
mouse("
|
|
480
|
+
const count = clickCount("left", e.clientX, e.clientY);
|
|
481
|
+
mouse("mousePressed", e, { button: "left", clickCount: count });
|
|
482
|
+
mouse("mouseReleased", e, { button: "left", clickCount: count });
|
|
427
483
|
onFocusKeys();
|
|
428
484
|
}
|
|
429
485
|
return;
|
|
430
486
|
}
|
|
431
487
|
if (e.pointerType === "touch" || !pressed.current) return;
|
|
432
488
|
pressed.current = null;
|
|
433
|
-
mouse("mouseReleased", e, { button: MOUSE_BUTTONS[e.button] ?? "left", clickCount:
|
|
489
|
+
mouse("mouseReleased", e, { button: MOUSE_BUTTONS[e.button] ?? "left", clickCount: clicks.current?.count ?? 1 });
|
|
434
490
|
};
|
|
435
491
|
|
|
436
492
|
// A new control/viewer epoch cannot inherit a drag from the previous one.
|
|
437
|
-
useEffect(()=>{touch.current=null;pressed.current=null;lastPoint.current=null;},[human,inputEpoch]);
|
|
493
|
+
useEffect(()=>{touch.current=null;pressed.current=null;lastPoint.current=null;clicks.current=null;},[human,inputEpoch]);
|
|
438
494
|
const release = useCallback(() => {
|
|
439
495
|
touch.current=null;
|
|
440
496
|
if (!pressed.current || !lastPoint.current) return;
|
|
@@ -709,6 +765,8 @@ function Viewer({ backend, jobId, human, feed, sink, onPage, onQuoteText }: {
|
|
|
709
765
|
const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
710
766
|
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
711
767
|
const mods = modifiers(e);
|
|
768
|
+
// Windows 等的 AltGr(Ctrl+Alt)打出的是字符(德语键盘的 @、€),不是快捷键:按文字插入。
|
|
769
|
+
if (e.getModifierState?.("AltGraph") && e.key.length === 1) { e.preventDefault(); send({ type: "text", text: e.key }); return; }
|
|
712
770
|
const shortcut = (mods & 6) !== 0;
|
|
713
771
|
if (shortcut && e.key.toLowerCase() === "v") return;
|
|
714
772
|
const special = SPECIAL_KEYS[e.key];
|
|
@@ -834,6 +892,7 @@ function BrowserPaneInner({ backend, jobId, readOnly, onQuote, onQuoteText, onPa
|
|
|
834
892
|
const sink = useRef<((m: BrowserMessage) => void) | null>(null);
|
|
835
893
|
const feed = useBrowserFeed(backend, jobId, sink);
|
|
836
894
|
const { status, setStatus, streamError, ended } = feed;
|
|
895
|
+
const statusRevision = feed.statusSnapshot.current.revision;
|
|
837
896
|
const [busy, setBusy] = useState<string | null>(null);
|
|
838
897
|
const [error, setError] = useState<string | null>(null);
|
|
839
898
|
|
|
@@ -846,12 +905,16 @@ function BrowserPaneInner({ backend, jobId, readOnly, onQuote, onQuoteText, onPa
|
|
|
846
905
|
return () => { document.body.style.overflow = prev; };
|
|
847
906
|
}, [big]);
|
|
848
907
|
const act = async (action: "open" | "close" | "takeover" | "handback") => {
|
|
908
|
+
const revision = feed.statusSnapshot.current.revision;
|
|
849
909
|
setBusy(action);
|
|
850
910
|
setError(null);
|
|
851
911
|
if (action === "handback" || action === "close") setBig(false);
|
|
852
912
|
try {
|
|
853
|
-
|
|
854
|
-
|
|
913
|
+
const result = await backend.browserAction(jobId, action);
|
|
914
|
+
// A stream event or another accepted response is newer than this action's snapshot.
|
|
915
|
+
if (feed.statusSnapshot.current.revision === revision) setStatus(result);
|
|
916
|
+
const current = feed.statusSnapshot.current.status;
|
|
917
|
+
if (action === "takeover" && current?.state === "running" && current.control === "human") setBig(true);
|
|
855
918
|
}
|
|
856
919
|
catch (e) { setError(e instanceof Error ? e.message : String(e)); }
|
|
857
920
|
finally { setBusy(null); }
|
|
@@ -939,7 +1002,7 @@ function BrowserPaneInner({ backend, jobId, readOnly, onQuote, onQuoteText, onPa
|
|
|
939
1002
|
</div>
|
|
940
1003
|
</div>
|
|
941
1004
|
)}
|
|
942
|
-
{extension?.(status,setStatus)}
|
|
1005
|
+
{extension?.(status,next => { if (feed.statusSnapshot.current.revision === statusRevision) setStatus(next); })}
|
|
943
1006
|
{footer}
|
|
944
1007
|
{shownError && <div className="bp-error">{shownError}</div>}
|
|
945
1008
|
{shownError && ended && <button className="btn btn-line btn-sm" onClick={feed.reconnect}>重试</button>}
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
// 改动:移植自 Operator 的 TaskChanges(只读部分:分支、统计、文件列表、逐文件 diff)。
|
|
2
2
|
// 合并 / 解决冲突 / 建 PR 是 Operator 里的操作,经中枢的对话任务不提供。
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { useDiffRefreshSignal } from "./diffRefresh";
|
|
5
|
+
import { CenterError, type BoardBackend } from "../core/client";
|
|
5
6
|
import type { DiffFile, DiffResult } from "../core/types";
|
|
7
|
+
import { countChanges } from "./diffLines";
|
|
8
|
+
import { FileDiff, useLazyPatches } from "./fileDiff";
|
|
6
9
|
|
|
7
10
|
const STATUS_LABEL: Record<string, string> = { A: "新增", M: "修改", D: "删除", R: "重命名", "?": "未跟踪" };
|
|
8
|
-
const COLLAPSE_LINES = 400;
|
|
9
11
|
/** 一次画多少个文件的 diff:改了几千个文件时不一次塞进页面,往下点「再显示」。 */
|
|
12
|
+
const UNCHANGED = Symbol("unchanged");
|
|
10
13
|
const RENDER_BATCH = 150;
|
|
11
14
|
|
|
12
|
-
// 去掉 diff --git / index / --- / +++ 文件头,只留 hunk 行(与 Operator 一致)。
|
|
13
|
-
function hunkLines(patch: string): string[] {
|
|
14
|
-
const lines = patch.split("\n");
|
|
15
|
-
const i = lines.findIndex((l) => l.startsWith("@@"));
|
|
16
|
-
return i >= 0 ? lines.slice(i) : [];
|
|
17
|
-
}
|
|
18
|
-
function lineClass(line: string): string {
|
|
19
|
-
if (line.startsWith("@@")) return "hunk";
|
|
20
|
-
if (line.startsWith("+") && !line.startsWith("+++")) return "add";
|
|
21
|
-
if (line.startsWith("-") && !line.startsWith("---")) return "del";
|
|
22
|
-
return "";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
15
|
/** 只给了一整段 unified diff 的节点:按文件切开。 */
|
|
26
16
|
export function splitUnified(diff: string): DiffFile[] {
|
|
27
17
|
const files: DiffFile[] = [];
|
|
@@ -30,73 +20,99 @@ export function splitUnified(diff: string): DiffFile[] {
|
|
|
30
20
|
const head = /^diff --git a\/(.+?) b\/(.+)$/m.exec(chunk);
|
|
31
21
|
const path = head?.[2] ?? "?";
|
|
32
22
|
const status = /^new file mode/m.test(chunk) ? "A" : /^deleted file mode/m.test(chunk) ? "D" : /^rename from/m.test(chunk) ? "R" : "M";
|
|
33
|
-
|
|
34
|
-
let deletions = 0;
|
|
35
|
-
for (const l of hunkLines(chunk)) {
|
|
36
|
-
if (l.startsWith("+") && !l.startsWith("+++")) additions++;
|
|
37
|
-
else if (l.startsWith("-") && !l.startsWith("---")) deletions++;
|
|
38
|
-
}
|
|
23
|
+
const { additions, deletions } = countChanges(chunk);
|
|
39
24
|
files.push({ path, status, additions, deletions, binary: /^Binary files /m.test(chunk), patch: chunk });
|
|
40
25
|
}
|
|
41
26
|
return files;
|
|
42
27
|
}
|
|
43
28
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<button className="tc-fhead" onClick={() => onToggle(f.path)}>
|
|
55
|
-
<span className={`tc-chev ${isCollapsed ? "" : "open"}`}>▸</span>
|
|
56
|
-
<span className={`tc-st s-${f.status === "?" ? "new" : f.status}`}>{f.status}</span>
|
|
57
|
-
<span className="tc-fpath">{f.path}</span>
|
|
58
|
-
{onOpen && f.status !== "D" && (
|
|
59
|
-
<span className="cli-tc-open" role="button" tabIndex={0} title="打开文件" onClick={(e) => { e.stopPropagation(); onOpen(f.path); }} onKeyDown={(e) => { if (e.key === "Enter") { e.stopPropagation(); onOpen(f.path); } }}>打开</span>
|
|
60
|
-
)}
|
|
61
|
-
<span className="tc-cnt"><b className="add">+{f.additions}</b> <b className="del">−{f.deletions}</b></span>
|
|
62
|
-
</button>
|
|
63
|
-
{isCollapsed ? (
|
|
64
|
-
big && <button className="tc-bigdiff" onClick={() => onToggle(f.path)}>大型 diff({lines.length.toLocaleString()} 行)—— 点击展开</button>
|
|
65
|
-
) : (
|
|
66
|
-
<div className="tc-hunks">
|
|
67
|
-
{f.omitted ? <div className="tc-empty">改动太多,这个文件的 diff 没有带上{onOpen && f.status !== "D" ? ",可以点「打开」看文件" : ""}。</div>
|
|
68
|
-
: f.binary ? <div className="tc-empty">二进制文件 —— 不予显示</div>
|
|
69
|
-
: lines.length === 0 ? <div className="tc-empty">没有文本改动(仅权限或重命名)。</div>
|
|
70
|
-
: lines.map((ln, i) => <div key={i} className={`dl ${lineClass(ln)}`}>{ln || " "}</div>)}
|
|
71
|
-
{f.truncated && <div className="tc-empty">… 文件 diff 已截断</div>}
|
|
72
|
-
</div>
|
|
73
|
-
)}
|
|
74
|
-
</div>
|
|
75
|
-
);
|
|
76
|
-
});
|
|
29
|
+
/** 刷新信号挤在一起时(轮末收尾 + 文件变化)合成一次读:diff 在节点上要跑一组 git 命令。 */
|
|
30
|
+
const REFRESH_COALESCE_MS = 250;
|
|
31
|
+
/** 节点暂时连不上、超时、网关错误:隔一会儿自动再读,几次之后只留「重试」。 */
|
|
32
|
+
const RETRY_DELAYS_MS = [3_000, 10_000, 30_000];
|
|
33
|
+
/** git 读失败、工作区已清理之类不会自己好,不自动重试。 */
|
|
34
|
+
function transient(error: unknown): boolean {
|
|
35
|
+
if (!(error instanceof CenterError)) return false;
|
|
36
|
+
return error.code === "NETWORK" || error.code === "node_unreachable" || error.code === "node_timeout" || [429, 502, 503, 504].includes(error.status);
|
|
37
|
+
}
|
|
38
|
+
const clock = (at: number) => new Date(at).toLocaleTimeString("zh-CN", { hour12: false });
|
|
77
39
|
|
|
78
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 自动重读(见 useDiffRefreshSignal,只看事件,没有定时轮询):
|
|
42
|
+
* settled:轮次收尾计数(store 的 ConvState.settled),变了马上重读;
|
|
43
|
+
* edits:运行中工具执行完的次数(ConvState.edits),refreshKey:文件变化、回到页面等,这两个节流重读(最多每 5 秒一次)。
|
|
44
|
+
*/
|
|
45
|
+
export function ChangesPane({ backend, jobId, refreshKey, settled = 0, edits = 0, onOpen }: { backend: BoardBackend; jobId: string; refreshKey: number; settled?: number; edits?: number; onOpen?: (path: string) => void }) {
|
|
46
|
+
const signal = useDiffRefreshSignal(settled, edits + refreshKey);
|
|
79
47
|
const [data, setData] = useState<DiffResult | null>(null);
|
|
80
48
|
const [error, setError] = useState<string | null>(null);
|
|
81
49
|
const [loading, setLoading] = useState(false);
|
|
82
50
|
const [manual, setManual] = useState(0);
|
|
83
51
|
const [toggled, setToggled] = useState<Set<string>>(new Set());
|
|
52
|
+
// 渐进式(新版中枢 + 节点):先拿文件列表和增删行数,点开哪个文件才取它的 patch;没变化时服务端回 304,不传正文。
|
|
53
|
+
const etag = useRef<{ job: string; value?: string } | null>(null);
|
|
84
54
|
const [active, setActive] = useState<string | null>(null);
|
|
85
55
|
const [shown, setShown] = useState(RENDER_BATCH);
|
|
86
56
|
const secRefs = useRef<Record<string, HTMLDivElement | null>>({});
|
|
87
57
|
const scrollRef = useRef<HTMLDivElement | null>(null);
|
|
88
58
|
|
|
59
|
+
// 上次读成功的时间:刷新失败时仍显示上次的结果,并写明是什么时候的。
|
|
60
|
+
const [loadedAt, setLoadedAt] = useState<number | null>(null);
|
|
61
|
+
// 自动重试:retrying = 已排好下一次;auto 每次到点 +1 触发重读。新的刷新信号(轮末、文件变化、手动)重新计数。
|
|
62
|
+
const [retrying, setRetrying] = useState(false);
|
|
63
|
+
const [auto, setAuto] = useState(0);
|
|
64
|
+
const attempts = useRef(0);
|
|
65
|
+
const trigger = `${signal}|${manual}`;
|
|
66
|
+
const lastTrigger = useRef(trigger);
|
|
67
|
+
// 首次读可以和同时打开的其他看板共用请求;之后每次刷新都单独发(fresh),不拿刷新之前就发出的结果。
|
|
68
|
+
const loadedOnce = useRef(false);
|
|
89
69
|
useEffect(() => {
|
|
90
70
|
let alive = true;
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
let retryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
73
|
+
if (lastTrigger.current !== trigger) { lastTrigger.current = trigger; attempts.current = 0; }
|
|
74
|
+
const refresh = loadedOnce.current;
|
|
75
|
+
loadedOnce.current = true;
|
|
91
76
|
setLoading(true);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
setRetrying(false);
|
|
78
|
+
// 没变化(304)用 UNCHANGED 表示;自定义后端回 null / 非对象当失败处理,不能停在「读取改动…」。
|
|
79
|
+
const tag = etag.current?.job === jobId ? etag.current.value : undefined;
|
|
80
|
+
const read: () => Promise<DiffResult | typeof UNCHANGED> = backend.diffSummary && backend.diffFile
|
|
81
|
+
? () => backend.diffSummary!(jobId, { etag: tag, signal: controller.signal }).then((r) => {
|
|
82
|
+
if (r && typeof r === "object" && "notModified" in r && r.notModified) return UNCHANGED;
|
|
83
|
+
if (alive && r && typeof r === "object") etag.current = { job: jobId, value: (r as { etag?: string }).etag };
|
|
84
|
+
return r as DiffResult;
|
|
85
|
+
})
|
|
86
|
+
: () => backend.diff(jobId, refresh ? { fresh: true } : undefined);
|
|
87
|
+
const load = () => read().then((d) => {
|
|
88
|
+
if (d !== UNCHANGED && (!d || typeof d !== "object")) throw new CenterError("改动接口没有返回内容,请稍后重试", "bad_response", 200);
|
|
89
|
+
return d === UNCHANGED ? null : d;
|
|
90
|
+
}).then((d) => {
|
|
91
|
+
if (!alive) return;
|
|
92
|
+
attempts.current = 0;
|
|
93
|
+
if (d) setData(d);
|
|
94
|
+
setError(null); setLoadedAt(Date.now()); setLoading(false);
|
|
95
|
+
}, (e: unknown) => {
|
|
96
|
+
if (!alive) return;
|
|
97
|
+
setError(e instanceof Error ? e.message : String(e)); setLoading(false);
|
|
98
|
+
if (transient(e) && attempts.current < RETRY_DELAYS_MS.length) {
|
|
99
|
+
setRetrying(true);
|
|
100
|
+
retryTimer = setTimeout(() => { if (alive) setAuto((n) => n + 1); }, RETRY_DELAYS_MS[attempts.current++]);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
if (!refresh) { void load(); return () => { alive = false; controller.abort(); clearTimeout(retryTimer); }; }
|
|
104
|
+
const timer = setTimeout(load, REFRESH_COALESCE_MS);
|
|
105
|
+
return () => { alive = false; controller.abort(); clearTimeout(timer); clearTimeout(retryTimer); };
|
|
106
|
+
}, [backend, jobId, signal, manual, auto]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
96
107
|
|
|
108
|
+
const lazy = !!data?.summary && !!backend.diffFile;
|
|
109
|
+
const fetchFile = useCallback((path: string, signal: AbortSignal) => backend.diffFile!(jobId, path, { signal }), [backend, jobId]);
|
|
110
|
+
const { patches, retry } = useLazyPatches({ files: data?.files, lazy, toggled, fetchFile });
|
|
97
111
|
const toggle = useCallback((path: string) => setToggled((s) => { const n = new Set(s); if (n.has(path)) n.delete(path); else n.add(path); return n; }), []);
|
|
98
112
|
const jump = (path: string) => {
|
|
99
113
|
setActive(path);
|
|
114
|
+
// 渐进式:跳过去的文件顺便展开(取它的 patch)。
|
|
115
|
+
if (lazy && !toggled.has(path)) toggle(path);
|
|
100
116
|
// 跳到还没画出来的文件:先把它画出来。
|
|
101
117
|
const at = files.findIndex((f) => f.path === path);
|
|
102
118
|
if (at >= shown) setShown(at + RENDER_BATCH);
|
|
@@ -107,7 +123,8 @@ export function ChangesPane({ backend, jobId, refreshKey, onOpen }: { backend: B
|
|
|
107
123
|
|
|
108
124
|
const files = useMemo(() => data?.files ?? (data?.diff || data?.patch ? splitUnified(data.diff ?? data.patch ?? "") : []), [data]);
|
|
109
125
|
|
|
110
|
-
|
|
126
|
+
const retryNote = retrying ? ",稍后自动重试" : "";
|
|
127
|
+
if (error && !data) return <div className="tc-note">读取改动失败:{error}{retryNote} <button className="tc-btn" onClick={() => setManual((n) => n + 1)}>重试</button></div>;
|
|
111
128
|
if (!data) return <div className="tc-note">读取改动…</div>;
|
|
112
129
|
if (data.error) return <div className="tc-note">{data.error} <button className="tc-btn" onClick={() => setManual((n) => n + 1)}>重试</button></div>;
|
|
113
130
|
const unified = !data.files && files.length > 0;
|
|
@@ -127,6 +144,12 @@ export function ChangesPane({ backend, jobId, refreshKey, onOpen }: { backend: B
|
|
|
127
144
|
<span className="tc-spacer" />
|
|
128
145
|
<button className="tc-btn" onClick={() => setManual((n) => n + 1)} disabled={loading}>{loading ? "…" : "刷新"}</button>
|
|
129
146
|
</div>
|
|
147
|
+
{error && (
|
|
148
|
+
<div className="tc-mergebar bad" role="status">
|
|
149
|
+
⚠ 刷新失败:{error}{loadedAt ? `。下面是 ${clock(loadedAt)} 的结果` : ""}{retryNote}{" "}
|
|
150
|
+
<button className="tc-btn" onClick={() => setManual((n) => n + 1)} disabled={loading}>重试</button>
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
130
153
|
{nothing ? (
|
|
131
154
|
<div className="tc-note">该分支上还没有改动。</div>
|
|
132
155
|
) : (
|
|
@@ -142,7 +165,8 @@ export function ChangesPane({ backend, jobId, refreshKey, onOpen }: { backend: B
|
|
|
142
165
|
))}
|
|
143
166
|
</div>
|
|
144
167
|
{(data.patchesOmitted ?? 0) > 0 && <div className="tc-empty">改动太多:{data.patchesOmitted} 个文件的 diff 没有带上(只列出文件),可以打开文件查看。</div>}
|
|
145
|
-
{files.slice(0, shown).map((f) => <FileDiff key={f.path} file={f} userToggled={toggled.has(f.path)} onToggle={toggle} refs={secRefs} onOpen={onOpen}
|
|
168
|
+
{files.slice(0, shown).map((f) => <FileDiff key={f.path} file={f} userToggled={toggled.has(f.path)} onToggle={toggle} refs={secRefs} onOpen={onOpen}
|
|
169
|
+
lazy={lazy} patch={lazy ? patches[f.path] : undefined} onRetry={retry} />)}
|
|
146
170
|
{files.length > shown && <button className="tc-bigdiff" onClick={() => setShown((n) => n + RENDER_BATCH)}>还有 {(files.length - shown).toLocaleString()} 个文件 —— 再显示 {Math.min(RENDER_BATCH, files.length - shown)} 个</button>}
|
|
147
171
|
</div>
|
|
148
172
|
)}
|