summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-31 18:10:49 -0400
committerDax Raad <[email protected]>2025-05-31 18:10:49 -0400
commit6d21525e717122f106c87821fc2aab9f7d2c3fe5 (patch)
tree3e3bc33a75bc85aaf2cfe604ca1e03931ba2ee1b
parentb4f809559eb2eb5634e9e2ee2d35a4ded9d67578 (diff)
downloadopencode-6d21525e717122f106c87821fc2aab9f7d2c3fe5.tar.gz
opencode-6d21525e717122f106c87821fc2aab9f7d2c3fe5.zip
sync
-rwxr-xr-xpackages/opencode/bin/opencode61
-rw-r--r--packages/opencode/bin/opencode.mjs29
-rwxr-xr-xpackages/opencode/script/release.ts4
-rw-r--r--packages/opencode/src/index.ts7
4 files changed, 68 insertions, 33 deletions
diff --git a/packages/opencode/bin/opencode b/packages/opencode/bin/opencode
new file mode 100755
index 000000000..f1e1e2e30
--- /dev/null
+++ b/packages/opencode/bin/opencode
@@ -0,0 +1,61 @@
+#!/bin/sh
+set -e
+
+if [ -n "$OPENCODE_BIN_PATH" ]; then
+ resolved="$OPENCODE_BIN_PATH"
+else
+ # Get the real path of this script, resolving any symlinks
+ script_path="$0"
+ while [ -L "$script_path" ]; do
+ link_target="$(readlink "$script_path")"
+ case "$link_target" in
+ /*) script_path="$link_target" ;;
+ *) script_path="$(dirname "$script_path")/$link_target" ;;
+ esac
+ done
+ script_dir="$(dirname "$script_path")"
+ script_dir="$(cd "$script_dir" && pwd)"
+
+ # Map platform names
+ case "$(uname -s)" in
+ Darwin) platform="darwin" ;;
+ Linux) platform="linux" ;;
+ MINGW*|CYGWIN*|MSYS*) platform="win32" ;;
+ *) platform="$(uname -s | tr '[:upper:]' '[:lower:]')" ;;
+ esac
+
+ # Map architecture names
+ case "$(uname -m)" in
+ x86_64|amd64) arch="x64" ;;
+ aarch64) arch="arm64" ;;
+ armv7l) arch="arm" ;;
+ *) arch="$(uname -m)" ;;
+ esac
+
+ name="opencode-${platform}-${arch}"
+ binary="opencode"
+ [ "$platform" = "win32" ] && binary="opencode.exe"
+
+ # Search for the binary starting from real script location
+ resolved=""
+ current_dir="$script_dir"
+ while [ "$current_dir" != "/" ]; do
+ candidate="$current_dir/node_modules/$name/bin/$binary"
+ if [ -f "$candidate" ]; then
+ resolved="$candidate"
+ break
+ fi
+ current_dir="$(dirname "$current_dir")"
+ done
+
+ if [ -z "$resolved" ]; then
+ printf "It seems that your package manager failed to install the right version of the SST CLI for your platform. You can try manually installing the \"%s\" package\n" "$name" >&2
+ exit 1
+ fi
+fi
+
+# Handle SIGINT gracefully
+trap '' INT
+
+# Execute the binary with all arguments
+exec "$resolved" "$@"
diff --git a/packages/opencode/bin/opencode.mjs b/packages/opencode/bin/opencode.mjs
deleted file mode 100644
index 05eac3fb7..000000000
--- a/packages/opencode/bin/opencode.mjs
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env node
-import { createRequire } from "node:module"
-const require = createRequire(import.meta.url)
-import path from "path"
-import { execFileSync } from "child_process"
-let resolved = process.env.SST_BIN_PATH
-if (!resolved) {
- const name = `opencode-${process.platform}-${process.arch}`
- const binary = process.platform === "win32" ? "opencode.exe" : "opencode"
- try {
- resolved = require.resolve(path.join(name, "bin", binary))
- } catch (ex) {
- console.error(
- `It seems that your package manager failed to install the right version of the SST CLI for your platform. You can try manually installing the "${name}" package`,
- )
-
- process.exit(1)
- }
-}
-
-process.on("SIGINT", () => {})
-
-try {
- execFileSync(resolved, process.argv.slice(2), {
- stdio: "inherit",
- })
-} catch (ex) {
- process.exit(1)
-}
diff --git a/packages/opencode/script/release.ts b/packages/opencode/script/release.ts
index 7e6bac666..12d56de24 100755
--- a/packages/opencode/script/release.ts
+++ b/packages/opencode/script/release.ts
@@ -31,7 +31,7 @@ for (const [os, arch] of targets) {
await $`GOOS=${os} GOARCH=${GOARCH[arch]} go build -ldflags="-s -w -X github.com/sst/opencode/internal/version.Version=${version}" -o ../opencode/dist/${name}/bin/tui ../tui/main.go`.cwd(
"../tui",
)
- await $`bun build --compile --minify --target=bun-${os}-${arch} --outfile=dist/${name}/bin/opencode ./src/index.ts ./dist/${name}/bin/tui`
+ await $`bun build --define OPENCODE_VERSION="'${version}'" --compile --minify --target=bun-${os}-${arch} --outfile=dist/${name}/bin/opencode ./src/index.ts ./dist/${name}/bin/tui`
await $`rm -rf ./dist/${name}/bin/tui`
await Bun.file(`dist/${name}/package.json`).write(
JSON.stringify(
@@ -56,7 +56,7 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
{
name: pkg.name + "-ai",
bin: {
- [pkg.name]: `./bin/${pkg.name}.mjs`,
+ [pkg.name]: `./bin/${pkg.name}`,
},
version,
optionalDependencies,
diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts
index 77738c7c7..e311a3044 100644
--- a/packages/opencode/src/index.ts
+++ b/packages/opencode/src/index.ts
@@ -7,11 +7,14 @@ import { Bus } from "./bus"
import { Session } from "./session/session"
import cac from "cac"
import { Share } from "./share/share"
-import { LLM } from "./llm/llm"
import { Message } from "./session/message"
import { Global } from "./global"
import { Provider } from "./provider/provider"
+declare global {
+ const OPENCODE_VERSION: string
+}
+
const cli = cac("opencode")
cli.command("", "Start the opencode in interactive mode").action(async () => {
@@ -111,6 +114,6 @@ cli
})
})
+cli.version(typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "dev")
cli.help()
-cli.version("1.0.0")
cli.parse()