Skip to content

Agent dev mode (tsx) broken since Phase D — switch to tsup --watch #253

@rz1989s

Description

@rz1989s

Context

PR #252 (Phase D — sip.sol agent tools) added @sip-protocol/sns-stealth which transitively pulls in @bonfida/spl-name-service@3.0.21. That package ships a broken ESM bundle (vendored borsh path resolution) that tsx's ESM loader cannot instantiate, even though plain Node ESM handles it fine.

Impact

  • Production: ✅ unaffected (Docker uses node dist/index.js via tsup-built output)
  • Sipher REST dev (root pnpm dev): ✅ unaffected (uses tsup → node)
  • Unit tests: ✅ unaffected (mock @sip-protocol/sns-stealth)
  • e2e in CI: ✅ fixed in feat(agent): sip.sol tools — resolveSNS + sendPrivateToSNS #252 (switched playwright webServer to pnpm --filter @sipher/agent start)
  • Agent dev mode: ❌ broken — pnpm --filter @sipher/agent dev (= tsx watch src/index.ts) crashes at boot

Repro

cd packages/agent
pnpm dev
# → SyntaxError: The requested module '../node_modules/borsh/lib/esm/index.js' does not provide an export named 'serialize'

Stack trace points to @bonfida/spl-name-service@3.0.21/dist/esm/instructions/burnInstruction.js:1 even though that path's vendored borsh DOES export serialize (verified via direct file import).

Proposed fix

Switch agent's dev script from tsx watch src/index.ts to a tsup-based watcher matching the root pattern:

"dev": "tsup --watch src --onSuccess 'node dist/index.js'"

This requires:

  1. Add tsup to packages/agent/devDependencies
  2. Add a tsup.config.ts in packages/agent/ (or inline config in package.json)
  3. Update dev script

Alternative: patch @bonfida/spl-name-service@3.0.21 via pnpm patch to fix the ESM bundle. Higher maintenance burden — would need to track Bonfida upstream releases.

Notes

  • Phase B (sip-app) + Phase C (sip-mobile) consume the same @sip-protocol/sns-stealth@0.1.0 without hitting this — their bundlers (Next.js webpack/turbopack + Metro) handle the broken Bonfida ESM differently than tsx.
  • The Phase A test suite for sns-stealth itself runs via vitest which mocks at the module level; the bug never surfaced there.
  • Upstream Bonfida issue worth filing separately if not already known.

Acceptance criteria

  • pnpm --filter @sipher/agent dev boots cleanly and reaches /api/health
  • Watch mode rebuilds on src changes
  • Existing tests continue to pass (pnpm --filter @sipher/agent test)
  • e2e in CI remains green (.github/workflows/e2e.yml may need re-simplification if dev is fixed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions