@quikit/quikpilot-runner 9.3.0-rc.31 → 9.3.0-rc.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/index.js +605 -79
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25300,8 +25300,8 @@ async function reportToQuikTest(params) {
|
|
|
25300
25300
|
try {
|
|
25301
25301
|
console.log(`reporting ${report}`);
|
|
25302
25302
|
const ciUrl = buildCiUrl(githubServerUrl, githubRepository, githubRunId);
|
|
25303
|
-
const { readFileSync:
|
|
25304
|
-
const body =
|
|
25303
|
+
const { readFileSync: readFileSync17 } = await import("node:fs");
|
|
25304
|
+
const body = readFileSync17(report);
|
|
25305
25305
|
let url = `${resultsUrl}?ciUrl=${encodeURIComponent(ciUrl)}&automationIdFormat=bracket`;
|
|
25306
25306
|
if (generatedFiles) {
|
|
25307
25307
|
url += `&generatedFiles=${encodeURIComponent(generatedFiles.join(","))}`;
|
|
@@ -26053,6 +26053,23 @@ function matchKey(key, specifier) {
|
|
|
26053
26053
|
if (specifier.length < prefix.length + suffix.length || !specifier.startsWith(prefix) || !specifier.endsWith(suffix)) return null;
|
|
26054
26054
|
return { captured: specifier.slice(prefix.length, specifier.length - suffix.length), weight: prefix.length };
|
|
26055
26055
|
}
|
|
26056
|
+
function aliasTable(opts) {
|
|
26057
|
+
let config = null;
|
|
26058
|
+
for (let d = opts.folder; ; d = d.includes("/") ? d.slice(0, d.lastIndexOf("/")) : "") {
|
|
26059
|
+
for (const name of ["tsconfig.json", "jsconfig.json"]) {
|
|
26060
|
+
config = resolveConfig(opts.readText, d === "" ? name : `${d}/${name}`, 0, /* @__PURE__ */ new Set());
|
|
26061
|
+
if (config) break;
|
|
26062
|
+
}
|
|
26063
|
+
if (config || d === "") break;
|
|
26064
|
+
}
|
|
26065
|
+
if (!config?.paths) return [];
|
|
26066
|
+
const lines = [];
|
|
26067
|
+
for (const [key, targets] of Object.entries(config.paths)) {
|
|
26068
|
+
const resolved = targets.map((t) => import_node_path7.posix.normalize(import_node_path7.posix.join(config.baseUrl ?? config.pathsDir, t))).filter((p) => p !== ".." && !p.startsWith("../") && !import_node_path7.posix.isAbsolute(p));
|
|
26069
|
+
if (resolved.length > 0) lines.push(`${key} -> ${resolved.join(", ")}`);
|
|
26070
|
+
}
|
|
26071
|
+
return lines.sort().slice(0, opts.max ?? 20);
|
|
26072
|
+
}
|
|
26056
26073
|
function createAliasMapper(opts) {
|
|
26057
26074
|
const cache2 = /* @__PURE__ */ new Map();
|
|
26058
26075
|
const configFor = (dir) => {
|
|
@@ -26950,11 +26967,11 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
|
|
|
26950
26967
|
envelope = await res.json();
|
|
26951
26968
|
checkHardFailure(envelope, "pilot.codegen", target.path);
|
|
26952
26969
|
throwOnTerminalRefusal(envelope, target.path);
|
|
26953
|
-
const
|
|
26954
|
-
if (
|
|
26955
|
-
throw codegenRefusedError(target.path,
|
|
26970
|
+
const whole3 = unwrapExecute(envelope, "pilot.codegen");
|
|
26971
|
+
if (whole3.outcome !== "GENERATED" || typeof whole3.newContent !== "string") {
|
|
26972
|
+
throw codegenRefusedError(target.path, whole3);
|
|
26956
26973
|
}
|
|
26957
|
-
newContent =
|
|
26974
|
+
newContent = whole3.newContent;
|
|
26958
26975
|
} catch (error) {
|
|
26959
26976
|
if (error instanceof RuntimeReplyError) {
|
|
26960
26977
|
throw new RuntimeReplyError(
|
|
@@ -27510,6 +27527,16 @@ function hasNul(bytes) {
|
|
|
27510
27527
|
for (let i2 = 0; i2 < n; i2++) if (bytes[i2] === 0) return true;
|
|
27511
27528
|
return false;
|
|
27512
27529
|
}
|
|
27530
|
+
var OUTSIDE_READ_SCOPE = {
|
|
27531
|
+
status: "outside_read_scope",
|
|
27532
|
+
message: "That is outside the folders this run may read (repoMap.readRoots). Look inside them."
|
|
27533
|
+
};
|
|
27534
|
+
function outsideReadScope(path, env2, prefix = false) {
|
|
27535
|
+
const roots = env2.readRoots;
|
|
27536
|
+
if (!roots) return false;
|
|
27537
|
+
if (roots.some((r) => matchesPrefix(path, r))) return false;
|
|
27538
|
+
return !(prefix && roots.some((r) => path === "" || r.startsWith(`${path}/`)));
|
|
27539
|
+
}
|
|
27513
27540
|
function gatePath(raw, env2) {
|
|
27514
27541
|
const n = normaliseToolPath(raw);
|
|
27515
27542
|
if (!n.ok) {
|
|
@@ -27518,6 +27545,7 @@ function gatePath(raw, env2) {
|
|
|
27518
27545
|
if (matchesDeniedPath(n.path, env2.readDenied ?? env2.deniedPaths)) {
|
|
27519
27546
|
return { ok: false, path: n.path, fail: { status: "refused", reason: "denied", message: "That path is protected and cannot be read." } };
|
|
27520
27547
|
}
|
|
27548
|
+
if (outsideReadScope(n.path, env2)) return { ok: false, path: n.path, fail: OUTSIDE_READ_SCOPE };
|
|
27521
27549
|
if (!env2.listing.has(n.path)) {
|
|
27522
27550
|
return { ok: false, path: n.path, fail: { status: "not_found", message: "Not a tracked file. Use list_files to see the available paths." } };
|
|
27523
27551
|
}
|
|
@@ -27630,13 +27658,14 @@ function prepareListFiles(args, env2) {
|
|
|
27630
27658
|
const n = normaliseToolPath(args.prefix, { allowRoot: true });
|
|
27631
27659
|
if (!n.ok) return { fail: { status: "refused", reason: n.reason, message: "That path is not allowed." } };
|
|
27632
27660
|
const prefix = n.path;
|
|
27633
|
-
|
|
27661
|
+
if (outsideReadScope(prefix, env2, true)) return { fail: OUTSIDE_READ_SCOPE };
|
|
27662
|
+
const cap2 = Math.min(max ?? env2.limits.listMaxEntries, env2.limits.listMaxEntries);
|
|
27634
27663
|
return {
|
|
27635
|
-
key: JSON.stringify({ prefix, maxEntries:
|
|
27664
|
+
key: JSON.stringify({ prefix, maxEntries: cap2 }),
|
|
27636
27665
|
exec: () => {
|
|
27637
27666
|
const matching = env2.visible.filter((p) => matchesPrefix(p, prefix));
|
|
27638
|
-
const entries = matching.slice(0,
|
|
27639
|
-
const truncated = matching.length >
|
|
27667
|
+
const entries = matching.slice(0, cap2);
|
|
27668
|
+
const truncated = matching.length > cap2;
|
|
27640
27669
|
const output = { entries, total: matching.length, truncated };
|
|
27641
27670
|
if (truncated) {
|
|
27642
27671
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -27689,6 +27718,7 @@ function prepareGrep(args, env2) {
|
|
|
27689
27718
|
const n = normaliseToolPath(args.pathPrefix, { allowRoot: true });
|
|
27690
27719
|
if (!n.ok) return { fail: { status: "refused", reason: n.reason, message: "That path is not allowed." } };
|
|
27691
27720
|
const prefix = n.path;
|
|
27721
|
+
if (outsideReadScope(prefix, env2, true)) return { fail: OUTSIDE_READ_SCOPE };
|
|
27692
27722
|
const ignoreCase = args.ignoreCase === true;
|
|
27693
27723
|
const wholeWord = args.wholeWord === true;
|
|
27694
27724
|
const maxMatches = Math.min(maxIn ?? env2.limits.grepMaxMatches, env2.limits.grepMaxMatches);
|
|
@@ -30157,9 +30187,9 @@ function placementWhy(find, k, added) {
|
|
|
30157
30187
|
if (!DECLARES_TEST.test(added)) return "not_a_test_or_import";
|
|
30158
30188
|
return bracketsBalance(added) ? null : "unbalanced_block";
|
|
30159
30189
|
}
|
|
30160
|
-
function isSubsequence(part,
|
|
30190
|
+
function isSubsequence(part, whole3) {
|
|
30161
30191
|
let i2 = 0;
|
|
30162
|
-
for (let j = 0; j <
|
|
30192
|
+
for (let j = 0; j < whole3.length && i2 < part.length; j++) if (whole3.charCodeAt(j) === part.charCodeAt(i2)) i2++;
|
|
30163
30193
|
return i2 === part.length;
|
|
30164
30194
|
}
|
|
30165
30195
|
function lostTextWhy(find, replace) {
|
|
@@ -37691,7 +37721,7 @@ var import_node_fs12 = require("node:fs");
|
|
|
37691
37721
|
var import_node_path15 = require("node:path");
|
|
37692
37722
|
function createNodeWriteFs(rootDir = process.cwd()) {
|
|
37693
37723
|
const base = createNodeToolFs(rootDir);
|
|
37694
|
-
const
|
|
37724
|
+
const inside3 = (real) => {
|
|
37695
37725
|
const r = (0, import_node_path15.relative)(base.rootReal, real);
|
|
37696
37726
|
return !r.startsWith("..") && !(0, import_node_path15.isAbsolute)(r);
|
|
37697
37727
|
};
|
|
@@ -37701,7 +37731,7 @@ function createNodeWriteFs(rootDir = process.cwd()) {
|
|
|
37701
37731
|
let dir = (0, import_node_path15.dirname)((0, import_node_path15.join)(rootDir, rel));
|
|
37702
37732
|
for (; ; ) {
|
|
37703
37733
|
try {
|
|
37704
|
-
return
|
|
37734
|
+
return inside3((0, import_node_fs12.realpathSync)(dir));
|
|
37705
37735
|
} catch {
|
|
37706
37736
|
const up = (0, import_node_path15.dirname)(dir);
|
|
37707
37737
|
if (up === dir) return false;
|
|
@@ -37967,6 +37997,7 @@ function createCodegenWorkspace(args) {
|
|
|
37967
37997
|
const n = normaliseToolPath(raw);
|
|
37968
37998
|
if (!n.ok) return { ok: false, fail: { status: "refused", reason: n.reason, message: "That path is not allowed." } };
|
|
37969
37999
|
if (!insideWriteRoot(n.path, writeRoot)) {
|
|
38000
|
+
if (args.readRoots) return { ok: false, fail: { status: "outside_write_scope", message: outsideRootMessage(writeRoot) } };
|
|
37970
38001
|
return { ok: false, fail: { status: "refused", reason: "outside_workspace", message: outsideRootMessage(writeRoot) } };
|
|
37971
38002
|
}
|
|
37972
38003
|
if (matchesDeniedPath(n.path, deniedPaths)) {
|
|
@@ -38182,6 +38213,7 @@ function createCodegenWorkspace(args) {
|
|
|
38182
38213
|
fs: createOverlayFs(baseFs, overlay),
|
|
38183
38214
|
limits,
|
|
38184
38215
|
...args.scrub ? { scrub: args.scrub } : {},
|
|
38216
|
+
...args.readRoots ? { readRoots: args.readRoots } : {},
|
|
38185
38217
|
extraTools: {
|
|
38186
38218
|
edit_file: prepareEdit,
|
|
38187
38219
|
write_file: prepareWrite,
|
|
@@ -38447,6 +38479,7 @@ function estimateRequestTokens(contextData) {
|
|
|
38447
38479
|
|
|
38448
38480
|
// src/targetingLoop.ts
|
|
38449
38481
|
var LOOP_CONTRACT_VERSION = "targeting-loop-1";
|
|
38482
|
+
var MAP_LOOP_CONTRACT_VERSION = "targeting-loop-2";
|
|
38450
38483
|
var LoopFailure = class extends Error {
|
|
38451
38484
|
reason;
|
|
38452
38485
|
runtimeCode;
|
|
@@ -38500,7 +38533,8 @@ async function runTargetingLoop(args, deps) {
|
|
|
38500
38533
|
readDenied: readDenied(args.deniedPaths),
|
|
38501
38534
|
fs: deps.fs ?? createNodeToolFs(),
|
|
38502
38535
|
limits,
|
|
38503
|
-
scrub: makeCodeScrubber(deps.secrets ?? [], (c) => log({ event: "loop.scrubbed", ...nonZero(c) }))
|
|
38536
|
+
scrub: makeCodeScrubber(deps.secrets ?? [], (c) => log({ event: "loop.scrubbed", ...nonZero(c) })),
|
|
38537
|
+
...args.readRoots ? { readRoots: args.readRoots } : {}
|
|
38504
38538
|
};
|
|
38505
38539
|
const ledger = newLedger();
|
|
38506
38540
|
const reads = [];
|
|
@@ -38509,13 +38543,14 @@ async function runTargetingLoop(args, deps) {
|
|
|
38509
38543
|
const usedIds = /* @__PURE__ */ new Set();
|
|
38510
38544
|
const refusedTurns = [];
|
|
38511
38545
|
let refusedStreak = 0;
|
|
38546
|
+
let peakRequestTokens = 0;
|
|
38512
38547
|
let turns = 0;
|
|
38513
38548
|
let noProgressStreak = 0;
|
|
38514
38549
|
let forced = null;
|
|
38515
38550
|
const started = now();
|
|
38516
38551
|
const buildContext = (turn, isFinal, finalReason) => ({
|
|
38517
38552
|
...args.baseContext,
|
|
38518
|
-
contractVersion: LOOP_CONTRACT_VERSION,
|
|
38553
|
+
contractVersion: args.contractVersion ?? LOOP_CONTRACT_VERSION,
|
|
38519
38554
|
loop: {
|
|
38520
38555
|
turn,
|
|
38521
38556
|
maxTurns: limits.maxTurns,
|
|
@@ -38538,7 +38573,8 @@ async function runTargetingLoop(args, deps) {
|
|
|
38538
38573
|
refused: ledger.refused,
|
|
38539
38574
|
stopReason,
|
|
38540
38575
|
reads: [...reads],
|
|
38541
|
-
...refusedTurns.length > 0 ? { refusedTurns: refusedTurns.map((t) => ({ turn: t.turn, rules: [...t.rules] })) } : {}
|
|
38576
|
+
...refusedTurns.length > 0 ? { refusedTurns: refusedTurns.map((t) => ({ turn: t.turn, rules: [...t.rules] })) } : {},
|
|
38577
|
+
...peakRequestTokens > 0 ? { peakRequestTokens } : {}
|
|
38542
38578
|
});
|
|
38543
38579
|
log({ event: "targeting.loop_start", mode: "loop", maxTurns: limits.maxTurns, maxToolCalls: limits.maxToolCalls, listingFiles: args.listing.length });
|
|
38544
38580
|
try {
|
|
@@ -38550,6 +38586,7 @@ async function runTargetingLoop(args, deps) {
|
|
|
38550
38586
|
const contextData = buildContext(turn, isFinal, finalReason);
|
|
38551
38587
|
const requestChars = JSON.stringify(contextData).length;
|
|
38552
38588
|
const requestTokens = estimateRequestTokens(contextData);
|
|
38589
|
+
peakRequestTokens = Math.max(peakRequestTokens, requestTokens);
|
|
38553
38590
|
if (requestTokens > limits.maxRequestTokens) {
|
|
38554
38591
|
log({ event: "targeting.loop_ceiling", turn, action: "not_sent", projectedTokens: requestTokens, ceiling: limits.maxRequestTokens });
|
|
38555
38592
|
throw new LoopFailure("token_ceiling");
|
|
@@ -38712,6 +38749,8 @@ async function runTargetingLoop(args, deps) {
|
|
|
38712
38749
|
var CODEGEN_LOOP_CONTRACT_VERSION = "codegen-loop-1";
|
|
38713
38750
|
var CODEGEN_LOOP_2_CONTRACT_VERSION = "codegen-loop-2";
|
|
38714
38751
|
var CODEGEN_LOOP_3_CONTRACT_VERSION = "codegen-loop-3";
|
|
38752
|
+
var CODEGEN_LOOP_4_CONTRACT_VERSION = "codegen-loop-4";
|
|
38753
|
+
var MAP_SOFT_REQUEST_TOKENS = 4e4;
|
|
38715
38754
|
var CodegenLoopFailure = class extends Error {
|
|
38716
38755
|
reason;
|
|
38717
38756
|
runtimeCode;
|
|
@@ -38784,7 +38823,8 @@ async function runCodegenLoop(args, deps) {
|
|
|
38784
38823
|
const ws = createCodegenWorkspace({
|
|
38785
38824
|
// S2b: credentials in what a tool answers are hidden (the AI's own writes are not touched).
|
|
38786
38825
|
scrub: makeCodeScrubber(deps.secrets ?? [], (c) => (deps.log ?? ((e) => console.log(JSON.stringify(e))))({ event: "loop.scrubbed", ...nonZero(c) })),
|
|
38787
|
-
listing: args.listing,
|
|
38826
|
+
listing: args.readListing ?? args.listing,
|
|
38827
|
+
...args.readRoots ? { readRoots: args.readRoots } : {},
|
|
38788
38828
|
deniedPaths: args.deniedPaths,
|
|
38789
38829
|
protectedTestPaths: args.protectedTestPaths,
|
|
38790
38830
|
...args.discoveredTests ? { discoveredTests: args.discoveredTests } : {},
|
|
@@ -38826,7 +38866,8 @@ async function runCodegenLoop(args, deps) {
|
|
|
38826
38866
|
log,
|
|
38827
38867
|
now
|
|
38828
38868
|
}) : null;
|
|
38829
|
-
const contractVersion = harness ? CODEGEN_LOOP_3_CONTRACT_VERSION : tests ? CODEGEN_LOOP_2_CONTRACT_VERSION : CODEGEN_LOOP_CONTRACT_VERSION;
|
|
38869
|
+
const contractVersion = harness ? args.readRoots ? CODEGEN_LOOP_4_CONTRACT_VERSION : CODEGEN_LOOP_3_CONTRACT_VERSION : tests ? CODEGEN_LOOP_2_CONTRACT_VERSION : CODEGEN_LOOP_CONTRACT_VERSION;
|
|
38870
|
+
let peakRequestTokens = 0;
|
|
38830
38871
|
const previousAttempt = args.previousAttempt && !harness ? previousForLoop2(args.previousAttempt) : args.previousAttempt;
|
|
38831
38872
|
if (tests && args.seed && args.seed.length > 0) tests.markSeen(versionOfFiles(filesOnDisk()));
|
|
38832
38873
|
let testMs = 0;
|
|
@@ -38924,14 +38965,17 @@ async function runCodegenLoop(args, deps) {
|
|
|
38924
38965
|
syntaxWarnings: ws.syntaxWarnings,
|
|
38925
38966
|
...tests ? { contractVersion, testRuns: tests.record() } : {},
|
|
38926
38967
|
...refusedTurns.length > 0 ? { refusedTurns: refusedTurns.map((t) => ({ turn: t.turn, rules: [...t.rules] })) } : {},
|
|
38927
|
-
reasoning: [...reasoning]
|
|
38968
|
+
reasoning: [...reasoning],
|
|
38969
|
+
...args.repoView ? { repoView: args.repoView, peakRequestTokens } : {}
|
|
38928
38970
|
});
|
|
38929
38971
|
const makeRoom = (nextTurn, nextFinal, finalReason) => {
|
|
38930
|
-
const
|
|
38931
|
-
|
|
38972
|
+
const under = (limit) => estimateRequestTokens(buildContext(nextTurn, nextFinal, finalReason)) <= limit;
|
|
38973
|
+
const fits = () => under(limits.maxRequestTokens);
|
|
38974
|
+
const soft = args.readRoots ? Math.min(MAP_SOFT_REQUEST_TOKENS, limits.maxRequestTokens) : limits.maxRequestTokens;
|
|
38975
|
+
if (under(soft)) return true;
|
|
38932
38976
|
const lastTestRun = toolResults.map((r) => r.name).lastIndexOf(RUN_TESTS_TOOL);
|
|
38933
38977
|
const lastCall = toolResults.map((r) => r.name).lastIndexOf(CALL_FUNCTION_TOOL);
|
|
38934
|
-
for (let i2 = 0; i2 < toolResults.length && !
|
|
38978
|
+
for (let i2 = 0; i2 < toolResults.length && !under(soft); i2++) {
|
|
38935
38979
|
const r = toolResults[i2];
|
|
38936
38980
|
if (READ_TOOLS.has(r.name) && r.status === "ok" && r.output !== DROPPED_OUTPUT) toolResults[i2] = { ...r, output: DROPPED_OUTPUT };
|
|
38937
38981
|
if (r.name === RUN_TESTS_TOOL && i2 !== lastTestRun && r.output !== void 0 && r.output !== DROPPED_OUTPUT) toolResults[i2] = { ...r, output: DROPPED_OUTPUT };
|
|
@@ -39007,6 +39051,7 @@ async function runCodegenLoop(args, deps) {
|
|
|
39007
39051
|
const finalReason = forced ?? "max_turns";
|
|
39008
39052
|
const contextData = buildContext(turn, isFinal, finalReason);
|
|
39009
39053
|
const requestTokens = estimateRequestTokens(contextData);
|
|
39054
|
+
peakRequestTokens = Math.max(peakRequestTokens, requestTokens);
|
|
39010
39055
|
if (requestTokens > limits.maxRequestTokens) {
|
|
39011
39056
|
log({ event: "codegen.loop_ceiling", turn, action: "not_sent", projectedTokens: requestTokens, ceiling: limits.maxRequestTokens });
|
|
39012
39057
|
throw new CodegenLoopFailure("token_ceiling");
|
|
@@ -39289,8 +39334,8 @@ function amendmentOverreach(before, after, token) {
|
|
|
39289
39334
|
const lb = after.split("\n");
|
|
39290
39335
|
const outside = (lines, s) => [...lines.slice(0, s.start), ...lines.slice(s.end)].join("\n");
|
|
39291
39336
|
if (outside(la, a) !== outside(lb, b)) return "lines outside that test changed";
|
|
39292
|
-
const
|
|
39293
|
-
if (
|
|
39337
|
+
const inside3 = (lines, s) => withoutExpectations(lines.slice(s.start, s.end).join("\n")).replace(/\s+/g, "");
|
|
39338
|
+
if (inside3(la, a) !== inside3(lb, b)) return "the test's setup or inputs changed, not only its expected values";
|
|
39294
39339
|
return null;
|
|
39295
39340
|
}
|
|
39296
39341
|
var record = (phase, outcome, summary, redUnproven) => ({
|
|
@@ -39467,6 +39512,27 @@ function mergePhaseSummaries(parts, phases) {
|
|
|
39467
39512
|
};
|
|
39468
39513
|
}
|
|
39469
39514
|
|
|
39515
|
+
// src/repoViewRecord.ts
|
|
39516
|
+
var MAX_ROOTS = 8;
|
|
39517
|
+
var MAX_ROOT_CHARS = 300;
|
|
39518
|
+
var MAX_REASON_CHARS2 = 40;
|
|
39519
|
+
var whole = (n) => typeof n === "number" && Number.isFinite(n) && n >= 0 ? Math.floor(n) : 0;
|
|
39520
|
+
function repoViewOf(scope) {
|
|
39521
|
+
if (!scope || scope.view !== "map") return void 0;
|
|
39522
|
+
return { view: "map", fileCount: scope.readListing.length, readRoots: [...scope.readRoots], mapTokens: scope.mapTokens ?? 0 };
|
|
39523
|
+
}
|
|
39524
|
+
function clampRepoView(facts, peakRequestTokens) {
|
|
39525
|
+
if (!facts) return {};
|
|
39526
|
+
return {
|
|
39527
|
+
view: "map",
|
|
39528
|
+
fileCount: whole(facts.fileCount),
|
|
39529
|
+
readRoots: facts.readRoots.filter((r) => r.length <= MAX_ROOT_CHARS).slice(0, MAX_ROOTS),
|
|
39530
|
+
mapTokens: whole(facts.mapTokens),
|
|
39531
|
+
...peakRequestTokens && peakRequestTokens > 0 ? { peakRequestTokens: whole(peakRequestTokens) } : {},
|
|
39532
|
+
...facts.failReason ? { failReason: facts.failReason.slice(0, MAX_REASON_CHARS2) } : {}
|
|
39533
|
+
};
|
|
39534
|
+
}
|
|
39535
|
+
|
|
39470
39536
|
// src/codegenLoopRecord.ts
|
|
39471
39537
|
var MAX_RECORD_PATHS = 50;
|
|
39472
39538
|
var MAX_RECORD_PATH_CHARS = 300;
|
|
@@ -39498,11 +39564,11 @@ function gateOf(g) {
|
|
|
39498
39564
|
alreadyFailing: gateCount(x.alreadyFailing)
|
|
39499
39565
|
};
|
|
39500
39566
|
}
|
|
39501
|
-
function
|
|
39567
|
+
function whole2(n) {
|
|
39502
39568
|
return typeof n === "number" && Number.isInteger(n) && n >= 0 ? n : 0;
|
|
39503
39569
|
}
|
|
39504
39570
|
function small(n) {
|
|
39505
|
-
return Math.min(MAX_ATTEMPT_COUNT,
|
|
39571
|
+
return Math.min(MAX_ATTEMPT_COUNT, whole2(n));
|
|
39506
39572
|
}
|
|
39507
39573
|
function pathOk(p) {
|
|
39508
39574
|
return typeof p === "string" && p.length > 0 && p.length <= MAX_RECORD_PATH_CHARS;
|
|
@@ -39528,14 +39594,14 @@ function buildCodegenLoopRecord(loop) {
|
|
|
39528
39594
|
path: r.path.trim(),
|
|
39529
39595
|
...Number.isInteger(r.startLine) ? { startLine: r.startLine } : {},
|
|
39530
39596
|
...Number.isInteger(r.endLine) ? { endLine: r.endLine } : {},
|
|
39531
|
-
chars:
|
|
39597
|
+
chars: whole2(r.chars),
|
|
39532
39598
|
...r.refused ? { refused: true } : {}
|
|
39533
39599
|
}));
|
|
39534
|
-
const edits = room(loop.edits).map((e) => ({ path: e.path, count:
|
|
39535
|
-
const created = room(loop.created).map((c) => ({ path: c.path, chars:
|
|
39600
|
+
const edits = room(loop.edits).map((e) => ({ path: e.path, count: whole2(e.count) }));
|
|
39601
|
+
const created = room(loop.created).map((c) => ({ path: c.path, chars: whole2(c.chars) }));
|
|
39536
39602
|
const statusCounts = {};
|
|
39537
39603
|
for (const [k, v] of Object.entries(loop.statusCounts).slice(0, MAX_STATUS_KEYS)) {
|
|
39538
|
-
if (k.length > 0 && k.length <= MAX_STATUS_KEY_CHARS) statusCounts[k] =
|
|
39604
|
+
if (k.length > 0 && k.length <= MAX_STATUS_KEY_CHARS) statusCounts[k] = whole2(v);
|
|
39539
39605
|
else cut = true;
|
|
39540
39606
|
}
|
|
39541
39607
|
if (Object.keys(loop.statusCounts).length > MAX_STATUS_KEYS) cut = true;
|
|
@@ -39548,7 +39614,7 @@ function buildCodegenLoopRecord(loop) {
|
|
|
39548
39614
|
const text = typeof r.text === "string" ? r.text.trim() : "";
|
|
39549
39615
|
if (text.length === 0) continue;
|
|
39550
39616
|
const over = text.length > MAX_RECORD_REASONING_CHARS;
|
|
39551
|
-
reasoning.push({ turn:
|
|
39617
|
+
reasoning.push({ turn: whole2(r.turn), text: over ? text.slice(0, MAX_RECORD_REASONING_CHARS) : text, ...over ? { truncated: true } : {} });
|
|
39552
39618
|
}
|
|
39553
39619
|
const testRuns = [];
|
|
39554
39620
|
for (const t of loop.testRuns ?? []) {
|
|
@@ -39557,16 +39623,16 @@ function buildCodegenLoopRecord(loop) {
|
|
|
39557
39623
|
break;
|
|
39558
39624
|
}
|
|
39559
39625
|
testRuns.push({
|
|
39560
|
-
n:
|
|
39626
|
+
n: whole2(t.n),
|
|
39561
39627
|
status: String(t.status).slice(0, MAX_STATUS_KEY_CHARS),
|
|
39562
39628
|
...t.reason ? { reason: String(t.reason).slice(0, MAX_STATUS_KEY_CHARS) } : {},
|
|
39563
|
-
passed:
|
|
39564
|
-
failed:
|
|
39565
|
-
regressions:
|
|
39566
|
-
newFailures:
|
|
39567
|
-
alreadyFailing:
|
|
39629
|
+
passed: whole2(t.passed),
|
|
39630
|
+
failed: whole2(t.failed),
|
|
39631
|
+
regressions: whole2(t.regressions),
|
|
39632
|
+
newFailures: whole2(t.newFailures),
|
|
39633
|
+
alreadyFailing: whole2(t.alreadyFailing),
|
|
39568
39634
|
timedOut: t.timedOut === true,
|
|
39569
|
-
seconds:
|
|
39635
|
+
seconds: whole2(t.seconds),
|
|
39570
39636
|
...t.scope === "file" ? { scope: "file" } : {},
|
|
39571
39637
|
...t.phase && PHASES.has(t.phase) ? { phase: t.phase } : {}
|
|
39572
39638
|
});
|
|
@@ -39583,7 +39649,7 @@ function buildCodegenLoopRecord(loop) {
|
|
|
39583
39649
|
outcome: ph.outcome.slice(0, MAX_STATUS_KEY_CHARS),
|
|
39584
39650
|
turns: small(ph.turns),
|
|
39585
39651
|
toolCalls: small(ph.toolCalls),
|
|
39586
|
-
...
|
|
39652
|
+
...whole2(ph.redUnproven) > 0 ? { redUnproven: small(ph.redUnproven) } : {}
|
|
39587
39653
|
});
|
|
39588
39654
|
}
|
|
39589
39655
|
const refused2 = clampRefusedTurns(loop.refusedTurns);
|
|
@@ -39614,15 +39680,15 @@ function buildCodegenLoopRecord(loop) {
|
|
|
39614
39680
|
const healIn = loop.heal;
|
|
39615
39681
|
const healed = healIn && typeof healIn.stop === "string" && HEAL_STOPS.has(healIn.stop) ? {
|
|
39616
39682
|
stop: healIn.stop,
|
|
39617
|
-
allowed: Math.min(3,
|
|
39618
|
-
made: Math.min(3,
|
|
39683
|
+
allowed: Math.min(3, whole2(healIn.allowed)),
|
|
39684
|
+
made: Math.min(3, whole2(healIn.made)),
|
|
39619
39685
|
...gateOf(healIn.startedFrom) ? { startedFrom: gateOf(healIn.startedFrom) } : {},
|
|
39620
39686
|
...typeof healIn.failureReason === "string" && healIn.failureReason.length > 0 ? { failureReason: healIn.failureReason.slice(0, MAX_STATUS_KEY_CHARS) } : {}
|
|
39621
39687
|
} : void 0;
|
|
39622
39688
|
return {
|
|
39623
|
-
turns:
|
|
39624
|
-
toolCalls:
|
|
39625
|
-
refused:
|
|
39689
|
+
turns: whole2(loop.turns),
|
|
39690
|
+
toolCalls: whole2(loop.toolCalls),
|
|
39691
|
+
refused: whole2(loop.refused),
|
|
39626
39692
|
stopReason: loop.stopReason,
|
|
39627
39693
|
...loop.fellBack ? { fellBack: true } : {},
|
|
39628
39694
|
...loop.fallbackReason ? { fallbackReason: String(loop.fallbackReason).slice(0, MAX_RECORD_FALLBACK_REASON_CHARS) } : {},
|
|
@@ -39630,8 +39696,9 @@ function buildCodegenLoopRecord(loop) {
|
|
|
39630
39696
|
edits,
|
|
39631
39697
|
created,
|
|
39632
39698
|
statusCounts,
|
|
39633
|
-
...
|
|
39699
|
+
...whole2(loop.syntaxWarnings) > 0 ? { syntaxWarnings: whole2(loop.syntaxWarnings) } : {},
|
|
39634
39700
|
...typeof loop.contractVersion === "string" && loop.contractVersion.length > 0 ? { contractVersion: loop.contractVersion.slice(0, 40) } : {},
|
|
39701
|
+
...clampRepoView(loop.repoView, loop.peakRequestTokens),
|
|
39635
39702
|
...testRuns.length > 0 ? { testRuns } : {},
|
|
39636
39703
|
...refused2.rows.length > 0 ? { refusedTurns: refused2.rows } : {},
|
|
39637
39704
|
...attempts.length > 0 ? { attempts } : {},
|
|
@@ -39813,6 +39880,31 @@ function collectLoopContext(p) {
|
|
|
39813
39880
|
return { entries, testPaths, records };
|
|
39814
39881
|
}
|
|
39815
39882
|
|
|
39883
|
+
// src/mapModeError.ts
|
|
39884
|
+
var MapModeError = class extends Error {
|
|
39885
|
+
phase;
|
|
39886
|
+
reason;
|
|
39887
|
+
constructor(phase, reason) {
|
|
39888
|
+
super(mapModeMessage(phase, reason));
|
|
39889
|
+
this.name = "MapModeError";
|
|
39890
|
+
this.phase = phase;
|
|
39891
|
+
this.reason = reason;
|
|
39892
|
+
}
|
|
39893
|
+
};
|
|
39894
|
+
var MAP_NEEDS_TESTS_MESSAGE = "QuikPilot could not start: this project is too large to send the AI its full list of files, and the way it works on a project this size needs a test command to check the change. Add a test command in the space's QuikPilot settings and run it again.";
|
|
39895
|
+
var WHY = {
|
|
39896
|
+
contract_rejected: "the AI service did not accept the summary that replaces the list (map mode may be switched off on it)",
|
|
39897
|
+
token_ceiling: "a step grew too large for the AI service even without the list",
|
|
39898
|
+
final_invalid: "the files it chose could not be used",
|
|
39899
|
+
final_not_produced: "it never reached an answer",
|
|
39900
|
+
loop_deadline: "it took too long",
|
|
39901
|
+
turn_timeout: "one step took too long"
|
|
39902
|
+
};
|
|
39903
|
+
function mapModeMessage(phase, reason) {
|
|
39904
|
+
const what = phase === "targeting" ? "choose the files to change" : "write the change";
|
|
39905
|
+
return `QuikPilot could not ${what}: this project is too large to send the AI its full list of files, so it was sent a summary instead, and that did not finish (${WHY[reason] ?? reason}). There is no other way to try on a project this size, so nothing was changed.`;
|
|
39906
|
+
}
|
|
39907
|
+
|
|
39816
39908
|
// src/codegenStep.ts
|
|
39817
39909
|
function testTargetPaths(targets, discoveredTests) {
|
|
39818
39910
|
const isTest = testRule(discoveredTests);
|
|
@@ -39822,6 +39914,7 @@ function discoveredTestsOf(testDiscovery) {
|
|
|
39822
39914
|
return testDiscovery.report === "PRESENT" ? testDiscovery.discoveredTestFiles : void 0;
|
|
39823
39915
|
}
|
|
39824
39916
|
var MAX_PROTECTED_PATHS_ON_WIRE = 300;
|
|
39917
|
+
var MAX_PROTECTED_PATHS_ON_WIRE_MAP = 100;
|
|
39825
39918
|
async function postCodegenTurn(gateway, contextData, signal) {
|
|
39826
39919
|
const res = await fetchWithRetry(`${gateway.baseUrl}/ai/execute`, {
|
|
39827
39920
|
method: "POST",
|
|
@@ -39887,7 +39980,9 @@ function buildCodegenLoopArgs(p, context = collectLoopContext({
|
|
|
39887
39980
|
for (const t of p.targets) for (const id of t.automationIds ?? []) if (!skipped.has(id)) claimed.add(id);
|
|
39888
39981
|
const requiredTests = p.requiredTests.filter((tc) => claimed.has(tc.automationId));
|
|
39889
39982
|
const protectedTestPaths = protectedTestFiles(p.workspaceListing, p.testDiscovery);
|
|
39983
|
+
const map = p.scope?.view === "map" && p.scope.repoMap ? p.scope : void 0;
|
|
39890
39984
|
const baseContext = {
|
|
39985
|
+
...map ? { repoMap: map.repoMap } : {},
|
|
39891
39986
|
targets: p.targets.map((t) => ({
|
|
39892
39987
|
path: t.path,
|
|
39893
39988
|
kind: t.kind,
|
|
@@ -39896,12 +39991,15 @@ function buildCodegenLoopArgs(p, context = collectLoopContext({
|
|
|
39896
39991
|
automationIds: t.automationIds ?? []
|
|
39897
39992
|
})),
|
|
39898
39993
|
requiredTests,
|
|
39899
|
-
workspaceListing: p.workspaceListing
|
|
39994
|
+
...map ? {} : { workspaceListing: p.workspaceListing }
|
|
39900
39995
|
};
|
|
39901
39996
|
if (context.entries.length > 0) baseContext.contextContents = scrubEntriesForModel(context.entries, [p.gateway.token], new Set(p.targets.map((t) => t.path)));
|
|
39902
39997
|
if (p.deniedPaths.length > 0) baseContext.deniedPaths = p.deniedPaths;
|
|
39903
39998
|
if (protectedTestPaths.length > 0) {
|
|
39904
|
-
baseContext.protectedTestPaths = orderProtectedForWire(protectedTestPaths, p.targets.map((t) => t.path), context.testPaths).slice(
|
|
39999
|
+
baseContext.protectedTestPaths = orderProtectedForWire(protectedTestPaths, p.targets.map((t) => t.path), context.testPaths).slice(
|
|
40000
|
+
0,
|
|
40001
|
+
map ? MAX_PROTECTED_PATHS_ON_WIRE_MAP : MAX_PROTECTED_PATHS_ON_WIRE
|
|
40002
|
+
);
|
|
39905
40003
|
}
|
|
39906
40004
|
if (p.outOfScope.length > 0) baseContext.outOfScope = p.outOfScope;
|
|
39907
40005
|
return {
|
|
@@ -39909,6 +40007,7 @@ function buildCodegenLoopArgs(p, context = collectLoopContext({
|
|
|
39909
40007
|
targets: p.targets,
|
|
39910
40008
|
requiredAutomationIds: requiredTests.map((tc) => tc.automationId),
|
|
39911
40009
|
listing: p.workspaceListing,
|
|
40010
|
+
...map ? { readRoots: map.readRoots, readListing: map.readListing, repoView: repoViewOf(map) } : {},
|
|
39912
40011
|
deniedPaths: p.deniedPaths,
|
|
39913
40012
|
protectedTestPaths,
|
|
39914
40013
|
...discoveredTests ? { discoveredTests } : {},
|
|
@@ -40069,6 +40168,16 @@ async function runCodegenStep(p) {
|
|
|
40069
40168
|
log({ event: "codegen.attempt_start", attempt: 1 });
|
|
40070
40169
|
const firstStarted = now();
|
|
40071
40170
|
let first = await attempt2();
|
|
40171
|
+
if ("failure" in first && first.failure.reason === "contract_rejected" && p.scope?.view === "map") {
|
|
40172
|
+
const view = repoViewOf(p.scope);
|
|
40173
|
+
p.out.loop = buildCodegenLoopRecord({
|
|
40174
|
+
...first.failure.summary ?? NO_SUMMARY,
|
|
40175
|
+
stopReason: "map_failed",
|
|
40176
|
+
...view ? { repoView: { ...view, failReason: "contract_rejected" } } : {}
|
|
40177
|
+
});
|
|
40178
|
+
log({ event: "codegen.map_failed", reason: "contract_rejected" });
|
|
40179
|
+
throw new MapModeError("codegen", "contract_rejected");
|
|
40180
|
+
}
|
|
40072
40181
|
if ("failure" in first && first.failure.reason === "contract_rejected" && args?.harness === true) {
|
|
40073
40182
|
log({ event: "codegen.version_fallback", from: "codegen-loop-3", to: "codegen-loop-2" });
|
|
40074
40183
|
p.harness = false;
|
|
@@ -41347,6 +41456,375 @@ ${violations.join("\n")}`);
|
|
|
41347
41456
|
return { leftOut: writeRoot ? changedOutside(writeRoot).length : 0 };
|
|
41348
41457
|
}
|
|
41349
41458
|
|
|
41459
|
+
// src/run.ts
|
|
41460
|
+
var import_node_fs22 = require("node:fs");
|
|
41461
|
+
|
|
41462
|
+
// src/mapMode.ts
|
|
41463
|
+
var MAP_ENV = "QUIKPILOT_MAP";
|
|
41464
|
+
var MAP_AUTO_LISTING_TOKENS = 4e4;
|
|
41465
|
+
function resolveMapSetting(env2 = process.env) {
|
|
41466
|
+
const v = env2[MAP_ENV]?.trim().toLowerCase();
|
|
41467
|
+
return v === "on" || v === "off" ? v : "auto";
|
|
41468
|
+
}
|
|
41469
|
+
function listingTokens(listing) {
|
|
41470
|
+
return estimateTokens(JSON.stringify(listing, null, 2));
|
|
41471
|
+
}
|
|
41472
|
+
function wantsMap(setting, listing) {
|
|
41473
|
+
const tokens = listingTokens(listing);
|
|
41474
|
+
if (setting === "on") return { map: true, listingTokens: tokens };
|
|
41475
|
+
if (setting === "off") return { map: false, listingTokens: tokens };
|
|
41476
|
+
return { map: tokens > MAP_AUTO_LISTING_TOKENS, listingTokens: tokens };
|
|
41477
|
+
}
|
|
41478
|
+
function startMapMode(i2) {
|
|
41479
|
+
if (!i2.testCommand) throw new Error(MAP_NEEDS_TESTS_MESSAGE);
|
|
41480
|
+
const overrode = i2.targetingMode !== "loop" || i2.codegenMode !== "loop-tests";
|
|
41481
|
+
return { event: "map.mode", ...overrode ? { overrode: { targeting: i2.targetingMode, codegen: i2.codegenMode } } : {} };
|
|
41482
|
+
}
|
|
41483
|
+
|
|
41484
|
+
// src/repoMap.ts
|
|
41485
|
+
var import_node_path19 = require("node:path");
|
|
41486
|
+
var MAP_BUDGET_TOKENS = 4e3;
|
|
41487
|
+
var MAX_FOLDERS = 200;
|
|
41488
|
+
var MAX_LANGUAGES = 12;
|
|
41489
|
+
var GUIDANCE_NAMES = ["AGENTS.md", "CLAUDE.md", "CONTRIBUTING.md", "README.md"];
|
|
41490
|
+
var GUIDANCE_FILE_CHARS = 2e3;
|
|
41491
|
+
var GUIDANCE_TOTAL_CHARS = 6e3;
|
|
41492
|
+
var MAX_GUIDANCE_FILES = 8;
|
|
41493
|
+
var MIN_GUIDANCE_CHARS = 200;
|
|
41494
|
+
var MAX_ENTRY_CHARS = 200;
|
|
41495
|
+
var inside = (path, root) => root === "" || path === root || path.startsWith(`${root}/`);
|
|
41496
|
+
var cap = (s) => s.length <= MAX_ENTRY_CHARS ? s : `${s.slice(0, MAX_ENTRY_CHARS - 1)}\u2026`;
|
|
41497
|
+
var parentOf2 = (d) => d.includes("/") ? d.slice(0, d.lastIndexOf("/")) : "";
|
|
41498
|
+
function clip(text, max) {
|
|
41499
|
+
if (text.length <= max) return { text, truncated: false };
|
|
41500
|
+
const cut = text.slice(0, max);
|
|
41501
|
+
const nl = cut.lastIndexOf("\n");
|
|
41502
|
+
return { text: nl > max / 2 ? cut.slice(0, nl) : cut, truncated: true };
|
|
41503
|
+
}
|
|
41504
|
+
function guidanceFiles(i2, perFile2, total) {
|
|
41505
|
+
const tracked = new Set(i2.fullListing);
|
|
41506
|
+
const denied = readDenied(i2.deniedPaths);
|
|
41507
|
+
const out = [];
|
|
41508
|
+
let left = total;
|
|
41509
|
+
for (let d = i2.writeRoot; ; d = parentOf2(d)) {
|
|
41510
|
+
for (const name of GUIDANCE_NAMES) {
|
|
41511
|
+
const path = d === "" ? name : `${d}/${name}`;
|
|
41512
|
+
if (out.length >= MAX_GUIDANCE_FILES || left < MIN_GUIDANCE_CHARS) break;
|
|
41513
|
+
if (!tracked.has(path) || matchesDeniedPath(path, denied)) continue;
|
|
41514
|
+
const raw = i2.readText(path);
|
|
41515
|
+
if (raw === null || raw.trim() === "") continue;
|
|
41516
|
+
const clipped = clip(i2.scrub(raw.replace(/\r\n/g, "\n")).trim(), Math.min(perFile2, left));
|
|
41517
|
+
out.push({ path, ...clipped });
|
|
41518
|
+
left -= clipped.text.length;
|
|
41519
|
+
}
|
|
41520
|
+
if (d === "") break;
|
|
41521
|
+
}
|
|
41522
|
+
return out;
|
|
41523
|
+
}
|
|
41524
|
+
function languages(listing) {
|
|
41525
|
+
const counts = /* @__PURE__ */ new Map();
|
|
41526
|
+
for (const p of listing) {
|
|
41527
|
+
const ext = import_node_path19.posix.extname(p).toLowerCase();
|
|
41528
|
+
if (ext && ext.length <= 12) counts.set(ext, (counts.get(ext) ?? 0) + 1);
|
|
41529
|
+
}
|
|
41530
|
+
return [...counts.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, MAX_LANGUAGES).map(([ext, n]) => `${ext} ${n}`);
|
|
41531
|
+
}
|
|
41532
|
+
function testFacts(i2) {
|
|
41533
|
+
const inWrite = i2.readListing.filter((p) => inside(p, i2.writeRoot));
|
|
41534
|
+
const isTest = testRule(i2.discoveredTests ?? null);
|
|
41535
|
+
const tests = inWrite.filter(isTest);
|
|
41536
|
+
const out = [];
|
|
41537
|
+
if (i2.discoveredTests) out.push(`test files the project's test report lists: ${i2.discoveredTests.filter((p) => inside(p, i2.writeRoot)).length}`);
|
|
41538
|
+
out.push(`test files in ${i2.writeRoot || "the repository"}: ${tests.length}`);
|
|
41539
|
+
const byFolder = /* @__PURE__ */ new Map();
|
|
41540
|
+
const depth = i2.writeRoot === "" ? 0 : i2.writeRoot.split("/").length;
|
|
41541
|
+
for (const t of tests) {
|
|
41542
|
+
const parts = t.split("/");
|
|
41543
|
+
const folder = parts.length > depth + 1 ? parts.slice(0, depth + 1).join("/") : import_node_path19.posix.dirname(t);
|
|
41544
|
+
byFolder.set(folder, (byFolder.get(folder) ?? 0) + 1);
|
|
41545
|
+
}
|
|
41546
|
+
for (const [folder, n] of [...byFolder.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, 3)) {
|
|
41547
|
+
out.push(`${folder}/ holds ${n} of them`);
|
|
41548
|
+
}
|
|
41549
|
+
for (let d = i2.writeRoot; ; d = parentOf2(d)) {
|
|
41550
|
+
const text = i2.readText(d === "" ? "package.json" : `${d}/package.json`);
|
|
41551
|
+
const json = text === null ? null : parseJsonc(text);
|
|
41552
|
+
const script = json && typeof json === "object" && !Array.isArray(json) ? json.scripts?.test : void 0;
|
|
41553
|
+
if (typeof script === "string") {
|
|
41554
|
+
const runner = ["vitest", "jest", "mocha", "ava", "playwright", "cypress"].find((r) => script.includes(r)) ?? (script.includes("node --test") ? "node --test" : null);
|
|
41555
|
+
if (runner) out.push(`test runner: ${runner}`);
|
|
41556
|
+
break;
|
|
41557
|
+
}
|
|
41558
|
+
if (d === "") break;
|
|
41559
|
+
}
|
|
41560
|
+
return out.map(cap);
|
|
41561
|
+
}
|
|
41562
|
+
function folderCounts(listing, root, depth) {
|
|
41563
|
+
const counts = /* @__PURE__ */ new Map();
|
|
41564
|
+
const base = root === "" ? 0 : root.split("/").length;
|
|
41565
|
+
for (const p of listing) {
|
|
41566
|
+
if (!inside(p, root)) continue;
|
|
41567
|
+
const parts = p.split("/");
|
|
41568
|
+
for (let k = base + 1; k <= Math.min(base + depth, parts.length - 1); k++) {
|
|
41569
|
+
const dir = parts.slice(0, k).join("/");
|
|
41570
|
+
counts.set(dir, (counts.get(dir) ?? 0) + 1);
|
|
41571
|
+
}
|
|
41572
|
+
}
|
|
41573
|
+
return counts;
|
|
41574
|
+
}
|
|
41575
|
+
function folderCandidates(i2) {
|
|
41576
|
+
const out = [];
|
|
41577
|
+
const total = (root) => i2.readListing.filter((p) => inside(p, root)).length;
|
|
41578
|
+
for (const r of i2.readRoots) out.push({ text: `${r === "" ? "." : r}/ ${total(r)}`, order: `0 ${r}` });
|
|
41579
|
+
const level = (root, depth) => {
|
|
41580
|
+
const counts = folderCounts(i2.readListing, root, depth);
|
|
41581
|
+
const want = (root === "" ? 0 : root.split("/").length) + depth;
|
|
41582
|
+
return [...counts.entries()].filter(([dir]) => dir.split("/").length === want).sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).map(([dir, n]) => ({ text: `${dir}/ ${n}`, order: `0 ${dir}` }));
|
|
41583
|
+
};
|
|
41584
|
+
const others = i2.readRoots.filter((r) => r !== i2.writeRoot);
|
|
41585
|
+
out.push(...level(i2.writeRoot, 1));
|
|
41586
|
+
for (const r of others) out.push(...level(r, 1));
|
|
41587
|
+
if (i2.writeRoot !== "") {
|
|
41588
|
+
const outside = /* @__PURE__ */ new Map();
|
|
41589
|
+
for (const p of i2.fullListing) {
|
|
41590
|
+
if (i2.readRoots.some((r) => inside(p, r))) continue;
|
|
41591
|
+
const top = p.includes("/") ? p.slice(0, p.indexOf("/")) : null;
|
|
41592
|
+
if (top) outside.set(top, (outside.get(top) ?? 0) + 1);
|
|
41593
|
+
}
|
|
41594
|
+
for (const [dir, n] of [...outside.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1))) {
|
|
41595
|
+
out.push({ text: `(not readable) ${dir}/ ${n}`, order: `1 ${dir}` });
|
|
41596
|
+
}
|
|
41597
|
+
}
|
|
41598
|
+
out.push(...level(i2.writeRoot, 2));
|
|
41599
|
+
for (const r of others) out.push(...level(r, 2));
|
|
41600
|
+
out.push(...level(i2.writeRoot, 3));
|
|
41601
|
+
return out.map((e) => ({ ...e, text: cap(e.text) }));
|
|
41602
|
+
}
|
|
41603
|
+
var mapTokens = (map) => estimateTokens(JSON.stringify(map, null, 2));
|
|
41604
|
+
var lineTokens = (text) => estimateTokens(` ${JSON.stringify(text)},
|
|
41605
|
+
`);
|
|
41606
|
+
function buildRepoMap(i2) {
|
|
41607
|
+
const budget = i2.budgetTokens ?? MAP_BUDGET_TOKENS;
|
|
41608
|
+
const packages = [
|
|
41609
|
+
...i2.packages.map((p) => cap(`${p.name} -> ${p.folder}`)),
|
|
41610
|
+
...i2.packagesLeft && i2.packagesLeft > 0 ? [`+${i2.packagesLeft} more packages it uses are not readable in this run`] : []
|
|
41611
|
+
];
|
|
41612
|
+
const base = (guidance) => ({
|
|
41613
|
+
writeRoots: [i2.writeRoot],
|
|
41614
|
+
readRoots: [...i2.readRoots],
|
|
41615
|
+
fileCount: i2.readListing.length,
|
|
41616
|
+
folders: [],
|
|
41617
|
+
languages: languages(i2.readListing),
|
|
41618
|
+
facts: {
|
|
41619
|
+
pathAliases: aliasTable({ readText: i2.readText, folder: i2.writeRoot }).map(cap),
|
|
41620
|
+
packages,
|
|
41621
|
+
tests: testFacts(i2)
|
|
41622
|
+
},
|
|
41623
|
+
guidance
|
|
41624
|
+
});
|
|
41625
|
+
const candidates = folderCandidates(i2);
|
|
41626
|
+
const roots = candidates.slice(0, i2.readRoots.length);
|
|
41627
|
+
const rootCost = roots.reduce((n, e) => n + lineTokens(e.text), 0) + lineTokens("+999 more folders");
|
|
41628
|
+
let perFile2 = GUIDANCE_FILE_CHARS;
|
|
41629
|
+
let total = GUIDANCE_TOTAL_CHARS;
|
|
41630
|
+
let map = base(guidanceFiles(i2, perFile2, total));
|
|
41631
|
+
while (mapTokens(map) + rootCost > budget && total > 0) {
|
|
41632
|
+
perFile2 = Math.floor(perFile2 / 2);
|
|
41633
|
+
total = perFile2 < 200 ? 0 : Math.floor(total / 2);
|
|
41634
|
+
map = base(guidanceFiles(i2, perFile2, total));
|
|
41635
|
+
}
|
|
41636
|
+
let spent = mapTokens(map) + lineTokens("+999 more folders");
|
|
41637
|
+
const kept = [];
|
|
41638
|
+
for (const entry of candidates) {
|
|
41639
|
+
if (kept.length >= MAX_FOLDERS - 1) break;
|
|
41640
|
+
const cost = lineTokens(entry.text);
|
|
41641
|
+
if (spent + cost > budget) continue;
|
|
41642
|
+
kept.push(entry);
|
|
41643
|
+
spent += cost;
|
|
41644
|
+
}
|
|
41645
|
+
const left = candidates.length - kept.length;
|
|
41646
|
+
kept.sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0);
|
|
41647
|
+
map.folders = [...kept.map((e) => e.text), ...left > 0 ? [`+${left} more folders`] : []];
|
|
41648
|
+
while (mapTokens(map) > budget && map.folders.length > 1) map.folders.splice(map.folders.length - (left > 0 ? 2 : 1), 1);
|
|
41649
|
+
return { map, tokens: mapTokens(map), foldersLeft: left };
|
|
41650
|
+
}
|
|
41651
|
+
|
|
41652
|
+
// src/workspacePackages.ts
|
|
41653
|
+
var import_node_path20 = require("node:path");
|
|
41654
|
+
var MAX_READ_ROOTS = 8;
|
|
41655
|
+
function isObject2(x) {
|
|
41656
|
+
return typeof x === "object" && x !== null && !Array.isArray(x);
|
|
41657
|
+
}
|
|
41658
|
+
function stringList2(x) {
|
|
41659
|
+
return Array.isArray(x) ? x.filter((s) => typeof s === "string" && s.trim() !== "") : [];
|
|
41660
|
+
}
|
|
41661
|
+
function pnpmWorkspacePatterns(text) {
|
|
41662
|
+
const out = [];
|
|
41663
|
+
let inPackages = false;
|
|
41664
|
+
for (const raw of text.replace(/\r\n/g, "\n").split("\n")) {
|
|
41665
|
+
const line = raw.replace(/\s+#.*$/, "");
|
|
41666
|
+
if (/^packages\s*:/.test(line)) {
|
|
41667
|
+
inPackages = true;
|
|
41668
|
+
continue;
|
|
41669
|
+
}
|
|
41670
|
+
if (!inPackages) continue;
|
|
41671
|
+
const item = /^\s+-\s+(.+?)\s*$/.exec(line);
|
|
41672
|
+
if (item) {
|
|
41673
|
+
out.push(item[1].replace(/^["']|["']$/g, ""));
|
|
41674
|
+
continue;
|
|
41675
|
+
}
|
|
41676
|
+
if (line.trim() !== "" && !/^\s/.test(line)) inPackages = false;
|
|
41677
|
+
}
|
|
41678
|
+
return out;
|
|
41679
|
+
}
|
|
41680
|
+
function workspacePatterns(readText) {
|
|
41681
|
+
const root = readText("package.json");
|
|
41682
|
+
if (root !== null) {
|
|
41683
|
+
const json = parseJsonc(root);
|
|
41684
|
+
if (isObject2(json)) {
|
|
41685
|
+
const ws = json.workspaces;
|
|
41686
|
+
const list2 = Array.isArray(ws) ? stringList2(ws) : isObject2(ws) ? stringList2(ws.packages) : [];
|
|
41687
|
+
if (list2.length > 0) return list2;
|
|
41688
|
+
}
|
|
41689
|
+
}
|
|
41690
|
+
const pnpm = readText("pnpm-workspace.yaml");
|
|
41691
|
+
return pnpm === null ? [] : pnpmWorkspacePatterns(pnpm);
|
|
41692
|
+
}
|
|
41693
|
+
function globMatcher(pattern) {
|
|
41694
|
+
const parts = pattern.replace(/^\.\//, "").replace(/\/+$/, "").split("/");
|
|
41695
|
+
const escape = (s) => s.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
41696
|
+
let re = "";
|
|
41697
|
+
parts.forEach((part, i2) => {
|
|
41698
|
+
const first = i2 === 0;
|
|
41699
|
+
if (part === "**") {
|
|
41700
|
+
re += first ? "(?:[^/]+/)*" : "(?:/[^/]+)*";
|
|
41701
|
+
return;
|
|
41702
|
+
}
|
|
41703
|
+
const segment = part.split("*").map(escape).join("[^/]*");
|
|
41704
|
+
re += first || i2 === 1 && parts[0] === "**" ? segment : `/${segment}`;
|
|
41705
|
+
});
|
|
41706
|
+
return new RegExp(`^${re}$`);
|
|
41707
|
+
}
|
|
41708
|
+
function workspacePackages(readText, packageJsonPaths) {
|
|
41709
|
+
const patterns = workspacePatterns(readText);
|
|
41710
|
+
if (patterns.length === 0) return [];
|
|
41711
|
+
const include = patterns.filter((p) => !p.startsWith("!")).map(globMatcher);
|
|
41712
|
+
const exclude = patterns.filter((p) => p.startsWith("!")).map((p) => globMatcher(p.slice(1)));
|
|
41713
|
+
const out = [];
|
|
41714
|
+
for (const file of packageJsonPaths) {
|
|
41715
|
+
if (import_node_path20.posix.basename(file) !== "package.json" || file === "package.json" || file.split("/").includes("node_modules")) continue;
|
|
41716
|
+
const folder = import_node_path20.posix.dirname(file);
|
|
41717
|
+
if (!include.some((re) => re.test(folder)) || exclude.some((re) => re.test(folder))) continue;
|
|
41718
|
+
const text = readText(file);
|
|
41719
|
+
const json = text === null ? null : parseJsonc(text);
|
|
41720
|
+
if (isObject2(json) && typeof json.name === "string" && json.name.trim() !== "") out.push({ name: json.name.trim(), folder });
|
|
41721
|
+
}
|
|
41722
|
+
return out.sort((a, b) => a.folder < b.folder ? -1 : a.folder > b.folder ? 1 : 0);
|
|
41723
|
+
}
|
|
41724
|
+
function dependencyNames2(text) {
|
|
41725
|
+
const json = text === null ? null : parseJsonc(text);
|
|
41726
|
+
if (!isObject2(json)) return [];
|
|
41727
|
+
const names = /* @__PURE__ */ new Set();
|
|
41728
|
+
for (const key of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
41729
|
+
const deps = json[key];
|
|
41730
|
+
if (isObject2(deps)) for (const name of Object.keys(deps)) names.add(name);
|
|
41731
|
+
}
|
|
41732
|
+
return [...names];
|
|
41733
|
+
}
|
|
41734
|
+
function nearestManifest(folder, tracked) {
|
|
41735
|
+
for (let d = folder; ; d = d.includes("/") ? d.slice(0, d.lastIndexOf("/")) : "") {
|
|
41736
|
+
const file = d === "" ? "package.json" : `${d}/package.json`;
|
|
41737
|
+
if (tracked.has(file)) return file;
|
|
41738
|
+
if (d === "") return null;
|
|
41739
|
+
}
|
|
41740
|
+
}
|
|
41741
|
+
var inside2 = (path, root) => root === "" || path === root || path.startsWith(`${root}/`);
|
|
41742
|
+
function readRootsFor(i2) {
|
|
41743
|
+
if (i2.writeRoot === "") return { readRoots: [""], packages: [], left: 0 };
|
|
41744
|
+
const manifest = nearestManifest(i2.writeRoot, new Set(i2.packageJsonPaths));
|
|
41745
|
+
const wanted = new Set(manifest ? dependencyNames2(i2.readText(manifest)) : []);
|
|
41746
|
+
const used = workspacePackages(i2.readText, i2.packageJsonPaths).filter(
|
|
41747
|
+
(p) => wanted.has(p.name) && !inside2(p.folder, i2.writeRoot) && !inside2(i2.writeRoot, p.folder)
|
|
41748
|
+
);
|
|
41749
|
+
const kept = used.slice(0, MAX_READ_ROOTS - 1);
|
|
41750
|
+
return { readRoots: [i2.writeRoot, ...kept.map((p) => p.folder)], packages: kept, left: used.length - kept.length };
|
|
41751
|
+
}
|
|
41752
|
+
|
|
41753
|
+
// src/repoScope.ts
|
|
41754
|
+
function buildRepoScope(i2) {
|
|
41755
|
+
const decided = wantsMap(i2.setting, i2.writeListing);
|
|
41756
|
+
const log = i2.log ?? (() => {
|
|
41757
|
+
});
|
|
41758
|
+
if (!decided.map) {
|
|
41759
|
+
return {
|
|
41760
|
+
view: "listing",
|
|
41761
|
+
writeRoot: i2.writeRoot,
|
|
41762
|
+
readRoots: [i2.writeRoot],
|
|
41763
|
+
writeListing: i2.writeListing,
|
|
41764
|
+
readListing: i2.writeListing,
|
|
41765
|
+
packages: [],
|
|
41766
|
+
listingTokens: decided.listingTokens
|
|
41767
|
+
};
|
|
41768
|
+
}
|
|
41769
|
+
const fullListing = i2.listAll();
|
|
41770
|
+
const { readRoots, packages, left } = readRootsFor({
|
|
41771
|
+
writeRoot: i2.writeRoot,
|
|
41772
|
+
readText: i2.readText,
|
|
41773
|
+
packageJsonPaths: fullListing.filter((p) => p === "package.json" || p.endsWith("/package.json"))
|
|
41774
|
+
});
|
|
41775
|
+
const readListing = readRoots.length === 1 ? i2.writeListing : fullListing.filter((p) => readRoots.some((r) => matchesPrefix(p, r)));
|
|
41776
|
+
const built = buildRepoMap({
|
|
41777
|
+
writeRoot: i2.writeRoot,
|
|
41778
|
+
readRoots,
|
|
41779
|
+
readListing,
|
|
41780
|
+
fullListing,
|
|
41781
|
+
packages,
|
|
41782
|
+
packagesLeft: left,
|
|
41783
|
+
readText: i2.readText,
|
|
41784
|
+
deniedPaths: i2.deniedPaths,
|
|
41785
|
+
scrub: i2.scrub,
|
|
41786
|
+
...i2.discoveredTests ? { discoveredTests: i2.discoveredTests } : {}
|
|
41787
|
+
});
|
|
41788
|
+
log({
|
|
41789
|
+
event: "map.built",
|
|
41790
|
+
setting: i2.setting,
|
|
41791
|
+
listingTokens: decided.listingTokens,
|
|
41792
|
+
mapTokens: built.tokens,
|
|
41793
|
+
readRoots: readRoots.length,
|
|
41794
|
+
packagesLeft: left,
|
|
41795
|
+
fileCount: readListing.length,
|
|
41796
|
+
folders: built.map.folders.length,
|
|
41797
|
+
foldersLeft: built.foldersLeft,
|
|
41798
|
+
guidance: built.map.guidance.length
|
|
41799
|
+
});
|
|
41800
|
+
return {
|
|
41801
|
+
view: "map",
|
|
41802
|
+
writeRoot: i2.writeRoot,
|
|
41803
|
+
readRoots,
|
|
41804
|
+
writeListing: i2.writeListing,
|
|
41805
|
+
readListing,
|
|
41806
|
+
repoMap: built.map,
|
|
41807
|
+
mapTokens: built.tokens,
|
|
41808
|
+
packages,
|
|
41809
|
+
listingTokens: decided.listingTokens
|
|
41810
|
+
};
|
|
41811
|
+
}
|
|
41812
|
+
|
|
41813
|
+
// src/targetingMode.ts
|
|
41814
|
+
var TARGETING_MODE_ENV = "QUIKPILOT_TARGETING_MODE";
|
|
41815
|
+
function parse5(value) {
|
|
41816
|
+
if (typeof value !== "string") return null;
|
|
41817
|
+
const v = value.trim().toLowerCase();
|
|
41818
|
+
if (v === "loop") return "loop";
|
|
41819
|
+
if (v === "single") return "single";
|
|
41820
|
+
return null;
|
|
41821
|
+
}
|
|
41822
|
+
function resolveTargetingMode(env2 = process.env, packetSetting) {
|
|
41823
|
+
const fromSetting = parse5(packetSetting);
|
|
41824
|
+
if (fromSetting) return fromSetting;
|
|
41825
|
+
return parse5(env2[TARGETING_MODE_ENV]) ?? "single";
|
|
41826
|
+
}
|
|
41827
|
+
|
|
41350
41828
|
// src/installationToken.ts
|
|
41351
41829
|
async function exchangeForInstallationToken(installationTokenUrl, runToken) {
|
|
41352
41830
|
const res = await fetch(installationTokenUrl, {
|
|
@@ -41513,23 +41991,23 @@ function writePhase0Marker(runId) {
|
|
|
41513
41991
|
|
|
41514
41992
|
// src/failureArtifact.ts
|
|
41515
41993
|
var import_node_fs21 = require("node:fs");
|
|
41516
|
-
var
|
|
41994
|
+
var import_node_path21 = require("node:path");
|
|
41517
41995
|
var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
|
|
41518
41996
|
var REPORT_COPY = "final-test-report.xml";
|
|
41519
41997
|
var MAX_REPORT_BYTES = 5 * 1024 * 1024;
|
|
41520
41998
|
var MAX_FILES = 200;
|
|
41521
|
-
var RUNNER_VERSION = true ? "9.3.0-rc.
|
|
41999
|
+
var RUNNER_VERSION = true ? "9.3.0-rc.32" : "dev";
|
|
41522
42000
|
function safeDestination(base, repoPath) {
|
|
41523
|
-
if (!repoPath || (0,
|
|
41524
|
-
const destination = (0,
|
|
41525
|
-
const rel = (0,
|
|
41526
|
-
if (!rel || rel.startsWith("..") || (0,
|
|
42001
|
+
if (!repoPath || (0, import_node_path21.isAbsolute)(repoPath)) return null;
|
|
42002
|
+
const destination = (0, import_node_path21.resolve)(base, repoPath);
|
|
42003
|
+
const rel = (0, import_node_path21.relative)(base, destination);
|
|
42004
|
+
if (!rel || rel.startsWith("..") || (0, import_node_path21.isAbsolute)(rel)) return null;
|
|
41527
42005
|
return destination;
|
|
41528
42006
|
}
|
|
41529
42007
|
function writeFailureArtifact(input) {
|
|
41530
42008
|
if (input.results.length === 0) return { written: false };
|
|
41531
42009
|
try {
|
|
41532
|
-
const base = (0,
|
|
42010
|
+
const base = (0, import_node_path21.resolve)(input.cwd, FAILURE_ARTIFACT_DIR);
|
|
41533
42011
|
(0, import_node_fs21.rmSync)(base, { recursive: true, force: true });
|
|
41534
42012
|
(0, import_node_fs21.mkdirSync)(base, { recursive: true });
|
|
41535
42013
|
const files = [];
|
|
@@ -41540,7 +42018,7 @@ function writeFailureArtifact(input) {
|
|
|
41540
42018
|
skipped.push(result.targetPath);
|
|
41541
42019
|
continue;
|
|
41542
42020
|
}
|
|
41543
|
-
(0, import_node_fs21.mkdirSync)((0,
|
|
42021
|
+
(0, import_node_fs21.mkdirSync)((0, import_node_path21.dirname)(destination), { recursive: true });
|
|
41544
42022
|
(0, import_node_fs21.writeFileSync)(destination, result.newContent);
|
|
41545
42023
|
files.push({ path: result.targetPath, bytes: Buffer.byteLength(result.newContent) });
|
|
41546
42024
|
}
|
|
@@ -41549,7 +42027,7 @@ function writeFailureArtifact(input) {
|
|
|
41549
42027
|
if (input.testReport.byteLength > MAX_REPORT_BYTES) {
|
|
41550
42028
|
testReport = "too-large";
|
|
41551
42029
|
} else {
|
|
41552
|
-
(0, import_node_fs21.writeFileSync)((0,
|
|
42030
|
+
(0, import_node_fs21.writeFileSync)((0, import_node_path21.join)(base, REPORT_COPY), input.testReport);
|
|
41553
42031
|
testReport = "included";
|
|
41554
42032
|
}
|
|
41555
42033
|
}
|
|
@@ -41569,8 +42047,8 @@ function writeFailureArtifact(input) {
|
|
|
41569
42047
|
failureReasons: input.failureReasons
|
|
41570
42048
|
};
|
|
41571
42049
|
const text = JSON.stringify(manifest, (_key, value) => typeof value === "string" ? scrubSecrets(value, input.secrets) : value, 2);
|
|
41572
|
-
(0, import_node_fs21.writeFileSync)((0,
|
|
41573
|
-
return { written: (0, import_node_fs21.existsSync)((0,
|
|
42050
|
+
(0, import_node_fs21.writeFileSync)((0, import_node_path21.join)(base, "manifest.json"), text);
|
|
42051
|
+
return { written: (0, import_node_fs21.existsSync)((0, import_node_path21.join)(base, "manifest.json")) };
|
|
41574
42052
|
} catch (err) {
|
|
41575
42053
|
console.warn(`::warning::Could not keep the failed run's files: ${err instanceof Error ? err.message : String(err)}`);
|
|
41576
42054
|
return { written: false };
|
|
@@ -41696,21 +42174,6 @@ function prepareTargetingFindings(raw, listing, deniedPaths) {
|
|
|
41696
42174
|
};
|
|
41697
42175
|
}
|
|
41698
42176
|
|
|
41699
|
-
// src/targetingMode.ts
|
|
41700
|
-
var TARGETING_MODE_ENV = "QUIKPILOT_TARGETING_MODE";
|
|
41701
|
-
function parse5(value) {
|
|
41702
|
-
if (typeof value !== "string") return null;
|
|
41703
|
-
const v = value.trim().toLowerCase();
|
|
41704
|
-
if (v === "loop") return "loop";
|
|
41705
|
-
if (v === "single") return "single";
|
|
41706
|
-
return null;
|
|
41707
|
-
}
|
|
41708
|
-
function resolveTargetingMode(env2 = process.env, packetSetting) {
|
|
41709
|
-
const fromSetting = parse5(packetSetting);
|
|
41710
|
-
if (fromSetting) return fromSetting;
|
|
41711
|
-
return parse5(env2[TARGETING_MODE_ENV]) ?? "single";
|
|
41712
|
-
}
|
|
41713
|
-
|
|
41714
42177
|
// src/targeting.ts
|
|
41715
42178
|
var CONTRACT_VERSION2 = "test-targets-1";
|
|
41716
42179
|
function listWorkspaceFiles(workspaceRoot) {
|
|
@@ -41839,6 +42302,9 @@ async function runSingleShot(gateway, design, workspaceRoot, workspaceListing, r
|
|
|
41839
42302
|
}
|
|
41840
42303
|
var CODE_LIKE = /^[A-Z0-9_]{1,40}$/;
|
|
41841
42304
|
async function runTargeting(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope = [], options = {}) {
|
|
42305
|
+
if (options.scope?.view === "map") {
|
|
42306
|
+
return runMapTargeting(gateway, design, workspaceRoot, options.scope, requiredTests, deniedPaths, testDiscovery, outOfScope, options);
|
|
42307
|
+
}
|
|
41842
42308
|
const mode = options.mode ?? resolveTargetingMode();
|
|
41843
42309
|
const findings = prepareTargetingFindings(options.findings, new Set(workspaceListing), deniedPaths);
|
|
41844
42310
|
if (mode !== "loop") {
|
|
@@ -41891,6 +42357,44 @@ async function runTargeting(gateway, design, workspaceRoot, workspaceListing, re
|
|
|
41891
42357
|
warnings: [`QuikPilot's read-only targeting could not complete (${reason}); standard targeting was used instead.`, ...single.warnings ?? []]
|
|
41892
42358
|
};
|
|
41893
42359
|
}
|
|
42360
|
+
var MAP_DISCOVERY_MAX_TOKENS = 12e3;
|
|
42361
|
+
function mapTestDiscovery(testDiscovery) {
|
|
42362
|
+
if (testDiscovery.report !== "PRESENT") return testDiscovery;
|
|
42363
|
+
if (estimateTokens(JSON.stringify(testDiscovery.discoveredTestFiles, null, 2)) <= MAP_DISCOVERY_MAX_TOKENS) return testDiscovery;
|
|
42364
|
+
return { report: "PRESENT", discoveredTestFiles: [], unmappedEntries: Math.max(1, testDiscovery.unmappedEntries + testDiscovery.discoveredTestFiles.length) };
|
|
42365
|
+
}
|
|
42366
|
+
function buildMapContextData(repoMap, design, requiredTests, deniedPaths, testDiscovery, outOfScope, findings) {
|
|
42367
|
+
return {
|
|
42368
|
+
repoMap,
|
|
42369
|
+
design,
|
|
42370
|
+
requiredTests,
|
|
42371
|
+
contractVersion: MAP_LOOP_CONTRACT_VERSION,
|
|
42372
|
+
...deniedPaths.length > 0 ? { deniedPaths } : {},
|
|
42373
|
+
...outOfScope.length > 0 ? { outOfScope } : {},
|
|
42374
|
+
testDiscovery: mapTestDiscovery(testDiscovery),
|
|
42375
|
+
...findings ? { findings } : {}
|
|
42376
|
+
};
|
|
42377
|
+
}
|
|
42378
|
+
async function runMapTargeting(gateway, design, workspaceRoot, scope, requiredTests, deniedPaths, testDiscovery, outOfScope, options) {
|
|
42379
|
+
const findings = prepareTargetingFindings(options.findings, new Set(scope.readListing), deniedPaths);
|
|
42380
|
+
const baseContext = buildMapContextData(scope.repoMap, design, requiredTests, deniedPaths, testDiscovery, outOfScope, findings);
|
|
42381
|
+
const repoView = repoViewOf(scope);
|
|
42382
|
+
const log = options.loopDeps?.log ?? ((e) => console.log(JSON.stringify(e)));
|
|
42383
|
+
let reason;
|
|
42384
|
+
try {
|
|
42385
|
+
const looped = await runTargetingLoop(
|
|
42386
|
+
{ baseContext, listing: scope.readListing, deniedPaths, readRoots: scope.readRoots, contractVersion: MAP_LOOP_CONTRACT_VERSION },
|
|
42387
|
+
{ secrets: [gateway.token], ...options.loopDeps, post: (contextData, signal) => postTargeting(gateway, contextData, signal) }
|
|
42388
|
+
);
|
|
42389
|
+
const result = finalizeTargeting(looped.body, workspaceRoot, scope.writeListing, deniedPaths);
|
|
42390
|
+
return { ...result, loop: { ...looped.summary, ...repoView ? { repoView } : {} } };
|
|
42391
|
+
} catch (err) {
|
|
42392
|
+
if (err instanceof DeniedPathError || err instanceof SafetyRefusalError) throw err;
|
|
42393
|
+
reason = err instanceof LoopFailure ? err.reason : "final_invalid";
|
|
42394
|
+
}
|
|
42395
|
+
log({ event: "targeting.map_failed", reason });
|
|
42396
|
+
throw new MapModeError("targeting", reason);
|
|
42397
|
+
}
|
|
41894
42398
|
|
|
41895
42399
|
// src/targetingRecord.ts
|
|
41896
42400
|
var MAX_TARGETS = 25;
|
|
@@ -41902,7 +42406,7 @@ var MAX_SKIPPED_CASES = 200;
|
|
|
41902
42406
|
var MAX_CONTEXT_RECORDS = 25;
|
|
41903
42407
|
var MAX_PATH_CHARS3 = 300;
|
|
41904
42408
|
var MAX_ID_CHARS3 = 100;
|
|
41905
|
-
var
|
|
42409
|
+
var MAX_REASON_CHARS3 = 300;
|
|
41906
42410
|
var MAX_LOOP_READS = 50;
|
|
41907
42411
|
var MAX_FALLBACK_REASON_CHARS = 40;
|
|
41908
42412
|
function clampList(values, max, maxChars) {
|
|
@@ -41952,6 +42456,7 @@ function clampLoop(loop) {
|
|
|
41952
42456
|
stopReason: loop.stopReason,
|
|
41953
42457
|
...loop.fellBack ? { fellBack: true } : {},
|
|
41954
42458
|
...loop.fallbackReason ? { fallbackReason: String(loop.fallbackReason).slice(0, MAX_FALLBACK_REASON_CHARS) } : {},
|
|
42459
|
+
...clampRepoView(loop.repoView, loop.peakRequestTokens),
|
|
41955
42460
|
reads,
|
|
41956
42461
|
...refusedTurns.rows.length > 0 ? { refusedTurns: refusedTurns.rows } : {},
|
|
41957
42462
|
...cut ? { truncated: true } : {}
|
|
@@ -41966,8 +42471,8 @@ function buildTargetingRecord(targeting, contextLog) {
|
|
|
41966
42471
|
const record3 = { outcome: "NO_TARGET", targets: [], skippedCaseIds: [], codegenContext: [] };
|
|
41967
42472
|
const reason = (targeting.reason ?? "").trim();
|
|
41968
42473
|
if (reason.length > 0) {
|
|
41969
|
-
record3.noTargetReason = reason.slice(0,
|
|
41970
|
-
if (reason.length >
|
|
42474
|
+
record3.noTargetReason = reason.slice(0, MAX_REASON_CHARS3);
|
|
42475
|
+
if (reason.length > MAX_REASON_CHARS3) record3.noTargetReasonTruncated = true;
|
|
41971
42476
|
}
|
|
41972
42477
|
if (targeting.loop) record3.loop = clampLoop(targeting.loop);
|
|
41973
42478
|
return record3;
|
|
@@ -42098,6 +42603,26 @@ async function run(env2) {
|
|
|
42098
42603
|
const writeRoot = normaliseWorkspaceRoot(packet.workspaceRoot);
|
|
42099
42604
|
scopeRoot = writeRoot;
|
|
42100
42605
|
const workspaceListing = listWorkspaceFiles(writeRoot === "" ? null : writeRoot);
|
|
42606
|
+
const scope = buildRepoScope({
|
|
42607
|
+
writeRoot,
|
|
42608
|
+
writeListing: workspaceListing,
|
|
42609
|
+
setting: resolveMapSetting(),
|
|
42610
|
+
listAll: () => listFiles("."),
|
|
42611
|
+
readText: (path) => {
|
|
42612
|
+
try {
|
|
42613
|
+
return (0, import_node_fs22.readFileSync)(path, "utf8");
|
|
42614
|
+
} catch {
|
|
42615
|
+
return null;
|
|
42616
|
+
}
|
|
42617
|
+
},
|
|
42618
|
+
deniedPaths: packet.guardrails.deniedPaths,
|
|
42619
|
+
scrub: makeCodeScrubber([runToken, packet.gateway.token].filter((s) => typeof s === "string" && s.length > 0)),
|
|
42620
|
+
log: (e) => console.log(JSON.stringify(e))
|
|
42621
|
+
});
|
|
42622
|
+
const mapMode = scope.view === "map";
|
|
42623
|
+
if (mapMode) {
|
|
42624
|
+
console.log(JSON.stringify(startMapMode({ testCommand: packet.commands.test, targetingMode: resolveTargetingMode(), codegenMode: resolveCodegenMode() })));
|
|
42625
|
+
}
|
|
42101
42626
|
const outOfScope = (packet.outOfScope ?? []).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
42102
42627
|
const setupStartedAt = Date.now();
|
|
42103
42628
|
runCommand(packet.commands.setup, "Setup");
|
|
@@ -42134,7 +42659,7 @@ async function run(env2) {
|
|
|
42134
42659
|
packet.guardrails.deniedPaths,
|
|
42135
42660
|
discovery.result.value,
|
|
42136
42661
|
outOfScope,
|
|
42137
|
-
...packet.findings ? [{ findings: packet.findings }] : []
|
|
42662
|
+
...packet.findings || mapMode ? [{ ...packet.findings ? { findings: packet.findings } : {}, ...mapMode ? { scope } : {} }] : []
|
|
42138
42663
|
);
|
|
42139
42664
|
targetingResult = targeting;
|
|
42140
42665
|
for (const w of targeting.warnings ?? []) {
|
|
@@ -42186,7 +42711,7 @@ async function run(env2) {
|
|
|
42186
42711
|
targeting.targets,
|
|
42187
42712
|
targeting.skippedCases ?? []
|
|
42188
42713
|
);
|
|
42189
|
-
const codegenMode = resolveCodegenMode();
|
|
42714
|
+
const codegenMode = mapMode ? "loop-tests" : resolveCodegenMode();
|
|
42190
42715
|
const keepOnGiveUp = codegenMode === "loop-tests" && packet.guardrails.maxHealIterations > 0 && process.env.QUIKPILOT_KEEP_ON_GIVE_UP?.trim().toLowerCase() !== "off";
|
|
42191
42716
|
const callFunctionAllowed = callFunctionEnabled(env2.githubRepository, codegenMode);
|
|
42192
42717
|
const callFunctionFits = callFunctionFitsTargets(targeting.targets, discoveredTestsOf(packet.testDiscovery));
|
|
@@ -42224,6 +42749,7 @@ async function run(env2) {
|
|
|
42224
42749
|
gateway: packet.gateway,
|
|
42225
42750
|
targets: targeting.targets,
|
|
42226
42751
|
workspaceListing,
|
|
42752
|
+
...mapMode ? { scope } : {},
|
|
42227
42753
|
...writeRoot ? { writeRoot } : {},
|
|
42228
42754
|
requiredTests: packet.requiredTests,
|
|
42229
42755
|
deniedPaths: packet.guardrails.deniedPaths,
|