The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(tokens): match dotted claude versions in the context window table (#1051)
Rudy Mizrahi Celekli71ef441cf58e
diff --git a/cli/beacon/internal/pricing/lookup.go b/cli/beacon/internal/pricing/lookup.goindex 4c8310fb..94ed7a5f 100644--- a/cli/beacon/internal/pricing/lookup.go+++ b/cli/beacon/internal/pricing/lookup.go@@ -3,6 +3,7 @@ package pricingimport ("reflect""regexp"+ "slices""sort""strings"@@ -134,6 +135,19 @@ func spell(r rung, s string) string {return s}+// Spellings returns the ways the catalog compares model, from closest to the original to most+// reduced: canonical (lowercased, provider prefix dropped), with version dots folded, and with a+// Bedrock route removed. Repeats are dropped, and an empty model has none.+func Spellings(model string) []string {+ var out []string+ for r := rungCanonical; r < numRungs; r++ {+ if s := spell(r, model); s != "" && !slices.Contains(out, s) {+ out = append(out, s)+ }+ }+ return out+}+// bedrockRegions are the inference-profile prefixes Bedrock puts in front of a model id.var bedrockRegions = []string{"us-gov.", "global.", "apac.", "us.", "eu.", "au.", "jp."}diff --git a/cli/beacon/internal/tokens/contextwindow.go b/cli/beacon/internal/tokens/contextwindow.goindex 787efa50..c79e122d 100644--- a/cli/beacon/internal/tokens/contextwindow.go+++ b/cli/beacon/internal/tokens/contextwindow.go@@ -1,6 +1,10 @@package tokens-import "strings"+import (+ "strings"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/pricing"+)// contextWindows maps normalized model-name prefixes to context window sizes// in tokens. Longest prefix wins. The table is a best-effort static snapshot;@@ -52,29 +56,21 @@ var contextWindows = []struct {{"gemini-3", 1048576},}-// ContextWindow returns the context window size for a model name, matching-// provider-prefixed and date-suffixed variants such as-// "anthropic/claude-sonnet-4-5" or "gpt-4o-2024-08-06".+// ContextWindow returns the context window size for a model name, matching provider-prefixed,+// dotted, Bedrock-routed and date-suffixed variants such as "anthropic/claude-sonnet-4-5",+// "claude-sonnet-4.6", "us.anthropic.claude-sonnet-4-6-v1:0" or "gpt-4o-2024-08-06".func ContextWindow(model string) (int64, bool) {- normalized := normalizeModel(model)- if normalized == "" {- return 0, false- }best := int64(0)bestLen := -1- for _, entry := range contextWindows {- if strings.HasPrefix(normalized, entry.prefix) && len(entry.prefix) > bestLen {- best = entry.tokens- bestLen = len(entry.prefix)+ // Every spelling is tried, not only the most reduced, because the table keeps dotted ids of+ // its own (gpt-4.1) that folding would turn into ids no vendor uses.+ for _, spelling := range pricing.Spellings(model) {+ for _, entry := range contextWindows {+ if strings.HasPrefix(spelling, entry.prefix) && len(entry.prefix) > bestLen {+ best = entry.tokens+ bestLen = len(entry.prefix)+ }}}return best, bestLen >= 0}--func normalizeModel(model string) string {- normalized := strings.ToLower(strings.TrimSpace(model))- if idx := strings.LastIndex(normalized, "/"); idx >= 0 {- normalized = normalized[idx+1:]- }- return normalized-}diff --git a/cli/beacon/internal/tokens/contextwindow_test.go b/cli/beacon/internal/tokens/contextwindow_test.goindex 065d8804..ebdcbb17 100644--- a/cli/beacon/internal/tokens/contextwindow_test.go+++ b/cli/beacon/internal/tokens/contextwindow_test.go@@ -51,6 +51,29 @@ func TestContextWindowDoesNotConfuseAdjacentClaudeVersions(t *testing.T) {}}+// Copilot and OpenRouter report Claude models with a dotted version, and Bedrock with a route+// around the id. They have the window of the dashed id, not the 200K "claude" fallback or none.+func TestContextWindowMatchesDottedClaudeVersions(t *testing.T) {+ for _, tc := range []struct {+ model string+ want int64+ }{+ {"claude-sonnet-4.6", 1000000},+ {"claude-opus-4.7", 1000000},+ {"claude-haiku-4.5", 200000},+ {"gpt-4.1", 1047576},+ {"openrouter/anthropic/claude-opus-4.6", 1000000},+ {"us.anthropic.claude-sonnet-4-6-v1:0", 1000000},+ {"global.anthropic.claude-haiku-4-5-20251001-v1:0", 200000},+ {"gpt-4-1106-preview", 8192},+ } {+ got, known := ContextWindow(tc.model)+ if !known || got != tc.want {+ t.Errorf("ContextWindow(%q) = %d/%v, want %d/true", tc.model, got, known, tc.want)+ }+ }+}+// An unknown model must stay unknown rather than being given a plausible-looking window.// A wrong window does not read as missing data; it reads as a confident ratio, and the// near-limit counter fires on it.