Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
feat(decisions): flag a bundled claim on every capture path, not one lane (#2422)
Raghav Chamadiya6a3322939edb
diff --git a/packages/core/src/repowise/core/analysis/decisions/discovery/grounding.py b/packages/core/src/repowise/core/analysis/decisions/discovery/grounding.pyindex 08ffa7dc9..c223ed001 100644--- a/packages/core/src/repowise/core/analysis/decisions/discovery/grounding.py+++ b/packages/core/src/repowise/core/analysis/decisions/discovery/grounding.py@@ -14,6 +14,7 @@ from dataclasses import dataclass, fieldfrom typing import Anyfrom repowise.core.analysis.decisions.discovery.spans import ProseSpan+from repowise.core.analysis.decisions.lifecycle import bundles_decisionsfrom repowise.core.analysis.decisions.provenance import verify_quote__all__ = [@@ -39,10 +40,6 @@ _GENERIC_CLAIMS = (#: Below this a "decision" is a fragment, not a rule._MIN_DECISION_CHARS = 20-#: A claim joining independent choices is flagged, never split by machine: a-#: wrong split files one of them under the other's evidence.-_SPLIT_MARKERS = ("; ", " and also ", " and, ")-#: Dropped before scoring a claim against its spans. Without this a claim is#: carried by its function words: "always deploy to production on fridays"#: scores 2/6 on any span containing "to" and "on", which clears a 0.3 gate@@ -257,7 +254,6 @@ def _ground_one(else [])- low = decision.lower()return GroundedCandidate(title=title,decision=decision,@@ -268,5 +264,5 @@ def _ground_one(verification=verification,spans=spans,affected_files=tuple(dict.fromkeys(files)),- needs_split=any(marker in low for marker in _SPLIT_MARKERS),+ needs_split=bundles_decisions(decision),)diff --git a/packages/core/src/repowise/core/analysis/decisions/lifecycle.py b/packages/core/src/repowise/core/analysis/decisions/lifecycle.pyindex b1c32ae28..dedd75aa5 100644--- a/packages/core/src/repowise/core/analysis/decisions/lifecycle.py+++ b/packages/core/src/repowise/core/analysis/decisions/lifecycle.py@@ -25,9 +25,11 @@ __all__ = ["DECISION_STATUS_ORDER","NEEDS_REVIEW_STALENESS","REVIEW_LANES",+ "SPLIT_MARKERS","STORED_CURRENCIES","AcceptanceRequirement","acceptance_blockers",+ "bundles_decisions","currency_for_legacy_status","effective_currency","is_governing",@@ -74,6 +76,30 @@ CANDIDATE_REVIEW_STATES: tuple[str, ...] = ("dismissed",)+#: Punctuation that joins independent choices into one claim. A candidate+#: carrying any of them is flagged for review and never split by machine: a+#: wrong split files one decision under the other's evidence, which is a+#: harder mistake to see than a bundle nobody separated.+#:+#: Deliberately narrow, and measured that way over 357 records. The three+#: below flag 29; adding a bare ``" and "`` flags 194 of 357, which is 44% of+#: the store held out to catch one more bundle. The guard is partial on+#: purpose: the cost of a marker it misses is a merge a reviewer has to undo,+#: and the cost of one it invents is a decision that never merges at all.+SPLIT_MARKERS: tuple[str, ...] = ("; ", " and also ", " and, ")+++def bundles_decisions(text: str) -> bool:+ """Whether *text* joins what look like two independent choices.++ A pure function of the claim, so both capture lanes can ask it, and both+ must: the flag is what stops evidence-keyed identity from folding a+ bundled claim together with the separate decisions it bundles.+ """+ low = text.lower()+ return any(marker in low for marker in SPLIT_MARKERS)++#: The currencies a person or artifact can *set*. ``needs_review`` and#: ``uncheckable`` are also derived from the code by :func:`effective_currency`,#: which is why the stored set is smaller than the vocabulary.diff --git a/packages/core/src/repowise/core/persistence/crud/decisions.py b/packages/core/src/repowise/core/persistence/crud/decisions.pyindex 7ae33752e..74d50342f 100644--- a/packages/core/src/repowise/core/persistence/crud/decisions.py+++ b/packages/core/src/repowise/core/persistence/crud/decisions.py@@ -1314,10 +1314,17 @@ async def bulk_upsert_decisions(touched_ids.append(rec.id)# Two title groups can fold onto one record, so this accumulates:# the later group must not drop what the earlier one raised.+ #+ # The split flag is read from every member, not from the headline+ # alone. The headline is the highest-ranked source in the group, and+ # the lane that notices a claim bundles two decisions is usually not+ # the highest-ranked one: a session-mined candidate that flags itself+ # loses its flag the moment a CLI-authored record shares its title.+ # A flag raised by any contributor is a flag on the record.prior_lane, prior_split = captured.get(rec.id, ("", False))captured[rec.id] = (prior_lane or headline.get("lane") or "",- prior_split or bool(headline.get("needs_split")),+ prior_split or any(bool(d.get("needs_split")) for d in members),)# Mirror the JSON file/module arrays into first-class decision→codediff --git a/packages/core/src/repowise/core/sessions/miners/decisions.py b/packages/core/src/repowise/core/sessions/miners/decisions.pyindex 4143d40ff..05fd140d7 100644--- a/packages/core/src/repowise/core/sessions/miners/decisions.py+++ b/packages/core/src/repowise/core/sessions/miners/decisions.py@@ -59,6 +59,7 @@ import structlogfrom repowise.core.analysis.decisions.discovery.spans import SpanCollectorfrom repowise.core.analysis.decisions.extractor import ExtractedDecisionfrom repowise.core.analysis.decisions.kinds import classify_kind+from repowise.core.analysis.decisions.lifecycle import bundles_decisionsfrom repowise.core.analysis.decisions.policy import DEFAULT_HARNESSES, resolve_policyfrom repowise.core.analysis.decisions.provenance import (completeness,@@ -820,6 +821,15 @@ def promotion_decisions(),)sessions = row["sessions"][-_MAX_EVIDENCE_SESSIONS:] or [None]+ # Flagged here rather than at staging, for the same reason binding and+ # classification are: a row staged before the flag existed is judged on+ # its way out instead of staying unflagged forever, which is the whole+ # backlog. The discovery lane already decides this at grounding time, so+ # its answer is kept and only ever raised -- the two lanes ask the same+ # question of the same text and must not disagree by which ran first.+ needs_split = bool(structured.get("needs_split")) or bundles_decisions(+ structured.get("decision", "") or ""+ )# Classified here rather than at staging, for the same reason binding is:# a candidate staged before the split existed is classified on its way out# instead of staying one noun forever.@@ -844,7 +854,7 @@ def promotion_decisions(source_quote=structured.get("source_quote", ""),verification=structured.get("verification", "unverified"),lane=lane,- needs_split=bool(structured.get("needs_split")),+ needs_split=needs_split,)for sid in sessions]diff --git a/tests/unit/analysis/test_decision_authority_containment.py b/tests/unit/analysis/test_decision_authority_containment.pyindex 65cea468f..0a6e86273 100644--- a/tests/unit/analysis/test_decision_authority_containment.py+++ b/tests/unit/analysis/test_decision_authority_containment.py@@ -260,6 +260,45 @@ class TestPromotionCarriesTheReviewLane:assert all(d.needs_split for d in promotion_decisions(row, Path(".")))+class TestBundledClaimsAreFlaggedOnEveryLane:+ """The detector ran only in the broad lane, which is off, so it never ran.++ Every record in the dogfood store carried ``needs_split=False``, including+ the ones that visibly bundle two decisions. Evidence-keyed identity folds+ a bundled claim together with the separate decisions it bundles, so the+ flag has to be set wherever a candidate is captured, not in one lane.+ """++ def test_a_marker_in_the_decision_text_raises_the_flag(self):+ row = _row(kind="user_correction")+ row["structured"]["decision"] = "Enable WAL; set a bounded busy timeout"++ assert all(d.needs_split for d in promotion_decisions(row, Path(".")))++ def test_an_unbundled_decision_is_not_flagged(self):+ assert not any(d.needs_split for d in promotion_decisions(_row(), Path(".")))++ def test_a_bare_conjunction_is_not_a_marker(self):+ """Widening to ``" and "`` flags 194 of 357 records and is not shipping."""+ row = _row()+ row["structured"]["decision"] = "Enable WAL and a bounded busy timeout"++ assert not any(d.needs_split for d in promotion_decisions(row, Path(".")))++ def test_a_flag_the_broad_lane_set_survives_prose_that_carries_no_marker(self):+ row = _row(kind="session_discovery")+ row["structured"]["decision"] = "Enable WAL and a bounded busy timeout"+ row["structured"]["needs_split"] = True++ assert all(d.needs_split for d in promotion_decisions(row, Path(".")))++ def test_a_row_with_no_decision_text_at_all_is_not_flagged(self):+ row = _row()+ row["structured"]["decision"] = None++ assert not any(d.needs_split for d in promotion_decisions(row, Path(".")))++class TestScopeNamesOnlyIndexedCode:"""A record is delivered as a rule about the files it names."""diff --git a/tests/unit/persistence/test_decision_candidate_meta_capture.py b/tests/unit/persistence/test_decision_candidate_meta_capture.pyindex d48d3a23c..ff8a01dbb 100644--- a/tests/unit/persistence/test_decision_candidate_meta_capture.py+++ b/tests/unit/persistence/test_decision_candidate_meta_capture.py@@ -202,6 +202,28 @@ async def test_needs_split_survives_a_capture_that_does_not_claim_it(async_sessiassert meta.needs_split is True+async def test_a_split_flag_from_any_contributor_reaches_the_record(async_session):+ """The headline is the highest-ranked source; the flag is rarely on it.++ ``cli`` outranks ``session``, so a manually authored record sharing a+ title with a session-mined bundled one is the headline, and reading the+ flag off the headline alone drops what the mining lane noticed.+ """+ repo = await insert_repo(async_session)+ await bulk_upsert_decisions(+ async_session,+ repo.id,+ [+ _decision("Two choices", source="cli", confidence=0.9),+ _decision("Two choices", source="session", needs_split=True),+ ],+ )++ rec = await _record(async_session, "Two choices")+ meta = await async_session.get(DecisionCandidateMeta, rec.id)+ assert meta is not None and meta.needs_split is True++async def test_the_scope_flag_agrees_with_the_contract_on_blank_entries(async_session):"""A scope list of one empty string is no scope, and both readers say so."""repo = await insert_repo(async_session)