diff --git a/src/web/client.ts b/src/web/client.ts index 1dbee04fa6..1d0d934430 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -850,7 +850,7 @@ export const WEB_CLIENT = `(function () { // the same bucket membership the economics card aggregates. The gap // heuristic remains only as the legacy fallback for old ledgers whose // lines carry no attribution fields. - const CAUSE_COLOR = { cold: "#6e7681", comp: "#bf8700", seam: "#cf222e", pt: "#1a7f37", ps: "#f0883e", rw: "#57606a", rest: "#8250df" }; + const CAUSE_COLOR = { cold: "#6e7681", comp: "#bf8700", seam: "#cf222e", pt: "#1a7f37", ps: "#f0883e", rw: "#57606a", rest: "#9aa1a8" }; const CAUSE_KEY = { cold: "det.cause_cold", comp: "det.cause_comp", seam: "det.legend_seam", pt: "det.leg_pttl", ps: "det.leg_pside", rw: "det.leg_rewind", rest: "det.cause_ttl" }; let foldTailClaims = 0; const causes = lines.map((l, i) => { @@ -1269,14 +1269,14 @@ export const WEB_CLIENT = `(function () { if (seam.providerTtl.count > 0) sub.push(legendItem("background:#1a7f37", t("det.leg_pttl"))); if (seam.providerSide.count > 0) sub.push(legendItem("background:#f0883e", t("det.leg_pside"))); if (seam.rewinds.count > 0) sub.push(legendItem("background:#57606a", t("det.leg_rewind"))); - sub.push(legendItem("background:#8250df", t("det.leg_rest"))); + sub.push(legendItem("background:#9aa1a8", t("det.leg_rest"))); parts.push('' + legendItem("background:#8250df", t("det.cause_unattrib")) + '⊇' + sub.join("") + ""); } else { - parts.push(legendItem("background:#8250df", t("det.cause_ttl"))); + parts.push(legendItem("background:#9aa1a8", t("det.cause_ttl"))); } if (d.systemPromptTokens || lines.length >= 20) parts.push(legendItem("border:1.5px solid #8b949e;background:#f2f5f7;", d.systemPromptTokens ? t("det.legend_base") : t("det.legend_base_est"))); parts.push(""); @@ -1363,24 +1363,33 @@ export const WEB_CLIENT = `(function () { const tot = ledger.totals; parts.push('
' + t("det.cache_econ") + "" + (tot ? (tot.balanced ? ' ' + t("det.ce_balanced") + "" : ' ' + t("det.ce_unbalanced") + "") : "") + '
' + (d.ledger ? '
" : "")); if (tot) { + // #2929: percentages mirror the top-of-page basis — share of TOTAL + // INPUT (same denominator as the cache-hit % above). The + // unattributed tile's chips instead show their share of that + // bucket's parent total — "what eats the 2.6M" is the useful split. + const inp = Number(tot.input) || 0; + const parentU = Number(tot.ttlRepay) || 0; + const pc = (x) => (x >= 10 ? x.toFixed(0) : x.toFixed(1)) + "%"; + const pctIn = (v) => (+v > 0 && inp > 0) ? ' ' + pc((+v / inp) * 100) + "" : ""; + const pctU = (v) => (parentU > 0 && +v > 0) ? " (" + pc((+v / parentU) * 100) + ")" : ""; parts.push('
'); - mini(parts, t("det.ce_new"), fmtW(tot.newContent || 0)); - mini(parts, t("det.ce_comp"), fmtW(tot.compRepay || 0), false, (tot.compRepay || 0) > 0 ? t("det.ce_comp_hint") : ""); + mini(parts, t("det.ce_new"), fmtW(tot.newContent || 0) + pctIn(tot.newContent || 0)); + mini(parts, t("det.ce_comp"), fmtW(tot.compRepay || 0) + pctIn(tot.compRepay || 0), false, (tot.compRepay || 0) > 0 ? t("det.ce_comp_hint") : ""); // #2929: the unattributed bucket shows its own composition INSIDE the // tile (label · value · then the parts, top to bottom) — containment // rendered as layout, not as a caption floating beside the tiles. - const plainUnattrib = () => '
' + t("det.ce_ttl") + '
' + fmtW(tot.ttlRepay || 0) + "
"; + const plainUnattrib = () => '
' + t("det.ce_ttl") + '
' + fmtW(tot.ttlRepay || 0) + pctIn(tot.ttlRepay || 0) + "
"; if (seam && (seam.missed > 0 || seam.providerTtl.count > 0 || seam.providerSide.count > 0 || seam.rewinds.count > 0)) { var uChips = []; - if (seam.missed > 0 || seam.suspects > 0) uChips.push('' + t("det.attr_seam") + " " + fmtW(seam.missed) + (seam.suspects > 0 ? " ×" + seam.suspects : "") + ""); - if (seam.providerTtl.missed > 0 || seam.providerTtl.count > 0) uChips.push('' + t("det.attr_ttl") + " " + fmtW(seam.providerTtl.missed) + (seam.providerTtl.count > 0 ? " ×" + seam.providerTtl.count : "") + ""); - if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) uChips.push('' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + ""); - if (seam.rewinds.missed > 0 || seam.rewinds.count > 0) uChips.push('' + t("det.attr_rewind") + " " + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? " ×" + seam.rewinds.count : "") + ""); + if (seam.missed > 0 || seam.suspects > 0) uChips.push('' + t("det.attr_seam") + " " + fmtW(seam.missed) + (seam.suspects > 0 ? " ×" + seam.suspects : "") + pctU(seam.missed) + ""); + if (seam.providerTtl.missed > 0 || seam.providerTtl.count > 0) uChips.push('' + t("det.attr_ttl") + " " + fmtW(seam.providerTtl.missed) + (seam.providerTtl.count > 0 ? " ×" + seam.providerTtl.count : "") + pctU(seam.providerTtl.missed) + ""); + if (seam.providerSide.missed > 0 || seam.providerSide.count > 0) uChips.push('' + t("det.attr_provider") + " " + fmtW(seam.providerSide.missed) + (seam.providerSide.count > 0 ? " ×" + seam.providerSide.count : "") + pctU(seam.providerSide.missed) + ""); + if (seam.rewinds.missed > 0 || seam.rewinds.count > 0) uChips.push('' + t("det.attr_rewind") + " " + fmtW(seam.rewinds.missed) + (seam.rewinds.count > 0 ? " ×" + seam.rewinds.count : "") + pctU(seam.rewinds.missed) + ""); if (seam.abortCorrelated > 0) uChips.push('' + t("det.attr_abort") + " ×" + seam.abortCorrelated + ""); var uRest = Math.max(0, (tot.ttlRepay || 0) - seam.missed - seam.providerTtl.missed - seam.providerSide.missed - seam.rewinds.missed); - if (uRest > 8192) uChips.push('' + t("det.attr_rest", { x: fmtW(uRest) }) + ""); + if (uRest > 8192) uChips.push('' + t("det.attr_rest", { x: fmtW(uRest) }) + pctU(uRest) + ""); if (uChips.length) { - parts.push('
' + t("det.ce_ttl") + '
' + fmtW(tot.ttlRepay || 0) + '
' + parts.push('
' + t("det.ce_ttl") + '
' + fmtW(tot.ttlRepay || 0) + pctIn(tot.ttlRepay || 0) + '
' + '
' + escapeHtml(t("det.ce_breakdown")) + "
" + uChips.join("
") + "
"); } else { parts.push(plainUnattrib()); @@ -1388,7 +1397,7 @@ export const WEB_CLIENT = `(function () { } else { parts.push(plainUnattrib()); } - mini(parts, t("det.ce_residual"), fmtW(tot.residual || 0)); + mini(parts, t("det.ce_residual"), fmtW(tot.residual || 0) + pctIn(tot.residual || 0)); parts.push("
"); } const folds = ledger.folds || [];