@h-rig/runtime 0.0.6-alpha.11 → 0.0.6-alpha.13
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/bin/rig-agent-dispatch.js +5 -313
- package/dist/bin/rig-agent.js +3 -2
- package/dist/src/control-plane/agent-wrapper.js +10 -15
- package/dist/src/control-plane/harness-main.js +914 -153
- package/dist/src/control-plane/hooks/completion-verification.js +1182 -281
- package/dist/src/control-plane/native/git-ops.js +31 -43
- package/dist/src/control-plane/native/harness-cli.js +914 -153
- package/dist/src/control-plane/native/pr-automation.js +1008 -38
- package/dist/src/control-plane/native/pr-review-gate.js +905 -0
- package/dist/src/control-plane/native/task-ops.js +909 -151
- package/dist/src/control-plane/native/verifier.js +911 -150
- package/native/darwin-arm64/rig-git +0 -0
- package/native/darwin-arm64/rig-git.build-manifest.json +1 -1
- package/native/darwin-arm64/rig-shell +0 -0
- package/native/darwin-arm64/rig-shell.build-manifest.json +1 -1
- package/native/darwin-arm64/rig-tools +0 -0
- package/native/darwin-arm64/rig-tools.build-manifest.json +1 -1
- package/native/darwin-arm64/runtime-native.dylib +0 -0
- package/package.json +6 -6
|
@@ -3611,6 +3611,777 @@ ${JSON.stringify(result, null, 2)}
|
|
|
3611
3611
|
// packages/runtime/src/control-plane/native/verifier.ts
|
|
3612
3612
|
import { existsSync as existsSync19, mkdirSync as mkdirSync8, writeFileSync as writeFileSync8 } from "fs";
|
|
3613
3613
|
import { resolve as resolve22 } from "path";
|
|
3614
|
+
|
|
3615
|
+
// packages/runtime/src/control-plane/native/pr-review-gate.ts
|
|
3616
|
+
function parseJsonObject(value) {
|
|
3617
|
+
if (!value?.trim())
|
|
3618
|
+
return { value: {}, error: "empty JSON output" };
|
|
3619
|
+
try {
|
|
3620
|
+
const parsed = JSON.parse(value);
|
|
3621
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? { value: parsed } : { value: {}, error: "JSON output was not an object" };
|
|
3622
|
+
} catch (error) {
|
|
3623
|
+
return { value: {}, error: error instanceof Error ? error.message : String(error) };
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
function flattenPaginatedArray(value) {
|
|
3627
|
+
if (!Array.isArray(value))
|
|
3628
|
+
return null;
|
|
3629
|
+
if (value.every((entry) => Array.isArray(entry))) {
|
|
3630
|
+
return value.flatMap((entry) => entry);
|
|
3631
|
+
}
|
|
3632
|
+
return value;
|
|
3633
|
+
}
|
|
3634
|
+
function parseJsonArray(value) {
|
|
3635
|
+
if (!value?.trim())
|
|
3636
|
+
return { value: [], error: "empty JSON output" };
|
|
3637
|
+
try {
|
|
3638
|
+
const parsed = JSON.parse(value);
|
|
3639
|
+
const flattened = flattenPaginatedArray(parsed);
|
|
3640
|
+
return flattened ? { value: flattened } : { value: [], error: "JSON output was not an array" };
|
|
3641
|
+
} catch (error) {
|
|
3642
|
+
return { value: [], error: error instanceof Error ? error.message : String(error) };
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
function parseGithubPrUrl(prUrl) {
|
|
3646
|
+
const match = /^https?:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)\/?$/i.exec(prUrl.trim());
|
|
3647
|
+
if (!match)
|
|
3648
|
+
return null;
|
|
3649
|
+
const prNumber = Number.parseInt(match[3], 10);
|
|
3650
|
+
if (!Number.isFinite(prNumber))
|
|
3651
|
+
return null;
|
|
3652
|
+
return { owner: match[1], repo: match[2], repoName: `${match[1]}/${match[2]}`, prNumber };
|
|
3653
|
+
}
|
|
3654
|
+
function checkName(check) {
|
|
3655
|
+
return String(check.name ?? check.context ?? "").trim();
|
|
3656
|
+
}
|
|
3657
|
+
function checkState(check) {
|
|
3658
|
+
return String(check.conclusion ?? check.state ?? check.status ?? "").trim().toLowerCase();
|
|
3659
|
+
}
|
|
3660
|
+
function isGreptileLabel(value) {
|
|
3661
|
+
return String(value ?? "").toLowerCase().includes("greptile");
|
|
3662
|
+
}
|
|
3663
|
+
function isGreptileGithubLogin(value) {
|
|
3664
|
+
const login = String(value ?? "").toLowerCase().replace(/\[bot\]$/, "");
|
|
3665
|
+
return login === "greptile" || login === "greptile-ai" || login === "greptileai" || login === "greptile-apps";
|
|
3666
|
+
}
|
|
3667
|
+
function isPassingCheck(check) {
|
|
3668
|
+
const state = checkState(check);
|
|
3669
|
+
return ["success", "successful", "passed", "neutral", "skipped", "completed"].includes(state);
|
|
3670
|
+
}
|
|
3671
|
+
function isPendingCheck(check) {
|
|
3672
|
+
const state = checkState(check);
|
|
3673
|
+
return ["pending", "queued", "in_progress", "waiting", "requested", "expected", "action_required"].includes(state);
|
|
3674
|
+
}
|
|
3675
|
+
function isFailingCheck(check) {
|
|
3676
|
+
const state = checkState(check);
|
|
3677
|
+
return ["failure", "failed", "timed_out", "action_required", "cancelled", "canceled", "error"].includes(state);
|
|
3678
|
+
}
|
|
3679
|
+
function wildcardToRegExp(pattern) {
|
|
3680
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
3681
|
+
return new RegExp(`^${escaped}$`, "i");
|
|
3682
|
+
}
|
|
3683
|
+
function isAllowedFailure(name, allowedFailures) {
|
|
3684
|
+
return allowedFailures.some((pattern) => wildcardToRegExp(pattern).test(name));
|
|
3685
|
+
}
|
|
3686
|
+
function greptileScorePatterns() {
|
|
3687
|
+
return [
|
|
3688
|
+
/\b(?:confidence\s+score|confidence|rating|score)\s*:?\s*(\d+)\s*\/\s*(\d+)/gi,
|
|
3689
|
+
/\b(\d+)\s*\/\s*(\d+)\s*(?:confidence|rating|score)/gi,
|
|
3690
|
+
/\bgreptile[^\n]{0,80}?(\d+)\s*\/\s*(\d+)/gi
|
|
3691
|
+
];
|
|
3692
|
+
}
|
|
3693
|
+
function parseGreptileScores(input) {
|
|
3694
|
+
const text = stripHtml(input);
|
|
3695
|
+
const seen = new Set;
|
|
3696
|
+
const scores = [];
|
|
3697
|
+
for (const pattern of greptileScorePatterns()) {
|
|
3698
|
+
for (const match of text.matchAll(pattern)) {
|
|
3699
|
+
const value = Number.parseInt(match[1] || "", 10);
|
|
3700
|
+
const scale = Number.parseInt(match[2] || "", 10);
|
|
3701
|
+
if (!Number.isFinite(value) || !Number.isFinite(scale) || scale <= 0)
|
|
3702
|
+
continue;
|
|
3703
|
+
const raw = match[0] || `${value}/${scale}`;
|
|
3704
|
+
const key = `${match.index ?? -1}:${value}/${scale}:${raw.toLowerCase()}`;
|
|
3705
|
+
if (seen.has(key))
|
|
3706
|
+
continue;
|
|
3707
|
+
seen.add(key);
|
|
3708
|
+
scores.push({ value, scale, raw });
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
return scores;
|
|
3712
|
+
}
|
|
3713
|
+
function parseGreptileScore(input) {
|
|
3714
|
+
return parseGreptileScores(input)[0] ?? null;
|
|
3715
|
+
}
|
|
3716
|
+
function stripHtml(input) {
|
|
3717
|
+
return input.replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\r/g, "").replace(/\n{3,}/g, `
|
|
3718
|
+
|
|
3719
|
+
`).trim();
|
|
3720
|
+
}
|
|
3721
|
+
function containsBlockerText(input) {
|
|
3722
|
+
const text = stripHtml(input).replace(/\b(?:no|without|zero)\s+blockers?\b/gi, " ").replace(/\bno\s+changes\s+requested\b/gi, " ");
|
|
3723
|
+
return /not safe(?: to merge)?|unsafe(?: to merge)?|do not merge|cannot merge|blockers?|must fix|changes requested|please fix|needs? fix|fix this|address this/i.test(text);
|
|
3724
|
+
}
|
|
3725
|
+
function isStrictFiveOfFive(score) {
|
|
3726
|
+
return score.value === 5 && score.scale === 5;
|
|
3727
|
+
}
|
|
3728
|
+
function containsConflictingScoreText(input) {
|
|
3729
|
+
return parseGreptileScores(input).some((score) => !isStrictFiveOfFive(score));
|
|
3730
|
+
}
|
|
3731
|
+
function firstString(record, keys) {
|
|
3732
|
+
for (const key of keys) {
|
|
3733
|
+
const value = record[key];
|
|
3734
|
+
if (typeof value === "string")
|
|
3735
|
+
return value;
|
|
3736
|
+
}
|
|
3737
|
+
return "";
|
|
3738
|
+
}
|
|
3739
|
+
function arrayField(record, key) {
|
|
3740
|
+
const value = record[key];
|
|
3741
|
+
return Array.isArray(value) ? value : [];
|
|
3742
|
+
}
|
|
3743
|
+
async function runJsonArray(command, args, cwd) {
|
|
3744
|
+
const result = await command(args, { cwd });
|
|
3745
|
+
const label = `gh ${args.join(" ")}`;
|
|
3746
|
+
if (result.exitCode !== 0) {
|
|
3747
|
+
return { value: [], error: `${label} failed (${result.exitCode}): ${result.stderr ?? result.stdout ?? ""}`.trim() };
|
|
3748
|
+
}
|
|
3749
|
+
const parsed = parseJsonArray(result.stdout);
|
|
3750
|
+
return parsed.error ? { value: parsed.value, error: `${label} returned invalid JSON: ${parsed.error}` } : { value: parsed.value };
|
|
3751
|
+
}
|
|
3752
|
+
async function runJsonObject(command, args, cwd) {
|
|
3753
|
+
const result = await command(args, { cwd });
|
|
3754
|
+
const label = `gh ${args.join(" ")}`;
|
|
3755
|
+
if (result.exitCode !== 0) {
|
|
3756
|
+
return { value: {}, error: `${label} failed (${result.exitCode}): ${result.stderr ?? result.stdout ?? ""}`.trim() };
|
|
3757
|
+
}
|
|
3758
|
+
const parsed = parseJsonObject(result.stdout);
|
|
3759
|
+
return parsed.error ? { value: parsed.value, error: `${label} returned invalid JSON: ${parsed.error}` } : { value: parsed.value };
|
|
3760
|
+
}
|
|
3761
|
+
function normalizeStatusCheck(entry) {
|
|
3762
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
3763
|
+
return null;
|
|
3764
|
+
const record = entry;
|
|
3765
|
+
const name = firstString(record, ["name", "context"]);
|
|
3766
|
+
if (!name.trim())
|
|
3767
|
+
return null;
|
|
3768
|
+
const output = record.output && typeof record.output === "object" && !Array.isArray(record.output) ? record.output : null;
|
|
3769
|
+
const app = record.app && typeof record.app === "object" && !Array.isArray(record.app) ? record.app : null;
|
|
3770
|
+
return {
|
|
3771
|
+
__typename: typeof record.__typename === "string" ? record.__typename : null,
|
|
3772
|
+
name,
|
|
3773
|
+
context: typeof record.context === "string" ? record.context : null,
|
|
3774
|
+
status: typeof record.status === "string" ? record.status : null,
|
|
3775
|
+
state: typeof record.state === "string" ? record.state : null,
|
|
3776
|
+
conclusion: typeof record.conclusion === "string" ? record.conclusion : null,
|
|
3777
|
+
detailsUrl: typeof record.detailsUrl === "string" ? record.detailsUrl : typeof record.details_url === "string" ? record.details_url : typeof record.html_url === "string" ? record.html_url : typeof record.link === "string" ? record.link : null,
|
|
3778
|
+
link: typeof record.link === "string" ? record.link : typeof record.html_url === "string" ? record.html_url : null,
|
|
3779
|
+
headSha: typeof record.headSha === "string" ? record.headSha : null,
|
|
3780
|
+
head_sha: typeof record.head_sha === "string" ? record.head_sha : null,
|
|
3781
|
+
output: output ? {
|
|
3782
|
+
title: typeof output.title === "string" ? output.title : null,
|
|
3783
|
+
summary: typeof output.summary === "string" ? output.summary : null,
|
|
3784
|
+
text: typeof output.text === "string" ? output.text : null
|
|
3785
|
+
} : null,
|
|
3786
|
+
app: app ? {
|
|
3787
|
+
slug: typeof app.slug === "string" ? app.slug : null,
|
|
3788
|
+
name: typeof app.name === "string" ? app.name : null,
|
|
3789
|
+
owner: app.owner && typeof app.owner === "object" ? app.owner : null
|
|
3790
|
+
} : null
|
|
3791
|
+
};
|
|
3792
|
+
}
|
|
3793
|
+
function normalizeReview(entry) {
|
|
3794
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
3795
|
+
return null;
|
|
3796
|
+
const record = entry;
|
|
3797
|
+
return {
|
|
3798
|
+
id: typeof record.id === "string" ? record.id : typeof record.id === "number" ? String(record.id) : null,
|
|
3799
|
+
state: typeof record.state === "string" ? record.state : null,
|
|
3800
|
+
body: typeof record.body === "string" ? record.body : null,
|
|
3801
|
+
commit_id: typeof record.commit_id === "string" ? record.commit_id : typeof record.commitId === "string" ? record.commitId : record.commit && typeof record.commit === "object" && typeof record.commit.oid === "string" ? record.commit.oid : null,
|
|
3802
|
+
html_url: typeof record.html_url === "string" ? record.html_url : typeof record.url === "string" ? record.url : null,
|
|
3803
|
+
author: record.author && typeof record.author === "object" ? record.author : record.user && typeof record.user === "object" ? record.user : null
|
|
3804
|
+
};
|
|
3805
|
+
}
|
|
3806
|
+
function normalizeReviewComment(entry) {
|
|
3807
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
3808
|
+
return null;
|
|
3809
|
+
const record = entry;
|
|
3810
|
+
const body = typeof record.body === "string" ? record.body : null;
|
|
3811
|
+
const path = typeof record.path === "string" ? record.path : null;
|
|
3812
|
+
if (!body && !path)
|
|
3813
|
+
return null;
|
|
3814
|
+
return {
|
|
3815
|
+
id: typeof record.id === "string" || typeof record.id === "number" ? record.id : null,
|
|
3816
|
+
user: record.user && typeof record.user === "object" ? record.user : null,
|
|
3817
|
+
author: record.author && typeof record.author === "object" ? record.author : null,
|
|
3818
|
+
body,
|
|
3819
|
+
path,
|
|
3820
|
+
html_url: typeof record.html_url === "string" ? record.html_url : null,
|
|
3821
|
+
url: typeof record.url === "string" ? record.url : null,
|
|
3822
|
+
commit_id: typeof record.commit_id === "string" ? record.commit_id : null,
|
|
3823
|
+
original_commit_id: typeof record.original_commit_id === "string" ? record.original_commit_id : null
|
|
3824
|
+
};
|
|
3825
|
+
}
|
|
3826
|
+
function normalizeIssueComment(entry) {
|
|
3827
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
3828
|
+
return null;
|
|
3829
|
+
const record = entry;
|
|
3830
|
+
const body = typeof record.body === "string" ? record.body : null;
|
|
3831
|
+
if (!body)
|
|
3832
|
+
return null;
|
|
3833
|
+
return {
|
|
3834
|
+
id: typeof record.id === "string" || typeof record.id === "number" ? record.id : null,
|
|
3835
|
+
user: record.user && typeof record.user === "object" ? record.user : null,
|
|
3836
|
+
author: record.author && typeof record.author === "object" ? record.author : null,
|
|
3837
|
+
body,
|
|
3838
|
+
html_url: typeof record.html_url === "string" ? record.html_url : null,
|
|
3839
|
+
url: typeof record.url === "string" ? record.url : null,
|
|
3840
|
+
created_at: typeof record.created_at === "string" ? record.created_at : null
|
|
3841
|
+
};
|
|
3842
|
+
}
|
|
3843
|
+
function normalizeReviewThread(entry) {
|
|
3844
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
3845
|
+
return null;
|
|
3846
|
+
const record = entry;
|
|
3847
|
+
return {
|
|
3848
|
+
id: typeof record.id === "string" ? record.id : null,
|
|
3849
|
+
isResolved: typeof record.isResolved === "boolean" ? record.isResolved : null,
|
|
3850
|
+
isOutdated: typeof record.isOutdated === "boolean" ? record.isOutdated : null,
|
|
3851
|
+
comments: record.comments && typeof record.comments === "object" ? record.comments : null
|
|
3852
|
+
};
|
|
3853
|
+
}
|
|
3854
|
+
function relevantIssueComment(comment) {
|
|
3855
|
+
const login = comment.user?.login ?? comment.author?.login ?? "";
|
|
3856
|
+
const body = comment.body ?? "";
|
|
3857
|
+
return isGreptileGithubLogin(login) || /greptile|blocker|unsafe|not safe|do not merge|must fix|please fix|changes requested|score|confidence|\b\d+\s*\/\s*5\b/i.test(body);
|
|
3858
|
+
}
|
|
3859
|
+
function latestThreadComment(thread) {
|
|
3860
|
+
const nodes = thread.comments?.nodes ?? [];
|
|
3861
|
+
return nodes.length > 0 ? nodes[nodes.length - 1] : null;
|
|
3862
|
+
}
|
|
3863
|
+
function unresolvedThreadSummaries(threads) {
|
|
3864
|
+
return threads.flatMap((thread) => {
|
|
3865
|
+
if (thread.isResolved === true || thread.isOutdated === true)
|
|
3866
|
+
return [];
|
|
3867
|
+
const latest = latestThreadComment(thread);
|
|
3868
|
+
if (!latest)
|
|
3869
|
+
return ["Unresolved review thread"];
|
|
3870
|
+
const path = latest.path ? ` on ${latest.path}` : "";
|
|
3871
|
+
return [`Unresolved review thread${path}: ${(latest.body ?? "").trim() || "(empty comment)"}`];
|
|
3872
|
+
});
|
|
3873
|
+
}
|
|
3874
|
+
function collectBodies(evidence) {
|
|
3875
|
+
return [
|
|
3876
|
+
evidence.title ?? "",
|
|
3877
|
+
evidence.body,
|
|
3878
|
+
...evidence.reviews.map((review) => review.body ?? ""),
|
|
3879
|
+
...evidence.changedFileReviewComments.map((comment) => comment.body ?? ""),
|
|
3880
|
+
...evidence.relevantIssueComments.map((comment) => comment.body ?? ""),
|
|
3881
|
+
...evidence.reviewThreads.flatMap((thread) => thread.comments?.nodes?.map((comment) => comment.body ?? "") ?? []),
|
|
3882
|
+
...(evidence.apiSignals ?? []).map((signal) => signal.body ?? "")
|
|
3883
|
+
].filter((body) => body.trim().length > 0);
|
|
3884
|
+
}
|
|
3885
|
+
function bodyExcerpt(body) {
|
|
3886
|
+
const text = stripHtml(body).replace(/\s+/g, " ").trim();
|
|
3887
|
+
return text.length > 240 ? `${text.slice(0, 237)}...` : text;
|
|
3888
|
+
}
|
|
3889
|
+
function makeGreptileSignal(input) {
|
|
3890
|
+
const scores = parseGreptileScores(input.body);
|
|
3891
|
+
const reviewedSha = input.reviewedSha?.trim() || null;
|
|
3892
|
+
const current = reviewedSha ? reviewedSha === input.currentHeadSha : null;
|
|
3893
|
+
const blocker = input.blocker ?? containsBlockerText(input.body);
|
|
3894
|
+
const explicitApproval = input.explicitApproval ?? false;
|
|
3895
|
+
return {
|
|
3896
|
+
source: input.source,
|
|
3897
|
+
trusted: input.trusted,
|
|
3898
|
+
authorLogin: input.authorLogin ?? null,
|
|
3899
|
+
reviewedSha,
|
|
3900
|
+
current,
|
|
3901
|
+
stale: current === false,
|
|
3902
|
+
score: scores[0] ?? null,
|
|
3903
|
+
scores,
|
|
3904
|
+
explicitApproval,
|
|
3905
|
+
blocker,
|
|
3906
|
+
actionable: input.actionable ?? blocker,
|
|
3907
|
+
bodyExcerpt: bodyExcerpt(input.body),
|
|
3908
|
+
body: input.body,
|
|
3909
|
+
allScores: scores
|
|
3910
|
+
};
|
|
3911
|
+
}
|
|
3912
|
+
function reviewAuthorLogin(review) {
|
|
3913
|
+
return review.author?.login ?? null;
|
|
3914
|
+
}
|
|
3915
|
+
function commentAuthorLogin(comment) {
|
|
3916
|
+
return comment.user?.login ?? comment.author?.login ?? null;
|
|
3917
|
+
}
|
|
3918
|
+
function collectGreptileSignals(evidence) {
|
|
3919
|
+
const signals = [];
|
|
3920
|
+
const contextSources = [
|
|
3921
|
+
{ source: "pr-title", body: evidence.title ?? "" },
|
|
3922
|
+
{ source: "pr-body", body: evidence.body }
|
|
3923
|
+
];
|
|
3924
|
+
for (const context of contextSources) {
|
|
3925
|
+
if (!context.body.trim())
|
|
3926
|
+
continue;
|
|
3927
|
+
if (!/greptile|score|confidence|\b\d+\s*\/\s*5\b|blocker|unsafe|not safe|do not merge|changes requested/i.test(context.body))
|
|
3928
|
+
continue;
|
|
3929
|
+
const contextBlocker = containsBlockerText(context.body);
|
|
3930
|
+
signals.push(makeGreptileSignal({
|
|
3931
|
+
source: context.source,
|
|
3932
|
+
body: context.body,
|
|
3933
|
+
currentHeadSha: evidence.currentHeadSha,
|
|
3934
|
+
trusted: false,
|
|
3935
|
+
blocker: contextBlocker,
|
|
3936
|
+
actionable: contextBlocker
|
|
3937
|
+
}));
|
|
3938
|
+
}
|
|
3939
|
+
for (const apiSignal of evidence.apiSignals ?? []) {
|
|
3940
|
+
const body = [apiSignal.status ? `Status: ${apiSignal.status}` : "", apiSignal.body ?? ""].filter(Boolean).join(`
|
|
3941
|
+
|
|
3942
|
+
`);
|
|
3943
|
+
if (!body.trim())
|
|
3944
|
+
continue;
|
|
3945
|
+
signals.push(makeGreptileSignal({
|
|
3946
|
+
source: "api",
|
|
3947
|
+
body,
|
|
3948
|
+
currentHeadSha: evidence.currentHeadSha,
|
|
3949
|
+
trusted: true,
|
|
3950
|
+
reviewedSha: apiSignal.reviewedSha ?? null,
|
|
3951
|
+
explicitApproval: false
|
|
3952
|
+
}));
|
|
3953
|
+
}
|
|
3954
|
+
for (const review of evidence.reviews) {
|
|
3955
|
+
const login = reviewAuthorLogin(review);
|
|
3956
|
+
if (!isGreptileGithubLogin(login))
|
|
3957
|
+
continue;
|
|
3958
|
+
const state = String(review.state ?? "").toUpperCase();
|
|
3959
|
+
const body = [state ? `Review state: ${state}` : "", review.body ?? ""].filter(Boolean).join(`
|
|
3960
|
+
|
|
3961
|
+
`);
|
|
3962
|
+
if (!body.trim())
|
|
3963
|
+
continue;
|
|
3964
|
+
const dismissed = state === "DISMISSED";
|
|
3965
|
+
signals.push(makeGreptileSignal({
|
|
3966
|
+
source: "github-review",
|
|
3967
|
+
body,
|
|
3968
|
+
currentHeadSha: evidence.currentHeadSha,
|
|
3969
|
+
trusted: !dismissed,
|
|
3970
|
+
authorLogin: login,
|
|
3971
|
+
reviewedSha: review.commit_id ?? null,
|
|
3972
|
+
explicitApproval: undefined,
|
|
3973
|
+
blocker: state === "CHANGES_REQUESTED" || undefined
|
|
3974
|
+
}));
|
|
3975
|
+
}
|
|
3976
|
+
for (const comment of evidence.changedFileReviewComments) {
|
|
3977
|
+
const login = commentAuthorLogin(comment);
|
|
3978
|
+
const body = comment.body ?? "";
|
|
3979
|
+
if (!body.trim() || !isGreptileGithubLogin(login))
|
|
3980
|
+
continue;
|
|
3981
|
+
signals.push(makeGreptileSignal({
|
|
3982
|
+
source: "changed-file-comment",
|
|
3983
|
+
body,
|
|
3984
|
+
currentHeadSha: evidence.currentHeadSha,
|
|
3985
|
+
trusted: true,
|
|
3986
|
+
authorLogin: login,
|
|
3987
|
+
reviewedSha: comment.commit_id ?? comment.original_commit_id ?? null
|
|
3988
|
+
}));
|
|
3989
|
+
}
|
|
3990
|
+
for (const comment of evidence.relevantIssueComments) {
|
|
3991
|
+
const login = commentAuthorLogin(comment);
|
|
3992
|
+
const body = comment.body ?? "";
|
|
3993
|
+
if (!body.trim() || !isGreptileGithubLogin(login))
|
|
3994
|
+
continue;
|
|
3995
|
+
signals.push(makeGreptileSignal({
|
|
3996
|
+
source: "issue-comment",
|
|
3997
|
+
body,
|
|
3998
|
+
currentHeadSha: evidence.currentHeadSha,
|
|
3999
|
+
trusted: true,
|
|
4000
|
+
authorLogin: login
|
|
4001
|
+
}));
|
|
4002
|
+
}
|
|
4003
|
+
for (const thread of evidence.reviewThreads) {
|
|
4004
|
+
if (thread.isOutdated === true || thread.isResolved === true)
|
|
4005
|
+
continue;
|
|
4006
|
+
for (const comment of thread.comments?.nodes ?? []) {
|
|
4007
|
+
const login = comment.author?.login ?? null;
|
|
4008
|
+
const body = comment.body ?? "";
|
|
4009
|
+
if (!body.trim() || !isGreptileGithubLogin(login))
|
|
4010
|
+
continue;
|
|
4011
|
+
signals.push(makeGreptileSignal({
|
|
4012
|
+
source: "review-thread",
|
|
4013
|
+
body,
|
|
4014
|
+
currentHeadSha: evidence.currentHeadSha,
|
|
4015
|
+
trusted: true,
|
|
4016
|
+
authorLogin: login
|
|
4017
|
+
}));
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
for (const check of evidence.checks) {
|
|
4021
|
+
if (!isGreptileLabel(checkName(check)))
|
|
4022
|
+
continue;
|
|
4023
|
+
const reviewedSha = check.headSha ?? check.head_sha ?? null;
|
|
4024
|
+
const label = `${checkName(check)} (${checkState(check) || "unknown"})`;
|
|
4025
|
+
const body = [label, check.output?.title ?? "", check.output?.summary ?? "", check.output?.text ?? ""].filter((entry) => entry.trim().length > 0).join(`
|
|
4026
|
+
|
|
4027
|
+
`);
|
|
4028
|
+
signals.push(makeGreptileSignal({
|
|
4029
|
+
source: "github-check",
|
|
4030
|
+
body,
|
|
4031
|
+
currentHeadSha: evidence.currentHeadSha,
|
|
4032
|
+
trusted: false,
|
|
4033
|
+
reviewedSha,
|
|
4034
|
+
explicitApproval: false,
|
|
4035
|
+
blocker: isFailingCheck(check),
|
|
4036
|
+
actionable: isFailingCheck(check)
|
|
4037
|
+
}));
|
|
4038
|
+
}
|
|
4039
|
+
return signals;
|
|
4040
|
+
}
|
|
4041
|
+
function unresolvedGreptileThreadSummaries(threads) {
|
|
4042
|
+
return threads.flatMap((thread) => {
|
|
4043
|
+
if (thread.isResolved === true || thread.isOutdated === true)
|
|
4044
|
+
return [];
|
|
4045
|
+
const comments = thread.comments?.nodes ?? [];
|
|
4046
|
+
if (!comments.some((comment) => isGreptileGithubLogin(comment.author?.login)))
|
|
4047
|
+
return [];
|
|
4048
|
+
const latest = latestThreadComment(thread);
|
|
4049
|
+
if (!latest)
|
|
4050
|
+
return ["Unresolved Greptile review thread"];
|
|
4051
|
+
const path = latest.path ? ` on ${latest.path}` : "";
|
|
4052
|
+
return [`Unresolved Greptile review thread${path}: ${(latest.body ?? "").trim() || "(empty comment)"}`];
|
|
4053
|
+
});
|
|
4054
|
+
}
|
|
4055
|
+
function actionableChangedFileCommentSummaries(_comments) {
|
|
4056
|
+
return [];
|
|
4057
|
+
}
|
|
4058
|
+
function issueLevelBlockerSummaries(comments) {
|
|
4059
|
+
return comments.flatMap((comment) => {
|
|
4060
|
+
const body = comment.body?.trim() ?? "";
|
|
4061
|
+
if (!body || !containsBlockerText(body) && !containsConflictingScoreText(body))
|
|
4062
|
+
return [];
|
|
4063
|
+
const login = commentAuthorLogin(comment) ?? "unknown";
|
|
4064
|
+
const author = isGreptileGithubLogin(login) ? `Greptile issue comment by ${login}` : `Issue-level PR comment by ${login}`;
|
|
4065
|
+
return [`${author}: ${body}`];
|
|
4066
|
+
});
|
|
4067
|
+
}
|
|
4068
|
+
function reviewBodyBlockerSummaries(reviews) {
|
|
4069
|
+
return reviews.flatMap((review) => {
|
|
4070
|
+
const login = reviewAuthorLogin(review) ?? "unknown";
|
|
4071
|
+
if (isGreptileGithubLogin(login))
|
|
4072
|
+
return [];
|
|
4073
|
+
const body = review.body?.trim() ?? "";
|
|
4074
|
+
if (!body || !containsBlockerText(body) && !containsConflictingScoreText(body))
|
|
4075
|
+
return [];
|
|
4076
|
+
const state = review.state ? ` (${review.state})` : "";
|
|
4077
|
+
return [`PR review summary by ${login}${state}: ${body}`];
|
|
4078
|
+
});
|
|
4079
|
+
}
|
|
4080
|
+
function signalLabel(signal) {
|
|
4081
|
+
const source = signal.source.replace(/-/g, " ");
|
|
4082
|
+
const author = signal.authorLogin ? ` by ${signal.authorLogin}` : "";
|
|
4083
|
+
const sha = signal.reviewedSha ? ` at ${signal.reviewedSha}` : "";
|
|
4084
|
+
return `${source}${author}${sha}`;
|
|
4085
|
+
}
|
|
4086
|
+
function deriveGreptileEvidence(input) {
|
|
4087
|
+
const rawBodies = collectBodies(input);
|
|
4088
|
+
const signals = collectGreptileSignals(input);
|
|
4089
|
+
const trustedSignals = signals.filter((signal) => signal.trusted);
|
|
4090
|
+
const trustedScoreEntries = trustedSignals.flatMap((signal) => signal.allScores.map((score2) => ({ score: score2, signal })));
|
|
4091
|
+
const contextScoreEntries = signals.filter((signal) => !signal.trusted).flatMap((signal) => signal.allScores.map((score2) => ({ score: score2, signal })));
|
|
4092
|
+
const allScoreEntries = [...trustedScoreEntries, ...contextScoreEntries];
|
|
4093
|
+
const staleSignals = signals.filter((signal) => !!signal.reviewedSha && signal.reviewedSha !== input.currentHeadSha && (signal.trusted || signal.source === "github-check"));
|
|
4094
|
+
const isCurrentOrUntied = (signal) => !signal.reviewedSha || signal.reviewedSha === input.currentHeadSha;
|
|
4095
|
+
const currentOrUntiedScoreEntries = allScoreEntries.filter((entry) => isCurrentOrUntied(entry.signal));
|
|
4096
|
+
const lowScoreEntries = currentOrUntiedScoreEntries.filter((entry) => !isStrictFiveOfFive(entry.score));
|
|
4097
|
+
const approvingScoreEntry = trustedScoreEntries.find((entry) => entry.signal.reviewedSha === input.currentHeadSha && entry.signal.source !== "github-check" && isStrictFiveOfFive(entry.score)) ?? null;
|
|
4098
|
+
const approvedByScore = !!approvingScoreEntry;
|
|
4099
|
+
const approvedByExplicitMapping = false;
|
|
4100
|
+
const approvingSignal = approvingScoreEntry?.signal ?? null;
|
|
4101
|
+
const lowestScore = lowScoreEntries.map((entry) => entry.score).sort((left, right) => left.value - right.value)[0] ?? null;
|
|
4102
|
+
const score = lowestScore ?? approvingScoreEntry?.score ?? trustedScoreEntries[0]?.score ?? contextScoreEntries[0]?.score ?? null;
|
|
4103
|
+
const failedGreptileChecks = input.checks.filter((check) => isGreptileLabel(checkName(check)) && isFailingCheck(check)).map((check) => `${checkName(check)} (${checkState(check) || "failed"})`);
|
|
4104
|
+
const blockerSignals = signals.filter((signal) => (signal.blocker || signal.actionable) && (!signal.reviewedSha || signal.reviewedSha === input.currentHeadSha));
|
|
4105
|
+
const staleBlockingSignals = [];
|
|
4106
|
+
const blockers = [
|
|
4107
|
+
...blockerSignals.map((signal) => `${signalLabel(signal)}: ${signal.bodyExcerpt || "blocker text"}`),
|
|
4108
|
+
...reviewBodyBlockerSummaries(input.reviews),
|
|
4109
|
+
...issueLevelBlockerSummaries(input.relevantIssueComments),
|
|
4110
|
+
...lowScoreEntries.map((entry) => `Greptile score from ${signalLabel(entry.signal)} is ${entry.score.value}/${entry.score.scale}; strict merge requires trusted current-head 5/5.`),
|
|
4111
|
+
...staleBlockingSignals.map((signal) => `Greptile blocking signal from ${signalLabel(signal)} is stale; current PR head is ${input.currentHeadSha || "unknown"}.`),
|
|
4112
|
+
...failedGreptileChecks.map((entry) => `Greptile check failed: ${entry}`)
|
|
4113
|
+
];
|
|
4114
|
+
const unresolvedComments = [
|
|
4115
|
+
...unresolvedGreptileThreadSummaries(input.reviewThreads),
|
|
4116
|
+
...actionableChangedFileCommentSummaries(input.changedFileReviewComments)
|
|
4117
|
+
];
|
|
4118
|
+
const greptileChecks = input.checks.filter((check) => isGreptileLabel(checkName(check)));
|
|
4119
|
+
const greptileReviews = input.reviews.filter((review) => isGreptileGithubLogin(review.author?.login));
|
|
4120
|
+
const completedGreptileCheck = greptileChecks.some((check) => {
|
|
4121
|
+
const reviewedSha2 = check.headSha ?? check.head_sha ?? null;
|
|
4122
|
+
return reviewedSha2 === input.currentHeadSha && (isPassingCheck(check) || isFailingCheck(check));
|
|
4123
|
+
});
|
|
4124
|
+
const completedGreptileReview = greptileReviews.some((review) => {
|
|
4125
|
+
const state = String(review.state ?? "").toUpperCase();
|
|
4126
|
+
const completedState = ["APPROVED", "COMMENTED", "CHANGES_REQUESTED"].includes(state) || !!review.body?.trim();
|
|
4127
|
+
return completedState && review.commit_id === input.currentHeadSha;
|
|
4128
|
+
});
|
|
4129
|
+
const approvalReviewedSha = approvingSignal?.reviewedSha ?? null;
|
|
4130
|
+
const reviewedSha = approvalReviewedSha ?? staleSignals[0]?.reviewedSha ?? trustedSignals.map((signal) => signal.reviewedSha ?? null).find(Boolean) ?? null;
|
|
4131
|
+
const fresh = !!approvalReviewedSha && approvalReviewedSha === input.currentHeadSha;
|
|
4132
|
+
const completed = completedGreptileCheck || completedGreptileReview || !!approvingSignal || trustedSignals.some((signal) => signal.source === "api" && signal.reviewedSha === input.currentHeadSha);
|
|
4133
|
+
const hasGreptileEvidence = trustedSignals.length > 0 || signals.some((signal) => /greptile/i.test(signal.body));
|
|
4134
|
+
const approved = fresh && completed && !blockers.length && !unresolvedComments.length && (approvedByScore || approvedByExplicitMapping);
|
|
4135
|
+
const mapping = !hasGreptileEvidence ? "missing" : staleSignals.length > 0 && !approvingSignal ? "stale" : approvedByScore ? "score-5-of-5" : "unproven";
|
|
4136
|
+
const source = approvingSignal?.source === "api" ? "api" : approvingSignal?.source === "github-review" ? "github-review" : approvingSignal?.source === "changed-file-comment" || approvingSignal?.source === "issue-comment" || approvingSignal?.source === "review-thread" ? "github-comment" : greptileReviews.length > 0 && greptileChecks.length > 0 ? "combined" : greptileReviews.length > 0 ? "github-review" : greptileChecks.length > 0 ? "github-check" : signals.some((signal) => signal.source === "pr-body" || signal.source === "pr-title") ? "pr-body" : "missing";
|
|
4137
|
+
return {
|
|
4138
|
+
source,
|
|
4139
|
+
currentHeadSha: input.currentHeadSha,
|
|
4140
|
+
reviewedSha,
|
|
4141
|
+
fresh,
|
|
4142
|
+
completed,
|
|
4143
|
+
approved,
|
|
4144
|
+
score,
|
|
4145
|
+
explicitApproval: approvedByExplicitMapping,
|
|
4146
|
+
blockers,
|
|
4147
|
+
unresolvedComments,
|
|
4148
|
+
rawBodies,
|
|
4149
|
+
signals: signals.map(({ body: _body, allScores: _allScores, ...signal }) => signal),
|
|
4150
|
+
mapping
|
|
4151
|
+
};
|
|
4152
|
+
}
|
|
4153
|
+
function isGreptileCheckDetail(check) {
|
|
4154
|
+
return isGreptileLabel(checkName(check)) || isGreptileGithubLogin(check.app?.slug) || isGreptileGithubLogin(check.app?.owner?.login) || isGreptileLabel(check.app?.name);
|
|
4155
|
+
}
|
|
4156
|
+
async function collectGreptileCheckDetails(input) {
|
|
4157
|
+
const checkRunsRead = await runJsonArray(input.command, [
|
|
4158
|
+
"api",
|
|
4159
|
+
`repos/${input.repoName}/commits/${input.headSha}/check-runs`,
|
|
4160
|
+
"--paginate",
|
|
4161
|
+
"--slurp",
|
|
4162
|
+
"--jq",
|
|
4163
|
+
"map(.check_runs // []) | add // []"
|
|
4164
|
+
], input.projectRoot);
|
|
4165
|
+
const checkRuns = checkRunsRead.value.map(normalizeStatusCheck).filter((entry) => !!entry).filter(isGreptileCheckDetail);
|
|
4166
|
+
return checkRunsRead.error ? { value: checkRuns, error: checkRunsRead.error } : { value: checkRuns };
|
|
4167
|
+
}
|
|
4168
|
+
async function collectReviewThreads(input) {
|
|
4169
|
+
const reviewThreads = [];
|
|
4170
|
+
let afterCursor = null;
|
|
4171
|
+
for (let page = 0;page < 100; page += 1) {
|
|
4172
|
+
const afterLiteral = afterCursor ? JSON.stringify(afterCursor) : "null";
|
|
4173
|
+
const threadsResponse = await runJsonObject(input.command, [
|
|
4174
|
+
"api",
|
|
4175
|
+
"graphql",
|
|
4176
|
+
"-F",
|
|
4177
|
+
`owner=${input.owner}`,
|
|
4178
|
+
"-F",
|
|
4179
|
+
`name=${input.name}`,
|
|
4180
|
+
"-F",
|
|
4181
|
+
`prNumber=${input.prNumber}`,
|
|
4182
|
+
"-f",
|
|
4183
|
+
`query=query($owner: String!, $name: String!, $prNumber: Int!) { repository(owner:$owner, name:$name) { pullRequest(number:$prNumber) { reviewThreads(first: 100, after: ${afterLiteral}) { nodes { id isResolved isOutdated comments(first: 100) { nodes { author { login } body path url createdAt } pageInfo { hasNextPage endCursor } } } pageInfo { hasNextPage endCursor } } } } }`
|
|
4184
|
+
], input.projectRoot);
|
|
4185
|
+
if (threadsResponse.error) {
|
|
4186
|
+
return { value: reviewThreads, error: threadsResponse.error };
|
|
4187
|
+
}
|
|
4188
|
+
const data = threadsResponse.value.data;
|
|
4189
|
+
const repository = data?.repository;
|
|
4190
|
+
const pullRequest = repository?.pullRequest;
|
|
4191
|
+
const threads = pullRequest?.reviewThreads;
|
|
4192
|
+
const nodes = threads?.nodes;
|
|
4193
|
+
if (!Array.isArray(nodes)) {
|
|
4194
|
+
return { value: reviewThreads, error: "GitHub reviewThreads response did not include a nodes array" };
|
|
4195
|
+
}
|
|
4196
|
+
const normalized = nodes.map(normalizeReviewThread).filter((entry) => !!entry);
|
|
4197
|
+
reviewThreads.push(...normalized);
|
|
4198
|
+
const truncatedCommentThread = normalized.find((thread) => thread.comments?.pageInfo?.hasNextPage === true);
|
|
4199
|
+
if (truncatedCommentThread) {
|
|
4200
|
+
return { value: reviewThreads, error: `GitHub review thread ${truncatedCommentThread.id ?? "unknown"} has more than 100 comments; nested pagination is incomplete` };
|
|
4201
|
+
}
|
|
4202
|
+
const pageInfo = threads?.pageInfo;
|
|
4203
|
+
if (!pageInfo) {
|
|
4204
|
+
if (nodes.length >= 100) {
|
|
4205
|
+
return { value: reviewThreads, error: "GitHub reviewThreads pagination metadata missing after a full page" };
|
|
4206
|
+
}
|
|
4207
|
+
return { value: reviewThreads };
|
|
4208
|
+
}
|
|
4209
|
+
if (pageInfo.hasNextPage !== true) {
|
|
4210
|
+
return { value: reviewThreads };
|
|
4211
|
+
}
|
|
4212
|
+
if (typeof pageInfo.endCursor !== "string" || !pageInfo.endCursor.trim()) {
|
|
4213
|
+
return { value: reviewThreads, error: "GitHub reviewThreads pagination reported hasNextPage without endCursor" };
|
|
4214
|
+
}
|
|
4215
|
+
afterCursor = pageInfo.endCursor;
|
|
4216
|
+
}
|
|
4217
|
+
return { value: reviewThreads, error: "GitHub reviewThreads pagination exceeded 100 pages" };
|
|
4218
|
+
}
|
|
4219
|
+
async function collectPrReviewEvidence(input) {
|
|
4220
|
+
const parsed = parseGithubPrUrl(input.prUrl);
|
|
4221
|
+
if (!parsed) {
|
|
4222
|
+
throw new Error(`Cannot parse GitHub PR URL: ${input.prUrl}`);
|
|
4223
|
+
}
|
|
4224
|
+
const readErrors = [];
|
|
4225
|
+
const viewRead = await runJsonObject(input.command, [
|
|
4226
|
+
"pr",
|
|
4227
|
+
"view",
|
|
4228
|
+
input.prUrl,
|
|
4229
|
+
"--json",
|
|
4230
|
+
"title,body,headRefOid,headRefName,baseRefName,state,isDraft,mergeable,mergeStateStatus,reviewDecision,reviews,statusCheckRollup"
|
|
4231
|
+
], input.projectRoot);
|
|
4232
|
+
if (viewRead.error)
|
|
4233
|
+
readErrors.push(viewRead.error);
|
|
4234
|
+
const view = viewRead.value;
|
|
4235
|
+
if (!Array.isArray(view.statusCheckRollup)) {
|
|
4236
|
+
readErrors.push("gh pr view did not return required statusCheckRollup array");
|
|
4237
|
+
}
|
|
4238
|
+
if (!Array.isArray(view.reviews)) {
|
|
4239
|
+
readErrors.push("gh pr view did not return required reviews array");
|
|
4240
|
+
}
|
|
4241
|
+
const headSha = firstString(view, ["headRefOid", "headSha", "head_sha"]);
|
|
4242
|
+
const statusCheckRollup = arrayField(view, "statusCheckRollup").map(normalizeStatusCheck).filter((entry) => !!entry);
|
|
4243
|
+
const reviews = arrayField(view, "reviews").map(normalizeReview).filter((entry) => !!entry);
|
|
4244
|
+
const reviewCommentsRead = await runJsonArray(input.command, ["api", `repos/${parsed.repoName}/pulls/${parsed.prNumber}/comments`, "--paginate", "--slurp"], input.projectRoot);
|
|
4245
|
+
if (reviewCommentsRead.error)
|
|
4246
|
+
readErrors.push(reviewCommentsRead.error);
|
|
4247
|
+
const reviewComments = reviewCommentsRead.value.map(normalizeReviewComment).filter((entry) => !!entry);
|
|
4248
|
+
const issueCommentsRead = await runJsonArray(input.command, ["api", `repos/${parsed.repoName}/issues/${parsed.prNumber}/comments`, "--paginate", "--slurp"], input.projectRoot);
|
|
4249
|
+
if (issueCommentsRead.error)
|
|
4250
|
+
readErrors.push(issueCommentsRead.error);
|
|
4251
|
+
const issueComments = issueCommentsRead.value.map(normalizeIssueComment).filter((entry) => !!entry).filter(relevantIssueComment);
|
|
4252
|
+
const reviewThreadsRead = await collectReviewThreads({
|
|
4253
|
+
command: input.command,
|
|
4254
|
+
projectRoot: input.projectRoot,
|
|
4255
|
+
owner: parsed.owner,
|
|
4256
|
+
name: parsed.repo,
|
|
4257
|
+
prNumber: parsed.prNumber
|
|
4258
|
+
});
|
|
4259
|
+
if (reviewThreadsRead.error)
|
|
4260
|
+
readErrors.push(reviewThreadsRead.error);
|
|
4261
|
+
const reviewThreads = reviewThreadsRead.value;
|
|
4262
|
+
const greptileRollupChecks = statusCheckRollup.filter((check) => isGreptileLabel(checkName(check)));
|
|
4263
|
+
let greptileCheckDetails = [];
|
|
4264
|
+
if (headSha && greptileRollupChecks.length > 0) {
|
|
4265
|
+
const checkDetailsRead = await collectGreptileCheckDetails({
|
|
4266
|
+
command: input.command,
|
|
4267
|
+
projectRoot: input.projectRoot,
|
|
4268
|
+
repoName: parsed.repoName,
|
|
4269
|
+
headSha
|
|
4270
|
+
});
|
|
4271
|
+
if (checkDetailsRead.error)
|
|
4272
|
+
readErrors.push(checkDetailsRead.error);
|
|
4273
|
+
greptileCheckDetails = checkDetailsRead.value;
|
|
4274
|
+
if (!checkDetailsRead.error && greptileCheckDetails.length === 0) {
|
|
4275
|
+
readErrors.push("Greptile check details could not be found for the current PR head");
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4278
|
+
const checksWithGreptileDetails = [...statusCheckRollup, ...greptileCheckDetails];
|
|
4279
|
+
const checkFailures = statusCheckRollup.filter((check) => !isGreptileLabel(checkName(check)) && isFailingCheck(check) && !isAllowedFailure(checkName(check), input.allowedFailures ?? [])).map((check) => `Check failed: ${checkName(check)}${check.detailsUrl || check.link ? ` (${check.detailsUrl ?? check.link})` : ""}`);
|
|
4280
|
+
const pendingChecks = statusCheckRollup.filter((check) => isPendingCheck(check) && !isAllowedFailure(checkName(check), input.allowedFailures ?? [])).map((check) => `Check pending: ${checkName(check)}`);
|
|
4281
|
+
const evidenceBase = {
|
|
4282
|
+
title: firstString(view, ["title"]),
|
|
4283
|
+
body: firstString(view, ["body"]),
|
|
4284
|
+
reviews,
|
|
4285
|
+
changedFileReviewComments: reviewComments,
|
|
4286
|
+
relevantIssueComments: issueComments,
|
|
4287
|
+
reviewThreads,
|
|
4288
|
+
checks: checksWithGreptileDetails,
|
|
4289
|
+
currentHeadSha: headSha,
|
|
4290
|
+
apiSignals: input.apiSignals ?? []
|
|
4291
|
+
};
|
|
4292
|
+
const greptile = deriveGreptileEvidence(evidenceBase);
|
|
4293
|
+
return {
|
|
4294
|
+
prUrl: input.prUrl,
|
|
4295
|
+
prNumber: parsed.prNumber,
|
|
4296
|
+
repoName: parsed.repoName,
|
|
4297
|
+
title: evidenceBase.title,
|
|
4298
|
+
body: evidenceBase.body,
|
|
4299
|
+
headSha,
|
|
4300
|
+
headRefName: firstString(view, ["headRefName"]),
|
|
4301
|
+
baseRefName: firstString(view, ["baseRefName"]),
|
|
4302
|
+
state: firstString(view, ["state"]),
|
|
4303
|
+
isDraft: typeof view.isDraft === "boolean" ? view.isDraft : null,
|
|
4304
|
+
mergeable: firstString(view, ["mergeable"]),
|
|
4305
|
+
mergeStateStatus: firstString(view, ["mergeStateStatus"]),
|
|
4306
|
+
reviewDecision: firstString(view, ["reviewDecision"]),
|
|
4307
|
+
reviews,
|
|
4308
|
+
reviewThreads,
|
|
4309
|
+
changedFileReviewComments: reviewComments,
|
|
4310
|
+
relevantIssueComments: issueComments,
|
|
4311
|
+
statusCheckRollup: checksWithGreptileDetails,
|
|
4312
|
+
checkFailures,
|
|
4313
|
+
pendingChecks,
|
|
4314
|
+
readErrors,
|
|
4315
|
+
greptile
|
|
4316
|
+
};
|
|
4317
|
+
}
|
|
4318
|
+
function evaluateEvidence(evidence) {
|
|
4319
|
+
const reasons = [];
|
|
4320
|
+
const warnings = [];
|
|
4321
|
+
let pending = false;
|
|
4322
|
+
if (evidence.readErrors.length > 0) {
|
|
4323
|
+
reasons.push(...evidence.readErrors.map((error) => `Required PR evidence surface could not be read completely: ${error}`));
|
|
4324
|
+
}
|
|
4325
|
+
if (!evidence.headSha)
|
|
4326
|
+
reasons.push("PR head SHA could not be read; current-head Greptile approval cannot be proven.");
|
|
4327
|
+
if (evidence.checkFailures.length > 0)
|
|
4328
|
+
reasons.push(...evidence.checkFailures);
|
|
4329
|
+
if (evidence.pendingChecks.length > 0) {
|
|
4330
|
+
pending = true;
|
|
4331
|
+
reasons.push(...evidence.pendingChecks);
|
|
4332
|
+
}
|
|
4333
|
+
const reviewDecision = String(evidence.reviewDecision ?? "").toUpperCase();
|
|
4334
|
+
if (reviewDecision === "CHANGES_REQUESTED" || reviewDecision === "REVIEW_REQUIRED") {
|
|
4335
|
+
reasons.push(`Required review is unresolved (${evidence.reviewDecision}).`);
|
|
4336
|
+
}
|
|
4337
|
+
const unresolvedThreads = unresolvedThreadSummaries(evidence.reviewThreads);
|
|
4338
|
+
if (unresolvedThreads.length > 0)
|
|
4339
|
+
reasons.push(...unresolvedThreads);
|
|
4340
|
+
const greptile = evidence.greptile;
|
|
4341
|
+
if (greptile.mapping === "missing")
|
|
4342
|
+
reasons.push("Missing Greptile check/review evidence for this PR.");
|
|
4343
|
+
const staleSignal = greptile.signals.find((signal) => signal.reviewedSha && signal.reviewedSha !== evidence.headSha);
|
|
4344
|
+
if (greptile.mapping === "stale" || greptile.reviewedSha && greptile.reviewedSha !== evidence.headSha || !greptile.approved && staleSignal) {
|
|
4345
|
+
reasons.push(`Greptile evidence is stale (reviewed ${greptile.reviewedSha ?? staleSignal?.reviewedSha ?? "unknown"}, current ${evidence.headSha || "unknown"}).`);
|
|
4346
|
+
}
|
|
4347
|
+
if (!greptile.completed) {
|
|
4348
|
+
pending = true;
|
|
4349
|
+
reasons.push("Greptile check/review has not completed for the current PR head.");
|
|
4350
|
+
}
|
|
4351
|
+
if (!greptile.fresh)
|
|
4352
|
+
reasons.push("Greptile approval is not tied to the current PR head SHA.");
|
|
4353
|
+
if (greptile.score && !(greptile.score.scale === 5 && greptile.score.value === 5)) {
|
|
4354
|
+
reasons.push(`Greptile score is ${greptile.score.value}/${greptile.score.scale}; strict merge requires trusted current-head 5/5.`);
|
|
4355
|
+
}
|
|
4356
|
+
if (!greptile.score && greptile.mapping !== "score-5-of-5") {
|
|
4357
|
+
reasons.push("No parseable Greptile 5/5 score or explicit approved mapping was found from trusted current-head evidence; merge is blocked.");
|
|
4358
|
+
}
|
|
4359
|
+
if (greptile.mapping === "unproven") {
|
|
4360
|
+
reasons.push("Greptile approval mapping is unproven; PR body/title or a green check alone cannot approve merge.");
|
|
4361
|
+
}
|
|
4362
|
+
if (greptile.blockers.length > 0) {
|
|
4363
|
+
reasons.push(...greptile.blockers.map((entry) => `Greptile/blocker text: ${entry.trim().slice(0, 500)}`));
|
|
4364
|
+
}
|
|
4365
|
+
if (greptile.unresolvedComments.length > 0)
|
|
4366
|
+
reasons.push(...greptile.unresolvedComments);
|
|
4367
|
+
if (!greptile.approved)
|
|
4368
|
+
warnings.push(`Greptile approval mapping is ${greptile.mapping}.`);
|
|
4369
|
+
return { reasons: Array.from(new Set(reasons)), warnings, pending };
|
|
4370
|
+
}
|
|
4371
|
+
function evaluateStrictPrMergeGate(evidence) {
|
|
4372
|
+
const evaluated = evaluateEvidence(evidence);
|
|
4373
|
+
const approved = evaluated.reasons.length === 0 && evidence.greptile.approved;
|
|
4374
|
+
return {
|
|
4375
|
+
approved,
|
|
4376
|
+
pending: evaluated.pending,
|
|
4377
|
+
reasons: evaluated.reasons,
|
|
4378
|
+
warnings: evaluated.warnings,
|
|
4379
|
+
actionableFeedback: evaluated.reasons,
|
|
4380
|
+
evidence
|
|
4381
|
+
};
|
|
4382
|
+
}
|
|
4383
|
+
|
|
4384
|
+
// packages/runtime/src/control-plane/native/verifier.ts
|
|
3614
4385
|
async function verifyTask(options) {
|
|
3615
4386
|
const paths = resolveHarnessPaths(options.projectRoot);
|
|
3616
4387
|
const taskId = options.taskId;
|
|
@@ -4406,7 +5177,8 @@ async function runGreptileReviewForPr(options) {
|
|
|
4406
5177
|
}
|
|
4407
5178
|
};
|
|
4408
5179
|
}
|
|
4409
|
-
|
|
5180
|
+
const blockerScanBody = stripHtml(reviewBody).replace(/\b(?:no|without|zero)\s+blockers?\b/gi, " ").replace(/\bno\s+changes\s+requested\b/gi, " ");
|
|
5181
|
+
if (/not safe(?: to merge)?|unsafe(?: to merge)?|do not merge|cannot merge|blockers?|must fix|changes requested|please fix|needs? fix|fix this|address this/i.test(blockerScanBody)) {
|
|
4410
5182
|
reasons.push(`[AI Review] ${repoName}#${prNumber} summary indicates the PR is not safe to merge.`);
|
|
4411
5183
|
return {
|
|
4412
5184
|
verdict: "REJECT",
|
|
@@ -4422,44 +5194,78 @@ async function runGreptileReviewForPr(options) {
|
|
|
4422
5194
|
}
|
|
4423
5195
|
};
|
|
4424
5196
|
}
|
|
4425
|
-
if (score) {
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
5197
|
+
if (score?.scale === 5 && score.value < 5) {
|
|
5198
|
+
reasons.push(`[AI Review] ${repoName}#${prNumber} completed with Greptile confidence ${score.value}/${score.scale}; strict review requires 5/5 before merge.`);
|
|
5199
|
+
return {
|
|
5200
|
+
verdict: "REJECT",
|
|
5201
|
+
feedback,
|
|
5202
|
+
reasons,
|
|
5203
|
+
warnings,
|
|
5204
|
+
rawPayload: {
|
|
5205
|
+
pr: options.prState,
|
|
5206
|
+
codeReviews: reviewsPayload,
|
|
5207
|
+
selectedReview,
|
|
5208
|
+
reviewDetails,
|
|
5209
|
+
comments: commentsPayload,
|
|
5210
|
+
score
|
|
5211
|
+
}
|
|
5212
|
+
};
|
|
5213
|
+
}
|
|
5214
|
+
const prUrl = options.prState.url || `https://github.com/${repoName}/pull/${prNumber}`;
|
|
5215
|
+
let strictGate = null;
|
|
5216
|
+
try {
|
|
5217
|
+
const strictEvidence = await collectStrictPrEvidenceForVerifier({
|
|
5218
|
+
projectRoot: options.projectRoot,
|
|
5219
|
+
taskId: options.taskId,
|
|
5220
|
+
prUrl,
|
|
5221
|
+
apiSignals: [{
|
|
5222
|
+
id: selectedReview.id,
|
|
5223
|
+
body: reviewBody,
|
|
5224
|
+
reviewedSha: selectedReview.metadata?.checkHeadSha ?? null,
|
|
5225
|
+
status: selectedReview.status
|
|
5226
|
+
}]
|
|
5227
|
+
});
|
|
5228
|
+
strictGate = evaluateStrictPrMergeGate(strictEvidence);
|
|
5229
|
+
} catch (error) {
|
|
5230
|
+
reasons.push(`[AI Review] Strict Greptile evidence collection failed for ${repoName}#${prNumber}: ${error instanceof Error ? error.message : String(error)}`);
|
|
5231
|
+
return {
|
|
5232
|
+
verdict: "REJECT",
|
|
5233
|
+
feedback,
|
|
5234
|
+
reasons,
|
|
5235
|
+
warnings,
|
|
5236
|
+
rawPayload: {
|
|
5237
|
+
pr: options.prState,
|
|
5238
|
+
codeReviews: reviewsPayload,
|
|
5239
|
+
selectedReview,
|
|
5240
|
+
reviewDetails,
|
|
5241
|
+
comments: commentsPayload,
|
|
5242
|
+
score
|
|
5243
|
+
}
|
|
5244
|
+
};
|
|
5245
|
+
}
|
|
5246
|
+
if (!strictGate.approved) {
|
|
5247
|
+
return {
|
|
5248
|
+
verdict: strictGate.pending ? "SKIP" : "REJECT",
|
|
5249
|
+
feedback,
|
|
5250
|
+
reasons: strictGate.reasons.map((reason) => reason.startsWith("[AI Review]") ? reason : `[AI Review] ${reason}`),
|
|
5251
|
+
warnings: [...warnings, ...strictGate.warnings],
|
|
5252
|
+
rawPayload: {
|
|
5253
|
+
pr: options.prState,
|
|
5254
|
+
codeReviews: reviewsPayload,
|
|
5255
|
+
selectedReview,
|
|
5256
|
+
reviewDetails,
|
|
5257
|
+
comments: commentsPayload,
|
|
5258
|
+
score,
|
|
5259
|
+
strictGate: {
|
|
5260
|
+
approved: strictGate.approved,
|
|
5261
|
+
pending: strictGate.pending,
|
|
5262
|
+
reasons: strictGate.reasons,
|
|
5263
|
+
warnings: strictGate.warnings,
|
|
5264
|
+
greptile: strictGate.evidence.greptile,
|
|
5265
|
+
readErrors: strictGate.evidence.readErrors
|
|
4457
5266
|
}
|
|
4458
|
-
}
|
|
4459
|
-
}
|
|
4460
|
-
if (score.scale === 5 && score.value < 5) {
|
|
4461
|
-
warnings.push(`[AI Review] ${repoName}#${prNumber} completed with Greptile confidence ${score.value}/${score.scale}; continue only after reviewing remaining risk.`);
|
|
4462
|
-
}
|
|
5267
|
+
}
|
|
5268
|
+
};
|
|
4463
5269
|
}
|
|
4464
5270
|
return {
|
|
4465
5271
|
verdict: "APPROVE",
|
|
@@ -4471,7 +5277,15 @@ async function runGreptileReviewForPr(options) {
|
|
|
4471
5277
|
codeReviews: reviewsPayload,
|
|
4472
5278
|
selectedReview,
|
|
4473
5279
|
reviewDetails,
|
|
4474
|
-
comments: commentsPayload
|
|
5280
|
+
comments: commentsPayload,
|
|
5281
|
+
strictGate: {
|
|
5282
|
+
approved: strictGate.approved,
|
|
5283
|
+
pending: strictGate.pending,
|
|
5284
|
+
reasons: strictGate.reasons,
|
|
5285
|
+
warnings: strictGate.warnings,
|
|
5286
|
+
greptile: strictGate.evidence.greptile,
|
|
5287
|
+
readErrors: strictGate.evidence.readErrors
|
|
5288
|
+
}
|
|
4475
5289
|
}
|
|
4476
5290
|
};
|
|
4477
5291
|
}
|
|
@@ -4495,7 +5309,7 @@ async function runGithubGreptileFallbackReviewForPr(options) {
|
|
|
4495
5309
|
let threads = [];
|
|
4496
5310
|
let actionableThreads = [];
|
|
4497
5311
|
let checkRollup = [];
|
|
4498
|
-
let
|
|
5312
|
+
let checkState2 = { pending: false, completed: false };
|
|
4499
5313
|
for (let attempt = 0;; attempt += 1) {
|
|
4500
5314
|
reviews = runGhJson(options.projectRoot, ["api", `repos/${repoName}/pulls/${prNumber}/reviews`]);
|
|
4501
5315
|
selectedReview = pickRelevantGithubGreptileReview(reviews, expectedHeadSha);
|
|
@@ -4504,15 +5318,15 @@ async function runGithubGreptileFallbackReviewForPr(options) {
|
|
|
4504
5318
|
threads = loadGithubReviewThreads(options.projectRoot, repoName, prNumber);
|
|
4505
5319
|
actionableThreads = filterActionableGithubGreptileThreads(threads);
|
|
4506
5320
|
checkRollup = loadGithubPullRequestCheckRollup(options.projectRoot, repoName, prNumber);
|
|
4507
|
-
|
|
4508
|
-
const
|
|
5321
|
+
checkState2 = classifyGithubGreptileCheckState(checkRollup);
|
|
5322
|
+
const approvedViaReviewedAncestor = !selectedReview && !!fallbackReview?.commit_id && !!expectedHeadSha && isCommitAncestorOfPrHead(options.projectRoot, options.prState, fallbackReview.commit_id, expectedHeadSha);
|
|
4509
5323
|
if (!shouldContinueGithubGreptileFallbackPolling({
|
|
4510
5324
|
attempt,
|
|
4511
5325
|
pollAttempts: options.pollAttempts,
|
|
4512
|
-
checkState,
|
|
5326
|
+
checkState: checkState2,
|
|
4513
5327
|
fallbackReview,
|
|
4514
5328
|
selectedReview,
|
|
4515
|
-
approvedViaReviewedAncestor
|
|
5329
|
+
approvedViaReviewedAncestor
|
|
4516
5330
|
})) {
|
|
4517
5331
|
break;
|
|
4518
5332
|
}
|
|
@@ -4540,7 +5354,7 @@ async function runGithubGreptileFallbackReviewForPr(options) {
|
|
|
4540
5354
|
].filter(Boolean).join(`
|
|
4541
5355
|
`);
|
|
4542
5356
|
const warnings = buildGithubGreptileFallbackWarnings(options);
|
|
4543
|
-
if (
|
|
5357
|
+
if (checkState2.pending) {
|
|
4544
5358
|
return {
|
|
4545
5359
|
verdict: "SKIP",
|
|
4546
5360
|
feedback,
|
|
@@ -4551,34 +5365,20 @@ async function runGithubGreptileFallbackReviewForPr(options) {
|
|
|
4551
5365
|
rawPayload: { ...buildGithubGreptileFallbackRawPayload(options), reviews, threads, checkRollup }
|
|
4552
5366
|
};
|
|
4553
5367
|
}
|
|
4554
|
-
const
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
};
|
|
4565
|
-
}
|
|
4566
|
-
return {
|
|
4567
|
-
verdict: "SKIP",
|
|
4568
|
-
feedback,
|
|
4569
|
-
reasons: [
|
|
4570
|
-
`[AI Review] Greptile GitHub review for ${repoName}#${prNumber} is not available.`
|
|
4571
|
-
],
|
|
4572
|
-
warnings,
|
|
4573
|
-
rawPayload: { ...buildGithubGreptileFallbackRawPayload(options), reviews, threads, checkRollup }
|
|
4574
|
-
};
|
|
4575
|
-
}
|
|
4576
|
-
const approvedViaReviewedAncestor = !selectedReview && !!fallbackReview.commit_id && !!expectedHeadSha && isCommitAncestorOfPrHead(options.projectRoot, options.prState, fallbackReview.commit_id, expectedHeadSha);
|
|
4577
|
-
if (actionableThreads.length > 0) {
|
|
5368
|
+
const prUrl = options.prState.url || `https://github.com/${repoName}/pull/${prNumber}`;
|
|
5369
|
+
let strictGate;
|
|
5370
|
+
try {
|
|
5371
|
+
const strictEvidence = await collectStrictPrEvidenceForVerifier({
|
|
5372
|
+
projectRoot: options.projectRoot,
|
|
5373
|
+
taskId: options.taskId,
|
|
5374
|
+
prUrl
|
|
5375
|
+
});
|
|
5376
|
+
strictGate = evaluateStrictPrMergeGate(strictEvidence);
|
|
5377
|
+
} catch (error) {
|
|
4578
5378
|
return {
|
|
4579
5379
|
verdict: "REJECT",
|
|
4580
5380
|
feedback,
|
|
4581
|
-
reasons:
|
|
5381
|
+
reasons: [`[AI Review] Strict Greptile evidence collection failed for ${repoName}#${prNumber}: ${error instanceof Error ? error.message : String(error)}`],
|
|
4582
5382
|
warnings,
|
|
4583
5383
|
rawPayload: {
|
|
4584
5384
|
pr: options.prState,
|
|
@@ -4591,44 +5391,30 @@ async function runGithubGreptileFallbackReviewForPr(options) {
|
|
|
4591
5391
|
}
|
|
4592
5392
|
};
|
|
4593
5393
|
}
|
|
4594
|
-
if (!
|
|
4595
|
-
if (approvedViaCompletedCheck) {
|
|
4596
|
-
warnings.push(`[AI Review Warning] ${repoName}#${prNumber} has no fresh Greptile GitHub review on the current head, but the Greptile check completed successfully and all Greptile threads are resolved.`);
|
|
4597
|
-
return {
|
|
4598
|
-
verdict: "APPROVE",
|
|
4599
|
-
feedback,
|
|
4600
|
-
reasons: [],
|
|
4601
|
-
warnings,
|
|
4602
|
-
rawPayload: {
|
|
4603
|
-
pr: options.prState,
|
|
4604
|
-
selectedReview: fallbackReview,
|
|
4605
|
-
reviews,
|
|
4606
|
-
threads,
|
|
4607
|
-
checkRollup,
|
|
4608
|
-
...buildGithubGreptileFallbackRawPayload(options)
|
|
4609
|
-
}
|
|
4610
|
-
};
|
|
4611
|
-
}
|
|
5394
|
+
if (!strictGate.approved) {
|
|
4612
5395
|
return {
|
|
4613
|
-
verdict: "SKIP",
|
|
5396
|
+
verdict: strictGate.pending ? "SKIP" : "REJECT",
|
|
4614
5397
|
feedback,
|
|
4615
|
-
reasons: [
|
|
4616
|
-
|
|
4617
|
-
],
|
|
4618
|
-
warnings,
|
|
5398
|
+
reasons: strictGate.reasons.map((reason) => reason.startsWith("[AI Review]") ? reason : `[AI Review] ${reason}`),
|
|
5399
|
+
warnings: [...warnings, ...strictGate.warnings],
|
|
4619
5400
|
rawPayload: {
|
|
4620
5401
|
pr: options.prState,
|
|
4621
5402
|
selectedReview: fallbackReview,
|
|
4622
5403
|
reviews,
|
|
4623
5404
|
threads,
|
|
4624
5405
|
checkRollup,
|
|
5406
|
+
actionableThreads,
|
|
5407
|
+
strictGate: {
|
|
5408
|
+
approved: strictGate.approved,
|
|
5409
|
+
pending: strictGate.pending,
|
|
5410
|
+
reasons: strictGate.reasons,
|
|
5411
|
+
warnings: strictGate.warnings,
|
|
5412
|
+
greptile: strictGate.evidence.greptile
|
|
5413
|
+
},
|
|
4625
5414
|
...buildGithubGreptileFallbackRawPayload(options)
|
|
4626
5415
|
}
|
|
4627
5416
|
};
|
|
4628
5417
|
}
|
|
4629
|
-
if (approvedViaReviewedAncestor) {
|
|
4630
|
-
warnings.push(`[AI Review Warning] ${repoName}#${prNumber} has no fresh Greptile review on the current head, but the latest reviewed commit is an ancestor and all Greptile threads are resolved.`);
|
|
4631
|
-
}
|
|
4632
5418
|
return {
|
|
4633
5419
|
verdict: "APPROVE",
|
|
4634
5420
|
feedback,
|
|
@@ -4640,6 +5426,13 @@ async function runGithubGreptileFallbackReviewForPr(options) {
|
|
|
4640
5426
|
reviews,
|
|
4641
5427
|
threads,
|
|
4642
5428
|
checkRollup,
|
|
5429
|
+
strictGate: {
|
|
5430
|
+
approved: strictGate.approved,
|
|
5431
|
+
pending: strictGate.pending,
|
|
5432
|
+
reasons: strictGate.reasons,
|
|
5433
|
+
warnings: strictGate.warnings,
|
|
5434
|
+
greptile: strictGate.evidence.greptile
|
|
5435
|
+
},
|
|
4643
5436
|
...buildGithubGreptileFallbackRawPayload(options)
|
|
4644
5437
|
}
|
|
4645
5438
|
};
|
|
@@ -4825,6 +5618,20 @@ function runGhJson(projectRoot, args) {
|
|
|
4825
5618
|
throw new Error(`gh ${args.join(" ")} returned malformed JSON: ${result.stdout}`);
|
|
4826
5619
|
}
|
|
4827
5620
|
}
|
|
5621
|
+
async function collectStrictPrEvidenceForVerifier(input) {
|
|
5622
|
+
return collectPrReviewEvidence({
|
|
5623
|
+
projectRoot: input.projectRoot,
|
|
5624
|
+
prUrl: input.prUrl,
|
|
5625
|
+
taskId: input.taskId,
|
|
5626
|
+
runId: "verifier",
|
|
5627
|
+
cycle: 0,
|
|
5628
|
+
apiSignals: input.apiSignals ?? [],
|
|
5629
|
+
command: async (args, options) => {
|
|
5630
|
+
const result = runCapture(["gh", ...args], options?.cwd ?? input.projectRoot);
|
|
5631
|
+
return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };
|
|
5632
|
+
}
|
|
5633
|
+
});
|
|
5634
|
+
}
|
|
4828
5635
|
function deriveRepoName(projectRoot, prState) {
|
|
4829
5636
|
const fromUrl = /github\.com\/([^/]+\/[^/]+)\/pull\/\d+/.exec(prState.url || "");
|
|
4830
5637
|
if (fromUrl?.[1]) {
|
|
@@ -4839,8 +5646,9 @@ function resolvePrHeadSha(projectRoot, prState) {
|
|
|
4839
5646
|
const repoRoot = resolvePrRepoRoot(projectRoot, prState);
|
|
4840
5647
|
return runCapture(["git", "-C", repoRoot, "rev-parse", "HEAD"], projectRoot).stdout.trim();
|
|
4841
5648
|
}
|
|
4842
|
-
function
|
|
4843
|
-
|
|
5649
|
+
function isGreptileGithubLogin2(login) {
|
|
5650
|
+
const normalized = (login || "").toLowerCase().replace(/\[bot\]$/, "");
|
|
5651
|
+
return normalized === "greptile" || normalized === "greptile-ai" || normalized === "greptileai" || normalized === "greptile-apps";
|
|
4844
5652
|
}
|
|
4845
5653
|
function pickRelevantGithubGreptileReview(reviews, expectedHeadSha) {
|
|
4846
5654
|
const matching = sortGithubGreptileReviews(reviews);
|
|
@@ -4857,7 +5665,7 @@ function pickLatestGithubGreptileReview(reviews) {
|
|
|
4857
5665
|
return sortGithubGreptileReviews(reviews)[0] || null;
|
|
4858
5666
|
}
|
|
4859
5667
|
function sortGithubGreptileReviews(reviews) {
|
|
4860
|
-
return reviews.filter((review) =>
|
|
5668
|
+
return reviews.filter((review) => isGreptileGithubLogin2(review.user?.login)).sort((left, right) => Date.parse(right.submitted_at || "") - Date.parse(left.submitted_at || ""));
|
|
4861
5669
|
}
|
|
4862
5670
|
function loadGithubPullRequestCheckRollup(projectRoot, repoName, prNumber) {
|
|
4863
5671
|
const response = runGhJson(projectRoot, [
|
|
@@ -4930,32 +5738,6 @@ function classifyGithubGreptileCheckState(checks) {
|
|
|
4930
5738
|
}
|
|
4931
5739
|
return { pending: false, completed: false };
|
|
4932
5740
|
}
|
|
4933
|
-
function isGithubGreptileCheckApproved(checks) {
|
|
4934
|
-
const greptileChecks = checks.filter((check) => {
|
|
4935
|
-
const label = (check.name || check.context || "").toLowerCase();
|
|
4936
|
-
return label.includes("greptile");
|
|
4937
|
-
});
|
|
4938
|
-
if (greptileChecks.length === 0) {
|
|
4939
|
-
return false;
|
|
4940
|
-
}
|
|
4941
|
-
for (const check of greptileChecks) {
|
|
4942
|
-
if ((check.__typename || "") === "CheckRun") {
|
|
4943
|
-
if ((check.status || "").toUpperCase() !== "COMPLETED") {
|
|
4944
|
-
return false;
|
|
4945
|
-
}
|
|
4946
|
-
const conclusion = (check.conclusion || "").toUpperCase();
|
|
4947
|
-
if (!["SUCCESS", "NEUTRAL", "SKIPPED"].includes(conclusion)) {
|
|
4948
|
-
return false;
|
|
4949
|
-
}
|
|
4950
|
-
continue;
|
|
4951
|
-
}
|
|
4952
|
-
const state = (check.state || "").toUpperCase();
|
|
4953
|
-
if (!["SUCCESS", "NEUTRAL", "SKIPPED"].includes(state)) {
|
|
4954
|
-
return false;
|
|
4955
|
-
}
|
|
4956
|
-
}
|
|
4957
|
-
return true;
|
|
4958
|
-
}
|
|
4959
5741
|
function loadGithubReviewThreads(projectRoot, repoName, prNumber) {
|
|
4960
5742
|
const [owner, name] = repoName.split("/");
|
|
4961
5743
|
if (!owner || !name) {
|
|
@@ -4981,7 +5763,7 @@ function filterActionableGithubGreptileThreads(threads) {
|
|
|
4981
5763
|
return [];
|
|
4982
5764
|
}
|
|
4983
5765
|
const comments = thread.comments?.nodes || [];
|
|
4984
|
-
const latestGreptileComment = [...comments].reverse().find((comment) =>
|
|
5766
|
+
const latestGreptileComment = [...comments].reverse().find((comment) => isGreptileGithubLogin2(comment.author?.login));
|
|
4985
5767
|
if (!latestGreptileComment?.path?.trim()) {
|
|
4986
5768
|
return [];
|
|
4987
5769
|
}
|
|
@@ -5003,11 +5785,6 @@ function isCommitAncestorOfPrHead(projectRoot, prState, reviewedCommit, headComm
|
|
|
5003
5785
|
const repoRoot = resolvePrRepoRoot(projectRoot, prState);
|
|
5004
5786
|
return runCapture(["git", "-C", repoRoot, "merge-base", "--is-ancestor", reviewedCommit, headCommit], projectRoot).exitCode === 0;
|
|
5005
5787
|
}
|
|
5006
|
-
function stripHtml(input) {
|
|
5007
|
-
return input.replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\r/g, "").replace(/\n{3,}/g, `
|
|
5008
|
-
|
|
5009
|
-
`).trim();
|
|
5010
|
-
}
|
|
5011
5788
|
function summarizeComment(input) {
|
|
5012
5789
|
const text = stripHtml(input).replace(/\s+/g, " ").trim();
|
|
5013
5790
|
return text.length > 160 ? `${text.slice(0, 157)}...` : text;
|
|
@@ -5016,31 +5793,14 @@ function asGreptileInfrastructureWarning(reason) {
|
|
|
5016
5793
|
return reason.startsWith("[AI Review]") ? reason.replace("[AI Review]", "[AI Review Warning]") : reason;
|
|
5017
5794
|
}
|
|
5018
5795
|
function isAiReviewApproved(input) {
|
|
5796
|
+
if (input.aiVerdict === "REJECT" && input.aiReasons.length > 0) {
|
|
5797
|
+
return false;
|
|
5798
|
+
}
|
|
5019
5799
|
if (input.reviewMode !== "required") {
|
|
5020
5800
|
return true;
|
|
5021
5801
|
}
|
|
5022
5802
|
return input.aiVerdict === "APPROVE" && input.aiReasons.length === 0;
|
|
5023
5803
|
}
|
|
5024
|
-
function parseGreptileScore(input) {
|
|
5025
|
-
const text = stripHtml(input);
|
|
5026
|
-
const patterns = [
|
|
5027
|
-
/confidence score:\s*(\d+)\s*\/\s*(\d+)/i,
|
|
5028
|
-
/\bscore:\s*(\d+)\s*\/\s*(\d+)/i,
|
|
5029
|
-
/\b(\d+)\s*\/\s*(\d+)\s*(?:confidence|score)/i
|
|
5030
|
-
];
|
|
5031
|
-
for (const pattern of patterns) {
|
|
5032
|
-
const match = pattern.exec(text);
|
|
5033
|
-
if (!match) {
|
|
5034
|
-
continue;
|
|
5035
|
-
}
|
|
5036
|
-
const value = Number.parseInt(match[1] || "", 10);
|
|
5037
|
-
const scale = Number.parseInt(match[2] || "", 10);
|
|
5038
|
-
if (Number.isFinite(value) && Number.isFinite(scale) && scale > 0) {
|
|
5039
|
-
return { value, scale };
|
|
5040
|
-
}
|
|
5041
|
-
}
|
|
5042
|
-
return null;
|
|
5043
|
-
}
|
|
5044
5804
|
|
|
5045
5805
|
// packages/runtime/src/control-plane/provider/runtime-instructions.ts
|
|
5046
5806
|
var CLAUDE_ROUTER_TOOL_NAMES = [
|
|
@@ -6353,8 +7113,9 @@ function defaultPrCloseoutLine(taskId, repoNameWithOwner) {
|
|
|
6353
7113
|
const sourceIssueId = loadRuntimeContextFromEnv()?.sourceTask?.sourceIssueId;
|
|
6354
7114
|
if (sourceIssueId) {
|
|
6355
7115
|
const match = sourceIssueId.match(/^([^#]+)#(\d+)$/);
|
|
6356
|
-
if (match) {
|
|
6357
|
-
const
|
|
7116
|
+
if (match?.[1] && match[2]) {
|
|
7117
|
+
const sourceRepo = match[1];
|
|
7118
|
+
const issueNumber = match[2];
|
|
6358
7119
|
return sourceRepo.toLowerCase() === repoNameWithOwner.toLowerCase() ? `Closes #${issueNumber}` : `Closes ${sourceRepo}#${issueNumber}`;
|
|
6359
7120
|
}
|
|
6360
7121
|
}
|