| 36 | } |
| 37 | |
| 38 | export function readCommentMetadata(value: unknown) { |
| 39 | if (!value || typeof value !== "object") return |
| 40 | const meta = (value as { opencodeComment?: unknown }).opencodeComment |
| 41 | if (!meta || typeof meta !== "object") return |
| 42 | const path = (meta as { path?: unknown }).path |
| 43 | const comment = (meta as { comment?: unknown }).comment |
| 44 | if (typeof path !== "string" || typeof comment !== "string") return |
| 45 | const preview = (meta as { preview?: unknown }).preview |
| 46 | const origin = (meta as { origin?: unknown }).origin |
| 47 | return { |
| 48 | path, |
| 49 | selection: selection((meta as { selection?: unknown }).selection), |
| 50 | comment, |
| 51 | preview: typeof preview === "string" ? preview : undefined, |
| 52 | origin: origin === "review" || origin === "file" ? origin : undefined, |
| 53 | } satisfies PromptComment |
| 54 | } |
| 55 | |
| 56 | export function formatCommentNote(input: { path: string; selection?: FileSelection; comment: string }) { |
| 57 | const start = input.selection ? Math.min(input.selection.startLine, input.selection.endLine) : undefined |