Skip to content
This repository was archived by the owner on Jun 9, 2026. It is now read-only.
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
23 changes: 14 additions & 9 deletions PAI-Install/engine/steps-fresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { buildOpenCodeBinary } from "./build-opencode.ts";
import type { BuildResult } from "./build-opencode.ts";
import { PROVIDER_MODELS, PROVIDER_LABELS } from "./provider-models.ts";
import type { ProviderName } from "./provider-models.ts";
import { existsSync, mkdirSync, writeFileSync, chmodSync, symlinkSync, unlinkSync, lstatSync, realpathSync, readFileSync } from "node:fs";
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";

Expand Down Expand Up @@ -380,14 +380,19 @@ ${providerEnvVar}=${state.collected.apiKey || ""}
}
// If it already points to our location, nothing to do
} else if (stats.isDirectory()) {
// It's a real directory - backup and replace with symlink
if (realpathSync(globalOpencodeLink) === localOpencodeDir) {
console.warn("PAI install directory already matches ~/.opencode; no symlink changes needed.");
} else {
// It's a real directory — back it up and replace it so validation reads the new install.
const backupPath = `${globalOpencodeLink}.backup-${Date.now()}`;
// Note: In production, this would need proper backup logic
// For now, we just warn and don't overwrite
throw new Error(
`~/.opencode is a directory (not a symlink). ` +
`Please backup and remove it manually, then re-run the installer.`
);
renameSync(globalOpencodeLink, backupPath);
symlinkSync(localOpencodeDir, globalOpencodeLink, "dir");
console.warn(`Warning: Existing ~/.opencode directory moved to ${backupPath}`);
}
} else {
// Regular file (not a symlink or directory) — replace it with the symlink.
unlinkSync(globalOpencodeLink);
symlinkSync(localOpencodeDir, globalOpencodeLink, "dir");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
} else {
// No ~/.opencode exists - create symlink
Expand Down Expand Up @@ -585,4 +590,4 @@ export async function runFreshInstall(
import { exec as execCallback } from "node:child_process";
import { promisify } from "node:util";

const exec = promisify(execCallback);
const exec = promisify(execCallback);
10 changes: 8 additions & 2 deletions PAI-Install/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ let voiceEnabled = true;
let currentAudio = null;
let installMode = null; // 'fresh', 'migrate', 'update'
let steps = [];
let installationComplete = false;

// ─── WebSocket Connection ────────────────────────────────────────

function connect() {
if (installationComplete) return;
const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
ws = new WebSocket(`${protocol}//${location.host}/ws`);

Expand All @@ -35,8 +37,10 @@ function connect() {

ws.onclose = () => {
connected = false;
addMessage('system', 'Connection lost. Reconnecting...', false);
setTimeout(connect, 2000); // Auto-reconnect
if (!installationComplete) {
addMessage('system', 'Connection lost. Reconnecting...', false);
setTimeout(connect, 2000); // Auto-reconnect
}
};

ws.onerror = () => {
Expand All @@ -59,6 +63,7 @@ function handleServerMessage(msg) {
break;

case 'mode_selected':
installationComplete = false;
setStepsForMode(msg.mode);
renderSteps();
break;
Expand Down Expand Up @@ -111,6 +116,7 @@ function handleServerMessage(msg) {
break;

case 'install_complete':
installationComplete = true;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
renderSummary(msg.summary);
break;

Expand Down
Loading