MCPcopy Create free account
hub / github.com/tiann/hapi / ensurePluginRuntime

Function ensurePluginRuntime

cli/src/opencode/utils/hookPlugin.ts:191–212  ·  view source on GitHub ↗

* Ensure the opencode runtime can resolve `@opencode-ai/plugin` from our * isolated config dir. Since opencode 1.14.x the plugin loader is a separate * npm package, and ` /plugins/*.ts` files are only evaluated when * that package is resolvable from ` `. HAPI's per-session *

(rootPath: string)

Source from the content-addressed store, hash-verified

189 * degraded but not fatal.
190 */
191function ensurePluginRuntime(rootPath: string): void {
192 if (!isHapiManagedDir(rootPath)) {
193 logger.debug(`[opencode-hook] Skipping plugin runtime materialization for non-HAPI dir: ${rootPath}`);
194 return;
195 }
196
197 const packageJsonPath = join(rootPath, PACKAGE_JSON_FILENAME);
198 if (existsSync(packageJsonPath)) {
199 if (hasDeclaredPluginPackage(packageJsonPath)) {
200 // Existing file already declares the plugin (likely opencode-
201 // installed with a matching lock file). Leave it untouched.
202 return;
203 }
204 logger.debug(`[opencode-hook] package.json exists at ${packageJsonPath} but does not declare ${PLUGIN_PACKAGE}; overwriting placeholder.`);
205 }
206
207 try {
208 writeFileSync(packageJsonPath, buildMinimalPackageJson(), 'utf-8');
209 } catch (error) {
210 logger.warn(`[opencode-hook] Failed to materialize ${packageJsonPath}; the hook plugin channel may stay inert. Storage scanner remains as fallback. Error: ${(error as Error).message}`);
211 }
212}
213
214export function ensureOpencodeHookPlugin(rootPath: string, hookUrl: string, token: string): string {
215 const pluginDir = resolvePluginDir(rootPath);

Callers 1

ensureOpencodeHookPluginFunction · 0.85

Calls 5

isHapiManagedDirFunction · 0.85
hasDeclaredPluginPackageFunction · 0.85
buildMinimalPackageJsonFunction · 0.85
debugMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected