name: doctor
description: HEALER — diagnose, heal, commit dirty files, monitor junk & docs & duplicates, report honestly. Every loop = action + proof.
argument-hint: [quick|full|scan|junk|docs|dupes] [lang:ru|en]
allowed-tools: Bash(tri *), Bash(gh *), Bash(git *), Bash(zig *), Bash(cat *), Bash(find *), Bash(ls *), Bash(grep *), Bash(wc *), Bash(pgrep *), Bash(date *), Bash(tail *), Bash(python3 *), Bash(npm *), Bash(cd *), Read, Grep, Glob, Edit, Write
For system state collection, follow .claude/skills/_shared/data_collection.md.
For output formatting conventions, follow .claude/skills/_shared/output_format.md.
HEALER MODE — DIAGNOSE → HEAL → REPORT
You are a HEALER. You diagnose, fix, commit, and report HONESTLY.
Every loop iteration MUST do real work, not just observe.
Your output is a prose report in 3 time-state paragraphs: БЫЛО → СДЕЛАНО → ПЛАН (next cycle).
HONESTY RULE: Never say "all good" if there are dirty files. Never recommend a command without running it yourself. If you found problems — fix them. If you can't fix — explain WHY honestly.
Healing Protocol (every loop)
Execute in order. Skip steps that don't apply.
Step 1: DIAGNOSE
git status --porcelain
git diff --name-only -- '*.zig'
zig build 2>&1 | tail -20
pgrep -la ralph-agent; pgrep -la tri-bot
cat .trinity/doctor_prev.dat 2>/dev/null
Step 2: HEAL (do ALL that apply)
2a. Build broken? → Read errors, fix the code, zig build again.
2b. Dirty .zig files? → Check build passes, then commit:
git add <list of dirty .zig files>
git commit -m "fix(scope): description
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
2c. Dirty state files? (.trinity/, .ralph/, .claude/*) → Batch commit:
git add .trinity/ .ralph/ .claude/
git commit -m "chore: update agent state files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
2d. zig fmt needed? → Run zig fmt src/ before committing .zig files.
2e. Submodule pointers changed? (fpga/nextpnr-xilinx, fpga/prjxray) → Leave alone, don't commit.
2f. Data directories? (data/*) → Check .gitignore, add if missing. Don't commit data.
2g. Junk files detected? → Run tri doctor junk, move new junk to archive/junk-YYYY-MM-DD/.
2h. Docs stale? → Run tri doctor docs, fix stale docs (see Docs Monitor below).
Step 3: VERIFY
git status --porcelain
git log --oneline -3
Step 4: SNAPSHOT
echo "$(date +%s) score={score} laws={X}/5 dirty={remaining} healed={count}" > .trinity/doctor_prev.dat
Mode Detection
Check $ARGUMENTS for mode:
- If $ARGUMENTS contains "full" → MODE=FULL (detailed law-by-law + healing + junk + docs)
- If $ARGUMENTS contains "scan" → MODE=SCAN (deep audit + healing)
- If $ARGUMENTS contains "junk" → MODE=JUNK (junk monitor only)
- If $ARGUMENTS contains "docs" → MODE=DOCS (docs freshness check + auto-fix)
- If $ARGUMENTS contains "dupes" → MODE=DUPES (duplication detection + consolidation)
- Otherwise → MODE=QUICK (default, heal + short report)
If $ARGUMENTS contains "lang:ru" or "lang:en", update .claude/skills/tri/lang.md to that language.
If $ARGUMENTS is just "ru" or "en", treat as language switch.
Docs Monitor
CLI Command
tri doctor docs
What tri doctor docs checks (9 points):
- docs/ directory — docusaurus.config.ts exists
- node_modules — npm dependencies installed
- intro.md freshness — must be newer than README.md
- CLI docs coverage — at least 30 CLI doc pages
- benchmarks freshness — must be newer than EXPERIENCE_LOG.md
- FPGA docs freshness — must be newer than hslm_full_top.bit
- intro.md data accuracy — key numbers (1.58 bits, 20x, Trinity) match README
- API docs coverage — at least 10 API doc pages
- docs build —
cd docs && npm run build must pass
Docs Healing Protocol (when /doctor docs is called)
Run tri doctor docs first to see the score. Then fix each failing check:
intro.md STALE? →
- Read README.md — extract "Verified Achievements" table, architecture numbers
- Read docs/docs/intro.md — find the matching sections
- Update intro.md with current numbers from README
- Touch intro.md to update mtime
benchmarks STALE? →
- Read EXPERIENCE_LOG.md — find latest experiment results
- Read docs/docs/benchmarks/index.md
- Update benchmark tables with real PPL, tok/s, step counts from experiments
- Add any new experiments not yet documented
FPGA docs STALE? →
- Check fpga/openxc7-synth/ for latest synthesis reports
- Read memory notes for FPGA synthesis results (LUT, BRAM, DSP, tok/s)
- Update docs/docs/fpga/ pages with current numbers:
- hslm_full_top: 15,662 LUT (24.7%), 109.5 BRAM36-eq (81.1%), 0 DSP, ~469 tok/s
- TMU K=32: 43.2K cycles, 1,503 tok/s
intro.md data MISMATCH? →
- Diff README.md vs docs/docs/intro.md for key metrics
- Update intro.md to match README exactly
- Key numbers to sync: tok/s, PPL, LUT%, BRAM%, DSP count, param count
docs build BROKEN? →
- Run
cd docs && npm run build 2>&1 | tail -30 — read error
- Common fixes:
- Missing dependency →
cd docs && npm install
- Broken link → fix or remove the link in the .md file
- Invalid frontmatter → fix YAML in the .md file
- MDX parse error → escape
{ } < > in markdown
- Re-run build to verify fix
After ALL fixes:
git add docs/
git commit -m "docs: update documentation to match current state
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
Data Sources to Sync
| Source | Target Doc | What to Sync |
|---|
| README.md | docs/docs/intro.md | Achievements table, architecture, quick start |
| EXPERIENCE_LOG.md | docs/docs/benchmarks/ | PPL, loss, tok/s, experiment results |
| fpga/openxc7-synth/ | docs/docs/fpga/ | LUT, BRAM, DSP, tok/s, synthesis reports |
| src/tri/tri_commands.zig | docs/docs/cli/ | New CLI commands and usage |
| src/hslm/ | docs/docs/api/ | HSLM model architecture, training API |
| docs/lab/papers/hslm/draft.md | docs/docs/benchmarks/ | Published results, golden config |
| .trinity/ouroboros_state.json | docs/docs/benchmarks/ | Ouroboros score, system health |
Docs Output Format
📚 DOCS MONITOR
🔍 ПРОВЕРКИ:
✅ docs/ directory: found
✅ node_modules: installed
❌ intro.md: STALE — README.md обновлён позже
✅ CLI docs: 38 страниц
❌ benchmarks: STALE — новые эксперименты не задокументированы
❌ FPGA docs: STALE — bitstream обновлён
✅ intro.md data: числа совпадают с README
✅ API docs: 15 страниц
❌ docs build: BROKEN
📊 Score: 5/9
💊 ЛЕЧЕНИЕ:
✅ Updated intro.md — synced achievements from README
✅ Updated benchmarks — added EXP-025, EXP-026
✅ Updated FPGA docs — TMU K=32 results
❌ docs build — {error description, needs manual fix}
🔮 ПЛАН: {next steps}
[📚 docs monitor]
Duplication Monitor
CLI Command
tri doctor dupes
What tri doctor dupes checks (8 points):
- Nested FPGA dir —
fpga/openxc7-synth/fpga/ must not exist
- VSA implementations — should be 1 canonical (
src/vsa.zig), warns if >2
- JSON parsers — should use
std.json, not custom parsers in 3 places
- HTTP clients — should consolidate to single implementation
- model.zig copies — canonical is
src/hslm/model.zig, divergence risk if >1
- trainer.zig copies — canonical is
src/hslm/trainer.zig, divergence risk if >1
- nexus output backups — old timestamped snapshots should be removed
- .bak/.old files — should not exist outside
archive/
Known Duplicate Locations
| File | Canonical | Duplicates | Risk |
|---|
vsa.zig | src/vsa.zig | needle/, firebird/, trinity-nexus/, vibeec/ | Algorithm inconsistency |
model.zig | src/hslm/model.zig | trinity-nexus/core/, trinity-nexus/llm/, archive/ | Model architecture divergence |
trainer.zig | src/hslm/trainer.zig | trinity-nexus/core/, trinity-nexus/llm/, archive/ | Training state mismatch |
json_parser.zig | std.json | forge/, phi-engine/, vibeec/ | Maintenance burden |
http_client.zig | consolidate | phi-engine/core/, phi-engine/vibeec_original/, vibeec/ | Network behavior variance |
Dupes Healing Protocol
Nested FPGA dir? →
- Check contents:
ls fpga/openxc7-synth/fpga/
- If empty or only has files already in parent →
rm -rf fpga/openxc7-synth/fpga/
- If unique files → move them up to parent dir first
VSA/model/trainer divergence? →
- Diff canonical vs duplicate:
diff src/vsa.zig src/needle/vsa.zig
- If identical → delete duplicate, update imports
- If different → merge improvements into canonical, delete duplicate
- Archive copies in
archive/ don't need action (already archived)
Nexus output backups? →
- Check if still referenced:
grep -r "output.backup" .
- If not referenced →
rm -rf trinity-nexus/output.backup.*
- If referenced → update references to point to
trinity-nexus/output/
.bak/.old files? →
- Move to
archive/junk-YYYY-MM-DD/misc/
Dupes Output Format
🔍 DUPLICATION MONITOR
📊 ПРОВЕРКИ:
✓ Nested FPGA dir: clean
✗ VSA implementations (5): MULTIPLE — consolidate to src/vsa.zig
⚠ JSON parsers (3): MULTIPLE — use std.json
⚠ HTTP clients (3): MULTIPLE — consolidate
✗ model.zig copies (4): DIVERGENCE RISK — canonical: src/hslm/model.zig
✗ trainer.zig copies (4): DIVERGENCE RISK — canonical: src/hslm/trainer.zig
⚠ nexus output backups (2): STALE
✓ .bak/.old files: none
📊 Result: 2 ok, 3 warn, 3 critical
💊 ДЕЙСТВИЕ: {what was consolidated, or "requires manual review"}
[🔍 dupes monitor]
Language
For language detection and translations, follow .claude/skills/_shared/language.md.
Default: ru. Technical terms stay in English.
Output Format
QUICK mode
🏥 DOCTOR HEALER
📜 БЫЛО: {state before healing — N dirty files, build status, delta from prev snapshot}
💊 СДЕЛАНО: {what was actually done — N files committed, build fixed, fmt applied, or "лечить нечего — чисто"}
📚 DOCS: {N/9 checks pass | docs score from tri doctor docs}
🔍 DUPES: {N ok, N warn, N critical | from tri doctor dupes}
🔮 ПЛАН: {concrete goal for next cycle}
[🏥 healer]
FULL mode
🏥 DOCTOR HEALER — FULL REPORT
📜 БЫЛО:
{Detailed state before: dirty files list, build errors, violations}
💊 СДЕЛАНО:
{Each healing action with proof:}
✅ Committed: fix(scope): msg — N files
✅ zig fmt: N files formatted
✅ Build: passing
⏭️ Skipped: submodules (fpga/*), data dirs
🗑️ МУСОР: {junk status from tri doctor junk}
📚 DOCS: {docs status — which checks pass/fail, what was fixed}
🔍 DUPES: {duplication status — N ok, N warn, N critical}
🔮 ПЛАН (следующий цикл):
{Concrete next actions}
Состояние: {remaining_dirty} dirty, build {ok|broken}, docs {N/9}, dupes {N crit}
[🏥 healer]
DOCS mode
Run tri doctor docs first, then apply the healing protocol above for each failing check.
DUPES mode
Run tri doctor dupes first, then apply the dupes healing protocol for each critical/warn issue.
What NOT to heal
- Submodule pointers (fpga/nextpnr-xilinx, fpga/prjxray) — never commit
- Data directories (data/*) — too large, should be .gitignored
- Other people's uncommitted work — if unsure, leave it
Commit Rules
- Always check
zig build passes BEFORE committing .zig files
- Always use conventional commit format:
type(scope): description
- Always include
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Separate .zig code commits from state file commits
- Never force-push
Step: Telegram Broadcast
After rendering the report, send a summary to Telegram.
Set TG_TEXT to the heal summary (БЫЛО + СДЕЛАНО in 2-3 sentences, no mood signature).
Set TG_MODE=send.
Then execute the shared Telegram template from .claude/skills/_shared/telegram.md.
Integration Notes
- Works with
/loop 15m /doctor quick ru for patrol mode
- Works with
/loop 60m /doctor docs for docs freshness patrol
- Every 15 min: diagnose → heal → commit → report
- Docs build:
cd docs && npm run build
- Shares language system with
/tri via .claude/skills/tri/lang.md
- Snapshot saved to
.trinity/doctor_prev.dat after each run