π The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
id: ADR-0003 title: ruflo-cost-tracker β implementation arc from v0.4.0 to v0.15.0 (auto-capture, budget enforcement, model-outcome feedback, observability, federation consumer) status: Accepted date: 2026-05-05 authors: - planner (Claude Code) tags: [plugin, cost, telemetry, budget, federation, observability, ci, summary, model-outcome, retrospective]
Context
ADR-0001 fixed namespace routing (v0.2.2). ADR-0002 added the Agent Booster integration with verification (v0.3.0βv0.4.0). At that point the plugin had a credible verification harness β but it was almost entirely a consumer of the cost-tracking AgentDB namespace. Nothing in the plugin actually wrote to that namespace. Every skill operated on empty data.
This ADR documents the implementation arc that closed that gap (v0.4.0 β v0.15.0) and the deliberate scope decisions made along the way.
Decision
Eleven priorities were implemented as separate plugin-local commits, each with version bump + smoke contract growth. Headline numbers from a fresh measured bench (2026-05-05, corpus v3 = 25 cases):
| Endpoint | Tier 1 win | Adversarial correct | Avg latency | Cost / edit | Speedup vs Booster |
|---|---|---|---|---|---|
| Agent Booster (WASM) | 18/18 | escalates 7/7 | 0.36 ms | $0 | β |
| Gemini 2.0 Flash | 18/18 | 3/7 | 807.56 ms | $0.000028 | 2243Γ |
| Claude Sonnet 4.6 | 18/18 | 2/7 | 1270.64 ms | $0.000933 | 3530Γ |
| Claude Opus 4.7 | 18/18 | 5/7 | 1563.72 ms | $0.005943 | 4344Γ |
Implementation order and rationale
- P1 β
cost-track(v0.5.0) β the most embarrassing gap. Reads~/.claude/projects/<encoded-cwd>/<session>.jsonl, sums per-messageusageby model, persists tocost-trackingnamespace. Without this every other skill operated on empty data. - P2 β
cost-budget-check(v0.6.0) β the README documented a 50/75/90/100% alert ladder but no code enforced it. Wired the producer (cost track) to the consumer (budget check) with a real fail-closed exit-1 path onHARD_STOP. - P3 β auto-emit
hooks_model-outcome(v0.7.0) βcost-optimizestep 8 was prose. Replaced with a wrapper script (outcome.mjs) and acost outcomesubcommand so applied recommendations actually train the router. - P4 β
compact.mjs(v0.8.0) β dropped the inlinenode --input-type=module -e '...'block fromcost-compact-context. True MCP wrapping (modifying @claude-flow/cli source) deliberately deferred β see "Riskiest assumption" below. - P5 β
cost-trend(v0.9.0) β the binary smoke gate misses curves. Trend across allruns/*.jsonflags drifts the gate doesn't. - P7 β corpus v2 β v3 (v0.10.0) β added
expectedTier1field and 7 adversarial cases. Win rate now means something (was tautological at 100% across all endpoints on v1). - P8 β GitHub Actions (v0.11.0) β smoke + booster-only bench on every PR; LLM/Anthropic baselines deliberately excluded from CI (cost guard).
- P11 β
cost-conversation(v0.12.0) β per-conversation lens (different aggregation axis fromcost-report's per-agent / per-model). - P10 β
cost-export(v0.13.0) β Prometheus textfile collector + webhook POST. External observability. - P6 β
cost-federation(v0.14.0) β ADR-097 Phase 3 consumer wired. Activates when upstream emits. - P9 β
cost-summary(v0.15.0) β stable programmatic JSON contract for inter-plugin consumption.
Consequences
Positive:
- The plugin now has a real producer (
cost-trackwriting tocost-tracking) and four lenses on the same data (report, optimize, conversation, summary). Before this work, every skill consumed an empty namespace. - Budget enforcement is mechanical β
budget check && spawn β¦fail-closed pattern guards expensive operations. - The verification corpus (25 cases, including 7 adversarial) produces honest signal: on adversarial cases the booster correctly refuses (escalates) while Sonnet 4.6 only solves 2/7. Booster's qualitative win β correct refuse β is not just speed.
- External observability is wired: Prometheus for dashboards, webhooks for ad-hoc reporting, programmatic summary for cross-plugin consumption.
- Federation consumer is ready ahead of upstream Phase 3 emission, so when the producer side lands the plugin starts aggregating immediately with no further changes.
Negative:
- No real MCP tools registered β adding
cost_report/cost_summaryMCP tools requires modifyingv3/@claude-flow/cli/src/mcp-tools/, which is outside plugin-local scope and deserves its own ADR. The currentsummary.mjsprovides equivalent functionality via Bash shell-out, but it is not an MCP tool. - Budget upsert workaround β
npx @claude-flow/cli memory storerejects keys thatmemory retrievedoesn't see (a UNIQUE-constraint inconsistency in the @claude-flow/cli memory layer).budget.mjsworks around this by writing timestamped keys (budget-config-<ms>) and resolving the latest at retrieve time. This is functional but indicates an upstream bug that should be fixed in a separate ADR. - Federation consumer activates only when Phase 3 lands β the skill is dormant until
federation_sendcompletion events flow into thefederation-spendnamespace. Documented; not a hard issue but means the metric is currently zero. - CI bench is booster-only β LLM and Anthropic baselines are deliberately not run in CI (cost). Drift in those numbers can only be caught manually via
BENCH_LLM_BASELINE=1 BENCH_ANTHROPIC=1.
Neutral:
- Plugin is at v0.15.0 within the 0.x line β additive surface change is the norm.
- Smoke contract grew from 27 β 44 checks. All under 100 ms wall-time.
- 13 skills now load in agent context. Each has tight
allowed-tools(no wildcards). Smoke step 10 enforces this.
Riskiest assumptions
- The plugin works without
agent-boosterinstalled when the bench isn't being run. All other skills (track, budget, outcome, trend, conversation, export, federation, summary) avoid the booster import entirely. Verified live:cost-track,cost-budget-check,cost-summaryall run cleanly outside the v3/ tree. - Sonnet 4.6 / Opus 4.7 latency is representative. The Anthropic baseline measured 1270 / 1563 ms avg latency. These are real GCP-region-affected numbers and will fluctuate. The trend script flags drift.
- The 25-case corpus reflects production work patterns. It probably under-represents larger-context refactors. If real workloads differ materially, the win rate / escalation rate could change. Mitigation: extend corpus, re-run bench, smoke step 23 fails CI on regression.
Verification
Smoke contract is at 44 checks (bash plugins/ruflo-cost-tracker/scripts/smoke.sh). Live verified:
cost-trackcaptured this session: 1597 messages, $1546.36 on Opus 4.7cost-budgetset / get / check: $2500 budget, 61.9% utilization β π‘ INFOoutcome.mjs: emittedhaiku=successto router,[OK] Outcome recordedcost-trend: 6+ runs analyzed, 100% win rate stable, latency drifted 0.58β0.36 mscost-export --prometheus: textfile cleanly written with all 6 metric typescost-federation: with mock events, peer-bob $7.50 β β flagged over $5/24h thresholdcost-summary --format json: stable contract verified
Bench result persisted at docs/benchmarks/runs/latest.json (corpus v3, 4 endpoints).
Related
- ADR-0001 β namespace routing fix
- ADR-0002 β Agent Booster integration + verification
- ADR-097 β federation budget circuit breaker (Phase 3 consumer wired)
- Issue #1743 β public verification thread
- Gist
15fae7a5495026f025fb3baf721c20eaβ bench proof + corpus + harness - Cron
c0b44f45β driver of this implementation arc; cancelled at end of session
Deferred for follow-up ADRs
- Real MCP tool registration (
cost_report/cost_summaryas registered MCP tools, not Bash shell-out) - Upstream fix for the
memory storeUNIQUE-constraint inconsistency - Federation Phase 3 producer (in
ruflo-federationplugin, not this one) - Adversarial corpus expansion to 50+ cases for tighter signal