@ex-machina/opencode 0.0.1 → 1.1.25-exmachina.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/opencode +66 -0
  2. package/package.json +13 -3
package/bin/opencode ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+
3
+ const childProcess = require("child_process")
4
+ const fs = require("fs")
5
+ const path = require("path")
6
+ const os = require("os")
7
+
8
+ function run(target) {
9
+ const result = childProcess.spawnSync(target, process.argv.slice(2), {
10
+ stdio: "inherit",
11
+ })
12
+ if (result.error) {
13
+ console.error(result.error.message)
14
+ process.exit(1)
15
+ }
16
+ const code = typeof result.status === "number" ? result.status : 0
17
+ process.exit(code)
18
+ }
19
+
20
+ const envPath = process.env.OPENCODE_BIN_PATH
21
+ if (envPath) {
22
+ run(envPath)
23
+ }
24
+
25
+ const scriptPath = fs.realpathSync(__filename)
26
+ const scriptDir = path.dirname(scriptPath)
27
+
28
+ const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" }
29
+ const archMap = { x64: "x64", arm64: "arm64", arm: "arm" }
30
+
31
+ let platform = platformMap[os.platform()] || os.platform()
32
+ let arch = archMap[os.arch()] || os.arch()
33
+ const base = "@ex-machina/opencode-" + platform + "-" + arch
34
+ const binary = platform === "windows" ? "opencode.exe" : "opencode"
35
+
36
+ function findBinary(startDir) {
37
+ let current = startDir
38
+ for (;;) {
39
+ const modules = path.join(current, "node_modules")
40
+ if (fs.existsSync(modules)) {
41
+ const scoped = path.join(modules, "@ex-machina")
42
+ if (fs.existsSync(scoped)) {
43
+ const entries = fs.readdirSync(scoped)
44
+ for (const entry of entries) {
45
+ if (!entry.startsWith("opencode-" + platform + "-" + arch)) continue
46
+ const candidate = path.join(scoped, entry, "bin", binary)
47
+ if (fs.existsSync(candidate)) return candidate
48
+ }
49
+ }
50
+ }
51
+ const parent = path.dirname(current)
52
+ if (parent === current) return
53
+ current = parent
54
+ }
55
+ }
56
+
57
+ const resolved = findBinary(scriptDir)
58
+ if (!resolved) {
59
+ console.error(
60
+ 'It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing the "' +
61
+ base + '" package'
62
+ )
63
+ process.exit(1)
64
+ }
65
+
66
+ run(resolved)
package/package.json CHANGED
@@ -1,5 +1,15 @@
1
1
  {
2
2
  "name": "@ex-machina/opencode",
3
- "version": "0.0.1",
4
- "description": "Patched opencode CLI"
5
- }
3
+ "version": "1.1.25-exmachina.5",
4
+ "description": "Patched opencode CLI with additional features",
5
+ "bin": {
6
+ "opencode": "bin/opencode"
7
+ },
8
+ "optionalDependencies": {
9
+ "@ex-machina/opencode-darwin-arm64": "1.1.25-exmachina.5"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/ex-machina-co/opencode"
14
+ }
15
+ }