Skip to content

fix(pty): ensure runtime args precede positional prompt in CLI arg order#1399

Merged
arnestrickmann merged 1 commit intomainfrom
emdash/feat-auto-task-high-codex-3r1
Mar 10, 2026
Merged

fix(pty): ensure runtime args precede positional prompt in CLI arg order#1399
arnestrickmann merged 1 commit intomainfrom
emdash/feat-auto-task-high-codex-3r1

Conversation

@arnestrickmann
Copy link
Contributor

Summary

  • Fix CLI argument ordering in buildProviderCliArgs so that extraArgs and runtimeArgs (e.g. Codex -c notify=...) are placed before the positional initial prompt, preventing agents like Codex from misinterpreting flags as part of the prompt text
  • Enhance stripAnsi to handle additional ANSI escape sequences: ST-terminated OSC (\x1b\\), DCS sequences, and lone ESC codes (SS2/SS3) — fixes issues where terminal color query responses from agent TUIs leaked into captured input
  • Add tests covering the new arg ordering and ANSI stripping behavior
  • Minor whitespace cleanup in MCP docs table

Test plan

  • New test: positional prompt placed after --full-auto and runtime args for Codex
  • New test: extraArgs and runtimeArgs included before prompt in arg output
  • New test: OSC color query responses (ST-terminated) stripped from terminal input buffer
  • New test: empty input after stripping OSC data does not trigger capture
  • Existing tests continue to pass

Fixes GEN-508

@vercel
Copy link

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Mar 10, 2026 10:11pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 10, 2026

Greptile Summary

This PR fixes two distinct bugs affecting Codex (and similar agents) when launched via the PTY manager:

  1. CLI arg orderingextraArgs and runtimeArgs (e.g. -c notify=...) were previously appended after the positional initial prompt, causing agents like Codex to misinterpret flags as part of the prompt text. Both are now passed to buildProviderCliArgs and emitted before the prompt, and both startDirectPty and startPty are updated consistently.
  2. ANSI strippingstripAnsi is extended to handle ST-terminated OSC sequences, DCS sequences, and lone ESC codes that Codex's TUI emits as color query responses. Without this, those sequences leaked into TerminalInputBuffer and could either corrupt the captured task name or fire spurious captures.

Key changes:

  • ProviderCliArgsOptions gains a runtimeArgs field; buildProviderCliArgs pushes extraArgs then runtimeArgs before the positional prompt block.
  • getProviderRuntimeCliArgs result is now threaded as runtimeArgs into buildProviderCliArgs rather than appended after it in both startDirectPty and startPty.
  • stripAnsi adds three new regex passes: OSC+ST, DCS+ST, and a final lone-ESC catch-all — applied after the existing CSI and OSC+BEL passes.
  • New tests cover arg ordering for both the generic and Codex-specific cases, plus OSC color-response stripping and the empty-after-strip guard.

Confidence Score: 5/5

  • This PR is safe to merge — the fixes are narrowly scoped, both call sites are updated, and the new tests accurately validate the changed behaviour.
  • The arg-ordering fix is a straightforward refactor with no new external dependencies. The stripAnsi additions are purely additive regex passes with no side-effects on existing patterns. Both call sites (startDirectPty and startPty) are updated symmetrically, and the four new tests directly exercise the new code paths. No regressions are expected in unrelated areas.
  • No files require special attention.

Important Files Changed

Filename Overview
src/main/services/ptyManager.ts Adds runtimeArgs to ProviderCliArgsOptions, moves both extraArgs and runtimeArgs before the positional initialPrompt in buildProviderCliArgs, and updates both startDirectPty and startPty to pass getProviderRuntimeCliArgs as runtimeArgs rather than appending after the fact. The fix is correct and both call sites are updated consistently.
src/renderer/terminal/stripAnsi.ts Extends ANSI stripping with ST-terminated OSC, DCS, and lone-ESC patterns. The regexes are correct for the targeted sequences. One minor edge case: the final lone-ESC regex /\x1b[^[\]P]/g only handles 2-character ESC sequences; multi-character private sequences like \x1b(B (charset selection) would leave a stray trailing character, though this is an inherent limitation of the regex approach and pre-existing non-standard CSI variants (e.g. \x1b[?25h) are likewise not caught by the CSI regex. Neither scenario is introduced by this PR.
src/test/main/ptyManager.test.ts Adds two well-targeted tests: one confirming the full arg ordering (resume → defaultArgs → autoApproveFlag → extraArgs → runtimeArgs → prompt) and one confirming the Codex-specific --full-auto + -c notify=... case. Both tests accurately reflect the new implementation.
src/test/renderer/terminalInputBuffer.test.ts Adds two tests exercising the new ST-terminated OSC stripping: one ensures real user input survives after OSC color responses, the other confirms an OSC-only input does not trigger capture. Both are correct and cover the specific bug scenario.
docs/content/docs/mcp.mdx Whitespace-only cleanup of the Markdown table column widths. No functional change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[startDirectPty / startPty] --> B[buildProviderCliArgs]
    B --> C[resume + resumeFlag]
    C --> D[defaultArgs]
    D --> E[autoApproveFlag]
    E --> F[extraArgs]
    F --> G[runtimeArgs\ne.g. -c notify=...]
    G --> H{initialPromptFlag\ndefined AND\nnot keystroke injection?}
    H -- Yes --> I[push initialPromptFlag\nif non-empty]
    I --> J[push initialPrompt\npositional arg]
    H -- No --> K[skip prompt args]
    J --> L[return cliArgs]
    K --> L

    style G fill:#d4edda,stroke:#28a745
    style F fill:#d4edda,stroke:#28a745
    style J fill:#cce5ff,stroke:#004085
Loading

Last reviewed commit: 18bcc09

@arnestrickmann arnestrickmann merged commit 470c628 into main Mar 10, 2026
5 checks passed
@arnestrickmann arnestrickmann deleted the emdash/feat-auto-task-high-codex-3r1 branch March 12, 2026 04:46
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.

1 participant