@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.
Files changed (159) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +102 -18
  3. package/README.zh.md +102 -18
  4. package/assets/agent-bot.ico +0 -0
  5. package/assets/roboto-mono-OFL.txt +93 -0
  6. package/assets/roboto-mono-latin.woff2 +0 -0
  7. package/assets/workspace-drafts.js +88 -0
  8. package/assets/workspace-sessions.js +2676 -243
  9. package/assets/workspace.css +553 -44
  10. package/assets/workspace.js +3429 -327
  11. package/dist/cli/SelfUpdateObserver.js +124 -0
  12. package/dist/cli/SelfUpdateObserver.js.map +1 -0
  13. package/dist/cli/SelfUpdateRunner.js +267 -70
  14. package/dist/cli/SelfUpdateRunner.js.map +1 -1
  15. package/dist/cli/SelfUpdater.js +54 -15
  16. package/dist/cli/SelfUpdater.js.map +1 -1
  17. package/dist/cli/controlProtocol.js.map +1 -1
  18. package/dist/cli/help.js +6 -0
  19. package/dist/cli/help.js.map +1 -1
  20. package/dist/cli.js +85 -6
  21. package/dist/cli.js.map +1 -1
  22. package/dist/codex/CodexEventMapper.js +29 -5
  23. package/dist/codex/CodexEventMapper.js.map +1 -1
  24. package/dist/codex/CodexRuntime.js +3 -0
  25. package/dist/codex/CodexRuntime.js.map +1 -1
  26. package/dist/feishu/CardRenderer.js +45 -13
  27. package/dist/feishu/CardRenderer.js.map +1 -1
  28. package/dist/feishu/ConsoleFeishuClient.js +4 -0
  29. package/dist/feishu/ConsoleFeishuClient.js.map +1 -1
  30. package/dist/feishu/FeishuMarkdown.js +2 -14
  31. package/dist/feishu/FeishuMarkdown.js.map +1 -1
  32. package/dist/feishu/FeishuMessageClient.js +9 -0
  33. package/dist/feishu/FeishuMessageClient.js.map +1 -1
  34. package/dist/feishu/FeishuTurnPresenter.js +51 -22
  35. package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
  36. package/dist/index.js +47 -12
  37. package/dist/index.js.map +1 -1
  38. package/dist/local-files/DiagramPreview.js +11 -6
  39. package/dist/local-files/DiagramPreview.js.map +1 -1
  40. package/dist/local-files/GitDiffPreview.js +106 -14
  41. package/dist/local-files/GitDiffPreview.js.map +1 -1
  42. package/dist/local-files/LiveMarkup.js +104 -0
  43. package/dist/local-files/LiveMarkup.js.map +1 -0
  44. package/dist/local-files/LocalFileViewerServer.js +141 -122
  45. package/dist/local-files/LocalFileViewerServer.js.map +1 -1
  46. package/dist/local-files/MarkdownExport.js +54 -0
  47. package/dist/local-files/MarkdownExport.js.map +1 -0
  48. package/dist/local-files/PreviewCodeFont.js +11 -0
  49. package/dist/local-files/PreviewCodeFont.js.map +1 -0
  50. package/dist/local-files/PreviewSyntaxHighlight.js +73 -0
  51. package/dist/local-files/PreviewSyntaxHighlight.js.map +1 -1
  52. package/dist/local-files/ToolCommandDisplay.js +111 -0
  53. package/dist/local-files/ToolCommandDisplay.js.map +1 -0
  54. package/dist/local-files/TurnPreviewPage.js +53 -276
  55. package/dist/local-files/TurnPreviewPage.js.map +1 -1
  56. package/dist/local-files/WorkspaceFileEvents.js +206 -0
  57. package/dist/local-files/WorkspaceFileEvents.js.map +1 -0
  58. package/dist/local-files/WorkspaceFiles.js +79 -3
  59. package/dist/local-files/WorkspaceFiles.js.map +1 -1
  60. package/dist/local-files/WorkspaceImages.js +43 -0
  61. package/dist/local-files/WorkspaceImages.js.map +1 -0
  62. package/dist/local-files/WorkspacePage.js +24 -6
  63. package/dist/local-files/WorkspacePage.js.map +1 -1
  64. package/dist/local-files/WorkspaceSessions.js +1153 -104
  65. package/dist/local-files/WorkspaceSessions.js.map +1 -1
  66. package/dist/local-files/WorkspaceTimeline.js +129 -0
  67. package/dist/local-files/WorkspaceTimeline.js.map +1 -0
  68. package/dist/presentation/OutboundRouter.js +15 -6
  69. package/dist/presentation/OutboundRouter.js.map +1 -1
  70. package/dist/presentation/TurnStateReducer.js +31 -22
  71. package/dist/presentation/TurnStateReducer.js.map +1 -1
  72. package/dist/proxy/ProxySessionController.js +335 -113
  73. package/dist/proxy/ProxySessionController.js.map +1 -1
  74. package/dist/proxy/TaskMetadata.js +86 -0
  75. package/dist/proxy/TaskMetadata.js.map +1 -0
  76. package/dist/scheduling/ScheduleCards.js +10 -4
  77. package/dist/scheduling/ScheduleCards.js.map +1 -1
  78. package/dist/scheduling/ScheduleCommand.js +4 -0
  79. package/dist/scheduling/ScheduleCommand.js.map +1 -1
  80. package/dist/scheduling/ScheduledTaskStore.js +53 -12
  81. package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
  82. package/dist/scheduling/types.js +19 -4
  83. package/dist/scheduling/types.js.map +1 -1
  84. package/dist/state/StateStore.js +213 -23
  85. package/dist/state/StateStore.js.map +1 -1
  86. package/dist/state/TurnPreviewJournal.js +157 -39
  87. package/dist/state/TurnPreviewJournal.js.map +1 -1
  88. package/dist/state/TurnToolText.js +172 -0
  89. package/dist/state/TurnToolText.js.map +1 -0
  90. package/dist/state/migrations.js +4 -0
  91. package/dist/state/migrations.js.map +1 -1
  92. package/dist/supervision/SafeRestartNotifier.js +9 -6
  93. package/dist/supervision/SafeRestartNotifier.js.map +1 -1
  94. package/dist/terminal/TerminalPage.js +5 -0
  95. package/dist/terminal/TerminalPage.js.map +1 -1
  96. package/dist/updates/AutomaticUpdatePreparer.js +63 -12
  97. package/dist/updates/AutomaticUpdatePreparer.js.map +1 -1
  98. package/dist/updates/ManualUpdateController.js +7 -2
  99. package/dist/updates/ManualUpdateController.js.map +1 -1
  100. package/dist/utils/promptAttachments.js +22 -0
  101. package/dist/utils/promptAttachments.js.map +1 -0
  102. package/dist/utils/promptQuotes.js +47 -0
  103. package/dist/utils/promptQuotes.js.map +1 -0
  104. package/dist/utils/toolTimestamp.js +6 -0
  105. package/dist/utils/toolTimestamp.js.map +1 -0
  106. package/npm-shrinkwrap.json +2 -2
  107. package/package.json +1 -1
  108. package/skills/agent-bot/SKILL.md +23 -2
  109. package/src/cli/SelfUpdateObserver.ts +111 -0
  110. package/src/cli/SelfUpdateRunner.ts +271 -85
  111. package/src/cli/SelfUpdater.ts +53 -16
  112. package/src/cli/controlProtocol.ts +1 -0
  113. package/src/cli/help.ts +6 -0
  114. package/src/cli.ts +71 -5
  115. package/src/codex/CodexEventMapper.ts +25 -5
  116. package/src/codex/CodexRuntime.ts +4 -0
  117. package/src/feishu/CardRenderer.ts +48 -13
  118. package/src/feishu/ConsoleFeishuClient.ts +6 -1
  119. package/src/feishu/FeishuMarkdown.ts +2 -14
  120. package/src/feishu/FeishuMessageClient.ts +10 -0
  121. package/src/feishu/FeishuTurnPresenter.ts +49 -16
  122. package/src/feishu/types.ts +1 -0
  123. package/src/index.ts +47 -12
  124. package/src/local-files/DiagramPreview.ts +11 -6
  125. package/src/local-files/GitDiffPreview.ts +107 -15
  126. package/src/local-files/LiveMarkup.ts +103 -0
  127. package/src/local-files/LocalFileViewerServer.ts +128 -125
  128. package/src/local-files/MarkdownExport.ts +54 -0
  129. package/src/local-files/PreviewCodeFont.ts +12 -0
  130. package/src/local-files/PreviewSyntaxHighlight.ts +75 -0
  131. package/src/local-files/ToolCommandDisplay.ts +104 -0
  132. package/src/local-files/TurnPreviewPage.ts +58 -261
  133. package/src/local-files/WorkspaceFileEvents.ts +186 -0
  134. package/src/local-files/WorkspaceFiles.ts +72 -5
  135. package/src/local-files/WorkspaceImages.ts +35 -0
  136. package/src/local-files/WorkspacePage.ts +24 -6
  137. package/src/local-files/WorkspaceSessions.ts +1057 -111
  138. package/src/local-files/WorkspaceTimeline.ts +135 -0
  139. package/src/presentation/OutboundRouter.ts +18 -4
  140. package/src/presentation/TurnStateReducer.ts +30 -19
  141. package/src/presentation/turnViewTypes.ts +3 -1
  142. package/src/proxy/ProxySessionController.ts +336 -96
  143. package/src/proxy/TaskMetadata.ts +81 -0
  144. package/src/runtime/types.ts +2 -1
  145. package/src/scheduling/ScheduleCards.ts +10 -4
  146. package/src/scheduling/ScheduleCommand.ts +4 -0
  147. package/src/scheduling/ScheduledTaskStore.ts +56 -9
  148. package/src/scheduling/types.ts +27 -4
  149. package/src/state/StateStore.ts +227 -24
  150. package/src/state/TurnPreviewJournal.ts +155 -38
  151. package/src/state/TurnToolText.ts +156 -0
  152. package/src/state/migrations.ts +4 -0
  153. package/src/supervision/SafeRestartNotifier.ts +9 -6
  154. package/src/terminal/TerminalPage.ts +5 -0
  155. package/src/updates/AutomaticUpdatePreparer.ts +52 -11
  156. package/src/updates/ManualUpdateController.ts +8 -3
  157. package/src/utils/promptAttachments.ts +27 -0
  158. package/src/utils/promptQuotes.ts +48 -0
  159. 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
+ }