@quikit/quikpilot-runner 9.3.0-rc.35 → 9.3.0-rc.37
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 +4 -0
- package/dist/index.js +280 -107
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -144,8 +144,8 @@ var require_types = __commonJS({
|
|
|
144
144
|
TokenType4[TokenType4["IS_POSTFIX"] = IS_POSTFIX] = "IS_POSTFIX";
|
|
145
145
|
const IS_EXPRESSION_START = 1 << 9;
|
|
146
146
|
TokenType4[TokenType4["IS_EXPRESSION_START"] = IS_EXPRESSION_START] = "IS_EXPRESSION_START";
|
|
147
|
-
const
|
|
148
|
-
TokenType4[TokenType4["num"] =
|
|
147
|
+
const num2 = 512;
|
|
148
|
+
TokenType4[TokenType4["num"] = num2] = "num";
|
|
149
149
|
const bigint = 1536;
|
|
150
150
|
TokenType4[TokenType4["bigint"] = bigint] = "bigint";
|
|
151
151
|
const decimal = 2560;
|
|
@@ -12785,8 +12785,8 @@ var require_sourcemap_codec_umd = __commonJS({
|
|
|
12785
12785
|
}
|
|
12786
12786
|
return relative10 + value;
|
|
12787
12787
|
}
|
|
12788
|
-
function encodeInteger(builder,
|
|
12789
|
-
let delta =
|
|
12788
|
+
function encodeInteger(builder, num2, relative10) {
|
|
12789
|
+
let delta = num2 - relative10;
|
|
12790
12790
|
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
12791
12791
|
do {
|
|
12792
12792
|
let clamped = delta & 31;
|
|
@@ -12794,7 +12794,7 @@ var require_sourcemap_codec_umd = __commonJS({
|
|
|
12794
12794
|
if (delta > 0) clamped |= 32;
|
|
12795
12795
|
builder.write(intToChar[clamped]);
|
|
12796
12796
|
} while (delta > 0);
|
|
12797
|
-
return
|
|
12797
|
+
return num2;
|
|
12798
12798
|
}
|
|
12799
12799
|
function hasMoreVlq(reader, max) {
|
|
12800
12800
|
if (reader.pos >= max) return false;
|
|
@@ -12851,7 +12851,7 @@ var require_sourcemap_codec_umd = __commonJS({
|
|
|
12851
12851
|
return idx === -1 ? buffer.length : idx;
|
|
12852
12852
|
}
|
|
12853
12853
|
};
|
|
12854
|
-
var
|
|
12854
|
+
var EMPTY2 = [];
|
|
12855
12855
|
function decodeOriginalScopes(input) {
|
|
12856
12856
|
const { length } = input;
|
|
12857
12857
|
const reader = new StringReader(input);
|
|
@@ -12871,7 +12871,7 @@ var require_sourcemap_codec_umd = __commonJS({
|
|
|
12871
12871
|
const fields = decodeInteger(reader, 0);
|
|
12872
12872
|
const hasName = fields & 1;
|
|
12873
12873
|
const scope = hasName ? [line, column, 0, 0, kind, decodeInteger(reader, 0)] : [line, column, 0, 0, kind];
|
|
12874
|
-
let vars =
|
|
12874
|
+
let vars = EMPTY2;
|
|
12875
12875
|
if (hasMoreVlq(reader, length)) {
|
|
12876
12876
|
vars = [];
|
|
12877
12877
|
do {
|
|
@@ -12947,7 +12947,7 @@ var require_sourcemap_codec_umd = __commonJS({
|
|
|
12947
12947
|
const hasCallsite = fields & 2;
|
|
12948
12948
|
const hasScope = fields & 4;
|
|
12949
12949
|
let callsite = null;
|
|
12950
|
-
let bindings =
|
|
12950
|
+
let bindings = EMPTY2;
|
|
12951
12951
|
let range;
|
|
12952
12952
|
if (hasDefinition) {
|
|
12953
12953
|
const defSourcesIndex = decodeInteger(reader, definitionSourcesIndex);
|
|
@@ -24436,7 +24436,7 @@ async function describeQuikTrackFailure(res) {
|
|
|
24436
24436
|
|
|
24437
24437
|
// src/callback.ts
|
|
24438
24438
|
async function reportBack(params) {
|
|
24439
|
-
const { callbackUrl, runToken, status, branch, warnings, targeting, baselineFindings, vanishedTests, unsuppliedInputs, changesNoTestDependsOn, testsCorrected, codegenLoop, unresolved } = params;
|
|
24439
|
+
const { callbackUrl, runToken, status, branch, warnings, targeting, baselineFindings, vanishedTests, unsuppliedInputs, changesNoTestDependsOn, testsCorrected, codegenLoop, unresolved, aiCostUsd } = params;
|
|
24440
24440
|
const body = { status };
|
|
24441
24441
|
if (branch) body.branch = branch;
|
|
24442
24442
|
if (warnings && warnings.length > 0) body.warnings = warnings;
|
|
@@ -24448,6 +24448,7 @@ async function reportBack(params) {
|
|
|
24448
24448
|
if (changesNoTestDependsOn && changesNoTestDependsOn.hunks.length > 0) body.changesNoTestDependsOn = changesNoTestDependsOn;
|
|
24449
24449
|
if (testsCorrected && testsCorrected.files.length > 0) body.testsCorrected = testsCorrected;
|
|
24450
24450
|
if (codegenLoop) body.codegenLoop = codegenLoop;
|
|
24451
|
+
if (typeof aiCostUsd === "number" && Number.isFinite(aiCostUsd) && aiCostUsd > 0) body.aiCostUsd = Math.round(aiCostUsd * 1e6) / 1e6;
|
|
24451
24452
|
const res = await fetch(callbackUrl, {
|
|
24452
24453
|
method: "POST",
|
|
24453
24454
|
headers: { Authorization: `Bearer ${runToken}`, "Content-Type": "application/json" },
|
|
@@ -26348,6 +26349,144 @@ function commitAndPush(branch, runId, installationToken, targeted, issueKey, iss
|
|
|
26348
26349
|
return { changed: true, branch };
|
|
26349
26350
|
}
|
|
26350
26351
|
|
|
26352
|
+
// src/tokenEstimate.ts
|
|
26353
|
+
var TOKENS_PER_ALPHA_CHAR = 0.3;
|
|
26354
|
+
var TOKENS_PER_DIGIT_CHAR = 0.18;
|
|
26355
|
+
var TOKENS_PER_SPACE_CHAR = 0.05;
|
|
26356
|
+
var TOKENS_PER_PUNCTUATION_CHAR = 1.05;
|
|
26357
|
+
var TOKENS_PER_NON_ASCII_CHAR = 1;
|
|
26358
|
+
var PROMPT_OVERHEAD_TOKENS = 5e3;
|
|
26359
|
+
function estimateTokens(text) {
|
|
26360
|
+
let alpha = 0;
|
|
26361
|
+
let digit = 0;
|
|
26362
|
+
let space = 0;
|
|
26363
|
+
let punct = 0;
|
|
26364
|
+
let nonAscii = 0;
|
|
26365
|
+
for (const ch of text) {
|
|
26366
|
+
const code = ch.codePointAt(0);
|
|
26367
|
+
if (code >= 128) nonAscii++;
|
|
26368
|
+
else if (code >= 65 && code <= 90 || code >= 97 && code <= 122) alpha++;
|
|
26369
|
+
else if (code >= 48 && code <= 57) digit++;
|
|
26370
|
+
else if (code === 32 || code === 9 || code === 13 || code === 10) space++;
|
|
26371
|
+
else punct++;
|
|
26372
|
+
}
|
|
26373
|
+
return Math.ceil(
|
|
26374
|
+
alpha * TOKENS_PER_ALPHA_CHAR + digit * TOKENS_PER_DIGIT_CHAR + space * TOKENS_PER_SPACE_CHAR + punct * TOKENS_PER_PUNCTUATION_CHAR + nonAscii * TOKENS_PER_NON_ASCII_CHAR
|
|
26375
|
+
);
|
|
26376
|
+
}
|
|
26377
|
+
function estimateRequestTokens(contextData) {
|
|
26378
|
+
return PROMPT_OVERHEAD_TOKENS + estimateTokens(JSON.stringify(contextData ?? {}, null, 2));
|
|
26379
|
+
}
|
|
26380
|
+
|
|
26381
|
+
// src/turnUsage.ts
|
|
26382
|
+
var MAX_TURN_ROWS = 30;
|
|
26383
|
+
var num = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : void 0;
|
|
26384
|
+
function usageOf(envelope) {
|
|
26385
|
+
if (typeof envelope !== "object" || envelope === null) return {};
|
|
26386
|
+
const e = envelope;
|
|
26387
|
+
const tokensIn = num(e.tokensInput);
|
|
26388
|
+
const tokensOut = num(e.tokensOutput);
|
|
26389
|
+
const costUsd = num(e.costEstimateUsd);
|
|
26390
|
+
const ms = num(e.latencyMs);
|
|
26391
|
+
return {
|
|
26392
|
+
...tokensIn !== void 0 ? { tokensIn: Math.round(tokensIn) } : {},
|
|
26393
|
+
...tokensOut !== void 0 ? { tokensOut: Math.round(tokensOut) } : {},
|
|
26394
|
+
...costUsd !== void 0 ? { costUsd } : {},
|
|
26395
|
+
...ms !== void 0 ? { ms: Math.round(ms) } : {}
|
|
26396
|
+
};
|
|
26397
|
+
}
|
|
26398
|
+
var sizeOf = (value) => value === void 0 ? 0 : estimateTokens(JSON.stringify(value, null, 2));
|
|
26399
|
+
var RESULT_KEYS = /* @__PURE__ */ new Set(["transcript", "toolResults", "previousAttempt"]);
|
|
26400
|
+
function requestParts(contextData) {
|
|
26401
|
+
const parts = { fixed: PROMPT_OVERHEAD_TOKENS, map: 0, cases: 0, task: 0, results: 0, notes: 0, other: 0 };
|
|
26402
|
+
for (const [key, value] of Object.entries(contextData)) {
|
|
26403
|
+
if (key === "repoMap" || key === "workspaceListing") parts.map += sizeOf(value);
|
|
26404
|
+
else if (key === "requiredTests") parts.cases += sizeOf(value);
|
|
26405
|
+
else if (key === "loop" && typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
26406
|
+
for (const [loopKey, loopValue] of Object.entries(value)) {
|
|
26407
|
+
if (RESULT_KEYS.has(loopKey)) parts.results += sizeOf(loopValue);
|
|
26408
|
+
else if (loopKey === "recap") parts.notes += sizeOf(loopValue);
|
|
26409
|
+
else parts.other += sizeOf(loopValue);
|
|
26410
|
+
}
|
|
26411
|
+
} else parts.task += sizeOf(value);
|
|
26412
|
+
}
|
|
26413
|
+
return parts;
|
|
26414
|
+
}
|
|
26415
|
+
var TurnUsage = class {
|
|
26416
|
+
rows = [];
|
|
26417
|
+
rowsCut = false;
|
|
26418
|
+
totals = { calls: 0, tokensIn: 0, tokensOut: 0, costUsd: 0 };
|
|
26419
|
+
record(turn, contextData, estTokens, envelope, elapsedMs) {
|
|
26420
|
+
const used = usageOf(envelope);
|
|
26421
|
+
this.totals.calls += 1;
|
|
26422
|
+
this.totals.tokensIn += used.tokensIn ?? 0;
|
|
26423
|
+
this.totals.tokensOut += used.tokensOut ?? 0;
|
|
26424
|
+
this.totals.costUsd += used.costUsd ?? 0;
|
|
26425
|
+
if (this.rows.length >= MAX_TURN_ROWS) {
|
|
26426
|
+
this.rowsCut = true;
|
|
26427
|
+
return;
|
|
26428
|
+
}
|
|
26429
|
+
this.rows.push({
|
|
26430
|
+
turn,
|
|
26431
|
+
estTokens,
|
|
26432
|
+
parts: requestParts(contextData),
|
|
26433
|
+
...used.tokensIn !== void 0 ? { tokensIn: used.tokensIn } : {},
|
|
26434
|
+
...used.tokensOut !== void 0 ? { tokensOut: used.tokensOut } : {},
|
|
26435
|
+
...used.costUsd !== void 0 ? { costUsd: used.costUsd } : {},
|
|
26436
|
+
seconds: Math.max(0, Math.round(elapsedMs / 1e3))
|
|
26437
|
+
});
|
|
26438
|
+
}
|
|
26439
|
+
};
|
|
26440
|
+
function addTotals(a, b) {
|
|
26441
|
+
return {
|
|
26442
|
+
calls: (a?.calls ?? 0) + (b?.calls ?? 0),
|
|
26443
|
+
tokensIn: (a?.tokensIn ?? 0) + (b?.tokensIn ?? 0),
|
|
26444
|
+
tokensOut: (a?.tokensOut ?? 0) + (b?.tokensOut ?? 0),
|
|
26445
|
+
costUsd: (a?.costUsd ?? 0) + (b?.costUsd ?? 0)
|
|
26446
|
+
};
|
|
26447
|
+
}
|
|
26448
|
+
var whole = (n, max) => typeof n === "number" && Number.isFinite(n) && n >= 0 ? Math.min(Math.round(n), max) : 0;
|
|
26449
|
+
var money = (n) => typeof n === "number" && Number.isFinite(n) && n >= 0 ? Math.min(Math.round(n * 1e6) / 1e6, 1e3) : 0;
|
|
26450
|
+
function clampTurnRows(rows) {
|
|
26451
|
+
if (!rows || rows.length === 0) return void 0;
|
|
26452
|
+
return rows.slice(0, MAX_TURN_ROWS).map((r) => ({
|
|
26453
|
+
turn: whole(r.turn, 1e3),
|
|
26454
|
+
estTokens: whole(r.estTokens, 1e7),
|
|
26455
|
+
parts: {
|
|
26456
|
+
fixed: whole(r.parts.fixed, 1e7),
|
|
26457
|
+
map: whole(r.parts.map, 1e7),
|
|
26458
|
+
cases: whole(r.parts.cases, 1e7),
|
|
26459
|
+
task: whole(r.parts.task, 1e7),
|
|
26460
|
+
results: whole(r.parts.results, 1e7),
|
|
26461
|
+
notes: whole(r.parts.notes, 1e7),
|
|
26462
|
+
other: whole(r.parts.other, 1e7)
|
|
26463
|
+
},
|
|
26464
|
+
...r.tokensIn !== void 0 ? { tokensIn: whole(r.tokensIn, 1e7) } : {},
|
|
26465
|
+
...r.tokensOut !== void 0 ? { tokensOut: whole(r.tokensOut, 1e7) } : {},
|
|
26466
|
+
...r.costUsd !== void 0 ? { costUsd: money(r.costUsd) } : {},
|
|
26467
|
+
seconds: whole(r.seconds, 1e5)
|
|
26468
|
+
}));
|
|
26469
|
+
}
|
|
26470
|
+
function clampTotals(t) {
|
|
26471
|
+
if (!t || t.calls <= 0) return void 0;
|
|
26472
|
+
return { calls: whole(t.calls, 1e4), tokensIn: whole(t.tokensIn, 1e8), tokensOut: whole(t.tokensOut, 1e8), costUsd: money(t.costUsd) };
|
|
26473
|
+
}
|
|
26474
|
+
|
|
26475
|
+
// src/aiSpend.ts
|
|
26476
|
+
var EMPTY = { calls: 0, tokensIn: 0, tokensOut: 0, costUsd: 0 };
|
|
26477
|
+
var byStep = { targeting: { ...EMPTY }, codegen: { ...EMPTY }, investigate: { ...EMPTY } };
|
|
26478
|
+
function noteSpend(envelope, step) {
|
|
26479
|
+
const used = usageOf(envelope);
|
|
26480
|
+
byStep[step] = addTotals(byStep[step], { calls: 1, tokensIn: used.tokensIn ?? 0, tokensOut: used.tokensOut ?? 0, costUsd: used.costUsd ?? 0 });
|
|
26481
|
+
return envelope;
|
|
26482
|
+
}
|
|
26483
|
+
function spendOf(step) {
|
|
26484
|
+
return { ...byStep[step] };
|
|
26485
|
+
}
|
|
26486
|
+
function spendSoFar() {
|
|
26487
|
+
return addTotals(addTotals(byStep.targeting, byStep.codegen), byStep.investigate);
|
|
26488
|
+
}
|
|
26489
|
+
|
|
26351
26490
|
// src/codegen.ts
|
|
26352
26491
|
var import_node_fs7 = require("node:fs");
|
|
26353
26492
|
var import_node_path9 = require("node:path");
|
|
@@ -26884,7 +27023,7 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
|
|
|
26884
27023
|
if (!res.ok) {
|
|
26885
27024
|
throw new Error(`Codegen call failed for ${target.path}: ${res.status} ${res.statusText}`);
|
|
26886
27025
|
}
|
|
26887
|
-
let envelope = await res.json();
|
|
27026
|
+
let envelope = noteSpend(await res.json(), "codegen");
|
|
26888
27027
|
checkHardFailure(envelope, "pilot.codegen", target.path);
|
|
26889
27028
|
if (envelope?.errorCode === JUDGED_BY_TOO_LARGE_CODE && contextData.judgedBy) {
|
|
26890
27029
|
const before = contextData.judgedBy.length;
|
|
@@ -26899,7 +27038,7 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
|
|
|
26899
27038
|
if (!res.ok) {
|
|
26900
27039
|
throw new Error(`Codegen call failed for ${target.path}: ${res.status} ${res.statusText}`);
|
|
26901
27040
|
}
|
|
26902
|
-
envelope = await res.json();
|
|
27041
|
+
envelope = noteSpend(await res.json(), "codegen");
|
|
26903
27042
|
checkHardFailure(envelope, "pilot.codegen", target.path);
|
|
26904
27043
|
}
|
|
26905
27044
|
if (envelope?.errorCode === CONTEXT_TOO_LARGE_CODE && added.entries.length > 0) {
|
|
@@ -26912,7 +27051,7 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
|
|
|
26912
27051
|
if (!res.ok) {
|
|
26913
27052
|
throw new Error(`Codegen call failed for ${target.path}: ${res.status} ${res.statusText}`);
|
|
26914
27053
|
}
|
|
26915
|
-
envelope = await res.json();
|
|
27054
|
+
envelope = noteSpend(await res.json(), "codegen");
|
|
26916
27055
|
checkHardFailure(envelope, "pilot.codegen", target.path);
|
|
26917
27056
|
}
|
|
26918
27057
|
throwOnTerminalRefusal(envelope, target.path);
|
|
@@ -26964,14 +27103,14 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
|
|
|
26964
27103
|
if (!res.ok) {
|
|
26965
27104
|
throw new Error(`Codegen call failed for ${target.path}: ${res.status} ${res.statusText}`);
|
|
26966
27105
|
}
|
|
26967
|
-
envelope = await res.json();
|
|
27106
|
+
envelope = noteSpend(await res.json(), "codegen");
|
|
26968
27107
|
checkHardFailure(envelope, "pilot.codegen", target.path);
|
|
26969
27108
|
throwOnTerminalRefusal(envelope, target.path);
|
|
26970
|
-
const
|
|
26971
|
-
if (
|
|
26972
|
-
throw codegenRefusedError(target.path,
|
|
27109
|
+
const whole4 = unwrapExecute(envelope, "pilot.codegen");
|
|
27110
|
+
if (whole4.outcome !== "GENERATED" || typeof whole4.newContent !== "string") {
|
|
27111
|
+
throw codegenRefusedError(target.path, whole4);
|
|
26973
27112
|
}
|
|
26974
|
-
newContent =
|
|
27113
|
+
newContent = whole4.newContent;
|
|
26975
27114
|
} catch (error) {
|
|
26976
27115
|
if (error instanceof RuntimeReplyError) {
|
|
26977
27116
|
throw new RuntimeReplyError(
|
|
@@ -35508,8 +35647,8 @@ function readFileText(fs, path) {
|
|
|
35508
35647
|
function clampNotesRecord(n) {
|
|
35509
35648
|
if (typeof n !== "object" || n === null) return void 0;
|
|
35510
35649
|
const { chars, stubbed, guidance } = n;
|
|
35511
|
-
const
|
|
35512
|
-
return { chars:
|
|
35650
|
+
const whole4 = (v, max) => typeof v === "number" && Number.isInteger(v) && v >= 0 ? Math.min(v, max) : 0;
|
|
35651
|
+
return { chars: whole4(chars, NOTES_KEPT_CHARS), stubbed: whole4(stubbed, 1e5), guidance: whole4(guidance, GUIDANCE_PER_RUN) };
|
|
35513
35652
|
}
|
|
35514
35653
|
|
|
35515
35654
|
// ../../../../quikit1926/node_modules/eslint-scope/lib/index.js
|
|
@@ -36924,9 +37063,9 @@ function placementWhy(find, k, added) {
|
|
|
36924
37063
|
if (!DECLARES_TEST.test(added)) return "not_a_test_or_import";
|
|
36925
37064
|
return bracketsBalance(added) ? null : "unbalanced_block";
|
|
36926
37065
|
}
|
|
36927
|
-
function isSubsequence(part,
|
|
37066
|
+
function isSubsequence(part, whole4) {
|
|
36928
37067
|
let i2 = 0;
|
|
36929
|
-
for (let j = 0; j <
|
|
37068
|
+
for (let j = 0; j < whole4.length && i2 < part.length; j++) if (whole4.charCodeAt(j) === part.charCodeAt(i2)) i2++;
|
|
36930
37069
|
return i2 === part.length;
|
|
36931
37070
|
}
|
|
36932
37071
|
function lostTextWhy(find, replace) {
|
|
@@ -39385,40 +39524,12 @@ var TargetingHttpError = class extends Error {
|
|
|
39385
39524
|
}
|
|
39386
39525
|
};
|
|
39387
39526
|
|
|
39388
|
-
// src/tokenEstimate.ts
|
|
39389
|
-
var TOKENS_PER_ALPHA_CHAR = 0.3;
|
|
39390
|
-
var TOKENS_PER_DIGIT_CHAR = 0.18;
|
|
39391
|
-
var TOKENS_PER_SPACE_CHAR = 0.05;
|
|
39392
|
-
var TOKENS_PER_PUNCTUATION_CHAR = 1.05;
|
|
39393
|
-
var TOKENS_PER_NON_ASCII_CHAR = 1;
|
|
39394
|
-
var PROMPT_OVERHEAD_TOKENS = 5e3;
|
|
39395
|
-
function estimateTokens(text) {
|
|
39396
|
-
let alpha = 0;
|
|
39397
|
-
let digit = 0;
|
|
39398
|
-
let space = 0;
|
|
39399
|
-
let punct = 0;
|
|
39400
|
-
let nonAscii = 0;
|
|
39401
|
-
for (const ch of text) {
|
|
39402
|
-
const code = ch.codePointAt(0);
|
|
39403
|
-
if (code >= 128) nonAscii++;
|
|
39404
|
-
else if (code >= 65 && code <= 90 || code >= 97 && code <= 122) alpha++;
|
|
39405
|
-
else if (code >= 48 && code <= 57) digit++;
|
|
39406
|
-
else if (code === 32 || code === 9 || code === 13 || code === 10) space++;
|
|
39407
|
-
else punct++;
|
|
39408
|
-
}
|
|
39409
|
-
return Math.ceil(
|
|
39410
|
-
alpha * TOKENS_PER_ALPHA_CHAR + digit * TOKENS_PER_DIGIT_CHAR + space * TOKENS_PER_SPACE_CHAR + punct * TOKENS_PER_PUNCTUATION_CHAR + nonAscii * TOKENS_PER_NON_ASCII_CHAR
|
|
39411
|
-
);
|
|
39412
|
-
}
|
|
39413
|
-
function estimateRequestTokens(contextData) {
|
|
39414
|
-
return PROMPT_OVERHEAD_TOKENS + estimateTokens(JSON.stringify(contextData ?? {}, null, 2));
|
|
39415
|
-
}
|
|
39416
|
-
|
|
39417
39527
|
// src/turnTimeout.ts
|
|
39418
39528
|
var FIRST_TURN_TIMEOUT_MS = 42e4;
|
|
39419
|
-
|
|
39529
|
+
var INVESTIGATE_FIRST_TURN_TIMEOUT_MS = 15e4;
|
|
39530
|
+
function turnTimeoutFor(turn, perTurnMs, setByCaller, firstTurnMs = FIRST_TURN_TIMEOUT_MS) {
|
|
39420
39531
|
if (setByCaller || turn > 1) return perTurnMs;
|
|
39421
|
-
return Math.max(perTurnMs,
|
|
39532
|
+
return Math.max(perTurnMs, firstTurnMs);
|
|
39422
39533
|
}
|
|
39423
39534
|
|
|
39424
39535
|
// src/targetingLoop.ts
|
|
@@ -39508,6 +39619,7 @@ async function runTargetingLoop(args, deps) {
|
|
|
39508
39619
|
const refusedTurns = [];
|
|
39509
39620
|
let refusedStreak = 0;
|
|
39510
39621
|
let peakRequestTokens = 0;
|
|
39622
|
+
const usage = new TurnUsage();
|
|
39511
39623
|
let turns = 0;
|
|
39512
39624
|
let noProgressStreak = 0;
|
|
39513
39625
|
let forced = null;
|
|
@@ -39543,7 +39655,9 @@ async function runTargetingLoop(args, deps) {
|
|
|
39543
39655
|
...refusedTurns.length > 0 ? { refusedTurns: refusedTurns.map((t) => ({ turn: t.turn, rules: [...t.rules] })) } : {},
|
|
39544
39656
|
...peakRequestTokens > 0 ? { peakRequestTokens } : {},
|
|
39545
39657
|
...args.tools2 ? { contractVersion: args.contractVersion ?? TOOLS2_LOOP_CONTRACT_VERSION } : {},
|
|
39546
|
-
...notesOn ? { notes: { chars: notes.length, stubbed, guidance: env2.guidance?.shown() ?? 0 } } : {}
|
|
39658
|
+
...notesOn ? { notes: { chars: notes.length, stubbed, guidance: env2.guidance?.shown() ?? 0 } } : {},
|
|
39659
|
+
...usage.totals.calls > 0 ? { turnUsage: usage.rows.map((r) => ({ ...r, parts: { ...r.parts } })), usage: { ...usage.totals } } : {},
|
|
39660
|
+
...usage.rowsCut ? { turnUsageCut: true } : {}
|
|
39547
39661
|
});
|
|
39548
39662
|
log({ event: "targeting.loop_start", mode: "loop", maxTurns: limits.maxTurns, maxToolCalls: limits.maxToolCalls, listingFiles: args.listing.length });
|
|
39549
39663
|
try {
|
|
@@ -39567,6 +39681,7 @@ async function runTargetingLoop(args, deps) {
|
|
|
39567
39681
|
} catch (err) {
|
|
39568
39682
|
throw classifyTransport(err);
|
|
39569
39683
|
}
|
|
39684
|
+
usage.record(turn, contextData, requestTokens, envelope, now() - turnStarted);
|
|
39570
39685
|
const code = envelope?.errorCode;
|
|
39571
39686
|
try {
|
|
39572
39687
|
checkHardFailure(envelope, "pilot.targeting");
|
|
@@ -39730,6 +39845,10 @@ var CODEGEN_LOOP_4_CONTRACT_VERSION = "codegen-loop-4";
|
|
|
39730
39845
|
var CODEGEN_LOOP_5_CONTRACT_VERSION = "codegen-loop-5";
|
|
39731
39846
|
var CODEGEN_LOOP_6_CONTRACT_VERSION = "codegen-loop-6";
|
|
39732
39847
|
var MAP_SOFT_REQUEST_TOKENS = 4e4;
|
|
39848
|
+
var MAP_SOFT_HEADROOM_TOKENS = 2e4;
|
|
39849
|
+
function mapSoftTarget(firstRequestTokens, ceiling) {
|
|
39850
|
+
return Math.min(ceiling, Math.max(MAP_SOFT_REQUEST_TOKENS, firstRequestTokens + MAP_SOFT_HEADROOM_TOKENS));
|
|
39851
|
+
}
|
|
39733
39852
|
var CodegenLoopFailure = class extends Error {
|
|
39734
39853
|
reason;
|
|
39735
39854
|
runtimeCode;
|
|
@@ -39798,6 +39917,7 @@ function isTestAnswer(x) {
|
|
|
39798
39917
|
return isPlainObject3(x) && typeof x.passed === "number" && Array.isArray(x.failingTests);
|
|
39799
39918
|
}
|
|
39800
39919
|
var DROPPED_OUTPUT = { dropped: true, note: "Dropped to keep the request small. Read the file again if you need it." };
|
|
39920
|
+
var DROPPED_UNSEEN_OUTPUT = { dropped: true, note: "Too large to send with the rest of this request. Read a smaller part of the file." };
|
|
39801
39921
|
function repoMapGuidancePaths(baseContext) {
|
|
39802
39922
|
const map = baseContext.repoMap;
|
|
39803
39923
|
return (Array.isArray(map?.guidance) ? map.guidance : []).map((g) => g.path).filter((p) => typeof p === "string");
|
|
@@ -39854,6 +39974,8 @@ async function runCodegenLoop(args, deps) {
|
|
|
39854
39974
|
const notesOn = harness && args.tools2?.notes === true;
|
|
39855
39975
|
const contractVersion = harness ? args.tools2 ? notesOn ? CODEGEN_LOOP_6_CONTRACT_VERSION : CODEGEN_LOOP_5_CONTRACT_VERSION : args.readRoots ? CODEGEN_LOOP_4_CONTRACT_VERSION : CODEGEN_LOOP_3_CONTRACT_VERSION : tests ? CODEGEN_LOOP_2_CONTRACT_VERSION : CODEGEN_LOOP_CONTRACT_VERSION;
|
|
39856
39976
|
let peakRequestTokens = 0;
|
|
39977
|
+
let firstRequestTokens = 0;
|
|
39978
|
+
const usage = new TurnUsage();
|
|
39857
39979
|
let notes = "";
|
|
39858
39980
|
let stubbed = 0;
|
|
39859
39981
|
const turnOfId = /* @__PURE__ */ new Map();
|
|
@@ -39961,21 +40083,30 @@ async function runCodegenLoop(args, deps) {
|
|
|
39961
40083
|
...refusedTurns.length > 0 ? { refusedTurns: refusedTurns.map((t) => ({ turn: t.turn, rules: [...t.rules] })) } : {},
|
|
39962
40084
|
reasoning: [...reasoning],
|
|
39963
40085
|
...args.repoView ? { repoView: args.repoView, peakRequestTokens } : {},
|
|
39964
|
-
...notesOn ? { notes: { chars: notes.length, stubbed, guidance: env2.guidance?.shown() ?? 0 } } : {}
|
|
40086
|
+
...notesOn ? { notes: { chars: notes.length, stubbed, guidance: env2.guidance?.shown() ?? 0 } } : {},
|
|
40087
|
+
...usage.totals.calls > 0 ? { turnUsage: usage.rows.map((r) => ({ ...r, parts: { ...r.parts } })), usage: { ...usage.totals } } : {},
|
|
40088
|
+
...usage.rowsCut ? { turnUsageCut: true } : {}
|
|
39965
40089
|
});
|
|
39966
|
-
const
|
|
39967
|
-
const under = (limit) => estimateRequestTokens(buildContext(nextTurn, nextFinal, finalReason)) <= limit;
|
|
39968
|
-
const fits = () => under(limits.maxRequestTokens);
|
|
39969
|
-
const soft = args.readRoots ? Math.min(MAP_SOFT_REQUEST_TOKENS, limits.maxRequestTokens) : limits.maxRequestTokens;
|
|
39970
|
-
if (under(soft)) return true;
|
|
40090
|
+
const dropOutputs = (upTo, done, output) => {
|
|
39971
40091
|
const lastTestRun = toolResults.map((r) => r.name).lastIndexOf(RUN_TESTS_TOOL);
|
|
39972
40092
|
const lastCall = toolResults.map((r) => r.name).lastIndexOf(CALL_FUNCTION_TOOL);
|
|
39973
|
-
|
|
40093
|
+
let dropped = 0;
|
|
40094
|
+
for (let i2 = 0; i2 < upTo && !done(); i2++) {
|
|
39974
40095
|
const r = toolResults[i2];
|
|
39975
|
-
if (
|
|
39976
|
-
|
|
39977
|
-
if (
|
|
40096
|
+
if (r.output === DROPPED_OUTPUT || r.output === DROPPED_UNSEEN_OUTPUT) continue;
|
|
40097
|
+
const stale = READ_TOOLS.has(r.name) && r.status === "ok" || r.name === RUN_TESTS_TOOL && i2 !== lastTestRun && r.output !== void 0 || r.name === CALL_FUNCTION_TOOL && i2 !== lastCall && r.output !== void 0;
|
|
40098
|
+
if (!stale) continue;
|
|
40099
|
+
toolResults[i2] = { ...r, output };
|
|
40100
|
+
dropped++;
|
|
39978
40101
|
}
|
|
40102
|
+
return dropped;
|
|
40103
|
+
};
|
|
40104
|
+
const makeRoom = (nextTurn, nextFinal, finalReason) => {
|
|
40105
|
+
const under = (limit) => estimateRequestTokens(buildContext(nextTurn, nextFinal, finalReason)) <= limit;
|
|
40106
|
+
const fits = () => under(limits.maxRequestTokens);
|
|
40107
|
+
const soft = args.readRoots ? mapSoftTarget(firstRequestTokens, limits.maxRequestTokens) : limits.maxRequestTokens;
|
|
40108
|
+
if (under(soft)) return true;
|
|
40109
|
+
dropOutputs(sent.results, () => under(soft), DROPPED_OUTPUT);
|
|
39979
40110
|
for (const key of [...ledger.seen.keys()]) {
|
|
39980
40111
|
if (key.startsWith("read_file:") || key.startsWith("grep:") || key.startsWith("list_files:") || key.startsWith("show_changes:")) ledger.seen.delete(key);
|
|
39981
40112
|
}
|
|
@@ -39987,6 +40118,9 @@ async function runCodegenLoop(args, deps) {
|
|
|
39987
40118
|
return { ...c, args: { ...path, _omitted: "written earlier; read the file to see it" } };
|
|
39988
40119
|
});
|
|
39989
40120
|
}
|
|
40121
|
+
if (fits()) return true;
|
|
40122
|
+
const unseen = dropOutputs(toolResults.length, fits, DROPPED_UNSEEN_OUTPUT);
|
|
40123
|
+
if (unseen > 0) log({ event: "codegen.read_dropped_unseen", turn: nextTurn - 1, outputs: unseen, ceiling: limits.maxRequestTokens });
|
|
39990
40124
|
return fits();
|
|
39991
40125
|
};
|
|
39992
40126
|
const settleNextTurn = (turn, forcedNow) => {
|
|
@@ -40047,6 +40181,7 @@ async function runCodegenLoop(args, deps) {
|
|
|
40047
40181
|
const contextData = buildContext(turn, isFinal, finalReason);
|
|
40048
40182
|
const requestTokens = estimateRequestTokens(contextData);
|
|
40049
40183
|
peakRequestTokens = Math.max(peakRequestTokens, requestTokens);
|
|
40184
|
+
if (firstRequestTokens === 0) firstRequestTokens = requestTokens;
|
|
40050
40185
|
if (requestTokens > limits.maxRequestTokens) {
|
|
40051
40186
|
log({ event: "codegen.loop_ceiling", turn, action: "not_sent", projectedTokens: requestTokens, ceiling: limits.maxRequestTokens });
|
|
40052
40187
|
throw new CodegenLoopFailure("token_ceiling");
|
|
@@ -40059,6 +40194,7 @@ async function runCodegenLoop(args, deps) {
|
|
|
40059
40194
|
} catch (err) {
|
|
40060
40195
|
throw classifyTransport2(err);
|
|
40061
40196
|
}
|
|
40197
|
+
usage.record(turn, contextData, requestTokens, envelope, now() - turnStarted);
|
|
40062
40198
|
const code = envelope?.errorCode;
|
|
40063
40199
|
try {
|
|
40064
40200
|
checkHardFailure(envelope, "pilot.codegen");
|
|
@@ -40496,8 +40632,11 @@ function mergePhaseSummaries(parts, phases) {
|
|
|
40496
40632
|
for (const [k, v] of Object.entries(summary.statusCounts)) statusCounts[k] = (statusCounts[k] ?? 0) + v;
|
|
40497
40633
|
}
|
|
40498
40634
|
let n = 0;
|
|
40499
|
-
const testRuns = parts.flatMap(({ phase, summary }) => (summary.testRuns ?? []).map((
|
|
40635
|
+
const testRuns = parts.flatMap(({ phase, summary }) => (summary.testRuns ?? []).map((t2) => ({ ...t2, n: ++n, phase })));
|
|
40500
40636
|
const refusedTurns = parts.flatMap(({ summary }) => summary.refusedTurns ?? []);
|
|
40637
|
+
let t = 0;
|
|
40638
|
+
const turnUsage = parts.flatMap(({ summary }) => (summary.turnUsage ?? []).map((r) => ({ ...r, turn: ++t })));
|
|
40639
|
+
const turnUsageCut = parts.some(({ summary }) => summary.turnUsageCut) || turnUsage.length > MAX_TURN_ROWS;
|
|
40501
40640
|
return {
|
|
40502
40641
|
...last,
|
|
40503
40642
|
turns: parts.reduce((s, p) => s + p.summary.turns, 0),
|
|
@@ -40511,7 +40650,9 @@ function mergePhaseSummaries(parts, phases) {
|
|
|
40511
40650
|
...testRuns.length > 0 ? { testRuns } : {},
|
|
40512
40651
|
...refusedTurns.length > 0 ? { refusedTurns } : {},
|
|
40513
40652
|
reasoning: parts.flatMap((p) => p.summary.reasoning),
|
|
40514
|
-
phases
|
|
40653
|
+
phases,
|
|
40654
|
+
...turnUsage.length > 0 ? { turnUsage: turnUsage.slice(0, MAX_TURN_ROWS) } : {},
|
|
40655
|
+
...turnUsageCut ? { turnUsageCut: true } : {}
|
|
40515
40656
|
};
|
|
40516
40657
|
}
|
|
40517
40658
|
|
|
@@ -40519,19 +40660,23 @@ function mergePhaseSummaries(parts, phases) {
|
|
|
40519
40660
|
var MAX_ROOTS = 8;
|
|
40520
40661
|
var MAX_ROOT_CHARS = 300;
|
|
40521
40662
|
var MAX_REASON_CHARS2 = 40;
|
|
40522
|
-
var
|
|
40663
|
+
var whole2 = (n) => typeof n === "number" && Number.isFinite(n) && n >= 0 ? Math.floor(n) : 0;
|
|
40523
40664
|
function repoViewOf(scope) {
|
|
40524
|
-
if (!scope
|
|
40525
|
-
|
|
40665
|
+
if (!scope) return void 0;
|
|
40666
|
+
if (scope.view !== "map") {
|
|
40667
|
+
return { view: "listing", writeRoot: scope.writeRoot, fileCount: scope.writeListing.length, readRoots: [scope.writeRoot] };
|
|
40668
|
+
}
|
|
40669
|
+
return { view: "map", writeRoot: scope.writeRoot, fileCount: scope.readListing.length, readRoots: [...scope.readRoots], mapTokens: scope.mapTokens ?? 0 };
|
|
40526
40670
|
}
|
|
40527
40671
|
function clampRepoView(facts, peakRequestTokens) {
|
|
40528
40672
|
if (!facts) return {};
|
|
40529
40673
|
return {
|
|
40530
|
-
view: "map",
|
|
40531
|
-
|
|
40674
|
+
view: facts.view === "map" ? "map" : "listing",
|
|
40675
|
+
...facts.writeRoot.length <= MAX_ROOT_CHARS ? { writeRoot: facts.writeRoot } : {},
|
|
40676
|
+
fileCount: whole2(facts.fileCount),
|
|
40532
40677
|
readRoots: facts.readRoots.filter((r) => r.length <= MAX_ROOT_CHARS).slice(0, MAX_ROOTS),
|
|
40533
|
-
mapTokens:
|
|
40534
|
-
...peakRequestTokens && peakRequestTokens > 0 ? { peakRequestTokens:
|
|
40678
|
+
...facts.view === "map" ? { mapTokens: whole2(facts.mapTokens) } : {},
|
|
40679
|
+
...peakRequestTokens && peakRequestTokens > 0 ? { peakRequestTokens: whole2(peakRequestTokens) } : {},
|
|
40535
40680
|
...facts.failReason ? { failReason: facts.failReason.slice(0, MAX_REASON_CHARS2) } : {}
|
|
40536
40681
|
};
|
|
40537
40682
|
}
|
|
@@ -40567,11 +40712,11 @@ function gateOf(g) {
|
|
|
40567
40712
|
alreadyFailing: gateCount(x.alreadyFailing)
|
|
40568
40713
|
};
|
|
40569
40714
|
}
|
|
40570
|
-
function
|
|
40715
|
+
function whole3(n) {
|
|
40571
40716
|
return typeof n === "number" && Number.isInteger(n) && n >= 0 ? n : 0;
|
|
40572
40717
|
}
|
|
40573
40718
|
function small(n) {
|
|
40574
|
-
return Math.min(MAX_ATTEMPT_COUNT,
|
|
40719
|
+
return Math.min(MAX_ATTEMPT_COUNT, whole3(n));
|
|
40575
40720
|
}
|
|
40576
40721
|
function pathOk(p) {
|
|
40577
40722
|
return typeof p === "string" && p.length > 0 && p.length <= MAX_RECORD_PATH_CHARS;
|
|
@@ -40597,14 +40742,14 @@ function buildCodegenLoopRecord(loop) {
|
|
|
40597
40742
|
path: r.path.trim(),
|
|
40598
40743
|
...Number.isInteger(r.startLine) ? { startLine: r.startLine } : {},
|
|
40599
40744
|
...Number.isInteger(r.endLine) ? { endLine: r.endLine } : {},
|
|
40600
|
-
chars:
|
|
40745
|
+
chars: whole3(r.chars),
|
|
40601
40746
|
...r.refused ? { refused: true } : {}
|
|
40602
40747
|
}));
|
|
40603
|
-
const edits = room(loop.edits).map((e) => ({ path: e.path, count:
|
|
40604
|
-
const created = room(loop.created).map((c) => ({ path: c.path, chars:
|
|
40748
|
+
const edits = room(loop.edits).map((e) => ({ path: e.path, count: whole3(e.count) }));
|
|
40749
|
+
const created = room(loop.created).map((c) => ({ path: c.path, chars: whole3(c.chars) }));
|
|
40605
40750
|
const statusCounts = {};
|
|
40606
40751
|
for (const [k, v] of Object.entries(loop.statusCounts).slice(0, MAX_STATUS_KEYS)) {
|
|
40607
|
-
if (k.length > 0 && k.length <= MAX_STATUS_KEY_CHARS) statusCounts[k] =
|
|
40752
|
+
if (k.length > 0 && k.length <= MAX_STATUS_KEY_CHARS) statusCounts[k] = whole3(v);
|
|
40608
40753
|
else cut = true;
|
|
40609
40754
|
}
|
|
40610
40755
|
if (Object.keys(loop.statusCounts).length > MAX_STATUS_KEYS) cut = true;
|
|
@@ -40617,7 +40762,7 @@ function buildCodegenLoopRecord(loop) {
|
|
|
40617
40762
|
const text = typeof r.text === "string" ? r.text.trim() : "";
|
|
40618
40763
|
if (text.length === 0) continue;
|
|
40619
40764
|
const over = text.length > MAX_RECORD_REASONING_CHARS;
|
|
40620
|
-
reasoning.push({ turn:
|
|
40765
|
+
reasoning.push({ turn: whole3(r.turn), text: over ? text.slice(0, MAX_RECORD_REASONING_CHARS) : text, ...over ? { truncated: true } : {} });
|
|
40621
40766
|
}
|
|
40622
40767
|
const testRuns = [];
|
|
40623
40768
|
for (const t of loop.testRuns ?? []) {
|
|
@@ -40626,16 +40771,16 @@ function buildCodegenLoopRecord(loop) {
|
|
|
40626
40771
|
break;
|
|
40627
40772
|
}
|
|
40628
40773
|
testRuns.push({
|
|
40629
|
-
n:
|
|
40774
|
+
n: whole3(t.n),
|
|
40630
40775
|
status: String(t.status).slice(0, MAX_STATUS_KEY_CHARS),
|
|
40631
40776
|
...t.reason ? { reason: String(t.reason).slice(0, MAX_STATUS_KEY_CHARS) } : {},
|
|
40632
|
-
passed:
|
|
40633
|
-
failed:
|
|
40634
|
-
regressions:
|
|
40635
|
-
newFailures:
|
|
40636
|
-
alreadyFailing:
|
|
40777
|
+
passed: whole3(t.passed),
|
|
40778
|
+
failed: whole3(t.failed),
|
|
40779
|
+
regressions: whole3(t.regressions),
|
|
40780
|
+
newFailures: whole3(t.newFailures),
|
|
40781
|
+
alreadyFailing: whole3(t.alreadyFailing),
|
|
40637
40782
|
timedOut: t.timedOut === true,
|
|
40638
|
-
seconds:
|
|
40783
|
+
seconds: whole3(t.seconds),
|
|
40639
40784
|
...t.scope === "file" ? { scope: "file" } : {},
|
|
40640
40785
|
...t.phase && PHASES.has(t.phase) ? { phase: t.phase } : {}
|
|
40641
40786
|
});
|
|
@@ -40652,7 +40797,7 @@ function buildCodegenLoopRecord(loop) {
|
|
|
40652
40797
|
outcome: ph.outcome.slice(0, MAX_STATUS_KEY_CHARS),
|
|
40653
40798
|
turns: small(ph.turns),
|
|
40654
40799
|
toolCalls: small(ph.toolCalls),
|
|
40655
|
-
...
|
|
40800
|
+
...whole3(ph.redUnproven) > 0 ? { redUnproven: small(ph.redUnproven) } : {}
|
|
40656
40801
|
});
|
|
40657
40802
|
}
|
|
40658
40803
|
const refused2 = clampRefusedTurns(loop.refusedTurns);
|
|
@@ -40683,15 +40828,15 @@ function buildCodegenLoopRecord(loop) {
|
|
|
40683
40828
|
const healIn = loop.heal;
|
|
40684
40829
|
const healed = healIn && typeof healIn.stop === "string" && HEAL_STOPS.has(healIn.stop) ? {
|
|
40685
40830
|
stop: healIn.stop,
|
|
40686
|
-
allowed: Math.min(3,
|
|
40687
|
-
made: Math.min(3,
|
|
40831
|
+
allowed: Math.min(3, whole3(healIn.allowed)),
|
|
40832
|
+
made: Math.min(3, whole3(healIn.made)),
|
|
40688
40833
|
...gateOf(healIn.startedFrom) ? { startedFrom: gateOf(healIn.startedFrom) } : {},
|
|
40689
40834
|
...typeof healIn.failureReason === "string" && healIn.failureReason.length > 0 ? { failureReason: healIn.failureReason.slice(0, MAX_STATUS_KEY_CHARS) } : {}
|
|
40690
40835
|
} : void 0;
|
|
40691
40836
|
return {
|
|
40692
|
-
turns:
|
|
40693
|
-
toolCalls:
|
|
40694
|
-
refused:
|
|
40837
|
+
turns: whole3(loop.turns),
|
|
40838
|
+
toolCalls: whole3(loop.toolCalls),
|
|
40839
|
+
refused: whole3(loop.refused),
|
|
40695
40840
|
stopReason: loop.stopReason,
|
|
40696
40841
|
...loop.fellBack ? { fellBack: true } : {},
|
|
40697
40842
|
...loop.fallbackReason ? { fallbackReason: String(loop.fallbackReason).slice(0, MAX_RECORD_FALLBACK_REASON_CHARS) } : {},
|
|
@@ -40699,10 +40844,13 @@ function buildCodegenLoopRecord(loop) {
|
|
|
40699
40844
|
edits,
|
|
40700
40845
|
created,
|
|
40701
40846
|
statusCounts,
|
|
40702
|
-
...
|
|
40847
|
+
...whole3(loop.syntaxWarnings) > 0 ? { syntaxWarnings: whole3(loop.syntaxWarnings) } : {},
|
|
40703
40848
|
...typeof loop.contractVersion === "string" && loop.contractVersion.length > 0 ? { contractVersion: loop.contractVersion.slice(0, 40) } : {},
|
|
40704
40849
|
...clampNotesRecord(loop.notes) ? { notes: clampNotesRecord(loop.notes) } : {},
|
|
40705
40850
|
...clampRepoView(loop.repoView, loop.peakRequestTokens),
|
|
40851
|
+
...clampTurnRows(loop.turnUsage) ? { turnUsage: clampTurnRows(loop.turnUsage) } : {},
|
|
40852
|
+
...loop.turnUsageCut ? { turnUsageCut: true } : {},
|
|
40853
|
+
...clampTotals(loop.usage) ? { usage: clampTotals(loop.usage) } : {},
|
|
40706
40854
|
...testRuns.length > 0 ? { testRuns } : {},
|
|
40707
40855
|
...refused2.rows.length > 0 ? { refusedTurns: refused2.rows } : {},
|
|
40708
40856
|
...attempts.length > 0 ? { attempts } : {},
|
|
@@ -40933,7 +41081,7 @@ async function postCodegenTurn(gateway, contextData, signal) {
|
|
|
40933
41081
|
...signal ? { signal } : {}
|
|
40934
41082
|
});
|
|
40935
41083
|
if (!res.ok) throw new TargetingHttpError(res.status, res.statusText);
|
|
40936
|
-
return res.json();
|
|
41084
|
+
return noteSpend(await res.json(), "codegen");
|
|
40937
41085
|
}
|
|
40938
41086
|
function protectedTestFiles(listing, testDiscovery) {
|
|
40939
41087
|
const inListing2 = new Set(listing);
|
|
@@ -41011,7 +41159,9 @@ function buildCodegenLoopArgs(p, context = collectLoopContext({
|
|
|
41011
41159
|
targets: p.targets,
|
|
41012
41160
|
requiredAutomationIds: requiredTests.map((tc) => tc.automationId),
|
|
41013
41161
|
listing: p.workspaceListing,
|
|
41014
|
-
...map ? { readRoots: map.readRoots, readListing: map.readListing
|
|
41162
|
+
...map ? { readRoots: map.readRoots, readListing: map.readListing } : {},
|
|
41163
|
+
// QUIKTR-1582: how the run saw the repository, in both views (the record says which folder it could change).
|
|
41164
|
+
...p.scope ? { repoView: repoViewOf(p.scope) } : {},
|
|
41015
41165
|
deniedPaths: p.deniedPaths,
|
|
41016
41166
|
protectedTestPaths,
|
|
41017
41167
|
...discoveredTests ? { discoveredTests } : {},
|
|
@@ -43046,7 +43196,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
|
|
|
43046
43196
|
var REPORT_COPY = "final-test-report.xml";
|
|
43047
43197
|
var MAX_REPORT_BYTES = 5 * 1024 * 1024;
|
|
43048
43198
|
var MAX_FILES = 200;
|
|
43049
|
-
var RUNNER_VERSION = true ? "9.3.0-rc.
|
|
43199
|
+
var RUNNER_VERSION = true ? "9.3.0-rc.37" : "dev";
|
|
43050
43200
|
function safeDestination(base, repoPath) {
|
|
43051
43201
|
if (!repoPath || (0, import_node_path21.isAbsolute)(repoPath)) return null;
|
|
43052
43202
|
const destination = (0, import_node_path21.resolve)(base, repoPath);
|
|
@@ -43303,7 +43453,7 @@ async function postTargeting(gateway, contextData, signal) {
|
|
|
43303
43453
|
if (!res.ok) {
|
|
43304
43454
|
throw new TargetingHttpError(res.status, res.statusText);
|
|
43305
43455
|
}
|
|
43306
|
-
return res.json();
|
|
43456
|
+
return noteSpend(await res.json(), "targeting");
|
|
43307
43457
|
}
|
|
43308
43458
|
function finalizeTargeting(body, workspaceRoot, workspaceListing, deniedPaths) {
|
|
43309
43459
|
if (body.outcome === "NO_TARGET") {
|
|
@@ -43386,6 +43536,7 @@ async function runTargeting(gateway, design, workspaceRoot, workspaceListing, re
|
|
|
43386
43536
|
return runSingleShot(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings);
|
|
43387
43537
|
}
|
|
43388
43538
|
const baseContext = buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings);
|
|
43539
|
+
const listingView = repoViewOf(options.scope);
|
|
43389
43540
|
let summary;
|
|
43390
43541
|
let runtimeCode;
|
|
43391
43542
|
let reason;
|
|
@@ -43397,7 +43548,7 @@ async function runTargeting(gateway, design, workspaceRoot, workspaceListing, re
|
|
|
43397
43548
|
);
|
|
43398
43549
|
summary = looped.summary;
|
|
43399
43550
|
const result = finalizeTargeting(looped.body, workspaceRoot, workspaceListing, deniedPaths);
|
|
43400
|
-
return { ...result, loop: summary };
|
|
43551
|
+
return { ...result, loop: { ...summary, ...listingView ? { repoView: listingView } : {} } };
|
|
43401
43552
|
} catch (err) {
|
|
43402
43553
|
if (err instanceof DeniedPathError || err instanceof SafetyRefusalError) throw err;
|
|
43403
43554
|
if (err instanceof LoopFailure) {
|
|
@@ -43416,7 +43567,12 @@ async function runTargeting(gateway, design, workspaceRoot, workspaceListing, re
|
|
|
43416
43567
|
reads: summary?.reads ?? [],
|
|
43417
43568
|
stopReason: "fallback",
|
|
43418
43569
|
fellBack: true,
|
|
43419
|
-
fallbackReason: reason
|
|
43570
|
+
fallbackReason: reason,
|
|
43571
|
+
// QUIKTR-1582: what the loop cost and saw before it gave up is kept, so the card still shows it.
|
|
43572
|
+
...summary?.peakRequestTokens ? { peakRequestTokens: summary.peakRequestTokens } : {},
|
|
43573
|
+
...summary?.turnUsage ? { turnUsage: summary.turnUsage } : {},
|
|
43574
|
+
...summary?.turnUsageCut ? { turnUsageCut: true } : {},
|
|
43575
|
+
...listingView ? { repoView: listingView } : {}
|
|
43420
43576
|
};
|
|
43421
43577
|
const log = options.loopDeps?.log ?? ((e) => console.log(JSON.stringify(e)));
|
|
43422
43578
|
log({
|
|
@@ -43536,6 +43692,9 @@ function clampLoop(loop) {
|
|
|
43536
43692
|
...typeof loop.contractVersion === "string" && loop.contractVersion.length > 0 ? { contractVersion: loop.contractVersion.slice(0, 40) } : {},
|
|
43537
43693
|
...clampNotesRecord(loop.notes) ? { notes: clampNotesRecord(loop.notes) } : {},
|
|
43538
43694
|
...clampRepoView(loop.repoView, loop.peakRequestTokens),
|
|
43695
|
+
...clampTurnRows(loop.turnUsage) ? { turnUsage: clampTurnRows(loop.turnUsage) } : {},
|
|
43696
|
+
...loop.turnUsageCut ? { turnUsageCut: true } : {},
|
|
43697
|
+
...clampTotals(loop.usage) ? { usage: clampTotals(loop.usage) } : {},
|
|
43539
43698
|
reads,
|
|
43540
43699
|
...refusedTurns.rows.length > 0 ? { refusedTurns: refusedTurns.rows } : {},
|
|
43541
43700
|
...cut ? { truncated: true } : {}
|
|
@@ -43742,7 +43901,11 @@ async function run(env2) {
|
|
|
43742
43901
|
packet.guardrails.deniedPaths,
|
|
43743
43902
|
discovery.result.value,
|
|
43744
43903
|
outOfScope,
|
|
43745
|
-
|
|
43904
|
+
// QUIKTR-1561 - the early look's findings, filtered to this checkout inside runTargeting. Passed ONLY when there are some, so a run
|
|
43905
|
+
// without a completed look calls it exactly as before.
|
|
43906
|
+
// QUIKTR-1580 - and the scope: in map mode it is how targeting sees the repository; since QUIKTR-1582 it is also handed over in listing
|
|
43907
|
+
// mode, only so the record can say which folder the run could change (listing-mode targeting reads nothing else from it).
|
|
43908
|
+
{ ...packet.findings ? { findings: packet.findings } : {}, scope, ...tools2 ? { tools2 } : {} }
|
|
43746
43909
|
);
|
|
43747
43910
|
targetingResult = targeting;
|
|
43748
43911
|
for (const w of targeting.warnings ?? []) {
|
|
@@ -43832,7 +43995,8 @@ async function run(env2) {
|
|
|
43832
43995
|
gateway: packet.gateway,
|
|
43833
43996
|
targets: targeting.targets,
|
|
43834
43997
|
workspaceListing,
|
|
43835
|
-
|
|
43998
|
+
// In both views (QUIKTR-1582): map mode reads the repository through it; listing mode only records the folder it could change.
|
|
43999
|
+
scope,
|
|
43836
44000
|
...tools2 ? { tools2 } : {},
|
|
43837
44001
|
...writeRoot ? { writeRoot } : {},
|
|
43838
44002
|
requiredTests: packet.requiredTests,
|
|
@@ -44029,6 +44193,11 @@ async function run(env2) {
|
|
|
44029
44193
|
console.warn(`::warning::Could not keep the failed run's files: ${err instanceof Error ? err.message : String(err)}`);
|
|
44030
44194
|
}
|
|
44031
44195
|
}
|
|
44196
|
+
const targetingRecord = targetingResult ? buildTargetingRecord(targetingResult, contextLog) : void 0;
|
|
44197
|
+
const targetingUsage = clampTotals(spendOf("targeting"));
|
|
44198
|
+
if (targetingRecord?.loop && targetingUsage) targetingRecord.loop = { ...targetingRecord.loop, usage: targetingUsage };
|
|
44199
|
+
const codegenUsage = clampTotals(spendOf("codegen"));
|
|
44200
|
+
const codegenRecord = codegenOut.loop && codegenUsage ? { ...codegenOut.loop, usage: codegenUsage } : codegenOut.loop;
|
|
44032
44201
|
await reportBack({
|
|
44033
44202
|
callbackUrl: env2.callbackUrl,
|
|
44034
44203
|
runToken,
|
|
@@ -44036,14 +44205,15 @@ async function run(env2) {
|
|
|
44036
44205
|
branch,
|
|
44037
44206
|
warnings,
|
|
44038
44207
|
// Omitted when targeting itself never produced a result (nothing exists to record).
|
|
44039
|
-
targeting:
|
|
44208
|
+
targeting: targetingRecord,
|
|
44040
44209
|
baselineFindings,
|
|
44041
44210
|
vanishedTests,
|
|
44042
44211
|
unsuppliedInputs,
|
|
44043
44212
|
changesNoTestDependsOn,
|
|
44044
44213
|
testsCorrected,
|
|
44045
|
-
codegenLoop:
|
|
44046
|
-
unresolved: failureReasons.length > 0 ? failureReasons : void 0
|
|
44214
|
+
codegenLoop: codegenRecord,
|
|
44215
|
+
unresolved: failureReasons.length > 0 ? failureReasons : void 0,
|
|
44216
|
+
aiCostUsd: spendSoFar().costUsd
|
|
44047
44217
|
});
|
|
44048
44218
|
return { hardFailure };
|
|
44049
44219
|
}
|
|
@@ -44344,7 +44514,7 @@ async function runInvestigateLoop(args, deps) {
|
|
|
44344
44514
|
const now = deps.now ?? Date.now;
|
|
44345
44515
|
const log = deps.log ?? ((e) => console.log(JSON.stringify(e)));
|
|
44346
44516
|
const turnTimeoutMs = deps.turnTimeoutMs ?? 6e4;
|
|
44347
|
-
const deadlineMs = deps.deadlineMs ??
|
|
44517
|
+
const deadlineMs = deps.deadlineMs ?? 21e4;
|
|
44348
44518
|
const secrets = deps.secrets ?? [];
|
|
44349
44519
|
const env2 = {
|
|
44350
44520
|
listing: new Set(args.listing),
|
|
@@ -44407,7 +44577,10 @@ async function runInvestigateLoop(args, deps) {
|
|
|
44407
44577
|
const turnStarted = now();
|
|
44408
44578
|
let envelope;
|
|
44409
44579
|
try {
|
|
44410
|
-
envelope = await deps.post(
|
|
44580
|
+
envelope = await deps.post(
|
|
44581
|
+
contextData,
|
|
44582
|
+
AbortSignal.timeout(turnTimeoutFor(turn, turnTimeoutMs, deps.turnTimeoutMs !== void 0, INVESTIGATE_FIRST_TURN_TIMEOUT_MS))
|
|
44583
|
+
);
|
|
44411
44584
|
} catch (err) {
|
|
44412
44585
|
throw classifyTransport3(err);
|
|
44413
44586
|
}
|
|
@@ -44540,7 +44713,7 @@ async function postInvestigate(gateway, contextData, signal) {
|
|
|
44540
44713
|
signal
|
|
44541
44714
|
});
|
|
44542
44715
|
if (!res.ok) throw new TargetingHttpError(res.status, res.statusText);
|
|
44543
|
-
return res.json();
|
|
44716
|
+
return noteSpend(await res.json(), "investigate");
|
|
44544
44717
|
}
|
|
44545
44718
|
async function reportInvestigation(callbackUrl, runToken, body) {
|
|
44546
44719
|
const res = await fetch(callbackUrl, {
|