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
29 changes: 29 additions & 0 deletions .cursor/rules/watcher-knowledge-graph.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
description: CodeGenome knowledge graph and MCP Context
alwaysApply: true
---

# CodeGenome MCP Integration

You are operating within a repository analyzed by CodeGenome, an architectural knowledge graph tool. This project contains a `.genome/` directory.

## Core Directives

1. **Mandatory MCP Usage**: When `.genome/watcher.db` exists, you MUST use CodeGenome MCP access for all codebase, architecture, dependency, or symbol queries whenever it is available.
2. **Access Order**: First use native CodeGenome MCP tools exposed in your context. If those tools are missing, you MAY try a local MCP HTTP endpoint such as `http://127.0.0.1:7331/mcp` when the user has started it or configured it. Treat this as MCP transport access, not as an arbitrary application HTTP API.
3. **Prefer Graph over Grep**: Use graph-backed MCP tools instead of raw file searching (`grep`) or reading entire files blindly. The graph provides semantic understanding.
4. **Fallback Gracefully**: If native MCP tools are missing and HTTP MCP access is unavailable, incompatible, or returns empty data, tell the user exactly what failed and what to configure. Then, if needed, read `.genome/graph.json` or `.genome/exports/*.md` before resorting to standard text searches.
5. **Keep Context Fresh**: After modifying code files, remind the user to run `codegenome analyze` or start the live evolution server `codegenome evolve --live` to keep the graph updated.

## Available MCP Capabilities

- **Discovery**: `search_nodes` (find symbols)
- **Relationships**: `get_neighbors` (imports, callers, callees)
- **Architecture**: `get_entry_points`, `get_dead_code`, `get_circular_deps`, `get_god_nodes`
- **Metrics**: `get_complexity`, `get_churn`, `get_graph` (summary statistics)
- **Evolution**: `get_timeline`, `get_changes` (architectural diffs)

## Constraints & Behaviors

- Only read `.genome/graph.json` or `.genome/exports/*.md` directly if native MCP tools and local HTTP MCP transport are unavailable or fail to surface enough context.
- Verify your MCP usage by monitoring tool call success. If native tools are missing, try the configured local HTTP MCP endpoint when possible. If both native and HTTP MCP access fail, politely ask the user to configure their editor's MCP settings to run `codegenome mcp-start` (stdio) or start the server with `codegenome mcp-start --transport http`.
24 changes: 24 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CodeGenome Knowledge Graph (MCP)

You are operating within a repository analyzed by CodeGenome, an architectural knowledge graph tool. This project contains a `.genome/` directory.

## Core Directives

1. **Mandatory MCP Usage**: When `.genome/watcher.db` exists, you MUST use CodeGenome MCP access for all codebase, architecture, dependency, or symbol queries whenever it is available.
2. **Access Order**: First use native CodeGenome MCP tools exposed in your context. If those tools are missing, you MAY try a local MCP HTTP endpoint such as `http://127.0.0.1:7331/mcp` when the user has started it or configured it. Treat this as MCP transport access, not as an arbitrary application HTTP API.
3. **Prefer Graph over Grep**: Use graph-backed MCP tools instead of raw file searching (`grep`) or reading entire files blindly. The graph provides semantic understanding.
4. **Fallback Gracefully**: If native MCP tools are missing and HTTP MCP access is unavailable, incompatible, or returns empty data, tell the user exactly what failed and what to configure. Then, if needed, read `.genome/graph.json` or `.genome/exports/*.md` before resorting to standard text searches.
5. **Keep Context Fresh**: After modifying code files, remind the user to run `codegenome analyze` or start the live evolution server `codegenome evolve --live` to keep the graph updated.

## Available MCP Capabilities

- **Discovery**: `search_nodes` (find symbols)
- **Relationships**: `get_neighbors` (imports, callers, callees)
- **Architecture**: `get_entry_points`, `get_dead_code`, `get_circular_deps`, `get_god_nodes`
- **Metrics**: `get_complexity`, `get_churn`, `get_graph` (summary statistics)
- **Evolution**: `get_timeline`, `get_changes` (architectural diffs)

## Constraints & Behaviors

- Only read `.genome/graph.json` or `.genome/exports/*.md` directly if native MCP tools and local HTTP MCP transport are unavailable or fail to surface enough context.
- Verify your MCP usage by monitoring tool call success. If native tools are missing, try the configured local HTTP MCP endpoint when possible. If both native and HTTP MCP access fail, politely ask the user to configure their editor's MCP settings to run `codegenome mcp-start` (stdio) or start the server with `codegenome mcp-start --transport http`.
41 changes: 41 additions & 0 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Compatibility

on:
push:
branches: ["main"]
pull_request:

jobs:
install-and-parser-smoke:
name: "${{ matrix.os }} / py${{ matrix.python-version }}"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-14]
python-version: ["3.11", "3.12", "3.13"]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade build tooling
run: python -m pip install --upgrade pip setuptools wheel

- name: Install package and test dependencies
run: |
python -m pip install .
python -m pip install pytest

- name: Parser test suite
run: python -m pytest tests/test_parser.py -q

- name: CLI smoke test
run: |
codegenome --help
python -c "import codegenome; print(codegenome.__version__)"
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/codegenome.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions .windsurfrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CodeGenome Knowledge Graph (MCP)

You are operating within a repository analyzed by CodeGenome, an architectural knowledge graph tool. This project contains a `.genome/` directory.

## Core Directives

1. **Mandatory MCP Usage**: When `.genome/watcher.db` exists, you MUST use CodeGenome MCP access for all codebase, architecture, dependency, or symbol queries whenever it is available.
2. **Access Order**: First use native CodeGenome MCP tools exposed in your context. If those tools are missing, you MAY try a local MCP HTTP endpoint such as `http://127.0.0.1:7331/mcp` when the user has started it or configured it. Treat this as MCP transport access, not as an arbitrary application HTTP API.
3. **Prefer Graph over Grep**: Use graph-backed MCP tools instead of raw file searching (`grep`) or reading entire files blindly. The graph provides semantic understanding.
4. **Fallback Gracefully**: If native MCP tools are missing and HTTP MCP access is unavailable, incompatible, or returns empty data, tell the user exactly what failed and what to configure. Then, if needed, read `.genome/graph.json` or `.genome/exports/*.md` before resorting to standard text searches.
5. **Keep Context Fresh**: After modifying code files, remind the user to run `codegenome analyze` or start the live evolution server `codegenome evolve --live` to keep the graph updated.

## Available MCP Capabilities

- **Discovery**: `search_nodes` (find symbols)
- **Relationships**: `get_neighbors` (imports, callers, callees)
- **Architecture**: `get_entry_points`, `get_dead_code`, `get_circular_deps`, `get_god_nodes`
- **Metrics**: `get_complexity`, `get_churn`, `get_graph` (summary statistics)
- **Evolution**: `get_timeline`, `get_changes` (architectural diffs)

## Constraints & Behaviors

- Only read `.genome/graph.json` or `.genome/exports/*.md` directly if native MCP tools and local HTTP MCP transport are unavailable or fail to surface enough context.
- Verify your MCP usage by monitoring tool call success. If native tools are missing, try the configured local HTTP MCP endpoint when possible. If both native and HTTP MCP access fail, politely ask the user to configure their editor's MCP settings to run `codegenome mcp-start` (stdio) or start the server with `codegenome mcp-start --transport http`.
24 changes: 24 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CodeGenome Knowledge Graph (MCP)

You are operating within a repository analyzed by CodeGenome, an architectural knowledge graph tool. This project contains a `.genome/` directory.

## Core Directives

1. **Mandatory MCP Usage**: When `.genome/watcher.db` exists, you MUST use CodeGenome MCP access for all codebase, architecture, dependency, or symbol queries whenever it is available.
2. **Access Order**: First use native CodeGenome MCP tools exposed in your context. If those tools are missing, you MAY try a local MCP HTTP endpoint such as `http://127.0.0.1:7331/mcp` when the user has started it or configured it. Treat this as MCP transport access, not as an arbitrary application HTTP API.
3. **Prefer Graph over Grep**: Use graph-backed MCP tools instead of raw file searching (`grep`) or reading entire files blindly. The graph provides semantic understanding.
4. **Fallback Gracefully**: If native MCP tools are missing and HTTP MCP access is unavailable, incompatible, or returns empty data, tell the user exactly what failed and what to configure. Then, if needed, read `.genome/graph.json` or `.genome/exports/*.md` before resorting to standard text searches.
5. **Keep Context Fresh**: After modifying code files, remind the user to run `codegenome analyze` or start the live evolution server `codegenome evolve --live` to keep the graph updated.

## Available MCP Capabilities

- **Discovery**: `search_nodes` (find symbols)
- **Relationships**: `get_neighbors` (imports, callers, callees)
- **Architecture**: `get_entry_points`, `get_dead_code`, `get_circular_deps`, `get_god_nodes`
- **Metrics**: `get_complexity`, `get_churn`, `get_graph` (summary statistics)
- **Evolution**: `get_timeline`, `get_changes` (architectural diffs)

## Constraints & Behaviors

- Only read `.genome/graph.json` or `.genome/exports/*.md` directly if native MCP tools and local HTTP MCP transport are unavailable or fail to surface enough context.
- Verify your MCP usage by monitoring tool call success. If native tools are missing, try the configured local HTTP MCP endpoint when possible. If both native and HTTP MCP access fail, politely ask the user to configure their editor's MCP settings to run `codegenome mcp-start` (stdio) or start the server with `codegenome mcp-start --transport http`.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- **Copyable TUI console outputs** — users can now select text in the log panes and press `Ctrl+C` to copy it to the clipboard.
- **LAN live graph sharing** — `codegenome evolve --live --lan` binds HTTP and WebSocket to `0.0.0.0` so other devices on the same network can open the live graph. The CLI prints a shareable LAN URL (for example `http://192.168.1.42:8000/graph.html?live=1`).
- **TUI MCP HTTP mode controls** — the dashboard now includes separate **Start MCP HTTP (Local)** and **Start MCP HTTP (LAN)** buttons so users can intentionally choose localhost-only or LAN exposure.
- **Git-aware file filtering** — the scanner respects workspace `.gitignore` and `.genomeignore` files, including nested ignore files in subdirectories, negation rules (`!pattern`), and anchored patterns.
Expand All @@ -33,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Agent rules no longer reference misleading HTTP endpoints that caused agents to `curl` the server instead of using MCP transport.
- MCP server keeps localhost-only behavior by default and now requires an explicit remote HTTP opt-in (`--allow-remote-http`) for non-loopback hosts.
- Release lint blockers (unused imports and test lint violations) were resolved so full lint/test/build gates pass before upload.
- Tree-sitter dependency constraints now support Python 3.12+ installations (including macOS Apple Silicon) while preserving legacy pins for Python 3.11 compatibility (fixes [#1](https://github.com/Ogro-Projukti/codegenome/issues/1)).
- Updated tree-sitter `Parser` initialization to support both legacy and modern (`>=0.23`) API signatures without breaking runtime.

### Documentation

Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ classifiers = [
"Topic :: Software Development :: Quality Assurance",
]
dependencies = [
"tree-sitter==0.21.3",
"tree-sitter-python==0.21.0",
"tree-sitter-javascript==0.21.0",
"tree-sitter-typescript==0.21.0",
"tree-sitter-go==0.21.0",
"tree-sitter-rust==0.21.2",
"tree-sitter==0.21.3; python_version < '3.12'",
"tree-sitter>=0.23,<0.26; python_version >= '3.12'",
"tree-sitter-python==0.21.0; python_version < '3.12'",
"tree-sitter-python>=0.23,<0.26; python_version >= '3.12'",
"tree-sitter-javascript==0.21.0; python_version < '3.12'",
"tree-sitter-javascript>=0.23,<0.26; python_version >= '3.12'",
"tree-sitter-typescript==0.21.0; python_version < '3.12'",
"tree-sitter-typescript>=0.23,<0.26; python_version >= '3.12'",
"tree-sitter-go==0.21.0; python_version < '3.12'",
"tree-sitter-go>=0.23,<0.26; python_version >= '3.12'",
"tree-sitter-rust==0.21.2; python_version < '3.12'",
"tree-sitter-rust>=0.23,<0.26; python_version >= '3.12'",
"watchdog",
"fastmcp",
"leidenalg",
Expand Down
18 changes: 12 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
tree-sitter==0.21.3
tree-sitter-python==0.21.0
tree-sitter-javascript==0.21.0
tree-sitter-typescript==0.21.0
tree-sitter-go==0.21.0
tree-sitter-rust==0.21.2
tree-sitter==0.21.3; python_version < "3.12"
tree-sitter>=0.23,<0.26; python_version >= "3.12"
tree-sitter-python==0.21.0; python_version < "3.12"
tree-sitter-python>=0.23,<0.26; python_version >= "3.12"
tree-sitter-javascript==0.21.0; python_version < "3.12"
tree-sitter-javascript>=0.23,<0.26; python_version >= "3.12"
tree-sitter-typescript==0.21.0; python_version < "3.12"
tree-sitter-typescript>=0.23,<0.26; python_version >= "3.12"
tree-sitter-go==0.21.0; python_version < "3.12"
tree-sitter-go>=0.23,<0.26; python_version >= "3.12"
tree-sitter-rust==0.21.2; python_version < "3.12"
tree-sitter-rust>=0.23,<0.26; python_version >= "3.12"
networkx>=3.2,<4
watchdog>=4.0,<5
fastmcp>=2.0,<3
Expand Down
19 changes: 16 additions & 3 deletions src/codegenome/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,22 @@ def _load_languages() -> dict[str, Language]:
for key, module_name, attr_name, lang_name in specs:
try:
module = __import__(module_name)
languages[key] = Language(getattr(module, attr_name)(), lang_name)
languages[key] = _build_language(module, attr_name, lang_name)
except Exception as exc: # pragma: no cover - optional grammars
logger.warning("Failed to load tree-sitter grammar %s: %s", key, exc)
return languages


def _build_language(module: object, attr_name: str, lang_name: str) -> Language:
"""Create a Language object across tree-sitter API variants."""
language_capsule = getattr(module, attr_name)()
try:
return Language(language_capsule, lang_name)
except TypeError:
# Newer tree-sitter releases accept only the grammar capsule.
return Language(language_capsule)


class SourceParser:
"""Parse source files and extract symbols, imports, calls, and inheritance.

Expand All @@ -232,8 +242,11 @@ def __init__(self) -> None:
self._languages = _load_languages()
self._parsers: dict[str, Parser] = {}
for key, language in self._languages.items():
parser = Parser()
parser.set_language(language)
try:
parser = Parser(language)
except TypeError:
parser = Parser()
parser.set_language(language)
self._parsers[key] = parser

def detect_language(self, path: Path | str) -> str | None:
Expand Down
Loading
Loading