-
Notifications
You must be signed in to change notification settings - Fork 41
Add initial Context-Engine CLI implementation #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a1a9fb2
Add initial Context-Engine CLI implementation
m1rl0k 774fd3f
Update project URL in CLI help text
m1rl0k e186fe2
Remove INSTALLATION.md documentation file
m1rl0k f28c0db
Refactor MCP tool calls to use MCPClient with session handshake
m1rl0k c4c8be3
Improve collection param handling and error reporting
m1rl0k 6c70fc0
Add bridge, collections, and doctor commands to ctx CLI
m1rl0k 3fbb65a
Refactor CLI commands and config resolution
m1rl0k 1672d95
Improve collection selection and persistence in CLI
m1rl0k 61b1f3d
Refactor prune command to return exit codes
m1rl0k b40d41b
Enhance ctx CLI indexing and quickstart path handling
m1rl0k 78b0d42
Enhance quickstart indexing for multi-repo and external paths
m1rl0k ffde715
Improve CLI robustness and Rich library handling
m1rl0k f36576b
Improve test setup for multi-repo and indexing scenarios
m1rl0k 20c7eb0
Prevent duplicate collection recreation in indexing
m1rl0k 94b1b93
Add graph, memory, and pattern CLI commands
m1rl0k 581c282
Add remote sync command and UI helpers to ctx CLI
m1rl0k 6f030ca
Add .indexignore file for indexing exclusions
m1rl0k 1fbc2e9
Enable logical repo reuse for CLI and improve graph status reporting
m1rl0k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| cosqa*.json | ||
| # dev-workspace contains uploaded client workspaces - they get indexed | ||
| # separately via upload service, not as part of the main Context-Engine repo | ||
| dev-workspace/ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| [build-system] | ||
| requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "context-engine" | ||
| version = "0.1.0" | ||
| description = "Context-Engine: Semantic code search and memory system with MCP tools" | ||
| readme = "README.md" | ||
| authors = [ | ||
| {name = "Context-Engine Team", email = "mirlok89@gmail.com"} | ||
| ] | ||
| license = {text = "Business Source License 1.1"} | ||
| requires-python = ">=3.10" | ||
| classifiers = [ | ||
| "Development Status :: 4 - Beta", | ||
| "Intended Audience :: Developers", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| ] | ||
|
|
||
| dependencies = [ | ||
| "qdrant-client>=1.15.0,<1.16.0", | ||
| "fastembed", | ||
| "watchdog", | ||
| "onnxruntime", | ||
| "tokenizers", | ||
| "orjson", | ||
| "tree_sitter>=0.25.0", | ||
| "tree_sitter_python>=0.23.0", | ||
| "tree_sitter_javascript>=0.23.0", | ||
| "tree_sitter_typescript>=0.23.0", | ||
| "tree_sitter_go>=0.23.0", | ||
| "tree_sitter_rust>=0.23.0", | ||
| "tree_sitter_java>=0.23.0", | ||
| "tree_sitter_c>=0.23.0", | ||
| "tree_sitter_cpp>=0.23.0", | ||
| "tree_sitter_ruby>=0.23.0", | ||
| "tree_sitter_c_sharp>=0.23.0", | ||
| "tree_sitter_bash>=0.23.0", | ||
| "tree_sitter_json>=0.24.0", | ||
| "tree_sitter_yaml>=0.7.0", | ||
| "tree_sitter_html>=0.23.0", | ||
| "tree_sitter_css>=0.23.0", | ||
| "tree_sitter_markdown>=0.5.0", | ||
| "mcp==1.17.0", | ||
| "fastmcp==2.12.4", | ||
| "fastapi", | ||
| "uvicorn[standard]", | ||
| "python-multipart", | ||
| "jinja2", | ||
| "openai>=2.11.0", | ||
| "openlit>=1.0.0", | ||
| "python-toon>=0.1.3", | ||
| "rich>=13.0.0", | ||
| "typer>=0.9.0", | ||
| "requests>=2.28.0", | ||
| ] | ||
|
|
||
| [project.optional-dependencies] | ||
| test = [ | ||
| "pytest", | ||
| "pytest-asyncio", | ||
| "anyio", | ||
| "testcontainers", | ||
| ] | ||
|
|
||
| [project.scripts] | ||
| ctx = "scripts.ctx_cli:main" | ||
| ctx-cli = "scripts.ctx_cli:main" | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/m1rl0k/context-engine" | ||
| Documentation = "https://github.com/m1rl0k/context-engine/tree/main/docs" | ||
| Repository = "https://github.com/m1rl0k/context-engine" | ||
|
|
||
| [tool.setuptools.packages.find] | ||
| where = ["."] | ||
| include = ["scripts", "scripts.*"] | ||
|
|
||
| [tool.setuptools] | ||
| include-package-data = true | ||
|
|
||
| [tool.setuptools.package-data] | ||
| "scripts.ctx_cli" = ["*.py", "completions/*.sh", "completions/*.zsh", "completions/*.fish"] | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| # ctx CLI | ||
|
|
||
| Unified command-line interface for Context-Engine. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install -e . | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| Get up and running with a single command: | ||
|
|
||
| ```bash | ||
| ctx quickstart | ||
| ``` | ||
|
|
||
| This will: | ||
| 1. Configure your environment | ||
| 2. Start all services | ||
| 3. Index your codebase | ||
| 4. Warm up embedding models | ||
|
|
||
| ## Commands | ||
|
|
||
| ### Getting Started | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `ctx quickstart` | One command to rule them all - full setup | | ||
| | `ctx init [--full]` | Interactive setup wizard | | ||
| | `ctx doctor` | Diagnose issues with actionable fixes | | ||
|
|
||
| ### Service Management | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `ctx up [--build] [--wait N]` | Start services | | ||
| | `ctx down [--volumes]` | Stop services | | ||
| | `ctx restart [--build]` | Restart services | | ||
| | `ctx status [--json] [--verbose]` | Show stack health, model state, cache stats | | ||
| | `ctx logs [SERVICE] [-f] [--tail N]` | View service logs | | ||
| | `ctx warmup [--status]` | Preload models for fast queries | | ||
|
|
||
| ### Search & Retrieval | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `ctx search <query> [options]` | Semantic code search | | ||
| | `ctx answer <query> [options]` | LLM-generated answers with citations | | ||
| | `ctx memory store <info> [--tags]` | Store knowledge in memory | | ||
| | `ctx memory find <query> [--kind]` | Search stored memories | | ||
| | `ctx graph callers <symbol>` | Find who calls a symbol | | ||
| | `ctx graph definition <symbol>` | Find where symbol is defined | | ||
| | `ctx graph importers <symbol>` | Find what imports a module | | ||
| | `ctx graph callees <symbol>` | Find what a symbol calls | | ||
| | `ctx pattern <query> [--mode]` | Find structurally similar code | | ||
|
|
||
| ### Indexing | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `ctx index [path] [--watch]` | Index codebase (local/mounted) | | ||
| | `ctx sync [path] [--watch]` | Upload/sync to remote server | | ||
| | `ctx prune [--collection]` | Remove stale entries | | ||
| | `ctx collections list` | List all collections | | ||
| | `ctx collections create NAME` | Create new collection | | ||
| | `ctx collections delete NAME` | Delete collection | | ||
|
|
||
| ### Remote Sync (VS Code Extension Equivalent) | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `ctx sync` | Force sync current directory | | ||
| | `ctx sync --watch` | Watch mode with auto-sync | | ||
| | `ctx sync --git-history` | Include git commit metadata | | ||
| | `ctx sync --endpoint URL` | Use custom upload endpoint | | ||
|
|
||
| ### IDE Integration | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `ctx bridge generate claude` | Generate Claude Desktop config | | ||
| | `ctx bridge generate cursor` | Generate Cursor IDE config | | ||
| | `ctx bridge generate windsurf` | Generate Windsurf config | | ||
| | `ctx bridge generate all` | Generate all IDE configs | | ||
|
|
||
| ### Configuration | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `ctx config [--get K] [--set K=V]` | View/edit configuration | | ||
| | `ctx completion [bash\|zsh\|fish]` | Shell completions | | ||
|
|
||
| ## Examples | ||
|
|
||
| ```bash | ||
| # Quick start for new users | ||
| ctx quickstart | ||
|
|
||
| # Check system health | ||
| ctx doctor | ||
|
|
||
| # Start services and monitor logs | ||
| ctx up --build | ||
| ctx logs indexer -f | ||
|
|
||
| # Search the codebase | ||
| ctx search "database connection" --language python --snippet | ||
| ctx answer "how does the indexing pipeline work?" | ||
|
|
||
| # Memory operations | ||
| ctx memory store "JWT tokens are used for auth" --kind explanation --tags topic=auth | ||
| ctx memory find "authentication" --limit 5 | ||
|
|
||
| # Symbol graph navigation | ||
| ctx graph callers authenticate --depth 2 | ||
| ctx graph definition MCPClient --language python | ||
| ctx graph importers qdrant_client | ||
|
|
||
| # Pattern search | ||
| ctx pattern "try: ... except: pass" --snippet | ||
| ctx pattern "retry with backoff" --mode description | ||
|
|
||
| # Manage collections | ||
| ctx collections list | ||
| ctx collections create my-project | ||
| ctx collections switch my-project | ||
|
|
||
| # Generate IDE configs | ||
| ctx bridge generate all | ||
|
|
||
| # Monitor and maintain | ||
| ctx status --verbose | ||
| ctx warmup --status | ||
| ctx index --watch | ||
| ``` | ||
|
|
||
| ## Shell Completion | ||
|
|
||
| ```bash | ||
| eval "$(ctx completion bash)" # Bash | ||
| eval "$(ctx completion zsh)" # Zsh | ||
| ctx completion fish | source # Fish | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Config loaded from `./.ctxrc` or `~/.ctxrc`: | ||
|
|
||
| ```ini | ||
| [indexer] | ||
| url = http://localhost:8003 | ||
| timeout = 30 | ||
|
|
||
| [memory] | ||
| url = http://localhost:8002 | ||
|
|
||
| [search] | ||
| default_limit = 10 | ||
| default_collection = codebase | ||
|
|
||
| [docker] | ||
| compose_file = compose.yaml | ||
| ``` | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| | Variable | Description | Default | | ||
| |----------|-------------|---------| | ||
| | `MCP_INDEXER_URL` | Indexer HTTP endpoint | `http://localhost:8003/mcp` | | ||
| | `MCP_MEMORY_URL` | Memory HTTP endpoint | `http://localhost:8002/mcp` | | ||
| | `COLLECTION_NAME` | Default collection | `codebase` | | ||
| | `COMPOSE_FILE` | Docker compose file | `compose.yaml` | | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| Run the doctor command to diagnose issues: | ||
|
|
||
| ```bash | ||
| ctx doctor | ||
| ``` | ||
|
|
||
| Common fixes: | ||
| - **Services not running**: `ctx up` | ||
| - **Models not loaded**: `ctx warmup` | ||
| - **Stale index**: `ctx prune && ctx index` | ||
| - **Config issues**: `ctx init --env-only` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright 2025 John Donalson and Context-Engine Contributors. | ||
| # Licensed under the Business Source License 1.1. | ||
| """ | ||
| Context-Engine CLI - Unified command-line interface for MCP tools. | ||
|
|
||
| This package provides a production-ready CLI for interacting with the | ||
| Context-Engine MCP servers (Memory and Indexer). | ||
| """ | ||
|
|
||
| __version__ = "0.1.0" | ||
| __author__ = "Context-Engine Team" | ||
|
|
||
| try: | ||
| from scripts.ctx_cli.main import main | ||
| except ImportError: | ||
| # Allow import to succeed even if dependencies aren't installed | ||
| def main(): | ||
| """Placeholder main function when dependencies are missing.""" | ||
| print("Error: ctx_cli dependencies not installed. Run: pip install -e .") | ||
| return 1 | ||
|
|
||
| # For backward compatibility | ||
| app = main | ||
|
|
||
| __all__ = ["main", "app", "__version__"] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """ | ||
| Entry point for running the CLI as a module. | ||
|
|
||
| Usage: | ||
| python -m scripts.ctx_cli | ||
| python -m scripts.ctx_cli --help | ||
| python -m scripts.ctx_cli status | ||
| """ | ||
|
|
||
| import sys | ||
| from scripts.ctx_cli.main import main | ||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright 2025 John Donalson and Context-Engine Contributors. | ||
| # Licensed under the Business Source License 1.1. | ||
| """ | ||
| Context-Engine CLI commands package. | ||
|
|
||
| Available commands: | ||
| - quickstart: One command setup - init, start, index, and warmup | ||
| - up: Start services | ||
| - down: Stop services | ||
| - restart: Restart services | ||
| - status: Show stack status | ||
| - doctor: Comprehensive health check | ||
| - logs: View service logs | ||
| - init: Interactive setup wizard | ||
| - search: Search the codebase | ||
| - answer: Get natural language answer with citations | ||
| - memory: Store and search knowledge entries | ||
| - graph: Navigate symbol relationships (callers, definitions, imports) | ||
| - pattern: Find structurally similar code patterns | ||
| - index: Index codebase into Qdrant | ||
| - sync: Upload/sync workspace to remote Context-Engine | ||
| - prune: Remove stale entries from index | ||
| - collections: Manage Qdrant collections | ||
| - bridge: Manage MCP bridge and generate IDE configs | ||
| - warmup: Preload models to reduce first-query latency | ||
| - completion: Shell completion scripts | ||
| """ | ||
|
|
||
| from . import status, init, answer, index, prune, completion, lifecycle, search, config, logs, warmup, collections, bridge, quickstart, doctor, memory, graph, pattern, sync | ||
|
|
||
| # List of all command modules | ||
| COMMANDS = [ | ||
| quickstart, # The ONE COMMAND to rule them all | ||
| lifecycle, # up, down, restart commands | ||
| status, | ||
| doctor, | ||
| logs, | ||
| init, | ||
| search, | ||
| answer, | ||
| memory, # Memory store/find | ||
| graph, # Symbol graph navigation | ||
| pattern, # Pattern search | ||
| index, | ||
| sync, # Remote upload/sync (like VS Code extension) | ||
| prune, | ||
| collections, | ||
| warmup, | ||
| config, | ||
| bridge, | ||
| completion, | ||
| ] | ||
|
|
||
|
|
||
| def register_all_commands(subparsers): | ||
| """Register all available commands with the argument parser.""" | ||
| for command in COMMANDS: | ||
| command.register_command(subparsers) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.