cadr-cli 1.10.0 → 2.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.
- package/dist/adr/adr.d.ts +17 -0
- package/dist/adr/adr.d.ts.map +1 -0
- package/dist/{adr.js → adr/adr.js} +4 -44
- package/dist/adr/adr.js.map +1 -0
- package/dist/adr/adr.test.d.ts +5 -0
- package/dist/{adr.test.d.ts.map → adr/adr.test.d.ts.map} +1 -1
- package/dist/{adr.test.js → adr/adr.test.js} +0 -14
- package/dist/adr/adr.test.js.map +1 -0
- package/dist/adr/index.d.ts +2 -0
- package/dist/adr/index.d.ts.map +1 -0
- package/dist/adr/index.js +18 -0
- package/dist/adr/index.js.map +1 -0
- package/dist/analysis/analysis.orchestrator.d.ts +14 -0
- package/dist/analysis/analysis.orchestrator.d.ts.map +1 -0
- package/dist/analysis/analysis.orchestrator.js +175 -0
- package/dist/analysis/analysis.orchestrator.js.map +1 -0
- package/dist/analysis/strategies/git-strategy.d.ts +22 -0
- package/dist/analysis/strategies/git-strategy.d.ts.map +1 -0
- package/dist/analysis/strategies/git-strategy.js +114 -0
- package/dist/analysis/strategies/git-strategy.js.map +1 -0
- package/dist/commands/analyze.js +3 -3
- package/dist/commands/analyze.js.map +1 -1
- package/dist/commands/status.d.ts +11 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +69 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/status.test.d.ts +2 -0
- package/dist/commands/status.test.d.ts.map +1 -0
- package/dist/commands/status.test.js +83 -0
- package/dist/commands/status.test.js.map +1 -0
- package/dist/git/git.errors.d.ts +6 -0
- package/dist/git/git.errors.d.ts.map +1 -0
- package/dist/git/git.errors.js +15 -0
- package/dist/git/git.errors.js.map +1 -0
- package/dist/git/git.operations.d.ts +12 -0
- package/dist/git/git.operations.d.ts.map +1 -0
- package/dist/git/git.operations.js +64 -0
- package/dist/git/git.operations.js.map +1 -0
- package/dist/git/index.d.ts +4 -0
- package/dist/git/index.d.ts.map +1 -0
- package/dist/git/index.js +19 -0
- package/dist/git/index.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/index.d.ts +3 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +19 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/llm.d.ts +35 -0
- package/dist/llm/llm.d.ts.map +1 -0
- package/dist/{llm.js → llm/llm.js} +16 -58
- package/dist/llm/llm.js.map +1 -0
- package/dist/{prompts.d.ts → llm/prompts.d.ts} +1 -38
- package/dist/llm/prompts.d.ts.map +1 -0
- package/dist/{prompts.js → llm/prompts.js} +9 -54
- package/dist/llm/prompts.js.map +1 -0
- package/dist/llm/response-parser.d.ts +9 -0
- package/dist/llm/response-parser.d.ts.map +1 -0
- package/dist/llm/response-parser.js +67 -0
- package/dist/llm/response-parser.js.map +1 -0
- package/dist/presenters/console-presenter.d.ts +35 -0
- package/dist/presenters/console-presenter.d.ts.map +1 -0
- package/dist/presenters/console-presenter.js +114 -0
- package/dist/presenters/console-presenter.js.map +1 -0
- package/package.json +1 -1
- package/src/{adr.test.ts → adr/adr.test.ts} +10 -23
- package/src/{adr.ts → adr/adr.ts} +7 -48
- package/src/adr/index.ts +1 -0
- package/src/analysis/analysis.orchestrator.ts +175 -0
- package/src/analysis/strategies/git-strategy.ts +106 -0
- package/src/commands/analyze.ts +8 -9
- package/src/commands/status.test.ts +64 -0
- package/src/commands/status.ts +71 -0
- package/src/git/git.errors.ts +10 -0
- package/src/git/git.operations.ts +85 -0
- package/src/git/index.ts +3 -0
- package/src/index.ts +6 -0
- package/src/llm/index.ts +2 -0
- package/src/{llm.ts → llm/llm.ts} +46 -107
- package/src/{prompts.ts → llm/prompts.ts} +30 -72
- package/src/llm/response-parser.ts +90 -0
- package/src/presenters/console-presenter.ts +152 -0
- package/dist/adr.d.ts +0 -50
- package/dist/adr.d.ts.map +0 -1
- package/dist/adr.js.map +0 -1
- package/dist/adr.test.d.ts +0 -8
- package/dist/adr.test.js.map +0 -1
- package/dist/analysis.d.ts +0 -24
- package/dist/analysis.d.ts.map +0 -1
- package/dist/analysis.js +0 -281
- package/dist/analysis.js.map +0 -1
- package/dist/analysis.test.d.ts +0 -8
- package/dist/analysis.test.d.ts.map +0 -1
- package/dist/analysis.test.js +0 -351
- package/dist/analysis.test.js.map +0 -1
- package/dist/git.d.ts +0 -54
- package/dist/git.d.ts.map +0 -1
- package/dist/git.js +0 -204
- package/dist/git.js.map +0 -1
- package/dist/llm.d.ts +0 -73
- package/dist/llm.d.ts.map +0 -1
- package/dist/llm.js.map +0 -1
- package/dist/llm.test.d.ts +0 -2
- package/dist/llm.test.d.ts.map +0 -1
- package/dist/llm.test.js +0 -592
- package/dist/llm.test.js.map +0 -1
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js.map +0 -1
- package/dist/prompts.test.d.ts +0 -2
- package/dist/prompts.test.d.ts.map +0 -1
- package/dist/prompts.test.js +0 -427
- package/dist/prompts.test.js.map +0 -1
- package/src/analysis.test.ts +0 -396
- package/src/analysis.ts +0 -262
- package/src/git.ts +0 -300
- package/src/llm.test.ts +0 -701
- package/src/prompts.test.ts +0 -515
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-presenter.js","sourceRoot":"","sources":["../../src/presenters/console-presenter.ts"],"names":[],"mappings":";;;AAiBA,MAAa,gBAAgB;IAC3B,eAAe;QACb,OAAO,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACzC,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC1D,OAAO,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC1E,CAAC;IAED,YAAY,CAAC,OAAe;QAC1B,OAAO,CAAC,KAAK,CAAC,kBAAkB,OAAO,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,kBAAkB;QAChB,OAAO,CAAC,KAAK,CA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CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAC/D,CAAC;IAED,gBAAgB,CAAC,KAAc;QAC7B,OAAO,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QACxC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,wBAAwB,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,sBAAsB;QACpB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;IACnF,CAAC;IAED,mBAAmB;QACjB,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAClD,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC7D,CAAC;CACF;AApID,4CAoIC;AAEY,QAAA,SAAS,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ADR File Management Module Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests for ADR file creation, numbering, and management.
|
|
5
|
-
* Following TDD: These tests are written BEFORE implementation.
|
|
6
3
|
*/
|
|
7
4
|
|
|
8
5
|
import * as fs from 'fs';
|
|
@@ -20,14 +17,12 @@ describe('ADR Module', () => {
|
|
|
20
17
|
const testDir = path.join(__dirname, '../test-adrs');
|
|
21
18
|
|
|
22
19
|
beforeEach(() => {
|
|
23
|
-
// Clean up test directory before each test
|
|
24
20
|
if (fs.existsSync(testDir)) {
|
|
25
21
|
fs.rmSync(testDir, { recursive: true, force: true });
|
|
26
22
|
}
|
|
27
23
|
});
|
|
28
24
|
|
|
29
25
|
afterEach(() => {
|
|
30
|
-
// Clean up test directory after each test
|
|
31
26
|
if (fs.existsSync(testDir)) {
|
|
32
27
|
fs.rmSync(testDir, { recursive: true, force: true });
|
|
33
28
|
}
|
|
@@ -187,14 +182,15 @@ describe('ADR Module', () => {
|
|
|
187
182
|
expect(result1.filePath).toContain('0001-first.md');
|
|
188
183
|
expect(result2.filePath).toContain('0002-second.md');
|
|
189
184
|
expect(result3.filePath).toContain('0003-third.md');
|
|
190
|
-
|
|
185
|
+
|
|
191
186
|
expect(fs.existsSync(result1.filePath!)).toBe(true);
|
|
192
187
|
expect(fs.existsSync(result2.filePath!)).toBe(true);
|
|
193
188
|
expect(fs.existsSync(result3.filePath!)).toBe(true);
|
|
194
189
|
});
|
|
195
190
|
|
|
196
191
|
it('saves correct content to file', () => {
|
|
197
|
-
const content =
|
|
192
|
+
const content =
|
|
193
|
+
'# My Decision\n\n* Status: accepted\n* Date: 2025-10-21\n\n## Context\n\nSome context here.';
|
|
198
194
|
const result = saveADR(content, 'My Decision', testDir);
|
|
199
195
|
|
|
200
196
|
const savedContent = fs.readFileSync(result.filePath!, 'utf-8');
|
|
@@ -202,7 +198,6 @@ describe('ADR Module', () => {
|
|
|
202
198
|
});
|
|
203
199
|
|
|
204
200
|
it('uses default directory when not specified', () => {
|
|
205
|
-
// Clean up default directory
|
|
206
201
|
const defaultPath = path.join(process.cwd(), DEFAULT_ADR_DIR);
|
|
207
202
|
if (fs.existsSync(defaultPath)) {
|
|
208
203
|
fs.rmSync(defaultPath, { recursive: true, force: true });
|
|
@@ -213,44 +208,38 @@ describe('ADR Module', () => {
|
|
|
213
208
|
|
|
214
209
|
expect(result.success).toBe(true);
|
|
215
210
|
expect(result.filePath).toContain(DEFAULT_ADR_DIR);
|
|
216
|
-
|
|
217
|
-
// Cleanup
|
|
211
|
+
|
|
218
212
|
if (fs.existsSync(defaultPath)) {
|
|
219
213
|
fs.rmSync(defaultPath, { recursive: true, force: true });
|
|
220
214
|
}
|
|
221
215
|
});
|
|
222
216
|
|
|
223
217
|
it('handles file write errors gracefully', () => {
|
|
224
|
-
// Create a read-only directory to trigger write error
|
|
225
218
|
fs.mkdirSync(testDir, { recursive: true });
|
|
226
|
-
|
|
227
|
-
// Make directory read-only (if not Windows)
|
|
219
|
+
|
|
228
220
|
if (process.platform !== 'win32') {
|
|
229
221
|
fs.chmodSync(testDir, 0o444);
|
|
230
|
-
|
|
222
|
+
|
|
231
223
|
const content = '# Test\n\nContent';
|
|
232
224
|
const result = saveADR(content, 'Test', testDir);
|
|
233
225
|
|
|
234
226
|
expect(result.success).toBe(false);
|
|
235
227
|
expect(result.error).toBeDefined();
|
|
236
228
|
expect(result.filePath).toBeUndefined();
|
|
237
|
-
|
|
238
|
-
// Restore permissions for cleanup
|
|
229
|
+
|
|
239
230
|
fs.chmodSync(testDir, 0o755);
|
|
240
231
|
} else {
|
|
241
|
-
// On Windows, just verify error handling structure exists
|
|
242
|
-
// Skip actual permission test as Windows permissions work differently
|
|
243
232
|
const content = '# Test\n\nContent';
|
|
244
233
|
const result = saveADR(content, 'Test', testDir);
|
|
245
|
-
|
|
246
|
-
// Should succeed on Windows since we can't easily simulate permission errors
|
|
234
|
+
|
|
247
235
|
expect(result).toHaveProperty('success');
|
|
248
236
|
expect(typeof result.success).toBe('boolean');
|
|
249
237
|
}
|
|
250
238
|
});
|
|
251
239
|
|
|
252
240
|
it('handles long titles correctly', () => {
|
|
253
|
-
const longTitle =
|
|
241
|
+
const longTitle =
|
|
242
|
+
'This is a very long title that should still work correctly when converted to a filename slug';
|
|
254
243
|
const content = `# ${longTitle}\n\nContent`;
|
|
255
244
|
const result = saveADR(content, longTitle, testDir);
|
|
256
245
|
|
|
@@ -263,7 +252,6 @@ describe('ADR Module', () => {
|
|
|
263
252
|
const result = saveADR(content, 'Decision with émojis 🚀', testDir);
|
|
264
253
|
|
|
265
254
|
expect(result.success).toBe(true);
|
|
266
|
-
// Should strip unicode to safe characters
|
|
267
255
|
expect(result.filePath).toMatch(/0001-.+\.md$/);
|
|
268
256
|
});
|
|
269
257
|
});
|
|
@@ -275,4 +263,3 @@ describe('ADR Module', () => {
|
|
|
275
263
|
});
|
|
276
264
|
});
|
|
277
265
|
});
|
|
278
|
-
|
|
@@ -1,46 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ADR File Management Module
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Handles creation and management of Architectural Decision Record files.
|
|
5
5
|
* Follows MADR (Markdown Architectural Decision Records) format.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import * as fs from 'fs';
|
|
9
9
|
import * as path from 'path';
|
|
10
|
-
import { loggerInstance as logger } from '
|
|
10
|
+
import { loggerInstance as logger } from '../logger';
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Default ADR directory relative to project root
|
|
14
|
-
*/
|
|
15
12
|
export const DEFAULT_ADR_DIR = 'docs/adr';
|
|
16
13
|
|
|
17
|
-
/**
|
|
18
|
-
* Convert a title to a filename-safe slug
|
|
19
|
-
* Example: "Use PostgreSQL for Storage" -> "use-postgresql-for-storage"
|
|
20
|
-
*/
|
|
21
14
|
export function titleToSlug(title: string): string {
|
|
22
15
|
return title
|
|
23
16
|
.toLowerCase()
|
|
24
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
25
|
-
.replace(/^-+|-+$/g, '');
|
|
17
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
18
|
+
.replace(/^-+|-+$/g, '');
|
|
26
19
|
}
|
|
27
20
|
|
|
28
|
-
/**
|
|
29
|
-
* Get the next ADR number by scanning existing ADR files
|
|
30
|
-
*
|
|
31
|
-
* @param adrDir - Directory containing ADR files
|
|
32
|
-
* @returns Next available ADR number (e.g., 1, 2, 3...)
|
|
33
|
-
*/
|
|
34
21
|
export function getNextADRNumber(adrDir: string): number {
|
|
35
22
|
try {
|
|
36
23
|
if (!fs.existsSync(adrDir)) {
|
|
37
|
-
return 1;
|
|
24
|
+
return 1;
|
|
38
25
|
}
|
|
39
26
|
|
|
40
27
|
const files = fs.readdirSync(adrDir);
|
|
41
28
|
const adrNumbers: number[] = [];
|
|
42
29
|
|
|
43
|
-
// Extract numbers from existing ADR files (format: 0001-title.md)
|
|
44
30
|
for (const file of files) {
|
|
45
31
|
const match = file.match(/^(\d{4})-/);
|
|
46
32
|
if (match) {
|
|
@@ -52,7 +38,6 @@ export function getNextADRNumber(adrDir: string): number {
|
|
|
52
38
|
return 1;
|
|
53
39
|
}
|
|
54
40
|
|
|
55
|
-
// Return next number after the highest existing number
|
|
56
41
|
return Math.max(...adrNumbers) + 1;
|
|
57
42
|
} catch (error) {
|
|
58
43
|
logger.warn('Failed to scan existing ADRs, defaulting to 1', { error, adrDir });
|
|
@@ -60,11 +45,6 @@ export function getNextADRNumber(adrDir: string): number {
|
|
|
60
45
|
}
|
|
61
46
|
}
|
|
62
47
|
|
|
63
|
-
/**
|
|
64
|
-
* Ensure ADR directory exists, create if it doesn't
|
|
65
|
-
*
|
|
66
|
-
* @param adrDir - Directory path to ensure exists
|
|
67
|
-
*/
|
|
68
48
|
export function ensureADRDirectory(adrDir: string): void {
|
|
69
49
|
if (!fs.existsSync(adrDir)) {
|
|
70
50
|
logger.info('Creating ADR directory', { adrDir });
|
|
@@ -72,56 +52,36 @@ export function ensureADRDirectory(adrDir: string): void {
|
|
|
72
52
|
}
|
|
73
53
|
}
|
|
74
54
|
|
|
75
|
-
/**
|
|
76
|
-
* Generate ADR filename from number and title
|
|
77
|
-
*
|
|
78
|
-
* @param number - ADR number (will be zero-padded to 4 digits)
|
|
79
|
-
* @param title - ADR title (will be converted to slug)
|
|
80
|
-
* @returns Filename like "0001-use-postgresql-for-storage.md"
|
|
81
|
-
*/
|
|
82
55
|
export function generateADRFilename(number: number, title: string): string {
|
|
83
56
|
const paddedNumber = String(number).padStart(4, '0');
|
|
84
57
|
const slug = titleToSlug(title);
|
|
85
58
|
return `${paddedNumber}-${slug}.md`;
|
|
86
59
|
}
|
|
87
60
|
|
|
88
|
-
/**
|
|
89
|
-
* Save ADR content to file
|
|
90
|
-
*
|
|
91
|
-
* @param content - Full markdown content of the ADR
|
|
92
|
-
* @param title - Title extracted from ADR content
|
|
93
|
-
* @param adrDir - Directory to save ADR in (defaults to docs/adr)
|
|
94
|
-
* @returns Object with success status, file path, and any error
|
|
95
|
-
*/
|
|
96
61
|
export function saveADR(
|
|
97
62
|
content: string,
|
|
98
63
|
title: string,
|
|
99
64
|
adrDir: string = DEFAULT_ADR_DIR
|
|
100
65
|
): { success: boolean; filePath?: string; error?: string } {
|
|
101
66
|
try {
|
|
102
|
-
// Ensure directory exists
|
|
103
67
|
ensureADRDirectory(adrDir);
|
|
104
68
|
|
|
105
|
-
// Get next ADR number
|
|
106
69
|
const adrNumber = getNextADRNumber(adrDir);
|
|
107
70
|
|
|
108
|
-
// Generate filename
|
|
109
71
|
const filename = generateADRFilename(adrNumber, title);
|
|
110
72
|
const filePath = path.join(adrDir, filename);
|
|
111
73
|
|
|
112
|
-
// Check if file already exists (shouldn't happen, but safety check)
|
|
113
74
|
if (fs.existsSync(filePath)) {
|
|
114
75
|
logger.warn('ADR file already exists, using alternative name', { filePath });
|
|
115
76
|
const alternativeFilename = generateADRFilename(adrNumber + 1, title);
|
|
116
77
|
const alternativeFilePath = path.join(adrDir, alternativeFilename);
|
|
117
|
-
|
|
78
|
+
|
|
118
79
|
fs.writeFileSync(alternativeFilePath, content, 'utf-8');
|
|
119
80
|
logger.info('ADR saved successfully', { filePath: alternativeFilePath });
|
|
120
|
-
|
|
81
|
+
|
|
121
82
|
return { success: true, filePath: alternativeFilePath };
|
|
122
83
|
}
|
|
123
84
|
|
|
124
|
-
// Write ADR content to file
|
|
125
85
|
fs.writeFileSync(filePath, content, 'utf-8');
|
|
126
86
|
|
|
127
87
|
logger.info('ADR saved successfully', { filePath, adrNumber });
|
|
@@ -133,4 +93,3 @@ export function saveADR(
|
|
|
133
93
|
return { success: false, error: errorMessage };
|
|
134
94
|
}
|
|
135
95
|
}
|
|
136
|
-
|
package/src/adr/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './adr';
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { loadConfig, getDefaultConfigPath } from '../config';
|
|
3
|
+
import type { DiffOptions } from '../git/index';
|
|
4
|
+
import {
|
|
5
|
+
formatPrompt,
|
|
6
|
+
ANALYSIS_PROMPT_V1,
|
|
7
|
+
formatGenerationPrompt,
|
|
8
|
+
promptForGeneration,
|
|
9
|
+
} from '../llm/prompts';
|
|
10
|
+
import { analyzeChanges, generateADRContent } from '../llm/llm';
|
|
11
|
+
import { loggerInstance as logger } from '../logger';
|
|
12
|
+
import { saveADR } from '../adr/adr';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import { createGitStrategy, type GitStrategy } from './strategies/git-strategy';
|
|
15
|
+
import { presenter, type AnalysisSummary } from '../presenters/console-presenter';
|
|
16
|
+
|
|
17
|
+
export interface AnalysisResult {
|
|
18
|
+
is_significant: boolean;
|
|
19
|
+
reason: string;
|
|
20
|
+
confidence?: number;
|
|
21
|
+
timestamp: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface GenerationResult {
|
|
25
|
+
content: string;
|
|
26
|
+
title: string;
|
|
27
|
+
timestamp: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function runAnalysisInternal(diffOptions: DiffOptions): Promise<void> {
|
|
31
|
+
const configPath = getDefaultConfigPath();
|
|
32
|
+
const config = await loadConfig(configPath);
|
|
33
|
+
|
|
34
|
+
if (!config) {
|
|
35
|
+
presenter.showConfigError();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const gitStrategy: GitStrategy = createGitStrategy(diffOptions);
|
|
40
|
+
|
|
41
|
+
let changedFiles: string[];
|
|
42
|
+
try {
|
|
43
|
+
changedFiles = await gitStrategy.getFiles();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const gitError = error as { name?: string; message?: string };
|
|
46
|
+
if (gitError.name === 'GitError') {
|
|
47
|
+
presenter.showGitError(gitError.message || 'Unknown Git error');
|
|
48
|
+
} else {
|
|
49
|
+
presenter.showReadFilesError();
|
|
50
|
+
}
|
|
51
|
+
logger.error('Failed to get changed files', { error, mode: diffOptions.mode });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (changedFiles.length === 0) {
|
|
56
|
+
presenter.showNoChanges(diffOptions);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
presenter.showAnalyzingFiles(changedFiles, diffOptions);
|
|
61
|
+
|
|
62
|
+
let diffContent: string;
|
|
63
|
+
try {
|
|
64
|
+
diffContent = await gitStrategy.getDiff();
|
|
65
|
+
} catch (error) {
|
|
66
|
+
presenter.showReadFilesError();
|
|
67
|
+
logger.error('Failed to get diff', { error, mode: diffOptions.mode });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!diffContent || diffContent.trim().length === 0) {
|
|
72
|
+
presenter.showNoDiffContent();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const repositoryContext = path.basename(process.cwd());
|
|
77
|
+
const prompt = formatPrompt(ANALYSIS_PROMPT_V1, {
|
|
78
|
+
file_paths: changedFiles,
|
|
79
|
+
diff_content: diffContent,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
presenter.showSendingToLLM(diffOptions, config.provider, config.analysis_model);
|
|
83
|
+
|
|
84
|
+
const response = await analyzeChanges(config, {
|
|
85
|
+
file_paths: changedFiles,
|
|
86
|
+
diff_content: diffContent,
|
|
87
|
+
repository_context: repositoryContext,
|
|
88
|
+
analysis_prompt: prompt,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (!response.result || response.error) {
|
|
92
|
+
presenter.showAnalysisFailed(response.error);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const result = response.result;
|
|
97
|
+
|
|
98
|
+
presenter.showAnalysisComplete();
|
|
99
|
+
|
|
100
|
+
if (result.is_significant) {
|
|
101
|
+
const summary: AnalysisSummary = {
|
|
102
|
+
fileCount: changedFiles.length,
|
|
103
|
+
mode: diffOptions.mode,
|
|
104
|
+
isSignificant: true,
|
|
105
|
+
reason: result.reason,
|
|
106
|
+
confidence: result.confidence,
|
|
107
|
+
};
|
|
108
|
+
presenter.showSignificantResult(summary);
|
|
109
|
+
|
|
110
|
+
const shouldGenerate = await promptForGeneration(result.reason);
|
|
111
|
+
|
|
112
|
+
if (shouldGenerate) {
|
|
113
|
+
presenter.showGeneratingADR();
|
|
114
|
+
|
|
115
|
+
const generationPrompt = formatGenerationPrompt({
|
|
116
|
+
file_paths: changedFiles,
|
|
117
|
+
diff_content: diffContent,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const generationResponse = await generateADRContent(config, {
|
|
121
|
+
file_paths: changedFiles,
|
|
122
|
+
diff_content: diffContent,
|
|
123
|
+
reason: result.reason,
|
|
124
|
+
generation_prompt: generationPrompt,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (!generationResponse.result || generationResponse.error) {
|
|
128
|
+
presenter.showGenerationFailed(generationResponse.error);
|
|
129
|
+
logger.error('ADR generation failed', { error: generationResponse.error });
|
|
130
|
+
} else {
|
|
131
|
+
const saveResult = saveADR(
|
|
132
|
+
generationResponse.result.content,
|
|
133
|
+
generationResponse.result.title
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (saveResult.success && saveResult.filePath) {
|
|
137
|
+
presenter.showADRSuccess(saveResult.filePath);
|
|
138
|
+
logger.info('ADR generation workflow completed successfully', {
|
|
139
|
+
filePath: saveResult.filePath,
|
|
140
|
+
title: generationResponse.result.title,
|
|
141
|
+
});
|
|
142
|
+
} else {
|
|
143
|
+
presenter.showADRSaveError(saveResult.error);
|
|
144
|
+
logger.error('Failed to save ADR', { error: saveResult.error });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
presenter.showSkippingGeneration();
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
const summary: AnalysisSummary = {
|
|
152
|
+
fileCount: changedFiles.length,
|
|
153
|
+
mode: diffOptions.mode,
|
|
154
|
+
isSignificant: false,
|
|
155
|
+
reason: result.reason,
|
|
156
|
+
confidence: result.confidence,
|
|
157
|
+
};
|
|
158
|
+
presenter.showNotSignificantResult(summary);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
logger.info('Analysis workflow completed successfully', {
|
|
162
|
+
is_significant: result.is_significant,
|
|
163
|
+
file_count: changedFiles.length,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function runAnalysis(diffOptions: DiffOptions = { mode: 'all' }): Promise<void> {
|
|
168
|
+
try {
|
|
169
|
+
logger.info('Starting analysis workflow');
|
|
170
|
+
await runAnalysisInternal(diffOptions);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
logger.error('Unexpected error in analysis workflow', { error });
|
|
173
|
+
presenter.showUnexpectedError();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getStagedFiles,
|
|
3
|
+
getStagedDiff,
|
|
4
|
+
getAllChanges,
|
|
5
|
+
getAllDiff,
|
|
6
|
+
type DiffOptions,
|
|
7
|
+
} from '../../git/git.operations';
|
|
8
|
+
import { GitError } from '../../git';
|
|
9
|
+
|
|
10
|
+
export interface GitStrategy {
|
|
11
|
+
getFiles(): Promise<string[]>;
|
|
12
|
+
getDiff(): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class StagedChangesStrategy implements GitStrategy {
|
|
16
|
+
async getFiles(): Promise<string[]> {
|
|
17
|
+
return getStagedFiles();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getDiff(): Promise<string> {
|
|
21
|
+
return getStagedDiff();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class AllChangesStrategy implements GitStrategy {
|
|
26
|
+
async getFiles(): Promise<string[]> {
|
|
27
|
+
return getAllChanges();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async getDiff(): Promise<string> {
|
|
31
|
+
return getAllDiff();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class BranchDiffStrategy implements GitStrategy {
|
|
36
|
+
constructor(
|
|
37
|
+
private base: string,
|
|
38
|
+
private head: string
|
|
39
|
+
) {}
|
|
40
|
+
|
|
41
|
+
async getFiles(): Promise<string[]> {
|
|
42
|
+
const { exec } = await import('child_process');
|
|
43
|
+
const { promisify } = await import('util');
|
|
44
|
+
const execAsync = promisify(exec);
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const { stdout } = await execAsync(`git diff --name-only ${this.base}...${this.head}`);
|
|
48
|
+
return stdout
|
|
49
|
+
.split('\n')
|
|
50
|
+
.map((f) => f.trim())
|
|
51
|
+
.filter((f) => f.length > 0);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const errorWithCode = error as { code?: number };
|
|
54
|
+
if (errorWithCode.code === 128) {
|
|
55
|
+
throw new GitError(
|
|
56
|
+
`Invalid git reference: ${this.base} or ${this.head}. Please ensure both references exist.`,
|
|
57
|
+
'GIT_ERROR',
|
|
58
|
+
error instanceof Error ? error : new Error(String(error))
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
throw new GitError(
|
|
62
|
+
'Unable to read Git repository. Please check repository permissions.',
|
|
63
|
+
'GIT_ERROR',
|
|
64
|
+
error instanceof Error ? error : new Error(String(error))
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getDiff(): Promise<string> {
|
|
70
|
+
const { exec } = await import('child_process');
|
|
71
|
+
const { promisify } = await import('util');
|
|
72
|
+
const execAsync = promisify(exec);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const { stdout } = await execAsync(`git diff ${this.base}...${this.head} --unified=1`);
|
|
76
|
+
return stdout;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
const errorWithCode = error as { code?: number };
|
|
79
|
+
if (errorWithCode.code === 128) {
|
|
80
|
+
throw new GitError(
|
|
81
|
+
`Invalid git reference: ${this.base} or ${this.head}. Please ensure both references exist.`,
|
|
82
|
+
'GIT_ERROR',
|
|
83
|
+
error instanceof Error ? error : new Error(String(error))
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
throw new GitError(
|
|
87
|
+
'Unable to read Git repository. Please check repository permissions.',
|
|
88
|
+
'GIT_ERROR',
|
|
89
|
+
error instanceof Error ? error : new Error(String(error))
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function createGitStrategy(options: DiffOptions): GitStrategy {
|
|
96
|
+
switch (options.mode) {
|
|
97
|
+
case 'staged':
|
|
98
|
+
return new StagedChangesStrategy();
|
|
99
|
+
case 'all':
|
|
100
|
+
return new AllChangesStrategy();
|
|
101
|
+
case 'branch-diff':
|
|
102
|
+
return new BranchDiffStrategy(options.base || 'origin/main', options.head || 'HEAD');
|
|
103
|
+
default:
|
|
104
|
+
return new AllChangesStrategy();
|
|
105
|
+
}
|
|
106
|
+
}
|
package/src/commands/analyze.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Analyze Command
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Triggers LLM-powered analysis of code changes.
|
|
5
5
|
* Thin wrapper around analysis orchestration module.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { runAnalysis } from '../analysis';
|
|
8
|
+
import { runAnalysis } from '../analysis/analysis.orchestrator';
|
|
9
9
|
import { DiffOptions } from '../git';
|
|
10
10
|
import { loggerInstance as logger } from '../logger';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Execute the analyze command
|
|
14
14
|
* Analyzes code changes for architectural significance
|
|
15
|
-
*
|
|
15
|
+
*
|
|
16
16
|
* @param args - Command line arguments (e.g., ['--staged'], ['--all'])
|
|
17
17
|
*/
|
|
18
18
|
export async function analyzeCommand(args: string[] = []): Promise<void> {
|
|
19
19
|
try {
|
|
20
20
|
// Parse command line flags to determine diff options
|
|
21
21
|
const diffOptions: DiffOptions = { mode: 'all' }; // Default to all uncommitted
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
// Check for --base flag (implies branch-diff mode)
|
|
24
24
|
const baseIndex = args.indexOf('--base');
|
|
25
25
|
if (baseIndex !== -1 && baseIndex + 1 < args.length) {
|
|
26
26
|
diffOptions.mode = 'branch-diff';
|
|
27
27
|
diffOptions.base = args[baseIndex + 1];
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
// Check for optional --head flag
|
|
30
30
|
const headIndex = args.indexOf('--head');
|
|
31
31
|
if (headIndex !== -1 && headIndex + 1 < args.length) {
|
|
@@ -36,11 +36,11 @@ export async function analyzeCommand(args: string[] = []): Promise<void> {
|
|
|
36
36
|
} else if (args.includes('--all')) {
|
|
37
37
|
diffOptions.mode = 'all';
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
logger.info('Analyze command started', {
|
|
39
|
+
|
|
40
|
+
logger.info('Analyze command started', {
|
|
41
41
|
mode: diffOptions.mode,
|
|
42
42
|
base: diffOptions.base,
|
|
43
|
-
head: diffOptions.head
|
|
43
|
+
head: diffOptions.head,
|
|
44
44
|
});
|
|
45
45
|
await runAnalysis(diffOptions);
|
|
46
46
|
logger.info('Analyze command completed');
|
|
@@ -53,4 +53,3 @@ export async function analyzeCommand(args: string[] = []): Promise<void> {
|
|
|
53
53
|
console.error('Please check the logs for more details.\n');
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { statusCommand } from './status';
|
|
2
|
+
import * as config from '../config';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
|
|
5
|
+
// Mock dependencies
|
|
6
|
+
jest.mock('../config');
|
|
7
|
+
jest.mock('fs');
|
|
8
|
+
jest.mock('../logger');
|
|
9
|
+
|
|
10
|
+
describe('Status Command', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
jest.clearAllMocks();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('statusCommand', () => {
|
|
16
|
+
test('displays status when config exists', async () => {
|
|
17
|
+
(fs.existsSync as jest.Mock).mockReturnValue(true);
|
|
18
|
+
(config.getDefaultConfigPath as jest.Mock).mockReturnValue('cadr.yaml');
|
|
19
|
+
(config.loadConfig as jest.Mock).mockResolvedValue({
|
|
20
|
+
provider: 'openai',
|
|
21
|
+
analysis_model: 'gpt-4',
|
|
22
|
+
api_key_env: 'OPENAI_API_KEY'
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
26
|
+
|
|
27
|
+
await statusCommand();
|
|
28
|
+
|
|
29
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('cADR Status'));
|
|
30
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Provider: openai'));
|
|
31
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Model: gpt-4'));
|
|
32
|
+
|
|
33
|
+
consoleSpy.mockRestore();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('displays warning when config does not exist', async () => {
|
|
37
|
+
(fs.existsSync as jest.Mock).mockReturnValue(false);
|
|
38
|
+
(config.getDefaultConfigPath as jest.Mock).mockReturnValue('cadr.yaml');
|
|
39
|
+
|
|
40
|
+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
41
|
+
|
|
42
|
+
await statusCommand();
|
|
43
|
+
|
|
44
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Not Found'));
|
|
45
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Run `cadr init`'));
|
|
46
|
+
|
|
47
|
+
consoleSpy.mockRestore();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('handles errors gracefully', async () => {
|
|
51
|
+
(config.getDefaultConfigPath as jest.Mock).mockImplementation(() => {
|
|
52
|
+
throw new Error('FileSystem error');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const errorSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
56
|
+
|
|
57
|
+
await statusCommand();
|
|
58
|
+
|
|
59
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('Failed to retrieve status'));
|
|
60
|
+
|
|
61
|
+
errorSpy.mockRestore();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|