Skip to content

[codex-cli] Add ripgrep as a dependency for node environment - #2237

Merged
dylan-hurd-oai merged 5 commits into
mainfrom
dh--npm-rg
Aug 13, 2025
Merged

dylan-hurd-oai merged 5 commits into
mainfrom
dh--npm-rg

Conversation

@dylan-hurd-oai

@dylan-hurd-oai dylan-hurd-oai commented Aug 12, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Ripgrep is our preferred tool for file search. When users install via brew install codex, it's automatically installed as a dependency. We want to ensure that users running via an npm install also have this tool! Microsoft has already solved this problem for VS Code - let's not reinvent the wheel.

This approach of appending to the PATH directly might be a bit heavy-handed, but feels reasonably robust to a variety of environment concerns. Open to thoughts on better approaches here!

Testing

  • confirmed this import approach works with node -e "const { rgPath } = require('@vscode/ripgrep'); require('child_process').spawn(rgPath, ['--version'], { stdio: 'inherit' })"
  • Ran codex.js locally with rg uninstalled, asked it to run which rg. Output below:
⚡ Ran command which rg; echo $?
  ⎿ /Users/dylan.hurd/code/dh--npm-rg/node_modules/@vscode/ripgrep/bin/rg
    0

codex
Re-running to confirm the path and exit code.

- Path: `/Users/dylan.hurd/code/dh--npm-rg/node_modules/@vscode/ripgrep/bin/rg`
- Exit code: `0`

@bolinfest bolinfest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is imperative that you test this with:

./scripts/publish_to_npm.py --dry-run

and make sure all the files that you expect to go in the .tgz end up there.

I believe this is responsible for ensuring which files are included:

"files": [
"bin",
"dist"
],

I don't think there are any new files, but to be sure, I would use ./scripts/publish_to_npm.py --dry-run to create the .tgz and then do a local install using that to ensure that the dependencies get installed into node_modules as expected and everything lines up.

Comment thread codex-cli/bin/codex.js Outdated
}
}

async function resolveRgPath() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In deleting most of codex-cli, I guess we lost Prettier coverage for this file...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated package.json scripts to include js files!

Comment thread package.json Outdated
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"@vscode/ripgrep": "^1.15.14"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this does not guarantee that rg gets installed because the npm package does not bundle the binaries itself, but downloads them via postinstall:

https://www.npmjs.com/package/@vscode/ripgrep

Because we expect our users to install via npm -g and have network access at that time, this should be fine, but if they used --ignore-scripts for some reason, then it wouldn't end up getting fetched.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agree it's not bullet-proof! However, the postinstall script also resolves to a platform-specific build for us, which is a nice property. I think the tradeoff is worth it. We could add a note to one of our docs about installing correctly

Comment thread codex-cli/bin/codex.js Resolved
Comment thread codex-cli/bin/codex.js Resolved
Comment thread codex-cli/bin/codex.js Resolved
Comment thread codex-cli/bin/codex.js Resolved
@dylan-hurd-oai

Copy link
Copy Markdown
Contributor Author

Tested with the following steps:

# on local branch
npm pack --pack-destination ../dist
scp ./dist/openai-codex-0.0.0-dev.tgz user@devbox:~/code/test/

# on devbox
tar -xzf openai-codex-0.0.0-dev.tgz
cd package
npm install
./bin/codex.js e --skip-git-repo-check "run which rg. do not use bash -lc"
...
rg found at: `/root/code/test_codex_npm/package/node_modules/@vscode/ripgrep/bin/rg`

@bolinfest bolinfest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good, but I would make it so the CLI still runs if we can't load rg from @vscode/ripgrep.

Comment thread codex-cli/bin/codex.js Resolved
@dylan-hurd-oai
dylan-hurd-oai merged commit 99a242e into main Aug 13, 2025
@dylan-hurd-oai
dylan-hurd-oai deleted the dh--npm-rg branch August 13, 2025 20:49
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants