Visitar URL original
refactor(opencode): remove JSON storage migration · anomalyco/opencode@7f34399 · GitHub
Skip to content

Commit 7f34399

Browse files
committed
refactor(opencode): remove JSON storage migration
1 parent 7f1ef5f commit 7f34399

20 files changed

Lines changed: 17 additions & 1590 deletions

File tree

‎bun.lock‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/desktop/electron.vite.config.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export default defineConfig({
8888
rollupOptions: {
8989
input: {
9090
main: "src/renderer/index.html",
91-
loading: "src/renderer/loading.html",
9291
},
9392
},
9493
},

‎packages/desktop/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"electron-store": "^10",
3232
"electron-updater": "^6",
3333
"electron-window-state": "^5.0.3",
34-
"drizzle-orm": "catalog:",
3534
"marked": "^15"
3635
},
3736
"devDependencies": {

‎packages/desktop/src/main/env.d.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,5 @@ declare module "virtual:opencode-server" {
1818
export namespace Log {
1919
export const init: typeof import("../../../opencode/dist/types/src/node").Log.init
2020
}
21-
export namespace Database {
22-
export const getPath: typeof import("../../../opencode/dist/types/src/node").Database.getPath
23-
export const Client: typeof import("../../../opencode/dist/types/src/node").Database.Client
24-
}
25-
export namespace JsonMigration {
26-
export type Progress = import("../../../opencode/dist/types/src/node").JsonMigration.Progress
27-
export const run: typeof import("../../../opencode/dist/types/src/node").JsonMigration.run
28-
}
2921
export const bootstrap: typeof import("../../../opencode/dist/types/src/node").bootstrap
3022
}

‎packages/desktop/src/main/index.ts‎

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { randomUUID } from "node:crypto"
2-
import { EventEmitter } from "node:events"
3-
import { existsSync, mkdirSync, rmSync } from "node:fs"
2+
import { mkdirSync, rmSync } from "node:fs"
43
import * as http from "node:http"
54
import { createServer } from "node:net"
65
import { homedir, tmpdir } from "node:os"
@@ -11,10 +10,10 @@ import { app, BrowserWindow } from "electron"
1110

1211
import contextMenu from "electron-context-menu"
1312

14-
import type { InitStep, ServerReadyData, SqliteMigrationProgress, WslConfig } from "../preload/types"
13+
import type { ServerReadyData, WslConfig } from "../preload/types"
1514
import { checkAppExists, resolveAppPath, wslPath } from "./apps"
1615
import { CHANNEL, UPDATER_ENABLED } from "./constants"
17-
import { registerIpcHandlers, sendDeepLinks, sendMenuCommand, sendSqliteMigrationProgress } from "./ipc"
16+
import { registerIpcHandlers, sendDeepLinks, sendMenuCommand } from "./ipc"
1817
import { exportDebugLogs, initCrashReporter, initLogging, startNetLog, write as writeLog } from "./logging"
1918
import { parseMarkdown } from "./markdown"
2019
import { createMenu } from "./menu"
@@ -28,7 +27,6 @@ import {
2827
type SidecarListener,
2928
} from "./server"
3029
import {
31-
createLoadingWindow,
3230
createMainWindow,
3331
registerRendererProtocol,
3432
setRelaunchHandler,
@@ -56,9 +54,6 @@ let logger: ReturnType<typeof initLogging>
5654
let mainWindow: BrowserWindow | null = null
5755
let server: SidecarListener | null = null
5856

59-
const initEmitter = new EventEmitter()
60-
let initStep: InitStep = { phase: "server_waiting" }
61-
6257
const pendingDeepLinks: string[] = []
6358

6459
function useEnvProxy() {
@@ -76,12 +71,6 @@ function emitDeepLinks(urls: string[]) {
7671
if (mainWindow) sendDeepLinks(mainWindow, urls)
7772
}
7873

79-
function setInitStep(step: InitStep) {
80-
initStep = step
81-
logger.log("init step", { step })
82-
initEmitter.emit("step", step)
83-
}
84-
8574
async function killSidecar() {
8675
if (!server) return
8776
const current = server
@@ -219,23 +208,15 @@ const main = Effect.gen(function* () {
219208
}
220209

221210
const serverReady = Deferred.makeUnsafe<ServerReadyData>()
222-
const loadingComplete = Deferred.makeUnsafe<void>()
223211

224212
registerIpcHandlers({
225213
killSidecar: () => killSidecar(),
226214
awaitInitialization: Effect.fnUntraced(
227-
function* (sendStep) {
228-
sendStep(initStep)
229-
const listener = (step: InitStep) => sendStep(step)
230-
initEmitter.on("step", listener)
231-
try {
232-
logger.log("awaiting server ready")
233-
const res = yield* Deferred.await(serverReady)
234-
logger.log("server ready", { url: res.url })
235-
return res
236-
} finally {
237-
initEmitter.off("step", listener)
238-
}
215+
function* () {
216+
logger.log("awaiting server ready")
217+
const res = yield* Deferred.await(serverReady)
218+
logger.log("server ready", { url: res.url })
219+
return res
239220
},
240221
(e) => Effect.runPromise(e),
241222
),
@@ -251,7 +232,6 @@ const main = Effect.gen(function* () {
251232
checkAppExists: (appName) => checkAppExists(appName),
252233
wslPath: async (path, mode) => wslPath(path, mode),
253234
resolveAppPath: async (appName) => resolveAppPath(appName),
254-
loadingWindowComplete: () => Deferred.doneUnsafe(loadingComplete, Effect.void),
255235
runUpdater: async (alertOnFail) => checkForUpdates(alertOnFail, killSidecar),
256236
checkUpdate: async () => checkUpdate(),
257237
installUpdate: async () => installUpdate(killSidecar),
@@ -275,15 +255,6 @@ const main = Effect.gen(function* () {
275255
),
276256
)
277257

278-
const needsMigration = ((): boolean => {
279-
if (process.env.OPENCODE_DB === ":memory:") return false
280-
281-
const xdg = process.env.XDG_DATA_HOME
282-
const base = xdg && xdg.length > 0 ? xdg : join(homedir(), ".local", "share")
283-
return !existsSync(join(base, "opencode", "opencode.db"))
284-
})()
285-
let overlay: BrowserWindow | null = null
286-
287258
const port = yield* Effect.gen(function* () {
288259
const fromEnv = process.env.OPENCODE_PORT
289260
if (fromEnv) {
@@ -314,21 +285,13 @@ const main = Effect.gen(function* () {
314285
const loadingTask = yield* Effect.gen(function* () {
315286
logger.log("sidecar connection started", { url })
316287

317-
initEmitter.on("sqlite", (progress: SqliteMigrationProgress) => {
318-
setInitStep({ phase: "sqlite_waiting" })
319-
if (overlay) sendSqliteMigrationProgress(overlay, progress)
320-
if (mainWindow) sendSqliteMigrationProgress(mainWindow, progress)
321-
})
322-
323288
ensureLoopbackNoProxy()
324289
useEnvProxy()
325290

326291
logger.log("spawning sidecar", { url })
327292
const { listener, health } = yield* Effect.promise(() =>
328293
spawnLocalServer(hostname, port, password, {
329-
needsMigration,
330294
userDataPath: app.getPath("userData"),
331-
onSqliteProgress: (progress) => initEmitter.emit("sqlite", progress),
332295
onStdout: (message) => writeLog("server", "stdout", { message }),
333296
onStderr: (message) => writeLog("server", "stderr", { message }, "warn"),
334297
onExit: (code) => writeLog("utility", "sidecar exited", { code }, "warn"),
@@ -353,23 +316,7 @@ const main = Effect.gen(function* () {
353316
logger.log("loading task finished")
354317
}).pipe(Effect.forkChild)
355318

356-
if (needsMigration) {
357-
const show = yield* loadingTask.pipe(
358-
Fiber.await,
359-
Effect.timeout("1 second"),
360-
Effect.as(false),
361-
Effect.catch(() => Effect.succeed(true)),
362-
)
363-
if (show) {
364-
overlay = createLoadingWindow()
365-
yield* Effect.sleep("1 second")
366-
}
367-
}
368-
369319
yield* Fiber.await(loadingTask)
370-
setInitStep({ phase: "done" })
371-
372-
if (overlay) yield* Deferred.await(loadingComplete)
373320

374321
mainWindow = createMainWindow()
375322
if (mainWindow) {
@@ -389,8 +336,6 @@ const main = Effect.gen(function* () {
389336
},
390337
})
391338
}
392-
393-
overlay?.close()
394339
})
395340

396341
Effect.runFork(main)

‎packages/desktop/src/main/ipc.ts‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import type { IpcMainEvent, IpcMainInvokeEvent } from "electron"
44
import type { DesktopMenuAction } from "@opencode-ai/app/desktop-menu"
55

66
import type {
7-
InitStep,
87
FatalRendererError,
98
ServerReadyData,
10-
SqliteMigrationProgress,
119
TitlebarTheme,
1210
WindowConfig,
1311
WslConfig,
@@ -23,7 +21,7 @@ const pickerFilters = (ext?: string[]) => {
2321

2422
type Deps = {
2523
killSidecar: () => Promise<void> | void
26-
awaitInitialization: (sendStep: (step: InitStep) => void) => Promise<ServerReadyData>
24+
awaitInitialization: () => Promise<ServerReadyData>
2725
getWindowConfig: () => Promise<WindowConfig> | WindowConfig
2826
consumeInitialDeepLinks: () => Promise<string[]> | string[]
2927
getDefaultServerUrl: () => Promise<string | null> | string | null
@@ -36,7 +34,6 @@ type Deps = {
3634
checkAppExists: (appName: string) => Promise<boolean> | boolean
3735
wslPath: (path: string, mode: "windows" | "linux" | null) => Promise<string>
3836
resolveAppPath: (appName: string) => Promise<string | null>
39-
loadingWindowComplete: () => void
4037
runUpdater: (alertOnFail: boolean) => Promise<void> | void
4138
checkUpdate: () => Promise<{ updateAvailable: boolean; version?: string }>
4239
installUpdate: () => Promise<void> | void
@@ -47,10 +44,7 @@ type Deps = {
4744

4845
export function registerIpcHandlers(deps: Deps) {
4946
ipcMain.handle("kill-sidecar", () => deps.killSidecar())
50-
ipcMain.handle("await-initialization", (event: IpcMainInvokeEvent) => {
51-
const send = (step: InitStep) => event.sender.send("init-step", step)
52-
return deps.awaitInitialization(send)
53-
})
47+
ipcMain.handle("await-initialization", () => deps.awaitInitialization())
5448
ipcMain.handle("get-window-config", () => deps.getWindowConfig())
5549
ipcMain.handle("consume-initial-deep-links", () => deps.consumeInitialDeepLinks())
5650
ipcMain.handle("get-default-server-url", () => deps.getDefaultServerUrl())
@@ -69,7 +63,6 @@ export function registerIpcHandlers(deps: Deps) {
6963
deps.wslPath(path, mode),
7064
)
7165
ipcMain.handle("resolve-app-path", (_event: IpcMainInvokeEvent, appName: string) => deps.resolveAppPath(appName))
72-
ipcMain.on("loading-window-complete", () => deps.loadingWindowComplete())
7366
ipcMain.handle("run-updater", (_event: IpcMainInvokeEvent, alertOnFail: boolean) => deps.runUpdater(alertOnFail))
7467
ipcMain.handle("check-update", () => deps.checkUpdate())
7568
ipcMain.handle("install-update", () => deps.installUpdate())
@@ -216,10 +209,6 @@ export function registerIpcHandlers(deps: Deps) {
216209
})
217210
}
218211

219-
export function sendSqliteMigrationProgress(win: BrowserWindow, progress: SqliteMigrationProgress) {
220-
win.webContents.send("sqlite-migration-progress", progress)
221-
}
222-
223212
export function sendMenuCommand(win: BrowserWindow, id: string) {
224213
win.webContents.send("menu-command", id)
225214
}

‎packages/desktop/src/main/server.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import type { Details } from "electron"
55
import { DEFAULT_SERVER_URL_KEY, WSL_ENABLED_KEY } from "./constants"
66
import { getUserShell, loadShellEnv } from "./shell-env"
77
import { getStore } from "./store"
8-
import type { SqliteMigrationProgress } from "../preload/types"
98

109
export type WslConfig = { enabled: boolean }
1110

1211
export type HealthCheck = { wait: Promise<void> }
1312

1413
type SidecarMessage =
15-
| { type: "sqlite"; progress: SqliteMigrationProgress }
1614
| { type: "ready" }
1715
| { type: "stopped" }
1816
| { type: "error"; error: { message: string; stack?: string } }
@@ -24,9 +22,7 @@ const SIDECAR_START_STALL_TIMEOUT = 60_000
2422
const SIDECAR_STOP_TIMEOUT = 6_000
2523

2624
type SpawnLocalServerOptions = {
27-
needsMigration: boolean
2825
userDataPath: string
29-
onSqliteProgress?: (progress: SqliteMigrationProgress) => void
3026
onStdout?: (message: string) => void
3127
onStderr?: (message: string) => void
3228
onExit?: (code: number) => void
@@ -118,11 +114,6 @@ export async function spawnLocalServer(
118114
}
119115

120116
const onMessage = (message: SidecarMessage) => {
121-
if (message.type === "sqlite") {
122-
refreshTimeout()
123-
options.onSqliteProgress?.(message.progress)
124-
return
125-
}
126117
if (message.type === "ready") {
127118
if (done) return
128119
done = true
@@ -152,7 +143,6 @@ export async function spawnLocalServer(
152143
port,
153144
password,
154145
userDataPath: options.userDataPath,
155-
needsMigration: options.needsMigration,
156146
})
157147
}).catch((error) => {
158148
if (!exited) child.kill()

‎packages/desktop/src/main/sidecar.ts‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { drizzle } from "drizzle-orm/node-sqlite/driver"
21
import * as http from "node:http"
32
import * as tls from "node:tls"
43

@@ -17,14 +16,12 @@ type StartCommand = {
1716
port: number
1817
password: string
1918
userDataPath: string
20-
needsMigration: boolean
2119
}
2220

2321
type StopCommand = { type: "stop" }
2422
type SidecarCommand = StartCommand | StopCommand
2523

2624
type SidecarMessage =
27-
| { type: "sqlite"; progress: { type: "InProgress"; value: number } | { type: "Done" } }
2825
| { type: "ready" }
2926
| { type: "stopped" }
3027
| { type: "error"; error: { message: string; stack?: string } }
@@ -57,24 +54,9 @@ async function start(command: StartCommand) {
5754
ensureLoopbackNoProxy()
5855
useSystemCertificates()
5956
useEnvProxy()
60-
const { Database, JsonMigration, Log, Server } = await import("virtual:opencode-server")
57+
const { Log, Server } = await import("virtual:opencode-server")
6158
await Log.init({ level: "WARN" })
6259

63-
if (command.needsMigration) {
64-
await JsonMigration.run(drizzle({ client: Database.Client().$client }), {
65-
progress: (event: { current: number; total: number }) => {
66-
parentPort.postMessage({
67-
type: "sqlite",
68-
progress: {
69-
type: "InProgress",
70-
value: event.total === 0 ? 100 : Math.round((event.current / event.total) * 100),
71-
},
72-
})
73-
},
74-
})
75-
parentPort.postMessage({ type: "sqlite", progress: { type: "Done" } })
76-
}
77-
7860
listener = await Server.listen({
7961
port: command.port,
8062
hostname: command.hostname,
@@ -155,14 +137,12 @@ function parseCommand(value: unknown): SidecarCommand | undefined {
155137
if (typeof command.port !== "number") return
156138
if (typeof command.password !== "string") return
157139
if (typeof command.userDataPath !== "string") return
158-
if (typeof command.needsMigration !== "boolean") return
159140
return {
160141
type: "start",
161142
hostname: command.hostname,
162143
port: command.port,
163144
password: command.password,
164145
userDataPath: command.userDataPath,
165-
needsMigration: command.needsMigration,
166146
}
167147
}
168148

0 commit comments

Comments
 (0)