diff --git a/apps/host/server/agent/events.mjs b/apps/host/server/agent/events.mjs index cec153f0..f8d0d658 100644 --- a/apps/host/server/agent/events.mjs +++ b/apps/host/server/agent/events.mjs @@ -82,10 +82,33 @@ const VERBS = { job_kill: ['Stopping a background task', 'Stopped a background task', "Couldn't stop the background task"], }; const GENERIC_VERBS = ['Using a tool', 'Used a tool', 'The tool failed']; +/** The browser tool server's tools (Settings -> Tools): the card says what happened to the page, not the tool's internal name. */ +const BROWSER_VERBS = { + browser_navigate: ['Opening a page in the browser', 'Opened a page in the browser', "Couldn't open the page"], + browser_click: ['Clicking on the page', 'Clicked on the page', "Couldn't click on the page"], + browser_hover: ['Pointing at the page', 'Pointed at the page', "Couldn't point at the page"], + browser_type: ['Typing on the page', 'Typed on the page', "Couldn't type on the page"], + browser_fill_form: ['Typing on the page', 'Typed on the page', "Couldn't type on the page"], + browser_press_key: ['Typing on the page', 'Typed on the page', "Couldn't type on the page"], + browser_snapshot: ['Looking at the page', 'Looked at the page', "Couldn't look at the page"], + browser_take_screenshot: ['Looking at the page', 'Looked at the page', "Couldn't look at the page"], +}; +const BROWSER_GENERIC = ['Using the browser', 'Used the browser', 'The browser step failed']; +const BROWSER_PREFIX = 'mcp__browser__', INSTRUCTIONS_PREFIX = 'mcp__strata-instructions__', COMMANDS_PREFIX = 'mcp__strata-commands__'; +/** The person's own tool's name as they wrote it (spaces for underscores). */ +const ownToolName = name => name.replace(/^mcp__strata-(?:instructions|commands)__/, '').replace(/_/g, ' '); +/** The three sentences (running, worked, failed) for a tool, and whether this is one the app knows by name. */ +function verbsFor(name) { + if (VERBS[name]) return { verbs: VERBS[name], known: true }; + if (name.startsWith(BROWSER_PREFIX)) return { verbs: BROWSER_VERBS[name.slice(BROWSER_PREFIX.length)] ?? BROWSER_GENERIC, known: true }; + if (name.startsWith(INSTRUCTIONS_PREFIX)) return { verbs: ['Reading your instructions', 'Read your instructions', "Couldn't read your instructions"], known: true }; + if (name.startsWith(COMMANDS_PREFIX)) return { verbs: ['Running your tool', 'Ran your tool', 'Your tool failed'], known: true }; + return { verbs: GENERIC_VERBS, known: false }; +} /** The sentence for a card in this state (the first for a running or waiting card). */ export function toolVerb(name, state) { - const v = VERBS[name] ?? GENERIC_VERBS; + const v = verbsFor(name).verbs; return state === 'error' ? v[2] : state === 'done' ? v[1] : v[0]; } /** The ToolCall fields the card needs, from one Harness tool call. */ @@ -94,11 +117,11 @@ export function presentTool({ callId, name, args, reason = null }) { const words = WORDS[name]?.(args); const preview = scope === 'shell' && !words ? args.command ?? '' : scope === 'write' ? args.file_path ?? args.path ?? args.filePath ?? '' - : words ? words[1] ?? '' : args.file_path ?? args.path ?? args.pattern ?? args.url ?? args.query ?? JSON.stringify(args); + : words ? words[1] ?? '' : name.startsWith(INSTRUCTIONS_PREFIX) || name.startsWith(COMMANDS_PREFIX) ? ownToolName(name) : args.file_path ?? args.path ?? args.pattern ?? args.url ?? args.element ?? args.query ?? JSON.stringify(args); const effect = reason ?? (words ? words[0] : scope === 'shell' ? (args.description ?? 'Runs a command in the workspace.') : scope === 'write' ? 'Changes a file in the workspace.' : scope === 'read' ? 'Reads from the workspace.' : 'Uses a connected tool.'); - return { id: callId, name, args, preview: clip(preview, 600), effect: clip(effect, 400), scope, verb: toolVerb(name, 'running'), target: clip(name in VERBS ? preview : name, 300) }; + return { id: callId, name, args, preview: clip(preview, 600), effect: clip(effect, 400), scope, verb: toolVerb(name, 'running'), target: clip(verbsFor(name).known ? preview : name, 300) }; } /** A tool's failure in plain words, or null when there is nothing better than the original text. */ diff --git a/apps/host/src/locales/de.json b/apps/host/src/locales/de.json index 01bdc0e8..c953491d 100644 --- a/apps/host/src/locales/de.json +++ b/apps/host/src/locales/de.json @@ -2802,5 +2802,29 @@ "s2804": "Das Werkzeug konnte nicht entfernt werden.", "s2805": "Das Browser-Werkzeug gehört nicht zu dieser Installation.", "s2806": "Es wird an einer Kopie deiner Dateien gearbeitet. Den Fortschritt siehst du in der Seitenleiste.", - "s2807": "Das Ergebnis ist fertig. Wechsle zwischen Original und Aktualisiert oder vergleiche beide nebeneinander." + "s2807": "Das Ergebnis ist fertig. Wechsle zwischen Original und Aktualisiert oder vergleiche beide nebeneinander.", + "s2808": "Eine Seite im Browser wird geöffnet", + "s2809": "Eine Seite im Browser geöffnet", + "s2810": "Die Seite ließ sich nicht öffnen", + "s2811": "Es wird auf der Seite geklickt", + "s2812": "Auf der Seite geklickt", + "s2813": "Der Klick auf der Seite ging nicht", + "s2814": "Es wird auf die Seite gezeigt", + "s2815": "Auf die Seite gezeigt", + "s2816": "Das Zeigen auf der Seite ging nicht", + "s2817": "Es wird auf der Seite getippt", + "s2818": "Auf der Seite getippt", + "s2819": "Das Tippen auf der Seite ging nicht", + "s2820": "Die Seite wird angesehen", + "s2821": "Die Seite angesehen", + "s2822": "Die Seite ließ sich nicht ansehen", + "s2823": "Der Browser wird benutzt", + "s2824": "Den Browser benutzt", + "s2825": "Der Browser-Schritt ist fehlgeschlagen", + "s2826": "Deine Anweisungen werden gelesen", + "s2827": "Deine Anweisungen gelesen", + "s2828": "Deine Anweisungen ließen sich nicht lesen", + "s2829": "Dein Werkzeug läuft", + "s2830": "Dein Werkzeug ausgeführt", + "s2831": "Dein Werkzeug ist fehlgeschlagen" } diff --git a/apps/host/src/locales/en.json b/apps/host/src/locales/en.json index 7cad6594..5bb94693 100644 --- a/apps/host/src/locales/en.json +++ b/apps/host/src/locales/en.json @@ -2802,5 +2802,29 @@ "s2804": "The tool could not be removed.", "s2805": "The browser tool is not part of this installation.", "s2806": "Working on a copy of your files. Follow the progress in the sidebar.", - "s2807": "The result is ready. Switch between Original and Updated, or compare them side by side." + "s2807": "The result is ready. Switch between Original and Updated, or compare them side by side.", + "s2808": "Opening a page in the browser", + "s2809": "Opened a page in the browser", + "s2810": "Couldn't open the page", + "s2811": "Clicking on the page", + "s2812": "Clicked on the page", + "s2813": "Couldn't click on the page", + "s2814": "Pointing at the page", + "s2815": "Pointed at the page", + "s2816": "Couldn't point at the page", + "s2817": "Typing on the page", + "s2818": "Typed on the page", + "s2819": "Couldn't type on the page", + "s2820": "Looking at the page", + "s2821": "Looked at the page", + "s2822": "Couldn't look at the page", + "s2823": "Using the browser", + "s2824": "Used the browser", + "s2825": "The browser step failed", + "s2826": "Reading your instructions", + "s2827": "Read your instructions", + "s2828": "Couldn't read your instructions", + "s2829": "Running your tool", + "s2830": "Ran your tool", + "s2831": "Your tool failed" } diff --git a/apps/host/src/locales/es.json b/apps/host/src/locales/es.json index 84736fd7..5616bd58 100644 --- a/apps/host/src/locales/es.json +++ b/apps/host/src/locales/es.json @@ -2802,5 +2802,29 @@ "s2804": "No se pudo quitar la herramienta.", "s2805": "La herramienta de navegador no forma parte de esta instalación.", "s2806": "Trabajando en una copia de tus archivos. Sigue el progreso en la barra lateral.", - "s2807": "El resultado está listo. Cambia entre Original y Actualizado, o compáralos lado a lado." + "s2807": "El resultado está listo. Cambia entre Original y Actualizado, o compáralos lado a lado.", + "s2808": "Abriendo una página en el navegador", + "s2809": "Abrió una página en el navegador", + "s2810": "No se pudo abrir la página", + "s2811": "Haciendo clic en la página", + "s2812": "Hizo clic en la página", + "s2813": "No se pudo hacer clic en la página", + "s2814": "Señalando la página", + "s2815": "Señaló la página", + "s2816": "No se pudo señalar la página", + "s2817": "Escribiendo en la página", + "s2818": "Escribió en la página", + "s2819": "No se pudo escribir en la página", + "s2820": "Mirando la página", + "s2821": "Miró la página", + "s2822": "No se pudo mirar la página", + "s2823": "Usando el navegador", + "s2824": "Usó el navegador", + "s2825": "El paso del navegador falló", + "s2826": "Leyendo tus instrucciones", + "s2827": "Leyó tus instrucciones", + "s2828": "No se pudieron leer tus instrucciones", + "s2829": "Ejecutando tu herramienta", + "s2830": "Ejecutó tu herramienta", + "s2831": "Tu herramienta falló" } diff --git a/apps/host/src/locales/ja.json b/apps/host/src/locales/ja.json index 7af3baef..ab643940 100644 --- a/apps/host/src/locales/ja.json +++ b/apps/host/src/locales/ja.json @@ -2802,5 +2802,29 @@ "s2804": "ツールを削除できませんでした。", "s2805": "ブラウザーのツールは、このインストールには含まれていません。", "s2806": "ファイルのコピーで作業しています。進み具合はサイドバーで確認できます。", - "s2807": "結果の準備ができました。「元の結果」と「更新後」を切り替えたり、並べて比較したりできます。" + "s2807": "結果の準備ができました。「元の結果」と「更新後」を切り替えたり、並べて比較したりできます。", + "s2808": "ブラウザーでページを開いています", + "s2809": "ブラウザーでページを開きました", + "s2810": "ページを開けませんでした", + "s2811": "ページをクリックしています", + "s2812": "ページをクリックしました", + "s2813": "ページをクリックできませんでした", + "s2814": "ページの上にポインターを置いています", + "s2815": "ページの上にポインターを置きました", + "s2816": "ページの上にポインターを置けませんでした", + "s2817": "ページに入力しています", + "s2818": "ページに入力しました", + "s2819": "ページに入力できませんでした", + "s2820": "ページを見ています", + "s2821": "ページを見ました", + "s2822": "ページを見られませんでした", + "s2823": "ブラウザーを使っています", + "s2824": "ブラウザーを使いました", + "s2825": "ブラウザーの操作に失敗しました", + "s2826": "あなたの指示を読んでいます", + "s2827": "あなたの指示を読みました", + "s2828": "あなたの指示を読めませんでした", + "s2829": "あなたのツールを実行しています", + "s2830": "あなたのツールを実行しました", + "s2831": "あなたのツールは失敗しました" } diff --git a/apps/host/src/locales/ko.json b/apps/host/src/locales/ko.json index 71a25933..e096fbab 100644 --- a/apps/host/src/locales/ko.json +++ b/apps/host/src/locales/ko.json @@ -2802,5 +2802,29 @@ "s2804": "도구를 제거할 수 없었습니다.", "s2805": "브라우저 도구는 이 설치에 포함되어 있지 않습니다.", "s2806": "파일의 복사본에서 작업 중입니다. 진행 상황은 사이드바에서 확인하세요.", - "s2807": "결과가 준비되었습니다. 원본과 업데이트됨을 전환하거나 나란히 비교해 보세요." + "s2807": "결과가 준비되었습니다. 원본과 업데이트됨을 전환하거나 나란히 비교해 보세요.", + "s2808": "브라우저에서 페이지를 여는 중", + "s2809": "브라우저에서 페이지를 열었습니다", + "s2810": "페이지를 열 수 없었습니다", + "s2811": "페이지를 클릭하는 중", + "s2812": "페이지를 클릭했습니다", + "s2813": "페이지를 클릭할 수 없었습니다", + "s2814": "페이지를 가리키는 중", + "s2815": "페이지를 가리켰습니다", + "s2816": "페이지를 가리킬 수 없었습니다", + "s2817": "페이지에 입력하는 중", + "s2818": "페이지에 입력했습니다", + "s2819": "페이지에 입력할 수 없었습니다", + "s2820": "페이지를 보는 중", + "s2821": "페이지를 보았습니다", + "s2822": "페이지를 볼 수 없었습니다", + "s2823": "브라우저를 사용하는 중", + "s2824": "브라우저를 사용했습니다", + "s2825": "브라우저 단계가 실패했습니다", + "s2826": "내 지침을 읽는 중", + "s2827": "내 지침을 읽었습니다", + "s2828": "내 지침을 읽을 수 없었습니다", + "s2829": "내 도구를 실행하는 중", + "s2830": "내 도구를 실행했습니다", + "s2831": "내 도구가 실패했습니다" } diff --git a/apps/host/src/locales/pt.json b/apps/host/src/locales/pt.json index cb417dd7..3647ea9d 100644 --- a/apps/host/src/locales/pt.json +++ b/apps/host/src/locales/pt.json @@ -2802,5 +2802,29 @@ "s2804": "Não foi possível remover a ferramenta.", "s2805": "A ferramenta de navegador não faz parte desta instalação.", "s2806": "Trabalhando numa cópia dos seus arquivos. Acompanhe o progresso na barra lateral.", - "s2807": "O resultado está pronto. Alterne entre Original e Atualizado, ou compare lado a lado." + "s2807": "O resultado está pronto. Alterne entre Original e Atualizado, ou compare lado a lado.", + "s2808": "Abrindo uma página no navegador", + "s2809": "Abriu uma página no navegador", + "s2810": "Não foi possível abrir a página", + "s2811": "Clicando na página", + "s2812": "Clicou na página", + "s2813": "Não foi possível clicar na página", + "s2814": "Apontando para a página", + "s2815": "Apontou para a página", + "s2816": "Não foi possível apontar para a página", + "s2817": "Digitando na página", + "s2818": "Digitou na página", + "s2819": "Não foi possível digitar na página", + "s2820": "Olhando a página", + "s2821": "Olhou a página", + "s2822": "Não foi possível olhar a página", + "s2823": "Usando o navegador", + "s2824": "Usou o navegador", + "s2825": "A etapa do navegador falhou", + "s2826": "Lendo as suas instruções", + "s2827": "Leu as suas instruções", + "s2828": "Não foi possível ler as suas instruções", + "s2829": "Executando a sua ferramenta", + "s2830": "Executou a sua ferramenta", + "s2831": "A sua ferramenta falhou" } diff --git a/apps/host/src/locales/ru.json b/apps/host/src/locales/ru.json index ec1eff25..093af322 100644 --- a/apps/host/src/locales/ru.json +++ b/apps/host/src/locales/ru.json @@ -2802,5 +2802,29 @@ "s2804": "Не удалось удалить инструмент.", "s2805": "Инструмент браузера не входит в эту установку.", "s2806": "Идёт работа над копией ваших файлов. Ход работы виден на боковой панели.", - "s2807": "Результат готов. Переключайтесь между «Оригинал» и «Обновлено» или сравнивайте их рядом." + "s2807": "Результат готов. Переключайтесь между «Оригинал» и «Обновлено» или сравнивайте их рядом.", + "s2808": "Открывается страница в браузере", + "s2809": "Открыта страница в браузере", + "s2810": "Не удалось открыть страницу", + "s2811": "Выполняется щелчок на странице", + "s2812": "Выполнен щелчок на странице", + "s2813": "Не удалось щёлкнуть на странице", + "s2814": "Наведение на странице", + "s2815": "Наведено на странице", + "s2816": "Не удалось навести на странице", + "s2817": "Ввод на странице", + "s2818": "Выполнен ввод на странице", + "s2819": "Не удалось ввести текст на странице", + "s2820": "Просмотр страницы", + "s2821": "Страница просмотрена", + "s2822": "Не удалось просмотреть страницу", + "s2823": "Используется браузер", + "s2824": "Браузер использован", + "s2825": "Шаг в браузере не удался", + "s2826": "Чтение ваших инструкций", + "s2827": "Ваши инструкции прочитаны", + "s2828": "Не удалось прочитать ваши инструкции", + "s2829": "Запускается ваш инструмент", + "s2830": "Ваш инструмент выполнен", + "s2831": "Ваш инструмент завершился с ошибкой" } diff --git a/apps/host/src/locales/zh.json b/apps/host/src/locales/zh.json index bf4e9da6..0262f774 100644 --- a/apps/host/src/locales/zh.json +++ b/apps/host/src/locales/zh.json @@ -2802,5 +2802,29 @@ "s2804": "无法移除工具。", "s2805": "此安装中不包含浏览器工具。", "s2806": "正在对你的文件副本进行处理。请在侧边栏查看进度。", - "s2807": "结果已准备好。你可以在“原版”和“更新版”之间切换,也可以并排比较。" + "s2807": "结果已准备好。你可以在“原版”和“更新版”之间切换,也可以并排比较。", + "s2808": "正在浏览器中打开页面", + "s2809": "已在浏览器中打开页面", + "s2810": "无法打开页面", + "s2811": "正在点击页面", + "s2812": "已点击页面", + "s2813": "无法点击页面", + "s2814": "正在指向页面", + "s2815": "已指向页面", + "s2816": "无法指向页面", + "s2817": "正在页面中输入", + "s2818": "已在页面中输入", + "s2819": "无法在页面中输入", + "s2820": "正在查看页面", + "s2821": "已查看页面", + "s2822": "无法查看页面", + "s2823": "正在使用浏览器", + "s2824": "已使用浏览器", + "s2825": "浏览器步骤失败", + "s2826": "正在读取你的说明", + "s2827": "已读取你的说明", + "s2828": "无法读取你的说明", + "s2829": "正在运行你的工具", + "s2830": "已运行你的工具", + "s2831": "你的工具运行失败" } diff --git a/apps/host/tests/agent-events.test.mjs b/apps/host/tests/agent-events.test.mjs index 02504656..ee982b6e 100644 --- a/apps/host/tests/agent-events.test.mjs +++ b/apps/host/tests/agent-events.test.mjs @@ -3,7 +3,7 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { buildProfile, outputBudget, routeFor, ASSUMED_API_CONTEXT } from '../server/agent/profile.mjs'; import { agentEnvironment, redact } from '../server/agent/harness-runtime.mjs'; -import { TurnProjector, presentTool, toolScope, friendlyFailure } from '../server/agent/events.mjs'; +import { TurnProjector, presentTool, toolScope, toolVerb, friendlyFailure } from '../server/agent/events.mjs'; import { withEarlierConversation } from '../server/agent/agent-bridge.mjs'; const local = [{ id: 'inst-1', label: 'Qwen', baseUrl: 'http://127.0.0.1:8095/v1', modelId: 'qwen', context: 32768, key: 'local-secret-key-1' }]; @@ -129,3 +129,28 @@ test('a chat that existed before the agent carries a bounded summary into its fi assert.ok(prompt.length < 12 * 1600 + 200, 'bounded'); assert.equal(withEarlierConversation([], 'NOW'), 'NOW'); }); + +test('the browser and the person\'s own tools have plain sentences, translated in every language', async () => { + const { readFileSync } = await import('node:fs'); + const catalog = Object.fromEntries(['en', 'de', 'es', 'ja', 'ko', 'pt', 'ru', 'zh'].map(l => [l, JSON.parse(readFileSync(new URL(`../src/locales/${l}.json`, import.meta.url), 'utf8'))])); + const idOf = text => Object.entries(catalog.en).find(([, v]) => v === text)?.[0]; + const cases = [ + ['mcp__browser__browser_navigate', 'Opening a page in the browser', 'Opened a page in the browser', "Couldn't open the page"], + ['mcp__browser__browser_click', 'Clicking on the page', 'Clicked on the page', "Couldn't click on the page"], + ['mcp__browser__browser_type', 'Typing on the page', 'Typed on the page', "Couldn't type on the page"], + ['mcp__browser__browser_snapshot', 'Looking at the page', 'Looked at the page', "Couldn't look at the page"], + ['mcp__browser__browser_something_new', 'Using the browser', 'Used the browser', 'The browser step failed'], + ['mcp__strata-instructions__house_style', 'Reading your instructions', 'Read your instructions', "Couldn't read your instructions"], + ['mcp__strata-commands__check_site', 'Running your tool', 'Ran your tool', 'Your tool failed'], + ['mcp__github__create_issue', 'Using a tool', 'Used a tool', 'The tool failed'], + ]; + for (const [name, running, done, failed] of cases) { + assert.equal(toolVerb(name, 'running'), running, name); assert.equal(toolVerb(name, 'done'), done, name); assert.equal(toolVerb(name, 'error'), failed, name); + for (const text of [running, done, failed]) { const id = idOf(text); assert.ok(id, `${text} is in the catalog`); for (const l of ['de', 'es', 'ja', 'ko', 'pt', 'ru', 'zh']) assert.ok(catalog[l][id]?.trim(), `${l}: ${text}`); } + } + const nav = presentTool({ callId: 'c1', name: 'mcp__browser__browser_navigate', args: { url: 'https://example.com' } }); + assert.equal(nav.target, 'https://example.com'); assert.equal(nav.verb, 'Opening a page in the browser'); + const own = presentTool({ callId: 'c2', name: 'mcp__strata-commands__check_site', args: {} }); + assert.equal(own.target, 'check site'); + assert.equal(presentTool({ callId: 'c3', name: 'mcp__github__create_issue', args: {} }).target, 'mcp__github__create_issue', 'an unknown connected tool keeps its name'); +});