Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 38 additions & 35 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CodeGraph AI Assistant Skill Document
# CodeGraph: AI Assistant Skill Document

CodeGraph indexes codebases into a graph database (FalkorDB) and provides MCP tools for code search, context retrieval, repository analysis, knowledge management, and raw graph queries.

Expand All @@ -21,9 +21,9 @@ Configuration does not index the project. Reindexing parses structure first and

## Tool Reference (5 tool groups, 25 actions)

### 1. `search` Find code and knowledge
### 1. `search`: Find code and knowledge

Vector search + cross-encoder reranking. Returns enriched results with complexity, callers, callees, importerCount, linkedKnowledge.
Vector search with optional cross-encoder reranking when a supported provider key is configured. Without one, search keeps vector-search ordering. Local 768-dimension embeddings remain the no-key default. Results include complexity, callers, callees, importerCount, and linkedKnowledge.

| Action | Use When | Required Params |
|--------|----------|-----------------|
Expand All @@ -40,33 +40,33 @@ search({ action: "context", file: "src/service.ts", includeRelationships: true }
search({ action: "context", symbol: "enrichedSearchV2" })
```

**Multi-step questions:** for complex queries that need iterative refinement, chain `search` calls in your agent — examine results, refine the query, search again. CodeGraph stays focused on per-call retrieval quality; orchestration is the agent's job.
**Multi-step questions:** for complex queries that need iterative refinement, chain `search` calls in your agent. Examine results, refine the query, and search again. CodeGraph stays focused on per-call retrieval quality; orchestration is the agent's job.

### 2. `knowledge` Knowledge graph (8 actions)
### 2. `knowledge`: Knowledge graph (8 actions)

| Action | Use When | Required Params |
|--------|----------|-----------------|
| `store` | Store entities, relationships, or extract facts from text | `text` |
| `add` | Ingest a document (PDF, DOCX, HTML, CSV, URL, or raw text) | `input` |
| `recall` | "What do I know about X?" with temporal and speaker queries | `text` |
| `recall` | "What do I know about X?", with temporal and speaker queries | `text` |
| `query_knowledge` | Search entities by type, text, source, or fact meaning | (any filter) |
| `ingest_conversation` | Ingest multi-turn conversation with speaker attribution | `text` |
| `resolve_entities` | On-demand 3-tier entity deduplication | (none) |
| `decay_and_prune` | Temporal maintenance decay relevance, prune stale entities | (none) |
| `decay_and_prune` | Temporal maintenance: decay relevance, prune stale entities | (none) |
| `get_knowledge_stats` | Memory statistics | (none) |

**Recall parameters (all optional):**
- `at` ISO timestamp for point-in-time: "what was true on March 1st?"
- `from` / `to` time range: "what changed this week?"
- `timeline: true` full chronological history including superseded facts
- `minRelevance` relevance-weighted search (0-1 threshold)
- `speaker` "what has Alice said?" (follows SAID relationships)
- `includeHistory: true` include invalidated/superseded facts
- `at`: ISO timestamp for point-in-time: "what was true on March 1st?"
- `from` / `to`: time range: "what changed this week?"
- `timeline: true`: full chronological history including superseded facts
- `minRelevance`: relevance-weighted search (0-1 threshold)
- `speaker`: "what has Alice said?" (follows SAID relationships)
- `includeHistory: true`: include invalidated/superseded facts

**Query parameters (all optional):**
- `semanticQuery` find entities by meaning, not just text
- `searchFacts` search relationship explanations by meaning
- `source` filter by provenance/sampleId prefix
- `semanticQuery`: find entities by meaning, not just text
- `searchFacts`: search relationship explanations by meaning
- `source`: filter by provenance/sampleId prefix

**Examples:**
```
Expand All @@ -84,7 +84,7 @@ knowledge({ action: "ingest_conversation", text: "Alice: let's use Redis\nBob: a
knowledge({ action: "resolve_entities" })
```

### 3. `codebase` Index management
### 3. `codebase`: Index management

| Action | Use When | Required Params |
|--------|----------|-----------------|
Expand All @@ -96,6 +96,8 @@ knowledge({ action: "resolve_entities" })
| `ping` | Test connectivity | (none) |
| `profile` | Get a fast static and dynamic project snapshot | (none) |

The `profile` handler is intended to accept an optional absolute `projectPath` filter and an optional `limit` (default 10). Its published input schema currently omits both properties, so clients that enforce the schema cannot reliably send them. Calling `profile` without either property remains schema-valid and returns the unfiltered snapshot.

Widen the persisted git history window during reindexing when deeper history is needed:
```
codebase({ action: "reindex", mode: "full", scope: "/path/to/project", historySince: "2024-01-01T00:00:00Z", historyMaxCommits: 20000 })
Expand Down Expand Up @@ -141,17 +143,17 @@ query({ cypher: "MATCH (f:Function) WHERE f.name CONTAINS $name RETURN f.name, f
## Workflow Guides

### Codebase Onboarding
1. `codebase({ action: "stats" })` get overview
2. `search({ action: "find", query: "main index app" })` find entry points
3. `search({ action: "context", file: "<entry_point>", includeRelationships: true })` understand architecture
1. `codebase({ action: "stats" })`: get overview
2. `search({ action: "find", query: "main index app" })`: find entry points
3. `search({ action: "context", file: "<entry_point>", includeRelationships: true })`: understand architecture

### Find and Understand Code
1. `search({ action: "find", query: "authentication" })` find relevant symbols
2. `search({ action: "context", symbol: "<result>" })` see callers, imports, relationships
3. `codebase({ action: "source", path: "<file>" })` read the actual code
1. `search({ action: "find", query: "authentication" })`: find relevant symbols
2. `search({ action: "context", symbol: "<result>" })`: see callers, imports, relationships
3. `codebase({ action: "source", path: "<file>" })`: read the actual code

### Unified Search (Code + Knowledge)
1. `search({ action: "find", query: "retry logic", searchScope: "all" })` search both code and knowledge
1. `search({ action: "find", query: "retry logic", searchScope: "all" })`: search both code and knowledge
2. Results include both code symbols and knowledge entities, ranked by RRF fusion

### Analyze Change Risk
Expand All @@ -164,27 +166,28 @@ query({ cypher: "MATCH (f:Function) WHERE f.name CONTAINS $name RETURN f.name, f
2. `analyze({ action: "dead_code", projectPath: "<absolute-project-path>" })`: review unreferenced export candidates
3. `analyze({ action: "hotspots", projectPath: "<absolute-project-path>" })`: rank frequently changed files
4. `analyze({ action: "change_coupling", projectPath: "<absolute-project-path>" })`: find correlated file changes
5. Treat historyCoverage as the observed indexed window, not all-time repository history
5. `analyze({ action: "ownership", projectPath: "<absolute-project-path>" })`: review inferred per-file authorship contributors
6. Treat `historyCoverage` as the observed indexed window, not all-time repository history. Ownership reflects authorship inferred from that indexed history, not CODEOWNERS, review activity, expertise, or current team assignment.

### Ingest Documents
1. `knowledge({ action: "add", input: "/path/to/spec.pdf" })` auto-detects format, chunks, extracts entities
1. `knowledge({ action: "add", input: "/path/to/spec.pdf" })`: auto-detects format, chunks, extracts entities
2. Supported: PDF, DOCX, HTML, CSV, URLs, raw text

### Temporal Knowledge Queries
1. `knowledge({ action: "recall", text: "auth system", at: "2026-01-15T00:00:00Z" })` point-in-time reconstruction
2. `knowledge({ action: "recall", text: "decisions", from: "2026-03-01", to: "2026-03-31" })` what changed in March
3. `knowledge({ action: "recall", text: "AuthModule", timeline: true })` full entity history
1. `knowledge({ action: "recall", text: "auth system", at: "2026-01-15T00:00:00Z" })`: point-in-time reconstruction
2. `knowledge({ action: "recall", text: "decisions", from: "2026-03-01", to: "2026-03-31" })`: what changed in March
3. `knowledge({ action: "recall", text: "AuthModule", timeline: true })`: full entity history

### Knowledge Capture
1. `knowledge({ action: "store", text: "<conversation>" })` extract and store entities
2. `knowledge({ action: "recall", text: "<topic>" })` retrieve what was captured
1. `knowledge({ action: "store", text: "<conversation>" })`: extract and store entities
2. `knowledge({ action: "recall", text: "<topic>" })`: retrieve what was captured

## Anti-Patterns

- **Don't** pass raw user input to `query` — use parameterized queries with `params`
- **Don't** fetch everything — always use `limit` and `scope` to constrain results
- **Don't** pass raw user input to `query`. Use parameterized queries with `params`
- **Don't** fetch everything. Always use `limit` and `scope` to constrain results
- **Don't** use `query` for things `search` or `analyze` can do. The purpose-built tools have safer bounds and clearer caveats.
- **Don't** call `codebase({ action: "reindex" })` repeatedly — use `mode: "incremental"` (the default)
- **Don't** call `codebase({ action: "reindex" })` repeatedly. Use `mode: "incremental"` (the default)

## Environment

Expand All @@ -196,6 +199,6 @@ query({ cypher: "MATCH (f:Function) WHERE f.name CONTAINS $name RETURN f.name, f
- **Build**: `pnpm build` (monorepo with Turbo)
- **Test**: `pnpm test`

## Public Benchmark CGBench v1
## Public Benchmark: CGBench v1

Cross-system retrieval benchmark at `benchmarks/cgbench-v1/`. Compares CodeGraph against 7 named competitors on a uniform 6-task battery (NL→code, structural, multi-hop, bitemporal, linked code+knowledge, document ingestion). Results published in [`benchmarks/cgbench-v1/BENCHMARKS.md`](benchmarks/cgbench-v1/BENCHMARKS.md). Methodology: [`benchmarks/cgbench-v1/COMPETITORS.md`](benchmarks/cgbench-v1/COMPETITORS.md), [`benchmarks/cgbench-v1/questions/REVIEW.md`](benchmarks/cgbench-v1/questions/REVIEW.md).
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Include the commands and results in the pull request. CI repeats the repository
- Keep public functions typed and validate data at system boundaries.
- Add tests for new behavior and regressions.
- Update user-facing documentation when commands, configuration, or behavior changes.
- For documentation and landing-page changes, avoid the em dash character U+2014 and verify links and factual copy against merged source.
- Call out security, compatibility, migration, and release effects.
- Never commit generated `dist` directories, secrets, `.env` files, local `.codegraph` data, or benchmark output containing local paths.

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CodeGraph turns source code and project knowledge into a searchable graph for AI

## Access the project

- [Live application](https://v0-landing-page-build-kappa-virid.vercel.app)
- [Landing page](https://v0-landing-page-build-kappa-virid.vercel.app)
- [Source code](https://github.com/Phoenixrr2113/codebase-graph)
- [Issues](https://github.com/Phoenixrr2113/codebase-graph/issues)
- [Discussions](https://github.com/Phoenixrr2113/codebase-graph/discussions)
Expand All @@ -26,6 +26,7 @@ The public npm package is named `codegraph-mcp`. Its npm link, version badge, an
- Stores project facts with `valid_at` and `invalid_at` timestamps for point-in-time queries.
- Supports first-class TypeScript, JavaScript, Python, Go, Rust, and Markdown parsing, with generic tree-sitter support for additional languages.
- Runs with embedded FalkorDBLite on Linux x64 and Apple silicon macOS, or an external FalkorDB service on any supported Node.js platform. Apple silicon requires Homebrew `libomp` and `openssl@3` runtime libraries.
- Explores exact graph totals in Files or Symbols view with most-connected-first windows, Previous/Next paging, append-style loading, in-place neighbor expansion, and a Files-view toggle for unresolved external modules.
- Exposes `analyze`, `codebase`, `knowledge`, `query`, and `search` MCP tools.

## Choose how to start
Expand All @@ -50,17 +51,17 @@ Add this server configuration to an MCP client:
In the first conversation, ask the agent to check CodeGraph status:

```json
{"action":"status"}
{"method":"tools/call","params":{"name":"codebase","arguments":{"action":"status"}}}
```

On a fresh install, `codebase` status returns `configured: false` and `setupRequired: true`. An empty database is a valid first run. Configure one absolute project path, then start a full index:

```json
{"action":"configure","projectAction":"set","projects":["/absolute/path/to/project"]}
{"method":"tools/call","params":{"name":"codebase","arguments":{"action":"configure","projectAction":"set","projects":["/absolute/path/to/project"]}}}
```

```json
{"action":"reindex","mode":"full","scope":"/absolute/path/to/project"}
{"method":"tools/call","params":{"name":"codebase","arguments":{"action":"reindex","mode":"full","scope":"/absolute/path/to/project"}}}
```

Configuration saves the project but does not index it. The full reindex parses structure first and then finishes embeddings. With the local provider, `codebase` status includes model load and indexing state while work is running.
Expand All @@ -73,7 +74,7 @@ Start the dashboard directly from the package:
npx -y --package codegraph-mcp codegraph-dashboard
```

Open the URL printed by the process. A fresh database opens on the setup flow. Confirm storage and embeddings, use Browse to choose a folder, then select Index project. The page shows model download and indexing progress, finishes remaining embeddings automatically, and reports file, symbol, edge, and embedding counts before opening the graph explorer.
Open the URL printed by the process. A fresh database opens on the setup flow. Confirm storage and embeddings, choose Browse to select a folder, then select Index project. The page shows model download and indexing progress, finishes remaining embeddings automatically, and reports file, symbol, edge, and embedding counts before opening the graph explorer.

The dashboard and MCP server are separate entry points. They can run at the same time against the same data path.

Expand Down Expand Up @@ -125,13 +126,13 @@ Provider, model, and dimension are stored with the graph. If any of them changes

| Tool | Purpose |
| --- | --- |
| `analyze` | Inspect impact, call hierarchy, cycles, dead-code candidates, hotspots, and change coupling |
| `analyze` | Inspect impact, call hierarchy, cycles, dead-code candidates, hotspots, change coupling, and ownership inferred from indexed git history |
| `search` | Find code and project knowledge by name, structure, or meaning |
| `knowledge` | Store and recall entities, relationships, facts, and documents |
| `codebase` | Configure projects, index code, inspect status, and read source |
| `query` | Run read-only Cypher queries against the graph |

Set `CODEGRAPH_RAW_TOOLS=1` to expose lower-level handlers instead of the five grouped tools.
Set `CODEGRAPH_RAW_TOOLS=true` to expose lower-level handlers alongside the five grouped tools.

## Configuration

Expand All @@ -150,6 +151,7 @@ Set `CODEGRAPH_RAW_TOOLS=1` to expose lower-level handlers instead of the five g
| `CEREBRAS_API_KEY` | Optional LLM-backed knowledge extraction |
| `API_PORT` | Dashboard and REST API port, default `3001`; use the printed URL |
| `CODEGRAPH_BROWSE_ROOTS` | Additional absolute dashboard Browse roots, separated by commas |
| `CODEGRAPH_RAW_TOOLS` | Set to the literal value `true` to expose raw handlers alongside the five grouped MCP tools |

Never commit provider keys. Put secrets in the MCP client's protected environment configuration or a local ignored `.env` file.

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Include affected versions, impact, reproduction steps, and any suggested mitigat

The maintainer will aim to acknowledge a report within 72 hours, provide status updates while it is investigated, and coordinate disclosure after a fix is available. Response and remediation timing depend on severity and reproducibility.

## Known advisories in the published package
## Known advisories in the package dependency tree

`npm audit` reports findings against `codegraph-mcp` that we cannot resolve from this
repository. They are listed here rather than suppressed, and the release pipeline enforces
Expand Down
22 changes: 15 additions & 7 deletions apps/web/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@ import { Analytics } from '@vercel/analytics/next'
import './globals.css'

export const metadata: Metadata = {
title: 'CodeGraph — Deep Codebase Understanding for AI Agents',
description: 'CodeGraph builds a queryable knowledge graph of every function, class, and relationship in your codebase — then gives your AI assistant the tools to search, analyze, and navigate it.',
title: 'CodeGraph | Local-first code intelligence for AI agents',
description: 'CodeGraph indexes supported code structure, relationships, git history, and project knowledge into a local-first graph for AI agents and developers.',
keywords: ['CodeGraph', 'MCP', 'AI agent', 'codebase', 'knowledge graph', 'tree-sitter', 'FalkorDB', 'developer tools'],
authors: [{ name: 'CodeGraph' }],
icons: {
icon: [
{ url: '/icon.svg', type: 'image/svg+xml' },
{ url: '/icon-light-32x32.png', media: '(prefers-color-scheme: light)' },
{ url: '/icon-dark-32x32.png', media: '(prefers-color-scheme: dark)' },
],
apple: '/apple-icon.png',
},
openGraph: {
title: 'CodeGraph — Deep Codebase Understanding for AI Agents',
description: 'Your AI agent doesn\'t understand your codebase. CodeGraph fixes that.',
title: 'CodeGraph | Local-first code intelligence for AI agents',
description: 'Index supported code structure, relationships, git history, and project knowledge into a graph your tools can query.',
type: 'website',
},
twitter: {
card: 'summary_large_image',
title: 'CodeGraph — Deep Codebase Understanding for AI Agents',
description: 'Your AI agent doesn\'t understand your codebase. CodeGraph fixes that.',
title: 'CodeGraph | Local-first code intelligence for AI agents',
description: 'Index supported code structure, relationships, git history, and project knowledge into a graph your tools can query.',
},
}

Expand All @@ -34,7 +42,7 @@ export default function RootLayout({
<html lang="en" className="dark">
<body className="font-sans antialiased">
{children}
<Analytics />
{process.env.VERCEL === '1' ? <Analytics /> : null}
</body>
</html>
)
Expand Down
Loading
Loading