{"id":47685715,"url":"https://github.com/freepeak/leankg","last_synced_at":"2026-04-11T06:01:08.754Z","repository":{"id":346402868,"uuid":"1189734976","full_name":"FreePeak/LeanKG","owner":"FreePeak","description":"LeanKG: Stop Burning Tokens. Start Coding Lean.","archived":false,"fork":false,"pushed_at":"2026-04-09T03:29:00.000Z","size":1307,"stargazers_count":29,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-09T03:35:04.180Z","etag":null,"topics":["ai-agent","claude","claude-code","claude-code-plugin","concise-context","cursor","gemini","graph-database","kilo","knowledge-graph","lean-code","lean-context","llm","mcp","mpc-servers","opencode","opencode-plugin","saving-token","token","token-lean"],"latest_commit_sha":null,"homepage":"https://leankg.com","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FreePeak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":"docs/roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-03-23T16:04:34.000Z","updated_at":"2026-04-09T02:25:07.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/FreePeak/LeanKG","commit_stats":null,"previous_names":["freepeak/leankg"],"tags_count":71,"template":false,"template_full_name":null,"purl":"pkg:github/FreePeak/LeanKG","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreePeak%2FLeanKG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreePeak%2FLeanKG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreePeak%2FLeanKG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreePeak%2FLeanKG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FreePeak","download_url":"https://codeload.github.com/FreePeak/LeanKG/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreePeak%2FLeanKG/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31670383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T17:19:37.612Z","status":"online","status_checked_at":"2026-04-11T02:00:05.776Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agent","claude","claude-code","claude-code-plugin","concise-context","cursor","gemini","graph-database","kilo","knowledge-graph","lean-code","lean-context","llm","mcp","mpc-servers","opencode","opencode-plugin","saving-token","token","token-lean"],"created_at":"2026-04-02T14:49:18.283Z","updated_at":"2026-04-11T06:01:08.746Z","avatar_url":"https://github.com/FreePeak.png","language":"Rust","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/icon.svg\" alt=\"LeanKG\" width=\"80\" height=\"80\"\u003e\n\u003c/p\u003e\n\n# LeanKG\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange?logo=rust\u0026logoColor=white)](https://www.rust-lang.org/)\n[![crates.io](https://img.shields.io/badge/crates.io-latest-orange)](https://crates.io/crates/leankg)\n\n**Lightweight Knowledge Graph for AI-Assisted Development**\n\nLeanKG is a local-first knowledge graph that gives AI coding tools accurate codebase context. It indexes your code, builds dependency graphs, generates documentation, and exposes an MCP server so tools like Cursor, OpenCode, and Claude Code can query the knowledge graph directly. No cloud services, no external databases -- everything runs on your machine with minimal resources.\n\n---\n\n## How LeanKG Helps\n\n```mermaid\ngraph LR\n    subgraph \"Without LeanKG\"\n        A1[AI Tool] --\u003e|Scans entire codebase| B1[10,000+ tokens]\n        B1 --\u003e A1\n    end\n\n    subgraph \"With LeanKG\"\n        A2[AI Tool] --\u003e|13-42 tokens| C[LeanKG Graph]\n        C --\u003e|Targeted subgraph| A2\n    end\n```\n\n**Without LeanKG**: AI scans entire codebase, wasting tokens on irrelevant context (~10,000+ tokens).\n\n**With LeanKG**: AI queries the knowledge graph for targeted context only (13-42 tokens). **98% token saving** for impact analysis.\n\n---\n\n## Installation\n\n### One-Line Install (Recommended)\n\nInstall the LeanKG binary, configure MCP, and add agent instructions for your AI coding tool:\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- \u003ctarget\u003e\n```\n\nThis installs:\n1. LeanKG binary to `~/.local/bin`\n2. MCP configuration for your AI tool\n3. Agent instructions (LeanKG tool usage guidance) to the tool's config directory\n\n**Supported targets:**\n\n| Target | AI Tool | Global Install | Agent Instructions |\n|--------|---------|--------------|-------------------|\n| `opencode` | OpenCode AI | `~/.config/opencode/opencode.json` | `~/.config/opencode/AGENTS.md` |\n| `cursor` | Cursor AI | `~/.cursor/mcp.json` (global) | `~/.cursor/AGENTS.md` |\n| `claude` | Claude Code/Desktop | `~/.config/claude/settings.json` | `~/.config/claude/CLAUDE.md` |\n| `gemini` | Gemini CLI | `~/.config/gemini-cli/mcp.json` | `~/.gemini/GEMINI.md` |\n| `kilo` | Kilo Code | `~/.config/kilo/kilo.json` | `~/.config/kilo/AGENTS.md` |\n\n**Examples:**\n\n```bash\n# Install for OpenCode\ncurl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- opencode\n\n# Install for Cursor (binary only - see per-project setup below)\ncurl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- cursor\n\n# Install for Claude Code\ncurl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- claude\n\n# Install for Gemini CLI\ncurl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- gemini\n\n# Install for Kilo Code\ncurl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- kilo\n\n\n```\n\n### Cursor Installation Details\n\nLeanKG for Cursor includes:\n- **Global MCP server** - `~/.cursor/mcp.json` adds LeanKG to all projects\n- **Plugin** - `~/.cursor/plugins/leankg/` with:\n  - `skills/using-leankg/SKILL.md` - Mandatory LeanKG-first skill\n  - `rules/leankg-rule.mdc` - Auto-trigger rule for code search\n  - `agents/leankg-agents.md` - Agent instructions\n  - `commands/leankg-commands.md` - Command reference\n  - `hooks/session-start` - Session bootstrap hook\n- **User skill preservation** - Other skills in `~/.cursor/skills/` are NOT removed\n\n### Per-Project MCP Setup (Cursor)\n\nLeanKG uses **per-project MCP configuration** for Cursor. This allows LeanKG to automatically detect and index the project you're working on.\n\n**In each project directory, run:**\n```bash\nleankg install    # Creates .cursor/mcp.json in the project\n```\n\nThis creates `.cursor/mcp.json` which Cursor automatically detects when you open that project.\n\n**Example workflow:**\n```bash\n# First time: install LeanKG binary globally\ncurl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- cursor\n\n# Then in each project you want to use LeanKG with:\ncd /path/to/project\nleankg install    # Creates .cursor/mcp.json\n# Restart Cursor or click refresh in MCP settings\n```\n\n### Install via Cargo\n\n```bash\ncargo install leankg\nleankg --version\n```\n\n### Build from Source\n\n```bash\ngit clone https://github.com/FreePeak/LeanKG.git\ncd LeanKG\ncargo build --release\n```\n\n---\n\n## Try Without Install\n\n**Use GitHub Codespaces** to try LeanKG in your browser - no installation required!\n\n1. Go to **github.com/FreePeak/LeanKG**\n2. Click **\"Code\" → \"Create Codespace\"**\n3. LeanKG auto-installs when the codespace starts\n4. In the terminal:\n   ```bash\n   leankg index ./src\n   leankg web\n   ```\n5. Click **\"Open in Browser\"** on port 8080\n\n**Free tier:** 60 hours/month (3 months), then 15 hours/month\n\n---\n\n## Live Demo\n\nTry LeanKG without installing - visit the live demo at **https://leankg.onrender.com**\n\n---\n\n## Update\n\nTo update LeanKG to the latest version, run the same install command:\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- update\n```\n\nThis will replace the existing binary with the latest release while preserving your configuration.\n\n---\n\n## Quick Start\n\n```bash\n# 1. Initialize LeanKG in your project\nleankg init\n\n# 2. Index your codebase\nleankg index ./src\n\n# 3. Start the MCP server (for AI tools)\nleankg serve\n\n# 4. Start the Web UI (for visualization)\n# Open http://localhost:8080 in your browser\nleankg web\n\n# 5. Run commands with RTK-style compression\nleankg run \"cargo test\"\n\n# 6. Compute impact radius for a file\nleankg impact src/main.rs --depth 3\n\n# 7. Check index status\nleankg status\n\n# 8. Watch for changes and auto-index\nleankg watch ./src\n\n# 9. View context metrics (token savings)\nleankg metrics\nleankg metrics --seed  # Seed test data\n```\n\n---\n\n## How It Works\n\n### C4 Model - Level 2: Component Diagram\n\n```mermaid\ngraph TB\n    subgraph \"Developer Machine\"\n        subgraph \"LeanKG System\"\n            direction TB\n            CLI[\"CLI\u003cbr/\u003einit, index, serve, watch\"]\n            \n            subgraph \"Indexer\"\n                Parser[\"Parser\u003cbr/\u003e(tree-sitter)\"]\n                Extractor[\"Extractor\u003cbr/\u003efunctions, classes, imports, calls\"]\n            end\n            \n            DB[(\"CozoDB\u003cbr/\u003eSQLite\")]\n            \n            subgraph \"MCP Server\"\n                Tools[\"MCP Tools\u003cbr/\u003esearch, query, impact, context\"]\n            end\n            \n            subgraph \"Web UI\"\n                Graph[\"Graph Viewer\u003cbr/\u003esigma.js\"]\n                API[\"REST API\u003cbr/\u003e/api/graph/data\"]\n            end\n        end\n        \n        AI[\"AI Tool\u003cbr/\u003e(Claude, Cursor, OpenCode)\"]\n    end\n    \n    CLI --\u003e|init| DB\n    CLI --\u003e|index| Parser\n    Parser --\u003e|parse| Extractor\n    Extractor --\u003e|store| DB\n    CLI --\u003e|serve| MCP\n    DB --\u003e|query| Tools\n    Tools --\u003e|MCP| AI\n    CLI --\u003e|web| API\n    API --\u003e|fetch| Graph\n    Extractor --\u003e|watch| CLI\n```\n\n### Data Flow\n\n```mermaid\ngraph LR\n    subgraph \"1. Index Phase\"\n        A[\"Source Code\u003cbr/\u003e*.rs, *.ts, *.py, *.go, *.java, *.kt, *.tf, *.yml\"] --\u003e B[\"tree-sitter Parser\"]\n        B --\u003e C[\"Code Elements\u003cbr/\u003efunctions, classes, modules\"]\n        B --\u003e D[\"Relationships\u003cbr/\u003eimports, calls, tested_by\"]\n        C --\u003e E[(\"CozoDB\")]\n        D --\u003e E\n    end\n    \n    subgraph \"2. Query Phase\"\n        E --\u003e F[\"MCP Tools\"]\n        F --\u003e G[\"AI Tool Context\u003cbr/\u003e13-42 tokens\"]\n    end\n```\n\n### Node Types in the Graph\n\n| Element Type | Description | Example |\n|--------------|-------------|---------|\n| `function` | Code functions | `src/auth.rs::validate_token` |\n| `class` | Classes and structs | `src/db/models.rs::User` |\n| `module` | Files/modules | `src/db/models.rs` |\n| `document` | Documentation files | `docs/architecture.md` |\n| `doc_section` | Doc headings | `docs/api.md::Usage` |\n\n### Relationship Types\n\n| Type | Direction | Description |\n|------|----------|-------------|\n| `calls` | A → B | Function A calls function B (confidence 0.5-1.0) |\n| `imports` | A → B | Module A imports module B |\n| `contains` | doc → section | Document contains section |\n| `tested_by` | A → B | Code A is tested by test B |\n| `tests` | test → B | Test file tests code B |\n| `documented_by` | A → B | Code A is documented by doc B |\n| `references` | doc → code | Doc references code element |\n| `defines` | A → B | Element A defines element B |\n| `implements` | struct → interface | Struct implements interface |\n| `implementations` | interface → struct | Interface implementations |\n\n**Key Insight:** The graph stores the FULL dependency graph at indexing time. When you query, LeanKG traverses N hops from your target to find all affected elements - no file scanning needed.\n\n---\n\n## MCP Server Setup\n\nSee [MCP Setup](docs/mcp-setup.md) for detailed setup instructions for all supported AI tools.\n\n---\n\n## Agentic Instructions for AI Tools\n\nLeanKG instructs AI coding agents to use LeanKG **first** for codebase queries.\n\n### Quick Rule to Add Manually\n\nAdd this to your AI tool's instruction file:\n\n```markdown\n## MANDATORY: Use LeanKG First\nBefore ANY codebase search/navigation, use LeanKG tools:\n1. `mcp_status` - check if ready\n2. Use tool: `search_code`, `find_function`, `query_file`, `get_impact_radius`, `get_dependencies`, `get_dependents`, `get_tested_by`, `get_context`, `get_review_context`\n3. Only fallback to grep/read if LeanKG fails\n\n| Task | Use |\n|------|-----|\n| Where is X? | `search_code` or `find_function` |\n| What breaks if I change Y? | `get_impact_radius` or `detect_changes` |\n| What tests cover Y? | `get_tested_by` |\n| How does X work? | `get_context`, `get_review_context` |\n| Read file efficiently? | `ctx_read` (with adaptive/full/map/signatures modes) |\n| Intelligent routing? | `orchestrate` (cache-graph-compress flow) |\n```\n\n### Instruction Files (Auto-installed)\n\n| Tool | File | Auto-install |\n|------|------|--------------|\n| Claude Code | `~/.config/claude/CLAUDE.md` | Yes |\n| OpenCode | `~/.config/opencode/AGENTS.md` | Yes |\n| Cursor | `~/.cursor/AGENTS.md` | Yes |\n| KiloCode | `~/.config/kilo/AGENTS.md` | Yes |\n| Codex | `~/.config/codex/AGENTS.md` | Yes |\n| Gemini CLI | `~/.gemini/GEMINI.md` | Yes |\n\nSee [Agentic Instructions](docs/agentic-instructions.md) for detailed setup.\n\n### Per-Tool Setup\n\nAll tools use the same MCP config. The install script handles setup automatically:\n\n| Tool | Install Command | MCP Config Location |\n|------|----------------|-------------------|\n| **OpenCode** | `curl ... \\| bash -s -- opencode` | `~/.config/opencode/opencode.json` |\n| **Cursor** | `curl ... \\| bash -s -- cursor` | `~/.cursor/mcp.json` (global) + `.cursor/mcp.json` (per-project) |\n| **Claude Code** | `curl ... \\| bash -s -- claude` | `~/.config/claude/settings.json` |\n| **Gemini CLI** | `curl ... \\| bash -s -- gemini` | `~/.config/gemini-cli/mcp.json` |\n| **Kilo Code** | `curl ... \\| bash -s -- kilo` | `~/.config/kilo/kilo.json` |\n\n**Manual MCP config** (same for all tools):\n\n```json\n{\n  \"mcpServers\": {\n    \"leankg\": {\n      \"command\": \"leankg\",\n      \"args\": [\"mcp-stdio\", \"--watch\"]\n    }\n  }\n}\n```\n\nSee [MCP Setup](docs/mcp-setup.md) for per-tool configuration details.\n\n---\n\n## Highlights\n\n- **Token Concise** -- Returns 13-42 tokens per query vs 10,000+ tokens for full codebase scan. AI tools get exactly what they need.\n- **Token Saving** -- Up to 98% token reduction for impact analysis queries. Index once, query efficiently forever.\n- **Code Indexing** -- Parse and index Go, TypeScript, Python, Rust, Java, Kotlin, C++, C#, Ruby, and PHP codebases with tree-sitter.\n- **Dependency Graph** -- Build call graphs with `IMPORTS`, `CALLS`, `TESTED_BY`, and `REFERENCES` edges.\n- **Impact Radius** -- Compute blast radius for any file to see downstream impact with severity classification (WILL BREAK, LIKELY AFFECTED, MAY BE AFFECTED).\n- **Cluster Detection** -- Community detection to identify code clusters and their relationships.\n- **Business Logic Mapping** -- Annotate code elements with business logic, link to user stories and features, trace requirements to code.\n- **Auto-Indexing** -- Watch mode automatically updates the index when files change.\n- **Context Metrics** -- Track token savings, F1 scores, and usage statistics per tool call with full query metadata.\n- **Auto Documentation** -- Generate markdown docs from code structure automatically.\n- **MCP Server** -- Expose the graph via MCP protocol for AI tool integration (stdio transport).\n- **File Watching** -- Watch for changes and incrementally update the index.\n- **CLI** -- Single binary with 30+ commands for indexing, querying, annotating, benchmarking, and serving.\n- **RTK Compression** -- RTK-style compression for CLI output and MCP responses (`leankg run`, compress_response on all graph tools).\n- **Orchestrator** -- Intelligent query routing with cache-graph-compress flow and adaptive compression modes.\n- **Traceability** -- Show feature-to-code and requirement-to-code traceability chains via `trace` command.\n- **Documentation Mapping** -- Index docs/ directory, map doc references to code elements, generate `get_doc_for_file` chains.\n- **Graph Viewer** -- Visualize knowledge graph using standalone web UI with sigma.js.\n- **REST API** -- Start a REST API server with authentication (`leankg api-serve --port 8080 --auth`).\n- **Global Registry** -- Manage multiple repositories from a single global registry (`leankg register`, `leankg list`).\n- **Benchmark** -- Compare LeanKG context quality against OpenCode, Gemini, and Kilo CLI tools.\n- **Compression Modes** -- File reading with adaptive modes: `adaptive`, `full`, `map`, `signatures`, `diff`, `aggressive`, `entropy`, `lines`.\n- **Change Detection** -- Pre-commit risk analysis with severity levels (critical/high/medium/low) via `detect_changes` tool.\n- **Multi-Language** -- Also supports Terraform (`.tf`), CI/CD YAML (GitHub workflows, GitLab CI, Azure Pipelines), and Markdown docs.\n- **Test Detection** -- Auto-detects test files across all languages and creates `tested_by` relationships.\n\n---\n\n## Benchmark Results\n\n### Core Value Props: Token Concise + Token Saving\n\n| Metric | Value |\n|--------|-------|\n| **Tokens per query** | 13-42 tokens (vs 10,000+ without) |\n| **Token saving** | Up to 98% for impact analysis |\n| **Context correctness** | F1 0.31-0.46 on complex queries |\n\nLeanKG provides **concise context** (targeted subgraph, not full scan) and **saves tokens** over baseline.\n\n| Metric | Baseline | LeanKG |\n|--------|----------|--------|\n| Tokens (7-test avg) | 150,420 | 191,468 |\n| Token overhead | - | +41,048 |\n| F1 wins | 0 | 2/7 tests |\n| Context correctness | - | Higher |\n\n**Key Findings:**\n- LeanKG wins on F1 context quality in 2/7 tests (navigation, impact analysis)\n- Token overhead: +41,048 tokens across all tests (pending deduplication fix)\n- Context deduplication optimizations pending (see [AB Testing Results](docs/analysis/ab-testing-results-2026-04-08.md))\n\n**Historical (2026-03-25):** 98.4% token savings for impact analysis on Go example\n\nSee [AB Testing Results](docs/analysis/ab-testing-results-2026-04-08.md) for detailed analysis and [benchmark/README.md](benchmark/README.md) for test methodology.\n\n---\n\n## Web UI\n\nStart the web UI with `leankg web` and open [http://localhost:8080](http://localhost:8080).\n\n### Graph Viewer\n\n![LeanKG Graph Visualization](docs/screenshots/graph.png)\n\nThe graph viewer provides an interactive visualization of your codebase's dependency graph. Filter by element type, zoom, pan, and click nodes for details.\n\nSee [Web UI](docs/web-ui.md) for detailed documentation.\n\n---\n\n## Auto-Indexing\n\nLeanKG watches your codebase and automatically keeps the knowledge graph up-to-date. When you modify, create, or delete files, LeanKG incrementally updates the index.\n\n```bash\n# Watch mode - auto-index on file changes\nleankg watch ./src\n\n# Or use the serve command with auto-index enabled\nleankg web --watch ./src\n```\n\nSee [CLI Reference](docs/cli-reference.md#auto-indexing) for detailed commands.\n\n---\n\n## Context Metrics\n\nTrack token savings and usage statistics to understand how LeanKG improves your AI tool's context efficiency.\n\n```bash\n# View metrics summary\nleankg metrics\n\n# View with JSON output\nleankg metrics --json\n\n# Filter by time period\nleankg metrics --since 7d\n\n# Filter by tool name\nleankg metrics --tool search_code\n\n# Seed test data for demo\nleankg metrics --seed\n\n# Reset all metrics\nleankg metrics --reset\n\n# Cleanup old metrics (retention: 30 days default)\nleankg metrics --cleanup --retention 60\n```\n\n### Metrics Schema\n\n| Field | Index | Type | Description |\n|-------|-------|------|-------------|\n| `tool_name` | 0 | String | LeanKG tool name (search_code, get_context, etc.) |\n| `timestamp` | 1 | Int | Unix timestamp of the call |\n| `project_path` | 2 | String | Project root being queried |\n| `input_tokens` | 3 | Int | Tokens in the query |\n| `output_tokens` | 4 | Int | Tokens returned |\n| `output_elements` | 5 | Int | Number of elements returned |\n| `execution_time_ms` | 6 | Int | Tool execution time |\n| `baseline_tokens` | 7 | Int | Tokens a grep scan would use |\n| `baseline_lines_scanned` | 8 | Int | Lines grep would scan |\n| `tokens_saved` | 9 | Int | `baseline_tokens - output_tokens` |\n| `savings_percent` | 10 | Float | `(tokens_saved / baseline_tokens) * 100` |\n| `correct_elements` | - | Int? | Elements matching expected (if ground truth) |\n| `total_expected` | - | Int? | Total expected elements |\n| `f1_score` | - | Float? | Precision/recall F1 |\n| `query_pattern` | - | String? | What was being searched |\n| `query_file` | - | String? | File being queried |\n| `query_depth` | - | Int? | Depth parameter |\n| `success` | - | Bool | Whether the tool succeeded |\n| `is_deleted` | - | Bool | Soft delete flag |\n\n**Note:** Entries with negative savings (where LeanKG outputs more tokens than baseline) are automatically filtered from the display. This ensures metrics only show tools that actually saved tokens.\n\n### Example Output\n\n```\n=== LeanKG Context Metrics ===\n\nTotal Savings: 64,160 tokens across 7 calls\nAverage Savings: 99.4%\nRetention: 30 days\n\nBy Tool:\n  search_code:        2 calls,  avg 100% saved, 25,903 tokens saved\n  get_impact_radius:  1 calls,  avg 99% saved, 24,820 tokens saved\n  get_context:        1 calls,  avg 100% saved, 7,965 tokens saved\n  find_function:      1 calls,  avg 100% saved, 5,972 tokens saved\n```\n\n**Average calculation:** Only entries with positive `savings_percent` contribute to the average. Negative entries (where LeanKG outputs more tokens than baseline) are excluded from both the total count and the percentage calculation.\n\n---\n\n## CLI Commands\n\nFor the complete CLI reference, see [CLI Reference](docs/cli-reference.md).\n\n---\n\n## MCP Tools\n\nSee [MCP Tools](docs/mcp-tools.md) for the complete list of available tools.\n\n---\n\n## Supported AI Tools\n\n| Tool | Integration | Agent Instructions |\n|------|-------------|-------------------|\n| **Claude Code** | MCP | Yes (`CLAUDE.md`) |\n| **OpenCode** | MCP | Yes (`AGENTS.md`) |\n| **Cursor** | MCP | Yes (`AGENTS.md`) |\n| **KiloCode** | MCP | Yes (`AGENTS.md`) |\n| **Codex** | MCP | Yes (`AGENTS.md`) |\n| **Gemini CLI** | MCP | Yes (`AGENTS.md`) |\n\n---\n\n## Roadmap\n\nSee [Roadmap](docs/roadmap.md) for detailed feature planning and implementation status.\n\n---\n\n## Requirements\n\n- Rust 1.70+\n- macOS or Linux\n\n## Supported Languages\n\n| Language | Extensions | Parser |\n|----------|------------|--------|\n| Go | `.go` | tree-sitter-go |\n| TypeScript | `.ts`, `.tsx`, `.js`, `.jsx` | tree-sitter-typescript |\n| Python | `.py` | tree-sitter-python |\n| Rust | `.rs` | tree-sitter-rust |\n| Java | `.java` | tree-sitter-java |\n| Kotlin | `.kt`, `.kts` | tree-sitter-kotlin-ng |\n| C++ | `.cpp`, `.cxx`, `.cc`, `.hpp`, `.h`, `.c` | tree-sitter-cpp |\n| C# | `.cs` | tree-sitter-c-sharp |\n| Ruby | `.rb` | tree-sitter-ruby |\n| PHP | `.php` | tree-sitter-php |\n| Dart | `.dart` | tree-sitter-dart (parser only) |\n| Swift | `.swift` | tree-sitter-swift (parser only) |\n| Terraform | `.tf` | Custom extractor |\n| CI/CD YAML | `.yml`, `.yaml` | Custom extractor (GitHub, GitLab, Azure) |\n| Markdown | `.md` | doc indexer |\n\n## Tech Stack \u0026 Project Structure\n\nSee [Tech Stack](docs/tech-stack.md) for architecture, tech stack details, and project structure.\n\n---\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreepeak%2Fleankg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreepeak%2Fleankg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreepeak%2Fleankg/lists"}