@ainative/cody-cli 0.1.1 → 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 (3) hide show
  1. package/bin/cody.js +51 -34
  2. package/dist/cli.js +22 -2
  3. 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 — Node.js shim
4
+ * Cody CLI launcher
5
5
  *
6
- * This shim ensures `npm install -g @ainative/cody-cli && cody` works
7
- * without requiring the user to install Bun first. It checks for Bun,
8
- * auto-installs it if missing, then exec's the real CLI bundle.
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, execFileSync, spawn } = require('child_process')
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 runtime. Installing...')
56
+ console.error('Cody CLI requires Bun >= ' + MIN_BUN_VERSION + '. Installing...')
40
57
  try {
41
- if (process.platform === 'win32') {
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
- console.error('Bun installed successfully.\n')
50
- return bun
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 or install Bun
66
+ // Find Bun
62
67
  let bun = findBun()
63
- if (!bun) {
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
- // Exec the real CLI
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
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env bun
2
1
  // @bun
3
2
  var __create = Object.create;
4
3
  var __getProtoOf = Object.getPrototypeOf;
@@ -157401,7 +157400,28 @@ var require_react = __commonJS((exports, module) => {
157401
157400
 
157402
157401
  // node_modules/react/cjs/react-compiler-runtime.development.js
157403
157402
  var require_react_compiler_runtime_development = __commonJS((exports) => {
157404
- var react = __toESM(require_react());
157403
+
157404
+ // Polyfill useEffectEvent for Bun runtime compatibility (React Compiler API)
157405
+ (function() {
157406
+ var _origRequireReact = require_react;
157407
+ require_react = function() {
157408
+ var mod = _origRequireReact.apply(this, arguments);
157409
+ if (mod && mod.exports && !mod.exports.useEffectEvent) {
157410
+ var React = mod.exports;
157411
+ React.useEffectEvent = function useEffectEvent(fn) {
157412
+ var ref = React.useRef(fn);
157413
+ ref.current = fn;
157414
+ return React.useCallback(function() {
157415
+ return ref.current.apply(this, arguments);
157416
+ }, []);
157417
+ };
157418
+ }
157419
+ return mod;
157420
+ };
157421
+ // Copy __commonJS metadata
157422
+ if (_origRequireReact.__esModule) require_react.__esModule = true;
157423
+ })();
157424
+ var react = __toESM(require_react());
157405
157425
  (function() {
157406
157426
  var ReactSharedInternals = react.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
157407
157427
  exports.c = function(size) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainative/cody-cli",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
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
- "build:compile": "bun build src/main.tsx --compile --outfile cody --define 'MACRO.VERSION=\"0.1.0\"' --define 'MACRO.FINGERPRINT=\"ainative\"' --define 'process.env.USER_TYPE=\"external\"'",
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
  },