cadr-cli 2.0.0 → 2.0.2

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 (153) hide show
  1. package/dist/adr/adr.d.ts +17 -0
  2. package/dist/adr/adr.d.ts.map +1 -0
  3. package/dist/{adr.js → adr/adr.js} +4 -44
  4. package/dist/adr/adr.js.map +1 -0
  5. package/dist/adr/adr.test.d.ts +5 -0
  6. package/dist/{adr.test.d.ts.map → adr/adr.test.d.ts.map} +1 -1
  7. package/dist/{adr.test.js → adr/adr.test.js} +0 -14
  8. package/dist/adr/adr.test.js.map +1 -0
  9. package/dist/adr/index.d.ts +2 -0
  10. package/dist/adr/index.d.ts.map +1 -0
  11. package/dist/adr/index.js +18 -0
  12. package/dist/adr/index.js.map +1 -0
  13. package/dist/analysis/analysis.orchestrator.d.ts +14 -0
  14. package/dist/analysis/analysis.orchestrator.d.ts.map +1 -0
  15. package/dist/analysis/analysis.orchestrator.js +175 -0
  16. package/dist/analysis/analysis.orchestrator.js.map +1 -0
  17. package/dist/analysis/analysis.orchestrator.test.d.ts +2 -0
  18. package/dist/analysis/analysis.orchestrator.test.d.ts.map +1 -0
  19. package/dist/analysis/analysis.orchestrator.test.js +177 -0
  20. package/dist/analysis/analysis.orchestrator.test.js.map +1 -0
  21. package/dist/analysis/strategies/git-strategy.d.ts +22 -0
  22. package/dist/analysis/strategies/git-strategy.d.ts.map +1 -0
  23. package/dist/analysis/strategies/git-strategy.js +114 -0
  24. package/dist/analysis/strategies/git-strategy.js.map +1 -0
  25. package/dist/analysis/strategies/git-strategy.test.d.ts +2 -0
  26. package/dist/analysis/strategies/git-strategy.test.d.ts.map +1 -0
  27. package/dist/analysis/strategies/git-strategy.test.js +147 -0
  28. package/dist/analysis/strategies/git-strategy.test.js.map +1 -0
  29. package/dist/commands/analyze.js +3 -3
  30. package/dist/commands/analyze.js.map +1 -1
  31. package/dist/commands/analyze.test.d.ts +2 -0
  32. package/dist/commands/analyze.test.d.ts.map +1 -0
  33. package/dist/commands/analyze.test.js +70 -0
  34. package/dist/commands/analyze.test.js.map +1 -0
  35. package/dist/commands/init.test.js +128 -2
  36. package/dist/commands/init.test.js.map +1 -1
  37. package/dist/config.test.js +167 -0
  38. package/dist/config.test.js.map +1 -1
  39. package/dist/git/git.errors.d.ts +6 -0
  40. package/dist/git/git.errors.d.ts.map +1 -0
  41. package/dist/git/git.errors.js +15 -0
  42. package/dist/git/git.errors.js.map +1 -0
  43. package/dist/git/git.errors.test.d.ts +2 -0
  44. package/dist/git/git.errors.test.d.ts.map +1 -0
  45. package/dist/git/git.errors.test.js +34 -0
  46. package/dist/git/git.errors.test.js.map +1 -0
  47. package/dist/git/git.operations.d.ts +12 -0
  48. package/dist/git/git.operations.d.ts.map +1 -0
  49. package/dist/git/git.operations.js +64 -0
  50. package/dist/git/git.operations.js.map +1 -0
  51. package/dist/git/git.operations.test.d.ts +2 -0
  52. package/dist/git/git.operations.test.d.ts.map +1 -0
  53. package/dist/git/git.operations.test.js +164 -0
  54. package/dist/git/git.operations.test.js.map +1 -0
  55. package/dist/git/index.d.ts +4 -0
  56. package/dist/git/index.d.ts.map +1 -0
  57. package/dist/git/index.js +19 -0
  58. package/dist/git/index.js.map +1 -0
  59. package/dist/llm/index.d.ts +3 -0
  60. package/dist/llm/index.d.ts.map +1 -0
  61. package/dist/llm/index.js +19 -0
  62. package/dist/llm/index.js.map +1 -0
  63. package/dist/llm/llm.d.ts +35 -0
  64. package/dist/llm/llm.d.ts.map +1 -0
  65. package/dist/{llm.js → llm/llm.js} +16 -58
  66. package/dist/llm/llm.js.map +1 -0
  67. package/dist/{llm.test.d.ts.map → llm/llm.test.d.ts.map} +1 -1
  68. package/dist/llm/llm.test.js +224 -0
  69. package/dist/llm/llm.test.js.map +1 -0
  70. package/dist/{prompts.d.ts → llm/prompts.d.ts} +1 -38
  71. package/dist/llm/prompts.d.ts.map +1 -0
  72. package/dist/{prompts.js → llm/prompts.js} +9 -54
  73. package/dist/llm/prompts.js.map +1 -0
  74. package/dist/llm/response-parser.d.ts +9 -0
  75. package/dist/llm/response-parser.d.ts.map +1 -0
  76. package/dist/llm/response-parser.js +67 -0
  77. package/dist/llm/response-parser.js.map +1 -0
  78. package/dist/llm/response-parser.test.d.ts +2 -0
  79. package/dist/llm/response-parser.test.d.ts.map +1 -0
  80. package/dist/llm/response-parser.test.js +134 -0
  81. package/dist/llm/response-parser.test.js.map +1 -0
  82. package/dist/presenters/console-presenter.d.ts +35 -0
  83. package/dist/presenters/console-presenter.d.ts.map +1 -0
  84. package/dist/presenters/console-presenter.js +114 -0
  85. package/dist/presenters/console-presenter.js.map +1 -0
  86. package/dist/presenters/console-presenter.test.d.ts +2 -0
  87. package/dist/presenters/console-presenter.test.d.ts.map +1 -0
  88. package/dist/presenters/console-presenter.test.js +227 -0
  89. package/dist/presenters/console-presenter.test.js.map +1 -0
  90. package/dist/version.test.d.ts +1 -2
  91. package/dist/version.test.d.ts.map +1 -1
  92. package/dist/version.test.js +29 -16
  93. package/dist/version.test.js.map +1 -1
  94. package/package.json +1 -1
  95. package/src/{adr.test.ts → adr/adr.test.ts} +10 -23
  96. package/src/{adr.ts → adr/adr.ts} +7 -48
  97. package/src/adr/index.ts +1 -0
  98. package/src/analysis/analysis.orchestrator.test.ts +237 -0
  99. package/src/analysis/analysis.orchestrator.ts +175 -0
  100. package/src/analysis/strategies/git-strategy.test.ts +210 -0
  101. package/src/analysis/strategies/git-strategy.ts +106 -0
  102. package/src/commands/analyze.test.ts +91 -0
  103. package/src/commands/analyze.ts +8 -9
  104. package/src/commands/init.test.ts +200 -5
  105. package/src/config.test.ts +232 -2
  106. package/src/git/git.errors.test.ts +43 -0
  107. package/src/git/git.errors.ts +10 -0
  108. package/src/git/git.operations.test.ts +222 -0
  109. package/src/git/git.operations.ts +85 -0
  110. package/src/git/index.ts +3 -0
  111. package/src/llm/index.ts +2 -0
  112. package/src/llm/llm.test.ts +315 -0
  113. package/src/{llm.ts → llm/llm.ts} +46 -107
  114. package/src/{prompts.ts → llm/prompts.ts} +30 -72
  115. package/src/llm/response-parser.test.ts +170 -0
  116. package/src/llm/response-parser.ts +90 -0
  117. package/src/presenters/console-presenter.test.ts +259 -0
  118. package/src/presenters/console-presenter.ts +152 -0
  119. package/src/version.test.ts +30 -16
  120. package/dist/adr.d.ts +0 -50
  121. package/dist/adr.d.ts.map +0 -1
  122. package/dist/adr.js.map +0 -1
  123. package/dist/adr.test.d.ts +0 -8
  124. package/dist/adr.test.js.map +0 -1
  125. package/dist/analysis.d.ts +0 -24
  126. package/dist/analysis.d.ts.map +0 -1
  127. package/dist/analysis.js +0 -281
  128. package/dist/analysis.js.map +0 -1
  129. package/dist/analysis.test.d.ts +0 -8
  130. package/dist/analysis.test.d.ts.map +0 -1
  131. package/dist/analysis.test.js +0 -351
  132. package/dist/analysis.test.js.map +0 -1
  133. package/dist/git.d.ts +0 -54
  134. package/dist/git.d.ts.map +0 -1
  135. package/dist/git.js +0 -204
  136. package/dist/git.js.map +0 -1
  137. package/dist/llm.d.ts +0 -73
  138. package/dist/llm.d.ts.map +0 -1
  139. package/dist/llm.js.map +0 -1
  140. package/dist/llm.test.js +0 -592
  141. package/dist/llm.test.js.map +0 -1
  142. package/dist/prompts.d.ts.map +0 -1
  143. package/dist/prompts.js.map +0 -1
  144. package/dist/prompts.test.d.ts +0 -2
  145. package/dist/prompts.test.d.ts.map +0 -1
  146. package/dist/prompts.test.js +0 -427
  147. package/dist/prompts.test.js.map +0 -1
  148. package/src/analysis.test.ts +0 -396
  149. package/src/analysis.ts +0 -262
  150. package/src/git.ts +0 -300
  151. package/src/llm.test.ts +0 -701
  152. package/src/prompts.test.ts +0 -515
  153. /package/dist/{llm.test.d.ts → llm/llm.test.d.ts} +0 -0
package/src/git.ts DELETED
@@ -1,300 +0,0 @@
1
- import { exec } from 'child_process';
2
- import { promisify } from 'util';
3
-
4
- const execAsync = promisify(exec);
5
-
6
- export class GitError extends Error {
7
- constructor(
8
- message: string,
9
- public readonly code: 'NOT_GIT_REPO' | 'GIT_NOT_FOUND' | 'GIT_ERROR',
10
- public readonly originalError?: Error
11
- ) {
12
- super(message);
13
- this.name = 'GitError';
14
- }
15
- }
16
-
17
- /**
18
- * Options for specifying what diff to analyze
19
- */
20
- export interface DiffOptions {
21
- mode: 'staged' | 'all' | 'branch-diff';
22
- base?: string; // For branch-diff: base git reference (e.g., 'origin/main')
23
- head?: string; // For branch-diff: head git reference (e.g., 'HEAD')
24
- }
25
-
26
- /**
27
- * Retrieves the list of staged files in the current Git repository
28
- * @returns Promise<string[]> Array of staged file paths
29
- * @throws GitError When Git is not available or repository is invalid
30
- */
31
- export async function getStagedFiles(): Promise<string[]> {
32
- try {
33
- const { stdout } = await execAsync('git diff --cached --name-only');
34
-
35
- // Split by newlines and filter out empty strings
36
- const stagedFiles = stdout
37
- .split('\n')
38
- .map(file => file.trim())
39
- .filter(file => file.length > 0);
40
-
41
- return stagedFiles;
42
- } catch (error: unknown) {
43
- // Handle different Git error scenarios
44
- const errorWithCode = error as { code?: number };
45
-
46
- if (errorWithCode.code === 128) {
47
- throw new GitError(
48
- 'Not in a Git repository. Please run \'cadr\' from within a Git repository.',
49
- 'NOT_GIT_REPO',
50
- error instanceof Error ? error : new Error(String(error))
51
- );
52
- }
53
-
54
- if (errorWithCode.code === 127) {
55
- throw new GitError(
56
- 'Git is not installed. Please install Git and try again.',
57
- 'GIT_NOT_FOUND',
58
- error instanceof Error ? error : new Error(String(error))
59
- );
60
- }
61
-
62
- // Handle other Git errors (permissions, corruption, etc.)
63
- throw new GitError(
64
- 'Unable to read Git repository. Please check repository permissions.',
65
- 'GIT_ERROR',
66
- error instanceof Error ? error : new Error(String(error))
67
- );
68
- }
69
- }
70
-
71
- /**
72
- * Retrieves the full diff content for staged files
73
- * Uses minimal context to reduce token usage
74
- * @returns Promise<string> Full diff content of staged changes
75
- * @throws GitError When Git is not available or repository is invalid
76
- */
77
- export async function getStagedDiff(): Promise<string> {
78
- try {
79
- // Use --unified=1 for minimal context (1 line before/after instead of 3)
80
- // This significantly reduces token usage while maintaining readability
81
- const { stdout } = await execAsync('git diff --cached --unified=1');
82
- return stdout;
83
- } catch (error: unknown) {
84
- // Handle different Git error scenarios (same as getStagedFiles)
85
- const errorWithCode = error as { code?: number };
86
-
87
- if (errorWithCode.code === 128) {
88
- throw new GitError(
89
- 'Not in a Git repository. Please run \'cadr\' from within a Git repository.',
90
- 'NOT_GIT_REPO',
91
- error instanceof Error ? error : new Error(String(error))
92
- );
93
- }
94
-
95
- if (errorWithCode.code === 127) {
96
- throw new GitError(
97
- 'Git is not installed. Please install Git and try again.',
98
- 'GIT_NOT_FOUND',
99
- error instanceof Error ? error : new Error(String(error))
100
- );
101
- }
102
-
103
- // Handle other Git errors (permissions, corruption, etc.)
104
- throw new GitError(
105
- 'Unable to read Git repository. Please check repository permissions.',
106
- 'GIT_ERROR',
107
- error instanceof Error ? error : new Error(String(error))
108
- );
109
- }
110
- }
111
-
112
- /**
113
- * Retrieves the list of all uncommitted files (staged + unstaged) in the current Git repository
114
- * @returns Promise<string[]> Array of uncommitted file paths
115
- * @throws GitError When Git is not available or repository is invalid
116
- */
117
- export async function getUncommittedFiles(): Promise<string[]> {
118
- try {
119
- const { stdout } = await execAsync('git diff HEAD --name-only');
120
-
121
- // Split by newlines and filter out empty strings
122
- const uncommittedFiles = stdout
123
- .split('\n')
124
- .map(file => file.trim())
125
- .filter(file => file.length > 0);
126
-
127
- return uncommittedFiles;
128
- } catch (error: unknown) {
129
- // Handle different Git error scenarios
130
- const errorWithCode = error as { code?: number };
131
-
132
- if (errorWithCode.code === 128) {
133
- throw new GitError(
134
- 'Not in a Git repository. Please run \'cadr\' from within a Git repository.',
135
- 'NOT_GIT_REPO',
136
- error instanceof Error ? error : new Error(String(error))
137
- );
138
- }
139
-
140
- if (errorWithCode.code === 127) {
141
- throw new GitError(
142
- 'Git is not installed. Please install Git and try again.',
143
- 'GIT_NOT_FOUND',
144
- error instanceof Error ? error : new Error(String(error))
145
- );
146
- }
147
-
148
- // Handle other Git errors (permissions, corruption, etc.)
149
- throw new GitError(
150
- 'Unable to read Git repository. Please check repository permissions.',
151
- 'GIT_ERROR',
152
- error instanceof Error ? error : new Error(String(error))
153
- );
154
- }
155
- }
156
-
157
- /**
158
- * Retrieves the full diff content for all uncommitted files (staged + unstaged)
159
- * Uses minimal context to reduce token usage
160
- * @returns Promise<string> Full diff content of uncommitted changes
161
- * @throws GitError When Git is not available or repository is invalid
162
- */
163
- export async function getUncommittedDiff(): Promise<string> {
164
- try {
165
- // Use --unified=1 for minimal context (1 line before/after instead of 3)
166
- // This significantly reduces token usage while maintaining readability
167
- const { stdout } = await execAsync('git diff HEAD --unified=1');
168
- return stdout;
169
- } catch (error: unknown) {
170
- // Handle different Git error scenarios (same as getUncommittedFiles)
171
- const errorWithCode = error as { code?: number };
172
-
173
- if (errorWithCode.code === 128) {
174
- throw new GitError(
175
- 'Not in a Git repository. Please run \'cadr\' from within a Git repository.',
176
- 'NOT_GIT_REPO',
177
- error instanceof Error ? error : new Error(String(error))
178
- );
179
- }
180
-
181
- if (errorWithCode.code === 127) {
182
- throw new GitError(
183
- 'Git is not installed. Please install Git and try again.',
184
- 'GIT_NOT_FOUND',
185
- error instanceof Error ? error : new Error(String(error))
186
- );
187
- }
188
-
189
- // Handle other Git errors (permissions, corruption, etc.)
190
- throw new GitError(
191
- 'Unable to read Git repository. Please check repository permissions.',
192
- 'GIT_ERROR',
193
- error instanceof Error ? error : new Error(String(error))
194
- );
195
- }
196
- }
197
-
198
- /**
199
- * Generic function to get changed files based on diff options
200
- * @param options - Diff options specifying which changes to analyze
201
- * @returns Promise<string[]> Array of changed file paths
202
- * @throws GitError When Git is not available or repository is invalid
203
- */
204
- export async function getChangedFiles(options: DiffOptions = { mode: 'all' }): Promise<string[]> {
205
- switch (options.mode) {
206
- case 'staged':
207
- return getStagedFiles();
208
- case 'all':
209
- return getUncommittedFiles();
210
- case 'branch-diff': {
211
- const base = options.base || 'origin/main';
212
- const head = options.head || 'HEAD';
213
- try {
214
- // Use triple-dot syntax for merge-base diff (standard in CI/CD)
215
- const { stdout } = await execAsync(`git diff ${base}...${head} --name-only`);
216
-
217
- const files = stdout
218
- .split('\n')
219
- .map(file => file.trim())
220
- .filter(file => file.length > 0);
221
-
222
- return files;
223
- } catch (error: unknown) {
224
- // Handle different Git error scenarios
225
- const errorWithCode = error as { code?: number };
226
-
227
- if (errorWithCode.code === 128) {
228
- throw new GitError(
229
- `Invalid git references: ${base}...${head}. Please ensure both references exist.`,
230
- 'GIT_ERROR',
231
- error instanceof Error ? error : new Error(String(error))
232
- );
233
- }
234
-
235
- if (errorWithCode.code === 127) {
236
- throw new GitError(
237
- 'Git is not installed. Please install Git and try again.',
238
- 'GIT_NOT_FOUND',
239
- error instanceof Error ? error : new Error(String(error))
240
- );
241
- }
242
-
243
- throw new GitError(
244
- 'Unable to read Git repository. Please check repository permissions.',
245
- 'GIT_ERROR',
246
- error instanceof Error ? error : new Error(String(error))
247
- );
248
- }
249
- }
250
- }
251
- }
252
-
253
- /**
254
- * Generic function to get diff content based on diff options
255
- * @param options - Diff options specifying which changes to analyze
256
- * @returns Promise<string> Full diff content
257
- * @throws GitError When Git is not available or repository is invalid
258
- */
259
- export async function getDiff(options: DiffOptions = { mode: 'all' }): Promise<string> {
260
- switch (options.mode) {
261
- case 'staged':
262
- return getStagedDiff();
263
- case 'all':
264
- return getUncommittedDiff();
265
- case 'branch-diff': {
266
- const base = options.base || 'origin/main';
267
- const head = options.head || 'HEAD';
268
- try {
269
- // Use triple-dot syntax for merge-base diff with minimal context
270
- const { stdout } = await execAsync(`git diff ${base}...${head} --unified=1`);
271
- return stdout;
272
- } catch (error: unknown) {
273
- // Handle different Git error scenarios
274
- const errorWithCode = error as { code?: number };
275
-
276
- if (errorWithCode.code === 128) {
277
- throw new GitError(
278
- `Invalid git references: ${base}...${head}. Please ensure both references exist.`,
279
- 'GIT_ERROR',
280
- error instanceof Error ? error : new Error(String(error))
281
- );
282
- }
283
-
284
- if (errorWithCode.code === 127) {
285
- throw new GitError(
286
- 'Git is not installed. Please install Git and try again.',
287
- 'GIT_NOT_FOUND',
288
- error instanceof Error ? error : new Error(String(error))
289
- );
290
- }
291
-
292
- throw new GitError(
293
- 'Unable to read Git repository. Please check repository permissions.',
294
- 'GIT_ERROR',
295
- error instanceof Error ? error : new Error(String(error))
296
- );
297
- }
298
- }
299
- }
300
- }