Commit Graph
14 Commits
Author SHA1 Message Date
yetone 6e5f4fc97f gui: Tuned for you names its advice "Fewest tokens" and says a compaction window is a token estimate, not what the agent keeps (#1854)
cnlove7777777-art: the card called 230K -> 150K "best for you" on token
savings alone, while compacting sooner may lose more of a long coding
task. A retention benchmark isn't built now; the card says what it
measures instead:

- the advised value's label is "Fewest tokens", not "Best for you";
- a compaction row that advises a change adds "A token estimate only: it
  doesn't measure how well the agent keeps the task after a compaction.
  The lower the window, the more often it compacts." Not on a window
  already the leanest, nor on the cache lifetimes.
- zh, zh-TW, ja, de translations; agent-wiring.md says the same.

Run: context-tune.test.cjs (new assertions on label and caveat) passes in
Chromium and WebKit, 360 and 1100 wide, en/zh/zh-TW/ja/de; on
origin/main's assets it fails 11 of 12. context-*.test.cjs, gui-zh-tw,
gui-ja, gui-de, compact-at, i18n-keys: 99 pass, 0 fail. Not tried in the
real app window.
2026-10-13 04:31:07 +08:00
yetone 18e82adc62 gui: the window's pages down a sidebar in groups, the open page's tabs under it, and a button to have the header's tabs instead
From 1024 points wide (SIDE_AT) the window lays its pages down the left
as a Mac app's sidebar: Work (Agents, Sessions, Library), Models
(Providers, Routing, Gateway), Insights (Usage), Extend (Plugins), with
Settings and the gateway's address at the foot. The open page's own tabs
(Usage, Library, Plugins, Settings) are listed under it, opening and
folding on an iOS-like spring, and the page's strip is hidden. The header
becomes a breadcrumb, and pages whose head held only tools have them in
the title bar. Graphite: the open page is in the text's ink, not purple.
A pressed row darkens and never shrinks. The selection under the tabs
sets off as the row is pressed, on a 0.3s curve (it felt behind the
finger), and is the list's only shape: a sub-row hovered or pressed has
no ground of its own, which showed a block under the finger before the
selection slid there. The page's tab is clicked at once, so what is
typed next goes to it.

The title bar's button (or ⌃⌘S, Ctrl+Shift+S), there at every width,
picks the sidebar or the header's tabs. The choice is kept in
localStorage magpie.navLayout (side or top) at every width, so it is laid
out from the first frame; picked in a narrow window the sidebar is 184
points under 860. The two trade places in
a view transition: the sidebar slides, each tab flies to its place, and
the page slides as one. Without view transitions or under reduced
motion, the change is at once.

With nothing picked, narrower than 1024 the page beside a sidebar would
be narrower than Usage's requests table needs, so the header's tabs come
back. A resize
drops what a click held (heldWidth). Usage's KPI strip goes two to a line
by the room the page gives it (a container query), and Japanese counts
wrap there. Tests whose window is 1024+ were updated for the sidebar,
and docs/subsystems/gui-shell.md says how it works.

Run: sidebar.test.cjs and side-toggle.test.cjs 16/16 in chromium and
webkit, in en, zh, zh-TW, ja and de. Each was broken by hand (press
shrink, address cut, press glide, sub-row ground, view transition, kept
choice) and went red. Every page at 560 points with the sidebar picked,
zh and de, both engines: nothing scrolls sideways. session-identity's
ledger row sits under the footer beside the sidebar; WebKit's click
doesn't scroll to it, so the test wheels it up first. Animation frames were checked from a recorded video. The 105
affected GUI files in both engines; their reds were rerun alone and fixed
(filter-ime: the sub-row's click now at once; session-identity, above) or
fail the same on main (tray-logos). The full GUI suite in chromium, on
the rebase onto d5cae267a, was cut short at 352 tests on the owner's
"ship": 6 reds (account-alias, account-models, codex-auto-review,
codex-credits, context-text) each pass alone, here and on main d5cae267a,
so they are timing under the full run's load and are to be filed. After
rebasing onto e4e22b23e: sidebar, side-toggle, session-identity,
filter-ime, library-instr-busy, usage-speed-count and view-scrollbar,
50/50 in chromium and webkit. go build ./... passes.
2026-10-12 00:41:34 +08:00
yetone a98ab77fde gui, gateway: a context window's part, cell or item clicked opens the text the request sent there (masaka)
masaka on Discord asked to see the whole context behind the context window
card: click the agent's prompt, or any other part, and read it.

What changed:
- gateway: the trace keeps the last 10 request bodies in memory only
  (promptBodies; at most 32 MiB each and 64 MiB together, oldest dropped
  first), masked as the vendor got them. For a model the user let have
  the request unmasked, the masked copy is kept all the same. Never
  written to disk, never in telemetry. Route.Prompt and the routing
  history keep names and sizes only, as before.
- gateway: Server.PromptText re-reads a part's items and their text from
  that body (prompt_text.go). promptBuilder gains a keep mode that records
  each item's pieces: system text, tool definitions laid out as JSON, each
  turn's user/thinking/assistant/call pieces, tool results, and images
  or sealed reasoning named with their size. Sizes are unchanged.
- gui: GET /api/context/text?id=&kind=[&item=] (no-store; 404 "not kept"
  when the body is gone or another process serves the gateway).
- gui: in the card, a legend part, a waffle cell or a content row
  (click, Enter or Space) opens a wide modal: one item alone with "All of
  {part}", or the part's list 100 rows at a time, each item's text
  fetched when it is opened and shown 20000 characters at a time, with
  copy buttons. Strings in zh, zh-TW, ja and de.
- docs: gateway-routing and gui-shell subsystem pages; the site's start
  page (en, zh, ja) says the text is kept for the last 10 requests in
  memory and sent nowhere. The README Privacy is unchanged, since nothing
  more is sent.

What was run:
- go test -tags nogui ./... (temp HOME). internal/gateway hit the 10m
  default under the full parallel run, in TestRequestTailAfterOldLimit,
  which takes 57s alone on the base commit too; the package run alone
  with -timeout 30m: ok (700s, the machine shared with other runs). Every other package: ok.
- New tests TestPromptTextIsWhatWasSent, ...KeepsOnlyTheLastBodies,
  ...ChatPieces, TestContextTextAPI. Broken by hand: keeping the unmasked
  body fails (the key shows), and dropping keepBody fails ("not kept").
- gofmt -l; go vet, GOOS=linux and GOOS=windows go vet on internal/gateway
  and internal/gui.
- GUI: tests/context-text.test.cjs in Chromium and WebKit, en/zh/zh-TW/
  ja/de, at 1100 and 420px: legend, row, cell and keyboard open the text,
  long text grows on demand, the page never scrolls, and a gone body is
  named. It fails with the click wiring removed. Under a load average of
  ~140 one case failed once: the test read the list while the dialog
  still said "Reading…". Reproduced with a 400ms reply, fixed by waiting
  for the list; the mock now always answers after 200ms. A second case
  ("a click doesn't move the page", 662 vs 605 on the contents row) came
  from taking the page's top while a wheel scroll was still easing: the
  test now wheels to the row like the other cases, and wheelTo waits for
  three equal looks. Four full runs at load ~150 then passed (80 cases). context-window,
  i18n-keys, held-animations and the modal tests (dialog-backdrop-drag,
  editor-short-window, readable-focus, ux-safety, whats-new, add-sheet,
  api-key-theme) pass in both engines.
- Real use: a sandbox magpie (own HOME, ports 3486/3487, the Codex login)
  served a real `claude -p` (Claude Code) request on codex/gpt-6-luna
  that read a file. In its web UI, Usage > Context: each of System
  prompt, Tools, Memory, Files and Conversation, a waffle cell and a
  contents row opened the request's real text (Claude Code's system
  prompt, 21 tool definitions, the CLAUDE.md reminder, main.go's Read
  result, the turn with its thinking and call). No page errors.
2026-10-11 00:49:01 +08:00
yetone 05ed5e69ba context: Tuned for you's curves draw themselves once, not again each time the pane is redrawn
The Context tab redraws the whole pane whenever the advice answers, the
routing history answers, the state changes or a setting is put in. Only
loadContext marked the pane "still", and only when a new history replaced
an old one, so on opening the tab every curve played its entrance two or
more times (the owner saw them play "好多次"), and the history's cards
replayed theirs when the advice came in after them.

renderContext now remembers whether its last draw showed the history and
the advice: what was on the pane already holds still (.still for the
history, .tune-still for the advice), and only what is new plays. A range
change clears both, so the new range's draw plays once.

Run:
- new test "the advice's curves play their entrance once" (chromium,
  webkit): red without the change (8 draws of 4 curves in both), green
  with it.
- context-tune, context-window, context-scroll-end, group-context,
  routing-ctx-fold, routing-ctx-still: all pass in both engines.
- routing-context-fold: 2 WebKit failures, the same on origin/main without
  this change (the sticky header covers the fold button), filed as #1529.
2026-10-11 00:22:41 +08:00
yetone ad136426d2 gui: the context window's 400 cells and other entrance animations let go of their layers once played (#1481, hoffman24)
hoffman24's macOS app had a WebKit WebContent process over 1GB, 866MB of
it IOSurface graphics buffers for ~1,600 compositing layers. One clear
cause is ours: entrance animations played with fill "both" stay in effect
for good once finished, and an element with a finished transform/opacity
animation held keeps its compositing layer. The context window card's
waffle is 400 cells, each with ctx-cell (opacity + scale) and fill both,
so every card on Routing kept 400 layers alive.

Every one of these keyframes only says where the element starts (from),
or ends where its own style already is, so "backwards" draws the same
before and during the animation and lets go after:
- context.css: ctx-cell (waffle cells), ctx-grow (cache bar), ctx-arc
  (ring), ctx-draw (tune chart), ctx-pop (tune dots)
- library.css: lib-skel-in, .mk-card content-in (a market card's hover
  lift now shows too: the held animation overrode its transform)
- routing.css: .masking .pii rtpii

Measured on Routing with one context card (origin/main assets vs these):
- document.getAnimations(): 412 -> 13 (WebKit), 412 -> 15 (Chromium)
- Chromium CDP LayerTree: 421 layers -> 21

held-animations.test.cjs opens Routing with three traced requests,
waits for the cells to finish and asserts no finished animation is held
and the card looks the same (every cell opacity 1, no transform, cache
bar grown). It fails on origin/main ('ctx-cell': 400 held) in all four
cases and passes here: Chromium and WebKit at 420 and 1100px.

Run: the GUI tests touching ctx-/mk-card/lib-skel/masking/Routing/
Library (116 files): Chromium 576/576, WebKit 574/576. The two are one
case of routing-pointer-pin.test.cjs, whose card moved 588.56 -> 590px
under the full run's load; alone and 4-up it passed 3/3 and 36/36 here,
and 12/12 on origin/main's assets 4-up. Filed with the purpose-filter
WebKit 1px drift.
2026-10-10 20:00:38 +08:00
yetone 27e69702e1 context: Tuned for you draws each setting's cost as a curve over the advice, its waste shaded, the window set now saying how much more
The small sparkline had no scale: it couldn't show how much a setting
costs over the one advised. The curve is now the row's width and measured
from the advice's own cost (tune takes the largest window within 1% of the
cheapest, so the cheapest point is not the level): the area over the
advice's dashed level is what the other settings spend past it, the window
set now and the costliest say how much more (+%), and the advice is marked
Leanest. The cache lifetimes get the same chart for their two choices, and
it shows at a phone's width too. The section note sits closer to its
heading and further from the cards.

Run: context-tune.test.cjs in Chromium and WebKit, every language, phone
and desk widths (22/22), with checks on the set window's +% and the
advice's level; a shot of the owner's real 7-day /api/tune.
2026-10-10 18:25:14 +08:00
yetone 9d92068204 context: a folded context window card has as much space under its head as over it
Folded, the card is its head alone, but kept the open card's 14px over and
12px under, so the head sat 2px high (the user's screenshot). The folded
card's bottom padding is now 14px; the top is unchanged, so the title stays
where it is when the card opens.

routing-ctx-fold asserts the two gaps are equal (14,12 before the fix, both
engines). Run: routing-ctx-fold, routing-context-fold, routing-ctx-still,
group-context, context-window in chromium and webkit.
2026-10-10 17:55:31 +08:00
yetone 9e665491ec context: Tuned for you — each agent's settings worked out from the user's own calls, for the fewest tokens, put in on a click and undone on another
The Context tab now replays the period's calls of each agent against the
settings that decide what they cost, and shows, per agent and per model,
the value that would have used the fewest tokens for how this user works:
Claude Code's auto-compact window per model (modelSettings.<model>.
autoCompactWindow), its main and subagent prompt cache lifetimes
(promptCacheTtl, subagentPromptCacheTtl: 5m or 1h), and Codex's
model_auto_compact_token_limit. Each row says where the value comes from
now (the agent's default, the user's own setting, one magpie set, or a
variable that comes first and locks it), why (how fast conversations grow,
what a compaction leaves, how long the user pauses), the cost curve, and
the saving. Nothing is written until "Use …" is clicked; what was there is
stashed and Undo puts it back, unless the user changed it since. A window
the user set past the model's own is shown capped, as Claude Code caps it
(min(setting, model window)), so no saving is claimed that wouldn't happen.
Advice under a 3% saving is "already the leanest".

On the owner's 7 days (88K Claude Code calls, 956 Codex): opus keeps 200K
(their 500K is capped to it), fable 5.1 200K → 160K saves 5% (2.56M
tokens), both cache lifetimes and Codex's 272K are already the leanest.

Run: go vet ./... and go test ./... pass (internal/tune, internal/agent
TestTune*: user-set values kept, env locks, undo after a user edit, TOML
key order). context-tune.test.cjs passes in Chromium and WebKit, en/zh/
zh-TW/ja/de, at 360 and 1100px (22); context-window, context-scroll-end
pass. Full GUI suite: library-servers-bulk and market-have failed once
under load and pass alone; market-have fails on origin/main 494dedcf too
(1 of 8 runs). Claude Code 2.1.296 in a sandbox config dir shows
"Auto-compact window for Fable 5.1: 160k tokens (from settings)" for the
written modelSettings key. The real-data advice was read from the owner's
own ~/.claude and ~/.codex, nothing written.
2026-10-10 15:05:53 +08:00
yetone 666c0fa4fd routing: the context window holds still while requests stream in, and the prompt-cache card shows the last request's hit, dimmed, or a dash with the reason instead of "——命中" and an empty bar (dumplings on Discord)
dumplings reported that on Routing, every new request made the context
window jitter and flash, and that the prompt-cache card read "——命中",
glued together, with an empty bar under it.

Causes, measured with a frame sampler while requests stream through
start/read/done:
- A live request's story is shorter than a finished one's. "Is
  answering…" becomes "answered in 4.0 s…", which wraps onto two lines
  at phone width. The log head also gains View usage and Replay once the
  request is done. So the card under it moved up and back down on every
  request: 45px at 420px wide, 6px at 900px.
- The state pill ("Live" or "Counted") changed width, which moved the
  model name beside it by about 11px.
- While a request was under way the cache card dropped to "—" with a
  0% bar, then came back. That was the flash.
- A flex item's leading space is dropped, so " hit" and " / 272K" were
  glued to the figure before them.

Fix:
- routing.js holdStory keeps the log head and steps at the tallest
  height seen while following live, at this width and language. A
  picked request, a replay or a past day is drawn at its own height. A
  ResizeObserver on the steps measures again as soon as the width
  changes. Without it, a scrollbar appearing before the first request
  left a stale height and a 6px shift (seen in WebKit under load).
- context.js stacks all three state words in one grid cell and shows
  only the current one, so the pill keeps one width.
- While the next request is under way, the cache card keeps the last
  request's figure, dimmed (.was), with "The last request's · this one
  is on its way". When there is nothing to show, it gives a faint "—"
  and the reason ("Read once the vendor answers" or "The vendor didn't
  say"). The bar stays hidden but keeps its space. The remembered
  figure resets when the agent or session changes.
- .ctx-big gets a gap. Width and opacity transitions are turned off
  under reduced motion.
- The three new strings are added in zh, zh-TW, ja and de.

Verified:
- The new tests/routing-ctx-still.test.cjs streams two requests and
  checks that the card, model, state, used, cache, figure, bar, grid,
  legend and foot rects never move by more than 0.5px. It also checks
  the figure-to-word gap and both empty states.
- It runs in Chromium and WebKit, at en 420/1100, zh 420/1100,
  zh-TW 900, ja 900 and de 420. It narrows the viewport by 10px after
  load.
- On the old assets it fails 16 of 16 (the card moves 6–52px). It also
  fails with only the ResizeObserver removed.
- routing-live-patch now expects the held figure ("97%") on live steps
  instead of "—".
- Under --test-concurrency=4 in both engines: 578/578 pass across
  routing-*, context-*, click-scroll, group-context, panel-routing and
  gui-de/ja/zh-tw.
- go test -tags nogui ./internal/gui passes.
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gui are
  clean.
2026-10-10 10:13:43 +08:00
yetone c17cbfa161 routing, gui: the folded context window shows a thin bar of what fills it beside how full it is, one line high whatever a live request puts in it, and a request opened from the Usage page's Context tab shows its card unfolded, it alone (PILIPALA @NXirg2 on X, Jeremy.Zhou on Discord)
On af798bd1's fold: folded, the head carries a bar of the window's
parts (system, tools, memory, files, results, chat), morphed with the
head so a live request changes its widths only; the folded head is
pinned at the open head's 20px and doesn't wrap. "Latest request" and a
point of the session line on the Usage page's Context tab open the
request with { context: true }: its card shows unfolded for it, the
next request takes the reader's choice (magpie.ctxShut) again, which is
left as it was; folding that card by its title keeps it folded.

routing-context-fold (new): folded at 1920x1080, 1440x900 and 440x900
in en, zh and de, one line with the bar, the stage and (at 1440 and
wider) the request list in view, nothing running over; opening doesn't
move the page; the Usage page's request opens unfolded for itself only.
routing-live-patch's folded cases: the card, head and bar are the same
nodes across live requests and the card's height never changes. Both
fail on af798bd1's assets. No new strings.
2026-10-09 02:22:10 +08:00
yetone 03c8d21fde gui: opening the folded context window on Routing no longer scrolls the page 4px; the folded card keeps the open card's padding, so its title stays where it is and the browser's scroll anchoring has nothing to follow (af798bd1's fold)
The folded card had padding-block 10px against the open card's 14px, so
the title moved down 4px as the card opened and scroll anchoring moved
the page with it, at the top of the page too. A click never moves the
page. Folded, the card is 50px instead of 42px, still one line.

routing-ctx-fold now opens the card with the title in view and checks
that scrollTop is the same and the title moved at most 1px. On
af798bd1's assets it fails in Chromium and WebKit ("200 -> 204", "0 -> 4");
with this change it passes 3/3 in each.
2026-10-09 02:22:10 +08:00
yetone af798bd1bf routing, gui: the context window's card folds to its head, with how full it is beside the title ("114K / 272K · 42%"), and stays folded for the next request and after the page comes back, so the request list under it has the room (0xBCD18E on X: 这个"上下文窗口"的板块非常占"上下"高度,还不能折叠,下面只能展示三行)
ctxCard takes opts.foldable (Routing passes it; the Usage page's cards
don't): its title becomes a button with a chevron, aria-expanded, and a
click toggles .shut on the card, which hides all but the head. The choice
is kept in localStorage (magpie.ctxShut). The head is morphed in place, so
the click reads the button from the event, and the card that is there
keeps .shut across live patches; a new card takes it from the saved choice.

Verified: routing-ctx-fold.test.cjs (new), at 420 and 1100 wide in
Chromium and WebKit, 3/3 each: open, then folded to one line (<60px) with
the figure, the list under it up by >200px, nothing runs over at 420px;
another request picked is still folded; after a reload still folded;
opened again, 400 cells and the same height as before. It fails on the old
code (no .ctx-fold). routing-*, context-*, usage*, group-context,
click-scroll, panel-routing, old-webkit, gui-ja/de/zh-tw: WebKit 371/371;
Chromium 370/371 once at --test-concurrency=4, routing-blocked's "picking
the request moved the page", which passes 3/3 alone and in two more
routing-* runs at the same concurrency (196/196 each). Not filed as caused
by this change; seen once under load.
2026-10-09 01:40:02 +08:00
yetone 6485f5ecb5 gui: the Routing page, and Usage's Context tab with a session open, scroll to their end in WebKit: their narrow and wide layouts go by classes set from each box's width, not container queries (#1249)
In WebKit (the macOS app's WKWebView, and Playwright's WebKit) the Routing
page stopped well short of its bottom (wizzy-yang on #1213). Each time the
page was drawn again while it was scrolled near its end, WebKit cut its
scrollTop back to a shorter range. The page has query containers in it
(.rt, .rt-accts, .rt-more, .rt-col), and the cut happens during a redraw.
Seen at 440x620: 575 of 585, and up to a whole screen short when a part
was redrawn. Chromium is unaffected. With container-type set to normal on
those boxes the page reaches its end, and the cut goes away. Replacing a
container with its clone at the end reproduces it in WKWebView too.

Each box's width now sets a class, the same way container queries would
have chosen a layout:
- routing.js sets the classes from a ResizeObserver: max560 on .rt and
  .rt-accts, max460 on .rt-accts, max520/min1150 on .rt-more, and
  max440/max760 on each .rt-col.
- context.js does the same for each .ctx-card: max520 and max420.
- A rule that names the box goes through :where(), so it keeps the
  specificity it had inside its query.
- The class is set on the next frame, as quotaFit does: set in the
  observer's own call, it changes the box's height, and WebKit reports
  that as a ResizeObserver loop.
- A redrawn ctx-card starts with the width the last card in its place had
  (routing or session). It doesn't lay out wide for a frame and then
  narrow, which would itself pull the page up.
- The Safari 15 @supports fallbacks are dropped. They chose a layout by the
  window's width, and ResizeObserver covers that Safari.

Sibling: Usage → Context, with a session open, has the same bug. Each
timed read redraws the card, and WebKit pulled the page up by up to 946px
at 420 wide (682px at 1100). It is fixed the same way. The other query
containers were checked at their end with a synthetic redraw and were not
affected: Library's .lib-row.with-agents and Agents' .row.agent .who.
Sessions (.sess-pane) also jumps in WebKit as it refreshes, but it still
does with its container removed, so the cause is something else. It is
left alone here.

Run:
- routing-scroll-end.test.cjs (new): 440x620, 600x700, 900x500, 1200x600
  and 1400x700, en and zh, Chromium and WebKit, with the trace redrawing
  the page. It also checks the stage, request and column layouts. On the
  old CSS all 10 WebKit cases fail (twice); with the fix it passes 22/22
  (four runs).
- context-scroll-end.test.cjs (new): 420, 700 and 1100 wide, en and zh,
  across a timed read. On the old CSS the WebKit cases fail ("958 of
  1891"…); with the fix it passes 14/14.
- Layout compared with the old CSS: every element's rect on the Routing
  page (group editor closed and open) and in the Context card. Widths
  360–1700, en/zh/zh-TW/ja/de, Chromium and WebKit: 220 + 100
  configurations, none differ, and there are no page errors.
- The macOS WKWebView: a part redrawn at the end left the page 200–238px
  short before the fix and 0 after, at 440 and 1100.
- gui-ja, gui-de, gui-zh-tw and i18n-keys pass.
- Full GUI suite (concurrency 4): 3719/3733.
  - Pass alone: azure-endpoint, remote-magpie, signin-again and
    routing-sessions.
  - mobile-web compares with origin/main, which had moved on; against
    this commit's parent it passes.
  - panel-arrange fails the same way on the parent.
  - context-window's chromium 1100px hover flakes under load on the parent
    too: 5 of 16 parallel runs, against 1 of 16 here.
- go test ./internal/gui; GOOS=linux and GOOS=windows go vet
  ./internal/gui.

Not run: the reporter's own machine, or an old Safari 15 WebKit.
2026-10-08 15:57:08 +08:00
yetone 586f2bce8f context: magpie inspects the context window of every request, session and agent
The gateway reads each request's prompt into its parts (system prompt,
tools and MCP servers, memory, files, tool results, chat), measured
against the model's window and calibrated to the tokens the vendor
counted. Routing shows a request's window as a card: a 400-cell grid by
part, a hover naming what is largest in a cell, and the contents by part.
The Usage page's Context tab scores each agent out of 100 (cache reuse,
how lean it starts, how fast it grows, how reliably it answers), tags it
(lean, cache-friendly, mcp-heavy, compacts, near-full…), and draws each
session's growth with its latest request's card.

Older Safari (15) gets media-query and solid-colour fallbacks for the
card's container queries and color-mix.
2026-10-08 05:36:17 +08:00