MCPcopy Create free account
hub / github.com/github/gh-aw / resolveCodexPromptFileArgs

Function resolveCodexPromptFileArgs

actions/setup/js/codex_harness.cjs:180–219  ·  view source on GitHub ↗

* Resolve --prompt-file arguments for the Codex run. * Strips the --prompt-file pair from args and appends the file content * as the last positional argument, which is where `codex exec` expects the prompt. * * @param {string[]} args * @returns {string[]} Args with --prompt-file resolved

(args)

Source from the content-addressed store, hash-verified

178 * @returns {string[]} Args with --prompt-file resolved to inline prompt content
179 */
180function resolveCodexPromptFileArgs(args) {
181 /** @type {string[]} */
182 const filteredArgs = [];
183 /** @type {string|null} */
184 let promptContent = null;
185
186 for (let i = 0; i < args.length; i++) {
187 if (args[i] !== "--prompt-file") {
188 filteredArgs.push(args[i]);
189 continue;
190 }
191
192 if (i + 1 >= args.length) {
193 log("warning: --prompt-file provided without a path; leaving arguments unchanged");
194 filteredArgs.push(args[i]);
195 continue;
196 }
197
198 const promptFile = args[i + 1];
199 try {
200 const stat = fs.statSync(promptFile);
201 log(`resolved --prompt-file: path=${promptFile} size=${stat.size}B`);
202 promptContent = fs.readFileSync(promptFile, "utf8");
203 } catch (error) {
204 const err = /** @type {Error} */ error;
205 // An unreadable prompt file means no task instructions can be delivered to Codex.
206 // Propagate as a fatal error rather than forwarding the harness-only flag to the
207 // codex subprocess (which would fail with an "unknown option" error).
208 throw new Error(`--prompt-file '${promptFile}' is not readable: ${err.message}`);
209 }
210 i++; // Skip the prompt-file path argument
211 }
212
213 // Append the prompt content as the last positional argument (codex exec convention).
214 if (promptContent !== null) {
215 filteredArgs.push(promptContent);
216 }
217
218 return filteredArgs;
219}
220
221/**
222 * Inject `--json` after `exec` in the args list so that Codex streams structured

Callers 2

mainFunction · 0.85

Calls 1

logFunction · 0.70

Tested by

no test coverage detected