@keyou007/agent-bot 0.1.27-alpha.3 → 0.1.27-alpha.5
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 +32 -0
- package/README.md +102 -18
- package/README.zh.md +102 -18
- package/assets/agent-bot.ico +0 -0
- package/assets/roboto-mono-OFL.txt +93 -0
- package/assets/roboto-mono-latin.woff2 +0 -0
- package/assets/workspace-drafts.js +88 -0
- package/assets/workspace-sessions.js +2676 -243
- package/assets/workspace.css +553 -44
- package/assets/workspace.js +3429 -327
- package/dist/cli/SelfUpdateObserver.js +124 -0
- package/dist/cli/SelfUpdateObserver.js.map +1 -0
- package/dist/cli/SelfUpdateRunner.js +267 -70
- package/dist/cli/SelfUpdateRunner.js.map +1 -1
- package/dist/cli/SelfUpdater.js +54 -15
- package/dist/cli/SelfUpdater.js.map +1 -1
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +6 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.js +85 -6
- package/dist/cli.js.map +1 -1
- package/dist/codex/CodexEventMapper.js +29 -5
- package/dist/codex/CodexEventMapper.js.map +1 -1
- package/dist/codex/CodexRuntime.js +3 -0
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/feishu/CardRenderer.js +45 -13
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/ConsoleFeishuClient.js +4 -0
- package/dist/feishu/ConsoleFeishuClient.js.map +1 -1
- package/dist/feishu/FeishuMarkdown.js +2 -14
- package/dist/feishu/FeishuMarkdown.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +9 -0
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +51 -22
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +47 -12
- package/dist/index.js.map +1 -1
- package/dist/local-files/DiagramPreview.js +11 -6
- package/dist/local-files/DiagramPreview.js.map +1 -1
- package/dist/local-files/GitDiffPreview.js +106 -14
- package/dist/local-files/GitDiffPreview.js.map +1 -1
- package/dist/local-files/LiveMarkup.js +104 -0
- package/dist/local-files/LiveMarkup.js.map +1 -0
- package/dist/local-files/LocalFileViewerServer.js +141 -122
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/MarkdownExport.js +54 -0
- package/dist/local-files/MarkdownExport.js.map +1 -0
- package/dist/local-files/PreviewCodeFont.js +11 -0
- package/dist/local-files/PreviewCodeFont.js.map +1 -0
- package/dist/local-files/PreviewSyntaxHighlight.js +73 -0
- package/dist/local-files/PreviewSyntaxHighlight.js.map +1 -1
- package/dist/local-files/ToolCommandDisplay.js +111 -0
- package/dist/local-files/ToolCommandDisplay.js.map +1 -0
- package/dist/local-files/TurnPreviewPage.js +53 -276
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/local-files/WorkspaceFileEvents.js +206 -0
- package/dist/local-files/WorkspaceFileEvents.js.map +1 -0
- package/dist/local-files/WorkspaceFiles.js +79 -3
- package/dist/local-files/WorkspaceFiles.js.map +1 -1
- package/dist/local-files/WorkspaceImages.js +43 -0
- package/dist/local-files/WorkspaceImages.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +24 -6
- package/dist/local-files/WorkspacePage.js.map +1 -1
- package/dist/local-files/WorkspaceSessions.js +1153 -104
- package/dist/local-files/WorkspaceSessions.js.map +1 -1
- package/dist/local-files/WorkspaceTimeline.js +129 -0
- package/dist/local-files/WorkspaceTimeline.js.map +1 -0
- package/dist/presentation/OutboundRouter.js +15 -6
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +31 -22
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +335 -113
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/proxy/TaskMetadata.js +86 -0
- package/dist/proxy/TaskMetadata.js.map +1 -0
- package/dist/scheduling/ScheduleCards.js +10 -4
- package/dist/scheduling/ScheduleCards.js.map +1 -1
- package/dist/scheduling/ScheduleCommand.js +4 -0
- package/dist/scheduling/ScheduleCommand.js.map +1 -1
- package/dist/scheduling/ScheduledTaskStore.js +53 -12
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
- package/dist/scheduling/types.js +19 -4
- package/dist/scheduling/types.js.map +1 -1
- package/dist/state/StateStore.js +213 -23
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +157 -39
- package/dist/state/TurnPreviewJournal.js.map +1 -1
- package/dist/state/TurnToolText.js +172 -0
- package/dist/state/TurnToolText.js.map +1 -0
- package/dist/state/migrations.js +4 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +9 -6
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/dist/terminal/TerminalPage.js +5 -0
- package/dist/terminal/TerminalPage.js.map +1 -1
- package/dist/updates/AutomaticUpdatePreparer.js +63 -12
- package/dist/updates/AutomaticUpdatePreparer.js.map +1 -1
- package/dist/updates/ManualUpdateController.js +7 -2
- package/dist/updates/ManualUpdateController.js.map +1 -1
- package/dist/utils/promptAttachments.js +22 -0
- package/dist/utils/promptAttachments.js.map +1 -0
- package/dist/utils/promptQuotes.js +47 -0
- package/dist/utils/promptQuotes.js.map +1 -0
- package/dist/utils/toolTimestamp.js +6 -0
- package/dist/utils/toolTimestamp.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +23 -2
- package/src/cli/SelfUpdateObserver.ts +111 -0
- package/src/cli/SelfUpdateRunner.ts +271 -85
- package/src/cli/SelfUpdater.ts +53 -16
- package/src/cli/controlProtocol.ts +1 -0
- package/src/cli/help.ts +6 -0
- package/src/cli.ts +71 -5
- package/src/codex/CodexEventMapper.ts +25 -5
- package/src/codex/CodexRuntime.ts +4 -0
- package/src/feishu/CardRenderer.ts +48 -13
- package/src/feishu/ConsoleFeishuClient.ts +6 -1
- package/src/feishu/FeishuMarkdown.ts +2 -14
- package/src/feishu/FeishuMessageClient.ts +10 -0
- package/src/feishu/FeishuTurnPresenter.ts +49 -16
- package/src/feishu/types.ts +1 -0
- package/src/index.ts +47 -12
- package/src/local-files/DiagramPreview.ts +11 -6
- package/src/local-files/GitDiffPreview.ts +107 -15
- package/src/local-files/LiveMarkup.ts +103 -0
- package/src/local-files/LocalFileViewerServer.ts +128 -125
- package/src/local-files/MarkdownExport.ts +54 -0
- package/src/local-files/PreviewCodeFont.ts +12 -0
- package/src/local-files/PreviewSyntaxHighlight.ts +75 -0
- package/src/local-files/ToolCommandDisplay.ts +104 -0
- package/src/local-files/TurnPreviewPage.ts +58 -261
- package/src/local-files/WorkspaceFileEvents.ts +186 -0
- package/src/local-files/WorkspaceFiles.ts +72 -5
- package/src/local-files/WorkspaceImages.ts +35 -0
- package/src/local-files/WorkspacePage.ts +24 -6
- package/src/local-files/WorkspaceSessions.ts +1057 -111
- package/src/local-files/WorkspaceTimeline.ts +135 -0
- package/src/presentation/OutboundRouter.ts +18 -4
- package/src/presentation/TurnStateReducer.ts +30 -19
- package/src/presentation/turnViewTypes.ts +3 -1
- package/src/proxy/ProxySessionController.ts +336 -96
- package/src/proxy/TaskMetadata.ts +81 -0
- package/src/runtime/types.ts +2 -1
- package/src/scheduling/ScheduleCards.ts +10 -4
- package/src/scheduling/ScheduleCommand.ts +4 -0
- package/src/scheduling/ScheduledTaskStore.ts +56 -9
- package/src/scheduling/types.ts +27 -4
- package/src/state/StateStore.ts +227 -24
- package/src/state/TurnPreviewJournal.ts +155 -38
- package/src/state/TurnToolText.ts +156 -0
- package/src/state/migrations.ts +4 -0
- package/src/supervision/SafeRestartNotifier.ts +9 -6
- package/src/terminal/TerminalPage.ts +5 -0
- package/src/updates/AutomaticUpdatePreparer.ts +52 -11
- package/src/updates/ManualUpdateController.ts +8 -3
- package/src/utils/promptAttachments.ts +27 -0
- package/src/utils/promptQuotes.ts +48 -0
- package/src/utils/toolTimestamp.ts +5 -0
|
@@ -48,6 +48,8 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
48
48
|
const states = new WeakMap();
|
|
49
49
|
let library;
|
|
50
50
|
let sequence = 0;
|
|
51
|
+
const workspaceTheme = () => document.documentElement.dataset.workspaceTheme;
|
|
52
|
+
const isRendered = (state) => state.rendered === state.source && state.renderedTheme === workspaceTheme();
|
|
51
53
|
const loadLibrary = () => {
|
|
52
54
|
if (!library) library = new Promise((resolve, reject) => {
|
|
53
55
|
const url = document.body.dataset.diagramScript;
|
|
@@ -84,20 +86,21 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
84
86
|
block.querySelector(".diagram-source").hidden = mode !== "source";
|
|
85
87
|
block.dataset.diagramSize = state.size;
|
|
86
88
|
const sizeButton = block.querySelector("[data-diagram-size-toggle]");
|
|
87
|
-
|
|
89
|
+
const ready = isRendered(state);
|
|
90
|
+
sizeButton.hidden = mode !== "preview" || !ready;
|
|
88
91
|
sizeButton.textContent = state.size === "actual" ? (zh ? "适应" : "Fit") : (zh ? "原大" : "Actual size");
|
|
89
92
|
sizeButton.setAttribute("aria-label", state.size === "actual"
|
|
90
93
|
? (zh ? "适应容器宽度" : "Fit diagram to width")
|
|
91
94
|
: (zh ? "按原始尺寸查看图表" : "View diagram at actual size"));
|
|
92
95
|
const notice = block.querySelector(".diagram-notice");
|
|
93
|
-
notice.hidden = !state.error && (
|
|
96
|
+
notice.hidden = !state.error && (ready || mode === "source");
|
|
94
97
|
notice.textContent = state.error ? failed : loading;
|
|
95
98
|
block.querySelectorAll("[data-diagram-mode]").forEach((button) => {
|
|
96
99
|
button.setAttribute("aria-pressed", String(button.dataset.diagramMode === mode));
|
|
97
100
|
});
|
|
98
101
|
};
|
|
99
102
|
const render = async (block, state, revision) => {
|
|
100
|
-
const source = state.source;
|
|
103
|
+
const source = state.source, theme = workspaceTheme();
|
|
101
104
|
let container;
|
|
102
105
|
try {
|
|
103
106
|
// Keep model-authored Mermaid config from weakening the renderer's safety policy.
|
|
@@ -109,7 +112,8 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
109
112
|
container = document.createElement("div");
|
|
110
113
|
container.style.cssText = "position:absolute;left:-100000px;top:0;width:1000px;visibility:hidden;pointer-events:none";
|
|
111
114
|
document.body.appendChild(container);
|
|
112
|
-
const
|
|
115
|
+
const themedSource = theme ? "---\nconfig:\n theme: " + (theme === "dark" ? "dark" : "default") + "\n---\n" + source : source;
|
|
116
|
+
const result = await mermaid.render("agentbot-diagram-" + (++sequence), themedSource, container);
|
|
113
117
|
if (!block.isConnected || state.revision !== revision) return;
|
|
114
118
|
const template = document.createElement("template");
|
|
115
119
|
template.innerHTML = result.svg;
|
|
@@ -128,6 +132,7 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
128
132
|
}
|
|
129
133
|
block.querySelector(".diagram-preview").replaceChildren(template.content);
|
|
130
134
|
state.rendered = source;
|
|
135
|
+
state.renderedTheme = theme;
|
|
131
136
|
state.error = false;
|
|
132
137
|
show(block, state);
|
|
133
138
|
} catch {
|
|
@@ -137,7 +142,7 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
137
142
|
const schedule = (block, state) => {
|
|
138
143
|
clearTimeout(state.timer);
|
|
139
144
|
state.revision += 1;
|
|
140
|
-
if (state.mode !== "preview" || state
|
|
145
|
+
if (state.mode !== "preview" || isRendered(state)) return;
|
|
141
146
|
const revision = state.revision;
|
|
142
147
|
state.timer = setTimeout(() => void render(block, state, revision), 180);
|
|
143
148
|
};
|
|
@@ -162,7 +167,7 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
162
167
|
schedule(block, state);
|
|
163
168
|
});
|
|
164
169
|
});
|
|
165
|
-
} else if (state.source === source && (state.mode !== "preview" || state
|
|
170
|
+
} else if (state.source === source && (state.mode !== "preview" || isRendered(state) || state.error)) { return; }
|
|
166
171
|
else { state.source = source; state.error = false; }
|
|
167
172
|
show(block, state);
|
|
168
173
|
schedule(block, state);
|
|
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { highlightPreviewCode, highlightTextLines, MAX_PREVIEW_HIGHLIGHT_BYTES, syntaxLanguageFor } from "./PreviewSyntaxHighlight.js";
|
|
5
6
|
|
|
6
7
|
const runFile = promisify(execFile);
|
|
7
8
|
const MAX_DIFF_BYTES = 1024 * 1024;
|
|
@@ -55,7 +56,37 @@ export async function readGitFileDiff(filePath: string): Promise<string | undefi
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
type DiffLine = { kind: "context" | "addition" | "deletion"; text: string; oldNumber?: number; newNumber?: number };
|
|
59
|
+
type DiffLine = { kind: "context" | "addition" | "deletion"; text: string; oldNumber?: number; newNumber?: number; hunk?: string };
|
|
60
|
+
|
|
61
|
+
const PATCH_HUNK_START = /(?=^@@(?:[ \t]|$))/mu;
|
|
62
|
+
export const PATCH_HUNK_HEADER = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?:.*)$/u;
|
|
63
|
+
|
|
64
|
+
export function highlightRecordedPatch(patch: string, filePath: string, originalPath: string): string | undefined {
|
|
65
|
+
if (Buffer.byteLength(patch, "utf8") > MAX_PREVIEW_HIGHLIGHT_BYTES) return undefined;
|
|
66
|
+
const normalized = patch.replace(/\r\n?/gu, "\n");
|
|
67
|
+
if (!PATCH_HUNK_START.test(normalized)) {
|
|
68
|
+
const language = normalized.startsWith("diff --git ") ? "diff" : syntaxLanguageFor(filePath) ?? "diff";
|
|
69
|
+
return highlightPreviewCode(normalized, language) || undefined;
|
|
70
|
+
}
|
|
71
|
+
return normalized.split(PATCH_HUNK_START).map((block) => {
|
|
72
|
+
if (!block.startsWith("@@")) return highlightPreviewCode(block, "diff") || escapeHtml(block);
|
|
73
|
+
const [header, ...lines] = block.split("\n");
|
|
74
|
+
// Each side gets its own syntax state, including context shared by both sides of the hunk.
|
|
75
|
+
const before = highlightTextLines(lines.filter((line) => /^[ -]/u.test(line)).map((line) => line.slice(1)).join("\n"), originalPath);
|
|
76
|
+
const after = highlightTextLines(lines.filter((line) => /^[ +]/u.test(line)).map((line) => line.slice(1)).join("\n"), filePath);
|
|
77
|
+
let oldLine = 0;
|
|
78
|
+
let newLine = 0;
|
|
79
|
+
const rows = lines.map((line) => {
|
|
80
|
+
switch (line[0]) {
|
|
81
|
+
case "-": return `<span class="hljs-deletion">-${before[oldLine++]}</span>`;
|
|
82
|
+
case "+": return `<span class="hljs-addition">+${after[newLine++]}</span>`;
|
|
83
|
+
case " ": oldLine++; return ` ${after[newLine++]}`;
|
|
84
|
+
default: return escapeHtml(line);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return [`<span class="hljs-meta">${escapeHtml(header!)}</span>`, ...rows].join("\n");
|
|
88
|
+
}).join("");
|
|
89
|
+
}
|
|
59
90
|
|
|
60
91
|
export function renderGitFileDiff(diff: string, currentText: string, highlight?: (text: string) => string[]): string | undefined {
|
|
61
92
|
const source = splitLines(currentText.replace(/^\uFEFF/u, ""));
|
|
@@ -78,7 +109,7 @@ export function renderGitFileDiff(diff: string, currentText: string, highlight?:
|
|
|
78
109
|
// Git identifies edits; fill the gaps from the complete current file, checking hunk coordinates and text.
|
|
79
110
|
for (let index = 1; index < lines.length; index += 1) {
|
|
80
111
|
const line = lines[index]!;
|
|
81
|
-
const hunk =
|
|
112
|
+
const hunk = PATCH_HUNK_HEADER.exec(line);
|
|
82
113
|
if (!hunk) {
|
|
83
114
|
if (line === "\") continue;
|
|
84
115
|
if (inHunks || line.startsWith("@@") || line.startsWith("diff --git ") || line === "GIT binary patch") return undefined;
|
|
@@ -107,17 +138,81 @@ export function renderGitFileDiff(diff: string, currentText: string, highlight?:
|
|
|
107
138
|
while (newLine <= source.length) if (!append("context", source[newLine - 1]!)) return undefined;
|
|
108
139
|
const before = highlight?.(rows.filter((row) => row.kind !== "addition").map((row) => row.text).join("\n"));
|
|
109
140
|
const after = highlight?.(source.join("\n"));
|
|
110
|
-
const
|
|
141
|
+
const oldNumberWidth = Math.max(2, String(oldLine - 1).length);
|
|
142
|
+
const newNumberWidth = Math.max(2, String(newLine - 1).length);
|
|
143
|
+
return renderDiffRows(rows, oldNumberWidth, newNumberWidth, "Git diff", (row) =>
|
|
144
|
+
row.kind === "deletion" ? before?.[row.oldNumber! - 1] : after?.[row.newNumber! - 1]);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function renderRecordedDiff(
|
|
148
|
+
patch: string, filePath: string, originalPath: string, additions?: number, deletions?: number,
|
|
149
|
+
): string {
|
|
150
|
+
const label = "本次修改";
|
|
151
|
+
const normalized = patch.replace(/\r\n?/gu, "\n");
|
|
152
|
+
const rows: Array<DiffLine & { highlighted?: string }> = [];
|
|
153
|
+
if (PATCH_HUNK_START.test(normalized)) {
|
|
154
|
+
for (const block of normalized.split(PATCH_HUNK_START)) {
|
|
155
|
+
const [header, ...lines] = splitLines(block);
|
|
156
|
+
const range = header && PATCH_HUNK_HEADER.exec(header);
|
|
157
|
+
if (!range) continue;
|
|
158
|
+
let oldNumber = Number(range[1]), newNumber = Number(range[3]);
|
|
159
|
+
let oldRemaining = Number(range[2] ?? 1), newRemaining = Number(range[4] ?? 1);
|
|
160
|
+
if (![oldNumber, newNumber, oldRemaining, newRemaining].every(Number.isSafeInteger)) continue;
|
|
161
|
+
const hunk: DiffLine[] = [];
|
|
162
|
+
for (const line of lines) {
|
|
163
|
+
if (line === "\") continue;
|
|
164
|
+
const marker = line[0];
|
|
165
|
+
if (marker !== " " && marker !== "+" && marker !== "-") break;
|
|
166
|
+
if ((marker !== "+" && oldRemaining-- <= 0) || (marker !== "-" && newRemaining-- <= 0)) break;
|
|
167
|
+
hunk.push({ kind: marker === "+" ? "addition" : marker === "-" ? "deletion" : "context", text: line.slice(1),
|
|
168
|
+
oldNumber: marker === "+" ? undefined : oldNumber++, newNumber: marker === "-" ? undefined : newNumber++,
|
|
169
|
+
hunk: hunk.length ? undefined : header });
|
|
170
|
+
}
|
|
171
|
+
const before = highlightTextLines(hunk.filter((row) => row.kind !== "addition").map((row) => row.text).join("\n"), originalPath);
|
|
172
|
+
const after = highlightTextLines(hunk.filter((row) => row.kind !== "deletion").map((row) => row.text).join("\n"), filePath);
|
|
173
|
+
let oldIndex = 0, newIndex = 0;
|
|
174
|
+
for (const row of hunk) {
|
|
175
|
+
const left = row.kind === "addition" ? undefined : before[oldIndex++];
|
|
176
|
+
const right = row.kind === "deletion" ? undefined : after[newIndex++];
|
|
177
|
+
rows.push({ ...row, highlighted: right ?? left });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
} else if (!/^diff --git |^--- [^\n]*\n\+\+\+ /u.test(normalized)) {
|
|
181
|
+
// Whole-file additions and deletions are recorded as file contents instead of hunks.
|
|
182
|
+
const kind = additions && deletions === 0 ? "addition" : deletions && additions === 0 ? "deletion" : undefined;
|
|
183
|
+
if (kind) {
|
|
184
|
+
const highlighted = highlightTextLines(normalized, kind === "addition" ? filePath : originalPath);
|
|
185
|
+
splitLines(normalized).forEach((text, index) => rows.push({ kind, text, highlighted: highlighted[index],
|
|
186
|
+
...(kind === "addition" ? { newNumber: index + 1 } : { oldNumber: index + 1 }) }));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (!rows.length) {
|
|
190
|
+
return `<pre class="code" aria-label="${label}"><code>${highlightRecordedPatch(patch, filePath, originalPath) ?? escapeHtml(patch)}</code></pre>`;
|
|
191
|
+
}
|
|
192
|
+
let oldWidth = 2, newWidth = 2;
|
|
193
|
+
for (const row of rows) {
|
|
194
|
+
oldWidth = Math.max(oldWidth, String(row.oldNumber ?? "").length);
|
|
195
|
+
newWidth = Math.max(newWidth, String(row.newNumber ?? "").length);
|
|
196
|
+
}
|
|
197
|
+
return renderDiffRows(rows, oldWidth, newWidth, label, (_row, index) => rows[index]?.highlighted);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function renderDiffRows(
|
|
201
|
+
rows: DiffLine[], oldNumberWidth: number, newNumberWidth: number, label: string,
|
|
202
|
+
highlight: (row: DiffLine, index: number) => string | undefined,
|
|
203
|
+
): string {
|
|
204
|
+
const content = rows.map((row, index) => {
|
|
111
205
|
const id = row.newNumber !== undefined ? `L${row.newNumber}` : `D${row.oldNumber}`;
|
|
112
206
|
const oldNumber = `<span class="diff-number" aria-hidden="true">${row.oldNumber ?? ""}</span>`;
|
|
113
207
|
const newNumber = row.newNumber !== undefined
|
|
114
208
|
? `<a class="diff-number" href="#${id}" aria-label="Line ${row.newNumber}">${row.newNumber}</a>`
|
|
115
209
|
: '<span class="diff-number" aria-hidden="true"></span>';
|
|
116
210
|
const marker = row.kind === "addition" ? "+" : row.kind === "deletion" ? "-" : " ";
|
|
117
|
-
const text = row
|
|
118
|
-
|
|
211
|
+
const text = highlight(row, index);
|
|
212
|
+
const header = row.hunk ? `<span class="line diff-hunk">${escapeHtml(row.hunk)}</span>` : "";
|
|
213
|
+
return `${header}<span class="line diff-${row.kind}" id="${id}">${oldNumber}${newNumber}<span class="diff-marker" aria-hidden="true">${marker}</span><span class="diff-text">${text ?? escapeHtml(row.text)}</span></span>`;
|
|
119
214
|
}).join("");
|
|
120
|
-
return `<pre class="code git-diff" aria-label="
|
|
215
|
+
return `<pre class="code git-diff" aria-label="${label}" style="--old-line-number-width:${oldNumberWidth}ch;--new-line-number-width:${newNumberWidth}ch"><code>${content}</code></pre>`;
|
|
121
216
|
}
|
|
122
217
|
|
|
123
218
|
function splitLines(value: string): string[] {
|
|
@@ -130,15 +225,12 @@ function escapeHtml(value: string): string {
|
|
|
130
225
|
|
|
131
226
|
export const GIT_DIFF_PREVIEW_CSS = `
|
|
132
227
|
.git-diff .line { display:flex; width:max-content; min-width:100%; padding-right:16px; }
|
|
133
|
-
.git-diff .diff-number { display:inline-block; flex:
|
|
228
|
+
.git-diff .diff-number { display:inline-block; flex:none; box-sizing:content-box; width:var(--new-line-number-width, 2ch); padding:0 6px; text-align:right; color:var(--git-diff-gutter-text, light-dark(#6e7781, #8b949e)); border-right:1px solid var(--git-diff-gutter-border, light-dark(#d8dee4, #3a3b3d)); text-decoration:none; user-select:none; }
|
|
229
|
+
.git-diff .diff-number:first-child { width:var(--old-line-number-width, 2ch); }
|
|
134
230
|
.git-diff .diff-marker { flex:0 0 2em; width:2em; text-align:center; user-select:none; }
|
|
135
231
|
.git-diff .diff-text { white-space:pre; }
|
|
136
|
-
.git-diff .diff-
|
|
137
|
-
.git-diff .diff-
|
|
138
|
-
|
|
139
|
-
@media (
|
|
140
|
-
.git-diff .diff-number { color:#8b949e; border-color:#3a3b3d; }
|
|
141
|
-
.git-diff .diff-addition { background:#033a16; color:#aff5b4; }
|
|
142
|
-
.git-diff .diff-deletion { background:#67060c; color:#ffdcd7; }
|
|
143
|
-
}
|
|
232
|
+
.git-diff .diff-hunk { padding-inline-start:6px; color:var(--git-diff-gutter-text, light-dark(#6e7781, #8b949e)); }
|
|
233
|
+
.git-diff .diff-addition { background:var(--git-diff-added-bg, light-dark(#dafbe1, #033a16)); color:var(--git-diff-added-text, light-dark(#116329, #aff5b4)); }
|
|
234
|
+
.git-diff .diff-deletion { background:var(--git-diff-removed-bg, light-dark(#ffebe9, #67060c)); color:var(--git-diff-removed-text, light-dark(#a40e26, #ffdcd7)); }
|
|
235
|
+
@media (max-width:640px) { .git-diff .diff-number { padding:0 4px; } }
|
|
144
236
|
`;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export const LIVE_MARKUP_CLIENT_SCRIPT = `(() => {
|
|
2
|
+
const nodeKey = (node) => {
|
|
3
|
+
if (node.nodeType !== 1) return undefined;
|
|
4
|
+
for (const attribute of ["data-preview-key", "data-activity", "data-activity-id", "data-scroll-id", "data-reasoning-field", "data-reasoning-part"]) {
|
|
5
|
+
if (node.hasAttribute(attribute)) return attribute + ":" + node.getAttribute(attribute);
|
|
6
|
+
}
|
|
7
|
+
if (node.tagName === "IMG") return "image:" + node.getAttribute("src");
|
|
8
|
+
// Keep Markdown image paragraphs/links anchored when text is inserted before them.
|
|
9
|
+
if (["P", "A", "FIGURE", "PICTURE"].includes(node.tagName)) {
|
|
10
|
+
const image = node.querySelector("img");
|
|
11
|
+
if (image) return node.tagName + ":image:" + image.getAttribute("src");
|
|
12
|
+
}
|
|
13
|
+
for (const name of ["markdown", "tool-command", "tool-image", "files", "tool-header", "tool-body", "tool-footer"]) {
|
|
14
|
+
if (node.classList.contains(name)) return node.tagName + ":" + name;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
18
|
+
const compatible = (current, next) => current.nodeType === next.nodeType && current.nodeName === next.nodeName;
|
|
19
|
+
const patchNode = (current, next) => {
|
|
20
|
+
if (!compatible(current, next)) {
|
|
21
|
+
current.replaceWith(next.cloneNode(true));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// Summary snapshots never own a detail body that has already been fetched.
|
|
25
|
+
if (current.nodeType === 1 && current.hasAttribute("data-detail-body") && next.hasAttribute("data-detail-body")) return;
|
|
26
|
+
if (current.isEqualNode(next)) return;
|
|
27
|
+
if (current.nodeType !== 1) {
|
|
28
|
+
if (current.nodeValue !== next.nodeValue) current.nodeValue = next.nodeValue;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (current.hasAttribute("data-diagram") && next.hasAttribute("data-diagram")) {
|
|
32
|
+
const code = current.querySelector(".diagram-source code");
|
|
33
|
+
const nextCode = next.querySelector(".diagram-source code");
|
|
34
|
+
if (code && nextCode && code.textContent !== nextCode.textContent) {
|
|
35
|
+
code.textContent = nextCode.textContent;
|
|
36
|
+
window.agentBotDiagrams.refresh(current);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const preserveOpen = current.tagName === "DETAILS";
|
|
41
|
+
for (const attribute of Array.from(current.attributes)) {
|
|
42
|
+
if (preserveOpen && attribute.name === "open") continue;
|
|
43
|
+
if (!next.hasAttribute(attribute.name)) current.removeAttribute(attribute.name);
|
|
44
|
+
}
|
|
45
|
+
for (const attribute of Array.from(next.attributes)) {
|
|
46
|
+
if (preserveOpen && attribute.name === "open") continue;
|
|
47
|
+
if (current.getAttribute(attribute.name) !== attribute.value) current.setAttribute(attribute.name, attribute.value);
|
|
48
|
+
}
|
|
49
|
+
patchChildren(current, next);
|
|
50
|
+
};
|
|
51
|
+
const patchChildren = (parent, next) => {
|
|
52
|
+
const nextChildren = Array.from(next.childNodes);
|
|
53
|
+
const nextKeys = new Set(nextChildren.map(nodeKey).filter((key) => key !== undefined));
|
|
54
|
+
const remaining = new Set(Array.from(parent.childNodes));
|
|
55
|
+
const keyed = new Map();
|
|
56
|
+
for (const child of remaining) {
|
|
57
|
+
const key = nodeKey(child);
|
|
58
|
+
if (key === undefined) continue;
|
|
59
|
+
if (!nextKeys.has(key)) {
|
|
60
|
+
child.remove();
|
|
61
|
+
remaining.delete(child);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const matches = keyed.get(key) || [];
|
|
65
|
+
matches.push(child);
|
|
66
|
+
keyed.set(key, matches);
|
|
67
|
+
}
|
|
68
|
+
let cursor = parent.firstChild;
|
|
69
|
+
for (const child of nextChildren) {
|
|
70
|
+
const key = nodeKey(child);
|
|
71
|
+
const matches = key === undefined ? undefined : keyed.get(key);
|
|
72
|
+
const current = key === undefined
|
|
73
|
+
? cursor && nodeKey(cursor) === undefined && compatible(cursor, child) ? cursor : undefined
|
|
74
|
+
: matches?.find((candidate) => remaining.has(candidate) && compatible(candidate, child));
|
|
75
|
+
if (current) {
|
|
76
|
+
remaining.delete(current);
|
|
77
|
+
// Drop obsolete text/markup before a retained block without detaching that block.
|
|
78
|
+
while (cursor && cursor !== current && nodeKey(cursor) === undefined) {
|
|
79
|
+
const obsolete = cursor;
|
|
80
|
+
cursor = cursor.nextSibling;
|
|
81
|
+
remaining.delete(obsolete);
|
|
82
|
+
obsolete.remove();
|
|
83
|
+
}
|
|
84
|
+
if (current !== cursor) {
|
|
85
|
+
if (typeof parent.moveBefore === "function" && current.isConnected) parent.moveBefore(current, cursor);
|
|
86
|
+
else parent.insertBefore(current, cursor);
|
|
87
|
+
}
|
|
88
|
+
patchNode(current, child);
|
|
89
|
+
cursor = current.nextSibling;
|
|
90
|
+
} else {
|
|
91
|
+
const added = child.cloneNode(true);
|
|
92
|
+
parent.insertBefore(added, cursor);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const child of remaining) child.remove();
|
|
96
|
+
};
|
|
97
|
+
const patchMarkup = (element, markup) => {
|
|
98
|
+
const template = document.createElement("template");
|
|
99
|
+
template.innerHTML = markup;
|
|
100
|
+
patchChildren(element, template.content);
|
|
101
|
+
};
|
|
102
|
+
window.agentBotLiveMarkup = { nodeKey, patchMarkup, patchNode };
|
|
103
|
+
})();\n`;
|