Skip to content

Plugin bundling doesn't copy audio files (.wav) breaking opencode-notifier sounds #266

@shuv1337

Description

@shuv1337

Problem

The @mohak34/opencode-notifier plugin doesn't play sounds in shuvcode, while it works correctly in upstream opencode.

User Report: Plugin configured in opencode.json but sounds don't work:

"I have this set up in opencode.json https://github.com/mohak34/opencode-notifier but its not working in shuvcode. I don't get the sounds I mean. It works with opencode"

Root Cause

Shuvcode bundles plugins for compiled binary compatibility using Bun.build(). During this process, plugin assets are copied from the original location to the bundled directory. However, the copyPluginAssets function only copies a limited set of file extensions:

// packages/opencode/src/bun/index.ts:224-226
const assetExtensions = [".html", ".css", ".json", ".txt", ".svg", ".png", ".jpg", ".gif"]

The .wav files used by opencode-notifier are not included in this list.

The plugin uses __dirname to resolve sound file paths:

// From opencode-notifier/src/sound.ts
const __dirname = dirname(fileURLToPath(import.meta.url))
// ...
return join(__dirname, "..", "sounds", `${event}.wav`)

After bundling, __dirname points to ~/.cache/opencode/bundled/, but the sound files are never copied there, causing existsSync() to return false and sounds to silently fail.

Acceptance Criteria

  • Plugin bundling copies .wav audio files (and potentially other audio formats like .mp3, .ogg)
  • The @mohak34/opencode-notifier plugin sounds work correctly after the fix
  • Sound files are discoverable relative to the bundled plugin location

Implementation Details

Suggested Fix

Update the asset extensions list in packages/opencode/src/bun/index.ts:

// Line 226
const assetExtensions = [
  ".html", ".css", ".json", ".txt", ".svg", ".png", ".jpg", ".gif",
  // Audio files
  ".wav", ".mp3", ".ogg", ".flac", ".m4a"
]

Additional Consideration

The current asset copying logic only copies to the root bundled directory:

const destPath = path.join(destDir, path.basename(entry))

However, the plugin expects sounds in a sounds/ subdirectory relative to __dirname. We may need to preserve the directory structure:

// Alternative: preserve relative directory structure
const destPath = path.join(destDir, entry)  // Keep subdirectory structure
await Bun.$`mkdir -p ${path.dirname(destPath)}`
await Bun.write(destPath, content)

Files to Modify

  • packages/opencode/src/bun/index.ts:224-253 - copyPluginAssets function

Reference Implementation

The opencode-notifier plugin sound resolution: https://github.com/mohak34/opencode-notifier/blob/main/src/sound.ts#L8-L24

Tasks

  • Add audio file extensions (.wav, .mp3, .ogg) to assetExtensions
  • Preserve subdirectory structure when copying assets (for sounds/ directory)
  • Test with @mohak34/opencode-notifier plugin
  • Clear plugin cache and verify sounds work: rm -rf ~/.cache/opencode/bundled/*mohak34*

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions