Setup
28.9kConfigura GBrain con auto-aprovisionamiento de Supabase o PGLite, inyección en AGENTS.md y primera importación.
- Costo de contexto al activarse
- 7.4k tok
- Tamaño del paquete
- 1 archivo
- Última actualización
- hace 4 días
Toma un libro (EPUB/PDF) y genera un análisis personalizado capítulo a capítulo: cada capítulo se conserva en detalle y se refleja en la vida real del lector usando el contexto de su brain.
Reemplaza a: Generic book summary skill (for flat summaries), strategic-reading (for a problem-lens read instead of full personalization)
en todo el repo
0–100, la ruta de este skill
último commit aquí
últimos 90 días
160 tok en reposo
27 KB
Funciona con cualquier agente que lea SKILL.md
npx -y skills add garrytan/gbrain --skill book-mirror --agent claude-codeSe instala solo en este repositorio.
Este skill reads environment config.
Di cualquiera de estas frases y el agente debería cargar este skill.
Convention: see _brain-filing-rules.md for the sanctioned
media/<format>/<slug>exception this skill files under.Convention: see conventions/quality.md for citation rules, back-link enforcement, and output quality bars.
Convention: see conventions/brain-first.md for the lookup chain (brain → search → external) the context-gathering phase follows.
Given a book (EPUB or PDF), produce a brain page where every chapter is
summarized in detail on one side ("The Chapter") and mirrored back to the
reader's actual life on the other ("The Mirror"), using their own words,
situations, people, and patterns from the brain. Output is a brain page at
media/books/<slug>-personalized.md.
This is NOT a generic book summary. The mirror is the value: it makes the book read like a smart friend who happens to know the reader's life deeply is pointing things out in the margins. The mirror's job is recognition — "that's exactly me" — and then getting out of the way. If the user wants a flat summary instead, route them to a different skill.
book-mirror runs as a CLI command (gbrain book-mirror), NOT as a pure
markdown skill that the agent dispatches via tools. The CLI is the trusted
runtime; the skill is the orchestration prose around it.
What this means for the agent:
allowed_tools: ['get_page', 'search'] only. They CANNOT call
put_page or any mutating op. They produce markdown analysis via their
final message.job.result, assembles the final
page, and writes it via a single operator-trust put_page.people/* page. The trust narrowing happens at the tool allowlist,
not at the slug-prefix layer.1. ACQUIRE → User has the EPUB/PDF locally (manual; book-acquisition is
not currently shipped — see "Acquiring the book" below).
2. EXTRACT → Pull chapter text from EPUB/PDF into one .txt per chapter.
3. CONTEXT → Gather everything the brain knows about the reader.
4. ANALYZE → `gbrain book-mirror` fans out N read-only subagents.
5. ASSEMBLE → CLI reads each child result and writes one put_page.
6. PDF → Optional: render via skills/brain-pdf for delivery.
book-acquisition (legal-grey-area downloader) was deliberately not shipped in this skill wave. The user drops the EPUB/PDF manually. Common paths the user might use:
# User-supplied path
ls path/to/book.epub
ls path/to/book.pdf
# Or already in the brain repo (recommended for tracking)
ls $BRAIN_DIR/media/books/
Resolve $BRAIN_DIR from the gbrain config (gbrain config get sync.repo_path)
or accept it from the user.
Goal: one .txt file per chapter under a temp directory. The agent has
shell + python access; the CLI is downstream of this and takes the
extracted directory as input.
SLUG="this-book" # kebab-case
WORK="$(mktemp -d)/$SLUG"
mkdir -p "$WORK/chapters"
unzip -o path/to/book.epub -d "$WORK/unpacked"
# Find content files (XHTML/HTML), sorted (chapter order = sort order)
find "$WORK/unpacked" -name "*.xhtml" -o -name "*.html" | sort > "$WORK/files.txt"
# Strip HTML to text per chapter
python3 - <<'PY'
from bs4 import BeautifulSoup
import os, sys
work = os.environ['WORK']
files = open(f'{work}/files.txt').read().splitlines()
for i, path in enumerate(files, 1):
html = open(path, encoding='utf-8', errors='replace').read()
text = BeautifulSoup(html, 'html.parser').get_text('\n')
text = '\n'.join(line.strip() for line in text.splitlines() if line.strip())
with open(f'{work}/chapters/{i:02d}.txt', 'w') as f:
f.write(text)
PY
If bs4 is missing: pip3 install beautifulsoup4 lxml.
Inspect the chapter files to identify which are real chapters vs front
matter (TOC, copyright, acknowledgments). Often the EPUB ships one file
per chapter; sometimes multiple chapters per file. Use
head -5 "$WORK/chapters/"*.txt to spot-check.
pdftotext -layout path/to/book.pdf "$WORK/full.txt"
Then split by chapter heading (look for "Chapter N", "CHAPTER N", or
all-caps title lines) using awk or python. If the PDF is a scan with
no embedded text, fall back to OCR via skills/brain-pdf or another
vision tool.
For each chapter file:
\n\n.Save a chapters/INDEX.md mapping chapter number → title → file → word
count for reference.
This is the most critical step. The mirror is only as good as the context fed to each chapter subagent.
templates/USER.md and templates/SOUL.md;
they live in the brain repo when populated). Read full.wiki/personal/reflections/ or wherever the user files daily notes.gbrain query "marriage", gbrain query "couples therapy" for a
marriage book.gbrain query "founders", gbrain query "fundraising" for a
business book.gbrain query "shame", gbrain query "anger" for a psychology book.gbrain query "<name>" for
people who will likely come up.A thin static context pack is the #1 cause of a generic mirror. The quality ceiling is the brain itself, not whatever got manually stuffed into one file. Do per-section retrieval before invoking the CLI:
Query generation strategy (per section):
Execution:
gbrain query "QUERY" --limit 3
gbrain get "PAGE_SLUG"
Budget: 15–20 searches per section × N sections, plus 40–60 full page
fetches. All local DB queries — essentially free. Target 50–80K chars of
retrieved brain context total. The chapter subagents also carry read-only
search + get_page tools at run time, so the context pack is the floor,
not the ceiling — but do not rely on subagents to rediscover what the
orchestrating pass already found.
Minimum retrieved material for a high-stakes mirror:
Write everything to a single file the CLI can read:
CONTEXT="$WORK/context.md"
{
echo "## USER.md (if any)"
[ -f "$BRAIN_DIR/USER.md" ] && cat "$BRAIN_DIR/USER.md"
echo
echo "## SOUL.md (if any)"
[ -f "$BRAIN_DIR/SOUL.md" ] && cat "$BRAIN_DIR/SOUL.md"
echo
echo "## Recent reflections (last 14 days)"
# Pull recent daily reflections — adapt to the user's filing scheme
# ...
echo
echo "## Topic-relevant brain pages (grouped per chapter)"
# Deep-retrieval results from above, grouped by the chapter they serve
# ...
echo
echo "## Themes & cruxes"
# A 1-page summary, written by the agent, calling out:
# - What's currently active in the user's life that this book intersects
# - Specific quotes from the user that map to book themes
# - People and dates that should appear in the mirror
# - The anti-repetition constraints (domain map + phrase caps, below)
} > "$CONTEXT"
Make this dense. It's read by every chapter subagent. Encode the anti-repetition constraints (next section) here — the per-chapter domain assignment and phrase caps only work if every subagent can see them.
These rules were earned through iteration with cross-modal eval. They are mandatory for every book-mirror.
The single most important lesson: rich chapter summaries drive varied mirrors. When you compress the source material, the mirror has nothing to respond to except its own greatest hits. The two halves are symbiotic, not competing for space.
Rule: Every distinct idea, story, framework, numbered list item, and memorable phrase the author presents gets its own section. If the author lists six kinds of loneliness, that's six sections. If they tell three stories, that's three sections. The Chapter half should be detailed enough that someone could skip the book and not lose much. The Mirror half responds to EACH specific idea with a DIFFERENT personal mapping.
Do NOT emit a bare | The Chapter | The Mirror | markdown pipe
table. GitHub (and most renderers) pad a table row's cells to equal height
and vertically center the shorter cell's text — so when the two halves
differ in length (they always do), one column floats down with a block of
whitespace above it. Plain markdown has no per-cell vertical-align. That
is the root cause, not a styling nit.
Two valid containers — both are correct, pick by destination:
Top-aligned HTML table (the CLI default). The gbrain book-mirror
chapter prompt already mandates an HTML <table> with valign="top"
on EVERY <td> — this is baked into the trusted runtime. Facts worth
knowing when hand-writing or repairing a mirror: GitHub KEEPS
valign="top" but STRIPS inline style="vertical-align", and does NOT
render markdown emphasis inside a raw <td> — pre-convert emphasis to
<em>/<strong>, and use <br><br> for paragraph breaks within a
cell.
Stacked sections — best for mobile and chat delivery, and the right choice for any hand-assembled mirror (children's variant, retro-fixes of legacy pages):
### Chapter N: <title>
**The Chapter**
<chapter prose, normal paragraphs separated by blank lines>
**The Mirror**
<mirror prose, normal paragraphs separated by blank lines>
Use real blank-line paragraph breaks, never <br><br> outside a table
cell. Reads top-to-top every time, zero alignment bug. The
Chapter/Mirror naming and the one-section-per-idea richness rule are
unchanged — only the container changes.
"Be more varied" doesn't work as an instruction. LLMs remix the deck they're given — if the deck is 6 cards, you get 6 cards N times. Use hard constraints, written into the context pack's "Themes & cruxes" section:
Domain mapping: Before writing, assign each chapter a PRIMARY life domain (career, family, civic work, creative life, a specific relationship, childhood, intellectual life, spiritual practice, etc.). No two adjacent chapters should share the same primary domain.
Phrase caps: No word or phrase may appear as a thematic anchor in more than 3 chapters. Identify the reader's "greatest hits" (the 5–6 themes that would dominate without constraints) and set explicit limits or bans.
Story deduplication: Before writing each mirror, check: "Have I already used this story/incident/quote in a previous chapter?" If yes, find a different one.
Emotional range requirement: At least 25% of chapters must map to JOY, HUMOR, CREATIVE EXCITEMENT, or VICTORY — not only wounds and struggle. When the author describes something beautiful, the mirror should find something beautiful in the reader's life.
Deep retrieval is the engine, not the product. The reader should never feel like they're reading a research paper or a search results page. The mirror must read like a brilliant essay by someone who knows the reader deeply — not a report proving it did homework.
The test: If you remove all citations and source attributions, does the mirror still make the reader feel seen? Does it still produce epiphanies? Does it still work as standalone writing? If yes, the retrieval served its purpose. If the mirror only works because of its citations, the retrieval failed.
Citations: Optional. Use sparingly as footnotes when the source adds genuine value ("you wrote this at 19" lands differently when the reader knows you actually read the journal entry). But never let citations become the point. Never let the mirror read like it's performing thoroughness.
After generating a mirror, run gbrain eval cross-modal (or the manual
gate in skills/cross-modal-review/SKILL.md) with these custom
dimensions:
gbrain eval cross-modal --slug <slug>-personalized \
--dimensions VARIETY,SPECIFICITY,DEPTH,LEFT_COLUMN_FIDELITY,EMOTIONAL_RANGE
Pass threshold: all dimensions average 7+ across models. If any dimension is below 6, rebuild with targeted fixes. The eval→fix→re-eval cycle is the quality multiplier. Evaluator model pairs and refusal routing follow conventions/cross-modal.yaml.
For picture books and children's books (under ~5K words), use a Parent's Reading Guide format instead of the standard mirror:
Hand-assembled variants like this use the stacked-sections container.
gbrain book-mirrorgbrain book-mirror \
--chapters-dir "$WORK/chapters" \
--context-file "$CONTEXT" \
--slug "$SLUG" \
--title "Book Title Goes Here" \
--author "Author Name" \
--model claude-opus-4-7
The CLI:
allowed_tools.job.result (the markdown analysis text).put_page to media/books/<slug>-personalized.md.{"slug": "...", "chapters_total": N, "chapters_completed": N, "chapters_failed": 0}.If any chapter failed, the CLI exits 1 and the user can re-run — idempotency
keys (book-mirror:<slug>:ch-<N>) deduplicate completed chapters at the
queue level, so retry is cheap. Note that reproducing verbatim book quotes
plus the reader's verbatim words can occasionally trip a provider output
filter; a chapter blocked that way is just a failed chapter — re-run, or
retry with a different --model.
The default model is claude-opus-4-7. Sonnet works (use --model claude-sonnet-4-6) but the mirror quality drops noticeably — the
texture that makes the analysis feel like it was written by someone who
knows the reader needs Opus-grade reasoning.
The CLI refuses to spend in a non-TTY context without --yes. CI / scripted
invocations must pass --yes explicitly. TTY users get a [y/N] prompt
before submission.
Deep retrieval raises total cost meaningfully versus a thin static context pack (roughly an order of magnitude at Opus rates). The quality jump is worth it for a book the reader cares about; use a static pack only for low-stakes runs.
After the brain page is written (the CLI already did the put_page),
render to PDF using skills/brain-pdf:
# See skills/brain-pdf/SKILL.md for the invocation.
If the user asked for a deliverable, prefer the PDF over sending raw markdown — the brain page is the source of truth; the PDF is the artifact that travels.
After the page lands, run a fact-check pass on factual claims about the reader (parents, siblings, marriage history, jobs, heritage). Common error patterns to look for:
If you can't verify a claim, remove it. Better to lose texture than to introduce a falsehood.
Cross-link entities mentioned in the analysis:
people/<slug> to the new media/books/<slug>-personalized
page (per conventions/quality.md Iron Law).The Chapter half should:
The Mirror half should:
The whole document should feel like one coherent voice, calibrated to the reader's actual life rather than a generic profile, and honest about where the book's framing breaks down for this specific reader. It should make the reader feel SEEN, not studied — and work as good standalone writing even with every citation stripped.
<table> with valign="top" on every
<td>, or stacked sections. See the layout hard rule above.$WORK/chapters/*.txt with sane word counts.$WORK/context.md is dense: deep-retrieval results
grouped per chapter + domain map + phrase caps.gbrain book-mirror --chapters-dir … --context-file … --slug … --title … returned exit 0.media/books/<slug>-personalized.md exists in the brain.skills/brain-pdf/SKILL.md — render the personalized page to PDF.skills/strategic-reading/SKILL.md — read a book through a specific
problem-lens instead of personalizing to the whole reader.skills/article-enrichment/SKILL.md — same shape applied to articles
rather than books.skills/cross-modal-review/SKILL.md — the manual second-model quality
gate; gbrain eval cross-modal is the scripted sibling surface.This skill guarantees:
writes_to: (when applicable).quality.md, brain-first.md, _brain-filing-rules.md) are followed.The full behavior contract is documented in the body sections above; this section exists for the conformance test.
The skill's output shape is documented inline in the body sections above (see "Output", "Brain page format", or equivalent). The literal section header here exists for the conformance test (test/skills-conformance.test.ts).
The full anti-pattern list is in the body sections above; this header exists for the conformance test if the body uses a different casing.
Reproducido de garrytan/gbrain bajo licencia MIT. Leer esta página en markdown.
2 archivos en el paquete. Solo se lee SKILL.md al activarse — las referencias se cargan si el skill decide que las necesita.
Requires the gbrain CLI, a local EPUB/PDF, a configured brain (USER.md/SOUL.md), and Python with beautifulsoup4/lxml for EPUB extraction.
Necesita en el PATH:python3
Variables de entorno:BRAIN_DIRCONTEXTSLUGWORK
Este repo incluye 75 skills. Si instalas uno, normalmente ya tienes los demás.
Configura GBrain con auto-aprovisionamiento de Supabase o PGLite, inyección en AGENTS.md y primera importación.
Chequeos de salud del brain: aplicación de back-links, auditoría de citas, validación de filing, detección de info obsoleta, páginas huérfanas y benchmarks.
Migra un brain de gbrain-base a la taxonomía de 14 tipos canónicos de gbrain-base-v2 usando gbrain onboard --check y el handler Minion unify-types.
Cuándo y qué recuperar: abre la página del brain de una entidad relevante antes de responder desde memoria.
Operaciones del brain: búsqueda primero, ciclo leer-enriquecer-escribir, atribución de fuentes, enriquecimiento ambiental y back-linking. Leer antes de cualquier interacción con el brain.
Importa exports de ChatGPT, Claude y Perplexity y transcripciones de sesiones como páginas fechadas en conversations/, valida y extrae hechos, y mantiene el archivo sin huecos con detección y backfill.
Genera un PDF de calidad de publicación desde cualquier brain page usando el binario make-pdf de gstack; la brain page siempre es la fuente de verdad, el PDF es solo una renderización.
Audita y corrige el formato de citas en las páginas del brain, asegurando que cada hecho tenga [Source: ...]; resuelve referencias a tweets sin URL vía la API de X.”
Reglas de decisión para archivar páginas nuevas del brain según el tema principal, no el formato ni la fuente. Referencia para todas las skills de escritura.