Skip to content

The agent that grows with you

fix(desktop): render a skill send as its invocation everywhere it surfaces

Brooklyn Nicholson20b2022b8c6b
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.ts
index dff3804bb69..e1bb5442fef 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
@@ -106,7 +106,9 @@ export function useComposerQueue({
entryId: entry.id,
sessionKey: activeQueueSessionKey
})
- loadIntoComposer(entry.text, entry.attachments)
+ // Edit what the panel SHOWS. A queued `/skill` entry's text is the
+ // expanded skill body — never drop that into the composer.
+ loadIntoComposer(entry.displayText ?? entry.text, entry.attachments)
triggerHaptic('selection')
focusInput()
}
@@ -135,7 +137,7 @@ export function useComposerQueue({
if (next) {
setQueueEditSnapshot({ ...queueEdit, entryId: next.id })
- loadIntoComposer(next.text, next.attachments)
+ loadIntoComposer(next.displayText ?? next.text, next.attachments)
} else {
setQueueEditSnapshot(null)
loadIntoComposer(queueEdit.draft, queueEdit.attachments)
@@ -213,6 +215,7 @@ export function useComposerQueue({
const accepted = await Promise.resolve(
onSubmit(entry.text, {
attachments: entry.attachments,
+ ...(entry.displayText ? { displayText: entry.displayText } : {}),
fromQueue: true,
sessionId: drainRuntimeSessionId,
storedSessionId: drainQueueSessionKey
diff --git a/apps/desktop/src/app/chat/composer/queue-panel.tsx b/apps/desktop/src/app/chat/composer/queue-panel.tsx
index 591eeb10ebb..2f5612efd13 100644
--- a/apps/desktop/src/app/chat/composer/queue-panel.tsx
+++ b/apps/desktop/src/app/chat/composer/queue-panel.tsx
@@ -22,7 +22,7 @@ interface QueuePanelProps {
}
const entryPreview = (entry: QueuedPromptEntry, c: Translations['composer']) =>
- entry.text.trim() || (entry.attachments.length > 0 ? c.attachmentOnly : c.emptyTurn)
+ (entry.displayText ?? entry.text).trim() || (entry.attachments.length > 0 ? c.attachmentOnly : c.emptyTurn)
export function QueuePanel({
busy,
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.tsx
index c9cd19c6406..6bf51c1e0fc 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
@@ -1215,9 +1215,9 @@ describe('usePromptActions slash.exec dispatch payloads', () => {
it("sends a skill's kickoff into the TAB that invoked it, not the foreground chat", async () => {
// `/work` in a fresh ⌘T tab: slash.exec returns a skill dispatch whose
// `message` is the kickoff prompt. The dispatcher resolved the tab as its
- // target, printed "⚡ loading skill" there — then submitted the kickoff
- // with no target at all, so submit re-resolved from activeSessionIdRef and
- // fired it as a user message into whatever conversation was on screen.
+ // target, then submitted the kickoff with no target at all, so submit
+ // re-resolved from activeSessionIdRef and fired it as a user message into
+ // whatever conversation was on screen.
const tabRuntimeId = 'tab-runtime'
const tabStoredId = 'tab-stored'
@@ -1262,6 +1262,56 @@ describe('usePromptActions slash.exec dispatch payloads', () => {
$queuedPromptsBySession.set({})
})
+ it('renders a skill turn as its invocation — the expanded body never reaches a bubble', async () => {
+ // A `/skill` dispatch's `message` is the whole skill body (model-facing
+ // scaffolding). The agent must receive it verbatim; every UI surface —
+ // the user bubble and any system line — must show only `/work fix it`.
+ const skillBody =
+ '[IMPORTANT: The user has invoked the "work" skill, indicating they want you to follow its instructions.\n' +
+ 'The full skill content is loaded below.]\n\nSPIN UP A WORKTREE, never the primary checkout.\n\n' +
+ 'The user has provided the following instruction alongside the skill invocation: fix it'
+
+ const states: Record<string, unknown>[] = []
+ const submitted: (Record<string, unknown> | undefined)[] = []
+
+ const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
+ if (method === 'prompt.submit') {
+ submitted.push(params)
+ }
+
+ return (
+ method === 'slash.exec' ? { type: 'skill', name: 'work', message: skillBody, display: '/work fix it' } : {}
+ ) as never
+ })
+
+ let handle: HarnessHandle | null = null
+ await actRender(
+ <Harness
+ onReady={h => (handle = h)}
+ onSeedState={s => states.push(s)}
+ refreshSessions={async () => undefined}
+ requestGateway={requestGateway}
+ />
+ )
+
+ await handle!.submitText('/work fix it')
+
+ // The agent still gets the full skill.
+ expect(submitted).toEqual([expect.objectContaining({ text: skillBody })])
+
+ const rendered = states.flatMap(state => {
+ const messages = Array.isArray(state.messages)
+ ? (state.messages as Array<{ parts?: Array<{ text?: string }> }>)
+ : []
+
+ return messages.flatMap(message => (message.parts ?? []).map(part => part.text ?? ''))
+ })
+
+ expect(rendered).toContain('/work fix it')
+ expect(rendered.join('\n')).not.toContain('SPIN UP A WORKTREE')
+ expect(rendered.join('\n')).not.toContain('IMPORTANT: The user has invoked')
+ })
+
it('slash status header carries the command token, not the full invocation', async () => {
// `/goal <long prose>` used to echo the entire invocation in the mono
// header AND the goal text again in the backend notice right under it.
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
index c70e6977c0a..5bfccf1be7a 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
@@ -1,5 +1,7 @@
import { type MutableRefObject, useCallback, useRef } from 'react'
+import { dispatchDisplayText } from '@hermes/shared'
+
import { getProfiles } from '@/hermes'
import type { Translations } from '@/i18n'
import { type ChatMessage, toChatMessages } from '@/lib/chat-messages'
@@ -264,9 +266,10 @@ export function useSlashCommand(deps: SlashCommandDeps) {
return
}
- if (dispatch.type === 'skill') {
- renderSlashOutput(`⚡ loading skill: ${dispatch.name}`)
- }
+ // A skill/bundle dispatch's `message` is the expanded skill body —
+ // model-facing scaffolding. Never render it; the bubble shows the
+ // invocation instead.
+ const displayText = dispatchDisplayText('display' in dispatch ? dispatch.display : undefined, message)
// Gate on the TARGET session's own busy state, not the foreground
// view's — see isTargetSessionBusy. `busyRef` mirrors whatever chat
@@ -286,7 +289,7 @@ export function useSlashCommand(deps: SlashCommandDeps) {
// whichever chat is now in front.
const queueKey = resolveComposerSessionKey(storedSessionId, $sessions.get()) || storedSessionId || sessionId
- if (enqueueQueuedPrompt(queueKey, { attachments: [], text: message })) {
+ if (enqueueQueuedPrompt(queueKey, { attachments: [], text: message, displayText })) {
renderSlashOutput('session busy — message queued to send when the current turn finishes')
} else {
renderSlashOutput('session busy — /interrupt the current turn before sending this command')
@@ -299,12 +302,11 @@ export function useSlashCommand(deps: SlashCommandDeps) {
// same pair the output writer and the busy gate above already use.
// Bare `submitPromptText(message)` let submit re-resolve from
// `activeSessionIdRef`, which names the FOREGROUND chat: a `/work`
- // typed into a fresh ⌘T tab loaded the skill in that tab, printed
- // "⚡ loading skill" there, then fired its kickoff as a user message
- // into whatever conversation was on screen. Every other target the
- // dispatcher serves (tile, background queue drain, a session created
- // by this very call) had the same leak.
- await submitPromptText(message, { sessionId, storedSessionId })
+ // typed into a fresh ⌘T tab loaded the skill in that tab, then fired
+ // its kickoff as a user message into whatever conversation was on
+ // screen. Every other target the dispatcher serves (tile, background
+ // queue drain, a session created by this very call) had the same leak.
+ await submitPromptText(message, { sessionId, storedSessionId, displayText })
}
try {
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts
index d8988a0c926..33b6ab4c33e 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts
@@ -268,10 +268,16 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {
const optimisticId = `user-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
+ // What the bubble shows. A `/skill` send carries the whole expanded
+ // skill body as its text — model-facing scaffolding — so the dispatcher
+ // hands us the invocation to render instead. Everything else shows what
+ // was typed.
+ const bubbleText = options?.displayText ?? visibleText
+
const buildUserMessage = (): ChatMessage => ({
id: optimisticId,
role: 'user',
- parts: [textPart(visibleText || (attachmentRefs.length ? '' : attachments.map(a => a.label).join(', ')))],
+ parts: [textPart(bubbleText || (attachmentRefs.length ? '' : attachments.map(a => a.label).join(', ')))],
attachmentRefs
})
@@ -466,7 +472,7 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {
if (!sessionId) {
try {
- sessionId = await createBackendSessionForSend(visibleText)
+ sessionId = await createBackendSessionForSend(bubbleText)
} catch (err) {
dropOptimistic(null)
releaseBusy()
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts
index b193b1aebf1..a2ec14eb2a5 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts
@@ -393,6 +393,11 @@ export interface SubmitTextOptions {
* (queue drain, steer, external submit requests): the check is a no-op
* without it. */
composerScope?: string | null
+ /** What the transcript shows for this send, when it differs from the text
+ * the agent receives. A `/skill` invocation expands into the whole skill
+ * body — model-facing scaffolding the UI must never render — so the slash
+ * dispatcher passes the invocation (`/work fix the leak`) here. */
+ displayText?: string
fromQueue?: boolean
/** Runtime session id to submit into. Queue drains pass this so a
* backgrounded/source session cannot be replaced by the current foreground
diff --git a/apps/desktop/src/app/types.ts b/apps/desktop/src/app/types.ts
index 01ada56e935..f7452607f7c 100644
--- a/apps/desktop/src/app/types.ts
+++ b/apps/desktop/src/app/types.ts
@@ -132,12 +132,17 @@ export interface SkillCommandDispatchResponse {
type: 'skill'
name: string
message?: string
+ /** The invocation the UI renders (`/work fix the leak`). `message` is the
+ * expanded skill body — model-facing scaffolding no surface may show. */
+ display?: string
}
export interface SendCommandDispatchResponse {
type: 'send'
message: string
notice?: string
+ /** Set for a skill-bundle send: see SkillCommandDispatchResponse.display. */
+ display?: string
}
export interface PrefillCommandDispatchResponse {
diff --git a/apps/desktop/src/components/assistant-ui/directive-text.tsx b/apps/desktop/src/components/assistant-ui/directive-text.tsx
index 94edc90963d..f04340c5d6e 100644
--- a/apps/desktop/src/components/assistant-ui/directive-text.tsx
+++ b/apps/desktop/src/components/assistant-ui/directive-text.tsx
@@ -177,16 +177,17 @@ const HERMES_DIRECTIVE_RE = new RegExp(
'g'
)
-// A skill referenced mid-prose (`clean this up with /clean`). The composer
-// inserts it as a pill, so the sent message renders it as one too rather than
-// flattening back to raw text. Only matches after whitespace — a leading `/`
-// is a command invocation, which never reaches a rendered message as text.
+// A skill referenced in a sent message — either the invocation that opens it
+// (`/work fix the leak`, which is all a skill turn ever renders as) or one
+// named mid-prose (`clean this up with /clean`). The composer inserts both as
+// pills, so the sent message renders them as pills too rather than flattening
+// back to raw text.
//
// Unlike the composer's caret-anchored trigger, this scans finished text, so
// it must reject a token that continues into a path: `/usr/local/bin` would
// otherwise chip as `/usr`. `(?![\w-]*\/)` requires the token to end at
// something other than another slash.
-const SLASH_SKILL_RE = /(?<=\s)\/([a-zA-Z][\w-]*)(?![\w-]*\/)/g
+const SLASH_SKILL_RE = /(?<=^|\s)\/([a-zA-Z][\w-]*)(?![\w-]*\/)/g
const TRAILING_PUNCTUATION_RE = /[,.;!?]+$/
diff --git a/apps/desktop/src/lib/chat-messages.ts b/apps/desktop/src/lib/chat-messages.ts
index 13cca5b511b..6ee82ebbb6e 100644
--- a/apps/desktop/src/lib/chat-messages.ts
+++ b/apps/desktop/src/lib/chat-messages.ts
@@ -1,5 +1,5 @@
import type { ThreadMessageLike } from '@assistant-ui/react'
-import type { BillingBlock } from '@hermes/shared'
+import { type BillingBlock, skillInvocationText } from '@hermes/shared'
import { extractImageRefs } from '@/lib/embedded-images'
import { dedupeGeneratedImageEchoesInParts } from '@/lib/generated-images'
@@ -301,6 +301,15 @@ function displayContentForMessage(role: SessionMessage['role'], content: unknown
return textContent
}
+ // A `/skill` turn is stored expanded (the whole skill body). Current
+ // gateways project it to the invocation before it ever reaches us; this is
+ // the fallback for an older backend that still ships the raw payload.
+ const invocation = skillInvocationText(textContent)
+
+ if (invocation) {
+ return invocation
+ }
+
const marker = textContent.match(ATTACHED_CONTEXT_MARKER_RE)
if (!marker || marker.index === undefined) {
diff --git a/apps/desktop/src/lib/chat-runtime.ts b/apps/desktop/src/lib/chat-runtime.ts
index b392d2692a3..65965c41b67 100644
--- a/apps/desktop/src/lib/chat-runtime.ts
+++ b/apps/desktop/src/lib/chat-runtime.ts
@@ -283,10 +283,14 @@ export function parseCommandDispatch(raw: unknown): CommandDispatchResponse | nu
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) } : null
+ 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) } : null
+ 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
diff --git a/apps/desktop/src/store/composer-queue.ts b/apps/desktop/src/store/composer-queue.ts
index 9a048c78699..ba610b36275 100644
--- a/apps/desktop/src/store/composer-queue.ts
+++ b/apps/desktop/src/store/composer-queue.ts
@@ -5,6 +5,10 @@ import type { ComposerAttachment } from './composer'
export interface QueuedPromptEntry {
id: string
text: string
+ /** What the queue panel and the sent bubble show, when it differs from the
+ * text the agent receives. A queued `/skill` invocation carries the whole
+ * expanded skill body as `text` — the UI shows the invocation instead. */
+ displayText?: string
attachments: ComposerAttachment[]
queuedAt: number
}
@@ -110,7 +114,7 @@ export const getQueuedPrompts = (key: string | null | undefined): QueuedPromptEn
export const enqueueQueuedPrompt = (
key: string | null | undefined,
- payload: { text: string; attachments: ComposerAttachment[] }
+ payload: { text: string; attachments: ComposerAttachment[]; displayText?: string }
): null | QueuedPromptEntry => {
const sid = sidOf(key)
@@ -121,6 +125,7 @@ export const enqueueQueuedPrompt = (
const entry: QueuedPromptEntry = {
id: nextId(),
text: payload.text,
+ ...(payload.displayText ? { displayText: payload.displayText } : {}),
attachments: cloneAttachments(payload.attachments),
queuedAt: Date.now()
}
@@ -218,7 +223,12 @@ export const updateQueuedPrompt = (
changed = true
- return { ...entry, text: update.text, attachments }
+ // The user rewrote the text, so any display projection it carried (a
+ // `/skill` invocation standing in for the expanded body) no longer
+ // describes it — what they typed is now what sends.
+ const { displayText: _dropped, ...rest } = entry
+
+ return { ...rest, text: update.text, attachments }
})
if (!changed) {