@ai-devkit/agent-manager 0.22.1 → 0.24.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.
Files changed (34) hide show
  1. package/README.md +3 -0
  2. package/dist/__tests__/AgentManager.test.js +9 -1
  3. package/dist/__tests__/AgentManager.test.js.map +1 -1
  4. package/dist/__tests__/terminal/TerminalFocusManager.test.js +180 -0
  5. package/dist/__tests__/terminal/TerminalFocusManager.test.js.map +1 -1
  6. package/dist/__tests__/terminal/TtyWriter.test.js +206 -0
  7. package/dist/__tests__/terminal/TtyWriter.test.js.map +1 -1
  8. package/dist/__tests__/utils/agent-requests.test.js +90 -0
  9. package/dist/__tests__/utils/agent-requests.test.js.map +1 -0
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/terminal/TerminalFocusManager.d.ts +11 -0
  15. package/dist/terminal/TerminalFocusManager.d.ts.map +1 -1
  16. package/dist/terminal/TerminalFocusManager.js +84 -10
  17. package/dist/terminal/TerminalFocusManager.js.map +1 -1
  18. package/dist/terminal/TtyWriter.d.ts +19 -0
  19. package/dist/terminal/TtyWriter.d.ts.map +1 -1
  20. package/dist/terminal/TtyWriter.js +167 -1
  21. package/dist/terminal/TtyWriter.js.map +1 -1
  22. package/dist/utils/agent-requests.d.ts +10 -0
  23. package/dist/utils/agent-requests.d.ts.map +1 -0
  24. package/dist/utils/agent-requests.js +22 -0
  25. package/dist/utils/agent-requests.js.map +1 -0
  26. package/package.json +1 -1
  27. package/src/__tests__/AgentManager.test.ts +7 -1
  28. package/src/__tests__/terminal/TerminalFocusManager.test.ts +187 -0
  29. package/src/__tests__/terminal/TtyWriter.test.ts +234 -0
  30. package/src/__tests__/utils/agent-requests.test.ts +74 -0
  31. package/src/index.ts +3 -0
  32. package/src/terminal/TerminalFocusManager.ts +103 -11
  33. package/src/terminal/TtyWriter.ts +161 -1
  34. package/src/utils/agent-requests.ts +28 -0
@@ -165,6 +165,88 @@ describe('TtyWriter', ()=>{
165
165
  await expect(TtyWriter.send(location, 'test')).rejects.toThrow('Terminal.app tab disappeared before Enter');
166
166
  });
167
167
  });
168
+ describe('WezTerm', ()=>{
169
+ const location = {
170
+ type: TerminalType.WEZTERM,
171
+ identifier: '7',
172
+ tty: '/dev/ttys030'
173
+ };
174
+ it('sends the message via stdin and Enter as a separate send-text call', async ()=>{
175
+ mockExecFileSuccess();
176
+ await TtyWriter.send(location, 'continue');
177
+ // Step 1: message body via stdin, not argv, so prompt contents are
178
+ // not exposed through process listings.
179
+ expect(mockedExecFile).toHaveBeenCalledWith('wezterm', [
180
+ 'cli',
181
+ 'send-text',
182
+ '--pane-id',
183
+ '7'
184
+ ], expect.any(Function));
185
+ expect(mockedExecFile.mock.results[0]?.value.stdin.end).toHaveBeenCalledWith('continue');
186
+ // Step 2: Enter as a single carriage return (0x0d) with --no-paste,
187
+ // so the CR is delivered literally (not wrapped in paste brackets).
188
+ // execFile passes the actual CR byte (JS '\x0d'); the equivalent
189
+ // shell command is:
190
+ // wezterm cli send-text --pane-id <id> --no-paste $'\x0d'
191
+ expect(mockedExecFile).toHaveBeenCalledWith('wezterm', [
192
+ 'cli',
193
+ 'send-text',
194
+ '--pane-id',
195
+ '7',
196
+ '--no-paste',
197
+ '\x0d'
198
+ ], expect.any(Function));
199
+ expect(mockedExecFile).toHaveBeenCalledTimes(2);
200
+ });
201
+ it('passes the Enter byte as the carriage return (0x0d), not newline', async ()=>{
202
+ mockExecFileSuccess();
203
+ await TtyWriter.send(location, 'continue');
204
+ // The Enter call is the second invocation; its last argv element is
205
+ // a single byte equal to char code 13 (0x0d).
206
+ const enterCall = mockedExecFile.mock.calls[1];
207
+ const enterArgs = enterCall[1];
208
+ const enterByte = enterArgs[enterArgs.length - 1];
209
+ expect(enterByte).toHaveLength(1);
210
+ expect(enterByte.charCodeAt(0)).toBe(0x0d);
211
+ expect(enterArgs).toContain('--no-paste');
212
+ });
213
+ it('keeps the whole message out of argv and writes it verbatim to stdin', async ()=>{
214
+ mockExecFileSuccess();
215
+ const hostile = 'echo pwned; $(rm -rf /) `whoami` | cat\nline2';
216
+ await TtyWriter.send(location, hostile);
217
+ // The message is written verbatim to stdin, not built into a shell
218
+ // string or exposed as a process argument.
219
+ const textCall = mockedExecFile.mock.calls[0];
220
+ const textArgs = textCall[1];
221
+ expect(textArgs).toEqual([
222
+ 'cli',
223
+ 'send-text',
224
+ '--pane-id',
225
+ '7'
226
+ ]);
227
+ expect(textCall[2]).toBeTypeOf('function');
228
+ expect(mockedExecFile.mock.results[0]?.value.stdin.end).toHaveBeenCalledWith(hostile);
229
+ });
230
+ it('uses the pane id from location.identifier', async ()=>{
231
+ mockExecFileSuccess();
232
+ const pane42 = {
233
+ ...location,
234
+ identifier: '42'
235
+ };
236
+ await TtyWriter.send(pane42, 'hi');
237
+ expect(mockedExecFile).toHaveBeenCalledWith('wezterm', [
238
+ 'cli',
239
+ 'send-text',
240
+ '--pane-id',
241
+ '42'
242
+ ], expect.any(Function));
243
+ expect(mockedExecFile.mock.results[0]?.value.stdin.end).toHaveBeenCalledWith('hi');
244
+ });
245
+ it('throws when the text send fails', async ()=>{
246
+ mockExecFileError('wezterm send-text failed');
247
+ await expect(TtyWriter.send(location, 'hello')).rejects.toThrow('wezterm send-text failed');
248
+ });
249
+ });
168
250
  describe('unsupported terminal', ()=>{
169
251
  it('throws for unknown terminal type', async ()=>{
170
252
  const location = {
@@ -175,6 +257,130 @@ describe('TtyWriter', ()=>{
175
257
  await expect(TtyWriter.send(location, 'test')).rejects.toThrow('Cannot send input: unsupported terminal type');
176
258
  });
177
259
  });
260
+ describe('sendKey — tmux', ()=>{
261
+ const location = {
262
+ type: TerminalType.TMUX,
263
+ identifier: 'main:0.1',
264
+ tty: '/dev/ttys030'
265
+ };
266
+ it('sends key via tmux send-keys directly (no paste buffer, no auto-Enter)', async ()=>{
267
+ mockExecFileSuccess();
268
+ await TtyWriter.sendKey(location, '1');
269
+ expect(mockedExecFile).toHaveBeenCalledTimes(1);
270
+ expect(mockedExecFile).toHaveBeenCalledWith('tmux', [
271
+ 'send-keys',
272
+ '-t',
273
+ 'main:0.1',
274
+ '1'
275
+ ], expect.any(Function));
276
+ });
277
+ it('passes through named keys like Enter', async ()=>{
278
+ mockExecFileSuccess();
279
+ await TtyWriter.sendKey(location, 'Enter');
280
+ expect(mockedExecFile).toHaveBeenCalledWith('tmux', [
281
+ 'send-keys',
282
+ '-t',
283
+ 'main:0.1',
284
+ 'Enter'
285
+ ], expect.any(Function));
286
+ });
287
+ it('translates Esc byte (\\x1b) to the named "Escape" key', async ()=>{
288
+ mockExecFileSuccess();
289
+ await TtyWriter.sendKey(location, '\x1b');
290
+ expect(mockedExecFile).toHaveBeenCalledWith('tmux', [
291
+ 'send-keys',
292
+ '-t',
293
+ 'main:0.1',
294
+ 'Escape'
295
+ ], expect.any(Function));
296
+ });
297
+ });
298
+ describe('sendKey — WezTerm', ()=>{
299
+ const location = {
300
+ type: TerminalType.WEZTERM,
301
+ identifier: '7',
302
+ tty: '/dev/ttys030'
303
+ };
304
+ it('uses wezterm cli send-text --no-paste to deliver a raw key', async ()=>{
305
+ mockExecFileSuccess();
306
+ await TtyWriter.sendKey(location, '1');
307
+ expect(mockedExecFile).toHaveBeenCalledTimes(1);
308
+ expect(mockedExecFile).toHaveBeenCalledWith('wezterm', [
309
+ 'cli',
310
+ 'send-text',
311
+ '--pane-id',
312
+ '7',
313
+ '--no-paste',
314
+ '1'
315
+ ], expect.any(Function));
316
+ });
317
+ });
318
+ describe('sendKey — iTerm2', ()=>{
319
+ const location = {
320
+ type: TerminalType.ITERM2,
321
+ identifier: '/dev/ttys030',
322
+ tty: '/dev/ttys030'
323
+ };
324
+ it('uses System Events keystroke after activating the iTerm2 session', async ()=>{
325
+ mockExecFileSuccess('ok');
326
+ await TtyWriter.sendKey(location, '2');
327
+ const args = mockedExecFile.mock.calls[0][1];
328
+ const script = args[1];
329
+ expect(script).toContain('tell application "iTerm"');
330
+ expect(script).toContain('tell application "System Events" to keystroke "2"');
331
+ expect(mockedExecFile).toHaveBeenCalledTimes(1);
332
+ });
333
+ it('translates Esc byte (\\x1b) to AppleScript `key code 53`', async ()=>{
334
+ mockExecFileSuccess('ok');
335
+ await TtyWriter.sendKey(location, '\x1b');
336
+ const args = mockedExecFile.mock.calls[0][1];
337
+ const script = args[1];
338
+ expect(script).toContain('tell application "System Events" to key code 53');
339
+ expect(script).not.toContain('keystroke');
340
+ });
341
+ it('throws when session not found', async ()=>{
342
+ mockExecFileSuccess('not_found');
343
+ await expect(TtyWriter.sendKey(location, '1')).rejects.toThrow('iTerm2 session not found');
344
+ });
345
+ });
346
+ describe('sendKey — Terminal.app', ()=>{
347
+ const location = {
348
+ type: TerminalType.TERMINAL_APP,
349
+ identifier: '/dev/ttys030',
350
+ tty: '/dev/ttys030'
351
+ };
352
+ it('uses System Events keystroke after selecting the Terminal.app tab', async ()=>{
353
+ mockExecFileSuccess('ok');
354
+ await TtyWriter.sendKey(location, '3');
355
+ const args = mockedExecFile.mock.calls[0][1];
356
+ const script = args[1];
357
+ expect(script).toContain('tell application "Terminal"');
358
+ expect(script).toContain('tell application "System Events" to keystroke "3"');
359
+ expect(mockedExecFile).toHaveBeenCalledTimes(1);
360
+ });
361
+ it('translates Esc byte (\\x1b) to AppleScript `key code 53`', async ()=>{
362
+ mockExecFileSuccess('ok');
363
+ await TtyWriter.sendKey(location, '\x1b');
364
+ const args = mockedExecFile.mock.calls[0][1];
365
+ const script = args[1];
366
+ expect(script).toContain('tell application "System Events" to key code 53');
367
+ expect(script).not.toContain('keystroke');
368
+ });
369
+ it('throws when tab not found', async ()=>{
370
+ mockExecFileSuccess('not_found');
371
+ await expect(TtyWriter.sendKey(location, '1')).rejects.toThrow('Terminal.app tab not found');
372
+ });
373
+ });
374
+ describe('sendKey — unsupported terminal', ()=>{
375
+ it('throws for unknown terminal type', async ()=>{
376
+ const location = {
377
+ type: TerminalType.UNKNOWN,
378
+ identifier: '',
379
+ tty: '/dev/ttys030'
380
+ };
381
+ await expect(TtyWriter.sendKey(location, '1')).rejects.toThrow('Cannot send key: unsupported terminal type');
382
+ });
383
+ });
178
384
  });
179
385
 
180
386
  //# sourceMappingURL=TtyWriter.test.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/__tests__/terminal/TtyWriter.test.ts"],"sourcesContent":["import type { Mock } from 'vitest';\n\nimport { TtyWriter } from '../../terminal/TtyWriter.js';\nimport { TerminalType } from '../../terminal/TerminalFocusManager.js';\nimport type { TerminalLocation } from '../../terminal/TerminalFocusManager.js';\nimport { execFile } from 'child_process';\n\nvi.mock('child_process', async () => {\n const actual = await vi.importActual<typeof import('child_process')>('child_process');\n return {\n ...actual,\n execFile: vi.fn(),\n };\n});\n\nconst mockedExecFile = execFile as unknown as Mock;\n\nfunction mockExecFileSuccess(stdout = '') {\n mockedExecFile.mockImplementation((...args: unknown[]) => {\n const cb = args[args.length - 1] as (err: Error | null, result: { stdout: string }, stderr: string) => void;\n cb(null, { stdout }, '');\n return { stdin: { end: vi.fn() } };\n });\n}\n\nfunction mockExecFileError(message: string) {\n mockedExecFile.mockImplementation((...args: unknown[]) => {\n const cb = args[args.length - 1] as (err: Error | null, result: null, stderr: string) => void;\n cb(new Error(message), null, '');\n });\n}\n\ndescribe('TtyWriter', () => {\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n describe('tmux', () => {\n const location: TerminalLocation = {\n type: TerminalType.TMUX,\n identifier: 'main:0.1',\n tty: '/dev/ttys030',\n };\n\n it('pastes message in bracketed paste mode and sends Enter separately', async () => {\n mockExecFileSuccess();\n const message = 'line 1\\nline 2\\n';\n\n await TtyWriter.send(location, message);\n\n const loadArgs = mockedExecFile.mock.calls[0]?.[1] as string[];\n const bufferName = loadArgs[2];\n expect(bufferName).toMatch(/^ai-devkit-send-/);\n expect(mockedExecFile).toHaveBeenNthCalledWith(\n 1,\n 'tmux',\n ['load-buffer', '-b', bufferName, '-'],\n expect.any(Function),\n );\n expect(mockedExecFile.mock.results[0]?.value.stdin.end)\n .toHaveBeenCalledWith(message);\n expect(mockedExecFile).toHaveBeenNthCalledWith(\n 2,\n 'tmux',\n ['paste-buffer', '-t', 'main:0.1', '-b', bufferName, '-p', '-d'],\n expect.any(Function),\n );\n expect(mockedExecFile).toHaveBeenNthCalledWith(\n 3,\n 'tmux',\n ['send-keys', '-t', 'main:0.1', 'Enter'],\n expect.any(Function),\n );\n expect(mockedExecFile).toHaveBeenCalledTimes(3);\n });\n\n it('throws on tmux failure', async () => {\n mockExecFileError('tmux not running');\n\n await expect(TtyWriter.send(location, 'hello'))\n .rejects.toThrow('tmux not running');\n });\n });\n\n describe('iTerm2', () => {\n const location: TerminalLocation = {\n type: TerminalType.ITERM2,\n identifier: '/dev/ttys030',\n tty: '/dev/ttys030',\n };\n\n it('sends message via osascript with execFile (no shell)', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.send(location, 'hello');\n\n // First call: send text without newline\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'osascript',\n ['-e', expect.stringContaining('write text \"hello\" newline no')],\n expect.any(Function),\n );\n // Second call: send Enter via separate write text with newline\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'osascript',\n ['-e', expect.stringContaining('write text \"\" newline yes')],\n expect.any(Function),\n );\n expect(mockedExecFile).toHaveBeenCalledTimes(2);\n });\n\n it('escapes special characters in message', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.send(location, 'say \"hi\" \\\\ there');\n\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'osascript',\n ['-e', expect.stringContaining('write text \"say \\\\\"hi\\\\\" \\\\\\\\ there\" newline no')],\n expect.any(Function),\n );\n });\n\n it('escapes newlines in message', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.send(location, 'line1\\nline2');\n\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'osascript',\n ['-e', expect.stringContaining('write text \"line1\\\\nline2\" newline no')],\n expect.any(Function),\n );\n });\n\n it('throws when session not found', async () => {\n mockExecFileSuccess('not_found');\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('iTerm2 session not found');\n });\n\n it('throws when session disappears before Enter', async () => {\n // First call succeeds (text sent), second returns not_found\n let callCount = 0;\n mockedExecFile.mockImplementation((...args: unknown[]) => {\n const cb = args[args.length - 1] as (err: Error | null, result: { stdout: string }, stderr: string) => void;\n callCount++;\n cb(null, { stdout: callCount === 1 ? 'ok' : 'not_found' }, '');\n });\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('iTerm2 session disappeared before Enter');\n });\n });\n\n describe('Terminal.app', () => {\n const location: TerminalLocation = {\n type: TerminalType.TERMINAL_APP,\n identifier: '/dev/ttys030',\n tty: '/dev/ttys030',\n };\n\n it('sends message via do script (not System Events)', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.send(location, 'hello');\n\n // First call: send text via do script\n const firstCallArgs = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];\n const textScript = firstCallArgs[1];\n expect(textScript).toContain('do script \"hello\" in targetTab');\n expect(textScript).not.toContain('keystroke');\n expect(textScript).not.toContain('key code 36');\n\n // Second call: send Enter via separate do script\n const secondCallArgs = (mockedExecFile.mock.calls[1] as unknown[])[1] as string[];\n const enterScript = secondCallArgs[1];\n expect(enterScript).toContain('do script \"\" in targetTab');\n\n expect(mockedExecFile).toHaveBeenCalledTimes(2);\n });\n\n it('throws when tab not found', async () => {\n mockExecFileSuccess('not_found');\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('Terminal.app tab not found');\n });\n\n it('throws when tab disappears before Enter', async () => {\n let callCount = 0;\n mockedExecFile.mockImplementation((...args: unknown[]) => {\n const cb = args[args.length - 1] as (err: Error | null, result: { stdout: string }, stderr: string) => void;\n callCount++;\n cb(null, { stdout: callCount === 1 ? 'ok' : 'not_found' }, '');\n });\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('Terminal.app tab disappeared before Enter');\n });\n });\n\n describe('unsupported terminal', () => {\n it('throws for unknown terminal type', async () => {\n const location: TerminalLocation = {\n type: TerminalType.UNKNOWN,\n identifier: '',\n tty: '/dev/ttys030',\n };\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('Cannot send input: unsupported terminal type');\n });\n });\n});\n"],"names":["TtyWriter","TerminalType","execFile","vi","mock","actual","importActual","fn","mockedExecFile","mockExecFileSuccess","stdout","mockImplementation","args","cb","length","stdin","end","mockExecFileError","message","Error","describe","beforeEach","clearAllMocks","location","type","TMUX","identifier","tty","it","send","loadArgs","calls","bufferName","expect","toMatch","toHaveBeenNthCalledWith","any","Function","results","value","toHaveBeenCalledWith","toHaveBeenCalledTimes","rejects","toThrow","ITERM2","stringContaining","callCount","TERMINAL_APP","firstCallArgs","textScript","toContain","not","secondCallArgs","enterScript","UNKNOWN"],"mappings":"AAEA,SAASA,SAAS,QAAQ,8BAA8B;AACxD,SAASC,YAAY,QAAQ,yCAAyC;AAEtE,SAASC,QAAQ,QAAQ,gBAAgB;AAEzCC,GAAGC,IAAI,CAAC,iBAAiB;IACrB,MAAMC,SAAS,MAAMF,GAAGG,YAAY,CAAiC;IACrE,OAAO;QACH,GAAGD,MAAM;QACTH,UAAUC,GAAGI,EAAE;IACnB;AACJ;AAEA,MAAMC,iBAAiBN;AAEvB,SAASO,oBAAoBC,SAAS,EAAE;IACpCF,eAAeG,kBAAkB,CAAC,CAAC,GAAGC;QAClC,MAAMC,KAAKD,IAAI,CAACA,KAAKE,MAAM,GAAG,EAAE;QAChCD,GAAG,MAAM;YAAEH;QAAO,GAAG;QACrB,OAAO;YAAEK,OAAO;gBAAEC,KAAKb,GAAGI,EAAE;YAAG;QAAE;IACrC;AACJ;AAEA,SAASU,kBAAkBC,OAAe;IACtCV,eAAeG,kBAAkB,CAAC,CAAC,GAAGC;QAClC,MAAMC,KAAKD,IAAI,CAACA,KAAKE,MAAM,GAAG,EAAE;QAChCD,GAAG,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C,MAAMvB,aAAaqD,OAAO;gBAC1B5B,YAAY;gBACZC,KAAK;YACT;YAEA,MAAMM,OAAOjC,UAAU6B,IAAI,CAACN,UAAU,SACjCmB,OAAO,CAACC,OAAO,CAAC;QACzB;IACJ;AACJ"}
1
+ {"version":3,"sources":["../../../src/__tests__/terminal/TtyWriter.test.ts"],"sourcesContent":["import type { Mock } from 'vitest';\n\nimport { TtyWriter } from '../../terminal/TtyWriter.js';\nimport { TerminalType } from '../../terminal/TerminalFocusManager.js';\nimport type { TerminalLocation } from '../../terminal/TerminalFocusManager.js';\nimport { execFile } from 'child_process';\n\nvi.mock('child_process', async () => {\n const actual = await vi.importActual<typeof import('child_process')>('child_process');\n return {\n ...actual,\n execFile: vi.fn(),\n };\n});\n\nconst mockedExecFile = execFile as unknown as Mock;\n\nfunction mockExecFileSuccess(stdout = '') {\n mockedExecFile.mockImplementation((...args: unknown[]) => {\n const cb = args[args.length - 1] as (err: Error | null, result: { stdout: string }, stderr: string) => void;\n cb(null, { stdout }, '');\n return { stdin: { end: vi.fn() } };\n });\n}\n\nfunction mockExecFileError(message: string) {\n mockedExecFile.mockImplementation((...args: unknown[]) => {\n const cb = args[args.length - 1] as (err: Error | null, result: null, stderr: string) => void;\n cb(new Error(message), null, '');\n });\n}\n\ndescribe('TtyWriter', () => {\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n describe('tmux', () => {\n const location: TerminalLocation = {\n type: TerminalType.TMUX,\n identifier: 'main:0.1',\n tty: '/dev/ttys030',\n };\n\n it('pastes message in bracketed paste mode and sends Enter separately', async () => {\n mockExecFileSuccess();\n const message = 'line 1\\nline 2\\n';\n\n await TtyWriter.send(location, message);\n\n const loadArgs = mockedExecFile.mock.calls[0]?.[1] as string[];\n const bufferName = loadArgs[2];\n expect(bufferName).toMatch(/^ai-devkit-send-/);\n expect(mockedExecFile).toHaveBeenNthCalledWith(\n 1,\n 'tmux',\n ['load-buffer', '-b', bufferName, '-'],\n expect.any(Function),\n );\n expect(mockedExecFile.mock.results[0]?.value.stdin.end)\n .toHaveBeenCalledWith(message);\n expect(mockedExecFile).toHaveBeenNthCalledWith(\n 2,\n 'tmux',\n ['paste-buffer', '-t', 'main:0.1', '-b', bufferName, '-p', '-d'],\n expect.any(Function),\n );\n expect(mockedExecFile).toHaveBeenNthCalledWith(\n 3,\n 'tmux',\n ['send-keys', '-t', 'main:0.1', 'Enter'],\n expect.any(Function),\n );\n expect(mockedExecFile).toHaveBeenCalledTimes(3);\n });\n\n it('throws on tmux failure', async () => {\n mockExecFileError('tmux not running');\n\n await expect(TtyWriter.send(location, 'hello'))\n .rejects.toThrow('tmux not running');\n });\n });\n\n describe('iTerm2', () => {\n const location: TerminalLocation = {\n type: TerminalType.ITERM2,\n identifier: '/dev/ttys030',\n tty: '/dev/ttys030',\n };\n\n it('sends message via osascript with execFile (no shell)', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.send(location, 'hello');\n\n // First call: send text without newline\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'osascript',\n ['-e', expect.stringContaining('write text \"hello\" newline no')],\n expect.any(Function),\n );\n // Second call: send Enter via separate write text with newline\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'osascript',\n ['-e', expect.stringContaining('write text \"\" newline yes')],\n expect.any(Function),\n );\n expect(mockedExecFile).toHaveBeenCalledTimes(2);\n });\n\n it('escapes special characters in message', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.send(location, 'say \"hi\" \\\\ there');\n\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'osascript',\n ['-e', expect.stringContaining('write text \"say \\\\\"hi\\\\\" \\\\\\\\ there\" newline no')],\n expect.any(Function),\n );\n });\n\n it('escapes newlines in message', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.send(location, 'line1\\nline2');\n\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'osascript',\n ['-e', expect.stringContaining('write text \"line1\\\\nline2\" newline no')],\n expect.any(Function),\n );\n });\n\n it('throws when session not found', async () => {\n mockExecFileSuccess('not_found');\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('iTerm2 session not found');\n });\n\n it('throws when session disappears before Enter', async () => {\n // First call succeeds (text sent), second returns not_found\n let callCount = 0;\n mockedExecFile.mockImplementation((...args: unknown[]) => {\n const cb = args[args.length - 1] as (err: Error | null, result: { stdout: string }, stderr: string) => void;\n callCount++;\n cb(null, { stdout: callCount === 1 ? 'ok' : 'not_found' }, '');\n });\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('iTerm2 session disappeared before Enter');\n });\n });\n\n describe('Terminal.app', () => {\n const location: TerminalLocation = {\n type: TerminalType.TERMINAL_APP,\n identifier: '/dev/ttys030',\n tty: '/dev/ttys030',\n };\n\n it('sends message via do script (not System Events)', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.send(location, 'hello');\n\n // First call: send text via do script\n const firstCallArgs = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];\n const textScript = firstCallArgs[1];\n expect(textScript).toContain('do script \"hello\" in targetTab');\n expect(textScript).not.toContain('keystroke');\n expect(textScript).not.toContain('key code 36');\n\n // Second call: send Enter via separate do script\n const secondCallArgs = (mockedExecFile.mock.calls[1] as unknown[])[1] as string[];\n const enterScript = secondCallArgs[1];\n expect(enterScript).toContain('do script \"\" in targetTab');\n\n expect(mockedExecFile).toHaveBeenCalledTimes(2);\n });\n\n it('throws when tab not found', async () => {\n mockExecFileSuccess('not_found');\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('Terminal.app tab not found');\n });\n\n it('throws when tab disappears before Enter', async () => {\n let callCount = 0;\n mockedExecFile.mockImplementation((...args: unknown[]) => {\n const cb = args[args.length - 1] as (err: Error | null, result: { stdout: string }, stderr: string) => void;\n callCount++;\n cb(null, { stdout: callCount === 1 ? 'ok' : 'not_found' }, '');\n });\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('Terminal.app tab disappeared before Enter');\n });\n });\n\n describe('WezTerm', () => {\n const location: TerminalLocation = {\n type: TerminalType.WEZTERM,\n identifier: '7',\n tty: '/dev/ttys030',\n };\n\n it('sends the message via stdin and Enter as a separate send-text call', async () => {\n mockExecFileSuccess();\n\n await TtyWriter.send(location, 'continue');\n\n // Step 1: message body via stdin, not argv, so prompt contents are\n // not exposed through process listings.\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'wezterm',\n ['cli', 'send-text', '--pane-id', '7'],\n expect.any(Function),\n );\n expect(mockedExecFile.mock.results[0]?.value.stdin.end)\n .toHaveBeenCalledWith('continue');\n // Step 2: Enter as a single carriage return (0x0d) with --no-paste,\n // so the CR is delivered literally (not wrapped in paste brackets).\n // execFile passes the actual CR byte (JS '\\x0d'); the equivalent\n // shell command is:\n // wezterm cli send-text --pane-id <id> --no-paste $'\\x0d'\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'wezterm',\n ['cli', 'send-text', '--pane-id', '7', '--no-paste', '\\x0d'],\n expect.any(Function),\n );\n expect(mockedExecFile).toHaveBeenCalledTimes(2);\n });\n\n it('passes the Enter byte as the carriage return (0x0d), not newline', async () => {\n mockExecFileSuccess();\n\n await TtyWriter.send(location, 'continue');\n\n // The Enter call is the second invocation; its last argv element is\n // a single byte equal to char code 13 (0x0d).\n const enterCall = mockedExecFile.mock.calls[1];\n const enterArgs = enterCall[1] as string[];\n const enterByte = enterArgs[enterArgs.length - 1];\n expect(enterByte).toHaveLength(1);\n expect(enterByte.charCodeAt(0)).toBe(0x0d);\n expect(enterArgs).toContain('--no-paste');\n });\n\n it('keeps the whole message out of argv and writes it verbatim to stdin', async () => {\n mockExecFileSuccess();\n const hostile = 'echo pwned; $(rm -rf /) `whoami` | cat\\nline2';\n\n await TtyWriter.send(location, hostile);\n\n // The message is written verbatim to stdin, not built into a shell\n // string or exposed as a process argument.\n const textCall = mockedExecFile.mock.calls[0];\n const textArgs = textCall[1] as string[];\n expect(textArgs).toEqual(\n ['cli', 'send-text', '--pane-id', '7'],\n );\n expect(textCall[2]).toBeTypeOf('function');\n expect(mockedExecFile.mock.results[0]?.value.stdin.end)\n .toHaveBeenCalledWith(hostile);\n });\n\n it('uses the pane id from location.identifier', async () => {\n mockExecFileSuccess();\n const pane42 = { ...location, identifier: '42' };\n\n await TtyWriter.send(pane42, 'hi');\n\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'wezterm',\n ['cli', 'send-text', '--pane-id', '42'],\n expect.any(Function),\n );\n expect(mockedExecFile.mock.results[0]?.value.stdin.end)\n .toHaveBeenCalledWith('hi');\n });\n\n it('throws when the text send fails', async () => {\n mockExecFileError('wezterm send-text failed');\n\n await expect(TtyWriter.send(location, 'hello'))\n .rejects.toThrow('wezterm send-text failed');\n });\n });\n\n describe('unsupported terminal', () => {\n it('throws for unknown terminal type', async () => {\n const location: TerminalLocation = {\n type: TerminalType.UNKNOWN,\n identifier: '',\n tty: '/dev/ttys030',\n };\n\n await expect(TtyWriter.send(location, 'test'))\n .rejects.toThrow('Cannot send input: unsupported terminal type');\n });\n });\n\n describe('sendKey — tmux', () => {\n const location: TerminalLocation = {\n type: TerminalType.TMUX,\n identifier: 'main:0.1',\n tty: '/dev/ttys030',\n };\n\n it('sends key via tmux send-keys directly (no paste buffer, no auto-Enter)', async () => {\n mockExecFileSuccess();\n\n await TtyWriter.sendKey(location, '1');\n\n expect(mockedExecFile).toHaveBeenCalledTimes(1);\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'tmux',\n ['send-keys', '-t', 'main:0.1', '1'],\n expect.any(Function),\n );\n });\n\n it('passes through named keys like Enter', async () => {\n mockExecFileSuccess();\n await TtyWriter.sendKey(location, 'Enter');\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'tmux',\n ['send-keys', '-t', 'main:0.1', 'Enter'],\n expect.any(Function),\n );\n });\n\n it('translates Esc byte (\\\\x1b) to the named \"Escape\" key', async () => {\n mockExecFileSuccess();\n await TtyWriter.sendKey(location, '\\x1b');\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'tmux',\n ['send-keys', '-t', 'main:0.1', 'Escape'],\n expect.any(Function),\n );\n });\n });\n\n describe('sendKey — WezTerm', () => {\n const location: TerminalLocation = {\n type: TerminalType.WEZTERM,\n identifier: '7',\n tty: '/dev/ttys030',\n };\n\n it('uses wezterm cli send-text --no-paste to deliver a raw key', async () => {\n mockExecFileSuccess();\n\n await TtyWriter.sendKey(location, '1');\n\n expect(mockedExecFile).toHaveBeenCalledTimes(1);\n expect(mockedExecFile).toHaveBeenCalledWith(\n 'wezterm',\n ['cli', 'send-text', '--pane-id', '7', '--no-paste', '1'],\n expect.any(Function),\n );\n });\n });\n\n describe('sendKey — iTerm2', () => {\n const location: TerminalLocation = {\n type: TerminalType.ITERM2,\n identifier: '/dev/ttys030',\n tty: '/dev/ttys030',\n };\n\n it('uses System Events keystroke after activating the iTerm2 session', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.sendKey(location, '2');\n\n const args = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];\n const script = args[1];\n expect(script).toContain('tell application \"iTerm\"');\n expect(script).toContain('tell application \"System Events\" to keystroke \"2\"');\n expect(mockedExecFile).toHaveBeenCalledTimes(1);\n });\n\n it('translates Esc byte (\\\\x1b) to AppleScript `key code 53`', async () => {\n mockExecFileSuccess('ok');\n await TtyWriter.sendKey(location, '\\x1b');\n const args = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];\n const script = args[1];\n expect(script).toContain('tell application \"System Events\" to key code 53');\n expect(script).not.toContain('keystroke');\n });\n\n it('throws when session not found', async () => {\n mockExecFileSuccess('not_found');\n await expect(TtyWriter.sendKey(location, '1'))\n .rejects.toThrow('iTerm2 session not found');\n });\n });\n\n describe('sendKey — Terminal.app', () => {\n const location: TerminalLocation = {\n type: TerminalType.TERMINAL_APP,\n identifier: '/dev/ttys030',\n tty: '/dev/ttys030',\n };\n\n it('uses System Events keystroke after selecting the Terminal.app tab', async () => {\n mockExecFileSuccess('ok');\n\n await TtyWriter.sendKey(location, '3');\n\n const args = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];\n const script = args[1];\n expect(script).toContain('tell application \"Terminal\"');\n expect(script).toContain('tell application \"System Events\" to keystroke \"3\"');\n expect(mockedExecFile).toHaveBeenCalledTimes(1);\n });\n\n it('translates Esc byte (\\\\x1b) to AppleScript `key code 53`', async () => {\n mockExecFileSuccess('ok');\n await TtyWriter.sendKey(location, '\\x1b');\n const args = (mockedExecFile.mock.calls[0] as unknown[])[1] as string[];\n const script = args[1];\n expect(script).toContain('tell application \"System Events\" to key code 53');\n expect(script).not.toContain('keystroke');\n });\n\n it('throws when tab not found', async () => {\n mockExecFileSuccess('not_found');\n await expect(TtyWriter.sendKey(location, '1'))\n .rejects.toThrow('Terminal.app tab not found');\n });\n });\n\n describe('sendKey — unsupported terminal', () => {\n it('throws for unknown terminal type', async () => {\n const location: TerminalLocation = {\n type: TerminalType.UNKNOWN,\n identifier: '',\n tty: '/dev/ttys030',\n };\n await expect(TtyWriter.sendKey(location, '1'))\n .rejects.toThrow('Cannot send key: unsupported terminal type');\n });\n });\n});\n"],"names":["TtyWriter","TerminalType","execFile","vi","mock","actual","importActual","fn","mockedExecFile","mockExecFileSuccess","stdout","mockImplementation","args","cb","length","stdin","end","mockExecFileError","message","Error","describe","beforeEach","clearAllMocks","location","type","TMUX","identifier","tty","it","send","loadArgs","calls","bufferName","expect","toMatch","toHaveBeenNthCalledWith","any","Function","results","value","toHaveBeenCalledWith","toHaveBeenCalledTimes","rejects","toThrow","ITERM2","stringContaining","callCount","TERMINAL_APP","firstCallArgs","textScript","toContain","not","secondCallArgs","enterScript","WEZTERM","enterCall","enterArgs","enterByte","toHaveLength","charCodeAt","toBe","hostile","textCall","textArgs","toEqual","toBeTypeOf","pane42","UNKNOWN","sendKey","script"],"mappings":"AAEA,SAASA,SAAS,QAAQ,8BAA8B;AACxD,SAASC,YAAY,QAAQ,yCAAyC;AAEtE,SAASC,QAAQ,QAAQ,gBAAgB;AAEzCC,GAAGC,IAAI,CAA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,EAAE;YAC3D,MAAMsC,SAASzD,IAAI,CAAC,EAAE;YACtBqB,OAAOoC,QAAQnB,SAAS,CAAC;YACzBjB,OAAOoC,QAAQnB,SAAS,CAAC;YACzBjB,OAAOzB,gBAAgBiC,qBAAqB,CAAC;QACjD;QAEAb,GAAG,4DAA4D;YAC3DnB,oBAAoB;YACpB,MAAMT,UAAUoE,OAAO,CAAC7C,UAAU;YAClC,MAAMX,OAAO,AAACJ,eAAeJ,IAAI,CAAC2B,KAAK,CAAC,EAAE,AAAc,CAAC,EAAE;YAC3D,MAAMsC,SAASzD,IAAI,CAAC,EAAE;YACtBqB,OAAOoC,QAAQnB,SAAS,CAAC;YACzBjB,OAAOoC,QAAQlB,GAAG,CAACD,SAAS,CAAC;QACjC;QAEAtB,GAAG,6BAA6B;YAC5BnB,oBAAoB;YACpB,MAAMwB,OAAOjC,UAAUoE,OAAO,CAAC7C,UAAU,MACpCmB,OAAO,CAACC,OAAO,CAAC;QACzB;IACJ;IAEAvB,SAAS,kCAAkC;QACvCQ,GAAG,oCAAoC;YACnC,MAAML,WAA6B;gBAC/BC,MAAMvB,aAAakE,OAAO;gBAC1BzC,YAAY;gBACZC,KAAK;YACT;YACA,MAAMM,OAAOjC,UAAUoE,OAAO,CAAC7C,UAAU,MACpCmB,OAAO,CAACC,OAAO,CAAC;QACzB;IACJ;AACJ"}
@@ -0,0 +1,90 @@
1
+ import { mkdtempSync, rmSync, writeFileSync } from 'fs';
2
+ import { tmpdir } from 'os';
3
+ import { join } from 'path';
4
+ import { getAgentRequestPath, readLatestAgentRequest, writeAgentRequest } from '../../utils/agent-requests.js';
5
+ describe('agent-requests', ()=>{
6
+ let homeDir;
7
+ beforeEach(()=>{
8
+ homeDir = mkdtempSync(join(tmpdir(), 'agent-requests-test-'));
9
+ });
10
+ afterEach(()=>{
11
+ rmSync(homeDir, {
12
+ recursive: true,
13
+ force: true
14
+ });
15
+ });
16
+ describe('getAgentRequestPath', ()=>{
17
+ it('returns ~/.ai-devkit/agent-requests/<sessionId>.json', ()=>{
18
+ expect(getAgentRequestPath(homeDir, 'abc-123')).toBe(join(homeDir, '.ai-devkit', 'agent-requests', 'abc-123.json'));
19
+ });
20
+ });
21
+ describe('writeAgentRequest', ()=>{
22
+ it('creates the directory and file on first write', ()=>{
23
+ const entry = {
24
+ sessionId: 'sess-1',
25
+ toolName: 'Bash',
26
+ toolInput: {
27
+ command: 'ls /tmp'
28
+ },
29
+ timestamp: '2026-06-29T00:00:00.000Z'
30
+ };
31
+ writeAgentRequest(homeDir, entry);
32
+ expect(readLatestAgentRequest(homeDir, 'sess-1')).toEqual(entry);
33
+ });
34
+ it('overwrites an existing entry on subsequent writes', ()=>{
35
+ const first = {
36
+ sessionId: 'sess-2',
37
+ toolName: 'Bash',
38
+ toolInput: {
39
+ command: 'echo first'
40
+ },
41
+ timestamp: '2026-06-29T00:00:01.000Z'
42
+ };
43
+ const second = {
44
+ sessionId: 'sess-2',
45
+ toolName: 'Bash',
46
+ toolInput: {
47
+ command: 'echo second'
48
+ },
49
+ timestamp: '2026-06-29T00:00:02.000Z'
50
+ };
51
+ writeAgentRequest(homeDir, first);
52
+ writeAgentRequest(homeDir, second);
53
+ expect(readLatestAgentRequest(homeDir, 'sess-2')).toEqual(second);
54
+ });
55
+ });
56
+ describe('readLatestAgentRequest', ()=>{
57
+ it('returns null when no file exists for the session', ()=>{
58
+ expect(readLatestAgentRequest(homeDir, 'no-such-session')).toBeNull();
59
+ });
60
+ it('returns null when the file contains malformed JSON', ()=>{
61
+ const entry = {
62
+ sessionId: 'bad',
63
+ toolName: 'Bash',
64
+ toolInput: {},
65
+ timestamp: '2026-06-29T00:00:00.000Z'
66
+ };
67
+ writeAgentRequest(homeDir, entry);
68
+ writeFileSync(getAgentRequestPath(homeDir, 'bad'), 'NOT JSON{{{', 'utf-8');
69
+ expect(readLatestAgentRequest(homeDir, 'bad')).toBeNull();
70
+ });
71
+ it('returns the stored entry when the file is valid', ()=>{
72
+ const entry = {
73
+ sessionId: 'good',
74
+ toolName: 'AskUserQuestion',
75
+ toolInput: {
76
+ question: 'Which option?',
77
+ options: [
78
+ 'A',
79
+ 'B'
80
+ ]
81
+ },
82
+ timestamp: '2026-06-29T12:00:00.000Z'
83
+ };
84
+ writeAgentRequest(homeDir, entry);
85
+ expect(readLatestAgentRequest(homeDir, 'good')).toEqual(entry);
86
+ });
87
+ });
88
+ });
89
+
90
+ //# sourceMappingURL=agent-requests.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/__tests__/utils/agent-requests.test.ts"],"sourcesContent":["import { mkdtempSync, rmSync, writeFileSync } from 'fs';\nimport { tmpdir } from 'os';\nimport { join } from 'path';\nimport { getAgentRequestPath, readLatestAgentRequest, writeAgentRequest, type AgentRequest } from '../../utils/agent-requests.js';\n\ndescribe('agent-requests', () => {\n let homeDir: string;\n\n beforeEach(() => {\n homeDir = mkdtempSync(join(tmpdir(), 'agent-requests-test-'));\n });\n\n afterEach(() => {\n rmSync(homeDir, { recursive: true, force: true });\n });\n\n describe('getAgentRequestPath', () => {\n it('returns ~/.ai-devkit/agent-requests/<sessionId>.json', () => {\n expect(getAgentRequestPath(homeDir, 'abc-123')).toBe(\n join(homeDir, '.ai-devkit', 'agent-requests', 'abc-123.json'),\n );\n });\n });\n\n describe('writeAgentRequest', () => {\n it('creates the directory and file on first write', () => {\n const entry: AgentRequest = {\n sessionId: 'sess-1',\n toolName: 'Bash',\n toolInput: { command: 'ls /tmp' },\n timestamp: '2026-06-29T00:00:00.000Z',\n };\n writeAgentRequest(homeDir, entry);\n\n expect(readLatestAgentRequest(homeDir, 'sess-1')).toEqual(entry);\n });\n\n it('overwrites an existing entry on subsequent writes', () => {\n const first: AgentRequest = { sessionId: 'sess-2', toolName: 'Bash', toolInput: { command: 'echo first' }, timestamp: '2026-06-29T00:00:01.000Z' };\n const second: AgentRequest = { sessionId: 'sess-2', toolName: 'Bash', toolInput: { command: 'echo second' }, timestamp: '2026-06-29T00:00:02.000Z' };\n\n writeAgentRequest(homeDir, first);\n writeAgentRequest(homeDir, second);\n\n expect(readLatestAgentRequest(homeDir, 'sess-2')).toEqual(second);\n });\n });\n\n describe('readLatestAgentRequest', () => {\n it('returns null when no file exists for the session', () => {\n expect(readLatestAgentRequest(homeDir, 'no-such-session')).toBeNull();\n });\n\n it('returns null when the file contains malformed JSON', () => {\n const entry: AgentRequest = { sessionId: 'bad', toolName: 'Bash', toolInput: {}, timestamp: '2026-06-29T00:00:00.000Z' };\n writeAgentRequest(homeDir, entry);\n writeFileSync(getAgentRequestPath(homeDir, 'bad'), 'NOT JSON{{{', 'utf-8');\n\n expect(readLatestAgentRequest(homeDir, 'bad')).toBeNull();\n });\n\n it('returns the stored entry when the file is valid', () => {\n const entry: AgentRequest = {\n sessionId: 'good',\n toolName: 'AskUserQuestion',\n toolInput: { question: 'Which option?', options: ['A', 'B'] },\n timestamp: '2026-06-29T12:00:00.000Z',\n };\n writeAgentRequest(homeDir, entry);\n\n expect(readLatestAgentRequest(homeDir, 'good')).toEqual(entry);\n });\n });\n});\n"],"names":["mkdtempSync","rmSync","writeFileSync","tmpdir","join","getAgentRequestPath","readLatestAgentRequest","writeAgentRequest","describe","homeDir","beforeEach","afterEach","recursive","force","it","expect","toBe","entry","sessionId","toolName","toolInput","command","timestamp","toEqual","first","second","toBeNull","question","options"],"mappings":"AAAA,SAASA,WAAW,EAAEC,MAAM,EAAEC,aAAa,QAAQ,KAAK;AACxD,SAASC,MAAM,QAAQ,KAAK;AAC5B,SAASC,IAAI,QAAQ,OAAO;AAC5B,SAASC,mBAAmB,EAAEC,sBAAsB,EAAEC,iBAAiB,QAA2B,gCAAgC;AAElIC,SAAS,kBAAkB;IACvB,IAAIC;IAEJC,WAAW;QACPD,UAAUT,YAAYI,KAAKD,UAAU;IACzC;IAEAQ,UAAU;QACNV,OAAOQ,SAAS;YAAEG,WAAW;YAAMC,OAAO;QAAK;IACnD;IAEAL,SAAS,uBAAuB;QAC5BM,GAAG,wDAAwD;YACvDC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CAACN;QAC5D;IACJ;AACJ"}
package/dist/index.d.ts CHANGED
@@ -18,4 +18,6 @@ export type { RegistryEntry } from './utils/AgentRegistry.js';
18
18
  export { TmuxManager } from './terminal/TmuxManager.js';
19
19
  export { AGENTS } from './utils/agents.js';
20
20
  export type { AgentConfig, StartableAgentType } from './utils/agents.js';
21
+ export type { AgentRequest } from './utils/agent-requests.js';
22
+ export { getAgentRequestPath, readLatestAgentRequest, writeAgentRequest } from './utils/agent-requests.js';
21
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,YAAY,EACR,YAAY,EACZ,SAAS,EACT,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACxF,YAAY,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EAA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BAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACnG,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEzE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -12,5 +12,6 @@ export { getProcessTty } from './utils/process.js';
12
12
  export { AgentRegistry, RenameNotFoundError, RenameConflictError } from './utils/AgentRegistry.js';
13
13
  export { TmuxManager } from './terminal/TmuxManager.js';
14
14
  export { AGENTS } from './utils/agents.js';
15
+ export { getAgentRequestPath, readLatestAgentRequest, writeAgentRequest } from './utils/agent-requests.js';
15
16
 
16
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { AgentManager } from './AgentManager.js';\n\nexport { ClaudeCodeAdapter } from './adapters/ClaudeCodeAdapter.js';\nexport { CodexAdapter } from './adapters/CodexAdapter.js';\nexport { CopilotAdapter } from './adapters/CopilotAdapter.js';\nexport { GeminiCliAdapter } from './adapters/GeminiCliAdapter.js';\nexport { OpenCodeAdapter } from './adapters/OpenCodeAdapter.js';\nexport { PiAdapter } from './adapters/PiAdapter.js';\nexport { AgentStatus } from './adapters/AgentAdapter.js';\nexport type {\n AgentAdapter,\n AgentType,\n AgentInfo,\n ProcessInfo,\n ConversationMessage,\n SessionSummary,\n ListSessionsOptions,\n} from './adapters/AgentAdapter.js';\n\nexport { TerminalFocusManager, TerminalType } from './terminal/TerminalFocusManager.js';\nexport type { TerminalLocation } from './terminal/TerminalFocusManager.js';\nexport { TtyWriter } from './terminal/TtyWriter.js';\n\nexport { getProcessTty } from './utils/process.js';\nexport type { AgentSortKey } from './utils/sortAgents.js';\nexport type { ListAgentsOptions } from './AgentManager.js';\n\nexport { AgentRegistry, RenameNotFoundError, RenameConflictError } from './utils/AgentRegistry.js';\nexport type { RegistryEntry } from './utils/AgentRegistry.js';\nexport { TmuxManager } from './terminal/TmuxManager.js';\nexport { AGENTS } from './utils/agents.js';\nexport type { AgentConfig, StartableAgentType } from './utils/agents.js';\n"],"names":["AgentManager","ClaudeCodeAdapter","CodexAdapter","CopilotAdapter","GeminiCliAdapter","OpenCodeAdapter","PiAdapter","AgentStatus","TerminalFocusManager","TerminalType","TtyWriter","getProcessTty","AgentRegistry","RenameNotFoundError","RenameConflictError","TmuxManager","AGENTS"],"mappings":"AAAA,SAASA,YAAY,QAAQ,oBAAoB;AAEjD,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,YAAY,QAAQ,6BAA6B;AAC1D,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,gBAAgB,QAAQ,iCAAiC;AAClE,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,SAAS,QAAQ,0BAA0B;AACpD,SAASC,WAAW,QAAQ,6BAA6B;AAWzD,SAASC,oBAAoB,EAAEC,YAAY,QAAQ,qCAAqC;AAExF,SAASC,SAAS,QAAQ,0BAA0B;AAEpD,SAASC,aAAa,QAAQ,qBAAqB;AAInD,SAASC,aAAa,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,2BAA2B;AAEnG,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAASC,MAAM,QAAQ,oBAAoB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { AgentManager } from './AgentManager.js';\n\nexport { ClaudeCodeAdapter } from './adapters/ClaudeCodeAdapter.js';\nexport { CodexAdapter } from './adapters/CodexAdapter.js';\nexport { CopilotAdapter } from './adapters/CopilotAdapter.js';\nexport { GeminiCliAdapter } from './adapters/GeminiCliAdapter.js';\nexport { OpenCodeAdapter } from './adapters/OpenCodeAdapter.js';\nexport { PiAdapter } from './adapters/PiAdapter.js';\nexport { AgentStatus } from './adapters/AgentAdapter.js';\nexport type {\n AgentAdapter,\n AgentType,\n AgentInfo,\n ProcessInfo,\n ConversationMessage,\n SessionSummary,\n ListSessionsOptions,\n} from './adapters/AgentAdapter.js';\n\nexport { TerminalFocusManager, TerminalType } from './terminal/TerminalFocusManager.js';\nexport type { TerminalLocation } from './terminal/TerminalFocusManager.js';\nexport { TtyWriter } from './terminal/TtyWriter.js';\n\nexport { getProcessTty } from './utils/process.js';\nexport type { AgentSortKey } from './utils/sortAgents.js';\nexport type { ListAgentsOptions } from './AgentManager.js';\n\nexport { AgentRegistry, RenameNotFoundError, RenameConflictError } from './utils/AgentRegistry.js';\nexport type { RegistryEntry } from './utils/AgentRegistry.js';\nexport { TmuxManager } from './terminal/TmuxManager.js';\nexport { AGENTS } from './utils/agents.js';\nexport type { AgentConfig, StartableAgentType } from './utils/agents.js';\n\nexport type { AgentRequest } from './utils/agent-requests.js';\nexport { getAgentRequestPath, readLatestAgentRequest, writeAgentRequest } from './utils/agent-requests.js';\n"],"names":["AgentManager","ClaudeCodeAdapter","CodexAdapter","CopilotAdapter","GeminiCliAdapter","OpenCodeAdapter","PiAdapter","AgentStatus","TerminalFocusManager","TerminalType","TtyWriter","getProcessTty","AgentRegistry","RenameNotFoundError","RenameConflictError","TmuxManager","AGENTS","getAgentRequestPath","readLatestAgentRequest","writeAgentRequest"],"mappings":"AAAA,SAASA,YAAY,QAAQ,oBAAoB;AAEjD,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,YAAY,QAAQ,6BAA6B;AAC1D,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,gBAAgB,QAAQ,iCAAiC;AAClE,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,SAAS,QAAQ,0BAA0B;AACpD,SAASC,WAAW,QAAQ,6BAA6B;AAWzD,SAASC,oBAAoB,EAAEC,YAAY,QAAQ,qCAAqC;AAExF,SAASC,SAAS,QAAQ,0BAA0B;AAEpD,SAASC,aAAa,QAAQ,qBAAqB;AAInD,SAASC,aAAa,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,2BAA2B;AAEnG,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAASC,MAAM,QAAQ,oBAAoB;AAI3C,SAASC,mBAAmB,EAAEC,sBAAsB,EAAEC,iBAAiB,QAAQ,4BAA4B"}
@@ -1,5 +1,6 @@
1
1
  export declare enum TerminalType {
2
2
  TMUX = "tmux",
3
+ WEZTERM = "wezterm",
3
4
  ITERM2 = "iterm2",
4
5
  TERMINAL_APP = "terminal-app",
5
6
  UNKNOWN = "unknown"
@@ -9,7 +10,15 @@ export interface TerminalLocation {
9
10
  identifier: string;
10
11
  tty: string;
11
12
  }
13
+ /**
14
+ * Optional trace sink. When provided to {@link TerminalFocusManager}, each
15
+ * discovery/focus step reports a human-readable line so callers (e.g. the
16
+ * `agent open --debug` command) can inspect the matching/focus decision path.
17
+ */
18
+ export type TerminalDebugLogger = (message: string) => void;
12
19
  export declare class TerminalFocusManager {
20
+ private readonly debug?;
21
+ constructor(debug?: TerminalDebugLogger | undefined);
13
22
  /**
14
23
  * Find the terminal location (emulator info) for a given process ID
15
24
  */
@@ -18,6 +27,8 @@ export declare class TerminalFocusManager {
18
27
  * Focus the terminal identified by the location
19
28
  */
20
29
  focusTerminal(location: TerminalLocation): Promise<boolean>;
30
+ private findWeztermPane;
31
+ private focusWeztermPane;
21
32
  private findTmuxPane;
22
33
  private findITerm2Session;
23
34
  private findTerminalAppWindow;
@@ -1 +1 @@
1
- {"version":3,"file":"TerminalFocusManager.d.ts","sourceRoot":"","sources":["../../src/terminal/TerminalFocusManager.ts"],"names":[],"mappings":"AAOA,oBAAY,YA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,eAAe;YA6Bf,gBAAgB;YAShB,YAAY;YAwBZ,iBAAiB;YAsCjB,qBAAqB;YAoCrB,gBAAgB;YAQhB,aAAa;YASb,kBAAkB;YAqBlB,sBAAsB;CAmBvC"}
@@ -5,31 +5,58 @@ import { escapeAppleScript } from '../utils/applescript.js';
5
5
  const execFileAsync = promisify(execFile);
6
6
  export var TerminalType = /*#__PURE__*/ function(TerminalType) {
7
7
  TerminalType["TMUX"] = "tmux";
8
+ TerminalType["WEZTERM"] = "wezterm";
8
9
  TerminalType["ITERM2"] = "iterm2";
9
10
  TerminalType["TERMINAL_APP"] = "terminal-app";
10
11
  TerminalType["UNKNOWN"] = "unknown";
11
12
  return TerminalType;
12
13
  }({});
13
14
  export class TerminalFocusManager {
15
+ debug;
16
+ constructor(debug){
17
+ this.debug = debug;
18
+ }
14
19
  /**
15
20
  * Find the terminal location (emulator info) for a given process ID
16
21
  */ async findTerminal(pid) {
17
22
  const ttyShort = getProcessTty(pid);
18
23
  // If no TTY or invalid, we can't find the terminal
19
24
  if (!ttyShort || ttyShort === '?') {
25
+ this.debug?.(`findTerminal(pid=${pid}): no usable TTY, cannot resolve terminal`);
20
26
  return null;
21
27
  }
22
28
  const fullTty = `/dev/${ttyShort}`;
29
+ this.debug?.(`findTerminal(pid=${pid}): resolving terminal for ${fullTty}`);
23
30
  // 1. Check tmux (most specific if running inside it)
24
31
  const tmuxLocation = await this.findTmuxPane(fullTty);
25
- if (tmuxLocation) return tmuxLocation;
26
- // 2. Check iTerm2
32
+ if (tmuxLocation) {
33
+ this.debug?.(`findTerminal: matched tmux (identifier=${tmuxLocation.identifier})`);
34
+ return tmuxLocation;
35
+ }
36
+ this.debug?.('findTerminal: tmux no match');
37
+ // 2. Check WezTerm (cross-platform, via its CLI — no AppleScript)
38
+ const weztermLocation = await this.findWeztermPane(fullTty);
39
+ if (weztermLocation) {
40
+ this.debug?.(`findTerminal: matched wezterm (pane_id=${weztermLocation.identifier})`);
41
+ return weztermLocation;
42
+ }
43
+ this.debug?.('findTerminal: wezterm no match');
44
+ // 3. Check iTerm2
27
45
  const itermLocation = await this.findITerm2Session(fullTty);
28
- if (itermLocation) return itermLocation;
29
- // 3. Check Terminal.app
46
+ if (itermLocation) {
47
+ this.debug?.(`findTerminal: matched iTerm2 (tty=${itermLocation.tty})`);
48
+ return itermLocation;
49
+ }
50
+ this.debug?.('findTerminal: iTerm2 no match');
51
+ // 4. Check Terminal.app
30
52
  const terminalAppLocation = await this.findTerminalAppWindow(fullTty);
31
- if (terminalAppLocation) return terminalAppLocation;
32
- // 4. Fallback: we know the TTY but not the emulator wrapper
53
+ if (terminalAppLocation) {
54
+ this.debug?.(`findTerminal: matched Terminal.app (tty=${terminalAppLocation.tty})`);
55
+ return terminalAppLocation;
56
+ }
57
+ this.debug?.('findTerminal: Terminal.app no match');
58
+ // 5. Fallback: we know the TTY but not the emulator wrapper
59
+ this.debug?.('findTerminal: no emulator matched; returning UNKNOWN');
33
60
  return {
34
61
  type: "unknown",
35
62
  identifier: '',
@@ -39,17 +66,64 @@ export class TerminalFocusManager {
39
66
  /**
40
67
  * Focus the terminal identified by the location
41
68
  */ async focusTerminal(location) {
69
+ this.debug?.(`focusTerminal: focusing ${location.type} (identifier=${location.identifier}, tty=${location.tty})`);
70
+ let success = false;
42
71
  try {
43
72
  switch(location.type){
44
73
  case "tmux":
45
- return await this.focusTmuxPane(location.identifier);
74
+ success = await this.focusTmuxPane(location.identifier);
75
+ break;
76
+ case "wezterm":
77
+ success = await this.focusWeztermPane(location.identifier);
78
+ break;
46
79
  case "iterm2":
47
- return await this.focusITerm2Session(location.tty);
80
+ success = await this.focusITerm2Session(location.tty);
81
+ break;
48
82
  case "terminal-app":
49
- return await this.focusTerminalAppWindow(location.tty);
83
+ success = await this.focusTerminalAppWindow(location.tty);
84
+ break;
50
85
  default:
51
- return false;
86
+ success = false;
87
+ }
88
+ } catch {
89
+ success = false;
90
+ }
91
+ this.debug?.(`focusTerminal: ${success ? 'succeeded' : 'failed'} for ${location.type}`);
92
+ return success;
93
+ }
94
+ async findWeztermPane(tty) {
95
+ try {
96
+ const { stdout } = await execFileAsync('wezterm', [
97
+ 'cli',
98
+ 'list',
99
+ '--format',
100
+ 'json'
101
+ ]);
102
+ const panes = JSON.parse(stdout);
103
+ if (!Array.isArray(panes)) return null;
104
+ for (const pane of panes){
105
+ if (pane && typeof pane.tty_name === 'string' && pane.tty_name === tty && pane.pane_id != null) {
106
+ return {
107
+ type: "wezterm",
108
+ identifier: String(pane.pane_id),
109
+ tty
110
+ };
111
+ }
52
112
  }
113
+ } catch {
114
+ // wezterm not installed, not running, or returned invalid JSON
115
+ }
116
+ return null;
117
+ }
118
+ async focusWeztermPane(paneId) {
119
+ try {
120
+ await execFileAsync('wezterm', [
121
+ 'cli',
122
+ 'activate-pane',
123
+ '--pane-id',
124
+ paneId
125
+ ]);
126
+ return true;
53
127
  } catch {
54
128
  return false;
55
129
  }