@codemieai/code 0.0.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 (159) hide show
  1. package/.claude/agents/README.md +298 -0
  2. package/.claude/agents/release-manager.md +857 -0
  3. package/CLAUDE.md +856 -0
  4. package/LICENSE +201 -0
  5. package/README.md +917 -0
  6. package/bin/codemie-code.js +23 -0
  7. package/bin/codemie.js +8 -0
  8. package/dist/agents/adapters/aider.d.ts +12 -0
  9. package/dist/agents/adapters/aider.d.ts.map +1 -0
  10. package/dist/agents/adapters/aider.js +80 -0
  11. package/dist/agents/adapters/aider.js.map +1 -0
  12. package/dist/agents/adapters/claude-code.d.ts +12 -0
  13. package/dist/agents/adapters/claude-code.d.ts.map +1 -0
  14. package/dist/agents/adapters/claude-code.js +98 -0
  15. package/dist/agents/adapters/claude-code.js.map +1 -0
  16. package/dist/agents/adapters/codemie-code.d.ts +12 -0
  17. package/dist/agents/adapters/codemie-code.d.ts.map +1 -0
  18. package/dist/agents/adapters/codemie-code.js +42 -0
  19. package/dist/agents/adapters/codemie-code.js.map +1 -0
  20. package/dist/agents/adapters/codex.d.ts +12 -0
  21. package/dist/agents/adapters/codex.d.ts.map +1 -0
  22. package/dist/agents/adapters/codex.js +80 -0
  23. package/dist/agents/adapters/codex.js.map +1 -0
  24. package/dist/agents/registry.d.ts +18 -0
  25. package/dist/agents/registry.d.ts.map +1 -0
  26. package/dist/agents/registry.js +35 -0
  27. package/dist/agents/registry.js.map +1 -0
  28. package/dist/cli/cli.d.ts +4 -0
  29. package/dist/cli/cli.d.ts.map +1 -0
  30. package/dist/cli/cli.js +107 -0
  31. package/dist/cli/cli.js.map +1 -0
  32. package/dist/cli/commands/doctor.d.ts +3 -0
  33. package/dist/cli/commands/doctor.d.ts.map +1 -0
  34. package/dist/cli/commands/doctor.js +128 -0
  35. package/dist/cli/commands/doctor.js.map +1 -0
  36. package/dist/cli/commands/install.d.ts +3 -0
  37. package/dist/cli/commands/install.d.ts.map +1 -0
  38. package/dist/cli/commands/install.js +76 -0
  39. package/dist/cli/commands/install.js.map +1 -0
  40. package/dist/cli/commands/list.d.ts +3 -0
  41. package/dist/cli/commands/list.d.ts.map +1 -0
  42. package/dist/cli/commands/list.js +50 -0
  43. package/dist/cli/commands/list.js.map +1 -0
  44. package/dist/cli/commands/mcp.d.ts +3 -0
  45. package/dist/cli/commands/mcp.d.ts.map +1 -0
  46. package/dist/cli/commands/mcp.js +459 -0
  47. package/dist/cli/commands/mcp.js.map +1 -0
  48. package/dist/cli/commands/run.d.ts +3 -0
  49. package/dist/cli/commands/run.d.ts.map +1 -0
  50. package/dist/cli/commands/run.js +41 -0
  51. package/dist/cli/commands/run.js.map +1 -0
  52. package/dist/cli/commands/uninstall.d.ts +3 -0
  53. package/dist/cli/commands/uninstall.d.ts.map +1 -0
  54. package/dist/cli/commands/uninstall.js +71 -0
  55. package/dist/cli/commands/uninstall.js.map +1 -0
  56. package/dist/cli/commands/version.d.ts +3 -0
  57. package/dist/cli/commands/version.d.ts.map +1 -0
  58. package/dist/cli/commands/version.js +28 -0
  59. package/dist/cli/commands/version.js.map +1 -0
  60. package/dist/cli/index.d.ts +3 -0
  61. package/dist/cli/index.d.ts.map +1 -0
  62. package/dist/cli/index.js +50 -0
  63. package/dist/cli/index.js.map +1 -0
  64. package/dist/code/agent-events.d.ts +39 -0
  65. package/dist/code/agent-events.d.ts.map +1 -0
  66. package/dist/code/agent-events.js +4 -0
  67. package/dist/code/agent-events.js.map +1 -0
  68. package/dist/code/agent.d.ts +19 -0
  69. package/dist/code/agent.d.ts.map +1 -0
  70. package/dist/code/agent.js +144 -0
  71. package/dist/code/agent.js.map +1 -0
  72. package/dist/code/config.d.ts +13 -0
  73. package/dist/code/config.d.ts.map +1 -0
  74. package/dist/code/config.js +41 -0
  75. package/dist/code/config.js.map +1 -0
  76. package/dist/code/index.d.ts +19 -0
  77. package/dist/code/index.d.ts.map +1 -0
  78. package/dist/code/index.js +400 -0
  79. package/dist/code/index.js.map +1 -0
  80. package/dist/code/prompts.d.ts +2 -0
  81. package/dist/code/prompts.d.ts.map +1 -0
  82. package/dist/code/prompts.js +45 -0
  83. package/dist/code/prompts.js.map +1 -0
  84. package/dist/code/tools/command.d.ts +8 -0
  85. package/dist/code/tools/command.d.ts.map +1 -0
  86. package/dist/code/tools/command.js +83 -0
  87. package/dist/code/tools/command.js.map +1 -0
  88. package/dist/code/tools/diff-utils.d.ts +2 -0
  89. package/dist/code/tools/diff-utils.d.ts.map +1 -0
  90. package/dist/code/tools/diff-utils.js +45 -0
  91. package/dist/code/tools/diff-utils.js.map +1 -0
  92. package/dist/code/tools/filesystem.d.ts +11 -0
  93. package/dist/code/tools/filesystem.d.ts.map +1 -0
  94. package/dist/code/tools/filesystem.js +442 -0
  95. package/dist/code/tools/filesystem.js.map +1 -0
  96. package/dist/code/tools/git.d.ts +7 -0
  97. package/dist/code/tools/git.d.ts.map +1 -0
  98. package/dist/code/tools/git.js +111 -0
  99. package/dist/code/tools/git.js.map +1 -0
  100. package/dist/code/tools/mcp.d.ts +13 -0
  101. package/dist/code/tools/mcp.d.ts.map +1 -0
  102. package/dist/code/tools/mcp.js +230 -0
  103. package/dist/code/tools/mcp.js.map +1 -0
  104. package/dist/data/tips.json +118 -0
  105. package/dist/env/manager.d.ts +14 -0
  106. package/dist/env/manager.d.ts.map +1 -0
  107. package/dist/env/manager.js +99 -0
  108. package/dist/env/manager.js.map +1 -0
  109. package/dist/index.d.ts +14 -0
  110. package/dist/index.d.ts.map +1 -0
  111. package/dist/index.js +47 -0
  112. package/dist/index.js.map +1 -0
  113. package/dist/ui/terminal-ui.d.ts +73 -0
  114. package/dist/ui/terminal-ui.d.ts.map +1 -0
  115. package/dist/ui/terminal-ui.js +900 -0
  116. package/dist/ui/terminal-ui.js.map +1 -0
  117. package/dist/utils/async-tips.d.ts +64 -0
  118. package/dist/utils/async-tips.d.ts.map +1 -0
  119. package/dist/utils/async-tips.js +242 -0
  120. package/dist/utils/async-tips.js.map +1 -0
  121. package/dist/utils/env-mapper.d.ts +40 -0
  122. package/dist/utils/env-mapper.d.ts.map +1 -0
  123. package/dist/utils/env-mapper.js +122 -0
  124. package/dist/utils/env-mapper.js.map +1 -0
  125. package/dist/utils/errors.d.ts +25 -0
  126. package/dist/utils/errors.d.ts.map +1 -0
  127. package/dist/utils/errors.js +58 -0
  128. package/dist/utils/errors.js.map +1 -0
  129. package/dist/utils/exec.d.ts +12 -0
  130. package/dist/utils/exec.d.ts.map +1 -0
  131. package/dist/utils/exec.js +49 -0
  132. package/dist/utils/exec.js.map +1 -0
  133. package/dist/utils/logger.d.ts +19 -0
  134. package/dist/utils/logger.d.ts.map +1 -0
  135. package/dist/utils/logger.js +53 -0
  136. package/dist/utils/logger.js.map +1 -0
  137. package/dist/utils/tips.d.ts +35 -0
  138. package/dist/utils/tips.d.ts.map +1 -0
  139. package/dist/utils/tips.js +132 -0
  140. package/dist/utils/tips.js.map +1 -0
  141. package/docs/USER_GUIDE.md +573 -0
  142. package/eslint.config.mjs +43 -0
  143. package/package.json +66 -0
  144. package/tests/agent-direct.test.mjs +45 -0
  145. package/tests/agent-output.test.mjs +64 -0
  146. package/tests/codemie-code.test.mjs +42 -0
  147. package/tests/context7-only.test.mjs +42 -0
  148. package/tests/conversation-flow.test.mjs +63 -0
  149. package/tests/interactive-simulation.test.mjs +60 -0
  150. package/tests/live-output.test.mjs +53 -0
  151. package/tests/mcp-context7.test.mjs +105 -0
  152. package/tests/mcp-e2e.test.mjs +109 -0
  153. package/tests/mcp-time-server.test.mjs +58 -0
  154. package/tests/streaming.test.mjs +57 -0
  155. package/tests/test-helpers.mjs +94 -0
  156. package/tests/text-wrapping.test.mjs +33 -0
  157. package/tests/tool-count.test.mjs +81 -0
  158. package/tests/ui-format.test.mjs +39 -0
  159. package/tests/ui-state.test.mjs +72 -0
package/CLAUDE.md ADDED
@@ -0,0 +1,856 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Critical First Step: ALWAYS Read Documentation
6
+
7
+ **MANDATORY**: Before writing ANY code, you MUST:
8
+ 1. Read the `README.md` file - this is your PRIMARY source of truth
9
+ 2. Review this CLAUDE.md for architectural patterns and conventions
10
+ 3. Study reference implementations mentioned in this guide
11
+
12
+ ## Common Commands
13
+
14
+ ```bash
15
+ # Installation & Setup
16
+ npm install # Install dependencies
17
+ npm link # Link globally for local testing
18
+
19
+ # Building
20
+ npm run build # Compile TypeScript and copy assets (to dist/)
21
+ npm run dev # Watch mode for development
22
+
23
+ # Testing
24
+ npm test # Run all tests (Node.js native test runner)
25
+ npm run test:watch # Run tests in watch mode
26
+
27
+ # Run individual test files
28
+ node --test tests/agent-direct.test.mjs
29
+ node --test tests/streaming.test.mjs
30
+
31
+ # Code Quality
32
+ npm run lint # Check code style with ESLint
33
+ npm run lint:fix # Fix linting issues automatically
34
+
35
+ # Development Workflow
36
+ npm run build && npm link # Build and link for testing
37
+ codemie doctor # Verify installation and configuration
38
+
39
+ # Release & Publishing
40
+ git tag -a v0.0.1 -m "Release version 0.0.1" # Create release tag
41
+ git push origin v0.0.1 # Push tag to trigger publish
42
+ ```
43
+
44
+ ## Core Principles
45
+
46
+ **ALWAYS follow these fundamental principles:**
47
+
48
+ ### KISS (Keep It Simple, Stupid)
49
+ - Write simple, straightforward code that's easy to understand
50
+ - Avoid over-engineering and unnecessary complexity
51
+ - Remove redundant code, scripts, and configuration
52
+ - If something can be done in fewer lines/steps, do it
53
+ - Question every piece of complexity - is it truly needed?
54
+
55
+ ### DRY (Don't Repeat Yourself)
56
+ - Never duplicate code, logic, or configuration
57
+ - Extract common patterns into reusable functions/utilities
58
+ - Reuse existing utilities from `src/utils/` before creating new ones
59
+ - If you find yourself copying code, refactor it into a shared function
60
+ - One source of truth for each piece of knowledge
61
+
62
+ **Remember:** Simple, clean code is better than clever, complex code.
63
+
64
+ ## Specialized Agents
65
+
66
+ This project uses specialized subagents for complex, multi-step workflows. These agents have dedicated system prompts stored in `.claude/agents/` that can be updated independently.
67
+
68
+ ### Release Manager Agent
69
+
70
+ **Location:** `.claude/agents/release-manager.md`
71
+
72
+ **Purpose:** Automate the complete release process from change analysis to npm publication.
73
+
74
+ **Trigger Phrases:**
75
+ - "Release version X.X.X"
76
+ - "Create a new release"
77
+ - "Release a patch/minor/major version"
78
+ - "Use release manager to..."
79
+ - "Prepare a release"
80
+
81
+ **What it does:**
82
+ 1. Runs pre-flight checks (clean working directory, correct branch)
83
+ 2. Analyzes git history since last release tag
84
+ 3. Categorizes commits using conventional commits
85
+ 4. Generates structured release notes (Keep a Changelog format)
86
+ 5. Updates package.json and package-lock.json version
87
+ 6. Creates git commit for version bump
88
+ 7. Creates and pushes annotated git tag
89
+ 8. Creates GitHub release with generated notes
90
+ 9. Triggers npm publish workflow via GitHub Actions
91
+ 10. Reports completion status and provides verification links
92
+
93
+ **Example Usage:**
94
+ ```
95
+ You: "Release version 0.0.2"
96
+
97
+ Claude:
98
+ 1. Checks git status and current branch
99
+ 2. Analyzes 12 commits since v0.0.1
100
+ 3. Generates release notes with categorized changes
101
+ 4. Shows preview and asks for confirmation
102
+ 5. Updates package.json to 0.0.2
103
+ 6. Creates commit "chore: bump version to 0.0.2"
104
+ 7. Creates tag v0.0.2 and pushes
105
+ 8. Creates GitHub Release
106
+ 9. Reports: "✅ Released v0.0.2, npm publish workflow triggered"
107
+ ```
108
+
109
+ **Customization:**
110
+ Edit `.claude/agents/release-manager.md` to modify:
111
+ - Release notes format
112
+ - Commit categorization rules
113
+ - Version bump strategies
114
+ - Error handling behavior
115
+ - Pre-flight check requirements
116
+
117
+ ### Creating Additional Agents
118
+
119
+ To create your own specialized agent:
120
+
121
+ 1. **Create the agent file**: `.claude/agents/{role}-{function}.md`
122
+ - Example: `code-reviewer.md`, `test-generator.md`, `security-auditor.md`
123
+
124
+ 2. **Define the system prompt**: Include role, capabilities, workflow, error handling, and examples
125
+
126
+ 3. **Document trigger phrases**: Add them to this CLAUDE.md section
127
+
128
+ 4. **Update agents README**: Add documentation to `.claude/agents/README.md`
129
+
130
+ **Naming convention:** `{role}-{function}.md`
131
+ - ✅ `release-manager.md`, `code-reviewer.md`, `test-generator.md`
132
+ - ❌ `release.md`, `agent1.md`, `helper.md`
133
+
134
+ **See:** `.claude/agents/README.md` for detailed agent creation guide and best practices.
135
+
136
+ ## Critical Policies
137
+
138
+ ### Testing & Documentation Policy
139
+
140
+ **IMPORTANT - Do NOT write tests, documentation, or summaries unless explicitly requested:**
141
+ - Do NOT write tests unless user explicitly says: "Write tests", "Create unit tests", etc.
142
+ - Do NOT run tests unless user explicitly says: "Run the tests", "Execute test suite", etc.
143
+ - Do NOT generate documentation unless user explicitly says: "Write documentation", "Create docs", etc.
144
+ - Do NOT write summaries unless user explicitly says: "Summarize", "Write a summary", etc.
145
+ - Do NOT run compilation checks unless explicitly requested
146
+ - Do NOT proactively create README files or documentation files
147
+
148
+ ### Node Modules Policy
149
+
150
+ **IMPORTANT:**
151
+ - NEVER modify files inside `node_modules/`
152
+ - All source code lives in `src/`
153
+ - All tests live in `tests/`
154
+ - Build output goes to `dist/`
155
+
156
+ ### Utilities Policy
157
+
158
+ **Before implementing new utility functions:**
159
+ 1. Check if similar functionality exists in `src/utils/` directory
160
+ 2. Always reuse existing utilities (logger, exec, errors, tips, etc.)
161
+ 3. If implementing new shared utilities, get user approval first
162
+
163
+ ### Git Workflow Policy
164
+
165
+ **IMPORTANT - Always use feature branches:**
166
+ - NEVER commit directly to `main` branch
167
+ - ALWAYS create a feature branch for changes
168
+ - Follow standard git branch naming conventions:
169
+ - `feature/add-something` - New features
170
+ - `fix/issue-description` - Bug fixes
171
+ - `docs/update-readme` - Documentation changes
172
+ - `refactor/component-name` - Code refactoring
173
+ - `chore/update-dependencies` - Maintenance tasks
174
+
175
+ **Standard workflow:**
176
+ ```bash
177
+ # 1. Create feature branch from main
178
+ git checkout main
179
+ git pull origin main
180
+ git checkout -b feature/your-feature-name
181
+
182
+ # 2. Make changes and commit
183
+ git add .
184
+ git commit -m "Descriptive commit message"
185
+
186
+ # 3. Push branch to remote
187
+ git push -u origin feature/your-feature-name
188
+
189
+ # 4. Create Pull Request for review
190
+ # Use GitHub UI or gh CLI to create PR
191
+
192
+ # 5. After PR approval, merge to main
193
+ ```
194
+
195
+ **Branch naming guidelines:**
196
+ - Use lowercase with hyphens
197
+ - Be descriptive but concise
198
+ - Include ticket/issue number if applicable (e.g., `feature/GH-123-add-feature`)
199
+ - Keep branch names under 50 characters when possible
200
+
201
+ ### Release & Publishing Policy
202
+
203
+ **IMPORTANT - How to publish to npm registry:**
204
+
205
+ The project uses GitHub Actions to automatically publish to npm when a release is created. The workflow is defined in `.github/workflows/publish.yml`.
206
+
207
+ **Step-by-step release process:**
208
+
209
+ 1. **Ensure you're on the main branch** (after merging your feature branch):
210
+ ```bash
211
+ git checkout main
212
+ git pull origin main
213
+ ```
214
+
215
+ 2. **Create an annotated git tag** with the version number:
216
+ ```bash
217
+ # Match the version in package.json (e.g., 0.0.1)
218
+ git tag -a v0.0.1 -m "Release version 0.0.1"
219
+ ```
220
+
221
+ 3. **Push the tag to GitHub**:
222
+ ```bash
223
+ git push origin v0.0.1
224
+ ```
225
+
226
+ 4. **Create a GitHub Release** (two options):
227
+
228
+ **Option A - GitHub UI (recommended):**
229
+ - Go to GitHub repository → Releases → "Draft a new release"
230
+ - Select the tag you just pushed (`v0.0.1`)
231
+ - Add release title (e.g., `v0.0.1` or `Release 0.0.1`)
232
+ - Add release notes describing changes
233
+ - Click "Publish release"
234
+
235
+ **Option B - Manual workflow trigger:**
236
+ - Go to Actions → "Publish to NPM" workflow
237
+ - Click "Run workflow"
238
+ - Select the `main` branch
239
+ - Click "Run workflow"
240
+
241
+ 5. **The workflow will automatically**:
242
+ - Checkout code
243
+ - Install dependencies
244
+ - Run CI checks (`npm run ci` - includes lint, build, and tests)
245
+ - Publish to npm with `npm publish --access public`
246
+ - Authenticate using the `NPM_TOKEN` secret
247
+
248
+ **Prerequisites:**
249
+ - `NPM_TOKEN` must be configured in GitHub repository secrets
250
+ - Version in `package.json` must match the tag version (without the `v` prefix)
251
+ - All CI checks must pass (linting, build, tests)
252
+
253
+ **Version bumping:**
254
+ ```bash
255
+ # Update version in package.json
256
+ npm version patch # 0.0.1 → 0.0.2
257
+ npm version minor # 0.0.1 → 0.1.0
258
+ npm version major # 0.0.1 → 1.0.0
259
+
260
+ # This creates a commit and tag automatically
261
+ # Then push both:
262
+ git push origin main --tags
263
+ ```
264
+
265
+ **Verifying the publish:**
266
+ ```bash
267
+ # Check on npm registry
268
+ npm view @codemieai/code
269
+
270
+ # Install and test locally
271
+ npm install -g @codemieai/code@latest
272
+ codemie doctor
273
+ ```
274
+
275
+ ## Reference Implementations
276
+
277
+ Study these excellent examples before implementing new code:
278
+ - **AI Assistant** (`src/code/`) - Complete ReAct agent implementation with streaming
279
+ - **Tool System** (`src/code/tools/`) - Filesystem, Git, Command, and MCP tools
280
+ - **UI Layer** (`src/ui/terminal-ui.ts`) - Interactive terminal with cancellation support
281
+ - **Agent System** (`src/agents/`) - Agent registry and adapters pattern
282
+
283
+ ## Communication Style
284
+
285
+ When responding:
286
+ 1. Confirm your understanding of the request
287
+ 2. Reference which patterns you're following from existing code
288
+ 3. Outline your implementation approach
289
+ 4. Present complete, working code
290
+ 5. Explain key design decisions
291
+ 6. Highlight any assumptions requiring user input
292
+
293
+ ## Self-Verification Before Delivery
294
+
295
+ - [ ] README.md and CLAUDE.md have been read and understood
296
+ - [ ] Reference implementations reviewed for similar patterns
297
+ - [ ] Code follows TypeScript best practices and project conventions
298
+ - [ ] No tests written (unless explicitly requested)
299
+ - [ ] No tests executed (unless explicitly requested)
300
+ - [ ] Code is production-ready and follows DRY/KISS principles
301
+
302
+ ## Escalation Scenarios
303
+
304
+ Seek user guidance when:
305
+ - Documentation is missing, unclear, or contradictory
306
+ - New dependencies are required
307
+ - Breaking changes are necessary
308
+ - Multiple valid approaches exist
309
+ - Reference implementations don't cover the use case
310
+ - Security or architectural concerns arise
311
+
312
+ ## Project Overview
313
+
314
+ **CodeMie Code** is a unified npm package that provides:
315
+ - A built-in AI coding assistant powered by LiteLLM (via LangChain)
316
+ - A CLI wrapper for managing multiple AI coding agents (Claude Code, Aider, Codex)
317
+
318
+ The project uses TypeScript with a ReAct agent pattern via LangGraph for autonomous tool execution.
319
+
320
+ ## Quick Architecture Overview
321
+
322
+ ### Core Components
323
+
324
+ - **AI Assistant** (`src/code/`): Main assistant class, agent, configuration, prompts
325
+ - **Tool System** (`src/code/tools/`): Filesystem, Git, Command execution, MCP integration
326
+ - **CLI Wrapper** (`src/cli/commands/`): Commands for managing external agents
327
+ - **Agent System** (`src/agents/`): Registry and adapters for different AI agents
328
+ - **UI Layer** (`src/ui/`): Interactive terminal with streaming and cancellation
329
+ - **Environment** (`src/env/`, `src/utils/`): Config management and utilities
330
+
331
+ ### Entry Points
332
+ - `bin/codemie-code.js` - Starts the AI assistant
333
+ - `bin/codemie.js` - CLI wrapper for agent management
334
+
335
+ ### Key Design Patterns
336
+
337
+ #### ReAct Agent Pattern
338
+ Uses LangGraph's `createReactAgent`:
339
+ 1. **Reasoning** - LLM thinks about what to do
340
+ 2. **Acting** - Calls tools based on reasoning
341
+ 3. **Observing** - Receives tool results
342
+ 4. Loops until task is complete
343
+
344
+ #### Streaming Architecture
345
+ Agent supports streaming via `chatStream()`:
346
+ - `thinking_start/end` - Agent is reasoning
347
+ - `tool_call_start` - Tool invocation begins
348
+ - `tool_call_result` - Tool returns result
349
+ - `content_chunk` - Partial response content
350
+ - `complete/cancelled/error` - Terminal states
351
+
352
+ #### Security Model
353
+ All filesystem/command operations validate:
354
+ - Paths must be within `allowedDirectories`
355
+ - Symlinks are resolved and validated
356
+ - Dangerous command patterns are blocked
357
+ - Ignore patterns exclude sensitive dirs
358
+
359
+ ## Project Structure
360
+
361
+ ```
362
+ codemie-code/
363
+ ├── bin/
364
+ │ ├── codemie-code.js # AI assistant entry point
365
+ │ └── codemie.js # CLI wrapper entry point
366
+
367
+ ├── src/
368
+ │ ├── code/ # CodeMie Code Assistant
369
+ │ │ ├── index.ts # Main assistant class
370
+ │ │ ├── agent.ts # LangChain ReAct agent
371
+ │ │ ├── agent-events.ts # Event system for streaming
372
+ │ │ ├── config.ts # Configuration loader
373
+ │ │ ├── prompts.ts # System prompts
374
+ │ │ └── tools/ # Tool implementations
375
+ │ │ ├── filesystem.ts # 8 filesystem tools
376
+ │ │ ├── git.ts # 4 git tools
377
+ │ │ ├── command.ts # Command execution
378
+ │ │ ├── mcp.ts # MCP integration
379
+ │ │ └── diff-utils.ts # Diff utilities
380
+ │ │
381
+ │ ├── cli/ # CLI Wrapper
382
+ │ │ └── commands/ # CLI commands
383
+ │ │ ├── list.ts
384
+ │ │ ├── install.ts
385
+ │ │ ├── run.ts
386
+ │ │ ├── doctor.ts
387
+ │ │ ├── uninstall.ts
388
+ │ │ └── version.ts
389
+ │ │
390
+ │ ├── agents/ # Agent System
391
+ │ │ ├── registry.ts # Agent registry
392
+ │ │ └── adapters/ # Agent adapters
393
+ │ │ ├── codemie-code.ts
394
+ │ │ ├── claude-code.ts
395
+ │ │ ├── codex.ts
396
+ │ │ └── aider.ts
397
+ │ │
398
+ │ ├── env/ # Environment Management
399
+ │ │ └── manager.ts
400
+ │ │
401
+ │ ├── ui/ # UI Layer
402
+ │ │ └── terminal-ui.ts # Interactive terminal
403
+ │ │
404
+ │ └── utils/ # Utilities
405
+ │ ├── env-mapper.ts # Environment variable mapping
406
+ │ ├── exec.ts # Process execution
407
+ │ ├── logger.ts # Logging
408
+ │ ├── errors.ts # Error classes
409
+ │ └── tips.ts # Loading tips
410
+
411
+ ├── tests/ # Test files
412
+ │ ├── test-*.js # Manual integration tests
413
+ │ └── integration/ # Additional test scenarios
414
+
415
+ ├── dist/ # Build output (TypeScript compilation)
416
+ ├── mcp/ # MCP server configurations
417
+ │ └── servers.json
418
+ ├── package.json # Dependencies and scripts
419
+ ├── tsconfig.json # TypeScript configuration
420
+ ├── eslint.config.mjs # ESLint configuration
421
+ └── README.md # Package documentation
422
+ ```
423
+
424
+ ## Technology Stack
425
+
426
+ - **Language**: TypeScript (ES2022, NodeNext modules)
427
+ - **Runtime**: Node.js >= 24.0.0 (LTS Krypton)
428
+ - **Package Manager**: npm
429
+ - **LLM Framework**: LangChain 1.x (`@langchain/core`, `@langchain/langgraph`, `@langchain/openai`)
430
+ - **LLM Provider**: LiteLLM (OpenAI-compatible proxy)
431
+ - **CLI Framework**: Commander.js
432
+ - **Schema Validation**: Zod
433
+ - **Diff Generation**: diff package
434
+ - **UI**: Chalk, Inquirer, Ora
435
+ - **Testing**: Jest with ts-jest
436
+ - **Linting**: ESLint with TypeScript support
437
+
438
+ ## Configuration & Environment
439
+
440
+ ### Environment Variable Priority
441
+ The config loader (`src/utils/env-mapper.ts`) checks in order:
442
+ 1. `ANTHROPIC_*` - For Claude models
443
+ 2. `OPENAI_*` - For GPT models
444
+ 3. `AI_*` - Generic provider-agnostic
445
+ 4. `LITELLM_*` - Legacy format (still supported)
446
+
447
+ ### Required Environment Variables
448
+
449
+ ```bash
450
+ # Provider-specific (choose one set)
451
+
452
+ # For Anthropic Claude models
453
+ ANTHROPIC_BASE_URL=https://litellm-proxy.example.com
454
+ ANTHROPIC_AUTH_TOKEN=your-token
455
+ ANTHROPIC_MODEL=claude-4-5-sonnet
456
+
457
+ # OR for OpenAI models
458
+ OPENAI_BASE_URL=https://api.openai.com/v1
459
+ OPENAI_API_KEY=your-token
460
+ OPENAI_MODEL=gpt-4
461
+
462
+ # OR generic provider-agnostic
463
+ AI_BASE_URL=https://litellm-proxy.example.com
464
+ AI_AUTH_TOKEN=your-token
465
+ AI_MODEL=claude-4-5-sonnet
466
+ ```
467
+
468
+ ### Optional Environment Variables
469
+
470
+ ```bash
471
+ CODEMIE_DEBUG=true # Enable debug logging
472
+ CODEMIE_MODEL=claude-opus # Override model
473
+ CODEMIE_MCP_SERVERS=filesystem,cli-mcp-server # Load specific MCP servers
474
+ AI_TIMEOUT=300 # Request timeout in seconds
475
+ ```
476
+
477
+ ### MCP Configuration
478
+ MCP servers are defined in:
479
+ 1. `mcp/servers.json` - Default server configurations
480
+ 2. `~/.codemie/config.json` - User-specific MCP config
481
+
482
+ MCP integration is handled by `src/code/tools/mcp.ts` which dynamically loads tools from configured servers.
483
+
484
+ ## Development Guidelines
485
+
486
+ ### File Naming Conventions
487
+
488
+ - **Modules**: kebab-case (e.g., `terminal-ui.ts`, `agent-events.ts`)
489
+ - **Classes**: PascalCase (e.g., `CodeMieCode`, `CodeMieAgent`)
490
+ - **Functions**: camelCase (e.g., `loadConfig`, `getTools`)
491
+ - **Constants**: UPPER_SNAKE_CASE (e.g., `SYSTEM_PROMPT`)
492
+ - **Tests**: `test-*.js` or `*.test.ts`
493
+
494
+ ### Code Style
495
+
496
+ - **Formatter**: TypeScript default (2 spaces)
497
+ - **Line Length**: No strict limit, but keep reasonable
498
+ - **Quotes**: Single quotes preferred
499
+ - **Semicolons**: Required
500
+ - **Imports**: Organized (standard library, third-party, local)
501
+ - **Type Hints**: Use TypeScript types throughout
502
+ - **Async/Await**: Preferred over promises/callbacks
503
+
504
+ ### Import Organization
505
+
506
+ ```typescript
507
+ // Third-party imports
508
+ import { ChatOpenAI } from '@langchain/openai';
509
+ import { StructuredTool } from '@langchain/core/tools';
510
+ import chalk from 'chalk';
511
+
512
+ // Local imports
513
+ import { CodeMieConfig } from './config';
514
+ import { logger } from '../utils/logger';
515
+ import { FilesystemTools } from './tools/filesystem';
516
+ ```
517
+
518
+ ## Tool Development
519
+
520
+ ### Adding New Filesystem Tools
521
+
522
+ Extend `FilesystemTools` class in `src/code/tools/filesystem.ts`:
523
+ 1. Create tool using `new StructuredTool()` with Zod schema
524
+ 2. Add validation via `validatePath()` or `validateInAllowedDirectory()`
525
+ 3. Push to tools array in constructor
526
+ 4. Handle errors with try-catch, return error messages
527
+
528
+ Example:
529
+ ```typescript
530
+ const myNewTool = new StructuredTool({
531
+ name: "my_new_tool",
532
+ description: "Description of what this tool does",
533
+ schema: z.object({
534
+ path: z.string().describe("File path"),
535
+ content: z.string().describe("File content")
536
+ }),
537
+ func: async ({ path, content }) => {
538
+ try {
539
+ const fullPath = this.validatePath(path);
540
+ // Tool implementation
541
+ return "Success message";
542
+ } catch (error: any) {
543
+ return `Error: ${error.message}`;
544
+ }
545
+ }
546
+ });
547
+ ```
548
+
549
+ ### Adding New Git Tools
550
+
551
+ Extend `GitTools` class in `src/code/tools/git.ts` following the same pattern.
552
+
553
+ ### Diff-Based Editing
554
+
555
+ The `edit_file` tool uses `diff` package to generate unified diffs:
556
+ - Preserves indentation (tabs vs spaces)
557
+ - Shows clear before/after changes
558
+ - Validates file exists before editing
559
+
560
+ ## Agent Adapters
561
+
562
+ To add a new agent adapter (e.g., for Cursor or Copilot):
563
+
564
+ 1. Create `src/agents/adapters/my-agent.ts` implementing `AgentAdapter` interface
565
+ 2. Register in `src/agents/registry.ts`
566
+ 3. Implement required methods:
567
+ - `install()` - Install the agent
568
+ - `uninstall()` - Uninstall the agent
569
+ - `isInstalled()` - Check if installed
570
+ - `run(args)` - Run the agent
571
+ - `getVersion()` - Get version info
572
+
573
+ Example:
574
+ ```typescript
575
+ export class MyAgentAdapter implements AgentAdapter {
576
+ name = 'my-agent';
577
+ displayName = 'My Agent';
578
+ description = 'Description of my agent';
579
+
580
+ async install(): Promise<void> { /* ... */ }
581
+ async uninstall(): Promise<void> { /* ... */ }
582
+ async isInstalled(): Promise<boolean> { /* ... */ }
583
+ async run(args: string[]): Promise<void> { /* ... */ }
584
+ async getVersion(): Promise<string | null> { /* ... */ }
585
+ }
586
+ ```
587
+
588
+ ## Error Handling
589
+
590
+ ### Standard Error Pattern
591
+
592
+ ```typescript
593
+ try {
594
+ // Operation
595
+ const result = await performOperation();
596
+ return result;
597
+ } catch (error: any) {
598
+ // Log error for debugging
599
+ logger.error('Operation failed:', error);
600
+
601
+ // Return user-friendly error message
602
+ throw new Error(`Operation failed: ${error.message}`);
603
+ }
604
+ ```
605
+
606
+ ### Custom Error Classes
607
+
608
+ Located in `src/utils/errors.ts`:
609
+ - `ConfigurationError` - Configuration issues
610
+ - Use standard `Error` for most cases
611
+
612
+ ## Testing Approach
613
+
614
+ ### Test Framework & Structure
615
+
616
+ - Uses **Node.js native test runner** (`node:test`)
617
+ - All test files are located in `tests/` directory
618
+ - Test files use `.mjs` extension (ES modules)
619
+ - Tests are built using `describe()`, `it()`, `before()`, and `after()` from `node:test`
620
+
621
+ ### Test Categories
622
+
623
+ 1. **Agent Tests** - Test LLM agent functionality (requires base URL configuration)
624
+ - `agent-direct.test.mjs` - Direct agent tool calling
625
+ - `agent-output.test.mjs` - Agent output format
626
+ - `streaming.test.mjs` - Streaming functionality
627
+ - `conversation-flow.test.mjs` - Multiple question handling
628
+
629
+ 2. **Integration Tests** - Test `codemie-code` (AI assistant) (requires base URL configuration)
630
+ - `codemie-code.test.mjs` - CodeMieCode tool calling
631
+ - `tool-count.test.mjs` - Tool loading verification
632
+ - `interactive-simulation.test.mjs` - Interactive conversation simulation
633
+ - `ui-state.test.mjs` - UI state management
634
+ - `live-output.test.mjs` - Live output format
635
+
636
+ 3. **MCP Tests** - Test MCP server integration with AI assistant (requires base URL configuration)
637
+ - `mcp-context7.test.mjs` - Context7 MCP server
638
+ - `mcp-time-server.test.mjs` - Time MCP server
639
+ - `mcp-e2e.test.mjs` - End-to-end MCP integration
640
+ - `context7-only.test.mjs` - Context7 server only
641
+
642
+ 4. **UI/Format Tests** - Test formatting and UI logic (does NOT require base URL)
643
+ - `ui-format.test.mjs` - UI formatting
644
+ - `text-wrapping.test.mjs` - Text wrapping logic
645
+
646
+ 5. **CLI Wrapper Tests** - Test `codemie` CLI commands (does NOT require base URL)
647
+ - Currently no tests exist for CLI commands (`codemie doctor`, `codemie list`, etc.)
648
+ - These commands don't interact with LLM, so they don't need base URL configuration
649
+
650
+ ### Test Helpers
651
+
652
+ The `tests/test-helpers.mjs` file provides utilities for managing test preconditions:
653
+
654
+ **Key Functions:**
655
+
656
+ ```javascript
657
+ // Check if base URL is configured
658
+ isBaseUrlConfigured()
659
+
660
+ // Skip test if base URL is not configured (with warning)
661
+ skipIfNoBaseUrl(testContext, customMessage?)
662
+
663
+ // Get list of missing environment variables
664
+ getMissingEnvVars()
665
+
666
+ // Check if all required environment variables are configured
667
+ isFullyConfigured()
668
+
669
+ // Print configuration status for debugging
670
+ printConfigStatus()
671
+ ```
672
+
673
+ **Usage Example:**
674
+
675
+ ```javascript
676
+ import { describe, it, before } from 'node:test';
677
+ import { skipIfNoBaseUrl } from './test-helpers.mjs';
678
+
679
+ describe('My Test Suite', () => {
680
+ before(() => {
681
+ if (skipIfNoBaseUrl()) return;
682
+ // ... setup code
683
+ });
684
+
685
+ it('should do something', () => {
686
+ if (skipIfNoBaseUrl()) return;
687
+ // ... test code
688
+ });
689
+ });
690
+ ```
691
+
692
+ ### Environment Variable Requirements
693
+
694
+ Tests that interact with LLM agents require one of:
695
+ - `CODEMIE_BASE_URL`
696
+ - `ANTHROPIC_BASE_URL`
697
+ - `OPENAI_BASE_URL`
698
+
699
+ If these are not set, tests will be **skipped with a warning** instead of failing.
700
+
701
+ ### Running Tests
702
+
703
+ ```bash
704
+ # Run all tests
705
+ npm test
706
+
707
+ # Run tests in watch mode
708
+ npm run test:watch
709
+
710
+ # Run specific test file
711
+ node --test tests/agent-direct.test.mjs
712
+
713
+ # Run tests without base URL (will skip LLM tests)
714
+ unset CODEMIE_BASE_URL ANTHROPIC_BASE_URL OPENAI_BASE_URL
715
+ npm test
716
+
717
+ # Run tests with debug output
718
+ CODEMIE_DEBUG=true npm test
719
+ ```
720
+
721
+ ### Writing New Tests
722
+
723
+ **For tests requiring LLM interaction:**
724
+
725
+ 1. Import test helpers: `import { skipIfNoBaseUrl } from './test-helpers.mjs'`
726
+ 2. Add skip checks to `before()` hooks: `before(() => { if (skipIfNoBaseUrl()) return; ... })`
727
+ 3. Add skip checks to each test: `it('test name', () => { if (skipIfNoBaseUrl()) return; ... })`
728
+
729
+ **For tests NOT requiring LLM interaction:**
730
+
731
+ 1. No need to import or use test helpers
732
+ 2. Tests will run regardless of environment configuration
733
+
734
+ ### Test Best Practices
735
+
736
+ - **Always build before testing**: Run `npm run build` to ensure dist/ is up to date
737
+ - **Use descriptive test names**: Clearly state what is being tested
738
+ - **Clean up resources**: Use `after()` hooks to dispose of resources (agents, MCP tools, etc.)
739
+ - **Test isolation**: Each test should be independent and not rely on state from other tests
740
+ - **Mock external dependencies**: When possible, avoid hitting real external services
741
+ - **Handle async properly**: Use `async/await` for asynchronous operations
742
+
743
+ ## Debugging
744
+
745
+ Enable debug mode to see detailed execution:
746
+
747
+ ```bash
748
+ export CODEMIE_DEBUG=true
749
+ codemie-code
750
+ ```
751
+
752
+ This shows:
753
+ - Tool initialization counts
754
+ - LLM request/response details
755
+ - File operation details
756
+ - Error stack traces
757
+
758
+ ## Important Notes
759
+
760
+ ### Module System
761
+ - Uses ES modules (`"module": "NodeNext"`)
762
+ - Import paths use `.js` extensions even for `.ts` files
763
+ - Example: `import { logger } from '../utils/logger.js'`
764
+
765
+ ### TypeScript Configuration
766
+ - Strict mode enabled
767
+ - Declaration maps for debugging
768
+ - Output to `dist/` directory
769
+ - Source maps enabled
770
+
771
+ ### LangChain Version
772
+ - Uses LangChain 1.x ecosystem
773
+ - `@langchain/core` for base types
774
+ - `@langchain/langgraph` for agent creation
775
+ - `@langchain/openai` for ChatOpenAI model
776
+
777
+ ### Not a Git Repository
778
+ - This directory is NOT initialized as a git repository
779
+ - It's a package within a larger monorepo structure
780
+
781
+ ## Build Process
782
+
783
+ The build process (`npm run build`):
784
+ 1. Compiles TypeScript from `src/` to `dist/`
785
+ 2. Copies `src/data/tips.json` to `dist/data/`
786
+ 3. Generates declaration files (`.d.ts`)
787
+ 4. Generates source maps
788
+
789
+ ## Common Patterns & Utilities
790
+
791
+ ### Configuration Loading
792
+ See `src/code/config.ts` and `src/utils/env-mapper.ts` for how configuration is loaded with fallbacks.
793
+
794
+ ### Logging
795
+ Use the shared logger from `src/utils/logger.ts`:
796
+ ```typescript
797
+ import { logger } from '../utils/logger';
798
+
799
+ logger.info('Information message');
800
+ logger.success('Success message');
801
+ logger.error('Error message');
802
+ logger.debug('Debug message'); // Only shown when CODEMIE_DEBUG=true
803
+ ```
804
+
805
+ ### Process Execution
806
+ Use utilities from `src/utils/exec.ts` for running commands.
807
+
808
+ ### Tips System
809
+ Loading tips are displayed during initialization from `src/data/tips.json`.
810
+
811
+ ## Best Practices
812
+
813
+ 1. **Modular Design**: Each component should have clear separation of concerns
814
+ 2. **Error Handling**: Always handle errors gracefully with user-friendly messages
815
+ 3. **Security**: Validate all paths and commands before execution
816
+ 4. **Reusability**: Utilize shared utilities from `src/utils/`
817
+ 5. **Documentation**: Provide comprehensive JSDoc comments for all public methods
818
+ 6. **TypeScript**: Use proper types throughout, avoid `any` when possible
819
+ 7. **Testing**: Write tests for new functionality when requested
820
+ 8. **Async/Await**: Handle async operations properly with try-catch
821
+
822
+ ## Troubleshooting
823
+
824
+ ### Issue: Command not found after installation
825
+ **Solution**: Re-link the package
826
+ ```bash
827
+ npm link
828
+ which codemie
829
+ which codemie-code
830
+ ```
831
+
832
+ ### Issue: TypeScript compilation errors
833
+ **Solution**: Clean build
834
+ ```bash
835
+ rm -rf dist/
836
+ npm run build
837
+ ```
838
+
839
+ ### Issue: Import errors
840
+ **Solution**: Check import paths use `.js` extensions and are correct
841
+
842
+ ### Issue: Environment variables not loaded
843
+ **Solution**: Check variable names match the priority order and verify with:
844
+ ```bash
845
+ echo $ANTHROPIC_BASE_URL
846
+ echo $AI_BASE_URL
847
+ codemie doctor
848
+ ```
849
+
850
+ ## Support
851
+
852
+ For questions or issues:
853
+ - Review existing implementations in `src/`
854
+ - Check test examples in `tests/`
855
+ - Consult utilities in `src/utils/`
856
+ - Read comprehensive `README.md`