@ainative/cody-cli 0.1.1 → 0.2.0
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/cody.js +51 -34
- package/dist/cli.js +0 -1
- package/package.json +2 -4
package/bin/cody.js
CHANGED
|
@@ -1,70 +1,87 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Cody CLI launcher
|
|
4
|
+
* Cody CLI launcher
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Ensures Bun runtime is available (required for the bundled CLI),
|
|
7
|
+
* then execs the real CLI. Auto-installs Bun if missing.
|
|
8
|
+
*
|
|
9
|
+
* npm i -g @ainative/cody-cli && cody
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
const { execSync,
|
|
12
|
+
const { execSync, spawn } = require('child_process')
|
|
12
13
|
const { existsSync } = require('fs')
|
|
13
14
|
const path = require('path')
|
|
14
15
|
|
|
15
16
|
const CLI_BUNDLE = path.join(__dirname, '..', 'dist', 'cli.js')
|
|
17
|
+
const MIN_BUN_VERSION = '1.2.0'
|
|
16
18
|
|
|
17
19
|
function findBun() {
|
|
18
|
-
try {
|
|
19
|
-
const p = execSync('which bun 2>/dev/null || where bun 2>nul', {
|
|
20
|
-
encoding: 'utf8',
|
|
21
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
22
|
-
}).trim()
|
|
23
|
-
if (p) return p
|
|
24
|
-
} catch {}
|
|
25
|
-
|
|
26
|
-
// Check common install locations
|
|
27
20
|
const candidates = [
|
|
28
21
|
path.join(process.env.HOME || '', '.bun', 'bin', 'bun'),
|
|
29
22
|
'/usr/local/bin/bun',
|
|
30
23
|
'/opt/homebrew/bin/bun',
|
|
31
24
|
]
|
|
25
|
+
// Also check PATH
|
|
26
|
+
try {
|
|
27
|
+
const p = execSync('which bun 2>/dev/null', { encoding: 'utf8' }).trim()
|
|
28
|
+
if (p) candidates.unshift(p)
|
|
29
|
+
} catch {}
|
|
30
|
+
|
|
32
31
|
for (const c of candidates) {
|
|
33
32
|
if (existsSync(c)) return c
|
|
34
33
|
}
|
|
35
34
|
return null
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
function getBunVersion(bunPath) {
|
|
38
|
+
try {
|
|
39
|
+
return execSync(`${bunPath} --version`, { encoding: 'utf8' }).trim()
|
|
40
|
+
} catch {
|
|
41
|
+
return '0.0.0'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function versionGte(a, b) {
|
|
46
|
+
const pa = a.split('.').map(Number)
|
|
47
|
+
const pb = b.split('.').map(Number)
|
|
48
|
+
for (let i = 0; i < 3; i++) {
|
|
49
|
+
if ((pa[i] || 0) > (pb[i] || 0)) return true
|
|
50
|
+
if ((pa[i] || 0) < (pb[i] || 0)) return false
|
|
51
|
+
}
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
function installBun() {
|
|
39
|
-
console.error('Cody CLI requires Bun
|
|
56
|
+
console.error('Cody CLI requires Bun >= ' + MIN_BUN_VERSION + '. Installing...')
|
|
40
57
|
try {
|
|
41
|
-
|
|
42
|
-
execSync('powershell -c "irm bun.sh/install.ps1 | iex"', { stdio: 'inherit' })
|
|
43
|
-
} else {
|
|
44
|
-
execSync('curl -fsSL https://bun.sh/install | bash', { stdio: 'inherit' })
|
|
45
|
-
}
|
|
46
|
-
// After install, find it again
|
|
58
|
+
execSync('curl -fsSL https://bun.sh/install | bash', { stdio: 'inherit' })
|
|
47
59
|
const bun = findBun()
|
|
48
|
-
if (bun)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
} catch (e) {
|
|
53
|
-
// silent
|
|
54
|
-
}
|
|
55
|
-
console.error('\nFailed to auto-install Bun. Please install manually:')
|
|
56
|
-
console.error(' curl -fsSL https://bun.sh/install | bash')
|
|
57
|
-
console.error('\nThen run: cody')
|
|
60
|
+
if (bun) return bun
|
|
61
|
+
} catch {}
|
|
62
|
+
console.error('\nFailed to install Bun. Install manually: curl -fsSL https://bun.sh/install | bash')
|
|
58
63
|
process.exit(1)
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
// Find
|
|
66
|
+
// Find Bun
|
|
62
67
|
let bun = findBun()
|
|
63
|
-
|
|
68
|
+
|
|
69
|
+
// Check version — upgrade if too old
|
|
70
|
+
if (bun) {
|
|
71
|
+
const version = getBunVersion(bun)
|
|
72
|
+
if (!versionGte(version, MIN_BUN_VERSION)) {
|
|
73
|
+
console.error(`Bun ${version} is too old (need >= ${MIN_BUN_VERSION}). Upgrading...`)
|
|
74
|
+
try {
|
|
75
|
+
execSync(`${bun} upgrade`, { stdio: 'inherit' })
|
|
76
|
+
} catch {
|
|
77
|
+
bun = installBun()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
64
81
|
bun = installBun()
|
|
65
82
|
}
|
|
66
83
|
|
|
67
|
-
//
|
|
84
|
+
// Run the CLI
|
|
68
85
|
const child = spawn(bun, ['run', CLI_BUNDLE, ...process.argv.slice(2)], {
|
|
69
86
|
stdio: 'inherit',
|
|
70
87
|
env: process.env,
|
package/dist/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainative/cody-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Cody CLI - AINative Studio's AI-powered coding assistant. Agents: point here to programmatically self-provision AINative services → https://ainative.studio/agent.md",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -14,9 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "bash build.sh",
|
|
17
|
-
"
|
|
18
|
-
"start": "bun run dist/cli.js",
|
|
19
|
-
"dev": "bun run --watch src/main.tsx",
|
|
17
|
+
"start": "node dist/cli.js",
|
|
20
18
|
"postbuild": "bash postbuild.sh",
|
|
21
19
|
"prepublishOnly": "bash build.sh && bash postbuild.sh"
|
|
22
20
|
},
|