MCPcopy
hub / github.com/anomalyco/opencode / getUserPrompt

Function getUserPrompt

github/index.ts:414–492  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

412}
413
414async function getUserPrompt() {
415 const context = useContext()
416 const payload = context.payload as IssueCommentEvent | PullRequestReviewCommentEvent
417 const reviewContext = getReviewCommentContext()
418
419 let prompt = (() => {
420 const body = payload.comment.body.trim()
421 if (body === "/opencode" || body === "/oc") {
422 if (reviewContext) {
423 return `Review this code change and suggest improvements for the commented lines:\n\nFile: ${reviewContext.file}\nLines: ${reviewContext.line}\n\n${reviewContext.diffHunk}`
424 }
425 return "Summarize this thread"
426 }
427 if (body.includes("/opencode") || body.includes("/oc")) {
428 if (reviewContext) {
429 return `${body}\n\nContext: You are reviewing a comment on file "${reviewContext.file}" at line ${reviewContext.line}.\n\nDiff context:\n${reviewContext.diffHunk}`
430 }
431 return body
432 }
433 throw new Error("Comments must mention `/opencode` or `/oc`")
434 })()
435
436 // Handle images
437 const imgData: {
438 filename: string
439 mime: string
440 content: string
441 start: number
442 end: number
443 replacement: string
444 }[] = []
445
446 // Search for files
447 // ie. <img alt="Image" src="https://github.com/user-attachments/assets/xxxx" />
448 // ie. [api.json](https://github.com/user-attachments/files/21433810/api.json)
449 // ie. ![Image](https://github.com/user-attachments/assets/xxxx)
450 const mdMatches = prompt.matchAll(/!?\[.*?\]\((https:\/\/github\.com\/user-attachments\/[^)]+)\)/gi)
451 const tagMatches = prompt.matchAll(/<img .*?src="(https:\/\/github\.com\/user-attachments\/[^"]+)" \/>/gi)
452 const matches = [...mdMatches, ...tagMatches].sort((a, b) => a.index - b.index)
453 console.log("Images", JSON.stringify(matches, null, 2))
454
455 let offset = 0
456 for (const m of matches) {
457 const tag = m[0]
458 const url = m[1]
459 const start = m.index
460
461 if (!url) continue
462 const filename = path.basename(url)
463
464 // Download image
465 const res = await fetch(url, {
466 headers: {
467 Authorization: `Bearer ${accessToken}`,
468 Accept: "application/vnd.github.v3+json",
469 },
470 })
471 if (!res.ok) {

Callers 1

index.tsFile · 0.70

Calls 8

useContextFunction · 0.85
pushMethod · 0.80
getReviewCommentContextFunction · 0.70
getMethod · 0.65
arrayBufferMethod · 0.65
fetchFunction · 0.50
logMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected