@cubic-dev-ai/cli 0.0.0-feat-git-ai-integration-202602161235

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/cubic ADDED
@@ -0,0 +1,61 @@
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ if [ -n "$CUBIC_BIN_PATH" ]; then
5
+ resolved="$CUBIC_BIN_PATH"
6
+ else
7
+ # Get the real path of this script, resolving any symlinks
8
+ script_path="$0"
9
+ while [ -L "$script_path" ]; do
10
+ link_target="$(readlink "$script_path")"
11
+ case "$link_target" in
12
+ /*) script_path="$link_target" ;;
13
+ *) script_path="$(dirname "$script_path")/$link_target" ;;
14
+ esac
15
+ done
16
+ script_dir="$(dirname "$script_path")"
17
+ script_dir="$(cd "$script_dir" && pwd)"
18
+
19
+ # Map platform names
20
+ case "$(uname -s)" in
21
+ Darwin) platform="darwin" ;;
22
+ Linux) platform="linux" ;;
23
+ MINGW*|CYGWIN*|MSYS*) platform="win32" ;;
24
+ *) platform="$(uname -s | tr '[:upper:]' '[:lower:]')" ;;
25
+ esac
26
+
27
+ # Map architecture names
28
+ case "$(uname -m)" in
29
+ x86_64|amd64) arch="x64" ;;
30
+ aarch64) arch="arm64" ;;
31
+ armv7l) arch="arm" ;;
32
+ *) arch="$(uname -m)" ;;
33
+ esac
34
+
35
+ name="@cubic-dev-ai/cli-${platform}-${arch}"
36
+ binary="cubic"
37
+ [ "$platform" = "win32" ] && binary="cubic.exe"
38
+
39
+ # Search for the binary starting from real script location
40
+ resolved=""
41
+ current_dir="$script_dir"
42
+ while [ "$current_dir" != "/" ]; do
43
+ candidate="$current_dir/node_modules/$name/bin/$binary"
44
+ if [ -f "$candidate" ]; then
45
+ resolved="$candidate"
46
+ break
47
+ fi
48
+ current_dir="$(dirname "$current_dir")"
49
+ done
50
+
51
+ if [ -z "$resolved" ]; then
52
+ printf "It seems that your package manager failed to install the right version of the cubic CLI for your platform. You can try manually installing the \"%s\" package\n" "$name" >&2
53
+ exit 1
54
+ fi
55
+ fi
56
+
57
+ # Handle SIGINT gracefully
58
+ trap '' INT
59
+
60
+ # Execute the binary with all arguments
61
+ exec "$resolved" "$@"
package/bin/cubic.cmd ADDED
@@ -0,0 +1,58 @@
1
+ @echo off
2
+ setlocal enabledelayedexpansion
3
+
4
+ if defined CUBIC_BIN_PATH (
5
+ set "resolved=%CUBIC_BIN_PATH%"
6
+ goto :execute
7
+ )
8
+
9
+ rem Get the directory of this script
10
+ set "script_dir=%~dp0"
11
+ set "script_dir=%script_dir:~0,-1%"
12
+
13
+ rem Detect platform and architecture
14
+ set "platform=windows"
15
+
16
+ rem Detect architecture
17
+ if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
18
+ set "arch=x64"
19
+ ) else if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
20
+ set "arch=arm64"
21
+ ) else if "%PROCESSOR_ARCHITECTURE%"=="x86" (
22
+ set "arch=x86"
23
+ ) else (
24
+ set "arch=x64"
25
+ )
26
+
27
+ set "name=cubic-!platform!-!arch!"
28
+ set "binary=cubic.exe"
29
+
30
+ rem Search for the binary starting from script location
31
+ set "resolved="
32
+ set "current_dir=%script_dir%"
33
+
34
+ :search_loop
35
+ set "candidate=%current_dir%\node_modules\%name%\bin\%binary%"
36
+ if exist "%candidate%" (
37
+ set "resolved=%candidate%"
38
+ goto :execute
39
+ )
40
+
41
+ rem Move up one directory
42
+ for %%i in ("%current_dir%") do set "parent_dir=%%~dpi"
43
+ set "parent_dir=%parent_dir:~0,-1%"
44
+
45
+ rem Check if we've reached the root
46
+ if "%current_dir%"=="%parent_dir%" goto :not_found
47
+ set "current_dir=%parent_dir%"
48
+ goto :search_loop
49
+
50
+ :not_found
51
+ echo It seems that your package manager failed to install the right version of the cubic CLI for your platform. You can try manually installing the "%name%" package >&2
52
+ exit /b 1
53
+
54
+ :execute
55
+ rem Execute the binary with all arguments in the same console window
56
+ rem Use start /b /wait to ensure it runs in the current shell context for all shells
57
+ start /b /wait "" "%resolved%" %*
58
+ exit /b %ERRORLEVEL%
package/git-ai.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": "v1.1.2"
3
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@cubic-dev-ai/cli",
3
+ "bin": {
4
+ "cubic": "./bin/cubic"
5
+ },
6
+ "scripts": {
7
+ "preinstall": "bun ./preinstall.mjs || node ./preinstall.mjs",
8
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
9
+ },
10
+ "version": "0.0.0-feat-git-ai-integration-202602161235",
11
+ "optionalDependencies": {
12
+ "@cubic-dev-ai/cli-linux-arm64": "0.0.0-feat-git-ai-integration-202602161235",
13
+ "@cubic-dev-ai/cli-linux-x64": "0.0.0-feat-git-ai-integration-202602161235",
14
+ "@cubic-dev-ai/cli-linux-x64-baseline": "0.0.0-feat-git-ai-integration-202602161235",
15
+ "@cubic-dev-ai/cli-linux-arm64-musl": "0.0.0-feat-git-ai-integration-202602161235",
16
+ "@cubic-dev-ai/cli-linux-x64-musl": "0.0.0-feat-git-ai-integration-202602161235",
17
+ "@cubic-dev-ai/cli-linux-x64-baseline-musl": "0.0.0-feat-git-ai-integration-202602161235",
18
+ "@cubic-dev-ai/cli-darwin-arm64": "0.0.0-feat-git-ai-integration-202602161235",
19
+ "@cubic-dev-ai/cli-darwin-x64": "0.0.0-feat-git-ai-integration-202602161235",
20
+ "@cubic-dev-ai/cli-darwin-x64-baseline": "0.0.0-feat-git-ai-integration-202602161235",
21
+ "@cubic-dev-ai/cli-windows-x64": "0.0.0-feat-git-ai-integration-202602161235",
22
+ "@cubic-dev-ai/cli-windows-x64-baseline": "0.0.0-feat-git-ai-integration-202602161235"
23
+ }
24
+ }
@@ -0,0 +1,211 @@
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
+ import { execSync } from "child_process"
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
11
+ const require = createRequire(import.meta.url)
12
+
13
+ // Read git-ai version from JSON (single source of truth for JS/TS)
14
+ let GIT_AI_VERSION = "v1.1.2" // fallback
15
+ try {
16
+ // In published package, git-ai.json is a sibling file
17
+ // In development, it's at src/constants/git-ai.json relative to script/
18
+ const publishedPath = path.join(__dirname, "git-ai.json")
19
+ const devPath = path.join(__dirname, "..", "src", "constants", "git-ai.json")
20
+ const configPath = fs.existsSync(publishedPath) ? publishedPath : devPath
21
+ if (fs.existsSync(configPath)) {
22
+ const config = JSON.parse(fs.readFileSync(configPath, "utf-8"))
23
+ GIT_AI_VERSION = config.version
24
+ }
25
+ } catch {
26
+ // Use fallback
27
+ }
28
+
29
+ // Validate version format to prevent command injection (must be vX.Y.Z format)
30
+ function isValidVersion(version) {
31
+ return /^v\d+\.\d+\.\d+$/.test(version)
32
+ }
33
+
34
+ if (!isValidVersion(GIT_AI_VERSION)) {
35
+ console.warn(`Invalid git-ai version format: ${GIT_AI_VERSION}, using fallback`)
36
+ GIT_AI_VERSION = "v1.1.2"
37
+ }
38
+
39
+ function detectPlatformAndArch() {
40
+ // Map platform names
41
+ let platform
42
+ switch (os.platform()) {
43
+ case "darwin":
44
+ platform = "darwin"
45
+ break
46
+ case "linux":
47
+ platform = "linux"
48
+ break
49
+ case "win32":
50
+ platform = "windows"
51
+ break
52
+ default:
53
+ platform = os.platform()
54
+ break
55
+ }
56
+
57
+ // Map architecture names
58
+ let arch
59
+ switch (os.arch()) {
60
+ case "x64":
61
+ arch = "x64"
62
+ break
63
+ case "arm64":
64
+ arch = "arm64"
65
+ break
66
+ case "arm":
67
+ arch = "arm"
68
+ break
69
+ default:
70
+ arch = os.arch()
71
+ break
72
+ }
73
+
74
+ return { platform, arch }
75
+ }
76
+
77
+ function findBinary() {
78
+ const { platform, arch } = detectPlatformAndArch()
79
+ const packageName = `@cubic-dev-ai/cli-${platform}-${arch}`
80
+ const binary = platform === "windows" ? "cubic.exe" : "cubic"
81
+
82
+ try {
83
+ // Use require.resolve to find the package
84
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
85
+ const packageDir = path.dirname(packageJsonPath)
86
+ const binaryPath = path.join(packageDir, "bin", binary)
87
+
88
+ if (!fs.existsSync(binaryPath)) {
89
+ throw new Error(`Binary not found at ${binaryPath}`)
90
+ }
91
+
92
+ return binaryPath
93
+ } catch (error) {
94
+ throw new Error(`Could not find package ${packageName}: ${error.message}`)
95
+ }
96
+ }
97
+
98
+ async function regenerateWindowsCmdWrappers() {
99
+ console.log("Windows + npm detected: Forcing npm to rebuild bin links")
100
+
101
+ try {
102
+ const pkgPath = path.join(__dirname, "..")
103
+
104
+ // npm_config_global is string | undefined
105
+ // if it exists, the value is true
106
+ const isGlobal = process.env.npm_config_global === "true" || pkgPath.includes(path.join("npm", "node_modules"))
107
+
108
+ // The npm rebuild command does 2 things - Execute lifecycle scripts and rebuild bin links
109
+ // We want to skip lifecycle scripts to avoid infinite loops, so we use --ignore-scripts
110
+ const cmd = `npm rebuild cubic --ignore-scripts${isGlobal ? " -g" : ""}`
111
+ const opts = {
112
+ stdio: "inherit",
113
+ shell: true,
114
+ ...(isGlobal ? {} : { cwd: path.join(pkgPath, "..", "..") }), // For local, run from project root
115
+ }
116
+
117
+ console.log(`Running: ${cmd}`)
118
+ execSync(cmd, opts)
119
+ console.log("Successfully rebuilt npm bin links")
120
+ } catch (error) {
121
+ console.error("Error rebuilding npm links:", error.message)
122
+ console.error("npm rebuild failed. You may need to manually run: npm rebuild cubic --ignore-scripts")
123
+ }
124
+ }
125
+
126
+ // Install git-ai using official installer
127
+ // 2 minute timeout to prevent indefinite hangs during npm install
128
+ const GIT_AI_INSTALL_TIMEOUT = 120000
129
+
130
+ function setupGitAi() {
131
+ // Allow users to opt-out of automatic git-ai installation
132
+ if (process.env.CUBIC_DISABLE_GIT_AI === "true") {
133
+ console.log("Skipping git-ai installation (CUBIC_DISABLE_GIT_AI=true)")
134
+ console.log("You can install it later with: cubic stats enable")
135
+ return
136
+ }
137
+
138
+ console.log(`Installing git-ai ${GIT_AI_VERSION} for AI code tracking...`)
139
+
140
+ try {
141
+ if (os.platform() === "win32") {
142
+ // PowerShell installer for Windows
143
+ execSync(
144
+ `powershell -NoProfile -ExecutionPolicy Bypass -Command "$env:GIT_AI_RELEASE_TAG='${GIT_AI_VERSION}'; irm https://usegitai.com/install.ps1 | iex"`,
145
+ { stdio: "inherit", shell: true, timeout: GIT_AI_INSTALL_TIMEOUT },
146
+ )
147
+ } else {
148
+ // Bash installer for macOS/Linux
149
+ execSync(`export GIT_AI_RELEASE_TAG="${GIT_AI_VERSION}" && curl -sSL https://usegitai.com/install.sh | bash`, {
150
+ stdio: "inherit",
151
+ shell: "/bin/bash",
152
+ timeout: GIT_AI_INSTALL_TIMEOUT,
153
+ })
154
+ }
155
+
156
+ console.log("git-ai installed successfully")
157
+
158
+ // Configure git-ai to run in quiet mode (suppress chart output after commits)
159
+ const gitAiBinary = path.join(os.homedir(), ".git-ai", "bin", os.platform() === "win32" ? "git-ai.exe" : "git-ai")
160
+ try {
161
+ execSync(`"${gitAiBinary}" config set quiet true`, { stdio: "ignore", timeout: 5000 })
162
+ } catch {
163
+ // Ignore if config fails - git-ai will work without quiet mode
164
+ }
165
+ } catch (error) {
166
+ console.warn("git-ai installation failed, continuing without it:", error.message)
167
+ console.log("You can install it later with: cubic stats enable")
168
+ }
169
+ }
170
+
171
+ async function main() {
172
+ try {
173
+ if (os.platform() === "win32") {
174
+ // NPM eg format - npm/11.4.2 node/v24.4.1 win32 x64
175
+ // Bun eg format - bun/1.2.19 npm/? node/v24.3.0 win32 x64
176
+ if (process.env.npm_config_user_agent && process.env.npm_config_user_agent.startsWith("npm")) {
177
+ await regenerateWindowsCmdWrappers()
178
+ } else {
179
+ console.log("Windows detected but not npm, skipping binary symlink")
180
+ }
181
+ // Install git-ai on Windows too
182
+ setupGitAi()
183
+ return
184
+ }
185
+
186
+ const binaryPath = findBinary()
187
+ const binScript = path.join(__dirname, "bin", "cubic")
188
+
189
+ // Remove existing bin script if it exists
190
+ if (fs.existsSync(binScript)) {
191
+ fs.unlinkSync(binScript)
192
+ }
193
+
194
+ // Create symlink to the actual binary
195
+ fs.symlinkSync(binaryPath, binScript)
196
+ console.log(`cubic binary symlinked: ${binScript} -> ${binaryPath}`)
197
+
198
+ // Install git-ai
199
+ setupGitAi()
200
+ } catch (error) {
201
+ console.error("Failed to create cubic binary symlink:", error.message)
202
+ process.exit(1)
203
+ }
204
+ }
205
+
206
+ try {
207
+ main()
208
+ } catch (error) {
209
+ console.error("Postinstall script error:", error.message)
210
+ process.exit(0)
211
+ }
package/preinstall.mjs ADDED
@@ -0,0 +1,44 @@
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
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
+
10
+ function main() {
11
+ if (os.platform() !== "win32") {
12
+ console.log("Non-Windows platform detected, skipping preinstall")
13
+ return
14
+ }
15
+
16
+ console.log("Windows detected: Modifying package.json bin entry")
17
+
18
+ // Read package.json
19
+ const packageJsonPath = path.join(__dirname, "package.json")
20
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
21
+
22
+ // Modify bin to point to .cmd file on Windows
23
+ packageJson.bin = {
24
+ cubic: "./bin/cubic.cmd",
25
+ }
26
+
27
+ // Write it back
28
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
29
+ console.log("Updated package.json bin to use cubic.cmd")
30
+
31
+ // Now you can also remove the Unix script if you want
32
+ const unixScript = path.join(__dirname, "bin", "cubic")
33
+ if (fs.existsSync(unixScript)) {
34
+ console.log("Removing Unix shell script")
35
+ fs.unlinkSync(unixScript)
36
+ }
37
+ }
38
+
39
+ try {
40
+ main()
41
+ } catch (error) {
42
+ console.error("Preinstall script error:", error.message)
43
+ process.exit(0)
44
+ }