Skip to content

Pi generated extension should default-export its factory function #1550

Closed

Description

@musichen

Summary

The generated Pi extension currently exports a named register(pi) function, but Pi expects an extension file to default-export a factory function.

This makes Pi fail on startup whenever the generated extension is present.

Environment

  • codebase-memory-mcp: 0.10.1
  • Pi coding agent: 0.84.1
  • macOS arm64

Repro

After installing codebase-memory-mcp with Pi integration, the generated file at:

~/.pi/agent/extensions/cbmem.ts

contained:

export function register(pi) {
  pi.registerTool({ name: 'index_repository', run: (args, ctx) => call('index_repository', args, ctx?.signal) });
  // ...
}

Running any Pi command with extensions enabled then failed:

pi doctor

with:

Error: Failed to load extension "/Users/musichen/.pi/agent/extensions/cbmem.ts": Extension does not export a valid factory function: /Users/musichen/.pi/agent/extensions/cbmem.ts
Hint: Start without extensions using "pi -ne".

Local fix verified

Changing the generated export to a default factory fixed Pi startup:

-export function register(pi) {
+export default function (pi) {

After this change, both commands worked with extensions enabled:

pi doctor
pi -p 'reply exactly: pi-ok'

Expected generator output

The Pi extension generator should emit:

export default function (pi) {
  pi.registerTool({ name: 'index_repository', run: (args, ctx) => call('index_repository', args, ctx?.signal) });
}

Related

I also opened a Pi issue asking for a clearer loader diagnostic when the default export is missing:

earendil-works/pi#7985

Activity

  1. added
    bugSomething isn't working
    editor/integrationEditor compatibility and CLI integration
    priority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.
    on Aug 11, 2026
  2. DeusData commented on Aug 11, 2026

    @DeusData
    Owner

    Confirmed, and thank you @musichen — this is our bug, introduced when the Pi extension started being generated from the tool registry (#1392, shipped in v0.10.0). src/cli/client_adapter.c emits export function register(pi), and Pi wants a default-exported factory.

    What makes it worse than a cbm-only failure: a broken extension file makes every Pi command fail to load, not just ours — pi doctor included, exactly as you saw. So this is queued for the next patch release.

    Immediate unblock if you need Pi working right now: delete ~/.pi/agent/extensions/cbmem.ts (cbm keeps working through its MCP server registration; only the extension surface goes away), or edit it to export default function (pi) { ... } with the same body.

  3. musichen commented on Aug 12, 2026

    @musichen
    ContributorAuthor

    A test-backed fix is available in #1553.

  4. DeusData commented on Aug 12, 2026

    @DeusData
    Owner

    @musichen — shipping in v0.10.3 (releasing now).

    Your PR #1553 and @henri-edh's #1564 both arrived while ours was already in CI, so the commits are ours, but both of you are recorded as co-authors on 42e320a6 — and @henri-edh's description of the loader (jiti.import(path, { default: true }) rejecting a non-function, hence the module namespace object a named-only export hands back) replaced our vaguer comment, because it explains why a named export cannot simply be added alongside.

    Thank you for reporting it and fixing it within the hour, and for the workaround you posted for anyone who needed Pi working before the release.

  5. DeusData commented on Aug 13, 2026

    @DeusData
    Owner

    v0.10.3 is published — https://github.com/DeusData/codebase-memory-mcp/releases/tag/v0.10.3 (GitHub archives, npm, and PyPI are all serving it).

    This fix is in it. Please give it a try when you get a chance: if it behaves in your setup, feel free to close this out, and if anything still looks off, say so and we'll pick it straight back up. Thank you again for the report.

  6. DeusData commented on Aug 13, 2026

    @DeusData
    Owner

    Closing as fixed in v0.10.3 by commit 42e320a6. The generated Pi extension now default-exports the factory expected by Pi's loader, with the community fixes credited as co-authored work.

    Thank you again @musichen for the exact loader failure, verified workaround, and prompt PR. If Pi still rejects a freshly generated extension on v0.10.3 or newer, comment here and we will reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingeditor/integrationEditor compatibility and CLI integrationpriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions