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.

perf(cli): defer the pipeline import out of the generate engine (#1140)

Raghav Chamadiya432666bbaa71
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 64d0eb54b..bb4894ad4 100644
--- a/packages/cli/src/repowise/cli/commands/generate_cmd/engine.py
+++ b/packages/cli/src/repowise/cli/commands/generate_cmd/engine.py
@@ -17,10 +17,6 @@ from repowise.cli.helpers import console, load_state
from repowise.core.generation.cascade import CascadeMode
from repowise.core.generation.page_selection import PageSelectionIntent
from repowise.core.generation.scope import ScopePlan, build_cost_plans, resolve_scope
-from repowise.core.pipeline.scoped_generation import (
- execute_scoped_generation,
- rehydrate_repo,
-)
# The page types a model writes. Everything else is structural and refreshes on
# `repowise update`, so `generate` never writes one: it works on the concept
@@ -92,6 +88,16 @@ async def run_scoped_generation(
)
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 (
+ execute_scoped_generation,
+ rehydrate_repo,
+ )
+
url = get_db_url_for_repo(repo_path)
engine = create_engine(url)
await init_db(engine)
diff --git a/tests/unit/cli/test_init_ux.py b/tests/unit/cli/test_init_ux.py
index e0d71e16b..0264a96f9 100644
--- a/tests/unit/cli/test_init_ux.py
+++ b/tests/unit/cli/test_init_ux.py
@@ -118,6 +118,28 @@ def test_the_progress_module_does_not_drag_in_the_pipeline_package() -> None:
)
+def test_the_cli_entry_point_does_not_drag_in_the_pipeline_package() -> None:
+ """The guard above covers one module; this covers the whole entry point.
+
+ ``repowise.cli.main`` imports every command module at module scope, so a
+ single ``from repowise.core.pipeline...`` anywhere under it is paid by every
+ invocation — ``repowise --help`` and each post-commit hook run included.
+ Generation is the only thing that needs the package, and it is always
+ reached through a function body, so nothing here should load it.
+ """
+ import subprocess
+ import sys
+
+ probe = (
+ "import repowise.cli.main, sys; "
+ "print([m for m in sys.modules if m.startswith('repowise.core.pipeline')])"
+ )
+ out = subprocess.run([sys.executable, "-c", probe], capture_output=True, text=True, check=True)
+ assert out.stdout.strip() == "[]", (
+ f"importing repowise.cli.main pulled in the pipeline package: {out.stdout.strip()}"
+ )
+
+
# --- keyless provider detection --------------------------------------------