From 4bc02b0102e45dc8cce97b7fc8499e0ab23d862f Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Fri, 12 Jun 2026 01:01:32 +0900 Subject: feat(metrics): consume contextSize — current context-usage readout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend context-size handoff: re-pin wire@0.5.0 / transport-contract@0.6.0 (+ re-mirror .dispatch reference snapshots). Thread the optional contextSize through core/metrics (done fold + durable + selectCurrentContextSize: latest turn's defined value, undefined=>unknown never 0, durable-wins-over-live). Chat store exposes currentContextSize; ContextSizeBadge renders "N tokens in context" / "context size unknown" above the composer. GLOSSARY: add context size / context window. 533 tests green. --- src/core/metrics/format.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/core/metrics/format.test.ts') diff --git a/src/core/metrics/format.test.ts b/src/core/metrics/format.test.ts index 3eec93d..7c143d7 100644 --- a/src/core/metrics/format.test.ts +++ b/src/core/metrics/format.test.ts @@ -4,6 +4,7 @@ import { computeCachePct, computeExpectedCachePct, computeTps, + formatContextSize, viewCacheRate, viewExpectedCache, viewStepMetrics, @@ -308,3 +309,17 @@ describe("viewExpectedCache", () => { expect(v?.isHit).toBe(true); }); }); + +describe("formatContextSize", () => { + it("formats a defined count with thousands separators", () => { + expect(formatContextSize(34102)).toBe("34,102 tokens in context"); + }); + + it("renders a placeholder for undefined (never 0)", () => { + expect(formatContextSize(undefined)).toBe("context size unknown"); + }); + + it("renders an explicit 0 as zero tokens (a real reported value)", () => { + expect(formatContextSize(0)).toBe("0 tokens in context"); + }); +}); -- cgit v1.2.3