-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraditional-probe.ts
More file actions
67 lines (62 loc) · 1.97 KB
/
Copy pathtraditional-probe.ts
File metadata and controls
67 lines (62 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {
globFilesFiltered,
readAll,
traditionalFanoutImportLines,
} from "../../src/benchmark-common";
import { collectGlobalRegexMatches } from "../../src/benchmark-config";
import { getProjectRoot } from "../../src/runtime";
import type { TraditionalSpec } from "./schema";
export interface TraditionalProbeResult {
results: unknown[];
filesRead: number;
bytesRead: number;
wallMs: number;
}
export function runTraditionalProbe(
spec: TraditionalSpec,
): TraditionalProbeResult {
const t0 = performance.now();
const raw =
"builtin" in spec
? traditionalFanoutImportLines()
: runRegexTraditional(spec);
return { ...raw, wallMs: performance.now() - t0 };
}
function compileTraditionalRegex(regex: string): RegExp {
try {
return new RegExp(regex);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
throw new Error(`agent-eval: invalid traditional regex "${regex}": ${msg}`);
}
}
function runRegexTraditional(spec: {
globs: string[];
regex: string;
mode: "files" | "matches";
}): Omit<TraditionalProbeResult, "wallMs"> {
const cwd = getProjectRoot();
const files = globFilesFiltered(spec.globs, cwd);
const { totalBytes, contents } = readAll(files, cwd);
const results: unknown[] = [];
if (spec.mode === "matches") {
for (const [path, content] of contents) {
for (const match of collectGlobalRegexMatches(content, spec.regex)) {
results.push({ file_path: path, match });
}
}
} else {
for (const [path, content] of contents) {
if (compileTraditionalRegex(spec.regex).test(content))
results.push({ file_path: path });
}
}
return { results, filesRead: files.length, bytesRead: totalBytes };
}
/** Agent-discovery tool sequence for glob → read → grep (no MCP). */
export function traditionalToolSequence(filesRead: number): string[] {
const seq: string[] = ["glob"];
for (let i = 0; i < filesRead; i++) seq.push("read");
seq.push("grep");
return seq;
}