15 Commits
Author SHA1 Message Date
owen b35c4fb7e1 Send reasoning effort 'none' when reasoning is off
CI / Build (push) Waiting to run
CI / Test (push) Waiting to run
When a reasoning-capable model has reasoning effort set to off, send
'none' rather than omitting the field or sending 'off'. This applies
to both the ChatGPT Codex Responses API and OpenAI-compatible chat
completions (both reasoning_effort and reasoning object formats).
Non-reasoning models continue to send no reasoning field at all.

Bumps version to 0.3.4.
2026-06-25 20:08:15 -05:00
owen d05bb87a23 Prepare v0.3.3 release
CI / Build (push) Waiting to run
CI / Test (push) Waiting to run
2026-06-25 19:48:48 -05:00
owen 52eca6477e Bump version to 0.3.2
CI / Build (push) Waiting to run
CI / Test (push) Waiting to run
2026-06-25 19:22:56 -05:00
IrrelevantandGitHub 8b87e11e53 Merge pull request #13 from owenqwenstarsky/feat/fast-mode
Implement fast mode preference
2026-06-25 19:20:05 -05:00
owen 62e1d53f60 Implement fast mode preference 2026-06-25 19:17:44 -05:00
owen 39e0c14eec Plan tool output context reliability 2026-06-25 19:04:49 -05:00
owen 909c28d587 Plan v0.3.2 fast mode
CI / Build (push) Waiting to run
CI / Test (push) Waiting to run
2026-06-25 18:55:23 -05:00
owen a2d2549df4 Fix transcript bottom scroll 2026-06-25 18:54:24 -05:00
owen b37bc677bd Add ChatGPT Codex provider
CI / Build (push) Waiting to run
CI / Test (push) Waiting to run
2026-06-25 18:21:03 -05:00
owen 6767bef88e Replace MkDocs pages build with plain markdown HTML 2026-06-25 14:45:02 -05:00
owen cd6b2ca034 Fix MkDocs config path 2026-06-25 14:11:22 -05:00
owen 4687f835cb Moving docs config 2026-06-25 14:00:53 -05:00
owen 1ab982167b Install MkDocs Material for Pages build 2026-06-25 13:57:10 -05:00
owen 1c1eeb18f7 Cleaning up the docs website 2026-06-25 13:55:12 -05:00
owen 93348269a8 Adding mkdocs 2026-06-25 13:38:33 -05:00
35 changed files with 2914 additions and 117 deletions
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env python3
"""Build the docs Markdown files into a static GitHub Pages site.
This intentionally avoids themed site generators and template files. Each Markdown
file is converted to a minimal standalone HTML page, and relative .md links are
rewritten to the generated .html filenames.
"""
from __future__ import annotations
import html
import re
import shutil
from pathlib import Path, PurePosixPath
from urllib.parse import urlsplit, urlunsplit
import markdown
ROOT = Path(__file__).resolve().parents[2]
DOCS_DIR = ROOT / "docs"
SITE_DIR = ROOT / "site"
MARKDOWN_EXTENSIONS = ["fenced_code", "tables", "toc"]
HREF_RE = re.compile(r'href="([^"]+)"')
def output_path(source: Path) -> Path:
if source.name == "README.md":
return SITE_DIR / "index.html"
return SITE_DIR / f"{source.stem}.html"
def page_title(text: str, fallback: str) -> str:
for line in text.splitlines():
if line.startswith("# "):
return line[2:].strip()
return fallback
def rewrite_markdown_links(rendered: str) -> str:
def replace(match: re.Match[str]) -> str:
href = html.unescape(match.group(1))
parts = urlsplit(href)
if parts.scheme or parts.netloc or not parts.path.endswith(".md"):
return match.group(0)
url_path = PurePosixPath(parts.path)
if url_path.name == "README.md":
new_path = str(url_path.with_name("index.html"))
else:
new_path = parts.path[:-3] + ".html"
new_href = urlunsplit(("", "", new_path, parts.query, parts.fragment))
return f'href="{html.escape(new_href, quote=True)}"'
return HREF_RE.sub(replace, rendered)
def render_page(source: Path) -> str:
text = source.read_text(encoding="utf-8")
title = page_title(text, "Cassady docs")
body = markdown.markdown(
text,
extensions=MARKDOWN_EXTENSIONS,
output_format="html5",
)
body = rewrite_markdown_links(body)
return "\n".join(
[
"<!doctype html>",
'<html lang="en">',
"<head>",
' <meta charset="utf-8">',
' <meta name="viewport" content="width=device-width, initial-scale=1">',
f" <title>{html.escape(title)}</title>",
"</head>",
"<body>",
body,
"</body>",
"</html>",
"",
]
)
def copy_static_assets() -> None:
for item in DOCS_DIR.iterdir():
if item.suffix == ".md":
continue
destination = SITE_DIR / item.name
if item.is_dir():
shutil.copytree(item, destination)
elif item.is_file():
shutil.copy2(item, destination)
def main() -> None:
if SITE_DIR.exists():
shutil.rmtree(SITE_DIR)
SITE_DIR.mkdir(parents=True)
for source in sorted(DOCS_DIR.glob("*.md")):
output_path(source).write_text(render_page(source), encoding="utf-8")
copy_static_assets()
(SITE_DIR / ".nojekyll").write_text("", encoding="utf-8")
if __name__ == "__main__":
main()
+67
View File
@@ -0,0 +1,67 @@
name: Publish Markdown site
on:
push:
branches:
- main
paths:
- 'docs/**'
- '.github/scripts/build-pages.py'
- '.github/workflows/pages.yml'
pull_request:
paths:
- 'docs/**'
- '.github/scripts/build-pages.py'
- '.github/workflows/pages.yml'
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: github-pages
cancel-in-progress: false
jobs:
build:
name: Build Markdown site
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Markdown converter
run: python -m pip install Markdown
- name: Build site
run: python .github/scripts/build-pages.py
- name: Configure Pages
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: actions/configure-pages@v5
- name: Upload Pages artifact
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: actions/upload-pages-artifact@v3
with:
path: site
deploy:
name: Deploy to GitHub Pages
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy Pages artifact
id: deployment
uses: actions/deploy-pages@v4
+1
View File
@@ -1,2 +1,3 @@
/target/
/dist/
/site/
Generated
+1 -1
View File
@@ -226,7 +226,7 @@ checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593"
[[package]]
name = "cassady"
version = "0.2.9"
version = "0.3.4"
dependencies = [
"anyhow",
"async-trait",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "cassady"
version = "0.2.9"
version = "0.3.4"
edition = "2021"
description = "Cassady/Cass minimal terminal coding agent"
license = "MIT"
+6 -5
View File
@@ -1,12 +1,12 @@
# Cassady / Cass
Cassady (`cass`) is a terminal coding agent written in Rust. It runs an interactive chat in your project, can inspect files, apply exact edits, run shell commands when the active safety mode allows them, and persist sessions for later resume. Cassady currently talks to OpenAI-compatible providers.
Cassady (`cass`) is a terminal coding agent written in Rust. It runs an interactive chat in your project, can inspect files, apply exact edits, run shell commands when the active safety mode allows them, and persist sessions for later resume. Cassady talks to OpenAI-compatible providers and a built-in ChatGPT Codex provider preset.
The project installs two equivalent commands, `cass` and `cassady`; examples use `cass`.
## Current scope and limitations
- Provider support is OpenAI-compatible chat/completions APIs only.
- Provider support includes OpenAI-compatible chat/completions APIs plus the `ChatGPT Codex` preset for users already signed in to Codex.
- The primary interface is an interactive terminal UI.
- v0.2.6 adds an experimental Rust embedding API for headless sessions; it is useful for early integrations but not yet a stable long-term library contract.
- Config and conversation state live under `~/.cass`.
@@ -44,7 +44,7 @@ cass update --check
cass
```
The setup wizard lets you choose one or more OpenAI-compatible providers, enter the API key environment-variable name, discover models from `GET /models` when the key is available, or enter a model id manually.
The setup wizard lets you choose one or more providers. OpenAI-compatible providers use an API key environment variable and can discover models from `GET /models` when the key is available. `ChatGPT Codex` uses your existing local Codex login (`~/.codex/auth.json`) and the Codex responses endpoint instead of a Cassady API-key environment variable.
Set your provider key in the shell where you run Cassady. For example, on macOS/Linux:
@@ -80,10 +80,11 @@ Common in-chat commands:
- `/branch` or `/restore`: open the branch/restore menu.
- `/login`: configure or update provider login settings.
- `/logout`: remove saved provider config and associated model entries.
- `/fast`, `/fast on`, `/fast off`, `/fast status`: prefer faster inference when the active provider/model supports it. ChatGPT Codex models, including `gpt-5.5`, are treated as fast-capable.
- `/model <model>`: switch to a model from `~/.cass/models.json`.
- `/new`: create a new chat for the current directory.
- `/resume <chat>`: resume a saved chat for the current directory.
- `/status`: show chat id, model, mode, cwd, record count, and current status.
- `/status`: show chat id, model, fast-mode state, mode, cwd, record count, and current status.
Helpful keys:
@@ -123,7 +124,7 @@ Cassady stores user-editable files in `~/.cass`:
- `global.md`: optional global instructions added to new chat system prompts when they fit the active request; they cannot override access modes, tool denials, approvals, or workspace boundaries.
- `docs/`: bundled documentation installed from the current binary.
API key references should usually be written as environment variables such as `"$OPENAI_API_KEY"`.
API key references should usually be written as environment variables such as `"$OPENAI_API_KEY"`. The `ChatGPT Codex` provider is different: it stores no key in `~/.cass` and reads the bearer token from local Codex auth at check/request time.
Detailed bundled docs live in this repository under [`docs/`](docs/README.md) and are installed to `~/.cass/docs` at runtime.
+123 -2
View File
@@ -1,6 +1,127 @@
# Cassady (Cass) Roadmap
## v0.2.9 — Provider Login Management
## v0.3.3 — Codex Fast-Mode Compatibility
This release focuses on keeping fast mode available for ChatGPT Codex users when local model metadata predates the fast-mode capability flag. Cassady should treat active `chatgpt-codex` provider models, including `gpt-5.5`, as fast-capable while leaving OpenAI-compatible and custom providers capability-gated by model metadata.
### Fast Mode Compatibility
- [x] **Treat ChatGPT Codex models as fast-capable at runtime.** Make `/fast` active for any active `chatgpt-codex` provider model even when legacy `models.json` metadata says `fast_mode.supported` is false.
- Keep non-Codex providers governed by their model metadata.
- Preserve the saved fast-mode preference behavior and status reporting.
- [x] **Document the Codex capability fallback.** Update README and bundled docs so users understand that ChatGPT Codex models, including `gpt-5.5`, can honor fast mode without refreshed metadata.
- Keep docs clear that provider-specific fast-mode request shaping remains Codex-only.
- [x] **Add regression coverage for legacy metadata.** Test that a ChatGPT Codex model with older `fast_mode.supported: false` metadata still reports fast mode as supported and active when preferred.
- Verify `cargo fmt` and `cargo test --locked --all-targets` pass before handoff.
## v0.3.4 — Tool Output Context Reliability
This release focuses on making large tool outputs easier for the assistant to recover from when model-context compaction or truncation hides important details. Cassady should guide the assistant toward smaller, targeted reads and searches, preserve enough provenance for follow-up inspection, and add regression coverage for broad-output workflows that previously stalled safe edits. See `plans/V0_3_4_TOOL_OUTPUT_CONTEXT_RELIABILITY_PLAN.md`.
### Model Context Recovery
- [ ] **Improve compacted tool-output guidance.** Replace generic head/tail compaction notices with actionable guidance that tells the assistant what was omitted and how to inspect it again safely.
- Include tool name, output size, retained excerpt shape, and suggested narrower follow-up reads or searches when available.
- Keep model-facing guidance concise enough that it does not worsen context pressure.
- [ ] **Preserve targeted reinspection metadata.** Track enough structured context for large reads and command output so the assistant can recover omitted details without repeating broad requests.
- For file reads, preserve path and line-range coverage even after compaction.
- For shell and search output, prefer guidance toward narrower commands or `grep`/`read` follow-ups rather than blindly rerunning the same broad command.
### Tool Behavior and Prompting
- [ ] **Bias tool use toward smaller inspections.** Update tool descriptions, prompt guidance, and result messages so broad reads become a fallback rather than the default.
- Encourage search-first workflows for large files and unknown locations.
- Mention result limits before or at truncation points so the assistant knows when context may be incomplete.
- [ ] **Make truncation and compaction visible across layers.** Align model-facing messages, stored conversation records, and UI summaries so users and the assistant can tell when output was incomplete.
- Do not let UI-only collapsed output change what is stored or sent to the model.
- Keep existing conversation files readable and resumable.
### Validation
- [ ] **Add regression coverage for broad-output recovery.** Test workflows where an early broad read or command output is compacted before the assistant needs exact context for an edit.
- Cover superseded reads, compacted non-newest tool outputs, provider-message validity, and suggested follow-up guidance.
- Verify `cargo fmt` and `cargo test --locked --all-targets` pass before handoff.
## v0.3.2 — Provider Fast Mode
This release focuses on adding a `/fast` command that lets users prefer faster inference when the active provider/model supports it. The first supported provider is `ChatGPT Codex`; other providers can add their own fast-mode request behavior later without changing the user-facing command. See `plans/V0_3_2_FAST_MODE_PLAN.md`.
### Fast Mode Command
- [ ] **Add a persisted `/fast` preference.** Let users toggle fast mode from an idle chat and keep that preference across sessions.
- Store the preference in `config.json` without disturbing provider/model configuration.
- Keep the preference separate from whether the current provider/model can honor it.
- [ ] **Show capability-aware fast-mode status.** Display fast mode as enabled only when the active provider/model supports it.
- If the user switches to an unsupported provider/model, hide the enabled state and report fast mode as unavailable when relevant.
- If the user switches back to a supported provider/model, apply the existing preference again.
### Provider Support
- [ ] **Implement ChatGPT Codex fast-mode requests.** Add the provider-specific request option for Codex when fast mode is active.
- Verify and test the exact Codex responses request shape during implementation.
- Do not send Codex-specific fast-mode fields to OpenAI-compatible providers.
- [ ] **Add extensible provider/model capability metadata.** Model fast-mode support as provider/model metadata so future providers can opt in case by case.
- Default unknown and custom providers to unsupported.
- Mark built-in ChatGPT Codex model metadata as supported when Cassady can send the fast-mode request.
### Documentation and Validation
- [ ] **Document fast mode behavior and limits.** Update README and bundled docs for `/fast`, `default_fast_mode`, model capability metadata, and Codex-only initial support.
- Explain the difference between a saved fast-mode preference and active fast-mode support.
- [ ] **Test fast-mode preference, switching, and provider requests.** Cover command parsing, persistence, status rendering, model/provider switching, and Codex request body behavior.
- Verify `cargo fmt` and `cargo test --locked --all-targets` pass before handoff.
## v0.3.1 — Transcript Scroll Stability
This release focuses on keeping the live transcript anchored correctly above the input and footer during long sessions with blank reasoning or tool-output lines.
### TUI Reliability
- [x] **Fix bottom-scroll row counting for whitespace-only lines.** Count indented blank transcript rows the same way Ratatui renders them so accumulated blank rows no longer hide recent transcript content above the footer.
- Add regression coverage for whitespace-only wrapped row counting.
## v0.3.0 — ChatGPT Codex Provider ✅ Completed
This release focuses on letting users who are already signed in to Codex with a ChatGPT subscription use that account from Cassady. `ChatGPT Codex` becomes a provider preset that calls the Codex responses endpoint and reads its bearer token from local Codex auth instead of an API-key environment variable. See `plans/V0_3_0_CHATGPT_CODEX_PROVIDER_PLAN.md`.
### Provider Setup
- [x] **Add a ChatGPT Codex provider preset.** Make `ChatGPT Codex` available from `cass login`, `/login`, and first-run setup as a distinct provider option.
- Use provider id `chatgpt-codex` and endpoint `https://chatgpt.com/backend-api/codex/responses`.
- Skip the normal API-key environment-variable prompt for this preset.
- Prefer the model configured in local Codex config when available, with manual model entry as a fallback.
- [x] **Read local Codex auth safely.** Resolve the bearer token from `$CODEX_HOME/auth.json` or `~/.codex/auth.json` at check/request time.
- Support the local Codex `tokens.access_token` shape without copying the token into `~/.cass`.
- Give clear recovery steps when the user has not run `codex login`, signed in to the Codex app, or has an expired/missing token.
### Provider Runtime
- [x] **Add a ChatGPT Codex responses client.** Route `chatgpt-codex` providers to the exact Codex responses endpoint instead of the OpenAI-compatible `/chat/completions` path.
- Translate Cassady messages, tools, tool calls, and tool outputs to the endpoint's expected responses format.
- Stream assistant text, safe reasoning summaries when available, and function-call deltas back into the existing agent loop.
- [x] **Keep OpenAI-compatible providers unchanged.** Refactor provider dispatch only as much as needed to support the new provider kind.
- Existing provider config, setup, model discovery, API-key env vars, `/model`, and `cass check` behavior should continue to work.
- Avoid leaking ChatGPT access tokens in errors, logs, transcripts, or config files.
### Documentation and Validation
- [x] **Document ChatGPT Codex prerequisites and caveats.** Update README and bundled docs for setup, config examples, `cass check`, troubleshooting, and the distinction between ChatGPT subscription-backed access and API-key providers.
- Make clear that Cassady uses an existing Codex login and does not implement its own browser login or token refresh flow in this release.
- Note that the ChatGPT backend endpoint may change outside Cassady's control.
- [x] **Test Codex auth and provider behavior.** Cover Codex auth fixtures, config validation, setup catalog behavior, provider dispatch, streaming response parsing, tool calls, and secret redaction.
- Verify `cargo fmt` and `cargo test --locked --all-targets` pass before handoff.
## v0.2.9 — Provider Login Management ✅ Completed
This release focuses on making provider configuration available from both the shell and an active Cassady chat. Users can add or update OpenAI-compatible provider/model settings with `cass login` or `/login`, and remove saved providers and their associated models with `cass logout` or `/logout`. See `plans/V0_2_9_PROVIDER_LOGIN_MANAGEMENT_PLAN.md`.
@@ -32,7 +153,7 @@ This release focuses on making provider configuration available from both the sh
- [x] **Test provider management behavior.** Cover provider/model removal, active default repair, local command parsing, and autocomplete.
- Verify `cargo fmt` and `cargo test --locked --all-targets` pass before handoff.
## v0.2.8 — Conversation Branch and Restore
## v0.2.8 — Conversation Branch and Restore ✅ Completed
This release focuses on making conversation recovery safe and explorable. Pressing `Esc` twice while idle opens a branch/restore menu where users can browse prior user messages, assistant messages, and tool calls, create a new branch from a selected checkpoint, and optionally restore Cassady-tracked file edits without destroying the original conversation. See `plans/V0_2_8_CONVERSATION_BRANCH_RESTORE_PLAN.md`.
+1 -1
View File
@@ -8,7 +8,7 @@ Cassady tools may list, search, and read this directory. Mutating tools are bloc
- [Commands](commands.md): CLI forms, global flags, `cass update`, in-chat commands, and keys.
- [Configuration](configuration.md): `~/.cass` files, setup, precedence, schema examples, and validation.
- [Providers and models](providers.md): built-in OpenAI-compatible providers, custom endpoints, model discovery, and reasoning metadata.
- [Providers and models](providers.md): built-in provider presets, custom OpenAI-compatible endpoints, ChatGPT Codex auth, model discovery, reasoning metadata, and fast-mode support.
- [Access modes and tool safety](access-modes.md): what tools can read, write, edit, and run in each mode.
- [Experimental Rust embedding API](embedding.md): import Cassady from Rust, start headless sessions, stream events, and handle approvals.
- [Workflows](workflows.md): common ways to inspect code, apply edits, run checks, switch models, and resume chats.
+8 -7
View File
@@ -35,7 +35,7 @@ Resume this chat with: cass --resume <id>
- `--resume [CHAT_ID]`: resume a chat, or list chats for the current cwd when no id is provided.
- `--model MODEL`: use `MODEL` for this session.
- `--base-url URL`: override the active provider's OpenAI-compatible base URL for this session.
- `--base-url URL`: override the active provider's base URL or endpoint for this session.
- `--api-key-env ENV`: read the API key from environment variable `ENV` for this session.
- `--cwd PATH`: use `PATH` as the launch cwd and workspace root.
- `--readonly`: force read-only mode.
@@ -56,15 +56,15 @@ Validates Cassady configuration under `~/.cass`:
- duplicate provider/model ids.
- model/provider references.
- active provider and model resolution.
- active API key availability.
- active authentication availability.
Missing API keys for inactive providers are warnings. A missing active API key is an error and `cass check` exits with a non-zero status.
Missing API keys for inactive OpenAI-compatible providers are warnings. A missing active API key is an error. For `ChatGPT Codex`, missing or expired local Codex auth is an error when it is active. `cass check` exits with a non-zero status when errors are present.
### `cass login`
Runs the provider login/configuration wizard. This is the same provider setup flow used by `cass setup`, framed for adding or updating saved OpenAI-compatible provider access. It can configure multiple providers, discover or manually enter models, update active defaults, and validate the saved files.
Runs the provider login/configuration wizard. This is the same provider setup flow used by `cass setup`, framed for adding or updating saved provider access. It can configure multiple providers, discover or manually enter models, update active defaults, and validate the saved files.
`cass login` edits Cassady files under `~/.cass`; it does not sign in through a browser or create provider accounts.
`cass login` edits Cassady files under `~/.cass`; it does not create provider accounts. For `ChatGPT Codex`, sign in with `codex login` or the Codex app first; Cassady then uses local Codex auth instead of storing an API key.
### `cass logout`
@@ -74,7 +74,7 @@ Opens an interactive menu for removing saved providers from Cassady config. Remo
### `cass setup`
Runs the interactive setup wizard in a terminal. It configures OpenAI-compatible providers, API key environment-variable references, and first models. It updates `config.json`, `providers.json`, and `models.json` while preserving unrelated entries where possible.
Runs the interactive setup wizard in a terminal. It configures providers, authentication sources, and first models. OpenAI-compatible providers use API key environment-variable references; `ChatGPT Codex` uses local Codex auth. It updates `config.json`, `providers.json`, and `models.json` while preserving unrelated entries where possible.
### `cass update`
@@ -107,12 +107,13 @@ The updater does not invoke `sudo` or administrator prompts. If the install dire
Type `/` to open command autocomplete.
- `/branch` or `/restore`: open the branch/restore menu for the current conversation family.
- `/fast`, `/fast on`, `/fast off`, `/fast status`: toggle or inspect a persisted fast-mode preference. Fast mode is active only when the current provider/model supports it; ChatGPT Codex models, including `gpt-5.5`, are treated as fast-capable.
- `/login`: configure or update provider login settings, then reload active provider/model config.
- `/logout`: remove saved providers and their associated models, then reload active provider/model config when any remain.
- `/model <model>`: switch the model for future turns. Autocomplete lists models from `~/.cass/models.json`.
- `/new`: create a new chat for the current directory.
- `/resume <chat>`: resume a saved chat from the current directory. Autocomplete lists matching chats.
- `/status`: show chat id, state, model, access mode, cwd, record count, and current status.
- `/status`: show chat id, state, model, fast-mode state, access mode, cwd, record count, and current status.
Local commands can be used only when the agent is idle.
+36 -8
View File
@@ -19,7 +19,7 @@ Run:
cass setup
```
Cassady also offers setup automatically when `cass` cannot resolve a usable active provider, model, or API key before starting a chat.
Cassady also offers setup automatically when `cass` cannot resolve a usable active provider, model, or authentication source before starting a chat.
For everyday provider management, `cass login` opens the same provider configuration flow with login-oriented wording. Inside an idle chat, `/login` temporarily opens that flow and reloads the active provider/model after it closes.
@@ -27,9 +27,9 @@ To remove saved provider configuration, run `cass logout` or type `/logout` whil
The wizard uses keyboard prompts: `↑`/`↓` moves through choices, `Space` selects providers in the multi-select screen, and `Enter` submits. Text fields use the same prompt style instead of falling back to plain line input.
The wizard supports configuring multiple OpenAI-compatible providers at once. If more than one provider is configured, setup asks which one should be active first. If the selected API key environment variable is set, Cassady tries to fetch models from `GET {base_url}/models` and lets you choose one. If discovery fails, it offers a retry before falling back to manual model entry. If the API key is not set, setup asks for a model id manually.
The wizard supports configuring multiple providers at once. If more than one provider is configured, setup asks which one should be active first. For OpenAI-compatible providers, if the selected API key environment variable is set, Cassady tries to fetch models from `GET {base_url}/models` and lets you choose one. If discovery fails, it offers a retry before falling back to manual model entry. If the API key is not set, setup asks for a model id manually. For `ChatGPT Codex`, setup skips API-key prompts and reads model defaults from local Codex config when available.
Setup stores API keys as environment-variable references such as `"$OPENAI_API_KEY"` by default. After setup, Cassady writes/updates `config.json`, `providers.json`, and `models.json`, validates them, and starts a chat only when the active API key is available in the current shell.
Setup stores API keys as environment-variable references such as `"$OPENAI_API_KEY"` by default for OpenAI-compatible providers. `ChatGPT Codex` stores no API key in `~/.cass`; it reads local Codex auth at check/request time. After setup, Cassady writes/updates `config.json`, `providers.json`, and `models.json`, validates them, and starts a chat only when the active authentication source is available.
## `config.json`
@@ -42,6 +42,7 @@ Example:
"default_provider": "openai",
"default_model": "gpt-4.1",
"default_reasoning_effort": "medium",
"default_fast_mode": false,
"default_access_mode": "read-only",
"context_message_limit": 80,
"model_tool_result_limit": 24000,
@@ -56,6 +57,7 @@ Fields:
- `default_provider`: optional provider id from `providers.json`. If omitted, Cassady infers the provider from `default_model` when possible.
- `default_model`: optional model id to use by default.
- `default_reasoning_effort`: optional `off`, `low`, `medium`, or `high`, clamped to model metadata.
- `default_fast_mode`: optional boolean, defaults to `false`. When `true`, Cassady requests faster inference only for provider/model combinations that advertise fast-mode support.
- `default_access_mode`: `"read-only"`, `"workspace-edit"`, or `"full-access"`.
- `context_message_limit`: optional legacy upper bound for recent non-system messages. Cassady primarily budgets context from model metadata and trims along valid tool-call boundaries.
- `model_tool_result_limit`: optional max bytes of tool output sent back to the model.
@@ -89,14 +91,33 @@ Fields:
- `id`: required unique provider id.
- `name`: optional display name.
- `kind`: required provider kind. Currently only `"openai-compatible"` is supported.
- `base_url`: required OpenAI-compatible API base URL.
- `api_key`: required string. Use either a literal key or an environment-variable reference like `"$OPENAI_API_KEY"`.
- `kind`: required provider kind. Supported values are `"openai-compatible"` and `"chatgpt-codex"`.
- `base_url`: required API base URL or endpoint. `chatgpt-codex` uses `https://chatgpt.com/backend-api/codex/responses`.
- `api_key`: required for `openai-compatible` providers. Use either a literal key or an environment-variable reference like `"$OPENAI_API_KEY"`. Omit it for `chatgpt-codex`; that provider reads local Codex auth instead.
- `default_model`: optional model id used when no default model is configured.
- `models`: optional list of model ids associated with this provider.
Only strings that start with `$` are resolved as environment variables. Cassady does not expand partial strings or `${NAME}` syntax.
`ChatGPT Codex` example:
```json
{
"providers": [
{
"id": "chatgpt-codex",
"name": "ChatGPT Codex",
"kind": "chatgpt-codex",
"base_url": "https://chatgpt.com/backend-api/codex/responses",
"default_model": "gpt-5.5",
"models": ["gpt-5.5"]
}
]
}
```
Run `codex login` or sign in with the Codex app before using this provider. Cassady reads `$CODEX_HOME/auth.json` or `~/.codex/auth.json` and does not store the Codex access token in `~/.cass`.
## `models.json`
Example:
@@ -117,6 +138,9 @@ Example:
"required": false,
"default_effort": "medium",
"request_format": "reasoning_effort"
},
"fast_mode": {
"supported": false
}
}
]
@@ -137,9 +161,13 @@ Fields:
- `required`: optional boolean, defaults to `false`.
- `default_effort`: optional `off`, `low`, `medium`, or `high`; defaults to `medium`. Cannot effectively be `off` when `required` is `true`.
- `request_format`: optional `reasoning_effort` or `reasoning_object`; defaults to `reasoning_effort`.
- `fast_mode`: optional object. Defaults to unsupported.
- `supported`: optional boolean, defaults to `false`. Cassady treats active `chatgpt-codex` provider models as fast-capable even if older metadata says otherwise; custom and OpenAI-compatible model entries default to unsupported.
Reasoning effort is a runtime per-turn setting. Press `Tab` to cycle it while idle. Provider-streamed reasoning is persisted and sent back in future model context using the provider's reasoning field, such as `reasoning_content` or `reasoning`.
Fast mode is a persisted preference, not a guarantee. Use `/fast` to toggle it while idle. `/status` shows `enabled` only when the preference is on and the current provider/model can honor it; otherwise it reports `off` or `preferred, unavailable ...`. Fast-mode request shaping is implemented only for `chatgpt-codex`.
## Precedence
- CLI access-mode flags override `default_access_mode` for the current session.
@@ -158,7 +186,7 @@ Run:
cass check
```
This validates JSON syntax, expected schema, duplicate provider/model ids, model/provider references, active provider/model resolution, and API key environment-variable availability. Missing API keys for inactive providers are warnings; a missing active provider API key is an error.
This validates JSON syntax, expected schema, duplicate provider/model ids, model/provider references, active provider/model resolution, and authentication availability. Missing API keys for inactive OpenAI-compatible providers are warnings; a missing active provider API key is an error. For `ChatGPT Codex`, missing or expired local Codex auth is an active-provider error.
When setup is incomplete, `cass check` prints actionable next steps such as:
@@ -172,7 +200,7 @@ cass
1. Edit one file at a time.
2. Keep provider ids and model provider references in sync.
3. Prefer API key env references over literal keys.
3. Prefer API key env references over literal keys for OpenAI-compatible providers; do not paste Codex tokens into Cassady config.
4. Prefer `cass login` and `cass logout` for routine provider changes.
5. Run `cass check` before starting a chat.
+3 -1
View File
@@ -14,9 +14,11 @@
**Exact edit**: An `edit` tool replacement where each `old_text` must match exactly once in the original file before anything is written.
**Fast mode**: A saved preference enabled with `/fast`. It is active only when the current provider/model advertises fast-mode support; otherwise Cassady keeps the preference but reports it as unavailable.
**Global instructions**: Optional text in `~/.cass/global.md` included in new chat system prompts. Cassady follows these instructions when they fit the active request, but they cannot override runtime safety constraints such as access modes, tool denials, approvals, or workspace boundaries.
**Model metadata**: The `models.json` entry describing a model id, owning provider, display name, context limits, tool/streaming support, and reasoning behavior.
**Model metadata**: The `models.json` entry describing a model id, owning provider, display name, context limits, tool/streaming support, reasoning behavior, and fast-mode support.
**OpenAI-compatible provider**: A provider exposing an API compatible with the OpenAI-style chat/completions behavior Cassady uses.
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

+27 -8
View File
@@ -1,14 +1,15 @@
# Providers and models
Cassady currently supports OpenAI-compatible providers. A provider supplies the base URL and API key; a model entry supplies metadata for one model id used with that provider.
Cassady supports OpenAI-compatible providers plus a built-in `ChatGPT Codex` provider preset. A provider supplies the endpoint and authentication source; a model entry supplies metadata for one model id used with that provider.
## Built-in setup catalog
The setup wizard offers these provider templates:
| Provider | Provider id | Base URL | Suggested API key env var |
| Provider | Provider id | Base URL / endpoint | Suggested auth source |
| --- | --- | --- | --- |
| OpenAI | `openai` | `https://api.openai.com/v1` | `OPENAI_API_KEY` |
| ChatGPT Codex | `chatgpt-codex` | `https://chatgpt.com/backend-api/codex/responses` | local Codex auth |
| xAI | `xai` | `https://api.x.ai/v1` | `XAI_API_KEY` |
| Fireworks | `fireworks` | `https://api.fireworks.ai/inference/v1` | `FIREWORKS_API_KEY` |
| Groq | `groq` | `https://api.groq.com/openai/v1` | `GROQ_API_KEY` |
@@ -27,9 +28,17 @@ Use `cass login` to add or update provider configuration from the shell. Inside
Use `cass logout` or `/logout` to remove saved provider entries from Cassady config. Logout also removes model metadata entries associated with the removed providers and repairs active defaults when other providers remain. It does not delete environment variables, shell profile exports, API keys stored elsewhere, or external provider accounts.
## ChatGPT Codex preset
`ChatGPT Codex` is for users who have already signed in with Codex. Run `codex login` or sign in with the Codex app first, then select `ChatGPT Codex` in `cass login` or `cass setup`.
Cassady reads the bearer token from `$CODEX_HOME/auth.json` or `~/.codex/auth.json` at check/request time. It does not copy the access token or refresh token into `~/.cass`, and `cass check` redacts secret values. Setup prefers the `model` value from `$CODEX_HOME/config.toml` when present and otherwise offers a default/manual model id.
This preset uses `kind: "chatgpt-codex"` and posts to `https://chatgpt.com/backend-api/codex/responses`. That ChatGPT backend endpoint and Codex auth file format are outside Cassady's control, so users may need to update Cassady if they change.
## Model discovery
When the selected API key environment variable is available, setup tries:
For OpenAI-compatible providers, when the selected API key environment variable is available, setup tries:
```text
GET {base_url}/models
@@ -46,7 +55,7 @@ A custom provider should expose OpenAI-compatible chat completions behavior at t
- optional reasoning fields or reasoning request controls;
- optional `/models` discovery during setup.
Provider protocols that are not OpenAI-compatible are not currently supported.
Provider protocols that are not OpenAI-compatible are supported only when Cassady has an explicit provider kind for them, such as `chatgpt-codex`.
## Provider vs model metadata
@@ -54,7 +63,7 @@ Provider protocols that are not OpenAI-compatible are not currently supported.
- provider id;
- base URL;
- API key reference;
- API key reference or local auth source;
- optional default model;
- optional list of associated model ids.
@@ -65,7 +74,8 @@ Provider protocols that are not OpenAI-compatible are not currently supported.
- display name;
- context length and max output tokens;
- tool and streaming support;
- reasoning support and request format.
- reasoning support and request format;
- fast-mode support.
`config.json` selects active defaults, such as `default_provider`, `default_model`, and `default_access_mode`.
@@ -81,6 +91,15 @@ Reasoning metadata controls how the runtime reasoning effort behaves:
Reasoning display is separate. `show_reasoning` controls whether provider-streamed reasoning is visible in the transcript; press `Ctrl-Shift-R` or `Ctrl-R` to toggle it at runtime.
## Fast-mode metadata
Fast mode has two parts:
- `default_fast_mode` in `config.json`: the user's saved preference.
- `fast_mode.supported` in `models.json`: whether non-Codex provider/model metadata can honor that preference.
Cassady sends fast-mode requests only for `ChatGPT Codex`. Any active `chatgpt-codex` provider model, including `gpt-5.5`, is treated as fast-capable so older model metadata does not block the feature. OpenAI-compatible and custom model entries default to unsupported, so `/fast` can remember the preference without sending provider-specific fields.
## Switching models
Use one of these approaches:
@@ -95,7 +114,7 @@ or inside a chat:
/model MODEL
```
The in-chat model autocomplete lists entries from `~/.cass/models.json`. Switching the model also updates the default model and reasoning effort in `config.json` for future sessions.
The in-chat model autocomplete lists entries from `~/.cass/models.json`. Switching the model also updates the default provider, default model, and reasoning effort in `config.json` for future sessions. If fast mode is preferred, Cassady recomputes whether it is active after the switch.
## Health checks
@@ -105,4 +124,4 @@ Run:
cass check
```
This confirms that the active provider and model resolve and that the active API key environment variable is set. Missing inactive-provider keys are warnings; missing active-provider keys are errors.
This confirms that the active provider and model resolve. For OpenAI-compatible providers it checks API key environment variables; missing inactive-provider keys are warnings and missing active-provider keys are errors. For `ChatGPT Codex`, it checks that local Codex auth contains an access token and prints recovery steps if not.
+22 -5
View File
@@ -1,6 +1,6 @@
# Troubleshooting
Use `cass check` first for configuration problems. It validates files, provider/model references, and API key availability.
Use `cass check` first for configuration problems. It validates files, provider/model references, and authentication availability.
## Missing active API key
@@ -24,6 +24,22 @@ cass check
cass
```
## Missing or expired ChatGPT Codex auth
Symptom: `cass check` reports `Codex auth` errors, or chat startup says provider authentication is not available for `chatgpt-codex`.
Likely cause: `ChatGPT Codex` is active but `$CODEX_HOME/auth.json` or `~/.codex/auth.json` is missing, unreadable, lacks `tokens.access_token`, or contains an expired token.
Fix:
```sh
codex login
cass check
cass
```
You can also sign in with the Codex app if that is how your local Codex auth is managed. Cassady does not refresh or store ChatGPT/Codex tokens; it reads local Codex auth at check/request time and redacts secret values.
## Invalid API key reference
Symptom: the key is not resolved the way you expect.
@@ -45,9 +61,10 @@ Likely causes:
- wrong `base_url`;
- network or proxy problem;
- provider outage;
- provider requires a different OpenAI-compatible path.
- provider requires a different OpenAI-compatible path;
- for `ChatGPT Codex`, the private ChatGPT backend endpoint changed or the selected model is unavailable.
Fix: verify the base URL in `providers.json`, retry setup, or enter the model id manually if only `/models` discovery is failing.
Fix: verify the base URL in `providers.json`, retry setup, or enter the model id manually if only `/models` discovery is failing. For `ChatGPT Codex`, verify that `base_url` is `https://chatgpt.com/backend-api/codex/responses`, rerun `codex login`, and try a current Codex model id.
## `/models` discovery fails
@@ -75,9 +92,9 @@ Then verify with a small prompt.
Symptom: the assistant says the provider returned an error.
Likely cause: provider-side authentication, quota, billing, or rate limit.
Likely cause: provider-side authentication, quota, billing, or rate limit. For `ChatGPT Codex`, this can also mean your ChatGPT subscription/account does not have the requested Codex model available or the local Codex token needs to be refreshed by Codex.
Fix: confirm the API key, provider account status, selected model, and provider dashboard. Cassady forwards provider failures into the chat but cannot resolve account-level issues.
Fix: confirm the API key, provider account status, selected model, and provider dashboard. For `ChatGPT Codex`, rerun `codex login` or open Codex to refresh local auth. Cassady forwards provider failures into the chat but cannot resolve account-level issues.
## Invalid JSON or unknown config fields
+17 -3
View File
@@ -83,7 +83,9 @@ Inside an idle chat:
/logout
```
Logout removes selected providers from Cassady's config and removes their associated model entries. It does not delete environment variables or external provider accounts.
Logout removes selected providers from Cassady's config and removes their associated model entries. It does not delete environment variables, local Codex auth, or external provider accounts.
For `ChatGPT Codex`, run `codex login` or sign in with the Codex app before `cass login`. Cassady validates `~/.codex/auth.json` and uses that local token source instead of asking for an API-key environment variable.
## Switch model
@@ -93,7 +95,7 @@ Inside a chat:
/model MODEL_ID
```
Autocomplete lists models from `~/.cass/models.json`. Switching models is allowed only when idle. Cassady persists the last used model and reasoning effort into `config.json`.
Autocomplete lists models from `~/.cass/models.json`. Switching models is allowed only when idle. Cassady persists the last used provider, model, and reasoning effort into `config.json`.
You can also launch with a model override:
@@ -101,6 +103,18 @@ You can also launch with a model override:
cass --model MODEL_ID
```
## Prefer fast mode
Inside a chat:
```text
/fast
```
Use `/fast on`, `/fast off`, or `/fast status` when you want an explicit action. Cassady saves the preference in `config.json`, but fast mode is active only when the current provider/model supports it. ChatGPT Codex models, including `gpt-5.5`, are treated as fast-capable.
Switching to an unsupported provider/model keeps the preference but makes `/status` show fast mode as unavailable. Switching back to ChatGPT Codex enables it again.
## Resume a chat
List chats for the current directory:
@@ -166,4 +180,4 @@ Config files live under `~/.cass`, outside a normal project workspace. To inspec
cass check
```
Prefer `cass setup` for provider/model changes when possible.
For OpenAI-compatible providers this checks API key environment variables. For `ChatGPT Codex` this checks local Codex auth and points you back to `codex login` if the token is missing or expired. Prefer `cass setup` or `cass login` for provider/model changes when possible.
+234
View File
@@ -0,0 +1,234 @@
# v0.3.0 ChatGPT Codex Provider Implementation Plan
## Goal
This release adds a first-class `ChatGPT Codex` provider preset so users who are already signed in to Codex with a ChatGPT subscription can run Cassady without creating a separate API-key environment variable. The preset should call `https://chatgpt.com/backend-api/codex/responses` and resolve its bearer token from the local Codex auth config by default.
Success statement:
> A user who has already run `codex login` or signed in through the Codex app can select `ChatGPT Codex` in `cass login`, pass `cass check`, and send Cassady turns through their Codex subscription without copying tokens into Cassady config.
## Scope
### In scope
- Add `ChatGPT Codex` as a built-in provider preset in the setup/login catalog.
- Add a provider kind/client for the ChatGPT Codex responses endpoint rather than forcing it through `/chat/completions` URL construction.
- Read the default access token from the local Codex auth file, normally `$CODEX_HOME/auth.json` or `~/.codex/auth.json`.
- Support the observed Codex auth shape with `tokens.access_token`, while keeping token values out of Cassady config, logs, check output, and error text.
- Prefer the Codex-configured model from `$CODEX_HOME/config.toml` when available, with a safe manual model fallback.
- Teach `cass check` to validate that local Codex auth is present and usable for the active `ChatGPT Codex` provider.
- Add docs explaining prerequisites, setup flow, token-source behavior, expiration troubleshooting, and the distinction between ChatGPT subscription access and API-key providers.
- Add focused tests with temporary Codex-home fixtures and mocked streaming responses.
### Out of scope
- Implementing Cassady's own browser OAuth/device-login flow for ChatGPT.
- Storing or refreshing ChatGPT/Codex tokens in Cassady-owned config files.
- Reverse engineering unrelated ChatGPT backend endpoints beyond the requested Codex responses endpoint.
- Guaranteeing compatibility if the private ChatGPT backend endpoint or Codex auth file format changes.
- Replacing OpenAI-compatible provider support or changing existing provider presets.
- Release tagging, packaging, or GitHub release creation.
## Context or Current State
Cassady's provider stack is currently centered on OpenAI-compatible chat completions:
- `src/setup.rs` owns the built-in provider catalog, setup/login prompts, model discovery via `GET {base_url}/models`, and writes to `providers.json`/`models.json`/`config.json`.
- `src/config.rs` defines `ProviderDefinition`, validates provider registries, resolves `api_key` values from literals or environment-variable references, and currently accepts only `kind = "openai-compatible"`.
- `src/agent.rs` constructs `OpenAiCompatibleProvider` directly from resolved config.
- `src/providers/openai_compatible.rs` appends `/chat/completions`, sends OpenAI-compatible chat payloads, and parses OpenAI-compatible streaming deltas.
- `docs/providers.md`, `docs/configuration.md`, `docs/commands.md`, `docs/workflows.md`, and `README.md` describe provider setup as API-key/environment-variable based.
The new preset differs in two important ways:
1. Authentication should come from Codex's local login state, not from a Cassady environment-variable API key.
2. The endpoint is a Codex-specific responses endpoint (`https://chatgpt.com/backend-api/codex/responses`), so Cassady needs an endpoint-specific provider client or a more general provider dispatch layer.
Local Codex auth is expected to live under Codex home, normally `~/.codex/auth.json`, with a shape like:
```json
{
"auth_mode": "chatgpt",
"tokens": {
"access_token": "...",
"refresh_token": "...",
"account_id": "..."
},
"last_refresh": "..."
}
```
Cassady should treat this file as sensitive input: read it only when resolving the active provider token, never copy the access token into Cassady-owned JSON, and never print token contents.
## Design Principles
1. **Use Codex login state, do not own ChatGPT auth.** Cassady should integrate with an existing Codex login and tell users to run `codex login` or sign in to Codex when auth is missing or expired.
2. **Keep provider protocols explicit.** Do not pretend the ChatGPT Codex endpoint is OpenAI-compatible if it needs different URL construction, request shape, or stream parsing.
3. **Avoid token leakage.** Token values must not be stored in `~/.cass`, included in transcripts, surfaced in `cass check`, or embedded in test snapshots.
4. **Keep existing setup stable.** Existing providers should continue to use environment-variable API keys and `/models` discovery without extra Codex dependencies.
5. **Fail with clear recovery steps.** Missing Codex auth should produce actionable messages, not generic provider errors.
## Design
### Provider catalog and setup UX
Add a built-in catalog entry:
| Provider | Provider id | Kind | Endpoint | Token source |
| --- | --- | --- | --- | --- |
| ChatGPT Codex | `chatgpt-codex` | `chatgpt-codex` | `https://chatgpt.com/backend-api/codex/responses` | Local Codex auth |
In `cass login`/`cass setup`, selecting this provider should skip the normal `API key environment variable` prompt and instead show a prerequisite check:
```text
ChatGPT Codex uses your local Codex login.
✓ Found Codex auth at ~/.codex/auth.json
```
If the file or access token is missing:
```text
ChatGPT Codex needs a local Codex login.
Run `codex login` or sign in with the Codex app, then run `cass login` again.
```
Model selection should prefer, in order:
1. The `model` value from `$CODEX_HOME/config.toml` when present.
2. A known default Codex model constant only if the project already has a current default available.
3. Manual model id entry.
Do not call `GET /models` for `chatgpt-codex` unless a verified endpoint is added later; model discovery remains an OpenAI-compatible setup behavior.
### Provider configuration shape
Extend provider config without breaking existing files. One possible JSON shape is:
```json
{
"id": "chatgpt-codex",
"name": "ChatGPT Codex",
"kind": "chatgpt-codex",
"base_url": "https://chatgpt.com/backend-api/codex/responses",
"auth": { "type": "codex_local" },
"default_model": "gpt-5.5",
"models": ["gpt-5.5"]
}
```
Implementation may choose an equivalent internal representation, but it should preserve these properties:
- Existing `api_key` string behavior remains valid for OpenAI-compatible providers.
- `chatgpt-codex` providers can omit environment-variable API keys.
- `cass check` can distinguish missing local Codex auth from missing API-key env vars.
- Serialized config does not contain the Codex access token.
### Codex auth resolution
Add a small resolver module, for example `src/codex_auth.rs`, with helpers like:
- `codex_home() -> PathBuf`: `$CODEX_HOME` when set, otherwise `~/.codex`.
- `codex_auth_path() -> PathBuf`: `$CODEX_AUTH_FILE` for tests/overrides when set, otherwise `{codex_home}/auth.json`.
- `load_codex_access_token() -> Result<CodexAccessToken>`: parse `tokens.access_token` and return a redacted/display-safe token wrapper.
- `check_codex_auth() -> CodexAuthStatus`: report path found, auth mode, access-token presence, optional JWT expiration, and recovery hints.
If the access token looks like a JWT, parse the `exp` claim without validating the signature so Cassady can warn or fail early when the token is expired. Token refresh itself should stay out of scope unless Codex exposes a stable documented local refresh interface.
Read the token at request time rather than caching it during setup. This allows a separate Codex process to refresh `auth.json` between Cassady turns.
### Provider dispatch
Refactor provider construction so `src/agent.rs` does not instantiate only `OpenAiCompatibleProvider`. A simple first step is an enum:
```rust
enum ProviderClient {
OpenAiCompatible(OpenAiCompatibleProvider),
ChatGptCodex(ChatGptCodexProvider),
}
```
Both variants should expose a common `complete(messages, tools, tx)` async method returning the existing `CompletionResult`. This preserves the current agent loop, tool execution, conversation storage, and TUI behavior.
### ChatGPT Codex responses client
Add a new provider module, for example `src/providers/chatgpt_codex.rs`, that:
- Posts to the exact configured endpoint, defaulting to `https://chatgpt.com/backend-api/codex/responses`.
- Sends `Authorization: Bearer <local Codex access token>`.
- Includes the active model and converted message/tool context in the endpoint's expected responses format.
- Streams assistant text into `AgentEvent::AssistantChunk`.
- Streams reasoning summaries into `AgentEvent::ReasoningChunk` only when the endpoint provides a safe reasoning summary field.
- Converts function/tool call deltas into Cassady `StoredToolCall` values.
- Converts Cassady tool results back into the endpoint's function-call-output input shape on the next turn.
- Redacts authentication details from non-success response errors.
The exact request/stream schema should be verified against the endpoint during implementation and captured in mocked fixtures. If the endpoint rejects a field used by OpenAI-compatible providers, keep the Codex payload minimal rather than adding compatibility shims that risk breaking the flow.
### Check and troubleshooting behavior
For active `chatgpt-codex` providers, `cass check` should report status like:
```text
✓ active provider: chatgpt-codex
✓ endpoint: https://chatgpt.com/backend-api/codex/responses
✓ Codex auth: ~/.codex/auth.json contains an access token
```
Failure should point to recovery:
```text
✗ Codex auth: no access token found in ~/.codex/auth.json
Run `codex login` or sign in with the Codex app, then rerun `cass check`.
```
Do not print the token, account id, refresh token, or full auth JSON.
## Implementation Steps
1. Add the v0.3.0 roadmap entry and this implementation plan.
2. Extend provider config types/validation to support `kind = "chatgpt-codex"` and a non-env local Codex auth source while preserving existing OpenAI-compatible files.
3. Add `src/codex_auth.rs` for Codex home discovery, auth-file parsing, redacted status reporting, and optional JWT expiration checks.
4. Add `ChatGPT Codex` to `src/setup.rs` provider catalog and branch setup behavior so it skips API-key env prompts and `/models` discovery.
5. Refactor provider construction in `src/agent.rs` behind a small provider dispatch enum or trait.
6. Implement `src/providers/chatgpt_codex.rs` with endpoint-specific request conversion, streaming parsing, tool-call conversion, and redacted errors.
7. Update `cass check` so active and inactive provider checks understand Codex-local auth separately from environment-variable API keys.
8. Update README and bundled docs for the new preset, prerequisites, config example, troubleshooting, and known endpoint/auth caveats.
9. Add unit tests for config parsing/validation, Codex auth fixtures, setup catalog behavior, and provider dispatch.
10. Add mocked streaming tests for the ChatGPT Codex client, including text, tool calls, tool outputs, auth failures, and redaction.
## Tests
- `providers.json` with existing OpenAI-compatible providers still parses and validates.
- A `chatgpt-codex` provider with local Codex auth validates without `api_key`/env-var availability.
- Missing `~/.codex/auth.json` produces a clear `cass check` error for an active `chatgpt-codex` provider.
- A fixture `auth.json` with `tokens.access_token` resolves a token but redacts it in display and errors.
- Expired JWT-like access tokens are detected when possible and produce a recovery hint.
- Setup/login catalog includes `ChatGPT Codex` and skips the API-key env-var prompt for that provider.
- Model selection uses `$CODEX_HOME/config.toml` `model` when available, with manual fallback.
- Provider dispatch selects `ChatGptCodexProvider` only for `kind = "chatgpt-codex"`.
- Mocked Codex streaming responses produce assistant chunks and final `CompletionResult.content`.
- Mocked Codex function-call streams produce Cassady `StoredToolCall` values and accept subsequent tool output messages.
- Provider error messages never include access tokens, refresh tokens, or raw auth JSON.
- `cargo fmt` passes.
- `cargo test --locked --all-targets` passes when practical.
## Documentation
- Update `README.md` setup/provider sections with `ChatGPT Codex` as a subscription-backed option.
- Update `docs/providers.md` with the new preset, endpoint, token-source behavior, and private-endpoint caveat.
- Update `docs/configuration.md` with the extended provider schema and a safe example that uses local Codex auth.
- Update `docs/commands.md` and `docs/workflows.md` for `cass login`, `cass check`, and troubleshooting steps.
- Update `docs/troubleshooting.md` with missing/expired Codex auth, unsupported model, and backend endpoint failure guidance.
## Acceptance Criteria
- `cass login` offers `ChatGPT Codex` as a provider preset.
- Selecting `ChatGPT Codex` does not ask for an API-key environment variable by default.
- Cassady reads the access token from local Codex auth at request/check time and never stores that token under `~/.cass`.
- Active `chatgpt-codex` sessions call `https://chatgpt.com/backend-api/codex/responses` instead of appending `/chat/completions`.
- Normal OpenAI-compatible providers continue to work unchanged.
- `cass check` gives clear success/failure output for local Codex auth without leaking secrets.
- README and bundled docs explain the prerequisite of signing in to Codex first.
- `cargo fmt` and `cargo test --locked --all-targets` pass.
+285
View File
@@ -0,0 +1,285 @@
# v0.3.2 Fast Mode Implementation Plan
## Goal
v0.3.2 adds a `/fast` command that lets users opt into faster provider inference when the active provider/model supports it. The setting should feel like a user preference, but the runtime state should be capability-aware: fast mode is shown as enabled only when the current provider/model can actually honor it.
Success statement:
> A ChatGPT Codex user can type `/fast`, see fast mode enabled for Codex models that support it, switch to an unsupported provider/model and see fast mode become unavailable, then switch back and have the preference apply again.
## Scope
### In scope
- Add an idle-only `/fast` local command that toggles the user's fast-mode preference.
- Persist the preference in Cassady config so it survives new chats and restarts.
- Add provider/model capability metadata that determines whether fast mode is currently active.
- Implement fast-mode request support for `ChatGPT Codex` first.
- Keep unsupported providers/models explicit: the preference can remain on, but the UI/status should say fast mode is unavailable rather than enabled.
- Update `/status`, the bottom/status line, command autocomplete/help, README, and bundled docs.
- Add focused tests for command parsing, persistence, capability gating, provider request shaping, and model switching.
### Out of scope
- Adding fast-mode support for OpenAI-compatible providers in v0.3.2.
- Guessing provider-specific fast-mode request fields without verified behavior.
- Adding latency benchmarking, automatic mode selection, or per-turn speed/quality controls beyond the `/fast` toggle.
- Changing the default model selection flow except to record fast-mode capability for known built-in presets.
- Treating fast mode as a quality guarantee; providers may still vary in latency and output behavior.
## Context or Current State
Cassady already has several runtime preferences and model/provider capability paths that should guide this work:
- `src/app.rs` parses local slash commands such as `/model`, `/login`, `/logout`, and `/status`, and already restricts provider/model changes to idle state.
- `src/config.rs` persists default model and reasoning effort in `config.json` and stores model metadata in `models.json`.
- `ModelDefinition` already includes capability-like metadata such as `supports_tools`, `supports_streaming`, and `reasoning`.
- `ProviderClient::from_config` in `src/providers/mod.rs` dispatches by provider kind to `OpenAiCompatibleProvider` or `ChatGptCodexProvider`.
- `src/providers/chatgpt_codex.rs` is the first provider where fast mode should affect the outgoing request.
- `/model` already reloads model metadata and resets reasoning effort based on the new model.
- `/status` currently reports chat id, model, mode, cwd, records, and current status.
The important product behavior is that "fast mode preference" and "fast mode active" are different states:
- Preference: whether the user wants fast mode when possible.
- Active: whether the current provider/model supports fast mode and the preference is enabled.
## Design Principles
1. **Preference stays stable, capability controls activation.** Switching to an unsupported provider/model should not erase the user's preference; it should only make fast mode inactive until support is available again.
2. **Provider-specific request details stay behind provider clients.** The agent loop should pass a normalized fast-mode flag; each provider decides whether and how to encode it.
3. **UI wording must distinguish enabled from unavailable.** Avoid showing "fast mode enabled" when Cassady cannot send a fast-mode request for the active provider/model.
4. **Extend metadata, do not hardcode every check in the TUI.** Use provider/model capability helpers so future providers can add fast mode without rewriting command handling.
5. **Keep unsupported behavior quiet and compatible.** Existing OpenAI-compatible providers should continue working unchanged and should not receive unknown request fields.
## Design
### User model
Add a user preference to `config.json`:
```json
{
"default_fast_mode": true
}
```
Suggested behavior:
- Missing `default_fast_mode` defaults to `false`.
- `/fast` toggles the preference while idle.
- `/fast on` and `/fast off` may be supported if easy, but the minimum required command is the toggle form.
- The preference is persisted immediately, similar to last-used model/reasoning persistence.
- The active state is recomputed whenever config, provider, model, or model metadata changes.
Status examples:
```text
fast mode: enabled
fast mode: unavailable for provider fireworks
fast mode: off
```
If the user toggles fast mode on while using an unsupported provider:
```text
fast mode preference on; unavailable for this provider/model
```
If the user later switches to a supported Codex model, the UI should show:
```text
fast mode enabled
```
### Capability model
Add a small capability representation, preferably on model metadata with provider-kind fallback:
```json
{
"id": "gpt-5.5",
"provider": "chatgpt-codex",
"fast_mode": {
"supported": true
}
}
```
Rules:
- `fast_mode.supported` defaults to `false` unless a provider-specific built-in preset intentionally marks it true.
- For the `ChatGPT Codex` built-in setup path, saved Codex model metadata should mark fast mode as supported when the implementation can send the fast-mode request for that provider.
- Manual custom providers and discovered OpenAI-compatible models should default to unsupported.
- If a provider supports fast mode for all models but model metadata is missing, provider-specific capability fallback may return supported. Keep that fallback in config/provider capability helpers, not in UI string matching.
Add helper APIs along these lines:
```rust
pub struct FastModeState {
pub preferred: bool,
pub supported: bool,
pub active: bool,
pub unavailable_reason: Option<String>,
}
impl Config {
pub fn fast_mode_state(&self) -> FastModeState;
}
```
`active` should be exactly `preferred && supported`.
### Provider request behavior
Thread the active fast-mode boolean through the provider settings:
```rust
ProviderClient::from_config(&config, reasoning_effort, fast_mode_active)
```
or include it in a runtime options struct if that is cleaner:
```rust
pub struct ProviderRuntimeOptions {
pub reasoning_effort: ReasoningEffort,
pub fast_mode: bool,
}
```
`ChatGptCodexProvider` should encode fast mode using the verified Codex responses request shape. During implementation, verify the exact field against the current Codex behavior and capture the resulting request body in tests. The plan intentionally does not prescribe a speculative field name.
OpenAI-compatible providers should ignore the setting until support is explicitly added. They must not receive experimental Codex-only fields.
### UI and command behavior
Add `LocalCommand::Fast(FastModeCommand)` in `src/app.rs`.
Minimum command behavior:
```text
/fast
```
Recommended optional forms:
```text
/fast on
/fast off
/fast status
```
Command handling:
- Only allow changes while idle.
- Persist the preference to `config.json`.
- Recompute active state from the current provider/model after toggling.
- Append or show a concise status message.
- Include `/fast` in autocomplete/local command help.
Update `/status` to include both preference and active state, for example:
```text
fast: enabled
```
or:
```text
fast: preferred, unavailable for provider fireworks
```
The bottom/status line should include a compact signal only when useful:
- `fast` when active.
- No `fast` label when off.
- Optional `fast unavailable` only immediately after toggling or in `/status`, to avoid clutter.
### Model and provider switching
When `/model` changes the active model:
- Reload `config.model_metadata` as today.
- Recompute reasoning effort as today.
- Recompute fast-mode state.
- Show the model status with fast-mode state when the preference is on.
Expected examples:
```text
model: gpt-5.5 · fast enabled
model: accounts/fireworks/models/qwen3p7-plus · fast unavailable
```
When `/login` or `/logout` updates provider config:
- Reload config as today.
- Preserve `default_fast_mode`.
- Recompute fast-mode state for the new active provider/model.
### Configuration and docs
Update docs to describe:
- `default_fast_mode` in `config.json`.
- `fast_mode.supported` in `models.json`.
- `/fast` command behavior.
- Provider support status: v0.3.2 supports fast mode only for `ChatGPT Codex`.
- The distinction between fast-mode preference and active fast-mode support.
## Implementation Steps
1. Extend config types in `src/config.rs`:
- Add `default_fast_mode: Option<bool>` to the config file representation.
- Add `fast_mode` metadata to model definitions.
- Add a `FastModeState` helper that computes preferred/supported/active.
2. Add persistence helpers:
- Save fast-mode preference without disturbing unrelated config fields.
- Ensure existing `save_last_used` behavior preserves the new field.
3. Mark built-in `ChatGPT Codex` model metadata as fast-mode capable during setup/login when the provider implementation supports it.
4. Add provider runtime options and pass `fast_mode_state.active` into `ProviderClient` construction from `src/agent.rs`.
5. Implement Codex request support in `src/providers/chatgpt_codex.rs` using the verified fast-mode request shape.
6. Keep `OpenAiCompatibleProvider` behavior unchanged and add tests proving it does not receive fast-mode fields.
7. Add `/fast` parsing and idle command handling in `src/app.rs`, including optional `on`, `off`, and `status` forms if the implementation remains small.
8. Update `/status`, status-line rendering, autocomplete/help text, and model-switch status messages.
9. Update `README.md`, `docs/commands.md`, `docs/configuration.md`, `docs/providers.md`, `docs/workflows.md`, and `docs/glossary.md`.
10. Add focused tests and run `cargo fmt` plus `cargo test --locked --all-targets`.
## Tests
- `config.json` without `default_fast_mode` defaults to fast mode off.
- `default_fast_mode: true` loads and persists without losing existing config fields.
- `models.json` parses `fast_mode.supported`.
- Unsupported or missing fast-mode metadata produces `FastModeState { preferred: true, supported: false, active: false }`.
- A supported ChatGPT Codex model produces `active: true` when preference is on.
- `/fast` parses as a local command and rejects unexpected arguments unless explicit `on`/`off`/`status` forms are implemented.
- `/fast` cannot change preference during an active turn.
- Toggling `/fast` while on an unsupported provider stores the preference but reports unavailable.
- Switching from a supported Codex model to an unsupported model hides the active fast-mode signal without clearing the preference.
- Switching back to a supported Codex model restores active fast mode.
- `ChatGptCodexProvider` includes the verified fast-mode request field only when active.
- `OpenAiCompatibleProvider` request bodies are unchanged when fast-mode preference is on but unsupported.
- `/status` includes fast-mode state.
- README and bundled docs mention `/fast` and provider-specific support.
- `cargo fmt` passes.
- `cargo test --locked --all-targets` passes when practical.
## Documentation
- README command list and provider setup notes.
- `docs/commands.md` for `/fast` syntax and idle-only behavior.
- `docs/configuration.md` for `default_fast_mode` and `models.json` fast-mode capability metadata.
- `docs/providers.md` for the initial ChatGPT Codex-only support.
- `docs/workflows.md` for switching models/providers with fast-mode preference preserved.
- `docs/glossary.md` for "Fast mode" as a preference plus provider/model capability.
## Acceptance Criteria
- `/fast` toggles a persisted fast-mode preference.
- Fast mode is shown as enabled only when the active provider/model supports it.
- Unsupported providers/models do not show fast mode enabled and do not receive fast-mode request fields.
- ChatGPT Codex requests include the verified fast-mode option when the preference is on and the active Codex model supports it.
- Switching models/providers recomputes fast-mode active state without clearing the user's preference.
- `/status`, autocomplete/help, README, and bundled docs describe the feature accurately.
- `cargo fmt` and `cargo test --locked --all-targets` pass before implementation handoff.
@@ -0,0 +1,175 @@
# v0.3.4 Tool Output Context Reliability Implementation Plan
## Goal
v0.3.4 makes Cassady more reliable after broad tool output has been truncated, compacted, or superseded in the model context. The assistant should be able to tell when details are missing, understand which file range or command produced them, and quickly recover by using narrower reads or searches instead of stalling or making unsafe edits from incomplete context.
Success statement:
> After a large read or command output is compacted out of the request context, the assistant receives concise recovery guidance with enough provenance to inspect the exact missing area again before editing.
## Scope
### In scope
- Improve model-facing compaction notes for large tool outputs.
- Preserve useful provenance for compacted `read`, `grep`, and `shell` outputs.
- Add focused guidance that nudges the assistant toward smaller line ranges and search-first workflows.
- Keep existing provider message structure valid when tool outputs are compacted or earlier records are omitted.
- Align UI summaries, stored records, and model-facing transformed output so truncation/compaction is understandable without changing the full conversation history.
- Add regression tests for broad-output recovery and context-budget trimming.
- Update README and bundled docs where they describe context management, tool output limits, and recommended inspection workflows.
### Out of scope
- Implementing semantic summarization with an additional model call.
- Replacing Cassady's approximate token estimator with provider-specific tokenizers.
- Adding a full retrieval index over prior tool outputs or repository contents.
- Changing the JSONL conversation storage format in a way that makes existing chats unreadable.
- Changing UI collapsed-tool behavior except where labels or summaries need to expose truncation/compaction status.
- Automatically editing files based on compacted output without reinspection.
## Context or Current State
Relevant current behavior:
- `src/agent.rs` converts conversation records into provider messages, supersedes older repeated read outputs, compacts older tool outputs with `compact_tool_outputs`, and trims records with `trim_to_context_budget` and `trim_to_message_limit`.
- `compact_text` currently emits a generic head/tail note: `Cass compacted this tool output from ... chars to fit the model context`.
- `superseded_read_note` already preserves file path and line range when a later read covers an earlier read range.
- `src/tools/read.rs` returns headers like `--- path lines start-end ---`, followed by numbered lines. This is good provenance, but compaction can obscure the most useful middle section.
- `src/tools/grep.rs` already recommends narrowing when `max_matches` is reached.
- `src/tools/shell.rs` returns complete stdout/stderr/exit-code text to the agent loop; if the output is large, current compaction does not know the original command or suggest a narrower command.
- `src/ui/render.rs` has separate collapsed/full tool-output presentation. That display choice must remain UI-only and must not affect the stored record or model-facing context.
The main reliability gap is that once a broad output has been compacted, the assistant may see only a generic excerpt and lose the clue needed to make the next targeted tool call.
## Design Principles
1. **Never hide incompleteness.** If Cassady compacts or truncates output before sending it to the model, the transformed content must say so plainly.
2. **Recovery beats summarization.** Prefer actionable provenance and follow-up instructions over trying to summarize omitted content heuristically.
3. **Keep guidance compact.** The fix must not consume enough context to make context pressure worse.
4. **Preserve valid provider conversations.** Tool result messages must still match their assistant tool calls after compaction and trimming.
5. **Do not mutate history for UI convenience.** JSONL records should retain original tool outputs unless a future storage migration explicitly changes that contract.
## Design
### Model-facing compaction notes
Replace the generic `compact_text(content, target_chars)` path with a metadata-aware formatter, for example:
```rust
struct ToolOutputCompactionHint {
tool_name: Option<String>,
original_chars: usize,
retained_head_chars: usize,
retained_tail_chars: usize,
provenance: ToolOutputProvenance,
}
enum ToolOutputProvenance {
Read { sections: Vec<ReadOutputSection> },
Grep { stopped_after: Option<usize> },
Shell { command: Option<String> },
Unknown,
}
```
The first implementation can infer provenance from the tool result text and nearby conversation/tool-call data rather than changing stored record schemas.
Example compacted read result:
```text
[Cass compacted this read output from 48,212 chars to fit the model context. The omitted content came from src/app.rs lines 1-1820. Use read with a narrower line range, or grep for a symbol before reading, before relying on omitted details.]
--- retained head excerpt ---
...
--- omitted middle ---
--- retained tail excerpt ---
...
```
Example compacted shell result:
```text
[Cass compacted this shell output from 81,004 chars to fit the model context. Rerun a narrower command, pipe through grep/head/tail, or inspect the specific files named in the excerpt before making edits based on omitted lines.]
```
Keep notes deterministic and short; avoid per-line summaries of omitted content.
### Read-output provenance
Reuse and extend the existing `ReadOutputSection` parsing in `src/agent.rs`:
- Detect every `--- path lines start-end ---` section before compaction.
- Preserve observed line coverage from numbered lines when available.
- Include one compact range summary in compaction notes:
- Single section: `path lines 35-220`.
- Multiple sections: `3 read sections including path_a lines 1-120 and path_b lines 40-90`.
- When a later read supersedes an earlier range, continue using the current superseded-read note and ensure tests cover interaction with compaction.
### Grep and shell guidance
For `grep` output:
- Preserve existing `… stopped after N matches` text.
- If compacted, add a note suggesting a narrower query, smaller path scope, lower `max_matches`, or a focused `read` around matching lines.
For `shell` output:
- If the tool-call arguments are available in the message conversion path, include a sanitized command preview in the note when reasonably short.
- Suggest command narrowing patterns without prescribing platform-specific syntax unless the command itself is already shell-specific, e.g. `grep`, `head`, `tail`, or a more targeted subcommand.
- Do not rerun shell commands automatically.
### Prompt and tool descriptions
Update the base prompt and tool descriptions only enough to reinforce reliable behavior:
- Prefer `grep` before broad `read` when the target location is unknown.
- Read smaller line ranges when files are large or when previous output says it was compacted.
- Treat compacted/truncated output as incomplete evidence; reinspect before editing.
Avoid bloating `src/prompt.rs`; keep additions short and test expected key phrases rather than full prompt text.
### UI and storage alignment
- Stored JSONL should keep the original tool result content.
- Model-facing transformed messages may contain compacted/superseded notes.
- UI collapsed mode should keep using summaries, but summaries should not imply the model saw the full output when it did not.
- If practical, make collapsed tool summaries include a compact `compacted` or `truncated` marker only when the stored/result text itself says that Cassady truncated or stopped output.
## Implementation Steps
1. Inspect provider-message conversion in `src/agent.rs` and identify where tool-call names/arguments are still available when compacting tool results.
2. Refactor `compact_text` into metadata-aware helpers that can produce deterministic compaction notes for read, grep, shell, and unknown outputs.
3. Reuse existing read-section parsing to build concise read range summaries for compacted read outputs.
4. Add shell and grep-specific recovery guidance based on tool name and output markers.
5. Preserve the newest tool result behavior unless tests show that the newest result can still exceed practical context limits; if changed, document the tradeoff explicitly.
6. Update `src/tools/read.rs`, `src/tools/grep.rs`, and `src/prompt.rs` descriptions with concise search-first and narrow-range guidance.
7. Add or update UI summary helpers in `src/ui/render.rs` only if needed to expose stored truncation/compaction markers consistently.
8. Update README and bundled docs for context reliability, broad-output recovery, and recommended inspection workflow.
9. Run `cargo fmt` and `cargo test --locked --all-targets`.
## Tests
- Large read output compacts to a note that includes original size, path, line range, and a narrower-read/search suggestion.
- Multi-file read output compacts to a concise multi-section provenance summary.
- Superseded read output still produces the superseded note and does not lose provider-message validity after context trimming.
- Large grep output compaction preserves or adds narrowing guidance.
- Large shell output compaction suggests rerunning a narrower command and does not include unsafe automatic actions.
- Context-budget trimming does not leave orphaned tool results or assistant tool calls.
- Stored conversation records retain original tool output while model-facing messages can be compacted.
- Prompt/tool spec tests verify the presence of concise search-first and reinspection guidance.
## Documentation
- Update `README.md` where tool output/context behavior is described.
- Update `docs/workflows.md` with recommended search-first and narrow-read workflows.
- Update `docs/troubleshooting.md` with recovery steps for compacted or truncated output.
- Update `docs/glossary.md` if terms such as compacted output, superseded read, or model-facing context need clarification.
## Acceptance Criteria
- Compacted tool outputs include actionable provenance and recovery guidance.
- Broad read and command-output workflows have regression coverage demonstrating safe reinspection before edits.
- Existing conversations remain loadable and resumable.
- Provider message conversion remains valid for tool-call/tool-result pairs after compaction and trimming.
- `cargo fmt` and `cargo test --locked --all-targets` pass.
+13 -20
View File
@@ -2,8 +2,8 @@ use crate::access::AccessMode;
use crate::config::{Config, ReasoningEffort};
use crate::conversation::{now_ts, Conversation, Record, StoredToolCall};
use crate::prompt;
use crate::providers::openai_compatible::{OpenAiCompatibleProvider, OpenAiCompatibleSettings};
use crate::providers::types::ModelMessage;
use crate::providers::{ProviderClient, ProviderRuntimeOptions};
use crate::security::PolicyDecision;
use crate::tools::{self, ToolContext, ToolRuntimeEvent};
use anyhow::Result;
@@ -85,34 +85,27 @@ pub async fn run_turn_with_commands(
ts: now_ts(),
})?;
let api_key = match settings.config.resolved_api_key() {
Ok(api_key) => api_key,
let reasoning_effort = settings
.reasoning_effort
.clamp_for_model(settings.config.model_metadata.as_ref());
let provider = match ProviderClient::from_config(
&settings.config,
ProviderRuntimeOptions {
reasoning_effort,
fast_mode: settings.config.fast_mode_state().active,
},
) {
Ok(provider) => provider,
Err(err) => {
append_visible_assistant(
&mut conversation,
&tx,
format!("I couldn't start the turn because the API key is not available: {err}"),
format!("I couldn't start the turn because provider authentication is not available: {err}"),
)?;
let _ = tx.send(AgentEvent::TurnFinished);
return Ok(conversation);
}
};
let reasoning_request_format = settings
.config
.model_metadata
.as_ref()
.map(|model| model.reasoning.request_format)
.unwrap_or_default();
let reasoning_effort = settings
.reasoning_effort
.clamp_for_model(settings.config.model_metadata.as_ref());
let provider = OpenAiCompatibleProvider::new(OpenAiCompatibleSettings {
model: settings.config.model.clone(),
base_url: settings.config.active_provider.base_url.clone(),
api_key,
reasoning_effort,
reasoning_request_format,
});
let docs_dir = settings.config.docs_dir();
let tool_ctx = ToolContext {
+226 -14
View File
@@ -1,6 +1,6 @@
use crate::agent::{self, AgentCommand, AgentEvent, AgentSettings};
use crate::cli::{self, Cli, Command};
use crate::config::{self, Config, ModelDefinition, ReasoningEffort};
use crate::config::{self, Config, FastModeState, ModelDefinition, ReasoningEffort};
use crate::conversation::{self, Conversation, Record};
use crate::prompt;
use crate::ui::autofill::{AutoFillItem, AutoFillMenu};
@@ -80,7 +80,7 @@ pub async fn run() -> Result<()> {
return Ok(());
}
if config.resolved_api_key().is_err() {
if config.ensure_provider_auth().is_err() {
let outcome = crate::setup::run(&cli, crate::setup::SetupMode::Auto).await?;
if !outcome.start_session {
return Ok(());
@@ -397,6 +397,7 @@ async fn run_tui(
show_full_tools,
show_reasoning,
reasoning_effort,
fast_mode_active: config.fast_mode_state().active,
scroll,
autofill: if branch_menu.is_some() {
None
@@ -862,10 +863,46 @@ async fn run_tui(
}
}
}
Ok(LocalCommand::Fast(command)) => {
if busy {
status = "fast mode can be changed when idle".into();
} else {
input.clear();
autofill_selected = 0;
match apply_fast_mode_command(&mut config, command) {
Ok(message) => {
transcript.push(TranscriptBlock {
kind: TranscriptKind::Status,
title: "fast".into(),
content: message.clone(),
});
status = message;
}
Err(err) => {
status =
format!("fast mode update failed: {err}");
transcript.push(TranscriptBlock {
kind: TranscriptKind::Error,
title: "fast".into(),
content: err.to_string(),
});
}
}
if stick_to_bottom {
scroll = bottom_scroll(
&terminal,
&input,
&transcript,
show_full_tools,
show_reasoning,
)?;
}
}
}
Ok(LocalCommand::Status) => {
let content = chat_status(
&chat_id,
&config.model,
&config,
mode,
&cwd,
busy,
@@ -894,14 +931,13 @@ async fn run_tui(
if busy {
status = "model can be changed when idle".into();
} else {
config.model = model.clone();
config.model_metadata =
model_metadata_for(&config, &model)?;
apply_model_selection(&mut config, &model)?;
reasoning_effort = ReasoningEffort::default_for_model(
config.model_metadata.as_ref(),
);
let _ = crate::config::save_last_used(
let _ = crate::config::save_last_used_provider(
&config.root,
&config.provider_id,
&config.model,
reasoning_effort,
);
@@ -910,9 +946,9 @@ async fn run_tui(
transcript.push(TranscriptBlock {
kind: TranscriptKind::Status,
title: "model".into(),
content: format!("model changed to {model}"),
content: model_status_message(&config),
});
status = format!("model: {model}");
status = model_status_message(&config);
if stick_to_bottom {
scroll = bottom_scroll(
&terminal,
@@ -1885,6 +1921,7 @@ fn assistant_content_matches(a: &str, b: &str) -> bool {
#[derive(Debug, Clone, PartialEq, Eq)]
enum LocalCommand {
Branch,
Fast(FastModeCommand),
Login,
Logout,
Model(String),
@@ -1893,6 +1930,14 @@ enum LocalCommand {
Status,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum FastModeCommand {
Toggle,
On,
Off,
Status,
}
struct CommandSpec {
name: &'static str,
usage: &'static str,
@@ -1907,6 +1952,12 @@ const COMMANDS: &[CommandSpec] = &[
description: "open branch/restore menu",
takes_value: false,
},
CommandSpec {
name: "fast",
usage: "/fast [on|off|status]",
description: "toggle faster Codex inference when supported",
takes_value: false,
},
CommandSpec {
name: "login",
usage: "/login",
@@ -2038,14 +2089,38 @@ fn model_autofill(input: &str, selected: usize, config: &Config) -> Result<Optio
}
}
fn model_metadata_for(config: &Config, model_id: &str) -> Result<Option<ModelDefinition>> {
fn apply_model_selection(config: &mut Config, model_id: &str) -> Result<()> {
let models = crate::config::load_or_create_default_model_registry(&config.root)?;
Ok(models
let metadata = models
.models
.iter()
.find(|model| model.id == model_id && model.provider == config.provider_id)
.cloned()
.or_else(|| models.models.into_iter().find(|model| model.id == model_id)))
.or_else(|| {
models
.models
.iter()
.find(|model| model.id == model_id)
.cloned()
});
if let Some(model) = &metadata {
if model.provider != config.provider_id {
let providers = crate::config::load_or_create_default_provider_registry(&config.root)?;
if let Some(provider) = providers
.providers
.iter()
.find(|provider| provider.id == model.provider)
{
config.provider_id = provider.id.clone();
config.active_provider = provider.to_resolved();
}
}
}
config.model = model_id.to_string();
config.model_metadata = metadata;
Ok(())
}
fn model_matches(model: &ModelDefinition, query: &str) -> bool {
@@ -2175,6 +2250,19 @@ fn parse_local_command(input: &str) -> std::result::Result<LocalCommand, String>
}
Ok(LocalCommand::Branch)
}
"/fast" => {
let command = match parts.next() {
None => FastModeCommand::Toggle,
Some("on") => FastModeCommand::On,
Some("off") => FastModeCommand::Off,
Some("status") => FastModeCommand::Status,
Some(_) => return Err("usage: /fast [on|off|status]".into()),
};
if parts.next().is_some() {
return Err("usage: /fast [on|off|status]".into());
}
Ok(LocalCommand::Fast(command))
}
"/login" => {
if parts.next().is_some() {
return Err("usage: /login".into());
@@ -2223,7 +2311,7 @@ fn parse_local_command(input: &str) -> std::result::Result<LocalCommand, String>
fn chat_status(
chat_id: &str,
model: &str,
config: &Config,
mode: crate::access::AccessMode,
cwd: &Path,
busy: bool,
@@ -2231,13 +2319,76 @@ fn chat_status(
record_count: usize,
) -> String {
format!(
"chat: {chat_id}\nstate: {}\nmodel: {model}\nmode: {mode}\ncwd: {}\nrecords: {record_count}\nstatus: {}",
"chat: {chat_id}\nstate: {}\nmodel: {}\nfast: {}\nmode: {mode}\ncwd: {}\nrecords: {record_count}\nstatus: {}",
if busy { "running" } else { "idle" },
config.model,
fast_mode_status(&config.fast_mode_state()),
cwd.display(),
if status.is_empty() { "idle" } else { status }
)
}
fn apply_fast_mode_command(config: &mut Config, command: FastModeCommand) -> Result<String> {
match command {
FastModeCommand::Status => Ok(fast_mode_status(&config.fast_mode_state())),
FastModeCommand::Toggle | FastModeCommand::On | FastModeCommand::Off => {
let enabled = match command {
FastModeCommand::Toggle => !config.default_fast_mode,
FastModeCommand::On => true,
FastModeCommand::Off => false,
FastModeCommand::Status => unreachable!(),
};
crate::config::save_fast_mode_preference(&config.root, enabled)?;
config.default_fast_mode = enabled;
Ok(fast_mode_change_message(&config.fast_mode_state()))
}
}
}
fn fast_mode_change_message(state: &FastModeState) -> String {
if state.active {
"fast mode enabled".into()
} else if state.preferred {
format!(
"fast mode preference on; unavailable for {}",
state
.unavailable_reason
.as_deref()
.unwrap_or("this provider/model")
)
} else {
"fast mode off".into()
}
}
fn fast_mode_status(state: &FastModeState) -> String {
if state.active {
"enabled".into()
} else if state.preferred {
format!(
"preferred, unavailable for {}",
state
.unavailable_reason
.as_deref()
.unwrap_or("this provider/model")
)
} else {
"off".into()
}
}
fn model_status_message(config: &Config) -> String {
let model = &config.model;
let state = config.fast_mode_state();
if state.active {
format!("model: {model} · fast enabled")
} else if state.preferred {
format!("model: {model} · fast unavailable")
} else {
format!("model: {model}")
}
}
fn transcript_from_loaded(
conversation: &Conversation,
warning: Option<String>,
@@ -2667,6 +2818,67 @@ mod tests {
);
}
#[test]
fn parse_local_command_accepts_fast_forms() {
assert_eq!(
parse_local_command("/fast").unwrap(),
LocalCommand::Fast(FastModeCommand::Toggle)
);
assert_eq!(
parse_local_command("/fast on").unwrap(),
LocalCommand::Fast(FastModeCommand::On)
);
assert_eq!(
parse_local_command("/fast off").unwrap(),
LocalCommand::Fast(FastModeCommand::Off)
);
assert_eq!(
parse_local_command("/fast status").unwrap(),
LocalCommand::Fast(FastModeCommand::Status)
);
assert_eq!(
parse_local_command("/fast maybe"),
Err("usage: /fast [on|off|status]".into())
);
}
#[test]
fn fast_mode_status_distinguishes_preference_and_activation() {
let mut config = Config {
default_fast_mode: true,
..Config::default()
};
assert_eq!(
fast_mode_status(&config.fast_mode_state()),
"preferred, unavailable for provider fireworks"
);
config.provider_id = config::CHATGPT_CODEX_PROVIDER_ID.into();
config.active_provider.kind = config::CHATGPT_CODEX_PROVIDER_KIND.into();
config.model = config::CHATGPT_CODEX_DEFAULT_MODEL.into();
config.model_metadata = Some(config::ModelDefinition {
id: config::CHATGPT_CODEX_DEFAULT_MODEL.into(),
provider: config::CHATGPT_CODEX_PROVIDER_ID.into(),
display_name: None,
context_length: None,
max_output_tokens: None,
supports_tools: true,
supports_streaming: true,
reasoning: Default::default(),
fast_mode: config::FastModeMetadata { supported: true },
});
assert_eq!(fast_mode_status(&config.fast_mode_state()), "enabled");
assert_eq!(
model_status_message(&config),
format!(
"model: {} · fast enabled",
config::CHATGPT_CODEX_DEFAULT_MODEL
)
);
}
#[test]
fn cancelled_turn_repairs_missing_tool_results() {
let root = tempdir().unwrap();
+65 -4
View File
@@ -1,5 +1,9 @@
use crate::cli::Cli;
use crate::config::{self, ApiKeyReference, Config, ModelsFile, ProvidersFile};
use crate::codex_auth;
use crate::config::{
self, ApiKeyReference, Config, ModelsFile, ProvidersFile, CHATGPT_CODEX_PROVIDER_KIND,
DEFAULT_PROVIDER_KIND,
};
use anyhow::{Context, Result};
use std::fs;
use std::path::{Path, PathBuf};
@@ -72,6 +76,9 @@ impl CheckReport {
"cass".into(),
];
}
if error.contains("Codex auth") {
return vec!["codex login".into(), "cass check".into(), "cass".into()];
}
}
vec!["cass setup".into()]
}
@@ -191,29 +198,83 @@ fn check_active_config(report: &mut CheckReport, cfg: &Config, providers: &Provi
report
.successes
.push(format!("active provider: {}", cfg.provider_id));
let endpoint_label = if cfg.active_provider.kind == CHATGPT_CODEX_PROVIDER_KIND {
"active provider endpoint"
} else {
"active provider base URL"
};
report.successes.push(format!(
"active provider base URL: {}",
"{endpoint_label}: {}",
cfg.active_provider.base_url
));
report
.successes
.push(format!("active model: {}", cfg.model));
check_api_key(report, "api key", &cfg.active_provider.api_key, true);
check_provider_auth(
report,
"api key",
&cfg.active_provider.kind,
&cfg.active_provider.api_key,
true,
);
for provider in &providers.providers {
if provider.id == cfg.provider_id {
continue;
}
check_api_key(
check_provider_auth(
report,
&format!("provider `{}` api key", provider.id),
&provider.kind,
&provider.api_key,
false,
);
}
}
fn check_provider_auth(
report: &mut CheckReport,
label: &str,
kind: &str,
api_key: &str,
active: bool,
) {
match kind {
DEFAULT_PROVIDER_KIND => check_api_key(report, label, api_key, active),
CHATGPT_CODEX_PROVIDER_KIND => check_codex_auth(report, active),
_ if active => report
.errors
.push(format!("provider kind `{kind}` is unsupported")),
_ => report
.warnings
.push(format!("provider kind `{kind}` is unsupported")),
}
}
fn check_codex_auth(report: &mut CheckReport, active: bool) {
let status = codex_auth::check_codex_auth();
if status.is_usable() {
if active {
report
.successes
.push(format!("Codex auth: {}", status.summary()));
}
} else if active {
report.errors.push(format!(
"Codex auth: {}. {}",
status.summary(),
status.recovery_hint()
));
} else {
report.warnings.push(format!(
"Codex auth: {}. {}",
status.summary(),
status.recovery_hint()
));
}
}
fn check_api_key(report: &mut CheckReport, label: &str, spec: &str, active: bool) {
match config::api_key_reference(spec) {
Ok(ApiKeyReference::Env(name)) => match std::env::var(&name) {
+311
View File
@@ -0,0 +1,311 @@
use anyhow::{bail, Context, Result};
use serde::Deserialize;
use serde_json::Value;
use std::fs;
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
#[derive(Debug, Clone)]
pub struct CodexAccessToken {
value: String,
}
impl CodexAccessToken {
pub fn new(value: String) -> Result<Self> {
if value.trim().is_empty() {
bail!("Codex access token is empty");
}
Ok(Self { value })
}
pub fn as_secret(&self) -> &str {
&self.value
}
pub fn redacted(&self) -> &'static str {
"<Codex access token>"
}
}
impl std::fmt::Display for CodexAccessToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.redacted())
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CodexAuthStatus {
pub path: PathBuf,
pub auth_mode: Option<String>,
pub has_access_token: bool,
pub expires_at: Option<i64>,
pub expired: bool,
pub error: Option<String>,
}
impl CodexAuthStatus {
pub fn is_usable(&self) -> bool {
self.error.is_none() && self.has_access_token && !self.expired
}
pub fn recovery_hint(&self) -> &'static str {
"Run `codex login` or sign in with the Codex app, then rerun `cass check`."
}
pub fn summary(&self) -> String {
if self.is_usable() {
if let Some(auth_mode) = &self.auth_mode {
format!(
"{} contains an access token (auth mode: {auth_mode})",
pretty_path(&self.path)
)
} else {
format!("{} contains an access token", pretty_path(&self.path))
}
} else if let Some(error) = &self.error {
format!("{}: {error}", pretty_path(&self.path))
} else if self.expired {
format!(
"{} contains an expired access token",
pretty_path(&self.path)
)
} else {
format!(
"{} does not contain an access token",
pretty_path(&self.path)
)
}
}
}
#[derive(Debug, Deserialize)]
struct CodexAuthFile {
auth_mode: Option<String>,
tokens: Option<CodexTokens>,
}
#[derive(Debug, Deserialize)]
struct CodexTokens {
access_token: Option<String>,
}
pub fn codex_home() -> PathBuf {
std::env::var_os("CODEX_HOME")
.map(PathBuf::from)
.or_else(|| dirs::home_dir().map(|home| home.join(".codex")))
.unwrap_or_else(|| PathBuf::from(".codex"))
}
pub fn codex_auth_path() -> PathBuf {
std::env::var_os("CODEX_AUTH_FILE")
.map(PathBuf::from)
.unwrap_or_else(|| codex_home().join("auth.json"))
}
pub fn codex_config_path() -> PathBuf {
std::env::var_os("CODEX_CONFIG_FILE")
.map(PathBuf::from)
.unwrap_or_else(|| codex_home().join("config.toml"))
}
pub fn load_codex_access_token() -> Result<CodexAccessToken> {
load_codex_access_token_from_path(&codex_auth_path())
}
pub fn load_codex_access_token_from_path(path: &Path) -> Result<CodexAccessToken> {
let text = fs::read_to_string(path).with_context(|| {
format!(
"Codex auth not found at {}; run `codex login` or sign in with the Codex app",
pretty_path(path)
)
})?;
let parsed: CodexAuthFile = serde_json::from_str(&text)
.with_context(|| format!("parsing Codex auth at {}", pretty_path(path)))?;
let token = parsed
.tokens
.and_then(|tokens| tokens.access_token)
.filter(|token| !token.trim().is_empty())
.with_context(|| {
format!(
"no access token found in {}; run `codex login` or sign in with the Codex app",
pretty_path(path)
)
})?;
if jwt_is_expired(&token) == Some(true) {
bail!(
"Codex access token in {} is expired; run `codex login` or sign in with the Codex app",
pretty_path(path)
);
}
CodexAccessToken::new(token)
}
pub fn check_codex_auth() -> CodexAuthStatus {
check_codex_auth_at(&codex_auth_path())
}
pub fn check_codex_auth_at(path: &Path) -> CodexAuthStatus {
let mut status = CodexAuthStatus {
path: path.to_path_buf(),
auth_mode: None,
has_access_token: false,
expires_at: None,
expired: false,
error: None,
};
let text = match fs::read_to_string(path) {
Ok(text) => text,
Err(err) => {
status.error = Some(format!("not readable ({err})"));
return status;
}
};
let parsed: CodexAuthFile = match serde_json::from_str(&text) {
Ok(parsed) => parsed,
Err(err) => {
status.error = Some(format!("invalid JSON ({err})"));
return status;
}
};
status.auth_mode = parsed.auth_mode;
let token = parsed
.tokens
.and_then(|tokens| tokens.access_token)
.filter(|token| !token.trim().is_empty());
if let Some(token) = token {
status.has_access_token = true;
status.expires_at = jwt_expiration(&token);
status.expired = jwt_is_expired(&token).unwrap_or(false);
}
status
}
pub fn read_codex_default_model() -> Option<String> {
read_codex_default_model_from_path(&codex_config_path())
}
pub fn read_codex_default_model_from_path(path: &Path) -> Option<String> {
let text = fs::read_to_string(path).ok()?;
for line in text.lines() {
let line = line.trim();
if line.starts_with('#') || !line.starts_with("model") {
continue;
}
let Some((key, value)) = line.split_once('=') else {
continue;
};
if key.trim() != "model" {
continue;
}
let value = value.trim();
let value = value
.strip_prefix('"')
.and_then(|v| v.strip_suffix('"'))
.or_else(|| value.strip_prefix('\'').and_then(|v| v.strip_suffix('\'')))
.unwrap_or(value)
.trim();
if !value.is_empty() {
return Some(value.to_string());
}
}
None
}
fn jwt_is_expired(token: &str) -> Option<bool> {
let exp = jwt_expiration(token)?;
let now = SystemTime::now().duration_since(UNIX_EPOCH).ok()?.as_secs() as i64;
Some(exp <= now)
}
fn jwt_expiration(token: &str) -> Option<i64> {
let mut parts = token.split('.');
let _header = parts.next()?;
let payload = parts.next()?;
let bytes = base64_url_decode(payload).ok()?;
let json: Value = serde_json::from_slice(&bytes).ok()?;
json.get("exp")?.as_i64()
}
fn base64_url_decode(input: &str) -> Result<Vec<u8>, String> {
let mut bits = 0u32;
let mut bit_count = 0u8;
let mut out = Vec::new();
for byte in input.bytes() {
let value = match byte {
b'A'..=b'Z' => byte - b'A',
b'a'..=b'z' => byte - b'a' + 26,
b'0'..=b'9' => byte - b'0' + 52,
b'-' | b'+' => 62,
b'_' | b'/' => 63,
b'=' => break,
_ => return Err("invalid base64 character".into()),
} as u32;
bits = (bits << 6) | value;
bit_count += 6;
if bit_count >= 8 {
bit_count -= 8;
out.push(((bits >> bit_count) & 0xff) as u8);
}
}
Ok(out)
}
pub fn pretty_path(path: &Path) -> String {
if let Some(home) = dirs::home_dir() {
if let Ok(rest) = path.strip_prefix(&home) {
return format!("~/{}", rest.display());
}
}
path.display().to_string()
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
#[test]
fn reads_access_token_without_displaying_it() {
let dir = tempdir().unwrap();
let path = dir.path().join("auth.json");
fs::write(
&path,
r#"{"auth_mode":"chatgpt","tokens":{"access_token":"secret-token"}}"#,
)
.unwrap();
let token = load_codex_access_token_from_path(&path).unwrap();
assert_eq!(token.as_secret(), "secret-token");
assert_eq!(token.to_string(), "<Codex access token>");
}
#[test]
fn check_reports_missing_token_without_secret_fields() {
let dir = tempdir().unwrap();
let path = dir.path().join("auth.json");
fs::write(
&path,
r#"{"tokens":{"refresh_token":"refresh-secret","account_id":"acct"}}"#,
)
.unwrap();
let status = check_codex_auth_at(&path);
assert!(!status.is_usable());
let summary = status.summary();
assert!(!summary.contains("refresh-secret"));
assert!(!summary.contains("acct"));
}
#[test]
fn reads_model_from_codex_config() {
let dir = tempdir().unwrap();
let path = dir.path().join("config.toml");
fs::write(&path, "model = \"gpt-test\"\n").unwrap();
assert_eq!(
read_codex_default_model_from_path(&path).as_deref(),
Some("gpt-test")
);
}
}
+120 -5
View File
@@ -9,6 +9,11 @@ use std::path::{Path, PathBuf};
pub const DEFAULT_PROVIDER_ID: &str = "fireworks";
pub const DEFAULT_PROVIDER_NAME: &str = "Fireworks";
pub const DEFAULT_PROVIDER_KIND: &str = "openai-compatible";
pub const CHATGPT_CODEX_PROVIDER_ID: &str = "chatgpt-codex";
pub const CHATGPT_CODEX_PROVIDER_NAME: &str = "ChatGPT Codex";
pub const CHATGPT_CODEX_PROVIDER_KIND: &str = "chatgpt-codex";
pub const CHATGPT_CODEX_RESPONSES_URL: &str = "https://chatgpt.com/backend-api/codex/responses";
pub const CHATGPT_CODEX_DEFAULT_MODEL: &str = "gpt-5.5";
pub const DEFAULT_MODEL: &str = "accounts/fireworks/models/qwen3p7-plus";
pub const DEFAULT_BASE_URL: &str = "https://api.fireworks.ai/inference/v1";
pub const DEFAULT_API_KEY_ENV: &str = "FIREWORKS_API_KEY";
@@ -22,6 +27,8 @@ pub struct ConfigFile {
pub default_model: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub default_reasoning_effort: Option<ReasoningEffort>,
#[serde(skip_serializing_if = "Option::is_none")]
pub default_fast_mode: Option<bool>,
// Deprecated compatibility fields accepted from older config.json files.
#[serde(skip_serializing_if = "Option::is_none")]
@@ -61,6 +68,7 @@ pub struct ProviderDefinition {
pub name: Option<String>,
pub kind: String,
pub base_url: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub api_key: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub default_model: Option<String>,
@@ -91,6 +99,8 @@ pub struct ModelDefinition {
pub supports_streaming: bool,
#[serde(default)]
pub reasoning: ReasoningMetadata,
#[serde(default)]
pub fast_mode: FastModeMetadata,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -106,6 +116,13 @@ pub struct ReasoningMetadata {
pub request_format: ReasoningRequestFormat,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FastModeMetadata {
#[serde(default)]
pub supported: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ReasoningEffort {
@@ -128,7 +145,7 @@ pub struct ResolvedProviderConfig {
pub name: Option<String>,
pub kind: String,
pub base_url: String,
/// Either a literal API key or an env-var reference like "$FIREWORKS_API_KEY".
/// Either a literal API key, an env-var reference like "$FIREWORKS_API_KEY", or empty for provider kinds that use external local auth.
pub api_key: String,
pub default_model: Option<String>,
pub models: Vec<String>,
@@ -139,6 +156,7 @@ pub struct Config {
pub provider_id: String,
pub model: String,
pub reasoning_effort: ReasoningEffort,
pub default_fast_mode: bool,
pub active_provider: ResolvedProviderConfig,
pub model_metadata: Option<ModelDefinition>,
pub default_access_mode: AccessMode,
@@ -151,6 +169,14 @@ pub struct Config {
pub docs_dir: PathBuf,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FastModeState {
pub preferred: bool,
pub supported: bool,
pub active: bool,
pub unavailable_reason: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct ConfigOverrides {
pub model: Option<String>,
@@ -196,6 +222,12 @@ impl Default for ReasoningMetadata {
}
}
impl Default for FastModeMetadata {
fn default() -> Self {
Self { supported: false }
}
}
impl Default for ReasoningRequestFormat {
fn default() -> Self {
Self::ReasoningEffort
@@ -281,6 +313,7 @@ impl Default for Config {
provider_id: DEFAULT_PROVIDER_ID.to_string(),
model: DEFAULT_MODEL.to_string(),
reasoning_effort: ReasoningEffort::Medium,
default_fast_mode: false,
active_provider,
model_metadata: Some(default_model_definition()),
default_access_mode: AccessMode::ReadOnly,
@@ -368,6 +401,9 @@ impl Config {
if let Some(v) = file.confirm_destructive_operations {
cfg.confirm_destructive_operations = v;
}
if let Some(v) = file.default_fast_mode {
cfg.default_fast_mode = v;
}
}
if let Some(access_mode) = overrides.access_mode {
@@ -429,6 +465,49 @@ impl Config {
pub fn resolved_api_key(&self) -> Result<String> {
resolve_api_key(&self.active_provider.api_key)
}
pub fn ensure_provider_auth(&self) -> Result<()> {
match self.active_provider.kind.as_str() {
DEFAULT_PROVIDER_KIND => self.resolved_api_key().map(|_| ()),
CHATGPT_CODEX_PROVIDER_KIND => crate::codex_auth::load_codex_access_token().map(|_| ()),
kind => bail!("unsupported provider kind `{kind}`"),
}
}
pub fn fast_mode_state(&self) -> FastModeState {
let preferred = self.default_fast_mode;
let supported = self.fast_mode_supported();
let active = preferred && supported;
let unavailable_reason = if preferred && !supported {
Some(self.fast_mode_unavailable_reason())
} else {
None
};
FastModeState {
preferred,
supported,
active,
unavailable_reason,
}
}
fn fast_mode_supported(&self) -> bool {
if self.active_provider.kind == CHATGPT_CODEX_PROVIDER_KIND {
return true;
}
self.model_metadata
.as_ref()
.is_some_and(|model| model.fast_mode.supported)
}
fn fast_mode_unavailable_reason(&self) -> String {
if self.active_provider.kind != CHATGPT_CODEX_PROVIDER_KIND {
format!("provider {}", self.provider_id)
} else {
format!("model {}", self.model)
}
}
}
impl ProviderDefinition {
@@ -469,6 +548,28 @@ pub fn save_last_used(root: &Path, model: &str, reasoning_effort: ReasoningEffor
file.default_reasoning_effort = Some(reasoning_effort);
write_json_pretty(&path, &file)
}
pub fn save_last_used_provider(
root: &Path,
provider_id: &str,
model: &str,
reasoning_effort: ReasoningEffort,
) -> Result<()> {
let path = config_path(root);
let mut file = load_config_file(root)?.unwrap_or_default();
file.default_provider = Some(provider_id.to_string());
file.default_model = Some(model.to_string());
file.default_reasoning_effort = Some(reasoning_effort);
write_json_pretty(&path, &file)
}
pub fn save_fast_mode_preference(root: &Path, enabled: bool) -> Result<()> {
let path = config_path(root);
let mut file = load_config_file(root)?.unwrap_or_default();
file.default_fast_mode = Some(enabled);
write_json_pretty(&path, &file)
}
pub fn load_or_create_default_provider_registry(root: &Path) -> Result<ProvidersFile> {
fs::create_dir_all(root).with_context(|| format!("creating {}", root.display()))?;
let path = providers_path(root);
@@ -519,6 +620,7 @@ pub fn default_model_definition() -> ModelDefinition {
supports_tools: true,
supports_streaming: true,
reasoning: ReasoningMetadata::default(),
fast_mode: FastModeMetadata::default(),
}
}
@@ -535,6 +637,10 @@ pub fn api_key_reference(spec: &str) -> Result<ApiKeyReference> {
Ok(ApiKeyReference::Literal)
}
pub fn is_supported_provider_kind(kind: &str) -> bool {
matches!(kind, DEFAULT_PROVIDER_KIND | CHATGPT_CODEX_PROVIDER_KIND)
}
pub fn resolve_api_key(spec: &str) -> Result<String> {
match api_key_reference(spec)? {
ApiKeyReference::Env(name) => {
@@ -576,7 +682,7 @@ pub fn validate_registries(
"providers.json: provider `{}` kind must not be empty",
provider.id
));
} else if provider.kind != DEFAULT_PROVIDER_KIND {
} else if !is_supported_provider_kind(&provider.kind) {
out.errors.push(format!(
"providers.json: provider `{}` uses unsupported kind `{}`",
provider.id, provider.kind
@@ -593,9 +699,18 @@ pub fn validate_registries(
provider.id
));
}
if let Err(err) = api_key_reference(&provider.api_key) {
out.errors.push(format!(
"providers.json: provider `{}` has invalid api_key: {err}",
if provider.kind == DEFAULT_PROVIDER_KIND {
if let Err(err) = api_key_reference(&provider.api_key) {
out.errors.push(format!(
"providers.json: provider `{}` has invalid api_key: {err}",
provider.id
));
}
} else if provider.kind == CHATGPT_CODEX_PROVIDER_KIND
&& !provider.api_key.trim().is_empty()
{
out.warnings.push(format!(
"providers.json: provider `{}` ignores api_key because ChatGPT Codex uses local Codex auth",
provider.id
));
}
+1 -1
View File
@@ -157,7 +157,7 @@ impl SessionBuilder {
access_mode: self.access_mode,
};
let config = Config::load_with_overrides(root, overrides).map_err(Error::config)?;
config.resolved_api_key().map_err(Error::config)?;
config.ensure_provider_auth().map_err(Error::config)?;
let cwd = resolve_cwd(self.cwd).map_err(Error::config)?;
let mode = config.default_access_mode;
let reasoning_effort = self
+1
View File
@@ -4,6 +4,7 @@ pub mod app;
pub mod branch;
pub mod check;
pub mod cli;
pub mod codex_auth;
pub mod config;
pub mod conversation;
pub mod docs;
+544
View File
@@ -0,0 +1,544 @@
use super::types::{CompletionResult, ModelMessage};
use crate::agent::AgentEvent;
use crate::codex_auth::load_codex_access_token;
use crate::config::{ReasoningEffort, CHATGPT_CODEX_RESPONSES_URL};
use crate::conversation::StoredToolCall;
use crate::tools::ToolSpec;
use anyhow::{bail, Result};
use futures_util::StreamExt;
use reqwest::Client;
use serde_json::{json, Value};
use std::collections::BTreeMap;
use tokio::sync::mpsc;
#[derive(Debug, Clone)]
pub struct ChatGptCodexProvider {
client: Client,
model: String,
endpoint: String,
reasoning_effort: ReasoningEffort,
fast_mode: bool,
}
#[derive(Debug, Clone)]
pub struct ChatGptCodexSettings {
pub model: String,
pub endpoint: String,
pub reasoning_effort: ReasoningEffort,
pub fast_mode: bool,
}
#[derive(Debug, Default, Clone)]
struct PartialFunctionCall {
call_id: Option<String>,
name: Option<String>,
arguments: String,
}
impl ChatGptCodexProvider {
pub fn new(settings: ChatGptCodexSettings) -> Self {
Self {
client: Client::new(),
model: settings.model,
endpoint: normalize_endpoint(&settings.endpoint),
reasoning_effort: settings.reasoning_effort,
fast_mode: settings.fast_mode,
}
}
pub async fn complete(
&self,
messages: Vec<ModelMessage>,
tools: Vec<ToolSpec>,
tx: &mpsc::UnboundedSender<AgentEvent>,
) -> Result<CompletionResult> {
let token = load_codex_access_token()?;
let secret = token.as_secret().to_string();
let body = responses_body(
&self.model,
messages,
tools,
self.reasoning_effort,
self.fast_mode,
);
let resp = self
.client
.post(&self.endpoint)
.bearer_auth(token.as_secret())
.json(&body)
.send()
.await?;
if !resp.status().is_success() {
let status = resp.status();
let text = resp.text().await.unwrap_or_default();
bail!(
"ChatGPT Codex returned {status}: {}",
redact_secret(&text, &secret)
);
}
let mut state = StreamState::default();
let mut buf = String::new();
let mut stream = resp.bytes_stream();
while let Some(chunk) = stream.next().await {
let chunk = chunk?;
let chunk_text = String::from_utf8_lossy(&chunk).replace("\r\n", "\n");
buf.push_str(&chunk_text);
while let Some(pos) = buf.find("\n\n") {
let frame = buf[..pos].to_string();
buf = buf[pos + 2..].to_string();
process_frame(&frame, &mut state, tx)?;
}
}
if !buf.trim().is_empty() {
process_frame(&buf, &mut state, tx)?;
}
Ok(state.finish())
}
}
#[derive(Debug, Default)]
struct StreamState {
content: String,
reasoning: String,
reasoning_field: Option<String>,
partials: BTreeMap<String, PartialFunctionCall>,
}
impl StreamState {
fn finish(self) -> CompletionResult {
let tool_calls = self
.partials
.into_iter()
.filter_map(|(key, partial)| {
let name = partial.name?;
let id = partial.call_id.unwrap_or(key);
let arguments = serde_json::from_str(&partial.arguments)
.unwrap_or_else(|_| json!({"_raw": partial.arguments}));
Some(StoredToolCall {
id,
name,
arguments,
})
})
.collect();
CompletionResult {
content: self.content,
reasoning: self.reasoning,
reasoning_field: self.reasoning_field,
tool_calls,
}
}
}
fn responses_body(
model: &str,
messages: Vec<ModelMessage>,
tools: Vec<ToolSpec>,
reasoning_effort: ReasoningEffort,
fast_mode: bool,
) -> Value {
let mut instructions = Vec::new();
let mut input = Vec::new();
for message in messages {
match message {
ModelMessage::System { content } => instructions.push(content),
ModelMessage::User { content } => input.push(json!({
"type": "message",
"role": "user",
"content": [{"type": "input_text", "text": content}]
})),
ModelMessage::Assistant {
content,
reasoning: _,
reasoning_field: _,
tool_calls,
} => {
if !content.is_empty() {
input.push(json!({
"type": "message",
"role": "assistant",
"content": [{"type": "output_text", "text": content}]
}));
}
for call in tool_calls {
input.push(json!({
"type": "function_call",
"call_id": call.id,
"name": call.name,
"arguments": call.arguments.to_string()
}));
}
}
ModelMessage::Tool {
tool_call_id,
name: _,
content,
} => input.push(json!({
"type": "function_call_output",
"call_id": tool_call_id,
"output": content
})),
}
}
let mut body = json!({
"model": model,
"input": input,
"tools": tools_to_responses(tools),
"stream": true,
"store": false
});
if !instructions.is_empty() {
body["instructions"] = Value::String(instructions.join("\n\n"));
}
if fast_mode {
body["reasoning"] = json!({"effort": "minimal", "summary": "auto"});
} else if let Some(effort) = reasoning_effort.request_value() {
body["reasoning"] = json!({"effort": effort, "summary": "auto"});
} else if reasoning_effort == ReasoningEffort::Off {
body["reasoning"] = json!({"effort": "none", "summary": "auto"});
}
body
}
fn tools_to_responses(tools: Vec<ToolSpec>) -> Vec<Value> {
tools
.into_iter()
.map(|tool| {
json!({
"type": "function",
"name": tool.name,
"description": tool.description,
"parameters": tool.parameters
})
})
.collect()
}
fn process_frame(
frame: &str,
state: &mut StreamState,
tx: &mpsc::UnboundedSender<AgentEvent>,
) -> Result<()> {
for line in frame.lines() {
let line = line.trim();
if !line.starts_with("data:") {
continue;
}
let data = line.trim_start_matches("data:").trim();
if data == "[DONE]" || data.is_empty() {
continue;
}
let value: Value = serde_json::from_str(data)?;
handle_event(&value, state, tx)?;
}
Ok(())
}
fn handle_event(
value: &Value,
state: &mut StreamState,
tx: &mpsc::UnboundedSender<AgentEvent>,
) -> Result<()> {
let event_type = value
.get("type")
.and_then(Value::as_str)
.unwrap_or_default();
match event_type {
"response.output_text.delta" | "response.message.delta" | "output_text.delta" => {
if let Some(delta) = string_field(value, &["delta", "text"]) {
push_content(state, tx, delta);
}
}
"response.reasoning_summary_text.delta"
| "response.reasoning_text.delta"
| "response.reasoning.delta"
| "reasoning.delta" => {
if let Some(delta) = string_field(value, &["delta", "text"]) {
push_reasoning(state, tx, "reasoning_summary", delta);
}
}
"response.function_call_arguments.delta" | "function_call_arguments.delta" => {
let key = event_key(value);
let partial = state.partials.entry(key).or_default();
if let Some(delta) = string_field(value, &["delta", "arguments_delta"]) {
partial.arguments.push_str(delta);
}
}
"response.function_call_arguments.done" | "function_call_arguments.done" => {
let key = event_key(value);
let partial = state.partials.entry(key).or_default();
if let Some(arguments) = string_field(value, &["arguments"]) {
partial.arguments = arguments.to_string();
}
if let Some(call_id) = string_field(value, &["call_id", "id"]) {
partial.call_id = Some(call_id.to_string());
}
if let Some(name) = string_field(value, &["name"]) {
partial.name = Some(name.to_string());
}
}
"response.output_item.added"
| "response.output_item.done"
| "output_item.added"
| "output_item.done" => {
if let Some(item) = value.get("item") {
handle_item(item, state, tx, event_type.ends_with("done"));
}
}
"response.completed" | "response.done" => {
if state.content.is_empty() {
if let Some(response) = value.get("response") {
extract_final_response(response, state, tx);
}
}
}
_ => {
if let Some(item) = value.get("item") {
handle_item(item, state, tx, false);
} else if let Some(delta) = value
.get("delta")
.and_then(Value::as_str)
.filter(|_| event_type.contains("output_text"))
{
push_content(state, tx, delta);
}
}
}
Ok(())
}
fn handle_item(
item: &Value,
state: &mut StreamState,
tx: &mpsc::UnboundedSender<AgentEvent>,
final_item: bool,
) {
match item.get("type").and_then(Value::as_str).unwrap_or_default() {
"message" => {
if final_item && state.content.is_empty() {
for content in item
.get("content")
.and_then(Value::as_array)
.into_iter()
.flatten()
{
if matches!(
content.get("type").and_then(Value::as_str),
Some("output_text")
) {
if let Some(text) = content.get("text").and_then(Value::as_str) {
push_content(state, tx, text);
}
}
}
}
}
"reasoning" => {
for summary in item
.get("summary")
.and_then(Value::as_array)
.into_iter()
.flatten()
{
if let Some(text) = summary.get("text").and_then(Value::as_str) {
push_reasoning(state, tx, "reasoning_summary", text);
}
}
}
"function_call" => {
let key = item
.get("call_id")
.or_else(|| item.get("id"))
.or_else(|| item.get("item_id"))
.and_then(Value::as_str)
.unwrap_or("call")
.to_string();
let partial = state.partials.entry(key.clone()).or_default();
if let Some(call_id) = item
.get("call_id")
.or_else(|| item.get("id"))
.and_then(Value::as_str)
{
partial.call_id = Some(call_id.to_string());
}
if let Some(name) = item.get("name").and_then(Value::as_str) {
partial.name = Some(name.to_string());
}
if let Some(arguments) = item.get("arguments").and_then(Value::as_str) {
partial.arguments = arguments.to_string();
}
}
_ => {}
}
}
fn extract_final_response(
response: &Value,
state: &mut StreamState,
tx: &mpsc::UnboundedSender<AgentEvent>,
) {
for item in response
.get("output")
.and_then(Value::as_array)
.into_iter()
.flatten()
{
handle_item(item, state, tx, true);
}
}
fn push_content(state: &mut StreamState, tx: &mpsc::UnboundedSender<AgentEvent>, text: &str) {
state.content.push_str(text);
let _ = tx.send(AgentEvent::AssistantChunk(text.to_string()));
}
fn push_reasoning(
state: &mut StreamState,
tx: &mpsc::UnboundedSender<AgentEvent>,
field: &'static str,
text: &str,
) {
state
.reasoning_field
.get_or_insert_with(|| field.to_string());
state.reasoning.push_str(text);
let _ = tx.send(AgentEvent::ReasoningChunk(text.to_string()));
}
fn string_field<'a>(value: &'a Value, fields: &[&str]) -> Option<&'a str> {
fields.iter().find_map(|field| value.get(*field)?.as_str())
}
fn event_key(value: &Value) -> String {
string_field(
value,
&["call_id", "item_id", "output_item_id", "id", "output_index"],
)
.map(str::to_string)
.or_else(|| {
value
.get("output_index")
.and_then(Value::as_u64)
.map(|n| n.to_string())
})
.unwrap_or_else(|| "call".to_string())
}
fn normalize_endpoint(endpoint: &str) -> String {
let endpoint = endpoint.trim();
if endpoint.is_empty() {
CHATGPT_CODEX_RESPONSES_URL.to_string()
} else {
endpoint.to_string()
}
}
fn redact_secret(text: &str, secret: &str) -> String {
if secret.is_empty() {
text.to_string()
} else {
text.replace(secret, "<redacted>")
}
}
#[cfg(test)]
mod tests {
use super::*;
use tokio::sync::mpsc;
#[test]
fn responses_body_uses_function_call_items() {
let body = responses_body(
"gpt-test",
vec![
ModelMessage::System {
content: "system".into(),
},
ModelMessage::User {
content: "hello".into(),
},
ModelMessage::Assistant {
content: String::new(),
reasoning: String::new(),
reasoning_field: None,
tool_calls: vec![StoredToolCall {
id: "call_1".into(),
name: "read".into(),
arguments: json!({"path":"README.md"}),
}],
},
ModelMessage::Tool {
tool_call_id: "call_1".into(),
name: "read".into(),
content: "ok".into(),
},
],
Vec::new(),
ReasoningEffort::Off,
false,
);
assert_eq!(body["model"], "gpt-test");
assert_eq!(body["instructions"], "system");
assert!(body["input"].as_array().unwrap().iter().any(|item| {
item.get("type").and_then(Value::as_str) == Some("function_call_output")
}));
}
#[test]
fn responses_body_uses_minimal_reasoning_for_fast_mode() {
let body = responses_body(
"gpt-test",
vec![ModelMessage::User {
content: "hello".into(),
}],
Vec::new(),
ReasoningEffort::High,
true,
);
assert_eq!(
body["reasoning"],
json!({"effort": "minimal", "summary": "auto"})
);
}
#[test]
fn responses_body_sends_none_effort_when_reasoning_is_off() {
let body = responses_body(
"gpt-test",
vec![ModelMessage::User {
content: "hello".into(),
}],
Vec::new(),
ReasoningEffort::Off,
false,
);
assert_eq!(
body["reasoning"],
json!({"effort": "none", "summary": "auto"})
);
}
#[test]
fn stream_parser_collects_text_and_function_call() {
let (tx, _rx) = mpsc::unbounded_channel();
let mut state = StreamState::default();
process_frame(
"data: {\"type\":\"response.output_text.delta\",\"delta\":\"hi\"}\n\ndata: {\"type\":\"response.output_item.added\",\"item\":{\"type\":\"function_call\",\"call_id\":\"call_1\",\"name\":\"read\",\"arguments\":\"{\\\"path\\\":\\\"README.md\\\"}\"}}\n\n",
&mut state,
&tx,
)
.unwrap();
let result = state.finish();
assert_eq!(result.content, "hi");
assert_eq!(result.tool_calls.len(), 1);
assert_eq!(result.tool_calls[0].id, "call_1");
assert_eq!(result.tool_calls[0].name, "read");
}
}
+70
View File
@@ -1,2 +1,72 @@
pub mod chatgpt_codex;
pub mod openai_compatible;
pub mod types;
use crate::agent::AgentEvent;
use crate::config::{Config, ReasoningEffort, CHATGPT_CODEX_PROVIDER_KIND, DEFAULT_PROVIDER_KIND};
use crate::providers::chatgpt_codex::{ChatGptCodexProvider, ChatGptCodexSettings};
use crate::providers::openai_compatible::{OpenAiCompatibleProvider, OpenAiCompatibleSettings};
use crate::providers::types::{CompletionResult, ModelMessage};
use crate::tools::ToolSpec;
use anyhow::{bail, Result};
use tokio::sync::mpsc;
#[derive(Debug, Clone)]
pub enum ProviderClient {
OpenAiCompatible(OpenAiCompatibleProvider),
ChatGptCodex(ChatGptCodexProvider),
}
#[derive(Debug, Clone, Copy)]
pub struct ProviderRuntimeOptions {
pub reasoning_effort: ReasoningEffort,
pub fast_mode: bool,
}
impl ProviderClient {
pub fn from_config(config: &Config, options: ProviderRuntimeOptions) -> Result<Self> {
match config.active_provider.kind.as_str() {
DEFAULT_PROVIDER_KIND => {
let api_key = config.resolved_api_key()?;
let model_metadata = config.model_metadata.as_ref();
let reasoning_request_format = model_metadata
.map(|model| model.reasoning.request_format)
.unwrap_or_default();
let reasoning_supported = model_metadata
.map(|model| model.reasoning.supported)
.unwrap_or(false);
Ok(Self::OpenAiCompatible(OpenAiCompatibleProvider::new(
OpenAiCompatibleSettings {
model: config.model.clone(),
base_url: config.active_provider.base_url.clone(),
api_key,
reasoning_effort: options.reasoning_effort,
reasoning_request_format,
reasoning_supported,
},
)))
}
CHATGPT_CODEX_PROVIDER_KIND => Ok(Self::ChatGptCodex(ChatGptCodexProvider::new(
ChatGptCodexSettings {
model: config.model.clone(),
endpoint: config.active_provider.base_url.clone(),
reasoning_effort: options.reasoning_effort,
fast_mode: options.fast_mode,
},
))),
kind => bail!("unsupported provider kind `{kind}`"),
}
}
pub async fn complete(
&self,
messages: Vec<ModelMessage>,
tools: Vec<ToolSpec>,
tx: &mpsc::UnboundedSender<AgentEvent>,
) -> Result<CompletionResult> {
match self {
Self::OpenAiCompatible(provider) => provider.complete(messages, tools, tx).await,
Self::ChatGptCodex(provider) => provider.complete(messages, tools, tx).await,
}
}
}
+72 -3
View File
@@ -18,6 +18,7 @@ pub struct OpenAiCompatibleProvider {
api_key: String,
reasoning_effort: ReasoningEffort,
reasoning_request_format: ReasoningRequestFormat,
reasoning_supported: bool,
}
#[derive(Debug, Clone)]
@@ -27,6 +28,7 @@ pub struct OpenAiCompatibleSettings {
pub api_key: String,
pub reasoning_effort: ReasoningEffort,
pub reasoning_request_format: ReasoningRequestFormat,
pub reasoning_supported: bool,
}
#[derive(Debug, Default)]
@@ -45,6 +47,7 @@ impl OpenAiCompatibleProvider {
api_key: settings.api_key,
reasoning_effort: settings.reasoning_effort,
reasoning_request_format: settings.reasoning_request_format,
reasoning_supported: settings.reasoning_supported,
}
}
@@ -65,6 +68,7 @@ impl OpenAiCompatibleProvider {
&mut body,
self.reasoning_effort,
self.reasoning_request_format,
self.reasoning_supported,
);
let resp = self
.client
@@ -219,9 +223,17 @@ fn apply_reasoning_request(
body: &mut Value,
effort: ReasoningEffort,
format: ReasoningRequestFormat,
supported: bool,
) {
let Some(effort) = effort.request_value() else {
if !supported {
return;
}
let effort_str = match effort {
ReasoningEffort::Off => "none",
_ => match effort.request_value() {
Some(value) => value,
None => return,
},
};
let Value::Object(obj) = body else {
return;
@@ -230,11 +242,11 @@ fn apply_reasoning_request(
ReasoningRequestFormat::ReasoningEffort => {
obj.insert(
"reasoning_effort".to_string(),
Value::String(effort.to_string()),
Value::String(effort_str.to_string()),
);
}
ReasoningRequestFormat::ReasoningObject => {
obj.insert("reasoning".to_string(), json!({ "effort": effort }));
obj.insert("reasoning".to_string(), json!({ "effort": effort_str }));
}
}
}
@@ -316,3 +328,60 @@ fn chat_url(base: &str) -> String {
format!("{}/chat/completions", base.trim_end_matches('/'))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn reasoning_effort_format_sends_none_when_off_and_supported() {
let mut body = json!({"model": "test"});
apply_reasoning_request(
&mut body,
ReasoningEffort::Off,
ReasoningRequestFormat::ReasoningEffort,
true,
);
assert_eq!(
body["reasoning_effort"],
Value::String("none".to_string())
);
}
#[test]
fn reasoning_object_format_sends_none_when_off_and_supported() {
let mut body = json!({"model": "test"});
apply_reasoning_request(
&mut body,
ReasoningEffort::Off,
ReasoningRequestFormat::ReasoningObject,
true,
);
assert_eq!(body["reasoning"], json!({ "effort": "none" }));
}
#[test]
fn reasoning_sends_nothing_when_unsupported_even_if_off() {
let mut body = json!({"model": "test"});
apply_reasoning_request(
&mut body,
ReasoningEffort::Off,
ReasoningRequestFormat::ReasoningEffort,
false,
);
assert!(body.get("reasoning_effort").is_none());
assert!(body.get("reasoning").is_none());
}
#[test]
fn reasoning_sends_nothing_when_unsupported_even_if_high() {
let mut body = json!({"model": "test"});
apply_reasoning_request(
&mut body,
ReasoningEffort::High,
ReasoningRequestFormat::ReasoningObject,
false,
);
assert!(body.get("reasoning").is_none());
}
}
+73 -24
View File
@@ -1,8 +1,11 @@
use crate::check;
use crate::cli::Cli;
use crate::codex_auth;
use crate::config::{
self, ConfigFile, ModelDefinition, ModelsFile, ProviderDefinition, ProvidersFile,
ReasoningEffort, ReasoningMetadata, ReasoningRequestFormat, DEFAULT_PROVIDER_KIND,
self, ConfigFile, FastModeMetadata, ModelDefinition, ModelsFile, ProviderDefinition,
ProvidersFile, ReasoningEffort, ReasoningMetadata, ReasoningRequestFormat,
CHATGPT_CODEX_DEFAULT_MODEL, CHATGPT_CODEX_PROVIDER_ID, CHATGPT_CODEX_PROVIDER_KIND,
CHATGPT_CODEX_PROVIDER_NAME, CHATGPT_CODEX_RESPONSES_URL, DEFAULT_PROVIDER_KIND,
};
use crate::menu::{Menu, MenuItem, TextPrompt};
use anyhow::{bail, Context, Result};
@@ -75,14 +78,12 @@ struct ModelItem {
fn print_banner() {
println!("Cassady setup");
println!("Configure an OpenAI-compatible provider, API key environment variable, and model.");
println!("Configure a provider, authentication source, and model.");
}
fn print_login_banner() {
println!("Cassady login");
println!(
"Add or update an OpenAI-compatible provider, API key environment variable, and model."
);
println!("Add or update a provider, authentication source, and model.");
}
fn section(title: &str) {
@@ -150,6 +151,12 @@ pub fn provider_catalog() -> Vec<ProviderCatalogEntry> {
base_url: "https://api.openai.com/v1",
api_key_env: "OPENAI_API_KEY",
},
ProviderCatalogEntry {
name: CHATGPT_CODEX_PROVIDER_NAME,
id: CHATGPT_CODEX_PROVIDER_ID,
base_url: CHATGPT_CODEX_RESPONSES_URL,
api_key_env: "",
},
ProviderCatalogEntry {
name: "xAI",
id: "xai",
@@ -265,7 +272,7 @@ pub async fn run(cli: &Cli, mode: SetupMode) -> Result<SetupOutcome> {
let report = check::run(cli)?;
if report.has_errors() {
if std::env::var(&active_api_key_env).is_err() {
if !active_api_key_env.is_empty() && std::env::var(&active_api_key_env).is_err() {
section(match mode {
SetupMode::Login => "Login saved",
_ => "Setup saved",
@@ -476,24 +483,39 @@ async fn configure_provider(
key_value("id", &provider.id);
key_value("endpoint", &provider.base_url);
let api_key_env = ask_default("API key environment variable", &provider.api_key_env)?;
if !looks_like_env_var(&api_key_env) {
warn(format!(
"`{api_key_env}` is an unusual environment variable name. Continuing."
));
}
let api_key = match std::env::var(&api_key_env) {
Ok(value) if !value.is_empty() => {
success(format!("{api_key_env} is set"));
Some(value)
let (api_key_env, api_key) = if is_chatgpt_codex_provider(&provider.id) {
info(
"ChatGPT Codex uses your local Codex login instead of an API-key environment variable.",
);
let status = codex_auth::check_codex_auth();
if status.is_usable() {
success(format!("Codex auth: {}", status.summary()));
} else {
warn(format!("Codex auth: {}", status.summary()));
hint(status.recovery_hint());
}
_ => {
(String::new(), None)
} else {
let api_key_env = ask_default("API key environment variable", &provider.api_key_env)?;
if !looks_like_env_var(&api_key_env) {
warn(format!(
"{api_key_env} is not set in this shell. Setup can still be saved."
"`{api_key_env}` is an unusual environment variable name. Continuing."
));
hint(format!("Later, run: export {api_key_env}=..."));
None
}
let api_key = match std::env::var(&api_key_env) {
Ok(value) if !value.is_empty() => {
success(format!("{api_key_env} is set"));
Some(value)
}
_ => {
warn(format!(
"{api_key_env} is not set in this shell. Setup can still be saved."
));
hint(format!("Later, run: export {api_key_env}=..."));
None
}
};
(api_key_env, api_key)
};
let model_id = choose_model(&provider, api_key.as_deref()).await?;
@@ -556,6 +578,15 @@ fn choose_active_provider(selections: &[SetupSelection]) -> Result<usize> {
async fn choose_model(provider: &ChosenProvider, api_key: Option<&str>) -> Result<String> {
section("Model");
if is_chatgpt_codex_provider(&provider.id) {
if let Some(model) = codex_auth::read_codex_default_model() {
success(format!("Found Codex default model: {model}"));
return ask_default("Model id", &model);
}
warn("Could not find a model in local Codex config. Using a safe default; edit it if needed.");
return ask_default("Model id", CHATGPT_CODEX_DEFAULT_MODEL);
}
let Some(api_key) = api_key else {
warn("Model discovery was skipped because the API key is not available in this shell.");
hint("Enter the model id manually now; Cassady will use it after the key is exported.");
@@ -670,7 +701,9 @@ pub fn apply_setups(root: &Path, selections: &[SetupSelection], active_index: us
for selection in selections {
validate_provider_id(&selection.provider_id)?;
validate_base_url(&selection.base_url)?;
if selection.api_key_env.trim().is_empty() {
if !is_chatgpt_codex_provider(&selection.provider_id)
&& selection.api_key_env.trim().is_empty()
{
bail!("API key environment variable must not be empty");
}
if selection.model_id.trim().is_empty() {
@@ -883,12 +916,21 @@ fn model_belongs_to_provider(models: &ModelsFile, provider_id: &str, model_id: &
}
fn upsert_provider(providers: &mut ProvidersFile, selection: &SetupSelection) {
let is_codex = is_chatgpt_codex_provider(&selection.provider_id);
let new_entry = ProviderDefinition {
id: selection.provider_id.clone(),
name: Some(selection.provider_name.clone()),
kind: DEFAULT_PROVIDER_KIND.to_string(),
kind: if is_codex {
CHATGPT_CODEX_PROVIDER_KIND.to_string()
} else {
DEFAULT_PROVIDER_KIND.to_string()
},
base_url: selection.base_url.clone(),
api_key: format!("${}", selection.api_key_env),
api_key: if is_codex {
String::new()
} else {
format!("${}", selection.api_key_env)
},
default_model: Some(selection.model_id.clone()),
models: vec![selection.model_id.clone()],
};
@@ -928,6 +970,9 @@ fn upsert_model(models: &mut ModelsFile, selection: &SetupSelection) {
},
request_format: ReasoningRequestFormat::ReasoningEffort,
},
fast_mode: FastModeMetadata {
supported: is_chatgpt_codex_provider(&selection.provider_id),
},
};
if let Some(existing) = models.models.iter_mut().find(|existing| {
@@ -981,6 +1026,10 @@ fn validate_base_url(base_url: &str) -> Result<()> {
}
}
fn is_chatgpt_codex_provider(id: &str) -> bool {
id == CHATGPT_CODEX_PROVIDER_ID
}
fn looks_like_env_var(value: &str) -> bool {
let mut chars = value.chars();
let Some(first) = chars.next() else {
+9 -3
View File
@@ -53,6 +53,7 @@ pub struct RenderState<'a> {
pub show_full_tools: bool,
pub show_reasoning: bool,
pub reasoning_effort: ReasoningEffort,
pub fast_mode_active: bool,
pub scroll: u16,
pub autofill: Option<&'a AutoFillMenu>,
pub overlay: Option<&'a OverlayView>,
@@ -600,9 +601,6 @@ fn ratatui_wrapped_row_count(line: &str, content_width: usize) -> usize {
non_whitespace_previous = !is_whitespace;
}
if !pending_line_has_symbols && word_symbols == 0 && whitespace_symbols > 0 {
rows = rows.saturating_add(1);
}
if whitespace_symbols > 0 || word_symbols > 0 {
pending_line_has_symbols = true;
}
@@ -727,6 +725,9 @@ fn footer_text(state: &RenderState<'_>) -> String {
parts.push("tools:full".into());
}
parts.push(format!("reasoning:{}", state.reasoning_effort));
if state.fast_mode_active {
parts.push("fast".into());
}
if state.show_reasoning {
parts.push("reasoning:visible".into());
}
@@ -993,6 +994,11 @@ mod tests {
assert_eq!(max_transcript_scroll(&transcript, false, false, area), 0);
}
#[test]
fn whitespace_only_line_counts_as_one_wrapped_row() {
assert_eq!(ratatui_wrapped_row_count(" ", 80), 1);
}
#[test]
fn input_height_wraps_long_line() {
// A single long line with no newlines should occupy more than 1 row
+56
View File
@@ -123,6 +123,62 @@ async fn reasoning_effort_supports_reasoning_object_format() {
.unwrap();
}
#[tokio::test]
async fn fast_mode_preference_does_not_change_openai_compatible_request() {
let server = MockServer::start().await;
Mock::given(method("POST"))
.and(path("/chat/completions"))
.respond_with(sse(
"data: {\"choices\":[{\"index\":0,\"delta\":{\"content\":\"Done.\"}}]}\r\n\r\ndata: [DONE]\r\n\r\n",
))
.expect(1)
.mount(&server)
.await;
let root = tempdir().unwrap();
let cwd = tempdir().unwrap();
let docs = tempdir().unwrap();
let config = Config {
root: root.path().to_path_buf(),
docs_dir: docs.path().to_path_buf(),
model: "test-model".into(),
default_fast_mode: true,
active_provider: cassady::config::ResolvedProviderConfig {
base_url: server.uri(),
api_key: "test-key".into(),
..Config::default().active_provider
},
..Config::default()
};
let conversation = Conversation::create(
&config.conversations_dir(),
&config.model,
cwd.path(),
"base prompt".into(),
)
.unwrap();
let (tx, _rx) = mpsc::unbounded_channel::<AgentEvent>();
run_turn(
conversation,
"stay compatible".into(),
AgentSettings {
config,
cwd: cwd.path().to_path_buf(),
mode: AccessMode::ReadOnly,
reasoning_effort: ReasoningEffort::Off,
},
tx,
)
.await
.unwrap();
let requests = server.received_requests().await.unwrap();
let body = String::from_utf8_lossy(&requests[0].body);
assert!(!body.contains("\"effort\":\"minimal\""));
assert!(!body.contains("\"fast_mode\""));
}
#[tokio::test]
async fn reasoning_is_streamed_persisted_and_sent_back() {
let server = MockServer::start().await;
+201
View File
@@ -47,6 +47,7 @@ fn default_provider_and_model_files_are_created() {
.unwrap();
assert_eq!(models.models[0].provider, "fireworks");
assert!(models.models[0].reasoning.supported);
assert!(!models.models[0].fast_mode.supported);
assert_eq!(
models.models[0].reasoning.default_effort,
ReasoningEffort::Medium
@@ -127,6 +128,206 @@ fn reasoning_defaults_to_supported_medium_for_model_metadata() {
);
}
#[test]
fn fast_mode_defaults_to_off_and_unsupported() {
let model: config::ModelDefinition = serde_json::from_str(
r#"{
"id": "test-model",
"provider": "test-provider"
}
"#,
)
.unwrap();
assert!(!model.fast_mode.supported);
let root = tempdir().unwrap();
let cfg = Config::load_from_root_with_docs(
root.path().to_path_buf(),
root.path().join("docs"),
&cli(),
)
.unwrap();
let state = cfg.fast_mode_state();
assert!(!state.preferred);
assert!(!state.supported);
assert!(!state.active);
}
#[test]
fn fast_mode_preference_persists_without_losing_config_fields() {
let root = tempdir().unwrap();
std::fs::write(
root.path().join("config.json"),
r#"{
"default_access_mode": "workspace-edit",
"show_reasoning": true
}
"#,
)
.unwrap();
config::save_fast_mode_preference(root.path(), true).unwrap();
let cfg = Config::load_from_root_with_docs(
root.path().to_path_buf(),
root.path().join("docs"),
&cli(),
)
.unwrap();
assert!(cfg.default_fast_mode);
assert!(cfg.show_reasoning);
assert_eq!(cfg.default_access_mode.to_string(), "workspace-edit");
}
#[test]
fn fast_mode_state_is_active_for_supported_codex_model() {
let root = tempdir().unwrap();
std::fs::write(
root.path().join("providers.json"),
r#"{
"providers": [
{
"id": "chatgpt-codex",
"name": "ChatGPT Codex",
"kind": "chatgpt-codex",
"base_url": "https://chatgpt.com/backend-api/codex/responses",
"api_key": "",
"default_model": "gpt-5.5",
"models": ["gpt-5.5"]
}
]
}
"#,
)
.unwrap();
std::fs::write(
root.path().join("models.json"),
r#"{
"models": [
{
"id": "gpt-5.5",
"provider": "chatgpt-codex",
"fast_mode": { "supported": true }
}
]
}
"#,
)
.unwrap();
std::fs::write(
root.path().join("config.json"),
r#"{
"default_provider": "chatgpt-codex",
"default_model": "gpt-5.5",
"default_fast_mode": true
}
"#,
)
.unwrap();
let cfg = Config::load_from_root_with_docs(
root.path().to_path_buf(),
root.path().join("docs"),
&cli(),
)
.unwrap();
let state = cfg.fast_mode_state();
assert!(state.preferred);
assert!(state.supported);
assert!(state.active);
}
#[test]
fn fast_mode_state_is_active_for_chatgpt_codex_even_with_legacy_metadata() {
let root = tempdir().unwrap();
std::fs::write(
root.path().join("providers.json"),
r#"{
"providers": [
{
"id": "chatgpt-codex",
"name": "ChatGPT Codex",
"kind": "chatgpt-codex",
"base_url": "https://chatgpt.com/backend-api/codex/responses",
"api_key": "",
"default_model": "gpt-5.5",
"models": ["gpt-5.5"]
}
]
}
"#,
)
.unwrap();
std::fs::write(
root.path().join("models.json"),
r#"{
"models": [
{
"id": "gpt-5.5",
"provider": "chatgpt-codex",
"fast_mode": { "supported": false }
}
]
}
"#,
)
.unwrap();
std::fs::write(
root.path().join("config.json"),
r#"{
"default_provider": "chatgpt-codex",
"default_model": "gpt-5.5",
"default_fast_mode": true
}
"#,
)
.unwrap();
let cfg = Config::load_from_root_with_docs(
root.path().to_path_buf(),
root.path().join("docs"),
&cli(),
)
.unwrap();
let state = cfg.fast_mode_state();
assert!(state.preferred);
assert!(state.supported);
assert!(state.active);
}
#[test]
fn validation_accepts_chatgpt_codex_without_api_key() {
let providers = ProvidersFile {
providers: vec![ProviderDefinition {
id: config::CHATGPT_CODEX_PROVIDER_ID.into(),
name: Some(config::CHATGPT_CODEX_PROVIDER_NAME.into()),
kind: config::CHATGPT_CODEX_PROVIDER_KIND.into(),
base_url: config::CHATGPT_CODEX_RESPONSES_URL.into(),
api_key: String::new(),
default_model: Some(config::CHATGPT_CODEX_DEFAULT_MODEL.into()),
models: vec![config::CHATGPT_CODEX_DEFAULT_MODEL.into()],
}],
};
let models = ModelsFile {
models: vec![config::ModelDefinition {
id: config::CHATGPT_CODEX_DEFAULT_MODEL.into(),
provider: config::CHATGPT_CODEX_PROVIDER_ID.into(),
display_name: None,
context_length: None,
max_output_tokens: None,
supports_tools: true,
supports_streaming: true,
reasoning: Default::default(),
fast_mode: Default::default(),
}],
};
let summary = config::validate_registries(None, &providers, &models);
assert!(summary.errors.is_empty(), "{:?}", summary.errors);
}
#[test]
fn validation_rejects_duplicate_provider_ids() {
let providers = ProvidersFile {
+34 -1
View File
@@ -5,7 +5,7 @@ use wiremock::matchers::{header, method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};
#[test]
fn provider_catalog_contains_expected_openai_compatible_providers() {
fn provider_catalog_contains_expected_providers() {
let catalog = setup::provider_catalog();
let ids: Vec<_> = catalog.iter().map(|entry| entry.id).collect();
@@ -13,6 +13,7 @@ fn provider_catalog_contains_expected_openai_compatible_providers() {
ids,
vec![
"openai",
"chatgpt-codex",
"xai",
"fireworks",
"groq",
@@ -148,6 +149,38 @@ fn apply_setup_upserts_selected_provider_model_and_preserves_unrelated_entries()
);
}
#[test]
fn apply_setup_writes_chatgpt_codex_without_api_key() {
let root = tempdir().unwrap();
setup::apply_setup(
root.path(),
&SetupSelection {
provider_id: config::CHATGPT_CODEX_PROVIDER_ID.into(),
provider_name: config::CHATGPT_CODEX_PROVIDER_NAME.into(),
base_url: config::CHATGPT_CODEX_RESPONSES_URL.into(),
api_key_env: String::new(),
model_id: config::CHATGPT_CODEX_DEFAULT_MODEL.into(),
supports_tools: true,
supports_reasoning: true,
},
)
.unwrap();
let providers: ProvidersFile =
serde_json::from_str(&std::fs::read_to_string(root.path().join("providers.json")).unwrap())
.unwrap();
let provider = &providers.providers[0];
assert_eq!(provider.id, config::CHATGPT_CODEX_PROVIDER_ID);
assert_eq!(provider.kind, config::CHATGPT_CODEX_PROVIDER_KIND);
assert!(provider.api_key.is_empty());
let models: ModelsFile =
serde_json::from_str(&std::fs::read_to_string(root.path().join("models.json")).unwrap())
.unwrap();
assert!(models.models[0].fast_mode.supported);
}
#[test]
fn apply_setups_writes_multiple_providers_and_active_choice() {
let root = tempdir().unwrap();