Skip to content

Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.

List Codex's own models instead of a fixed three (#33)

Eduardo Machado00436431bc3c
diff --git a/src/core/engines/detect.ts b/src/core/engines/detect.ts
index 746b90f..4104301 100644
--- a/src/core/engines/detect.ts
+++ b/src/core/engines/detect.ts
@@ -1,6 +1,6 @@
import { execFile } from 'node:child_process'
import { access, constants } from 'node:fs/promises'
-import { existsSync } from 'node:fs'
+import { existsSync, readFileSync } from 'node:fs'
import { homedir } from 'node:os'
import { join } from 'node:path'
import { L } from '../../shared/lang'
@@ -110,6 +110,42 @@ export async function detectCodex(home: string): Promise<EngineStatus> {
}
}
+// The models Codex offers this login, newest first, from its own catalog: `codex debug models`
+// (its cache when that command isn't there). Hidden ones (internal, retired) are left out.
+export interface CodexModel {
+ slug: string
+ label: string
+ description?: string
+}
+
+export function parseCodexCatalog(json: string): CodexModel[] {
+ try {
+ const d = JSON.parse(json) as { models?: unknown } | unknown[]
+ const list = (Array.isArray(d) ? d : Array.isArray(d.models) ? d.models : []) as { slug?: unknown; display_name?: unknown; description?: unknown; visibility?: unknown; priority?: unknown }[]
+ return list
+ .filter((m) => typeof m.slug === 'string' && m.slug && (m.visibility === undefined || m.visibility === 'list'))
+ .sort((a, b) => (Number(a.priority) || 999) - (Number(b.priority) || 999))
+ .map((m) => ({
+ slug: m.slug as string,
+ label: typeof m.display_name === 'string' && m.display_name ? m.display_name : (m.slug as string),
+ ...(typeof m.description === 'string' && m.description ? { description: m.description } : {})
+ }))
+ } catch {
+ return []
+ }
+}
+
+export async function codexModels(path: string, home: string): Promise<CodexModel[]> {
+ const r = await run(path, ['debug', 'models'], 15_000, codexEnv(home))
+ const list = r.code === 0 ? parseCodexCatalog(r.stdout) : []
+ if (list.length) return list
+ try {
+ return parseCodexCatalog(readFileSync(join(home, '.codex', 'models_cache.json'), 'utf8'))
+ } catch {
+ return []
+ }
+}
+
// OpenCode and Pi keep their own logins and providers; what they list is what
// the person can use, so the list is the status. Their models go to `listed`.
const providerName = (id: string): string => ({ openai: 'OpenAI', anthropic: 'Anthropic', openrouter: 'OpenRouter', google: 'Google', opencode: 'OpenCode', 'opencode-go': 'OpenCode Go', 'openai-codex': 'ChatGPT', 'github-copilot': 'Copilot' })[id] ?? id
@@ -179,9 +215,17 @@ export async function detectGemini(): Promise<{ status: EngineStatus; models: st
}
}
-export async function detectEngines(codexHome: string): Promise<{ engines: Record<EngineId, EngineStatus>; listed: Partial<Record<EngineId, string[]>> }> {
+export async function detectEngines(codexHome: string): Promise<{ engines: Record<EngineId, EngineStatus>; listed: Partial<Record<EngineId, string[]>>; codexCatalog: CodexModel[] }> {
// A CLI installed while the app is open may have created its folder just now.
process.env['PATH'] = withInstallDirs(process.env['PATH'] ?? '')
+ // Codex's catalog is read alongside (it can take a couple of seconds), used once the login is known.
+ const catalog = which('codex').then((p) => (p ? codexModels(p, codexHome) : []))
const [claude, codex, opencode, pi, gemini] = await Promise.all([detectClaude(), detectCodex(codexHome), detectOpenCode(), detectPi(), detectGemini()])
- return { engines: { claude, codex, opencode: opencode.status, pi: pi.status, gemini: gemini.status }, listed: { opencode: opencode.models, pi: pi.models, gemini: gemini.models } }
+ // A gateway serves its own list (asked when picking); a plan or an API key gets Codex's catalog.
+ const codexCatalog = codex.loggedIn && codex.route !== 'gateway' ? await catalog : []
+ return {
+ engines: { claude, codex, opencode: opencode.status, pi: pi.status, gemini: gemini.status },
+ listed: { opencode: opencode.models, pi: pi.models, gemini: gemini.models, ...(codexCatalog.length ? { codex: codexCatalog.map((m) => m.slug) } : {}) },
+ codexCatalog
+ }
}
diff --git a/src/core/index.ts b/src/core/index.ts
index bb92c0c..53bc893 100644
--- a/src/core/index.ts
+++ b/src/core/index.ts
@@ -9,7 +9,7 @@ import { randomUUID } from 'node:crypto'
import type { MessagePortMain } from 'electron'
import { L, langOf, locale, setLang, type Lang } from '../shared/lang'
import type { Api, CoreEvent, Method, Request, Wire } from '../shared/rpc'
-import { channelName, ENGINES, inQuietHours, modelInfo, WEBHOOK_PORT, type Agent, type BrowserReply, type Message, type EngineId, type EngineStatus, type Settings } from '../shared/types'
+import { channelName, ENGINES, inQuietHours, modelInfo, rememberModels, WEBHOOK_PORT, type Agent, type BrowserReply, type Message, type EngineId, type EngineStatus, type Settings } from '../shared/types'
import { listModels, quietClaude, quietCodex, withChoice } from './harness'
import { Db } from './db'
import { claudeEngine, userProvider } from './engines/claude'
@@ -17,7 +17,7 @@ import { codexEngine, userCodexProvider } from './engines/codex'
import { opencodeEngine } from './engines/opencode'
import { piEngine } from './engines/pi'
import { geminiAppDir, geminiEngine } from './engines/gemini'
-import { adoptLoginShellPath, detectEngines } from './engines/detect'
+import { adoptLoginShellPath, detectEngines, type CodexModel } from './engines/detect'
import { fakeEngine } from './engines/fake'
import type { Engine } from './engines/types'
import { ConnectorManager } from './connectors'
@@ -81,13 +81,16 @@ const unknownEngine: EngineStatus = { installed: false, loggedIn: false }
let engines: Record<EngineId, EngineStatus> = { claude: unknownEngine, codex: unknownEngine, opencode: unknownEngine, pi: unknownEngine, gemini: unknownEngine }
// The models OpenCode and Pi list (what the person has logins for), from the last check.
let listed: Partial<Record<EngineId, string[]>> = {}
+// Codex's own catalog for this login (names and what each model is for), from the last check.
+let codexCatalog: CodexModel[] = []
const fakeStatus = (v: string): EngineStatus => ({ installed: true, loggedIn: true, path: 'fake', version: v, account: L('Motor de teste', 'Test engine'), route: 'plan' })
async function detect(): Promise<void> {
if (fake) {
engines = { claude: fakeStatus('0.0.0'), codex: fakeStatus('0.0.0'), opencode: { ...fakeStatus('0.0.0'), route: 'providers', account: 'OpenAI, OpenCode · 3 modelos' }, pi: { installed: false, loggedIn: false }, gemini: { installed: false, loggedIn: false } }
listed = { opencode: ['openai/gpt-5.5', 'opencode/big-pickle', 'opencode-go/qwen3.8-max'] }
- } else ({ engines, listed } = await detectEngines(codexHome))
+ } else ({ engines, listed, codexCatalog } = await detectEngines(codexHome))
+ rememberModels(codexCatalog.map((m) => ({ id: m.slug, engine: 'codex', label: m.label, hint: m.description ?? '' })))
gatewayLists.clear()
emit({ type: 'settings', settings: settings() })
}
@@ -647,6 +650,8 @@ const api: Api = {
// The models a harness offers, besides the app's list for a plan: what OpenCode
// and Pi list, or what the gateway in Claude Code's or Codex's config lists.
engineModels: async ({ engine }) => {
+ if (engine === 'codex' && codexCatalog.length)
+ return { models: codexCatalog.map((m) => m.slug), labels: Object.fromEntries(codexCatalog.map((m) => [m.slug, { label: m.label, ...(m.description ? { hint: m.description } : {}) }])) }
if (listed[engine]) return { models: listed[engine]! }
if (engines[engine].route !== 'gateway') return { models: [] }
if (!gatewayLists.has(engine))
diff --git a/src/core/tuca.ts b/src/core/tuca.ts
index 2240577..dada590 100644
--- a/src/core/tuca.ts
+++ b/src/core/tuca.ts
@@ -4,7 +4,7 @@
// person creates it. He has no connectors, no web and no computer of his own.
import { randomUUID } from 'node:crypto'
import { L } from '../shared/lang'
-import { ENGINES, MODELS, modelInfo, type Agent, type AgentColor, type AgentDraft, type Connector, type Effort, type GrantLevel, type Settings } from '../shared/types'
+import { codexValue, ENGINES, MODELS, modelInfo, type Agent, type AgentColor, type AgentDraft, type Connector, type Effort, type GrantLevel, type Settings } from '../shared/types'
import type { ToolDef } from './gateway'
const COLORS: AgentColor[] = ['sky', 'indigo', 'violet', 'rose', 'amber', 'green', 'teal', 'graphite']
@@ -71,7 +71,11 @@ export const PROPOR_AGENTE: ToolDef = {
// The models agents can run on now: the listed ones of a ready plan, and what OpenCode and Pi list.
export function availableModels(s: Pick<Settings, 'engines'>, listed: Partial<Record<string, string[]>> = {}): { id: string; label: string }[] {
- const plan = MODELS.filter((m) => s.engines[m.engine].loggedIn && s.engines[m.engine].route !== 'gateway').map((m) => ({ id: m.id, label: `${ENGINES[m.engine].label} · ${m.label}` }))
+ // Codex's own catalog when there is one (newest first); the app's list otherwise.
+ const codex = listed['codex']?.length ? listed['codex'].map((slug) => modelInfo(codexValue(slug)) ?? { id: slug, engine: 'codex' as const, label: slug, hint: '' }) : undefined
+ const plan = [...MODELS.filter((m) => m.engine !== 'codex' || !codex), ...(codex ?? []).map((m) => ({ ...m, id: codexValue(m.id) }))]
+ .filter((m) => s.engines[m.engine].loggedIn && s.engines[m.engine].route !== 'gateway')
+ .map((m) => ({ id: m.id, label: `${ENGINES[m.engine].label} · ${m.label}` }))
const own = (['opencode', 'pi'] as const).flatMap((e) => (s.engines[e].loggedIn ? (listed[e] ?? []).slice(0, 12).map((name) => ({ id: `${e}:${name}`, label: `${ENGINES[e].label} · ${name}` })) : []))
return [...plan, ...own]
}
diff --git a/src/renderer/src/components/Harness.tsx b/src/renderer/src/components/Harness.tsx
index 2849a54..11c05af 100644
--- a/src/renderer/src/components/Harness.tsx
+++ b/src/renderer/src/components/Harness.tsx
@@ -9,6 +9,7 @@ import {
ENGINE_IDS,
MODELS,
startsPicked,
+ codexValue,
customModel,
engineModels,
harnessMcps,
@@ -17,6 +18,7 @@ import {
loginEngine,
modelInfo,
openExternal,
+ rememberModels,
testEngine,
updateSettings,
useStore,
@@ -41,26 +43,39 @@ export interface ModelOption {
}
// A model list asked once per harness and route (and again after "Verificar de novo").
-const lists = new Map<string, Promise<{ models: string[]; error?: string }>>()
+type Listed = { models: string[]; labels?: Record<string, { label: string; hint?: string }>; error?: string }
+const lists = new Map<string, Promise<Listed>>()
-// What a harness offers: the app's list on a plan; what OpenCode or Pi list; what the gateway lists.
+// What a harness offers: the app's list on Claude's plan; Codex's own catalog (newest first);
+// what OpenCode or Pi list; what the gateway lists.
export function useEngineModels(engine: EngineId | undefined): { options: ModelOption[]; loading: boolean; error?: string } {
const st = useStore((s) => (engine ? s.settings.engines[engine] : undefined))
const plan = !!engine && (engine === 'claude' || engine === 'codex') && st?.route !== 'gateway'
- const id = engine && st?.installed && !plan ? `${engine}|${st.route}|${st.gateway ?? ''}|${st.account ?? ''}` : ''
- const [got, setGot] = useState<{ id: string; models: string[]; error?: string } | null>(null)
+ const fixed = plan && engine === 'claude'
+ const id = engine && st?.installed && !fixed ? `${engine}|${st.route}|${st.gateway ?? ''}|${st.account ?? ''}` : ''
+ const [got, setGot] = useState<({ id: string } & Listed) | null>(null)
useEffect(() => {
if (!id || !engine) return
if (!lists.has(id)) lists.set(id, engineModels(engine).catch((e: unknown) => ({ models: [], error: String(e) })))
let live = true
- void lists.get(id)!.then((r) => live && setGot({ id, ...r }))
+ void lists.get(id)!.then((r) => {
+ // Codex's names, for wherever a model shows (an agent's page, a card).
+ if (engine === 'codex' && r.labels) rememberModels(Object.entries(r.labels).map(([slug, l]) => ({ id: slug, engine, label: l.label, hint: l.hint ?? '' })))
+ if (live) setGot({ id, ...r })
+ })
return () => {
live = false
}
}, [id, engine])
if (!engine) return { options: [], loading: false }
- if (plan) return { options: MODELS.filter((m) => m.engine === engine).map((m) => ({ value: m.id, label: m.label, hint: m.hint })), loading: false }
const mine = got?.id === id ? got : undefined
+ const app = (): ModelOption[] => MODELS.filter((m) => m.engine === engine).map((m) => ({ value: m.id, label: m.label, hint: m.hint }))
+ if (fixed) return { options: app(), loading: false }
+ // Codex on a plan or a key: its catalog, the app's own list until it comes (or if it can't).
+ if (plan)
+ return mine?.models.length
+ ? { options: mine.models.map((slug) => ({ value: codexValue(slug), label: mine.labels?.[slug]?.label ?? slug, hint: L('', mine.labels?.[slug]?.hint ?? '') || undefined })), loading: false }
+ : { options: app(), loading: false }
return { options: (mine?.models ?? []).map((m) => ({ value: customModel(engine, m), label: m })), loading: !!id && !mine, error: mine?.error }
}
diff --git a/src/renderer/src/store.ts b/src/renderer/src/store.ts
index 9ad9964..5e305e1 100644
--- a/src/renderer/src/store.ts
+++ b/src/renderer/src/store.ts
@@ -447,7 +447,7 @@ export const openExternal = (url: string): void =>
export const saveRoutine = (routine: RoutineInput): Promise<Routine> => call('saveRoutine', { routine })
export const setJevKey = (key: string | null): Promise<void> => call('setJevKey', { key })
-export const engineModels = (engine: EngineId): Promise<{ models: string[]; error?: string }> => call('engineModels', { engine })
+export const engineModels = (engine: EngineId): Promise<{ models: string[]; labels?: Record<string, { label: string; hint?: string }>; error?: string }> => call('engineModels', { engine })
export const testEngine = (model: string): Promise<{ ok: boolean; message: string }> => call('testEngine', { model })
export const saveSkill = (skill: SkillInput): Promise<Skill> => call('saveSkill', { skill })
export const localSkills = (): Promise<LocalSkill[]> => call('localSkills')
diff --git a/src/shared/rpc.ts b/src/shared/rpc.ts
index 786e5cd..60df25f 100644
--- a/src/shared/rpc.ts
+++ b/src/shared/rpc.ts
@@ -67,7 +67,7 @@ export interface Api {
openExternal(p: { url: string }): void
saveRoutine(p: { routine: RoutineInput }): Routine // throws a message for the form
setJevKey(p: { key: string | null }): Promise<void> // checks the key with TypeSafe; throws why it's refused
- engineModels(p: { engine: EngineId }): Promise<{ models: string[]; error?: string }> // a harness's own list (OpenCode, Pi, a gateway)
+ engineModels(p: { engine: EngineId }): Promise<{ models: string[]; labels?: Record<string, { label: string; hint?: string }>; error?: string }> // a harness's own list (OpenCode, Pi, a gateway)
testEngine(p: { model: string }): Promise<{ ok: boolean; message: string }> // one real reply through that model
saveSkill(p: { skill: SkillInput }): Skill // throws a message for the form
localSkills(): LocalSkill[] // the skills of the user's Claude Code, its plugins and Codex
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 256c140..72fec39 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -331,9 +331,20 @@ export const customModel = (engine: EngineId, name: string): string => `${engine
// A model to run with: a custom one with no name yet falls back to the default.
export const usable = (m: Model | undefined): Model | undefined => (m?.id ? m : undefined)
+// Models a harness lists on its own (Codex's catalog), known once it's read: their names
+// show everywhere (an agent's page, Tuca's list), not just in the picker.
+const found = new Map<string, Model>()
+export const rememberModels = (list: Model[]): void => {
+ for (const m of list) found.set(customModel(m.engine, m.id), m)
+}
+// A Codex model as an agent keeps it: the app's own ids stay as they were, the rest go by name.
+export const codexValue = (slug: string): string => (MODELS.some((m) => m.id === slug) ? slug : customModel('codex', slug))
+
export const modelInfo = (id: string): Model | undefined => {
const listed = MODELS.find((m) => m.id === id)
if (listed) return listed
+ const known = found.get(id)
+ if (known) return known
const m = /^(claude|codex|opencode|pi):(.*)$/s.exec(id)
return m ? { id: m[2]!.trim(), engine: m[1] as EngineId, label: m[2]!.trim(), hint: L('Nome próprio', 'Custom name') } : undefined
}
diff --git a/test/codex-models.test.ts b/test/codex-models.test.ts
new file mode 100644
index 0000000..e521a2c
--- /dev/null
+++ b/test/codex-models.test.ts
@@ -0,0 +1,47 @@
+import { describe, expect, it } from 'vitest'
+import { parseCodexCatalog } from '../src/core/engines/detect'
+import { availableModels } from '../src/core/tuca'
+import { codexValue, modelInfo, rememberModels, type Settings } from '../src/shared/types'
+
+// What `codex debug models` prints (trimmed): newest first by priority, some hidden.
+const CATALOG = JSON.stringify({
+ models: [
+ { slug: 'gpt-5.6-luna', display_name: 'GPT-5.6-Luna', description: 'Older fast and efficient model.', visibility: 'list', priority: 9 },
+ { slug: 'codex-auto-review', display_name: 'Codex Auto Review', visibility: 'hide', priority: 43 },
+ { slug: 'gpt-6-astra', display_name: 'GPT-6-Astra', description: 'Frontier intelligence for the most demanding work.', visibility: 'list', priority: 2 },
+ { slug: 'gpt-reserve', display_name: 'GPT-Reserve', visibility: 'hide', priority: 4 }
+ ]
+})
+
+describe("Codex's own catalog", () => {
+ it('lists what Codex shows, newest first, with its names, and leaves hidden models out', () => {
+ expect(parseCodexCatalog(CATALOG)).toEqual([
+ { slug: 'gpt-6-astra', label: 'GPT-6-Astra', description: 'Frontier intelligence for the most demanding work.' },
+ { slug: 'gpt-5.6-luna', label: 'GPT-5.6-Luna', description: 'Older fast and efficient model.' }
+ ])
+ })
+
+ it('takes a bare list (the cache file) and bad output without breaking', () => {
+ expect(parseCodexCatalog(JSON.stringify([{ slug: 'x' }]))).toEqual([{ slug: 'x', label: 'x' }])
+ expect(parseCodexCatalog('')).toEqual([])
+ expect(parseCodexCatalog('{"error":"not logged in"}')).toEqual([])
+ })
+
+ it("keeps the app's own ids for the models agents already use, and names new ones", () => {
+ expect(codexValue('gpt-5.6-luna')).toBe('gpt-5.6-luna')
+ expect(codexValue('gpt-6-astra')).toBe('codex:gpt-6-astra')
+ rememberModels([{ id: 'gpt-6-astra', engine: 'codex', label: 'GPT-6-Astra', hint: 'Frontier' }])
+ expect(modelInfo('codex:gpt-6-astra')).toMatchObject({ id: 'gpt-6-astra', engine: 'codex', label: 'GPT-6-Astra' })
+ })
+
+ it("gives Tuca the catalog's models instead of the app's Codex list", () => {
+ const off = { installed: false, loggedIn: false }
+ const s = { engines: { claude: off, codex: { installed: true, loggedIn: true, route: 'plan' }, opencode: off, pi: off, gemini: off } } as unknown as Pick<Settings, 'engines'>
+ expect(availableModels(s, { codex: ['gpt-6-astra', 'gpt-5.6-luna'] })).toEqual([
+ { id: 'codex:gpt-6-astra', label: 'Codex · GPT-6-Astra' },
+ { id: 'gpt-5.6-luna', label: 'Codex · GPT-5.6 Luna' }
+ ])
+ // No catalog (an old Codex): the app's list, as before.
+ expect(availableModels(s).map((m) => m.id)).toEqual(['gpt-5.6-luna', 'gpt-5.6-terra', 'gpt-5.6-sol'])
+ })
+})