@reddb-io/redcode 0.12.0 → 0.13.1

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.
package/NOTICE CHANGED
@@ -30,7 +30,7 @@ copyright notice is preserved verbatim in LICENSE:
30
30
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
31
  SOFTWARE.
32
32
 
33
- Redcode keeps OpenCode's internal package names (@opencode-ai/*), environment
33
+ Redcode keeps OpenCode's internal package names (@reddb-io/redcode-*), environment
34
34
  variable prefixes (OPENCODE_*), and module layout deliberately, so that changes
35
35
  made here stay readable against upstream.
36
36
 
package/README.md CHANGED
@@ -10,7 +10,8 @@ npm install -g @reddb-io/redcode
10
10
  redcode
11
11
  ```
12
12
 
13
- One native binary for Linux (glibc and musl), macOS, and Windows on x64 and arm64.
13
+ One native package for Linux (glibc and musl), macOS, and Windows on x64 and arm64. It includes the
14
+ `redcode-rpc-sidecar` companion for framed JSON/TOON RPC integrations.
14
15
 
15
16
  ## Use
16
17
 
package/bin/redcode CHANGED
@@ -43,10 +43,12 @@ function run(target) {
43
43
  })
44
44
  }
45
45
 
46
- const envPath = process.env.REDCODE_BIN_PATH || process.env.OPENCODE_BIN_PATH
47
-
48
46
  const scriptPath = fs.realpathSync(__filename)
49
47
  const scriptDir = path.dirname(scriptPath)
48
+ const sidecar = path.basename(scriptPath).startsWith("redcode-rpc-sidecar")
49
+ const envPath = sidecar
50
+ ? process.env.REDCODE_RPC_SIDECAR_PATH
51
+ : process.env.REDCODE_BIN_PATH || process.env.OPENCODE_BIN_PATH
50
52
 
51
53
  //
52
54
  const cached = path.join(scriptDir, ".redcode")
@@ -71,7 +73,13 @@ if (!arch) {
71
73
  arch = os.arch()
72
74
  }
73
75
  const base = "@reddb-io/redcode-" + platform + "-" + arch
74
- const binary = platform === "windows" ? "redcode.exe" : "redcode"
76
+ const binary = sidecar
77
+ ? platform === "windows"
78
+ ? "redcode-rpc-sidecar.exe"
79
+ : "redcode-rpc-sidecar"
80
+ : platform === "windows"
81
+ ? "redcode.exe"
82
+ : "redcode"
75
83
 
76
84
  function supportsAvx2() {
77
85
  if (arch !== "x64") return false
@@ -186,10 +194,10 @@ function findBinary(startDir) {
186
194
  }
187
195
  }
188
196
 
189
- const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
197
+ const resolved = envPath || (!sidecar && fs.existsSync(cached) ? cached : findBinary(scriptDir))
190
198
  if (!resolved) {
191
199
  console.error(
192
- "It seems that your package manager failed to install the right version of the Redcode CLI for your platform. You can try manually installing " +
200
+ `It seems that your package manager failed to install the right version of ${sidecar ? "the Redcode RPC sidecar" : "the Redcode CLI"} for your platform. You can try manually installing ` +
193
201
  names.map((n) => `\"${n}\"`).join(" or ") +
194
202
  " package",
195
203
  )
@@ -0,0 +1,207 @@
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
+ const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"]
9
+
10
+ function run(target) {
11
+ const child = childProcess.spawn(target, process.argv.slice(2), {
12
+ stdio: "inherit",
13
+ })
14
+
15
+ child.on("error", (error) => {
16
+ console.error(error.message)
17
+ process.exit(1)
18
+ })
19
+
20
+ const forwarders = {}
21
+ for (const signal of forwardedSignals) {
22
+ forwarders[signal] = () => {
23
+ try {
24
+ child.kill(signal)
25
+ } catch {
26
+ // The child may have already exited.
27
+ }
28
+ }
29
+ process.on(signal, forwarders[signal])
30
+ }
31
+
32
+ child.on("exit", (code, signal) => {
33
+ for (const forwardedSignal of forwardedSignals) {
34
+ process.removeListener(forwardedSignal, forwarders[forwardedSignal])
35
+ }
36
+
37
+ if (signal) {
38
+ process.kill(process.pid, signal)
39
+ return
40
+ }
41
+
42
+ process.exit(typeof code === "number" ? code : 0)
43
+ })
44
+ }
45
+
46
+ const scriptPath = fs.realpathSync(__filename)
47
+ const scriptDir = path.dirname(scriptPath)
48
+ const sidecar = path.basename(scriptPath).startsWith("redcode-rpc-sidecar")
49
+ const envPath = sidecar
50
+ ? process.env.REDCODE_RPC_SIDECAR_PATH
51
+ : process.env.REDCODE_BIN_PATH || process.env.OPENCODE_BIN_PATH
52
+
53
+ //
54
+ const cached = path.join(scriptDir, ".redcode")
55
+
56
+ const platformMap = {
57
+ darwin: "darwin",
58
+ linux: "linux",
59
+ win32: "windows",
60
+ }
61
+ const archMap = {
62
+ x64: "x64",
63
+ arm64: "arm64",
64
+ arm: "arm",
65
+ }
66
+
67
+ let platform = platformMap[os.platform()]
68
+ if (!platform) {
69
+ platform = os.platform()
70
+ }
71
+ let arch = archMap[os.arch()]
72
+ if (!arch) {
73
+ arch = os.arch()
74
+ }
75
+ const base = "@reddb-io/redcode-" + platform + "-" + arch
76
+ const binary = sidecar
77
+ ? platform === "windows"
78
+ ? "redcode-rpc-sidecar.exe"
79
+ : "redcode-rpc-sidecar"
80
+ : platform === "windows"
81
+ ? "redcode.exe"
82
+ : "redcode"
83
+
84
+ function supportsAvx2() {
85
+ if (arch !== "x64") return false
86
+
87
+ if (platform === "linux") {
88
+ try {
89
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
90
+ } catch {
91
+ return false
92
+ }
93
+ }
94
+
95
+ if (platform === "darwin") {
96
+ try {
97
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
98
+ encoding: "utf8",
99
+ timeout: 1500,
100
+ })
101
+ if (result.status !== 0) return false
102
+ return (result.stdout || "").trim() === "1"
103
+ } catch {
104
+ return false
105
+ }
106
+ }
107
+
108
+ if (platform === "windows") {
109
+ const cmd =
110
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
111
+
112
+ for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
113
+ try {
114
+ const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
115
+ encoding: "utf8",
116
+ timeout: 3000,
117
+ windowsHide: true,
118
+ })
119
+ if (result.status !== 0) continue
120
+ const out = (result.stdout || "").trim().toLowerCase()
121
+ if (out === "true" || out === "1") return true
122
+ if (out === "false" || out === "0") return false
123
+ } catch {
124
+ continue
125
+ }
126
+ }
127
+
128
+ return false
129
+ }
130
+
131
+ return false
132
+ }
133
+
134
+ const names = (() => {
135
+ const avx2 = supportsAvx2()
136
+ const baseline = arch === "x64" && !avx2
137
+
138
+ if (platform === "linux") {
139
+ const musl = (() => {
140
+ try {
141
+ if (fs.existsSync("/etc/alpine-release")) return true
142
+ } catch {
143
+ // ignore
144
+ }
145
+
146
+ try {
147
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
148
+ const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
149
+ if (text.includes("musl")) return true
150
+ } catch {
151
+ // ignore
152
+ }
153
+
154
+ return false
155
+ })()
156
+
157
+ if (musl) {
158
+ if (arch === "x64") {
159
+ if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
160
+ return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
161
+ }
162
+ return [`${base}-musl`, base]
163
+ }
164
+
165
+ if (arch === "x64") {
166
+ if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
167
+ return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
168
+ }
169
+ return [base, `${base}-musl`]
170
+ }
171
+
172
+ if (arch === "x64") {
173
+ if (baseline) return [`${base}-baseline`, base]
174
+ return [base, `${base}-baseline`]
175
+ }
176
+ return [base]
177
+ })()
178
+
179
+ function findBinary(startDir) {
180
+ let current = startDir
181
+ for (;;) {
182
+ const modules = path.join(current, "node_modules")
183
+ if (fs.existsSync(modules)) {
184
+ for (const name of names) {
185
+ const candidate = path.join(modules, name, "bin", binary)
186
+ if (fs.existsSync(candidate)) return candidate
187
+ }
188
+ }
189
+ const parent = path.dirname(current)
190
+ if (parent === current) {
191
+ return
192
+ }
193
+ current = parent
194
+ }
195
+ }
196
+
197
+ const resolved = envPath || (!sidecar && fs.existsSync(cached) ? cached : findBinary(scriptDir))
198
+ if (!resolved) {
199
+ console.error(
200
+ `It seems that your package manager failed to install the right version of ${sidecar ? "the Redcode RPC sidecar" : "the Redcode CLI"} for your platform. You can try manually installing ` +
201
+ names.map((n) => `\"${n}\"`).join(" or ") +
202
+ " package",
203
+ )
204
+ process.exit(1)
205
+ }
206
+
207
+ run(resolved)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reddb-io/redcode",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
4
4
  "description": "RedDB's AI coding agent for the terminal",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,7 +8,8 @@
8
8
  "url": "https://github.com/reddb-io/redcode"
9
9
  },
10
10
  "bin": {
11
- "redcode": "./bin/redcode"
11
+ "redcode": "./bin/redcode",
12
+ "redcode-rpc-sidecar": "./bin/redcode-rpc-sidecar"
12
13
  },
13
14
  "os": [
14
15
  "darwin",
@@ -20,17 +21,17 @@
20
21
  "x64"
21
22
  ],
22
23
  "optionalDependencies": {
23
- "@reddb-io/redcode-darwin-arm64": "0.12.0",
24
- "@reddb-io/redcode-darwin-x64": "0.12.0",
25
- "@reddb-io/redcode-darwin-x64-baseline": "0.12.0",
26
- "@reddb-io/redcode-linux-arm64": "0.12.0",
27
- "@reddb-io/redcode-linux-arm64-musl": "0.12.0",
28
- "@reddb-io/redcode-linux-x64": "0.12.0",
29
- "@reddb-io/redcode-linux-x64-baseline": "0.12.0",
30
- "@reddb-io/redcode-linux-x64-baseline-musl": "0.12.0",
31
- "@reddb-io/redcode-linux-x64-musl": "0.12.0",
32
- "@reddb-io/redcode-windows-arm64": "0.12.0",
33
- "@reddb-io/redcode-windows-x64": "0.12.0",
34
- "@reddb-io/redcode-windows-x64-baseline": "0.12.0"
24
+ "@reddb-io/redcode-darwin-arm64": "0.13.1",
25
+ "@reddb-io/redcode-darwin-x64": "0.13.1",
26
+ "@reddb-io/redcode-darwin-x64-baseline": "0.13.1",
27
+ "@reddb-io/redcode-linux-arm64": "0.13.1",
28
+ "@reddb-io/redcode-linux-arm64-musl": "0.13.1",
29
+ "@reddb-io/redcode-linux-x64": "0.13.1",
30
+ "@reddb-io/redcode-linux-x64-baseline": "0.13.1",
31
+ "@reddb-io/redcode-linux-x64-baseline-musl": "0.13.1",
32
+ "@reddb-io/redcode-linux-x64-musl": "0.13.1",
33
+ "@reddb-io/redcode-windows-arm64": "0.13.1",
34
+ "@reddb-io/redcode-windows-x64": "0.13.1",
35
+ "@reddb-io/redcode-windows-x64-baseline": "0.13.1"
35
36
  }
36
37
  }