From 42e320a6cbbff4b4dcac1ef522301fbff2405a21 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Wed, 12 Aug 2026 12:52:46 +0200 Subject: [PATCH] docs(pi): name the loader mechanism behind the default-export requirement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two contributors independently sent the same fix for #1550 while ours was already in CI (#1553 by @musichen, who also reported the bug, and #1564 by @henri-edh). Rather than close both as duplicates, this takes the part of theirs that ours was missing. @henri-edh's comment names the actual mechanism: Pi loads an extension via jiti.import(path, { default: true }) and rejects anything that is not a function, so a named-only export hands the loader the module namespace object and the install fails with "Extension does not export a valid factory function". Ours said "Pi calls the default export" — true, but it does not tell the next reader why a named export cannot simply be added alongside, which is exactly the change someone would try. Their wording is now ours. The assertion is tightened the same way, from `export default function` to `export default function (pi)`, so a default export with the wrong shape cannot satisfy it. Co-Authored-By: musichen Co-Authored-By: henri-edh Signed-off-by: Martin Vogel --- src/cli/client_adapter.c | 13 +++++++------ tests/test_agent_clients.c | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cli/client_adapter.c b/src/cli/client_adapter.c index be00cdb33..839b3d87b 100644 --- a/src/cli/client_adapter.c +++ b/src/cli/client_adapter.c @@ -157,12 +157,13 @@ char *cbm_client_adapter_pi(const char *binary_path) { /* Register every tool the registry advertises — never a hand-picked subset, * which is the drift this generator exists to prevent. * - * DEFAULT export, and it must stay that way: Pi loads an extension by - * calling its default export as a factory. A named `register` export made - * the file fail to load, and a Pi extension that fails to load takes EVERY - * pi command down with it — `pi doctor` included — not just cbm's tools - * (#1550). The named binding is kept alongside for anything that imported - * it by name. */ + * DEFAULT export, and it must stay that way. Pi loads an extension via + * jiti.import(path, { default: true }) and rejects anything that is not a + * function, so a named `export function register(pi)` hands the loader the + * module namespace object instead and every install fails with "Extension + * does not export a valid factory function". A Pi extension that fails to + * load takes EVERY pi command down with it — `pi doctor` included — not + * just cbm's tools (#1550). */ sb_append(&sb, "export default function (pi) {\n"); for (int i = 0; i < count; i++) { const char *name = cbm_mcp_tool_name(i); diff --git a/tests/test_agent_clients.c b/tests/test_agent_clients.c index edfc3a803..15794c2b1 100644 --- a/tests/test_agent_clients.c +++ b/tests/test_agent_clients.c @@ -1106,7 +1106,7 @@ TEST(client_adapter_pi_registers_every_registry_tool) { TEST(client_adapter_pi_default_exports_its_factory_issue1550) { char *js = cbm_client_adapter_pi("/usr/local/bin/codebase-memory-mcp"); ASSERT_NOT_NULL(js); - ASSERT_NOT_NULL(strstr(js, "export default function")); + ASSERT_NOT_NULL(strstr(js, "export default function (pi)")); /* The old shape must be gone: a bare `export function register(pi)` is the * exact form Pi rejects. */ ASSERT_NULL(strstr(js, "export function register(pi)"));