@nerviq/cli 1.29.0 → 1.29.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +1527 -1493
  2. package/README.md +550 -538
  3. package/SECURITY.md +82 -82
  4. package/bin/cli.js +2562 -2558
  5. package/docs/api-reference.md +356 -356
  6. package/docs/audit-fix.md +109 -0
  7. package/docs/autofix.md +3 -62
  8. package/docs/getting-started.md +1 -1
  9. package/docs/index.html +592 -592
  10. package/docs/integration-contracts.md +287 -287
  11. package/docs/maintenance.md +128 -128
  12. package/docs/new-platform-guide.md +202 -202
  13. package/docs/release-process.md +63 -0
  14. package/docs/shallow-risk.md +244 -244
  15. package/docs/why-nerviq.md +82 -82
  16. package/package.json +67 -67
  17. package/src/aider/activity.js +226 -226
  18. package/src/aider/context.js +162 -162
  19. package/src/aider/freshness.js +123 -123
  20. package/src/aider/techniques.js +3465 -3465
  21. package/src/audit/layers.js +180 -180
  22. package/src/audit.js +1032 -1032
  23. package/src/benchmark.js +299 -299
  24. package/src/codex/activity.js +324 -324
  25. package/src/codex/freshness.js +142 -142
  26. package/src/codex/techniques.js +4895 -4895
  27. package/src/context.js +326 -326
  28. package/src/continuous-ops.js +11 -1
  29. package/src/convert.js +340 -340
  30. package/src/copilot/config-parser.js +280 -280
  31. package/src/copilot/context.js +218 -218
  32. package/src/copilot/freshness.js +177 -177
  33. package/src/copilot/patch.js +238 -238
  34. package/src/copilot/techniques.js +3578 -3578
  35. package/src/cursor/freshness.js +194 -194
  36. package/src/cursor/patch.js +243 -243
  37. package/src/cursor/techniques.js +3735 -3735
  38. package/src/doctor.js +201 -201
  39. package/src/fix-engine.js +511 -8
  40. package/src/formatters/csv.js +86 -86
  41. package/src/formatters/junit.js +123 -123
  42. package/src/formatters/markdown.js +164 -164
  43. package/src/formatters/otel.js +151 -151
  44. package/src/freshness.js +156 -156
  45. package/src/gemini/activity.js +402 -402
  46. package/src/gemini/context.js +290 -290
  47. package/src/gemini/freshness.js +183 -183
  48. package/src/gemini/patch.js +229 -229
  49. package/src/gemini/techniques.js +3811 -3811
  50. package/src/governance.js +533 -533
  51. package/src/harmony/audit.js +306 -306
  52. package/src/i18n.js +63 -63
  53. package/src/insights.js +119 -119
  54. package/src/integrations.js +134 -134
  55. package/src/locales/en.json +33 -33
  56. package/src/locales/es.json +33 -33
  57. package/src/migrate.js +354 -354
  58. package/src/opencode/activity.js +286 -286
  59. package/src/opencode/freshness.js +137 -137
  60. package/src/opencode/techniques.js +3450 -3450
  61. package/src/setup/analysis.js +12 -12
  62. package/src/setup.js +7 -6
  63. package/src/shallow-risk/index.js +56 -56
  64. package/src/shallow-risk/patterns/agent-config-cross-platform-drift.js +50 -50
  65. package/src/shallow-risk/patterns/agent-config-dangerous-autoapprove.js +46 -46
  66. package/src/shallow-risk/patterns/agent-config-deprecated-keys.js +46 -46
  67. package/src/shallow-risk/patterns/agent-config-missing-file.js +317 -317
  68. package/src/shallow-risk/patterns/agent-config-secret-literal.js +49 -49
  69. package/src/shallow-risk/patterns/agent-config-stack-contradiction.js +34 -34
  70. package/src/shallow-risk/patterns/hook-script-missing.js +70 -70
  71. package/src/shallow-risk/patterns/mcp-server-no-allowlist.js +52 -52
  72. package/src/shallow-risk/shared.js +648 -648
  73. package/src/source-urls.js +295 -295
  74. package/src/state-paths.js +85 -85
  75. package/src/supplemental-checks.js +805 -805
  76. package/src/telemetry.js +160 -160
  77. package/src/windsurf/context.js +359 -359
  78. package/src/windsurf/freshness.js +194 -194
  79. package/src/windsurf/patch.js +231 -231
  80. package/src/windsurf/techniques.js +3779 -3779
@@ -1,317 +1,317 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
-
5
- const {
6
- SHALLOW_RISK_DOC_URL,
7
- escapeRegExp,
8
- findFirstRepoPath,
9
- getAgentConfigEntries,
10
- getScannableLines,
11
- isKnownConventionPath,
12
- lineHasExampleContext,
13
- looksLikeRelativeFileReference,
14
- normalizeCandidatePath,
15
- resolveRepoPath,
16
- toPosix,
17
- } = require('../shared');
18
-
19
- const POINTER_RE = /(?:^|[\s([`'"])(@?(?:\.{1,2}\/)?[A-Za-z0-9._/-]+)(?=$|[\s)\]`'",:;!?])/g;
20
- const MARKDOWN_LINK_RE = /\[[^\]]+\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g;
21
- const BACKTICK_TOKEN_RE = /`([^`]+)`/g;
22
- const PLACEHOLDER_PATH_RE = /(?:^|\/)(?:path(?:_to)?|to)(?:\/|$)|(?:^|\/)test_file\.py$|(?:^|\/)path_to_test\.py$|(?:^|\/)module_name\.[A-Za-z0-9._-]+$/i;
23
- const ENV_POLICY_RE = /\b(?:dotenv|environment variables?|api keys?|secrets?|credential|gitignore|removed\s+\.env|look for\s+\.env|via\s+`?\.env|defaults?\s+to|do not commit)\b/i;
24
- const OWNERSHIP_CONTEXT_RE = /\b(?:subdirectory|integration|folder|workspace|extension|module|package|component|app|generated file|composition root|entrypoint|directory structure|utility functions|updated in|register feature|build from)s?(?:['’]s)?\b/i;
25
- const SOFT_REFERENCE_CONTEXT_RE = /\b(?:can be deleted afterwards|quality scale|search result|scrape the web page content)\b/i;
26
- const ALWAYS_AMBIGUOUS_BASENAMES = new Set([
27
- 'findings.md',
28
- 'manifest.json',
29
- 'progress.md',
30
- 'quality_scale.yaml',
31
- 'task_plan.md',
32
- 'todo.md',
33
- ]);
34
-
35
- function repoHasBasename(ctx, basename, state) {
36
- if (!basename) {
37
- return false;
38
- }
39
- if (state.basenameCache.has(basename)) {
40
- return state.basenameCache.get(basename);
41
- }
42
-
43
- const match = findFirstRepoPath(ctx, (_relPath, entryName) => entryName === basename, { maxDepth: 10 });
44
- const exists = Boolean(match);
45
- state.basenameCache.set(basename, exists);
46
- return exists;
47
- }
48
-
49
- function repoHasPathSuffix(ctx, candidate, state) {
50
- const normalized = toPosix(candidate || '').replace(/^\.?\//, '');
51
- if (!normalized) {
52
- return false;
53
- }
54
- if (state.suffixCache.has(normalized)) {
55
- return state.suffixCache.get(normalized);
56
- }
57
-
58
- const match = findFirstRepoPath(
59
- ctx,
60
- (relPath) => {
61
- const normalizedPath = toPosix(relPath);
62
- return normalizedPath === normalized || normalizedPath.endsWith(`/${normalized}`);
63
- },
64
- { maxDepth: 10 },
65
- );
66
- const exists = Boolean(match);
67
- state.suffixCache.set(normalized, exists);
68
- return exists;
69
- }
70
-
71
- function lineHasEnvPolicyContext(line) {
72
- return ENV_POLICY_RE.test(String(line || ''));
73
- }
74
-
75
- function lineHasScopedOwnershipContext(line) {
76
- const text = String(line || '');
77
- return OWNERSHIP_CONTEXT_RE.test(text) || SOFT_REFERENCE_CONTEXT_RE.test(text) || /<[^>]+>/.test(text);
78
- }
79
-
80
- function extractLineAnchors(line) {
81
- const anchors = new Set();
82
- const text = String(line || '');
83
-
84
- BACKTICK_TOKEN_RE.lastIndex = 0;
85
- let match = BACKTICK_TOKEN_RE.exec(text);
86
- while (match) {
87
- const rawToken = String(match[1] || '');
88
- const token = normalizeCandidatePath(rawToken)
89
- .replace(/<[^>]+>/g, '')
90
- .replace(/^\/+/, '')
91
- .replace(/\/+$/, '');
92
- if (!token || !rawToken.includes('/')) {
93
- match = BACKTICK_TOKEN_RE.exec(text);
94
- continue;
95
- }
96
- anchors.add(token);
97
- match = BACKTICK_TOKEN_RE.exec(text);
98
- }
99
-
100
- MARKDOWN_LINK_RE.lastIndex = 0;
101
- match = MARKDOWN_LINK_RE.exec(text);
102
- while (match) {
103
- const rawToken = String(match[1] || '');
104
- const token = normalizeCandidatePath(rawToken)
105
- .replace(/<[^>]+>/g, '')
106
- .replace(/^\/+/, '')
107
- .replace(/\/+$/, '');
108
- if (!token || !rawToken.includes('/')) {
109
- match = MARKDOWN_LINK_RE.exec(text);
110
- continue;
111
- }
112
- anchors.add(token);
113
- match = MARKDOWN_LINK_RE.exec(text);
114
- }
115
-
116
- return [...anchors];
117
- }
118
-
119
- function anchorDirsForToken(token) {
120
- if (!token) {
121
- return [];
122
- }
123
-
124
- const normalized = normalizeCandidatePath(token)
125
- .replace(/<[^>]+>/g, '')
126
- .replace(/^\/+/, '')
127
- .replace(/\/+$/, '');
128
- if (!normalized) {
129
- return [];
130
- }
131
-
132
- const dirs = new Set();
133
- const looksFileLike = looksLikeRelativeFileReference(normalized);
134
- const direct = normalized.includes('/')
135
- ? (looksFileLike ? path.posix.dirname(normalized) : normalized)
136
- : normalized;
137
- if (direct && direct !== '.') {
138
- dirs.add(direct);
139
- }
140
-
141
- const parent = path.posix.dirname(direct || normalized);
142
- if (parent && parent !== '.' && parent !== direct) {
143
- dirs.add(parent);
144
- }
145
-
146
- return [...dirs];
147
- }
148
-
149
- function lineResolvesBareCandidate(ctx, line, candidate, state) {
150
- const base = path.posix.basename(candidate);
151
- const anchors = extractLineAnchors(line);
152
-
153
- for (const anchor of anchors) {
154
- const normalizedAnchor = normalizeCandidatePath(anchor);
155
- if (path.posix.basename(normalizedAnchor) === base && (ctx.fileContent(normalizedAnchor) !== null || repoHasPathSuffix(ctx, normalizedAnchor, state))) {
156
- return true;
157
- }
158
-
159
- for (const dir of anchorDirsForToken(anchor)) {
160
- const match = findFirstRepoPath(
161
- ctx,
162
- (relPath, entryName) => entryName === base && toPosix(relPath).startsWith(`${dir}/`),
163
- { maxDepth: 10 },
164
- );
165
- if (match) {
166
- return true;
167
- }
168
- }
169
- }
170
-
171
- if (anchors.length > 0 && repoHasBasename(ctx, base, state)) {
172
- return true;
173
- }
174
-
175
- if (lineHasScopedOwnershipContext(line) && repoHasBasename(ctx, base, state)) {
176
- return true;
177
- }
178
-
179
- return false;
180
- }
181
-
182
- function lineHasAnchorContext(line) {
183
- return extractLineAnchors(line).length > 0;
184
- }
185
-
186
- function lineResolvesPathSuffix(ctx, line, candidate, state) {
187
- if (!candidate || !candidate.includes('/')) {
188
- return false;
189
- }
190
- if (!lineHasAnchorContext(line) && !lineHasScopedOwnershipContext(line)) {
191
- return false;
192
- }
193
- return repoHasPathSuffix(ctx, candidate, state);
194
- }
195
-
196
- function shouldIgnoreCandidate(ctx, line, candidate, state) {
197
- const normalized = String(candidate || '');
198
- const base = path.posix.basename(normalized);
199
- if (!normalized) {
200
- return true;
201
- }
202
- if (PLACEHOLDER_PATH_RE.test(normalized)) {
203
- return true;
204
- }
205
- if (ALWAYS_AMBIGUOUS_BASENAMES.has(base) && repoHasBasename(ctx, base, state)) {
206
- return true;
207
- }
208
- if (SOFT_REFERENCE_CONTEXT_RE.test(String(line || '')) && (base === 'PLAN.md' || base === 'web_scraper.py')) {
209
- return true;
210
- }
211
- if (normalized === '.env' && lineHasEnvPolicyContext(line)) {
212
- return true;
213
- }
214
- if (lineResolvesPathSuffix(ctx, line, normalized, state)) {
215
- return true;
216
- }
217
- if (!normalized.includes('/') && lineResolvesBareCandidate(ctx, line, normalized, state)) {
218
- return true;
219
- }
220
- return false;
221
- }
222
-
223
- function resolveMissingCandidate(ctx, fromFile, candidate) {
224
- const isNestedAgentDoc = toPosix(fromFile).includes('/');
225
- const prefersRepoRoot = isNestedAgentDoc && !candidate.startsWith('../');
226
- const modes = prefersRepoRoot
227
- ? ['repo-root', 'relative-to-file']
228
- : ['relative-to-file', 'repo-root'];
229
-
230
- let firstMissing = null;
231
- for (const mode of modes) {
232
- const resolvedPath = resolveRepoPath(ctx, fromFile, candidate, mode);
233
- if (!resolvedPath || isKnownConventionPath(resolvedPath)) {
234
- continue;
235
- }
236
- if (!firstMissing) {
237
- firstMissing = resolvedPath;
238
- }
239
- if (ctx.fileContent(resolvedPath) !== null) {
240
- return { exists: true, resolvedPath };
241
- }
242
- }
243
-
244
- return { exists: false, resolvedPath: firstMissing };
245
- }
246
-
247
- function rewriteMarkdownLinksForScanning(text) {
248
- return String(text || '').replace(MARKDOWN_LINK_RE, (_match, target) => ` ${target} `);
249
- }
250
-
251
- module.exports = {
252
- key: 'agent-config-missing-file',
253
- name: 'Agent config references missing file',
254
- severity: 'high',
255
- layer: 'shallow-risk',
256
- sourceUrl: SHALLOW_RISK_DOC_URL,
257
- run(ctx) {
258
- const findings = [];
259
- const seen = new Set();
260
- const state = {
261
- basenameCache: new Map(),
262
- suffixCache: new Map(),
263
- };
264
-
265
- for (const entry of getAgentConfigEntries(ctx)) {
266
- if (!/\.(?:md|mdc|txt|rst)$/i.test(entry.path) && !/\.cursorrules$|\.windsurfrules$/i.test(entry.path)) {
267
- continue;
268
- }
269
- for (const { lineNumber, text } of getScannableLines(entry.content)) {
270
- const scanText = rewriteMarkdownLinksForScanning(text);
271
- POINTER_RE.lastIndex = 0;
272
- let match = POINTER_RE.exec(scanText);
273
- while (match) {
274
- const candidate = normalizeCandidatePath(match[1]);
275
- if (!looksLikeRelativeFileReference(candidate)) {
276
- match = POINTER_RE.exec(scanText);
277
- continue;
278
- }
279
-
280
- if (lineHasExampleContext(text)) {
281
- match = POINTER_RE.exec(scanText);
282
- continue;
283
- }
284
-
285
- if (shouldIgnoreCandidate(ctx, text, candidate, state)) {
286
- match = POINTER_RE.exec(scanText);
287
- continue;
288
- }
289
-
290
- const resolution = resolveMissingCandidate(ctx, entry.path, candidate);
291
- if (!resolution.resolvedPath || resolution.exists) {
292
- match = POINTER_RE.exec(scanText);
293
- continue;
294
- }
295
- const resolvedPath = resolution.resolvedPath;
296
-
297
- const dedupeKey = `${entry.path}:${toPosix(resolvedPath)}`;
298
- if (seen.has(dedupeKey)) {
299
- match = POINTER_RE.exec(scanText);
300
- continue;
301
- }
302
- seen.add(dedupeKey);
303
-
304
- findings.push({
305
- file: entry.path,
306
- line: lineNumber || ctx.lineNumber(entry.path, new RegExp(escapeRegExp(candidate))),
307
- fix: `${entry.path} references \`${toPosix(resolvedPath)}\`, but the file is missing. Create the file or update the agent guidance to point at a real repo path.`,
308
- });
309
-
310
- match = POINTER_RE.exec(scanText);
311
- }
312
- }
313
- }
314
-
315
- return findings;
316
- },
317
- };
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+
5
+ const {
6
+ SHALLOW_RISK_DOC_URL,
7
+ escapeRegExp,
8
+ findFirstRepoPath,
9
+ getAgentConfigEntries,
10
+ getScannableLines,
11
+ isKnownConventionPath,
12
+ lineHasExampleContext,
13
+ looksLikeRelativeFileReference,
14
+ normalizeCandidatePath,
15
+ resolveRepoPath,
16
+ toPosix,
17
+ } = require('../shared');
18
+
19
+ const POINTER_RE = /(?:^|[\s([`'"])(@?(?:\.{1,2}\/)?[A-Za-z0-9._/-]+)(?=$|[\s)\]`'",:;!?])/g;
20
+ const MARKDOWN_LINK_RE = /\[[^\]]+\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g;
21
+ const BACKTICK_TOKEN_RE = /`([^`]+)`/g;
22
+ const PLACEHOLDER_PATH_RE = /(?:^|\/)(?:path(?:_to)?|to)(?:\/|$)|(?:^|\/)test_file\.py$|(?:^|\/)path_to_test\.py$|(?:^|\/)module_name\.[A-Za-z0-9._-]+$/i;
23
+ const ENV_POLICY_RE = /\b(?:dotenv|environment variables?|api keys?|secrets?|credential|gitignore|removed\s+\.env|look for\s+\.env|via\s+`?\.env|defaults?\s+to|do not commit)\b/i;
24
+ const OWNERSHIP_CONTEXT_RE = /\b(?:subdirectory|integration|folder|workspace|extension|module|package|component|app|generated file|composition root|entrypoint|directory structure|utility functions|updated in|register feature|build from)s?(?:['’]s)?\b/i;
25
+ const SOFT_REFERENCE_CONTEXT_RE = /\b(?:can be deleted afterwards|quality scale|search result|scrape the web page content)\b/i;
26
+ const ALWAYS_AMBIGUOUS_BASENAMES = new Set([
27
+ 'findings.md',
28
+ 'manifest.json',
29
+ 'progress.md',
30
+ 'quality_scale.yaml',
31
+ 'task_plan.md',
32
+ 'todo.md',
33
+ ]);
34
+
35
+ function repoHasBasename(ctx, basename, state) {
36
+ if (!basename) {
37
+ return false;
38
+ }
39
+ if (state.basenameCache.has(basename)) {
40
+ return state.basenameCache.get(basename);
41
+ }
42
+
43
+ const match = findFirstRepoPath(ctx, (_relPath, entryName) => entryName === basename, { maxDepth: 10 });
44
+ const exists = Boolean(match);
45
+ state.basenameCache.set(basename, exists);
46
+ return exists;
47
+ }
48
+
49
+ function repoHasPathSuffix(ctx, candidate, state) {
50
+ const normalized = toPosix(candidate || '').replace(/^\.?\//, '');
51
+ if (!normalized) {
52
+ return false;
53
+ }
54
+ if (state.suffixCache.has(normalized)) {
55
+ return state.suffixCache.get(normalized);
56
+ }
57
+
58
+ const match = findFirstRepoPath(
59
+ ctx,
60
+ (relPath) => {
61
+ const normalizedPath = toPosix(relPath);
62
+ return normalizedPath === normalized || normalizedPath.endsWith(`/${normalized}`);
63
+ },
64
+ { maxDepth: 10 },
65
+ );
66
+ const exists = Boolean(match);
67
+ state.suffixCache.set(normalized, exists);
68
+ return exists;
69
+ }
70
+
71
+ function lineHasEnvPolicyContext(line) {
72
+ return ENV_POLICY_RE.test(String(line || ''));
73
+ }
74
+
75
+ function lineHasScopedOwnershipContext(line) {
76
+ const text = String(line || '');
77
+ return OWNERSHIP_CONTEXT_RE.test(text) || SOFT_REFERENCE_CONTEXT_RE.test(text) || /<[^>]+>/.test(text);
78
+ }
79
+
80
+ function extractLineAnchors(line) {
81
+ const anchors = new Set();
82
+ const text = String(line || '');
83
+
84
+ BACKTICK_TOKEN_RE.lastIndex = 0;
85
+ let match = BACKTICK_TOKEN_RE.exec(text);
86
+ while (match) {
87
+ const rawToken = String(match[1] || '');
88
+ const token = normalizeCandidatePath(rawToken)
89
+ .replace(/<[^>]+>/g, '')
90
+ .replace(/^\/+/, '')
91
+ .replace(/\/+$/, '');
92
+ if (!token || !rawToken.includes('/')) {
93
+ match = BACKTICK_TOKEN_RE.exec(text);
94
+ continue;
95
+ }
96
+ anchors.add(token);
97
+ match = BACKTICK_TOKEN_RE.exec(text);
98
+ }
99
+
100
+ MARKDOWN_LINK_RE.lastIndex = 0;
101
+ match = MARKDOWN_LINK_RE.exec(text);
102
+ while (match) {
103
+ const rawToken = String(match[1] || '');
104
+ const token = normalizeCandidatePath(rawToken)
105
+ .replace(/<[^>]+>/g, '')
106
+ .replace(/^\/+/, '')
107
+ .replace(/\/+$/, '');
108
+ if (!token || !rawToken.includes('/')) {
109
+ match = MARKDOWN_LINK_RE.exec(text);
110
+ continue;
111
+ }
112
+ anchors.add(token);
113
+ match = MARKDOWN_LINK_RE.exec(text);
114
+ }
115
+
116
+ return [...anchors];
117
+ }
118
+
119
+ function anchorDirsForToken(token) {
120
+ if (!token) {
121
+ return [];
122
+ }
123
+
124
+ const normalized = normalizeCandidatePath(token)
125
+ .replace(/<[^>]+>/g, '')
126
+ .replace(/^\/+/, '')
127
+ .replace(/\/+$/, '');
128
+ if (!normalized) {
129
+ return [];
130
+ }
131
+
132
+ const dirs = new Set();
133
+ const looksFileLike = looksLikeRelativeFileReference(normalized);
134
+ const direct = normalized.includes('/')
135
+ ? (looksFileLike ? path.posix.dirname(normalized) : normalized)
136
+ : normalized;
137
+ if (direct && direct !== '.') {
138
+ dirs.add(direct);
139
+ }
140
+
141
+ const parent = path.posix.dirname(direct || normalized);
142
+ if (parent && parent !== '.' && parent !== direct) {
143
+ dirs.add(parent);
144
+ }
145
+
146
+ return [...dirs];
147
+ }
148
+
149
+ function lineResolvesBareCandidate(ctx, line, candidate, state) {
150
+ const base = path.posix.basename(candidate);
151
+ const anchors = extractLineAnchors(line);
152
+
153
+ for (const anchor of anchors) {
154
+ const normalizedAnchor = normalizeCandidatePath(anchor);
155
+ if (path.posix.basename(normalizedAnchor) === base && (ctx.fileContent(normalizedAnchor) !== null || repoHasPathSuffix(ctx, normalizedAnchor, state))) {
156
+ return true;
157
+ }
158
+
159
+ for (const dir of anchorDirsForToken(anchor)) {
160
+ const match = findFirstRepoPath(
161
+ ctx,
162
+ (relPath, entryName) => entryName === base && toPosix(relPath).startsWith(`${dir}/`),
163
+ { maxDepth: 10 },
164
+ );
165
+ if (match) {
166
+ return true;
167
+ }
168
+ }
169
+ }
170
+
171
+ if (anchors.length > 0 && repoHasBasename(ctx, base, state)) {
172
+ return true;
173
+ }
174
+
175
+ if (lineHasScopedOwnershipContext(line) && repoHasBasename(ctx, base, state)) {
176
+ return true;
177
+ }
178
+
179
+ return false;
180
+ }
181
+
182
+ function lineHasAnchorContext(line) {
183
+ return extractLineAnchors(line).length > 0;
184
+ }
185
+
186
+ function lineResolvesPathSuffix(ctx, line, candidate, state) {
187
+ if (!candidate || !candidate.includes('/')) {
188
+ return false;
189
+ }
190
+ if (!lineHasAnchorContext(line) && !lineHasScopedOwnershipContext(line)) {
191
+ return false;
192
+ }
193
+ return repoHasPathSuffix(ctx, candidate, state);
194
+ }
195
+
196
+ function shouldIgnoreCandidate(ctx, line, candidate, state) {
197
+ const normalized = String(candidate || '');
198
+ const base = path.posix.basename(normalized);
199
+ if (!normalized) {
200
+ return true;
201
+ }
202
+ if (PLACEHOLDER_PATH_RE.test(normalized)) {
203
+ return true;
204
+ }
205
+ if (ALWAYS_AMBIGUOUS_BASENAMES.has(base) && repoHasBasename(ctx, base, state)) {
206
+ return true;
207
+ }
208
+ if (SOFT_REFERENCE_CONTEXT_RE.test(String(line || '')) && (base === 'PLAN.md' || base === 'web_scraper.py')) {
209
+ return true;
210
+ }
211
+ if (normalized === '.env' && lineHasEnvPolicyContext(line)) {
212
+ return true;
213
+ }
214
+ if (lineResolvesPathSuffix(ctx, line, normalized, state)) {
215
+ return true;
216
+ }
217
+ if (!normalized.includes('/') && lineResolvesBareCandidate(ctx, line, normalized, state)) {
218
+ return true;
219
+ }
220
+ return false;
221
+ }
222
+
223
+ function resolveMissingCandidate(ctx, fromFile, candidate) {
224
+ const isNestedAgentDoc = toPosix(fromFile).includes('/');
225
+ const prefersRepoRoot = isNestedAgentDoc && !candidate.startsWith('../');
226
+ const modes = prefersRepoRoot
227
+ ? ['repo-root', 'relative-to-file']
228
+ : ['relative-to-file', 'repo-root'];
229
+
230
+ let firstMissing = null;
231
+ for (const mode of modes) {
232
+ const resolvedPath = resolveRepoPath(ctx, fromFile, candidate, mode);
233
+ if (!resolvedPath || isKnownConventionPath(resolvedPath)) {
234
+ continue;
235
+ }
236
+ if (!firstMissing) {
237
+ firstMissing = resolvedPath;
238
+ }
239
+ if (ctx.fileContent(resolvedPath) !== null) {
240
+ return { exists: true, resolvedPath };
241
+ }
242
+ }
243
+
244
+ return { exists: false, resolvedPath: firstMissing };
245
+ }
246
+
247
+ function rewriteMarkdownLinksForScanning(text) {
248
+ return String(text || '').replace(MARKDOWN_LINK_RE, (_match, target) => ` ${target} `);
249
+ }
250
+
251
+ module.exports = {
252
+ key: 'agent-config-missing-file',
253
+ name: 'Agent config references missing file',
254
+ severity: 'high',
255
+ layer: 'shallow-risk',
256
+ sourceUrl: SHALLOW_RISK_DOC_URL,
257
+ run(ctx) {
258
+ const findings = [];
259
+ const seen = new Set();
260
+ const state = {
261
+ basenameCache: new Map(),
262
+ suffixCache: new Map(),
263
+ };
264
+
265
+ for (const entry of getAgentConfigEntries(ctx)) {
266
+ if (!/\.(?:md|mdc|txt|rst)$/i.test(entry.path) && !/\.cursorrules$|\.windsurfrules$/i.test(entry.path)) {
267
+ continue;
268
+ }
269
+ for (const { lineNumber, text } of getScannableLines(entry.content)) {
270
+ const scanText = rewriteMarkdownLinksForScanning(text);
271
+ POINTER_RE.lastIndex = 0;
272
+ let match = POINTER_RE.exec(scanText);
273
+ while (match) {
274
+ const candidate = normalizeCandidatePath(match[1]);
275
+ if (!looksLikeRelativeFileReference(candidate)) {
276
+ match = POINTER_RE.exec(scanText);
277
+ continue;
278
+ }
279
+
280
+ if (lineHasExampleContext(text)) {
281
+ match = POINTER_RE.exec(scanText);
282
+ continue;
283
+ }
284
+
285
+ if (shouldIgnoreCandidate(ctx, text, candidate, state)) {
286
+ match = POINTER_RE.exec(scanText);
287
+ continue;
288
+ }
289
+
290
+ const resolution = resolveMissingCandidate(ctx, entry.path, candidate);
291
+ if (!resolution.resolvedPath || resolution.exists) {
292
+ match = POINTER_RE.exec(scanText);
293
+ continue;
294
+ }
295
+ const resolvedPath = resolution.resolvedPath;
296
+
297
+ const dedupeKey = `${entry.path}:${toPosix(resolvedPath)}`;
298
+ if (seen.has(dedupeKey)) {
299
+ match = POINTER_RE.exec(scanText);
300
+ continue;
301
+ }
302
+ seen.add(dedupeKey);
303
+
304
+ findings.push({
305
+ file: entry.path,
306
+ line: lineNumber || ctx.lineNumber(entry.path, new RegExp(escapeRegExp(candidate))),
307
+ fix: `${entry.path} references \`${toPosix(resolvedPath)}\`, but the file is missing. Create the file or update the agent guidance to point at a real repo path.`,
308
+ });
309
+
310
+ match = POINTER_RE.exec(scanText);
311
+ }
312
+ }
313
+ }
314
+
315
+ return findings;
316
+ },
317
+ };