@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
package/src/cli/SelfUpdater.ts
CHANGED
|
@@ -8,19 +8,24 @@ import { cliText } from "./i18n.js";
|
|
|
8
8
|
import { readPackageVersion } from "./packageVersion.js";
|
|
9
9
|
import {
|
|
10
10
|
runNpmCommand,
|
|
11
|
+
sanitizeUpdateDiagnostic,
|
|
11
12
|
SELF_UPDATE_PLAN_VERSION,
|
|
12
13
|
validateInstalledPackage,
|
|
14
|
+
writeSelfUpdateJson,
|
|
13
15
|
type SelfUpdatePlan,
|
|
14
16
|
} from "./SelfUpdateRunner.js";
|
|
15
17
|
|
|
16
18
|
export const AGENT_BOT_PACKAGE_NAME = "@keyou007/agent-bot";
|
|
17
19
|
|
|
20
|
+
export class SelfUpdatePreparationError extends Error {}
|
|
21
|
+
|
|
18
22
|
export type SelfUpdateChannel = "alpha" | "latest";
|
|
19
23
|
|
|
20
24
|
export interface SelfUpdateOptions {
|
|
21
25
|
channel?: SelfUpdateChannel;
|
|
22
26
|
version?: string;
|
|
23
27
|
allowDowngrade?: boolean;
|
|
28
|
+
onProgress?(message: string): void;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
export interface PendingSelfUpdate {
|
|
@@ -69,12 +74,17 @@ export interface SelfUpdaterDependencies {
|
|
|
69
74
|
|
|
70
75
|
export function parseSelfUpdateOptions(input: string[]): SelfUpdateOptions & {
|
|
71
76
|
json: boolean;
|
|
77
|
+
background?: boolean;
|
|
72
78
|
taskReference?: string;
|
|
73
79
|
} {
|
|
74
|
-
const options: SelfUpdateOptions & { json: boolean; taskReference?: string } =
|
|
80
|
+
const options: SelfUpdateOptions & { json: boolean; background?: boolean; taskReference?: string } =
|
|
75
81
|
{ json: false };
|
|
76
82
|
for (let index = 0; index < input.length; index += 1) {
|
|
77
83
|
const value = input[index]!;
|
|
84
|
+
if (value === "--background") {
|
|
85
|
+
options.background = true;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
78
88
|
if (value === "--json") {
|
|
79
89
|
options.json = true;
|
|
80
90
|
continue;
|
|
@@ -127,6 +137,7 @@ export async function prepareSelfUpdate(
|
|
|
127
137
|
options: SelfUpdateOptions = {},
|
|
128
138
|
dependencies: SelfUpdaterDependencies = defaultDependencies(),
|
|
129
139
|
): Promise<PrepareSelfUpdateResult> {
|
|
140
|
+
options.onProgress?.(cliText("Checking the npm installation...", "正在检查 npm 安装方式……"));
|
|
130
141
|
const currentVersion = readVersionFromRoot(dependencies.packageRoot);
|
|
131
142
|
const installation = requireNpmSelfUpdateInstallation(
|
|
132
143
|
dependencies.packageRoot,
|
|
@@ -134,6 +145,7 @@ export async function prepareSelfUpdate(
|
|
|
134
145
|
);
|
|
135
146
|
|
|
136
147
|
const channel = options.channel ?? defaultUpdateChannel(currentVersion);
|
|
148
|
+
options.onProgress?.(cliText("Resolving the target version...", "正在查询目标版本……"));
|
|
137
149
|
const targetVersion = options.version
|
|
138
150
|
? normalizeVersion(options.version)
|
|
139
151
|
: resolvePublishedVersion(
|
|
@@ -174,12 +186,14 @@ export async function prepareSelfUpdate(
|
|
|
174
186
|
fs.mkdirSync(candidateInstallRoot, { recursive: true });
|
|
175
187
|
fs.mkdirSync(path.dirname(backupPackageRoot), { recursive: true });
|
|
176
188
|
|
|
189
|
+
options.onProgress?.(cliText(`Downloading Agent Bot ${targetVersion}...`, `正在下载 Agent Bot ${targetVersion}……`));
|
|
177
190
|
const candidateTarball = packPackage(
|
|
178
191
|
`${AGENT_BOT_PACKAGE_NAME}@${targetVersion}`,
|
|
179
192
|
downloadRoot,
|
|
180
193
|
dependencies.packageRoot,
|
|
181
194
|
dependencies.runNpm,
|
|
182
195
|
);
|
|
196
|
+
options.onProgress?.(cliText("Installing candidate dependencies for validation...", "正在安装候选版本依赖以进行预检……"));
|
|
183
197
|
runRequiredNpm(
|
|
184
198
|
[
|
|
185
199
|
"install",
|
|
@@ -199,12 +213,14 @@ export async function prepareSelfUpdate(
|
|
|
199
213
|
"node_modules",
|
|
200
214
|
...AGENT_BOT_PACKAGE_NAME.split("/"),
|
|
201
215
|
);
|
|
216
|
+
options.onProgress?.(cliText("Validating the candidate CLI...", "正在校验候选版本 CLI……"));
|
|
202
217
|
dependencies.validatePackage(
|
|
203
218
|
candidatePackageRoot,
|
|
204
219
|
AGENT_BOT_PACKAGE_NAME,
|
|
205
220
|
targetVersion,
|
|
206
221
|
);
|
|
207
222
|
|
|
223
|
+
options.onProgress?.(cliText("Backing up the installed package...", "正在备份已安装的版本……"));
|
|
208
224
|
fs.cpSync(dependencies.packageRoot, backupPackageRoot, {
|
|
209
225
|
recursive: true,
|
|
210
226
|
dereference: false,
|
|
@@ -215,6 +231,7 @@ export async function prepareSelfUpdate(
|
|
|
215
231
|
AGENT_BOT_PACKAGE_NAME,
|
|
216
232
|
currentVersion,
|
|
217
233
|
);
|
|
234
|
+
options.onProgress?.(cliText("Packing the rollback archive...", "正在生成回滚包……"));
|
|
218
235
|
const backupTarball = packPackage(
|
|
219
236
|
dependencies.packageRoot,
|
|
220
237
|
downloadRoot,
|
|
@@ -244,10 +261,11 @@ export async function prepareSelfUpdate(
|
|
|
244
261
|
controlEndpoint: "pending",
|
|
245
262
|
workingDirectory: process.cwd(),
|
|
246
263
|
restartService: false,
|
|
264
|
+
preparationPid: process.pid,
|
|
247
265
|
resultPath,
|
|
248
266
|
logPath,
|
|
249
267
|
};
|
|
250
|
-
|
|
268
|
+
writeSelfUpdateJson(planPath, plan);
|
|
251
269
|
fs.writeFileSync(
|
|
252
270
|
pendingMarkerPath,
|
|
253
271
|
`${JSON.stringify(
|
|
@@ -281,7 +299,7 @@ export async function prepareSelfUpdate(
|
|
|
281
299
|
} catch (error) {
|
|
282
300
|
releaseSelfUpdateLock(lockPath, lockToken);
|
|
283
301
|
releasePendingMarker(pendingMarkerPath, lockToken);
|
|
284
|
-
throw error;
|
|
302
|
+
throw new SelfUpdatePreparationError(sanitizeUpdateDiagnostic(error instanceof Error ? error.message : String(error)), { cause: error });
|
|
285
303
|
}
|
|
286
304
|
}
|
|
287
305
|
|
|
@@ -317,6 +335,8 @@ export function finalizeSelfUpdatePlan(
|
|
|
317
335
|
reason?: string;
|
|
318
336
|
notificationSessionId?: string;
|
|
319
337
|
notificationTarget?: SelfUpdatePlan["notificationTarget"];
|
|
338
|
+
notificationMessageId?: string;
|
|
339
|
+
recoveryAttemptIds?: string[];
|
|
320
340
|
},
|
|
321
341
|
): void {
|
|
322
342
|
const plan = readSelfUpdatePlan(planPath);
|
|
@@ -326,9 +346,11 @@ export function finalizeSelfUpdatePlan(
|
|
|
326
346
|
if (values.workingDirectory) plan.workingDirectory = values.workingDirectory;
|
|
327
347
|
if (values.reason) plan.reason = values.reason;
|
|
328
348
|
if (values.notificationTarget) plan.notificationTarget = values.notificationTarget;
|
|
349
|
+
if (values.notificationMessageId) plan.notificationMessageId = values.notificationMessageId;
|
|
350
|
+
if (values.recoveryAttemptIds) plan.recoveryAttemptIds = values.recoveryAttemptIds;
|
|
329
351
|
if (values.notificationSessionId)
|
|
330
352
|
plan.notificationSessionId = values.notificationSessionId;
|
|
331
|
-
|
|
353
|
+
writeSelfUpdateJson(planPath, plan);
|
|
332
354
|
}
|
|
333
355
|
|
|
334
356
|
export function readSelfUpdatePlan(planPath: string): SelfUpdatePlan {
|
|
@@ -405,7 +427,7 @@ export function assertSelfUpdatePlanPath(
|
|
|
405
427
|
export function launchSelfUpdateRunner(
|
|
406
428
|
planPath: string,
|
|
407
429
|
options: { waitPids?: number[]; environment?: NodeJS.ProcessEnv } = {},
|
|
408
|
-
): number
|
|
430
|
+
): Promise<number> {
|
|
409
431
|
const runnerPath = path.join(path.dirname(planPath), "update-runner.mjs");
|
|
410
432
|
const waitArguments = (options.waitPids ?? []).flatMap((pid) => [
|
|
411
433
|
"--wait-pid",
|
|
@@ -418,12 +440,27 @@ export function launchSelfUpdateRunner(
|
|
|
418
440
|
cwd: path.dirname(planPath),
|
|
419
441
|
detached: true,
|
|
420
442
|
windowsHide: true,
|
|
421
|
-
stdio: "ignore",
|
|
443
|
+
stdio: ["ignore", "ignore", "ignore", "ipc"],
|
|
422
444
|
env: options.environment ?? process.env,
|
|
423
445
|
},
|
|
424
446
|
);
|
|
425
|
-
|
|
426
|
-
|
|
447
|
+
return new Promise((resolve, reject) => {
|
|
448
|
+
const timeout = setTimeout(() => finish(new Error("Update runner did not acknowledge startup within 5 seconds.")), 5_000);
|
|
449
|
+
const finish = (error?: Error): void => {
|
|
450
|
+
clearTimeout(timeout);
|
|
451
|
+
child.removeAllListeners("exit");
|
|
452
|
+
child.removeAllListeners("message");
|
|
453
|
+
if (child.connected) child.disconnect();
|
|
454
|
+
child.unref();
|
|
455
|
+
if (error) reject(error); else resolve(child.pid!);
|
|
456
|
+
};
|
|
457
|
+
child.once("error", finish);
|
|
458
|
+
child.once("exit", (code, signal) => finish(new Error(`Update runner exited before startup (code ${code}, signal ${signal}).`)));
|
|
459
|
+
child.once("message", (message) => {
|
|
460
|
+
if (typeof message === "object" && message !== null && "status" in message && message.status === "ready") finish();
|
|
461
|
+
else finish(new Error("Update runner returned an invalid startup acknowledgement."));
|
|
462
|
+
});
|
|
463
|
+
});
|
|
427
464
|
}
|
|
428
465
|
|
|
429
466
|
export function inspectNpmInstallation(
|
|
@@ -432,9 +469,9 @@ export function inspectNpmInstallation(
|
|
|
432
469
|
): { kind: "global" | "linked" | "source"; packageRoot: string } {
|
|
433
470
|
const result = runNpm(["root", "--global"], packageRoot);
|
|
434
471
|
if (result.error || result.status !== 0)
|
|
435
|
-
|
|
472
|
+
throw new Error(sanitizeUpdateDiagnostic(`Could not inspect the npm global installation: ${result.error?.message || result.stderr.trim() || result.stdout.trim() || `npm exited with ${result.status}.`}`));
|
|
436
473
|
const globalRoot = lastMatchingLine(result.stdout, () => true);
|
|
437
|
-
if (!globalRoot) return
|
|
474
|
+
if (!globalRoot) throw new Error("npm root --global did not return an installation directory.");
|
|
438
475
|
const expected = path.join(globalRoot, ...AGENT_BOT_PACKAGE_NAME.split("/"));
|
|
439
476
|
if (!fs.existsSync(expected)) return { kind: "source", packageRoot };
|
|
440
477
|
const linked = fs.lstatSync(expected).isSymbolicLink();
|
|
@@ -487,10 +524,10 @@ function resolvePublishedVersion(
|
|
|
487
524
|
["view", `${AGENT_BOT_PACKAGE_NAME}@${channel}`, "version", "--json"],
|
|
488
525
|
cwd,
|
|
489
526
|
);
|
|
490
|
-
if (result.error) throw result.error;
|
|
527
|
+
if (result.error) throw new Error(sanitizeUpdateDiagnostic(result.error.message));
|
|
491
528
|
if (result.status !== 0)
|
|
492
529
|
throw new Error(
|
|
493
|
-
result.stderr.trim() || `npm view exited with ${result.status}
|
|
530
|
+
sanitizeUpdateDiagnostic(result.stderr.trim() || `npm view exited with ${result.status}.`),
|
|
494
531
|
);
|
|
495
532
|
let value: unknown;
|
|
496
533
|
try {
|
|
@@ -535,12 +572,12 @@ function runRequiredNpm(
|
|
|
535
572
|
runNpm: (args: string[], cwd: string) => CommandResult,
|
|
536
573
|
): CommandResult {
|
|
537
574
|
const result = runNpm(args, cwd);
|
|
538
|
-
if (result.error) throw result.error;
|
|
575
|
+
if (result.error) throw new Error(sanitizeUpdateDiagnostic(result.error.message));
|
|
539
576
|
if (result.status !== 0) {
|
|
540
577
|
throw new Error(
|
|
541
|
-
result.stderr.trim() ||
|
|
578
|
+
sanitizeUpdateDiagnostic(result.stderr.trim() ||
|
|
542
579
|
result.stdout.trim() ||
|
|
543
|
-
`npm exited with ${result.status}
|
|
580
|
+
`npm exited with ${result.status}.`),
|
|
544
581
|
);
|
|
545
582
|
}
|
|
546
583
|
return result;
|
|
@@ -625,7 +662,7 @@ function writeUpdateLock(
|
|
|
625
662
|
lockPath: string,
|
|
626
663
|
value: Record<string, unknown>,
|
|
627
664
|
): void {
|
|
628
|
-
|
|
665
|
+
writeSelfUpdateJson(lockPath, value);
|
|
629
666
|
}
|
|
630
667
|
|
|
631
668
|
function releaseSelfUpdateLock(lockPath: string, token: string): void {
|
|
@@ -70,6 +70,7 @@ export type ControlRequest =
|
|
|
70
70
|
| { action: "task_mute"; localSessionId: string; enabled?: boolean }
|
|
71
71
|
| { action: "task_shell"; localSessionId: string; command: string }
|
|
72
72
|
| { action: "task_directory"; localSessionId: string; directory?: string; page?: number }
|
|
73
|
+
| { action: "task_metadata"; localSessionId: string; command: import("../proxy/TaskMetadata.js").TaskMetadataCommand }
|
|
73
74
|
| { action: "task_send_file"; localSessionId: string; filePath: string }
|
|
74
75
|
| {
|
|
75
76
|
action: "task_new_group";
|
package/src/cli/help.ts
CHANGED
|
@@ -49,6 +49,8 @@ export function renderCliHelp(version: string, language: CliLanguage = cliLangua
|
|
|
49
49
|
task reset [任务] <Turn ID> 将对话上下文 Reset 到指定 Turn
|
|
50
50
|
task mute [任务] [on|off] 设置群聊仅 @ 响应模式;不传值等同于 on
|
|
51
51
|
task dir [任务] [目录] 浏览任务目录;支持 --page、--json
|
|
52
|
+
task metadata [任务] directory add <路径> [--user-directory] | list | remove <ID>
|
|
53
|
+
管理工作台新标签页中的任务目录;支持 --task、--json
|
|
52
54
|
task file [任务] <路径> 将文件发送到任务绑定的飞书会话
|
|
53
55
|
task shell [任务] <命令> 在任务目录执行本地命令
|
|
54
56
|
task stop [任务] 停止任务
|
|
@@ -79,6 +81,7 @@ export function renderCliHelp(version: string, language: CliLanguage = cliLangua
|
|
|
79
81
|
--version <版本> 更新到指定版本
|
|
80
82
|
--task <任务> 将更新和重启状态发回任务所在会话
|
|
81
83
|
--allow-downgrade 明确允许安装较旧版本
|
|
84
|
+
--background 仅安排更新后返回;默认等待最终结果
|
|
82
85
|
|
|
83
86
|
重启选项:
|
|
84
87
|
--task <任务> 覆盖自动识别的来源任务或默认私聊
|
|
@@ -151,6 +154,8 @@ Task commands:
|
|
|
151
154
|
task reset [task] <Turn ID> Reset conversation context to a Turn
|
|
152
155
|
task mute [task] [on|off] Set group mention-only mode; omitted means on
|
|
153
156
|
task dir [task] [directory] Browse task files; supports --page and --json
|
|
157
|
+
task metadata [task] directory add <path> [--user-directory] | list | remove <id>
|
|
158
|
+
Manage directories in Workspace new tabs; supports --task and --json
|
|
154
159
|
task file [task] <path> Send a file to the task's Lark conversation
|
|
155
160
|
task shell [task] <command> Run a local command in the task directory
|
|
156
161
|
task stop [task] Stop a task
|
|
@@ -181,6 +186,7 @@ Update options:
|
|
|
181
186
|
--version <version> Update to an exact version
|
|
182
187
|
--task <task> Return update and restart status to the task's conversation
|
|
183
188
|
--allow-downgrade Explicitly allow an older version
|
|
189
|
+
--background Return after scheduling instead of waiting for the final result
|
|
184
190
|
|
|
185
191
|
Restart options:
|
|
186
192
|
--task <task> Override the inferred source task or default private chat
|
package/src/cli.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import { observeSelfUpdateCommand } from "./cli/SelfUpdateObserver.js";
|
|
3
4
|
import { spawnSync } from "node:child_process";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { stripVTControlCharacters } from "node:util";
|
|
5
7
|
import { loadConfig, loadConfigWithoutEnvironmentMutation } from "./config/loadConfig.js";
|
|
6
8
|
import { sendControlRequest, isServerReachable } from "./cli/LocalControlClient.js";
|
|
7
9
|
import {
|
|
@@ -61,6 +63,7 @@ import {
|
|
|
61
63
|
} from "./cli/FeishuConfigurationFeatures.js";
|
|
62
64
|
import { renderCliHelp } from "./cli/help.js";
|
|
63
65
|
import { cliLanguage, cliText, localizeCliErrorMessage } from "./cli/i18n.js";
|
|
66
|
+
import type { listTaskDirectories, TaskMetadataCommand } from "./proxy/TaskMetadata.js";
|
|
64
67
|
import {
|
|
65
68
|
inspectSupportedAgent,
|
|
66
69
|
inspectSupportedAgents,
|
|
@@ -128,6 +131,7 @@ import {
|
|
|
128
131
|
parseSelfUpdateOptions,
|
|
129
132
|
prepareSelfUpdate,
|
|
130
133
|
releaseSelfUpdatePlan,
|
|
134
|
+
SelfUpdatePreparationError,
|
|
131
135
|
requireNpmSelfUpdateInstallation,
|
|
132
136
|
} from "./cli/SelfUpdater.js";
|
|
133
137
|
import { createCurrentAutostartManager } from "./cli/AutostartManager.js";
|
|
@@ -198,6 +202,20 @@ async function main(input: string[]): Promise<void> {
|
|
|
198
202
|
|
|
199
203
|
async function updateCommand(input: string[]): Promise<void> {
|
|
200
204
|
const options = parseSelfUpdateOptions(input);
|
|
205
|
+
if (!options.background && process.env.AGENT_BOT !== "1") {
|
|
206
|
+
const result = await observeSelfUpdateCommand(fileURLToPath(import.meta.url), input, (text) => process.stderr.write(text));
|
|
207
|
+
if (options.json) printJson(result);
|
|
208
|
+
else if (result.status === "current") process.stdout.write(cliText(`Agent Bot ${result.currentVersion} is already current.\n`, `Agent Bot ${result.currentVersion} 已是当前版本。\n`));
|
|
209
|
+
else if (result.status === "updated") process.stdout.write(cliText(`Agent Bot updated to ${result.activeVersion}.\n`, `Agent Bot 已更新到 ${result.activeVersion}。\n`));
|
|
210
|
+
else if (result.status === "failed" || result.status === "rolled-back") {
|
|
211
|
+
process.stderr.write(result.status === "rolled-back"
|
|
212
|
+
? cliText(`Update failed; restored Agent Bot ${result.activeVersion}.\n`, `更新失败,已恢复 Agent Bot ${result.activeVersion}。\n`)
|
|
213
|
+
: cliText("Update failed; automatic recovery did not succeed.\n", "更新失败,自动恢复未成功。\n"));
|
|
214
|
+
process.stderr.write([result.error, result.rollbackError].filter(Boolean).join("\n") + "\n");
|
|
215
|
+
}
|
|
216
|
+
if (result.status === "failed" || result.status === "rolled-back") process.exitCode = 1;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
201
219
|
requireNpmSelfUpdateInstallation();
|
|
202
220
|
const config = loadConfig();
|
|
203
221
|
const endpoint = controlEndpoint(config.storage.sqlitePath);
|
|
@@ -210,6 +228,22 @@ async function updateCommand(input: string[]): Promise<void> {
|
|
|
210
228
|
channel: options.channel,
|
|
211
229
|
version: options.version,
|
|
212
230
|
allowDowngrade: options.allowDowngrade,
|
|
231
|
+
onProgress: (message) => process.stderr.write(message + "\n"),
|
|
232
|
+
}).catch(async (error: unknown) => {
|
|
233
|
+
if (!(error instanceof SelfUpdatePreparationError)) throw error;
|
|
234
|
+
try {
|
|
235
|
+
if (serverRunning) {
|
|
236
|
+
const notificationSessionId = resolveRestartNotificationSessionId(config.storage.sqlitePath, options.taskReference ? ["--task", options.taskReference] : []);
|
|
237
|
+
ensureOk(await sendControlRequest(endpoint, { action: "server_restart", mode: "safe", reason: "更新准备失败,重启当前版本", notificationSessionId }));
|
|
238
|
+
process.stderr.write(cliText("Preparation failed; a safe restart of the current version is scheduled.\n", "更新准备失败,已安排当前版本安全重启。\n"));
|
|
239
|
+
} else {
|
|
240
|
+
await startServer(config);
|
|
241
|
+
process.stderr.write(cliText("Preparation failed; the current Agent Bot service has been started.\n", "更新准备失败,已启动当前 Agent Bot 服务。\n"));
|
|
242
|
+
}
|
|
243
|
+
} catch (restartError) {
|
|
244
|
+
throw new Error(`${error.message}\nCould not restart the current service: ${restartError instanceof Error ? restartError.message : String(restartError)}`, { cause: error });
|
|
245
|
+
}
|
|
246
|
+
throw error;
|
|
213
247
|
});
|
|
214
248
|
if (prepared.status === "current") {
|
|
215
249
|
if (options.json) printJson(prepared);
|
|
@@ -234,7 +268,7 @@ async function updateCommand(input: string[]): Promise<void> {
|
|
|
234
268
|
finalizeSelfUpdatePlan(prepared.planPath, {
|
|
235
269
|
controlEndpoint: endpoint,
|
|
236
270
|
databasePath: config.storage.sqlitePath,
|
|
237
|
-
restartService:
|
|
271
|
+
restartService: true,
|
|
238
272
|
workingDirectory: process.cwd(),
|
|
239
273
|
reason,
|
|
240
274
|
notificationSessionId,
|
|
@@ -247,7 +281,7 @@ async function updateCommand(input: string[]): Promise<void> {
|
|
|
247
281
|
notificationSessionId,
|
|
248
282
|
}, 15_000));
|
|
249
283
|
} else {
|
|
250
|
-
launchSelfUpdateRunner(prepared.planPath, { waitPids: [process.pid] });
|
|
284
|
+
await launchSelfUpdateRunner(prepared.planPath, { waitPids: [process.pid] });
|
|
251
285
|
}
|
|
252
286
|
} catch (error) {
|
|
253
287
|
releaseSelfUpdatePlan(prepared.planPath);
|
|
@@ -262,6 +296,7 @@ async function updateCommand(input: string[]): Promise<void> {
|
|
|
262
296
|
serviceWasRunning: serverRunning,
|
|
263
297
|
logPath: prepared.logPath,
|
|
264
298
|
resultPath: prepared.resultPath,
|
|
299
|
+
planPath: prepared.planPath,
|
|
265
300
|
};
|
|
266
301
|
if (options.json) printJson(result);
|
|
267
302
|
else {
|
|
@@ -274,6 +309,7 @@ async function updateCommand(input: string[]): Promise<void> {
|
|
|
274
309
|
`Agent Bot ${prepared.targetVersion} is verified. Installation will continue after this command exits.\n`,
|
|
275
310
|
`Agent Bot ${prepared.targetVersion} 已通过预检。本命令退出后将继续安装。\n`,
|
|
276
311
|
));
|
|
312
|
+
if (process.env.AGENT_BOT === "1") process.stdout.write(cliText("Agent-hosted updates return after scheduling so the current task can finish safely.\n", "Agent 内调用只等待更新安排完成,避免当前任务等待自身结束造成死锁。\n"));
|
|
277
313
|
process.stdout.write(`${cliText("Update log: ", "更新日志:")}${prepared.logPath}\n`);
|
|
278
314
|
}
|
|
279
315
|
}
|
|
@@ -1589,6 +1625,26 @@ async function taskCommand(input: string[]): Promise<void> {
|
|
|
1589
1625
|
if (result.exitCode && result.exitCode !== 0) process.exitCode = result.exitCode;
|
|
1590
1626
|
return;
|
|
1591
1627
|
}
|
|
1628
|
+
if (action === "metadata") {
|
|
1629
|
+
const target = resolveTaskCommandTarget(allSessions, rest, action, { preferCurrent: true });
|
|
1630
|
+
const json = target.args.includes("--json");
|
|
1631
|
+
const userDirectory = target.args.includes("--user-directory");
|
|
1632
|
+
const [kind, operation, value, ...extra] = target.args.filter((arg) => arg !== "--json" && arg !== "--user-directory");
|
|
1633
|
+
let command: TaskMetadataCommand;
|
|
1634
|
+
if (kind === "directory" && !extra.length && !value?.startsWith("--") && (operation === "add" || !userDirectory)) {
|
|
1635
|
+
if (operation === "add" && value) command = { kind, operation, directory: value, userDirectory };
|
|
1636
|
+
else if (operation === "remove" && value) command = { kind, operation, key: value };
|
|
1637
|
+
else if (operation === "list" && value === undefined) command = { kind, operation };
|
|
1638
|
+
else throw new Error("Usage: task metadata directory add <path> [--user-directory] | list | remove <id>");
|
|
1639
|
+
} else throw new Error("Usage: task metadata directory add <path> [--user-directory] | list | remove <id>");
|
|
1640
|
+
const result = controlData<{ directories: ReturnType<typeof listTaskDirectories> }>(await sendControlRequest(
|
|
1641
|
+
controlEndpoint(config.storage.sqlitePath), { action: "task_metadata", localSessionId: target.session.localSessionId, command },
|
|
1642
|
+
));
|
|
1643
|
+
if (json) printJson(result);
|
|
1644
|
+
else if (!result.directories.length) process.stdout.write(cliText("No task directories recorded.\n", "任务尚未登记目录。\n"));
|
|
1645
|
+
else for (const directory of result.directories) process.stdout.write(`${directory.id} ${directory.path}\n`);
|
|
1646
|
+
return;
|
|
1647
|
+
}
|
|
1592
1648
|
if (action === "dir") {
|
|
1593
1649
|
const target = resolveTaskCommandTarget(allSessions, rest, action);
|
|
1594
1650
|
const parsedDirectory = parseTaskDirectoryArgs([target.session.localSessionId, ...target.args]);
|
|
@@ -1956,9 +2012,14 @@ async function outputTaskStatus(
|
|
|
1956
2012
|
const statusSession = live?.session ?? session;
|
|
1957
2013
|
const snapshot = live?.snapshot
|
|
1958
2014
|
?? (statusSession.lastTurnId ? store.getTurnSnapshot(statusSession.lastTurnId) : undefined);
|
|
1959
|
-
const
|
|
2015
|
+
const queuedPrompts = store.listQueuedPrompts(session.localSessionId).map(prompt => ({
|
|
2016
|
+
id: prompt.promptId,
|
|
2017
|
+
text: stripVTControlCharacters(prompt.displayPrompt ?? prompt.text).replace(/\s+/gu, " ").trim().slice(0, 180),
|
|
2018
|
+
}));
|
|
2019
|
+
const result = { ...statusSession, snapshot, queued: queuedPrompts.length, queuedPrompts,
|
|
2020
|
+
...(live?.remote ? { remote: live.remote } : {}) };
|
|
1960
2021
|
if (json) printJson(result);
|
|
1961
|
-
else printTaskStatus(statusSession, snapshot, live?.remote);
|
|
2022
|
+
else printTaskStatus(statusSession, snapshot, queuedPrompts, live?.remote);
|
|
1962
2023
|
}
|
|
1963
2024
|
|
|
1964
2025
|
function filterSessions(sessions: SessionRecord[], args: string[], aliasSearchTerm?: string): SessionRecord[] {
|
|
@@ -1996,7 +2057,8 @@ function printTaskList(sessions: SessionRecord[]): void {
|
|
|
1996
2057
|
process.stdout.write(formatTaskList(sessions, cliLanguage, currentAppServerThreadIds(process.env)));
|
|
1997
2058
|
}
|
|
1998
2059
|
|
|
1999
|
-
function printTaskStatus(session: SessionRecord, snapshot: unknown,
|
|
2060
|
+
function printTaskStatus(session: SessionRecord, snapshot: unknown, queuedPrompts: Array<{ text: string }>,
|
|
2061
|
+
remote?: TaskStatusControlData["remote"]): void {
|
|
2000
2062
|
process.stdout.write(`${cliText("Title: ", "标题:")}${session.title ?? cliText("Untitled task", "未命名任务")}\n`);
|
|
2001
2063
|
process.stdout.write(`${cliText("Agent: ", "Agent:")}${session.agentName}\n`);
|
|
2002
2064
|
process.stdout.write(`${cliText("Task ID: ", "任务 ID:")}${session.remoteSessionId ?? session.acpSessionId ?? session.localSessionId}\n`);
|
|
@@ -2005,6 +2067,10 @@ function printTaskStatus(session: SessionRecord, snapshot: unknown, remote?: Tas
|
|
|
2005
2067
|
process.stdout.write(`${cliText("Status: ", "状态:")}${taskStateLabel(session.status)} / ${taskStateLabel(session.lastTurnStatus)}\n`);
|
|
2006
2068
|
process.stdout.write(`${cliText("Directory: ", "目录:")}${session.cwd}\n`);
|
|
2007
2069
|
process.stdout.write(`${cliText("Last turn: ", "上一轮:")}${session.lastTurnId ?? "-"}\n`);
|
|
2070
|
+
process.stdout.write(`${cliText("Queued prompts: ", "排队消息:")}${queuedPrompts.length}\n`);
|
|
2071
|
+
for (const [index, prompt] of queuedPrompts.entries()) {
|
|
2072
|
+
process.stdout.write(` ${index + 1}. ${prompt.text || cliText("Attachment", "附件")}\n`);
|
|
2073
|
+
}
|
|
2008
2074
|
let displayedFinalResponse: string | undefined;
|
|
2009
2075
|
if (snapshot && typeof snapshot === "object") {
|
|
2010
2076
|
const state = snapshot as Record<string, unknown>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { ModelQueueStatus, PlanStep, ToolState } from "../runtime/types.js";
|
|
3
|
+
import { toolTimestamp } from "../utils/toolTimestamp.js";
|
|
3
4
|
import { readTaskNotification, readTaskNotifications, type TaskNotificationActivity } from "./TraeTaskNotification.js";
|
|
4
5
|
|
|
5
6
|
// Optional TraeX extension; ordinary Codex notifications need no queue fields.
|
|
@@ -235,7 +236,7 @@ export function mapCodexNotification(method: string, params: unknown): MappedCod
|
|
|
235
236
|
return { kind: "agent_message_phase", threadId, turnId, itemId, phase };
|
|
236
237
|
}
|
|
237
238
|
const phase = method === "item/started" ? "started" : "updated";
|
|
238
|
-
const tool = mapTool(params.item, phase,
|
|
239
|
+
const tool = mapTool(params.item, phase, toolTimestamp(params.startedAtMs), toolTimestamp(params.completedAtMs));
|
|
239
240
|
if (!tool) return undefined;
|
|
240
241
|
return {
|
|
241
242
|
kind: "tool",
|
|
@@ -315,11 +316,19 @@ function mapTool(
|
|
|
315
316
|
};
|
|
316
317
|
}
|
|
317
318
|
if (type === "fileChange") {
|
|
319
|
+
let patchBudget = 16_000;
|
|
318
320
|
const files = Array.isArray(item.changes)
|
|
319
321
|
? item.changes.flatMap((change): NonNullable<ToolState["files"]> => {
|
|
320
322
|
if (!isRecord(change) || typeof change.path !== "string") return [];
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
+
const kind = isRecord(change.kind) ? change.kind : undefined;
|
|
324
|
+
const file = { path: change.path, moveTo: stringValue(kind?.move_path) };
|
|
325
|
+
const diff = stringValue(change.diff);
|
|
326
|
+
if (diff === undefined) return [file];
|
|
327
|
+
const limit = Math.min(patchBudget, 4_000);
|
|
328
|
+
const patch = diff.slice(0, limit).replace(/[\uD800-\uDBFF]$/u, "");
|
|
329
|
+
patchBudget -= patch.length;
|
|
330
|
+
return [{ ...file, ...countDiff(diff, kind?.type), patch: patch || undefined,
|
|
331
|
+
patchTruncated: diff.length > patch.length ? true : undefined }];
|
|
323
332
|
})
|
|
324
333
|
: [];
|
|
325
334
|
return { id, title: `修改 ${files.length} 个文件`, kind: "file_change", status, files, startedAt, completedAt };
|
|
@@ -502,8 +511,19 @@ function mapToolStatus(value: unknown, phase: "started" | "updated"): ToolState[
|
|
|
502
511
|
return phase === "updated" ? "completed" : "running";
|
|
503
512
|
}
|
|
504
513
|
|
|
505
|
-
function countDiff(diff: string,
|
|
506
|
-
|
|
514
|
+
function countDiff(diff: string, kind: unknown): { additions: number; deletions: number } {
|
|
515
|
+
const lines = diff.split("\n");
|
|
516
|
+
if (kind === "add" || kind === "delete") {
|
|
517
|
+
const length = diff ? lines.length - Number(diff.endsWith("\n")) : 0;
|
|
518
|
+
return kind === "add" ? { additions: length, deletions: 0 } : { additions: 0, deletions: length };
|
|
519
|
+
}
|
|
520
|
+
let additions = 0, deletions = 0, hunk = false;
|
|
521
|
+
for (const line of lines) {
|
|
522
|
+
if (line.startsWith("@@ ")) hunk = true;
|
|
523
|
+
else if (line[0] === "+" && (hunk || !line.startsWith("+++"))) additions++;
|
|
524
|
+
else if (line[0] === "-" && (hunk || !line.startsWith("---"))) deletions++;
|
|
525
|
+
}
|
|
526
|
+
return { additions, deletions };
|
|
507
527
|
}
|
|
508
528
|
|
|
509
529
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -432,6 +432,10 @@ export class CodexRuntime implements AgentRuntime {
|
|
|
432
432
|
return this.decorateRemoteSession(remoteSessionId, remoteSessionSummary({ ...response.thread, turns }));
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
+
getSessionStorageBytes(localSessionId: string): number | undefined {
|
|
436
|
+
return rolloutStorageBytes(this.sessions.get(localSessionId)?.rolloutPath);
|
|
437
|
+
}
|
|
438
|
+
|
|
435
439
|
async readRemoteSessionMetrics(remoteSessionId: string): Promise<RemoteSessionMetrics> {
|
|
436
440
|
const client = await this.client();
|
|
437
441
|
const metadata = await client.request<ThreadReadResponse>(
|