@vite-hub/presets 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +296 -2
- package/dist/admission-DBJdt-CX.d.ts +639 -0
- package/dist/babysitter/server.d.ts +46 -0
- package/dist/babysitter/server.js +2 -0
- package/dist/babysitter-B4D1zeYf.js +715 -0
- package/dist/babysitter.d.ts +246 -0
- package/dist/babysitter.js +2 -0
- package/dist/host-CH0L3VC9.js +438 -0
- package/dist/labeller.d.ts +53 -0
- package/dist/labeller.js +208 -0
- package/dist/server-DDmyZ98B.js +6745 -0
- package/dist/workspace.d.ts +6 -0
- package/dist/workspace.js +16 -0
- package/package.json +94 -3
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
import { AgentRunActivity } from "@vite-hub/agent";
|
|
2
|
+
import { GitHubPullRequestFilter } from "@vite-hub/agent/channels";
|
|
3
|
+
import "valibot";
|
|
4
|
+
import { SqliteAgentStateExtension } from "@vite-hub/agent/state/sqlite";
|
|
5
|
+
//#region src/babysitter/inbox/types.d.ts
|
|
6
|
+
interface GitHubActor {
|
|
7
|
+
login?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
__typename?: string;
|
|
10
|
+
}
|
|
11
|
+
interface GitHubTimestamps {
|
|
12
|
+
updated_at?: string | null;
|
|
13
|
+
updatedAt?: string | null;
|
|
14
|
+
created_at?: string | null;
|
|
15
|
+
createdAt?: string | null;
|
|
16
|
+
submitted_at?: string | null;
|
|
17
|
+
submittedAt?: string | null;
|
|
18
|
+
completed_at?: string | null;
|
|
19
|
+
started_at?: string | null;
|
|
20
|
+
}
|
|
21
|
+
interface GitHubRef {
|
|
22
|
+
sha?: string;
|
|
23
|
+
ref?: string;
|
|
24
|
+
repo?: {
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
full_name: string;
|
|
27
|
+
default_branch?: string;
|
|
28
|
+
owner?: {
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
login?: string;
|
|
31
|
+
} | null;
|
|
32
|
+
} | null;
|
|
33
|
+
}
|
|
34
|
+
interface GitHubPullRequestRecord extends GitHubTimestamps {
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
number: number;
|
|
37
|
+
user?: GitHubActor | null;
|
|
38
|
+
author?: GitHubActor | null;
|
|
39
|
+
state?: string;
|
|
40
|
+
draft?: boolean;
|
|
41
|
+
isDraft?: boolean;
|
|
42
|
+
title?: string;
|
|
43
|
+
body?: string | null;
|
|
44
|
+
html_url?: string;
|
|
45
|
+
url?: string;
|
|
46
|
+
head?: GitHubRef;
|
|
47
|
+
base?: GitHubRef;
|
|
48
|
+
headRefOid?: string;
|
|
49
|
+
headRefName?: string;
|
|
50
|
+
baseRefOid?: string;
|
|
51
|
+
baseRefName?: string;
|
|
52
|
+
headRepository?: {
|
|
53
|
+
nameWithOwner: string;
|
|
54
|
+
} | null;
|
|
55
|
+
author_association?: string;
|
|
56
|
+
authorAssociation?: string;
|
|
57
|
+
labels?: (string | {
|
|
58
|
+
name: string;
|
|
59
|
+
})[];
|
|
60
|
+
mergeable?: boolean | null;
|
|
61
|
+
mergeable_state?: string;
|
|
62
|
+
reviewDecision?: string | null;
|
|
63
|
+
}
|
|
64
|
+
/** Fields consumed from comments, reviews, checks, and statuses. Extra GitHub fields remain stored. */
|
|
65
|
+
interface GitHubEvidence extends GitHubTimestamps {
|
|
66
|
+
[key: string]: unknown;
|
|
67
|
+
id?: string | number;
|
|
68
|
+
node_id?: string;
|
|
69
|
+
databaseId?: number | null;
|
|
70
|
+
user?: GitHubActor | null;
|
|
71
|
+
author?: GitHubActor | null;
|
|
72
|
+
body?: string | null;
|
|
73
|
+
html_url?: string;
|
|
74
|
+
url?: string;
|
|
75
|
+
deleted?: boolean;
|
|
76
|
+
state?: string;
|
|
77
|
+
name?: string;
|
|
78
|
+
status?: string;
|
|
79
|
+
conclusion?: string | null;
|
|
80
|
+
head_sha?: string;
|
|
81
|
+
sha?: string;
|
|
82
|
+
context?: string;
|
|
83
|
+
description?: string | null;
|
|
84
|
+
details_url?: string | null;
|
|
85
|
+
target_url?: string | null;
|
|
86
|
+
performed_via_github_app?: {
|
|
87
|
+
id: number;
|
|
88
|
+
} | null;
|
|
89
|
+
app?: {
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
slug?: string;
|
|
92
|
+
id?: number;
|
|
93
|
+
} | null;
|
|
94
|
+
output?: {
|
|
95
|
+
summary?: string | null;
|
|
96
|
+
text?: string | null;
|
|
97
|
+
};
|
|
98
|
+
pull_requests?: {
|
|
99
|
+
number: number;
|
|
100
|
+
}[];
|
|
101
|
+
commit_id?: string;
|
|
102
|
+
original_commit_id?: string;
|
|
103
|
+
commit?: {
|
|
104
|
+
oid: string;
|
|
105
|
+
} | null;
|
|
106
|
+
pull_request_review_id?: number;
|
|
107
|
+
in_reply_to_id?: number;
|
|
108
|
+
path?: string;
|
|
109
|
+
line?: number | null;
|
|
110
|
+
original_line?: number | null;
|
|
111
|
+
start_line?: number | null;
|
|
112
|
+
original_start_line?: number | null;
|
|
113
|
+
side?: string;
|
|
114
|
+
start_side?: string | null;
|
|
115
|
+
}
|
|
116
|
+
interface GitHubReviewThread {
|
|
117
|
+
[key: string]: unknown;
|
|
118
|
+
id?: string;
|
|
119
|
+
node_id?: string;
|
|
120
|
+
isResolved?: boolean;
|
|
121
|
+
isOutdated?: boolean;
|
|
122
|
+
path?: string;
|
|
123
|
+
line?: number | null;
|
|
124
|
+
originalLine?: number | null;
|
|
125
|
+
startLine?: number | null;
|
|
126
|
+
originalStartLine?: number | null;
|
|
127
|
+
comments?: GitHubEvidence[] | {
|
|
128
|
+
nodes: GitHubEvidence[];
|
|
129
|
+
pageInfo?: {
|
|
130
|
+
hasNextPage: boolean;
|
|
131
|
+
endCursor?: string | null;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
resolutionSource?: string;
|
|
135
|
+
resolutionObservedAt?: string;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/babysitter/inbox/budgets.d.ts
|
|
139
|
+
interface ProviderBudget {
|
|
140
|
+
generation: string;
|
|
141
|
+
maxRetries: number;
|
|
142
|
+
nextAttempt: number;
|
|
143
|
+
succeededThrough: number;
|
|
144
|
+
pending: number[];
|
|
145
|
+
failures: number[];
|
|
146
|
+
resetReason?: string;
|
|
147
|
+
}
|
|
148
|
+
type ProviderAttempt = {
|
|
149
|
+
provider: string;
|
|
150
|
+
generation: string;
|
|
151
|
+
attempt: number;
|
|
152
|
+
};
|
|
153
|
+
type ProviderAttemptOutcome = "success" | "retryable-failure" | "other-failure";
|
|
154
|
+
/** New evidence that gives an exhausted head one more pass, once per head. */
|
|
155
|
+
type ProgressGrant = "conflict" | "bot-feedback";
|
|
156
|
+
interface ProgressBudget {
|
|
157
|
+
head: string;
|
|
158
|
+
limit: number;
|
|
159
|
+
count: number;
|
|
160
|
+
exhausted: boolean;
|
|
161
|
+
evidence?: string;
|
|
162
|
+
creditedEvidence: string[];
|
|
163
|
+
resetReason?: string;
|
|
164
|
+
grants?: ProgressGrant[];
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The host verifies progress from GitHub/provider state, never from Agent prose. `reviewDriven` marks a
|
|
168
|
+
* push whose pass had no merge conflict and no failing check outside the review checks; the host
|
|
169
|
+
* decides it from the claimed snapshot.
|
|
170
|
+
*/
|
|
171
|
+
type ProgressOutcome = {
|
|
172
|
+
kind: "no-progress";
|
|
173
|
+
} | {
|
|
174
|
+
kind: "verified";
|
|
175
|
+
evidence: string;
|
|
176
|
+
reviewDriven?: boolean;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Review-driven pushes on one PR, over its whole life. `heads` lists the heads that this worker pushed
|
|
180
|
+
* and, once the budget is spent, the heads that already got a model pass. A head outside it was moved
|
|
181
|
+
* by someone else.
|
|
182
|
+
*/
|
|
183
|
+
interface ReviewPushBudget {
|
|
184
|
+
count: number;
|
|
185
|
+
heads: string[];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Model passes on one PR in the last 24 hours. `passes` holds the time each pass started the model.
|
|
189
|
+
* `human` is the generation of the last person's feedback that a pass saw. `exemptions` lists the
|
|
190
|
+
* exemptions already used, so each applies once.
|
|
191
|
+
*/
|
|
192
|
+
interface DailyPassBudget {
|
|
193
|
+
passes: number[];
|
|
194
|
+
human?: number;
|
|
195
|
+
exemptions: string[];
|
|
196
|
+
}
|
|
197
|
+
interface InboxBudgets {
|
|
198
|
+
providerRetries?: number;
|
|
199
|
+
noProgress?: number;
|
|
200
|
+
reviewPushes?: number;
|
|
201
|
+
dailyPasses?: number;
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/babysitter/inbox/wait-state.d.ts
|
|
205
|
+
type PullRequestWake = {
|
|
206
|
+
kind: "checks";
|
|
207
|
+
repository: string;
|
|
208
|
+
headSha: string;
|
|
209
|
+
} | {
|
|
210
|
+
kind: "pull-request";
|
|
211
|
+
repository: string;
|
|
212
|
+
number: number;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Caller-selected structured evidence that must change before another Agent pass.
|
|
216
|
+
* `retryAt` schedules host reevaluation after transient gates.
|
|
217
|
+
* `knownFailures` lists failing checks that the parked pass already saw.
|
|
218
|
+
* An external wait without `wake` resumes on feedback, head or base changes after the named manual action.
|
|
219
|
+
* `defer: 'checks'` postpones a pass while gates run; it records no assessment and ends when they stop.
|
|
220
|
+
*/
|
|
221
|
+
type PullRequestWait = {
|
|
222
|
+
headSha: string;
|
|
223
|
+
reason: string;
|
|
224
|
+
reasonCode?: string;
|
|
225
|
+
evidenceKey: string;
|
|
226
|
+
retryAt?: number;
|
|
227
|
+
knownFailures?: string[];
|
|
228
|
+
kind?: "checks" | "external";
|
|
229
|
+
defer?: "checks";
|
|
230
|
+
wake?: PullRequestWake;
|
|
231
|
+
};
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/babysitter/inbox/storage.d.ts
|
|
234
|
+
/**
|
|
235
|
+
* SQL access for the PR inbox. `agentState.extension("babysitter")` from
|
|
236
|
+
* `@vite-hub/agent/state/sqlite` satisfies it and keeps the inbox in the Agent State database.
|
|
237
|
+
*/
|
|
238
|
+
interface PullRequestInboxStorage extends Pick<SqliteAgentStateExtension, "execute" | "tablePrefix" | "transaction"> {
|
|
239
|
+
close?: () => Promise<void>;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/babysitter/inbox/status-delivery.d.ts
|
|
243
|
+
interface StatusDelivery {
|
|
244
|
+
version: string;
|
|
245
|
+
contentKey: string;
|
|
246
|
+
repository: string;
|
|
247
|
+
number: number;
|
|
248
|
+
head: string;
|
|
249
|
+
precedingHead?: string;
|
|
250
|
+
projection?: true;
|
|
251
|
+
workerLease?: string;
|
|
252
|
+
generation: number;
|
|
253
|
+
text: string;
|
|
254
|
+
attempts: number;
|
|
255
|
+
nextAt: number;
|
|
256
|
+
lease?: string;
|
|
257
|
+
leaseUntil?: number;
|
|
258
|
+
lastError?: string;
|
|
259
|
+
activity: {
|
|
260
|
+
runId: string;
|
|
261
|
+
status: "queued" | "running" | "failed" | "completed" | "waiting";
|
|
262
|
+
startedAt?: string;
|
|
263
|
+
updatedAt: string;
|
|
264
|
+
links: Array<{
|
|
265
|
+
label: string;
|
|
266
|
+
url: string;
|
|
267
|
+
}>;
|
|
268
|
+
tasks: never[];
|
|
269
|
+
summary: string;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/babysitter/inbox/store.d.ts
|
|
274
|
+
type Snapshot = {
|
|
275
|
+
repository: string;
|
|
276
|
+
number: number;
|
|
277
|
+
pr: GitHubPullRequestRecord | null;
|
|
278
|
+
generation: number;
|
|
279
|
+
handled: number;
|
|
280
|
+
dirtyAt: number;
|
|
281
|
+
nextAt: number;
|
|
282
|
+
revision?: number;
|
|
283
|
+
status: "ready" | "working" | "waiting" | "terminal";
|
|
284
|
+
wait?: PullRequestWait;
|
|
285
|
+
lease: string | null;
|
|
286
|
+
leaseUntil: number;
|
|
287
|
+
attempts: number;
|
|
288
|
+
progressBudget?: ProgressBudget;
|
|
289
|
+
/** Review-driven pushes on this PR. Set when `budgets.reviewPushes` is configured. */
|
|
290
|
+
reviewPushBudget?: ReviewPushBudget;
|
|
291
|
+
/** Model passes in the last 24 hours. Set when `budgets.dailyPasses` is configured. */
|
|
292
|
+
dailyPassBudget?: DailyPassBudget;
|
|
293
|
+
/** Generation of the last human comment or review. A wait rejected before it stays free. */
|
|
294
|
+
humanFeedbackGeneration?: number;
|
|
295
|
+
recoveryHead?: string;
|
|
296
|
+
sourcePushHead?: string;
|
|
297
|
+
sourcePushHeads?: string[];
|
|
298
|
+
sourcePushOverflow?: boolean;
|
|
299
|
+
prospectivePush?: {
|
|
300
|
+
token: string;
|
|
301
|
+
heads: string[];
|
|
302
|
+
};
|
|
303
|
+
threadReopens?: Record<string, number>;
|
|
304
|
+
hydrated: boolean;
|
|
305
|
+
refresh: boolean;
|
|
306
|
+
feedbackRefresh: boolean;
|
|
307
|
+
comments: Record<string, GitHubEvidence>;
|
|
308
|
+
reviews: Record<string, GitHubEvidence>;
|
|
309
|
+
reviewComments: Record<string, GitHubEvidence>;
|
|
310
|
+
checks: Record<string, GitHubEvidence>;
|
|
311
|
+
statuses: Record<string, GitHubEvidence>;
|
|
312
|
+
ciEvidence?: Record<string, unknown>[];
|
|
313
|
+
threads: GitHubReviewThread[];
|
|
314
|
+
threadsHydrated?: boolean;
|
|
315
|
+
reasons: string[];
|
|
316
|
+
lastResult?: string;
|
|
317
|
+
};
|
|
318
|
+
type SnapshotPatch = Partial<Pick<Snapshot, "pr" | "comments" | "reviews" | "reviewComments" | "checks" | "statuses" | "threads" | "hydrated" | "refresh" | "feedbackRefresh" | "threadsHydrated" | "ciEvidence">>;
|
|
319
|
+
interface GitHubInboxDeliveryResult {
|
|
320
|
+
accepted: true;
|
|
321
|
+
duplicate?: boolean;
|
|
322
|
+
queued: number[];
|
|
323
|
+
updated: number[];
|
|
324
|
+
ignored?: boolean;
|
|
325
|
+
reason?: string;
|
|
326
|
+
}
|
|
327
|
+
interface GitHubInboxSummary {
|
|
328
|
+
repository: string;
|
|
329
|
+
number: number;
|
|
330
|
+
head?: string;
|
|
331
|
+
generation: number;
|
|
332
|
+
handled: number;
|
|
333
|
+
status: Snapshot["status"];
|
|
334
|
+
reasons: string[];
|
|
335
|
+
/** Every current-head check finished without failing and nothing conflicts. Such PRs are claimed early. */
|
|
336
|
+
mergeReady?: boolean;
|
|
337
|
+
wait?: PullRequestWait;
|
|
338
|
+
dirty: boolean;
|
|
339
|
+
attempts: number;
|
|
340
|
+
nextAt: number;
|
|
341
|
+
lastResult?: string;
|
|
342
|
+
progressBudget?: ProgressBudget;
|
|
343
|
+
state?: string;
|
|
344
|
+
dirtyAt?: number;
|
|
345
|
+
reviewPushBudget?: ReviewPushBudget;
|
|
346
|
+
dailyPassBudget?: DailyPassBudget;
|
|
347
|
+
stackBlocked?: boolean;
|
|
348
|
+
stackParent?: {
|
|
349
|
+
number: number;
|
|
350
|
+
state: string;
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
type Claim = {
|
|
354
|
+
token: string;
|
|
355
|
+
generation: number;
|
|
356
|
+
snapshot: Snapshot;
|
|
357
|
+
runId?: string;
|
|
358
|
+
startedAt?: number;
|
|
359
|
+
activity?: AgentRunActivity;
|
|
360
|
+
};
|
|
361
|
+
type DirectMergeAttempt = {
|
|
362
|
+
token: string;
|
|
363
|
+
generation: number;
|
|
364
|
+
revision: number;
|
|
365
|
+
head: string;
|
|
366
|
+
startedAt: number;
|
|
367
|
+
asynchronous?: boolean;
|
|
368
|
+
enqueued?: boolean;
|
|
369
|
+
};
|
|
370
|
+
interface PullRequestInboxOptions {
|
|
371
|
+
/** A private `node:sqlite` file. Use `storage` instead to keep the inbox in the Agent State database. */
|
|
372
|
+
path?: string;
|
|
373
|
+
/** SQL storage, for example `agentState.extension("babysitter")`. */
|
|
374
|
+
storage?: PullRequestInboxStorage;
|
|
375
|
+
/** Separates inboxes that share one storage, for example one per Agent. */
|
|
376
|
+
scope?: string;
|
|
377
|
+
repositories: readonly string[];
|
|
378
|
+
filter?: GitHubPullRequestFilter;
|
|
379
|
+
clock?: () => number;
|
|
380
|
+
activityAuthors?: readonly string[];
|
|
381
|
+
activityAppId?: number;
|
|
382
|
+
budgets?: InboxBudgets;
|
|
383
|
+
/**
|
|
384
|
+
* Called once per process for each stored PR row that fails validation. The inbox skips such a row
|
|
385
|
+
* in claims, summaries and wait evaluation, so one bad row cannot stop the queue or its health.
|
|
386
|
+
*/
|
|
387
|
+
invalidRow?: (row: InvalidInboxRow) => void;
|
|
388
|
+
}
|
|
389
|
+
interface InvalidInboxRow {
|
|
390
|
+
repository: string;
|
|
391
|
+
number: number;
|
|
392
|
+
error: unknown;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Durable PR inbox. Every method reads and writes storage, so all of them are asynchronous.
|
|
396
|
+
* Snapshot JSON stays the source of truth. Claim, recovery, head matching, and summaries use
|
|
397
|
+
* indexed columns derived from it on every write, so they do not parse every snapshot.
|
|
398
|
+
*/
|
|
399
|
+
declare class PullRequestInbox {
|
|
400
|
+
private storage;
|
|
401
|
+
private ownsStorage;
|
|
402
|
+
private scope;
|
|
403
|
+
private ready?;
|
|
404
|
+
private tables;
|
|
405
|
+
private repositories;
|
|
406
|
+
private clock;
|
|
407
|
+
private filter?;
|
|
408
|
+
private activityAuthors;
|
|
409
|
+
private activityAppId?;
|
|
410
|
+
private budgets;
|
|
411
|
+
private invalidRow?;
|
|
412
|
+
private reportedRows;
|
|
413
|
+
constructor({ path, storage, scope, repositories, filter, clock, budgets, activityAuthors, activityAppId, invalidRow }: PullRequestInboxOptions);
|
|
414
|
+
close(): Promise<void>;
|
|
415
|
+
private init;
|
|
416
|
+
private transaction;
|
|
417
|
+
private read;
|
|
418
|
+
/** Parses one stored row. An invalid row is reported once and skipped by queue-wide reads. */
|
|
419
|
+
private parseRow;
|
|
420
|
+
private reportInvalidRow;
|
|
421
|
+
private repositoryFilter;
|
|
422
|
+
private ownsComment;
|
|
423
|
+
private isActivityComment;
|
|
424
|
+
private cleanSnapshot;
|
|
425
|
+
private getIn;
|
|
426
|
+
/** A snapshot for a queue-wide scan. An invalid row is reported and skipped. */
|
|
427
|
+
private getRowIn;
|
|
428
|
+
get(repository: string, number: number): Promise<Snapshot | undefined>;
|
|
429
|
+
all(): Promise<Snapshot[]>;
|
|
430
|
+
private compactTerminal;
|
|
431
|
+
private put;
|
|
432
|
+
private empty;
|
|
433
|
+
private metaIn;
|
|
434
|
+
private setMetaIn;
|
|
435
|
+
meta(key: string): Promise<unknown>;
|
|
436
|
+
/** A numeric metadata value, such as a timestamp; anything else reads as undefined. */
|
|
437
|
+
metaNumber(key: string): Promise<number | undefined>;
|
|
438
|
+
/** Metadata entries whose keys start with `prefix`. */
|
|
439
|
+
metaEntries(prefix: string): Promise<Array<[string, unknown]>>;
|
|
440
|
+
deleteMeta(key: string): Promise<void>;
|
|
441
|
+
setMeta(key: string, value: unknown): Promise<void>;
|
|
442
|
+
private enqueueStatusResult;
|
|
443
|
+
private statusWritersIn;
|
|
444
|
+
private settleStatusWriterIn;
|
|
445
|
+
private enqueueStatusProjectionIn;
|
|
446
|
+
/** A bounded batch of due deliveries. Invalid metadata never reaches the publisher. */
|
|
447
|
+
pendingStatusDeliveries(limit?: number): Promise<StatusDelivery[]>;
|
|
448
|
+
/** Claim due, eligible deliveries atomically across hosts. Deferred heads yield the batch. */
|
|
449
|
+
claimStatusDeliveries(limit?: number, leaseMs?: number): Promise<StatusDelivery[]>;
|
|
450
|
+
/** Keep the external writer's lease, including when its saved result is superseded. */
|
|
451
|
+
renewStatusDelivery(observed: StatusDelivery, leaseMs?: number): Promise<boolean>;
|
|
452
|
+
/** Version and lease comparisons preserve newer results and fence replaced consumers. */
|
|
453
|
+
finishStatusDelivery(observed: StatusDelivery, outcome: "delivered" | "discarded"): Promise<boolean>;
|
|
454
|
+
retryStatusDelivery(observed: StatusDelivery, failure: unknown): Promise<boolean>;
|
|
455
|
+
/** Repair the external projection after a replaced writer finally settles. */
|
|
456
|
+
reconcileSettledStatusWriter(observed: StatusDelivery): Promise<boolean>;
|
|
457
|
+
private reconcileStatusWriterIn;
|
|
458
|
+
/** Upgrade historical waiting results without synthetic webhooks or model passes. */
|
|
459
|
+
backfillStatusDeliveries(): Promise<void>;
|
|
460
|
+
recordWorkerBlocker(observed: Snapshot, revision: string): Promise<void>;
|
|
461
|
+
/** Wake and persist its release marker atomically, so restart cannot repeat the wake. */
|
|
462
|
+
wakeForWorkerRelease(observed: Snapshot, revision: string, evidenceKey: string): Promise<boolean>;
|
|
463
|
+
private directMergeKey;
|
|
464
|
+
/** Atomically records that a claim has started an irreversible merge request. */
|
|
465
|
+
beginDirectMerge(claim: Claim, head: string, asynchronous?: boolean): Promise<boolean>;
|
|
466
|
+
directMergeAttempt(repository: string, number: number): Promise<DirectMergeAttempt | undefined>;
|
|
467
|
+
/** Preserve a final enqueued result. */
|
|
468
|
+
recordDirectMergeEnqueued(repository: string, number: number, token: string): Promise<boolean>;
|
|
469
|
+
clearDirectMerge(repository: string, number: number, token: string): Promise<boolean>;
|
|
470
|
+
/** Shared provider scope should identify the credential/account, without including its secret. */
|
|
471
|
+
providerBudget(provider: string): Promise<ProviderBudget | undefined>;
|
|
472
|
+
private providerBudgetIn;
|
|
473
|
+
reserveProviderAttempt(provider: string): Promise<ProviderAttempt | undefined>;
|
|
474
|
+
finishProviderAttempt(token: ProviderAttempt, outcome: ProviderAttemptOutcome): Promise<boolean>;
|
|
475
|
+
resetProviderBudget(provider: string, reason: string): Promise<void>;
|
|
476
|
+
resetProgressBudget(repository: string, number: number, head: string, reason: string): Promise<boolean>;
|
|
477
|
+
private dirty;
|
|
478
|
+
private updatePr;
|
|
479
|
+
eligible(repository: string, pr: GitHubPullRequestRecord | null): boolean;
|
|
480
|
+
seed(repository: string, value: unknown): Promise<Snapshot>;
|
|
481
|
+
ingest(id: string, event: string, value: unknown): Promise<GitHubInboxDeliveryResult>;
|
|
482
|
+
/** Leases up to `limit` eligible PRs. `skip` leaves a candidate unclaimed for this call. */
|
|
483
|
+
claim(limit: number, options?: {
|
|
484
|
+
only?: (snapshot: Snapshot) => boolean;
|
|
485
|
+
skip?: (snapshot: Snapshot) => boolean;
|
|
486
|
+
includeBlocked?: boolean;
|
|
487
|
+
}): Promise<Claim[]>;
|
|
488
|
+
hydrate(claim: Claim, patch: SnapshotPatch): Promise<boolean>;
|
|
489
|
+
refreshThreads(observed: Snapshot, threads: GitHubReviewThread[]): Promise<boolean>;
|
|
490
|
+
/** Retain a worker's verified thread resolution even when its webhook is missing. */
|
|
491
|
+
recordThreadResolution(claim: Claim, id: string, observed: Snapshot): Promise<boolean>;
|
|
492
|
+
/** Retain CI for an exact candidate before its source-push webhook arrives. This is not a publication receipt. */
|
|
493
|
+
registerProspectivePush(claim: Claim, head: string): Promise<boolean>;
|
|
494
|
+
release(claim: Claim): Promise<boolean>;
|
|
495
|
+
renew(claim: Claim, leaseUntil: number): Promise<boolean>;
|
|
496
|
+
/**
|
|
497
|
+
* Records that a claimed pass started the model, with the exemption that let it run past
|
|
498
|
+
* `budgets.dailyPasses`. It changes no evidence, so the claim stays current.
|
|
499
|
+
*/
|
|
500
|
+
recordModelPass(claim: Claim, exemption?: string): Promise<boolean>;
|
|
501
|
+
/** Checks the durable claim fence immediately before an irreversible provider action. */
|
|
502
|
+
isClaimCurrent(claim: Claim): Promise<boolean>;
|
|
503
|
+
/**
|
|
504
|
+
* Whether this claim still holds the lease on its claimed head, with no source push since the claim.
|
|
505
|
+
* Unrelated events can move the generation or revision; a pinned wait from `finish()` still accepts them.
|
|
506
|
+
*/
|
|
507
|
+
holdsClaimedHead(claim: Claim): Promise<boolean>;
|
|
508
|
+
/**
|
|
509
|
+
* Finishes a claimed pass. A `wait` without `headSha` binds to the claimed head and requires
|
|
510
|
+
* unchanged evidence. A wait with `headSha`, such as the head of a repair push, keeps later events
|
|
511
|
+
* unhandled, so `waitsToEvaluate()` returns the PR and the host decides whether they need work.
|
|
512
|
+
*/
|
|
513
|
+
finish(claim: Claim, result: {
|
|
514
|
+
text: string;
|
|
515
|
+
retry?: boolean;
|
|
516
|
+
terminal?: boolean;
|
|
517
|
+
progress?: ProgressOutcome;
|
|
518
|
+
verifiedPushHeads?: readonly string[];
|
|
519
|
+
wait?: Omit<PullRequestWait, "headSha"> & {
|
|
520
|
+
headSha?: string;
|
|
521
|
+
};
|
|
522
|
+
}): Promise<boolean>;
|
|
523
|
+
/**
|
|
524
|
+
* A wait rejected by new evidence still used its pass. Checks and bot reviews arrive during most
|
|
525
|
+
* passes, so the pass counts unless a person commented after the claim: the next pass answers them.
|
|
526
|
+
*/
|
|
527
|
+
private recordRejectedProgress;
|
|
528
|
+
/**
|
|
529
|
+
* An exhausted head gets one more pass for new evidence that a pass can act on: a new merge
|
|
530
|
+
* conflict, or new bot feedback. Each kind is granted once per head. A person's feedback resets the budget instead.
|
|
531
|
+
*/
|
|
532
|
+
private grantProgress;
|
|
533
|
+
private recordReviewPush;
|
|
534
|
+
private recordProgress;
|
|
535
|
+
/** Waiting PRs that received events since the host last evaluated their wait. */
|
|
536
|
+
waitsToEvaluate(includeExternal?: boolean, includeIdle?: boolean): Promise<Snapshot[]>;
|
|
537
|
+
/** Records that the host evaluated a wait's new events and the wait still holds. */
|
|
538
|
+
acknowledgeWait(observed: Snapshot): Promise<boolean>;
|
|
539
|
+
/** Re-evaluate structured evidence outside an Agent invocation before calling this method. */
|
|
540
|
+
wake(observed: Snapshot, evidenceKey: string, options?: {
|
|
541
|
+
recovery?: boolean;
|
|
542
|
+
}): Promise<boolean>;
|
|
543
|
+
/**
|
|
544
|
+
* Frees every lease in this scope at startup and returns how many were held. Call it only when one
|
|
545
|
+
* process owns the scope: a pass cannot survive a restart, so its lease only delays the PR.
|
|
546
|
+
*/
|
|
547
|
+
releaseLeases(): Promise<number>;
|
|
548
|
+
recoverLeases(): Promise<void>;
|
|
549
|
+
summary(): Promise<GitHubInboxSummary[]>;
|
|
550
|
+
/** The open, unleased PR that a reconciliation probe checked longest ago, with that probe time. */
|
|
551
|
+
nextProbe(): Promise<{
|
|
552
|
+
repository: string;
|
|
553
|
+
number: number;
|
|
554
|
+
probedAt: number;
|
|
555
|
+
} | undefined>;
|
|
556
|
+
/**
|
|
557
|
+
* Copies a pre-Agent-State inbox file once: snapshots, metadata except probe schedules, and
|
|
558
|
+
* delivery IDs from the last 30 days. Leases are cleared, so stop the old process first.
|
|
559
|
+
* The source file is opened read-only and left unchanged.
|
|
560
|
+
*/
|
|
561
|
+
importLegacyFile(path: string): Promise<{
|
|
562
|
+
imported: boolean;
|
|
563
|
+
snapshots: number;
|
|
564
|
+
skipped: number;
|
|
565
|
+
deliveries: number;
|
|
566
|
+
}>;
|
|
567
|
+
/** Drops delivery payloads after `payloadMs` and delivery IDs after `idMs`. Recent IDs still deduplicate redeliveries. */
|
|
568
|
+
pruneDeliveries({ payloadMs, idMs }?: {
|
|
569
|
+
payloadMs?: number;
|
|
570
|
+
idMs?: number;
|
|
571
|
+
}): Promise<void>;
|
|
572
|
+
}
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region src/babysitter/admission.d.ts
|
|
575
|
+
/** A reason to stop model passes, returned by `admission.check`. */
|
|
576
|
+
interface BabysitterAdmissionPause {
|
|
577
|
+
/** Short machine-readable reason, such as `"provider-quota"`. */
|
|
578
|
+
reason: string;
|
|
579
|
+
detail?: string;
|
|
580
|
+
/** Epoch milliseconds when the pause ends, if it ends at a known time. */
|
|
581
|
+
retryAt?: number;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Shared-resource limits that the host checks before it claims a PR. A spent limit stops model
|
|
585
|
+
* passes. Direct merges and recorded waits continue.
|
|
586
|
+
*/
|
|
587
|
+
interface BabysitterAdmissionOptions {
|
|
588
|
+
/**
|
|
589
|
+
* Input tokens that this Agent's passes may use per local clock hour and per local day. Leave a
|
|
590
|
+
* window out for no limit. Defaults to no limit.
|
|
591
|
+
*/
|
|
592
|
+
inputTokens?: {
|
|
593
|
+
hourly?: number;
|
|
594
|
+
daily?: number;
|
|
595
|
+
};
|
|
596
|
+
/** Free space, in MiB, that the temporary directory needs before a pass. `false` disables the check. Defaults to 4096. */
|
|
597
|
+
minFreeTmpMb?: number | false;
|
|
598
|
+
/** Stop every claim, including direct merges, for example during a smoke boot. Defaults to `false`. */
|
|
599
|
+
paused?: boolean;
|
|
600
|
+
/**
|
|
601
|
+
* Extra check before each claim, for example a provider quota. Return a pause to stop model
|
|
602
|
+
* passes, or `undefined` to continue. An error is reported in health and does not pause.
|
|
603
|
+
*/
|
|
604
|
+
check?: () => BabysitterAdmissionPause | undefined | Promise<BabysitterAdmissionPause | undefined>;
|
|
605
|
+
}
|
|
606
|
+
/** Token limits are best-effort retained-journal thresholds, not billing caps. */
|
|
607
|
+
interface BabysitterAdmissionLimits {
|
|
608
|
+
minFreeTmpBytes?: number;
|
|
609
|
+
hourlyInputTokens?: number;
|
|
610
|
+
dailyInputTokens?: number;
|
|
611
|
+
paused: boolean;
|
|
612
|
+
}
|
|
613
|
+
interface BabysitterBudgetWindows {
|
|
614
|
+
hourStart: number;
|
|
615
|
+
hourEnd: number;
|
|
616
|
+
dayStart: number;
|
|
617
|
+
dayEnd: number;
|
|
618
|
+
}
|
|
619
|
+
interface BabysitterAdmissionState {
|
|
620
|
+
windows: BabysitterBudgetWindows;
|
|
621
|
+
tmpDir: string;
|
|
622
|
+
freeTmpBytes?: number;
|
|
623
|
+
hourlyInputTokens?: number;
|
|
624
|
+
dailyInputTokens?: number;
|
|
625
|
+
pause?: BabysitterAdmissionPause;
|
|
626
|
+
errors?: string[];
|
|
627
|
+
}
|
|
628
|
+
interface BabysitterAdmissionResult {
|
|
629
|
+
accepting: boolean;
|
|
630
|
+
hostOnly?: boolean;
|
|
631
|
+
reason?: string;
|
|
632
|
+
detail?: string;
|
|
633
|
+
retryAt?: number;
|
|
634
|
+
accounting: "best-effort-retained-journal";
|
|
635
|
+
state: BabysitterAdmissionState;
|
|
636
|
+
limits: BabysitterAdmissionLimits;
|
|
637
|
+
}
|
|
638
|
+
//#endregion
|
|
639
|
+
export { Snapshot as a, PullRequestInbox as i, BabysitterAdmissionPause as n, PullRequestInboxStorage as o, BabysitterAdmissionResult as r, BabysitterAdmissionOptions as t };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { i as PullRequestInbox, o as PullRequestInboxStorage, r as BabysitterAdmissionResult } from "../admission-DBJdt-CX.js";
|
|
2
|
+
import { AgentInput } from "@vite-hub/agent";
|
|
3
|
+
import { GitHubHost } from "@vite-hub/agent/server/github";
|
|
4
|
+
import { ProcessReconcilerRunContext } from "@vite-hub/runtime/node";
|
|
5
|
+
//#region src/babysitter/server.d.ts
|
|
6
|
+
export interface BabysitterRuntimeOptions {
|
|
7
|
+
agent: AgentInput;
|
|
8
|
+
/** Discovered Agent name for per-Agent public URLs. Defaults to the definition name. */
|
|
9
|
+
agentName?: string;
|
|
10
|
+
github: GitHubHost;
|
|
11
|
+
/** Private `node:sqlite` inbox file. Set this or `inboxStorage`. */
|
|
12
|
+
inboxPath?: string;
|
|
13
|
+
/** Inbox tables in shared SQL storage, for example `agentState.extension("babysitter")`. */
|
|
14
|
+
inboxStorage?: PullRequestInboxStorage;
|
|
15
|
+
/** Separates this Agent's inbox in shared storage. Defaults to the Agent name. */
|
|
16
|
+
inboxScope?: string;
|
|
17
|
+
repositories: string[];
|
|
18
|
+
concurrency: number;
|
|
19
|
+
/** Public Console origin. Defaults to `vitehub({ publicUrl })`. */
|
|
20
|
+
publicUrl?: string;
|
|
21
|
+
event?: (name: string, properties: Record<string, unknown>) => void;
|
|
22
|
+
error?: (name: string, error: unknown, properties: Record<string, unknown>) => void;
|
|
23
|
+
wake?: () => void;
|
|
24
|
+
/** GitHub logins whose marked comments are emitted by this host. */
|
|
25
|
+
activityAuthors: readonly string[];
|
|
26
|
+
/** How long a pass may continue after a repair push. Defaults to 3 minutes. */
|
|
27
|
+
postPushGraceMs?: number;
|
|
28
|
+
/** Delay between provider rate-limit retries. Defaults to 10 seconds. */
|
|
29
|
+
providerRetryDelayMs?: number;
|
|
30
|
+
/** Delay between live reads while GitHub computes mergeability before a direct merge. Defaults to 3 seconds. */
|
|
31
|
+
mergeabilityRetryDelayMs?: number;
|
|
32
|
+
admission?: () => Promise<Pick<BabysitterAdmissionResult, "accepting" | "hostOnly" | "reason" | "retryAt" | "detail">>;
|
|
33
|
+
}
|
|
34
|
+
/** Provider quota and rate-limit failures. Cancellation is never a rate limit. */
|
|
35
|
+
export declare function isProviderRateLimit(error: unknown): boolean;
|
|
36
|
+
/** Own one durable PR inbox and its repair passes inside a process host. */
|
|
37
|
+
export interface BabysitterRuntime {
|
|
38
|
+
inbox: PullRequestInbox;
|
|
39
|
+
reconcile(reason: string, context: ProcessReconcilerRunContext, accepting?: () => boolean): Promise<void>;
|
|
40
|
+
workload(): {
|
|
41
|
+
running: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export declare function createBabysitterRuntime(options: BabysitterRuntimeOptions): BabysitterRuntime;
|
|
45
|
+
//#endregion
|
|
46
|
+
export type { PullRequestInboxStorage };
|