Repository navigation
fix(native-chat): make the launch-draft mirror reachable - #11222
Conversation
Seed the chat-composer copy of unsent launch context on every originating draft path, then let those launches open in chat by default. Three paths delivered a draft to the TUI without mirroring it into chat: folder-workspace create, the local argv-prefill branch of launchAgentInNewTab, and the web-host equivalent. The first was invisible; the other two were hidden only because draft launches were forced into terminal view. The view-mode decision now gates on the same predicate as seeding (canMirrorLaunchDraftToNativeChat), so a draft can never open in chat with a composer chat would refuse to fill.
|
Warning Review limit reached
Next review available in: 7 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
📝 WalkthroughWalkthroughThe change centralizes launch prompt planning, adds shared single-line draft mirrorability checks, and uses them for native-chat view selection and composer seeding. Folder-workspace creation now resolves and mirrors linked drafts. Web-runtime launches use a draft-aware terminal creation helper. Paste timeout notifications are encapsulated in a reusable factory, and tests cover startup plans, native-chat behavior, folder workspaces, worktree activation, and web-runtime launches. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 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.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 24c371da-625f-42ae-90bd-28df875702a3
📒 Files selected for processing (16)
src/renderer/src/components/sidebar/folder-workspace-composer-submit.test.tssrc/renderer/src/components/sidebar/folder-workspace-composer-submit.tssrc/renderer/src/lib/agent-launch-prompt-delivery.tssrc/renderer/src/lib/launch-agent-in-new-tab.test.tssrc/renderer/src/lib/launch-agent-in-new-tab.tssrc/renderer/src/lib/launch-agent-paste-timeout-notice.tssrc/renderer/src/lib/launch-agent-startup-prompt-plan.tssrc/renderer/src/lib/launch-agent-web-host-tab.tssrc/renderer/src/lib/native-chat-initial-view-mode.test.tssrc/renderer/src/lib/native-chat-initial-view-mode.tssrc/renderer/src/lib/native-chat-launch-draft-mirrorability.test.tssrc/renderer/src/lib/native-chat-launch-draft-mirrorability.tssrc/renderer/src/lib/worktree-activation.test.tssrc/renderer/src/lib/worktree-activation.tssrc/renderer/src/runtime/web-runtime-session.test.tssrc/renderer/src/runtime/web-runtime-session.ts
| }) | ||
|
|
||
| it('seeds the chat composer for a draft that rode in on the launch command', async () => { | ||
| const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Remove the duplicate runtimeCall declaration.
Line 1258 declares runtimeCall twice, producing invalid test structure and preventing TypeScript from compiling.
Proposed fix
- const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => {
const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => { | |
| const runtimeCall = vi.fn(async (request: { method: string; params?: unknown }) => { |
Greptile SummaryThis PR makes draft launches actually open in native chat by fixing two interconnected gaps: (1) three code paths that never seeded the chat composer for argv-prefill draft launches, and (2) a view-mode gate that used
Confidence Score: 5/5Safe to merge. The invariant that seeding and view-mode decisions are always driven by the same predicate is enforced structurally, and every new code path is covered by mutation-verified tests. The change is careful and well-bounded: a shared predicate (canMirrorLaunchDraftToNativeChat) ensures the chat-opening set and the composer-seeding set can never drift apart. The new launchDraftText field is deliberately distinct from draftPrompt to prevent double-delivery to the TUI. All six originating launch paths are accounted for, the consistency suite catches any inline reimplementation, and the mutation results documented in the PR description confirm each test actually fails when its corresponding production line is reverted. The multi-line-draft guard that protects against TUI Ctrl+U concatenation remains intact by construction. Files Needing Attention: No files require special attention. worktree-draft-startup-view-mode.ts and worktree-creation-agent-seeds.ts are the most novel paths, but both are covered by the new worktree-creation-flow and worktree-creation-agent-seeds test suites.
|
| Filename | Overview |
|---|---|
| src/renderer/src/lib/native-chat-launch-draft-mirrorability.ts | New single-source-of-truth predicate; correctly covers \r, \n, U+2028, U+2029 line separators and rejects empty/whitespace-only text. |
| src/renderer/src/lib/worktree-activation.ts | Adds launchDraftText field, resolveStartupLaunchDraftText helper, and shared draftViewModeProps so both tab-creation sites use identical logic. |
| src/renderer/src/lib/worktree-draft-startup-view-mode.ts | New helper resolves backend startup viewMode; correctly handles local/remote grok readability, but connectionId lookup returns undefined (not null) when repo is missing, creating a minor type inconsistency that is safe in practice. |
| src/renderer/src/lib/worktree-creation-agent-seeds.ts | Adds applyBackendSpawnedDraftViewMode to correct view mode after backend worktree create; handles both local tab and web-runtime tab (via dynamic import) cases correctly. |
| src/renderer/src/lib/launch-agent-in-new-tab.ts | Refactored to extract startup-plan logic; adds argv-prefill seeding branch (pasteDraftAfterLaunch === null) and passes launchDraftText to view-mode props. |
| src/renderer/src/runtime/web-runtime-session.ts | New createWebRuntimeAgentSessionTerminalWithLaunchDraft function correctly seeds the composer once the mirrored host tab id is known from the creation result. |
| src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts | Extracts resolveFolderWorkspaceLaunchDraft for reuse, adds launchDraftText to startup payload, and seeds the composer after activation for both argv-prefill and paste paths. |
| src/renderer/src/lib/worktree-creation-flow.ts | Adds launchDraftText to buildStartupOpt and calls resolveBackendDraftStartup to inject viewMode into the backend startup payload before createWorktree. |
| src/shared/types.ts | Adds viewMode to WorktreeStartupLaunch; minimal and correct change to the shared type. |
| src/main/runtime/orca-runtime.ts | Three call sites propagate viewMode from sequencedStartup/effectiveStartup to createTerminal; correct conditional spread pattern matches existing launchConfig/launchAgent handling. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Draft Launch Triggered] --> B{Delivery Method}
B -->|argv prefill\nClaude --prefill| C[launchCommand carries draft\ndraftPrompt = undefined\nlaunchDraftText = draft text]
B -->|bracketed paste\nCodex| D[draftPrompt = draft text\nlaunchDraftText = draft text]
C --> E{canMirrorLaunchDraftToNativeChat}
D --> E
E -->|Single-line, non-empty| F[View mode = chat\nSeed chat composer]
E -->|Multi-line or empty| G[View mode = terminal\nDo NOT seed composer]
F --> H{Launch Path}
G --> H
H -->|launchAgentInNewTab local| I[Create tab with viewMode\nargv: seedNativeChatLaunchDraftForAgentTab\npaste: deliverLaunchPromptToAgentTab seeds]
H -->|launchAgentInNewTab web-host| J[createWebRuntimeAgentSessionTerminalWithLaunchDraft\nSeeds composer after host tab id known]
H -->|folder-workspace| K[activateAndRevealFolderWorkspace\nresolveFolderWorkspaceLaunchDraft\nseedNativeChatLaunchDraftForAgentTab]
H -->|worktree creation flow background| L[resolveBackendDraftStartup\nSets viewMode on startup payload\napplyBackendSpawnedDraftViewMode corrects after create]
H -->|launchWorkItemDirect| M[buildDirectWorkItemStartupOpts\nlaunchDraftText passed through\nworktree-activation reads it]
Reviews (3): Last reviewed commit: "fix(native-chat): reconcile backend draf..." | Re-trigger Greptile
The draft view-mode gate read `startup.draftPrompt`, which only the post-ready-paste delivery sets. An argv-prefill launch carries its draft inside `launchCommand`, so the gate never saw one and the tab opened in chat unconditionally — a multi-line draft was correctly not seeded yet still opened chat, leaving an empty composer beside a filled TUI input. Adds `launchDraftText` to the activation startup payload as a view-mode-only field, deliberately distinct from `draftPrompt` so it cannot double-deliver the draft through pty-connection's bracketed paste, and sets it at all four originating producers.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/lib/worktree-activation.ts (1)
86-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep one concise launch-draft contract. The same implementation rationale is repeated across API docs, call sites, and tests.
src/renderer/src/lib/worktree-activation.ts#L86-L93: reduce this to one concise contract sentence.src/renderer/src/lib/worktree-activation.ts#L101-L106: remove this duplicate helper walkthrough.src/renderer/src/lib/worktree-activation.ts#L583-L584: remove this call-site duplication.src/renderer/src/lib/worktree-activation.test.ts#L536-L538: remove the test-side duplication.
As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fb5aed80-ea88-42c4-a970-56cb812c5d15
📒 Files selected for processing (10)
src/renderer/src/components/sidebar/folder-workspace-composer-submit.test.tssrc/renderer/src/components/sidebar/folder-workspace-composer-submit.tssrc/renderer/src/lib/launch-work-item-direct-agent.test.tssrc/renderer/src/lib/launch-work-item-direct-agent.tssrc/renderer/src/lib/launch-work-item-direct.test.tssrc/renderer/src/lib/launch-work-item-direct.tssrc/renderer/src/lib/worktree-activation.test.tssrc/renderer/src/lib/worktree-activation.tssrc/renderer/src/lib/worktree-creation-flow.test.tssrc/renderer/src/lib/worktree-creation-flow.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts
) * fix(native-chat): make the launch-draft mirror reachable Seed the chat-composer copy of unsent launch context on every originating draft path, then let those launches open in chat by default. Three paths delivered a draft to the TUI without mirroring it into chat: folder-workspace create, the local argv-prefill branch of launchAgentInNewTab, and the web-host equivalent. The first was invisible; the other two were hidden only because draft launches were forced into terminal view. The view-mode decision now gates on the same predicate as seeding (canMirrorLaunchDraftToNativeChat), so a draft can never open in chat with a composer chat would refuse to fill. * fix(native-chat): gate draft view mode on argv-prefill launches too The draft view-mode gate read `startup.draftPrompt`, which only the post-ready-paste delivery sets. An argv-prefill launch carries its draft inside `launchCommand`, so the gate never saw one and the tab opened in chat unconditionally — a multi-line draft was correctly not seeded yet still opened chat, leaving an empty composer beside a filled TUI input. Adds `launchDraftText` to the activation startup payload as a view-mode-only field, deliberately distinct from `draftPrompt` so it cannot double-deliver the draft through pty-connection's bracketed paste, and sets it at all four originating producers. * fix(native-chat): reconcile backend draft launch tabs
Follow-up to #9802. That PR added the native-chat mirror of unsent launch context; this one makes it actually reachable.
Behavior change — draft launches now open in chat
With "open agent tabs in chat by default" on, a draft launch used to be forced into terminal view. It now opens in chat when the draft can be mirrored (see the predicate below). This changes the default view for every mirrorable draft launch.
The gaps
Six originating paths deliver a draft to the agent's TUI. Two problems, both concentrated on the argv-prefill branch (Claude
--prefilletc.), where the draft rides insidelaunchCommandand the plan sets nodraftPrompt:1. Three paths never seeded the chat composer at all. Paste-based branches were already fine — they route through
deliverLaunchPromptToAgentTab, which seeds. Only argv prefill fell through, because no paste runs.folder-workspace-composer-submit.tslaunch-agent-in-new-tab.ts(local)launch-agent-web-host-tab.ts(web runtime)2. The view-mode gate itself missed argv prefill on four paths.
worktree-activation.tsderived the gate fromstartup.draftPrompt != null, which only paste delivery sets. So argv-prefill launches were never classified as drafts and opened in chat unconditionally — including multi-line drafts that are correctly not seeded, producing exactly the empty-composer-beside-filled-TUI failure the predicate exists to prevent. Affected:folder-workspace-composer-submit.ts,launch-work-item-direct.ts, and bothworktree-creation-flow.tsproducers (useComposerState.submitQuick,github-work-item-background-request.ts).Fix: a
launchDraftTextfield on the activation startup payload, carrying the resolved draft text for the view-mode decision only. It is deliberately distinct fromdraftPrompt, which drives the bracketed paste inpty-connection— reusing it would deliver the draft a second time on top of the argv prefill.resolveStartupLaunchDraftTextreads either field, and both tab-creation sites share onedraftViewModePropshelper so they cannot drift.Seeded set == chat-opening set, by construction
Lifting the guard outright would have regressed the majority case.
seedNativeChatLaunchDraftForAgentTabrejects multi-line text, and multi-line is the common shape:formatDraftContextBlockappends a trailing newline to every Linear blockbuildLinearLaunchContextBlockjoins identifier and URL with a newlineA bare issue URL with no note is essentially the only single-line draft. So instead of deleting the guard, both sides gate on one shared predicate,
canMirrorLaunchDraftToNativeChatinnative-chat-launch-draft-mirrorability.ts.Draft paths that still do not mirror — by design
Multi-line drafts still open in terminal view, and today that is the majority of draft launches. That is deliberate: the chat send pre-clears the TUI with Ctrl+U, which is kill-to-start-of-line, so a multi-line mirror could concatenate onto the message being sent. The send-protocol work on
brennanb2025/native-chat-multiline-sendis what flips them.Note for that worktree — measured, not estimated
The production change stays a one-line edit to the predicate body. The test fallout is larger than I first claimed. Measured by mutating the predicate to accept multi-line and diffing the full
src/rendererfailure set against baseline: 13 tests across 7 files go red.worktree-activation.test.ts(3),folder-workspace-composer-submit.test.ts(3),native-chat-initial-view-mode.test.ts(2),native-chat-launch-draft-mirrorability.test.ts(1),launch-agent-in-new-tab.test.ts(1)agent-launch-prompt-delivery.test.ts,launch-work-item-direct.test.tsOf these, only
native-chat-launch-draft-mirrorability.test.tspins the rule directly; the rest assert multi-line stays in the terminal and flip as a consequence. The consistency suite's 16 agreement assertions stay green throughout — they follow the predicate rather than restating it.Tests
Every added test was mutation-checked — production line reverted, test confirmed RED, restored.
Gate and all four producers, each mutated independently:
draftPrompt-only (the shipped bug)launchDraftTextworktree-creation-flowproducer droppedlaunch-work-item-direct-agentproducer droppedlaunch-work-item-directcaller stops passingdraftContentSeeding, from the first round:
startupPlan.draftPrompt-keyed implementationThe end-to-end invariant test in
folder-workspace-composer-submit.test.tsruns the realsubmitFolderWorkspaceCreateand the real view-mode decision over all four delivery/shape combinations and assertsseeded === opensInChat. Its module mock usesimportOriginalso it exercises the shippedresolveStartupLaunchDraftTextrather than a copy — without that it silently tested a reimplementation.Note on the original target
The brief named
useComposerState.ts'ssubmit. That branch is dead:NewWorkspaceComposerModalis the only consumer ofuseComposerStateand usessubmitQuickonly (it also overridescardProps.onCreate), andsubmitbuilds its plan withbuildAgentStartupPlan, which never setsdraftPrompt. Seeding it would have been inert with an unfalsifiable test.Also here
launch-agent-in-new-tab.tscrossed the 300-linemax-linescap. PerAGENTS.mdI split rather than bump it:launch-agent-startup-prompt-plan.ts(how a launch delivers its prompt) andlaunch-agent-paste-timeout-notice.ts(the dropped-paste notice). Both are pure moves.Verification
npm run typecheckclean (afterrm -f config/*.tsbuildinfo)npm run lintclean, including the native and type-aware quality auditsb41e813cb5with the same command, and they survive--maxWorkers=2, so they are not load flakesexpois not installed here, so all 351 mobile files fail to parse (TSConfckParseError: failed to resolve "extends":"expo/tsconfig.base.json"). No mobile files are changed, but CI green does not represent local mobile coverage.