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(generation): say when a standing decision was not signed by a person (#2458)
Raghav Chamadiya50ae7dc54f8a
diff --git a/packages/core/src/repowise/core/generation/editor_files/data.py b/packages/core/src/repowise/core/generation/editor_files/data.pyindex bb40a4c33..fbaf410d6 100644--- a/packages/core/src/repowise/core/generation/editor_files/data.py+++ b/packages/core/src/repowise/core/generation/editor_files/data.py@@ -56,6 +56,9 @@ class DecisionSummary:status: str # active | deprecated | superseded | proposedrationale: str # first ~100 chars of decision.rationaledecision: str = "" # what was chosen (first ~120 chars)+ #: Pre-rendered mark for a line a person did not sign, else "". Empty in+ #: the ordinary case, so the common line costs no extra tokens.+ signed_by: str = ""@dataclass(frozen=True)diff --git a/packages/core/src/repowise/core/generation/editor_files/fetcher.py b/packages/core/src/repowise/core/generation/editor_files/fetcher.pyindex 88f539152..784fb11dc 100644--- a/packages/core/src/repowise/core/generation/editor_files/fetcher.py+++ b/packages/core/src/repowise/core/generation/editor_files/fetcher.py@@ -50,6 +50,24 @@ _MAX_HOTSPOTS = 5_MAX_DECISIONS = 8+def _signed_by(signature) -> str:+ """The mark for a decision a person did not sign, else ``""``.++ An agent reads this block as standing rules, so one it accepted itself has+ to be legible as that rather than as the team's. A person's acceptance is+ the ordinary case and is left unmarked, which is also what keeps the line+ cheap: these files are read into every session.+ """+ if signature is None or signature.kind == "person":+ return ""+ if signature.kind == "agent":+ who = signature.accepter or "an agent"+ return f" [accepted by {who}, not a person]"+ if signature.kind == "import":+ return " [accepted by a tracked file]"+ return " [signer not recorded]"++class EditorFileDataFetcher:"""Fetches all data needed to render an editor-file template."""@@ -282,9 +300,15 @@ class EditorFileDataFetcher:An agent reads this block as instructions, so it is the surface wherethe candidate/decision distinction matters most: acceptance, not astatus string a recurrence check wrote, is what earns a line here.++ It is also where an agent can read back its own acceptance as the+ team's rule, so a line a person did not sign says so."""from repowise.core.exclusion import build_exclude_spec, decision_is_excluded- from repowise.core.persistence.crud.authority import accepted_predicate+ from repowise.core.persistence.crud.authority import (+ accepted_predicate,+ decision_signatures,+ )result = await self._session.execute(select(DecisionRecord)@@ -302,18 +326,16 @@ class EditorFileDataFetcher:records = [r for r in result.scalars().all() if not decision_is_excluded(r, exclude_spec)][:_MAX_DECISIONS]+ signatures = await decision_signatures(self._session, self._repo_id, records)summaries: list[DecisionSummary] = []for rec in records:- rationale = (rec.rationale or "").strip()- rationale = rationale[:100].rstrip(".,;") if rationale else ""- decision_text = (rec.decision or "").strip()- decision_text = decision_text[:120].rstrip(".,;") if decision_text else ""summaries.append(DecisionSummary(title=rec.title,status=rec.status,- rationale=rationale,- decision=decision_text,+ rationale=_truncate_at_word(rec.rationale or "", 100),+ decision=_truncate_at_word(rec.decision or "", 120),+ signed_by=_signed_by(signatures.get(rec.id)),))return summariesdiff --git a/packages/core/src/repowise/core/generation/templates/agents_md.j2 b/packages/core/src/repowise/core/generation/templates/agents_md.j2index 10629ba9c..a3eba654b 100644--- a/packages/core/src/repowise/core/generation/templates/agents_md.j2+++ b/packages/core/src/repowise/core/generation/templates/agents_md.j2@@ -60,7 +60,7 @@ Critical files:### Standing decisions (ask `get_why` before diverging){% for d in data.decisions[:3] %}-- {{ d.title }}{% if d.rationale %} — {{ d.rationale }}{% endif %}+- {{ d.title }}{{ d.signed_by }}{% if d.rationale %} — {{ d.rationale }}{% endif %}{% endfor %}{% endif %}diff --git a/packages/core/src/repowise/core/generation/templates/claude_md.j2 b/packages/core/src/repowise/core/generation/templates/claude_md.j2index 044521123..eee5854a8 100644--- a/packages/core/src/repowise/core/generation/templates/claude_md.j2+++ b/packages/core/src/repowise/core/generation/templates/claude_md.j2@@ -60,7 +60,7 @@ Critical files:### Standing decisions (ask `get_why` before diverging){% for d in data.decisions[:3] %}-- {{ d.title }}{% if d.rationale %} — {{ d.rationale }}{% endif %}+- {{ d.title }}{{ d.signed_by }}{% if d.rationale %} — {{ d.rationale }}{% endif %}{% endfor %}{% endif %}diff --git a/tests/unit/generation/test_editor_fetcher_helpers.py b/tests/unit/generation/test_editor_fetcher_helpers.pyindex 7d05941e6..5fe5ddff0 100644--- a/tests/unit/generation/test_editor_fetcher_helpers.py+++ b/tests/unit/generation/test_editor_fetcher_helpers.py@@ -9,6 +9,7 @@ from __future__ import annotationsfrom repowise.core.generation.editor_files.fetcher import (_extract_sentences,+ _signed_by,_truncate_at_word,)@@ -93,3 +94,45 @@ class TestTruncateAtWord:def test_exact_limit_unchanged(self) -> None:text = "x" * 80assert _truncate_at_word(text, 80) == text+++class TestSignedBy:+ """A line a person did not sign says so, and costs nothing when they did.++ These files are read into every session, so the mark has to be absent in+ the ordinary case rather than merely short.+ """++ @staticmethod+ def _sig(kind: str, accepter: str = ""):+ from repowise.core.persistence.crud.authority import AcceptanceSignature++ return AcceptanceSignature(kind=kind, accepter=accepter, artifact="", session="")++ def test_a_person_costs_no_tokens(self) -> None:+ assert _signed_by(self._sig("person", "Raghav")) == ""++ def test_a_candidate_costs_no_tokens(self) -> None:+ # Belt and braces: the fetcher only selects accepted records.+ assert _signed_by(None) == ""++ def test_an_agent_is_named_as_one(self) -> None:+ """The block reads as standing rules, so an agent must not find its+ own acceptance there presented as the team's."""+ mark = _signed_by(self._sig("agent", "claude_code"))++ assert "claude_code" in mark+ assert "not a person" in mark++ def test_an_agent_with_no_name_still_says_it_was_one(self) -> None:+ assert "an agent" in _signed_by(self._sig("agent"))++ def test_an_import_is_marked_but_not_called_an_agent(self) -> None:+ mark = _signed_by(self._sig("import", "adr/0001.md"))++ assert mark and "agent" not in mark++ def test_an_unrecorded_kind_is_not_silently_a_person(self) -> None:+ # A row written before provenance existed. Rendering nothing would+ # claim a human signed it.+ assert _signed_by(self._sig("")) == " [signer not recorded]"diff --git a/tests/unit/generation/test_editor_file_fetcher.py b/tests/unit/generation/test_editor_file_fetcher.pyindex 46269153a..062f3b2e1 100644--- a/tests/unit/generation/test_editor_file_fetcher.py+++ b/tests/unit/generation/test_editor_file_fetcher.py@@ -138,7 +138,9 @@ async def _add_git_meta(return gm-async def _add_decision(session, repo_id, title, status="active", rationale="Some reason"):+async def _add_decision(+ session, repo_id, title, status="active", rationale="Some reason", **accept+):"""Add a record, accepting it when the caller wants one that governs.The generated block serves accepted decisions, so a fixture that only sets@@ -163,7 +165,8 @@ async def _add_decision(session, repo_id, title, status="active", rationale="Somif status == "active":from repowise.core.persistence.crud.authority import accept_decision- await accept_decision(session, dr, accepter="tester")+ accept.setdefault("accepter", "tester")+ await accept_decision(session, dr, **accept)return dr@@ -392,6 +395,57 @@ async def test_a_candidate_never_reaches_the_generated_block(session, repo, tmp_assert [d.title for d in data.decisions] == []+async def test_a_person_signed_line_carries_no_mark(session, repo, tmp_path):+ """The ordinary case, and the one that must stay free.++ These files are read into every session, so the signature costs tokens+ only where it changes what the line means.+ """+ await _add_decision(session, repo.id, "Use JWT", accepter="Raghav", kind="person")+ await session.commit()++ data = await EditorFileDataFetcher(session, repo.id, tmp_path).fetch()++ assert [d.signed_by for d in data.decisions] == [""]+++async def test_an_agent_signed_line_says_a_person_did_not(session, repo, tmp_path):+ """Otherwise an agent reads its own acceptance back as a standing rule."""+ await _add_decision(+ session,+ repo.id,+ "Use JWT",+ accepter="claude_code",+ kind="agent",+ agent_acceptance=True,+ )+ await session.commit()++ data = await EditorFileDataFetcher(session, repo.id, tmp_path).fetch()++ mark = data.decisions[0].signed_by+ assert "claude_code" in mark and "not a person" in mark+++async def test_the_mark_reaches_both_generated_files(session, repo, tmp_path):+ """The template carries it, not only the summary."""+ from repowise.core.generation.editor_files import AgentsMdGenerator, ClaudeMdGenerator++ await _add_decision(+ session,+ repo.id,+ "Use JWT",+ accepter="claude_code",+ kind="agent",+ agent_acceptance=True,+ )+ await session.commit()+ data = await EditorFileDataFetcher(session, repo.id, tmp_path).fetch()++ for gen in (ClaudeMdGenerator(), AgentsMdGenerator()):+ assert "not a person" in gen.render_full(tmp_path, data), type(gen).__name__++async def test_an_accepted_agreement_reaches_the_generated_block(session, repo, tmp_path):"""A working agreement rides the instructions file unchanged.