@keyou007/agent-bot 0.1.26 → 0.1.27-alpha.1
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 +17 -0
- package/README.md +18 -8
- package/README.zh.md +17 -7
- package/SECURITY.md +4 -4
- package/config.example.yaml +3 -2
- package/dist/cli/AutostartManager.js +1 -1
- package/dist/config/SettingsStore.js +10 -5
- package/dist/config/SettingsStore.js.map +1 -1
- package/dist/config/loadConfig.js +2 -1
- package/dist/config/loadConfig.js.map +1 -1
- package/dist/config/schema.js +5 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/feishu/CardRenderer.js +5 -8
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuConnector.js +1 -1
- package/dist/feishu/FeishuConnector.js.map +1 -1
- package/dist/feishu/SettingsCard.js +4 -3
- package/dist/feishu/SettingsCard.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/local-files/GitDiffPreview.js +163 -0
- package/dist/local-files/GitDiffPreview.js.map +1 -0
- package/dist/local-files/LocalFileViewerServer.js +63 -9
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/TurnPreviewPage.js +106 -48
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/terminal/TerminalCards.js +1 -1
- package/dist/terminal/TerminalPage.js +52 -20
- package/dist/terminal/TerminalPage.js.map +1 -1
- package/dist/terminal/TerminalServer.js +72 -73
- package/dist/terminal/TerminalServer.js.map +1 -1
- package/docs/technical-reference.md +23 -14
- package/docs/technical-reference.zh.md +23 -14
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +7 -3
- package/src/cli/AutostartManager.ts +1 -1
- package/src/config/SettingsStore.ts +12 -7
- package/src/config/loadConfig.ts +2 -1
- package/src/config/schema.ts +6 -1
- package/src/feishu/CardRenderer.ts +5 -8
- package/src/feishu/FeishuConnector.ts +1 -1
- package/src/feishu/SettingsCard.ts +3 -2
- package/src/index.ts +3 -1
- package/src/local-files/GitDiffPreview.ts +141 -0
- package/src/local-files/LocalFileViewerServer.ts +54 -9
- package/src/local-files/TurnPreviewPage.ts +124 -60
- package/src/terminal/TerminalCards.ts +1 -1
- package/src/terminal/TerminalPage.ts +53 -20
- package/src/terminal/TerminalServer.ts +69 -62
|
@@ -11,6 +11,7 @@ import dockerfile from "highlight.js/lib/languages/dockerfile";
|
|
|
11
11
|
import powershell from "highlight.js/lib/languages/powershell";
|
|
12
12
|
import MarkdownIt from "markdown-it";
|
|
13
13
|
import { CSV_PREVIEW_CSS, renderCsvPreview, csvSourcePreview } from "./CsvPreview.js";
|
|
14
|
+
import { GIT_DIFF_PREVIEW_CSS, readGitFileDiff, renderGitFileDiff } from "./GitDiffPreview.js";
|
|
14
15
|
import { enableDiagramFences, DIAGRAM_PREVIEW_CLIENT_SCRIPT, DIAGRAM_PREVIEW_CSS } from "./DiagramPreview.js";
|
|
15
16
|
import { isFileUrl, rewriteMarkdownFileLinks } from "./MarkdownFileLinks.js";
|
|
16
17
|
import {
|
|
@@ -404,18 +405,20 @@ export class LocalFileViewerServer {
|
|
|
404
405
|
} catch { return undefined; }
|
|
405
406
|
}
|
|
406
407
|
|
|
407
|
-
createFileUrl(filePath: string, reference?: string): string | undefined {
|
|
408
|
+
createFileUrl(filePath: string, reference?: string, options?: { diff?: boolean }): string | undefined {
|
|
408
409
|
if (!this.address || !this.secret) return undefined;
|
|
409
410
|
const absolutePath = normalizeAbsolutePath(filePath);
|
|
410
411
|
if (!absolutePath) return undefined;
|
|
411
412
|
try {
|
|
412
413
|
const stat = fs.statSync(absolutePath);
|
|
413
414
|
if (!stat.isFile() && !stat.isDirectory()) return undefined;
|
|
414
|
-
|
|
415
|
-
|
|
415
|
+
if (options?.diff && stat.isDirectory()) return undefined;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
if (!options?.diff || !["ENOENT", "ENOTDIR"].includes((error as NodeJS.ErrnoException).code ?? "")) return undefined;
|
|
416
418
|
}
|
|
417
419
|
|
|
418
420
|
const url = this.createPreviewUrl(absolutePath);
|
|
421
|
+
if (options?.diff) url.searchParams.set("diff", "1");
|
|
419
422
|
const line = parseLineReference(reference);
|
|
420
423
|
if (line !== undefined) url.hash = `L${line}`;
|
|
421
424
|
return url.toString();
|
|
@@ -513,7 +516,7 @@ export class LocalFileViewerServer {
|
|
|
513
516
|
&& (snapshot.fullToolOutputs?.[tool.id]?.length ?? 0) > outputAppend.length
|
|
514
517
|
? { key, revision: String(tool.tool.previewRevision), content: "", outputAppend,
|
|
515
518
|
footer: renderToolFooter(tool.tool, snapshot.fullToolOutputs?.[tool.id]?.length ?? 0, language) }
|
|
516
|
-
: renderTurnPreviewDetail(snapshot, key, (filePath) => this.createFileUrl(filePath), language);
|
|
519
|
+
: renderTurnPreviewDetail(snapshot, key, (filePath, options) => this.createFileUrl(filePath, undefined, options), language);
|
|
517
520
|
setSecurityHeaders(response);
|
|
518
521
|
response.statusCode = detail ? 200 : 404;
|
|
519
522
|
response.setHeader("Cache-Control", "no-store");
|
|
@@ -533,7 +536,7 @@ export class LocalFileViewerServer {
|
|
|
533
536
|
state: snapshot,
|
|
534
537
|
eventsUrl: eventsUrl.toString(),
|
|
535
538
|
scriptPath: `${this.basePath}/assets/turn-preview.js`.replace(/\/{2,}/gu, "/"),
|
|
536
|
-
localFileUrl: (filePath) => this.createFileUrl(filePath),
|
|
539
|
+
localFileUrl: (filePath, options) => this.createFileUrl(filePath, undefined, options),
|
|
537
540
|
diagramScriptPath: `${this.basePath}/assets/mermaid.js`.replace(/\/{2,}/gu, "/"),
|
|
538
541
|
language,
|
|
539
542
|
});
|
|
@@ -558,6 +561,24 @@ export class LocalFileViewerServer {
|
|
|
558
561
|
return;
|
|
559
562
|
}
|
|
560
563
|
|
|
564
|
+
if (requestUrl.searchParams.get("diff") === "1" && requestUrl.searchParams.get("raw") !== "1"
|
|
565
|
+
&& legacyMatch?.[1] !== "raw" && requestUrl.searchParams.get("render") !== "html"
|
|
566
|
+
&& requestUrl.searchParams.get("events") !== "1") {
|
|
567
|
+
const content = await readGitDiffPreview(filePath);
|
|
568
|
+
if (content !== undefined) {
|
|
569
|
+
const original = this.createFileUrl(filePath);
|
|
570
|
+
const actions: Array<{ href: string; label: string }> = [];
|
|
571
|
+
if (original) {
|
|
572
|
+
const raw = new URL(original); raw.searchParams.set("raw", "1");
|
|
573
|
+
const download = new URL(raw); download.searchParams.set("download", "1");
|
|
574
|
+
actions.push({ href: original, label: "查看文件" }, { href: raw.toString(), label: "打开原始文件" }, { href: download.toString(), label: "下载" });
|
|
575
|
+
}
|
|
576
|
+
this.sendHtml(response, 200, renderViewerPage({ title: path.basename(filePath), filePath,
|
|
577
|
+
metadata: ["Git diff", "完整文件", "当前工作区"], actions, content }), request.method === "HEAD");
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
561
582
|
let stat: fs.Stats;
|
|
562
583
|
try {
|
|
563
584
|
stat = fs.statSync(filePath);
|
|
@@ -853,7 +874,7 @@ export class LocalFileViewerServer {
|
|
|
853
874
|
if (!batch.records.length) {
|
|
854
875
|
const state = projection.state;
|
|
855
876
|
if (state && ["completed", "cancelled", "failed"].includes(state.status)) {
|
|
856
|
-
const update = renderTurnPreviewPatch(state, new Set(), new Set(), (file) => this.createFileUrl(file), language);
|
|
877
|
+
const update = renderTurnPreviewPatch(state, new Set(), new Set(), (file, options) => this.createFileUrl(file, undefined, options), language);
|
|
857
878
|
response.write(`id: ${offset}\nevent: patch\ndata: ${JSON.stringify(update)}\n\n`);
|
|
858
879
|
cleanup(); response.end();
|
|
859
880
|
}
|
|
@@ -864,8 +885,8 @@ export class LocalFileViewerServer {
|
|
|
864
885
|
const state = projection.state;
|
|
865
886
|
if (!state) return;
|
|
866
887
|
const render = initial
|
|
867
|
-
? renderTurnPreviewSnapshot(state, (file) => this.createFileUrl(file), language, { deferDetails: true })
|
|
868
|
-
: renderTurnPreviewPatch(state, projection.changed, projection.removed, (file) => this.createFileUrl(file), language);
|
|
888
|
+
? renderTurnPreviewSnapshot(state, (file, options) => this.createFileUrl(file, undefined, options), language, { deferDetails: true })
|
|
889
|
+
: renderTurnPreviewPatch(state, projection.changed, projection.removed, (file, options) => this.createFileUrl(file, undefined, options), language);
|
|
869
890
|
// A terminal record can share a batch with later metadata. Drain the captured prefix first.
|
|
870
891
|
render.terminal = render.terminal && batch.end;
|
|
871
892
|
waitingDrain = !response.write(`id: ${offset}\nevent: ${initial ? "update" : "patch"}\ndata: ${JSON.stringify(render)}\n\n`);
|
|
@@ -916,7 +937,7 @@ export class LocalFileViewerServer {
|
|
|
916
937
|
const serialized = JSON.stringify(state);
|
|
917
938
|
if (serialized === previousSnapshot) return;
|
|
918
939
|
previousSnapshot = serialized;
|
|
919
|
-
const snapshot = renderTurnPreviewSnapshot(state, (filePath) => this.createFileUrl(filePath), language, { deferDetails: true });
|
|
940
|
+
const snapshot = renderTurnPreviewSnapshot(state, (filePath, options) => this.createFileUrl(filePath, undefined, options), language, { deferDetails: true });
|
|
920
941
|
writeServerSentEvent(response, "update", JSON.stringify(snapshot));
|
|
921
942
|
};
|
|
922
943
|
sendSnapshot();
|
|
@@ -1149,6 +1170,7 @@ function renderViewerPage(input: {
|
|
|
1149
1170
|
.markdown-body img { max-width: 100%; height: auto; }
|
|
1150
1171
|
.markdown-body hr { height: 1px; margin: 1.5em 0; border: 0; background: #dfe3e8; }
|
|
1151
1172
|
${CSV_PREVIEW_CSS}
|
|
1173
|
+
${GIT_DIFF_PREVIEW_CSS}
|
|
1152
1174
|
.media { display: grid; place-items: center; min-height: 220px; }
|
|
1153
1175
|
.media img, .media video { max-width: 100%; max-height: calc(100vh - 70px); }
|
|
1154
1176
|
.media audio { width: min(720px, 100%); }
|
|
@@ -1350,6 +1372,29 @@ function parseDirectoryPage(value: string | null): number {
|
|
|
1350
1372
|
return Number.isSafeInteger(page) && page >= 0 ? page : 0;
|
|
1351
1373
|
}
|
|
1352
1374
|
|
|
1375
|
+
async function readGitDiffPreview(filePath: string): Promise<string | undefined> {
|
|
1376
|
+
try {
|
|
1377
|
+
const before = fs.statSync(filePath, { throwIfNoEntry: false });
|
|
1378
|
+
let text = "";
|
|
1379
|
+
if (before) {
|
|
1380
|
+
if (!before.isFile() || before.size > MAX_TEXT_PREVIEW_BYTES) return undefined;
|
|
1381
|
+
const classification = classifyFileContent(filePath, before.size);
|
|
1382
|
+
if (classification.kind !== "text") return undefined;
|
|
1383
|
+
const preview = readTextPreview(filePath, before.size, classification.encoding);
|
|
1384
|
+
if (preview.truncated) return undefined;
|
|
1385
|
+
text = preview.text;
|
|
1386
|
+
}
|
|
1387
|
+
const diff = await readGitFileDiff(filePath);
|
|
1388
|
+
if (!diff) return undefined;
|
|
1389
|
+
const after = fs.statSync(filePath, { throwIfNoEntry: false });
|
|
1390
|
+
if (before?.size !== after?.size || before?.mtimeMs !== after?.mtimeMs || before?.ctimeMs !== after?.ctimeMs
|
|
1391
|
+
|| before?.ino !== after?.ino || before?.dev !== after?.dev) return undefined;
|
|
1392
|
+
return renderGitFileDiff(diff, text);
|
|
1393
|
+
} catch {
|
|
1394
|
+
return undefined;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1353
1398
|
function readTextPreview(
|
|
1354
1399
|
filePath: string,
|
|
1355
1400
|
size: number,
|
|
@@ -13,6 +13,8 @@ import { visibleTurnActivities } from "../presentation/visibleTurnActivities.js"
|
|
|
13
13
|
import { displayRuntimeError } from "../runtime/responseErrors.js";
|
|
14
14
|
import { isFileUrl, rewriteMarkdownFileLinks } from "./MarkdownFileLinks.js";
|
|
15
15
|
|
|
16
|
+
type PreviewFileUrl = (filePath: string, options?: { diff?: boolean }) => string | undefined;
|
|
17
|
+
|
|
16
18
|
const MARKDOWN = new MarkdownIt({
|
|
17
19
|
breaks: true,
|
|
18
20
|
html: false,
|
|
@@ -236,7 +238,9 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
|
|
|
236
238
|
});
|
|
237
239
|
|
|
238
240
|
let source;
|
|
241
|
+
let eventCursor;
|
|
239
242
|
const terminalAtLoad = document.body.dataset.terminal === "true";
|
|
243
|
+
let terminal = terminalAtLoad;
|
|
240
244
|
const updateElapsed = () => {
|
|
241
245
|
document.querySelectorAll("[data-live-elapsed]").forEach((element) => {
|
|
242
246
|
const startedAt = Number(element.dataset.startedAt);
|
|
@@ -270,7 +274,37 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
|
|
|
270
274
|
});
|
|
271
275
|
};
|
|
272
276
|
updateElapsed();
|
|
273
|
-
|
|
277
|
+
let clock = terminalAtLoad ? undefined : setInterval(updateElapsed, 1000);
|
|
278
|
+
|
|
279
|
+
const historyKey = "agentBotTurnPreview";
|
|
280
|
+
const turnId = document.body.dataset.turnId;
|
|
281
|
+
const disclosureStates = new Map();
|
|
282
|
+
const restoredDisclosures = new WeakSet();
|
|
283
|
+
try {
|
|
284
|
+
const saved = window.history?.state?.[historyKey];
|
|
285
|
+
if (saved?.turnId === turnId && Array.isArray(saved.details)) {
|
|
286
|
+
for (const entry of saved.details) {
|
|
287
|
+
if (Array.isArray(entry) && typeof entry[0] === "string" && typeof entry[1] === "boolean") disclosureStates.set(entry[0], entry[1]);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} catch {}
|
|
291
|
+
const saveDisclosures = () => {
|
|
292
|
+
for (const details of content.querySelectorAll("details[data-activity-id]")) {
|
|
293
|
+
disclosureStates.set(details.dataset.activityId, details.hasAttribute("open"));
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
window.history?.replaceState({ ...window.history.state,
|
|
297
|
+
[historyKey]: { turnId, details: Array.from(disclosureStates) } }, "");
|
|
298
|
+
} catch {}
|
|
299
|
+
};
|
|
300
|
+
const restoreDisclosures = () => {
|
|
301
|
+
for (const details of content.querySelectorAll("details[data-activity-id]")) {
|
|
302
|
+
if (restoredDisclosures.has(details)) continue;
|
|
303
|
+
restoredDisclosures.add(details);
|
|
304
|
+
const open = disclosureStates.get(details.dataset.activityId);
|
|
305
|
+
if (typeof open === "boolean") details.toggleAttribute("open", open);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
274
308
|
|
|
275
309
|
const nodeKey = (node) => {
|
|
276
310
|
if (node.nodeType !== 1) return undefined;
|
|
@@ -441,6 +475,7 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
|
|
|
441
475
|
};
|
|
442
476
|
content.addEventListener("toggle", (event) => {
|
|
443
477
|
const details = event.target;
|
|
478
|
+
if (details.matches?.("details[data-activity-id]")) saveDisclosures();
|
|
444
479
|
if (!details.matches?.("details[data-detail-key]")) return;
|
|
445
480
|
if (details.open) { void loadDetails(details, true); return; }
|
|
446
481
|
const state = detailState(details);
|
|
@@ -451,13 +486,22 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
|
|
|
451
486
|
if (message) message.textContent = "";
|
|
452
487
|
}, true);
|
|
453
488
|
const refreshDetails = () => {
|
|
489
|
+
restoreDisclosures();
|
|
454
490
|
for (const details of content.querySelectorAll("details[data-detail-key][open]")) void loadDetails(details);
|
|
455
491
|
};
|
|
456
492
|
window.addEventListener("pagehide", () => {
|
|
493
|
+
saveDisclosures();
|
|
457
494
|
source?.close();
|
|
495
|
+
source = undefined;
|
|
458
496
|
clearInterval(clock);
|
|
459
|
-
|
|
460
|
-
|
|
497
|
+
clock = undefined;
|
|
498
|
+
for (const details of content.querySelectorAll("details[data-detail-key]")) {
|
|
499
|
+
const state = detailStates.get(details);
|
|
500
|
+
state?.pending?.controller.abort();
|
|
501
|
+
if (state) state.pending = undefined;
|
|
502
|
+
details.querySelector("[data-detail-body]")?.removeAttribute("aria-busy");
|
|
503
|
+
}
|
|
504
|
+
});
|
|
461
505
|
let previousContent;
|
|
462
506
|
let previousMetadata;
|
|
463
507
|
const applySnapshot = (update) => {
|
|
@@ -533,38 +577,58 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
|
|
|
533
577
|
refreshDetails();
|
|
534
578
|
updateElapsed();
|
|
535
579
|
};
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
if (
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
580
|
+
const connect = () => {
|
|
581
|
+
if (terminal || source || typeof EventSource !== "function") return;
|
|
582
|
+
const resumeUrl = eventCursor ? new URL(eventsUrl, window.location.href) : undefined;
|
|
583
|
+
if (resumeUrl) resumeUrl.searchParams.set("after", eventCursor);
|
|
584
|
+
const connection = new EventSource(resumeUrl?.toString() ?? eventsUrl);
|
|
585
|
+
source = connection;
|
|
586
|
+
connection.addEventListener("patch", (event) => {
|
|
587
|
+
if (source !== connection) return;
|
|
588
|
+
try {
|
|
589
|
+
const update = JSON.parse(event.data);
|
|
590
|
+
applyPatch(update);
|
|
591
|
+
eventCursor = event.lastEventId || eventCursor;
|
|
592
|
+
live.textContent = update.terminal ? "" : labels.live;
|
|
593
|
+
live.className = update.terminal ? "live terminal" : "live connected";
|
|
594
|
+
if (update.terminal) { terminal = true; connection.close(); clearInterval(clock); }
|
|
595
|
+
} catch { live.textContent = labels.waitingForUpdates; }
|
|
596
|
+
});
|
|
597
|
+
connection.addEventListener("update", (event) => {
|
|
598
|
+
if (source !== connection) return;
|
|
599
|
+
try {
|
|
600
|
+
const update = JSON.parse(event.data);
|
|
601
|
+
if (typeof update.content !== "string" || typeof update.metadata !== "string") return;
|
|
602
|
+
applySnapshot(update);
|
|
603
|
+
eventCursor = event.lastEventId || eventCursor;
|
|
604
|
+
live.textContent = update.terminal ? "" : labels.live;
|
|
605
|
+
live.className = update.terminal ? "live terminal" : "live connected";
|
|
606
|
+
if (update.terminal) { terminal = true; connection.close(); clearInterval(clock); }
|
|
607
|
+
} catch {
|
|
608
|
+
live.textContent = labels.waitingForUpdates;
|
|
609
|
+
live.className = "live";
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
connection.addEventListener("unavailable", () => {
|
|
613
|
+
if (source !== connection) return;
|
|
614
|
+
live.textContent = labels.unavailable;
|
|
615
|
+
live.className = "live disconnected";
|
|
616
|
+
});
|
|
617
|
+
connection.onerror = () => {
|
|
618
|
+
if (source !== connection) return;
|
|
619
|
+
live.textContent = labels.reconnecting;
|
|
620
|
+
live.className = "live disconnected";
|
|
621
|
+
};
|
|
567
622
|
};
|
|
623
|
+
window.addEventListener("pageshow", (event) => {
|
|
624
|
+
if (!event.persisted) return;
|
|
625
|
+
updateElapsed();
|
|
626
|
+
refreshDetails();
|
|
627
|
+
if (!terminal && clock === undefined) clock = setInterval(updateElapsed, 1000);
|
|
628
|
+
connect();
|
|
629
|
+
});
|
|
630
|
+
refreshDetails();
|
|
631
|
+
connect();
|
|
568
632
|
})();
|
|
569
633
|
`;
|
|
570
634
|
|
|
@@ -594,7 +658,7 @@ export function renderTurnPreviewPage(input: {
|
|
|
594
658
|
eventsUrl: string;
|
|
595
659
|
scriptPath: string;
|
|
596
660
|
diagramScriptPath?: string;
|
|
597
|
-
localFileUrl?:
|
|
661
|
+
localFileUrl?: PreviewFileUrl;
|
|
598
662
|
language?: TurnPreviewLanguage;
|
|
599
663
|
}): string {
|
|
600
664
|
const language = input.language ?? "zh";
|
|
@@ -608,7 +672,7 @@ export function renderTurnPreviewPage(input: {
|
|
|
608
672
|
<title>${escapeHtml(title)} · Agent Bot</title>
|
|
609
673
|
<style>${TURN_PREVIEW_CSS}${DIAGRAM_PREVIEW_CSS}${PREVIEW_SYNTAX_CSS}</style>
|
|
610
674
|
</head>
|
|
611
|
-
<body data-terminal="${snapshot.terminal}" data-events-url="${escapeAttribute(input.eventsUrl)}" data-diagram-script="${escapeAttribute(input.diagramScriptPath ?? "")}">
|
|
675
|
+
<body data-turn-id="${escapeAttribute(input.state.turnId)}" data-terminal="${snapshot.terminal}" data-events-url="${escapeAttribute(input.eventsUrl)}" data-diagram-script="${escapeAttribute(input.diagramScriptPath ?? "")}">
|
|
612
676
|
<header class="page-header">
|
|
613
677
|
<div class="header-inner">
|
|
614
678
|
<div class="header-top">
|
|
@@ -627,7 +691,7 @@ export function renderTurnPreviewPage(input: {
|
|
|
627
691
|
|
|
628
692
|
export function renderTurnPreviewPatch(
|
|
629
693
|
state: TurnViewState, changed: Set<string>, removed: Set<string>,
|
|
630
|
-
localFileUrl:
|
|
694
|
+
localFileUrl: PreviewFileUrl, language: TurnPreviewLanguage,
|
|
631
695
|
): TurnPreviewSnapshot & { removed: string[]; before: Record<string, string> } {
|
|
632
696
|
const visible = visibleTurnActivities(state);
|
|
633
697
|
const visibleIds = new Set(visible.map((activity) => activity.id));
|
|
@@ -646,15 +710,15 @@ export function renderTurnPreviewPatch(
|
|
|
646
710
|
|
|
647
711
|
export function renderTurnPreviewSnapshot(
|
|
648
712
|
state: TurnViewState,
|
|
649
|
-
localFileUrl?:
|
|
713
|
+
localFileUrl?: PreviewFileUrl,
|
|
650
714
|
language: TurnPreviewLanguage = "zh",
|
|
651
715
|
options: { deferDetails?: boolean } = {},
|
|
652
716
|
): TurnPreviewSnapshot {
|
|
653
717
|
const labels = previewLabels(language);
|
|
654
|
-
const resolveFileUrl = localFileUrl ? (filePath
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
return localFileUrl(
|
|
718
|
+
const resolveFileUrl: PreviewFileUrl | undefined = localFileUrl ? (filePath, options) => {
|
|
719
|
+
const target = path.isAbsolute(filePath) || path.win32.isAbsolute(filePath) ? filePath
|
|
720
|
+
: state.projectCwd && path.isAbsolute(state.projectCwd) ? path.resolve(state.projectCwd, filePath) : undefined;
|
|
721
|
+
return target ? options ? localFileUrl(target, options) : localFileUrl(target) : undefined;
|
|
658
722
|
} : undefined;
|
|
659
723
|
const renderText = (value: string): string => renderMarkdown(value, state.projectCwd, localFileUrl, language);
|
|
660
724
|
const timeline = renderTimeline({ ...state, activities: visibleTurnActivities(state) }, renderText, resolveFileUrl, state.fullToolOutputs, state.fullToolErrors, language, state.projectCwd, options.deferDetails);
|
|
@@ -736,7 +800,7 @@ function renderPlan(state: TurnViewState, language: TurnPreviewLanguage): string
|
|
|
736
800
|
function renderTimeline(
|
|
737
801
|
state: TurnViewState,
|
|
738
802
|
renderText: (value: string) => string,
|
|
739
|
-
localFileUrl?:
|
|
803
|
+
localFileUrl?: PreviewFileUrl,
|
|
740
804
|
fullToolOutputs?: Record<string, string>,
|
|
741
805
|
fullToolErrors?: Record<string, string>,
|
|
742
806
|
language: TurnPreviewLanguage = "zh",
|
|
@@ -800,7 +864,7 @@ function leadingReasoningHeading(text: string): { title: string; body: string }
|
|
|
800
864
|
function renderReasoningItem(
|
|
801
865
|
item: TurnReasoningItem,
|
|
802
866
|
cwd: string | undefined,
|
|
803
|
-
localFileUrl:
|
|
867
|
+
localFileUrl: PreviewFileUrl | undefined,
|
|
804
868
|
language: TurnPreviewLanguage,
|
|
805
869
|
deferDetails: boolean,
|
|
806
870
|
): string {
|
|
@@ -819,7 +883,7 @@ function renderReasoningItem(
|
|
|
819
883
|
function renderReasoningBody(
|
|
820
884
|
item: TurnReasoningItem,
|
|
821
885
|
cwd: string | undefined,
|
|
822
|
-
localFileUrl:
|
|
886
|
+
localFileUrl: PreviewFileUrl | undefined,
|
|
823
887
|
language: TurnPreviewLanguage,
|
|
824
888
|
presentation = reasoningPresentation(item),
|
|
825
889
|
): string {
|
|
@@ -838,7 +902,7 @@ function reasoningRevision(item: TurnReasoningItem, cwd?: string): string {
|
|
|
838
902
|
function renderActivity(
|
|
839
903
|
activity: Exclude<TurnActivity, { kind: "reasoning" }>,
|
|
840
904
|
renderText: (value: string) => string,
|
|
841
|
-
localFileUrl?:
|
|
905
|
+
localFileUrl?: PreviewFileUrl,
|
|
842
906
|
fullToolOutputs?: Record<string, string>,
|
|
843
907
|
fullToolErrors?: Record<string, string>,
|
|
844
908
|
language: TurnPreviewLanguage = "zh",
|
|
@@ -862,7 +926,7 @@ function renderMessageActivity(id: string, text: string, kind: string, renderTex
|
|
|
862
926
|
return `<article class="activity message ${kind}" data-activity="${escapeAttribute(id)}"><div class="markdown">${renderText(text)}${images}</div></article>`;
|
|
863
927
|
}
|
|
864
928
|
|
|
865
|
-
function renderMessageImages(paths: string[] | undefined, localFileUrl:
|
|
929
|
+
function renderMessageImages(paths: string[] | undefined, localFileUrl: PreviewFileUrl | undefined, language: TurnPreviewLanguage): string {
|
|
866
930
|
if (!paths?.length) return "";
|
|
867
931
|
return [...new Set(paths)].map((filePath, index) => {
|
|
868
932
|
const label = language === "zh" ? `图片 ${index + 1}` : `Image ${index + 1}`;
|
|
@@ -883,7 +947,7 @@ function renderMessageImages(paths: string[] | undefined, localFileUrl: ((filePa
|
|
|
883
947
|
function renderToolActivity(
|
|
884
948
|
activityId: string,
|
|
885
949
|
tool: ToolState,
|
|
886
|
-
localFileUrl?:
|
|
950
|
+
localFileUrl?: PreviewFileUrl,
|
|
887
951
|
fullToolOutputs?: Record<string, string>,
|
|
888
952
|
fullToolErrors?: Record<string, string>,
|
|
889
953
|
language: TurnPreviewLanguage = "zh",
|
|
@@ -916,7 +980,7 @@ function renderToolActivity(
|
|
|
916
980
|
function renderToolBody(
|
|
917
981
|
activityId: string,
|
|
918
982
|
tool: ToolState,
|
|
919
|
-
localFileUrl?:
|
|
983
|
+
localFileUrl?: PreviewFileUrl,
|
|
920
984
|
fullToolOutputs?: Record<string, string>,
|
|
921
985
|
fullToolErrors?: Record<string, string>,
|
|
922
986
|
language: TurnPreviewLanguage = "zh",
|
|
@@ -1109,7 +1173,7 @@ function formatShortDuration(duration: string): string {
|
|
|
1109
1173
|
|
|
1110
1174
|
function renderToolImage(
|
|
1111
1175
|
tool: ToolState,
|
|
1112
|
-
localFileUrl?:
|
|
1176
|
+
localFileUrl?: PreviewFileUrl,
|
|
1113
1177
|
language: TurnPreviewLanguage = "zh",
|
|
1114
1178
|
): string {
|
|
1115
1179
|
if (!tool.imagePath || !localFileUrl) return "";
|
|
@@ -1127,7 +1191,7 @@ function renderToolImage(
|
|
|
1127
1191
|
function renderFileSummary(
|
|
1128
1192
|
state: TurnViewState,
|
|
1129
1193
|
language: TurnPreviewLanguage,
|
|
1130
|
-
localFileUrl?:
|
|
1194
|
+
localFileUrl?: PreviewFileUrl,
|
|
1131
1195
|
deferDetails = false,
|
|
1132
1196
|
): string {
|
|
1133
1197
|
const labels = previewLabels(language);
|
|
@@ -1136,7 +1200,7 @@ function renderFileSummary(
|
|
|
1136
1200
|
return `<details class="files-summary" data-activity-id="turn:files-summary"${lazy}><summary><h2>${escapeHtml(labels.fileChanges)} <span>${state.fileSummary.length}</span></h2></summary>${body}</details>`;
|
|
1137
1201
|
}
|
|
1138
1202
|
|
|
1139
|
-
function renderFileSummaryBody(state: TurnViewState, localFileUrl?:
|
|
1203
|
+
function renderFileSummaryBody(state: TurnViewState, localFileUrl?: PreviewFileUrl): string {
|
|
1140
1204
|
return `<ul class="files">${state.fileSummary.map((file) => renderFileEntry(file, localFileUrl, state.projectCwd)).join("")}</ul>`;
|
|
1141
1205
|
}
|
|
1142
1206
|
|
|
@@ -1167,13 +1231,13 @@ export interface TurnPreviewDetail {
|
|
|
1167
1231
|
export function renderTurnPreviewDetail(
|
|
1168
1232
|
state: TurnViewState,
|
|
1169
1233
|
key: string,
|
|
1170
|
-
localFileUrl?:
|
|
1234
|
+
localFileUrl?: PreviewFileUrl,
|
|
1171
1235
|
language: TurnPreviewLanguage = "zh",
|
|
1172
1236
|
): TurnPreviewDetail | undefined {
|
|
1173
|
-
const resolveFileUrl = localFileUrl ? (filePath
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
return localFileUrl(
|
|
1237
|
+
const resolveFileUrl: PreviewFileUrl | undefined = localFileUrl ? (filePath, options) => {
|
|
1238
|
+
const target = path.isAbsolute(filePath) || path.win32.isAbsolute(filePath) ? filePath
|
|
1239
|
+
: state.projectCwd && path.isAbsolute(state.projectCwd) ? path.resolve(state.projectCwd, filePath) : undefined;
|
|
1240
|
+
return target ? options ? localFileUrl(target, options) : localFileUrl(target) : undefined;
|
|
1177
1241
|
} : undefined;
|
|
1178
1242
|
if (key === "files" && state.fileSummary.length > 0) {
|
|
1179
1243
|
return { key, revision: fileSummaryRevision(state), content: renderFileSummaryBody(state, resolveFileUrl) };
|
|
@@ -1195,9 +1259,9 @@ export function renderTurnPreviewDetail(
|
|
|
1195
1259
|
};
|
|
1196
1260
|
}
|
|
1197
1261
|
|
|
1198
|
-
function renderFileEntry(file: FileSummary, localFileUrl?:
|
|
1262
|
+
function renderFileEntry(file: FileSummary, localFileUrl?: PreviewFileUrl, projectCwd?: string): string {
|
|
1199
1263
|
const label = `<code>${escapeHtml(displayFilePath(file.path, projectCwd))}</code>`;
|
|
1200
|
-
const url = localFileUrl?.(file.path);
|
|
1264
|
+
const url = localFileUrl?.(file.path, { diff: true });
|
|
1201
1265
|
const link = url
|
|
1202
1266
|
? `<a class="file-link" href="${escapeAttribute(url)}" target="_blank" rel="noreferrer noopener">${label}</a>`
|
|
1203
1267
|
: label;
|
|
@@ -1238,7 +1302,7 @@ function previewTitle(state: TurnViewState): string {
|
|
|
1238
1302
|
return value.length > 80 ? `${value.slice(0, 79)}…` : value;
|
|
1239
1303
|
}
|
|
1240
1304
|
|
|
1241
|
-
function renderMarkdown(value: string, projectCwd?: string, localFileUrl?:
|
|
1305
|
+
function renderMarkdown(value: string, projectCwd?: string, localFileUrl?: PreviewFileUrl, language: TurnPreviewLanguage = "zh"): string {
|
|
1242
1306
|
const environment = { language };
|
|
1243
1307
|
const tokens = MARKDOWN.parse(value, environment);
|
|
1244
1308
|
// Only the directory is used to resolve relative links; no Markdown file is created.
|
|
@@ -10,7 +10,7 @@ export async function sendTerminalAuthorization(
|
|
|
10
10
|
const card = new CardRenderer().renderTerminalAuthorization(view);
|
|
11
11
|
if (isThreadContextKey(view.contextKey)) {
|
|
12
12
|
if (!outbound.replyInteractiveCard || !view.commandCardMessageId) {
|
|
13
|
-
throw new Error("
|
|
13
|
+
throw new Error("无法向原话题发送终端管理卡,请重新打开命令卡片。");
|
|
14
14
|
}
|
|
15
15
|
return outbound.replyInteractiveCard(view.contextKey, { messageId: view.commandCardMessageId, replyInThread: true }, card);
|
|
16
16
|
}
|