Repository navigation
fix(mobile): label native-chat tool rows with a clean, expandable input summary (STA-3333) - #12498
Conversation
…(STA-3333)
Mobile tool rows showed the raw input JSON (`{"file_path":…}`) as the row
label, and the expanded detail just repeated that same truncated string.
- `describeToolInput` labels a row with the target file path, else the
primary argument (command/cmd/query/pattern/url/description), else the
bounded JSON preview.
- Codex delivers tool arguments as a JSON string; normalize those into the
object shape the helpers already understand, so labels, file links,
run summaries and the expanded detail all work for Codex calls too.
- The expanded detail now renders the fully formatted input, capped at
MAX_TOOL_RESULT_CHARS like desktop's tool detail (and like the result
body), and a structured input makes the row expandable.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change adds shared normalization for structured and JSON-string tool inputs. It adds labels for paths, commands, queries, patterns, URLs, and descriptions. Mobile code re-exports the shared helpers. Tool messages now display human-readable previews, bounded input and result text, formatted expanded details, and structured-input expansion. Tests cover normalization, labeling, formatting, truncation, rendering, and interaction. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c095b630-e48b-4f68-b027-3252e7513591
📒 Files selected for processing (6)
mobile/src/session/MobileNativeChatMessage.test.tsmobile/src/session/MobileNativeChatMessage.tsxmobile/src/session/mobile-native-chat-tool-summary.test.tsmobile/src/session/mobile-native-chat-tool-summary.tssrc/shared/native-chat-tool-summary.test.tssrc/shared/native-chat-tool-summary.ts
| // The row label is a human summary (path / primary arg), never raw JSON; the | ||
| // expanded detail below carries the full formatted input. | ||
| const preview = call | ||
| ? summarizeToolInput(call.input) | ||
| ? describeToolInput(call.input) | ||
| : (result?.output.split('\n')[0]?.slice(0, 80) ?? '') | ||
| // Why: collapsed tool rows are the common path; defer bounded diff parsing | ||
| // until the user asks to reveal the detail. | ||
| // and detail formatting until the user asks to reveal the detail. | ||
| const callDiff = expanded && call ? diffFromToolCall(call.name, call.input, diffLineLimit) : null | ||
| const resultDiff = expanded && result ? diffFromText(result.output, diffLineLimit) : null | ||
| const hasDetail = callDiff !== null || result !== undefined || preview.length > 40 | ||
| // Bound before handing it to native text layout, like the result body. | ||
| const callDetail = | ||
| expanded && call && !callDiff ? boundedText(formatToolInput(call.input)) : undefined | ||
| const hasDetail = | ||
| callDiff !== null || | ||
| result !== undefined || | ||
| preview.length > 40 || | ||
| (call !== undefined && isStructuredToolInput(call.input)) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Normalize serialized edit inputs before diff extraction.
Line 102 passes the raw JSON string to diffFromToolCall. That helper rejects non-object input. A Codex Edit call with serialized JSON therefore shows formatted JSON instead of the existing diff view.
Normalize the input before calling diffFromToolCall. Add a rendering test for a JSON-string Edit input with old_string and new_string.
…path labels (STA-3333) Review follow-ups to the tool-row summary, all in the shared helper: - A Grep/Glob row labelled itself with the directory it scanned and dropped the pattern entirely, because `toolFilePath` treats `path` as a file target. That path is a scan root, so it also rendered a tap-to-open link that asked the app to open a folder. `toolFilePath` now ignores the generic `path` key for search-shaped input, which lets the pattern win the label and drops the bogus link; an explicit `file_path` still wins. - An overlong path was truncated from the head, cutting off the basename — the one part that tells two rows apart. Trim from the front instead, so the label reads `…/session/MobileNativeChatMessage.tsx`. - The primary-argument chain used `??`, so a present-but-blank key selected itself and swallowed the keys ranked after it, dropping the label all the way back to raw JSON. Take the first key that actually yields a label. Refs STA-3333.
…A-3333)
An empty tool input formats back to the row label verbatim, so `{}` and `[]`
advertised an expander and then re-showed the label — the same repeat-the-JSON
problem this change set out to remove. Gate `isStructuredToolInput` on the
collection actually having contents; the lazy detail path is untouched.
Also pins the overlong-path test to the path itself: asserting only length<=80
plus a `…` passed just as well with path labelling deleted.
The Tools toggle opens every row at once, bypassing the row's tap guard, so a row with nothing to expand rendered its own label again underneath itself — and the tap that would dismiss it is a no-op. Matches desktop.
Skipping a present-but-blank primary key let `briefToolArg` fall through
to the raw JSON preview, so a run header read `Bash {"command":""}` where
it used to read `Bash`. Also state the search-path trade-off honestly:
suppressing the link costs a file-scoped search its tap target.
…A-3333) The previous guard tested key presence, so a populated but non-string argument — a mixed argv like ['kill','-9',pid], or a structured query — dropped out of the run header instead of falling back to the preview.
The panel gate was covered but the chevron beside it was not: swapping `showDetail` back to `expanded` on the icon alone left all 909 mobile tests green, so the affordance lie this branch fixes could return unnoticed — a down-chevron over no panel, on a row whose tap is guarded off. Asserts both icon counts on the fixture that test already renders. The two halves now die for distinct reasons: the panel gate on the duplicate label text, the chevron on the icon count.
…333) Dropping `.trim()` from summarizePrimaryToolArg left all 32 tests green, yet it leaks through isSearchToolInput: a whitespace-only `query` starts counting as a search term, which suppresses `path`. One character takes the row's label, its tap-to-open link and its run-header argument at once, and puts the raw JSON label back — the bug this branch removes. Asserts all three outputs on that shape. Kills only that mutant; the isSearchToolInput mutant still dies on the existing search test.
Review loop — final stateHead Reviewed by successive independent same-model passes until clean. Three passes found something real; each finding was reproduced locally before any code changed, and each fix was mutation-tested in both directions before being pushed. What the passes caught
I verified the final guard against
Both new tests were checked for vacuity in both directions: each kills its intended mutant, and each survives the other's mutant, so they pin distinct edges rather than standing in for one another. Known limitation, pre-existing, not addressed here
Evidence and gatesThe Electron A/B screenshots above were captured at Gates at Mobile emulator QA was not run — simulator capacity was held by other owners at the time, so this carries desktop evidence only. |
Build the tool row label, file target, detail eligibility and bounded detail from one normalized input model. Mobile no longer reparses JSON-string input across independent helpers or repeats an already-complete plain label, and desktop now uses the same clean row summary instead of retaining raw JSON.\n\nKeep full detail formatting lazy for collapsed rows and share the 4000-character detail cap across both renderers. Tests pin desktop adoption, mobile disclosure parity, one-pass JSON parsing and the shared bound.
…ut summary (STA-3333) (stablyai#12498) * fix(mobile): label tool rows with a clean summary, expand full input (STA-3333) Mobile tool rows showed the raw input JSON (`{"file_path":…}`) as the row label, and the expanded detail just repeated that same truncated string. - `describeToolInput` labels a row with the target file path, else the primary argument (command/cmd/query/pattern/url/description), else the bounded JSON preview. - Codex delivers tool arguments as a JSON string; normalize those into the object shape the helpers already understand, so labels, file links, run summaries and the expanded detail all work for Codex calls too. - The expanded detail now renders the fully formatted input, capped at MAX_TOOL_RESULT_CHARS like desktop's tool detail (and like the result body), and a structured input makes the row expandable. * fix(mobile): name search rows by their term and keep the filename in path labels (STA-3333) Review follow-ups to the tool-row summary, all in the shared helper: - A Grep/Glob row labelled itself with the directory it scanned and dropped the pattern entirely, because `toolFilePath` treats `path` as a file target. That path is a scan root, so it also rendered a tap-to-open link that asked the app to open a folder. `toolFilePath` now ignores the generic `path` key for search-shaped input, which lets the pattern win the label and drops the bogus link; an explicit `file_path` still wins. - An overlong path was truncated from the head, cutting off the basename — the one part that tells two rows apart. Trim from the front instead, so the label reads `…/session/MobileNativeChatMessage.tsx`. - The primary-argument chain used `??`, so a present-but-blank key selected itself and swallowed the keys ranked after it, dropping the label all the way back to raw JSON. Take the first key that actually yields a label. Refs STA-3333. * fix(mobile): don't offer an expander whose detail repeats the row (STA-3333) An empty tool input formats back to the row label verbatim, so `{}` and `[]` advertised an expander and then re-showed the label — the same repeat-the-JSON problem this change set out to remove. Gate `isStructuredToolInput` on the collection actually having contents; the lazy detail path is untouched. Also pins the overlong-path test to the path itself: asserting only length<=80 plus a `…` passed just as well with path labelling deleted. * fix(mobile): gate the tool detail panel on having detail (STA-3333) The Tools toggle opens every row at once, bypassing the row's tap guard, so a row with nothing to expand rendered its own label again underneath itself — and the tap that would dismiss it is a no-op. Matches desktop. * fix(mobile): keep a blank tool argument out of the run header (STA-3333) Skipping a present-but-blank primary key let `briefToolArg` fall through to the raw JSON preview, so a run header read `Bash {"command":""}` where it used to read `Bash`. Also state the search-path trade-off honestly: suppressing the link costs a file-scoped search its tap target. * fix(mobile): only treat a blank primary key as a missing argument (STA-3333) The previous guard tested key presence, so a populated but non-string argument — a mixed argv like ['kill','-9',pid], or a structured query — dropped out of the run header instead of falling back to the preview. * test(mobile): pin the tool-row chevron to the detail panel (STA-3333) The panel gate was covered but the chevron beside it was not: swapping `showDetail` back to `expanded` on the icon alone left all 909 mobile tests green, so the affordance lie this branch fixes could return unnoticed — a down-chevron over no panel, on a row whose tap is guarded off. Asserts both icon counts on the fixture that test already renders. The two halves now die for distinct reasons: the panel gate on the duplicate label text, the chevron on the icon count. * test(shared): pin the blank-search-key guard in the tool label (STA-3333) Dropping `.trim()` from summarizePrimaryToolArg left all 32 tests green, yet it leaks through isSearchToolInput: a whitespace-only `query` starts counting as a search term, which suppresses `path`. One character takes the row's label, its tap-to-open link and its run-header argument at once, and puts the raw JSON label back — the bug this branch removes. Asserts all three outputs on that shape. Kills only that mutant; the isSearchToolInput mutant still dies on the existing search test. * fix(native-chat): share tool input display semantics (STA-3333) Build the tool row label, file target, detail eligibility and bounded detail from one normalized input model. Mobile no longer reparses JSON-string input across independent helpers or repeats an already-complete plain label, and desktop now uses the same clean row summary instead of retaining raw JSON.\n\nKeep full detail formatting lazy for collapsed rows and share the 4000-character detail cap across both renderers. Tests pin desktop adoption, mobile disclosure parity, one-pass JSON parsing and the shared bound.







Summary
Mobile tool rows in native chat labelled themselves with the raw tool-call input JSON — a
Readshowed{"file_path":"src/index.ts","offset":10}instead of the file it read — and tapping the row open just repeated that same truncated string as the "detail", so expanding revealed nothing new.This makes the mobile tool row read as a clean, bounded, expandable summary:
describeToolInputlabels a row with the target file path, else the primary argument (command/cmd/query/pattern/url, falling back todescription), else the existing bounded JSON preview. Concrete target/action wins over prose, so a Bash call labels with its command rather than its description.{/[string by parsing it into the object shape they already handle; prose strings, JSON scalars, and malformed JSON are left exactly as-is.MAX_TOOL_RESULT_CHARS(4000) — the same cap desktop applies to its tool detail, and the same cap the mobile result body already used. Native text layout has no scroll container to absorb a runaway payload, so this is bounded before it reaches layout. A structured input also makes the row expandable, which it previously wasn't unless the preview happened to exceed 40 chars. Conversely, a row with nothing to expand no longer renders a panel at all: the detail panel and the open-chevron are gated on the samehasDetailguard as the tap, so the Tools toggle — which opens every row at once, bypassing that tap — can no longer leave a row echoing its own label under itself with no way to dismiss it. This matches desktopNativeChatToolRun.tsx.Known limitation, pre-existing and left for follow-up.
sanitizeToolInputinsrc/main/runtime/rpc/methods/native-chat.tsclips a tool-call input that is a JSON string atMOBILE_BLOCK_CHAR_CAP(4000) and appends a truncation marker, which leaves it unparseable. So a Codex call whose arguments exceed 4000 chars — a write with largecontent, or a multi-line script — still falls back to the raw-JSON label, and loses its open-file link, where the byte-identical Claude call keeps both (the sanitizer shrinks object values key-by-key but truncates a string as one opaque blob).mainshowed raw JSON at every size, so nothing regresses; this PR simply doesn't reach that case. The contained fix is to parse the string main-side, sanitize the parsed object with the existing caps, and re-stringify — which keeps the wire shape a string — but that is a main-process change outside this PR's scope.Split out of #12373 (item 10 of that QA sweep) as an independent, focused PR targeting
main. #12373 stays open and is not affected by this branch.Refs STA-3333.
Screenshots
No visual change to layout, spacing, color, or typography — existing tokens and components only. The user-visible change is the text inside the existing tool row.
Desktop A/B captured with
playwright-cliover CDP against a dev build of this branch, on a resumed read-only Codex session with 104 realexec_commandcalls. Same session, viewport, scroll offset and DOM in both frames; the only difference issrc/shared/native-chat-tool-summary.ts(branch vsorigin/main).origin/main)The
18×run is the clearest case: onmainthe{"cmd":"prefix eats 8 of the 28 label characters, so two different calls render byte-identical labels (exec_command {"cmd":"ps -p 20068 -o pid=,twice); after the fix they readps -p 20068 -o pid=,pgid=,cwand…,pgid=,coand are distinguishable.Desktop parity — a Codex JSON-string call now pretty-prints in its expanded detail via the same
formatToolInputnormalization:The per-call row label inside an expanded desktop run still uses
summarizeToolInput(the raw bounded preview) — unchanged frommain, and a desktop-renderer decision left outside this PR.Testing
pnpm lint— rootoxlintclean, mobileoxlintclean, native + type-aware code-quality audits clean,check:max-lines-ratchetOK (352 grandfathered, no new bypasses),lint:react-doctor:changedexit 0 (the threeno-array-index-as-keywarnings it prints are pre-existing, on lines this PR does not touch)pnpm typecheck— all three root tsc projects (node,tc.cli,tc.web) and mobiletsc --noEmitcleanpnpm test— 464 files / 4452 tests desktop+shared, 403 files / 3015 tests mobile, all passingpnpm build— not run; no build-affecting changes (pure string formatting + one renderer file), CI covers itTests added:
describeToolInputpath/primary-argument/fallback/truncation labelling and theurl-before-descriptionordering; a dedicated Codex JSON-string block covering label, formatted detail, file link,briefToolArg,isStructuredToolInput, argv-array joining, and the negative cases (prose, malformed JSON, JSON scalar); mobile renderer tests that the row labels with the path rather than raw JSON, that the expanded diff-less detail is capped at exactlyMAX_TOOL_RESULT_CHARS + 1chars ending in…, that a Codex JSON-string call labels with its command and reveals pretty-printed JSON only once its row is tapped, that a row with nothing to expand renders no detail panel even when the Tools toggle opens every row, and that a present-but-blank primary argument keeps the run header readingBashrather thanBash {"command":""}while a populated but non-string one (mixed argv, structured query) still falls back to the preview.Anti-vacuity check: every new test was re-run against mutated source rather than only against a revert. Reverting the three source files (tests kept) fails all four original renderer/barrel tests; deleting the detail-panel guard fails the row-echo test; deleting the blank-argument guard fails the run-header test. Two things are deliberately not pinned and are cosmetic: the segment-boundary alignment inside
summarizeToolPath, and the chevron half of the detail-panel guard.AI Review Report
Self-reviewed with focus on:
formatToolInput,toolFilePathandbriefToolArgare shared with the desktop renderer (NativeChatToolRun.tsx), so normalizing JSON-string input changes desktop behavior too. Verified this is strictly an improvement and intended parity: a Codex JSON-string call on desktop now pretty-prints in its detail and becomes expandable via the existingdetailAddsInfocheck, where it previously collapsed to detail-equals-preview. The desktop renderer itself is deliberately untouched (this PR is scoped to the mobile row label); its 897 existing tests pass unchanged.normalizeToolInputonly attemptsJSON.parsewhen the trimmed string starts with{or[, is wrapped in try/catch, and returns the original string on failure or when the parse yields a non-object — so prose, malformed JSON, and JSON scalars round-trip unchanged. Locked by test.boundedTexthelper rather than duplicated. Verified with a 100 KB payload.describeToolInput,toolFilePathandisStructuredToolInputeach re-run the JSON-string normalization, so a collapsed Codex row costs 3JSON.parseof its arguments per render (+1 per run-header render viasummarizeToolRun→briefToolArg). Measured over 6 rows: 2 KB payload 0.81 → 0.87 ms (noise), 100 KB 0.70 → 1.47 ms. Sub-millisecond and bounded upstream by the 4000-char wire cap, so not worth memoizing here — but worth memoizing if these helpers ever move onto a hot virtualized list.ToolLineremains a pure render.lint:react-doctor:changedpasses.Cross-platform: no keyboard shortcuts, shortcut labels, shell invocation, or filesystem path construction are touched. Path handling is read-only string inspection that already splits on
[\\/], and Windows backslash paths are covered by both pre-existing and newly added assertions. The change is React Native / renderer string formatting and is identical on iOS and Android and agnostic of the desktop host OS — it behaves the same for a local, WSL, SSH, or relay-backed session, and for folder workspaces as well as git worktrees, because it never inspects the workspace kind. No Git commands involved.Security Audit
No command execution, no auth, no secrets, no dependency changes, and no IPC/RPC surface change (no new methods; this is pure presentation over data the chat transcript already carries).
The one new input-handling surface is
JSON.parseon agent-supplied tool-argument strings. It is gated on a leading{/[, wrapped in try/catch, and its result is only ever read as data — never evaluated, never used to construct a path or command, and never used for a filesystem or network operation. Parsed values flow through the pre-existing bounded-preview logic (length, collection-size, depth, and circular-reference caps) and render into plainTextnodes, so there is no injection or amplification surface. Deeply nested or oversized payloads are bounded by the existing preview caps for the label and byMAX_TOOL_RESULT_CHARSfor the detail.JSON.parseon a hostile string is a memory cost only, and tool inputs are already fully materialized in the transcript before this code runs.The existing
onOpenFilelink now also fires for Codex calls, sincetoolFilePathcan finally read their path. That path goes to the same already-validated open-file handler used by object-input calls — this widens which calls get a link, not what the handler accepts.Notes
origin/mainand targetsmain, so it can merge independently and in any order relative to fix(mobile): native chat QA sweep — reconnect history, stale status, prompt-card and paging fixes (STA-3333) #12373.diffFromToolCallstill receives the raw, un-normalizedcall.input, so a Codex JSON-stringEditrenders as formatted JSON rather than a diff — unchanged frommain, and left alone as it belongs to the diff module rather than this summary scope. Worth a follow-up if Codex edit diffs are wanted on mobile.{}or[]) is no longer advertised as expandable: its formatted detail is byte-identical to the row label, so offering the expander promised detail and then repeated the row — the same defect this PR removes.isStructuredToolInputnow requires the collection to be non-empty; the lazy-detail path is untouched.MOBILE_BLOCK_CHAR_CAP), and for a Codex JSON-string input that clip lands mid-JSON, soJSON.parsefails and the row falls back to the raw-JSON label. Measured against 29,947 real Codex tool calls across 1,981 transcripts, 0.2% exceed that cap (exec_commandmedian 221 chars, p95 740). Fixing it means parsing before sanitizing in the main-process RPC — a different layer, and it would also silently un-defer thediffFromToolCallgap noted above. Left for a follow-up rather than widened into this PR.