128 lines
14 KiB
Markdown
128 lines
14 KiB
Markdown
---
|
||
name: android-project-full-audit
|
||
description: Audit-level architecture report for an existing Android project, built by reading the source files themselves (not README/docs, which may be stale). Use when the user wants to understand, audit, map, or document how an Android app is architected — its file/module organization, the libraries and mechanisms behind each implementation category (UI, navigation, networking, concurrency, persistence, DI, background work, etc.) with code pointers, how modules interact and pass data to each other (grouped into user-facing and background interactions), and the user-facing features. Crawls files one by one (optionally fanned out to subagents), records findings into a library of per-category audit docs, then synthesizes a REPORT.md with an implementation table, a module interaction map and a features table.
|
||
---
|
||
|
||
# Android Project Full Audit
|
||
|
||
Goal: a report of how the app is built **as implemented today**. Every claim traces to a source file the auditor actually read. Documentation (README, `docs/`, wiki, ADRs, comments describing intent) is **not evidence** — it is excluded from the crawl and must not be used to fill gaps. Where code is unclear, say so; don't backfill from docs.
|
||
|
||
The audit runs in phases. All state lives in an **audit workspace** so the work can be resumed and split across subagents:
|
||
|
||
```
|
||
<AUDIT_DIR>/
|
||
ledger.tsv every in-scope file + status (pending/contributed/redundant/trivial/skipped)
|
||
library/<cat>.md one audit doc per implementation category — the findings library
|
||
occurrences.tsv further files that repeat an already-documented pattern (prevalence)
|
||
batches/ file lists for subagents
|
||
modules.txt, resource-counts.tsv
|
||
timeline.tsv phase start timestamps (duration tracking)
|
||
usage.md/.json token usage + duration, written by `finish`
|
||
REPORT.md final synthesized report
|
||
```
|
||
|
||
**Timing and tokens:** `init` starts the clock. Run `bash $A phase $AUDIT_DIR <name>` as the first command of each later phase (`orientation`, `per-file`, `gate`, `cross-cutting`, `report`). `bash $A finish $AUDIT_DIR` stops the clock and writes `usage.md`. Usage is read from the harness's own logs: Claude Code transcripts (main session, subagents and headless local workers) or OpenCode's session DB. Calls are counted only inside the audit window, and only from sessions whose transcript mentions `AUDIT_DIR`. Nothing to track by hand.
|
||
|
||
## Harness notes (Claude Code and OpenCode)
|
||
|
||
This skill is shared by Claude Code and OpenCode, which both load it from `~/.claude/skills/`.
|
||
- **`SKILL_DIR`** is the directory containing this SKILL.md. Claude Code provides it; elsewhere use the skill's reported location, normally `~/.claude/skills/android-project-full-audit`.
|
||
- **Tool names:** "file-read tool" means `Read` in Claude Code and `read` in OpenCode. "Subagent" means the `Agent` tool with `general-purpose` in Claude Code, and the `task` tool with the `general` agent in OpenCode.
|
||
- **Local model:** if you yourself are running on a locally hosted model (e.g. OpenCode pointed at vLLM or Ollama), your subagents already run locally. Never use `local-worker-handoff` from there; it exists only to move work off Anthropic models in Claude Code.
|
||
|
||
Helper: `A="$SKILL_DIR/scripts/audit.sh"` (run `bash $A` with no args for usage). It is the only way findings and statuses are written — it validates categories, keeps one entry per pattern slug, and locks for concurrent subagents.
|
||
|
||
## Phase 0 — Set up
|
||
|
||
1. Confirm the project root (the dir with `settings.gradle(.kts)`). If the user didn't give one, use the cwd if it qualifies; otherwise ask.
|
||
2. `AUDIT_DIR` defaults to `<project>/.android-audit/`. Tell the user it was created there and suggest adding it to `.gitignore` (don't edit `.gitignore` yourself unless asked). Use another location if the user names one.
|
||
3. If `AUDIT_DIR/ledger.tsv` already exists with progress, **resume**: skip to the phase `bash $A coverage $AUDIT_DIR` indicates. `init` refuses to overwrite progress.
|
||
4. Record the git SHA if the project is a repo (`git -C <project> rev-parse --short HEAD`) for the report header.
|
||
|
||
## Phase 1 — Inventory
|
||
|
||
```bash
|
||
bash $A init <project> <AUDIT_DIR> # builds ledger + empty library docs; prints counts by module/kind
|
||
bash $A tree <AUDIT_DIR> # module → source set → package tree with file counts
|
||
bash $A signals <AUDIT_DIR> # import/plugin hits per library
|
||
```
|
||
|
||
- The inventory includes `.kt .kts .java .gradle .toml gradle.properties gradle-wrapper.properties .pro .aidl .proto .sq`, manifests, `res/values|layout|navigation|xml`, and CI config. It excludes build outputs, generated code, drawables/mipmaps/fonts/raw (counted only), translated `values-*`, and all documentation (listed in `docs.txt` for the optional drift step only).
|
||
- `secret-files.txt` lists `local.properties`, keystores, `google-services.json`, `.env` etc. **Never open them.** Record their existence and role from what the build scripts read (e.g. "`TMDB_API_KEY` read from `local.properties`") under `security-auth`.
|
||
- `signals` output is a **map of where to look, not evidence**. A library on the classpath may be unused; an import may be dead. Nothing goes into the library from `signals` alone.
|
||
- If the ledger has obvious noise (e.g. a vendored SDK, sample app, or a huge generated dir the filters missed), mark those `skipped` with a reason and tell the user what was excluded.
|
||
|
||
## Phase 2 — Orientation pass (main model, always)
|
||
|
||
`bash $A phase $AUDIT_DIR orientation`
|
||
|
||
Read these yourself first, in full, recording findings and marking each file. They establish the vocabulary every later reader needs:
|
||
|
||
1. `settings.gradle(.kts)`, `gradle/libs.versions.toml`, root `build.gradle(.kts)`, `gradle.properties`, convention plugins (`build-logic/`, `buildSrc/`).
|
||
2. Each module's `build.gradle(.kts)` — note plugins and `project(":…")` dependencies → module graph.
|
||
3. Every `AndroidManifest.xml` — components, permissions, deep links, `Application` class.
|
||
4. The `Application` class, the launcher Activity, the DI root (Hilt modules / Koin `startKoin` / Dagger component), and the top-level nav host / nav graph.
|
||
|
||
Then write a 10–20 line **orientation summary** (modules and what each is for, core libraries + versions, architectural style as seen so far, slug names already used). Keep it in your context; it is passed to every subagent.
|
||
|
||
## Phase 3 — Per-file audit
|
||
|
||
`bash $A phase $AUDIT_DIR per-file`
|
||
|
||
Every remaining `pending` file is read **one by one, in full**, and filed into the right library doc. The exact procedure — read, pick category, new pattern vs. refinement vs. repetition, features, mark status — is in **`references/file-auditor-prompt.md`**. Read it before starting this phase; it applies to you as much as to subagents.
|
||
|
||
Reading: use one file-read call per file (several independent reads in one message is fine). Don't `cat` whole packages through Bash — it blurs the per-file judgement and large UI packages overflow tool output.
|
||
|
||
Key rule on redundancy: a file does not need to contribute. When a file is "more of the same" (the 12th Room DAO, the 30th screen ViewModel with the identical shape) log it with `also` and mark it `redundant`. Only write prose when the file shows something not already in the library. Before writing, check `bash $A patterns $AUDIT_DIR <category>`.
|
||
|
||
**Choose an execution mode** from the pending count (`bash $A coverage $AUDIT_DIR`):
|
||
|
||
- **≤ 150 pending files → main model alone.** Loop: `bash $A next $AUDIT_DIR 10`, read and file each, repeat until `coverage` exits 0.
|
||
- **> 150, or the user asked to offload to a local model → batched workers.** `bash $A batch $AUDIT_DIR 40` (batches stay within one module where possible). Fill the prompt in `references/file-auditor-prompt.md` per batch (`{PROJECT_ROOT}`, `{AUDIT_DIR}`, `{SKILL_DIR}`, `{BATCH_FILE}`, `{ORIENTATION_SUMMARY}`). Then pick the worker backend:
|
||
1. **Local worker (Claude Code only, preferred when available).** If you are in Claude Code on an Anthropic model and the `local-worker-handoff` skill is installed, load it and run its `check`. On success, write each filled prompt to a file and dispatch it through that skill's `run`, with `--cwd <project>` and `--allow "Read Grep Glob Bash(bash $A:*)"`, respecting the backend's `max_parallel`. Use batches of ~20 files for local workers. This skill never names a server, model or key; those belong to the handoff skill's config.
|
||
2. **Native subagents.** This is the default in OpenCode and the fallback in Claude Code when the handoff skill is absent or `check` fails (say so in one line). Spawn one subagent per batch (see Harness notes for the tool), several in a single message: **up to 6 at a time** on hosted models, **2–3 at a time** on a local model so they don't queue on one GPU. Local-model subagents get batches of ~20 files and the heavier spot-check in Phase 4.
|
||
|
||
When a wave finishes, run `patterns` and pass any notable new slugs into the next wave's orientation summary so later workers reuse them instead of inventing synonyms. Tell the user the batch count and backend before launching, and give a one-line update per wave.
|
||
- If the user asked for a quick/cheaper run, say what you'll reduce (e.g. read all Kotlin/Java but only sample res files) and mark the unsampled files `skipped` with note `sampled-out` — never silently drop coverage.
|
||
|
||
## Phase 4 — Coverage gate
|
||
|
||
`bash $A phase $AUDIT_DIR gate`
|
||
|
||
1. `bash $A gate $AUDIT_DIR` must print `GATE: PASS`: no `pending` files, every `contributed` file is cited by a finding, every `redundant` file has a logged occurrence. Fix or re-audit whatever it lists. (`coverage` is the non-failing progress view.)
|
||
2. **Spot-check delegated work** (skip in main-model mode). Per batch, pick ~3 files marked `redundant`/`trivial` and ~2 `contributed` exemplars, open them, and confirm the status and the finding are right. Check local-worker batches more heavily (~5 + 3). If a batch looks skimmed (everything `trivial`, findings that don't match the file, invented line numbers), redo it with a built-in subagent or yourself and tell the user which batches were redone.
|
||
3. Check for slug synonyms across workers (`patterns` output: e.g. `retrofit-api-service` vs `retrofit-service-interface`). Treat them as one pattern in the report.
|
||
|
||
## Phase 4.5 — Cross-cutting entries (main model)
|
||
|
||
`bash $A phase $AUDIT_DIR cross-cutting`
|
||
|
||
The per-file loop doesn't naturally produce these, so write them now:
|
||
- `file-organization`: the packaging scheme, naming conventions and outliers, from `audit.sh tree` plus what you read. Use source `(project)`.
|
||
- Empty categories: `bash $A none $AUDIT_DIR <category> "<what you looked for>"`, so the report can say "None found in code" with evidence of looking.
|
||
- `module-interactions`: close the gaps the per-file pass leaves. For every `project(":…")` edge in the module graph (Phase 2), check that at least one interaction entry explains what that dependency is used for; read the files needed to fill any missing edge. Confirm or correct "Inferred:" callee sides with a refinement. In a single-module app, do the same across top-level feature/layer packages. If the app really is one undivided unit, record `none` saying so.
|
||
- `observations`: inconsistencies across files, such as two mechanisms for one job or migrations in progress, that no single file reveals.
|
||
- Superseded claims: the library is append-only. If an early finding was wrong or an "Inferred:" note was later confirmed, add a refinement to that slug saying so. The report uses the latest refinement.
|
||
|
||
## Phase 5 — Consolidate and report
|
||
|
||
`bash $A phase $AUDIT_DIR report`
|
||
|
||
1. Read **every** `library/*.md` in full and `occurrences.tsv` (prevalence per slug: `awk -F'\t' 'NR>1{print $1"/"$2}' occurrences.tsv | sort | uniq -c | sort -rn`).
|
||
2. Resolve conflicts: where two mechanisms coexist (Gson + kotlinx.serialization, LiveData + StateFlow), report both with counts — that is a finding, not noise. Note which is newer/dominant only if the code shows it.
|
||
3. Pick **code pointers** per category: the 1–3 files that most clearly show the pattern (usually the exemplar, but prefer a clean canonical file over a first-seen edge case). Verify each path exists.
|
||
4. Run `bash $A finish $AUDIT_DIR` immediately before writing the report. It stops the clock and writes `usage.md`, whose tables go verbatim into the report's "Usage & duration" section. Tokens spent writing the report itself fall after the clock stops; the report's section says so.
|
||
5. Write `AUDIT_DIR/REPORT.md` following **`references/report-template.md`**: at-a-glance, build & toolchain, **file tree organization scheme**, **implementation summary table (Category | Implementation details | Code pointers)**, **features table (Feature | What it lets the user do | Entry point)**, architecture & data flow with one end-to-end trace, **module interactions** (user-facing and background tables of From → To | Mechanism | Data passed | Trigger, plus a diagram), observations (inconsistencies, risks, strengths), coverage & method.
|
||
6. Print the summary to the terminal as the template's last paragraph describes, and give the full path to `REPORT.md` and the library dir.
|
||
|
||
If this skill is itself running inside a subagent and the harness refuses the `REPORT.md` write, don't work around it. Return the full report text as your final reply, with the intended path, so the parent session saves it.
|
||
|
||
Optional, only after the report is complete and only if documentation exists: add a **"Documentation drift"** section listing doc claims the code contradicts (e.g. README says Dagger, code uses Hilt). This is the only point where docs are opened, and they are compared against the report — never used to write it.
|
||
|
||
## Guardrails
|
||
|
||
- Read files; don't infer content from names, grep hits, or `signals`.
|
||
- Cite paths (and `:line` for key facts). Mark inferences as "Inferred:".
|
||
- Versions from version catalog/build files only.
|
||
- Never open files in `secret-files.txt`, and never copy secret values into the library or report; note location and type only.
|
||
- Don't modify the audited project. The only writes are inside `AUDIT_DIR`.
|