Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(pi): return a valid AgentToolResult and request raw JSON
Alex Musichencf5eb61c20d0
diff --git a/src/cli/client_adapter.c b/src/cli/client_adapter.cindex dd7e62570..f0c92a3fa 100644--- a/src/cli/client_adapter.c+++ b/src/cli/client_adapter.c@@ -164,7 +164,7 @@ char *cbm_client_adapter_pi(const char *binary_path) {sb_append(&sb, "async function call(tool, args, signal) {\n"" return new Promise((resolve) => {\n"- " const child = spawn(BIN, ['cli', tool, JSON.stringify(args ?? {})], {\n"+ " const child = spawn(BIN, ['cli', '--json', tool, JSON.stringify(args ?? {})], {\n"" stdio: ['ignore', 'pipe', 'pipe'],\n"" env: { ...process.env, CBM_LOG_LEVEL: 'error' },\n"" });\n"@@ -218,9 +218,20 @@ char *cbm_client_adapter_pi(const char *binary_path) {* literal; embedding it directly keeps the generated module free of a* JSON.parse indirection and of any escaping drift. */sb_append(&sb, schema ? schema : "{}");- sb_append(&sb, ",\n execute: (args, ctx) => call(");+ sb_append(&sb, ",\n execute: async (args, ctx) => {\n");+ sb_append(&sb, " const result = await call(");sb_append_js_string(&sb, name);- sb_append(&sb, ", args, ctx?.signal),\n });\n");+ sb_append(&sb,+ ", args, ctx?.signal);\n"+ " if (result && typeof result === 'object' && result.error) {\n"+ " throw new Error(String(result.error));\n"+ " }\n"+ " const content = result && Array.isArray(result.content)\n"+ " ? result.content\n"+ " : [{ type: 'text', text: JSON.stringify(result ?? null, null, 2) }];\n"+ " return { content, details: result ?? {} };\n"+ " },\n"+ " });\n");}sb_append(&sb, "}\n");diff --git a/tests/test_agent_clients.c b/tests/test_agent_clients.cindex d8dd7026e..f15e69a66 100644--- a/tests/test_agent_clients.c+++ b/tests/test_agent_clients.c@@ -1122,11 +1122,15 @@ TEST(client_adapter_pi_default_exports_its_factory_issue1550) {TEST(client_adapter_pi_emits_parameters_and_execute) {char *js = cbm_client_adapter_pi("/usr/local/bin/codebase-memory-mcp");ASSERT_NOT_NULL(js);- ASSERT_NOT_NULL(strstr(js, "execute: (args, ctx) => call("));+ ASSERT_NOT_NULL(strstr(js, "execute: async (args, ctx) => {"));+ ASSERT_NOT_NULL(strstr(js, "result.content"));ASSERT_NULL(strstr(js, "run: (args, ctx)"));ASSERT_NOT_NULL(strstr(js, "parameters:"));/* The registry input_schema is embedded as a JSON object literal. */ASSERT_NOT_NULL(strstr(js, "\"type\":\"object\""));+ /* Raw JSON output is required so the bridge can parse the MCP result; the+ * human-readable path would leave `call` with nothing to JSON.parse. */+ ASSERT_NOT_NULL(strstr(js, "'cli', '--json'"));free(js);PASS();}