agent-gear 2.12.0 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +20 -2
- package/dist/acp/bridge.d.ts +4 -0
- package/dist/acp/bridge.d.ts.map +1 -1
- package/dist/acp/bridge.js +72 -45
- package/dist/acp/bridge.js.map +1 -1
- package/dist/acp/bridge.test.js +40 -33
- package/dist/acp/bridge.test.js.map +1 -1
- package/dist/acp/process-registry.d.ts.map +1 -1
- package/dist/acp/process-registry.js +3 -1
- package/dist/acp/process-registry.js.map +1 -1
- package/dist/acp/process-registry.test.js +1 -0
- package/dist/acp/process-registry.test.js.map +1 -1
- package/dist/acp/spawner.d.ts +15 -0
- package/dist/acp/spawner.d.ts.map +1 -1
- package/dist/acp/spawner.js +51 -4
- package/dist/acp/spawner.js.map +1 -1
- package/dist/acp/sync-bridge.d.ts.map +1 -1
- package/dist/acp/sync-bridge.js +3 -1
- package/dist/acp/sync-bridge.js.map +1 -1
- package/dist/cloud-host/supervisor.d.ts +3 -1
- package/dist/cloud-host/supervisor.d.ts.map +1 -1
- package/dist/cloud-host/supervisor.js +18 -12
- package/dist/cloud-host/supervisor.js.map +1 -1
- package/dist/cloud-host/supervisor.test.js +19 -14
- package/dist/cloud-host/supervisor.test.js.map +1 -1
- package/dist/commands/harness.d.ts.map +1 -1
- package/dist/commands/harness.js +4 -2
- package/dist/commands/harness.js.map +1 -1
- package/dist/commands/mcp-proxy.d.ts +2 -1
- package/dist/commands/mcp-proxy.d.ts.map +1 -1
- package/dist/commands/mcp-proxy.js +26 -18
- package/dist/commands/mcp-proxy.js.map +1 -1
- package/dist/commands/mcp.js +1 -1
- package/dist/commands/mcp.js.map +1 -1
- package/dist/gateway.d.ts +3 -0
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +14 -8
- package/dist/gateway.js.map +1 -1
- package/dist/gateway.test.js +9 -4
- package/dist/gateway.test.js.map +1 -1
- package/dist/github/commit-identity-manager.d.ts +3 -1
- package/dist/github/commit-identity-manager.d.ts.map +1 -1
- package/dist/github/commit-identity-manager.js +13 -6
- package/dist/github/commit-identity-manager.js.map +1 -1
- package/dist/github/commit-identity-manager.test.js +26 -24
- package/dist/github/commit-identity-manager.test.js.map +1 -1
- package/dist/github/credential-manager.d.ts +3 -1
- package/dist/github/credential-manager.d.ts.map +1 -1
- package/dist/github/credential-manager.js +18 -10
- package/dist/github/credential-manager.js.map +1 -1
- package/dist/github/credential-manager.test.js +36 -33
- package/dist/github/credential-manager.test.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +77 -70
- package/dist/index.js.map +1 -1
- package/dist/mcp/local-server.d.ts +3 -1
- package/dist/mcp/local-server.d.ts.map +1 -1
- package/dist/mcp/local-server.js +19 -9
- package/dist/mcp/local-server.js.map +1 -1
- package/dist/mcp/relay.d.ts +3 -1
- package/dist/mcp/relay.d.ts.map +1 -1
- package/dist/mcp/relay.js +20 -12
- package/dist/mcp/relay.js.map +1 -1
- package/dist/observability/http-context.d.ts +32 -0
- package/dist/observability/http-context.d.ts.map +1 -0
- package/dist/observability/http-context.js +97 -0
- package/dist/observability/http-context.js.map +1 -0
- package/dist/observability/log-context.d.ts +19 -0
- package/dist/observability/log-context.d.ts.map +1 -0
- package/dist/observability/log-context.js +21 -0
- package/dist/observability/log-context.js.map +1 -0
- package/dist/observability/logger.d.ts +31 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +129 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/no-console.test.d.ts +2 -0
- package/dist/observability/no-console.test.d.ts.map +1 -0
- package/dist/observability/no-console.test.js +78 -0
- package/dist/observability/no-console.test.js.map +1 -0
- package/dist/observability/register.d.ts +2 -0
- package/dist/observability/register.d.ts.map +1 -0
- package/dist/observability/register.js +29 -0
- package/dist/observability/register.js.map +1 -0
- package/dist/observability/telemetry.d.ts +12 -0
- package/dist/observability/telemetry.d.ts.map +1 -0
- package/dist/observability/telemetry.js +164 -0
- package/dist/observability/telemetry.js.map +1 -0
- package/dist/observability/testing.d.ts +24 -0
- package/dist/observability/testing.d.ts.map +1 -0
- package/dist/observability/testing.js +31 -0
- package/dist/observability/testing.js.map +1 -0
- package/dist/observability/trace.d.ts +42 -0
- package/dist/observability/trace.d.ts.map +1 -0
- package/dist/observability/trace.js +123 -0
- package/dist/observability/trace.js.map +1 -0
- package/dist/socketio-client.auth-gate.test.js +0 -3
- package/dist/socketio-client.auth-gate.test.js.map +1 -1
- package/dist/socketio-client.d.ts +3 -0
- package/dist/socketio-client.d.ts.map +1 -1
- package/dist/socketio-client.js +140 -69
- package/dist/socketio-client.js.map +1 -1
- package/dist/socketio-client.test.js +0 -6
- package/dist/socketio-client.test.js.map +1 -1
- package/dist/startup-span.d.ts +15 -0
- package/dist/startup-span.d.ts.map +1 -0
- package/dist/startup-span.js +21 -0
- package/dist/startup-span.js.map +1 -0
- package/dist/startup-span.test.d.ts +2 -0
- package/dist/startup-span.test.d.ts.map +1 -0
- package/dist/startup-span.test.js +71 -0
- package/dist/startup-span.test.js.map +1 -0
- package/dist/worktree-handler.d.ts +25 -2
- package/dist/worktree-handler.d.ts.map +1 -1
- package/dist/worktree-handler.js +95 -5
- package/dist/worktree-handler.js.map +1 -1
- package/dist/worktree-handler.test.js +88 -5
- package/dist/worktree-handler.test.js.map +1 -1
- package/package.json +8 -1
- package/src/acp/bridge.test.ts +63 -34
- package/src/acp/bridge.ts +95 -51
- package/src/acp/process-registry.test.ts +1 -0
- package/src/acp/process-registry.ts +4 -1
- package/src/acp/spawner.ts +68 -4
- package/src/acp/sync-bridge.ts +4 -1
- package/src/cloud-host/supervisor.test.ts +25 -14
- package/src/cloud-host/supervisor.ts +29 -14
- package/src/commands/harness.ts +4 -2
- package/src/commands/mcp-proxy.ts +41 -18
- package/src/commands/mcp.ts +1 -1
- package/src/gateway.test.ts +10 -5
- package/src/gateway.ts +15 -8
- package/src/github/commit-identity-manager.test.ts +30 -24
- package/src/github/commit-identity-manager.ts +19 -9
- package/src/github/credential-manager.test.ts +42 -33
- package/src/github/credential-manager.ts +28 -15
- package/src/index.ts +85 -74
- package/src/mcp/local-server.ts +31 -9
- package/src/mcp/relay.ts +32 -13
- package/src/observability/http-context.ts +122 -0
- package/src/observability/log-context.ts +39 -0
- package/src/observability/logger.ts +160 -0
- package/src/observability/no-console.test.ts +99 -0
- package/src/observability/register.ts +34 -0
- package/src/observability/telemetry.ts +180 -0
- package/src/observability/testing.ts +51 -0
- package/src/observability/trace.ts +163 -0
- package/src/socketio-client.auth-gate.test.ts +0 -3
- package/src/socketio-client.test.ts +0 -6
- package/src/socketio-client.ts +220 -71
- package/src/startup-span.test.ts +83 -0
- package/src/startup-span.ts +27 -0
- package/src/worktree-handler.test.ts +106 -5
- package/src/worktree-handler.ts +116 -6
- package/tests/acp-bridge.test.ts +11 -3
- package/tests/acp-spawner.test.ts +119 -14
- package/tests/acp-wire-elicitation.test.ts +0 -3
- package/tests/acp-wire-mcp.test.ts +9 -6
- package/tests/commands/harness.test.ts +6 -0
- package/tests/commands/mcp-proxy-dispatcher.test.ts +0 -2
- package/tests/commands/mcp-proxy.test.ts +43 -0
- package/tests/commands/mcp.test.ts +4 -0
- package/tests/socketio-client.test.ts +114 -36
- package/vitest.config.ts +3 -0
package/src/acp/bridge.test.ts
CHANGED
|
@@ -31,6 +31,11 @@ vi.mock('@agentclientprotocol/sdk', () => ({
|
|
|
31
31
|
|
|
32
32
|
import { AcpSessionBridge } from './bridge.js';
|
|
33
33
|
import { CLIENT_CAPABILITIES, FEATURE_IDS } from './capabilities.js';
|
|
34
|
+
import { createTestLogger, type TestLogger } from '../observability/testing.js';
|
|
35
|
+
import type { ObservationLogger } from '../observability/logger.js';
|
|
36
|
+
|
|
37
|
+
/** 每个用例独立的内存日志 sink(断言结构化 records,不再 spy console)。 */
|
|
38
|
+
let testLog: TestLogger;
|
|
34
39
|
|
|
35
40
|
class MockAcpSpawner {
|
|
36
41
|
start = vi.fn();
|
|
@@ -58,7 +63,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
58
63
|
function createBridge() {
|
|
59
64
|
return new AcpSessionBridge(
|
|
60
65
|
mockSocket as never,
|
|
61
|
-
{ sessionId: 'sess-1', cwd: '/home/user' },
|
|
66
|
+
{ sessionId: 'sess-1', cwd: '/home/user', logger: testLog.logger },
|
|
62
67
|
mockSpawner as never,
|
|
63
68
|
);
|
|
64
69
|
}
|
|
@@ -68,6 +73,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
68
73
|
vi.useFakeTimers();
|
|
69
74
|
mockSocket = createMockSocket();
|
|
70
75
|
mockSpawner = new MockAcpSpawner();
|
|
76
|
+
testLog = createTestLogger('acp-bridge');
|
|
71
77
|
});
|
|
72
78
|
|
|
73
79
|
afterEach(() => {
|
|
@@ -139,12 +145,16 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
139
145
|
|
|
140
146
|
it('should warn and ignore invalid requestId in handlePermissionResponse', () => {
|
|
141
147
|
const bridge = createBridge();
|
|
142
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
143
148
|
|
|
144
149
|
bridge.handlePermissionResponse('invalid-id', { outcome: 'selected', optionId: 'opt-1' });
|
|
145
150
|
|
|
146
|
-
expect(
|
|
147
|
-
|
|
151
|
+
expect(testLog.records).toContainEqual(
|
|
152
|
+
expect.objectContaining({
|
|
153
|
+
level: 'warn',
|
|
154
|
+
msg: 'permission request not found',
|
|
155
|
+
requestId: 'invalid-id',
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
148
158
|
});
|
|
149
159
|
|
|
150
160
|
it('should handle cancelled outcome from user', async () => {
|
|
@@ -203,13 +213,13 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
203
213
|
await vi.advanceTimersByTimeAsync(65_000);
|
|
204
214
|
await promise;
|
|
205
215
|
|
|
206
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
207
216
|
const emitCall = mockSocket.emit.mock.calls.find((c: unknown[]) => c[0] === 'acp:permission');
|
|
208
217
|
const requestId = (emitCall![1] as { requestId: string }).requestId;
|
|
209
218
|
|
|
210
219
|
bridge.handlePermissionResponse(requestId, { outcome: 'selected', optionId: 'opt-1' });
|
|
211
|
-
expect(
|
|
212
|
-
|
|
220
|
+
expect(testLog.records).toContainEqual(
|
|
221
|
+
expect.objectContaining({ level: 'warn', msg: 'permission request not found', requestId }),
|
|
222
|
+
);
|
|
213
223
|
});
|
|
214
224
|
});
|
|
215
225
|
|
|
@@ -220,7 +230,7 @@ describe('AcpSessionBridge - mcpEndpoint injection', () => {
|
|
|
220
230
|
function createBridge(mcpEndpoint?: { token: string; serverNames: string[] }) {
|
|
221
231
|
return new AcpSessionBridge(
|
|
222
232
|
mockSocket as never,
|
|
223
|
-
{ sessionId: 'sess-1', cwd: '/home/user', mcpEndpoint, mcpPort: 47291 },
|
|
233
|
+
{ sessionId: 'sess-1', cwd: '/home/user', mcpEndpoint, mcpPort: 47291, logger: testLog.logger },
|
|
224
234
|
mockSpawner as never,
|
|
225
235
|
);
|
|
226
236
|
}
|
|
@@ -230,6 +240,7 @@ describe('AcpSessionBridge - mcpEndpoint injection', () => {
|
|
|
230
240
|
vi.useFakeTimers();
|
|
231
241
|
mockSocket = createMockSocket();
|
|
232
242
|
mockSpawner = new MockAcpSpawner();
|
|
243
|
+
testLog = createTestLogger('acp-bridge');
|
|
233
244
|
});
|
|
234
245
|
|
|
235
246
|
afterEach(() => {
|
|
@@ -278,7 +289,6 @@ describe('AcpSessionBridge - mcpEndpoint injection', () => {
|
|
|
278
289
|
});
|
|
279
290
|
|
|
280
291
|
it('should fail with a diagnosable error when mcpEndpoint.serverNames is missing', async () => {
|
|
281
|
-
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
282
292
|
const bridge = createBridge({
|
|
283
293
|
token: 'tok-1',
|
|
284
294
|
// simulate an upstream payload that drifts from the contract
|
|
@@ -294,7 +304,13 @@ describe('AcpSessionBridge - mcpEndpoint injection', () => {
|
|
|
294
304
|
error: expect.stringContaining('serverNames'),
|
|
295
305
|
}));
|
|
296
306
|
// the failure must be visible in local logs, not only via socket events
|
|
297
|
-
expect(
|
|
307
|
+
expect(testLog.records).toContainEqual(
|
|
308
|
+
expect.objectContaining({
|
|
309
|
+
level: 'error',
|
|
310
|
+
msg: 'acp session failed',
|
|
311
|
+
err: expect.objectContaining({ message: expect.stringContaining('serverNames') }),
|
|
312
|
+
}),
|
|
313
|
+
);
|
|
298
314
|
expect(mockSpawner.stop).toHaveBeenCalled();
|
|
299
315
|
});
|
|
300
316
|
|
|
@@ -315,7 +331,6 @@ describe('AcpSessionBridge - mcpEndpoint injection', () => {
|
|
|
315
331
|
});
|
|
316
332
|
|
|
317
333
|
it('should log the MCP servers passed to session/new without leaking the token', async () => {
|
|
318
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
319
334
|
const bridge = createBridge({
|
|
320
335
|
token: 'secret-token',
|
|
321
336
|
serverNames: ['fluentui-mcp'],
|
|
@@ -323,11 +338,11 @@ describe('AcpSessionBridge - mcpEndpoint injection', () => {
|
|
|
323
338
|
|
|
324
339
|
await bridge.start();
|
|
325
340
|
|
|
326
|
-
const
|
|
327
|
-
const mcpLog = logLines.find((l) => l.includes('passing MCP servers via session/new'));
|
|
341
|
+
const mcpLog = testLog.records.find((r) => r.event === 'mcp_servers_passed');
|
|
328
342
|
expect(mcpLog).toBeDefined();
|
|
329
|
-
expect(mcpLog).
|
|
330
|
-
expect(mcpLog).
|
|
343
|
+
expect(mcpLog).toEqual(expect.objectContaining({ component: 'acp-bridge', method: 'session/new' }));
|
|
344
|
+
expect(String(mcpLog?.servers)).toContain('fluentui-mcp(type=http, url=http://127.0.0.1:47291/mcp/sess-1/fluentui-mcp');
|
|
345
|
+
expect(JSON.stringify(mcpLog)).not.toContain('secret-token');
|
|
331
346
|
});
|
|
332
347
|
|
|
333
348
|
it('should warn when passing http MCP servers to an agent without http MCP capability', async () => {
|
|
@@ -335,7 +350,6 @@ describe('AcpSessionBridge - mcpEndpoint injection', () => {
|
|
|
335
350
|
protocolVersion: 1,
|
|
336
351
|
agentCapabilities: { mcpCapabilities: { http: false, sse: true } },
|
|
337
352
|
});
|
|
338
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
339
353
|
const bridge = createBridge({
|
|
340
354
|
token: 'tok-1',
|
|
341
355
|
serverNames: ['fluentui-mcp'],
|
|
@@ -343,7 +357,9 @@ describe('AcpSessionBridge - mcpEndpoint injection', () => {
|
|
|
343
357
|
|
|
344
358
|
await bridge.start();
|
|
345
359
|
|
|
346
|
-
expect(
|
|
360
|
+
expect(testLog.records).toContainEqual(
|
|
361
|
+
expect.objectContaining({ level: 'warn', msg: expect.stringContaining('mcpCapabilities.http') }),
|
|
362
|
+
);
|
|
347
363
|
// still passes the servers through — the agent decides
|
|
348
364
|
expect(mockNewSession).toHaveBeenCalledWith(expect.objectContaining({
|
|
349
365
|
mcpServers: [expect.objectContaining({ type: 'http', name: 'fluentui-mcp' })],
|
|
@@ -402,9 +418,10 @@ describe('AcpSessionBridge - initial mode/model', () => {
|
|
|
402
418
|
}
|
|
403
419
|
|
|
404
420
|
function createBridge(opts: { modeId?: string; modelId?: string } = {}) {
|
|
405
|
-
const options: { sessionId: string; cwd: string; initialModeId?: string; initialModelId?: string } = {
|
|
421
|
+
const options: { sessionId: string; cwd: string; initialModeId?: string; initialModelId?: string; logger?: ObservationLogger } = {
|
|
406
422
|
sessionId: 'sess-1',
|
|
407
423
|
cwd: '/home/user',
|
|
424
|
+
logger: testLog.logger,
|
|
408
425
|
};
|
|
409
426
|
if (opts.modeId) options.initialModeId = opts.modeId;
|
|
410
427
|
if (opts.modelId) options.initialModelId = opts.modelId;
|
|
@@ -417,6 +434,7 @@ describe('AcpSessionBridge - initial mode/model', () => {
|
|
|
417
434
|
vi.useFakeTimers();
|
|
418
435
|
mockSocket = createMockSocket();
|
|
419
436
|
mockSpawner = new MockAcpSpawner();
|
|
437
|
+
testLog = createTestLogger('acp-bridge');
|
|
420
438
|
});
|
|
421
439
|
|
|
422
440
|
afterEach(() => {
|
|
@@ -527,7 +545,6 @@ describe('AcpSessionBridge - initial mode/model', () => {
|
|
|
527
545
|
});
|
|
528
546
|
|
|
529
547
|
it('响应快照 currentValue 与请求值不一致 → 重试一次 → 仍不符 → emit failed', async () => {
|
|
530
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
531
548
|
mockNewSession.mockResolvedValueOnce({
|
|
532
549
|
sessionId: 'acp-sess-abc',
|
|
533
550
|
configOptions: [modeConfigOption('build')],
|
|
@@ -547,7 +564,9 @@ describe('AcpSessionBridge - initial mode/model', () => {
|
|
|
547
564
|
modeStatus: 'failed',
|
|
548
565
|
error: expect.stringContaining('code'),
|
|
549
566
|
}));
|
|
550
|
-
expect(
|
|
567
|
+
expect(testLog.records).toContainEqual(
|
|
568
|
+
expect.objectContaining({ level: 'warn', kind: 'mode', requested: 'code' }),
|
|
569
|
+
);
|
|
551
570
|
});
|
|
552
571
|
|
|
553
572
|
it('session/new 无 configOptions:config_option_update 到达后补应用 + 回读确认 + emit applied', async () => {
|
|
@@ -588,7 +607,6 @@ describe('AcpSessionBridge - initial mode/model', () => {
|
|
|
588
607
|
});
|
|
589
608
|
|
|
590
609
|
it('agent 不暴露 model config-option:挂起超时后 warn 并 emit failed(不阻断会话)', async () => {
|
|
591
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
592
610
|
const bridge = createBridge({ modelId: 'gpt-5' });
|
|
593
611
|
const initialized = vi.fn();
|
|
594
612
|
bridge.on('acp:initialized', initialized);
|
|
@@ -609,11 +627,12 @@ describe('AcpSessionBridge - initial mode/model', () => {
|
|
|
609
627
|
modelStatus: 'failed',
|
|
610
628
|
error: expect.any(String),
|
|
611
629
|
}));
|
|
612
|
-
expect(
|
|
630
|
+
expect(testLog.records).toContainEqual(
|
|
631
|
+
expect.objectContaining({ level: 'warn', event: 'initial_config_timeout', kind: 'model', requested: 'gpt-5' }),
|
|
632
|
+
);
|
|
613
633
|
});
|
|
614
634
|
|
|
615
635
|
it('INITIAL_CONFIG_PENDING_TIMEOUT_MS 覆盖默认挂起等待上限', async () => {
|
|
616
|
-
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
617
636
|
process.env.INITIAL_CONFIG_PENDING_TIMEOUT_MS = '1500';
|
|
618
637
|
const bridge = createBridge({ modelId: 'gpt-5' });
|
|
619
638
|
|
|
@@ -628,7 +647,6 @@ describe('AcpSessionBridge - initial mode/model', () => {
|
|
|
628
647
|
});
|
|
629
648
|
|
|
630
649
|
it('apply 抛错(agent 拒绝 model 切换)→ 重试一次仍失败 → warn 并 emit failed', async () => {
|
|
631
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
632
650
|
mockNewSession.mockResolvedValueOnce({
|
|
633
651
|
sessionId: 'acp-sess-abc',
|
|
634
652
|
configOptions: [modelConfigOption('gpt-4')],
|
|
@@ -651,7 +669,9 @@ describe('AcpSessionBridge - initial mode/model', () => {
|
|
|
651
669
|
modelStatus: 'failed',
|
|
652
670
|
error: expect.stringContaining('model switching is not supported'),
|
|
653
671
|
}));
|
|
654
|
-
expect(
|
|
672
|
+
expect(testLog.records).toContainEqual(
|
|
673
|
+
expect.objectContaining({ level: 'warn', kind: 'model', requested: 'gpt-5' }),
|
|
674
|
+
);
|
|
655
675
|
});
|
|
656
676
|
|
|
657
677
|
it('should not apply mode/model when not provided', async () => {
|
|
@@ -729,7 +749,7 @@ describe('AcpSessionBridge - capability snapshot', () => {
|
|
|
729
749
|
function createBridge() {
|
|
730
750
|
return new AcpSessionBridge(
|
|
731
751
|
mockSocket as never,
|
|
732
|
-
{ sessionId: 'sess-1', cwd: '/home/user' },
|
|
752
|
+
{ sessionId: 'sess-1', cwd: '/home/user', logger: testLog.logger },
|
|
733
753
|
mockSpawner as never,
|
|
734
754
|
);
|
|
735
755
|
}
|
|
@@ -739,6 +759,7 @@ describe('AcpSessionBridge - capability snapshot', () => {
|
|
|
739
759
|
vi.useFakeTimers();
|
|
740
760
|
mockSocket = createMockSocket();
|
|
741
761
|
mockSpawner = new MockAcpSpawner();
|
|
762
|
+
testLog = createTestLogger('acp-bridge');
|
|
742
763
|
});
|
|
743
764
|
|
|
744
765
|
afterEach(() => {
|
|
@@ -810,7 +831,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
810
831
|
function createBridge() {
|
|
811
832
|
return new AcpSessionBridge(
|
|
812
833
|
mockSocket as never,
|
|
813
|
-
{ sessionId: 'sess-1', cwd: '/home/user' },
|
|
834
|
+
{ sessionId: 'sess-1', cwd: '/home/user', logger: testLog.logger },
|
|
814
835
|
mockSpawner as never,
|
|
815
836
|
);
|
|
816
837
|
}
|
|
@@ -820,6 +841,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
820
841
|
vi.useFakeTimers();
|
|
821
842
|
mockSocket = createMockSocket();
|
|
822
843
|
mockSpawner = new MockAcpSpawner();
|
|
844
|
+
testLog = createTestLogger('acp-bridge');
|
|
823
845
|
});
|
|
824
846
|
|
|
825
847
|
afterEach(() => {
|
|
@@ -828,7 +850,6 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
828
850
|
});
|
|
829
851
|
|
|
830
852
|
it('T-B3: 未知 elicitation 模式返回 cancel 并发出 resolved(unsupported_mode)', async () => {
|
|
831
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
832
853
|
const bridge = createBridge();
|
|
833
854
|
|
|
834
855
|
const result = await bridge.unstable_createElicitation({ mode: 'custom' } as never);
|
|
@@ -841,11 +862,13 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
841
862
|
detail: 'custom',
|
|
842
863
|
}));
|
|
843
864
|
expect(mockSocket.emit).not.toHaveBeenCalledWith('acp:elicitation', expect.anything());
|
|
844
|
-
expect(
|
|
865
|
+
expect(testLog.records.filter((r) => r.level === 'warn')).toHaveLength(1);
|
|
866
|
+
expect(testLog.records).toContainEqual(
|
|
867
|
+
expect.objectContaining({ level: 'warn', event: 'elicitation_unsupported_mode', mode: 'custom' }),
|
|
868
|
+
);
|
|
845
869
|
});
|
|
846
870
|
|
|
847
871
|
it('T-B3b: unsupported_mode 的 detail 截断 Agent 可控字符串', async () => {
|
|
848
|
-
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
849
872
|
const bridge = createBridge();
|
|
850
873
|
|
|
851
874
|
await bridge.unstable_createElicitation({ mode: 'x'.repeat(500) } as never);
|
|
@@ -857,7 +880,6 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
857
880
|
});
|
|
858
881
|
|
|
859
882
|
it('T-B4: 65s 超时返回 cancel 并发出 resolved(timeout),不残留 pending', async () => {
|
|
860
|
-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
861
883
|
const bridge = createBridge();
|
|
862
884
|
|
|
863
885
|
const promise = bridge.unstable_createElicitation({
|
|
@@ -877,10 +899,18 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
877
899
|
reason: 'timeout',
|
|
878
900
|
detail: 'bridge timeout (65s)',
|
|
879
901
|
}));
|
|
880
|
-
expect(
|
|
902
|
+
expect(testLog.records).toContainEqual(
|
|
903
|
+
expect.objectContaining({ level: 'warn', event: 'elicitation_timeout', requestId }),
|
|
904
|
+
);
|
|
881
905
|
|
|
882
906
|
bridge.handleElicitationResponse(requestId, 'accept', { answer: 'x' });
|
|
883
|
-
expect(
|
|
907
|
+
expect(testLog.records).toContainEqual(
|
|
908
|
+
expect.objectContaining({
|
|
909
|
+
level: 'warn',
|
|
910
|
+
msg: 'elicitation request not found',
|
|
911
|
+
elicitationId: requestId,
|
|
912
|
+
}),
|
|
913
|
+
);
|
|
884
914
|
});
|
|
885
915
|
|
|
886
916
|
it('T-B5: 正常 form 模式只发 acp:elicitation,响应后 65s 内不发 resolved(clearTimeout 生效)', async () => {
|
|
@@ -1072,7 +1102,6 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1072
1102
|
});
|
|
1073
1103
|
|
|
1074
1104
|
it('T-B11: 进程退出(spawner.closed)收敛 pending 并发 cancelled,65s 后不再发 timeout', async () => {
|
|
1075
|
-
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
1076
1105
|
const bridge = createBridge();
|
|
1077
1106
|
await bridge.start();
|
|
1078
1107
|
|
package/src/acp/bridge.ts
CHANGED
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
normalizeCapabilities,
|
|
8
8
|
type AgentCapabilitySnapshot,
|
|
9
9
|
} from './capabilities.js';
|
|
10
|
+
import { logger as rootLogger, type ObservationLogger } from '../observability/logger.js';
|
|
11
|
+
import { withSpan } from '../observability/trace.js';
|
|
10
12
|
|
|
11
13
|
const ACP_PROTOCOL_VERSION = 1;
|
|
12
14
|
|
|
@@ -29,6 +31,8 @@ export interface AcpBridgeOptions {
|
|
|
29
31
|
/** 会话初始化时应用的工作模式/模型(工作流节点配置;不提供则使用 harness 默认) */
|
|
30
32
|
initialModeId?: string;
|
|
31
33
|
initialModelId?: string;
|
|
34
|
+
/** 注入 logger(测试用);缺省进程级单例,`component: 'acp-bridge'` + `sessionId` 字段化。 */
|
|
35
|
+
logger?: ObservationLogger;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
interface QueuedInput {
|
|
@@ -217,6 +221,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
217
221
|
private socket: Socket;
|
|
218
222
|
private sessionId: string;
|
|
219
223
|
private cwd: string;
|
|
224
|
+
private log: ObservationLogger;
|
|
220
225
|
private additionalDirectories: string[];
|
|
221
226
|
private mcpServers: AcpBridgeOptions['mcpServers'];
|
|
222
227
|
private mcpEndpoint: AcpBridgeOptions['mcpEndpoint'];
|
|
@@ -277,6 +282,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
277
282
|
this.socket = socket;
|
|
278
283
|
this.sessionId = options.sessionId;
|
|
279
284
|
this.cwd = options.cwd;
|
|
285
|
+
this.log = options.logger ?? rootLogger.child({ component: 'acp-bridge', sessionId: options.sessionId });
|
|
280
286
|
this.additionalDirectories = options.additionalDirectories ?? [];
|
|
281
287
|
this.mcpServers = options.mcpServers;
|
|
282
288
|
this.mcpEndpoint = options.mcpEndpoint;
|
|
@@ -297,12 +303,20 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
297
303
|
// session/new (or session/resume), and warn when the agent did not
|
|
298
304
|
// advertise the required MCP transport capability in initialize.
|
|
299
305
|
private logMcpServersForSession(method: 'session/new' | 'session/resume', servers: acp.McpServer[]): void {
|
|
300
|
-
|
|
306
|
+
this.log.info(
|
|
307
|
+
{ event: 'mcp_servers_passed', method, servers: describeMcpServersForLog(servers) },
|
|
308
|
+
'passing MCP servers to agent',
|
|
309
|
+
);
|
|
301
310
|
const httpServers = servers.filter((s) => 'url' in s && (s as { type?: string }).type === 'http');
|
|
302
311
|
if (httpServers.length > 0 && this.agentMcpCapabilities && this.agentMcpCapabilities.http === false) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
312
|
+
this.log.warn(
|
|
313
|
+
{
|
|
314
|
+
event: 'mcp_http_capability_missing',
|
|
315
|
+
method,
|
|
316
|
+
httpServerCount: httpServers.length,
|
|
317
|
+
httpServerNames: httpServers.map((s) => s.name).join(', '),
|
|
318
|
+
},
|
|
319
|
+
'agent did not advertise mcpCapabilities.http but http MCP servers are being passed',
|
|
306
320
|
);
|
|
307
321
|
}
|
|
308
322
|
}
|
|
@@ -311,7 +325,10 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
311
325
|
if (this.initializing) return;
|
|
312
326
|
this.initializing = true;
|
|
313
327
|
|
|
314
|
-
|
|
328
|
+
// acp child spawn:一次 spawn 一个 span(进程事件不逐条开 span)
|
|
329
|
+
withSpan('acp.child.spawn', { sessionId: this.sessionId, cwd: this.cwd }, () => {
|
|
330
|
+
this.spawner.start();
|
|
331
|
+
});
|
|
315
332
|
this.subscribeToProcessExit();
|
|
316
333
|
try {
|
|
317
334
|
await this.initConnection();
|
|
@@ -341,7 +358,10 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
341
358
|
if (this.initializing) return;
|
|
342
359
|
this.initializing = true;
|
|
343
360
|
|
|
344
|
-
|
|
361
|
+
// acp child spawn:一次 spawn 一个 span(进程事件不逐条开 span)
|
|
362
|
+
withSpan('acp.child.spawn', { sessionId: this.sessionId, cwd: this.cwd }, () => {
|
|
363
|
+
this.spawner.start();
|
|
364
|
+
});
|
|
345
365
|
this.subscribeToProcessExit();
|
|
346
366
|
try {
|
|
347
367
|
await this.initConnection();
|
|
@@ -442,8 +462,11 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
442
462
|
this.processExitSubscribed = true;
|
|
443
463
|
this.spawner.closed.then(() => {
|
|
444
464
|
if (this.stopped) return;
|
|
445
|
-
|
|
446
|
-
this.
|
|
465
|
+
// acp child exit:进程退出收敛一个 span(不逐进程事件开 span)
|
|
466
|
+
withSpan('acp.child.exit', { sessionId: this.sessionId }, () => {
|
|
467
|
+
this.log.warn({ event: 'acp_process_exited' }, 'acp process exited, settling pending requests');
|
|
468
|
+
this.settlePendingRequests('process exited');
|
|
469
|
+
});
|
|
447
470
|
}).catch(() => { /* ignore */ });
|
|
448
471
|
}
|
|
449
472
|
|
|
@@ -536,7 +559,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
536
559
|
else await this.setModel(requested);
|
|
537
560
|
const config = findConfigByCategory(this.configOptions, kind);
|
|
538
561
|
if (!config || config.currentValue === requested) {
|
|
539
|
-
|
|
562
|
+
this.log.info({ event: 'initial_config_applied', kind, requested }, 'applied initial config');
|
|
540
563
|
return null;
|
|
541
564
|
}
|
|
542
565
|
lastError = `agent confirmed "${config.currentValue ?? 'null'}" instead of "${requested}"`;
|
|
@@ -544,9 +567,9 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
544
567
|
lastError = (err as Error).message;
|
|
545
568
|
}
|
|
546
569
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
570
|
+
this.log.warn(
|
|
571
|
+
{ event: 'initial_config_failed', kind, requested, error: lastError },
|
|
572
|
+
'failed to apply initial config',
|
|
550
573
|
);
|
|
551
574
|
return `requested "${requested}": ${lastError}`;
|
|
552
575
|
}
|
|
@@ -575,9 +598,9 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
575
598
|
for (const kind of this.pendingInitialConfigKinds.splice(0)) {
|
|
576
599
|
const requested = kind === 'mode' ? this.initialModeId : this.initialModelId;
|
|
577
600
|
const error = `agent did not expose a ${kind} config option within ${timeoutMs}ms`;
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
601
|
+
this.log.warn(
|
|
602
|
+
{ event: 'initial_config_timeout', kind, requested, error },
|
|
603
|
+
'failed to apply initial config: config option not exposed',
|
|
581
604
|
);
|
|
582
605
|
this.recordInitialConfigStatus(kind, 'failed', `requested "${requested}": ${error}`);
|
|
583
606
|
}
|
|
@@ -705,31 +728,35 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
705
728
|
}
|
|
706
729
|
prompt.push({ type: 'text' as const, text: message.content });
|
|
707
730
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
prompt
|
|
711
|
-
|
|
731
|
+
// session.prompt:一条 prompt 一个 span(流式 chunk 不逐条开 span)
|
|
732
|
+
await withSpan('session.prompt', { sessionId: this.sessionId }, async (span) => {
|
|
733
|
+
this.activePrompt = this.connection!.prompt({
|
|
734
|
+
sessionId: this.acpSessionId!,
|
|
735
|
+
prompt,
|
|
736
|
+
});
|
|
712
737
|
|
|
713
|
-
|
|
738
|
+
this.socket.emit('acp:prompt:start', { sessionId: this.sessionId });
|
|
714
739
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
this.
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
740
|
+
let stopReason = 'end_turn';
|
|
741
|
+
try {
|
|
742
|
+
const result = await this.activePrompt;
|
|
743
|
+
stopReason = result?.stopReason ?? 'end_turn';
|
|
744
|
+
} catch {
|
|
745
|
+
stopReason = 'error';
|
|
746
|
+
} finally {
|
|
747
|
+
span.setAttribute('acp.stop_reason', stopReason);
|
|
748
|
+
this.activePrompt = null;
|
|
749
|
+
if (!this.stopped) {
|
|
750
|
+
this.socket.emit('acp:prompt:complete', {
|
|
751
|
+
sessionId: this.sessionId,
|
|
752
|
+
stopReason,
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
if (this.inputQueue.length > 0) {
|
|
756
|
+
this.processPrompt(this.inputQueue.shift()!);
|
|
757
|
+
}
|
|
731
758
|
}
|
|
732
|
-
}
|
|
759
|
+
});
|
|
733
760
|
}
|
|
734
761
|
|
|
735
762
|
private async initConnection(): Promise<void> {
|
|
@@ -772,10 +799,15 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
772
799
|
this.authMethodsRaw = result.authMethods ?? null;
|
|
773
800
|
this.authMethods = toAuthMethods(result.authMethods);
|
|
774
801
|
this.agentMcpCapabilities = result.agentCapabilities?.mcpCapabilities ?? null;
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
802
|
+
this.log.info(
|
|
803
|
+
{
|
|
804
|
+
event: 'agent_capabilities',
|
|
805
|
+
protocolVersion: result.protocolVersion ?? null,
|
|
806
|
+
mcp: this.agentMcpCapabilities,
|
|
807
|
+
agentName: this.agentInfo?.name ?? null,
|
|
808
|
+
agentVersion: this.agentInfo?.version ?? null,
|
|
809
|
+
},
|
|
810
|
+
'agent capabilities',
|
|
779
811
|
);
|
|
780
812
|
this.supportsAdditionalDirectories =
|
|
781
813
|
result.agentCapabilities?.sessionCapabilities?.additionalDirectories !== undefined &&
|
|
@@ -943,7 +975,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
943
975
|
handlePermissionResponse(requestId: string, outcome: acp.RequestPermissionOutcome): void {
|
|
944
976
|
const pending = this.pendingPermissions.get(requestId);
|
|
945
977
|
if (!pending) {
|
|
946
|
-
|
|
978
|
+
this.log.warn({ event: 'permission_response_unknown', requestId }, 'permission request not found');
|
|
947
979
|
return;
|
|
948
980
|
}
|
|
949
981
|
|
|
@@ -964,7 +996,10 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
964
996
|
// 否则「Agent 发起问询但用户从未看到弹窗」无法从日志/待办侧定位。
|
|
965
997
|
if (!acp.CreateElicitationRequest.isForm(params) && !acp.CreateElicitationRequest.isUrl(params)) {
|
|
966
998
|
const mode = (params as { mode?: unknown }).mode ?? 'unknown';
|
|
967
|
-
|
|
999
|
+
this.log.warn(
|
|
1000
|
+
{ event: 'elicitation_unsupported_mode', mode: String(mode).slice(0, 100) },
|
|
1001
|
+
'unsupported elicitation mode',
|
|
1002
|
+
);
|
|
968
1003
|
this.socket.emit('acp:elicitation:resolved', {
|
|
969
1004
|
requestId,
|
|
970
1005
|
sessionId: this.sessionId,
|
|
@@ -979,12 +1014,16 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
979
1014
|
|
|
980
1015
|
return new Promise((resolve) => {
|
|
981
1016
|
const timeout = setTimeout(() => {
|
|
1017
|
+
const pending = this.pendingElicitations.get(requestId);
|
|
982
1018
|
this.pendingElicitations.delete(requestId);
|
|
983
1019
|
this.emit('elicitation:settled', requestId);
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1020
|
+
this.log.warn(
|
|
1021
|
+
{
|
|
1022
|
+
event: 'elicitation_timeout',
|
|
1023
|
+
requestId,
|
|
1024
|
+
...(pending?.elicitationId ? { elicitationId: pending.elicitationId } : {}),
|
|
1025
|
+
},
|
|
1026
|
+
'elicitation timed out after 65s, auto-cancelling',
|
|
988
1027
|
);
|
|
989
1028
|
this.socket.emit('acp:elicitation:resolved', {
|
|
990
1029
|
requestId,
|
|
@@ -1042,7 +1081,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1042
1081
|
): void {
|
|
1043
1082
|
const pending = this.pendingElicitations.get(requestId);
|
|
1044
1083
|
if (!pending) {
|
|
1045
|
-
|
|
1084
|
+
this.log.warn({ event: 'elicitation_response_unknown', elicitationId: requestId }, 'elicitation request not found');
|
|
1046
1085
|
return;
|
|
1047
1086
|
}
|
|
1048
1087
|
|
|
@@ -1119,7 +1158,10 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1119
1158
|
}
|
|
1120
1159
|
|
|
1121
1160
|
private emitStopped(reason: string, exitCode?: number, silent = false): void {
|
|
1122
|
-
|
|
1161
|
+
this.log.info(
|
|
1162
|
+
{ event: 'acp_stopped', reason, exitCode: exitCode ?? null, silent },
|
|
1163
|
+
'acp session stopped',
|
|
1164
|
+
);
|
|
1123
1165
|
this.stopped = true;
|
|
1124
1166
|
if (this.textChunkTimer) {
|
|
1125
1167
|
clearTimeout(this.textChunkTimer);
|
|
@@ -1135,8 +1177,10 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1135
1177
|
|
|
1136
1178
|
private handleError(error: unknown): void {
|
|
1137
1179
|
const msg = error instanceof Error ? error.message : String(error);
|
|
1138
|
-
|
|
1139
|
-
|
|
1180
|
+
this.log.error(
|
|
1181
|
+
{ err: error instanceof Error ? error : new Error(msg) },
|
|
1182
|
+
'acp session failed',
|
|
1183
|
+
);
|
|
1140
1184
|
const wasStopped = this.stopped || this.silentStop;
|
|
1141
1185
|
this.stopped = true;
|
|
1142
1186
|
// 进程崩溃同样必须收敛 pending:否则 65s timer 泄漏且迟发 timeout 事件
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
|
+
import { logger } from '../observability/logger.js';
|
|
5
|
+
|
|
6
|
+
const log = logger.child({ component: 'process-registry' });
|
|
4
7
|
|
|
5
8
|
const REGISTRY_DIR = join(homedir(), '.zag');
|
|
6
9
|
const REGISTRY_FILE = join(REGISTRY_DIR, 'processes.json');
|
|
@@ -131,7 +134,7 @@ export class ProcessRegistry {
|
|
|
131
134
|
} catch (err) {
|
|
132
135
|
// Persistence is best-effort: a flush failure must never crash the
|
|
133
136
|
// controller (this can be called from timer callbacks).
|
|
134
|
-
|
|
137
|
+
log.warn({ err }, 'process registry flush failed');
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
140
|
}
|