MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / new

Method new

crates/opencode-plugin/src/subprocess/loader.rs:58–76  ·  view source on GitHub ↗

Create a new loader. Detects the JS runtime and writes the host script to `~/.cache/opencode/plugin-host.ts`.

()

Source from the content-addressed store, hash-verified

56 /// Create a new loader. Detects the JS runtime and writes the host script
57 /// to `~/.cache/opencode/plugin-host.ts`.
58 pub fn new() -> Result<Self, PluginLoaderError> {
59 let runtime = detect_runtime().ok_or(PluginLoaderError::NoRuntime)?;
60
61 let cache_dir = dirs::cache_dir()
62 .unwrap_or_else(|| PathBuf::from("/tmp"))
63 .join("opencode");
64 std::fs::create_dir_all(&cache_dir)?;
65
66 let host_script_path = cache_dir.join("plugin-host.ts");
67 std::fs::write(&host_script_path, HOST_SCRIPT)?;
68
69 Ok(Self {
70 clients: RwLock::new(Vec::new()),
71 auth_bridges: RwLock::new(HashMap::new()),
72 hook_system: Arc::new(PluginSystem::new()),
73 runtime,
74 host_script_path,
75 })
76 }
77
78 /// Load all plugins from the given spec list.
79 ///

Callers

nothing calls this directly

Calls 2

detect_runtimeFunction · 0.85
newFunction · 0.85

Tested by

no test coverage detected