Skip to content

The agent that grows with you

fix(tui): staged images survive a skill or alias slash submit

teknium1109987a5d4a5
diff --git a/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx b/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
index eb1102e5591..4576f566b4c 100644
--- a/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
+++ b/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
@@ -14,7 +14,7 @@ import { useSubmission } from '../app/useSubmission.js'
const flush = () => new Promise<void>(resolve => setImmediate(resolve))
-function mount(canonical = false) {
+function mount(canonical = false, extra: (method: string, params: any) => unknown = () => undefined) {
const home = mkdtempSync(join(tmpdir(), 'ink-slash-attachment-'))
vi.stubEnv('HERMES_HOME', home)
resetUiState()
@@ -23,6 +23,10 @@ function mount(canonical = false) {
const pending: Array<{ sid: string; finish: (path: string) => void }> = []
const request = vi.fn((method: string, params: any) => {
+ const handled = extra(method, params)
+
+ if (handled !== undefined) { return Promise.resolve(handled) }
+
if (method === 'prompt.submit' && canonical) { return Promise.resolve({ status: 'started' }) }
if (method === 'image.attach' || method === 'clipboard.paste') {
@@ -58,7 +62,7 @@ function mount(canonical = false) {
composer = useComposerState({ gw, submitRef, sys })
submission = useSubmission({ gw, submitRef, slashRef, sys, composerActions: composer.actions,
composerRefs: composer.refs, composerState: composer.state, appendMessage: vi.fn(), setLastUserMsg: vi.fn() })
- slashRef.current = createSlashHandler({ gateway: { gw }, local: {}, transcript: { sys },
+ slashRef.current = createSlashHandler({ gateway: { gw }, local: {}, transcript: { sys, send: submission.send },
composer: composer.actions, slashFlightRef } as any)
return <Text>{composer.state.input}</Text>
@@ -187,3 +191,26 @@ it('stale attachment cleanup uses its captured owner and preserves a concurrent
}
}
})
+
+it('a skill slash command keeps the staged image descriptors through the expanded skill send', async () => {
+ const skill = (method: string, params: any) => method === 'slash.exec'
+ ? { type: 'skill', name: 'review', message: `SKILL BODY\n\nUser request: ${params.command.replace(/^review\s*/, '')}`, display: `/${params.command}` }
+ : undefined
+ const h = mount(true, skill)
+ vi.stubEnv('HERMES_TUI_GATEWAY_URL', '')
+ const path = join(h.home, 'shot.png')
+ writeFileSync(path, Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wl2nL8AAAAASUVORK5CYII=', 'base64'))
+
+ try {
+ await h.submit(`/image ${path}`)
+ await vi.waitFor(() => expect(h.composer.state.input).toContain('[[ Image 1 ]]'))
+ const token = h.composer.refs.tokensRef.current[0]!
+ await h.submit('/review this screenshot [[ Image 1 ]]')
+ await vi.waitFor(() => expect(h.request.mock.calls.some(([method]) => method === 'prompt.submit')).toBe(true))
+ const wire = h.request.mock.calls.find(([method]) => method === 'prompt.submit')![1]
+ expect(wire.attachments).toEqual([{ path: token.path, mime: 'image/png' }])
+ expect(wire.text).toContain('SKILL BODY')
+ expect(wire.text).not.toContain('[[ Image')
+ expect(h.composer.refs.tokensRef.current).toEqual([])
+ } finally { h.close() }
+})
diff --git a/ui-tui/src/app/createSlashHandler.ts b/ui-tui/src/app/createSlashHandler.ts
index 41dc93ec3c5..c9dbdb3dc4b 100644
--- a/ui-tui/src/app/createSlashHandler.ts
+++ b/ui-tui/src/app/createSlashHandler.ts
@@ -4,19 +4,19 @@ import { asCommandDispatch, rpcErrorMessage } from '../lib/rpc.js'
import { launchWidget } from '../sdk/host.js'
import { getWidgetApp } from '../sdk/registry.js'
-import type { SlashHandlerContext } from './interfaces.js'
+import type { SlashHandler, SlashHandlerContext, SlashSubmission } from './interfaces.js'
import { scoreSlashMenuItem } from './slash/fuzzyScore.js'
import { findSlashCommand } from './slash/registry.js'
import type { SlashRunCtx } from './slash/types.js'
import { captureDestination, isCurrentDestination } from './submissionDestination.js'
import { getUiState } from './uiStore.js'
-export function createSlashHandler(ctx: SlashHandlerContext): (cmd: string) => boolean {
+export function createSlashHandler(ctx: SlashHandlerContext): SlashHandler {
const { gw } = ctx.gateway
const { catalog } = ctx.local
const { page, send, sys } = ctx.transcript
- const handler = (cmd: string): boolean => {
+ const handler = (cmd: string, submission?: SlashSubmission): boolean => {
const flight = ++ctx.slashFlightRef.current
const ui = getUiState()
const sid = ui.sid
@@ -69,7 +69,7 @@ export function createSlashHandler(ctx: SlashHandlerContext): (cmd: string) => b
if (exact) {
if (exact.toLowerCase() !== needle) {
- return handler(`${exact}${argTail}`)
+ return handler(`${exact}${argTail}`, submission)
}
} else {
// Tiered name scoring (ported from grok-cli's slash menu): prefix
@@ -87,7 +87,7 @@ export function createSlashHandler(ctx: SlashHandlerContext): (cmd: string) => b
const matches = [...new Set(scored.filter(entry => entry.score === best).map(entry => entry.canon))]
if (matches.length === 1 && matches[0]!.toLowerCase() !== needle) {
- return handler(`${matches[0]}${argTail}`)
+ return handler(`${matches[0]}${argTail}`, submission)
}
if (matches.length > 1) {
@@ -110,7 +110,7 @@ export function createSlashHandler(ctx: SlashHandlerContext): (cmd: string) => b
}
if (d.type === 'alias') {
- return void handler(`/${d.target}${argTail}`)
+ return void handler(`/${d.target}${argTail}`, submission)
}
// A skill/bundle dispatch's `message` is the expanded skill body —
@@ -120,9 +120,10 @@ export function createSlashHandler(ctx: SlashHandlerContext): (cmd: string) => b
// the TUI spawns its gateway from this same checkout, so the two can't
// version-skew (unlike the desktop, which can meet an older backend).
const sendDispatch = (display: string | undefined, message: string) => {
- const shown = display?.trim()
+ const shown = display?.trim() || undefined
+ const attachments = submission?.attachments.length ? { attachments: submission.attachments } : undefined
- return shown ? send(message, true, shown) : send(message)
+ return send(message, true, shown, submission?.expand, attachments)
}
if (d.type === 'skill') {
diff --git a/ui-tui/src/app/interfaces.ts b/ui-tui/src/app/interfaces.ts
index 673ed3376ad..9b0b55f5eb7 100644
--- a/ui-tui/src/app/interfaces.ts
+++ b/ui-tui/src/app/interfaces.ts
@@ -524,6 +524,19 @@ export interface GatewayEventHandlerContext {
}
}
+/**
+ * What a slash command's composer held at submit time. A skill or alias
+ * eventually sends ordinary user text, so the staged image descriptors and the
+ * token expander travel with the command instead of dying with the cleared
+ * composer.
+ */
+export interface SlashSubmission {
+ attachments: Array<{ path: string; mime: string }>
+ expand: (text: string) => string
+}
+
+export type SlashHandler = (cmd: string, submission?: SlashSubmission) => boolean
+
export interface SlashHandlerContext {
composer: {
attachClipboardImage: () => void
@@ -558,7 +571,8 @@ export interface SlashHandlerContext {
transcript: {
page: (text: string, title?: string) => void
panel: (title: string, sections: PanelSection[]) => void
- send: (text: string, showUserMessage?: boolean, displayText?: string) => void
+ send: (text: string, showUserMessage?: boolean, displayText?: string, expandOverride?: (value: string) => string,
+ submitOpts?: { attachments?: Array<{ path: string; mime: string }> }) => void
setHistoryItems: StateSetter<Msg[]>
sys: (text: string) => void
trimLastExchange: (items: Msg[]) => Msg[]
diff --git a/ui-tui/src/app/useMainApp.ts b/ui-tui/src/app/useMainApp.ts
index fbce79da1ba..2e5ad208cb0 100644
--- a/ui-tui/src/app/useMainApp.ts
+++ b/ui-tui/src/app/useMainApp.ts
@@ -52,7 +52,7 @@ import { createGatewayEventHandler } from './createGatewayEventHandler.js'
import { createSlashHandler } from './createSlashHandler.js'
import { planGatewayRecovery } from './gatewayRecovery.js'
import { getInputSelection } from './inputSelectionStore.js'
-import { type GatewayRpc, type StateSetter, type TranscriptRow } from './interfaces.js'
+import { type GatewayRpc, type SlashHandler, type StateSetter, type TranscriptRow } from './interfaces.js'
import { $overlayState, capturePromptResponseGuard, patchOverlayState } from './overlayStore.js'
import { $goodVibesTick } from './petFlashStore.js'
import { scrollWithSelectionBy } from './scroll.js'
@@ -234,7 +234,7 @@ export function useMainApp(gw: GatewayClient) {
)
const slashFlightRef = useRef(0)
- const slashRef = useRef<(cmd: string) => boolean>(() => false)
+ const slashRef = useRef<SlashHandler>(() => false)
const colsRef = useRef(cols)
const scrollRef = useRef<null | ScrollBoxHandle>(null)
const onEventRef = useRef<(ev: GatewayEvent) => void>(() => {})
diff --git a/ui-tui/src/app/useSubmission.ts b/ui-tui/src/app/useSubmission.ts
index e3f36ca1f0e..702b09e47cd 100644
--- a/ui-tui/src/app/useSubmission.ts
+++ b/ui-tui/src/app/useSubmission.ts
@@ -11,7 +11,7 @@ import { asRpcResult } from '../lib/rpc.js'
import { hasInterpolation, INTERPOLATION_RE } from '../protocol/interpolation.js'
import type { Msg } from '../types.js'
-import type { ComposerActions, ComposerRefs, ComposerState, ComposerToken } from './interfaces.js'
+import type { ComposerActions, ComposerRefs, ComposerState, ComposerToken, SlashHandler } from './interfaces.js'
import { submitPrompt } from './submissionCore.js'
import { captureDestination, isCurrentDestination, type SubmissionDestination } from './submissionDestination.js'
import { turnController } from './turnController.js'
@@ -333,7 +333,9 @@ export function useSubmission(opts: UseSubmissionOptions) {
if (retained) { retained.attachments = submission.attachments; savePendingInput(retained) }
sys(`queued: "${queued.display.slice(0, 50)}${queued.display.length > 50 ? '…' : ''}"`)
} else {
- slashRef.current(slash.command)
+ // Image tokens are labels in the command; the descriptors and their
+ // expander ride along so a skill/alias send still carries the image.
+ slashRef.current(slash.command, { attachments: submission.attachments, expand: expandTokens(submissionTokens) })
}
return
@@ -499,7 +501,7 @@ export interface UseSubmissionOptions {
composerState: ComposerState
gw: GatewayClient
setLastUserMsg: (value: string) => void
- slashRef: MutableRefObject<(cmd: string) => boolean>
+ slashRef: MutableRefObject<SlashHandler>
submitRef: MutableRefObject<(value: string) => void>
sys: (text: string) => void
}