|
| 1 | +# 010 — Layer 1: advertise `api_types` + `capabilities` on the raw `/v1/models` list |
| 2 | + |
| 3 | +Branch: `codex/cursor-local-models-schema` (base: `origin/dev` at `85f7ef92a`, created with |
| 4 | +`git switch -c codex/cursor-local-models-schema origin/dev`). |
| 5 | +PR 1 of the stack, targets `dev`. Thesis: one additive schema change on the OpenAI-shape |
| 6 | +model list so Cursor's local-agent runtime detects extended capabilities. |
| 7 | + |
| 8 | +## File change map |
| 9 | + |
| 10 | +| Path | Action | Why | |
| 11 | +|---|---|---| |
| 12 | +| `src/server/models-capabilities.ts` | NEW | Pure helper: build the `api_types` + `capabilities` fields from catalog data. Keeps `index.ts` from growing another inline lambda. | |
| 13 | +| `src/server/index.ts` | MODIFY | Spread the helper's output into `nativeModelRow` and the routed-row object in the raw-list branch. | |
| 14 | +| `tests/cursor-local-models-schema.test.ts` | NEW | Regression test: server start, GET `/v1/models`, assert schema on a native row and a routed row; assert Grok fields unchanged; assert `OPENCODEX_MODEL_API_TYPES` keeps an OpenAI-family member (load-bearing: Cursor routes to the Messages wire only when NO OpenAI-family type is present). | |
| 15 | +| `tests/server-combo-failover-e2e.test.ts` | MODIFY | Six `toEqual` row literals at :824-846 become `toMatchObject`; keep `is_combo` absence explicit (`expect(row.is_combo).toBeUndefined()`) so the combo-off path stays verified. | |
| 16 | + |
| 17 | +Scope OUT: the Codex-catalog `{ models: [...] }` branch, Claude gateway branch, GUI, docs (020). |
| 18 | + |
| 19 | +## `src/server/models-capabilities.ts` (NEW) |
| 20 | + |
| 21 | +```ts |
| 22 | +/** |
| 23 | + * Extended capability advertisement for the OpenAI-shape `GET /v1/models` list. |
| 24 | + * |
| 25 | + * Cursor's local-agent runtime (the "Private Inference" build) only enables its reasoning |
| 26 | + * effort control when at least one row in `data[]` carries `api_types` (a non-empty array |
| 27 | + * naming an API family it can speak) and, optionally, a `capabilities` object. Plain OpenAI |
| 28 | + * clients ignore both keys. Every OpenCodex route serves chat completions, Responses and |
| 29 | + * Anthropic Messages, streams, and accepts tool calls, so those are constants; context and |
| 30 | + * vision come from catalog data when known and are omitted otherwise. |
| 31 | + */ |
| 32 | +// Membership is load-bearing for Cursor: its selector picks the Anthropic Messages wire only |
| 33 | +// when NO OpenAI-family type (chat_completions/responses/openai_chat/openai_responses) is |
| 34 | +// present. Keep at least one OpenAI-family entry. Guarded by a unit test. |
| 35 | +export const OPENCODEX_MODEL_API_TYPES = ["chat_completions", "responses", "anthropic_messages"] as const; |
| 36 | + |
| 37 | +export interface ModelCapabilityInput { |
| 38 | + reasoningEfforts?: readonly string[]; |
| 39 | + contextWindow?: number; |
| 40 | + inputModalities?: readonly string[]; |
| 41 | +} |
| 42 | + |
| 43 | +export interface ModelCapabilityFields { |
| 44 | + api_types: readonly string[]; |
| 45 | + capabilities: { |
| 46 | + context_length?: number; |
| 47 | + supports_tool_use: true; |
| 48 | + supports_streaming: true; |
| 49 | + supports_reasoning: boolean; |
| 50 | + supports_vision?: boolean; |
| 51 | + reasoning_effort?: string[]; |
| 52 | + }; |
| 53 | +} |
| 54 | + |
| 55 | +function positiveInt(value: unknown): number | undefined { |
| 56 | + return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : undefined; |
| 57 | +} |
| 58 | + |
| 59 | +export function modelCapabilityFields(input: ModelCapabilityInput): ModelCapabilityFields { |
| 60 | + const efforts = (input.reasoningEfforts ?? []).filter(e => typeof e === "string" && e.length > 0); |
| 61 | + const contextLength = positiveInt(input.contextWindow); |
| 62 | + const modalities = input.inputModalities; |
| 63 | + const supportsVision = Array.isArray(modalities) ? modalities.includes("image") : undefined; |
| 64 | + return { |
| 65 | + api_types: OPENCODEX_MODEL_API_TYPES, |
| 66 | + capabilities: { |
| 67 | + ...(contextLength !== undefined ? { context_length: contextLength } : {}), |
| 68 | + supports_tool_use: true, |
| 69 | + supports_streaming: true, |
| 70 | + supports_reasoning: efforts.length > 0, |
| 71 | + ...(supportsVision !== undefined ? { supports_vision: supportsVision } : {}), |
| 72 | + ...(efforts.length > 0 ? { reasoning_effort: [...efforts] } : {}), |
| 73 | + }, |
| 74 | + }; |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +## `src/server/index.ts` (MODIFY, raw-list branch ~L1481-1553) |
| 79 | + |
| 80 | +Before: |
| 81 | + |
| 82 | +```ts |
| 83 | + const nativeModelRow = (id: string, metadataId = id) => ({ |
| 84 | + id, |
| 85 | + object: "model", |
| 86 | + created: 0, |
| 87 | + owned_by: "openai", |
| 88 | + ...grokEffortFields( |
| 89 | + nativeReasoningEfforts(metadataId), |
| 90 | + nativeDefaultReasoningEffort(metadataId), |
| 91 | + ), |
| 92 | + }); |
| 93 | +``` |
| 94 | + |
| 95 | +After: |
| 96 | + |
| 97 | +```ts |
| 98 | + // modelCapabilityFields is a static import at the top of index.ts (pure helper, no |
| 99 | + // startup side effects). nativeOpenAiContextWindow / nativeInputModalities join the |
| 100 | + // existing catalog destructuring at ~L1347. |
| 101 | + const nativeLimits = nativeContextLimits(config); |
| 102 | + const nativeModelRow = (id: string, metadataId = id) => ({ |
| 103 | + id, |
| 104 | + object: "model", |
| 105 | + created: 0, |
| 106 | + owned_by: "openai", |
| 107 | + ...grokEffortFields( |
| 108 | + nativeReasoningEfforts(metadataId), |
| 109 | + nativeDefaultReasoningEffort(metadataId), |
| 110 | + ), |
| 111 | + // Cursor local-agent discovery (Private Inference build) reads api_types + |
| 112 | + // capabilities; other OpenAI clients ignore them. See src/server/models-capabilities.ts. |
| 113 | + ...modelCapabilityFields({ |
| 114 | + reasoningEfforts: nativeReasoningEfforts(metadataId), |
| 115 | + contextWindow: nativeOpenAiContextWindow(metadataId, nativeLimits), |
| 116 | + inputModalities: nativeInputModalities(metadataId), |
| 117 | + }), |
| 118 | + }); |
| 119 | +``` |
| 120 | + |
| 121 | +`nativeOpenAiContextWindow` and `nativeInputModalities` are added to the existing `await import("../codex/catalog")` |
| 122 | +destructuring at the top of the branch (both re-exported by `src/codex/catalog.ts:5`, verified). Native modalities come from the pinned upstream entry via `nativeInputModalities` (metadata.ts). |
| 123 | + |
| 124 | +Routed row, before: |
| 125 | + |
| 126 | +```ts |
| 127 | + ...(effective ? { alias_of: `${provider?.alias || m.provider}/${effective.alias}` } : {}), |
| 128 | + ...grokEffortFields(m.reasoningEfforts ?? [], m.defaultReasoningEffort), |
| 129 | + }; |
| 130 | +``` |
| 131 | + |
| 132 | +After: |
| 133 | + |
| 134 | +```ts |
| 135 | + ...(effective ? { alias_of: `${provider?.alias || m.provider}/${effective.alias}` } : {}), |
| 136 | + ...grokEffortFields(m.reasoningEfforts ?? [], m.defaultReasoningEffort), |
| 137 | + ...modelCapabilityFields({ |
| 138 | + reasoningEfforts: m.reasoningEfforts, |
| 139 | + contextWindow: m.contextCap ?? m.contextWindow, |
| 140 | + inputModalities: m.inputModalities, |
| 141 | + }), |
| 142 | + }; |
| 143 | +``` |
| 144 | + |
| 145 | +`contextCap` wins over `contextWindow` because it is the operator-narrowed effective limit |
| 146 | +(`CatalogModel.contextCap`, `parsing.ts:117`). |
| 147 | + |
| 148 | +## `tests/cursor-local-models-schema.test.ts` (NEW) |
| 149 | + |
| 150 | +Modelled on `tests/grok-models-effort-list.test.ts` (same fixture: `kimi` provider with |
| 151 | +`liveModels: false`, seeded native entitlements, `OPENCODEX_HOME` tmp dir, `SERVER_BUDGET_MS`). |
| 152 | + |
| 153 | +Assertions: |
| 154 | + |
| 155 | +1. Routed row `kimi/k3` (config: `modelReasoningEfforts.k3 = ["low","high","max"]`, |
| 156 | + `modelContextWindows.k3 = 200000`, `modelInputModalities.k3 = ["text","image"]`): |
| 157 | + - `api_types` equals `["chat_completions","responses","anthropic_messages"]` |
| 158 | + - `capabilities` equals `{ context_length: 200000, supports_tool_use: true, supports_streaming: true, supports_reasoning: true, supports_vision: true, reasoning_effort: ["low","high","max"] }` |
| 159 | + - Grok fields still present and unchanged: `supports_reasoning_effort === true`, |
| 160 | + `reasoning_efforts[1].default === true`. |
| 161 | +2. Routed row `kimi/kimi-for-coding` (no efforts): `capabilities.supports_reasoning === false`, |
| 162 | + no `reasoning_effort` key. |
| 163 | +3. Native row `gpt-5.6-sol`: `api_types` present; `capabilities.reasoning_effort` equals |
| 164 | + `nativeReasoningEfforts("gpt-5.6-sol")`; `capabilities.context_length` is a positive number. |
| 165 | +4. Unit test of `modelCapabilityFields` directly: empty input yields |
| 166 | + `{ api_types, capabilities: { supports_tool_use: true, supports_streaming: true, supports_reasoning: false } }` with no |
| 167 | + `context_length`/`supports_vision`/`reasoning_effort` keys (activation scenario for the |
| 168 | + omit branches, C-ACTIVATION-GROUNDING-01). |
| 169 | + |
| 170 | +Config keys confirmed on `OcxProviderConfig` in `src/types/provider.ts`: `modelContextWindows` |
| 171 | +(:362), `modelInputModalities` (:364), `modelReasoningEfforts` (:440), |
| 172 | +`modelDefaultReasoningEfforts` (:442). No fallback needed. |
| 173 | + |
| 174 | +## Accept criteria |
| 175 | + |
| 176 | +- `bun run typecheck` exit 0. |
| 177 | +- Focused set covering every raw-list consumer (audit blocker 2): `bun test tests/cursor-local-models-schema.test.ts tests/grok-models-effort-list.test.ts tests/server-combo-failover-e2e.test.ts tests/claude-models-discovery.test.ts tests/server-auth.test.ts tests/ollama-native.test.ts tests/provider-outbound.test.ts tests/codex-catalog.test.ts tests/gui-management-session.test.ts` exit 0. The full suite stays forbidden; exact-head CI is the gate. |
| 178 | +- Restarted local proxy: `curl -s http://127.0.0.1:10100/v1/models | jq '.data[] | select(.id=="gpt-5.6-sol") | {api_types, capabilities}'` shows both keys. |
| 179 | +- Live: Cursor Private Inference → Settings → Models → "Refresh model list" → composer |
| 180 | + model row for `gpt-5.6-sol` shows a Reasoning control with low/medium/high/xhigh. |
| 181 | + Screenshot saved as `devlog/_plan/260902_cursor_local_models_schema/011_effort_control.png`. |
| 182 | +- Live: send a turn with effort `high`; `ocx observe logs --json` last `gpt-5.6-sol` row |
| 183 | + shows the effort (field name to record at C — the log has `requestedEffort`/`reasoningEffort` |
| 184 | + or similar; if the log does not carry it, capture via `ocx debug provider on` request dump). |
| 185 | + |
| 186 | +## Bypass / enforcement (PLAN-BYPASS-NAMED-01) |
| 187 | + |
| 188 | +Not an enforcement change; no gate added. n/a. |
| 189 | + |
| 190 | +## Field chain (PLAN-FIELD-CHAIN-01) |
| 191 | + |
| 192 | +New output keys only (`api_types`, `capabilities`). Creation: helper. Serialization: |
| 193 | +`jsonResponse`. Deserialization: none server-side (`N/A` — inbound consumers are external |
| 194 | +clients). Consumers: Cursor local runtime (target), Grok Build (ignores), Codex (uses the other |
| 195 | +branch), Claude gateway (other branch), GUI API-keys page (`gui/src/pages/ApiKeys.tsx:170`) reads this list and only displays ids — additive keys are ignored. |
0 commit comments