mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The `codex_local` adapter has a model picker. `loadCodexModels()` in `server/src/adapters/codex-models.ts` fills it from two sources: the OpenAI models API (only when an `OPENAI_API_KEY` resolves) and a static array shipped with the adapter. > - Most Codex users authenticate the CLI with a ChatGPT account. Those installs have no API key, so the picker always shows the static array, which changes only when Paperclip cuts a release. The Refresh button re-reads the same array and changes nothing, which reads as a broken control. > - The Codex CLI already maintains an authoritative catalog for these installs at `$CODEX_HOME/models_cache.json`, refreshed from the ChatGPT backend during normal use. > - This pull request reads that cache as the no-API-key discovery source, filters it to entries the CLI marks `visibility: "list"`, and merges it with the static fallback through the existing dedupe/merge helpers. > - The benefit is that a model the user's Codex install can already run appears in the picker without a Paperclip release, and internal slugs such as `gpt-reserve` stay out of the catalog. ## Linked Issues or Issue Description Fixes: #13126 Refs: #1317 (the user-facing report of the same root cause) ## What Changed - `server/src/adapters/codex-models.ts`: added `readCodexModelsCache()`, which reads `$CODEX_HOME/models_cache.json` (default `~/.codex/models_cache.json`), keeps entries with `visibility === "list"` and a non-empty `slug`, uses `display_name` as the label (falling back to the slug), and returns `[]` when the file is missing, unreadable, malformed, or lists nothing usable. - `loadCodexModels()`: when no OpenAI API key resolves, the result is now `mergedWithFallback(readCodexModelsCache())` instead of the static array alone. The API-key path is unchanged. - Added `server/src/adapters/codex-models.test.ts` with 6 tests: missing cache file, visibility filter (internal slugs excluded), missing display name, malformed JSON, non-array `models` payload, and empty/missing slugs. ## Verification - `npx vitest run server/src/adapters/` — 49 tests pass (6 new). - `tsc --noEmit` in `server/`: no errors in the changed files (the only errors are pre-existing missing `@paperclipai/paperclip-runner` vendor types that require the `prepare:runner-vendor` build step, also present on a clean master checkout). - Manual check against a real cache file: with `codex-cli 0.153.4` and a ChatGPT-authenticated install, the picker catalog grows from the 13 static entries to include the CLI's current list entries with their display names. ## Risks Low risk. The change only affects the no-API-key path and is additive: the static fallback still merges in, so no model id offered today disappears. Labels for cache-listed models change from the bare slug to the CLI's display name (ids, which agent config persists, are unchanged). The cache file is read with a try/catch, so a corrupt or unreadable file degrades to today's behavior. No new network calls, credentials, or auth surface. ## Model Used Codex (OpenAI Codex CLI, gpt-5-codex, agentic coding with tool use; the models_cache.json schema was verified against a live Codex install; change and tests authored with AI assistance) ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: 馨冉 <xinxincui239@gmail.com>