Skip to content

Commit 664313e

Browse files
committed
feat(index): missed graph in UI + read-time coverage hook + recovery subtraction
Four refinements to the coverage signal: - extraction: subtract DEFINITE recovery before flagging. Tree-sitter error recovery plus the ERROR-descending def walker often re-extract constructs inside a failed region (verified: `def broken(:` comes back as a def); a region whose every line is covered by definitions that START inside it is not a miss, and a fully recovered file is not flagged at all. Container defs (Module/Package) don't count as evidence, and partially covered regions stay flagged — the #ifdef-split case keeps its flag because the first branch's function is genuinely lost - naming: the query_graph option is graph="missed" (the graph shows ONLY misses — "coverage" was misleading); shadow project renamed to "<name>::missed"; tool descriptions updated so agents discover both the option and its semantics - hook: the CLI-installed PreToolUse augmenter now also matches Read and injects a coverage note when the file being read is listed as not fully indexed ("line ranges X-Y could not be parsed — the file content you are reading is ground truth"). Safe against the old issue-362 hazard: the augmenter is structurally non-blocking (always exit 0, additionalContext only), mirroring the Gemini matcher that already includes read_file; matcher upgrade bookkeeping updated - ui: "Missed files" toggle in the graph sidebar renders the miss graph as a second graph option — /api/layout gains graph=missed (same db file, shadow-project scoping; base project name validated as before) Tests: recovery-subtraction cases (recovered def unflagged, garbage region flagged, trailing recovered defs keep the flag), CLI matcher tests updated, e2e resilience fixtures switched to an unrecovered miss; verified end-to-end: hook emits the note for a flagged file and stays silent otherwise, /api/layout?graph=missed serves the miss graph and the code graph is unchanged, frontend build + tests green. Refs DeusData#963 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent f9d7f4a commit 664313e

14 files changed

Lines changed: 464 additions & 90 deletions

File tree

‎graph-ui/src/components/FilterPanel.tsx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ interface FilterPanelProps {
2222
onToggleShowOnlyDead: () => void;
2323
onToggleHideEntryPoints: () => void;
2424
onToggleHideTests: () => void;
25+
/* Missed graph (#963): file structure of not-fully-indexed files */
26+
missedView: boolean;
27+
onToggleMissedView: () => void;
2528
}
2629

2730
/* Checkbox row matching the existing "Show labels" toggle style */
@@ -76,6 +79,8 @@ export function FilterPanel({
7679
onToggleShowOnlyDead,
7780
onToggleHideEntryPoints,
7881
onToggleHideTests,
82+
missedView,
83+
onToggleMissedView,
7984
}: FilterPanelProps) {
8085
const { labelCounts, edgeTypeCounts, statusCounts } = useMemo(() => {
8186
const lc = new Map<string, number>();
@@ -163,6 +168,27 @@ export function FilterPanel({
163168
</div>
164169
</ScrollArea>
165170

171+
{/* Missed graph (#963): swaps the layout to the file structure of files
172+
the indexer could not fully cover (best-effort signal). */}
173+
<div className="px-4 pt-2 border-t border-border/30 space-y-2 shrink-0">
174+
<div className="flex items-center justify-between">
175+
<span className="text-[10px] text-foreground/30 uppercase tracking-widest">
176+
Graph
177+
</span>
178+
</div>
179+
<CheckRow
180+
checked={missedView}
181+
onToggle={onToggleMissedView}
182+
label="Missed files (not fully indexed)"
183+
/>
184+
{missedView && (
185+
<p className="text-[9px] leading-snug text-foreground/30">
186+
Best-effort: files with unparseable regions or skips. Empty = no
187+
known misses (not a completeness guarantee).
188+
</p>
189+
)}
190+
</div>
191+
166192
{/* Dead-code view */}
167193
<div className="px-4 pt-2 border-t border-border/30 space-y-2 shrink-0">
168194
<div className="flex items-center justify-between">

‎graph-ui/src/components/GraphTab.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export function GraphTab({ project }: GraphTabProps) {
102102
const [enabledLabels, setEnabledLabels] = useState<Set<string>>(new Set());
103103
const [enabledEdgeTypes, setEnabledEdgeTypes] = useState<Set<string>>(new Set());
104104

105+
/* Missed graph (#963): render the file structure of files the indexer
106+
* could not fully cover instead of the code graph. Server-side option
107+
* (`graph=missed` on /api/layout) — toggling refetches. */
108+
const [missedView, setMissedView] = useState(false);
109+
105110
/* Dead-code view: recolor by status + status-based filters */
106111
const [deadCodeView, setDeadCodeView] = useState(false);
107112
const [showOnlyDead, setShowOnlyDead] = useState(false);
@@ -184,11 +189,11 @@ export function GraphTab({ project }: GraphTabProps) {
184189
/* …and fetch only once budget and project agree (one fetch per change). */
185190
useEffect(() => {
186191
if (project && budget.project === project) {
187-
fetchOverview(project, budget.value);
192+
fetchOverview(project, budget.value, missedView ? "missed" : "code");
188193
setHighlightedIds(null);
189194
setSelectedPath(null);
190195
}
191-
}, [project, budget, fetchOverview]);
196+
}, [project, budget, missedView, fetchOverview]);
192197

193198
/* Fetch git remote metadata for GitHub deep-links */
194199
useEffect(() => {
@@ -351,6 +356,8 @@ export function GraphTab({ project }: GraphTabProps) {
351356
onToggleShowOnlyDead={() => setShowOnlyDead((v) => !v)}
352357
onToggleHideEntryPoints={() => setHideEntryPoints((v) => !v)}
353358
onToggleHideTests={() => setHideTests((v) => !v)}
359+
missedView={missedView}
360+
onToggleMissedView={() => setMissedView((v) => !v)}
354361
/>
355362
<Sidebar
356363
nodes={filteredData.nodes}

‎graph-ui/src/hooks/useGraphData.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ interface UseGraphDataResult {
1111
loading: boolean;
1212
error: string | null;
1313
progress: LoadProgress;
14-
fetchOverview: (project: string, maxNodes?: number) => void;
14+
fetchOverview: (
15+
project: string,
16+
maxNodes?: number,
17+
graph?: "code" | "missed",
18+
) => void;
1519
fetchDetail: (project: string, centerNode: string) => void;
1620
}
1721

@@ -32,12 +36,18 @@ export function clampNodeBudget(value: number): number {
3236
return stepped;
3337
}
3438

39+
/** Which graph to lay out: the code graph (default) or the missed graph —
40+
* only files the indexer could not fully cover, as their file structure. */
41+
export type GraphVariant = "code" | "missed";
42+
3543
export async function fetchLayout(
3644
project: string,
3745
maxNodes = GRAPH_RENDER_NODE_LIMIT,
3846
onProgress?: (progress: LoadProgress) => void,
47+
graph: GraphVariant = "code",
3948
): Promise<GraphData> {
4049
const params = new URLSearchParams({ project, max_nodes: String(maxNodes) });
50+
if (graph === "missed") params.set("graph", "missed");
4151
const res = await fetch(`/api/layout?${params}`);
4252

4353
if (!res.ok) {
@@ -83,12 +93,12 @@ export function useGraphData(): UseGraphDataResult {
8393
const [progress, setProgress] = useState<LoadProgress>(NO_PROGRESS);
8494

8595
const fetchOverview = useCallback(
86-
async (project: string, maxNodes?: number) => {
96+
async (project: string, maxNodes?: number, graph: GraphVariant = "code") => {
8797
setLoading(true);
8898
setError(null);
8999
setProgress(NO_PROGRESS);
90100
try {
91-
const result = await fetchLayout(project, maxNodes, setProgress);
101+
const result = await fetchLayout(project, maxNodes, setProgress, graph);
92102
setData(result);
93103
} catch (e) {
94104
setError(e instanceof Error ? e.message : "Failed to fetch layout");

‎internal/cbm/cbm.c‎

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,72 @@ static void cbm_collect_error_regions(TSNode n, cbm_error_regions_t *acc) {
725725
}
726726
}
727727

728+
/* Recovery subtraction (#963): tree-sitter error recovery plus the
729+
* ERROR-descending def walker often still extract constructs INSIDE a failed
730+
* region (verified: a function in an #ifdef-split ERROR region and even a
731+
* `def broken(:` both came back as defs). A region whose every line is
732+
* covered by definitions that START inside it is definitely recovered — its
733+
* constructs ARE in the graph — so flagging it would be a false miss.
734+
* Container defs (Module/Package) are ignored: a file-spanning Module node is
735+
* not evidence the region's constructs survived. Conservative: partially
736+
* covered regions stay flagged. */
737+
static bool cbm_region_is_recovered(uint32_t rs, uint32_t re, const CBMDefArray *defs) {
738+
enum { MAX_COVER_DEFS = 256 };
739+
uint32_t starts[MAX_COVER_DEFS];
740+
uint32_t ends[MAX_COVER_DEFS];
741+
int n = 0;
742+
for (int i = 0; i < defs->count && n < MAX_COVER_DEFS; i++) {
743+
const CBMDefinition *d = &defs->items[i];
744+
if (!d->label || strcmp(d->label, "Module") == 0 || strcmp(d->label, "Package") == 0) {
745+
continue;
746+
}
747+
if (d->start_line < rs || d->start_line > re) {
748+
continue; /* recovery evidence must originate inside the region */
749+
}
750+
starts[n] = d->start_line;
751+
ends[n] = d->end_line < d->start_line ? d->start_line : d->end_line;
752+
n++;
753+
}
754+
if (n == 0) {
755+
return false;
756+
}
757+
/* Insertion-sort by start, then sweep for gaps in [rs, re]. */
758+
for (int i = 1; i < n; i++) {
759+
uint32_t s = starts[i];
760+
uint32_t e = ends[i];
761+
int j = i - 1;
762+
while (j >= 0 && starts[j] > s) {
763+
starts[j + 1] = starts[j];
764+
ends[j + 1] = ends[j];
765+
j--;
766+
}
767+
starts[j + 1] = s;
768+
ends[j + 1] = e;
769+
}
770+
uint32_t covered_to = rs - 1;
771+
for (int i = 0; i < n; i++) {
772+
if (starts[i] > covered_to + 1) {
773+
return false; /* uncovered gap */
774+
}
775+
if (ends[i] > covered_to) {
776+
covered_to = ends[i];
777+
}
778+
}
779+
return covered_to >= re;
780+
}
781+
782+
static void cbm_subtract_recovered_regions(cbm_error_regions_t *regs, const CBMDefArray *defs) {
783+
int kept = 0;
784+
for (int i = 0; i < regs->count; i++) {
785+
if (!cbm_region_is_recovered(regs->starts[i], regs->ends[i], defs)) {
786+
regs->starts[kept] = regs->starts[i];
787+
regs->ends[kept] = regs->ends[i];
788+
kept++;
789+
}
790+
}
791+
regs->count = kept;
792+
}
793+
728794
/* Serialize collected regions as "start-end,start-end,..." into the arena. */
729795
static const char *cbm_error_ranges_str(CBMArena *a, const cbm_error_regions_t *regs) {
730796
if (regs->count <= 0) {
@@ -843,22 +909,6 @@ static CBMFileResult *cbm_extract_file_impl(const char *source, int source_len,
843909

844910
TSNode root = ts_tree_root_node(tree);
845911

846-
/* Best-effort parse-coverage signal (#963): flag files whose tree contains
847-
* ERROR/MISSING nodes — constructs inside those regions are silently absent
848-
* from the graph. Detection aid only: the absence of this flag is NOT a
849-
* completeness guarantee. */
850-
if (ts_node_has_error(root)) {
851-
result->parse_incomplete = true;
852-
cbm_error_regions_t regs = {{0}, {0}, 0};
853-
if (strcmp(ts_node_type(root), "ERROR") == 0) {
854-
cbm_error_regions_push(&regs, root); /* whole file unparseable */
855-
} else {
856-
cbm_collect_error_regions(root, &regs);
857-
}
858-
result->error_region_count = regs.count;
859-
result->error_ranges = cbm_error_ranges_str(a, &regs);
860-
}
861-
862912
// Compute module QN. Java/Go derive the module from the CONTAINING
863913
// DIRECTORY (package semantics) rather than baking the filename stem in,
864914
// so def QNs, the LSP caller_qn, and the textual calls-enclosing QN all
@@ -1108,6 +1158,26 @@ static CBMFileResult *cbm_extract_file_impl(const char *source, int source_len,
11081158

11091159
uint64_t t2 = now_ns();
11101160

1161+
/* Best-effort parse-coverage signal (#963): flag files whose tree contains
1162+
* ERROR/MISSING regions. Computed AFTER extraction so definite recovery is
1163+
* subtracted first — a region fully re-extracted as definitions is not a
1164+
* miss, and a fully recovered file is not flagged at all. Detection aid
1165+
* only: the absence of this flag is NOT a completeness guarantee. */
1166+
if (ts_node_has_error(root)) {
1167+
cbm_error_regions_t regs = {{0}, {0}, 0};
1168+
if (strcmp(ts_node_type(root), "ERROR") == 0) {
1169+
cbm_error_regions_push(&regs, root); /* whole file unparseable */
1170+
} else {
1171+
cbm_collect_error_regions(root, &regs);
1172+
}
1173+
cbm_subtract_recovered_regions(&regs, &result->defs);
1174+
if (regs.count > 0) {
1175+
result->parse_incomplete = true;
1176+
result->error_region_count = regs.count;
1177+
result->error_ranges = cbm_error_ranges_str(a, &regs);
1178+
}
1179+
}
1180+
11111181
result->imports_count = result->imports.count;
11121182

11131183
// Accumulate profiling counters

‎src/cli/cli.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,10 +1789,13 @@ int cbm_remove_junie_mcp(const char *config_path) {
17891789

17901790
/* ── Claude Code pre-tool hooks ───────────────────────────────── */
17911791

1792-
/* Matcher intentionally excludes Read: gating Read breaks Claude Code's
1793-
* read-before-edit invariant (issue #362). The hook is a non-blocking
1794-
* augmenter, never a gate. */
1795-
#define CMM_HOOK_MATCHER "Grep|Glob"
1792+
/* Matcher includes Read for the indexing-coverage note (#963): when the agent
1793+
* reads a file the indexer could not fully cover, the hook injects a warning
1794+
* as additionalContext. The issue-#362 hazard (a GATING hook denying Read and
1795+
* breaking the read-before-edit invariant) cannot recur: the augmenter is
1796+
* structurally non-blocking — it always exits 0 and only ever ADDS context —
1797+
* mirroring the Gemini matcher, which already includes read_file. */
1798+
#define CMM_HOOK_MATCHER "Grep|Glob|Read"
17961799
/* Basename only; the full command path is resolved at install time via
17971800
* cbm_resolve_hook_command so $CLAUDE_CONFIG_DIR is honored. */
17981801
#define CMM_HOOK_GATE_SCRIPT "cbm-code-discovery-gate"
@@ -1805,7 +1808,7 @@ int cbm_remove_junie_mcp(const char *config_path) {
18051808
* Per-agent lists (no shared global): each caller passes its own. */
18061809
static const char *const cmm_claude_old_matchers[] = {
18071810
"Grep|Glob|Read|Search",
1808-
"Grep|Glob|Read",
1811+
"Grep|Glob", /* pre-#963 matcher — Read re-added for the coverage note */
18091812
NULL,
18101813
};
18111814
static const char *const cmm_gemini_old_matchers[] = {

0 commit comments

Comments
 (0)