@ai-devkit/agent-manager 0.1.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 (57) hide show
  1. package/.eslintrc.json +31 -0
  2. package/dist/AgentManager.d.ts +104 -0
  3. package/dist/AgentManager.d.ts.map +1 -0
  4. package/dist/AgentManager.js +185 -0
  5. package/dist/AgentManager.js.map +1 -0
  6. package/dist/adapters/AgentAdapter.d.ts +76 -0
  7. package/dist/adapters/AgentAdapter.d.ts.map +1 -0
  8. package/dist/adapters/AgentAdapter.js +20 -0
  9. package/dist/adapters/AgentAdapter.js.map +1 -0
  10. package/dist/adapters/ClaudeCodeAdapter.d.ts +58 -0
  11. package/dist/adapters/ClaudeCodeAdapter.d.ts.map +1 -0
  12. package/dist/adapters/ClaudeCodeAdapter.js +274 -0
  13. package/dist/adapters/ClaudeCodeAdapter.js.map +1 -0
  14. package/dist/adapters/index.d.ts +4 -0
  15. package/dist/adapters/index.d.ts.map +1 -0
  16. package/dist/adapters/index.js +8 -0
  17. package/dist/adapters/index.js.map +1 -0
  18. package/dist/index.d.ts +10 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +23 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/terminal/TerminalFocusManager.d.ts +22 -0
  23. package/dist/terminal/TerminalFocusManager.d.ts.map +1 -0
  24. package/dist/terminal/TerminalFocusManager.js +196 -0
  25. package/dist/terminal/TerminalFocusManager.js.map +1 -0
  26. package/dist/terminal/index.d.ts +3 -0
  27. package/dist/terminal/index.d.ts.map +1 -0
  28. package/dist/terminal/index.js +6 -0
  29. package/dist/terminal/index.js.map +1 -0
  30. package/dist/utils/file.d.ts +52 -0
  31. package/dist/utils/file.d.ts.map +1 -0
  32. package/dist/utils/file.js +135 -0
  33. package/dist/utils/file.js.map +1 -0
  34. package/dist/utils/index.d.ts +4 -0
  35. package/dist/utils/index.d.ts.map +1 -0
  36. package/dist/utils/index.js +15 -0
  37. package/dist/utils/index.js.map +1 -0
  38. package/dist/utils/process.d.ts +61 -0
  39. package/dist/utils/process.d.ts.map +1 -0
  40. package/dist/utils/process.js +166 -0
  41. package/dist/utils/process.js.map +1 -0
  42. package/jest.config.js +21 -0
  43. package/package.json +42 -0
  44. package/project.json +29 -0
  45. package/src/AgentManager.ts +198 -0
  46. package/src/__tests__/AgentManager.test.ts +308 -0
  47. package/src/__tests__/adapters/ClaudeCodeAdapter.test.ts +286 -0
  48. package/src/adapters/AgentAdapter.ts +94 -0
  49. package/src/adapters/ClaudeCodeAdapter.ts +344 -0
  50. package/src/adapters/index.ts +3 -0
  51. package/src/index.ts +12 -0
  52. package/src/terminal/TerminalFocusManager.ts +206 -0
  53. package/src/terminal/index.ts +2 -0
  54. package/src/utils/file.ts +100 -0
  55. package/src/utils/index.ts +3 -0
  56. package/src/utils/process.ts +184 -0
  57. package/tsconfig.json +17 -0
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Process Detection Utilities
3
+ *
4
+ * Utilities for detecting and inspecting running processes on the system.
5
+ * Primarily focused on macOS/Unix-like systems using the `ps` command.
6
+ */
7
+
8
+ import { execSync } from 'child_process';
9
+ import type { ProcessInfo } from '../adapters/AgentAdapter';
10
+
11
+ /**
12
+ * Options for listing processes
13
+ */
14
+ export interface ListProcessesOptions {
15
+ /** Filter processes by name pattern (case-insensitive) */
16
+ namePattern?: string;
17
+
18
+ /** Include only processes matching these PIDs */
19
+ pids?: number[];
20
+ }
21
+
22
+ /**
23
+ * List running processes on the system
24
+ *
25
+ * @param options Filtering options
26
+ * @returns Array of process information
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * // List all Claude Code processes
31
+ * const processes = listProcesses({ namePattern: 'claude' });
32
+ *
33
+ * // Get specific process info
34
+ * const process = listProcesses({ pids: [12345] });
35
+ * ```
36
+ */
37
+ export function listProcesses(options: ListProcessesOptions = {}): ProcessInfo[] {
38
+ try {
39
+ // Get all processes with full details
40
+ // Format: user pid command
41
+ const psOutput = execSync('ps aux', { encoding: 'utf-8' });
42
+
43
+ const lines = psOutput.trim().split('\n');
44
+ // Skip header line
45
+ const processLines = lines.slice(1);
46
+
47
+ const processes: ProcessInfo[] = [];
48
+
49
+ for (const line of processLines) {
50
+ // Parse ps aux output
51
+ // Format: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
52
+ const parts = line.trim().split(/\s+/);
53
+
54
+ if (parts.length < 11) continue;
55
+
56
+ const pid = parseInt(parts[1], 10);
57
+ if (isNaN(pid)) continue;
58
+
59
+ const tty = parts[6];
60
+ const command = parts.slice(10).join(' ');
61
+
62
+ // Apply PID filter
63
+ if (options.pids && !options.pids.includes(pid)) {
64
+ continue;
65
+ }
66
+
67
+ // Apply name pattern filter (case-insensitive)
68
+ if (options.namePattern) {
69
+ const pattern = options.namePattern.toLowerCase();
70
+ const commandLower = command.toLowerCase();
71
+ if (!commandLower.includes(pattern)) {
72
+ continue;
73
+ }
74
+ }
75
+
76
+ // Get working directory for this process
77
+ const cwd = getProcessCwd(pid);
78
+
79
+ // Get TTY in short format (remove /dev/ prefix if present)
80
+ const ttyShort = tty.startsWith('/dev/') ? tty.slice(5) : tty;
81
+
82
+ processes.push({
83
+ pid,
84
+ command,
85
+ cwd,
86
+ tty: ttyShort,
87
+ });
88
+ }
89
+
90
+ return processes;
91
+ } catch (error) {
92
+ // If ps command fails, return empty array
93
+ console.error('Failed to list processes:', error);
94
+ return [];
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Get the current working directory for a specific process
100
+ *
101
+ * @param pid Process ID
102
+ * @returns Working directory path, or empty string if unavailable
103
+ */
104
+ export function getProcessCwd(pid: number): string {
105
+ try {
106
+ // Use lsof to get the current working directory
107
+ // -a: AND the selections, -d cwd: get cwd only, -Fn: output format (file names only)
108
+ const output = execSync(`lsof -a -p ${pid} -d cwd -Fn 2>/dev/null`, {
109
+ encoding: 'utf-8',
110
+ });
111
+
112
+ // Parse lsof output
113
+ // Format: p{PID}\nn{path}
114
+ const lines = output.trim().split('\n');
115
+ for (const line of lines) {
116
+ if (line.startsWith('n')) {
117
+ return line.slice(1); // Remove 'n' prefix
118
+ }
119
+ }
120
+
121
+ return '';
122
+ } catch (error) {
123
+ // If lsof fails, try alternative method using pwdx (Linux)
124
+ try {
125
+ const output = execSync(`pwdx ${pid} 2>/dev/null`, {
126
+ encoding: 'utf-8',
127
+ });
128
+ // Format: {PID}: {path}
129
+ const match = output.match(/^\d+:\s*(.+)$/);
130
+ return match ? match[1].trim() : '';
131
+ } catch {
132
+ // Both methods failed
133
+ return '';
134
+ }
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Get the TTY device for a specific process
140
+ *
141
+ * @param pid Process ID
142
+ * @returns TTY device name (e.g., "ttys030"), or "?" if unavailable
143
+ */
144
+ export function getProcessTty(pid: number): string {
145
+ try {
146
+ const output = execSync(`ps -p ${pid} -o tty=`, {
147
+ encoding: 'utf-8',
148
+ });
149
+
150
+ const tty = output.trim();
151
+ // Remove /dev/ prefix if present
152
+ return tty.startsWith('/dev/') ? tty.slice(5) : tty;
153
+ } catch (error) {
154
+ return '?';
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Check if a process with the given PID is running
160
+ *
161
+ * @param pid Process ID
162
+ * @returns True if process is running
163
+ */
164
+ export function isProcessRunning(pid: number): boolean {
165
+ try {
166
+ // Send signal 0 to check if process exists
167
+ // This doesn't actually send a signal, just checks if we can
168
+ execSync(`kill -0 ${pid} 2>/dev/null`);
169
+ return true;
170
+ } catch {
171
+ return false;
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Get detailed information for a specific process
177
+ *
178
+ * @param pid Process ID
179
+ * @returns Process information, or null if process not found
180
+ */
181
+ export function getProcessInfo(pid: number): ProcessInfo | null {
182
+ const processes = listProcesses({ pids: [pid] });
183
+ return processes.length > 0 ? processes[0] : null;
184
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "moduleResolution": "node",
6
+ "rootDir": "./src",
7
+ "outDir": "./dist"
8
+ },
9
+ "include": [
10
+ "src/**/*"
11
+ ],
12
+ "exclude": [
13
+ "node_modules",
14
+ "dist",
15
+ "src/__tests__"
16
+ ]
17
+ }