Split CLI into separate lightweight falkordb-cgraph package#630
Open
Split CLI into separate lightweight falkordb-cgraph package#630
falkordb-cgraph package#630Conversation
Co-authored-by: gkorland <753206+gkorland@users.noreply.github.com> Agent-Logs-Url: https://github.com/FalkorDB/code-graph/sessions/b48ad8e3-c799-4522-9425-93bd5e5b2574
Copilot
AI
changed the title
[WIP] Split CLI into separate lightweight package
Split CLI into separate lightweight Mar 24, 2026
falkordb-cgraph package
Contributor
|
@copilot did you also organize the publish workflow to pypi? |
Co-authored-by: gkorland <753206+gkorland@users.noreply.github.com> Agent-Logs-Url: https://github.com/FalkorDB/code-graph/sessions/f73e3404-4a23-4f64-98d4-3ad79f7a340f
Contributor
Author
Done in commit 9f65d25. The
Both jobs use trusted publishing (OIDC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pipx install falkordb-code-graphpulls in the entire server dependency tree (tree-sitter grammars, graphrag-sdk, fastapi, pygit2, multilspy, etc.) becauseapi/__init__.pyeagerly imports everything — even though the CLI only needsfalkordb+typerfor query commands.New
cli/package (falkordb-cgraph)cli/pyproject.toml— declares onlyfalkordb,typer,python-dotenvas dependenciescli/cgraph/main.py— standalone CLI with zero imports fromapi/; implements query commands directly against FalkorDB via CypherCommand behavior
falkordb-cgraphfalkordb-code-graphensure-db,list,search,neighbors,paths,infoindex,index-repofalkordb-code-graphOther changes
Makefile:install-clinow installs fromcli/instead of the root packageREADME.md,AGENTS.md,skills/code-graph/references/management.md: updated install instructions to recommendfalkordb-cgraphfor end users.github/workflows/pypi-publish.yml: added apublish-clijob that builds and publishesfalkordb-cgraphfromcli/dist/in parallel with the existing server publish job, both triggered onv*.*.*tags using trusted OIDC publishingOriginal prompt
Problem
Running
pipx install falkordb-code-graphfreezes the machine because the singlepyproject.tomlbundles all dependencies (tree-sitter grammars, graphrag-sdk, fastapi, uvicorn, pygit2, javatools, multilspy, etc.) even though the CLI only needstyperandfalkordbfor most commands. After install,cgraphmay also not be found due to packaging issues.The root cause is that
api/cli.pylives inside theapi/package, andapi/__init__.pyeagerly imports everything:So even though
cli.pyuses lazy imports for heavy modules, Python resolves theapipackage and pulls in the entire dependency tree.Solution
Split the CLI into its own separate lightweight package. The repo should have two
pyproject.tomlfiles:1. New lightweight CLI package (e.g.
cli/directory)Create a new
cli/directory at the repo root with its ownpyproject.toml:falkordb-cgraph(or similar lightweight name)cgraphcommandtyper,falkordb(which brings in redis), and maybepython-dotenvlist,search,neighbors,paths,info,ensure-dbpipx install falkordb-cgraph— fast, lightweight, just worksThe CLI code should be extracted from
api/cli.pyinto the new package. The query commands (search,neighbors,paths,info,list,ensure-db) only usefalkordbto query the graph database directly — they don't need any analysis pipeline code.For the
indexandindex-repocommands, which DO need the heavy dependencies (tree-sitter, pygit2, project.py, analyzers, etc.), there are a few options:POST /api/analyze_folder,POST /api/analyze_repo) instead of importing the analysis code directly2. Existing server/full package (root
pyproject.toml)The existing
pyproject.tomlat the repo root keeps all the heavy dependencies for the server (fastapi,uvicorn, tree-sitter grammars,graphrag-sdk,pygit2,javatools,multilspy, etc.). This is what gets deployed via Docker oruv runfor the web server + indexing pipeline. It may optionally still expose acgraphentry point for development convenience, but the primary install path for CLI users is the lightweight package.Key architectural point
The new CLI package must NOT import from the
apipackage (sinceapi/__init__.pyeagerly imports everything heavy). It should have its own clean module that only depends onfalkordbfor graph queries andtyperfor the CLI framework. The graph query logic needed by the CLI (prefix_search, get_neighbors, find_paths, stats, get_repos) is straightforward FalkorDB/Cypher queries that can be duplicated or extracted into shared lightweight query code.Current relevant files
pyproject.toml— single package definition with all depsapi/cli.py— CLI entry point (cgraph = "api.cli:app")api/__init__.py— eagerly imports everythingapi/graph.py— Graph class with query methods (only needsfalkordb)api/project.py— importspygit2,validators,SourceAnalyzer(heavy)api/index.py— FastAPI server (heavy)Makefile— hasinstall-clitargetREADME.md— documents CLI installAGENTS.md— documents CLIskills/code-graph/— Claude Code skill references CLIThe following is the prior conversation context from the user's chat exploration (may be truncated):
User: running
pipx install falkordb-code-graphon my local ubuntu is freezing my machine and even after the install finishescgraphcommand is not foundAssistant:
Let me investigate this issue by looking at the repository's setup configuration and installation mechanism.
Assistant: I found two issues causing your problems. Let me look at the dependency list more closely to understand the freeze issue:
Assistant: I can see two issues here. Let me explain what's happening:
1. Machine Freezing During Install
The
falkordb-code-graphpackage has a very heavy dependency tree (26 direct dependencies includinggraphrag-sdk, multipletree-sitter-*grammars,fastapi,uvicorn,pygit2,javatools, etc.). Whenpipxresolves and installs all of these into an isolated virtualenv, it can be extremely CPU and memory intensive — especially if some packages need to be built from source (e.g.,pygit2has native C extensions).Workaround: Try...
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.