Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .indexignore
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/
87 changes: 87 additions & 0 deletions pyproject.toml
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"]
189 changes: 189 additions & 0 deletions scripts/ctx_cli/README.md
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`
26 changes: 26 additions & 0 deletions scripts/ctx_cli/__init__.py
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__"]
14 changes: 14 additions & 0 deletions scripts/ctx_cli/__main__.py
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())
59 changes: 59 additions & 0 deletions scripts/ctx_cli/commands/__init__.py
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)
Loading
Loading