MCPcopy Create free account
hub / github.com/anomalyco/opencode / main

Function main

script/duplicate-pr.ts:8–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import { parseArgs } from "util"
7
8async function main() {
9 const { values, positionals } = parseArgs({
10 args: Bun.argv.slice(2),
11 options: {
12 file: { type: "string", short: "f" },
13 help: { type: "boolean", short: "h", default: false },
14 },
15 allowPositionals: true,
16 })
17
18 if (values.help) {
19 console.log(`
20Usage: bun script/duplicate-pr.ts [options] <message>
21
22Options:
23 -f, --file <path> File to attach to the prompt
24 -h, --help Show this help message
25
26Examples:
27 bun script/duplicate-pr.ts -f pr_info.txt "Check the attached file for PR details"
28`)
29 process.exit(0)
30 }
31
32 const message = positionals.join(" ")
33 if (!message) {
34 console.error("Error: message is required")
35 process.exit(1)
36 }
37
38 const opencode = await createOpencode({ port: 0 })
39
40 try {
41 const parts: Array<{ type: "text"; text: string } | { type: "file"; url: string; filename: string; mime: string }> =
42 []
43
44 if (values.file) {
45 const resolved = path.resolve(process.cwd(), values.file)
46 const file = Bun.file(resolved)
47 if (!(await file.exists())) {
48 console.error(`Error: file not found: ${values.file}`)
49 process.exit(1)
50 }
51 parts.push({
52 type: "file",
53 url: pathToFileURL(resolved).href,
54 filename: path.basename(resolved),
55 mime: "text/plain",
56 })
57 }
58
59 parts.push({ type: "text", text: message })
60
61 const session = await opencode.client.session.create()
62 const result = await opencode.client.session
63 .prompt({
64 path: { id: session.data!.id },
65 body: {

Callers 1

duplicate-pr.tsFile · 0.70

Calls 11

createOpencodeFunction · 0.90
parseArgsFunction · 0.85
fileMethod · 0.80
pushMethod · 0.80
cwdMethod · 0.65
createMethod · 0.65
promptMethod · 0.65
findMethod · 0.65
logMethod · 0.45
existsMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected