Repository navigation
Description
Bug Report
Description
When using the bun-pty dependency in a local OpenCode plugin (installed via .opencode/package.json), the native librust_pty.so library cannot be found even though it exists at .opencode/node_modules/bun-pty/rust-pty/target/release/librust_pty.so. The bun-pty library only checks hardcoded paths that don't include .opencode/node_modules/.
Environment
- OpenCode Version: 1.1.35-0bc4a43
- Operating System: NixOS
- GLIBC Version: 2.42
- bun-pty Version: 0.4.8
- Architecture: x86-64
Steps to Reproduce
-
Create a new test workspace:
mkdir test-workspace cd test-workspace mkdir -p .opencode/plugins -
Add bun-pty dependency to
.opencode/package.json:{ "dependencies": { "bun-pty": "^0.4.8" } } -
Install dependencies:
cd .opencode && bun install
-
Verify the library exists:
ls .opencode/node_modules/bun-pty/rust-pty/target/release/librust_pty.so # File exists and is valid ELF 64-bit LSB shared object -
Start OpenCode:
opencode debug wait
Expected Behavior
OpenCode should start successfully and find the librust_pty.so library in the .opencode/node_modules/ directory where bun-pty was installed.
Actual Behavior
OpenCode fails with:
Error: Unexpected error, check log file at /home/michi/.local/share/opencode/log/dev.log for more details
librust_pty shared library not found.
Checked:
- BUN_PTY_LIB=<unset>
- /home/michi/dev/opencode-pty-branches/web-ui/test-workspace/.opencode/plugins/rust-pty/target/release/librust_pty.so
- /home/michi/dev/opencode-pty-branches/web-ui/test-workspace/.opencode/bun-pty/rust-pty/target/release/librust_pty.so
- /home/michi/dev/opencode-pty-branches/web-ui/test-workspace/node_modules/bun-pty/rust-pty/target/release/librust_pty.so
Root Cause Analysis
The bun-pty library searches for librust_pty.so in these paths:
.opencode/plugins/rust-pty/target/release/librust_pty.so.opencode/bun-pty/rust-pty/target/release/librust_pty.sonode_modules/bun-pty/rust-pty/target/release/librust_pty.so
However, when bun-pty is installed as a dependency via .opencode/package.json, it gets installed to .opencode/node_modules/bun-pty/rust-pty/target/release/librust_pty.so, which is not in the search paths.
Directory Structure
test-workspace/
├── .opencode/
│ ├── package.json
│ ├── bun.lock
│ ├── node_modules/
│ │ └── bun-pty/
│ │ ├── rust-pty/
│ │ │ └── target/
│ │ │ └── release/
│ │ │ ├── librust_pty.so ← FILE EXISTS HERE
│ │ │ ├── librust_pty_arm64.so
│ │ │ └── ...
│ │ └── package.json
│ └── plugins/
│ └── opencode-pty.js
Temporary Workarounds
-
Set BUN_PTY_LIB environment variable:
export BUN_PTY_LIB=.opencode/node_modules/bun-pty/rust-pty/target/release/librust_pty.so opencode debug wait
-
Create symbolic link:
mkdir -p .opencode/bun-pty/rust-pty/target/release ln -s .opencode/node_modules/bun-pty/rust-pty/target/release/librust_pty.so .opencode/bun-pty/rust-pty/target/release/
-
Copy the library:
mkdir -p .opencode/bun-pty/rust-pty/target/release cp .opencode/node_modules/bun-pty/rust-pty/target/release/librust_pty.so .opencode/bun-pty/rust-pty/target/release/
Suggested Fix
The bun-pty library should be updated to include .opencode/node_modules/bun-pty/rust-pty/target/release/librust_pty.so in its search paths when resolving the native library.
Alternatively, OpenCode could provide a standardized way for plugins to resolve native dependencies installed via .opencode/package.json.
Related Issues
This appears to be similar to other path resolution issues in the plugin system:
- Cannot load custom providers from local file paths #4324: Cannot load custom providers from local file paths
- "@opencode-ai/plugin" error when creating custom tools, #3001: "@opencode-ai/plugin" error when creating custom tools
- Issues with plugin dependency resolution during local dev
Additional Context
This is particularly problematic for PTY/terminal functionality which relies on native libraries. The current workaround requires manual intervention that breaks the "just work" experience that OpenCode aims to provide with local plugins.
The issue affects the opencode-pty plugin development workflow, making it difficult to test local changes without manual setup steps.
Activity
github-actions commentedon Jan 25, 2026
This issue appears to be related to plugin dependency path resolution, similar in nature to other plugin-related issues, but it is distinct in that it specifically addresses the missing search path for native libraries (librust_pty.so) when bun-pty is installed as a dependency in .opencode/node_modules/.
You may want to check the following related issues for additional context on plugin system limitations:
These don't directly solve your issue but represent ongoing challenges with the plugin dependency resolution system.
MBanucu commentedon Jan 25, 2026
🐛 Plugin Dependency Path Resolution: Mixed Results
Plugin Loading is Functional ✅
The plugin system successfully loads plugins with npm dependencies. JavaScript/TypeScript imports work perfectly, and plugins can register hooks and execute normally.
✅ What's Working
bun-ptyJavaScript/TypeScript imports work perfectly.opencode/node_modules/as expected🔍 Native Library Resolution: Inconsistent
librust_pty.soIS present at:.opencode/node_modules/📊 Test Results from Different Workspaces
Workspace A (test-workspace-bun-pty/):
Workspace B (test-workspace/ with opencode-pty):
🤔 This Suggests
.opencode/node_modules/for consistency📁 Test Workspaces Available
Created workspaces demonstrating both working and failing PTY scenarios for testing fixes.
Impact: Creates unpredictable behavior for plugins requiring native libraries.
MBanucu commentedon Jan 25, 2026
Investigation findings: The native library path resolution bug occurs when plugins are bundled with
bun build --target bun. The bun-pty library checks specific paths that exclude.opencode/node_modules/, where dependencies are installed for OpenCode plugins. This triggers immediate library loading at module import time in bundled plugins, unlike unbundled scripts. MWE created and confirms the issue. Potential fixes: update bun-pty paths, set NODE_PATH/BUN_PTY_LIB in OpenCode, or modify test scripts to set BUN_PTY_LIB.MBanucu commentedon Jan 25, 2026
test-bun-pty-path-resolution.shoutput
MBanucu commentedon Jan 25, 2026
test-bun-pty-path-resolution-no-bundle.shoutput
MBanucu commentedon Jan 25, 2026
So without bundling with bun it works.
MBanucu commentedon Jan 25, 2026
Conclusion: bun-pty has a path resolution bug
Based on comprehensive testing of multiple Rust-based Node.js libraries:
Confirmed Bug:
librust_pty.solibrary when bundledresolveLibPath()doesn't handle plugin subdirectories or bundled environments correctlybun buildOther Libraries Work Fine:
Root Cause:
The issue is specifically in bun-pty's
resolveLibPath()function. It calculates incorrect paths whenimport.meta.urlchanges after bundling, and doesn't check the localnode_modulesdirectory where the library is actually installed.Required Fix:
The bun-pty library needs to update its path resolution logic to:
import.meta.urlpoints to the output directorynode_modulespaths relative to the plugin locationThis is not a Bun bundling issue - it's a bun-pty library bug that affects plugin developers using bundled PTY functionality.
MBanucu commentedon Jan 25, 2026
test-opencode-plugin-structure.sh
MBanucu commentedon Jan 26, 2026
added this line
additional output
MBanucu commentedon Jan 26, 2026
So in the end who is the bad guy? opencode or sursaone/bun-pty?
fix(pty): graceful degradation when bun-pty native library unavailable
fix(pty): graceful degradation when bun-pty native library unavailable (
github-actions commentedon Mar 29, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.
fix(pty): graceful degradation when bun-pty native library unavailable (