From a0b389e7d5210ad108d393029ee381070aed7b88 Mon Sep 17 00:00:00 2001 From: Steffen Zellmer <151627820+Steffen025@users.noreply.github.com> Date: Wed, 1 Apr 2026 23:08:12 +0200 Subject: [PATCH] fix(installer): install runtime deps for .opencode tooling --- PAI-Install/engine/steps-fresh.ts | 25 +++++++++++++++++++++++++ PAI-Install/engine/steps-migrate.ts | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/PAI-Install/engine/steps-fresh.ts b/PAI-Install/engine/steps-fresh.ts index cc90839f..f7a92b7f 100644 --- a/PAI-Install/engine/steps-fresh.ts +++ b/PAI-Install/engine/steps-fresh.ts @@ -14,6 +14,7 @@ import type { ProviderName } from "./provider-models.ts"; import { existsSync, mkdirSync, writeFileSync, chmodSync, symlinkSync, unlinkSync, lstatSync, realpathSync, readFileSync, renameSync } from "node:fs"; import { join, resolve, dirname } from "node:path"; import { homedir } from "node:os"; +import { spawnSync } from "bun"; // ═══════════════════════════════════════════════════════════ // Step 1: Welcome @@ -359,6 +360,30 @@ ${providerEnvVar}=${state.collected.apiKey || ""} ); onProgress(96, "Generated opencode.json..."); + // Install runtime dependencies needed by .opencode/tools scripts (e.g. yaml in switch-provider.ts) + onProgress(97, "Installing PAI runtime dependencies..."); + const rootInstall = spawnSync({ + cmd: ["bun", "install"], + cwd: installDir, + stdout: "pipe", + stderr: "pipe", + }); + if (rootInstall.exitCode !== 0) { + const err = rootInstall.stderr.toString().trim() || rootInstall.stdout.toString().trim(); + throw new Error(`Failed to install repository dependencies: ${err}`); + } + + const opencodeInstall = spawnSync({ + cmd: ["bun", "install"], + cwd: localOpencodeDir, + stdout: "pipe", + stderr: "pipe", + }); + if (opencodeInstall.exitCode !== 0) { + const err = opencodeInstall.stderr.toString().trim() || opencodeInstall.stdout.toString().trim(); + throw new Error(`Failed to install .opencode dependencies: ${err}`); + } + // Create symlink from ~/.opencode to local .opencode onProgress(98, "Creating symlink ~/.opencode → ./.opencode..."); diff --git a/PAI-Install/engine/steps-migrate.ts b/PAI-Install/engine/steps-migrate.ts index bfae6955..60e5cff1 100644 --- a/PAI-Install/engine/steps-migrate.ts +++ b/PAI-Install/engine/steps-migrate.ts @@ -8,6 +8,7 @@ import { existsSync, cpSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { homedir } from "node:os"; +import { spawnSync } from "bun"; import type { InstallState } from "./types"; import { PAI_VERSION } from "./types"; import { migrateV2ToV3, isMigrationNeeded } from "./migrate"; @@ -242,6 +243,23 @@ exec bun "${join(paiDir, "PAI", "Tools", "pai.ts")}" "$@" } catch (err) { console.warn("Could not update shell rc file:", err); } + + // 4. Ensure runtime deps for .opencode/tools scripts are installed + onProgress(99, "Installing runtime dependencies..."); + try { + const installResult = spawnSync({ + cmd: ["bun", "install"], + cwd: paiDir, + stdout: "pipe", + stderr: "pipe", + }); + if (installResult.exitCode !== 0) { + const err = installResult.stderr.toString().trim() || installResult.stdout.toString().trim(); + console.warn("Could not install .opencode dependencies:", err); + } + } catch (err) { + console.warn("Could not install runtime dependencies:", err); + } onProgress(100, "Migration complete!"); }