# 19. A product tree over the code graph, measured before it is trusted

**Status:** Accepted (ships off; M0 verdict NO-GO) · 2026-11-02 · extends [ADR-0010](./0010-own-code-graph.md)

## Context

A bug report is written in the words a person saw: a button label, a screen,
a step in a flow. The code graph (ADR-0010) knows files and symbols, and it
scored 63% on questions phrased in domain words against near-perfect scores
on questions that named a type. The gap is the vocabulary between the two.

The proposed answer is a screen layer joined over the graph: localized text,
string key, route, screen, the files a screen owns, the endpoints it calls,
the tests that name it. The literature on bug localization (BM25F over
structured fields, query expansion through UI strings, graph-seeded ranking)
reports gains from exactly these joins, but on other corpora and with other
baselines. Before the pipeline relies on such a layer, it has to beat the
graph it sits on, on bugs it has not been tuned on.

## Decision

Build the layer deterministically, keep it local, and gate its use on a
measurement.

- `pipeline/scripts/product-tree.mjs build` derives
  `~/.claude/knowledge/<project>/product-tree.json` (0600, never shipped)
  without a model. SwiftUI: views named Screen, Scene or Page, every
  navigation target (links by destination, closure and value,
  `navigationDestination` over a route enum, sheets, covers, stack roots,
  tabs, scenes) and coordinators that host a view, which become flow nodes.
  Compose: `composable`, `dialog`, `bottomSheet` and Navigation 3 `entry`
  registrations, `@Serializable` route types, start destinations, one hop
  through a wrapper composable. Web: Next.js `app/` and `pages/` routes when a
  `package.json` depends on Next, app router API handlers, react-router tables
  and `<Route>` elements. Strings from `.strings`, `.xcstrings`,
  `strings.xml` and i18n JSON; endpoints from Retrofit annotations, route
  handlers and API-shaped literals; tests by the screen names they contain.
- Programmatic navigation is counted and each call is resolved only when its
  argument is a literal route or a view constructor. The rest are listed with
  file and line. Coverage is reported per stack, never assumed.
- `locate` ranks files under three arms that share one implementation with the
  evaluation: BM25F over names, symbols and directories; the same plus query
  expansion through matched UI strings, a UI-string ranking, personalized
  PageRank over the import and reference edges, Turkish-aware folding and
  stemming, and identifier splitting; and the screen layer on top.
- The model only proposes, with evidence that resolves to a line of a
  regular file inside the repository, into an append-only overlay. Proposing
  the same thing again leaves an earlier decision in place. `agree` and
  `reject` are refused in an unattended run and without a terminal. The
  terminal check stops a piped shell but not an agent that allocates a
  pseudo-terminal, so agent-guard is the layer that asks before an agent's
  `agree` or `reject` and refuses a file tool aimed at the overlay. No
  ranking reads the overlay yet: agreed rows are planned to feed `locate` in
  M2.
- The repository is untrusted input. The build reads only regular files
  inside the root, up to the same 2 MB limit the evaluation uses, never
  through a symlink; every git call turns off the repository's fsmonitor,
  hooks, external diff, pager, signature checks and gpg programs, and reads
  no global or system config. `locate` and `show` print their result inside
  one untrusted-data block. A repository listed in
  `prefs.global.memory.excludeProjects` gets no tree.
- `prefs.global.productTree.enabled` defaults to `false`. When on, Phase 0
  locates the task and Phase 1 injects the result, cut by `fitToBudget` to
  `productTree.maxChars` (6,000).

## Measurement

This measurement is the M0 gate; M1 is the Phase 0/1 wiring; M2 is derived flows and agreed overlay rows read by locate.

`product-tree-eval.mjs` mines bug-fix commits from git history, rebuilds the
graph and the tree at each fix commit's parent from git objects, ranks files
for the commit subject (conventional prefix and PR number removed) and scores
them against the production files the fix modified. Every arm is cut to the
same 6,000-character budget before scoring. Bugs are split by time per
repository: ranking settings were grid-searched on the older half only, and
the verdict is read from the newer half. Bugs whose text already names a file,
symbol or stack frame are reported apart.

Corpus: nine repositories, of which eight yielded qualifying fixes, 60 per
repository (480 bugs): two Node tooling repositories, three web applications
(two Next.js, one React single-page app), one Compose app, one SwiftUI macOS
app and one iOS app that mixes SwiftUI with UIKit.

Held-out, domain-text bugs (n = 230), recall@10 with a 95% bootstrap interval:

| Arm   | Acc@1 | Acc@5 | Acc@10 | R@1   | R@5   | R@10                  | MRR   | Mean chars |
| ----- | ----- | ----- | ------ | ----- | ----- | --------------------- | ----- | ---------- |
| bm25  | 29.1% | 50.4% | 57.4%  | 19.5% | 38.6% | 45.7% [40.1, 51.1]    | 0.393 | 2,552      |
| graph | 29.1% | 51.3% | 58.3%  | 19.5% | 39.5% | 47.1% [41.3, 52.8]    | 0.396 | 4,014      |
| tree  | 27.8% | 50.4% | 57.8%  | 19.2% | 39.1% | 46.5% [40.9, 52.3]    | 0.382 | 4,038      |

Tree against graph: hit@10 discordant pairs 3 (graph only) and 2 (tree only),
exact McNemar p = 1.0; recall@10 difference -0.6 points, interval
[-1.5, +0.4]. Per repository the tree arm was lower than the graph arm on
four of eight (between -1.2 and -2.0 points), equal on three and higher on
one (+1.7, the SwiftUI macOS app). On the development half the tuned tree arm led
the graph arm by 0.8 points (46.3% against 45.5%, n = 220), which did not
survive to the held-out half. The ten held-out bugs that name code scored
54.5% under bm25 and graph and 42.0% under the tree.

Screen-index coverage at each repository's head: Compose 5 of 6 screens
reachable, 3 of 4 programmatic calls resolved; SwiftUI macOS 16 of 28
reachable, 0 of 22 programmatic; the mixed iOS app 45 of 92 reachable, 8 of
25 enum routes with a screen, 0 of 286 programmatic calls resolved (almost all
UIKit pushes and presents of view controllers); web apps reach every screen by
construction, since a web screen is a route target, and resolved 20% to 40% of
programmatic navigation calls.

**Verdict: NO-GO.** The rule was a recall@10 lift of at least 15 points,
McNemar p below 0.05 and no repository regressing. None of the three held.

## Consequences

- The tree ships off. Nothing in a default run builds or reads it.
- The non-tree signals (UI-string expansion and boost, PageRank) gave 1.4
  points over plain BM25F on held-out bugs, inside the noise. They are not
  moved into graph-query on this evidence.
- iOS programmatic navigation is the measured weak point: an app that
  navigates through UIKit coordinators has half its screens unreachable and
  no resolved programmatic call. Flows (M2) cannot be derived for such apps
  from regex alone.
- Commit subjects are short and written by the developer who fixed the bug;
  they are a weaker proxy for a user's report than issue text. A rerun with
  linked issue bodies, and the optional issue-text-only memorization arm
  (`--issue-text-arm`), is the next measurement before any re-decision.
- 41.7% of held-out bugs had no changed file in the top 10 under the best
  arm. That is a candidate-recall question; it was not measured past k = 10
  here.
- The per-bug rows and repository names stay in the harness's report under
  `~/.claude/knowledge/_eval/` (0600); this ADR carries only pooled numbers
  and repository kinds.

## Alternatives considered

- **A model-written tree.** Generated repository summaries have lowered agent
  success in published measurements, and a node nobody can re-derive is an
  assertion. The model may propose with evidence; it never writes fact.
- **Embeddings for the screen match.** Not tried: an embedding model arrives
  as a runtime package or a hosted service, and ADR-0004 keeps runtime
  packages out of the published package. This measurement did not test
  whether they would close the candidate-recall gap; see Consequences.
- **Shipping on by default on the development-half result.** The 0.8-point
  development lead is the kind of result the time split exists to catch.
