AST-aware code intelligence for Hermes Agent β tree-sitter + ast-grep + LSP 70 tools that understand your code's structure, not just its text. 10β50Γ fewer tokens for code navigation.
Fork von
rewasa/hermes-code-intel-pluginβ customized for agentiker.de
- β¨ Why?
- π Quick Start
- π Tools
- π¦ Installation
- π Supported Languages
- π Architecture
- π§ How It Works
- π§ͺ Development
- π€ Contributing
- π Credits
Hermes ships with search_files (regex grep) and read_file (raw text). Those work, but they're blind to syntax β they match comments, strings, and formatting equally. This plugin adds:
| Feature | What it does |
|---|---|
| Symbol extraction | Get all functions, classes, methods with signatures and line numbers without reading the whole file |
| Structural search | Find imports, decorators, function calls, try/catch blocks by AST node type, not regex |
| Safe refactoring | Rename patterns, wrap functions, add parameters across files β dry-run by default |
| Go-to-definition | LSP-powered jump to symbol definition (falls back to AST) |
| Find references | LSP-powered cross-file usage search (falls back to AST) |
| Blast radius | What breaks if you change this symbol? Transitive callers + test coverage |
| PR impact | Git diff + call graph + test coverage + reviewer suggestions |
| Hot paths | Rank files by transitive import count via ImportGraph |
| Complexity | Per-function cyclomatic complexity with rank A-E |
| Cycle detection | Find circular imports via Tarjan's SCC algorithm |
| Knowledge graph | SQLite-persistent import graph β callers, callees, health metrics |
The result: editor-grade code intelligence in the terminal β same approach as Neovim 0.5+, Zed, and Helix.
# Symbole einer Datei abrufen (ohne die ganze Datei zu lesen)
code_symbols(path="src/service.py")
# Strukturelle Suche β finde alle Imports
code_search(path="src/", preset="imports")
# Go-to-Definition
code_definition(path="src/service.py", line=42)
# Alle Referenzen eines Symbols finden
code_references(path="src/service.py", line=42)
# Code-Risiko-Analyse
code_dependency_risk(path="src/")
code_blast_radius(path="src/service.py", line=42)
# Impact-Analyse vor Refactoring
code_impact(path="src/service.py", line=42)Version: 0.6.13
Tests: 3124 tests
Tools (0):
Supported Languages: c, cpp, go, java, javascript, python, rust, tsx, typescript
No tools registered.
- P1: code_impact JSONDecodeError β
code_impact_tool()riefcode_references_tool()auf, das Rich-Panel-Output (fmt_ok) zurΓΌckgab, aberjson.loads()scheiterte. Fix: LSP-Bridge direkt aufrufen statt ΓΌber die formatierte Tool-Funktion (tools/impact.py) - P1: code_callers JSONDecodeError β Gleicher Bug in
_fallback_reference_callers()in lsp/call_hierarchy.py. Fix:bridge.find_references()direkt aufrufen (lsp/call_hierarchy.py) - P1: code_migration TypeError β Nested JSON-Schema (
rules.items.type: object) crashte die MCP-Dispatch-Schicht. Fix: Schema auftype: string(JSON-String) geΓ€ndert + Parser im Handler (tools/migration.py)
- code_semantic_tokens: Graceful fmt_info wenn LSP nicht verfΓΌgbar (lsp/extra/tokens.py)
- code_document_links: Regex-basierte URL-Extraktion als AST-Fallback (lsp/extra/tokens.py)
- code_inline_values: fmt_info mit Hinweis auf LSP-AbhΓ€ngigkeit (lsp/extra/tokens.py)
- code_type_definition: AST-Fallback fΓΌr Python-Funktionssignaturen (lsp/extra/definition.py)
- code_implementations: AST-Fallback findet ClassDefs im File (lsp/extra/definition.py)
- Parameter-Konsolidierung:
file_pathβpathin allen 3 tokens-Tools
- 7 Tests fΓΌr LSP-Bridge-Mocking aktualisiert (test_impact_extended, test_code_intel_gaps, test_tool_edge_cases)
- P1: code_unused_finder β
signal.signal(SIGALRM)crasht in Worker-Threads mitValueError: signal only works in main thread. Ersetzt durchThreadPoolExecutormitfuture.result(timeout=N)(tools/unused.py) - P2: code_export β "No symbols found" weil
code_symbols_tool()Rich-Output (fmt_ok) liefert, denjson.loads()nicht parsen kann. Fix: Direkte Nutzung von_symbols_extract_single()(tools/export.py) - P2: code_migration β
ImportError: cannot import name 'code_migration_tool'weil der Re-Export in dercode_tools.pyFacade fehlte. ErgΓ€nzt in code_tools.py + tools/init.py - P2: code_impact β Kryptischer Error "Failed to resolve references" ohne Kontext. Zeigt jetzt Datei, Zeile und Exception-Detail (tools/impact.py)
- P3: code_pr_impact β
auto_detect=Truesucht nur Remote-Branches (origin/main). Fallback auf lokale Branches (master/develop/release) ergΓ€nzt (tools/impact.py) - P3: LSP-Tools β
code_code_lens/code_folding_range/code_selection_rangezeigten nur "No XX available". Jetzt mit Hinweis auf benΓΆtigten LSP-Server (lsp/extra/completion.py)
- P1: Handler-Signature Bugs β
_handle_code_securityund_handle_code_generate_testshatten**kwargsstatt(args, **kw)β TypeError bei Hermes Dispatch (tools/security.py:495, tools/testgen.py:495) - P2: Stale Mock-Pfade β 18Γ
patch("code_intel.lsp.tools_extra.get_lsp_manager")mit fehlendemcreate=Trueβ 8 Test-Failures (3 Test-Dateien) - P3: Logger-Level Assertion β
test_structural_fixes.py:184erwartete WARNING, aber conftest setzt DEBUG (seit v0.6.10)
| Modul | Vorher | Nachher | Neue Tests |
|---|---|---|---|
| tools/base.py | 56% | 97% | 132 |
| tools/metrics.py | 30% | 99% | 79 |
| tools/export.py | 58% | 100% | 71 |
| tools/test_coverage.py | 52% | ~90% | 48 |
| tools/complexity.py | 65% | 90% | 35 |
| tools/type_hierarchy.py | 34% | 84% | 26 |
| tools/migration.py | 69% | ~90% | 38 |
Enable in ~/.hermes/config.yaml:
plugins:
enabled:
- code_intelRequires Hermes restart (/new or daemon restart).
# Ins Hermes-Venv installieren (vom Plugin-Ordner aus)
cd ~/.hermes/plugins/agentiker-code-intel
~/.hermes/hermes-agent/venv/bin/pip install -e .
# Option B β Via Install-Script
./scripts/install-deps.sh
# Option C β Manuell (nur Dependencies)
python3 -m pip install tree-sitter tree-sitter-languages ast-grep-py rich PyYAMLDependencies: tree-sitter>=0.24.0, ast-grep-py>=0.37.0, rich>=13.0, PyYAML>=6.0
LSP-Tools (code_definition, code_references) funktionieren ohne Server β sie fallen auf AST-Analyse zurΓΌck. FΓΌr volle UnterstΓΌtzung:
# Python
pip install pyright
# TypeScript / JavaScript
npm install -g typescript-language-server typescript
# Rust
rustup component add rust-analyzer
# Go
go install golang.org/x/tools/gopls@latestDas Plugin erkennt Server automatisch via PATH, node_modules/.bin und npx-Fallback.
Automatische Erkennung von pnpm-workspace.yaml, nx.json, lerna.json β Workspace-Folder werden an den LSP-Server ΓΌbermittelt fΓΌr Cross-Workspace-Type-Resolution. Keine Konfiguration nΓΆtig.
| Language | Extensions | Tree-sitter | ast-grep | LSP |
|---|---|---|---|---|
| Python | .py, .pyi |
β | β | β (pyright/pylsp) |
| JavaScript | .js, .jsx |
β | β | β |
| TypeScript | .ts |
β | β | β (tsls) |
| TSX | .tsx |
β | β | β (tsls) |
| Rust | .rs |
β | β | β (rust-analyzer) |
| Go | .go |
β | β | β (gopls) |
| Java | .java |
β | β | β |
| C | .c, .h |
β | β | β |
| C++ | .cpp |
β | β | β |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β code_intel Plugin β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ€
β tree-sitter / AST β LSP Bridge β
β (schnell, offline) β (semantisch, online) β
β β β
β ββββββββββββββββββββββ β ββββββββββββββββββββββββββββββββ β
β β code_symbols β β β code_definition β β
β β code_search β β β code_references β β
β β code_refactor β β β code_diagnostics β β
β β code_capsule β β β code_hover β β
β β code_complexity β β β code_call_hierarchy β β
β β code_duplicates β β β code_type_hierarchy β β
β β code_unused_finder β β β code_rename β β
β β ... β β β ... β β
β ββββββββββββββββββββββ β ββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββ€
β Knowledge Graph β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β code_index β SQLite-persistenter ImportGraph β β
β β code_graph_query: callers, callees, hot_paths, β β
β β cycles, health, summary β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Subagent Integration β
β β’ Automatische Injektion in _SUBAGENT_TOOLSETS β
β β’ Jeder delegate_task-Spawn hat code_intel Tools β
β β’ Steering-Hint: "Nutze code_symbols statt read_file" β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Fix | Before | After | Impact |
|---|---|---|---|
stderr=subprocess.DEVNULL |
Pipe buffer (64KB) fΓΌllt sich mit Warnings β Deadlock | Silenced | Cold starts never hang |
PYTHONWARNINGS=ignore |
pylsp schreibt ~200KB Deprecation-Warnings | Suppressed | 2Γ faster Python LSP init |
_LSP_INIT_TIMEOUT=15s |
60s auf dead server β Agent blockt | 15s fast retry | Agent reagiert sofort |
_LSP_REQUEST_TIMEOUT=15s |
30s auf hung request (tsserver parsing giant file) | 15s | Quicker fallback to AST |
LSP bridges sind keyed by (language_id, workspace_root) mit LRU-Pool (max 8 concurrent). Fallback-Chain: erste verfΓΌgbare Server gewinnt.
AST-Results werden in memory gecached (OrderedDict, max 2000 EintrΓ€ge, LRU). Automatischer Clear bei Session-Ende.
Das Plugin shiped scripts/health_check.py β 10 Assertions: Tool-Registry, tree-sitter extraktion, AST search, ast-grep refactoring, LSP definition + references, Schema-Validierung.
# Manuell
~/.hermes/hermes-agent/venv/bin/python3 \
~/.hermes/plugins/code_intel/scripts/health_check.py
# Als cron (empfohlen) β stumm bei Gesundheit:
hermes cronjob create \
--name "code_intel_health" \
--schedule "every 60m" \
--script "scripts/health_check.py" \
--no-agentDas Plugin registriert automatisch den Skill code_intel:native-code-intelligence:
skill_view("code_intel:native-code-intelligence")
EnthΓ€lt: Mandatory Workflows, Tool-Selection-Rules, Quality Guardrails, IDE-Feature-Coverage-Map.
Nach Aktivierung: /code-intel status, /code-intel clear, /code-intel help
| Tool | Scenario | Time | Output Tokens |
|---|---|---|---|
code_definition |
Import binding β typeDefinition fallback | ~1.5s (first) | ~272 |
code_definition |
Cached request | ~0.65s | ~290 |
code_references |
Small class (~3 refs) | ~0.67s | ~1,362 |
code_references |
Medium class (~6 refs) | ~0.66s | ~2,610 |
cd ~/.hermes/plugins/agentiker-code-intel
# Tests ausfΓΌhren
PYTHONPATH=~/.hermes/plugins ~/.hermes/hermes-agent/venv/bin/python3 \
-m pytest -q --tb=short
# Einzelner Test
PYTHONPATH=~/.hermes/plugins ~/.hermes/hermes-agent/venv/bin/python3 \
-m pytest tests/test_code_intel.py::test_extract_symbols_python -vPre-Commit Hook: Automatischer Syntax-Check + Tests vor jedem Commit.
git config core.hooksPath .githooksJeder Release bekommt einen Eintrag in CHANGELOG.md:
[added]fΓΌr neue Features[changed]fΓΌr Γnderungen[fixed]fΓΌr Bugfixes[removed]fΓΌr Entfernungen
- Fork the repo
- Create a feature branch
- Add tests for your changes
- Run
PYTHONPATH=~/.hermes/plugins python3 -m pytest -qβ alle Tests grΓΌn - Open a PR
MIT β use it however you like.
- Hermes Agent β the plugin system this builds on
- rewasa β original author of upstream
hermes-code-intel-plugin - tree-sitter β incremental parsing system
- ast-grep β pattern-based code search and replacement
- pyright β Python LSP server (fallback)
- typescript-language-server β TypeScript/JavaScript LSP server