roadmapsmith 0.5.1 → 0.7.0
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/bin/cli.js +247 -211
- package/package.json +20 -4
- package/src/config.js +7 -0
- package/src/generator/index.js +563 -562
- package/src/model.js +1 -0
- package/src/renderer/professional.js +536 -476
- package/src/validator/index.js +464 -420
package/src/validator/index.js
CHANGED
|
@@ -1,420 +1,464 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const { walkFiles, detectTestFrameworks } = require('../io');
|
|
6
|
-
const { collectPluginContributions } = require('../config');
|
|
7
|
-
const { escapeRegExp, tokenize } = require('../utils');
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
content
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (!
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (rule.
|
|
268
|
-
const
|
|
269
|
-
if (!
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
evidence.
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
evidence
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const { walkFiles, detectTestFrameworks } = require('../io');
|
|
6
|
+
const { collectPluginContributions } = require('../config');
|
|
7
|
+
const { escapeRegExp, tokenize } = require('../utils');
|
|
8
|
+
|
|
9
|
+
const CONFIDENCE_RANK = { low: 0, medium: 1, high: 2 };
|
|
10
|
+
|
|
11
|
+
const CODE_EXTENSIONS = new Set([
|
|
12
|
+
'.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.py', '.go', '.rs', '.java', '.kt', '.swift', '.rb', '.php', '.cs'
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const DOC_HINTS = ['readme', 'changelog', 'docs', 'documentation', 'spec', 'diagram', 'runbook'];
|
|
16
|
+
const CODE_HINTS = ['implement', 'add', 'create', 'build', 'refactor', 'fix', 'module', 'function', 'api', 'endpoint', 'command'];
|
|
17
|
+
const GENERIC_TASK_TOKENS = new Set([
|
|
18
|
+
'implement',
|
|
19
|
+
'implementation',
|
|
20
|
+
'module',
|
|
21
|
+
'function',
|
|
22
|
+
'class',
|
|
23
|
+
'method',
|
|
24
|
+
'command',
|
|
25
|
+
'create',
|
|
26
|
+
'add',
|
|
27
|
+
'build',
|
|
28
|
+
'refactor',
|
|
29
|
+
'fix',
|
|
30
|
+
'test',
|
|
31
|
+
'tests'
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const CANONICAL_FILES = {
|
|
35
|
+
security: 'SECURITY.md',
|
|
36
|
+
readme: 'README.md',
|
|
37
|
+
changelog: 'CHANGELOG.md',
|
|
38
|
+
license: 'LICENSE'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function readFileIndex(projectRoot, files) {
|
|
42
|
+
const index = [];
|
|
43
|
+
for (const relativePath of files) {
|
|
44
|
+
const absolutePath = path.resolve(projectRoot, relativePath);
|
|
45
|
+
const ext = path.extname(relativePath).toLowerCase();
|
|
46
|
+
let content = '';
|
|
47
|
+
try {
|
|
48
|
+
const buffer = fs.readFileSync(absolutePath);
|
|
49
|
+
if (buffer.length > 512 * 1024) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
content = buffer.toString('utf8');
|
|
53
|
+
} catch {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
index.push({
|
|
58
|
+
relativePath,
|
|
59
|
+
absolutePath,
|
|
60
|
+
ext,
|
|
61
|
+
content,
|
|
62
|
+
isTestFile: /(^|\/)(__tests__|tests)\//.test(relativePath) || /\.test\.|\.spec\.|_test\.go$/.test(relativePath)
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return index;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const KNOWN_PATH_ROOTS = [
|
|
69
|
+
'src/', 'lib/', 'bin/', 'test/', 'tests/', 'docs/', 'scripts/',
|
|
70
|
+
'packages/', 'apps/', 'tools/', '.github/', 'roadmap-skill/'
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
function hasFileExtension(token) {
|
|
74
|
+
const lastSegment = token.replace(/\\/g, '/').split('/').pop() || '';
|
|
75
|
+
return /\.[A-Za-z0-9]{1,10}$/.test(lastSegment);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isLikelyPath(token) {
|
|
79
|
+
if (/^\.{1,2}\/|^\//.test(token)) return true;
|
|
80
|
+
if (hasFileExtension(token)) return true;
|
|
81
|
+
if (KNOWN_PATH_ROOTS.some((root) => token.startsWith(root))) return true;
|
|
82
|
+
if ((token.match(/\//g) || []).length >= 2) return true;
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function extractExplicitPaths(text) {
|
|
87
|
+
const results = new Set();
|
|
88
|
+
const quoted = String(text).match(/`([^`]+)`/g) || [];
|
|
89
|
+
for (const token of quoted) {
|
|
90
|
+
const clean = token.slice(1, -1);
|
|
91
|
+
if (clean.includes('/') || clean.includes('\\') || clean.includes('.')) {
|
|
92
|
+
results.add(clean);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const pathTokens = String(text).match(/([A-Za-z0-9_.-]+\/[A-Za-z0-9_./-]+)/g) || [];
|
|
97
|
+
for (const raw of pathTokens) {
|
|
98
|
+
const token = raw.replace(/[.,;:!?)]+$/, '');
|
|
99
|
+
if (isLikelyPath(token)) results.add(token);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return Array.from(results).sort((left, right) => left.localeCompare(right));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function extractSymbolHints(text) {
|
|
106
|
+
const symbols = new Set();
|
|
107
|
+
const patterns = [
|
|
108
|
+
/(?:function|class|method|command)\s+([A-Za-z_][A-Za-z0-9_]*)/gi,
|
|
109
|
+
/(?:function|module|class|command|method)\s+`([A-Za-z_][A-Za-z0-9_-]*)`/gi,
|
|
110
|
+
/`([A-Za-z_][A-Za-z0-9_-]*)`\s+(?:function|module|class|command|method)/gi
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
for (const pattern of patterns) {
|
|
114
|
+
let match = pattern.exec(text);
|
|
115
|
+
while (match) {
|
|
116
|
+
symbols.add(match[1]);
|
|
117
|
+
match = pattern.exec(text);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return Array.from(symbols).sort((left, right) => left.localeCompare(right));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function isCodeTask(taskText) {
|
|
125
|
+
const normalized = String(taskText).toLowerCase();
|
|
126
|
+
return CODE_HINTS.some((hint) => normalized.includes(hint));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isDocTask(taskText) {
|
|
130
|
+
const normalized = String(taskText).toLowerCase();
|
|
131
|
+
return DOC_HINTS.some((hint) => normalized.includes(hint));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function findFilesByPathHints(pathHints, fileIndex) {
|
|
135
|
+
const matches = [];
|
|
136
|
+
for (const hint of pathHints) {
|
|
137
|
+
const normalizedHint = hint.replace(/\\/g, '/');
|
|
138
|
+
const direct = fileIndex.find((file) => file.relativePath === normalizedHint);
|
|
139
|
+
if (direct) {
|
|
140
|
+
matches.push(direct.relativePath);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
for (const file of fileIndex) {
|
|
145
|
+
if (file.relativePath.endsWith(normalizedHint)) {
|
|
146
|
+
matches.push(file.relativePath);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return Array.from(new Set(matches)).sort((left, right) => left.localeCompare(right));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function findFilesBySymbols(symbolHints, fileIndex) {
|
|
154
|
+
const matches = new Set();
|
|
155
|
+
for (const symbol of symbolHints) {
|
|
156
|
+
const regex = new RegExp(`\\b${escapeRegExp(symbol)}\\b`, 'i');
|
|
157
|
+
for (const file of fileIndex) {
|
|
158
|
+
if (!CODE_EXTENSIONS.has(file.ext)) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (regex.test(file.content)) {
|
|
162
|
+
matches.add(file.relativePath);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return Array.from(matches).sort((left, right) => left.localeCompare(right));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function findCodeEvidence(taskText, fileIndex) {
|
|
170
|
+
const tokens = tokenize(taskText)
|
|
171
|
+
.filter((token) => token.length >= 3 && !GENERIC_TASK_TOKENS.has(token))
|
|
172
|
+
.slice(0, 8);
|
|
173
|
+
if (tokens.length === 0) {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const matches = [];
|
|
178
|
+
for (const file of fileIndex) {
|
|
179
|
+
if (!CODE_EXTENSIONS.has(file.ext) || file.isTestFile) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let score = 0;
|
|
184
|
+
const lowered = file.content.toLowerCase();
|
|
185
|
+
for (const token of tokens) {
|
|
186
|
+
if (token.length < 3) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (lowered.includes(token)) {
|
|
190
|
+
score += 1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const threshold = tokens.length === 1 ? 1 : 2;
|
|
195
|
+
if (score >= threshold) {
|
|
196
|
+
matches.push(file.relativePath);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return matches.slice(0, 20);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function findTestEvidence(taskText, fileIndex) {
|
|
204
|
+
const tokens = tokenize(taskText)
|
|
205
|
+
.filter((token) => token.length >= 3 && !GENERIC_TASK_TOKENS.has(token))
|
|
206
|
+
.slice(0, 8);
|
|
207
|
+
const matches = [];
|
|
208
|
+
|
|
209
|
+
for (const file of fileIndex) {
|
|
210
|
+
if (!file.isTestFile) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const lowered = file.content.toLowerCase();
|
|
214
|
+
const hasMatch = tokens.some((token) => lowered.includes(token));
|
|
215
|
+
if (hasMatch) {
|
|
216
|
+
matches.push(file.relativePath);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return matches.slice(0, 20);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function findArtifactEvidence(taskText, fileIndex) {
|
|
224
|
+
const normalized = String(taskText).toLowerCase();
|
|
225
|
+
const files = [];
|
|
226
|
+
const heuristicArtifacts = [];
|
|
227
|
+
|
|
228
|
+
for (const [keyword, filename] of Object.entries(CANONICAL_FILES)) {
|
|
229
|
+
if (normalized.includes(keyword)) {
|
|
230
|
+
const hit = fileIndex.find(
|
|
231
|
+
(f) => f.relativePath === filename || f.relativePath.endsWith('/' + filename)
|
|
232
|
+
);
|
|
233
|
+
if (hit) {
|
|
234
|
+
files.push(hit.relativePath);
|
|
235
|
+
heuristicArtifacts.push(hit.relativePath);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (!isDocTask(taskText) && !normalized.includes('artifact') && !normalized.includes('release')) {
|
|
241
|
+
return { files, heuristicArtifacts };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const artifactPatterns = [
|
|
245
|
+
/^README\.md$/i,
|
|
246
|
+
/^CHANGELOG\.md$/i,
|
|
247
|
+
/^docs\//i,
|
|
248
|
+
/^artifacts\//i,
|
|
249
|
+
/^dist\//i,
|
|
250
|
+
/^build\//i
|
|
251
|
+
];
|
|
252
|
+
|
|
253
|
+
for (const file of fileIndex) {
|
|
254
|
+
if (artifactPatterns.some((pattern) => pattern.test(file.relativePath)) && !files.includes(file.relativePath)) {
|
|
255
|
+
files.push(file.relativePath);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return { files: files.slice(0, 20), heuristicArtifacts };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function evaluateRule(rule, task, context) {
|
|
263
|
+
if (!rule) {
|
|
264
|
+
return { passed: true, reasons: [], evidence: {} };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (rule.when) {
|
|
268
|
+
const regexp = new RegExp(rule.when, 'i');
|
|
269
|
+
if (!regexp.test(task.text)) {
|
|
270
|
+
return { passed: true, reasons: [], evidence: {} };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (typeof rule.check === 'function') {
|
|
275
|
+
const custom = rule.check(task, context);
|
|
276
|
+
if (!custom) {
|
|
277
|
+
return { passed: true, reasons: [], evidence: {} };
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
passed: custom.passed !== false,
|
|
281
|
+
reasons: Array.isArray(custom.reasons) ? custom.reasons : [],
|
|
282
|
+
evidence: custom.evidence || {}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const reasons = [];
|
|
287
|
+
const evidence = {};
|
|
288
|
+
|
|
289
|
+
if (rule.type === 'file-exists' && rule.path) {
|
|
290
|
+
const hit = context.fileIndex.find((file) => file.relativePath === rule.path || file.relativePath.endsWith(rule.path));
|
|
291
|
+
if (!hit) {
|
|
292
|
+
reasons.push(rule.message || `missing file: ${rule.path}`);
|
|
293
|
+
} else {
|
|
294
|
+
evidence.file = hit.relativePath;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (rule.type === 'symbol' && rule.pattern) {
|
|
299
|
+
const regex = new RegExp(rule.pattern, 'i');
|
|
300
|
+
const hit = context.fileIndex.find((file) => regex.test(file.content));
|
|
301
|
+
if (!hit) {
|
|
302
|
+
reasons.push(rule.message || `missing symbol pattern: ${rule.pattern}`);
|
|
303
|
+
} else {
|
|
304
|
+
evidence.symbol = hit.relativePath;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (rule.type === 'artifact' && rule.path) {
|
|
309
|
+
const hit = context.fileIndex.find((file) => file.relativePath.startsWith(rule.path) || file.relativePath === rule.path);
|
|
310
|
+
if (!hit) {
|
|
311
|
+
reasons.push(rule.message || `missing artifact: ${rule.path}`);
|
|
312
|
+
} else {
|
|
313
|
+
evidence.artifact = hit.relativePath;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (rule.type === 'test' && context.testFrameworks.length === 0) {
|
|
318
|
+
reasons.push(rule.message || 'test framework not detected');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
passed: reasons.length === 0,
|
|
323
|
+
reasons,
|
|
324
|
+
evidence
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function buildValidationContext(projectRoot, config, plugins) {
|
|
329
|
+
const files = walkFiles(projectRoot);
|
|
330
|
+
const fileIndex = readFileIndex(projectRoot, files);
|
|
331
|
+
const testFrameworks = detectTestFrameworks(projectRoot, files);
|
|
332
|
+
|
|
333
|
+
return {
|
|
334
|
+
projectRoot,
|
|
335
|
+
config,
|
|
336
|
+
plugins,
|
|
337
|
+
files,
|
|
338
|
+
fileIndex,
|
|
339
|
+
testFrameworks
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function validateTask(task, context, config, plugins) {
|
|
344
|
+
const pathHints = extractExplicitPaths(task.text);
|
|
345
|
+
const symbolHints = extractSymbolHints(task.text);
|
|
346
|
+
|
|
347
|
+
const filesFromPaths = findFilesByPathHints(pathHints, context.fileIndex);
|
|
348
|
+
const filesFromSymbols = findFilesBySymbols(symbolHints, context.fileIndex);
|
|
349
|
+
const filesFromCode = findCodeEvidence(task.text, context.fileIndex);
|
|
350
|
+
const filesFromTests = findTestEvidence(task.text, context.fileIndex);
|
|
351
|
+
const { files: filesFromArtifacts, heuristicArtifacts } = findArtifactEvidence(task.text, context.fileIndex);
|
|
352
|
+
|
|
353
|
+
const evidence = {
|
|
354
|
+
code: filesFromCode.length > 0 || filesFromSymbols.length > 0,
|
|
355
|
+
test: filesFromTests.length > 0,
|
|
356
|
+
artifact: filesFromArtifacts.length > 0,
|
|
357
|
+
files: filesFromPaths,
|
|
358
|
+
symbols: filesFromSymbols,
|
|
359
|
+
codeFiles: filesFromCode,
|
|
360
|
+
testFiles: filesFromTests,
|
|
361
|
+
artifactFiles: filesFromArtifacts,
|
|
362
|
+
heuristicArtifacts
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const reasons = [];
|
|
366
|
+
if (pathHints.length > 0 && filesFromPaths.length === 0) {
|
|
367
|
+
reasons.push(`missing referenced file(s): ${pathHints.join(', ')}`);
|
|
368
|
+
}
|
|
369
|
+
if (symbolHints.length > 0 && filesFromSymbols.length === 0) {
|
|
370
|
+
reasons.push(`missing symbol(s): ${symbolHints.join(', ')}`);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const hasEvidence = evidence.code || evidence.test || evidence.artifact || evidence.files.length > 0;
|
|
374
|
+
if (!hasEvidence) {
|
|
375
|
+
reasons.push('no code, test, or artifact evidence found');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const requiresTest = context.testFrameworks.length > 0 && isCodeTask(task.text) && !isDocTask(task.text);
|
|
379
|
+
if (requiresTest && !evidence.test) {
|
|
380
|
+
reasons.push('missing test evidence');
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const configuredRules = Array.isArray(config.validators) ? config.validators : [];
|
|
384
|
+
const pluginRules = collectPluginContributions(plugins || [], 'registerValidators', context);
|
|
385
|
+
for (const rule of [...configuredRules, ...pluginRules]) {
|
|
386
|
+
const ruleResult = evaluateRule(rule, task, context);
|
|
387
|
+
if (!ruleResult.passed) {
|
|
388
|
+
reasons.push(...ruleResult.reasons);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const uniqueReasons = Array.from(new Set(reasons));
|
|
393
|
+
const attempted = hasEvidence || pathHints.length > 0 || symbolHints.length > 0;
|
|
394
|
+
|
|
395
|
+
const evidenceCount = [evidence.code, evidence.test, evidence.artifact].filter(Boolean).length;
|
|
396
|
+
const confidence = evidenceCount >= 2 ? 'high' : evidenceCount === 1 ? 'medium' : 'low';
|
|
397
|
+
|
|
398
|
+
return {
|
|
399
|
+
taskId: task.id,
|
|
400
|
+
passed: uniqueReasons.length === 0,
|
|
401
|
+
confidence,
|
|
402
|
+
reasons: uniqueReasons,
|
|
403
|
+
evidence,
|
|
404
|
+
requiresTest,
|
|
405
|
+
hasEvidence,
|
|
406
|
+
attempted
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function validateTasks(tasks, context, config, plugins) {
|
|
411
|
+
const result = {};
|
|
412
|
+
for (const task of tasks) {
|
|
413
|
+
result[task.id] = validateTask(task, context, config, plugins);
|
|
414
|
+
}
|
|
415
|
+
return result;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function auditValidation(tasks, results) {
|
|
419
|
+
const checkedWithoutEvidence = [];
|
|
420
|
+
const readyButUnchecked = [];
|
|
421
|
+
|
|
422
|
+
for (const task of tasks) {
|
|
423
|
+
const result = results[task.id];
|
|
424
|
+
if (!result) {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (task.checked && !result.passed) {
|
|
429
|
+
checkedWithoutEvidence.push({ task, result });
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (!task.checked && result.passed) {
|
|
433
|
+
readyButUnchecked.push({ task, result });
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return {
|
|
438
|
+
checkedWithoutEvidence,
|
|
439
|
+
readyButUnchecked
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function applyMinimumConfidence(results, minimumConfidence) {
|
|
444
|
+
const minRank = CONFIDENCE_RANK[minimumConfidence] ?? 0;
|
|
445
|
+
if (minRank === 0) return;
|
|
446
|
+
for (const result of Object.values(results)) {
|
|
447
|
+
if ((CONFIDENCE_RANK[result.confidence] ?? 0) < minRank) {
|
|
448
|
+
result.passed = false;
|
|
449
|
+
result.reasons = [
|
|
450
|
+
...result.reasons,
|
|
451
|
+
`validation confidence "${result.confidence}" is below required "${minimumConfidence}"`
|
|
452
|
+
];
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
module.exports = {
|
|
458
|
+
auditValidation,
|
|
459
|
+
buildValidationContext,
|
|
460
|
+
validateTask,
|
|
461
|
+
validateTasks,
|
|
462
|
+
CONFIDENCE_RANK,
|
|
463
|
+
applyMinimumConfidence
|
|
464
|
+
};
|