Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions PAI-Install/engine/steps-fresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...");

Expand Down
18 changes: 18 additions & 0 deletions PAI-Install/engine/steps-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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!");
}
Expand Down
Loading