Skip to content

Harden chat protocol parsing and submit flow - #54

Merged
TraderSamwise merged 5 commits into
masterfrom
codex/chat-protocol-robustness
Jun 2, 2026
Merged

Harden chat protocol parsing and submit flow#54
TraderSamwise merged 5 commits into
masterfrom
codex/chat-protocol-robustness

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • harden Claude/Codex terminal transcript parsing for prompts, responses, status rows, and startup chrome
  • route tmux-backed GUI sends through the carriage-return prompt submit path
  • add composer protocol tests and attachment URL rendering coverage
  • keep context capture focused on parsed assistant responses instead of terminal chrome

Verification

  • YARN_IGNORE_ENGINES=1 yarn vitest src/context/context-bridge.test.ts src/agent-output-parser.test.ts src/multiplexer/session-runtime-core.test.ts --run
  • YARN_IGNORE_ENGINES=1 yarn typecheck
  • YARN_IGNORE_ENGINES=1 yarn lint
  • YARN_IGNORE_ENGINES=1 yarn build
  • YARN_IGNORE_ENGINES=1 git push pre-push hook: typecheck, lint, 648 tests
  • Chrome MCP live smoke: Codex CODEX_PROTOCOL_OK and Claude CLAUDE_PROTOCOL_OK_2 round trips

Summary by CodeRabbit

  • Bug Fixes

    • Fixed image URL normalization to properly handle relative paths and absent URLs
    • Improved message sending eligibility logic for consistent send enablement
  • Improvements

    • Refined agent response parsing to better classify and extract content, status, and prompt sections
    • Enhanced multi-line message submission handling for terminal-backed sessions
    • Improved message composition input validation and send-text computation
  • Tests

    • Added and extended tests to cover composer behavior, parsing, and session input flows

@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Jun 2, 2026 8:07am

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bd8008fe-f3bf-4395-b7f7-a643604bba80

📥 Commits

Reviewing files that changed from the base of the PR and between 78734c3 and bc9250d.

📒 Files selected for processing (2)
  • src/agent-output-parser.test.ts
  • src/agent-output-parser.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/agent-output-parser.ts

📝 Walkthrough

Walkthrough

Adds a composer protocol and integrates it into AgentChatScreen and tmux send flow; enhances parseAgentOutput to better classify Codex/Claude UI and preserve trailing prompts; context bridge now uses parser for live snapshots; normalizes image attachment URLs and adds tests.

Changes

Message Composition & Sending

Layer / File(s) Summary
Composer protocol contracts and helpers
app/lib/composer-protocol.ts, app/lib/composer-protocol.test.ts
Exports composer types and helpers: normalizeComposerDraft, shouldSubmitComposerKey, and getComposerSendText. Tests validate draft trimming, Enter-key rules, and conditional send-text logic.
Chat screen message eligibility and submission
app/components/screens/AgentChatScreen.tsx
AgentChatScreen imports composer helpers, computes composerSendText for gating and submission, delegates web key handling to shouldSubmitComposerKey, and ties Send button disabled state to composerSendText.
Tmux prompt submission normalization
src/multiplexer/session-runtime-core.ts, src/multiplexer/session-runtime-core.test.ts
sendAgentInput now normalizes the prompt, writes the normalized draft to the tmux transport, and awaits waitForTmuxPromptSubmit. Test covers carriage-return prompt submission with fake timers.

Agent Output Parsing & Context Extraction

Layer / File(s) Summary
Enhanced agent output parsing logic
src/agent-output-parser.ts, src/agent-output-parser.test.ts
Adds Codex UI detection and expands isStatusLine heuristics (MCP startup, progress bullets), treats Codex UI as meta before prompts or status after, tightens prompt/empty-line handling, and removes trailing prompt stripping. Tests cover Codex/Claude status parsing, wrapped prompts, and trailing prompt preservation.
Context bridge live snapshot extraction
src/context/context-bridge.ts, src/context/context-bridge.test.ts
ContextBridge now parses pane text with parseAgentOutput and selects the last response block for snapshotTurn. Tests updated to ensure chrome/progress rows are excluded and only last real response is recorded.

Message Display Improvements

Layer / File(s) Summary
Image URL path normalization and null handling
app/components/MessageBlock.tsx, app/components/MessageBlock.test.ts
resolveImageUrl prepends a leading / for non-absolute contentUrl values before joining with getServiceUrl(endpoint) and returns null when contentUrl is missing. Tests assert normalized local URLs and null behavior.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant AgentChatScreen
  participant ComposerProtocol
  participant SessionRuntime
  participant TmuxTransport
  User->>AgentChatScreen: type text / press Enter
  AgentChatScreen->>ComposerProtocol: normalizeComposerDraft(draft)
  ComposerProtocol-->>AgentChatScreen: normalizedDraft or null
  AgentChatScreen->>ComposerProtocol: getComposerSendText(state)
  ComposerProtocol-->>AgentChatScreen: composerSendText or null
  AgentChatScreen->>ComposerProtocol: shouldSubmitComposerKey(event)
  ComposerProtocol-->>AgentChatScreen: true/false
  AgentChatScreen->>SessionRuntime: handleSendMessage(composerSendText)
  SessionRuntime->>TmuxTransport: sendAgentInput(normalized prompt)
  TmuxTransport-->>SessionRuntime: waitForTmuxPromptSubmit result
  SessionRuntime-->>AgentChatScreen: acceptance result
Loading
sequenceDiagram
  participant TmuxPane
  participant ContextBridge
  participant OutputParser
  participant ContextWatcher
  TmuxPane->>ContextBridge: capturePaneSnapshot(normalized text)
  ContextBridge->>OutputParser: parseAgentOutput(pane text)
  OutputParser-->>ContextBridge: parsed blocks (meta/prompt/status/response)
  ContextBridge->>OutputParser: select last response block
  OutputParser-->>ContextBridge: final response text
  ContextBridge->>ContextWatcher: snapshotTurn = response text
  ContextWatcher-->>ContextBridge: snapshot recorded
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I trimmed the draft and watched the keys,

Sent prompts that waited for tmux replies,
Parsers learned to skip the chrome and spinners,
Images found their proper path again,
A rabbit cheers—careful, neat, and spry.

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main changes: hardening chat protocol parsing and the message submit flow, which are the core objectives reflected throughout the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/chat-protocol-robustness

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/agent-output-parser.ts`:
- Around line 82-86: The current bullet-line regexes treat any bullet containing
"for <n>s", an ellipsis, or a trailing parenthetical as a status, which swallows
normal assistant replies; narrow these patterns in agent-output-parser by
changing the checks that use trimmed (the /^•\s?\S.*\bfor \d+s\b/ and
/^[*✻✽✶]\s+\S.*(?:\bfor \d+s\b|\.\.\.|…|\(.+\))$/ tests) to only match
well-known short status phrases — e.g., require the bullet to start with a
capitalized status keyword
(Starting|Started|Stopped|Running|Restarting|Added|Removed|Updated) or to be a
very short token (limit to 1–3 words) when paired with a
timing/ellipsis/parenthetical, and restrict parenthetical matches to explicit
timing formats like \(\d+(?:ms|s)\); update those regexes accordingly so
ordinary sentences like "I'll wait for 5s..." or "Added tests (2 files)" no
longer qualify as status lines.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 99f57741-8317-4842-8224-2b062bf3c106

📥 Commits

Reviewing files that changed from the base of the PR and between ae9a215 and 78734c3.

📒 Files selected for processing (11)
  • app/components/MessageBlock.test.ts
  • app/components/MessageBlock.tsx
  • app/components/screens/AgentChatScreen.tsx
  • app/lib/composer-protocol.test.ts
  • app/lib/composer-protocol.ts
  • src/agent-output-parser.test.ts
  • src/agent-output-parser.ts
  • src/context/context-bridge.test.ts
  • src/context/context-bridge.ts
  • src/multiplexer/session-runtime-core.test.ts
  • src/multiplexer/session-runtime-core.ts

Comment thread src/agent-output-parser.ts Outdated
@TraderSamwise
TraderSamwise merged commit af2e76b into master Jun 2, 2026
3 checks passed
@TraderSamwise
TraderSamwise deleted the codex/chat-protocol-robustness branch June 2, 2026 08:15
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