Module change_context
Expand description
Temporal pre-write briefing: what an agent should know about a set of files before it edits them.
build_change_context assembles a compact, deterministic text briefing
for 1–MAX_BRIEFING_PATHS repo-relative paths. Like
crate::enrichment::fact_sheet, it never computes anything new: it runs
the existing analyses once for the whole batch (run_code_health,
run_hotspots, run_coupling, owner_activity_for_paths, plus a windowed
churn query), then picks each path’s values and renders them. It only
reads the fact store — it never writes to it and never perturbs any
analysis output.
§Determinism
Two builds over the same fact store produce byte-identical text: every
float renders through a fixed rounding, blocks appear in request order, and
nothing iterates a HashMap into the output (co-change partners are sorted
into a Vec during assembly; per-path owner / churn data is looked up by
key, never enumerated).
§Rendered format (the output contract)
When the repository is partway through a merge / rebase / cherry-pick /
revert (Repo::merge_or_rebase_in_progress), one leading note precedes
everything, separated from the first block by a blank line:
note: merge/rebase in progress — briefing reflects committed HEAD historyEach requested path renders one block; blocks are separated by a single
blank line. A path with recorded history renders five indented lines, plus
an optional sixth → next-action line:
crates/codelore-lib/src/cache.rs
health 67.3 (yellow) · risk 0.42 · calibrated defects-2026-07-15
hotspot #12 (score 0.67, 23 revs)
co-change: options.rs (68%, p=0.003) · facts/mod.rs (54%, p=0.011)
owner: Emre Camdere 82% (sole owner, active 12d ago)
recent: 4 commits, 310 lines churned in last 90d
→ historically co-changes with options.rs — consider the same edit thereEach line falls back to an honest-absence form when its data is missing:
health— score to one decimal + band,risk(structural_risk) to two decimals, and a calibration suffix (calibrated <vintage>fromactive_vintage, elseuncalibrated). A path with no code-health row but some other history rendershealth: no code-health row.hotspot #<rank> (score <score>, <revs> revs)—rankis the 1-based position in the un-row-limited hotspot ranking; a path outside the ranking rendersnot in the hotspot set.co-change:— up to three partners withshared >= DEFAULT_MIN_SHARED_REVSandfisher_p < DEFAULT_FISHER_SIGNIFICANCE, sorted bydegreedescending then partner path ascending; when more partners clear the filter than are rendered, the line ends with(+n more)disclosing the overflow count; none rendersco-change: none significant.owner:— main author, ownership share,sole owner/sharedconcentration, anddeparted <n>dwhendays_since_main_activeexceedsdeparted_threshold_days(elseactive <n>d ago). A path with no attributable ownership rendersowner: inconclusive.recent:— commit count + churned lines over the lastwindow_days; a path untouched in the window rendersrecent: quiet in last <window_days>d.new-code:(optional, before the action line) — rendered only when the repo declares a[new_code]section AND the path is inside its window:born in the last <n>d(first seen in the window) ortouched in the last <n>d(touched, first seen earlier), each with the obligation that band implies. Absent the section, or for a path outside the window, no line renders — a repo without[new_code]is byte-identical to before.→(optional final line) — a single next action derived from the picked values: co-change partners surface the top partner to edit alongside; with no partners, a main author pastdeparted_threshold_dayssurfaces a knowledge-continuity flag. A block with neither carries no action line.
A path absent from every feed — no code-health row, not in the hotspot ranking, no significant co-change partners, no attributable ownership, and untouched in the churn window (a brand-new, untracked, or mistyped path) — renders a two-line block instead:
brand/new.rs
no history at HEAD (new or untracked file)Constants§
- MAX_
BRIEFING_ PATHS - Maximum number of paths a single briefing accepts. Keeps the assembled text within the tool’s token budget and bounds the per-batch query cost.
Functions§
- build_
change_ context - Assemble and render the pre-write briefing for
paths.