@nathapp/nax 0.92.9 → 0.92.10
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/dist/nax.js +936 -272
- package/package.json +2 -2
package/dist/nax.js
CHANGED
|
@@ -56758,7 +56758,7 @@ var package_default;
|
|
|
56758
56758
|
var init_package = __esm(() => {
|
|
56759
56759
|
package_default = {
|
|
56760
56760
|
name: "@nathapp/nax",
|
|
56761
|
-
version: "0.92.
|
|
56761
|
+
version: "0.92.10",
|
|
56762
56762
|
description: "AI Coding Agent Orchestrator \u2014 loops until done",
|
|
56763
56763
|
type: "module",
|
|
56764
56764
|
bin: {
|
|
@@ -56844,7 +56844,7 @@ var init_package = __esm(() => {
|
|
|
56844
56844
|
"@agentclientprotocol/sdk": "~1.7.0",
|
|
56845
56845
|
"@anthropic-ai/sandbox-runtime": "0.0.77",
|
|
56846
56846
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
56847
|
-
"@nathapp/nax-ai": "0.92.
|
|
56847
|
+
"@nathapp/nax-ai": "0.92.10",
|
|
56848
56848
|
chalk: "^5.6.2",
|
|
56849
56849
|
commander: "^13.1.0",
|
|
56850
56850
|
"highlight.js": "^11.12.0",
|
|
@@ -87125,8 +87125,8 @@ var init_version = __esm(() => {
|
|
|
87125
87125
|
NAX_AI_VERSION = CATALOG_VERSION;
|
|
87126
87126
|
NAX_COMMIT = (() => {
|
|
87127
87127
|
try {
|
|
87128
|
-
if (/^[0-9a-f]{6,10}$/.test("
|
|
87129
|
-
return "
|
|
87128
|
+
if (/^[0-9a-f]{6,10}$/.test("997157d"))
|
|
87129
|
+
return "997157d";
|
|
87130
87130
|
} catch {}
|
|
87131
87131
|
try {
|
|
87132
87132
|
const result = Bun.spawnSync(["git", "rev-parse", "--short", "HEAD"], {
|
|
@@ -107648,7 +107648,7 @@ var init_issues = __esm(() => {
|
|
|
107648
107648
|
|
|
107649
107649
|
// src/forge/marker-grammar.ts
|
|
107650
107650
|
function isTopLevelMarkerKey(key) {
|
|
107651
|
-
return TOP_LEVEL_MARKER_KEYS.some((known) => known === key) || PUSH_RECORD_KEY.test(key);
|
|
107651
|
+
return TOP_LEVEL_MARKER_KEYS.some((known) => known === key) || PUSH_RECORD_KEY.test(key) || CARRIED_RECORD_KEY.test(key);
|
|
107652
107652
|
}
|
|
107653
107653
|
function isNaxBotMarkerKey(key) {
|
|
107654
107654
|
return MARKER_KEY.exec(key)?.[0] === key;
|
|
@@ -107663,7 +107663,7 @@ function parseNaxBotMarker(body) {
|
|
|
107663
107663
|
}
|
|
107664
107664
|
return result;
|
|
107665
107665
|
}
|
|
107666
|
-
var TOP_LEVEL_MARKER_KEYS, PUSH_RECORD_KEY, MARKER_KEY_PATTERN = "[A-Za-z0-9._:-]{1,128}", markerPattern = () => new RegExp(`<!-- nax-bot:v1 key=(${MARKER_KEY_PATTERN}) -->`, "g"), MARKER_KEY;
|
|
107666
|
+
var TOP_LEVEL_MARKER_KEYS, PUSH_RECORD_KEY, CARRIED_RECORD_KEY, MARKER_KEY_PATTERN = "[A-Za-z0-9._:-]{1,128}", markerPattern = () => new RegExp(`<!-- nax-bot:v1 key=(${MARKER_KEY_PATTERN}) -->`, "g"), MARKER_KEY;
|
|
107667
107667
|
var init_marker_grammar = __esm(() => {
|
|
107668
107668
|
TOP_LEVEL_MARKER_KEYS = [
|
|
107669
107669
|
"summary",
|
|
@@ -107674,6 +107674,7 @@ var init_marker_grammar = __esm(() => {
|
|
|
107674
107674
|
"w-ci-waiver"
|
|
107675
107675
|
];
|
|
107676
107676
|
PUSH_RECORD_KEY = /^push-[0-9a-f]{40}$/;
|
|
107677
|
+
CARRIED_RECORD_KEY = /^w-carry(?:-incomplete)?:[0-9a-f]{40}$/;
|
|
107677
107678
|
MARKER_KEY = new RegExp(`^${MARKER_KEY_PATTERN}$`);
|
|
107678
107679
|
});
|
|
107679
107680
|
|
|
@@ -117956,10 +117957,17 @@ function renderItemIndex(index, settled = 0) {
|
|
|
117956
117957
|
].join(`
|
|
117957
117958
|
`);
|
|
117958
117959
|
}
|
|
117960
|
+
function parseItemIndexSettled(body) {
|
|
117961
|
+
if (parseItemIndex(body) === null)
|
|
117962
|
+
return null;
|
|
117963
|
+
const [countLine] = bodyLines(body);
|
|
117964
|
+
const modern = MODERN_COUNT_LINE.exec(countLine ?? "");
|
|
117965
|
+
return modern ? Number(modern[2]) : 0;
|
|
117966
|
+
}
|
|
117959
117967
|
function parseItemIndex(body) {
|
|
117960
117968
|
const [countLine, headLine, ...rest] = bodyLines(body);
|
|
117961
|
-
const modern =
|
|
117962
|
-
const count = modern?.[1] ??
|
|
117969
|
+
const modern = MODERN_COUNT_LINE.exec(countLine ?? "");
|
|
117970
|
+
const count = modern?.[1] ?? LEGACY_COUNT_LINE.exec(countLine ?? "")?.[1];
|
|
117963
117971
|
if (count === undefined || Number(modern?.[2] ?? 0) > Number(count))
|
|
117964
117972
|
return null;
|
|
117965
117973
|
if (!headLine?.startsWith("Reviewed head: "))
|
|
@@ -117983,7 +117991,7 @@ function parseItemIndex(body) {
|
|
|
117983
117991
|
...base ? { reviewedBase: base } : {}
|
|
117984
117992
|
};
|
|
117985
117993
|
}
|
|
117986
|
-
var HASH_CHARS2 = 8, SHORT_SHA_CHARS = 7, MAX_REPLY_ID_CHARS = 20, ITEM_KEY_PATTERN, SHA_PATTERN, REPLY_INSTRUCTION = "Rule on it by replying: fixed <sha>, waive: <reason>, confirm, override: <reason>, or verified. Any other reply from a collaborator is read as a ruling only when its meaning is clear.", CHANGE_INSTRUCTION = "To change it, reply on this thread.", FILES_HEADING = "Files:", FILES_LINE, DISPOSITION_NAMES2, KIND_NAMES2, REOPENED_BY_RERAISE, CALLER_SUFFIX;
|
|
117994
|
+
var HASH_CHARS2 = 8, SHORT_SHA_CHARS = 7, MAX_REPLY_ID_CHARS = 20, ITEM_KEY_PATTERN, SHA_PATTERN, MODERN_COUNT_LINE, LEGACY_COUNT_LINE, REPLY_INSTRUCTION = "Rule on it by replying: fixed <sha>, waive: <reason>, confirm, override: <reason>, or verified. Any other reply from a collaborator is read as a ruling only when its meaning is clear.", CHANGE_INSTRUCTION = "To change it, reply on this thread.", FILES_HEADING = "Files:", FILES_LINE, DISPOSITION_NAMES2, KIND_NAMES2, REOPENED_BY_RERAISE, CALLER_SUFFIX;
|
|
117987
117995
|
var init_item_threads = __esm(() => {
|
|
117988
117996
|
init_errors4();
|
|
117989
117997
|
init_forge();
|
|
@@ -117991,6 +117999,8 @@ var init_item_threads = __esm(() => {
|
|
|
117991
117999
|
init_pr_body_safe();
|
|
117992
118000
|
ITEM_KEY_PATTERN = /^w-([A-Za-z0-9._:-]+)\.[a-f0-9]{8}$/;
|
|
117993
118001
|
SHA_PATTERN = /^[a-fA-F0-9]{40}$/;
|
|
118002
|
+
MODERN_COUNT_LINE = /^nax workflow items: (\d+) \((\d+) settled\)$/;
|
|
118003
|
+
LEGACY_COUNT_LINE = /^nax workflow open items: (\d+)$/;
|
|
117994
118004
|
FILES_LINE = /^ - `(.*)`$/;
|
|
117995
118005
|
DISPOSITION_NAMES2 = {
|
|
117996
118006
|
fixed: true,
|
|
@@ -118630,6 +118640,10 @@ function policyLines(input) {
|
|
|
118630
118640
|
function summarySections(input) {
|
|
118631
118641
|
return [
|
|
118632
118642
|
{ heading: "### Sensitive paths changed", items: input.sensitive.map((path) => `- \`${safeCode(path)}\``) },
|
|
118643
|
+
{
|
|
118644
|
+
heading: "### Still open from an earlier review",
|
|
118645
|
+
items: (input.carried ?? []).map(residualItem)
|
|
118646
|
+
},
|
|
118633
118647
|
{ heading: "### Findings not on a changed line", items: input.offLine.map(offLineItem) },
|
|
118634
118648
|
{ heading: "### Residual findings (not blocking)", items: (input.residual ?? []).map(residualItem) },
|
|
118635
118649
|
{ heading: "### Minor findings", items: (input.minor ?? []).map(offLineItem) },
|
|
@@ -119413,6 +119427,135 @@ var init_blocking_threads = __esm(() => {
|
|
|
119413
119427
|
};
|
|
119414
119428
|
});
|
|
119415
119429
|
|
|
119430
|
+
// src/bot/carried-record.ts
|
|
119431
|
+
function carriedRecordKey(headSha) {
|
|
119432
|
+
return `${CARRIED_RECORD_PREFIX}${headSha}`;
|
|
119433
|
+
}
|
|
119434
|
+
function carryWidenKey(headSha) {
|
|
119435
|
+
return `${CARRY_WIDEN_PREFIX}${headSha}`;
|
|
119436
|
+
}
|
|
119437
|
+
function carryWidenComment(own, headSha) {
|
|
119438
|
+
return own.find((candidate) => candidate.key === carryWidenKey(headSha) && candidate.threadId === undefined);
|
|
119439
|
+
}
|
|
119440
|
+
function carryWidenPending(comment) {
|
|
119441
|
+
return comment !== undefined && !comment.comment.body.split(/\r?\n/).includes(CARRY_WIDEN_CLEARED);
|
|
119442
|
+
}
|
|
119443
|
+
function pendingCarryWidenComments(own) {
|
|
119444
|
+
return own.filter((candidate) => candidate.threadId === undefined && candidate.key.startsWith(CARRY_WIDEN_PREFIX) && carryWidenPending(candidate));
|
|
119445
|
+
}
|
|
119446
|
+
function encode3(record) {
|
|
119447
|
+
return Buffer.from(JSON.stringify(record), "utf8").toString("base64");
|
|
119448
|
+
}
|
|
119449
|
+
function heading(record) {
|
|
119450
|
+
return `Carried blocking findings at ${record.headSha}: ${record.findings.length}`;
|
|
119451
|
+
}
|
|
119452
|
+
function body(record) {
|
|
119453
|
+
return `${heading(record)}
|
|
119454
|
+
<!-- nax-bot:carried v1 ${encode3(record)} -->`;
|
|
119455
|
+
}
|
|
119456
|
+
function carriedRecordComment(own, headSha) {
|
|
119457
|
+
const key = carriedRecordKey(headSha);
|
|
119458
|
+
return own.find((candidate) => candidate.key === key && candidate.threadId === undefined);
|
|
119459
|
+
}
|
|
119460
|
+
function isSeverity(value) {
|
|
119461
|
+
return SEVERITIES2.some((severity) => severity === value);
|
|
119462
|
+
}
|
|
119463
|
+
function readCarriedEntry(value) {
|
|
119464
|
+
if (typeof value !== "object" || value === null)
|
|
119465
|
+
return;
|
|
119466
|
+
const item = value;
|
|
119467
|
+
if (typeof item.key !== "string" || item.key === "")
|
|
119468
|
+
return;
|
|
119469
|
+
if (typeof item.issue !== "string" || !isSeverity(item.severity))
|
|
119470
|
+
return;
|
|
119471
|
+
const { trigger, triggerEvidence, raisedBy } = item;
|
|
119472
|
+
const knownTrigger = FINDING_TRIGGERS.find((candidate) => candidate === trigger);
|
|
119473
|
+
if (trigger !== undefined && knownTrigger === undefined)
|
|
119474
|
+
return;
|
|
119475
|
+
if (triggerEvidence !== undefined && typeof triggerEvidence !== "string")
|
|
119476
|
+
return;
|
|
119477
|
+
if (raisedBy !== undefined && (typeof raisedBy !== "string" || raisedBy === ""))
|
|
119478
|
+
return;
|
|
119479
|
+
return {
|
|
119480
|
+
key: item.key,
|
|
119481
|
+
severity: item.severity,
|
|
119482
|
+
issue: item.issue,
|
|
119483
|
+
...knownTrigger === undefined ? {} : { trigger: knownTrigger },
|
|
119484
|
+
...triggerEvidence === undefined ? {} : { triggerEvidence },
|
|
119485
|
+
...raisedBy === undefined ? {} : { raisedBy },
|
|
119486
|
+
...typeof item.file === "string" ? { file: item.file } : {},
|
|
119487
|
+
...typeof item.line === "number" && Number.isFinite(item.line) ? { line: item.line } : {},
|
|
119488
|
+
...typeof item.suggestion === "string" ? { suggestion: item.suggestion } : {}
|
|
119489
|
+
};
|
|
119490
|
+
}
|
|
119491
|
+
function readPayload(decoded) {
|
|
119492
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
119493
|
+
return;
|
|
119494
|
+
const item = decoded;
|
|
119495
|
+
if (typeof item.headSha !== "string" || !FULL_SHA.test(item.headSha) || !Array.isArray(item.findings))
|
|
119496
|
+
return;
|
|
119497
|
+
const findings = [];
|
|
119498
|
+
for (const value of item.findings) {
|
|
119499
|
+
const entry = readCarriedEntry(value);
|
|
119500
|
+
if (entry === undefined)
|
|
119501
|
+
return;
|
|
119502
|
+
findings.push(entry);
|
|
119503
|
+
}
|
|
119504
|
+
return { headSha: item.headSha, findings };
|
|
119505
|
+
}
|
|
119506
|
+
function parseCarriedRecord(text) {
|
|
119507
|
+
const lines = stripNaxBotMarkers(text).split(/\r?\n/);
|
|
119508
|
+
const at = lines.findIndex((line) => HEADING.test(line));
|
|
119509
|
+
if (at === -1)
|
|
119510
|
+
return null;
|
|
119511
|
+
const declared = HEADING.exec(lines[at] ?? "");
|
|
119512
|
+
const payload = BLOCK.exec(lines[at + 1] ?? "");
|
|
119513
|
+
if (declared?.[1] === undefined || declared[2] === undefined || payload?.[1] === undefined)
|
|
119514
|
+
return null;
|
|
119515
|
+
if (!BASE64.test(payload[1]))
|
|
119516
|
+
return null;
|
|
119517
|
+
const bytes = Buffer.from(payload[1], "base64");
|
|
119518
|
+
if (bytes.toString("base64") !== payload[1])
|
|
119519
|
+
return null;
|
|
119520
|
+
let decoded;
|
|
119521
|
+
try {
|
|
119522
|
+
decoded = JSON.parse(bytes.toString("utf8"));
|
|
119523
|
+
} catch {
|
|
119524
|
+
return null;
|
|
119525
|
+
}
|
|
119526
|
+
const record = readPayload(decoded);
|
|
119527
|
+
if (record === undefined || record.findings.length !== Number(declared[2]))
|
|
119528
|
+
return null;
|
|
119529
|
+
return record.headSha === declared[1] ? record : null;
|
|
119530
|
+
}
|
|
119531
|
+
function budgeted(entry) {
|
|
119532
|
+
return {
|
|
119533
|
+
...entry,
|
|
119534
|
+
issue: entry.issue.slice(0, MAX_ISSUE_CHARS2),
|
|
119535
|
+
...entry.suggestion === undefined ? {} : { suggestion: entry.suggestion.slice(0, MAX_SUGGESTION_CHARS) }
|
|
119536
|
+
};
|
|
119537
|
+
}
|
|
119538
|
+
function carriedRecordBody(record) {
|
|
119539
|
+
const kept = [];
|
|
119540
|
+
for (const entry of record.findings.slice(0, MAX_CARRIED_ENTRIES).map(budgeted)) {
|
|
119541
|
+
const candidate = { headSha: record.headSha, findings: [...kept, entry] };
|
|
119542
|
+
if (body(candidate).length > MAX_CARRIED_CHARS)
|
|
119543
|
+
break;
|
|
119544
|
+
kept.push(entry);
|
|
119545
|
+
}
|
|
119546
|
+
return { body: body({ headSha: record.headSha, findings: kept }), dropped: record.findings.length - kept.length };
|
|
119547
|
+
}
|
|
119548
|
+
var CARRIED_RECORD_PREFIX = "w-carry:", CARRY_WIDEN_PREFIX = "w-carry-incomplete:", CARRY_WIDEN_CLEARED = "A complete full review restored carried finding coverage.", FULL_SHA, HEADING, BLOCK, BASE64, SEVERITIES2, MAX_CARRIED_ENTRIES = 32, MAX_CARRIED_CHARS = 24000, MAX_ISSUE_CHARS2 = 1000, MAX_SUGGESTION_CHARS = 500;
|
|
119549
|
+
var init_carried_record = __esm(() => {
|
|
119550
|
+
init_forge();
|
|
119551
|
+
init_blocking_findings();
|
|
119552
|
+
FULL_SHA = /^[0-9a-f]{40}$/;
|
|
119553
|
+
HEADING = /^Carried blocking findings at ([0-9a-f]{40}): (\d+)$/;
|
|
119554
|
+
BLOCK = /^<!-- nax-bot:carried v1 (.*?) -->$/;
|
|
119555
|
+
BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
119556
|
+
SEVERITIES2 = ["critical", "important", "minor"];
|
|
119557
|
+
});
|
|
119558
|
+
|
|
119416
119559
|
// src/worktree/nax-orphan-ref.ts
|
|
119417
119560
|
function naxOrphanRefName(worktreeId) {
|
|
119418
119561
|
validateStoryId(worktreeId);
|
|
@@ -120142,16 +120285,16 @@ function isLedgerLine(line) {
|
|
|
120142
120285
|
function isMarkerLine(line) {
|
|
120143
120286
|
return markerPattern().test(line);
|
|
120144
120287
|
}
|
|
120145
|
-
function
|
|
120288
|
+
function encode4(entries) {
|
|
120146
120289
|
return `${LEDGER_PREFIX}${Buffer.from(JSON.stringify(entries), "utf8").toString("base64")}${LEDGER_SUFFIX}`;
|
|
120147
120290
|
}
|
|
120148
120291
|
function readItem(value) {
|
|
120149
120292
|
if (typeof value !== "object" || value === null)
|
|
120150
120293
|
return;
|
|
120151
|
-
const { key, generation, issue } = value;
|
|
120294
|
+
const { key, generation, issue, raisedBy } = value;
|
|
120152
120295
|
if (typeof key !== "string" || typeof generation !== "number" || typeof issue !== "string")
|
|
120153
120296
|
return;
|
|
120154
|
-
return { key, generation, issue };
|
|
120297
|
+
return { key, generation, issue, ...typeof raisedBy === "string" && raisedBy !== "" ? { raisedBy } : {} };
|
|
120155
120298
|
}
|
|
120156
120299
|
function readItems(values) {
|
|
120157
120300
|
const items = [];
|
|
@@ -120167,7 +120310,7 @@ function readEntry(value) {
|
|
|
120167
120310
|
if (typeof value !== "object" || value === null)
|
|
120168
120311
|
return;
|
|
120169
120312
|
const { base, sha, at, items } = value;
|
|
120170
|
-
if (typeof base !== "string" || typeof sha !== "string" || !
|
|
120313
|
+
if (typeof base !== "string" || typeof sha !== "string" || !FULL_SHA2.test(sha) || !Array.isArray(items))
|
|
120171
120314
|
return;
|
|
120172
120315
|
const read = readItems(items);
|
|
120173
120316
|
if (read === undefined)
|
|
@@ -120187,7 +120330,7 @@ function readEntries(decoded) {
|
|
|
120187
120330
|
return entries;
|
|
120188
120331
|
}
|
|
120189
120332
|
function parsePayload(payload) {
|
|
120190
|
-
if (!
|
|
120333
|
+
if (!BASE642.test(payload))
|
|
120191
120334
|
return;
|
|
120192
120335
|
const bytes = Buffer.from(payload, "base64");
|
|
120193
120336
|
if (bytes.toString("base64") !== payload)
|
|
@@ -120223,7 +120366,7 @@ function withPushLedger(body, entries) {
|
|
|
120223
120366
|
const kept = body.split(`
|
|
120224
120367
|
`).filter((line) => !isLedgerLine(line));
|
|
120225
120368
|
return entries.length === 0 ? kept.join(`
|
|
120226
|
-
`) : insertBeforeMarker(kept,
|
|
120369
|
+
`) : insertBeforeMarker(kept, encode4(entries));
|
|
120227
120370
|
}
|
|
120228
120371
|
function ledgerIssue(issue) {
|
|
120229
120372
|
return firstIssueLine(issue).slice(0, MAX_ITEM_ISSUE_CHARS);
|
|
@@ -120232,7 +120375,7 @@ function parentIssue(pushSha, parent, entries) {
|
|
|
120232
120375
|
return entries.find(({ sha }) => sha === pushSha)?.items.find(({ key }) => key === parent)?.issue;
|
|
120233
120376
|
}
|
|
120234
120377
|
function fits(entries) {
|
|
120235
|
-
return
|
|
120378
|
+
return encode4(entries).length <= MAX_LEDGER_CHARS;
|
|
120236
120379
|
}
|
|
120237
120380
|
function fitted(entries) {
|
|
120238
120381
|
let kept = entries.slice(-MAX_PUSH_ENTRIES);
|
|
@@ -120295,7 +120438,7 @@ function pushRecordEntries(own) {
|
|
|
120295
120438
|
return own.flatMap((own) => own.threadId === undefined && own.key.startsWith(PUSH_RECORD_PREFIX) ? readPushLedger(own.comment.body).entries : []);
|
|
120296
120439
|
}
|
|
120297
120440
|
function pushLedgerChars(entries) {
|
|
120298
|
-
return entries.length === 0 ? 0 :
|
|
120441
|
+
return entries.length === 0 ? 0 : encode4(entries).length + 1;
|
|
120299
120442
|
}
|
|
120300
120443
|
function readEntriesOf(body) {
|
|
120301
120444
|
return body === undefined ? [] : readPushLedger(body).entries;
|
|
@@ -120305,13 +120448,13 @@ function nextLedgerEntries(input) {
|
|
|
120305
120448
|
const kept = mergeLedgerEntries(merged, input.records ?? []);
|
|
120306
120449
|
return input.entry === undefined ? fitted(kept) : appendPushEntry(kept, input.entry);
|
|
120307
120450
|
}
|
|
120308
|
-
var MAX_PUSH_ENTRIES = 64, MAX_LEDGER_CHARS = 24000, MAX_ITEM_ISSUE_CHARS = 120, SHORT_SHA_LENGTH3 = 7, LEDGER_PREFIX = "<!-- nax-bot:pushes v1 ", LEDGER_SUFFIX = " -->", LEDGER_LINE,
|
|
120451
|
+
var MAX_PUSH_ENTRIES = 64, MAX_LEDGER_CHARS = 24000, MAX_ITEM_ISSUE_CHARS = 120, SHORT_SHA_LENGTH3 = 7, LEDGER_PREFIX = "<!-- nax-bot:pushes v1 ", LEDGER_SUFFIX = " -->", LEDGER_LINE, FULL_SHA2, BASE642, PUSH_RECORD_PREFIX = "push-";
|
|
120309
120452
|
var init_push_ledger = __esm(() => {
|
|
120310
120453
|
init_forge();
|
|
120311
120454
|
init_blocking_findings();
|
|
120312
120455
|
LEDGER_LINE = /<!-- nax-bot:pushes v1 (.*?) -->/;
|
|
120313
|
-
|
|
120314
|
-
|
|
120456
|
+
FULL_SHA2 = /^[0-9a-f]{40}$/;
|
|
120457
|
+
BASE642 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
120315
120458
|
});
|
|
120316
120459
|
|
|
120317
120460
|
// src/bot/convergence-summary.ts
|
|
@@ -120422,12 +120565,12 @@ async function creditedFiles(input) {
|
|
|
120422
120565
|
}
|
|
120423
120566
|
|
|
120424
120567
|
// src/bot/coverage-record.ts
|
|
120425
|
-
function
|
|
120568
|
+
function heading2(headSha, count) {
|
|
120426
120569
|
return `Review coverage at ${headSha}: ${count} required file(s) not read`;
|
|
120427
120570
|
}
|
|
120428
120571
|
function renderCoverageRecord(record) {
|
|
120429
120572
|
const files = record.uncovered.map((path) => `- \`${path}\``);
|
|
120430
|
-
return [
|
|
120573
|
+
return [heading2(record.headSha, record.uncovered.length), ...files].join(`
|
|
120431
120574
|
`);
|
|
120432
120575
|
}
|
|
120433
120576
|
function fileLines(lines) {
|
|
@@ -120443,10 +120586,10 @@ function fileLines(lines) {
|
|
|
120443
120586
|
}
|
|
120444
120587
|
function parseCoverageRecord(body) {
|
|
120445
120588
|
const lines = stripNaxBotMarkers(body).split(/\r?\n/);
|
|
120446
|
-
const start = lines.findIndex((line) =>
|
|
120589
|
+
const start = lines.findIndex((line) => HEADING2.test(line));
|
|
120447
120590
|
if (start === -1)
|
|
120448
120591
|
return null;
|
|
120449
|
-
const [, headSha, declared] =
|
|
120592
|
+
const [, headSha, declared] = HEADING2.exec(lines[start] ?? "") ?? [];
|
|
120450
120593
|
if (headSha === undefined || declared === undefined)
|
|
120451
120594
|
return null;
|
|
120452
120595
|
const { files: uncovered, rest } = fileLines(lines.slice(start + 1));
|
|
@@ -120456,10 +120599,36 @@ function parseCoverageRecord(body) {
|
|
|
120456
120599
|
return null;
|
|
120457
120600
|
return { headSha, uncovered };
|
|
120458
120601
|
}
|
|
120459
|
-
|
|
120602
|
+
function recordsCodeReview(input) {
|
|
120603
|
+
if (input.staticMode || input.scope === "conversation-only")
|
|
120604
|
+
return false;
|
|
120605
|
+
return hasNaxWorkflowMarker(input.info.body);
|
|
120606
|
+
}
|
|
120607
|
+
async function postCoverageRecord(input) {
|
|
120608
|
+
if (!recordsCodeReview(input))
|
|
120609
|
+
return true;
|
|
120610
|
+
try {
|
|
120611
|
+
const body = withNaxBotMarker(renderCoverageRecord({ headSha: input.info.headSha, uncovered: input.unreadFiles ?? [] }), COVERAGE_RECORD_KEY);
|
|
120612
|
+
const own = input.own.find(({ key }) => key === COVERAGE_RECORD_KEY);
|
|
120613
|
+
if (own)
|
|
120614
|
+
await editComment(input.ref, own.comment, body, input.deps, input.cwd);
|
|
120615
|
+
else
|
|
120616
|
+
await postPrComment(input.ref, body, input.deps, input.cwd);
|
|
120617
|
+
return true;
|
|
120618
|
+
} catch (cause) {
|
|
120619
|
+
getLogger2()?.warn("bot-post", "Could not write the review coverage record", {
|
|
120620
|
+
pr: input.ref.number,
|
|
120621
|
+
error: errorMessage(cause)
|
|
120622
|
+
});
|
|
120623
|
+
return false;
|
|
120624
|
+
}
|
|
120625
|
+
}
|
|
120626
|
+
var COVERAGE_RECORD_KEY = "w-coverage", HEADING2, FILE_LINE;
|
|
120460
120627
|
var init_coverage_record = __esm(() => {
|
|
120628
|
+
init_internal();
|
|
120461
120629
|
init_forge();
|
|
120462
|
-
|
|
120630
|
+
init_logger2();
|
|
120631
|
+
HEADING2 = /^Review coverage at ([0-9A-Fa-f]{40}): (\d+) required file\(s\) not read$/;
|
|
120463
120632
|
FILE_LINE = /^- `([^`]+)`$/;
|
|
120464
120633
|
});
|
|
120465
120634
|
|
|
@@ -120966,6 +121135,251 @@ var init_chat_asks = __esm(() => {
|
|
|
120966
121135
|
init_logger2();
|
|
120967
121136
|
});
|
|
120968
121137
|
|
|
121138
|
+
// src/bot/review-blocking.ts
|
|
121139
|
+
function reviewBlockingTriggers(env) {
|
|
121140
|
+
return env.review.blockingTriggers ?? env.codeReview?.blockingTriggers ?? configuredBlockingTriggers(env.config);
|
|
121141
|
+
}
|
|
121142
|
+
function hasPushWorthyItem(env) {
|
|
121143
|
+
const blocking = reviewBlockingTriggers(env);
|
|
121144
|
+
return env.review.agreed.some((item) => item.kind !== "finding" || isBlockingFinding(item, blocking));
|
|
121145
|
+
}
|
|
121146
|
+
var init_review_blocking = __esm(() => {
|
|
121147
|
+
init_blocking_findings();
|
|
121148
|
+
});
|
|
121149
|
+
|
|
121150
|
+
// src/bot/fix-carried.ts
|
|
121151
|
+
function candidates(env, blocking) {
|
|
121152
|
+
const head = env.info.headSha;
|
|
121153
|
+
if (env.review.headSha !== head)
|
|
121154
|
+
return [];
|
|
121155
|
+
const own = carriedRecordComment(env.own, head);
|
|
121156
|
+
const record = own === undefined ? null : parseCarriedRecord(own.comment.body);
|
|
121157
|
+
if (record?.headSha !== head)
|
|
121158
|
+
return [];
|
|
121159
|
+
const seen = new Set(env.review.agreed.map(({ key }) => key));
|
|
121160
|
+
return record.findings.flatMap((entry) => {
|
|
121161
|
+
if (seen.has(entry.key) || !isBlockingFinding(entry, blocking))
|
|
121162
|
+
return [];
|
|
121163
|
+
seen.add(entry.key);
|
|
121164
|
+
return [{ kind: "finding", ...entry }];
|
|
121165
|
+
});
|
|
121166
|
+
}
|
|
121167
|
+
async function withCarriedFixFindings(env) {
|
|
121168
|
+
const carry = candidates(env, reviewBlockingTriggers(env));
|
|
121169
|
+
if (carry.length === 0)
|
|
121170
|
+
return env;
|
|
121171
|
+
const input = {
|
|
121172
|
+
ref: env.ref,
|
|
121173
|
+
login: env.user.login,
|
|
121174
|
+
threads: env.threads,
|
|
121175
|
+
comments: env.own.filter(({ threadId }) => threadId === undefined).map(({ comment }) => comment),
|
|
121176
|
+
deps: env.forge,
|
|
121177
|
+
cwd: env.repoRoot
|
|
121178
|
+
};
|
|
121179
|
+
const withdrawn = new Set((env.review.events ?? []).flatMap((event) => event.type === "finding-withdrawn" ? [event.key] : []));
|
|
121180
|
+
const [settled, confirmed] = await Promise.all([
|
|
121181
|
+
_fixCarriedDeps.readSettledKeys(input),
|
|
121182
|
+
withdrawn.size === 0 ? new Set : _fixCarriedDeps.readConfirmedKeys(input)
|
|
121183
|
+
]);
|
|
121184
|
+
const open = carry.filter(({ key }) => withdrawn.has(key) ? confirmed.has(key) : !settled.has(key));
|
|
121185
|
+
return { ...env, review: { ...env.review, agreed: [...env.review.agreed, ...open] } };
|
|
121186
|
+
}
|
|
121187
|
+
var _fixCarriedDeps;
|
|
121188
|
+
var init_fix_carried = __esm(() => {
|
|
121189
|
+
init_blocking_findings();
|
|
121190
|
+
init_carried_record();
|
|
121191
|
+
init_review_blocking();
|
|
121192
|
+
init_rulings();
|
|
121193
|
+
_fixCarriedDeps = { readSettledKeys, readConfirmedKeys };
|
|
121194
|
+
});
|
|
121195
|
+
|
|
121196
|
+
// src/bot/carried-findings.ts
|
|
121197
|
+
function carriedOpen(input) {
|
|
121198
|
+
const earlier = input.carriedFindings ?? [];
|
|
121199
|
+
if (earlier.length === 0)
|
|
121200
|
+
return [];
|
|
121201
|
+
const blocking = input.blockingTriggers ?? DEFAULT_BLOCKING_TRIGGERS;
|
|
121202
|
+
const raised = new Set(input.verdict.findings.map(findingKey));
|
|
121203
|
+
const threaded = new Set(input.own.flatMap(({ key, threadId }) => threadId === undefined ? [] : [key]));
|
|
121204
|
+
const pushed = (input.carriedFixPushes ?? []).flatMap(({ items }) => items);
|
|
121205
|
+
const kept = [];
|
|
121206
|
+
const seen = new Set;
|
|
121207
|
+
for (const finding of earlier) {
|
|
121208
|
+
if (seen.has(finding.key) || !isBlockingFinding(finding, blocking))
|
|
121209
|
+
continue;
|
|
121210
|
+
if (raised.has(finding.key) || threaded.has(finding.key))
|
|
121211
|
+
continue;
|
|
121212
|
+
if (input.settledKeys?.has(finding.key) === true)
|
|
121213
|
+
continue;
|
|
121214
|
+
if (finding.raisedBy !== undefined && pushed.some(({ key, raisedBy }) => key === finding.key && raisedBy === finding.raisedBy))
|
|
121215
|
+
continue;
|
|
121216
|
+
seen.add(finding.key);
|
|
121217
|
+
kept.push(finding);
|
|
121218
|
+
}
|
|
121219
|
+
return kept;
|
|
121220
|
+
}
|
|
121221
|
+
function asCarried(entry) {
|
|
121222
|
+
return { kind: "finding", ...entry };
|
|
121223
|
+
}
|
|
121224
|
+
function readRecord3(own, head) {
|
|
121225
|
+
const comment = carriedRecordComment(own, head);
|
|
121226
|
+
if (comment === undefined)
|
|
121227
|
+
return { kind: "absent" };
|
|
121228
|
+
const record = parseCarriedRecord(comment.comment.body);
|
|
121229
|
+
if (record === null || record.headSha !== head)
|
|
121230
|
+
return { kind: "unusable" };
|
|
121231
|
+
return { kind: "usable", findings: record.findings.map(asCarried) };
|
|
121232
|
+
}
|
|
121233
|
+
function carriedFromArtifact(agreed) {
|
|
121234
|
+
if (!Array.isArray(agreed))
|
|
121235
|
+
return { findings: [], widen: true };
|
|
121236
|
+
const candidates = agreed.filter((item) => item?.kind === "finding");
|
|
121237
|
+
const findings = candidates.flatMap((item) => {
|
|
121238
|
+
const finding = readCarriedEntry(item);
|
|
121239
|
+
return finding === undefined ? [] : [asCarried(finding)];
|
|
121240
|
+
});
|
|
121241
|
+
return { findings, widen: candidates.length > 0 && findings.length === 0 };
|
|
121242
|
+
}
|
|
121243
|
+
async function earlierCarriedFindings(input) {
|
|
121244
|
+
const reviewedHead = input.index?.reviewedHead;
|
|
121245
|
+
if (reviewedHead === undefined)
|
|
121246
|
+
return NO_CARRY;
|
|
121247
|
+
if (input.scope === "full" || input.rangeBase !== reviewedHead)
|
|
121248
|
+
return NO_CARRY;
|
|
121249
|
+
if (pendingCarryWidenComments(input.own).length > 0)
|
|
121250
|
+
return { findings: [], widen: true };
|
|
121251
|
+
if (input.scope !== "incremental")
|
|
121252
|
+
return NO_CARRY;
|
|
121253
|
+
const record = readRecord3(input.own, reviewedHead);
|
|
121254
|
+
if (record.kind === "usable")
|
|
121255
|
+
return { findings: record.findings, widen: false };
|
|
121256
|
+
if (record.kind === "unusable")
|
|
121257
|
+
return { findings: [], widen: true };
|
|
121258
|
+
return input.load(input.outputDir, input.ref, reviewedHead);
|
|
121259
|
+
}
|
|
121260
|
+
var NO_CARRY;
|
|
121261
|
+
var init_carried_findings = __esm(() => {
|
|
121262
|
+
init_blocking_findings();
|
|
121263
|
+
init_carried_record();
|
|
121264
|
+
init_render2();
|
|
121265
|
+
NO_CARRY = { findings: [], widen: false };
|
|
121266
|
+
});
|
|
121267
|
+
|
|
121268
|
+
// src/bot/post-carried.ts
|
|
121269
|
+
function entryOf2({ kind, ...entry }) {
|
|
121270
|
+
return entry;
|
|
121271
|
+
}
|
|
121272
|
+
function offLineFinding(finding, key, raisedBy) {
|
|
121273
|
+
return {
|
|
121274
|
+
kind: "finding",
|
|
121275
|
+
key,
|
|
121276
|
+
issue: finding.issue,
|
|
121277
|
+
severity: finding.severity,
|
|
121278
|
+
raisedBy,
|
|
121279
|
+
...finding.trigger === undefined ? {} : { trigger: finding.trigger },
|
|
121280
|
+
...finding.triggerEvidence === undefined ? {} : { triggerEvidence: finding.triggerEvidence },
|
|
121281
|
+
...finding.file === undefined ? {} : { file: finding.file },
|
|
121282
|
+
...finding.line === undefined ? {} : { line: finding.line },
|
|
121283
|
+
...finding.suggestion === undefined ? {} : { suggestion: finding.suggestion }
|
|
121284
|
+
};
|
|
121285
|
+
}
|
|
121286
|
+
function carriedForRecord(input, offLine, reviewId) {
|
|
121287
|
+
const blocking = input.blockingTriggers ?? DEFAULT_BLOCKING_TRIGGERS;
|
|
121288
|
+
const kept = [...carriedOpen(input)];
|
|
121289
|
+
const seen = new Set(kept.map(({ key }) => key));
|
|
121290
|
+
for (const finding of offLine) {
|
|
121291
|
+
const key = findingKey(finding);
|
|
121292
|
+
if (seen.has(key) || !isBlockingFinding(finding, blocking))
|
|
121293
|
+
continue;
|
|
121294
|
+
seen.add(key);
|
|
121295
|
+
kept.push(offLineFinding(finding, key, reviewId));
|
|
121296
|
+
}
|
|
121297
|
+
return kept;
|
|
121298
|
+
}
|
|
121299
|
+
async function postCarriedRecord(input, offLine, review) {
|
|
121300
|
+
if (!recordsCodeReview(input))
|
|
121301
|
+
return true;
|
|
121302
|
+
const blocking = input.blockingTriggers ?? DEFAULT_BLOCKING_TRIGGERS;
|
|
121303
|
+
const hasNewBlocker = offLine.some((finding) => isBlockingFinding(finding, blocking));
|
|
121304
|
+
if (!review.complete)
|
|
121305
|
+
return !hasNewBlocker || writeCarryWiden(input, true);
|
|
121306
|
+
const findings = carriedForRecord(input, offLine, review.id);
|
|
121307
|
+
if (!await replaceCarriedRecord(input, findings)) {
|
|
121308
|
+
if (hasNewBlocker)
|
|
121309
|
+
await writeCarryWiden(input, true);
|
|
121310
|
+
return false;
|
|
121311
|
+
}
|
|
121312
|
+
return true;
|
|
121313
|
+
}
|
|
121314
|
+
async function clearCarryWidens(input) {
|
|
121315
|
+
let cleared = true;
|
|
121316
|
+
for (const own of pendingCarryWidenComments(input.own)) {
|
|
121317
|
+
if (!await writeCarryWidenComment(input, { key: own.key, own, pending: false }))
|
|
121318
|
+
cleared = false;
|
|
121319
|
+
}
|
|
121320
|
+
return cleared;
|
|
121321
|
+
}
|
|
121322
|
+
async function writeCarryWiden(input, pending) {
|
|
121323
|
+
const key = carryWidenKey(input.info.headSha);
|
|
121324
|
+
const own = carryWidenComment(input.own, input.info.headSha);
|
|
121325
|
+
if (pending === carryWidenPending(own))
|
|
121326
|
+
return true;
|
|
121327
|
+
return writeCarryWidenComment(input, { key, own, pending });
|
|
121328
|
+
}
|
|
121329
|
+
async function writeCarryWidenComment(input, signal) {
|
|
121330
|
+
const { key, own, pending } = signal;
|
|
121331
|
+
const text = pending ? "Carried finding coverage is incomplete. Review the full range before relying on this head." : CARRY_WIDEN_CLEARED;
|
|
121332
|
+
try {
|
|
121333
|
+
const body = withNaxBotMarker(text, key);
|
|
121334
|
+
if (own)
|
|
121335
|
+
await editComment(input.ref, own.comment, body, input.deps, input.cwd);
|
|
121336
|
+
else
|
|
121337
|
+
await postPrComment(input.ref, body, input.deps, input.cwd);
|
|
121338
|
+
return true;
|
|
121339
|
+
} catch (cause) {
|
|
121340
|
+
getLogger2()?.warn("bot-post", "Could not update the full-review signal for carried findings", {
|
|
121341
|
+
pr: input.ref.number,
|
|
121342
|
+
error: errorMessage(cause)
|
|
121343
|
+
});
|
|
121344
|
+
return false;
|
|
121345
|
+
}
|
|
121346
|
+
}
|
|
121347
|
+
async function replaceCarriedRecord(input, findings) {
|
|
121348
|
+
const { body, dropped } = carriedRecordBody({ headSha: input.info.headSha, findings: findings.map(entryOf2) });
|
|
121349
|
+
if (dropped > 0) {
|
|
121350
|
+
getLogger2()?.warn("bot-post", "Carried findings record exceeded its budget; holding the reviewed head", {
|
|
121351
|
+
pr: input.ref.number,
|
|
121352
|
+
dropped
|
|
121353
|
+
});
|
|
121354
|
+
return false;
|
|
121355
|
+
}
|
|
121356
|
+
const own = carriedRecordComment(input.own, input.info.headSha);
|
|
121357
|
+
try {
|
|
121358
|
+
const marked = withNaxBotMarker(body, carriedRecordKey(input.info.headSha));
|
|
121359
|
+
if (own)
|
|
121360
|
+
await editComment(input.ref, own.comment, marked, input.deps, input.cwd);
|
|
121361
|
+
else
|
|
121362
|
+
await postPrComment(input.ref, marked, input.deps, input.cwd);
|
|
121363
|
+
} catch (cause) {
|
|
121364
|
+
getLogger2()?.warn("bot-post", "Could not write the carried findings record", {
|
|
121365
|
+
pr: input.ref.number,
|
|
121366
|
+
error: errorMessage(cause)
|
|
121367
|
+
});
|
|
121368
|
+
return own === undefined && findings.length === 0;
|
|
121369
|
+
}
|
|
121370
|
+
return true;
|
|
121371
|
+
}
|
|
121372
|
+
var init_post_carried = __esm(() => {
|
|
121373
|
+
init_internal();
|
|
121374
|
+
init_forge();
|
|
121375
|
+
init_logger2();
|
|
121376
|
+
init_blocking_findings();
|
|
121377
|
+
init_carried_findings();
|
|
121378
|
+
init_carried_record();
|
|
121379
|
+
init_coverage_record();
|
|
121380
|
+
init_render2();
|
|
121381
|
+
});
|
|
121382
|
+
|
|
120969
121383
|
// src/bot/post.ts
|
|
120970
121384
|
import { join as join154 } from "path";
|
|
120971
121385
|
function reviewQuality(scope, quality) {
|
|
@@ -120980,7 +121394,7 @@ function lineageFacts(input, key) {
|
|
|
120980
121394
|
return { lineage };
|
|
120981
121395
|
return input.lineage?.unknown.has(key) === true ? { lineageUnknown: true } : {};
|
|
120982
121396
|
}
|
|
120983
|
-
function agreedItems(input) {
|
|
121397
|
+
function agreedItems(input, reviewId) {
|
|
120984
121398
|
const items = input.verdict.findings.filter((finding) => !input.settledKeys?.has(findingKey(finding))).map(({ severity, issue, file, line, suggestion, decision, trigger, triggerEvidence }) => {
|
|
120985
121399
|
const key = findingKey({ file, issue });
|
|
120986
121400
|
return {
|
|
@@ -120994,6 +121408,7 @@ function agreedItems(input) {
|
|
|
120994
121408
|
...decision === undefined ? {} : { decision },
|
|
120995
121409
|
...trigger === undefined ? {} : { trigger },
|
|
120996
121410
|
...triggerEvidence === undefined ? {} : { triggerEvidence },
|
|
121411
|
+
...reviewId === undefined ? {} : { raisedBy: reviewId },
|
|
120997
121412
|
...lineageFacts(input, key)
|
|
120998
121413
|
};
|
|
120999
121414
|
});
|
|
@@ -121023,6 +121438,7 @@ function agreedItems(input) {
|
|
|
121023
121438
|
continue;
|
|
121024
121439
|
items.push({ key: commentKey(comment.id), kind: "comment", issue: comment.body, reason: verdict.reason });
|
|
121025
121440
|
}
|
|
121441
|
+
items.push(...carriedOpen(input));
|
|
121026
121442
|
return mergeEarlier(input, items);
|
|
121027
121443
|
}
|
|
121028
121444
|
function earlierTrigger(body) {
|
|
@@ -121075,7 +121491,7 @@ function mergeEarlier(input, items) {
|
|
|
121075
121491
|
}
|
|
121076
121492
|
return items;
|
|
121077
121493
|
}
|
|
121078
|
-
async function persistArtifact(input) {
|
|
121494
|
+
async function persistArtifact(input, reviewId) {
|
|
121079
121495
|
const artifact = {
|
|
121080
121496
|
version: 3,
|
|
121081
121497
|
...input.rulings === undefined ? {} : { rulings: input.rulings },
|
|
@@ -121089,7 +121505,7 @@ async function persistArtifact(input) {
|
|
|
121089
121505
|
trusted: !input.staticMode,
|
|
121090
121506
|
intent: input.verdict.intent,
|
|
121091
121507
|
quality: reviewQuality(input.scope, input.verdict.quality),
|
|
121092
|
-
agreed: agreedItems(input),
|
|
121508
|
+
agreed: agreedItems(input, reviewId),
|
|
121093
121509
|
...input.blockingTriggers === undefined ? {} : { blockingTriggers: input.blockingTriggers },
|
|
121094
121510
|
...input.lineage === undefined || input.lineage.unreachable === 0 ? {} : { unreachablePushes: input.lineage.unreachable }
|
|
121095
121511
|
};
|
|
@@ -121142,6 +121558,7 @@ async function postFindings(input) {
|
|
|
121142
121558
|
residual
|
|
121143
121559
|
};
|
|
121144
121560
|
let inlineFindings = 0;
|
|
121561
|
+
let reopenFailed = 0;
|
|
121145
121562
|
for (const finding of input.verdict.findings) {
|
|
121146
121563
|
if (input.settledKeys?.has(findingKey(finding)))
|
|
121147
121564
|
continue;
|
|
@@ -121158,8 +121575,10 @@ async function postFindings(input) {
|
|
|
121158
121575
|
try {
|
|
121159
121576
|
if (await writeFinding(input, finding))
|
|
121160
121577
|
inlineFindings++;
|
|
121161
|
-
else
|
|
121578
|
+
else {
|
|
121579
|
+
reopenFailed++;
|
|
121162
121580
|
offLine.push(finding);
|
|
121581
|
+
}
|
|
121163
121582
|
} catch (cause) {
|
|
121164
121583
|
if (input.own.some((own) => own.key === key))
|
|
121165
121584
|
throw cause;
|
|
@@ -121167,7 +121586,7 @@ async function postFindings(input) {
|
|
|
121167
121586
|
offLine.push(finding);
|
|
121168
121587
|
}
|
|
121169
121588
|
}
|
|
121170
|
-
return { inlineFindings, offLine, minor, residual };
|
|
121589
|
+
return { inlineFindings, reopenFailed, offLine, minor, residual };
|
|
121171
121590
|
}
|
|
121172
121591
|
function blockingFindingCount(input) {
|
|
121173
121592
|
const blocking = input.blockingTriggers ?? DEFAULT_BLOCKING_TRIGGERS;
|
|
@@ -121216,6 +121635,7 @@ async function postSummary(input, findings, threads) {
|
|
|
121216
121635
|
...input.buildFailed === undefined ? {} : { buildFailed: input.buildFailed },
|
|
121217
121636
|
...input.ci === undefined ? {} : { ci: input.ci },
|
|
121218
121637
|
...findings,
|
|
121638
|
+
carried: carriedOpen(input),
|
|
121219
121639
|
...threads,
|
|
121220
121640
|
...input.blockingTriggers === undefined ? {} : { blockingTriggers: input.blockingTriggers },
|
|
121221
121641
|
...input.blockingSource === undefined ? {} : { blockingSource: input.blockingSource },
|
|
@@ -121235,43 +121655,26 @@ async function postSummary(input, findings, threads) {
|
|
|
121235
121655
|
else
|
|
121236
121656
|
await postPrComment(input.ref, body, input.deps, input.cwd);
|
|
121237
121657
|
}
|
|
121238
|
-
function recordsCoverage(input) {
|
|
121239
|
-
if (input.staticMode || input.scope === "conversation-only")
|
|
121240
|
-
return false;
|
|
121241
|
-
return hasNaxWorkflowMarker(input.info.body);
|
|
121242
|
-
}
|
|
121243
|
-
async function postCoverageRecord(input) {
|
|
121244
|
-
if (!recordsCoverage(input))
|
|
121245
|
-
return;
|
|
121246
|
-
try {
|
|
121247
|
-
const body = withNaxBotMarker(renderCoverageRecord({ headSha: input.info.headSha, uncovered: input.unreadFiles ?? [] }), COVERAGE_RECORD_KEY);
|
|
121248
|
-
const own = input.own.find(({ key }) => key === COVERAGE_RECORD_KEY);
|
|
121249
|
-
if (own)
|
|
121250
|
-
await editComment(input.ref, own.comment, body, input.deps, input.cwd);
|
|
121251
|
-
else
|
|
121252
|
-
await postPrComment(input.ref, body, input.deps, input.cwd);
|
|
121253
|
-
} catch (cause) {
|
|
121254
|
-
getLogger2()?.warn("bot-post", "Could not write the review coverage record", {
|
|
121255
|
-
pr: input.ref.number,
|
|
121256
|
-
error: errorMessage(cause)
|
|
121257
|
-
});
|
|
121258
|
-
}
|
|
121259
|
-
}
|
|
121260
121658
|
async function postPrReview(input) {
|
|
121261
|
-
|
|
121659
|
+
const reviewId = crypto.randomUUID();
|
|
121660
|
+
await persistArtifact(input, recordsCodeReview(input) ? reviewId : undefined);
|
|
121262
121661
|
const findings = await postFindings(input);
|
|
121263
121662
|
const threads = await postThreads(input);
|
|
121264
121663
|
const earlier = await postEarlier(input);
|
|
121265
|
-
const failed = threads.failed + earlier.failed;
|
|
121664
|
+
const failed = threads.failed + earlier.failed + findings.reopenFailed;
|
|
121266
121665
|
await postSummary(input, findings, { ...threads, failed });
|
|
121267
|
-
await postCoverageRecord(input);
|
|
121666
|
+
const coverageRecorded = await postCoverageRecord(input);
|
|
121667
|
+
const complete = failed === 0 && coverageRecorded && (input.unreadFiles?.length ?? 0) === 0;
|
|
121668
|
+
const carriedRecorded = await postCarriedRecord(input, findings.offLine, { id: reviewId, complete });
|
|
121268
121669
|
return {
|
|
121269
121670
|
inlineFindings: findings.inlineFindings,
|
|
121270
121671
|
...threads,
|
|
121271
121672
|
earlierAnswered: earlier.earlierAnswered,
|
|
121272
121673
|
failed,
|
|
121273
121674
|
commentsAnswered: input.verdict.comments.length,
|
|
121274
|
-
offLine: findings.offLine.length
|
|
121675
|
+
offLine: findings.offLine.length,
|
|
121676
|
+
...coverageRecorded ? {} : { coverageRecordFailed: true },
|
|
121677
|
+
...carriedRecorded ? {} : { carriedRecordFailed: true }
|
|
121275
121678
|
};
|
|
121276
121679
|
}
|
|
121277
121680
|
var BOT_REVIEW_FILENAME = "bot-review.json", _postDeps, TRIGGER_LINE = "Trigger:", LINEAGE_LINE = "Lineage:";
|
|
@@ -121281,7 +121684,9 @@ var init_post = __esm(() => {
|
|
|
121281
121684
|
init_forge();
|
|
121282
121685
|
init_logger2();
|
|
121283
121686
|
init_blocking_findings();
|
|
121687
|
+
init_carried_findings();
|
|
121284
121688
|
init_coverage_record();
|
|
121689
|
+
init_post_carried();
|
|
121285
121690
|
init_post_earlier();
|
|
121286
121691
|
init_render2();
|
|
121287
121692
|
init_render_comments();
|
|
@@ -121298,55 +121703,95 @@ async function readReview(path) {
|
|
|
121298
121703
|
const value = JSON.parse(await _fixInputDeps.readText(path));
|
|
121299
121704
|
if (typeof value !== "object" || value === null || !("version" in value) || value.version !== 1 && value.version !== 2 && value.version !== 3)
|
|
121300
121705
|
return null;
|
|
121301
|
-
|
|
121302
|
-
getLogger2()?.warn("bot-fix", "Ignoring review artifact with invalid checks; re-run nax bot review", { path });
|
|
121303
|
-
return null;
|
|
121304
|
-
}
|
|
121305
|
-
const review = value;
|
|
121306
|
-
if (review.version < 3 && Array.isArray(review.agreed)) {
|
|
121307
|
-
const agreed = review.agreed.filter((item) => item?.kind === "finding");
|
|
121308
|
-
const dropped = review.agreed.length - agreed.length;
|
|
121309
|
-
if (dropped > 0)
|
|
121310
|
-
getLogger2()?.warn("bot-fix", "Dropped unchecked thread and comment items from an older review; re-run nax bot review", { path, dropped });
|
|
121311
|
-
return { ...review, agreed };
|
|
121312
|
-
}
|
|
121313
|
-
return review;
|
|
121706
|
+
return value;
|
|
121314
121707
|
} catch (cause) {
|
|
121315
121708
|
getLogger2()?.debug("bot-fix", "Ignoring unreadable review artifact", { path, error: errorMessage(cause) });
|
|
121316
121709
|
return null;
|
|
121317
121710
|
}
|
|
121318
121711
|
}
|
|
121319
|
-
|
|
121320
|
-
|
|
121712
|
+
function fixReview(review, path) {
|
|
121713
|
+
if (review.checks !== undefined && review.checks !== null && !checksSchema.safeParse(review.checks).success) {
|
|
121714
|
+
getLogger2()?.warn("bot-fix", "Ignoring review artifact with invalid checks; re-run nax bot review", { path });
|
|
121715
|
+
return null;
|
|
121716
|
+
}
|
|
121717
|
+
if (review.agreed !== undefined && !Array.isArray(review.agreed)) {
|
|
121718
|
+
getLogger2()?.warn("bot-fix", "Ignoring review artifact with an unreadable agreed list; re-run nax bot review", {
|
|
121719
|
+
path
|
|
121720
|
+
});
|
|
121721
|
+
return null;
|
|
121722
|
+
}
|
|
121723
|
+
if (review.version < 3 && Array.isArray(review.agreed)) {
|
|
121724
|
+
const agreed = review.agreed.filter((item) => item?.kind === "finding");
|
|
121725
|
+
const dropped = review.agreed.length - agreed.length;
|
|
121726
|
+
if (dropped > 0)
|
|
121727
|
+
getLogger2()?.warn("bot-fix", "Dropped unchecked thread and comment items from an older review; re-run nax bot review", { path, dropped });
|
|
121728
|
+
return { ...review, agreed };
|
|
121729
|
+
}
|
|
121730
|
+
return review;
|
|
121731
|
+
}
|
|
121732
|
+
async function reviewPaths({ outputDir, ref }) {
|
|
121321
121733
|
try {
|
|
121322
|
-
|
|
121734
|
+
return await _fixInputDeps.glob(join155("bot", `pr-${ref.number}`, "*", BOT_REVIEW_FILENAME), outputDir);
|
|
121323
121735
|
} catch (cause) {
|
|
121324
121736
|
if (typeof cause === "object" && cause !== null && "code" in cause && cause.code === "ENOENT")
|
|
121325
|
-
return
|
|
121737
|
+
return [];
|
|
121326
121738
|
throw cause;
|
|
121327
121739
|
}
|
|
121740
|
+
}
|
|
121741
|
+
async function selectReview(input) {
|
|
121328
121742
|
let latest = null;
|
|
121329
121743
|
let newest = Number.NEGATIVE_INFINITY;
|
|
121330
|
-
|
|
121744
|
+
let matched = false;
|
|
121745
|
+
for (const path of await reviewPaths(input)) {
|
|
121331
121746
|
const review = await readReview(path);
|
|
121332
|
-
if (review?.headSha !== headSha)
|
|
121747
|
+
if (review?.headSha !== input.headSha || !samePr(review.pr, input.ref))
|
|
121748
|
+
continue;
|
|
121749
|
+
if (input.codeOnly && review.scope === "conversation-only")
|
|
121333
121750
|
continue;
|
|
121334
|
-
|
|
121751
|
+
matched = true;
|
|
121752
|
+
const usable = input.select(review, path);
|
|
121753
|
+
if (usable === null)
|
|
121335
121754
|
continue;
|
|
121336
|
-
let mtime;
|
|
121337
121755
|
try {
|
|
121338
|
-
mtime = await _fixInputDeps.mtimeMs(path);
|
|
121756
|
+
const mtime = await _fixInputDeps.mtimeMs(path);
|
|
121757
|
+
if (mtime > newest) {
|
|
121758
|
+
latest = usable;
|
|
121759
|
+
newest = mtime;
|
|
121760
|
+
}
|
|
121339
121761
|
} catch (cause) {
|
|
121340
121762
|
getLogger2()?.debug("bot-fix", "Ignoring vanished review artifact", { path, error: errorMessage(cause) });
|
|
121341
|
-
continue;
|
|
121342
|
-
}
|
|
121343
|
-
if (mtime > newest) {
|
|
121344
|
-
latest = review;
|
|
121345
|
-
newest = mtime;
|
|
121346
121763
|
}
|
|
121347
121764
|
}
|
|
121765
|
+
return { latest, matched };
|
|
121766
|
+
}
|
|
121767
|
+
async function loadLatestReview(outputDir, ref, headSha, options = {}) {
|
|
121768
|
+
const { latest } = await selectReview({
|
|
121769
|
+
outputDir,
|
|
121770
|
+
ref,
|
|
121771
|
+
headSha,
|
|
121772
|
+
codeOnly: options.codeOnly === true,
|
|
121773
|
+
select: fixReview
|
|
121774
|
+
});
|
|
121348
121775
|
return latest;
|
|
121349
121776
|
}
|
|
121777
|
+
async function loadLatestCarry(outputDir, ref, headSha) {
|
|
121778
|
+
const { latest, matched } = await selectReview({
|
|
121779
|
+
outputDir,
|
|
121780
|
+
ref,
|
|
121781
|
+
headSha,
|
|
121782
|
+
codeOnly: true,
|
|
121783
|
+
select(review) {
|
|
121784
|
+
const carry = carriedFromArtifact(review.agreed);
|
|
121785
|
+
return carry.widen ? null : carry;
|
|
121786
|
+
}
|
|
121787
|
+
});
|
|
121788
|
+
return latest ?? (matched ? { findings: [], widen: true } : NO_CARRY);
|
|
121789
|
+
}
|
|
121790
|
+
function samePr(recorded, wanted) {
|
|
121791
|
+
if (recorded === undefined || recorded === null)
|
|
121792
|
+
return false;
|
|
121793
|
+
return recorded.forge === wanted.forge && recorded.host === wanted.host && recorded.number === wanted.number && typeof recorded.repo === "string" && (wanted.forge === "github" ? recorded.repo.toLowerCase() === wanted.repo.toLowerCase() : recorded.repo === wanted.repo);
|
|
121794
|
+
}
|
|
121350
121795
|
function toFixFindings(items) {
|
|
121351
121796
|
return items.map((item) => ({
|
|
121352
121797
|
id: item.key,
|
|
@@ -121371,6 +121816,7 @@ var init_fix_input = __esm(() => {
|
|
|
121371
121816
|
init_zod();
|
|
121372
121817
|
init_logger2();
|
|
121373
121818
|
init_prompts();
|
|
121819
|
+
init_carried_findings();
|
|
121374
121820
|
init_checkout();
|
|
121375
121821
|
init_git3();
|
|
121376
121822
|
init_post();
|
|
@@ -122024,6 +122470,27 @@ var init_ci_wait = __esm(() => {
|
|
|
122024
122470
|
NO_CHECKS = /no checks reported/i;
|
|
122025
122471
|
});
|
|
122026
122472
|
|
|
122473
|
+
// src/bot/carried-hold.ts
|
|
122474
|
+
function carriedReadiness(own, headSha, blocking) {
|
|
122475
|
+
if (pendingCarryWidenComments(own).length > 0)
|
|
122476
|
+
return { kind: "held", reason: CARRY_INCOMPLETE_HOLD };
|
|
122477
|
+
const comment = carriedRecordComment(own, headSha);
|
|
122478
|
+
if (comment === undefined)
|
|
122479
|
+
return { kind: "keys", keys: [] };
|
|
122480
|
+
const record = parseCarriedRecord(comment.comment.body);
|
|
122481
|
+
if (record === null || record.headSha !== headSha)
|
|
122482
|
+
return { kind: "held", reason: CARRY_UNREADABLE_HOLD };
|
|
122483
|
+
return {
|
|
122484
|
+
kind: "keys",
|
|
122485
|
+
keys: record.findings.filter((entry) => isBlockingFinding(entry, blocking)).map(({ key }) => key)
|
|
122486
|
+
};
|
|
122487
|
+
}
|
|
122488
|
+
var CARRY_INCOMPLETE_HOLD = "carried finding coverage is incomplete; a complete full bot review (nax bot review --full) decides readiness", CARRY_UNREADABLE_HOLD = "the carried findings record of this head cannot be read; a complete full bot review decides readiness";
|
|
122489
|
+
var init_carried_hold = __esm(() => {
|
|
122490
|
+
init_blocking_findings();
|
|
122491
|
+
init_carried_record();
|
|
122492
|
+
});
|
|
122493
|
+
|
|
122027
122494
|
// src/workflow/ci-waiver.ts
|
|
122028
122495
|
function parseWaiverReason(raw) {
|
|
122029
122496
|
const reason = raw.trim();
|
|
@@ -122044,7 +122511,7 @@ function invalidReason(why, context) {
|
|
|
122044
122511
|
...context
|
|
122045
122512
|
});
|
|
122046
122513
|
}
|
|
122047
|
-
function
|
|
122514
|
+
function heading3(headSha, count) {
|
|
122048
122515
|
return `CI waiver at ${headSha}: ${count} check(s) never got a runner`;
|
|
122049
122516
|
}
|
|
122050
122517
|
function checkLine(name) {
|
|
@@ -122053,7 +122520,7 @@ function checkLine(name) {
|
|
|
122053
122520
|
}
|
|
122054
122521
|
function renderCiWaiver(waiver) {
|
|
122055
122522
|
const lines = [
|
|
122056
|
-
|
|
122523
|
+
heading3(waiver.headSha, waiver.checks.length),
|
|
122057
122524
|
...waiver.checks.map(checkLine),
|
|
122058
122525
|
`${REASON_PREFIX}${neutralise(waiver.reason)}`
|
|
122059
122526
|
];
|
|
@@ -122073,10 +122540,10 @@ function checkLines(lines) {
|
|
|
122073
122540
|
}
|
|
122074
122541
|
function parseCiWaiver(body) {
|
|
122075
122542
|
const lines = stripNaxBotMarkers(body).split(/\r?\n/);
|
|
122076
|
-
const start = lines.findIndex((line) =>
|
|
122543
|
+
const start = lines.findIndex((line) => HEADING3.test(line));
|
|
122077
122544
|
if (start === -1)
|
|
122078
122545
|
return null;
|
|
122079
|
-
const [, headSha, declared] =
|
|
122546
|
+
const [, headSha, declared] = HEADING3.exec(lines[start] ?? "") ?? [];
|
|
122080
122547
|
if (headSha === undefined || declared === undefined)
|
|
122081
122548
|
return null;
|
|
122082
122549
|
const { checks, rest } = checkLines(lines.slice(start + 1));
|
|
@@ -122098,12 +122565,12 @@ function latestCiWaiver(comments, login) {
|
|
|
122098
122565
|
}
|
|
122099
122566
|
return null;
|
|
122100
122567
|
}
|
|
122101
|
-
var CI_WAIVER_KEY = "w-ci-waiver", CI_WAIVER_REASON_MAX = 300,
|
|
122568
|
+
var CI_WAIVER_KEY = "w-ci-waiver", CI_WAIVER_REASON_MAX = 300, HEADING3, CHECK_LINE, REASON_PREFIX = "Reason: ", UNNAMED_CHECK = "(unnamed check)", LINE_BREAK5, REASON_LINE_BREAK, REASON_MARKER = "<!--";
|
|
122102
122569
|
var init_ci_waiver = __esm(() => {
|
|
122103
122570
|
init_errors4();
|
|
122104
122571
|
init_forge();
|
|
122105
122572
|
init_pr_body_safe();
|
|
122106
|
-
|
|
122573
|
+
HEADING3 = /^CI waiver at ([0-9A-Fa-f]{40}): (\d+) check\(s\) never got a runner$/;
|
|
122107
122574
|
CHECK_LINE = /^- `(.*)`$/;
|
|
122108
122575
|
LINE_BREAK5 = /[\r\n]+/g;
|
|
122109
122576
|
REASON_LINE_BREAK = /[\r\n]/;
|
|
@@ -122358,18 +122825,6 @@ var init_fix_summary = __esm(() => {
|
|
|
122358
122825
|
init_render2();
|
|
122359
122826
|
});
|
|
122360
122827
|
|
|
122361
|
-
// src/bot/review-blocking.ts
|
|
122362
|
-
function reviewBlockingTriggers(env) {
|
|
122363
|
-
return env.review.blockingTriggers ?? env.codeReview?.blockingTriggers ?? configuredBlockingTriggers(env.config);
|
|
122364
|
-
}
|
|
122365
|
-
function hasPushWorthyItem(env) {
|
|
122366
|
-
const blocking = reviewBlockingTriggers(env);
|
|
122367
|
-
return env.review.agreed.some((item) => item.kind !== "finding" || isBlockingFinding(item, blocking));
|
|
122368
|
-
}
|
|
122369
|
-
var init_review_blocking = __esm(() => {
|
|
122370
|
-
init_blocking_findings();
|
|
122371
|
-
});
|
|
122372
|
-
|
|
122373
122828
|
// src/bot/fix-summary-body.ts
|
|
122374
122829
|
function pushEntry2(env, state) {
|
|
122375
122830
|
if (state.outcome !== "pushed" || state.pushedSha === undefined)
|
|
@@ -122378,11 +122833,15 @@ function pushEntry2(env, state) {
|
|
|
122378
122833
|
base: env.info.headSha,
|
|
122379
122834
|
sha: state.pushedSha,
|
|
122380
122835
|
at: new Date().toISOString(),
|
|
122381
|
-
items: env.review.agreed.map((item) =>
|
|
122382
|
-
|
|
122383
|
-
|
|
122384
|
-
|
|
122385
|
-
|
|
122836
|
+
items: env.review.agreed.map((item) => {
|
|
122837
|
+
const raisedBy = item.kind !== "finding" ? undefined : state.reusedFix === undefined ? item.raisedBy : state.reusedFindingProvenance?.find(({ key }) => key === item.key)?.raisedBy;
|
|
122838
|
+
return {
|
|
122839
|
+
key: item.key,
|
|
122840
|
+
generation: item.kind === "finding" ? item.lineage?.generation ?? 0 : 0,
|
|
122841
|
+
issue: ledgerIssue(item.issue),
|
|
122842
|
+
...raisedBy === undefined ? {} : { raisedBy }
|
|
122843
|
+
};
|
|
122844
|
+
})
|
|
122386
122845
|
};
|
|
122387
122846
|
}
|
|
122388
122847
|
function outOfItemDetail(env, state) {
|
|
@@ -122791,6 +123250,9 @@ async function workflowReadyHold(env, state) {
|
|
|
122791
123250
|
const { info, user, comments, outcome } = await readReadyRulings(env);
|
|
122792
123251
|
if (info.headSha !== expectedSha)
|
|
122793
123252
|
return { held: "PR head changed since this execution" };
|
|
123253
|
+
const findings = await openFindingHold({ ...env, own: ownComments(comments, user.login) });
|
|
123254
|
+
if (findings)
|
|
123255
|
+
return { held: findings };
|
|
122794
123256
|
const ready = workflowPrReadiness({
|
|
122795
123257
|
outcome,
|
|
122796
123258
|
ci,
|
|
@@ -122900,7 +123362,12 @@ async function openKeys(env, keys) {
|
|
|
122900
123362
|
}
|
|
122901
123363
|
async function openFindingHold(env) {
|
|
122902
123364
|
const review = readinessReview(env);
|
|
122903
|
-
const
|
|
123365
|
+
const blocking = reviewBlockingTriggers(env);
|
|
123366
|
+
const carried = carriedReadiness(env.own, review.headSha, blocking);
|
|
123367
|
+
if (carried.kind === "held")
|
|
123368
|
+
return carried.reason;
|
|
123369
|
+
const reviewed = blockingKeys(review, blocking);
|
|
123370
|
+
const keys = await openKeys(env, [...reviewed, ...carried.keys.filter((key) => !reviewed.includes(key))]);
|
|
122904
123371
|
if (keys.length === 0)
|
|
122905
123372
|
return;
|
|
122906
123373
|
const hidden = keys.length - READY_HOLD_FINDINGS_SHOWN;
|
|
@@ -122916,6 +123383,16 @@ async function plainReadyHold(env, state) {
|
|
|
122916
123383
|
const held = await readyHeadHold(env, state);
|
|
122917
123384
|
if (held !== undefined)
|
|
122918
123385
|
return { held };
|
|
123386
|
+
try {
|
|
123387
|
+
const comments = await _fixReportDeps.listPrComments(env.ref, env.forge, env.repoRoot);
|
|
123388
|
+
const findings = await openFindingHold({ ...env, own: ownComments(comments, env.user.login) });
|
|
123389
|
+
if (findings)
|
|
123390
|
+
return { held: findings };
|
|
123391
|
+
} catch (error) {
|
|
123392
|
+
env.ctx.callCtx.runtime.signal.throwIfAborted();
|
|
123393
|
+
getLogger2()?.warn("bot-fix", "Could not re-read carried findings after CI", { error: errorMessage(error) });
|
|
123394
|
+
return { held: "carried findings could not be re-read after CI" };
|
|
123395
|
+
}
|
|
122919
123396
|
const waiver = await recordCiWaiver({ env, state, ci, post: _fixReportDeps.postPrComment });
|
|
122920
123397
|
if (waiver.held !== undefined || waiver.ciWaived === undefined)
|
|
122921
123398
|
return waiver;
|
|
@@ -122998,6 +123475,7 @@ var init_fix_report = __esm(() => {
|
|
|
122998
123475
|
init_decisions_sidecar();
|
|
122999
123476
|
init_item_threads();
|
|
123000
123477
|
init_promote();
|
|
123478
|
+
init_carried_hold();
|
|
123001
123479
|
init_ci_waiver_ready();
|
|
123002
123480
|
init_coverage_record();
|
|
123003
123481
|
init_fix_summary_body();
|
|
@@ -124617,6 +125095,214 @@ var init_lineage = __esm(() => {
|
|
|
124617
125095
|
BLAMED_SHA = /^[0-9a-f]{40}$/;
|
|
124618
125096
|
});
|
|
124619
125097
|
|
|
125098
|
+
// src/bot/review-advance.ts
|
|
125099
|
+
function heldBy(posted) {
|
|
125100
|
+
if (posted.coverageRecordFailed === true)
|
|
125101
|
+
return "coverage record";
|
|
125102
|
+
if (posted.carriedRecordFailed === true)
|
|
125103
|
+
return "carried findings record";
|
|
125104
|
+
return;
|
|
125105
|
+
}
|
|
125106
|
+
function mayAdvance(input) {
|
|
125107
|
+
if (input.posted === undefined || input.posted.failed > 0)
|
|
125108
|
+
return false;
|
|
125109
|
+
if ((input.unreadFiles?.length ?? 0) > 0)
|
|
125110
|
+
return false;
|
|
125111
|
+
if (input.reviewedIndex === undefined)
|
|
125112
|
+
return false;
|
|
125113
|
+
return input.scope !== "conversation-only";
|
|
125114
|
+
}
|
|
125115
|
+
async function advanceAfterReview(input) {
|
|
125116
|
+
if (!mayAdvance(input))
|
|
125117
|
+
return false;
|
|
125118
|
+
const held = heldBy(input.posted);
|
|
125119
|
+
if (held !== undefined) {
|
|
125120
|
+
getLogger2().warn("bot", `Reviewed head held: ${held} did not land`, { pr: input.ref.number });
|
|
125121
|
+
return false;
|
|
125122
|
+
}
|
|
125123
|
+
const outcome = await input.advance({
|
|
125124
|
+
ref: input.ref,
|
|
125125
|
+
login: input.login,
|
|
125126
|
+
expectedHead: input.reviewedIndex?.reviewedHead,
|
|
125127
|
+
head: input.head,
|
|
125128
|
+
base: input.mergeBase,
|
|
125129
|
+
deps: input.deps,
|
|
125130
|
+
cwd: input.cwd
|
|
125131
|
+
});
|
|
125132
|
+
getLogger2().info("bot", "Reviewed head advance", { pr: input.ref.number, outcome: outcome.kind });
|
|
125133
|
+
return outcome.kind === "advanced" || outcome.kind === "unchanged";
|
|
125134
|
+
}
|
|
125135
|
+
var init_review_advance = __esm(() => {
|
|
125136
|
+
init_logger2();
|
|
125137
|
+
});
|
|
125138
|
+
|
|
125139
|
+
// src/bot/review-rulings.ts
|
|
125140
|
+
function itemStatus(outcome) {
|
|
125141
|
+
if (outcome.index === undefined)
|
|
125142
|
+
return;
|
|
125143
|
+
const settled = new Set(outcome.settled.map(({ key }) => key));
|
|
125144
|
+
const total = outcome.index.keys.length;
|
|
125145
|
+
return {
|
|
125146
|
+
recorded: outcome.recorded.map(({ itemId, disposition, by }) => ({ id: itemId, disposition, by })),
|
|
125147
|
+
open: total - outcome.index.keys.filter((key) => settled.has(key)).length,
|
|
125148
|
+
total
|
|
125149
|
+
};
|
|
125150
|
+
}
|
|
125151
|
+
function confirmedItems(outcome, login) {
|
|
125152
|
+
return (outcome.confirmedWork ?? []).map(({ thread, ruling }) => ({
|
|
125153
|
+
reason: ruling.reason,
|
|
125154
|
+
thread: {
|
|
125155
|
+
...thread,
|
|
125156
|
+
comments: thread.comments.filter((comment, index) => index === 0 || comment.author === login)
|
|
125157
|
+
}
|
|
125158
|
+
}));
|
|
125159
|
+
}
|
|
125160
|
+
function unappliedReport(file, reason = "unknown-item") {
|
|
125161
|
+
return { applied: [], skipped: file.rulings.map(({ item }) => ({ item, reason })) };
|
|
125162
|
+
}
|
|
125163
|
+
function callerGate(file, staticMode, raw) {
|
|
125164
|
+
if (!file)
|
|
125165
|
+
return { kind: "apply" };
|
|
125166
|
+
if (staticMode) {
|
|
125167
|
+
getLogger2().warn("bot", "Ignoring caller rulings: the PR is untrusted", { pr: raw.ref.number });
|
|
125168
|
+
return { kind: "early", result: { callerRulings: ignoredCallerRulings("untrusted-pr") } };
|
|
125169
|
+
}
|
|
125170
|
+
if (!hasNaxWorkflowMarker(raw.info.body))
|
|
125171
|
+
return { kind: "early", result: { callerRulings: unappliedReport(file) } };
|
|
125172
|
+
if (file.headSha.toLowerCase() !== raw.info.headSha.toLowerCase()) {
|
|
125173
|
+
getLogger2().warn("bot", "Ignoring caller rulings: made against a different head", { pr: raw.ref.number });
|
|
125174
|
+
return { kind: "ignored", report: ignoredCallerRulings("head-mismatch") };
|
|
125175
|
+
}
|
|
125176
|
+
return { kind: "apply", rulings: file.rulings };
|
|
125177
|
+
}
|
|
125178
|
+
function failedReport2(file, error) {
|
|
125179
|
+
return error instanceof CallerRecordingError ? error.callerRulings : unappliedReport(file, "recorder-failed");
|
|
125180
|
+
}
|
|
125181
|
+
function settledEntry(item) {
|
|
125182
|
+
const opener = item.thread.comments[0]?.body ?? "";
|
|
125183
|
+
const files = parseItemFiles(opener);
|
|
125184
|
+
return {
|
|
125185
|
+
id: item.itemId,
|
|
125186
|
+
kind: item.kind,
|
|
125187
|
+
issue: parseItemOpener(opener)?.issue ?? earlierIssue(item.thread),
|
|
125188
|
+
disposition: item.ruling.disposition,
|
|
125189
|
+
reason: item.ruling.reason,
|
|
125190
|
+
...item.ruling.sha !== undefined && { sha: item.ruling.sha },
|
|
125191
|
+
...files.length > 0 && { files }
|
|
125192
|
+
};
|
|
125193
|
+
}
|
|
125194
|
+
async function readReviewRulings(input, record) {
|
|
125195
|
+
const { staticMode, ctx, callerRulings: file, ...raw } = input;
|
|
125196
|
+
const gate = callerGate(file, staticMode, raw);
|
|
125197
|
+
if (gate.kind === "early")
|
|
125198
|
+
return gate.result;
|
|
125199
|
+
if (staticMode || !hasNaxWorkflowMarker(raw.info.body))
|
|
125200
|
+
return {};
|
|
125201
|
+
try {
|
|
125202
|
+
const outcome = await record({
|
|
125203
|
+
...raw,
|
|
125204
|
+
readModel: rulingModelReader(ctx),
|
|
125205
|
+
...gate.kind === "apply" && gate.rulings ? { callerRulings: gate.rulings } : {}
|
|
125206
|
+
});
|
|
125207
|
+
return {
|
|
125208
|
+
...file === undefined ? {} : { callerRulings: gate.kind === "ignored" ? gate.report : outcome.callerRulings ?? unappliedReport(file) },
|
|
125209
|
+
reviewedIndex: outcome.index,
|
|
125210
|
+
...outcome.index === undefined ? {} : { itemStatus: itemStatus(outcome) },
|
|
125211
|
+
...outcome.confirmedWork?.length ? { itemConfirmed: confirmedItems(outcome, raw.login) } : {},
|
|
125212
|
+
settled: [...outcome.settled, ...outcome.confirmedWork ?? []].map(settledEntry),
|
|
125213
|
+
itemEarlier: rulingEarlier(outcome, raw.login),
|
|
125214
|
+
rulings: {
|
|
125215
|
+
recorded: outcome.recorded.length,
|
|
125216
|
+
open: outcome.open.length + (outcome.confirmedWork?.length ?? 0),
|
|
125217
|
+
asked: outcome.asked
|
|
125218
|
+
}
|
|
125219
|
+
};
|
|
125220
|
+
} catch (error) {
|
|
125221
|
+
getLogger2().warn("bot", "Could not record PR rulings", { pr: raw.ref.number, error: errorMessage(error) });
|
|
125222
|
+
if (!file)
|
|
125223
|
+
return {};
|
|
125224
|
+
return { callerRulings: gate.kind === "ignored" ? gate.report : failedReport2(file, error) };
|
|
125225
|
+
}
|
|
125226
|
+
}
|
|
125227
|
+
function rulingEarlier(outcome, login) {
|
|
125228
|
+
return outcome.open.flatMap((item) => {
|
|
125229
|
+
if (item.kind !== "finding" && item.kind !== "ruling")
|
|
125230
|
+
return [];
|
|
125231
|
+
const own = new Set(ownComments(item.thread.comments, login).map(({ comment }) => comment.id));
|
|
125232
|
+
const kept = new Set(item.kept.map(({ id }) => id));
|
|
125233
|
+
return [
|
|
125234
|
+
{
|
|
125235
|
+
...item.thread,
|
|
125236
|
+
comments: item.thread.comments.filter((comment, index) => index === 0 || own.has(comment.id) || kept.has(comment.id))
|
|
125237
|
+
}
|
|
125238
|
+
];
|
|
125239
|
+
});
|
|
125240
|
+
}
|
|
125241
|
+
function reviewScopeOf(input) {
|
|
125242
|
+
if (input.conversationOnly === true)
|
|
125243
|
+
return "conversation-only";
|
|
125244
|
+
if (input.rangeBase !== undefined && input.rangeBase !== input.mergeBase)
|
|
125245
|
+
return "incremental";
|
|
125246
|
+
return "full";
|
|
125247
|
+
}
|
|
125248
|
+
async function reviewRange(input, isAncestor) {
|
|
125249
|
+
const { index, checkout, head } = input;
|
|
125250
|
+
const full = { rangeBase: checkout.mergeBase };
|
|
125251
|
+
const reviewedHead = index?.reviewedHead;
|
|
125252
|
+
const reviewedBase = index?.reviewedBase;
|
|
125253
|
+
if (!reviewedHead || !reviewedBase || !/^[a-fA-F0-9]{40}$/.test(reviewedHead) || !/^[a-fA-F0-9]{40}$/.test(reviewedBase))
|
|
125254
|
+
return full;
|
|
125255
|
+
try {
|
|
125256
|
+
if (!await isAncestor(checkout.worktree, reviewedHead, head))
|
|
125257
|
+
return full;
|
|
125258
|
+
if (!await isAncestor(checkout.worktree, reviewedBase, checkout.mergeBase))
|
|
125259
|
+
return full;
|
|
125260
|
+
return reviewedHead === head ? { rangeBase: reviewedHead, conversationOnly: true } : { rangeBase: reviewedHead };
|
|
125261
|
+
} catch (error) {
|
|
125262
|
+
getLogger2().warn("bot", "Could not check reviewed ancestry; reviewing full range", { error: errorMessage(error) });
|
|
125263
|
+
return full;
|
|
125264
|
+
}
|
|
125265
|
+
}
|
|
125266
|
+
var init_review_rulings = __esm(() => {
|
|
125267
|
+
init_internal();
|
|
125268
|
+
init_forge();
|
|
125269
|
+
init_logger2();
|
|
125270
|
+
init_item_threads();
|
|
125271
|
+
init_caller_rulings();
|
|
125272
|
+
init_post_earlier();
|
|
125273
|
+
init_ruling_reader();
|
|
125274
|
+
});
|
|
125275
|
+
|
|
125276
|
+
// src/bot/review-carry.ts
|
|
125277
|
+
function scopeOf2(range, mergeBase) {
|
|
125278
|
+
return reviewScopeOf({ ...range, mergeBase });
|
|
125279
|
+
}
|
|
125280
|
+
async function reviewCarry(input) {
|
|
125281
|
+
const full = { rangeBase: input.checkout.mergeBase };
|
|
125282
|
+
const range = input.full ? full : await reviewRange({ index: input.index, checkout: input.checkout, head: input.head }, input.isAncestor);
|
|
125283
|
+
const scope = scopeOf2(range, input.checkout.mergeBase);
|
|
125284
|
+
const carry = await earlierCarriedFindings({
|
|
125285
|
+
outputDir: input.outputDir,
|
|
125286
|
+
ref: input.ref,
|
|
125287
|
+
index: input.index,
|
|
125288
|
+
scope,
|
|
125289
|
+
rangeBase: range.rangeBase,
|
|
125290
|
+
own: input.own,
|
|
125291
|
+
load: input.load
|
|
125292
|
+
});
|
|
125293
|
+
if (!carry.widen)
|
|
125294
|
+
return { range, scope, carried: carry.findings };
|
|
125295
|
+
getLogger2().warn("bot", "Carried findings incomplete or unreadable; reviewing the full range", {
|
|
125296
|
+
pr: input.ref.number
|
|
125297
|
+
});
|
|
125298
|
+
return { range: full, scope: scopeOf2(full, input.checkout.mergeBase), carried: [] };
|
|
125299
|
+
}
|
|
125300
|
+
var init_review_carry = __esm(() => {
|
|
125301
|
+
init_logger2();
|
|
125302
|
+
init_carried_findings();
|
|
125303
|
+
init_review_rulings();
|
|
125304
|
+
});
|
|
125305
|
+
|
|
124620
125306
|
// src/bot/review-convergence.ts
|
|
124621
125307
|
function reviewConvergence(input) {
|
|
124622
125308
|
const effective = effectiveBlockingTriggers({
|
|
@@ -124664,6 +125350,14 @@ async function reviewHistory(input) {
|
|
|
124664
125350
|
return { botPushes };
|
|
124665
125351
|
return { botPushes, inRange: await pushesInRange(input, input.rangeBase, botPushes) };
|
|
124666
125352
|
}
|
|
125353
|
+
async function reviewPushFacts(input) {
|
|
125354
|
+
const history = await reviewHistory(input);
|
|
125355
|
+
const inRange = history.inRange ?? [];
|
|
125356
|
+
return {
|
|
125357
|
+
prompt: inRange.length > 0 ? { botPushes: inRange } : {},
|
|
125358
|
+
post: history.botPushes.length > 0 ? { botPushes: history.botPushes, worktree: input.worktree, carriedFixPushes: inRange } : {}
|
|
125359
|
+
};
|
|
125360
|
+
}
|
|
124667
125361
|
var init_review_convergence = __esm(() => {
|
|
124668
125362
|
init_logger2();
|
|
124669
125363
|
init_blocking_findings();
|
|
@@ -124887,143 +125581,6 @@ var init_story_review = __esm(() => {
|
|
|
124887
125581
|
init_step_context();
|
|
124888
125582
|
});
|
|
124889
125583
|
|
|
124890
|
-
// src/bot/review-rulings.ts
|
|
124891
|
-
function itemStatus(outcome) {
|
|
124892
|
-
if (outcome.index === undefined)
|
|
124893
|
-
return;
|
|
124894
|
-
const settled = new Set(outcome.settled.map(({ key }) => key));
|
|
124895
|
-
const total = outcome.index.keys.length;
|
|
124896
|
-
return {
|
|
124897
|
-
recorded: outcome.recorded.map(({ itemId, disposition, by }) => ({ id: itemId, disposition, by })),
|
|
124898
|
-
open: total - outcome.index.keys.filter((key) => settled.has(key)).length,
|
|
124899
|
-
total
|
|
124900
|
-
};
|
|
124901
|
-
}
|
|
124902
|
-
function confirmedItems(outcome, login) {
|
|
124903
|
-
return (outcome.confirmedWork ?? []).map(({ thread, ruling }) => ({
|
|
124904
|
-
reason: ruling.reason,
|
|
124905
|
-
thread: {
|
|
124906
|
-
...thread,
|
|
124907
|
-
comments: thread.comments.filter((comment, index) => index === 0 || comment.author === login)
|
|
124908
|
-
}
|
|
124909
|
-
}));
|
|
124910
|
-
}
|
|
124911
|
-
function unappliedReport(file, reason = "unknown-item") {
|
|
124912
|
-
return { applied: [], skipped: file.rulings.map(({ item }) => ({ item, reason })) };
|
|
124913
|
-
}
|
|
124914
|
-
function callerGate(file, staticMode, raw) {
|
|
124915
|
-
if (!file)
|
|
124916
|
-
return { kind: "apply" };
|
|
124917
|
-
if (staticMode) {
|
|
124918
|
-
getLogger2().warn("bot", "Ignoring caller rulings: the PR is untrusted", { pr: raw.ref.number });
|
|
124919
|
-
return { kind: "early", result: { callerRulings: ignoredCallerRulings("untrusted-pr") } };
|
|
124920
|
-
}
|
|
124921
|
-
if (!hasNaxWorkflowMarker(raw.info.body))
|
|
124922
|
-
return { kind: "early", result: { callerRulings: unappliedReport(file) } };
|
|
124923
|
-
if (file.headSha.toLowerCase() !== raw.info.headSha.toLowerCase()) {
|
|
124924
|
-
getLogger2().warn("bot", "Ignoring caller rulings: made against a different head", { pr: raw.ref.number });
|
|
124925
|
-
return { kind: "ignored", report: ignoredCallerRulings("head-mismatch") };
|
|
124926
|
-
}
|
|
124927
|
-
return { kind: "apply", rulings: file.rulings };
|
|
124928
|
-
}
|
|
124929
|
-
function failedReport2(file, error) {
|
|
124930
|
-
return error instanceof CallerRecordingError ? error.callerRulings : unappliedReport(file, "recorder-failed");
|
|
124931
|
-
}
|
|
124932
|
-
function settledEntry(item) {
|
|
124933
|
-
const opener = item.thread.comments[0]?.body ?? "";
|
|
124934
|
-
const files = parseItemFiles(opener);
|
|
124935
|
-
return {
|
|
124936
|
-
id: item.itemId,
|
|
124937
|
-
kind: item.kind,
|
|
124938
|
-
issue: parseItemOpener(opener)?.issue ?? earlierIssue(item.thread),
|
|
124939
|
-
disposition: item.ruling.disposition,
|
|
124940
|
-
reason: item.ruling.reason,
|
|
124941
|
-
...item.ruling.sha !== undefined && { sha: item.ruling.sha },
|
|
124942
|
-
...files.length > 0 && { files }
|
|
124943
|
-
};
|
|
124944
|
-
}
|
|
124945
|
-
async function readReviewRulings(input, record) {
|
|
124946
|
-
const { staticMode, ctx, callerRulings: file, ...raw } = input;
|
|
124947
|
-
const gate = callerGate(file, staticMode, raw);
|
|
124948
|
-
if (gate.kind === "early")
|
|
124949
|
-
return gate.result;
|
|
124950
|
-
if (staticMode || !hasNaxWorkflowMarker(raw.info.body))
|
|
124951
|
-
return {};
|
|
124952
|
-
try {
|
|
124953
|
-
const outcome = await record({
|
|
124954
|
-
...raw,
|
|
124955
|
-
readModel: rulingModelReader(ctx),
|
|
124956
|
-
...gate.kind === "apply" && gate.rulings ? { callerRulings: gate.rulings } : {}
|
|
124957
|
-
});
|
|
124958
|
-
return {
|
|
124959
|
-
...file === undefined ? {} : { callerRulings: gate.kind === "ignored" ? gate.report : outcome.callerRulings ?? unappliedReport(file) },
|
|
124960
|
-
reviewedIndex: outcome.index,
|
|
124961
|
-
...outcome.index === undefined ? {} : { itemStatus: itemStatus(outcome) },
|
|
124962
|
-
...outcome.confirmedWork?.length ? { itemConfirmed: confirmedItems(outcome, raw.login) } : {},
|
|
124963
|
-
settled: [...outcome.settled, ...outcome.confirmedWork ?? []].map(settledEntry),
|
|
124964
|
-
itemEarlier: rulingEarlier(outcome, raw.login),
|
|
124965
|
-
rulings: {
|
|
124966
|
-
recorded: outcome.recorded.length,
|
|
124967
|
-
open: outcome.open.length + (outcome.confirmedWork?.length ?? 0),
|
|
124968
|
-
asked: outcome.asked
|
|
124969
|
-
}
|
|
124970
|
-
};
|
|
124971
|
-
} catch (error) {
|
|
124972
|
-
getLogger2().warn("bot", "Could not record PR rulings", { pr: raw.ref.number, error: errorMessage(error) });
|
|
124973
|
-
if (!file)
|
|
124974
|
-
return {};
|
|
124975
|
-
return { callerRulings: gate.kind === "ignored" ? gate.report : failedReport2(file, error) };
|
|
124976
|
-
}
|
|
124977
|
-
}
|
|
124978
|
-
function rulingEarlier(outcome, login) {
|
|
124979
|
-
return outcome.open.flatMap((item) => {
|
|
124980
|
-
if (item.kind !== "finding" && item.kind !== "ruling")
|
|
124981
|
-
return [];
|
|
124982
|
-
const own = new Set(ownComments(item.thread.comments, login).map(({ comment }) => comment.id));
|
|
124983
|
-
const kept = new Set(item.kept.map(({ id }) => id));
|
|
124984
|
-
return [
|
|
124985
|
-
{
|
|
124986
|
-
...item.thread,
|
|
124987
|
-
comments: item.thread.comments.filter((comment, index) => index === 0 || own.has(comment.id) || kept.has(comment.id))
|
|
124988
|
-
}
|
|
124989
|
-
];
|
|
124990
|
-
});
|
|
124991
|
-
}
|
|
124992
|
-
function reviewScopeOf(input) {
|
|
124993
|
-
if (input.conversationOnly === true)
|
|
124994
|
-
return "conversation-only";
|
|
124995
|
-
if (input.rangeBase !== undefined && input.rangeBase !== input.mergeBase)
|
|
124996
|
-
return "incremental";
|
|
124997
|
-
return "full";
|
|
124998
|
-
}
|
|
124999
|
-
async function reviewRange(input, isAncestor) {
|
|
125000
|
-
const { index, checkout, head } = input;
|
|
125001
|
-
const full = { rangeBase: checkout.mergeBase };
|
|
125002
|
-
const reviewedHead = index?.reviewedHead;
|
|
125003
|
-
const reviewedBase = index?.reviewedBase;
|
|
125004
|
-
if (!reviewedHead || !reviewedBase || !/^[a-fA-F0-9]{40}$/.test(reviewedHead) || !/^[a-fA-F0-9]{40}$/.test(reviewedBase))
|
|
125005
|
-
return full;
|
|
125006
|
-
try {
|
|
125007
|
-
if (!await isAncestor(checkout.worktree, reviewedHead, head))
|
|
125008
|
-
return full;
|
|
125009
|
-
if (!await isAncestor(checkout.worktree, reviewedBase, checkout.mergeBase))
|
|
125010
|
-
return full;
|
|
125011
|
-
return reviewedHead === head ? { rangeBase: reviewedHead, conversationOnly: true } : { rangeBase: reviewedHead };
|
|
125012
|
-
} catch (error) {
|
|
125013
|
-
getLogger2().warn("bot", "Could not check reviewed ancestry; reviewing full range", { error: errorMessage(error) });
|
|
125014
|
-
return full;
|
|
125015
|
-
}
|
|
125016
|
-
}
|
|
125017
|
-
var init_review_rulings = __esm(() => {
|
|
125018
|
-
init_internal();
|
|
125019
|
-
init_forge();
|
|
125020
|
-
init_logger2();
|
|
125021
|
-
init_item_threads();
|
|
125022
|
-
init_caller_rulings();
|
|
125023
|
-
init_post_earlier();
|
|
125024
|
-
init_ruling_reader();
|
|
125025
|
-
});
|
|
125026
|
-
|
|
125027
125584
|
// src/bot/review-step.ts
|
|
125028
125585
|
import { join as join162 } from "path";
|
|
125029
125586
|
async function writePackage(ctx, mergeBase, packagePath, staticMode) {
|
|
@@ -125135,6 +125692,64 @@ var init_review_step = __esm(() => {
|
|
|
125135
125692
|
_reviewStepDeps = { writeBranchReviewPackage };
|
|
125136
125693
|
});
|
|
125137
125694
|
|
|
125695
|
+
// src/bot/reviewed-head.ts
|
|
125696
|
+
function warn6(message, data) {
|
|
125697
|
+
getLogger2()?.warn("bot-reviewed-head", `[bot-reviewed-head] ${message}`, data);
|
|
125698
|
+
}
|
|
125699
|
+
async function readComments(input) {
|
|
125700
|
+
try {
|
|
125701
|
+
return await _reviewedHeadDeps.listPrComments(input.ref, input.deps, input.cwd);
|
|
125702
|
+
} catch (error) {
|
|
125703
|
+
warn6("Could not read the PR comments to advance the reviewed head", {
|
|
125704
|
+
pr: input.ref.number,
|
|
125705
|
+
error: errorMessage(error)
|
|
125706
|
+
});
|
|
125707
|
+
return null;
|
|
125708
|
+
}
|
|
125709
|
+
}
|
|
125710
|
+
async function writeIndex(input, comment, fresh) {
|
|
125711
|
+
const settled = parseItemIndexSettled(comment.body) ?? 0;
|
|
125712
|
+
const body = withNaxBotMarker(renderItemIndex({ ...fresh, reviewedHead: input.head, reviewedBase: input.base }, settled), "w-index");
|
|
125713
|
+
try {
|
|
125714
|
+
await _reviewedHeadDeps.editComment(input.ref, comment, body, input.deps, input.cwd);
|
|
125715
|
+
} catch (error) {
|
|
125716
|
+
warn6("Could not advance the reviewed head", { pr: input.ref.number, error: errorMessage(error) });
|
|
125717
|
+
return { kind: "failed" };
|
|
125718
|
+
}
|
|
125719
|
+
return { kind: "advanced" };
|
|
125720
|
+
}
|
|
125721
|
+
async function advanceReviewedHead(input) {
|
|
125722
|
+
if (!SHA_PATTERN2.test(input.head) || !SHA_PATTERN2.test(input.base)) {
|
|
125723
|
+
return { kind: "skipped", reason: "invalid-sha" };
|
|
125724
|
+
}
|
|
125725
|
+
const comments = await readComments(input);
|
|
125726
|
+
if (!comments)
|
|
125727
|
+
return { kind: "failed" };
|
|
125728
|
+
const read = readItemThreads([], comments, input.login);
|
|
125729
|
+
const fresh = read.index;
|
|
125730
|
+
if (!read.indexComment)
|
|
125731
|
+
return { kind: "skipped", reason: "no-index" };
|
|
125732
|
+
if (!fresh)
|
|
125733
|
+
return { kind: "skipped", reason: "unparseable" };
|
|
125734
|
+
if (fresh.reviewedHead !== input.expectedHead) {
|
|
125735
|
+
warn6("The item index moved; the reviewed head it names wins", { pr: input.ref.number });
|
|
125736
|
+
return { kind: "skipped", reason: "moved" };
|
|
125737
|
+
}
|
|
125738
|
+
if (fresh.reviewedHead === input.head && fresh.reviewedBase === input.base)
|
|
125739
|
+
return { kind: "unchanged" };
|
|
125740
|
+
return writeIndex(input, read.indexComment, fresh);
|
|
125741
|
+
}
|
|
125742
|
+
var _reviewedHeadDeps, SHA_PATTERN2;
|
|
125743
|
+
var init_reviewed_head = __esm(() => {
|
|
125744
|
+
init_internal();
|
|
125745
|
+
init_forge();
|
|
125746
|
+
init_logger2();
|
|
125747
|
+
init_item_thread_state();
|
|
125748
|
+
init_item_threads();
|
|
125749
|
+
_reviewedHeadDeps = { listPrComments, editComment };
|
|
125750
|
+
SHA_PATTERN2 = /^[a-fA-F0-9]{40}$/;
|
|
125751
|
+
});
|
|
125752
|
+
|
|
125138
125753
|
// src/hooks/runner.ts
|
|
125139
125754
|
import { join as join163 } from "path";
|
|
125140
125755
|
function captureStream(stream) {
|
|
@@ -132098,7 +132713,7 @@ var init_item_threads_reopen = __esm(() => {
|
|
|
132098
132713
|
|
|
132099
132714
|
// src/workflow/item-threads-post.ts
|
|
132100
132715
|
import { posix as posix6 } from "path";
|
|
132101
|
-
function
|
|
132716
|
+
function warn7(identity, message, error) {
|
|
132102
132717
|
getLogger2()?.warn(STAGE18, message, {
|
|
132103
132718
|
...typeof identity === "string" ? { itemId: identity } : identity,
|
|
132104
132719
|
...error === undefined ? {} : { error: errorMessage(error) }
|
|
@@ -132109,7 +132724,7 @@ async function attempt(item, post) {
|
|
|
132109
132724
|
await post();
|
|
132110
132725
|
return true;
|
|
132111
132726
|
} catch (error) {
|
|
132112
|
-
|
|
132727
|
+
warn7(item.id, "[item-threads] Posting attempt failed", error);
|
|
132113
132728
|
return false;
|
|
132114
132729
|
}
|
|
132115
132730
|
}
|
|
@@ -132128,7 +132743,7 @@ async function postItem(item, context) {
|
|
|
132128
132743
|
return true;
|
|
132129
132744
|
}
|
|
132130
132745
|
if (anchor === undefined && ref.forge === "github") {
|
|
132131
|
-
|
|
132746
|
+
warn7(item.id, "[item-threads] No changed file available for item anchor");
|
|
132132
132747
|
return false;
|
|
132133
132748
|
}
|
|
132134
132749
|
return attempt(item, () => postFile(anchor ?? ""));
|
|
@@ -132146,14 +132761,14 @@ async function indexIsMissing(options) {
|
|
|
132146
132761
|
const comments = await listPrComments(context.ref, context.deps, context.cwd);
|
|
132147
132762
|
return !ownComments(comments, context.login).some(({ key }) => key === "w-index");
|
|
132148
132763
|
} catch (error) {
|
|
132149
|
-
|
|
132764
|
+
warn7({ feature }, "[item-threads] Cannot confirm the index state; reading the failed write instead", error);
|
|
132150
132765
|
return failure === "refused" && !context.indexWriteUnconfirmed ? true : undefined;
|
|
132151
132766
|
}
|
|
132152
132767
|
}
|
|
132153
132768
|
async function readContext(input, deps) {
|
|
132154
132769
|
const number = prNumberFromUrl(input.url);
|
|
132155
132770
|
if (number === null) {
|
|
132156
|
-
|
|
132771
|
+
warn7({ feature: input.feature }, "[item-threads] Cannot read PR number from URL");
|
|
132157
132772
|
return null;
|
|
132158
132773
|
}
|
|
132159
132774
|
try {
|
|
@@ -132166,7 +132781,7 @@ async function readContext(input, deps) {
|
|
|
132166
132781
|
]);
|
|
132167
132782
|
return { ref, info, login: user.login, read: readItemThreads(threads, comments, user.login) };
|
|
132168
132783
|
} catch (error) {
|
|
132169
|
-
|
|
132784
|
+
warn7({ feature: input.feature }, "[item-threads] Initial PR read failed; posting nothing", error);
|
|
132170
132785
|
return null;
|
|
132171
132786
|
}
|
|
132172
132787
|
}
|
|
@@ -132184,7 +132799,7 @@ async function postItemThreads(input, deps = _featureDeps.forge) {
|
|
|
132184
132799
|
for (const [index, item] of items.entries()) {
|
|
132185
132800
|
const key = itemKey(item);
|
|
132186
132801
|
if (!isPostable(item)) {
|
|
132187
|
-
|
|
132802
|
+
warn7(item.id, "[item-threads] Skipping non-postable item");
|
|
132188
132803
|
outcome.skipped++;
|
|
132189
132804
|
} else if (owned.has(key)) {
|
|
132190
132805
|
outcome.skipped++;
|
|
@@ -145229,11 +145844,13 @@ var init_review_deps = __esm(() => {
|
|
|
145229
145844
|
init_checkout_in_place();
|
|
145230
145845
|
init_checks4();
|
|
145231
145846
|
init_finding_rulings();
|
|
145847
|
+
init_fix_input();
|
|
145232
145848
|
init_gate_baseline();
|
|
145233
145849
|
init_git3();
|
|
145234
145850
|
init_log();
|
|
145235
145851
|
init_post();
|
|
145236
145852
|
init_review_step();
|
|
145853
|
+
init_reviewed_head();
|
|
145237
145854
|
init_rulings();
|
|
145238
145855
|
init_run_setup2();
|
|
145239
145856
|
_botReviewDeps = {
|
|
@@ -145288,6 +145905,8 @@ var init_review_deps = __esm(() => {
|
|
|
145288
145905
|
recordPrRulings,
|
|
145289
145906
|
recordFindingRulings,
|
|
145290
145907
|
postPrReview,
|
|
145908
|
+
advanceReviewedHead,
|
|
145909
|
+
loadLatestCarry,
|
|
145291
145910
|
async writeJson(path, value) {
|
|
145292
145911
|
await Bun.write(path, `${JSON.stringify(value, null, 2)}
|
|
145293
145912
|
`);
|
|
@@ -145336,17 +145955,6 @@ var init_review_triage = __esm(() => {
|
|
|
145336
145955
|
|
|
145337
145956
|
// src/bot/review-run.ts
|
|
145338
145957
|
import { join as join190 } from "path";
|
|
145339
|
-
function incrementalBase(scope, range) {
|
|
145340
|
-
return scope === "incremental" ? range.rangeBase : undefined;
|
|
145341
|
-
}
|
|
145342
|
-
async function reviewPushFacts(input) {
|
|
145343
|
-
const history = await reviewHistory({ ...input, isAncestor: _botReviewDeps.isAncestor });
|
|
145344
|
-
const inRange = history.inRange ?? [];
|
|
145345
|
-
return {
|
|
145346
|
-
prompt: inRange.length > 0 ? { botPushes: inRange } : {},
|
|
145347
|
-
post: history.botPushes.length > 0 ? { botPushes: history.botPushes, worktree: input.worktree } : {}
|
|
145348
|
-
};
|
|
145349
|
-
}
|
|
145350
145958
|
async function reviewLineage(post, verdict) {
|
|
145351
145959
|
const { botPushes, worktree } = post;
|
|
145352
145960
|
if (botPushes === undefined || botPushes.length === 0 || worktree === undefined)
|
|
@@ -145475,18 +146083,30 @@ async function reviewEnvironment(input, prepared, context) {
|
|
|
145475
146083
|
setupFailed: preparation.preRunFailed ?? preparation.buildFailed,
|
|
145476
146084
|
ciFiles: await listCiConfigFiles(checkout.worktree)
|
|
145477
146085
|
});
|
|
145478
|
-
const range
|
|
145479
|
-
|
|
146086
|
+
const { range, scope, carried } = await reviewCarry({
|
|
146087
|
+
outputDir: context.outputDir,
|
|
146088
|
+
ref,
|
|
146089
|
+
own: items.own,
|
|
146090
|
+
index: reviewedIndex,
|
|
146091
|
+
full: input.full === true,
|
|
146092
|
+
checkout,
|
|
146093
|
+
head: info.headSha,
|
|
146094
|
+
load: _botReviewDeps.loadLatestCarry,
|
|
146095
|
+
isAncestor: _botReviewDeps.isAncestor
|
|
146096
|
+
});
|
|
145480
146097
|
const push = await reviewPushFacts({
|
|
146098
|
+
isAncestor: _botReviewDeps.isAncestor,
|
|
145481
146099
|
own: items.own,
|
|
145482
146100
|
worktree: checkout.worktree,
|
|
145483
146101
|
head: info.headSha,
|
|
145484
|
-
rangeBase:
|
|
146102
|
+
rangeBase: scope === "incremental" ? range.rangeBase : undefined
|
|
145485
146103
|
});
|
|
145486
146104
|
return {
|
|
145487
146105
|
...preparation,
|
|
145488
146106
|
cost: context.cost,
|
|
145489
146107
|
ctx,
|
|
146108
|
+
reviewedIndex,
|
|
146109
|
+
login: items.login,
|
|
145490
146110
|
review: {
|
|
145491
146111
|
mergeBase: checkout.mergeBase,
|
|
145492
146112
|
...range,
|
|
@@ -145527,6 +146147,7 @@ async function reviewEnvironment(input, prepared, context) {
|
|
|
145527
146147
|
...scope === "incremental" && { incrementalSince: range.rangeBase },
|
|
145528
146148
|
staticMode,
|
|
145529
146149
|
sensitive: sensitivePaths(checkout.changedFiles),
|
|
146150
|
+
carriedFindings: carried,
|
|
145530
146151
|
stateDir,
|
|
145531
146152
|
deps: _botReviewDeps.forge,
|
|
145532
146153
|
cwd: repoRoot,
|
|
@@ -145534,6 +146155,23 @@ async function reviewEnvironment(input, prepared, context) {
|
|
|
145534
146155
|
}
|
|
145535
146156
|
};
|
|
145536
146157
|
}
|
|
146158
|
+
async function advance(env, state) {
|
|
146159
|
+
const referenced = await advanceAfterReview({
|
|
146160
|
+
posted: state.posted,
|
|
146161
|
+
unreadFiles: state.unreadFiles,
|
|
146162
|
+
reviewedIndex: env.reviewedIndex,
|
|
146163
|
+
scope: env.post.scope,
|
|
146164
|
+
ref: env.post.ref,
|
|
146165
|
+
login: env.login,
|
|
146166
|
+
head: env.post.info.headSha,
|
|
146167
|
+
mergeBase: env.review.mergeBase,
|
|
146168
|
+
deps: _botReviewDeps.forge,
|
|
146169
|
+
cwd: env.post.cwd,
|
|
146170
|
+
advance: _botReviewDeps.advanceReviewedHead
|
|
146171
|
+
});
|
|
146172
|
+
if (referenced && env.post.scope === "full")
|
|
146173
|
+
await clearCarryWidens(env.post);
|
|
146174
|
+
}
|
|
145537
146175
|
async function executeReview(env, runtime) {
|
|
145538
146176
|
const state = await runStepGraph(BOT_REVIEW_GRAPH, env, { step: "review", timings: {} }, { persist: (value) => _botReviewDeps.writeJson(join190(env.post.stateDir, "bot-state.json"), value) }, {
|
|
145539
146177
|
aborted: () => runtime.signal.aborted,
|
|
@@ -145551,11 +146189,13 @@ async function executeReview(env, runtime) {
|
|
|
145551
146189
|
intent: state.verdict.intent,
|
|
145552
146190
|
quality
|
|
145553
146191
|
});
|
|
146192
|
+
const { coverageRecordFailed, carriedRecordFailed, ...posted } = state.posted;
|
|
146193
|
+
await advance(env, state);
|
|
145554
146194
|
return {
|
|
145555
146195
|
outcome: "posted",
|
|
145556
146196
|
spentUsd: env.cost.spentUsd(),
|
|
145557
146197
|
limitUsd: env.cost.limitUsd,
|
|
145558
|
-
...
|
|
146198
|
+
...posted,
|
|
145559
146199
|
intent: state.verdict.intent,
|
|
145560
146200
|
quality,
|
|
145561
146201
|
staticMode: env.review.staticMode,
|
|
@@ -145606,6 +146246,7 @@ async function reviewCheckout(input, prepared) {
|
|
|
145606
146246
|
checks,
|
|
145607
146247
|
ctx: context.ctx,
|
|
145608
146248
|
stateDir,
|
|
146249
|
+
outputDir: runtime.outputDir,
|
|
145609
146250
|
cost: botCostEnv(config, runtime, input.costLimitUsd)
|
|
145610
146251
|
});
|
|
145611
146252
|
const result = await executeReview(env, runtime);
|
|
@@ -145665,7 +146306,10 @@ var init_review_run = __esm(() => {
|
|
|
145665
146306
|
init_models2();
|
|
145666
146307
|
init_path_policy();
|
|
145667
146308
|
init_post();
|
|
146309
|
+
init_post_carried();
|
|
145668
146310
|
init_post_earlier();
|
|
146311
|
+
init_review_advance();
|
|
146312
|
+
init_review_carry();
|
|
145669
146313
|
init_review_convergence();
|
|
145670
146314
|
init_review_deps();
|
|
145671
146315
|
init_review_rulings();
|
|
@@ -145808,12 +146452,25 @@ async function reuseSavedFix(input) {
|
|
|
145808
146452
|
logFailure2("checkout", env.ref.number, result.stderr || `git exited ${result.exitCode}`);
|
|
145809
146453
|
return initial;
|
|
145810
146454
|
}
|
|
145811
|
-
return {
|
|
146455
|
+
return {
|
|
146456
|
+
step: "check",
|
|
146457
|
+
timings: {},
|
|
146458
|
+
reusedFix: entry.sha,
|
|
146459
|
+
fixSha: entry.sha,
|
|
146460
|
+
agreedCount: keys.length,
|
|
146461
|
+
...entry.findingProvenance === undefined ? {} : { reusedFindingProvenance: entry.findingProvenance }
|
|
146462
|
+
};
|
|
145812
146463
|
} catch (error) {
|
|
145813
146464
|
logFailure2("reuse", env.ref.number, error);
|
|
145814
146465
|
return initial;
|
|
145815
146466
|
}
|
|
145816
146467
|
}
|
|
146468
|
+
function findingProvenance(env, state) {
|
|
146469
|
+
if (state.reusedFix !== undefined)
|
|
146470
|
+
return state.reusedFindingProvenance?.slice();
|
|
146471
|
+
const entries = env.review.agreed.flatMap((item) => item.kind === "finding" && item.raisedBy !== undefined ? [{ key: item.key, raisedBy: item.raisedBy }] : []);
|
|
146472
|
+
return entries.length === 0 ? undefined : entries;
|
|
146473
|
+
}
|
|
145817
146474
|
async function persistSavedFix(input) {
|
|
145818
146475
|
const { env, state, outputDir, savedFix } = input;
|
|
145819
146476
|
if (state.outcome === "pushed") {
|
|
@@ -145836,6 +146493,7 @@ async function persistSavedFix(input) {
|
|
|
145836
146493
|
sha,
|
|
145837
146494
|
headSha: env.info.headSha,
|
|
145838
146495
|
agreedKeys: env.review.agreed.map((item) => item.key).sort(),
|
|
146496
|
+
findingProvenance: findingProvenance(env, state),
|
|
145839
146497
|
outcome: outcome.data,
|
|
145840
146498
|
savedAt: new Date().toISOString()
|
|
145841
146499
|
});
|
|
@@ -145864,6 +146522,7 @@ var init_saved_fix = __esm(() => {
|
|
|
145864
146522
|
sha: shaSchema,
|
|
145865
146523
|
headSha: shaSchema,
|
|
145866
146524
|
agreedKeys: array(string2()),
|
|
146525
|
+
findingProvenance: array(object({ key: string2().min(1), raisedBy: string2().min(1) })).optional(),
|
|
145867
146526
|
outcome: _enum(SAVABLE_OUTCOMES),
|
|
145868
146527
|
savedAt: string2().datetime()
|
|
145869
146528
|
});
|
|
@@ -146181,13 +146840,13 @@ async function fixCheckout(input, prepared) {
|
|
|
146181
146840
|
agentName: resolveDefaultAgent(config),
|
|
146182
146841
|
pr: { forge: ref.forge, number: ref.number, base: checkout.mergeBase, head: info.headSha }
|
|
146183
146842
|
});
|
|
146184
|
-
const review = await deps.loadLatestReview(runtime.outputDir, ref
|
|
146843
|
+
const review = await deps.loadLatestReview(runtime.outputDir, ref, info.headSha);
|
|
146185
146844
|
if (!review)
|
|
146186
146845
|
return finishFix({
|
|
146187
146846
|
outcome: "refused",
|
|
146188
146847
|
reason: `no nax bot review of head ${info.headSha.slice(0, SHORT_SHA_LENGTH11)}; run nax bot review ${ref.number} first`
|
|
146189
146848
|
}, log);
|
|
146190
|
-
const codeReview = await deps.loadLatestReview(runtime.outputDir, ref
|
|
146849
|
+
const codeReview = await deps.loadLatestReview(runtime.outputDir, ref, info.headSha, { codeOnly: true });
|
|
146191
146850
|
if (!input.readyOnly) {
|
|
146192
146851
|
const access = await deps.checkPushAccess(checkout.worktree, info.headRef);
|
|
146193
146852
|
if (!access.ok)
|
|
@@ -146221,9 +146880,10 @@ async function fixCheckout(input, prepared) {
|
|
|
146221
146880
|
};
|
|
146222
146881
|
await recordFixRulings(env, items.comments);
|
|
146223
146882
|
try {
|
|
146224
|
-
const
|
|
146883
|
+
const fixEnv = input.readyOnly ? env : await withCarriedFixFindings(env);
|
|
146884
|
+
const result = await executeFix(fixEnv, runtime, input);
|
|
146225
146885
|
if (!checkout.inPlace && !input.readyOnly && result.outcome !== "refused")
|
|
146226
|
-
await persistSavedFix({ env, state: result, outputDir: runtime.outputDir, savedFix: deps.savedFix });
|
|
146886
|
+
await persistSavedFix({ env: fixEnv, state: result, outputDir: runtime.outputDir, savedFix: deps.savedFix });
|
|
146227
146887
|
return finishFix(result, log);
|
|
146228
146888
|
} finally {
|
|
146229
146889
|
await preserveFixReport(env.ctx.reportPath, stateDir);
|
|
@@ -146286,6 +146946,7 @@ var init_fix_run = __esm(() => {
|
|
|
146286
146946
|
init_chat_asks();
|
|
146287
146947
|
init_checks4();
|
|
146288
146948
|
init_cost3();
|
|
146949
|
+
init_fix_carried();
|
|
146289
146950
|
init_fix_input();
|
|
146290
146951
|
init_fix_report();
|
|
146291
146952
|
init_fix_steps();
|
|
@@ -146518,6 +147179,7 @@ var init_bot = __esm(() => {
|
|
|
146518
147179
|
init_base_config();
|
|
146519
147180
|
init_blocking_threads();
|
|
146520
147181
|
init_caller_rulings();
|
|
147182
|
+
init_carried_record();
|
|
146521
147183
|
init_checkout();
|
|
146522
147184
|
init_checkout_in_place();
|
|
146523
147185
|
init_checks4();
|
|
@@ -146542,6 +147204,8 @@ var init_bot = __esm(() => {
|
|
|
146542
147204
|
init_push_ledger();
|
|
146543
147205
|
init_render2();
|
|
146544
147206
|
init_render_comments();
|
|
147207
|
+
init_review_advance();
|
|
147208
|
+
init_review_carry();
|
|
146545
147209
|
init_review_run();
|
|
146546
147210
|
init_review_step();
|
|
146547
147211
|
init_run_setup2();
|