Repository navigation
Reliably deliver the issue prompt into opencode's composer - #6798
Conversation
"Start workspace from issue" seeds the issue URL as an editable, unsubmitted draft and pastes it into the agent's composer once the TUI is ready. For opencode (and other flag-prompt agents with no prefill flag, e.g. mimo-code), readiness used a quiet-output window after bracketed-paste was enabled. opencode enables bracketed paste ~2s before its composer actually mounts, so the quiet window elapses early and the paste lands in a not-yet-mounted input — and a slow setup script churning output makes it time out entirely. The URL frequently never arrived. Gate the paste on opencode's DECTCEM show-cursor (\x1b[?25h) emitted after bracketed-paste-enable (\x1b[?2004h) — the point where the composer is mounted and focused — keeping the quiet-window as a fallback so behavior is never worse than before. The draft stays editable and unsubmitted (no auto-submit). The readiness scanner was duplicated in the renderer (local delivery) and the main process (runtime/SSH/remote + mobile delivery). Extract one shared, pure scanner so both paths get the fix and can't drift, and unit-test it directly. - Add 'render-cursor-after-bracketed-paste' signal; wire opencode + mimo-code. - Extract createDraftPasteReadyScanner (src/shared) consumed by both waiters. - Regression tests at the shared delivery-decision seam plus config invariants.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughA new shared module, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/draft-paste-ready-scanner.test.ts (1)
41-47: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a split-
2004hhandshake regression case.This suite exercises a split show-cursor, but not a split
\x1b[?2004h. The scanner has dedicated pre-handshake buffering for that exact boundary, so a regression there would disable both quiet-window arming and cursor-gated readiness for fragmented PTY packets. A small case like'\x1b[?20'then'04h'(and optionallySHOW_CURSOR) would lock down the other half of the new state machine.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: acf25e79-75b9-4722-b950-acdcf6e12ed4
📒 Files selected for processing (7)
src/main/runtime/orca-runtime.tssrc/renderer/src/lib/agent-draft-readiness.tssrc/renderer/src/lib/agent-paste-draft.test.tssrc/shared/draft-paste-ready-scanner.test.tssrc/shared/draft-paste-ready-scanner.tssrc/shared/tui-agent-config.tssrc/shared/tui-agent-startup.test.ts
Add a regression case where \x1b[?2004h straddles two PTY packets, exercising the pre-handshake `recent` ring (the other half of the scanner state machine).
…gnal A/B testing the real opencode CLI (v1.17.11) end to end revealed the cursor signal was being defeated by its own fallback. opencode enables bracketed paste (\x1b[?2004h) ~1.5-2s before its composer mounts and stays silent in between, then emits show-cursor (\x1b[?25h) at mount. The quiet-window fallback armed during that silent gap fired ~200-400ms BEFORE the composer existed, pre-empting the cursor signal — so the paste still landed too early and the URL was lost. Make the cursor signal marker-only, exactly like Codex: it never arms the quiet window. opencode re-emits show-cursor on every render frame once mounted, so the marker is effectively guaranteed; the caller's hard timeout (plus its best-effort process-ownership paste) is the backstop if it is ever missed. Only the default signal, which has no marker, still uses the quiet window. Verified against the real opencode CLI: the URL now lands in the editable, unsubmitted composer on clean and noisy startups; the old logic dropped it.
|
thanks for reporting. looking into it |
What changes
"Start workspace from issue" seeds the issue URL as an editable, unsubmitted draft and pastes it into the launched agent's composer once the TUI is ready. For opencode (and other flag-prompt agents with no prefill flag, e.g.
mimo-code) that draft frequently never arrived. This PR makes it land reliably, while keeping it editable and unsubmitted.What does NOT change
The draft is still editable and unsubmitted — opencode is not launched with
--prompt(that would auto-submit the URL immediately). The user still reviews the seeded prompt and presses Enter, exactly as with Claude/codex. No agent's submit behavior changes.Root cause
Readiness for paste-after-ready used a quiet-output window after bracketed paste was enabled (DECSET 2004,
\x1b[?2004h). Measured against real opencode v1.17.11: opencode enables bracketed paste at ~1.4s but its composer doesn't mount until ~3.4s. The 1500ms quiet window therefore resolves at ~2.9s — ~450ms before the composer exists — so the paste lands in a not-yet-mounted input. A slow setup script churning output keeps resetting the quiet timer until the readiness wait hits its 8s hard timeout and the URL is dropped entirely. This matches the report: with a 20–30s setup script the prompt "often doesn't arrive."Fix
Gate opencode's paste on the DECTCEM show-cursor (
\x1b[?25h) emitted after bracketed-paste-enable — the point where opencode's composer row is mounted and focused (analogous to Codex's›composer-prompt signal). Crucially, this signal must not also arm the quiet window: opencode goes silent during the ~1.5–2s between enabling bracketed paste and mounting its composer, so a quiet window armed on that gap fires ~200–400ms before the composer exists and pre-empts the cursor signal (this was caught by A/B testing the real opencode CLI end to end, and an earlier revision of this PR had exactly that bug). The cursor signal therefore waits only for its marker, bounded by the existing hard timeout plus the caller's best-effort process-ownership paste — the same model Codex uses. opencode re-emits show-cursor on every render frame once mounted, so the marker is effectively guaranteed.The readiness scanner was duplicated: one copy in the renderer (
waitForAgentDraftInputReady, desktop-local delivery) and one in the main process (waitForStartupDraftReadyinorca-runtime.ts, the delivery path for runtime/SSH/remote-owned worktrees and mobile "Start workspace from issue"). A renderer-only fix would have been inert on the SSH/remote path. This PR extracts a single pure scanner —createDraftPasteReadyScannerinsrc/shared/— that both waiters consume, so the fix applies to every delivery surface and the two copies can't drift again.Design approach
Investigated the delivery path end to end, wrote a design doc (scratch, not shipped), and ran it through design review before implementing. The auto-submit-vs-editable-draft decision was surfaced and resolved as keep editable draft + harden readiness before any code was written. Empirically grounded the choice with a node-pty probe (
opencode --promptauto-submits) and confirmed the new signal with a headless terminal-grid render (URL lands in the editable composer, placeholder replaced, not submitted).Design-review outcome
Design review converged clean after hardening two points: the fallback must not be starved (the new signal falls through to arm the quiet timer on a miss, unlike Codex's early-return), and the existing default-path test must keep coverage (re-targeted to a still-default agent rather than deleted).
Implementation & deviations
Implemented exactly as designed. One addition beyond the original doc, surfaced by code review: extracting the shared scanner (instead of editing the renderer only) so the runtime/SSH/remote/mobile path is also fixed. No other deviations.
Completeness verification
Verified the full path: issue URL →
draftPrompt(emptyprompt, so no--prompt) →pasteDraftToAgentPtyWhenReady(forcePaste: true, nosubmit) → shared scanner gating on\x1b[?25h. Submit stays false end to end. opencode + mimo-code both route through the paste path (no native prefill flag/env). Other agents (Claude, codex, gemini, pi, …) are byte-for-byte unchanged.Headline behavior status
Implemented. Production code delivers the editable, unsubmitted issue draft into opencode's composer reliably, on both the already-ready and racing-fresh-startup cases.
Broad app consistency
Source-of-truth behavior is "deliver a seeded prompt into the agent composer as an editable, unsubmitted draft," shared by all draft-seeding surfaces (quick "Start workspace from issue", new-workspace composer, direct work-item launch) which all funnel through the readiness waiter. Fixing the shared scanner fixes opencode across all of them at once. No surface special-cases opencode, so there was no divergence to reconcile. Codex (its own signal) and the quiet-window default agents (gemini/cursor/copilot/stdin agents) are intentionally untouched.
Risks, ambiguities, non-goals
--prompt. The draft stays editable.\x1b[?25hand leaves a long silent pre-composer gap, the quiet window can still fire early — exactly as today. The change strictly improves the common case and never regresses it.\x1b[?25hmatching cannot collide with\x1b[?25l(hide) or compound sequences like\x1b[?25;1049h(terminator differs), and is only honored after\x1b[?2004h, so pre-composer cursor toggles don't trip it.Perf
Audited the touched hot path (the per-PTY-chunk
observe). The 512-byte ring bounds are preserved, no O(n²) growth, no new timer churn, subscription/timer teardown unchanged, and zero added cost for agents not using the new signal. No measurement needed; verdict: no perf concerns.Code-review loop
Two rounds, two independent reviewers each. Round 1 both reviewers independently flagged one P0 — the un-updated main-process scanner copy (SSH/remote path); fixed by the shared-scanner extraction. Round 2 both reviewers returned clean (byte-for-byte behavior preservation verified across all three signals); two minor advisory nits (docstring wording for mimo-code, an extra replay-path test) were addressed.
Validation (merge confidence)
@xterm/headless. Result — old quiet-window logic: URL dropped (resolves before composer mounts); new cursor-gated logic: URL lands in the editable, unsubmitted composer, on both clean and noisy (render-churn) startups, repeatably. This test is what surfaced and then confirmed the fix to the quiet-window pre-emption bug above.pasteDraftToAgentPtyWhenReadywithagent: 'opencode'. The issue URL landed in opencode's composer, unsubmitted (agent stayed "Idle"), both against an already-ready opencode and when racing a freshly-relaunched opencode. Screenshot evidence captured.orca-runtimetests pass.Validation gap (stated honestly): the live UI run exercised the renderer/local desktop path. The runtime/SSH/remote and mobile paths use the same shared scanner but were validated via unit tests + byte-for-byte behavior-preservation review, not a live remote run (no SSH remote available in the dev env).
Static checks
Node + web typecheck clean (no new errors; one unrelated pre-existing TS error in
useSessionRestoredBannerDismiss.test.tsxexists on the base branch). oxlint and switch-exhaustiveness clean.