fix(optimize): scope the apply-able subtotal to the local MCP subset

A mixed local + claude.ai connector finding is class `fix`, but `--apply`
only mutates the local servers. classTotals now credits the `fix` group
with `applyTokensSaved` when present, so the "Fix now (apply-able)"
subtotal, the "apply-able: ~$X" headline and `summary.byClass.fix` (CLI,
TUI and desktop all read these) describe what apply can actually recover.
The finding keeps the whole opportunity in its own `tokensSaved`.

Also fixes the desktop connector fixture, which predated the class/basis
fields, and adds class-level coverage: connector-only findings resolve to
`nudge` (no apply payload), a local server named like a connector stays
manual-only, and local-only findings keep their full subtotal.
This commit is contained in:
iamtoruk 2026-08-18 08:22:33 -07:00
parent c5df60e69a
commit 117aa833cc
3 changed files with 71 additions and 3 deletions

View file

@ -403,9 +403,17 @@ export function classTotals(findings: WasteFinding[], costRate: number): Record<
keep: { tokensSaved: 0, savingsUSD: 0, count: 0 },
}
for (const f of findings) {
const t = totals[findingClass(f)]
t.tokensSaved += f.tokensSaved
t.savingsUSD += f.tokensSaved * costRate
const cls = findingClass(f)
// A `fix` whose plan owns only part of its estimate (a mixed local +
// claude.ai connector MCP finding) contributes only the apply-able
// subset, so this subtotal and the "apply-able" headline never promise
// what `--apply` cannot recover. The finding keeps the whole
// opportunity in its own `tokensSaved`, so the fix subtotal can be
// smaller than the findings listed under it.
const tokens = cls === 'fix' ? f.applyTokensSaved ?? f.tokensSaved : f.tokensSaved
const t = totals[cls]
t.tokensSaved += tokens
t.savingsUSD += tokens * costRate
t.count++
}
return totals