crysk 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/SKILL-y8rv8msh.md +134 -0
- package/dist/SKILL-ygka1bs0.md +515 -0
- package/dist/ci-admission-qk9r9taq.md +124 -0
- package/dist/cli.js +659 -450
- package/dist/index.js +5 -5
- package/package.json +2 -2
- package/skills/crysk-ci-setup/SKILL.md +1 -1
- package/skills/crysk-ci-setup/references/ci-admission.md +4 -2
- package/skills/crysk-loop/SKILL.md +30 -11
- package/src/assets.ts +1 -1
- package/src/ci/gates.ts +28 -6
- package/src/ci/reporter.ts +2 -2
- package/src/ci/review-admission.ts +11 -2
- package/src/index.ts +1 -1
- package/src/pr/admission.ts +178 -41
- package/src/pr/answered-findings.ts +169 -0
- package/src/pr/ci-admission-gate.ts +80 -2
- package/src/pr/pr-status.ts +59 -1
- package/src/updater.ts +1 -1
package/dist/cli.js
CHANGED
|
@@ -1859,7 +1859,7 @@ var workflow_default = "./workflow-w1g9szna.yml";
|
|
|
1859
1859
|
var init_workflow = () => {};
|
|
1860
1860
|
|
|
1861
1861
|
// skills/crysk-ci-setup/references/ci-admission.md
|
|
1862
|
-
var ci_admission_default = "./ci-admission-
|
|
1862
|
+
var ci_admission_default = "./ci-admission-qk9r9taq.md";
|
|
1863
1863
|
var init_ci_admission = () => {};
|
|
1864
1864
|
|
|
1865
1865
|
// skills/crysk-ci-setup/references/opencode-ci.md
|
|
@@ -1867,7 +1867,7 @@ var opencode_ci_default = "./opencode-ci-7b0be64p.md";
|
|
|
1867
1867
|
var init_opencode_ci = () => {};
|
|
1868
1868
|
|
|
1869
1869
|
// skills/crysk-ci-setup/SKILL.md
|
|
1870
|
-
var SKILL_default2 = "./SKILL-
|
|
1870
|
+
var SKILL_default2 = "./SKILL-y8rv8msh.md";
|
|
1871
1871
|
var init_SKILL2 = () => {};
|
|
1872
1872
|
|
|
1873
1873
|
// skills/crysk-loop/adjudicator.md
|
|
@@ -1875,7 +1875,7 @@ var adjudicator_default = "./adjudicator-dtg2axnh.md";
|
|
|
1875
1875
|
var init_adjudicator = () => {};
|
|
1876
1876
|
|
|
1877
1877
|
// skills/crysk-loop/SKILL.md
|
|
1878
|
-
var SKILL_default3 = "./SKILL-
|
|
1878
|
+
var SKILL_default3 = "./SKILL-ygka1bs0.md";
|
|
1879
1879
|
var init_SKILL3 = () => {};
|
|
1880
1880
|
|
|
1881
1881
|
// skills/crysk-pr/SKILL.md
|
|
@@ -1959,7 +1959,7 @@ function resolveVersion() {
|
|
|
1959
1959
|
}
|
|
1960
1960
|
}
|
|
1961
1961
|
} catch {}
|
|
1962
|
-
return "0.3.
|
|
1962
|
+
return "0.3.1";
|
|
1963
1963
|
}
|
|
1964
1964
|
function resolveEngineAssets() {
|
|
1965
1965
|
const mode = detectAssetMode();
|
|
@@ -8297,9 +8297,9 @@ function skipCoverageLines(data) {
|
|
|
8297
8297
|
}
|
|
8298
8298
|
function manualRequiredLines(data) {
|
|
8299
8299
|
return [
|
|
8300
|
-
`### \
|
|
8300
|
+
`### \u23F9\uFE0F Crysk Review \u2014 Automatic Reviews Done \u2014 PR #${data.prNumber}`,
|
|
8301
8301
|
"",
|
|
8302
|
-
"**Reason:** automatic review
|
|
8302
|
+
"**Reason:** no automatic review is left for this pull request; the gate keeps the last verdict.",
|
|
8303
8303
|
"",
|
|
8304
8304
|
"| Metric | Value |",
|
|
8305
8305
|
"| --- | --- |",
|
|
@@ -9106,6 +9106,10 @@ function ciReviewSkipDetail(verdict) {
|
|
|
9106
9106
|
}
|
|
9107
9107
|
function ciReviewSkipLabel(reason) {
|
|
9108
9108
|
switch (reason) {
|
|
9109
|
+
case "max-attempts-exhausted":
|
|
9110
|
+
return "review budget for this PR is used up";
|
|
9111
|
+
case "manual-only-policy":
|
|
9112
|
+
return "ci_review_policy is manual_only";
|
|
9109
9113
|
case "once-per-pr":
|
|
9110
9114
|
return "once_per_pr policy allows one automatic review";
|
|
9111
9115
|
case "below-threshold":
|
|
@@ -9343,19 +9347,29 @@ function buildCoverageSkipComment(data, reason) {
|
|
|
9343
9347
|
`;
|
|
9344
9348
|
}
|
|
9345
9349
|
function buildManualRequiredComment(data) {
|
|
9350
|
+
const manualOnly = data.admissionReason === "manual-only-policy";
|
|
9351
|
+
const rules = [
|
|
9352
|
+
...data.policyMode === undefined ? [] : [`- Review policy: \`${data.policyMode}\` (\`ci_review_policy\`).`],
|
|
9353
|
+
manualOnly ? "- This repository reviews automatically once per pull request; every later review is on request." : `- Automatic reviews used: ${data.reviewCount}/${data.maxAttempts} (\`ci_max_attempts\`).`,
|
|
9354
|
+
...data.reviewedHead === undefined || data.reviewedHead === null ? [] : [`- Last reviewed head: \`${data.reviewedHead.slice(0, 7)}\`.`]
|
|
9355
|
+
];
|
|
9346
9356
|
const lines = [
|
|
9347
9357
|
MANUAL_REQUIRED_COMMENT_MARKER,
|
|
9348
|
-
"## Crysk
|
|
9358
|
+
"## Crysk: automatic reviews are done for this pull request",
|
|
9349
9359
|
"",
|
|
9350
|
-
"\
|
|
9360
|
+
"\u23F9\uFE0F No more automatic reviews will run on this pull request.",
|
|
9351
9361
|
"",
|
|
9352
9362
|
`**${data.detail}**`,
|
|
9353
9363
|
"",
|
|
9354
|
-
|
|
9364
|
+
"How it got here, by this repository's rules:",
|
|
9355
9365
|
"",
|
|
9356
|
-
|
|
9366
|
+
...rules,
|
|
9357
9367
|
"",
|
|
9358
|
-
|
|
9368
|
+
"What the gate does with the next pushes: it keeps the last review's verdict. A red verdict turns " + "green, marked unverified, once every blocking finding has a reply from someone with write access: " + "`applied`, or a `dismissed` the CI adjudicator upheld. Reply before you push: the gate reads the " + "replies when the push arrives.",
|
|
9369
|
+
"",
|
|
9370
|
+
"The existing review comment still describes the last head Crysk reviewed.",
|
|
9371
|
+
"",
|
|
9372
|
+
`Want more review rounds? ${ciForceReviewHintLine(data.prNumber)}`
|
|
9359
9373
|
];
|
|
9360
9374
|
return `${lines.join(`
|
|
9361
9375
|
`)}
|
|
@@ -28799,7 +28813,7 @@ var PRHERO_GITHUB_REPO = "cryskai/crysk";
|
|
|
28799
28813
|
function detectInstallMethod(options = {}) {
|
|
28800
28814
|
const home = options.home ?? os14.homedir();
|
|
28801
28815
|
const execPath = options.execPath ?? process.execPath;
|
|
28802
|
-
const version = options.version ?? "0.3.
|
|
28816
|
+
const version = options.version ?? "0.3.1";
|
|
28803
28817
|
const exists = options.exists ?? existsSync24;
|
|
28804
28818
|
const isSource = options.isDev !== undefined ? options.isDev : version === "dev" || exists("./src/cli.ts") && !execPath.includes(".crysk/bin") && !execPath.includes(".prhero/bin");
|
|
28805
28819
|
if (isSource) {
|
|
@@ -33841,7 +33855,7 @@ async function recordCiAdmissionGateSkip(input) {
|
|
|
33841
33855
|
} catch {}
|
|
33842
33856
|
}
|
|
33843
33857
|
function isCarriedReason(reason) {
|
|
33844
|
-
return reason
|
|
33858
|
+
return reason !== "same-head";
|
|
33845
33859
|
}
|
|
33846
33860
|
var BLOCKING_COUNT = /^crysk: (\d+) blocking finding\(s\)/;
|
|
33847
33861
|
function blockingCountIn(description) {
|
|
@@ -33859,6 +33873,17 @@ function carriedSuccessDescription(label, sha) {
|
|
|
33859
33873
|
function carriedBlockingDescription(count, sha) {
|
|
33860
33874
|
return clipStatusDescription(`${STATUS_CONTEXT}: ${count} blocking finding(s) ${CARRIED_FROM}${sha.slice(0, 7)} \u2014 fix and push, or /pr-hero override`);
|
|
33861
33875
|
}
|
|
33876
|
+
function unverifiedFixesDescription(count, label, sha) {
|
|
33877
|
+
return clipStatusDescription(`${STATUS_CONTEXT}: ${count} answered finding(s), fixes unverified (${label}); ${CARRIED_FROM}${sha.slice(0, 7)}`);
|
|
33878
|
+
}
|
|
33879
|
+
var ANSWERED_COUNT = /^crysk: (\d+) answered finding\(s\), fixes unverified/;
|
|
33880
|
+
function answeredCountIn(description) {
|
|
33881
|
+
const match = ANSWERED_COUNT.exec(canonicalStatusText(description));
|
|
33882
|
+
if (match === null)
|
|
33883
|
+
return null;
|
|
33884
|
+
const count = Number(match[1]);
|
|
33885
|
+
return count > 0 ? count : null;
|
|
33886
|
+
}
|
|
33862
33887
|
function carriedPartialDescription(failed, total, sha, set) {
|
|
33863
33888
|
const suffix = set === undefined ? "" : `, set ${set}`;
|
|
33864
33889
|
return clipStatusDescription(`${STATUS_CONTEXT}: review partial (${failed} of ${total} hunters failed${suffix}) ${CARRIED_FROM}${sha.slice(0, 7)} \u2014 /pr-hero review retries it`);
|
|
@@ -33867,7 +33892,9 @@ var CARRY_REASONS = [
|
|
|
33867
33892
|
"once-per-pr",
|
|
33868
33893
|
"below-threshold",
|
|
33869
33894
|
"low-risk-delta",
|
|
33870
|
-
"stopped"
|
|
33895
|
+
"stopped",
|
|
33896
|
+
"max-attempts-exhausted",
|
|
33897
|
+
"manual-only-policy"
|
|
33871
33898
|
];
|
|
33872
33899
|
function finishedSuccessMatches(rawDescription) {
|
|
33873
33900
|
const description = canonicalStatusText(rawDescription);
|
|
@@ -33895,6 +33922,12 @@ function carriedSuccessMatches(rawDescription) {
|
|
|
33895
33922
|
const sha = carriedSha(description);
|
|
33896
33923
|
return sha !== null && CARRY_REASONS.some((reason) => carriedSuccessDescription(ciReviewSkipLabel(reason), sha) === description);
|
|
33897
33924
|
}
|
|
33925
|
+
function unverifiedFixesMatches(rawDescription) {
|
|
33926
|
+
const description = canonicalStatusText(rawDescription);
|
|
33927
|
+
const sha = carriedSha(description);
|
|
33928
|
+
const count = answeredCountIn(description);
|
|
33929
|
+
return sha !== null && count !== null && CARRY_REASONS.some((reason) => unverifiedFixesDescription(count, ciReviewSkipLabel(reason), sha) === description);
|
|
33930
|
+
}
|
|
33898
33931
|
function carriedBlockingMatches(rawDescription) {
|
|
33899
33932
|
const description = canonicalStatusText(rawDescription);
|
|
33900
33933
|
const sha = carriedSha(description);
|
|
@@ -33932,7 +33965,7 @@ function isReviewVerdictStatus(status) {
|
|
|
33932
33965
|
if (typeof description !== "string")
|
|
33933
33966
|
return false;
|
|
33934
33967
|
if (status.state === "success") {
|
|
33935
|
-
return finishedSuccessMatches(description) || carriedSuccessMatches(description);
|
|
33968
|
+
return finishedSuccessMatches(description) || carriedSuccessMatches(description) || unverifiedFixesMatches(description);
|
|
33936
33969
|
}
|
|
33937
33970
|
if (status.state === "failure") {
|
|
33938
33971
|
return finishedBlockingMatches(description) || carriedBlockingMatches(description) || finishedPartialMatches(description) || carriedPartialMatches(description);
|
|
@@ -33949,25 +33982,8 @@ function failClosed(label) {
|
|
|
33949
33982
|
};
|
|
33950
33983
|
}
|
|
33951
33984
|
function admissionSkipDecision(input) {
|
|
33952
|
-
|
|
33953
|
-
|
|
33954
|
-
return null;
|
|
33955
|
-
case "max-attempts-exhausted":
|
|
33956
|
-
return {
|
|
33957
|
-
state: "failure",
|
|
33958
|
-
description: clipStatusDescription(`${STATUS_CONTEXT}: review budget for this PR is used up \u2014 /pr-hero review reviews this head`)
|
|
33959
|
-
};
|
|
33960
|
-
case "manual-only-policy":
|
|
33961
|
-
return {
|
|
33962
|
-
state: "failure",
|
|
33963
|
-
description: clipStatusDescription(`${STATUS_CONTEXT}: review needs a manual trigger (ci_review_policy is manual_only) \u2014 /pr-hero review reviews this head`)
|
|
33964
|
-
};
|
|
33965
|
-
case "once-per-pr":
|
|
33966
|
-
case "below-threshold":
|
|
33967
|
-
case "low-risk-delta":
|
|
33968
|
-
case "stopped":
|
|
33969
|
-
break;
|
|
33970
|
-
}
|
|
33985
|
+
if (input.reason === "same-head")
|
|
33986
|
+
return null;
|
|
33971
33987
|
const label = ciReviewSkipLabel(input.reason);
|
|
33972
33988
|
if (input.carried === null)
|
|
33973
33989
|
return failClosed(label);
|
|
@@ -33975,9 +33991,10 @@ function admissionSkipDecision(input) {
|
|
|
33975
33991
|
if (verdict === undefined)
|
|
33976
33992
|
return failClosed(label);
|
|
33977
33993
|
if (verdict.state === "success") {
|
|
33994
|
+
const answeredCount = answeredCountIn(verdict.description ?? "");
|
|
33978
33995
|
return {
|
|
33979
33996
|
state: "success",
|
|
33980
|
-
description: carriedSuccessDescription(label, input.carried.sha)
|
|
33997
|
+
description: answeredCount === null ? carriedSuccessDescription(label, input.carried.sha) : unverifiedFixesDescription(answeredCount, label, input.carried.sha)
|
|
33981
33998
|
};
|
|
33982
33999
|
}
|
|
33983
34000
|
const partial = partialCountsIn(verdict.description);
|
|
@@ -33990,11 +34007,28 @@ function admissionSkipDecision(input) {
|
|
|
33990
34007
|
const blocking = blockingCountIn(verdict.description) ?? (input.priorBlocking > 0 ? input.priorBlocking : null);
|
|
33991
34008
|
if (blocking === null)
|
|
33992
34009
|
return failClosed(label);
|
|
34010
|
+
const answered = input.answered ?? null;
|
|
34011
|
+
if (answered !== null && answered.open === 0 && answered.blocking > 0 && answered.blocking >= blocking) {
|
|
34012
|
+
return {
|
|
34013
|
+
state: "success",
|
|
34014
|
+
description: unverifiedFixesDescription(answered.blocking, label, input.carried.sha)
|
|
34015
|
+
};
|
|
34016
|
+
}
|
|
33993
34017
|
return {
|
|
33994
34018
|
state: "failure",
|
|
33995
34019
|
description: carriedBlockingDescription(blocking, input.carried.sha)
|
|
33996
34020
|
};
|
|
33997
34021
|
}
|
|
34022
|
+
function carriedBlockingCount(carried) {
|
|
34023
|
+
if (carried === null)
|
|
34024
|
+
return null;
|
|
34025
|
+
const verdict = newestCarriedVerdict(carried.statuses);
|
|
34026
|
+
if (verdict === undefined || verdict.state !== "failure")
|
|
34027
|
+
return null;
|
|
34028
|
+
if (partialCountsIn(verdict.description) !== null)
|
|
34029
|
+
return null;
|
|
34030
|
+
return blockingCountIn(verdict.description);
|
|
34031
|
+
}
|
|
33998
34032
|
var CARRY_WALK_CAP = 20;
|
|
33999
34033
|
async function findCarriedVerdict(input) {
|
|
34000
34034
|
const shas = await input.listCommits(input.operatorRoot, input.prNumber, {
|
|
@@ -34012,8 +34046,9 @@ async function findCarriedVerdict(input) {
|
|
|
34012
34046
|
});
|
|
34013
34047
|
if (statuses === null)
|
|
34014
34048
|
return null;
|
|
34015
|
-
if (newestCarriedVerdict(statuses) !== undefined)
|
|
34016
|
-
return { sha, statuses };
|
|
34049
|
+
if (newestCarriedVerdict(statuses) !== undefined) {
|
|
34050
|
+
return { sha, statuses, older: earlier.slice(earlier.indexOf(sha) + 1) };
|
|
34051
|
+
}
|
|
34017
34052
|
}
|
|
34018
34053
|
return null;
|
|
34019
34054
|
}
|
|
@@ -34031,6 +34066,36 @@ async function overrideStandsOnHead(input) {
|
|
|
34031
34066
|
const newest = newestStatusInContext(statuses, COMMIT_STATUS_CONTEXT);
|
|
34032
34067
|
return newest !== undefined && isOverrideStatus(newest);
|
|
34033
34068
|
}
|
|
34069
|
+
async function reviewVerdictTime(input) {
|
|
34070
|
+
if (input.carried === null)
|
|
34071
|
+
return null;
|
|
34072
|
+
const ownIn = (statuses) => newestStatusInContext(statuses.filter((status) => finishedVerdict(status)), COMMIT_STATUS_CONTEXT);
|
|
34073
|
+
const first = ownIn(input.carried.statuses);
|
|
34074
|
+
if (first !== undefined)
|
|
34075
|
+
return first.created_at ?? null;
|
|
34076
|
+
for (const sha of input.carried.older ?? []) {
|
|
34077
|
+
const statuses = await input.readStatuses(input.operatorRoot, sha, {
|
|
34078
|
+
spawnFn: input.spawnFn
|
|
34079
|
+
});
|
|
34080
|
+
if (statuses === null)
|
|
34081
|
+
return null;
|
|
34082
|
+
const own = ownIn(statuses);
|
|
34083
|
+
if (own !== undefined)
|
|
34084
|
+
return own.created_at ?? null;
|
|
34085
|
+
}
|
|
34086
|
+
return null;
|
|
34087
|
+
}
|
|
34088
|
+
function finishedVerdict(status) {
|
|
34089
|
+
const description = status.description;
|
|
34090
|
+
if (typeof description !== "string")
|
|
34091
|
+
return false;
|
|
34092
|
+
if (status.state === "success")
|
|
34093
|
+
return finishedSuccessMatches(description);
|
|
34094
|
+
if (status.state === "failure") {
|
|
34095
|
+
return finishedBlockingMatches(description) || finishedPartialMatches(description);
|
|
34096
|
+
}
|
|
34097
|
+
return false;
|
|
34098
|
+
}
|
|
34034
34099
|
async function gateSkipDecision(input, skip) {
|
|
34035
34100
|
if (skip === "size" || skip === "budget") {
|
|
34036
34101
|
const request = skipCommitStatusRequest({
|
|
@@ -34051,7 +34116,20 @@ async function gateSkipDecision(input, skip) {
|
|
|
34051
34116
|
listCommits: input.listCommits ?? fetchPrCommitShas,
|
|
34052
34117
|
readStatuses: input.readStatuses ?? fetchCommitStatusList
|
|
34053
34118
|
}) : null;
|
|
34054
|
-
|
|
34119
|
+
let answered = null;
|
|
34120
|
+
if (carriedBlockingCount(carried) !== null && input.admission.readAnswered !== undefined) {
|
|
34121
|
+
try {
|
|
34122
|
+
answered = await input.admission.readAnswered(await reviewVerdictTime({
|
|
34123
|
+
operatorRoot: input.operatorRoot,
|
|
34124
|
+
carried,
|
|
34125
|
+
spawnFn: input.spawnFn,
|
|
34126
|
+
readStatuses: input.readStatuses ?? fetchCommitStatusList
|
|
34127
|
+
}));
|
|
34128
|
+
} catch {
|
|
34129
|
+
answered = null;
|
|
34130
|
+
}
|
|
34131
|
+
}
|
|
34132
|
+
return admissionSkipDecision({ ...input.admission, carried, answered });
|
|
34055
34133
|
}
|
|
34056
34134
|
function cliSkipKindOf(plan) {
|
|
34057
34135
|
switch (plan.outputs.status) {
|
|
@@ -34121,6 +34199,510 @@ async function publishCiSkip(input) {
|
|
|
34121
34199
|
return 0;
|
|
34122
34200
|
}
|
|
34123
34201
|
|
|
34202
|
+
// src/pr/pr-status.ts
|
|
34203
|
+
init_outcome();
|
|
34204
|
+
init_override();
|
|
34205
|
+
init_trigger();
|
|
34206
|
+
init_preflight2();
|
|
34207
|
+
init_triage();
|
|
34208
|
+
init_preflight3();
|
|
34209
|
+
init_brand();
|
|
34210
|
+
var PR_STATUS_SCHEMA = "pr-hero.status/v1";
|
|
34211
|
+
var STATUS_WAIT_POLL_INTERVAL_MS = 15000;
|
|
34212
|
+
var STATUS_WAIT_STARTUP_GRACE_MS = 180000;
|
|
34213
|
+
var STATUS_WAIT_MAX_MS = IN_FLIGHT_TTL_MS;
|
|
34214
|
+
var TRIGGER_COMMANDS = [REVIEW_COMMAND, REVIEW_FULL_COMMAND, RECHECK_COMMAND];
|
|
34215
|
+
var IN_FLIGHT_WINDOW_MINUTES = Math.round(IN_FLIGHT_TTL_MS / 60000);
|
|
34216
|
+
function buildPrStatus(input) {
|
|
34217
|
+
const gate = readGate(input);
|
|
34218
|
+
const summary = readSummary(input.issueComments);
|
|
34219
|
+
const analyzed = readFindings(input, summary.rows);
|
|
34220
|
+
const liveBlocking = analyzed.filter((a) => a.finding.blocking && a.finding.live_on_head);
|
|
34221
|
+
const decision = decideNext(gate, analyzed, input.head, summary);
|
|
34222
|
+
return {
|
|
34223
|
+
schema: PR_STATUS_SCHEMA,
|
|
34224
|
+
pr: input.pr,
|
|
34225
|
+
head: input.head,
|
|
34226
|
+
gate,
|
|
34227
|
+
report: {
|
|
34228
|
+
head: summary.head,
|
|
34229
|
+
complete: summary.complete,
|
|
34230
|
+
reviews: summary.reviews,
|
|
34231
|
+
outcome_code: outcomeCodeOf(input.issueComments)
|
|
34232
|
+
},
|
|
34233
|
+
findings: analyzed.map((a) => a.finding),
|
|
34234
|
+
unresolved_blocking: unresolvedBlocking(gate, liveBlocking.filter((a) => !upheldDismissal(a)).length),
|
|
34235
|
+
next_action: decision.next_action,
|
|
34236
|
+
reason: decision.reason
|
|
34237
|
+
};
|
|
34238
|
+
}
|
|
34239
|
+
function readGate(input) {
|
|
34240
|
+
const latest = latestStatusInContext(input.statuses, COMMIT_STATUS_CONTEXT);
|
|
34241
|
+
if (latest === null) {
|
|
34242
|
+
return {
|
|
34243
|
+
state: "none",
|
|
34244
|
+
description: null,
|
|
34245
|
+
target_url: null,
|
|
34246
|
+
created_at: null,
|
|
34247
|
+
pending_in_flight: false,
|
|
34248
|
+
override: { active: false, by: null }
|
|
34249
|
+
};
|
|
34250
|
+
}
|
|
34251
|
+
const active = isOverrideStatus(latest);
|
|
34252
|
+
const description = latest.description ?? null;
|
|
34253
|
+
return {
|
|
34254
|
+
state: gateStateOf(latest.state),
|
|
34255
|
+
description,
|
|
34256
|
+
target_url: latest.target_url ?? null,
|
|
34257
|
+
created_at: latest.created_at,
|
|
34258
|
+
pending_in_flight: isInFlightCommitStatus(input.statuses, input.nowMs),
|
|
34259
|
+
override: {
|
|
34260
|
+
active,
|
|
34261
|
+
by: active && description !== null ? overrideActorOf(description) : null
|
|
34262
|
+
}
|
|
34263
|
+
};
|
|
34264
|
+
}
|
|
34265
|
+
function gateStateOf(state) {
|
|
34266
|
+
if (state === "success" || state === "failure" || state === "error" || state === "pending") {
|
|
34267
|
+
return state;
|
|
34268
|
+
}
|
|
34269
|
+
return "error";
|
|
34270
|
+
}
|
|
34271
|
+
function liveBlockingFindings(input) {
|
|
34272
|
+
const summary = readSummary(input.issueComments);
|
|
34273
|
+
return readFindings(input, summary.rows).filter((a) => a.finding.blocking && a.finding.live_on_head).map((a) => a.finding);
|
|
34274
|
+
}
|
|
34275
|
+
function readSummary(comments) {
|
|
34276
|
+
const id = findMarkedCommentId(comments);
|
|
34277
|
+
const body = comments.find((c) => c.id === id)?.body ?? null;
|
|
34278
|
+
if (id === null || body === null) {
|
|
34279
|
+
return { head: null, complete: null, reviews: null, rows: [] };
|
|
34280
|
+
}
|
|
34281
|
+
const marker = parsePrCommentMarker(body);
|
|
34282
|
+
const state = parseStateBlock(body);
|
|
34283
|
+
return {
|
|
34284
|
+
head: marker?.head ?? null,
|
|
34285
|
+
complete: marker?.complete ?? null,
|
|
34286
|
+
reviews: state?.reviews ?? null,
|
|
34287
|
+
rows: state?.findings ?? []
|
|
34288
|
+
};
|
|
34289
|
+
}
|
|
34290
|
+
function outcomeCodeOf(comments) {
|
|
34291
|
+
let newest = null;
|
|
34292
|
+
for (const comment of comments) {
|
|
34293
|
+
if (matchMarkerPrefix(comment.body, OUTCOME_MARKER_PREFIX) === undefined) {
|
|
34294
|
+
continue;
|
|
34295
|
+
}
|
|
34296
|
+
if (newest === null || comment.id > newest.id)
|
|
34297
|
+
newest = comment;
|
|
34298
|
+
}
|
|
34299
|
+
return newest === null ? null : parseOutcomeCode(newest.body);
|
|
34300
|
+
}
|
|
34301
|
+
function readFindings(input, rows) {
|
|
34302
|
+
const sources = [
|
|
34303
|
+
...input.reviewComments.map((c) => ({
|
|
34304
|
+
id: c.id,
|
|
34305
|
+
body: c.body,
|
|
34306
|
+
channel: "inline",
|
|
34307
|
+
livePath: c.path,
|
|
34308
|
+
liveLine: c.line ?? undefined
|
|
34309
|
+
})),
|
|
34310
|
+
...input.issueComments.map((c) => ({
|
|
34311
|
+
id: c.id,
|
|
34312
|
+
body: c.body,
|
|
34313
|
+
channel: "outside"
|
|
34314
|
+
}))
|
|
34315
|
+
].sort((a, b) => a.id - b.id);
|
|
34316
|
+
const posted = [];
|
|
34317
|
+
for (const source of sources) {
|
|
34318
|
+
const marker = parseFindingMarker(source.body);
|
|
34319
|
+
if (marker !== null)
|
|
34320
|
+
posted.push({ source, marker });
|
|
34321
|
+
}
|
|
34322
|
+
const bound = bindPriorsToPosted(rows, posted.map(({ source, marker }) => ({
|
|
34323
|
+
id: source.id,
|
|
34324
|
+
marker,
|
|
34325
|
+
livePath: source.livePath,
|
|
34326
|
+
liveLine: source.liveLine
|
|
34327
|
+
})));
|
|
34328
|
+
const rowByComment = new Map;
|
|
34329
|
+
for (const row2 of rows) {
|
|
34330
|
+
const comment = bound.get(row2.id);
|
|
34331
|
+
if (comment !== undefined)
|
|
34332
|
+
rowByComment.set(comment.id, row2);
|
|
34333
|
+
}
|
|
34334
|
+
const out = [];
|
|
34335
|
+
for (const { source, marker } of posted) {
|
|
34336
|
+
const row2 = rowByComment.get(source.id);
|
|
34337
|
+
const badge = parseFindingCommentBadge(source.body);
|
|
34338
|
+
const replies = repliesTo(source, input);
|
|
34339
|
+
const newest = newestReply(replies);
|
|
34340
|
+
const triage = newest?.marker ?? null;
|
|
34341
|
+
const tier = badge?.tier ?? row2?.tier ?? TIER_UNRECOVERABLE;
|
|
34342
|
+
out.push({
|
|
34343
|
+
finding: {
|
|
34344
|
+
id: row2?.id ?? null,
|
|
34345
|
+
path: marker.path,
|
|
34346
|
+
line: marker.line,
|
|
34347
|
+
head: marker.headSha,
|
|
34348
|
+
comment_id: source.id,
|
|
34349
|
+
channel: source.channel,
|
|
34350
|
+
severity: badge?.sev ?? (row2 !== undefined && row2.sev !== SEVERITY_UNRECOVERABLE ? row2.sev : null),
|
|
34351
|
+
tier,
|
|
34352
|
+
blocking: tier !== "advisory",
|
|
34353
|
+
live_on_head: row2 !== undefined || marker.headSha === input.head,
|
|
34354
|
+
triage: triage === null ? null : {
|
|
34355
|
+
tag: triage.tag,
|
|
34356
|
+
verdict: triage.verdict ?? null,
|
|
34357
|
+
actor: triage.actor,
|
|
34358
|
+
head: triage.headSha
|
|
34359
|
+
},
|
|
34360
|
+
ci_verdict: source.channel === "inline" ? ciVerdictOf(source.id, newest?.id ?? null, input) : null
|
|
34361
|
+
},
|
|
34362
|
+
triagedAtPostedHead: replies.some((r) => r.marker.headSha === marker.headSha)
|
|
34363
|
+
});
|
|
34364
|
+
}
|
|
34365
|
+
for (const row2 of rows) {
|
|
34366
|
+
if (bound.has(row2.id))
|
|
34367
|
+
continue;
|
|
34368
|
+
out.push({ finding: unthreadedFinding(row2), triagedAtPostedHead: false });
|
|
34369
|
+
}
|
|
34370
|
+
return out;
|
|
34371
|
+
}
|
|
34372
|
+
function unthreadedFinding(row2) {
|
|
34373
|
+
const first = row2.locs[0];
|
|
34374
|
+
const span = first === undefined ? undefined : parseProofRefLocs(first)[0];
|
|
34375
|
+
const tier = row2.tier;
|
|
34376
|
+
return {
|
|
34377
|
+
id: row2.id,
|
|
34378
|
+
path: span?.path ?? first ?? "",
|
|
34379
|
+
line: span?.span.start ?? 0,
|
|
34380
|
+
head: null,
|
|
34381
|
+
comment_id: null,
|
|
34382
|
+
channel: row2.channel,
|
|
34383
|
+
severity: row2.sev !== SEVERITY_UNRECOVERABLE ? row2.sev : null,
|
|
34384
|
+
tier,
|
|
34385
|
+
blocking: tier !== "advisory",
|
|
34386
|
+
live_on_head: true,
|
|
34387
|
+
triage: null,
|
|
34388
|
+
ci_verdict: null
|
|
34389
|
+
};
|
|
34390
|
+
}
|
|
34391
|
+
function ciVerdictOf(threadId, newestTriageId, input) {
|
|
34392
|
+
if (newestTriageId === null)
|
|
34393
|
+
return null;
|
|
34394
|
+
let best = null;
|
|
34395
|
+
for (const comment of input.reviewComments) {
|
|
34396
|
+
if (comment.in_reply_to_id !== threadId)
|
|
34397
|
+
continue;
|
|
34398
|
+
if (comment.user !== CI_ADJUDICATOR_LOGIN)
|
|
34399
|
+
continue;
|
|
34400
|
+
const marker = parseAdjudicationMarker(comment.body);
|
|
34401
|
+
if (marker === null)
|
|
34402
|
+
continue;
|
|
34403
|
+
if (marker.reply !== newestTriageId || marker.head !== input.head)
|
|
34404
|
+
continue;
|
|
34405
|
+
if (best === null || comment.id > best.id) {
|
|
34406
|
+
best = { id: comment.id, verdict: marker.verdict };
|
|
34407
|
+
}
|
|
34408
|
+
}
|
|
34409
|
+
return best?.verdict ?? null;
|
|
34410
|
+
}
|
|
34411
|
+
function repliesTo(source, input) {
|
|
34412
|
+
const out = [];
|
|
34413
|
+
if (source.channel === "inline") {
|
|
34414
|
+
for (const reply of input.reviewComments) {
|
|
34415
|
+
if (reply.in_reply_to_id !== source.id)
|
|
34416
|
+
continue;
|
|
34417
|
+
const marker = parseTriageMarker(reply.body);
|
|
34418
|
+
if (marker !== null)
|
|
34419
|
+
out.push({ id: reply.id, marker });
|
|
34420
|
+
}
|
|
34421
|
+
return out;
|
|
34422
|
+
}
|
|
34423
|
+
const link = new RegExp(`#issuecomment-${source.id}(?!\\d)`);
|
|
34424
|
+
for (const comment of input.issueComments) {
|
|
34425
|
+
const marker = parseTriageMarker(comment.body);
|
|
34426
|
+
if (marker === null || !link.test(comment.body))
|
|
34427
|
+
continue;
|
|
34428
|
+
out.push({ id: comment.id, marker });
|
|
34429
|
+
}
|
|
34430
|
+
return out;
|
|
34431
|
+
}
|
|
34432
|
+
function newestReply(replies) {
|
|
34433
|
+
let newest = null;
|
|
34434
|
+
for (const reply of replies) {
|
|
34435
|
+
if (newest === null || reply.id > newest.id)
|
|
34436
|
+
newest = reply;
|
|
34437
|
+
}
|
|
34438
|
+
return newest;
|
|
34439
|
+
}
|
|
34440
|
+
var PARTIAL_REVIEW_GATE = /^crysk: review partial \(\d+ of \d+ hunters failed(?:, set [0-9a-f]{6})?\)/;
|
|
34441
|
+
var PARTIAL_REVIEW_AGAIN_GATE = /^crysk: review partial again \(\d+ of \d+ hunters failed(?:, set [0-9a-f]{6})?\)/;
|
|
34442
|
+
function unresolvedBlocking(gate, liveBlockingCount) {
|
|
34443
|
+
return gateBlockingCount(gate) ?? liveBlockingCount;
|
|
34444
|
+
}
|
|
34445
|
+
function gateBlockingCount(gate) {
|
|
34446
|
+
if (gate.state !== "failure" || gate.description === null)
|
|
34447
|
+
return null;
|
|
34448
|
+
const counted = /^crysk: (\d+) blocking finding\(s\)/.exec(canonicalStatusText(gate.description));
|
|
34449
|
+
return counted?.[1] === undefined ? null : Number(counted[1]);
|
|
34450
|
+
}
|
|
34451
|
+
var REVIEW_TRIGGER_GATE = /^crysk: review (budget for this PR is used up|needs a manual trigger)/;
|
|
34452
|
+
var CARRIED_BLOCKING_GATE = /^crysk: \d+ blocking finding\(s\) carried from /;
|
|
34453
|
+
var UNVERIFIED_FIXES_GATE = /^crysk: \d+ answered finding\(s\), fixes unverified \(/;
|
|
34454
|
+
function upheldDismissal(a) {
|
|
34455
|
+
return a.finding.triage?.tag === "dismissed" && a.finding.ci_verdict === "upheld";
|
|
34456
|
+
}
|
|
34457
|
+
function decideNext(gate, analyzed, head, summary) {
|
|
34458
|
+
const liveBlocking = analyzed.filter((a) => a.finding.blocking && a.finding.live_on_head);
|
|
34459
|
+
if (gate.state === "pending") {
|
|
34460
|
+
if (gate.pending_in_flight) {
|
|
34461
|
+
return {
|
|
34462
|
+
next_action: "wait",
|
|
34463
|
+
reason: `A crysk review is in flight on this head (pending since ${gate.created_at}); wait for it to finish.`
|
|
34464
|
+
};
|
|
34465
|
+
}
|
|
34466
|
+
return {
|
|
34467
|
+
next_action: "review",
|
|
34468
|
+
reason: `The pending crysk status on this head is older than the ${IN_FLIGHT_WINDOW_MINUTES}-minute in-flight window and no run holds it; start a review.`
|
|
34469
|
+
};
|
|
34470
|
+
}
|
|
34471
|
+
if (gate.state === "none") {
|
|
34472
|
+
return {
|
|
34473
|
+
next_action: "review",
|
|
34474
|
+
reason: "No crysk gate status is on this head, so no review has run here yet; start one."
|
|
34475
|
+
};
|
|
34476
|
+
}
|
|
34477
|
+
if (gate.state === "error") {
|
|
34478
|
+
return {
|
|
34479
|
+
next_action: "review",
|
|
34480
|
+
reason: `The last crysk review on this head did not finish (${gate.description ?? "no description"}); start a review.`
|
|
34481
|
+
};
|
|
34482
|
+
}
|
|
34483
|
+
if (gate.state === "success") {
|
|
34484
|
+
if (gate.override.active) {
|
|
34485
|
+
return {
|
|
34486
|
+
next_action: "done",
|
|
34487
|
+
reason: `The gate is green through an override by @${gate.override.by ?? "an unknown login"}; nothing is owed on this head.`
|
|
34488
|
+
};
|
|
34489
|
+
}
|
|
34490
|
+
if (summary.head === head && summary.complete === false) {
|
|
34491
|
+
return {
|
|
34492
|
+
next_action: "review",
|
|
34493
|
+
reason: `The last review of this head was partial (some reviewers failed); run ${commandHint(REVIEW_COMMAND, "")}.`
|
|
34494
|
+
};
|
|
34495
|
+
}
|
|
34496
|
+
const owed = analyzed.filter((a) => a.finding.head === head && !a.triagedAtPostedHead);
|
|
34497
|
+
if (owed.length > 0) {
|
|
34498
|
+
return {
|
|
34499
|
+
next_action: "triage",
|
|
34500
|
+
reason: `The gate is green, but ${owed.length} finding(s) on this head have no reply yet; triage them.`
|
|
34501
|
+
};
|
|
34502
|
+
}
|
|
34503
|
+
if (UNVERIFIED_FIXES_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
34504
|
+
return {
|
|
34505
|
+
next_action: "done",
|
|
34506
|
+
reason: `The gate is green on answered findings no review verified (${gate.description}); the PR is ready to merge, or comment ${commandHint(REVIEW_COMMAND, "")} for another review.`
|
|
34507
|
+
};
|
|
34508
|
+
}
|
|
34509
|
+
return {
|
|
34510
|
+
next_action: "done",
|
|
34511
|
+
reason: "The review on this head passed the gate, and every finding on this head has a reply."
|
|
34512
|
+
};
|
|
34513
|
+
}
|
|
34514
|
+
if (REVIEW_TRIGGER_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
34515
|
+
return {
|
|
34516
|
+
next_action: "review",
|
|
34517
|
+
reason: `The automatic review budget for this PR is used up, or the review policy is manual (ci_review_policy is manual_only); comment ${commandHint(REVIEW_COMMAND, "")} to review this head.`
|
|
34518
|
+
};
|
|
34519
|
+
}
|
|
34520
|
+
const untriaged = liveBlocking.filter((a) => a.finding.comment_id !== null && !a.triagedAtPostedHead);
|
|
34521
|
+
if (untriaged.length > 0) {
|
|
34522
|
+
return {
|
|
34523
|
+
next_action: "triage",
|
|
34524
|
+
reason: `${untriaged.length} live blocking finding(s) on this head have no triage reply at the head they were posted on; triage them first.`
|
|
34525
|
+
};
|
|
34526
|
+
}
|
|
34527
|
+
const unthreaded = liveBlocking.filter((a) => a.finding.comment_id === null);
|
|
34528
|
+
if (unthreaded.length > 0 && gateBlockingCount(gate) !== null) {
|
|
34529
|
+
const ids = unthreaded.map((a) => a.finding.id ?? "unnamed").join(", ");
|
|
34530
|
+
return {
|
|
34531
|
+
next_action: "fix",
|
|
34532
|
+
reason: `${unthreaded.length} live blocking finding(s) (${ids}) have no comment thread to answer (summary-only or never posted inline); fix them and push, or ${commandHint(OVERRIDE_COMMAND, "")}.`
|
|
34533
|
+
};
|
|
34534
|
+
}
|
|
34535
|
+
const applied = liveBlocking.filter((a) => a.finding.triage?.tag === "applied");
|
|
34536
|
+
if (applied.length > 0) {
|
|
34537
|
+
if (CARRIED_BLOCKING_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
34538
|
+
const open3 = liveBlocking.filter((a) => !(a.finding.triage?.tag === "applied" && a.finding.triage.head === a.finding.head || upheldDismissal(a))).length;
|
|
34539
|
+
const counted = gateBlockingCount(gate);
|
|
34540
|
+
const unseen = counted === null ? 0 : Math.max(0, counted - liveBlocking.length);
|
|
34541
|
+
return {
|
|
34542
|
+
next_action: "fix",
|
|
34543
|
+
reason: open3 === 0 && unseen === 0 ? "Every live blocking finding is answered and a review rule skipped this head; push the fix. If a rule skips that push too, the gate reads the replies on it and can turn green, marked unverified; otherwise the review verifies it." : `A live blocking finding is tagged applied, but ${open3 + unseen} blocking finding(s) are still open (deferred, misclassified, a dismissal not upheld, a reply at another head, or one this read cannot see), so replies alone will not unlock the carried red; push the fix, and answer or fix the rest.`
|
|
34544
|
+
};
|
|
34545
|
+
}
|
|
34546
|
+
return {
|
|
34547
|
+
next_action: "fix",
|
|
34548
|
+
reason: "A live blocking finding is tagged applied; push the fix, and the next review verifies it."
|
|
34549
|
+
};
|
|
34550
|
+
}
|
|
34551
|
+
const dismissed = liveBlocking.filter((a) => a.finding.triage?.tag === "dismissed");
|
|
34552
|
+
const pendingRulings = dismissed.filter((a) => a.finding.channel === "inline" && (a.finding.ci_verdict === null || a.finding.ci_verdict === "inconclusive"));
|
|
34553
|
+
if (pendingRulings.length > 0) {
|
|
34554
|
+
return {
|
|
34555
|
+
next_action: "recheck",
|
|
34556
|
+
reason: `${pendingRulings.length} live blocking finding(s) are answered dismissed with no CI ruling on this head (or an inconclusive one); comment ${commandHint(RECHECK_COMMAND, "")} so the CI adjudicator rules on them.`
|
|
34557
|
+
};
|
|
34558
|
+
}
|
|
34559
|
+
const gateCount = gateBlockingCount(gate);
|
|
34560
|
+
if (dismissed.length > 0 && dismissed.length === liveBlocking.length && dismissed.every(upheldDismissal) && (gateCount === null || gateCount <= dismissed.length)) {
|
|
34561
|
+
return {
|
|
34562
|
+
next_action: "review",
|
|
34563
|
+
reason: `The CI adjudicator upheld every dismissal on this head; run ${commandHint(REVIEW_COMMAND, "")}, and that review no longer counts them.`
|
|
34564
|
+
};
|
|
34565
|
+
}
|
|
34566
|
+
if (canonicalStatusText(gate.description ?? "").startsWith("crysk skipped the review")) {
|
|
34567
|
+
return {
|
|
34568
|
+
next_action: "override-or-fix",
|
|
34569
|
+
reason: `The review on this head was skipped (${gate.description}); run ${commandHint(REVIEW_COMMAND, "")} to review it anyway, or override the gate.`
|
|
34570
|
+
};
|
|
34571
|
+
}
|
|
34572
|
+
if (PARTIAL_REVIEW_AGAIN_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
34573
|
+
return {
|
|
34574
|
+
next_action: "override-or-fix",
|
|
34575
|
+
reason: `The review is partial again with the same hunters failing: a retry already failed the same way; fix the failing hunter's route (model or provider) or run ${commandHint(OVERRIDE_COMMAND, "")}.`
|
|
34576
|
+
};
|
|
34577
|
+
}
|
|
34578
|
+
if (PARTIAL_REVIEW_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
34579
|
+
return {
|
|
34580
|
+
next_action: "review",
|
|
34581
|
+
reason: `The last review of this head was partial (some reviewers failed); run ${commandHint(REVIEW_COMMAND, "")}, which retries it. If the same reviewers fail every time (an unavailable model, a broken route), fix that route or override the gate.`
|
|
34582
|
+
};
|
|
34583
|
+
}
|
|
34584
|
+
if (liveBlocking.length > 0) {
|
|
34585
|
+
return {
|
|
34586
|
+
next_action: "override-or-fix",
|
|
34587
|
+
reason: `The gate is red with ${liveBlocking.length} live blocking finding(s), all triaged and none applied or pending a CI ruling (a rejected dismissal, or a deferred or misclassified tag, never leaves the count): fix and push, or override the gate.`
|
|
34588
|
+
};
|
|
34589
|
+
}
|
|
34590
|
+
return {
|
|
34591
|
+
next_action: "override-or-fix",
|
|
34592
|
+
reason: `The gate is red and names no live blocking finding on this head (${gate.description ?? "no description"}); read the gate description.`
|
|
34593
|
+
};
|
|
34594
|
+
}
|
|
34595
|
+
function shouldWaitPrStatus(input) {
|
|
34596
|
+
const { status, issueComments, nowMs, elapsedMs } = input;
|
|
34597
|
+
const startupGraceMs = input.startupGraceMs ?? STATUS_WAIT_STARTUP_GRACE_MS;
|
|
34598
|
+
if (status.next_action === "wait")
|
|
34599
|
+
return true;
|
|
34600
|
+
if (status.gate.state === "none" && elapsedMs < startupGraceMs) {
|
|
34601
|
+
return true;
|
|
34602
|
+
}
|
|
34603
|
+
const gateMs = status.gate.created_at !== null ? Date.parse(status.gate.created_at) : Number.NEGATIVE_INFINITY;
|
|
34604
|
+
for (const comment of issueComments) {
|
|
34605
|
+
if (!TRIGGER_COMMANDS.some((command) => isCommand(comment.body, command))) {
|
|
34606
|
+
continue;
|
|
34607
|
+
}
|
|
34608
|
+
if (comment.created_at === undefined)
|
|
34609
|
+
continue;
|
|
34610
|
+
const commentMs = Date.parse(comment.created_at);
|
|
34611
|
+
if (!Number.isFinite(commentMs))
|
|
34612
|
+
continue;
|
|
34613
|
+
const ageMs = nowMs - commentMs;
|
|
34614
|
+
if (ageMs >= 0 && ageMs < startupGraceMs && commentMs > gateMs) {
|
|
34615
|
+
return true;
|
|
34616
|
+
}
|
|
34617
|
+
}
|
|
34618
|
+
return false;
|
|
34619
|
+
}
|
|
34620
|
+
function renderPrStatusLines(status) {
|
|
34621
|
+
const gate = status.gate.description === null ? status.gate.state : `${status.gate.state} (${status.gate.description})`;
|
|
34622
|
+
return [
|
|
34623
|
+
`crysk status: PR #${status.pr} at ${status.head.slice(0, 7)}`,
|
|
34624
|
+
`gate: ${gate}`,
|
|
34625
|
+
`findings: ${status.findings.length} posted, ${status.unresolved_blocking} unresolved blocking`,
|
|
34626
|
+
`next: ${status.next_action} \u2014 ${status.reason}`
|
|
34627
|
+
];
|
|
34628
|
+
}
|
|
34629
|
+
|
|
34630
|
+
// src/pr/answered-findings.ts
|
|
34631
|
+
init_preflight2();
|
|
34632
|
+
init_triage();
|
|
34633
|
+
init_preflight3();
|
|
34634
|
+
function isTriageReply(body) {
|
|
34635
|
+
return parseTriageMarker(body) !== null;
|
|
34636
|
+
}
|
|
34637
|
+
function triageReplyAuthors(comments) {
|
|
34638
|
+
const authors = new Set;
|
|
34639
|
+
for (const comment of comments) {
|
|
34640
|
+
if (isTriageReply(comment.body))
|
|
34641
|
+
authors.add(comment.user);
|
|
34642
|
+
}
|
|
34643
|
+
return [...authors];
|
|
34644
|
+
}
|
|
34645
|
+
function trustedPoster(user, trustedActors) {
|
|
34646
|
+
if (trustedActors === undefined)
|
|
34647
|
+
return true;
|
|
34648
|
+
return user === CI_ADJUDICATOR_LOGIN || trustedActors.has(user);
|
|
34649
|
+
}
|
|
34650
|
+
function isGateInput(body) {
|
|
34651
|
+
return parseFindingMarker(body) !== null || parsePrCommentMarker(body) !== null;
|
|
34652
|
+
}
|
|
34653
|
+
function isStaleReply(comment, reviewedHead, verdictAt) {
|
|
34654
|
+
const marker = parseTriageMarker(comment.body);
|
|
34655
|
+
if (marker === null || marker.headSha === reviewedHead)
|
|
34656
|
+
return false;
|
|
34657
|
+
const createdAt = comment.created_at === undefined ? Number.NaN : Date.parse(comment.created_at);
|
|
34658
|
+
return verdictAt === null || Number.isNaN(createdAt) || createdAt <= verdictAt;
|
|
34659
|
+
}
|
|
34660
|
+
function trustedComments(comments, writers, trustedActors, reviewedHead, verdictAt) {
|
|
34661
|
+
const kept = [];
|
|
34662
|
+
for (const comment of comments) {
|
|
34663
|
+
if (isTriageReply(comment.body)) {
|
|
34664
|
+
if (isStaleReply(comment, reviewedHead, verdictAt))
|
|
34665
|
+
continue;
|
|
34666
|
+
const writer = writers.get(comment.user);
|
|
34667
|
+
if (writer === undefined || writer === null)
|
|
34668
|
+
return null;
|
|
34669
|
+
if (writer)
|
|
34670
|
+
kept.push(comment);
|
|
34671
|
+
continue;
|
|
34672
|
+
}
|
|
34673
|
+
if (isGateInput(comment.body) && !trustedPoster(comment.user, trustedActors))
|
|
34674
|
+
continue;
|
|
34675
|
+
kept.push(comment);
|
|
34676
|
+
}
|
|
34677
|
+
return kept;
|
|
34678
|
+
}
|
|
34679
|
+
function answeredBlockingFindings(input) {
|
|
34680
|
+
const parsedAt = input.verdictAt === null ? Number.NaN : Date.parse(input.verdictAt);
|
|
34681
|
+
const verdictAt = Number.isNaN(parsedAt) ? null : parsedAt;
|
|
34682
|
+
const issueComments = trustedComments(input.issueComments, input.writers, input.trustedActors, input.reviewedHead, verdictAt);
|
|
34683
|
+
const reviewComments = trustedComments(input.reviewComments, input.writers, input.trustedActors, input.reviewedHead, verdictAt);
|
|
34684
|
+
if (issueComments === null || reviewComments === null)
|
|
34685
|
+
return null;
|
|
34686
|
+
const findings = liveBlockingFindings({
|
|
34687
|
+
pr: input.pr,
|
|
34688
|
+
head: input.reviewedHead,
|
|
34689
|
+
nowMs: 0,
|
|
34690
|
+
statuses: [],
|
|
34691
|
+
issueComments,
|
|
34692
|
+
reviewComments
|
|
34693
|
+
});
|
|
34694
|
+
if (findings.some((finding) => finding.tier === TIER_UNRECOVERABLE))
|
|
34695
|
+
return null;
|
|
34696
|
+
let open3 = 0;
|
|
34697
|
+
for (const finding of findings) {
|
|
34698
|
+
const triage = finding.triage;
|
|
34699
|
+
const answered = triage !== null && finding.head !== null && triage.head === finding.head && (triage.tag === "applied" || triage.tag === "dismissed" && finding.ci_verdict === "upheld");
|
|
34700
|
+
if (!answered)
|
|
34701
|
+
open3++;
|
|
34702
|
+
}
|
|
34703
|
+
return { blocking: findings.length, open: open3 };
|
|
34704
|
+
}
|
|
34705
|
+
|
|
34124
34706
|
// src/pr/ci-admission-gate.ts
|
|
34125
34707
|
init_preflight2();
|
|
34126
34708
|
init_primitives();
|
|
@@ -34176,6 +34758,16 @@ async function evaluateCiAdmissionGate(input) {
|
|
|
34176
34758
|
extra: config.ci_trusted_actors
|
|
34177
34759
|
});
|
|
34178
34760
|
const allComments = [...reviewComments, ...issueComments];
|
|
34761
|
+
const readAnswered = answeredReader({
|
|
34762
|
+
operatorRoot,
|
|
34763
|
+
prNumber,
|
|
34764
|
+
reviewedHead: authorityFailOpen ? null : summaryHead,
|
|
34765
|
+
issueComments,
|
|
34766
|
+
reviewComments,
|
|
34767
|
+
trustedActors,
|
|
34768
|
+
spawnFn,
|
|
34769
|
+
sleepFn: input.sleepFn ?? Bun.sleep
|
|
34770
|
+
});
|
|
34179
34771
|
const postedFindings = summaryHead === null ? null : scanPostedFindingTiers({
|
|
34180
34772
|
summaryHead,
|
|
34181
34773
|
comments: allComments,
|
|
@@ -34283,7 +34875,8 @@ async function evaluateCiAdmissionGate(input) {
|
|
|
34283
34875
|
admission: {
|
|
34284
34876
|
reason: admissionVerdict.reason,
|
|
34285
34877
|
reviewedHead: summaryHead,
|
|
34286
|
-
priorBlocking: admissionVerdict.prior.blocking
|
|
34878
|
+
priorBlocking: admissionVerdict.prior.blocking,
|
|
34879
|
+
readAnswered
|
|
34287
34880
|
}
|
|
34288
34881
|
});
|
|
34289
34882
|
return { ciPolicy, ciPolicyHash, ledgerRecords, exitCode };
|
|
@@ -34315,14 +34908,15 @@ async function evaluateCiAdmissionGate(input) {
|
|
|
34315
34908
|
isCi,
|
|
34316
34909
|
stepSummaryFlag: options.stepSummary,
|
|
34317
34910
|
plan,
|
|
34318
|
-
noticeMessage: `crysk
|
|
34911
|
+
noticeMessage: `crysk automatic reviews are done for this PR \u2014 ${manualReason}`,
|
|
34319
34912
|
ciMode: input.ciMode,
|
|
34320
34913
|
headSha,
|
|
34321
34914
|
spawnFn,
|
|
34322
34915
|
admission: {
|
|
34323
34916
|
reason: admissionVerdict.reason,
|
|
34324
34917
|
reviewedHead: summaryHead,
|
|
34325
|
-
priorBlocking: admissionVerdict.prior.blocking
|
|
34918
|
+
priorBlocking: admissionVerdict.prior.blocking,
|
|
34919
|
+
readAnswered
|
|
34326
34920
|
}
|
|
34327
34921
|
});
|
|
34328
34922
|
return { ciPolicy, ciPolicyHash, ledgerRecords, exitCode };
|
|
@@ -34423,6 +35017,30 @@ async function stoppedByMaintainer(operatorRoot, issueComments, spawnFn, sleepFn
|
|
|
34423
35017
|
}
|
|
34424
35018
|
return false;
|
|
34425
35019
|
}
|
|
35020
|
+
function answeredReader(input) {
|
|
35021
|
+
return async (verdictAt) => {
|
|
35022
|
+
const reviewedHead = input.reviewedHead;
|
|
35023
|
+
if (reviewedHead === null)
|
|
35024
|
+
return null;
|
|
35025
|
+
const writers = new Map;
|
|
35026
|
+
for (const login of triageReplyAuthors([
|
|
35027
|
+
...input.reviewComments,
|
|
35028
|
+
...input.issueComments
|
|
35029
|
+
])) {
|
|
35030
|
+
const permission = await stopAuthorPermission(input.operatorRoot, login, input.spawnFn, input.sleepFn);
|
|
35031
|
+
writers.set(login, permission === null ? null : permission === "admin" || permission === "write");
|
|
35032
|
+
}
|
|
35033
|
+
return answeredBlockingFindings({
|
|
35034
|
+
pr: input.prNumber,
|
|
35035
|
+
reviewedHead,
|
|
35036
|
+
issueComments: input.issueComments,
|
|
35037
|
+
reviewComments: input.reviewComments,
|
|
35038
|
+
trustedActors: input.trustedActors,
|
|
35039
|
+
writers,
|
|
35040
|
+
verdictAt
|
|
35041
|
+
});
|
|
35042
|
+
};
|
|
35043
|
+
}
|
|
34426
35044
|
var STOP_PERMISSION_RETRY_DELAY_MS = 2000;
|
|
34427
35045
|
var STOP_PERMISSION_TIMEOUT_MS = 30000;
|
|
34428
35046
|
async function stopAuthorPermission(operatorRoot, login, spawnFn, sleepFn) {
|
|
@@ -40407,415 +41025,6 @@ async function skillsInstallCommand(options, deps = {}) {
|
|
|
40407
41025
|
|
|
40408
41026
|
// src/commands/status.ts
|
|
40409
41027
|
init_git();
|
|
40410
|
-
|
|
40411
|
-
// src/pr/pr-status.ts
|
|
40412
|
-
init_outcome();
|
|
40413
|
-
init_override();
|
|
40414
|
-
init_trigger();
|
|
40415
|
-
init_preflight2();
|
|
40416
|
-
init_triage();
|
|
40417
|
-
init_preflight3();
|
|
40418
|
-
init_brand();
|
|
40419
|
-
var PR_STATUS_SCHEMA = "pr-hero.status/v1";
|
|
40420
|
-
var STATUS_WAIT_POLL_INTERVAL_MS = 15000;
|
|
40421
|
-
var STATUS_WAIT_STARTUP_GRACE_MS = 180000;
|
|
40422
|
-
var STATUS_WAIT_MAX_MS = IN_FLIGHT_TTL_MS;
|
|
40423
|
-
var TRIGGER_COMMANDS = [REVIEW_COMMAND, REVIEW_FULL_COMMAND, RECHECK_COMMAND];
|
|
40424
|
-
var IN_FLIGHT_WINDOW_MINUTES = Math.round(IN_FLIGHT_TTL_MS / 60000);
|
|
40425
|
-
function buildPrStatus(input) {
|
|
40426
|
-
const gate = readGate(input);
|
|
40427
|
-
const summary = readSummary(input.issueComments);
|
|
40428
|
-
const analyzed = readFindings(input, summary.rows);
|
|
40429
|
-
const liveBlocking = analyzed.filter((a) => a.finding.blocking && a.finding.live_on_head);
|
|
40430
|
-
const decision = decideNext(gate, analyzed, input.head, summary);
|
|
40431
|
-
return {
|
|
40432
|
-
schema: PR_STATUS_SCHEMA,
|
|
40433
|
-
pr: input.pr,
|
|
40434
|
-
head: input.head,
|
|
40435
|
-
gate,
|
|
40436
|
-
report: {
|
|
40437
|
-
head: summary.head,
|
|
40438
|
-
complete: summary.complete,
|
|
40439
|
-
reviews: summary.reviews,
|
|
40440
|
-
outcome_code: outcomeCodeOf(input.issueComments)
|
|
40441
|
-
},
|
|
40442
|
-
findings: analyzed.map((a) => a.finding),
|
|
40443
|
-
unresolved_blocking: unresolvedBlocking(gate, liveBlocking.filter((a) => !upheldDismissal(a)).length),
|
|
40444
|
-
next_action: decision.next_action,
|
|
40445
|
-
reason: decision.reason
|
|
40446
|
-
};
|
|
40447
|
-
}
|
|
40448
|
-
function readGate(input) {
|
|
40449
|
-
const latest = latestStatusInContext(input.statuses, COMMIT_STATUS_CONTEXT);
|
|
40450
|
-
if (latest === null) {
|
|
40451
|
-
return {
|
|
40452
|
-
state: "none",
|
|
40453
|
-
description: null,
|
|
40454
|
-
target_url: null,
|
|
40455
|
-
created_at: null,
|
|
40456
|
-
pending_in_flight: false,
|
|
40457
|
-
override: { active: false, by: null }
|
|
40458
|
-
};
|
|
40459
|
-
}
|
|
40460
|
-
const active = isOverrideStatus(latest);
|
|
40461
|
-
const description = latest.description ?? null;
|
|
40462
|
-
return {
|
|
40463
|
-
state: gateStateOf(latest.state),
|
|
40464
|
-
description,
|
|
40465
|
-
target_url: latest.target_url ?? null,
|
|
40466
|
-
created_at: latest.created_at,
|
|
40467
|
-
pending_in_flight: isInFlightCommitStatus(input.statuses, input.nowMs),
|
|
40468
|
-
override: {
|
|
40469
|
-
active,
|
|
40470
|
-
by: active && description !== null ? overrideActorOf(description) : null
|
|
40471
|
-
}
|
|
40472
|
-
};
|
|
40473
|
-
}
|
|
40474
|
-
function gateStateOf(state) {
|
|
40475
|
-
if (state === "success" || state === "failure" || state === "error" || state === "pending") {
|
|
40476
|
-
return state;
|
|
40477
|
-
}
|
|
40478
|
-
return "error";
|
|
40479
|
-
}
|
|
40480
|
-
function readSummary(comments) {
|
|
40481
|
-
const id = findMarkedCommentId(comments);
|
|
40482
|
-
const body = comments.find((c) => c.id === id)?.body ?? null;
|
|
40483
|
-
if (id === null || body === null) {
|
|
40484
|
-
return { head: null, complete: null, reviews: null, rows: [] };
|
|
40485
|
-
}
|
|
40486
|
-
const marker = parsePrCommentMarker(body);
|
|
40487
|
-
const state = parseStateBlock(body);
|
|
40488
|
-
return {
|
|
40489
|
-
head: marker?.head ?? null,
|
|
40490
|
-
complete: marker?.complete ?? null,
|
|
40491
|
-
reviews: state?.reviews ?? null,
|
|
40492
|
-
rows: state?.findings ?? []
|
|
40493
|
-
};
|
|
40494
|
-
}
|
|
40495
|
-
function outcomeCodeOf(comments) {
|
|
40496
|
-
let newest = null;
|
|
40497
|
-
for (const comment of comments) {
|
|
40498
|
-
if (matchMarkerPrefix(comment.body, OUTCOME_MARKER_PREFIX) === undefined) {
|
|
40499
|
-
continue;
|
|
40500
|
-
}
|
|
40501
|
-
if (newest === null || comment.id > newest.id)
|
|
40502
|
-
newest = comment;
|
|
40503
|
-
}
|
|
40504
|
-
return newest === null ? null : parseOutcomeCode(newest.body);
|
|
40505
|
-
}
|
|
40506
|
-
function readFindings(input, rows) {
|
|
40507
|
-
const sources = [
|
|
40508
|
-
...input.reviewComments.map((c) => ({
|
|
40509
|
-
id: c.id,
|
|
40510
|
-
body: c.body,
|
|
40511
|
-
channel: "inline",
|
|
40512
|
-
livePath: c.path,
|
|
40513
|
-
liveLine: c.line ?? undefined
|
|
40514
|
-
})),
|
|
40515
|
-
...input.issueComments.map((c) => ({
|
|
40516
|
-
id: c.id,
|
|
40517
|
-
body: c.body,
|
|
40518
|
-
channel: "outside"
|
|
40519
|
-
}))
|
|
40520
|
-
].sort((a, b) => a.id - b.id);
|
|
40521
|
-
const posted = [];
|
|
40522
|
-
for (const source of sources) {
|
|
40523
|
-
const marker = parseFindingMarker(source.body);
|
|
40524
|
-
if (marker !== null)
|
|
40525
|
-
posted.push({ source, marker });
|
|
40526
|
-
}
|
|
40527
|
-
const bound = bindPriorsToPosted(rows, posted.map(({ source, marker }) => ({
|
|
40528
|
-
id: source.id,
|
|
40529
|
-
marker,
|
|
40530
|
-
livePath: source.livePath,
|
|
40531
|
-
liveLine: source.liveLine
|
|
40532
|
-
})));
|
|
40533
|
-
const rowByComment = new Map;
|
|
40534
|
-
for (const row2 of rows) {
|
|
40535
|
-
const comment = bound.get(row2.id);
|
|
40536
|
-
if (comment !== undefined)
|
|
40537
|
-
rowByComment.set(comment.id, row2);
|
|
40538
|
-
}
|
|
40539
|
-
const out = [];
|
|
40540
|
-
for (const { source, marker } of posted) {
|
|
40541
|
-
const row2 = rowByComment.get(source.id);
|
|
40542
|
-
const badge = parseFindingCommentBadge(source.body);
|
|
40543
|
-
const replies = repliesTo(source, input);
|
|
40544
|
-
const newest = newestReply(replies);
|
|
40545
|
-
const triage = newest?.marker ?? null;
|
|
40546
|
-
const tier = badge?.tier ?? row2?.tier ?? TIER_UNRECOVERABLE;
|
|
40547
|
-
out.push({
|
|
40548
|
-
finding: {
|
|
40549
|
-
id: row2?.id ?? null,
|
|
40550
|
-
path: marker.path,
|
|
40551
|
-
line: marker.line,
|
|
40552
|
-
head: marker.headSha,
|
|
40553
|
-
comment_id: source.id,
|
|
40554
|
-
channel: source.channel,
|
|
40555
|
-
severity: badge?.sev ?? (row2 !== undefined && row2.sev !== SEVERITY_UNRECOVERABLE ? row2.sev : null),
|
|
40556
|
-
tier,
|
|
40557
|
-
blocking: tier !== "advisory",
|
|
40558
|
-
live_on_head: row2 !== undefined || marker.headSha === input.head,
|
|
40559
|
-
triage: triage === null ? null : {
|
|
40560
|
-
tag: triage.tag,
|
|
40561
|
-
verdict: triage.verdict ?? null,
|
|
40562
|
-
actor: triage.actor,
|
|
40563
|
-
head: triage.headSha
|
|
40564
|
-
},
|
|
40565
|
-
ci_verdict: source.channel === "inline" ? ciVerdictOf(source.id, newest?.id ?? null, input) : null
|
|
40566
|
-
},
|
|
40567
|
-
triagedAtPostedHead: replies.some((r) => r.marker.headSha === marker.headSha)
|
|
40568
|
-
});
|
|
40569
|
-
}
|
|
40570
|
-
for (const row2 of rows) {
|
|
40571
|
-
if (bound.has(row2.id))
|
|
40572
|
-
continue;
|
|
40573
|
-
out.push({ finding: unthreadedFinding(row2), triagedAtPostedHead: false });
|
|
40574
|
-
}
|
|
40575
|
-
return out;
|
|
40576
|
-
}
|
|
40577
|
-
function unthreadedFinding(row2) {
|
|
40578
|
-
const first = row2.locs[0];
|
|
40579
|
-
const span = first === undefined ? undefined : parseProofRefLocs(first)[0];
|
|
40580
|
-
const tier = row2.tier;
|
|
40581
|
-
return {
|
|
40582
|
-
id: row2.id,
|
|
40583
|
-
path: span?.path ?? first ?? "",
|
|
40584
|
-
line: span?.span.start ?? 0,
|
|
40585
|
-
head: null,
|
|
40586
|
-
comment_id: null,
|
|
40587
|
-
channel: row2.channel,
|
|
40588
|
-
severity: row2.sev !== SEVERITY_UNRECOVERABLE ? row2.sev : null,
|
|
40589
|
-
tier,
|
|
40590
|
-
blocking: tier !== "advisory",
|
|
40591
|
-
live_on_head: true,
|
|
40592
|
-
triage: null,
|
|
40593
|
-
ci_verdict: null
|
|
40594
|
-
};
|
|
40595
|
-
}
|
|
40596
|
-
function ciVerdictOf(threadId, newestTriageId, input) {
|
|
40597
|
-
if (newestTriageId === null)
|
|
40598
|
-
return null;
|
|
40599
|
-
let best = null;
|
|
40600
|
-
for (const comment of input.reviewComments) {
|
|
40601
|
-
if (comment.in_reply_to_id !== threadId)
|
|
40602
|
-
continue;
|
|
40603
|
-
if (comment.user !== CI_ADJUDICATOR_LOGIN)
|
|
40604
|
-
continue;
|
|
40605
|
-
const marker = parseAdjudicationMarker(comment.body);
|
|
40606
|
-
if (marker === null)
|
|
40607
|
-
continue;
|
|
40608
|
-
if (marker.reply !== newestTriageId || marker.head !== input.head)
|
|
40609
|
-
continue;
|
|
40610
|
-
if (best === null || comment.id > best.id) {
|
|
40611
|
-
best = { id: comment.id, verdict: marker.verdict };
|
|
40612
|
-
}
|
|
40613
|
-
}
|
|
40614
|
-
return best?.verdict ?? null;
|
|
40615
|
-
}
|
|
40616
|
-
function repliesTo(source, input) {
|
|
40617
|
-
const out = [];
|
|
40618
|
-
if (source.channel === "inline") {
|
|
40619
|
-
for (const reply of input.reviewComments) {
|
|
40620
|
-
if (reply.in_reply_to_id !== source.id)
|
|
40621
|
-
continue;
|
|
40622
|
-
const marker = parseTriageMarker(reply.body);
|
|
40623
|
-
if (marker !== null)
|
|
40624
|
-
out.push({ id: reply.id, marker });
|
|
40625
|
-
}
|
|
40626
|
-
return out;
|
|
40627
|
-
}
|
|
40628
|
-
const link = new RegExp(`#issuecomment-${source.id}(?!\\d)`);
|
|
40629
|
-
for (const comment of input.issueComments) {
|
|
40630
|
-
const marker = parseTriageMarker(comment.body);
|
|
40631
|
-
if (marker === null || !link.test(comment.body))
|
|
40632
|
-
continue;
|
|
40633
|
-
out.push({ id: comment.id, marker });
|
|
40634
|
-
}
|
|
40635
|
-
return out;
|
|
40636
|
-
}
|
|
40637
|
-
function newestReply(replies) {
|
|
40638
|
-
let newest = null;
|
|
40639
|
-
for (const reply of replies) {
|
|
40640
|
-
if (newest === null || reply.id > newest.id)
|
|
40641
|
-
newest = reply;
|
|
40642
|
-
}
|
|
40643
|
-
return newest;
|
|
40644
|
-
}
|
|
40645
|
-
var PARTIAL_REVIEW_GATE = /^crysk: review partial \(\d+ of \d+ hunters failed(?:, set [0-9a-f]{6})?\)/;
|
|
40646
|
-
var PARTIAL_REVIEW_AGAIN_GATE = /^crysk: review partial again \(\d+ of \d+ hunters failed(?:, set [0-9a-f]{6})?\)/;
|
|
40647
|
-
function unresolvedBlocking(gate, liveBlockingCount) {
|
|
40648
|
-
return gateBlockingCount(gate) ?? liveBlockingCount;
|
|
40649
|
-
}
|
|
40650
|
-
function gateBlockingCount(gate) {
|
|
40651
|
-
if (gate.state !== "failure" || gate.description === null)
|
|
40652
|
-
return null;
|
|
40653
|
-
const counted = /^crysk: (\d+) blocking finding\(s\)/.exec(canonicalStatusText(gate.description));
|
|
40654
|
-
return counted?.[1] === undefined ? null : Number(counted[1]);
|
|
40655
|
-
}
|
|
40656
|
-
var REVIEW_TRIGGER_GATE = /^crysk: review (budget for this PR is used up|needs a manual trigger)/;
|
|
40657
|
-
function upheldDismissal(a) {
|
|
40658
|
-
return a.finding.triage?.tag === "dismissed" && a.finding.ci_verdict === "upheld";
|
|
40659
|
-
}
|
|
40660
|
-
function decideNext(gate, analyzed, head, summary) {
|
|
40661
|
-
const liveBlocking = analyzed.filter((a) => a.finding.blocking && a.finding.live_on_head);
|
|
40662
|
-
if (gate.state === "pending") {
|
|
40663
|
-
if (gate.pending_in_flight) {
|
|
40664
|
-
return {
|
|
40665
|
-
next_action: "wait",
|
|
40666
|
-
reason: `A crysk review is in flight on this head (pending since ${gate.created_at}); wait for it to finish.`
|
|
40667
|
-
};
|
|
40668
|
-
}
|
|
40669
|
-
return {
|
|
40670
|
-
next_action: "review",
|
|
40671
|
-
reason: `The pending crysk status on this head is older than the ${IN_FLIGHT_WINDOW_MINUTES}-minute in-flight window and no run holds it; start a review.`
|
|
40672
|
-
};
|
|
40673
|
-
}
|
|
40674
|
-
if (gate.state === "none") {
|
|
40675
|
-
return {
|
|
40676
|
-
next_action: "review",
|
|
40677
|
-
reason: "No crysk gate status is on this head, so no review has run here yet; start one."
|
|
40678
|
-
};
|
|
40679
|
-
}
|
|
40680
|
-
if (gate.state === "error") {
|
|
40681
|
-
return {
|
|
40682
|
-
next_action: "review",
|
|
40683
|
-
reason: `The last crysk review on this head did not finish (${gate.description ?? "no description"}); start a review.`
|
|
40684
|
-
};
|
|
40685
|
-
}
|
|
40686
|
-
if (gate.state === "success") {
|
|
40687
|
-
if (gate.override.active) {
|
|
40688
|
-
return {
|
|
40689
|
-
next_action: "done",
|
|
40690
|
-
reason: `The gate is green through an override by @${gate.override.by ?? "an unknown login"}; nothing is owed on this head.`
|
|
40691
|
-
};
|
|
40692
|
-
}
|
|
40693
|
-
if (summary.head === head && summary.complete === false) {
|
|
40694
|
-
return {
|
|
40695
|
-
next_action: "review",
|
|
40696
|
-
reason: `The last review of this head was partial (some reviewers failed); run ${commandHint(REVIEW_COMMAND, "")}.`
|
|
40697
|
-
};
|
|
40698
|
-
}
|
|
40699
|
-
const owed = analyzed.filter((a) => a.finding.head === head && !a.triagedAtPostedHead);
|
|
40700
|
-
if (owed.length > 0) {
|
|
40701
|
-
return {
|
|
40702
|
-
next_action: "triage",
|
|
40703
|
-
reason: `The gate is green, but ${owed.length} finding(s) on this head have no reply yet; triage them.`
|
|
40704
|
-
};
|
|
40705
|
-
}
|
|
40706
|
-
return {
|
|
40707
|
-
next_action: "done",
|
|
40708
|
-
reason: "The review on this head passed the gate, and every finding on this head has a reply."
|
|
40709
|
-
};
|
|
40710
|
-
}
|
|
40711
|
-
if (REVIEW_TRIGGER_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
40712
|
-
return {
|
|
40713
|
-
next_action: "review",
|
|
40714
|
-
reason: `The automatic review budget for this PR is used up, or the review policy is manual (ci_review_policy is manual_only); comment ${commandHint(REVIEW_COMMAND, "")} to review this head.`
|
|
40715
|
-
};
|
|
40716
|
-
}
|
|
40717
|
-
const untriaged = liveBlocking.filter((a) => a.finding.comment_id !== null && !a.triagedAtPostedHead);
|
|
40718
|
-
if (untriaged.length > 0) {
|
|
40719
|
-
return {
|
|
40720
|
-
next_action: "triage",
|
|
40721
|
-
reason: `${untriaged.length} live blocking finding(s) on this head have no triage reply at the head they were posted on; triage them first.`
|
|
40722
|
-
};
|
|
40723
|
-
}
|
|
40724
|
-
const unthreaded = liveBlocking.filter((a) => a.finding.comment_id === null);
|
|
40725
|
-
if (unthreaded.length > 0 && gateBlockingCount(gate) !== null) {
|
|
40726
|
-
const ids = unthreaded.map((a) => a.finding.id ?? "unnamed").join(", ");
|
|
40727
|
-
return {
|
|
40728
|
-
next_action: "fix",
|
|
40729
|
-
reason: `${unthreaded.length} live blocking finding(s) (${ids}) have no comment thread to answer (summary-only or never posted inline); fix them and push, or ${commandHint(OVERRIDE_COMMAND, "")}.`
|
|
40730
|
-
};
|
|
40731
|
-
}
|
|
40732
|
-
const applied = liveBlocking.filter((a) => a.finding.triage?.tag === "applied");
|
|
40733
|
-
if (applied.length > 0) {
|
|
40734
|
-
return {
|
|
40735
|
-
next_action: "fix",
|
|
40736
|
-
reason: "A live blocking finding is tagged applied; push the fix, and the next review verifies it."
|
|
40737
|
-
};
|
|
40738
|
-
}
|
|
40739
|
-
const dismissed = liveBlocking.filter((a) => a.finding.triage?.tag === "dismissed");
|
|
40740
|
-
const pendingRulings = dismissed.filter((a) => a.finding.channel === "inline" && (a.finding.ci_verdict === null || a.finding.ci_verdict === "inconclusive"));
|
|
40741
|
-
if (pendingRulings.length > 0) {
|
|
40742
|
-
return {
|
|
40743
|
-
next_action: "recheck",
|
|
40744
|
-
reason: `${pendingRulings.length} live blocking finding(s) are answered dismissed with no CI ruling on this head (or an inconclusive one); comment ${commandHint(RECHECK_COMMAND, "")} so the CI adjudicator rules on them.`
|
|
40745
|
-
};
|
|
40746
|
-
}
|
|
40747
|
-
const gateCount = gateBlockingCount(gate);
|
|
40748
|
-
if (dismissed.length > 0 && dismissed.length === liveBlocking.length && dismissed.every(upheldDismissal) && (gateCount === null || gateCount <= dismissed.length)) {
|
|
40749
|
-
return {
|
|
40750
|
-
next_action: "review",
|
|
40751
|
-
reason: `The CI adjudicator upheld every dismissal on this head; run ${commandHint(REVIEW_COMMAND, "")}, and that review no longer counts them.`
|
|
40752
|
-
};
|
|
40753
|
-
}
|
|
40754
|
-
if (canonicalStatusText(gate.description ?? "").startsWith("crysk skipped the review")) {
|
|
40755
|
-
return {
|
|
40756
|
-
next_action: "override-or-fix",
|
|
40757
|
-
reason: `The review on this head was skipped (${gate.description}); run ${commandHint(REVIEW_COMMAND, "")} to review it anyway, or override the gate.`
|
|
40758
|
-
};
|
|
40759
|
-
}
|
|
40760
|
-
if (PARTIAL_REVIEW_AGAIN_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
40761
|
-
return {
|
|
40762
|
-
next_action: "override-or-fix",
|
|
40763
|
-
reason: `The review is partial again with the same hunters failing: a retry already failed the same way; fix the failing hunter's route (model or provider) or run ${commandHint(OVERRIDE_COMMAND, "")}.`
|
|
40764
|
-
};
|
|
40765
|
-
}
|
|
40766
|
-
if (PARTIAL_REVIEW_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
40767
|
-
return {
|
|
40768
|
-
next_action: "review",
|
|
40769
|
-
reason: `The last review of this head was partial (some reviewers failed); run ${commandHint(REVIEW_COMMAND, "")}, which retries it. If the same reviewers fail every time (an unavailable model, a broken route), fix that route or override the gate.`
|
|
40770
|
-
};
|
|
40771
|
-
}
|
|
40772
|
-
if (liveBlocking.length > 0) {
|
|
40773
|
-
return {
|
|
40774
|
-
next_action: "override-or-fix",
|
|
40775
|
-
reason: `The gate is red with ${liveBlocking.length} live blocking finding(s), all triaged and none applied or pending a CI ruling (a rejected dismissal, or a deferred or misclassified tag, never leaves the count): fix and push, or override the gate.`
|
|
40776
|
-
};
|
|
40777
|
-
}
|
|
40778
|
-
return {
|
|
40779
|
-
next_action: "override-or-fix",
|
|
40780
|
-
reason: `The gate is red and names no live blocking finding on this head (${gate.description ?? "no description"}); read the gate description.`
|
|
40781
|
-
};
|
|
40782
|
-
}
|
|
40783
|
-
function shouldWaitPrStatus(input) {
|
|
40784
|
-
const { status, issueComments, nowMs, elapsedMs } = input;
|
|
40785
|
-
const startupGraceMs = input.startupGraceMs ?? STATUS_WAIT_STARTUP_GRACE_MS;
|
|
40786
|
-
if (status.next_action === "wait")
|
|
40787
|
-
return true;
|
|
40788
|
-
if (status.gate.state === "none" && elapsedMs < startupGraceMs) {
|
|
40789
|
-
return true;
|
|
40790
|
-
}
|
|
40791
|
-
const gateMs = status.gate.created_at !== null ? Date.parse(status.gate.created_at) : Number.NEGATIVE_INFINITY;
|
|
40792
|
-
for (const comment of issueComments) {
|
|
40793
|
-
if (!TRIGGER_COMMANDS.some((command) => isCommand(comment.body, command))) {
|
|
40794
|
-
continue;
|
|
40795
|
-
}
|
|
40796
|
-
if (comment.created_at === undefined)
|
|
40797
|
-
continue;
|
|
40798
|
-
const commentMs = Date.parse(comment.created_at);
|
|
40799
|
-
if (!Number.isFinite(commentMs))
|
|
40800
|
-
continue;
|
|
40801
|
-
const ageMs = nowMs - commentMs;
|
|
40802
|
-
if (ageMs >= 0 && ageMs < startupGraceMs && commentMs > gateMs) {
|
|
40803
|
-
return true;
|
|
40804
|
-
}
|
|
40805
|
-
}
|
|
40806
|
-
return false;
|
|
40807
|
-
}
|
|
40808
|
-
function renderPrStatusLines(status) {
|
|
40809
|
-
const gate = status.gate.description === null ? status.gate.state : `${status.gate.state} (${status.gate.description})`;
|
|
40810
|
-
return [
|
|
40811
|
-
`crysk status: PR #${status.pr} at ${status.head.slice(0, 7)}`,
|
|
40812
|
-
`gate: ${gate}`,
|
|
40813
|
-
`findings: ${status.findings.length} posted, ${status.unresolved_blocking} unresolved blocking`,
|
|
40814
|
-
`next: ${status.next_action} \u2014 ${status.reason}`
|
|
40815
|
-
];
|
|
40816
|
-
}
|
|
40817
|
-
|
|
40818
|
-
// src/commands/status.ts
|
|
40819
41028
|
init_preflight2();
|
|
40820
41029
|
init_primitives();
|
|
40821
41030
|
init_errors();
|