brain-doctor
Skill18 starsChanged 2 months agoMITView on GitHub
Lint and repair the Claude Brain Logseq graph — find and fix format violations that create phantom pages or broken macros. Triggers: "brain doctor", "lint brain", "check brain health", "clean up brain", "fix brain", "graph hygiene", "why are there empty pages", "find broken pages", "backfill digests", "rebuild digest for <project>". Don't fire for loads (use brain-load), saves (use brain-save), status/analytics (use brain-status), or first-time setup (use brain-init).
In this repository7 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- evalSkill
- releaseSkill
- brain-initSkill
- brain-loadSkill
- brain-saveSkill
- brain-statusSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
Put text arguments in single quotes.
- Very specific: line 28
Run brain info once, and use its graph: path for the backup and for every Edit this skill makes.
- Distinctive: line 35
If the trigger is ambiguous, run Report first and offer to fix.
- Distinctive: line 56
Confirm before any write: Ask which classes to fix if the user hasn't said.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Brain Doctor
Scan the whole graph for the format mistakes that silently corrupt a Logseq graph. Report them and, on confirmation and after a backup, repair them. This is a maintenance tool: run it on demand, not in the save/load cycle. Detection runs through the helper (below). The catalog of meaning, tiers and remediation is skills/_shared/hygiene-rules.md.
Running the helper
- Bash:
sh "<this skill's base directory>/../_shared/bin/brain" <command> … - PowerShell-only Windows:
& "$(Split-Path (Split-Path (Get-Command git).Source))\bin\bash.exe" "<base>/../_shared/bin/brain" <command> … - Neither works: stop and say "logseq-brain needs Git for Windows (Git Bash) — https://git-scm.com/download/win".
- In Cowork, always pass
--graph <connected folder>. Elsewhere pass--graphonly when the graph is not configured. It may go anywhere on the line. On exit 2 withgraph not resolved, followskills/_shared/path-resolution.md, then pass--graph. - Put text arguments in single quotes; a
'inside becomes'\''. In double quotes the shell runs backticks and expands$. - Exit 0 clean, 1 findings (act on them), 2 error (act on its reason; don't retry blindly). Quote every
coverage:line. Never recompute a figure it printed. Itsgraph:line is the folder for your own Read, Edit and Write calls.
Prerequisites
Run brain info once, and use its graph: path for the backup and for every Edit this skill makes. If it exits 2, follow skills/_shared/path-resolution.md, then pass --graph to every call.
Modes
- Report (default: "lint brain" / "check brain health" / "why are there empty pages"): detect and summarize, change nothing.
- Fix ("fix brain" / "clean up brain" / "yes, fix them" after a report): repair after a backup, with confirmation.
If the trigger is ambiguous, run Report first and offer to fix.
Process
- Scan in one call:
brain lint --all. It prints every mechanical rule, plus the digest rules for every digest-bearing page, asfile:line rule tier detail, followed by asummary:line. Then run the three judgment rules the helper does not:description-link(from the phantom-target procedure underbroken-link),duplicate-entryandstructural-integrity, per the catalog. Report, grouped by the catalog's
auto-fixablefield:- Auto-fixable:
code-in-braces,bare-hash-tag,unnamespaced-link,file-link,relative-link,malformed-property(page-top only), andstale-map/map-label. The digest ones are fixed withbrain digest <page> --apply. - Needs your call:
description-link,broken-link,new-property-key,duplicate-entry,structural-integrity,jira-markup,missing-digest,stale-digest,oversized-digest,nonconvergent-map,duplicate-map— the helper refuses to write on either (see the catalog), so the fix is a human edit, not a bulk pass.
The headline total counts every bucket. Example:
Brain health: 16 issues across 8 pages Auto-fixable (5): 3 bare #tags (incl. C#-parity), 1 {{code}}, 1 stale Map Needs your call (7): 4 links to missing task pages, 2 one-off property keys, 1 unfenced Jira draft Digests (4): 4 pages with no digest — say "backfill digests"Empty pages that lint no longer explains: Logseq never deletes a page once it has parsed one. Pages created by text that has since been fixed survive until the graph is re-indexed in Logseq (All graphs → Re-index). A clean
brain lintplus leftover empty pages means "re-index", not "fix more". If the graph is clean, say so, runbrain activity "ran brain-doctor (clean)", and stop.- Auto-fixable:
- Confirm before any write. Ask which classes to fix if the user hasn't said.
- Back up first. The graph is usually not git-tracked, so there is no undo. Copy
pages/,journals/andlogseq/to a timestamped folder (e.g.<graph>/.brain-doctor-backup-<yyyy-MM-dd-HHmm>/, or the host scratchpad) and say where. If the backup fails, stop. - Repair.
- Mechanical classes: Edit each hit per the catalog's remediation. For high-volume classes a single scripted pass is acceptable (this is one-time maintenance, and a backup exists), but it must mask fenced blocks and inline code exactly as the catalog says.
stale-map/map-label:brain digest <page> --applyper page.- Needs-your-call findings: walk them with the user and apply only what they approve. Never auto-write
broken-link,duplicate-entryorstructural-integritychanges.
- Verify.
brain lint <every file you changed>: expect zero for the fixed classes.- Per-file backtick parity (the catalog's "After repair — verify").
- Then
brain digest <page> --applyon every digest-bearing page whose bytes changed. This is a Remap:digest-updated::and the prose stay untouched. Skip a page with no## Digestsection — that's amissing-digestfinding, not a Remap, and--applyexits 2 on it; leave it to the guided digest backfill below.
brain activity "ran brain-doctor · fixed <N> issues"and report the result.
Guided digest backfill
Triggered by "backfill digests" or accepted from a missing-digest report. The shape is: report, cost, one confirmation, then work.
- Report what is missing: the
missing-digestrows frombrain lint --all. These are pages with no## Digest, and pages whose Digest has no Map line (e.g.Tasks/CRMGM-2037). List each with its size frombrain sections, largest first; the biggest pages pay back a digest soonest. - State the cost before spending it. For each page,
brain sections <page>gives the sections its Rebuild branch will read (skills/_shared/digest.md). Project-shaped pages read Overview, Current Plan, the Decisions headlines and the Session Log tail. Task-shaped pages read their largest one or two sections. Cap each at 8 KB and sum. Quote the sum: "14 pages, ~340 KB on disk — the bounded reads come to roughly 90 KB. Proceed?" - Offer a scope: project pages by default; "all" includes task pages.
- Back up first, unconditionally.
- Build each digest per the Rebuild procedure in
skills/_shared/digest.md: bounded reads, then prose Edits, thenbrain digest <page> --apply. Work one page at a time, so an interruption leaves a consistent graph. - Report pages built, skipped and bytes read. Then
brain activity "backfilled N digests".
Never build a digest without confirmation. It is a write, and it costs tokens.
Important Notes
- Report before repair, backup before write, confirm before both.
- A link to a missing page is not always a bug. Tickets that don't have a page yet are legitimate forward references. Surface them, but leave them unless the user says otherwise.
- Logseq may be running. Recommend closing it (or pausing Sync) during a bulk fix.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

