@ainative/cody-cli 0.7.2 → 0.7.4
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.cjs +94 -0
- package/bin/postinstall.cjs +81 -0
- package/dist/cli.js +45722 -42504
- package/package.json +7 -3
package/bin/cody.cjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cody CLI launcher
|
|
5
|
+
*
|
|
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
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { execSync, spawn } = require('child_process')
|
|
13
|
+
const { existsSync } = require('fs')
|
|
14
|
+
const path = require('path')
|
|
15
|
+
|
|
16
|
+
const CLI_BUNDLE = path.join(__dirname, '..', 'dist', 'cli.js')
|
|
17
|
+
const MIN_BUN_VERSION = '1.2.0'
|
|
18
|
+
|
|
19
|
+
function findBun() {
|
|
20
|
+
const candidates = [
|
|
21
|
+
path.join(process.env.HOME || '', '.bun', 'bin', 'bun'),
|
|
22
|
+
'/usr/local/bin/bun',
|
|
23
|
+
'/opt/homebrew/bin/bun',
|
|
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
|
+
|
|
31
|
+
for (const c of candidates) {
|
|
32
|
+
if (existsSync(c)) return c
|
|
33
|
+
}
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
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
|
+
|
|
55
|
+
function installBun() {
|
|
56
|
+
console.error('Cody CLI requires Bun >= ' + MIN_BUN_VERSION + '. Installing...')
|
|
57
|
+
try {
|
|
58
|
+
execSync('curl -fsSL https://bun.sh/install | bash', { stdio: 'inherit' })
|
|
59
|
+
const bun = findBun()
|
|
60
|
+
if (bun) return bun
|
|
61
|
+
} catch {}
|
|
62
|
+
console.error('\nFailed to install Bun. Install manually: curl -fsSL https://bun.sh/install | bash')
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Find Bun
|
|
67
|
+
let bun = findBun()
|
|
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 {
|
|
81
|
+
bun = installBun()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Run the CLI
|
|
85
|
+
const child = spawn(bun, ['run', CLI_BUNDLE, ...process.argv.slice(2)], {
|
|
86
|
+
stdio: 'inherit',
|
|
87
|
+
env: process.env,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
child.on('exit', (code) => process.exit(code ?? 0))
|
|
91
|
+
child.on('error', (err) => {
|
|
92
|
+
console.error(`Failed to start Cody CLI: ${err.message}`)
|
|
93
|
+
process.exit(1)
|
|
94
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cody CLI postinstall cleanup
|
|
5
|
+
*
|
|
6
|
+
* Removes stale cached data from older builds that may cause:
|
|
7
|
+
* - Wrong OAuth URLs (pointing to upstream instead of ainative.studio)
|
|
8
|
+
* - Stale theme/settings that reference old branding
|
|
9
|
+
* - Cached tokens with wrong scopes
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require('fs')
|
|
13
|
+
const path = require('path')
|
|
14
|
+
const os = require('os')
|
|
15
|
+
|
|
16
|
+
const HOME = os.homedir()
|
|
17
|
+
const STALE_MARKERS = ['anthropic.com/api', 'claude.ai/api', 'console.anthropic.com']
|
|
18
|
+
|
|
19
|
+
function cleanDir(dirPath, description) {
|
|
20
|
+
if (!fs.existsSync(dirPath)) return
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
// Check for stale OAuth tokens with wrong URLs
|
|
24
|
+
const credFiles = ['credentials.json', 'oauth.json', 'tokens.json', '.credentials']
|
|
25
|
+
for (const f of credFiles) {
|
|
26
|
+
const fp = path.join(dirPath, f)
|
|
27
|
+
if (fs.existsSync(fp)) {
|
|
28
|
+
try {
|
|
29
|
+
const content = fs.readFileSync(fp, 'utf8')
|
|
30
|
+
if (STALE_MARKERS.some(m => content.includes(m))) {
|
|
31
|
+
fs.unlinkSync(fp)
|
|
32
|
+
console.log(` Cleaned stale credentials: ${f}`)
|
|
33
|
+
}
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Clean stale settings that reference old branding
|
|
39
|
+
const settingsFile = path.join(dirPath, 'settings.json')
|
|
40
|
+
if (fs.existsSync(settingsFile)) {
|
|
41
|
+
try {
|
|
42
|
+
const content = fs.readFileSync(settingsFile, 'utf8')
|
|
43
|
+
if (STALE_MARKERS.some(m => content.includes(m))) {
|
|
44
|
+
fs.unlinkSync(settingsFile)
|
|
45
|
+
console.log(` Cleaned stale settings`)
|
|
46
|
+
}
|
|
47
|
+
} catch {}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Clean old cached responses
|
|
51
|
+
const cacheDir = path.join(dirPath, 'cache')
|
|
52
|
+
if (fs.existsSync(cacheDir)) {
|
|
53
|
+
try {
|
|
54
|
+
fs.rmSync(cacheDir, { recursive: true, force: true })
|
|
55
|
+
console.log(` Cleared cache`)
|
|
56
|
+
} catch {}
|
|
57
|
+
}
|
|
58
|
+
} catch {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Only run cleanup, never fail the install
|
|
62
|
+
try {
|
|
63
|
+
const configDirs = [
|
|
64
|
+
path.join(HOME, '.cody'),
|
|
65
|
+
path.join(HOME, '.config', 'cody-cli'),
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
let cleaned = false
|
|
69
|
+
for (const dir of configDirs) {
|
|
70
|
+
if (fs.existsSync(dir)) {
|
|
71
|
+
cleanDir(dir, dir)
|
|
72
|
+
cleaned = true
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (cleaned) {
|
|
77
|
+
console.log('Cody CLI: cleaned stale data from previous versions.')
|
|
78
|
+
}
|
|
79
|
+
} catch {
|
|
80
|
+
// Never fail install due to cleanup
|
|
81
|
+
}
|