Skip to content

Commit 991ec1b

Browse files
committed
serving: honor the auth wizard's choice and say who served the turn
An explicitly selected subscription source (memcode auth claude/codex/ copilot/grok) now outranks a stored memcode login at boot. Before, the wizard printed 'using your claude subscription' while the org-key login silently kept every turn on the hosted gateway — the user had no way to tell. Ambient endpoints and exported keys still lose to a login; only the wizard-consented path gets precedence. The served-by line now names the credential in endpoint mode: 'served by sonnet via claude'.
1 parent 81f118a commit 991ec1b

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎internal/agent/runtime/loop.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,12 @@ func (s *Session) complete(ctx context.Context, purpose llm.Purpose, req wire.Re
11751175
name = provider.ShortModel(resp.Model)
11761176
}
11771177
line := "⇄ served by " + name
1178+
// In endpoint mode, say WHOSE credential served the turn ("via claude" =
1179+
// the Claude subscription, "via chatgpt" = Codex, a custom endpoint by
1180+
// its name) — the one-line answer to "is this really on my sub?".
1181+
if ep, ok := s.Endpoint(); ok && ep.Name != "" {
1182+
line += " via " + provider.ServingLabel(ep.Name)
1183+
}
11781184
// Why this turn isn't on the pool — the dogfooding instrument for the 80/20 flip.
11791185
// "thinking"/"planner"/"vision" = deterministic policy; "escalate:<reason>" = a
11801186
// routing_hint; "cheap_lane_error"/"cheap_lane_overflow"/… = a real fallback. A drift back toward

‎internal/provider/credsource.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,40 @@ func discoverCredentialEndpoint() (Endpoint, bool) {
102102
return Endpoint{}, false
103103
}
104104

105+
// ServingLabel maps an endpoint's internal name to the word a user chose in
106+
// the auth wizard — the "via X" in the TUI's served-by line. Empty for
107+
// endpoints that aren't a subscription source (their Name already reads fine).
108+
func ServingLabel(name string) string {
109+
switch name {
110+
case "claude-sub":
111+
return "claude"
112+
case "codex":
113+
return "chatgpt"
114+
case "copilot":
115+
return "copilot"
116+
case "grok-sub":
117+
return "grok"
118+
}
119+
return name
120+
}
121+
122+
// SubscriptionEndpointName reports whether an endpoint name is one of the
123+
// wizard-selected subscription sources (vs a custom endpoint or own key).
124+
func SubscriptionEndpointName(name string) bool {
125+
switch name {
126+
case "claude-sub", "codex", "copilot", "grok-sub":
127+
return true
128+
}
129+
return false
130+
}
131+
132+
// ExplicitCredentialSource reports the user has actively selected a
133+
// credential source (memcode auth …) — the consent signal that lets a
134+
// subscription login outrank other backends.
135+
func ExplicitCredentialSource() bool {
136+
return strings.TrimSpace(os.Getenv(EnvCredentialSource)) != ""
137+
}
138+
105139
// sourceModel resolves a subscription source's initial model: an explicit
106140
// MEMCODE_ENDPOINT_MODEL override wins, else the source's sensible default so a
107141
// subscription "just works" with no configuration. The /model picker changes it

‎internal/provider/provider.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,17 @@ func NewFromEnvLazy(endpoints ...Endpoint) *Lazy {
265265
// the endpoint instead of dead air (backend selection re-applies).
266266
l.fallback.Store(&ep)
267267
}
268+
// An EXPLICITLY selected subscription source (memcode auth claude/codex/…)
269+
// outranks a stored memcode login: the user just chose where turns should
270+
// be served, and silently ignoring that choice made the auth wizard a lie
271+
// (it printed "using your claude subscription" while the gateway kept
272+
// serving). Ambient endpoints and own keys still lose to a login — only
273+
// the wizard-consented subscription path gets this precedence.
274+
if ep := l.fallback.Load(); ep != nil &&
275+
ExplicitCredentialSource() && SubscriptionEndpointName(ep.Name) {
276+
l.c.Store(dialEndpoint(*ep))
277+
return l
278+
}
268279
if token := os.Getenv(EnvAPIToken); strings.HasPrefix(token, TokenPrefix) {
269280
l.c.Store(dial(APIURL(), token))
270281
} else if ep := l.fallback.Load(); ep != nil {

0 commit comments

Comments
 (0)