@vite-hub/presets 0.0.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,923 @@
1
+ import { AgentChannelDefinition, AgentRunActivity } from "@vite-hub/agent";
2
+ import "valibot";
3
+ import { GitHubAppDelivery, GitHubAppRepository, GitHubProvider } from "@vite-hub/forge";
4
+ import { GitHubChannelOptions, GitHubPullRequestFilter } from "@vite-hub/agent/channels";
5
+ import { SqliteAgentStateExtension } from "@vite-hub/agent/state";
6
+ //#region src/babysitter/inbox/budgets.d.ts
7
+ interface ProviderBudget {
8
+ generation: string;
9
+ maxRetries: number;
10
+ nextAttempt: number;
11
+ succeededThrough: number;
12
+ pending: number[];
13
+ failures: number[];
14
+ resetReason?: string;
15
+ }
16
+ type ProviderAttempt = {
17
+ provider: string;
18
+ generation: string;
19
+ attempt: number;
20
+ };
21
+ type ProviderAttemptOutcome = "success" | "retryable-failure" | "other-failure";
22
+ /** New evidence that gives an exhausted head one more pass, once per head. */
23
+ type ProgressGrant = "conflict" | "bot-feedback";
24
+ /** `exhaustedAt` is when the head spent its budget. After `progressCooldownMs` it gets one more pass. */
25
+ interface ProgressBudget {
26
+ head: string;
27
+ limit: number;
28
+ count: number;
29
+ exhausted: boolean;
30
+ evidence?: string;
31
+ creditedEvidence: string[];
32
+ resetReason?: string;
33
+ grants?: ProgressGrant[];
34
+ exhaustedAt?: number;
35
+ }
36
+ /**
37
+ * The host verifies progress from GitHub/provider state, never from Agent prose. `reviewDriven` marks a
38
+ * push whose pass had no merge conflict and no failing check outside the review checks; the host
39
+ * decides it from the claimed snapshot.
40
+ */
41
+ type ProgressOutcome = {
42
+ kind: "no-progress";
43
+ } | {
44
+ kind: "verified";
45
+ evidence: string;
46
+ reviewDriven?: boolean;
47
+ };
48
+ /**
49
+ * Review-driven pushes on one PR, over its whole life. `heads` lists the heads that this worker pushed
50
+ * and, once the budget is spent, the heads that already got a model pass. A head outside it was moved
51
+ * by someone else. `minorHeads` lists the heads in a row whose automated review a pass classed with
52
+ * nothing above P2.
53
+ */
54
+ interface ReviewPushBudget {
55
+ count: number;
56
+ heads: string[];
57
+ minorHeads?: string[];
58
+ }
59
+ /** The highest class of valid automated review finding that a pass reported for the head it started on. */
60
+ type AutomatedReviewClass = "P0" | "P1" | "P2" | "P3" | "none";
61
+ /**
62
+ * Model passes on one PR in the last 24 hours. `passes` holds the time each pass started the model.
63
+ * `human` is the generation of the last person's feedback that a pass saw. `exemptions` lists the
64
+ * exemptions already used, so each applies once.
65
+ */
66
+ interface DailyPassBudget {
67
+ passes: number[];
68
+ human?: number;
69
+ exemptions: string[];
70
+ }
71
+ interface InboxBudgets {
72
+ providerRetries?: number;
73
+ noProgress?: number;
74
+ reviewPushes?: number;
75
+ minorReviewRounds?: number;
76
+ dailyPasses?: number;
77
+ }
78
+ //#endregion
79
+ //#region src/github/checkout.d.ts
80
+ /** Why a persistent provider workspace was kept or emptied. */
81
+ type GitHubWorkspaceReuse = "warm" | "cold" | "dirty" | "missing-metadata" | (string & {});
82
+ //#endregion
83
+ //#region src/github/repair.d.ts
84
+ interface GitHubRepairCommit {
85
+ message: string;
86
+ paths: string[];
87
+ /** Files where a base merge intentionally keeps the PR's version over a base change, each with the reason. */
88
+ baseOverrides?: Array<{
89
+ path: string;
90
+ reason: string;
91
+ }>;
92
+ }
93
+ //#endregion
94
+ //#region src/github/host.d.ts
95
+ type GitHubHostSecret = string | {
96
+ unseal: () => string;
97
+ };
98
+ interface GitHubHostCredentials {
99
+ appId?: number | string;
100
+ installationId?: number | string;
101
+ owner?: string;
102
+ privateKey?: GitHubHostSecret;
103
+ token?: GitHubHostSecret;
104
+ }
105
+ interface GitHubHostCredentialContext {
106
+ /** Repository whose GitHub credentials are needed; omitted for unscoped access. */
107
+ repository?: string;
108
+ signal: AbortSignal;
109
+ }
110
+ interface GitHubHostOptions {
111
+ credentials: (context: GitHubHostCredentialContext) => GitHubHostCredentials | Promise<GitHubHostCredentials>;
112
+ /** A `fetch` for Forge requests, for tests and runtimes without a global one. */
113
+ fetch?: typeof fetch;
114
+ identity?: {
115
+ appId?: number;
116
+ email?: string;
117
+ login?: string;
118
+ };
119
+ maxBuffer?: number;
120
+ /** Forge request timeout in milliseconds. Default 60000. */
121
+ timeout?: number;
122
+ userAgent?: string;
123
+ /**
124
+ * `false` stops Forge providers from revalidating repeated GETs with `If-None-Match`. Default: on. Entries are
125
+ * kept per App installation, so they survive the hourly token rotation, or per token without an App.
126
+ */
127
+ conditionalRequests?: boolean;
128
+ }
129
+ interface GitHubHostAccess {
130
+ /**
131
+ * Environment for `gh` and `git`: `GH_TOKEN`, `GITHUB_TOKEN`, and the commit identity. With a `repository`,
132
+ * it also has the Git credentials for that repository in `GIT_CONFIG_KEY_<n>` and `GIT_CONFIG_VALUE_<n>`.
133
+ */
134
+ env: Record<string, string>;
135
+ token: string;
136
+ }
137
+ interface GitHubHostPullRequest {
138
+ headRef?: string;
139
+ headRepository?: string;
140
+ headSha: string;
141
+ number: number;
142
+ repository: string;
143
+ }
144
+ interface GitHubHostCheckout extends GitHubHostAccess {
145
+ path: string;
146
+ /**
147
+ * Restore source instruction files only before the provider injects its instructions. For the
148
+ * `persistent.work` directory, `reuse` keeps its ignored files when the tracked tree matches the
149
+ * head, and the result says whether it did. `complete` checks the whole head out into another
150
+ * directory the caller owns, the way the `persistent.work` directory is prepared.
151
+ */
152
+ prepareWorkspace(target: string, options?: {
153
+ restoreInstructions?: boolean;
154
+ reuse?: boolean;
155
+ reason?: string;
156
+ complete?: boolean;
157
+ }): Promise<{
158
+ reused: boolean;
159
+ reason: GitHubWorkspaceReuse;
160
+ } | void>;
161
+ commitRepair(target: string, input: GitHubRepairCommit, options?: {
162
+ verifyDependencies?: boolean;
163
+ }): Promise<string>;
164
+ push(target?: string, options?: {
165
+ signal?: AbortSignal;
166
+ beforePush?: (head?: string) => void | Promise<void>;
167
+ afterPush?: (head: string) => void | Promise<void>;
168
+ }): Promise<string>;
169
+ signal: AbortSignal;
170
+ }
171
+ interface GitHubHostCheckoutOptions {
172
+ signal?: AbortSignal;
173
+ timeout?: number;
174
+ /**
175
+ * Keep the host clone in `checkout` after the callback and fetch into it next time instead of
176
+ * cloning. `work` is the provider workspace that `prepareWorkspace` keeps between calls.
177
+ */
178
+ persistent?: {
179
+ checkout: string;
180
+ work: string;
181
+ };
182
+ }
183
+ interface GitHubHostForgeOptions extends GitHubHostCheckoutOptions {
184
+ /** Repository whose credentials the provider uses; omitted for unscoped access. */
185
+ repository?: string;
186
+ }
187
+ interface GitHubHostAccessOptions extends GitHubHostCheckoutOptions {
188
+ fallback?: boolean;
189
+ refresh?: boolean;
190
+ /** Mint a new App installation token when the cached one expires within this many milliseconds. */
191
+ minLifetime?: number;
192
+ repository?: string;
193
+ }
194
+ /** A GitHub rate limit that the response headers of this host's Forge requests reported. */
195
+ interface GitHubHostRateLimit {
196
+ /** The GitHub rate limit resource, for example `core` or `graphql`. */
197
+ resource: string;
198
+ limit: number;
199
+ remaining: number;
200
+ resetAt: number;
201
+ checkedAt: number;
202
+ }
203
+ interface GitHubHost {
204
+ channel(options?: Omit<GitHubChannelOptions, "app">): AgentChannelDefinition;
205
+ /** Return the verified login configured for this host, when available. */
206
+ identity(): string | undefined;
207
+ /** Immutable GitHub App ID for managed activity ownership. */
208
+ appId?(): number | undefined;
209
+ /** Resolve credentials and Git binding for the current checkout callback. */
210
+ environment(): Promise<Record<string, string>>;
211
+ access(input?: GitHubHostAccessOptions): Promise<GitHubHostAccess>;
212
+ /**
213
+ * A `forges` GitHub provider with the repository's credentials. It has every Forge verb and `graphql()`.
214
+ * Create one for each operation: installation tokens expire after one hour.
215
+ */
216
+ forge(input?: GitHubHostForgeOptions): Promise<GitHubProvider>;
217
+ /** The most constrained rate limit that recent Forge responses reported, or undefined before the first response. */
218
+ rateLimit(): GitHubHostRateLimit | undefined;
219
+ withPullRequestCheckout<T>(pullRequest: GitHubHostPullRequest, run: (checkout: GitHubHostCheckout) => Promise<T>, options?: GitHubHostCheckoutOptions): Promise<T>;
220
+ }
221
+ interface GitHubAppEnvironment {
222
+ appId: number;
223
+ privateKey: string;
224
+ /** Fixed installation of `owner`, which it needs. Repositories of other owners use `installations` or discovery. */
225
+ installationId?: number;
226
+ /** Repository owner of `installationId`. */
227
+ owner?: string;
228
+ /** Explicit installation IDs by repository owner. */
229
+ installations?: Record<string, number>;
230
+ /** Fallback token for repositories without an App installation. */
231
+ token?: string;
232
+ userAgent?: string;
233
+ }
234
+ /**
235
+ * GitHub App credentials for `createGitHubHost()` that resolve the installation of each
236
+ * repository from the App, and the App's bot identity for commits. Results are cached.
237
+ */
238
+ declare function createGitHubAppCredentials(app: GitHubAppEnvironment): {
239
+ credentials(context: GitHubHostCredentialContext): Promise<GitHubHostCredentials>;
240
+ /** Every repository that the App's installations can access. */
241
+ repositories: (signal?: AbortSignal) => Promise<GitHubAppRepository[]>;
242
+ /** Failed App webhook deliveries since `since` that no later attempt delivered, oldest first. */
243
+ failedDeliveries: (since: number, signal?: AbortSignal) => Promise<GitHubAppDelivery[]>;
244
+ /** Sends one App webhook delivery again. */
245
+ redeliver: (id: string, signal?: AbortSignal) => Promise<void>;
246
+ /** The App bot's login and noreply email, used as the commit author. */
247
+ identity(): Promise<{
248
+ appId: number;
249
+ login: string;
250
+ email: string;
251
+ }>;
252
+ };
253
+ declare function createGitHubHost(options: GitHubHostOptions): GitHubHost;
254
+ //#endregion
255
+ //#region src/github/required-checks.d.ts
256
+ type GitHubRequiredCheckState = "pending" | "failed" | "passed" | "unknown";
257
+ //#endregion
258
+ //#region src/babysitter/inbox/types.d.ts
259
+ interface GitHubActor {
260
+ login?: string;
261
+ type?: string;
262
+ __typename?: string;
263
+ }
264
+ interface GitHubTimestamps {
265
+ updated_at?: string | null;
266
+ updatedAt?: string | null;
267
+ created_at?: string | null;
268
+ createdAt?: string | null;
269
+ submitted_at?: string | null;
270
+ submittedAt?: string | null;
271
+ completed_at?: string | null;
272
+ started_at?: string | null;
273
+ }
274
+ interface GitHubRef {
275
+ sha?: string;
276
+ ref?: string;
277
+ repo?: {
278
+ [key: string]: unknown;
279
+ full_name: string;
280
+ default_branch?: string;
281
+ owner?: {
282
+ [key: string]: unknown;
283
+ login?: string;
284
+ } | null;
285
+ } | null;
286
+ }
287
+ interface GitHubPullRequestRecord extends GitHubTimestamps {
288
+ [key: string]: unknown;
289
+ number: number;
290
+ user?: GitHubActor | null;
291
+ author?: GitHubActor | null;
292
+ state?: string;
293
+ draft?: boolean;
294
+ isDraft?: boolean;
295
+ title?: string;
296
+ body?: string | null;
297
+ html_url?: string;
298
+ url?: string;
299
+ head?: GitHubRef;
300
+ base?: GitHubRef;
301
+ headRefOid?: string;
302
+ headRefName?: string;
303
+ baseRefOid?: string;
304
+ baseRefName?: string;
305
+ headRepository?: {
306
+ nameWithOwner: string;
307
+ } | null;
308
+ author_association?: string;
309
+ authorAssociation?: string;
310
+ labels?: (string | {
311
+ name: string;
312
+ })[];
313
+ mergeable?: boolean | null;
314
+ mergeable_state?: string;
315
+ reviewDecision?: string | null;
316
+ }
317
+ /** Fields consumed from comments, reviews, checks, and statuses. Extra GitHub fields remain stored. */
318
+ interface GitHubEvidence extends GitHubTimestamps {
319
+ [key: string]: unknown;
320
+ id?: string | number;
321
+ node_id?: string;
322
+ databaseId?: number | null;
323
+ user?: GitHubActor | null;
324
+ author?: GitHubActor | null;
325
+ body?: string | null;
326
+ html_url?: string;
327
+ url?: string;
328
+ deleted?: boolean;
329
+ state?: string;
330
+ name?: string;
331
+ status?: string;
332
+ conclusion?: string | null;
333
+ head_sha?: string;
334
+ sha?: string;
335
+ context?: string;
336
+ description?: string | null;
337
+ details_url?: string | null;
338
+ target_url?: string | null;
339
+ performed_via_github_app?: {
340
+ id: number;
341
+ } | null;
342
+ app?: {
343
+ [key: string]: unknown;
344
+ slug?: string;
345
+ id?: number;
346
+ } | null;
347
+ output?: {
348
+ summary?: string | null;
349
+ text?: string | null;
350
+ };
351
+ pull_requests?: {
352
+ number: number;
353
+ }[];
354
+ commit_id?: string;
355
+ original_commit_id?: string;
356
+ commit?: {
357
+ [key: string]: unknown;
358
+ oid?: string;
359
+ } | null;
360
+ pull_request_review_id?: number;
361
+ in_reply_to_id?: number;
362
+ path?: string;
363
+ line?: number | null;
364
+ original_line?: number | null;
365
+ start_line?: number | null;
366
+ original_start_line?: number | null;
367
+ side?: string;
368
+ start_side?: string | null;
369
+ }
370
+ interface GitHubReviewThread {
371
+ [key: string]: unknown;
372
+ id?: string;
373
+ node_id?: string;
374
+ isResolved?: boolean;
375
+ isOutdated?: boolean;
376
+ path?: string;
377
+ line?: number | null;
378
+ originalLine?: number | null;
379
+ startLine?: number | null;
380
+ originalStartLine?: number | null;
381
+ comments?: GitHubEvidence[] | {
382
+ nodes: GitHubEvidence[];
383
+ pageInfo?: {
384
+ hasNextPage: boolean;
385
+ endCursor?: string | null;
386
+ };
387
+ };
388
+ resolutionSource?: string;
389
+ resolutionObservedAt?: string;
390
+ }
391
+ //#endregion
392
+ //#region src/babysitter/inbox/wait-state.d.ts
393
+ type PullRequestWake = {
394
+ kind: "checks";
395
+ repository: string;
396
+ headSha: string;
397
+ } | {
398
+ kind: "pull-request";
399
+ repository: string;
400
+ number: number;
401
+ };
402
+ /**
403
+ * Caller-selected structured evidence that must change before another Agent pass.
404
+ * `retryAt` schedules host reevaluation after transient gates.
405
+ * `knownFailures` lists failing checks that the parked pass already saw.
406
+ * An external wait without `wake` resumes on feedback, head or base changes after the named manual action.
407
+ * `defer: 'checks'` postpones a pass while gates run; it records no assessment and ends when they stop.
408
+ */
409
+ type PullRequestWait = {
410
+ headSha: string;
411
+ reason: string;
412
+ reasonCode?: string;
413
+ evidenceKey: string;
414
+ retryAt?: number;
415
+ knownFailures?: string[];
416
+ kind?: "checks" | "external";
417
+ defer?: "checks";
418
+ wake?: PullRequestWake;
419
+ };
420
+ //#endregion
421
+ //#region src/babysitter/inbox/storage.d.ts
422
+ /**
423
+ * SQL access for the PR inbox. `agentState.extension("babysitter")` from
424
+ * `@vite-hub/agent/state` satisfies it and keeps the inbox in the Agent State database.
425
+ */
426
+ interface PullRequestInboxStorage extends Pick<SqliteAgentStateExtension, "execute" | "tablePrefix" | "transaction"> {
427
+ close?: () => Promise<void>;
428
+ }
429
+ //#endregion
430
+ //#region src/babysitter/inbox/status-delivery.d.ts
431
+ interface StatusDelivery {
432
+ version: string;
433
+ contentKey: string;
434
+ repository: string;
435
+ number: number;
436
+ head: string;
437
+ precedingHead?: string;
438
+ projection?: true;
439
+ workerLease?: string;
440
+ generation: number;
441
+ text: string;
442
+ attempts: number;
443
+ nextAt: number;
444
+ lease?: string;
445
+ leaseUntil?: number;
446
+ lastError?: string;
447
+ activity: {
448
+ runId: string;
449
+ status: "queued" | "running" | "failed" | "completed" | "waiting";
450
+ startedAt?: string;
451
+ updatedAt: string;
452
+ links: Array<{
453
+ label: string;
454
+ url: string;
455
+ }>;
456
+ tasks: never[];
457
+ summary: string;
458
+ };
459
+ }
460
+ //#endregion
461
+ //#region src/babysitter/inbox/store.d.ts
462
+ type Snapshot = {
463
+ repository: string;
464
+ number: number;
465
+ pr: GitHubPullRequestRecord | null;
466
+ generation: number;
467
+ handled: number;
468
+ dirtyAt: number;
469
+ nextAt: number;
470
+ revision?: number;
471
+ status: "ready" | "working" | "waiting" | "terminal";
472
+ wait?: PullRequestWait;
473
+ lease: string | null;
474
+ leaseUntil: number;
475
+ attempts: number;
476
+ progressBudget?: ProgressBudget;
477
+ /** Review-driven pushes on this PR. Set when `budgets.reviewPushes` is configured. */
478
+ reviewPushBudget?: ReviewPushBudget;
479
+ /** Model passes in the last 24 hours. Set when `budgets.dailyPasses` is configured. */
480
+ dailyPassBudget?: DailyPassBudget;
481
+ /** Generation of the last human comment or review. A wait rejected before it stays free. */
482
+ humanFeedbackGeneration?: number;
483
+ recoveryHead?: string;
484
+ sourcePushHead?: string;
485
+ sourcePushHeads?: string[];
486
+ sourcePushOverflow?: boolean;
487
+ prospectivePush?: {
488
+ token: string;
489
+ heads: string[];
490
+ };
491
+ threadReopens?: Record<string, number>;
492
+ /** Authenticated outcome replies, including IDs used by thread-only reads. */
493
+ ownedReviewCommentIds?: string[];
494
+ hydrated: boolean;
495
+ refresh: boolean;
496
+ feedbackRefresh: boolean;
497
+ comments: Record<string, GitHubEvidence>;
498
+ reviews: Record<string, GitHubEvidence>;
499
+ reviewComments: Record<string, GitHubEvidence>;
500
+ checks: Record<string, GitHubEvidence>;
501
+ statuses: Record<string, GitHubEvidence>;
502
+ ciEvidence?: Record<string, unknown>[];
503
+ threads: GitHubReviewThread[];
504
+ threadsHydrated?: boolean;
505
+ reasons: string[];
506
+ lastResult?: string;
507
+ };
508
+ type SnapshotPatch = Partial<Pick<Snapshot, "pr" | "comments" | "reviews" | "reviewComments" | "checks" | "statuses" | "threads" | "hydrated" | "refresh" | "feedbackRefresh" | "threadsHydrated" | "ciEvidence">>;
509
+ interface GitHubInboxDeliveryResult {
510
+ accepted: true;
511
+ duplicate?: boolean;
512
+ queued: number[];
513
+ updated: number[];
514
+ ignored?: boolean;
515
+ reason?: string;
516
+ }
517
+ interface GitHubInboxSummary {
518
+ repository: string;
519
+ number: number;
520
+ head?: string;
521
+ generation: number;
522
+ handled: number;
523
+ status: Snapshot["status"];
524
+ reasons: string[];
525
+ /** Every current-head check finished without failing and nothing conflicts. Such PRs are claimed early. */
526
+ mergeReady?: boolean;
527
+ wait?: PullRequestWait;
528
+ dirty: boolean;
529
+ attempts: number;
530
+ nextAt: number;
531
+ lastResult?: string;
532
+ progressBudget?: ProgressBudget;
533
+ state?: string;
534
+ dirtyAt?: number;
535
+ reviewPushBudget?: ReviewPushBudget;
536
+ dailyPassBudget?: DailyPassBudget;
537
+ stackBlocked?: boolean;
538
+ stackParent?: {
539
+ number: number;
540
+ state: string;
541
+ };
542
+ }
543
+ type Claim = {
544
+ token: string;
545
+ generation: number;
546
+ snapshot: Snapshot;
547
+ runId?: string;
548
+ startedAt?: number;
549
+ activity?: AgentRunActivity;
550
+ /** The pass's class of the automated review of the claimed head. `finish()` records it with `budgets.minorReviewRounds`. */
551
+ automatedReview?: AutomatedReviewClass;
552
+ };
553
+ type DirectMergeAttempt = {
554
+ token: string;
555
+ generation: number;
556
+ revision: number;
557
+ head: string;
558
+ startedAt: number;
559
+ asynchronous?: boolean;
560
+ enqueued?: boolean;
561
+ foldInto?: number;
562
+ };
563
+ interface PullRequestInboxOptions {
564
+ /** A private `node:sqlite` file. Use `storage` instead to keep the inbox in the Agent State database. */
565
+ path?: string;
566
+ /** SQL storage, for example `agentState.extension("babysitter")`. */
567
+ storage?: PullRequestInboxStorage;
568
+ /** Separates inboxes that share one storage, for example one per Agent. */
569
+ scope?: string;
570
+ /** The served repositories, or a function that returns the current lowercase list on each read. */
571
+ repositories: readonly string[] | (() => readonly string[]);
572
+ filter?: GitHubPullRequestFilter;
573
+ clock?: () => number;
574
+ activityAuthors?: readonly string[];
575
+ activityAppId?: number;
576
+ budgets?: InboxBudgets;
577
+ /** Labels that put a PR first in the claim order after main repairs. Matched case-insensitively. */
578
+ priorityLabels?: readonly string[];
579
+ /** Head branch prefix of PRs that repair the base branch. They are claimed first and never exhaust `budgets.noProgress`. */
580
+ mainRepairBranchPrefix?: string;
581
+ /** Claim a PR whose base is another open PR's branch. By default it waits until its parent merges. */
582
+ claimStackChildren?: boolean;
583
+ /**
584
+ * Called once per process for each stored PR row that fails validation. The inbox skips such a row
585
+ * in claims, summaries and wait evaluation, so one bad row cannot stop the queue or its health.
586
+ */
587
+ invalidRow?: (row: InvalidInboxRow) => void;
588
+ }
589
+ interface InvalidInboxRow {
590
+ repository: string;
591
+ number: number;
592
+ error: unknown;
593
+ }
594
+ /**
595
+ * Durable PR inbox. Every method reads and writes storage, so all of them are asynchronous.
596
+ * Snapshot JSON stays the source of truth. Claim, recovery, head matching, and summaries use
597
+ * indexed columns derived from it on every write, so they do not parse every snapshot.
598
+ */
599
+ declare class PullRequestInbox {
600
+ private storage;
601
+ private ownsStorage;
602
+ private scope;
603
+ private ready?;
604
+ private tables;
605
+ private repositoryList;
606
+ private clock;
607
+ private filter?;
608
+ private activityAuthors;
609
+ private activityAppId?;
610
+ private budgets;
611
+ private priorityLabels;
612
+ private mainRepairBranchPrefix?;
613
+ private claimStackChildren;
614
+ private invalidRow?;
615
+ private reportedRows;
616
+ constructor({ path, storage, scope, repositories, filter, clock, budgets, activityAuthors, activityAppId, priorityLabels, mainRepairBranchPrefix, claimStackChildren, invalidRow }: PullRequestInboxOptions);
617
+ close(): Promise<void>;
618
+ private init;
619
+ private transaction;
620
+ private read;
621
+ /** Parses one stored row. An invalid row is reported once and skipped by queue-wide reads. */
622
+ private parseRow;
623
+ private reportInvalidRow;
624
+ private get repositories();
625
+ private repositoryFilter;
626
+ private ownsComment;
627
+ private isActivityComment;
628
+ private isOutcomeComment;
629
+ private cleanReviewComments;
630
+ private cleanSnapshot;
631
+ private getIn;
632
+ /** A snapshot for a queue-wide scan. An invalid row is reported and skipped. */
633
+ private getRowIn;
634
+ get(repository: string, number: number): Promise<Snapshot | undefined>;
635
+ all(): Promise<Snapshot[]>;
636
+ private compactTerminal;
637
+ private put;
638
+ private empty;
639
+ private metaIn;
640
+ private setMetaIn;
641
+ meta(key: string): Promise<unknown>;
642
+ /** A numeric metadata value, such as a timestamp; anything else reads as undefined. */
643
+ metaNumber(key: string): Promise<number | undefined>;
644
+ /** Metadata entries whose keys start with `prefix`. */
645
+ metaEntries(prefix: string): Promise<Array<[string, unknown]>>;
646
+ deleteMeta(key: string): Promise<void>;
647
+ setMeta(key: string, value: unknown): Promise<void>;
648
+ private enqueueStatusResult;
649
+ private statusWritersIn;
650
+ private settleStatusWriterIn;
651
+ private enqueueStatusProjectionIn;
652
+ /** A bounded batch of due deliveries. Invalid metadata never reaches the publisher. */
653
+ pendingStatusDeliveries(limit?: number): Promise<StatusDelivery[]>;
654
+ /** Claim due, eligible deliveries atomically across hosts. Deferred heads yield the batch. */
655
+ claimStatusDeliveries(limit?: number, leaseMs?: number): Promise<StatusDelivery[]>;
656
+ /** Keep the external writer's lease, including when its saved result is superseded. */
657
+ renewStatusDelivery(observed: StatusDelivery, leaseMs?: number): Promise<boolean>;
658
+ /** Version and lease comparisons preserve newer results and fence replaced consumers. */
659
+ finishStatusDelivery(observed: StatusDelivery, outcome: "delivered" | "discarded"): Promise<boolean>;
660
+ retryStatusDelivery(observed: StatusDelivery, failure: unknown): Promise<boolean>;
661
+ /** Repair the external projection after a replaced writer finally settles. */
662
+ reconcileSettledStatusWriter(observed: StatusDelivery): Promise<boolean>;
663
+ private reconcileStatusWriterIn;
664
+ /** Upgrade historical waiting results without synthetic webhooks or model passes. */
665
+ backfillStatusDeliveries(): Promise<void>;
666
+ recordWorkerBlocker(observed: Snapshot, revision: string): Promise<void>;
667
+ /** Wake and persist its release marker atomically, so restart cannot repeat the wake. */
668
+ wakeForWorkerRelease(observed: Snapshot, revision: string, evidenceKey: string): Promise<boolean>;
669
+ private directMergeKey;
670
+ private stackFoldKey;
671
+ /** The stacked pull request whose merge into this pull request's branch has an unknown outcome. */
672
+ private foldingChildIn;
673
+ foldingChild(repository: string, parent: number): Promise<number | undefined>;
674
+ /**
675
+ * Atomically records that a claim has started an irreversible merge request. With `foldInto`, the merge
676
+ * targets that open parent's branch. A parent with a merge in flight refuses the fold, and a parent with
677
+ * a fold in flight refuses its own merge, so a fold never lands on a branch that already merged.
678
+ */
679
+ beginDirectMerge(claim: Claim, head: string, asynchronous?: boolean, foldInto?: number): Promise<boolean>;
680
+ directMergeAttempt(repository: string, number: number): Promise<DirectMergeAttempt | undefined>;
681
+ /** Preserve a final enqueued result. */
682
+ recordDirectMergeEnqueued(repository: string, number: number, token: string): Promise<boolean>;
683
+ clearDirectMerge(repository: string, number: number, token: string): Promise<boolean>;
684
+ /** Shared provider scope should identify the credential/account, without including its secret. */
685
+ providerBudget(provider: string): Promise<ProviderBudget | undefined>;
686
+ private providerBudgetIn;
687
+ reserveProviderAttempt(provider: string): Promise<ProviderAttempt | undefined>;
688
+ finishProviderAttempt(token: ProviderAttempt, outcome: ProviderAttemptOutcome): Promise<boolean>;
689
+ resetProviderBudget(provider: string, reason: string): Promise<void>;
690
+ resetProgressBudget(repository: string, number: number, head: string, reason: string): Promise<boolean>;
691
+ private dirty;
692
+ private updatePr;
693
+ /** Whether the PR carries one of `priorityLabels`. */
694
+ isPriority(pr: GitHubPullRequestRecord | null | undefined): boolean;
695
+ /** Whether the PR's head branch starts with `mainRepairBranchPrefix`. */
696
+ isMainRepair(pr: GitHubPullRequestRecord | null | undefined): boolean;
697
+ eligible(repository: string, pr: GitHubPullRequestRecord | null): boolean;
698
+ seed(repository: string, value: unknown): Promise<Snapshot>;
699
+ ingest(id: string, event: string, value: unknown): Promise<GitHubInboxDeliveryResult>;
700
+ /** Leases up to `limit` eligible PRs. `skip` leaves a candidate unclaimed for this call. */
701
+ claim(limit: number, options?: {
702
+ only?: (snapshot: Snapshot) => boolean;
703
+ skip?: (snapshot: Snapshot) => boolean;
704
+ includeBlocked?: boolean;
705
+ }): Promise<Claim[]>;
706
+ hydrate(claim: Claim, patch: SnapshotPatch): Promise<boolean>;
707
+ refreshThreads(observed: Snapshot, threads: GitHubReviewThread[]): Promise<boolean>;
708
+ /** Retain a worker's verified thread resolution even when its webhook is missing. */
709
+ recordThreadResolution(claim: Claim, id: string, observed: Snapshot): Promise<boolean>;
710
+ /** Retain CI for an exact candidate before its source-push webhook arrives. This is not a publication receipt. */
711
+ registerProspectivePush(claim: Claim, head: string): Promise<boolean>;
712
+ release(claim: Claim): Promise<boolean>;
713
+ renew(claim: Claim, leaseUntil: number): Promise<boolean>;
714
+ /**
715
+ * Records that a claimed pass started the model, with the exemption that let it run past
716
+ * `budgets.dailyPasses`. It changes no evidence, so the claim stays current.
717
+ */
718
+ recordModelPass(claim: Claim, exemption?: string): Promise<number | false>;
719
+ /**
720
+ * Gives back the pass that `recordModelPass` counted at `at`, and its exemption, when the provider
721
+ * failed the pass before it did any work. It changes no evidence, so the claim stays current.
722
+ */
723
+ releaseModelPass(claim: Claim, at: number, exemption?: string): Promise<boolean>;
724
+ /** Checks the durable claim fence immediately before an irreversible provider action. */
725
+ isClaimCurrent(claim: Claim): Promise<boolean>;
726
+ /**
727
+ * Whether this claim still holds the lease on its claimed head, with no source push since the claim.
728
+ * Unrelated events can move the generation or revision; a pinned wait from `finish()` still accepts them.
729
+ */
730
+ holdsClaimedHead(claim: Claim): Promise<boolean>;
731
+ /**
732
+ * Finishes a claimed pass. A `wait` without `headSha` binds to the claimed head and requires
733
+ * unchanged evidence. A wait with `headSha`, such as the head of a repair push, keeps later events
734
+ * unhandled, so `waitsToEvaluate()` returns the PR and the host decides whether they need work.
735
+ */
736
+ finish(claim: Claim, result: {
737
+ text: string;
738
+ retry?: boolean;
739
+ terminal?: boolean;
740
+ progress?: ProgressOutcome;
741
+ verifiedPushHeads?: readonly string[];
742
+ wait?: Omit<PullRequestWait, "headSha"> & {
743
+ headSha?: string;
744
+ };
745
+ }): Promise<boolean>;
746
+ /**
747
+ * A wait rejected by new evidence still used its pass. Checks and bot reviews arrive during most
748
+ * passes, so the pass counts unless a person commented after the claim: the next pass answers them.
749
+ */
750
+ private recordRejectedProgress;
751
+ /**
752
+ * An exhausted head gets one more pass for new evidence that a pass can act on: a new merge
753
+ * conflict, or new bot feedback. Each kind is granted once per head. A person's feedback resets the budget instead.
754
+ */
755
+ private grantProgress;
756
+ private recordReviewPush;
757
+ private recordProgress;
758
+ /** Waiting PRs that received events since the host last evaluated their wait. */
759
+ waitsToEvaluate(includeExternal?: boolean, includeIdle?: boolean): Promise<Snapshot[]>;
760
+ /** Records that the host evaluated a wait's new events and the wait still holds. */
761
+ acknowledgeWait(observed: Snapshot): Promise<boolean>;
762
+ /** Re-evaluate structured evidence outside an Agent invocation before calling this method. */
763
+ wake(observed: Snapshot, evidenceKey: string, options?: {
764
+ recovery?: boolean;
765
+ }): Promise<boolean>;
766
+ /**
767
+ * Frees every lease in this scope at startup and returns how many were held. Call it only when one
768
+ * process owns the scope: a pass cannot survive a restart, so its lease only delays the PR.
769
+ */
770
+ releaseLeases(): Promise<number>;
771
+ recoverLeases(): Promise<void>;
772
+ summary(): Promise<GitHubInboxSummary[]>;
773
+ /** The open, unleased PR that a reconciliation probe checked longest ago, with that probe time. */
774
+ nextProbe(): Promise<{
775
+ repository: string;
776
+ number: number;
777
+ probedAt: number;
778
+ } | undefined>;
779
+ /**
780
+ * Copies a pre-Agent-State inbox file once: snapshots, metadata except probe schedules, and
781
+ * delivery IDs from the last 30 days. Leases are cleared, so stop the old process first.
782
+ * The source file is opened read-only and left unchanged.
783
+ */
784
+ importLegacyFile(path: string): Promise<{
785
+ imported: boolean;
786
+ snapshots: number;
787
+ skipped: number;
788
+ deliveries: number;
789
+ }>;
790
+ /** Drops delivery payloads after `payloadMs` and delivery IDs after `idMs`. Recent IDs still deduplicate redeliveries. */
791
+ pruneDeliveries({ payloadMs, idMs }?: {
792
+ payloadMs?: number;
793
+ idMs?: number;
794
+ }): Promise<void>;
795
+ }
796
+ //#endregion
797
+ //#region src/babysitter/admission.d.ts
798
+ /** A reason to stop model passes, returned by `admission.check`. */
799
+ interface BabysitterAdmissionPause {
800
+ /** Short machine-readable reason, such as `"provider-quota"`. */
801
+ reason: string;
802
+ detail?: string;
803
+ /** Epoch milliseconds when the pause ends, if it ends at a known time. */
804
+ retryAt?: number;
805
+ }
806
+ /**
807
+ * Shared-resource limits that the host checks before it claims a PR. A spent limit stops model
808
+ * passes. Direct merges and recorded waits continue.
809
+ */
810
+ interface BabysitterAdmissionOptions {
811
+ /**
812
+ * Input tokens that this Agent's passes may use per local clock hour and per local day. Leave a
813
+ * window out for no limit. Defaults to no limit.
814
+ */
815
+ inputTokens?: {
816
+ hourly?: number;
817
+ daily?: number;
818
+ };
819
+ /** Free space, in MiB, that the temporary directory needs before a pass. `false` disables the check. Defaults to 4096. */
820
+ minFreeTmpMb?: number | false;
821
+ /** Stop every claim, including direct merges, for example during a smoke boot. Defaults to `false`. */
822
+ paused?: boolean;
823
+ /**
824
+ * Extra check before each claim, for example a provider quota. Return a pause to stop model
825
+ * passes, or `undefined` to continue. An error is reported in health and does not pause.
826
+ */
827
+ check?: () => BabysitterAdmissionPause | undefined | Promise<BabysitterAdmissionPause | undefined>;
828
+ }
829
+ /** Token limits are best-effort retained-journal thresholds, not billing caps. */
830
+ interface BabysitterAdmissionLimits {
831
+ minFreeTmpBytes?: number;
832
+ hourlyInputTokens?: number;
833
+ dailyInputTokens?: number;
834
+ paused: boolean;
835
+ }
836
+ interface BabysitterBudgetWindows {
837
+ hourStart: number;
838
+ hourEnd: number;
839
+ dayStart: number;
840
+ dayEnd: number;
841
+ }
842
+ interface BabysitterAdmissionState {
843
+ windows: BabysitterBudgetWindows;
844
+ tmpDir: string;
845
+ freeTmpBytes?: number;
846
+ hourlyInputTokens?: number;
847
+ dailyInputTokens?: number;
848
+ pause?: BabysitterAdmissionPause;
849
+ errors?: string[];
850
+ }
851
+ interface BabysitterAdmissionResult {
852
+ accepting: boolean;
853
+ hostOnly?: boolean;
854
+ reason?: string;
855
+ detail?: string;
856
+ retryAt?: number;
857
+ accounting: "best-effort-retained-journal";
858
+ state: BabysitterAdmissionState;
859
+ limits: BabysitterAdmissionLimits;
860
+ }
861
+ //#endregion
862
+ //#region src/babysitter/pr-workspaces.d.ts
863
+ /** Keep one workspace per open PR between passes. See `BabysitterOptions.warmWorkspaces`. */
864
+ interface BabysitterWarmWorkspaces {
865
+ /**
866
+ * Continue the previous pass's provider thread when this pass starts in a warm workspace on the
867
+ * same base commit and release, after a pass that pushed or recorded a wait. Defaults to `false`.
868
+ */
869
+ resumeThreads?: boolean;
870
+ /** Disk the kept workspaces may use, in GiB. Least recently used entries go first. Defaults to 60. */
871
+ budgetGb?: number;
872
+ /** Days without a pass after which a PR's workspace is removed. Defaults to 7. */
873
+ idleDays?: number;
874
+ /** Free space, in percent of the filesystem, below which least recently used entries go. Defaults to 15. */
875
+ minFreePercent?: number;
876
+ /** Minutes between sweeps of terminal, idle and over-budget entries. `0` sweeps only at startup. Defaults to 60. */
877
+ sweepMinutes?: number;
878
+ }
879
+ /** What a pass left in its PR workspace. The next pass decides from it whether to keep the tree. */
880
+ interface PullRequestWorkspaceRecord {
881
+ /** The head the workspace holds: the pass's push, or the head it started on. */
882
+ head: string;
883
+ /** The base commit the pass started on. */
884
+ base?: string;
885
+ /** The pass finished without an error, so its tree and installed dependencies are complete. */
886
+ ok: boolean;
887
+ /** The pass pushed or recorded a wait, so its provider thread may continue. */
888
+ resumable?: boolean;
889
+ release?: string;
890
+ /** The provider thread suffix the pass ran in. */
891
+ session?: string;
892
+ outcome?: string;
893
+ }
894
+ interface PullRequestWorkspaceEntry {
895
+ /** The trusted host clone. */
896
+ checkout: string;
897
+ /** The provider workspace, used as `driver.cwd`. */
898
+ work: string;
899
+ /** Whether a provider workspace existed before this pass. */
900
+ existed: boolean;
901
+ previous?: PullRequestWorkspaceRecord;
902
+ record(result: PullRequestWorkspaceRecord): Promise<void>;
903
+ release(): Promise<void>;
904
+ }
905
+ type PullRequestWorkspaceStatus = "open" | "terminal" | "unknown";
906
+ interface PullRequestWorkspaces {
907
+ root: string;
908
+ resumeThreads: boolean;
909
+ sweepMs: number;
910
+ /** Locks the PR's entry for one pass. A pass that ends without `record()` leaves a failed record. */
911
+ acquire(repository: string, number: number, signal?: AbortSignal): Promise<PullRequestWorkspaceEntry>;
912
+ /** Removes terminal, unknown and idle entries, then least recently used ones while over budget or low on disk. */
913
+ sweep(status: (repository: string, number: number) => Promise<PullRequestWorkspaceStatus>): Promise<{
914
+ removed: {
915
+ name: string;
916
+ reason: string;
917
+ }[];
918
+ keptBytes: number;
919
+ kept: number;
920
+ }>;
921
+ }
922
+ //#endregion
923
+ export { createGitHubAppCredentials as C, GitHubHostSecret as S, AutomatedReviewClass as T, GitHubHostCredentials as _, BabysitterAdmissionResult as a, GitHubHostPullRequest as b, PullRequestInboxStorage as c, GitHubHost as d, GitHubHostAccess as f, GitHubHostCredentialContext as g, GitHubHostCheckoutOptions as h, BabysitterAdmissionPause as i, GitHubRequiredCheckState as l, GitHubHostCheckout as m, PullRequestWorkspaces as n, PullRequestInbox as o, GitHubHostAccessOptions as p, BabysitterAdmissionOptions as r, Snapshot as s, BabysitterWarmWorkspaces as t, GitHubAppEnvironment as u, GitHubHostForgeOptions as v, createGitHubHost as w, GitHubHostRateLimit as x, GitHubHostOptions as y };