@ainative/cody-cli 0.7.1 → 0.7.3

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.
@@ -1,49 +1,84 @@
1
1
  # Project Context
2
2
 
3
- <!-- Replace with your project name and description -->
4
- **Project**: My Project
5
- **Compatible With**: Gemini CLI, Claude Code, and other AI coding assistants
3
+ **Project**: Cody CLI AINative Studio's AI-powered coding assistant
4
+ **Compatible With**: Claude Code, Gemini CLI, and other AI coding assistants
6
5
 
7
6
  ---
8
7
 
9
8
  ## Project Overview
10
9
 
11
- <!-- Replace with your project description -->
12
- <!-- Example: This is a Next.js web application for... -->
10
+ Cody CLI is a fork/rebrand of Claude Code, building AINative Studio's terminal-based AI coding assistant. It connects to AINative's API gateway (Kong) which routes to multiple LLM providers. The CLI supports OAuth 2.1 + PKCE authentication, MCP (Model Context Protocol) servers, streaming chat completions, tool use, sub-agents, and a rich terminal UI built with Ink/React.
11
+
12
+ **Current Version**: 0.7.1
13
+ **Status**: Active Development — SDK works, chat completions API confirmed working
13
14
 
14
15
  ---
15
16
 
16
17
  ## Repository Paths
17
18
 
18
19
  ### Primary Repository
19
- <!-- Replace with your repository path -->
20
- **Path**: `/path/to/your/project`
21
- **Framework**: <!-- e.g., Next.js 16, FastAPI, etc. -->
20
+ **Path**: `/Users/aideveloper/Desktop/cody-cli`
21
+ **GitHub**: `https://github.com/AINative-Studio/cody-cli`
22
+ **Framework**: Bun + TypeScript + React (Ink terminal UI)
22
23
  **Status**: Active Development
23
24
 
24
25
  ---
25
26
 
26
27
  ## Tech Stack
27
28
 
28
- <!-- Replace with your actual tech stack -->
29
- - **Framework**: <!-- e.g., Next.js 16 (App Router, TypeScript) -->
30
- - **Styling**: <!-- e.g., Tailwind CSS + shadcn/ui -->
31
- - **State Management**: <!-- e.g., React Query -->
32
- - **Deployment**: <!-- e.g., Railway, Vercel, AWS -->
33
- - **Package Manager**: <!-- e.g., npm, bun, pnpm -->
29
+ - **Runtime**: Bun >= 1.1.0 (also supports Node >= 18 via thin wrapper)
30
+ - **Language**: TypeScript (ES2022, JSX, bundler module resolution)
31
+ - **UI Framework**: Ink 5.0 + React 19.1.0 (terminal UI)
32
+ - **CLI Framework**: Commander.js 12.0
33
+ - **AI SDK**: @anthropic-ai/sdk 0.82.0 (Beta Messages API)
34
+ - **MCP**: @modelcontextprotocol/sdk 1.29.0
35
+ - **Observability**: OpenTelemetry (traces, metrics, logs)
36
+ - **Build**: Bun bundler (TypeScript -> JS bundle -> optional native binary)
37
+ - **Testing**: bun:test (built-in test runner)
38
+ - **Deployment**: npm registry (@ainative/cody-cli), Homebrew tap
39
+ - **Package Manager**: Bun (bun.lock)
34
40
 
35
41
  ---
36
42
 
37
43
  ## Architecture
38
44
 
39
- <!-- Replace with your architecture description -->
45
+ ### System Flow
46
+ ```
47
+ Developer -> Cody CLI -> Kong API Gateway -> Backend LLMs
48
+ |
49
+ +-> MCP Servers (ZeroDB, Chrome, etc.)
50
+ +-> OAuth 2.1 + PKCE (api.ainative.studio)
51
+ +-> Local tools (Bash, FileRead, FileWrite, etc.)
52
+ ```
40
53
 
41
- ### Page/Module Structure
54
+ ### Two CLI Modes
55
+ 1. **Thin Wrapper** (`bin/cody.js`): Node.js launcher, auto-installs Bun
56
+ 2. **Full Binary** (`cody-bin`): ~80MB self-contained Bun-compiled binary
57
+
58
+ ### Source Directory Structure
42
59
  ```
43
- <!-- Replace with your directory structure -->
44
- app/
45
- layout.tsx
46
- page.tsx
60
+ src/
61
+ entrypoints/ # CLI bootstrap (cli.tsx, init.ts, mcp.ts, sdk/)
62
+ commands/ # 100+ slash commands
63
+ tools/ # LLM-callable tools (Bash, FileRead, FileWrite, Glob, Grep, Agent, MCP)
64
+ services/ # Business logic (oauth, mcp, api, analytics, compact, memory)
65
+ components/ # 140+ Ink/React UI components
66
+ hooks/ # 85+ React hooks
67
+ utils/ # 330+ utility modules
68
+ bridge/ # Remote control / bridge mode
69
+ skills/ # Loadable skill system
70
+ tasks/ # Task tracking subsystem
71
+ context/ # Context window management
72
+ state/ # Application state management
73
+ main.tsx # Main application loop & Ink render tree
74
+ commands.ts # Command registry & dispatch
75
+ ```
76
+
77
+ ### Build Pipeline
78
+ ```
79
+ TypeScript (src/) -> bun build -> dist/cli.js (JS bundle)
80
+ |
81
+ +-> bun build --compile -> cody-bin (native binary)
47
82
  ```
48
83
 
49
84
  ---
@@ -51,9 +86,19 @@ app/
51
86
  ## Services & APIs
52
87
 
53
88
  ### Backend API
54
- <!-- Replace with your API details -->
55
- **Base URL**: `https://your-api.example.com`
56
- **Auth**: <!-- e.g., JWT tokens, API keys -->
89
+ **Base URL**: `https://api.ainative.studio`
90
+ **Auth**: OAuth 2.1 + PKCE (Client ID: `ainative-cody-cli-001`)
91
+ **Scopes**: `user:profile`, `user:inference`, `user:sessions:claude_code`, `user:mcp_servers`, `user:file_upload`, `org:create_api_key`
92
+
93
+ ### MCP Servers
94
+ - **ZeroDB**: Vector database and storage (`https://api.ainative.studio/v1/mcp/zerodb-mcp/messages`)
95
+
96
+ ### Available Models
97
+ - `qwen-coder-32b` (default)
98
+ - `qwen-coder-7b`
99
+ - `nouscoder-14b`
100
+ - `gemma-9b`
101
+ - `deepseek-r1-distill-qwen-7b`
57
102
 
58
103
  ---
59
104
 
@@ -61,33 +106,34 @@ app/
61
106
 
62
107
  ### Local Development
63
108
  ```bash
64
- # Replace with your actual commands
65
- npm run dev # Start dev server
66
- npm run lint # Linting
67
- npm run type-check # Type checking
68
- npm run build # Build verification
69
- npm test # Run tests
109
+ bun install # Install dependencies
110
+ bun run build # Build JS bundle (dist/cli.js)
111
+ bun run start # Run built CLI
112
+ bash compile.sh # Build native binary (optional)
113
+ bun test # Run all tests
114
+ bun test --coverage # Run tests with coverage report
70
115
  ```
71
116
 
72
117
  ### Pre-Commit Checklist
73
- 1. Lint - must pass
74
- 2. Type-check - must pass
75
- 3. Build - must succeed
76
- 4. Tests - all tests pass
118
+ 1. Build must succeed (`bun run build`)
119
+ 2. Tests all tests pass with >= 80% coverage (`bun test --coverage`)
120
+ 3. No secrets, API keys, or tokens in code
121
+ 4. No AI tool attribution in commit messages
77
122
 
78
123
  ---
79
124
 
80
125
  ## Git Workflow
81
126
 
82
127
  ### Branch Strategy
83
- - `main` - production branch
128
+ - `main` production branch
84
129
  - Feature branches: `feature/[name]`
85
130
  - Bug fixes: `fix/[name]`
86
131
 
87
132
  ### Commit Rules (ZERO TOLERANCE)
88
133
  **NEVER include in commits, PRs, or GitHub activity:**
89
- - AI tool attribution of any kind
134
+ - AI tool attribution of any kind ("Claude", "Anthropic", "ChatGPT", "Copilot")
90
135
  - "Generated with", "Co-Authored-By" referencing AI tools
136
+ - "AI-generated" or "AI-assisted"
91
137
 
92
138
  See `.ainative/git-rules.md` for complete rules.
93
139
 
@@ -96,33 +142,45 @@ See `.ainative/git-rules.md` for complete rules.
96
142
  ## AI Agent Configuration
97
143
 
98
144
  ### Claude Code
99
- - Primary agent configuration: `.claude/CLAUDE.md`
100
- - Custom rules: `.claude/rules/`
145
+ - Primary agent configuration: `CLAUDE.md` (project root)
146
+ - Settings: `.claude/settings.json`
147
+ - Skills: `.claude/skills/`
148
+ - Hooks: `.claude/hooks/`
101
149
 
102
- ### Gemini CLI (This File)
150
+ ### Gemini CLI / Other AI Tools
103
151
  - Project context: `.ainative/AINATIVE.md` (this file)
104
152
  - Settings: `.ainative/settings.json`
105
- - Custom rules: `.ainative/rules/`
153
+ - Skills: `.ainative/skills/`
106
154
 
107
155
  ---
108
156
 
109
157
  ## MCP Servers (Model Context Protocol)
110
158
 
111
- <!-- Replace with your MCP server configuration -->
112
- See `.claude/mcp.json` for MCP configuration.
159
+ See `.mcp.json` for MCP configuration.
160
+ See `.claude/settings.local.json` for enabled MCP servers.
113
161
 
114
162
  ---
115
163
 
116
164
  ## Key Files Reference
117
165
 
118
166
  ### Configuration
119
- <!-- Replace with your key config files -->
120
- - `package.json` - Dependencies
121
- - `tsconfig.json` - TypeScript configuration
167
+ - `package.json` Dependencies, scripts, npm publishing config
168
+ - `tsconfig.json` TypeScript config (ES2022, bundler, JSX)
169
+ - `bunfig.toml` Bun test runner config (30s timeout)
170
+ - `.mcp.json` — MCP server URLs
171
+ - `globals.d.ts` — Build-time MACRO type declarations
172
+
173
+ ### Build
174
+ - `build.sh` — TypeScript -> JS bundle
175
+ - `compile.sh` — JS -> native binary
176
+ - `postbuild.sh` — Add shebang + chmod
177
+ - `install.sh` — End-user installer (curl | sh)
122
178
 
123
179
  ### Documentation
124
- - `.ainative/AINATIVE.md` - This file
125
- - `.claude/CLAUDE.md` - Claude Code context
180
+ - `docs/ARCHITECTURE.md` System design
181
+ - `docs/DEVELOPMENT.md` Setup & contribution guide
182
+ - `docs/TESTING.md` — Test strategy & running tests
183
+ - `docs/MODELS.md` — Available models & selection
126
184
 
127
185
  ---
128
186
 
@@ -130,15 +188,17 @@ See `.claude/mcp.json` for MCP configuration.
130
188
 
131
189
  ### Required
132
190
  ```bash
133
- # Replace with your required env vars
134
- # EXAMPLE:
135
- # NEXT_PUBLIC_SITE_URL=https://www.example.com
136
- # NEXT_PUBLIC_API_URL=https://api.example.com
191
+ ANTHROPIC_API_KEY=your-api-key
192
+ ANTHROPIC_BASE_URL=https://api.ainative.studio
137
193
  ```
138
194
 
139
195
  ### Optional
140
196
  ```bash
141
- # Replace with your optional env vars
197
+ ANTHROPIC_MODEL=qwen-coder-32b # Override default model
198
+ CODY_E2E_API_KEY=your-e2e-key # For live API tests
199
+ CODY_VERSION=0.7.1 # Build version override
200
+ CODY_INTERNAL=1 # Internal build flag
201
+ ANTHROPIC_SMALL_FAST_MODEL=qwen-coder-7b # Small model override
142
202
  ```
143
203
 
144
204
  ---
@@ -146,19 +206,50 @@ See `.claude/mcp.json` for MCP configuration.
146
206
  ## Testing
147
207
 
148
208
  ### Testing Philosophy
149
- - Test-driven development (TDD) preferred
150
- - BDD-style tests (Given/When/Then)
151
- - Minimum 80% coverage for new features
209
+ - **TDD/BDD preferred**: Write tests before implementation
210
+ - **BDD-style**: `describe/it` syntax with `bun:test`
211
+ - **Minimum 80% coverage** for new features
212
+ - **Tests MUST be executed** with proof of passing before any commit/PR
213
+
214
+ ### Test Structure
215
+ ```
216
+ tests/
217
+ setup.ts # Shared helpers, constants, spawn utilities
218
+ e2e/
219
+ cli-basics.test.ts # Version flags, help, CLI modes
220
+ branding.test.ts # ASCII logo, brand colors, product names
221
+ oauth-flow.test.ts # OAuth URLs, client IDs, scopes
222
+ api-integration.test.ts # Live API calls (requires CODY_E2E_API_KEY)
223
+ installer.test.ts # install.sh validation
224
+ build-artifacts.test.ts # dist/cli.js, cody-bin, package.json
225
+ mcp-connection.test.ts # MCP server connectivity
226
+ ```
227
+
228
+ ### Running Tests
229
+ ```bash
230
+ bun test # All tests
231
+ bun test tests/e2e/cli-basics.test.ts # Specific file
232
+ bun test --filter "version" # Pattern matching
233
+ bun test --coverage # With coverage report
234
+ CODY_E2E_API_KEY=sk-xxx bun test # With live API
235
+ ```
152
236
 
153
237
  ---
154
238
 
155
- ## Resources
239
+ ## Open Issues (17 active)
156
240
 
157
- ### Documentation
158
- <!-- Replace with relevant documentation links -->
241
+ ### Core Architecture
242
+ - #65 Build usage-tracked dual-provider model routing
243
+ - #64 — Claude models fail through Anthropic adapter (BUG)
244
+ - #66 — [EPIC] Full roadmap
245
+
246
+ ### Chrome Extension (#45)
247
+ - #51-#54 — Build Cody in Chrome MV3 extension
248
+
249
+ ### Mobile App (#47)
250
+ - #57-#63 — React Native + Expo scaffold, QR pairing, streaming, notifications
159
251
 
160
252
  ---
161
253
 
162
- <!-- Replace with your team/project info -->
163
- **Team**: Your Team Name
164
- **Repository**: your-repo-name
254
+ **Team**: AINative Studio
255
+ **Repository**: AINative-Studio/cody-cli
@@ -2,33 +2,36 @@
2
2
  "$schema": "https://google-gemini.github.io/gemini-cli/schemas/settings.schema.json",
3
3
  "version": "1.0.0",
4
4
  "project": {
5
- "name": "My Project",
6
- "type": "web-application",
7
- "framework": "your-framework",
8
- "language": "your-language"
5
+ "name": "Cody CLI",
6
+ "type": "cli-application",
7
+ "framework": "bun-typescript-ink",
8
+ "language": "typescript"
9
9
  },
10
10
  "paths": {
11
- "root": "__REPO_ROOT__",
11
+ "root": "/Users/aideveloper/Desktop/cody-cli",
12
12
  "include_directories": [
13
- "app",
14
- "components",
15
- "lib",
16
- "services",
17
- "public"
13
+ "src",
14
+ "tests",
15
+ "bin",
16
+ "docs",
17
+ "packages",
18
+ "homebrew"
18
19
  ],
19
20
  "exclude_patterns": [
20
21
  "node_modules",
21
- ".next",
22
22
  "dist",
23
- "build",
24
23
  "*.test.ts",
25
- "*.test.tsx"
24
+ "*.test.tsx",
25
+ "bun.lock",
26
+ "cody-bin"
26
27
  ]
27
28
  },
28
29
  "context": {
29
30
  "primary_context_file": ".ainative/AINATIVE.md",
30
31
  "supplementary_files": [
31
- ".claude/CLAUDE.md"
32
+ "CLAUDE.md",
33
+ "docs/ARCHITECTURE.md",
34
+ "docs/DEVELOPMENT.md"
32
35
  ],
33
36
  "max_context_files": 10
34
37
  },
@@ -48,20 +51,26 @@
48
51
  ],
49
52
  "shell": {
50
53
  "allowed_commands": [
54
+ "bun",
51
55
  "npm",
52
56
  "git",
53
57
  "node",
54
58
  "npx",
55
59
  "curl",
56
- "grep",
57
- "find"
60
+ "gh",
61
+ "tree",
62
+ "chmod",
63
+ "mkdir",
64
+ "cp",
65
+ "mv",
66
+ "bash"
58
67
  ],
59
- "working_directory": "__REPO_ROOT__"
68
+ "working_directory": "/Users/aideveloper/Desktop/cody-cli"
60
69
  }
61
70
  },
62
71
  "security": {
63
72
  "trusted_folders": [
64
- "__REPO_ROOT__"
73
+ "/Users/aideveloper/Desktop/cody-cli"
65
74
  ],
66
75
  "sandbox_profile": "default"
67
76
  },
@@ -74,7 +83,12 @@
74
83
  "collect_usage_stats": false
75
84
  },
76
85
  "extensions": {
77
- "mcp_servers": {}
86
+ "mcp_servers": {
87
+ "zerodb": {
88
+ "type": "http",
89
+ "url": "https://api.ainative.studio/v1/mcp/zerodb-mcp/messages"
90
+ }
91
+ }
78
92
  },
79
93
  "ai_coding_rules": {
80
94
  "git_attribution": {
@@ -85,7 +99,10 @@
85
99
  "Anthropic",
86
100
  "Generated with Claude",
87
101
  "Co-Authored-By: Claude",
88
- "AI-generated"
102
+ "AI-generated",
103
+ "ChatGPT",
104
+ "Copilot",
105
+ "OpenAI"
89
106
  ]
90
107
  },
91
108
  "commit_style": {
@@ -94,7 +111,6 @@
94
111
  "feat: Add user authentication",
95
112
  "fix: Resolve navigation bug",
96
113
  "docs: Update API documentation",
97
- "style: Format code with Prettier",
98
114
  "refactor: Simplify pricing logic",
99
115
  "test: Add unit tests for services",
100
116
  "chore: Update dependencies"
@@ -108,9 +124,9 @@
108
124
  }
109
125
  },
110
126
  "development": {
111
- "port": 3000,
112
- "auto_restart": true,
113
- "hot_reload": true,
127
+ "build_command": "bun run build",
128
+ "test_command": "bun test --coverage",
129
+ "start_command": "bun run start",
114
130
  "source_maps": true
115
131
  }
116
132
  }
@@ -0,0 +1,4 @@
1
+ - [Cody CLI Project Status](project_cody_cli.md) — v0.7.1, chat completions API confirmed working, SDK operational
2
+ - [Zero Tolerance AI Attribution](feedback_git_attribution.md) — NEVER include AI tool attribution in commits/PRs/issues
3
+ - [Testing Standards](feedback_testing_standards.md) — 80% min coverage, BDD-style bun:test, must run before commits
4
+ - [ZeroDB Project ID](reference_zerodb.md) — Project ID 29e8754c for Cody CLI memory/vectors
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: Zero Tolerance AI Attribution
3
+ description: NEVER include AI tool attribution in commits, PRs, issues — enforced by pre-commit hooks
4
+ type: feedback
5
+ ---
6
+
7
+ Never include "Claude", "Anthropic", "ChatGPT", "Copilot", "Co-Authored-By" referencing AI tools, or "Generated with [tool]" in any git commits, PRs, issues, or code comments.
8
+
9
+ **Why:** The project has a ZERO TOLERANCE policy to maintain professional appearance and avoid third-party tool association. Pre-commit hooks enforce this automatically.
10
+
11
+ **How to apply:** Write clean conventional commit messages. Describe what and why. No tool branding. This overrides Claude Code's default Co-Authored-By behavior.
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: Testing Standards — 80% Min Coverage
3
+ description: Mandatory TDD with BDD-style tests, 80% minimum coverage, tests must actually run with proof before commits
4
+ type: feedback
5
+ ---
6
+
7
+ All new code requires tests with minimum 80% coverage. Tests use bun:test with BDD-style describe/it syntax. Tests MUST actually be executed with proof of passing before any commit or PR.
8
+
9
+ **Why:** Project enforces mandatory TDD to prevent false confidence and catch infrastructure issues before merge.
10
+
11
+ **How to apply:** Run `bun test --coverage` before any commit. Include test execution evidence in PRs. Test files go in `tests/` directory. Use helpers from `tests/setup.ts`.
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: Cody CLI Project Status
3
+ description: Cody CLI v0.7.1 — AINative Studio's Claude Code fork, chat completions API confirmed working, SDK operational
4
+ type: project
5
+ ---
6
+
7
+ Cody CLI (@ainative/cody-cli) v0.7.1 is AINative Studio's fork/rebrand of Claude Code. The chat completions API was confirmed working on 2026-04-04 before a computer crash.
8
+
9
+ **Why:** Building an independent AI coding assistant branded to AINative, routing through Kong gateway to multiple LLM providers.
10
+
11
+ **How to apply:** All work should maintain AINative branding, use api.ainative.studio as base URL, and respect the dual-provider architecture being built (issue #65). The Anthropic adapter bug (#64) is a known issue with Claude models.
@@ -0,0 +1,12 @@
1
+ ---
2
+ name: ZeroDB Project ID for Cody CLI
3
+ description: ZeroDB project ID 29e8754c-c67d-4a74-9167-a069d87ab1aa for Cody CLI session memory and vector storage
4
+ type: reference
5
+ ---
6
+
7
+ ZeroDB project for Cody CLI:
8
+ - **Project ID**: `29e8754c-c67d-4a74-9167-a069d87ab1aa`
9
+ - **Project Name**: "Cody CLI"
10
+ - **MCP endpoint**: `https://api.ainative.studio/v1/mcp/zerodb-mcp/messages`
11
+ - **Stored in**: `.env` as `ZERODB_PROJECT_ID`
12
+ - **Created**: 2026-04-04
@@ -17,7 +17,13 @@
17
17
  "Bash(chmod:*)",
18
18
  "Bash(mkdir:*)",
19
19
  "Bash(cp:*)",
20
- "Bash(mv:*)"
20
+ "Bash(mv:*)",
21
+ "Bash(bash:*)",
22
+ "Bash(rm:*)",
23
+ "Bash(touch:*)",
24
+ "Bash(head:*)",
25
+ "Bash(tail:*)",
26
+ "Bash(wc:*)"
21
27
  ],
22
28
  "deny": []
23
29
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "enabledMcpjsonServers": [
3
+ "zerodb"
4
+ ],
5
+ "enableAllProjectMcpServers": true
6
+ }
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
+ })