agent-gear 2.23.0 → 2.26.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 +45 -13
- package/dist/acp/auth-gate.d.ts +35 -19
- package/dist/acp/auth-gate.d.ts.map +1 -1
- package/dist/acp/auth-gate.js +59 -41
- package/dist/acp/auth-gate.js.map +1 -1
- package/dist/acp/auth-gate.test.js +53 -56
- package/dist/acp/auth-gate.test.js.map +1 -1
- package/dist/acp/bridge.d.ts +13 -3
- package/dist/acp/bridge.d.ts.map +1 -1
- package/dist/acp/bridge.js +61 -18
- package/dist/acp/bridge.js.map +1 -1
- package/dist/acp/bridge.test.js +134 -20
- package/dist/acp/bridge.test.js.map +1 -1
- package/dist/acp/capabilities.d.ts.map +1 -1
- package/dist/acp/capabilities.js +2 -4
- package/dist/acp/capabilities.js.map +1 -1
- package/dist/acp/capabilities.test.js +2 -2
- package/dist/acp/capabilities.test.js.map +1 -1
- package/dist/acp/spawner.js +1 -1
- package/dist/acp/spawner.js.map +1 -1
- package/dist/acp/sync-bridge.d.ts.map +1 -1
- package/dist/acp/sync-bridge.js +2 -1
- package/dist/acp/sync-bridge.js.map +1 -1
- package/dist/harness/kimi-login.d.ts +44 -3
- package/dist/harness/kimi-login.d.ts.map +1 -1
- package/dist/harness/kimi-login.js +133 -4
- package/dist/harness/kimi-login.js.map +1 -1
- package/dist/harness/kimi-login.test.js +54 -1
- package/dist/harness/kimi-login.test.js.map +1 -1
- package/dist/socketio-client.auth-gate.test.js +48 -60
- package/dist/socketio-client.auth-gate.test.js.map +1 -1
- package/dist/socketio-client.d.ts.map +1 -1
- package/dist/socketio-client.js +80 -11
- package/dist/socketio-client.js.map +1 -1
- package/dist/version.d.ts +9 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/dist/version.test.d.ts +2 -0
- package/dist/version.test.d.ts.map +1 -0
- package/dist/version.test.js +27 -0
- package/dist/version.test.js.map +1 -0
- package/dist/worktree-handler.test.js +26 -0
- package/dist/worktree-handler.test.js.map +1 -1
- package/package.json +1 -1
- package/src/acp/auth-gate.test.ts +55 -58
- package/src/acp/auth-gate.ts +73 -43
- package/src/acp/bridge.test.ts +158 -20
- package/src/acp/bridge.ts +69 -18
- package/src/acp/capabilities.test.ts +2 -2
- package/src/acp/capabilities.ts +2 -4
- package/src/acp/spawner.ts +1 -1
- package/src/acp/sync-bridge.ts +2 -1
- package/src/harness/kimi-login.test.ts +60 -0
- package/src/harness/kimi-login.ts +149 -4
- package/src/socketio-client.auth-gate.test.ts +49 -60
- package/src/socketio-client.ts +98 -13
- package/src/version.test.ts +36 -0
- package/src/version.ts +13 -0
- package/src/worktree-handler.test.ts +31 -0
- package/tests/acp-bridge.test.ts +36 -5
- package/tests/acp-sync-bridge.test.ts +17 -1
- package/tests/manual/repro-question-tool.ts +8 -3
- package/tests/socketio-client.test.ts +138 -0
package/src/acp/bridge.test.ts
CHANGED
|
@@ -109,7 +109,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
109
109
|
expect(result).toEqual({ outcome: { outcome: 'selected', optionId: 'opt-1' } });
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
it('should resolve with cancelled after
|
|
112
|
+
it('should resolve with cancelled after 905s timeout', async () => {
|
|
113
113
|
const bridge = createBridge();
|
|
114
114
|
|
|
115
115
|
const promise = bridge.requestPermission({
|
|
@@ -117,7 +117,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
117
117
|
options: [{ optionId: 'opt-1', name: 'Allow', kind: 'allow_once' }],
|
|
118
118
|
} as never);
|
|
119
119
|
|
|
120
|
-
await vi.advanceTimersByTimeAsync(
|
|
120
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
121
121
|
|
|
122
122
|
const result = await promise;
|
|
123
123
|
expect(result).toEqual({ outcome: { outcome: 'cancelled' } });
|
|
@@ -140,7 +140,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
140
140
|
const result = await promise;
|
|
141
141
|
expect(result).toEqual({ outcome: { outcome: 'selected', optionId: 'opt-1' } });
|
|
142
142
|
|
|
143
|
-
await vi.advanceTimersByTimeAsync(
|
|
143
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
it('should warn and ignore invalid requestId in handlePermissionResponse', () => {
|
|
@@ -210,7 +210,7 @@ describe('AcpSessionBridge - requestPermission', () => {
|
|
|
210
210
|
options: [{ optionId: 'opt-1', name: 'Allow', kind: 'allow_once' }],
|
|
211
211
|
} as never);
|
|
212
212
|
|
|
213
|
-
await vi.advanceTimersByTimeAsync(
|
|
213
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
214
214
|
await promise;
|
|
215
215
|
|
|
216
216
|
const emitCall = mockSocket.emit.mock.calls.find((c: unknown[]) => c[0] === 'acp:permission');
|
|
@@ -879,7 +879,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
879
879
|
expect((resolved![1] as { detail: string }).detail).toHaveLength(100);
|
|
880
880
|
});
|
|
881
881
|
|
|
882
|
-
it('T-B4:
|
|
882
|
+
it('T-B4: 1805s 超时返回 cancel 并发出 resolved(timeout),不残留 pending', async () => {
|
|
883
883
|
const bridge = createBridge();
|
|
884
884
|
|
|
885
885
|
const promise = bridge.unstable_createElicitation({
|
|
@@ -891,13 +891,13 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
891
891
|
const emitCall = mockSocket.emit.mock.calls.find((c: unknown[]) => c[0] === 'acp:elicitation');
|
|
892
892
|
const requestId = (emitCall![1] as { requestId: string }).requestId;
|
|
893
893
|
|
|
894
|
-
await vi.advanceTimersByTimeAsync(
|
|
894
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
895
895
|
|
|
896
896
|
expect(await promise).toEqual({ action: 'cancel' });
|
|
897
897
|
expect(mockSocket.emit).toHaveBeenCalledWith('acp:elicitation:resolved', expect.objectContaining({
|
|
898
898
|
requestId,
|
|
899
899
|
reason: 'timeout',
|
|
900
|
-
detail: 'bridge timeout (
|
|
900
|
+
detail: 'bridge timeout (1805s)',
|
|
901
901
|
}));
|
|
902
902
|
expect(testLog.records).toContainEqual(
|
|
903
903
|
expect.objectContaining({ level: 'warn', event: 'elicitation_timeout', requestId }),
|
|
@@ -913,7 +913,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
913
913
|
);
|
|
914
914
|
});
|
|
915
915
|
|
|
916
|
-
it('T-B5: 正常 form 模式只发 acp:elicitation,响应后
|
|
916
|
+
it('T-B5: 正常 form 模式只发 acp:elicitation,响应后 1805s 内不发 resolved(clearTimeout 生效)', async () => {
|
|
917
917
|
const bridge = createBridge();
|
|
918
918
|
|
|
919
919
|
const promise = bridge.unstable_createElicitation({
|
|
@@ -929,8 +929,8 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
929
929
|
|
|
930
930
|
expect(await promise).toEqual({ action: 'accept', content: { answer: 'x' } });
|
|
931
931
|
|
|
932
|
-
// 推进
|
|
933
|
-
await vi.advanceTimersByTimeAsync(
|
|
932
|
+
// 推进 1805s:已响应的请求不得再发 timeout resolved
|
|
933
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
934
934
|
expect(mockSocket.emit).not.toHaveBeenCalledWith('acp:elicitation:resolved', expect.anything());
|
|
935
935
|
});
|
|
936
936
|
|
|
@@ -958,7 +958,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
958
958
|
expect(await promise).toEqual({ action: 'cancel' });
|
|
959
959
|
});
|
|
960
960
|
|
|
961
|
-
it('T-B5c: stop() 就地收敛 pending 问询为 cancelled,
|
|
961
|
+
it('T-B5c: stop() 就地收敛 pending 问询为 cancelled,1805s 后不再发 timeout', async () => {
|
|
962
962
|
const bridge = createBridge();
|
|
963
963
|
|
|
964
964
|
const promise = bridge.unstable_createElicitation({
|
|
@@ -979,7 +979,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
979
979
|
}));
|
|
980
980
|
|
|
981
981
|
mockSocket.emit.mockClear();
|
|
982
|
-
await vi.advanceTimersByTimeAsync(
|
|
982
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
983
983
|
expect(mockSocket.emit).not.toHaveBeenCalledWith('acp:elicitation:resolved', expect.anything());
|
|
984
984
|
});
|
|
985
985
|
|
|
@@ -997,8 +997,8 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
997
997
|
|
|
998
998
|
expect(await promise).toEqual({ outcome: { outcome: 'cancelled' } });
|
|
999
999
|
expect(settled).toHaveBeenCalledTimes(1);
|
|
1000
|
-
await vi.advanceTimersByTimeAsync(
|
|
1001
|
-
// timer 已清理:
|
|
1000
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
1001
|
+
// timer 已清理:905s 后不会再有新的 permission 事件,且不会二次 settled
|
|
1002
1002
|
expect(mockSocket.emit.mock.calls.filter((c: unknown[]) => c[0] === 'acp:permission')).toHaveLength(1);
|
|
1003
1003
|
expect(settled).toHaveBeenCalledTimes(1);
|
|
1004
1004
|
});
|
|
@@ -1101,7 +1101,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1101
1101
|
await stopPromise;
|
|
1102
1102
|
});
|
|
1103
1103
|
|
|
1104
|
-
it('T-B11: 进程退出(spawner.closed)收敛 pending 并发 cancelled,
|
|
1104
|
+
it('T-B11: 进程退出(spawner.closed)收敛 pending 并发 cancelled,1805s 后不再发 timeout', async () => {
|
|
1105
1105
|
const bridge = createBridge();
|
|
1106
1106
|
await bridge.start();
|
|
1107
1107
|
|
|
@@ -1125,11 +1125,11 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1125
1125
|
detail: 'process exited',
|
|
1126
1126
|
}));
|
|
1127
1127
|
|
|
1128
|
-
// 真实时钟推进
|
|
1128
|
+
// 真实时钟推进 1805s:timer 已清理,不得再发 timeout
|
|
1129
1129
|
const resolvedReasons = mockSocket.emit.mock.calls
|
|
1130
1130
|
.filter((c: unknown[]) => c[0] === 'acp:elicitation:resolved')
|
|
1131
1131
|
.map((c: unknown[]) => (c[1] as { reason: string }).reason);
|
|
1132
|
-
await vi.advanceTimersByTimeAsync(
|
|
1132
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
1133
1133
|
const afterReasons = mockSocket.emit.mock.calls
|
|
1134
1134
|
.filter((c: unknown[]) => c[0] === 'acp:elicitation:resolved')
|
|
1135
1135
|
.map((c: unknown[]) => (c[1] as { reason: string }).reason);
|
|
@@ -1150,7 +1150,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1150
1150
|
bridge.settlePendingOnDisconnect();
|
|
1151
1151
|
|
|
1152
1152
|
expect(await promise).toEqual({ action: 'cancel' });
|
|
1153
|
-
await vi.advanceTimersByTimeAsync(
|
|
1153
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
1154
1154
|
const reasons = mockSocket.emit.mock.calls
|
|
1155
1155
|
.filter((c: unknown[]) => c[0] === 'acp:elicitation:resolved')
|
|
1156
1156
|
.map((c: unknown[]) => (c[1] as { reason: string }).reason);
|
|
@@ -1183,7 +1183,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1183
1183
|
const permissionId = (mockSocket.emit.mock.calls.find(
|
|
1184
1184
|
(c: unknown[]) => c[0] === 'acp:permission',
|
|
1185
1185
|
)![1] as { requestId: string }).requestId;
|
|
1186
|
-
await vi.advanceTimersByTimeAsync(
|
|
1186
|
+
await vi.advanceTimersByTimeAsync(905_000);
|
|
1187
1187
|
await permissionPromise;
|
|
1188
1188
|
expect(permissionSettled).toHaveBeenCalledWith(permissionId);
|
|
1189
1189
|
});
|
|
@@ -1216,7 +1216,7 @@ describe('AcpSessionBridge - elicitation observability', () => {
|
|
|
1216
1216
|
}));
|
|
1217
1217
|
|
|
1218
1218
|
mockSocket.emit.mockClear();
|
|
1219
|
-
await vi.advanceTimersByTimeAsync(
|
|
1219
|
+
await vi.advanceTimersByTimeAsync(1_805_000);
|
|
1220
1220
|
expect(mockSocket.emit).not.toHaveBeenCalledWith('acp:elicitation:resolved', expect.anything());
|
|
1221
1221
|
});
|
|
1222
1222
|
});
|
|
@@ -1294,6 +1294,39 @@ describe('AcpSessionBridge - processPrompt 有序 parts(2.17.0)', () => {
|
|
|
1294
1294
|
expect(prompt.mock.calls[1][0].prompt).toEqual([{ type: 'text', text: 'plain' }]);
|
|
1295
1295
|
});
|
|
1296
1296
|
|
|
1297
|
+
it('T-ATT1 parts 非文本映射:audio/resource/resource_link 与 text/image 保序一致', async () => {
|
|
1298
|
+
const bridge = createBridge();
|
|
1299
|
+
await bridge.start();
|
|
1300
|
+
const prompt = connectionPrompt();
|
|
1301
|
+
|
|
1302
|
+
bridge.sendInput({
|
|
1303
|
+
type: 'text',
|
|
1304
|
+
content: 'x',
|
|
1305
|
+
parts: [
|
|
1306
|
+
{ type: 'audio', data: 'AUDIO', mimeType: 'audio/mpeg' },
|
|
1307
|
+
{ type: 'resource_link', uri: 'https://example.com/a.txt', name: 'a.txt', size: 12 },
|
|
1308
|
+
{ type: 'resource', uri: 'file:///tmp/b.txt', text: 'body', mimeType: 'text/plain' },
|
|
1309
|
+
{ type: 'text', text: 'tail' },
|
|
1310
|
+
],
|
|
1311
|
+
});
|
|
1312
|
+
|
|
1313
|
+
await vi.waitFor(() => expect(prompt).toHaveBeenCalledTimes(1));
|
|
1314
|
+
expect(prompt.mock.calls[0][0].prompt).toEqual([
|
|
1315
|
+
{ type: 'audio', data: 'AUDIO', mimeType: 'audio/mpeg' },
|
|
1316
|
+
{
|
|
1317
|
+
type: 'resource_link',
|
|
1318
|
+
uri: 'https://example.com/a.txt',
|
|
1319
|
+
name: 'a.txt',
|
|
1320
|
+
size: 12,
|
|
1321
|
+
},
|
|
1322
|
+
{
|
|
1323
|
+
type: 'resource',
|
|
1324
|
+
resource: { uri: 'file:///tmp/b.txt', text: 'body', mimeType: 'text/plain' },
|
|
1325
|
+
},
|
|
1326
|
+
{ type: 'text', text: 'tail' },
|
|
1327
|
+
]);
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1297
1330
|
it('T-BR3 activePrompt 排队:parts 报文入队后按序消费', async () => {
|
|
1298
1331
|
const bridge = createBridge();
|
|
1299
1332
|
await bridge.start();
|
|
@@ -1314,3 +1347,108 @@ describe('AcpSessionBridge - processPrompt 有序 parts(2.17.0)', () => {
|
|
|
1314
1347
|
]);
|
|
1315
1348
|
});
|
|
1316
1349
|
});
|
|
1350
|
+
|
|
1351
|
+
describe('AcpSessionBridge - setConfigOption 布尔归一(T-CFG1~4)', () => {
|
|
1352
|
+
let mockSocket: ReturnType<typeof createMockSocket>;
|
|
1353
|
+
let mockSpawner: MockAcpSpawner;
|
|
1354
|
+
|
|
1355
|
+
function createBridge() {
|
|
1356
|
+
return new AcpSessionBridge(
|
|
1357
|
+
mockSocket as never,
|
|
1358
|
+
{ sessionId: 'sess-cfg', cwd: '/home/user', logger: testLog.logger },
|
|
1359
|
+
mockSpawner as never,
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
beforeEach(() => {
|
|
1364
|
+
vi.clearAllMocks();
|
|
1365
|
+
mockSocket = createMockSocket();
|
|
1366
|
+
mockSpawner = new MockAcpSpawner();
|
|
1367
|
+
testLog = createTestLogger('acp-bridge-cfg');
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1370
|
+
afterEach(() => {
|
|
1371
|
+
vi.restoreAllMocks();
|
|
1372
|
+
});
|
|
1373
|
+
|
|
1374
|
+
async function startedBridge() {
|
|
1375
|
+
mockNewSession.mockResolvedValueOnce({
|
|
1376
|
+
sessionId: 'acp-sess-abc',
|
|
1377
|
+
configOptions: [
|
|
1378
|
+
{ id: 'flag', name: 'Flag', type: 'boolean', currentValue: false },
|
|
1379
|
+
{ id: 'mode', name: 'Mode', type: 'select', currentValue: 'build', options: [{ value: 'build', name: 'Build' }] },
|
|
1380
|
+
],
|
|
1381
|
+
});
|
|
1382
|
+
const bridge = createBridge();
|
|
1383
|
+
await bridge.start();
|
|
1384
|
+
return bridge;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
it('T-CFG1 布尔值 wire 形态:{ value: bool, type: "boolean" }', async () => {
|
|
1388
|
+
const bridge = await startedBridge();
|
|
1389
|
+
mockSetSessionConfigOption.mockResolvedValueOnce({});
|
|
1390
|
+
|
|
1391
|
+
await bridge.setConfigOption('flag', true);
|
|
1392
|
+
|
|
1393
|
+
expect(mockSetSessionConfigOption).toHaveBeenCalledWith({
|
|
1394
|
+
sessionId: 'acp-sess-abc',
|
|
1395
|
+
configId: 'flag',
|
|
1396
|
+
value: true,
|
|
1397
|
+
type: 'boolean',
|
|
1398
|
+
});
|
|
1399
|
+
});
|
|
1400
|
+
|
|
1401
|
+
it('T-CFG2 字符串二次归一:本地快照为 boolean 时 "TRUE"/"false" 均转布尔', async () => {
|
|
1402
|
+
const bridge = await startedBridge();
|
|
1403
|
+
mockSetSessionConfigOption.mockResolvedValue({});
|
|
1404
|
+
|
|
1405
|
+
await bridge.setConfigOption('flag', 'TRUE');
|
|
1406
|
+
await bridge.setConfigOption('flag', 'false');
|
|
1407
|
+
|
|
1408
|
+
expect(mockSetSessionConfigOption).toHaveBeenNthCalledWith(1, {
|
|
1409
|
+
sessionId: 'acp-sess-abc',
|
|
1410
|
+
configId: 'flag',
|
|
1411
|
+
value: true,
|
|
1412
|
+
type: 'boolean',
|
|
1413
|
+
});
|
|
1414
|
+
expect(mockSetSessionConfigOption).toHaveBeenNthCalledWith(2, {
|
|
1415
|
+
sessionId: 'acp-sess-abc',
|
|
1416
|
+
configId: 'flag',
|
|
1417
|
+
value: false,
|
|
1418
|
+
type: 'boolean',
|
|
1419
|
+
});
|
|
1420
|
+
});
|
|
1421
|
+
|
|
1422
|
+
it('T-CFG3 非 boolean 配置项零回归:字符串原样、无 type 字段', async () => {
|
|
1423
|
+
const bridge = await startedBridge();
|
|
1424
|
+
mockSetSessionConfigOption.mockResolvedValue({});
|
|
1425
|
+
|
|
1426
|
+
await bridge.setConfigOption('mode', 'code');
|
|
1427
|
+
await bridge.setConfigOption('unknown', 'true');
|
|
1428
|
+
|
|
1429
|
+
expect(mockSetSessionConfigOption).toHaveBeenNthCalledWith(1, {
|
|
1430
|
+
sessionId: 'acp-sess-abc',
|
|
1431
|
+
configId: 'mode',
|
|
1432
|
+
value: 'code',
|
|
1433
|
+
});
|
|
1434
|
+
expect(mockSetSessionConfigOption).toHaveBeenNthCalledWith(2, {
|
|
1435
|
+
sessionId: 'acp-sess-abc',
|
|
1436
|
+
configId: 'unknown',
|
|
1437
|
+
value: 'true',
|
|
1438
|
+
});
|
|
1439
|
+
});
|
|
1440
|
+
|
|
1441
|
+
it('T-CFG4 成功响应快照回发 acp:config-options(零回归)', async () => {
|
|
1442
|
+
const bridge = await startedBridge();
|
|
1443
|
+
mockSetSessionConfigOption.mockResolvedValueOnce({
|
|
1444
|
+
configOptions: [{ id: 'flag', name: 'Flag', type: 'boolean', currentValue: true }],
|
|
1445
|
+
});
|
|
1446
|
+
|
|
1447
|
+
await bridge.setConfigOption('flag', 'true');
|
|
1448
|
+
|
|
1449
|
+
expect(mockSocket.emit).toHaveBeenCalledWith('acp:config-options', {
|
|
1450
|
+
sessionId: 'sess-cfg',
|
|
1451
|
+
configOptions: [expect.objectContaining({ id: 'flag', type: 'boolean', currentValue: 'true' })],
|
|
1452
|
+
});
|
|
1453
|
+
});
|
|
1454
|
+
});
|
package/src/acp/bridge.ts
CHANGED
|
@@ -9,9 +9,14 @@ import {
|
|
|
9
9
|
} from './capabilities.js';
|
|
10
10
|
import { logger as rootLogger, type ObservationLogger } from '../observability/logger.js';
|
|
11
11
|
import { withSpan } from '../observability/trace.js';
|
|
12
|
+
import { CONTROLLER_VERSION } from '../version.js';
|
|
12
13
|
|
|
13
14
|
const ACP_PROTOCOL_VERSION = 1;
|
|
14
15
|
|
|
16
|
+
/** 问询/授权兜底超时 = controller-api 权威超时 + 5s race 余量(提问 30 分钟 / 权限审批 15 分钟) */
|
|
17
|
+
const ELICITATION_FALLBACK_TIMEOUT_MS = 1_805_000;
|
|
18
|
+
const PERMISSION_FALLBACK_TIMEOUT_MS = 905_000;
|
|
19
|
+
|
|
15
20
|
/** 初始 mode/model 应用后回读确认失败时的重试间隔 */
|
|
16
21
|
const INITIAL_CONFIG_RETRY_DELAY_MS = 300;
|
|
17
22
|
|
|
@@ -45,10 +50,15 @@ interface QueuedInput {
|
|
|
45
50
|
|
|
46
51
|
/** acp:message parts 元素(契约 agent-session-websocket.md §2.6 AcpPromptPart) */
|
|
47
52
|
export interface AcpPromptPart {
|
|
48
|
-
type: 'text' | 'image';
|
|
53
|
+
type: 'text' | 'image' | 'audio' | 'resource' | 'resource_link';
|
|
49
54
|
text?: string;
|
|
50
55
|
data?: string;
|
|
51
56
|
mimeType?: string;
|
|
57
|
+
uri?: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
title?: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
size?: number;
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
export interface SessionConfigOptionData {
|
|
@@ -174,6 +184,38 @@ export function extractConfigOptions(
|
|
|
174
184
|
});
|
|
175
185
|
}
|
|
176
186
|
|
|
187
|
+
/**
|
|
188
|
+
* 把 AcpPromptPart 映射为 ACP ContentBlock(契约 §2.6)。
|
|
189
|
+
* 非文本类型与 text/image 同口径保序;未知类型降级为文本块(防御旧上游)。
|
|
190
|
+
*/
|
|
191
|
+
export function mapPromptPart(part: AcpPromptPart): acp.ContentBlock {
|
|
192
|
+
switch (part.type) {
|
|
193
|
+
case 'image':
|
|
194
|
+
return { type: 'image', data: part.data ?? '', mimeType: part.mimeType ?? 'image/png' };
|
|
195
|
+
case 'audio':
|
|
196
|
+
return { type: 'audio', data: part.data ?? '', mimeType: part.mimeType ?? 'audio/mpeg' };
|
|
197
|
+
case 'resource_link':
|
|
198
|
+
return {
|
|
199
|
+
type: 'resource_link',
|
|
200
|
+
uri: part.uri ?? '',
|
|
201
|
+
name: part.name ?? part.title ?? part.uri ?? '',
|
|
202
|
+
...(part.title ? { title: part.title } : {}),
|
|
203
|
+
...(part.description ? { description: part.description } : {}),
|
|
204
|
+
...(part.mimeType ? { mimeType: part.mimeType } : {}),
|
|
205
|
+
...(typeof part.size === 'number' ? { size: part.size } : {}),
|
|
206
|
+
};
|
|
207
|
+
case 'resource': {
|
|
208
|
+
const resource = typeof part.text === 'string'
|
|
209
|
+
? { uri: part.uri ?? '', text: part.text, ...(part.mimeType ? { mimeType: part.mimeType } : {}) }
|
|
210
|
+
: { uri: part.uri ?? '', blob: part.data ?? '', ...(part.mimeType ? { mimeType: part.mimeType } : {}) };
|
|
211
|
+
return { type: 'resource', resource };
|
|
212
|
+
}
|
|
213
|
+
case 'text':
|
|
214
|
+
default:
|
|
215
|
+
return { type: 'text', text: part.text ?? '' };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
177
219
|
function findConfigByCategory(
|
|
178
220
|
configOptions: SessionConfigOptionData[],
|
|
179
221
|
category: string,
|
|
@@ -418,7 +460,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
418
460
|
this.activePrompt = null;
|
|
419
461
|
this.inputQueue = [];
|
|
420
462
|
// 会话关闭:所有在途问询/授权必须先同步收敛(在 cancel/closeSession 的 5s race 之前),
|
|
421
|
-
// 否则 race 窗口内
|
|
463
|
+
// 否则 race 窗口内 1805s/905s timer 仍可能迟到发 timeout。
|
|
422
464
|
this.settlePendingRequests('session stopped by user');
|
|
423
465
|
this.clearPendingInitialConfig();
|
|
424
466
|
let stopTimer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -442,7 +484,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
442
484
|
|
|
443
485
|
/**
|
|
444
486
|
* 清空 pending 请求:clearTimeout + resolve(cancel) + delete。
|
|
445
|
-
* 问询额外回发 resolved(cancelled),让服务端待办收敛为 cancelled 而不是等
|
|
487
|
+
* 问询额外回发 resolved(cancelled),让服务端待办收敛为 cancelled 而不是等 1805s 超时误标 expired。
|
|
446
488
|
* 同时发出 settled 事件,供 socketio-client 清理 requestId → bridge 映射(避免 Map 单调增长/阻止 GC)。
|
|
447
489
|
*/
|
|
448
490
|
private settlePendingRequests(detail: string): void {
|
|
@@ -677,10 +719,20 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
677
719
|
if (!this.connection || !this.acpSessionId) {
|
|
678
720
|
throw new Error('ACP bridge is not initialized');
|
|
679
721
|
}
|
|
722
|
+
// 布尔配置项按本地快照二次归一:兼容旧上游(agent-api 未转换时)传 'true'/'false' 字符串;
|
|
723
|
+
// 无定义信息时维持字符串原样(零回归)。
|
|
724
|
+
const definition = this.configOptions.find((opt) => opt.id === configId);
|
|
725
|
+
let wireValue: string | boolean = value;
|
|
726
|
+
if (typeof value === 'string' && definition?.type === 'boolean') {
|
|
727
|
+
const normalized = value.trim().toLowerCase();
|
|
728
|
+
if (normalized === 'true' || normalized === 'false') {
|
|
729
|
+
wireValue = normalized === 'true';
|
|
730
|
+
}
|
|
731
|
+
}
|
|
680
732
|
const response = await this.connection.setSessionConfigOption({
|
|
681
733
|
sessionId: this.acpSessionId,
|
|
682
734
|
configId,
|
|
683
|
-
...(typeof
|
|
735
|
+
...(typeof wireValue === 'boolean' ? { value: wireValue, type: 'boolean' as const } : { value: wireValue }),
|
|
684
736
|
});
|
|
685
737
|
if (response.configOptions) {
|
|
686
738
|
// SDK 1.3.0:set_config_option 响应携带全量快照,与 config_option_update 通知同源
|
|
@@ -693,11 +745,14 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
693
745
|
return response;
|
|
694
746
|
}
|
|
695
747
|
|
|
696
|
-
async authenticate(methodId: string): Promise<void> {
|
|
748
|
+
async authenticate(methodId: string, input?: Record<string, unknown>): Promise<void> {
|
|
697
749
|
if (!this.connection) {
|
|
698
750
|
throw new Error('ACP bridge is not initialized');
|
|
699
751
|
}
|
|
700
|
-
|
|
752
|
+
// 契约 §2.26:`input` 承载认证所需用户输入(如环境变量值),凭据仅内存透传,
|
|
753
|
+
// 不落库、不进日志。SDK 1.9.0 的 AuthenticateRequest 类型尚未声明 `input`,
|
|
754
|
+
// 按原始 wire 透传(Agent 侧按 schema 自行消费,未知字段忽略)。
|
|
755
|
+
await this.connection.authenticate({ methodId, input } as unknown as acp.AuthenticateRequest);
|
|
701
756
|
}
|
|
702
757
|
|
|
703
758
|
async logout(): Promise<void> {
|
|
@@ -737,11 +792,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
737
792
|
if (message.parts && message.parts.length > 0) {
|
|
738
793
|
// parts 非空:按序映射(保序),不追加 content 文本块(content 仅为合并文本兼容字段)
|
|
739
794
|
for (const part of message.parts) {
|
|
740
|
-
|
|
741
|
-
prompt.push({ type: 'text' as const, text: part.text ?? '' });
|
|
742
|
-
} else {
|
|
743
|
-
prompt.push({ type: 'image' as const, data: part.data ?? '', mimeType: part.mimeType ?? 'image/png' });
|
|
744
|
-
}
|
|
795
|
+
prompt.push(mapPromptPart(part));
|
|
745
796
|
}
|
|
746
797
|
} else {
|
|
747
798
|
for (const attachment of message.attachments ?? []) {
|
|
@@ -791,7 +842,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
791
842
|
clientCapabilities: CLIENT_CAPABILITIES,
|
|
792
843
|
clientInfo: {
|
|
793
844
|
name: 'agent-gear',
|
|
794
|
-
version:
|
|
845
|
+
version: CONTROLLER_VERSION,
|
|
795
846
|
},
|
|
796
847
|
});
|
|
797
848
|
|
|
@@ -979,7 +1030,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
979
1030
|
this.pendingPermissions.delete(requestId);
|
|
980
1031
|
this.emit('permission:settled', requestId);
|
|
981
1032
|
resolve({ outcome: { outcome: 'cancelled' } });
|
|
982
|
-
},
|
|
1033
|
+
}, PERMISSION_FALLBACK_TIMEOUT_MS);
|
|
983
1034
|
|
|
984
1035
|
this.pendingPermissions.set(requestId, { resolve, timeout });
|
|
985
1036
|
|
|
@@ -1045,16 +1096,16 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1045
1096
|
requestId,
|
|
1046
1097
|
...(pending?.elicitationId ? { elicitationId: pending.elicitationId } : {}),
|
|
1047
1098
|
},
|
|
1048
|
-
'elicitation timed out after
|
|
1099
|
+
'elicitation timed out after 1805s, auto-cancelling',
|
|
1049
1100
|
);
|
|
1050
1101
|
this.socket.emit('acp:elicitation:resolved', {
|
|
1051
1102
|
requestId,
|
|
1052
1103
|
sessionId: this.sessionId,
|
|
1053
1104
|
reason: 'timeout',
|
|
1054
|
-
detail: 'bridge timeout (
|
|
1105
|
+
detail: 'bridge timeout (1805s)',
|
|
1055
1106
|
});
|
|
1056
1107
|
resolve({ action: 'cancel' });
|
|
1057
|
-
},
|
|
1108
|
+
}, ELICITATION_FALLBACK_TIMEOUT_MS);
|
|
1058
1109
|
|
|
1059
1110
|
this.pendingElicitations.set(requestId, {
|
|
1060
1111
|
resolve,
|
|
@@ -1124,7 +1175,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1124
1175
|
elicitationId: params.elicitationId,
|
|
1125
1176
|
});
|
|
1126
1177
|
|
|
1127
|
-
// Agent 自行完成/取消:对匹配的 pending 就地收敛,避免悬挂到
|
|
1178
|
+
// Agent 自行完成/取消:对匹配的 pending 就地收敛,避免悬挂到 1805s 被误标 expired。
|
|
1128
1179
|
// 契约 reason:'cancelled' 的产生路径之一(另一处为会话关闭 settle)。
|
|
1129
1180
|
const entry = [...this.pendingElicitations.entries()]
|
|
1130
1181
|
.find(([, pending]) => pending.elicitationId === params.elicitationId);
|
|
@@ -1205,7 +1256,7 @@ export class AcpSessionBridge extends EventEmitter implements acp.Client {
|
|
|
1205
1256
|
);
|
|
1206
1257
|
const wasStopped = this.stopped || this.silentStop;
|
|
1207
1258
|
this.stopped = true;
|
|
1208
|
-
// 进程崩溃同样必须收敛 pending:否则
|
|
1259
|
+
// 进程崩溃同样必须收敛 pending:否则 1805s timer 泄漏且迟发 timeout 事件
|
|
1209
1260
|
this.settlePendingRequests('session failed');
|
|
1210
1261
|
this.clearPendingInitialConfig();
|
|
1211
1262
|
// 已停止(含 silent 替换/对账)后迟到的初始化失败:不得再发 stopped,
|
|
@@ -63,11 +63,11 @@ describe('normalizeCapabilities', () => {
|
|
|
63
63
|
for (const id of ['session.load', 'session.resume', 'session.close', 'session.list', 'session.delete']) {
|
|
64
64
|
expect(statusOf(snapshot, id)?.status).toBe('supported');
|
|
65
65
|
}
|
|
66
|
-
expect(statusOf(snapshot, 'prompt.image')?.status).toBe('
|
|
66
|
+
expect(statusOf(snapshot, 'prompt.image')?.status).toBe('supported');
|
|
67
67
|
expect(statusOf(snapshot, 'prompt.embeddedContext')?.status).toBe('partial');
|
|
68
68
|
expect(statusOf(snapshot, 'prompt.audio')?.status).toBe('unsupported');
|
|
69
69
|
expect(statusOf(snapshot, 'session.fork')?.status).toBe('partial');
|
|
70
|
-
expect(statusOf(snapshot, 'session.additionalDirectories')?.status).toBe('
|
|
70
|
+
expect(statusOf(snapshot, 'session.additionalDirectories')?.status).toBe('supported');
|
|
71
71
|
expect(statusOf(snapshot, 'config.model')?.status).toBe('supported');
|
|
72
72
|
expect(statusOf(snapshot, 'config.mode')?.status).toBe('supported');
|
|
73
73
|
expect(statusOf(snapshot, 'mcp.http')?.status).toBe('supported');
|
package/src/acp/capabilities.ts
CHANGED
|
@@ -46,8 +46,8 @@ const PLATFORM_SUPPORT: Record<string, PlatformSupport> = {
|
|
|
46
46
|
'session.list': 'full',
|
|
47
47
|
'session.delete': 'full',
|
|
48
48
|
'session.fork': 'none',
|
|
49
|
-
'session.additionalDirectories': '
|
|
50
|
-
'prompt.image': '
|
|
49
|
+
'session.additionalDirectories': 'full',
|
|
50
|
+
'prompt.image': 'full',
|
|
51
51
|
'prompt.audio': 'none',
|
|
52
52
|
'prompt.embeddedContext': 'none',
|
|
53
53
|
'auth.login': 'none',
|
|
@@ -112,8 +112,6 @@ const SOURCE_FIELD: Record<string, string> = {
|
|
|
112
112
|
|
|
113
113
|
const PLATFORM_LIMITATION: Partial<Record<string, string>> = {
|
|
114
114
|
'session.fork': '平台暂未提供入口',
|
|
115
|
-
'session.additionalDirectories': '平台暂未提供入口',
|
|
116
|
-
'prompt.image': '平台暂未提供附件入口',
|
|
117
115
|
'prompt.audio': '平台暂未提供附件入口',
|
|
118
116
|
'prompt.embeddedContext': '平台暂未提供附件入口',
|
|
119
117
|
'auth.login': '平台暂未提供认证入口',
|
package/src/acp/spawner.ts
CHANGED
|
@@ -125,7 +125,7 @@ export class AcpSpawner {
|
|
|
125
125
|
|
|
126
126
|
this.process.on('error', (error) => {
|
|
127
127
|
this.log.error({ event: 'acp_process_error', command: cmd, err: error }, 'acp process error');
|
|
128
|
-
// spawn 失败同样视为进程终止:必须 resolve closed,让 bridge 收敛 pending,避免
|
|
128
|
+
// spawn 失败同样视为进程终止:必须 resolve closed,让 bridge 收敛 pending,避免 1805s(提问)/905s(权限审批)迟到 timeout
|
|
129
129
|
this.process = null;
|
|
130
130
|
this.resolveClosed?.();
|
|
131
131
|
});
|
package/src/acp/sync-bridge.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as acp from '@agentclientprotocol/sdk';
|
|
|
2
2
|
import { AcpSpawner } from './spawner.js';
|
|
3
3
|
import { CLIENT_CAPABILITIES } from './capabilities.js';
|
|
4
4
|
import { logger } from '../observability/logger.js';
|
|
5
|
+
import { CONTROLLER_VERSION } from '../version.js';
|
|
5
6
|
|
|
6
7
|
const log = logger.child({ component: 'acp-sync-bridge' });
|
|
7
8
|
|
|
@@ -55,7 +56,7 @@ export class AcpSyncBridge implements acp.Client {
|
|
|
55
56
|
const initPromise = this.connection.initialize({
|
|
56
57
|
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
57
58
|
clientCapabilities: CLIENT_CAPABILITIES,
|
|
58
|
-
clientInfo: { name: 'agent-gear', version:
|
|
59
|
+
clientInfo: { name: 'agent-gear', version: CONTROLLER_VERSION },
|
|
59
60
|
});
|
|
60
61
|
|
|
61
62
|
const result = await withTimeout(
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from 'vitest';
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { existsSync, mkdtempSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
3
6
|
import {
|
|
4
7
|
KimiLoginFlow,
|
|
8
|
+
KimiLogoutFlow,
|
|
5
9
|
classifyExit,
|
|
10
|
+
detectKimiLoggedIn,
|
|
6
11
|
parseKimiLoginLine,
|
|
7
12
|
resolveKimiLoginWaitMs,
|
|
8
13
|
sanitizeErrorSummary,
|
|
@@ -220,3 +225,58 @@ describe('KimiLoginFlow', () => {
|
|
|
220
225
|
await expect(pending).resolves.toMatchObject({ state: 'failed', reason: 'error' });
|
|
221
226
|
});
|
|
222
227
|
});
|
|
228
|
+
|
|
229
|
+
describe('KimiLogoutFlow(2.26.0 主动登出)', () => {
|
|
230
|
+
function logoutSetup(exitCode: number | null = 0) {
|
|
231
|
+
const child = createFakeChild();
|
|
232
|
+
const spawnFn = vi.fn(() => child);
|
|
233
|
+
const credentialsDir = mkdtempSync(join(tmpdir(), "kimi-logout-"));
|
|
234
|
+
const flow = new KimiLogoutFlow({ spawnFn: spawnFn as never, credentialsDir });
|
|
235
|
+
return { child, spawnFn, flow, credentialsDir };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
it('T-HLO1: kimi logout 退出码 0 → 成功且清理凭据目录', async () => {
|
|
239
|
+
const { child, spawnFn, flow, credentialsDir } = logoutSetup(0);
|
|
240
|
+
writeFileSync(join(credentialsDir, 'kimi.json'), '{}');
|
|
241
|
+
const pending = flow.run();
|
|
242
|
+
await tick();
|
|
243
|
+
child.emit('exit', 0, null);
|
|
244
|
+
await expect(pending).resolves.toEqual({ success: true, usedFallback: false });
|
|
245
|
+
expect(spawnFn).toHaveBeenCalledWith('kimi', ['logout'], expect.anything());
|
|
246
|
+
expect(existsSync(credentialsDir)).toBe(false);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('T-HLO2: 非零退出 → 回退删除凭据目录且判成功', async () => {
|
|
250
|
+
const { child, flow, credentialsDir } = logoutSetup(1);
|
|
251
|
+
writeFileSync(join(credentialsDir, 'kimi.json'), '{}');
|
|
252
|
+
const pending = flow.run();
|
|
253
|
+
await tick();
|
|
254
|
+
child.emit('exit', 1, null);
|
|
255
|
+
await expect(pending).resolves.toEqual({ success: true, usedFallback: true });
|
|
256
|
+
expect(existsSync(credentialsDir)).toBe(false);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('T-HLO3: spawn 不可用(ENOENT)→ 回退删除凭据目录', async () => {
|
|
260
|
+
const credentialsDir = mkdtempSync(join(tmpdir(), "kimi-logout-"));
|
|
261
|
+
writeFileSync(join(credentialsDir, 'kimi.json'), '{}');
|
|
262
|
+
const flow = new KimiLogoutFlow({
|
|
263
|
+
spawnFn: (() => {
|
|
264
|
+
throw Object.assign(new Error('spawn kimi ENOENT'), { code: 'ENOENT' });
|
|
265
|
+
}) as never,
|
|
266
|
+
credentialsDir,
|
|
267
|
+
});
|
|
268
|
+
await expect(flow.run()).resolves.toEqual({ success: true, usedFallback: true });
|
|
269
|
+
expect(existsSync(credentialsDir)).toBe(false);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('T-HLO4: 登录态探测只 stat 凭据目录(存在/不存在/异常)', async () => {
|
|
273
|
+
const credentialsDir = join(mkdtempSync(join(tmpdir(), 'kimi-detect-')), 'credentials');
|
|
274
|
+
await expect(detectKimiLoggedIn(credentialsDir)).resolves.toBe(false);
|
|
275
|
+
mkdirSync(credentialsDir, { recursive: true });
|
|
276
|
+
writeFileSync(join(credentialsDir, 'other.txt'), 'x');
|
|
277
|
+
await expect(detectKimiLoggedIn(credentialsDir)).resolves.toBe(false);
|
|
278
|
+
writeFileSync(join(credentialsDir, 'creds.json'), '{}');
|
|
279
|
+
await expect(detectKimiLoggedIn(credentialsDir)).resolves.toBe(true);
|
|
280
|
+
await expect(detectKimiLoggedIn(join(credentialsDir, 'missing'))).resolves.toBe(false);
|
|
281
|
+
});
|
|
282
|
+
});
|