Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(generate): after a keyless init, generate also reads the decisions it skipped (#4243)

Raghav Chamadiya6e20607bbd62
diff --git a/docs/reference/CLI_REFERENCE.md b/docs/reference/CLI_REFERENCE.md
index fe71f5861..81ff2c684 100644
--- a/docs/reference/CLI_REFERENCE.md
+++ b/docs/reference/CLI_REFERENCE.md
@@ -335,6 +335,12 @@ cycle) is rendered from structure and refreshes on `repowise update`, so
naming one with `--page` is an actionable error rather than a silent LLM
re-render.
+**Decisions a keyless index skipped.** An index built without a model (no key,
+or `--no-prose`) cannot read decisions from PRs, git history or code comments.
+The first `generate` (or `update --full`) with a model runs those lanes too, and
+the cost estimate prices them on their own line. Later runs skip them, and
+`repowise status` shows a Decisions row while they are still pending.
+
**Interactive chooser.** Run `repowise generate` with no selection flag on a
terminal and it prints the wiki's state (written / unwritten / stale on the
concept layer), writes the unwritten subsystem pages, asks about cascade only
diff --git a/packages/cli/src/repowise/cli/commands/decision_lanes.py b/packages/cli/src/repowise/cli/commands/decision_lanes.py
new file mode 100644
index 000000000..10acb63fa
--- /dev/null
+++ b/packages/cli/src/repowise/cli/commands/decision_lanes.py
@@ -0,0 +1,104 @@
+"""The decision lanes a keyless index skipped, as ``generate`` and ``update --full`` run them.
+
+Every helper takes ``None`` for "nothing pending" so a caller needs no branch of
+its own around the lanes.
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import Any
+
+import structlog
+
+from repowise.cli.helpers import console
+from repowise.core.decision_lanes import (
+ DecisionLaneOutcome,
+ DecisionLanePlan,
+ lanes_label,
+ run_decision_lanes,
+)
+
+logger = structlog.get_logger(__name__)
+
+
+def with_lane_plan(cost_plans: list[Any], plan: DecisionLanePlan | None) -> list[Any]:
+ """*cost_plans* plus the decision calls, so one estimate prices both."""
+ return [*cost_plans, plan.cost_plan()] if plan else list(cost_plans)
+
+
+def lane_estimate(plan: DecisionLanePlan, provider: Any) -> Any:
+ """The plan's estimate, priced for *provider* (unpriced when it is ``None``)."""
+ from repowise.core.cost_estimator import estimate_cost
+
+ if provider is None:
+ return estimate_cost([plan.cost_plan()], "none", "")
+ return estimate_cost([plan.cost_plan()], provider.provider_name, provider.model_name)
+
+
+def print_lane_estimate(plan: DecisionLanePlan | None, provider: Any) -> None:
+ """``Decisions from PRs, history and comments: about N tokens, $X.``"""
+ if plan is None:
+ return
+ est = lane_estimate(plan, provider)
+ tokens = est.estimated_input_tokens + est.estimated_output_tokens
+ # Unpriced without a model; the caller says so once for the whole run.
+ price = "" if provider is None else f", ${est.estimated_cost_usd:.2f}"
+ calls = f"{plan.calls} model call{'s' if plan.calls != 1 else ''}"
+ console.print(
+ f"Decisions from {lanes_label(plan.lanes)}: about [bold]{tokens:,}[/bold] tokens "
+ f"({calls}){price}."
+ )
+
+
+def still_pending_after(outcome: DecisionLaneOutcome | None) -> tuple[str, ...] | None:
+ """Lanes left after a run, or ``None`` when no lanes ran (leave state alone)."""
+ return outcome.still_pending if outcome is not None else None
+
+
+async def run_and_report_lanes(
+ session_factory: Any,
+ repo_id: str,
+ repo_path: Path,
+ plan: DecisionLanePlan | None,
+ *,
+ provider: Any,
+ inputs: Any,
+ vector_store: Any = None,
+ cost_tracker: Any = None,
+) -> DecisionLaneOutcome | None:
+ """Run the planned lanes on *provider*'s tracker and print what they found.
+
+ ``None`` when nothing was planned.
+ """
+ if plan is None:
+ return None
+ if cost_tracker is not None:
+ provider._cost_tracker = cost_tracker
+ label = lanes_label(plan.lanes)
+ console.print(f"Reading decisions from {label}...")
+ try:
+ outcome = await run_decision_lanes(
+ session_factory,
+ repo_id,
+ repo_path,
+ plan,
+ provider=provider,
+ inputs=inputs,
+ vector_store=vector_store,
+ )
+ except Exception as exc:
+ # Broad on purpose: the pages are already written, so any store or model
+ # failure here must leave the lanes pending, not lose the run's state write.
+ logger.warning("decision_lanes_failed", error=str(exc), exc_info=True)
+ console.print(f"[yellow]Decision extraction failed ({exc}).[/yellow]")
+ outcome = DecisionLaneOutcome(found=0, still_pending=plan.lanes)
+ if cost_tracker is not None:
+ await cost_tracker.flush()
+ console.print(f"Decisions from {label}: [bold]{outcome.found}[/bold] found.")
+ if outcome.still_pending:
+ console.print(
+ f"[yellow]Decisions from {lanes_label(outcome.still_pending)} failed.[/yellow] "
+ "The next model run retries them."
+ )
+ return outcome
diff --git a/packages/cli/src/repowise/cli/commands/generate_cmd/command.py b/packages/cli/src/repowise/cli/commands/generate_cmd/command.py
index 7262fd3fa..2cafe3ffc 100644
--- a/packages/cli/src/repowise/cli/commands/generate_cmd/command.py
+++ b/packages/cli/src/repowise/cli/commands/generate_cmd/command.py
@@ -34,9 +34,11 @@ from repowise.cli.helpers import (
from repowise.cli.providers import model_run_embedder
from repowise.cli.ui import load_dotenv
from repowise.core.cost_estimator import STRUCTURAL_PAGE_TYPES
+from repowise.core.decision_lanes import set_pending_decision_lanes
from repowise.core.docs_mode import docs_mode_state_fields, resolve_docs_mode
from repowise.core.generation.page_selection import PageSelectionIntent
+from ..decision_lanes import print_lane_estimate
from .engine import NO_DOCUMENTATION_MESSAGE, has_documentation, run_scoped_generation
@@ -110,7 +112,13 @@ def _make_gate(dry_run: bool, embedder: str | None = None):
"""
def gate_cost(
- cost_plans: Any, provider: Any, repo_path: Path, *, yes: bool, dry_run: bool
+ cost_plans: Any,
+ provider: Any,
+ repo_path: Path,
+ *,
+ yes: bool,
+ dry_run: bool,
+ decisions: Any = None,
) -> bool:
from repowise.cli.commands.init_cmd.generation import (
cost_gate_blocks,
@@ -120,21 +128,18 @@ def _make_gate(dry_run: bool, embedder: str | None = None):
from repowise.cli.providers.embedders import resolve_embedding_model
from repowise.core.cost_estimator import estimate_cost
+ from ..decision_lanes import with_lane_plan
+
if provider is None:
- est = estimate_cost(cost_plans, "none", "", repo_path=repo_path)
- tokens = est.estimated_input_tokens + est.estimated_output_tokens
- console.print(
- f"Writing [bold]{est.total_pages}[/bold] pages, about [bold]{tokens:,}[/bold] "
- "tokens. No model is configured, so there is no price; pass "
- "[cyan]--provider[/cyan] to price it."
- )
+ _print_unpriced_plan(cost_plans, decisions, repo_path)
console.print("[dim]Dry run, nothing generated.[/dim]")
return False
est = None
try:
+ # One estimate prices pages and decision calls together.
est = estimate_cost(
- cost_plans,
+ with_lane_plan(cost_plans, decisions),
provider.provider_name,
provider.model_name,
repo_path=repo_path,
@@ -145,11 +150,9 @@ def _make_gate(dry_run: bool, embedder: str | None = None):
console.print(f"[yellow]Cost estimate unavailable ({exc}).[/yellow]")
if est is not None:
- pages = sum(p.count for p in cost_plans)
- console.print(
- f"Writing [bold]{pages}[/bold] pages with "
- f"[cyan]{provider.model_name}[/cyan]. Estimated [bold]{format_cost(est)}[/bold]."
- )
+ _print_page_line(cost_plans, f" with [cyan]{provider.model_name}[/cyan]")
+ print_lane_estimate(decisions, provider)
+ console.print(f"Estimated [bold]{format_cost(est)}[/bold].")
embedding = embedding_note(est)
if embedding:
console.print(f"[dim]{embedding}[/dim]")
@@ -375,7 +378,36 @@ def _account_for_plan(
return counts
+def _print_page_line(cost_plans: Any, detail: str) -> None:
+ """``Writing N pages <detail>.``, or nothing on a decisions-only run."""
+ pages = sum(p.count for p in cost_plans)
+ if pages:
+ console.print(f"Writing [bold]{pages}[/bold] pages{detail}.")
+
+
+def _print_unpriced_plan(cost_plans: Any, decisions: Any, repo_path: Path) -> None:
+ """The keyless dry run: token counts for pages and decision lanes, no price."""
+ from repowise.core.cost_estimator import estimate_cost
+
+ est = estimate_cost(cost_plans, "none", "", repo_path=repo_path)
+ tokens = est.estimated_input_tokens + est.estimated_output_tokens
+ _print_page_line(cost_plans, f", about [bold]{tokens:,}[/bold] tokens")
+ print_lane_estimate(decisions, None)
+ console.print(
+ "No model is configured, so there is no price; pass [cyan]--provider[/cyan] to price it."
+ )
+
+
def _report_outcome(outcome: Any, elapsed: float) -> None:
+ """Report the pages, or only the cost on a decisions-only run."""
+ if outcome.plan.generate_ids:
+ _report_pages(outcome, elapsed)
+ else:
+ # The lane lines already said what the decisions-only run found.
+ console.print(f"Cost: [bold]${outcome.cost_usd:.3f}[/bold] ({outcome.tokens:,} tokens).")
+
+
+def _report_pages(outcome: Any, elapsed: float) -> None:
"""Print where every planned page went, the actual cost, and what is left."""
planned = outcome.plan.generate_ids
c = _account_for_plan(planned, outcome.generated_pages, outcome.swept_page_ids)
@@ -496,4 +528,7 @@ def _write_state(
provider=provider_block,
upgrade={"status": "not_applicable", "retryable": False, "next_stage": None},
)
+ lanes = getattr(outcome, "decision_lanes", None)
+ if lanes is not None:
+ set_pending_decision_lanes(state, lanes.still_pending)
save_state(repo_path, state)
diff --git a/packages/cli/src/repowise/cli/commands/generate_cmd/engine.py b/packages/cli/src/repowise/cli/commands/generate_cmd/engine.py
index 08b9eeb28..d392a91b0 100644
--- a/packages/cli/src/repowise/cli/commands/generate_cmd/engine.py
+++ b/packages/cli/src/repowise/cli/commands/generate_cmd/engine.py
@@ -97,6 +97,8 @@ class GenerateOutcome:
tokens: int = 0
#: Model-written pages still stale after the run.
stale_page_ids: set[str] = field(default_factory=set)
+ #: The skipped decision lanes this run filled, when any were pending.
+ decision_lanes: Any | None = None
async def run_scoped_generation(
@@ -126,6 +128,13 @@ async def run_scoped_generation(
cost_tracking_disabled,
resolve_embedder,
)
+
+ # Deferred like every other CLI call site: ``repowise.core.pipeline.__init__``
+ # eagerly pulls in the orchestrator and the persist layer. At module scope
+ # that cost every ``repowise`` invocation 31 extra modules (20 of them the
+ # pipeline package) — ``--help`` and the post-commit hook included, neither
+ # of which generates.
+ from repowise.core.decision_lanes import plan_decision_lanes
from repowise.core.generation.cost_tracker import CostTracker
from repowise.core.persistence import (
FullTextSearch,
@@ -135,17 +144,14 @@ async def run_scoped_generation(
upsert_repository,
)
from repowise.core.persistence import get_session as _get_session
-
- # Deferred like every other CLI call site: ``repowise.core.pipeline.__init__``
- # eagerly pulls in the orchestrator and the persist layer. At module scope
- # that cost every ``repowise`` invocation 31 extra modules (20 of them the
- # pipeline package) — ``--help`` and the post-commit hook included, neither
- # of which generates.
from repowise.core.pipeline.scoped_generation import (
+ ScopedGenerationResult,
execute_scoped_generation,
rehydrate_repo,
)
+ from ..decision_lanes import run_and_report_lanes
+
url = get_db_url_for_repo(repo_path)
engine = create_engine(url)
await init_db(engine)
@@ -208,14 +214,19 @@ async def run_scoped_generation(
console.print(
"[yellow]No such page(s), skipped:[/yellow] " + ", ".join(plan.unknown_page_ids)
)
+ # The decision lanes a keyless index skipped run with this model too.
+ lane_plan = plan_decision_lanes(state, repo_path, rehydrated)
if not plan.generate_ids:
console.print("[yellow]Nothing to generate for that selection.[/yellow]")
- return None
-
- _report_plan(plan, cascade_mode)
+ if lane_plan is None:
+ return None
+ else:
+ _report_plan(plan, cascade_mode)
# Cost gate (and the dry-run stop) share the same estimate.
- proceed = gate_cost(plan.cost_plans, provider, repo_path, yes=yes, dry_run=dry_run)
+ proceed = gate_cost(
+ plan.cost_plans, provider, repo_path, yes=yes, dry_run=dry_run, decisions=lane_plan
+ )
if not proceed:
return None
@@ -251,20 +262,33 @@ async def run_scoped_generation(
console.print(f"[dim]Full-text index unavailable: {exc}[/dim]")
fts = None
- result = await execute_scoped_generation(
- session_factory=sf,
- repo_id=repo_id,
- repo_path=repo_path,
- rehydrated=rehydrated,
- plan=plan,
+ result = ScopedGenerationResult(generated_pages=[], marked_stale=0)
+ if plan.generate_ids:
+ result = await execute_scoped_generation(
+ session_factory=sf,
+ repo_id=repo_id,
+ repo_path=repo_path,
+ rehydrated=rehydrated,
+ plan=plan,
+ provider=provider,
+ generation_config=config,
+ embedder=embedder,
+ vector_store=vector_store,
+ fts=fts,
+ progress=None,
+ cost_tracker=cost_tracker,
+ concurrency=config.max_concurrency,
+ )
+
+ lanes = await run_and_report_lanes(
+ sf,
+ repo_id,
+ repo_path,
+ lane_plan,
provider=provider,
- generation_config=config,
- embedder=embedder,
+ inputs=rehydrated,
vector_store=vector_store,
- fts=fts,
- progress=None,
cost_tracker=cost_tracker,
- concurrency=config.max_concurrency,
)
total_pages, remaining_templates, stale_ids = await _page_stats(sf, repo_id)
@@ -278,6 +302,7 @@ async def run_scoped_generation(
cost_usd=cost_tracker.session_cost,
tokens=cost_tracker.session_tokens,
stale_page_ids=stale_ids,
+ decision_lanes=lanes,
)
finally:
await engine.dispose()
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/_finish.py b/packages/cli/src/repowise/cli/commands/init_cmd/_finish.py
index 24164720e..0f12d4137 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/_finish.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/_finish.py
@@ -32,10 +32,12 @@ from repowise.cli.ui import (
)
from repowise.core.analysis.health import HEALTH_ANALYZER_VERSION
from repowise.core.analysis.security_scan import SECURITY_SCANNER_VERSION
+from repowise.core.decision_lanes import record_decision_lanes
from repowise.core.docs_mode import docs_mode_state_fields
from repowise.core.generation.styles import DEFAULT_STYLE
from repowise.core.repo_config import config_dependency_fingerprints
+from ._ingest import decision_llm_client
from ._interactive import offer_distill_rewrite_hook, offer_hook_install
from ._options import InitRun
from .persistence import (
@@ -245,6 +247,9 @@ def _base_state(run: InitRun) -> dict[str, Any]:
base_state["git_tier"] = git_tier_for_run_mode(run_mode)
apply_git_history_coverage_state(base_state, result)
_stamp_scope(run, base_state, docs_mode)
+ record_decision_lanes(
+ base_state, repo_path, ran_with_model=decision_llm_client(run) is not None
+ )
keep_prior_documentation(base_state, prior_state, run_mode)
base_state["include_submodules"] = run.opts.include_submodules
if run.phase_timings:
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/_ingest.py b/packages/cli/src/repowise/cli/commands/init_cmd/_ingest.py
index 770e86c81..a47227e8e 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/_ingest.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/_ingest.py
@@ -119,14 +119,21 @@ async def _index_with_resume(
await engine.dispose()
+def decision_llm_client(run: InitRun) -> Any:
+ """The model decision extraction calls this run, or None (always None on a dry run).
+
+ A structural run makes no model calls, decisions included.
+ """
+ return None if run.opts.dry_run or run.opts.index_only else run.provider
+
+
def index_repository(run: InitRun) -> None:
"""Phases 1 and 2, without docs (generation follows the cost gate). Exits 130 if interrupted."""
opts = run.opts
# Fast mode skips generation, so it has three phases.
run.total_phases = 3 if opts.run_mode == "fast" else 4
# None on a dry run: analysis would call it before generation's dry-run exit.
- # A structural run never resolved one (see ``_resolve_provider_stage``).
- llm_client = None if opts.dry_run else run.provider
+ llm_client = decision_llm_client(run)
from repowise.core.pipeline import PhaseTimingRecorder, run_pipeline
from repowise.core.pipeline.modes import OrchestratorMode
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py b/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py
index 77635f5ed..5f851f0b6 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py
@@ -28,6 +28,7 @@ from repowise.cli.helpers import (
from repowise.cli.state_persistence import build_kg_state, save_knowledge_graph_json
from repowise.core.analysis.health import HEALTH_ANALYZER_VERSION
from repowise.core.analysis.security_scan import SECURITY_SCANNER_VERSION
+from repowise.core.decision_lanes import record_decision_lanes
from repowise.core.docs_mode import docs_mode_state_fields
from repowise.core.generation.models import count_stub_fallbacks
from repowise.core.index_scope import (
@@ -517,6 +518,8 @@ def save_full_state_and_config(
state["run_mode"] = "standard"
state["git_tier"] = "full"
apply_git_history_coverage_state(state, result)
+ # The docs model ran every decision lane, so none is left for a later run.
+ record_decision_lanes(state, repo_path, ran_with_model=True)
_stamp_full_init_scope(
state,
result,
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py
index a1d285a7d..b287e324b 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py
@@ -71,6 +71,7 @@ from repowise.cli.ui import (
)
from repowise.cli.ui.mode_names import pages
from repowise.core.ci.markdown import plural
+from repowise.core.decision_lanes import record_decision_lanes
from repowise.core.docs_mode import docs_mode_state_fields
from repowise.core.generation.styles import DEFAULT_STYLE
@@ -646,6 +647,7 @@ def _stamp_repo_scope(
)
state["run_mode"] = ctx.run_mode
state["git_tier"] = "essential" if ctx.run_mode == "fast" else "full"
+ record_decision_lanes(state, repo_path, ran_with_model=repo_provider is not None)
unavailable = [] if getattr(result, "health_report", None) is not None else ["health"]
stamp_index_scope(
state,
diff --git a/packages/cli/src/repowise/cli/commands/status_cmd.py b/packages/cli/src/repowise/cli/commands/status_cmd.py
index e2e4850ca..b3bec043d 100644
--- a/packages/cli/src/repowise/cli/commands/status_cmd.py
+++ b/packages/cli/src/repowise/cli/commands/status_cmd.py
@@ -31,6 +31,7 @@ from repowise.cli.ui.mode_names import (
scope_line,
)
from repowise.cli.ui.result_panels import keyless_upgrade_note
+from repowise.core.decision_lanes import lanes_label, pending_decision_lanes
from repowise.core.docs_mode import resolve_docs_mode
from repowise.core.index_scope import resolve_index_scope
@@ -690,6 +691,7 @@ def status_command(path: str | None, workspace: bool, no_workspace: bool, fmt: s
db_path = repowise_dir / "wiki.db"
has_db = db_path.exists() or db_configured()
incomplete = _incomplete_index(repo_path, state)
+ pending_lanes = pending_decision_lanes(state, repo_path)
if fmt == "json":
counts, total_db_tokens = (
@@ -716,6 +718,7 @@ def status_command(path: str | None, workspace: bool, no_workspace: bool, fmt: s
"health": _query_health(repo_path),
"next_actions": _next_actions_summary(_load_actions(repo_path) if has_db else None),
"index_scope": scope,
+ "decision_lanes_pending": list(pending_lanes),
}
)
return
@@ -780,6 +783,11 @@ def status_command(path: str | None, workspace: bool, no_workspace: bool, fmt: s
state_table.add_row("Test run", "documentation covers the top 10 files only")
if _shows_upgrade_row(scope):
state_table.add_row("Full upgrade", scope["upgrade"]["status"])
+ if pending_lanes:
+ state_table.add_row(
+ "Decisions",
+ f"{lanes_label(pending_lanes)} not read yet (needs a model): repowise generate",
+ )
console.print(state_table)
# A template-only scope is a finished keyless index, not a broken one —
diff --git a/packages/cli/src/repowise/cli/commands/upgrade_flow.py b/packages/cli/src/repowise/cli/commands/upgrade_flow.py
index 667d81198..31d763919 100644
--- a/packages/cli/src/repowise/cli/commands/upgrade_flow.py
+++ b/packages/cli/src/repowise/cli/commands/upgrade_flow.py
@@ -28,10 +28,17 @@ import contextlib
import sys
import time
from pathlib import Path
+from types import SimpleNamespace
from typing import Any
import click
+from repowise.cli.commands.decision_lanes import (
+ print_lane_estimate,
+ run_and_report_lanes,
+ still_pending_after,
+ with_lane_plan,
+)
from repowise.cli.helpers import (
console,
get_head_commit,
@@ -45,6 +52,7 @@ from repowise.cli.helpers import (
stamp_offered_slots,
)
from repowise.core.analysis.health import HEALTH_ANALYZER_VERSION
+from repowise.core.decision_lanes import plan_decision_lanes, set_pending_decision_lanes
from repowise.core.docs_mode import docs_mode_state_fields
from repowise.core.index_scope import file_page_scope, stamp_index_scope
from repowise.core.ingestion.git_indexer import GIT_HISTORY_VERSION, GIT_HISTORY_VERSION_KEY
@@ -60,6 +68,7 @@ def _gate_cost(
repo_path: Path,
*,
yes: bool,
+ decisions: Any = None,
embedder: str = "mock",
) -> None:
"""Print the estimated spend, embedding included, and confirm past the gate.
@@ -83,7 +92,7 @@ def _gate_cost(
plans = build_generation_plan(parsed_files, graph_builder, config)
est = estimate_cost(
- plans,
+ with_lane_plan(plans, decisions),
provider.provider_name,
provider.model_name,
repo_path=repo_path,
@@ -102,6 +111,7 @@ def _gate_cost(
embedding = embedding_note(est)
if embedding:
console.print(f" [dim]{embedding}[/dim]")
+ print_lane_estimate(decisions, provider)
# Nothing to ask on a run that cannot be asked. Without this the confirm
# reads EOF, raises, and the caller reports a successful run that generated
@@ -309,6 +319,15 @@ async def _run_upgrade(
"(graph reused from index — not re-resolved)."
)
+ # The decision lanes a keyless index skipped run with this model as well.
+ lane_inputs = SimpleNamespace(
+ graph_builder=graph_builder,
+ git_meta_map=git_meta_map,
+ parsed_files=parsed_files,
+ source_map=source_map,
+ )
+ lane_plan = plan_decision_lanes(load_state(repo_path), repo_path, lane_inputs)
+
# Show the bill before running it, as init does: the user reaching for
# `--full` has never been shown a cost for this repo.
_gate_cost(
@@ -318,6 +337,7 @@ async def _run_upgrade(
provider,
repo_path,
yes=yes,
+ decisions=lane_plan,
embedder=embedder_name or "mock",
)
@@ -343,6 +363,17 @@ async def _run_upgrade(
# Flush buffered cost rows now generation is done (best-effort).
await cost_tracker.flush()
+ lanes = await run_and_report_lanes(
+ sf,
+ repo_id,
+ repo_path,
+ lane_plan,
+ provider=provider,
+ inputs=lane_inputs,
+ vector_store=vector_store,
+ cost_tracker=cost_tracker,
+ )
+
# 6. Persist pages + a GenerationJob marker, then build the FTS index.
retired_page_ids = await _persist_upgrade_pages(
sf, repo_id, generated_pages, vector_store, stub_fallbacks
@@ -403,6 +434,7 @@ async def _run_upgrade(
"embedding_error": embedding_error,
"stub_fallbacks": stub_fallbacks,
"stub_reasons": stub_reasons,
+ "decision_lanes_pending": still_pending_after(lanes),
},
)
@@ -993,6 +1025,8 @@ def _finish_upgrade_state(
# Every onboarding slot was evaluated against whole-repo signals, so the
# missing-slot notice has nothing left to report.
stamp_offered_slots(state, enabled=config.enable_onboarding)
+ if outcome.get("decision_lanes_pending") is not None:
+ set_pending_decision_lanes(state, outcome["decision_lanes_pending"])
# Health and the git backfill ran over the whole repo under the current
# analyzer and history rules, so the next update need not redo them.
state["health_analyzer_version"] = HEALTH_ANALYZER_VERSION
diff --git a/packages/core/src/repowise/core/analysis/decisions/extractor.py b/packages/core/src/repowise/core/analysis/decisions/extractor.py
index d75fb3fbd..8c30a4587 100644
--- a/packages/core/src/repowise/core/analysis/decisions/extractor.py
+++ b/packages/core/src/repowise/core/analysis/decisions/extractor.py
@@ -131,6 +131,12 @@ _COMMENT_RATIONALE_CUES = (
)
_MAX_COMMENT_NODES = 30
+# Items per model call for the three model-only sources.
+_GIT_BATCH = 5
+_PR_BATCH = 5
+_COMMENT_BATCH = 4
+_MAX_SIGNAL_COMMITS = 20
+
# Inline markers sent to the model per call. Caps prompt length only; a file
# with more markers is sent in several calls rather than truncated.
_MARKERS_PER_CALL = 5
@@ -408,20 +414,12 @@ class DecisionExtractor:
async def mine_git_archaeology(self) -> list[ExtractedDecision]:
"""Extract decisions from significant git commits."""
provider = self._llm("git_archaeology")
- if not provider or not self._git_meta_map:
+ if not provider:
return []
-
- commit_map, commit_files = signal_commits(self._git_meta_map)
- if not commit_map:
+ ranked, commit_files = self._git_archaeology_candidates()
+ if not ranked:
return []
- # Rank by signal count, take top 20
- ranked = sorted(
- commit_map.values(),
- key=lambda c: c["signal_count"],
- reverse=True,
- )[:20]
-
# Batch LLM calls (5 commits per batch)
async def _process_batch(batch: list[dict]) -> list[ExtractedDecision]:
commits_block = ""
@@ -451,7 +449,15 @@ class DecisionExtractor:
return extracted
- return await _run_batches("git_archaeology", ranked, 5, _process_batch)
+ return await _run_batches("git_archaeology", ranked, _GIT_BATCH, _process_batch)
+
+ def _git_archaeology_candidates(self) -> tuple[list[dict], dict[str, list[str]]]:
+ """The commits git archaeology sends, strongest signal first, and their files."""
+ if not self._git_meta_map:
+ return [], {}
+ commit_map, commit_files = signal_commits(self._git_meta_map)
+ ranked = sorted(commit_map.values(), key=lambda c: c["signal_count"], reverse=True)
+ return ranked[:_MAX_SIGNAL_COMMITS], commit_files
# ------------------------------------------------------------------
# Source 3: ADR auto-discovery (deterministic-first)
@@ -559,14 +565,11 @@ class DecisionExtractor:
async def mine_pr_bodies(self) -> list[ExtractedDecision]:
"""Extract decisions from PR / squash-merge commit bodies."""
provider = self._llm("pr")
- if not provider or not self._git_meta_map:
+ if not provider:
return []
-
- candidates, files_by_sha = pr_candidates(self._git_meta_map)
- if not candidates:
+ ranked, files_by_sha = self._pr_body_candidates()
+ if not ranked:
return []
-
- ranked = list(candidates.values())[:_MAX_PR_BODIES]
forge = get_forge(detect_forge(self._repo_path))
async def _process_batch(batch: list[dict]) -> list[ExtractedDecision]:
@@ -591,7 +594,14 @@ class DecisionExtractor:
d.affected_modules = self._infer_modules(d.affected_files)
return extracted
- return await _run_batches("pr", ranked, 5, _process_batch)
+ return await _run_batches("pr", ranked, _PR_BATCH, _process_batch)
+
+ def _pr_body_candidates(self) -> tuple[list[dict], dict[str, list[str]]]:
+ """The PR bodies the PR source sends, and the files each one touched."""
+ if not self._git_meta_map:
+ return [], {}
+ candidates, files_by_sha = pr_candidates(self._git_meta_map)
+ return list(candidates.values())[:_MAX_PR_BODIES], files_by_sha
# ------------------------------------------------------------------
# Source 5: Comment archaeology (centrality-bounded)
@@ -606,18 +616,9 @@ class DecisionExtractor:
``scan_inline_markers``.
"""
provider = self._llm("comment")
- if not provider or self._graph is None:
+ if not provider:
return []
-
- top_files = self._top_central_files(_MAX_COMMENT_NODES)
- if not top_files:
- return []
-
- snippets: list[tuple[str, str]] = []
- for fp in top_files:
- prose = extract_leading_prose(self._repo_path, fp)
- if prose and any(cue in prose.lower() for cue in _COMMENT_RATIONALE_CUES):
- snippets.append((fp, prose))
+ snippets = self._comment_snippets()
if not snippets:
return []
@@ -642,7 +643,36 @@ class DecisionExtractor:
d.affected_modules = self._infer_modules([best_fp])
return extracted
- return await _run_batches("comment", snippets, 4, _process_batch)
+ return await _run_batches("comment", snippets, _COMMENT_BATCH, _process_batch)
+
+ def _comment_snippets(self) -> list[tuple[str, str]]:
+ """Leading rationale prose on the most central files, as ``(path, prose)``."""
+ if self._graph is None:
+ return []
+ snippets: list[tuple[str, str]] = []
+ for fp in self._top_central_files(_MAX_COMMENT_NODES):
+ prose = extract_leading_prose(self._repo_path, fp)
+ if prose and any(cue in prose.lower() for cue in _COMMENT_RATIONALE_CUES):
+ snippets.append((fp, prose))
+ return snippets
+
+ def planned_model_calls(self, sources: Collection[str]) -> int:
+ """Model calls the named model-only sources would make; calls none.
+
+ Reads the same candidates the miners send, so the estimate and the run
+ cannot drift apart.
+ """
+ planned = {
+ "git_archaeology": lambda: (len(self._git_archaeology_candidates()[0]), _GIT_BATCH),
+ "pr": lambda: (len(self._pr_body_candidates()[0]), _PR_BATCH),
+ "comment": lambda: (len(self._comment_snippets()), _COMMENT_BATCH),
+ }
+ calls = 0
+ for source in sources:
+ if source in planned:
+ items, size = planned[source]()
+ calls += -(-items // size)
+ return calls
# ------------------------------------------------------------------
# Source 6: Conventions (deterministic, graph-counted)
diff --git a/packages/core/src/repowise/core/cost_estimator/heuristics.py b/packages/core/src/repowise/core/cost_estimator/heuristics.py
index 245b69e92..f722864a1 100644
--- a/packages/core/src/repowise/core/cost_estimator/heuristics.py
+++ b/packages/core/src/repowise/core/cost_estimator/heuristics.py
@@ -24,6 +24,8 @@ _TOKEN_HEURISTICS: dict[str, tuple[int, int]] = {
"repo_overview": (30_000, 5_000),
"infra_page": (4_000, 2_000),
"onboarding": (15_000, 3_500),
+ # One decision-extraction call: a batch of commits, PR bodies or comments.
+ "decision_call": (5_000, 2_500),
}
diff --git a/packages/core/src/repowise/core/decision_lanes.py b/packages/core/src/repowise/core/decision_lanes.py
new file mode 100644
index 000000000..461dcfd01
--- /dev/null
+++ b/packages/core/src/repowise/core/decision_lanes.py
@@ -0,0 +1,172 @@
+"""Decision lanes a run without a model skipped, and the later run that fills them.
+
+PRs, git history and code comments produce decisions only through a model, so a
+keyless or ``--no-prose`` index records them as pending in ``state.json``. The
+first run that has a model (``generate``, ``update --full``) runs exactly those
+lanes through the index's own extraction entry point and clears them.
+"""
+
+from __future__ import annotations
+
+import types
+from collections.abc import Mapping
+from dataclasses import dataclass
+from pathlib import Path
+from typing import Any
+
+#: ``state.json`` key holding the lanes still waiting on a model.
+PENDING_DECISION_LANES_KEY = "decision_lanes_pending"
+
+#: Words for each model-only lane, in the order they are named to a user.
+_LANE_WORDS: tuple[tuple[str, str], ...] = (
+ ("pr", "PRs"),
+ ("git_archaeology", "history"),
+ ("comment", "comments"),
+)
+
+#: Pseudo page type the cost estimator prices one decision-extraction call as.
+DECISION_CALL_TYPE = "decision_call"
+
+
+def lanes_needing_model(repo_path: Path) -> tuple[str, ...]:
+ """Enabled index sources that produce nothing without a model."""
+ from repowise.core.analysis.decisions.policy import INDEX_SOURCE_KEYS, resolve_policy
+ from repowise.core.repo_config import load_repo_config
+
+ policy = resolve_policy(load_repo_config(repo_path)).policy
+ return tuple(
+ rt.key
+ for rt in policy.runtime(provider_available=False)
+ if rt.key in INDEX_SOURCE_KEYS and rt.status == "skipped_no_provider"
+ )
+
+
+def set_pending_decision_lanes(state: dict[str, Any], lanes: tuple[str, ...] | list[str]) -> None:
+ """Store *lanes* as pending; an empty set removes the key."""
+ if lanes:
+ state[PENDING_DECISION_LANES_KEY] = list(lanes)
+ else:
+ state.pop(PENDING_DECISION_LANES_KEY, None)
+
+
+def record_decision_lanes(state: dict[str, Any], repo_path: Path, *, ran_with_model: bool) -> None:
+ """After a full extraction: pending is every model-only lane, or none with a model."""
+ set_pending_decision_lanes(state, () if ran_with_model else lanes_needing_model(repo_path))
+
+
+def pending_decision_lanes(state: Mapping[str, Any], repo_path: Path) -> tuple[str, ...]:
+ """Pending lanes the repo's current decision policy still wants run."""
+ stored = state.get(PENDING_DECISION_LANES_KEY)
+ if not isinstance(stored, list) or not stored:
+ return ()
+ wanted = set(lanes_needing_model(repo_path))
+ return tuple(key for key, _ in _LANE_WORDS if key in stored and key in wanted)
+
+
+def lanes_label(lanes: tuple[str, ...] | list[str]) -> str:
+ """``PRs, history and comments`` for the named lanes."""
+ words = [word for key, word in _LANE_WORDS if key in lanes]
+ if len(words) <= 1:
+ return "".join(words)
+ return f"{', '.join(words[:-1])} and {words[-1]}"
+
+
+@dataclass(frozen=True)
+class DecisionLanePlan:
+ """The lanes a run will fill and the model calls they will make."""
+
+ lanes: tuple[str, ...]
+ calls: int
+
+ def cost_plan(self) -> Any:
+ from repowise.core.cost_estimator import PageTypePlan
+
+ return PageTypePlan(page_type=DECISION_CALL_TYPE, count=self.calls, level=0)
+
+
+def _extractor(repo_path: Path, inputs: Any, provider: Any = None) -> Any:
+ from repowise.core.analysis.decision_extractor import DecisionExtractor
+ from repowise.core.analysis.decisions.policy import resolve_policy
+ from repowise.core.repo_config import load_repo_config
+
+ return DecisionExtractor(
+ repo_path=repo_path,
+ provider=provider,
+ graph=inputs.graph_builder.graph(),
+ git_meta_map=inputs.git_meta_map,
+ parsed_files=inputs.parsed_files,
+ source_map=inputs.source_map,
+ policy=resolve_policy(load_repo_config(repo_path)).policy,
+ )
+
+
+def plan_decision_lanes(
+ state: Mapping[str, Any], repo_path: Path, inputs: Any
+) -> DecisionLanePlan | None:
+ """The pending lanes and their call count, or ``None`` when nothing is pending.
+
+ *inputs* carries ``graph_builder``, ``git_meta_map``, ``parsed_files`` and
+ ``source_map`` (a rehydrated repo).
+ """
+ lanes = pending_decision_lanes(state, repo_path)
+ if not lanes:
+ return None
+ return DecisionLanePlan(lanes, _extractor(repo_path, inputs).planned_model_calls(lanes))
+
+
+@dataclass(frozen=True)
+class DecisionLaneOutcome:
+ """What a lane run found, and the lanes still pending after it."""
+
+ found: int
+ still_pending: tuple[str, ...]
+
+
+async def run_decision_lanes(
+ session_factory: Any,
+ repo_id: str,
+ repo_path: Path,
+ plan: DecisionLanePlan,
+ *,
+ provider: Any,
+ inputs: Any,
+ vector_store: Any = None,
+) -> DecisionLaneOutcome:
+ """Run the planned lanes with *provider*, persist what they find.
+
+ A lane that failed stays pending so the next model run retries it; one that
+ ran and found nothing is done.
+ """
+ from repowise.core.persistence import get_session
+ from repowise.core.pipeline.persist import persist_analysis
+ from repowise.core.pipeline.phases.analysis import _run_decision_extraction
+
+ report = await _run_decision_extraction(
+ repo_path,
+ llm_client=provider,
+ graph_builder=inputs.graph_builder,
+ git_meta_map=inputs.git_meta_map,
+ parsed_files=inputs.parsed_files,
+ source_map=inputs.source_map,
+ progress=None,
+ only_sources=plan.lanes,
+ )
+ if report is None:
+ return DecisionLaneOutcome(found=0, still_pending=plan.lanes)
+ failures = getattr(report, "failures", None) or {}
+ # Only the decision fields: the other analyses were not rerun.
+ result = types.SimpleNamespace(
+ decision_report=report,
+ dead_code_report=None,
+ doc_drift_report=None,
+ health_report=None,
+ vector_store=vector_store,
+ git_metadata_list=list(inputs.git_meta_map.values()),
+ repo_path=repo_path,
+ )
+ async with get_session(session_factory) as session:
+ await persist_analysis(result, session, repo_id)
+ return DecisionLaneOutcome(
+ found=len(report.decisions),
+ still_pending=tuple(lane for lane in plan.lanes if lane in failures),
+ )
diff --git a/packages/core/src/repowise/core/pipeline/phases/analysis.py b/packages/core/src/repowise/core/pipeline/phases/analysis.py
index 860a6ce77..359a6377e 100644
--- a/packages/core/src/repowise/core/pipeline/phases/analysis.py
+++ b/packages/core/src/repowise/core/pipeline/phases/analysis.py
@@ -387,11 +387,14 @@ async def _run_decision_extraction(
source_map: dict[str, bytes] | None = None,
progress: ProgressCallback | None,
no_model_reason: str | None = None,
+ only_sources: Container[str] | None = None,
) -> Any | None:
"""Extract architectural decisions from source and git history.
*no_model_reason* replaces the no-provider reason when the caller chose a
- run without a model rather than having none configured.
+ run without a model rather than having none configured. *only_sources* runs
+ just those index sources and skips the session passes: the later run that
+ fills in the lanes a keyless index could not.
"""
try:
from repowise.core.analysis.decision_extractor import DecisionExtractor
@@ -403,7 +406,7 @@ async def _run_decision_extraction(
# sources run and which of them may call a model.
repo_cfg = load_repo_config(repo_path)
policy = resolve_policy(repo_cfg).policy
- enabled = policy.enabled_index_sources()
+ enabled = _index_sources(policy, only_sources)
if progress:
progress.on_phase_start("decisions", len(enabled))
@@ -431,26 +434,15 @@ async def _run_decision_extraction(
timeout=DECISION_EXTRACTION_TIMEOUT_SECS,
)
- await _add_session_decisions(
- repo_path,
- llm_client=llm_client,
- policy=policy,
- report=report,
- indexed=indexed,
- progress=progress,
- )
- # After the miner: its single read is what filled the discovery span queue.
- discovery = await _run_session_discovery(
- repo_path, llm_client=llm_client, policy=policy, report=report, indexed=indexed
- )
- if progress:
- _report_decision_sources(
- progress,
- report,
+ if only_sources is None:
+ await _session_passes_and_report(
+ repo_path,
+ llm_client=llm_client,
policy=policy,
+ report=report,
+ indexed=indexed,
enabled=enabled,
- discovery=discovery,
- provider_available=llm_client is not None,
+ progress=progress,
no_model_reason=no_model_reason,
)
@@ -463,6 +455,50 @@ async def _run_decision_extraction(
return None
+def _index_sources(policy: Any, only_sources: Container[str] | None) -> tuple[str, ...]:
+ """The policy's enabled index sources, narrowed to *only_sources* when given."""
+ enabled = policy.enabled_index_sources()
+ if only_sources is None:
+ return enabled
+ return tuple(key for key in enabled if key in only_sources)
+
+
+async def _session_passes_and_report(
+ repo_path: Path,
+ *,
+ llm_client: Any | None,
+ policy: Any,
+ report: Any,
+ indexed: Container[str] | None,
+ enabled: Any,
+ progress: ProgressCallback | None,
+ no_model_reason: str | None = None,
+) -> None:
+ """Session mining, broad discovery, then the per-source summary lines."""
+ await _add_session_decisions(
+ repo_path,
+ llm_client=llm_client,
+ policy=policy,
+ report=report,
+ indexed=indexed,
+ progress=progress,
+ )
+ # After the miner: its single read is what filled the discovery span queue.
+ discovery = await _run_session_discovery(
+ repo_path, llm_client=llm_client, policy=policy, report=report, indexed=indexed
+ )
+ if progress:
+ _report_decision_sources(
+ progress,
+ report,
+ policy=policy,
+ enabled=enabled,
+ discovery=discovery,
+ provider_available=llm_client is not None,
+ no_model_reason=no_model_reason,
+ )
+
+
async def _add_session_decisions(
repo_path: Path,
*,
diff --git a/tests/unit/cli/test_generate_decision_lanes.py b/tests/unit/cli/test_generate_decision_lanes.py
new file mode 100644
index 000000000..de8ae2396
--- /dev/null
+++ b/tests/unit/cli/test_generate_decision_lanes.py
@@ -0,0 +1,169 @@
+"""``generate`` and ``update --full`` price, run and settle the decision lanes a keyless init skipped."""
+
+from __future__ import annotations
+
+import io
+import subprocess
+from pathlib import Path
+from types import SimpleNamespace
+
+import pytest
+from rich.console import Console
+
+from repowise.cli.commands import decision_lanes as cli_lanes
+from repowise.cli.commands import status_cmd, upgrade_flow
+from repowise.cli.commands.generate_cmd import command as generate_command
+from repowise.cli.helpers import load_state, save_state
+from repowise.core.cost_estimator import PageTypePlan
+from repowise.core.decision_lanes import (
+ PENDING_DECISION_LANES_KEY,
+ DecisionLaneOutcome,
+ DecisionLanePlan,
+)
+
+LANES = ("pr", "git_archaeology", "comment")
+MOCK = SimpleNamespace(provider_name="mock", model_name="mock")
+
+
+def _capture(monkeypatch: pytest.MonkeyPatch, *modules) -> io.StringIO:
+ buf = io.StringIO()
+ console = Console(file=buf, width=200, force_terminal=False)
+ for module in modules:
+ monkeypatch.setattr(module, "console", console)
+ return buf
+
+
+def _gate(**kwargs) -> bool:
+ gate = generate_command._make_gate(kwargs["dry_run"])
+ return gate(
+ [PageTypePlan(page_type="module_page", count=3, level=0)],
+ kwargs["provider"],
+ Path("."),
+ yes=True,
+ dry_run=kwargs["dry_run"],
+ decisions=DecisionLanePlan(LANES, calls=4),
+ )
+
+
+def test_keyless_dry_run_names_the_decision_lanes_on_their_own_line(monkeypatch) -> None:
+ buf = _capture(monkeypatch, generate_command, cli_lanes)
+ assert _gate(provider=None, dry_run=True) is False
+ out = buf.getvalue()
+ assert "Writing 3 pages" in out
+ # 4 calls at the decision-call heuristic of 7,500 tokens each.
+ assert "Decisions from PRs, history and comments: about 30,000 tokens (4 model calls)." in out
+ assert "there is no price" in out
+ assert "Dry run, nothing generated." in out
+
+
+def test_priced_dry_run_includes_the_decision_lanes(monkeypatch) -> None:
+ buf = _capture(monkeypatch, generate_command, cli_lanes)
+ assert _gate(provider=MOCK, dry_run=True) is False
+ out = buf.getvalue()
+ assert "Decisions from PRs, history and comments: about 30,000 tokens (4 model calls), $0.00." in out
+ assert "Estimated" in out
+
+
+def test_generate_state_write_clears_the_lanes_that_ran(monkeypatch, tmp_path: Path) -> None:
+ (tmp_path / ".repowise").mkdir()
+ state = {PENDING_DECISION_LANES_KEY: list(LANES)}
+ outcome = SimpleNamespace(
+ total_pages=1,
+ remaining_template_pages=0,
+ decision_lanes=DecisionLaneOutcome(found=2, still_pending=("comment",)),
+ )
+ monkeypatch.setattr(generate_command, "get_head_commit", lambda _p: None)
+ generate_command._write_state(tmp_path, state, MOCK, outcome)
+ assert load_state(tmp_path)[PENDING_DECISION_LANES_KEY] == ["comment"]
+
+ outcome.decision_lanes = DecisionLaneOutcome(found=0, still_pending=())
+ generate_command._write_state(tmp_path, state, MOCK, outcome)
+ assert PENDING_DECISION_LANES_KEY not in load_state(tmp_path)
+
+
+def test_update_full_settles_the_lanes_its_run_reports(monkeypatch, tmp_path: Path) -> None:
+ repo = tmp_path / "repo"
+ repo.mkdir()
+ subprocess.run(["git", "init"], cwd=repo, capture_output=True, check=True)
+ (repo / ".repowise").mkdir()
+ save_state(repo, {"run_mode": "standard", "docs_mode": "deterministic",
+ PENDING_DECISION_LANES_KEY: list(LANES)})
+ monkeypatch.setattr(upgrade_flow, "resolve_provider", lambda *a, **k: MOCK)
+ monkeypatch.setattr(upgrade_flow, "try_acquire_update_lock", lambda *a, **k: None)
+ monkeypatch.setattr(upgrade_flow, "release_update_lock", lambda *a, **k: None)
+
+ async def succeed(*_a, **_k):
+ return [], 0, {
+ "git_history_coverage": None,
+ "file_pages": {"configured_cap": None},
+ "search": {"full_text": "available", "semantic": "unavailable", "next_command": None},
+ "embedding_error": None,
+ "decision_lanes_pending": (),
+ }
+
+ monkeypatch.setattr(upgrade_flow, "_run_upgrade", succeed)
+ upgrade_flow.upgrade_to_full(
+ repo, provider_name=None, model=None, reasoning=None, concurrency=1, yes=True
+ )
+ assert PENDING_DECISION_LANES_KEY not in load_state(repo)
+
+
+def _status(monkeypatch, tmp_path: Path, state: dict, *args: str):
+ from click.testing import CliRunner
+
+ (tmp_path / ".repowise").mkdir(exist_ok=True)
+ buf = _capture(monkeypatch, status_cmd)
+ monkeypatch.setattr(status_cmd, "load_state", lambda _p: state)
+ monkeypatch.setattr(status_cmd, "load_config", lambda _p: {})
+ monkeypatch.setattr(status_cmd, "db_configured", lambda: False)
+ result = CliRunner().invoke(
+ status_cmd.status_command, [str(tmp_path), "--no-workspace", *args]
+ )
+ assert result.exit_code == 0, result.output
+ return buf.getvalue(), result.output
+
+
+def test_status_names_pending_lanes_and_the_command_that_runs_them(monkeypatch, tmp_path) -> None:
+ out, _ = _status(monkeypatch, tmp_path, {PENDING_DECISION_LANES_KEY: list(LANES)})
+ assert "PRs, history and comments not read yet (needs a model): repowise generate" in out
+
+
+def test_status_is_quiet_once_the_lanes_ran(monkeypatch, tmp_path) -> None:
+ out, _ = _status(monkeypatch, tmp_path, {"docs_mode": "llm"})
+ assert "not read yet" not in out
+
+
+def test_status_json_carries_the_pending_lanes(monkeypatch, tmp_path) -> None:
+ import json
+
+ _, raw = _status(
+ monkeypatch, tmp_path, {PENDING_DECISION_LANES_KEY: ["pr"]}, "--format", "json"
+ )
+ assert json.loads(raw)["decision_lanes_pending"] == ["pr"]
+
+
+def test_keyless_init_records_the_lanes_a_model_init_does_not(tmp_path: Path) -> None:
+ from repowise.cli.commands.init_cmd._ingest import decision_llm_client
+
+ opts = SimpleNamespace(dry_run=False, index_only=True)
+ assert decision_llm_client(SimpleNamespace(opts=opts, provider=MOCK, decision_provider=None)) is None
+ opts = SimpleNamespace(dry_run=False, index_only=False)
+ assert decision_llm_client(SimpleNamespace(opts=opts, provider=MOCK, decision_provider=None)) is MOCK
+ opts = SimpleNamespace(dry_run=True, index_only=False)
+ assert decision_llm_client(SimpleNamespace(opts=opts, provider=MOCK, decision_provider=None)) is None
+
+
+async def test_a_lane_run_that_raises_keeps_every_lane_pending(monkeypatch) -> None:
+ """Pages written before the lanes keep their state write when the lanes fail."""
+ buf = _capture(monkeypatch, cli_lanes)
+
+ async def boom(*_a, **_k):
+ raise RuntimeError("store locked")
+
+ monkeypatch.setattr(cli_lanes, "run_decision_lanes", boom)
+ plan = DecisionLanePlan(LANES, calls=2)
+ outcome = await cli_lanes.run_and_report_lanes(
+ None, "repo-1", Path("."), plan, provider=SimpleNamespace(), inputs=None
+ )
+ assert outcome.still_pending == LANES
+ assert "store locked" in buf.getvalue()
diff --git a/tests/unit/core/test_decision_lanes.py b/tests/unit/core/test_decision_lanes.py
new file mode 100644
index 000000000..b4f414c3e
--- /dev/null
+++ b/tests/unit/core/test_decision_lanes.py
@@ -0,0 +1,176 @@
+"""The decision lanes a keyless index skips, and the later run that fills them."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from types import SimpleNamespace
+
+import pytest
+
+from repowise.core import decision_lanes
+from repowise.core.analysis.decision_extractor import DecisionExtractor
+from repowise.core.decision_lanes import (
+ PENDING_DECISION_LANES_KEY,
+ DecisionLanePlan,
+ lanes_label,
+ lanes_needing_model,
+ pending_decision_lanes,
+ record_decision_lanes,
+ run_decision_lanes,
+)
+
+MODEL_LANES = {"git_archaeology", "pr", "comment"}
+
+
+def _repo(tmp_path: Path, config: str = "") -> Path:
+ (tmp_path / ".repowise").mkdir()
+ if config:
+ (tmp_path / ".repowise" / "config.yaml").write_text(config, encoding="utf-8")
+ return tmp_path
+
+
+def test_default_policy_needs_a_model_for_prs_history_and_comments(tmp_path: Path) -> None:
+ assert set(lanes_needing_model(_repo(tmp_path))) == MODEL_LANES
+
+
+def test_a_keyless_run_records_the_lanes_and_a_model_run_clears_them(tmp_path: Path) -> None:
+ repo = _repo(tmp_path)
+ state: dict = {}
+ record_decision_lanes(state, repo, ran_with_model=False)
+ assert set(state[PENDING_DECISION_LANES_KEY]) == MODEL_LANES
+
+ record_decision_lanes(state, repo, ran_with_model=True)
+ assert PENDING_DECISION_LANES_KEY not in state
+
+
+def test_pending_lanes_follow_the_current_policy(tmp_path: Path) -> None:
+ """A lane switched off since the keyless run is not run later."""
+ repo = _repo(tmp_path, "decisions:\n sources:\n pr: false\n")
+ state = {PENDING_DECISION_LANES_KEY: ["git_archaeology", "pr", "comment"]}
+ assert pending_decision_lanes(state, repo) == ("git_archaeology", "comment")
+
+
+def test_local_only_preset_leaves_nothing_pending(tmp_path: Path) -> None:
+ repo = _repo(tmp_path, "decisions:\n preset: local_only\n")
+ state: dict = {}
+ record_decision_lanes(state, repo, ran_with_model=False)
+ assert PENDING_DECISION_LANES_KEY not in state
+
+
+def test_lanes_label_reads_as_a_list() -> None:
+ assert lanes_label(("comment", "git_archaeology", "pr")) == "PRs, history and comments"
+ assert lanes_label(("pr", "comment")) == "PRs and comments"
+ assert lanes_label(("git_archaeology",)) == "history"
+
+
+def test_planned_calls_batch_the_same_candidates_the_miners_send(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ extractor = DecisionExtractor(repo_path=Path("."))
+ monkeypatch.setattr(extractor, "_git_archaeology_candidates", lambda: ([{}] * 7, {}))
+ monkeypatch.setattr(extractor, "_pr_body_candidates", lambda: ([{}] * 25, {}))
+ monkeypatch.setattr(extractor, "_comment_snippets", lambda: [("a", "b")] * 5)
+ # 7 commits in fives, 25 PR bodies in fives, 5 comments in fours.
+ assert extractor.planned_model_calls(("git_archaeology", "pr", "comment")) == 2 + 5 + 2
+ assert extractor.planned_model_calls(("adr", "inline_marker")) == 0
+
+
+def _inputs() -> SimpleNamespace:
+ return SimpleNamespace(
+ graph_builder=SimpleNamespace(graph=lambda: None),
+ git_meta_map={"a.py": {"path": "a.py"}},
+ parsed_files=[],
+ source_map={},
+ )
+
+
+async def test_only_sources_runs_just_those_lanes_and_no_session_pass(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from repowise.core.pipeline.phases import analysis
+
+ seen: dict = {}
+
+ async def fake_extract_all(self, *, on_step=None, enabled_sources=None):
+ seen["sources"] = tuple(enabled_sources)
+ return SimpleNamespace(decisions=[], by_source={}, total_found=0, failures={})
+
+ async def no_session(*_a, **_k):
+ raise AssertionError("session passes must not run for a lane fill")
+
+ monkeypatch.setattr(DecisionExtractor, "extract_all", fake_extract_all)
+ monkeypatch.setattr(analysis, "_add_session_decisions", no_session)
+ monkeypatch.setattr(analysis, "_run_session_discovery", no_session)
+
+ report = await analysis._run_decision_extraction(
+ _repo(tmp_path),
+ llm_client=object(),
+ graph_builder=_inputs().graph_builder,
+ git_meta_map={},
+ parsed_files=[],
+ progress=None,
+ only_sources=("pr", "comment"),
+ )
+ assert report is not None
+ assert seen["sources"] == ("pr", "comment")
+
+
+async def test_a_failed_lane_stays_pending_and_the_rest_persist(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from repowise.core.pipeline import persist
+ from repowise.core.pipeline.phases import analysis
+
+ report = SimpleNamespace(decisions=[object(), object()], failures={"pr": "boom"})
+
+ async def fake_extraction(*_a, **kwargs):
+ assert kwargs["only_sources"] == ("git_archaeology", "pr")
+ return report
+
+ persisted: list = []
+
+ async def fake_persist(result, _session, repo_id):
+ persisted.append((result.decision_report, result.health_report, repo_id))
+
+ class _Session:
+ async def commit(self) -> None: ...
+ async def rollback(self) -> None: ...
+ async def __aenter__(self):
+ return self
+
+ async def __aexit__(self, *_exc) -> None: ...
+
+ monkeypatch.setattr(analysis, "_run_decision_extraction", fake_extraction)
+ monkeypatch.setattr(persist, "persist_analysis", fake_persist)
+
+ outcome = await run_decision_lanes(
+ _Session,
+ "repo-1",
+ _repo(tmp_path),
+ DecisionLanePlan(("git_archaeology", "pr"), calls=3),
+ provider=object(),
+ inputs=_inputs(),
+ )
+ assert outcome.found == 2
+ assert outcome.still_pending == ("pr",)
+ assert persisted == [(report, None, "repo-1")]
+
+
+async def test_an_extraction_that_never_finished_keeps_every_lane_pending(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from repowise.core.pipeline.phases import analysis
+
+ async def fake_extraction(*_a, **_k):
+ return None
+
+ monkeypatch.setattr(analysis, "_run_decision_extraction", fake_extraction)
+ plan = DecisionLanePlan(("git_archaeology", "comment"), calls=2)
+ outcome = await run_decision_lanes(
+ None, "repo-1", _repo(tmp_path), plan, provider=object(), inputs=_inputs()
+ )
+ assert outcome.still_pending == plan.lanes
+
+
+def test_plan_is_none_when_nothing_is_pending(tmp_path: Path) -> None:
+ assert decision_lanes.plan_decision_lanes({}, _repo(tmp_path), _inputs()) is None