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。

fix(auto-review): 文字渠道确认提示显示具体操作(微信/钉钉/企业微信共用操作摘要)

Dashcad7efe65ccc
diff --git a/apps/desktop/src/main/im/dingtalk/__tests__/interaction.test.ts b/apps/desktop/src/main/im/dingtalk/__tests__/interaction.test.ts
index 787ed53aa4..bf8455e083 100644
--- a/apps/desktop/src/main/im/dingtalk/__tests__/interaction.test.ts
+++ b/apps/desktop/src/main/im/dingtalk/__tests__/interaction.test.ts
@@ -36,6 +36,20 @@ describe('dingtalk text interactions', () => {
});
});
+ // 2026-10-24 review: text channels showed only the tool name, so a safe and a destructive
+ // Bash call looked identical. They now share the desktop/phone operation summary.
+ it('确认提示显示要执行的具体操作和审核原因', () => {
+ const prompt = __testing.formatInteractionPrompt({
+ kind: 'permission',
+ requestId: 'request-2',
+ toolName: 'Bash',
+ input: { command: 'xcrun simctl delete all' },
+ metadata: { autoReviewReason: '这会删除所有模拟器。' },
+ });
+ expect(prompt).toContain('操作:xcrun simctl delete all');
+ expect(prompt).toContain('自动审批需要你决定:这会删除所有模拟器。');
+ });
+
it('自动审批故障时在钉钉确认提示里写明原因', () => {
const ordinary = __testing.formatInteractionPrompt({
kind: 'permission',
diff --git a/apps/desktop/src/main/im/dingtalk/interaction.ts b/apps/desktop/src/main/im/dingtalk/interaction.ts
index 21677db314..f9d8edc7bb 100644
--- a/apps/desktop/src/main/im/dingtalk/interaction.ts
+++ b/apps/desktop/src/main/im/dingtalk/interaction.ts
@@ -1,7 +1,7 @@
import type { InteractionDecision, InteractionRequest } from '@cindy/maker-core';
import type { DingTalkIM } from '@cindy/im';
-import { autoReviewUnavailablePromptLine, permissionPromptDescription } from '../shared/autoReviewUnavailablePrompt';
+import { autoReviewUnavailablePromptLine, permissionOperationPreview, permissionPromptDescription } from '../shared/autoReviewUnavailablePrompt';
import type { SharedPermission } from '../../maker-ipc/sharedPermission';
import { permissionOutcomeText } from '../shared/permissionPresentation';
@@ -54,6 +54,7 @@ function formatInteractionPrompt(request: InteractionRequest): string {
`需要确认操作:${request.toolName}`,
...(permissionPromptDescription(request) ? [permissionPromptDescription(request)!] : []),
...(unavailable ? [unavailable] : []),
+ ...(permissionOperationPreview(request) ? [`操作:${permissionOperationPreview(request)}`] : []),
'回复“允许”继续,或回复“拒绝”取消。',
].join('\n');
}
diff --git a/apps/desktop/src/main/im/shared/autoReviewUnavailablePrompt.ts b/apps/desktop/src/main/im/shared/autoReviewUnavailablePrompt.ts
index b79c7e1aee..9ab31192fc 100644
--- a/apps/desktop/src/main/im/shared/autoReviewUnavailablePrompt.ts
+++ b/apps/desktop/src/main/im/shared/autoReviewUnavailablePrompt.ts
@@ -1,3 +1,4 @@
+import { describePermissionAction } from '@cindy/maker-shared/interaction';
import {
AUTO_REVIEW_UNAVAILABLE_PROMPT_TEXT,
autoReviewReasonFromMetadata,
@@ -34,3 +35,26 @@ export function permissionPromptDescription(request: InteractionRequest): string
if (!request.description.endsWith(AUTO_REVIEW_UNAVAILABLE_PROMPT_TEXT)) return request.description;
return request.description.slice(0, -AUTO_REVIEW_UNAVAILABLE_PROMPT_TEXT.length).trim() || undefined;
}
+
+const TEXT_PERMISSION_PREVIEW_MAX = 800;
+
+/**
+ * 文字渠道确认提示里「要执行的具体操作」:与桌面、手机、富卡、Hook 共用
+ * describePermissionAction,命令 / 文件 / 插件 / 浏览器步骤直接给出,认不出的工具给格式化 JSON。
+ * 反引号转义,避免模型控制的内容破坏提示里的代码围栏。
+ */
+export function permissionOperationPreview(request: InteractionRequest): string {
+ if (request.kind !== 'permission') return '';
+ if (!request.input || Object.keys(request.input).length === 0) return '';
+ let text: string;
+ try {
+ const action = describePermissionAction(request.toolName, request.input ?? {});
+ text = action.kind === 'tool' ? JSON.stringify(request.input ?? {}, null, 2) : action.preview;
+ } catch {
+ return '<无法序列化>';
+ }
+ if (!text) return '';
+ const clipped = text.length > TEXT_PERMISSION_PREVIEW_MAX
+ ? `${text.slice(0, TEXT_PERMISSION_PREVIEW_MAX)}\n…(已截断)` : text;
+ return clipped.replaceAll('`', '\\u0060');
+}
diff --git a/apps/desktop/src/main/im/wechat/WechatIM.ts b/apps/desktop/src/main/im/wechat/WechatIM.ts
index fe2e59dda7..cac0c1bbe5 100644
--- a/apps/desktop/src/main/im/wechat/WechatIM.ts
+++ b/apps/desktop/src/main/im/wechat/WechatIM.ts
@@ -28,7 +28,7 @@ import type { InteractionDecision, InteractionRequest } from '@cindy/maker-core'
import type { SharedPermission } from '../../maker-ipc/sharedPermission';
import { INTERACTION_CHOICE_RECEIVED_TEXT, permissionOutcomeText } from '../shared/permissionPresentation';
-import { autoReviewUnavailablePromptLine, permissionPromptDescription } from '../shared/autoReviewUnavailablePrompt';
+import { autoReviewUnavailablePromptLine, permissionOperationPreview, permissionPromptDescription } from '../shared/autoReviewUnavailablePrompt';
import { buildImReplyContextBlock } from '../shared/replyContext';
import { captureImContext } from '../../../shared/imMessageSource';
import type { ImSessionRepo } from '../shared/sessionRepo';
@@ -2112,7 +2112,7 @@ function formatWechatInteractionPrompt(request: InteractionRequest): string {
const unavailable = autoReviewUnavailablePromptLine(request);
return `需要确认工具“${request.displayName ?? request.toolName}”。
${permissionPromptDescription(request) ?? ''}
-${unavailable ? `${unavailable}\n` : ''}回复“允许”执行一次,或回复“拒绝”取消本次操作。微信内不支持永久授权。`;
+${unavailable ? `${unavailable}\n` : ''}${permissionOperationPreview(request) ? `操作:\n${permissionOperationPreview(request)}\n` : ''}回复“允许”执行一次,或回复“拒绝”取消本次操作。微信内不支持永久授权。`;
}
if (request.kind === 'plan_review') {
const plan = request.plan.length > 6_000 ? `${request.plan.slice(0, 6_000)}…` : request.plan;
diff --git a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
index 4866c1bf75..40b3f6d683 100644
--- a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
+++ b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
@@ -317,6 +317,18 @@ describe('WechatIM host boundary', () => {
});
});
+ it('确认提示显示要执行的具体操作和审核原因', () => {
+ const prompt = __testing.formatWechatInteractionPrompt({
+ kind: 'permission',
+ requestId: 'request-2',
+ toolName: 'mcp:cindy_browser:call_tool',
+ input: { name: 'browser', args: { action: 'click', selector: '[data-testid="tweetButton"]' } },
+ metadata: { autoReviewReason: '这会公开发帖。' },
+ });
+ expect(prompt).toContain('操作:\nclick {"selector":"[data-testid=\\"tweetButton\\"]"}');
+ expect(prompt).toContain('自动审批需要你决定:这会公开发帖。');
+ });
+
it('自动审批故障时在微信确认提示里写明原因', () => {
const ordinary = __testing.formatWechatInteractionPrompt({
kind: 'permission',
diff --git a/apps/desktop/src/main/im/wecom/__tests__/textInteractions.test.ts b/apps/desktop/src/main/im/wecom/__tests__/textInteractions.test.ts
index 8a089e0df4..df86528e98 100644
--- a/apps/desktop/src/main/im/wecom/__tests__/textInteractions.test.ts
+++ b/apps/desktop/src/main/im/wecom/__tests__/textInteractions.test.ts
@@ -77,8 +77,8 @@ describe('formatWecomInteractionPrompt', () => {
);
expect(prompt).toContain('需要确认工具“运行命令”');
- expect(prompt).toContain('"command": "pnpm test"');
- expect(prompt).toContain('"path": "D:\\\\workspace\\\\cindy"');
+ // Shell tools show the command itself, not a JSON envelope.
+ expect(prompt).toContain('操作:\n```\npnpm test\n```');
expect(prompt).toContain('回复“允许”执行一次');
expect(prompt).not.toContain('自动审批没完成');
});
diff --git a/apps/desktop/src/main/im/wecom/textInteractions.ts b/apps/desktop/src/main/im/wecom/textInteractions.ts
index 51fcc6847e..970678e391 100644
--- a/apps/desktop/src/main/im/wecom/textInteractions.ts
+++ b/apps/desktop/src/main/im/wecom/textInteractions.ts
@@ -1,7 +1,7 @@
import type { InteractionDecision, InteractionRequest } from '@cindy/maker-core';
import { escapeWecomMarkdown, type IMMessageEvent, type WecomIM } from '@cindy/im';
-import { autoReviewUnavailablePromptLine, permissionPromptDescription } from '../shared/autoReviewUnavailablePrompt';
+import { autoReviewUnavailablePromptLine, permissionOperationPreview, permissionPromptDescription } from '../shared/autoReviewUnavailablePrompt';
import { isStopCommand } from '../shared/controlCommands';
import type { SharedPermission } from '../../maker-ipc/sharedPermission';
import { INTERACTION_CHOICE_RECEIVED_TEXT, permissionOutcomeText } from '../shared/permissionPresentation';
@@ -13,7 +13,6 @@ interface PendingInteraction {
}
const INTERACTION_TIMEOUT_MS = 10 * 60_000;
-const MAX_PERMISSION_INPUT_PREVIEW = 800;
export class WecomTextInteractions {
private readonly pending = new Map<string, PendingInteraction>();
@@ -105,21 +104,6 @@ export class WecomTextInteractions {
}
}
-function previewPermissionInput(input: Record<string, unknown>): string {
- try {
- const json = JSON.stringify(input, null, 2);
- if (!json) return '<无法序列化>';
- const preview = json.length > MAX_PERMISSION_INPUT_PREVIEW
- ? `${json.slice(0, MAX_PERMISSION_INPUT_PREVIEW)}\n…(已截断)`
- : json;
- // Keep the surrounding template fence intact even when a string value
- // contains model-controlled backticks. JSON's unicode escape stays valid.
- return preview.replaceAll('`', '\\u0060');
- } catch {
- return '<无法序列化>';
- }
-}
-
export function formatWecomInteractionPrompt(request: InteractionRequest): string {
if (request.kind === 'permission') {
const toolName = escapeWecomMarkdown(request.displayName ?? request.toolName);
@@ -127,10 +111,11 @@ export function formatWecomInteractionPrompt(request: InteractionRequest): strin
return `需要确认工具“${toolName}”。
${permissionPromptDescription(request) ?? ''}
${unavailable ? `\n${unavailable}\n` : ''}
-参数:
-\`\`\`json
-${previewPermissionInput(request.input)}
+${permissionOperationPreview(request) ? `操作:
+\`\`\`
+${permissionOperationPreview(request)}
\`\`\`
+` : ''}
回复“允许”执行一次,或回复“拒绝”取消本次操作。企业微信内不支持永久授权。`;
}