Skip to content

Commit 42e320a

Browse files
DeusDatamusichenhenri-edh
committed
docs(pi): name the loader mechanism behind the default-export requirement
Two contributors independently sent the same fix for DeusData#1550 while ours was already in CI (DeusData#1553 by @musichen, who also reported the bug, and DeusData#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 <musichen@users.noreply.github.com> Co-Authored-By: henri-edh <henri-edh@users.noreply.github.com> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent b91abca commit 42e320a

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎src/cli/client_adapter.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ char *cbm_client_adapter_pi(const char *binary_path) {
157157
/* Register every tool the registry advertises — never a hand-picked subset,
158158
* which is the drift this generator exists to prevent.
159159
*
160-
* DEFAULT export, and it must stay that way: Pi loads an extension by
161-
* calling its default export as a factory. A named `register` export made
162-
* the file fail to load, and a Pi extension that fails to load takes EVERY
163-
* pi command down with it — `pi doctor` included — not just cbm's tools
164-
* (#1550). The named binding is kept alongside for anything that imported
165-
* it by name. */
160+
* DEFAULT export, and it must stay that way. Pi loads an extension via
161+
* jiti.import(path, { default: true }) and rejects anything that is not a
162+
* function, so a named `export function register(pi)` hands the loader the
163+
* module namespace object instead and every install fails with "Extension
164+
* does not export a valid factory function". A Pi extension that fails to
165+
* load takes EVERY pi command down with it — `pi doctor` included — not
166+
* just cbm's tools (#1550). */
166167
sb_append(&sb, "export default function (pi) {\n");
167168
for (int i = 0; i < count; i++) {
168169
const char *name = cbm_mcp_tool_name(i);

‎tests/test_agent_clients.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ TEST(client_adapter_pi_registers_every_registry_tool) {
11061106
TEST(client_adapter_pi_default_exports_its_factory_issue1550) {
11071107
char *js = cbm_client_adapter_pi("/usr/local/bin/codebase-memory-mcp");
11081108
ASSERT_NOT_NULL(js);
1109-
ASSERT_NOT_NULL(strstr(js, "export default function"));
1109+
ASSERT_NOT_NULL(strstr(js, "export default function (pi)"));
11101110
/* The old shape must be gone: a bare `export function register(pi)` is the
11111111
* exact form Pi rejects. */
11121112
ASSERT_NULL(strstr(js, "export function register(pi)"));

0 commit comments

Comments
 (0)