Skip to content

fix(native-chat): pass agent-implemented slash commands through to the agent - #19929

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/native-chat-command-passthrough
Sep 11, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/native-chat-command-passthrough

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​344 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​330
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​58

What changes for you

Before — a slash command the agent itself implements was refused by the chat host, and nothing was sent:

  • Claude chat: /init, /review and /help answered "/init is not available in chat sessions. Use the slash menu to see available commands." — even though Claude's own harness implements them and would have run them. /init is even offered in Claude's slash menu, so picking it from the menu produced the refusal too.
  • Codex chat: /goal <objective> was refused the same way.

After — the host claims only the commands it implements (/clear, /compact, /model, /effort); a command the agent implements is sent on as the message text and actually runs:

  • Claude chat: /init reaches Claude, which analyses the project and writes CLAUDE.md.
  • Codex chat: /goal is now listed in the / menu, and /goal <objective> reaches the model, which opens a real goal and works the objective.

A hand-typed /clear is still answered by the host and never sent to the model as literal text — claiming remains the default for every agent that has no pass-through policy.

Before / after, on a real build

Both runs use the same throwaway folder workspace and the same typed command. "Before" is a dev build of main (12f2c6b991); "after" is a dev build of this branch (9eab58a823). Captured over CDP against the rendered app.

Claude — /init

Before (main): refused, nothing sent After (this branch): runs, CLAUDE.md created
before-claude-init.png after-claude-init.png

In the "after" shot the user bubble is the /init the user typed, the turn reads Worked for 44s, and CLAUDE.md has appeared in the file tree on the right.

Codex — /goal Add a unit test for countWidgets

Before (main): refused, nothing sent After (this branch): the model takes the objective
before-codex-goal.png after-codex-goal.png

The Codex session rollout for that run records the model calling create_goal({objective: "Add and verify a focused unit test for countWidgets"}) and, once the test passed, update_goal({status: "complete"}) — so /goal as prose really does reach the model's goal tools.

And /goal is now discoverable, not just typable

Codex reports no command catalog, so its structured / menu is the host's fallback list — which offered only the host's own commands and hid /goal even after it started working. The picker now also offers the commands the agent itself runs from message text, described from the curated catalog:

The Codex / menu now lists /goal Picking it reaches the model, not a refusal
after-codex-picker.png after-codex-goal-pick.png

Claude's menu is unchanged: it reports its own catalog, so it takes the session-reported branch and never reaches this fallback.

The principle

Claim what the host implements; pass through what the agent implements.

dispatchStructuredAgentSessionComposerCommand decides the fate of every /command typed into a structured native chat session. Anything in its recognized set is claimed by the host; anything else falls through and is sent to the agent as ordinary message text. Until now the recognized set was the host's own commands plus the whole per-agent curated catalog — which is wrong whenever the agent itself implements the command.

The two providers differ fundamentally:

  • Claude (Agent SDK, stream-json): the harness expands a slash command out of the user text, provided the command is in the last content block. A command sent as text genuinely runs.
  • Codex (app-server): there is no slash parsing anywhere in the server — expansion is a TUI-only concern, so a slash command sent as text reaches the model as prose. The single exception is /goal: the model owns goal tools and calls create_goal itself when /goal <objective> arrives as prose.

So the policy is per-agent, and src/shared/native-chat-agent-profiles.ts already declares itself the single place that kind of policy lives. It now carries two fields:

  • expandsSlashCommandsFromText — Claude and OpenClaude. The host claims nothing from the catalog; it keeps only its own four (clear, compact, model, effort).
  • textDrivenCommands — Codex's ['goal']. An explicit, narrow allowance, not a blanket unclaim.

getHostClaimedNativeChatCommands(agent) applies that policy, and the composer's structuredRecognizedCommands consults it instead of the raw catalog. No agent checks were added to the dispatcher.

Claiming stays the default. An agent with no policy (and the custom-agent fallback) still has its whole catalog claimed, so a hand-typed /clear is answered by the host and never reaches the model as literal prompt text. That protective intent is what the recognized set is for, and it is untouched.

getVerifiedNativeChatCommands is deliberately unchanged — send classification, collision detection, transcript envelope surfacing, and the mobile composer all key off it, and none of those want the host-claim distinction.

Bugs fixed

  1. /init on Claude answered "/init is not available in chat sessions" — init is in CLAUDE_COMMANDS, so the host claimed and refused a command Claude implements and would have run. It now passes through.
  2. /review on Claude — identical mechanism, identical fix.

(/help on Claude was refused by the same mechanism and now passes through too.)

/goal on Codex

goal is in CODEX_COMMANDS, so /goal <objective> was refused. It now passes through as text, where the model's own goal tools create a real goal. Every other Codex catalog command stays claimed and refused, because sending e.g. /permissions or /vim as text would just be garbage in the transcript.

Attachment guard: decision

isStructuredAgentSessionComposerCommand is also the attachment guard in use-native-chat-structured-composer-send.ts ("Remove attachments before using a chat-session command."). No code change there — and that is the point.

The predicate's meaning is now precisely "the host, not the agent, owns this command", which is exactly the condition the guard wants:

  • A host command sends no message at all. Its attachments would be silently dropped, so refusing the send is right, and /clear, /compact, /model, /effort still refuse.
  • A pass-through command is the message. Attachments ride along with it through transport.send(text, attachments), so refusing would be a regression. /init, /review and /goal <objective> now send normally with their attachments.

The same predicate change makes the mobile bridge and the desktop draft-preservation path correct for free: a passed-through command is a real chat turn, so it gets its optimistic bubble and clears the composer like any other send.

The function's doc comment now states this contract so the next caller does not have to infer it.

Discoverability: the structured picker

structuredSlashCommands() builds the / menu for a structured session whose host reports no catalog of its own — which is every Codex session. It took no agent, so it could only ever offer host commands, and /goal was invisible in the one place a user looks for it.

It now takes the agent and appends getTextDrivenNativeChatCommands(agent) — the exact mirror of the claimed set, resolved against the curated catalog so the row carries the description that already exists (goal → "Set or view the goal"). Nothing was added to CODEX_COMMANDS: a name added there would be claimed-and-refused unless it were also in textDrivenCommands, which is the coupling this PR documents. A name already offered by the host is not duplicated.

The menu invariant is preserved and now stated in the terms the change requires: a row the user picks is either answered by the host or run by the agent — never refused. The existing NativeChatComposer test that pinned the Codex menu to an exact list now pins ['model', 'effort', 'goal'], and the shared test walks every offered row through the real dispatcher asserting none of them produces the "not available in chat sessions" refusal.

Callers updated: use-native-chat-composer-catalog.ts (desktop) and MobileNativeChatComposer.tsx (mobile) both pass their agent.

Validation (picker commit fce181473d)

Ablation — new/updated tests kept, all four prod files reverted to 9eab58a823:

Test files Tests
Change reverted 3 failed | 1 passed 3 failed, 58 passed
Change restored 4 passed 61 passed, 0 failed

The three failures are one per surface: the shared picker, the desktop hook, and the rendered composer. A second arm reverting only the desktop caller failed exactly one test (the hook), so the caller wiring is pinned independently rather than riding on the shared change.

Gates (all gated on exit status):

  • pnpm run typecheck:tsc — exit 0, 0 error TS (non-incremental, all three projects; the incremental pnpm tc can pass on a stale tsbuildinfo)
  • pnpm run check:code-quality:changed — exit 0: 0 new findings across 9 changed files
  • pnpm run check:react-doctor:changed — exit 0
  • pnpm run audit:code-quality:native — exit 0 (repo-wide, --deny-warnings)
  • pnpm test src/shared src/renderer/src/components/native-chat — 8997 passed, 0 failed, 117 skipped (813 files). The first sweep caught one real regression — NativeChatComposer.test.tsx pinned the Codex menu to an exact ['model', 'effort'] — which is updated in this commit rather than worked around.

Not verified locally: mobile/node_modules is empty in this worktree, so mobile's own vitest and tsc --noEmit cannot run — reverting the mobile edit reproduces the identical expo/tsconfig.base.json resolution error, so the failure is environmental and pre-existing. The mobile change is one argument on an existing call; it is covered by CI.

Validation (pass-through commit 9eab58a823)

Ablation — new tests kept, both source files reverted to base 721a269289:

Test files Tests
Change reverted 3 failed 10 failed, 24 passed
Change restored 3 passed 34 passed, 0 failed

Gates (all gated on exit status):

  • pnpm tc — exit 0
  • pnpm run check:code-quality:changed — exit 0: 0 new findings across 5 changed files (code quality, type-aware, React Doctor)
  • pnpm test src/shared src/renderer/src/components/native-chat — 8988–8992 passed of 9110. Five failures across two full runs, all Test timed out / socket-timing under load, a different set each run, and all four files pass in isolation (41/41, exit 0): feature-interactions, export-let-function-initializer-ban, remote-runtime-shared-control-connection, NativeChatMessageList.tool-stream-cost. None touch command dispatch.

Coverage added

  • src/shared/structured-agent-session-composer.test.ts — /init, /review, /help pass through on Claude; /clear, /compact, /model, /effort still claimed on Claude; /goal ship the fix passes through on Codex; /permissions still refused on Codex with its original message.
  • src/shared/native-chat-agent-profiles.test.ts — the policy itself: Claude-family claims nothing, Codex claims everything but goal (while the verified catalog still lists it), unpolicied agents claim their whole catalog.
  • src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.test.tsx (new) — the attachment guard end-to-end through the real dispatcher: refuses on host-claimed commands, sends with attachments on passed-through ones.

…e agent

Claim what the host implements; pass through what the agent implements.
Claude's harness expands a slash command out of the message text, so the
host claimed catalog commands it had no way to run and answered "/init is
not available in chat sessions" for commands Claude does run. Codex's
app-server has no slash parser at all, so its catalog stays claimed —
except /goal, which the model carries out through its own goal tools.
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: ce46cc8b-8ce6-452a-b0b4-325f4cfd80c6

📥 Commits

Reviewing files that changed from the base of the PR and between cdec484 and eaf580e.

📒 Files selected for processing (1)
  • mobile/src/session/use-mobile-native-chat-controller.ts

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


📝 Walkthrough

Walkthrough

The change adds agent profile metadata for text-driven and harness-expanded slash commands. It adds helpers for text-driven and host-claimed commands. The structured composer uses the active agent to build menus and route host commands. The mobile send bridge applies agent-specific reconciliation. Tests cover command ownership, structured routing, unsupported commands, and attachment handling.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to eaf58

No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 12 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 main change: passing agent-implemented native chat slash commands through to the agent.
Description check ✅ Passed The description is detailed and on topic. It explains the behavior change, rationale, affected agents, visual results, tests, validation, and known mobile testing limitation. The required Linked Issue…
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.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch brennanb2025/native-chat-command-passthrough

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 new issues found.

Reviewed changes

  • Per-agent host-claim policy — native-chat-agent-profiles.ts adds expandsSlashCommandsFromText (Claude-family) and textDrivenCommands (Codex goal) and a new getHostClaimedNativeChatCommands that applies them.
  • Dispatcher consults the host-claimed set — structuredRecognizedCommands now unions the four host commands with getHostClaimedNativeChatCommands instead of the raw catalog, so /init /review /help (Claude) and /goal (Codex) reach the agent as text.
  • Attachment-guard contract made explicit — isStructuredAgentSessionComposerCommand now means "the host owns this command", with a doc comment stating it for the next caller.
  • Tests — new coverage for the profile policy, the dispatcher pass-through/refusal split, and the renderer attachment guard end-to-end.

The change is precisely scoped: for Codex the only behavioral delta is /goal (everything else in its catalog stays claimed and refused), and for Claude the only delta is the three catalog commands its harness genuinely implements. I verified the two load-bearing domain claims against the code — claudeDispatchInvokesSlashCommand already mirrors the SDK's "trailing / text runs a command" rule (comment says "verified against the real CLI over stream-json"), and the Codex structured turn is sent as raw turn/start input with no slash parse, with goal tool + thread/goal/* notifications supporting the model-owned-goal claim. The new tests assert exact values (not loose truthiness) and passed locally (34/34).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Codex reports no command catalog, so its structured `/` menu is the host
fallback -- which listed only the host's own commands and hid `/goal`, the
one command the model itself acts on. The picker now appends the profile's
text-driven commands, described from the curated catalog, so a command that
passes through is discoverable and not merely typable.

The menu invariant holds either way: a pick is answered by the host or run
by the agent, never refused with "not available in chat sessions".

@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 new issues found.

Reviewed changes

  • Text-driven command mirror — getTextDrivenNativeChatCommands in native-chat-agent-profiles.ts returns the catalog entries whose names are in the profile's textDrivenCommands, mirroring the claimed set.
  • Pick the offer for agent-run commands — structuredSlashCommands now takes an agent and appends the text-driven commands, so Codex's /goal is discoverable in the fallback / menu (Codex reports no catalog) and not merely typable.
  • Callers pass agent — both useNativeChatComposerCatalog and MobileNativeChatComposer thread the agent through so the menu matches the dispatcher's pass-through policy.
  • Tests — exact-value coverage for menu/dispatcher sync (every offered row is either host-answered or passes through), Claude non-regression, and Codex /goal discovery.

The change stays symmetric with the first commit's host-claim policy: getTextDrivenNativeChatCommands returns exactly the complement that getHostClaimedNativeChatCommands unclaims, so the offered-but-unclaimed set for Codex is precisely ['goal'] and the "menu pick is never refused" invariant holds. All four changed test files plus the desktop composer test pass locally (42/42 and 25/25).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@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 new issues found.

Reviewed changes

  • Per-agent host-command reconciliation on mobile — useMobileStructuredNativeChatSendBridge now takes an agent and computes isStructuredAgentSessionComposerCommand(text, agent) once, replacing the hardcoded union over 'codex' and 'claude'.
  • Agent threaded through the controller — useMobileNativeChatController passes activeChatResolution?.agent === 'claude' ? 'claude' : 'codex', mirroring the existing normalization in use-mobile-structured-agent-session.ts.
  • Tests — a new use-mobile-structured-native-chat-send-bridge.test.ts covers the optimistic echo for a passed-through /init, the unconfirmed-hold for /review on Claude, and the restored-draft path for a Codex host command.

The prior bridge checked whether either agent claimed a command, so a command Codex claims but Claude passes through (e.g. /init, /review, both present in both catalogs) was reconciled as a host command in a Claude session — no optimistic bubble on accepted, and a wrongly restored draft on unknown. Routing the check through the actual agent fixes that. The mapping is closed because structured sessions only resolve to claude or codex (isAgentSessionHandleProvider), and it matches the dispatch path's own agent === 'claude' ? 'claude' : 'codex' normalization. The new tests assert exact calls, and the first two fail against the old union logic, so they pin the fix rather than just observing it.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready

Final reviewed head: 7b590f8. The PR is mergeable, the branch is synchronized, and all current GitHub checks are green.

Meaningful fix made during review

The review found that mobile structured-send reconciliation classified slash commands against a union of provider catalogs instead of the active provider. That could suppress the optimistic echo for accepted Claude commands and mishandle uncertain sends. The branch now uses the same active-agent ownership policy as desktop and shared dispatch. The focused fix was pushed without expanding product scope.

Review and readiness verdict

  • Three same-model review passes are clean.
  • Opening and closing readiness audits found zero P0, P1, or P2 candidates.
  • The fix addresses the ownership-classification failure at the shared policy boundary; it is not a UI-only guard.
  • The existing session-reported catalog remains authoritative, with the curated profile catalog used only as the fallback.
  • No wire, RPC schema, persistence, migration, shell, path, Git-provider, or execution-boundary change.
  • Performance review found only bounded small-catalog scans on explicit sends or memoized picker construction; no polling, timers, listeners, subprocesses, extra RPCs, render fanout, or unbounded state.
  • The final main sync preserved the newer stream-liveness and turn-timing behavior and resolved the only merge conflict without changing command semantics.

Validation

  • 67 desktop/shared focused tests passed.
  • 43 mobile tests passed; mobile TypeScript passed.
  • 14 mixed-version wire tests passed.
  • Full pnpm tc passed.
  • Changed-code quality, type-aware checks, React Doctor, max-lines ratchet, focused performance lint, and git diff --check passed.
  • GitHub: Mobile Checks, PR Checks, PR test LoC, Windows/Linux packaging, static analysis, typecheck, and all eight test shards passed.

Rendered Electron evidence

Captured over hidden CDP with ORCA_BACKGROUND_LAUNCH=1. The capture preceded the final main sync; that sync preserved these command paths unchanged.

Claude /init is offered Claude receives and runs /init
Claude init picker Claude init running
Codex /goal is offered Codex receives the goal
Codex goal picker Codex goal running

Host-owned control: Codex /model remains host-handled and does not start a new agent response.

Codex model host command

QA limitations

  • The requested Grok Electron worker could not start because the provider reported a weekly quota limit. Hidden Electron CDP validation was completed as the fallback; no visible app window was focused or shown.
  • The native iOS app launched successfully in an iPhone 17 Pro simulator. End-to-end mobile command interaction remained blocked because the saved hosts were unreachable and the temporary pairing runtime timed out. No desktop interaction was substituted as mobile evidence.

@brennanb2025
brennanb2025 merged commit ecd7b19 into main Sep 11, 2026
29 checks passed
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