feat: execute omx dispatches via local-agent
This commit is contained in:
@@ -7,6 +7,11 @@ import os from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { discoverCodexProjectCandidatesInWorker } from "./codex-session-discovery.mjs";
|
||||
import { buildCodexTaskExecution } from "./codex-task-runner.mjs";
|
||||
import {
|
||||
executeOmxTeamTask,
|
||||
getOmxTeamTaskRunnerConfig,
|
||||
shouldUseOmxTeamTaskRunner,
|
||||
} from "./omx-team-task-runner.mjs";
|
||||
import { createSerializedRunner } from "./serialized-runner.mjs";
|
||||
|
||||
async function loadConfig(configPath) {
|
||||
@@ -364,32 +369,48 @@ async function runMasterAgentTask(config, runtime, task) {
|
||||
};
|
||||
|
||||
try {
|
||||
const codexExecution = buildCodexTaskExecution(config, task, outputFile);
|
||||
await new Promise((resolveTask, rejectTask) => {
|
||||
const child = spawn("codex", codexExecution.args, {
|
||||
cwd: codexExecution.cwd,
|
||||
env: process.env,
|
||||
let replyBody;
|
||||
let dispatchExecutionCompletion = null;
|
||||
|
||||
if (shouldUseOmxTeamTaskRunner(task)) {
|
||||
const omxResult = await executeOmxTeamTask(getOmxTeamTaskRunnerConfig(process.env, config), task);
|
||||
if (omxResult.status === "failed") {
|
||||
throw new Error(omxResult.errorMessage || "OMX_EXECUTION_FAILED");
|
||||
}
|
||||
replyBody = omxResult.replyBody ?? omxResult.rawThreadReply;
|
||||
dispatchExecutionCompletion = {
|
||||
rawThreadReply: omxResult.rawThreadReply,
|
||||
replyBody: omxResult.replyBody,
|
||||
};
|
||||
} else {
|
||||
const codexExecution = buildCodexTaskExecution(config, task, outputFile);
|
||||
await new Promise((resolveTask, rejectTask) => {
|
||||
const child = spawn("codex", codexExecution.args, {
|
||||
cwd: codexExecution.cwd,
|
||||
env: process.env,
|
||||
});
|
||||
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderrChunks.push(String(chunk));
|
||||
});
|
||||
|
||||
child.on("error", rejectTask);
|
||||
child.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
resolveTask();
|
||||
return;
|
||||
}
|
||||
rejectTask(new Error(stderrChunks.join("").trim() || `codex exit code ${code}`));
|
||||
});
|
||||
});
|
||||
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderrChunks.push(String(chunk));
|
||||
});
|
||||
replyBody = (await readFile(outputFile, "utf8")).trim();
|
||||
dispatchExecutionCompletion =
|
||||
task.taskType === "dispatch_execution"
|
||||
? parseDispatchExecutionCompletion(replyBody)
|
||||
: null;
|
||||
}
|
||||
|
||||
child.on("error", rejectTask);
|
||||
child.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
resolveTask();
|
||||
return;
|
||||
}
|
||||
rejectTask(new Error(stderrChunks.join("").trim() || `codex exit code ${code}`));
|
||||
});
|
||||
});
|
||||
|
||||
const replyBody = (await readFile(outputFile, "utf8")).trim();
|
||||
const dispatchExecutionCompletion =
|
||||
task.taskType === "dispatch_execution"
|
||||
? parseDispatchExecutionCompletion(replyBody)
|
||||
: null;
|
||||
const completion = await completeMasterAgentTask(
|
||||
config,
|
||||
runtime,
|
||||
|
||||
Reference in New Issue
Block a user