Files
magpie/internal/usage/purpose.go
T
congee949 b6831d83e1 gateway, gui: Codex's thread descriptions go to a model picked in Settings, apart from its titles (#1198, congee949)
Codex asks its own model, through its ChatGPT sign-in, for each thread's
description (thread_description), even while the conversation runs on
magpie's models. Settings › General gets "Codex thread descriptions"
beside "Codex thread titles". It defaults to Codex's own, which sends the
request as Codex sent it, or it can name one of magpie's models or a
routing group. The answer is wrapped as description-only JSON. The titles
setting is untouched. Usage and Routing show these requests under their
own Description purpose. The setting is kept across unrelated Settings
saves. There is no Off yet, because Codex's handling of an empty
description hasn't been checked. This is a first slice of #742.

Squashed from the PR and merged onto current main. Conflicts resolved:
- codex_backend.go: the description branch comes after the title branch,
  ahead of main's subagent pick.
- gateway.go: main's CC Switch #1301 comment above the compaction block is
  kept; the PR had shortened it.
- app.js: the gateway-mode list of hidden rows takes the new row.
- i18n.js and settings_keep_test.go: both sides kept.
- purposes.js: regenerated with go generate ./internal/usage.

Run on the merged tree:
- gofmt -l is clean.
- go vet passes on darwin, linux -tags nogui and windows; the builds on
  all three succeed.
- go test -tags nogui passes for ./internal/gateway, ./internal/gui,
  ./internal/settings and ./internal/usage.
- GUI, chromium and webkit: codex-titles, gateway-mode, purpose-filter,
  routing-purpose-state, gui-de, gui-ja, gui-zh-tw, i18n-keys,
  settings-general/-groups/-sections/-search and click-scroll: 118/118.

Broken by hand: with the description branch removed from codexBackend and
handle, TestCodexDescriptionsSetting, TestCodexDescriptionFallbackOnMagpie
and TestNoDescription fail.

Not tried: a real Codex thread_description request, and whether Codex's
sidebar takes the answer.
2026-10-13 10:13:15 +08:00

51 lines
1.7 KiB
Go

package usage
import "maps"
//go:generate go run ../gui/genpurposes -out ../gui/assets/purposes.js
// PurposeKind is the shared filtering key and untranslated display name of a kind.
type PurposeKind struct {
Purpose string `json:"purpose"`
Name string `json:"name"`
}
var purposeKinds = func() map[string]PurposeKind {
out := map[string]PurposeKind{}
add := func(name string, kinds ...string) {
for _, kind := range kinds {
out[kind] = PurposeKind{"kind:" + kinds[0], name}
}
}
add("Approval check", "guardian", "auto_review", "guardian_review")
add("Review", "review")
add("Compaction", "compact")
add("Memory", "memory_consolidation", "memgen", "memory")
add("Title", "thread_title", "thread_title_reconsideration", "title_generation", "title")
add("Description", "thread_description")
add("Subagent", "collab_spawn", "thread_spawn", "agent_job")
add("Luna Reserve", "luna_reserve")
add("Suggestions", "ambient_suggestions", "ambient_suggestion_safety")
add("Web search", "web_search")
add("Image description", "vision")
add("Routing classifier", "routing")
return out
}()
// PurposeKinds returns a copy of the catalog used to generate the UI's catalog.
// Add aliases here, then run go generate ./internal/usage from the repo root.
func PurposeKinds() map[string]PurposeKind { return maps.Clone(purposeKinds) }
// PurposeOf groups the agent's equivalent call-kind spellings for filtering.
// The recorded Kind stays untouched. Prefixing nonempty kinds keeps future
// names distinct from the unmarked bucket (which is not necessarily a chat).
func PurposeOf(kind string) string {
if kind == "" {
return "unmarked"
}
if p, ok := purposeKinds[kind]; ok {
return p.Purpose
}
return "kind:" + kind
}