@keyou007/agent-bot 0.1.27-alpha.3 → 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.
Files changed (156) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +77 -12
  3. package/README.zh.md +77 -12
  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 +1935 -232
  9. package/assets/workspace.css +360 -35
  10. package/assets/workspace.js +2115 -249
  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 +26 -14
  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 +40 -10
  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 +133 -117
  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 +23 -269
  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 +15 -0
  61. package/dist/local-files/WorkspaceImages.js.map +1 -0
  62. package/dist/local-files/WorkspacePage.js +20 -5
  63. package/dist/local-files/WorkspacePage.js.map +1 -1
  64. package/dist/local-files/WorkspaceSessions.js +881 -79
  65. package/dist/local-files/WorkspaceSessions.js.map +1 -1
  66. package/dist/local-files/WorkspaceTimeline.js +105 -0
  67. package/dist/local-files/WorkspaceTimeline.js.map +1 -0
  68. package/dist/presentation/OutboundRouter.js +13 -6
  69. package/dist/presentation/OutboundRouter.js.map +1 -1
  70. package/dist/presentation/TurnStateReducer.js +28 -21
  71. package/dist/presentation/TurnStateReducer.js.map +1 -1
  72. package/dist/proxy/ProxySessionController.js +229 -92
  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 +51 -12
  81. package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
  82. package/dist/scheduling/types.js +18 -4
  83. package/dist/scheduling/types.js.map +1 -1
  84. package/dist/state/StateStore.js +145 -19
  85. package/dist/state/StateStore.js.map +1 -1
  86. package/dist/state/TurnPreviewJournal.js +143 -36
  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 +20 -0
  101. package/dist/utils/promptAttachments.js.map +1 -0
  102. package/dist/utils/toolTimestamp.js +6 -0
  103. package/dist/utils/toolTimestamp.js.map +1 -0
  104. package/npm-shrinkwrap.json +2 -2
  105. package/package.json +1 -1
  106. package/skills/agent-bot/SKILL.md +23 -2
  107. package/src/cli/SelfUpdateObserver.ts +111 -0
  108. package/src/cli/SelfUpdateRunner.ts +271 -85
  109. package/src/cli/SelfUpdater.ts +53 -16
  110. package/src/cli/controlProtocol.ts +1 -0
  111. package/src/cli/help.ts +6 -0
  112. package/src/cli.ts +71 -5
  113. package/src/codex/CodexEventMapper.ts +25 -5
  114. package/src/codex/CodexRuntime.ts +4 -0
  115. package/src/feishu/CardRenderer.ts +48 -13
  116. package/src/feishu/ConsoleFeishuClient.ts +6 -1
  117. package/src/feishu/FeishuMarkdown.ts +2 -14
  118. package/src/feishu/FeishuMessageClient.ts +10 -0
  119. package/src/feishu/FeishuTurnPresenter.ts +22 -8
  120. package/src/feishu/types.ts +1 -0
  121. package/src/index.ts +47 -12
  122. package/src/local-files/DiagramPreview.ts +11 -6
  123. package/src/local-files/GitDiffPreview.ts +38 -10
  124. package/src/local-files/LiveMarkup.ts +103 -0
  125. package/src/local-files/LocalFileViewerServer.ts +120 -120
  126. package/src/local-files/MarkdownExport.ts +54 -0
  127. package/src/local-files/PreviewCodeFont.ts +12 -0
  128. package/src/local-files/PreviewSyntaxHighlight.ts +75 -0
  129. package/src/local-files/ToolCommandDisplay.ts +104 -0
  130. package/src/local-files/TurnPreviewPage.ts +23 -254
  131. package/src/local-files/WorkspaceFileEvents.ts +186 -0
  132. package/src/local-files/WorkspaceFiles.ts +72 -5
  133. package/src/local-files/WorkspaceImages.ts +10 -0
  134. package/src/local-files/WorkspacePage.ts +20 -5
  135. package/src/local-files/WorkspaceSessions.ts +811 -82
  136. package/src/local-files/WorkspaceTimeline.ts +109 -0
  137. package/src/presentation/OutboundRouter.ts +15 -4
  138. package/src/presentation/TurnStateReducer.ts +27 -18
  139. package/src/presentation/turnViewTypes.ts +2 -0
  140. package/src/proxy/ProxySessionController.ts +226 -77
  141. package/src/proxy/TaskMetadata.ts +81 -0
  142. package/src/runtime/types.ts +2 -1
  143. package/src/scheduling/ScheduleCards.ts +10 -4
  144. package/src/scheduling/ScheduleCommand.ts +4 -0
  145. package/src/scheduling/ScheduledTaskStore.ts +54 -9
  146. package/src/scheduling/types.ts +24 -4
  147. package/src/state/StateStore.ts +157 -20
  148. package/src/state/TurnPreviewJournal.ts +138 -34
  149. package/src/state/TurnToolText.ts +156 -0
  150. package/src/state/migrations.ts +4 -0
  151. package/src/supervision/SafeRestartNotifier.ts +9 -6
  152. package/src/terminal/TerminalPage.ts +5 -0
  153. package/src/updates/AutomaticUpdatePreparer.ts +52 -11
  154. package/src/updates/ManualUpdateController.ts +8 -3
  155. package/src/utils/promptAttachments.ts +24 -0
  156. package/src/utils/toolTimestamp.ts +5 -0
@@ -0,0 +1,109 @@
1
+ import type { ToolStatus } from "../runtime/types.js";
2
+ import { toolTimestamp } from "../utils/toolTimestamp.js";
3
+ import type { PreviewToolHeading } from "./ToolCommandDisplay.js";
4
+
5
+ export type WorkspaceActivity = { id: string } & (
6
+ | { kind: "assistant" | "user" | "system" | "reasoning"; text: string | null; images: unknown }
7
+ | { kind: "tool"; heading: PreviewToolHeading; toolKind: string | null; status: ToolStatus; startedAt?: number | null; completedAt?: number | null }
8
+ );
9
+ export interface WorkspaceReasoning {
10
+ id: string;
11
+ after: string | null;
12
+ parts: Array<{ index: number; text: string }>;
13
+ }
14
+ type WorkspaceTool = { id: string; title: string; kind: string; command?: true; status: ToolStatus; startedAt?: number; completedAt?: number };
15
+ interface ExecutionGroup {
16
+ kind: "execution";
17
+ id: string;
18
+ title: string;
19
+ tools: WorkspaceTool[];
20
+ }
21
+
22
+ const reasoningPart = /^reasoning:(.+):(\d+)$/u;
23
+ const isNativeReasoning = (activity: WorkspaceActivity) => activity.kind === "reasoning" && !activity.id.startsWith("commentary:");
24
+
25
+ function reasoningTitle(summary: string | null): string | undefined {
26
+ const line = summary?.trim().split(/\r?\n/u, 1)[0]?.replace(/^#{1,6}\s+/u, "").trim() ?? "";
27
+ const title = /^(?:\*\*(.+)\*\*|__(.+)__)$/u.exec(line);
28
+ if (!title && /^(?:\*\*|__|#{1,6}$)/u.test(line)) return undefined;
29
+ const text = title?.[1] ?? title?.[2] ?? line;
30
+ return text.length > 140 ? `${text.slice(0, 139)}…` : text || undefined;
31
+ }
32
+
33
+ function reasoningUpdates(activities: WorkspaceActivity[], saved: WorkspaceReasoning[]) {
34
+ const positions = new Map(activities.map((item, index) => [item.id, index]));
35
+ const markers = new Map<string, Map<number, { position: number; text: string | null }>>();
36
+ for (const [index, activity] of activities.entries()) {
37
+ if (activity.kind !== "reasoning" || !isNativeReasoning(activity)) continue;
38
+ const match = reasoningPart.exec(activity.id);
39
+ const id = match?.[1] ?? activity.id;
40
+ let parts = markers.get(id);
41
+ if (!parts) { parts = new Map(); markers.set(id, parts); }
42
+ const section = match ? Number(match[2]) : 0;
43
+ parts.set(section, { position: index, text: activity.text });
44
+ }
45
+ const result = new Map<number, { title?: string; excerpt: string }>();
46
+ const add = (index: number, text: string | null) => {
47
+ const excerpt = text?.trim().slice(0, 512);
48
+ if (!excerpt || /^[*_#\s]+$/u.test(excerpt)) return;
49
+ result.set(index, { title: reasoningTitle(excerpt) ?? result.get(index)?.title, excerpt });
50
+ };
51
+ for (const item of saved) {
52
+ const parts = markers.get(item.id);
53
+ markers.delete(item.id);
54
+ const anchor = item.after === null ? -1 : positions.get(item.after);
55
+ let position = anchor === undefined ? parts?.values().next().value?.position : anchor + 1;
56
+ if (position === undefined) continue;
57
+ const projected = new Map(item.parts.map((part) => [part.index, part.text]));
58
+ const sections = [...new Set([...projected.keys(), ...(parts?.keys() ?? [])])].sort((a, b) => a - b);
59
+ for (const section of sections) {
60
+ const marker = parts?.get(section);
61
+ const summary = projected.get(section);
62
+ const sectionPosition = marker?.position ?? position;
63
+ add(sectionPosition, summary?.trim() ? summary : marker?.text ?? null);
64
+ position = Math.max(position, sectionPosition);
65
+ }
66
+ }
67
+ for (const parts of markers.values()) for (const { position, text } of parts.values()) add(position, text);
68
+ return result;
69
+ }
70
+
71
+ /** Visible messages split execution stretches; native summary sections update the title in arrival order. */
72
+ export function workspaceTimeline(
73
+ activities: WorkspaceActivity[], saved: WorkspaceReasoning[], answer?: string | null, showThinking = false,
74
+ ) {
75
+ const reasoningAt = reasoningUpdates(activities, saved);
76
+ const rows: Array<ExecutionGroup | Exclude<WorkspaceActivity, { kind: "tool" }>> = [];
77
+ let group: ExecutionGroup | undefined, title: string | undefined, thinking: string | undefined;
78
+ for (let index = 0; index <= activities.length; index++) {
79
+ const next = reasoningAt.get(index);
80
+ if (next) {
81
+ thinking = next.excerpt;
82
+ if (next.title) { title = next.title; if (group) group.title = title; }
83
+ }
84
+ const activity = activities[index];
85
+ if (!activity) break;
86
+ if (isNativeReasoning(activity)) continue;
87
+ if (activity.kind === "tool") {
88
+ if (!group) {
89
+ group = { kind: "execution", id: `tools:${activity.id}`, title: title ?? "工具执行", tools: [] };
90
+ rows.push(group);
91
+ }
92
+ const { heading } = activity;
93
+ group.tools.push({ id: activity.id, title: heading.title, kind: heading.repl ? "repl" : activity.toolKind || "tool",
94
+ command: heading.command, status: activity.status,
95
+ startedAt: toolTimestamp(activity.startedAt), completedAt: toolTimestamp(activity.completedAt) });
96
+ } else {
97
+ const kind = activity.kind === "assistant" && /^(?:model-queue|context-compaction):/u.test(activity.id) ? "system"
98
+ : activity.kind === "reasoning" ? "assistant" : activity.kind;
99
+ if (kind === "assistant" && activity.text === answer && index === activities.length - 1) { group = title = thinking = undefined; continue; }
100
+ if (!activity.text?.trim() && !(kind === "user" && Array.isArray(activity.images) && activity.images.length)) continue;
101
+ rows.push({ ...activity, kind });
102
+ group = title = thinking = undefined;
103
+ }
104
+ }
105
+ if (showThinking && !answer && thinking && !group) {
106
+ rows.push({ kind: "reasoning", id: "workspace:thinking", text: thinking, images: null });
107
+ }
108
+ return rows;
109
+ }
@@ -20,8 +20,9 @@ export interface TurnPresenter {
20
20
  agentLabel?: string,
21
21
  model?: string,
22
22
  modelProvider?: string,
23
+ reasoningEffort?: string,
23
24
  ): void;
24
- updateSessionModel(sessionId: string, model?: string, modelProvider?: string): void;
25
+ updateSessionModel(sessionId: string, model?: string, modelProvider?: string, reasoningEffort?: string): void;
25
26
  updateSessionTitle(sessionId: string, taskTitle: string): void;
26
27
  unregisterSession(sessionId: string): void;
27
28
  startPendingTurn(
@@ -31,6 +32,7 @@ export interface TurnPresenter {
31
32
  replyTarget?: MessageReplyTarget,
32
33
  prompt?: string,
33
34
  localImagePaths?: string[],
35
+ promptRequestId?: string,
34
36
  ): Promise<string | undefined>;
35
37
  failPendingTurn(
36
38
  sessionId: string,
@@ -76,12 +78,13 @@ export class OutboundRouter {
76
78
  agentLabel?: string,
77
79
  model?: string,
78
80
  modelProvider?: string,
81
+ reasoningEffort?: string,
79
82
  ): void {
80
83
  const route = this.route(contextKey);
81
84
  this.sessionRoutes.set(sessionId, route);
82
85
  this.sessionContextKeys.set(sessionId, contextKey);
83
86
  route.presenter.registerSession(sessionId, contextKey, taskTitle, projectCwd, agentLabel);
84
- if (model || modelProvider) route.presenter.updateSessionModel(sessionId, model, modelProvider);
87
+ route.presenter.updateSessionModel(sessionId, model, modelProvider, reasoningEffort);
85
88
  }
86
89
 
87
90
  getSessionContextKey(sessionId: string): string | undefined {
@@ -100,8 +103,8 @@ export class OutboundRouter {
100
103
  this.sessionRoutes.get(sessionId)?.presenter.updateSessionTitle(sessionId, taskTitle);
101
104
  }
102
105
 
103
- updateSessionModel(sessionId: string, model?: string, modelProvider?: string): void {
104
- this.sessionRoutes.get(sessionId)?.presenter.updateSessionModel(sessionId, model, modelProvider);
106
+ updateSessionModel(sessionId: string, model?: string, modelProvider?: string, reasoningEffort?: string): void {
107
+ this.sessionRoutes.get(sessionId)?.presenter.updateSessionModel(sessionId, model, modelProvider, reasoningEffort);
105
108
  }
106
109
 
107
110
  unregisterSession(sessionId: string): void {
@@ -119,12 +122,14 @@ export class OutboundRouter {
119
122
  replyTarget?: MessageReplyTarget,
120
123
  prompt?: string,
121
124
  localImagePaths?: string[],
125
+ promptRequestId?: string,
122
126
  ): Promise<string | undefined> {
123
127
  const route = this.route(contextKey);
124
128
  this.sessionRoutes.set(sessionId, route);
125
129
  this.sessionContextKeys.set(sessionId, contextKey);
126
130
  if (replyTarget) this.sessionReplyTargets.set(sessionId, replyTarget);
127
131
  else this.sessionReplyTargets.delete(sessionId);
132
+ if (promptRequestId) return route.presenter.startPendingTurn(sessionId, contextKey, taskTitle, replyTarget, prompt, localImagePaths, promptRequestId);
128
133
  return route.presenter.startPendingTurn(sessionId, contextKey, taskTitle, replyTarget, prompt, ...(localImagePaths ? [localImagePaths] : []));
129
134
  }
130
135
 
@@ -273,6 +278,12 @@ export class OutboundRouter {
273
278
  return outbound.sendFile(contextKey, filePath);
274
279
  }
275
280
 
281
+ sendPromptImages(contextKey: string, text: string, files: string[], onPosting?: () => void): Promise<string | undefined> {
282
+ const outbound = this.route(contextKey).outbound;
283
+ if (!outbound.sendPromptImages) throw new Error("当前消息通道不支持发送图片附件。");
284
+ return outbound.sendPromptImages(contextKey, text, files, this.currentReplyTarget(contextKey), onPosting);
285
+ }
286
+
276
287
  sendMarkdown(contextKey: string, markdown: string): Promise<string | undefined> {
277
288
  const outbound = this.route(contextKey).outbound;
278
289
  const target = this.currentReplyTarget(contextKey);
@@ -2,6 +2,7 @@ import { TASK_NOTIFICATION_ACTIVITY_PREFIX, type AgentEvent, type ApprovalDecisi
2
2
  import { appendGeneratedImageMarkdown } from "../utils/generatedImageMarkdown.js";
3
3
  import type { MessageReplyTarget } from "../feishu/types.js";
4
4
  import { formatStorageSize } from "../utils/formatStorageSize.js";
5
+ import { toolTimestamp } from "../utils/toolTimestamp.js";
5
6
  import type { FileSummary, TurnActivity, TurnReasoningItem, TurnViewState } from "./turnViewTypes.js";
6
7
  import { turnReasoningItems } from "./turnReasoning.js";
7
8
  import { canApplyTurnEvent, modelQueueLabel } from "./turnStatus.js";
@@ -24,6 +25,7 @@ export function createTurnViewState(
24
25
  model?: string,
25
26
  promptImagePaths?: string[],
26
27
  modelProvider?: string,
28
+ reasoningEffort?: string,
27
29
  ): TurnViewState {
28
30
  return {
29
31
  sessionId,
@@ -31,6 +33,7 @@ export function createTurnViewState(
31
33
  agentLabel,
32
34
  model,
33
35
  modelProvider,
36
+ reasoningEffort,
34
37
  taskTitle,
35
38
  prompt,
36
39
  ...(promptImagePaths?.length ? { promptImagePaths: [...new Set(promptImagePaths)] } : {}),
@@ -59,7 +62,7 @@ export function hydrateTurnViewState(summary: TurnViewState, details: RemoteTurn
59
62
  ...summary,
60
63
  ...createTurnViewState(summary.sessionId, summary.turnId, details.startedAt ?? summary.startedAt,
61
64
  summary.taskTitle, summary.replyTarget, summary.projectCwd, summary.prompt,
62
- summary.agentLabel, summary.model, summary.promptImagePaths, summary.modelProvider),
65
+ summary.agentLabel, summary.model, summary.promptImagePaths, summary.modelProvider, summary.reasoningEffort),
63
66
  historyDetail: "full",
64
67
  historyDetailError: undefined,
65
68
  statusMessage: undefined,
@@ -82,7 +85,8 @@ export function hydrateTurnViewState(summary: TurnViewState, details: RemoteTurn
82
85
  }
83
86
  } else if (item.kind === "tool") {
84
87
  state = reduceToolUpdate(state, item.tool, undefined, true);
85
- state.activities = state.activities.map((a) => a.kind === "tool" && a.id === item.tool.id ? { ...a, tool: item.tool } : a);
88
+ state.activities = state.activities.map((a) => a.kind === "tool" && a.id === item.tool.id
89
+ ? { ...a, tool: { ...item.tool, startedAt: a.tool.startedAt, completedAt: a.tool.completedAt } } : a);
86
90
  } else if (item.kind === "reasoning") {
87
91
  for (const [summaryIndex, text] of item.summary.entries()) {
88
92
  state = reduceTurnEvent(state, { ...identity, type: "progress", text,
@@ -112,7 +116,7 @@ export function hydrateTurnViewState(summary: TurnViewState, details: RemoteTurn
112
116
  };
113
117
  }
114
118
 
115
- export function reduceTurnEvent(state: TurnViewState, event: AgentEvent, complete = false): TurnViewState {
119
+ export function reduceTurnEvent(state: TurnViewState, event: AgentEvent, complete = false, historical = false): TurnViewState {
116
120
  if (!canApplyTurnEvent(state, event)) return state;
117
121
  const endingQueue = state.modelQueue && (event.type === "turn_completed" || event.type === "turn_cancelled"
118
122
  || event.type === "turn_failed" || event.type === "turn_status_unknown");
@@ -120,7 +124,7 @@ export function reduceTurnEvent(state: TurnViewState, event: AgentEvent, complet
120
124
  type: "model_queue_updated", sessionId: state.sessionId, turnId: state.turnId, queue: { state: "ready" },
121
125
  reason: event.type === "turn_status_unknown" ? "disconnected" : "turn_ended",
122
126
  }) : state;
123
- const next = reduceEvent(input, event);
127
+ const next = reduceEvent(input, event, historical);
124
128
  if (!complete) return next;
125
129
  if (event.type === "turn_completed") next.finalResponse = event.finalResponse;
126
130
  if (event.type === "agent_text_delta") next.assistantText = state.assistantText + event.text;
@@ -140,15 +144,15 @@ export function reduceTurnEvent(state: TurnViewState, event: AgentEvent, complet
140
144
  }
141
145
  if (event.type === "tool_started" || event.type === "tool_updated") {
142
146
  next.activities = next.activities.map((a) => a.kind === "tool" && a.id === event.tool.id
143
- ? { ...a, tool: { ...a.tool, ...event.tool } } : a);
147
+ ? { ...a, tool: { ...a.tool, ...event.tool, startedAt: a.tool.startedAt, completedAt: a.tool.completedAt } } : a);
144
148
  const files = new Map(state.fileSummary.map((f) => [f.path, f]));
145
- for (const file of event.tool.files ?? []) files.set(file.path, file);
149
+ for (const { path, additions, deletions } of event.tool.files ?? []) files.set(path, { path, additions, deletions });
146
150
  next.fileSummary = [...files.values()];
147
151
  }
148
152
  return next;
149
153
  }
150
154
 
151
- function reduceEvent(state: TurnViewState, event: AgentEvent): TurnViewState {
155
+ function reduceEvent(state: TurnViewState, event: AgentEvent, historical: boolean): TurnViewState {
152
156
  if (event.sessionId !== state.sessionId || event.turnId !== state.turnId) return state;
153
157
 
154
158
  switch (event.type) {
@@ -330,7 +334,7 @@ function reduceEvent(state: TurnViewState, event: AgentEvent): TurnViewState {
330
334
  case "plan_updated":
331
335
  return { ...state, plan: event.steps.slice(0, 30).map((step) => ({ ...step, text: bound(step.text) })) };
332
336
  case "tool_started": {
333
- const tool = withToolTiming(state, event.tool);
337
+ const tool = withToolTiming(state, event.tool, historical);
334
338
  const bounded = boundTool(tool);
335
339
  const activityUpdate = upsertToolActivity(state.activities ?? [], bounded);
336
340
  const tracking = trackToolStatus(state, tool);
@@ -345,9 +349,9 @@ function reduceEvent(state: TurnViewState, event: AgentEvent): TurnViewState {
345
349
  };
346
350
  }
347
351
  case "tool_updated":
348
- return reduceToolUpdate(state, event.tool);
352
+ return reduceToolUpdate(state, event.tool, undefined, historical);
349
353
  case "tool_output_delta":
350
- return reduceToolOutputDelta(state, event.toolId, event.delta);
354
+ return reduceToolOutputDelta(state, event.toolId, event.delta, historical);
351
355
  case "approval_requested":
352
356
  return { ...state, status: event.request.automatic ? state.activeTool ? "tool_running" : "running" : "waiting_for_approval", approval: event.request,
353
357
  activities: [...state.activities.filter((a) => a.id !== approvalActivityId(event.turnId, event.request.id)), {
@@ -502,7 +506,7 @@ export function appendSteerMessage(state: TurnViewState, id: string, text: strin
502
506
  };
503
507
  }
504
508
 
505
- function reduceToolOutputDelta(state: TurnViewState, toolId: string, delta: string): TurnViewState {
509
+ function reduceToolOutputDelta(state: TurnViewState, toolId: string, delta: string, historical: boolean): TurnViewState {
506
510
  if (!delta) return state;
507
511
  const tool = findTool(state, toolId);
508
512
  if (!tool || tool.status !== "running" || tool.kind !== "command") return state;
@@ -510,7 +514,7 @@ function reduceToolOutputDelta(state: TurnViewState, toolId: string, delta: stri
510
514
  return reduceToolUpdate(state, {
511
515
  ...tool,
512
516
  output: appendBoundedOutput(tool.output, delta),
513
- }, fullOutput);
517
+ }, fullOutput, historical);
514
518
  }
515
519
 
516
520
  function findTool(state: TurnViewState, toolId: string): ToolState | undefined {
@@ -522,14 +526,16 @@ function findTool(state: TurnViewState, toolId: string): ToolState | undefined {
522
526
  ?? state.completedTools.find((tool) => tool.id === toolId);
523
527
  }
524
528
 
525
- function withToolTiming(state: TurnViewState, tool: ToolState): ToolState {
529
+ function withToolTiming(state: TurnViewState, tool: ToolState, historical: boolean): ToolState {
526
530
  const previous = findTool(state, tool.id);
527
- const now = Date.now();
528
- const startedAt = tool.startedAt ?? previous?.startedAt ?? tool.completedAt ?? now;
531
+ const now = historical ? undefined : Date.now();
532
+ const completedAt = toolTimestamp(tool.completedAt);
533
+ const startedAt = toolTimestamp(tool.startedAt) ?? toolTimestamp(previous?.startedAt)
534
+ ?? (historical ? undefined : completedAt ?? now);
529
535
  return {
530
536
  ...tool,
531
537
  startedAt,
532
- completedAt: tool.status === "running" ? tool.completedAt : tool.completedAt ?? now,
538
+ completedAt: tool.status === "running" ? completedAt : completedAt ?? toolTimestamp(previous?.completedAt) ?? now,
533
539
  };
534
540
  }
535
541
 
@@ -540,7 +546,7 @@ function appendBoundedOutput(previous: string | undefined, delta: string): strin
540
546
  }
541
547
 
542
548
  function reduceToolUpdate(state: TurnViewState, tool: ToolState, fullOutput?: string, historical = false): TurnViewState {
543
- if (!historical) tool = withToolTiming(state, tool);
549
+ tool = withToolTiming(state, tool, historical);
544
550
  const nextFullOutput = fullOutput ?? tool.output;
545
551
  const fullToolOutputs = nextFullOutput === undefined
546
552
  ? state.fullToolOutputs
@@ -874,7 +880,10 @@ export function compactTurnView(state: TurnViewState): TurnViewState {
874
880
  completedTools: state.completedTools.slice(-20).map(boundTool), failedTools: state.failedTools.slice(-5).map(boundTool),
875
881
  fileSummary: state.fileSummary.slice(-30),
876
882
  activitiesTruncated: state.activitiesTruncated || state.activities.length > 80,
877
- reasoningItems: [], fullToolOutputs: {}, fullToolErrors: {},
883
+ // Keep only the reasoning anchors and summary headings in the hot snapshot; the body stays in the journal.
884
+ reasoningItems: state.reasoningItems?.slice(-32).map((item) => ({
885
+ ...item, summary: item.summary.slice(0, 4).map((text) => text?.slice(0, 512) ?? ""), content: [],
886
+ })) ?? [], fullToolOutputs: {}, fullToolErrors: {},
878
887
  toolStatuses: Object.fromEntries(Object.entries(state.toolStatuses ?? {}).filter(([id]) => ids.has(id))),
879
888
  };
880
889
  }
@@ -50,9 +50,11 @@ export interface TurnViewState {
50
50
  agentLabel?: string;
51
51
  model?: string;
52
52
  modelProvider?: string;
53
+ reasoningEffort?: string;
53
54
  taskTitle?: string;
54
55
  prompt?: string;
55
56
  promptImagePaths?: string[];
57
+ promptRequestId?: string;
56
58
  projectCwd?: string;
57
59
  replyTarget?: MessageReplyTarget;
58
60
  status: TurnViewStatus;