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(init): the workspace finish panel matches the single-repo one (#4263)
Raghav Chamadiya0f1fc0c0aa87
diff --git a/packages/cli/src/repowise/cli/commands/generate_cmd/command.py b/packages/cli/src/repowise/cli/commands/generate_cmd/command.pyindex 0abee9199..a6c8dfec9 100644--- a/packages/cli/src/repowise/cli/commands/generate_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/generate_cmd/command.py@@ -33,6 +33,7 @@ from repowise.cli.helpers import ()from repowise.cli.providers import model_run_embedderfrom repowise.cli.ui import load_dotenv+from repowise.cli.ui.mode_names import provider_modelfrom repowise.core.cost_estimator import STRUCTURAL_PAGE_TYPESfrom repowise.core.decision_lanes import set_pending_decision_lanesfrom repowise.core.docs_mode import docs_mode_state_fields, resolve_docs_mode@@ -296,7 +297,7 @@ def generate_command(console.print(f"[bold]repowise generate[/bold] {repo_path}")if provider is not None:console.print(- f"Provider: [cyan]{provider.provider_name}[/cyan] / [cyan]{provider.model_name}[/cyan]"+ f"Provider: [cyan]{provider_model(provider.provider_name, provider.model_name)}[/cyan]")from repowise.core.generation import GenerationConfigdiff --git a/packages/cli/src/repowise/cli/commands/init_cmd/_generate.py b/packages/cli/src/repowise/cli/commands/init_cmd/_generate.pyindex 7d624d3ac..a287b9ac1 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/_generate.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/_generate.py@@ -11,7 +11,7 @@ from rich.table import Tablefrom repowise.cli.cost_gate import spend_phrasefrom repowise.cli.helpers import console, load_config, warnfrom repowise.cli.ui import BRAND, VALUE, print_stage-from repowise.cli.ui.mode_names import INDEX_ONLY+from repowise.cli.ui.mode_names import INDEX_ONLY, provider_modelfrom repowise.core.generation.styles import DEFAULT_STYLEfrom ._exit import COST_UNCONFIRMED_BUILT, COST_UNCONFIRMED_KEPT@@ -264,7 +264,7 @@ def _run_generation_phase(console,"generation",total_phases,- f"Writing documentation with {provider.provider_name} / {provider.model_name}",+ f"Writing documentation with {provider_model(provider.provider_name, provider.model_name)}",)gen_config = GenerationConfig.from_repo_config(diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/_provider.py b/packages/cli/src/repowise/cli/commands/init_cmd/_provider.pyindex 7b0492f87..0cb9d12d0 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/_provider.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/_provider.py@@ -11,7 +11,7 @@ from repowise.cli.errors import reasoned_errorfrom repowise.cli.helpers import console, resolve_explicit_provider_or_prompt, run_asyncfrom repowise.cli.providers import resolve_embedder_choice, template_run_embedderfrom repowise.cli.ui import OK, OWL_SPINNER, VALUE, WARN-from repowise.cli.ui.mode_names import BUILT_FROM_CODE, INDEX_ONLY, written_by+from repowise.cli.ui.mode_names import BUILT_FROM_CODE, INDEX_ONLY, model_name, written_byfrom ._options import InitRun@@ -103,11 +103,14 @@ def _wants_subscription_note(run: InitRun) -> bool:def _print_provider_summary(run: InitRun) -> None:provider = run.providerif not run.is_interactive and not run.no_provider:- mode = written_by(provider.model_name if provider is not None else None)+ mode = written_by(+ model_name(provider.provider_name, provider.model_name) if provider else None+ )console.print(f"[bold]repowise init[/bold] · {mode} · {run.repo_path}")if provider is not None:+ shown = model_name(provider.provider_name, provider.model_name)console.print(- f" Provider: [{VALUE}]{provider.provider_name}[/] / Model: [{VALUE}]{provider.model_name}[/]"+ f" Provider: [{VALUE}]{provider.provider_name}[/] / Model: [{VALUE}]{shown}[/]")console.print(f" Embedder: [{VALUE}]{_stated_embedder(run)}[/]")if run.language != "en":diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/reporting.py b/packages/cli/src/repowise/cli/commands/init_cmd/reporting.pyindex ac1292c07..f71c13339 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/reporting.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/reporting.py@@ -13,16 +13,16 @@ from typing import Anyfrom repowise.cli.helpers import console, load_config, load_statefrom repowise.cli.ui import (- OK,- WARN,build_contextual_next_steps,format_elapsed,- print_completion_panel,)from repowise.cli.ui.finish_panel import FinishFacts, print_finish_panel-from repowise.cli.ui.mode_names import TITLE_WORKSPACE, pages-from repowise.cli.ui.result_panels import serve_step-from repowise.core.index_scope import fast_to_full_command+from repowise.cli.ui.mode_names import pages, provider_model+from repowise.cli.ui.workspace_finish import (+ RepoOutcome,+ WorkspaceFacts,+ print_workspace_finish_panel,+)def _dead_counts(result: Any) -> tuple[int, int]:@@ -221,85 +221,43 @@ def _show_generation_checks(result: Any) -> None:console.print(f" [dim]Generation checks were skipped ({type(exc).__name__}: {exc}).[/dim]")-def _workspace_next_steps(run_mode: str, keyless: bool) -> list[tuple[str, str]]:- """Dashboard and status, then the one upgrade that fits how the repos were indexed."""- if run_mode == "fast":- upgrade = (- fast_to_full_command("<repo>"),- "build a repo's documentation from code and its full git history (no key)",- )- elif keyless:- upgrade = ("repowise generate <repo>", "write a repo's documentation with a model")- else:- upgrade = ("repowise search <query>", "search across all indexed repos")- return [- serve_step("workspace dashboard"),- ("repowise status --workspace", "show workspace status"),- upgrade,- ]---def _upgradable_skips(docs_outcomes: dict[str, tuple[int, str | None]]) -> list[tuple[str, str]]:- """Repos that skipped documentation; a dry run wrote nothing, so it has nothing to upgrade."""- return [- (alias, reason)- for alias, (_count, reason) in docs_outcomes.items()- if reason and reason != "dry run"- ]--def show_workspace_completion(*,selected: list[Any],errors: list,total_files: int,total_symbols: int,- total_pages: int,primary_alias: str,elapsed: float,index_only: bool,provider: Any,docs_outcomes: dict[str, tuple[int, str | None]],- run_mode: str = "standard",+ dry_run: bool = False,+ setup: Any = None,) -> None:- """Render the workspace completion panel + per-repo docs status."""- metrics: list[tuple[str, str]] = [- ("Repositories", f"{len(selected) - len(errors)} indexed"),- ("Total files", f"{total_files:,}"),- ("Total symbols", f"{total_symbols:,}"),- ("Primary repo", primary_alias),- ("Elapsed", format_elapsed(elapsed)),- ]- if not index_only and provider is not None:- metrics.insert(3, ("Documentation", pages(total_pages)))- metrics.insert(4, ("Provider", f"{provider.provider_name} / {provider.model_name}"))- if errors:- metrics.append(("Errors", f"{len(errors)} repos failed"))-- next_steps = _workspace_next_steps(run_mode, index_only or provider is None)+ """Render the workspace finish panel, the per-repo documentation inside it."""+ from repowise.core.index_scope import resolve_index_scope+ failed = dict(errors)+ repos = []+ for repo in selected:+ if repo.alias in failed:+ repos.append(RepoOutcome(repo.alias, error=failed[repo.alias]))+ continue+ count, skipped = docs_outcomes.get(repo.alias, (0, None))+ scope = resolve_index_scope(load_state(repo.path), load_config(repo.path))+ repos.append(RepoOutcome(repo.alias, scope, pages=count, skipped=skipped))+ facts = WorkspaceFacts(+ repos=repos,+ files=total_files,+ symbols=total_symbols,+ primary=primary_alias,+ dry_run=dry_run,+ elapsed=format_elapsed(elapsed),+ provider=None+ if index_only or provider is None+ else provider_model(provider.provider_name, provider.model_name),+ )console.print()- print_completion_panel(console, TITLE_WORKSPACE, metrics, next_steps)+ print_workspace_finish_panel(console, facts, setup=setup)console.print()-- # Honest docs status — print a per-repo summary listing exactly which- # repos generated pages and which were skipped, so the user never has- # to discover empty Docs/Overview in the web UI on their own.- docs_skipped = _upgradable_skips(docs_outcomes)- if docs_outcomes:- console.print("[bold]Documentation[/bold]")- for alias, (count, reason) in docs_outcomes.items():- if reason:- console.print(- f" [{WARN}]✗[/] {alias:<20} [{WARN}]skipped[/] [dim]({reason})[/dim]"- )- else:- console.print(f" [{OK}]✓[/] {alias:<20} [{OK}]{pages(count)}[/]")- if docs_skipped:- first = docs_skipped[0][0]- console.print()- console.print(- f" Run [bold]{fast_to_full_command(first)}[/bold] "- "to build documentation for a skipped repo."- )- console.print()diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.pyindex 4bb7b7866..bae5b328d 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py@@ -292,6 +292,8 @@ class _WorkspaceCtx:embedder_was_requested: boolresolved_commit_limit: intrun_mode: str = "standard"+ #: No workspace config existed before this run, so the MCP entry is new.+ first_index: bool = True#: Mirrors the single-repo flag. A workspace writes project files per repo,#: so --no-editor-setup has to reach every one of them, not just the#: primary's client registration.@@ -462,9 +464,9 @@ def _generate_repo_docs(repo: Any, ctx: _WorkspaceCtx, index: _RepoIndex) -> _Re)docs.skip_reason = "dry run"elif ctx.run_mode == "fast":- # Fast mode is a graph-and-git index by design, as in single-repo init.+ # Fast mode is a graph-and-git index by design, as in single-repo init;+ # the panel names it Index only rather than calling it skipped.console.print()- docs.skip_reason = "fast mode"elif not ctx.index_only and ctx.provider is not None:_generate_repo_with_model(repo, ctx, index, docs)else:@@ -741,7 +743,6 @@ class _WorkspaceTotals:total_files: int = 0total_symbols: int = 0- total_pages: int = 0errors: list[tuple[str, str]] = field(default_factory=list)#: alias -> (generated_count, skip_reason | None), shown in the completion#: panel so the user never has to guess why a repo has no pages.@@ -846,6 +847,9 @@ def _workspace_init(provider, resolved_reasoning = _resolve_workspace_provider(answers, primary_repo, yes=yes, save_key=save_key)+ from repowise.core.workspace.config import WORKSPACE_CONFIG_FILENAME++ first_index = not (root / WORKSPACE_CONFIG_FILENAME).exists()ws_config = _workspace_config(pick, ask=sys.stdin.isatty() and not yes, dry_run=dry_run)if repo_names:console.print(repos_primary_line(ws_config.default_repo, pick))@@ -878,6 +882,7 @@ def _workspace_init(embedder_was_requested=embedder_was_requested,resolved_commit_limit=max(1, min(answers.commit_limit or _DEFAULT_COMMIT_LIMIT, 10000)),run_mode=run_mode,+ first_index=first_index,)totals = _index_workspace_repos(selected, ctx)@@ -893,32 +898,48 @@ def _workspace_init(global_consent=plan.global_consent if plan is not None else None,)+ if not dry_run:+ _offer_workspace_hooks(+ selected,+ totals.errors,+ hook=hook,+ distill_hook=distill_hook,+ yes=yes,+ editor_setup=editor_setup,+ )++ # Last, so Connected and Auto-sync read what the hook offers left behind.show_workspace_completion(selected=selected,errors=totals.errors,total_files=totals.total_files,total_symbols=totals.total_symbols,- total_pages=totals.total_pages,primary_alias=primary_alias,elapsed=time.monotonic() - start,index_only=answers.index_only,provider=provider,docs_outcomes=totals.docs_outcomes,- run_mode=run_mode,+ dry_run=dry_run,+ setup=_workspace_setup(primary_repo.path, ctx),)- if not dry_run:- _offer_workspace_hooks(- selected,- totals.errors,- hook=hook,- distill_hook=distill_hook,- yes=yes,- editor_setup=editor_setup,- )console.print()exit_on_gaps(_workspace_gaps(ctx, totals))+def _workspace_setup(primary_path: Path, ctx: _WorkspaceCtx) -> Any:+ """What editor setup left for the primary repo; None on a dry run, which set nothing up."""+ if ctx.dry_run:+ return None+ from repowise.cli.editor_setup import detect_editor_setup_outcome++ return detect_editor_setup_outcome(+ primary_path,+ interactive=sys.stdin.isatty() and not ctx.yes,+ first_index=ctx.first_index,+ no_editor_setup=not ctx.editor_setup,+ )++def _settle_repos(scan: Any,answers: WorkspaceAnswers,@@ -1104,7 +1125,6 @@ def _index_workspace_repos(selected: list[Any], ctx: _WorkspaceCtx) -> _Workspaccontinuetotals.total_files += outcome.file_counttotals.total_symbols += outcome.symbol_count- totals.total_pages += outcome.pages_generatedtotals.docs_outcomes[repo.alias] = outcome.docs_outcomeif outcome.embed_failed_pages:totals.embed_failures[repo.alias] = outcome.embed_failed_pagesdiff --git a/packages/cli/src/repowise/cli/commands/restyle_cmd.py b/packages/cli/src/repowise/cli/commands/restyle_cmd.pyindex a874c7669..79f18af90 100644--- a/packages/cli/src/repowise/cli/commands/restyle_cmd.py+++ b/packages/cli/src/repowise/cli/commands/restyle_cmd.py@@ -33,6 +33,7 @@ from repowise.cli.helpers import (save_state,)from repowise.cli.ui import load_dotenv+from repowise.cli.ui.mode_names import provider_modelfrom repowise.core.docs_mode import docs_mode_state_fields, resolve_docs_modefrom repowise.core.generation.styles import (DEFAULT_STYLE,@@ -225,7 +226,7 @@ def restyle_command(console.print(f"[bold]repowise restyle[/bold] — {repo_path}\n"f"Style: [cyan]{current}[/cyan] → [cyan]{style}[/cyan] · "- f"Provider: [cyan]{provider.provider_name}[/cyan] / [cyan]{provider.model_name}[/cyan]"+ f"Provider: [cyan]{provider_model(provider.provider_name, provider.model_name)}[/cyan]")if not yes and not click.confirm("This regenerates the whole wiki (LLM calls, cost). Continue?", default=Truediff --git a/packages/cli/src/repowise/cli/commands/update_cmd/reporting.py b/packages/cli/src/repowise/cli/commands/update_cmd/reporting.pyindex ade03cbbb..bf1272c4b 100644--- a/packages/cli/src/repowise/cli/commands/update_cmd/reporting.py+++ b/packages/cli/src/repowise/cli/commands/update_cmd/reporting.py@@ -20,7 +20,12 @@ from repowise.cli.ui import (build_completion_panel,format_elapsed,)-from repowise.cli.ui.mode_names import TITLE_INDEX_UPDATED, TITLE_UPDATED_BUILT_FROM_CODE, pages+from repowise.cli.ui.mode_names import (+ TITLE_INDEX_UPDATED,+ TITLE_UPDATED_BUILT_FROM_CODE,+ pages,+ provider_model,+)from repowise.cli.ui.result_panels import serve_step# Status -> display color, shared by the changed-file summary.@@ -300,7 +305,7 @@ def show_full_completion(if tokens:metrics.append(("Total tokens", f"{tokens:,}"))if provider is not None:- metrics.append(("Provider", f"{provider.provider_name} / {provider.model_name}"))+ metrics.append(("Provider", provider_model(provider.provider_name, provider.model_name)))if cost:metrics.append(("Cost", f"${cost:.3f}"))metrics.append(("Elapsed", format_elapsed(elapsed)))diff --git a/packages/cli/src/repowise/cli/ui/finish_panel.py b/packages/cli/src/repowise/cli/ui/finish_panel.pyindex 791ff2009..4d1089c21 100644--- a/packages/cli/src/repowise/cli/ui/finish_panel.py+++ b/packages/cli/src/repowise/cli/ui/finish_panel.py@@ -92,13 +92,13 @@ def _metrics(facts: FinishFacts) -> list[tuple[str, str]]:return rows-def _line(markup: str, indent: int = 2) -> Padding:+def line(markup: str, indent: int = 2) -> Padding:"""One wrapped line; wrapped text keeps the indent."""return Padding(Text.from_markup(markup), (0, 0, 0, indent))-def _dim(markup: str) -> Padding:- return _line(f"[dim]{markup}[/dim]")+def dim_line(markup: str, indent: int = 2) -> Padding:+ return line(f"[dim]{markup}[/dim]", indent)def connected_lines(setup: Any) -> list[RenderableType]:@@ -119,24 +119,24 @@ def connected_lines(setup: Any) -> list[RenderableType]:# has not loaded it yet.if getattr(setup, "first_index", True):lines.append(- _line(+ line(f"[bold {BRAND}]Restart Claude Code[/] [bold](or run /mcp) ""to load the repowise tools.[/bold]"))else:lines.append(- _dim("Claude Code stays connected; restart it only if the tools are not showing.")+ dim_line("Claude Code stays connected; restart it only if the tools are not showing."))lines.append(- _dim("Cursor or Codex: run [bold]repowise mcp .[/bold] (config in .repowise/mcp.json).")+ dim_line("Cursor or Codex: run [bold]repowise mcp .[/bold] (config in .repowise/mcp.json)."))# The interactive run offered this hook live; a --yes run skipped the offer.if not getattr(setup, "interactive", False) and not getattr(setup, "rewrite_hook_installed", False):lines.append(- _dim("[bold]repowise hook rewrite install[/bold] compresses noisy command output.")+ dim_line("[bold]repowise hook rewrite install[/bold] compresses noisy command output."))return lines@@ -151,9 +151,9 @@ def agent_questions(top_hotspot: str = "") -> list[str]:return ["How is this repo organised, and where should I start reading?", second]-def _ask_lines(top_hotspot: str) -> list[RenderableType]:- lines: list[RenderableType] = [Text(""), _line("[bold]Try asking your agent[/bold]")]- lines += [_line(f'[dim]"{escape(q)}"[/dim]', indent=4) for q in agent_questions(top_hotspot)]+def ask_lines(questions: list[str]) -> list[RenderableType]:+ lines: list[RenderableType] = [Text(""), line("[bold]Try asking your agent[/bold]")]+ lines += [line(f'[dim]"{escape(q)}"[/dim]', indent=4) for q in questions]return lines@@ -172,7 +172,7 @@ def _search_lines(facts: FinishFacts) -> list[RenderableType]:search = facts.scope.get("search") or {}if facts.embed_failed:return [- _line(+ line(f"[{WARN}]Semantic search is unavailable:[/] embedding failed for "f"{facts.embed_failed} page(s). See the warning above, then run ""[bold]repowise reindex[/bold]."@@ -182,7 +182,7 @@ def _search_lines(facts: FinishFacts) -> list[RenderableType]:return []command = search.get("next_command") or "repowise reindex"return [- _dim(+ dim_line(f"Semantic search is off: [bold]{command}[/bold] turns it on "f"({_embed_cost(command)}).")@@ -211,23 +211,26 @@ def _footer(lines = _search_lines(facts)if files_written:lines.append(- _dim(+ dim_line("Files added: "+ escape(", ".join(_relative(repo_path, files_written)))+ " (not gitignored; [bold]--no-editor-setup[/bold] skips them)."))- if setup is not None and not getattr(setup, "editor_setup_disabled", False):- if getattr(setup, "autosync_hook_installed", False):- lines.append(_dim("Auto-sync: on, the index updates after each commit."))- else:- lines.append(- _dim(- "Auto-sync: off. [bold]repowise hook install[/bold] keeps the index "- "synced on commit."- )- )- return lines+ return lines + autosync_lines(setup)+++def autosync_lines(setup: Any) -> list[RenderableType]:+ """Whether the post-commit hook keeps the index synced; silent without editor setup."""+ if setup is None or getattr(setup, "editor_setup_disabled", False):+ return []+ if getattr(setup, "autosync_hook_installed", False):+ return [dim_line("Auto-sync: on, the index updates after each commit.")]+ return [+ dim_line(+ "Auto-sync: off. [bold]repowise hook install[/bold] keeps the index synced on commit."+ )+ ]def build_finish_panel(@@ -268,6 +271,6 @@ def _panel_parts(if connected:body.append(Text(""))body += connected- body += _ask_lines(facts.top_hotspot)+ body += ask_lines(agent_questions(facts.top_hotspot))footer = _footer(facts, setup, repo_path or Path("."), files_written or [])return escape(completion_title(facts.scope)), _metrics(facts), body, footerdiff --git a/packages/cli/src/repowise/cli/ui/mode_names.py b/packages/cli/src/repowise/cli/ui/mode_names.pyindex 0cbe266ec..77d5344c1 100644--- a/packages/cli/src/repowise/cli/ui/mode_names.py+++ b/packages/cli/src/repowise/cli/ui/mode_names.py@@ -27,6 +27,19 @@ TITLE_UPDATED_BUILT_FROM_CODE = "Index updated, documentation built from code"_PROVENANCE_BY_DOCS_MODE = {"none": "none", "deterministic": "template", "llm": "model"}+def model_name(provider: str | None, model: str | None) -> str | None:+ """The model id without a repeated ``<provider>/`` prefix (agent CLIs store one)."""+ if model and provider:+ return model.removeprefix(f"{provider}/") or model+ return model+++def provider_model(provider: str, model: str | None) -> str:+ """``claude_cli / claude-haiku-5-5``, the provider named once."""+ shown = model_name(provider, model)+ return f"{provider} / {shown}" if shown else provider++def written_by(model: str | None = None) -> str:"""``Written by <model>``, or ``Written by a model`` when none is recorded."""return f"Written by {model}" if model else "Written by a model"@@ -54,7 +67,7 @@ def mode_label(scope: Mapping[str, Any]) -> str:if provenance == "unknown" and scope.get("run_mode") == "fast":provenance = "none"provider = scope.get("provider") if isinstance(scope.get("provider"), Mapping) else {}- return provenance_label(provenance, provider.get("model"))+ return provenance_label(provenance, model_name(provider.get("name"), provider.get("model")))def completion_title(scope: Mapping[str, Any]) -> str:diff --git a/packages/cli/src/repowise/cli/ui/plan_screen/state.py b/packages/cli/src/repowise/cli/ui/plan_screen/state.pyindex d7571e5a8..b04f15235 100644--- a/packages/cli/src/repowise/cli/ui/plan_screen/state.py+++ b/packages/cli/src/repowise/cli/ui/plan_screen/state.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport mathfrom dataclasses import dataclass, field+from repowise.cli.ui.mode_names import model_namefrom repowise.cli.ui.repo_scanner import (RepoScanInfo,estimated_model_minutes,@@ -26,7 +27,7 @@ class ModelPrice:@propertydef model_label(self) -> str:"""The model id without a repeated ``<provider>/`` prefix."""- return self.model.removeprefix(f"{self.provider}/")+ return model_name(self.provider, self.model) or self.model@dataclass(frozen=True)diff --git a/packages/cli/src/repowise/cli/ui/workspace_finish.py b/packages/cli/src/repowise/cli/ui/workspace_finish.pynew file mode 100644index 000000000..24d0a3565--- /dev/null+++ b/packages/cli/src/repowise/cli/ui/workspace_finish.py@@ -0,0 +1,221 @@+"""The panel a workspace ``repowise init`` ends on.++Same shape as the single-repo finish panel (:mod:`finish_panel`): counts with a+Scope row, then Connected, questions for the agent, serve first, and a short+receipt. The per-repo documentation list sits inside it.+"""++from __future__ import annotations++from collections import Counter+from collections.abc import Mapping, Sequence+from dataclasses import dataclass, field+from typing import Any++from rich.console import RenderableType+from rich.markup import escape+from rich.padding import Padding+from rich.text import Text++from repowise.cli.ui.brand import ERR, OK, WARN, key_value_table+from repowise.cli.ui.finish_panel import (+ agent_questions,+ ask_lines,+ autosync_lines,+ connected_lines,+ dim_line,+ line,+)+from repowise.cli.ui.mode_names import (+ INDEX_ONLY,+ TITLE_WORKSPACE,+ UNKNOWN_MODE,+ commit_cap_label,+ mode_label,+ pages,+)+from repowise.cli.ui.result_panels import (+ build_completion_panel,+ print_completion_panel,+ serve_step,+)+from repowise.core.index_scope import fast_to_full_command++#: Repos listed by name; the rest are counted, problems listed first.+MAX_REPO_ROWS = 10+_MAX_FOLLOW_UPS = 2+++@dataclass(frozen=True)+class RepoOutcome:+ """One repo's result. ``scope`` is its resolved index scope (empty when it failed)."""++ alias: str+ scope: Mapping[str, Any] = field(default_factory=dict)+ pages: int = 0+ skipped: str | None = None+ error: str | None = None+++@dataclass(frozen=True)+class WorkspaceFacts:+ repos: Sequence[RepoOutcome]+ files: int+ symbols: int+ primary: str+ elapsed: str+ #: ``claude_cli / claude-haiku-5-5``; None for a run without a model.+ provider: str | None = None+ #: Nothing was written, so there is no mode to name and nothing to rebuild.+ dry_run: bool = False+++def _n(count: int, noun: str) -> str:+ return f"{count:,} {noun}" if count == 1 else f"{count:,} {noun}s"+++def _indexed(facts: WorkspaceFacts) -> list[RepoOutcome]:+ return [r for r in facts.repos if not r.error]+++def workspace_scope_line(scopes: Sequence[Mapping[str, Any]]) -> str:+ """``Built from code · git full · last 5,000 commits``, or ``Mixed (...)`` across repos."""+ if not scopes:+ return UNKNOWN_MODE+ labels = Counter(mode_label(s) for s in scopes)+ if len(labels) == 1:+ parts = [next(iter(labels))]+ else:+ counts = ", ".join(f"{_n(n, 'repo')} {label}" for label, n in labels.most_common())+ parts = [f"Mixed ({counts})"]+ tiers = {s.get("git_tier", "unknown") for s in scopes}+ parts.append(f"git {tiers.pop()}" if len(tiers) == 1 else "git mixed")+ caps = {s.get("git_commit_cap") for s in scopes}+ cap = commit_cap_label(caps.pop()) if len(caps) == 1 else None+ if cap:+ parts.append(cap)+ return " · ".join(parts)+++def _metrics(facts: WorkspaceFacts) -> list[tuple[str, str]]:+ indexed = _indexed(facts)+ failed = len(facts.repos) - len(indexed)+ repos = f"{len(indexed):,} indexed" + (f" · {failed:,} failed" if failed else "")+ total_pages = sum(r.pages for r in indexed)+ scopes = [r.scope for r in indexed]+ no_docs = "none (Index only)" if {mode_label(s) for s in scopes} == {INDEX_ONLY} else "none"+ rows = [+ (+ "Scope",+ "Dry run, nothing written"+ if facts.dry_run+ else escape(workspace_scope_line(scopes)),+ ),+ ("Repositories", repos),+ ("Indexed", f"{_n(facts.files, 'file')} · {_n(facts.symbols, 'symbol')}"),+ ("Documentation", pages(total_pages) if total_pages else no_docs),+ ]+ if facts.provider:+ rows.append(("Provider", escape(facts.provider)))+ rows += [("Primary repo", escape(facts.primary)), ("Elapsed", facts.elapsed)]+ return rows+++def _repo_row(repo: RepoOutcome, *, mixed: bool) -> tuple[str, str]:+ name = escape(repo.alias)+ if repo.error:+ return f"[{ERR}]✗[/] {name}", f"[{ERR}]failed[/] [dim]({escape(repo.error)})[/dim]"+ if repo.skipped:+ return (+ f"[{WARN}]✗[/] {name}",+ f"[{WARN}]documentation skipped[/] [dim]({escape(repo.skipped)})[/dim]",+ )+ label = mode_label(repo.scope)+ value = pages(repo.pages) if repo.pages else f"no documentation ({label})"+ if mixed and repo.pages:+ value += f" [dim]· {escape(label)}[/dim]"+ return f"[{OK}]✓[/] {name}", value+++def _repo_lines(facts: WorkspaceFacts) -> list[RenderableType]:+ """The per-repo list, failures and skips first so a cut never hides one."""+ mixed = len({mode_label(r.scope) for r in _indexed(facts)}) > 1+ ordered = sorted(facts.repos, key=lambda r: 0 if r.error else 1 if r.skipped else 2)+ shown = ordered[:MAX_REPO_ROWS]+ table = key_value_table(+ [_repo_row(r, mixed=mixed) for r in shown], label_width=16, label_style="", value_style=""+ )+ lines: list[RenderableType] = [+ Text(""),+ line("[bold]By repository[/bold]"),+ Padding(table, (0, 0, 0, 2)),+ ]+ if len(ordered) > MAX_REPO_ROWS:+ rest = len(ordered) - MAX_REPO_ROWS+ lines.append(+ dim_line(+ f"and {_n(rest, 'more repo')}; "+ "[bold]repowise status --workspace[/bold] lists them all.",+ indent=4,+ )+ )+ return lines+++def workspace_steps(facts: WorkspaceFacts, setup: Any = None) -> list[tuple[str, str]]:+ """``repowise serve``, then the two moves that most need making."""+ candidates: list[tuple[str, str]] = []+ if setup is not None and getattr(setup, "editor_setup_disabled", False):+ candidates.append(("repowise mcp .", "connect an MCP client (Cursor, Codex, Claude Code)"))+ skipped = next((r for r in facts.repos if r.skipped), None)+ if skipped and not facts.dry_run:+ candidates.append(+ (fast_to_full_command(escape(skipped.alias)), "build its documentation")+ )+ elif not facts.provider and not facts.dry_run:+ candidates.append(+ ("repowise generate <repo>", "write a repo's documentation with a model")+ )+ candidates += [+ ('repowise search "<query>"', "search across all indexed repos"),+ ("repowise status --workspace", "show workspace status"),+ ]+ return [serve_step("workspace dashboard"), *candidates[:_MAX_FOLLOW_UPS]]+++def _questions() -> list[str]:+ return [+ "How do these repos depend on each other, and where should I start reading?",+ agent_questions()[1],+ ]+++def build_workspace_finish_panel(facts: WorkspaceFacts, *, setup: Any = None) -> Any:+ """The workspace completion panel: counts, repos, Connected, questions, steps."""+ return build_completion_panel(+ TITLE_WORKSPACE,+ _metrics(facts),+ next_steps=workspace_steps(facts, setup),+ body=_body(facts, setup),+ footer=autosync_lines(setup),+ )+++def print_workspace_finish_panel(console: Any, facts: WorkspaceFacts, *, setup: Any = None) -> None:+ """The workspace panel on a terminal; the same rows as plain lines off one."""+ print_completion_panel(+ console,+ TITLE_WORKSPACE,+ _metrics(facts),+ workspace_steps(facts, setup),+ body=_body(facts, setup),+ footer=autosync_lines(setup),+ )+++def _body(facts: WorkspaceFacts, setup: Any) -> list[RenderableType]:+ body = _repo_lines(facts)+ connected = connected_lines(setup)+ if connected:+ body += [Text(""), *connected]+ return body + ask_lines(_questions())diff --git a/tests/unit/cli/test_update_full_keyless.py b/tests/unit/cli/test_update_full_keyless.pyindex 6bda23183..8c2363292 100644--- a/tests/unit/cli/test_update_full_keyless.py+++ b/tests/unit/cli/test_update_full_keyless.py@@ -213,22 +213,21 @@ def test_update_panel_on_an_index_only_repo_names_update_full(monkeypatch) -> Nodef test_workspace_init_on_fast_repos_names_update_full(monkeypatch) -> None:- from repowise.cli.commands.init_cmd import reporting+ from repowise.cli.ui.workspace_finish import (+ RepoOutcome,+ WorkspaceFacts,+ build_workspace_finish_panel,+ )- out = _plain(monkeypatch, reporting)- reporting.show_workspace_completion(- selected=[object(), object()],- errors=[],- total_files=2,- total_symbols=2,- total_pages=0,- primary_alias="api",- elapsed=1.0,- index_only=True,- provider=None,- docs_outcomes={"api": (0, "fast mode"), "web": (0, "fast mode")},- run_mode="fast",+ facts = WorkspaceFacts(+ repos=[RepoOutcome("api", skipped="fast mode"), RepoOutcome("web", skipped="fast mode")],+ files=2,+ symbols=2,+ primary="api",+ elapsed="1s",)+ out = io.StringIO()+ Console(file=out, width=200).print(build_workspace_finish_panel(facts))printed = out.getvalue()assert "repowise update --repo api --full" in printedassert "repowise generate" not in printeddiff --git a/tests/unit/cli/test_workspace_finish.py b/tests/unit/cli/test_workspace_finish.pynew file mode 100644index 000000000..2b5f476fb--- /dev/null+++ b/tests/unit/cli/test_workspace_finish.py@@ -0,0 +1,125 @@+"""The workspace finish panel: same shape as the single-repo one, repos inside it."""++from __future__ import annotations++import io++from rich.console import Console++from repowise.cli.editor_setup import EditorSetupOutcome+from repowise.cli.ui.mode_names import model_name, provider_model+from repowise.cli.ui.workspace_finish import (+ MAX_REPO_ROWS,+ RepoOutcome,+ WorkspaceFacts,+ build_workspace_finish_panel,+ print_workspace_finish_panel,+)++_WRITTEN = {+ "content_provenance": "model",+ "git_tier": "full",+ "git_commit_cap": 5000,+ "provider": {"name": "claude_cli", "model": "claude_cli/claude-haiku-5-5"},+}+_FROM_CODE = {"content_provenance": "template", "git_tier": "full", "git_commit_cap": 5000}+_INDEX_ONLY = {"content_provenance": "none", "git_tier": "full", "git_commit_cap": 5000}+++def _render(facts: WorkspaceFacts, setup=None) -> str:+ console = Console(record=True, width=100)+ console.print(build_workspace_finish_panel(facts, setup=setup))+ return console.export_text()+++def _facts(repos, provider=None) -> WorkspaceFacts:+ return WorkspaceFacts(+ repos=repos, files=553, symbols=8528, primary=repos[0].alias, elapsed="6m 50s",+ provider=provider,+ )+++def test_one_repo_reads_like_the_single_repo_panel():+ setup = EditorSetupOutcome(claude_code_connected=True, first_index=True)+ facts = _facts(+ [RepoOutcome("beast", _WRITTEN, pages=937)],+ provider=provider_model("claude_cli", "claude_cli/claude-haiku-5-5"),+ )+ text = _render(facts, setup)++ assert "Workspace ready" in text+ assert "Written by claude-haiku-5-5 · git full · last 5,000 commits" in text+ assert "claude_cli / claude-haiku-5-5" in text+ assert "claude_cli/claude" not in text+ assert "553 files · 8,528 symbols" in text+ assert "beast" in text and "937 pages" in text+ assert "Restart Claude Code" in text+ assert "Try asking your agent" in text+ assert "—" not in text+ steps = text[text.index("What's next:") :]+ assert steps.index("repowise serve") < steps.index("repowise search")+ assert len([ln for ln in steps.splitlines() if ln.strip().startswith("│ repowise")]) == 3+++def test_mixed_modes_count_each_and_label_each_repo():+ facts = _facts(+ [+ RepoOutcome("api", _FROM_CODE, pages=12),+ RepoOutcome("web", _FROM_CODE, pages=8),+ RepoOutcome("infra", _INDEX_ONLY),+ RepoOutcome("broken", error="parse failed"),+ ]+ )+ text = _render(facts)++ assert "Mixed (2 repos Built from code, 1 repo Index only) · git full" in text+ assert "3 indexed · 1 failed" in text+ assert "12 pages · Built from code" in text+ assert "no documentation (Index only)" in text+ # Problems lead the list.+ assert text.index("✗ broken") < text.index("✓ api")+ assert "failed (parse failed)" in text+ assert "repowise generate <repo>" in text+++def test_many_repos_are_cut_after_ten_with_the_rest_counted():+ repos = [RepoOutcome(f"svc-{i:02d}", _FROM_CODE, pages=3) for i in range(25)]+ repos[20] = RepoOutcome("svc-20", _FROM_CODE, skipped="no source files")+ text = _render(_facts(repos))++ listed = [f"svc-{i:02d}" for i in range(25) if f"svc-{i:02d}" in text]+ assert len(listed) == MAX_REPO_ROWS+ assert "svc-20" in listed # the skipped one is never cut+ assert f"and {25 - MAX_REPO_ROWS} more repos" in text+ assert "repowise update --repo svc-20 --full" in text+++def test_dry_run_names_no_mode_and_suggests_no_rebuild():+ repos = [RepoOutcome("api", {}, skipped="dry run")]+ facts = WorkspaceFacts(+ repos=repos, files=0, symbols=0, primary="api", elapsed="1s", dry_run=True+ )+ text = _render(facts)++ assert "Dry run, nothing written" in text+ assert "--full" not in text+ assert "Mode unknown" not in text+++def test_model_name_drops_a_repeated_provider_prefix():+ assert model_name("claude_cli", "claude_cli/claude-haiku-5-5") == "claude-haiku-5-5"+ assert model_name("openrouter", "anthropic/claude-sonnet") == "anthropic/claude-sonnet"+ assert model_name(None, "gemini-2.5-flash") == "gemini-2.5-flash"+ assert provider_model("claude_cli", "claude_cli/claude-haiku-5-5") == (+ "claude_cli / claude-haiku-5-5"+ )+ assert provider_model("gemini", "gemini-2.5-flash") == "gemini / gemini-2.5-flash"+++def test_off_a_terminal_the_workspace_panel_is_plain_lines():+ console = Console(file=io.StringIO(), width=100, force_terminal=False)+ print_workspace_finish_panel(console, _facts([RepoOutcome("api", _FROM_CODE, pages=3)]))+ out = console.file.getvalue()++ assert "╭" not in out and "│" not in out+ assert "api" in out and "repowise serve" in out