summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-06-12 00:50:49 -0400
committerDax Raad <[email protected]>2025-06-12 00:50:49 -0400
commitb7b490f67c1041e2ec36dda390967525338cb9e1 (patch)
tree7aa972a3b2ae926efe6a63f10494dfc8e49ccb13
parentf6ed59bf459defd4db62135d262fc222e909e0b3 (diff)
downloadopencode-b7b490f67c1041e2ec36dda390967525338cb9e1.tar.gz
opencode-b7b490f67c1041e2ec36dda390967525338cb9e1.zip
Add postinstall script and update session/release configuration
🤖 Generated with [OpenCode](https://opencode.ai) Co-Authored-By: OpenCode <[email protected]>
-rw-r--r--packages/opencode/script/postinstall.js90
-rwxr-xr-xpackages/opencode/script/release.ts4
-rw-r--r--packages/opencode/src/session/index.ts25
3 files changed, 107 insertions, 12 deletions
diff --git a/packages/opencode/script/postinstall.js b/packages/opencode/script/postinstall.js
new file mode 100644
index 000000000..7bf119269
--- /dev/null
+++ b/packages/opencode/script/postinstall.js
@@ -0,0 +1,90 @@
+#!/usr/bin/env node
+
+import fs from "fs"
+import path from "path"
+import os from "os"
+import { fileURLToPath } from "url"
+import { createRequire } from "module"
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url))
+const require = createRequire(import.meta.url)
+
+function detectPlatformAndArch() {
+ // Map platform names
+ let platform
+ switch (os.platform()) {
+ case "darwin":
+ platform = "darwin"
+ break
+ case "linux":
+ platform = "linux"
+ break
+ case "win32":
+ platform = "win32"
+ break
+ default:
+ platform = os.platform()
+ break
+ }
+
+ // Map architecture names
+ let arch
+ switch (os.arch()) {
+ case "x64":
+ arch = "x64"
+ break
+ case "arm64":
+ arch = "arm64"
+ break
+ case "arm":
+ arch = "arm"
+ break
+ default:
+ arch = os.arch()
+ break
+ }
+
+ return { platform, arch }
+}
+
+function findBinary() {
+ const { platform, arch } = detectPlatformAndArch()
+ const packageName = `opencode-${platform}-${arch}`
+ const binary = platform === "win32" ? "opencode.exe" : "opencode"
+
+ try {
+ // Use require.resolve to find the package
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
+ const packageDir = path.dirname(packageJsonPath)
+ const binaryPath = path.join(packageDir, "bin", binary)
+
+ if (!fs.existsSync(binaryPath)) {
+ throw new Error(`Binary not found at ${binaryPath}`)
+ }
+
+ return binaryPath
+ } catch (error) {
+ throw new Error(`Could not find package ${packageName}: ${error.message}`)
+ }
+}
+
+function main() {
+ try {
+ const binaryPath = findBinary()
+ const binScript = path.join(__dirname, "bin", "opencode")
+
+ // Remove existing bin script if it exists
+ if (fs.existsSync(binScript)) {
+ fs.unlinkSync(binScript)
+ }
+
+ // Create symlink to the actual binary
+ fs.symlinkSync(binaryPath, binScript)
+ console.log(`OpenCode binary symlinked: ${binScript} -> ${binaryPath}`)
+ } catch (error) {
+ console.error("Failed to create OpenCode binary symlink:", error.message)
+ process.exit(1)
+ }
+}
+
+main()
diff --git a/packages/opencode/script/release.ts b/packages/opencode/script/release.ts
index 39a9acf43..e75ca9736 100755
--- a/packages/opencode/script/release.ts
+++ b/packages/opencode/script/release.ts
@@ -51,6 +51,7 @@ for (const [os, arch] of targets) {
await $`mkdir -p ./dist/${pkg.name}`
await $`cp -r ./bin ./dist/${pkg.name}/bin`
+await $`cp ./script/postinstall.js ./dist/${pkg.name}/postinstall.js`
await Bun.file(`./dist/${pkg.name}/package.json`).write(
JSON.stringify(
{
@@ -58,6 +59,9 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
bin: {
[pkg.name]: `./bin/${pkg.name}`,
},
+ scripts: {
+ postinstall: "node ./postinstall.js",
+ },
version,
optionalDependencies,
},
diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts
index 8ffabaa60..59d0ca361 100644
--- a/packages/opencode/src/session/index.ts
+++ b/packages/opencode/src/session/index.ts
@@ -465,22 +465,23 @@ export namespace Session {
} else text.text += value.text
break
- case "tool-call":
- next.parts.push({
- type: "tool-invocation",
- toolInvocation: {
- state: "call",
- ...value,
- // hack until zod v4
- args: value.args as any,
- },
- })
+ case "tool-call": {
+ const [match] = next.parts.flatMap((p) =>
+ p.type === "tool-invocation" &&
+ p.toolInvocation.toolCallId === value.toolCallId
+ ? [p]
+ : [],
+ )
+ if (!match) break
+ match.toolInvocation.args = value.args
+ match.toolInvocation.state = "call"
Bus.publish(Message.Event.PartUpdated, {
- part: next.parts[next.parts.length - 1],
+ part: match,
messageID: next.id,
sessionID: next.metadata.sessionID,
})
break
+ }
case "tool-call-streaming-start":
next.parts.push({
@@ -572,7 +573,7 @@ export namespace Session {
await updateMessage(next)
return step
},
- toolCallStreaming: false,
+ toolCallStreaming: true,
abortSignal: abort.signal,
stopWhen: stepCountIs(1000),
messages: convertToModelMessages(msgs),