Skip to content

Commit c8c51c9

Browse files
Antigravity Agentclaude
andcommitted
feat(scholar): Self-Evolving Research Agent skill via Perplexity MCP
/scholar scan|eval|apply|full|errors|zig|fpga|agents|topic:"query" Uses perplexity_search, perplexity_research, perplexity_reason MCP tools. 3-phase pipeline: SCAN → EVAL (score 0-1) → APPLY (issues/MU/archive). Cron-ready via bridge-agent: claude:Run /scholar full Closes #113 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 40db6a0 commit c8c51c9

1 file changed

Lines changed: 290 additions & 0 deletions

File tree

.claude/skills/scholar/SKILL.md

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
---
2+
name: scholar
3+
description: Self-Evolving Research Agent — scans web for relevant tech, evaluates findings, proposes improvements. Uses Perplexity Sonar API via MCP.
4+
argument-hint: [scan|eval|apply|full|topic:"query"]
5+
allowed-tools: Bash(gh *), Bash(cat *), Bash(grep *), Bash(find *), Bash(python3 *), Bash(echo *), Bash(date *), Bash(wc *), Bash(git *), Bash(test *), Bash(ls *), Read, Edit, Write, mcp__perplexity__perplexity_search, mcp__perplexity__perplexity_ask, mcp__perplexity__perplexity_research, mcp__perplexity__perplexity_reason
6+
---
7+
8+
Scholar — autonomous research agent for Trinity.
9+
Scans the web for relevant technologies, evaluates findings against project context,
10+
and proposes improvements via GitHub issues or MU Learning DB entries.
11+
12+
Uses Perplexity Sonar API via MCP (4 tools: search, ask, research, reason).
13+
14+
## Modes
15+
16+
Parse $ARGUMENTS to determine mode:
17+
18+
- `scan` — Run SCAN phase only (search for new findings)
19+
- `eval` — Run EVAL phase on last scan results
20+
- `apply` — Run APPLY phase (create issues / enrich MU)
21+
- `full` — Run all 3 phases sequentially (default if no args)
22+
- `topic:"<query>"` — Deep research on a specific topic
23+
- `errors` — Scan for solutions to current broken specs/compilation errors
24+
- `zig` — Scan for Zig 0.15 updates and best practices
25+
- `fpga` — Scan for FPGA/edge AI optimization techniques
26+
- `agents` — Scan for self-evolving agent architectures
27+
28+
## Phase 1: SCAN
29+
30+
### Context Collection (ALWAYS run first)
31+
```bash
32+
# Current project state — feeds into search queries
33+
OPEN_ISSUES=$(gh issue list --state open --json number,title,labels --limit 20 2>/dev/null || echo "[]")
34+
BROKEN_SPECS=$(grep -c "" specs/REGENERATION_REPORT.md 2>/dev/null || echo "0")
35+
TOTAL_SPECS=$(grep -c "✅\|❌" specs/REGENERATION_REPORT.md 2>/dev/null || echo "0")
36+
COMPILE_RATE=$((TOTAL_SPECS > 0 ? (TOTAL_SPECS - BROKEN_SPECS) * 100 / TOTAL_SPECS : 0))
37+
RECENT_ERRORS=$(grep -r "TODO\|FIXME\|HACK" src/ --include="*.zig" 2>/dev/null | head -10)
38+
LAST_COMMITS=$(git log --oneline -5)
39+
ZIG_VERSION=$(zig version 2>/dev/null || echo "0.15.x")
40+
41+
# MU patterns — what errors keep recurring?
42+
MU_PATTERNS=$(cat .ralph/memory/REGRESSION_PATTERNS.md 2>/dev/null | head -30 || echo "none")
43+
44+
# Current priorities from issues
45+
P0_ISSUES=$(echo "$OPEN_ISSUES" | python3 -c "import json,sys; issues=json.load(sys.stdin); p0=[i for i in issues if any('P0' in l.get('name','') for l in i.get('labels',[]))]; [print(f'#{i[\"number\"]}: {i[\"title\"]}') for i in p0]" 2>/dev/null || echo "none")
46+
```
47+
48+
### Search Queries
49+
50+
Based on mode and context, call Perplexity MCP tools.
51+
52+
#### Default scan domains (mode: `scan` or `full`):
53+
54+
1. **Zig ecosystem** — use `perplexity_search`:
55+
Query: "Zig 0.15 {ZIG_VERSION} new features best practices memory allocator patterns 2025 2026"
56+
57+
2. **FPGA + edge AI** — use `perplexity_search`:
58+
Query: "FPGA edge AI optimization ternary computing open source synthesis 2025 2026"
59+
60+
3. **Agent architectures** — use `perplexity_research` (deep):
61+
Query: "self-evolving AI agent architectures autonomous code generation self-improvement loop 2025 2026"
62+
63+
4. **Error-specific** (only if BROKEN_SPECS > 0) — use `perplexity_ask`:
64+
Query: "Zig {ZIG_VERSION} compilation error {first error from REGRESSION_PATTERNS} fix solution"
65+
66+
5. **MCP extensions** — use `perplexity_search`:
67+
Query: "Model Context Protocol MCP new servers tools 2025 anthropic"
68+
69+
#### Mode-specific queries:
70+
71+
- `errors` — Focus all queries on current broken specs and compilation errors.
72+
Read REGENERATION_REPORT.md, extract error messages, search for fixes.
73+
- `zig` — Deep research on Zig language updates.
74+
- `fpga` — Deep research on FPGA synthesis techniques.
75+
- `agents` — Deep research on agent architectures.
76+
- `topic:"<query>"` — Use `perplexity_research` with the exact user query.
77+
78+
### Store scan results
79+
80+
Save raw findings to `.trinity/scholar/`:
81+
```bash
82+
mkdir -p .trinity/scholar
83+
```
84+
85+
Write findings to `.trinity/scholar/scan_YYYYMMDD.json`:
86+
```json
87+
{
88+
"date": "2026-03-11",
89+
"mode": "full",
90+
"context": {
91+
"compile_rate": 85,
92+
"broken_specs": 3,
93+
"open_issues": 8,
94+
"p0_count": 1
95+
},
96+
"findings": [
97+
{
98+
"id": 1,
99+
"domain": "zig",
100+
"query": "...",
101+
"summary": "...",
102+
"citations": ["url1", "url2"],
103+
"raw_response": "..."
104+
}
105+
]
106+
}
107+
```
108+
109+
## Phase 2: EVAL
110+
111+
Read the latest scan file from `.trinity/scholar/`.
112+
113+
For each finding, evaluate relevance to Trinity:
114+
115+
### Scoring Criteria (0.0 - 1.0):
116+
117+
| Factor | Weight | How to measure |
118+
|--------|--------|----------------|
119+
| **Addresses open issue** | 0.3 | Finding matches an open issue title/description |
120+
| **Fixes broken spec** | 0.3 | Finding addresses a known compilation error |
121+
| **Novel technique** | 0.2 | Not already known in project (check REGRESSION_PATTERNS) |
122+
| **Actionable** | 0.2 | Contains specific code/command/approach to implement |
123+
124+
Use `perplexity_reason` to evaluate complex findings:
125+
Query: "Given this Trinity project context: {context}. Rate the relevance of this finding: {summary}. Score 0-1 and explain."
126+
127+
### Classification:
128+
129+
| Score | Action | Label |
130+
|-------|--------|-------|
131+
| > 0.8 | Create GitHub issue | `research:high` |
132+
| 0.5 - 0.8 | Add to MU Learning DB | `research:medium` |
133+
| < 0.5 | Archive (log only) | `research:low` |
134+
135+
Update scan file with scores:
136+
```json
137+
{
138+
"findings": [
139+
{
140+
"id": 1,
141+
"relevance": 0.85,
142+
"classification": "high",
143+
"reason": "Directly addresses broken specs issue...",
144+
"action": "create_issue"
145+
}
146+
]
147+
}
148+
```
149+
150+
## Phase 3: APPLY
151+
152+
Read evaluated scan file. For each finding based on classification:
153+
154+
### HIGH (> 0.8) — Create GitHub Issue
155+
156+
```bash
157+
gh issue create \
158+
--title "research: {concise finding title}" \
159+
--label "research:high,agent:scholar" \
160+
--body "## Scholar Finding
161+
162+
**Source:** {citations}
163+
**Relevance:** {score}/1.0
164+
**Domain:** {domain}
165+
166+
### Summary
167+
{finding summary}
168+
169+
### Proposed Action
170+
{specific steps to apply this finding to Trinity}
171+
172+
### Context
173+
- Compile rate: {rate}%
174+
- Related issues: {matching issues}
175+
176+
---
177+
*Auto-generated by Scholar Agent via Perplexity Sonar API*"
178+
```
179+
180+
Add to project board:
181+
```bash
182+
gh project item-add 6 --owner gHashTag --url "https://github.com/gHashTag/trinity/issues/$ISSUE_NUM"
183+
```
184+
185+
### MEDIUM (0.5-0.8) — Enrich MU Learning DB
186+
187+
Append to `.trinity/mu/learning_db.json`:
188+
```bash
189+
python3 -c "
190+
import json, time
191+
db_path = '.trinity/mu/learning_db.json'
192+
try:
193+
db = json.load(open(db_path))
194+
except: db = {'entries': []}
195+
db['entries'].append({
196+
'timestamp': int(time.time()),
197+
'source': 'scholar',
198+
'domain': '${DOMAIN}',
199+
'summary': '${SUMMARY}',
200+
'relevance': ${SCORE},
201+
'citations': ${CITATIONS},
202+
'applied': False
203+
})
204+
with open(db_path, 'w') as f:
205+
json.dump(db, f, indent=2)
206+
print(f'Added to MU Learning DB: {len(db[\"entries\"])} entries')
207+
"
208+
```
209+
210+
### LOW (< 0.5) — Archive
211+
212+
Just log to `.trinity/scholar/archive.log`:
213+
```bash
214+
echo "$(date -Iseconds) | score=${SCORE} | ${DOMAIN} | ${SUMMARY}" >> .trinity/scholar/archive.log
215+
```
216+
217+
## Output Format
218+
219+
Render a report after each run:
220+
221+
```
222+
═══════════════════════════════════════════════════
223+
🔍 SCHOLAR RESEARCH REPORT — {date}
224+
═══════════════════════════════════════════════════
225+
226+
📡 SCAN CONTEXT
227+
┌──────────────────┬───────────────┐
228+
│ Compile rate │ {rate}% │
229+
│ Broken specs │ {N} │
230+
│ Open issues │ {N} │
231+
│ MU patterns │ {N} │
232+
│ Mode │ {mode} │
233+
└──────────────────┴───────────────┘
234+
235+
🔬 FINDINGS ({N} total)
236+
┌────┬─────────┬───────┬────────────────────────────────────┐
237+
│ # │ Domain │ Score │ Summary │
238+
├────┼─────────┼───────┼────────────────────────────────────┤
239+
│ 1 │ {dom} │ {S} │ {one-line summary} │
240+
│ 2 │ {dom} │ {S} │ {one-line summary} │
241+
└────┴─────────┴───────┴────────────────────────────────────┘
242+
243+
📋 ACTIONS TAKEN
244+
┌────────────┬─────────────────────────────────────────────┐
245+
│ Action │ Details │
246+
├────────────┼─────────────────────────────────────────────┤
247+
│ Issues │ Created #{N}: {title} │
248+
│ MU entries │ {N} findings added to Learning DB │
249+
│ Archived │ {N} low-relevance findings logged │
250+
└────────────┴─────────────────────────────────────────────┘
251+
252+
📚 CITATIONS
253+
1. {url} — {what it's about}
254+
2. {url} — {what it's about}
255+
256+
✨ Scholar says: "{contextual insight about findings}"
257+
```
258+
259+
## Cron Integration
260+
261+
Scholar can be triggered remotely via bridge-agent:
262+
```
263+
claude:Run /scholar full
264+
claude:Run /scholar errors
265+
claude:Run /scholar topic:"ternary neural network quantization"
266+
```
267+
268+
For automated 24h cycle, add to bridge cron:
269+
- 08:00 — `claude:Run /scholar zig` (morning: language updates)
270+
- 20:00 — `claude:Run /scholar errors` (evening: fix broken specs)
271+
- 02:00 — `claude:Run /scholar full` (night: deep research)
272+
273+
## Translation Table (EN → RU)
274+
275+
| EN | RU |
276+
|----|-----|
277+
| SCHOLAR RESEARCH REPORT | ИССЛЕДОВАТЕЛЬСКИЙ ОТЧЁТ SCHOLAR |
278+
| SCAN CONTEXT | КОНТЕКСТ СКАНИРОВАНИЯ |
279+
| FINDINGS | НАХОДКИ |
280+
| ACTIONS TAKEN | ПРЕДПРИНЯТЫЕ ДЕЙСТВИЯ |
281+
| CITATIONS | ИСТОЧНИКИ |
282+
| Domain | Домен |
283+
| Score | Оценка |
284+
| Issues | Задачи |
285+
| MU entries | Записи MU |
286+
| Archived | Архивировано |
287+
| Scholar says | Scholar говорит |
288+
| Created | Создано |
289+
| findings added to Learning DB | находок добавлено в базу обучения |
290+
| low-relevance findings logged | находок низкой релевантности записано |

0 commit comments

Comments
 (0)