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): 确认卡解析字符串化的渐进式工具参数

Dash96313a00af21
diff --git a/packages/maker-shared/src/__tests__/interaction.test.ts b/packages/maker-shared/src/__tests__/interaction.test.ts
index 6e87fef2d8..da0cd814c9 100644
--- a/packages/maker-shared/src/__tests__/interaction.test.ts
+++ b/packages/maker-shared/src/__tests__/interaction.test.ts
@@ -308,6 +308,13 @@ describe('interaction shared model', () => {
expect(describePermissionAction('mcp:cindy_browser:call_tool', {
name: 'browser', args: { action: 'recipe', recipeId: 'post-reply', site: 'x.com', text: 'hello' },
}).preview).toBe('recipe {"recipeId":"post-reply","site":"x.com","text":"hello"}');
+ // call_tool.args stringified by the caller (issue #350) is parsed like the approval policy does.
+ expect(describePermissionAction('mcp:cindy_browser:call_tool', {
+ name: 'browser', args: JSON.stringify({ action: 'recipe', recipeId: 'post-reply' }),
+ }).preview).toBe('recipe {"recipeId":"post-reply"}');
+ expect(describePermissionAction('mcp:cindy:ghost_call', {
+ ghost_id: 'cindy-github', tool: 'call_tool', args: JSON.stringify({ name: 'get_user', args: JSON.stringify({ username: 'octo' }) }),
+ }).preview).toBe('get_user {"username":"octo"}');
expect(describePermissionAction('file_change', { changes: [
{ path: '/repo/a.ts', kind: { type: 'update', move_path: '/repo/b.ts' }, diff: '@@ -1 +1 @@' },
{ path: '/repo/old.ts', kind: { type: 'delete' } },
diff --git a/packages/maker-shared/src/interaction.ts b/packages/maker-shared/src/interaction.ts
index c24a3d07fb..18d8c4897d 100644
--- a/packages/maker-shared/src/interaction.ts
+++ b/packages/maker-shared/src/interaction.ts
@@ -899,6 +899,14 @@ function previewOf(value: unknown): string {
return text.length > 500 ? `${text.slice(0, 500)}...` : text;
}
+/** Progressive `call_tool.args` may arrive as a JSON string (issue #350); approval parses it the same way. */
+function argsObject(value: unknown): Record<string, unknown> {
+ if (typeof value === 'string') {
+ try { value = JSON.parse(value); } catch { return {}; }
+ }
+ return isRecord(value) ? value : {};
+}
+
/** One-line arguments after the tool name; empty when there are none. */
function argsPreview(args: Record<string, unknown>): string {
if (!Object.keys(args).length) return '';
@@ -949,7 +957,7 @@ export function describePermissionAction(toolName: string, input: Record<string,
const name = toolName.toLowerCase();
// Progressive MCP dispatchers: mcp__server__call_tool / mcp:server:call_tool → inner tool.
const innerName = readString(input.name);
- const innerArgs = isRecord(input.args) ? input.args : {};
+ const innerArgs = argsObject(input.args);
if (name.includes('browser') || innerName === 'browser') {
return { kind: 'browser', preview: browserStep(innerName === 'browser' ? innerArgs : input) };
}
@@ -958,7 +966,7 @@ export function describePermissionAction(toolName: string, input: Record<string,
const tool = readString(input.tool);
const dispatched = tool === 'call_tool' && readString(innerArgs.name);
const call = dispatched || tool;
- const args = dispatched ? (isRecord(innerArgs.args) ? innerArgs.args : {}) : innerArgs;
+ const args = dispatched ? argsObject(innerArgs.args) : innerArgs;
return { kind: 'plugin', subject: readString(input.ghost_id)!, preview: [call, argsPreview(args)].filter(Boolean).join(' ') || previewOf(input) };
}
if (COMMAND_TOOLS.has(name)) {