specvector 0.1.3 → 0.1.4
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/package.json +1 -1
- package/src/config/index.ts +3 -0
- package/src/context/adr.ts +218 -0
- package/src/context/index.ts +9 -0
- package/src/review/engine.ts +8 -2
package/package.json
CHANGED
package/src/config/index.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface SpecVectorConfig {
|
|
|
24
24
|
maxFileSize: number;
|
|
25
25
|
/** Maximum iterations for agent */
|
|
26
26
|
maxIterations: number;
|
|
27
|
+
/** Path to ADR directory (relative to project root), null to disable */
|
|
28
|
+
adrPath: string | null;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/** Default configuration */
|
|
@@ -47,6 +49,7 @@ export const DEFAULT_CONFIG: SpecVectorConfig = {
|
|
|
47
49
|
strictness: "normal",
|
|
48
50
|
maxFileSize: 100 * 1024, // 100KB
|
|
49
51
|
maxIterations: 15,
|
|
52
|
+
adrPath: null, // Disabled by default, set to "docs/adr" to enable
|
|
50
53
|
};
|
|
51
54
|
|
|
52
55
|
/** Config file name */
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR Context Provider - Reads Architecture Decision Records for reviews.
|
|
3
|
+
*
|
|
4
|
+
* Scans a configurable directory for markdown files and includes them
|
|
5
|
+
* as context in the review prompt.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readdir, readFile, stat } from "fs/promises";
|
|
9
|
+
import { join, basename } from "path";
|
|
10
|
+
import type { Result } from "../types/result";
|
|
11
|
+
import { ok, err } from "../types/result";
|
|
12
|
+
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Types
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
export interface ADRFile {
|
|
18
|
+
/** Filename (e.g., "001-use-bun-runtime.md") */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Full file content */
|
|
21
|
+
content: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ADRContext {
|
|
25
|
+
/** List of ADR files found */
|
|
26
|
+
files: ADRFile[];
|
|
27
|
+
/** Number of files loaded */
|
|
28
|
+
count: number;
|
|
29
|
+
/** Path that was scanned */
|
|
30
|
+
path: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ADRContextError {
|
|
34
|
+
code: "PATH_NOT_FOUND" | "READ_ERROR" | "NO_FILES";
|
|
35
|
+
message: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// Constants
|
|
40
|
+
// ============================================================================
|
|
41
|
+
|
|
42
|
+
/** Maximum ADR file size (50KB) */
|
|
43
|
+
const MAX_ADR_FILE_SIZE = 50 * 1024;
|
|
44
|
+
|
|
45
|
+
/** Maximum number of ADR files to read */
|
|
46
|
+
const MAX_ADR_FILES = 20;
|
|
47
|
+
|
|
48
|
+
/** Supported file extensions */
|
|
49
|
+
const ADR_EXTENSIONS = [".md", ".markdown"];
|
|
50
|
+
|
|
51
|
+
/** Common paths to auto-detect (in priority order) */
|
|
52
|
+
const AUTO_DETECT_PATHS = [
|
|
53
|
+
"_bmad-output/planning-artifacts", // BMAD projects
|
|
54
|
+
"docs/adr", // Standard ADR location
|
|
55
|
+
"docs/architecture", // Common alternative
|
|
56
|
+
"adr", // Simple ADR folder
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
// ============================================================================
|
|
60
|
+
// Main Function
|
|
61
|
+
// ============================================================================
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Read ADR files from a directory.
|
|
65
|
+
*
|
|
66
|
+
* @param workingDir - The project root directory
|
|
67
|
+
* @param adrPath - Relative path to ADR directory (e.g., "docs/adr")
|
|
68
|
+
*/
|
|
69
|
+
export async function getADRContext(
|
|
70
|
+
workingDir: string,
|
|
71
|
+
adrPath: string
|
|
72
|
+
): Promise<Result<ADRContext, ADRContextError>> {
|
|
73
|
+
const fullPath = join(workingDir, adrPath);
|
|
74
|
+
|
|
75
|
+
// Check if directory exists
|
|
76
|
+
try {
|
|
77
|
+
const stats = await stat(fullPath);
|
|
78
|
+
if (!stats.isDirectory()) {
|
|
79
|
+
return err({
|
|
80
|
+
code: "PATH_NOT_FOUND",
|
|
81
|
+
message: `ADR path is not a directory: ${adrPath}`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
return err({
|
|
86
|
+
code: "PATH_NOT_FOUND",
|
|
87
|
+
message: `ADR directory not found: ${adrPath}`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Read directory contents
|
|
92
|
+
let entries: string[];
|
|
93
|
+
try {
|
|
94
|
+
entries = await readdir(fullPath);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
return err({
|
|
97
|
+
code: "READ_ERROR",
|
|
98
|
+
message: `Failed to read ADR directory: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Filter to markdown files
|
|
103
|
+
const mdFiles = entries
|
|
104
|
+
.filter((f) => ADR_EXTENSIONS.some((ext) => f.toLowerCase().endsWith(ext)))
|
|
105
|
+
.sort() // Sort alphabetically (ADRs often numbered: 001-xxx.md)
|
|
106
|
+
.slice(0, MAX_ADR_FILES);
|
|
107
|
+
|
|
108
|
+
if (mdFiles.length === 0) {
|
|
109
|
+
return err({
|
|
110
|
+
code: "NO_FILES",
|
|
111
|
+
message: `No ADR markdown files found in: ${adrPath}`,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Read each file
|
|
116
|
+
const files: ADRFile[] = [];
|
|
117
|
+
for (const filename of mdFiles) {
|
|
118
|
+
const filePath = join(fullPath, filename);
|
|
119
|
+
try {
|
|
120
|
+
const fileStats = await stat(filePath);
|
|
121
|
+
|
|
122
|
+
// Skip files that are too large
|
|
123
|
+
if (fileStats.size > MAX_ADR_FILE_SIZE) {
|
|
124
|
+
console.log(`⚠️ Skipping large ADR: ${filename} (${Math.round(fileStats.size / 1024)}KB)`);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const content = await readFile(filePath, "utf-8");
|
|
129
|
+
files.push({
|
|
130
|
+
name: basename(filename),
|
|
131
|
+
content: content.trim(),
|
|
132
|
+
});
|
|
133
|
+
} catch {
|
|
134
|
+
// Skip files we can't read
|
|
135
|
+
console.log(`⚠️ Could not read ADR: ${filename}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (files.length === 0) {
|
|
140
|
+
return err({
|
|
141
|
+
code: "NO_FILES",
|
|
142
|
+
message: `No readable ADR files in: ${adrPath}`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return ok({
|
|
147
|
+
files,
|
|
148
|
+
count: files.length,
|
|
149
|
+
path: adrPath,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ============================================================================
|
|
154
|
+
// Formatting
|
|
155
|
+
// ============================================================================
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Format ADR context for inclusion in review prompt.
|
|
159
|
+
*/
|
|
160
|
+
export function formatADRContext(context: ADRContext): string {
|
|
161
|
+
const lines: string[] = [
|
|
162
|
+
`## Architecture Decision Records (${context.count} files from ${context.path})`,
|
|
163
|
+
"",
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
for (const file of context.files) {
|
|
167
|
+
lines.push(`### ${file.name}`);
|
|
168
|
+
lines.push("");
|
|
169
|
+
lines.push(file.content);
|
|
170
|
+
lines.push("");
|
|
171
|
+
lines.push("---");
|
|
172
|
+
lines.push("");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return lines.join("\n");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get ADR context for a review, with graceful error handling.
|
|
180
|
+
* Returns null if ADRs are not available (no error thrown).
|
|
181
|
+
*
|
|
182
|
+
* If adrPath is not set, auto-detects common paths:
|
|
183
|
+
* - _bmad-output/planning-artifacts (BMAD projects)
|
|
184
|
+
* - docs/adr (standard ADR location)
|
|
185
|
+
* - docs/architecture (common alternative)
|
|
186
|
+
* - adr (simple ADR folder)
|
|
187
|
+
*/
|
|
188
|
+
export async function getADRContextForReview(
|
|
189
|
+
workingDir: string,
|
|
190
|
+
adrPath: string | null | undefined
|
|
191
|
+
): Promise<{ context: ADRContext; formatted: string } | null> {
|
|
192
|
+
// If path is explicitly set, use it
|
|
193
|
+
if (adrPath) {
|
|
194
|
+
const result = await getADRContext(workingDir, adrPath);
|
|
195
|
+
if (!result.ok) {
|
|
196
|
+
console.log(`⚠️ ADR context unavailable: ${result.error.message}`);
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
context: result.value,
|
|
201
|
+
formatted: formatADRContext(result.value),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Auto-detect: try common paths in priority order
|
|
206
|
+
for (const path of AUTO_DETECT_PATHS) {
|
|
207
|
+
const result = await getADRContext(workingDir, path);
|
|
208
|
+
if (result.ok) {
|
|
209
|
+
return {
|
|
210
|
+
context: result.value,
|
|
211
|
+
formatted: formatADRContext(result.value),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// No docs found - this is fine, not all projects have ADRs
|
|
217
|
+
return null;
|
|
218
|
+
}
|
package/src/context/index.ts
CHANGED
package/src/review/engine.ts
CHANGED
|
@@ -20,7 +20,7 @@ import type { ReviewResult, ReviewFinding, Severity } from "../types/review";
|
|
|
20
20
|
import type { Result } from "../types/result";
|
|
21
21
|
import { ok, err } from "../types/result";
|
|
22
22
|
import { loadConfig, getStrictnessModifier } from "../config";
|
|
23
|
-
import { getLinearContextForReview } from "../context";
|
|
23
|
+
import { getLinearContextForReview, getADRContextForReview } from "../context";
|
|
24
24
|
|
|
25
25
|
/** Review engine configuration */
|
|
26
26
|
export interface ReviewConfig {
|
|
@@ -109,12 +109,18 @@ export async function runReview(
|
|
|
109
109
|
|
|
110
110
|
if (linearResult.context) {
|
|
111
111
|
systemPrompt = linearResult.context + "\n\n" + systemPrompt;
|
|
112
|
-
// linearResult.ticketId available for future use (e.g., in review output)
|
|
113
112
|
console.log(`📎 Loaded Linear context for ticket: ${linearResult.ticketId}`);
|
|
114
113
|
} else if (linearResult.warning) {
|
|
115
114
|
console.warn(`⚠️ ${linearResult.warning}`);
|
|
116
115
|
}
|
|
117
116
|
|
|
117
|
+
// Fetch ADR context if configured
|
|
118
|
+
const adrResult = await getADRContextForReview(config.workingDir, fileConfig.adrPath);
|
|
119
|
+
if (adrResult) {
|
|
120
|
+
systemPrompt = adrResult.formatted + "\n\n" + systemPrompt;
|
|
121
|
+
console.log(`📚 Loaded ${adrResult.context.count} ADR files from ${adrResult.context.path}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
118
124
|
// Create agent
|
|
119
125
|
const agent = createAgentLoop(providerResult.value, tools, {
|
|
120
126
|
maxIterations: config.maxIterations || fileConfig.maxIterations || 15,
|