feat: CLI-first expansion — 10 subcommands + CommonJS require() parsing#95
Conversation
…rsing Adds 10 new CLI subcommands that expose MCP tool functions directly, enabling CLI-first workflows without requiring the MCP server: query, impact, search, flows, flow, communities, community, architecture, large-functions, refactor Also adds CLI post-processing after build/update (fixes tirth8205#93): - Signature computation - FTS5 index rebuild - Execution flow detection - Community detection CommonJS require() parsing (parser.py): - `_js_get_require_target()`: extracts module paths from require(), path.join(), path.resolve(), template literals, dynamic import() - `_extract_js_require_constructs()`: creates IMPORTS_FROM edges - `_collect_js_require_names()`: populates import map for call resolution - Empty-string guards at all call sites - Depth-limited recursion (max_depth=50) for nested require walks Results on test monorepo (14.5K files): - IMPORTS_FROM edges increased 4x (525 → 2,075) - Flows detected: 1,185 - Communities: 605 - FTS indexed: 7,766 nodes CLI UX improvements: - Updated banner and docstring with all new commands - "Graph not built" warning when DB is missing - Argparse validation for flow/community (require --id or --name) - Argparse validation for refactor rename (require --old-name/--new-name) - DELEGATED_COMMANDS skip redundant GraphStore creation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
tirth8205#93) Extract the 4-step post-processing pipeline (signatures, FTS, flows, communities) from tools/build.py into a shared postprocessing.py module. Wire it into CLI build/update and watch mode via callback. - Add code_review_graph/postprocessing.py with run_post_processing() - tools/build.py now delegates to run_post_processing() (-62 lines) - cli.py uses thin _cli_post_process() wrapper (+summary printing) - watch() accepts on_files_updated callback for post-build steps - Hard error (sys.exit(1)) when querying without built graph - Fix: IndexError instead of KeyError in signature except clause - Fix: Callable type annotation instead of Any for watch callback - 9 new tests covering pipeline, idempotency, step isolation Closes tirth8205#93 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update: Shared post-processing pipeline (addresses #93)After reviewing PR #98's approach to fixing #93, I've adopted the same architectural pattern in this PR — but went further: What changed (commit
|
| Aspect | This PR (#95) | PR #98 |
|---|---|---|
Shared postprocessing.py |
✅ | ✅ |
tools/build.py refactored |
✅ (-62 lines) | ✅ (-68 lines) |
watch callback |
✅ | ✅ |
| 10 CLI subcommands | ✅ | ❌ |
| CommonJS require() parsing | ✅ | ❌ |
sys.exit(1) on missing graph |
✅ | ❌ |
| IndexError fix | ✅ | ❌ |
| Callable type annotation | ✅ | ❌ |
| Tests for post-processing | ✅ (9 tests) | ✅ (18 tests) |
If #98 merges first, rebasing this PR is straightforward — just drop the postprocessing.py creation and keep everything else.
Test results
574 passed, 5 skipped, 2 xpassed (full suite)
9 passed (new postprocessing tests)
ruff: 0 errors
|
@murilloimparavel add some more tests, and would suggest to keep a bug fix separate from the feature you are adding. |
Summary
Exposes all 22 MCP tool functions as direct CLI subcommands, enabling CLI-first workflows without requiring the MCP server. Also adds CommonJS
require()parsing for JavaScript codebases that use dynamic imports.New CLI subcommands
query <pattern> <target>impact [--files] [--depth]search <query> [--kind]flows [--sort] [--limit]flow [--id | --name]communities [--sort]community [--id | --name]architecturelarge-functions [--min-lines]refactor <mode>CLI post-processing (fixes #93)
buildandupdatecommands now run the same post-processing as the MCP tool:CommonJS require() parsing
Three new methods in
parser.py:_js_get_require_target(): extracts module paths fromrequire(),path.join(),path.resolve(), template literals,dynamic import()_extract_js_require_constructs(): createsIMPORTS_FROMedges for CommonJS patterns_collect_js_require_names(): populates import map for call resolutionResults on test monorepo (14.5K files):
CLI UX improvements
flow/communityrequire--idor--namerefactor renamerequires--old-name/--new-nameDELEGATED_COMMANDSset skips redundant GraphStore creationTest plan
require('')andrequire()handled gracefully (no crash, no empty edges)bin/crg repos,bin/crg --version,bin/crg --helpwork without--repo🤖 Generated with Claude Code