@ai-devkit/agent-manager 0.22.1 → 0.25.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/README.md +3 -0
- package/dist/__tests__/AgentManager.test.js +9 -1
- package/dist/__tests__/AgentManager.test.js.map +1 -1
- package/dist/__tests__/adapters/GrokCliAdapter.test.js +403 -0
- package/dist/__tests__/adapters/GrokCliAdapter.test.js.map +1 -0
- package/dist/__tests__/terminal/TerminalFocusManager.test.js +180 -0
- package/dist/__tests__/terminal/TerminalFocusManager.test.js.map +1 -1
- package/dist/__tests__/terminal/TtyWriter.test.js +206 -0
- package/dist/__tests__/terminal/TtyWriter.test.js.map +1 -1
- package/dist/__tests__/utils/agent-requests.test.js +90 -0
- package/dist/__tests__/utils/agent-requests.test.js.map +1 -0
- package/dist/__tests__/utils/agents.test.js +6 -0
- package/dist/__tests__/utils/agents.test.js.map +1 -1
- package/dist/adapters/AgentAdapter.d.ts +1 -1
- package/dist/adapters/AgentAdapter.d.ts.map +1 -1
- package/dist/adapters/AgentAdapter.js.map +1 -1
- package/dist/adapters/GrokCliAdapter.d.ts +79 -0
- package/dist/adapters/GrokCliAdapter.d.ts.map +1 -0
- package/dist/adapters/GrokCliAdapter.js +306 -0
- package/dist/adapters/GrokCliAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +1 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/terminal/TerminalFocusManager.d.ts +11 -0
- package/dist/terminal/TerminalFocusManager.d.ts.map +1 -1
- package/dist/terminal/TerminalFocusManager.js +84 -10
- package/dist/terminal/TerminalFocusManager.js.map +1 -1
- package/dist/terminal/TtyWriter.d.ts +19 -0
- package/dist/terminal/TtyWriter.d.ts.map +1 -1
- package/dist/terminal/TtyWriter.js +167 -1
- package/dist/terminal/TtyWriter.js.map +1 -1
- package/dist/utils/agent-requests.d.ts +10 -0
- package/dist/utils/agent-requests.d.ts.map +1 -0
- package/dist/utils/agent-requests.js +22 -0
- package/dist/utils/agent-requests.js.map +1 -0
- package/dist/utils/agents.d.ts +1 -1
- package/dist/utils/agents.d.ts.map +1 -1
- package/dist/utils/agents.js +4 -0
- package/dist/utils/agents.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/AgentManager.test.ts +7 -1
- package/src/__tests__/adapters/GrokCliAdapter.test.ts +307 -0
- package/src/__tests__/terminal/TerminalFocusManager.test.ts +187 -0
- package/src/__tests__/terminal/TtyWriter.test.ts +234 -0
- package/src/__tests__/utils/agent-requests.test.ts +74 -0
- package/src/__tests__/utils/agents.test.ts +7 -0
- package/src/adapters/AgentAdapter.ts +1 -1
- package/src/adapters/GrokCliAdapter.ts +394 -0
- package/src/adapters/index.ts +1 -0
- package/src/index.ts +4 -0
- package/src/terminal/TerminalFocusManager.ts +103 -11
- package/src/terminal/TtyWriter.ts +161 -1
- package/src/utils/agent-requests.ts +28 -0
- package/src/utils/agents.ts +2 -1
|
@@ -201,6 +201,96 @@ describe('TtyWriter', () => {
|
|
|
201
201
|
});
|
|
202
202
|
});
|
|
203
203
|
|
|
204
|
+
describe('WezTerm', () => {
|
|
205
|
+
const location: TerminalLocation = {
|
|
206
|
+
type: TerminalType.WEZTERM,
|
|
207
|
+
identifier: '7',
|
|
208
|
+
tty: '/dev/ttys030',
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
it('sends the message via stdin and Enter as a separate send-text call', async () => {
|
|
212
|
+
mockExecFileSuccess();
|
|
213
|
+
|
|
214
|
+
await TtyWriter.send(location, 'continue');
|
|
215
|
+
|
|
216
|
+
// Step 1: message body via stdin, not argv, so prompt contents are
|
|
217
|
+
// not exposed through process listings.
|
|
218
|
+
expect(mockedExecFile).toHaveBeenCalledWith(
|
|
219
|
+
'wezterm',
|
|
220
|
+
['cli', 'send-text', '--pane-id', '7'],
|
|
221
|
+
expect.any(Function),
|
|
222
|
+
);
|
|
223
|
+
expect(mockedExecFile.mock.results[0]?.value.stdin.end)
|
|
224
|
+
.toHaveBeenCalledWith('continue');
|
|
225
|
+
// Step 2: Enter as a single carriage return (0x0d) with --no-paste,
|
|
226
|
+
// so the CR is delivered literally (not wrapped in paste brackets).
|
|
227
|
+
// execFile passes the actual CR byte (JS '\x0d'); the equivalent
|
|
228
|
+
// shell command is:
|
|
229
|
+
// wezterm cli send-text --pane-id <id> --no-paste $'\x0d'
|
|
230
|
+
expect(mockedExecFile).toHaveBeenCalledWith(
|
|
231
|
+
'wezterm',
|
|
232
|
+
['cli', 'send-text', '--pane-id', '7', '--no-paste', '\x0d'],
|
|
233
|
+
expect.any(Function),
|
|
234
|
+
);
|
|
235
|
+
expect(mockedExecFile).toHaveBeenCalledTimes(2);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('passes the Enter byte as the carriage return (0x0d), not newline', async () => {
|
|
239
|
+
mockExecFileSuccess();
|
|
240
|
+
|
|
241
|
+
await TtyWriter.send(location, 'continue');
|
|
242
|
+
|
|
243
|
+
// The Enter call is the second invocation; its last argv element is
|
|
244
|
+
// a single byte equal to char code 13 (0x0d).
|
|
245
|
+
const enterCall = mockedExecFile.mock.calls[1];
|
|
246
|
+
const enterArgs = enterCall[1] as string[];
|
|
247
|
+
const enterByte = enterArgs[enterArgs.length - 1];
|
|
248
|
+
expect(enterByte).toHaveLength(1);
|
|
249
|
+
expect(enterByte.charCodeAt(0)).toBe(0x0d);
|
|
250
|
+
expect(enterArgs).toContain('--no-paste');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('keeps the whole message out of argv and writes it verbatim to stdin', async () => {
|
|
254
|
+
mockExecFileSuccess();
|
|
255
|
+
const hostile = 'echo pwned; $(rm -rf /) `whoami` | cat\nline2';
|
|
256
|
+
|
|
257
|
+
await TtyWriter.send(location, hostile);
|
|
258
|
+
|
|
259
|
+
// The message is written verbatim to stdin, not built into a shell
|
|
260
|
+
// string or exposed as a process argument.
|
|
261
|
+
const textCall = mockedExecFile.mock.calls[0];
|
|
262
|
+
const textArgs = textCall[1] as string[];
|
|
263
|
+
expect(textArgs).toEqual(
|
|
264
|
+
['cli', 'send-text', '--pane-id', '7'],
|
|
265
|
+
);
|
|
266
|
+
expect(textCall[2]).toBeTypeOf('function');
|
|
267
|
+
expect(mockedExecFile.mock.results[0]?.value.stdin.end)
|
|
268
|
+
.toHaveBeenCalledWith(hostile);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('uses the pane id from location.identifier', async () => {
|
|
272
|
+
mockExecFileSuccess();
|
|
273
|
+
const pane42 = { ...location, identifier: '42' };
|
|
274
|
+
|
|
275
|
+
await TtyWriter.send(pane42, 'hi');
|
|
276
|
+
|
|
277
|
+
expect(mockedExecFile).toHaveBeenCalledWith(
|
|
278
|
+
'wezterm',
|
|
279
|
+
['cli', 'send-text', '--pane-id', '42'],
|
|
280
|
+
expect.any(Function),
|
|
281
|
+
);
|
|
282
|
+
expect(mockedExecFile.mock.results[0]?.value.stdin.end)
|
|
283
|
+
.toHaveBeenCalledWith('hi');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('throws when the text send fails', async () => {
|
|
287
|
+
mockExecFileError('wezterm send-text failed');
|
|
288
|
+
|
|
289
|
+
await expect(TtyWriter.send(location, 'hello'))
|
|
290
|
+
.rejects.toThrow('wezterm send-text failed');
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
204
294
|
describe('unsupported terminal', () => {
|
|
205
295
|
it('throws for unknown terminal type', async () => {
|
|
206
296
|
const location: TerminalLocation = {
|
|
@@ -213,4 +303,148 @@ describe('TtyWriter', () => {
|
|
|
213
303
|
.rejects.toThrow('Cannot send input: unsupported terminal type');
|
|
214
304
|
});
|
|
215
305
|
});
|
|
306
|
+
|
|
307
|
+
describe('sendKey — tmux', () => {
|
|
308
|
+
const location: TerminalLocation = {
|
|
309
|
+
type: TerminalType.TMUX,
|
|
310
|
+
identifier: 'main:0.1',
|
|
311
|
+
tty: '/dev/ttys030',
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
it('sends key via tmux send-keys directly (no paste buffer, no auto-Enter)', async () => {
|
|
315
|
+
mockExecFileSuccess();
|
|
316
|
+
|
|
317
|
+
await TtyWriter.sendKey(location, '1');
|
|
318
|
+
|
|
319
|
+
expect(mockedExecFile).toHaveBeenCalledTimes(1);
|
|
320
|
+
expect(mockedExecFile).toHaveBeenCalledWith(
|
|
321
|
+
'tmux',
|
|
322
|
+
['send-keys', '-t', 'main:0.1', '1'],
|
|
323
|
+
expect.any(Function),
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('passes through named keys like Enter', async () => {
|
|
328
|
+
mockExecFileSuccess();
|
|
329
|
+
await TtyWriter.sendKey(location, 'Enter');
|
|
330
|
+
expect(mockedExecFile).toHaveBeenCalledWith(
|
|
331
|
+
'tmux',
|
|
332
|
+
['send-keys', '-t', 'main:0.1', 'Enter'],
|
|
333
|
+
expect.any(Function),
|
|
334
|
+
);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('translates Esc byte (\\x1b) to the named "Escape" key', async () => {
|
|
338
|
+
mockExecFileSuccess();
|
|
339
|
+
await TtyWriter.sendKey(location, '\x1b');
|
|
340
|
+
expect(mockedExecFile).toHaveBeenCalledWith(
|
|
341
|
+
'tmux',
|
|
342
|
+
['send-keys', '-t', 'main:0.1', 'Escape'],
|
|
343
|
+
expect.any(Function),
|
|
344
|
+
);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe('sendKey — WezTerm', () => {
|
|
349
|
+
const location: TerminalLocation = {
|
|
350
|
+
type: TerminalType.WEZTERM,
|
|
351
|
+
identifier: '7',
|
|
352
|
+
tty: '/dev/ttys030',
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
it('uses wezterm cli send-text --no-paste to deliver a raw key', async () => {
|
|
356
|
+
mockExecFileSuccess();
|
|
357
|
+
|
|
358
|
+
await TtyWriter.sendKey(location, '1');
|
|
359
|
+
|
|
360
|
+
expect(mockedExecFile).toHaveBeenCalledTimes(1);
|
|
361
|
+
expect(mockedExecFile).toHaveBeenCalledWith(
|
|
362
|
+
'wezterm',
|
|
363
|
+
['cli', 'send-text', '--pane-id', '7', '--no-paste', '1'],
|
|
364
|
+
expect.any(Function),
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
describe('sendKey — iTerm2', () => {
|
|
370
|
+
const location: TerminalLocation = {
|
|
371
|
+
type: TerminalType.ITERM2,
|
|
372
|
+
identifier: '/dev/ttys030',
|
|
373
|
+
tty: '/dev/ttys030',
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
it('uses System Events keystroke after activating the iTerm2 session', async () => {
|
|
377
|
+
mockExecFileSuccess('ok');
|
|
378
|
+
|
|
379
|
+
await TtyWriter.sendKey(location, '2');
|
|
380
|
+
|
|
381
|
+
const args = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];
|
|
382
|
+
const script = args[1];
|
|
383
|
+
expect(script).toContain('tell application "iTerm"');
|
|
384
|
+
expect(script).toContain('tell application "System Events" to keystroke "2"');
|
|
385
|
+
expect(mockedExecFile).toHaveBeenCalledTimes(1);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('translates Esc byte (\\x1b) to AppleScript `key code 53`', async () => {
|
|
389
|
+
mockExecFileSuccess('ok');
|
|
390
|
+
await TtyWriter.sendKey(location, '\x1b');
|
|
391
|
+
const args = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];
|
|
392
|
+
const script = args[1];
|
|
393
|
+
expect(script).toContain('tell application "System Events" to key code 53');
|
|
394
|
+
expect(script).not.toContain('keystroke');
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('throws when session not found', async () => {
|
|
398
|
+
mockExecFileSuccess('not_found');
|
|
399
|
+
await expect(TtyWriter.sendKey(location, '1'))
|
|
400
|
+
.rejects.toThrow('iTerm2 session not found');
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
describe('sendKey — Terminal.app', () => {
|
|
405
|
+
const location: TerminalLocation = {
|
|
406
|
+
type: TerminalType.TERMINAL_APP,
|
|
407
|
+
identifier: '/dev/ttys030',
|
|
408
|
+
tty: '/dev/ttys030',
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
it('uses System Events keystroke after selecting the Terminal.app tab', async () => {
|
|
412
|
+
mockExecFileSuccess('ok');
|
|
413
|
+
|
|
414
|
+
await TtyWriter.sendKey(location, '3');
|
|
415
|
+
|
|
416
|
+
const args = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];
|
|
417
|
+
const script = args[1];
|
|
418
|
+
expect(script).toContain('tell application "Terminal"');
|
|
419
|
+
expect(script).toContain('tell application "System Events" to keystroke "3"');
|
|
420
|
+
expect(mockedExecFile).toHaveBeenCalledTimes(1);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it('translates Esc byte (\\x1b) to AppleScript `key code 53`', async () => {
|
|
424
|
+
mockExecFileSuccess('ok');
|
|
425
|
+
await TtyWriter.sendKey(location, '\x1b');
|
|
426
|
+
const args = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];
|
|
427
|
+
const script = args[1];
|
|
428
|
+
expect(script).toContain('tell application "System Events" to key code 53');
|
|
429
|
+
expect(script).not.toContain('keystroke');
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it('throws when tab not found', async () => {
|
|
433
|
+
mockExecFileSuccess('not_found');
|
|
434
|
+
await expect(TtyWriter.sendKey(location, '1'))
|
|
435
|
+
.rejects.toThrow('Terminal.app tab not found');
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
describe('sendKey — unsupported terminal', () => {
|
|
440
|
+
it('throws for unknown terminal type', async () => {
|
|
441
|
+
const location: TerminalLocation = {
|
|
442
|
+
type: TerminalType.UNKNOWN,
|
|
443
|
+
identifier: '',
|
|
444
|
+
tty: '/dev/ttys030',
|
|
445
|
+
};
|
|
446
|
+
await expect(TtyWriter.sendKey(location, '1'))
|
|
447
|
+
.rejects.toThrow('Cannot send key: unsupported terminal type');
|
|
448
|
+
});
|
|
449
|
+
});
|
|
216
450
|
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'fs';
|
|
2
|
+
import { tmpdir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { getAgentRequestPath, readLatestAgentRequest, writeAgentRequest, type AgentRequest } from '../../utils/agent-requests.js';
|
|
5
|
+
|
|
6
|
+
describe('agent-requests', () => {
|
|
7
|
+
let homeDir: string;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
homeDir = mkdtempSync(join(tmpdir(), 'agent-requests-test-'));
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
rmSync(homeDir, { recursive: true, force: true });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('getAgentRequestPath', () => {
|
|
18
|
+
it('returns ~/.ai-devkit/agent-requests/<sessionId>.json', () => {
|
|
19
|
+
expect(getAgentRequestPath(homeDir, 'abc-123')).toBe(
|
|
20
|
+
join(homeDir, '.ai-devkit', 'agent-requests', 'abc-123.json'),
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('writeAgentRequest', () => {
|
|
26
|
+
it('creates the directory and file on first write', () => {
|
|
27
|
+
const entry: AgentRequest = {
|
|
28
|
+
sessionId: 'sess-1',
|
|
29
|
+
toolName: 'Bash',
|
|
30
|
+
toolInput: { command: 'ls /tmp' },
|
|
31
|
+
timestamp: '2026-06-29T00:00:00.000Z',
|
|
32
|
+
};
|
|
33
|
+
writeAgentRequest(homeDir, entry);
|
|
34
|
+
|
|
35
|
+
expect(readLatestAgentRequest(homeDir, 'sess-1')).toEqual(entry);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('overwrites an existing entry on subsequent writes', () => {
|
|
39
|
+
const first: AgentRequest = { sessionId: 'sess-2', toolName: 'Bash', toolInput: { command: 'echo first' }, timestamp: '2026-06-29T00:00:01.000Z' };
|
|
40
|
+
const second: AgentRequest = { sessionId: 'sess-2', toolName: 'Bash', toolInput: { command: 'echo second' }, timestamp: '2026-06-29T00:00:02.000Z' };
|
|
41
|
+
|
|
42
|
+
writeAgentRequest(homeDir, first);
|
|
43
|
+
writeAgentRequest(homeDir, second);
|
|
44
|
+
|
|
45
|
+
expect(readLatestAgentRequest(homeDir, 'sess-2')).toEqual(second);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('readLatestAgentRequest', () => {
|
|
50
|
+
it('returns null when no file exists for the session', () => {
|
|
51
|
+
expect(readLatestAgentRequest(homeDir, 'no-such-session')).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('returns null when the file contains malformed JSON', () => {
|
|
55
|
+
const entry: AgentRequest = { sessionId: 'bad', toolName: 'Bash', toolInput: {}, timestamp: '2026-06-29T00:00:00.000Z' };
|
|
56
|
+
writeAgentRequest(homeDir, entry);
|
|
57
|
+
writeFileSync(getAgentRequestPath(homeDir, 'bad'), 'NOT JSON{{{', 'utf-8');
|
|
58
|
+
|
|
59
|
+
expect(readLatestAgentRequest(homeDir, 'bad')).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('returns the stored entry when the file is valid', () => {
|
|
63
|
+
const entry: AgentRequest = {
|
|
64
|
+
sessionId: 'good',
|
|
65
|
+
toolName: 'AskUserQuestion',
|
|
66
|
+
toolInput: { question: 'Which option?', options: ['A', 'B'] },
|
|
67
|
+
timestamp: '2026-06-29T12:00:00.000Z',
|
|
68
|
+
};
|
|
69
|
+
writeAgentRequest(homeDir, entry);
|
|
70
|
+
|
|
71
|
+
expect(readLatestAgentRequest(homeDir, 'good')).toEqual(entry);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -14,4 +14,11 @@ describe('AGENTS', () => {
|
|
|
14
14
|
expect(AGENTS.pi.matches('/usr/local/bin/pi --model x')).toBe(true);
|
|
15
15
|
expect(AGENTS.pi.matches('node /repo/feature-pi-adapter/script.js')).toBe(false);
|
|
16
16
|
});
|
|
17
|
+
|
|
18
|
+
it('includes Grok as a startable agent', () => {
|
|
19
|
+
expect(AGENTS.grok_cli.command).toBe('grok');
|
|
20
|
+
expect(AGENTS.grok_cli.matches('grok')).toBe(true);
|
|
21
|
+
expect(AGENTS.grok_cli.matches('/Users/dev/.grok/bin/grok --always-approve')).toBe(true);
|
|
22
|
+
expect(AGENTS.grok_cli.matches('node /repo/feature-grok-cli/script.js')).toBe(false);
|
|
23
|
+
});
|
|
17
24
|
});
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Type of AI agent
|
|
10
10
|
*/
|
|
11
|
-
export type AgentType = 'claude' | 'gemini_cli' | 'codex' | 'opencode' | 'copilot' | 'pi' | 'other';
|
|
11
|
+
export type AgentType = 'claude' | 'gemini_cli' | 'grok_cli' | 'codex' | 'opencode' | 'copilot' | 'pi' | 'other';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Current status of an agent
|