@vite-hub/presets 0.5.0 → 0.6.0
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 +3 -2
- package/dist/babysitter/server.d.ts +6 -5
- package/dist/babysitter/server.js +1 -2
- package/dist/{babysitter-B5C0KLRl.js → babysitter-YDTdao5H.js} +24 -34
- package/dist/babysitter.d.ts +1 -11
- package/dist/babysitter.js +1 -2
- package/dist/{error-diagnostics-o3pHscWs.js → error-diagnostics-BqwPfmNx.js} +6 -4
- package/dist/{host-gF2JTvw8.js → host-DkX1bQwj.js} +8 -13
- package/dist/labeller.d.ts +1 -2
- package/dist/labeller.js +2 -3
- package/dist/{pr-workspaces-QjQyRB6g.d.ts → pr-workspaces-BGAsF7fH.d.ts} +5 -26
- package/dist/{server-Bj5_Uf_Y.js → server-BAwiKpEK.js} +333 -130
- package/dist/workspace.d.ts +0 -2
- package/dist/workspace.js +1 -2
- package/package.json +13 -13
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as isRuntimeString, i as isRuntimeRecord, n as hasRuntimeType, r as isRuntimeNumber, t as presetsErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { A as
|
|
1
|
+
import { a as isRuntimeString, i as isRuntimeRecord, n as hasRuntimeType, r as isRuntimeNumber, t as presetsErrorDiagnostics } from "./error-diagnostics-BqwPfmNx.js";
|
|
2
|
+
import { A as invariant, B as createBabysitterPassResultSchema, C as approvalReviewers, D as normalizeGitHubMentionAllowlist, E as isReviewThreadOutcome, F as failed$1, I as hydrateFailedCiEvidence, L as newestCheckRun, M as hasGitHubLogin, N as matchesBabysitterPullRequestFilter, O as reviewThreadOutcomes, P as actionLocation, R as createBabysitterCheckRuns, S as snapshotCheckEvidence, T as createGitHubPullRequestOperations, _ as isAutomatedFeedback, a as isBabysitterPlacementCapacityError, b as mergeReviewEvidenceKey, c as workspaceDecision, g as headChecksUnreported, h as hasHumanComment, j as invariantError, k as reviewerLabeledSevere, l as babysitterModelAdmission, m as feedbackFingerprints, p as directMergeReadiness, r as resolveBabysitterLifecycleFilter, s as providerSessionDecision, v as liveMergeReadiness, w as maintainerApproval, x as resolveBabysitterMerge, y as matchesMergeReviewEvidence, z as isBabysitterCheckRun } from "./babysitter-YDTdao5H.js";
|
|
3
3
|
import { activeProviderSandbox, agentInvocationId, agentSettings, createMessage, defineAgent, defineCapability, publishAgentActivity, recordProviderCheckout, runAgent, withoutForgeAccess } from "@vite-hub/agent";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { resolvePublicUrl } from "@vite-hub/runtime";
|
|
@@ -19,7 +19,7 @@ import { consoleInvocationUrl } from "@vite-hub/runtime/internal/console";
|
|
|
19
19
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
20
20
|
import { resolveRuntimeValue } from "@vite-hub/runtime/internal/context";
|
|
21
21
|
import { resolveRegisteredWorkspaceDefinition } from "@vite-hub/workspace/runtime";
|
|
22
|
-
|
|
22
|
+
// src/github/checkout.ts
|
|
23
23
|
const exec$6 = promisify(execFile);
|
|
24
24
|
/** Credentials belong to the host. Never carry saved clone authentication into a worker. */
|
|
25
25
|
async function sanitizeProviderGitConfig(git, destination) {
|
|
@@ -355,8 +355,7 @@ async function preparePersistentGitHubPullRequestWorkspace(checkout, target, opt
|
|
|
355
355
|
reason: reason ?? "warm"
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
|
-
|
|
359
|
-
//#region src/github/base-reverts.ts
|
|
358
|
+
// src/github/base-reverts.ts
|
|
360
359
|
const lockfile = /(?:^|\/)(?:pnpm-lock\.yaml|package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|bun\.lockb?)$/;
|
|
361
360
|
/**
|
|
362
361
|
* Find base changes that a staged merge of `base` into the PR `head` undoes.
|
|
@@ -393,7 +392,69 @@ async function findGitHubBaseReverts(git, options) {
|
|
|
393
392
|
}
|
|
394
393
|
return reverts;
|
|
395
394
|
}
|
|
396
|
-
/**
|
|
395
|
+
/**
|
|
396
|
+
* Find changes of the PR `head` that a staged merge of `base` undoes.
|
|
397
|
+
*
|
|
398
|
+
* A resolution that takes the base's copy of a conflicted hunk silently drops the PR's own work. This is
|
|
399
|
+
* `findGitHubBaseReverts` with the sides swapped: the result must keep every line the PR added unless
|
|
400
|
+
* the base removed it, and must not bring back a line the PR removed unless the base added it.
|
|
401
|
+
* Follow renames on both sides. `skip` names unchanged host resolutions in the staged result.
|
|
402
|
+
*/
|
|
403
|
+
async function findGitHubHeadReverts(git, options) {
|
|
404
|
+
const origin = (await git("merge-base", options.head, options.base)).trim();
|
|
405
|
+
const skipped = new Set(options.skip);
|
|
406
|
+
const [headChanges, baseChanges, stagedChanges] = await Promise.all([
|
|
407
|
+
changedPaths(git, origin, options.head),
|
|
408
|
+
changedPaths(git, origin, options.base),
|
|
409
|
+
changedPaths(git, "--cached", options.head)
|
|
410
|
+
]);
|
|
411
|
+
const differs = /* @__PURE__ */ new Set([...stagedChanges.keys(), ...stagedChanges.values()]);
|
|
412
|
+
const reverts = [];
|
|
413
|
+
for (const [original, path] of headChanges) {
|
|
414
|
+
const base = baseChanges.get(original) ?? original;
|
|
415
|
+
const staged = stagedChanges.get(path) ?? path;
|
|
416
|
+
if (!differs.has(path) && !differs.has(base)) continue;
|
|
417
|
+
const merged = staged === path && base !== path && !await isBlob(git, `:${path}`) ? base : staged;
|
|
418
|
+
if (skipped.has(merged) || [
|
|
419
|
+
original,
|
|
420
|
+
path,
|
|
421
|
+
base,
|
|
422
|
+
merged
|
|
423
|
+
].some((name) => lockfile.test(name))) continue;
|
|
424
|
+
const [o, b, p, r] = await Promise.all([
|
|
425
|
+
`${origin}:${original}`,
|
|
426
|
+
`${options.base}:${base}`,
|
|
427
|
+
`${options.head}:${path}`,
|
|
428
|
+
`:${merged}`
|
|
429
|
+
].map((spec) => blob(git, spec)));
|
|
430
|
+
if ([
|
|
431
|
+
o,
|
|
432
|
+
b,
|
|
433
|
+
p,
|
|
434
|
+
r
|
|
435
|
+
].some((text) => text.includes("\0"))) continue;
|
|
436
|
+
const revert = revertedLines(o, p, b, r);
|
|
437
|
+
if (revert.dropped.length || revert.restored.length) reverts.push({
|
|
438
|
+
path,
|
|
439
|
+
...revert
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
return reverts;
|
|
443
|
+
}
|
|
444
|
+
async function changedPaths(git, ...refs) {
|
|
445
|
+
const entries = names(await git("diff", "--name-status", "--find-renames", "-z", ...refs));
|
|
446
|
+
const paths = /* @__PURE__ */ new Map();
|
|
447
|
+
for (let index = 0; index < entries.length;) {
|
|
448
|
+
const status = entries[index++];
|
|
449
|
+
const path = entries[index++];
|
|
450
|
+
paths.set(path, status.startsWith("R") ? entries[index++] : path);
|
|
451
|
+
}
|
|
452
|
+
return paths;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Compare one file's merge base, base, PR head and merge result. Pass the PR head as `base` and the
|
|
456
|
+
* base as `head` to find what the result undoes of the PR.
|
|
457
|
+
*/
|
|
397
458
|
function revertedLines(origin, base, head, result) {
|
|
398
459
|
const [o, b, p, r] = [
|
|
399
460
|
origin,
|
|
@@ -431,12 +492,12 @@ function lineCounts(text) {
|
|
|
431
492
|
}
|
|
432
493
|
return counts;
|
|
433
494
|
}
|
|
495
|
+
const isBlob = (git, spec) => git("cat-file", "-t", spec).then((type) => type.trim() === "blob", () => false);
|
|
434
496
|
async function blob(git, spec) {
|
|
435
|
-
return await git
|
|
497
|
+
return await isBlob(git, spec) ? await git("cat-file", "blob", spec) : "";
|
|
436
498
|
}
|
|
437
499
|
const names = (output) => output.split("\0").filter(Boolean);
|
|
438
|
-
|
|
439
|
-
//#region src/github/install-inputs.ts
|
|
500
|
+
// src/github/install-inputs.ts
|
|
440
501
|
const inputNames = /* @__PURE__ */ new Set([
|
|
441
502
|
".npmrc",
|
|
442
503
|
".yarnrc.yml",
|
|
@@ -837,8 +898,7 @@ const publishOutputScript = `
|
|
|
837
898
|
if (present[index]) await rename(join(source, name), name);
|
|
838
899
|
}
|
|
839
900
|
`;
|
|
840
|
-
|
|
841
|
-
//#region src/github/install-snapshot.ts
|
|
901
|
+
// src/github/install-snapshot.ts
|
|
842
902
|
const exec$5 = promisify(execFile);
|
|
843
903
|
const yarnOutputs = /* @__PURE__ */ new Set([
|
|
844
904
|
"cache",
|
|
@@ -967,8 +1027,7 @@ async function publishGitHubInstallSnapshot(snapshot, signal) {
|
|
|
967
1027
|
});
|
|
968
1028
|
}
|
|
969
1029
|
}
|
|
970
|
-
|
|
971
|
-
//#region src/github/install.ts
|
|
1030
|
+
// src/github/install.ts
|
|
972
1031
|
const exec$4 = promisify(execFile);
|
|
973
1032
|
const manifest = v.object({ packageManager: v.optional(v.string()) });
|
|
974
1033
|
const systemError = v.object({ errno: v.pipe(v.number(), v.integer(), v.maxValue(-1)) });
|
|
@@ -1405,8 +1464,7 @@ async function hasCurrentGitHubDependencies(target, inputs = target) {
|
|
|
1405
1464
|
return false;
|
|
1406
1465
|
}
|
|
1407
1466
|
}
|
|
1408
|
-
|
|
1409
|
-
//#region src/github/conflicts.ts
|
|
1467
|
+
// src/github/conflicts.ts
|
|
1410
1468
|
/**
|
|
1411
1469
|
* Resolve conflicts of a prepared merge that need no judgment, and stage each resolution.
|
|
1412
1470
|
* Ours is the PR head and theirs is the base. Anything the rules cannot prove stays conflicted.
|
|
@@ -1762,8 +1820,7 @@ function lockfileResolutions(text) {
|
|
|
1762
1820
|
for (const [key, versions] of edgeVersions) resolutions.set(key, [...new Set(versions)].sort().join(" "));
|
|
1763
1821
|
return resolutions;
|
|
1764
1822
|
}
|
|
1765
|
-
|
|
1766
|
-
//#region src/github/repair.ts
|
|
1823
|
+
// src/github/repair.ts
|
|
1767
1824
|
const exec$3 = promisify(execFile);
|
|
1768
1825
|
/** Git metadata is protected by provider sandboxes. Only the host stages repairs. */
|
|
1769
1826
|
async function commitGitHubPullRequestWorkspace(target, input, options) {
|
|
@@ -1793,17 +1850,29 @@ async function commitGitHubPullRequestWorkspace(target, input, options) {
|
|
|
1793
1850
|
if (skipped.length) await git("update-index", "--no-skip-worktree", "--", ...skipped);
|
|
1794
1851
|
await git("add", "--sparse", "--", ...input.paths);
|
|
1795
1852
|
if (mergeRecord) {
|
|
1853
|
+
const index = await git("ls-files", "--stage", "-z");
|
|
1796
1854
|
await writeFile(recordPath, JSON.stringify({
|
|
1797
1855
|
...mergeRecord,
|
|
1798
|
-
index: digest$1(
|
|
1856
|
+
index: digest$1(index)
|
|
1799
1857
|
}));
|
|
1800
1858
|
const unresolved = await git("diff", "--name-only", "--diff-filter=U");
|
|
1801
1859
|
if (unresolved) throw presetsErrorDiagnostics.PRESETS_REPAIR_CONFLICTS_UNRESOLVED({ files: unresolved });
|
|
1802
1860
|
const reasons = new Map(input.baseOverrides?.map(({ path, reason }) => [path, reason.trim()]));
|
|
1803
1861
|
const reverts = await findGitHubBaseReverts(git.raw, mergeRecord);
|
|
1804
1862
|
const unexplained = reverts.filter(({ path }) => !reasons.get(path));
|
|
1805
|
-
if (unexplained.length) throw presetsErrorDiagnostics.PRESETS_REPAIR_BASE_REVERTED({ files:
|
|
1863
|
+
if (unexplained.length) throw presetsErrorDiagnostics.PRESETS_REPAIR_BASE_REVERTED({ files: describeReverts(unexplained, "base line(s)", "the base") });
|
|
1864
|
+
const prReasons = new Map(input.prOverrides?.map(({ path, reason }) => [path, reason.trim()]));
|
|
1865
|
+
const staged = stagedEntries(index);
|
|
1866
|
+
const skip = mergeRecord.hostResolvedEntries?.filter(({ path, entry }) => staged.get(path) === entry).map(({ path }) => path);
|
|
1867
|
+
const prReverts = await findGitHubHeadReverts(git.raw, {
|
|
1868
|
+
head: mergeRecord.head,
|
|
1869
|
+
base: mergeRecord.base,
|
|
1870
|
+
skip
|
|
1871
|
+
});
|
|
1872
|
+
const unexplainedPr = prReverts.filter(({ path }) => !prReasons.get(path));
|
|
1873
|
+
if (unexplainedPr.length) throw presetsErrorDiagnostics.PRESETS_REPAIR_PR_REVERTED({ files: describeReverts(unexplainedPr, "line(s) of this PR", "this PR") });
|
|
1806
1874
|
if (reverts.length) message += `\n\nKeeps this PR's version over base changes:\n${reverts.map(({ path }) => `- ${path}: ${reasons.get(path)}`).join("\n")}`;
|
|
1875
|
+
if (prReverts.length) message += `\n\nKeeps the base version over this PR's changes:\n${prReverts.map(({ path }) => `- ${path}: ${prReasons.get(path)}`).join("\n")}`;
|
|
1807
1876
|
}
|
|
1808
1877
|
if (options.verifyDependencies) {
|
|
1809
1878
|
const directory = await mkdtemp(join(target, ".git", "vitehub-commit-snapshot-"));
|
|
@@ -1831,6 +1900,10 @@ const mergeRecordSchema = v.object({
|
|
|
1831
1900
|
head: v.string(),
|
|
1832
1901
|
base: v.string(),
|
|
1833
1902
|
index: v.string(),
|
|
1903
|
+
hostResolvedEntries: v.optional(v.array(v.object({
|
|
1904
|
+
path: v.string(),
|
|
1905
|
+
entry: v.string()
|
|
1906
|
+
}))),
|
|
1834
1907
|
conflicts: v.optional(v.object({
|
|
1835
1908
|
conflicted: v.array(v.string()),
|
|
1836
1909
|
resolved: v.array(v.object({
|
|
@@ -1845,16 +1918,25 @@ const mergeRecordSchema = v.object({
|
|
|
1845
1918
|
lockfile: v.optional(v.string())
|
|
1846
1919
|
}))
|
|
1847
1920
|
});
|
|
1848
|
-
function
|
|
1921
|
+
function describeReverts(reverts, added, remover) {
|
|
1849
1922
|
const quote = (line) => JSON.stringify(line.length > 100 ? `${line.slice(0, 100)}…` : line);
|
|
1850
1923
|
return reverts.slice(0, 10).map(({ path, dropped, restored }) => [
|
|
1851
1924
|
`${path}:`,
|
|
1852
|
-
dropped.length ? ` drops ${dropped.length}
|
|
1925
|
+
dropped.length ? ` drops ${dropped.length} ${added} such as ${dropped.slice(0, 2).map(quote).join(", ")}` : "",
|
|
1853
1926
|
dropped.length && restored.length ? ";" : "",
|
|
1854
|
-
restored.length ? ` restores ${restored.length} line(s)
|
|
1927
|
+
restored.length ? ` restores ${restored.length} line(s) ${remover} removed, such as ${restored.slice(0, 2).map(quote).join(", ")}` : ""
|
|
1855
1928
|
].join("")).join("\n") + (reverts.length > 10 ? `\nand ${reverts.length - 10} more files` : "");
|
|
1856
1929
|
}
|
|
1857
1930
|
const digest$1 = (index) => createHash("sha256").update(index).digest("hex");
|
|
1931
|
+
function stagedEntries(index) {
|
|
1932
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1933
|
+
for (const record of index.split("\0")) {
|
|
1934
|
+
const tab = record.indexOf(" ");
|
|
1935
|
+
const entry = record.slice(0, tab);
|
|
1936
|
+
if (tab !== -1 && entry.endsWith(" 0")) entries.set(record.slice(tab + 1), entry);
|
|
1937
|
+
}
|
|
1938
|
+
return entries;
|
|
1939
|
+
}
|
|
1858
1940
|
function repairGit(target, options) {
|
|
1859
1941
|
const env = {
|
|
1860
1942
|
PATH: process.env.PATH,
|
|
@@ -1910,16 +1992,25 @@ async function prepareGitHubRepairBase(target, options) {
|
|
|
1910
1992
|
...options.conflicts,
|
|
1911
1993
|
signal: options.signal
|
|
1912
1994
|
});
|
|
1995
|
+
const index = await git("ls-files", "--stage", "-z");
|
|
1996
|
+
const staged = stagedEntries(index);
|
|
1997
|
+
const hostResolvedEntries = conflicts?.resolved.flatMap(({ path }) => {
|
|
1998
|
+
const entry = staged.get(path);
|
|
1999
|
+
return entry === void 0 ? [] : [{
|
|
2000
|
+
path,
|
|
2001
|
+
entry
|
|
2002
|
+
}];
|
|
2003
|
+
});
|
|
1913
2004
|
await writeFile(join(target, ".git", "vitehub-merge.json"), JSON.stringify({
|
|
1914
2005
|
head: options.expectedHead,
|
|
1915
2006
|
base: options.base,
|
|
1916
|
-
index: digest$1(
|
|
1917
|
-
conflicts
|
|
2007
|
+
index: digest$1(index),
|
|
2008
|
+
conflicts,
|
|
2009
|
+
hostResolvedEntries
|
|
1918
2010
|
}));
|
|
1919
2011
|
return conflicts;
|
|
1920
2012
|
}
|
|
1921
|
-
|
|
1922
|
-
//#region src/github/host.ts
|
|
2013
|
+
// src/github/host.ts
|
|
1923
2014
|
const exec$2 = promisify(execFile);
|
|
1924
2015
|
const rateLimitLimit = 256;
|
|
1925
2016
|
function secret(value) {
|
|
@@ -2658,8 +2749,7 @@ function createGitHubHost(options) {
|
|
|
2658
2749
|
withPullRequestCheckout
|
|
2659
2750
|
};
|
|
2660
2751
|
}
|
|
2661
|
-
|
|
2662
|
-
//#region src/github/pull-requests.ts
|
|
2752
|
+
// src/github/pull-requests.ts
|
|
2663
2753
|
const rollupSchema = v.object({ nodes: v.array(v.object({ commit: v.object({ statusCheckRollup: v.nullable(v.object({ contexts: v.object({ nodes: v.array(v.unknown()) }) })) }) })) });
|
|
2664
2754
|
v.pipe(v.object({
|
|
2665
2755
|
baseRefOid: v.string(),
|
|
@@ -2714,8 +2804,7 @@ async function createGitHubPullRequestRun(repository, pullRequest, options) {
|
|
|
2714
2804
|
}
|
|
2715
2805
|
};
|
|
2716
2806
|
}
|
|
2717
|
-
|
|
2718
|
-
//#region src/github/required-checks.ts
|
|
2807
|
+
// src/github/required-checks.ts
|
|
2719
2808
|
/** Cache authoritative policy, including explicit unknown results; never infer CI requirements from names. */
|
|
2720
2809
|
function createGitHubRequiredCheckPolicyReader(read, options = {}) {
|
|
2721
2810
|
const clock = options.clock ?? Date.now;
|
|
@@ -2866,8 +2955,7 @@ function combine(states) {
|
|
|
2866
2955
|
if (!states.length || states.includes("unknown")) return "unknown";
|
|
2867
2956
|
return states.includes("pending") ? "pending" : "passed";
|
|
2868
2957
|
}
|
|
2869
|
-
|
|
2870
|
-
//#region src/babysitter/inbox/budgets.ts
|
|
2958
|
+
// src/babysitter/inbox/budgets.ts
|
|
2871
2959
|
const count = v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(Number.MAX_SAFE_INTEGER - 1));
|
|
2872
2960
|
const providerBudgetSchema = v.object({
|
|
2873
2961
|
generation: v.string(),
|
|
@@ -3016,8 +3104,7 @@ function validateBudgets(budgets) {
|
|
|
3016
3104
|
function requireEvidence(evidence) {
|
|
3017
3105
|
invariant(evidence.trim(), "the inbox passes evidence that the runtime builds, such as push:<sha>, or a fixed reset reason");
|
|
3018
3106
|
}
|
|
3019
|
-
|
|
3020
|
-
//#region src/babysitter/inbox/wait-state.ts
|
|
3107
|
+
// src/babysitter/inbox/wait-state.ts
|
|
3021
3108
|
const nonempty = v.pipe(v.string(), v.minLength(1));
|
|
3022
3109
|
const repository = v.pipe(v.string(), v.regex(/^[\w.-]+\/[\w.-]+$/));
|
|
3023
3110
|
const commitSha = v.pipe(v.string(), v.regex(/^[a-f0-9]{40,64}$/));
|
|
@@ -3042,8 +3129,7 @@ const waitSchema = v.object({
|
|
|
3042
3129
|
wake: v.optional(wakeSchema)
|
|
3043
3130
|
});
|
|
3044
3131
|
const parseWait = (value) => v.parse(waitSchema, value);
|
|
3045
|
-
|
|
3046
|
-
//#region src/babysitter/inbox/storage.ts
|
|
3132
|
+
// src/babysitter/inbox/storage.ts
|
|
3047
3133
|
function isBusy(error) {
|
|
3048
3134
|
return error instanceof Error && ("errcode" in error && (error.errcode === 5 || error.errcode === 6) || /database is (?:locked|busy)/i.test(error.message));
|
|
3049
3135
|
}
|
|
@@ -3116,8 +3202,7 @@ function createNodeSqliteInboxStorage(path) {
|
|
|
3116
3202
|
}
|
|
3117
3203
|
};
|
|
3118
3204
|
}
|
|
3119
|
-
|
|
3120
|
-
//#region src/babysitter/inbox/status-delivery.ts
|
|
3205
|
+
// src/babysitter/inbox/status-delivery.ts
|
|
3121
3206
|
const statusOutboxPrefix = "status-outbox:v1:";
|
|
3122
3207
|
const statusWriterPrefix = "status-writers:v1:";
|
|
3123
3208
|
const statusSentPrefix = "status-sent:v1:";
|
|
@@ -3185,8 +3270,7 @@ function isStatusDeliveryCurrent(pending, snapshot) {
|
|
|
3185
3270
|
const terminalResult = snapshot.status === "terminal" && pending.activity.status === "completed";
|
|
3186
3271
|
return snapshot.lastResult === pending.text && (snapshot.generation === pending.generation || Boolean(repairHeadObserved) || terminalResult);
|
|
3187
3272
|
}
|
|
3188
|
-
|
|
3189
|
-
//#region src/babysitter/inbox/types.ts
|
|
3273
|
+
// src/babysitter/inbox/types.ts
|
|
3190
3274
|
const actor = v.nullish(v.object({
|
|
3191
3275
|
login: v.optional(v.string()),
|
|
3192
3276
|
type: v.optional(v.string()),
|
|
@@ -3348,8 +3432,7 @@ const deliverySchema = v.looseObject({
|
|
|
3348
3432
|
state: v.optional(v.string())
|
|
3349
3433
|
});
|
|
3350
3434
|
const parseDelivery = (value) => v.parse(deliverySchema, value);
|
|
3351
|
-
|
|
3352
|
-
//#region src/babysitter/inbox/store.ts
|
|
3435
|
+
// src/babysitter/inbox/store.ts
|
|
3353
3436
|
const digest = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
3354
3437
|
const statusContentKey = (snapshot, head = snapshot.wait?.headSha ?? snapshot.pr?.head?.sha) => digest([
|
|
3355
3438
|
head,
|
|
@@ -5537,8 +5620,7 @@ var PullRequestInbox = class {
|
|
|
5537
5620
|
});
|
|
5538
5621
|
}
|
|
5539
5622
|
};
|
|
5540
|
-
|
|
5541
|
-
//#region src/babysitter/inbox/snapshot-prompt.ts
|
|
5623
|
+
// src/babysitter/inbox/snapshot-prompt.ts
|
|
5542
5624
|
const author = (value) => ({
|
|
5543
5625
|
login: value.user?.login ?? value.author?.login ?? null,
|
|
5544
5626
|
type: value.user?.type ?? value.author?.__typename ?? "unknown"
|
|
@@ -5731,8 +5813,7 @@ function assertPromptFits(message, limit = 95e4) {
|
|
|
5731
5813
|
limit
|
|
5732
5814
|
});
|
|
5733
5815
|
}
|
|
5734
|
-
|
|
5735
|
-
//#region src/babysitter/inbox/claim-state.ts
|
|
5816
|
+
// src/babysitter/inbox/claim-state.ts
|
|
5736
5817
|
/** REST fields are authoritative; older persisted GraphQL aliases may be stale. */
|
|
5737
5818
|
function snapshotPullRequest(snapshot) {
|
|
5738
5819
|
const pr = snapshot.pr;
|
|
@@ -5790,8 +5871,7 @@ function createClaimStopCheck(claim, readCurrent, readProviderHead, now = Date.n
|
|
|
5790
5871
|
acceptedSelfHead = providerHead;
|
|
5791
5872
|
};
|
|
5792
5873
|
}
|
|
5793
|
-
|
|
5794
|
-
//#region src/babysitter/inbox/snapshot-sync.ts
|
|
5874
|
+
// src/babysitter/inbox/snapshot-sync.ts
|
|
5795
5875
|
/** Read review conversations through forges `threads.reviewThreads()`. */
|
|
5796
5876
|
async function readForgePullRequestThreads(provider, repository, number, signal) {
|
|
5797
5877
|
const repo = repoRef(provider, repository);
|
|
@@ -5880,6 +5960,26 @@ async function readThreadComments(request, id) {
|
|
|
5880
5960
|
} while (after);
|
|
5881
5961
|
return comments;
|
|
5882
5962
|
}
|
|
5963
|
+
/** The check runs and commit statuses that GitHub reports for one commit now. */
|
|
5964
|
+
async function readHeadChecks(read, repository, head, signal) {
|
|
5965
|
+
const readAll = async (path, projection) => {
|
|
5966
|
+
const items = [];
|
|
5967
|
+
for (let page = 1;; page++) {
|
|
5968
|
+
const batch = await read(`${path}&page=${page}`, projection, signal);
|
|
5969
|
+
signal?.throwIfAborted();
|
|
5970
|
+
items.push(...batch);
|
|
5971
|
+
if (batch.length < 100) return items;
|
|
5972
|
+
}
|
|
5973
|
+
};
|
|
5974
|
+
const [checks, statuses] = await Promise.all([readAll(`repos/${repository}/commits/${head}/check-runs?per_page=100`, ".check_runs[]"), readAll(`repos/${repository}/commits/${head}/statuses?per_page=100`)]);
|
|
5975
|
+
return {
|
|
5976
|
+
checks: Object.fromEntries(checks.map(parseEvidence).filter((c) => !isBabysitterCheckRun(c)).map((c) => [`check_run:${c.id}`, c])),
|
|
5977
|
+
statuses: Object.fromEntries(statuses.map(parseEvidence).reverse().map((s) => [s.context, {
|
|
5978
|
+
...s,
|
|
5979
|
+
sha: head
|
|
5980
|
+
}]))
|
|
5981
|
+
};
|
|
5982
|
+
}
|
|
5883
5983
|
/** REST snapshots fill webhook gaps without asking an LLM to poll GitHub. */
|
|
5884
5984
|
async function readSnapshot(read, repository, number, readThreads, activityAuthors = [], signal) {
|
|
5885
5985
|
const prefix = `repos/${repository}`;
|
|
@@ -5898,12 +5998,11 @@ async function readSnapshot(read, repository, number, readThreads, activityAutho
|
|
|
5898
5998
|
if (batch.length < 100) return items;
|
|
5899
5999
|
}
|
|
5900
6000
|
};
|
|
5901
|
-
const [comments, reviews, reviewComments,
|
|
6001
|
+
const [comments, reviews, reviewComments, headChecks, threads] = await Promise.all([
|
|
5902
6002
|
readAll(`${prefix}/issues/${number}/comments?per_page=100`),
|
|
5903
6003
|
readAll(`${prefix}/pulls/${number}/reviews?per_page=100`),
|
|
5904
6004
|
readAll(`${prefix}/pulls/${number}/comments?per_page=100`),
|
|
5905
|
-
|
|
5906
|
-
readAll(`${prefix}/commits/${pr.head.sha}/statuses?per_page=100`),
|
|
6005
|
+
readHeadChecks(read, repository, pr.head.sha, signal),
|
|
5907
6006
|
readThreads?.(repository, number, signal)
|
|
5908
6007
|
]);
|
|
5909
6008
|
const normalizedActivityAuthors = new Set(activityAuthors.map((author) => author.trim().toLowerCase()));
|
|
@@ -5912,8 +6011,7 @@ async function readSnapshot(read, repository, number, readThreads, activityAutho
|
|
|
5912
6011
|
comments: index(comments.map(parseEvidence).filter((comment) => !(normalizedActivityAuthors.has(String(comment.user?.login ?? comment.author?.login ?? "").trim().toLowerCase()) && String(comment.body ?? "").startsWith("<!-- vitehub-agent-activity:")))),
|
|
5913
6012
|
reviews: index(reviews.map(parseEvidence)),
|
|
5914
6013
|
reviewComments: index(reviewComments.map(parseEvidence)),
|
|
5915
|
-
|
|
5916
|
-
statuses: Object.fromEntries(statuses.map(parseEvidence).reverse().map((s) => [s.context, s])),
|
|
6014
|
+
...headChecks,
|
|
5917
6015
|
hydrated: true
|
|
5918
6016
|
};
|
|
5919
6017
|
if (threads) Object.assign(snapshot, {
|
|
@@ -6259,8 +6357,7 @@ async function probeChangedSnapshots(inbox, read, now = Date.now(), readThreads,
|
|
|
6259
6357
|
}
|
|
6260
6358
|
return probed;
|
|
6261
6359
|
}
|
|
6262
|
-
|
|
6263
|
-
//#region src/babysitter/box-commit.ts
|
|
6360
|
+
// src/babysitter/box-commit.ts
|
|
6264
6361
|
/** Import committed Sandbox work before the host publishes it with host-owned credentials. */
|
|
6265
6362
|
async function importSandboxCommit(session, checkout, base, signal) {
|
|
6266
6363
|
const git = async (args) => {
|
|
@@ -6354,8 +6451,7 @@ async function importSandboxCommit(session, checkout, base, signal) {
|
|
|
6354
6451
|
await session.files.remove(remoteBundle, { signal }).catch(() => {});
|
|
6355
6452
|
}
|
|
6356
6453
|
}
|
|
6357
|
-
|
|
6358
|
-
//#region src/babysitter/checkout-watch.ts
|
|
6454
|
+
// src/babysitter/checkout-watch.ts
|
|
6359
6455
|
const exec$1 = promisify(execFile);
|
|
6360
6456
|
/** Read host checkout proof when a synchronize event changes the claimed head. */
|
|
6361
6457
|
function createProviderHeadReader(providerDirectory, pushedHead) {
|
|
@@ -6374,8 +6470,7 @@ function createProviderHeadReader(providerDirectory, pushedHead) {
|
|
|
6374
6470
|
})).stdout.trim();
|
|
6375
6471
|
};
|
|
6376
6472
|
}
|
|
6377
|
-
|
|
6378
|
-
//#region src/babysitter/box-repair.ts
|
|
6473
|
+
// src/babysitter/box-repair.ts
|
|
6379
6474
|
const exec = promisify(execFile);
|
|
6380
6475
|
const inside = (root, path) => {
|
|
6381
6476
|
const part = relative(root, path);
|
|
@@ -6531,8 +6626,7 @@ async function publishSandboxDependencies(session, checkout, signal) {
|
|
|
6531
6626
|
await session.files.remove(remote, { signal }).catch(() => {});
|
|
6532
6627
|
}
|
|
6533
6628
|
}
|
|
6534
|
-
|
|
6535
|
-
//#region src/babysitter/feedback.ts
|
|
6629
|
+
// src/babysitter/feedback.ts
|
|
6536
6630
|
const feedbackInputSchema = v.strictObject({
|
|
6537
6631
|
kind: v.picklist([
|
|
6538
6632
|
"comment",
|
|
@@ -6595,8 +6689,7 @@ function readBabysitterFeedback(snapshot, input) {
|
|
|
6595
6689
|
}
|
|
6596
6690
|
};
|
|
6597
6691
|
}
|
|
6598
|
-
|
|
6599
|
-
//#region src/babysitter/repair.ts
|
|
6692
|
+
// src/babysitter/repair.ts
|
|
6600
6693
|
const noArguments = {
|
|
6601
6694
|
type: "object",
|
|
6602
6695
|
properties: {},
|
|
@@ -6751,7 +6844,7 @@ function repairCapability(operations, autoMerge, mentionAllowlist = [], beforePu
|
|
|
6751
6844
|
},
|
|
6752
6845
|
commitRepair: {
|
|
6753
6846
|
name: "commitRepair",
|
|
6754
|
-
description: "Stage the named repair files and commit them on the host. Git metadata is read-only in the provider sandbox. A base merge is rejected when it undoes base
|
|
6847
|
+
description: "Stage the named repair files and commit them on the host. Git metadata is read-only in the provider sandbox. A base merge is rejected when it undoes changes of the base or of this PR, unless baseOverrides or prOverrides names each such file with a reason. Call pushRepair after validation and this commit.",
|
|
6755
6848
|
inputSchema: {
|
|
6756
6849
|
type: "object",
|
|
6757
6850
|
properties: {
|
|
@@ -6785,6 +6878,25 @@ function repairCapability(operations, autoMerge, mentionAllowlist = [], beforePu
|
|
|
6785
6878
|
required: ["path", "reason"],
|
|
6786
6879
|
additionalProperties: false
|
|
6787
6880
|
}
|
|
6881
|
+
},
|
|
6882
|
+
prOverrides: {
|
|
6883
|
+
type: "array",
|
|
6884
|
+
description: "Files where the base version deliberately replaces a change this PR made, each with a one-sentence reason.",
|
|
6885
|
+
items: {
|
|
6886
|
+
type: "object",
|
|
6887
|
+
properties: {
|
|
6888
|
+
path: {
|
|
6889
|
+
type: "string",
|
|
6890
|
+
minLength: 1
|
|
6891
|
+
},
|
|
6892
|
+
reason: {
|
|
6893
|
+
type: "string",
|
|
6894
|
+
minLength: 1
|
|
6895
|
+
}
|
|
6896
|
+
},
|
|
6897
|
+
required: ["path", "reason"],
|
|
6898
|
+
additionalProperties: false
|
|
6899
|
+
}
|
|
6788
6900
|
}
|
|
6789
6901
|
},
|
|
6790
6902
|
required: ["message", "paths"],
|
|
@@ -6793,18 +6905,25 @@ function repairCapability(operations, autoMerge, mentionAllowlist = [], beforePu
|
|
|
6793
6905
|
execute: (input) => withinRepair(async () => {
|
|
6794
6906
|
if (!isRuntimeRecord(input) || !Array.isArray(input.paths) || !input.paths.every((path) => hasRuntimeType(path, "string"))) throw presetsErrorDiagnostics.PRESETS_BABYSITTER_TOOL_PATHS_MISSING();
|
|
6795
6907
|
await workspace?.beforeRepair(context.context, input.paths);
|
|
6796
|
-
|
|
6797
|
-
key
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6908
|
+
const overrides = (key) => {
|
|
6909
|
+
const entries = input[key];
|
|
6910
|
+
if (entries === void 0) return void 0;
|
|
6911
|
+
if (!Array.isArray(entries)) throw presetsErrorDiagnostics.PRESETS_BABYSITTER_TOOL_FIELD_INVALID({
|
|
6912
|
+
key,
|
|
6913
|
+
expected: "an array"
|
|
6914
|
+
});
|
|
6915
|
+
return entries.map((entry) => ({
|
|
6916
|
+
path: stringField(entry, "path"),
|
|
6917
|
+
reason: stringField(entry, "reason")
|
|
6918
|
+
}));
|
|
6919
|
+
};
|
|
6920
|
+
const baseOverrides = overrides("baseOverrides");
|
|
6921
|
+
const prOverrides = overrides("prOverrides");
|
|
6804
6922
|
return { head: await operations.commitRepair({
|
|
6805
6923
|
message: stringField(input, "message"),
|
|
6806
6924
|
paths: input.paths,
|
|
6807
|
-
...baseOverrides && { baseOverrides }
|
|
6925
|
+
...baseOverrides && { baseOverrides },
|
|
6926
|
+
...prOverrides && { prOverrides }
|
|
6808
6927
|
}) };
|
|
6809
6928
|
})
|
|
6810
6929
|
},
|
|
@@ -6937,8 +7056,7 @@ function repairEnvironment(environment = {}, githubConfigDirectory, identity = {
|
|
|
6937
7056
|
GIT_TERMINAL_PROMPT: "0"
|
|
6938
7057
|
};
|
|
6939
7058
|
}
|
|
6940
|
-
|
|
6941
|
-
//#region src/babysitter/wait.ts
|
|
7059
|
+
// src/babysitter/wait.ts
|
|
6942
7060
|
const hash = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
6943
7061
|
const pending = /* @__PURE__ */ new Set([
|
|
6944
7062
|
"queued",
|
|
@@ -7275,8 +7393,7 @@ function checksDependencyEvidence(checks) {
|
|
|
7275
7393
|
])).sort()
|
|
7276
7394
|
});
|
|
7277
7395
|
}
|
|
7278
|
-
|
|
7279
|
-
//#region src/babysitter/provider-quota.ts
|
|
7396
|
+
// src/babysitter/provider-quota.ts
|
|
7280
7397
|
const providerBlockedKey = "provider-quota-blocked-until";
|
|
7281
7398
|
const providerStrikesKey = "provider-quota-strikes";
|
|
7282
7399
|
const forgeBlockedKey = "forge-quota-blocked-until";
|
|
@@ -7340,8 +7457,7 @@ function createForgeQuota(store, now = Date.now) {
|
|
|
7340
7457
|
}
|
|
7341
7458
|
};
|
|
7342
7459
|
}
|
|
7343
|
-
|
|
7344
|
-
//#region src/babysitter/base-freshness.ts
|
|
7460
|
+
// src/babysitter/base-freshness.ts
|
|
7345
7461
|
/** Files the comparison may list before it counts as truncated. GitHub caps this at 300. */
|
|
7346
7462
|
const compareFileLimit = 300;
|
|
7347
7463
|
/** Pushes this close to the run start may not be in the run's checkout. */
|
|
@@ -7454,8 +7570,7 @@ async function baseFixedSinceFailure(reader, snapshot, failed, signal) {
|
|
|
7454
7570
|
for (const value of baseStatuses) if (isRuntimeRecord(value) && hasRuntimeType(value.context, "string") && hasRuntimeType(value.state, "string") && !latestStatuses.has(value.context)) latestStatuses.set(value.context, value.state);
|
|
7455
7571
|
return baseChecks.some((check) => isRuntimeRecord(check) && !isBabysitterCheckRun(check) && failing.has(String(check.name)) && hasRuntimeType(check.conclusion, "string") && failedSet.has(check.conclusion.toLowerCase())) || [...latestStatuses].some(([context, value]) => failing.has(context) && failedSet.has(value.toLowerCase())) ? void 0 : compare.ahead_by;
|
|
7456
7572
|
}
|
|
7457
|
-
|
|
7458
|
-
//#region src/babysitter/ci-attribution.ts
|
|
7573
|
+
// src/babysitter/ci-attribution.ts
|
|
7459
7574
|
const strip = (line) => stripVTControlCharacters(line.replace(/^\S+Z /, ""));
|
|
7460
7575
|
/** Undefined when no step exited with an error code. */
|
|
7461
7576
|
function parseFailedActionOutput(log) {
|
|
@@ -7656,8 +7771,7 @@ function inheritedBypassSafety({ protection, rules, reviewDecision, threadsResol
|
|
|
7656
7771
|
if (strict && !upToDate) return "branch must be up to date";
|
|
7657
7772
|
return true;
|
|
7658
7773
|
}
|
|
7659
|
-
|
|
7660
|
-
//#region src/babysitter/stack.ts
|
|
7774
|
+
// src/babysitter/stack.ts
|
|
7661
7775
|
const field = (value, ...path) => {
|
|
7662
7776
|
let current = value;
|
|
7663
7777
|
for (const key of path) current = isRuntimeRecord(current) ? current[key] : void 0;
|
|
@@ -7725,18 +7839,30 @@ function directMergeBranchSafety(repository, pr, openChildren) {
|
|
|
7725
7839
|
if (!hasRuntimeType(branch, "string")) return "pull request source branch unavailable";
|
|
7726
7840
|
return openChildren.some((child) => String(field(child, "state")).toLowerCase() === "open" && field(child, "base", "ref") === branch) ? stackChildBaseDeletion : true;
|
|
7727
7841
|
}
|
|
7728
|
-
/**
|
|
7729
|
-
|
|
7842
|
+
/**
|
|
7843
|
+
* Whether a PR's head branch lives in its base repository. GitHub reports both under the repository's
|
|
7844
|
+
* current name, so this compares them with each other, by id when both carry one. `repository` is the
|
|
7845
|
+
* configured name, which goes stale when the repository is renamed; it only stands in for a missing base.
|
|
7846
|
+
*/
|
|
7847
|
+
function headInBaseRepository(pr, repository) {
|
|
7848
|
+
const headId = field(pr, "head", "repo", "id");
|
|
7849
|
+
const baseId = field(pr, "base", "repo", "id");
|
|
7850
|
+
if (hasRuntimeType(headId, "number") && hasRuntimeType(baseId, "number")) return headId === baseId;
|
|
7730
7851
|
const headRepository = field(pr, "head", "repo", "full_name");
|
|
7731
|
-
|
|
7852
|
+
if (!hasRuntimeType(headRepository, "string")) return void 0;
|
|
7853
|
+
const baseRepository = field(pr, "base", "repo", "full_name");
|
|
7854
|
+
return headRepository.toLowerCase() === (hasRuntimeType(baseRepository, "string") ? baseRepository : repository).toLowerCase();
|
|
7855
|
+
}
|
|
7856
|
+
/** Whether a PR's head branch lives in another repository than its base, such as a fork. */
|
|
7857
|
+
function isForkHead(pr, repository) {
|
|
7858
|
+
return headInBaseRepository(pr, repository) === false;
|
|
7732
7859
|
}
|
|
7733
|
-
/** The head and base branch of a PR whose head branch lives in
|
|
7860
|
+
/** The head and base branch of a PR whose head branch lives in its base repository, which the host can push to. */
|
|
7734
7861
|
function sameRepositoryBranches(pr, repository) {
|
|
7735
7862
|
const head = field(pr, "head", "ref");
|
|
7736
7863
|
const base = field(pr, "base", "ref");
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
return headRepository.toLowerCase() === repository.toLowerCase() ? {
|
|
7864
|
+
if (!hasRuntimeType(head, "string") || !hasRuntimeType(base, "string")) return void 0;
|
|
7865
|
+
return headInBaseRepository(pr, repository) === true ? {
|
|
7740
7866
|
head,
|
|
7741
7867
|
base
|
|
7742
7868
|
} : void 0;
|
|
@@ -7794,8 +7920,7 @@ function branchFilter(pattern) {
|
|
|
7794
7920
|
}
|
|
7795
7921
|
return new RegExp(`^${source}$`);
|
|
7796
7922
|
}
|
|
7797
|
-
|
|
7798
|
-
//#region src/babysitter/merge-ready.ts
|
|
7923
|
+
// src/babysitter/merge-ready.ts
|
|
7799
7924
|
/** Fence application callbacks so stalled or rejected readiness never retains a scheduler slot. */
|
|
7800
7925
|
async function boundedMergeReady(ready, signal, timeoutMs = 5e3) {
|
|
7801
7926
|
if (signal?.aborted) return "merge readiness cancelled";
|
|
@@ -7811,8 +7936,7 @@ async function boundedMergeReady(ready, signal, timeoutMs = 5e3) {
|
|
|
7811
7936
|
Promise.resolve().then(ready).then((result) => finish(result === true ? true : hasRuntimeType(result, "string") ? result : "merge readiness declined"), () => finish("merge readiness check failed"));
|
|
7812
7937
|
});
|
|
7813
7938
|
}
|
|
7814
|
-
|
|
7815
|
-
//#region src/babysitter/install.ts
|
|
7939
|
+
// src/babysitter/install.ts
|
|
7816
7940
|
const execFileAsync = promisify(execFile);
|
|
7817
7941
|
const environmentNames = /^(?:PATH|HOME|USER|LOGNAME|LANG|LC_[A-Z]+|TMPDIR|TERM|SHELL|COREPACK_[A-Z_]+|npm_config_[a-z_]+|PNPM_HOME)$/;
|
|
7818
7942
|
const exists = (path) => access(path).then(() => true, () => false);
|
|
@@ -8139,8 +8263,7 @@ function createBabysitterInstaller(install, env = process.env, repository) {
|
|
|
8139
8263
|
};
|
|
8140
8264
|
};
|
|
8141
8265
|
}
|
|
8142
|
-
|
|
8143
|
-
//#region src/babysitter/ci-recovery.ts
|
|
8266
|
+
// src/babysitter/ci-recovery.ts
|
|
8144
8267
|
function hasFailedActions(snapshot) {
|
|
8145
8268
|
const head = snapshot.pr?.head?.sha;
|
|
8146
8269
|
return Boolean(head && Object.values(snapshot.checks).some((check) => failed$1(check) && check.head_sha === head && actionLocation(snapshot.repository, check)?.runId));
|
|
@@ -8277,8 +8400,7 @@ async function rerunFailedActions(inbox, claim, forge, now = Date.now(), signal)
|
|
|
8277
8400
|
reason: blocked.map((run) => `Actions run ${run.runId}: ${run.reason}`).join("; ")
|
|
8278
8401
|
};
|
|
8279
8402
|
}
|
|
8280
|
-
|
|
8281
|
-
//#region src/babysitter/status-recovery.ts
|
|
8403
|
+
// src/babysitter/status-recovery.ts
|
|
8282
8404
|
function isWorkerBlocker(snapshot) {
|
|
8283
8405
|
if (snapshot.wait?.kind !== "external" || snapshot.wait.wake || snapshot.wait.retryAt !== void 0) return false;
|
|
8284
8406
|
const text = `${snapshot.wait.reason}\n${snapshot.lastResult ?? ""}`;
|
|
@@ -8391,8 +8513,7 @@ function createBabysitterStatusRecovery(options) {
|
|
|
8391
8513
|
}
|
|
8392
8514
|
};
|
|
8393
8515
|
}
|
|
8394
|
-
|
|
8395
|
-
//#region src/babysitter/transient.ts
|
|
8516
|
+
// src/babysitter/transient.ts
|
|
8396
8517
|
const transientStatuses = /* @__PURE__ */ new Set([
|
|
8397
8518
|
502,
|
|
8398
8519
|
503,
|
|
@@ -8428,8 +8549,7 @@ async function retryTransient(read, signal) {
|
|
|
8428
8549
|
}
|
|
8429
8550
|
}
|
|
8430
8551
|
}
|
|
8431
|
-
|
|
8432
|
-
//#region src/babysitter/queue-health.ts
|
|
8552
|
+
// src/babysitter/queue-health.ts
|
|
8433
8553
|
/** Derive bounded operational counters from the durable queue, including scheduled retries. */
|
|
8434
8554
|
function babysitterQueueHealth(items, now = Date.now()) {
|
|
8435
8555
|
const mergedTerminal = (result) => result?.startsWith("Merged ") || result === "Asynchronous merge confirmed by GitHub." || result === "Direct merge outcome reconciled: GitHub reports the pull request merged.";
|
|
@@ -8453,8 +8573,7 @@ function babysitterQueueHealth(items, now = Date.now()) {
|
|
|
8453
8573
|
}
|
|
8454
8574
|
};
|
|
8455
8575
|
}
|
|
8456
|
-
|
|
8457
|
-
//#region src/babysitter/main-repair.ts
|
|
8576
|
+
// src/babysitter/main-repair.ts
|
|
8458
8577
|
const defaultStuckJobMinutes = 90;
|
|
8459
8578
|
const branchSchema = v.looseObject({
|
|
8460
8579
|
name: v.string(),
|
|
@@ -8484,6 +8603,8 @@ const jobsSchema = v.looseObject({ jobs: v.array(v.looseObject({
|
|
|
8484
8603
|
const pullsSchema = v.array(v.looseObject({
|
|
8485
8604
|
number: v.number(),
|
|
8486
8605
|
merged_at: v.nullish(v.string()),
|
|
8606
|
+
title: v.optional(v.string()),
|
|
8607
|
+
user: v.nullish(v.looseObject({ login: v.string() })),
|
|
8487
8608
|
head: v.looseObject({
|
|
8488
8609
|
ref: v.string(),
|
|
8489
8610
|
repo: v.nullish(v.looseObject({ full_name: v.string() }))
|
|
@@ -8530,6 +8651,12 @@ async function repairBaseBranch(github, options) {
|
|
|
8530
8651
|
const base = v.parse(repositorySchema, await github.read(`repos/${repository}`)).default_branch;
|
|
8531
8652
|
const tip = v.parse(branchSchema, await github.read(`repos/${repository}/branches/${encodeURIComponent(base)}`));
|
|
8532
8653
|
const head = tip.commit.sha;
|
|
8654
|
+
const repairTitle = (shortSha) => `fix: repair ${base} after ${shortSha}`;
|
|
8655
|
+
const repairAuthor = options.repairAuthor?.toLowerCase();
|
|
8656
|
+
const ownedRepairPull = (pull) => {
|
|
8657
|
+
const shortSha = pull.head.ref.slice(branchPrefix.length);
|
|
8658
|
+
return repairAuthor !== void 0 && pull.user?.login.toLowerCase() === repairAuthor && /^[0-9a-f]{8}$/.test(shortSha) && pull.title === repairTitle(shortSha);
|
|
8659
|
+
};
|
|
8533
8660
|
const stuckJobMinutes = mainRepair.stuckJobMinutes ?? defaultStuckJobMinutes;
|
|
8534
8661
|
if (stuckJobMinutes !== false) {
|
|
8535
8662
|
const running = v.parse(runsSchema, await github.read(`repos/${repository}/actions/runs`, {
|
|
@@ -8583,6 +8710,18 @@ async function repairBaseBranch(github, options) {
|
|
|
8583
8710
|
})).workflow_runs.filter((run) => watched(run) && !["cancelled", "skipped"].includes(run.conclusion ?? "") && Date.parse(run.created_at) > repairedAt);
|
|
8584
8711
|
failed = mainRepair.workflows.flatMap((name) => finished.find((run) => run.name === name) ?? []).find((run) => run.conclusion === "failure");
|
|
8585
8712
|
}
|
|
8713
|
+
async function* openRepairs() {
|
|
8714
|
+
for (let page = 1;; page++) {
|
|
8715
|
+
const pulls = v.parse(pullsSchema, await github.read(`repos/${repository}/pulls`, {
|
|
8716
|
+
state: "open",
|
|
8717
|
+
base,
|
|
8718
|
+
per_page: 100,
|
|
8719
|
+
page
|
|
8720
|
+
}));
|
|
8721
|
+
yield* pulls.filter(repairPull);
|
|
8722
|
+
if (pulls.length < 100) return;
|
|
8723
|
+
}
|
|
8724
|
+
}
|
|
8586
8725
|
if (!failed) {
|
|
8587
8726
|
if (!runs.length || runs.some((run) => run.status !== "completed")) {
|
|
8588
8727
|
event("waiting", {
|
|
@@ -8595,24 +8734,30 @@ async function repairBaseBranch(github, options) {
|
|
|
8595
8734
|
reason: runs.length ? "ci-running" : "no-ci-run"
|
|
8596
8735
|
};
|
|
8597
8736
|
}
|
|
8598
|
-
|
|
8599
|
-
|
|
8737
|
+
const tipPassed = runs.every((run) => run.conclusion === "success") && mainRepair.workflows.every((name) => runs.some((run) => run.name === name));
|
|
8738
|
+
const stale = [];
|
|
8739
|
+
if (tipPassed && repairAuthor) {
|
|
8740
|
+
for await (const pull of openRepairs()) if (ownedRepairPull(pull)) stale.push(pull);
|
|
8741
|
+
}
|
|
8742
|
+
for (const pull of stale) {
|
|
8743
|
+
await github.write(`repos/${repository}/issues/${pull.number}/comments`, { body: `${base} is green at ${head}, so this repair is no longer needed. Closed by the Babysitter.` });
|
|
8744
|
+
await github.write(`repos/${repository}/pulls/${pull.number}`, { state: "closed" }, "PATCH");
|
|
8745
|
+
}
|
|
8746
|
+
const closed = stale.map((pull) => pull.number);
|
|
8747
|
+
event("green", {
|
|
8748
|
+
head,
|
|
8749
|
+
...closed.length ? { closed } : {}
|
|
8750
|
+
});
|
|
8751
|
+
return closed.length ? {
|
|
8752
|
+
state: "green",
|
|
8753
|
+
head,
|
|
8754
|
+
closed
|
|
8755
|
+
} : {
|
|
8600
8756
|
state: "green",
|
|
8601
8757
|
head
|
|
8602
8758
|
};
|
|
8603
8759
|
}
|
|
8604
|
-
|
|
8605
|
-
for (let page = 1; !open; page++) {
|
|
8606
|
-
const pulls = v.parse(pullsSchema, await github.read(`repos/${repository}/pulls`, {
|
|
8607
|
-
state: "open",
|
|
8608
|
-
base,
|
|
8609
|
-
per_page: 100,
|
|
8610
|
-
page
|
|
8611
|
-
}));
|
|
8612
|
-
open = pulls.find(repairPull);
|
|
8613
|
-
if (pulls.length < 100) break;
|
|
8614
|
-
}
|
|
8615
|
-
if (open) {
|
|
8760
|
+
for await (const open of openRepairs()) {
|
|
8616
8761
|
event("repair_open", {
|
|
8617
8762
|
head,
|
|
8618
8763
|
pull_request: open.number
|
|
@@ -8667,7 +8812,7 @@ Opened automatically by the Babysitter.`;
|
|
|
8667
8812
|
});
|
|
8668
8813
|
}
|
|
8669
8814
|
const pull = v.parse(pullSchema, await github.write(`repos/${repository}/pulls`, {
|
|
8670
|
-
title:
|
|
8815
|
+
title: repairTitle(red.slice(0, 8)),
|
|
8671
8816
|
head: branch,
|
|
8672
8817
|
base,
|
|
8673
8818
|
body
|
|
@@ -8688,8 +8833,7 @@ Opened automatically by the Babysitter.`;
|
|
|
8688
8833
|
jobs: jobs.map((job) => job.name)
|
|
8689
8834
|
};
|
|
8690
8835
|
}
|
|
8691
|
-
|
|
8692
|
-
//#region src/babysitter/server.ts
|
|
8836
|
+
// src/babysitter/server.ts
|
|
8693
8837
|
/** The first and the longest wait before a reviewed head's merge gates are checked again. */
|
|
8694
8838
|
const mergeRetryMinMs = 12e4;
|
|
8695
8839
|
const mergeRetryMaxMs = 18e5;
|
|
@@ -8833,7 +8977,7 @@ function createBabysitterRuntime(options) {
|
|
|
8833
8977
|
ignoreAssessedBotThreads: presetOptions.ignoreAssessedBotThreads === true
|
|
8834
8978
|
};
|
|
8835
8979
|
const schedulerEvent = (name, properties = {}) => options.event?.(name, properties);
|
|
8836
|
-
const release = baseAgent.version ?? "
|
|
8980
|
+
const release = baseAgent.version ?? "e84ed17cf4cb5d201e05886cccf8b5601be874adf9b44800cd7ea43f162f41b5";
|
|
8837
8981
|
const workspaces = options.workspaces;
|
|
8838
8982
|
const schedulerError = (name, error, properties = {}) => options.error?.(name, error, properties);
|
|
8839
8983
|
const statusComment = !!verifiedHostIdentity && presetOptions.status?.comment !== false;
|
|
@@ -9012,9 +9156,9 @@ function createBabysitterRuntime(options) {
|
|
|
9012
9156
|
throw error;
|
|
9013
9157
|
}
|
|
9014
9158
|
},
|
|
9015
|
-
async write(path, body) {
|
|
9159
|
+
async write(path, body, method = "POST") {
|
|
9016
9160
|
const { provider } = await forge(repository, signal);
|
|
9017
|
-
return (await provider.request(
|
|
9161
|
+
return (await provider.request(method, `/${path}`, {
|
|
9018
9162
|
body,
|
|
9019
9163
|
signal
|
|
9020
9164
|
})).data;
|
|
@@ -9034,6 +9178,7 @@ function createBabysitterRuntime(options) {
|
|
|
9034
9178
|
track(repairBaseBranch(mainRepairGitHub(repository, AbortSignal.timeout(3e5)), {
|
|
9035
9179
|
repository,
|
|
9036
9180
|
branchPrefix: mainRepairPrefix,
|
|
9181
|
+
repairAuthor: verifiedHostIdentity,
|
|
9037
9182
|
mainRepair,
|
|
9038
9183
|
event: schedulerEvent
|
|
9039
9184
|
}).catch(async (error) => {
|
|
@@ -9058,8 +9203,8 @@ function createBabysitterRuntime(options) {
|
|
|
9058
9203
|
if (!authors) return false;
|
|
9059
9204
|
const { repository, number } = snapshot;
|
|
9060
9205
|
const allowed = (pr) => {
|
|
9061
|
-
if (!isRuntimeRecord(pr) || pr.draft !== true || !isRuntimeRecord(pr.user) || !isRuntimeRecord(pr.head)
|
|
9062
|
-
return pr.head.sha === snapshot.pr?.head?.sha && hasRuntimeType(pr.user.login, "string") && authors.has(pr.user.login.toLowerCase()) &&
|
|
9206
|
+
if (!isRuntimeRecord(pr) || pr.draft !== true || !isRuntimeRecord(pr.user) || !isRuntimeRecord(pr.head)) return false;
|
|
9207
|
+
return pr.head.sha === snapshot.pr?.head?.sha && hasRuntimeType(pr.user.login, "string") && authors.has(pr.user.login.toLowerCase()) && headInBaseRepository(pr, repository) === true;
|
|
9063
9208
|
};
|
|
9064
9209
|
if (!allowed(snapshot.pr)) return false;
|
|
9065
9210
|
let failure;
|
|
@@ -9158,7 +9303,13 @@ function createBabysitterRuntime(options) {
|
|
|
9158
9303
|
if (!hostIdentity) return false;
|
|
9159
9304
|
const key = forkReopenKey(repository, number);
|
|
9160
9305
|
const previous = await pullRequestInbox.meta(key);
|
|
9161
|
-
if (isRuntimeRecord(previous) && (previous.closing === true || Number(previous.at) > Date.now() - 36e5))
|
|
9306
|
+
if (isRuntimeRecord(previous) && (previous.closing === true || Number(previous.at) > Date.now() - 36e5)) {
|
|
9307
|
+
schedulerEvent("babysitter.fork_checks.reopen_skipped", {
|
|
9308
|
+
...owner,
|
|
9309
|
+
reason: previous.closing === true ? "reopen in flight" : "reopened in the last hour"
|
|
9310
|
+
});
|
|
9311
|
+
return false;
|
|
9312
|
+
}
|
|
9162
9313
|
const { provider } = await forge(repository, signal);
|
|
9163
9314
|
try {
|
|
9164
9315
|
const live = (await provider.request("GET", `/repos/${repository}/pulls/${number}`, { signal })).data;
|
|
@@ -9766,6 +9917,7 @@ function createBabysitterRuntime(options) {
|
|
|
9766
9917
|
return "blocked";
|
|
9767
9918
|
};
|
|
9768
9919
|
const stoppedKey = `direct-merge-stopped:${repository}#${number}`;
|
|
9920
|
+
const firstCheckKey = `first-check-wait:${repository}#${number}`;
|
|
9769
9921
|
if (pending) try {
|
|
9770
9922
|
const live = await readPull(repository, number, signal);
|
|
9771
9923
|
const state = isRuntimeRecord(live) && hasRuntimeType(live.state, "string") ? live.state : void 0;
|
|
@@ -9869,7 +10021,8 @@ function createBabysitterRuntime(options) {
|
|
|
9869
10021
|
return await parkMerge("GitHub merge outcome could not be reconciled; retrying the provider read.");
|
|
9870
10022
|
}
|
|
9871
10023
|
if (signal.aborted) return "blocked";
|
|
9872
|
-
const
|
|
10024
|
+
const policy = await requiredCheckPolicy(snapshot, foldInto !== void 0);
|
|
10025
|
+
const evaluation = await checkEvaluation(snapshot, policy, signal);
|
|
9873
10026
|
const savedAssessment = await pullRequestInbox.meta(`review-assessment:${repository}#${number}`);
|
|
9874
10027
|
const assessment = isRuntimeRecord(savedAssessment) && savedAssessment.version === 2 ? savedAssessment : void 0;
|
|
9875
10028
|
const reviewedEvidenceKey = isRuntimeRecord(assessment) && assessment.head === snapshot.pr?.head?.sha && hasRuntimeType(assessment.evidenceKey, "string") ? assessment.evidenceKey : void 0;
|
|
@@ -9920,6 +10073,23 @@ function createBabysitterRuntime(options) {
|
|
|
9920
10073
|
});
|
|
9921
10074
|
return pending?.asynchronous ? await parkMerge(`Unconfirmed merge is waiting for ${decision.reason}.`) : "not-ready";
|
|
9922
10075
|
}
|
|
10076
|
+
const everyCheckGates = policy.status === "known" && !policy.required.length;
|
|
10077
|
+
if (!pending && everyCheckGates && firstCheckWaitMs > 0 && headChecksUnreported(snapshot)) {
|
|
10078
|
+
const saved = await pullRequestInbox.meta(firstCheckKey);
|
|
10079
|
+
const since = isRuntimeRecord(saved) && saved.head === decision.head && hasRuntimeType(saved.since, "number") ? saved.since : pullRequestInbox.now();
|
|
10080
|
+
if (!isRuntimeRecord(saved) || saved.head !== decision.head) await pullRequestInbox.setMeta(firstCheckKey, {
|
|
10081
|
+
head: decision.head,
|
|
10082
|
+
since
|
|
10083
|
+
});
|
|
10084
|
+
const until = since + firstCheckWaitMs;
|
|
10085
|
+
if (until > pullRequestInbox.now()) {
|
|
10086
|
+
schedulerEvent("babysitter.direct_merge.skipped", {
|
|
10087
|
+
...owner,
|
|
10088
|
+
reason: "no check reported for the head yet"
|
|
10089
|
+
});
|
|
10090
|
+
return await parkMerge(`GitHub has reported no check for ${decision.head} yet; waiting until ${new Date(until).toISOString()} for its first check.`, until);
|
|
10091
|
+
}
|
|
10092
|
+
}
|
|
9923
10093
|
const stopped = pending ? void 0 : await pullRequestInbox.meta(stoppedKey);
|
|
9924
10094
|
if (isRuntimeRecord(stopped) && stopped.head === decision.head && hasRuntimeType(stopped.until, "number") && stopped.until > pullRequestInbox.now()) return await parkMerge(hasRuntimeType(stopped.reason, "string") ? stopped.reason : "Stopped waiting for a pending GitHub merge.", stopped.until);
|
|
9925
10095
|
const folding = pending ? void 0 : await pullRequestInbox.foldingChild(repository, number);
|
|
@@ -9978,7 +10148,21 @@ function createBabysitterRuntime(options) {
|
|
|
9978
10148
|
...owner,
|
|
9979
10149
|
reason: `${base} changed files this PR touches after its checks ran: ${files}`
|
|
9980
10150
|
});
|
|
9981
|
-
if (!await updateBranch(owner, repository, number, decision.head, signal, live))
|
|
10151
|
+
if (!await updateBranch(owner, repository, number, decision.head, signal, live)) {
|
|
10152
|
+
const reopened = isForkHead(live, repository) ? await pullRequestInbox.meta(forkReopenKey(repository, number)) : void 0;
|
|
10153
|
+
const at = isRuntimeRecord(reopened) ? Number(reopened.at) : NaN;
|
|
10154
|
+
const reopening = Number.isFinite(at) && at > Date.now() - 36e5;
|
|
10155
|
+
if (!reopening && !reviewPushBudgetSpent(snapshot, waitPolicy)) return "not-ready";
|
|
10156
|
+
const retryAt = reopening ? Math.max(at + 36e5, Date.now() + 6e4) : Date.now() + 6e5;
|
|
10157
|
+
await pullRequestInbox.finish(claim, {
|
|
10158
|
+
text: `${base} changed ${files} after its checks ran, and the branch could not be refreshed yet. Waiting for fresh checks or a retry.`,
|
|
10159
|
+
wait: {
|
|
10160
|
+
...createCheckWait(snapshot, waitPolicy),
|
|
10161
|
+
retryAt
|
|
10162
|
+
}
|
|
10163
|
+
});
|
|
10164
|
+
return "blocked";
|
|
10165
|
+
}
|
|
9982
10166
|
schedulerEvent("babysitter.branch.updated", {
|
|
9983
10167
|
...owner,
|
|
9984
10168
|
files: overlap.slice(0, 10)
|
|
@@ -10040,6 +10224,24 @@ function createBabysitterRuntime(options) {
|
|
|
10040
10224
|
return pending?.asynchronous ? await parkMerge(`Unconfirmed fold is waiting: ${reason}.`) : "not-ready";
|
|
10041
10225
|
}
|
|
10042
10226
|
}
|
|
10227
|
+
if (everyCheckGates) {
|
|
10228
|
+
const reported = await readHeadChecks((path, projection) => readRest(path, projection, signal), repository, decision.head, signal);
|
|
10229
|
+
const fresh = {
|
|
10230
|
+
...snapshot,
|
|
10231
|
+
...reported
|
|
10232
|
+
};
|
|
10233
|
+
const freshEvaluation = await checkEvaluation(fresh, policy, signal);
|
|
10234
|
+
const freshDecision = readiness(fresh, freshEvaluation.state, freshEvaluation.inheritedCheckIds);
|
|
10235
|
+
if (!freshDecision.ready) {
|
|
10236
|
+
schedulerEvent("babysitter.direct_merge.skipped", {
|
|
10237
|
+
...owner,
|
|
10238
|
+
reason: `GitHub reports checks the inbox lacks: ${freshDecision.reason}`
|
|
10239
|
+
});
|
|
10240
|
+
if (await pullRequestInbox.hydrate(claim, reported)) return pending ? await parkMerge(`Unconfirmed merge is waiting for ${freshDecision.reason}.`) : "not-ready";
|
|
10241
|
+
await pullRequestInbox.release(claim);
|
|
10242
|
+
return "blocked";
|
|
10243
|
+
}
|
|
10244
|
+
}
|
|
10043
10245
|
if (!await pullRequestInbox.isClaimCurrent(claim)) {
|
|
10044
10246
|
schedulerEvent("babysitter.direct_merge.skipped", {
|
|
10045
10247
|
...owner,
|
|
@@ -10111,6 +10313,7 @@ function createBabysitterRuntime(options) {
|
|
|
10111
10313
|
return await parkMerge(`GitHub merge request failed: ${(error instanceof Error ? error.message : String(error)).slice(0, 200)}`);
|
|
10112
10314
|
}
|
|
10113
10315
|
await pullRequestInbox.clearDirectMerge(repository, number, mergeToken);
|
|
10316
|
+
await pullRequestInbox.deleteMeta(firstCheckKey);
|
|
10114
10317
|
if (foldInto !== void 0) {
|
|
10115
10318
|
await pullRequestInbox.finish(claim, {
|
|
10116
10319
|
text: `Merged ${decision.head} into ${base}, the branch of parent #${foldInto}: it lands with its parent.`,
|
|
@@ -10295,6 +10498,7 @@ function createBabysitterRuntime(options) {
|
|
|
10295
10498
|
const providerRetryDelayMs = options.providerRetryDelayMs ?? 1e4;
|
|
10296
10499
|
const providerRetries = presetOptions.providerRetries ?? 3;
|
|
10297
10500
|
const mergeabilityRetryDelayMs = options.mergeabilityRetryDelayMs ?? 3e3;
|
|
10501
|
+
const firstCheckWaitMs = options.firstCheckWaitMs ?? 6e4;
|
|
10298
10502
|
/** A GitHub rate limit stops every forge request until it resets. Returns whether the error was one. */
|
|
10299
10503
|
async function noteForgeQuota(error, operation) {
|
|
10300
10504
|
if (!(error instanceof RateLimitedError)) return false;
|
|
@@ -12567,5 +12771,4 @@ function withoutCapacity(driver) {
|
|
|
12567
12771
|
const { capacity: _capacity, ...rest } = driver;
|
|
12568
12772
|
return rest;
|
|
12569
12773
|
}
|
|
12570
|
-
//#endregion
|
|
12571
12774
|
export { budgetParks as a, createGitHubHost as c, babysitterQueueHealth as i, isProviderRateLimit as n, pullRequestThreadId as o, pendingMergeRetryAt as r, createGitHubAppCredentials as s, createBabysitterRuntime as t };
|