@vite-hub/presets 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -11
- package/dist/babysitter/server.d.ts +9 -4
- package/dist/babysitter/server.js +1 -1
- package/dist/{babysitter-C71pgjkv.js → babysitter-DQeA81N0.js} +83 -29
- package/dist/babysitter.d.ts +11 -2
- package/dist/babysitter.js +1 -1
- package/dist/{error-diagnostics-BTBW9sZx.js → error-diagnostics-o3pHscWs.js} +5 -1
- package/dist/{host-Dsi6saqi.js → host-DH0o7xSq.js} +22 -51
- package/dist/labeller.d.ts +6 -2
- package/dist/labeller.js +2 -1
- package/dist/{pr-workspaces-CjX3PSqM.d.ts → pr-workspaces-CMdQ9U15.d.ts} +13 -10
- package/dist/{server-CIgjUG63.js → server-ILDJE5V7.js} +812 -195
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# @vite-hub/presets
|
|
2
2
|
|
|
3
|
-
[](https://npmx.dev/package/@vite-hub/presets)
|
|
4
|
+
[](https://npmx.dev/package/@vite-hub/presets)
|
|
5
|
+
[](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
|
|
6
|
+
[](https://vitehub.dev/docs)
|
|
7
7
|
|
|
8
8
|
`@vite-hub/presets` contains ready-made Agents that are built from ViteHub
|
|
9
9
|
primitives. Each preset is a subpath. The package depends on
|
|
10
10
|
[`@vite-hub/agent`](../agent/README.md); the Agent package does not know these presets.
|
|
11
11
|
|
|
12
|
-
Most applications use the `vite-hub/presets/*` imports of the `vite-hub` framework distribution.
|
|
12
|
+
Most applications use the `vite-hub/presets/*` imports of the `vite-hub` framework distribution. User docs: [Agent presets](https://vitehub.dev/docs/presets).
|
|
13
13
|
|
|
14
14
|
| Import | Preset |
|
|
15
15
|
| --- | --- |
|
|
@@ -35,7 +35,7 @@ Most applications use the `vite-hub/presets/*` imports of the `vite-hub` framewo
|
|
|
35
35
|
import { labeller } from "@vite-hub/presets/labeller"
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
See the [Labeller docs](https://vitehub.dev/docs/
|
|
38
|
+
See the [Labeller docs](https://vitehub.dev/docs/presets/labeller).
|
|
39
39
|
|
|
40
40
|
## Workspace preset
|
|
41
41
|
|
|
@@ -43,7 +43,7 @@ See the [Labeller docs](https://vitehub.dev/docs/agents/labeller).
|
|
|
43
43
|
import workspace from "@vite-hub/presets/workspace"
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
See the [workspace preset docs](https://vitehub.dev/docs/
|
|
46
|
+
See the [workspace preset docs](https://vitehub.dev/docs/presets/workspace).
|
|
47
47
|
|
|
48
48
|
## Babysitter
|
|
49
49
|
|
|
@@ -159,7 +159,14 @@ changed its files after its checks ran, gets a branch update instead of a merge
|
|
|
159
159
|
or a model pass. A head that already contains the base tip needs no update. When
|
|
160
160
|
GitHub refuses `update-branch`, as it does for some stacked PRs, the host merges
|
|
161
161
|
the base into a same-repository head branch through `POST /repos/{owner}/{repo}/merges`
|
|
162
|
-
after checking that the head did not move.
|
|
162
|
+
after checking that the head did not move. GitHub refuses App pushes to a fork,
|
|
163
|
+
so a fork PR whose base changed its files, or that needs a retest on the current
|
|
164
|
+
base, is closed and reopened instead, at most hourly. Its `pull_request` workflows
|
|
165
|
+
then run again on the merge with the current base. GitHub lists no pull request on
|
|
166
|
+
a fork's Actions runs, so the host matches the workflow run to the fork branch and
|
|
167
|
+
head, then uses base branch activity before the run was created. Push runs do not
|
|
168
|
+
count. The host records the close first and recovers an interrupted reopen only
|
|
169
|
+
when its own GitHub identity closed the PR.
|
|
163
170
|
|
|
164
171
|
PRs whose head branch starts with `mainRepairBranchPrefix` still get a repair pass when their failure repeats the base.
|
|
165
172
|
|
|
@@ -178,6 +185,17 @@ branch rules. A required check that never reported, 10 minutes after the head's
|
|
|
178
185
|
checks finished, gets a branch update or an Actions rerun once per head every
|
|
179
186
|
six hours.
|
|
180
187
|
|
|
188
|
+
`forkHeadBranches` (off by default), such as
|
|
189
|
+
`{ "acme/app": "preview/pr-{number}" }`, is for required checks that run only on
|
|
190
|
+
pushes to the repository, like pkg.pr.new. Such a check never reports on a fork
|
|
191
|
+
PR's head. When it is missing, the host pushes the head to that branch, once per
|
|
192
|
+
head. A push runs the workflow files of the pushed commit with the repository's
|
|
193
|
+
permissions, so the host first rereads GitHub and pushes only when a reviewer with
|
|
194
|
+
write access approved that exact head, no change request stands, and any local
|
|
195
|
+
action, reusable workflow, or workflow triggered by pushing or creating that
|
|
196
|
+
branch still matches the live base. It moves and deletes only a
|
|
197
|
+
branch it created, and deletes it once the PR closes.
|
|
198
|
+
|
|
181
199
|
`markDraftsReady` lists GitHub logins, such as maintainers and their bots, whose
|
|
182
200
|
drafts should merge. Off by default. When a pass has reviewed a draft's head, no
|
|
183
201
|
required check failed, and the head branch is in the repository itself, the host
|
|
@@ -295,9 +313,9 @@ installations can access, except archived ones and `filter.repository.deny`),
|
|
|
295
313
|
claims, repair passes, and wake handling. Installing the App on a repository
|
|
296
314
|
enrolls it; `installation` and `installation_repositories` webhooks update the
|
|
297
315
|
list at once, and the host lists the installations again every 10 minutes. Signed
|
|
298
|
-
GitHub deliveries to `/
|
|
299
|
-
inbox; they never start the Agent directly. `GET /
|
|
300
|
-
reports drain status, and `GET /
|
|
316
|
+
GitHub deliveries to `/_vitehub/agents/<name>/webhooks/github` feed the
|
|
317
|
+
inbox; they never start the Agent directly. `GET /_vitehub/host/drain`
|
|
318
|
+
reports drain status, and `GET /_vitehub/host/health` reports each host's
|
|
301
319
|
health and queue. SIGUSR2 starts a drain. The build fails with `AGENT_B0022` on
|
|
302
320
|
hosts that cannot keep a process running, and with `AGENT_B0023` without SQL
|
|
303
321
|
Agent State. Hosts start in production builds, or in development only with
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as createGitHubAppCredentials, S as GitHubHostSecret, _ as GitHubHostCredentials, a as BabysitterAdmissionResult, b as GitHubHostPullRequest, c as PullRequestInboxStorage, d as GitHubHost, f as GitHubHostAccess, g as GitHubHostCredentialContext, h as GitHubHostCheckoutOptions, m as GitHubHostCheckout, n as PullRequestWorkspaces, o as PullRequestInbox, p as GitHubHostAccessOptions, u as GitHubAppEnvironment, v as GitHubHostForgeOptions, w as createGitHubHost, x as GitHubHostRateLimit, y as GitHubHostOptions } from "../pr-workspaces-
|
|
1
|
+
import { C as createGitHubAppCredentials, S as GitHubHostSecret, _ as GitHubHostCredentials, a as BabysitterAdmissionResult, b as GitHubHostPullRequest, c as PullRequestInboxStorage, d as GitHubHost, f as GitHubHostAccess, g as GitHubHostCredentialContext, h as GitHubHostCheckoutOptions, m as GitHubHostCheckout, n as PullRequestWorkspaces, o as PullRequestInbox, p as GitHubHostAccessOptions, u as GitHubAppEnvironment, v as GitHubHostForgeOptions, w as createGitHubHost, x as GitHubHostRateLimit, y as GitHubHostOptions } from "../pr-workspaces-CMdQ9U15.js";
|
|
2
2
|
import { AgentInput } from "@vite-hub/agent";
|
|
3
3
|
import { GitHubAppRepository } from "@vite-hub/forge";
|
|
4
4
|
import { ProcessReconcilerRunContext } from "@vite-hub/runtime/internal/node";
|
|
@@ -10,7 +10,7 @@ interface BabysitterRepositories {
|
|
|
10
10
|
/** The list without a GitHub read. */
|
|
11
11
|
known(): readonly string[];
|
|
12
12
|
/** The list, read again from the App installations when it is stale. A failed read keeps the last list and rejects. */
|
|
13
|
-
current(): Promise<readonly string[]>;
|
|
13
|
+
current(signal?: AbortSignal): Promise<readonly string[]>;
|
|
14
14
|
/**
|
|
15
15
|
* Notes a signed delivery. Installation events update the list and make it stale. An event from a
|
|
16
16
|
* repository the list does not have yet adds it, because GitHub sends only events of installed repositories.
|
|
@@ -50,7 +50,7 @@ export interface BabysitterRuntimeOptions {
|
|
|
50
50
|
providerRetryDelayMs?: number;
|
|
51
51
|
/** Delay between live reads while GitHub computes mergeability before a direct merge. Defaults to 3 seconds. */
|
|
52
52
|
mergeabilityRetryDelayMs?: number;
|
|
53
|
-
admission?: () => Promise<Pick<BabysitterAdmissionResult, "accepting" | "hostOnly" | "reason" | "retryAt" | "detail">>;
|
|
53
|
+
admission?: (signal?: AbortSignal) => Promise<Pick<BabysitterAdmissionResult, "accepting" | "hostOnly" | "reason" | "retryAt" | "detail">>;
|
|
54
54
|
/**
|
|
55
55
|
* Samples memory and pressure for work that runs like a worker before the model starts, such as the
|
|
56
56
|
* merge and install of a conflicting PR. `active` counts the worker passes and preparations already
|
|
@@ -65,11 +65,16 @@ export interface BabysitterRuntimeOptions {
|
|
|
65
65
|
}>;
|
|
66
66
|
/** One kept workspace per open PR. Without it, each pass clones and installs into temporary directories. */
|
|
67
67
|
workspaces?: PullRequestWorkspaces;
|
|
68
|
+
/**
|
|
69
|
+
* How long one reconcile may wait before the runtime reports `babysitter.reconcile.stalled` and stops
|
|
70
|
+
* it, so the next reconcile can claim work. Defaults to 15 minutes.
|
|
71
|
+
*/
|
|
72
|
+
stallMs?: number;
|
|
68
73
|
}
|
|
69
74
|
/**
|
|
70
75
|
* GitHub settles most asynchronous merges in seconds, so poll a pending request less often as it ages:
|
|
71
76
|
* after 30 seconds at first, then after as long as it has been pending, at most every five minutes.
|
|
72
|
-
*
|
|
77
|
+
* A fixed 30-second poll can run for hours on a request that GitHub never settles.
|
|
73
78
|
*/
|
|
74
79
|
export declare function pendingMergeRetryAt(startedAt: number, now: number): number;
|
|
75
80
|
/** Provider quota and rate-limit failures. Cancellation is never a rate limit. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as createGitHubHost, n as isProviderRateLimit, r as pendingMergeRetryAt, s as createGitHubAppCredentials, t as createBabysitterRuntime } from "../server-ILDJE5V7.js";
|
|
2
2
|
export { createBabysitterRuntime, createGitHubAppCredentials, createGitHubHost, isProviderRateLimit, pendingMergeRetryAt };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as isRuntimeRecord, n as hasRuntimeType, t as presetsErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { i as isRuntimeRecord, n as hasRuntimeType, t as presetsErrorDiagnostics } from "./error-diagnostics-o3pHscWs.js";
|
|
2
2
|
import { claudeCodeDriver, codexDriver, defineAgent } from "@vite-hub/agent";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import * as v from "valibot";
|
|
@@ -13,7 +13,7 @@ import { Diagnostic, defineDiagnostics } from "nostics";
|
|
|
13
13
|
import { parseMarkdown } from "comark";
|
|
14
14
|
import html from "comark/plugins/html";
|
|
15
15
|
import linkify from "comark/plugins/linkify";
|
|
16
|
-
import { setTimeout } from "node:timers/promises";
|
|
16
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
17
17
|
import { agentProcessHostIntake, withAgentProcessHost } from "@vite-hub/agent/process";
|
|
18
18
|
//#region src/babysitter/result.ts
|
|
19
19
|
const babysitterSha = /^[a-f0-9]{40,64}$/;
|
|
@@ -132,7 +132,9 @@ Never park a PR to ask a maintainer to choose between requirements. Pick the opt
|
|
|
132
132
|
|
|
133
133
|
## Checks and validation
|
|
134
134
|
|
|
135
|
-
Failing required checks come before review findings.
|
|
135
|
+
Failing required checks come before review findings. Repair required setup, install, lint, typecheck, build and test failures unless the host's live-base-attribution block verifies that the job fails the same way in the live base tip's CI, or a runner or network error such as a lost runner or a failed registry, Git or image fetch stopped it. Name inherited and infrastructure failures in the result; do not push for them. Use readBaseCheckEvidence and readBaseCheckLogs for diagnosis and reproduction on the assigned base, not as proof that the live tip still fails. A flaky, timing-dependent or order-dependent failure is this pass's work even if it also reproduces on base code: fix the flake at its root in this PR and never report it as inherited without live CI proof. Do not report reviewedHead while a repairable required failure remains. If the base already contains a fix, copy it (\`git diff HEAD...origin/<base> -- <file>\`). Never ask anyone to rerun a check.
|
|
136
|
+
|
|
137
|
+
A host-supplied verified-main-repair block authorizes repairing inherited default-branch failures, even when the initial PR tree equals the base tree. Reproduce and repair those base failures, and do not report reviewedHead until the branch contains a repair.
|
|
136
138
|
|
|
137
139
|
Make at most one repair commit per pass. Use the focused-test recipe from the repository's AGENTS.md or CONTRIBUTING.md, including prerequisite builds, and run tests from the owning package rather than the repository root. When a focused test or typecheck cannot resolve a workspace export, build its owner with the repository's documented build target and retry the same command. List instruction files with \`git ls-files '*AGENTS.md' '*CONTRIBUTING.md'\`. Never search outside the checkout (\`find ..\`, \`/\`, \`~\`).
|
|
138
140
|
|
|
@@ -413,9 +415,9 @@ const key = (kind, value) => `ci-evidence:v1:${kind}:${createHash("sha256").upda
|
|
|
413
415
|
const failed = (item) => item.status === "completed" && failures.has(item.conclusion ?? "");
|
|
414
416
|
const sourceUrl = (repository, job) => `https://github.com/${repository}/actions/runs/${job.run_id}/job/${job.id}`;
|
|
415
417
|
/**
|
|
416
|
-
* The run of one check that counts: the newer one, unless it was cancelled beside a finished run.
|
|
417
|
-
*
|
|
418
|
-
*
|
|
418
|
+
* The run of one check that counts: the newer one, unless it was cancelled beside a finished run. When
|
|
419
|
+
* the push and pull_request runs of one workflow share a concurrency group, the later one is cancelled,
|
|
420
|
+
* and the PR must not wait on checks that already passed.
|
|
419
421
|
*/
|
|
420
422
|
function newestCheckRun(previous, check) {
|
|
421
423
|
if (!previous) return check;
|
|
@@ -1498,13 +1500,29 @@ function resolveBabysitterMerge(merge) {
|
|
|
1498
1500
|
if (checks.length) bypassInheritedChecks.set(repository.toLowerCase(), new Set(checks.map((check) => check.toLowerCase())));
|
|
1499
1501
|
}
|
|
1500
1502
|
}
|
|
1503
|
+
const forkHeadBranches = /* @__PURE__ */ new Map();
|
|
1504
|
+
if (merge.forkHeadBranches !== void 0) {
|
|
1505
|
+
const expected = "an object of branch names by repository, such as { \"acme/app\": \"preview/pr-{number}\" }";
|
|
1506
|
+
if (!isRuntimeRecord(merge.forkHeadBranches) || Array.isArray(merge.forkHeadBranches)) throw presetsErrorDiagnostics.PRESETS_BABYSITTER_OPTION_INVALID({
|
|
1507
|
+
option: "merge.forkHeadBranches",
|
|
1508
|
+
expected
|
|
1509
|
+
});
|
|
1510
|
+
for (const [repository, branch] of Object.entries(merge.forkHeadBranches)) {
|
|
1511
|
+
if (!hasRuntimeType(branch, "string") || !branch.includes("{number}") || !/^[\w.{}/-]+$/.test(branch)) throw presetsErrorDiagnostics.PRESETS_BABYSITTER_OPTION_INVALID({
|
|
1512
|
+
option: `merge.forkHeadBranches["${repository}"]`,
|
|
1513
|
+
expected: "a branch name with {number}, such as \"preview/pr-{number}\""
|
|
1514
|
+
});
|
|
1515
|
+
forkHeadBranches.set(repository.toLowerCase(), branch);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1501
1518
|
return {
|
|
1502
1519
|
mode: "direct",
|
|
1503
1520
|
method,
|
|
1504
1521
|
foldStacks: merge.foldStacks ?? true,
|
|
1505
1522
|
...ready ? { ready } : {},
|
|
1506
1523
|
...drafts?.length ? { markDraftsReady: new Set(drafts.map((login) => login.trim().toLowerCase())) } : {},
|
|
1507
|
-
...bypassInheritedChecks.size ? { bypassInheritedChecks } : {}
|
|
1524
|
+
...bypassInheritedChecks.size ? { bypassInheritedChecks } : {},
|
|
1525
|
+
...forkHeadBranches.size ? { forkHeadBranches } : {}
|
|
1508
1526
|
};
|
|
1509
1527
|
}
|
|
1510
1528
|
throw presetsErrorDiagnostics.PRESETS_BABYSITTER_OPTION_INVALID({
|
|
@@ -1607,6 +1625,39 @@ function liveMergeReadiness(live, head, reviewPolicy = {}) {
|
|
|
1607
1625
|
};
|
|
1608
1626
|
}
|
|
1609
1627
|
//#endregion
|
|
1628
|
+
//#region src/babysitter/shared-read.ts
|
|
1629
|
+
function sharedBabysitterRead(read) {
|
|
1630
|
+
let pending;
|
|
1631
|
+
return async (caller, ...args) => {
|
|
1632
|
+
caller?.throwIfAborted();
|
|
1633
|
+
if (!pending || pending.controller.signal.aborted) {
|
|
1634
|
+
const controller = new AbortController();
|
|
1635
|
+
const signal = controller.signal;
|
|
1636
|
+
const timer = setTimeout(() => controller.abort(new DOMException("Babysitter read timed out", "TimeoutError")), 9e5);
|
|
1637
|
+
timer.unref?.();
|
|
1638
|
+
const timeout = new Promise((_, reject) => signal.addEventListener("abort", () => reject(signal.reason), { once: true }));
|
|
1639
|
+
pending = {
|
|
1640
|
+
result: Promise.race([Promise.resolve().then(() => {
|
|
1641
|
+
signal.throwIfAborted();
|
|
1642
|
+
return read(signal, ...args);
|
|
1643
|
+
}), timeout]).finally(() => {
|
|
1644
|
+
clearTimeout(timer);
|
|
1645
|
+
if (pending?.controller === controller) pending = void 0;
|
|
1646
|
+
}),
|
|
1647
|
+
controller
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
const { result, controller } = pending;
|
|
1651
|
+
const stop = () => controller.abort(caller?.reason);
|
|
1652
|
+
caller?.addEventListener("abort", stop, { once: true });
|
|
1653
|
+
try {
|
|
1654
|
+
return await result;
|
|
1655
|
+
} finally {
|
|
1656
|
+
caller?.removeEventListener("abort", stop);
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
//#endregion
|
|
1610
1661
|
//#region src/babysitter/admission.ts
|
|
1611
1662
|
const tokenLimit = (value) => value === void 0 || Number.isSafeInteger(value) && Number(value) >= 0;
|
|
1612
1663
|
/** Whether `value` is a valid `admission` option. */
|
|
@@ -1686,12 +1737,13 @@ function babysitterAdmissionDecision(state, limits) {
|
|
|
1686
1737
|
};
|
|
1687
1738
|
return { accepting: true };
|
|
1688
1739
|
}
|
|
1689
|
-
async function readInvocationInputTokens(invocations, since) {
|
|
1740
|
+
async function readInvocationInputTokens(invocations, since, signal) {
|
|
1690
1741
|
invariant(invocations, "the admission controller reads token usage only after the runtime assigns the invocation journal");
|
|
1691
1742
|
const usage = [];
|
|
1692
1743
|
let cursor;
|
|
1693
1744
|
const seenCursors = /* @__PURE__ */ new Set();
|
|
1694
1745
|
do {
|
|
1746
|
+
signal?.throwIfAborted();
|
|
1695
1747
|
const page = await invocations.list({
|
|
1696
1748
|
cursor,
|
|
1697
1749
|
limit: 100,
|
|
@@ -1707,6 +1759,7 @@ async function readInvocationInputTokens(invocations, since) {
|
|
|
1707
1759
|
invariant(!page.cursor || !seenCursors.has(page.cursor), "the Agent Invocation store returns a new pagination cursor for each page");
|
|
1708
1760
|
if (page.cursor) seenCursors.add(page.cursor);
|
|
1709
1761
|
for (const summary of page.invocations) {
|
|
1762
|
+
signal?.throwIfAborted();
|
|
1710
1763
|
if (Date.parse(summary.updatedAt) < since) continue;
|
|
1711
1764
|
const record = await invocations.get(summary.id);
|
|
1712
1765
|
if (!record) continue;
|
|
@@ -1744,20 +1797,17 @@ function normalizeAdmissionPause(value) {
|
|
|
1744
1797
|
return pause;
|
|
1745
1798
|
}
|
|
1746
1799
|
function coalesceBabysitterAdmission(read, clock = Date.now) {
|
|
1747
|
-
let pending;
|
|
1748
1800
|
let latest;
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
return pending;
|
|
1760
|
-
}
|
|
1801
|
+
const sample = sharedBabysitterRead(async (signal, now) => {
|
|
1802
|
+
const result = await read(now, signal);
|
|
1803
|
+
signal.throwIfAborted();
|
|
1804
|
+
latest = {
|
|
1805
|
+
...result,
|
|
1806
|
+
observedAt: clock()
|
|
1807
|
+
};
|
|
1808
|
+
return latest;
|
|
1809
|
+
});
|
|
1810
|
+
const check = (now, signal) => sample(signal, now);
|
|
1761
1811
|
return Object.assign(check, {
|
|
1762
1812
|
health: () => latest && clock() - latest.observedAt <= 12e4 ? Promise.resolve(latest) : check(),
|
|
1763
1813
|
invalidate: () => {
|
|
@@ -1769,7 +1819,7 @@ function createBabysitterAdmission(options) {
|
|
|
1769
1819
|
const usage = /* @__PURE__ */ new Map();
|
|
1770
1820
|
let readAt;
|
|
1771
1821
|
let cursor;
|
|
1772
|
-
return coalesceBabysitterAdmission(async function check(now = Date.now()) {
|
|
1822
|
+
return coalesceBabysitterAdmission(async function check(now = Date.now(), signal) {
|
|
1773
1823
|
const windows = babysitterBudgetWindows(now);
|
|
1774
1824
|
const state = {
|
|
1775
1825
|
windows,
|
|
@@ -1781,9 +1831,12 @@ function createBabysitterAdmission(options) {
|
|
|
1781
1831
|
} catch (error) {
|
|
1782
1832
|
state.errors = [`tmp: ${error instanceof Error ? error.message : String(error)}`];
|
|
1783
1833
|
}
|
|
1834
|
+
signal?.throwIfAborted();
|
|
1784
1835
|
if ((options.limits.hourlyInputTokens !== void 0 || options.limits.dailyInputTokens !== void 0) && (readAt === void 0 || now - readAt >= 6e4)) try {
|
|
1785
1836
|
const since = cursor === void 0 ? windows.dayStart : Math.max(windows.dayStart, cursor - 6e4);
|
|
1786
|
-
|
|
1837
|
+
const entries = await readInvocationInputTokens(options.invocations, since, signal);
|
|
1838
|
+
signal?.throwIfAborted();
|
|
1839
|
+
for (const entry of entries) usage.set(entry.id, {
|
|
1787
1840
|
updatedAt: Date.parse(entry.updatedAt),
|
|
1788
1841
|
tokens: Number(entry.tokens) || 0
|
|
1789
1842
|
});
|
|
@@ -1793,12 +1846,13 @@ function createBabysitterAdmission(options) {
|
|
|
1793
1846
|
} catch (error) {
|
|
1794
1847
|
state.errors = [...state.errors ?? [], `tokens: ${error instanceof Error ? error.message : String(error)}`];
|
|
1795
1848
|
}
|
|
1849
|
+
signal?.throwIfAborted();
|
|
1796
1850
|
if (readAt !== void 0) {
|
|
1797
1851
|
state.hourlyInputTokens = sumInvocationInputTokens(usage, windows.hourStart);
|
|
1798
1852
|
state.dailyInputTokens = sumInvocationInputTokens(usage, windows.dayStart);
|
|
1799
1853
|
}
|
|
1800
1854
|
if (options.check && !options.limits.paused) try {
|
|
1801
|
-
const pause = normalizeAdmissionPause(await options.check());
|
|
1855
|
+
const pause = normalizeAdmissionPause(await options.check(signal));
|
|
1802
1856
|
if (pause) state.pause = pause;
|
|
1803
1857
|
} catch (error) {
|
|
1804
1858
|
state.errors = [...state.errors ?? [], `check: ${error instanceof Error ? error.message : String(error)}`];
|
|
@@ -1981,7 +2035,7 @@ function createPullRequestWorkspaces(options) {
|
|
|
1981
2035
|
try {
|
|
1982
2036
|
while (!await tryLockFile(name)) {
|
|
1983
2037
|
signal?.throwIfAborted();
|
|
1984
|
-
await setTimeout(500, void 0, { signal });
|
|
2038
|
+
await setTimeout$1(500, void 0, { signal });
|
|
1985
2039
|
}
|
|
1986
2040
|
} catch (error) {
|
|
1987
2041
|
unlock();
|
|
@@ -2214,7 +2268,7 @@ function validMainRepair(mainRepair) {
|
|
|
2214
2268
|
return names(workflows, /\S/) && (repositories === void 0 || names(repositories, /^[\w.-]+\/[\w.-]+$/)) && (stuckJobMinutes === void 0 || stuckJobMinutes === false || Number.isSafeInteger(stuckJobMinutes) && Number(stuckJobMinutes) >= 1);
|
|
2215
2269
|
}
|
|
2216
2270
|
const babysitterHost = { async create(context) {
|
|
2217
|
-
const { createBabysitterProcessHost } = await import("./host-
|
|
2271
|
+
const { createBabysitterProcessHost } = await import("./host-DH0o7xSq.js");
|
|
2218
2272
|
return await createBabysitterProcessHost(context);
|
|
2219
2273
|
} };
|
|
2220
2274
|
function plainSecret(value) {
|
|
@@ -2227,9 +2281,9 @@ const babysitterIntake = channelAdapter("babysitter-github", {
|
|
|
2227
2281
|
webhooks: [{
|
|
2228
2282
|
id: "github",
|
|
2229
2283
|
provider: "github",
|
|
2230
|
-
signature: "github
|
|
2284
|
+
signature: "github",
|
|
2231
2285
|
secretHeader: "x-hub-signature-256",
|
|
2232
|
-
|
|
2286
|
+
secret: async (context) => {
|
|
2233
2287
|
const secret = plainSecret(await channelEnvValue("github", "webhookSecret", context));
|
|
2234
2288
|
if (!secret) throw presetsErrorDiagnostics.PRESETS_BABYSITTER_ENV_MISSING({ variables: ["VITEHUB_GITHUB_WEBHOOK_SECRET"] });
|
|
2235
2289
|
return secret;
|
|
@@ -2484,4 +2538,4 @@ const babysitter = defineAgent({
|
|
|
2484
2538
|
}
|
|
2485
2539
|
});
|
|
2486
2540
|
//#endregion
|
|
2487
|
-
export {
|
|
2541
|
+
export { matchesBabysitterPullRequestFilter as A, isReviewThreadOutcome as C, invariant as D, reviewerLabeledSevere as E, createBabysitterCheckRuns as F, isBabysitterCheckRun as I, createBabysitterPassResultSchema as L, failed as M, hydrateFailedCiEvidence as N, invariantError as O, newestCheckRun as P, createGitHubPullRequestOperations as S, reviewThreadOutcomes as T, liveMergeReadiness as _, isBabysitterPlacementCapacityError as a, resolveBabysitterMerge as b, workspaceDecision as c, resolveBabysitterAdmissionLimits as d, sharedBabysitterRead as f, isAutomatedFeedback as g, hasHumanComment as h, BabysitterPlacementCapacityError as i, actionLocation as j, hasGitHubLogin as k, babysitterModelAdmission as l, feedbackFingerprints as m, babysitterPassResultSchema as n, createPullRequestWorkspaces as o, directMergeReadiness as p, resolveBabysitterLifecycleFilter as r, providerSessionDecision as s, babysitter as t, createBabysitterAdmission as u, matchesMergeReviewEvidence as v, normalizeGitHubMentionAllowlist as w, snapshotCheckEvidence as x, mergeReviewEvidenceKey as y };
|
package/dist/babysitter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as AutomatedReviewClass, i as BabysitterAdmissionPause, l as GitHubRequiredCheckState, r as BabysitterAdmissionOptions, s as Snapshot, t as BabysitterWarmWorkspaces } from "./pr-workspaces-
|
|
1
|
+
import { T as AutomatedReviewClass, i as BabysitterAdmissionPause, l as GitHubRequiredCheckState, r as BabysitterAdmissionOptions, s as Snapshot, t as BabysitterWarmWorkspaces } from "./pr-workspaces-CMdQ9U15.js";
|
|
2
2
|
import { AgentDefinition, AgentInvocationContextValues, AgentInvoker, AgentRuntimeConfig, AgentSandboxDefinition, BuiltInAgentDriverName, ConfiguredAgentDefinition } from "@vite-hub/agent";
|
|
3
3
|
import { GitHubPullRequestFilter } from "@vite-hub/agent/channels";
|
|
4
4
|
import { Diagnostic } from "nostics";
|
|
@@ -70,6 +70,14 @@ type BabysitterMerge = false | "auto" | "direct" | {
|
|
|
70
70
|
* branch is in the repository itself qualify, so a fork's draft stays a draft.
|
|
71
71
|
*/
|
|
72
72
|
markDraftsReady?: readonly string[];
|
|
73
|
+
/**
|
|
74
|
+
* A branch, by repository (`owner/name`), that receives a fork PR's head when a required check never
|
|
75
|
+
* reported on it, such as `{ "acme/app": "preview/pr-{number}" }`. Checks that run only on pushes to
|
|
76
|
+
* the repository itself, like pkg.pr.new, then report on the head. `{number}` is the PR number. The
|
|
77
|
+
* host pushes only a head that a reviewer with write access approved and whose `.github` folder is the
|
|
78
|
+
* base branch's, because a push runs the pushed commit's workflows with the repository's permissions.
|
|
79
|
+
*/
|
|
80
|
+
forkHeadBranches?: Record<string, string>;
|
|
73
81
|
/**
|
|
74
82
|
* Merge a ready pull request into its parent's branch when its base is the head branch of another
|
|
75
83
|
* open pull request in the same repository, so the stack lands with the parent. Default `true`.
|
|
@@ -135,8 +143,9 @@ export interface BabysitterPlacement {
|
|
|
135
143
|
/**
|
|
136
144
|
* Slots that hosts admit now, counting passes already running. A reconcile claims at most this
|
|
137
145
|
* many PRs minus the active owners, so it never claims work that `place` must turn away.
|
|
146
|
+
* Stop the capacity check and discard a pending shared probe when the signal aborts.
|
|
138
147
|
*/
|
|
139
|
-
admitted?(): number | Promise<number>;
|
|
148
|
+
admitted?(signal?: AbortSignal): number | Promise<number>;
|
|
140
149
|
}
|
|
141
150
|
/** Where the Babysitter reports its state on each PR. Both need a verified GitHub App identity. */
|
|
142
151
|
export interface BabysitterStatusOptions {
|
package/dist/babysitter.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as BabysitterPlacementCapacityError, n as babysitterPassResultSchema, r as resolveBabysitterLifecycleFilter, t as babysitter } from "./babysitter-
|
|
1
|
+
import { i as BabysitterPlacementCapacityError, n as babysitterPassResultSchema, r as resolveBabysitterLifecycleFilter, t as babysitter } from "./babysitter-DQeA81N0.js";
|
|
2
2
|
export { BabysitterPlacementCapacityError, babysitter, babysitterPassResultSchema, resolveBabysitterLifecycleFilter };
|
|
@@ -13,7 +13,7 @@ function isRuntimeString(value) {
|
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/error-diagnostics.ts
|
|
15
15
|
const presetsErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
16
|
-
docs: "https://vitehub.dev/docs/
|
|
16
|
+
docs: "https://vitehub.dev/docs/presets/diagnostics",
|
|
17
17
|
codes: {
|
|
18
18
|
PRESETS_BABYSITTER_REPOSITORIES_INVALID: {
|
|
19
19
|
why: "Babysitter filter.repository.allow lists no \"owner/name\" repository.",
|
|
@@ -355,6 +355,10 @@ const presetsErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
|
355
355
|
why: "[vitehub] Babysitter noFindingsReviews cannot contain an empty prefix.",
|
|
356
356
|
fix: "Remove the empty string from noFindingsReviews in the Babysitter options, or give each entry the text that starts a no-findings review."
|
|
357
357
|
},
|
|
358
|
+
PRESETS_BABYSITTER_RECONCILE_STALLED: {
|
|
359
|
+
why: ({ step, minutes }) => `The Babysitter reconcile waited ${minutes} minutes in its ${step} step, so the Babysitter stopped it.`,
|
|
360
|
+
fix: "Read the babysitter.reconcile.stalled event: it names the step and the pull request that did not answer. The next reconcile claims work again. If the same step stalls again, find the request or lock in that step that never settles and give it a timeout."
|
|
361
|
+
},
|
|
358
362
|
PRESETS_BABYSITTER_TOOL_FIELD_INVALID: {
|
|
359
363
|
why: ({ key, expected }) => `${key} must be ${expected}.`,
|
|
360
364
|
fix: "Pass the field that the message names as a string in the tool input. Only a body may be empty."
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as isRuntimeRecord, n as hasRuntimeType, t as presetsErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { d as resolveBabysitterAdmissionLimits, o as createPullRequestWorkspaces, r as resolveBabysitterLifecycleFilter, u as createBabysitterAdmission } from "./babysitter-
|
|
3
|
-
import { a as
|
|
1
|
+
import { i as isRuntimeRecord, n as hasRuntimeType, t as presetsErrorDiagnostics } from "./error-diagnostics-o3pHscWs.js";
|
|
2
|
+
import { d as resolveBabysitterAdmissionLimits, f as sharedBabysitterRead, o as createPullRequestWorkspaces, r as resolveBabysitterLifecycleFilter, u as createBabysitterAdmission } from "./babysitter-DQeA81N0.js";
|
|
3
|
+
import { a as budgetParks, c as createGitHubHost, i as babysitterQueueHealth, o as pullRequestThreadId, s as createGitHubAppCredentials, t as createBabysitterRuntime } from "./server-ILDJE5V7.js";
|
|
4
4
|
import { defineAgent } from "@vite-hub/agent";
|
|
5
5
|
import { forgeErrorStatus, githubInstallationRouting } from "@vite-hub/forge";
|
|
6
6
|
import { channelEnv } from "@vite-hub/agent/channels";
|
|
@@ -186,31 +186,6 @@ function createBabysitterPreflight(install, checkCommand = async (program, probe
|
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
//#endregion
|
|
189
|
-
//#region src/babysitter/queue-health.ts
|
|
190
|
-
/** Derive bounded operational counters from the durable queue, including scheduled retries. */
|
|
191
|
-
function babysitterQueueHealth(items, now = Date.now()) {
|
|
192
|
-
const mergedTerminal = (result) => result?.startsWith("Merged ") || result === "Asynchronous merge confirmed by GitHub." || result === "Direct merge outcome reconciled: GitHub reports the pull request merged.";
|
|
193
|
-
const ready = items.filter((item) => item.status === "ready" && item.dirty && !item.stackBlocked && item.nextAt <= now);
|
|
194
|
-
const waiting = items.filter((item) => item.status === "waiting");
|
|
195
|
-
return {
|
|
196
|
-
working: items.filter((item) => item.status === "working").length,
|
|
197
|
-
ready: ready.length,
|
|
198
|
-
scheduled: items.filter((item) => item.status === "ready" && item.dirty && !item.stackBlocked && item.nextAt > now).length,
|
|
199
|
-
stackBlocked: items.filter((item) => item.stackBlocked).length,
|
|
200
|
-
waiting: waiting.length,
|
|
201
|
-
suppressed: items.filter((item) => item.status === "terminal" && item.state === "open" && !mergedTerminal(item.lastResult)).length,
|
|
202
|
-
oldestReadyAgeMs: ready.reduce((age, item) => Math.max(age, item.dirtyAt === void 0 ? 0 : now - item.dirtyAt), 0),
|
|
203
|
-
blockers: {
|
|
204
|
-
checks: waiting.filter((item) => item.wait && item.wait.kind !== "external" && !item.wait.wake).length,
|
|
205
|
-
dependency: waiting.filter((item) => item.wait?.wake).length,
|
|
206
|
-
manual: waiting.filter((item) => item.wait?.kind === "external" && !item.wait.wake && item.wait.retryAt === void 0).length,
|
|
207
|
-
timed: waiting.filter((item) => item.wait?.retryAt !== void 0).length,
|
|
208
|
-
installCapacity: waiting.filter((item) => item.wait?.reasonCode === "install-capacity").length,
|
|
209
|
-
noProgress: waiting.filter((item) => item.progressBudget?.exhausted && item.progressBudget.head === item.head).length
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
//#endregion
|
|
214
189
|
//#region src/babysitter/repositories.ts
|
|
215
190
|
/** How long the installation repository list stays fresh without an installation webhook. */
|
|
216
191
|
const installationRepositoriesTtlMs = 6e5;
|
|
@@ -239,7 +214,6 @@ function babysitterRepositories(filter, read, { ttlMs = installationRepositories
|
|
|
239
214
|
const accepted = (repository) => repositoryName.test(repository) && !deny.has(repository);
|
|
240
215
|
let repositories = [];
|
|
241
216
|
let loadedAt;
|
|
242
|
-
let refreshing;
|
|
243
217
|
let installationEvents = 0;
|
|
244
218
|
const set = (next) => {
|
|
245
219
|
const sorted = [...new Set(next)].sort();
|
|
@@ -247,24 +221,22 @@ function babysitterRepositories(filter, read, { ttlMs = installationRepositories
|
|
|
247
221
|
repositories = sorted;
|
|
248
222
|
return changed;
|
|
249
223
|
};
|
|
250
|
-
const refresh = (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
refreshing = void 0;
|
|
260
|
-
}
|
|
261
|
-
})();
|
|
224
|
+
const refresh = sharedBabysitterRead(async (signal) => {
|
|
225
|
+
const events = installationEvents;
|
|
226
|
+
const installed = await read(signal);
|
|
227
|
+
signal.throwIfAborted();
|
|
228
|
+
if (events !== installationEvents) return repositories;
|
|
229
|
+
set(installed.filter((item) => !item.archived).map((item) => item.repository.toLowerCase()).filter(accepted));
|
|
230
|
+
loadedAt = now();
|
|
231
|
+
return repositories;
|
|
232
|
+
});
|
|
262
233
|
return {
|
|
263
234
|
source: "installations",
|
|
264
235
|
known: () => repositories,
|
|
265
|
-
async current() {
|
|
236
|
+
async current(signal) {
|
|
237
|
+
signal?.throwIfAborted();
|
|
266
238
|
if (loadedAt !== void 0 && now() - loadedAt < ttlMs) return repositories;
|
|
267
|
-
return await refresh();
|
|
239
|
+
return await refresh(signal);
|
|
268
240
|
},
|
|
269
241
|
observe(event, payload) {
|
|
270
242
|
if (!isRuntimeRecord(payload)) return false;
|
|
@@ -288,8 +260,8 @@ function babysitterRepositories(filter, read, { ttlMs = installationRepositories
|
|
|
288
260
|
/**
|
|
289
261
|
* Progress events that a later event of the same run replaces. A lost `check_run.created` or
|
|
290
262
|
* `workflow_run.in_progress` changes nothing once its `completed` event arrives, and change detection
|
|
291
|
-
* reads running checks anyway.
|
|
292
|
-
*
|
|
263
|
+
* reads running checks anyway. They are most of the failed deliveries, and sending them first delays
|
|
264
|
+
* the `completed` events that let a green PR merge.
|
|
293
265
|
*/
|
|
294
266
|
const superseded = /* @__PURE__ */ new Set([
|
|
295
267
|
"check_run.created",
|
|
@@ -310,9 +282,8 @@ function priority(name) {
|
|
|
310
282
|
}
|
|
311
283
|
/**
|
|
312
284
|
* Sends failed GitHub App webhook deliveries again. GitHub does not retry a delivery that timed out
|
|
313
|
-
* after 10 seconds or failed.
|
|
314
|
-
*
|
|
315
|
-
* for the change detection to find them. The inbox deduplicates by delivery ID, so an event that the
|
|
285
|
+
* after 10 seconds or failed. When the receiver is slow, `check_suite.completed` events get lost and
|
|
286
|
+
* green pull requests wait for the change detection to find them. The inbox deduplicates by delivery ID, so an event that the
|
|
316
287
|
* receiver stored after GitHub stopped waiting is not processed twice.
|
|
317
288
|
*/
|
|
318
289
|
function createWebhookRedelivery(options) {
|
|
@@ -512,7 +483,7 @@ async function createBabysitterProcessHost(context) {
|
|
|
512
483
|
await cleanupLegacyBabysitterCheckouts(context.dataDir);
|
|
513
484
|
const app = await readGitHubAppEnvironment({}, { webhookSecret: true });
|
|
514
485
|
const credentials = createGitHubAppCredentials(app);
|
|
515
|
-
const repositories = babysitterRepositories(agent.options.filter, () => credentials.repositories());
|
|
486
|
+
const repositories = babysitterRepositories(agent.options.filter, (signal) => credentials.repositories(signal));
|
|
516
487
|
const identity = await credentials.identity();
|
|
517
488
|
const github = createGitHubHost({
|
|
518
489
|
credentials: credentials.credentials,
|
|
@@ -541,7 +512,7 @@ async function createBabysitterProcessHost(context) {
|
|
|
541
512
|
run: async (reason, run, accepting) => await runtime?.reconcile(reason, run, accepting)
|
|
542
513
|
});
|
|
543
514
|
const preflight = createBabysitterPreflight(agent.options.install ?? true);
|
|
544
|
-
const buildRevision = "
|
|
515
|
+
const buildRevision = "91ca93f60843c0df231a3f438cf1c2ef1587bfc67b8791323ef4f38cc44ca863";
|
|
545
516
|
const admission = createBabysitterAdmission({
|
|
546
517
|
invocations: host.invocations,
|
|
547
518
|
limits: resolveBabysitterAdmissionLimits(agent.options.admission),
|
|
@@ -576,7 +547,7 @@ async function createBabysitterProcessHost(context) {
|
|
|
576
547
|
event: host.event,
|
|
577
548
|
error: host.error,
|
|
578
549
|
wake: () => host.wake(),
|
|
579
|
-
admission,
|
|
550
|
+
admission: (signal) => admission(void 0, signal),
|
|
580
551
|
hostCapacity: async ({ active, signal }) => {
|
|
581
552
|
try {
|
|
582
553
|
return await hostSample.sample({
|
package/dist/labeller.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentDefinition, AgentInvocationContextValues, AgentInvoker, AgentRuntimeConfig, AgentRuntimeContext, ConfiguredAgentDefinition } from "@vite-hub/agent";
|
|
2
|
-
import { GmailClient, GmailLabelSettings } from "@vite-hub/agent/channels";
|
|
2
|
+
import { GmailChannel, GmailClient, GmailLabelSettings } from "@vite-hub/agent/channels";
|
|
3
3
|
//#region src/labeller.d.ts
|
|
4
4
|
export interface LabellerLabel extends GmailLabelSettings {}
|
|
5
5
|
export type LabellerPattern = string | readonly string[];
|
|
@@ -64,7 +64,11 @@ type LabellerResult = {
|
|
|
64
64
|
};
|
|
65
65
|
rule?: string;
|
|
66
66
|
};
|
|
67
|
-
type LabellerDefinition = AgentDefinition<AgentRuntimeConfig, unknown, AgentInvoker, AgentInvocationContextValues, LabellerResult | LabellerDecision
|
|
67
|
+
type LabellerDefinition = AgentDefinition<AgentRuntimeConfig, unknown, AgentInvoker, AgentInvocationContextValues, LabellerResult | LabellerDecision> & {
|
|
68
|
+
readonly channels: {
|
|
69
|
+
readonly gmail: GmailChannel;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
68
72
|
export type LabellerAgent = ConfiguredAgentDefinition<LabellerOptions, LabellerDefinition>;
|
|
69
73
|
/** Gmail labelling preset: ordered rules first, then a constrained Jev choice. */
|
|
70
74
|
export declare const labeller: LabellerAgent;
|
package/dist/labeller.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as isRuntimeRecord, t as presetsErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { i as isRuntimeRecord, t as presetsErrorDiagnostics } from "./error-diagnostics-o3pHscWs.js";
|
|
2
2
|
import { defineAgent } from "@vite-hub/agent";
|
|
3
3
|
import { hasRuntimeType, isRuntimeObject } from "@vite-hub/runtime/internal/runtime-type";
|
|
4
4
|
import * as v from "valibot";
|
|
@@ -178,6 +178,7 @@ const labeller = defineAgent({
|
|
|
178
178
|
if (materializingTemplate) {
|
|
179
179
|
materializingTemplate = false;
|
|
180
180
|
return defineAgent({
|
|
181
|
+
channels: { gmail: gmail({ dryRun: true }) },
|
|
181
182
|
driver: { run: () => {
|
|
182
183
|
throw presetsErrorDiagnostics.PRESETS_LABELLER_LABEL_COUNT_INVALID();
|
|
183
184
|
} },
|