Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(agent-island): 优先显示可读的工具状态说明

zcinta05146858f1f49795
diff --git a/apps/desktop/src/main/agent-island/__tests__/state.test.ts b/apps/desktop/src/main/agent-island/__tests__/state.test.ts
index a008d949d2..0ee912e9b4 100644
--- a/apps/desktop/src/main/agent-island/__tests__/state.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/state.test.ts
@@ -478,7 +478,7 @@ describe('Agent Island display state', () => {
expect(display.sessions[0]).toMatchObject({
sessionId: 's1',
projectName: 'xdt-maker',
- detail: 'imagegen',
+ detail: '正在调用工具…',
activityLines: [
{ id: '1', kind: 'user', text: '正在执行绘画命令 请生成一张图' },
{ id: '2', kind: 'assistant', text: '我会开始生成图片。' },
@@ -685,6 +685,24 @@ describe('Agent Island display state', () => {
});
});
+ // #7474, unit: the public event -> display/activity snapshot path must not
+ // fall back to an internal tool name when a real event has no input payload.
+ it('publishes readable tool activity even when input is absent', () => {
+ const state = createAgentIslandState();
+ setAgentIslandToolWording(state, {
+ ...DEFAULT_TOOL_ROW_WORDING,
+ toolCallLabel: () => 'Calling a tool…',
+ });
+ applyAgentIslandEvent(state, { sessionId: 's1', title: 'Task', agentKind: 'codex' }, {
+ type: 'tool_use',
+ source: 'codex',
+ data: { toolUseId: 'tool-1', toolName: 'mcp:server:read_by_url' },
+ }, 1_000);
+
+ expect(buildAgentIslandDisplayState(state, 1_050).sessions[0]?.detail).toBe('Calling a tool…');
+ expect(buildAllSessionActivitySnapshots(state)[0]?.detail).toBe('Calling a tool…');
+ });
+
it('keeps the raw shell command when no intent rule classifies it', () => {
const state = createAgentIslandState();
applyAgentIslandEvent(
diff --git a/apps/desktop/src/main/agent-island/__tests__/toolDetail.test.ts b/apps/desktop/src/main/agent-island/__tests__/toolDetail.test.ts
index 987a74210c..ab44cd353d 100644
--- a/apps/desktop/src/main/agent-island/__tests__/toolDetail.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/toolDetail.test.ts
@@ -46,7 +46,7 @@ describe('formatIslandToolDetail', () => {
expect(detail('WebFetch', { url: 'https://example.com/docs' })).toBe('访问 https://example.com/docs');
expect(detail('TodoWrite', { todos: [] })).toBe('更新待办');
expect(detail('mcp__lizi_feishu__read_by_url', { url: 'https://example.com' }))
- .toBe('调用 lizi_feishu · read by url');
+ .toBe('正在调用工具…');
expect(detail('file_change', {
changes: [
{ path: '/repo/a.ts', kind: { type: 'update' }, diff: '-a\n+b' },
@@ -91,14 +91,15 @@ describe('formatIslandToolDetail', () => {
})).toBe('Needs network access to fetch docs');
});
- it('truncates task descriptions and generic labels to the island cap', () => {
+ it('truncates task descriptions and readable summaries to the island cap', () => {
const longDescription = 'x'.repeat(120);
const taskLabel = detail('Task', { description: longDescription, prompt: 'ignored' });
expect(taskLabel).not.toBeNull();
expect(taskLabel!.length).toBeLessThanOrEqual(80);
- expect(detail('SomeUnknownTool', { anything: true })).toBe('调用 SomeUnknownTool');
- // generic 但 input 有可读细节(DETAIL_KEYS)时,label 后跟细节(对齐面板行)。
- expect(detail('SomeUnknownTool', { query: 'find usages' })).toBe('调用 SomeUnknownTool · find usages');
+ expect(detail('mcp:server:tool', { toolTitle: longDescription })!.length).toBeLessThanOrEqual(80);
+ expect(detail('SomeUnknownTool', { anything: true })).toBe('正在调用工具…');
+ // A query is tool data, not a reliable description of the current action.
+ expect(detail('SomeUnknownTool', { query: 'find usages' })).toBe('正在调用工具…');
});
it('prefers codex tool-side questions over tool shape', () => {
@@ -114,7 +115,33 @@ describe('formatIslandToolDetail', () => {
expect(formatIslandToolDetail('CustomTool', undefined, { wording }, {
displayName: 'Custom Tool',
})).toBe('Custom Tool');
- expect(formatIslandToolDetail('CustomTool', undefined, { wording })).toBeNull();
+ expect(formatIslandToolDetail('CustomTool', undefined, { wording })).toBe('正在调用工具…');
+ });
+
+ // #7474: unit regression through the production formatter. Existing MCP coverage
+ // required internal names and never supplied readable metadata or absent input.
+ it.each([
+ 'mcp__lizi_feishu__read_by_url',
+ 'mcp:lizi_feishu:read_by_url',
+ 'dynamic:tools:read_by_url',
+ 'collab:wait',
+ 'SomeUnknownTool',
+ ])('prefers readable metadata and a localized fallback for %s', (name) => {
+ const localized = { ...wording, toolCallLabel: () => 'Calling a tool…' };
+ expect(formatIslandToolDetail(name, { toolTitle: '读取飞书文档' }, { wording: localized }))
+ .toBe('读取飞书文档');
+ expect(formatIslandToolDetail(name, {}, { wording: localized }, { description: '读取飞书文档' }))
+ .toBe('读取飞书文档');
+ expect(formatIslandToolDetail(name, {}, { wording: localized })).toBe('Calling a tool…');
+ expect(formatIslandToolDetail(name, null, { wording: localized })).toBe('Calling a tool…');
+ });
+
+ it('keeps tool identity and opaque input detail available for permission prompts', () => {
+ expect(detail('mcp__lizi_feishu__read_by_url', {}, true)).toBe('调用 lizi_feishu · read by url');
+ expect(detail('mcp__lizi_feishu__read_by_url', { toolTitle: '读取飞书文档' }, true))
+ .toBe('调用 lizi_feishu · read by url');
+ expect(detail('SomeUnknownTool', { query: 'find usages' }, true))
+ .toBe('调用 SomeUnknownTool · find usages');
});
it('routes wording through the injected implementation', () => {
diff --git a/apps/desktop/src/main/agent-island/toolDetail.ts b/apps/desktop/src/main/agent-island/toolDetail.ts
index c8119c1564..43be4d6231 100644
--- a/apps/desktop/src/main/agent-island/toolDetail.ts
+++ b/apps/desktop/src/main/agent-island/toolDetail.ts
@@ -6,7 +6,7 @@
* 纯模块(无 electron / i18n import),可直接单测;措辞由调用方注入
* (state 持有,默认共享包中文表,service 换成本地化实现)。
*/
-import { formatToolRowText, type ToolRowWording } from '@cindy/maker-shared/message-presentation';
+import { DEFAULT_TOOL_ROW_WORDING, formatToolRowText, type ToolRowWording } from '@cindy/maker-shared/message-presentation';
import { describeToolUse, truncateToolText, type ToolUseDescriptor } from '@cindy/maker-shared/tool-use-descriptor';
/** task 描述与 generic 兜底沿用旧岛的 80 字上限,防长 prompt 撑爆 pill。 */
@@ -29,7 +29,9 @@ export function formatIslandToolDetail(
): string | null {
const toolInput = asRecord(input);
if (!toolInput) {
- return firstNonEmptyString(fallback?.description, fallback?.toolDescription, fallback?.displayName);
+ const description = firstNonEmptyString(fallback?.description, fallback?.toolDescription, fallback?.displayName);
+ if (options.requireCommandVisible) return description;
+ return truncateToolText(description ?? toolCallLabel(options.wording), ISLAND_DETAIL_MAX_CHARS);
}
// codex 工具侧问题(input.questions)优先于工具形态展示。
@@ -42,19 +44,26 @@ export function formatIslandToolDetail(
}
const label = formatToolRowText(descriptor, options.wording).label;
if (!label) return null;
- if (descriptor.kind === 'generic') {
- // 描述符解析不出形态的工具(codex MCP elicitation 的 `mcp:server`、
- // permissions 等):input 里的人话字段与请求级 description 比「调用 X」
- // 更有信息量,优先展示(旧岛行为);都没有时才落 label(+detail)。
+ if (
+ descriptor.kind === 'generic' || descriptor.kind === 'mcp'
+ || descriptor.kind === 'dynamic' || descriptor.kind === 'collab'
+ ) {
+ if (options.requireCommandVisible && descriptor.kind !== 'generic') return label;
+ // Runtime activity is a glanceable summary, not the detailed tool row.
+ // Only explicit action metadata is used; URL/query/prompt are tool data.
const informative = firstNonEmptyString(
- toolInput.message,
+ descriptor.kind === 'generic' ? toolInput.message : null,
toolInput.toolTitle,
toolInput.toolDescription,
fallback?.description,
+ options.requireCommandVisible ? null : fallback?.toolDescription,
+ options.requireCommandVisible ? null : fallback?.displayName,
);
if (informative) return truncateToolText(informative, ISLAND_DETAIL_MAX_CHARS);
+ if (!options.requireCommandVisible) return toolCallLabel(options.wording);
+ // Permission prompts retain the original identity and details being approved.
return truncateToolText(
- descriptor.detail ? `${label} · ${descriptor.detail}` : label,
+ descriptor.kind === 'generic' && descriptor.detail ? `${label} · ${descriptor.detail}` : label,
ISLAND_DETAIL_MAX_CHARS,
);
}
@@ -64,6 +73,10 @@ export function formatIslandToolDetail(
return label;
}
+function toolCallLabel(wording: ToolRowWording): string {
+ return (wording.toolCallLabel ?? DEFAULT_TOOL_ROW_WORDING.toolCallLabel)();
+}
+
/**
* 命令类单行拼接:
* - 模型 description → `描述 · $ 命令`(描述已含命令时不重复);
diff --git a/apps/desktop/src/main/agent-island/toolWording.ts b/apps/desktop/src/main/agent-island/toolWording.ts
index 6da5a945f0..4f3fb26753 100644
--- a/apps/desktop/src/main/agent-island/toolWording.ts
+++ b/apps/desktop/src/main/agent-island/toolWording.ts
@@ -18,6 +18,7 @@ import {
export function createLocalizedToolRowWording(): ToolRowWording {
return {
+ toolCallLabel: () => t('agentIsland.native.callingTool'),
verb: (key) => t(TOOL_ROW_VERB_I18N_KEY[key]),
intentVerb: (action) => t(INTENT_ROW_VERB_KEY[action]),
// main 的迷你 i18n 只支持 {{appName}} 插值,{{count}} 在调用点手动替换。
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 46e29467ea..2886284b3a 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -1182,6 +1182,7 @@
"done": "Done",
"running": "Running",
"networkReconnecting": "({{attempt}}/{{maxAttempts}}) Connection interrupted — reconnecting…",
+ "callingTool": "Calling a tool…",
"updatingTasks": "Updating tasks",
"awaitingPermission": "Awaiting permission",
"awaitingQuestion": "Awaiting your reply",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 33a1a4a002..223949c4e8 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -1170,6 +1170,7 @@
"done": "完了",
"running": "実行中",
"networkReconnecting": "({{attempt}}/{{maxAttempts}})接続が中断されました。再接続中…",
+ "callingTool": "ツールを実行中…",
"updatingTasks": "タスクを更新中",
"awaitingPermission": "承認待ち",
"awaitingQuestion": "返信待ち",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index d79b3ed3d2..5f033c6649 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -1170,6 +1170,7 @@
"done": "완료",
"running": "실행 중",
"networkReconnecting": "({{attempt}}/{{maxAttempts}}) 연결이 끊어졌습니다. 다시 연결하는 중…",
+ "callingTool": "도구 호출 중…",
"updatingTasks": "작업 업데이트 중",
"awaitingPermission": "승인 대기 중",
"awaitingQuestion": "답장 대기 중",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 88fd2309e8..ad18b6baf6 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -1170,6 +1170,7 @@
"done": "完成",
"running": "运行中",
"networkReconnecting": "({{attempt}}/{{maxAttempts}})网络连接中断,正在重新连接…",
+ "callingTool": "正在调用工具…",
"updatingTasks": "正在更新任务",
"awaitingPermission": "等待授权",
"awaitingQuestion": "等待你的回复",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 2d119bbbea..89c1cf9383 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -1170,6 +1170,7 @@
"done": "完成",
"running": "執行中",
"networkReconnecting": "({{attempt}}/{{maxAttempts}})網路連線中斷,正在重新連線…",
+ "callingTool": "正在呼叫工具…",
"updatingTasks": "正在更新任務",
"awaitingPermission": "等待授權",
"awaitingQuestion": "等待你的回覆",
diff --git a/packages/maker-shared/src/messagePresentation.ts b/packages/maker-shared/src/messagePresentation.ts
index ce7fa302ad..66893e33f4 100644
--- a/packages/maker-shared/src/messagePresentation.ts
+++ b/packages/maker-shared/src/messagePresentation.ts
@@ -319,13 +319,16 @@ export interface ToolRowWording {
intentVerb(action: CommandIntentAction): string;
/** fileChange 多文件复合短语("更新 3 个文件");量词与语序语言相关,整短语粒度,count 恒 >= 2。 */
updateFilesLabel(count: number): string;
+ /** Compact activity fallback when no reliable action description is available. */
+ toolCallLabel?(): string;
}
-export const DEFAULT_TOOL_ROW_WORDING: ToolRowWording = {
+export const DEFAULT_TOOL_ROW_WORDING = {
verb: (key) => TOOL_ROW_VERB_ZH[key],
intentVerb: (action) => INTENT_VERB_ZH[action],
updateFilesLabel: (count) => `${TOOL_ROW_VERB_ZH.update} ${count} 个文件`,
-};
+ toolCallLabel: () => '正在调用工具…',
+} satisfies ToolRowWording;
const TOOL_ROW_TEXT_MAX_CHARS = 60;