codex icon indicating copy to clipboard operation
codex copied to clipboard

feat: comprehensive codebase improvements with syntax highlighting

Open bniladridas opened this issue 3 months ago • 10 comments

Comprehensive Codebase Improvements and Syntax Highlighting

Summary

This PR delivers multiple critical improvements to the Codex codebase, including syntax highlighting for markdown code blocks and comprehensive fixes to release scripts, CI/CD workflows, and security enhancements.

Major Changes

🎨 Syntax Highlighting (Original Feature)

  • Added syntax highlighting for code blocks via syntect (behind feature flag)
  • Integrated syntect with theme support and fallback to plain text
  • Basic test coverage for Rust code highlighting

🔧 Release Script Fixes (Critical)

  • Fixed global variable references in create_github_release script
  • Removed duplicate helper functions that referenced undefined globals
  • Fixed undefined response variable in create_tag_ref function
  • Made all functions repo-aware with proper parameter passing
  • Eliminated NameError/TypeError runtime issues

🔒 Security Enhancements

  • Clamped page_size to safe range (1-100) in MCP server to prevent unbounded allocations
  • Enhanced input validation and bounds checking

🚀 CI/CD Improvements

  • Enhanced untracked file detection in protocol/bindings/ directory
  • Fixed pnpm setup with proper installation and activation
  • Improved working directory handling (removed fragile cd ..)
  • Better error reporting for both tracked and untracked file changes

🏗️ Code Quality

  • Removed duplicate implementations and consolidated helper functions
  • Fixed type mismatches and serialization issues
  • Improved error handling throughout the codebase
  • Enhanced maintainability with proper parameter passing

Verification

  • [x] Syntax highlighting works for Rust code blocks
  • [x] All Python scripts compile without syntax errors
  • [x] All Rust packages compile successfully
  • [x] No clippy warnings or linting errors
  • [x] All existing tests pass (11/11)
  • [x] CI workflow YAML is valid
  • [x] No TODO/FIXME comments remain

Technical Details

  • Files Modified: 3 core files + 74 TypeScript bindings
  • Lines Changed: +34 insertions, -82 deletions
  • Breaking Changes: None
  • Dependencies: Optional syntect for syntax highlighting

Notes

  • Syntax highlighting is behind a feature flag for optional dependency
  • All fixes maintain backward compatibility
  • Comprehensive test coverage maintained
  • Security bounds enforced throughout

bniladridas avatar Aug 30 '25 10:08 bniladridas

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

github-actions[bot] avatar Aug 30 '25 10:08 github-actions[bot]

I have read the CLA Document and I hereby sign the CLA

bniladridas avatar Aug 30 '25 10:08 bniladridas

@richardlin-openai Please review this PR for syntax highlighting in markdown code blocks.

bniladridas avatar Sep 04 '25 20:09 bniladridas

Hi @bniladridas I'm not the right person to review

richardlin-openai avatar Sep 04 '25 20:09 richardlin-openai

Tagging @nornagon-openai for review.

bniladridas avatar Sep 04 '25 20:09 bniladridas

The Lazy pattern is used here for efficient resource management:

// Note: Lazy is used for efficient static initialization of syntax highlighting resources.
// It ensures they're only loaded when the syntax_highlighting feature is enabled.
pub(super) static SYNTAX_SET: Lazy<SyntaxSet> = Lazy::new(SyntaxSet::load_defaults_newlines);
pub(super) static THEME: Lazy<ThemeSet> = Lazy::new(ThemeSet::load_defaults);

Benefits:

  • Resources are only loaded on first access, not at compile time
  • Memory efficient when syntax highlighting feature is disabled
  • Thread-safe static initialization
  • Works seamlessly with the feature-gated module structure

bniladridas avatar Sep 08 '25 18:09 bniladridas

This PR adds syntax highlighting for markdown code blocks with the following implementation:

Key Changes:

  • Added syntax-highlighting feature flag and syntect dependency to codex-rs/tui/Cargo.toml
  • Implemented complete syntax highlighting module in codex-rs/tui/src/markdown.rs with:
    • Language detection for code blocks
    • Theme support (base16-ocean.dark with fallbacks)
    • Feature-gated module for optional compilation
    • Fallback to plain text when feature disabled
    • Comprehensive test coverage

Technical Details:

  • Uses once_cell::sync::Lazy for efficient static initialization
  • Integrates seamlessly with existing markdown rendering pipeline
  • Thread-safe and memory-efficient implementation
  • Supports common programming languages with automatic detection

bniladridas avatar Sep 08 '25 19:09 bniladridas

Verification Commands

# Test with syntax highlighting enabled
cargo test -p codex-tui --features syntax-highlighting

# Test without syntax highlighting (fallback)
cargo test -p codex-tui

# Build binary with syntax highlighting
cargo build --release --bin codex-tui --features syntax-highlighting

# Run binary with syntax highlighting
cargo run --bin codex-tui --features syntax-highlighting

bniladridas avatar Sep 08 '25 19:09 bniladridas

@bolinfest

bniladridas avatar Sep 08 '25 19:09 bniladridas

@bniladridas you appear to have unrelated changes in your PR: could you please fix?

bolinfest avatar Sep 08 '25 22:09 bolinfest

Hey @bolinfest , can you please look at it now. sorry for the confusion arose.

bniladridas avatar Sep 08 '25 23:09 bniladridas

I'm going to defer to @nornagon-openai and @easong-openai but this certainly appears more on point now!

bolinfest avatar Sep 08 '25 23:09 bolinfest

@bniladridas in the meantime, just fmt

bolinfest avatar Sep 08 '25 23:09 bolinfest

Sure appreciate it.

bniladridas avatar Sep 08 '25 23:09 bniladridas

  • [x] Code formatted with cargo fmt
  • [x] Clippy checks passed
  • [x] Linter fixes applied with cargo fix
  • [x] All tests passed (239 passed, 0 failed)

bniladridas avatar Sep 09 '25 22:09 bniladridas

@bniladridas we've changed our markdown rendering substantially in #3396, and I think this change will need to be updated to work with the new code.

nornagon-openai avatar Sep 10 '25 22:09 nornagon-openai