AOSP Book Polish
Bring the AOSP Internals book into sync with a newer AOSP source tree:
deep-rewrite existing chapters for accuracy, append new-feature content where a
subsystem changed, and — always — find newly-added modules/projects and make
sure the book covers them (fold into an existing chapter first; add a new
chapter/Part only when a threshold is met).
This is a large, multi-/goal-run, agent-team job. It is built to be
resumable and convergent: each chapter is rewritten then reviewed until
two consecutive clean rounds, and durable state lets a fresh run pick up where
the last stopped.
When to use
- The local AOSP checkout (its path supplied to you as a parameter, usually
androidNN-release) was synced to a newer version and the book should reflect it.
- The user asks to update/polish the book, deep-rewrite chapters, or
specifically to cover newly-added modules (the mandatory Phase C below).
- Pairs with the
aosp-version-diff skill: that skill produces the 16→17
style changeset (manifest-snapshots/_compare/<A>-to-<B>/) this skill consumes.
If there is no changeset yet, run aosp-version-diff first (or
tools/manifest_snapshot.py compare) — the changeset drives prioritization and
the new-module gap analysis.
Inputs
- AOSP source — the AOSP checkout root, supplied as a parameter (e.g. in
the task prompt); READ-ONLY. Never write into it, and never hardcode its path.
- Changeset —
manifest-snapshots/_compare/<old>-to-<new>/: report.md
(navigator + per-repo new/dropped counts), changes.txt (per-repo NEW
commits — large, grep per repo, never read whole), added-removed.txt (added
/ removed projects — the seed for Phase C).
- Book conventions —
book/CLAUDE.md (the writing rules; these are
non-negotiable), .claude/skills/book-writer/SKILL.md (chapter structure +
Mermaid syntax), agents/_content/manifest.toml (Part → chapter mapping),
existing chapters as style exemplars.
- The Android-NN appendix (e.g.
D-appendix-android-17-updates.md) — a
curated map of the new version's changes; a per-chapter checklist of what to
fold in, and the candidate universe for the Phase C gap analysis.
The five hard invariants (never violate)
These protect book integrity during autonomous rewrites. Full detail in
references/invariants.md — read it before editing any chapter.
- Chapter title is immutable; the number may be renumbered, but only as a
coordinated whole-book operation. The
# Chapter N: Title title text and
the slug never change. The number N (and the filename's NN- prefix) may
change to insert a new chapter at its logical position — but NEVER as an
ad-hoc single-chapter edit. A renumber is all-or-nothing: rename the files,
update each moved chapter's heading AND every internal section number
(## N.x → ## M.x), and fix every cross-reference book-wide, in one pass
(see references/bookkeeping.md → "Renumbering"). Default to appending new
chapters; renumber only when the user asks for logical ordering.
- Manual section numbering (
## N.1, ### N.1.2) is preserved, monotonic,
no duplicates. Terminal structure stays "Try It" then "Summary" (an
optional key-files table may follow Summary). No epigraph under the title.
- Mermaid follows CLAUDE.md rules and must pass
./serve.sh png <chapter>
with errors=0 — CI does NOT validate Mermaid, so this gate is the only
backstop. Also eyeball each diagram for overflow/overlap and architectural
correctness.
- Real source citations — every architectural claim cites a repo-relative
AOSP path that exists in the new tree. Never put a local absolute or
home-relative path (
/home/..., /Users/..., ~/...) or a username in
chapter text — repo-relative AOSP paths only.
- Per-chapter backup before rewriting — copy to
.superpowers/book-polish/backups/<slug>.bak.md (once; never overwrite) so a
bad rewrite is diffable/restorable.
Workflow
Phase A Prioritize (once) rank chapters by changeset signal -> queue.json
Phase B Per-chapter loop deep-rewrite + agent-team review to convergence
Phase C New modules (MANDATORY) gap analysis -> fold first, new chapter by threshold
Phase D Bookkeeping+gates regenerate skills, build, leak-sweep; user commits
Run Phase B over the queue and Phase C for the leftovers; they share the same
per-chapter convergent loop and the same gates. Checkpoint durable state after
every step so a fresh /goal run resumes.
Phase A — Prioritize (once)
Map each in-scope subsystem to its chapter(s) via manifest.toml, rank chapters
by 16→17-style signal (sum of NEW commits across the chapter's repos + count of
new modules touching it), and write queue.json (highest-priority first). The
most valuable chapters then land first even if a run stops early. Initialize
state.json with every chapter pending. See references/per-chapter-loop.md.
Phase B — Per-chapter convergent polish
For each chapter, in priority waves (≤ the agent cap): back it up, deep-rewrite
the body for accuracy against the new source + append new-feature sections
(before "Try It"), then run an independent agent-team review (accuracy +
Mermaid + structure-lint), fix the material findings, and repeat until two
consecutive clean rounds. One author agent per file (never two agents editing
the same file at once). Full procedure, agent roles, and the gate batch script
in references/per-chapter-loop.md.
Phase C — Newly-added modules/projects (MANDATORY)
This phase is required even when Phase B looks done — new modules are easy to
miss because they have no existing chapter. Always run it. The full
procedure is in references/new-modules.md. In brief:
- Gap analysis (in a subagent) — three candidate sets, see
references/new-modules.md:
- (A) changeset-driven (version bump): the added projects (changeset
added-removed.txt + the new-version appendix's enumerated new modules).
- (B) whole-tree sweep (when asked to "read across the whole source and
find what's left"): enumerate EVERY project from
<aosp-root>/.repo/project.list
and grep each path + last segment across [0-9][0-9]-*.md; keep in-scope
platform roots, drop noise (external/, prebuilts/, vendor/, device/,
test/toolchain). This catches subsystems that predate the diff baseline and
were never written up — (A) by construction cannot.
- (C) release-notes-driven (whenever official notes exist — always run on a
version bump): WebFetch the developer Beta/release blog and the
source.android.com/docs/whatsnew page, extract every called-out feature's
exact API/flag/symbol, and grep each token across the chapter bodies. This is
the ONLY method that finds new framework APIs / behavior changes /
deprecations inside repos that merely moved (e.g. a new camera2 method, an
SDK-37 relaunch-behavior change) — (A) and (B) are project-granular and
structurally blind to them. Verify each is a real AOSP platform change (not a
Play/first-party-app feature) and confirm the exact symbol in source; blog
prose loosely names flags that don't exist verbatim.
Whichever method, produce the uncovered list with, per item: real source path,
what it is (verified from source), substance (LOC / substantial-vs-stub), and
a recommended placement. Beware the grep's false positives (concept covered
under another name; deprecated/sample/empty repos; generic-word matches) —
verify coverage and substance, don't trust the grep.
- Placement policy (threshold):
- A new capability that extends an existing subsystem → fold a new
numbered section into that chapter (preferred — do this first).
- A substantial new top-level subsystem that does not fit any chapter →
a new chapter (appended number, continuing past the last one).
- A cluster of related new repos forming a new domain → a new Part
appended after the last numbered Part, before Appendices.
external/* deps and thin/stub/relocation/prebuilt modules → a brief
integration note in the most relevant chapter (or leave to the
appendix). They never get their own chapter.
- Author the sections/notes (with Mermaid where it clarifies) and run them
through the same convergent review loop as Phase B.
- New chapter/Part → do the new-chapter bookkeeping in Phase D.
Phase D — Bookkeeping & gates
After chapters reach convergence, and after any new chapter/Part. Full checklist
in references/bookkeeping.md. Gates that must be green:
python3 agents/build.py regenerated and agents/build.py --check exits 0
(content changes stale the Part-skills — rule 12).
properdocs build succeeds in the project Docker image (a local
properdocs fails on the !!python tag — that's environmental, not your
error).
- Every touched chapter
./serve.sh png reports errors=0.
- No local-path/username leaks anywhere in the touched files.
- New chapter only:
manifest.toml, properdocs.yml nav, the docs/ symlink,
README.md + agents/README.md counts/tables, and llms.txt updated; a new
Part also needs a hand-authored agents/_content/parts/<id>/SKILL.md before
build.py will run.
Agent-team orchestration (≤10 by default)
Process the queue in waves. Per wave: spawn one author agent per chapter
(distinct files only), then independent reviewer agents (accuracy + Mermaid
- structure), then targeted fixers. Fold the cheap accuracy self-check into
the author (have it verify every cited path against source and run
serve.sh png itself), then run a deterministic batch gate yourself and a
separate adversarial review team. Retry any subagent that hits a transient
API/network/tool error (≤3×) — these happen and a retry almost always works.
Resumable state — .superpowers/book-polish/ (gitignored)
state.json ({phase, sections:{<slug>:{status,round,dry_rounds,priority,part}}, new_parts, done_count, total}), queue.json, new-chapters.json,
backups/<slug>.bak.md, findings/, log.md. On start, if state.json
exists, resume from it; else initialize via Phase A. Steps are idempotent.
Commit policy
Do NOT auto-commit. Keep all changes local on the current branch; do not create
a branch or push. The user reviews and commits. When the user does ask to
commit: stage everything, confirm nothing under .superpowers/ or docs/ is
staged, and use a plain commit (no Co-Authored-By trailer — CLAUDE.md rule).
Gotchas learned the hard way
git checkout -- agents/ reverts your manifest + Part templates.
manifest.toml and agents/_content/parts/*/SKILL.md live under agents/, so
a blanket checkout to clear a subagent's stray build.py regen also wipes your
bookkeeping. Revert only the generated platform trees, or re-apply + regenerate.
- A new Part needs its source template first.
build.py fails with
"Missing SKILL.md for part " until you hand-author
agents/_content/parts/<id>/SKILL.md (copy an existing Part's as a model).
- The dup-section gate must use full tokens. A regex like
^#{2,3} N\.[0-9]+
mis-flags 4-level numbers (N.1.5.1 → "N.1.5"). Match the whole token:
^#{2,4} N\.[0-9]+(\.[0-9]+){0,3} then sort | uniq -d.
properdocs build must run in Docker. Validate with
docker compose run --rm --no-deps --entrypoint sh serve -c "properdocs build".
- Front matter (00) and intro (01) go last — they enumerate the book's
structure, so update them after new chapters/Parts exist. They have no
Try-It/Summary; do not add them.
References
references/new-modules.md — the mandatory Phase C gap-analysis-and-add procedure
references/per-chapter-loop.md — Phase A/B: prioritization, the convergent loop, agent roles, the batch gate
references/invariants.md — the hard invariants + book conventions in full
references/bookkeeping.md — Phase D: regeneration, new-chapter wiring, gates, commit
1---2name: aosp-book-polish3description: Update or polish the AOSP Internals reference book (the chapters at the repo root -- NN-slug.md -- plus the appendices and the generated agents/ Part-skills) so it is accurate and current for a newly-synced or newer AOSP/Android source tree. Use this whenever the user says anything like "polish the book for Android NN", "update the reference book to the new AOSP version", "the AOSP source got re-synced, bring the book up to date", "deep-rewrite the chapters against the new source", or -- importantly -- "cover the new Android modules/projects in the book". It drives a resumable, changeset-prioritized, per-chapter convergent deep-rewrite with an agent-team accuracy + Mermaid review loop, and MANDATORILY runs a gap analysis that finds newly-added modules/projects and folds them into existing chapters (or adds new chapters/Parts only by an explicit threshold). Trigger it even when the user only says "update the book for the new Android" without naming this process, and even when they only want the new-modules par4---56# AOSP Book Polish78Bring the AOSP Internals book into sync with a newer AOSP source tree:9deep-rewrite existing chapters for accuracy, append new-feature content where a10subsystem changed, and — always — **find newly-added modules/projects and make11sure the book covers them** (fold into an existing chapter first; add a new12chapter/Part only when a threshold is met).1314This is a large, multi-`/goal`-run, agent-team job. It is built to be15**resumable** and **convergent**: each chapter is rewritten then reviewed until16two consecutive clean rounds, and durable state lets a fresh run pick up where17the last stopped.1819## When to use2021- The local AOSP checkout (its path supplied to you as a parameter, usually22 `androidNN-release`) was synced to a newer version and the book should reflect it.23- The user asks to update/polish the book, deep-rewrite chapters, or24 specifically to **cover newly-added modules** (the mandatory Phase C below).25- Pairs with the **`aosp-version-diff`** skill: that skill produces the 16→1726 style changeset (`manifest-snapshots/_compare/<A>-to-<B>/`) this skill consumes.2728If there is no changeset yet, run `aosp-version-diff` first (or29`tools/manifest_snapshot.py compare`) — the changeset drives prioritization and30the new-module gap analysis.3132## Inputs3334- **AOSP source** — the AOSP checkout root, **supplied as a parameter** (e.g. in35 the task prompt); READ-ONLY. Never write into it, and never hardcode its path.36- **Changeset** — `manifest-snapshots/_compare/<old>-to-<new>/`: `report.md`37 (navigator + per-repo `new`/`dropped` counts), `changes.txt` (per-repo NEW38 commits — large, grep per repo, never read whole), `added-removed.txt` (added39 / removed projects — the seed for Phase C).40- **Book conventions** — `book/CLAUDE.md` (the writing rules; these are41 non-negotiable), `.claude/skills/book-writer/SKILL.md` (chapter structure +42 Mermaid syntax), `agents/_content/manifest.toml` (Part → chapter mapping),43 existing chapters as style exemplars.44- **The Android-NN appendix** (e.g. `D-appendix-android-17-updates.md`) — a45 curated map of the new version's changes; a per-chapter checklist of what to46 fold in, and the candidate universe for the Phase C gap analysis.4748## The five hard invariants (never violate)4950These protect book integrity during autonomous rewrites. Full detail in51`references/invariants.md` — read it before editing any chapter.52531. **Chapter title is immutable; the number may be renumbered, but only as a54 coordinated whole-book operation.** The `# Chapter N: Title` *title* text and55 the slug never change. The *number* `N` (and the filename's `NN-` prefix) may56 change to insert a new chapter at its logical position — but NEVER as an57 ad-hoc single-chapter edit. A renumber is all-or-nothing: rename the files,58 update each moved chapter's heading AND every internal section number59 (`## N.x` → `## M.x`), and fix every cross-reference book-wide, in one pass60 (see `references/bookkeeping.md` → "Renumbering"). Default to appending new61 chapters; renumber only when the user asks for logical ordering.622. **Manual section numbering** (`## N.1`, `### N.1.2`) is preserved, monotonic,63 **no duplicates**. Terminal structure stays "Try It" then "Summary" (an64 optional key-files table may follow Summary). No epigraph under the title.653. **Mermaid** follows CLAUDE.md rules and must pass `./serve.sh png <chapter>`66 with `errors=0` — CI does NOT validate Mermaid, so this gate is the only67 backstop. Also eyeball each diagram for overflow/overlap and architectural68 correctness.694. **Real source citations** — every architectural claim cites a repo-relative70 AOSP path that exists in the new tree. **Never** put a local absolute or71 home-relative path (`/home/...`, `/Users/...`, `~/...`) or a username in72 chapter text — repo-relative AOSP paths only.735. **Per-chapter backup before rewriting** — copy to74 `.superpowers/book-polish/backups/<slug>.bak.md` (once; never overwrite) so a75 bad rewrite is diffable/restorable.7677## Workflow7879```80Phase A Prioritize (once) rank chapters by changeset signal -> queue.json81Phase B Per-chapter loop deep-rewrite + agent-team review to convergence82Phase C New modules (MANDATORY) gap analysis -> fold first, new chapter by threshold83Phase D Bookkeeping+gates regenerate skills, build, leak-sweep; user commits84```8586Run Phase B over the queue and Phase C for the leftovers; they share the same87per-chapter convergent loop and the same gates. Checkpoint durable state after88every step so a fresh `/goal` run resumes.8990### Phase A — Prioritize (once)9192Map each in-scope subsystem to its chapter(s) via `manifest.toml`, rank chapters93by 16→17-style signal (sum of NEW commits across the chapter's repos + count of94new modules touching it), and write `queue.json` (highest-priority first). The95most valuable chapters then land first even if a run stops early. Initialize96`state.json` with every chapter `pending`. See `references/per-chapter-loop.md`.9798### Phase B — Per-chapter convergent polish99100For each chapter, in priority waves (≤ the agent cap): back it up, deep-rewrite101the body for accuracy against the new source + append new-feature sections102(before "Try It"), then run an **independent** agent-team review (accuracy +103Mermaid + structure-lint), fix the material findings, and repeat until **two104consecutive clean rounds**. One author agent per file (never two agents editing105the same file at once). Full procedure, agent roles, and the gate batch script106in `references/per-chapter-loop.md`.107108### Phase C — Newly-added modules/projects (MANDATORY)109110This phase is required even when Phase B looks done — new modules are easy to111miss because they have no existing chapter. **Always run it.** The full112procedure is in `references/new-modules.md`. In brief:1131141. **Gap analysis (in a subagent)** — three candidate sets, see115 `references/new-modules.md`:116 - **(A) changeset-driven** (version bump): the *added* projects (changeset117 `added-removed.txt` + the new-version appendix's enumerated new modules).118 - **(B) whole-tree sweep** (when asked to "read across the whole source and119 find what's left"): enumerate EVERY project from `<aosp-root>/.repo/project.list`120 and grep each path + last segment across `[0-9][0-9]-*.md`; keep in-scope121 platform roots, drop noise (`external/`, `prebuilts/`, `vendor/`, `device/`,122 test/toolchain). This catches subsystems that predate the diff baseline and123 were never written up — (A) by construction cannot.124 - **(C) release-notes-driven** (whenever official notes exist — always run on a125 version bump): WebFetch the developer Beta/release blog and the126 `source.android.com/docs/whatsnew` page, extract every called-out feature's127 exact API/flag/symbol, and grep each token across the chapter bodies. This is128 the ONLY method that finds new framework *APIs / behavior changes /129 deprecations inside repos that merely moved* (e.g. a new camera2 method, an130 SDK-37 relaunch-behavior change) — (A) and (B) are project-granular and131 structurally blind to them. Verify each is a real AOSP platform change (not a132 Play/first-party-app feature) and confirm the exact symbol in source; blog133 prose loosely names flags that don't exist verbatim.134 Whichever method, produce the *uncovered* list with, per item: real source path,135 what it is (verified from source), substance (LOC / substantial-vs-stub), and136 a recommended placement. Beware the grep's false positives (concept covered137 under another name; deprecated/sample/empty repos; generic-word matches) —138 verify coverage and substance, don't trust the grep.1392. **Placement policy (threshold):**140 - A new capability that **extends an existing subsystem** → fold a new141 numbered section into that chapter (preferred — do this first).142 - A **substantial new top-level subsystem that does not fit any chapter** →143 a new chapter (appended number, continuing past the last one).144 - A **cluster** of related new repos forming a new domain → a new **Part**145 appended after the last numbered Part, before Appendices.146 - `external/*` deps and thin/stub/relocation/prebuilt modules → a brief147 **integration note** in the most relevant chapter (or leave to the148 appendix). They never get their own chapter.1493. Author the sections/notes (with Mermaid where it clarifies) and run them150 through the **same** convergent review loop as Phase B.1514. New chapter/Part → do the new-chapter bookkeeping in Phase D.152153### Phase D — Bookkeeping & gates154155After chapters reach convergence, and after any new chapter/Part. Full checklist156in `references/bookkeeping.md`. Gates that must be green:157158- `python3 agents/build.py` regenerated and `agents/build.py --check` exits 0159 (content changes stale the Part-skills — rule 12).160- `properdocs build` succeeds **in the project Docker image** (a local161 `properdocs` fails on the `!!python` tag — that's environmental, not your162 error).163- Every touched chapter `./serve.sh png` reports `errors=0`.164- No local-path/username leaks anywhere in the touched files.165- New chapter only: `manifest.toml`, `properdocs.yml` nav, the `docs/` symlink,166 `README.md` + `agents/README.md` counts/tables, and `llms.txt` updated; a new167 Part also needs a hand-authored `agents/_content/parts/<id>/SKILL.md` before168 `build.py` will run.169170## Agent-team orchestration (≤10 by default)171172Process the queue in waves. Per wave: spawn one **author** agent per chapter173(distinct files only), then independent **reviewer** agents (accuracy + Mermaid174+ structure), then targeted **fixers**. Fold the cheap accuracy self-check into175the author (have it verify every cited path against source and run176`serve.sh png` itself), then run a deterministic batch gate yourself and a177separate adversarial review team. **Retry any subagent that hits a transient178API/network/tool error** (≤3×) — these happen and a retry almost always works.179180## Resumable state — `.superpowers/book-polish/` (gitignored)181182`state.json` (`{phase, sections:{<slug>:{status,round,dry_rounds,priority,part}},183new_parts, done_count, total}`), `queue.json`, `new-chapters.json`,184`backups/<slug>.bak.md`, `findings/`, `log.md`. On start, if `state.json`185exists, resume from it; else initialize via Phase A. Steps are idempotent.186187## Commit policy188189Do NOT auto-commit. Keep all changes local on the current branch; do not create190a branch or push. The user reviews and commits. When the user does ask to191commit: stage everything, **confirm nothing under `.superpowers/` or `docs/` is192staged**, and use a plain commit (no `Co-Authored-By` trailer — CLAUDE.md rule).193194## Gotchas learned the hard way195196- **`git checkout -- agents/` reverts your manifest + Part templates.**197 `manifest.toml` and `agents/_content/parts/*/SKILL.md` live under `agents/`, so198 a blanket checkout to clear a subagent's stray `build.py` regen also wipes your199 bookkeeping. Revert only the generated platform trees, or re-apply + regenerate.200- **A new Part needs its source template first.** `build.py` fails with201 "Missing SKILL.md for part <id>" until you hand-author202 `agents/_content/parts/<id>/SKILL.md` (copy an existing Part's as a model).203- **The dup-section gate must use full tokens.** A regex like `^#{2,3} N\.[0-9]+`204 mis-flags 4-level numbers (`N.1.5.1` → "N.1.5"). Match the whole token:205 `^#{2,4} N\.[0-9]+(\.[0-9]+){0,3}` then `sort | uniq -d`.206- **`properdocs build` must run in Docker.** Validate with207 `docker compose run --rm --no-deps --entrypoint sh serve -c "properdocs build"`.208- **Front matter (00) and intro (01) go last** — they enumerate the book's209 structure, so update them after new chapters/Parts exist. They have no210 Try-It/Summary; do not add them.211212## References213214- `references/new-modules.md` — the mandatory Phase C gap-analysis-and-add procedure215- `references/per-chapter-loop.md` — Phase A/B: prioritization, the convergent loop, agent roles, the batch gate216- `references/invariants.md` — the hard invariants + book conventions in full217- `references/bookkeeping.md` — Phase D: regeneration, new-chapter wiring, gates, commit