ac4af582301a4e8a29245dbba767eba31334ddf9
13
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
f78d6b0d95 |
tune: gateway mode leaves Tuned for you out
/api/tune replays this computer's Claude Code and Codex files, and a ~/.claude folder alone makes a Claude Code card. In gateway mode the agents are on other computers, so the card said Claude Code made 0 requests while the harness card counted the gateway's. /api/tune now says gateway: true with no agents, Use and Undo answer 409, and context.js draws no section. Run (mote): go test ./internal/gui -run 'TestTune|TestGatewayMode' ok; node --test context-tune-gateway, context-tune, context-tune-shapes 334/334 (Chromium and WebKit, en and zh, 900 and 420 wide); vet both OSes and gofmt clean. Broken by hand: with the ownSessionsOff checks taken out the Go test shows the reported Claude card with 0 calls; the GUI test fails 20 of 30 (every gateway-mode case) on the old context.js. Not tried: a real Docker magpie; the full suite (mote rebooted mid-run). Reported-by: linkaww on Discord |
||
|
|
9ed0f1fa49 |
agents: Claude Code's prompt cache lifetime is picked in its settings
Linka (Discord) asked to set Claude Code's prompt cache TTL from magpie. Until now only Usage › Context's "Tuned for you" card wrote it, and that card offers nothing when the value is already the cheapest it found. Claude Code's opened row and settings sheet now have two rows under its own Long conversations: "Prompt cache · main conversation" and "Prompt cache · subagents". Each opens the app menu with Claude Code's default, 5 min and 1 hour. They write the keys the card writes, promptCacheTtl and subagentPromptCacheTtl in Claude Code's settings.json (agent.ClaudeCacheSet, POST /api/settings/claude-cache). Default takes the key out. A pick is the user's own: it forgets the card's stash, so the card's Undo leaves it. A variable that comes before the setting (FORCE_PROMPT_CACHING_5M, CLAUDE_CODE_PROMPT_CACHE_TTL, CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL, in settings.json's env or magpie's own) disables the row and names the variable, and the route refuses it, so a value the user set by hand is never written over. The names were checked in Claude Code 2.1.316's binary. Its resolver checks FORCE_PROMPT_CACHING_5M, then the env var, then the setting (enum "5m"/"1h"), then an agent's experimental.cacheTtl, then ENABLE_PROMPT_CACHING_1H. With nothing set, the main conversation gets 1h on a subscription within its limits and subagents get 5m. Run (mote, at this tree on |
||
|
|
ff2a06c349 |
gui, tune: Tuned for you weighs a model magpie routes at its provider's price, not by its name (#3435)
Tune weighed a call's tokens by its model's name alone (tune.WeightsFor):
an id starting "claude" at Anthropic's ratios (read 0.1, write 1.25, an
hour's write 2), any other at generic ones (an hour's write at a
5-minute one's price). Claude Code is given magpie's models as
provider/model ids (copilot/claude-opus-5-5, anthropic/claude-opus-5-5),
which the name rule took for no Claude model. So a Claude model on an
Anthropic-billed provider was weighed with its hour costing no more than
5 minutes, and none was weighed at the price the usage pages count.
The replay now takes its weights from a tune.Weigh (CompactOpts.Weigh,
and CacheTTL's third argument), per stream; nil weighs as before. Tuned
for you passes pricedWeights: an id with a provider resolves as the
gateway resolves it (provider.Resolve after ClaudeRead) and is weighed
at that provider's EffectivePriceIn, so a Claude model on Copilot has
its hour at the 5-minute write Copilot bills (the previous commit) and
one on Anthropic at 2x. A model Claude Code named itself keeps its
maker's weights, as does a price with no cache read or write. The
compaction advice is weighed the same way. docs/subsystems/agent-wiring.md
says so.
Run on mote (go1.26.8, macOS) at
|
||
|
|
fcc0daa23e |
usage: Tuned for you tells Claude Code's cache here with no calls, and an hour of the user's has Use 5 min
linkaww (Discord, #help) set Claude Code's prompt cache to 1 hour from Usage > Context > Tuned for you and asked how to go back to 5 minutes. On the computer that sends its requests to a Remote magpie the card was empty, so there was nothing to see or undo. Cause: the card's rows came only from advice, which needs 50 calls read from this computer's session files, or from a knob tune put in itself (TuneKept, v0.1.3120). A Remote-magpie client with too few calls read here, or a 1 hour it didn't put in through magpie (set on the other computer's card and copied, set by hand, or stashed by a version before 3120), had no row. The setting itself is Claude Code's settings.json on the computer where Claude Code runs (promptCacheTtl, subagentPromptCacheTtl); a Remote magpie's requests read B's, not A's. Now: - agent.TuneCacheHere reads Claude Code's two cache lifetimes on this computer whoever set them: the main conversation's always, the subagents' when something sets it, nothing when there is no ~/.claude. adviseOf adds them to the kept knobs, so Claude Code's card shows with no calls at all, each row's Now saying 1 hour, 5 minutes or Default. - A row with too few calls at 1 hour that magpie didn't put in has Use 5 minutes (tooltip: Replaces your 1 hour; Undo puts it back); after it, Undo gives the hour back from the stash. A variable that comes first (CLAUDE_CODE_PROMPT_CACHE_TTL, FORCE_PROMPT_CACHING_5M) still locks it. - A row with too few calls no longer reads "Already the leanest". - The three Use buttons share one helper, which pays for the new one: context.js is 82 bytes smaller, TestCoreScriptBudget's budget untouched. No new strings. Run (mote, via mote-run): - go test ./internal/agent ./internal/gui -count=1: agent ok; gui's only reds are TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27 on mote) and, before the helper, TestCoreScriptBudget (fixed as above); after: -run 'CoreScriptBudget|Tune' ok. - context-tune.test.cjs in Chromium and WebKit, all five languages, 360 and 1100 wide: 24 of 24 ok. i18n-keys: every test ok but "a plugin's words are its own", red on main for three strings in other files (#5332, #5426, #5482). - gofmt -l clean; go vet darwin (touched packages), GOOS=linux -tags nogui ./... and GOOS=windows ./... ok; builds for all three ok. Broken by hand: - old internal/gui/tune.go: TestTuneTellsTheCacheHere red ("the user's own 1h, no calls: rows []") and TestTuneKeepsWhatItPutIn red. - old context.js: the new GUI test red in both engines (Now read "—" where Default is expected). Not tried: a real Remote magpie pair (two computers) with linkaww's settings, and a real Claude Code session reading the 5m after the press; the whole GUI suite ran after the push, not before (suite lock held). Reported-by: linkaww (Discord) |
||
|
|
6b91c2ea5b |
usage: a cache or window Tuned for you put in keeps its Undo with too few calls
linkaww on Discord (11-06): "之前在用量 - 上下文把Claude Code缓存改成了1h 请问在哪里改回5m". Usage › Context › Tuned for you is the one place in the GUI that sets Claude Code's promptCacheTtl, subagentPromptCacheTtl and a model's autoCompactWindow, and its row (with Undo) came only from advice, which needs 50 calls in the range. On Today, or a quiet week, the row and the way back were gone, and an agent with no calls had no card at all. agent.TuneKept lists the knobs tune put in (its stash, read back as ours, not under Long conversations). /api/tune adds each one that has no advice row as a few row, and keeps an agent with none of its own calls when it has one. The card draws a few row as In use with Undo and "Not enough calls in this range to tune on", and no curve; the card's totals skip it. A value the user wrote themselves is not listed. Codex's compact is left out: Settings changes it. Run (mote, at this tree): - go test ./internal/agent ./internal/gui -count=1: agent ok. gui is red only in TestMainWindowCorners, which is red the same way on a fresh origin/main |
||
|
|
3eb2bda4f2 |
settings: Codex, Claude Code and Grok Build each take a Long conversations of their own (molianyin4227 on Discord)
molianyin4227 (Discord #help): models differ, so one compaction size
for every agent fits none; they asked for Codex, Claude Code and Grok
Build to each have their own, falling back to the shared one.
- settings.AgentCompacts[agent] {At, Full} for the agents that write a
compaction window (CompactAgents: codex, claude, grok); Settings.
ForAgent(agent) lays it over CompactAt/FullContext for that agent's
readers only: codexcat.entriesAt, provider codexListed, Claude Code's
writeCompact and desktopPlan, grokModelTables, the route list's
buildModels, Codex's window line (api.go) and Tuned for you
(gui/tune.go, agent/tune.go). A model's or provider's own Compact at
still comes first. An agent with none follows the shared value, so
nothing new is written for it, and an agent outside the three has no
such key and is refused (provider.SetAgentCompact).
- POST /api/settings/agent-compact {agent, own, full, at}; own false
takes the agent's value away. settingsapi.Merge keeps the map.
- GUI: a row "Long conversations in <agent>" under Long conversations,
in the agent's opened row and its sheet: Every agent / Compact at N /
Full window (segs, no select), a size box when Compact at. It lives in
agentcompact.js, imported when the agent's settings hold Long
conversations, then put in synchronously (an async put-in after a
redraw moved the page in chromium: codex-memories-settings' scroll
check). It draws again only when its own values change. i18n in
zh, zh-TW, ja, de.
- Tuned for you's Use on an agent with its own value changes that one,
stashed under tune.long.compact.<agent>; Undo puts it back.
- codex-memories-settings' "no Codex" check counts Long conversations
alone again (:not(.agent-compact)) and waits for the new row.
- docs/subsystems/agent-wiring.md: a row for it.
Core size: app.js 1,311,919 bytes, 109 under origin/main
|
||
|
|
c903c3a411 |
usage: Use on Codex's window lands over 7 and 30 days, a model's own Compact at named apart (hoobnn on Discord)
hoobnn on Discord (11-01): "观测-用量-上下文里,在7天或者30天的选项里,点击
应用codex的上下文,没生效。" Over 7 or 30 days the range held calls on a
model whose provider has a Compact at of its own (430K); today's didn't.
Tuned for you's "Now" was the largest compaction point over every model
in the range, so it came from that model. Use put the advice in Long
conversations, which did move Codex's other models (Codex's list had
them at the advice), but the card still read 430K and then turned held
("compacts at its own 430K, which comes first"), so nothing seemed to
happen. And with Long conversations at magpie's default, a range of
only such models offered a Use that could move nothing.
codexWindow (internal/gui/tune.go) now reads "Now" from the models Long
conversations moves, and lists each model with its own Compact at as
Apart (largest first). Only a range whose every model has its own is
held (Own), whatever Long conversations says. The card names each
model kept apart under the row: "{model} compacts at its own {value},
which this doesn't move", in en, zh, zh-TW, ja and de.
provider.CompactSetIn is CompactSet with the caller's settings and
group finder, as CompactFor takes them.
Siblings: Claude Code's knob is per model (no max over models), so it
has no such mix. 1, 7 and 30 days go through the same codexWindow;
the GUI test covers 7 and 30 and the Go test the 1-day sample.
Run on mote at
|
||
|
|
5d955a4d4b |
tune: Codex can take the compaction advice in the background, its own limit kept (herman_hong)
herman_hong on Discord: Tuned for you advises Codex compact at ~120K.
A foreground compaction kept them waiting, so they had set 384K by hand.
Now that Codex compacts in the background, they want the advice there
and the 384K kept as the backstop.
Codex has this since 0.163.0 (checked in codex-rs at rust-v0.166.0, not
in 0.162.1): [features.async_compaction] enabled and
model_async_compact_threshold_percent, an integer share (1 to 100) of
the model's window, 65 by default. It is Stage::UnderDevelopment, runs
only with remote compaction v2 (which magpie already sets on its
provider), and starts none once the foreground limit is reached. magpie
already writes it from Settings' Background compaction (#2490), with
the version gate and the user's own keys kept. This drives that setting
from tune:
- agent: knob TuneAsync ("async_compact") on codex. TuneRead gives the
share, TuneApply turns Background compaction on at it (stashing what
Settings had the first time), and TuneUndo puts that back unless the
user changed it since. The foreground limit (Long conversations, or
the user's model_auto_compact_token_limit) is never touched. Async
keys the user wrote in config.toml come first (codexAsyncOwn): the
row says so and Apply errors. A table magpie wrote itself doesn't
count as the user's.
- gui/tune.go: advice.async holds the advice as a share of the window,
rounded down. With timed compactions it uses the token-cheapest
window, since a background compaction keeps no one waiting. It is
offered only when it would start before the foreground limit (the
lesser of the limit now and 90% of the window). held lists Codexes
too old for a share.
- context.js: the row gets a text button, "Use 120K in the background",
whose tip gives the share and says the foreground limit stays. After
Use a chip says so, with Undo background. A config.toml of the
user's, or a Codex too old, gets a one-line caveat and no button.
The too-old line is shared with Settings' row (codexHeld). No select,
no layout change. zh, zh-TW, ja and de are in i18n.js.
- The core script budget goes up by 1,571 bytes for the row
(core_budget_test.go says why). app.js is 278 bytes smaller.
Run (at this change on origin/main 6893cfbe3; rebased on
|
||
|
|
fbeed7e7f7 |
usage: the Context tab reads each day and each session file once, not at every refresh (Yayoi_no_yume on X)
A user running magpie on a 1-core, 962 MB server opened Usage › Context.
CPU went to 100%, memory to 91%, and the server went down.
Cause: the tab asks /api/context and /api/tune at every refresh of the
Usage page (every 5s by default). Each ask:
- /api/context read up to 7 days of routing history again, as whole
gateway.Route values (prompt items, order, tries). A gzipped day not yet
counted was parsed whole, every route of it, before being cut to its
latest 2000 (gateway.History).
- /api/tune read every Claude Code and Codex session file in the range
again, whole, into []sessions.Call, then worked the advice out of all of
them.
Now:
- gateway.History counts a .gz day's lines first and then parses only its
latest historyMax+historySlack routes, as it already did for .jsonl.
- /api/context keeps each day's routes slimmed (ctxRec: the parts' tokens
without their items; the whole prompt only on the routes that can be a
session's latest), keyed by the size and mtime of the day's files. A
day is read again only when its files change. The answer is given again
while its days and the trace are unchanged, for at most a minute.
- /api/tune keeps each file's calls as tune.Call (~100 B each), keyed by
size, mtime and agent, read one file at a time through
sessions.ReadCallSource. A message copied into a resumed session is
still counted once (the earlier file owns it, as in sessions.Calls). The
advice stands for a minute, and apply or undo lets it go at once.
- tune's stable sorts use slices.SortStableFunc instead of
sort.SliceStable, which was most of the CPU over 300k calls.
Measured on mote with a generated fixture: 8 days of 20,000 routes each
(7 gzipped, built from a real 2.2 KB route), and 200 Claude Code files of
1,500 calls each (300k calls). The scratch bench was not committed. mote
was at load 130-170 from other suites, so wall times are noisy; CPU time
is from rusage and peak heap is sampled every 2 ms.
/api/context before: 1st ask 4.2s CPU, 158 MB peak heap, 202 MB RSS;
every refresh 0.63s CPU, 111-121 MB peak heap
after: 1st ask 0.84s CPU, 48-55 MB, 90-93 MB RSS;
every refresh 3-5 ms CPU, 21-34 MB
/api/tune before: 1st ask 4.3s CPU, 498 MB peak heap, 717 MB RSS;
every refresh 1.0s CPU, 370-494 MB peak heap
after: 1st ask 0.83s CPU, 373 MB, 409 MB RSS;
within a minute 0 CPU, nothing read;
after a minute with a file changed, that file is
read and the advice worked out again (~0.5s CPU)
Tests:
- TestContextReadsADayOnce: a day whose files are unchanged is not read
again; a grown day is, and only that day; each session's latest prompt
keeps its items; the kept answer equals contextOf over every route.
- TestTuneReadsAFileOnce: an unchanged file is not read again; a grown
one is; a copied message counts once; the call count matches
tuneOf(sessions.Calls(...)); within a minute nothing is read.
- TestHistoryParsesOnlyAGzDaysLatest: a 5,200-route gz day parses at
most 2,200 routes.
Broken by hand: always re-read the day, skip tune's file check, drop
History's count-first block. All three tests went red (days read 4
times, files read 5 times, 5,200 routes parsed), then green again once
restored.
Run on mote at this tree:
- gofmt -l: clean.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
go vet ./..., go build ./...: all ok.
- go test ./internal/gui ./internal/gateway ./internal/tune
./internal/sessions: tune and sessions ok. gui is red only on
TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27 on mote). gateway
is red only on the Antigravity turned-away tests and
TestCodexSpentGrokFailingIsTold, which are red on main (#4362). This
change touches neither.
- GUI (node --test, Chromium and WebKit): context-*.test.cjs,
compact-one-value, usage-refresh, usage-refresh-flight and
usage-stale-answer: 270 of 273 pass. The 3 reds are context-map's
"two tiles overlap" in WebKit at 420px (en, ja, de), the overlap
#3488 has under load (mote at load ~160). No .js changed, so app.js's budget is
untouched.
Not tried:
- A real 1-core, 1 GB box.
- Codex rollouts in the fixture: Codex files take the same path.
- internal/usage's codexCalls, which still uses sessions.AgentCalls
(Codex only, on the Usage identity path) and is unchanged.
- tune's first ask, and each ask after a minute with a file changed,
still works over the range's calls at once: ~30 MB kept per 300k calls,
and a few hundred MB peak while the advice is worked out. It is bounded
by the calls in the range, not by a fixed size.
|
||
|
|
5143bf593a |
tune: Codex's "Now" is read the same way in every range, and a model's own Compact at is not "In use"
hoobnn (Discord #feedback): Usage > Context's Codex card read differently
for Today and 7 days. 7 days: "Now 380K", "Not the leanest" and a Use
220K button. Today: "Now 430K -> Fewest tokens 170K" with a green "In use".
Two causes:
- codexWindow dropped what magpie tells Codex (told) for the whole range
as soon as one call was on a model outside the catalog or with an
unknown window (Codex's own gpt-5.x beside a provider's). "Now" was
then guessed from the prompts' peaks (380K) over 7 days, while today's
calls, on catalog models only, read told (430K). told is now the
largest value over the models magpie knows, in every range.
- Long conversations held magpie's 170K and the advice was 170K, so the
row said "In use", but a provider's or model's own Compact at (430K)
comes first and is where Codex runs. The advice now carries Own
{model, value}; the card shows "{model} compacts at its own {value},
which comes first" in place of "In use" and hides Use and Other window,
as it does for a locked setting. Undo stays. New string in en, zh,
zh-TW, ja, de.
Run (at this tree, rebased on origin/main
|
||
|
|
f201183047 |
tune: the compact window is Long conversations, one value for both agents
7eleven (Discord #help): the Usage page's "Tuned for you" compaction
value and the agents' sheet "Long conversations" window were two values
that could disagree. Codex's tune wrote model_auto_compact_token_limit
into config.toml beside the catalog's context_window that Long
conversations writes; Claude's read its own env.
One source of truth: settings.CompactAt / FullContext. Tune's compact
row for Codex and Claude Code now has source "long": its Current is
settings.Compact(), Use calls provider.SetCompactAt (Sync writes Codex's
catalog and Claude's CLAUDE_CODE_AUTO_COMPACT_WINDOW as before), Undo
puts back the CompactAt/Full it stashed under tune.long.compact. So a
value set on either page shows on the other and writes the same config.
writeCompact marks claude.compact_long when the env value came from
settings, so Claude's row reads it as ours, not as the user's.
Migration (Codex Sync, local place): an old tune.codex.compact stash
whose limit is still the one tune wrote moves into Long conversations.
At default or Full it takes tune's value; with a value the user set it
takes tune's only when smaller. config.toml gets the user's earlier
limit back or loses the key; the stash is forgotten. A limit the user
changed after tune wrote it, or wrote themselves, stays and reads
Locked. A provider's Compact at or the user's own Claude env stays
Locked too.
Run (mote, at this tree):
- go vet on agent, provider, gui, tune; GOOS=linux go vet -tags nogui
./...; GOOS=windows go vet ./...; go build ./... and -tags nogui: ok
- go test -tags nogui ./internal/agent ./internal/provider
./internal/tune ./internal/gui: ok (TestCoreScriptBudget within the
budget, not raised; context.js is 33 bytes smaller)
- GUI: compact-one-value.test.cjs (new; Chromium and WebKit, en zh
zh-TW ja de) and context-tune: 104/104 at the rebased head
Broken by hand: the Codex long branch, the Claude long env check and
the Sync migration call each turned red TestClaudeCompactAt,
TestCodexHomeEnvTakesThePick, TestTuneCodexCompact,
TestTuneCodexOwnLimit, TestTuneCodexMigrate (4 subtests),
TestTuneClaudeLong and TestTuneCodexMigrateOnSync. Old context.js and
i18n.js turn compact-one-value red ("You set 272K").
Not run: full suite, Go or GUI (shipped at once per owner; the GUI suite
is still running on mote, reds get their own issues).
Not tried: a real Codex or Claude Code session reading the written
config; the migration on Windows/WSL places (it runs for the local
place only).
|
||
|
|
035c259a6d |
tune: Codex's compaction windows run to the model's own window or 1M, not the largest prompt seen (zhemu on Discord)
zhemu: Codex Desktop on a CLIProxyAPI provider's 1M GPT model, Settings ›
Long conversations at 750K; Usage › Context › "Other window…" stopped at
~412K. tuneOf took Codex's window as max(272K, the largest prompt seen),
so tune.Compact capped both the offered windows and the user's own value
at the largest prompt (~412K), whatever the model's window or the
user's setting.
Now codexWindow reads the window from magpie's catalog: a model with a
known window (typed or catalog) is offered up to it, and "now" is the
window magpie tells Codex (Settings' long-conversation value or the
model's own compaction, as codexcat writes it), 750K for zhemu. A model
whose window magpie doesn't know caps nothing short of 1M, and a mix
with one unknown is unknown. Codex's own models keep 272K or the
largest prompt. Claude Code is unchanged: only Claude models get the
advice, and other vendors' models use magpie's own window.
Run:
- TestTuneWindowsAreTheUsers (internal/gui), a custom provider with an
unknown window, 1M and 400K, on Codex and Claude Code. Old code:
"Codex on cpa/gpt-cpa-open: windows offered up to 410000; want
1000000" (and for 1m). Broken by hand: told dropped → "now 0, want
750000"; window=0 for unknown dropped → the mixed case fails.
- TestCompactUnknownWindowCapsNothing (internal/tune): old code "no advice".
- gofmt -l clean; go vet ./... and -tags nogui for GOOS=darwin, linux,
windows clean.
- context-tune.test.cjs (Chromium + WebKit): 70/70 pass.
- go test ./internal/tune ./internal/gui ./internal/settings ./internal/davsync
green at this head, rebased on origin/main
|
||
|
|
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
|