book-mirror

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

book-mirror — Personalized Chapter-by-Chapter Book Analysis

book-mirror — 个性化书籍逐章分析

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.
约定: 请查看 _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.md
.
This 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 (
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:
  • The CLI submits N read-only subagent jobs (one per chapter). Each subagent has
    allowed_tools: ['get_page', 'search']
    only. They CANNOT call put_page or any mutating op. They produce markdown analysis via their final message.
  • The CLI reads each child's
    job.result
    , assembles the final two-column page, and writes it via a single operator-trust
    put_page
    .
  • This means untrusted EPUB/PDF content cannot prompt-inject any
    people/*
    page. The trust narrowing happens at the tool allowlist, not at the slug-prefix layer.
book-mirror以CLI命令形式运行(
gbrain book-mirror
),而非由Agent通过工具调度的纯Markdown技能。CLI是可信运行环境;本技能仅负责编排流程说明。
这对Agent意味着:
  • CLI会提交N个只读子Agent任务(每章一个)。每个子Agent仅拥有
    allowed_tools: ['get_page', 'search']
    权限,无法调用put_page或任何修改操作。它们通过最终消息生成Markdown分析内容。
  • 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
undefined
book-acquisition(涉及法律灰色地带的下载工具)未包含在本次技能发布中。用户需手动导入EPUB/PDF文件。用户常用的文件路径示例:
bash
undefined

User-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
.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.
目标:在临时目录下为每章生成一个
.txt
文件。Agent拥有shell和python权限;CLI会接收提取后的目录作为输入。

EPUB

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

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
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.
bash
pdftotext -layout path/to/book.pdf "$WORK/full.txt"
随后通过
awk
或python按章节标题(查找“Chapter N”、“CHAPTER N”或全大写标题行)拆分文本。若PDF是无嵌入文本的扫描件,则需通过
skills/brain-pdf
或其他视觉工具进行OCR识别。

Quality check

质量检查

For each chapter file:
  • Word count > 1500 (typical chapter range 2k–8k words).
  • No HTML tags.
  • Paragraphs preserved with
    \n\n
    .
Save a
chapters/INDEX.md
mapping chapter number → title → file → word count for reference.
对每个章节文件进行如下检查:
  • 字数>1500(典型章节字数范围2k–8k)。
  • 无HTML标签。
  • 段落用
    \n\n
    分隔保留格式。
保存
chapters/INDEX.md
文件,映射章节编号→标题→文件→字数,以供参考。

3. 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

需要提取的内容

  1. Templates: USER.md and SOUL.md if the user maintains them (gbrain ships templates at
    templates/USER.md
    and
    templates/SOUL.md
    ; they live in the brain repo when populated). Read full.
  2. Recent daily memory — last 14 days of brain pages under
    wiki/personal/reflections/
    or wherever the user files daily notes.
  3. Topic-relevant brain searches tuned to the book's themes:
    • 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.
  4. Brain pages for relevant entities
    gbrain query "<name>"
    for people who will likely come up.
  5. Standing patterns — anything in the user's reflections or originals that's been recurring.
  1. 模板文件:USER.md和SOUL.md(如果用户已维护) (gbrain在
    templates/USER.md
    templates/SOUL.md
    提供模板;用户填充后存储在大脑仓库中)。需完整读取。
  2. 近期日常记忆 — 大脑知识库中
    wiki/personal/reflections/
    或用户存储日常笔记的其他路径下最近14天的页面。
  3. 与书籍主题相关的大脑知识库搜索
    • 若为婚姻类书籍,执行
      gbrain query "marriage"
      gbrain query "couples therapy"
    • 若为商业类书籍,执行
      gbrain query "founders"
      gbrain query "fundraising"
    • 若为心理学类书籍,执行
      gbrain query "shame"
      gbrain query "anger"
  4. 相关实体的大脑页面 — 对可能出现的人物执行
    gbrain query "<name>"
  5. 持续出现的模式 — 用户反思或原创内容中反复出现的任何内容。

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

4. 分析处理:调用
gbrain book-mirror

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-7
The 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
    job.result
    (the markdown analysis text).
  • Assembles all chapters into one page with frontmatter + intro + per-chapter sections + closing.
  • Writes ONE
    put_page
    to
    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 (
book-mirror:<slug>:ch-<N>
) deduplicate completed chapters at the queue level, so retry is cheap.
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-7
CLI执行以下操作:
  • 验证输入并加载章节文件。
  • 打印成本估算(使用Opus模型约每章0.30美元)并提示确认。
  • 提交N个拥有只读
    allowed_tools
    权限的子Agent任务。
  • 等待所有子任务完成。
  • 读取每个子任务的
    job.result
    (Markdown分析文本)。
  • 将所有章节内容组装成包含前置内容+引言+逐章小节+结语的单个页面。
  • 执行一次
    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
claude-opus-4-7
. Sonnet works (use
--model claude-sonnet-4-6
) 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
。Sonnet模型也可使用(添加参数
--model claude-sonnet-4-6
),但右栏质量会明显下降——要让分析内容达到“熟悉读者的心理咨询师”级别的质感,需要Opus级别的推理能力。

Cost gate

成本限制

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.
在非TTY环境下,CLI会拒绝执行,除非添加
--yes
参数。CI/脚本调用必须显式传入
--yes
。TTY用户会在提交前看到
[y/N]
确认提示。

5. PDF (optional)

5. 生成PDF(可选)

After the brain page is written, render to PDF using
skills/brain-pdf
:
bash
gbrain put_page  # already done by the CLI; nothing to add here
大脑页面写入完成后,使用
skills/brain-pdf
渲染为PDF:
bash
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调用方式)

undefined
undefined

6. 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
    people/<slug>
    to the new
    media/books/<slug>-personalized
    page (per
    conventions/quality.md
    Iron Law).
页面生成后,对涉及读者的事实性内容(父母、兄弟姐妹、婚姻史、工作、出身)进行核查。常见错误模式包括:
  • 将读者父母的关系与大家庭模式混淆。
  • 编造治疗背景(“父母离婚后……”)但读者父母仍在一起。
  • 子女数量/年龄错误,配偶/子女/兄弟姐妹姓名错误。
若无法验证某一内容,请删除。宁可减少内容质感,也不要引入错误信息。
为分析中提及的实体添加交叉链接:
  • 右栏中提及的每个拥有大脑页面的人物,需从
    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
    $WORK/chapters/*.txt
    with sane word counts.
  • Context pack at
    $WORK/context.md
    is dense.
  • gbrain book-mirror --chapters-dir … --context-file … --slug … --title …
    returned exit 0.
  • media/books/<slug>-personalized.md
    exists in the brain.
  • 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
    中的上下文包内容详实。
  • gbrain book-mirror --chapters-dir … --context-file … --slug … --title …
    执行成功(返回状态码0)。
  • 大脑知识库中存在
    media/books/<slug>-personalized.md
    文件。
  • 完成事实核查(与USER.md或其他可信源无冲突)。
  • 已为提及的人物/公司添加交叉链接。
  • (可选)通过brain-pdf渲染并交付PDF版本。

Related skills

相关技能

  • 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/brain-pdf/SKILL.md
    — 将个性化页面渲染为PDF格式。
  • 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
    writes_to:
    (when applicable).
  • Conventions referenced (
    quality.md
    ,
    brain-first.md
    ,
    _brain-filing-rules.md
    ) are followed.
  • 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.ts
)。

Anti-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.
完整反模式列表已在正文部分记录;本标题的存在是为了适配一致性测试(若正文使用了不同的大小写格式)。