Skip to content

feat: Node.js compatibility (remove Bun runtime requirement)Β #146

@joelhooks

Description

@joelhooks

Problem

The CLI requires Bun to run (#!/usr/bin/env bun) but this isn't obvious until you try to use it. Users who install via npm install -g hit env: bun: No such file or directory with no guidance.

Reported in #116 by @gaearon.

Current Bun Dependencies

Heavy usage throughout the codebase:

Bun API Usage Node Equivalent
Bun.$\cmd`` Shell commands (tagged template) execa or child_process.exec
Bun.spawn() Process spawning child_process.spawn
Bun.file().exists() File existence check fs.existsSync
Bun.file().text() Read file fs.readFileSync
Bun.write() Write file fs.writeFileSync
Bun.argv CLI arguments process.argv
Bun.sleep() Async delay setTimeout promisified

Files with Bun APIs:

  • bin/swarm.ts - CLI entrypoint
  • src/swarm-worktree.ts - Heavy Bun.$ usage for git
  • src/swarm-verify.ts - Bun.file, Bun.$
  • src/swarm-decompose.ts - Bun.$
  • src/tool-availability.ts - Bun.$, Bun.spawn
  • src/agent-mail.ts - Bun.spawn, Bun.file
  • src/hive.ts - Bun.spawn
  • src/storage.ts - Bun.spawn
  • src/skills.ts - Bun.spawn

Proposed Solution

Option A: Runtime Abstraction Layer (Recommended)

Create src/runtime.ts that exports platform-agnostic helpers:

// src/runtime.ts
export const runtime = {
  spawn: async (cmd: string[], opts?: SpawnOpts) => { ... },
  shell: async (cmd: string) => { ... },
  fileExists: async (path: string) => { ... },
  readFile: async (path: string) => { ... },
  writeFile: async (path: string, content: string) => { ... },
  sleep: async (ms: number) => { ... },
  argv: process.argv,
};

Detect runtime at startup, use Bun APIs when available, fall back to Node equivalents.

Option B: Compile to JS

Use bun build to compile to standalone JS. Problem: Bun.$ shell syntax won't survive compilation.

Option C: Require tsx

Change shebang to #!/usr/bin/env tsx and replace Bun APIs with Node equivalents. Requires tsx as a dependency.

Acceptance Criteria

  • npm install -g opencode-swarm-plugin && swarm setup works without Bun
  • All existing functionality preserved
  • Tests pass on both Bun and Node
  • CI tests both runtimes
  • README updated with Node as primary, Bun as optional

Complexity

Estimate: Medium-High (2-3 days)

Most work is mechanical replacement, but needs careful testing of shell command edge cases.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions