@aryam/fixmap-core 0.8.8 → 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 +16 -17
  14. package/dist/explain.js.map +1 -1
  15. package/dist/grounding.d.ts +3 -1
  16. package/dist/grounding.js +21 -17
  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 +4 -1
  22. package/dist/index.js +3 -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 +2 -0
  34. package/dist/plan.js +58 -14
  35. package/dist/plan.js.map +1 -1
  36. package/dist/rank.d.ts +9 -0
  37. package/dist/rank.js +167 -89
  38. package/dist/rank.js.map +1 -1
  39. package/dist/repo-scan.d.ts +3 -1
  40. package/dist/repo-scan.js +386 -104
  41. package/dist/repo-scan.js.map +1 -1
  42. package/dist/report.d.ts +6 -0
  43. package/dist/report.js +40 -51
  44. package/dist/report.js.map +1 -1
  45. package/dist/signals.d.ts +5 -0
  46. package/dist/signals.js +130 -38
  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 +2 -2
  54. package/dist/validate.d.ts +1 -1
  55. package/dist/validate.js +148 -16
  56. package/dist/validate.js.map +1 -1
  57. package/dist/verify.js +25 -3
  58. package/dist/verify.js.map +1 -1
  59. package/package.json +1 -1
package/dist/plan.js CHANGED
@@ -1,39 +1,83 @@
1
1
  import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
2
+ import { join, resolve } from "node:path";
3
3
  import { buildPathExcluder, parseIgnoreFile, NO_EXCLUSIONS } from "./exclude.js";
4
+ import { markdownCode } from "./markdown.js";
4
5
  import { buildReportFromRepo } from "./report.js";
5
6
  import { scanRepo } from "./repo-scan.js";
6
7
  export async function buildFixMapReport(input) {
7
8
  const repo = await scanRepo(input);
8
- const exclude = await resolveExclusions(input.repoRoot, input.exclude ?? []);
9
+ const requestedExclude = await resolveExclusions(input.repoRoot, input.exclude ?? []);
10
+ const internalExclude = buildPathExcluder((input.internalExclude ?? []).map((pattern) => normalizeAbsolutePattern(input.repoRoot, pattern)));
11
+ const exclude = combineExclusions(requestedExclude, internalExclude);
9
12
  const report = buildReportFromRepo(repo, {
10
13
  issueText: input.issueText,
11
14
  limit: input.limit,
12
15
  exclude
13
16
  });
14
- if (exclude.patterns.length > 0) {
15
- const excludedPaths = repo.files.filter((file) => exclude.excludes(file.path)).map((file) => file.path);
16
- if (excludedPaths.length === 0)
17
- return report;
18
- report.diagnostics.push({
19
- code: "paths-excluded",
20
- severity: report.contextFiles.length === 0 ? "warning" : "info",
21
- message: `${exclude.patterns.length} exclusion ${exclude.patterns.length === 1 ? "pattern" : "patterns"} ` +
22
- `removed ${excludedPaths.length} ${excludedPaths.length === 1 ? "path" : "paths"} from ranking: ${exclude.patterns.join(", ")}. ` +
23
- "Run --explain on a file you expected to see if this is why it is absent."
24
- });
17
+ if (requestedExclude.patterns.length > 0) {
18
+ const excludedPaths = repo.files.filter((file) => requestedExclude.excludes(file.path)).map((file) => file.path);
19
+ const unmatchedPatterns = requestedExclude.patterns.filter((pattern) => !pattern.startsWith("!") && !requestedExclude.matchedPatterns.has(pattern));
20
+ if (unmatchedPatterns.length > 0) {
21
+ const sample = unmatchedPatterns.slice(0, 5).map(markdownCode).join(", ");
22
+ report.diagnostics.push({
23
+ code: "exclusion-no-match",
24
+ severity: "warning",
25
+ message: `${unmatchedPatterns.length} exclusion ${unmatchedPatterns.length === 1 ? "pattern matched" : "patterns matched"} no scanned paths: ${sample}` +
26
+ `${unmatchedPatterns.length > 5 ? ", ..." : ""}. Check that patterns are repository-relative or run --explain on an expected file.`
27
+ });
28
+ }
29
+ if (excludedPaths.length > 0) {
30
+ report.diagnostics.push({
31
+ code: "paths-excluded",
32
+ severity: report.contextFiles.length === 0 ? "warning" : "info",
33
+ message: `${requestedExclude.patterns.length} exclusion ${requestedExclude.patterns.length === 1 ? "pattern" : "patterns"} ` +
34
+ `removed ${excludedPaths.length} ${excludedPaths.length === 1 ? "path" : "paths"} from ranking: ${requestedExclude.patterns.map(markdownCode).join(", ")}. ` +
35
+ "Run --explain on a file you expected to see if this is why it is absent.",
36
+ paths: excludedPaths.slice(0, 8)
37
+ });
38
+ }
25
39
  }
26
40
  return report;
27
41
  }
42
+ function combineExclusions(primary, internal) {
43
+ if (internal.patterns.length === 0)
44
+ return primary;
45
+ if (primary.patterns.length === 0)
46
+ return internal;
47
+ return {
48
+ excludes: (path) => primary.excludes(path) || internal.excludes(path),
49
+ reasonFor: (path) => primary.reasonFor(path) ?? internal.reasonFor(path),
50
+ patterns: [...primary.patterns, ...internal.patterns],
51
+ matchedPatterns: new Set([...primary.matchedPatterns, ...internal.matchedPatterns])
52
+ };
53
+ }
28
54
  /**
29
55
  * Command-line exclusions and `.fixmapignore` combine rather than override. A repository
30
56
  * that ships an ignore file has said something durable about itself; a flag is one run's
31
57
  * refinement of that, not a replacement for it.
32
58
  */
33
59
  export async function resolveExclusions(repoRoot, patterns) {
34
- const combined = [...await readIgnoreFile(repoRoot), ...patterns];
60
+ const combined = [...await readIgnoreFile(repoRoot), ...patterns]
61
+ .map((pattern) => normalizeAbsolutePattern(repoRoot, pattern));
35
62
  return combined.length > 0 ? buildPathExcluder(combined) : NO_EXCLUSIONS;
36
63
  }
64
+ /**
65
+ * A leading slash normally anchors a pattern to the repository root. If a user instead
66
+ * pastes the repository's full absolute path, strip that known prefix so the intent remains
67
+ * portable inside the scan. Paths outside the repository keep their normal anchored meaning.
68
+ */
69
+ function normalizeAbsolutePattern(repoRoot, pattern) {
70
+ const trimmed = pattern.trim();
71
+ const negated = trimmed.startsWith("!");
72
+ const body = (negated ? trimmed.slice(1) : trimmed).replace(/\\/g, "/");
73
+ const normalizedRoot = resolve(repoRoot).replace(/\\/g, "/").replace(/\/$/, "");
74
+ const caseInsensitive = /^[A-Za-z]:\//.test(normalizedRoot);
75
+ const comparableBody = caseInsensitive ? body.toLowerCase() : body;
76
+ const comparableRoot = caseInsensitive ? normalizedRoot.toLowerCase() : normalizedRoot;
77
+ if (!comparableBody.startsWith(`${comparableRoot}/`))
78
+ return pattern;
79
+ return `${negated ? "!" : ""}/${body.slice(normalizedRoot.length + 1)}`;
80
+ }
37
81
  async function readIgnoreFile(repoRoot) {
38
82
  try {
39
83
  return parseIgnoreFile(await readFile(join(repoRoot, ".fixmapignore"), "utf8"));
package/dist/plan.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"plan.js","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEjF,OAAO,EAAE,mBAAmB,EAAE,MA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AG,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxE,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChF,MAAM,eAAe,GAAG,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC5D,MAAM,cAAc,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,MAAM,cAAc,GAAG,eAAe,CAAC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;IACvF,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IACrE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;AAC1E,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,QAAgB;IAC5C,IAAI,CAAC;QACH,OAAO,eAAe,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAClF,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;QAC1E,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
package/dist/rank.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { PathExcluder } from "./exclude.js";
2
2
  import type { RankedFile, RepoMap } from "./types.js";
3
+ export declare const RANKING_SIGNAL_TERMS: string[];
3
4
  export declare const REPORT_SCORE_CUTOFF = 4;
4
5
  export declare const DEFAULT_CONTEXT_FILE_LIMIT = 8;
5
6
  export declare function rankContextFiles(repo: RepoMap, input: {
@@ -7,3 +8,11 @@ export declare function rankContextFiles(repo: RepoMap, input: {
7
8
  diffText?: string | undefined;
8
9
  exclude?: PathExcluder | undefined;
9
10
  }, limit?: number, minScore?: number): RankedFile[];
11
+ export declare function rankContextFilesDetailed(repo: RepoMap, input: {
12
+ issueText?: string | undefined;
13
+ diffText?: string | undefined;
14
+ exclude?: PathExcluder | undefined;
15
+ }, limit?: number, minScore?: number): {
16
+ contextFiles: RankedFile[];
17
+ ranking: import("./grounding.js").RankingShape;
18
+ };
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
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,13 @@ 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;
25
32
  const GENERATED_TWIN_PENALTY = 21;
26
33
  const GENERATED_TWIN_REASON = "generated build artifact; maintained source counterpart exists";
27
34
  // Bundlers strip newlines; people do not. A file averaging hundreds of characters per
@@ -44,7 +51,7 @@ const BUNDLE_MARKERS = [
44
51
  /\b__defProp\s*=/,
45
52
  /\/\/# sourceMappingURL=/
46
53
  ];
47
- const EXPLICIT_PATH_BOOST = 40;
54
+ const EXPLICIT_PATH_BOOST = 60;
48
55
  const EXACT_LITERAL_BOOST = 8;
49
56
  const MEMBER_MENTION_BOOST = 8;
50
57
  // A term counts as repository-wide boilerplate only when nearly every file carries it.
@@ -58,10 +65,13 @@ const MAX_DEFINITION_IDENTIFIERS = 2;
58
65
  const TASK_MATCHED_DEFINITION_BOOST = 4;
59
66
  // How close to the leader a file must score to share its "high" label. Two points matches
60
67
  // the window `isClusteredRanking` already treats as indistinguishable.
61
- const HIGH_CONFIDENCE_MARGIN = 2;
68
+ const HIGH_CONFIDENCE_MARGIN = CLUSTERED_RANKING_MARGIN;
62
69
  export const REPORT_SCORE_CUTOFF = 4;
63
70
  export const DEFAULT_CONTEXT_FILE_LIMIT = 8;
64
- 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,
65
75
  // `explainFile` lowers this to see what a file scored below the reporting cutoff.
66
76
  // Ranking never calls it with anything but the default.
67
77
  minScore = REPORT_SCORE_CUTOFF) {
@@ -77,8 +87,7 @@ minScore = REPORT_SCORE_CUTOFF) {
77
87
  diffText: input.diffText ?? "",
78
88
  changedFiles: repo.changedFiles
79
89
  });
80
- const mentionedPaths = matchMentionedPaths(signals.fileMentions, repo.files.map((file) => file.path));
81
- const taskTargetsEvaluation = hasAny(taskTokens, ["benchmark", "benchmarks", "evaluation", "evaluate"]);
90
+ const mentionedPaths = matchMentionedPaths(signals.fileMentions, repo.files.map((file) => file.path), repo.root);
82
91
  // Excluded before anything else reads the candidate set. The boilerplate threshold below
83
92
  // is a share of that set, so removing files later would leave scoring computed against a
84
93
  // population that no longer exists.
@@ -86,8 +95,7 @@ minScore = REPORT_SCORE_CUTOFF) {
86
95
  (mentionedPaths.has(file.path) ||
87
96
  (file.isSource &&
88
97
  !file.isTest &&
89
- !LOCKFILES.has(file.path.split("/").pop() ?? "") &&
90
- (!file.path.startsWith("benchmarks/") || taskTargetsEvaluation))));
98
+ !LOCKFILE_NAMES.has(file.path.split("/").pop() ?? ""))));
91
99
  // Generated output is kept only when the source it came from is absent. chalk's sole
92
100
  // color-detection implementation lives in `source/vendor/`, so it stays; a committed
93
101
  // bundle beside the module it was built from does not, because editing it is always
@@ -95,25 +103,32 @@ minScore = REPORT_SCORE_CUTOFF) {
95
103
  const maintainedStems = new Set(scannable
96
104
  .filter((file) => !isGeneratedPath(file.path) && !isBackupPath(file.path))
97
105
  .map((file) => moduleStem(file.path)));
98
- 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) ||
99
107
  signals.changedFiles.has(file.path) ||
100
108
  !isGeneratedPath(file.path) ||
101
109
  !maintainedStems.has(moduleStem(file.path))));
102
- 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
+ ]));
103
115
  const commonTokens = findCommonTokens(contentTokensByPath);
104
116
  const allTaskTermsAreWidespread = taskTokens.size > 0 &&
105
117
  [...taskTokens].every((token) => commonTokens.has(token));
106
118
  const definitionSignals = buildDefinitionSignals(signals.identifiers);
119
+ const memberSignals = [...signals.memberMentions].map((member) => ({
120
+ member,
121
+ pattern: exactIdentifierPattern(member)
122
+ }));
107
123
  const taskText = [input.issueText ?? "", input.diffText ?? ""].join("\n");
124
+ const exactFragmentOccurrences = new Map(signals.exactFragments.map((fragment) => [fragment, countOccurrences(taskText, fragment)]));
108
125
  const taskTargetsDocumentation = targetsDocumentation(taskText);
109
- const taskTargetsConfiguration = hasAny(taskTokens, ["config", "configuration", "workflow", "action", "ci", "yaml"]);
110
- const taskTargetsDeployment = hasAny(taskTokens, DEPLOYMENT_TERMS);
126
+ const taskTargetsConfiguration = hasAnyNormalized(taskTokens, taskText, CONFIGURATION_TERMS);
127
+ const taskTargetsDeployment = hasAnyNormalized(taskTokens, taskText, DEPLOYMENT_TERMS);
111
128
  const taskTargetsExamples = /\b(?:demos?|examples?|samples?)\b/i.test(taskText.replace(/\bfor example\b/gi, ""));
112
- const taskTargetsPresentation = hasAny(taskTokens, [
113
- "browser", "button", "client", "display", "form", "frontend", "layout", "page", "screen", "ui", "visitor", "web", "website"
114
- ]);
129
+ const taskTargetsPresentation = hasAnyNormalized(taskTokens, taskText, PRESENTATION_TERMS);
115
130
  const taskTargetsTypeDeclarations = /\b(?:typescript|types?|type definitions?|declarations?|typings?|\.d\.(?:ts|mts|cts))\b/i.test(taskText);
116
- const scored = candidates
131
+ const scored = candidateFiles
117
132
  .map((file) => {
118
133
  const reasons = [];
119
134
  let score = 0;
@@ -136,6 +151,16 @@ minScore = REPORT_SCORE_CUTOFF) {
136
151
  if (pathOverlap.length > 0) {
137
152
  score += pathOverlap.length * 3;
138
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
+ }
139
164
  }
140
165
  const contentTokens = contentTokensByPath.get(file.path) ?? new Set();
141
166
  const contentOverlap = [...contentTokens].filter((token) => taskTokens.has(token) && (allTaskTermsAreWidespread || !commonTokens.has(token)));
@@ -143,13 +168,16 @@ minScore = REPORT_SCORE_CUTOFF) {
143
168
  score += Math.min(contentOverlap.length, 8) * 2;
144
169
  reasons.push(`content matches task terms: ${contentOverlap.slice(0, 8).join(", ")}`);
145
170
  }
146
- const regexTokenOverlap = findRegexTokenOverlap(file.textSample, taskTokens);
171
+ const regexTokenOverlap = [...(regexTokensByPath.get(file.path) ?? [])]
172
+ .filter((token) => taskTokens.has(token))
173
+ .slice(0, 2);
147
174
  if (regexTokenOverlap.length > 0) {
148
175
  score += Math.min(regexTokenOverlap.length, 2) * 12;
149
176
  reasons.push(`regex literal matches task tokens: ${regexTokenOverlap.join(", ")}`);
150
177
  }
151
- const matchedMembers = [...signals.memberMentions]
152
- .filter((member) => hasExactIdentifier(file.textSample, member))
178
+ const matchedMembers = memberSignals
179
+ .filter((signal) => signal.pattern.test(file.textSample))
180
+ .map((signal) => signal.member)
153
181
  .slice(0, 3);
154
182
  if (matchedMembers.length > 0) {
155
183
  score += matchedMembers.length * MEMBER_MENTION_BOOST;
@@ -157,10 +185,10 @@ minScore = REPORT_SCORE_CUTOFF) {
157
185
  }
158
186
  const exactLiteral = signals.exactFragments
159
187
  .filter((fragment) => file.textSample.includes(fragment))
160
- .sort((a, b) => countOccurrences(taskText, b) - countOccurrences(taskText, a) ||
188
+ .sort((a, b) => (exactFragmentOccurrences.get(b) ?? 0) - (exactFragmentOccurrences.get(a) ?? 0) ||
161
189
  b.length - a.length)[0];
162
190
  if (exactLiteral) {
163
- score += EXACT_LITERAL_BOOST * Math.min(3, countOccurrences(taskText, exactLiteral));
191
+ score += EXACT_LITERAL_BOOST * Math.min(3, exactFragmentOccurrences.get(exactLiteral) ?? 0);
164
192
  reasons.push(`contains exact task literal: ${previewFragment(exactLiteral)}`);
165
193
  }
166
194
  const definedIdentifiers = (file.kind === "documentation" ? [] : findDefinedIdentifiers(file.textSample, definitionSignals))
@@ -168,10 +196,17 @@ minScore = REPORT_SCORE_CUTOFF) {
168
196
  if (definedIdentifiers.length > 0) {
169
197
  score += definedIdentifiers.length * DEFINITION_IDENTIFIER_BOOST;
170
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
+ }
171
207
  }
172
208
  const taskMatchedDefinitions = signals.exactFragments.length === 0 &&
173
- !taskTargetsDocumentation &&
174
- !taskTargetsPresentation
209
+ !taskTargetsDocumentation
175
210
  ? (file.kind === "documentation" ? [] : findTaskMatchedDefinitions(file.textSample, taskTokens))
176
211
  .filter((identifier) => !definedIdentifiers.includes(identifier))
177
212
  .slice(0, MAX_DEFINITION_IDENTIFIERS)
@@ -207,7 +242,7 @@ minScore = REPORT_SCORE_CUTOFF) {
207
242
  else if (file.kind === "config" && !isChanged) {
208
243
  score -= 4;
209
244
  }
210
- 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)));
211
246
  if (taskTargetsDeployment && file.kind === "config" && !file.path.includes("/") && isDeploymentConfig) {
212
247
  score += 5;
213
248
  reasons.push("root configuration for a deployment-related task");
@@ -220,14 +255,24 @@ minScore = REPORT_SCORE_CUTOFF) {
220
255
  !mentionedPaths.has(file.path)) {
221
256
  score -= EXAMPLE_CODE_PENALTY;
222
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
+ }
223
262
  }
224
- if (isPresentationSurfacePath(file.path) &&
225
- !taskTargetsPresentation &&
226
- !taskTargetsExamples &&
227
- !isChanged &&
228
- !mentionedPaths.has(file.path)) {
229
- score -= PRESENTATION_CODE_PENALTY;
230
- 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
+ }
231
276
  }
232
277
  if (isTypeDeclarationPath(file.path) &&
233
278
  !taskTargetsTypeDeclarations &&
@@ -235,6 +280,10 @@ minScore = REPORT_SCORE_CUTOFF) {
235
280
  !mentionedPaths.has(file.path)) {
236
281
  score -= TYPE_DECLARATION_PENALTY;
237
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
+ }
238
287
  }
239
288
  else if (isTypeDeclarationPath(file.path) &&
240
289
  taskTargetsTypeDeclarations &&
@@ -259,24 +308,27 @@ minScore = REPORT_SCORE_CUTOFF) {
259
308
  return { path: file.path, score, isChanged, reasons };
260
309
  });
261
310
  applyImportProximity(scored, repo);
262
- const ranked = scored
311
+ const candidates = scored
263
312
  .filter((file) => file.score >= minScore)
264
- .sort((a, b) => b.score - a.score || a.path.localeCompare(b.path))
265
- .slice(0, limit);
266
- const clustered = isClusteredRanking(ranked);
267
- const leadIsContested = hasContestedLead(ranked);
268
- 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
269
319
  .map((entry, position) => ({
270
320
  rank: position + 1,
271
321
  path: entry.path,
272
322
  score: entry.score,
273
323
  confidence: confidenceForEntry(entry, grounding, clustered, {
274
324
  position,
275
- topScore: ranked[0]?.score ?? entry.score,
276
- leadIsContested
325
+ topScore: candidates[0]?.score ?? entry.score,
326
+ leadIsContested,
327
+ issueIsVague: isVagueTaskText(input.issueText ?? "")
277
328
  }),
278
329
  reasons: entry.reasons.length > 0 ? entry.reasons : ["source file baseline"]
279
330
  }));
331
+ return { contextFiles, ranking };
280
332
  }
281
333
  /**
282
334
  * Is the leading file's claim disputed by a definition site behind it?
@@ -304,16 +356,31 @@ function hasDefinitionEvidence(entry) {
304
356
  reason.startsWith("exact task literal at definition:"));
305
357
  }
306
358
  function applyImportProximity(scored, repo) {
307
- const seedEntries = scored
359
+ const directSeeds = scored
308
360
  .filter((entry) => entry.score >= 8 && hasDirectEvidence(entry))
309
361
  .sort((a, b) => b.score - a.score || a.path.localeCompare(b.path))
310
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);
311
369
  if (seedEntries.length === 0) {
312
370
  return;
313
371
  }
314
372
  const seeds = seedEntries.map((entry) => entry.path);
315
373
  const seedScores = new Map(seedEntries.map((entry) => [entry.path, entry.score]));
316
- 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);
317
384
  for (const entry of scored) {
318
385
  const hit = proximity.get(entry.path);
319
386
  if (hit) {
@@ -335,9 +402,6 @@ function proximityReason(hit) {
335
402
  return hit.direction === "imported-by" ? `imported by ranked file ${hit.seed}` : `imports ranked file ${hit.seed}`;
336
403
  }
337
404
  function confidenceForEntry(entry, grounding, clustered, shape) {
338
- if (entry.isChanged) {
339
- return "high";
340
- }
341
405
  const hasMaintainedSourceTwin = entry.reasons.includes(GENERATED_TWIN_REASON);
342
406
  if (entry.reasons.includes("explicitly named in the task") &&
343
407
  shape.position === 0 &&
@@ -362,6 +426,14 @@ function confidenceForEntry(entry, grounding, clustered, shape) {
362
426
  if (hasMaintainedSourceTwin) {
363
427
  confidence = capConfidence(confidence, "medium");
364
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
+ }
365
437
  const supportedIdentifierCount = grounding.identifiers.filter((identifier) => identifier.status === "exact-definition" ||
366
438
  identifier.status === "exact-text" ||
367
439
  identifier.status === "partial-definition").length;
@@ -380,7 +452,7 @@ function confidenceForEntry(entry, grounding, clustered, shape) {
380
452
  if (grounding.partiallyResolvedIdentifiers.length > 0) {
381
453
  confidence = capConfidence(confidence, "medium");
382
454
  }
383
- if (grounding.specificity === "vague") {
455
+ if (grounding.specificity === "vague" || shape.issueIsVague) {
384
456
  return "low";
385
457
  }
386
458
  if (!grounding.scanComplete) {
@@ -400,17 +472,20 @@ function hasDirectEvidence(entry) {
400
472
  reason.startsWith("defines task identifiers:") ||
401
473
  reason.startsWith("exact task literal at definition:"));
402
474
  }
403
- function isClusteredRanking(entries) {
404
- const top = entries[0]?.score;
405
- const third = entries[2]?.score;
406
- return top !== undefined && third !== undefined && top - third <= 2;
407
- }
408
- function hasAny(tokens, values) {
409
- 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
+ });
410
482
  }
411
- function matchMentionedPaths(mentions, repoPaths) {
483
+ function matchMentionedPaths(mentions, repoPaths, repoRoot) {
412
484
  const matched = new Set();
413
- for (const mention of mentions) {
485
+ for (const rawMention of mentions) {
486
+ const mention = repositoryRelativeMention(rawMention, repoRoot);
487
+ if (!mention)
488
+ continue;
414
489
  const exactMatches = repoPaths.filter((path) => pathMatchesMention(path, mention));
415
490
  if (exactMatches.length > 0) {
416
491
  if (exactMatches.length <= MAX_FILES_PER_MENTION) {
@@ -430,8 +505,15 @@ function matchMentionedPaths(mentions, repoPaths) {
430
505
  }
431
506
  return matched;
432
507
  }
433
- function pathMatchesMention(path, mention) {
434
- 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;
435
517
  }
436
518
  function compiledSourcePathVariants(path) {
437
519
  const lowerPath = path.toLowerCase();
@@ -447,31 +529,26 @@ function compiledSourcePathVariants(path) {
447
529
  function isAuxiliaryCodePath(path) {
448
530
  const parts = path.split("/");
449
531
  const stem = (parts.at(-1) ?? "").replace(/\.[^.]+$/, "").toLowerCase();
450
- return parts.slice(0, -1).some((segment) => AUXILIARY_CODE_DIRS.has(segment.toLowerCase())) ||
451
- /^(?: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"));
452
535
  }
453
536
  function isPresentationSurfacePath(path) {
454
537
  const name = path.split("/").at(-1)?.toLowerCase() ?? "";
455
- return /^(?:page|layout|demo|sample-repo)\.[cm]?[jt]sx?$/.test(name) ||
538
+ return /^(?:page|layout|demo)\.[cm]?[jt]sx?$/.test(name) ||
456
539
  /\.(?:css|less|sass|scss)$/.test(name);
457
540
  }
458
- 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) {
459
545
  const tokens = tokenizeText(text);
460
- for (const match of text.matchAll(/\b([A-Za-z])\{(\d+),(\d+)\}/g)) {
461
- const character = match[1]?.toLowerCase();
462
- const minimum = Number(match[2]);
463
- const maximum = Math.min(Number(match[3]), 8);
464
- if (!character || !Number.isSafeInteger(minimum) || !Number.isSafeInteger(maximum)) {
465
- continue;
466
- }
467
- for (let length = Math.max(3, minimum); length <= maximum; length += 1) {
468
- tokens.add(character.repeat(length));
469
- }
470
- }
546
+ for (const token of regexTokens)
547
+ tokens.add(token);
471
548
  return tokens;
472
549
  }
473
- function findRegexTokenOverlap(text, taskTokens) {
474
- const overlap = new Set();
550
+ function extractRegexTokens(text) {
551
+ const tokens = new Set();
475
552
  for (const match of text.matchAll(/\b([A-Za-z])\{(\d+),(\d+)\}/g)) {
476
553
  const character = match[1]?.toLowerCase();
477
554
  const minimum = Number(match[2]);
@@ -480,13 +557,10 @@ function findRegexTokenOverlap(text, taskTokens) {
480
557
  continue;
481
558
  }
482
559
  for (let length = Math.max(3, minimum); length <= maximum; length += 1) {
483
- const token = character.repeat(length);
484
- if (taskTokens.has(token)) {
485
- overlap.add(token);
486
- }
560
+ tokens.add(character.repeat(length));
487
561
  }
488
562
  }
489
- return [...overlap].slice(0, 2);
563
+ return tokens;
490
564
  }
491
565
  function isBundledOutput(textSample, path) {
492
566
  if (textSample.length < MIN_BUNDLE_SAMPLE_BYTES) {
@@ -512,35 +586,39 @@ function isTypeDeclarationPath(path) {
512
586
  return /\.d\.(?:ts|mts|cts)$/i.test(path);
513
587
  }
514
588
  function targetsDocumentation(taskText) {
515
- const documentation = "(?:docs?|documentation|readme|guide|copy)";
516
- 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?)";
517
592
  return (new RegExp(`\\b${action}\\b[^\\n.]{0,60}\\b${documentation}\\b`, "i").test(taskText) ||
518
- 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));
519
597
  }
520
598
  function buildDefinitionSignals(identifiers) {
521
599
  return [...identifiers]
522
600
  .sort((a, b) => a.localeCompare(b))
523
601
  .map((identifier) => ({
524
602
  identifier,
525
- 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")
526
604
  }));
527
605
  }
528
606
  function findDefinedIdentifiers(text, signals) {
529
607
  return signals.filter((signal) => signal.pattern.test(text)).map((signal) => signal.identifier);
530
608
  }
531
- function hasExactIdentifier(text, identifier) {
532
- 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");
533
611
  }
534
612
  function findTaskMatchedDefinitions(text, taskTokens) {
535
613
  const definitions = new Set();
536
- 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;
537
615
  for (const match of text.matchAll(pattern)) {
538
616
  const identifier = match[1];
539
617
  if (!identifier) {
540
618
  continue;
541
619
  }
542
620
  const overlap = [...tokenizeText(identifier)].filter((token) => taskTokens.has(token));
543
- if (overlap.length >= 2) {
621
+ if (overlap.length >= 2 || (overlap.length === 1 && identifier.length >= 6)) {
544
622
  definitions.add(identifier);
545
623
  }
546
624
  }