opencode-config/.opencode/tools/post-review.ts
Sergey 1acac5229f
feat(tools): deterministic review posting tools (post-review, post-docs-review) (#46)
* feat(tools): add post-review and post-docs-review tools

* refactor(agents): use post-review/post-docs-review tools in reviewer and docs-reviewer

* feat(permissions): add post_review and post_docs_review to agent.tools map

* test(tools): add tests for post-review and post-docs-review tools

* docs(handoff): add handoff ADR and project-map for review posting tools

* docs(handoff): set PR number

* docs: fix PR#45→PR#46 refs in project map

---------

Co-authored-by: opencode-agent <agent@slaid098.dev>
2026-07-24 18:26:48 +03:00

25 lines
No EOL
1.3 KiB
TypeScript

import { spawnSync } from "child_process"
import { tool } from "@opencode-ai/plugin"
const VERDICTS = ["APPROVE", "REQUEST_CHANGES", "NEEDS_DISCUSSION"] as const
type Verdict = typeof VERDICTS[number]
export default tool({
description: "Post code review verdict as PR comment with deterministic heading. Reviewer agent uses this instead of raw `gh pr comment` to guarantee `## Code Review Summary` + `### Verdict: <verdict>` format that pipeline-status.py parses.",
args: {
pr_number: tool.schema.number().describe("PR number to comment on"),
verdict: tool.schema.enum(VERDICTS).describe("Review verdict: APPROVE, REQUEST_CHANGES, or NEEDS_DISCUSSION"),
body: tool.schema.string().describe("Review body text (without heading — heading is auto-generated)"),
},
async execute(args, context) {
const comment = `## Code Review Summary\n\n${args.body}\n\n### Verdict: ${args.verdict}`
const r = spawnSync("gh", ["pr", "comment", String(args.pr_number), "--body", comment, "--repo", "slaid098/opencode-config"], {
encoding: "utf-8",
cwd: context.worktree,
})
if (r.status !== 0) {
return `⚠️ post-review failed for PR #${args.pr_number} (exit ${r.status}): ${r.stderr || r.stdout}`
}
return `Review posted on PR #${args.pr_number}: verdict=${args.verdict}`
},
})