Skip to content

fix: daemon autostart for prebuilt npm binaries#84

Merged
benvinegar merged 2 commits intomainfrom
fix/mcp-daemon-autostart-prebuilt
Mar 23, 2026
Merged

fix: daemon autostart for prebuilt npm binaries#84
benvinegar merged 2 commits intomainfrom
fix/mcp-daemon-autostart-prebuilt

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • Fix MCP daemon auto-start failing silently when hunk is installed via npm (prebuilt binary path)
  • Root cause: Bun-compiled single-file executables set process.execPath to the embedded Bun runtime, not the binary itself. launchHunkDaemon() was spawning bare Bun with ["mcp", "serve"] — an invalid command
  • Fix: when argv[0] differs from execPath, use argv[0] as the spawn command since that's the actual compiled binary

Test plan

  • Existing daemon launcher tests pass
  • New test case covers the prebuilt binary scenario (argv[0] != execPath)
  • Full test suite passes (1 pre-existing unrelated failure in loaders.test.ts)
  • Manual: npm i -g hunkdiff, kill any daemon, run hunk show — daemon should auto-start and hunk session list should find it

🤖 Generated with Claude Code

benvinegar and others added 2 commits March 23, 2026 12:03
Bun-compiled single-file executables set process.execPath to the
embedded Bun runtime, not the binary itself. When the daemon launcher
tried to spawn `process.execPath mcp serve`, it was invoking bare Bun
with invalid args instead of the prebuilt hunk binary.

Fix: when argv[0] differs from execPath, use argv[0] as the command —
that's the actual compiled binary the user invoked.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@benvinegar benvinegar merged commit 13fd1bb into main Mar 23, 2026
3 checks passed
benvinegar added a commit that referenced this pull request Mar 23, 2026
The previous fix (PR #84) assumed argv[0] was the real binary and
execPath was the embedded Bun runtime, but it's the opposite: Bun
compiled binaries report argv as ["bun", "/$bunfs/root/<name>", ...]
with execPath pointing to the real binary on disk. The old code matched
the $bunfs virtual path against SCRIPT_ENTRYPOINT_PATTERN (because it
contains "/"), spawning `bun /$bunfs/root/hunk mcp serve` — a path
that doesn't exist outside the binary.

Fix: detect the /$bunfs/ prefix in argv[1] and use execPath directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
benvinegar added a commit that referenced this pull request Mar 23, 2026
…#86)

* fix: detect $bunfs virtual paths for daemon autostart in Bun binaries

The previous fix (PR #84) assumed argv[0] was the real binary and
execPath was the embedded Bun runtime, but it's the opposite: Bun
compiled binaries report argv as ["bun", "/$bunfs/root/<name>", ...]
with execPath pointing to the real binary on disk. The old code matched
the $bunfs virtual path against SCRIPT_ENTRYPOINT_PATTERN (because it
contains "/"), spawning `bun /$bunfs/root/hunk mcp serve` — a path
that doesn't exist outside the binary.

Fix: detect the /$bunfs/ prefix in argv[1] and use execPath directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* style: format daemon launcher test

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant