@codemieai/code 0.0.1 → 0.0.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.
Files changed (244) hide show
  1. package/.codemie/guides/git-workflow.md +493 -0
  2. package/CLAUDE.md +130 -761
  3. package/README.md +283 -695
  4. package/bin/codemie-claude.js +122 -0
  5. package/bin/codemie-code.js +90 -15
  6. package/bin/codemie-codex.js +138 -0
  7. package/bin/codemie.js +1 -1
  8. package/config.example.json +10 -0
  9. package/dist/agents/adapters/claude-code.d.ts +2 -2
  10. package/dist/agents/adapters/claude-code.d.ts.map +1 -1
  11. package/dist/agents/adapters/claude-code.js +20 -42
  12. package/dist/agents/adapters/claude-code.js.map +1 -1
  13. package/dist/agents/adapters/codemie-code.d.ts +11 -2
  14. package/dist/agents/adapters/codemie-code.d.ts.map +1 -1
  15. package/dist/agents/adapters/codemie-code.js +93 -25
  16. package/dist/agents/adapters/codemie-code.js.map +1 -1
  17. package/dist/agents/adapters/codex.d.ts +2 -2
  18. package/dist/agents/adapters/codex.d.ts.map +1 -1
  19. package/dist/agents/adapters/codex.js +31 -24
  20. package/dist/agents/adapters/codex.js.map +1 -1
  21. package/dist/agents/codemie-code/agent.d.ts +89 -0
  22. package/dist/agents/codemie-code/agent.d.ts.map +1 -0
  23. package/dist/agents/codemie-code/agent.js +523 -0
  24. package/dist/agents/codemie-code/agent.js.map +1 -0
  25. package/dist/agents/codemie-code/config.d.ts +40 -0
  26. package/dist/agents/codemie-code/config.d.ts.map +1 -0
  27. package/dist/agents/codemie-code/config.js +276 -0
  28. package/dist/agents/codemie-code/config.js.map +1 -0
  29. package/dist/agents/codemie-code/filters.d.ts +91 -0
  30. package/dist/agents/codemie-code/filters.d.ts.map +1 -0
  31. package/dist/agents/codemie-code/filters.js +328 -0
  32. package/dist/agents/codemie-code/filters.js.map +1 -0
  33. package/dist/agents/codemie-code/index.d.ts +78 -0
  34. package/dist/agents/codemie-code/index.d.ts.map +1 -0
  35. package/dist/agents/codemie-code/index.js +259 -0
  36. package/dist/agents/codemie-code/index.js.map +1 -0
  37. package/dist/agents/codemie-code/prompts.d.ts +11 -0
  38. package/dist/agents/codemie-code/prompts.d.ts.map +1 -0
  39. package/dist/agents/codemie-code/prompts.js +31 -0
  40. package/dist/agents/codemie-code/prompts.js.map +1 -0
  41. package/dist/agents/codemie-code/streaming/events.d.ts +7 -0
  42. package/dist/agents/codemie-code/streaming/events.d.ts.map +1 -0
  43. package/dist/agents/codemie-code/streaming/events.js +7 -0
  44. package/dist/agents/codemie-code/streaming/events.js.map +1 -0
  45. package/dist/agents/codemie-code/streaming/formatter.d.ts +2 -0
  46. package/dist/agents/codemie-code/streaming/formatter.d.ts.map +1 -0
  47. package/dist/agents/codemie-code/streaming/formatter.js +2 -0
  48. package/dist/agents/codemie-code/streaming/formatter.js.map +1 -0
  49. package/dist/agents/codemie-code/streaming/ui.d.ts +2 -0
  50. package/dist/agents/codemie-code/streaming/ui.d.ts.map +1 -0
  51. package/dist/agents/codemie-code/streaming/ui.js +2 -0
  52. package/dist/agents/codemie-code/streaming/ui.js.map +1 -0
  53. package/dist/agents/codemie-code/tokenUtils.d.ts +108 -0
  54. package/dist/agents/codemie-code/tokenUtils.d.ts.map +1 -0
  55. package/dist/agents/codemie-code/tokenUtils.js +220 -0
  56. package/dist/agents/codemie-code/tokenUtils.js.map +1 -0
  57. package/dist/agents/codemie-code/toolMetadata.d.ts +15 -0
  58. package/dist/agents/codemie-code/toolMetadata.d.ts.map +1 -0
  59. package/dist/agents/codemie-code/toolMetadata.js +315 -0
  60. package/dist/agents/codemie-code/toolMetadata.js.map +1 -0
  61. package/dist/agents/codemie-code/tools/command.d.ts +2 -0
  62. package/dist/agents/codemie-code/tools/command.d.ts.map +1 -0
  63. package/dist/agents/codemie-code/tools/command.js +2 -0
  64. package/dist/agents/codemie-code/tools/command.js.map +1 -0
  65. package/dist/agents/codemie-code/tools/filesystem.d.ts +2 -0
  66. package/dist/agents/codemie-code/tools/filesystem.d.ts.map +1 -0
  67. package/dist/agents/codemie-code/tools/filesystem.js +2 -0
  68. package/dist/agents/codemie-code/tools/filesystem.js.map +1 -0
  69. package/dist/agents/codemie-code/tools/git.d.ts +2 -0
  70. package/dist/agents/codemie-code/tools/git.d.ts.map +1 -0
  71. package/dist/agents/codemie-code/tools/git.js +2 -0
  72. package/dist/agents/codemie-code/tools/git.js.map +1 -0
  73. package/dist/agents/codemie-code/tools/index.d.ts +19 -0
  74. package/dist/agents/codemie-code/tools/index.d.ts.map +1 -0
  75. package/dist/agents/codemie-code/tools/index.js +239 -0
  76. package/dist/agents/codemie-code/tools/index.js.map +1 -0
  77. package/dist/agents/codemie-code/tools/security.d.ts +2 -0
  78. package/dist/agents/codemie-code/tools/security.d.ts.map +1 -0
  79. package/dist/agents/codemie-code/tools/security.js +2 -0
  80. package/dist/agents/codemie-code/tools/security.js.map +1 -0
  81. package/dist/agents/codemie-code/types.d.ts +254 -0
  82. package/dist/agents/codemie-code/types.d.ts.map +1 -0
  83. package/dist/agents/codemie-code/types.js +35 -0
  84. package/dist/agents/codemie-code/types.js.map +1 -0
  85. package/dist/agents/codemie-code/ui.d.ts +83 -0
  86. package/dist/agents/codemie-code/ui.d.ts.map +1 -0
  87. package/dist/agents/codemie-code/ui.js +624 -0
  88. package/dist/agents/codemie-code/ui.js.map +1 -0
  89. package/dist/agents/registry.d.ts +1 -1
  90. package/dist/agents/registry.d.ts.map +1 -1
  91. package/dist/agents/registry.js +7 -13
  92. package/dist/agents/registry.js.map +1 -1
  93. package/dist/cli/commands/config.d.ts +3 -0
  94. package/dist/cli/commands/config.d.ts.map +1 -0
  95. package/dist/cli/commands/config.js +323 -0
  96. package/dist/cli/commands/config.js.map +1 -0
  97. package/dist/cli/commands/doctor.d.ts.map +1 -1
  98. package/dist/cli/commands/doctor.js +113 -69
  99. package/dist/cli/commands/doctor.js.map +1 -1
  100. package/dist/cli/commands/env.d.ts +3 -0
  101. package/dist/cli/commands/env.d.ts.map +1 -0
  102. package/dist/cli/commands/env.js +19 -0
  103. package/dist/cli/commands/env.js.map +1 -0
  104. package/dist/cli/commands/install.js +27 -33
  105. package/dist/cli/commands/install.js.map +1 -1
  106. package/dist/cli/commands/list.js +18 -24
  107. package/dist/cli/commands/list.js.map +1 -1
  108. package/dist/cli/commands/run.d.ts.map +1 -1
  109. package/dist/cli/commands/run.js +307 -21
  110. package/dist/cli/commands/run.js.map +1 -1
  111. package/dist/cli/commands/setup.d.ts +3 -0
  112. package/dist/cli/commands/setup.d.ts.map +1 -0
  113. package/dist/cli/commands/setup.js +357 -0
  114. package/dist/cli/commands/setup.js.map +1 -0
  115. package/dist/cli/commands/uninstall.js +24 -30
  116. package/dist/cli/commands/uninstall.js.map +1 -1
  117. package/dist/cli/commands/version.d.ts.map +1 -1
  118. package/dist/cli/commands/version.js +11 -16
  119. package/dist/cli/commands/version.js.map +1 -1
  120. package/dist/cli/index.js +47 -31
  121. package/dist/cli/index.js.map +1 -1
  122. package/dist/env/manager.js +9 -46
  123. package/dist/env/manager.js.map +1 -1
  124. package/dist/index.d.ts +6 -13
  125. package/dist/index.d.ts.map +1 -1
  126. package/dist/index.js +6 -43
  127. package/dist/index.js.map +1 -1
  128. package/dist/utils/async-tips.d.ts.map +1 -1
  129. package/dist/utils/async-tips.js +16 -55
  130. package/dist/utils/async-tips.js.map +1 -1
  131. package/dist/utils/clipboard.d.ts +16 -0
  132. package/dist/utils/clipboard.d.ts.map +1 -0
  133. package/dist/utils/clipboard.js +179 -0
  134. package/dist/utils/clipboard.js.map +1 -0
  135. package/dist/utils/config-loader.d.ts +96 -0
  136. package/dist/utils/config-loader.d.ts.map +1 -0
  137. package/dist/utils/config-loader.js +351 -0
  138. package/dist/utils/config-loader.js.map +1 -0
  139. package/dist/utils/dirname.d.ts +7 -0
  140. package/dist/utils/dirname.d.ts.map +1 -0
  141. package/dist/utils/dirname.js +11 -0
  142. package/dist/utils/dirname.js.map +1 -0
  143. package/dist/utils/errors.js +7 -17
  144. package/dist/utils/errors.js.map +1 -1
  145. package/dist/utils/exec.js +3 -6
  146. package/dist/utils/exec.js.map +1 -1
  147. package/dist/utils/first-time.d.ts +34 -0
  148. package/dist/utils/first-time.d.ts.map +1 -0
  149. package/dist/utils/first-time.js +245 -0
  150. package/dist/utils/first-time.js.map +1 -0
  151. package/dist/utils/health-checker.d.ts +20 -0
  152. package/dist/utils/health-checker.d.ts.map +1 -0
  153. package/dist/utils/health-checker.js +168 -0
  154. package/dist/utils/health-checker.js.map +1 -0
  155. package/dist/utils/logger.js +12 -18
  156. package/dist/utils/logger.js.map +1 -1
  157. package/dist/utils/model-fetcher.d.ts +21 -0
  158. package/dist/utils/model-fetcher.d.ts.map +1 -0
  159. package/dist/utils/model-fetcher.js +137 -0
  160. package/dist/utils/model-fetcher.js.map +1 -0
  161. package/dist/utils/tips.d.ts.map +1 -1
  162. package/dist/utils/tips.js +13 -52
  163. package/dist/utils/tips.js.map +1 -1
  164. package/package.json +17 -23
  165. package/scripts/README.md +80 -0
  166. package/scripts/release.sh +156 -0
  167. package/dist/agents/adapters/aider.d.ts +0 -12
  168. package/dist/agents/adapters/aider.d.ts.map +0 -1
  169. package/dist/agents/adapters/aider.js +0 -80
  170. package/dist/agents/adapters/aider.js.map +0 -1
  171. package/dist/cli/cli.d.ts +0 -4
  172. package/dist/cli/cli.d.ts.map +0 -1
  173. package/dist/cli/cli.js +0 -107
  174. package/dist/cli/cli.js.map +0 -1
  175. package/dist/cli/commands/mcp.d.ts +0 -3
  176. package/dist/cli/commands/mcp.d.ts.map +0 -1
  177. package/dist/cli/commands/mcp.js +0 -459
  178. package/dist/cli/commands/mcp.js.map +0 -1
  179. package/dist/code/agent-events.d.ts +0 -39
  180. package/dist/code/agent-events.d.ts.map +0 -1
  181. package/dist/code/agent-events.js +0 -4
  182. package/dist/code/agent-events.js.map +0 -1
  183. package/dist/code/agent.d.ts +0 -19
  184. package/dist/code/agent.d.ts.map +0 -1
  185. package/dist/code/agent.js +0 -144
  186. package/dist/code/agent.js.map +0 -1
  187. package/dist/code/config.d.ts +0 -13
  188. package/dist/code/config.d.ts.map +0 -1
  189. package/dist/code/config.js +0 -41
  190. package/dist/code/config.js.map +0 -1
  191. package/dist/code/index.d.ts +0 -19
  192. package/dist/code/index.d.ts.map +0 -1
  193. package/dist/code/index.js +0 -400
  194. package/dist/code/index.js.map +0 -1
  195. package/dist/code/prompts.d.ts +0 -2
  196. package/dist/code/prompts.d.ts.map +0 -1
  197. package/dist/code/prompts.js +0 -45
  198. package/dist/code/prompts.js.map +0 -1
  199. package/dist/code/tools/command.d.ts +0 -8
  200. package/dist/code/tools/command.d.ts.map +0 -1
  201. package/dist/code/tools/command.js +0 -83
  202. package/dist/code/tools/command.js.map +0 -1
  203. package/dist/code/tools/diff-utils.d.ts +0 -2
  204. package/dist/code/tools/diff-utils.d.ts.map +0 -1
  205. package/dist/code/tools/diff-utils.js +0 -45
  206. package/dist/code/tools/diff-utils.js.map +0 -1
  207. package/dist/code/tools/filesystem.d.ts +0 -11
  208. package/dist/code/tools/filesystem.d.ts.map +0 -1
  209. package/dist/code/tools/filesystem.js +0 -442
  210. package/dist/code/tools/filesystem.js.map +0 -1
  211. package/dist/code/tools/git.d.ts +0 -7
  212. package/dist/code/tools/git.d.ts.map +0 -1
  213. package/dist/code/tools/git.js +0 -111
  214. package/dist/code/tools/git.js.map +0 -1
  215. package/dist/code/tools/mcp.d.ts +0 -13
  216. package/dist/code/tools/mcp.d.ts.map +0 -1
  217. package/dist/code/tools/mcp.js +0 -230
  218. package/dist/code/tools/mcp.js.map +0 -1
  219. package/dist/data/tips.json +0 -118
  220. package/dist/ui/terminal-ui.d.ts +0 -73
  221. package/dist/ui/terminal-ui.d.ts.map +0 -1
  222. package/dist/ui/terminal-ui.js +0 -900
  223. package/dist/ui/terminal-ui.js.map +0 -1
  224. package/dist/utils/env-mapper.d.ts +0 -40
  225. package/dist/utils/env-mapper.d.ts.map +0 -1
  226. package/dist/utils/env-mapper.js +0 -122
  227. package/dist/utils/env-mapper.js.map +0 -1
  228. package/docs/USER_GUIDE.md +0 -573
  229. package/tests/agent-direct.test.mjs +0 -45
  230. package/tests/agent-output.test.mjs +0 -64
  231. package/tests/codemie-code.test.mjs +0 -42
  232. package/tests/context7-only.test.mjs +0 -42
  233. package/tests/conversation-flow.test.mjs +0 -63
  234. package/tests/interactive-simulation.test.mjs +0 -60
  235. package/tests/live-output.test.mjs +0 -53
  236. package/tests/mcp-context7.test.mjs +0 -105
  237. package/tests/mcp-e2e.test.mjs +0 -109
  238. package/tests/mcp-time-server.test.mjs +0 -58
  239. package/tests/streaming.test.mjs +0 -57
  240. package/tests/test-helpers.mjs +0 -94
  241. package/tests/text-wrapping.test.mjs +0 -33
  242. package/tests/tool-count.test.mjs +0 -81
  243. package/tests/ui-format.test.mjs +0 -39
  244. package/tests/ui-state.test.mjs +0 -72
@@ -0,0 +1,328 @@
1
+ /**
2
+ * Directory and File Filtering System
3
+ *
4
+ * Provides intelligent filtering for directory listings to exclude common
5
+ * directories and files that are typically gitignored or not relevant
6
+ * for code analysis (dependencies, build artifacts, IDE files, etc.)
7
+ */
8
+ /**
9
+ * Default filter patterns organized by category
10
+ */
11
+ export const DEFAULT_IGNORE_PATTERNS = {
12
+ // Version Control
13
+ versionControl: [
14
+ '.git/**',
15
+ '.svn/**',
16
+ '.hg/**',
17
+ '.bzr/**'
18
+ ],
19
+ // Dependencies & Package Managers
20
+ dependencies: [
21
+ 'node_modules/**',
22
+ 'bower_components/**',
23
+ 'vendor/**',
24
+ 'packages/**',
25
+ '.pnpm-store/**',
26
+ '.yarn/**'
27
+ ],
28
+ // Build & Distribution
29
+ buildArtifacts: [
30
+ 'dist/**',
31
+ 'build/**',
32
+ 'out/**',
33
+ 'target/**',
34
+ '.next/**',
35
+ '.nuxt/**',
36
+ '.vuepress/**',
37
+ 'public/build/**',
38
+ '.output/**'
39
+ ],
40
+ // Test Coverage & Reports
41
+ testOutput: [
42
+ 'coverage/**',
43
+ '.nyc_output/**',
44
+ '.pytest_cache/**',
45
+ 'htmlcov/**',
46
+ 'test-results/**',
47
+ '.coverage'
48
+ ],
49
+ // IDE & Editor Files
50
+ ideFiles: [
51
+ '.vscode/**',
52
+ '.idea/**',
53
+ '.eclipse/**',
54
+ '*.swp',
55
+ '*.swo',
56
+ '*~',
57
+ '.*.swp',
58
+ '.*.swo'
59
+ ],
60
+ // OS Files
61
+ osFiles: [
62
+ '.DS_Store',
63
+ 'Thumbs.db',
64
+ 'desktop.ini',
65
+ '*.tmp',
66
+ '*.temp',
67
+ '.Trashes',
68
+ '.fseventsd',
69
+ '.Spotlight-V100',
70
+ '.TemporaryItems'
71
+ ],
72
+ // Cache & Temporary
73
+ cache: [
74
+ '.cache/**',
75
+ '.tmp/**',
76
+ '.temp/**',
77
+ 'tmp/**',
78
+ 'temp/**',
79
+ '.parcel-cache/**',
80
+ '.turbo/**'
81
+ ],
82
+ // Language-Specific Patterns
83
+ python: [
84
+ '__pycache__/**',
85
+ '*.pyc',
86
+ '*.pyo',
87
+ '*.pyd',
88
+ '.Python',
89
+ '*.so',
90
+ '.venv/**',
91
+ 'venv/**',
92
+ 'env/**',
93
+ '.env/**',
94
+ 'virtualenv/**',
95
+ '.virtualenv/**',
96
+ 'myenv/**',
97
+ '.myenv/**',
98
+ '*venv/**', // Matches any directory ending with 'venv'
99
+ '.*venv/**', // Matches any hidden directory ending with 'venv'
100
+ 'pip-log.txt',
101
+ 'pip-delete-this-directory.txt',
102
+ '.pytest_cache/**',
103
+ '.tox/**',
104
+ 'site-packages/**'
105
+ ],
106
+ java: [
107
+ '*.class',
108
+ '*.jar',
109
+ '*.war',
110
+ '*.ear',
111
+ '.gradle/**',
112
+ 'target/**',
113
+ '.mvn/**'
114
+ ],
115
+ javascript: [
116
+ 'node_modules/**',
117
+ '.npm/**',
118
+ '.yarn/**',
119
+ 'yarn-error.log',
120
+ 'npm-debug.log*',
121
+ 'yarn-debug.log*',
122
+ 'lerna-debug.log*'
123
+ ],
124
+ go: [
125
+ 'vendor/**',
126
+ '*.exe',
127
+ '*.test',
128
+ '*.prof'
129
+ ],
130
+ rust: [
131
+ 'target/**',
132
+ 'Cargo.lock'
133
+ ],
134
+ cCpp: [
135
+ '*.o',
136
+ '*.so',
137
+ '*.dll',
138
+ '*.exe',
139
+ '*.out',
140
+ '*.a',
141
+ '*.lib'
142
+ ],
143
+ ruby: [
144
+ '.bundle/**',
145
+ 'vendor/bundle/**',
146
+ '*.gem'
147
+ ],
148
+ dotnet: [
149
+ 'bin/**',
150
+ 'obj/**',
151
+ '*.user',
152
+ '*.suo',
153
+ '*.sln.docstates'
154
+ ]
155
+ };
156
+ /**
157
+ * Compile all default patterns into a single array
158
+ */
159
+ export function getDefaultIgnorePatterns() {
160
+ return Object.values(DEFAULT_IGNORE_PATTERNS).flat();
161
+ }
162
+ /**
163
+ * Simple glob pattern matcher
164
+ * Supports * (any chars), ** (any dirs), and ? (single char)
165
+ */
166
+ export function matchesPattern(filename, pattern, caseSensitive = false) {
167
+ if (!caseSensitive) {
168
+ filename = filename.toLowerCase();
169
+ pattern = pattern.toLowerCase();
170
+ }
171
+ // Handle simple cases first
172
+ if (pattern === filename)
173
+ return true;
174
+ if (pattern === '*')
175
+ return true;
176
+ if (pattern === '**')
177
+ return true;
178
+ // Split pattern into parts for better handling
179
+ const patternParts = pattern.split('/');
180
+ const filenameParts = filename.split('/');
181
+ // Handle directory patterns ending with **
182
+ if (pattern.endsWith('/**')) {
183
+ const baseParts = patternParts.slice(0, -1); // Remove the '**'
184
+ // Match the base directory first
185
+ if (filenameParts.length >= baseParts.length) {
186
+ for (let i = 0; i < baseParts.length; i++) {
187
+ if (!matchesSinglePattern(filenameParts[i], baseParts[i])) {
188
+ return false;
189
+ }
190
+ }
191
+ return true; // Base matches, ** matches the rest
192
+ }
193
+ return false;
194
+ }
195
+ // Handle exact path matching
196
+ if (patternParts.length !== filenameParts.length) {
197
+ return false;
198
+ }
199
+ // Match each part
200
+ for (let i = 0; i < patternParts.length; i++) {
201
+ if (!matchesSinglePattern(filenameParts[i], patternParts[i])) {
202
+ return false;
203
+ }
204
+ }
205
+ return true;
206
+ }
207
+ /**
208
+ * Match a single pattern part (no slashes)
209
+ */
210
+ function matchesSinglePattern(text, pattern) {
211
+ if (pattern === text)
212
+ return true;
213
+ if (pattern === '*')
214
+ return true;
215
+ if (pattern === '**')
216
+ return true;
217
+ // Convert simple glob to regex
218
+ let regexPattern = pattern
219
+ .replace(/\./g, '\\.') // Escape dots
220
+ .replace(/\+/g, '\\+') // Escape plus
221
+ .replace(/\^/g, '\\^') // Escape caret
222
+ .replace(/\$/g, '\\$') // Escape dollar
223
+ .replace(/\(/g, '\\(') // Escape parentheses
224
+ .replace(/\)/g, '\\)')
225
+ .replace(/\[/g, '\\[') // Escape brackets
226
+ .replace(/\]/g, '\\]')
227
+ .replace(/\{/g, '\\{') // Escape braces
228
+ .replace(/\}/g, '\\}')
229
+ .replace(/\*/g, '.*') // * matches anything
230
+ .replace(/\?/g, '.'); // ? matches single char
231
+ try {
232
+ const regex = new RegExp(`^${regexPattern}$`);
233
+ return regex.test(text);
234
+ }
235
+ catch {
236
+ return text === pattern;
237
+ }
238
+ }
239
+ /**
240
+ * Check if a file or directory should be ignored
241
+ */
242
+ export function shouldIgnore(name, isDirectory, config, relativePath) {
243
+ if (!config.enabled) {
244
+ return false;
245
+ }
246
+ // Full path for matching (use name if no relative path provided)
247
+ const fullPath = relativePath || name;
248
+ const pathToCheck = isDirectory ? `${fullPath}/` : fullPath;
249
+ // Check force include patterns first
250
+ if (config.forceIncludePatterns) {
251
+ for (const pattern of config.forceIncludePatterns) {
252
+ if (matchesPattern(pathToCheck, pattern, config.caseSensitive)) {
253
+ return false; // Force include overrides ignore
254
+ }
255
+ if (matchesPattern(name, pattern, config.caseSensitive)) {
256
+ return false;
257
+ }
258
+ }
259
+ }
260
+ // Get all ignore patterns (default + custom)
261
+ const ignorePatterns = [
262
+ ...getDefaultIgnorePatterns(),
263
+ ...(config.customIgnorePatterns || [])
264
+ ];
265
+ // Check ignore patterns
266
+ for (const pattern of ignorePatterns) {
267
+ if (matchesPattern(pathToCheck, pattern, config.caseSensitive)) {
268
+ return true;
269
+ }
270
+ if (matchesPattern(name, pattern, config.caseSensitive)) {
271
+ return true;
272
+ }
273
+ }
274
+ return false;
275
+ }
276
+ /**
277
+ * Filter an array of directory entries
278
+ */
279
+ export function filterDirectoryEntries(entries, config, basePath = '') {
280
+ if (!config.enabled) {
281
+ return entries;
282
+ }
283
+ return entries.filter(entry => {
284
+ const relativePath = basePath ? `${basePath}/${entry.name}` : entry.name;
285
+ return !shouldIgnore(entry.name, entry.isDirectory, config, relativePath);
286
+ });
287
+ }
288
+ /**
289
+ * Default filter configuration
290
+ */
291
+ export const DEFAULT_FILTER_CONFIG = {
292
+ enabled: true,
293
+ caseSensitive: false,
294
+ customIgnorePatterns: [],
295
+ forceIncludePatterns: []
296
+ };
297
+ /**
298
+ * Create a filter configuration with custom settings
299
+ */
300
+ export function createFilterConfig(overrides = {}) {
301
+ return {
302
+ ...DEFAULT_FILTER_CONFIG,
303
+ ...overrides
304
+ };
305
+ }
306
+ /**
307
+ * Generate filtering statistics
308
+ */
309
+ export function generateFilterStats(originalEntries, filteredEntries, config) {
310
+ const ignoredEntries = originalEntries.filter(entry => !filteredEntries.some(filtered => filtered.name === entry.name));
311
+ const ignoredByCategory = {};
312
+ if (config.enabled) {
313
+ for (const [category, patterns] of Object.entries(DEFAULT_IGNORE_PATTERNS)) {
314
+ ignoredByCategory[category] = ignoredEntries.filter(entry => {
315
+ const pathToCheck = entry.isDirectory ? `${entry.name}/` : entry.name;
316
+ return patterns.some(pattern => matchesPattern(pathToCheck, pattern, config.caseSensitive) ||
317
+ matchesPattern(entry.name, pattern, config.caseSensitive));
318
+ }).length;
319
+ }
320
+ }
321
+ return {
322
+ totalEntries: originalEntries.length,
323
+ filteredEntries: filteredEntries.length,
324
+ ignoredEntries: ignoredEntries.length,
325
+ ignoredByCategory
326
+ };
327
+ }
328
+ //# sourceMappingURL=filters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../src/agents/codemie-code/filters.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmBH;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,kBAAkB;IAClB,cAAc,EAAE;QACd,SAAS;QACT,SAAS;QACT,QAAQ;QACR,SAAS;KACV;IAED,kCAAkC;IAClC,YAAY,EAAE;QACZ,iBAAiB;QACjB,qBAAqB;QACrB,WAAW;QACX,aAAa;QACb,gBAAgB;QAChB,UAAU;KACX;IAED,uBAAuB;IACvB,cAAc,EAAE;QACd,SAAS;QACT,UAAU;QACV,QAAQ;QACR,WAAW;QACX,UAAU;QACV,UAAU;QACV,cAAc;QACd,iBAAiB;QACjB,YAAY;KACb;IAED,0BAA0B;IAC1B,UAAU,EAAE;QACV,aAAa;QACb,gBAAgB;QAChB,kBAAkB;QAClB,YAAY;QACZ,iBAAiB;QACjB,WAAW;KACZ;IAED,qBAAqB;IACrB,QAAQ,EAAE;QACR,YAAY;QACZ,UAAU;QACV,aAAa;QACb,OAAO;QACP,OAAO;QACP,IAAI;QACJ,QAAQ;QACR,QAAQ;KACT;IAED,WAAW;IACX,OAAO,EAAE;QACP,WAAW;QACX,WAAW;QACX,aAAa;QACb,OAAO;QACP,QAAQ;QACR,UAAU;QACV,YAAY;QACZ,iBAAiB;QACjB,iBAAiB;KAClB;IAED,oBAAoB;IACpB,KAAK,EAAE;QACL,WAAW;QACX,SAAS;QACT,UAAU;QACV,QAAQ;QACR,SAAS;QACT,kBAAkB;QAClB,WAAW;KACZ;IAED,6BAA6B;IAC7B,MAAM,EAAE;QACN,gBAAgB;QAChB,OAAO;QACP,OAAO;QACP,OAAO;QACP,SAAS;QACT,MAAM;QACN,UAAU;QACV,SAAS;QACT,QAAQ;QACR,SAAS;QACT,eAAe;QACf,gBAAgB;QAChB,UAAU;QACV,WAAW;QACX,UAAU,EAAU,2CAA2C;Q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I,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;gBACtE,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAC7B,cAAc,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;oBAC1D,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC,CAC1D,CAAC;YACJ,CAAC,CAAC,CAAC,MAAM,CAAC;QACZ,CAAC;IACH,CAAC;IAED,OAAO;QACL,YAAY,EAAE,eAAe,CAAC,MAAM;QACpC,eAAe,EAAE,eAAe,CAAC,MAAM;QACvC,cAAc,EAAE,cAAc,CAAC,MAAM;QACrC,iBAAiB;KAClB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * CodeMie Native Agent - Main Entry Point
3
+ *
4
+ * Orchestrates the entire CodeMie native agent including initialization,
5
+ * tool loading, and interactive/non-interactive execution modes.
6
+ */
7
+ import type { CodeMieConfig, InitializationResult, AgentStats } from './types.js';
8
+ export declare class CodeMieCode {
9
+ private agent;
10
+ private config;
11
+ private initializationResult;
12
+ constructor(workingDir?: string);
13
+ private workingDirectory;
14
+ /**
15
+ * Initialize the CodeMie agent asynchronously
16
+ */
17
+ initialize(): Promise<InitializationResult>;
18
+ /**
19
+ * Start interactive mode with modern terminal UI
20
+ */
21
+ startInteractive(): Promise<void>;
22
+ /**
23
+ * Execute a single task (non-interactive mode)
24
+ */
25
+ executeTask(task: string): Promise<string>;
26
+ /**
27
+ * Execute a single task with modern UI feedback (for CLI usage)
28
+ */
29
+ executeTaskWithUI(task: string): Promise<string>;
30
+ /**
31
+ * Stream a task with event callbacks (for programmatic use)
32
+ */
33
+ streamTask(task: string, onEvent: (event: any) => void): Promise<void>;
34
+ /**
35
+ * Get agent statistics
36
+ */
37
+ getStats(): AgentStats | null;
38
+ /**
39
+ * Get initialization result
40
+ */
41
+ getInitializationResult(): InitializationResult | null;
42
+ /**
43
+ * Get agent configuration (sanitized)
44
+ */
45
+ getConfig(): CodeMieConfig | null;
46
+ /**
47
+ * Clear conversation history
48
+ */
49
+ clearHistory(): void;
50
+ /**
51
+ * Health check for the entire system
52
+ */
53
+ healthCheck(): Promise<{
54
+ status: 'healthy' | 'unhealthy';
55
+ initialized: boolean;
56
+ config: any;
57
+ agent?: any;
58
+ error?: string;
59
+ }>;
60
+ /**
61
+ * Dispose of resources
62
+ */
63
+ dispose(): Promise<void>;
64
+ /**
65
+ * Static method to test connection and configuration
66
+ */
67
+ static testConnection(workingDir?: string): Promise<{
68
+ success: boolean;
69
+ provider?: string;
70
+ model?: string;
71
+ error?: string;
72
+ }>;
73
+ }
74
+ export type { CodeMieConfig, AgentEvent, EventCallback, AgentStats, TokenUsage, ExecutionStep } from './types.js';
75
+ export { loadCodeMieConfig, getConfigSummary } from './config.js';
76
+ export { CodeMieAgent } from './agent.js';
77
+ export { formatCost, formatTokens, formatTokenUsageSummary, calculateCost } from './tokenUtils.js';
78
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/codemie-code/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAIlF,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,oBAAoB,CAAqC;gBAErD,UAAU,CAAC,EAAE,MAAM;IAQ/B,OAAO,CAAC,gBAAgB,CAAS;IAEjC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAqDjD;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBvC;;OAEG;IACG,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CA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@ -0,0 +1,259 @@
1
+ /**
2
+ * CodeMie Native Agent - Main Entry Point
3
+ *
4
+ * Orchestrates the entire CodeMie native agent including initialization,
5
+ * tool loading, and interactive/non-interactive execution modes.
6
+ */
7
+ import { CodeMieAgent } from './agent.js';
8
+ import { loadCodeMieConfig, getConfigSummary } from './config.js';
9
+ import { createSystemTools } from './tools/index.js';
10
+ import { CodeMieAgentError } from './types.js';
11
+ import { hasClipboardImage, getClipboardImage } from '../../utils/clipboard.js';
12
+ export class CodeMieCode {
13
+ agent = null;
14
+ config;
15
+ initializationResult = null;
16
+ constructor(workingDir) {
17
+ // Load configuration first - this may throw if config is invalid
18
+ this.config = {}; // Temporary placeholder
19
+ // Actual loading happens in initialize() to handle async operations
20
+ this.workingDirectory = workingDir || process.cwd();
21
+ }
22
+ workingDirectory;
23
+ /**
24
+ * Initialize the CodeMie agent asynchronously
25
+ */
26
+ async initialize() {
27
+ try {
28
+ // Load configuration
29
+ this.config = await loadCodeMieConfig(this.workingDirectory);
30
+ if (this.config.debug) {
31
+ console.log('[DEBUG] Configuration loaded:', getConfigSummary(this.config));
32
+ }
33
+ // Create system tools
34
+ const tools = await createSystemTools(this.config);
35
+ if (this.config.debug) {
36
+ console.log(`[DEBUG] Created ${tools.length} system tools`);
37
+ }
38
+ // Initialize the agent
39
+ this.agent = new CodeMieAgent(this.config, tools);
40
+ this.initializationResult = {
41
+ success: true,
42
+ toolCount: tools.length,
43
+ duration: 0
44
+ };
45
+ if (this.config.debug) {
46
+ console.log('[DEBUG] Agent initialized successfully');
47
+ }
48
+ return this.initializationResult;
49
+ }
50
+ catch (error) {
51
+ const errorMessage = error instanceof Error ? error.message : String(error);
52
+ this.initializationResult = {
53
+ success: false,
54
+ toolCount: 0,
55
+ duration: 0,
56
+ error: errorMessage
57
+ };
58
+ if (this.config.debug) {
59
+ console.error('[DEBUG] Initialization failed:', error);
60
+ }
61
+ throw new CodeMieAgentError(`Failed to initialize CodeMie agent: ${errorMessage}`, 'INITIALIZATION_ERROR', { workingDirectory: this.workingDirectory, originalError: error });
62
+ }
63
+ }
64
+ /**
65
+ * Start interactive mode with modern terminal UI
66
+ */
67
+ async startInteractive() {
68
+ if (!this.agent) {
69
+ throw new CodeMieAgentError('Agent not initialized. Call initialize() first.', 'NOT_INITIALIZED');
70
+ }
71
+ // Use modern Clack-based terminal UI
72
+ const { CodeMieTerminalUI } = await import('./ui.js');
73
+ const ui = new CodeMieTerminalUI(this.agent);
74
+ try {
75
+ await ui.startInteractive();
76
+ }
77
+ finally {
78
+ ui.dispose();
79
+ }
80
+ }
81
+ /**
82
+ * Execute a single task (non-interactive mode)
83
+ */
84
+ async executeTask(task) {
85
+ if (!this.agent) {
86
+ throw new CodeMieAgentError('Agent not initialized. Call initialize() first.', 'NOT_INITIALIZED');
87
+ }
88
+ try {
89
+ if (this.config.debug) {
90
+ console.log(`[DEBUG] Executing task: ${task.substring(0, 100)}...`);
91
+ }
92
+ let result = '';
93
+ await this.agent.chatStream(task, (event) => {
94
+ if (event.type === 'content_chunk') {
95
+ result += event.content || '';
96
+ }
97
+ });
98
+ return result;
99
+ }
100
+ catch (error) {
101
+ const errorMessage = error instanceof Error ? error.message : String(error);
102
+ if (this.config.debug) {
103
+ console.error('[DEBUG] Task execution failed:', error);
104
+ }
105
+ throw new CodeMieAgentError(`Task execution failed: ${errorMessage}`, 'TASK_EXECUTION_ERROR', { task, originalError: error });
106
+ }
107
+ }
108
+ /**
109
+ * Execute a single task with modern UI feedback (for CLI usage)
110
+ */
111
+ async executeTaskWithUI(task) {
112
+ if (!this.agent) {
113
+ throw new CodeMieAgentError('Agent not initialized. Call initialize() first.', 'NOT_INITIALIZED');
114
+ }
115
+ // Use modern Clack-based terminal UI for single task
116
+ const { CodeMieTerminalUI } = await import('./ui.js');
117
+ const ui = new CodeMieTerminalUI(this.agent);
118
+ try {
119
+ // Check for clipboard image
120
+ let clipboardImage;
121
+ if (await hasClipboardImage()) {
122
+ clipboardImage = await getClipboardImage() || undefined;
123
+ }
124
+ ui.showTaskWelcome(task);
125
+ const result = await ui.executeSingleTask(task, clipboardImage ? [clipboardImage] : []);
126
+ ui.showTaskComplete();
127
+ return result;
128
+ }
129
+ catch (error) {
130
+ const errorMessage = error instanceof Error ? error.message : String(error);
131
+ ui.showError(errorMessage);
132
+ throw error;
133
+ }
134
+ finally {
135
+ ui.dispose();
136
+ }
137
+ }
138
+ /**
139
+ * Stream a task with event callbacks (for programmatic use)
140
+ */
141
+ async streamTask(task, onEvent) {
142
+ if (!this.agent) {
143
+ throw new CodeMieAgentError('Agent not initialized. Call initialize() first.', 'NOT_INITIALIZED');
144
+ }
145
+ try {
146
+ await this.agent.chatStream(task, onEvent);
147
+ }
148
+ catch (error) {
149
+ throw new CodeMieAgentError(`Streaming task failed: ${error instanceof Error ? error.message : String(error)}`, 'STREAM_TASK_ERROR', { task, originalError: error });
150
+ }
151
+ }
152
+ /**
153
+ * Get agent statistics
154
+ */
155
+ getStats() {
156
+ return this.agent?.getStats() || null;
157
+ }
158
+ /**
159
+ * Get initialization result
160
+ */
161
+ getInitializationResult() {
162
+ return this.initializationResult;
163
+ }
164
+ /**
165
+ * Get agent configuration (sanitized)
166
+ */
167
+ getConfig() {
168
+ return this.agent?.getConfig() || null;
169
+ }
170
+ /**
171
+ * Clear conversation history
172
+ */
173
+ clearHistory() {
174
+ if (this.agent) {
175
+ this.agent.clearHistory();
176
+ }
177
+ }
178
+ /**
179
+ * Health check for the entire system
180
+ */
181
+ async healthCheck() {
182
+ try {
183
+ const configStatus = {
184
+ valid: !!this.config,
185
+ provider: this.config?.provider,
186
+ model: this.config?.model,
187
+ workingDirectory: this.config?.workingDirectory
188
+ };
189
+ if (!this.agent) {
190
+ return {
191
+ status: 'unhealthy',
192
+ initialized: false,
193
+ config: configStatus,
194
+ error: 'Agent not initialized'
195
+ };
196
+ }
197
+ const agentStats = this.agent.getStats();
198
+ const agentConfig = this.agent.getConfig();
199
+ return {
200
+ status: 'healthy',
201
+ initialized: true,
202
+ config: configStatus,
203
+ agent: {
204
+ stats: agentStats,
205
+ config: agentConfig ? {
206
+ provider: agentConfig.provider,
207
+ model: agentConfig.model
208
+ } : null
209
+ }
210
+ };
211
+ }
212
+ catch (error) {
213
+ return {
214
+ status: 'unhealthy',
215
+ initialized: !!this.agent,
216
+ config: { valid: false },
217
+ error: error instanceof Error ? error.message : String(error)
218
+ };
219
+ }
220
+ }
221
+ /**
222
+ * Dispose of resources
223
+ */
224
+ async dispose() {
225
+ // Future: Clean up any resources, close connections, etc.
226
+ if (this.config.debug) {
227
+ console.log('[DEBUG] CodeMie agent disposed');
228
+ }
229
+ }
230
+ /**
231
+ * Static method to test connection and configuration
232
+ */
233
+ static async testConnection(workingDir) {
234
+ try {
235
+ const config = await loadCodeMieConfig(workingDir);
236
+ // Basic validation that we can create an agent
237
+ const codeMie = new CodeMieCode(workingDir);
238
+ codeMie.config = config;
239
+ // Try to initialize (this will test tool creation and agent setup)
240
+ const initResult = await codeMie.initialize();
241
+ await codeMie.dispose();
242
+ return {
243
+ success: initResult.success,
244
+ provider: config.provider,
245
+ model: config.model
246
+ };
247
+ }
248
+ catch (error) {
249
+ return {
250
+ success: false,
251
+ error: error instanceof Error ? error.message : String(error)
252
+ };
253
+ }
254
+ }
255
+ }
256
+ export { loadCodeMieConfig, getConfigSummary } from './config.js';
257
+ export { CodeMieAgent } from './agent.js';
258
+ export { formatCost, formatTokens, formatTokenUsageSummary, calculateCost } from './tokenUtils.js';
259
+ //# sourceMappingURL=index.js.map