MCPcopy
hub / github.com/openai/codex-plugin-cc / runAppServerTurn

Function runAppServerTurn

plugins/codex/scripts/lib/codex.mjs:1095–1160  ·  view source on GitHub ↗
(cwd, options = {})

Source from the content-addressed store, hash-verified

1093}
1094
1095export async function runAppServerTurn(cwd, options = {}) {
1096 const availability = getCodexAvailability(cwd);
1097 if (!availability.available) {
1098 throw new Error("Codex CLI is not installed or is missing required runtime support. Install it with `npm install -g @openai/codex`, then rerun `/codex:setup`.");
1099 }
1100
1101 return withAppServer(cwd, async (client) => {
1102 let threadId;
1103
1104 if (options.resumeThreadId) {
1105 emitProgress(options.onProgress, `Resuming thread ${options.resumeThreadId}.`, "starting");
1106 const response = await resumeThread(client, options.resumeThreadId, cwd, {
1107 model: options.model,
1108 sandbox: options.sandbox,
1109 ephemeral: false
1110 });
1111 threadId = response.thread.id;
1112 } else {
1113 emitProgress(options.onProgress, "Starting Codex task thread.", "starting");
1114 const response = await startThread(client, cwd, {
1115 model: options.model,
1116 sandbox: options.sandbox,
1117 ephemeral: options.persistThread ? false : true,
1118 threadName: options.persistThread ? options.threadName : options.threadName ?? null
1119 });
1120 threadId = response.thread.id;
1121 }
1122
1123 emitProgress(options.onProgress, `Thread ready (${threadId}).`, "starting", {
1124 threadId
1125 });
1126
1127 const prompt = options.prompt?.trim() || options.defaultPrompt || "";
1128 if (!prompt) {
1129 throw new Error("A prompt is required for this Codex run.");
1130 }
1131
1132 const turnState = await captureTurn(
1133 client,
1134 threadId,
1135 () =>
1136 client.request("turn/start", {
1137 threadId,
1138 input: buildTurnInput(prompt),
1139 model: options.model ?? null,
1140 effort: options.effort ?? null,
1141 outputSchema: options.outputSchema ?? null
1142 }),
1143 { onProgress: options.onProgress }
1144 );
1145
1146 return {
1147 status: buildResultStatus(turnState),
1148 threadId,
1149 turnId: turnState.turnId,
1150 finalMessage: turnState.lastAgentMessage,
1151 reasoningSummary: turnState.reasoningSummary,
1152 turn: turnState.finalTurn,

Callers 2

executeReviewRunFunction · 0.90
executeTaskRunFunction · 0.90

Calls 11

getCodexAvailabilityFunction · 0.85
withAppServerFunction · 0.85
emitProgressFunction · 0.85
resumeThreadFunction · 0.85
startThreadFunction · 0.85
captureTurnFunction · 0.85
buildTurnInputFunction · 0.85
buildResultStatusFunction · 0.85
cleanCodexStderrFunction · 0.85
collectTouchedFilesFunction · 0.85
requestMethod · 0.80

Tested by

no test coverage detected