@reddb-io/redcode 0.81.6 → 0.81.9

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/bin/redcode CHANGED
@@ -207,4 +207,8 @@ if (!resolved) {
207
207
  process.exit(1)
208
208
  }
209
209
 
210
- run(resolved)
210
+ if (process.platform === "win32" && process.env.REDCODE_INSTALL_WINDOWS_SHIMS === "1") {
211
+ require("../postinstall.cjs").install(resolved, sidecar ? "redcode-rpc-sidecar" : "redcode")
212
+ } else {
213
+ run(resolved)
214
+ }
@@ -207,4 +207,8 @@ if (!resolved) {
207
207
  process.exit(1)
208
208
  }
209
209
 
210
- run(resolved)
210
+ if (process.platform === "win32" && process.env.REDCODE_INSTALL_WINDOWS_SHIMS === "1") {
211
+ require("../postinstall.cjs").install(resolved, sidecar ? "redcode-rpc-sidecar" : "redcode")
212
+ } else {
213
+ run(resolved)
214
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reddb-io/redcode",
3
- "version": "0.81.6",
3
+ "version": "0.81.9",
4
4
  "description": "RedDB's AI coding agent for the terminal",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,6 +11,9 @@
11
11
  "redcode": "./bin/redcode",
12
12
  "redcode-rpc-sidecar": "./bin/redcode-rpc-sidecar"
13
13
  },
14
+ "scripts": {
15
+ "postinstall": "node postinstall.cjs"
16
+ },
14
17
  "os": [
15
18
  "darwin",
16
19
  "linux",
@@ -21,13 +24,13 @@
21
24
  "x64"
22
25
  ],
23
26
  "optionalDependencies": {
24
- "@reddb-io/redcode-darwin-arm64": "0.81.6",
25
- "@reddb-io/redcode-darwin-x64-baseline": "0.81.6",
26
- "@reddb-io/redcode-linux-arm64": "0.81.6",
27
- "@reddb-io/redcode-linux-arm64-musl": "0.81.6",
28
- "@reddb-io/redcode-linux-x64-baseline": "0.81.6",
29
- "@reddb-io/redcode-linux-x64-baseline-musl": "0.81.6",
30
- "@reddb-io/redcode-windows-arm64": "0.81.6",
31
- "@reddb-io/redcode-windows-x64-baseline": "0.81.6"
27
+ "@reddb-io/redcode-darwin-arm64": "0.81.9",
28
+ "@reddb-io/redcode-darwin-x64-baseline": "0.81.9",
29
+ "@reddb-io/redcode-linux-arm64": "0.81.9",
30
+ "@reddb-io/redcode-linux-arm64-musl": "0.81.9",
31
+ "@reddb-io/redcode-linux-x64-baseline": "0.81.9",
32
+ "@reddb-io/redcode-linux-x64-baseline-musl": "0.81.9",
33
+ "@reddb-io/redcode-windows-arm64": "0.81.9",
34
+ "@reddb-io/redcode-windows-x64-baseline": "0.81.9"
32
35
  }
33
36
  }
@@ -0,0 +1,40 @@
1
+ const fs = require("node:fs")
2
+ const path = require("node:path")
3
+ const childProcess = require("node:child_process")
4
+
5
+ // npm's default Windows shims keep node.exe alive as the native TUI's parent. Invoke
6
+ // the selected executable directly so restarting a Node service cannot kill that launcher.
7
+ function install(binary, command) {
8
+ for (const directory of [path.resolve(__dirname, "../../.."), path.resolve(__dirname, "../../.bin")]) {
9
+ const relative = path.relative(directory, binary)
10
+ const variable = command === "redcode" ? "REDCODE_BIN_PATH" : "REDCODE_RPC_SIDECAR_PATH"
11
+ const legacy = command === "redcode"
12
+ const owner = `@reddb-io/redcode/bin/${command}`
13
+ const files = {
14
+ ".cmd": `@ECHO off\r\nREM ${owner}\r\nSETLOCAL\r\nIF DEFINED ${variable} (\r\n "%${variable}%" %*\r\n)${legacy ? ' ELSE IF DEFINED OPENCODE_BIN_PATH (\r\n "%OPENCODE_BIN_PATH%" %*\r\n)' : ""} ELSE (\r\n "%~dp0${relative}" %*\r\n)\r\nEXIT /b %ERRORLEVEL%\r\n`,
15
+ ".ps1": `# ${owner}\n$target = Join-Path $PSScriptRoot '${relative.replaceAll("'", "''")}'\nif ($env:${variable}) { $target = $env:${variable} }${legacy ? " elseif ($env:OPENCODE_BIN_PATH) { $target = $env:OPENCODE_BIN_PATH }" : ""}\n& $target @args\nexit $LASTEXITCODE\n`,
16
+ "": `#!/bin/sh\n# ${owner}\nbasedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")\nif [ -n "$${variable}" ]; then\n exec "$${variable}" "$@"\nfi\n${legacy ? 'if [ -n "$OPENCODE_BIN_PATH" ]; then\n exec "$OPENCODE_BIN_PATH" "$@"\nfi\n' : ""}exec "$basedir/${relative.replaceAll("\\", "/").replaceAll('"', '\\"').replaceAll("$", "\\$").replaceAll("`", "\\`")}" "$@"\n`,
17
+ }
18
+ for (const [extension, content] of Object.entries(files)) {
19
+ const file = path.join(directory, command + extension)
20
+ if (!fs.existsSync(file) || !fs.lstatSync(file).isFile()) continue
21
+ // Only replace shims npm created for this package, never another install on PATH.
22
+ if (!fs.readFileSync(file, "utf8").replaceAll("\\", "/").includes(owner)) continue
23
+ fs.writeFileSync(file, content)
24
+ }
25
+ }
26
+ }
27
+
28
+ module.exports = { install }
29
+
30
+ if (require.main === module && process.platform === "win32") {
31
+ for (const command of ["redcode", "redcode-rpc-sidecar"]) {
32
+ const result = childProcess.spawnSync(process.execPath, [path.join(__dirname, "bin", command)], {
33
+ stdio: "inherit",
34
+ windowsHide: true,
35
+ env: { ...process.env, REDCODE_INSTALL_WINDOWS_SHIMS: "1" },
36
+ })
37
+ if (result.error) throw result.error
38
+ if (result.status !== 0) process.exit(result.status ?? 1)
39
+ }
40
+ }