Persist Codex review result to file
This commit is contained in:
1 parent
04ec203b61
commit
a638d9dbc5
3 files changed
+25
-40
No files matched your search
@@ -39,6 +39,8 @@ jobs:
|
|||||||
run: npm install -g @openai/codex
|
run: npm install -g @openai/codex
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
- name: Remove stale review result
|
||||||
|
run: rm -f .review-result.json
|
||||||
- run: node dist/src/actions/runReview.js
|
- run: node dist/src/actions/runReview.js
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ yarn-debug.log*
|
|||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
pnpm-debug.log*
|
pnpm-debug.log*
|
||||||
.vercel
|
.vercel
|
||||||
|
.ghbot-tmp/
|
||||||
|
.review-result.json
|
||||||
@@ -37,24 +37,19 @@ export class CodexCliReviewer {
|
|||||||
const tempRoot = path.join(process.cwd(), ".ghbot-tmp");
|
const tempRoot = path.join(process.cwd(), ".ghbot-tmp");
|
||||||
await fs.mkdir(tempRoot, { recursive: true });
|
await fs.mkdir(tempRoot, { recursive: true });
|
||||||
const tempDir = await fs.mkdtemp(path.join(tempRoot, "codex-"));
|
const tempDir = await fs.mkdtemp(path.join(tempRoot, "codex-"));
|
||||||
const schemaPath = path.join(tempDir, "review-schema.json");
|
|
||||||
const outputPath = path.join(tempDir, "review-output.json");
|
|
||||||
const codexHome = path.join(tempDir, "codex-home");
|
const codexHome = path.join(tempDir, "codex-home");
|
||||||
|
const resultPath = path.join(process.cwd(), ".review-result.json");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
await fs.rm(resultPath, { force: true });
|
||||||
await fs.mkdir(codexHome, { recursive: true });
|
await fs.mkdir(codexHome, { recursive: true });
|
||||||
await fs.writeFile(path.join(codexHome, "config.toml"), buildCodexConfig(), "utf8");
|
await fs.writeFile(path.join(codexHome, "config.toml"), buildCodexConfig(), "utf8");
|
||||||
await fs.writeFile(schemaPath, JSON.stringify(buildSchema(), null, 2), "utf8");
|
|
||||||
|
|
||||||
const prompt = buildPrompt(input);
|
const prompt = buildPrompt(input, resultPath);
|
||||||
const args = [
|
const args = [
|
||||||
"exec",
|
"exec",
|
||||||
"--skip-git-repo-check",
|
"--skip-git-repo-check",
|
||||||
"--dangerously-bypass-approvals-and-sandbox",
|
"--dangerously-bypass-approvals-and-sandbox",
|
||||||
"--output-schema",
|
|
||||||
schemaPath,
|
|
||||||
"--output-last-message",
|
|
||||||
outputPath,
|
|
||||||
"-C",
|
"-C",
|
||||||
process.cwd(),
|
process.cwd(),
|
||||||
"--ephemeral"
|
"--ephemeral"
|
||||||
@@ -93,9 +88,16 @@ export class CodexCliReviewer {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const raw = await fs.readFile(outputPath, "utf8");
|
try {
|
||||||
|
await fs.access(resultPath);
|
||||||
|
} catch {
|
||||||
|
throw new Error(`Codex CLI did not create ${resultPath}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const raw = await fs.readFile(resultPath, "utf8");
|
||||||
return reviewDecisionSchema.parse(JSON.parse(raw));
|
return reviewDecisionSchema.parse(JSON.parse(raw));
|
||||||
} finally {
|
} finally {
|
||||||
|
await fs.rm(resultPath, { force: true });
|
||||||
await fs.rm(tempDir, { recursive: true, force: true });
|
await fs.rm(tempDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -241,44 +243,23 @@ function toTomlString(value: string): string {
|
|||||||
return JSON.stringify(value);
|
return JSON.stringify(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSchema() {
|
|
||||||
return {
|
|
||||||
type: "object",
|
|
||||||
additionalProperties: false,
|
|
||||||
required: ["safeToMerge", "shouldClosePullRequest", "closeReason", "summary", "findings"],
|
|
||||||
properties: {
|
|
||||||
safeToMerge: { type: "boolean" },
|
|
||||||
shouldClosePullRequest: { type: "boolean" },
|
|
||||||
closeReason: { type: "string" },
|
|
||||||
summary: { type: "string" },
|
|
||||||
findings: {
|
|
||||||
type: "array",
|
|
||||||
items: {
|
|
||||||
type: "object",
|
|
||||||
additionalProperties: false,
|
|
||||||
required: ["path", "line", "severity", "title", "body"],
|
|
||||||
properties: {
|
|
||||||
path: { type: "string" },
|
|
||||||
line: { type: "integer", minimum: 1 },
|
|
||||||
severity: { type: "string", enum: ["blocking", "suggestion"] },
|
|
||||||
title: { type: "string" },
|
|
||||||
body: { type: "string" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildPrompt(input: {
|
function buildPrompt(input: {
|
||||||
title: string;
|
title: string;
|
||||||
body: string | null;
|
body: string | null;
|
||||||
files: PullRequestFile[];
|
files: PullRequestFile[];
|
||||||
mode: ReviewMode;
|
mode: ReviewMode;
|
||||||
}): string {
|
}, resultPath: string): string {
|
||||||
return [
|
return [
|
||||||
buildSystemPrompt(input.mode),
|
buildSystemPrompt(input.mode),
|
||||||
"",
|
"",
|
||||||
|
`Write your final JSON review result to ${resultPath}.`,
|
||||||
|
"Do not wrap the JSON in markdown.",
|
||||||
|
"Do not print the final JSON to stdout.",
|
||||||
|
"The JSON must have exactly these top-level keys: safeToMerge, shouldClosePullRequest, closeReason, summary, findings.",
|
||||||
|
"Each item in findings must have exactly these keys: path, line, severity, title, body.",
|
||||||
|
'Valid severity values are only "blocking" or "suggestion".',
|
||||||
|
`After writing ${resultPath}, you may print short progress logs, but the file contents must be valid JSON.`,
|
||||||
|
"",
|
||||||
"Pull request payload:",
|
"Pull request payload:",
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
{
|
{
|
||||||
@@ -303,7 +284,7 @@ function buildPrompt(input: {
|
|||||||
function buildSystemPrompt(mode: ReviewMode): string {
|
function buildSystemPrompt(mode: ReviewMode): string {
|
||||||
const commonRules = [
|
const commonRules = [
|
||||||
"You are a senior software engineer reviewing a GitHub pull request.",
|
"You are a senior software engineer reviewing a GitHub pull request.",
|
||||||
"Return JSON that exactly matches the provided schema.",
|
"Produce a final result object that exactly matches the requested JSON structure.",
|
||||||
"Only set safeToMerge=true when there are no blocking findings.",
|
"Only set safeToMerge=true when there are no blocking findings.",
|
||||||
"Set shouldClosePullRequest=true only for clearly malicious code: backdoors, credential theft, token exfiltration, destructive commands, malware, hidden persistence, privilege escalation, supply-chain compromise, or intentionally abusive behavior.",
|
"Set shouldClosePullRequest=true only for clearly malicious code: backdoors, credential theft, token exfiltration, destructive commands, malware, hidden persistence, privilege escalation, supply-chain compromise, or intentionally abusive behavior.",
|
||||||
"Do not set shouldClosePullRequest=true for ordinary bugs, crashes, failing tests, incomplete code, suspicious-but-unproven code, or low-quality changes.",
|
"Do not set shouldClosePullRequest=true for ordinary bugs, crashes, failing tests, incomplete code, suspicious-but-unproven code, or low-quality changes.",
|
||||||
|
|||||||
Reference in new issue
Block a user