fix(desktop): de-duplicate the action verb in terminal tool titles

A model-authored terminal `context`/`preview` sometimes already opens with
the verb the title template prepends ("Running grep …"), so the pending row
rendered as a doubled "Running Running grep …". Strip a leading word that
matches the action being prefixed so the verb appears once.
This commit is contained in:
PRATHAMESH75 authored and brooklyn! committed 2026-09-25 17:03:35 -05:00
1 parent fe417523fe
commit f4f92e507d
2 files changed
+38 -1

No files matched your search

@@ -449,6 +449,27 @@ describe('buildToolView title actions', () => {
expect(view.detail).toBe('')
})
it('does not double the action verb when the context already starts with it', () => {
// A model-authored `context` that opens with the same verb the template
// prepends ("Running grep …") otherwise renders as "Running Running grep …".
const view = buildToolView(
part({
args: { context: 'Running grep -rn -i "bedrock" ~/.hermes/' },
result: undefined,
toolName: 'terminal'
}),
''
)
expect(view.title.startsWith('Running Running')).toBe(false)
expect(view.title).toBe('Running grep -rn -i "bedrock" ~/.hermes/')
expect(view.titleAction).toEqual({
prefix: '',
text: 'Running',
suffix: ' grep -rn -i "bedrock" ~/.hermes/'
})
})
it('uses the runtime locale for title text and action placement', () => {
setRuntimeI18nLocale('ja')
@@ -1322,6 +1322,22 @@ function titlePartsFromAction(title: string, action?: string): ToolTitleParts {
}
}
// A model-authored terminal `context`/`preview` sometimes already opens with
// the verb the title template prepends ("Running grep …"), which renders as a
// doubled "Running Running grep …". Drop a leading word that matches the action
// we're about to prefix so the verb appears once.
function withoutLeadingAction(value: string, action: string): string {
const verb = action.trim()
const text = value.trimStart()
const boundary = text.search(/\s/)
if (!verb || boundary < 0) {
return value
}
return text.slice(0, boundary).toLowerCase() === verb.toLowerCase() ? text.slice(boundary + 1).trimStart() : value
}
function dynamicTitle(
part: ToolPart,
args: Record<string, unknown>,
@@ -1411,7 +1427,7 @@ function dynamicTitle(
translateNow(
'assistant.tool.titleTemplates.actionCommand',
action,
compactPreview(summarizeShellCommand(command), 160)
withoutLeadingAction(compactPreview(summarizeShellCommand(command), 160), action)
)
)
}