This reverts: -28b03595bresearch: delete Hono backend (do not merge) (#25667) -b24a4e897chore(server): clean up post-Hono-deletion scar tissue (#26542) v1.14.42 broke startup for users with plugins that depend on the Hono wire format (most visibly opencode-gemini-auth, see #26546). Restoring Hono as the default backend on stable channels while we investigate the actual plugin compatibility story. OPENCODE_EXPERIMENTAL_HTTPAPI flag and dual-backend selection come back. Stable installs default to Hono; dev/beta default to HTTP API. Conflict resolution: took the pre-deletion side for control-plane schemas and the seven test files where post-deletion follow-up PRs had also touched the conflicting lines. The HTTP API code added since the deletion (compression, cors-vary, fence, lifecycle log, account error mapping, etc.) is preserved as-is — those still apply on the HTTP API path for users on dev/beta channels.
41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
import { Flag } from "@opencode-ai/core/flag/flag"
|
|
import { Effect } from "effect"
|
|
import path from "path"
|
|
|
|
const preserveExerciseGlobalRoot = !!process.env.OPENCODE_HTTPAPI_EXERCISE_GLOBAL
|
|
export const exerciseGlobalRoot =
|
|
process.env.OPENCODE_HTTPAPI_EXERCISE_GLOBAL ??
|
|
path.join(process.env.TMPDIR ?? "/tmp", `opencode-httpapi-global-${process.pid}`)
|
|
process.env.XDG_DATA_HOME = path.join(exerciseGlobalRoot, "data")
|
|
process.env.XDG_CONFIG_HOME = path.join(exerciseGlobalRoot, "config")
|
|
process.env.XDG_STATE_HOME = path.join(exerciseGlobalRoot, "state")
|
|
process.env.XDG_CACHE_HOME = path.join(exerciseGlobalRoot, "cache")
|
|
process.env.OPENCODE_DISABLE_SHARE = "true"
|
|
export const exerciseConfigDirectory = path.join(exerciseGlobalRoot, "config", "opencode")
|
|
export const exerciseDataDirectory = path.join(exerciseGlobalRoot, "data", "opencode")
|
|
|
|
const preserveExerciseDatabase = !!process.env.OPENCODE_HTTPAPI_EXERCISE_DB
|
|
export const exerciseDatabasePath =
|
|
process.env.OPENCODE_HTTPAPI_EXERCISE_DB ??
|
|
path.join(process.env.TMPDIR ?? "/tmp", `opencode-httpapi-exercise-${process.pid}.db`)
|
|
process.env.OPENCODE_DB = exerciseDatabasePath
|
|
Flag.OPENCODE_DB = exerciseDatabasePath
|
|
|
|
export const original = {
|
|
OPENCODE_EXPERIMENTAL_HTTPAPI: Flag.OPENCODE_EXPERIMENTAL_HTTPAPI,
|
|
OPENCODE_SERVER_PASSWORD: Flag.OPENCODE_SERVER_PASSWORD,
|
|
OPENCODE_SERVER_USERNAME: Flag.OPENCODE_SERVER_USERNAME,
|
|
}
|
|
|
|
export const cleanupExercisePaths = Effect.promise(async () => {
|
|
const fs = await import("fs/promises")
|
|
if (!preserveExerciseDatabase) {
|
|
await Promise.all(
|
|
[exerciseDatabasePath, `${exerciseDatabasePath}-wal`, `${exerciseDatabasePath}-shm`].map((file) =>
|
|
fs.rm(file, { force: true }).catch(() => undefined),
|
|
),
|
|
)
|
|
}
|
|
if (!preserveExerciseGlobalRoot)
|
|
await fs.rm(exerciseGlobalRoot, { recursive: true, force: true }).catch(() => undefined)
|
|
})
|