Commit Graph
8422 Commits
Author SHA1 Message Date
Michael Bolin 000b715181 feat: add support for login with ChatGPT 2025-06-03 14:31:59 -07:00
Reilly Wood a67a67f325 codex-rs: make tool calls prettier (#1211)
This PR overhauls how active tool calls and completed tool calls are
displayed:

1. More use of colour to indicate success/failure and distinguish
between components like tool name+arguments
2. Previously, the entire `CallToolResult` was serialized to JSON and
pretty-printed. Now, we extract each individual `CallToolResultContent`
and print those
1. The previous solution was wasting space by unnecessarily showing
details of the `CallToolResult` struct to users, without formatting the
actual tool call results nicely
2. We're now able to show users more information from tool results in
less space, with nicer formatting when tools return JSON results

### Before:

<img width="1251" alt="Screenshot 2025-06-03 at 11 24 26"
src="https://github.com/user-attachments/assets/5a58f222-219c-4c53-ace7-d887194e30cf"
/>

### After:

<img width="1265" alt="image"
src="https://github.com/user-attachments/assets/99fe54d0-9ebe-406a-855b-7aa529b91274"
/>

## Future Work

1. Integrate image tool result handling better. We should be able to
display images even if they're not the first `CallToolResultContent`
2. Users should have some way to view the full version of truncated tool
results
3. It would be nice to add some left padding for tool results, make it
more clear that they are results. This is doable, just a little fiddly
due to the way `first_visible_line` scrolling works
4. There's almost certainly a better way to format JSON than "all on 1
line with spaces to make Ratatui wrapping work". But I think that works
OK for now.
2025-06-03 14:29:26 -07:00
Michael Bolin 1c581c5d76 Merge 4f2686bb18 into sapling-pr-archive-bolinfest 2025-06-03 14:15:31 -07:00
Michael Bolin 4f2686bb18 feat: add support for login with ChatGPT 2025-06-03 14:15:12 -07:00
Michael Bolin c6fcec55fe fix: always send full instructions when using the Responses API (#1207)
This fixes a longstanding error in the Rust CLI where `codex.rs`
contained an errant `is_first_turn` check that would exclude the user
instructions for subsequent "turns" of a conversation when using the
responses API (i.e., when `previous_response_id` existed).

While here, renames `Prompt.instructions` to `Prompt.user_instructions`
since we now have quite a few levels of instructions floating around.
Also removed an unnecessary use of `clone()` in
`Prompt.get_full_instructions()`.
codex-rs-45519e12f39777b65c05ed498503ddcb60beb289-1-rust-v0.0.2506030956
2025-06-03 09:40:19 -07:00
Michael Bolin 2b678e91f2 merge commit for archive created by Sapling 2025-06-03 09:36:00 -07:00
Michael Bolin 7ee8eaedff fix: always send full instructions when using the Responses API 2025-06-03 09:35:54 -07:00
Michael Bolin 4a4187fda8 merge commit for archive created by Sapling 2025-06-03 09:22:49 -07:00
Michael Bolin d90692bdd7 fix: always send full instructions when using the Responses API 2025-06-03 09:22:37 -07:00
Michael Bolin 6fcc528a43 fix: provide tolerance for apply_patch tool (#993)
As explained in detail in the doc comment for `ParseMode::Lenient`, we
have observed that GPT-4.1 does not always generate a valid invocation
of `apply_patch`. Fortunately, the error is predictable, so we introduce
some new logic to the `codex-apply-patch` crate to recover from this
error.

Because we would like to avoid this becoming a de facto standard (as it
would be incompatible if `apply_patch` were provided as an actual
executable, unless we also introduced the lenient behavior in the
executable, as well), we require passing `ParseMode::Lenient` to
`parse_patch_text()` to make it clear that the caller is opting into
supporting this special case.

Note the analogous change to the TypeScript CLI was
https://github.com/openai/codex/pull/930. In addition to changing the
accepted input to `apply_patch`, it also introduced additional
instructions for the model, which we include in this PR.

Note that `apply-patch` does not depend on either `regex` or
`regex-lite`, so some of the checks are slightly more verbose to avoid
introducing this dependency.

That said, this PR does not leverage the existing
`extract_heredoc_body_from_apply_patch_command()`, which depends on
`tree-sitter` and `tree-sitter-bash`:


https://github.com/openai/codex/blob/5a5aa899143f9b9ef606692c401b010368b15bdb/codex-rs/apply-patch/src/lib.rs#L191-L246

though perhaps it should.
2025-06-03 09:06:38 -07:00
Michael Bolin bf4f9977f6 Merge fae9ff8317 into sapling-pr-archive-bolinfest 2025-06-03 08:50:44 -07:00
Michael Bolin fae9ff8317 fix: provide tolerance for apply_patch tool 2025-06-03 08:50:41 -07:00
Michael Bolin 26fe415a0d merge commit for archive created by Sapling 2025-06-03 08:49:45 -07:00
Michael Bolin 0cb4f46b08 fix: provide tolerance for apply_patch tool 2025-06-03 08:49:39 -07:00
Michael Bolin 06fb13a946 merge commit for archive created by Sapling 2025-06-03 08:27:49 -07:00
Michael Bolin 29686a7d8c fix: provide tolerance for apply_patch tool 2025-06-03 08:27:43 -07:00
Michael Bolin ca5e62998a merge commit for archive created by Sapling 2025-06-02 23:38:43 -07:00
Michael Bolin 1f0f39ca58 fix: provide tolerance for apply_patch tool 2025-06-02 23:38:36 -07:00
Michael Bolin 364366b690 merge commit for archive created by Sapling 2025-06-02 23:26:58 -07:00
Michael Bolin bdb0bd4d76 fix: provide tolerance for apply_patch tool 2025-06-02 23:26:03 -07:00
Michael Bolin 741479f5f5 merge commit for archive created by Sapling 2025-06-02 22:42:36 -07:00
Michael Bolin 8940dbb12a fix: provide tolerance for apply_patch tool 2025-06-02 22:42:09 -07:00
Michael Bolin 743e580b33 merge commit for archive created by Sapling 2025-06-02 17:25:28 -07:00
Michael Bolin 51cbec2dc3 fix: provide tolerance for apply_patch tool 2025-06-02 17:25:05 -07:00
Michael Bolin 5a5aa89914 chore: replace regex with regex-lite, where appropriate (#1200)
As explained on https://crates.io/crates/regex-lite, `regex-lite` is a
lighter alternative to `regex` and seems to be sufficient for our
purposes.
2025-06-02 17:11:45 -07:00
Michael Bolin 2d6824040a merge commit for archive created by Sapling 2025-06-02 16:59:26 -07:00
Michael Bolin 956dc56a1f chore: replace regex with regex-lite, where appropriate 2025-06-02 16:58:49 -07:00
Michael Bolin 8691e269c4 Merge 0efbb7f7f1 into sapling-pr-archive-bolinfest 2025-06-02 16:56:39 -07:00
Michael Bolin 0efbb7f7f1 chore: replace regex with regex-lite, where appropriate 2025-06-02 16:56:32 -07:00
Michael Bolin 0f3cc8f842 feat: make reasoning effort/summaries configurable (#1199)
Previous to this PR, we always set `reasoning` when making a request
using the Responses API:


https://github.com/openai/codex/blob/d7245cbbc9d8ff5446da45e5951761103492476d/codex-rs/core/src/client.rs#L108-L111

Though if you tried to use the Rust CLI with `--model gpt-4.1`, this
would fail with:

```shell
"Unsupported parameter: 'reasoning.effort' is not supported with this model."
```

We take a cue from the TypeScript CLI, which does a check on the model
name:


https://github.com/openai/codex/blob/d7245cbbc9d8ff5446da45e5951761103492476d/codex-cli/src/utils/agent/agent-loop.ts#L786-L789

This PR does a similar check, though also adds support for the following
config options:

```
model_reasoning_effort = "low" | "medium" | "high" | "none"
model_reasoning_summary = "auto" | "concise" | "detailed" | "none"
```

This way, if you have a model whose name happens to start with `"o"` (or
`"codex"`?), you can set these to `"none"` to explicitly disable
reasoning, if necessary. (That said, it seems unlikely anyone would use
the Responses API with non-OpenAI models, but we provide an escape
hatch, anyway.)

This PR also updates both the TUI and `codex exec` to show `reasoning
effort` and `reasoning summaries` in the header.
2025-06-02 16:01:34 -07:00
Michael Bolin 76e0eba41c merge commit for archive created by Sapling 2025-06-02 15:49:23 -07:00
Michael Bolin 75266a1018 feat: make reasoning effort/summaries configurable 2025-06-02 15:49:16 -07:00
Michael Bolin cb57fd44a9 Merge 02cf240557 into sapling-pr-archive-bolinfest 2025-06-02 15:24:32 -07:00
Michael Bolin 02cf240557 feat: make reasoning effort/summaries configurable 2025-06-02 15:24:23 -07:00
Michael Bolin d7245cbbc9 fix: chat completions API now also passes tools along (#1167)
Prior to this PR, there were two big misses in `chat_completions.rs`:

1. The loop in `stream_chat_completions()` was only including items of
type `ResponseItem::Message` when building up the `"messages"` JSON for
the `POST` request to the `chat/completions` endpoint. This fixes things
by ensuring other variants (`FunctionCall`, `LocalShellCall`, and
`FunctionCallOutput`) are included, as well.
2. In `process_chat_sse()`, we were not recording tool calls and were
only emitting items of type
`ResponseEvent::OutputItemDone(ResponseItem::Message)` to the stream.
Now we introduce `FunctionCallState`, which is used to accumulate the
`delta`s of type `tool_calls`, so we can ultimately emit a
`ResponseItem::FunctionCall`, when appropriate.

While function calling now appears to work for chat completions with my
local testing, I believe that there are still edge cases that are not
covered and that this codepath would benefit from a battery of
integration tests. (As part of that further cleanup, we should also work
to support streaming responses in the UI.)

The other important part of this PR is some cleanup in
`core/src/codex.rs`. In particular, it was hard to reason about how
`run_task()` was building up the list of messages to include in a
request across the various cases:

- Responses API
- Chat Completions API
- Responses API used in concert with ZDR

I like to think things are a bit cleaner now where:

- `zdr_transcript` (if present) contains all messages in the history of
the conversation, which includes function call outputs that have not
been sent back to the model yet
- `pending_input` includes any messages the user has submitted while the
turn is in flight that need to be injected as part of the next `POST` to
the model
- `input_for_next_turn` includes the tool call outputs that have not
been sent back to the model yet
2025-06-02 13:47:51 -07:00
Michael Bolin 0789e6125e Merge a13a300e0f into sapling-pr-archive-bolinfest 2025-06-02 13:33:13 -07:00
Michael Bolin a13a300e0f fix: chat completions API to work with tools 2025-06-02 13:33:06 -07:00
Michael Bolin e40f86b446 chore: logging cleanup (#1196)
Update what we log to make `RUST_LOG=debug` a bit easier to work with.
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/1196).
* #1167
* __->__ #1196
2025-06-02 13:31:33 -07:00
Michael Bolin d4e9a81abc Merge 0b880458a7 into sapling-pr-archive-bolinfest 2025-06-02 13:19:18 -07:00
Michael Bolin 0b880458a7 fix: chat completions API to work with tools 2025-06-02 13:18:56 -07:00
Michael Bolin ee43e1b2d1 chore: logging cleanup
Update what we log to make `RUST_LOG=debug` a bit easier to work with.
2025-06-02 13:18:50 -07:00
Michael Bolin 54854e516a Merge e5f9b9ce92 into sapling-pr-archive-bolinfest 2025-06-02 13:17:23 -07:00
Michael Bolin e5f9b9ce92 fix: chat completions API to work with tools 2025-06-02 13:13:14 -07:00
Michael Bolin 7907ead08e merge commit for archive created by Sapling 2025-06-02 13:09:45 -07:00
Michael Bolin c16d2ce27e fix: chat completions API to work with tools 2025-06-02 13:09:39 -07:00
Michael Bolin b1b2ff50d9 merge commit for archive created by Sapling 2025-06-02 12:00:39 -07:00
Michael Bolin 55c0d4e9c1 fix: chat completions API to work with tools 2025-06-02 12:00:32 -07:00
Michael Bolin 7896b1089d chore: update the WORKFLOW_URL in install_native_deps.sh to the latest release (#1190) 2025-05-31 10:30:50 -07:00
Michael Bolin f1731e7cac Merge ce808d7cc6 into sapling-pr-archive-bolinfest 2025-05-31 10:24:26 -07:00
Michael Bolin ce808d7cc6 chore: update the WORKFLOW_URL in install_native_deps.sh to the latest release 2025-05-31 10:24:19 -07:00