Skip to content

The agent that grows with you

fix(desktop): warn user when slash command sent with attachment

StanleyStetson1fa92e6cb54e
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
index f0a8457495d..8f7500b231b 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
@@ -3,12 +3,14 @@ import { type RefObject, useLayoutEffect, useRef } from 'react'
import { usePaneVisible } from '@/components/pane-shell/pane-visibility'
import { isSideTaskSlashCommand } from '@/lib/desktop-slash-commands'
+import { useI18n } from '@/i18n'
import { triggerHaptic } from '@/lib/haptics'
import { hasClarifyRequest, skipClarifyRequest } from '@/store/clarify'
import { clearSessionDraft, type ComposerAttachment, isFreshDraftScope } from '@/store/composer'
import { resetBrowseState } from '@/store/composer-input-history'
import { enqueueQueuedPrompt, type QueuedPromptEntry } from '@/store/composer-queue'
import { hasConnectionRequest, skipConnectionRequest } from '@/store/connection-request'
+import { notify } from '@/store/notifications'
import { hasBlockingPromptRequest } from '@/store/prompts'
import { cloneAttachments, type QueueEditState } from '../composer-utils'
@@ -83,6 +85,8 @@ export function useComposerSubmit({
const paneVisible = usePaneVisible()
const scope = useComposerScope()
const surfaceId = useComposerSurfaceId()
+ const { t } = useI18n()
+ const copy = t.desktop
// Shared send primitive: fire onSubmit, and if the gateway rejects (accepted
// === false) or throws, re-stash the draft so the words survive. Repaint it
@@ -286,7 +290,20 @@ export function useComposerSubmit({
// busy guard for commands that genuinely need an idle session (skill
// /send directives). Queuing them would make every slash command wait
// for the current turn to finish, which is how the TUI never behaves.
- if (!attachments.length && SLASH_COMMAND_RE.test(text.trim())) {
+ if (SLASH_COMMAND_RE.test(text.trim())) {
+ if (attachments.length) {
+ // Slash commands cannot ride alongside attachments — warn the user
+ // instead of silently queuing the payload (which would then reach the
+ // idle path and be submitted as plain text with no command execution).
+ notify({
+ kind: 'warning',
+ title: copy.slashCommandIgnoredTitle,
+ message: copy.slashCommandIgnoredBody
+ })
+
+ return
+ }
+
triggerHaptic('submit')
clearDraft()
dispatchSubmit(text)
diff --git a/apps/desktop/src/app/chat/session-tile-actions.ts b/apps/desktop/src/app/chat/session-tile-actions.ts
index 3def34d542a..257030a483f 100644
--- a/apps/desktop/src/app/chat/session-tile-actions.ts
+++ b/apps/desktop/src/app/chat/session-tile-actions.ts
@@ -20,7 +20,7 @@ import { triggerHaptic } from '@/lib/haptics'
import { clearClarifyRequest } from '@/store/clarify'
import type { ComposerAttachment } from '@/store/composer'
import { resetSessionBackground } from '@/store/composer-status'
-import { notifyError } from '@/store/notifications'
+import { notify, notifyError } from '@/store/notifications'
import { clearPreviewArtifacts } from '@/store/preview-status'
import { clearAllPrompts } from '@/store/prompts'
import { $sessions, knownSessionOwner, ownerLookupSessionRows, sessionMatchesStoredId } from '@/store/session'
@@ -325,7 +325,17 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, stored
listTileSession(visibleText)
- if (!attachments.length && SLASH_COMMAND_RE.test(visibleText)) {
+ if (SLASH_COMMAND_RE.test(visibleText)) {
+ if (attachments.length) {
+ notify({
+ kind: 'warning',
+ title: copy.slashCommandIgnoredTitle,
+ message: copy.slashCommandIgnoredBody
+ })
+
+ return false
+ }
+
triggerHaptic('selection')
await sessionTileDelegate()?.executeSlash(visibleText, runtimeIdRef.current)
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
index 4b935460d04..bd272d65ad0 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
@@ -632,7 +632,17 @@ export function usePromptActions({
const visibleText = sanitizeComposerInput(rawText).trim()
const attachments = options?.attachments ?? $composerAttachments.get()
- if (!attachments.length && SLASH_COMMAND_RE.test(visibleText)) {
+ if (SLASH_COMMAND_RE.test(visibleText)) {
+ if (attachments.length) {
+ notify({
+ kind: 'warning',
+ title: copy.slashCommandIgnoredTitle,
+ message: copy.slashCommandIgnoredBody
+ })
+
+ return false
+ }
+
triggerHaptic('selection')
// Forward the explicit target (background queue drain, tile) — dropping
// it ran the command against whatever chat happened to be in front.
diff --git a/apps/desktop/src/i18n/ar_chat.ts b/apps/desktop/src/i18n/ar_chat.ts
index bd690bf80a7..910adb3e24f 100644
--- a/apps/desktop/src/i18n/ar_chat.ts
+++ b/apps/desktop/src/i18n/ar_chat.ts
@@ -391,6 +391,8 @@ export const arChat = {
'كانت هذه النافذة متأخرة عن عرض آخر لنفس المحادثة. تم تحميل أحدث الرسائل. أعد الإرسال إذا كنت لا تزال تريد ذلك.',
providerCredentialRequired: 'مطلوب اعتماد المزود',
emptySlashCommand: 'أمر slash فارغ',
+ slashCommandIgnoredTitle: 'لم يتم إرسال الأمر',
+ slashCommandIgnoredBody: 'لا يمكن دمج أوامر slash مع المرفقات. أزل المرفق أو أرسل الأمر بشكل منفصل.',
desktopCommands: 'أوامر سطح المكتب',
skillCommandsAvailable: count => `${count} أمر مهارة متاح`,
warningLine: message => `تحذير: ${message}`,
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 242b6f6dcdd..8b6b514b8e2 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -5529,6 +5529,9 @@ export const en: Translations = {
'This window was behind another view of the same chat. Latest messages were loaded. Send again if you still want to.',
providerCredentialRequired: 'Add a provider credential before sending your first message.',
emptySlashCommand: 'empty slash command',
+ slashCommandIgnoredTitle: 'Command not sent',
+ slashCommandIgnoredBody:
+ 'Slash commands cannot be combined with attachments. Remove the attachment or send the command separately.',
desktopCommands: 'Desktop commands',
skillCommandsAvailable: count => `${count} skill commands available.`,
warningLine: message => `warning: ${message}`,
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 8c6349ca18a..0ece6d564a3 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -4123,6 +4123,9 @@ export const ja = defineLocale({
'このウィンドウは同じチャットの別ビューより遅れています。最新のメッセージを読み込みました。送信する場合はもう一度送ってください。',
providerCredentialRequired: '最初のメッセージを送信する前にプロバイダー認証情報を追加してください。',
emptySlashCommand: '空のスラッシュコマンド',
+ slashCommandIgnoredTitle: 'コマンドが送信されませんでした',
+ slashCommandIgnoredBody:
+ 'スラッシュコマンドと添付ファイルを同時に使用することはできません。添付ファイルを削除するか、コマンドを別途送信してください。',
desktopCommands: 'デスクトップコマンド',
skillCommandsAvailable: count => `${count} 件のスキルコマンドが利用可能です。`,
warningLine: message => `警告: ${message}`,
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 57054a40260..aa3b04df59e 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -4591,6 +4591,8 @@ export interface Translations {
staleSessionBody: string
providerCredentialRequired: string
emptySlashCommand: string
+ slashCommandIgnoredTitle: string
+ slashCommandIgnoredBody: string
desktopCommands: string
skillCommandsAvailable: (count: number) => string
warningLine: (message: string) => string
diff --git a/apps/desktop/src/i18n/zh-hant_chat.ts b/apps/desktop/src/i18n/zh-hant_chat.ts
index 80537a4fec8..1469fd0186a 100644
--- a/apps/desktop/src/i18n/zh-hant_chat.ts
+++ b/apps/desktop/src/i18n/zh-hant_chat.ts
@@ -415,6 +415,8 @@ export const zhHantChat = {
staleSessionBody: '此視窗落後於同一對話的其他視窗。已載入最新訊息。若仍要傳送請再試一次。',
providerCredentialRequired: '傳送第一則訊息前請先新增提供方憑證。',
emptySlashCommand: '空的斜線指令',
+ slashCommandIgnoredTitle: '指令未傳送',
+ slashCommandIgnoredBody: '斜線指令不能與附件同時使用。請移除附件或單獨傳送指令。',
desktopCommands: '桌面端指令',
skillCommandsAvailable: count => `${count} 個技能指令可用。`,
warningLine: message => `警告:${message}`,
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index e82d91a125a..2ee20a25730 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -5079,6 +5079,8 @@ export const zh = defineLocale({
staleSessionBody: '此窗口落后于同一对话的其他窗口。已加载最新消息。若仍要发送请再试一次。',
providerCredentialRequired: '发送第一条消息前请先添加提供方凭据。',
emptySlashCommand: '空 slash 命令',
+ slashCommandIgnoredTitle: '命令未发送',
+ slashCommandIgnoredBody: 'Slash 命令不能与附件同时使用。请移除附件或单独发送命令。',
desktopCommands: '桌面端命令',
skillCommandsAvailable: count => `${count} 个技能命令可用。`,
warningLine: message => `警告:${message}`,
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
deleted file mode 100644
index 5a362e69383..00000000000
--- a/contributors/emails/[email protected]
+++ /dev/null
@@ -1 +0,0 @@
-StanleyStetson
diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py
index b403617076f..6c735e80b8b 100644
--- a/gateway/platforms/base.py
+++ b/gateway/platforms/base.py
@@ -1309,6 +1309,15 @@ MEDIA_EXTENSIONLESS_TAG_RE = re.compile(
r'''[`"'*_]{0,3}\s*''',
re.IGNORECASE)
+# Desktop attachment reference tags prepended by buildContextText before the
+# user's visible text (e.g. "@image:/tmp/foo.png\n\n/moa ask something").
+# Strip these when detecting slash commands so a media-ref prefix does not hide
+# a slash token from MessageEvent.is_command() / get_command().
+# The pattern matches to end-of-line (not just whitespace-bounded) to handle
+# Windows paths that may contain spaces (e.g. "C:\Users\John Doe\image.png").
+_ATTACHMENT_REF_RE = re.compile(r"@(?:image|file|url):[^\n@]+", re.IGNORECASE)
+
+
def _match_extensionless_path(scan_text: str, match: "re.Match") -> Optional[Tuple[str, int]]:
"""Extensionless MEDIA tag match -> validated on-disk ``(safe_path, end_offset)`` or None: the
@@ -1575,6 +1584,7 @@ async def cache_media_bytes_async(
)
+
@dataclass
class TextDebounceState:
event: MessageEvent
diff --git a/tests/gateway/test_platform_base.py b/tests/gateway/test_platform_base.py
index 52dcccdc20e..41c7e3e0da5 100644
--- a/tests/gateway/test_platform_base.py
+++ b/tests/gateway/test_platform_base.py
@@ -85,6 +85,30 @@ class TestMessageEventIsCommand:
event = MessageEvent(text="/new")
assert event.is_command() is True
+ def test_slash_command_with_image_ref_prefix(self):
+ """Desktop buildContextText prepends @image: refs before the visible text.
+ is_command() must still detect the slash command after the ref."""
+ event = MessageEvent(text="@image:/tmp/screenshot.png\n\n/moa what is this?")
+ assert event.is_command() is True
+
+ def test_slash_command_with_image_ref_spaces_in_path(self):
+ """Image refs with Windows spaces (e.g. C:\\Users\\John Doe\\img.png) must be correctly stripped."""
+ event = MessageEvent(text="@image:C:\\Users\\John Doe\\My Pictures\\photo.png\n\n/moa what is this?")
+ assert event.is_command() is True
+
+ def test_slash_command_with_file_ref_prefix(self):
+ event = MessageEvent(text="@file:/tmp/report.pdf\n\n/compress")
+ assert event.is_command() is True
+
+ def test_slash_command_with_url_ref_prefix(self):
+ event = MessageEvent(text="@url:https://example.com\n\n/status")
+ assert event.is_command() is True
+
+ def test_non_command_with_image_ref(self):
+ """A regular message (no slash command) with an image ref must NOT be detected as a command."""
+ event = MessageEvent(text="@image:/tmp/foo.png\n\nwhat is this?")
+ assert event.is_command() is False
+
class TestMessageEventGetCommand:
def test_simple_command(self):
@@ -99,6 +123,11 @@ class TestMessageEventGetCommand:
event = MessageEvent(text="hello")
assert event.get_command() is None
+ def test_get_command_with_image_ref_prefix(self):
+ """get_command() must parse the command name even when prefixed with a Desktop media ref."""
+ event = MessageEvent(text="@image:/tmp/foo.png\n\n/moa something interesting")
+ assert event.get_command() == "moa"
+
class TestMessageEventGetCommandArgs:
def test_command_with_args(self):