book-mirror
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesebook-mirror — Personalized Chapter-by-Chapter Book Analysis
book-mirror — 个性化书籍逐章分析
Convention: see _brain-filing-rules.md for the sanctionedexception this skill files under.media/<format>/<slug>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.
约定: 请查看 _brain-filing-rules.md 了解此技能遵循的例外归档规则。media/<format>/<slug>约定: 请查看 conventions/quality.md 了解引用规则、反向链接要求及输出质量标准。约定: 请查看 conventions/brain-first.md 了解上下文收集阶段遵循的查找链(大脑知识库 → 搜索 → 外部资源)。
What this does
功能说明
Given a book (EPUB or PDF), produce a brain page where every chapter is
summarized in detail on the left and mirrored back to the reader's actual life
on the right, using their own words, situations, people, and patterns from
the brain. Output is a brain page at .
media/books/<slug>-personalized.mdThis is NOT a generic book summary. The right column is the value: it makes
the book read like a therapist who knows the reader is leaving notes in the
margins. If the user wants a flat summary instead, route them to a different
skill.
导入任意EPUB或PDF格式书籍,生成一个大脑页面,其中每章内容在左栏详细呈现,右栏则利用读者大脑知识库中的个人表述、经历、人际关系和行为模式,将书中内容与读者的真实生活关联起来。输出结果为位于的大脑页面。
media/books/<slug>-personalized.md请注意:这不是通用书籍摘要。右栏是核心价值所在:它让书籍阅读体验如同一位熟悉读者批注的心理咨询师。如果用户需要的是普通摘要,请引导他们使用其他技能。
Trust contract (read this before running)
信任协议(运行前必读)
book-mirror runs as a CLI command (), 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.
gbrain book-mirrorWhat this means for the agent:
- The CLI submits N read-only subagent jobs (one per chapter). Each subagent
has only. They CANNOT call put_page or any mutating op. They produce markdown analysis via their final message.
allowed_tools: ['get_page', 'search'] - The CLI reads each child's , assembles the final two-column page, and writes it via a single operator-trust
job.result.put_page - This means untrusted EPUB/PDF content cannot prompt-inject any
page. The trust narrowing happens at the tool allowlist, not at the slug-prefix layer.
people/*
book-mirror以CLI命令形式运行(),而非由Agent通过工具调度的纯Markdown技能。CLI是可信运行环境;本技能仅负责编排流程说明。
gbrain book-mirror这对Agent意味着:
- CLI会提交N个只读子Agent任务(每章一个)。每个子Agent仅拥有权限,无法调用put_page或任何修改操作。它们通过最终消息生成Markdown分析内容。
allowed_tools: ['get_page', 'search'] - CLI读取每个子任务的,组装成最终的双栏页面,并通过一次受信任的操作员
job.result操作完成写入。put_page - 这意味着不可信的EPUB/PDF内容无法通过提示注入修改任何页面。信任限制通过工具权限列表实现,而非路径前缀层。
people/*
The pipeline
处理流程
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.1. 获取书籍 → 用户本地已有EPUB/PDF文件(手动操作;目前未提供书籍获取功能——详见下方“获取书籍”)。
2. 提取文本 → 从EPUB/PDF中提取章节文本,每章保存为一个.txt文件。
3. 收集上下文 → 收集大脑知识库中关于读者的所有信息。
4. 分析处理 → `gbrain book-mirror`分发N个只读子Agent任务。
5. 组装页面 → CLI读取每个子任务结果,执行一次put_page操作写入内容。
6. 生成PDF(可选)→ 通过skills/brain-pdf工具渲染为PDF格式交付。1. Acquiring the book
1. 获取书籍
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:
bash
undefinedbook-acquisition(涉及法律灰色地带的下载工具)未包含在本次技能发布中。用户需手动导入EPUB/PDF文件。用户常用的文件路径示例:
bash
undefinedUser-supplied path
用户提供的路径
ls path/to/book.epub
ls path/to/book.pdf
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.ls $BRAIN_DIR/media/books/
从gbrain配置中解析`$BRAIN_DIR`(`gbrain config get sync.repo_path`),或接受用户输入的路径。2. Text extraction
2. 文本提取
Goal: one 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.
.txt目标:在临时目录下为每章生成一个文件。Agent拥有shell和python权限;CLI会接收提取后的目录作为输入。
.txtEPUB
EPUB格式
bash
SLUG="this-book" # kebab-case
WORK="$(mktemp -d)/$SLUG"
mkdir -p "$WORK/chapters"
unzip -o path/to/book.epub -d "$WORK/unpacked"bash
SLUG="this-book" # 短横线命名格式
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)
查找内容文件(XHTML/HTML)并按章节顺序排序
find "$WORK/unpacked" -name ".xhtml" -o -name ".html" | sort > "$WORK/files.txt"
find "$WORK/unpacked" -name ".xhtml" -o -name ".html" | sort > "$WORK/files.txt"
Strip HTML to text per chapter
剥离HTML标签,提取每章文本
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.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
若缺少`bs4`库:执行`pip3 install beautifulsoup4 lxml`安装。
检查章节文件,区分真实章节与前置内容(目录、版权页、致谢)。通常EPUB每章对应一个文件;有时多个章节会合并到一个文件中。可使用`head -5 "$WORK/chapters/"*.txt`进行抽查。PDF格式
bash
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 or . If the PDF is a scan with
no embedded text, fall back to OCR via or another
vision tool.
awkpythonskills/brain-pdfbash
pdftotext -layout path/to/book.pdf "$WORK/full.txt"随后通过或python按章节标题(查找“Chapter N”、“CHAPTER N”或全大写标题行)拆分文本。若PDF是无嵌入文本的扫描件,则需通过或其他视觉工具进行OCR识别。
awkskills/brain-pdfQuality check
质量检查
For each chapter file:
- Word count > 1500 (typical chapter range 2k–8k words).
- No HTML tags.
- Paragraphs preserved with .
\n\n
Save a mapping chapter number → title → file → word
count for reference.
chapters/INDEX.md对每个章节文件进行如下检查:
- 字数>1500(典型章节字数范围2k–8k)。
- 无HTML标签。
- 段落用分隔保留格式。
\n\n
保存文件,映射章节编号→标题→文件→字数,以供参考。
chapters/INDEX.md3. Context gathering
3. 上下文收集
This is the most critical step. The right column is only as good as the
context fed to each chapter subagent.
这是最关键的步骤。右栏内容的质量完全取决于提供给每章子Agent的上下文信息。
What to pull
需要提取的内容
- Templates: USER.md and SOUL.md if the user maintains them
(gbrain ships templates at and
templates/USER.md; they live in the brain repo when populated). Read full.templates/SOUL.md - Recent daily memory — last 14 days of brain pages under
or wherever the user files daily notes.
wiki/personal/reflections/ - Topic-relevant brain searches tuned to the book's themes:
- ,
gbrain query "marriage"for a marriage book.gbrain query "couples therapy" - ,
gbrain query "founders"for a business book.gbrain query "fundraising" - ,
gbrain query "shame"for a psychology book.gbrain query "anger"
- Brain pages for relevant entities — for people who will likely come up.
gbrain query "<name>" - Standing patterns — anything in the user's reflections or originals that's been recurring.
- 模板文件:USER.md和SOUL.md(如果用户已维护)
(gbrain在和
templates/USER.md提供模板;用户填充后存储在大脑仓库中)。需完整读取。templates/SOUL.md - 近期日常记忆 — 大脑知识库中或用户存储日常笔记的其他路径下最近14天的页面。
wiki/personal/reflections/ - 与书籍主题相关的大脑知识库搜索:
- 若为婚姻类书籍,执行、
gbrain query "marriage"。gbrain query "couples therapy" - 若为商业类书籍,执行、
gbrain query "founders"。gbrain query "fundraising" - 若为心理学类书籍,执行、
gbrain query "shame"。gbrain query "anger"
- 若为婚姻类书籍,执行
- 相关实体的大脑页面 — 对可能出现的人物执行。
gbrain query "<name>" - 持续出现的模式 — 用户反思或原创内容中反复出现的任何内容。
Assemble a context pack
组装上下文包
Write everything to a single file the CLI can read:
bash
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"
# gbrain query the book's key themes, embed top results
# ...
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 right column
} > "$CONTEXT"Make this dense. It's read by every chapter subagent.
将所有内容写入单个文件供CLI读取:
bash
CONTEXT="$WORK/context.md"
{
echo "## USER.md(如有)"
[ -f "$BRAIN_DIR/USER.md" ] && cat "$BRAIN_DIR/USER.md"
echo
echo "## SOUL.md(如有)"
[ -f "$BRAIN_DIR/SOUL.md" ] && cat "$BRAIN_DIR/SOUL.md"
echo
echo "## 近期反思(最近14天)"
# 提取近期日常反思内容 — 适配用户的归档方案
# ...
echo
echo "## 主题相关大脑页面"
# 对书籍核心主题执行gbrain query,嵌入顶级结果
# ...
echo
echo "## 核心主题与关键要点"
# 由Agent撰写的1页摘要,需包含:
# - 用户当前生活中与本书内容相关的事件
# - 用户表述中与书籍主题匹配的具体引文
# - 右栏中应提及的人物和日期
} > "$CONTEXT"内容需尽可能详实,供每章子Agent读取。
4. Analysis: invoke gbrain book-mirror
gbrain book-mirror4. 分析处理:调用gbrain book-mirror
gbrain book-mirrorbash
gbrain book-mirror \
--chapters-dir "$WORK/chapters" \
--context-file "$CONTEXT" \
--slug "$SLUG" \
--title "Book Title Goes Here" \
--author "Author Name" \
--model claude-opus-4-7The CLI:
- Validates inputs and loads chapter files.
- Prints a cost estimate (~$0.30/chapter at Opus) and prompts to confirm.
- Submits N child subagent jobs with read-only .
allowed_tools - Waits for every child to complete.
- Reads each child's (the markdown analysis text).
job.result - Assembles all chapters into one page with frontmatter + intro + per-chapter sections + closing.
- Writes ONE to
put_page.media/books/<slug>-personalized.md - Reports a JSON envelope on stdout:
.
{"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 () deduplicate completed chapters at the
queue level, so retry is cheap.
book-mirror:<slug>:ch-<N>bash
gbrain book-mirror \
--chapters-dir "$WORK/chapters" \
--context-file "$CONTEXT" \
--slug "$SLUG" \
--title "Book Title Goes Here" \
--author "Author Name" \
--model claude-opus-4-7CLI执行以下操作:
- 验证输入并加载章节文件。
- 打印成本估算(使用Opus模型约每章0.30美元)并提示确认。
- 提交N个拥有只读权限的子Agent任务。
allowed_tools - 等待所有子任务完成。
- 读取每个子任务的(Markdown分析文本)。
job.result - 将所有章节内容组装成包含前置内容+引言+逐章小节+结语的单个页面。
- 执行一次操作,写入
put_page。media/books/<slug>-personalized.md - 在标准输出中返回JSON结果:
。
{"slug": "...", "chapters_total": N, "chapters_completed": N, "chapters_failed": 0}
若有章节处理失败,CLI会以状态码1退出,用户可重新运行——幂等键()会在队列层面去重已完成的章节,因此重试成本极低。
book-mirror:<slug>:ch-<N>Model: Opus by default
默认模型:Opus
The default model is . Sonnet works (use ) but the right-column quality drops noticeably — the
texture that makes the analysis read like a therapist who knows the user
needs Opus-grade reasoning.
claude-opus-4-7--model claude-sonnet-4-6默认模型为。Sonnet模型也可使用(添加参数),但右栏质量会明显下降——要让分析内容达到“熟悉读者的心理咨询师”级别的质感,需要Opus级别的推理能力。
claude-opus-4-7--model claude-sonnet-4-6Cost gate
成本限制
The CLI refuses to spend in a non-TTY context without . CI / scripted
invocations must pass explicitly. TTY users get a prompt
before submission.
--yes--yes[y/N]在非TTY环境下,CLI会拒绝执行,除非添加参数。CI/脚本调用必须显式传入。TTY用户会在提交前看到确认提示。
--yes--yes[y/N]5. PDF (optional)
5. 生成PDF(可选)
After the brain page is written, render to PDF using :
skills/brain-pdfbash
gbrain put_page # already done by the CLI; nothing to add here大脑页面写入完成后,使用渲染为PDF:
skills/brain-pdfbash
gbrain put_page # 已由CLI完成,无需额外操作Then invoke brain-pdf:
然后调用brain-pdf:
(see skills/brain-pdf/SKILL.md for the make-pdf invocation)
(详见skills/brain-pdf/SKILL.md中的make-pdf调用方式)
undefinedundefined6. Fact-check and cross-link
6. 事实核查与交叉链接
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:
- Conflating the reader's parents' relationship with patterns in extended family.
- Inventing therapy backstory ("after his parents' divorce…") when the reader's parents are still together.
- Wrong number/age of children, wrong spouse / kid / sibling names.
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:
- For every person the right column references with a brain page, add a
back-link from to the new
people/<slug>page (permedia/books/<slug>-personalizedIron Law).conventions/quality.md
页面生成后,对涉及读者的事实性内容(父母、兄弟姐妹、婚姻史、工作、出身)进行核查。常见错误模式包括:
- 将读者父母的关系与大家庭模式混淆。
- 编造治疗背景(“父母离婚后……”)但读者父母仍在一起。
- 子女数量/年龄错误,配偶/子女/兄弟姐妹姓名错误。
若无法验证某一内容,请删除。宁可减少内容质感,也不要引入错误信息。
为分析中提及的实体添加交叉链接:
- 右栏中提及的每个拥有大脑页面的人物,需从页面添加反向链接至新生成的
people/<slug>页面(遵循media/books/<slug>-personalized中的铁则)。conventions/quality.md
Quality bar (the bar)
质量标准
The left column should:
- Preserve the author's actual stories, statistics, frameworks, examples.
- Quote memorable phrases verbatim.
- Be detailed enough that the reader could skip the book and not lose much.
The right column should:
- Use the reader's actual quoted words from the context pack.
- Reference specific dates, situations, people by name.
- Read like a therapist who knows the reader is leaving notes in the margins.
- Be plain about direct hits ("This is exactly the [name a real situation]").
- Be honest about misses ("This chapter is less directly relevant because…"). Don't force connections.
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.
左栏需满足:
- 保留作者的真实故事、数据、框架和示例。
- 逐字引用难忘语句。
- 内容足够详实,读者无需阅读原书也不会遗漏关键信息。
右栏需满足:
- 使用上下文包中读者的真实原话。
- 提及具体日期、事件和人物姓名。
- 阅读体验如同熟悉读者批注的心理咨询师。
- 直接点明匹配点(“这与[具体事件]完全吻合”)。
- 坦诚说明不匹配的情况(“本章相关性较低,因为……”)。不要强行关联。
整个文档需保持连贯统一的语气,贴合读者真实生活而非通用模板,并坦诚说明书籍框架在哪些方面不适用于该读者。
Anti-patterns (do not do these)
反模式(禁止操作)
- ❌ Skimming chapters. Standing instruction: preserve detail.
- ❌ Generic right column. "This might apply if you've ever felt…" → kill on sight.
- ❌ Factual errors about the reader's life. Always fact-check after assembly.
- ❌ Giving the subagent put_page access. Trust contract is read-only; the CLI does the writing.
- ❌ Forcing connections. If a chapter doesn't apply, say so plainly.
- ❌ Sycophancy or moralizing in the right column. No "you should…", no "consider…", no "perhaps it's time to…".
- ❌ Truncating the LEFT column. The book's actual content needs to survive.
- ❌ 略读章节。硬性要求:保留详细内容。
- ❌ 通用化右栏。“如果你曾有过……的感受,这可能适用”——此类内容需立即删除。
- ❌ 关于读者生活的事实错误。组装完成后必须进行事实核查。
- ❌ 赋予子Agent put_page权限。信任协议要求只读;仅CLI可执行写入操作。
- ❌ 强行关联内容。若某章不适用,请直接说明。
- ❌ 右栏中出现奉承或说教内容。禁止使用“你应该……”、“考虑……”、“或许是时候……”等表述。
- ❌ 截断左栏内容。必须保留书籍的真实内容。
Output checklist
输出检查清单
- Book file exists locally (path known).
- Chapter texts under with sane word counts.
$WORK/chapters/*.txt - Context pack at is dense.
$WORK/context.md - returned exit 0.
gbrain book-mirror --chapters-dir … --context-file … --slug … --title … - exists in the brain.
media/books/<slug>-personalized.md - Fact-check pass complete (no errors against USER.md or other source-of-truth pages).
- Cross-links added from referenced people/companies.
- Optional: PDF rendered via brain-pdf and delivered.
- 本地存在书籍文件(已知路径)。
- 下的章节文件字数合理。
$WORK/chapters/*.txt - 中的上下文包内容详实。
$WORK/context.md - 执行成功(返回状态码0)。
gbrain book-mirror --chapters-dir … --context-file … --slug … --title … - 大脑知识库中存在文件。
media/books/<slug>-personalized.md - 完成事实核查(与USER.md或其他可信源无冲突)。
- 已为提及的人物/公司添加交叉链接。
- (可选)通过brain-pdf渲染并交付PDF版本。
Related skills
相关技能
- — render the personalized page to PDF.
skills/brain-pdf/SKILL.md - — read a book through a specific problem-lens instead of personalizing to the whole reader.
skills/strategic-reading/SKILL.md - — same shape applied to articles rather than books.
skills/article-enrichment/SKILL.md
- — 将个性化页面渲染为PDF格式。
skills/brain-pdf/SKILL.md - — 从特定问题视角阅读书籍,而非针对读者整体进行个性化处理。
skills/strategic-reading/SKILL.md - — 针对文章而非书籍的同类功能。
skills/article-enrichment/SKILL.md
Contract
协议
This skill guarantees:
- Routing matches the canonical triggers in the frontmatter.
- Output written under the directories listed in (when applicable).
writes_to: - Conventions referenced (,
quality.md,brain-first.md) are followed._brain-filing-rules.md - Privacy contract preserved: no real names, no fork-specific filesystem path literals, no upstream-fork references.
The full behavior contract is documented in the body sections above; this section exists for the conformance test.
本技能保证:
- 路由匹配前置内容中的标准触发条件。
- 输出写入指定的目录(如适用)。
writes_to: - 遵循引用的约定(、
quality.md、brain-first.md)。_brain-filing-rules.md - 遵守隐私协议:不使用真实姓名、不包含特定文件系统路径、不引用上游分支。
完整行为协议已在正文部分记录;本部分用于一致性测试。
Output Format
输出格式
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技能的输出格式已在正文部分内联说明(详见“输出”、“大脑页面格式”或等效章节)。本标题的存在是为了适配一致性测试()。
test/skills-conformance.test.tsAnti-Patterns
反模式
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.
完整反模式列表已在正文部分记录;本标题的存在是为了适配一致性测试(若正文使用了不同的大小写格式)。