@ai-devkit/agent-manager 0.1.0 → 0.3.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 (39) hide show
  1. package/dist/adapters/ClaudeCodeAdapter.d.ts +12 -0
  2. package/dist/adapters/ClaudeCodeAdapter.d.ts.map +1 -1
  3. package/dist/adapters/ClaudeCodeAdapter.js +208 -50
  4. package/dist/adapters/ClaudeCodeAdapter.js.map +1 -1
  5. package/dist/adapters/CodexAdapter.d.ts +52 -0
  6. package/dist/adapters/CodexAdapter.d.ts.map +1 -0
  7. package/dist/adapters/CodexAdapter.js +432 -0
  8. package/dist/adapters/CodexAdapter.js.map +1 -0
  9. package/dist/adapters/index.d.ts +1 -0
  10. package/dist/adapters/index.d.ts.map +1 -1
  11. package/dist/adapters/index.js +3 -1
  12. package/dist/adapters/index.js.map +1 -1
  13. package/dist/index.d.ts +3 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +6 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/terminal/TerminalFocusManager.d.ts +7 -1
  18. package/dist/terminal/TerminalFocusManager.d.ts.map +1 -1
  19. package/dist/terminal/TerminalFocusManager.js +15 -8
  20. package/dist/terminal/TerminalFocusManager.js.map +1 -1
  21. package/dist/terminal/TtyWriter.d.ts +23 -0
  22. package/dist/terminal/TtyWriter.d.ts.map +1 -0
  23. package/dist/terminal/TtyWriter.js +106 -0
  24. package/dist/terminal/TtyWriter.js.map +1 -0
  25. package/dist/terminal/index.d.ts +2 -0
  26. package/dist/terminal/index.d.ts.map +1 -1
  27. package/dist/terminal/index.js +5 -1
  28. package/dist/terminal/index.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/__tests__/adapters/ClaudeCodeAdapter.test.ts +120 -2
  31. package/src/__tests__/adapters/CodexAdapter.test.ts +319 -0
  32. package/src/__tests__/terminal/TtyWriter.test.ts +154 -0
  33. package/src/adapters/ClaudeCodeAdapter.ts +309 -56
  34. package/src/adapters/CodexAdapter.ts +584 -0
  35. package/src/adapters/index.ts +1 -0
  36. package/src/index.ts +3 -1
  37. package/src/terminal/TerminalFocusManager.ts +15 -8
  38. package/src/terminal/TtyWriter.ts +112 -0
  39. package/src/terminal/index.ts +2 -0
@@ -0,0 +1,112 @@
1
+ import { execFile } from 'child_process';
2
+ import { promisify } from 'util';
3
+ import type { TerminalLocation } from './TerminalFocusManager';
4
+ import { TerminalType } from './TerminalFocusManager';
5
+
6
+ const execFileAsync = promisify(execFile);
7
+
8
+ /**
9
+ * Escape a string for safe use inside an AppleScript double-quoted string.
10
+ * Backslashes and double quotes must be escaped.
11
+ */
12
+ function escapeAppleScript(text: string): string {
13
+ return text.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
14
+ }
15
+
16
+ export class TtyWriter {
17
+ /**
18
+ * Send a message as keyboard input to a terminal session.
19
+ *
20
+ * Dispatches to the correct mechanism based on terminal type:
21
+ * - tmux: `tmux send-keys`
22
+ * - iTerm2: AppleScript `write text`
23
+ * - Terminal.app: System Events `keystroke` + `key code 36` (Return)
24
+ *
25
+ * All AppleScript is executed via `execFile('osascript', ['-e', script])`
26
+ * to avoid shell interpolation and command injection.
27
+ *
28
+ * @param location Terminal location from TerminalFocusManager.findTerminal()
29
+ * @param message Text to send
30
+ * @throws Error if terminal type is unsupported or send fails
31
+ */
32
+ static async send(location: TerminalLocation, message: string): Promise<void> {
33
+ switch (location.type) {
34
+ case TerminalType.TMUX:
35
+ return TtyWriter.sendViaTmux(location.identifier, message);
36
+ case TerminalType.ITERM2:
37
+ return TtyWriter.sendViaITerm2(location.tty, message);
38
+ case TerminalType.TERMINAL_APP:
39
+ return TtyWriter.sendViaTerminalApp(location.tty, message);
40
+ default:
41
+ throw new Error(
42
+ `Cannot send input: unsupported terminal type "${location.type}". ` +
43
+ 'Supported: tmux, iTerm2, Terminal.app.'
44
+ );
45
+ }
46
+ }
47
+
48
+ private static async sendViaTmux(identifier: string, message: string): Promise<void> {
49
+ await execFileAsync('tmux', ['send-keys', '-t', identifier, message, 'Enter']);
50
+ }
51
+
52
+ private static async sendViaITerm2(tty: string, message: string): Promise<void> {
53
+ const escaped = escapeAppleScript(message);
54
+ const script = `
55
+ tell application "iTerm"
56
+ repeat with w in windows
57
+ repeat with t in tabs of w
58
+ repeat with s in sessions of t
59
+ if tty of s is "${tty}" then
60
+ tell s to write text "${escaped}"
61
+ return "ok"
62
+ end if
63
+ end repeat
64
+ end repeat
65
+ end repeat
66
+ end tell
67
+ return "not_found"`;
68
+
69
+ const { stdout } = await execFileAsync('osascript', ['-e', script]);
70
+ if (stdout.trim() !== 'ok') {
71
+ throw new Error(`iTerm2 session not found for TTY ${tty}`);
72
+ }
73
+ }
74
+
75
+ private static async sendViaTerminalApp(tty: string, message: string): Promise<void> {
76
+ const escaped = escapeAppleScript(message);
77
+ // Use System Events keystroke to type into the foreground process,
78
+ // NOT Terminal.app's "do script" which runs a new shell command.
79
+ // First activate Terminal and select the correct tab, then type via System Events.
80
+ const script = `
81
+ tell application "Terminal"
82
+ set targetFound to false
83
+ repeat with w in windows
84
+ repeat with i from 1 to count of tabs of w
85
+ set t to tab i of w
86
+ if tty of t is "${tty}" then
87
+ set selected tab of w to t
88
+ set index of w to 1
89
+ activate
90
+ set targetFound to true
91
+ exit repeat
92
+ end if
93
+ end repeat
94
+ if targetFound then exit repeat
95
+ end repeat
96
+ if not targetFound then return "not_found"
97
+ end tell
98
+ delay 0.1
99
+ tell application "System Events"
100
+ tell process "Terminal"
101
+ keystroke "${escaped}"
102
+ key code 36
103
+ end tell
104
+ end tell
105
+ return "ok"`;
106
+
107
+ const { stdout } = await execFileAsync('osascript', ['-e', script]);
108
+ if (stdout.trim() !== 'ok') {
109
+ throw new Error(`Terminal.app tab not found for TTY ${tty}`);
110
+ }
111
+ }
112
+ }
@@ -1,2 +1,4 @@
1
1
  export { TerminalFocusManager } from './TerminalFocusManager';
2
+ export { TerminalType } from './TerminalFocusManager';
2
3
  export type { TerminalLocation } from './TerminalFocusManager';
4
+ export { TtyWriter } from './TtyWriter';