@vite-hub/presets 0.1.0 → 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 +171 -35
- package/dist/babysitter/server.d.ts +59 -6
- package/dist/babysitter/server.js +2 -2
- package/dist/babysitter-DQeA81N0.js +2541 -0
- package/dist/babysitter.d.ts +200 -18
- package/dist/babysitter.js +2 -2
- package/dist/error-diagnostics-o3pHscWs.js +729 -0
- package/dist/host-DH0o7xSq.js +695 -0
- package/dist/labeller.d.ts +47 -3
- package/dist/labeller.js +115 -33
- package/dist/{admission-DBJdt-CX.d.ts → pr-workspaces-CMdQ9U15.d.ts} +375 -88
- package/dist/server-ILDJE5V7.js +12254 -0
- package/dist/workspace.js +2 -5
- package/package.json +17 -18
- package/dist/babysitter-B4D1zeYf.js +0 -715
- package/dist/host-CH0L3VC9.js +0 -438
- package/dist/server-DDmyZ98B.js +0 -6745
package/dist/host-CH0L3VC9.js
DELETED
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
import { _ as hasRuntimeType, a as createBabysitterAdmission, o as resolveBabysitterAdmissionLimits, y as isRuntimeRecord } from "./babysitter-B4D1zeYf.js";
|
|
2
|
-
import { r as budgetParks, t as createBabysitterRuntime } from "./server-DDmyZ98B.js";
|
|
3
|
-
import { defineAgent } from "@vite-hub/agent";
|
|
4
|
-
import { access, lstat, mkdtemp, open, readFile, readdir, rename, rm, stat } from "node:fs/promises";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { channelEnv } from "@vite-hub/agent/channels";
|
|
7
|
-
import { registerAgentProcessHostIntake } from "@vite-hub/agent/process-host";
|
|
8
|
-
import { execFile } from "node:child_process";
|
|
9
|
-
import { promisify } from "node:util";
|
|
10
|
-
import { constants } from "node:fs";
|
|
11
|
-
import { delimiter, isAbsolute, join, resolve, sep } from "node:path";
|
|
12
|
-
import { createGitHubAppCredentials, createGitHubHost } from "@vite-hub/agent/server/github";
|
|
13
|
-
import { createProcessAgentHost } from "@vite-hub/agent/runtime/process";
|
|
14
|
-
//#region src/babysitter/preflight.ts
|
|
15
|
-
const execute = promisify(execFile);
|
|
16
|
-
async function validateExecutable(path) {
|
|
17
|
-
await access(path, constants.X_OK);
|
|
18
|
-
if (!(await stat(path)).isFile()) throw new Error(`Executable is not a file: ${path}`);
|
|
19
|
-
if (process.platform !== "win32") {
|
|
20
|
-
const file = await open(path, "r");
|
|
21
|
-
const buffer = Buffer.alloc(256);
|
|
22
|
-
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0).finally(() => file.close());
|
|
23
|
-
const bytes = buffer.subarray(0, bytesRead);
|
|
24
|
-
if (!(bytes[0] === 35 && bytes[1] === 33)) {
|
|
25
|
-
const elf = bytes[0] === 127 && bytes[1] === 69 && bytes[2] === 76 && bytes[3] === 70;
|
|
26
|
-
const macho = [
|
|
27
|
-
[
|
|
28
|
-
254,
|
|
29
|
-
237,
|
|
30
|
-
250,
|
|
31
|
-
206
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
206,
|
|
35
|
-
250,
|
|
36
|
-
237,
|
|
37
|
-
254
|
|
38
|
-
],
|
|
39
|
-
[
|
|
40
|
-
254,
|
|
41
|
-
237,
|
|
42
|
-
250,
|
|
43
|
-
207
|
|
44
|
-
],
|
|
45
|
-
[
|
|
46
|
-
207,
|
|
47
|
-
250,
|
|
48
|
-
237,
|
|
49
|
-
254
|
|
50
|
-
],
|
|
51
|
-
[
|
|
52
|
-
202,
|
|
53
|
-
254,
|
|
54
|
-
186,
|
|
55
|
-
190
|
|
56
|
-
],
|
|
57
|
-
[
|
|
58
|
-
190,
|
|
59
|
-
186,
|
|
60
|
-
254,
|
|
61
|
-
202
|
|
62
|
-
],
|
|
63
|
-
[
|
|
64
|
-
202,
|
|
65
|
-
254,
|
|
66
|
-
186,
|
|
67
|
-
191
|
|
68
|
-
],
|
|
69
|
-
[
|
|
70
|
-
191,
|
|
71
|
-
186,
|
|
72
|
-
254,
|
|
73
|
-
202
|
|
74
|
-
]
|
|
75
|
-
].some((magic) => magic.every((byte, index) => bytes[index] === byte));
|
|
76
|
-
if (!elf && !macho) throw new Error(`Executable has no interpreter: ${path}`);
|
|
77
|
-
} else {
|
|
78
|
-
const header = bytes.toString("utf8");
|
|
79
|
-
const parts = header.slice(2, header.indexOf("\n") < 0 ? void 0 : header.indexOf("\n")).trim().split(/\s+/).filter(Boolean);
|
|
80
|
-
const interpreter = parts[0] === "/usr/bin/env" || parts[0] === "/bin/env" ? parts.slice(1).find((part) => !part.startsWith("-") && !/^[A-Za-z_][A-Za-z0-9_]*=/.test(part)) : parts[0];
|
|
81
|
-
if (!interpreter) throw new Error(`Executable has no interpreter: ${path}`);
|
|
82
|
-
await resolveExecutable(interpreter);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
async function resolveExecutable(program) {
|
|
87
|
-
if (isAbsolute(program) || program.includes("/") || program.includes("\\")) {
|
|
88
|
-
await validateExecutable(program);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const path = process.env.PATH ?? "";
|
|
92
|
-
const extensions = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").some((extension) => program.toLowerCase().endsWith(extension.toLowerCase())) ? [""] : ["", ...(process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";")] : [""];
|
|
93
|
-
for (const directory of path.split(delimiter)) for (const extension of extensions) {
|
|
94
|
-
const candidate = join(directory || ".", `${program}${extension}`);
|
|
95
|
-
try {
|
|
96
|
-
await access(candidate, constants.X_OK);
|
|
97
|
-
} catch {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
await validateExecutable(candidate);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
throw new Error(`Executable not found: ${program}`);
|
|
104
|
-
}
|
|
105
|
-
/** Cached host prerequisites. Failed checks recover without restarting webhook intake. */
|
|
106
|
-
function createBabysitterPreflight(install, checkCommand = async (program, probe = "version") => {
|
|
107
|
-
if (probe === "path") await resolveExecutable(program);
|
|
108
|
-
else await execute(program, ["--version"], {
|
|
109
|
-
timeout: 5e3,
|
|
110
|
-
maxBuffer: 65536
|
|
111
|
-
});
|
|
112
|
-
}) {
|
|
113
|
-
let cached;
|
|
114
|
-
let expiresAt = 0;
|
|
115
|
-
let pending;
|
|
116
|
-
return async () => {
|
|
117
|
-
if (cached && Date.now() < expiresAt) return cached;
|
|
118
|
-
pending ??= (async () => {
|
|
119
|
-
const diagnostics = [];
|
|
120
|
-
const commands = ["git"];
|
|
121
|
-
if (install !== false) {
|
|
122
|
-
const installer = (isRuntimeRecord(install) ? install.command : void 0) ?? "corepack";
|
|
123
|
-
if (installer) {
|
|
124
|
-
if ((isAbsolute(installer) || !installer.includes("/") && !installer.includes("\\")) && !commands.includes(installer)) commands.push(installer);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
for (const program of commands) try {
|
|
128
|
-
await checkCommand(program, program === "git" || program === "corepack" ? "version" : "path");
|
|
129
|
-
diagnostics.push({
|
|
130
|
-
label: `Host ${program}`,
|
|
131
|
-
status: "ok",
|
|
132
|
-
value: "Available"
|
|
133
|
-
});
|
|
134
|
-
} catch {
|
|
135
|
-
const display = program === "git" ? "Git" : program === "corepack" ? "Corepack" : program;
|
|
136
|
-
diagnostics.push({
|
|
137
|
-
label: `Host ${program}`,
|
|
138
|
-
status: "warning",
|
|
139
|
-
value: "Unavailable",
|
|
140
|
-
detail: `Install ${display} in the trusted host service PATH. Model passes wait until this check succeeds.`
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
const failures = diagnostics.filter((item) => item.status === "warning");
|
|
144
|
-
const result = {
|
|
145
|
-
checkedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
146
|
-
diagnostics
|
|
147
|
-
};
|
|
148
|
-
if (failures.length) result.pause = {
|
|
149
|
-
reason: "host-prerequisite",
|
|
150
|
-
detail: failures.map((item) => item.detail).join(" "),
|
|
151
|
-
retryAt: Date.now() + 3e4
|
|
152
|
-
};
|
|
153
|
-
cached = result;
|
|
154
|
-
expiresAt = Date.now() + (failures.length ? 3e4 : 3e5);
|
|
155
|
-
return result;
|
|
156
|
-
})();
|
|
157
|
-
try {
|
|
158
|
-
return await pending;
|
|
159
|
-
} finally {
|
|
160
|
-
pending = void 0;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region src/babysitter/queue-health.ts
|
|
166
|
-
/** Derive bounded operational counters from the durable queue, including scheduled retries. */
|
|
167
|
-
function babysitterQueueHealth(items, now = Date.now()) {
|
|
168
|
-
const mergedTerminal = (result) => result?.startsWith("Merged ") || result === "Asynchronous merge confirmed by GitHub." || result === "Direct merge outcome reconciled: GitHub reports the pull request merged.";
|
|
169
|
-
const ready = items.filter((item) => item.status === "ready" && item.dirty && !item.stackBlocked && item.nextAt <= now);
|
|
170
|
-
const waiting = items.filter((item) => item.status === "waiting");
|
|
171
|
-
return {
|
|
172
|
-
working: items.filter((item) => item.status === "working").length,
|
|
173
|
-
ready: ready.length,
|
|
174
|
-
scheduled: items.filter((item) => item.status === "ready" && item.dirty && !item.stackBlocked && item.nextAt > now).length,
|
|
175
|
-
stackBlocked: items.filter((item) => item.stackBlocked).length,
|
|
176
|
-
waiting: waiting.length,
|
|
177
|
-
suppressed: items.filter((item) => item.status === "terminal" && item.state === "open" && !mergedTerminal(item.lastResult)).length,
|
|
178
|
-
oldestReadyAgeMs: ready.reduce((age, item) => Math.max(age, item.dirtyAt === void 0 ? 0 : now - item.dirtyAt), 0),
|
|
179
|
-
blockers: {
|
|
180
|
-
checks: waiting.filter((item) => item.wait && item.wait.kind !== "external" && !item.wait.wake).length,
|
|
181
|
-
dependency: waiting.filter((item) => item.wait?.wake).length,
|
|
182
|
-
manual: waiting.filter((item) => item.wait?.kind === "external" && !item.wait.wake && item.wait.retryAt === void 0).length,
|
|
183
|
-
timed: waiting.filter((item) => item.wait?.retryAt !== void 0).length,
|
|
184
|
-
installCapacity: waiting.filter((item) => item.wait?.reasonCode === "install-capacity").length,
|
|
185
|
-
noProgress: waiting.filter((item) => item.progressBudget?.exhausted && item.progressBudget.head === item.head).length
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
//#endregion
|
|
190
|
-
//#region src/babysitter/host.ts
|
|
191
|
-
/** Reads a plain or sealed Server Env value. */
|
|
192
|
-
function envString(value) {
|
|
193
|
-
const plain = isRuntimeRecord(value) && hasRuntimeType(value.unseal, "function") ? value.unseal() : value;
|
|
194
|
-
if (hasRuntimeType(plain, "number")) return String(plain);
|
|
195
|
-
return hasRuntimeType(plain, "string") && plain.trim() ? plain.trim() : void 0;
|
|
196
|
-
}
|
|
197
|
-
/** Accept PEM secrets from systemd and dotenv files that encode newlines as `\\n`. */
|
|
198
|
-
function normalizePrivateKey(value) {
|
|
199
|
-
return value?.replace(/\\n/g, "\n");
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Remove the persistent checkout pool created by older Babysitter releases.
|
|
203
|
-
*
|
|
204
|
-
* Current GitHub hosts use a disposable checkout for each pass. The old pool
|
|
205
|
-
* retained merged and closed PR workspaces, including installed dependencies,
|
|
206
|
-
* under the owning process host data directory; remove that pool as one unit.
|
|
207
|
-
*/
|
|
208
|
-
async function cleanupLegacyBabysitterCheckouts(dataDir) {
|
|
209
|
-
const root = join(dataDir, "checkouts");
|
|
210
|
-
const info = await lstat(root, { bigint: true }).catch((error) => {
|
|
211
|
-
if (error.code === "ENOENT") return void 0;
|
|
212
|
-
throw error;
|
|
213
|
-
});
|
|
214
|
-
if (!info) return 0;
|
|
215
|
-
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error(`[vitehub] Refusing to clean unsafe Babysitter checkout pool: ${root}`);
|
|
216
|
-
const quarantine = await mkdtemp(join(dataDir, ".checkouts-cleanup-"));
|
|
217
|
-
const claimed = join(quarantine, "checkouts");
|
|
218
|
-
await rename(root, claimed);
|
|
219
|
-
const claimedInfo = await lstat(claimed, { bigint: true });
|
|
220
|
-
if (!claimedInfo.isDirectory() || claimedInfo.dev !== info.dev || claimedInfo.ino !== info.ino) throw new Error(`[vitehub] Refusing to clean replaced Babysitter checkout pool: ${claimed}`);
|
|
221
|
-
const entries = await readdir(claimed, { withFileTypes: true });
|
|
222
|
-
await promisify(execFile)(process.execPath, [
|
|
223
|
-
"--input-type=module",
|
|
224
|
-
"--eval",
|
|
225
|
-
`
|
|
226
|
-
import { lstat, readdir, rm } from "node:fs/promises";
|
|
227
|
-
const info = await lstat(".", { bigint: true });
|
|
228
|
-
if (String(info.dev) !== process.argv[1] || String(info.ino) !== process.argv[2]) {
|
|
229
|
-
throw new Error("Refusing to clean replaced Babysitter checkout pool");
|
|
230
|
-
}
|
|
231
|
-
for (const entry of await readdir(".")) {
|
|
232
|
-
await rm(entry, { force: true, recursive: true, maxRetries: 5, retryDelay: 100 });
|
|
233
|
-
}
|
|
234
|
-
`,
|
|
235
|
-
String(info.dev),
|
|
236
|
-
String(info.ino)
|
|
237
|
-
], { cwd: claimed });
|
|
238
|
-
const remaining = await lstat(claimed, { bigint: true });
|
|
239
|
-
if (remaining.dev !== info.dev || remaining.ino !== info.ino) throw new Error(`[vitehub] Refusing to clean replaced Babysitter checkout pool: ${claimed}`);
|
|
240
|
-
return entries.length;
|
|
241
|
-
}
|
|
242
|
-
/** GitHub App settings from `env.server.github` or the VITEHUB_GITHUB_* variables. */
|
|
243
|
-
async function readGitHubAppEnvironment(context = {}) {
|
|
244
|
-
const env = await channelEnv("github", context);
|
|
245
|
-
const appId = Number(envString(env.appId));
|
|
246
|
-
const keyPath = envString(env.privateKeyPath);
|
|
247
|
-
const privateKey = normalizePrivateKey(envString(env.privateKey) ?? (keyPath ? (await readFile(keyPath, "utf8")).trim() : void 0));
|
|
248
|
-
const installation = envString(env.installationId);
|
|
249
|
-
if (!Number.isSafeInteger(appId) || appId <= 0 || !privateKey) throw new Error("[vitehub] The Babysitter needs a GitHub App: set VITEHUB_GITHUB_APP_ID and VITEHUB_GITHUB_PRIVATE_KEY (or VITEHUB_GITHUB_PRIVATE_KEY_PATH).");
|
|
250
|
-
const app = {
|
|
251
|
-
appId,
|
|
252
|
-
privateKey
|
|
253
|
-
};
|
|
254
|
-
if (installation) app.installationId = Number(installation);
|
|
255
|
-
app.owner = envString(env.appOwner)?.toLowerCase();
|
|
256
|
-
const configuredInstallations = envString(env.appInstallations);
|
|
257
|
-
if (configuredInstallations) {
|
|
258
|
-
const mappings = JSON.parse(configuredInstallations);
|
|
259
|
-
if (!isRuntimeRecord(mappings) || Array.isArray(mappings)) throw new Error("VITEHUB_GITHUB_APP_INSTALLATIONS must be an owner-to-installation object.");
|
|
260
|
-
app.installations = Object.fromEntries(Object.entries(mappings).map(([owner, id]) => {
|
|
261
|
-
const installationId = Number(id);
|
|
262
|
-
if (!Number.isSafeInteger(installationId) || installationId <= 0) throw new Error(`Invalid GitHub installation for ${owner}.`);
|
|
263
|
-
return [owner.toLowerCase(), installationId];
|
|
264
|
-
}));
|
|
265
|
-
}
|
|
266
|
-
if (!app.owner) delete app.installationId;
|
|
267
|
-
return app;
|
|
268
|
-
}
|
|
269
|
-
/** The repositories that the PR filter allows. The Babysitter discovers open PRs only there. */
|
|
270
|
-
function babysitterRepositories(filter) {
|
|
271
|
-
const allow = isRuntimeRecord(filter) && isRuntimeRecord(filter.repository) ? filter.repository.allow : void 0;
|
|
272
|
-
const repositories = Array.isArray(allow) ? allow.filter((value) => hasRuntimeType(value, "string") && /^[\w.-]+\/[\w.-]+$/.test(value)) : [];
|
|
273
|
-
if (!repositories.length) throw new Error("[vitehub] Set options.filter.repository.allow to the \"owner/name\" repositories that the Babysitter serves.");
|
|
274
|
-
return repositories.map((repository) => repository.toLowerCase());
|
|
275
|
-
}
|
|
276
|
-
const passWorkspace = /^(?:vitehub-provider-(?:launch-|tmp-|inspection-)?[A-Za-z0-9]{6}|vitehub-baseline-[A-Za-z0-9]{6}|vitehub-[\w.-]+-pr-\d+-[A-Za-z0-9]{6}(?:\.meta\.json|\.cleanup-\d+-\d+)?|t3-provider-runtime-[A-Za-z0-9]{6})$/;
|
|
277
|
-
/**
|
|
278
|
-
* Removes pass workspaces that an interrupted process left in `root`. It sweeps only a temporary
|
|
279
|
-
* directory inside the service's working directory, which no other process shares, and keeps
|
|
280
|
-
* anything this process created.
|
|
281
|
-
*/
|
|
282
|
-
async function sweepBabysitterWorkspaces(root = tmpdir(), startedAt = performance.timeOrigin, cwd = process.cwd()) {
|
|
283
|
-
if (!resolve(root).startsWith(`${resolve(cwd)}${sep}`)) return 0;
|
|
284
|
-
let removed = 0;
|
|
285
|
-
for (const entry of await readdir(root, { withFileTypes: true }).catch(() => [])) {
|
|
286
|
-
if (!passWorkspace.test(entry.name)) continue;
|
|
287
|
-
const path = join(root, entry.name);
|
|
288
|
-
const info = await lstat(path).catch(() => void 0);
|
|
289
|
-
if (!info || info.mtimeMs >= startedAt) continue;
|
|
290
|
-
await rm(path, {
|
|
291
|
-
force: true,
|
|
292
|
-
recursive: true,
|
|
293
|
-
maxRetries: 3
|
|
294
|
-
}).then(() => removed++, () => {});
|
|
295
|
-
}
|
|
296
|
-
return removed;
|
|
297
|
-
}
|
|
298
|
-
/** Builds the GitHub host, process host, inbox, and reconciler for one discovered Babysitter Agent. */
|
|
299
|
-
async function createBabysitterProcessHost(context) {
|
|
300
|
-
const agent = context.agent;
|
|
301
|
-
const repositories = babysitterRepositories(agent.options.filter);
|
|
302
|
-
await cleanupLegacyBabysitterCheckouts(context.dataDir);
|
|
303
|
-
const app = await readGitHubAppEnvironment();
|
|
304
|
-
const credentials = createGitHubAppCredentials(app);
|
|
305
|
-
const identity = await credentials.identity();
|
|
306
|
-
const github = createGitHubHost({
|
|
307
|
-
credentials: credentials.credentials,
|
|
308
|
-
identity
|
|
309
|
-
});
|
|
310
|
-
let runtime;
|
|
311
|
-
const host = await createProcessAgentHost({
|
|
312
|
-
name: context.agentName,
|
|
313
|
-
dataDir: context.dataDir,
|
|
314
|
-
invocations: agent.invocations,
|
|
315
|
-
invocationAgentName: `${context.agentName}-worker`,
|
|
316
|
-
capacity: {
|
|
317
|
-
...agent.options.capacity,
|
|
318
|
-
...agent.options.placement?.remoteActive ? { remoteActive: () => agent.options.placement?.remoteActive?.() ?? 0 } : {},
|
|
319
|
-
concurrency: agent.options.concurrency,
|
|
320
|
-
queue: {
|
|
321
|
-
maxPending: agent.options.concurrency,
|
|
322
|
-
timeout: 36e5
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
intervalMs: 1e4,
|
|
326
|
-
run: async (reason, run, accepting) => await runtime?.reconcile(reason, run, accepting)
|
|
327
|
-
});
|
|
328
|
-
const preflight = createBabysitterPreflight(agent.options.install ?? true);
|
|
329
|
-
const buildRevision = "6c9df4004457f5ecbb5c864a1de27e4864828d9125592c9c89c99bd88fc810b2";
|
|
330
|
-
const admission = createBabysitterAdmission({
|
|
331
|
-
invocations: host.invocations,
|
|
332
|
-
limits: resolveBabysitterAdmissionLimits(agent.options.admission),
|
|
333
|
-
check: async () => (await preflight()).pause ?? await agent.options.admission?.check?.()
|
|
334
|
-
});
|
|
335
|
-
let admissionPrerequisiteSample;
|
|
336
|
-
const worker = defineAgent({
|
|
337
|
-
extends: agent,
|
|
338
|
-
invocations: host.invocations,
|
|
339
|
-
driver: {
|
|
340
|
-
capacity: host.capacity,
|
|
341
|
-
sessionStorePath: host.providerSessionStorePath
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
runtime = createBabysitterRuntime({
|
|
345
|
-
agent: worker,
|
|
346
|
-
agentName: context.agentName,
|
|
347
|
-
github,
|
|
348
|
-
inboxStorage: context.state.extension("babysitter"),
|
|
349
|
-
inboxScope: context.agentName,
|
|
350
|
-
repositories,
|
|
351
|
-
concurrency: agent.options.concurrency,
|
|
352
|
-
activityAuthors: [identity.login],
|
|
353
|
-
event: host.event,
|
|
354
|
-
error: host.error,
|
|
355
|
-
wake: () => host.wake(),
|
|
356
|
-
admission
|
|
357
|
-
});
|
|
358
|
-
const inbox = runtime.inbox;
|
|
359
|
-
const swept = await sweepBabysitterWorkspaces();
|
|
360
|
-
return {
|
|
361
|
-
start() {
|
|
362
|
-
registerAgentProcessHostIntake(context.agentName, async ({ deliveryId, event, payload }) => {
|
|
363
|
-
const result = await inbox.ingest(deliveryId, event, payload);
|
|
364
|
-
if (result.updated.length) host.wake("webhook");
|
|
365
|
-
return Response.json(result, { status: 202 });
|
|
366
|
-
});
|
|
367
|
-
inbox.importLegacyFile(".vitehub/pull-request-inbox.sqlite").catch((error) => host.error("babysitter.legacy-import.failed", error)).then(() => inbox.releaseLeases()).then((released) => {
|
|
368
|
-
if (released) host.event("babysitter.leases.released", { released });
|
|
369
|
-
}, (error) => host.error("babysitter.leases.release-failed", error)).finally(() => {
|
|
370
|
-
if (swept) host.event("babysitter.workspaces.swept", { removed: swept });
|
|
371
|
-
host.start();
|
|
372
|
-
});
|
|
373
|
-
},
|
|
374
|
-
async close() {
|
|
375
|
-
registerAgentProcessHostIntake(context.agentName, void 0);
|
|
376
|
-
await host.close();
|
|
377
|
-
await inbox.close();
|
|
378
|
-
},
|
|
379
|
-
wake: (reason) => host.wake(reason),
|
|
380
|
-
status: () => host.status(),
|
|
381
|
-
async health() {
|
|
382
|
-
const health = await host.health();
|
|
383
|
-
const queue = await inbox.summary();
|
|
384
|
-
const prerequisites = await preflight();
|
|
385
|
-
if (admissionPrerequisiteSample !== prerequisites.checkedAt) {
|
|
386
|
-
admissionPrerequisiteSample = prerequisites.checkedAt;
|
|
387
|
-
admission.invalidate();
|
|
388
|
-
}
|
|
389
|
-
const guard = await admission.health();
|
|
390
|
-
const lastSkip = await inbox.meta("admission-skipped");
|
|
391
|
-
return {
|
|
392
|
-
...health,
|
|
393
|
-
status: prerequisites.pause ? "degraded" : health.status,
|
|
394
|
-
diagnostics: [...health.diagnostics, ...prerequisites.diagnostics],
|
|
395
|
-
release: agent.version,
|
|
396
|
-
framework: { buildRevision },
|
|
397
|
-
concurrency: agent.options.concurrency,
|
|
398
|
-
repositories,
|
|
399
|
-
queue: {
|
|
400
|
-
...babysitterQueueHealth(queue),
|
|
401
|
-
parked: budgetParks(queue)
|
|
402
|
-
},
|
|
403
|
-
admission: {
|
|
404
|
-
accepting: guard.accepting,
|
|
405
|
-
hostOnly: guard.hostOnly,
|
|
406
|
-
reason: guard.reason,
|
|
407
|
-
retryAt: guard.retryAt,
|
|
408
|
-
detail: guard.detail,
|
|
409
|
-
lastSkip,
|
|
410
|
-
history: { lastSkip }
|
|
411
|
-
},
|
|
412
|
-
budget: {
|
|
413
|
-
accounting: guard.accounting,
|
|
414
|
-
observedAt: new Date(guard.observedAt).toISOString(),
|
|
415
|
-
hourly: {
|
|
416
|
-
inputTokens: guard.state.hourlyInputTokens,
|
|
417
|
-
limit: guard.limits.hourlyInputTokens,
|
|
418
|
-
resetsAt: guard.state.windows.hourEnd
|
|
419
|
-
},
|
|
420
|
-
daily: {
|
|
421
|
-
inputTokens: guard.state.dailyInputTokens,
|
|
422
|
-
limit: guard.limits.dailyInputTokens,
|
|
423
|
-
resetsAt: guard.state.windows.dayEnd
|
|
424
|
-
},
|
|
425
|
-
tmp: {
|
|
426
|
-
dir: guard.state.tmpDir,
|
|
427
|
-
freeBytes: guard.state.freeTmpBytes,
|
|
428
|
-
minFreeBytes: guard.limits.minFreeTmpBytes
|
|
429
|
-
},
|
|
430
|
-
pause: guard.state.pause,
|
|
431
|
-
errors: guard.state.errors
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
//#endregion
|
|
438
|
-
export { createBabysitterProcessHost };
|