Skip to content

Commit 6d21525

Browse files
committed
sync
1 parent b4f8095 commit 6d21525

4 files changed

Lines changed: 68 additions & 33 deletions

File tree

packages/opencode/bin/opencode

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ -n "$OPENCODE_BIN_PATH" ]; then
5+
resolved="$OPENCODE_BIN_PATH"
6+
else
7+
# Get the real path of this script, resolving any symlinks
8+
script_path="$0"
9+
while [ -L "$script_path" ]; do
10+
link_target="$(readlink "$script_path")"
11+
case "$link_target" in
12+
/*) script_path="$link_target" ;;
13+
*) script_path="$(dirname "$script_path")/$link_target" ;;
14+
esac
15+
done
16+
script_dir="$(dirname "$script_path")"
17+
script_dir="$(cd "$script_dir" && pwd)"
18+
19+
# Map platform names
20+
case "$(uname -s)" in
21+
Darwin) platform="darwin" ;;
22+
Linux) platform="linux" ;;
23+
MINGW*|CYGWIN*|MSYS*) platform="win32" ;;
24+
*) platform="$(uname -s | tr '[:upper:]' '[:lower:]')" ;;
25+
esac
26+
27+
# Map architecture names
28+
case "$(uname -m)" in
29+
x86_64|amd64) arch="x64" ;;
30+
aarch64) arch="arm64" ;;
31+
armv7l) arch="arm" ;;
32+
*) arch="$(uname -m)" ;;
33+
esac
34+
35+
name="opencode-${platform}-${arch}"
36+
binary="opencode"
37+
[ "$platform" = "win32" ] && binary="opencode.exe"
38+
39+
# Search for the binary starting from real script location
40+
resolved=""
41+
current_dir="$script_dir"
42+
while [ "$current_dir" != "/" ]; do
43+
candidate="$current_dir/node_modules/$name/bin/$binary"
44+
if [ -f "$candidate" ]; then
45+
resolved="$candidate"
46+
break
47+
fi
48+
current_dir="$(dirname "$current_dir")"
49+
done
50+
51+
if [ -z "$resolved" ]; then
52+
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
53+
exit 1
54+
fi
55+
fi
56+
57+
# Handle SIGINT gracefully
58+
trap '' INT
59+
60+
# Execute the binary with all arguments
61+
exec "$resolved" "$@"

packages/opencode/bin/opencode.mjs

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/opencode/script/release.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ for (const [os, arch] of targets) {
3131
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(
3232
"../tui",
3333
)
34-
await $`bun build --compile --minify --target=bun-${os}-${arch} --outfile=dist/${name}/bin/opencode ./src/index.ts ./dist/${name}/bin/tui`
34+
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`
3535
await $`rm -rf ./dist/${name}/bin/tui`
3636
await Bun.file(`dist/${name}/package.json`).write(
3737
JSON.stringify(
@@ -56,7 +56,7 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
5656
{
5757
name: pkg.name + "-ai",
5858
bin: {
59-
[pkg.name]: `./bin/${pkg.name}.mjs`,
59+
[pkg.name]: `./bin/${pkg.name}`,
6060
},
6161
version,
6262
optionalDependencies,

packages/opencode/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import { Bus } from "./bus"
77
import { Session } from "./session/session"
88
import cac from "cac"
99
import { Share } from "./share/share"
10-
import { LLM } from "./llm/llm"
1110
import { Message } from "./session/message"
1211
import { Global } from "./global"
1312
import { Provider } from "./provider/provider"
1413

14+
declare global {
15+
const OPENCODE_VERSION: string
16+
}
17+
1518
const cli = cac("opencode")
1619

1720
cli.command("", "Start the opencode in interactive mode").action(async () => {
@@ -111,6 +114,6 @@ cli
111114
})
112115
})
113116

117+
cli.version(typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "dev")
114118
cli.help()
115-
cli.version("1.0.0")
116119
cli.parse()

0 commit comments

Comments
 (0)