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
3 changes: 2 additions & 1 deletion apps/desktop/e2e/fixture-thread-search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('fixture-seeded transcripts return content hits with turn ids', async ({
hit.target?.kind === 'thread' &&
hit.target.turnId === 'turn-prompt-rail-3',
);
expect(content?.summary).toBe('用户消息');
expect(content?.summary).toBeUndefined();
if (!content || content.target?.kind !== 'thread') {
throw new Error(`expected a thread search hit, got ${JSON.stringify(content)}`);
}
Expand All @@ -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
Expand Up @@ -29,6 +29,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 { buildRiveWorkflowTool } from '../rive-workflow-tool.js';
import { createDesktopNativeCapabilityProvider } from '../runtime-host-native-capabilities.js';
Expand Down Expand Up @@ -81,6 +82,21 @@ 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(),
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 @@ -66,10 +85,11 @@ test('Runtime Host transcripts produce title and content hits with turn ids', as
limit: 10,
}),
);
assert.equal(titleHits[0]?.summary, '任务标题');
assert.equal(titleHits[0]?.summary, undefined);
assert.deepEqual(titleHits[0]?.target, {
kind: 'thread',
sessionId: 'searchable-session',
matchKind: 'session_title',
});

const contentHits = expectResults(
Expand All @@ -80,14 +100,27 @@ test('Runtime Host transcripts produce title and content hits with turn ids', as
}),
);
assert.equal(contentHits.length, 1);
assert.equal(contentHits[0]?.summary, '用户消息');
assert.equal(contentHits[0]?.summary, undefined);
assert.deepEqual(contentHits[0]?.target, {
kind: 'thread',
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 @@ -185,7 +185,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 @@ -195,7 +195,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 @@ -206,9 +207,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
24 changes: 22 additions & 2 deletions apps/desktop/src/main/__tests__/thread-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ describe('runThreadSearch', () => {
sessionId: 's1',
matchKind: 'session_title',
});
assert.equal(titleHit.summary, '任务标题');
assert.equal(titleHit.summary, undefined);
assert.equal(titleHit.url, undefined);
assert.match(titleHit.snippet ?? '', /\[redacted\]/);
assert.equal(titleHit.snippet?.includes('sk-ant-test-secret-token-12345'), false);
Expand All @@ -445,7 +445,7 @@ describe('runThreadSearch', () => {
matchKind: 'user_message',
messageTimestamp: 1_700_000_000_000,
});
assert.equal(messageHit.summary, '用户消息');
assert.equal(messageHit.summary, undefined);
assert.equal(messageHit.url, undefined);
});

Expand Down 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: 3 additions & 2 deletions apps/desktop/src/main/runtime-host-boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { type ConnectionEvent } from '@maka/core/connections';
import { type SessionChangedEvent, type SessionChangedReason } from '@maka/core/session';
import { isBotDeliveryProvider } from '@maka/core/bot-chat-settings';
import { resolveSystemUiLocale } from '@maka/core/ui-locale';
import { DESKTOP_BUILTIN_TOOL_OFFER_IDS } from '@maka/core/tool-catalog';
import {
PROVIDER_DEFAULTS,
providerAuthRequiresSecret,
Expand Down Expand Up @@ -772,14 +773,14 @@ runtimeHostManager = await startRuntimeHostDesktopManager(
const mcpTools = buildMcpTools(mcpManager);
return [
{
offerId: "desktop_settings",
offerId: DESKTOP_BUILTIN_TOOL_OFFER_IDS.settings,
label: "Client settings",
description:
"Read or update UI and operating-system settings owned by this Desktop client.",
tools: clientSettingsTools,
},
{
offerId: "desktop_rive",
offerId: DESKTOP_BUILTIN_TOOL_OFFER_IDS.rive,
label: "Rive",
description:
"Use durable Rive workflows through this Desktop client.",
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src/main/runtime-host-native-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { Buffer } from "node:buffer";
import { DESKTOP_BUILTIN_TOOL_OFFER_IDS } from '@maka/core/tool-catalog';
import type { ComputerUseToolSet } from '@maka/runtime/computer-use-tools';
import type { MakaTool } from '@maka/runtime/tool-runtime';
import {
Expand All @@ -38,8 +39,8 @@ import { toJSONSchema, z } from "zod";
import type { DesktopTargetScope } from '../shared/runtime-host-identity.js';

const CAPABILITY_VERSION = "0";
const BROWSER_OFFER_ID = "desktop_browser";
const COMPUTER_USE_OFFER_ID = "desktop_computer_use";
const BROWSER_OFFER_ID = DESKTOP_BUILTIN_TOOL_OFFER_IDS.browser;
const COMPUTER_USE_OFFER_ID = DESKTOP_BUILTIN_TOOL_OFFER_IDS.computerUse;

export interface DesktopCapabilityGroup {
readonly offerId: string;
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 @@ -829,6 +829,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
38 changes: 11 additions & 27 deletions packages/core/src/thread-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ export async function runThreadSearch(
results.push({
source: THREAD_SOURCE,
title: searchableTitle,
summary: '任务标题',
snippet,
target: {
kind: 'thread',
Expand Down Expand Up @@ -339,7 +338,6 @@ export async function runThreadSearch(
results.push({
source: THREAD_SOURCE,
title: redactSecrets(session.name),
summary: formatSearchResultSummary(message),
snippet,
// PR-SEARCH-1.5: navigation target via discriminated union; no
// `url` field for thread results (maka://session is deferred).
Expand All @@ -350,6 +348,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 Expand Up @@ -471,31 +480,6 @@ export function threadSearchMatchKind(message: StoredMessage): ThreadSearchMatch
}
}

export function formatSearchResultSummary(message: StoredMessage): string {
switch (message.type) {
case 'user':
return '用户消息';
case 'assistant':
return '助手回复';
case 'tool_call':
return message.displayName
? `工具调用:${message.displayName}`
: `工具调用:${message.toolName}`;
case 'tool_result':
return message.isError ? '工具结果:失败' : '工具结果:成功';
case 'permission_decision':
return '权限记录';
case 'token_usage':
return '用量记录';
case 'turn_state':
return '回合状态';
case 'workhub_coordination':
return 'WorkHub 协调记录';
case 'system_note':
return '系统记录';
}
}

/**
* Extract user-visible answer text from a stored message. Returns `undefined`
* for excluded message kinds (system notes, token usage, turn state,
Expand Down
Loading