Skip to content

The agent that grows with you

fix(tui): an owner-refused slash command names itself instead of "unsupported_command"

Tekniumc9cb447c7559
diff --git a/ui-tui/src/__tests__/canonicalUnsupportedCommand.test.ts b/ui-tui/src/__tests__/canonicalUnsupportedCommand.test.ts
new file mode 100644
index 00000000000..ad244f40d75
--- /dev/null
+++ b/ui-tui/src/__tests__/canonicalUnsupportedCommand.test.ts
@@ -0,0 +1,44 @@
+import { JsonRpcGatewayError } from '@hermes/shared/json-rpc-channel'
+import { beforeEach, expect, it, vi } from 'vitest'
+
+import { createSlashHandler } from '../app/createSlashHandler.js'
+import { patchUiState, resetUiState } from '../app/uiStore.js'
+
+// The shared owner's slash.exec runs only its reviewed reads and refuses every other command with
+// `unsupported_command` (gateway/session_commands.py). Every Ink path that forwards a command there
+// (the generic fallback and the explicit slash-worker commands) must name the refusal like the
+// classic CLI, never print the bare wire reason.
+const flush = () => new Promise(resolve => setImmediate(resolve))
+
+beforeEach(() => {
+ resetUiState()
+ patchUiState({ sid: 'owner' })
+})
+
+it.each([
+ ['/config', 'config'],
+ ['/plugins enable foo', 'plugins'],
+ ['/pet toggle', 'pet']
+])('%s refused by the shared gateway names the command', async (cmd, name) => {
+ const request = vi.fn(async (method: string) => {
+ if (method === 'slash.exec' || method === 'command.dispatch') {
+ throw new JsonRpcGatewayError('unsupported_command', { code: 4001, data: { reason: 'unsupported_command' } })
+ }
+
+ return {}
+ })
+
+ const sys = vi.fn()
+
+ createSlashHandler({
+ composer: { enqueue: vi.fn() },
+ gateway: { gw: { isCanonical: true, request }, rpc: request },
+ local: { catalog: { canon: { [`/${name}`]: `/${name}` } }, getHistoryItems: () => [], getLastUserMsg: () => '' },
+ session: {},
+ slashFlightRef: { current: 0 },
+ transcript: { page: vi.fn(), panel: vi.fn(), send: vi.fn(), setHistoryItems: vi.fn(), sys }
+ } as never)(cmd)
+ await flush()
+
+ expect(sys.mock.calls.map(([line]) => String(line))).toEqual([`/${name} is not available on the shared gateway yet`])
+})
diff --git a/ui-tui/src/app/createSlashHandler.ts b/ui-tui/src/app/createSlashHandler.ts
index ee4117e9892..c7d30533578 100644
--- a/ui-tui/src/app/createSlashHandler.ts
+++ b/ui-tui/src/app/createSlashHandler.ts
@@ -12,7 +12,7 @@ import { findSlashCommand } from './slash/registry.js'
import type { SlashRunCtx } from './slash/types.js'
import { captureDestination, isCurrentDestination } from './submissionDestination.js'
import { getUiState } from './uiStore.js'
-import { describeSlashExecError, shouldFallbackToDispatch } from './userMessages.js'
+import { describeSlashExecError, isUnsupportedCommand, shouldFallbackToDispatch } from './userMessages.js'
/** Shared metrics count each user-typed command once, from the client: the gateway no longer
* counts slash.exec, so locally handled commands (/resume, /skin, overlays) land too.
@@ -59,7 +59,7 @@ export function createSlashHandler(ctx: SlashHandlerContext): SlashHandler {
const guardedErr = (e: unknown) => {
if (!stale()) {
- sys(`error: ${rpcErrorMessage(e)}`)
+ sys(isUnsupportedCommand(e) ? describeSlashExecError(parsed.name, e) : `error: ${rpcErrorMessage(e)}`)
}
}
@@ -209,6 +209,10 @@ export function createSlashHandler(ctx: SlashHandlerContext): SlashHandler {
// be shown as itself — the fallback's "not a quick/plugin/bundle/skill
// command" refusal used to bury the real cause and imply the command
// did not exist.
+ if (isUnsupportedCommand(execErr)) {
+ return sys(describeSlashExecError(parsed.name, execErr))
+ }
+
if (!shouldFallbackToDispatch(execErr)) {
sys(`error: ${describeSlashExecError(parsed.name, execErr)}`)
diff --git a/ui-tui/src/app/userMessages.ts b/ui-tui/src/app/userMessages.ts
index 70d4ce24f56..41d8645be76 100644
--- a/ui-tui/src/app/userMessages.ts
+++ b/ui-tui/src/app/userMessages.ts
@@ -171,11 +171,20 @@ export const describeRpcError = (err: unknown): string => {
return text
}
+/** The shared owner's slash.exec refuses every command outside its reviewed reads with
+ * `unsupported_command` (gateway/session_commands.py): name the command, as the classic CLI does. */
+export const isUnsupportedCommand = (err: unknown): boolean =>
+ (err as { data?: { reason?: string } } | null)?.data?.reason === 'unsupported_command'
+
/** The slash worker (built-in command helper) failed; name the command, not the helper. */
export const describeSlashExecError = (command: string, err: unknown): string => {
const { message } = rpcShape(err)
const text = message ?? ''
+ if (isUnsupportedCommand(err)) {
+ return t('canonical.controls.notAvailable', command)
+ }
+
if (/slash worker timed out/.test(text)) {
return t('userMessages.rpc.slashTimedOut', command)
}