@kafca/agentdock 0.1.43 → 0.1.44

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 (59) hide show
  1. package/README.md +6 -0
  2. package/dist/renderer/assets/{Badge-CbG6yRSm.js → Badge-Qk9qHovH.js} +1 -1
  3. package/dist/renderer/assets/{Chat-BvNNWGGX.js → Chat-BK-fm0Xr.js} +1 -1
  4. package/dist/renderer/assets/{ChatMarkdown-Ct-PvJB8.js → ChatMarkdown-BKdW8OON.js} +1 -1
  5. package/dist/renderer/assets/{Config-lQX2qVVV.js → Config-B93CQGvY.js} +1 -1
  6. package/dist/renderer/assets/{CronList-Dj_3muVG.js → CronList-Z3TvSRKP.js} +1 -1
  7. package/dist/renderer/assets/{Dashboard-eh_RhGYb.js → Dashboard-Ch3QkWwf.js} +2 -2
  8. package/dist/renderer/assets/{EmptyState-Bn2Qh14U.js → EmptyState-kD9yAwtw.js} +1 -1
  9. package/dist/renderer/assets/{KnowledgeDetail-Bsz6Ou41.js → KnowledgeDetail-BAMCLrjz.js} +1 -1
  10. package/dist/renderer/assets/{KnowledgeHome-Cgj4XFXn.js → KnowledgeHome-ChvjOfrc.js} +1 -1
  11. package/dist/renderer/assets/{Logs-Dp-NF6GN.js → Logs-Cv0nth3j.js} +1 -1
  12. package/dist/renderer/assets/{Modal-B6YPPBN6.js → Modal-DwY4lecS.js} +1 -1
  13. package/dist/renderer/assets/{MonitorList-xEZWg460.js → MonitorList-JEvMoWUm.js} +1 -1
  14. package/dist/renderer/assets/{Page-Bn7RjGOS.js → Page-CnB9ePsb.js} +1 -1
  15. package/dist/renderer/assets/{ProjectDetail-Cv_jIE61.js → ProjectDetail-DJa3sMmU.js} +1 -1
  16. package/dist/renderer/assets/{ProjectList-BDk5_gqY.js → ProjectList-D6CXumR_.js} +1 -1
  17. package/dist/renderer/assets/{Select-xshfMIEQ.js → Select-zfoksLGB.js} +1 -1
  18. package/dist/renderer/assets/{SessionChat-BkHy90z3.js → SessionChat-DUTh4WoM.js} +1 -1
  19. package/dist/renderer/assets/{SessionList-BZyXT92L.js → SessionList-D9o-lUst.js} +1 -1
  20. package/dist/renderer/assets/{ThreadChat-DUOIyXrS.js → ThreadChat-BYXlT-Kc.js} +1 -1
  21. package/dist/renderer/assets/{Workspace-Dl80fNEC.js → Workspace-BrhSwRQ-.js} +1 -1
  22. package/dist/renderer/assets/{arrow-left-C54ZI-AS.js → arrow-left-CNEAuElg.js} +1 -1
  23. package/dist/renderer/assets/{book-open-Dl7GO0zn.js → book-open-BNJMhNI-.js} +1 -1
  24. package/dist/renderer/assets/{check-CiqgtrOL.js → check-BnclClRU.js} +1 -1
  25. package/dist/renderer/assets/{chevron-down-DTL2OuVh.js → chevron-down-Bh53e0O-.js} +1 -1
  26. package/dist/renderer/assets/{circle-DaVKfa3P.js → circle-ClZTWCWO.js} +1 -1
  27. package/dist/renderer/assets/{desktop-jaAiayNB.js → desktop-C5vBT0yM.js} +1 -1
  28. package/dist/renderer/assets/{funnel-CrmnLMJI.js → funnel-_5hsz0xI.js} +1 -1
  29. package/dist/renderer/assets/{heart-BMfQI7y_.js → heart-u4Q1aOqj.js} +1 -1
  30. package/dist/renderer/assets/{index-HPNb1zfx.js → index-B36eowj-.js} +2 -2
  31. package/dist/renderer/assets/{index-nreiKY1f.js → index-BNFx4uYv.js} +1 -1
  32. package/dist/renderer/assets/{pencil-wTQ4l465.js → pencil-DLh9QNmT.js} +1 -1
  33. package/dist/renderer/assets/{play-BK--MXmw.js → play-BDTk9Scm.js} +1 -1
  34. package/dist/renderer/assets/{plug-BIx9fjip.js → plug-BG0JHW6B.js} +1 -1
  35. package/dist/renderer/assets/{plus-Dn7JFWQ8.js → plus-BSc8POsz.js} +1 -1
  36. package/dist/renderer/assets/projects-DwfZwxDW.js +1 -0
  37. package/dist/renderer/assets/{save-CC3zOSWb.js → save-D5AO_G6a.js} +1 -1
  38. package/dist/renderer/assets/{search-CDTy9Czu.js → search-CniPk7Ey.js} +1 -1
  39. package/dist/renderer/assets/{server-DtQk3t2a.js → server-GsXyQAZm.js} +1 -1
  40. package/dist/renderer/assets/{session-utils-4ep5D66T.js → session-utils-BDxzgTBC.js} +1 -1
  41. package/dist/renderer/assets/{sessions-Dor1LteH.js → sessions-CLcKA1Tt.js} +1 -1
  42. package/dist/renderer/assets/{shield-check-Cz2LpU6r.js → shield-check-4i0E3hmf.js} +1 -1
  43. package/dist/renderer/assets/{trash-2-C2EmWFZV.js → trash-2-DhtOCsO5.js} +1 -1
  44. package/dist/renderer/assets/{user-I8B-cs5A.js → user-BtC_pVXV.js} +1 -1
  45. package/dist/renderer/assets/{wifi-off-CPevTQJn.js → wifi-off-BHPzPY_B.js} +1 -1
  46. package/dist/renderer/index.html +1 -1
  47. package/dist-electron/services/local-ai-core/src/channel/lark/config.js +2 -0
  48. package/dist-electron/services/local-ai-core/src/channel/lark/inbound.js +114 -0
  49. package/dist-electron/services/local-ai-core/src/channel/lark/local-core-lark-gateway.js +52 -65
  50. package/dist-electron/services/local-ai-core/src/channel/shared/thread-routing.js +34 -0
  51. package/dist-electron/services/local-ai-core/src/channel/weixin/local-core-weixin-gateway.js +12 -18
  52. package/dist-electron/tests/integration/channel-gateways.test.js +32 -0
  53. package/dist-electron/tests/integration/lark-gateway.test.js +1918 -0
  54. package/dist-electron/tests/integration/local-core-acp-progress.test.js +1772 -0
  55. package/dist-electron/tests/integration/local-core-refactor.test.js +0 -4544
  56. package/dist-electron/tests/integration/local-core-routes.test.js +204 -0
  57. package/dist-electron/tests/integration/weixin-gateway.test.js +927 -0
  58. package/package.json +1 -1
  59. package/dist/renderer/assets/projects-brJZgwEJ.js +0 -1
@@ -0,0 +1,1772 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_test_1 = __importDefault(require("node:test"));
7
+ const strict_1 = __importDefault(require("node:assert/strict"));
8
+ const node_fs_1 = require("node:fs");
9
+ const node_os_1 = require("node:os");
10
+ const node_path_1 = require("node:path");
11
+ const local_core_acp_store_js_1 = require("../../services/local-ai-core/src/acp/local-core-acp-store.js");
12
+ const local_core_acp_turn_coordinator_js_1 = require("../../services/local-ai-core/src/acp/local-core-acp-turn-coordinator.js");
13
+ const local_core_acp_progress_js_1 = require("../../services/local-ai-core/src/acp/local-core-acp-progress.js");
14
+ const local_core_acp_permission_lifecycle_js_1 = require("../../services/local-ai-core/src/acp/local-core-acp-permission-lifecycle.js");
15
+ const workspace_acp_permissions_js_1 = require("../../services/local-ai-core/src/acp/workspace-acp-permissions.js");
16
+ (0, node_test_1.default)('ACP tool call update is emitted with its pending tool name', () => {
17
+ const appended = [];
18
+ const emitted = [];
19
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
20
+ appendMessage: (_threadId, _role, content, kind) => appended.push({ content, kind }),
21
+ emitBridge: (event) => emitted.push(event),
22
+ updateRunStatus: () => { },
23
+ sendRaw: () => true,
24
+ });
25
+ const session = {
26
+ threadId: 'thread-1',
27
+ bridgeSessionKey: 'session:thread-1',
28
+ currentRunId: 'run-1',
29
+ currentTurn: {
30
+ runId: 'run-1',
31
+ replyCtx: 'run-1',
32
+ previewHandle: 'preview-1',
33
+ assistantText: '',
34
+ typingStarted: true,
35
+ previewStarted: false,
36
+ permission: null,
37
+ },
38
+ loadReplayMode: false,
39
+ schedulerJobCreatedByRun: new Map(),
40
+ };
41
+ coordinator.handleAgentNotification(session, {
42
+ method: 'session/update',
43
+ params: {
44
+ update: {
45
+ sessionUpdate: 'tool_call',
46
+ title: 'Terminal',
47
+ },
48
+ },
49
+ });
50
+ coordinator.handleAgentNotification(session, {
51
+ method: 'session/update',
52
+ params: {
53
+ update: {
54
+ sessionUpdate: 'tool_call_update',
55
+ title: "ls ~/Desktop - List files on the user's desktop",
56
+ status: 'running',
57
+ },
58
+ },
59
+ });
60
+ strict_1.default.deepEqual(appended, [
61
+ {
62
+ content: "🔧 Terminal: ls ~/Desktop - List files on the user's desktop - running",
63
+ kind: 'progress',
64
+ },
65
+ ]);
66
+ strict_1.default.equal(emitted.length, 1);
67
+ strict_1.default.equal(emitted[0]?.content, appended[0]?.content);
68
+ });
69
+ (0, node_test_1.default)('ACP permission normalization treats allow_all as allow all', () => {
70
+ strict_1.default.equal((0, workspace_acp_permissions_js_1.normalizePermissionAction)('allow_all'), 'allow all');
71
+ strict_1.default.equal((0, workspace_acp_permissions_js_1.normalizePermissionAction)('allow_always'), 'allow all');
72
+ strict_1.default.equal((0, workspace_acp_permissions_js_1.normalizePermissionAction)('always'), 'allow all');
73
+ strict_1.default.equal((0, workspace_acp_permissions_js_1.normalizePermissionAction)('allow_once'), 'allow');
74
+ });
75
+ (0, node_test_1.default)('ACP permission normalization preserves always-allow option semantics', () => {
76
+ strict_1.default.equal((0, workspace_acp_permissions_js_1.normalizePermissionOptionAction)({
77
+ optionId: 'approve',
78
+ name: 'Always allow',
79
+ kind: 'allow',
80
+ }), 'allow all');
81
+ strict_1.default.equal((0, workspace_acp_permissions_js_1.normalizePermissionOptionAction)({
82
+ optionId: 'allow-all-tools',
83
+ name: '始终允许',
84
+ kind: 'allow',
85
+ }), 'allow all');
86
+ strict_1.default.equal((0, workspace_acp_permissions_js_1.normalizePermissionOptionAction)({
87
+ optionId: 'allow_once',
88
+ name: 'Allow once',
89
+ kind: 'allow',
90
+ }), 'allow');
91
+ });
92
+ (0, node_test_1.default)('ACP permission lifecycle parses actionable options and fallback prompt content', () => {
93
+ const options = (0, local_core_acp_permission_lifecycle_js_1.parsePermissionOptions)([
94
+ { optionId: 'approve-once', name: 'Allow once', kind: 'allow' },
95
+ { optionId: 'approve-always', name: 'Always allow', kind: 'allow' },
96
+ { optionId: '', name: 'missing id', kind: 'reject' },
97
+ ]);
98
+ strict_1.default.deepEqual(options, [
99
+ {
100
+ optionId: 'approve-once',
101
+ name: 'Allow once',
102
+ kind: 'allow',
103
+ normalizedAction: 'allow',
104
+ },
105
+ {
106
+ optionId: 'approve-always',
107
+ name: 'Always allow',
108
+ kind: 'allow',
109
+ normalizedAction: 'allow all',
110
+ },
111
+ ]);
112
+ strict_1.default.deepEqual((0, local_core_acp_permission_lifecycle_js_1.createRunningPermissionRequest)({
113
+ requestId: 42,
114
+ toolTitle: 'Terminal: lac scheduler add --cron "* * * * *"',
115
+ options,
116
+ approvalId: 'approval-1',
117
+ }), {
118
+ requestId: 42,
119
+ approvalId: 'approval-1',
120
+ toolTitle: 'Terminal: lac scheduler add --cron "* * * * *"',
121
+ isSchedulerAdd: true,
122
+ options,
123
+ });
124
+ strict_1.default.deepEqual((0, local_core_acp_permission_lifecycle_js_1.createPermissionApprovalInput)({
125
+ threadId: 'thread-1',
126
+ runId: 'run-1',
127
+ toolTitle: 'Terminal: npm test',
128
+ options,
129
+ }), {
130
+ threadId: 'thread-1',
131
+ runId: 'run-1',
132
+ title: 'Approve Terminal: npm test',
133
+ description: 'Terminal: npm test',
134
+ command: 'Terminal: npm test',
135
+ options,
136
+ });
137
+ strict_1.default.equal((0, local_core_acp_permission_lifecycle_js_1.isSchedulerAddCommand)('Terminal: lac scheduler add --cron "* * * * *"'), true);
138
+ strict_1.default.match((0, local_core_acp_permission_lifecycle_js_1.createPermissionPrompt)('Terminal: npm test'), /Terminal: npm test/);
139
+ strict_1.default.match((0, local_core_acp_permission_lifecycle_js_1.createPermissionPrompt)('Terminal: npm test'), /allow all \/ allow \/ deny/);
140
+ });
141
+ (0, node_test_1.default)('ACP permission lifecycle writes pending permission state and tool detail together', () => {
142
+ const permissionRequest = (0, local_core_acp_permission_lifecycle_js_1.createRunningPermissionRequest)({
143
+ requestId: 42,
144
+ toolTitle: 'Terminal: npm test',
145
+ options: [],
146
+ approvalId: 'approval-1',
147
+ });
148
+ const toolCall = {
149
+ key: 'call-1',
150
+ title: 'Terminal',
151
+ messageId: 'run-1-tool-1',
152
+ sequence: 1,
153
+ emitted: false,
154
+ };
155
+ const currentTurn = {
156
+ runId: 'run-1',
157
+ replyCtx: 'run-1',
158
+ previewHandle: 'preview-1',
159
+ thoughtPreviewHandle: 'thought-preview-1',
160
+ thoughtMessageId: 'run-1-thought',
161
+ assistantText: '',
162
+ thoughtText: '',
163
+ typingStarted: true,
164
+ previewStarted: false,
165
+ thoughtPreviewStarted: false,
166
+ permission: null,
167
+ pendingToolCalls: { 'call-1': toolCall },
168
+ pendingToolCallOrder: ['call-1'],
169
+ activeToolCallKey: 'call-1',
170
+ };
171
+ const session = {
172
+ currentTurn,
173
+ pendingPermissionByRun: new Map(),
174
+ };
175
+ const synced = [];
176
+ (0, local_core_acp_permission_lifecycle_js_1.applyPendingPermissionRequest)({
177
+ session,
178
+ runId: 'run-1',
179
+ permissionRequest,
180
+ resolveFallbackToolCall: () => toolCall,
181
+ syncLegacyPendingToolCall: (_turn, nextToolCall) => synced.push(nextToolCall?.detail || ''),
182
+ });
183
+ strict_1.default.equal(session.pendingPermissionByRun.get('run-1'), permissionRequest);
184
+ strict_1.default.equal(currentTurn.permission, permissionRequest);
185
+ strict_1.default.equal(currentTurn.pendingToolCallDetail, 'Terminal: npm test');
186
+ strict_1.default.equal(toolCall.detail, 'Terminal: npm test');
187
+ strict_1.default.deepEqual(synced, ['Terminal: npm test']);
188
+ });
189
+ (0, node_test_1.default)('ACP pending permission is projected into refreshed thread detail payloads', () => {
190
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
191
+ emitBridge: () => { },
192
+ appendMessage: () => { },
193
+ updateRunStatus: () => { },
194
+ sendRaw: () => true,
195
+ });
196
+ const permissionRequest = (0, local_core_acp_permission_lifecycle_js_1.createRunningPermissionRequest)({
197
+ requestId: 42,
198
+ toolTitle: 'Terminal: npm test',
199
+ options: (0, local_core_acp_permission_lifecycle_js_1.parsePermissionOptions)([
200
+ { optionId: 'approve-once', name: 'Allow once', kind: 'allow' },
201
+ { optionId: 'reject', name: 'Deny', kind: 'reject' },
202
+ ]),
203
+ approvalId: 'approval-1',
204
+ });
205
+ const session = {
206
+ currentRunId: 'run-1',
207
+ pendingPermissionByRun: new Map([['run-1', permissionRequest]]),
208
+ };
209
+ const detail = {
210
+ messages: [
211
+ {
212
+ id: 'permission-message',
213
+ role: 'assistant',
214
+ content: '等待工具确认',
215
+ },
216
+ ],
217
+ };
218
+ const pending = coordinator.getPendingPermissionRequest(session, detail);
219
+ strict_1.default.ok(pending);
220
+ strict_1.default.equal(pending.id, 'permission-message');
221
+ strict_1.default.equal(pending.content, '等待工具确认');
222
+ strict_1.default.equal(pending.actionReplyCtx, 'run-1');
223
+ strict_1.default.equal(pending.actionMode, 'permission');
224
+ strict_1.default.equal(pending.actionInteractive, true);
225
+ strict_1.default.deepEqual(pending.actions.flat().map((action) => action.data), ['allow', 'deny']);
226
+ });
227
+ (0, node_test_1.default)('ACP progress projection extracts tool output and formats durable progress content', () => {
228
+ strict_1.default.equal((0, local_core_acp_progress_js_1.extractToolCallKey)({ tool_call_id: ' call-a ' }), 'call-a');
229
+ strict_1.default.equal((0, local_core_acp_progress_js_1.extractToolCallKey)({ invocationId: 42 }), '42');
230
+ strict_1.default.equal((0, local_core_acp_progress_js_1.extractToolCallKey)({ id: ' ' }), '');
231
+ strict_1.default.equal((0, local_core_acp_progress_js_1.extractToolUpdateContent)([
232
+ { type: 'content', content: { type: 'text', text: 'first line' } },
233
+ { type: 'content', content: { type: 'image', text: 'ignored' } },
234
+ { type: 'content', content: { type: 'text', text: 'second line' } },
235
+ ]), 'first line\nsecond line');
236
+ strict_1.default.equal((0, local_core_acp_progress_js_1.formatToolProgressMessage)({
237
+ toolName: 'Terminal',
238
+ title: 'npm test',
239
+ status: 'completed',
240
+ content: 'ok',
241
+ }), '🔧 Terminal: npm test - completed - ok');
242
+ strict_1.default.equal((0, local_core_acp_progress_js_1.resolveToolUpdateDisplayTitle)({
243
+ title: 'Tool update',
244
+ status: 'completed',
245
+ priorDetail: 'npm test',
246
+ }), 'npm test');
247
+ strict_1.default.equal((0, local_core_acp_progress_js_1.isEmptyRunningToolUpdate)({
248
+ title: 'Tool update',
249
+ status: 'running',
250
+ content: '',
251
+ }), true);
252
+ });
253
+ (0, node_test_1.default)('ACP progress projection applies assistant and thought chunks with bridge metadata', () => {
254
+ const currentTurn = {
255
+ runId: 'run-1',
256
+ previewHandle: 'preview-1',
257
+ thoughtPreviewHandle: 'thought-preview-1',
258
+ thoughtMessageId: 'run-1-thought',
259
+ assistantText: '',
260
+ thoughtText: '',
261
+ previewStarted: false,
262
+ thoughtPreviewStarted: false,
263
+ };
264
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.applyAssistantMessageChunk)(currentTurn, 'hello'), {
265
+ bridgeType: 'preview_start',
266
+ previewHandle: 'preview-1',
267
+ content: 'hello',
268
+ bridgeKind: 'assistant',
269
+ });
270
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.applyAssistantMessageChunk)(currentTurn, ' world'), {
271
+ bridgeType: 'update_message',
272
+ previewHandle: 'preview-1',
273
+ content: 'hello world',
274
+ bridgeKind: 'assistant',
275
+ });
276
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.applyThoughtChunk)(currentTurn, '先理解'), {
277
+ bridgeType: 'preview_start',
278
+ previewHandle: 'thought-preview-1',
279
+ messageId: 'run-1-thought',
280
+ content: '先理解',
281
+ bridgeKind: 'thought',
282
+ });
283
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.applyThoughtChunk)(currentTurn, ',再修改'), {
284
+ bridgeType: 'update_message',
285
+ previewHandle: 'thought-preview-1',
286
+ messageId: 'run-1-thought',
287
+ content: '先理解,再修改',
288
+ bridgeKind: 'thought',
289
+ });
290
+ strict_1.default.equal(currentTurn.thoughtText, '先理解,再修改');
291
+ });
292
+ (0, node_test_1.default)('ACP thought chunks merge provider snapshots without duplicating text', () => {
293
+ const currentTurn = {
294
+ runId: 'run-1',
295
+ thoughtPreviewHandle: 'thought-preview-1',
296
+ thoughtMessageId: 'run-1-thought',
297
+ thoughtText: '',
298
+ thoughtPreviewStarted: false,
299
+ };
300
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.applyThoughtChunk)(currentTurn, 'The user wants to see their desktop files.'), {
301
+ bridgeType: 'preview_start',
302
+ previewHandle: 'thought-preview-1',
303
+ messageId: 'run-1-thought',
304
+ content: 'The user wants to see their desktop files.',
305
+ bridgeKind: 'thought',
306
+ });
307
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.applyThoughtChunk)(currentTurn, 'The user wants to see their desktop files. Let me show them.'), {
308
+ bridgeType: 'update_message',
309
+ previewHandle: 'thought-preview-1',
310
+ messageId: 'run-1-thought',
311
+ content: 'The user wants to see their desktop files. Let me show them.',
312
+ bridgeKind: 'thought',
313
+ });
314
+ strict_1.default.equal(currentTurn.thoughtText, 'The user wants to see their desktop files. Let me show them.');
315
+ });
316
+ (0, node_test_1.default)('ACP thought segment close starts a new streaming preview for web and app', () => {
317
+ const currentTurn = {
318
+ runId: 'run-1',
319
+ thoughtPreviewHandle: 'thought-preview-1',
320
+ thoughtMessageId: 'run-1-thought-1',
321
+ thoughtText: '',
322
+ thoughtSequence: 1,
323
+ thoughtPreviewStarted: false,
324
+ };
325
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.applyThoughtChunk)(currentTurn, 'first thought'), {
326
+ bridgeType: 'preview_start',
327
+ previewHandle: 'thought-preview-1',
328
+ messageId: 'run-1-thought-1',
329
+ content: 'first thought',
330
+ bridgeKind: 'thought',
331
+ });
332
+ (0, local_core_acp_progress_js_1.closeThoughtSegment)(currentTurn);
333
+ strict_1.default.equal(currentTurn.thoughtText, '');
334
+ strict_1.default.equal(currentTurn.thoughtPreviewStarted, false);
335
+ strict_1.default.equal(currentTurn.thoughtMessageId, 'run-1-thought-2');
336
+ strict_1.default.equal(currentTurn.thoughtPreviewHandle, 'run-1-thought-preview-2');
337
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.applyThoughtChunk)(currentTurn, 'second thought'), {
338
+ bridgeType: 'preview_start',
339
+ previewHandle: 'run-1-thought-preview-2',
340
+ messageId: 'run-1-thought-2',
341
+ content: 'second thought',
342
+ bridgeKind: 'thought',
343
+ });
344
+ });
345
+ (0, node_test_1.default)('ACP progress projection registers pending tool calls in order', () => {
346
+ const currentTurn = {
347
+ toolCallSequence: 0,
348
+ pendingToolCalls: {},
349
+ pendingToolCallOrder: [],
350
+ };
351
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.registerPendingToolCall)({
352
+ currentTurn,
353
+ runId: 'run-1',
354
+ update: { id: 'call-a', title: 'Terminal', rawInput: { command: 'npm test' } },
355
+ }), {
356
+ key: 'call-a',
357
+ title: 'Terminal',
358
+ messageId: 'run-1-tool-1',
359
+ input: { command: 'npm test' },
360
+ sequence: 1,
361
+ emitted: false,
362
+ });
363
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.registerPendingToolCall)({
364
+ currentTurn,
365
+ runId: 'run-1',
366
+ update: { title: 'Read' },
367
+ }), {
368
+ key: 'sequence:2',
369
+ title: 'Read',
370
+ messageId: 'run-1-tool-2',
371
+ sequence: 2,
372
+ emitted: false,
373
+ });
374
+ strict_1.default.deepEqual(currentTurn.pendingToolCallOrder, ['call-a', 'sequence:2']);
375
+ strict_1.default.equal(currentTurn.activeToolCallKey, 'sequence:2');
376
+ strict_1.default.deepEqual((0, local_core_acp_progress_js_1.getToolCallsInOrder)(currentTurn).map((toolCall) => toolCall.key), ['call-a', 'sequence:2']);
377
+ strict_1.default.equal((0, local_core_acp_progress_js_1.resolveFallbackToolCall)(currentTurn)?.key, 'sequence:2');
378
+ strict_1.default.equal((0, local_core_acp_progress_js_1.resolveToolCallForUpdate)(currentTurn, { id: 'call-a' })?.key, 'call-a');
379
+ strict_1.default.equal(currentTurn.activeToolCallKey, 'call-a');
380
+ (0, local_core_acp_progress_js_1.syncLegacyPendingToolCall)(currentTurn, currentTurn.pendingToolCalls['call-a']);
381
+ strict_1.default.equal(currentTurn.pendingToolCallTitle, 'Terminal');
382
+ strict_1.default.equal(currentTurn.pendingToolCallId, 'run-1-tool-1');
383
+ (0, local_core_acp_progress_js_1.deletePendingToolCall)(currentTurn, 'call-a');
384
+ strict_1.default.deepEqual(currentTurn.pendingToolCallOrder, ['sequence:2']);
385
+ strict_1.default.equal(currentTurn.activeToolCallKey, undefined);
386
+ });
387
+ (0, node_test_1.default)('ACP progress projection ignores empty plan entries', () => {
388
+ strict_1.default.equal((0, local_core_acp_progress_js_1.formatPlanProgress)([
389
+ { content: '检查消息流' },
390
+ { content: ' ' },
391
+ { content: '修复持久化' },
392
+ ]), '检查消息流 | 修复持久化');
393
+ strict_1.default.equal((0, local_core_acp_progress_js_1.formatPlanProgress)([{ content: '' }]), '');
394
+ });
395
+ (0, node_test_1.default)('ACP tool call running and completed updates share one message id', () => {
396
+ const upserted = [];
397
+ const emitted = [];
398
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
399
+ appendMessage: () => strict_1.default.fail('tool updates should be upserted'),
400
+ upsertMessage: (_threadId, id, _role, content, kind) => upserted.push({ id, content, kind }),
401
+ emitBridge: (event) => emitted.push(event),
402
+ updateRunStatus: () => { },
403
+ sendRaw: () => true,
404
+ });
405
+ const session = {
406
+ threadId: 'thread-1',
407
+ bridgeSessionKey: 'session:thread-1',
408
+ currentRunId: 'run-1',
409
+ currentTurn: {
410
+ runId: 'run-1',
411
+ replyCtx: 'run-1',
412
+ previewHandle: 'preview-1',
413
+ assistantText: '',
414
+ typingStarted: true,
415
+ previewStarted: false,
416
+ permission: null,
417
+ },
418
+ loadReplayMode: false,
419
+ schedulerJobCreatedByRun: new Map(),
420
+ };
421
+ coordinator.handleAgentNotification(session, {
422
+ method: 'session/update',
423
+ params: {
424
+ update: {
425
+ sessionUpdate: 'tool_call',
426
+ title: 'Find',
427
+ },
428
+ },
429
+ });
430
+ coordinator.handleAgentNotification(session, {
431
+ method: 'session/update',
432
+ params: {
433
+ update: {
434
+ sessionUpdate: 'tool_call_update',
435
+ title: "Find `src/pages/Threads/**/*`",
436
+ status: 'running',
437
+ },
438
+ },
439
+ });
440
+ coordinator.handleAgentNotification(session, {
441
+ method: 'session/update',
442
+ params: {
443
+ update: {
444
+ sessionUpdate: 'tool_call_update',
445
+ title: 'Tool update',
446
+ status: 'completed',
447
+ content: [
448
+ {
449
+ type: 'content',
450
+ content: {
451
+ type: 'text',
452
+ text: 'src/pages/Threads/ThreadChat.tsx',
453
+ },
454
+ },
455
+ ],
456
+ },
457
+ },
458
+ });
459
+ strict_1.default.equal(upserted.length, 2);
460
+ strict_1.default.equal(upserted[0]?.id, upserted[1]?.id);
461
+ strict_1.default.equal(upserted[0]?.id, 'run-1-tool-1');
462
+ strict_1.default.equal(upserted[0]?.content, "🔧 Find: Find `src/pages/Threads/**/*` - running");
463
+ strict_1.default.equal(upserted[1]?.content, '🔧 Find: Find `src/pages/Threads/**/*` - completed - src/pages/Threads/ThreadChat.tsx');
464
+ strict_1.default.equal(emitted.length, 2);
465
+ strict_1.default.deepEqual(emitted.map((event) => event.messageId), ['run-1-tool-1', 'run-1-tool-1']);
466
+ });
467
+ (0, node_test_1.default)('ACP concurrent tool call updates are matched by call id', () => {
468
+ const upserted = [];
469
+ const emitted = [];
470
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
471
+ appendMessage: () => strict_1.default.fail('tool updates should be upserted'),
472
+ upsertMessage: (_threadId, id, _role, content, kind, toolCall) => upserted.push({ id, content, kind, toolCall }),
473
+ emitBridge: (event) => emitted.push(event),
474
+ updateRunStatus: () => { },
475
+ sendRaw: () => true,
476
+ });
477
+ const session = {
478
+ threadId: 'thread-1',
479
+ bridgeSessionKey: 'session:thread-1',
480
+ currentRunId: 'run-1',
481
+ currentTurn: {
482
+ runId: 'run-1',
483
+ replyCtx: 'run-1',
484
+ previewHandle: 'preview-1',
485
+ assistantText: '',
486
+ typingStarted: true,
487
+ previewStarted: false,
488
+ permission: null,
489
+ },
490
+ loadReplayMode: false,
491
+ schedulerJobCreatedByRun: new Map(),
492
+ };
493
+ coordinator.handleAgentNotification(session, {
494
+ method: 'session/update',
495
+ params: {
496
+ update: {
497
+ sessionUpdate: 'tool_call',
498
+ id: 'call-a',
499
+ title: 'Terminal',
500
+ rawInput: { command: 'npm test' },
501
+ },
502
+ },
503
+ });
504
+ coordinator.handleAgentNotification(session, {
505
+ method: 'session/update',
506
+ params: {
507
+ update: {
508
+ sessionUpdate: 'tool_call',
509
+ id: 'call-b',
510
+ title: 'Read',
511
+ },
512
+ },
513
+ });
514
+ coordinator.handleAgentNotification(session, {
515
+ method: 'session/update',
516
+ params: {
517
+ update: {
518
+ sessionUpdate: 'tool_call_update',
519
+ id: 'call-b',
520
+ title: 'Read package.json',
521
+ status: 'running',
522
+ },
523
+ },
524
+ });
525
+ coordinator.handleAgentNotification(session, {
526
+ method: 'session/update',
527
+ params: {
528
+ update: {
529
+ sessionUpdate: 'tool_call_update',
530
+ id: 'call-a',
531
+ title: 'Tool update',
532
+ status: 'completed',
533
+ content: [
534
+ {
535
+ type: 'content',
536
+ content: {
537
+ type: 'text',
538
+ text: 'terminal output',
539
+ },
540
+ },
541
+ ],
542
+ },
543
+ },
544
+ });
545
+ strict_1.default.equal(upserted.length, 2);
546
+ strict_1.default.equal(upserted[0]?.id, 'run-1-tool-2');
547
+ strict_1.default.equal(upserted[0]?.content, '🔧 Read: Read package.json - running');
548
+ strict_1.default.equal(upserted[1]?.id, 'run-1-tool-1');
549
+ strict_1.default.equal(upserted[1]?.content, '🔧 Terminal: completed - terminal output');
550
+ strict_1.default.deepEqual(emitted.map((event) => event.messageId), ['run-1-tool-2', 'run-1-tool-1']);
551
+ strict_1.default.deepEqual(upserted[1]?.toolCall, {
552
+ id: 'call-a',
553
+ name: 'Terminal',
554
+ status: 'completed',
555
+ input: { command: 'npm test' },
556
+ output: 'terminal output',
557
+ detail: undefined,
558
+ label: '工具结果',
559
+ });
560
+ strict_1.default.deepEqual(emitted[1]?.toolCall, upserted[1]?.toolCall);
561
+ });
562
+ (0, node_test_1.default)('ACP tool call update backfills rawInput from pi ACP updates', () => {
563
+ const upserted = [];
564
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
565
+ appendMessage: () => strict_1.default.fail('tool updates should be upserted'),
566
+ upsertMessage: (_threadId, id, _role, content, _kind, toolCall) => upserted.push({ id, content, toolCall }),
567
+ emitBridge: () => { },
568
+ updateRunStatus: () => { },
569
+ sendRaw: () => true,
570
+ });
571
+ const session = {
572
+ threadId: 'thread-1',
573
+ bridgeSessionKey: 'session:thread-1',
574
+ currentRunId: 'run-1',
575
+ currentTurn: {
576
+ runId: 'run-1',
577
+ replyCtx: 'run-1',
578
+ previewHandle: 'preview-1',
579
+ assistantText: '',
580
+ typingStarted: true,
581
+ previewStarted: false,
582
+ permission: null,
583
+ },
584
+ loadReplayMode: false,
585
+ schedulerJobCreatedByRun: new Map(),
586
+ };
587
+ coordinator.handleAgentNotification(session, {
588
+ method: 'session/update',
589
+ params: {
590
+ update: {
591
+ sessionUpdate: 'tool_call',
592
+ toolCallId: 'call-a',
593
+ title: 'bash',
594
+ },
595
+ },
596
+ });
597
+ coordinator.handleAgentNotification(session, {
598
+ method: 'session/update',
599
+ params: {
600
+ update: {
601
+ sessionUpdate: 'tool_call_update',
602
+ toolCallId: 'call-a',
603
+ status: 'completed',
604
+ rawInput: { command: 'ls -la ~/Desktop' },
605
+ content: [
606
+ {
607
+ type: 'content',
608
+ content: {
609
+ type: 'text',
610
+ text: 'total 32',
611
+ },
612
+ },
613
+ ],
614
+ },
615
+ },
616
+ });
617
+ strict_1.default.equal(upserted[0]?.toolCall?.name, 'bash');
618
+ strict_1.default.deepEqual(upserted[0]?.toolCall?.input, { command: 'ls -la ~/Desktop' });
619
+ });
620
+ (0, node_test_1.default)('ACP permission tool parameters are preserved in completed tool cards', () => {
621
+ const upserted = [];
622
+ const emitted = [];
623
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
624
+ appendMessage: () => { },
625
+ upsertMessage: (_threadId, id, _role, content, kind) => upserted.push({ id, content, kind }),
626
+ emitBridge: (event) => emitted.push(event),
627
+ updateRunStatus: () => { },
628
+ sendRaw: () => true,
629
+ });
630
+ const session = {
631
+ threadId: 'thread-1',
632
+ bridgeSessionKey: 'session:thread-1',
633
+ currentRunId: 'run-1',
634
+ currentTurn: {
635
+ runId: 'run-1',
636
+ replyCtx: 'run-1',
637
+ previewHandle: 'preview-1',
638
+ assistantText: '',
639
+ typingStarted: true,
640
+ previewStarted: false,
641
+ permission: null,
642
+ },
643
+ pendingPermissionByRun: new Map(),
644
+ loadReplayMode: false,
645
+ schedulerJobCreatedByRun: new Map(),
646
+ };
647
+ coordinator.handleAgentNotification(session, {
648
+ method: 'session/update',
649
+ params: {
650
+ update: {
651
+ sessionUpdate: 'tool_call',
652
+ title: 'Terminal',
653
+ },
654
+ },
655
+ });
656
+ coordinator.handleAgentRequest(session, {
657
+ method: 'session/request_permission',
658
+ id: 42,
659
+ params: {
660
+ toolCall: {
661
+ title: 'Terminal',
662
+ parameters: {
663
+ command: 'ls -la ~/Desktop',
664
+ cwd: '/Users/mochuxian',
665
+ },
666
+ },
667
+ options: [
668
+ { optionId: 'allow-once', name: 'Allow', kind: 'allow_once' },
669
+ ],
670
+ },
671
+ });
672
+ coordinator.handleAgentNotification(session, {
673
+ method: 'session/update',
674
+ params: {
675
+ update: {
676
+ sessionUpdate: 'tool_call_update',
677
+ title: 'Tool update',
678
+ status: 'completed',
679
+ content: [
680
+ {
681
+ type: 'content',
682
+ content: {
683
+ type: 'text',
684
+ text: 'Desktop file list',
685
+ },
686
+ },
687
+ ],
688
+ },
689
+ },
690
+ });
691
+ strict_1.default.equal(upserted.length, 1);
692
+ strict_1.default.equal(upserted[0]?.id, 'run-1-tool-1');
693
+ strict_1.default.match(upserted[0]?.content || '', /Terminal/);
694
+ strict_1.default.match(upserted[0]?.content || '', /parameters:/);
695
+ strict_1.default.match(upserted[0]?.content || '', /ls -la ~\/Desktop/);
696
+ strict_1.default.match(upserted[0]?.content || '', /completed - Desktop file list/);
697
+ });
698
+ (0, node_test_1.default)('ACP permission button rows preserve always allow actions with structured status', () => {
699
+ const appended = [];
700
+ const emitted = [];
701
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
702
+ appendMessage: (_threadId, _role, content, kind, _toolCall, bridgeKind, bridgeStatus) => appended.push({ content, kind, bridgeKind, bridgeStatus }),
703
+ emitBridge: (event) => emitted.push(event),
704
+ updateRunStatus: () => { },
705
+ sendRaw: () => true,
706
+ });
707
+ const session = {
708
+ threadId: 'thread-1',
709
+ bridgeSessionKey: 'session:thread-1',
710
+ currentRunId: 'run-1',
711
+ currentTurn: {
712
+ runId: 'run-1',
713
+ replyCtx: 'run-1',
714
+ previewHandle: 'preview-1',
715
+ assistantText: '',
716
+ typingStarted: true,
717
+ previewStarted: false,
718
+ permission: null,
719
+ },
720
+ pendingPermissionByRun: new Map(),
721
+ loadReplayMode: false,
722
+ schedulerJobCreatedByRun: new Map(),
723
+ };
724
+ coordinator.handleAgentRequest(session, {
725
+ method: 'session/request_permission',
726
+ id: 42,
727
+ params: {
728
+ toolCall: {
729
+ title: 'Terminal',
730
+ parameters: {
731
+ command: 'system_profiler SPHardwareDataType',
732
+ },
733
+ },
734
+ options: [
735
+ { optionId: 'approve-once', name: 'Allow once', kind: 'allow' },
736
+ { optionId: 'approve-always', name: 'Always allow', kind: 'allow' },
737
+ { optionId: 'reject', name: 'Reject', kind: 'reject' },
738
+ ],
739
+ },
740
+ });
741
+ strict_1.default.equal(appended[0]?.bridgeKind, 'permission');
742
+ strict_1.default.equal(appended[0]?.bridgeStatus, 'awaiting_input');
743
+ strict_1.default.equal(emitted[0]?.bridgeKind, 'permission');
744
+ strict_1.default.equal(emitted[0]?.bridgeStatus, 'awaiting_input');
745
+ strict_1.default.deepEqual(emitted[0]?.buttonRows, [[
746
+ { text: 'allow', data: 'allow' },
747
+ { text: 'allow all', data: 'allow all' },
748
+ { text: 'deny', data: 'deny' },
749
+ ]]);
750
+ strict_1.default.equal(session.pendingPermissionByRun.get('run-1')?.options[1]?.optionId, 'approve-always');
751
+ });
752
+ (0, node_test_1.default)('Hermes ACP permission options respect allow_permanent false', () => {
753
+ const emitted = [];
754
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
755
+ appendMessage: () => { },
756
+ emitBridge: (event) => emitted.push(event),
757
+ updateRunStatus: () => { },
758
+ sendRaw: () => true,
759
+ });
760
+ const session = {
761
+ threadId: 'thread-1',
762
+ bridgeSessionKey: 'session:thread-1',
763
+ currentRunId: 'run-1',
764
+ currentTurn: {
765
+ runId: 'run-1',
766
+ replyCtx: 'run-1',
767
+ previewHandle: 'preview-1',
768
+ assistantText: '',
769
+ typingStarted: true,
770
+ previewStarted: false,
771
+ permission: null,
772
+ agentType: 'hermes',
773
+ },
774
+ pendingPermissionByRun: new Map(),
775
+ loadReplayMode: false,
776
+ schedulerJobCreatedByRun: new Map(),
777
+ };
778
+ coordinator.handleAgentRequest(session, {
779
+ method: 'session/request_permission',
780
+ id: 42,
781
+ params: {
782
+ allow_permanent: false,
783
+ toolCall: {
784
+ title: 'Terminal',
785
+ parameters: {
786
+ command: 'system_profiler SPHardwareDataType',
787
+ },
788
+ },
789
+ options: [
790
+ { optionId: 'approve-once', name: 'Allow once', kind: 'allow' },
791
+ { optionId: 'approve-always', name: 'Always allow', kind: 'allow' },
792
+ { optionId: 'reject', name: 'Reject', kind: 'reject' },
793
+ ],
794
+ },
795
+ });
796
+ strict_1.default.deepEqual(emitted[0]?.buttonRows, [[
797
+ { text: 'allow', data: 'allow' },
798
+ { text: 'deny', data: 'deny' },
799
+ ]]);
800
+ strict_1.default.deepEqual(session.pendingPermissionByRun.get('run-1')?.options.map((option) => option.optionId), ['approve-once', 'reject']);
801
+ });
802
+ (0, node_test_1.default)('ACP yolo mode auto-selects permission requests without rendering cards', () => {
803
+ const emitted = [];
804
+ const appended = [];
805
+ const rawPayloads = [];
806
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
807
+ appendMessage: (_threadId, _role, content) => appended.push(content),
808
+ emitBridge: (event) => emitted.push(event),
809
+ updateRunStatus: () => { },
810
+ getThreadAgentMode: () => 'bypassPermissions',
811
+ sendRaw: (_session, payload) => {
812
+ rawPayloads.push(payload);
813
+ return true;
814
+ },
815
+ });
816
+ const session = {
817
+ threadId: 'thread-1',
818
+ bridgeSessionKey: 'session:thread-1',
819
+ currentRunId: 'run-1',
820
+ currentTurn: {
821
+ runId: 'run-1',
822
+ replyCtx: 'run-1',
823
+ previewHandle: 'preview-1',
824
+ assistantText: '',
825
+ typingStarted: true,
826
+ previewStarted: false,
827
+ permission: null,
828
+ },
829
+ pendingPermissionByRun: new Map(),
830
+ loadReplayMode: false,
831
+ schedulerJobCreatedByRun: new Map(),
832
+ };
833
+ coordinator.handleAgentRequest(session, {
834
+ method: 'session/request_permission',
835
+ id: 42,
836
+ params: {
837
+ toolCall: {
838
+ title: 'Terminal',
839
+ parameters: {
840
+ command: 'system_profiler SPHardwareDataType',
841
+ },
842
+ },
843
+ options: [
844
+ { optionId: 'approve-once', name: 'Allow once', kind: 'allow' },
845
+ { optionId: 'approve-always', name: 'Always allow', kind: 'allow_all' },
846
+ { optionId: 'reject', name: 'Reject', kind: 'reject' },
847
+ ],
848
+ },
849
+ });
850
+ strict_1.default.equal(rawPayloads[0]?.id, 42);
851
+ strict_1.default.equal(rawPayloads[0]?.result?.outcome?.outcome, 'selected');
852
+ strict_1.default.equal(rawPayloads[0]?.result?.outcome?.optionId, 'approve-always');
853
+ strict_1.default.equal(session.pendingPermissionByRun.size, 0);
854
+ strict_1.default.deepEqual(appended, []);
855
+ strict_1.default.deepEqual(emitted, []);
856
+ });
857
+ (0, node_test_1.default)('ACP bare tool call is flushed before assistant text', () => {
858
+ const appended = [];
859
+ const emitted = [];
860
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
861
+ appendMessage: (_threadId, _role, content) => appended.push(content),
862
+ emitBridge: (event) => emitted.push(event),
863
+ updateRunStatus: () => { },
864
+ sendRaw: () => true,
865
+ });
866
+ const session = {
867
+ threadId: 'thread-1',
868
+ bridgeSessionKey: 'session:thread-1',
869
+ currentRunId: 'run-1',
870
+ currentTurn: {
871
+ runId: 'run-1',
872
+ replyCtx: 'run-1',
873
+ previewHandle: 'preview-1',
874
+ assistantText: '',
875
+ typingStarted: true,
876
+ previewStarted: false,
877
+ permission: null,
878
+ },
879
+ loadReplayMode: false,
880
+ schedulerJobCreatedByRun: new Map(),
881
+ };
882
+ coordinator.handleAgentNotification(session, {
883
+ method: 'session/update',
884
+ params: {
885
+ update: {
886
+ sessionUpdate: 'tool_call',
887
+ title: 'Terminal',
888
+ },
889
+ },
890
+ });
891
+ coordinator.handleAgentNotification(session, {
892
+ method: 'session/update',
893
+ params: {
894
+ update: {
895
+ sessionUpdate: 'agent_message_chunk',
896
+ content: { type: 'text', text: 'done' },
897
+ },
898
+ },
899
+ });
900
+ strict_1.default.deepEqual(appended, ['🔧 Terminal']);
901
+ strict_1.default.equal(emitted[0]?.content, '🔧 Terminal');
902
+ strict_1.default.equal(session.currentTurn.assistantText, 'done');
903
+ });
904
+ (0, node_test_1.default)('ACP closes assistant message segments at event boundaries without folding them into final', () => {
905
+ const upserted = [];
906
+ const emitted = [];
907
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
908
+ appendMessage: () => { },
909
+ upsertMessage: (_threadId, id, _role, content, _kind, _toolCall, bridgeKind) => {
910
+ upserted.push({ id, content, bridgeKind });
911
+ },
912
+ emitBridge: (event) => emitted.push(event),
913
+ updateRunStatus: () => { },
914
+ sendRaw: () => true,
915
+ });
916
+ const session = {
917
+ threadId: 'thread-1',
918
+ bridgeSessionKey: 'session:thread-1',
919
+ currentRunId: 'run-1',
920
+ currentTurn: {
921
+ runId: 'run-1',
922
+ replyCtx: 'run-1',
923
+ previewHandle: 'run-1-assistant-preview-1',
924
+ assistantMessageId: 'run-1-assistant-1',
925
+ assistantSequence: 1,
926
+ thoughtPreviewHandle: 'thought-preview-1',
927
+ thoughtMessageId: 'run-1-thought-1',
928
+ assistantText: '',
929
+ rawAssistantText: '',
930
+ thoughtText: '',
931
+ typingStarted: true,
932
+ previewStarted: false,
933
+ thoughtPreviewStarted: false,
934
+ pendingToolCalls: {},
935
+ pendingToolCallOrder: [],
936
+ toolCallSequence: 0,
937
+ toolObservations: [],
938
+ permission: null,
939
+ },
940
+ loadReplayMode: false,
941
+ schedulerJobCreatedByRun: new Map(),
942
+ };
943
+ coordinator.handleAgentNotification(session, {
944
+ method: 'session/update',
945
+ params: {
946
+ update: {
947
+ sessionUpdate: 'agent_message_chunk',
948
+ content: { type: 'text', text: '我先检查一下' },
949
+ },
950
+ },
951
+ });
952
+ strict_1.default.deepEqual(emitted, []);
953
+ strict_1.default.deepEqual(upserted, []);
954
+ coordinator.handleAgentNotification(session, {
955
+ method: 'session/update',
956
+ params: {
957
+ update: {
958
+ sessionUpdate: 'tool_call',
959
+ title: 'Terminal',
960
+ },
961
+ },
962
+ });
963
+ strict_1.default.deepEqual(upserted, [{
964
+ id: 'run-1-assistant-1',
965
+ content: '我先检查一下',
966
+ bridgeKind: 'assistant',
967
+ }]);
968
+ strict_1.default.equal(emitted.length, 1);
969
+ strict_1.default.equal(emitted[0]?.type, 'reply');
970
+ strict_1.default.equal(emitted[0]?.content, '我先检查一下');
971
+ strict_1.default.equal(emitted[0]?.messageId, 'run-1-assistant-1');
972
+ strict_1.default.equal(emitted[0]?.bridgeKind, 'assistant');
973
+ strict_1.default.equal(session.currentTurn.assistantText, '');
974
+ strict_1.default.equal(session.currentTurn.rawAssistantText, '');
975
+ coordinator.handleAgentNotification(session, {
976
+ method: 'session/update',
977
+ params: {
978
+ update: {
979
+ sessionUpdate: 'agent_message_chunk',
980
+ content: { type: 'text', text: '最终回答' },
981
+ },
982
+ },
983
+ });
984
+ strict_1.default.equal(session.currentTurn.assistantText, '最终回答');
985
+ strict_1.default.equal(session.currentTurn.rawAssistantText, '最终回答');
986
+ strict_1.default.equal(upserted.filter((entry) => entry.bridgeKind === 'assistant').length, 1);
987
+ strict_1.default.equal(emitted.length, 2);
988
+ strict_1.default.equal(emitted[1]?.bridgeKind, 'tool');
989
+ });
990
+ (0, node_test_1.default)('ACP tool-scoped assistant chunks stay out of final assistant buffer', () => {
991
+ const appended = [];
992
+ const emitted = [];
993
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
994
+ appendMessage: (_threadId, _role, content, _kind, _toolCall, bridgeKind) => appended.push({ content, bridgeKind }),
995
+ emitBridge: (event) => emitted.push(event),
996
+ updateRunStatus: () => { },
997
+ sendRaw: () => true,
998
+ });
999
+ const session = {
1000
+ threadId: 'thread-1',
1001
+ bridgeSessionKey: 'session:thread-1',
1002
+ currentRunId: 'run-1',
1003
+ currentTurn: {
1004
+ runId: 'run-1',
1005
+ replyCtx: 'run-1',
1006
+ previewHandle: 'preview-1',
1007
+ assistantText: '',
1008
+ typingStarted: true,
1009
+ previewStarted: false,
1010
+ permission: null,
1011
+ },
1012
+ loadReplayMode: false,
1013
+ schedulerJobCreatedByRun: new Map(),
1014
+ };
1015
+ coordinator.handleAgentNotification(session, {
1016
+ method: 'session/update',
1017
+ params: {
1018
+ update: {
1019
+ sessionUpdate: 'agent_message_chunk',
1020
+ _meta: {
1021
+ claudeCode: {
1022
+ parentToolUseId: 'tool-1',
1023
+ },
1024
+ },
1025
+ content: {
1026
+ type: 'text',
1027
+ text: 'tool scoped transcript',
1028
+ },
1029
+ },
1030
+ },
1031
+ });
1032
+ coordinator.handleAgentNotification(session, {
1033
+ method: 'session/update',
1034
+ params: {
1035
+ update: {
1036
+ sessionUpdate: 'agent_message_chunk',
1037
+ content: { type: 'text', text: 'final answer' },
1038
+ },
1039
+ },
1040
+ });
1041
+ strict_1.default.deepEqual(appended, [{ content: 'tool scoped transcript', bridgeKind: 'tool' }]);
1042
+ strict_1.default.equal(emitted[0]?.bridgeKind, 'tool');
1043
+ strict_1.default.equal(emitted[0]?.content, 'tool scoped transcript');
1044
+ strict_1.default.equal(session.currentTurn.assistantText, 'final answer');
1045
+ });
1046
+ (0, node_test_1.default)('Hermes ACP assistant chunks strip restored history replay inside its own behavior', () => {
1047
+ const emitted = [];
1048
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1049
+ appendMessage: () => { },
1050
+ emitBridge: (event) => emitted.push(event),
1051
+ updateRunStatus: () => { },
1052
+ sendRaw: () => true,
1053
+ });
1054
+ const session = {
1055
+ threadId: 'thread-1',
1056
+ bridgeSessionKey: 'session:thread-1',
1057
+ currentRunId: 'run-1',
1058
+ currentTurn: {
1059
+ runId: 'run-1',
1060
+ replyCtx: 'run-1',
1061
+ previewHandle: 'preview-1',
1062
+ agentType: 'hermes',
1063
+ assistantText: '',
1064
+ rawAssistantText: '',
1065
+ priorAssistantFinalMessages: ['Hi! 😊 How can I help you today?', '我是 Hermes Agent。'],
1066
+ typingStarted: true,
1067
+ previewStarted: false,
1068
+ permission: null,
1069
+ },
1070
+ loadReplayMode: false,
1071
+ schedulerJobCreatedByRun: new Map(),
1072
+ };
1073
+ for (const text of ['Hi! 😊 How can I help you today?', '我是 Hermes Agent。', '确认删除前需要你确认。']) {
1074
+ coordinator.handleAgentNotification(session, {
1075
+ method: 'session/update',
1076
+ params: {
1077
+ update: {
1078
+ sessionUpdate: 'agent_message_chunk',
1079
+ content: { type: 'text', text },
1080
+ },
1081
+ },
1082
+ });
1083
+ }
1084
+ strict_1.default.equal(session.currentTurn.assistantText, '确认删除前需要你确认。');
1085
+ strict_1.default.deepEqual(emitted.map((event) => event.content), []);
1086
+ });
1087
+ (0, node_test_1.default)('Hermes ACP assistant chunks strip replay even when stored prior final is already polluted', () => {
1088
+ const emitted = [];
1089
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1090
+ appendMessage: () => { },
1091
+ emitBridge: (event) => emitted.push(event),
1092
+ updateRunStatus: () => { },
1093
+ sendRaw: () => true,
1094
+ });
1095
+ const previousCleanFinal = '你确定要删除 **Sisyphus_介绍.txt** 这个文件吗?删除后无法恢复。确认的话我马上执行。';
1096
+ const pollutedStoredFinal = [
1097
+ 'Hi! How can I help you today?',
1098
+ '我是 Hermes Agent,你的 AI 助手。',
1099
+ '好的,让我看看你的桌面文件。',
1100
+ previousCleanFinal,
1101
+ ].join('');
1102
+ const session = {
1103
+ threadId: 'thread-1',
1104
+ bridgeSessionKey: 'session:thread-1',
1105
+ currentRunId: 'run-1',
1106
+ currentTurn: {
1107
+ runId: 'run-1',
1108
+ replyCtx: 'run-1',
1109
+ previewHandle: 'preview-1',
1110
+ agentType: 'hermes',
1111
+ assistantText: '',
1112
+ rawAssistantText: '',
1113
+ priorAssistantFinalMessages: [pollutedStoredFinal],
1114
+ typingStarted: true,
1115
+ previewStarted: false,
1116
+ permission: null,
1117
+ },
1118
+ loadReplayMode: false,
1119
+ schedulerJobCreatedByRun: new Map(),
1120
+ };
1121
+ for (const text of [
1122
+ 'Hi! How can I help you today?',
1123
+ '我是 Hermes Agent,你的 AI 助手。',
1124
+ '好的,让我看看你的桌面文件。',
1125
+ previousCleanFinal,
1126
+ '已删除 **Sisyphus_介绍.txt**,现在 Text 文件夹是空的了。',
1127
+ ]) {
1128
+ coordinator.handleAgentNotification(session, {
1129
+ method: 'session/update',
1130
+ params: {
1131
+ update: {
1132
+ sessionUpdate: 'agent_message_chunk',
1133
+ content: { type: 'text', text },
1134
+ },
1135
+ },
1136
+ });
1137
+ }
1138
+ strict_1.default.equal(session.currentTurn.assistantText, '已删除 **Sisyphus_介绍.txt**,现在 Text 文件夹是空的了。');
1139
+ strict_1.default.deepEqual(emitted.map((event) => event.content), []);
1140
+ });
1141
+ (0, node_test_1.default)('Hermes ACP assistant chunks keep a fresh answer when no replay anchor is present', () => {
1142
+ const emitted = [];
1143
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1144
+ appendMessage: () => { },
1145
+ emitBridge: (event) => emitted.push(event),
1146
+ updateRunStatus: () => { },
1147
+ sendRaw: () => true,
1148
+ });
1149
+ const session = {
1150
+ threadId: 'thread-1',
1151
+ bridgeSessionKey: 'session:thread-1',
1152
+ currentRunId: 'run-1',
1153
+ currentTurn: {
1154
+ runId: 'run-1',
1155
+ replyCtx: 'run-1',
1156
+ previewHandle: 'preview-1',
1157
+ agentType: 'hermes',
1158
+ assistantText: '',
1159
+ rawAssistantText: '',
1160
+ priorAssistantFinalMessages: ['上一轮已经污染的历史,但是它不会出现在这次新回复里。'],
1161
+ typingStarted: true,
1162
+ previewStarted: false,
1163
+ permission: null,
1164
+ },
1165
+ loadReplayMode: false,
1166
+ schedulerJobCreatedByRun: new Map(),
1167
+ };
1168
+ coordinator.handleAgentNotification(session, {
1169
+ method: 'session/update',
1170
+ params: {
1171
+ update: {
1172
+ sessionUpdate: 'agent_message_chunk',
1173
+ content: { type: 'text', text: '已删除文件。' },
1174
+ },
1175
+ },
1176
+ });
1177
+ strict_1.default.equal(session.currentTurn.assistantText, '已删除文件。');
1178
+ strict_1.default.deepEqual(emitted.map((event) => event.content), []);
1179
+ });
1180
+ (0, node_test_1.default)('Hermes ACP progress updates suppress restored tool and thought replay only', () => {
1181
+ const upserted = [];
1182
+ const emitted = [];
1183
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1184
+ appendMessage: () => strict_1.default.fail('tool updates should be upserted'),
1185
+ upsertMessage: (_threadId, id, _role, content, _kind, _toolCall, bridgeKind) => {
1186
+ upserted.push({ id, content, bridgeKind });
1187
+ },
1188
+ emitBridge: (event) => emitted.push(event),
1189
+ updateRunStatus: () => { },
1190
+ sendRaw: () => true,
1191
+ });
1192
+ const session = {
1193
+ threadId: 'thread-1',
1194
+ bridgeSessionKey: 'session:thread-1',
1195
+ currentRunId: 'run-1',
1196
+ currentTurn: {
1197
+ runId: 'run-1',
1198
+ replyCtx: 'run-1',
1199
+ previewHandle: 'preview-1',
1200
+ thoughtPreviewHandle: 'thought-preview-1',
1201
+ thoughtMessageId: 'run-1-thought-1',
1202
+ agentType: 'hermes',
1203
+ assistantText: '',
1204
+ thoughtText: '',
1205
+ thoughtSequence: 1,
1206
+ typingStarted: true,
1207
+ previewStarted: false,
1208
+ thoughtPreviewStarted: false,
1209
+ priorAssistantProgressMessages: [
1210
+ {
1211
+ kind: 'tool',
1212
+ content: '🔧 terminal: rm ~/Desktop/Text/Sisyphus_介绍.txt: completed - terminal result\n- **exit_code:** 0',
1213
+ },
1214
+ {
1215
+ kind: 'thought',
1216
+ content: 'The user confirmed they want to delete the file. Let me delete it.',
1217
+ },
1218
+ ],
1219
+ permission: null,
1220
+ },
1221
+ loadReplayMode: false,
1222
+ schedulerJobCreatedByRun: new Map(),
1223
+ };
1224
+ coordinator.handleAgentNotification(session, {
1225
+ method: 'session/update',
1226
+ params: {
1227
+ update: {
1228
+ sessionUpdate: 'tool_call',
1229
+ id: 'old-tool',
1230
+ title: 'terminal',
1231
+ rawInput: { command: 'rm ~/Desktop/Text/Sisyphus_介绍.txt' },
1232
+ },
1233
+ },
1234
+ });
1235
+ coordinator.handleAgentNotification(session, {
1236
+ method: 'session/update',
1237
+ params: {
1238
+ update: {
1239
+ sessionUpdate: 'tool_call_update',
1240
+ id: 'old-tool',
1241
+ title: 'tool update',
1242
+ status: 'completed',
1243
+ content: [
1244
+ {
1245
+ type: 'content',
1246
+ content: {
1247
+ type: 'text',
1248
+ text: 'terminal result\n- **exit_code:** 0',
1249
+ },
1250
+ },
1251
+ ],
1252
+ },
1253
+ },
1254
+ });
1255
+ coordinator.handleAgentNotification(session, {
1256
+ method: 'session/update',
1257
+ params: {
1258
+ update: {
1259
+ sessionUpdate: 'agent_thought_chunk',
1260
+ content: {
1261
+ type: 'text',
1262
+ text: 'The user confirmed they want to delete the file. Let me delete it.',
1263
+ },
1264
+ },
1265
+ },
1266
+ });
1267
+ coordinator.handleAgentNotification(session, {
1268
+ method: 'session/update',
1269
+ params: {
1270
+ update: {
1271
+ sessionUpdate: 'tool_call',
1272
+ id: 'new-tool',
1273
+ title: 'terminal',
1274
+ rawInput: { command: 'ls -la ~/Desktop/PDF/' },
1275
+ },
1276
+ },
1277
+ });
1278
+ coordinator.handleAgentNotification(session, {
1279
+ method: 'session/update',
1280
+ params: {
1281
+ update: {
1282
+ sessionUpdate: 'tool_call_update',
1283
+ id: 'new-tool',
1284
+ title: 'tool update',
1285
+ status: 'completed',
1286
+ content: [
1287
+ {
1288
+ type: 'content',
1289
+ content: {
1290
+ type: 'text',
1291
+ text: 'terminal result\n- **output:** pdf files\n- **exit_code:** 0',
1292
+ },
1293
+ },
1294
+ ],
1295
+ },
1296
+ },
1297
+ });
1298
+ coordinator.handleAgentNotification(session, {
1299
+ method: 'session/update',
1300
+ params: {
1301
+ update: {
1302
+ sessionUpdate: 'agent_thought_chunk',
1303
+ content: {
1304
+ type: 'text',
1305
+ text: 'Let me present the PDF files to the user.',
1306
+ },
1307
+ },
1308
+ },
1309
+ });
1310
+ strict_1.default.deepEqual(upserted.map((entry) => entry.content), [
1311
+ '🔧 terminal: completed - terminal result\n- **output:** pdf files\n- **exit_code:** 0',
1312
+ 'Let me present the PDF files to the user.',
1313
+ ]);
1314
+ strict_1.default.deepEqual(emitted.map((event) => event.content), [
1315
+ '🔧 terminal: completed - terminal result\n- **output:** pdf files\n- **exit_code:** 0',
1316
+ 'Let me present the PDF files to the user.',
1317
+ ]);
1318
+ });
1319
+ (0, node_test_1.default)('Hermes ACP progress updates suppress restored plan and tool-scoped assistant chunks', () => {
1320
+ const appended = [];
1321
+ const emitted = [];
1322
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1323
+ appendMessage: (_threadId, _role, content, _kind, _toolCall, bridgeKind) => appended.push({ content, bridgeKind }),
1324
+ emitBridge: (event) => emitted.push(event),
1325
+ updateRunStatus: () => { },
1326
+ sendRaw: () => true,
1327
+ });
1328
+ const session = {
1329
+ threadId: 'thread-1',
1330
+ bridgeSessionKey: 'session:thread-1',
1331
+ currentRunId: 'run-1',
1332
+ currentTurn: {
1333
+ runId: 'run-1',
1334
+ replyCtx: 'run-1',
1335
+ previewHandle: 'preview-1',
1336
+ agentType: 'hermes',
1337
+ assistantText: '',
1338
+ priorAssistantProgressMessages: [
1339
+ { kind: 'plan', content: '旧计划 | 已完成' },
1340
+ { kind: 'tool', content: 'raw restored command output' },
1341
+ ],
1342
+ typingStarted: true,
1343
+ previewStarted: false,
1344
+ permission: null,
1345
+ },
1346
+ loadReplayMode: false,
1347
+ schedulerJobCreatedByRun: new Map(),
1348
+ pendingRawAssistantProgressChunks: ['raw restored command output', 'fresh command output'],
1349
+ };
1350
+ coordinator.handleAgentNotification(session, {
1351
+ method: 'session/update',
1352
+ params: {
1353
+ update: {
1354
+ sessionUpdate: 'plan',
1355
+ entries: [{ content: '旧计划' }, { content: '已完成' }],
1356
+ },
1357
+ },
1358
+ });
1359
+ coordinator.handleAgentNotification(session, {
1360
+ method: 'session/update',
1361
+ params: {
1362
+ update: {
1363
+ sessionUpdate: 'agent_message_chunk',
1364
+ content: { type: 'text', text: 'raw restored command output' },
1365
+ },
1366
+ },
1367
+ });
1368
+ coordinator.handleAgentNotification(session, {
1369
+ method: 'session/update',
1370
+ params: {
1371
+ update: {
1372
+ sessionUpdate: 'plan',
1373
+ entries: [{ content: '新计划' }, { content: '进行中' }],
1374
+ },
1375
+ },
1376
+ });
1377
+ coordinator.handleAgentNotification(session, {
1378
+ method: 'session/update',
1379
+ params: {
1380
+ update: {
1381
+ sessionUpdate: 'agent_message_chunk',
1382
+ content: { type: 'text', text: 'fresh command output' },
1383
+ },
1384
+ },
1385
+ });
1386
+ strict_1.default.deepEqual(appended, [
1387
+ { content: '新计划 | 进行中', bridgeKind: 'plan' },
1388
+ { content: 'fresh command output', bridgeKind: 'tool' },
1389
+ ]);
1390
+ strict_1.default.deepEqual(emitted.map((event) => ({ content: event.content, bridgeKind: event.bridgeKind })), [
1391
+ { content: '新计划 | 进行中', bridgeKind: 'plan' },
1392
+ { content: 'fresh command output', bridgeKind: 'tool' },
1393
+ ]);
1394
+ });
1395
+ (0, node_test_1.default)('ACP raw local command output assistant chunks stay out of final assistant buffer', () => {
1396
+ const appended = [];
1397
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1398
+ appendMessage: (_threadId, _role, content, _kind, _toolCall, bridgeKind) => appended.push({ content, bridgeKind }),
1399
+ emitBridge: () => { },
1400
+ updateRunStatus: () => { },
1401
+ sendRaw: () => true,
1402
+ });
1403
+ const session = {
1404
+ threadId: 'thread-1',
1405
+ bridgeSessionKey: 'session:thread-1',
1406
+ currentRunId: 'run-1',
1407
+ currentTurn: {
1408
+ runId: 'run-1',
1409
+ replyCtx: 'run-1',
1410
+ previewHandle: 'preview-1',
1411
+ assistantText: '',
1412
+ typingStarted: true,
1413
+ previewStarted: false,
1414
+ permission: null,
1415
+ },
1416
+ loadReplayMode: false,
1417
+ schedulerJobCreatedByRun: new Map(),
1418
+ pendingRawAssistantProgressChunks: [],
1419
+ };
1420
+ coordinator.handleAgentNotification(session, {
1421
+ method: '_claude/sdkMessage',
1422
+ params: {
1423
+ message: {
1424
+ type: 'system',
1425
+ subtype: 'local_command_output',
1426
+ content: 'raw command output',
1427
+ },
1428
+ },
1429
+ });
1430
+ coordinator.handleAgentNotification(session, {
1431
+ method: 'session/update',
1432
+ params: {
1433
+ update: {
1434
+ sessionUpdate: 'agent_message_chunk',
1435
+ content: { type: 'text', text: 'raw command output' },
1436
+ },
1437
+ },
1438
+ });
1439
+ coordinator.handleAgentNotification(session, {
1440
+ method: 'session/update',
1441
+ params: {
1442
+ update: {
1443
+ sessionUpdate: 'agent_message_chunk',
1444
+ content: { type: 'text', text: 'final answer' },
1445
+ },
1446
+ },
1447
+ });
1448
+ strict_1.default.deepEqual(appended, [{ content: 'raw command output', bridgeKind: 'tool' }]);
1449
+ strict_1.default.equal(session.currentTurn.assistantText, 'final answer');
1450
+ });
1451
+ (0, node_test_1.default)('ACP final text strips observed provider tool transcript prefix', () => {
1452
+ const currentTurn = {
1453
+ runId: 'run-1',
1454
+ replyCtx: 'run-1',
1455
+ previewHandle: 'preview-1',
1456
+ assistantText: '',
1457
+ thoughtText: '',
1458
+ typingStarted: true,
1459
+ previewStarted: false,
1460
+ thoughtPreviewStarted: false,
1461
+ permission: null,
1462
+ toolObservations: [],
1463
+ };
1464
+ (0, local_core_acp_progress_js_1.recordToolObservation)(currentTurn, {
1465
+ name: 'webReader',
1466
+ title: 'webReader',
1467
+ input: {
1468
+ url: 'https://github.com/Thysrael/Horizon',
1469
+ return_format: 'markdown',
1470
+ retain_images: false,
1471
+ },
1472
+ status: 'completed',
1473
+ outputText: JSON.stringify([{
1474
+ title: 'GitHub - Thysrael/Horizon: Your own AI-powered news radar',
1475
+ description: 'Your own AI-powered news radar. Generates daily briefings in English & Chinese.',
1476
+ url: 'https://github.com/Thysrael/Horizon',
1477
+ }]),
1478
+ });
1479
+ const polluted = [
1480
+ '**🌐 Z.ai Built-in Tool: webReader**',
1481
+ '',
1482
+ '**Input:**',
1483
+ '```json',
1484
+ '{"url":"https://github.com/Thysrael/Horizon","return_format":"markdown","retain_images":false}',
1485
+ '```',
1486
+ '',
1487
+ '*Executing on server...*',
1488
+ ' **Output:**',
1489
+ '**webReader_result_summary:** [{"text": {"title": "GitHub - Thysrael/Horizon: Your own AI-powered news radar", "description": "Your own AI-powered news radar. Generates daily briefings in English & Chinese.", "url": "https...',
1490
+ ' 已放入 `00-Inbox/Horizon.md`。这个项目和咱们的 AI 早报 skill 功能高度重叠,架构可以作为参考。',
1491
+ ].join('\n');
1492
+ strict_1.default.equal((0, local_core_acp_progress_js_1.stripObservedToolTranscriptsFromAssistantText)(polluted, currentTurn.toolObservations), '已放入 `00-Inbox/Horizon.md`。这个项目和咱们的 AI 早报 skill 功能高度重叠,架构可以作为参考。');
1493
+ strict_1.default.equal((0, local_core_acp_progress_js_1.stripObservedToolTranscriptsFromAssistantText)(polluted, []), polluted.trim());
1494
+ });
1495
+ (0, node_test_1.default)('ACP final text keeps normal answers that mention observed tool evidence', () => {
1496
+ const observations = [{
1497
+ name: 'webReader',
1498
+ input: { url: 'https://github.com/Thysrael/Horizon' },
1499
+ outputText: JSON.stringify([{
1500
+ title: 'GitHub - Thysrael/Horizon: Your own AI-powered news radar',
1501
+ url: 'https://github.com/Thysrael/Horizon',
1502
+ }]),
1503
+ }];
1504
+ const answer = [
1505
+ '我看了 https://github.com/Thysrael/Horizon,它是一个 AI 新闻雷达项目。',
1506
+ '结论:可以作为早报 skill 的参考,但不需要直接照搬。',
1507
+ ].join('\n');
1508
+ strict_1.default.equal((0, local_core_acp_progress_js_1.stripObservedToolTranscriptsFromAssistantText)(answer, observations), answer);
1509
+ });
1510
+ (0, node_test_1.default)('ACP plan updates are persisted and emitted as thinking progress', () => {
1511
+ const appended = [];
1512
+ const emitted = [];
1513
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1514
+ appendMessage: (_threadId, _role, content, kind) => appended.push({ content, kind }),
1515
+ emitBridge: (event) => emitted.push(event),
1516
+ updateRunStatus: () => { },
1517
+ sendRaw: () => true,
1518
+ });
1519
+ const session = {
1520
+ threadId: 'thread-1',
1521
+ bridgeSessionKey: 'session:thread-1',
1522
+ currentRunId: 'run-1',
1523
+ currentTurn: {
1524
+ runId: 'run-1',
1525
+ replyCtx: 'run-1',
1526
+ previewHandle: 'preview-1',
1527
+ assistantText: '',
1528
+ typingStarted: true,
1529
+ previewStarted: false,
1530
+ permission: null,
1531
+ },
1532
+ loadReplayMode: false,
1533
+ schedulerJobCreatedByRun: new Map(),
1534
+ };
1535
+ coordinator.handleAgentNotification(session, {
1536
+ method: 'session/update',
1537
+ params: {
1538
+ update: {
1539
+ sessionUpdate: 'plan',
1540
+ entries: [
1541
+ { content: '检查消息流' },
1542
+ { content: '修复持久化' },
1543
+ ],
1544
+ },
1545
+ },
1546
+ });
1547
+ strict_1.default.deepEqual(appended, [
1548
+ {
1549
+ content: '检查消息流 | 修复持久化',
1550
+ kind: 'progress',
1551
+ },
1552
+ ]);
1553
+ strict_1.default.equal(emitted.length, 1);
1554
+ strict_1.default.equal(emitted[0]?.type, 'reply');
1555
+ strict_1.default.equal(emitted[0]?.bridgeKind, 'plan');
1556
+ strict_1.default.equal(emitted[0]?.content, appended[0]?.content);
1557
+ });
1558
+ (0, node_test_1.default)('ACP thought chunks stream for web/app and start a fresh segment at tool boundaries', () => {
1559
+ const appended = [];
1560
+ const upserted = [];
1561
+ const emitted = [];
1562
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1563
+ appendMessage: (_threadId, _role, content, kind) => appended.push({ content, kind }),
1564
+ upsertMessage: (_threadId, id, _role, content, kind) => upserted.push({ id, content, kind }),
1565
+ emitBridge: (event) => emitted.push(event),
1566
+ updateRunStatus: () => { },
1567
+ sendRaw: () => true,
1568
+ });
1569
+ const session = {
1570
+ threadId: 'thread-1',
1571
+ bridgeSessionKey: 'session:thread-1',
1572
+ currentRunId: 'run-1',
1573
+ currentTurn: {
1574
+ runId: 'run-1',
1575
+ replyCtx: 'run-1',
1576
+ previewHandle: 'preview-1',
1577
+ thoughtPreviewHandle: 'thought-preview-1',
1578
+ thoughtMessageId: 'run-1-thought-1',
1579
+ assistantText: '',
1580
+ thoughtText: '',
1581
+ thoughtSequence: 1,
1582
+ typingStarted: true,
1583
+ previewStarted: false,
1584
+ thoughtPreviewStarted: false,
1585
+ permission: null,
1586
+ },
1587
+ loadReplayMode: false,
1588
+ schedulerJobCreatedByRun: new Map(),
1589
+ };
1590
+ coordinator.handleAgentNotification(session, {
1591
+ method: 'session/update',
1592
+ params: {
1593
+ update: {
1594
+ sessionUpdate: 'agent_thought_chunk',
1595
+ content: { type: 'text', text: '先理解问题' },
1596
+ },
1597
+ },
1598
+ });
1599
+ strict_1.default.deepEqual(appended, []);
1600
+ strict_1.default.deepEqual(upserted, [
1601
+ {
1602
+ id: 'run-1-thought-1',
1603
+ content: '先理解问题',
1604
+ kind: 'progress',
1605
+ },
1606
+ ]);
1607
+ strict_1.default.deepEqual(emitted.map((event) => event.type), ['preview_start']);
1608
+ strict_1.default.equal(emitted[0]?.content, '先理解问题');
1609
+ coordinator.handleAgentNotification(session, {
1610
+ method: 'session/update',
1611
+ params: {
1612
+ update: {
1613
+ sessionUpdate: 'agent_thought_chunk',
1614
+ content: { type: 'text', text: ',再检查代码' },
1615
+ },
1616
+ },
1617
+ });
1618
+ strict_1.default.deepEqual(appended, []);
1619
+ strict_1.default.deepEqual(upserted.map((entry) => entry.content), ['先理解问题', '先理解问题,再检查代码']);
1620
+ strict_1.default.deepEqual(emitted.map((event) => event.type), ['preview_start', 'update_message']);
1621
+ strict_1.default.equal(emitted[1]?.content, '先理解问题,再检查代码');
1622
+ coordinator.handleAgentNotification(session, {
1623
+ method: 'session/update',
1624
+ params: {
1625
+ update: {
1626
+ sessionUpdate: 'tool_call',
1627
+ title: 'webReader',
1628
+ },
1629
+ },
1630
+ });
1631
+ strict_1.default.deepEqual(appended, []);
1632
+ strict_1.default.equal(session.currentTurn.thoughtText, '');
1633
+ strict_1.default.equal(session.currentTurn.thoughtMessageId, 'run-1-thought-2');
1634
+ strict_1.default.equal(session.currentTurn.thoughtPreviewHandle, 'run-1-thought-preview-2');
1635
+ });
1636
+ (0, node_test_1.default)('ACP store preserves structured progress metadata', () => {
1637
+ const userDataPath = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'agentdock-thought-store-'));
1638
+ const store = new local_core_acp_store_js_1.LocalCoreAcpStore(userDataPath);
1639
+ try {
1640
+ const thread = store.createThread('project-1', 'Thread');
1641
+ store.upsertMessage(thread.id, 'run-1-thought', 'assistant', '先理解问题', 'progress', undefined, 'thought');
1642
+ store.upsertMessage(thread.id, 'run-1-thought', 'assistant', '先理解问题,再检查代码', 'progress', undefined, 'thought');
1643
+ store.appendMessage(thread.id, 'assistant', '等待确认', 'progress', undefined, 'permission', 'awaiting_input');
1644
+ const detail = store.getThread(thread.id, []);
1645
+ strict_1.default.equal(detail.messages.length, 2);
1646
+ strict_1.default.equal(detail.messages[0]?.id, 'run-1-thought');
1647
+ strict_1.default.equal(detail.messages[0]?.kind, 'progress');
1648
+ strict_1.default.equal(detail.messages[0]?.bridgeKind, 'thought');
1649
+ strict_1.default.equal(detail.messages[0]?.content, '先理解问题,再检查代码');
1650
+ strict_1.default.equal(detail.messages[1]?.bridgeKind, 'permission');
1651
+ strict_1.default.equal(detail.messages[1]?.bridgeStatus, 'awaiting_input');
1652
+ strict_1.default.equal(detail.historyCount, 2);
1653
+ }
1654
+ finally {
1655
+ store.close();
1656
+ (0, node_fs_1.rmSync)(userDataPath, { recursive: true, force: true });
1657
+ }
1658
+ });
1659
+ (0, node_test_1.default)('ACP store preserves structured tool call progress metadata', () => {
1660
+ const userDataPath = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'agentdock-tool-store-'));
1661
+ const store = new local_core_acp_store_js_1.LocalCoreAcpStore(userDataPath);
1662
+ try {
1663
+ const thread = store.createThread('project-1', 'Thread');
1664
+ store.upsertMessage(thread.id, 'run-1-tool-1', 'assistant', '🔧 bash: completed - total 32', 'progress', {
1665
+ id: 'call-1',
1666
+ name: 'bash',
1667
+ status: 'completed',
1668
+ input: { command: 'ls -la ~/Desktop' },
1669
+ detail: 'ls -la ~/Desktop',
1670
+ output: 'total 32',
1671
+ label: '工具结果',
1672
+ });
1673
+ const detail = store.getThread(thread.id, []);
1674
+ strict_1.default.equal(detail.messages.length, 1);
1675
+ strict_1.default.equal(detail.messages[0]?.id, 'run-1-tool-1');
1676
+ strict_1.default.equal(detail.messages[0]?.toolCall?.name, 'bash');
1677
+ strict_1.default.equal(detail.messages[0]?.toolCall?.status, 'completed');
1678
+ strict_1.default.deepEqual(detail.messages[0]?.toolCall?.input, { command: 'ls -la ~/Desktop' });
1679
+ strict_1.default.equal(detail.messages[0]?.toolCall?.detail, 'ls -la ~/Desktop');
1680
+ strict_1.default.equal(detail.messages[0]?.toolCall?.output, 'total 32');
1681
+ }
1682
+ finally {
1683
+ store.close();
1684
+ (0, node_fs_1.rmSync)(userDataPath, { recursive: true, force: true });
1685
+ }
1686
+ });
1687
+ (0, node_test_1.default)('ACP skips empty generic running tool updates', () => {
1688
+ const appended = [];
1689
+ const emitted = [];
1690
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1691
+ appendMessage: (_threadId, _role, content) => appended.push(content),
1692
+ emitBridge: (event) => emitted.push(event),
1693
+ updateRunStatus: () => { },
1694
+ sendRaw: () => true,
1695
+ });
1696
+ const session = {
1697
+ threadId: 'thread-1',
1698
+ bridgeSessionKey: 'session:thread-1',
1699
+ currentRunId: 'run-1',
1700
+ currentTurn: {
1701
+ runId: 'run-1',
1702
+ replyCtx: 'run-1',
1703
+ previewHandle: 'preview-1',
1704
+ assistantText: '',
1705
+ typingStarted: true,
1706
+ previewStarted: false,
1707
+ permission: null,
1708
+ },
1709
+ loadReplayMode: false,
1710
+ schedulerJobCreatedByRun: new Map(),
1711
+ };
1712
+ coordinator.handleAgentNotification(session, {
1713
+ method: 'session/update',
1714
+ params: {
1715
+ update: {
1716
+ sessionUpdate: 'tool_call_update',
1717
+ title: 'Tool update',
1718
+ status: 'running',
1719
+ },
1720
+ },
1721
+ });
1722
+ strict_1.default.deepEqual(appended, []);
1723
+ strict_1.default.deepEqual(emitted, []);
1724
+ });
1725
+ (0, node_test_1.default)('ACP skips empty generic running updates even after a tool name', () => {
1726
+ const appended = [];
1727
+ const emitted = [];
1728
+ const coordinator = new local_core_acp_turn_coordinator_js_1.LocalCoreAcpTurnCoordinator({
1729
+ appendMessage: (_threadId, _role, content) => appended.push(content),
1730
+ emitBridge: (event) => emitted.push(event),
1731
+ updateRunStatus: () => { },
1732
+ sendRaw: () => true,
1733
+ });
1734
+ const session = {
1735
+ threadId: 'thread-1',
1736
+ bridgeSessionKey: 'session:thread-1',
1737
+ currentRunId: 'run-1',
1738
+ currentTurn: {
1739
+ runId: 'run-1',
1740
+ replyCtx: 'run-1',
1741
+ previewHandle: 'preview-1',
1742
+ assistantText: '',
1743
+ typingStarted: true,
1744
+ previewStarted: false,
1745
+ permission: null,
1746
+ },
1747
+ loadReplayMode: false,
1748
+ schedulerJobCreatedByRun: new Map(),
1749
+ };
1750
+ coordinator.handleAgentNotification(session, {
1751
+ method: 'session/update',
1752
+ params: {
1753
+ update: {
1754
+ sessionUpdate: 'tool_call',
1755
+ title: 'Terminal',
1756
+ },
1757
+ },
1758
+ });
1759
+ coordinator.handleAgentNotification(session, {
1760
+ method: 'session/update',
1761
+ params: {
1762
+ update: {
1763
+ sessionUpdate: 'tool_call_update',
1764
+ title: 'Tool update',
1765
+ status: 'running',
1766
+ },
1767
+ },
1768
+ });
1769
+ strict_1.default.deepEqual(appended, []);
1770
+ strict_1.default.deepEqual(emitted, []);
1771
+ strict_1.default.equal(session.currentTurn.pendingToolCallTitle, undefined);
1772
+ });