@trishchuk/codex-mcp-tool 1.2.0 → 1.4.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.
- package/README.md +84 -170
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +14 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/tools/ask-codex.tool.d.ts.map +1 -1
- package/dist/tools/ask-codex.tool.js +82 -54
- package/dist/tools/ask-codex.tool.js.map +1 -1
- package/dist/tools/batch-codex.tool.js +1 -1
- package/dist/tools/batch-codex.tool.js.map +1 -1
- package/dist/tools/health.tool.d.ts +3 -0
- package/dist/tools/health.tool.d.ts.map +1 -0
- package/dist/tools/health.tool.js +189 -0
- package/dist/tools/health.tool.js.map +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/list-sessions.tool.d.ts +3 -0
- package/dist/tools/list-sessions.tool.d.ts.map +1 -0
- package/dist/tools/list-sessions.tool.js +71 -0
- package/dist/tools/list-sessions.tool.js.map +1 -0
- package/dist/utils/codexCommandBuilder.d.ts +87 -0
- package/dist/utils/codexCommandBuilder.d.ts.map +1 -0
- package/dist/utils/codexCommandBuilder.js +285 -0
- package/dist/utils/codexCommandBuilder.js.map +1 -0
- package/dist/utils/codexExecutor.d.ts +12 -1
- package/dist/utils/codexExecutor.d.ts.map +1 -1
- package/dist/utils/codexExecutor.js +18 -181
- package/dist/utils/codexExecutor.js.map +1 -1
- package/dist/utils/commandExecutor.js +3 -3
- package/dist/utils/commandExecutor.js.map +1 -1
- package/dist/utils/errorTypes.d.ts +74 -0
- package/dist/utils/errorTypes.d.ts.map +1 -0
- package/dist/utils/errorTypes.js +268 -0
- package/dist/utils/errorTypes.js.map +1 -0
- package/dist/utils/modelDetection.d.ts +45 -0
- package/dist/utils/modelDetection.d.ts.map +1 -0
- package/dist/utils/modelDetection.js +148 -0
- package/dist/utils/modelDetection.js.map +1 -0
- package/dist/utils/sessionStorage.d.ts +79 -0
- package/dist/utils/sessionStorage.d.ts.map +1 -0
- package/dist/utils/sessionStorage.js +276 -0
- package/dist/utils/sessionStorage.js.map +1 -0
- package/dist/utils/versionDetection.d.ts +123 -0
- package/dist/utils/versionDetection.d.ts.map +1 -0
- package/dist/utils/versionDetection.js +188 -0
- package/dist/utils/versionDetection.js.map +1 -0
- package/dist/utils/workingDirResolver.d.ts +13 -8
- package/dist/utils/workingDirResolver.d.ts.map +1 -1
- package/dist/utils/workingDirResolver.js +44 -26
- package/dist/utils/workingDirResolver.js.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { CLI } from '../constants.js';
|
|
2
|
+
import { Logger } from './logger.js';
|
|
3
|
+
import { resolveWorkingDirectory } from './workingDirResolver.js';
|
|
4
|
+
import { getModelWithFallback } from './modelDetection.js';
|
|
5
|
+
import { supportsNativeSearch, supportsAddDir, supportsToolTokenLimit, supportsResume, } from './versionDetection.js';
|
|
6
|
+
import { writeFileSync, unlinkSync } from 'fs';
|
|
7
|
+
import { tmpdir } from 'os';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { randomBytes } from 'crypto';
|
|
10
|
+
/**
|
|
11
|
+
* Builder class for constructing Codex CLI commands
|
|
12
|
+
* Eliminates code duplication between executeCodexCLI and executeCodex
|
|
13
|
+
*/
|
|
14
|
+
export class CodexCommandBuilder {
|
|
15
|
+
args = [];
|
|
16
|
+
useResumeMode = false;
|
|
17
|
+
/**
|
|
18
|
+
* Build a complete Codex CLI command with all options
|
|
19
|
+
* @param prompt User prompt
|
|
20
|
+
* @param options Command options
|
|
21
|
+
* @returns Build result with args, temp file, and final prompt
|
|
22
|
+
*/
|
|
23
|
+
async build(prompt, options) {
|
|
24
|
+
this.args = []; // Reset args for fresh build
|
|
25
|
+
this.useResumeMode = false;
|
|
26
|
+
// 1. Validation
|
|
27
|
+
this.validateOptions(options);
|
|
28
|
+
// 2. Check if we should use resume mode
|
|
29
|
+
await this.checkResumeMode(options);
|
|
30
|
+
// 3. Model selection with fallback
|
|
31
|
+
await this.addModelArg(options?.model);
|
|
32
|
+
// 4. Safety controls (yolo, fullAuto, approval, sandbox)
|
|
33
|
+
this.addSafetyArgs(options);
|
|
34
|
+
// 5. Working directory
|
|
35
|
+
this.addWorkingDir(options, prompt);
|
|
36
|
+
// 6. OSS mode
|
|
37
|
+
if (options?.oss) {
|
|
38
|
+
this.args.push(CLI.FLAGS.OSS);
|
|
39
|
+
}
|
|
40
|
+
// 7. Search + Feature flags (shared 69-line logic)
|
|
41
|
+
await this.addSearchAndFeatures(options);
|
|
42
|
+
// 8. Disable features
|
|
43
|
+
if (options?.disableFeatures && Array.isArray(options.disableFeatures)) {
|
|
44
|
+
for (const feature of options.disableFeatures) {
|
|
45
|
+
this.args.push(CLI.FLAGS.DISABLE, feature);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// 9. Advanced features (addDirs + tokenLimit)
|
|
49
|
+
await this.addAdvancedFeatures(options);
|
|
50
|
+
// 10. Configuration
|
|
51
|
+
if (options?.config) {
|
|
52
|
+
if (typeof options.config === 'string') {
|
|
53
|
+
this.args.push(CLI.FLAGS.CONFIG, options.config);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const configStr = Object.entries(options.config)
|
|
57
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
58
|
+
.join(',');
|
|
59
|
+
this.args.push(CLI.FLAGS.CONFIG, configStr);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// 11. Profile
|
|
63
|
+
if (options?.profile) {
|
|
64
|
+
this.args.push(CLI.FLAGS.PROFILE, options.profile);
|
|
65
|
+
}
|
|
66
|
+
// 12. Images
|
|
67
|
+
if (options?.image) {
|
|
68
|
+
const images = Array.isArray(options.image) ? options.image : [options.image];
|
|
69
|
+
for (const img of images) {
|
|
70
|
+
this.args.push(CLI.FLAGS.IMAGE, img);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// 13. Command mode (exec or exec resume)
|
|
74
|
+
if (this.useResumeMode && options?.codexConversationId) {
|
|
75
|
+
// Use "exec resume <session_id>" for non-interactive resume
|
|
76
|
+
this.args.push('exec', CLI.FLAGS.RESUME, options.codexConversationId);
|
|
77
|
+
Logger.debug(`Using exec resume mode with conversation ID: ${options.codexConversationId}`);
|
|
78
|
+
}
|
|
79
|
+
else if (options?.useExec !== false) {
|
|
80
|
+
// Default to exec mode
|
|
81
|
+
this.args.push('exec');
|
|
82
|
+
}
|
|
83
|
+
// 14. Handle prompt (concise mode, stdin for large prompts)
|
|
84
|
+
return this.handlePrompt(prompt, options);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if resume mode should be used
|
|
88
|
+
*/
|
|
89
|
+
async checkResumeMode(options) {
|
|
90
|
+
if (options?.codexConversationId) {
|
|
91
|
+
const resumeSupported = await supportsResume();
|
|
92
|
+
if (resumeSupported) {
|
|
93
|
+
this.useResumeMode = true;
|
|
94
|
+
Logger.debug('Resume mode enabled (Codex CLI v0.36.0+)');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
Logger.warn('Resume mode requested but not supported (requires Codex CLI v0.36.0+). Falling back to exec mode.');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Validate options for conflicts
|
|
103
|
+
*/
|
|
104
|
+
validateOptions(options) {
|
|
105
|
+
if (options?.approvalPolicy && options?.yolo) {
|
|
106
|
+
throw new Error('Cannot use both yolo and approvalPolicy');
|
|
107
|
+
}
|
|
108
|
+
if (options?.sandboxMode && options?.yolo) {
|
|
109
|
+
throw new Error('Cannot use both yolo and sandboxMode');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Add model argument with fallback chain
|
|
114
|
+
*/
|
|
115
|
+
async addModelArg(model) {
|
|
116
|
+
const selectedModel = await getModelWithFallback(model);
|
|
117
|
+
this.args.push(CLI.FLAGS.MODEL, selectedModel);
|
|
118
|
+
if (model && model !== selectedModel) {
|
|
119
|
+
Logger.warn(`Requested model '${model}' not available, using fallback: '${selectedModel}'`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
Logger.debug(`Using model: ${selectedModel}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Add safety control arguments (yolo, fullAuto, approval, sandbox)
|
|
127
|
+
*/
|
|
128
|
+
addSafetyArgs(options) {
|
|
129
|
+
if (options?.yolo) {
|
|
130
|
+
this.args.push(CLI.FLAGS.YOLO);
|
|
131
|
+
}
|
|
132
|
+
else if (options?.fullAuto) {
|
|
133
|
+
this.args.push(CLI.FLAGS.FULL_AUTO);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
// Approval policy
|
|
137
|
+
if (options?.approvalPolicy) {
|
|
138
|
+
this.args.push(CLI.FLAGS.ASK_FOR_APPROVAL, options.approvalPolicy);
|
|
139
|
+
}
|
|
140
|
+
else if (options?.approval) {
|
|
141
|
+
this.args.push(CLI.FLAGS.APPROVAL, options.approval);
|
|
142
|
+
}
|
|
143
|
+
// Sandbox mode
|
|
144
|
+
if (options?.sandboxMode) {
|
|
145
|
+
this.args.push(CLI.FLAGS.SANDBOX_MODE, options.sandboxMode);
|
|
146
|
+
}
|
|
147
|
+
else if (options?.search || options?.oss) {
|
|
148
|
+
// Auto-enable workspace-write for search/oss if no sandbox specified
|
|
149
|
+
Logger.debug('Search/OSS enabled: auto-setting sandbox to workspace-write for network access');
|
|
150
|
+
this.args.push(CLI.FLAGS.SANDBOX_MODE, 'workspace-write');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Add working directory argument
|
|
156
|
+
*/
|
|
157
|
+
addWorkingDir(options, prompt) {
|
|
158
|
+
const resolvedWorkingDir = resolveWorkingDirectory({
|
|
159
|
+
workingDir: options?.workingDir || options?.cd,
|
|
160
|
+
prompt: prompt,
|
|
161
|
+
});
|
|
162
|
+
if (resolvedWorkingDir) {
|
|
163
|
+
// Use appropriate flag based on mode
|
|
164
|
+
const flag = options?.cd !== undefined ? CLI.FLAGS.CD : CLI.FLAGS.WORKING_DIR;
|
|
165
|
+
this.args.push(flag, resolvedWorkingDir);
|
|
166
|
+
Logger.debug(`Resolved working directory: ${resolvedWorkingDir}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Add search and feature flags (shared 69-line logic from both functions)
|
|
171
|
+
*/
|
|
172
|
+
async addSearchAndFeatures(options) {
|
|
173
|
+
// Web Search - Dual-flag approach for backward compatibility (v1.3.0+)
|
|
174
|
+
if (options?.search) {
|
|
175
|
+
// Check if native --search flag is supported (Codex CLI v0.52.0+)
|
|
176
|
+
const hasNativeSearch = await supportsNativeSearch();
|
|
177
|
+
if (hasNativeSearch) {
|
|
178
|
+
// Use native --search flag for newer versions
|
|
179
|
+
this.args.push(CLI.FLAGS.SEARCH);
|
|
180
|
+
Logger.debug('Using native --search flag (Codex CLI v0.52.0+)');
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
Logger.debug('Native --search flag not supported, falling back to web_search_request feature flag');
|
|
184
|
+
}
|
|
185
|
+
// Always add feature flag for backward compatibility
|
|
186
|
+
const enableFeatures = [...(options?.enableFeatures || [])];
|
|
187
|
+
if (!enableFeatures.includes('web_search_request')) {
|
|
188
|
+
enableFeatures.push('web_search_request');
|
|
189
|
+
}
|
|
190
|
+
// Add all features to args
|
|
191
|
+
for (const feature of enableFeatures) {
|
|
192
|
+
this.args.push(CLI.FLAGS.ENABLE, feature);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
// Normal feature flag handling when search is not enabled
|
|
197
|
+
const enableFeatures = [...(options?.enableFeatures || [])];
|
|
198
|
+
for (const feature of enableFeatures) {
|
|
199
|
+
this.args.push(CLI.FLAGS.ENABLE, feature);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Add advanced features (addDirs, toolOutputTokenLimit)
|
|
205
|
+
*/
|
|
206
|
+
async addAdvancedFeatures(options) {
|
|
207
|
+
// Additional writable directories (v1.3.0+, requires Codex CLI v0.59.0+)
|
|
208
|
+
if (options?.addDirs && Array.isArray(options.addDirs)) {
|
|
209
|
+
const hasAddDir = await supportsAddDir();
|
|
210
|
+
if (hasAddDir) {
|
|
211
|
+
for (const dir of options.addDirs) {
|
|
212
|
+
this.args.push(CLI.FLAGS.ADD_DIR, dir);
|
|
213
|
+
}
|
|
214
|
+
Logger.debug('Using --add-dir flag (Codex CLI v0.59.0+)');
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
Logger.warn('Additional directories specified but --add-dir flag not supported (requires Codex CLI v0.59.0+). Ignoring addDirs parameter.');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Tool output token limit (v1.3.0+, requires Codex CLI v0.59.0+)
|
|
221
|
+
if (options?.toolOutputTokenLimit) {
|
|
222
|
+
const hasTokenLimit = await supportsToolTokenLimit();
|
|
223
|
+
if (hasTokenLimit) {
|
|
224
|
+
this.args.push(CLI.FLAGS.CONFIG, `tool_output_token_limit=${options.toolOutputTokenLimit}`);
|
|
225
|
+
Logger.debug('Using tool_output_token_limit config (Codex CLI v0.59.0+)');
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
Logger.warn('Tool output token limit specified but not supported (requires Codex CLI v0.59.0+). Ignoring toolOutputTokenLimit parameter.');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Handle prompt with concise mode and stdin for large prompts
|
|
234
|
+
*/
|
|
235
|
+
handlePrompt(prompt, options) {
|
|
236
|
+
let finalPrompt = prompt;
|
|
237
|
+
let tempFile;
|
|
238
|
+
// Add conciseness instruction if requested
|
|
239
|
+
if (options?.concisePrompt) {
|
|
240
|
+
finalPrompt = `Please provide a focused, concise response without unnecessary elaboration. ${prompt}`;
|
|
241
|
+
}
|
|
242
|
+
// Check if prompt is too long for command line (OS dependent, ~100KB is safe)
|
|
243
|
+
const MAX_COMMAND_LINE_LENGTH = 100000;
|
|
244
|
+
const useStdin = options?.useStdinForLongPrompts !== false && finalPrompt.length > MAX_COMMAND_LINE_LENGTH;
|
|
245
|
+
if (useStdin) {
|
|
246
|
+
// Create temporary file for large prompts
|
|
247
|
+
const tempFileName = `codex-prompt-${randomBytes(8).toString('hex')}.txt`;
|
|
248
|
+
const tempFilePath = join(tmpdir(), tempFileName);
|
|
249
|
+
try {
|
|
250
|
+
writeFileSync(tempFilePath, finalPrompt, 'utf8');
|
|
251
|
+
Logger.debug(`Prompt too long (${finalPrompt.length} chars), using temp file: ${tempFilePath}`);
|
|
252
|
+
// Use stdin redirection via special prompt format
|
|
253
|
+
this.args.push(`@${tempFilePath}`);
|
|
254
|
+
tempFile = tempFilePath;
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
Logger.warn(`Failed to create temp file for large prompt: ${error}. Proceeding with direct prompt.`);
|
|
258
|
+
this.args.push(finalPrompt);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
// Normal prompt handling
|
|
263
|
+
this.args.push(finalPrompt);
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
args: this.args,
|
|
267
|
+
tempFile,
|
|
268
|
+
finalPrompt,
|
|
269
|
+
useResume: this.useResumeMode,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Cleanup temporary file if created
|
|
274
|
+
*/
|
|
275
|
+
static cleanupTempFile(tempFile) {
|
|
276
|
+
try {
|
|
277
|
+
unlinkSync(tempFile);
|
|
278
|
+
Logger.debug(`Cleaned up temp file: ${tempFile}`);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
Logger.warn(`Failed to cleanup temp file ${tempFile}:`, error);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=codexCommandBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexCommandBuilder.js","sourceRoot":"","sources":["../../src/utils/codexCommandBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAwCrC;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IACtB,IAAI,GAAa,EAAE,CAAC;IACpB,aAAa,GAAY,KAAK,CAAC;IAEvC;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAC,MAAc,EAAE,OAAoC;QAC9D,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,6BAA6B;QAC7C,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAE3B,gBAAgB;QAChB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAE9B,wCAAwC;QACxC,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAEpC,mCAAmC;QACnC,MAAM,IAAI,CAAC,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,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ;YACR,WAAW;YACX,SAAS,EAAE,IAAI,CAAC,aAAa;SAC9B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,QAAgB;QACrC,IAAI,CAAC;YACH,UAAU,CAAC,QAAQ,CAAC,CAAC;YACrB,MAAM,CAAC,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,+BAA+B,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { RetryOptions } from './commandExecutor.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extended result from Codex execution with stderr for conversation ID parsing
|
|
4
|
+
*/
|
|
5
|
+
export interface CodexExecutionResult {
|
|
6
|
+
output: string;
|
|
7
|
+
stderr: string;
|
|
8
|
+
}
|
|
2
9
|
export declare enum ApprovalPolicy {
|
|
3
10
|
Never = "never",
|
|
4
11
|
OnRequest = "on-request",
|
|
@@ -32,6 +39,9 @@ export interface CodexExecOptions {
|
|
|
32
39
|
readonly oss?: boolean;
|
|
33
40
|
readonly enableFeatures?: string[];
|
|
34
41
|
readonly disableFeatures?: string[];
|
|
42
|
+
readonly addDirs?: string[];
|
|
43
|
+
readonly toolOutputTokenLimit?: number;
|
|
44
|
+
readonly codexConversationId?: string;
|
|
35
45
|
}
|
|
36
46
|
/**
|
|
37
47
|
* Execute Codex CLI with enhanced error handling and memory efficiency
|
|
@@ -39,8 +49,9 @@ export interface CodexExecOptions {
|
|
|
39
49
|
export declare function executeCodexCLI(prompt: string, options?: CodexExecOptions, onProgress?: (newOutput: string) => void): Promise<string>;
|
|
40
50
|
/**
|
|
41
51
|
* High-level executeCodex function with comprehensive options support
|
|
52
|
+
* Returns both stdout and stderr for conversation ID parsing
|
|
42
53
|
*/
|
|
43
54
|
export declare function executeCodex(prompt: string, options?: CodexExecOptions & {
|
|
44
55
|
[key: string]: any;
|
|
45
|
-
}, onProgress?: (newOutput: string) => void): Promise<
|
|
56
|
+
}, onProgress?: (newOutput: string) => void): Promise<CodexExecutionResult>;
|
|
46
57
|
//# sourceMappingURL=codexExecutor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codexExecutor.d.ts","sourceRoot":"","sources":["../../src/utils/codexExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"codexExecutor.d.ts","sourceRoot":"","sources":["../../src/utils/codexExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAM5E;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,cAAc;IACxB,KAAK,UAAU;IACf,SAAS,eAAe;IACxB,SAAS,eAAe;IACxB,SAAS,cAAc;CACxB;AAED,oBAAY,WAAW;IACrB,QAAQ,cAAc;IACtB,cAAc,oBAAoB;IAClC,gBAAgB,uBAAuB;CACxC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EA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AAE,MAAM,KAAK,IAAI,GACvC,OAAO,CAAC,oBAAoB,CAAC,CAoD/B"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { executeCommandDetailed } from './commandExecutor.js';
|
|
2
2
|
import { Logger } from './logger.js';
|
|
3
3
|
import { CLI } from '../constants.js';
|
|
4
|
-
import {
|
|
5
|
-
import { tmpdir } from 'os';
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
import { randomBytes } from 'crypto';
|
|
8
|
-
import { resolveWorkingDirectory } from './workingDirResolver.js';
|
|
9
|
-
// Type-safe enums
|
|
4
|
+
import { CodexCommandBuilder } from './codexCommandBuilder.js';
|
|
10
5
|
export var ApprovalPolicy;
|
|
11
6
|
(function (ApprovalPolicy) {
|
|
12
7
|
ApprovalPolicy["Never"] = "never";
|
|
@@ -24,87 +19,13 @@ export var SandboxMode;
|
|
|
24
19
|
* Execute Codex CLI with enhanced error handling and memory efficiency
|
|
25
20
|
*/
|
|
26
21
|
export async function executeCodexCLI(prompt, options, onProgress) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (options?.sandboxMode && options?.yolo) {
|
|
33
|
-
throw new Error('Cannot use both yolo and sandboxMode');
|
|
34
|
-
}
|
|
35
|
-
// Build command arguments
|
|
36
|
-
if (options?.yolo) {
|
|
37
|
-
args.push(CLI.FLAGS.YOLO);
|
|
38
|
-
}
|
|
39
|
-
else if (options?.fullAuto) {
|
|
40
|
-
args.push(CLI.FLAGS.FULL_AUTO);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
if (options?.approvalPolicy) {
|
|
44
|
-
args.push(CLI.FLAGS.ASK_FOR_APPROVAL, options.approvalPolicy);
|
|
45
|
-
}
|
|
46
|
-
// Note: --search requires network access, so if search is enabled and no explicit sandbox mode
|
|
47
|
-
// is set, we need to ensure network is not blocked
|
|
48
|
-
if (options?.sandboxMode) {
|
|
49
|
-
args.push(CLI.FLAGS.SANDBOX_MODE, options.sandboxMode);
|
|
50
|
-
}
|
|
51
|
-
else if (options?.search || options?.oss) {
|
|
52
|
-
// Auto-enable workspace-write for search/oss if no sandbox specified
|
|
53
|
-
Logger.debug('Search/OSS enabled: auto-setting sandbox to workspace-write for network access');
|
|
54
|
-
args.push(CLI.FLAGS.SANDBOX_MODE, 'workspace-write');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (options?.model) {
|
|
58
|
-
args.push(CLI.FLAGS.MODEL, options.model);
|
|
59
|
-
}
|
|
60
|
-
// Resolve working directory using intelligent fallback chain
|
|
61
|
-
const resolvedWorkingDir = resolveWorkingDirectory({
|
|
62
|
-
workingDir: options?.cd,
|
|
63
|
-
prompt: prompt,
|
|
22
|
+
const builder = new CodexCommandBuilder();
|
|
23
|
+
const { args, tempFile } = await builder.build(prompt, {
|
|
24
|
+
...options,
|
|
25
|
+
concisePrompt: true,
|
|
26
|
+
useStdinForLongPrompts: options?.useStdinForLongPrompts !== false,
|
|
64
27
|
});
|
|
65
|
-
if (resolvedWorkingDir) {
|
|
66
|
-
args.push(CLI.FLAGS.CD, resolvedWorkingDir);
|
|
67
|
-
Logger.debug(`Resolved working directory: ${resolvedWorkingDir}`);
|
|
68
|
-
}
|
|
69
|
-
// OSS (Ollama) mode
|
|
70
|
-
if (options?.oss) {
|
|
71
|
-
args.push(CLI.FLAGS.OSS);
|
|
72
|
-
}
|
|
73
|
-
// Enable features (including web search)
|
|
74
|
-
const enableFeatures = [...(options?.enableFeatures || [])];
|
|
75
|
-
// Add web_search_request feature if search is requested
|
|
76
|
-
if (options?.search && !enableFeatures.includes('web_search_request')) {
|
|
77
|
-
enableFeatures.push('web_search_request');
|
|
78
|
-
}
|
|
79
|
-
// Add all features to args
|
|
80
|
-
for (const feature of enableFeatures) {
|
|
81
|
-
args.push(CLI.FLAGS.ENABLE, feature);
|
|
82
|
-
}
|
|
83
|
-
// Disable features
|
|
84
|
-
if (options?.disableFeatures && Array.isArray(options.disableFeatures)) {
|
|
85
|
-
for (const feature of options.disableFeatures) {
|
|
86
|
-
args.push(CLI.FLAGS.DISABLE, feature);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// Non-interactive run
|
|
90
|
-
args.push('exec');
|
|
91
|
-
// Add conciseness instruction
|
|
92
|
-
const concisePrompt = `Please provide a focused, concise response without unnecessary elaboration. ${prompt}`;
|
|
93
|
-
// Check if prompt is too long for command line (OS dependent, ~100KB is safe)
|
|
94
|
-
const promptSizeBytes = Buffer.byteLength(concisePrompt, 'utf8');
|
|
95
|
-
const useStdin = options?.useStdinForLongPrompts !== false && promptSizeBytes > 100 * 1024;
|
|
96
|
-
let tempFile;
|
|
97
28
|
try {
|
|
98
|
-
if (useStdin) {
|
|
99
|
-
// Write prompt to temp file and pass via stdin redirect
|
|
100
|
-
tempFile = join(tmpdir(), `codex-prompt-${randomBytes(8).toString('hex')}.txt`);
|
|
101
|
-
writeFileSync(tempFile, concisePrompt, 'utf8');
|
|
102
|
-
args.push(`< ${tempFile}`);
|
|
103
|
-
Logger.debug(`Using temp file for large prompt (${promptSizeBytes} bytes)`);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
args.push(concisePrompt);
|
|
107
|
-
}
|
|
108
29
|
// Use detailed execution for better error handling
|
|
109
30
|
const result = await executeCommandDetailed(CLI.COMMANDS.CODEX, args, {
|
|
110
31
|
onProgress,
|
|
@@ -132,109 +53,21 @@ export async function executeCodexCLI(prompt, options, onProgress) {
|
|
|
132
53
|
finally {
|
|
133
54
|
// Clean up temp file
|
|
134
55
|
if (tempFile) {
|
|
135
|
-
|
|
136
|
-
unlinkSync(tempFile);
|
|
137
|
-
}
|
|
138
|
-
catch (e) {
|
|
139
|
-
Logger.debug('Failed to delete temp file:', e);
|
|
140
|
-
}
|
|
56
|
+
CodexCommandBuilder.cleanupTempFile(tempFile);
|
|
141
57
|
}
|
|
142
58
|
}
|
|
143
59
|
}
|
|
144
60
|
/**
|
|
145
61
|
* High-level executeCodex function with comprehensive options support
|
|
62
|
+
* Returns both stdout and stderr for conversation ID parsing
|
|
146
63
|
*/
|
|
147
64
|
export async function executeCodex(prompt, options, onProgress) {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
// Safety controls
|
|
154
|
-
if (options?.yolo) {
|
|
155
|
-
args.push(CLI.FLAGS.YOLO);
|
|
156
|
-
}
|
|
157
|
-
else if (options?.fullAuto) {
|
|
158
|
-
args.push(CLI.FLAGS.FULL_AUTO);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
// Approval policy
|
|
162
|
-
if (options?.approval || options?.approvalPolicy) {
|
|
163
|
-
const approvalValue = options.approval || options.approvalPolicy;
|
|
164
|
-
if (approvalValue) {
|
|
165
|
-
args.push(CLI.FLAGS.APPROVAL, approvalValue);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
// Sandbox mode
|
|
169
|
-
if (options?.sandboxMode) {
|
|
170
|
-
args.push(CLI.FLAGS.SANDBOX_MODE, options.sandboxMode);
|
|
171
|
-
}
|
|
172
|
-
else if (options?.search || options?.oss) {
|
|
173
|
-
// Auto-enable workspace-write for search/oss if no sandbox specified
|
|
174
|
-
Logger.debug('Search/OSS enabled: auto-setting sandbox to workspace-write for network access');
|
|
175
|
-
args.push(CLI.FLAGS.SANDBOX_MODE, 'workspace-write');
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
// Resolve working directory using intelligent fallback chain
|
|
179
|
-
const resolvedWorkingDir = resolveWorkingDirectory({
|
|
180
|
-
workingDir: options?.workingDir || options?.cd,
|
|
181
|
-
prompt: prompt,
|
|
65
|
+
const builder = new CodexCommandBuilder();
|
|
66
|
+
const { args } = await builder.build(prompt, {
|
|
67
|
+
...options,
|
|
68
|
+
concisePrompt: false,
|
|
69
|
+
useStdinForLongPrompts: false,
|
|
182
70
|
});
|
|
183
|
-
if (resolvedWorkingDir) {
|
|
184
|
-
args.push(CLI.FLAGS.WORKING_DIR, resolvedWorkingDir);
|
|
185
|
-
Logger.debug(`Resolved working directory for executeCodex: ${resolvedWorkingDir}`);
|
|
186
|
-
}
|
|
187
|
-
// Configuration
|
|
188
|
-
if (options?.config) {
|
|
189
|
-
if (typeof options.config === 'string') {
|
|
190
|
-
args.push(CLI.FLAGS.CONFIG, options.config);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
// Convert object to key=value pairs
|
|
194
|
-
const configStr = Object.entries(options.config)
|
|
195
|
-
.map(([k, v]) => `${k}=${v}`)
|
|
196
|
-
.join(',');
|
|
197
|
-
args.push(CLI.FLAGS.CONFIG, configStr);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
// Profile
|
|
201
|
-
if (options?.profile) {
|
|
202
|
-
args.push(CLI.FLAGS.PROFILE, options.profile);
|
|
203
|
-
}
|
|
204
|
-
// Images
|
|
205
|
-
if (options?.image) {
|
|
206
|
-
const images = Array.isArray(options.image) ? options.image : [options.image];
|
|
207
|
-
for (const img of images) {
|
|
208
|
-
args.push(CLI.FLAGS.IMAGE, img);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
// OSS (Ollama) mode
|
|
212
|
-
if (options?.oss) {
|
|
213
|
-
args.push(CLI.FLAGS.OSS);
|
|
214
|
-
}
|
|
215
|
-
// Enable features (including web search)
|
|
216
|
-
const enableFeatures = [...(options?.enableFeatures || [])];
|
|
217
|
-
// Add web_search_request feature if search is requested
|
|
218
|
-
if (options?.search && !enableFeatures.includes('web_search_request')) {
|
|
219
|
-
enableFeatures.push('web_search_request');
|
|
220
|
-
}
|
|
221
|
-
// Add all features to args
|
|
222
|
-
for (const feature of enableFeatures) {
|
|
223
|
-
args.push(CLI.FLAGS.ENABLE, feature);
|
|
224
|
-
}
|
|
225
|
-
// Disable features
|
|
226
|
-
if (options?.disableFeatures && Array.isArray(options.disableFeatures)) {
|
|
227
|
-
for (const feature of options.disableFeatures) {
|
|
228
|
-
args.push(CLI.FLAGS.DISABLE, feature);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// Use exec mode for non-interactive execution
|
|
232
|
-
if (options?.useExec !== false) {
|
|
233
|
-
// Default to true for non-interactive execution
|
|
234
|
-
args.push('exec');
|
|
235
|
-
}
|
|
236
|
-
// Add the prompt
|
|
237
|
-
args.push(prompt);
|
|
238
71
|
try {
|
|
239
72
|
const timeoutMs = options?.timeout || options?.timeoutMs || 600000; // 10 minutes default
|
|
240
73
|
const result = await executeCommandDetailed(CLI.COMMANDS.CODEX, args, {
|
|
@@ -260,7 +93,11 @@ export async function executeCodex(prompt, options, onProgress) {
|
|
|
260
93
|
}
|
|
261
94
|
throw new Error(`Codex CLI failed: ${errorMessage}`);
|
|
262
95
|
}
|
|
263
|
-
|
|
96
|
+
// Return both stdout and stderr for conversation ID parsing
|
|
97
|
+
return {
|
|
98
|
+
output: result.stdout,
|
|
99
|
+
stderr: result.stderr,
|
|
100
|
+
};
|
|
264
101
|
}
|
|
265
102
|
catch (error) {
|
|
266
103
|
Logger.error('Codex execution failed:', error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codexExecutor.js","sourceRoot":"","sources":["../../src/utils/codexExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"codexExecutor.js","sourceRoot":"","sources":["../../src/utils/codexExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAgB,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAW/D,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,0CAAwB,CAAA;IACxB,0CAAwB,CAAA;IACxB,yCAAuB,CAAA;AACzB,CAAC,EALW,cAAc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ACrF,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;YACrF,CAAC;YAED,IAAI,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;gBACrF,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;YACpF,CAAC;YAED,IAAI,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC1E,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;YACpE,CAAC;YAED,IAAI,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5E,MAAM,IAAI,KAAK,CACb,qEAAqE,YAAY,EAAE,CACpF,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,YAAY,EAAE,CAAC,CAAC;QACvD,CAAC;QAED,4DAA4D;QAC5D,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAC/C,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import spawn from 'cross-spawn';
|
|
2
2
|
import { Logger } from './logger.js';
|
|
3
3
|
/**
|
|
4
4
|
* Execute a command with streaming output and structured error handling
|
|
@@ -61,7 +61,7 @@ async function executeOnce(command, args, { onProgress, timeoutMs, maxOutputByte
|
|
|
61
61
|
}, 5000);
|
|
62
62
|
}
|
|
63
63
|
}, timeoutMs || 600000);
|
|
64
|
-
childProcess.stdout
|
|
64
|
+
childProcess.stdout?.on('data', (data) => {
|
|
65
65
|
// Check output size limit
|
|
66
66
|
if (maxOutputBytes && totalStdoutBytes + data.length > maxOutputBytes) {
|
|
67
67
|
if (!outputExceeded) {
|
|
@@ -79,7 +79,7 @@ async function executeOnce(command, args, { onProgress, timeoutMs, maxOutputByte
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
// Capture stderr for error reporting
|
|
82
|
-
childProcess.stderr
|
|
82
|
+
childProcess.stderr?.on('data', (data) => {
|
|
83
83
|
stderrChunks.push(data);
|
|
84
84
|
});
|
|
85
85
|
childProcess.on('error', error => {
|