mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(desktop): follow up dev server split
Point dev-channel users with an empty Home to their earlier sessions in OpenCode Beta, make the startup probe read OPENCODE_DESKTOP_SERVER_CHANNEL like the main connection by resolving the service file from the environment in one place, and tidy the cli-version test tables.
This commit is contained in:
parent
8ee9351be9
commit
5d3d9b14de
6 changed files with 42 additions and 22 deletions
|
|
@ -178,6 +178,7 @@ export function HomeSessionsView(props: HomeSessionsViewProps) {
|
|||
fallback={
|
||||
<HomeSessionsEmpty
|
||||
onNewSession={props.canCreateSession ? props.onCreateSession : undefined}
|
||||
devChannel={props.desktop && import.meta.env.VITE_OPENCODE_CHANNEL === "dev"}
|
||||
language={props.language}
|
||||
/>
|
||||
}
|
||||
|
|
@ -910,7 +911,11 @@ function HomeSessionProjectName(props: { name: string; search?: boolean; trailin
|
|||
)
|
||||
}
|
||||
|
||||
function HomeSessionsEmpty(props: { onNewSession?: () => void; language: ReturnType<typeof useLanguage> }) {
|
||||
function HomeSessionsEmpty(props: {
|
||||
onNewSession?: () => void
|
||||
devChannel: boolean
|
||||
language: ReturnType<typeof useLanguage>
|
||||
}) {
|
||||
return (
|
||||
<div class="flex min-h-full flex-col items-center gap-4 px-6 pt-[52px] text-center">
|
||||
<div
|
||||
|
|
@ -936,6 +941,11 @@ function HomeSessionsEmpty(props: { onNewSession?: () => void; language: ReturnT
|
|||
</Button>
|
||||
)}
|
||||
</Show>
|
||||
<Show when={props.devChannel}>
|
||||
<p class="text-center text-[13px] leading-5 tracking-[-0.04px] text-v2-text-text-faint [font-weight:440]">
|
||||
{props.language.t("home.sessions.empty.devChannel")}
|
||||
</p>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -557,6 +557,7 @@ export const dict = {
|
|||
"home.sessions.search.noResults": "No sessions found for {{query}}",
|
||||
"home.sessions.empty": "Nothing here yet",
|
||||
"home.sessions.empty.description": "Create a session to get started",
|
||||
"home.sessions.empty.devChannel": "Dev builds keep their own sessions. Your earlier sessions are in OpenCode Beta.",
|
||||
"home.sessions.group.today": "Today",
|
||||
"home.sessions.group.yesterday": "Yesterday",
|
||||
"home.sessions.group.older": "Older",
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ export const layer = Layer.effect(
|
|||
const connect = Effect.fn("BackgroundService.connect")(function* (mode: "initial" | "reconnect") {
|
||||
yield* Effect.logInfo("starting v2 background service")
|
||||
const fs = yield* FileSystem.FileSystem
|
||||
const path = yield* Path.Path
|
||||
const desktopCli = yield* DesktopCli.Service
|
||||
const runFork = Effect.runForkWith(yield* Effect.context<FileSystem.FileSystem | Path.Path>())
|
||||
const isolated = !app.isPackaged && process.env.OPENCODE_DESKTOP_ISOLATED_SERVER === "1"
|
||||
|
|
@ -46,11 +45,7 @@ const connect = Effect.fn("BackgroundService.connect")(function* (mode: "initial
|
|||
if (isolated) process.env.XDG_STATE_HOME = app.getPath("userData")
|
||||
const client = yield* Effect.promise(() => import("@opencode/client/service"))
|
||||
|
||||
const file = serviceFile({
|
||||
version: cli.version,
|
||||
server: process.env.OPENCODE_DESKTOP_SERVER_CHANNEL,
|
||||
stateHome: process.env.XDG_STATE_HOME ?? path.join(app.getPath("home"), ".local", "state"),
|
||||
})
|
||||
const file = serviceFile({ version: cli.version, env: process.env, home: app.getPath("home") })
|
||||
|
||||
const ensure = (required = version) =>
|
||||
client.Service.ensure({
|
||||
|
|
|
|||
|
|
@ -51,12 +51,26 @@ describe("cli-version", () => {
|
|||
|
||||
// The file follows the CLI, not the app: a source build of the desktop runs whichever CLI it downloaded or built.
|
||||
test.each([
|
||||
{ version: "0.0.0-dev-9", server: undefined, expected: path.join("/state", "opencode", "service-dev.json") },
|
||||
{ version: "2.0.32", server: undefined, expected: undefined },
|
||||
{ version: "0.0.0-beta-2", server: undefined, expected: undefined },
|
||||
{ version: "0.0.0-dev-9", server: "", expected: path.join("/state", "opencode", "service-dev.json") },
|
||||
{ version: "2.0.32", server: "", expected: undefined },
|
||||
{ version: "0.0.0-beta-2", server: "", expected: undefined },
|
||||
{ version: "local", server: "local", expected: path.join("/state", "opencode", "service-local.json") },
|
||||
// The startup probe of a packaged build honours the override too, so it looks where the connection will.
|
||||
{ version: "0.0.0-beta-2", server: "local", expected: path.join("/state", "opencode", "service-local.json") },
|
||||
])("serviceFile($version, server=$server)", (input) => {
|
||||
expect(serviceFile({ ...input, stateHome: "/state" })).toBe(input.expected)
|
||||
expect(
|
||||
serviceFile({
|
||||
version: input.version,
|
||||
env: { OPENCODE_DESKTOP_SERVER_CHANNEL: input.server, XDG_STATE_HOME: "/state" },
|
||||
home: "/home",
|
||||
}),
|
||||
).toBe(input.expected)
|
||||
})
|
||||
|
||||
test("serviceFile falls back to ~/.local/state", () => {
|
||||
expect(serviceFile({ version: "0.0.0-dev-9", env: {}, home: "/home" })).toBe(
|
||||
path.join("/home", ".local", "state", "opencode", "service-dev.json"),
|
||||
)
|
||||
})
|
||||
|
||||
test.each([
|
||||
|
|
@ -71,13 +85,13 @@ describe("cli-version", () => {
|
|||
{ pinned: false, message: "Background service failed to start", expected: true },
|
||||
{ pinned: false, message: "Timed out waiting for the background service to start", expected: true },
|
||||
{
|
||||
version: releasedBuild,
|
||||
pinned: false,
|
||||
message:
|
||||
"Background service uses an incompatible health protocol. Update this client or explicitly restart the service.",
|
||||
expected: false,
|
||||
},
|
||||
{ pinned: true, message: "Background service failed to start", expected: false },
|
||||
])("shouldRetryEnsure($message) -> $expected", (input) => {
|
||||
])("shouldRetryEnsure(pinned=$pinned, $message) -> $expected", (input) => {
|
||||
expect(shouldRetryEnsure(input.pinned, input.message)).toBe(input.expected)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -37,13 +37,16 @@ export function releasedBuild(version: string) {
|
|||
export function serviceFile(input: {
|
||||
/** The CLI's version. */
|
||||
readonly version: string
|
||||
/** `OPENCODE_DESKTOP_SERVER_CHANNEL`: `local` for a CLI built from this checkout. */
|
||||
readonly server?: string
|
||||
readonly stateHome: string
|
||||
/** Reads `OPENCODE_DESKTOP_SERVER_CHANNEL` (`local` for a CLI built from this checkout) and `XDG_STATE_HOME`. */
|
||||
readonly env: NodeJS.ProcessEnv
|
||||
readonly home: string
|
||||
}) {
|
||||
if (input.server === "local") return path.join(input.stateHome, "opencode", "service-local.json")
|
||||
const stateHome = input.env.XDG_STATE_HOME ?? path.join(input.home, ".local", "state")
|
||||
|
||||
if (!releasedBuild(input.version)) return path.join(input.stateHome, "opencode", "service-dev.json")
|
||||
if (input.env.OPENCODE_DESKTOP_SERVER_CHANNEL === "local")
|
||||
return path.join(stateHome, "opencode", "service-local.json")
|
||||
|
||||
if (!releasedBuild(input.version)) return path.join(stateHome, "opencode", "service-dev.json")
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,7 @@ export function startSidecarProbe() {
|
|||
|
||||
if (version === "") return
|
||||
|
||||
const file = serviceFile({
|
||||
version: bundled,
|
||||
stateHome: process.env.XDG_STATE_HOME ?? path.join(homedir(), ".local", "state"),
|
||||
})
|
||||
const file = serviceFile({ version: bundled, env: process.env, home: homedir() })
|
||||
|
||||
probe = import("@opencode/client/service")
|
||||
.then(({ Service }) => Service.discover({ file, version }))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue