Add OpenCode binary selection with version detection

- Add binary selector component with dropdown and validation
- Support custom OpenCode binary paths and system PATH binary
- Async version checking for all binaries when selector opens
- Store recent binaries with timestamps and version info
- Enhanced instance creation to use selected binary
- Improved storage system for binary preferences
- Fixed validation to handle system PATH binaries properly
This commit is contained in:
Shantur Rathore
2025-10-26 10:26:32 +00:00
parent f4a664bfe7
commit f63a4b3754
11 changed files with 684 additions and 55 deletions

View File

@@ -40,7 +40,7 @@ function removeInstance(id: string) {
}
}
async function createInstance(folder: string): Promise<string> {
async function createInstance(folder: string, binaryPath?: string): Promise<string> {
const id = `instance-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
const instance: Instance = {
@@ -56,7 +56,12 @@ async function createInstance(folder: string): Promise<string> {
addInstance(instance)
try {
const { id: returnedId, port, pid, binaryPath } = await window.electronAPI.createInstance(id, folder)
const {
id: returnedId,
port,
pid,
binaryPath: actualBinaryPath,
} = await window.electronAPI.createInstance(id, folder, binaryPath)
const client = sdkManager.createClient(port)
@@ -65,7 +70,7 @@ async function createInstance(folder: string): Promise<string> {
pid,
client,
status: "ready",
binaryPath,
binaryPath: actualBinaryPath,
})
setActiveInstanceId(id)

View File

@@ -3,6 +3,13 @@ import { storage, type ConfigData } from "../lib/storage"
export interface Preferences {
showThinkingBlocks: boolean
lastUsedBinary?: string
}
export interface OpenCodeBinary {
path: string
version?: string
lastUsed: number
}
export interface RecentFolder {
@@ -18,12 +25,14 @@ const defaultPreferences: Preferences = {
const [preferences, setPreferences] = createSignal<Preferences>(defaultPreferences)
const [recentFolders, setRecentFolders] = createSignal<RecentFolder[]>([])
const [opencodeBinaries, setOpenCodeBinaries] = createSignal<OpenCodeBinary[]>([])
async function loadConfig(): Promise<void> {
try {
const config = await storage.loadConfig()
setPreferences({ ...defaultPreferences, ...config.preferences })
setRecentFolders(config.recentFolders)
setOpenCodeBinaries(config.opencodeBinaries || [])
} catch (error) {
console.error("Failed to load config:", error)
}
@@ -34,6 +43,7 @@ async function saveConfig(): Promise<void> {
const config: ConfigData = {
preferences: preferences(),
recentFolders: recentFolders(),
opencodeBinaries: opencodeBinaries(),
}
await storage.saveConfig(config)
} catch (error) {
@@ -66,6 +76,35 @@ function removeRecentFolder(path: string): void {
saveConfig().catch(console.error)
}
function addOpenCodeBinary(path: string, version?: string): void {
const binaries = opencodeBinaries().filter((b) => b.path !== path)
binaries.unshift({ path, version, lastUsed: Date.now() })
const trimmed = binaries.slice(0, 10) // Keep max 10 binaries
setOpenCodeBinaries(trimmed)
saveConfig().catch(console.error)
}
function removeOpenCodeBinary(path: string): void {
const binaries = opencodeBinaries().filter((b) => b.path !== path)
setOpenCodeBinaries(binaries)
saveConfig().catch(console.error)
}
function updateLastUsedBinary(path: string): void {
updatePreferences({ lastUsedBinary: path })
const binaries = opencodeBinaries()
const binary = binaries.find((b) => b.path === path)
if (binary) {
binary.lastUsed = Date.now()
// Move to front
const sorted = [binary, ...binaries.filter((b) => b.path !== path)]
setOpenCodeBinaries(sorted)
saveConfig().catch(console.error)
}
}
// Load config on mount and listen for changes from other instances
onMount(() => {
loadConfig()
@@ -79,4 +118,15 @@ onMount(() => {
return unsubscribe
})
export { preferences, updatePreferences, toggleShowThinkingBlocks, recentFolders, addRecentFolder, removeRecentFolder }
export {
preferences,
updatePreferences,
toggleShowThinkingBlocks,
recentFolders,
addRecentFolder,
removeRecentFolder,
opencodeBinaries,
addOpenCodeBinary,
removeOpenCodeBinary,
updateLastUsedBinary,
}