@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
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { StringDecoder } from "node:string_decoder";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { cliText } from "./i18n.js";
|
|
7
|
+
import type { SelfUpdateResult } from "./SelfUpdateRunner.js";
|
|
8
|
+
|
|
9
|
+
const scheduledSchema = z.discriminatedUnion("status", [
|
|
10
|
+
z.object({ status: z.literal("current"), currentVersion: z.string(), targetVersion: z.string(), channel: z.string() }),
|
|
11
|
+
z.object({ status: z.enum(["scheduled", "started"]), logPath: z.string(), resultPath: z.string(), planPath: z.string() }),
|
|
12
|
+
]);
|
|
13
|
+
const resultSchema = z.object({
|
|
14
|
+
status: z.enum(["updated", "rolled-back", "failed"]), fromVersion: z.string(), toVersion: z.string(),
|
|
15
|
+
activeVersion: z.string().optional(), initialized: z.boolean().optional(), serviceReady: z.boolean().optional(),
|
|
16
|
+
fallback: z.enum(["npm", "backup"]).optional(), error: z.string().optional(), rollbackError: z.string().optional(), completedAt: z.string(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export async function observeSelfUpdateCommand(
|
|
20
|
+
cliEntry: string,
|
|
21
|
+
args: string[],
|
|
22
|
+
writeProgress: (text: string) => void,
|
|
23
|
+
): Promise<z.infer<typeof scheduledSchema> | (SelfUpdateResult & { logPath: string; resultPath: string })> {
|
|
24
|
+
// The observer must not open SQLite: loaded native modules remain locked on Windows even after close().
|
|
25
|
+
const stdout = await new Promise<string>((resolve, reject) => {
|
|
26
|
+
const child = execFile(process.execPath, [cliEntry, "update", ...args.filter((arg) => arg !== "--json"), "--background", "--json"], {
|
|
27
|
+
windowsHide: true, encoding: "utf8", maxBuffer: 1_000_000,
|
|
28
|
+
}, (error, output, stderr) => error ? reject(new Error(stderr.trim() || error.message)) : resolve(output));
|
|
29
|
+
child.stderr?.on("data", (chunk: string) => writeProgress(chunk));
|
|
30
|
+
});
|
|
31
|
+
const scheduled = scheduledSchema.parse(JSON.parse(stdout));
|
|
32
|
+
if (scheduled.status === "current") return scheduled;
|
|
33
|
+
writeProgress(cliText("Waiting for safe installation and service readiness...\n", "正在等待安全安装与服务就绪……\n"));
|
|
34
|
+
writeProgress(`${cliText("Update log: ", "更新日志:")}${scheduled.logPath}\n`);
|
|
35
|
+
const result = await waitForSelfUpdateResult(scheduled, writeProgress);
|
|
36
|
+
return { ...result, logPath: scheduled.logPath, resultPath: scheduled.resultPath };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function waitForSelfUpdateResult(
|
|
40
|
+
operation: { logPath: string; resultPath: string; planPath: string },
|
|
41
|
+
writeProgress: (text: string) => void,
|
|
42
|
+
): Promise<SelfUpdateResult> {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
let offset = 0;
|
|
45
|
+
let pending = "";
|
|
46
|
+
const decoder = new StringDecoder("utf8");
|
|
47
|
+
let settled = false;
|
|
48
|
+
let lastNotice = Date.now();
|
|
49
|
+
const watcher = fs.watch(path.dirname(operation.resultPath), () => check());
|
|
50
|
+
const timer = setInterval(() => check(), 1_000);
|
|
51
|
+
const finish = (error?: Error, result?: SelfUpdateResult): void => {
|
|
52
|
+
if (settled) return;
|
|
53
|
+
settled = true;
|
|
54
|
+
clearInterval(timer);
|
|
55
|
+
watcher.close();
|
|
56
|
+
if (error) reject(error); else resolve(result!);
|
|
57
|
+
};
|
|
58
|
+
const check = (): void => {
|
|
59
|
+
if (settled) return;
|
|
60
|
+
try {
|
|
61
|
+
if (fs.existsSync(operation.logPath)) {
|
|
62
|
+
const size = fs.statSync(operation.logPath).size;
|
|
63
|
+
if (size > offset) {
|
|
64
|
+
const handle = fs.openSync(operation.logPath, "r");
|
|
65
|
+
const bytes = Buffer.alloc(size - offset);
|
|
66
|
+
let count: number;
|
|
67
|
+
try { count = fs.readSync(handle, bytes, 0, bytes.length, offset); } finally { fs.closeSync(handle); }
|
|
68
|
+
offset += count;
|
|
69
|
+
const lines = (pending + decoder.write(bytes.subarray(0, count))).split("\n");
|
|
70
|
+
pending = lines.pop()!;
|
|
71
|
+
for (const line of lines) {
|
|
72
|
+
const event = JSON.parse(line) as { event?: string; message?: string };
|
|
73
|
+
if (event.event === "update_progress" && event.message) {
|
|
74
|
+
writeProgress(event.message + "\n");
|
|
75
|
+
lastNotice = Date.now();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (fs.existsSync(operation.resultPath)) {
|
|
81
|
+
finish(undefined, resultSchema.parse(JSON.parse(fs.readFileSync(operation.resultPath, "utf8"))));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const plan = JSON.parse(fs.readFileSync(operation.planPath, "utf8")) as { lockPath: string; lockToken: string; pendingMarkerPath: string };
|
|
85
|
+
const lock = fs.existsSync(plan.lockPath) ? JSON.parse(fs.readFileSync(plan.lockPath, "utf8")) as { token?: string } : undefined;
|
|
86
|
+
if (lock?.token !== plan.lockToken) {
|
|
87
|
+
if (fs.existsSync(operation.resultPath)) { check(); return; }
|
|
88
|
+
finish(new Error(cliText("The update was cancelled or its reservation was released without a result.", "更新已取消,或更新锁已释放但没有生成结果。")));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (fs.existsSync(plan.pendingMarkerPath)) {
|
|
92
|
+
const marker = JSON.parse(fs.readFileSync(plan.pendingMarkerPath, "utf8")) as { phase?: string; runnerPid?: number };
|
|
93
|
+
if (marker.phase === "running" && marker.runnerPid) {
|
|
94
|
+
try { process.kill(marker.runnerPid, 0); } catch (error) {
|
|
95
|
+
if ((error as NodeJS.ErrnoException).code !== "EPERM") {
|
|
96
|
+
if (fs.existsSync(operation.resultPath)) { check(); return; }
|
|
97
|
+
finish(new Error(cliText("The update runner exited without a result. See the update log.", "更新进程退出但未生成结果,请查看更新日志。")));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (Date.now() - lastNotice >= 15_000) {
|
|
103
|
+
writeProgress(cliText("Update is still pending or running; waiting for completion...\n", "更新仍在等待或执行中,继续等待完成……\n"));
|
|
104
|
+
lastNotice = Date.now();
|
|
105
|
+
}
|
|
106
|
+
} catch (error) { finish(error instanceof Error ? error : new Error(String(error))); }
|
|
107
|
+
};
|
|
108
|
+
watcher.once("error", finish);
|
|
109
|
+
check();
|
|
110
|
+
});
|
|
111
|
+
}
|