Skip to content

fix(codex): replace rg with portable grep -E#1031

Closed
Piolttx wants to merge 1 commit intoaffaan-m:mainfrom
Piolttx:fix/codex-check-use-grep-instead-of-rg
Closed

fix(codex): replace rg with portable grep -E#1031
Piolttx wants to merge 1 commit intoaffaan-m:mainfrom
Piolttx:fix/codex-check-use-grep-instead-of-rg

Conversation

@Piolttx
Copy link
Copy Markdown

@Piolttx Piolttx commented Mar 31, 2026

What Changed

Replace all `rg -n` calls in `scripts/codex/check-codex-global-state.sh` with `grep -En`.
Also update `\s*` patterns to `[[:space:]]*` for POSIX ERE compatibility.

Why This Change

`ripgrep` is not universally available. Systems without `rg` installed silently fail the codex sanity check. `grep -E` is POSIX-standard and available everywhere.

Testing Done

  • Automated tests pass locally (`node tests/run-all.js`) — 1696/1696 ✓ (previously 1695/1696)

Type of Change

  • `fix:` Bug fix

Summary by cubic

Make the codex sanity check portable by replacing rg with grep -E and using POSIX-compatible patterns. This prevents silent failures on systems without ripgrep.

  • Bug Fixes
    • Replace rg -n with grep -En in scripts/codex/check-codex-global-state.sh.
    • Update \s* to [[:space:]]* for POSIX ERE compatibility.

Written for commit c141398. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Enhanced internal validation script pattern matching for improved accuracy and consistency across checks.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c007b4f9-8449-47ab-b112-b713c21060c0

📥 Commits

Reviewing files that changed from the base of the PR and between e68233c and c141398.

📒 Files selected for processing (1)
  • scripts/codex/check-codex-global-state.sh

📝 Walkthrough

Walkthrough

The shell script for Codex global-state validation was refactored to replace rg -n with grep -En across all pattern-matching checks, and regex patterns were tightened by substituting \s* with POSIX character class [[:space:]]* for explicit whitespace matching.

Changes

Cohort / File(s) Summary
Shell Script Validation Logic
scripts/codex/check-codex-global-state.sh
Replaced ripgrep (rg -n) with grep -En for pattern matching in all validation checks (config patterns, AGENTS.md markers, MCP headers). Updated regex patterns to use POSIX character classes ([[:space:]]*) instead of \s* for stricter whitespace matching in multi_agent and deprecated collab patterns.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A script that once searched with the ripgrep's bright glow,
Now grep commands dance in a standardized flow,
With POSIX spaces so perfectly tight,
The patterns align, oh what a sight! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(codex): replace rg with portable grep -E' directly and clearly describes the main change: replacing ripgrep (rg) with a portable grep -E implementation for improved compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 31, 2026

Greptile Summary

This PR replaces all rg -n (ripgrep) calls in scripts/codex/check-codex-global-state.sh with grep -En, and converts non-POSIX \s* shorthand to the standard POSIX ERE character class [[:space:]]*, making the script runnable on systems that do not have ripgrep installed.

  • All 8 rg -n invocations replaced with grep -En — functionally equivalent; both redirect output to /dev/null so only the exit code matters.
  • Three occurrences of \s* replaced with [[:space:]]*, which is the correct POSIX ERE equivalent and works with BSD grep (macOS) as well as GNU grep (Linux).
  • No logic, conditions, or patterns changed beyond the portability fix; all pattern anchors (^, ., escaped metacharacters) are preserved correctly.
  • The change is minimal, targeted, and correct; no new issues are introduced.

Confidence Score: 5/5

This PR is safe to merge; it is a straightforward portability fix with no logic changes.

All changes are mechanical substitutions of ripgrep with POSIX grep -E, and \s* with [[:space:]]*. The semantics are identical for the patterns used here. No new issues are introduced, and no pre-existing logic is altered. No P0 or P1 findings were identified.

No files require special attention.

Important Files Changed

Filename Overview
scripts/codex/check-codex-global-state.sh Replaces all rg -n (ripgrep) invocations with grep -En and converts \s* shorthand to POSIX ERE [[:space:]]*; change is correct and portable.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[check-codex-global-state.sh] --> B{File exists?}
    B -- AGENTS.md --> C[grep -En: ECC root header]
    B -- config.toml --> D[grep -En: multi_agent enabled]
    C --> E{Match?}
    D --> F{Match?}
    E -- yes --> G[ok]
    E -- no --> H[fail]
    F -- yes --> G
    F -- no --> H
    D --> I[grep -En: collab absent]
    D --> J[grep -En: persistent_instructions]
    D --> K[grep -En: profiles.strict / profiles.yolo]
    D --> L[grep -En: MCP sections loop]
    I --> M{Absent?}
    M -- yes --> G
    M -- no --> H
    J --> N{Present?}
    N -- yes --> G
    N -- no --> O[warn]
    L --> P{Match?}
    P -- yes --> G
    P -- no --> H
Loading

Reviews (1): Last reviewed commit: "fix(codex): replace rg with portable gre..." | Re-trigger Greptile

@affaan-m
Copy link
Copy Markdown
Owner

Superseded by #1039 which uses a search_file() fallback function.

@affaan-m affaan-m closed this Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants