Commit Graph
1776 Commits
Author SHA1 Message Date
Abdelrhman Kamal Mahmoud Ali Slim 425430debb fix(cli): ensure /clear resets context and exclude system messages from approximateTokenUsed count (#443)
https://github.com/user-attachments/assets/58b8f261-a359-4cd8-8c84-90d8d91a5592
2025-04-20 08:52:14 -07:00
Brayden MoonandThibault Sottiaux 6d6ca454cd feat: allow multi-line input (#438)
## Description
This PR implements multi-line input support for Codex when it asks for
user feedback (Issue #344). Users can now use Shift+Enter to add new
lines in their responses, making it easier to provide formatted code
snippets, lists, or other structured content.

## Changes
- Replace the single-line TextInput component with the
MultilineTextEditor component in terminal-chat-input.tsx
- Add support for Shift+Enter to create new lines
- Update key handling logic to properly handle history navigation in a
multi-line context
- Add reference to the editor to access cursor position information
- Update help text to inform users about the Shift+Enter functionality
- Add tests for the new functionality

## Testing
- Added new test file (terminal-chat-input-multiline.test.tsx) to test
the multi-line input functionality
- All existing tests continue to pass
- Manually tested the feature to ensure it works as expected

## Fixes
Closes #344

## Screenshots
N/A

## Additional Notes
This implementation maintains backward compatibility while adding the
requested multi-line input functionality. The UI remains clean and
intuitive, with a simple hint about using Shift+Enter for new lines.

---------

Co-authored-by: Thibault Sottiaux <tibo@openai.com>
2025-04-20 08:51:38 -07:00
Thomas fc1e45636e feat: add support for /diff command autocomplete in TerminalChatInput (#431)
It's not working without this
2025-04-19 20:01:40 -07:00
Michael Bolin c8946bc9ab Merge 698381bae4 into sapling-pr-archive-bolinfest 2025-04-19 18:30:15 -07:00
Michael Bolin 698381bae4 reduce max output of ExecResult 2025-04-19 18:29:11 -07:00
Michael Bolin 4025cb6909 remove unnecessary isLoggingEnabled() checks 2025-04-19 18:29:11 -07:00
Michael Bolin a7a4a69ccc CONFIG_DIR should not be in the list of writable roots by default 2025-04-19 18:29:11 -07:00
Michael Bolin 63c99e7d82 use spawn instead of exec to avoid injection vulnerability (#416)
https://github.com/openai/codex/pull/160 introduced a call to `exec()`
that takes a format string as an argument, but it is not clear that the
expansions within the format string are escaped safely. As written, it
is possible a carefully crafted command (e.g., if `cwd` were `"; && rm
-rf` or something...) could run arbitrary code.

Moving to `spawn()` makes this a bit better, as now at least `spawn()`
itself won't run an arbitrary process, though I suppose `osascript`
itself still could if the value passed to `-e` were abused. I'm not
clear on the escaping rules for AppleScript to ensure that `safePreview`
and `cwd` are injected safely.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/416).
* #423
* #420
* #419
* __->__ #416
2025-04-19 18:29:00 -07:00
Tomas CuprandThibault Sottiaux a3889f92e4 fix: full-auto support in quiet mode (#374)
Fixes https://github.com/openai/codex/issues/292

---------

Co-authored-by: Thibault Sottiaux <tibo@openai.com>
2025-04-19 17:00:33 -07:00
Fouad Matin b3b195351e feat: /diff command to view git diff (#426)
Adds `/diff` command to view git diff
2025-04-19 16:23:27 -07:00
Michael Bolin b569794440 merge commit for archive created by Sapling 2025-04-19 11:49:22 -07:00
Michael Bolin cdef7dfddc reduce max output of ExecResult 2025-04-19 11:49:16 -07:00
Michael Bolin 5bed84450d Merge cdb7325192 into sapling-pr-archive-bolinfest 2025-04-19 11:45:30 -07:00
Michael Bolin 1757ff3eb2 remove unnecessary isLoggingEnabled() checks 2025-04-19 11:45:21 -07:00
Michael Bolin cdb7325192 reduce max output of ExecResult 2025-04-19 11:45:21 -07:00
Michael Bolin 507bc768bd CONFIG_DIR should not be in the list of writable roots by default 2025-04-19 11:45:21 -07:00
Michael Bolin c392752867 Merge c03bb96438 into sapling-pr-archive-bolinfest 2025-04-19 11:41:56 -07:00
Michael Bolin c03bb96438 reduce max output of ExecResult 2025-04-19 11:41:49 -07:00
Michael Bolin 52f805d3f8 Merge 7a16e239fc into sapling-pr-archive-bolinfest 2025-04-19 11:24:07 -07:00
Michael Bolin 70138aed17 use spawn instead of exec to avoid injection vulnerability 2025-04-19 11:23:58 -07:00
Michael Bolin 7a16e239fc remove unnecessary isLoggingEnabled() checks 2025-04-19 11:23:58 -07:00
Michael Bolin 75919d78fc CONFIG_DIR should not be in the list of writable roots by default 2025-04-19 11:23:58 -07:00
Michael Bolin 419f085cc4 re-enable Prettier check for codex-cli in CI (#417)
This check was lost in https://github.com/openai/codex/pull/287. Both
the root folder and `codex-cli/` have their own `pnpm format` commands
that check the formatting of different things.

Also ran `pnpm format:fix` to fix the formatting violations that got in
while this was disabled in CI.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/417).
* #420
* #419
* #416
* __->__ #417
2025-04-19 11:22:45 -07:00
Michael Bolin 8c8b1c7787 merge commit for archive created by Sapling 2025-04-19 11:12:54 -07:00
Michael Bolin bce7ab2fea remove unnecessary isLoggingEnabled() checks 2025-04-19 11:12:49 -07:00
Michael Bolin 40dfb7053e merge commit for archive created by Sapling 2025-04-19 11:09:58 -07:00
Michael Bolin f77625ea88 remove unnecessary isLoggingEnabled() checks 2025-04-19 11:09:52 -07:00
Michael Bolin 3aa51bf393 Merge 6ac0fd5fc1 into sapling-pr-archive-bolinfest 2025-04-19 11:07:44 -07:00
Michael Bolin 6ac0fd5fc1 remove unnecessary isLoggingEnabled() checks 2025-04-19 11:07:35 -07:00
Michael Bolin 79cee3982c merge commit for archive created by Sapling 2025-04-19 10:29:40 -07:00
Michael Bolin 5333ea726f CONFIG_DIR should not be in the list of writable roots by default 2025-04-19 10:29:18 -07:00
Michael Bolin 0430ab327b use spawn instead of exec to avoid injection vulnerability 2025-04-19 10:29:18 -07:00
Michael Bolin 8a4968ae9f re-enable Prettier check for codex-cli in CI 2025-04-19 10:29:18 -07:00
Michael Bolin 6f3e126388 Merge 3bbeba28ce into sapling-pr-archive-bolinfest 2025-04-19 10:26:39 -07:00
Michael Bolin 3bbeba28ce CONFIG_DIR should not be in the list of writable roots by default 2025-04-19 10:26:23 -07:00
Michael Bolin 75ea97455f Merge 19a43ad15b into sapling-pr-archive-bolinfest 2025-04-19 10:03:37 -07:00
Michael Bolin 19a43ad15b use spawn instead of exec to avoid injection vulnerability 2025-04-19 10:03:17 -07:00
Michael Bolin 896b05ba27 Merge be9d216aab into sapling-pr-archive-bolinfest 2025-04-19 10:03:07 -07:00
Michael Bolin be9d216aab re-enable Prettier check for codex-cli in CI 2025-04-19 10:03:01 -07:00
Michael Bolin da6410668a Merge ede10c1247 into sapling-pr-archive-bolinfest 2025-04-19 10:01:49 -07:00
Michael Bolin ede10c1247 re-enable Prettier check for codex-cli in CI 2025-04-19 10:01:42 -07:00
Michael Bolin 37b878e933 Merge 66ae9fd234 into sapling-pr-archive-bolinfest 2025-04-19 10:01:29 -07:00
Michael Bolin 66ae9fd234 re-enable Prettier check for codex-cli in CI 2025-04-19 10:01:18 -07:00
Michael Bolin 832b98a557 use spawn instead of exec to avoid injection vulnerability 2025-04-19 09:52:49 -07:00
081786eaa6 feat: add /command autocomplete (#317)
Add interactive slash‑command autocomplete & navigation in chat input

    Description
This PR enhances the chat input component by adding first‑class support
for slash commands (/help, /clear, /compact, etc.)
    with:

* **Live filtering:** As soon as the user types leading `/`, a list of
matching commands is shown below the prompt.
* **Arrow‑key navigation:** Up/Down arrows cycle through suggestions.
* **Enter to autocomplete:** Pressing Enter on a partial command will
fill it (without submitting) so you can add
    arguments or simply press Enter again to execute.
* **Type‑safe registry:** A new `slash‑commands.ts` file declares all
supported commands in one place, along with
    TypeScript types to prevent drift.
* **Validation:** Only registered commands will ever autocomplete or be
suggested; unknown single‑word slash inputs still
    show an “Invalid command” system message.
        * **Automated tests:**
            * Unit tests for the command registry and prefix filtering

            * Existing tests continue passing with no regressions

    Motivation
Slash commands provide a quick, discoverable way to control the agent
(clearing history, compacting context, opening overlays,
etc.). Before, users had to memorize the exact command or rely on the
generic /help list—autocomplete makes them far more
    accessible and reduces typos.

    Changes

* `src/utils/slash‑commands.ts` – defines `SlashCommand` and exports a
flat list of supported commands + descriptions
        * `terminal‑chat‑input.tsx`
            * Import and type the command registry

* Render filtered suggestions under the prompt when input starts with
`/`

* Hook into `useInput` to handle Up/Down and Enter for selection & fill

* Flag to swallow the first Enter (autocomplete) and only submit on the
next
* Updated tests in `tests/slash‑commands.test.ts` to cover registry
contents and filtering logic
        * Removed old JS version and fixed stray `@ts‑expect‑error`

    How to test locally

        1. Type `/` in the prompt—you should see matching commands.
2. Use arrows to move the highlight, press Enter to fill, then Enter
again to execute.
3. Run the full test suite (`npm test`) to verify no regressions.

    Notes

* Future work could include fuzzy matching, paging long lists, or more
visual styling.
* This change is purely additive and does not affect non‑slash inputs or
existing slash handlers.

---------

Co-authored-by: Fouad Matin <169186268+fouad-openai@users.noreply.github.com>
Co-authored-by: Thibault Sottiaux <tibo@openai.com>
2025-04-19 07:25:46 -07:00
John Gardner 965420cfc5 feat: read approvalMode from config file (#298)
This PR implements support for reading the approvalMode setting from the
user's config file (`~/.codex/config.json` or `~/.codex/config.yaml`),
allowing users to set a persistent default approval mode without needing
to specify command-line flags for each session.

Changes:
- Added approvalMode to the AppConfig type in config.ts
- Updated loadConfig() to read the approval mode from the config file
- Modified saveConfig() to persist the approval mode setting
- Updated CLI logic to respect the config-defined approval mode (while
maintaining CLI flag priority)
- Added comprehensive tests for approval mode config functionality
- Updated README to document the new config option in both YAML and JSON
formats
- additions to `.gitignore` for other CLI tools

Motivation:
As a user who regularly works with CLI-tools, I found it odd to have to
alias this with the command flags I wanted when `approvalMode` simply
wasn't being parsed even though it was an optional prop in `config.ts`.
This change allows me (and other users) to set the preference once in
the config file, streamlining daily usage while maintaining the ability
to override via command-line flags when needed.

Testing:
I've added a new test case loads and saves approvalMode correctly that
verifies:
- Reading the approvalMode from the config file works correctly
- Saving the approvalMode to the config file works as expected
- The value persists through load/save operations

All tests related to the implementation are passing.
2025-04-19 07:25:25 -07:00
Suyash-KandThibault Sottiaux b37b257e63 gracefully handle SSE parse errors and suppress raw parser code (#367)
Closes #187
Closes #358

---------

Co-authored-by: Thibault Sottiaux <tibo@openai.com>
2025-04-19 07:24:29 -07:00
Abdelrhman Kamal Mahmoud Ali SlimandThibault Sottiaux f3cab736b4 fix: name of the file not matching the name of the component (#354)
before

![image](https://github.com/user-attachments/assets/e47595bc-8b5b-470d-8cca-1d4c4afbf802)
after

![image](https://github.com/user-attachments/assets/c04bc384-534e-44f0-9917-08a15f7280dc)

Co-authored-by: Thibault Sottiaux <tibo@openai.com>
2025-04-19 07:23:02 -07:00
Scott Leibrand 9eeb78e54f feat: allow switching approval modes when prompted to approve an edit/command (#400)
Implements https://github.com/openai/codex/issues/392

When the user is in suggest or auto-edit mode and gets an approval
request, they now have an option in the `Shell Command` dialog to:
`Switch approval mode (v)`

That option brings up the standard `Switch approval mode` dialog,
allowing the user to switch into the desired mode, then drops them back
to the `Shell Command` dialog's `Allow command?` prompt, allowing them
to approve the current command and let the agent continue doing the rest
of what it was doing without interruption.
```
╭────────────────────────────────────────────────────────
│Shell Command
│                          
│$ apply_patch << 'PATCH'    
│*** Begin Patch                      
│*** Update File: foo.txt          
│@@ -1 +1 @@                         
│-foo                                          
│+bar                                         
│*** End Patch                         
│PATCH                                    
│                                                
│                                                
│Allow command?                   
│                                                
│    Yes (y)                                
│    Explain this command (x) 
│    Edit or give feedback (e)  
│    Switch approval mode (v)
│    No, and keep going (n)    
│    No, and stop for now (esc)
╰────────────────────────────────────────────────────────╭────────────────────────────────────────────────────────
│ Switch approval mode      
│ Current mode: suggest  
│                                          
│                                          
│                                          
│ ❯ suggest                        
│   auto-edit                       
│   full-auto                        
│ type to search · enter to confirm · esc to cancel 
╰────────────────────────────────────────────────────────
```
2025-04-19 07:21:19 -07:00
Alpha DiopandThibault Sottiaux 6c7fbc7b94 fix: configure husky and lint-staged for pnpm monorepo (#384)
# Improve Developer Experience with Husky and lint-staged for pnpm
Monorepo

## Summary
This PR enhances the developer experience by configuring Husky and
lint-staged to work properly with our pnpm monorepo structure. It
centralizes Git hooks at the root level and ensures consistent code
quality across the project.

## Changes
- Centralized Husky and lint-staged configuration at the monorepo root
- Added pre-commit hook that runs lint-staged to enforce code quality
- Configured lint-staged to:
  - Format JSON, MD, and YAML files with Prettier
  - Lint and typecheck TypeScript files before commits
- Fixed release script in codex-cli package.json (changed "pmpm" to "npm
publish")
- Removed duplicate Husky and lint-staged configurations from codex-cli
package.json

## Benefits
- **Consistent Code Quality**: Ensures all committed code meets project
standards
- **Automated Formatting**: Automatically formats code during commits
- **Early Error Detection**: Catches type errors and lint issues before
they're committed
- **Centralized Configuration**: Easier to maintain and update in one
place
- **Improved Collaboration**: Ensures consistent code style across the
team

## Future Improvements
We could further enhance this setup by
**Commit Message Validation**: Add commitlint to enforce conventional
commit messages

---------

Co-authored-by: Thibault Sottiaux <tibo@openai.com>
2025-04-19 07:18:36 -07:00