@aryam/fixmap-core 0.8.7 → 0.8.9

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 (59) hide show
  1. package/README.md +5 -1
  2. package/dist/browser.d.ts +5 -1
  3. package/dist/browser.js +3 -1
  4. package/dist/browser.js.map +1 -1
  5. package/dist/cli-quote.d.ts +3 -0
  6. package/dist/cli-quote.js +9 -0
  7. package/dist/cli-quote.js.map +1 -0
  8. package/dist/compare.js +45 -12
  9. package/dist/compare.js.map +1 -1
  10. package/dist/exclude.d.ts +2 -0
  11. package/dist/exclude.js +8 -3
  12. package/dist/exclude.js.map +1 -1
  13. package/dist/explain.js +24 -17
  14. package/dist/explain.js.map +1 -1
  15. package/dist/grounding.d.ts +3 -1
  16. package/dist/grounding.js +24 -19
  17. package/dist/grounding.js.map +1 -1
  18. package/dist/import-graph.d.ts +2 -0
  19. package/dist/import-graph.js +84 -10
  20. package/dist/import-graph.js.map +1 -1
  21. package/dist/index.d.ts +6 -1
  22. package/dist/index.js +4 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/languages.d.ts +1 -1
  25. package/dist/languages.js +60 -12
  26. package/dist/languages.js.map +1 -1
  27. package/dist/markdown.d.ts +2 -0
  28. package/dist/markdown.js +8 -0
  29. package/dist/markdown.js.map +1 -0
  30. package/dist/paths.d.ts +8 -0
  31. package/dist/paths.js +38 -8
  32. package/dist/paths.js.map +1 -1
  33. package/dist/plan.d.ts +3 -1
  34. package/dist/plan.js +58 -15
  35. package/dist/plan.js.map +1 -1
  36. package/dist/rank.d.ts +9 -0
  37. package/dist/rank.js +171 -90
  38. package/dist/rank.js.map +1 -1
  39. package/dist/repo-scan.d.ts +3 -1
  40. package/dist/repo-scan.js +615 -116
  41. package/dist/repo-scan.js.map +1 -1
  42. package/dist/report.d.ts +6 -0
  43. package/dist/report.js +92 -55
  44. package/dist/report.js.map +1 -1
  45. package/dist/signals.d.ts +7 -0
  46. package/dist/signals.js +150 -44
  47. package/dist/signals.js.map +1 -1
  48. package/dist/test-gates.js +15 -3
  49. package/dist/test-gates.js.map +1 -1
  50. package/dist/text.d.ts +2 -0
  51. package/dist/text.js +4 -0
  52. package/dist/text.js.map +1 -1
  53. package/dist/types.d.ts +8 -2
  54. package/dist/validate.d.ts +10 -0
  55. package/dist/validate.js +188 -0
  56. package/dist/validate.js.map +1 -0
  57. package/dist/verify.js +48 -6
  58. package/dist/verify.js.map +1 -1
  59. package/package.json +1 -1
package/dist/rank.js CHANGED
@@ -1,12 +1,16 @@
1
1
  import { NO_EXCLUSIONS } from "./exclude.js";
2
2
  import { buildImportGraph, findImportProximity } from "./import-graph.js";
3
- import { analyzeTaskGrounding, buildGroundedTaskTokens } from "./grounding.js";
4
- import { isBackupPath, isGeneratedPath, isRecordedEvaluationOutput, moduleStem } from "./paths.js";
3
+ import { analyzeTaskGrounding, buildRankingShape, buildGroundedTaskTokens, CLUSTERED_RANKING_MARGIN, isVagueTaskText } from "./grounding.js";
4
+ import { isBackupPath, isGeneratedPath, isRecordedEvaluationOutput, LOCKFILE_NAMES, moduleStem, pathMatchesMention } from "./paths.js";
5
5
  import { extractTaskSignals, tokenizePath, tokenizeText } from "./signals.js";
6
6
  const DEPLOYMENT_TERMS = [
7
- "deploy", "deployment", "vercel", "netlify", "docker", "kubernetes", "hosting", "serverless", "production", "404", "500", "502"
7
+ "deploy", "deployment", "vercel", "netlify", "docker", "kubernetes", "hosting", "serverless", "production"
8
8
  ];
9
- const LOCKFILES = new Set(["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lock", "bun.lockb"]);
9
+ const CONFIGURATION_TERMS = ["config", "configuration", "workflow", "action", "ci", "yaml"];
10
+ const PRESENTATION_TERMS = [
11
+ "browser", "button", "client", "display", "form", "frontend", "layout", "page", "screen", "ui", "visitor", "web", "website"
12
+ ];
13
+ export const RANKING_SIGNAL_TERMS = [...DEPLOYMENT_TERMS, ...CONFIGURATION_TERMS, ...PRESENTATION_TERMS];
10
14
  const AUXILIARY_CODE_DIRS = new Set(["demo", "demos", "example", "examples", "sample", "samples"]);
11
15
  const COMPILED_TO_SOURCE_MENTION_EXTENSIONS = {
12
16
  ".js": [".ts", ".tsx"],
@@ -18,10 +22,14 @@ const MAX_FILES_PER_MENTION = 5;
18
22
  const MAX_PROXIMITY_SEEDS = 5;
19
23
  const IMPORT_PROXIMITY_BOOSTS = { 1: 4, 2: 2 };
20
24
  const EXAMPLE_CODE_PENALTY = 8;
25
+ const AUXILIARY_REPRODUCTION_PENALTY = 20;
21
26
  const PRESENTATION_CODE_PENALTY = 8;
27
+ const INTERACTIVE_PRESENTATION_BOOST = 4;
22
28
  const TYPE_DECLARATION_PENALTY = 4;
29
+ const TYPE_DECLARATION_DIRECT_PENALTY = 8;
23
30
  const BACKUP_COPY_PENALTY = 10;
24
- const BUNDLED_OUTPUT_PENALTY = 12;
31
+ const BUNDLED_OUTPUT_PENALTY = 16;
32
+ const GENERATED_TWIN_PENALTY = 21;
25
33
  const GENERATED_TWIN_REASON = "generated build artifact; maintained source counterpart exists";
26
34
  // Bundlers strip newlines; people do not. A file averaging hundreds of characters per
27
35
  // line is machine output, whatever directory it sits in. Repositories commit these —
@@ -43,7 +51,7 @@ const BUNDLE_MARKERS = [
43
51
  /\b__defProp\s*=/,
44
52
  /\/\/# sourceMappingURL=/
45
53
  ];
46
- const EXPLICIT_PATH_BOOST = 40;
54
+ const EXPLICIT_PATH_BOOST = 60;
47
55
  const EXACT_LITERAL_BOOST = 8;
48
56
  const MEMBER_MENTION_BOOST = 8;
49
57
  // A term counts as repository-wide boilerplate only when nearly every file carries it.
@@ -57,10 +65,13 @@ const MAX_DEFINITION_IDENTIFIERS = 2;
57
65
  const TASK_MATCHED_DEFINITION_BOOST = 4;
58
66
  // How close to the leader a file must score to share its "high" label. Two points matches
59
67
  // the window `isClusteredRanking` already treats as indistinguishable.
60
- const HIGH_CONFIDENCE_MARGIN = 2;
68
+ const HIGH_CONFIDENCE_MARGIN = CLUSTERED_RANKING_MARGIN;
61
69
  export const REPORT_SCORE_CUTOFF = 4;
62
70
  export const DEFAULT_CONTEXT_FILE_LIMIT = 8;
63
- export function rankContextFiles(repo, input, limit = DEFAULT_CONTEXT_FILE_LIMIT,
71
+ export function rankContextFiles(repo, input, limit = DEFAULT_CONTEXT_FILE_LIMIT, minScore = REPORT_SCORE_CUTOFF) {
72
+ return rankContextFilesDetailed(repo, input, limit, minScore).contextFiles;
73
+ }
74
+ export function rankContextFilesDetailed(repo, input, limit = DEFAULT_CONTEXT_FILE_LIMIT,
64
75
  // `explainFile` lowers this to see what a file scored below the reporting cutoff.
65
76
  // Ranking never calls it with anything but the default.
66
77
  minScore = REPORT_SCORE_CUTOFF) {
@@ -76,8 +87,7 @@ minScore = REPORT_SCORE_CUTOFF) {
76
87
  diffText: input.diffText ?? "",
77
88
  changedFiles: repo.changedFiles
78
89
  });
79
- const mentionedPaths = matchMentionedPaths(signals.fileMentions, repo.files.map((file) => file.path));
80
- const taskTargetsEvaluation = hasAny(taskTokens, ["benchmark", "benchmarks", "evaluation", "evaluate"]);
90
+ const mentionedPaths = matchMentionedPaths(signals.fileMentions, repo.files.map((file) => file.path), repo.root);
81
91
  // Excluded before anything else reads the candidate set. The boilerplate threshold below
82
92
  // is a share of that set, so removing files later would leave scoring computed against a
83
93
  // population that no longer exists.
@@ -85,8 +95,7 @@ minScore = REPORT_SCORE_CUTOFF) {
85
95
  (mentionedPaths.has(file.path) ||
86
96
  (file.isSource &&
87
97
  !file.isTest &&
88
- !LOCKFILES.has(file.path.split("/").pop() ?? "") &&
89
- (!file.path.startsWith("benchmarks/") || taskTargetsEvaluation))));
98
+ !LOCKFILE_NAMES.has(file.path.split("/").pop() ?? ""))));
90
99
  // Generated output is kept only when the source it came from is absent. chalk's sole
91
100
  // color-detection implementation lives in `source/vendor/`, so it stays; a committed
92
101
  // bundle beside the module it was built from does not, because editing it is always
@@ -94,25 +103,32 @@ minScore = REPORT_SCORE_CUTOFF) {
94
103
  const maintainedStems = new Set(scannable
95
104
  .filter((file) => !isGeneratedPath(file.path) && !isBackupPath(file.path))
96
105
  .map((file) => moduleStem(file.path)));
97
- const candidates = scannable.filter((file) => !isRecordedEvaluationOutput(file.path) && (mentionedPaths.has(file.path) ||
106
+ const candidateFiles = scannable.filter((file) => !isRecordedEvaluationOutput(file.path) && (mentionedPaths.has(file.path) ||
98
107
  signals.changedFiles.has(file.path) ||
99
108
  !isGeneratedPath(file.path) ||
100
109
  !maintainedStems.has(moduleStem(file.path))));
101
- const contentTokensByPath = new Map(candidates.map((file) => [file.path, tokenizeFileContent(file.textSample)]));
110
+ const regexTokensByPath = new Map(candidateFiles.map((file) => [file.path, extractRegexTokens(file.textSample)]));
111
+ const contentTokensByPath = new Map(candidateFiles.map((file) => [
112
+ file.path,
113
+ tokenizeFileContent(file.textSample, regexTokensByPath.get(file.path) ?? new Set())
114
+ ]));
102
115
  const commonTokens = findCommonTokens(contentTokensByPath);
103
116
  const allTaskTermsAreWidespread = taskTokens.size > 0 &&
104
117
  [...taskTokens].every((token) => commonTokens.has(token));
105
118
  const definitionSignals = buildDefinitionSignals(signals.identifiers);
119
+ const memberSignals = [...signals.memberMentions].map((member) => ({
120
+ member,
121
+ pattern: exactIdentifierPattern(member)
122
+ }));
106
123
  const taskText = [input.issueText ?? "", input.diffText ?? ""].join("\n");
124
+ const exactFragmentOccurrences = new Map(signals.exactFragments.map((fragment) => [fragment, countOccurrences(taskText, fragment)]));
107
125
  const taskTargetsDocumentation = targetsDocumentation(taskText);
108
- const taskTargetsConfiguration = hasAny(taskTokens, ["config", "configuration", "workflow", "action", "ci", "yaml"]);
109
- const taskTargetsDeployment = hasAny(taskTokens, DEPLOYMENT_TERMS);
126
+ const taskTargetsConfiguration = hasAnyNormalized(taskTokens, taskText, CONFIGURATION_TERMS);
127
+ const taskTargetsDeployment = hasAnyNormalized(taskTokens, taskText, DEPLOYMENT_TERMS);
110
128
  const taskTargetsExamples = /\b(?:demos?|examples?|samples?)\b/i.test(taskText.replace(/\bfor example\b/gi, ""));
111
- const taskTargetsPresentation = hasAny(taskTokens, [
112
- "browser", "button", "client", "display", "form", "frontend", "layout", "page", "screen", "ui", "visitor", "web", "website"
113
- ]);
129
+ const taskTargetsPresentation = hasAnyNormalized(taskTokens, taskText, PRESENTATION_TERMS);
114
130
  const taskTargetsTypeDeclarations = /\b(?:typescript|types?|type definitions?|declarations?|typings?|\.d\.(?:ts|mts|cts))\b/i.test(taskText);
115
- const scored = candidates
131
+ const scored = candidateFiles
116
132
  .map((file) => {
117
133
  const reasons = [];
118
134
  let score = 0;
@@ -126,13 +142,25 @@ minScore = REPORT_SCORE_CUTOFF) {
126
142
  reasons.push("explicitly named in the task");
127
143
  }
128
144
  if (isGeneratedPath(file.path) && maintainedStems.has(moduleStem(file.path))) {
145
+ score -= GENERATED_TWIN_PENALTY;
129
146
  reasons.push(GENERATED_TWIN_REASON);
147
+ reasons.push("generated counterpart deprioritized below maintained source");
130
148
  }
131
149
  const pathTokens = tokenizePath(file.path);
132
150
  const pathOverlap = [...pathTokens].filter((token) => taskTokens.has(token));
133
151
  if (pathOverlap.length > 0) {
134
152
  score += pathOverlap.length * 3;
135
153
  reasons.push(`path matches task terms: ${pathOverlap.join(", ")}`);
154
+ if (pathOverlap.length >= 2) {
155
+ score += 4;
156
+ reasons.push("multiple task terms converge in the file path");
157
+ const fileName = file.path.split("/").at(-1)?.replace(/\.[^.]+$/, "") ?? "";
158
+ const fileNameTokens = tokenizeText(fileName);
159
+ if (fileNameTokens.size === 1 && [...fileNameTokens].some((token) => taskTokens.has(token))) {
160
+ score += 5;
161
+ reasons.push("file module name exactly matches a task term");
162
+ }
163
+ }
136
164
  }
137
165
  const contentTokens = contentTokensByPath.get(file.path) ?? new Set();
138
166
  const contentOverlap = [...contentTokens].filter((token) => taskTokens.has(token) && (allTaskTermsAreWidespread || !commonTokens.has(token)));
@@ -140,13 +168,16 @@ minScore = REPORT_SCORE_CUTOFF) {
140
168
  score += Math.min(contentOverlap.length, 8) * 2;
141
169
  reasons.push(`content matches task terms: ${contentOverlap.slice(0, 8).join(", ")}`);
142
170
  }
143
- const regexTokenOverlap = findRegexTokenOverlap(file.textSample, taskTokens);
171
+ const regexTokenOverlap = [...(regexTokensByPath.get(file.path) ?? [])]
172
+ .filter((token) => taskTokens.has(token))
173
+ .slice(0, 2);
144
174
  if (regexTokenOverlap.length > 0) {
145
175
  score += Math.min(regexTokenOverlap.length, 2) * 12;
146
176
  reasons.push(`regex literal matches task tokens: ${regexTokenOverlap.join(", ")}`);
147
177
  }
148
- const matchedMembers = [...signals.memberMentions]
149
- .filter((member) => hasExactIdentifier(file.textSample, member))
178
+ const matchedMembers = memberSignals
179
+ .filter((signal) => signal.pattern.test(file.textSample))
180
+ .map((signal) => signal.member)
150
181
  .slice(0, 3);
151
182
  if (matchedMembers.length > 0) {
152
183
  score += matchedMembers.length * MEMBER_MENTION_BOOST;
@@ -154,10 +185,10 @@ minScore = REPORT_SCORE_CUTOFF) {
154
185
  }
155
186
  const exactLiteral = signals.exactFragments
156
187
  .filter((fragment) => file.textSample.includes(fragment))
157
- .sort((a, b) => countOccurrences(taskText, b) - countOccurrences(taskText, a) ||
188
+ .sort((a, b) => (exactFragmentOccurrences.get(b) ?? 0) - (exactFragmentOccurrences.get(a) ?? 0) ||
158
189
  b.length - a.length)[0];
159
190
  if (exactLiteral) {
160
- score += EXACT_LITERAL_BOOST * Math.min(3, countOccurrences(taskText, exactLiteral));
191
+ score += EXACT_LITERAL_BOOST * Math.min(3, exactFragmentOccurrences.get(exactLiteral) ?? 0);
161
192
  reasons.push(`contains exact task literal: ${previewFragment(exactLiteral)}`);
162
193
  }
163
194
  const definedIdentifiers = (file.kind === "documentation" ? [] : findDefinedIdentifiers(file.textSample, definitionSignals))
@@ -165,10 +196,17 @@ minScore = REPORT_SCORE_CUTOFF) {
165
196
  if (definedIdentifiers.length > 0) {
166
197
  score += definedIdentifiers.length * DEFINITION_IDENTIFIER_BOOST;
167
198
  reasons.push(`defines task identifiers: ${definedIdentifiers.join(", ")}`);
199
+ if (file.kind === "code" &&
200
+ !file.isTest &&
201
+ !isAuxiliaryCodePath(file.path) &&
202
+ !isTypeDeclarationPath(file.path) &&
203
+ !file.path.toLowerCase().startsWith("benchmarks/")) {
204
+ score += 4;
205
+ reasons.push("task identifier is defined in maintained implementation source");
206
+ }
168
207
  }
169
208
  const taskMatchedDefinitions = signals.exactFragments.length === 0 &&
170
- !taskTargetsDocumentation &&
171
- !taskTargetsPresentation
209
+ !taskTargetsDocumentation
172
210
  ? (file.kind === "documentation" ? [] : findTaskMatchedDefinitions(file.textSample, taskTokens))
173
211
  .filter((identifier) => !definedIdentifiers.includes(identifier))
174
212
  .slice(0, MAX_DEFINITION_IDENTIFIERS)
@@ -204,7 +242,7 @@ minScore = REPORT_SCORE_CUTOFF) {
204
242
  else if (file.kind === "config" && !isChanged) {
205
243
  score -= 4;
206
244
  }
207
- const isDeploymentConfig = file.path === "package.json" || DEPLOYMENT_TERMS.some((term) => pathTokens.has(term));
245
+ const isDeploymentConfig = file.path === "package.json" || DEPLOYMENT_TERMS.some((term) => [...tokenizeText(term)].some((token) => pathTokens.has(token)));
208
246
  if (taskTargetsDeployment && file.kind === "config" && !file.path.includes("/") && isDeploymentConfig) {
209
247
  score += 5;
210
248
  reasons.push("root configuration for a deployment-related task");
@@ -217,14 +255,24 @@ minScore = REPORT_SCORE_CUTOFF) {
217
255
  !mentionedPaths.has(file.path)) {
218
256
  score -= EXAMPLE_CODE_PENALTY;
219
257
  reasons.push("example or demo code deprioritized for an implementation task");
258
+ if (exactLiteral && definedIdentifiers.length > 0) {
259
+ score -= AUXILIARY_REPRODUCTION_PENALTY;
260
+ reasons.push("task reproduction evidence is weaker in auxiliary example code");
261
+ }
220
262
  }
221
- if (isPresentationSurfacePath(file.path) &&
222
- !taskTargetsPresentation &&
223
- !taskTargetsExamples &&
224
- !isChanged &&
225
- !mentionedPaths.has(file.path)) {
226
- score -= PRESENTATION_CODE_PENALTY;
227
- reasons.push("presentation or demo surface deprioritized for a non-UI implementation task");
263
+ if (isPresentationSurfacePath(file.path)) {
264
+ if (taskTargetsPresentation) {
265
+ score += PRESENTATION_CODE_PENALTY;
266
+ reasons.push("presentation surface matches a UI-focused task");
267
+ if (isInteractivePresentation(file.textSample)) {
268
+ score += INTERACTIVE_PRESENTATION_BOOST;
269
+ reasons.push("interactive presentation surface matches the requested user flow");
270
+ }
271
+ }
272
+ else if (!taskTargetsExamples && !isChanged && !mentionedPaths.has(file.path)) {
273
+ score -= PRESENTATION_CODE_PENALTY;
274
+ reasons.push("presentation or demo surface deprioritized for a non-UI implementation task");
275
+ }
228
276
  }
229
277
  if (isTypeDeclarationPath(file.path) &&
230
278
  !taskTargetsTypeDeclarations &&
@@ -232,6 +280,10 @@ minScore = REPORT_SCORE_CUTOFF) {
232
280
  !mentionedPaths.has(file.path)) {
233
281
  score -= TYPE_DECLARATION_PENALTY;
234
282
  reasons.push("type declaration deprioritized for a runtime task");
283
+ if (definedIdentifiers.length > 0) {
284
+ score -= TYPE_DECLARATION_DIRECT_PENALTY;
285
+ reasons.push("runtime implementation preferred over a matching declaration");
286
+ }
235
287
  }
236
288
  else if (isTypeDeclarationPath(file.path) &&
237
289
  taskTargetsTypeDeclarations &&
@@ -256,24 +308,27 @@ minScore = REPORT_SCORE_CUTOFF) {
256
308
  return { path: file.path, score, isChanged, reasons };
257
309
  });
258
310
  applyImportProximity(scored, repo);
259
- const ranked = scored
311
+ const candidates = scored
260
312
  .filter((file) => file.score >= minScore)
261
- .sort((a, b) => b.score - a.score || a.path.localeCompare(b.path))
262
- .slice(0, limit);
263
- const clustered = isClusteredRanking(ranked);
264
- const leadIsContested = hasContestedLead(ranked);
265
- return ranked
313
+ .sort((a, b) => b.score - a.score || a.path.localeCompare(b.path));
314
+ const ranking = buildRankingShape(candidates);
315
+ const clustered = ranking.clustered;
316
+ const leadIsContested = hasContestedLead(candidates);
317
+ const ranked = candidates.slice(0, limit);
318
+ const contextFiles = ranked
266
319
  .map((entry, position) => ({
267
320
  rank: position + 1,
268
321
  path: entry.path,
269
322
  score: entry.score,
270
323
  confidence: confidenceForEntry(entry, grounding, clustered, {
271
324
  position,
272
- topScore: ranked[0]?.score ?? entry.score,
273
- leadIsContested
325
+ topScore: candidates[0]?.score ?? entry.score,
326
+ leadIsContested,
327
+ issueIsVague: isVagueTaskText(input.issueText ?? "")
274
328
  }),
275
329
  reasons: entry.reasons.length > 0 ? entry.reasons : ["source file baseline"]
276
330
  }));
331
+ return { contextFiles, ranking };
277
332
  }
278
333
  /**
279
334
  * Is the leading file's claim disputed by a definition site behind it?
@@ -301,16 +356,31 @@ function hasDefinitionEvidence(entry) {
301
356
  reason.startsWith("exact task literal at definition:"));
302
357
  }
303
358
  function applyImportProximity(scored, repo) {
304
- const seedEntries = scored
359
+ const directSeeds = scored
305
360
  .filter((entry) => entry.score >= 8 && hasDirectEvidence(entry))
306
361
  .sort((a, b) => b.score - a.score || a.path.localeCompare(b.path))
307
362
  .slice(0, MAX_PROXIMITY_SEEDS);
363
+ const seedEntries = directSeeds.length > 0
364
+ ? directSeeds
365
+ : scored
366
+ .filter((entry) => entry.score >= 8)
367
+ .sort((a, b) => b.score - a.score || a.path.localeCompare(b.path))
368
+ .slice(0, 2);
308
369
  if (seedEntries.length === 0) {
309
370
  return;
310
371
  }
311
372
  const seeds = seedEntries.map((entry) => entry.path);
312
373
  const seedScores = new Map(seedEntries.map((entry) => [entry.path, entry.score]));
313
- const proximity = findImportProximity(buildImportGraph(repo.files), seeds);
374
+ const graph = buildImportGraph(repo.files);
375
+ if ((graph.truncatedFiles > 0 || graph.truncatedEdges > 0) && !repo.diagnostics.some((entry) => entry.code === "import-graph-truncated")) {
376
+ repo.diagnostics.push({
377
+ code: "import-graph-truncated",
378
+ severity: "info",
379
+ message: `Import proximity was bounded: ${graph.truncatedFiles.toLocaleString()} parseable files and ` +
380
+ `${graph.truncatedEdges.toLocaleString()} high-fanout files were not fully traversed. Ranking still uses path and content evidence.`
381
+ });
382
+ }
383
+ const proximity = findImportProximity(graph, seeds);
314
384
  for (const entry of scored) {
315
385
  const hit = proximity.get(entry.path);
316
386
  if (hit) {
@@ -332,9 +402,6 @@ function proximityReason(hit) {
332
402
  return hit.direction === "imported-by" ? `imported by ranked file ${hit.seed}` : `imports ranked file ${hit.seed}`;
333
403
  }
334
404
  function confidenceForEntry(entry, grounding, clustered, shape) {
335
- if (entry.isChanged) {
336
- return "high";
337
- }
338
405
  const hasMaintainedSourceTwin = entry.reasons.includes(GENERATED_TWIN_REASON);
339
406
  if (entry.reasons.includes("explicitly named in the task") &&
340
407
  shape.position === 0 &&
@@ -359,6 +426,14 @@ function confidenceForEntry(entry, grounding, clustered, shape) {
359
426
  if (hasMaintainedSourceTwin) {
360
427
  confidence = capConfidence(confidence, "medium");
361
428
  }
429
+ // A large lexical score and a wide lead can still be a convincing match to an absent
430
+ // feature (for example, a generic `hasFlag` helper in a repository with no CLI). Reserve
431
+ // high confidence for a changed file, an explicit path, or an exact identifier/literal
432
+ // definition. Vocabulary-only leaders remain useful, but are honest medium-confidence
433
+ // investigation targets.
434
+ if (!hasDirectEvidence(entry)) {
435
+ confidence = capConfidence(confidence, "medium");
436
+ }
362
437
  const supportedIdentifierCount = grounding.identifiers.filter((identifier) => identifier.status === "exact-definition" ||
363
438
  identifier.status === "exact-text" ||
364
439
  identifier.status === "partial-definition").length;
@@ -377,7 +452,7 @@ function confidenceForEntry(entry, grounding, clustered, shape) {
377
452
  if (grounding.partiallyResolvedIdentifiers.length > 0) {
378
453
  confidence = capConfidence(confidence, "medium");
379
454
  }
380
- if (grounding.specificity === "vague") {
455
+ if (grounding.specificity === "vague" || shape.issueIsVague) {
381
456
  return "low";
382
457
  }
383
458
  if (!grounding.scanComplete) {
@@ -397,17 +472,20 @@ function hasDirectEvidence(entry) {
397
472
  reason.startsWith("defines task identifiers:") ||
398
473
  reason.startsWith("exact task literal at definition:"));
399
474
  }
400
- function isClusteredRanking(entries) {
401
- const top = entries[0]?.score;
402
- const third = entries[2]?.score;
403
- return top !== undefined && third !== undefined && top - third <= 2;
404
- }
405
- function hasAny(tokens, values) {
406
- return values.some((value) => tokens.has(value));
475
+ function hasAnyNormalized(tokens, rawText, values) {
476
+ return values.some((value) => {
477
+ const normalized = tokenizeText(value);
478
+ if (normalized.size > 0 && [...normalized].every((token) => tokens.has(token)))
479
+ return true;
480
+ return new RegExp(`(^|[^\\p{L}\\p{N}_])${escapeRegExp(value)}(?=$|[^\\p{L}\\p{N}_])`, "iu").test(rawText);
481
+ });
407
482
  }
408
- function matchMentionedPaths(mentions, repoPaths) {
483
+ function matchMentionedPaths(mentions, repoPaths, repoRoot) {
409
484
  const matched = new Set();
410
- for (const mention of mentions) {
485
+ for (const rawMention of mentions) {
486
+ const mention = repositoryRelativeMention(rawMention, repoRoot);
487
+ if (!mention)
488
+ continue;
411
489
  const exactMatches = repoPaths.filter((path) => pathMatchesMention(path, mention));
412
490
  if (exactMatches.length > 0) {
413
491
  if (exactMatches.length <= MAX_FILES_PER_MENTION) {
@@ -427,8 +505,15 @@ function matchMentionedPaths(mentions, repoPaths) {
427
505
  }
428
506
  return matched;
429
507
  }
430
- function pathMatchesMention(path, mention) {
431
- return path === mention || path.endsWith(`/${mention}`) || mention.endsWith(`/${path}`);
508
+ function repositoryRelativeMention(mention, repoRoot) {
509
+ const normalizedMention = mention.replace(/\\/g, "/");
510
+ if (!/^(?:[A-Za-z]:\/|\/)/.test(normalizedMention))
511
+ return normalizedMention;
512
+ const normalizedRoot = repoRoot.replace(/\\/g, "/").replace(/\/$/, "");
513
+ const prefix = `${normalizedRoot}/`;
514
+ return normalizedMention.toLowerCase().startsWith(prefix.toLowerCase())
515
+ ? normalizedMention.slice(prefix.length)
516
+ : undefined;
432
517
  }
433
518
  function compiledSourcePathVariants(path) {
434
519
  const lowerPath = path.toLowerCase();
@@ -444,31 +529,26 @@ function compiledSourcePathVariants(path) {
444
529
  function isAuxiliaryCodePath(path) {
445
530
  const parts = path.split("/");
446
531
  const stem = (parts.at(-1) ?? "").replace(/\.[^.]+$/, "").toLowerCase();
447
- return parts.slice(0, -1).some((segment) => AUXILIARY_CODE_DIRS.has(segment.toLowerCase())) ||
448
- /^(?:demo|example|sample)(?:[-_.]|$)/.test(stem);
532
+ const parentSegments = parts.slice(0, -1).map((segment) => segment.toLowerCase());
533
+ return parentSegments.some((segment) => AUXILIARY_CODE_DIRS.has(segment)) ||
534
+ (stem === "sample-repo" && parentSegments.some((segment) => segment === "web" || segment === "website"));
449
535
  }
450
536
  function isPresentationSurfacePath(path) {
451
537
  const name = path.split("/").at(-1)?.toLowerCase() ?? "";
452
- return /^(?:page|layout|demo|sample-repo)\.[cm]?[jt]sx?$/.test(name) ||
538
+ return /^(?:page|layout|demo)\.[cm]?[jt]sx?$/.test(name) ||
453
539
  /\.(?:css|less|sass|scss)$/.test(name);
454
540
  }
455
- function tokenizeFileContent(text) {
541
+ function isInteractivePresentation(text) {
542
+ return /<(?:button|form|input|select|textarea)\b|\bon(?:Change|Click|Input|Submit)\s*=|\buseState\s*\(/.test(text);
543
+ }
544
+ function tokenizeFileContent(text, regexTokens) {
456
545
  const tokens = tokenizeText(text);
457
- for (const match of text.matchAll(/\b([A-Za-z])\{(\d+),(\d+)\}/g)) {
458
- const character = match[1]?.toLowerCase();
459
- const minimum = Number(match[2]);
460
- const maximum = Math.min(Number(match[3]), 8);
461
- if (!character || !Number.isSafeInteger(minimum) || !Number.isSafeInteger(maximum)) {
462
- continue;
463
- }
464
- for (let length = Math.max(3, minimum); length <= maximum; length += 1) {
465
- tokens.add(character.repeat(length));
466
- }
467
- }
546
+ for (const token of regexTokens)
547
+ tokens.add(token);
468
548
  return tokens;
469
549
  }
470
- function findRegexTokenOverlap(text, taskTokens) {
471
- const overlap = new Set();
550
+ function extractRegexTokens(text) {
551
+ const tokens = new Set();
472
552
  for (const match of text.matchAll(/\b([A-Za-z])\{(\d+),(\d+)\}/g)) {
473
553
  const character = match[1]?.toLowerCase();
474
554
  const minimum = Number(match[2]);
@@ -477,13 +557,10 @@ function findRegexTokenOverlap(text, taskTokens) {
477
557
  continue;
478
558
  }
479
559
  for (let length = Math.max(3, minimum); length <= maximum; length += 1) {
480
- const token = character.repeat(length);
481
- if (taskTokens.has(token)) {
482
- overlap.add(token);
483
- }
560
+ tokens.add(character.repeat(length));
484
561
  }
485
562
  }
486
- return [...overlap].slice(0, 2);
563
+ return tokens;
487
564
  }
488
565
  function isBundledOutput(textSample, path) {
489
566
  if (textSample.length < MIN_BUNDLE_SAMPLE_BYTES) {
@@ -509,35 +586,39 @@ function isTypeDeclarationPath(path) {
509
586
  return /\.d\.(?:ts|mts|cts)$/i.test(path);
510
587
  }
511
588
  function targetsDocumentation(taskText) {
512
- const documentation = "(?:docs?|documentation|readme|guide|copy)";
513
- const action = "(?:add|edit|update|write|rewrite|revise|remove|correct|document|improve)";
589
+ const documentation = "(?:docs?|documentation|readme|guide)";
590
+ const action = "(?:add|change|correct|document|edit|fix|improve|remove|revise|rewrite|update|write)";
591
+ const defect = "(?:typos?|spelling|grammar|wording|broken links?)";
514
592
  return (new RegExp(`\\b${action}\\b[^\\n.]{0,60}\\b${documentation}\\b`, "i").test(taskText) ||
515
- new RegExp(`\\b${documentation}\\b[^\\n.]{0,60}\\b${action}\\b`, "i").test(taskText));
593
+ new RegExp(`\\b${documentation}\\b[^\\n.]{0,60}\\b${action}\\b`, "i").test(taskText) ||
594
+ new RegExp(`\\b${defect}\\b[^\\n.]{0,60}\\b${documentation}\\b`, "i").test(taskText) ||
595
+ new RegExp(`\\b${documentation}\\b[^\\n.]{0,60}\\b${defect}\\b`, "i").test(taskText) ||
596
+ /\b(?:marketing|landing|website|page|button|label|headline|cta)\s+copy\b/i.test(taskText));
516
597
  }
517
598
  function buildDefinitionSignals(identifiers) {
518
599
  return [...identifiers]
519
600
  .sort((a, b) => a.localeCompare(b))
520
601
  .map((identifier) => ({
521
602
  identifier,
522
- pattern: new RegExp(`\\b(?:export\\s+)?(?:async\\s+)?(?:const|let|var|function|class|interface|type|enum|def|fn|struct|trait)\\s+${escapeRegExp(identifier)}\\b`)
603
+ pattern: new RegExp(`(?<![\\p{L}\\p{N}_$])(?:export\\s+)?(?:async\\s+)?(?:function\\s*\\*?\\s*|(?:const|let|var|class|interface|type|enum|def|fn|func|fun|struct|trait)\\s+)${escapeRegExp(identifier)}(?![\\p{L}\\p{N}_$])`, "u")
523
604
  }));
524
605
  }
525
606
  function findDefinedIdentifiers(text, signals) {
526
607
  return signals.filter((signal) => signal.pattern.test(text)).map((signal) => signal.identifier);
527
608
  }
528
- function hasExactIdentifier(text, identifier) {
529
- return new RegExp(`(^|[^$A-Za-z0-9_])${escapeRegExp(identifier)}(?=$|[^$A-Za-z0-9_])`).test(text);
609
+ function exactIdentifierPattern(identifier) {
610
+ return new RegExp(`(?<![\\p{L}\\p{N}_$])${escapeRegExp(identifier)}(?![\\p{L}\\p{N}_$])`, "u");
530
611
  }
531
612
  function findTaskMatchedDefinitions(text, taskTokens) {
532
613
  const definitions = new Set();
533
- const pattern = /\b(?:export\s+)?(?:async\s+)?(?:const|let|var|function|class|interface|type|enum|def|fn|struct|trait)\s+([$A-Za-z_][$A-Za-z0-9_]*)\b/g;
614
+ const pattern = /(?<![\p{L}\p{N}_$])(?:export\s+)?(?:async\s+)?(?:function\s*\*?\s*|(?:const|let|var|class|interface|type|enum|def|fn|func|fun|struct|trait)\s+)([\p{L}_$][\p{L}\p{N}_$]*)(?![\p{L}\p{N}_$])/gu;
534
615
  for (const match of text.matchAll(pattern)) {
535
616
  const identifier = match[1];
536
617
  if (!identifier) {
537
618
  continue;
538
619
  }
539
620
  const overlap = [...tokenizeText(identifier)].filter((token) => taskTokens.has(token));
540
- if (overlap.length >= 2) {
621
+ if (overlap.length >= 2 || (overlap.length === 1 && identifier.length >= 6)) {
541
622
  definitions.add(identifier);
542
623
  }
543
624
  }