feat: complete chat routing and openai onboarding

This commit is contained in:
kris
2026-03-31 03:31:22 +08:00
parent 5b590f7cc1
commit 9c02ebb574
25 changed files with 2241 additions and 133 deletions

View File

@@ -0,0 +1,51 @@
export function buildCodexTaskExecution(config, task, outputFile) {
const targetThreadRef =
String(task?.targetCodexThreadRef || task?.targetThreadId || "").trim();
const targetFolderRef =
String(task?.targetCodexFolderRef || config.masterAgentWorkdir || process.cwd()).trim() ||
process.cwd();
const prompt = String(task?.executionPrompt || "");
if (
targetThreadRef &&
(task?.taskType === "conversation_reply" || task?.taskType === "dispatch_execution")
) {
const args = [
"exec",
"resume",
"--skip-git-repo-check",
"-o",
outputFile,
];
if (config.masterAgentModel) {
args.push("-m", config.masterAgentModel);
}
args.push(targetThreadRef, prompt);
return {
mode: "resume",
cwd: targetFolderRef,
args,
};
}
const args = [
"exec",
"--ephemeral",
"--skip-git-repo-check",
"-C",
config.masterAgentWorkdir || process.cwd(),
"-s",
config.masterAgentSandbox || "workspace-write",
"-o",
outputFile,
];
if (config.masterAgentModel) {
args.push("-m", config.masterAgentModel);
}
args.push(prompt);
return {
mode: "ephemeral",
cwd: config.masterAgentWorkdir || process.cwd(),
args,
};
}

View File

@@ -6,6 +6,7 @@ import { access, readFile, readdir, rm } from "node:fs/promises";
import os from "node:os";
import { join, resolve } from "node:path";
import { discoverCodexProjectCandidates } from "./codex-session-discovery.mjs";
import { buildCodexTaskExecution } from "./codex-task-runner.mjs";
async function loadConfig(configPath) {
const raw = await readFile(resolve(configPath), "utf8");
@@ -298,25 +299,6 @@ async function completeMasterAgentTask(config, runtime, payload) {
};
}
function buildCodexArgs(config, outputFile, prompt) {
const args = [
"exec",
"--ephemeral",
"--skip-git-repo-check",
"-C",
config.masterAgentWorkdir || process.cwd(),
"-s",
config.masterAgentSandbox || "workspace-write",
"-o",
outputFile,
];
if (config.masterAgentModel) {
args.push("-m", config.masterAgentModel);
}
args.push(prompt);
return args;
}
function parseDispatchExecutionCompletion(rawOutput) {
const trimmed = String(rawOutput || "").trim();
if (!trimmed) {
@@ -363,9 +345,10 @@ async function runMasterAgentTask(config, runtime, task) {
};
try {
const codexExecution = buildCodexTaskExecution(config, task, outputFile);
await new Promise((resolveTask, rejectTask) => {
const child = spawn("codex", buildCodexArgs(config, outputFile, task.executionPrompt), {
cwd: config.masterAgentWorkdir || process.cwd(),
const child = spawn("codex", codexExecution.args, {
cwd: codexExecution.cwd,
env: process.env,
});