From d4dc8b48b143488da4da1f478ccd197fe0bb2be4 Mon Sep 17 00:00:00 2001 From: iris Date: Wed, 18 Nov 2026 22:11:04 +0100 Subject: [PATCH] swarm ui: the context limit zones line up with their handles and legend The zones were drawn by percentage of the full track, but a range input's thumb travels its own range less one thumb width, and the range starts at 5. So the colour edges sat off the handles. The zones now follow the thumb's travel (a tested helper in soft-context), and the Firefox thumb has the same size as the other. The legend bars had no colour either, as the item rule reset the border colour; their rule is now more specific. --- .../src/agent/detail/ContextLimits.css | 32 +++++++++++++------ .../src/agent/detail/ContextLimits.tsx | 5 +-- .../swarm-ui/src/agent/detail/soft-context.ts | 10 ++++++ .../swarm-ui/test/soft-context.test.mjs | 8 +++++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/frontend/packages/swarm-ui/src/agent/detail/ContextLimits.css b/frontend/packages/swarm-ui/src/agent/detail/ContextLimits.css index 9984cddbd..7c7350e8a 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/ContextLimits.css +++ b/frontend/packages/swarm-ui/src/agent/detail/ContextLimits.css @@ -1,4 +1,8 @@ -/* — one track with three zones and two thumbs over it. */ +/* — one track with three zones and two thumbs over it. A range + input's thumb travels the track less one thumb width, its centre running from + half a thumb in to half a thumb short of the far end, so the zone edges sit at + the same spots: a place `p` along the range (0 to 100, `along` in + `soft-context.ts`) is at `calc(thumb / 2 + (100% - thumb) * p / 100)`. */ .ui-context-limits { box-sizing: border-box; width: 100%; @@ -14,6 +18,11 @@ } .ui-context-limits-track { + --thumb: 1em; + --fresh-at: calc( + var(--thumb) / 2 + (100% - var(--thumb)) * var(--fresh) / 100 + ); + --soft-at: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--soft) / 100); position: relative; height: 1.8em; margin: 0.4em 0 0.6em; @@ -30,9 +39,10 @@ border-radius: 0.3em; background: linear-gradient( to right, - color-mix(in srgb, var(--muted) 40%, transparent) 0 var(--fresh), - color-mix(in srgb, var(--green) 60%, transparent) var(--fresh) var(--soft), - color-mix(in srgb, var(--purple) 65%, transparent) var(--soft) 100% + color-mix(in srgb, var(--muted) 40%, transparent) 0 var(--fresh-at), + color-mix(in srgb, var(--green) 60%, transparent) var(--fresh-at) + var(--soft-at), + color-mix(in srgb, var(--purple) 65%, transparent) var(--soft-at) 100% ); } @@ -58,7 +68,8 @@ pointer-events: auto; -webkit-appearance: none; appearance: none; - width: 1em; + box-sizing: border-box; + width: var(--thumb); height: 1.6em; border: 2px solid var(--fg); border-radius: 0.35em; @@ -67,8 +78,9 @@ } .ui-context-limits-handle::-moz-range-thumb { pointer-events: auto; - width: 0.8em; - height: 1.4em; + box-sizing: border-box; + width: var(--thumb); + height: 1.6em; border: 2px solid var(--fg); border-radius: 0.35em; background: var(--bg-elev); @@ -120,10 +132,12 @@ padding-inline-start: 0.6em; border-inline-start: 3px solid transparent; } -.ui-context-limits-legend-fresh { +/* Under `.ui-context-limits-legend li` for specificity: that rule's shorthand + would otherwise leave the bar clear. */ +.ui-context-limits-legend .ui-context-limits-legend-fresh { border-inline-start-color: var(--green); } -.ui-context-limits-legend-soft { +.ui-context-limits-legend .ui-context-limits-legend-soft { border-inline-start-color: var(--purple); } .ui-context-limits-source { diff --git a/frontend/packages/swarm-ui/src/agent/detail/ContextLimits.tsx b/frontend/packages/swarm-ui/src/agent/detail/ContextLimits.tsx index 042d50cfe..fa37a753a 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/ContextLimits.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/ContextLimits.tsx @@ -9,6 +9,7 @@ // Two native range inputs sit one over the other, so the keyboard and screen // readers get two sliders; the track and its three zones are drawn behind them. import { + along, clampFresh, clampSoft, DEFAULT_FRESH_SESSION_PERCENT, @@ -41,8 +42,8 @@ export function ContextLimits({