feat: add PR walkthrough generation workflow (#2933)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
import path from "path"
|
||||
|
||||
export default tool({
|
||||
description:
|
||||
"Validate and render a complete PR walkthrough JSON object. Retry with corrected JSON when this tool reports a renderer error.",
|
||||
args: {
|
||||
walkthrough: tool.schema
|
||||
.string()
|
||||
.max(2_000_000)
|
||||
.describe("The complete PR walkthrough JSON object as a string"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
const helper = path.join(context.worktree, ".opencode-walkthrough", "render")
|
||||
const sourceEnv = globalThis.process.env
|
||||
const childEnv = Object.fromEntries(
|
||||
["PATH", "PR_NUMBER", "PR_TITLE", "PR_URL", "PR_REPO", "PR_BASE", "PR_HEAD"]
|
||||
.filter((name) => sourceEnv[name] !== undefined)
|
||||
.map((name) => [name, sourceEnv[name] as string]),
|
||||
)
|
||||
const child = Bun.spawn(["python3", helper], {
|
||||
cwd: context.worktree,
|
||||
env: childEnv,
|
||||
stdin: new Blob([args.walkthrough]),
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
})
|
||||
const [status, stdout, stderr] = await Promise.all([
|
||||
child.exited,
|
||||
new Response(child.stdout).text(),
|
||||
new Response(child.stderr).text(),
|
||||
])
|
||||
if (status !== 0) {
|
||||
return `Renderer rejected the walkthrough. Correct the JSON and call this tool again.\n${stderr || stdout}`
|
||||
}
|
||||
return stdout.trim()
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user