@keyou007/agent-bot 0.1.27-alpha.2 → 0.1.27-alpha.4
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 +22 -0
- package/README.md +78 -13
- package/README.zh.md +78 -13
- 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 +1935 -232
- package/assets/workspace.css +360 -35
- package/assets/workspace.js +2115 -249
- 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 +26 -14
- 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 +40 -10
- 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 +219 -129
- 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 +23 -269
- 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 +15 -0
- package/dist/local-files/WorkspaceImages.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +20 -5
- package/dist/local-files/WorkspacePage.js.map +1 -1
- package/dist/local-files/WorkspaceSessions.js +881 -79
- package/dist/local-files/WorkspaceSessions.js.map +1 -1
- package/dist/local-files/WorkspaceTimeline.js +105 -0
- package/dist/local-files/WorkspaceTimeline.js.map +1 -0
- package/dist/presentation/OutboundRouter.js +13 -6
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +28 -21
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +229 -92
- 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 +51 -12
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
- package/dist/scheduling/types.js +18 -4
- package/dist/scheduling/types.js.map +1 -1
- package/dist/state/StateStore.js +145 -19
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +143 -36
- 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 +20 -0
- package/dist/utils/promptAttachments.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 +22 -8
- 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 +38 -10
- package/src/local-files/LiveMarkup.ts +103 -0
- package/src/local-files/LocalFileViewerServer.ts +207 -132
- 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 +23 -254
- package/src/local-files/WorkspaceFileEvents.ts +186 -0
- package/src/local-files/WorkspaceFiles.ts +72 -5
- package/src/local-files/WorkspaceImages.ts +10 -0
- package/src/local-files/WorkspacePage.ts +20 -5
- package/src/local-files/WorkspaceSessions.ts +811 -82
- package/src/local-files/WorkspaceTimeline.ts +109 -0
- package/src/presentation/OutboundRouter.ts +15 -4
- package/src/presentation/TurnStateReducer.ts +27 -18
- package/src/presentation/turnViewTypes.ts +2 -0
- package/src/proxy/ProxySessionController.ts +226 -77
- 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 +54 -9
- package/src/scheduling/types.ts +24 -4
- package/src/state/StateStore.ts +157 -20
- package/src/state/TurnPreviewJournal.ts +138 -34
- 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 +24 -0
- package/src/utils/toolTimestamp.ts +5 -0
|
@@ -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;
|
|
@@ -57,6 +58,35 @@ export async function readGitFileDiff(filePath: string): Promise<string | undefi
|
|
|
57
58
|
|
|
58
59
|
type DiffLine = { kind: "context" | "addition" | "deletion"; text: string; oldNumber?: number; newNumber?: number };
|
|
59
60
|
|
|
61
|
+
const PATCH_HUNK_START = /(?=^@@(?:[ \t]|$))/mu;
|
|
62
|
+
|
|
63
|
+
export function highlightRecordedPatch(patch: string, filePath: string, originalPath: string): string | undefined {
|
|
64
|
+
if (Buffer.byteLength(patch, "utf8") > MAX_PREVIEW_HIGHLIGHT_BYTES) return undefined;
|
|
65
|
+
const normalized = patch.replace(/\r\n?/gu, "\n");
|
|
66
|
+
if (!PATCH_HUNK_START.test(normalized)) {
|
|
67
|
+
const language = normalized.startsWith("diff --git ") ? "diff" : syntaxLanguageFor(filePath) ?? "diff";
|
|
68
|
+
return highlightPreviewCode(normalized, language) || undefined;
|
|
69
|
+
}
|
|
70
|
+
return normalized.split(PATCH_HUNK_START).map((block) => {
|
|
71
|
+
if (!block.startsWith("@@")) return highlightPreviewCode(block, "diff") || escapeHtml(block);
|
|
72
|
+
const [header, ...lines] = block.split("\n");
|
|
73
|
+
// Each side gets its own syntax state, including context shared by both sides of the hunk.
|
|
74
|
+
const before = highlightTextLines(lines.filter((line) => /^[ -]/u.test(line)).map((line) => line.slice(1)).join("\n"), originalPath);
|
|
75
|
+
const after = highlightTextLines(lines.filter((line) => /^[ +]/u.test(line)).map((line) => line.slice(1)).join("\n"), filePath);
|
|
76
|
+
let oldLine = 0;
|
|
77
|
+
let newLine = 0;
|
|
78
|
+
const rows = lines.map((line) => {
|
|
79
|
+
switch (line[0]) {
|
|
80
|
+
case "-": return `<span class="hljs-deletion">-${before[oldLine++]}</span>`;
|
|
81
|
+
case "+": return `<span class="hljs-addition">+${after[newLine++]}</span>`;
|
|
82
|
+
case " ": oldLine++; return ` ${after[newLine++]}`;
|
|
83
|
+
default: return escapeHtml(line);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return [`<span class="hljs-meta">${escapeHtml(header!)}</span>`, ...rows].join("\n");
|
|
87
|
+
}).join("");
|
|
88
|
+
}
|
|
89
|
+
|
|
60
90
|
export function renderGitFileDiff(diff: string, currentText: string, highlight?: (text: string) => string[]): string | undefined {
|
|
61
91
|
const source = splitLines(currentText.replace(/^\uFEFF/u, ""));
|
|
62
92
|
if (source.length > MAX_MERGED_LINES) return undefined;
|
|
@@ -117,7 +147,9 @@ export function renderGitFileDiff(diff: string, currentText: string, highlight?:
|
|
|
117
147
|
const text = row.kind === "deletion" ? before?.[row.oldNumber! - 1] : after?.[row.newNumber! - 1];
|
|
118
148
|
return `<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
149
|
}).join("");
|
|
120
|
-
|
|
150
|
+
const oldNumberWidth = Math.max(2, String(oldLine - 1).length);
|
|
151
|
+
const newNumberWidth = Math.max(2, String(newLine - 1).length);
|
|
152
|
+
return `<pre class="code git-diff" aria-label="Git diff" style="--old-line-number-width:${oldNumberWidth}ch;--new-line-number-width:${newNumberWidth}ch"><code>${content}</code></pre>`;
|
|
121
153
|
}
|
|
122
154
|
|
|
123
155
|
function splitLines(value: string): string[] {
|
|
@@ -130,15 +162,11 @@ function escapeHtml(value: string): string {
|
|
|
130
162
|
|
|
131
163
|
export const GIT_DIFF_PREVIEW_CSS = `
|
|
132
164
|
.git-diff .line { display:flex; width:max-content; min-width:100%; padding-right:16px; }
|
|
133
|
-
.git-diff .diff-number { display:inline-block; flex:
|
|
165
|
+
.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; }
|
|
166
|
+
.git-diff .diff-number:first-child { width:var(--old-line-number-width, 2ch); }
|
|
134
167
|
.git-diff .diff-marker { flex:0 0 2em; width:2em; text-align:center; user-select:none; }
|
|
135
168
|
.git-diff .diff-text { white-space:pre; }
|
|
136
|
-
.git-diff .diff-addition { background
|
|
137
|
-
.git-diff .diff-deletion { background
|
|
138
|
-
@media (max-width:640px) { .git-diff .diff-number {
|
|
139
|
-
@media (prefers-color-scheme:dark) {
|
|
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
|
-
}
|
|
169
|
+
.git-diff .diff-addition { background:var(--git-diff-added-bg, light-dark(#dafbe1, #033a16)); color:var(--git-diff-added-text, light-dark(#116329, #aff5b4)); }
|
|
170
|
+
.git-diff .diff-deletion { background:var(--git-diff-removed-bg, light-dark(#ffebe9, #67060c)); color:var(--git-diff-removed-text, light-dark(#a40e26, #ffdcd7)); }
|
|
171
|
+
@media (max-width:640px) { .git-diff .diff-number { padding:0 4px; } }
|
|
144
172
|
`;
|
|
@@ -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`;
|