settings: longest context can hold a model's own window too (WJaunita45604 on X)
v0.1.3681's Longest context left a window the user set for a model, or "*"
on its provider, alone even when longer. Settings > Models > Routing now has
a menu beside the field: "Models without their own" (the default, as before)
or "Every model". In both modes the shorter of the cap and the user's own
window is told; they differ only when the user's own is longer (own keeps it,
every model brings it down). Settings.ContextCapAll, Settings.CappedOwn,
POST /api/settings/context-cap-mode {all}, magpie model context-cap all|own.
Applied in provider.windowIn (so /v1/models, catalogs, compaction), Codex's
CodexNativeWindow/CodexWindow (the list's ETag tag carries the mode) and the
gateway fallback window. i18n in zh, zh-TW, ja, de.
Run (wsl-run, mote's disk was full): provider (full), settings, settingsapi,
codexcat packages; cli -run ContextCap; gateway -run ContextCap|ModelsList;
GUI context-cap, i18n-keys, model-load, settings-places, settings-general in
chromium and webkit; TestCoreScriptBudget; gofmt; go vet nogui and
GOOS=windows vet. Broken by hand: windowIn's CappedOwn removed turns
TestContextCapAllHoldsTheUsersOwnWindowsToo red.
Not tried: the whole Go and GUI suites, a real Codex reading the list, macOS
or Windows runs, GUI in zh-TW/ja/de beyond the i18n-keys check.
This commit is contained in:
@@ -26,7 +26,7 @@ something else shows up as drift.
|
||||
| Codex background compaction | Long conversations' Codex background compaction, in Codex's opened row on the Agents page (`CodexAsyncCompact`, `CodexAsyncCompactPercent`, #2490) writes `[features.async_compaction]` `enabled = true` and `model_async_compact_threshold_percent` (Codex 0.163 reads it only in that table) into each Codex config magpie routes, on every `Sync`. The table is written only when every Codex that reads the config is 0.163.0-alpha.8 or later (`codexReaders`: the CLI on PATH, the Mac app's bundled `codex-cli/codex-package.json`, the Windows Store app and an editor's `openai.chatgpt` extension, whose versions aren't known, a WSL distro's CLI): an older Codex takes every unknown `[features]` entry for a bool and won't load a config with the table ("invalid type: map, expected a boolean"). Otherwise, or with no Codex found, magpie writes the bare `[features]` `async_compaction = true`, which every Codex loads, and no threshold; a table magpie wrote before is taken out on the next `Sync`, and Settings' row names the Codex that held it (`CodexAsyncHeld`). Codex starts a background compaction only on a provider whose `capabilities.remote_compaction` is `"v2"`, which it gives OpenAI and Azure alone, so `[model_providers.magpie]` gets `capabilities = { remote_compaction = "v2" }` too, also when the user turned the feature on by hand (#2493); `putProvider` carries the table's capabilities over when it writes it again. What magpie wrote is in the stash under `codex.async`: a value the user set, or changed since, is never written over and stays when the switch goes off; a bare `async_compaction = true` the stash doesn't name as magpie's (`bool`), an inline or dotted table is the user's as written. | [`codex_async.go`](../../internal/agent/codex_async.go) |
|
||||
| Codex windows | Each magpie model's entry in Codex's catalog (`codexcat.entriesAt`, and `listedEntry` for a relay's own entry) says the model's whole window as `context_window`, which Codex shows (95% of it) as the conversation's context. Where Codex compacts goes in the entry's `auto_compact_token_limit`: the threshold set on the model or its provider, else Long conversations' (`settings.Working`, 272K by default), only when that is below the window; Full window writes none. A model whose window magpie doesn't know (a relay listing none, one models.dev lacks) gets no `context_window` and still the threshold as `auto_compact_token_limit` (Long conversations' Compact at, 272K by default; a relay's own entry only a user-set one, under its own window and limit): Codex compacts at no point on an entry with neither, and after the vendor's "too long" every turn errors again until a manual /compact (jiangguochao666 on X, 11-01; reproduced with real Codex 0.165 and a relay refusing past 100K, compacted at 80K after the fix). `TestCodexCompactsWithNoKnownWindow`. A vendor that lists a larger window than it takes is not caught: Codex compacts on that window's 90%, or the threshold. Codex 0.165 compacts at the lesser of it and 90% of the window, and a `model_auto_compact_token_limit` the user put in config.toml comes before it, as a `model_context_window` there replaces every model's window (Codex then compacts at 90% of it). Long conversations' row in Codex's opened card names either one, top-level or in the profile config.toml picks (`agent.CodexCompactHeld`, sent to the page as one line by `codexKeysText`), and Take it out deletes them (`DropCodexCompactHolds`); magpie never deletes them on its own, as the value is the user's (zgjfjfl on Discord, 10-31: 128000 there, 544K in Long conversations). No threshold above a model's window moves Codex either, which then compacts at 90% of it: the row names the model Codex's config runs (`agent.CodexModel`, the picked profile's first) and the window magpie tells Codex for it, when Long conversations doesn't come below it and no threshold is set on the model or its provider (`codexWindowUnder` in internal/gui/api.go; the reporter's model was a relay's gpt-6-A). `TestCodexCompactHeldNamedAndTakenOut`, `TestCodexWindowUnderLongConversations`, codex-compact-held.test.cjs. Until 10-30 the threshold went in `context_window` with the window as `max_context_window`, so a 1M model showed 258K in Codex (01huadalang on Discord); `max_context_window` stays a field magpie owns so `Keep` doesn't carry an old catalog's over. Codex's own models (`codex/`) keep their entry's window. `Tag` carries `catalogFormat`, so a Codex holding a list in the old shape asks again. `TestCodexCatalogCompactAt`, `TestCodexWindowShownCompactApart`. | [`codexcat.go`](../../internal/codexcat/codexcat.go) |
|
||||
| An agent's own Long conversations | Codex, Claude Code and Grok Build (`settings.CompactAgents`) can each have a Long conversations of their own over the one for every agent (molianyin4227 on Discord: models differ, so one size fits none): `settings.AgentCompacts[agent]` holds Compact at (`At`, 0 for the working window) or Full window (`Full`), and `Settings.ForAgent(agent)` lays it over `CompactAt`/`FullContext` for that agent's readers alone (`codexcat.entriesAt`, `codexListed`, `claudeIn`'s `writeCompact` and `desktopPlan`, `grokModelTables`, the route list's `buildModels`, Codex's window line and Tuned for you). A threshold set on a model or its provider still comes first. An agent with none follows the value for every agent, so an agent without the key (any agent outside the three) gets nothing new written. Set by `provider.SetAgentCompact` (`POST /api/settings/agent-compact` `{agent, own, full, at}`; `own` false takes it away), shown as a row under Long conversations in the agent's opened row and its sheet ("Long conversations in <agent>": Every agent, Compact at, Full window), drawn by `agentcompact.js`, which app.js imports when the agent's settings hold Long conversations. Tuned for you's Use on an agent with its own value changes that one and stashes it under `tune.long.compact.<agent>`. In a terminal, `magpie model compact <codex|claude|grok> [every|off|<size>]` (`agentCompact`, `TestModelCompactAgentCmd`). Not covered: t3code's route list reads the value for every agent. `TestSetAgentCompact`, `TestCodexCatalogCompactAt`, `TestGrokWindowFollowsLongConversations`, `TestClaudeCompactAt`, `TestTuneAgentOwnLong`, agent-compact.test.cjs. | [`settings.go`](../../internal/settings/settings.go), [`compact.go`](../../internal/provider/compact.go), [`agentcompact.js`](../../internal/gui/assets/agentcompact.js) |
|
||||
| Longest context | One cap on every model's window (`settings.ContextCap`, WJaunita45604 on X), in Settings › Models › Routing as Longest context (`renderContextCap`), `POST /api/settings/context-cap` `{at}` (0 takes it away), `magpie model context-cap [<size>\|off]`. It is a `min` against the vendor's listed window: `provider.windowIn` (`WindowOf`, `entryFor`, so /v1/models, every agent's catalog, group windows and the compaction thresholds derived from them) and, for Codex's own models, `CodexNativeWindow`, `CodexWindow` and `codexcat.Cap` on the list the gateway serves (`codexWindowsTag` carries the cap, so Codex asks again). A window the user set on a model, or `*` on its provider (`Contexts`), comes first and is not capped; a model whose window is unknown stays unknown. `Listed` in the provider editor is still the vendor's. Not covered: Claude Code's own `[1m]` choice (`claudeRunName`) and `agent/claude.go`'s fallback when a ref has no window. `TestContextCapHoldsEveryModelButTheOnesTheUserSet`, `TestModelsListContextCap`, `TestCapHoldsAnEntry`, `TestModelContextCapCmd`, context-cap.test.cjs. | [`settings.go`](../../internal/settings/settings.go), [`models.go`](../../internal/provider/models.go) |
|
||||
| Longest context | One cap on every model's window (`settings.ContextCap`, WJaunita45604 on X), in Settings › Models › Routing as Longest context (`renderContextCap`), `POST /api/settings/context-cap` `{at}` (0 takes it away), `magpie model context-cap [<size>\|off\|all\|own]`, and a menu beside it (`settings.ContextCapAll`, `POST /api/settings/context-cap-mode` `{all}`) for which windows it holds. It is a `min` against the vendor's listed window: `provider.windowIn` (`WindowOf`, `entryFor`, so /v1/models, every agent's catalog, group windows and the compaction thresholds derived from them) and, for Codex's own models, `CodexNativeWindow`, `CodexWindow` and `codexcat.Cap` on the list the gateway serves (`codexWindowsTag` carries the cap, so Codex asks again). A window the user set on a model, or `*` on its provider (`Contexts`), comes first and is not capped in the default mode (own: the user's word wins, longer or not); with `ContextCapAll` (`Settings.CappedOwn`) it is held to the cap too, so the shorter of the two is told in both modes; a model whose window is unknown stays unknown. `Listed` in the provider editor is still the vendor's. Not covered: Claude Code's own `[1m]` choice (`claudeRunName`) and `agent/claude.go`'s fallback when a ref has no window. `TestContextCapHoldsEveryModelButTheOnesTheUserSet`, `TestContextCapAllHoldsTheUsersOwnWindowsToo`, `TestModelsListContextCap`, `TestCapHoldsAnEntry`, `TestModelContextCapCmd`, context-cap.test.cjs. | [`settings.go`](../../internal/settings/settings.go), [`models.go`](../../internal/provider/models.go) |
|
||||
| Claude Code's prompt cache | Claude Code's opened row and sheet have, under its Long conversations, "Prompt cache · main conversation" and "Prompt cache · subagents" (Linka on Discord), each Claude Code's default, 5 min or 1 hour in the app menu (`claudeCacheRows` in `agentcompact.js`). They write the keys Tuned for you writes, `promptCacheTtl` and `subagentPromptCacheTtl` in Claude Code's settings.json (`agent.ClaudeCacheSet`, `POST /api/settings/claude-cache` `{knob, value}`; the values read back as `claudeCache` in `/api/settings`). Default takes the key out. A pick is the user's: it forgets the card's stash, so Undo leaves it. A variable that comes first (`FORCE_PROMPT_CACHING_5M`, `CLAUDE_CODE_PROMPT_CACHE_TTL`, `CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL`) disables the row and names it, and the route refuses. Claude Code 2.1.316 reads them in that order, then the setting, then an agent's `experimental.cacheTtl`, then `ENABLE_PROMPT_CACHING_1H`; unset, the main conversation takes 1 hour on a subscription within its limits and subagents 5 minutes. `TestClaudeCacheSet`, `TestClaudeCacheRoute`, claude-cache.test.cjs. | [`tune.go`](../../internal/agent/tune.go), [`agentcompact.js`](../../internal/gui/assets/agentcompact.js) |
|
||||
| Codex instructions | Each magpie model's entry in Codex's catalog carries the instructions official Codex sends that model, Codex's own text word for word; magpie writes none of its own and never changes the identity line (`codexcat.officialFor`). The model's slug (the id's last path segment, lowercased) is matched as Codex matches one, by the longest prefix of an official slug (`longestPrefix`; `auto/gpt-6.1-sol` takes gpt-6.1-sol's, `s2a/openai/gpt-6-luna-2026-09-14` gpt-6-luna's): first against the entries the user's ChatGPT account handed this Codex (`CacheEntries`, models_cache.json), whose `base_instructions` (else `model_messages.instructions_template`) and `model_messages` go over as sent; then against Codex's bundled catalog (`codex_instructions.json`, each model's `instructions_template` from openai/codex rust-v0.166.0's models-manager/models.json), the text only, as an older Codex may not read that release's `model_messages`. Any other model, and a routing group (`group/`), which may hand a turn to any model, takes Codex's prompt for a model it doesn't know (`Prompt`, models-manager/prompt.md), which is what official Codex sends it (`model_info_from_slug`). An entry Codex was handed with no `base_instructions` (`ownEntry`) takes its `model_messages.instructions_template`, else `Official`, and magpie's own ChatGPT-backend requests fall back to `Official` too (`codexInstructions` in internal/provider). Until 11-01 every third-party model was handed gpt-5.2-codex_prompt.md ("You are Codex, based on GPT-5"), so a magpie GPT-6 model ran on a GPT-5.2-era prompt (#3759, #4008, #4783). The Codex files are in testdata (`testdata/codex-rust-v0.166.0`), and `TestBundledIsCodexOwn` fails when the embedded copies differ from them; on a new Codex release copy its two files there and rebuild `codex_instructions.json`. Real Codex 0.166 against a capturing gateway sends the official text as its first developer message for a GPT-6 model and prompt.md for DeepSeek. `TestThirdPartyModelsTakeCodexOwnInstructions`, `TestThirdPartyModelsTakeCachedEntry`, `TestOwnEntryInstructions`. Not read: the bundled catalog inside the user's installed Codex binary. | [`codexcat.go`](../../internal/codexcat/codexcat.go) |
|
||||
| Codex: DeepSeek models | A DeepSeek model's entry (`codexcat.deepSeek`: deepseek-v4*, -flash, -pro, -chat, -reasoner after any provider or relay prefix; not a routing group, not a distill) takes what DeepSeek's own Codex setup (cdn.deepseek.com/api-docs/codex-deepseek-setup-en.sh, its models.json) says of its models: `shell_type` `shell_command` (Codex 0.165 reads it as `unified_exec`, its only shell; older Codex had a one-shot `shell_command` tool), `support_verbosity` with `default_verbosity` low, `default_reasoning_summary` none (no `reasoning.summary` sent), `multi_agent_version` v2, and `supports_image_detail_original` on a model whose entry takes images. Not taken: its `base_instructions`/`model_messages` (magpie never rewrites a Codex prompt), its `auto_compact_token_limit` null (magpie's 272K default stays, from e950eb080's DeepSeek latency report; Full window or the model's Compact at gives the whole window), `supports_search_tool` false on v4-pro (#258), its reasoning levels (the provider's). `default_reasoning_summary` is tagged `keep:"unset"`, so a value the user put in another model's entry stays (`Keep`). Other vendors' entries are unchanged. `TestCodexCatalogDeepSeekAsDeepSeekSays`, `TestCodexCatalogKeepsUsersSummary`. | [`codexcat.go`](../../internal/codexcat/codexcat.go) |
|
||||
|
||||
@@ -108,10 +108,12 @@ const modelUsage = `usage:
|
||||
settings on the Agents page,
|
||||
is the same switch; a provider's own Compact at (its
|
||||
editor) comes before it
|
||||
magpie model context-cap [<size>|off] the longest context window any model is told, such as 200k:
|
||||
magpie model context-cap [<size>|off|all|own] the longest context window any model is told, such as 200k:
|
||||
agents' lists and /v1/models say no more for every model
|
||||
that has no window of its own (magpie model context); a
|
||||
shorter or unknown window stays as it is. off takes it away
|
||||
shorter or unknown window stays as it is. off takes it away;
|
||||
all also holds a window you set for a model or its
|
||||
provider (the shorter is told), own leaves those alone
|
||||
magpie model compact <agent> [every|off|<size>] codex, claude or grok's own Long conversations: every
|
||||
follows the one above; off runs to the whole window; a
|
||||
size compacts there
|
||||
@@ -801,12 +803,26 @@ func modelCompact(args []string) error {
|
||||
func modelContextCap(args []string) error {
|
||||
if len(args) == 0 {
|
||||
if n := settings.Load().ContextCap; n > 0 {
|
||||
fmt.Println(bold.Render(tokenCount(n)), muted.Render("· no model is told a longer window, unless you set one for it or its provider · magpie model context-cap off"))
|
||||
fmt.Println(bold.Render(tokenCount(n)), muted.Render(map[bool]string{true: "· no model is told a longer window, one you set for it or its provider included · magpie model context-cap own", false: "· no model is told a longer window, unless you set one for it or its provider · magpie model context-cap all"}[settings.Load().ContextCapAll]), muted.Render("· magpie model context-cap off"))
|
||||
} else {
|
||||
fmt.Println("off", muted.Render("· every model takes its own window · magpie model context-cap <size>"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
switch strings.ToLower(args[0]) {
|
||||
case "all", "every":
|
||||
if err := provider.SetContextCapAll(true); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(green.Render("✓"), "the longest context also holds a window you set for a model or a provider (the shorter is told)")
|
||||
return nil
|
||||
case "own", "unset":
|
||||
if err := provider.SetContextCapAll(false); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(green.Render("✓"), "the longest context holds only models with no window of your own")
|
||||
return nil
|
||||
}
|
||||
var n int
|
||||
switch v := strings.ToLower(args[0]); v {
|
||||
case "off", "no", "none", "0":
|
||||
|
||||
@@ -2246,7 +2246,7 @@ func windowIn(served func() []provider.Entry, p provider.Provider, model string)
|
||||
return e.Context
|
||||
}
|
||||
}
|
||||
return p.ContextOf(model)
|
||||
return settings.Shared().CappedOwn(p.ContextOf(model))
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -1113,6 +1113,13 @@ func TestModelsListContextCap(t *testing.T) {
|
||||
if got := windows(); got["fake/m1"] != 200000 || got["fake/m2"] != 900000 {
|
||||
t.Fatalf("under a 200K cap: %v, want m1 200000 and m2's own 900000", got)
|
||||
}
|
||||
if err := provider.SetContextCapAll(true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { provider.SetContextCapAll(false) })
|
||||
if got := windows(); got["fake/m1"] != 200000 || got["fake/m2"] != 200000 {
|
||||
t.Fatalf("under a 200K cap on every model: %v, want both 200000", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelsListReasoning(t *testing.T) {
|
||||
|
||||
@@ -1901,6 +1901,20 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
}
|
||||
writeJSON(rw, settingsState())
|
||||
})
|
||||
// whether that longest context also holds a window the user set
|
||||
// (settings.ContextCapAll)
|
||||
mux.HandleFunc("POST /api/settings/context-cap-mode", func(rw http.ResponseWriter, r *http.Request) {
|
||||
var in struct{ All bool }
|
||||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
if err := provider.SetContextCapAll(in.All); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
writeJSON(rw, settingsState())
|
||||
})
|
||||
// an agent's own Long conversations (settings.AgentCompacts): Own
|
||||
// false follows the one for every agent again
|
||||
mux.HandleFunc("POST /api/settings/agent-compact", func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -1991,6 +1991,9 @@ const I18N = {
|
||||
"Compact at": "压缩阈值",
|
||||
"Longest context": "最长上下文",
|
||||
"Longest context: {v} is not a number of tokens like 272k": "最长上下文:{v} 不是 272k 这样的 token 数",
|
||||
"Longest context holds": "最长上下文生效于",
|
||||
"Every model": "每个模型",
|
||||
"Models without their own": "没有自带窗口的模型",
|
||||
"e.g. 500k · or deepseek-v4-flash=272k, comma separated": "如 500k · 或 deepseek-v4-flash=272k,逗号分隔",
|
||||
"Where Codex, Claude Code and Grok Build compact a long conversation on these models; empty follows Long conversations, in their settings on the Agents page (else in Settings), and a size at or above a model's window runs it to its whole window": "Codex、Claude Code 和 Grok Build 在这些模型上压缩长对话的位置;留空按 Agent 页里它们设置中的「长对话」(否则在「设置」里),大于等于模型窗口则用完整窗口",
|
||||
"Compact at: {v} is not a number of tokens like 272k": "压缩阈值:{v} 不是 272k 这样的 token 数",
|
||||
@@ -7023,6 +7026,9 @@ const I18N = {
|
||||
"Compact at": "壓縮閾值",
|
||||
"Longest context": "最長上下文",
|
||||
"Longest context: {v} is not a number of tokens like 272k": "最長上下文:{v} 不是 272k 這樣的 token 數",
|
||||
"Longest context holds": "最長上下文適用於",
|
||||
"Every model": "每個模型",
|
||||
"Models without their own": "沒有自帶視窗的模型",
|
||||
"e.g. 500k · or deepseek-v4-flash=272k, comma separated": "如 500k · 或 deepseek-v4-flash=272k,逗號分隔",
|
||||
"Where Codex, Claude Code and Grok Build compact a long conversation on these models; empty follows Long conversations, in their settings on the Agents page (else in Settings), and a size at or above a model's window runs it to its whole window": "Codex、Claude Code 和 Grok Build 在這些模型上壓縮長對話的位置;留空按 Agent 頁裡它們設定中的「長對話」(否則在「設定」裡),大於等於模型視窗則用完整視窗",
|
||||
"Compact at: {v} is not a number of tokens like 272k": "壓縮閾值:{v} 不是 272k 這樣的 token 數",
|
||||
@@ -12031,6 +12037,9 @@ const I18N = {
|
||||
"Compact at": "圧縮しきい値",
|
||||
"Longest context": "最長コンテキスト",
|
||||
"Longest context: {v} is not a number of tokens like 272k": "最長コンテキスト:{v} は 272k のようなトークン数ではありません",
|
||||
"Longest context holds": "最長コンテキストの対象",
|
||||
"Every model": "すべてのモデル",
|
||||
"Models without their own": "独自のウィンドウがないモデル",
|
||||
"e.g. 500k · or deepseek-v4-flash=272k, comma separated": "例:500k · または deepseek-v4-flash=272k(カンマ区切り)",
|
||||
"Where Codex, Claude Code and Grok Build compact a long conversation on these models; empty follows Long conversations, in their settings on the Agents page (else in Settings), and a size at or above a model's window runs it to its whole window": "Codex、Claude Code、Grok Build がこれらのモデルで長い会話を圧縮する位置です。空欄ならエージェントページのそれぞれの設定にある「長い会話」(なければ「設定」)に従い、モデルのウィンドウ以上ならウィンドウ全体を使います",
|
||||
"Compact at: {v} is not a number of tokens like 272k": "圧縮しきい値:{v} は 272k のようなトークン数ではありません",
|
||||
@@ -17070,6 +17079,9 @@ const I18N = {
|
||||
"Compact at": "Komprimieren ab",
|
||||
"Longest context": "Längster Kontext",
|
||||
"Longest context: {v} is not a number of tokens like 272k": "Längster Kontext: {v} ist keine Token-Zahl wie 272k",
|
||||
"Longest context holds": "Längster Kontext gilt für",
|
||||
"Every model": "Jedes Modell",
|
||||
"Models without their own": "Modelle ohne eigenes Fenster",
|
||||
"e.g. 500k · or deepseek-v4-flash=272k, comma separated": "z. B. 500k · oder deepseek-v4-flash=272k, durch Kommas getrennt",
|
||||
"Where Codex, Claude Code and Grok Build compact a long conversation on these models; empty follows Long conversations, in their settings on the Agents page (else in Settings), and a size at or above a model's window runs it to its whole window": "Wo Codex, Claude Code und Grok Build eine lange Unterhaltung bei diesen Modellen komprimieren; leer folgt Lange Unterhaltungen in ihren Einstellungen auf der Seite Agenten (sonst unter Einstellungen), ein Wert ab dem Fenster des Modells nutzt das ganze Fenster",
|
||||
"Compact at: {v} is not a number of tokens like 272k": "Komprimieren ab: {v} ist keine Token-Zahl wie 272k",
|
||||
|
||||
@@ -154,7 +154,23 @@ function renderContextCap(s) {
|
||||
};
|
||||
field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") field.blur(); if (e.key === "Escape") { field.value = s.contextCap ? contextsText({ "*": s.contextCap }) : ""; field.blur(); } };
|
||||
field.onchange = save;
|
||||
$("#contextCapVal").replaceChildren(field);
|
||||
// which windows it holds: only models with none of the user's own, or
|
||||
// every model (the shorter of the two is told; settings.ContextCapAll)
|
||||
const mode = el("button", "proto pick context-cap-mode");
|
||||
mode.type = "button";
|
||||
mode.setAttribute("aria-label", t("Longest context holds"));
|
||||
mode.replaceChildren(el("span", "", t(s.contextCapAll ? "Every model" : "Models without their own")), svg(CHEV, 11, 1.6));
|
||||
mode.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
if (mode.classList.contains("open")) return closeProtoMenu();
|
||||
openProtoMenu(mode, [{ v: "own", name: t("Models without their own") }, { v: "all", name: t("Every model") }], s.contextCapAll ? "all" : "own",
|
||||
(v) => { if ((v === "all") === !!s.contextCapAll) return; writingPrefs(api("settings/context-cap-mode", { all: v === "all" })).then((ns) => { prefs = state.settings = ns; renderSettings(); }).catch((er) => { status(t(er.message), "err"); renderSettings(); }); },
|
||||
"Longest context holds", "context-cap-menu");
|
||||
};
|
||||
const box = el("div", "");
|
||||
box.style.cssText = "display:flex;gap:8px;align-items:center;justify-content:flex-end";
|
||||
box.append(mode, field);
|
||||
$("#contextCapVal").replaceChildren(box);
|
||||
}
|
||||
|
||||
// renderCORS: the web pages whose scripts may call the gateway from a
|
||||
|
||||
@@ -30,6 +30,12 @@ function server(lang, posted) {
|
||||
cur = { ...cur, contextCap: body.at || undefined };
|
||||
return json(cur);
|
||||
}
|
||||
if (url.pathname === "/api/settings/context-cap-mode") {
|
||||
const body = req.postDataJSON();
|
||||
posted.push(["context-cap-mode", body]);
|
||||
cur = { ...cur, contextCapAll: body.all || undefined };
|
||||
return json(cur);
|
||||
}
|
||||
if (url.pathname === "/api/settings") {
|
||||
if (req.method() === "POST") posted.push(["settings", req.postDataJSON()]);
|
||||
return json(cur);
|
||||
@@ -46,8 +52,8 @@ function server(lang, posted) {
|
||||
}
|
||||
|
||||
const want = {
|
||||
en: { name: "Longest context", none: "None", bad: "Longest context: lots is not a number of tokens like 272k" },
|
||||
zh: { name: "最长上下文", none: "无", bad: "最长上下文:lots 不是 272k 这样的 token 数" },
|
||||
en: { all: "Every model", own: "Models without their own", name: "Longest context", none: "None", bad: "Longest context: lots is not a number of tokens like 272k" },
|
||||
zh: { all: "每个模型", own: "没有自带窗口的模型", name: "最长上下文", none: "无", bad: "最长上下文:lots 不是 272k 这样的 token 数" },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
@@ -87,6 +93,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await row.locator("input.context-cap").press("Enter");
|
||||
await page.waitForFunction(() => document.querySelector("#contextCapRow input")?.value === "");
|
||||
assert.deepEqual(posted.at(-1), ["context-cap", { at: 0 }]);
|
||||
const mode = row.locator("button.context-cap-mode");
|
||||
assert.equal((await mode.textContent()).trim(), w.own);
|
||||
await mode.click();
|
||||
await page.locator(".context-cap-menu [role=menuitemradio], .context-cap-menu button").filter({ hasText: w.all }).first().click();
|
||||
await page.waitForFunction((x) => document.querySelector("#contextCapRow .context-cap-mode")?.textContent.trim() === x, w.all);
|
||||
assert.deepEqual(posted.at(-1), ["context-cap-mode", { all: true }]);
|
||||
assert(!posted.some((p) => p[0] === "settings"), "set on its own, not with the other preferences");
|
||||
assert.equal(await view(), before, "typing scrolled the page");
|
||||
assert(await row.boundingBox().then((b) => b.height < 80), "the row stays one line");
|
||||
|
||||
@@ -840,7 +840,7 @@ func CodexNativeWindow(restore bool) func(slug string) (n, most int, ok bool) {
|
||||
capped := settings.Shared()
|
||||
return func(slug string) (int, int, bool) {
|
||||
if n := p.ContextOf(slug); n > 0 {
|
||||
return n, 0, true
|
||||
return capped.CappedOwn(n), 0, true
|
||||
}
|
||||
if !restore {
|
||||
return 0, 0, false
|
||||
@@ -868,10 +868,10 @@ func CodexNativeWindow(restore bool) func(slug string) (n, most int, ok bool) {
|
||||
// Codex Plus account.
|
||||
func CodexWindow(user, slug string) int {
|
||||
p, _ := find(All(), "codex")
|
||||
if n := p.ContextOf(slug); n > 0 {
|
||||
return n
|
||||
}
|
||||
capped := settings.Shared()
|
||||
if n := p.ContextOf(slug); n > 0 {
|
||||
return capped.CappedOwn(n)
|
||||
}
|
||||
var lists [][]catalog.Model
|
||||
if user != "" {
|
||||
if live, _, ok := catalog.Live(accountModels("codex", user)); ok {
|
||||
@@ -899,7 +899,11 @@ func codexWindowsTag() []catalog.Model {
|
||||
p, _ := find(All(), "codex")
|
||||
var out []catalog.Model
|
||||
if n := settings.Shared().ContextCap; n > 0 {
|
||||
out = append(out, catalog.Model{ID: "~cap", Context: n})
|
||||
id := "~cap"
|
||||
if settings.Shared().ContextCapAll {
|
||||
id = "~capall"
|
||||
}
|
||||
out = append(out, catalog.Model{ID: id, Context: n})
|
||||
}
|
||||
for _, k := range slices.Sorted(maps.Keys(p.Contexts)) {
|
||||
out = append(out, catalog.Model{ID: "=" + k, Context: p.Contexts[k]})
|
||||
|
||||
@@ -285,6 +285,21 @@ func SetCompactAt(n int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetContextCapAll chooses whether the longest context (SetContextCap) also
|
||||
// holds a window the user set for a model or its provider.
|
||||
func SetContextCapAll(all bool) error {
|
||||
s := settings.Load()
|
||||
if s.ContextCapAll == all {
|
||||
return nil
|
||||
}
|
||||
s.ContextCapAll = all
|
||||
if err := settings.Save(s); err != nil {
|
||||
return err
|
||||
}
|
||||
catalog.Touched()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetContextCap holds every model's window to n tokens at most
|
||||
// (settings.ContextCap), where the user set none for the model or its
|
||||
// provider; 0 takes the cap away. Agents' lists are written again.
|
||||
|
||||
@@ -63,3 +63,41 @@ func TestContextCapHoldsEveryModelButTheOnesTheUserSet(t *testing.T) {
|
||||
t.Fatalf("cap off: %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
// Both modes of the longest context: a window the user set that is shorter
|
||||
// than the cap is told as it is; a longer one stays in "own" mode and comes
|
||||
// down to the cap in "all" mode (WJaunita45604 on X).
|
||||
func TestContextCapAllHoldsTheUsersOwnWindowsToo(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
catalog.Changed = nil
|
||||
long := catalog.Model{ID: "long", Context: 1_000_000}
|
||||
own := Provider{ID: "a", Contexts: map[string]int{"long": 500_000}}
|
||||
wild := Provider{ID: "a", Contexts: map[string]int{"*": 400_000}}
|
||||
small := Provider{ID: "a", Contexts: map[string]int{"long": 100_000}}
|
||||
if err := SetContextCap(200_000); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check := func(mode string, want [4]int) {
|
||||
t.Helper()
|
||||
for i, p := range []Provider{{ID: "a"}, own, wild, small} {
|
||||
if got := p.WindowOf(long); got != want[i] {
|
||||
t.Errorf("%s, provider %d: %d, want %d", mode, i, got, want[i])
|
||||
}
|
||||
if got := entryFor(p, long, settings.Load()).Context; got != want[i] {
|
||||
t.Errorf("%s, provider %d: entry %d, want %d", mode, i, got, want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
check("own", [4]int{200_000, 500_000, 400_000, 100_000})
|
||||
if err := SetContextCapAll(true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check("all", [4]int{200_000, 200_000, 200_000, 100_000})
|
||||
if err := SetContextCapAll(false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check("own again", [4]int{200_000, 500_000, 400_000, 100_000})
|
||||
}
|
||||
|
||||
@@ -3724,17 +3724,18 @@ func (p Provider) WindowIn(m catalog.Model, s settings.Settings) int { return p.
|
||||
|
||||
// windowIn is WindowOf under settings s: a window the user typed, for the
|
||||
// model or for all the provider's (which is no larger than the model's own
|
||||
// where it says), is theirs as it is; any other is held to the longest
|
||||
// context the user set for every model (settings.ContextCap).
|
||||
// where it says), is theirs as it is, or held to the longest context too
|
||||
// when the user chose that (settings.ContextCapAll); any other is held to
|
||||
// the longest context the user set for every model (settings.ContextCap).
|
||||
func (p Provider) windowIn(m catalog.Model, s settings.Settings) int {
|
||||
if n := p.Contexts[m.ID]; n > 0 {
|
||||
return n
|
||||
return s.CappedOwn(n)
|
||||
}
|
||||
if n := p.Contexts["*"]; n > 0 {
|
||||
if most := max(catalog.Window(m.Context), m.MaxContext); most > 0 && most < n {
|
||||
return most
|
||||
return s.CappedOwn(most)
|
||||
}
|
||||
return n
|
||||
return s.CappedOwn(n)
|
||||
}
|
||||
return s.Capped(ListedWindow(m))
|
||||
}
|
||||
|
||||
@@ -867,6 +867,10 @@ type Settings struct {
|
||||
// each model's (WJaunita45604 on X). 0 is no cap. It only lowers: a
|
||||
// model whose window is shorter, or not known, is told what it was.
|
||||
ContextCap int `json:"contextCap,omitempty"`
|
||||
// ContextCapAll makes ContextCap hold a window the user set themselves
|
||||
// too (a model's, or its provider's "*"): the shorter of the two is
|
||||
// told. Off, the user's own window wins even when it is longer.
|
||||
ContextCapAll bool `json:"contextCapAll,omitempty"`
|
||||
// AgentCompacts is Long conversations of an agent's own, by its kind
|
||||
// (CompactAgents), over CompactAt and FullContext for that agent alone
|
||||
// (molianyin4227 on Discord: models differ, so one size for every
|
||||
@@ -1502,6 +1506,15 @@ func (s Settings) Capped(n int) int {
|
||||
return n
|
||||
}
|
||||
|
||||
// CappedOwn is a window n the user set themselves under ContextCap: as it
|
||||
// was unless ContextCapAll, then no longer than the cap.
|
||||
func (s Settings) CappedOwn(n int) int {
|
||||
if s.ContextCapAll {
|
||||
return s.Capped(n)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// Working is the context window an agent is told for a model with one of
|
||||
// n tokens (see FullContext).
|
||||
func (s Settings) Working(n int) int {
|
||||
|
||||
@@ -344,6 +344,7 @@ func Merge(body []byte, cur settings.Settings, web bool) (settings.Settings, err
|
||||
in.CompactAt = cur.CompactAt // and so is the threshold
|
||||
in.AgentCompacts = cur.AgentCompacts // and each agent's own (agent-compact)
|
||||
in.ContextCap = cur.ContextCap // and the longest window of every model (context-cap)
|
||||
in.ContextCapAll = cur.ContextCapAll // and whether it holds the user's own windows
|
||||
// Codex's background compaction, set on its own (codex-async-compact)
|
||||
in.CodexAsyncCompact, in.CodexAsyncCompactPercent = cur.CodexAsyncCompact, cur.CodexAsyncCompactPercent
|
||||
// Claude Desktop's list, set in its row on the Agents page
|
||||
|
||||
Reference in New Issue
Block a user