Skip to content

fix(composer): allow slash-space messages#2316

Open
reidliu41 wants to merge 1 commit into
Hmbown:mainfrom
reidliu41:fix/slash-space-message
Open

fix(composer): allow slash-space messages#2316
reidliu41 wants to merge 1 commit into
Hmbown:mainfrom
reidliu41:fix/slash-space-message

Conversation

@reidliu41
Copy link
Copy Markdown
Contributor

@reidliu41 reidliu41 commented May 28, 2026

Summary

Fixes #2310.

CodeWhale currently treats any input that starts with / as a slash command. That means a user cannot send a normal message such as / hello; it is parsed as a command and fails with an unknown-command error.

This PR updates the slash-command classifier so / followed immediately by whitespace is treated as plain text. Normal commands such as /help and /model deepseek-v4-pro continue to work as before.
from: input / hi
image

to:
image

Testing

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features
  • cargo test --workspace --all-features

Checklist

  • Updated docs or comments as needed
  • [] Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes

Greptile Summary

This PR fixes a classifier bug where any input starting with / (slash followed by whitespace) was incorrectly treated as a slash command instead of plain text. The fix is a single guard added to looks_like_slash_command_input in app.rs.

  • Adds an early-return in looks_like_slash_command_input: if the character immediately after the leading / is whitespace, the function returns false, letting the input flow through as a normal message.
  • Extends the existing unit test with two new assertions covering "/ hello" and " / hello", confirming the new behaviour without touching any callers.

Confidence Score: 5/5

Safe to merge — the change is a minimal, well-tested guard that only affects the slash-space edge case and leaves all existing command paths intact.

The guard is inserted before any command-word parsing, so /help, /model …, and bare / all continue along the same code path as before. The only callers of looks_like_slash_command_input branch on its boolean result, so returning false for '/ hello' correctly routes it to the plain-message path in every call site.

No files require special attention.

Important Files Changed

Filename Overview
crates/tui/src/tui/app.rs Adds a whitespace guard in looks_like_slash_command_input so / hello-style inputs are treated as plain text, and extends the unit-test block with two matching assertions.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User presses Enter] --> B[submit_input]
    B --> C{looks_like_slash_command_input?}
    C -->|strip leading whitespace then strip '/' prefix → prefix absent| D[return false]
    C -->|next char is whitespace e.g. '/ hello'| E[return false — NEW]
    C -->|rest is empty e.g. bare '/'| F[return true]
    C -->|command word contains '/' e.g. absolute path| G[return false]
    C -->|command word is clean e.g. '/help'| H[return true]
    D --> I[Send as plain message, add to history]
    E --> I
    G --> I
    F --> J[execute_command_input]
    H --> J
Loading

Comments Outside Diff (1)

  1. crates/tui/src/tui/app.rs, line 5012 (link)

    P2 The test name slash_command_classifier_treats_absolute_path_as_message no longer describes the new cases ("/ hello", " / hello"), which are about slash-space messages rather than filesystem paths. A broader name would keep the intent clear for future readers.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

    Fix in Codex Fix in Claude Code Fix in Cursor

Fix All in Codex Fix All in Claude Code Fix All in Cursor

Reviews (1): Last reviewed commit: "fix(composer): allow slash-space message..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

  Treat inputs like `/ hello` as plain user messages instead of slash commands.
  This lets users start a message with a literal slash while preserving normal
  slash command behavior for `/help`, `/model ...`, and other commands.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the slash command input detection logic in crates/tui/src/tui/app.rs to ensure that a slash followed immediately by whitespace is not classified as a slash command, and adds corresponding unit tests. The reviewer suggested a more idiomatic Rust approach using starts_with(char::is_whitespace) instead of manually checking the first character.

Comment thread crates/tui/src/tui/app.rs
Comment on lines +89 to +91
if rest.chars().next().is_some_and(|ch| ch.is_whitespace()) {
return false;
}
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.

medium

Using rest.starts_with(char::is_whitespace) is more idiomatic and concise than extracting the first character and checking it with is_some_and.

Suggested change
if rest.chars().next().is_some_and(|ch| ch.is_whitespace()) {
return false;
}
if rest.starts_with(char::is_whitespace) {
return false;
}

Comment thread crates/tui/src/tui/app.rs
Comment on lines +5016 to +5017
assert!(!looks_like_slash_command_input("/ hello"));
assert!(!looks_like_slash_command_input(" / hello"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 The new guard only checks the very first character after /, so "/ hello" (tab) and "/ hello" (newline) are also deflected — that's probably intentional, but a tab case in the existing test block would make the contract explicit without adding overhead.

Suggested change
assert!(!looks_like_slash_command_input("/ hello"));
assert!(!looks_like_slash_command_input(" / hello"));
assert!(!looks_like_slash_command_input("/ hello"));
assert!(!looks_like_slash_command_input(" / hello"));
assert!(!looks_like_slash_command_input("/\thello"));

Fix in Codex Fix in Claude Code Fix in Cursor

@reidliu41
Copy link
Copy Markdown
Contributor Author

hi @Hmbown please help to take a look when you have time. thanks.

Copy link
Copy Markdown
Owner

Hmbown commented May 28, 2026

will do - thanks as always 🙂

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.

Cannot start message with / (no escape for leading slash)

2 participants