Skip to content

fix(mobile-native-chat): pick the attachment form per agent - #20391

Closed
mmarabel wants to merge 4 commits into
stablyai:mainfrom
mmarabel:mmarabel/native-chat-mobile-parity
Closed

mmarabel wants to merge 4 commits into
stablyai:mainfrom
mmarabel:mmarabel/native-chat-mobile-parity

Conversation

@mmarabel

Copy link
Copy Markdown
Contributor

ELI5

Desktop already picks the attachment form each agent actually accepts. Mobile's native chat still sent every agent the same thing, so an agent without an image-paste gesture got a bare path where it should have got a file reference. This makes mobile use the same rule instead of keeping its own.

What Changed

  • Mobile's native-chat send path now builds its attachment writes with the shared buildNativeChatAttachmentWrites, keyed by the existing getNativeChatAttachmentForm — no third per-agent table.
  • Extracts the pure byte/framing primitives into src/shared/bracketed-paste-text.ts and src/shared/native-chat-paste-bytes.ts. The desktop helpers were renderer-bound (native-chat-send.ts pulled in native-chat-composer-target.ts, which imports renderer i18n/runtime, and terminal-bracketed-paste.ts is xterm-bound), so mobile could not import them. Both renderer modules now re-export from the shared modules, so no desktop caller changed.
  • The agent is read at send time from the chat tab's existing activeChatAgentRef, like mobile's other send paths.
  • A third commit hardens the shared module: a @path reference whose name holds a quote is now quoted (escaping only makes sense inside a quoted token), and a reference holding TAB or another C0 byte is framed instead of being written as keystrokes. ESC stays unframed but sanitized, which is the pre-existing deliberate behaviour.

Why

Same root cause as #20389 — the attachment form was uniform per agent. Reusing the shared rule rather than copying it is also what keeps desktop and mobile from drifting on this again.

Linked Issue

Part of #20389. Stacked on #20390, which fixes the desktop path.

Visual Proof

N/A — this changes the PTY bytes written for an attachment, not any rendered UI. There is no visual or interaction change.

Testing

  • mobile/: pnpm test → 510 files, 4175 passed, 3 skipped. pnpm typecheck (tsc --noEmit) clean. pnpm lint (oxlint) exit 0.

  • Root: native-chat + terminal-pane + shared suites pass; pnpm tc:web and pnpm tc:node clean; pnpm run check:code-quality:changed reports 0 new findings.

  • A direct test file was added for src/shared/native-chat-paste-bytes.ts, which previously had none, covering the quoting rule, the framing boundary, and both attachment forms.

  • Platform notes: byte construction only; no new path handling or platform branches. Worth knowing for review: mobile's tsconfig excludes test files, so mobile test files are not typechecked — a review pass caught a missing required argument in a new test that tsc did not.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Implemented with Claude Code (Opus 5), running as an Orca-supervised worker. Reviewed by a six-reviewer pass (correctness, project standards, testing, maintainability, frontend-races, plus an independent cross-model adversarial review), and independently verified by the coordinating agent, which re-ran the mobile and root gates against this tree.

Review

Stacking

This branch is stacked on #20390 — its first commit is that PR's commit, so review #20390 first. Both PRs target main rather than chaining bases, because the stacked branch lives in a fork and cannot be used as a base branch upstream; once #20390 merges, this diff collapses to the mobile commit plus the hardening commit.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: byte construction only; no new IPC, no new dependency.
  • Cross-platform: identical construction on macOS, Linux and Windows.
  • SSH/remote: unchanged — mobile reuses the existing send path.
  • Mobile: this is the mobile parity change for Native Chat: agents without a verified image-paste gesture receive a naked image path #20389.
  • Backwards compatibility: no desktop caller changed; the shared modules are re-exported from their previous homes.
  • Performance: the write count per send is unchanged, so the existing mobile sequence deadline still funds a whole send.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Native Chat bracket-pasted a raw image path for every agent, but only agents
with a verified image-paste gesture turn that into an attachment chip. `omp` is
a Native-Chat-supported agent with no such gesture (it wraps Pi's TUI), so a
dropped image reached it as a naked path the model reads as prose — exactly what
native-chat-image-paste.ts says must not happen. The clipboard route already
refused omp; the drop and file-picker routes did not.

Add `attachmentForm` to the existing per-agent profile table and branch the
existing attachment byte builder on it. Agents without a verified profile get
the portable `@path` reference. `@path` is plain text rather than a
self-delimiting frame, so every reference is space-separated, and a path holding
CR/LF goes through buildNativeChatPasteBytes so a filename cannot submit the
turn early.
Mobile Native Chat bracket-pasted a raw image path for every agent, but only
agents with a verified image-paste gesture turn that into an attachment chip.
Desktop already branches on the `attachmentForm` profile field; mobile did not,
so an agent without that gesture — omp, which wraps Pi's TUI — received a naked
path the model reads as prose.

The desktop byte builders were renderer-bound (`native-chat-send.ts` pulled in
`native-chat-composer-target.ts`, which imports the renderer i18n and runtime,
and `terminal-bracketed-paste.ts` is xterm-bound), so mobile could not import
them. Extract the smallest self-contained pieces instead of duplicating the
mapping: `src/shared/bracketed-paste-text.ts` holds the pure framing primitives,
`src/shared/native-chat-paste-bytes.ts` the paste/attachment byte builders. Both
renderer modules now re-export from them, so no desktop caller changes.

Mobile's send path builds its attachment writes with the shared
`buildNativeChatAttachmentWrites`, keyed by the existing
`getNativeChatAttachmentForm` — no third per-agent table. The agent comes from
the chat tab's existing `activeChatAgentRef`, read at send time like the other
mobile send paths. `@path` references go through the same framing, so a filename
holding CR/LF cannot submit the turn early, and each one is space-separated
because a reference is not self-delimiting. The write count per send is
unchanged, so the sequence deadline still funds the whole send.
Three findings from the review of the per-agent attachment form work.

formatNativeChatFileReference escaped `"` but only quoted on whitespace, so a
name holding a quote without a space emitted an unquoted `@path` carrying a
stray escape. Escaping only makes sense inside a quoted token, so a quote now
forces quoting too.

The `@path` branch framed only on CR/LF, so a file name holding TAB or another
C0 byte went out unframed and would act as a key rather than pasted text. Frame
anything sanitization cannot neutralise. ESC stays unframed but sanitized, which
is the existing deliberate behaviour and is asserted as such.

Drop the unused formatNativeChatFileReference re-export from native-chat-send.ts:
the one consumer imports it from native-chat-composer-target.

src/shared/native-chat-paste-bytes.ts had no direct test file; add one covering
the quoting rule, the framing boundary, and both attachment forms.
@mmarabel
mmarabel force-pushed the mmarabel/native-chat-mobile-parity branch from 8795da3 to 32e0346 Compare September 12, 2026 13:38
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e421130a-b1f4-48f8-866a-217ce638dff0

📥 Commits

Reviewing files that changed from the base of the PR and between 32e0346 and 339eb52.

📒 Files selected for processing (1)
  • src/shared/bracketed-paste-text.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/shared/bracketed-paste-text.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change centralizes bracketed-paste and native chat attachment encoding in shared modules. Agent profiles select either image-paste or file-reference. Desktop and mobile send paths pass the active agent to shared attachment builders. Mobile reads the agent from a send-time ref. Tests cover framing, quoting, spacing, agent mappings, and desktop and mobile send flows.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 339eb

The reviewed change does not leave a concrete merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 26 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: selecting the mobile native-chat attachment form per agent.
Description check ✅ Passed The description is complete and relevant. It includes the required explanation, change summary, rationale, issue references, visual-proof explanation, testing results, AI disclosure, review notes, com…
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.
  • Fix all pre-merge checks with AI

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.

❤️ Share

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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

  • Per-agent attachment form on mobile — pasteMobileNativeChatImagePaths now shapes each write from getNativeChatAttachmentForm(agentRef.current) via the shared buildNativeChatAttachmentWrites, so omp and custom agents get @path instead of a bracketed raw image path. The agent is read at send time and plumbed through the controller contract; the structured lane correctly ignores it.
  • Shared byte/framing extraction — src/shared/bracketed-paste-text.ts and src/shared/native-chat-paste-bytes.ts now hold the pure primitives, and the renderer modules re-export them, so desktop callers are unchanged while mobile can import them. The image-paste bytes are identical to the previous mobile/desktop builders.
  • Reference hardening — formatNativeChatFileReference quotes on " as well as whitespace, and the @path branch frames CR/LF/TAB/C0/DEL so an unframed reference cannot be read as keystrokes. Tests pin the exact bytes and cross-check the form table against IMAGE_ATTACHMENT_AGENTS.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/shared/bracketed-paste-text.ts Resolved
…uences

The extracted framing module inlined a raw 0x1b control byte and a literal
U+241B glyph, while the desktop source it was extracted from writes
'\u001b' and '\u241b'. A raw control byte is invisible in review and easy
to mangle in editors, and the escape form keeps the extraction faithful to
its original. Behavior is unchanged — the existing byte-pinning tests still
pass.
@nwparker

Copy link
Copy Markdown
Contributor

Superseded by merged current-main replacement #21674, which covers desktop and mobile composer, drop, picker, and clipboard-accessory image attachment paths with green hosted RPC recording verification and cross-platform test proof.

@nwparker nwparker closed this Sep 19, 2026
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.

2 participants