Commit Graph

1067 Commits

Author SHA1 Message Date
Michael Bolin
c058a6ea59 Merge 19bfb47768 into sapling-pr-archive-bolinfest 2025-05-09 11:06:54 -07:00
Michael Bolin
19bfb47768 feat: experimental env var: CODEX_SANDBOX_NETWORK_DISABLED
Previous to this change:

```
$ cargo run --bin codex -- debug seatbelt --full-auto -- cargo test
---- keeps_previous_response_id_between_tasks stdout ----

thread 'keeps_previous_response_id_between_tasks' panicked at /Users/mbolin/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wiremock-0.6.3/src/mock_server/builder.rs:107:46:
Failed to bind an OS port for a mock server.: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    keeps_previous_response_id_between_tasks

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p codex-core --test previous_response_id`
```
2025-05-09 11:06:50 -07:00
Michael Bolin
d0c0170026 merge commit for archive created by Sapling 2025-05-09 11:05:25 -07:00
Michael Bolin
e013fc76e1 feat: experimental env var: CODEX_SANDBOX_NETWORK_DISABLED
Previous to this change:

```
$ cargo run --bin codex -- debug seatbelt --full-auto -- cargo test
---- keeps_previous_response_id_between_tasks stdout ----

thread 'keeps_previous_response_id_between_tasks' panicked at /Users/mbolin/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wiremock-0.6.3/src/mock_server/builder.rs:107:46:
Failed to bind an OS port for a mock server.: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    keeps_previous_response_id_between_tasks

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p codex-core --test previous_response_id`
```
2025-05-09 11:05:17 -07:00
Michael Bolin
93817643ee chore: refactor exec() into spawn_child() and consume_truncated_output() (#878)
This PR is a straight refactor so that creating the `Child` process for
an `shell` tool call and consuming its output can be separate concerns.
For the actual tool call, we will always apply
`consume_truncated_output()`, but for the top-level debug commands in
the CLI (e.g., `debug seatbelt` and `debug landlock`), we only want to
use the `spawn_child()` part of `exec()`.

We want the subcommands to match the `shell` tool call usage as
faithfully as possible. This becomes more important when we introduce a
new parameter to `spawn_child()` in
https://github.com/openai/codex/pull/879.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/878).
* #879
* __->__ #878
2025-05-09 11:03:58 -07:00
Michael Bolin
79a294a636 merge commit for archive created by Sapling 2025-05-09 10:57:45 -07:00
Michael Bolin
63644102d7 feat: experimental env var: CODEX_SANDBOX_NETWORK_DISABLED
Previous to this change:

```
$ cargo run --bin codex -- debug seatbelt --full-auto -- cargo test
---- keeps_previous_response_id_between_tasks stdout ----

thread 'keeps_previous_response_id_between_tasks' panicked at /Users/mbolin/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wiremock-0.6.3/src/mock_server/builder.rs:107:46:
Failed to bind an OS port for a mock server.: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    keeps_previous_response_id_between_tasks

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p codex-core --test previous_response_id`
```
2025-05-09 10:57:39 -07:00
Michael Bolin
c436ac1989 chore: refactor exec() into spawn_child() and exec_child_and_truncate_output() 2025-05-09 10:56:51 -07:00
Michael Bolin
5a5f0c5603 merge commit for archive created by Sapling 2025-05-09 10:55:13 -07:00
Michael Bolin
d3a85ff1a6 chore: refactor exec() into spawn_child() and exec_child_and_truncate_output() 2025-05-09 10:54:40 -07:00
Michael Bolin
eeaeec641a Merge 63ab6984ed into sapling-pr-archive-bolinfest 2025-05-09 10:49:14 -07:00
Michael Bolin
63ab6984ed feat: experimental env var: CODEX_SANDBOX_NETWORK_DISABLED
Previous to this change:

```
$ cargo run --bin codex -- debug seatbelt --full-auto -- cargo test
---- keeps_previous_response_id_between_tasks stdout ----

thread 'keeps_previous_response_id_between_tasks' panicked at /Users/mbolin/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wiremock-0.6.3/src/mock_server/builder.rs:107:46:
Failed to bind an OS port for a mock server.: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    keeps_previous_response_id_between_tasks

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p codex-core --test previous_response_id`
```
2025-05-09 10:49:05 -07:00
Michael Bolin
644429b46f chore: refactor exec() into spawn_child() and exec_child_and_truncate_output() 2025-05-09 10:38:13 -07:00
Michael Bolin
27198bfe11 fix: make McpConnectionManager tolerant of MCPs that fail to start (#854)
I added a typo in my `config.toml` such that the `command` for one of my
`mcp_servers` did not exist and I verified that the error was surfaced
in the TUI (and that I was still able to use Codex).


![image](https://github.com/user-attachments/assets/f13cc08c-f4c6-40ec-9ab4-a9d75e03152f)
2025-05-08 23:45:54 -07:00
Michael Bolin
0d64b0b9c5 merge commit for archive created by Sapling 2025-05-08 23:40:33 -07:00
Michael Bolin
1f95c55bce fix: make McpConnectionManager tolerant of MCPs that fail to start 2025-05-08 23:40:29 -07:00
Michael Bolin
dc210fcfe4 merge commit for archive created by Sapling 2025-05-08 23:23:13 -07:00
Michael Bolin
eeda502171 fix: make McpConnectionManager tolerant of MCPs that fail to start 2025-05-08 23:23:07 -07:00
Michael Bolin
371e236185 Merge 009403b02b into sapling-pr-archive-bolinfest 2025-05-08 23:16:24 -07:00
Michael Bolin
009403b02b fix: make McpConnectionManager tolerant of MCPs that fail to start 2025-05-08 23:16:16 -07:00
Michael Bolin
b940adae8e fix: get responses API working again in Rust (#872)
I inadvertently regressed support for the Responses API when adding
support for the chat completions API in
https://github.com/openai/codex/pull/862. This should get both APIs
working again, but the chat completions codepath seems more complex than
necessary. I'll try to clean that up shortly, but I want to get things
working again ASAP.
2025-05-08 22:49:15 -07:00
Michael Bolin
b40c62362e Merge 5530786d9c into sapling-pr-archive-bolinfest 2025-05-08 22:44:59 -07:00
Michael Bolin
5530786d9c fix: get responses API working again in Rust 2025-05-08 22:44:52 -07:00
Michael Bolin
990c9ba727 Merge 88d1c77431 into sapling-pr-archive-bolinfest 2025-05-08 22:44:41 -07:00
Michael Bolin
88d1c77431 fix: get responses API working again in Rust 2025-05-08 22:44:34 -07:00
Michael Bolin
e924070cee feat: support the chat completions API in the Rust CLI (#862)
This is a substantial PR to add support for the chat completions API,
which in turn makes it possible to use non-OpenAI model providers (just
like in the TypeScript CLI):

* It moves a number of structs from `client.rs` to `client_common.rs` so
they can be shared.
* It introduces support for the chat completions API in
`chat_completions.rs`.
* It updates `ModelProviderInfo` so that `env_key` is `Option<String>`
instead of `String` (for e.g., ollama) and adds a `wire_api` field
* It updates `client.rs` to choose between `stream_responses()` and
`stream_chat_completions()` based on the `wire_api` for the
`ModelProviderInfo`
* It updates the `exec` and TUI CLIs to no longer fail if the
`OPENAI_API_KEY` environment variable is not set
* It updates the TUI so that `EventMsg::Error` is displayed more
prominently when it occurs, particularly now that it is important to
alert users to the `CodexErr::EnvVar` variant.
* `CodexErr::EnvVar` was updated to include an optional `instructions`
field so we can preserve the behavior where we direct users to
https://platform.openai.com if `OPENAI_API_KEY` is not set.
* Cleaned up the "welcome message" in the TUI to ensure the model
provider is displayed.
* Updated the docs in `codex-rs/README.md`.

To exercise the chat completions API from OpenAI models, I added the
following to my `config.toml`:

```toml
model = "gpt-4o"
model_provider = "openai-chat-completions"

[model_providers.openai-chat-completions]
name = "OpenAI using Chat Completions"
base_url = "https://api.openai.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "chat"
```

Though to test a non-OpenAI provider, I installed ollama with mistral
locally on my Mac because ChatGPT said that would be a good match for my
hardware:

```shell
brew install ollama
ollama serve
ollama pull mistral
```

Then I added the following to my `~/.codex/config.toml`:

```toml
model = "mistral"
model_provider = "ollama"
```

Note this code could certainly use more test coverage, but I want to get
this in so folks can start playing with it.

For reference, I believe https://github.com/openai/codex/pull/247 was
roughly the comparable PR on the TypeScript side.
2025-05-08 21:46:06 -07:00
Michael Bolin
d754120924 Merge bf8a38663a into sapling-pr-archive-bolinfest 2025-05-08 21:37:04 -07:00
Michael Bolin
bf8a38663a feat: support the chat completions API in the Rust CLI 2025-05-08 21:37:00 -07:00
Michael Bolin
1690a080de merge commit for archive created by Sapling 2025-05-08 16:41:41 -07:00
Michael Bolin
f216606834 feat: support the chat completions API in the Rust CLI 2025-05-08 16:41:34 -07:00
Michael Bolin
f458d391c1 Merge fb3a17e809 into sapling-pr-archive-bolinfest 2025-05-08 16:37:27 -07:00
Michael Bolin
fb3a17e809 feat: support the chat completions API in the Rust CLI 2025-05-08 16:37:20 -07:00
Michael Bolin
a538e6acb2 fix: use continue-on-error: true to tidy up GitHub Action (#871)
I installed the GitHub Actions extension for VS Code and it started
giving me lint warnings about this line:


a9adb4175c/.github/workflows/rust-ci.yml (L99)

Using an env var to track the state of individual steps was not great,
so I did some research about GitHub actions, which led to the discovery
of combining `continue-on-error: true` with `if .. steps.STEP.outcome ==
'failure'...`.

Apparently there is also a `failure()` macro that is supposed to make
this simpler, but I saw a number of complains online about it not
working as expected. Checking `outcome` seems maybe more reliable at the
cost of being slightly more verbose.
2025-05-08 16:21:11 -07:00
Michael Bolin
e4e3b3399e merge commit for archive created by Sapling 2025-05-08 16:17:09 -07:00
Michael Bolin
9991cb43f6 fix: use continue-on-error: true to tidy up GitHub Action 2025-05-08 16:16:59 -07:00
Michael Bolin
9ca1a68541 merge commit for archive created by Sapling 2025-05-08 16:12:43 -07:00
Michael Bolin
6cb677f2ab fix: use continue-on-error: true to tidy up GitHub Action 2025-05-08 16:12:33 -07:00
Michael Bolin
aac4fbd28d merge commit for archive created by Sapling 2025-05-08 16:11:27 -07:00
Michael Bolin
c9e9b1b365 fix: use continue-on-error: true to tidy up GitHub Action 2025-05-08 16:11:19 -07:00
Michael Bolin
a9adb4175c fix: enable clippy on tests (#870)
https://github.com/openai/codex/pull/855 added the clippy warning to
disallow `unwrap()`, but apparently we were not verifying that tests
were "clippy clean" in CI, so I ended up with a lot of local errors in
VS Code.

This turns on the check in CI and fixes the offenders.
2025-05-08 16:02:56 -07:00
Michael Bolin
35d7d23da4 Merge 81b854604e into sapling-pr-archive-bolinfest 2025-05-08 15:57:30 -07:00
Michael Bolin
81b854604e fix: enable clippy on tests 2025-05-08 15:57:24 -07:00
Michael Bolin
bda6cf4db9 Merge f0498675b6 into sapling-pr-archive-bolinfest 2025-05-08 15:53:18 -07:00
Michael Bolin
f0498675b6 fix: enable clippy on tests 2025-05-08 15:53:13 -07:00
Michael Bolin
c977e80515 Merge b07e74a95e into sapling-pr-archive-bolinfest 2025-05-08 15:40:16 -07:00
Michael Bolin
b07e74a95e fix: enable clippy on tests 2025-05-08 15:40:08 -07:00
Michael Bolin
2b5e41db65 Merge a32d8f8e3b into sapling-pr-archive-bolinfest 2025-05-08 15:17:39 -07:00
Michael Bolin
a32d8f8e3b feat: support the chat completions API in the Rust CLI 2025-05-08 15:17:29 -07:00
Michael Bolin
699ec5a87f fix: remove wrapping in Rust TUI that was incompatible with scrolling math (#868)
I noticed that sometimes I would enter a new message, but it would not
show up in the conversation history. Even if I focused the conversation
history and tried to scroll it to the bottom, I could not bring it into
view. At first, I was concerned that messages were not making it to the
UI layer, but I added debug statements and verified that was not the
issue.

It turned out that, previous to this PR, lines that are wider than the
viewport take up multiple lines of vertical space because `wrap()` was
set on the `Paragraph` inside the scroll pane. Unfortunately, that broke
our "scrollbar math" that assumed each `Line` contributes one line of
height in the UI.

This PR removes the `wrap()`, but introduces a new issue, which is that
now you cannot see long lines without resizing your terminal window. For
now, I filed an issue here:

https://github.com/openai/codex/issues/869

I think the long-term fix is to fix our math so it calculates the height
of a `Line` after it is wrapped given the current width of the viewport.
2025-05-08 15:17:17 -07:00
Michael Bolin
cc48304d61 Merge 3d676c3032 into sapling-pr-archive-bolinfest 2025-05-08 15:09:40 -07:00