Skip to content
Open
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
5 changes: 5 additions & 0 deletions packages/core/src/installation/version.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
declare global {
const OPENCODE_VERSION: string
const OPENCODE_CHANNEL: string
const OPENCODE_PLUGIN_VERSION: string
}

export const InstallationVersion = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local"
export const InstallationChannel = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local"
export const InstallationLocal = InstallationChannel === "local"
// Version of @opencode-ai/plugin installed into config directories. Builds whose own version is not
// published to npm (forks, custom builds) can pin a published one; otherwise it follows the binary.
export const InstallationPluginVersion =
typeof OPENCODE_PLUGIN_VERSION === "string" ? OPENCODE_PLUGIN_VERSION : InstallationVersion
3 changes: 3 additions & 0 deletions packages/opencode/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ for (const item of targets) {
OTUI_TREE_SITTER_WORKER_PATH: bunfsRoot + treeSitterWorkerPath,
OPENCODE_WORKER_PATH: workerPath,
OPENCODE_CHANNEL: `'${Script.channel}'`,
...(process.env.OPENCODE_PLUGIN_VERSION
? { OPENCODE_PLUGIN_VERSION: `'${process.env.OPENCODE_PLUGIN_VERSION}'` }
: {}),
OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "",
...(item.os === "linux" ? { "process.env.OPENTUI_LIBC": JSON.stringify(item.abi ?? "glibc") } : {}),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Flag } from "@opencode-ai/core/flag/flag"
import { Auth } from "../auth"
import { Env } from "../env"
import { applyEdits, modify } from "jsonc-parser"
import { InstallationLocal, InstallationVersion } from "@opencode-ai/core/installation/version"
import { InstallationLocal, InstallationPluginVersion } from "@opencode-ai/core/installation/version"
import { existsSync } from "fs"
import { Account } from "@/account/account"
import { isRecord } from "@/util/record"
Expand Down Expand Up @@ -454,7 +454,7 @@ const layer = Layer.effect(
add: [
{
name: "@opencode-ai/plugin",
version: InstallationLocal ? undefined : InstallationVersion,
version: InstallationLocal ? undefined : InstallationPluginVersion,
},
],
})
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/config/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { FSUtil } from "@opencode-ai/core/fs-util"
import { CurrentWorkingDirectory } from "./tui-cwd"
import { ConfigPlugin } from "@/config/plugin"
import { TuiKeybind } from "@opencode-ai/tui/config/keybind"
import { InstallationLocal, InstallationVersion } from "@opencode-ai/core/installation/version"
import { InstallationLocal, InstallationPluginVersion } from "@opencode-ai/core/installation/version"
import { makeRuntime } from "@opencode-ai/core/effect/runtime"
import { Filesystem } from "@/util/filesystem"
import { ConfigVariable } from "@/config/variable"
Expand Down Expand Up @@ -239,7 +239,7 @@ const layer = Layer.effect(
add: [
{
name: "@opencode-ai/plugin",
version: InstallationLocal ? undefined : InstallationVersion,
version: InstallationLocal ? undefined : InstallationPluginVersion,
},
],
})
Expand Down
8 changes: 7 additions & 1 deletion packages/opencode/test/installation/installation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as TestClock from "effect/testing/TestClock"
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
import { Installation } from "../../src/installation"
import { InstallationVersion } from "@opencode-ai/core/installation/version"
import { InstallationPluginVersion, InstallationVersion } from "@opencode-ai/core/installation/version"
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
import { testEffect } from "../lib/effect"

Expand Down Expand Up @@ -94,6 +94,12 @@ describe("installation", () => {
})
})

describe("plugin version", () => {
test("follows the binary version when no plugin version is pinned at build time", () => {
expect(InstallationPluginVersion).toBe(InstallationVersion)
})
})

describe("latest", () => {
const npm = "https://registry.npmjs.org/opencode-ai/latest"
const choco = "https://community.chocolatey.org/api/v2/Packages"
Expand Down
Loading