|
| 1 | +import { useEffect, useState } from "react"; |
| 2 | +import type { GraphNode } from "../lib/types"; |
| 3 | + |
| 4 | +/* Upstream tracker for indexing gaps — issues land on the codebase-memory-mcp |
| 5 | + * project itself (the tool that failed to index), never the user's repo. */ |
| 6 | +const UPSTREAM_ISSUES_URL = "https://github.com/DeusData/codebase-memory-mcp/issues/new"; |
| 7 | + |
| 8 | +interface MissedCalloutProps { |
| 9 | + node: GraphNode; |
| 10 | + project: string | null; |
| 11 | + onClose: () => void; |
| 12 | +} |
| 13 | + |
| 14 | +function buildIssueUrl(path: string, project: string | null): string { |
| 15 | + const title = `Indexing gap: ${path}`; |
| 16 | + const body = [ |
| 17 | + "## Not fully indexed (best-effort coverage signal)", |
| 18 | + "", |
| 19 | + `- **File:** \`${path}\``, |
| 20 | + `- **Project:** \`${project ?? "unknown"}\``, |
| 21 | + "", |
| 22 | + "<!-- Please add: the flagged line ranges from index_status (parse_partial),", |
| 23 | + "the language and the construct that fails to parse, and a minimal snippet", |
| 24 | + "of the affected code — ONLY if the code is shareable. -->", |
| 25 | + "", |
| 26 | + "_Reported from the graph UI's missed-coverage view._", |
| 27 | + ].join("\n"); |
| 28 | + return `${UPSTREAM_ISSUES_URL}?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`; |
| 29 | +} |
| 30 | + |
| 31 | +function buildAgentPrompt(path: string, project: string | null): string { |
| 32 | + return ( |
| 33 | + `codebase-memory-mcp could not fully index \`${path}\`` + |
| 34 | + (project ? ` (project \`${project}\`)` : "") + |
| 35 | + " — best-effort coverage signal. Please: " + |
| 36 | + "1) call the index_status MCP tool and note this file's flagged line ranges under parse_partial; " + |
| 37 | + "2) read those ranges in the file and summarize which construct fails to parse; " + |
| 38 | + `3) file a GitHub issue at ${UPSTREAM_ISSUES_URL} titled "Indexing gap: ${path}" ` + |
| 39 | + "with the summary — include a minimal reproducible snippet ONLY if the code is shareable." |
| 40 | + ); |
| 41 | +} |
| 42 | + |
| 43 | +/* Right-panel callout shown when a missed-skeleton node is selected: explains |
| 44 | + * the gap and offers two working actions — a prefilled upstream issue and a |
| 45 | + * ready-made agent prompt (clipboard, with visible feedback). */ |
| 46 | +export function MissedCallout({ node, project, onClose }: MissedCalloutProps) { |
| 47 | + const path = node.file_path || node.name; |
| 48 | + const [copied, setCopied] = useState(false); |
| 49 | + |
| 50 | + useEffect(() => { |
| 51 | + if (!copied) return; |
| 52 | + const t = setTimeout(() => setCopied(false), 2000); |
| 53 | + return () => clearTimeout(t); |
| 54 | + }, [copied]); |
| 55 | + |
| 56 | + const copyPrompt = async () => { |
| 57 | + try { |
| 58 | + await navigator.clipboard.writeText(buildAgentPrompt(path, project)); |
| 59 | + setCopied(true); |
| 60 | + } catch { |
| 61 | + /* clipboard unavailable (permissions/insecure context) — leave the |
| 62 | + * button state unchanged so the failure is visible, not silent */ |
| 63 | + } |
| 64 | + }; |
| 65 | + |
| 66 | + return ( |
| 67 | + <div className="h-full flex flex-col p-4 gap-3 overflow-y-auto"> |
| 68 | + <div className="flex items-start justify-between"> |
| 69 | + <div> |
| 70 | + <p className="text-[10px] text-foreground/30 uppercase tracking-widest"> |
| 71 | + Not fully indexed |
| 72 | + </p> |
| 73 | + <p className="text-sm font-medium text-foreground/90 break-all mt-1">{path}</p> |
| 74 | + <p className="text-[10px] text-foreground/40 mt-0.5">{node.label}</p> |
| 75 | + </div> |
| 76 | + <button |
| 77 | + onClick={onClose} |
| 78 | + className="text-foreground/40 hover:text-foreground/80 text-sm px-1" |
| 79 | + aria-label="Close" |
| 80 | + > |
| 81 | + × |
| 82 | + </button> |
| 83 | + </div> |
| 84 | + |
| 85 | + <p className="text-[12px] leading-relaxed text-foreground/70"> |
| 86 | + We did not manage to fully index this part of your code — constructs here may be |
| 87 | + missing from the graph (best-effort detection; the file content itself is ground |
| 88 | + truth). |
| 89 | + </p> |
| 90 | + <p className="text-[12px] leading-relaxed text-foreground/70"> |
| 91 | + Help us handle this edge case too: let your agent summarize what fails to parse |
| 92 | + here and file a GitHub issue for the codebase-memory-mcp project. |
| 93 | + </p> |
| 94 | + |
| 95 | + <div className="flex flex-col gap-2 mt-1"> |
| 96 | + <button |
| 97 | + onClick={copyPrompt} |
| 98 | + className={`text-[12px] font-medium rounded-md border px-3 py-1.5 transition-all text-left ${ |
| 99 | + copied |
| 100 | + ? "border-primary/60 bg-primary/15 text-primary" |
| 101 | + : "border-white/10 bg-white/[0.03] text-foreground/80 hover:bg-white/[0.07]" |
| 102 | + }`} |
| 103 | + > |
| 104 | + {copied ? "✓ Copied — paste it to your agent" : "Copy agent prompt"} |
| 105 | + </button> |
| 106 | + <a |
| 107 | + href={buildIssueUrl(path, project)} |
| 108 | + target="_blank" |
| 109 | + rel="noreferrer" |
| 110 | + className="text-[12px] font-medium rounded-md border border-white/10 bg-white/[0.03] text-foreground/80 hover:bg-white/[0.07] px-3 py-1.5 transition-all" |
| 111 | + > |
| 112 | + File a GitHub issue (prefilled) ↗ |
| 113 | + </a> |
| 114 | + </div> |
| 115 | + |
| 116 | + <p className="text-[10px] leading-snug text-foreground/35 mt-1"> |
| 117 | + The prefilled issue contains only the file path and project name — add code |
| 118 | + snippets only if they are shareable. |
| 119 | + </p> |
| 120 | + </div> |
| 121 | + ); |
| 122 | +} |
0 commit comments