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.
- package/dist/configure-hooks.d.ts +17 -0
- package/dist/configure-hooks.d.ts.map +1 -0
- package/dist/configure-hooks.js +235 -0
- package/dist/configure-hooks.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/base-provider.d.ts +125 -0
- package/dist/providers/base-provider.d.ts.map +1 -0
- package/dist/providers/base-provider.js +217 -0
- package/dist/providers/base-provider.js.map +1 -0
- package/dist/providers/claude-provider.d.ts +35 -0
- package/dist/providers/claude-provider.d.ts.map +1 -0
- package/dist/providers/claude-provider.js +298 -0
- package/dist/providers/claude-provider.js.map +1 -0
- package/dist/providers/codex-provider.d.ts +73 -0
- package/dist/providers/codex-provider.d.ts.map +1 -0
- package/dist/providers/codex-provider.js +426 -0
- package/dist/providers/codex-provider.js.map +1 -0
- package/dist/providers/gemini-provider.d.ts +37 -0
- package/dist/providers/gemini-provider.d.ts.map +1 -0
- package/dist/providers/gemini-provider.js +352 -0
- package/dist/providers/gemini-provider.js.map +1 -0
- package/dist/providers/index.d.ts +128 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +293 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/types/index.d.ts +123 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +9 -0
- package/dist/types/index.js.map +1 -0
- package/dist/unified-daemon.d.ts +18 -0
- package/dist/unified-daemon.d.ts.map +1 -0
- package/dist/unified-daemon.js +309 -0
- package/dist/unified-daemon.js.map +1 -0
- package/dist/unified-hook.d.ts +24 -0
- package/dist/unified-hook.d.ts.map +1 -0
- package/dist/unified-hook.js +173 -0
- package/dist/unified-hook.js.map +1 -0
- package/package.json +34 -8
- package/src/daemon.ts +0 -329
- package/src/hook.ts +0 -200
- package/src/index.ts +0 -1
- package/src/session-manager.ts +0 -270
- package/tsconfig.json +0 -19
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base Provider Interface and Abstract Class
|
|
4
|
+
*
|
|
5
|
+
* Defines the contract that all AI CLI providers must implement
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.BaseProvider = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class with common functionality
|
|
11
|
+
*/
|
|
12
|
+
class BaseProvider {
|
|
13
|
+
genboxId;
|
|
14
|
+
/**
|
|
15
|
+
* Common key mapping for tmux send-keys
|
|
16
|
+
*/
|
|
17
|
+
keyMap = {
|
|
18
|
+
enter: 'Enter',
|
|
19
|
+
escape: 'Escape',
|
|
20
|
+
up: 'Up',
|
|
21
|
+
down: 'Down',
|
|
22
|
+
left: 'Left',
|
|
23
|
+
right: 'Right',
|
|
24
|
+
tab: 'Tab',
|
|
25
|
+
backspace: 'BSpace',
|
|
26
|
+
delete: 'DC',
|
|
27
|
+
'ctrl-c': 'C-c',
|
|
28
|
+
'ctrl-d': 'C-d',
|
|
29
|
+
'ctrl-z': 'C-z',
|
|
30
|
+
y: 'y',
|
|
31
|
+
n: 'n',
|
|
32
|
+
};
|
|
33
|
+
constructor(genboxId) {
|
|
34
|
+
this.genboxId = genboxId;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Map provider event type to unified event type
|
|
38
|
+
*/
|
|
39
|
+
mapEventType(providerEventType) {
|
|
40
|
+
const mapping = this.config.eventMapping[providerEventType];
|
|
41
|
+
if (mapping) {
|
|
42
|
+
return mapping;
|
|
43
|
+
}
|
|
44
|
+
// Default mapping for unknown events
|
|
45
|
+
console.warn(`Unknown event type: ${providerEventType} for provider ${this.config.provider}`);
|
|
46
|
+
return 'notification';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Execute a tmux command
|
|
50
|
+
*/
|
|
51
|
+
runTmux(args, timeout = 10000) {
|
|
52
|
+
const { execSync } = require('child_process');
|
|
53
|
+
try {
|
|
54
|
+
const stdout = execSync(`tmux ${args.join(' ')}`, {
|
|
55
|
+
timeout,
|
|
56
|
+
encoding: 'utf-8',
|
|
57
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
58
|
+
});
|
|
59
|
+
return { stdout: stdout || '', stderr: '', success: true };
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
stdout: error.stdout?.toString() || '',
|
|
64
|
+
stderr: error.stderr?.toString() || error.message,
|
|
65
|
+
success: false,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the tmux session name for a session ID
|
|
71
|
+
*/
|
|
72
|
+
getSessionName(sessionId) {
|
|
73
|
+
return `${this.config.tmuxPrefix}${sessionId}`;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Send a prompt to a session via tmux
|
|
77
|
+
*/
|
|
78
|
+
sendPrompt(sessionId, prompt) {
|
|
79
|
+
const sessionName = this.getSessionName(sessionId);
|
|
80
|
+
// Send the prompt text with literal flag
|
|
81
|
+
const textResult = this.runTmux([
|
|
82
|
+
'send-keys',
|
|
83
|
+
'-t', sessionName,
|
|
84
|
+
'-l',
|
|
85
|
+
`"${prompt.replace(/"/g, '\\"')}"`,
|
|
86
|
+
]);
|
|
87
|
+
if (!textResult.success) {
|
|
88
|
+
console.error(`Failed to send prompt text: ${textResult.stderr}`);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
// Send Enter to submit
|
|
92
|
+
const enterResult = this.runTmux([
|
|
93
|
+
'send-keys',
|
|
94
|
+
'-t', sessionName,
|
|
95
|
+
'Enter',
|
|
96
|
+
]);
|
|
97
|
+
if (!enterResult.success) {
|
|
98
|
+
console.error(`Failed to send Enter: ${enterResult.stderr}`);
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Send a keystroke to a session via tmux
|
|
105
|
+
*/
|
|
106
|
+
sendKeystroke(sessionId, key) {
|
|
107
|
+
const sessionName = this.getSessionName(sessionId);
|
|
108
|
+
const tmuxKey = this.keyMap[key.toLowerCase()] || key;
|
|
109
|
+
const result = this.runTmux([
|
|
110
|
+
'send-keys',
|
|
111
|
+
'-t', sessionName,
|
|
112
|
+
tmuxKey,
|
|
113
|
+
]);
|
|
114
|
+
return result.success;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Capture terminal output from a session
|
|
118
|
+
*/
|
|
119
|
+
getOutput(sessionId, lines = 100) {
|
|
120
|
+
const sessionName = this.getSessionName(sessionId);
|
|
121
|
+
const result = this.runTmux([
|
|
122
|
+
'capture-pane',
|
|
123
|
+
'-t', sessionName,
|
|
124
|
+
'-p',
|
|
125
|
+
'-S', `-${lines}`,
|
|
126
|
+
]);
|
|
127
|
+
return result.success ? result.stdout : null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get session status by analyzing terminal output
|
|
131
|
+
*/
|
|
132
|
+
getSessionStatus(sessionId) {
|
|
133
|
+
const sessionName = this.getSessionName(sessionId);
|
|
134
|
+
// Check if session exists
|
|
135
|
+
const hasSession = this.runTmux(['has-session', '-t', sessionName]);
|
|
136
|
+
if (!hasSession.success) {
|
|
137
|
+
return 'ended';
|
|
138
|
+
}
|
|
139
|
+
const output = this.getOutput(sessionId, 10);
|
|
140
|
+
if (output) {
|
|
141
|
+
return this.analyzeOutputForStatus(output);
|
|
142
|
+
}
|
|
143
|
+
return 'idle';
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Analyze terminal output to determine status
|
|
147
|
+
* Subclasses can override for provider-specific logic
|
|
148
|
+
*/
|
|
149
|
+
analyzeOutputForStatus(output) {
|
|
150
|
+
const lowerOutput = output.toLowerCase();
|
|
151
|
+
const lastLine = output.split('\n').pop() || '';
|
|
152
|
+
if (lowerOutput.includes('waiting for input') || lastLine.includes('>')) {
|
|
153
|
+
return 'waiting_input';
|
|
154
|
+
}
|
|
155
|
+
if (lowerOutput.includes('error')) {
|
|
156
|
+
return 'error';
|
|
157
|
+
}
|
|
158
|
+
if (lowerOutput.includes('thinking') || lowerOutput.includes('working')) {
|
|
159
|
+
return 'active';
|
|
160
|
+
}
|
|
161
|
+
return 'idle';
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Kill a session
|
|
165
|
+
*/
|
|
166
|
+
killSession(sessionId) {
|
|
167
|
+
const sessionName = this.getSessionName(sessionId);
|
|
168
|
+
const result = this.runTmux(['kill-session', '-t', sessionName]);
|
|
169
|
+
return result.success;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* List all sessions for this provider
|
|
173
|
+
*/
|
|
174
|
+
listSessions() {
|
|
175
|
+
const result = this.runTmux([
|
|
176
|
+
'list-sessions',
|
|
177
|
+
'-F', '#{session_name}:#{session_created}',
|
|
178
|
+
]);
|
|
179
|
+
if (!result.success) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
const sessions = [];
|
|
183
|
+
for (const line of result.stdout.trim().split('\n')) {
|
|
184
|
+
if (!line || !line.startsWith(this.config.tmuxPrefix)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const [sessionName, createdAtStr] = line.split(':');
|
|
188
|
+
const sessionId = sessionName.replace(this.config.tmuxPrefix, '');
|
|
189
|
+
const createdAt = parseInt(createdAtStr, 10) * 1000 || 0;
|
|
190
|
+
sessions.push({
|
|
191
|
+
sessionId,
|
|
192
|
+
sessionName,
|
|
193
|
+
provider: this.config.provider,
|
|
194
|
+
projectPath: '/home/dev', // Default, actual path tracked elsewhere
|
|
195
|
+
createdAt,
|
|
196
|
+
status: this.getSessionStatus(sessionId),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return sessions;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Create base hook event with common fields
|
|
203
|
+
*/
|
|
204
|
+
createBaseHookEvent(eventType, sessionId) {
|
|
205
|
+
return {
|
|
206
|
+
provider: this.config.provider,
|
|
207
|
+
providerEventType: eventType,
|
|
208
|
+
eventType: this.mapEventType(eventType),
|
|
209
|
+
sessionId,
|
|
210
|
+
genboxId: this.genboxId,
|
|
211
|
+
timestamp: new Date().toISOString(),
|
|
212
|
+
projectPath: process.cwd(),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.BaseProvider = BaseProvider;
|
|
217
|
+
//# sourceMappingURL=base-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-provider.js","sourceRoot":"","sources":["../../src/providers/base-provider.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA6EH;;GAEG;AACH,MAAsB,YAAY;IAuBD;IApB/B;;OAEG;IACgB,MAAM,GAA2B;QAClD,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;QACd,GAAG,EAAE,KAAK;QACV,SAAS,EAAE,QAAQ;QACnB,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,KAAK;QACf,CAAC,EAAE,GAAG;QACN,CAAC,EAAE,GAAG;KACP,CAAC;IAEF,YAA+B,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;IAAG,CAAC;IAOnD;;OAEG;IACH,YAAY,CAAC,iBAAyB;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;QAC5D,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,qCAAqC;Q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;QACL,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACO,mBAAmB,CAC3B,SAAiB,EACjB,SAAiB;QAEjB,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9B,iBAAiB,EAAE,SAAS;YAC5B,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC;YACvC,SAAS;YACT,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,WAAW,EAAE,OAAO,CAAC,GAAG,EAAE;SAC3B,CAAC;IACJ,CAAC;CACF;AAjPD,oCAiPC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code Provider
|
|
3
|
+
*
|
|
4
|
+
* Provider implementation for Anthropic's Claude Code CLI
|
|
5
|
+
*/
|
|
6
|
+
import { AISession, ProviderConfig, ProviderDetectionResult, UnifiedHookEvent, HookConfig } from '../types';
|
|
7
|
+
import { BaseProvider } from './base-provider';
|
|
8
|
+
export declare class ClaudeProvider extends BaseProvider {
|
|
9
|
+
readonly config: ProviderConfig;
|
|
10
|
+
private sessions;
|
|
11
|
+
constructor(genboxId: string);
|
|
12
|
+
/**
|
|
13
|
+
* Detect if Claude Code CLI is installed
|
|
14
|
+
*/
|
|
15
|
+
detect(): ProviderDetectionResult;
|
|
16
|
+
/**
|
|
17
|
+
* Create a new Claude Code session
|
|
18
|
+
*/
|
|
19
|
+
createSession(projectPath?: string): AISession | null;
|
|
20
|
+
/**
|
|
21
|
+
* Parse Claude Code hook input
|
|
22
|
+
*/
|
|
23
|
+
parseHookInput(eventType: string, rawInput: string): UnifiedHookEvent;
|
|
24
|
+
/**
|
|
25
|
+
* Generate Claude Code hook configuration
|
|
26
|
+
*/
|
|
27
|
+
generateHookConfig(hookScriptPath: string): HookConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Analyze output for Claude-specific status indicators
|
|
30
|
+
*/
|
|
31
|
+
protected analyzeOutputForStatus(output: string): AISession['status'];
|
|
32
|
+
private generateSessionId;
|
|
33
|
+
private getOrCreateSessionId;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=claude-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-provider.d.ts","sourceRoot":"","sources":["../../src/providers/claude-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAEL,SAAS,EACT,cAAc,EACd,uBAAuB,EAEvB,gBAAgB,EAChB,UAAU,EACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAsC/C,qBAAa,cAAe,SAAQ,YAAY;IAC9C,QAAQ,CAAC,MAAM,iBAAiB;IAChC,OAAO,CAAC,QAAQ,CAAqC;gBAEzC,QAAQ,EAAE,MAAM;IAI5B;;OAEG;IACH,MAAM,IAAI,uBAAuB;IAqBjC;;OAEG;IACH,aAAa,CAAC,WAAW,SAAc,GAAG,SAAS,GAAG,IAAI;IAyC1D;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,gBAAgB;IAsErE;;OAEG;IACH,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,UAAU;IA0CtD;;OAEG;IACH,SAAS,CAAC,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC;IAmBrE,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,oBAAoB;CAuB7B"}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Claude Code Provider
|
|
4
|
+
*
|
|
5
|
+
* Provider implementation for Anthropic's Claude Code CLI
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.ClaudeProvider = void 0;
|
|
42
|
+
const child_process_1 = require("child_process");
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
const base_provider_1 = require("./base-provider");
|
|
45
|
+
/**
|
|
46
|
+
* Event mapping from Claude Code events to unified events
|
|
47
|
+
*/
|
|
48
|
+
const CLAUDE_EVENT_MAPPING = {
|
|
49
|
+
SessionStart: 'session_start',
|
|
50
|
+
SessionEnd: 'session_end',
|
|
51
|
+
UserPromptSubmit: 'before_prompt',
|
|
52
|
+
Stop: 'after_prompt',
|
|
53
|
+
PreToolUse: 'before_tool',
|
|
54
|
+
PostToolUse: 'after_tool',
|
|
55
|
+
Notification: 'notification',
|
|
56
|
+
SubagentStop: 'subagent_stop',
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Claude Code provider configuration
|
|
60
|
+
*/
|
|
61
|
+
const CLAUDE_CONFIG = {
|
|
62
|
+
provider: 'claude',
|
|
63
|
+
displayName: 'Claude Code',
|
|
64
|
+
cliCommand: 'claude',
|
|
65
|
+
settingsPath: '~/.claude/settings.json',
|
|
66
|
+
tmuxPrefix: 'claude-',
|
|
67
|
+
supportedEvents: [
|
|
68
|
+
'SessionStart',
|
|
69
|
+
'SessionEnd',
|
|
70
|
+
'UserPromptSubmit',
|
|
71
|
+
'Stop',
|
|
72
|
+
'PreToolUse',
|
|
73
|
+
'PostToolUse',
|
|
74
|
+
'Notification',
|
|
75
|
+
'SubagentStop',
|
|
76
|
+
],
|
|
77
|
+
eventMapping: CLAUDE_EVENT_MAPPING,
|
|
78
|
+
};
|
|
79
|
+
class ClaudeProvider extends base_provider_1.BaseProvider {
|
|
80
|
+
config = CLAUDE_CONFIG;
|
|
81
|
+
sessions = new Map();
|
|
82
|
+
constructor(genboxId) {
|
|
83
|
+
super(genboxId);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Detect if Claude Code CLI is installed
|
|
87
|
+
*/
|
|
88
|
+
detect() {
|
|
89
|
+
try {
|
|
90
|
+
const result = (0, child_process_1.execSync)('claude --version 2>/dev/null', {
|
|
91
|
+
encoding: 'utf-8',
|
|
92
|
+
timeout: 5000,
|
|
93
|
+
});
|
|
94
|
+
const versionMatch = result.match(/(\d+\.\d+\.\d+)/);
|
|
95
|
+
const version = versionMatch ? versionMatch[1] : undefined;
|
|
96
|
+
return {
|
|
97
|
+
detected: true,
|
|
98
|
+
provider: 'claude',
|
|
99
|
+
version,
|
|
100
|
+
configPath: this.config.settingsPath.replace('~', process.env.HOME || ''),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { detected: false };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create a new Claude Code session
|
|
109
|
+
*/
|
|
110
|
+
createSession(projectPath = '/home/dev') {
|
|
111
|
+
const sessionId = this.generateSessionId();
|
|
112
|
+
const sessionName = this.getSessionName(sessionId);
|
|
113
|
+
// Create detached tmux session
|
|
114
|
+
const result = this.runTmux([
|
|
115
|
+
'new-session',
|
|
116
|
+
'-d',
|
|
117
|
+
'-s', sessionName,
|
|
118
|
+
'-c', projectPath,
|
|
119
|
+
]);
|
|
120
|
+
if (!result.success) {
|
|
121
|
+
console.error(`Failed to create tmux session: ${result.stderr}`);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
// Wait for tmux to initialize
|
|
125
|
+
(0, child_process_1.execSync)('sleep 0.5');
|
|
126
|
+
// Start Claude Code
|
|
127
|
+
this.runTmux([
|
|
128
|
+
'send-keys',
|
|
129
|
+
'-t', sessionName,
|
|
130
|
+
'claude',
|
|
131
|
+
'Enter',
|
|
132
|
+
]);
|
|
133
|
+
const session = {
|
|
134
|
+
sessionId,
|
|
135
|
+
sessionName,
|
|
136
|
+
provider: 'claude',
|
|
137
|
+
projectPath,
|
|
138
|
+
createdAt: Date.now(),
|
|
139
|
+
status: 'starting',
|
|
140
|
+
};
|
|
141
|
+
this.sessions.set(sessionId, session);
|
|
142
|
+
return session;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Parse Claude Code hook input
|
|
146
|
+
*/
|
|
147
|
+
parseHookInput(eventType, rawInput) {
|
|
148
|
+
let hookData = {};
|
|
149
|
+
try {
|
|
150
|
+
if (rawInput.trim()) {
|
|
151
|
+
hookData = JSON.parse(rawInput);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
hookData = { raw_input: rawInput };
|
|
156
|
+
}
|
|
157
|
+
const sessionId = this.getOrCreateSessionId();
|
|
158
|
+
const baseEvent = this.createBaseHookEvent(eventType, sessionId);
|
|
159
|
+
const event = {
|
|
160
|
+
...baseEvent,
|
|
161
|
+
eventType: this.mapEventType(eventType),
|
|
162
|
+
provider: 'claude',
|
|
163
|
+
providerEventType: eventType,
|
|
164
|
+
sessionId,
|
|
165
|
+
genboxId: this.genboxId,
|
|
166
|
+
timestamp: new Date().toISOString(),
|
|
167
|
+
projectPath: process.cwd(),
|
|
168
|
+
rawData: hookData,
|
|
169
|
+
};
|
|
170
|
+
// Parse event-specific data
|
|
171
|
+
switch (eventType) {
|
|
172
|
+
case 'PreToolUse':
|
|
173
|
+
event.toolName = hookData.tool_name || '';
|
|
174
|
+
event.toolInput = hookData.tool_input || {};
|
|
175
|
+
break;
|
|
176
|
+
case 'PostToolUse':
|
|
177
|
+
event.toolName = hookData.tool_name || '';
|
|
178
|
+
event.toolInput = hookData.tool_input || {};
|
|
179
|
+
event.toolResponse = hookData.tool_response || {};
|
|
180
|
+
event.toolSuccess = hookData.tool_response?.success !== false;
|
|
181
|
+
break;
|
|
182
|
+
case 'UserPromptSubmit':
|
|
183
|
+
event.prompt = hookData.prompt || '';
|
|
184
|
+
event.promptLength = (hookData.prompt || '').length;
|
|
185
|
+
break;
|
|
186
|
+
case 'Stop':
|
|
187
|
+
event.stopReason = hookData.stop_reason || '';
|
|
188
|
+
break;
|
|
189
|
+
case 'SubagentStop':
|
|
190
|
+
event.subagentType = hookData.subagent_type || '';
|
|
191
|
+
event.stopReason = hookData.stop_reason || '';
|
|
192
|
+
break;
|
|
193
|
+
case 'Notification':
|
|
194
|
+
event.notification = hookData.message || '';
|
|
195
|
+
break;
|
|
196
|
+
case 'SessionStart':
|
|
197
|
+
event.cliVersion = hookData.cli_version || '';
|
|
198
|
+
break;
|
|
199
|
+
case 'SessionEnd':
|
|
200
|
+
event.sessionDuration = hookData.duration_ms || 0;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
return event;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Generate Claude Code hook configuration
|
|
207
|
+
*/
|
|
208
|
+
generateHookConfig(hookScriptPath) {
|
|
209
|
+
return {
|
|
210
|
+
provider: 'claude',
|
|
211
|
+
settingsJson: {
|
|
212
|
+
hooks: {
|
|
213
|
+
PreToolUse: [{
|
|
214
|
+
matcher: '.*',
|
|
215
|
+
hooks: [{
|
|
216
|
+
type: 'command',
|
|
217
|
+
command: `${hookScriptPath} claude PreToolUse`,
|
|
218
|
+
}],
|
|
219
|
+
}],
|
|
220
|
+
PostToolUse: [{
|
|
221
|
+
matcher: '.*',
|
|
222
|
+
hooks: [{
|
|
223
|
+
type: 'command',
|
|
224
|
+
command: `${hookScriptPath} claude PostToolUse`,
|
|
225
|
+
}],
|
|
226
|
+
}],
|
|
227
|
+
UserPromptSubmit: [{
|
|
228
|
+
hooks: [{
|
|
229
|
+
type: 'command',
|
|
230
|
+
command: `${hookScriptPath} claude UserPromptSubmit`,
|
|
231
|
+
}],
|
|
232
|
+
}],
|
|
233
|
+
Stop: [{
|
|
234
|
+
hooks: [{
|
|
235
|
+
type: 'command',
|
|
236
|
+
command: `${hookScriptPath} claude Stop`,
|
|
237
|
+
}],
|
|
238
|
+
}],
|
|
239
|
+
Notification: [{
|
|
240
|
+
hooks: [{
|
|
241
|
+
type: 'command',
|
|
242
|
+
command: `${hookScriptPath} claude Notification`,
|
|
243
|
+
}],
|
|
244
|
+
}],
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Analyze output for Claude-specific status indicators
|
|
251
|
+
*/
|
|
252
|
+
analyzeOutputForStatus(output) {
|
|
253
|
+
const lowerOutput = output.toLowerCase();
|
|
254
|
+
const lines = output.split('\n');
|
|
255
|
+
const lastNonEmptyLine = lines.filter(l => l.trim()).pop() || '';
|
|
256
|
+
// Claude-specific patterns
|
|
257
|
+
if (lastNonEmptyLine.includes('>') || lastNonEmptyLine.includes('Claude')) {
|
|
258
|
+
return 'waiting_input';
|
|
259
|
+
}
|
|
260
|
+
if (lowerOutput.includes('thinking') || lowerOutput.includes('analyzing')) {
|
|
261
|
+
return 'active';
|
|
262
|
+
}
|
|
263
|
+
if (lowerOutput.includes('error') || lowerOutput.includes('failed')) {
|
|
264
|
+
return 'error';
|
|
265
|
+
}
|
|
266
|
+
return 'idle';
|
|
267
|
+
}
|
|
268
|
+
generateSessionId() {
|
|
269
|
+
return crypto
|
|
270
|
+
.createHash('sha256')
|
|
271
|
+
.update(`${this.genboxId}-${Date.now()}-${process.pid}`)
|
|
272
|
+
.digest('hex')
|
|
273
|
+
.slice(0, 16);
|
|
274
|
+
}
|
|
275
|
+
getOrCreateSessionId() {
|
|
276
|
+
const fs = require('fs');
|
|
277
|
+
const path = require('path');
|
|
278
|
+
const sessionFile = path.join(process.env.HOME || '/tmp', '.claude-session-id');
|
|
279
|
+
try {
|
|
280
|
+
if (fs.existsSync(sessionFile)) {
|
|
281
|
+
return fs.readFileSync(sessionFile, 'utf-8').trim();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
// Ignore read errors
|
|
286
|
+
}
|
|
287
|
+
const sessionId = this.generateSessionId();
|
|
288
|
+
try {
|
|
289
|
+
fs.writeFileSync(sessionFile, sessionId);
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
// Ignore write errors
|
|
293
|
+
}
|
|
294
|
+
return sessionId;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.ClaudeProvider = ClaudeProvider;
|
|
298
|
+
//# sourceMappingURL=claude-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-provider.js","sourceRoot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I
|
|
5
|
+
*
|
|
6
|
+
* Note: As of late 2025, Codex CLI has limited hook support:
|
|
7
|
+
* - JSON event streaming via `--json` flag
|
|
8
|
+
* - `notify` config for agent-turn-complete event
|
|
9
|
+
* - Feature request for full hooks system is pending (Issue #2109)
|
|
10
|
+
*
|
|
11
|
+
* This provider is designed to work with current capabilities
|
|
12
|
+
* and will be extended when full hooks support is added.
|
|
13
|
+
*/
|
|
14
|
+
import { AISession, ProviderConfig, ProviderDetectionResult, UnifiedHookEvent, HookConfig } from '../types';
|
|
15
|
+
import { BaseProvider } from './base-provider';
|
|
16
|
+
export declare class CodexProvider extends BaseProvider {
|
|
17
|
+
readonly config: ProviderConfig;
|
|
18
|
+
private sessions;
|
|
19
|
+
private jsonStreamProcesses;
|
|
20
|
+
constructor(genboxId: string);
|
|
21
|
+
/**
|
|
22
|
+
* Detect if Codex CLI is installed
|
|
23
|
+
*/
|
|
24
|
+
detect(): ProviderDetectionResult;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new Codex CLI session
|
|
27
|
+
*
|
|
28
|
+
* For Codex, we can optionally run with --json to capture events
|
|
29
|
+
*/
|
|
30
|
+
createSession(projectPath?: string): AISession | null;
|
|
31
|
+
/**
|
|
32
|
+
* Create a session with JSON event streaming
|
|
33
|
+
* This is an alternative mode that captures all events but changes the UI
|
|
34
|
+
*/
|
|
35
|
+
createSessionWithJsonStream(projectPath: string | undefined, onEvent: (event: UnifiedHookEvent) => void): AISession | null;
|
|
36
|
+
/**
|
|
37
|
+
* Parse JSON stream event from Codex CLI
|
|
38
|
+
*/
|
|
39
|
+
private parseJsonStreamEvent;
|
|
40
|
+
/**
|
|
41
|
+
* Parse hook input from Codex CLI
|
|
42
|
+
*
|
|
43
|
+
* Currently Codex only supports notify for agent-turn-complete.
|
|
44
|
+
* This method is designed for future hooks support.
|
|
45
|
+
*/
|
|
46
|
+
parseHookInput(eventType: string, rawInput: string): UnifiedHookEvent;
|
|
47
|
+
/**
|
|
48
|
+
* Generate Codex CLI configuration
|
|
49
|
+
*
|
|
50
|
+
* Codex uses TOML for config (~/.codex/config.toml)
|
|
51
|
+
* Currently only supports notify for agent-turn-complete
|
|
52
|
+
*/
|
|
53
|
+
generateHookConfig(hookScriptPath: string): HookConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Generate TOML config string for Codex
|
|
56
|
+
*/
|
|
57
|
+
generateTomlConfig(hookScriptPath: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Analyze output for Codex-specific status indicators
|
|
60
|
+
*/
|
|
61
|
+
protected analyzeOutputForStatus(output: string): AISession['status'];
|
|
62
|
+
/**
|
|
63
|
+
* Send prompt to a JSON stream session
|
|
64
|
+
*/
|
|
65
|
+
sendPromptToJsonStream(sessionId: string, prompt: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Kill a session (including JSON stream sessions)
|
|
68
|
+
*/
|
|
69
|
+
killSession(sessionId: string): boolean;
|
|
70
|
+
private generateSessionId;
|
|
71
|
+
private getOrCreateSessionId;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=codex-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-provider.d.ts","sourceRoot":"","sources":["../../src/providers/codex-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAEL,SAAS,EACT,cAAc,EACd,uBAAuB,EAEvB,gBAAgB,EAChB,UAAU,EACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA4D/C,qBAAa,aAAc,SAAQ,YAAY;IAC7C,QAAQ,CAAC,MAAM,iBAAgB;IAC/B,OAAO,CAAC,QAAQ,CAAqC;IACrD,OAAO,CAAC,mBAAmB,CAAwC;gBAEvD,QAAQ,EAAE,MAAM;IAI5B;;OAEG;IACH,MAAM,IAAI,uBAAuB;IAqBjC;;;;OAIG;IACH,aAAa,CAAC,WAAW,SAAc,GAAG,SAAS,GAAG,I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