genbox-agent 0.0.2 → 1.0.1

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 (46) hide show
  1. package/dist/configure-hooks.d.ts +17 -0
  2. package/dist/configure-hooks.d.ts.map +1 -0
  3. package/dist/configure-hooks.js +235 -0
  4. package/dist/configure-hooks.js.map +1 -0
  5. package/dist/index.d.ts +16 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +41 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/providers/base-provider.d.ts +125 -0
  10. package/dist/providers/base-provider.d.ts.map +1 -0
  11. package/dist/providers/base-provider.js +217 -0
  12. package/dist/providers/base-provider.js.map +1 -0
  13. package/dist/providers/claude-provider.d.ts +35 -0
  14. package/dist/providers/claude-provider.d.ts.map +1 -0
  15. package/dist/providers/claude-provider.js +298 -0
  16. package/dist/providers/claude-provider.js.map +1 -0
  17. package/dist/providers/codex-provider.d.ts +73 -0
  18. package/dist/providers/codex-provider.d.ts.map +1 -0
  19. package/dist/providers/codex-provider.js +426 -0
  20. package/dist/providers/codex-provider.js.map +1 -0
  21. package/dist/providers/gemini-provider.d.ts +37 -0
  22. package/dist/providers/gemini-provider.d.ts.map +1 -0
  23. package/dist/providers/gemini-provider.js +352 -0
  24. package/dist/providers/gemini-provider.js.map +1 -0
  25. package/dist/providers/index.d.ts +128 -0
  26. package/dist/providers/index.d.ts.map +1 -0
  27. package/dist/providers/index.js +293 -0
  28. package/dist/providers/index.js.map +1 -0
  29. package/dist/types/index.d.ts +123 -0
  30. package/dist/types/index.d.ts.map +1 -0
  31. package/dist/types/index.js +9 -0
  32. package/dist/types/index.js.map +1 -0
  33. package/dist/unified-daemon.d.ts +18 -0
  34. package/dist/unified-daemon.d.ts.map +1 -0
  35. package/dist/unified-daemon.js +309 -0
  36. package/dist/unified-daemon.js.map +1 -0
  37. package/dist/unified-hook.d.ts +24 -0
  38. package/dist/unified-hook.d.ts.map +1 -0
  39. package/dist/unified-hook.js +173 -0
  40. package/dist/unified-hook.js.map +1 -0
  41. package/package.json +34 -8
  42. package/src/daemon.ts +0 -329
  43. package/src/hook.ts +0 -200
  44. package/src/index.ts +0 -1
  45. package/src/session-manager.ts +0 -270
  46. package/tsconfig.json +0 -19
@@ -1,270 +0,0 @@
1
- import { execSync, spawn } from 'child_process';
2
- import * as crypto from 'crypto';
3
-
4
- export interface ClaudeSession {
5
- sessionName: string;
6
- sessionId: string;
7
- projectPath: string;
8
- createdAt: number;
9
- status: string;
10
- }
11
-
12
- /**
13
- * Manages tmux sessions running Claude Code.
14
- */
15
- export class SessionManager {
16
- private readonly TMUX_PREFIX = 'claude-';
17
- private sessions: Map<string, ClaudeSession> = new Map();
18
-
19
- constructor(private readonly genboxId: string) {}
20
-
21
- private runTmux(args: string[], timeout = 10000): { stdout: string; stderr: string; success: boolean } {
22
- try {
23
- const stdout = execSync(`tmux ${args.join(' ')}`, {
24
- timeout,
25
- encoding: 'utf-8',
26
- stdio: ['pipe', 'pipe', 'pipe'],
27
- });
28
- return { stdout: stdout || '', stderr: '', success: true };
29
- } catch (error: any) {
30
- return {
31
- stdout: error.stdout?.toString() || '',
32
- stderr: error.stderr?.toString() || error.message,
33
- success: false,
34
- };
35
- }
36
- }
37
-
38
- private generateSessionId(): string {
39
- return crypto
40
- .createHash('sha256')
41
- .update(`${this.genboxId}-${Date.now()}-${process.pid}`)
42
- .digest('hex')
43
- .slice(0, 16);
44
- }
45
-
46
- /**
47
- * Create a new Claude Code session in tmux.
48
- */
49
- createSession(projectPath = '/home/dev'): ClaudeSession | null {
50
- const sessionId = this.generateSessionId();
51
- const sessionName = `${this.TMUX_PREFIX}${sessionId}`;
52
-
53
- // Create a new detached tmux session
54
- const result = this.runTmux([
55
- 'new-session',
56
- '-d',
57
- '-s', sessionName,
58
- '-c', projectPath,
59
- ]);
60
-
61
- if (!result.success) {
62
- console.error(`Failed to create tmux session: ${result.stderr}`);
63
- return null;
64
- }
65
-
66
- // Give tmux a moment to initialize
67
- execSync('sleep 0.5');
68
-
69
- // Start Claude Code in the session
70
- this.runTmux([
71
- 'send-keys',
72
- '-t', sessionName,
73
- 'claude',
74
- 'Enter',
75
- ]);
76
-
77
- const session: ClaudeSession = {
78
- sessionName,
79
- sessionId,
80
- projectPath,
81
- createdAt: Date.now(),
82
- status: 'active',
83
- };
84
-
85
- this.sessions.set(sessionId, session);
86
- return session;
87
- }
88
-
89
- /**
90
- * Send a prompt to a Claude Code session.
91
- */
92
- sendPrompt(sessionId: string, prompt: string): boolean {
93
- const session = this.sessions.get(sessionId);
94
- const sessionName = session?.sessionName || `${this.TMUX_PREFIX}${sessionId}`;
95
-
96
- // Send the prompt text with literal flag to handle special characters
97
- const textResult = this.runTmux([
98
- 'send-keys',
99
- '-t', sessionName,
100
- '-l', // Literal flag
101
- `"${prompt.replace(/"/g, '\\"')}"`,
102
- ]);
103
-
104
- if (!textResult.success) {
105
- console.error(`Failed to send prompt text: ${textResult.stderr}`);
106
- return false;
107
- }
108
-
109
- // Send Enter to submit the prompt
110
- const enterResult = this.runTmux([
111
- 'send-keys',
112
- '-t', sessionName,
113
- 'Enter',
114
- ]);
115
-
116
- if (!enterResult.success) {
117
- console.error(`Failed to send Enter: ${enterResult.stderr}`);
118
- return false;
119
- }
120
-
121
- return true;
122
- }
123
-
124
- /**
125
- * Send a keystroke to a Claude Code session.
126
- */
127
- sendKeystroke(sessionId: string, key: string): boolean {
128
- const session = this.sessions.get(sessionId);
129
- const sessionName = session?.sessionName || `${this.TMUX_PREFIX}${sessionId}`;
130
-
131
- // Map common key names to tmux key names
132
- const keyMap: Record<string, string> = {
133
- enter: 'Enter',
134
- escape: 'Escape',
135
- up: 'Up',
136
- down: 'Down',
137
- left: 'Left',
138
- right: 'Right',
139
- tab: 'Tab',
140
- backspace: 'BSpace',
141
- delete: 'DC',
142
- 'ctrl-c': 'C-c',
143
- 'ctrl-d': 'C-d',
144
- 'ctrl-z': 'C-z',
145
- y: 'y',
146
- n: 'n',
147
- };
148
-
149
- const tmuxKey = keyMap[key.toLowerCase()] || key;
150
-
151
- const result = this.runTmux([
152
- 'send-keys',
153
- '-t', sessionName,
154
- tmuxKey,
155
- ]);
156
-
157
- return result.success;
158
- }
159
-
160
- /**
161
- * Capture the terminal output from a session.
162
- */
163
- getOutput(sessionId: string, lines = 100): string | null {
164
- const session = this.sessions.get(sessionId);
165
- const sessionName = session?.sessionName || `${this.TMUX_PREFIX}${sessionId}`;
166
-
167
- const result = this.runTmux([
168
- 'capture-pane',
169
- '-t', sessionName,
170
- '-p', // Print to stdout
171
- '-S', `-${lines}`, // Start from lines back
172
- ]);
173
-
174
- return result.success ? result.stdout : null;
175
- }
176
-
177
- /**
178
- * Get the status of a session.
179
- */
180
- getSessionStatus(sessionId: string): string {
181
- const session = this.sessions.get(sessionId);
182
- const sessionName = session?.sessionName || `${this.TMUX_PREFIX}${sessionId}`;
183
-
184
- // Check if session exists
185
- const hasSession = this.runTmux(['has-session', '-t', sessionName]);
186
- if (!hasSession.success) {
187
- return 'ended';
188
- }
189
-
190
- // Get pane content to determine status
191
- const output = this.getOutput(sessionId, 10);
192
- if (output) {
193
- const lowerOutput = output.toLowerCase();
194
- const lastLine = output.split('\n').pop() || '';
195
-
196
- if (lowerOutput.includes('waiting for input') || lastLine.includes('>')) {
197
- return 'waiting_input';
198
- }
199
- if (lowerOutput.includes('error')) {
200
- return 'error';
201
- }
202
- if (lowerOutput.includes('thinking') || lowerOutput.includes('working')) {
203
- return 'active';
204
- }
205
- }
206
-
207
- return 'idle';
208
- }
209
-
210
- /**
211
- * Kill a Claude Code session.
212
- */
213
- killSession(sessionId: string): boolean {
214
- const session = this.sessions.get(sessionId);
215
- const sessionName = session?.sessionName || `${this.TMUX_PREFIX}${sessionId}`;
216
-
217
- const result = this.runTmux(['kill-session', '-t', sessionName]);
218
-
219
- if (result.success) {
220
- this.sessions.delete(sessionId);
221
- }
222
-
223
- return result.success;
224
- }
225
-
226
- /**
227
- * List all Claude Code sessions.
228
- */
229
- listSessions(): Array<{
230
- sessionId: string;
231
- sessionName: string;
232
- createdAt: number;
233
- status: string;
234
- }> {
235
- const result = this.runTmux([
236
- 'list-sessions',
237
- '-F', '#{session_name}:#{session_created}',
238
- ]);
239
-
240
- if (!result.success) {
241
- return [];
242
- }
243
-
244
- const sessions: Array<{
245
- sessionId: string;
246
- sessionName: string;
247
- createdAt: number;
248
- status: string;
249
- }> = [];
250
-
251
- for (const line of result.stdout.trim().split('\n')) {
252
- if (!line || !line.startsWith(this.TMUX_PREFIX)) {
253
- continue;
254
- }
255
-
256
- const [sessionName, createdAtStr] = line.split(':');
257
- const sessionId = sessionName.replace(this.TMUX_PREFIX, '');
258
- const createdAt = parseInt(createdAtStr, 10) * 1000 || 0;
259
-
260
- sessions.push({
261
- sessionId,
262
- sessionName,
263
- createdAt,
264
- status: this.getSessionStatus(sessionId),
265
- });
266
- }
267
-
268
- return sessions;
269
- }
270
- }
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "commonjs",
5
- "lib": ["ES2022"],
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "resolveJsonModule": true,
13
- "declaration": true,
14
- "declarationMap": true,
15
- "sourceMap": true
16
- },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules", "dist"]
19
- }