summaryrefslogtreecommitdiffhomepage
path: root/script
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2026-01-04 13:30:55 -0600
committerAiden Cline <[email protected]>2026-01-04 13:30:58 -0600
commit80235f325e5208bd462ba884200256d40a358f77 (patch)
treef9d6800eae2eec4aee366e6101e7b3799b613f88 /script
parent88c306efd297ff862ea425586a55f6d357817d4e (diff)
downloadopencode-80235f325e5208bd462ba884200256d40a358f77.tar.gz
opencode-80235f325e5208bd462ba884200256d40a358f77.zip
ci: fix dup pr action
Diffstat (limited to 'script')
-rwxr-xr-xscript/duplicate-pr.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/script/duplicate-pr.ts b/script/duplicate-pr.ts
new file mode 100755
index 000000000..aba078cec
--- /dev/null
+++ b/script/duplicate-pr.ts
@@ -0,0 +1,78 @@
+#!/usr/bin/env bun
+
+import path from "path"
+import { createOpencode } from "@opencode-ai/sdk"
+import { parseArgs } from "util"
+
+async function main() {
+ const { values, positionals } = parseArgs({
+ args: Bun.argv.slice(2),
+ options: {
+ file: { type: "string", short: "f" },
+ help: { type: "boolean", short: "h", default: false },
+ },
+ allowPositionals: true,
+ })
+
+ if (values.help) {
+ console.log(`
+Usage: bun script/duplicate-pr.ts [options] <message>
+
+Options:
+ -f, --file <path> File to attach to the prompt
+ -h, --help Show this help message
+
+Examples:
+ bun script/duplicate-pr.ts -f pr_info.txt "Check the attached file for PR details"
+`)
+ process.exit(0)
+ }
+
+ const message = positionals.join(" ")
+ if (!message) {
+ console.error("Error: message is required")
+ process.exit(1)
+ }
+
+ const opencode = await createOpencode({ port: 0 })
+
+ try {
+ const parts: Array<{ type: "text"; text: string } | { type: "file"; url: string; filename: string; mime: string }> =
+ []
+
+ if (values.file) {
+ const resolved = path.resolve(process.cwd(), values.file)
+ const file = Bun.file(resolved)
+ if (!(await file.exists())) {
+ console.error(`Error: file not found: ${values.file}`)
+ process.exit(1)
+ }
+ parts.push({
+ type: "file",
+ url: `file://${resolved}`,
+ filename: path.basename(resolved),
+ mime: "text/plain",
+ })
+ }
+
+ parts.push({ type: "text", text: message })
+
+ const session = await opencode.client.session.create()
+ const result = await opencode.client.session
+ .prompt({
+ path: { id: session.data!.id },
+ body: {
+ agent: "duplicate-pr",
+ parts,
+ },
+ signal: AbortSignal.timeout(120_000),
+ })
+ .then((x) => x.data?.parts?.find((y) => y.type === "text")?.text ?? "")
+
+ console.log(result.trim())
+ } finally {
+ opencode.server.close()
+ }
+}
+
+main()