Run the dependency analysis, write results to workspace files, and return a compact summary with file paths.
(
arguments: Dict[str, Any],
store: SessionStore,
)
| 280 | |
| 281 | |
| 282 | def handle_analyze_repo( |
| 283 | arguments: Dict[str, Any], |
| 284 | store: SessionStore, |
| 285 | ) -> str: |
| 286 | """Run the dependency analysis, write results to workspace files, |
| 287 | and return a compact summary with file paths.""" |
| 288 | repo_path = Path(arguments["repo_path"]).expanduser().resolve() |
| 289 | if not repo_path.exists(): |
| 290 | return json.dumps({"error": f"Repository not found: {repo_path}"}) |
| 291 | |
| 292 | output_dir = Path(arguments.get("output_dir", str(repo_path / "docs"))).expanduser().resolve() |
| 293 | output_dir.mkdir(parents=True, exist_ok=True) |
| 294 | |
| 295 | # Build a minimal Config for the dependency analyzer (no LLM fields used) |
| 296 | from codewiki.src.config import Config |
| 297 | config = Config( |
| 298 | repo_path=str(repo_path), |
| 299 | output_dir=str(output_dir / "temp"), |
| 300 | dependency_graph_dir=str(output_dir / "temp" / "dependency_graphs"), |
| 301 | docs_dir=str(output_dir), |
| 302 | max_depth=2, |
| 303 | llm_base_url="not-needed", |
| 304 | llm_api_key="not-needed", |
| 305 | main_model="unused", |
| 306 | cluster_model="unused", |
| 307 | use_gitignore=arguments.get("use_gitignore", True), |
| 308 | ) |
| 309 | |
| 310 | # Apply optional include/exclude patterns |
| 311 | include = arguments.get("include_patterns") |
| 312 | exclude = arguments.get("exclude_patterns") |
| 313 | if include or exclude: |
| 314 | agent_instructions: Dict[str, Any] = {} |
| 315 | if include: |
| 316 | agent_instructions["include_patterns"] = [p.strip() for p in include.split(",")] |
| 317 | if exclude: |
| 318 | agent_instructions["exclude_patterns"] = [p.strip() for p in exclude.split(",")] |
| 319 | config.agent_instructions = agent_instructions |
| 320 | |
| 321 | from codewiki.src.be.dependency_analyzer import DependencyGraphBuilder |
| 322 | builder = DependencyGraphBuilder(config) |
| 323 | components, leaf_nodes = builder.build_dependency_graph() |
| 324 | |
| 325 | # Create the session (generates session_id) |
| 326 | session = store.create( |
| 327 | repo_path=str(repo_path), |
| 328 | output_dir=str(output_dir), |
| 329 | components=components, |
| 330 | leaf_nodes=leaf_nodes, |
| 331 | ) |
| 332 | |
| 333 | # Record the analyzed commit now — close_session uses it as the |
| 334 | # incremental-update baseline in metadata.json. |
| 335 | from codewiki.cli.utils.repo_validator import get_git_commit_hash |
| 336 | session.analyzed_commit = get_git_commit_hash(repo_path) or None |
| 337 | |
| 338 | # Create the workspace with the real session_id |
| 339 | workspace = SessionWorkspace(repo_path, session.session_id) |