@keyou007/agent-bot 0.1.27-alpha.1 → 0.1.27-alpha.2
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 +24 -0
- package/README.md +54 -4
- package/README.zh.md +54 -4
- package/SECURITY.md +14 -0
- package/assets/workspace-sessions.js +648 -0
- package/assets/workspace.css +160 -0
- package/assets/workspace.js +1795 -0
- package/config.example.yaml +3 -2
- package/dist/codex/CodexEventMapper.js +35 -0
- package/dist/codex/CodexEventMapper.js.map +1 -1
- package/dist/codex/CodexRuntime.js +50 -4
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/codex/TraeTaskNotification.js +44 -0
- package/dist/codex/TraeTaskNotification.js.map +1 -0
- package/dist/config/SettingsStore.js +1 -1
- package/dist/config/SettingsStore.js.map +1 -1
- package/dist/config/loadConfig.js +3 -2
- package/dist/config/loadConfig.js.map +1 -1
- package/dist/config/paths.js +3 -0
- package/dist/config/paths.js.map +1 -1
- package/dist/feishu/CardRenderer.js +54 -10
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +2 -2
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +103 -16
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +61 -17
- package/dist/index.js.map +1 -1
- package/dist/local-files/DiagramPreview.js +1 -1
- package/dist/local-files/GitDiffPreview.js +11 -7
- package/dist/local-files/GitDiffPreview.js.map +1 -1
- package/dist/local-files/LocalFileViewerServer.js +273 -25
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/MarkdownFileLinks.js +5 -4
- package/dist/local-files/MarkdownFileLinks.js.map +1 -1
- package/dist/local-files/TurnPreviewPage.js +32 -10
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/local-files/WebPageTitle.js +85 -0
- package/dist/local-files/WebPageTitle.js.map +1 -0
- package/dist/local-files/WorkspaceFiles.js +553 -0
- package/dist/local-files/WorkspaceFiles.js.map +1 -0
- package/dist/local-files/WorkspaceOrigin.js +38 -0
- package/dist/local-files/WorkspaceOrigin.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +19 -0
- package/dist/local-files/WorkspacePage.js.map +1 -0
- package/dist/local-files/WorkspaceSessions.js +689 -0
- package/dist/local-files/WorkspaceSessions.js.map +1 -0
- package/dist/presentation/TurnStateReducer.js +74 -13
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/presentation/turnActivity.js +41 -0
- package/dist/presentation/turnActivity.js.map +1 -0
- package/dist/presentation/turnStatus.js +11 -0
- package/dist/presentation/turnStatus.js.map +1 -1
- package/dist/presentation/visibleTurnActivities.js +4 -2
- package/dist/presentation/visibleTurnActivities.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +150 -14
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/runtime/types.js +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/state/InboundMessageStore.js +54 -0
- package/dist/state/InboundMessageStore.js.map +1 -0
- package/dist/state/StateStore.js +71 -1
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +4 -2
- package/dist/state/TurnPreviewJournal.js.map +1 -1
- package/dist/state/migrations.js +20 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +1 -0
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/dist/supervision/SafeRestartScheduler.js +33 -16
- package/dist/supervision/SafeRestartScheduler.js.map +1 -1
- package/dist/terminal/TerminalLinks.js +32 -0
- package/dist/terminal/TerminalLinks.js.map +1 -1
- package/dist/terminal/TerminalPage.js +44 -24
- package/dist/terminal/TerminalPage.js.map +1 -1
- package/dist/terminal/TerminalServer.js +103 -39
- package/dist/terminal/TerminalServer.js.map +1 -1
- package/docs/technical-reference.md +1 -1
- package/docs/technical-reference.zh.md +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +3 -1
- package/src/codex/CodexEventMapper.ts +39 -1
- package/src/codex/CodexRuntime.ts +54 -4
- package/src/codex/TraeTaskNotification.ts +49 -0
- package/src/config/SettingsStore.ts +1 -1
- package/src/config/loadConfig.ts +3 -2
- package/src/config/paths.ts +4 -0
- package/src/feishu/CardRenderer.ts +45 -11
- package/src/feishu/FeishuMessageClient.ts +2 -2
- package/src/feishu/FeishuTurnPresenter.ts +110 -20
- package/src/index.ts +62 -17
- package/src/local-files/DiagramPreview.ts +1 -1
- package/src/local-files/GitDiffPreview.ts +10 -7
- package/src/local-files/LocalFileViewerServer.ts +243 -25
- package/src/local-files/MarkdownFileLinks.ts +5 -3
- package/src/local-files/TurnPreviewPage.ts +35 -9
- package/src/local-files/WebPageTitle.ts +59 -0
- package/src/local-files/WorkspaceFiles.ts +468 -0
- package/src/local-files/WorkspaceOrigin.ts +31 -0
- package/src/local-files/WorkspacePage.ts +21 -0
- package/src/local-files/WorkspaceSessions.ts +587 -0
- package/src/presentation/TurnStateReducer.ts +76 -14
- package/src/presentation/turnActivity.ts +43 -0
- package/src/presentation/turnStatus.ts +14 -0
- package/src/presentation/turnViewTypes.ts +10 -1
- package/src/presentation/visibleTurnActivities.ts +4 -2
- package/src/proxy/ProxySessionController.ts +149 -13
- package/src/runtime/types.ts +17 -0
- package/src/state/InboundMessageStore.ts +72 -0
- package/src/state/StateStore.ts +80 -1
- package/src/state/TurnPreviewJournal.ts +4 -2
- package/src/state/migrations.ts +20 -0
- package/src/supervision/SafeRestartNotifier.ts +1 -0
- package/src/supervision/SafeRestartScheduler.ts +42 -18
- package/src/terminal/TerminalLinks.ts +26 -0
- package/src/terminal/TerminalPage.ts +44 -24
- package/src/terminal/TerminalServer.ts +98 -36
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { PlanStep, ToolState } from "../runtime/types.js";
|
|
2
|
+
import type { ModelQueueStatus, PlanStep, ToolState } from "../runtime/types.js";
|
|
3
|
+
import { readTaskNotification, readTaskNotifications, type TaskNotificationActivity } from "./TraeTaskNotification.js";
|
|
4
|
+
|
|
5
|
+
// Optional TraeX extension; ordinary Codex notifications need no queue fields.
|
|
6
|
+
const modelQueueStatus = z.object({
|
|
7
|
+
state: z.enum(["queued", "waiting", "ready"]),
|
|
8
|
+
position: z.number().int().min(0).max(4_294_967_295).nullish(),
|
|
9
|
+
message: z.string().nullish(),
|
|
10
|
+
operation: z.enum(["contextCompaction"]).nullish(),
|
|
11
|
+
});
|
|
3
12
|
|
|
4
13
|
const modeChangeRequest = z.object({
|
|
5
14
|
requestId: z.string().min(1),
|
|
@@ -16,6 +25,7 @@ const modeChangeResolution = z.object({
|
|
|
16
25
|
|
|
17
26
|
export type MappedCodexNotification =
|
|
18
27
|
| { kind: "turn_started"; threadId: string; turnId: string; startedAt?: number }
|
|
28
|
+
| { kind: "model_queue"; threadId: string; turnId: string; queue: ModelQueueStatus }
|
|
19
29
|
| { kind: "runtime_error"; threadId: string; turnId: string; message: string; willRetry: boolean }
|
|
20
30
|
| {
|
|
21
31
|
kind: "token_usage";
|
|
@@ -68,6 +78,8 @@ export type MappedCodexNotification =
|
|
|
68
78
|
status: "completed" | "cancelled" | "failed";
|
|
69
79
|
durationMs?: number;
|
|
70
80
|
error?: string;
|
|
81
|
+
taskNotifications?: TaskNotificationActivity[];
|
|
82
|
+
taskNotificationFinalResponse?: string;
|
|
71
83
|
};
|
|
72
84
|
|
|
73
85
|
export function mapCodexNotification(method: string, params: unknown): MappedCodexNotification | undefined {
|
|
@@ -76,6 +88,18 @@ export function mapCodexNotification(method: string, params: unknown): MappedCod
|
|
|
76
88
|
const turnId = stringValue(params.turnId) ?? (isRecord(params.turn) ? stringValue(params.turn.id) : undefined);
|
|
77
89
|
if (!threadId || !turnId) return undefined;
|
|
78
90
|
|
|
91
|
+
if (method === "queue/status") {
|
|
92
|
+
const parsed = modelQueueStatus.safeParse(params);
|
|
93
|
+
if (!parsed.success) return undefined;
|
|
94
|
+
const { state, position, message, operation } = parsed.data;
|
|
95
|
+
return { kind: "model_queue", threadId, turnId, queue: {
|
|
96
|
+
state,
|
|
97
|
+
...(position == null ? {} : { position }),
|
|
98
|
+
...(message == null ? {} : { message: message.slice(0, 1_000) }),
|
|
99
|
+
...(operation == null ? {} : { operation }),
|
|
100
|
+
} };
|
|
101
|
+
}
|
|
102
|
+
|
|
79
103
|
if (method === "error" && isRecord(params.error)) {
|
|
80
104
|
const message = formatCodexError(params.error);
|
|
81
105
|
if (!message || typeof params.willRetry !== "boolean") return undefined;
|
|
@@ -176,6 +200,10 @@ export function mapCodexNotification(method: string, params: unknown): MappedCod
|
|
|
176
200
|
return { kind: "plan", threadId, turnId, steps };
|
|
177
201
|
}
|
|
178
202
|
if ((method === "item/started" || method === "item/completed") && isRecord(params.item)) {
|
|
203
|
+
if (params.item.type === "taskNotification") {
|
|
204
|
+
const activity = method === "item/completed" ? readTaskNotification(params.item) : undefined;
|
|
205
|
+
return activity && { kind: "progress", threadId, turnId, ...activity, append: false };
|
|
206
|
+
}
|
|
179
207
|
if (params.item.type === "reasoning") {
|
|
180
208
|
if (method !== "item/completed") return undefined;
|
|
181
209
|
const itemId = stringValue(params.item.id);
|
|
@@ -221,6 +249,14 @@ export function mapCodexNotification(method: string, params: unknown): MappedCod
|
|
|
221
249
|
const status = params.turn.status;
|
|
222
250
|
const mappedStatus = status === "interrupted" ? "cancelled" : status === "failed" ? "failed" : "completed";
|
|
223
251
|
const error = formatCodexError(params.turn.error);
|
|
252
|
+
const taskNotifications = readTaskNotifications(params.turn.items);
|
|
253
|
+
const taskNotificationFinalResponse = taskNotifications.length && Array.isArray(params.turn.items)
|
|
254
|
+
? params.turn.items.flatMap((item) => {
|
|
255
|
+
if (!isRecord(item) || item.type !== "agentMessage" || item.phase !== "final_answer") return [];
|
|
256
|
+
const text = nonEmptyString(item.text);
|
|
257
|
+
return text ? [text] : [];
|
|
258
|
+
}).join("\n\n")
|
|
259
|
+
: undefined;
|
|
224
260
|
return {
|
|
225
261
|
kind: "terminal",
|
|
226
262
|
threadId,
|
|
@@ -228,6 +264,8 @@ export function mapCodexNotification(method: string, params: unknown): MappedCod
|
|
|
228
264
|
status: mappedStatus,
|
|
229
265
|
durationMs: numberValue(params.turn.durationMs),
|
|
230
266
|
error,
|
|
267
|
+
...(taskNotifications.length ? { taskNotifications } : {}),
|
|
268
|
+
...(taskNotificationFinalResponse ? { taskNotificationFinalResponse } : {}),
|
|
231
269
|
};
|
|
232
270
|
}
|
|
233
271
|
return undefined;
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
ModelOption,
|
|
13
13
|
ModelListResult,
|
|
14
14
|
ModelProviderOption,
|
|
15
|
+
ModelQueueStatus,
|
|
15
16
|
PermissionMode,
|
|
16
17
|
RemoteSessionActivity,
|
|
17
18
|
RemoteSessionMetrics,
|
|
@@ -39,6 +40,8 @@ import { workspaceSandboxFromConfig, workspaceSandboxFromResponse, type TurnSand
|
|
|
39
40
|
import { formatCodexError, mapCodexNotification } from "./CodexEventMapper.js";
|
|
40
41
|
import { CodexLocalActivityDetector } from "./CodexLocalActivityDetector.js";
|
|
41
42
|
import { hasCompletedTraePlanEntry } from "./TraePlanEntry.js";
|
|
43
|
+
import { readTaskNotifications } from "./TraeTaskNotification.js";
|
|
44
|
+
import { TASK_NOTIFICATION_ACTIVITY_PREFIX } from "../runtime/types.js";
|
|
42
45
|
import { detectProjectlessWorkspace } from "./ProjectlessWorkspace.js";
|
|
43
46
|
import { threadWriterLockPath } from "./ThreadWriterProcess.js";
|
|
44
47
|
import { assertProviderSettingsApplied, PROVIDER_SWITCH_BUSY, PROVIDER_SWITCH_EMPTY, ProviderSwitchError, providerSwitchFailure } from "./ProviderSwitch.js";
|
|
@@ -88,6 +91,7 @@ export interface AppServerClientProvider {
|
|
|
88
91
|
|
|
89
92
|
interface CodexSession extends RuntimeSession {
|
|
90
93
|
activeTurnStartedAt?: number;
|
|
94
|
+
modelQueue?: ModelQueueStatus;
|
|
91
95
|
terminalTurnIds: Set<string>;
|
|
92
96
|
modeChangeRequestIds: Set<string>;
|
|
93
97
|
planContinuationTurnId?: string;
|
|
@@ -1373,6 +1377,7 @@ export class CodexRuntime implements AgentRuntime {
|
|
|
1373
1377
|
this.adoptTurn(session, mapped.turnId, mapped.startedAt ?? Date.now());
|
|
1374
1378
|
return;
|
|
1375
1379
|
}
|
|
1380
|
+
if (mapped.kind === "model_queue" && session.activeTurnId !== mapped.turnId) return;
|
|
1376
1381
|
if (!session.activeTurnId || session.activeTurnId !== mapped.turnId) {
|
|
1377
1382
|
this.logger.debug(
|
|
1378
1383
|
{ sessionId: session.localSessionId, activeTurnId: session.activeTurnId, notificationTurnId: mapped.turnId, method },
|
|
@@ -1384,7 +1389,9 @@ export class CodexRuntime implements AgentRuntime {
|
|
|
1384
1389
|
return;
|
|
1385
1390
|
}
|
|
1386
1391
|
const sessionId = session.localSessionId;
|
|
1387
|
-
if (mapped.kind === "
|
|
1392
|
+
if (mapped.kind === "model_queue") {
|
|
1393
|
+
this.updateModelQueue(session, mapped.turnId, mapped.queue);
|
|
1394
|
+
} else if (mapped.kind === "mode_change_requested") {
|
|
1388
1395
|
const requestId = `mode:${mapped.threadId}:${mapped.requestId}`;
|
|
1389
1396
|
if (session.modeChangeRequestIds.has(requestId)) return;
|
|
1390
1397
|
session.modeChangeRequestIds.add(requestId);
|
|
@@ -1537,6 +1544,9 @@ export class CodexRuntime implements AgentRuntime {
|
|
|
1537
1544
|
delta: mapped.delta,
|
|
1538
1545
|
});
|
|
1539
1546
|
} else if (mapped.kind === "terminal") {
|
|
1547
|
+
for (const activity of mapped.taskNotifications ?? []) {
|
|
1548
|
+
this.emit({ type: "progress", sessionId, turnId: mapped.turnId, ...activity, append: false });
|
|
1549
|
+
}
|
|
1540
1550
|
if (mapped.status === "completed" && !session.finalText && session.unphasedFinalMessageId) {
|
|
1541
1551
|
this.promoteUnphasedMessage(session, mapped.turnId, session.unphasedFinalMessageId);
|
|
1542
1552
|
}
|
|
@@ -1555,7 +1565,7 @@ export class CodexRuntime implements AgentRuntime {
|
|
|
1555
1565
|
this.emit({ type: "turn_failed", sessionId, turnId: mapped.turnId, message: mapped.error ?? "App Server turn failed." });
|
|
1556
1566
|
} else {
|
|
1557
1567
|
const finalResponse = appendModelSwitchGuidance(
|
|
1558
|
-
appendGeneratedImageMarkdown(session.finalText, session.generatedImagePaths),
|
|
1568
|
+
appendGeneratedImageMarkdown(session.finalText || mapped.taskNotificationFinalResponse || "", session.generatedImagePaths),
|
|
1559
1569
|
session.model,
|
|
1560
1570
|
);
|
|
1561
1571
|
this.emit({
|
|
@@ -1727,6 +1737,7 @@ export class CodexRuntime implements AgentRuntime {
|
|
|
1727
1737
|
if (session.turnCount !== undefined) session.turnCount += 1;
|
|
1728
1738
|
}
|
|
1729
1739
|
session.activeTurnId = turnId;
|
|
1740
|
+
session.modelQueue = undefined;
|
|
1730
1741
|
session.responseFailureTurnId = undefined;
|
|
1731
1742
|
session.activeTurnStartedAt = startedAt;
|
|
1732
1743
|
session.planContinuationTurnId = undefined;
|
|
@@ -1751,6 +1762,9 @@ export class CodexRuntime implements AgentRuntime {
|
|
|
1751
1762
|
|
|
1752
1763
|
private finishSnapshotTurn(session: CodexSession, turn: CodexTurnSnapshot): void {
|
|
1753
1764
|
if (session.activeTurnId !== turn.id) return;
|
|
1765
|
+
for (const activity of readTaskNotifications(turn.items)) {
|
|
1766
|
+
this.emit({ type: "progress", sessionId: session.localSessionId, turnId: turn.id, ...activity, append: false });
|
|
1767
|
+
}
|
|
1754
1768
|
if (turn.status === "completed") {
|
|
1755
1769
|
for (const item of finalResponseMessages(turn)) {
|
|
1756
1770
|
if (item.id) this.promoteUnphasedMessage(session, turn.id, item.id);
|
|
@@ -1880,7 +1894,40 @@ export class CodexRuntime implements AgentRuntime {
|
|
|
1880
1894
|
&& pending.targetMode === "default") session.planContinuationTurnId = pending.turnId;
|
|
1881
1895
|
}
|
|
1882
1896
|
|
|
1897
|
+
private updateModelQueue(
|
|
1898
|
+
session: CodexSession, turnId: string, queue: ModelQueueStatus,
|
|
1899
|
+
source: RuntimeEvent["type"] | "queue/status" = "queue/status",
|
|
1900
|
+
): void {
|
|
1901
|
+
const previous = session.modelQueue;
|
|
1902
|
+
const changed = previous?.state !== queue.state || previous?.position !== queue.position
|
|
1903
|
+
|| previous?.operation !== queue.operation;
|
|
1904
|
+
if (!changed && previous?.message === queue.message) return;
|
|
1905
|
+
session.modelQueue = queue;
|
|
1906
|
+
if (changed) this.logger.info({
|
|
1907
|
+
sessionId: session.localSessionId, turnId, state: queue.state, source,
|
|
1908
|
+
position: queue.position, operation: queue.operation,
|
|
1909
|
+
}, "App Server model queue status changed.");
|
|
1910
|
+
const reason = source === "queue/status" ? undefined : source === "turn_status_unknown" ? "disconnected"
|
|
1911
|
+
: source === "turn_completed" || source === "turn_cancelled" || source === "turn_failed" ? "turn_ended" : "output";
|
|
1912
|
+
this.emit({ type: "model_queue_updated", sessionId: session.localSessionId, turnId, queue, timestampMs: Date.now(), reason });
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1883
1915
|
private emit(event: RuntimeEvent): void {
|
|
1916
|
+
const session = this.sessions.get(event.sessionId);
|
|
1917
|
+
if (session?.modelQueue && session.modelQueue.state !== "ready" && (
|
|
1918
|
+
event.type === "agent_text_delta" && event.text.trim().length > 0
|
|
1919
|
+
|| event.type === "progress" && event.severity !== "warning"
|
|
1920
|
+
&& !event.activityId?.startsWith(TASK_NOTIFICATION_ACTIVITY_PREFIX) && event.text.trim().length > 0
|
|
1921
|
+
|| event.type === "reasoning_delta" && event.text.trim().length > 0
|
|
1922
|
+
|| event.type === "tool_started"
|
|
1923
|
+
|| event.type === "token_usage_updated"
|
|
1924
|
+
|| event.type === "approval_requested"
|
|
1925
|
+
|| event.type === "turn_completed" || event.type === "turn_cancelled" || event.type === "turn_failed"
|
|
1926
|
+
|| event.type === "turn_status_unknown"
|
|
1927
|
+
|| event.type === "context_compaction" && event.phase === "completed"
|
|
1928
|
+
)) {
|
|
1929
|
+
this.updateModelQueue(session, event.turnId, { state: "ready", operation: session.modelQueue.operation }, event.type);
|
|
1930
|
+
}
|
|
1884
1931
|
if (event.type === "turn_completed" || event.type === "turn_cancelled" || event.type === "turn_failed") {
|
|
1885
1932
|
for (const [requestId, pending] of this.modeChanges) {
|
|
1886
1933
|
if (pending.sessionId !== event.sessionId || pending.turnId !== event.turnId) continue;
|
|
@@ -2089,8 +2136,11 @@ function remoteTurnDetails(remoteSessionId: string, turn: CodexTurnSnapshot): Re
|
|
|
2089
2136
|
if (mapped?.kind === "tool") items.push({ kind: "tool", tool: mapped.tool });
|
|
2090
2137
|
else if (mapped?.kind === "reasoning_completed") {
|
|
2091
2138
|
items.push({ kind: "reasoning", id: mapped.itemId, summary: mapped.summary, content: mapped.content });
|
|
2092
|
-
} else if (mapped?.kind === "progress")
|
|
2093
|
-
|
|
2139
|
+
} else if (mapped?.kind === "progress") {
|
|
2140
|
+
const activityId = mapped.activityId.startsWith(TASK_NOTIFICATION_ACTIVITY_PREFIX)
|
|
2141
|
+
? mapped.activityId.slice("commentary:".length) : id;
|
|
2142
|
+
items.push({ kind: "message", id: activityId, role: "assistant", text: mapped.text });
|
|
2143
|
+
} else if (mapped?.kind === "plan") items.push({ kind: "plan", steps: mapped.steps });
|
|
2094
2144
|
}
|
|
2095
2145
|
return {
|
|
2096
2146
|
turnId: turn.id,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TASK_NOTIFICATION_ACTIVITY_PREFIX } from "../runtime/types.js";
|
|
2
|
+
|
|
3
|
+
export interface TaskNotificationActivity {
|
|
4
|
+
activityId: string;
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function readTaskNotification(item: unknown): TaskNotificationActivity | undefined {
|
|
9
|
+
if (!isRecord(item) || item.type !== "taskNotification" || typeof item.id !== "string"
|
|
10
|
+
|| !item.id.trim() || !Array.isArray(item.content)) return;
|
|
11
|
+
|
|
12
|
+
for (const block of item.content) {
|
|
13
|
+
if (!isRecord(block) || block.type !== "text" || typeof block.text !== "string" || block.text.length > 16_384) continue;
|
|
14
|
+
const payload = /^<task-notification>\s*([\s\S]*?)\s*<\/task-notification>$/u.exec(block.text.trim())?.[1];
|
|
15
|
+
if (!payload) continue;
|
|
16
|
+
const status = field(payload, "status");
|
|
17
|
+
const summary = field(payload, "summary");
|
|
18
|
+
if (!status && !summary) continue;
|
|
19
|
+
const taskId = field(payload, "task-id");
|
|
20
|
+
const label = status === "completed" ? "后台任务已完成"
|
|
21
|
+
: status === "failed" ? "后台任务失败"
|
|
22
|
+
: status === "stopped" || status === "cancelled" || status === "canceled" || status === "interrupted" || status === "killed" ? "后台任务已停止"
|
|
23
|
+
: status === "timeout" || status === "timed_out" ? "后台任务超时" : "后台任务通知";
|
|
24
|
+
const title = label + (taskId && /^[a-z\d][a-z\d._-]{0,63}$/iu.test(taskId) ? ` · #${taskId}` : "");
|
|
25
|
+
const exitCode = /^Shell task (?:completed|failed) with exit code (-?\d{1,12})$/iu.exec(summary ?? "")?.[1];
|
|
26
|
+
// Keep the reported summary as text. Do not surface or read the output-file field.
|
|
27
|
+
const characters = Array.from(summary?.replace(/[\u0000-\u001f\u007f-\u009f]/gu, " ").trim() ?? "");
|
|
28
|
+
const detail = characters.slice(0, 360).join("").replaceAll("```", "'''") + (characters.length > 360 ? "…" : "");
|
|
29
|
+
const text = exitCode !== undefined ? `${title} · Shell 退出码 ${exitCode}`
|
|
30
|
+
: detail ? `${title}\n\n\`\`\`\n${detail}\n\`\`\`` : title;
|
|
31
|
+
return { activityId: TASK_NOTIFICATION_ACTIVITY_PREFIX + item.id, text };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function readTaskNotifications(items: unknown): TaskNotificationActivity[] {
|
|
36
|
+
return Array.isArray(items) ? items.flatMap((item) => {
|
|
37
|
+
const activity = readTaskNotification(item);
|
|
38
|
+
return activity ? [activity] : [];
|
|
39
|
+
}) : [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function field(payload: string, name: "status" | "task-id" | "summary"): string | undefined {
|
|
43
|
+
const value = new RegExp(`(?:^|\\n)[ \\t]*<${name}>([\\s\\S]*?)</${name}>(?=[ \\t]*(?:\\r?\\n|$))`, "u").exec(payload)?.[1]?.trim();
|
|
44
|
+
return value || undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
48
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
49
|
+
}
|
|
@@ -240,7 +240,7 @@ function fieldsFor(
|
|
|
240
240
|
return [
|
|
241
241
|
bool("console", "本地控制台", ["console", "enabled"]),
|
|
242
242
|
bool("terminal", "网页终端", ["terminal", "enabled"]),
|
|
243
|
-
field("terminalPassword", "终端密码", ["terminal", "password"], "secret", DEFAULT_TERMINAL_PASSWORD, terminalPasswordSchema),
|
|
243
|
+
field("terminalPassword", "工作台 / 终端密码", ["terminal", "password"], "secret", DEFAULT_TERMINAL_PASSWORD, terminalPasswordSchema),
|
|
244
244
|
bool("preview", "文件与 Turn 预览", ["fileViewer", "enabled"]),
|
|
245
245
|
field(
|
|
246
246
|
"host",
|
package/src/config/loadConfig.ts
CHANGED
|
@@ -31,8 +31,9 @@ updates:
|
|
|
31
31
|
|
|
32
32
|
terminal:
|
|
33
33
|
enabled: true
|
|
34
|
-
#
|
|
35
|
-
#
|
|
34
|
+
# Shared Workspace / Terminal password, configurable in /settings > Advanced.
|
|
35
|
+
# With the public default, Workspace (including its embedded terminal) is open to anyone who can reach it.
|
|
36
|
+
# password: "123456" # Default when omitted.
|
|
36
37
|
|
|
37
38
|
fileViewer:
|
|
38
39
|
enabled: true
|
package/src/config/paths.ts
CHANGED
|
@@ -24,6 +24,10 @@ export function defaultSqlitePath(env: NodeJS.ProcessEnv = process.env): string
|
|
|
24
24
|
return path.join(agentBotHome(env), "data", "agent-bot.sqlite");
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export function inboundImageDirectory(sqlitePath: string): string {
|
|
28
|
+
return path.join(path.dirname(sqlitePath), "inbound-images");
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
export function resolveUserPath(input: string, baseDirectory = process.cwd()): string {
|
|
28
32
|
const expanded = expandHome(input);
|
|
29
33
|
return path.isAbsolute(expanded) ? path.normalize(expanded) : path.resolve(baseDirectory, expanded);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { approvalActivityId } from "../presentation/TurnStateReducer.js";
|
|
3
|
+
import { modelQueueLabel } from "../presentation/turnStatus.js";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import type { JsonValue } from "../acp/acpTypes.js";
|
|
5
6
|
import type { RuntimeSession } from "../acp/AcpSessionManager.js";
|
|
@@ -15,6 +16,7 @@ import type {
|
|
|
15
16
|
import type { TurnActivity, TurnViewState, TurnViewStatus } from "../presentation/turnViewTypes.js";
|
|
16
17
|
import type { ExecutionProvenance } from "../state/ExecutionProvenanceStore.js";
|
|
17
18
|
import { visibleTurnActivities } from "../presentation/visibleTurnActivities.js";
|
|
19
|
+
import { formatModelQueueDuration, isCommentaryActivity, liveModelQueueActivity, systemActivityQuote, USER_ACTIVITY_ICON } from "../presentation/turnActivity.js";
|
|
18
20
|
import { displayRuntimeError } from "../runtime/responseErrors.js";
|
|
19
21
|
import { truncateMiddle, truncateText } from "../utils/markdown.js";
|
|
20
22
|
import type { UpdateNotice } from "../updates/types.js";
|
|
@@ -64,6 +66,7 @@ export interface InitializationWelcomeView {
|
|
|
64
66
|
|
|
65
67
|
export interface SafeRestartStatusView {
|
|
66
68
|
activeTerminals?: number;
|
|
69
|
+
pendingInboundMessages?: number;
|
|
67
70
|
terminalBlockers?: ActiveTerminal[];
|
|
68
71
|
contextKey?: string;
|
|
69
72
|
scheduleId: number;
|
|
@@ -1059,6 +1062,7 @@ export class CardRenderer {
|
|
|
1059
1062
|
`**重启原因**:${inlineCode(view.reason)}`,
|
|
1060
1063
|
`**重启倒计时**:${countdown}`,
|
|
1061
1064
|
`**待投递结果**:${view.pendingFinalDeliveries} 条`,
|
|
1065
|
+
...(view.pendingInboundMessages ? [`**正在处理收到的消息**:${view.pendingInboundMessages} 条`] : []),
|
|
1062
1066
|
...(view.activeTerminals ? [`**活动终端**:${view.activeTerminals} 个。结束终端会中断其中的命令;ForceRestart 会中断所有终端。`] : []),
|
|
1063
1067
|
];
|
|
1064
1068
|
const elements: Record<string, unknown>[] = [markdown(lines.join("\n"))];
|
|
@@ -1321,18 +1325,42 @@ export class CardRenderer {
|
|
|
1321
1325
|
);
|
|
1322
1326
|
}
|
|
1323
1327
|
return turnCard(
|
|
1324
|
-
turnTitle(state.status, state.prompt ?? state.taskTitle),
|
|
1328
|
+
turnTitle(state.status, state.prompt ?? state.taskTitle, modelQueueLabel(state)),
|
|
1325
1329
|
turnTemplate(state.status),
|
|
1326
1330
|
elements,
|
|
1327
1331
|
renderTurnSubtitle(state),
|
|
1328
1332
|
);
|
|
1329
1333
|
}
|
|
1330
1334
|
|
|
1335
|
+
renderTaskNotification(state: TurnViewState, previewUrl?: string, answer?: string, hasMore = false): Record<string, unknown> {
|
|
1336
|
+
const elements = (state.taskNotificationCard ?? []).map((notice) => markdown(notice.text));
|
|
1337
|
+
if (answer) {
|
|
1338
|
+
elements.push({ tag: "hr" }, markdown("**补充回答**"), markdown(answer));
|
|
1339
|
+
if (hasMore) elements.push(markdown(previewUrl ? "回答较长,完整内容可在 Preview 查看。" : "回答较长,剩余内容将另行发送。"));
|
|
1340
|
+
} else if (isTurnStoppable(state.status) || state.status === "starting") {
|
|
1341
|
+
elements.push(markdown(modelQueueLabel(state) ?? "正在处理后台任务结果…"));
|
|
1342
|
+
} else if (state.status === "cancelled" && !state.statusMessage) {
|
|
1343
|
+
elements.push(markdown("已停止处理后台任务结果。"));
|
|
1344
|
+
}
|
|
1345
|
+
if (state.approval) elements.push(...renderApprovalElements(state, state.approval));
|
|
1346
|
+
if (state.statusMessage) elements.push(markdown(codeBlock(state.statusMessage, 2_000)));
|
|
1347
|
+
if (state.error) elements.push(markdown(codeBlock(displayRuntimeError(state.error), 2_000)));
|
|
1348
|
+
const actions: TaskListCardAction[] = [];
|
|
1349
|
+
if (isTurnStoppable(state.status)) actions.push({
|
|
1350
|
+
text: "Stop", type: "danger", value: { action: "turn_cancel", sessionId: state.sessionId, turnId: state.turnId },
|
|
1351
|
+
});
|
|
1352
|
+
if (previewUrl) actions.push(turnPreviewAction(previewUrl));
|
|
1353
|
+
if (actions.length) elements.push({ tag: "hr" }, taskActionRow(actions));
|
|
1354
|
+
return turnCard("后台任务通知", state.error ? "red" : "blue", elements, truncateText(state.taskTitle ?? "", 80));
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1331
1357
|
renderTurnDetails(state: TurnViewState, previewUrl?: string, provenance?: ExecutionProvenance): Record<string, unknown> {
|
|
1332
1358
|
const title = state.taskTitle
|
|
1333
1359
|
? `任务执行详情:${truncateText(state.taskTitle.replace(/\s+/g, " ").trim(), 60)}`
|
|
1334
1360
|
: "任务执行详情";
|
|
1335
1361
|
const elements = [markdown(`Turn: \`${state.turnId}\``)];
|
|
1362
|
+
const queueLabel = modelQueueLabel(state);
|
|
1363
|
+
if (queueLabel) elements.push(markdown(`**${queueLabel}**`));
|
|
1336
1364
|
if (provenance) {
|
|
1337
1365
|
const labels: Record<ExecutionProvenance["trigger"], string> = {
|
|
1338
1366
|
user: "用户消息", queue: "排队消息", schedule: "定时任务", recovery: "未提交请求恢复",
|
|
@@ -1901,6 +1929,12 @@ function renderActivity(
|
|
|
1901
1929
|
projectCwd?: string,
|
|
1902
1930
|
fullAssistantText = false,
|
|
1903
1931
|
): Record<string, unknown>[] {
|
|
1932
|
+
if (activity.kind === "system") {
|
|
1933
|
+
const text = activity.text.trim();
|
|
1934
|
+
if (!text) return [];
|
|
1935
|
+
const chunks = fullAssistantText ? splitText(text, ACTIVITY_TEXT_CHUNK) : [truncateText(text, MAX_LIVE_ASSISTANT_TEXT)];
|
|
1936
|
+
return chunks.map((chunk) => markdown(systemActivityQuote(chunk)));
|
|
1937
|
+
}
|
|
1904
1938
|
if (activity.kind === "user") {
|
|
1905
1939
|
const text = activity.text.trim();
|
|
1906
1940
|
if (!text) return [];
|
|
@@ -1931,7 +1965,7 @@ function boldUserActivity(text: string, showIcon: boolean): string {
|
|
|
1931
1965
|
return text
|
|
1932
1966
|
.split("\n")
|
|
1933
1967
|
.map((line, index) => {
|
|
1934
|
-
const content = showIcon && index === 0 ?
|
|
1968
|
+
const content = showIcon && index === 0 ? `${USER_ACTIVITY_ICON} ${line}` : line;
|
|
1935
1969
|
return content ? `**${content}**` : "";
|
|
1936
1970
|
})
|
|
1937
1971
|
.join("\n");
|
|
@@ -2004,7 +2038,7 @@ function groupTurnActivities(activities: TurnActivity[]): GroupedTurnActivity[]
|
|
|
2004
2038
|
};
|
|
2005
2039
|
|
|
2006
2040
|
for (const activity of activities) {
|
|
2007
|
-
if (!isCommentaryActivity(activity)) {
|
|
2041
|
+
if (!isCommentaryActivity(activity) && activity.kind !== "system") {
|
|
2008
2042
|
segment.push(activity);
|
|
2009
2043
|
continue;
|
|
2010
2044
|
}
|
|
@@ -2015,11 +2049,6 @@ function groupTurnActivities(activities: TurnActivity[]): GroupedTurnActivity[]
|
|
|
2015
2049
|
return groups;
|
|
2016
2050
|
}
|
|
2017
2051
|
|
|
2018
|
-
function isCommentaryActivity(activity: TurnActivity): boolean {
|
|
2019
|
-
return activity.kind === "assistant"
|
|
2020
|
-
|| (activity.kind === "reasoning" && activity.id.startsWith("commentary:"));
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
2052
|
function executionActivityPanel(
|
|
2024
2053
|
group: Extract<GroupedTurnActivity, { kind: "execution" }>,
|
|
2025
2054
|
projectCwd: string | undefined,
|
|
@@ -2250,7 +2279,11 @@ function removeMarkdownBold(value: string): string {
|
|
|
2250
2279
|
|
|
2251
2280
|
function turnActivities(state: TurnViewState): TurnActivity[] {
|
|
2252
2281
|
if (state.activities?.length) {
|
|
2253
|
-
const
|
|
2282
|
+
const queue = liveModelQueueActivity(state);
|
|
2283
|
+
const activities = visibleTurnActivities(state).map((activity) => queue && activity.id === queue.id
|
|
2284
|
+
&& activity.kind === "system" && activity.category === "model_queue"
|
|
2285
|
+
? { ...activity, text: `${queue.label} · 已等待 ${formatModelQueueDuration(Date.now() - queue.startedAt)}。` }
|
|
2286
|
+
: activity);
|
|
2254
2287
|
return state.approval ? activities.filter((a) => a.id !== approvalActivityId(state.turnId, state.approval!.id)) : activities;
|
|
2255
2288
|
}
|
|
2256
2289
|
|
|
@@ -2765,7 +2798,7 @@ function persistedTaskStatus(sessionStatus: string, lastTurnStatus?: string): st
|
|
|
2765
2798
|
return labels[lastTurnStatus ?? sessionStatus] ?? lastTurnStatus ?? sessionStatus;
|
|
2766
2799
|
}
|
|
2767
2800
|
|
|
2768
|
-
function turnTitle(status: TurnViewStatus, prompt?: string): string {
|
|
2801
|
+
function turnTitle(status: TurnViewStatus, prompt?: string, queueLabel?: string): string {
|
|
2769
2802
|
if (status === "unknown") return `待核实${prompt ? `:${truncateTurnPrompt(prompt)}` : ""}`;
|
|
2770
2803
|
const reactionEmoji = status === "completed"
|
|
2771
2804
|
? "✅"
|
|
@@ -2786,7 +2819,8 @@ function turnTitle(status: TurnViewStatus, prompt?: string): string {
|
|
|
2786
2819
|
? "等待确认"
|
|
2787
2820
|
: "正在处理";
|
|
2788
2821
|
const compactPrompt = truncateTurnPrompt(prompt);
|
|
2789
|
-
const
|
|
2822
|
+
const label = queueLabel ?? currentStatus;
|
|
2823
|
+
const title = compactPrompt ? `${label}:${compactPrompt}` : label;
|
|
2790
2824
|
return `${reactionEmoji} ${title}`;
|
|
2791
2825
|
}
|
|
2792
2826
|
|
|
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import type { Logger } from "pino";
|
|
5
|
-
import { defaultSqlitePath } from "../config/paths.js";
|
|
5
|
+
import { defaultSqlitePath, inboundImageDirectory } from "../config/paths.js";
|
|
6
6
|
import type { AppConfig } from "../config/schema.js";
|
|
7
7
|
import { normalizeFeishuMarkdown } from "./FeishuMarkdown.js";
|
|
8
8
|
import { LOCAL_CARD_IMAGE_PATH } from "./LocalCardImage.js";
|
|
@@ -835,7 +835,7 @@ export class FeishuMessageClient implements FeishuOutbound {
|
|
|
835
835
|
if (bytes.byteLength > 20 * 1024 * 1024) throw new Error("Feishu image exceeds the 20 MiB input limit.");
|
|
836
836
|
|
|
837
837
|
const sqlitePath = this.config.storage?.sqlitePath ?? defaultSqlitePath();
|
|
838
|
-
const directory =
|
|
838
|
+
const directory = inboundImageDirectory(sqlitePath);
|
|
839
839
|
await mkdir(directory, { recursive: true });
|
|
840
840
|
const digest = createHash("sha256").update(`${messageId}:${imageKey}`).digest("hex");
|
|
841
841
|
const filePath = path.join(directory, `${digest}${imageExtension(contentType)}`);
|