Skip to content

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.

docs(pi): name the loader mechanism behind the default-export requirement

Martin Vogel42e320a6cbbf
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)"));