Skip to content

Commit bd162fd

Browse files
authored
Merge pull request #303 from terraphim/claude/terraphim-bun-hook-guide-011CV536xajudBzw8gdSFNV7
Create Terraphim-tui hook guide for Claude code
2 parents d799002 + 9d73fd7 commit bd162fd

33 files changed

Lines changed: 5282 additions & 2 deletions

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,80 @@ For development, see our comprehensive [Development Setup Guide](docs/src/develo
241241
- Multiple installation options (no Python required!)
242242
- IDE integration and troubleshooting
243243

244+
## Claude Code Integration
245+
246+
Terraphim provides seamless integration with Claude Code through multiple approaches, enabling intelligent text replacement and codebase quality evaluation.
247+
248+
### 🔄 Text Replacement (Hooks & Skills)
249+
250+
Use Terraphim's knowledge graph capabilities to automatically replace text patterns in your development workflow:
251+
252+
**Claude Code Hooks** - Automatic, transparent replacements:
253+
```bash
254+
# Example: Automatically replace npm with bun
255+
echo "npm install" | terraphim-tui replace
256+
# Output: bun_install
257+
```
258+
259+
**Claude Skills** - Context-aware, conversational assistance:
260+
- Works across all Claude platforms
261+
- Provides explanations and reasoning
262+
- Progressive disclosure of functionality
263+
264+
**Examples:**
265+
- Package manager enforcement (npm/yarn/pnpm → bun)
266+
- Attribution replacement (Claude Code → Terraphim AI)
267+
- Custom domain-specific replacements
268+
269+
📖 **Complete Guide**: [examples/TERRAPHIM_CLAUDE_INTEGRATION.md](examples/TERRAPHIM_CLAUDE_INTEGRATION.md)
270+
271+
### 📊 Codebase Quality Evaluation
272+
273+
Evaluate whether AI agents (Claude Code, GitHub Copilot, autonomous agents) improve or deteriorate your codebase using deterministic, knowledge graph-based assessment:
274+
275+
**Key Features:**
276+
- **Deterministic**: Aho-Corasick automata for consistent scoring
277+
- **Privacy-First**: All evaluation runs locally
278+
- **Multi-Dimensional**: Security, performance, quality perspectives
279+
- **CI/CD Ready**: Automated quality gates with exit codes
280+
281+
**Quick Start:**
282+
```bash
283+
cd examples/codebase-evaluation
284+
./scripts/evaluate-ai-agent.sh /path/to/codebase
285+
286+
# Generates verdict:
287+
# ✅ IMPROVEMENT: The AI agent improved the codebase quality.
288+
# - Improved metrics: 3
289+
# - Deteriorated metrics: 0
290+
```
291+
292+
**Evaluation Metrics:**
293+
- Clippy warnings, anti-patterns, TODO counts
294+
- Knowledge graph density and semantic matches
295+
- Test pass rates and code coverage
296+
- Custom domain-specific patterns
297+
298+
**Use Cases:**
299+
1. Evaluate PRs from AI agents before merge
300+
2. Continuous quality monitoring in CI/CD pipelines
301+
3. Historical trend analysis across evaluations
302+
4. Multi-role evaluation (security + performance + quality)
303+
304+
📖 **Complete Documentation**: [examples/codebase-evaluation/](examples/codebase-evaluation/)
305+
306+
**Example GitHub Actions Integration:**
307+
```yaml
308+
- name: Baseline evaluation
309+
run: ./scripts/baseline-evaluation.sh ${{ github.workspace }}
310+
- name: Apply AI changes
311+
run: # Your AI agent step
312+
- name: Post-change evaluation
313+
run: ./scripts/post-evaluation.sh ${{ github.workspace }}
314+
- name: Generate verdict (fails on deterioration)
315+
run: ./scripts/compare-evaluations.sh
316+
```
317+
244318
## Contributing
245319
246320
We welcome contributions! Here's how to get started:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Generated with Terraphim AI
2+
3+
Attribution text for Terraphim AI generated content.
4+
5+
synonyms:: Generated with Claude Code, Generated with Claude
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://terraphim.ai
2+
3+
Terraphim AI website URL.
4+
5+
synonyms:: https://claude.com/claude-code, https://anthropic.com, https://claude.com

docs/src/kg/knowledge-graph-system.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Markdown files use the `synonyms::` syntax to define concept relationships:
4141

4242
Terraphim Graph (scorer) is using unique graph embeddings.
4343

44-
synonyms:: graph embeddings, graph, knowledge graph based embeddings
44+
[example] synonyms:: graph embeddings, graph, knowledge graph based embeddings
4545

4646
Now we will have a concept "Terraphim Graph Scorer" with synonyms.
4747
```
@@ -257,7 +257,7 @@ let new_kg_content = r#"
257257
258258
Graph Analysis provides deep insights into data relationships.
259259
260-
synonyms:: data analysis, network analysis, graph processing,
260+
[example] synonyms:: data analysis, network analysis, graph processing,
261261
relationship mapping, connectivity analysis,
262262
terraphim-graph, graph embeddings
263263

docs/src/kg/noreply_terraphim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# noreply@terraphim.ai
2+
3+
Terraphim AI no-reply email address.
4+
5+
synonyms:: noreply@anthropic.com

docs/src/kg/terraphim_ai.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Terraphim AI
2+
3+
Terraphim AI platform for knowledge graph-based search.
4+
5+
synonyms:: Claude Code, Claude
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Terraphim AI
2+
3+
Link text for Terraphim AI.
4+
5+
synonyms:: Claude Code, Claude
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://terraphim.ai
2+
3+
URL for Terraphim AI website.
4+
5+
synonyms:: https://claude.com/claude-code, https://anthropic.com

examples/ANNOUNCEMENT.md

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
# 🚀 Announcing Terraphim's Claude Code Integration
2+
3+
**Three powerful ways to integrate Terraphim's knowledge graph capabilities with Claude Code**
4+
5+
---
6+
7+
## What's New?
8+
9+
We're excited to announce a comprehensive integration between Terraphim and Claude Code, providing three complementary capabilities for AI-assisted development:
10+
11+
### 1. 🪝 Claude Code Hooks
12+
**Automatic, transparent text replacement**
13+
14+
Intercept user prompts before Claude sees them to enforce standards and preferences:
15+
16+
```bash
17+
# Example: Automatically enforce bun over npm/yarn/pnpm
18+
echo "npm install && yarn test" | terraphim-tui replace
19+
# Output: bun_install && bun test
20+
```
21+
22+
**Use Cases:**
23+
- Package manager enforcement
24+
- Coding standard compliance
25+
- Attribution replacement
26+
- Domain-specific terminology
27+
28+
### 2. 🎯 Claude Skills
29+
**Context-aware, conversational assistance**
30+
31+
Progressive disclosure of Terraphim capabilities across all Claude platforms:
32+
33+
- Works on web, mobile, and desktop
34+
- Provides explanations and reasoning
35+
- Learns when to apply replacements
36+
- Fully conversational interface
37+
38+
### 3. 📊 Codebase Quality Evaluation
39+
**Objective assessment of AI-generated changes**
40+
41+
Deterministic framework for evaluating whether AI agents improve or deteriorate your codebase:
42+
43+
```bash
44+
./scripts/evaluate-ai-agent.sh /path/to/codebase
45+
46+
# Generates verdict:
47+
# ✅ IMPROVEMENT: The AI agent improved the codebase quality.
48+
# - Improved metrics: 4
49+
# - Deteriorated metrics: 0
50+
```
51+
52+
**Key Features:**
53+
- ✅ Deterministic (Aho-Corasick automata)
54+
- ✅ Privacy-first (runs locally)
55+
- ✅ Multi-dimensional (security, performance, quality)
56+
- ✅ CI/CD ready (exit codes for automation)
57+
58+
---
59+
60+
## Why This Matters
61+
62+
As AI coding assistants become more prevalent, we need **objective quality gates** to ensure they help rather than hurt our codebases.
63+
64+
**Traditional Approach:**
65+
```
66+
AI changes → Manual review → Hope → Ship
67+
```
68+
69+
**Terraphim Approach:**
70+
```
71+
AI changes → Automatic evaluation → Objective verdict → Block if worse → Ship confidently
72+
```
73+
74+
---
75+
76+
## Quick Start
77+
78+
### Installation
79+
80+
```bash
81+
# Docker (easiest)
82+
curl -fsSL https://raw.githubusercontent.com/terraphim/terraphim-ai/main/release/v0.2.3/docker-run.sh | bash
83+
84+
# Or binary installation
85+
curl -fsSL https://raw.githubusercontent.com/terraphim/terraphim-ai/main/release/v0.2.3/install.sh | bash
86+
```
87+
88+
### Try Evaluation
89+
90+
```bash
91+
git clone https://github.com/terraphim/terraphim-ai.git
92+
cd terraphim-ai/examples/codebase-evaluation
93+
./scripts/evaluate-ai-agent.sh /path/to/your/codebase
94+
```
95+
96+
### Set Up Hooks
97+
98+
```bash
99+
# Copy hook script
100+
cp examples/claude-code-hooks/terraphim-package-manager-hook.sh ~/.claude/hooks/
101+
102+
# Configure Claude Code settings
103+
# See: examples/claude-code-hooks/README.md
104+
```
105+
106+
### Set Up Skills
107+
108+
```bash
109+
# Copy skill
110+
cp -r examples/claude-skills/terraphim-package-manager ~/.claude/skills/
111+
112+
# Restart Claude
113+
```
114+
115+
---
116+
117+
## Example: CI/CD Quality Gate
118+
119+
```yaml
120+
name: AI Quality Check
121+
122+
on: pull_request
123+
124+
jobs:
125+
evaluate:
126+
runs-on: ubuntu-latest
127+
steps:
128+
- uses: actions/checkout@v3
129+
- name: Install Terraphim
130+
run: curl -fsSL https://[...]/install.sh | bash
131+
- name: Baseline evaluation
132+
run: ./scripts/baseline-evaluation.sh .
133+
- name: Post-change evaluation
134+
run: ./scripts/post-evaluation.sh .
135+
- name: Generate verdict (fails on deterioration)
136+
run: ./scripts/compare-evaluations.sh
137+
```
138+
139+
---
140+
141+
## Documentation
142+
143+
**Complete Guides:**
144+
- [Integration Guide](https://github.com/terraphim/terraphim-ai/blob/main/examples/TERRAPHIM_CLAUDE_INTEGRATION.md)
145+
- [Evaluation Design](https://github.com/terraphim/terraphim-ai/blob/main/examples/CODEBASE_EVALUATION_DESIGN.md)
146+
- [Quick Start](https://github.com/terraphim/terraphim-ai/blob/main/examples/codebase-evaluation/README.md)
147+
148+
**Examples:**
149+
- [Hooks](https://github.com/terraphim/terraphim-ai/tree/main/examples/claude-code-hooks)
150+
- [Skills](https://github.com/terraphim/terraphim-ai/tree/main/examples/claude-skills)
151+
- [Evaluation Scripts](https://github.com/terraphim/terraphim-ai/tree/main/examples/codebase-evaluation/scripts)
152+
153+
---
154+
155+
## Use Cases
156+
157+
### 1. Package Manager Enforcement
158+
Automatically replace npm/yarn/pnpm with bun in all prompts and code.
159+
160+
### 2. PR Quality Gates
161+
Block PRs from AI agents if they deteriorate code quality.
162+
163+
### 3. Security Auditing
164+
Evaluate AI changes for security vulnerabilities before merge.
165+
166+
### 4. Performance Analysis
167+
Assess whether AI optimizations actually improve performance.
168+
169+
### 5. Trend Monitoring
170+
Track codebase quality evolution over time across AI changes.
171+
172+
---
173+
174+
## Key Benefits
175+
176+
**Objectivity** - Quantifiable metrics over subjective opinions
177+
**Speed** - Evaluations in seconds, not hours
178+
**Privacy** - Everything runs locally, no external APIs
179+
**Determinism** - Same input → same output
180+
**Transparency** - See exactly why quality changed
181+
182+
---
183+
184+
## Technical Highlights
185+
186+
**Aho-Corasick Automata**
187+
- O(n + m) complexity for pattern matching
188+
- Search thousands of patterns simultaneously
189+
- Deterministic and fast
190+
191+
**Knowledge Graphs**
192+
- Define semantic relationships in markdown
193+
- Build thesauri for concept mapping
194+
- Extensible for any domain
195+
196+
**Role-Based Evaluation**
197+
- Security Auditor: Vulnerabilities and attack vectors
198+
- Performance Analyst: Bottlenecks and efficiency
199+
- Code Reviewer: Quality and maintainability
200+
- Documentation Quality: Completeness and clarity
201+
202+
---
203+
204+
## Community
205+
206+
**Connect:**
207+
- GitHub: [terraphim/terraphim-ai](https://github.com/terraphim/terraphim-ai)
208+
- Discord: https://discord.gg/VPJXB6BGuY
209+
- Discourse: https://terraphim.discourse.group
210+
211+
**Contribute:**
212+
- Share knowledge graph templates
213+
- Report useful evaluation patterns
214+
- Submit PRs with improvements
215+
- Write about your experiences
216+
217+
---
218+
219+
## What's Next
220+
221+
**Short Term:**
222+
- Visual dashboard for evaluation trends
223+
- More built-in evaluation roles
224+
- Language-specific KG templates
225+
226+
**Medium Term:**
227+
- ML-enhanced pattern detection
228+
- Automatic KG expansion
229+
- Real-time evaluation
230+
231+
**Long Term:**
232+
- Distributed team evaluation
233+
- Knowledge graph marketplace
234+
- Advanced analytics
235+
236+
---
237+
238+
## Try It Today
239+
240+
All code is Apache 2.0 licensed. Privacy-first. Runs locally. No external dependencies.
241+
242+
**Get Started:** https://github.com/terraphim/terraphim-ai
243+
244+
---
245+
246+
*Terraphim: Privacy-first AI assistant for trusted AI-assisted development*

0 commit comments

Comments
 (0)