Repository navigation
Description
Part of #1341.
Context
packages/core/src/queries/graph.ts (492 lines, "Private UI-profile graph mechanics", used by ./queries) and packages/core/src/lib/graph/queries.ts (490 lines, used by brain graph) read the same tables and repeat constants (MAX_DISCOVERY_DEPTH = 8, DEFAULT_STALE_DAYS = 180). They differ in places: the UI profile clamps staleDays to 1..3650 (packages/core/src/queries/graph.ts:438), the CLI does not (packages/core/src/lib/graph/queries.ts:360). The CLI reader's header says ui-server keeps its own reader because it "deliberately does not depend on core" (packages/core/src/lib/graph/queries.ts:1-7), which is no longer true: both readers live in core.
Approved approach — 2026-10-09
A: one internal graph reader with explicit CLI/UI profiles. Consolidate common graph reading/traversal mechanics inside core. Keep the two existing surface adapters and public result types; each explicitly selects its internal profile. Profiles encode existing behavior, not a new extension interface or public configuration.
Preserve all current differences unless separately ruled: UI caps/truncation, ordering, precomputation/schema gates, missing-node errors, isolate defaults and staleDays clamping versus CLI defaults/degradation. The issue's two equal-size readers are not interchangeable; the implementation must inventory differences from source and use profile-specific tests before replacing either path. No behavior unification is authorized.
Scope
- Implement one internal graph reader and explicit concrete CLI/UI profiles, with thin existing adapters retaining their result shapes and ownership. Define shared constants once; fix the header to explain the actual profile differences. Preserve the supported query API’s root-bound read snapshots/native connection lifetime and the CLI’s existing resolved-database use. No core-to-UI dependency, raw-handle public export or configurable reader seam.
Out of scope
- Changing
./queriesresult shapes, errors, ordering, caps, defaults orbrain graph --jsonbehavior. Public graph semantics remain bound by docs/decisions/index-query-api.md and docs/content-index-queries.md. - Unifying profile behavior, exposing profile selection publicly, or changing graph computation/storage.
Acceptance criteria
- Constants are defined once.
- The header comment states the actual reason for any remaining split.
- Both adapters call the one internal reader with the intended explicit profile; no duplicated complete traversal/reader remains under the old paths.
- Inventory and independently assert profile differences on nonempty fictional fixtures: caps/truncation, ordering, isolate defaults, missing center/root, absent/old/uncomputed graph, and staleDays bounds/default. UI and CLI keep their former expected behavior; do not derive expected values from the new shared implementation.
- Existing graph contracts and real index-query consumer tests pass unchanged, including snapshot/replacement/error lifetime coverage. A swapped-profile or removed profile guard mutation fails the intended distinction assertion; restore it afterward.
- Published exports/types and package boundaries remain unchanged; normal consumer resolution still works.
Verification
bun run test packages/coreContract impact
No supported contract change: this is an internal behavior-preserving consolidation. Add the normal refactor changeset. If the source inventory reveals a desired public behavior change, report it for a separate maintainer ruling rather than folding it into this refactor.
Triage recommendation — 2026-10-09
Recommend B: share established constants/primitives while keeping separate profiles until their differing behavior is explicitly reviewed. A reduces duplication further but can unintentionally collapse intentional surface differences. A ruling should name which differences are contractual and which may converge. This is a recommendation for the maintainer, not approval; keep the unresolved need.
2026-10-09 maintainer ruling: selected A, consolidated the explicit profile constraints and verification criteria, and removed the decision prerequisite. Preserve p3 and epic #1341; add agent-ready for implementation.
Activity
schlessera commentedon Oct 9, 2026
Decision (maintainer, 2026-10-09): Choose A — one internal reader with explicit CLI/UI profiles.
Consolidate common graph mechanics inside core while retaining the existing adapters, public result types and each profile’s behavior. Preserve caps, ordering, errors, precomputation/degradation, isolate defaults and staleDays policies; this is not approval to unify those contracts. Profiles are concrete internal choices, not a public extension seam. Correct the obsolete dependency comment.
The body now requires a source-based difference inventory, independent profile tests and a profile mutation, alongside unchanged graph/query consumer contracts and snapshot ownership. No decision remains; remove
needs: decisionand addagent-ready, preserving p3 and #1341.schlessera commentedon Oct 21, 2026
New evidence from a repository review on 2026-10-22, at main
dcf5341aa, for the profile-difference inventory this issue requires:packages/core/src/lib/graph/queries.tshard-codestruncated: false: lines 202, 223, 244, 271, 291 and 330. The explicit-root discovery walk (getDiscoveryGraph,packages/core/src/lib/graph/queries.ts:260-292) has no node budget at all. It BFS-es up toMAX_DISCOVERY_DEPTHhops and returns every reached node.MAX_NODES = 5000(packages/core/src/queries/graph.ts:6,bfs(..., MAX_NODES)at:376,applyCapsat:378) and reportstruncated(:385).brain graph exportdocuments its output as{nodes, edges, truncated}(docs/cli.md:167). On the CLI profile, thetruncatedfield cannot be true.Under the 2026-10-09 ruling this difference must be preserved by the consolidation, so this comment is not a scope change. It is one more row for the inventory test ("caps/truncation"). Whether the CLI should cap discovery output and report truncation is a separate public-behaviour question that needs its own maintainer ruling. Do not fold it into this refactor.
schlessera commentedon Nov 2, 2026
Claimed (claim-1341-1354-9b111c56) as part of the #1341 integration lane. Branch
refactor/1354-graph-reader-profiles, targeting the epic integration branchepic/1341-shared-core-ops; the epic branch merges intomainin one go once every ready child has landed there.test(core): inventory the CLI and UI graph reader profiles
refactor(core): read the graph through one reader with CLI and UI pro…
refactor(core): read the graph through one reader with CLI and UI pro…
schlessera commentedon Nov 3, 2026
Delivered on
mainby the epic #1341 landing, #3505: merge commit06473ef31, parents559fe7b41(main) andbd2decac7(epic tip). This issue's change is #3295, squashed into the epic branch as44be369b9after passing readyproofon its exact head against the epic tip. The acceptance criteria and failing-first/mutation receipts are in that PR. Milestone 0.45.0. Closing manually: closing keywords do not fire for PRs that target a non-default branch.