Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop/e2e/accessibility-coverage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ test('data-backed conversation exposes ordered todos and keyboard access to tool
await expect(page.getByRole('main')).toHaveCount(1);
await enterMainFromSkipLink(page);

const toolCall = page.getByRole('button', { name: /^检查测试状态/ });
const toolCall = page.getByRole('button', { name: /^运行命令/ });
await tabTo(page, toolCall, 'tool result');
await page.keyboard.press('Enter');
await expect(toolCall).toHaveAttribute('aria-expanded', 'true');
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/e2e/fixture-thread-search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ test('fixture-seeded transcripts return content hits with turn ids', async ({
sessionId: desktopSessionKey({ hostId, sessionId: PROMPT_RAIL_SESSION_ID }),
turnId: 'turn-prompt-rail-3',
sequence: 4,
matchKind: 'user_message',
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import assert from 'node:assert/strict';
import test from 'node:test';
import { createDefaultRuntimePolicy } from '@maka/core/runtime-policy';
import { buildAgentSwarmStatusTool } from '@maka/runtime/agent-swarm-status-tool';
import { buildComputerUseTools } from '@maka/runtime/computer-use-tools';
import { buildDeepResearchTools } from '@maka/runtime/deep-research-tools';
import { buildGoalTools } from '@maka/runtime/goal-tools';
import { buildHistoryTools } from '@maka/runtime/history-tools';
import { buildMemoryExtractionTriggerTools } from '@maka/runtime/memory-extraction';
import {
buildCancelPlanTool,
buildSubmitPlanTool,
buildUpdatePlanTool,
} from '@maka/runtime/plan-tools';
import { buildScheduledTaskTool } from '@maka/runtime/scheduled-task-tools';
import { buildParentAgentTools } from '@maka/runtime/subagent-tools';
import { buildAgentGraphSupervisorTools } from '@maka/runtime/test-only/tool-presentation';
import { createToolResultArchiveCapability } from '@maka/runtime/tool-result-archive-capability';
import {
buildHostAgentSettingsTools,
createInteractiveRunComposer,
createHostWebFetchTool,
createHostWebSearchTool,
} from '@maka/runtime-host/test-only/interactive-run-composer';
import { BUILTIN_TOOL_LABELS } from '@maka/ui';
import { buildBrowserTools } from '../browser/browser-tools.js';
import { buildClientSettingsTools } from '../client-settings-tools.js';
import { buildRiveWorkflowTool } from '../rive-workflow-tool.js';

function assertLocalized(tools: readonly { readonly name: string }[]): void {
assert.deepEqual(
tools.map(({ name }) => name).filter((name) => !Object.hasOwn(BUILTIN_TOOL_LABELS, name)),
[],
);
}

test('every default Runtime Host tool has localized Desktop presentation', () => {
const composer = createInteractiveRunComposer({
runtimePolicy: { revision: 0, policy: createDefaultRuntimePolicy() },
skills: {
readCanonicalModelInventory: async () => ({ inventory: [] }),
} as never,
memory: {} as never,
sessionTodo: {} as never,
builtinTools: {
backgroundTasks: {} as never,
ptyControls: {} as never,
},
});

assertLocalized(composer.tools);
});

test('every conditional Runtime Host tool has localized Desktop presentation', () => {
assertLocalized([
...buildHostAgentSettingsTools({} as never),
createHostWebSearchTool({} as never),
createHostWebFetchTool({} as never),
...buildHistoryTools({} as never),
buildScheduledTaskTool({} as never),
...buildGoalTools({} as never),
...buildParentAgentTools(),
buildSubmitPlanTool({} as never),
buildUpdatePlanTool({} as never, 'presentation-contract'),
buildCancelPlanTool({} as never, 'presentation-contract'),
...buildDeepResearchTools({} as never),
...buildAgentGraphSupervisorTools({ graphId: 'presentation-contract' } as never),
buildAgentSwarmStatusTool({} as never),
...buildMemoryExtractionTriggerTools({} as never),
createToolResultArchiveCapability({} as never).archiveReadTool,
]);
});

test('every Desktop-owned tool has localized presentation', () => {
const tools = [
...buildBrowserTools(),
...buildComputerUseTools({ backend: {} as never }),
...buildClientSettingsTools({} as never),
buildRiveWorkflowTool(),
];

assertLocalized(tools);
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
type ClientCapabilityServiceCallFrame,
} from '@maka/runtime-host/protocol';
import { z } from 'zod';
import { buildBrowserTools } from '../browser/browser-tools.js';
import { buildClientSettingsTools } from '../client-settings-tools.js';
import { browserOriginAdmission } from '../browser/browser-origin-admission.js';
import { buildRiveWorkflowTool } from '../rive-workflow-tool.js';
Expand Down Expand Up @@ -84,6 +85,22 @@ test('publishes self-described session-affine Browser and Computer Use offers',
);
});

test('preserves built-in Browser labels for non-localized consumers', () => {
const provider = createDesktopNativeCapabilityProvider({
browserTools: buildBrowserTools(),
resolveBrowserUrl: () => 'https://example.com/',
releaseBrowserSession() {},
computerUseTools: computerTools(),
releaseComputerUseSession() {},
});

assert.deepEqual(
provider.offers().find((offer) => offer.offerId === 'desktop_browser')
?.tools.map((tool) => tool.annotations?.title),
['浏览器导航', '浏览器快照', '浏览器点击', '浏览器输入', '浏览器等待', '浏览器提取'],
);
});

test('remote providers do not request Host paths and use a Client-owned cwd', async () => {
let invokedCwd: string | undefined;
const provider = createDesktopNativeCapabilityProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ test('Runtime Host transcripts produce title and content hits with turn ids', as
ts: 1,
text: '第 3 个问题:这一段的调用链路是怎样的?',
},
{
type: 'tool_call',
id: 'browser-call',
turnId: 'turn-host-3',
ts: 2,
toolName: 'mcp__desktop_browser__browser_navigate',
displayName: 'browser_navigate',
intent: '打开检查页面',
args: {},
},
{
type: 'tool_result',
id: 'browser-result',
turnId: 'turn-host-3',
ts: 3,
toolUseId: 'browser-call',
isError: true,
content: { kind: 'text', text: '检查页面失败' },
},
],
close: async () => {
closed += 1;
Expand All @@ -70,6 +89,7 @@ test('Runtime Host transcripts produce title and content hits with turn ids', as
assert.deepEqual(titleHits[0]?.target, {
kind: 'thread',
sessionId: 'searchable-session',
matchKind: 'session_title',
});

const contentHits = expectResults(
Expand All @@ -86,8 +106,21 @@ test('Runtime Host transcripts produce title and content hits with turn ids', as
sessionId: 'searchable-session',
turnId: 'turn-host-3',
sequence: 0,
matchKind: 'user_message',
});

const toolHit = expectResults(
await handler({} as never, { source: 'thread', query: '打开检查', limit: 10 }),
)[0];
assert.deepEqual(toolHit?.target?.tool, {
name: 'mcp__desktop_browser__browser_navigate',
displayName: 'browser_navigate',
});
assert.equal(closed, 2);
const resultHit = expectResults(
await handler({} as never, { source: 'thread', query: '检查页面失败', limit: 10 }),
)[0];
assert.equal(resultHit?.target?.toolResultIsError, true);
assert.equal(closed, 4);
});

test('a Runtime Host transcript failure yields no content hit', async () => {
Expand Down Expand Up @@ -128,6 +161,9 @@ function expectResults(outcome: unknown): Array<{
sessionId: string;
turnId?: string;
sequence?: number;
matchKind?: string;
tool?: { name: string; displayName?: string };
toolResultIsError?: boolean;
};
}> {
if (!Array.isArray(outcome)) {
Expand Down
10 changes: 5 additions & 5 deletions apps/desktop/src/main/__tests__/streaming-handoff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('single live-turn handoff', () => {
assert.equal((markup.match(/data-transient-message-id=/g) ?? []).length, 2);
});

it('renders one ordered timeline: thinking before its tool and answer', () => {
it('renders thinking, answer, and tool in one ordered timeline', () => {
const markup = renderLiveTurn({
turnId: 'turn-1',
phase: 'streamed',
Expand All @@ -215,7 +215,8 @@ describe('single live-turn handoff', () => {
text: { text: '最终答案', truncated: false, complete: true },
tools: [{
toolUseId: 'tool-1',
toolName: 'Bash',
toolName: 'mcp__fixture__ordered_tool',
displayName: 'Timeline tool marker',
stepId: 'assistant-1',
status: 'running',
args: {},
Expand All @@ -226,9 +227,8 @@ describe('single live-turn handoff', () => {

// Thinking and tools own their disclosures; do not wrap them in another.
assert.equal((markup.match(/maka-processing-block/g) ?? []).length, 0);
assert.ok(markup.indexOf('深度思考') >= 0);
assert.ok(markup.indexOf('深度思考') < markup.indexOf('最终答案'));
assert.ok(markup.indexOf('最终答案') < markup.indexOf('Bash'));
assert.ok(markup.indexOf('先检查') < markup.indexOf('最终答案'));
assert.ok(markup.indexOf('最终答案') < markup.indexOf('Timeline tool marker'));
assert.equal((markup.match(/data-turn-id=/g) ?? []).length, 1);
});

Expand Down
20 changes: 20 additions & 0 deletions apps/desktop/src/main/__tests__/thread-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ describe('thread search text projection', () => {
);
assert.equal(hits[0]?.target?.matchKind, 'tool_result');
assert.equal(hits[0]?.target?.messageId, 'tr1');
assert.equal(hits[0]?.target?.toolResultIsError, false);
});

it('indexes tool intent but not tool names or display names', async () => {
Expand All @@ -562,6 +563,25 @@ describe('thread search text projection', () => {
assert.equal(hits.length, 1);
assert.equal(hits[0]?.target?.matchKind, 'tool_intent');
assert.equal(hits[0]?.target?.messageId, 'tc1');
assert.deepEqual(hits[0]?.target?.tool, {
name: 'Bash',
displayName: 'Shell command',
});
});

it('redacts tool labels in result metadata', async () => {
const message = {
...toolCall('find the metadata needle'),
displayName: 'token=secret-search-label',
};
const hits = expectResults(
await runThreadSearch(
{ source: 'thread', query: 'metadata needle', limit: 5 },
makeDeps({ s1: { session: session({ id: 's1' }), messages: [message] } }),
),
);

assert.equal(hits[0]?.target?.tool?.displayName, 'token=[redacted]');
});

it('indexes assistant answers without exposing thinking', async () => {
Expand Down
5 changes: 5 additions & 0 deletions apps/desktop/src/main/runtime-host-search-ipc-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function projectDesktopSearchResult(result: SearchResult): SearchResult {
sessionId: result.target.sessionId,
...(result.target.turnId !== undefined ? { turnId: result.target.turnId } : {}),
...(result.target.sequence !== undefined ? { sequence: result.target.sequence } : {}),
...(result.target.matchKind !== undefined ? { matchKind: result.target.matchKind } : {}),
...(result.target.tool !== undefined ? { tool: result.target.tool } : {}),
...(result.target.toolResultIsError !== undefined
? { toolResultIsError: result.target.toolResultIsError }
: {}),
},
};
}
4 changes: 4 additions & 0 deletions packages/core/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export type SearchResultTarget = {
messageId?: string;
/** Stable machine-readable classification of the matched transcript surface. */
matchKind?: ThreadSearchMatchKind;
/** Tool identity for UI-owned presentation of tool-intent matches. */
tool?: { name: string; displayName?: string };
/** Outcome for UI-owned presentation of tool-result matches. */
toolResultIsError?: boolean;
/** Timestamp of the matched stored message; absent for session-title matches. */
messageTimestamp?: number;
};
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ export interface ToolCallMessage {
toolName: string;
/** Stable semantic category for presentation; absent on legacy rows. */
activityKind?: ToolActivityKind;
/** Provider/compatibility label; built-in UI copy must resolve from toolName and the active locale. */
displayName?: string;
intent?: string;
args: unknown;
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/thread-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,17 @@ export async function runThreadSearch(
sequence: messageIndex,
messageId: message.id,
matchKind: threadSearchMatchKind(message),
...(message.type === 'tool_call'
? {
tool: {
name: message.toolName,
...(message.displayName
? { displayName: redactSecrets(message.displayName) }
: {}),
},
}
: {}),
...(message.type === 'tool_result' ? { toolResultIsError: message.isError } : {}),
messageTimestamp: message.ts,
},
});
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"./execution-candidate-main": "./dist/execution-candidate-main.js",
"./server": "./dist/server/index.js",
"./test-only/client-capability-host": "./dist/test-only/client-capability-host.js",
"./test-only/interactive-run-composer": "./dist/test-only/interactive-run-composer.js",
"./test-only/execution-candidate-e2e-main": "./dist/test-only/execution-candidate-e2e-main.js"
},
"scripts": {
Expand Down
23 changes: 23 additions & 0 deletions packages/runtime-host/src/test-only/interactive-run-composer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { createInteractiveRunComposer } from '../server/interactive-run-composer.js';
export { buildHostAgentSettingsTools } from '../server/agent-settings-tools.js';
export { createHostWebFetchTool } from '../server/web-fetch-tool.js';
export { createHostWebSearchTool } from '../server/web-search-tool.js';
1 change: 1 addition & 0 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"./session-manager": "./dist/session-manager.js",
"./session-todo-tools": "./dist/session-todo-tools.js",
"./test-only/fake-backend": "./dist/test-only/fake-backend.js",
"./test-only/tool-presentation": "./dist/test-only/tool-presentation.js",
"./test-only/observation-text-reader": "./dist/__tests__/observation-text-reader.js",
"./filesystem-worker": "./dist/filesystem-worker/index.js",
"./sandbox": "./dist/sandbox/index.js",
Expand Down
Loading
Loading