D104 — Tiered agent roster, code-graph MCP, and compressed reporting (pilot)
Architecture decision record. Status, thematic clusters, and how to record a new ADR: the decision log index. Full problem analysis, design alternatives, and the rollout plan across the other repos under
~/Code/stables/monorepo: the design spec,docs/superpowers/specs/2026-07-31-token-optimization-design.md.
Status: Accepted (pilot — stables-core-app is first; template rollout to the other repos follows a measured trial) · Date: 2026-07-31
Context
Agent sessions in this repo were burning tokens (cost + context-window headroom) in four
identifiable places: subagents had no explicit tiering and inherited the session model even
for mechanical work; the mandatory multi-persona-review protocol ran up to 10 full
session-model reviews per task (2 passes × 5 personas); symbol and dependency questions were
answered by grep sweeps and bulk file reads into agent contexts, with no code-graph tool to
answer them cheaply; and CLAUDE.md's hand-written section (~213 lines) largely duplicated the
agent-workflow skill's operating-model narrative, while subagent reports flowed back as
verbose prose the director quoted forward instead of digesting. Target: ≥50% reduction in
tokens per representative task, weighting cost and context-window pressure about equally.
Decision
Adopt the stables-agent-kit plugin — a new sibling repo
(github.com/stablesxyz/stables-agent-kit, Claude Code plugin-marketplace layout, external to
this repo) — as the shared source of:
- A seven-agent roster with explicitly pinned models:
explorer/junior-devon haiku,senior-dev/qa-engineeron sonnet,staff-engineer/architecton opus, andprincipalinheriting the session model, dispatched only for one of three triggers (an architectural call thearchitectflags as genuinely unresolved, arbitration whenqa-engineerfindings conflict, or an explicit user request). - The generic
agent-dispatchskill (roster, task-type → agent matrix, escalation ladder, four-slot dispatch prompt template) and the newcompressed-reportingskill (the report schemas: explorer report, finding ledger, decision memo).
Within stables-core-app:
agent-workflowrestructured from an abstract director narrative into a concrete dispatch playbook that activates alongside the kit'sagent-dispatchand adds only what is repo-specific: tool routing (Serena for symbols, Graphify for module/impact graphs, Laravel Boost for runtime facts), the gates, docs-sync, and RLS/concurrency cautions.multi-persona-reviewrestructured from 2 passes × 5 session-model personas to tiered QA: Pass 1 fans the diff out to five parallelqa-engineer(sonnet) dispatches, one per persona lens (Sr. Software Architect, Sr. Backend Engineer, Sr. UX Designer/Engineer, Principal Product Manager, Sr. Security Engineer); the director merges the finding ledgers and dispatches fixes to the matching tier; Pass 2 is a singleqa-engineerre-verification dispatch scoped to the fixes and the files they touched, not a second full five-lens sweep.- CLAUDE.md's hand-written section slimmed from ~213 to ~60 lines — skill-activation
pointers, the non-negotiables list, the new dispatch-first + director-digest rules, and
environment basics; the duplicated operating-model prose is gone in favor of a pointer to
agent-workflow. - Two new MCP servers, registered in the committed
.mcp.jsonand wired behind idempotentmaketargets: Serena (LSP/Intelephense — type-accurate symbol definitions/references) and Graphify (tree-sitter graph traversal — file/symbol neighborhoods, dependency paths; module-level impact is approximated by file-level traversal; heuristic, name-matched edges).make setup-agentsbootstraps a new machine in one idempotent pass (installsuvif missing, installs Serena + Graphify, generateslaravel-ide-helperstubs, builds the codemap, verifies each server responds);make agents-doctordiagnoses;make codemaprefreshes the Graphify index;make ide-helperregenerates the Intelephense stubs.
Consequences
- One-file model changes. Pinning a roster agent to a different model is a one-file edit in the kit repo, propagated to every repo that consumes the plugin — no per-repo drift.
- Graphify is orientation only. Its call/dependency edges are heuristic (name-matched); they scope impact and orient exploration, but proof that a symbol is actually referenced still comes from Serena or reading the code.
- Stub staleness is a new failure mode.
make ide-helpermust run after any Composer dependency change, or Serena's Intelephense backing goes facade-blind (unresolved facades/Eloquent magic) until the stubs are regenerated. - The review protocol changed shape, not rigor. Every finding is still fixed / refuted with evidence / deferred only with explicit user sign-off, and gates still re-run after fixes — the change is which dispatches do the reviewing and how many of them run at the session model.
- Docs-sync surfaces moved together with this ADR, per the same-change rule: the
skills-package README table (
packages/stables/skills/README.md) and the wiki pages describing the review protocol and operating model (How a change ships, the engineering index). - Rollout is staged, not simultaneous. stables-core-app pilots the full restructure; 2–3
real tasks are measured before the template (kit plugin reference +
.mcp.json+ Makefile targets + slim-CLAUDE.md skeleton) rolls to the other repos under~/Code/stables/monorepo(stables-core-web,stables-core-infra,stables-core-web-backoffice,stables-insights,stables-ops,stables-web-abilities, then the rest). - Success is measured, not yet certified live. The ≥50% token-reduction target and the
claim that tiered QA surfaces the same-or-more findings at a fraction of the cost are
pending a representative before/after task comparison — tracked against the spec's success
criteria, not asserted here as already proven (
docs/tracking/token-optimization-pilot-measurement.md). - The plugin marketplace tracks the kit repo's
mainbranch directly, not a pinned release/tag;stables-agent-kitis org-private, so this is an accepted risk (ruled 2026-07-31), not an oversight. MCP servers are approved per-developer, interactively, on first use rather than auto-enabled (enableAllProjectMcpServersis deliberately unset). qa-engineer's Bash grant is tool-level unrestricted — agent frontmatter cannot pattern-scope commands, so the "read-only, never edits" guarantee is enforced at the prompt level, not the tool level; the compensating controls are that the director reviews every diff andqa-engineerruns in a sandboxed session.