Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
ADR 0171: Host-owned completed-turn token history
- Status: Accepted (amended by ADR 0173)
- Date: 2026-09-07
- Related: D103, D157, D331, D335, ADR 0014, ADR 0173
Context
The turns table already stores input_tokens, output_tokens, and usage_json,
and session.endTurn already accepted usage, but Electron never sent it, while
per-message chips read provider usage from assistant meta_json, where subagent
spend would inflate the context inspector. A durable completed-turn total is still
needed without a new schema version.
Decision
- Parent
message.usagestays provider-reported. Subagent totals never merge into an assistant row. - Turn rollup is
session.endTurn.usage. Electron sums every parent assistantmessage_endusage and addsturn_end.subagentUsagedeltas. stats.getTokenUsageHistoryis an additive host RPC that reads completed turns in a bounded calendar window, buckets byday/ ISOweek/month, and bumps neitherPROTOCOL_VERSIONnorSCHEMA_VERSION.- The dashboard is not Settings. ADR 0173 moves that surface to plugin
pi.token-insights, and rows written before Electron sentusagemay be zero.
Consequences
- Context inspector and chips keep exact provider values.
- New completed turns populate host history; older turns may be zero.
- A backfill from transcript
meta.usagewould be a separate change.
Alternatives
- Rewrite parent
message.usagewith subagent spend — rejected: it corrupts the inspector and composed-turn total.