The open source coding agent.
TypeScript
sync
Dax Raad6d21525e7171
diff --git a/packages/opencode/bin/opencode b/packages/opencode/bin/opencodenew file mode 100755index 00000000000..f1e1e2e3097--- /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.mjsdeleted file mode 100644index 05eac3fb7b0..00000000000--- 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.tsindex 7e6bac666dc..12d56de2493 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.tsindex 77738c7c738..e311a30445d 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()