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
fix(decisions): correct refusal guidance (#4719)
MvMSOLO2d469ef28d5c
diff --git a/packages/cli/src/repowise/cli/commands/decision_cmd.py b/packages/cli/src/repowise/cli/commands/decision_cmd.pyindex eec004247..25724473f 100644--- a/packages/cli/src/repowise/cli/commands/decision_cmd.py+++ b/packages/cli/src/repowise/cli/commands/decision_cmd.py@@ -34,10 +34,16 @@ from repowise.cli.helpers import (from repowise.cli.output import emit_json, emit_refusal, format_option, notice_consolefrom repowise.cli.worktree import detect_worktree_basefrom repowise.core.analysis.decisions.lifecycle import (+ AGENT_ACCEPTANCE_DISABLED_BLOCKER,AGENT_ACCEPTANCE_REMEDY,AGREEMENT_KIND,ARCHITECTURAL_KIND,DECISION_KINDS,+ NO_ACCEPTANCE_IDENTITY_BLOCKER,+ NO_DECISION_BLOCKER,+ NO_EVIDENCE_BLOCKER,+ NO_RATIONALE_BLOCKER,+ NO_SCOPE_BLOCKER,)from repowise.core.analysis.decisions.provenance import LISTABLE_SOURCESfrom repowise.core.precedent.currency import describe_decision_currency@@ -857,6 +863,28 @@ def _decision_body_lines(rec) -> list[str]:#: The remedy printed beside a refused acceptance, naming the flags that#: supply what the contract found missing._ACCEPT_REMEDY = "Supply the missing parts with --decision, --reason, --scope or --evidence."+_ACCEPT_IDENTITY_REMEDY = "Name the signer with --as <name> or --agent <slug>."+++def _accept_remedy_for_blockers(blockers: list[str]) -> str:+ """Return only the remedies that address the blockers in this refusal."""+ remedies = []+ if any(AGENT_ACCEPTANCE_DISABLED_BLOCKER in blocker for blocker in blockers):+ remedies.append(AGENT_ACCEPTANCE_REMEDY)+ if NO_ACCEPTANCE_IDENTITY_BLOCKER in blockers:+ remedies.append(_ACCEPT_IDENTITY_REMEDY)+ if any(+ blocker+ in {+ NO_DECISION_BLOCKER,+ NO_RATIONALE_BLOCKER,+ NO_SCOPE_BLOCKER,+ NO_EVIDENCE_BLOCKER,+ }+ for blocker in blockers+ ):+ remedies.append(_ACCEPT_REMEDY)+ return " ".join(remedies)@decision_group.command("confirm")@@ -941,11 +969,12 @@ def decision_confirm(repo_path, ids, action="accepted", verb="accept", preview=preview, apply_one=_accept))- # Both, not either: one run can refuse one id for the policy and another- # for a missing scope.- remedy = _ACCEPT_REMEDY- if agent and not granted:- remedy = f"{AGENT_ACCEPTANCE_REMEDY} {remedy}"+ blockers = [+ blocker+ for result in results+ for blocker in result.get("blockers", [])+ ]+ remedy = _accept_remedy_for_blockers(blockers)if len(ids) > 1 or preview or fmt == "json":_emit_batch(results, "accepted", "accept", preview, fmt, remedy)returndiff --git a/packages/cli/src/repowise/cli/commands/decision_config_cmd.py b/packages/cli/src/repowise/cli/commands/decision_config_cmd.pyindex 01153b558..65bf6621c 100644--- a/packages/cli/src/repowise/cli/commands/decision_config_cmd.py+++ b/packages/cli/src/repowise/cli/commands/decision_config_cmd.py@@ -122,6 +122,7 @@ def _emit(repo_path: Path, resolution, fmt: str) -> None:)if policy.capture_prompt:from repowise.cli.editor_integrations.claude_config import (+ _claude_code_settings_path,claude_code_capture_hook_installed,)@@ -135,12 +136,17 @@ def _emit(repo_path: Path, resolution, fmt: str) -> None:"so it stays silent. `decision config enable` to use it.[/yellow]")elif not claude_code_capture_hook_installed():- # The flag is per repository and the hook is per install, so the- # two drift: a settings file from before the entry shipped lacks it.- console.print(- " [yellow] ...but no shell hook is installed to fire it. "- "Re-run `decision config capture-prompt --on`.[/yellow]"- )+ if not _claude_code_settings_path().is_file():+ console.print(+ "[yellow] ...but no Claude Code settings file was found to install the shell "+ "hook into, so nothing will fire it. Run `repowise init` or install the "+ "editor integration first.[/yellow]"+ )+ else:+ console.print(+ "[yellow] ...but no shell hook is installed to fire it. "+ "Re-run `repowise decision config capture-prompt --on`.[/yellow]"+ )else:console.print(" [dim]Capture prompt: off. Nothing asks an agent to record a decision.[/dim]")console.print("")diff --git a/packages/core/src/repowise/core/analysis/decisions/lifecycle.py b/packages/core/src/repowise/core/analysis/decisions/lifecycle.pyindex fd791775f..e26f6f89f 100644--- a/packages/core/src/repowise/core/analysis/decisions/lifecycle.py+++ b/packages/core/src/repowise/core/analysis/decisions/lifecycle.py@@ -20,6 +20,7 @@ __all__ = ["ACCEPTANCE_ACTIONS","ACCEPTER_KINDS","ACCEPTER_SESSION_MAX",+ "AGENT_ACCEPTANCE_DISABLED_BLOCKER","AGENT_ACCEPTANCE_REMEDY","AGREEMENT_KIND","AGREEMENT_SCOPE",@@ -31,7 +32,10 @@ __all__ = ["GRANTING_ACTIONS","HISTORY_CURRENCIES","NEEDS_REVIEW_STALENESS",+ "NO_ACCEPTANCE_IDENTITY_BLOCKER","NO_DECISION_BLOCKER",+ "NO_EVIDENCE_BLOCKER",+ "NO_RATIONALE_BLOCKER","REVIEW_LANES","SPLIT_MARKERS","STORED_CURRENCIES",@@ -182,6 +186,7 @@ ACCEPTANCE_ACTIONS: tuple[str, ...] = (#: Actions that create or renew authority, against the ones that withdraw it.GRANTING_ACTIONS: frozenset[str] = frozenset({"accepted", "reaffirmed", "merged"})+_GRANTING_ACTION_VERBS = {"accepted": "accept", "reaffirmed": "reaffirm", "merged": "merge"}#: Who signed an acceptance. ``person`` is a human, ``agent`` a coding agent#: or a pipeline stage, ``import`` a tracked artifact or manifest speaking for@@ -205,6 +210,12 @@ AGENT_ACCEPTANCE_REMEDY = ("turn agent acceptance back on with `repowise decision config agent-acceptance --on`.")+#: Stable blocker phrases shared with the CLI so remedy selection does not depend+#: on duplicating human-readable messages in another module.+AGENT_ACCEPTANCE_DISABLED_BLOCKER = "agent acceptance is off for this repository"+NO_RATIONALE_BLOCKER = "no rationale or explicit constraint reason"+NO_EVIDENCE_BLOCKER = "no evidence reference"+def accepter_kind_blocker(kind: str) -> str | None:"""Why *kind* cannot be stamped on a new acceptance, or ``None``."""@@ -225,10 +236,8 @@ def machine_grant_blocker(kind: str, action: str, *, granted: bool) -> str | Non"""if kind != "agent" or action not in GRANTING_ACTIONS or granted:return None- return (- f"an agent may not record a {action!r} acceptance here: agent acceptance "- "is off for this repository"- )+ verb = _GRANTING_ACTION_VERBS[action]+ return f"an agent may not {verb} here: {AGENT_ACCEPTANCE_DISABLED_BLOCKER}"#: The fraction of a decision's files that must have moved before the decision@@ -335,6 +344,7 @@ class AcceptanceRequirement:NO_SCOPE_BLOCKER = "no scope: name the files or modules it governs"NO_DECISION_BLOCKER = "no decision text: state what was chosen"+NO_ACCEPTANCE_IDENTITY_BLOCKER = "no accepter or tracked-artifact identity"def acceptance_blockers(req: AcceptanceRequirement) -> list[str]:@@ -351,13 +361,13 @@ def acceptance_blockers(req: AcceptanceRequirement) -> list[str]:if req.decision is not None and not req.decision.strip():blockers.append(NO_DECISION_BLOCKER)if not req.reason.strip():- blockers.append("no rationale or explicit constraint reason")+ blockers.append(NO_RATIONALE_BLOCKER)if not [s for s in req.scope if s and s.strip()]:blockers.append(NO_SCOPE_BLOCKER)if not req.self_authored and not [e for e in req.evidence if e and e.strip()]:- blockers.append("no evidence reference")+ blockers.append(NO_EVIDENCE_BLOCKER)if not req.accepter.strip() and not req.artifact.strip():- blockers.append("no accepter or tracked-artifact identity")+ blockers.append(NO_ACCEPTANCE_IDENTITY_BLOCKER)return blockersdiff --git a/tests/unit/cli/test_decision_agent_acceptance.py b/tests/unit/cli/test_decision_agent_acceptance.pyindex 7b6e509a4..bd7ea2793 100644--- a/tests/unit/cli/test_decision_agent_acceptance.py+++ b/tests/unit/cli/test_decision_agent_acceptance.py@@ -9,12 +9,15 @@ and it is refused only where the repository turned agent acceptance off.from __future__ import annotationsimport json+import sqlite3from pathlib import Pathimport pytestfrom click.testing import CliRunner+from repowise.cli.commands.decision_cmd import _accept_remedy_for_blockersfrom repowise.cli.main import cli+from repowise.core.analysis.decisions.lifecycle import NO_ACCEPTANCE_IDENTITY_BLOCKERfrom .test_decision_cmd import _seed_wiki_db@@ -45,6 +48,14 @@ def _forbid_agents(repo: Path) -> None:assert result.exit_code == 0, result.output+def test_a_missing_acceptance_identity_explains_how_to_name_the_signer() -> None:+ remedy = _accept_remedy_for_blockers([NO_ACCEPTANCE_IDENTITY_BLOCKER])++ assert "--as <name>" in remedy+ assert "--agent <slug>" in remedy+ assert "Supply the missing parts" not in remedy++def test_an_agent_accepts_with_no_config(repo: Path) -> None:result = _run(repo, "confirm", "aaaa", "--agent", "claude_code")@@ -59,7 +70,7 @@ def test_an_agent_is_refused_on_a_repository_that_turned_it_off(repo: Path) -> Nassert result.exit_code == 1, result.outputpayload = json.loads(result.output)- assert "may not record" in payload["results"][0]["message"]+ assert "may not accept here" in payload["results"][0]["message"]assert "agent-acceptance --on" in payload["remedy"]@@ -72,6 +83,7 @@ def test_the_refusal_leads_with_the_switch_it_was_refused_by(repo: Path) -> Noneremedy = json.loads(result.output)["remedy"]assert remedy.startswith("Agent acceptance is off")+ assert "Supply the missing parts" not in remedydef test_an_agent_signs_as_itself(repo: Path) -> None:@@ -98,14 +110,21 @@ def test_a_candidate_reports_no_signer(repo: Path) -> None:assert json.loads(_run(repo, "show", "aaaa").output)["decision"]["signature"] is None-def test_a_batch_refusal_still_names_the_switch(repo: Path) -> None:- """The remedy reached only the one-id path, so a scripted confirm of two- ids was refused without ever being told which switch to turn on."""+def test_a_batch_refusal_includes_each_remedy_needed(repo: Path) -> None:+ """A policy refusal and an incomplete record need different next steps."""_forbid_agents(repo)+ with sqlite3.connect(repo / ".repowise" / "wiki.db") as conn:+ conn.execute(+ "UPDATE decision_records SET affected_files_json = '[]' WHERE id = ?",+ ("b" * 32,),+ )+result = _run(repo, "confirm", "aaaa", "bbbb", "--agent", "claude_code")assert result.exit_code == 1, result.output- assert "agent-acceptance --on" in json.loads(result.output)["remedy"]+ remedy = json.loads(result.output)["remedy"]+ assert "agent-acceptance --on" in remedy+ assert "Supply the missing parts" in remedydef test_the_remedy_sends_the_agent_to_a_person(repo: Path) -> None:diff --git a/tests/unit/cli/test_decision_config_cmd.py b/tests/unit/cli/test_decision_config_cmd.pyindex 13e0d426a..c71ca27a7 100644--- a/tests/unit/cli/test_decision_config_cmd.py+++ b/tests/unit/cli/test_decision_config_cmd.py@@ -324,3 +324,39 @@ def test_switching_discovery_on_is_an_ordinary_source_toggle(repo: Path):assert result.exit_code == 0, result.outputassert _config(repo)["decisions"]["sources"]["session_discovery"] is True+++def test_show_points_to_init_when_claude_settings_file_is_missing(+ repo: Path, tmp_path: Path, monkeypatch+):+ from repowise.cli.editor_integrations import claude_config++ settings_path = tmp_path / ".claude" / "settings.json"+ monkeypatch.setattr(claude_config, "_claude_code_settings_path", lambda: settings_path)+ monkeypatch.setattr(claude_config, "_plugin_ships_capture_hook", lambda: False)+ _write(repo, "decisions:\n enabled: true\n capture_prompt: true\n")++ result = _run("decision", "config", "show", str(repo))++ assert result.exit_code == 0, result.output+ assert "Run `repowise init`" in result.output+ assert "Re-run `repowise decision config capture-prompt --on`." not in result.output+++def test_show_recommends_capture_prompt_when_settings_file_lacks_hook(+ repo: Path, tmp_path: Path, monkeypatch+):+ from repowise.cli.editor_integrations import claude_config++ settings_path = tmp_path / ".claude" / "settings.json"+ settings_path.parent.mkdir(parents=True)+ settings_path.write_text("{}", encoding="utf-8")+ monkeypatch.setattr(claude_config, "_claude_code_settings_path", lambda: settings_path)+ monkeypatch.setattr(claude_config, "_plugin_ships_capture_hook", lambda: False)+ _write(repo, "decisions:\n enabled: true\n capture_prompt: true\n")++ result = _run("decision", "config", "show", str(repo))++ assert result.exit_code == 0, result.output+ assert "Re-run `repowise decision config capture-prompt --on`." in result.output+ assert "Run `repowise init`" not in result.outputdiff --git a/tests/unit/persistence/test_decision_acceptance_provenance.py b/tests/unit/persistence/test_decision_acceptance_provenance.pyindex a8f15cf5c..9c3e21901 100644--- a/tests/unit/persistence/test_decision_acceptance_provenance.py+++ b/tests/unit/persistence/test_decision_acceptance_provenance.py@@ -131,7 +131,7 @@ async def test_an_agent_cannot_accept_by_default(async_session):repo = await insert_repo(async_session)rec = await _seed(async_session, repo.id, "Use Redis")- with pytest.raises(AcceptanceRefusedError, match="may not record a 'accepted'"):+ with pytest.raises(AcceptanceRefusedError, match="may not accept here"):await accept_decision(async_session, rec, accepter="claude_code", kind="agent")assert await latest_acceptance(async_session, rec.id) is None@@ -142,10 +142,22 @@ async def test_an_agent_cannot_reaffirm_by_default(async_session):rec = await _seed(async_session, repo.id, "Use Redis")await accept_decision(async_session, rec, accepter="Raghav", kind="person")- with pytest.raises(AcceptanceRefusedError, match="may not record a 'reaffirmed'"):+ with pytest.raises(AcceptanceRefusedError, match="may not reaffirm here"):await reaffirm_decision(async_session, rec, accepter="claude_code", kind="agent")+ ("action", "verb"),+ [("accepted", "accept"), ("reaffirmed", "reaffirm"), ("merged", "merge")],+)+def test_a_grant_refusal_uses_the_action_verb(action: str, verb: str) -> None:+ blocker = machine_grant_blocker("agent", action, granted=False)++ assert blocker == (+ f"an agent may not {verb} here: agent acceptance is off for this repository"+ )++async def test_an_agent_may_withdraw_authority_without_the_switch(async_session):"""The asymmetry, stated: a wrong withdrawal is recoverable, a wrong grant is not."""repo = await insert_repo(async_session)