Skip to content

Commit b195f28

Browse files
committed
Token efficiency: audit on cheapest capable model, read targeted excerpts not whole files, batch small/leaf modules, structure-only init for big repos; update stays git-incremental
1 parent 47d9b86 commit b195f28

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

SKILL.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ agent — only the convenience changes, never the rules above.
125125
The non-negotiables (independent per-module audit, deterministic scripts, the four-role
126126
fix gate) hold on every platform; the table only changes *how* you spawn the work.
127127

128+
## Token efficiency
129+
130+
Almost all the cost is the per-module audit sub-tasks reading code — the scripts are
131+
nearly free. Levers, biggest first:
132+
133+
1. **Audit on the cheapest capable model.** The audit is read-code + apply-fixed-rubric +
134+
emit-JSON; a small/fast model does it well, and `apply_audit.py` rejects bad output.
135+
Keep the top model for decomposition, theme synthesis, and fixes only.
136+
2. **Read targeted, not whole.** The audit prompt (STANDARDS.md) greps markers and reads
137+
only the flagged regions; a huge file is scored from its size + a few excerpts, not a
138+
full read. Use `query.py --format paths` so a sub-task opens only its module's files.
139+
3. **Batch the small modules.** Group tiny / low-coupling leaves (≤ ~150 LoC) into one
140+
sub-task that audits each independently (see STANDARDS.md). Core / large / high-coupling
141+
modules stay solo. This cuts the *number* of spawns (each spawn re-pays system-prompt +
142+
rubric overhead). `query.py --max-score 100 --format json` then group by loc/coupling.
143+
4. **`update`, not `init`.** After the first build, only ever run `update` — it re-audits
144+
just the git-changed modules (`needs_audit`), so steady-state cost is tiny.
145+
5. **Structure-first for big repos.** Run `init` in **structure-only** mode (decompose +
146+
`scan --write` + render, *no audits*) to get the map and LoC instantly and cheaply; the
147+
HTML renders unscored modules fine. Then fill scores over time with `update` / on-demand
148+
audits, cheapest-first or worst-suspected-first.
149+
128150
---
129151

130152
## Command: `init` (first build)
@@ -157,12 +179,14 @@ Use when no `modules.json` exists yet. (Also accepts `generate` as an alias.)
157179
yet). Coupling = structural centrality (low/med/high/core); core = the spine hubs.
158180
2. **Compute size:** `python3 scripts/scan.py --root <proj> --state <state> --write`.
159181
It reports every module as `unaudited`.
160-
3. **Audit — one independent subagent per module, in parallel.** For each id in
161-
`needs_audit`, spawn a subagent with the `reference/STANDARDS.md` prompt (filled with
182+
3. **Audit — one independent sub-task per module, in parallel.** For each id in
183+
`needs_audit`, spawn a sub-task with the `reference/STANDARDS.md` prompt (filled with
162184
the module's label/paths). Collect each JSON result and apply it:
163185
`python3 scripts/apply_audit.py --state <state> --id <id> --json '<result>' [--rev <git rev>]`.
164-
Batch the audits (dozens of modules → many parallel agents, but stay within sane
165-
concurrency; chunk if needed).
186+
Run on the cheapest capable model, read targeted excerpts, and batch the small/leaf
187+
modules per *Token efficiency* + STANDARDS.md. **Structure-only mode:** for a huge repo
188+
(or a fast/cheap first pass) you may SKIP this step entirely — render the map with no
189+
scores (it renders unscored modules fine), then fill scores later with `update`.
166190
4. **Synthesize `reportThemes`** (4–7 cross-cutting patterns) from the collected findings
167191
and write them into `modules.json`.
168192
5. **Render:** run the render command. Then **stamp the git baseline** so future updates

reference/STANDARDS.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,27 @@ grep hit as a problem without reading the surrounding code.
9292

9393
## Independent-subagent protocol (REQUIRED)
9494

95-
Every module's score MUST be produced by a separate subagent, never inline in the main
96-
thread, and never reused across modules. One subagent audits one module against the
97-
paths in its state entry. Spawn them in parallel (Explore or general-purpose).
95+
Every module's score MUST be produced by a separate sub-task, never inline in the main
96+
thread, and never reused across modules. The default is one sub-task per module, run in
97+
parallel. **Token-saving exception:** several *small, low-risk* modules (≤ ~150 LoC, or
98+
low-coupling leaves) MAY share one sub-task **only if** it audits each independently and
99+
returns a separate, evidence-backed result per module (this is not batch-scoring — it is
100+
several independent audits sharing one context to amortize overhead). Core / high-coupling
101+
/ large modules always get their own sub-task. The audit is a constrained read-and-grade
102+
task, so run these sub-tasks on the **cheapest capable model**; the strict `apply_audit.py`
103+
validation plus this rubric catch weak output. Reserve the top model for decomposition,
104+
theme synthesis, and fixes.
98105

99106
### Subagent prompt template
100107

101108
> You are auditing CODE QUALITY of ONE functional module for an architecture audit.
102109
> Module: **{label}** (`{id}`). Files: {paths}. Project root: {root}.
103110
>
104-
> Read the module's code (grep the markers below, then READ the surrounding code —
105-
> never flag a grep hit you haven't read). Judge it against this rubric:
111+
> Read EFFICIENTLY — do not read whole large files. First grep the smell markers below
112+
> across {paths}; skim each file's structure (sizes, top-level defs); then READ ONLY the
113+
> flagged regions plus enough context to judge them (never flag a grep hit you haven't
114+
> read). For a big file, the line count + a few representative excerpts are usually enough
115+
> to score bloat/god-component. Judge it against this rubric:
106116
> {paste the "Scoring rubric", "Smell taxonomy", "Severity" sections above}
107117
>
108118
> Hunt specifically for: monkeypatch / stdlib mutation, fallback chains & silent

0 commit comments

Comments
 (0)