Skip to content

The agent that grows with you

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

PRATHAMESH75f4f92e507d39
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts b/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
index a7508cc7b05..bda833c25ff 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
@@ -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')
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts b/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
index 2ad6cb3150b..b00f3c68840 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
@@ -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)
)
)
}