arcana-ai 0.1.4 → 0.2.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.
Files changed (2) hide show
  1. package/bin/arcana.js +134 -113
  2. package/package.json +1 -1
package/bin/arcana.js CHANGED
@@ -1,113 +1,134 @@
1
- #!/usr/bin/env node
2
- // arcana launcher downloads the binary from GitHub releases if needed, then runs it.
3
- // Entrypoint for: npx arcana-ai
4
- const { spawnSync, execSync } = require("child_process")
5
- const { existsSync, mkdirSync, chmodSync, writeFileSync, unlinkSync, renameSync } = require("fs")
6
- const path = require("path")
7
- const os = require("os")
8
-
9
- const REPO = "anomalyco/opencode"
10
- const VERSION = "v1.17.8" // TODO: fetch latest via GitHub API
11
-
12
- // Asset name = what GitHub release calls it. Binary name = what we rename it to.
13
- const PLATFORM_MAP = {
14
- "win32-x64": { asset: "opencode-windows-x64.zip", binary: "arcana.exe" },
15
- "win32-arm64": { asset: "opencode-windows-arm64.zip", binary: "arcana.exe" },
16
- "linux-x64": { asset: "opencode-linux-x64.tar.gz", binary: "arcana" },
17
- "linux-arm64": { asset: "opencode-linux-arm64.tar.gz", binary: "arcana" },
18
- "darwin-x64": { asset: "opencode-darwin-x64.zip", binary: "arcana" },
19
- "darwin-arm64": { asset: "opencode-darwin-arm64.zip", binary: "arcana" },
20
- }
21
-
22
- const platform = `${os.platform()}-${os.arch()}`
23
- const entry = PLATFORM_MAP[platform]
24
-
25
- if (!entry) {
26
- console.error(`arcana: unsupported platform ${platform}`)
27
- console.error(`arcana: try installing from source: https://github.com/Lento47/arcana`)
28
- process.exit(1)
29
- }
30
-
31
- const CACHE_DIR = process.env.ARCANA_CACHE || path.join(os.homedir(), ".arcana", "bin")
32
- const CACHED_BINARY = path.join(CACHE_DIR, entry.binary)
33
-
34
- async function downloadAndExtract() {
35
- const ext = entry.asset.endsWith(".tar.gz") ? ".tar.gz" : ".zip"
36
- const zipName = `arcana-${platform}${ext}`
37
-
38
- // Clean up any stale temp files from previous failed attempts
39
- try { unlinkSync(path.join(CACHE_DIR, zipName)) } catch {}
40
- try { unlinkSync(path.join(CACHE_DIR, entry.asset)) } catch {}
41
-
42
- const url = `https://github.com/${REPO}/releases/download/${VERSION}/${entry.asset}`
43
- console.error(`arcana: downloading ${zipName}...`)
44
-
45
- mkdirSync(CACHE_DIR, { recursive: true })
46
-
47
- const res = await fetch(url)
48
- if (!res.ok) {
49
- console.error(`arcana: download failed: ${res.status} ${res.statusText}`)
50
- process.exit(1)
51
- }
52
-
53
- const tmp = path.join(CACHE_DIR, zipName)
54
- const buf = Buffer.from(await res.arrayBuffer())
55
- writeFileSync(tmp, buf)
56
- console.error(`arcana: ${(buf.length / 1e6).toFixed(1)}MB, extracting...`)
57
-
58
- try {
59
- if (entry.asset.endsWith(".tar.gz")) {
60
- execSync(`tar xzf "${tmp}" -C "${CACHE_DIR}"`, { stdio: "pipe" })
61
- unlinkSync(tmp)
62
- } else if (entry.asset.endsWith(".zip")) {
63
- if (os.platform() === "win32") {
64
- // .NET ZipFile built into .NET, no PowerShell module needed
65
- const safeTmp = tmp.replace(/'/g, "''")
66
- const safeDir = CACHE_DIR.replace(/'/g, "''")
67
- execSync(
68
- `powershell -Command "[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null; [System.IO.Compression.ZipFile]::ExtractToDirectory('${safeTmp}', '${safeDir}')"`,
69
- { stdio: "pipe" },
70
- )
71
- } else {
72
- execSync(`unzip -o "${tmp}" -d "${CACHE_DIR}"`, { stdio: "pipe" })
73
- }
74
- unlinkSync(tmp)
75
- }
76
- } catch (e) {
77
- console.error(`arcana: extraction failed: ${e.message}`)
78
- process.exit(1)
79
- }
80
-
81
- // Rename extracted binary from opencode → arcana
82
- const extracted = path.join(CACHE_DIR, os.platform() === "win32" ? "opencode.exe" : "opencode")
83
- if (existsSync(extracted) && extracted !== CACHED_BINARY) {
84
- try { unlinkSync(CACHED_BINARY) } catch {}
85
- renameSync(extracted, CACHED_BINARY)
86
- }
87
-
88
- if (os.platform() !== "win32") {
89
- try { chmodSync(CACHED_BINARY, 0o755) } catch {}
90
- }
91
-
92
- console.error(`arcana: ready${CACHED_BINARY}`)
93
- }
94
-
95
- async function main() {
96
- if (!existsSync(CACHED_BINARY)) {
97
- await downloadAndExtract()
98
- }
99
-
100
- if (!existsSync(CACHED_BINARY)) {
101
- console.error(`arcana: binary not found: ${CACHED_BINARY}`)
102
- process.exit(1)
103
- }
104
-
105
- const args = process.argv.slice(2)
106
- const child = spawnSync(CACHED_BINARY, args, { stdio: "inherit" })
107
- process.exit(child.status ?? 0)
108
- }
109
-
110
- main().catch((err) => {
111
- console.error(`arcana: ${err.message}`)
112
- process.exit(1)
113
- })
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: MIT OR LicenseRef-arcana-Commercial
3
+ // Copyright (c) 2026 arcana contributors
4
+ // arcana launcher — downloads the binary from GitHub releases if needed, then runs it.
5
+ // Entrypoint for: npx arcana-ai
6
+ const { spawnSync, execSync } = require("child_process")
7
+ const { existsSync, mkdirSync, chmodSync, writeFileSync, unlinkSync } = require("fs")
8
+ const path = require("path")
9
+ const crypto = require("crypto")
10
+ const os = require("os")
11
+
12
+ const REPO = "Lento47/arcana"
13
+ const VERSION = "v0.1.2"
14
+
15
+ const PLATFORM_MAP = {
16
+ "win32-x64": { asset: "arcana-windows-x64.zip", binary: "arcana.exe" },
17
+ "win32-arm64": { asset: "arcana-windows-arm64.zip", binary: "arcana.exe" },
18
+ "linux-x64": { asset: "arcana-linux-x64.tar.gz", binary: "arcana" },
19
+ "linux-arm64": { asset: "arcana-linux-arm64.tar.gz", binary: "arcana" },
20
+ "darwin-x64": { asset: "arcana-darwin-x64.zip", binary: "arcana" },
21
+ "darwin-arm64": { asset: "arcana-darwin-arm64.zip", binary: "arcana" },
22
+ }
23
+
24
+ const platform = `${os.platform()}-${os.arch()}`
25
+ const entry = PLATFORM_MAP[platform]
26
+
27
+ if (!entry) {
28
+ console.error(`arcana: unsupported platform ${platform}`)
29
+ console.error(`arcana: try installing from source: https://github.com/Lento47/arcana`)
30
+ process.exit(1)
31
+ }
32
+
33
+ const CACHE_DIR = process.env.ARCANA_CACHE || path.join(os.homedir(), ".arcana", "bin")
34
+ const CACHED_BINARY = path.join(CACHE_DIR, entry.binary)
35
+
36
+ async function downloadAndExtract() {
37
+ const ext = entry.asset.endsWith(".tar.gz") ? ".tar.gz" : ".zip"
38
+ const zipName = `arcana-${platform}${ext}`
39
+
40
+ // Clean up any stale temp file from previous failed attempts
41
+ try { unlinkSync(path.join(CACHE_DIR, zipName)) } catch {}
42
+
43
+ const url = `https://github.com/${REPO}/releases/download/${VERSION}/${entry.asset}`
44
+ console.error(`arcana: downloading ${zipName}...`)
45
+
46
+ mkdirSync(CACHE_DIR, { recursive: true })
47
+
48
+ const res = await fetch(url)
49
+ if (!res.ok) {
50
+ console.error(`arcana: download failed: ${res.status} ${res.statusText}`)
51
+ process.exit(1)
52
+ }
53
+
54
+ const tmp = path.join(CACHE_DIR, zipName)
55
+ const buf = Buffer.from(await res.arrayBuffer())
56
+ writeFileSync(tmp, buf)
57
+ console.error(`arcana: ${(buf.length / 1e6).toFixed(1)}MB, verifying checksum...`)
58
+
59
+ // Verify binary checksum against GitHub release .sha256 artifact
60
+ const shaUrl = url + ".sha256"
61
+ try {
62
+ const shaRes = await fetch(shaUrl)
63
+ if (!shaRes.ok) {
64
+ console.error(`arcana: checksum file not found (${shaUrl}), skipping verification`)
65
+ } else {
66
+ const shaText = (await shaRes.text()).trim()
67
+ const expectedHash = shaText.split(/\s+/)[0]
68
+ const actualHash = crypto.createHash("sha256").update(buf).digest("hex")
69
+ if (expectedHash !== actualHash) {
70
+ console.error(`arcana: CHECKSUM MISMATCH for ${zipName}`)
71
+ console.error(` expected: ${expectedHash}`)
72
+ console.error(` actual: ${actualHash}`)
73
+ console.error(`arcana: binary may be corrupted or tampered — deleting`)
74
+ try { unlinkSync(tmp) } catch {}
75
+ process.exit(1)
76
+ }
77
+ console.error(`arcana: checksum OK (SHA256: ${actualHash.slice(0, 16)}...)`)
78
+ }
79
+ } catch (e) {
80
+ console.error(`arcana: checksum verification failed: ${e.message}`)
81
+ process.exit(1)
82
+ }
83
+
84
+ console.error(`arcana: extracting...`)
85
+
86
+ try {
87
+ if (entry.asset.endsWith(".tar.gz")) {
88
+ execSync(`tar xzf "${tmp}" -C "${CACHE_DIR}"`, { stdio: "pipe" })
89
+ unlinkSync(tmp)
90
+ } else if (entry.asset.endsWith(".zip")) {
91
+ if (os.platform() === "win32") {
92
+ // .NET ZipFilebuilt into .NET, no PowerShell module needed
93
+ const safeTmp = tmp.replace(/'/g, "''")
94
+ const safeDir = CACHE_DIR.replace(/'/g, "''")
95
+ execSync(
96
+ `powershell -Command "[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null; [System.IO.Compression.ZipFile]::ExtractToDirectory('${safeTmp}', '${safeDir}')"`,
97
+ { stdio: "pipe" },
98
+ )
99
+ } else {
100
+ execSync(`unzip -o "${tmp}" -d "${CACHE_DIR}"`, { stdio: "pipe" })
101
+ }
102
+ unlinkSync(tmp)
103
+ }
104
+ } catch (e) {
105
+ console.error(`arcana: extraction failed: ${e.message}`)
106
+ process.exit(1)
107
+ }
108
+
109
+ if (os.platform() !== "win32") {
110
+ try { chmodSync(CACHED_BINARY, 0o755) } catch {}
111
+ }
112
+
113
+ console.error(`arcana: ready — ${CACHED_BINARY}`)
114
+ }
115
+
116
+ async function main() {
117
+ if (!existsSync(CACHED_BINARY)) {
118
+ await downloadAndExtract()
119
+ }
120
+
121
+ if (!existsSync(CACHED_BINARY)) {
122
+ console.error(`arcana: binary not found: ${CACHED_BINARY}`)
123
+ process.exit(1)
124
+ }
125
+
126
+ const args = process.argv.slice(2)
127
+ const child = spawnSync(CACHED_BINARY, args, { stdio: "inherit" })
128
+ process.exit(child.status ?? 0)
129
+ }
130
+
131
+ main().catch((err) => {
132
+ console.error(`arcana: ${err.message}`)
133
+ process.exit(1)
134
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arcana-ai",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "Self-improving AI agent CLI — opencode TUI + skills. Installs the arcana binary.",
5
5
  "bin": {
6
6
  "arcana": "./bin/arcana.js"