The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): name web, browser and vision tool runs for what they did
Brooklyn Nicholson7d7f712a7863
diff --git a/apps/desktop/src/components/assistant-ui/tool/run-summary.test.ts b/apps/desktop/src/components/assistant-ui/tool/run-summary.test.tsindex ba47368a031..e3b27774df5 100644--- a/apps/desktop/src/components/assistant-ui/tool/run-summary.test.ts+++ b/apps/desktop/src/components/assistant-ui/tool/run-summary.test.ts@@ -9,6 +9,13 @@ function tool(toolName: string, args: Record<string, unknown> = {}, result?: unkconst read = (path: string) => tool('read_file', { path }, { content: '' })const searched = (query: string) => tool('search_files', { query }, { hits: [] })const ran = (command: string) => tool('terminal', { command }, { exit_code: 0 })+// Fixtures carry the REAL tool schemas (tools/web_tools.py): web_search takes+// `query`, web_extract takes `urls` (a list, up to five per call).+const webSearched = (query: string) => tool('web_search', { query }, { success: true })+const webExtracted = (urls: string[]) => tool('web_extract', { urls }, { success: true })+const navigated = (url: string) => tool('browser_navigate', { url }, { success: true })+const browsed = () => tool('browser_exec', { code: 'goto' }, { success: true })+const analyzed = (image: string) => tool('vision_analyze', { image_url: image }, { success: true, analysis: '' })const settled = (tools: ToolCallLike[]) => summarizeToolRun(tools, false)const running = (tools: ToolCallLike[]) => summarizeToolRun(tools, true)@@ -57,4 +64,58 @@ describe('summarizeToolRun', () => {it('reads a run the turn left unresolved as finished', () => {expect(settled([read('a.ts'), tool('search_files', { query: 'toolRuns' })])).toBe('Explored 2 files')})++ // The web tools act on queries and pages, not files. Counted in the explore+ // bucket they read as "Explored 2 files" while their own rows say Searched+ // (#123085).+ it('counts web searches as queries, not explored files', () => {+ expect(settled([webSearched('hermes agent'), webSearched('kv cache')])).toBe('Searched 2 queries')+ expect(running([webSearched('hermes agent'), webSearched('kv cache')])).toBe('Searching 2 queries')+ })++ it('names a lone web search the way its row does', () => {+ expect(settled([webSearched('hermes agent')])).toBe('Searched “hermes agent”')+ })++ it('names a lone web extract by hostname the way its row does', () => {+ expect(settled([webExtracted(['https://example.com/docs'])])).toBe('Read example.com/docs')+ expect(running([webExtracted(['https://example.com/docs'])])).toBe('Reading example.com/docs')+ })++ it('still names a legacy string-url web extract shape', () => {+ expect(settled([tool('web_extract', { url: 'https://example.com/docs' }, { success: true })])).toBe(+ 'Read example.com/docs'+ )+ })++ it('gives web searches their own clause after explored files', () => {+ expect(settled([read('a.ts'), webSearched('x'), webSearched('y')])).toBe('Explored a.ts, searched 2 queries')+ })++ // One web_extract call fetches up to five URLs, so the page count follows+ // the URLs rather than the calls.+ it('counts every page a batched fetch read', () => {+ expect(settled([webExtracted(['https://a.example', 'https://b.example', 'https://c.example'])])).toBe(+ 'Read 3 pages'+ )+ expect(+ settled([webExtracted(['https://a.example', 'https://b.example']), webExtracted(['https://c.example'])])+ ).toBe('Read 3 pages')+ })++ // Clicks, screenshots and scripts load nothing; only navigation opens pages.+ it('never counts browser interaction as pages', () => {+ const interaction = [browsed(), browsed(), tool('browser_screenshot'), tool('browser_scroll')]++ expect(settled(interaction)).toBe('Performed 4 browser actions')+ expect(settled([navigated('https://a.example'), navigated('https://b.example'), ...interaction])).toBe(+ 'Opened 2 pages, performed 4 browser actions'+ )+ expect(settled([navigated('https://a.example')])).toBe('Opened a.example')+ })++ it('counts vision analysis as images', () => {+ expect(settled([analyzed('shot.png')])).toBe('Analyzed 1 image')+ expect(settled([analyzed('shot.png'), analyzed('other.png')])).toBe('Analyzed 2 images')+ })})diff --git a/apps/desktop/src/components/assistant-ui/tool/run-summary.ts b/apps/desktop/src/components/assistant-ui/tool/run-summary.tsindex 1fea04e7999..81e7f214237 100644--- a/apps/desktop/src/components/assistant-ui/tool/run-summary.ts+++ b/apps/desktop/src/components/assistant-ui/tool/run-summary.ts@@ -2,7 +2,15 @@ import { translateNow } from '@/i18n'import { summarizeShellCommand } from '@/lib/summarize-command'import { firstStringField } from '@/lib/text'-import { fileEditBasename, isFileEditTool, parseMaybeObject, toolCallFailed } from './fallback-model'+import {+ compactPreview,+ fileEditBasename,+ findFirstUrl,+ hostnameOf,+ isFileEditTool,+ parseMaybeObject,+ toolCallFailed+} from './fallback-model'import { skillActivityTitle } from './skill-activity'/**@@ -23,48 +31,75 @@ export function isToolCallPart<T extends { type: string }>(part: T): part is Extreturn part.type === 'tool-call'}-type RunCategory = 'delegate' | 'edit' | 'explore' | 'other' | 'run'+type RunCategory =+ 'analyze' | 'browse' | 'delegate' | 'edit' | 'explore' | 'interact' | 'other' | 'read' | 'run' | 'search'// Clause order is fixed so the same run always reads the same way, whichever// category happens to be live.-const CATEGORY_ORDER: readonly RunCategory[] = ['edit', 'explore', 'run', 'delegate', 'other']+const CATEGORY_ORDER: readonly RunCategory[] = [+ 'edit',+ 'explore',+ 'search',+ 'read',+ 'browse',+ 'interact',+ 'analyze',+ 'run',+ 'delegate',+ 'other'+]const CATEGORY_COPY: Record<RunCategory, { noun: [string, string]; past: string; present: string }> = {+ analyze: { noun: ['image', 'images'], past: 'Analyzed', present: 'Analyzing' },+ browse: { noun: ['page', 'pages'], past: 'Opened', present: 'Opening' },delegate: { noun: ['task', 'tasks'], past: 'Delegated', present: 'Delegating' },edit: { noun: ['file', 'files'], past: 'Edited', present: 'Editing' },explore: { noun: ['file', 'files'], past: 'Explored', present: 'Exploring' },+ interact: { noun: ['browser action', 'browser actions'], past: 'Performed', present: 'Performing' },other: { noun: ['tool', 'tools'], past: 'Used', present: 'Using' },- run: { noun: ['command', 'commands'], past: 'Ran', present: 'Running' }+ read: { noun: ['page', 'pages'], past: 'Read', present: 'Reading' },+ run: { noun: ['command', 'commands'], past: 'Ran', present: 'Running' },+ search: { noun: ['query', 'queries'], past: 'Searched', present: 'Searching' }}-const EXPLORE_TOOLS = new Set([- 'list_files',- 'read_file',- 'search_files',- 'session_search_recall',- 'vision_analyze',- 'web_extract',- 'web_search'-])+// Routed by name so a web search never counts as an explored file (#123085).+// Browser tools other than navigation are interaction, not page loads: a+// screenshot or a click fetches nothing, so they must not be counted as pages.+const TOOL_CATEGORY: Record<string, RunCategory> = {+ browser_navigate: 'browse',+ delegate_task: 'delegate',+ execute_code: 'run',+ list_files: 'explore',+ read_file: 'explore',+ search_files: 'explore',+ session_search_recall: 'search',+ terminal: 'run',+ vision_analyze: 'analyze',+ web_extract: 'read',+ web_search: 'search'+}function toolCategory(toolName: string): RunCategory {if (isFileEditTool(toolName)) {return 'edit'}- if (toolName === 'terminal' || toolName === 'execute_code') {- return 'run'- }+ return TOOL_CATEGORY[toolName] ?? (toolName.startsWith('browser_') ? 'interact' : 'other')+}- if (toolName === 'delegate_task') {- return 'delegate'+/**+ * How many things one call acted on. One call is one thing everywhere except+ * `web_extract`, which takes up to five URLs — counting its calls would report+ * five fetched pages as one.+ */+function unitCount(tool: ToolCallLike): number {+ if (tool.toolName !== 'web_extract') {+ return 1}- if (EXPLORE_TOOLS.has(toolName) || toolName.startsWith('browser_')) {- return 'explore'- }+ const urls = parseMaybeObject(tool.args).urls- return 'other'+ return Array.isArray(urls) && urls.length > 0 ? urls.length : 1}function isPending(tool: ToolCallLike): boolean {@@ -87,11 +122,30 @@ export function toolPresentVerb(toolName: string): string {/** The thing a tool acted on, as the header should name it. */function toolTarget(tool: ToolCallLike): string {const args = parseMaybeObject(tool.args)+ const category = toolCategory(tool.toolName)- if (toolCategory(tool.toolName) === 'run') {+ if (category === 'run') {return summarizeShellCommand(firstStringField(args, ['command', 'code']))}+ // A lone search names what its own row names — the quoted query for+ // web_search — so the summary and the rows underneath it read as the same+ // work. The real schema key is `query`; `search_term` is a tolerated legacy+ // spelling.+ if (category === 'search') {+ const query = firstStringField(args, ['query', 'search_term'])++ return query ? `“${compactPreview(query, 48)}”` : ''+ }++ // A page read or a navigation names its host the way its own row does, so a+ // lone extract reads "Read example.com/docs" right above a row saying the+ // same. findFirstUrl walks the args, so the real `urls` list shape and the+ // legacy string-`url` shape both name a host.+ if (category === 'read' || category === 'browse') {+ return hostnameOf(findFirstUrl(args))+ }+const path = firstStringField(args, ['path', 'file', 'filepath'])return path ? fileEditBasename(path) : firstStringField(args, ['query', 'url'])@@ -106,13 +160,14 @@ function toolTarget(tool: ToolCallLike): string {function clause(category: RunCategory, tools: ToolCallLike[], live: boolean): string {const copy = CATEGORY_COPY[category]const verb = live ? copy.present : copy.past- const target = tools.length === 1 ? toolTarget(tools[0]) : ''+ const count = tools.reduce((sum, tool) => sum + unitCount(tool), 0)+ const target = count === 1 && category !== 'interact' ? toolTarget(tools[0]) : ''if (target && (live || category !== 'run')) {return `${verb} ${target}`}- return `${verb} ${tools.length} ${copy.noun[tools.length === 1 ? 0 : 1]}`+ return `${verb} ${count} ${copy.noun[count === 1 ? 0 : 1]}`}function lowerFirst(text: string): string {@@ -137,7 +192,7 @@ function lowerFirst(text: string): string {export function summarizeToolRun(tools: readonly ToolCallLike[], live: boolean): string {// Which clause narrates in the present tense: normally the outstanding call,// but sequential calls leave gaps where the run is still going and nothing is- // pending. The most recent call covers those, and it's the one the ticker is+ // pending. The most recent call covers these, and it's the one the ticker is// showing anyway.const narrating = live ? (tools.find(isPending) ?? tools.at(-1)) : undefinedconst liveCategory = narrating ? toolCategory(narrating.toolName) : null