Commit Graph

679 Commits

Author SHA1 Message Date
Michael Bolin
f53d9f73ac Merge f60e43a101 into sapling-pr-archive-bolinfest 2025-05-04 12:20:51 -07:00
Michael Bolin
f60e43a101 fix: ensure apply_patch resolves relative paths against workdir or project cwd 2025-05-04 12:20:40 -07:00
Michael Bolin
a134bdde49 fix: is_inside_git_repo should take the directory as a param (#809)
https://github.com/openai/codex/pull/800 made `cwd` a property of
`Config` and made it so the `cwd` is not necessarily
`std::env::current_dir()`. As such, `is_inside_git_repo()` should check
`Config.cwd` rather than `std::env::current_dir()`.

This PR updates `is_inside_git_repo()` to take `Config` instead of an
arbitrary `PathBuf` to force the check to operate on a `Config` where
`cwd` has been resolved to what the user specified.
2025-05-04 11:39:10 -07:00
Michael Bolin
1d4e6e275e merge commit for archive created by Sapling 2025-05-04 11:22:45 -07:00
Michael Bolin
92c5135060 fix: is_inside_git_repo should take the directory as a param 2025-05-04 11:22:41 -07:00
Michael Bolin
f8dae3f12c merge commit for archive created by Sapling 2025-05-04 11:22:35 -07:00
Michael Bolin
154fb92f02 fix: is_inside_git_repo should take the directory as a param 2025-05-04 11:22:31 -07:00
Michael Bolin
7fd16e13ec merge commit for archive created by Sapling 2025-05-04 11:21:58 -07:00
Michael Bolin
bb06b80404 fix: is_inside_git_repo should take the directory as a param 2025-05-04 11:21:53 -07:00
Michael Bolin
306f81f39c Merge 991bb2db44 into sapling-pr-archive-bolinfest 2025-05-04 11:17:45 -07:00
Michael Bolin
991bb2db44 fix: is_inside_git_repo should take the directory as a param 2025-05-04 11:17:29 -07:00
Michael Bolin
cd12f0c24a fix: TUI should use cwd from Config (#808)
https://github.com/openai/codex/pull/800 made `cwd` a property of
`Config`, so the TUI should use this instead of running
`std::env::current_dir()`.
2025-05-04 11:12:40 -07:00
Michael Bolin
29ebd0dc85 Merge 506b66e761 into sapling-pr-archive-bolinfest 2025-05-04 11:07:28 -07:00
Michael Bolin
506b66e761 fix: TUI should use cwd from Config 2025-05-04 11:07:18 -07:00
Michael Bolin
fb6f104765 Merge 5662a708e2 into sapling-pr-archive-bolinfest 2025-05-04 11:06:55 -07:00
Michael Bolin
5662a708e2 fix: TUI should use cwd from Config 2025-05-04 11:06:47 -07:00
Michael Bolin
421e159888 feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session (#800)
In order to expose Codex via an MCP server, I realized that we should be
taking `cwd` as a parameter rather than assuming
`std::env::current_dir()` as the `cwd`. Specifically, the user may want
to start a session in a directory other than the one where the MCP
server has been started.

This PR makes `cwd: PathBuf` a required field of `Session` and threads
it all the way through, though I think there is still an issue with not
honoring `workdir` for `apply_patch`, which is something we also had to
fix in the TypeScript version: https://github.com/openai/codex/pull/556.

This also adds `-C`/`--cd` to change the cwd via the command line.

To test, I ran:

```
cargo run --bin codex -- exec -C /tmp 'show the output of ls'
```

and verified it showed the contents of my `/tmp` folder instead of
`$PWD`.
2025-05-04 10:57:12 -07:00
Michael Bolin
2e1aa83cdb merge commit for archive created by Sapling 2025-05-04 09:36:21 -07:00
Michael Bolin
518023dbd9 feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 09:36:16 -07:00
Michael Bolin
f6b05ac326 merge commit for archive created by Sapling 2025-05-04 09:26:45 -07:00
Michael Bolin
9e3326e81e feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 09:26:40 -07:00
Michael Bolin
fd437390bf merge commit for archive created by Sapling 2025-05-04 09:26:12 -07:00
Michael Bolin
f9f0490ca2 feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 09:26:08 -07:00
Michael Bolin
c825ce2c72 merge commit for archive created by Sapling 2025-05-04 09:14:02 -07:00
Michael Bolin
f0ad889ebb feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 09:13:57 -07:00
Michael Bolin
71db7c5bfe merge commit for archive created by Sapling 2025-05-04 09:12:23 -07:00
Michael Bolin
a9816188c6 feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 09:12:18 -07:00
Michael Bolin
9514c89a6d merge commit for archive created by Sapling 2025-05-04 09:01:28 -07:00
Michael Bolin
b2a2481516 feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 09:01:23 -07:00
Michael Bolin
5ba44386a2 Merge 97bc9314ca into sapling-pr-archive-bolinfest 2025-05-04 08:56:28 -07:00
Michael Bolin
97bc9314ca feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 08:56:24 -07:00
Michael Bolin
e12cf808b5 merge commit for archive created by Sapling 2025-05-04 08:48:37 -07:00
Michael Bolin
72b1d3ad57 feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 08:48:32 -07:00
Michael Bolin
c2806574cb merge commit for archive created by Sapling 2025-05-04 08:43:54 -07:00
Michael Bolin
15bc38585c feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-04 08:43:49 -07:00
Michael Bolin
66a2153d4f Merge 3f73058676 into sapling-pr-archive-bolinfest 2025-05-03 13:52:15 -07:00
Michael Bolin
3f73058676 feat: make cwd a required field of Config so we stop assuming std::env::current_dir() in a session 2025-05-03 13:52:06 -07:00
Michael Bolin
717dac4690 Merge da049df255 into sapling-pr-archive-bolinfest 2025-05-03 12:31:08 -07:00
Michael Bolin
da049df255 feat: drop support for q since we already support ctrl+d 2025-05-03 12:30:58 -07:00
Andrey Mishchenko
4b61fb8bab use "Title case" in README.md (#798) 2025-05-03 10:17:44 -07:00
Michael Bolin
0442458309 doc: update the config.toml documentation for the Rust CLI in codex-rs/README.md (#795)
https://github.com/openai/codex/pull/793 had important information on
the `notify` config option that seemed worth memorializing, so this PR
updates the documentation about all of the configurable options in
`~/.codex/config.toml`.
2025-05-02 20:32:24 -07:00
Michael Bolin
7c7b55e7c9 merge commit for archive created by Sapling 2025-05-02 20:30:23 -07:00
Michael Bolin
cbd97f54e5 doc: update the config.toml documentation for the Rust CLI in codex-rs/README.md 2025-05-02 20:30:18 -07:00
Michael Bolin
a001909243 merge commit for archive created by Sapling 2025-05-02 20:29:23 -07:00
Michael Bolin
630880e379 doc: update the config.toml documentation for the Rust CLI in codex-rs/README.md 2025-05-02 20:29:18 -07:00
Michael Bolin
84c0b0c589 Merge dfa0c64528 into sapling-pr-archive-bolinfest 2025-05-02 20:27:14 -07:00
Michael Bolin
dfa0c64528 doc: update the config.toml documentation for the Rust CLI in codex-rs/README.md 2025-05-02 20:27:06 -07:00
Michael Bolin
a180ed44e8 feat: configurable notifications in the Rust CLI (#793)
With this change, you can specify a program that will be executed to get
notified about events generated by Codex. The notification info will be
packaged as a JSON object. The supported notification types are defined
by the `UserNotification` enum introduced in this PR. Initially, it
contains only one variant, `AgentTurnComplete`:

```rust
pub(crate) enum UserNotification {
    #[serde(rename_all = "kebab-case")]
    AgentTurnComplete {
        turn_id: String,

        /// Messages that the user sent to the agent to initiate the turn.
        input_messages: Vec<String>,

        /// The last message sent by the assistant in the turn.
        last_assistant_message: Option<String>,
    },
}
```

This is intended to support the common case when a "turn" ends, which
often means it is now your chance to give Codex further instructions.

For example, I have the following in my `~/.codex/config.toml`:

```toml
notify = ["python3", "/Users/mbolin/.codex/notify.py"]
```

I created my own custom notifier script that calls out to
[terminal-notifier](https://github.com/julienXX/terminal-notifier) to
show a desktop push notification on macOS. Contents of `notify.py`:

```python
#!/usr/bin/env python3

import json
import subprocess
import sys


def main() -> int:
    if len(sys.argv) != 2:
        print("Usage: notify.py <NOTIFICATION_JSON>")
        return 1

    try:
        notification = json.loads(sys.argv[1])
    except json.JSONDecodeError:
        return 1

    match notification_type := notification.get("type"):
        case "agent-turn-complete":
            assistant_message = notification.get("last-assistant-message")
            if assistant_message:
                title = f"Codex: {assistant_message}"
            else:
                title = "Codex: Turn Complete!"
            input_messages = notification.get("input_messages", [])
            message = " ".join(input_messages)
            title += message
        case _:
            print(f"not sending a push notification for: {notification_type}")
            return 0

    subprocess.check_output(
        [
            "terminal-notifier",
            "-title",
            title,
            "-message",
            message,
            "-group",
            "codex",
            "-ignoreDnD",
            "-activate",
            "com.googlecode.iterm2",
        ]
    )

    return 0


if __name__ == "__main__":
    sys.exit(main())
```

For reference, here are related PRs that tried to add this functionality
to the TypeScript version of the Codex CLI:

* https://github.com/openai/codex/pull/160
* https://github.com/openai/codex/pull/498
codex-rs-5915a59c8290765d6097caf4074aae93a85380fa-1-rust-v0.0.2505021951
2025-05-02 19:48:13 -07:00
Michael Bolin
2cee8b914e Merge 68a493930a into sapling-pr-archive-bolinfest 2025-05-02 19:37:33 -07:00
Michael Bolin
68a493930a feat: add support for notifications 2025-05-02 19:37:27 -07:00