@aspectlylabs/mikka 0.0.723 → 0.0.741
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/cli.js +834 -739
- package/client.js +2 -2
- package/http-link.js +2 -2
- package/login.js +2 -2
- package/main.js +585 -535
- package/mikka-release-manifest.json +20 -20
- package/mikka.js +834 -739
- package/npm-shrinkwrap.json +8 -8
- package/package.json +3 -3
- package/paths.js +2 -2
- package/sbom.cdx.json +23 -23
package/mikka.js
CHANGED
|
@@ -2063,7 +2063,7 @@ function readJson(file) {
|
|
|
2063
2063
|
}
|
|
2064
2064
|
|
|
2065
2065
|
// src/lock.ts
|
|
2066
|
-
import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, rmSync } from "node:fs";
|
|
2066
|
+
import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, rmSync } from "node:fs";
|
|
2067
2067
|
import { createConnection } from "node:net";
|
|
2068
2068
|
import { join } from "node:path";
|
|
2069
2069
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
@@ -2134,16 +2134,18 @@ async function acquireLock(dataDir, lockfilePath, onCompromised = () => void 0,
|
|
|
2134
2134
|
};
|
|
2135
2135
|
const deadline = Date.now() + (options.takeoverMs ?? LOCK_TAKEOVER_MS);
|
|
2136
2136
|
for (; ; ) {
|
|
2137
|
-
try {
|
|
2138
|
-
return await lock();
|
|
2139
|
-
} catch (error) {
|
|
2140
|
-
if (error.code !== "ELOCKED") throw error;
|
|
2141
|
-
}
|
|
2142
2137
|
if (options.socketPath && await socketAnswers(options.socketPath)) {
|
|
2143
2138
|
throw new DaemonAlreadyRunningError(dataDir);
|
|
2144
2139
|
}
|
|
2145
2140
|
const pid = holderPid(dataDir);
|
|
2146
2141
|
const crashed = pid !== null && pid !== process.pid && !processAlive(pid);
|
|
2142
|
+
if (pid === null || crashed || !existsSync(lockfilePath)) {
|
|
2143
|
+
try {
|
|
2144
|
+
return await lock();
|
|
2145
|
+
} catch (error) {
|
|
2146
|
+
if (error.code !== "ELOCKED") throw error;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2147
2149
|
if (crashed || pid === null && Date.now() >= deadline) {
|
|
2148
2150
|
rmSync(lockfilePath, { recursive: true, force: true });
|
|
2149
2151
|
try {
|
|
@@ -2219,11 +2221,49 @@ function closeLogger(logger) {
|
|
|
2219
2221
|
return new Promise((resolve20) => file.end(resolve20));
|
|
2220
2222
|
}
|
|
2221
2223
|
|
|
2224
|
+
// src/lifecycle-record.ts
|
|
2225
|
+
import { join as join2 } from "node:path";
|
|
2226
|
+
var LIFECYCLE_FILE = "lifecycle.json";
|
|
2227
|
+
function trackDaemonLifecycle(logsDir, proc = process, now = () => /* @__PURE__ */ new Date()) {
|
|
2228
|
+
const file = join2(logsDir, LIFECYCLE_FILE);
|
|
2229
|
+
const startedAt = now().toISOString();
|
|
2230
|
+
let reason, error, owned = true;
|
|
2231
|
+
const write = (phase, code) => {
|
|
2232
|
+
if (!owned) return;
|
|
2233
|
+
const record3 = { phase, pid: proc.pid, startedAt, ...reason ? { reason } : {}, ...error ? { error } : {}, ...code === void 0 ? {} : { code }, at: now().toISOString() };
|
|
2234
|
+
try {
|
|
2235
|
+
writeJsonAtomic(file, record3);
|
|
2236
|
+
} catch {
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
write("running");
|
|
2240
|
+
proc.on("uncaughtExceptionMonitor", (thrown, origin) => {
|
|
2241
|
+
reason ??= origin;
|
|
2242
|
+
if (error) return;
|
|
2243
|
+
const code = thrown?.code;
|
|
2244
|
+
error = { name: thrown instanceof Error ? thrown.name : typeof thrown, ...typeof code === "string" ? { code } : {} };
|
|
2245
|
+
});
|
|
2246
|
+
proc.once("exit", (code) => {
|
|
2247
|
+
reason ??= "exit";
|
|
2248
|
+
write("exited", code);
|
|
2249
|
+
});
|
|
2250
|
+
return {
|
|
2251
|
+
stopping(why) {
|
|
2252
|
+
reason ??= why;
|
|
2253
|
+
write("stopping");
|
|
2254
|
+
},
|
|
2255
|
+
/** Another daemon took the data dir; the record is its to write from now on. */
|
|
2256
|
+
disown() {
|
|
2257
|
+
owned = false;
|
|
2258
|
+
}
|
|
2259
|
+
};
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2222
2262
|
// src/auto-update.ts
|
|
2223
2263
|
import { execFile } from "node:child_process";
|
|
2224
2264
|
import { realpathSync } from "node:fs";
|
|
2225
2265
|
import { homedir } from "node:os";
|
|
2226
|
-
import { dirname as dirname2, join as
|
|
2266
|
+
import { dirname as dirname2, join as join3, resolve } from "node:path";
|
|
2227
2267
|
import { promisify } from "node:util";
|
|
2228
2268
|
var exec = promisify(execFile);
|
|
2229
2269
|
var PACKAGE = "@aspectlylabs/mikka";
|
|
@@ -2235,11 +2275,11 @@ function newerStableVersion(candidate, current) {
|
|
|
2235
2275
|
return false;
|
|
2236
2276
|
}
|
|
2237
2277
|
function serviceNpmEnvironment(entry, home, env) {
|
|
2238
|
-
const prefix =
|
|
2239
|
-
return resolve(entry) ===
|
|
2278
|
+
const prefix = join3(home, ".mikka/npm");
|
|
2279
|
+
return resolve(entry) === join3(prefix, "lib/node_modules/@aspectlylabs/mikka/mikka.js") ? { ...env, npm_config_prefix: prefix, npm_config_cache: join3(home, ".mikka/npm-cache") } : env;
|
|
2240
2280
|
}
|
|
2241
2281
|
async function runServiceNpm(args) {
|
|
2242
|
-
const npm = realpathSync(
|
|
2282
|
+
const npm = realpathSync(join3(dirname2(process.execPath), "npm"));
|
|
2243
2283
|
const { stdout } = await exec(process.execPath, [npm, ...args], {
|
|
2244
2284
|
cwd: homedir(),
|
|
2245
2285
|
timeout: 3e5,
|
|
@@ -2254,10 +2294,10 @@ async function managedAutoUpdateRuntime(entry, flavor, enabled) {
|
|
|
2254
2294
|
try {
|
|
2255
2295
|
const file = realpathSync(resolve(entry));
|
|
2256
2296
|
const root = dirname2(file);
|
|
2257
|
-
const pkg = readJson(
|
|
2297
|
+
const pkg = readJson(join3(root, "package.json"));
|
|
2258
2298
|
if (pkg?.name !== PACKAGE || pkg.private !== false) return;
|
|
2259
2299
|
const globalRoot = await runServiceNpm(["root", "--global"]);
|
|
2260
|
-
if (realpathSync(
|
|
2300
|
+
if (realpathSync(join3(globalRoot, PACKAGE)) !== root || file !== join3(root, "mikka.js")) return;
|
|
2261
2301
|
return {
|
|
2262
2302
|
install: async (version) => {
|
|
2263
2303
|
await runServiceNpm(["install", "--global", "--engine-strict", `${PACKAGE}@${version}`]);
|
|
@@ -2293,7 +2333,7 @@ import { execFile as execFile2 } from "node:child_process";
|
|
|
2293
2333
|
import { promisify as promisify2 } from "node:util";
|
|
2294
2334
|
import { mkdir, readFile, writeFile, rm } from "node:fs/promises";
|
|
2295
2335
|
import { homedir as homedir2 } from "node:os";
|
|
2296
|
-
import { dirname as dirname3, join as
|
|
2336
|
+
import { dirname as dirname3, join as join4, resolve as resolve2 } from "node:path";
|
|
2297
2337
|
var exec2 = promisify2(execFile2);
|
|
2298
2338
|
var label = "com.aspectlylabs.mikka.daemon";
|
|
2299
2339
|
var xml = (s) => s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
@@ -2321,7 +2361,7 @@ WantedBy=default.target
|
|
|
2321
2361
|
if (input.platform !== "darwin") throw new Error("Services require Linux or macOS");
|
|
2322
2362
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
2323
2363
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
2324
|
-
<plist version="1.0"><dict><key>Label</key><string>${label}</string><key>ProgramArguments</key><array>${args.map((arg) => `<string>${xml(arg)}</string>`).join("")}</array><key>RunAtLoad</key><true/><key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict><key>EnvironmentVariables</key><dict><key>PATH</key><string>${xml(input.path)}</string><key>MIKKA_SERVICE</key><string>launchd</string><key>MIKKA_DEVICE_TYPE</key><string>${input.deviceType === "server" ? "server" : "laptop"}</string></dict><key>StandardErrorPath</key><string>${xml(
|
|
2364
|
+
<plist version="1.0"><dict><key>Label</key><string>${label}</string><key>ProgramArguments</key><array>${args.map((arg) => `<string>${xml(arg)}</string>`).join("")}</array><key>RunAtLoad</key><true/><key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict><key>EnvironmentVariables</key><dict><key>PATH</key><string>${xml(input.path)}</string><key>MIKKA_SERVICE</key><string>launchd</string><key>MIKKA_DEVICE_TYPE</key><string>${input.deviceType === "server" ? "server" : "laptop"}</string></dict><key>StandardErrorPath</key><string>${xml(join4(input.home, "Library/Logs/mikka-daemon.log"))}</string></dict></plist>
|
|
2325
2365
|
`;
|
|
2326
2366
|
}
|
|
2327
2367
|
async function installService(server, deviceType = "server", options = {}) {
|
|
@@ -2330,7 +2370,7 @@ async function installService(server, deviceType = "server", options = {}) {
|
|
|
2330
2370
|
const home = homedir2();
|
|
2331
2371
|
const content = serviceDefinition({ platform: process.platform, node: process.execPath, entry: resolve2(process.argv[1]), server, home, path: process.env.PATH ?? "/usr/local/bin:/usr/bin:/bin", deviceType, ...options });
|
|
2332
2372
|
if (process.platform === "linux") {
|
|
2333
|
-
const file =
|
|
2373
|
+
const file = join4(home, ".config/systemd/user/mikka-daemon.service");
|
|
2334
2374
|
await mkdir(dirname3(file), { recursive: true, mode: 448 });
|
|
2335
2375
|
await writeFile(file, content, { mode: 384 });
|
|
2336
2376
|
await exec2("loginctl", ["enable-linger"], { timeout: 1e4 }).catch(() => void 0);
|
|
@@ -2338,9 +2378,9 @@ async function installService(server, deviceType = "server", options = {}) {
|
|
|
2338
2378
|
await exec2("systemctl", ["--user", "enable", "mikka-daemon.service"]);
|
|
2339
2379
|
await exec2("systemctl", ["--user", "restart", "mikka-daemon.service"]);
|
|
2340
2380
|
} else {
|
|
2341
|
-
const file =
|
|
2381
|
+
const file = join4(home, "Library/LaunchAgents", `${label}.plist`);
|
|
2342
2382
|
await mkdir(dirname3(file), { recursive: true, mode: 448 });
|
|
2343
|
-
await mkdir(
|
|
2383
|
+
await mkdir(join4(home, "Library/Logs"), { recursive: true });
|
|
2344
2384
|
const domain = `gui/${process.getuid()}`;
|
|
2345
2385
|
await installLaunchAgent(domain, file, content);
|
|
2346
2386
|
}
|
|
@@ -2403,10 +2443,10 @@ async function uninstallService(clearCredential, dependencies = {
|
|
|
2403
2443
|
try {
|
|
2404
2444
|
if (dependencies.manager === "systemd") {
|
|
2405
2445
|
await dependencies.run("systemctl", ["--user", "disable", "mikka-daemon.service"]);
|
|
2406
|
-
await rm(
|
|
2446
|
+
await rm(join4(dependencies.home, ".config/systemd/user/mikka-daemon.service"), { force: true });
|
|
2407
2447
|
await dependencies.run("systemctl", ["--user", "daemon-reload"]);
|
|
2408
2448
|
} else if (dependencies.manager === "launchd") {
|
|
2409
|
-
await rm(
|
|
2449
|
+
await rm(join4(dependencies.home, "Library/LaunchAgents", `${label}.plist`), { force: true });
|
|
2410
2450
|
}
|
|
2411
2451
|
} finally {
|
|
2412
2452
|
clearCredential();
|
|
@@ -6598,14 +6638,14 @@ function isNonRetryable(error) {
|
|
|
6598
6638
|
}
|
|
6599
6639
|
|
|
6600
6640
|
// src/paths.ts
|
|
6601
|
-
import { existsSync } from "node:fs";
|
|
6641
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
6602
6642
|
import { homedir as homedir3 } from "node:os";
|
|
6603
|
-
import { join as
|
|
6643
|
+
import { join as join5 } from "node:path";
|
|
6604
6644
|
|
|
6605
6645
|
// package.json
|
|
6606
6646
|
var package_default = {
|
|
6607
6647
|
name: "@mikka/daemon",
|
|
6608
|
-
version: "0.0.
|
|
6648
|
+
version: "0.0.741",
|
|
6609
6649
|
description: "Local Mikka daemon: runs agents through the user's own CLIs",
|
|
6610
6650
|
type: "module",
|
|
6611
6651
|
private: true,
|
|
@@ -6673,7 +6713,7 @@ var package_default = {
|
|
|
6673
6713
|
engines: {
|
|
6674
6714
|
node: ">=22"
|
|
6675
6715
|
},
|
|
6676
|
-
gitHead: "
|
|
6716
|
+
gitHead: "0b7e13795e13a5539bc161e1a78750bd47bb09b4"
|
|
6677
6717
|
};
|
|
6678
6718
|
|
|
6679
6719
|
// src/paths.ts
|
|
@@ -6686,10 +6726,10 @@ function defaultDataDir(flavor, env = process.env, platform4 = process.platform)
|
|
|
6686
6726
|
return env.MIKKA_USER_DATA_DIR;
|
|
6687
6727
|
}
|
|
6688
6728
|
const home = env.HOME || homedir3();
|
|
6689
|
-
const base = platform4 === "darwin" ?
|
|
6690
|
-
const dir =
|
|
6691
|
-
const legacy =
|
|
6692
|
-
return !
|
|
6729
|
+
const base = platform4 === "darwin" ? join5(home, "Library", "Application Support") : platform4 === "win32" ? env.APPDATA || join5(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME || join5(home, ".config");
|
|
6730
|
+
const dir = join5(base, productName(flavor));
|
|
6731
|
+
const legacy = join5(base, legacyProductName(flavor));
|
|
6732
|
+
return !existsSync2(dir) && existsSync2(legacy) ? legacy : dir;
|
|
6693
6733
|
}
|
|
6694
6734
|
function legacyProductName(flavor) {
|
|
6695
6735
|
return flavor === "dev" ? "Orvilo Dev" : "Orvilo";
|
|
@@ -6697,19 +6737,19 @@ function legacyProductName(flavor) {
|
|
|
6697
6737
|
function daemonPaths(dataDir) {
|
|
6698
6738
|
return {
|
|
6699
6739
|
dataDir,
|
|
6700
|
-
socket:
|
|
6701
|
-
lock:
|
|
6702
|
-
secret:
|
|
6703
|
-
device:
|
|
6704
|
-
journal:
|
|
6705
|
-
outbox:
|
|
6706
|
-
worktrees:
|
|
6707
|
-
repos:
|
|
6708
|
-
adapterState:
|
|
6740
|
+
socket: join5(dataDir, "daemon.sock"),
|
|
6741
|
+
lock: join5(dataDir, "daemon.lock"),
|
|
6742
|
+
secret: join5(dataDir, "daemon.secret"),
|
|
6743
|
+
device: join5(dataDir, "device.json"),
|
|
6744
|
+
journal: join5(dataDir, "runs.json"),
|
|
6745
|
+
outbox: join5(dataDir, "outbox"),
|
|
6746
|
+
worktrees: join5(dataDir, "worktrees"),
|
|
6747
|
+
repos: join5(dataDir, "repos"),
|
|
6748
|
+
adapterState: join5(dataDir, "adapters"),
|
|
6709
6749
|
/** Pinned Claude Code and Codex the daemon installs for its runs. */
|
|
6710
|
-
harness:
|
|
6711
|
-
logs:
|
|
6712
|
-
devRepos:
|
|
6750
|
+
harness: join5(dataDir, "harness"),
|
|
6751
|
+
logs: join5(dataDir, "logs"),
|
|
6752
|
+
devRepos: join5(dataDir, "dev-repos.json")
|
|
6713
6753
|
};
|
|
6714
6754
|
}
|
|
6715
6755
|
|
|
@@ -7275,7 +7315,7 @@ async function createRunMailbox(host) {
|
|
|
7275
7315
|
// src/run-drive.ts
|
|
7276
7316
|
import { createHash as createHash3 } from "node:crypto";
|
|
7277
7317
|
import { lstat, mkdir as mkdir2, readFile as readFile2, readdir, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
7278
|
-
import { dirname as dirname4, extname, join as
|
|
7318
|
+
import { dirname as dirname4, extname, join as join6, relative, resolve as resolve3, sep } from "node:path";
|
|
7279
7319
|
import { z as z35 } from "zod";
|
|
7280
7320
|
var READ_LIMIT = 1024 * 1024;
|
|
7281
7321
|
var WRITE_LIMIT = 4 * 1024 * 1024;
|
|
@@ -7301,7 +7341,7 @@ async function walk(folder) {
|
|
|
7301
7341
|
const visit = async (dir) => {
|
|
7302
7342
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
7303
7343
|
if (found.length >= MAX_FILES) return;
|
|
7304
|
-
const full =
|
|
7344
|
+
const full = join6(dir, entry.name);
|
|
7305
7345
|
if (entry.isSymbolicLink()) continue;
|
|
7306
7346
|
if (entry.isDirectory()) await visit(full);
|
|
7307
7347
|
else if (entry.isFile()) found.push(relative(folder, full).split(sep).join("/"));
|
|
@@ -7316,8 +7356,8 @@ function createDriveMirror(options) {
|
|
|
7316
7356
|
const { root, runId, call } = options;
|
|
7317
7357
|
const warn = options.warn ?? (() => {
|
|
7318
7358
|
});
|
|
7319
|
-
const folderOf = (scope) =>
|
|
7320
|
-
const stateFile = (scope) =>
|
|
7359
|
+
const folderOf = (scope) => join6(root, scope.scope, scope.scopeId);
|
|
7360
|
+
const stateFile = (scope) => join6(root, STATE_DIR, `${scope.scope}-${scope.scopeId}.json`);
|
|
7321
7361
|
const target = (scope) => ({ scope: scope.scope, scopeId: scope.scopeId });
|
|
7322
7362
|
const readState2 = async (scope) => {
|
|
7323
7363
|
try {
|
|
@@ -7327,7 +7367,7 @@ function createDriveMirror(options) {
|
|
|
7327
7367
|
}
|
|
7328
7368
|
};
|
|
7329
7369
|
const saveState = async (scope, state2) => {
|
|
7330
|
-
await mkdir2(
|
|
7370
|
+
await mkdir2(join6(root, STATE_DIR), { recursive: true, mode: 448 });
|
|
7331
7371
|
await writeFile2(stateFile(scope), JSON.stringify(state2), { mode: 384 });
|
|
7332
7372
|
};
|
|
7333
7373
|
const list = async (scope, volumeId) => {
|
|
@@ -9313,14 +9353,14 @@ async function registrationLogin(options) {
|
|
|
9313
9353
|
import { randomBytes as randomBytes6, randomUUID as randomUUID10 } from "node:crypto";
|
|
9314
9354
|
import {
|
|
9315
9355
|
chmodSync as chmodSync3,
|
|
9316
|
-
existsSync as
|
|
9356
|
+
existsSync as existsSync10,
|
|
9317
9357
|
mkdirSync as mkdirSync19,
|
|
9318
9358
|
readFileSync as readFileSync15,
|
|
9319
9359
|
rmSync as rmSync21,
|
|
9320
9360
|
realpathSync as realpathSync15
|
|
9321
9361
|
} from "node:fs";
|
|
9322
9362
|
import { arch as arch3, hostname as hostname2, platform as platform3 } from "node:os";
|
|
9323
|
-
import { join as
|
|
9363
|
+
import { join as join38 } from "node:path";
|
|
9324
9364
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
9325
9365
|
|
|
9326
9366
|
// src/runs/quota-exhausted.ts
|
|
@@ -9404,7 +9444,7 @@ function quotaStopApplies(assignment) {
|
|
|
9404
9444
|
import { spawn as spawn2 } from "node:child_process";
|
|
9405
9445
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
9406
9446
|
import { realpathSync as realpathSync10 } from "node:fs";
|
|
9407
|
-
import { join as
|
|
9447
|
+
import { join as join16 } from "node:path";
|
|
9408
9448
|
|
|
9409
9449
|
// src/adapters/generation-metrics.ts
|
|
9410
9450
|
var record2 = (value) => value && typeof value === "object" ? value : {};
|
|
@@ -9778,7 +9818,7 @@ import {
|
|
|
9778
9818
|
rmSync as rmSync2,
|
|
9779
9819
|
writeFileSync
|
|
9780
9820
|
} from "node:fs";
|
|
9781
|
-
import { join as
|
|
9821
|
+
import { join as join7 } from "node:path";
|
|
9782
9822
|
|
|
9783
9823
|
// src/credential-globs.ts
|
|
9784
9824
|
var CLOUD_WORKER_STATE_DIR = "/home/user/.mikka/worker/adapters";
|
|
@@ -9833,25 +9873,25 @@ var CODEX_CONFIG = [
|
|
|
9833
9873
|
].join("\n");
|
|
9834
9874
|
function prepareCodexHome(dir, log) {
|
|
9835
9875
|
ownDir(dir);
|
|
9836
|
-
writeOwnFile(
|
|
9837
|
-
if (lstatSync(
|
|
9876
|
+
writeOwnFile(join7(dir, "config.toml"), CODEX_CONFIG);
|
|
9877
|
+
if (lstatSync(join7(dir, "auth.json"), { throwIfNoEntry: false })) {
|
|
9838
9878
|
log.warn("removing a credential file left in the run's codex home");
|
|
9839
|
-
rmSync2(
|
|
9879
|
+
rmSync2(join7(dir, "auth.json"), { force: true, recursive: true });
|
|
9840
9880
|
}
|
|
9841
9881
|
return { home: dir };
|
|
9842
9882
|
}
|
|
9843
9883
|
function wipeRunCredentials(runDir) {
|
|
9844
|
-
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync2(
|
|
9884
|
+
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync2(join7(runDir, path3), { force: true, recursive: true });
|
|
9845
9885
|
}
|
|
9846
9886
|
function sweepRunCredentials(stateDir) {
|
|
9847
|
-
rmSync2(
|
|
9887
|
+
rmSync2(join7(stateDir, "github"), { recursive: true, force: true });
|
|
9848
9888
|
let runs;
|
|
9849
9889
|
try {
|
|
9850
|
-
runs = readdirSync(
|
|
9890
|
+
runs = readdirSync(join7(stateDir, "runs"));
|
|
9851
9891
|
} catch {
|
|
9852
9892
|
return;
|
|
9853
9893
|
}
|
|
9854
|
-
for (const run3 of runs) wipeRunCredentials(
|
|
9894
|
+
for (const run3 of runs) wipeRunCredentials(join7(stateDir, "runs", run3));
|
|
9855
9895
|
}
|
|
9856
9896
|
function writeOwnFile(file, content) {
|
|
9857
9897
|
rmSync2(file, { force: true, recursive: true });
|
|
@@ -9866,9 +9906,9 @@ function carryHistory(from, to, entries) {
|
|
|
9866
9906
|
if (!lstatSync(from, { throwIfNoEntry: false })?.isDirectory()) return;
|
|
9867
9907
|
ownDir(to);
|
|
9868
9908
|
for (const entry of entries) {
|
|
9869
|
-
const source =
|
|
9909
|
+
const source = join7(from, entry);
|
|
9870
9910
|
if (!lstatSync(source, { throwIfNoEntry: false })) continue;
|
|
9871
|
-
cpSync(source,
|
|
9911
|
+
cpSync(source, join7(to, entry), {
|
|
9872
9912
|
recursive: true,
|
|
9873
9913
|
force: true,
|
|
9874
9914
|
filter: (path3) => !lstatSync(path3).isSymbolicLink()
|
|
@@ -10062,17 +10102,17 @@ function errorMessage(error) {
|
|
|
10062
10102
|
}
|
|
10063
10103
|
|
|
10064
10104
|
// src/agents/github-runtime.ts
|
|
10065
|
-
import { existsSync as
|
|
10066
|
-
import { delimiter as delimiter2, join as
|
|
10105
|
+
import { existsSync as existsSync4, lstatSync as lstatSync4, mkdirSync as mkdirSync6, mkdtempSync as mkdtempSync2, realpathSync as realpathSync7, rmSync as rmSync6, writeFileSync as writeFileSync3 } from "node:fs";
|
|
10106
|
+
import { delimiter as delimiter2, join as join11, resolve as resolve7 } from "node:path";
|
|
10067
10107
|
import { execa as execa4 } from "execa";
|
|
10068
10108
|
|
|
10069
10109
|
// src/path-search.ts
|
|
10070
10110
|
import { accessSync, constants, statSync } from "node:fs";
|
|
10071
|
-
import { delimiter, isAbsolute, join as
|
|
10111
|
+
import { delimiter, isAbsolute, join as join8 } from "node:path";
|
|
10072
10112
|
function findOnPath(command, path3 = process.env.PATH ?? "") {
|
|
10073
10113
|
for (const directory of path3.split(delimiter)) {
|
|
10074
10114
|
if (!directory) continue;
|
|
10075
|
-
const candidate =
|
|
10115
|
+
const candidate = join8(directory, command);
|
|
10076
10116
|
try {
|
|
10077
10117
|
accessSync(candidate, constants.X_OK);
|
|
10078
10118
|
if (statSync(candidate).isFile()) return candidate;
|
|
@@ -10091,7 +10131,7 @@ import {
|
|
|
10091
10131
|
rmSync as rmSync5
|
|
10092
10132
|
} from "node:fs";
|
|
10093
10133
|
import { tmpdir } from "node:os";
|
|
10094
|
-
import { basename, dirname as dirname7, join as
|
|
10134
|
+
import { basename, dirname as dirname7, join as join10, resolve as resolve5 } from "node:path";
|
|
10095
10135
|
|
|
10096
10136
|
// src/ids.ts
|
|
10097
10137
|
var SAFE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
@@ -10150,7 +10190,7 @@ function withoutTaskEnv(assignment) {
|
|
|
10150
10190
|
import {
|
|
10151
10191
|
appendFileSync,
|
|
10152
10192
|
copyFileSync,
|
|
10153
|
-
existsSync as
|
|
10193
|
+
existsSync as existsSync3,
|
|
10154
10194
|
lstatSync as lstatSync2,
|
|
10155
10195
|
mkdirSync as mkdirSync5,
|
|
10156
10196
|
readdirSync as readdirSync2,
|
|
@@ -10159,7 +10199,7 @@ import {
|
|
|
10159
10199
|
rmSync as rmSync4
|
|
10160
10200
|
} from "node:fs";
|
|
10161
10201
|
import { lstat as lstat2, readdir as readdir2 } from "node:fs/promises";
|
|
10162
|
-
import { dirname as dirname6, isAbsolute as isAbsolute2, join as
|
|
10202
|
+
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join9, relative as relative2, resolve as resolve4 } from "node:path";
|
|
10163
10203
|
import { execa as execa2 } from "execa";
|
|
10164
10204
|
import { simpleGit } from "simple-git";
|
|
10165
10205
|
|
|
@@ -10280,7 +10320,7 @@ var WorktreeManager = class {
|
|
|
10280
10320
|
async create(runId, repoPath, baseBranch) {
|
|
10281
10321
|
await excludeVerifyArtifacts(repoPath);
|
|
10282
10322
|
const path3 = this.pathFor(runId);
|
|
10283
|
-
if (
|
|
10323
|
+
if (existsSync3(join9(path3, ".git"))) return path3;
|
|
10284
10324
|
mkdirSync5(this.root, { recursive: true });
|
|
10285
10325
|
await withRepoConfig(
|
|
10286
10326
|
repoPath,
|
|
@@ -10347,7 +10387,7 @@ var WorktreeManager = class {
|
|
|
10347
10387
|
const root = resolve4(this.root);
|
|
10348
10388
|
const path3 = resolve4(previousWorktree);
|
|
10349
10389
|
if (dirname6(path3) !== root) return null;
|
|
10350
|
-
if (!
|
|
10390
|
+
if (!existsSync3(join9(path3, ".git"))) return null;
|
|
10351
10391
|
let gitDir;
|
|
10352
10392
|
try {
|
|
10353
10393
|
gitDir = await worktreeGitDir(repoPath, path3);
|
|
@@ -10385,7 +10425,7 @@ var WorktreeManager = class {
|
|
|
10385
10425
|
if (rel === "" || rel.startsWith("..") || isAbsolute2(rel)) {
|
|
10386
10426
|
throw new Error(`setup recipe copies a file outside the repo: ${file}`);
|
|
10387
10427
|
}
|
|
10388
|
-
const from =
|
|
10428
|
+
const from = join9(repoPath, rel);
|
|
10389
10429
|
const fromStat = lstatSync2(from, { throwIfNoEntry: false });
|
|
10390
10430
|
if (!fromStat) continue;
|
|
10391
10431
|
if (!fromStat.isFile() || !isInside(repoReal, realpathSync4(from))) {
|
|
@@ -10393,7 +10433,7 @@ var WorktreeManager = class {
|
|
|
10393
10433
|
`setup recipe copies a symlink or non-file, or leaves the repo: ${file}`
|
|
10394
10434
|
);
|
|
10395
10435
|
}
|
|
10396
|
-
const to =
|
|
10436
|
+
const to = join9(worktree, rel);
|
|
10397
10437
|
mkdirSync5(dirname6(to), { recursive: true });
|
|
10398
10438
|
const toStat = lstatSync2(to, { throwIfNoEntry: false });
|
|
10399
10439
|
if (!isInside(worktreeReal, realpathSync4(dirname6(to))) || toStat && !toStat.isFile()) {
|
|
@@ -10442,7 +10482,7 @@ var WorktreeManager = class {
|
|
|
10442
10482
|
const path3 = worktree ? resolve4(worktree) : null;
|
|
10443
10483
|
if (path3 && dirname6(path3) !== root) return false;
|
|
10444
10484
|
const git3 = simpleGit(repoPath);
|
|
10445
|
-
if (path3 &&
|
|
10485
|
+
if (path3 && existsSync3(join9(path3, ".git"))) {
|
|
10446
10486
|
if ((await this.changedFiles(path3)).length > 0) return false;
|
|
10447
10487
|
}
|
|
10448
10488
|
const branches = [];
|
|
@@ -10531,7 +10571,7 @@ var WorktreeManager = class {
|
|
|
10531
10571
|
const removed = [];
|
|
10532
10572
|
for (const run3 of finished) {
|
|
10533
10573
|
if (now - Date.parse(run3.finishedAt) < retentionMs) continue;
|
|
10534
|
-
if (!
|
|
10574
|
+
if (!existsSync3(this.pathFor(run3.runId))) continue;
|
|
10535
10575
|
await this.remove(run3.runId, run3.repoPath);
|
|
10536
10576
|
removed.push(run3.runId);
|
|
10537
10577
|
}
|
|
@@ -10541,11 +10581,11 @@ var WorktreeManager = class {
|
|
|
10541
10581
|
async function excludeVerifyArtifacts(repoPath) {
|
|
10542
10582
|
await withRepoConfig(repoPath, async () => {
|
|
10543
10583
|
const common2 = (await simpleGit(repoPath).raw(["rev-parse", "--path-format=absolute", "--git-common-dir"])).trim();
|
|
10544
|
-
const info =
|
|
10584
|
+
const info = join9(common2, "info");
|
|
10545
10585
|
mkdirSync5(info, { recursive: true });
|
|
10546
|
-
const file =
|
|
10547
|
-
if (
|
|
10548
|
-
const existing =
|
|
10586
|
+
const file = join9(info, "exclude");
|
|
10587
|
+
if (existsSync3(file) && !lstatSync2(file).isFile()) throw new Error("Invalid repository exclude file");
|
|
10588
|
+
const existing = existsSync3(file) ? readFileSync4(file, "utf8") : "";
|
|
10549
10589
|
if (!existing.split(/\r?\n/).includes("/.verify/")) appendFileSync(file, "\n/.verify/\n");
|
|
10550
10590
|
});
|
|
10551
10591
|
}
|
|
@@ -10564,7 +10604,7 @@ async function du(path3) {
|
|
|
10564
10604
|
return 0;
|
|
10565
10605
|
}
|
|
10566
10606
|
let total = 0;
|
|
10567
|
-
for (const entry of entries) total += await du(
|
|
10607
|
+
for (const entry of entries) total += await du(join9(path3, entry));
|
|
10568
10608
|
return total;
|
|
10569
10609
|
}
|
|
10570
10610
|
|
|
@@ -10604,10 +10644,10 @@ async function worktreeGitDir(repoPath, worktree, signal) {
|
|
|
10604
10644
|
}
|
|
10605
10645
|
)).stdout.trim()
|
|
10606
10646
|
);
|
|
10607
|
-
const dotGit =
|
|
10608
|
-
const root =
|
|
10647
|
+
const dotGit = join10(realpathSync5(worktree), ".git");
|
|
10648
|
+
const root = join10(common2, "worktrees");
|
|
10609
10649
|
for (const name of readdirSync3(root)) {
|
|
10610
|
-
const gitdirFile =
|
|
10650
|
+
const gitdirFile = join10(root, name, "gitdir");
|
|
10611
10651
|
let target;
|
|
10612
10652
|
try {
|
|
10613
10653
|
target = readFileSync5(gitdirFile, "utf8").trim();
|
|
@@ -10615,7 +10655,7 @@ async function worktreeGitDir(repoPath, worktree, signal) {
|
|
|
10615
10655
|
continue;
|
|
10616
10656
|
}
|
|
10617
10657
|
if (target === dotGit || safeRealpath(target) === dotGit) {
|
|
10618
|
-
return
|
|
10658
|
+
return join10(root, name);
|
|
10619
10659
|
}
|
|
10620
10660
|
}
|
|
10621
10661
|
throw new Error(`${worktree} is not a worktree of ${repoPath}`);
|
|
@@ -10652,8 +10692,8 @@ async function pinnedGit(repoPath, worktree, env = process.env, signal) {
|
|
|
10652
10692
|
}
|
|
10653
10693
|
async function snapshotTree(repoPath, worktree, env, signal) {
|
|
10654
10694
|
const git3 = await pinnedGit(repoPath, worktree, env, signal);
|
|
10655
|
-
const dir = mkdtempSync(
|
|
10656
|
-
const index = { GIT_INDEX_FILE:
|
|
10695
|
+
const dir = mkdtempSync(join10(tmpdir(), "mikka-index-"));
|
|
10696
|
+
const index = { GIT_INDEX_FILE: join10(dir, "index") };
|
|
10657
10697
|
try {
|
|
10658
10698
|
await git3(["read-tree", "HEAD"], index);
|
|
10659
10699
|
await git3(["add", "--all"], index);
|
|
@@ -10879,19 +10919,19 @@ function githubReceiptEnvironment(host = process.env) {
|
|
|
10879
10919
|
function prepareGitHubEnvironment(runDir, github, path3, runtime) {
|
|
10880
10920
|
const endpoint = new URL(github.endpoint);
|
|
10881
10921
|
if (!endpoint.pathname.endsWith("/api/runs/github-token") || !trustedServerEndpoint(endpoint)) throw new Error("Invalid run GitHub endpoint");
|
|
10882
|
-
const gh = runtime?.ghBinary ?? path3.split(delimiter2).map((dir2) =>
|
|
10922
|
+
const gh = runtime?.ghBinary ?? path3.split(delimiter2).map((dir2) => join11(dir2, "gh")).find((file) => existsSync4(file));
|
|
10883
10923
|
const node = runtime?.nodeBinary ?? process.execPath;
|
|
10884
10924
|
if (!gh) throw new Error("Install GitHub CLI (gh) before running GitHub tasks");
|
|
10885
|
-
const dir =
|
|
10925
|
+
const dir = join11(runDir, "github");
|
|
10886
10926
|
mkdirSync6(dir, { recursive: true, mode: 448 });
|
|
10887
|
-
if (!lstatSync4(dir).isDirectory() || realpathSync7(dir) !==
|
|
10888
|
-
const config =
|
|
10927
|
+
if (!lstatSync4(dir).isDirectory() || realpathSync7(dir) !== join11(realpathSync7(runDir), "github")) throw new Error("Invalid run GitHub directory");
|
|
10928
|
+
const config = join11(dir, "config.json");
|
|
10889
10929
|
rmSync6(config, { force: true });
|
|
10890
10930
|
writeFileSync3(config, JSON.stringify({ ...github, gh }), { mode: 384, flag: "wx" });
|
|
10891
|
-
const bin =
|
|
10931
|
+
const bin = join11(dir, "bin");
|
|
10892
10932
|
mkdirSync6(bin, { recursive: true, mode: 448 });
|
|
10893
|
-
if (!lstatSync4(bin).isDirectory() || realpathSync7(bin) !==
|
|
10894
|
-
const wrapper =
|
|
10933
|
+
if (!lstatSync4(bin).isDirectory() || realpathSync7(bin) !== join11(realpathSync7(dir), "bin")) throw new Error("Invalid run GitHub executable directory");
|
|
10934
|
+
const wrapper = join11(bin, "gh");
|
|
10895
10935
|
rmSync6(wrapper, { force: true });
|
|
10896
10936
|
const fixtureConfig = localGitConfig();
|
|
10897
10937
|
const fixtureProxy = fixtureConfig.length ? 'case "${HTTP_PROXY:-${http_proxy:-}}" in http://*@localhost:*|http://*@127.0.0.1:*) unset NO_PROXY no_proxy ;; esac\n' : "";
|
|
@@ -10940,7 +10980,7 @@ async function withRunGitCredentials(assignment, privateDir, work, preparedEnvir
|
|
|
10940
10980
|
} });
|
|
10941
10981
|
}
|
|
10942
10982
|
mkdirSync6(privateDir, { recursive: true, mode: 448 });
|
|
10943
|
-
const dir = mkdtempSync2(
|
|
10983
|
+
const dir = mkdtempSync2(join11(privateDir, "github-fetch-"));
|
|
10944
10984
|
try {
|
|
10945
10985
|
let env = {};
|
|
10946
10986
|
try {
|
|
@@ -10964,7 +11004,7 @@ async function agentPublishedReceipt(input) {
|
|
|
10964
11004
|
if (!input.github.branch) throw new Error("No task branch to read back");
|
|
10965
11005
|
const branch = input.github.branch;
|
|
10966
11006
|
mkdirSync6(input.privateDir, { recursive: true, mode: 448 });
|
|
10967
|
-
const receiptDir = mkdtempSync2(
|
|
11007
|
+
const receiptDir = mkdtempSync2(join11(input.privateDir, "github-receipt-"));
|
|
10968
11008
|
const nativeGitHub = input.hosted || Boolean(input.githubEnvironment);
|
|
10969
11009
|
try {
|
|
10970
11010
|
const env = {
|
|
@@ -10994,7 +11034,7 @@ async function agentPublishedReceipt(input) {
|
|
|
10994
11034
|
try {
|
|
10995
11035
|
const gh = (args) => {
|
|
10996
11036
|
input.signal?.throwIfAborted();
|
|
10997
|
-
return execa4(nativeGitHub ? "gh" :
|
|
11037
|
+
return execa4(nativeGitHub ? "gh" : join11(receiptDir, "github", "bin", "gh"), args, { cwd: input.worktree, env, extendEnv: false, stdin: "ignore", cancelSignal: input.signal, killDescendants: true });
|
|
10998
11038
|
};
|
|
10999
11039
|
const [owner, repository2] = input.github.repository.split("/");
|
|
11000
11040
|
const query2 = "query($owner:String!,$repository:String!,$commit:GitObjectID!){repository(owner:$owner,name:$repository){object(oid:$commit){... on Commit {oid statusCheckRollup{state}}}}}";
|
|
@@ -11086,7 +11126,7 @@ import {
|
|
|
11086
11126
|
writeFileSync as writeFileSync4
|
|
11087
11127
|
} from "node:fs";
|
|
11088
11128
|
import { homedir as homedir5 } from "node:os";
|
|
11089
|
-
import { dirname as dirname11, join as
|
|
11129
|
+
import { dirname as dirname11, join as join15, resolve as resolve11 } from "node:path";
|
|
11090
11130
|
|
|
11091
11131
|
// src/agents/skill-artifact.ts
|
|
11092
11132
|
import { createHash as createHash5 } from "node:crypto";
|
|
@@ -11119,7 +11159,7 @@ import {
|
|
|
11119
11159
|
basename as basename3,
|
|
11120
11160
|
dirname as dirname9,
|
|
11121
11161
|
isAbsolute as isAbsolute3,
|
|
11122
|
-
join as
|
|
11162
|
+
join as join12,
|
|
11123
11163
|
relative as relative3,
|
|
11124
11164
|
resolve as resolve9
|
|
11125
11165
|
} from "node:path";
|
|
@@ -11210,7 +11250,7 @@ function realTarget(path3) {
|
|
|
11210
11250
|
let current = path3;
|
|
11211
11251
|
for (let hops = 0; ; ) {
|
|
11212
11252
|
try {
|
|
11213
|
-
return
|
|
11253
|
+
return join12(realpathSync8(current), ...[...missing2].reverse());
|
|
11214
11254
|
} catch {
|
|
11215
11255
|
if (lstatSync6(current, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
11216
11256
|
if (++hops > 40) return path3;
|
|
@@ -11238,7 +11278,7 @@ function classifyWrite(worktree, target) {
|
|
|
11238
11278
|
// src/captures.ts
|
|
11239
11279
|
import { createHash as createHash7 } from "node:crypto";
|
|
11240
11280
|
import { closeSync as closeSync2, constants as constants3, createReadStream, fstatSync, lstatSync as lstatSync7, mkdirSync as mkdirSync7, mkdtempSync as mkdtempSync3, openSync as openSync2, readFileSync as readFileSync7, readSync, readdirSync as readdirSync4, rmSync as rmSync7 } from "node:fs";
|
|
11241
|
-
import { join as
|
|
11281
|
+
import { join as join14 } from "node:path";
|
|
11242
11282
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
11243
11283
|
|
|
11244
11284
|
// src/agents/capture-video.mjs
|
|
@@ -11246,7 +11286,7 @@ import { execFile as execFile3 } from "node:child_process";
|
|
|
11246
11286
|
import { createHash as createHash6 } from "node:crypto";
|
|
11247
11287
|
import { constants as constants2, createWriteStream } from "node:fs";
|
|
11248
11288
|
import { chmod, lstat as lstat3, mkdir as mkdir3, mkdtemp, open, readFile as readFile3, rename, rm as rm3, stat } from "node:fs/promises";
|
|
11249
|
-
import { dirname as dirname10, basename as basename4, join as
|
|
11289
|
+
import { dirname as dirname10, basename as basename4, join as join13, resolve as resolve10 } from "node:path";
|
|
11250
11290
|
import { devNull } from "node:os";
|
|
11251
11291
|
import { pipeline } from "node:stream/promises";
|
|
11252
11292
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
@@ -11314,7 +11354,7 @@ async function captureVideoBinaries({ directory = CAPTURE_TOOLS_DIRECTORY, owner
|
|
|
11314
11354
|
if (!info) return { ffmpeg: "ffmpeg", ffprobe: "ffprobe" };
|
|
11315
11355
|
try {
|
|
11316
11356
|
if (!info.isDirectory() || info.uid !== ownerId || info.mode & 18) throw new Error("Private capture tools directory is unsafe");
|
|
11317
|
-
const binaries = { ffmpeg:
|
|
11357
|
+
const binaries = { ffmpeg: join13(directory, "ffmpeg"), ffprobe: join13(directory, "ffprobe") };
|
|
11318
11358
|
for (const path3 of Object.values(binaries)) {
|
|
11319
11359
|
const binary = await lstat3(path3);
|
|
11320
11360
|
if (!binary.isFile() || binary.uid !== ownerId || binary.mode & 18 || !(binary.mode & 73)) throw new Error("Private capture tool is unsafe");
|
|
@@ -11405,7 +11445,7 @@ async function processCaptureVideo(input, output, options = {}) {
|
|
|
11405
11445
|
const deadline = Date.now() + Math.min(options.timeoutMs ?? 9e4, 18e4);
|
|
11406
11446
|
const binaries = await captureVideoBinaries();
|
|
11407
11447
|
await mkdir3(dirname10(output), { recursive: true, mode: 448 });
|
|
11408
|
-
const temporary = await mkdtemp(
|
|
11448
|
+
const temporary = await mkdtemp(join13(dirname10(output), ".capture-process-"));
|
|
11409
11449
|
await chmod(temporary, 448);
|
|
11410
11450
|
const run3 = async (binary, args) => {
|
|
11411
11451
|
options.signal?.throwIfAborted();
|
|
@@ -11445,12 +11485,12 @@ async function processCaptureVideo(input, output, options = {}) {
|
|
|
11445
11485
|
return { durationMs: Math.round(seconds * 1e3), width: stream.width, height: stream.height };
|
|
11446
11486
|
};
|
|
11447
11487
|
try {
|
|
11448
|
-
const source =
|
|
11488
|
+
const source = join13(temporary, "source.video");
|
|
11449
11489
|
const originalFile = await snapshot2(input, source, options.signal);
|
|
11450
11490
|
const original = await probe(source);
|
|
11451
11491
|
const windows = recordingWindows(original.durationMs, steps);
|
|
11452
11492
|
const retainedMs = windows.reduce((total, window) => total + window.endMs - window.startMs, 0);
|
|
11453
|
-
const result =
|
|
11493
|
+
const result = join13(temporary, "final.mp4");
|
|
11454
11494
|
const base = [
|
|
11455
11495
|
"-y",
|
|
11456
11496
|
"-nostdin",
|
|
@@ -11490,7 +11530,7 @@ async function processCaptureVideo(input, output, options = {}) {
|
|
|
11490
11530
|
"2",
|
|
11491
11531
|
"-pix_fmt",
|
|
11492
11532
|
"yuv420p",
|
|
11493
|
-
...rate ? ["-b:v", `${rate}k`, "-pass", String(pass), "-passlogfile",
|
|
11533
|
+
...rate ? ["-b:v", `${rate}k`, "-pass", String(pass), "-passlogfile", join13(temporary, "pass")] : ["-crf", "28"],
|
|
11494
11534
|
...pass === 1 ? ["-f", "null", devNull] : ["-movflags", "+faststart", result]
|
|
11495
11535
|
]);
|
|
11496
11536
|
};
|
|
@@ -11567,7 +11607,7 @@ function readPlain(path3, max) {
|
|
|
11567
11607
|
}
|
|
11568
11608
|
}
|
|
11569
11609
|
var drop = (dir, id5) => {
|
|
11570
|
-
for (const name of [`${id5}.json`, ...EXTENSIONS.map((ext) => `${id5}.${ext}`)]) rmSync7(
|
|
11610
|
+
for (const name of [`${id5}.json`, ...EXTENSIONS.map((ext) => `${id5}.${ext}`)]) rmSync7(join14(dir, name), { force: true });
|
|
11571
11611
|
};
|
|
11572
11612
|
async function hashPlain(path3, signal) {
|
|
11573
11613
|
signal?.throwIfAborted();
|
|
@@ -11585,9 +11625,9 @@ async function hashPlain(path3, signal) {
|
|
|
11585
11625
|
}
|
|
11586
11626
|
async function prepareVideo(file, id5, steps, pendingDir, signal) {
|
|
11587
11627
|
signal?.throwIfAborted();
|
|
11588
|
-
const directory = pendingDir ?? mkdtempSync3(
|
|
11628
|
+
const directory = pendingDir ?? mkdtempSync3(join14(tmpdir3(), "mikka-capture-pending-"));
|
|
11589
11629
|
mkdirSync7(directory, { recursive: true, mode: 448 });
|
|
11590
|
-
const output =
|
|
11630
|
+
const output = join14(directory, `${id5}.processed.mp4`), receipt = join14(directory, `${id5}.video.json`);
|
|
11591
11631
|
try {
|
|
11592
11632
|
const originalHash = await hashPlain(file, signal);
|
|
11593
11633
|
const stepHash = createHash7("sha256").update(JSON.stringify(steps)).digest("hex");
|
|
@@ -11618,7 +11658,7 @@ async function prepareVideo(file, id5, steps, pendingDir, signal) {
|
|
|
11618
11658
|
}
|
|
11619
11659
|
function dropPrepared(pendingDir, id5) {
|
|
11620
11660
|
if (!pendingDir) return;
|
|
11621
|
-
for (const name of [`${id5}.json`, `${id5}.processed.mp4`, `${id5}.video.json`]) rmSync7(
|
|
11661
|
+
for (const name of [`${id5}.json`, `${id5}.processed.mp4`, `${id5}.video.json`]) rmSync7(join14(pendingDir, name), { force: true });
|
|
11622
11662
|
}
|
|
11623
11663
|
function fileType(path3) {
|
|
11624
11664
|
let fd;
|
|
@@ -11645,7 +11685,7 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11645
11685
|
signal?.throwIfAborted();
|
|
11646
11686
|
const id5 = name.endsWith(".json") ? name.slice(0, -5) : "";
|
|
11647
11687
|
if (!ID.test(id5)) continue;
|
|
11648
|
-
const meta = readPlain(
|
|
11688
|
+
const meta = readPlain(join14(dir, name), 128e3);
|
|
11649
11689
|
let title2 = "";
|
|
11650
11690
|
let steps = [];
|
|
11651
11691
|
try {
|
|
@@ -11655,7 +11695,7 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11655
11695
|
} catch {
|
|
11656
11696
|
title2 = "";
|
|
11657
11697
|
}
|
|
11658
|
-
const file = EXTENSIONS.map((ext) =>
|
|
11698
|
+
const file = EXTENSIONS.map((ext) => join14(dir, `${id5}.${ext}`)).find((path3) => lstatSync7(path3, { throwIfNoEntry: false }));
|
|
11659
11699
|
const originalType = file ? fileType(file) : null;
|
|
11660
11700
|
let video;
|
|
11661
11701
|
if (file && title2 && originalType?.startsWith("video/")) {
|
|
@@ -11678,7 +11718,7 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11678
11718
|
}
|
|
11679
11719
|
try {
|
|
11680
11720
|
const sha2562 = createHash7("sha256").update(bytes).digest("hex");
|
|
11681
|
-
const pendingPath = pendingDir ?
|
|
11721
|
+
const pendingPath = pendingDir ? join14(pendingDir, `${id5}.json`) : null;
|
|
11682
11722
|
let pending;
|
|
11683
11723
|
if (pendingPath) {
|
|
11684
11724
|
try {
|
|
@@ -11736,7 +11776,7 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11736
11776
|
log.warn({ run_id: runId, capture: id5, status: error.code }, "capture reservation unavailable; retry stopped");
|
|
11737
11777
|
if (pendingDir) {
|
|
11738
11778
|
mkdirSync7(pendingDir, { recursive: true, mode: 448 });
|
|
11739
|
-
writeJsonAtomic(
|
|
11779
|
+
writeJsonAtomic(join14(pendingDir, "blocked.json"), { status: error.code });
|
|
11740
11780
|
}
|
|
11741
11781
|
return sent;
|
|
11742
11782
|
}
|
|
@@ -11762,8 +11802,8 @@ var CaptureUploader = class {
|
|
|
11762
11802
|
/** A final signal bounds both this pass and any earlier pass still in flight. */
|
|
11763
11803
|
flush(runId, existingOnly = false, signal) {
|
|
11764
11804
|
if (!/^[A-Za-z0-9_-]{1,64}$/.test(runId)) return Promise.resolve();
|
|
11765
|
-
const pendingDir = this.pendingRoot ?
|
|
11766
|
-
if (pendingDir && lstatSync7(
|
|
11805
|
+
const pendingDir = this.pendingRoot ? join14(this.pendingRoot, runId) : void 0;
|
|
11806
|
+
if (pendingDir && lstatSync7(join14(pendingDir, "blocked.json"), { throwIfNoEntry: false }))
|
|
11767
11807
|
return signal ? Promise.reject(new Error("Capture upload incomplete")) : Promise.resolve();
|
|
11768
11808
|
const pass = this.passes.get(runId) ?? { tail: Promise.resolve(), abort: new AbortController() };
|
|
11769
11809
|
const abort = () => pass.abort.abort(signal?.reason);
|
|
@@ -11839,7 +11879,7 @@ function credentialDenyRead(harness, home = homedir5()) {
|
|
|
11839
11879
|
// Other harnesses' logins; each harness still reads its own.
|
|
11840
11880
|
...harness === "codex" ? [] : [".codex/auth.json"],
|
|
11841
11881
|
...harness === "claude_code" ? [] : [".claude/.credentials.json"]
|
|
11842
|
-
].map((path3) =>
|
|
11882
|
+
].map((path3) => join15(home, path3));
|
|
11843
11883
|
}
|
|
11844
11884
|
function daemonSecrets(dataDir) {
|
|
11845
11885
|
const paths = daemonPaths(realpathSync9(dataDir));
|
|
@@ -11850,7 +11890,7 @@ function daemonSecrets(dataDir) {
|
|
|
11850
11890
|
paths.outbox,
|
|
11851
11891
|
paths.logs,
|
|
11852
11892
|
paths.devRepos,
|
|
11853
|
-
|
|
11893
|
+
join15(paths.adapterState, "pids")
|
|
11854
11894
|
];
|
|
11855
11895
|
}
|
|
11856
11896
|
function runPaths(stateDir, runId) {
|
|
@@ -11859,9 +11899,9 @@ function runPaths(stateDir, runId) {
|
|
|
11859
11899
|
/** The daemon's data dir (`stateDir` is `<dataDir>/adapters`). */
|
|
11860
11900
|
privateDir: resolve11(stateDir, ".."),
|
|
11861
11901
|
/** Writable from the sandbox. */
|
|
11862
|
-
runDir:
|
|
11902
|
+
runDir: join15(stateDir, "runs", id5),
|
|
11863
11903
|
/** Daemon only. */
|
|
11864
|
-
pidFile:
|
|
11904
|
+
pidFile: join15(stateDir, "pids", `${id5}.pgid`)
|
|
11865
11905
|
};
|
|
11866
11906
|
}
|
|
11867
11907
|
function repositorySkill(worktree, slug) {
|
|
@@ -11869,7 +11909,7 @@ function repositorySkill(worktree, slug) {
|
|
|
11869
11909
|
const missing2 = (reason) => ({ id: id5, name: slug, description: "", source: "repository", digest: null, instructions: null, available: false, reason });
|
|
11870
11910
|
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(slug)) return missing2("invalid");
|
|
11871
11911
|
for (const root of [".claude/skills", ".agents/skills"]) {
|
|
11872
|
-
const file =
|
|
11912
|
+
const file = join15(worktree, root, slug, SKILL_BODY_FILE);
|
|
11873
11913
|
const meta = lstatSync8(file, { throwIfNoEntry: false });
|
|
11874
11914
|
if (!meta) continue;
|
|
11875
11915
|
if (!meta.isFile() || meta.isSymbolicLink() || meta.nlink !== 1 || meta.size < 1 || meta.size > MAX_PROFILE_SKILL_INSTRUCTIONS_LENGTH) return missing2("invalid");
|
|
@@ -11911,10 +11951,10 @@ function writeProfileSkillManifest(options, runDir, worktree, includeRepository)
|
|
|
11911
11951
|
}
|
|
11912
11952
|
for (const slug of declared) entries.push(includeRepository ? repositorySkill(worktree, slug) : { id: `repository:${slug}`, name: slug, description: "", source: "repository", digest: null, instructions: null, available: false, reason: "pending" });
|
|
11913
11953
|
const unique = [...new Map(entries.map((entry) => [entry.id, entry])).values()];
|
|
11914
|
-
const dir =
|
|
11954
|
+
const dir = join15(runDir, PROFILE_SKILLS_DIR);
|
|
11915
11955
|
ownDir(dir);
|
|
11916
11956
|
const manifest = { version: 1, skills: unique };
|
|
11917
|
-
const file =
|
|
11957
|
+
const file = join15(dir, PROFILE_SKILL_MANIFEST_FILE);
|
|
11918
11958
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
11919
11959
|
writeFileSync4(tmp, `${JSON.stringify(manifest)}
|
|
11920
11960
|
`, { encoding: "utf8", mode: 384 });
|
|
@@ -11927,9 +11967,9 @@ function prepareRunContextFiles(options) {
|
|
|
11927
11967
|
const files2 = {
|
|
11928
11968
|
worktree: resolve11(options.worktree),
|
|
11929
11969
|
runDir,
|
|
11930
|
-
handoffFile:
|
|
11931
|
-
tmpDir:
|
|
11932
|
-
capturesDir:
|
|
11970
|
+
handoffFile: join15(runDir, "handoff.json"),
|
|
11971
|
+
tmpDir: join15(runDir, "tmp"),
|
|
11972
|
+
capturesDir: join15(runDir, CAPTURES_DIR)
|
|
11933
11973
|
};
|
|
11934
11974
|
ownDir(files2.tmpDir);
|
|
11935
11975
|
ownDir(files2.capturesDir);
|
|
@@ -11963,7 +12003,7 @@ function runMcpServer(options, files2) {
|
|
|
11963
12003
|
files2.worktree,
|
|
11964
12004
|
"--capture-root",
|
|
11965
12005
|
files2.tmpDir,
|
|
11966
|
-
...options.profileSkills?.length || options.repositorySkills?.length ? ["--profile-skills",
|
|
12006
|
+
...options.profileSkills?.length || options.repositorySkills?.length ? ["--profile-skills", join15(files2.runDir, PROFILE_SKILLS_DIR)] : [],
|
|
11967
12007
|
...options.factoryCheck && (!options.factoryCheck.reportOnly || options.factoryCheck.inferCommand) ? ["--factory-verify", JSON.stringify({ cwd: files2.worktree, command: options.verifyCommand ?? null, infer: options.factoryCheck.inferCommand })] : [],
|
|
11968
12008
|
...options.factoryCheck?.reportOnly || readOnlyInspection ? ["--factory-artifacts", files2.worktree] : [],
|
|
11969
12009
|
...repositoryExecution ? ["--repository-selection", files2.worktree] : []
|
|
@@ -12011,13 +12051,13 @@ var RunContext = class {
|
|
|
12011
12051
|
);
|
|
12012
12052
|
ownDir(options.runDir);
|
|
12013
12053
|
this.runDir = realpathSync9(options.runDir);
|
|
12014
|
-
this.handoffFile =
|
|
12015
|
-
this.skillsDir =
|
|
12016
|
-
this.tmpDir =
|
|
12054
|
+
this.handoffFile = join15(this.runDir, "handoff.json");
|
|
12055
|
+
this.skillsDir = join15(this.runDir, SKILLS_DIR);
|
|
12056
|
+
this.tmpDir = join15(this.runDir, "tmp");
|
|
12017
12057
|
ownDir(this.tmpDir);
|
|
12018
|
-
this.capturesDir =
|
|
12058
|
+
this.capturesDir = join15(this.runDir, CAPTURES_DIR);
|
|
12019
12059
|
ownDir(this.capturesDir);
|
|
12020
|
-
this.profileSkillsDir =
|
|
12060
|
+
this.profileSkillsDir = join15(this.runDir, PROFILE_SKILLS_DIR);
|
|
12021
12061
|
this.writeSkills();
|
|
12022
12062
|
this.writeProfileSkills();
|
|
12023
12063
|
if (options.github && !options.machineEnvironment) {
|
|
@@ -12060,19 +12100,19 @@ var RunContext = class {
|
|
|
12060
12100
|
let slug = base;
|
|
12061
12101
|
for (let n = 2; taken.has(slug); n += 1) slug = `${base}-${n}`;
|
|
12062
12102
|
taken.add(slug);
|
|
12063
|
-
const dir =
|
|
12103
|
+
const dir = join15(this.skillsDir, slug);
|
|
12064
12104
|
if (this.options.skillReceipt) {
|
|
12065
12105
|
const existing = lstatSync8(dir, { throwIfNoEntry: false });
|
|
12066
12106
|
if (existing && (!existing.isDirectory() || existing.isSymbolicLink())) throw new Error("Unsafe Skill artifact directory");
|
|
12067
|
-
const file = lstatSync8(
|
|
12107
|
+
const file = lstatSync8(join15(dir, SKILL_BODY_FILE), { throwIfNoEntry: false });
|
|
12068
12108
|
if (file && (!file.isFile() || file.isSymbolicLink() || file.nlink !== 1)) throw new Error("Unsafe Skill artifact file");
|
|
12069
12109
|
}
|
|
12070
12110
|
mkdirSync8(dir, { recursive: true });
|
|
12071
|
-
const bodyFile =
|
|
12111
|
+
const bodyFile = join15(dir, SKILL_BODY_FILE);
|
|
12072
12112
|
if (this.options.skillReceipt) {
|
|
12073
12113
|
if (!lstatSync8(bodyFile, { throwIfNoEntry: false })) writeFileSync4(bodyFile, skillMarkdown(skill), { encoding: "utf8", flag: "wx", mode: 384 });
|
|
12074
12114
|
} else writeFileSync4(bodyFile, skillMarkdown(skill), "utf8");
|
|
12075
|
-
if (this.options.skillReceipt) verifyMountedSkill(
|
|
12115
|
+
if (this.options.skillReceipt) verifyMountedSkill(join15(dir, SKILL_BODY_FILE), this.options.skillReceipt);
|
|
12076
12116
|
for (const file of skill.files) {
|
|
12077
12117
|
const target = resolve11(dir, file.path);
|
|
12078
12118
|
if (!target.startsWith(`${dir}/`)) continue;
|
|
@@ -12110,14 +12150,14 @@ var RunContext = class {
|
|
|
12110
12150
|
denyWrite: [
|
|
12111
12151
|
// The fixture's refs/objects are writable for push; its configuration
|
|
12112
12152
|
// and hooks must remain host-owned because fixture verification runs Git.
|
|
12113
|
-
...fixtureOrigin ? [
|
|
12114
|
-
|
|
12115
|
-
|
|
12116
|
-
|
|
12117
|
-
|
|
12153
|
+
...fixtureOrigin ? [join15(fixtureOrigin, "config"), join15(fixtureOrigin, "hooks")] : [],
|
|
12154
|
+
join15(this.worktree, ".git"),
|
|
12155
|
+
join15(this.gitDir, "commondir"),
|
|
12156
|
+
join15(this.gitDir, "gitdir"),
|
|
12157
|
+
join15(this.gitDir, "config.worktree"),
|
|
12118
12158
|
// A repository's config and hooks in the shared clone, outside the
|
|
12119
12159
|
// working directory, are declared read-only here too.
|
|
12120
|
-
...this.options.gitWritePaths?.length ? [
|
|
12160
|
+
...this.options.gitWritePaths?.length ? [join15(this.gitDir, "..", "..", "config"), join15(this.gitDir, "..", "..", "hooks")] : [],
|
|
12121
12161
|
...readOnly ? [this.worktree, ...this.options.gitWritePaths ?? []] : []
|
|
12122
12162
|
],
|
|
12123
12163
|
denyRead: [
|
|
@@ -12171,7 +12211,7 @@ var RunContext = class {
|
|
|
12171
12211
|
*/
|
|
12172
12212
|
tempEnv() {
|
|
12173
12213
|
if (this.options.machineEnvironment) return this.options.policyHash ? { MIKKA_POLICY_HASH: this.options.policyHash } : {};
|
|
12174
|
-
return { TMPDIR: this.tmpDir, TMPPREFIX:
|
|
12214
|
+
return { TMPDIR: this.tmpDir, TMPPREFIX: join15(this.tmpDir, "zsh"), ...withGitConfig(this.githubEnv, RUN_GIT_CONFIG), ...this.options.policyHash ? { MIKKA_POLICY_HASH: this.options.policyHash } : {} };
|
|
12175
12215
|
}
|
|
12176
12216
|
/**
|
|
12177
12217
|
* The agent delivers this run itself: it commits, pushes to the task
|
|
@@ -12464,7 +12504,7 @@ function claudeSettings(workspace) {
|
|
|
12464
12504
|
attribution: { pr: "" }
|
|
12465
12505
|
};
|
|
12466
12506
|
}
|
|
12467
|
-
function claudeChunks(message) {
|
|
12507
|
+
function claudeChunks(message, turnModel) {
|
|
12468
12508
|
const chunks = [];
|
|
12469
12509
|
if (message.type === "assistant") {
|
|
12470
12510
|
message.message.content.forEach((block, index) => {
|
|
@@ -12509,11 +12549,15 @@ function claudeChunks(message) {
|
|
|
12509
12549
|
);
|
|
12510
12550
|
}
|
|
12511
12551
|
} else if (message.type === "result") {
|
|
12552
|
+
const usedModels = Object.keys(message.modelUsage ?? {});
|
|
12512
12553
|
chunks.push({
|
|
12513
12554
|
type: "data-usage",
|
|
12514
12555
|
data: {
|
|
12515
12556
|
inputTokens: message.usage.input_tokens ?? 0,
|
|
12516
12557
|
outputTokens: message.usage.output_tokens ?? 0,
|
|
12558
|
+
model: turnModel ?? (usedModels.length === 1 ? usedModels[0] : void 0),
|
|
12559
|
+
cacheReadTokens: message.usage.cache_read_input_tokens ?? null,
|
|
12560
|
+
cacheWriteTokens: message.usage.cache_creation_input_tokens ?? null,
|
|
12517
12561
|
costUsd: message.total_cost_usd ?? null,
|
|
12518
12562
|
source: "claude agent sdk result"
|
|
12519
12563
|
}
|
|
@@ -12811,15 +12855,15 @@ var ClaudeAdapter = class {
|
|
|
12811
12855
|
throw new Error(SUBSCRIPTION_ERROR, { cause: error });
|
|
12812
12856
|
}
|
|
12813
12857
|
}
|
|
12814
|
-
const nativeHome = options.machineEnvironment ? options.env.HOME :
|
|
12858
|
+
const nativeHome = options.machineEnvironment ? options.env.HOME : join16(runDir, "native-home");
|
|
12815
12859
|
if (!nativeHome) throw new Error("Cloud machine HOME unavailable");
|
|
12816
|
-
const configDir = options.machineEnvironment ? options.env.CLAUDE_CONFIG_DIR ??
|
|
12860
|
+
const configDir = options.machineEnvironment ? options.env.CLAUDE_CONFIG_DIR ?? join16(nativeHome, ".claude") : join16(nativeHome, ".claude");
|
|
12817
12861
|
if (!options.machineEnvironment) {
|
|
12818
12862
|
ownDir(nativeHome);
|
|
12819
12863
|
ownDir(configDir);
|
|
12820
12864
|
}
|
|
12821
12865
|
if (!options.machineEnvironment && mode === "continue" && options.continueSession) {
|
|
12822
|
-
carryHistory(
|
|
12866
|
+
carryHistory(join16(runPaths(this.options.stateDir, options.continueSession.runId).runDir, "native-home", ".claude"), configDir, ["projects"]);
|
|
12823
12867
|
}
|
|
12824
12868
|
if (externalAuth && options.credential) throw new Error(SUBSCRIPTION_ERROR);
|
|
12825
12869
|
const credentialEnv = claudeCredentialEnv(options.credential);
|
|
@@ -12854,8 +12898,8 @@ var ClaudeAdapter = class {
|
|
|
12854
12898
|
privateDir: paths.privateDir,
|
|
12855
12899
|
// Its session store, so `resume` works; keyed by the cwd it sees.
|
|
12856
12900
|
extraWrite: preparing ? [] : [
|
|
12857
|
-
|
|
12858
|
-
|
|
12901
|
+
join16(configDir, "projects", claudeProjectDirName(options.cwd)),
|
|
12902
|
+
join16(
|
|
12859
12903
|
configDir,
|
|
12860
12904
|
"projects",
|
|
12861
12905
|
claudeProjectDirName(realpathSync10(options.cwd))
|
|
@@ -12879,6 +12923,7 @@ var ClaudeAdapter = class {
|
|
|
12879
12923
|
let written = 0;
|
|
12880
12924
|
let results = 0;
|
|
12881
12925
|
let runtimeModel = null;
|
|
12926
|
+
let turnModel;
|
|
12882
12927
|
let ending = false;
|
|
12883
12928
|
let failureDetails;
|
|
12884
12929
|
let lastError;
|
|
@@ -12998,7 +13043,7 @@ var ClaudeAdapter = class {
|
|
|
12998
13043
|
if (preparation) {
|
|
12999
13044
|
const { binding, control } = preparation;
|
|
13000
13045
|
const fixed = claudePrewarmOptionsKey(options);
|
|
13001
|
-
const parking =
|
|
13046
|
+
const parking = join16(runDir, "claude-parking");
|
|
13002
13047
|
ownDir(parking);
|
|
13003
13048
|
let anonymousAdopted = false;
|
|
13004
13049
|
const prepared = prepareClaudeSession({
|
|
@@ -13142,8 +13187,10 @@ var ClaudeAdapter = class {
|
|
|
13142
13187
|
runRuntimeTimings.agentAccepted(options.runId, "claude_user_ack");
|
|
13143
13188
|
if (message.type === "system" && message.subtype === "init" && typeof message.model === "string")
|
|
13144
13189
|
runtimeModel = message.model || null;
|
|
13145
|
-
if (message.type === "assistant" && message.parent_tool_use_id == null && typeof message.message.model === "string")
|
|
13190
|
+
if (message.type === "assistant" && message.parent_tool_use_id == null && typeof message.message.model === "string") {
|
|
13146
13191
|
runtimeModel = message.message.model || null;
|
|
13192
|
+
if (!message.error && runtimeModel) turnModel = runtimeModel;
|
|
13193
|
+
}
|
|
13147
13194
|
if (runtimeModel && (message.type === "system" && message.subtype === "init" || message.type === "assistant" && message.parent_tool_use_id == null))
|
|
13148
13195
|
options.onRuntimeModel?.(sessionId, runtimeModel);
|
|
13149
13196
|
if (provesSession(message)) {
|
|
@@ -13157,8 +13204,9 @@ var ClaudeAdapter = class {
|
|
|
13157
13204
|
quota = mergeQuota(quota, claudeQuotaSignal(message));
|
|
13158
13205
|
if (message.type === "tool_progress" && message.session_id === sessionId) queue.progress();
|
|
13159
13206
|
if (!(message.type === "assistant" && message.error))
|
|
13160
|
-
for (const chunk of claudeChunks(message)) queue.chunk(chunk);
|
|
13207
|
+
for (const chunk of claudeChunks(message, turnModel)) queue.chunk(chunk);
|
|
13161
13208
|
if (message.type !== "result") continue;
|
|
13209
|
+
turnModel = void 0;
|
|
13162
13210
|
results++;
|
|
13163
13211
|
failureDetails = message.is_error ? capture(message) : void 0;
|
|
13164
13212
|
providerFailure = claudeProviderFailure(message, assistantError);
|
|
@@ -13354,7 +13402,7 @@ function codexFailureMessage(phase, info) {
|
|
|
13354
13402
|
}
|
|
13355
13403
|
|
|
13356
13404
|
// src/adapters/codex.ts
|
|
13357
|
-
import { delimiter as delimiter3, dirname as dirname12, isAbsolute as isAbsolute5, join as
|
|
13405
|
+
import { delimiter as delimiter3, dirname as dirname12, isAbsolute as isAbsolute5, join as join18, relative as relative5 } from "node:path";
|
|
13358
13406
|
import { mkdirSync as mkdirSync10 } from "node:fs";
|
|
13359
13407
|
|
|
13360
13408
|
// src/codex-generation-telemetry.ts
|
|
@@ -13870,9 +13918,14 @@ function jsonlConnection(input, output) {
|
|
|
13870
13918
|
|
|
13871
13919
|
// src/adapters/codex-mailbox.ts
|
|
13872
13920
|
import { closeSync as closeSync3, constants as constants4, fstatSync as fstatSync2, lstatSync as lstatSync9, mkdirSync as mkdirSync9, openSync as openSync3, readSync as readSync2 } from "node:fs";
|
|
13873
|
-
import { isAbsolute as isAbsolute4, join as
|
|
13921
|
+
import { isAbsolute as isAbsolute4, join as join17, relative as relative4, sep as sep3 } from "node:path";
|
|
13874
13922
|
import { isDeepStrictEqual } from "node:util";
|
|
13875
|
-
var
|
|
13923
|
+
var UNAVAILABLE = "Run mailbox requires a verified original Codex thread";
|
|
13924
|
+
var unavailable2 = (reason, cause) => Object.assign(
|
|
13925
|
+
new Error(`${UNAVAILABLE} (${reason})`, { cause }),
|
|
13926
|
+
{ name: "codex_mailbox_unavailable", detail: reason }
|
|
13927
|
+
);
|
|
13928
|
+
var isUnavailable = (error) => error instanceof Error && error.name === "codex_mailbox_unavailable";
|
|
13876
13929
|
function codexMailboxResumeVersion(userAgent) {
|
|
13877
13930
|
const version = typeof userAgent === "string" ? /^[A-Za-z0-9._-]+\/(0\.163\.0|0\.166\.0|0\.167\.0)(?:\s|$)/.exec(userAgent)?.[1] : void 0;
|
|
13878
13931
|
return version === "0.163.0" || version === "0.166.0" || version === "0.167.0" ? version : null;
|
|
@@ -13881,24 +13934,33 @@ function codexMailboxCatalogue(mailbox) {
|
|
|
13881
13934
|
return JSON.parse(JSON.stringify(mailbox.tools.map((tool) => ({ type: "function", ...tool }))));
|
|
13882
13935
|
}
|
|
13883
13936
|
function historyParts(value) {
|
|
13884
|
-
if (typeof value !== "string" || value.length > 1024 || /[\\\0]/.test(value)) throw unavailable2();
|
|
13937
|
+
if (typeof value !== "string" || value.length > 1024 || /[\\\0]/.test(value)) throw unavailable2("history_path");
|
|
13885
13938
|
const parts = value.split("/");
|
|
13886
|
-
if (!["sessions", "archived_sessions"].includes(parts[0]) || parts.length < 2 || parts.some((part) => !part || part === "." || part === "..") || !value.endsWith(".jsonl")) throw unavailable2();
|
|
13939
|
+
if (!["sessions", "archived_sessions"].includes(parts[0]) || parts.length < 2 || parts.some((part) => !part || part === "." || part === "..") || !value.endsWith(".jsonl")) throw unavailable2("history_path");
|
|
13887
13940
|
return parts;
|
|
13888
13941
|
}
|
|
13889
13942
|
function receiptFile(stateDir, runId) {
|
|
13890
|
-
return
|
|
13943
|
+
return join17(stateDir, "codex-mailbox", assertSafeId("run id", runId) + ".json");
|
|
13891
13944
|
}
|
|
13892
|
-
function readJson2(file, limit, firstLine = false) {
|
|
13893
|
-
|
|
13945
|
+
function readJson2(file, limit, firstLine = false, reason = "history_file") {
|
|
13946
|
+
let fd;
|
|
13947
|
+
try {
|
|
13948
|
+
fd = openSync3(file, constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK);
|
|
13949
|
+
} catch {
|
|
13950
|
+
throw unavailable2(reason);
|
|
13951
|
+
}
|
|
13894
13952
|
try {
|
|
13895
13953
|
const stat3 = fstatSync2(fd);
|
|
13896
|
-
if (!stat3.isFile() || stat3.nlink !== 1 || !firstLine && stat3.size > limit) throw unavailable2();
|
|
13954
|
+
if (!stat3.isFile() || stat3.nlink !== 1 || !firstLine && stat3.size > limit) throw unavailable2(reason);
|
|
13897
13955
|
const buffer = Buffer.alloc(Math.min(stat3.size, limit + 1));
|
|
13898
13956
|
const length = readSync2(fd, buffer, 0, buffer.length, 0);
|
|
13899
13957
|
const end = firstLine ? buffer.subarray(0, length).indexOf(10) : length;
|
|
13900
|
-
if (end < 0 || end > limit) throw unavailable2();
|
|
13901
|
-
|
|
13958
|
+
if (end < 0 || end > limit) throw unavailable2(reason);
|
|
13959
|
+
try {
|
|
13960
|
+
return JSON.parse(buffer.subarray(0, end).toString("utf8"));
|
|
13961
|
+
} catch {
|
|
13962
|
+
throw unavailable2(reason);
|
|
13963
|
+
}
|
|
13902
13964
|
} finally {
|
|
13903
13965
|
closeSync3(fd);
|
|
13904
13966
|
}
|
|
@@ -13907,38 +13969,38 @@ function verifyHistory(home, path3, threadId, catalogue) {
|
|
|
13907
13969
|
const parts = historyParts(path3);
|
|
13908
13970
|
let parent = home;
|
|
13909
13971
|
for (const part of ["", ...parts.slice(0, -1)]) {
|
|
13910
|
-
if (part) parent =
|
|
13972
|
+
if (part) parent = join17(parent, part);
|
|
13911
13973
|
const stat3 = lstatSync9(parent);
|
|
13912
|
-
if (!stat3.isDirectory() || stat3.isSymbolicLink()) throw unavailable2();
|
|
13974
|
+
if (!stat3.isDirectory() || stat3.isSymbolicLink()) throw unavailable2("history_dir");
|
|
13913
13975
|
}
|
|
13914
|
-
const header = readJson2(
|
|
13915
|
-
if (header?.type !== "session_meta" || header.payload?.id !== threadId || !isDeepStrictEqual(header.payload.dynamic_tools, catalogue)) throw unavailable2();
|
|
13976
|
+
const header = readJson2(join17(home, ...parts), 1024 * 1024, true, "history_meta");
|
|
13977
|
+
if (header?.type !== "session_meta" || header.payload?.id !== threadId || !isDeepStrictEqual(header.payload.dynamic_tools, catalogue)) throw unavailable2("history_meta");
|
|
13916
13978
|
}
|
|
13917
13979
|
function verifyCodexMailboxResume(stateDir, sourceRunId, home, threadId, catalogue) {
|
|
13918
13980
|
try {
|
|
13919
|
-
const dir = lstatSync9(
|
|
13920
|
-
if (!dir.isDirectory() || dir.isSymbolicLink()) throw unavailable2();
|
|
13921
|
-
const receipt = readJson2(receiptFile(stateDir, sourceRunId), 256 * 1024);
|
|
13922
|
-
if (receipt?.version !== 1 || receipt.nativeVersion !== "0.163.0" && receipt.nativeVersion !== "0.166.0" && receipt.nativeVersion !== "0.167.0" || receipt.runId !== sourceRunId || receipt.threadId !== threadId || !isDeepStrictEqual(receipt.catalogue, catalogue) || typeof receipt.historyPath !== "string") throw unavailable2();
|
|
13981
|
+
const dir = lstatSync9(join17(stateDir, "codex-mailbox"));
|
|
13982
|
+
if (!dir.isDirectory() || dir.isSymbolicLink()) throw unavailable2("mailbox_dir");
|
|
13983
|
+
const receipt = readJson2(receiptFile(stateDir, sourceRunId), 256 * 1024, false, "receipt");
|
|
13984
|
+
if (receipt?.version !== 1 || receipt.nativeVersion !== "0.163.0" && receipt.nativeVersion !== "0.166.0" && receipt.nativeVersion !== "0.167.0" || receipt.runId !== sourceRunId || receipt.threadId !== threadId || !isDeepStrictEqual(receipt.catalogue, catalogue) || typeof receipt.historyPath !== "string") throw unavailable2("receipt_mismatch");
|
|
13923
13985
|
verifyHistory(home, receipt.historyPath, threadId, catalogue);
|
|
13924
13986
|
return receipt.nativeVersion;
|
|
13925
|
-
} catch {
|
|
13926
|
-
throw unavailable2();
|
|
13987
|
+
} catch (error) {
|
|
13988
|
+
throw isUnavailable(error) ? error : unavailable2("verify", error);
|
|
13927
13989
|
}
|
|
13928
13990
|
}
|
|
13929
13991
|
function recordCodexMailboxSession(stateDir, runId, home, thread, catalogue, resumed, nativeVersion) {
|
|
13930
13992
|
try {
|
|
13931
|
-
if (!thread.id || typeof thread.path !== "string" || !isAbsolute4(thread.path)) throw unavailable2();
|
|
13993
|
+
if (!thread.id || typeof thread.path !== "string" || !isAbsolute4(thread.path)) throw unavailable2("thread_path");
|
|
13932
13994
|
const historyPath = relative4(home, thread.path).split(sep3).join("/");
|
|
13933
13995
|
historyParts(historyPath);
|
|
13934
13996
|
if (resumed) verifyHistory(home, historyPath, thread.id, catalogue);
|
|
13935
|
-
const dir =
|
|
13997
|
+
const dir = join17(stateDir, "codex-mailbox");
|
|
13936
13998
|
mkdirSync9(dir, { recursive: true, mode: 448 });
|
|
13937
13999
|
const stat3 = lstatSync9(dir);
|
|
13938
|
-
if (!stat3.isDirectory() || stat3.isSymbolicLink()) throw unavailable2();
|
|
14000
|
+
if (!stat3.isDirectory() || stat3.isSymbolicLink()) throw unavailable2("mailbox_dir");
|
|
13939
14001
|
writeJsonAtomic(receiptFile(stateDir, runId), { version: 1, nativeVersion, runId, threadId: thread.id, historyPath, catalogue });
|
|
13940
|
-
} catch {
|
|
13941
|
-
if (resumed) throw unavailable2();
|
|
14002
|
+
} catch (error) {
|
|
14003
|
+
if (resumed) throw isUnavailable(error) ? error : unavailable2("record", error);
|
|
13942
14004
|
}
|
|
13943
14005
|
}
|
|
13944
14006
|
|
|
@@ -14196,8 +14258,8 @@ var CodexAdapter = class {
|
|
|
14196
14258
|
options.continueSession.runId
|
|
14197
14259
|
).runDir;
|
|
14198
14260
|
carryHistory(
|
|
14199
|
-
|
|
14200
|
-
|
|
14261
|
+
join18(earlier2, "codex-home"),
|
|
14262
|
+
join18(runDir, "codex-home"),
|
|
14201
14263
|
CODEX_HISTORY
|
|
14202
14264
|
);
|
|
14203
14265
|
} catch (error) {
|
|
@@ -14208,7 +14270,7 @@ var CodexAdapter = class {
|
|
|
14208
14270
|
log.info({ err: error }, "could not copy the earlier codex threads");
|
|
14209
14271
|
}
|
|
14210
14272
|
}
|
|
14211
|
-
const codexHome = options.machineEnvironment ? { home: options.env.CODEX_HOME ??
|
|
14273
|
+
const codexHome = options.machineEnvironment ? { home: options.env.CODEX_HOME ?? join18(options.env.HOME, ".codex") } : prepareCodexHome(join18(runDir, "codex-home"), log);
|
|
14212
14274
|
if (options.machineEnvironment) mkdirSync10(codexHome.home, { recursive: true, mode: 448 });
|
|
14213
14275
|
const mailboxResumeVersion = mailboxCatalogue && threadId ? verifyCodexMailboxResume(
|
|
14214
14276
|
this.options.stateDir,
|
|
@@ -14416,7 +14478,15 @@ var CodexAdapter = class {
|
|
|
14416
14478
|
let quota;
|
|
14417
14479
|
let rateLimits;
|
|
14418
14480
|
let usage = { inputTokens: 0, outputTokens: 0 };
|
|
14419
|
-
|
|
14481
|
+
let turnUsage;
|
|
14482
|
+
const generations = new CodexGenerationMetrics((metrics) => {
|
|
14483
|
+
turnUsage = {
|
|
14484
|
+
inputTokens: (turnUsage?.inputTokens ?? 0) + (metrics.inputTokens ?? 0),
|
|
14485
|
+
outputTokens: (turnUsage?.outputTokens ?? 0) + (metrics.outputTokens ?? 0)
|
|
14486
|
+
};
|
|
14487
|
+
if (nativeGenerations) nativeGenerations.collector.observeFallback(metrics, sessionId);
|
|
14488
|
+
else daemonTracer.generation({ ...metrics, nativeUnavailableReason }, traceContext);
|
|
14489
|
+
});
|
|
14420
14490
|
const pendingMcp = /* @__PURE__ */ new Map();
|
|
14421
14491
|
const handInTools = /* @__PURE__ */ new Set([
|
|
14422
14492
|
"submit",
|
|
@@ -14599,11 +14669,14 @@ var CodexAdapter = class {
|
|
|
14599
14669
|
type: "data-usage",
|
|
14600
14670
|
data: {
|
|
14601
14671
|
...usage,
|
|
14672
|
+
turnUsage,
|
|
14673
|
+
model: runtimeModel ?? void 0,
|
|
14602
14674
|
// Priced later with the LiteLLM table (ADR 0003).
|
|
14603
14675
|
costUsd: null,
|
|
14604
14676
|
source: "codex app-server thread/tokenUsage"
|
|
14605
14677
|
}
|
|
14606
14678
|
});
|
|
14679
|
+
turnUsage = void 0;
|
|
14607
14680
|
if (ending) return;
|
|
14608
14681
|
if (cancelling) return finish({ outcome: "cancelled" });
|
|
14609
14682
|
const handoff = ctx.readHandoff(log);
|
|
@@ -14651,6 +14724,7 @@ var CodexAdapter = class {
|
|
|
14651
14724
|
throw new Error(SUBSCRIPTION_AUTH_ERROR, { cause: error });
|
|
14652
14725
|
}
|
|
14653
14726
|
}
|
|
14727
|
+
turnUsage = void 0;
|
|
14654
14728
|
generations.startTurn();
|
|
14655
14729
|
const result = rpc.sendRequest("turn/start", {
|
|
14656
14730
|
threadId: sessionId,
|
|
@@ -14852,7 +14926,7 @@ var CodexAdapter = class {
|
|
|
14852
14926
|
// src/adapters/cursor.ts
|
|
14853
14927
|
import { Readable, Writable } from "node:stream";
|
|
14854
14928
|
import * as acp from "@agentclientprotocol/sdk";
|
|
14855
|
-
import { join as
|
|
14929
|
+
import { join as join19 } from "node:path";
|
|
14856
14930
|
function cursorAppServers(apps) {
|
|
14857
14931
|
return [
|
|
14858
14932
|
...(apps?.apps ?? []).map((app) => ({ type: "http", name: app.name, url: app.url, headers: [{ name: "Authorization", value: `Bearer ${apps.token}` }] })),
|
|
@@ -14984,15 +15058,15 @@ var CursorAdapter = class {
|
|
|
14984
15058
|
options.continueSession.runId
|
|
14985
15059
|
).runDir;
|
|
14986
15060
|
carryHistory(
|
|
14987
|
-
|
|
14988
|
-
|
|
15061
|
+
join19(earlier2, "cursor-home"),
|
|
15062
|
+
join19(paths.runDir, "cursor-home"),
|
|
14989
15063
|
CURSOR_HISTORY
|
|
14990
15064
|
);
|
|
14991
15065
|
} catch (error) {
|
|
14992
15066
|
log.info({ err: error }, "could not copy the earlier cursor chats");
|
|
14993
15067
|
}
|
|
14994
15068
|
}
|
|
14995
|
-
const configDir = prepareCursorHome(
|
|
15069
|
+
const configDir = prepareCursorHome(join19(paths.runDir, "cursor-home"));
|
|
14996
15070
|
const ctx = new RunContext({
|
|
14997
15071
|
github: options.github,
|
|
14998
15072
|
githubEnvironment: options.githubEnvironment,
|
|
@@ -15227,7 +15301,7 @@ ${firstMessage}` : firstMessage
|
|
|
15227
15301
|
// src/adapters/mock.ts
|
|
15228
15302
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
15229
15303
|
import { mkdirSync as mkdirSync11, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "node:fs";
|
|
15230
|
-
import { dirname as dirname13, join as
|
|
15304
|
+
import { dirname as dirname13, join as join20, resolve as resolve12 } from "node:path";
|
|
15231
15305
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
15232
15306
|
import { execa as execa5 } from "execa";
|
|
15233
15307
|
|
|
@@ -15293,7 +15367,7 @@ var MockAdapter = class {
|
|
|
15293
15367
|
fixturesDir;
|
|
15294
15368
|
speed;
|
|
15295
15369
|
stateFile(sessionId) {
|
|
15296
|
-
return
|
|
15370
|
+
return join20(
|
|
15297
15371
|
this.options.stateDir,
|
|
15298
15372
|
`mock-${assertSafeId("session id", sessionId)}.json`
|
|
15299
15373
|
);
|
|
@@ -15337,7 +15411,7 @@ var MockAdapter = class {
|
|
|
15337
15411
|
open(sessionId, state2, options) {
|
|
15338
15412
|
const name = assertSafeId("fixture", state2.fixture.replace(/\.jsonl$/, ""));
|
|
15339
15413
|
const lines = parseFixture(
|
|
15340
|
-
readFileSync9(
|
|
15414
|
+
readFileSync9(join20(this.fixturesDir, `${name}.jsonl`), "utf8"),
|
|
15341
15415
|
name
|
|
15342
15416
|
);
|
|
15343
15417
|
const abort = new AbortController();
|
|
@@ -15452,12 +15526,12 @@ var MockAdapter = class {
|
|
|
15452
15526
|
// src/agents/local-github.ts
|
|
15453
15527
|
import { mkdirSync as mkdirSync13, mkdtempSync as mkdtempSync4, rmSync as rmSync10, writeFileSync as writeFileSync7 } from "node:fs";
|
|
15454
15528
|
import { homedir as homedir6 } from "node:os";
|
|
15455
|
-
import { delimiter as delimiter4, join as
|
|
15529
|
+
import { delimiter as delimiter4, join as join22 } from "node:path";
|
|
15456
15530
|
|
|
15457
15531
|
// src/agents/machine-github.ts
|
|
15458
|
-
import { existsSync as
|
|
15532
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync12, readFileSync as readFileSync10, renameSync as renameSync3, rmSync as rmSync9, writeFileSync as writeFileSync6 } from "node:fs";
|
|
15459
15533
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
15460
|
-
import { dirname as dirname14, join as
|
|
15534
|
+
import { dirname as dirname14, join as join21 } from "node:path";
|
|
15461
15535
|
function githubHosts(contents, token) {
|
|
15462
15536
|
if (!token || /[\r\n\0]/.test(token) || token.length > 32768) throw Error("github_credential_invalid");
|
|
15463
15537
|
const lines = contents.split(/\r?\n/);
|
|
@@ -15482,9 +15556,9 @@ function prepareMachineGitHub(github, host) {
|
|
|
15482
15556
|
if (!github.token) throw Error("github_credential_missing");
|
|
15483
15557
|
const home = host.env.HOME;
|
|
15484
15558
|
if (!home) throw Error("github_home_missing");
|
|
15485
|
-
const directory = host.env.GH_CONFIG_DIR ??
|
|
15486
|
-
const file =
|
|
15487
|
-
const original =
|
|
15559
|
+
const directory = host.env.GH_CONFIG_DIR ?? join21(host.env.XDG_CONFIG_HOME ?? join21(home, ".config"), "gh");
|
|
15560
|
+
const file = join21(directory, "hosts.yml");
|
|
15561
|
+
const original = existsSync5(file) ? readFileSync10(file, "utf8") : void 0;
|
|
15488
15562
|
let written;
|
|
15489
15563
|
let closed = false;
|
|
15490
15564
|
let timer;
|
|
@@ -15495,7 +15569,7 @@ function prepareMachineGitHub(github, host) {
|
|
|
15495
15569
|
if (credential.expiresAt !== null && (!Number.isFinite(Date.parse(credential.expiresAt)) || Date.parse(credential.expiresAt) <= Date.now()))
|
|
15496
15570
|
throw Error("github_credential_expired");
|
|
15497
15571
|
host.onCredential?.("GITHUB_TOKEN", credential.token);
|
|
15498
|
-
const latest =
|
|
15572
|
+
const latest = existsSync5(file) ? readFileSync10(file, "utf8") : "";
|
|
15499
15573
|
const next = githubHosts(latest, credential.token);
|
|
15500
15574
|
mkdirSync12(dirname14(file), { recursive: true, mode: 448 });
|
|
15501
15575
|
const temporary = `${file}.${randomUUID4()}`;
|
|
@@ -15537,7 +15611,7 @@ function prepareMachineGitHub(github, host) {
|
|
|
15537
15611
|
closed = true;
|
|
15538
15612
|
clearTimeout(timer);
|
|
15539
15613
|
host.signal.removeEventListener("abort", stopRefresh);
|
|
15540
|
-
if (!options?.retainCredential && written !== void 0 &&
|
|
15614
|
+
if (!options?.retainCredential && written !== void 0 && existsSync5(file) && readFileSync10(file, "utf8") === written) {
|
|
15541
15615
|
if (original === void 0) rmSync9(file, { force: true });
|
|
15542
15616
|
else writeFileSync6(file, original, { mode: 384 });
|
|
15543
15617
|
}
|
|
@@ -15583,14 +15657,14 @@ async function prepareLocalGitHub(assignment, host) {
|
|
|
15583
15657
|
const credential = assignment.github.token ? { token: assignment.github.token, expiresAt: assignment.github.expiresAt ?? null } : await lease();
|
|
15584
15658
|
if (host.signal.aborted) throw Error("github_run_closed");
|
|
15585
15659
|
mkdirSync13(host.stateDir, { recursive: true, mode: 448 });
|
|
15586
|
-
const directory = mkdtempSync4(
|
|
15660
|
+
const directory = mkdtempSync4(join22(host.stateDir, "github-"));
|
|
15587
15661
|
try {
|
|
15588
|
-
const bin =
|
|
15662
|
+
const bin = join22(directory, "bin");
|
|
15589
15663
|
const quote2 = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
15590
15664
|
const helper2 = `${process.versions.electron ? "env ELECTRON_RUN_AS_NODE=1 " : ""}${quote2(process.execPath)} ${quote2(GITHUB_CREDENTIAL_SCRIPT)}`;
|
|
15591
15665
|
if (binary) {
|
|
15592
15666
|
mkdirSync13(bin, { mode: 448 });
|
|
15593
|
-
writeFileSync7(
|
|
15667
|
+
writeFileSync7(join22(bin, "gh"), `#!/bin/sh
|
|
15594
15668
|
exec ${helper2} native-gh ${quote2(binary)} ${quote2(directory)} "$@"
|
|
15595
15669
|
`, { mode: 448, flag: "wx" });
|
|
15596
15670
|
}
|
|
@@ -15630,20 +15704,20 @@ exec ${helper2} native-gh ${quote2(binary)} ${quote2(directory)} "$@"
|
|
|
15630
15704
|
}
|
|
15631
15705
|
|
|
15632
15706
|
// src/agents/verify.ts
|
|
15633
|
-
import { existsSync as
|
|
15634
|
-
import { join as
|
|
15707
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync14, mkdtempSync as mkdtempSync5, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
|
|
15708
|
+
import { join as join23 } from "node:path";
|
|
15635
15709
|
var OUTPUT_TAIL = 4e3;
|
|
15636
15710
|
var SETUP_ATTEMPTS = 3;
|
|
15637
15711
|
async function runVerify(sandbox, options) {
|
|
15638
15712
|
options.signal?.throwIfAborted();
|
|
15639
15713
|
mkdirSync14(options.tmpRoot, { recursive: true, mode: 448 });
|
|
15640
|
-
const tmpDir = mkdtempSync5(
|
|
15714
|
+
const tmpDir = mkdtempSync5(join23(realpathSync11(options.tmpRoot), "verify-"));
|
|
15641
15715
|
const deadline = Date.now() + options.timeoutMs;
|
|
15642
15716
|
try {
|
|
15643
15717
|
for (let attempt = 1; ; attempt++) {
|
|
15644
|
-
const started =
|
|
15718
|
+
const started = join23(tmpDir, `.started-${attempt}`);
|
|
15645
15719
|
const result = await attemptVerify(sandbox, options, tmpDir, started, deadline - Date.now());
|
|
15646
|
-
if (result.exitCode === 0 || result.timedOut || options.signal?.aborted ||
|
|
15720
|
+
if (result.exitCode === 0 || result.timedOut || options.signal?.aborted || existsSync6(started) || attempt >= SETUP_ATTEMPTS)
|
|
15647
15721
|
return result;
|
|
15648
15722
|
}
|
|
15649
15723
|
} finally {
|
|
@@ -15660,7 +15734,7 @@ async function attemptVerify(sandbox, options, tmpDir, started, timeoutMs) {
|
|
|
15660
15734
|
policy: {
|
|
15661
15735
|
allowWrite: options.readOnly ? [tmpDir] : [options.worktree, tmpDir],
|
|
15662
15736
|
denyWrite: [
|
|
15663
|
-
|
|
15737
|
+
join23(options.worktree, ".git"),
|
|
15664
15738
|
...options.readOnly ? [options.worktree] : []
|
|
15665
15739
|
],
|
|
15666
15740
|
denyRead: [
|
|
@@ -15794,8 +15868,8 @@ import { execa as execa7 } from "execa";
|
|
|
15794
15868
|
// harness/install.mjs
|
|
15795
15869
|
import { createHash as createHash9, randomBytes as randomBytes2 } from "node:crypto";
|
|
15796
15870
|
import { execFile as execFile5 } from "node:child_process";
|
|
15797
|
-
import { createWriteStream as createWriteStream2, existsSync as
|
|
15798
|
-
import { dirname as dirname15, join as
|
|
15871
|
+
import { createWriteStream as createWriteStream2, existsSync as existsSync7, mkdirSync as mkdirSync15, readdirSync as readdirSync5, readFileSync as readFileSync11, renameSync as renameSync4, rmSync as rmSync12, statSync as statSync2, symlinkSync, writeFileSync as writeFileSync8 } from "node:fs";
|
|
15872
|
+
import { dirname as dirname15, join as join24, relative as relative6 } from "node:path";
|
|
15799
15873
|
import { Readable as Readable2, Transform } from "node:stream";
|
|
15800
15874
|
import { pipeline as pipeline2 } from "node:stream/promises";
|
|
15801
15875
|
import { promisify as promisify5 } from "node:util";
|
|
@@ -15844,17 +15918,17 @@ function resolvePin(store, harness) {
|
|
|
15844
15918
|
return { pin, artifact: pin.platforms[store.platform ?? platformKey()] };
|
|
15845
15919
|
}
|
|
15846
15920
|
function versionDir(store, harness) {
|
|
15847
|
-
return
|
|
15921
|
+
return join24(store.root, harness, resolvePin(store, harness).pin.version);
|
|
15848
15922
|
}
|
|
15849
15923
|
function harnessBinaryPath(store, harness) {
|
|
15850
|
-
return
|
|
15924
|
+
return join24(versionDir(store, harness), "bin", resolvePin(store, harness).pin.command);
|
|
15851
15925
|
}
|
|
15852
15926
|
function harnessInstallState(store, harness) {
|
|
15853
15927
|
const { pin, artifact } = resolvePin(store, harness);
|
|
15854
15928
|
if (!artifact) return { state: "unsupported", version: pin.version };
|
|
15855
15929
|
let installed = false;
|
|
15856
15930
|
try {
|
|
15857
|
-
installed = readFileSync11(
|
|
15931
|
+
installed = readFileSync11(join24(versionDir(store, harness), MARKER), "utf8") === installMarker(pin, artifact) && runtimeFiles(store, harness).every((path3) => {
|
|
15858
15932
|
const stat3 = statSync2(path3);
|
|
15859
15933
|
return stat3.isFile() && (stat3.mode & 73) !== 0;
|
|
15860
15934
|
});
|
|
@@ -15864,7 +15938,7 @@ function harnessInstallState(store, harness) {
|
|
|
15864
15938
|
}
|
|
15865
15939
|
function runtimeFiles(store, harness) {
|
|
15866
15940
|
const binary = harnessBinaryPath(store, harness);
|
|
15867
|
-
return harness === "codex" ? [binary,
|
|
15941
|
+
return harness === "codex" ? [binary, join24(dirname15(binary), "codex-code-mode-host")] : [binary];
|
|
15868
15942
|
}
|
|
15869
15943
|
function ensureHarness(store, harness) {
|
|
15870
15944
|
const key2 = `${store.root}\0${harness}`;
|
|
@@ -15881,29 +15955,29 @@ async function install(store, harness) {
|
|
|
15881
15955
|
if (state2 === "unsupported") throw new Error(`${harness} has no build for ${store.platform ?? platformKey()}`);
|
|
15882
15956
|
if (state2 === "installed") return binary;
|
|
15883
15957
|
const { pin, artifact } = resolvePin(store, harness);
|
|
15884
|
-
const parent =
|
|
15958
|
+
const parent = join24(store.root, harness);
|
|
15885
15959
|
mkdirSync15(parent, { recursive: true, mode: 448 });
|
|
15886
|
-
const staging =
|
|
15960
|
+
const staging = join24(parent, `.staging-${randomBytes2(6).toString("hex")}`);
|
|
15887
15961
|
mkdirSync15(staging, { recursive: true, mode: 448 });
|
|
15888
15962
|
try {
|
|
15889
|
-
const tarball =
|
|
15963
|
+
const tarball = join24(staging, "package.tgz");
|
|
15890
15964
|
await download(`${(store.pins ?? HARNESS_PINS).registry.replace(/\/$/, "")}/${artifact.tarball}`, tarball, artifact.integrity);
|
|
15891
15965
|
await run2("tar", ["-xzf", tarball, "-C", staging]);
|
|
15892
15966
|
if (harness === "codex") {
|
|
15893
15967
|
if (!artifact.entry.endsWith("/bin/codex")) throw new Error("Invalid Codex bundle entry");
|
|
15894
15968
|
const bundle = dirname15(dirname15(artifact.entry));
|
|
15895
|
-
for (const name of readdirSync5(
|
|
15969
|
+
for (const name of readdirSync5(join24(staging, bundle))) symlinkSync(relative6(staging, join24(staging, bundle, name)), join24(staging, name));
|
|
15896
15970
|
for (const name of ["codex", "codex-code-mode-host"]) {
|
|
15897
|
-
const stat3 = statSync2(
|
|
15971
|
+
const stat3 = statSync2(join24(staging, "bin", name));
|
|
15898
15972
|
if (!stat3.isFile() || (stat3.mode & 73) === 0) throw new Error("Incomplete Codex runtime bundle");
|
|
15899
15973
|
}
|
|
15900
15974
|
} else {
|
|
15901
|
-
mkdirSync15(
|
|
15902
|
-
symlinkSync(relative6(
|
|
15975
|
+
mkdirSync15(join24(staging, "bin"), { mode: 448 });
|
|
15976
|
+
symlinkSync(relative6(join24(staging, "bin"), join24(staging, artifact.entry)), join24(staging, "bin", pin.command));
|
|
15903
15977
|
}
|
|
15904
|
-
writeFileSync8(
|
|
15978
|
+
writeFileSync8(join24(staging, MARKER), installMarker(pin, artifact), { mode: 384 });
|
|
15905
15979
|
const target = versionDir(store, harness);
|
|
15906
|
-
const retained =
|
|
15980
|
+
const retained = existsSync7(target) ? `${target}.retained-${randomBytes2(6).toString("hex")}` : null;
|
|
15907
15981
|
if (retained) renameSync4(target, retained);
|
|
15908
15982
|
try {
|
|
15909
15983
|
renameSync4(staging, target);
|
|
@@ -15983,7 +16057,7 @@ function harnessFingerprint(store) {
|
|
|
15983
16057
|
// src/model-probe.ts
|
|
15984
16058
|
import { spawn as spawn3 } from "node:child_process";
|
|
15985
16059
|
import { mkdtempSync as mkdtempSync6, readdirSync as readdirSync6, rmSync as rmSync13 } from "node:fs";
|
|
15986
|
-
import { join as
|
|
16060
|
+
import { join as join25 } from "node:path";
|
|
15987
16061
|
|
|
15988
16062
|
// src/process-group.ts
|
|
15989
16063
|
async function stopGroup(child, graceMs = 3e3) {
|
|
@@ -16063,10 +16137,10 @@ function sweepModelProbeHomes(scratchDir) {
|
|
|
16063
16137
|
} catch {
|
|
16064
16138
|
return;
|
|
16065
16139
|
}
|
|
16066
|
-
for (const name of names) if (name.startsWith(HOME_PREFIX)) rmSync13(
|
|
16140
|
+
for (const name of names) if (name.startsWith(HOME_PREFIX)) rmSync13(join25(scratchDir, name), { recursive: true, force: true });
|
|
16067
16141
|
}
|
|
16068
16142
|
async function probeHarnessModels(harness, binary, options) {
|
|
16069
|
-
const home = mkdtempSync6(
|
|
16143
|
+
const home = mkdtempSync6(join25(options.scratchDir, HOME_PREFIX));
|
|
16070
16144
|
try {
|
|
16071
16145
|
return await exchange(harness, binary, home, options);
|
|
16072
16146
|
} finally {
|
|
@@ -16075,7 +16149,7 @@ async function probeHarnessModels(harness, binary, options) {
|
|
|
16075
16149
|
}
|
|
16076
16150
|
function exchange(harness, binary, home, options) {
|
|
16077
16151
|
const args = harness === "codex" ? ["app-server"] : ["-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose"];
|
|
16078
|
-
const env = { PATH: process.env.PATH ?? "", HOME: home, CODEX_HOME: home, CLAUDE_CONFIG_DIR:
|
|
16152
|
+
const env = { PATH: process.env.PATH ?? "", HOME: home, CODEX_HOME: home, CLAUDE_CONFIG_DIR: join25(home, ".claude"), LANG: process.env.LANG ?? "C.UTF-8" };
|
|
16079
16153
|
return new Promise((resolve20) => {
|
|
16080
16154
|
const child = (options.spawnImpl ?? spawn3)(binary, args, { env, cwd: home, detached: process.platform !== "win32", stdio: ["pipe", "pipe", "ignore"] });
|
|
16081
16155
|
let result;
|
|
@@ -16146,9 +16220,9 @@ function exchange(harness, binary, home, options) {
|
|
|
16146
16220
|
|
|
16147
16221
|
// src/cloud-registration.ts
|
|
16148
16222
|
import { createHash as createHash10 } from "node:crypto";
|
|
16149
|
-
import { join as
|
|
16223
|
+
import { join as join26 } from "node:path";
|
|
16150
16224
|
function writeCloudRegistration(dataDir, deviceId, workspaceId, credential) {
|
|
16151
|
-
writeJsonAtomic(
|
|
16225
|
+
writeJsonAtomic(join26(dataDir, "registration.json"), {
|
|
16152
16226
|
version: 1,
|
|
16153
16227
|
deviceId,
|
|
16154
16228
|
workspaceId,
|
|
@@ -16355,16 +16429,16 @@ async function prepareSubscriptionCredentials(assignment, host) {
|
|
|
16355
16429
|
|
|
16356
16430
|
// src/run-scratch.ts
|
|
16357
16431
|
import { rmSync as rmSync15 } from "node:fs";
|
|
16358
|
-
import { join as
|
|
16432
|
+
import { join as join27 } from "node:path";
|
|
16359
16433
|
function removeRunCredentials(stateDir, runId) {
|
|
16360
16434
|
const { runDir } = runPaths(stateDir, runId);
|
|
16361
|
-
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync15(
|
|
16435
|
+
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync15(join27(runDir, path3), { recursive: true, force: true });
|
|
16362
16436
|
}
|
|
16363
16437
|
|
|
16364
16438
|
// src/subscription-local-runner.ts
|
|
16365
16439
|
var unavailable3 = (detail, cause) => new CodedError("subscription_local_runtime_unavailable", { detail, cause });
|
|
16366
|
-
var
|
|
16367
|
-
var startFailed = (error) =>
|
|
16440
|
+
var isUnavailable2 = (error) => error instanceof CodedError && error.code === "subscription_local_runtime_unavailable";
|
|
16441
|
+
var startFailed = (error) => isUnavailable2(error) ? error : error instanceof SubscriptionCredentialError ? unavailable3(error.detail, error.cause ?? error) : unavailable3(findCodedError(error, "subscription_local_runtime_unavailable")?.detail ?? "adapter_start_failed", error);
|
|
16368
16442
|
function createLocalSubscriptionRunner(host) {
|
|
16369
16443
|
return {
|
|
16370
16444
|
async start(assignment, options) {
|
|
@@ -16457,7 +16531,7 @@ function createLocalSubscriptionRunner(host) {
|
|
|
16457
16531
|
|
|
16458
16532
|
// src/subscription-preflight.ts
|
|
16459
16533
|
import { mkdtempSync as mkdtempSync8, rmSync as rmSync16 } from "node:fs";
|
|
16460
|
-
import { join as
|
|
16534
|
+
import { join as join28 } from "node:path";
|
|
16461
16535
|
import { execa as execa8 } from "execa";
|
|
16462
16536
|
var refused = (detail, cause) => ({
|
|
16463
16537
|
ready: false,
|
|
@@ -16476,7 +16550,7 @@ async function preflightLocalSubscription(harness, options) {
|
|
|
16476
16550
|
const expected2 = (options.store.pins ?? HARNESS_PINS).harnesses[harness].version;
|
|
16477
16551
|
let home;
|
|
16478
16552
|
try {
|
|
16479
|
-
home = mkdtempSync8(
|
|
16553
|
+
home = mkdtempSync8(join28(options.scratchDir, "subscription-preflight-"));
|
|
16480
16554
|
const result = await execa8(binary, ["--version"], {
|
|
16481
16555
|
env: { ...env, HOME: home },
|
|
16482
16556
|
extendEnv: false,
|
|
@@ -16609,7 +16683,7 @@ import {
|
|
|
16609
16683
|
rmSync as rmSync17,
|
|
16610
16684
|
truncateSync
|
|
16611
16685
|
} from "node:fs";
|
|
16612
|
-
import { join as
|
|
16686
|
+
import { join as join29 } from "node:path";
|
|
16613
16687
|
var RETRY_MAX_MS = 3e4;
|
|
16614
16688
|
var Outbox = class {
|
|
16615
16689
|
constructor(dir, link, log, retryMs = 1e3, onUndeliverable = () => void 0, retainResources = false, traceContext = () => void 0) {
|
|
@@ -16637,10 +16711,10 @@ var Outbox = class {
|
|
|
16637
16711
|
/** Runs whose file was checked for a torn tail since this process started. */
|
|
16638
16712
|
repaired = /* @__PURE__ */ new Set();
|
|
16639
16713
|
file(runId) {
|
|
16640
|
-
return
|
|
16714
|
+
return join29(this.dir, `${assertSafeId("run id", runId)}.jsonl`);
|
|
16641
16715
|
}
|
|
16642
16716
|
ackFile(runId) {
|
|
16643
|
-
return
|
|
16717
|
+
return join29(this.dir, `${assertSafeId("run id", runId)}.ack.json`);
|
|
16644
16718
|
}
|
|
16645
16719
|
parse(runId) {
|
|
16646
16720
|
let data;
|
|
@@ -17118,6 +17192,405 @@ var RunJournal = class {
|
|
|
17118
17192
|
}
|
|
17119
17193
|
};
|
|
17120
17194
|
|
|
17195
|
+
// src/runs/publication.ts
|
|
17196
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
17197
|
+
import { lstatSync as lstatSync11, readFileSync as readFileSync14, readdirSync as readdirSync8 } from "node:fs";
|
|
17198
|
+
import { join as join30 } from "node:path";
|
|
17199
|
+
import { execa as execa10 } from "execa";
|
|
17200
|
+
|
|
17201
|
+
// src/runs/check.ts
|
|
17202
|
+
import { execa as execa9 } from "execa";
|
|
17203
|
+
async function fixedCheckSnapshot(repoPath, worktree, sha6, signal) {
|
|
17204
|
+
signal?.throwIfAborted();
|
|
17205
|
+
if (!/^[a-f0-9]{40}$/.test(sha6))
|
|
17206
|
+
throw new Error("Check requires an exact candidate SHA");
|
|
17207
|
+
const gitDir = await worktreeGitDir(repoPath, worktree, signal);
|
|
17208
|
+
const git3 = async (...args) => (await execa9(
|
|
17209
|
+
"git",
|
|
17210
|
+
[
|
|
17211
|
+
"-c",
|
|
17212
|
+
"core.hooksPath=/dev/null",
|
|
17213
|
+
"-c",
|
|
17214
|
+
"core.fsmonitor=false",
|
|
17215
|
+
...args
|
|
17216
|
+
],
|
|
17217
|
+
{
|
|
17218
|
+
cwd: worktree,
|
|
17219
|
+
env: { GIT_DIR: gitDir, GIT_WORK_TREE: worktree },
|
|
17220
|
+
stdin: "ignore",
|
|
17221
|
+
cancelSignal: signal,
|
|
17222
|
+
killDescendants: true
|
|
17223
|
+
}
|
|
17224
|
+
)).stdout.trim();
|
|
17225
|
+
if (await git3("rev-parse", "HEAD") !== sha6)
|
|
17226
|
+
throw new Error("Check worktree HEAD differs from the fixed candidate");
|
|
17227
|
+
if (await git3("status", "--porcelain"))
|
|
17228
|
+
throw new Error(
|
|
17229
|
+
"Check worktree contains changes outside the fixed candidate"
|
|
17230
|
+
);
|
|
17231
|
+
return { sha: sha6, tree: await git3("rev-parse", `${sha6}^{tree}`) };
|
|
17232
|
+
}
|
|
17233
|
+
|
|
17234
|
+
// src/runs/publication.ts
|
|
17235
|
+
var VERIFY_TIMEOUT_MS = 30 * 6e4;
|
|
17236
|
+
var MAX_REPORTED_FILES = 5e3;
|
|
17237
|
+
var MAX_REPORTED_CRITERIA = 200;
|
|
17238
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
17239
|
+
async function verifyAndPublish(context, event) {
|
|
17240
|
+
const { assignment, repo, worktree, signal } = context;
|
|
17241
|
+
const initialStopReason = context.getStopReason();
|
|
17242
|
+
const error = event.error ?? (initialStopReason === "turn_ended" ? "Session ended without a submission" : initialStopReason === "timeout" ? "No progress before the watchdog limit" : initialStopReason === "device_lost" ? "Run lease expired; the server could not be reached" : void 0);
|
|
17243
|
+
let outcome;
|
|
17244
|
+
try {
|
|
17245
|
+
if (assignment.benchmark && !context.cancelRequested) {
|
|
17246
|
+
const fixed = await fixedCheckSnapshot(repo.path, worktree, assignment.benchmark.sourceCommit, signal);
|
|
17247
|
+
if (createHash11("sha256").update(fixed.sha).digest("hex") !== assignment.benchmark.fixtureDigest)
|
|
17248
|
+
throw new Error("Benchmark fixture changed during model execution");
|
|
17249
|
+
}
|
|
17250
|
+
outcome = await collectReport(context, initialStopReason, error, event.report);
|
|
17251
|
+
} catch (error2) {
|
|
17252
|
+
if (!signal.aborted) throw error2;
|
|
17253
|
+
outcome = { report: { ...baseReport(), ...pickAgentReport(event.report) } };
|
|
17254
|
+
}
|
|
17255
|
+
if (context.isStopping()) return;
|
|
17256
|
+
const stopReason = context.getStopReason();
|
|
17257
|
+
const { verifyError, tree } = outcome;
|
|
17258
|
+
let report2 = stopReason === "quota_exhausted" ? { ...outcome.report, resetsAt: event.quota?.resetsAt ?? null } : outcome.report;
|
|
17259
|
+
if (stopReason === "provider_failure") {
|
|
17260
|
+
report2 = {
|
|
17261
|
+
...report2,
|
|
17262
|
+
providerFailure: providerFailureSchema.parse(event.providerFailure),
|
|
17263
|
+
...event.quota ? { resetsAt: event.quota.resetsAt } : {}
|
|
17264
|
+
};
|
|
17265
|
+
}
|
|
17266
|
+
const policy = runPolicy(assignment.policy);
|
|
17267
|
+
const { publisher } = context.deps;
|
|
17268
|
+
if (stopReason === "submitted" && report2.verify.status !== "failed" && tree && publisher && // The draft-PR exception requires an explicit repository push
|
|
17269
|
+
// approval. It must not even create a local commit without it.
|
|
17270
|
+
(report2.verify.status === "passed" || pushDecision(policy).push) && // A read-only check (ADR 0046) never commits or pushes: it reports
|
|
17271
|
+
// on the commit the implementation run already pushed.
|
|
17272
|
+
policy.readOnly !== true) {
|
|
17273
|
+
const publish = await publishRun2(context, publisher, report2, tree);
|
|
17274
|
+
report2 = { ...report2, publish };
|
|
17275
|
+
}
|
|
17276
|
+
return { report: report2, error: error ?? verifyError };
|
|
17277
|
+
}
|
|
17278
|
+
function finishRun(context, stopReason, error, report2 = baseReport(error), failureDetails) {
|
|
17279
|
+
const { runId, journal, active } = context;
|
|
17280
|
+
if (active?.cancelRequested || active?.forcedStop) {
|
|
17281
|
+
stopReason = active.forcedStop ?? "cancelled";
|
|
17282
|
+
error = void 0;
|
|
17283
|
+
}
|
|
17284
|
+
active?.span?.set("mikka.outcome", stopReason);
|
|
17285
|
+
if (stopReason !== "provider_failure" && report2.providerFailure) {
|
|
17286
|
+
const { providerFailure: _failure, ...rest } = report2;
|
|
17287
|
+
report2 = rest;
|
|
17288
|
+
}
|
|
17289
|
+
if (stopReason !== "provider_failure" && stopReason !== "quota_exhausted" && report2.providerCheckpoint) {
|
|
17290
|
+
const { providerCheckpoint: _checkpoint, ...rest } = report2;
|
|
17291
|
+
report2 = rest;
|
|
17292
|
+
}
|
|
17293
|
+
const entry = journal.get(runId);
|
|
17294
|
+
const planning = entry?.assignment.kind === "plan";
|
|
17295
|
+
if (entry && stopReason === "blocked" && report2.repositorySelection)
|
|
17296
|
+
entry.assignment.preserveQuestionWorktree = true;
|
|
17297
|
+
const readOnlyTask = entry && (isReadOnlyTask(entry.assignment) || entry.assignment.factoryCheck?.reportOnly === true || entry.assignment.factoryExecuteKind === "deliverable");
|
|
17298
|
+
const { sourceCommit: _source, deliverableCommit: _delivery, skillMount: _mount, skillPrompt: _prompt, execution: _execution, runtime: _runtime, safePoint: _safePoint, ...content } = report2;
|
|
17299
|
+
report2 = {
|
|
17300
|
+
...content,
|
|
17301
|
+
...active?.safePoint ? { safePoint: active.safePoint } : {},
|
|
17302
|
+
...entry?.baseCommit && /^[a-f0-9]{40}$/.test(entry.baseCommit) ? { sourceCommit: entry.baseCommit } : {},
|
|
17303
|
+
...entry?.assignment.factoryExecuteKind === "deliverable" && entry.deliverableCommit ? { deliverableCommit: entry.deliverableCommit } : {},
|
|
17304
|
+
// What the prompt actually carried of the run's skills; a deferred body
|
|
17305
|
+
// is a fact the person needs to see, not something to leave unsaid.
|
|
17306
|
+
...entry && skillPromptOf(entry.assignment) ? { skillPrompt: skillPromptOf(entry.assignment) } : {},
|
|
17307
|
+
...entry?.skillMount && entry.skillMount.sessionId === entry.sessionId && entry.skillMount.receiptId === entry.assignment.skillReceipt?.id && entry.skillMount.versionId === entry.assignment.skillReceipt?.artifact.versionId && entry.skillMount.sha256 === entry.assignment.skillReceipt?.artifact.sha256 ? {
|
|
17308
|
+
skillMount: entry.skillMount,
|
|
17309
|
+
...entry.runtime ? { runtime: {
|
|
17310
|
+
...entry.runtime,
|
|
17311
|
+
observedModel: active?.session?.runtimeModel ?? entry.runtime.observedModel
|
|
17312
|
+
} } : {},
|
|
17313
|
+
...entry.execution && entry.assignment.benchmark ? { execution: {
|
|
17314
|
+
...entry.execution,
|
|
17315
|
+
observedModel: active?.session?.runtimeModel ?? entry.execution.observedModel
|
|
17316
|
+
} } : {}
|
|
17317
|
+
} : {}
|
|
17318
|
+
};
|
|
17319
|
+
context.closeOutput(report2, planning);
|
|
17320
|
+
if (stopReason === "submitted") context.setState("finishing");
|
|
17321
|
+
let state2 = runStateForStop(stopReason);
|
|
17322
|
+
if (stopReason === "submitted" && report2.verify.status !== "passed") {
|
|
17323
|
+
const failed = report2.verify.status === "failed";
|
|
17324
|
+
if (!planning && !readOnlyTask) state2 = failed ? "failed" : report2.publish?.pushed === true ? "succeeded" : "stopped";
|
|
17325
|
+
if (!failed && !planning && !readOnlyTask)
|
|
17326
|
+
error ??= "Submitted, but no verify command ran; the work is unverified";
|
|
17327
|
+
}
|
|
17328
|
+
if ((stopReason === "asked_human" || stopReason === "blocked") && report2.question) {
|
|
17329
|
+
journal.update(runId, {
|
|
17330
|
+
waitingQuestionId: report2.question.questionId
|
|
17331
|
+
});
|
|
17332
|
+
}
|
|
17333
|
+
if (state2 === "failed") active?.span?.fail({ name: "RunFailure" }, stopReason);
|
|
17334
|
+
else active?.span?.set("mikka.outcome", stopReason);
|
|
17335
|
+
context.setState(state2, {
|
|
17336
|
+
stopReason,
|
|
17337
|
+
...error ? { error } : {}
|
|
17338
|
+
});
|
|
17339
|
+
const terminalFailure = state2 === "failed" && !active?.cancelRequested && !active?.forcedStop ? captureRunFailure(failureDetails ?? new Error(error ?? report2.summary), {
|
|
17340
|
+
runId,
|
|
17341
|
+
appVersion: DAEMON_VERSION,
|
|
17342
|
+
sensitiveText: [entry?.assignment.prompt ?? ""]
|
|
17343
|
+
}) : void 0;
|
|
17344
|
+
context.complete({ stopReason, report: report2, ...terminalFailure ? { failureDetails: terminalFailure } : {} });
|
|
17345
|
+
}
|
|
17346
|
+
async function collectReport(context, stopReason, error, agent) {
|
|
17347
|
+
const { deps, runId, worktree, repo, assignment, signal } = context;
|
|
17348
|
+
const profileSkills = profileSkillReport(runId, assignment, deps.adapterStateDir);
|
|
17349
|
+
let report2 = {
|
|
17350
|
+
...baseReport(error),
|
|
17351
|
+
...pickAgentReport(agent),
|
|
17352
|
+
...profileSkills ? { profileSkills } : {}
|
|
17353
|
+
};
|
|
17354
|
+
const filesChanged = (await deps.worktrees.changedFiles(worktree, deps.journal.get(runId)?.baseCommit).catch(() => [])).slice(0, MAX_REPORTED_FILES);
|
|
17355
|
+
const inferred = assignment.factoryCheck?.stage === "verify" && assignment.factoryCheck.inferCommand && !assignment.factoryCheck.reportOnly ? report2.verificationCommand : void 0;
|
|
17356
|
+
const command = assignment.verifyCommand ?? inferred?.command;
|
|
17357
|
+
if (stopReason === "submitted") context.assertLive();
|
|
17358
|
+
if (stopReason === "submitted" && assignment.factoryExecuteKind === "deliverable") {
|
|
17359
|
+
const deliverableCommit = await retainDeliverable(repo.path, worktree, runId, signal);
|
|
17360
|
+
context.assertLive();
|
|
17361
|
+
deps.journal.update(runId, { deliverableCommit });
|
|
17362
|
+
}
|
|
17363
|
+
if (stopReason !== "submitted" && fixedCandidateCheck(assignment)) {
|
|
17364
|
+
const fixed = await fixedCheckSnapshot(repo.path, worktree, assignment.baseBranch, signal).catch(() => null);
|
|
17365
|
+
if (fixed) report2 = { ...report2, check: { sha: fixed.sha, readOnly: true } };
|
|
17366
|
+
}
|
|
17367
|
+
if (stopReason !== "submitted" || assignment.kind === "plan" || isReadOnlyTask(assignment) || assignment.factoryExecuteKind === "deliverable")
|
|
17368
|
+
return {
|
|
17369
|
+
report: { ...report2, filesChanged, verify: { status: "not_run" } }
|
|
17370
|
+
};
|
|
17371
|
+
if (!command) {
|
|
17372
|
+
if (fixedCandidateCheck(assignment)) {
|
|
17373
|
+
const fixed = await fixedCheckSnapshot(repo.path, worktree, assignment.baseBranch, signal);
|
|
17374
|
+
report2 = { ...report2, check: { sha: fixed.sha, readOnly: true } };
|
|
17375
|
+
}
|
|
17376
|
+
context.assertLive();
|
|
17377
|
+
const tree = await deps.publisher?.snapshot({ worktree, repo, signal });
|
|
17378
|
+
context.assertLive();
|
|
17379
|
+
return { report: { ...report2, filesChanged, verify: { status: "not_run" } }, tree };
|
|
17380
|
+
}
|
|
17381
|
+
let execution = {};
|
|
17382
|
+
const failed = (output2, verifyError) => ({
|
|
17383
|
+
report: {
|
|
17384
|
+
...report2,
|
|
17385
|
+
filesChanged,
|
|
17386
|
+
verify: { status: "failed", command, output: output2, ...execution }
|
|
17387
|
+
},
|
|
17388
|
+
verifyError
|
|
17389
|
+
});
|
|
17390
|
+
const publisher = deps.publisher;
|
|
17391
|
+
let before;
|
|
17392
|
+
try {
|
|
17393
|
+
if (fixedCandidateCheck(assignment)) {
|
|
17394
|
+
if (runPolicy(assignment.policy).readOnly !== true)
|
|
17395
|
+
throw new Error("Check assignment is missing its read-only policy");
|
|
17396
|
+
const fixed = await fixedCheckSnapshot(
|
|
17397
|
+
repo.path,
|
|
17398
|
+
worktree,
|
|
17399
|
+
assignment.baseBranch,
|
|
17400
|
+
signal
|
|
17401
|
+
);
|
|
17402
|
+
report2 = { ...report2, check: { sha: fixed.sha, readOnly: true } };
|
|
17403
|
+
before = fixed.tree;
|
|
17404
|
+
} else {
|
|
17405
|
+
before = await publisher?.snapshot({ worktree, repo, signal });
|
|
17406
|
+
}
|
|
17407
|
+
} catch (snapshotError) {
|
|
17408
|
+
signal.throwIfAborted();
|
|
17409
|
+
return failed("", `Could not read the worktree: ${String(snapshotError)}`);
|
|
17410
|
+
}
|
|
17411
|
+
context.assertLive();
|
|
17412
|
+
const result = await (deps.verify ?? unsandboxedVerify)({
|
|
17413
|
+
runId,
|
|
17414
|
+
worktree,
|
|
17415
|
+
repo,
|
|
17416
|
+
command,
|
|
17417
|
+
timeoutMs: VERIFY_TIMEOUT_MS,
|
|
17418
|
+
signal,
|
|
17419
|
+
readOnly: runPolicy(assignment.policy).readOnly === true,
|
|
17420
|
+
githubEnvironment: context.githubEnvironment()
|
|
17421
|
+
});
|
|
17422
|
+
context.assertLive();
|
|
17423
|
+
execution = {
|
|
17424
|
+
exitCode: result.exitCode,
|
|
17425
|
+
signal: result.signal,
|
|
17426
|
+
timedOut: result.timedOut
|
|
17427
|
+
};
|
|
17428
|
+
const output = result.output.slice(-4e3);
|
|
17429
|
+
if (result.exitCode !== 0 || result.timedOut)
|
|
17430
|
+
return failed(output, verifyFailure(command, result));
|
|
17431
|
+
const after = fixedCandidateCheck(assignment) ? await fixedCheckSnapshot(repo.path, worktree, assignment.baseBranch, signal).then((fixed) => fixed.tree).catch(() => null) : publisher ? await publisher.snapshot({ worktree, repo, signal }).catch(() => null) : void 0;
|
|
17432
|
+
context.assertLive();
|
|
17433
|
+
if (after !== before)
|
|
17434
|
+
return failed(
|
|
17435
|
+
output,
|
|
17436
|
+
`Submitted, but the verify command changed the worktree (\`${command}\`); the work is unverified`
|
|
17437
|
+
);
|
|
17438
|
+
return {
|
|
17439
|
+
report: {
|
|
17440
|
+
...report2,
|
|
17441
|
+
filesChanged,
|
|
17442
|
+
verify: { status: "passed", command, output, ...inferred ? { inferredFrom: inferred.basis } : {}, ...execution }
|
|
17443
|
+
},
|
|
17444
|
+
tree: before
|
|
17445
|
+
};
|
|
17446
|
+
}
|
|
17447
|
+
async function publishRun2(context, publisher, report2, tree) {
|
|
17448
|
+
const { runId, worktree, repo, assignment, signal } = context;
|
|
17449
|
+
let data;
|
|
17450
|
+
try {
|
|
17451
|
+
context.assertLive();
|
|
17452
|
+
data = await publisher.publish({
|
|
17453
|
+
runId,
|
|
17454
|
+
worktree,
|
|
17455
|
+
repo,
|
|
17456
|
+
assignment,
|
|
17457
|
+
report: report2,
|
|
17458
|
+
tree,
|
|
17459
|
+
githubEnvironment: context.githubEnvironment(),
|
|
17460
|
+
signal
|
|
17461
|
+
});
|
|
17462
|
+
} catch (error) {
|
|
17463
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
17464
|
+
if (!signal.aborted) context.logPublishError(error);
|
|
17465
|
+
data = {
|
|
17466
|
+
branch: "",
|
|
17467
|
+
commit: null,
|
|
17468
|
+
pushed: false,
|
|
17469
|
+
remote: null,
|
|
17470
|
+
note: signal.aborted ? "Run stopped before publication completed" : `Commit failed: ${message}`.slice(0, 2e3)
|
|
17471
|
+
};
|
|
17472
|
+
}
|
|
17473
|
+
context.emitPublish(data);
|
|
17474
|
+
return data;
|
|
17475
|
+
}
|
|
17476
|
+
function profileSkillReport(runId, assignment, adapterStateDir) {
|
|
17477
|
+
const configured = (assignment.profileSkills ?? []).map((skill) => ({ id: skill.id, name: skill.name, source: skill.source, digest: skill.digest }));
|
|
17478
|
+
for (const slug of assignment.repositorySkills ?? []) {
|
|
17479
|
+
if (!configured.some((ref) => ref.id === `repository:${slug}`)) configured.push({ id: `repository:${slug}`, name: slug, source: "repository", digest: null });
|
|
17480
|
+
}
|
|
17481
|
+
if (configured.length === 0) return void 0;
|
|
17482
|
+
const loaded = [];
|
|
17483
|
+
if (adapterStateDir) {
|
|
17484
|
+
const dir = join30(runPaths(adapterStateDir, runId).runDir, PROFILE_SKILLS_DIR, PROFILE_SKILL_LOADS_DIR);
|
|
17485
|
+
try {
|
|
17486
|
+
for (const name of readdirSync8(dir).sort()) {
|
|
17487
|
+
if (!name.endsWith(".json") || loaded.length >= configured.length) continue;
|
|
17488
|
+
const file = join30(dir, name), meta = lstatSync11(file, { throwIfNoEntry: false });
|
|
17489
|
+
if (!meta?.isFile() || meta.isSymbolicLink() || meta.nlink !== 1 || meta.size < 2 || meta.size > 4096) continue;
|
|
17490
|
+
const receipt = profileSkillLoadReceiptSchema.safeParse(JSON.parse(readFileSync14(file, "utf8")));
|
|
17491
|
+
if (!receipt.success || loaded.some((item) => item.id === receipt.data.id)) continue;
|
|
17492
|
+
if (!configured.some((ref) => ref.id === receipt.data.id && (ref.digest === null || ref.digest === receipt.data.digest))) continue;
|
|
17493
|
+
loaded.push(receipt.data);
|
|
17494
|
+
}
|
|
17495
|
+
} catch {
|
|
17496
|
+
}
|
|
17497
|
+
}
|
|
17498
|
+
return { configured, loaded };
|
|
17499
|
+
}
|
|
17500
|
+
function pickAgentReport(agent) {
|
|
17501
|
+
if (!agent) return {};
|
|
17502
|
+
const picked = {};
|
|
17503
|
+
if (agent.repositorySelection) picked.repositorySelection = agent.repositorySelection;
|
|
17504
|
+
if (agent.verificationCommand && typeof agent.verificationCommand.command === "string" && agent.verificationCommand.command.trim() && typeof agent.verificationCommand.basis === "string" && agent.verificationCommand.basis.trim())
|
|
17505
|
+
picked.verificationCommand = { command: agent.verificationCommand.command.trim().slice(0, 2e3), basis: agent.verificationCommand.basis.trim().slice(0, 2e3) };
|
|
17506
|
+
const visualEvidence = runVisualEvidence.safeParse(agent.visualEvidence);
|
|
17507
|
+
if (visualEvidence.success) picked.visualEvidence = visualEvidence.data;
|
|
17508
|
+
const verdict = reviewVerdict.safeParse(agent.reviewVerdict);
|
|
17509
|
+
if (verdict.success) picked.reviewVerdict = verdict.data;
|
|
17510
|
+
if (typeof agent.summary === "string")
|
|
17511
|
+
picked.summary = agent.summary.slice(0, 1e4);
|
|
17512
|
+
if (Array.isArray(agent.openQuestions) && agent.openQuestions.every((q) => typeof q === "string"))
|
|
17513
|
+
picked.openQuestions = agent.openQuestions.slice(0, 50).map((q) => q.slice(0, 2e3));
|
|
17514
|
+
if (typeof agent.nextStep === "string")
|
|
17515
|
+
picked.nextStep = agent.nextStep.slice(0, 2e3);
|
|
17516
|
+
else if (agent.nextStep === null) picked.nextStep = null;
|
|
17517
|
+
if (typeof agent.blockedOn === "string")
|
|
17518
|
+
picked.blockedOn = agent.blockedOn.slice(0, 500);
|
|
17519
|
+
const question = runQuestion.safeParse(agent.question);
|
|
17520
|
+
if (question.success) picked.question = question.data;
|
|
17521
|
+
if (agent.plan) picked.plan = agent.plan;
|
|
17522
|
+
if (typeof agent.previewDatabaseBranch === "string" && agent.previewDatabaseBranch.trim())
|
|
17523
|
+
picked.previewDatabaseBranch = agent.previewDatabaseBranch.trim().slice(0, 500);
|
|
17524
|
+
if (Array.isArray(agent.criteria)) {
|
|
17525
|
+
const criteria = [];
|
|
17526
|
+
for (const entry of agent.criteria) {
|
|
17527
|
+
if (criteria.length >= MAX_REPORTED_CRITERIA) break;
|
|
17528
|
+
if (!entry || typeof entry !== "object") continue;
|
|
17529
|
+
const { criterionId, text: text4, passed, status: status3, reason, resolution, evidence, command, exitCode } = entry;
|
|
17530
|
+
if (!(typeof criterionId === "string" && UUID_RE.test(criterionId)) && !(typeof text4 === "string" && text4.trim()))
|
|
17531
|
+
continue;
|
|
17532
|
+
if (typeof passed !== "boolean") continue;
|
|
17533
|
+
const criterion = runCriterion.safeParse({
|
|
17534
|
+
...typeof criterionId === "string" && UUID_RE.test(criterionId) ? { criterionId } : {},
|
|
17535
|
+
...typeof text4 === "string" && text4.trim() ? { text: text4.trim().slice(0, 2e3) } : {},
|
|
17536
|
+
passed,
|
|
17537
|
+
...status3 !== void 0 ? { status: status3 } : {},
|
|
17538
|
+
...typeof reason === "string" && reason.trim() ? { reason: reason.trim().slice(0, 2e3) } : {},
|
|
17539
|
+
...typeof resolution === "string" && resolution.trim() ? { resolution: resolution.trim().slice(0, 2e3) } : {},
|
|
17540
|
+
...typeof command === "string" && command.trim() ? { command: command.trim().slice(0, 2e3), ...exitCode === null || typeof exitCode === "number" && Number.isSafeInteger(exitCode) ? { exitCode } : {} } : {},
|
|
17541
|
+
...typeof evidence === "string" ? { evidence: evidence.slice(0, 1e4) } : {}
|
|
17542
|
+
});
|
|
17543
|
+
if (criterion.success) criteria.push(criterion.data);
|
|
17544
|
+
}
|
|
17545
|
+
picked.criteria = criteria;
|
|
17546
|
+
}
|
|
17547
|
+
return picked;
|
|
17548
|
+
}
|
|
17549
|
+
async function unsandboxedVerify(run3) {
|
|
17550
|
+
const result = await execa10(run3.command, {
|
|
17551
|
+
shell: true,
|
|
17552
|
+
cwd: run3.worktree,
|
|
17553
|
+
env: buildChildEnv(),
|
|
17554
|
+
extendEnv: false,
|
|
17555
|
+
reject: false,
|
|
17556
|
+
all: true,
|
|
17557
|
+
stdin: "ignore",
|
|
17558
|
+
timeout: run3.timeoutMs,
|
|
17559
|
+
cancelSignal: run3.signal,
|
|
17560
|
+
killDescendants: true
|
|
17561
|
+
});
|
|
17562
|
+
return {
|
|
17563
|
+
exitCode: result.exitCode ?? null,
|
|
17564
|
+
signal: result.signal ?? null,
|
|
17565
|
+
timedOut: result.timedOut,
|
|
17566
|
+
output: String(result.all ?? "")
|
|
17567
|
+
};
|
|
17568
|
+
}
|
|
17569
|
+
function verifyFailure(command, result) {
|
|
17570
|
+
const how = result.timedOut ? "timed out" : result.exitCode !== null ? `exited with code ${result.exitCode}` : result.signal ? `was killed by ${result.signal}` : "did not finish";
|
|
17571
|
+
return `Submitted, but the verify command failed: \`${command}\` ${how}`;
|
|
17572
|
+
}
|
|
17573
|
+
function baseReport(summary = "") {
|
|
17574
|
+
return emptyRunReport(summary.slice(0, 1e4));
|
|
17575
|
+
}
|
|
17576
|
+
function isReadOnlyTask(assignment) {
|
|
17577
|
+
return runPolicy(assignment.policy).readOnly === true && assignment.kind !== "acceptance" && !assignment.benchmark;
|
|
17578
|
+
}
|
|
17579
|
+
function skillPromptOf(assignment) {
|
|
17580
|
+
const skills = assignment.skills;
|
|
17581
|
+
if (!skills?.length) return void 0;
|
|
17582
|
+
const plan = skillPromptPlan(skills);
|
|
17583
|
+
return {
|
|
17584
|
+
budgetChars: plan.budgetChars,
|
|
17585
|
+
usedChars: plan.usedChars,
|
|
17586
|
+
inlined: plan.inlined.map((entry) => entry.name),
|
|
17587
|
+
deferred: plan.degraded.map((entry) => entry.name)
|
|
17588
|
+
};
|
|
17589
|
+
}
|
|
17590
|
+
function fixedCandidateCheck(assignment) {
|
|
17591
|
+
return assignment.kind === "acceptance" && runPolicy(assignment.policy).readOnly === true && typeof assignment.baseBranch === "string" && /^[a-f0-9]{40}$/.test(assignment.baseBranch);
|
|
17592
|
+
}
|
|
17593
|
+
|
|
17121
17594
|
// src/tool-duration.ts
|
|
17122
17595
|
function toolDuration(clock = () => performance.now()) {
|
|
17123
17596
|
const starts = /* @__PURE__ */ new Map();
|
|
@@ -17341,9 +17814,9 @@ async function startTaskSecretBridge(options) {
|
|
|
17341
17814
|
}
|
|
17342
17815
|
|
|
17343
17816
|
// src/agents/chat-files.ts
|
|
17344
|
-
import { createHash as
|
|
17817
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
17345
17818
|
import { lstat as lstat4, mkdir as mkdir4, readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
|
|
17346
|
-
import { join as
|
|
17819
|
+
import { join as join31 } from "node:path";
|
|
17347
17820
|
async function materializeChatFiles(text4, directory, download2) {
|
|
17348
17821
|
const parsed = splitChatFiles(text4);
|
|
17349
17822
|
if (!parsed.files.length) return text4;
|
|
@@ -17355,19 +17828,19 @@ async function materializeChatFiles(text4, directory, download2) {
|
|
|
17355
17828
|
const file = chatFileDownloadSchema.parse(await download2(ref.id));
|
|
17356
17829
|
if (file.id !== ref.id) throw Error("Attachment identity mismatch");
|
|
17357
17830
|
const bytes = Buffer.from(file.data, "base64");
|
|
17358
|
-
if (bytes.length !== file.size || bytes.toString("base64") !== file.data ||
|
|
17831
|
+
if (bytes.length !== file.size || bytes.toString("base64") !== file.data || createHash12("sha256").update(bytes).digest("hex") !== file.sha256)
|
|
17359
17832
|
throw Error("Attachment content mismatch");
|
|
17360
17833
|
const ext = /\.([a-z0-9]{1,12})$/i.exec(file.name)?.[1]?.toLowerCase() ?? "bin";
|
|
17361
|
-
const path3 =
|
|
17834
|
+
const path3 = join31(directory, `${file.id}.${ext}`);
|
|
17362
17835
|
try {
|
|
17363
17836
|
await writeFile3(path3, bytes, { flag: "wx", mode: 256 });
|
|
17364
17837
|
} catch (error) {
|
|
17365
|
-
if (error.code !== "EEXIST" || (await lstat4(path3)).isSymbolicLink() ||
|
|
17838
|
+
if (error.code !== "EEXIST" || (await lstat4(path3)).isSymbolicLink() || createHash12("sha256").update(await readFile5(path3)).digest("hex") !== file.sha256)
|
|
17366
17839
|
throw Error("Attachment file unavailable");
|
|
17367
17840
|
}
|
|
17368
17841
|
let textPath;
|
|
17369
17842
|
if (file.text !== null) {
|
|
17370
|
-
textPath =
|
|
17843
|
+
textPath = join31(directory, `${file.id}.extracted.txt`);
|
|
17371
17844
|
try {
|
|
17372
17845
|
await writeFile3(textPath, file.text, { flag: "wx", mode: 256 });
|
|
17373
17846
|
} catch (error) {
|
|
@@ -17383,42 +17856,6 @@ Attached files (read the original files; extracted document text is provided whe
|
|
|
17383
17856
|
${JSON.stringify(entries)}`;
|
|
17384
17857
|
}
|
|
17385
17858
|
|
|
17386
|
-
// src/runs/check.ts
|
|
17387
|
-
import { execa as execa9 } from "execa";
|
|
17388
|
-
async function fixedCheckSnapshot(repoPath, worktree, sha6, signal) {
|
|
17389
|
-
signal?.throwIfAborted();
|
|
17390
|
-
if (!/^[a-f0-9]{40}$/.test(sha6))
|
|
17391
|
-
throw new Error("Check requires an exact candidate SHA");
|
|
17392
|
-
const gitDir = await worktreeGitDir(repoPath, worktree, signal);
|
|
17393
|
-
const git3 = async (...args) => (await execa9(
|
|
17394
|
-
"git",
|
|
17395
|
-
[
|
|
17396
|
-
"-c",
|
|
17397
|
-
"core.hooksPath=/dev/null",
|
|
17398
|
-
"-c",
|
|
17399
|
-
"core.fsmonitor=false",
|
|
17400
|
-
...args
|
|
17401
|
-
],
|
|
17402
|
-
{
|
|
17403
|
-
cwd: worktree,
|
|
17404
|
-
env: { GIT_DIR: gitDir, GIT_WORK_TREE: worktree },
|
|
17405
|
-
stdin: "ignore",
|
|
17406
|
-
cancelSignal: signal,
|
|
17407
|
-
killDescendants: true
|
|
17408
|
-
}
|
|
17409
|
-
)).stdout.trim();
|
|
17410
|
-
if (await git3("rev-parse", "HEAD") !== sha6)
|
|
17411
|
-
throw new Error("Check worktree HEAD differs from the fixed candidate");
|
|
17412
|
-
if (await git3("status", "--porcelain"))
|
|
17413
|
-
throw new Error(
|
|
17414
|
-
"Check worktree contains changes outside the fixed candidate"
|
|
17415
|
-
);
|
|
17416
|
-
return { sha: sha6, tree: await git3("rev-parse", `${sha6}^{tree}`) };
|
|
17417
|
-
}
|
|
17418
|
-
|
|
17419
|
-
// src/runs/supervisor.ts
|
|
17420
|
-
import { lstatSync as lstatSync11, readFileSync as readFileSync14, readdirSync as readdirSync8 } from "node:fs";
|
|
17421
|
-
|
|
17422
17859
|
// src/secret-mask.ts
|
|
17423
17860
|
import { gunzipSync, gzipSync } from "node:zlib";
|
|
17424
17861
|
var MASK_MIN_LENGTH = 8;
|
|
@@ -17561,23 +17998,22 @@ function createRunMasker(secrets) {
|
|
|
17561
17998
|
|
|
17562
17999
|
// src/runs/supervisor.ts
|
|
17563
18000
|
import { stdSerializers } from "pino";
|
|
17564
|
-
import { createHash as
|
|
17565
|
-
import { join as
|
|
18001
|
+
import { createHash as createHash14, randomUUID as randomUUID6 } from "node:crypto";
|
|
18002
|
+
import { join as join33, resolve as resolve14 } from "node:path";
|
|
17566
18003
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
17567
|
-
import { execa as execa12 } from "execa";
|
|
17568
18004
|
|
|
17569
18005
|
// src/agents/checkpoint.ts
|
|
17570
18006
|
import { mkdtempSync as mkdtempSync9, rmSync as rmSync19, writeFileSync as writeFileSync9 } from "node:fs";
|
|
17571
18007
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
17572
|
-
import { join as
|
|
18008
|
+
import { join as join32 } from "node:path";
|
|
17573
18009
|
import { gunzipSync as gunzipSync2, gzipSync as gzipSync2 } from "node:zlib";
|
|
17574
|
-
import { execa as
|
|
18010
|
+
import { execa as execa12 } from "execa";
|
|
17575
18011
|
|
|
17576
18012
|
// src/coding-workspace/checkpoint.ts
|
|
17577
|
-
import { createHash as
|
|
18013
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
17578
18014
|
import { resolve as resolve13 } from "node:path";
|
|
17579
|
-
import { execa as
|
|
17580
|
-
var digest6 = (value) =>
|
|
18015
|
+
import { execa as execa11 } from "execa";
|
|
18016
|
+
var digest6 = (value) => createHash13("sha256").update(value).digest("hex");
|
|
17581
18017
|
var oid = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
17582
18018
|
var MANIFEST_BYTES = 1536 * 1024;
|
|
17583
18019
|
var regular = (mode) => mode === null || mode === "100644" || mode === "100755";
|
|
@@ -17618,7 +18054,7 @@ async function captureCheckpointReview(input) {
|
|
|
17618
18054
|
};
|
|
17619
18055
|
const git3 = async (args, text4, maximum = MANIFEST_BYTES) => {
|
|
17620
18056
|
signal.throwIfAborted();
|
|
17621
|
-
const child = await
|
|
18057
|
+
const child = await execa11("git", [
|
|
17622
18058
|
"--no-optional-locks",
|
|
17623
18059
|
"-c",
|
|
17624
18060
|
"core.hooksPath=/dev/null",
|
|
@@ -17796,8 +18232,8 @@ async function takeCheckpoint(options) {
|
|
|
17796
18232
|
}
|
|
17797
18233
|
async function applyCheckpoint(options) {
|
|
17798
18234
|
const git3 = await pinnedGit(options.repoPath, options.worktree);
|
|
17799
|
-
const dir = mkdtempSync9(
|
|
17800
|
-
const file =
|
|
18235
|
+
const dir = mkdtempSync9(join32(tmpdir4(), "mikka-checkpoint-"));
|
|
18236
|
+
const file = join32(dir, "checkpoint.patch");
|
|
17801
18237
|
try {
|
|
17802
18238
|
const patch = gunzipSync2(Buffer.from(options.checkpoint.patch, "base64"));
|
|
17803
18239
|
if (!patch.length && options.checkpoint.files === 0) return true;
|
|
@@ -17818,7 +18254,7 @@ async function applyCheckpoint(options) {
|
|
|
17818
18254
|
}
|
|
17819
18255
|
}
|
|
17820
18256
|
async function hasCommit(repoPath, commit) {
|
|
17821
|
-
return
|
|
18257
|
+
return execa12(
|
|
17822
18258
|
"git",
|
|
17823
18259
|
["-c", "core.hooksPath=/dev/null", "cat-file", "-e", `${commit}^{commit}`],
|
|
17824
18260
|
{ cwd: repoPath, stdin: "ignore" }
|
|
@@ -18141,10 +18577,6 @@ var MemoryServer = class {
|
|
|
18141
18577
|
var DEFAULT_STALL_MS = 10 * 6e4;
|
|
18142
18578
|
var DEFAULT_STOP_GRACE_MS = 3e3;
|
|
18143
18579
|
var DEFAULT_CANCEL_GRACE_MS = 1e4;
|
|
18144
|
-
var VERIFY_TIMEOUT_MS = 30 * 6e4;
|
|
18145
|
-
var MAX_REPORTED_FILES = 5e3;
|
|
18146
|
-
var MAX_REPORTED_CRITERIA = 200;
|
|
18147
|
-
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
18148
18580
|
var CHECKPOINT_EVERY_MS = 2 * 6e4;
|
|
18149
18581
|
var RunSupervisor = class {
|
|
18150
18582
|
constructor(deps) {
|
|
@@ -18591,7 +19023,7 @@ var RunSupervisor = class {
|
|
|
18591
19023
|
const entry = this.deps.journal.get(runId);
|
|
18592
19024
|
if (splitChatFiles(text4).files.length) {
|
|
18593
19025
|
if (!entry || !this.deps.downloadChatFile || !this.deps.adapterStateDir) throw Error("Run attachments unavailable");
|
|
18594
|
-
text4 = await materializeChatFiles(text4,
|
|
19026
|
+
text4 = await materializeChatFiles(text4, join33(this.deps.adapterStateDir, "inputs", runId), (id5) => this.deps.downloadChatFile(entry.assignment, id5, run3.abort.signal));
|
|
18595
19027
|
}
|
|
18596
19028
|
await run3.session.send(text4, mode);
|
|
18597
19029
|
}
|
|
@@ -18762,80 +19194,25 @@ var RunSupervisor = class {
|
|
|
18762
19194
|
* The only way into a terminal state: the terminal patch, then exactly one
|
|
18763
19195
|
* completion for the server, then the outbox is compacted.
|
|
18764
19196
|
*/
|
|
18765
|
-
finish(runId, stopReason, error, report2
|
|
19197
|
+
finish(runId, stopReason, error, report2, failureDetails) {
|
|
18766
19198
|
this.active.get(runId)?.toolApproval?.revoke();
|
|
18767
19199
|
const active = this.active.get(runId);
|
|
18768
|
-
|
|
18769
|
-
stopReason = active.forcedStop ?? "cancelled";
|
|
18770
|
-
error = void 0;
|
|
18771
|
-
}
|
|
18772
|
-
active?.span?.set("mikka.outcome", stopReason);
|
|
18773
|
-
if (stopReason !== "provider_failure" && report2.providerFailure) {
|
|
18774
|
-
const { providerFailure: _failure, ...rest } = report2;
|
|
18775
|
-
report2 = rest;
|
|
18776
|
-
}
|
|
18777
|
-
if (stopReason !== "provider_failure" && stopReason !== "quota_exhausted" && report2.providerCheckpoint) {
|
|
18778
|
-
const { providerCheckpoint: _checkpoint, ...rest } = report2;
|
|
18779
|
-
report2 = rest;
|
|
18780
|
-
}
|
|
18781
|
-
const entry = this.deps.journal.get(runId);
|
|
18782
|
-
const planning = entry?.assignment.kind === "plan";
|
|
18783
|
-
if (entry && stopReason === "blocked" && report2.repositorySelection)
|
|
18784
|
-
entry.assignment.preserveQuestionWorktree = true;
|
|
18785
|
-
const readOnlyTask = entry && (isReadOnlyTask(entry.assignment) || entry.assignment.factoryCheck?.reportOnly === true || entry.assignment.factoryExecuteKind === "deliverable");
|
|
18786
|
-
const { sourceCommit: _source, deliverableCommit: _delivery, skillMount: _mount, skillPrompt: _prompt, execution: _execution, runtime: _runtime, safePoint: _safePoint, ...content } = report2;
|
|
18787
|
-
report2 = {
|
|
18788
|
-
...content,
|
|
18789
|
-
...active?.safePoint ? { safePoint: active.safePoint } : {},
|
|
18790
|
-
...entry?.baseCommit && /^[a-f0-9]{40}$/.test(entry.baseCommit) ? { sourceCommit: entry.baseCommit } : {},
|
|
18791
|
-
...entry?.assignment.factoryExecuteKind === "deliverable" && entry.deliverableCommit ? { deliverableCommit: entry.deliverableCommit } : {},
|
|
18792
|
-
// What the prompt actually carried of the run's skills; a deferred body
|
|
18793
|
-
// is a fact the person needs to see, not something to leave unsaid.
|
|
18794
|
-
...entry && skillPromptOf(entry.assignment) ? { skillPrompt: skillPromptOf(entry.assignment) } : {},
|
|
18795
|
-
...entry?.skillMount && entry.skillMount.sessionId === entry.sessionId && entry.skillMount.receiptId === entry.assignment.skillReceipt?.id && entry.skillMount.versionId === entry.assignment.skillReceipt?.artifact.versionId && entry.skillMount.sha256 === entry.assignment.skillReceipt?.artifact.sha256 ? {
|
|
18796
|
-
skillMount: entry.skillMount,
|
|
18797
|
-
...entry.runtime ? { runtime: {
|
|
18798
|
-
...entry.runtime,
|
|
18799
|
-
observedModel: this.active.get(runId)?.session?.runtimeModel ?? entry.runtime.observedModel
|
|
18800
|
-
} } : {},
|
|
18801
|
-
...entry.execution && entry.assignment.benchmark ? { execution: {
|
|
18802
|
-
...entry.execution,
|
|
18803
|
-
observedModel: this.active.get(runId)?.session?.runtimeModel ?? entry.execution.observedModel
|
|
18804
|
-
} } : {}
|
|
18805
|
-
} : {}
|
|
18806
|
-
};
|
|
18807
|
-
this.emitPlanCards(runId, report2, planning);
|
|
18808
|
-
this.endMessage(runId, this.active.get(runId)?.runtimeTiming?.finish());
|
|
18809
|
-
this.flushMasker(runId);
|
|
18810
|
-
this.openParts.delete(runId);
|
|
18811
|
-
if (stopReason === "submitted") this.setState(runId, "finishing");
|
|
18812
|
-
let state2 = runStateForStop(stopReason);
|
|
18813
|
-
if (stopReason === "submitted" && report2.verify.status !== "passed") {
|
|
18814
|
-
const failed = report2.verify.status === "failed";
|
|
18815
|
-
if (!planning && !readOnlyTask) state2 = failed ? "failed" : report2.publish?.pushed === true ? "succeeded" : "stopped";
|
|
18816
|
-
if (!failed && !planning && !readOnlyTask)
|
|
18817
|
-
error ??= "Submitted, but no verify command ran; the work is unverified";
|
|
18818
|
-
}
|
|
18819
|
-
if ((stopReason === "asked_human" || stopReason === "blocked") && report2.question) {
|
|
18820
|
-
this.deps.journal.update(runId, {
|
|
18821
|
-
waitingQuestionId: report2.question.questionId
|
|
18822
|
-
});
|
|
18823
|
-
}
|
|
18824
|
-
if (state2 === "failed") active?.span?.fail({ name: "RunFailure" }, stopReason);
|
|
18825
|
-
else active?.span?.set("mikka.outcome", stopReason);
|
|
18826
|
-
this.setState(runId, state2, {
|
|
18827
|
-
stopReason,
|
|
18828
|
-
...error ? { error } : {}
|
|
18829
|
-
});
|
|
18830
|
-
const terminalFailure = state2 === "failed" && !active?.cancelRequested && !active?.forcedStop ? captureRunFailure(failureDetails ?? new Error(error ?? report2.summary), {
|
|
19200
|
+
finishRun({
|
|
18831
19201
|
runId,
|
|
18832
|
-
|
|
18833
|
-
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
|
|
18837
|
-
|
|
18838
|
-
|
|
19202
|
+
journal: this.deps.journal,
|
|
19203
|
+
active,
|
|
19204
|
+
closeOutput: (report3, planning) => {
|
|
19205
|
+
this.emitPlanCards(runId, report3, planning);
|
|
19206
|
+
this.endMessage(runId, this.active.get(runId)?.runtimeTiming?.finish());
|
|
19207
|
+
this.flushMasker(runId);
|
|
19208
|
+
this.openParts.delete(runId);
|
|
19209
|
+
},
|
|
19210
|
+
setState: (state2, extra) => this.setState(runId, state2, extra),
|
|
19211
|
+
complete: (completion) => this.push(runId, { kind: "complete", completion })
|
|
19212
|
+
}, stopReason, error, report2, failureDetails);
|
|
19213
|
+
this.cleanupFinishedRun(runId);
|
|
19214
|
+
}
|
|
19215
|
+
cleanupFinishedRun(runId) {
|
|
18839
19216
|
this.disposeMasker(runId);
|
|
18840
19217
|
const run3 = this.active.get(runId);
|
|
18841
19218
|
if (run3) void this.closeMailbox(run3).catch(() => this.deps.log.warn("Run mailbox shutdown failed"));
|
|
@@ -18936,143 +19313,6 @@ var RunSupervisor = class {
|
|
|
18936
19313
|
this.forceStop(runId, run3, "device_lost");
|
|
18937
19314
|
signal.throwIfAborted();
|
|
18938
19315
|
}
|
|
18939
|
-
/**
|
|
18940
|
-
* What the frozen Profile selected and what its agent actually loaded. The
|
|
18941
|
-
* load receipts are written by the `load_skill` tool itself; a configured
|
|
18942
|
-
* Skill without a receipt is not reported as used. Digests must match the
|
|
18943
|
-
* configured pinned body, so a tampered manifest cannot mint a receipt.
|
|
18944
|
-
*/
|
|
18945
|
-
profileSkillReport(runId, assignment) {
|
|
18946
|
-
const configured = (assignment.profileSkills ?? []).map((skill) => ({ id: skill.id, name: skill.name, source: skill.source, digest: skill.digest }));
|
|
18947
|
-
for (const slug of assignment.repositorySkills ?? []) {
|
|
18948
|
-
if (!configured.some((ref) => ref.id === `repository:${slug}`)) configured.push({ id: `repository:${slug}`, name: slug, source: "repository", digest: null });
|
|
18949
|
-
}
|
|
18950
|
-
if (configured.length === 0) return void 0;
|
|
18951
|
-
const loaded = [];
|
|
18952
|
-
if (this.deps.adapterStateDir) {
|
|
18953
|
-
const dir = join31(runPaths(this.deps.adapterStateDir, runId).runDir, PROFILE_SKILLS_DIR, PROFILE_SKILL_LOADS_DIR);
|
|
18954
|
-
try {
|
|
18955
|
-
for (const name of readdirSync8(dir).sort()) {
|
|
18956
|
-
if (!name.endsWith(".json") || loaded.length >= configured.length) continue;
|
|
18957
|
-
const file = join31(dir, name), meta = lstatSync11(file, { throwIfNoEntry: false });
|
|
18958
|
-
if (!meta?.isFile() || meta.isSymbolicLink() || meta.nlink !== 1 || meta.size < 2 || meta.size > 4096) continue;
|
|
18959
|
-
const receipt = profileSkillLoadReceiptSchema.safeParse(JSON.parse(readFileSync14(file, "utf8")));
|
|
18960
|
-
if (!receipt.success || loaded.some((item) => item.id === receipt.data.id)) continue;
|
|
18961
|
-
if (!configured.some((ref) => ref.id === receipt.data.id && (ref.digest === null || ref.digest === receipt.data.digest))) continue;
|
|
18962
|
-
loaded.push(receipt.data);
|
|
18963
|
-
}
|
|
18964
|
-
} catch {
|
|
18965
|
-
}
|
|
18966
|
-
}
|
|
18967
|
-
return { configured, loaded };
|
|
18968
|
-
}
|
|
18969
|
-
/**
|
|
18970
|
-
* The handoff report: the agent's own words (summary, questions, next
|
|
18971
|
-
* step, blocker) plus what only the daemon may state: changed files and,
|
|
18972
|
-
* after a submit, the verify result. Anything else the agent sent
|
|
18973
|
-
* (a self-reported verify, say) is dropped. `verifyError` describes a
|
|
18974
|
-
* failed verify (command and exit code) for the run's error text.
|
|
18975
|
-
*/
|
|
18976
|
-
async report(runId, worktree, repo, assignment, stopReason, error, agent, signal) {
|
|
18977
|
-
const profileSkills = this.profileSkillReport(runId, assignment);
|
|
18978
|
-
let report2 = {
|
|
18979
|
-
...baseReport(error),
|
|
18980
|
-
...pickAgentReport(agent),
|
|
18981
|
-
...profileSkills ? { profileSkills } : {}
|
|
18982
|
-
};
|
|
18983
|
-
const filesChanged = (await this.deps.worktrees.changedFiles(worktree, this.deps.journal.get(runId)?.baseCommit).catch(() => [])).slice(0, MAX_REPORTED_FILES);
|
|
18984
|
-
const inferred = assignment.factoryCheck?.stage === "verify" && assignment.factoryCheck.inferCommand && !assignment.factoryCheck.reportOnly ? report2.verificationCommand : void 0;
|
|
18985
|
-
const command = assignment.verifyCommand ?? inferred?.command;
|
|
18986
|
-
if (stopReason === "submitted") this.assertFinishingRunLive(runId, signal);
|
|
18987
|
-
if (stopReason === "submitted" && assignment.factoryExecuteKind === "deliverable") {
|
|
18988
|
-
const deliverableCommit = await retainDeliverable(repo.path, worktree, runId, signal);
|
|
18989
|
-
this.assertFinishingRunLive(runId, signal);
|
|
18990
|
-
this.deps.journal.update(runId, { deliverableCommit });
|
|
18991
|
-
}
|
|
18992
|
-
if (stopReason !== "submitted" && fixedCandidateCheck(assignment)) {
|
|
18993
|
-
const fixed = await fixedCheckSnapshot(repo.path, worktree, assignment.baseBranch, signal).catch(() => null);
|
|
18994
|
-
if (fixed) report2 = { ...report2, check: { sha: fixed.sha, readOnly: true } };
|
|
18995
|
-
}
|
|
18996
|
-
if (stopReason !== "submitted" || assignment.kind === "plan" || isReadOnlyTask(assignment) || assignment.factoryExecuteKind === "deliverable")
|
|
18997
|
-
return {
|
|
18998
|
-
report: { ...report2, filesChanged, verify: { status: "not_run" } }
|
|
18999
|
-
};
|
|
19000
|
-
if (!command) {
|
|
19001
|
-
if (fixedCandidateCheck(assignment)) {
|
|
19002
|
-
const fixed = await fixedCheckSnapshot(repo.path, worktree, assignment.baseBranch, signal);
|
|
19003
|
-
report2 = { ...report2, check: { sha: fixed.sha, readOnly: true } };
|
|
19004
|
-
}
|
|
19005
|
-
this.assertFinishingRunLive(runId, signal);
|
|
19006
|
-
const tree = await this.deps.publisher?.snapshot({ worktree, repo, signal });
|
|
19007
|
-
this.assertFinishingRunLive(runId, signal);
|
|
19008
|
-
return { report: { ...report2, filesChanged, verify: { status: "not_run" } }, tree };
|
|
19009
|
-
}
|
|
19010
|
-
let execution = {};
|
|
19011
|
-
const failed = (output2, verifyError) => ({
|
|
19012
|
-
report: {
|
|
19013
|
-
...report2,
|
|
19014
|
-
filesChanged,
|
|
19015
|
-
verify: { status: "failed", command, output: output2, ...execution }
|
|
19016
|
-
},
|
|
19017
|
-
verifyError
|
|
19018
|
-
});
|
|
19019
|
-
const publisher = this.deps.publisher;
|
|
19020
|
-
let before;
|
|
19021
|
-
try {
|
|
19022
|
-
if (fixedCandidateCheck(assignment)) {
|
|
19023
|
-
if (runPolicy(assignment.policy).readOnly !== true)
|
|
19024
|
-
throw new Error("Check assignment is missing its read-only policy");
|
|
19025
|
-
const fixed = await fixedCheckSnapshot(
|
|
19026
|
-
repo.path,
|
|
19027
|
-
worktree,
|
|
19028
|
-
assignment.baseBranch,
|
|
19029
|
-
signal
|
|
19030
|
-
);
|
|
19031
|
-
report2 = { ...report2, check: { sha: fixed.sha, readOnly: true } };
|
|
19032
|
-
before = fixed.tree;
|
|
19033
|
-
} else {
|
|
19034
|
-
before = await publisher?.snapshot({ worktree, repo, signal });
|
|
19035
|
-
}
|
|
19036
|
-
} catch (snapshotError) {
|
|
19037
|
-
signal.throwIfAborted();
|
|
19038
|
-
return failed("", `Could not read the worktree: ${String(snapshotError)}`);
|
|
19039
|
-
}
|
|
19040
|
-
this.assertFinishingRunLive(runId, signal);
|
|
19041
|
-
const result = await (this.deps.verify ?? unsandboxedVerify)({
|
|
19042
|
-
runId,
|
|
19043
|
-
worktree,
|
|
19044
|
-
repo,
|
|
19045
|
-
command,
|
|
19046
|
-
timeoutMs: VERIFY_TIMEOUT_MS,
|
|
19047
|
-
signal,
|
|
19048
|
-
readOnly: runPolicy(assignment.policy).readOnly === true,
|
|
19049
|
-
githubEnvironment: this.active.get(runId)?.github?.env
|
|
19050
|
-
});
|
|
19051
|
-
this.assertFinishingRunLive(runId, signal);
|
|
19052
|
-
execution = {
|
|
19053
|
-
exitCode: result.exitCode,
|
|
19054
|
-
signal: result.signal,
|
|
19055
|
-
timedOut: result.timedOut
|
|
19056
|
-
};
|
|
19057
|
-
const output = result.output.slice(-4e3);
|
|
19058
|
-
if (result.exitCode !== 0 || result.timedOut)
|
|
19059
|
-
return failed(output, verifyFailure(command, result));
|
|
19060
|
-
const after = fixedCandidateCheck(assignment) ? await fixedCheckSnapshot(repo.path, worktree, assignment.baseBranch, signal).then((fixed) => fixed.tree).catch(() => null) : publisher ? await publisher.snapshot({ worktree, repo, signal }).catch(() => null) : void 0;
|
|
19061
|
-
this.assertFinishingRunLive(runId, signal);
|
|
19062
|
-
if (after !== before)
|
|
19063
|
-
return failed(
|
|
19064
|
-
output,
|
|
19065
|
-
`Submitted, but the verify command changed the worktree (\`${command}\`); the work is unverified`
|
|
19066
|
-
);
|
|
19067
|
-
return {
|
|
19068
|
-
report: {
|
|
19069
|
-
...report2,
|
|
19070
|
-
filesChanged,
|
|
19071
|
-
verify: { status: "passed", command, output, ...inferred ? { inferredFrom: inferred.basis } : {}, ...execution }
|
|
19072
|
-
},
|
|
19073
|
-
tree: before
|
|
19074
|
-
};
|
|
19075
|
-
}
|
|
19076
19316
|
/**
|
|
19077
19317
|
* Where a fresh worktree starts: the issue's branch on the remote when
|
|
19078
19318
|
* the run pushes there (ADR 0024), so it builds on what earlier runs and
|
|
@@ -19098,7 +19338,7 @@ var RunSupervisor = class {
|
|
|
19098
19338
|
try {
|
|
19099
19339
|
return await withRunGitCredentials(
|
|
19100
19340
|
assignment,
|
|
19101
|
-
runPaths(this.deps.adapterStateDir ??
|
|
19341
|
+
runPaths(this.deps.adapterStateDir ?? join33(tmpdir5(), "mikka-run-state"), runId).privateDir,
|
|
19102
19342
|
(env) => this.deps.worktrees.fetchBranch(
|
|
19103
19343
|
repo.path,
|
|
19104
19344
|
repo.push?.remote ?? "origin",
|
|
@@ -19116,39 +19356,6 @@ var RunSupervisor = class {
|
|
|
19116
19356
|
return base;
|
|
19117
19357
|
}
|
|
19118
19358
|
}
|
|
19119
|
-
/**
|
|
19120
|
-
* A failed commit or push is reported (in a `data-publish` chunk and in
|
|
19121
|
-
* the completion's report), never fails the verified run.
|
|
19122
|
-
*/
|
|
19123
|
-
async publish(runId, worktree, repo, assignment, report2, tree, signal) {
|
|
19124
|
-
const publisher = this.deps.publisher;
|
|
19125
|
-
let data;
|
|
19126
|
-
try {
|
|
19127
|
-
this.assertFinishingRunLive(runId, signal);
|
|
19128
|
-
data = await publisher.publish({
|
|
19129
|
-
runId,
|
|
19130
|
-
worktree,
|
|
19131
|
-
repo,
|
|
19132
|
-
assignment,
|
|
19133
|
-
report: report2,
|
|
19134
|
-
tree,
|
|
19135
|
-
githubEnvironment: this.active.get(runId)?.github?.env,
|
|
19136
|
-
signal
|
|
19137
|
-
});
|
|
19138
|
-
} catch (error) {
|
|
19139
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
19140
|
-
if (!signal.aborted) this.deps.log.error({ run_id: runId, err: this.logError(runId, error) }, "publish failed");
|
|
19141
|
-
data = {
|
|
19142
|
-
branch: "",
|
|
19143
|
-
commit: null,
|
|
19144
|
-
pushed: false,
|
|
19145
|
-
remote: null,
|
|
19146
|
-
note: signal.aborted ? "Run stopped before publication completed" : `Commit failed: ${message}`.slice(0, 2e3)
|
|
19147
|
-
};
|
|
19148
|
-
}
|
|
19149
|
-
this.emit(runId, { type: "data-publish", data });
|
|
19150
|
-
return data;
|
|
19151
|
-
}
|
|
19152
19359
|
launch(runId, repo, initialClaim = false) {
|
|
19153
19360
|
const run3 = {
|
|
19154
19361
|
repoPath: repo.path,
|
|
@@ -19497,7 +19704,7 @@ ${run3.drive.folders.map((folder) => `- ${folder.scope}: ${folder.path}${folder.
|
|
|
19497
19704
|
let followUp = assignment.followUp;
|
|
19498
19705
|
if (splitChatFiles(prompt).files.length || followUp && splitChatFiles(followUp).files.length) {
|
|
19499
19706
|
if (!this.deps.downloadChatFile || !this.deps.adapterStateDir) throw Error("Run attachments unavailable");
|
|
19500
|
-
const directory =
|
|
19707
|
+
const directory = join33(this.deps.adapterStateDir, "inputs", runId);
|
|
19501
19708
|
const download2 = (id5) => this.deps.downloadChatFile(assignment, id5, run3.abort.signal);
|
|
19502
19709
|
prompt = await materializeChatFiles(prompt, directory, download2);
|
|
19503
19710
|
if (followUp) followUp = await materializeChatFiles(followUp, directory, download2);
|
|
@@ -19519,13 +19726,13 @@ ${run3.drive.folders.map((folder) => `- ${folder.scope}: ${folder.path}${folder.
|
|
|
19519
19726
|
if (assignment.requireSessionResume && (!assignment.resumeSessionId || !assignment.continuesRunId || !adapter.capabilities.supportsResume || !resuming && !continueSession || resuming && entry.sessionId !== assignment.resumeSessionId))
|
|
19520
19727
|
throw new Error("factory_question_session_resume_required");
|
|
19521
19728
|
const benchmark = assignment.benchmark;
|
|
19522
|
-
const policyDigest = assignment.skillReceipt ?
|
|
19729
|
+
const policyDigest = assignment.skillReceipt ? createHash14("sha256").update(runPolicyDigestInput(assignment.policy)).digest("hex") : void 0;
|
|
19523
19730
|
if (benchmark && (!assignment.skillReceipt || assignment.harness === "mock" || !assignment.verifyCommand || benchmark.sourceCommit !== this.deps.journal.get(runId)?.baseCommit || policyDigest !== benchmark.policyDigest)) throw new Error("Frozen benchmark execution configuration mismatch");
|
|
19524
19731
|
let fixtureDigest;
|
|
19525
19732
|
if (benchmark) {
|
|
19526
19733
|
if (runPolicy(assignment.policy).readOnly !== true) throw new Error("Benchmark fixture must be read-only");
|
|
19527
19734
|
const fixed = await fixedCheckSnapshot(repo.path, worktree, benchmark.sourceCommit);
|
|
19528
|
-
fixtureDigest =
|
|
19735
|
+
fixtureDigest = createHash14("sha256").update(fixed.sha).digest("hex");
|
|
19529
19736
|
if (fixtureDigest !== benchmark.fixtureDigest) throw new Error("Frozen benchmark fixture digest mismatch");
|
|
19530
19737
|
}
|
|
19531
19738
|
const previousMount = entry.skillMount;
|
|
@@ -19566,7 +19773,7 @@ ${run3.drive.folders.map((folder) => `- ${folder.scope}: ${folder.path}${folder.
|
|
|
19566
19773
|
if (!this.deps.adapterStateDir || assignment.harness === "mock" || !session.sessionId || resuming && session.sessionId !== entry.sessionId || assignment.requireSessionResume && session.sessionId !== assignment.resumeSessionId)
|
|
19567
19774
|
throw new Error("Skill mount requires the actual original harness session");
|
|
19568
19775
|
verifySkillAssignment(assignment);
|
|
19569
|
-
const file =
|
|
19776
|
+
const file = join33(
|
|
19570
19777
|
runPaths(this.deps.adapterStateDir, runId).runDir,
|
|
19571
19778
|
SKILLS_DIR,
|
|
19572
19779
|
skillSlug(assignment.skills[0].name),
|
|
@@ -19678,55 +19885,29 @@ ${run3.drive.folders.map((folder) => `- ${folder.scope}: ${folder.path}${folder.
|
|
|
19678
19885
|
const finishingSignal = AbortSignal.any([this.stopController.signal, run3.abort.signal]);
|
|
19679
19886
|
run3.runtimeTiming?.finishing();
|
|
19680
19887
|
await this.closeMailbox(run3);
|
|
19681
|
-
|
|
19682
|
-
|
|
19683
|
-
|
|
19684
|
-
|
|
19685
|
-
|
|
19686
|
-
|
|
19687
|
-
|
|
19688
|
-
|
|
19689
|
-
|
|
19690
|
-
|
|
19691
|
-
|
|
19692
|
-
|
|
19693
|
-
|
|
19694
|
-
|
|
19695
|
-
|
|
19696
|
-
|
|
19697
|
-
|
|
19698
|
-
let report2 = stopReason === "quota_exhausted" ? { ...outcome.report, resetsAt: event.quota?.resetsAt ?? null } : outcome.report;
|
|
19699
|
-
if (stopReason === "provider_failure") {
|
|
19700
|
-
report2 = {
|
|
19701
|
-
...report2,
|
|
19702
|
-
providerFailure: providerFailureSchema.parse(event.providerFailure),
|
|
19703
|
-
...event.quota ? { resetsAt: event.quota.resetsAt } : {}
|
|
19704
|
-
};
|
|
19705
|
-
}
|
|
19706
|
-
const policy = runPolicy(assignment.policy);
|
|
19707
|
-
if (stopReason === "submitted" && report2.verify.status !== "failed" && tree && // The draft-PR exception requires an explicit repository push
|
|
19708
|
-
// approval. It must not even create a local commit without it.
|
|
19709
|
-
(report2.verify.status === "passed" || pushDecision(policy).push) && // A read-only check (ADR 0046) never commits or pushes: it reports
|
|
19710
|
-
// on the commit the implementation run already pushed.
|
|
19711
|
-
policy.readOnly !== true) {
|
|
19712
|
-
const publish = await this.publish(
|
|
19713
|
-
runId,
|
|
19714
|
-
worktree,
|
|
19715
|
-
repo,
|
|
19716
|
-
assignment,
|
|
19717
|
-
report2,
|
|
19718
|
-
tree,
|
|
19719
|
-
finishingSignal
|
|
19720
|
-
);
|
|
19721
|
-
report2 = { ...report2, publish };
|
|
19722
|
-
stopReason = stopReasonOf(event, run3, assignment);
|
|
19723
|
-
}
|
|
19888
|
+
const publication = await verifyAndPublish({
|
|
19889
|
+
deps: this.deps,
|
|
19890
|
+
runId,
|
|
19891
|
+
worktree,
|
|
19892
|
+
repo,
|
|
19893
|
+
assignment,
|
|
19894
|
+
signal: finishingSignal,
|
|
19895
|
+
assertLive: () => this.assertFinishingRunLive(runId, finishingSignal),
|
|
19896
|
+
githubEnvironment: () => this.active.get(runId)?.github?.env,
|
|
19897
|
+
getStopReason: () => stopReasonOf(event, run3, assignment),
|
|
19898
|
+
isStopping: () => this.stopping,
|
|
19899
|
+
cancelRequested: run3.cancelRequested,
|
|
19900
|
+
logPublishError: (error) => this.deps.log.error({ run_id: runId, err: this.logError(runId, error) }, "publish failed"),
|
|
19901
|
+
emitPublish: (data) => this.emit(runId, { type: "data-publish", data })
|
|
19902
|
+
}, event);
|
|
19903
|
+
if (!publication) return;
|
|
19904
|
+
let { report: report2 } = publication;
|
|
19724
19905
|
const capturesSaved = !this.stopping && await this.flushCaptures(runId, finishingSignal);
|
|
19725
|
-
stopReason = stopReasonOf(event, run3, assignment);
|
|
19906
|
+
const stopReason = stopReasonOf(event, run3, assignment);
|
|
19726
19907
|
const checkpoint = await this.saveTerminalCheckpoint(runId, run3, capturesSaved);
|
|
19727
19908
|
if (stopReason === "provider_failure" || stopReason === "quota_exhausted") report2 = { ...report2, providerCheckpoint: checkpoint.checkpoint };
|
|
19728
19909
|
if (this.stopping) return;
|
|
19729
|
-
this.finish(runId, stopReason, error
|
|
19910
|
+
this.finish(runId, stopReason, publication.error, report2, event.failureDetails);
|
|
19730
19911
|
log.info(
|
|
19731
19912
|
{ outcome: event.outcome, stop_reason: stopReason },
|
|
19732
19913
|
"run ended"
|
|
@@ -19774,55 +19955,6 @@ function abortPromise(signal) {
|
|
|
19774
19955
|
signal.addEventListener("abort", () => resolve20(ABORTED), { once: true });
|
|
19775
19956
|
});
|
|
19776
19957
|
}
|
|
19777
|
-
function pickAgentReport(agent) {
|
|
19778
|
-
if (!agent) return {};
|
|
19779
|
-
const picked = {};
|
|
19780
|
-
if (agent.repositorySelection) picked.repositorySelection = agent.repositorySelection;
|
|
19781
|
-
if (agent.verificationCommand && typeof agent.verificationCommand.command === "string" && agent.verificationCommand.command.trim() && typeof agent.verificationCommand.basis === "string" && agent.verificationCommand.basis.trim())
|
|
19782
|
-
picked.verificationCommand = { command: agent.verificationCommand.command.trim().slice(0, 2e3), basis: agent.verificationCommand.basis.trim().slice(0, 2e3) };
|
|
19783
|
-
const visualEvidence = runVisualEvidence.safeParse(agent.visualEvidence);
|
|
19784
|
-
if (visualEvidence.success) picked.visualEvidence = visualEvidence.data;
|
|
19785
|
-
const verdict = reviewVerdict.safeParse(agent.reviewVerdict);
|
|
19786
|
-
if (verdict.success) picked.reviewVerdict = verdict.data;
|
|
19787
|
-
if (typeof agent.summary === "string")
|
|
19788
|
-
picked.summary = agent.summary.slice(0, 1e4);
|
|
19789
|
-
if (Array.isArray(agent.openQuestions) && agent.openQuestions.every((q) => typeof q === "string"))
|
|
19790
|
-
picked.openQuestions = agent.openQuestions.slice(0, 50).map((q) => q.slice(0, 2e3));
|
|
19791
|
-
if (typeof agent.nextStep === "string")
|
|
19792
|
-
picked.nextStep = agent.nextStep.slice(0, 2e3);
|
|
19793
|
-
else if (agent.nextStep === null) picked.nextStep = null;
|
|
19794
|
-
if (typeof agent.blockedOn === "string")
|
|
19795
|
-
picked.blockedOn = agent.blockedOn.slice(0, 500);
|
|
19796
|
-
const question = runQuestion.safeParse(agent.question);
|
|
19797
|
-
if (question.success) picked.question = question.data;
|
|
19798
|
-
if (agent.plan) picked.plan = agent.plan;
|
|
19799
|
-
if (typeof agent.previewDatabaseBranch === "string" && agent.previewDatabaseBranch.trim())
|
|
19800
|
-
picked.previewDatabaseBranch = agent.previewDatabaseBranch.trim().slice(0, 500);
|
|
19801
|
-
if (Array.isArray(agent.criteria)) {
|
|
19802
|
-
const criteria = [];
|
|
19803
|
-
for (const entry of agent.criteria) {
|
|
19804
|
-
if (criteria.length >= MAX_REPORTED_CRITERIA) break;
|
|
19805
|
-
if (!entry || typeof entry !== "object") continue;
|
|
19806
|
-
const { criterionId, text: text4, passed, status: status3, reason, resolution, evidence, command, exitCode } = entry;
|
|
19807
|
-
if (!(typeof criterionId === "string" && UUID_RE.test(criterionId)) && !(typeof text4 === "string" && text4.trim()))
|
|
19808
|
-
continue;
|
|
19809
|
-
if (typeof passed !== "boolean") continue;
|
|
19810
|
-
const criterion = runCriterion.safeParse({
|
|
19811
|
-
...typeof criterionId === "string" && UUID_RE.test(criterionId) ? { criterionId } : {},
|
|
19812
|
-
...typeof text4 === "string" && text4.trim() ? { text: text4.trim().slice(0, 2e3) } : {},
|
|
19813
|
-
passed,
|
|
19814
|
-
...status3 !== void 0 ? { status: status3 } : {},
|
|
19815
|
-
...typeof reason === "string" && reason.trim() ? { reason: reason.trim().slice(0, 2e3) } : {},
|
|
19816
|
-
...typeof resolution === "string" && resolution.trim() ? { resolution: resolution.trim().slice(0, 2e3) } : {},
|
|
19817
|
-
...typeof command === "string" && command.trim() ? { command: command.trim().slice(0, 2e3), ...exitCode === null || typeof exitCode === "number" && Number.isSafeInteger(exitCode) ? { exitCode } : {} } : {},
|
|
19818
|
-
...typeof evidence === "string" ? { evidence: evidence.slice(0, 1e4) } : {}
|
|
19819
|
-
});
|
|
19820
|
-
if (criterion.success) criteria.push(criterion.data);
|
|
19821
|
-
}
|
|
19822
|
-
picked.criteria = criteria;
|
|
19823
|
-
}
|
|
19824
|
-
return picked;
|
|
19825
|
-
}
|
|
19826
19958
|
var KEEP_WORKTREE = ["turn_ended", "asked_human", "quota_exhausted", "provider_failure"];
|
|
19827
19959
|
function startupProviderFailure(error) {
|
|
19828
19960
|
for (let depth = 0; depth < 5 && error instanceof Error; depth++, error = error.cause) {
|
|
@@ -19838,50 +19970,6 @@ function stopReasonOf(event, run3, assignment) {
|
|
|
19838
19970
|
if (event.outcome === "failed" && event.quota && quotaStopApplies(assignment)) return "quota_exhausted";
|
|
19839
19971
|
return event.outcome === "failed" ? "error" : "turn_ended";
|
|
19840
19972
|
}
|
|
19841
|
-
async function unsandboxedVerify(run3) {
|
|
19842
|
-
const result = await execa12(run3.command, {
|
|
19843
|
-
shell: true,
|
|
19844
|
-
cwd: run3.worktree,
|
|
19845
|
-
env: buildChildEnv(),
|
|
19846
|
-
extendEnv: false,
|
|
19847
|
-
reject: false,
|
|
19848
|
-
all: true,
|
|
19849
|
-
stdin: "ignore",
|
|
19850
|
-
timeout: run3.timeoutMs,
|
|
19851
|
-
cancelSignal: run3.signal,
|
|
19852
|
-
killDescendants: true
|
|
19853
|
-
});
|
|
19854
|
-
return {
|
|
19855
|
-
exitCode: result.exitCode ?? null,
|
|
19856
|
-
signal: result.signal ?? null,
|
|
19857
|
-
timedOut: result.timedOut,
|
|
19858
|
-
output: String(result.all ?? "")
|
|
19859
|
-
};
|
|
19860
|
-
}
|
|
19861
|
-
function verifyFailure(command, result) {
|
|
19862
|
-
const how = result.timedOut ? "timed out" : result.exitCode !== null ? `exited with code ${result.exitCode}` : result.signal ? `was killed by ${result.signal}` : "did not finish";
|
|
19863
|
-
return `Submitted, but the verify command failed: \`${command}\` ${how}`;
|
|
19864
|
-
}
|
|
19865
|
-
function baseReport(summary = "") {
|
|
19866
|
-
return emptyRunReport(summary.slice(0, 1e4));
|
|
19867
|
-
}
|
|
19868
|
-
function isReadOnlyTask(assignment) {
|
|
19869
|
-
return runPolicy(assignment.policy).readOnly === true && assignment.kind !== "acceptance" && !assignment.benchmark;
|
|
19870
|
-
}
|
|
19871
|
-
function skillPromptOf(assignment) {
|
|
19872
|
-
const skills = assignment.skills;
|
|
19873
|
-
if (!skills?.length) return void 0;
|
|
19874
|
-
const plan = skillPromptPlan(skills);
|
|
19875
|
-
return {
|
|
19876
|
-
budgetChars: plan.budgetChars,
|
|
19877
|
-
usedChars: plan.usedChars,
|
|
19878
|
-
inlined: plan.inlined.map((entry) => entry.name),
|
|
19879
|
-
deferred: plan.degraded.map((entry) => entry.name)
|
|
19880
|
-
};
|
|
19881
|
-
}
|
|
19882
|
-
function fixedCandidateCheck(assignment) {
|
|
19883
|
-
return assignment.kind === "acceptance" && runPolicy(assignment.policy).readOnly === true && typeof assignment.baseBranch === "string" && /^[a-f0-9]{40}$/.test(assignment.baseBranch);
|
|
19884
|
-
}
|
|
19885
19973
|
|
|
19886
19974
|
// src/device-gateway.ts
|
|
19887
19975
|
var DEVICE_GATEWAY_PING = "ping";
|
|
@@ -20087,10 +20175,10 @@ import { constants as constants7 } from "node:fs";
|
|
|
20087
20175
|
import { open as open2, readFile as readFile6, realpath as realpath2 } from "node:fs/promises";
|
|
20088
20176
|
import { execFile as execFile7 } from "node:child_process";
|
|
20089
20177
|
import { promisify as promisify7 } from "node:util";
|
|
20090
|
-
import { createHash as
|
|
20178
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
20091
20179
|
import { extname as extname2, resolve as resolve15 } from "node:path";
|
|
20092
20180
|
var execute2 = promisify7(execFile7);
|
|
20093
|
-
var hash = (value) =>
|
|
20181
|
+
var hash = (value) => createHash15("sha256").update(value).digest("hex");
|
|
20094
20182
|
var denied = () => new CodingWorkspaceError("workspace_path_unavailable");
|
|
20095
20183
|
function isFileReadRequest(request2) {
|
|
20096
20184
|
return request2.kind === "file" || request2.kind === "tree" || request2.kind === "search" || request2.kind === "context";
|
|
@@ -20339,8 +20427,8 @@ async function readWorkspaceReceipt(command, entry) {
|
|
|
20339
20427
|
// src/coding-workspace/diff.ts
|
|
20340
20428
|
import { constants as constants8 } from "node:fs";
|
|
20341
20429
|
import { open as open3, realpath as realpath3, mkdtemp as mkdtemp2, mkdir as mkdir5, writeFile as writeFile4, rm as rm4, lstat as lstat5 } from "node:fs/promises";
|
|
20342
|
-
import { createHash as
|
|
20343
|
-
import { resolve as resolve16, dirname as dirname16, join as
|
|
20430
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
20431
|
+
import { resolve as resolve16, dirname as dirname16, join as join34, posix } from "node:path";
|
|
20344
20432
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
20345
20433
|
import { execa as execa13 } from "execa";
|
|
20346
20434
|
|
|
@@ -20409,7 +20497,7 @@ var CRLFCleaner = class {
|
|
|
20409
20497
|
};
|
|
20410
20498
|
|
|
20411
20499
|
// src/coding-workspace/diff.ts
|
|
20412
|
-
var digest7 = (value) =>
|
|
20500
|
+
var digest7 = (value) => createHash16("sha256").update(value).digest("hex");
|
|
20413
20501
|
var fenceMode = (mode) => mode === "100644" || mode === "100755" || mode === "120000" || mode === "160000" ? mode : null;
|
|
20414
20502
|
var oid2 = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
20415
20503
|
var MAX_SCAN_BYTES = 64 * 1024 * 1024;
|
|
@@ -20518,12 +20606,12 @@ async function conversionSettings(git3) {
|
|
|
20518
20606
|
const host = buildChildEnv({});
|
|
20519
20607
|
const defaults = ["/etc/gitattributes", "/usr/etc/gitattributes", "/usr/local/etc/gitattributes"];
|
|
20520
20608
|
if (!external) {
|
|
20521
|
-
const configHome = host.XDG_CONFIG_HOME || (host.HOME ?
|
|
20522
|
-
if (configHome) defaults.push(
|
|
20609
|
+
const configHome = host.XDG_CONFIG_HOME || (host.HOME ? join34(host.HOME, ".config") : void 0);
|
|
20610
|
+
if (configHome) defaults.push(join34(configHome, "git", "attributes"));
|
|
20523
20611
|
}
|
|
20524
|
-
const info =
|
|
20612
|
+
const info = join34(git3.commonDir, "info");
|
|
20525
20613
|
if (await existsWithoutReading(info)) {
|
|
20526
|
-
if (!(await lstat5(info)).isDirectory() || await existsWithoutReading(
|
|
20614
|
+
if (!(await lstat5(info)).isDirectory() || await existsWithoutReading(join34(info, "attributes")))
|
|
20527
20615
|
throw new CodingWorkspaceError("workspace_unsupported");
|
|
20528
20616
|
}
|
|
20529
20617
|
for (const path3 of defaults) if (await existsWithoutReading(path3)) throw new CodingWorkspaceError("workspace_unsupported");
|
|
@@ -20569,10 +20657,10 @@ async function workingConversion(git3, root, paths, head, signal, budget) {
|
|
|
20569
20657
|
throw new CodingWorkspaceError("workspace_unsupported");
|
|
20570
20658
|
attributeBytes.set(path3, bytes);
|
|
20571
20659
|
}
|
|
20572
|
-
const directory = await mkdtemp2(
|
|
20660
|
+
const directory = await mkdtemp2(join34(tmpdir6(), "mikka-diff-attributes-"));
|
|
20573
20661
|
const actions = /* @__PURE__ */ new Map();
|
|
20574
20662
|
try {
|
|
20575
|
-
const gitDir =
|
|
20663
|
+
const gitDir = join34(directory, "git"), worktree = join34(directory, "worktree");
|
|
20576
20664
|
await mkdir5(worktree, { mode: 448 });
|
|
20577
20665
|
const env = {
|
|
20578
20666
|
...buildChildEnv({}),
|
|
@@ -20592,7 +20680,7 @@ async function workingConversion(git3, root, paths, head, signal, budget) {
|
|
|
20592
20680
|
killDescendants: true
|
|
20593
20681
|
});
|
|
20594
20682
|
for (const [path3, bytes] of attributeBytes) {
|
|
20595
|
-
const target =
|
|
20683
|
+
const target = join34(worktree, path3);
|
|
20596
20684
|
await mkdir5(dirname16(target), { recursive: true, mode: 448 });
|
|
20597
20685
|
await writeFile4(target, bytes, { mode: 384, flag: "wx" });
|
|
20598
20686
|
}
|
|
@@ -20675,7 +20763,7 @@ async function currentFile(root, path3, head, budget, signal, conversion, git3)
|
|
|
20675
20763
|
budget.bytes += size;
|
|
20676
20764
|
if (budget.bytes > MAX_SCAN_BYTES) throw new CodingWorkspaceError("workspace_limit_exceeded");
|
|
20677
20765
|
const algorithm = head.length === 64 ? "sha256" : "sha1";
|
|
20678
|
-
const hasher =
|
|
20766
|
+
const hasher = createHash16(algorithm).update(`blob ${size}\0`), stats = new GitTextStats();
|
|
20679
20767
|
const bytes = size <= WORKSPACE_DIFF_MAX_BLOB_BYTES ? Buffer.alloc(size) : null;
|
|
20680
20768
|
const chunk = Buffer.alloc(64 * 1024);
|
|
20681
20769
|
let offset = 0;
|
|
@@ -20715,7 +20803,7 @@ async function currentFile(root, path3, head, budget, signal, conversion, git3)
|
|
|
20715
20803
|
let blob = rawBlob, cleanSize = size;
|
|
20716
20804
|
if (normalize) {
|
|
20717
20805
|
cleanSize -= stats.crlf;
|
|
20718
|
-
const cleaned =
|
|
20806
|
+
const cleaned = createHash16(algorithm).update(`blob ${cleanSize}\0`), cleaner = new CRLFCleaner();
|
|
20719
20807
|
if (bytes) cleaned.update(cleaner.push(bytes));
|
|
20720
20808
|
else {
|
|
20721
20809
|
budget.bytes += size;
|
|
@@ -20999,8 +21087,8 @@ async function readWorkspaceRevertPreview(command, entry, repoPath) {
|
|
|
20999
21087
|
// src/coding-workspace/git.ts
|
|
21000
21088
|
import { constants as constants9 } from "node:fs";
|
|
21001
21089
|
import { lstat as lstat6, mkdtemp as mkdtemp3, open as open4, readFile as readFile7, realpath as realpath4, rm as rm5, unlink, writeFile as writeFile5 } from "node:fs/promises";
|
|
21002
|
-
import { createHash as
|
|
21003
|
-
import { join as
|
|
21090
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
21091
|
+
import { join as join35, resolve as resolve17 } from "node:path";
|
|
21004
21092
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
21005
21093
|
import { execa as execa14 } from "execa";
|
|
21006
21094
|
|
|
@@ -21134,7 +21222,7 @@ function parseHistoryCursor(cursor, headSha2) {
|
|
|
21134
21222
|
var historyCursor = (headSha2, offset) => `${headSha2}:${offset}`;
|
|
21135
21223
|
|
|
21136
21224
|
// src/coding-workspace/git.ts
|
|
21137
|
-
var digest8 = (value) =>
|
|
21225
|
+
var digest8 = (value) => createHash17("sha256").update(value).digest("hex");
|
|
21138
21226
|
var oid4 = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
21139
21227
|
var STATUS_BYTES = 8 * 1024 * 1024;
|
|
21140
21228
|
var STATUS_SCAN_BYTES = 16 * 1024 * 1024;
|
|
@@ -21596,7 +21684,7 @@ function runGit(cwd, args, env, signal, maximum = 8 * 1024 * 1024) {
|
|
|
21596
21684
|
}
|
|
21597
21685
|
async function readTempFile(worktree, path3) {
|
|
21598
21686
|
if (!visibleWorkspacePath(path3)) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
21599
|
-
const full =
|
|
21687
|
+
const full = join35(worktree, ...path3.split("/"));
|
|
21600
21688
|
if (!full.startsWith(`${worktree}/`)) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
21601
21689
|
try {
|
|
21602
21690
|
const stat3 = await lstat6(full);
|
|
@@ -21617,8 +21705,8 @@ async function dryRunCheckpoint(git3, root, identity, statusBase, patchBase, pat
|
|
|
21617
21705
|
} catch (error) {
|
|
21618
21706
|
throw new CodingWorkspaceError("workspace_unsupported", { cause: error });
|
|
21619
21707
|
}
|
|
21620
|
-
const parent = await mkdtemp3(
|
|
21621
|
-
const worktree =
|
|
21708
|
+
const parent = await mkdtemp3(join35(tmpdir7(), "mikka-git-restore-"));
|
|
21709
|
+
const worktree = join35(parent, "wt"), patchFile = join35(parent, "checkpoint.patch");
|
|
21622
21710
|
try {
|
|
21623
21711
|
await writeFile5(patchFile, patch, { mode: 384 });
|
|
21624
21712
|
await runGit(git3.commonDir, ["worktree", "add", "--detach", "--quiet", worktree, head], commonEnv(git3), signal);
|
|
@@ -21898,9 +21986,9 @@ async function handleWorkspaceGitRequest(command, entry, repoPath) {
|
|
|
21898
21986
|
}
|
|
21899
21987
|
|
|
21900
21988
|
// src/repositories.ts
|
|
21901
|
-
import { createHash as
|
|
21902
|
-
import { existsSync as
|
|
21903
|
-
import { dirname as dirname17, join as
|
|
21989
|
+
import { createHash as createHash18, randomUUID as randomUUID7 } from "node:crypto";
|
|
21990
|
+
import { existsSync as existsSync8, lstatSync as lstatSync12, mkdirSync as mkdirSync17, readdirSync as readdirSync9, realpathSync as realpathSync13, renameSync as renameSync5, rmSync as rmSync20 } from "node:fs";
|
|
21991
|
+
import { dirname as dirname17, join as join36, resolve as resolve18 } from "node:path";
|
|
21904
21992
|
import { setTimeout as delay } from "node:timers/promises";
|
|
21905
21993
|
import { execa as execa15 } from "execa";
|
|
21906
21994
|
import lockfile2 from "proper-lockfile";
|
|
@@ -21924,7 +22012,7 @@ var RepositoryCache = class {
|
|
|
21924
22012
|
retainResources;
|
|
21925
22013
|
pathFor(remoteUrl) {
|
|
21926
22014
|
const { key: key2 } = normalizeRepository(remoteUrl, { allowFile: this.allowFile });
|
|
21927
|
-
const path3 = resolve18(this.root, "v2",
|
|
22015
|
+
const path3 = resolve18(this.root, "v2", createHash18("sha256").update(key2).digest("hex"));
|
|
21928
22016
|
if (!isInside(resolve18(this.root), path3) || path3 === resolve18(this.root)) throw new Error("Invalid repository cache path");
|
|
21929
22017
|
return path3;
|
|
21930
22018
|
}
|
|
@@ -21960,7 +22048,7 @@ var RepositoryCache = class {
|
|
|
21960
22048
|
return diagnostics.timer ? diagnostics.timer.measure(phase, traced) : traced();
|
|
21961
22049
|
};
|
|
21962
22050
|
let cloned = false;
|
|
21963
|
-
if (!
|
|
22051
|
+
if (!existsSync8(path3)) {
|
|
21964
22052
|
const temporary = `${path3}.clone-${randomUUID7()}`;
|
|
21965
22053
|
try {
|
|
21966
22054
|
await git3(["clone", "--depth=50", "--no-single-branch", "--no-checkout", "--no-hardlinks", "--no-recurse-submodules", "--", remote, temporary]);
|
|
@@ -21972,7 +22060,7 @@ var RepositoryCache = class {
|
|
|
21972
22060
|
} else {
|
|
21973
22061
|
this.assertClone(path3);
|
|
21974
22062
|
await git3(["remote", "set-url", "origin", remote], path3);
|
|
21975
|
-
const depth =
|
|
22063
|
+
const depth = existsSync8(join36(path3, ".git", "shallow")) ? ["--depth=50"] : [];
|
|
21976
22064
|
await git3(["fetch", ...depth, ...this.retainResources ? [] : ["--prune"], "--no-tags", "--no-recurse-submodules", "--no-write-fetch-head", "origin"], path3);
|
|
21977
22065
|
}
|
|
21978
22066
|
this.assertClone(path3);
|
|
@@ -22063,12 +22151,12 @@ var RepositoryCache = class {
|
|
|
22063
22151
|
/** Cache paths for retention/orphan cleanup; never consult user checkouts. */
|
|
22064
22152
|
paths() {
|
|
22065
22153
|
const visit = (path3) => {
|
|
22066
|
-
if (!
|
|
22067
|
-
if (
|
|
22154
|
+
if (!existsSync8(path3) || lstatSync12(path3).isSymbolicLink()) return [];
|
|
22155
|
+
if (existsSync8(join36(path3, ".git"))) {
|
|
22068
22156
|
this.assertClone(path3);
|
|
22069
22157
|
return [path3];
|
|
22070
22158
|
}
|
|
22071
|
-
return readdirSync9(path3, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() && !entry.name.endsWith(".lock") && !entry.name.includes(".clone-") ? visit(
|
|
22159
|
+
return readdirSync9(path3, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() && !entry.name.endsWith(".lock") && !entry.name.includes(".clone-") ? visit(join36(path3, entry.name)) : []);
|
|
22072
22160
|
};
|
|
22073
22161
|
return visit(resolve18(this.root));
|
|
22074
22162
|
}
|
|
@@ -22078,14 +22166,14 @@ var RepositoryCache = class {
|
|
|
22078
22166
|
const root = realpathSync13(this.root);
|
|
22079
22167
|
let current = resolve18(this.root);
|
|
22080
22168
|
for (const part of path3.slice(current.length + 1).split("/").filter(Boolean)) {
|
|
22081
|
-
current =
|
|
22082
|
-
if (
|
|
22169
|
+
current = join36(current, part);
|
|
22170
|
+
if (existsSync8(current) && lstatSync12(current).isSymbolicLink()) throw new Error("Repository cache contains a symlink");
|
|
22083
22171
|
mkdirSync17(current, { recursive: true, mode: 448 });
|
|
22084
22172
|
if (!isInside(root, realpathSync13(current))) throw new Error("Repository cache escapes its directory");
|
|
22085
22173
|
}
|
|
22086
22174
|
}
|
|
22087
22175
|
assertClone(path3) {
|
|
22088
|
-
if (lstatSync12(path3).isSymbolicLink() || !lstatSync12(
|
|
22176
|
+
if (lstatSync12(path3).isSymbolicLink() || !lstatSync12(join36(path3, ".git")).isDirectory() || lstatSync12(join36(path3, ".git")).isSymbolicLink()) throw new Error("Repository cache is not a standard clone");
|
|
22089
22177
|
if (!isInside(realpathSync13(this.root), realpathSync13(path3))) throw new Error("Repository cache escapes its directory");
|
|
22090
22178
|
}
|
|
22091
22179
|
async lock(path3, signal) {
|
|
@@ -22190,12 +22278,12 @@ async function prepareRunRepository(repositories, privateDir, assignment, signal
|
|
|
22190
22278
|
// src/subscription-hosted-runner.ts
|
|
22191
22279
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
22192
22280
|
import { spawn as spawn5 } from "node:child_process";
|
|
22193
|
-
import { existsSync as
|
|
22194
|
-
import { dirname as dirname18, join as
|
|
22281
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync18, realpathSync as realpathSync14 } from "node:fs";
|
|
22282
|
+
import { dirname as dirname18, join as join37, resolve as resolve19 } from "node:path";
|
|
22195
22283
|
import { fileURLToPath } from "node:url";
|
|
22196
22284
|
|
|
22197
22285
|
// src/official-cli-timing.ts
|
|
22198
|
-
import { createHash as
|
|
22286
|
+
import { createHash as createHash19, randomBytes as randomBytes4 } from "node:crypto";
|
|
22199
22287
|
import { createServer as createServer4 } from "node:http";
|
|
22200
22288
|
|
|
22201
22289
|
// src/mcp-http-timing.ts
|
|
@@ -22519,7 +22607,7 @@ var OfficialCliTimingCollector = class {
|
|
|
22519
22607
|
};
|
|
22520
22608
|
async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, decisionCatalogue }) {
|
|
22521
22609
|
const collector = new OfficialCliTimingCollector(runId, harness);
|
|
22522
|
-
const expectedCatalogueSha256 = decisionCatalogue ?
|
|
22610
|
+
const expectedCatalogueSha256 = decisionCatalogue ? createHash19("sha256").update(JSON.stringify(decisionCatalogue)).digest("hex") : null;
|
|
22523
22611
|
const mcpCollector = new McpHttpTimingCollector(runId, harness, remoteMcpServerCount, Date.now, expectedCatalogueSha256);
|
|
22524
22612
|
const path3 = `/v1/logs/${randomBytes4(16).toString("hex")}`;
|
|
22525
22613
|
const mcpPath = `/v1/mcp-http/${randomBytes4(16).toString("hex")}`;
|
|
@@ -22826,7 +22914,7 @@ async function createHostedBotRunner(host) {
|
|
|
22826
22914
|
});
|
|
22827
22915
|
Object.assign(env, github.env);
|
|
22828
22916
|
}
|
|
22829
|
-
const ledger =
|
|
22917
|
+
const ledger = join37(host.stateDir, "native-ledgers", assignment.runId + ".json");
|
|
22830
22918
|
const scope = selected && subscription ? {
|
|
22831
22919
|
runId: assignment.runId,
|
|
22832
22920
|
bindingId: selected.bindingId,
|
|
@@ -22838,12 +22926,12 @@ async function createHostedBotRunner(host) {
|
|
|
22838
22926
|
accountId: subscription.first.accountId,
|
|
22839
22927
|
modelId: subscription.first.modelId
|
|
22840
22928
|
} : void 0;
|
|
22841
|
-
if (continuation &&
|
|
22842
|
-
const previousLedger = continuation ?
|
|
22929
|
+
if (continuation && existsSync9(ledger)) throw unavailable5("ledger_mismatch");
|
|
22930
|
+
const previousLedger = continuation ? join37(host.stateDir, "native-ledgers", continuation.runId + ".json") : ledger;
|
|
22843
22931
|
const previous = scope ? readJson(previousLedger) : void 0;
|
|
22844
22932
|
if (preparation && previous) throw unavailable5("ledger_mismatch");
|
|
22845
22933
|
const expectedScope = scope && continuation ? { ...scope, runId: continuation.runId } : scope;
|
|
22846
|
-
if (scope && (
|
|
22934
|
+
if (scope && (existsSync9(previousLedger) && (!previous || JSON.stringify(previous.scope) !== JSON.stringify(expectedScope) || typeof previous.sessionId !== "string") || assignment.requireSessionResume && (!previous || previous.sessionId !== assignment.resumeSessionId))) throw unavailable5("ledger_mismatch");
|
|
22847
22935
|
if (scope) mkdirSync18(dirname18(ledger), { recursive: true, mode: 448 });
|
|
22848
22936
|
const record3 = async (sessionId) => {
|
|
22849
22937
|
assertOpen();
|
|
@@ -23105,7 +23193,7 @@ async function createHostedBotRunner(host) {
|
|
|
23105
23193
|
import {
|
|
23106
23194
|
randomBytes as randomBytes5,
|
|
23107
23195
|
randomUUID as randomUUID9,
|
|
23108
|
-
createHash as
|
|
23196
|
+
createHash as createHash21,
|
|
23109
23197
|
timingSafeEqual as timingSafeEqual2
|
|
23110
23198
|
} from "node:crypto";
|
|
23111
23199
|
import { chmodSync as chmodSync2 } from "node:fs";
|
|
@@ -23115,7 +23203,7 @@ import { createServer as createServer5 } from "node:net";
|
|
|
23115
23203
|
import { spawn as spawn6 } from "node:child_process";
|
|
23116
23204
|
import { execFile as execFile8 } from "node:child_process";
|
|
23117
23205
|
import { promisify as promisify8 } from "node:util";
|
|
23118
|
-
import { createHash as
|
|
23206
|
+
import { createHash as createHash20 } from "node:crypto";
|
|
23119
23207
|
import { readFile as readFile8, realpath as realpath5 } from "node:fs/promises";
|
|
23120
23208
|
import { createInterface } from "node:readline";
|
|
23121
23209
|
var exec3 = promisify8(execFile8);
|
|
@@ -23132,7 +23220,7 @@ async function detectComputerDriver(binary = "cua-driver") {
|
|
|
23132
23220
|
installed: true,
|
|
23133
23221
|
version,
|
|
23134
23222
|
path: path3,
|
|
23135
|
-
fingerprint:
|
|
23223
|
+
fingerprint: createHash20("sha256").update(await readFile8(path3)).digest("hex")
|
|
23136
23224
|
};
|
|
23137
23225
|
} catch {
|
|
23138
23226
|
return null;
|
|
@@ -23199,7 +23287,7 @@ async function executeDriver(driver, input, display, leaseGuard, assertLive = ()
|
|
|
23199
23287
|
if (display !== void 0 && !/^:[1-9][0-9]{0,3}$/.test(display))
|
|
23200
23288
|
throw new Error("Invalid desktop display");
|
|
23201
23289
|
const call = normalizeCall(input);
|
|
23202
|
-
const fingerprint2 =
|
|
23290
|
+
const fingerprint2 = createHash20("sha256").update(await readFile8(driver.path)).digest("hex");
|
|
23203
23291
|
if (fingerprint2 !== driver.fingerprint)
|
|
23204
23292
|
throw new Error("Driver changed; restart and approve a new request");
|
|
23205
23293
|
const args = driverArguments(call);
|
|
@@ -23494,7 +23582,7 @@ var ComputerBroker = class {
|
|
|
23494
23582
|
call,
|
|
23495
23583
|
expiresAt: this.now() + this.ttl
|
|
23496
23584
|
};
|
|
23497
|
-
const digest9 =
|
|
23585
|
+
const digest9 = createHash21("sha256").update(JSON.stringify(request2)).digest("hex");
|
|
23498
23586
|
return new Promise((resolve20, reject) => {
|
|
23499
23587
|
const timer = setTimeout(() => {
|
|
23500
23588
|
this.pending.delete(request2.id);
|
|
@@ -23611,10 +23699,10 @@ var ComputerBroker = class {
|
|
|
23611
23699
|
};
|
|
23612
23700
|
|
|
23613
23701
|
// src/computer/credential-executor.ts
|
|
23614
|
-
import { createHash as
|
|
23702
|
+
import { createHash as createHash22 } from "node:crypto";
|
|
23615
23703
|
function credentialAwareExecutor(deps) {
|
|
23616
23704
|
return async (driver, call, display, runId, context) => {
|
|
23617
|
-
const digest9 =
|
|
23705
|
+
const digest9 = createHash22("sha256").update(JSON.stringify(call)).digest("hex");
|
|
23618
23706
|
const resolved = await deps.consumeMatchingIntent(runId, context.actionId, digest9);
|
|
23619
23707
|
context.assertLive();
|
|
23620
23708
|
if (resolved.kind === "ordinary") return deps.executeOrdinary(driver, call, display, runId, context.assertLive);
|
|
@@ -23896,7 +23984,7 @@ var Daemon = class {
|
|
|
23896
23984
|
if (this.options.credential)
|
|
23897
23985
|
this.saveDevice({ credential: this.options.credential });
|
|
23898
23986
|
this.journal = new RunJournal(paths.journal);
|
|
23899
|
-
this.captureUploader = new CaptureUploader((runId) =>
|
|
23987
|
+
this.captureUploader = new CaptureUploader((runId) => join38(runPaths(paths.adapterState, runId).runDir, CAPTURES_DIR), this.options.link, this.log, join38(paths.dataDir, "capture-pending"));
|
|
23900
23988
|
this.outbox = new Outbox(
|
|
23901
23989
|
paths.outbox,
|
|
23902
23990
|
this.options.link,
|
|
@@ -23915,7 +24003,7 @@ var Daemon = class {
|
|
|
23915
24003
|
if (this.localComputerDriver && this.options.link.syncComputerReviews) {
|
|
23916
24004
|
this.localComputerBroker = new ComputerBroker({
|
|
23917
24005
|
driver: this.localComputerDriver,
|
|
23918
|
-
socketPath:
|
|
24006
|
+
socketPath: join38(paths.dataDir, "local-computer.sock"),
|
|
23919
24007
|
transport: "tcp",
|
|
23920
24008
|
needsPerson: this.computerNeedsPerson(),
|
|
23921
24009
|
permitted: (runId) => {
|
|
@@ -23958,7 +24046,7 @@ var Daemon = class {
|
|
|
23958
24046
|
};
|
|
23959
24047
|
this.cloudComputerBroker = new ComputerBroker({
|
|
23960
24048
|
driver,
|
|
23961
|
-
socketPath:
|
|
24049
|
+
socketPath: join38(paths.dataDir, "computer.sock"),
|
|
23962
24050
|
needsPerson: this.computerNeedsPerson(),
|
|
23963
24051
|
permitted: (runId) => {
|
|
23964
24052
|
const entry = this.journal.get(runId);
|
|
@@ -24053,7 +24141,7 @@ var Daemon = class {
|
|
|
24053
24141
|
prepareRunDrive: this.options.link.prepareRunDrive?.bind(this.options.link),
|
|
24054
24142
|
prepareRunToolApproval: this.options.link.prepareRunToolApproval?.bind(this.options.link),
|
|
24055
24143
|
prepareRunGitHub: hosted ? void 0 : (assignment, signal, onCredential) => prepareLocalGitHub(assignment, {
|
|
24056
|
-
stateDir:
|
|
24144
|
+
stateDir: join38(this.paths.adapterState, "github"),
|
|
24057
24145
|
link: this.options.link,
|
|
24058
24146
|
signal,
|
|
24059
24147
|
onCredential,
|
|
@@ -24123,7 +24211,7 @@ var Daemon = class {
|
|
|
24123
24211
|
worktree,
|
|
24124
24212
|
tree,
|
|
24125
24213
|
github: { ...assignment.github, runToken: assignment.mcp?.token, issueId: assignment.issueId },
|
|
24126
|
-
privateDir:
|
|
24214
|
+
privateDir: join38(paths.adapterState, "pids"),
|
|
24127
24215
|
...hosted ? { hosted: true } : {},
|
|
24128
24216
|
env: hosted ? process.env : githubReceiptEnvironment(),
|
|
24129
24217
|
githubEnvironment,
|
|
@@ -24838,11 +24926,11 @@ var Daemon = class {
|
|
|
24838
24926
|
return runVerify(sandbox, {
|
|
24839
24927
|
command,
|
|
24840
24928
|
worktree: realpathSync15(worktree),
|
|
24841
|
-
tmpRoot:
|
|
24929
|
+
tmpRoot: join38(this.paths.adapterState, "verify", runId),
|
|
24842
24930
|
privateDir: paths.privateDir,
|
|
24843
24931
|
pidFile: paths.pidFile.replace(/\.pgid$/, ".verify.pgid"),
|
|
24844
24932
|
networkAllow: repo.networkAllow,
|
|
24845
|
-
env: { ...buildChildEnv(), ...githubEnvironment, MIKKA_HANDOFF_FILE:
|
|
24933
|
+
env: { ...buildChildEnv(), ...githubEnvironment, MIKKA_HANDOFF_FILE: join38(paths.runDir, "handoff.json") },
|
|
24846
24934
|
timeoutMs,
|
|
24847
24935
|
signal,
|
|
24848
24936
|
readOnly
|
|
@@ -24917,7 +25005,7 @@ var Daemon = class {
|
|
|
24917
25005
|
void this.stop().finally(() => this.options.onLockLost?.(error));
|
|
24918
25006
|
}
|
|
24919
25007
|
ensureSecret() {
|
|
24920
|
-
if (
|
|
25008
|
+
if (existsSync10(this.paths.secret)) {
|
|
24921
25009
|
return readFileSync15(this.paths.secret, "utf8").trim();
|
|
24922
25010
|
}
|
|
24923
25011
|
const secret = randomBytes6(32).toString("hex");
|
|
@@ -25397,7 +25485,7 @@ var Daemon = class {
|
|
|
25397
25485
|
});
|
|
25398
25486
|
}
|
|
25399
25487
|
get updateStateFile() {
|
|
25400
|
-
return
|
|
25488
|
+
return join38(this.paths.dataDir, "auto-update.json");
|
|
25401
25489
|
}
|
|
25402
25490
|
/** A server named this release (a report answer, a commands read, a 426), or npm did for a refused daemon. */
|
|
25403
25491
|
learnRelease(latest) {
|
|
@@ -25759,6 +25847,7 @@ async function runCli(argv, io = defaultIO, privateConfig) {
|
|
|
25759
25847
|
dir: daemonPaths(dataDir).logs,
|
|
25760
25848
|
stdout: flavor === "dev"
|
|
25761
25849
|
});
|
|
25850
|
+
let lifecycle;
|
|
25762
25851
|
const speed = values["mock-speed"] ? Number(values["mock-speed"]) : void 0;
|
|
25763
25852
|
try {
|
|
25764
25853
|
const daemon = await startDaemon({
|
|
@@ -25782,17 +25871,23 @@ async function runCli(argv, io = defaultIO, privateConfig) {
|
|
|
25782
25871
|
e2bContainerRuntime: values["e2b-container-runtime"],
|
|
25783
25872
|
cloudComputer: values["e2b-computer"],
|
|
25784
25873
|
stallMs: values["stall-minutes"] ? Number(values["stall-minutes"]) * 6e4 : void 0,
|
|
25785
|
-
onDrained: () =>
|
|
25786
|
-
|
|
25874
|
+
onDrained: () => {
|
|
25875
|
+
lifecycle?.stopping("drained");
|
|
25876
|
+
process.exit(0);
|
|
25877
|
+
},
|
|
25878
|
+
onLockLost: () => {
|
|
25879
|
+
lifecycle?.disown();
|
|
25880
|
+
process.exit(1);
|
|
25881
|
+
}
|
|
25787
25882
|
});
|
|
25788
|
-
|
|
25789
|
-
|
|
25883
|
+
lifecycle = trackDaemonLifecycle(daemonPaths(dataDir).logs);
|
|
25884
|
+
const shutdown = (signal, code) => {
|
|
25885
|
+
lifecycle?.stopping(`signal:${signal}`);
|
|
25886
|
+
void daemon.stop().then(() => process.exit(code));
|
|
25790
25887
|
};
|
|
25791
|
-
process.once("SIGUSR2", () =>
|
|
25792
|
-
|
|
25793
|
-
|
|
25794
|
-
process.once("SIGINT", shutdown);
|
|
25795
|
-
process.once("SIGTERM", shutdown);
|
|
25888
|
+
process.once("SIGUSR2", () => shutdown("SIGUSR2", 1));
|
|
25889
|
+
process.once("SIGINT", () => shutdown("SIGINT", 0));
|
|
25890
|
+
process.once("SIGTERM", () => shutdown("SIGTERM", 0));
|
|
25796
25891
|
return null;
|
|
25797
25892
|
} catch (error) {
|
|
25798
25893
|
if (error instanceof DaemonAlreadyRunningError) {
|