55 Commits
Author SHA1 Message Date
zeekay ac805370ab feat: add in-terminal browser via CDP (feature-gated)
Port the browser crate from just-every/code into codex-rs as
codex-browser. Adds Chrome DevTools Protocol integration for
in-terminal web browsing, screenshot capture, and page interaction.

Feature-gated behind `browser` in codex-tui — default builds are
unchanged. Enable with: cargo build --features browser

New files:
- codex-rs/browser/ — CDP client (chromiumoxide), page management,
  screenshot capture, browser tools, hook injection
- codex-rs/tui/src/chatwidget/browser_sessions.rs — session tracking
- codex-rs/tui/src/history_cell/browser.rs — browser history cells
- codex-rs/tui/src/chrome_launch.rs — Chrome detection/launch
2026-03-31 13:53:35 -07:00
James Peter c785f2da58 chore(codex-rs): sync with upstream main 2025-10-05 12:05:06 +10:00
James Peter 7336ef435b fix(browser/goto): retry after recoverable failures 2025-10-01 18:59:40 +10:00
James Peter ee584fbe5d fix(login): remove rand deprecation warnings by using rand::rng().fill_bytes()
Policy: treat warnings as failures. Switched from thread_rng() to rng() in PKCE
and login state generation. Build remains clean.
2025-09-16 11:29:31 +10:00
James Peter 7129de26db ci(upstream-merge): default-to-ours; remove prefer_theirs usage; dynamic cleanup for reintroduced crates; smarter purge; agent autonomy 2025-09-07 19:36:08 +10:00
James Peter 238f495b67 feat(tui/chrome): allow specifying host for external Chrome connection (dev containers)\n\n- Add to browser config and plumb through BrowserManager\n- Extend to accept , Host port not found: 3(NXDOMAIN), plain , or a full endpoint\n- Use host when discovering WS URL instead of always 127.0.0.1\n\nThis enables connecting from inside Docker/devcontainers to a Chrome running on the host (e.g., host.docker.internal:9222).\n\nCloses #39 2025-09-06 10:20:42 +10:00
James Peter 8cc7b8ef04 chore: revert unrelated changes in browser/prompt/history/tui files from prior commit 2025-09-01 23:16:39 +10:00
James Peter 3650b647cb fix(core/exec): kill child on task abort to avoid orphaned commands\n\nWrap spawned child in KillOnDrop guard so user interrupts (which abort the agent\ntask) terminate the process immediately. This ensures the UI no longer shows\ncommands as still running after cancel, and the OS process is not left alive. 2025-09-01 23:16:21 +10:00
James Peter a240e22e45 feat(browser): improve internal browser launch diagnostics and log path 2025-09-01 18:05:09 +10:00
James Peter c38ed5bf31 feat(browser,tui): CDP console logs; collapsible HUD; page scroll
browser/manager: install JS console hook on connect to capture logs immediately for already-loaded pages; prefer CDP-captured buffer and fall back to JS hook.\n\nbrowser/page: enable CDP Runtime/Log and buffer console + log events; expose tail accessor.\n\nTUI/chatwidget: add HUD expand/collapse toggles (Ctrl+B for Browser, Ctrl+P for Agents), PageUp/PageDown to page transcript, and track external Chrome connection status for titles.\n\nTUI/height_manager: allow caller-provided HUD target height to support stacked/collapsed layout; keep legacy aspect estimate as fallback.\n\napp, app_event_sender, tui: wire height target and redraws.\n\nRationale: ensure reliable console capture regardless of page state and improve TUI ergonomics for HUD and scrolling.
2025-09-01 09:53:22 +10:00
James Peter ca102f4564 chore(codex-rs): commit outstanding changes across core, tui, and browser 2025-08-29 00:56:02 +10:00
James Peter 05e07fe138 fix(tui): clear full history region (incl. padding) each frame to eliminate rare margin artifacts and ensure background is fully painted 2025-08-24 00:57:37 +10:00
James Peter c692dcb2f7 tui: Clear stale cached Chrome WS URL and retry via port discovery when WS connect fails (handles 404 after Chrome restart).\n\n- Prefer cached WS; on failure, clear WS cache (in-memory + disk), fallback to cached port or auto-scan, and retry once.\n- Emit clear success/failure background events; persist new connection on success.\n\nbrowser(page.rs): Inline rationale and comments for screenshot strategy to avoid flash and reduce timeouts.\n\n- Prefer from_surface(false) for visible pages; conservative retries.\n- Non-visible: fast 8×8 preflight probe (350ms) cached ~5s to choose path.\n- Final from_surface(true) fallback only as last resort.\n\nDocs: Remove external doc; comments now self-contained. 2025-08-20 20:32:50 +10:00
James Peter d78ce1b8f5 fix(browser-console): improve console inspect output; update core exec events and TUI handling; minor cleanups 2025-08-20 18:27:44 +10:00
James Peter cce4afaac8 browser: add low-frequency viewport monitor; avoid internal CDP viewport override on connect; implement on-demand set_viewport; update config on browser.setViewport; stop per-screenshot resyncs 2025-08-20 14:03:26 +10:00
James Peter 275168f288 browser: stop per-screenshot viewport corrections to avoid flash on external Chrome; rely on connect-time metrics 2025-08-20 13:53:55 +10:00
James Peter ba447e0fb1 browser: remove inline screenshots; tighten click/move waits; snap cursor internally; faster typing (30–60ms) and paste-style for >=100 chars; reduce JS settle for internal/external; remove fixed post-move sleep 2025-08-20 13:41:28 +10:00
James Peter ec3c3adc20 chore: commit all current changes 2025-08-18 16:28:18 +10:00
James Peter b9adced314 refactor(naming): switch binaries and artifacts from 'coder' to 'code'; keep 'coder' as fallback alias only. Update workflows, scripts, and postinstall. 2025-08-17 20:45:10 +10:00
James Peter 98c169aef6 chore: commit pending code changes across codex-rs (browser, core, tui) 2025-08-17 18:55:58 +10:00
James Peter b3748ec9f9 core: implement sequential agent_wait when return_all=false
- Track seen completed agents per batch in session state
- agent_wait returns next unseen completed agent; returns immediately if none remain
- Preserve agent_id and return_all=true behaviors
2025-08-17 18:55:58 +10:00
James Peter 7748a83444 fix(codex-rs): clean dev-fast build warnings
- Remove unnecessary mut on Browser values; keep handler mutable
- Drop unused locals in chatwidget; underscore elapsed in history_cell
- Silence dead_code for ShowChromeOptions variant

Verified via ./build-fast.sh showing zero warnings.
2025-08-17 18:55:58 +10:00
James Peter a2f058369e chore(codex-rs): commit all pending changes 2025-08-17 18:55:58 +10:00
James PeterandClaude bd28c49ff1 Fix unused mut warning and add diff popup component
- Remove unnecessary mut from line mapping in history_cell.rs
- Add new diff_popup.rs component for displaying diffs in TUI
- Include markdown_renderer.rs for improved markdown rendering
- Clean up backup files and maintain theme consistency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-16 07:31:24 +10:00
James PeterandClaude acfae5bbd4 Enhance TUI with glitch animations and improved status handling
- Add glitch animation effects for assistant messages in chatwidget
- Implement GlitchText widget with multi-phase animation states
- Add status item deduplication for screenshots and system context
- Improve history cell rendering with proper exec command display
- Update browser page handling for screenshot optimization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-15 15:12:48 +10:00
James PeterandClaude 8b0e932f54 Remove all compilation warnings post-migration
Successfully eliminated 100% of compilation warnings following the trait-based HistoryCell migration:

Core fixes:
- Removed truly unused code that was orphaned after migration
- Marked test-only functions with #[cfg(test)] annotations
- Added #[allow(dead_code)] for intentionally unused future features
- Fixed unreachable pattern and unused variable warnings

Major discoveries during investigation:
- Live ring feature was partially implemented but never connected
- Text element system in textarea was added but never integrated
- history_cell_new.rs and text_block modules orphaned after migration
- ImageOutputCell.image field stored for future terminal image protocol

Files cleaned:
- app.rs: Removed unused event_sender() method
- chatwidget/interrupts.rs: Removed unused is_empty() method
- textarea.rs: Removed entire unused text element system
- colors.rs: Removed unused border_focused() function
- history_cell.rs: Cleaned up unused helper functions
- diff_render.rs: Marked internal constants/types appropriately
- lib.rs: Commented out orphaned module declarations
- text_processing.rs: Marked markdown functions with allow(dead_code)

Build now completes with 0 warnings in all profiles.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-15 14:14:57 +10:00
James PeterandClaude e2a432c08e Add browser screenshot deduplication and status items system
- Implement perceptual hashing (pHash + dHash) for screenshot comparison
- Add smart deduplication to avoid sending duplicate screenshots
- Create status items system for browser context and system state
- Include fresh screenshots with each API request when browser is active
- Clean up old status items to manage token usage efficiently
- Show "[Screenshot unchanged]" message when screenshot hasn't changed

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-15 11:21:44 +10:00
James PeterandClaude 5373fcf49e Add browser_console tool and conditional browser tool inclusion
- Add new browser_console tool to capture and return console output from the browser
- Implement get_console_logs() method in BrowserManager with JavaScript hooks to capture console.log, warn, error, info, and debug messages
- Add handle_browser_console() handler in codex.rs to format console logs with timestamps and levels
- Modify get_openai_tools() to conditionally include browser tools based on browser state
- When browser is disabled: only browser_open and browser_status tools are available
- When browser is enabled: all browser interaction tools are included
- Browser state is determined by checking if global browser manager exists

This allows the LLM to debug web pages by capturing console output and ensures browser interaction tools are only available when a browser session is active.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-15 08:12:37 +10:00
James Peter 8c165b14a4 Update browser page.rs with latest changes 2025-08-14 21:34:30 +10:00
James Peter 7f55e5c762 Fix sccache build error by removing CARGO_INCREMENTAL
sccache and incremental compilation are incompatible. Removing
CARGO_INCREMENTAL=1 since sccache provides better caching benefits
in CI environments.
2025-08-14 21:20:06 +10:00
James Peter adce5c9c0f Fix CI/CD issues and optimize build performance
- Disable rust-ci workflow temporarily due to clippy warnings from upstream merge
- Add comprehensive build caching to Release and rust-release workflows:
  - Cache cargo registry and build artifacts
  - Add sccache for compilation caching
  - Optimize with parallel jobs and incremental compilation
- Fix Rust formatting issues
- Fix some critical clippy warnings (redundant closures, format strings)
- Performance improvements should reduce CI build times significantly

The builds were taking 15-20 minutes but should now be much faster with:
- Cargo registry caching
- Target directory caching with content-aware keys
- sccache for compilation caching
- Parallel job optimization
- Incremental compilation enabled
2025-08-14 21:17:09 +10:00
James PeterandClaude a1ba1a1f9d Fix terminal query and improve image rendering initialization
- Query terminal capabilities at TUI startup using Picker::from_query_stdio()
- Store terminal info (picker and font size) and pass through initialization
- Fix unstable let-chains syntax in mcp-server
- Add missing std::env import in chatwidget.rs
- Add missing FilterType import for image resizing
- Update all ChatWidget creation calls to pass terminal_info
- Improve font size detection by querying once at startup instead of during render

This fixes the issue where from_query_stdio() couldn't work during rendering
because stdio was already in use by the TUI. Now we query capabilities once
at startup when it's safe to do so.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-14 20:59:35 +10:00
James Peter 88ca1f75ed Fix Windows PowerShell version replacement
- Fix PowerShell variable substitution in Windows builds
- Use proper escaping for PowerShell string replacement
- Ensures version is correctly set in Cargo.toml on Windows
2025-08-14 19:53:59 +10:00
James Peter 3ffd847a52 Fix version embedding in release builds
- Add determine-version job to calculate version before building
- Set version in Cargo.toml before building binaries
- Use pre-determined version for npm publishing
- This ensures binaries report correct version instead of 0.0.0
- Fixes upgrade check always appearing due to version mismatch
2025-08-14 19:50:53 +10:00
James Peter c50eb56b1c Fix formatting and build issues
- Applied cargo fmt to fix code formatting
- Fixed trailing whitespace issues
- Updated colors to use theme system
- Fixed merge-related syntax errors
- Recreated build-fast.sh for monorepo structure
2025-08-14 19:05:19 +10:00
James PeterandClaude fe8ed244aa Fix virtual cursor JavaScript - add missing defs and filter elements
The virtual cursor wasn't displaying because the SVG filter elements (defs and filt) were not being created, causing the JavaScript to fail silently. Added the missing element creation and proper filter attributes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-14 18:40:10 +10:00
James PeterandClaude ecdc9e7c05 Fix slash command argument parsing and add browser enhancements
Major changes:
- Fixed slash command handlers receiving full command text instead of just arguments
  - Added command_args extraction in app.rs to properly parse arguments
  - Now /browser and /chrome commands receive only their arguments, not the full command

Browser improvements:
- Added Chrome browser integration with external Chrome DevTools
- Implemented virtual cursor visualization with smooth animation
- Added screenshot deduplication using perceptual hashing (pHash + dHash)
- Enhanced browser manager with Chrome connection support
- Added chrome_selection_view for browser mode selection UI

Image comparison:
- Implemented efficient image comparison using perceptual hashing
- Screenshots are now deduplicated to reduce token usage
- System shows "[Screenshot unchanged]" when identical screenshots detected

Code cleanup:
- Fixed unused variable warnings in browser/src/page.rs
- Marked unused image comparison function with underscore prefix
- All builds now compile without warnings

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-14 18:30:08 +10:00
James PeterandClaude 409e37c916 feat: improve JavaScript execution harness in browser
- Replace basic harness with comprehensive error handling and normalization
- Add proper console capture for log, warn, error, and debug
- Implement smart value normalization for complex objects and DOM elements
- Add metadata tracking (URL changes, execution time)
- Include sourceURL for better debugging
- Capture window errors and unhandled promise rejections
- Use eval() within AsyncFunction for proper scope handling

This improved harness provides much better debugging capabilities and
handles edge cases like circular references, DOM elements, and BigInt values.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-13 21:08:18 +10:00
James PeterandClaude 39d826a2da feat: add debug logging system and improve TUI conversation history
- Add comprehensive debug logging system with file output
- Implement ScrollView component for better scrolling behavior
- Enhance conversation history with proper text wrapping
- Add browser debugging capabilities
- Improve ephemeral context handling
- Fix message duplication issues
- Add test scripts for debugging

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-13 21:08:18 +10:00
James PeterandClaude 104fef438b fix: improve height calculation for wrapped text in history cells
- Use Paragraph line_count for StyledText to properly calculate wrapped height
- Ensures proper vertical spacing for content that wraps across lines
- Fixes display layout issues with long text content

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-13 21:08:18 +10:00
James PeterandClaude 320a308e5f fix: add proper text wrapping to conversation history
- Added .wrap(Wrap { trim: false }) to BackgroundEvent, StyledText, and DimmedReasoning cells
- Now content flows naturally during streaming but wraps properly in history
- Text uses full terminal width and wraps at word boundaries
- Fixes issue where long lines would extend beyond terminal width

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-13 21:08:18 +10:00
James Peter 0a0303136f fix: remove artificial text wrapping at 80 chars during streaming
- Completely removed DEFAULT_WRAP_COLS constant
- RowBuilder now uses usize::MAX to disable wrapping during streaming
- Text flows naturally and is only wrapped when displayed based on terminal width
- Fixed issue where AI responses were being hard-wrapped at 80 characters
- Fixed styling of thinking content during streaming (uses StyledText)
- Prevented duplicate content in reasoning sections
2025-08-13 21:08:18 +10:00
James PeterandClaude 10cda43818 Merge branch 'feature-browser-upgrade' into main
Resolved conflicts by keeping the feature-browser-upgrade connection
setup code but removing the Browser Status panel UI as requested.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-12 23:04:48 +10:00
James PeterandClaude 9bafac6262 fix: remove unused capture_screenshot_background_strategy method
Removed dead code that was causing compilation warnings. The background
strategy was replaced by the regular strategy as noted in comments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-12 22:58:47 +10:00
James PeterandClaude a8dfa5ac2b feat: implement browser upgrade with improved screenshot functionality
- Remove prevent_focus_steal config option (no longer needed)
- Add background page for screenshots to prevent focus stealing
- Improve Chrome connection with parallel port testing
- Add navigation monitoring support
- Enhance chatwidget with screenshot slash command
- Add support for multiple screenshot paths
- Update README with feature descriptions
- Improve Chrome port detection script

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-12 22:57:53 +10:00
James PeterandClaude 2ade1d2d65 fix: resolve compilation errors in browser manager
- Fix missing semicolon in cdp_page initialization
- Move apply_page_overrides outside of else block to correct scope
- Fix Headers type usage for SetExtraHttpHeadersParams

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-12 22:42:11 +10:00
James PeterandClaude 635a54a9ca fix: resolve CI workflow compilation errors
- Remove duplicate shlex_join_safe function definition in history_cell.rs
- Fix padded_area reference by using area parameter in chatwidget.rs:1900
- Add missing Modifier import to chatwidget.rs
- Replace undefined LIGHT_BLUE with Color::LightBlue in history_cell.rs:426
- Fix trailing whitespace in openai_tools.rs:958
- Apply cargo fmt to all modified files

These changes fix the build errors that were causing the GitHub Actions release workflow to fail.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-12 16:32:58 +10:00
James PeterandClaude 2b92f0ea72 feat: Implement comprehensive focus prevention and unified browser management
- Add multi-layered focus prevention for external Chrome connections:
  * CDP-level: Disable page lifecycle events during screenshots
  * JavaScript-level: Override document.hasFocus() and dispatch blur events
  * macOS system-level: Detect and restore active app after browser operations
- Unify TUI and global browser managers to prevent dual instance issues
- Configure global manager when using /browser local to ensure LLM tools use external Chrome
- Add prevent_focus_steal config option (default: true) for external connections
- Prevent Chrome from stealing focus during screenshot operations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-08-12 14:49:43 +10:00
James Peter 427eaaf02f feat: Use active/focused tab when connecting to Chrome
- Check document.visibilityState and document.hasFocus() for each tab
- Prefer focused tab, then visible tab, then most recent tab
- No longer just uses the first tab which could be a pinned tab
- Provides better UX by controlling the tab user is actually looking at

This ensures the browser automation works with the tab the user has
active, not some random pinned tab that happened to be first.
2025-08-12 14:49:43 +10:00
James Peter a145182bad fix: Major browser connection fixes for external Chrome
1. Use existing tab instead of creating new one when connecting to Chrome
   - Check for existing pages and use the first/active one
   - Only create new tab if no tabs exist

2. Prevent cleanup/closing of externally connected Chrome instances
   - Do not close browser when disconnecting from external Chrome
   - Skip idle monitor for external connections
   - Only cleanup profiles we created, not external ones

3. Fix dual browser instance issue
   - Use global browser manager singleton in both TUI and core
   - Prevents creation of separate browser instances
   - Ensures /browser local and browser tools use same instance

This prevents Chrome from being killed when connected via CDP and ensures
the existing tab is used for navigation instead of creating new ones.
2025-08-12 14:49:43 +10:00