fix(app): 僅輸出 Codex 最後回覆
This commit is contained in:
+18
-4
@@ -183,11 +183,13 @@ function readExecutionConfig() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function codexExecArgs(model, prompt) {
|
function codexExecArgs(model, prompt, lastMessageFile) {
|
||||||
return [
|
return [
|
||||||
"exec",
|
"exec",
|
||||||
"--dangerously-bypass-approvals-and-sandbox",
|
"--dangerously-bypass-approvals-and-sandbox",
|
||||||
"--skip-git-repo-check",
|
"--skip-git-repo-check",
|
||||||
|
"--output-last-message",
|
||||||
|
lastMessageFile,
|
||||||
"--model",
|
"--model",
|
||||||
model,
|
model,
|
||||||
prompt,
|
prompt,
|
||||||
@@ -197,7 +199,10 @@ function codexExecArgs(model, prompt) {
|
|||||||
function runCodex(model, prompt) {
|
function runCodex(model, prompt) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const { timeoutMs, outputLimitBytes, workspace } = readExecutionConfig();
|
const { timeoutMs, outputLimitBytes, workspace } = readExecutionConfig();
|
||||||
const args = codexExecArgs(model, prompt);
|
const tempDir = makeTempDir(process.env.CODEX_HOME || "/root/.codex");
|
||||||
|
const lastMessageFile = path.join(tempDir, "last-message.txt");
|
||||||
|
tempFiles.trackFile(lastMessageFile);
|
||||||
|
const args = codexExecArgs(model, prompt, lastMessageFile);
|
||||||
|
|
||||||
// This Docker Action runs inside an ephemeral CI container where Codex must be
|
// This Docker Action runs inside an ephemeral CI container where Codex must be
|
||||||
// able to edit the checked-out workspace without interactive approvals.
|
// able to edit the checked-out workspace without interactive approvals.
|
||||||
@@ -210,7 +215,6 @@ function runCodex(model, prompt) {
|
|||||||
output.append(Buffer.from(`Codex execution timed out after ${timeoutMs} ms.\n`));
|
output.append(Buffer.from(`Codex execution timed out after ${timeoutMs} ms.\n`));
|
||||||
}, timeoutMs);
|
}, timeoutMs);
|
||||||
|
|
||||||
child.stdout.pipe(process.stdout);
|
|
||||||
child.stderr.pipe(process.stdout);
|
child.stderr.pipe(process.stdout);
|
||||||
|
|
||||||
child.stdout.on("data", (chunk) => {
|
child.stdout.on("data", (chunk) => {
|
||||||
@@ -235,7 +239,14 @@ function runCodex(model, prompt) {
|
|||||||
output.append(Buffer.from(`Codex process terminated by signal ${signal}.\n`));
|
output.append(Buffer.from(`Codex process terminated by signal ${signal}.\n`));
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve({ status: code ?? 1, output: output.toString() });
|
let lastMessage = "";
|
||||||
|
try {
|
||||||
|
lastMessage = fs.readFileSync(lastMessageFile, "utf8");
|
||||||
|
} catch {
|
||||||
|
lastMessage = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve({ status: code ?? 1, output: lastMessage || output.toString() });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -312,6 +323,9 @@ function setupAuth(oauth, codexHome) {
|
|||||||
async function runCodexAction({ oauth, model, codexHome, prompt }) {
|
async function runCodexAction({ oauth, model, codexHome, prompt }) {
|
||||||
const lockHandle = setupAuth(oauth, codexHome);
|
const lockHandle = setupAuth(oauth, codexHome);
|
||||||
const result = await runCodex(model, prompt);
|
const result = await runCodex(model, prompt);
|
||||||
|
if (result.output) {
|
||||||
|
process.stdout.write(result.output.endsWith("\n") ? result.output : `${result.output}\n`);
|
||||||
|
}
|
||||||
appendGithubOutput(result.status === 0 ? "completed" : "failed", result.output);
|
appendGithubOutput(result.status === 0 ? "completed" : "failed", result.output);
|
||||||
|
|
||||||
if (lockHandle !== undefined) {
|
if (lockHandle !== undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user