grace-code-cli 1.2.11

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opencode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Grace Code CLI
2
+
3
+ AI-powered development tool for the terminal.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g grace-code-cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ After installation, run:
14
+
15
+ ```bash
16
+ grace
17
+ ```
18
+
19
+ ## Supported Platforms
20
+
21
+ - **macOS** (Apple Silicon & Intel)
22
+ - **Linux** (x64 & ARM64, glibc & musl)
23
+ - **Windows** (x64)
24
+
25
+ ## Requirements
26
+
27
+ - Node.js >= 18
package/bin/grace.cjs ADDED
@@ -0,0 +1,193 @@
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.GRACE_BIN_PATH
21
+ if (envPath) {
22
+ run(envPath)
23
+ }
24
+
25
+ // Development mode check
26
+ const rootDir = path.join(__dirname, "..", "..", "..")
27
+ if (fs.existsSync(path.join(rootDir, "package.json"))) {
28
+ const pkg = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"))
29
+ if (pkg.name === "@mana-ai/graceCode") {
30
+ // We are in the development repository
31
+ const result = childProcess.spawnSync("bun", ["run", "dev"], {
32
+ cwd: rootDir,
33
+ stdio: "inherit",
34
+ })
35
+ process.exit(result.status || 0)
36
+ }
37
+ }
38
+
39
+ const scriptPath = fs.realpathSync(__filename)
40
+ const scriptDir = path.dirname(scriptPath)
41
+
42
+ //
43
+ const cached = path.join(scriptDir, ".grace")
44
+ if (fs.existsSync(cached)) {
45
+ run(cached)
46
+ }
47
+
48
+ const platformMap = {
49
+ darwin: "darwin",
50
+ linux: "linux",
51
+ win32: "windows",
52
+ }
53
+ const archMap = {
54
+ x64: "x64",
55
+ arm64: "arm64",
56
+ arm: "arm",
57
+ }
58
+
59
+ let platform = platformMap[os.platform()]
60
+ if (!platform) {
61
+ platform = os.platform()
62
+ }
63
+ let arch = archMap[os.arch()]
64
+ if (!arch) {
65
+ arch = os.arch()
66
+ }
67
+ const base = "grace-code-" + platform + "-" + arch
68
+ const binary = platform === "windows" ? "grace.exe" : "grace"
69
+
70
+ function supportsAvx2() {
71
+ if (arch !== "x64") return false
72
+
73
+ if (platform === "linux") {
74
+ try {
75
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
76
+ } catch {
77
+ return false
78
+ }
79
+ }
80
+
81
+ if (platform === "darwin") {
82
+ try {
83
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
84
+ encoding: "utf8",
85
+ timeout: 1500,
86
+ })
87
+ if (result.status !== 0) return false
88
+ return (result.stdout || "").trim() === "1"
89
+ } catch {
90
+ return false
91
+ }
92
+ }
93
+
94
+ if (platform === "windows") {
95
+ const cmd =
96
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
97
+
98
+ for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
99
+ try {
100
+ const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
101
+ encoding: "utf8",
102
+ timeout: 3000,
103
+ windowsHide: true,
104
+ })
105
+ if (result.status !== 0) continue
106
+ const out = (result.stdout || "").trim().toLowerCase()
107
+ if (out === "true" || out === "1") return true
108
+ if (out === "false" || out === "0") return false
109
+ } catch {
110
+ continue
111
+ }
112
+ }
113
+
114
+ return false
115
+ }
116
+
117
+ return false
118
+ }
119
+
120
+ const names = (() => {
121
+ const avx2 = supportsAvx2()
122
+ const baseline = arch === "x64" && !avx2
123
+
124
+ if (platform === "linux") {
125
+ const musl = (() => {
126
+ try {
127
+ if (fs.existsSync("/etc/alpine-release")) return true
128
+ } catch {
129
+ // ignore
130
+ }
131
+
132
+ try {
133
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
134
+ const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
135
+ if (text.includes("musl")) return true
136
+ } catch {
137
+ // ignore
138
+ }
139
+
140
+ return false
141
+ })()
142
+
143
+ if (musl) {
144
+ if (arch === "x64") {
145
+ if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
146
+ return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
147
+ }
148
+ return [`${base}-musl`, base]
149
+ }
150
+
151
+ if (arch === "x64") {
152
+ if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
153
+ return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
154
+ }
155
+ return [base, `${base}-musl`]
156
+ }
157
+
158
+ if (arch === "x64") {
159
+ if (baseline) return [`${base}-baseline`, base]
160
+ return [base, `${base}-baseline`]
161
+ }
162
+ return [base]
163
+ })()
164
+
165
+ function findBinary(startDir) {
166
+ let current = startDir
167
+ for (;;) {
168
+ const modules = path.join(current, "node_modules")
169
+ if (fs.existsSync(modules)) {
170
+ for (const name of names) {
171
+ const candidate = path.join(modules, name, "bin", binary)
172
+ if (fs.existsSync(candidate)) return candidate
173
+ }
174
+ }
175
+ const parent = path.dirname(current)
176
+ if (parent === current) {
177
+ return
178
+ }
179
+ current = parent
180
+ }
181
+ }
182
+
183
+ const resolved = findBinary(scriptDir)
184
+ if (!resolved) {
185
+ console.error(
186
+ "It seems that your package manager failed to install the right version of the grace CLI for your platform. You can try manually installing " +
187
+ names.map((n) => `\"${n}\"`).join(" or ") +
188
+ " package",
189
+ )
190
+ process.exit(1)
191
+ }
192
+
193
+ run(resolved)
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "grace-code-cli",
3
+ "version": "1.2.11",
4
+ "description": "Grace Code - AI-powered development tool for the terminal. Works on macOS, Linux, and Windows.",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "grace": "./bin/grace.cjs",
8
+ "Grace": "./bin/grace.cjs"
9
+ },
10
+ "scripts": {
11
+ "postinstall": "node script/postinstall.mjs"
12
+ },
13
+ "keywords": [
14
+ "ai",
15
+ "cli",
16
+ "coding",
17
+ "terminal",
18
+ "grace",
19
+ "developer-tools",
20
+ "code-assistant"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/BalaBenna/Grace-Code-CLI"
25
+ },
26
+ "homepage": "https://github.com/BalaBenna/Grace-Code-CLI#readme",
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "os": [
31
+ "darwin",
32
+ "linux",
33
+ "win32"
34
+ ],
35
+ "optionalDependencies": {
36
+ "grace-code-darwin-arm64": "1.2.11",
37
+ "grace-code-darwin-x64": "1.2.11",
38
+ "grace-code-linux-arm64": "1.2.11",
39
+ "grace-code-linux-x64": "1.2.11",
40
+ "grace-code-linux-x64-baseline": "1.2.11",
41
+ "grace-code-linux-arm64-musl": "1.2.11",
42
+ "grace-code-linux-x64-musl": "1.2.11",
43
+ "grace-code-linux-x64-baseline-musl": "1.2.11",
44
+ "grace-code-windows-x64": "1.2.11",
45
+ "grace-code-windows-x64-baseline": "1.2.11"
46
+ }
47
+ }
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs"
4
+ import path from "path"
5
+ import os from "os"
6
+ import { fileURLToPath } from "url"
7
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const packageRoot = path.resolve(__dirname, "..")
11
+ const require = createRequire(import.meta.url)
12
+
13
+ function detectPlatformAndArch() {
14
+ // Map platform names
15
+ let platform
16
+ switch (os.platform()) {
17
+ case "darwin":
18
+ platform = "darwin"
19
+ break
20
+ case "linux":
21
+ platform = "linux"
22
+ break
23
+ case "win32":
24
+ platform = "windows"
25
+ break
26
+ default:
27
+ platform = os.platform()
28
+ break
29
+ }
30
+
31
+ // Map architecture names
32
+ let arch
33
+ switch (os.arch()) {
34
+ case "x64":
35
+ arch = "x64"
36
+ break
37
+ case "arm64":
38
+ arch = "arm64"
39
+ break
40
+ case "arm":
41
+ arch = "arm"
42
+ break
43
+ default:
44
+ arch = os.arch()
45
+ break
46
+ }
47
+
48
+ return { platform, arch }
49
+ }
50
+
51
+ function findBinary() {
52
+ const { platform, arch } = detectPlatformAndArch()
53
+ const packageName = `grace-code-${platform}-${arch}`
54
+ const binaryName = platform === "windows" ? "grace.exe" : "grace"
55
+
56
+ try {
57
+ // Use require.resolve to find the package
58
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
59
+ const packageDir = path.dirname(packageJsonPath)
60
+ const binaryPath = path.join(packageDir, "bin", binaryName)
61
+
62
+ if (!fs.existsSync(binaryPath)) {
63
+ throw new Error(`Binary not found at ${binaryPath}`)
64
+ }
65
+
66
+ return { binaryPath, binaryName }
67
+ } catch (error) {
68
+ throw new Error(`Could not find package ${packageName}: ${error.message}`)
69
+ }
70
+ }
71
+
72
+ function prepareBinDirectory(binaryName) {
73
+ const binDir = path.join(__dirname, "bin")
74
+ const targetPath = path.join(binDir, binaryName)
75
+
76
+ // Ensure bin directory exists
77
+ if (!fs.existsSync(binDir)) {
78
+ fs.mkdirSync(binDir, { recursive: true })
79
+ }
80
+
81
+ // Remove existing binary/symlink if it exists
82
+ if (fs.existsSync(targetPath)) {
83
+ fs.unlinkSync(targetPath)
84
+ }
85
+
86
+ return { binDir, targetPath }
87
+ }
88
+
89
+ function symlinkBinary(sourcePath, binaryName) {
90
+ const { targetPath } = prepareBinDirectory(binaryName)
91
+
92
+ fs.symlinkSync(sourcePath, targetPath)
93
+ console.log(`grace binary symlinked: ${targetPath} -> ${sourcePath}`)
94
+
95
+ // Verify the file exists after operation
96
+ if (!fs.existsSync(targetPath)) {
97
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
98
+ }
99
+ }
100
+
101
+ async function main() {
102
+ try {
103
+ if (os.platform() === "win32") {
104
+ // On Windows, the .exe is already included in the package and bin field points to it
105
+ // No postinstall setup needed
106
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
107
+ return
108
+ }
109
+
110
+ // On non-Windows platforms, just verify the binary package exists
111
+ // Don't replace the wrapper script - it handles binary execution
112
+ const { binaryPath } = findBinary()
113
+ const target = path.join(packageRoot, "bin", ".grace")
114
+ if (fs.existsSync(target)) fs.unlinkSync(target)
115
+ try {
116
+ fs.linkSync(binaryPath, target)
117
+ } catch {
118
+ fs.copyFileSync(binaryPath, target)
119
+ }
120
+ fs.chmodSync(target, 0o755)
121
+ } catch (error) {
122
+ console.error("Failed to setup grace binary:", error.message)
123
+ process.exit(1)
124
+ }
125
+ }
126
+
127
+ try {
128
+ main()
129
+ } catch (error) {
130
+ console.error("Postinstall script error:", error.message)
131
+ process.exit(0)
132
+ }