The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): sort imports to satisfy perfectionist lint rule
StanleyStetson2ce63fc248e1
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.tsindex 4d99c6b6f42..7a319fdfdbe 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts@@ -2,8 +2,8 @@ import { useStore } from '@nanostores/react'import { type RefObject, useCallback, useEffect, useRef, useState } from 'react'import { useI18n } from '@/i18n'-import { triggerHaptic } from '@/lib/haptics'import { isSlashCommandText } from '@/lib/chat-runtime'+import { triggerHaptic } from '@/lib/haptics'import { useSessionSlice } from '@/lib/use-session-slice'import { type ComposerAttachment } from '@/store/composer'import { resetBrowseState } from '@/store/composer-input-history'diff --git a/apps/desktop/src/app/chat/session-tile-actions.ts b/apps/desktop/src/app/chat/session-tile-actions.tsindex ac7b01c42e6..22aac1d5100 100644--- a/apps/desktop/src/app/chat/session-tile-actions.ts+++ b/apps/desktop/src/app/chat/session-tile-actions.ts@@ -9,7 +9,6 @@*/import type { AppendMessage, ThreadMessage } from '@assistant-ui/react'-import { SLASH_COMMAND_RE } from '@hermes/shared'import { useCallback, useMemo, useRef } from 'react'import type { ClientSessionState } from '@/app/types'diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsxindex fdfadb5433d..0844a193915 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx@@ -5,6 +5,7 @@ import { useEffect, useRef } from 'react'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { getLatestSessionMessages, getSession } from '@/hermes'+import { en } from '@/i18n/en'import { textPart, toChatMessages } from '@/lib/chat-messages'import { createClientSessionState } from '@/lib/chat-runtime'import { $compactingSessions, setSessionCompacting } from '@/store/compaction'@@ -6288,6 +6289,52 @@ describe('usePromptActions stale multi-window guard (#65047)', () => {1_800_000)})++ it('refuses a slash command sent alongside an attachment instead of silently degrading to a chat message (#81798)', async () => {+ // The attachment's refText gets prepended ahead of the typed text by+ // buildContextText, so the merged wire text no longer starts with "/".+ // Before the fix, submitText's attachment-count gate silently fell through+ // to a normal prompt.submit — /goal (and every other slash command) with an+ // attachment vanished into a regular chat message with no feedback.+ const requestGateway = vi.fn(async (method: string) => {+ if (method === 'slash.exec') {+ throw new Error('slash.exec must never be called when an attachment is present')+ }++ if (method === 'prompt.submit') {+ throw new Error('prompt.submit must never be called for a slash command')+ }++ return {} as never+ })++ let handle: HarnessHandle | null = null+ await actRender(+ <Harness+ onReady={h => (handle = h)}+ refreshSessions={async () => undefined}+ requestGateway={requestGateway}+ />+ )++ const ok = await handle!.submitText('/goal align with the handoff doc', {+ attachments: [+ {+ id: 'file:handoff.md',+ kind: 'file',+ label: 'handoff.md',+ path: '/Users/alice/handoff.md',+ refText: '@file:`/Users/alice/handoff.md`'+ }+ ]+ })++ expect(ok).toBe(false)+ expect(requestGateway).not.toHaveBeenCalled()+ expect($notifications.get()).toEqual(+ expect.arrayContaining([expect.objectContaining({ message: en.desktop.slashCommandIgnoredBody })])+ )+ })})// The stale-closure suite above seeds the GLOBAL `$messages` mirror, whichdiff --git a/apps/desktop/src/lib/chat-runtime.test.ts b/apps/desktop/src/lib/chat-runtime.test.tsindex fe1fc9db6ec..21dd715ad79 100644--- a/apps/desktop/src/lib/chat-runtime.test.ts+++ b/apps/desktop/src/lib/chat-runtime.test.ts@@ -13,8 +13,6 @@ import {isSlashCommandText,messageCreatedAt,optimisticAttachmentRef,- parseCommandDispatch,- parseSlashCommand,personalityNamesFromConfig,stripAttachmentRefs,toRuntimeMessagediff --git a/apps/desktop/src/lib/chat-runtime.ts b/apps/desktop/src/lib/chat-runtime.tsindex cfd115e43c1..a55248d153a 100644--- a/apps/desktop/src/lib/chat-runtime.ts+++ b/apps/desktop/src/lib/chat-runtime.ts@@ -1,5 +1,6 @@import type { ThreadMessage } from '@assistant-ui/react'import type { ModelOptionsResult } from '@hermes/shared'+import { SLASH_COMMAND_RE } from '@hermes/shared'import type { QuickModelOption } from '@/app/chat/composer/types'import type { ClientSessionState } from '@/app/types'@@ -342,52 +343,6 @@ export function isSlashCommandText(text: string): boolean {return SLASH_COMMAND_RE.test(stripAttachmentRefs(text).trimStart())}-export function parseSlashCommand(command: string) {- // `[\s\S]*` (not `.*`): the arg may span newlines — `/goal <multi-line text>`- // or a skill command with a long pasted context. The old `.*$` regex failed- // the whole match on any newline, so every multiline slash command parsed as- // an empty name and got swallowed (#41323, #55510). The backend and CLI both- // split on any whitespace (`split(maxsplit=1)`), so this is the parity fix.- const match = command.replace(/^\/+/, '').match(/^(\S+)([\s\S]*)$/)-- return match ? { name: match[1], arg: match[2].trim() } : { name: '', arg: '' }-}--export function parseCommandDispatch(raw: unknown): CommandDispatchResponse | null {- if (!raw || typeof raw !== 'object') {- return null- }-- const row = raw as Record<string, unknown>- const str = (value: unknown) => (typeof value === 'string' ? value : undefined)-- switch (row.type) {- case 'exec':-- case 'plugin':- return { type: row.type, output: str(row.output) }-- case 'alias':- return typeof row.target === 'string' ? { type: 'alias', target: row.target } : null-- case 'skill':- return typeof row.name === 'string'- ? { type: 'skill', name: row.name, message: str(row.message), display: str(row.display) }- : null-- case 'send':- return typeof row.message === 'string'- ? { type: 'send', message: row.message, notice: str(row.notice), display: str(row.display) }- : null-- case 'prefill':- return typeof row.message === 'string' ? { type: 'prefill', message: row.message, notice: str(row.notice) } : null-- default:- return null- }-}-export function quickModelOptions(data: ModelOptionsResult | undefined,currentProvider: string,diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..5a362e69383--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+StanleyStetsondiff --git a/gateway/platforms/base.py b/gateway/platforms/base.pyindex dc7177c6eec..b403617076f 100644--- a/gateway/platforms/base.py+++ b/gateway/platforms/base.py@@ -1309,15 +1309,6 @@ 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]+\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@@ -1584,7 +1575,6 @@ async def cache_media_bytes_async()-@dataclassclass TextDebounceState:event: MessageEventdiff --git a/gateway/platforms/event.py b/gateway/platforms/event.pyindex 4e9faa40976..eef3a9d34a8 100644--- a/gateway/platforms/event.py+++ b/gateway/platforms/event.py@@ -4,6 +4,7 @@ A leaf module: adapters, helpers and the runner import it, so it must not importgateway.platforms.*."""+import refrom dataclasses import dataclass, fieldfrom datetime import datetimefrom enum import Enum@@ -11,6 +12,14 @@ from typing import Any, Dict, List, Optionalfrom gateway.session import SessionSource+# 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]+\n?)+", re.IGNORECASE)+class MessageType(Enum):"""Types of incoming messages."""@@ -103,15 +112,25 @@ class MessageEvent:if self.reply_expected is not True and other.reply_expected is not False:self.reply_expected = other.reply_expected+ def _command_text(self) -> str:+ """Return the message text with leading Desktop attachment refs stripped.++ Desktop's buildContextText prepends ``@image:<path>``, ``@file:<path>``,+ or ``@url:<url>`` tags before the user's visible text. Stripping these+ lets is_command / get_command / get_command_args work correctly even+ when the payload is prefixed with one or more media refs.+ """+ return _ATTACHMENT_REF_RE.sub("", (self.text or "").lstrip()).lstrip()+def is_command(self) -> bool:"""Check if this is a command message (e.g., /new, /reset)."""- return self.allow_gateway_control and (self.text or "").lstrip().startswith("/")+ return self.allow_gateway_control and self._command_text().startswith("/")def get_command(self) -> Optional[str]:"""Extract command name if this is a command message."""if not self.is_command():return None- raw = (self.text or "").lstrip().split(maxsplit=1)[0][1:].lower().split("@", 1)[0]+ raw = self._command_text().split(maxsplit=1)[0][1:].lower().split("@", 1)[0]# Reject file paths: valid command names never contain /return None if "/" in raw else raw@@ -119,7 +138,7 @@ class MessageEvent:"""Get the arguments after a command."""if not self.is_command():return self.text- parts = (self.text or "").lstrip().split(maxsplit=1)+ parts = self._command_text().lstrip().split(maxsplit=1)args = parts[1] if len(parts) > 1 else ""# iOS auto-corrects -- to — (em dash) and - to – (en dash)return args.replace("\u2014\u2014", "--").replace("\u2014", "--").replace("\u2013", "-")