@aspectlylabs/mikka 0.0.714 → 0.0.716
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 +779 -511
- package/client.js +10 -2
- package/http-link.js +280 -21
- package/login.js +40 -22
- package/main.js +40 -11
- package/mikka-release-manifest.json +19 -19
- package/mikka.js +779 -511
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
- package/paths.js +2 -2
- package/sbom.cdx.json +7 -7
package/cli.js
CHANGED
|
@@ -1147,16 +1147,16 @@ var require_range = __commonJS({
|
|
|
1147
1147
|
};
|
|
1148
1148
|
var replaceTilde = (comp, options) => {
|
|
1149
1149
|
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
1150
|
-
const
|
|
1150
|
+
const z39 = options.includePrerelease ? "-0" : "";
|
|
1151
1151
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1152
1152
|
debug("tilde", comp, _, M, m, p, pr);
|
|
1153
1153
|
let ret;
|
|
1154
1154
|
if (isX(M)) {
|
|
1155
1155
|
ret = "";
|
|
1156
1156
|
} else if (isX(m)) {
|
|
1157
|
-
ret = `>=${M}.0.0${
|
|
1157
|
+
ret = `>=${M}.0.0${z39} <${+M + 1}.0.0-0`;
|
|
1158
1158
|
} else if (isX(p)) {
|
|
1159
|
-
ret = `>=${M}.${m}.0${
|
|
1159
|
+
ret = `>=${M}.${m}.0${z39} <${M}.${+m + 1}.0-0`;
|
|
1160
1160
|
} else if (pr) {
|
|
1161
1161
|
debug("replaceTilde pr", pr);
|
|
1162
1162
|
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
@@ -1173,19 +1173,19 @@ var require_range = __commonJS({
|
|
|
1173
1173
|
var replaceCaret = (comp, options) => {
|
|
1174
1174
|
debug("caret", comp, options);
|
|
1175
1175
|
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
|
|
1176
|
-
const
|
|
1176
|
+
const z39 = options.includePrerelease ? "-0" : "";
|
|
1177
1177
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1178
1178
|
debug("caret", comp, _, M, m, p, pr);
|
|
1179
1179
|
let ret;
|
|
1180
1180
|
if (isX(M)) {
|
|
1181
1181
|
ret = "";
|
|
1182
1182
|
} else if (isX(m)) {
|
|
1183
|
-
ret = `>=${M}.0.0${
|
|
1183
|
+
ret = `>=${M}.0.0${z39} <${+M + 1}.0.0-0`;
|
|
1184
1184
|
} else if (isX(p)) {
|
|
1185
1185
|
if (M === "0") {
|
|
1186
|
-
ret = `>=${M}.${m}.0${
|
|
1186
|
+
ret = `>=${M}.${m}.0${z39} <${M}.${+m + 1}.0-0`;
|
|
1187
1187
|
} else {
|
|
1188
|
-
ret = `>=${M}.${m}.0${
|
|
1188
|
+
ret = `>=${M}.${m}.0${z39} <${+M + 1}.0.0-0`;
|
|
1189
1189
|
}
|
|
1190
1190
|
} else if (pr) {
|
|
1191
1191
|
debug("replaceCaret pr", pr);
|
|
@@ -2102,11 +2102,11 @@ function daemonProcessAlive(dataDir) {
|
|
|
2102
2102
|
return pid !== null && processAlive(pid);
|
|
2103
2103
|
}
|
|
2104
2104
|
function socketAnswers(socketPath) {
|
|
2105
|
-
return new Promise((
|
|
2105
|
+
return new Promise((resolve20) => {
|
|
2106
2106
|
const socket = createConnection(socketPath);
|
|
2107
2107
|
const done = (alive) => {
|
|
2108
2108
|
socket.destroy();
|
|
2109
|
-
|
|
2109
|
+
resolve20(alive);
|
|
2110
2110
|
};
|
|
2111
2111
|
socket.once("connect", () => done(true));
|
|
2112
2112
|
socket.once("error", () => done(false));
|
|
@@ -2215,7 +2215,7 @@ function closeLogger(logger) {
|
|
|
2215
2215
|
const file = files.get(logger);
|
|
2216
2216
|
if (!file) return Promise.resolve();
|
|
2217
2217
|
files.delete(logger);
|
|
2218
|
-
return new Promise((
|
|
2218
|
+
return new Promise((resolve20) => file.end(resolve20));
|
|
2219
2219
|
}
|
|
2220
2220
|
|
|
2221
2221
|
// src/auto-update.ts
|
|
@@ -3504,6 +3504,14 @@ var USER_ERROR_CODES = {
|
|
|
3504
3504
|
"adapter_start_failed",
|
|
3505
3505
|
"cleanup_failed"
|
|
3506
3506
|
],
|
|
3507
|
+
/** Agent/Bot interop: reads, sends and Drive across threads and Bots (decision 2026-11-19-2200). */
|
|
3508
|
+
interop_not_found: [],
|
|
3509
|
+
interop_invalid_request: [],
|
|
3510
|
+
interop_scope_required: [],
|
|
3511
|
+
interop_send_unavailable: ["run_not_active", "thread_replaced", "thread_cannot_continue", "delivery_unavailable", "delivery_uncertain", "bot_unavailable", "continuation_requires_grant"],
|
|
3512
|
+
interop_diff_unavailable: ["no_checkpoint", "masked"],
|
|
3513
|
+
interop_drive_conflict: [],
|
|
3514
|
+
interop_drive_unavailable: ["file_too_large"],
|
|
3507
3515
|
cloud_machine_unfunded: []
|
|
3508
3516
|
};
|
|
3509
3517
|
|
|
@@ -3659,7 +3667,7 @@ function sensitiveTexts(errorNodes, context) {
|
|
|
3659
3667
|
else incomplete = true;
|
|
3660
3668
|
}
|
|
3661
3669
|
}
|
|
3662
|
-
const
|
|
3670
|
+
const walk2 = (value, depth) => {
|
|
3663
3671
|
if (++inspected > 8192 || depth > 8) {
|
|
3664
3672
|
incomplete = true;
|
|
3665
3673
|
return;
|
|
@@ -3667,7 +3675,7 @@ function sensitiveTexts(errorNodes, context) {
|
|
|
3667
3675
|
if (typeof value === "string") {
|
|
3668
3676
|
if (value.length <= MAX_INPUT && (value.trimStart().startsWith("[") || value.trimStart().startsWith("{"))) {
|
|
3669
3677
|
try {
|
|
3670
|
-
|
|
3678
|
+
walk2(JSON.parse(value), depth + 1);
|
|
3671
3679
|
return;
|
|
3672
3680
|
} catch {
|
|
3673
3681
|
}
|
|
@@ -3686,7 +3694,7 @@ function sensitiveTexts(errorNodes, context) {
|
|
|
3686
3694
|
incomplete = true;
|
|
3687
3695
|
continue;
|
|
3688
3696
|
}
|
|
3689
|
-
|
|
3697
|
+
walk2(descriptor.value, depth + 1);
|
|
3690
3698
|
}
|
|
3691
3699
|
} catch {
|
|
3692
3700
|
incomplete = true;
|
|
@@ -3696,7 +3704,7 @@ function sensitiveTexts(errorNodes, context) {
|
|
|
3696
3704
|
try {
|
|
3697
3705
|
const descriptor = Object.getOwnPropertyDescriptor(node, key2);
|
|
3698
3706
|
if (descriptor && !("value" in descriptor)) incomplete = true;
|
|
3699
|
-
else if (descriptor)
|
|
3707
|
+
else if (descriptor) walk2(descriptor.value, 0);
|
|
3700
3708
|
} catch {
|
|
3701
3709
|
incomplete = true;
|
|
3702
3710
|
}
|
|
@@ -6508,7 +6516,7 @@ function normalizeRepository(input, options = {}) {
|
|
|
6508
6516
|
|
|
6509
6517
|
// src/login.ts
|
|
6510
6518
|
import { arch, hostname, platform } from "node:os";
|
|
6511
|
-
import { z as
|
|
6519
|
+
import { z as z37 } from "zod";
|
|
6512
6520
|
|
|
6513
6521
|
// src/errors.ts
|
|
6514
6522
|
var DaemonError = class extends Error {
|
|
@@ -6596,7 +6604,7 @@ import { join as join4 } from "node:path";
|
|
|
6596
6604
|
// package.json
|
|
6597
6605
|
var package_default = {
|
|
6598
6606
|
name: "@mikka/daemon",
|
|
6599
|
-
version: "0.0.
|
|
6607
|
+
version: "0.0.716",
|
|
6600
6608
|
description: "Local Mikka daemon: runs agents through the user's own CLIs",
|
|
6601
6609
|
type: "module",
|
|
6602
6610
|
private: true,
|
|
@@ -6664,7 +6672,7 @@ var package_default = {
|
|
|
6664
6672
|
engines: {
|
|
6665
6673
|
node: ">=22"
|
|
6666
6674
|
},
|
|
6667
|
-
gitHead: "
|
|
6675
|
+
gitHead: "c0661a23ac7ffd231ef10ad15ce379b20991c120"
|
|
6668
6676
|
};
|
|
6669
6677
|
|
|
6670
6678
|
// src/paths.ts
|
|
@@ -6705,7 +6713,7 @@ function daemonPaths(dataDir) {
|
|
|
6705
6713
|
}
|
|
6706
6714
|
|
|
6707
6715
|
// src/server-link-http.ts
|
|
6708
|
-
import { z as
|
|
6716
|
+
import { z as z36 } from "zod";
|
|
6709
6717
|
|
|
6710
6718
|
// ../protocol/src/chat-attachments.ts
|
|
6711
6719
|
import { z as z32 } from "zod";
|
|
@@ -6818,7 +6826,7 @@ var ToolApprovalGate = class {
|
|
|
6818
6826
|
/** Resolves on the next push or revocation. A paused run waits here instead
|
|
6819
6827
|
* of asking the server on a timer. */
|
|
6820
6828
|
changed(signal) {
|
|
6821
|
-
return new Promise((
|
|
6829
|
+
return new Promise((resolve20, reject) => {
|
|
6822
6830
|
if (signal.aborted || this.revoked) {
|
|
6823
6831
|
reject(new Error("cancelled"));
|
|
6824
6832
|
return;
|
|
@@ -6827,7 +6835,7 @@ var ToolApprovalGate = class {
|
|
|
6827
6835
|
this.changes.delete(wake);
|
|
6828
6836
|
signal.removeEventListener("abort", abort);
|
|
6829
6837
|
if (error) reject(error);
|
|
6830
|
-
else
|
|
6838
|
+
else resolve20();
|
|
6831
6839
|
};
|
|
6832
6840
|
const wake = () => done(this.revoked ? new Error("cancelled") : void 0);
|
|
6833
6841
|
const abort = () => done(new Error("cancelled"));
|
|
@@ -7263,9 +7271,250 @@ async function createRunMailbox(host) {
|
|
|
7263
7271
|
return { tools, request: invoke, close };
|
|
7264
7272
|
}
|
|
7265
7273
|
|
|
7274
|
+
// src/run-drive.ts
|
|
7275
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
7276
|
+
import { lstat, mkdir as mkdir2, readFile as readFile2, readdir, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
7277
|
+
import { dirname as dirname4, extname, join as join5, relative, resolve as resolve3, sep } from "node:path";
|
|
7278
|
+
import { z as z35 } from "zod";
|
|
7279
|
+
var READ_LIMIT = 1024 * 1024;
|
|
7280
|
+
var WRITE_LIMIT = 4 * 1024 * 1024;
|
|
7281
|
+
var MAX_FILES = 2e3;
|
|
7282
|
+
var STATE_DIR = ".state";
|
|
7283
|
+
var scopeSchema = z35.object({ scope: z35.enum(["bot", "thread", "environment", "workspace"]), scopeId: z35.uuid(), write: z35.boolean() }).strict();
|
|
7284
|
+
var listingSchema = z35.object({
|
|
7285
|
+
volume: z35.object({ id: z35.string(), headDigest: z35.string(), entries: z35.array(z35.object({ path: z35.string(), sizeBytes: z35.number(), sha256: z35.string() })) }).nullable()
|
|
7286
|
+
}).passthrough();
|
|
7287
|
+
var stateSchema = z35.object({ volumeId: z35.string().nullable(), headDigest: z35.string().nullable(), files: z35.record(z35.string(), z35.string()) }).strict();
|
|
7288
|
+
var sha5 = (bytes) => createHash3("sha256").update(bytes).digest("hex");
|
|
7289
|
+
function localDrivePath(folder, path3) {
|
|
7290
|
+
if (!path3 || path3.startsWith("/") || path3.includes("\\") || path3.split("/").some((part) => !part || part === "." || part === "..")) return null;
|
|
7291
|
+
const target = resolve3(folder, ...path3.split("/"));
|
|
7292
|
+
return target.startsWith(resolve3(folder) + sep) ? target : null;
|
|
7293
|
+
}
|
|
7294
|
+
function conflictPath(path3, runId) {
|
|
7295
|
+
const ext = extname(path3);
|
|
7296
|
+
return `${ext ? path3.slice(0, -ext.length) : path3}.conflict-${runId.slice(0, 8)}${ext}`;
|
|
7297
|
+
}
|
|
7298
|
+
async function walk(folder) {
|
|
7299
|
+
const found = [];
|
|
7300
|
+
const visit = async (dir) => {
|
|
7301
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
7302
|
+
if (found.length >= MAX_FILES) return;
|
|
7303
|
+
const full = join5(dir, entry.name);
|
|
7304
|
+
if (entry.isSymbolicLink()) continue;
|
|
7305
|
+
if (entry.isDirectory()) await visit(full);
|
|
7306
|
+
else if (entry.isFile()) found.push(relative(folder, full).split(sep).join("/"));
|
|
7307
|
+
}
|
|
7308
|
+
};
|
|
7309
|
+
await visit(folder).catch((error) => {
|
|
7310
|
+
if (error.code !== "ENOENT") throw error;
|
|
7311
|
+
});
|
|
7312
|
+
return found;
|
|
7313
|
+
}
|
|
7314
|
+
function createDriveMirror(options) {
|
|
7315
|
+
const { root, runId, call } = options;
|
|
7316
|
+
const warn = options.warn ?? (() => {
|
|
7317
|
+
});
|
|
7318
|
+
const folderOf = (scope) => join5(root, scope.scope, scope.scopeId);
|
|
7319
|
+
const stateFile = (scope) => join5(root, STATE_DIR, `${scope.scope}-${scope.scopeId}.json`);
|
|
7320
|
+
const target = (scope) => ({ scope: scope.scope, scopeId: scope.scopeId });
|
|
7321
|
+
const readState2 = async (scope) => {
|
|
7322
|
+
try {
|
|
7323
|
+
return stateSchema.parse(JSON.parse(await readFile2(stateFile(scope), "utf8")));
|
|
7324
|
+
} catch {
|
|
7325
|
+
return { volumeId: null, headDigest: null, files: {} };
|
|
7326
|
+
}
|
|
7327
|
+
};
|
|
7328
|
+
const saveState = async (scope, state2) => {
|
|
7329
|
+
await mkdir2(join5(root, STATE_DIR), { recursive: true, mode: 448 });
|
|
7330
|
+
await writeFile2(stateFile(scope), JSON.stringify(state2), { mode: 384 });
|
|
7331
|
+
};
|
|
7332
|
+
const list = async (scope, volumeId) => {
|
|
7333
|
+
const result = await call("drive_list", { ...target(scope), ...volumeId ? { volumeId } : {} });
|
|
7334
|
+
if (result.isError) throw new Error(`drive_list ${String(result.value.error ?? "failed")}`);
|
|
7335
|
+
return listingSchema.parse(result.value).volume;
|
|
7336
|
+
};
|
|
7337
|
+
const download2 = async (scope, volumeId, path3, file, expected2) => {
|
|
7338
|
+
const result = await call("drive_read", { ...target(scope), volumeId, path: path3, encoding: "base64" });
|
|
7339
|
+
if (result.isError || typeof result.value.content !== "string") throw new Error(`drive_read ${String(result.value.error ?? "failed")}`);
|
|
7340
|
+
const bytes = Buffer.from(result.value.content, "base64");
|
|
7341
|
+
if (sha5(bytes) !== expected2) throw new Error("drive_read digest mismatch");
|
|
7342
|
+
await mkdir2(dirname4(file), { recursive: true });
|
|
7343
|
+
await writeFile2(file, bytes);
|
|
7344
|
+
};
|
|
7345
|
+
async function pullScope(scope) {
|
|
7346
|
+
const folder = folderOf(scope);
|
|
7347
|
+
await mkdir2(folder, { recursive: true, mode: 448 });
|
|
7348
|
+
const previous = await readState2(scope);
|
|
7349
|
+
const volume = await list(scope);
|
|
7350
|
+
const state2 = { volumeId: volume?.id ?? null, headDigest: volume?.headDigest ?? null, files: {} };
|
|
7351
|
+
const remote = /* @__PURE__ */ new Set();
|
|
7352
|
+
for (const entry of volume?.entries ?? []) {
|
|
7353
|
+
const file = localDrivePath(folder, entry.path);
|
|
7354
|
+
if (!file) continue;
|
|
7355
|
+
remote.add(entry.path);
|
|
7356
|
+
if (entry.sizeBytes > READ_LIMIT) continue;
|
|
7357
|
+
let local = null;
|
|
7358
|
+
try {
|
|
7359
|
+
local = sha5(await readFile2(file));
|
|
7360
|
+
} catch {
|
|
7361
|
+
}
|
|
7362
|
+
if (local !== entry.sha256) await download2(scope, volume.id, entry.path, file, entry.sha256);
|
|
7363
|
+
state2.files[entry.path] = entry.sha256;
|
|
7364
|
+
}
|
|
7365
|
+
for (const path3 of Object.keys(previous.files)) {
|
|
7366
|
+
if (remote.has(path3)) continue;
|
|
7367
|
+
const file = localDrivePath(folder, path3);
|
|
7368
|
+
if (file) await rm2(file, { force: true });
|
|
7369
|
+
}
|
|
7370
|
+
await saveState(scope, state2);
|
|
7371
|
+
}
|
|
7372
|
+
async function write(scope, state2, path3, bytes) {
|
|
7373
|
+
const content = bytes === null ? {} : { content: bytes.toString("base64"), encoding: "base64" };
|
|
7374
|
+
const fingerprint2 = sha5(`${path3}\0${bytes === null ? "delete" : sha5(bytes)}`).slice(0, 32);
|
|
7375
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
7376
|
+
const result = await call("drive_write", {
|
|
7377
|
+
...target(scope),
|
|
7378
|
+
...state2.volumeId ? { volumeId: state2.volumeId } : {},
|
|
7379
|
+
path: path3,
|
|
7380
|
+
...content,
|
|
7381
|
+
expectedDigest: state2.headDigest ?? "0".repeat(64),
|
|
7382
|
+
mutationId: `sync:${runId}:${fingerprint2}:${attempt}`
|
|
7383
|
+
});
|
|
7384
|
+
if (!result.isError) {
|
|
7385
|
+
state2.volumeId = String(result.value.volumeId);
|
|
7386
|
+
state2.headDigest = String(result.value.headDigest);
|
|
7387
|
+
return "ok";
|
|
7388
|
+
}
|
|
7389
|
+
if (result.value.error !== "interop_drive_conflict") throw new Error(`drive_write ${String(result.value.error ?? "failed")}`);
|
|
7390
|
+
const volume = await list(scope, state2.volumeId);
|
|
7391
|
+
state2.volumeId = volume?.id ?? state2.volumeId;
|
|
7392
|
+
state2.headDigest = volume?.headDigest ?? (typeof result.value.headDigest === "string" ? result.value.headDigest : state2.headDigest);
|
|
7393
|
+
const remoteSha = volume?.entries.find((entry) => entry.path === path3)?.sha256 ?? null;
|
|
7394
|
+
if (remoteSha !== (state2.files[path3] ?? null)) return "conflict";
|
|
7395
|
+
}
|
|
7396
|
+
return "conflict";
|
|
7397
|
+
}
|
|
7398
|
+
async function pushScope(scope) {
|
|
7399
|
+
if (!scope.write) return;
|
|
7400
|
+
const folder = folderOf(scope);
|
|
7401
|
+
const state2 = await readState2(scope);
|
|
7402
|
+
const local = /* @__PURE__ */ new Map();
|
|
7403
|
+
for (const path3 of await walk(folder)) {
|
|
7404
|
+
const file = localDrivePath(folder, path3);
|
|
7405
|
+
if (!file || (await lstat(file)).size > WRITE_LIMIT) continue;
|
|
7406
|
+
local.set(path3, await readFile2(file));
|
|
7407
|
+
}
|
|
7408
|
+
const changes = [];
|
|
7409
|
+
for (const [path3, bytes] of local) if (state2.files[path3] !== sha5(bytes)) changes.push({ path: path3, bytes });
|
|
7410
|
+
for (const path3 of Object.keys(state2.files)) if (!local.has(path3)) changes.push({ path: path3, bytes: null });
|
|
7411
|
+
if (!changes.length) return;
|
|
7412
|
+
let conflicted = false;
|
|
7413
|
+
for (const change of changes) {
|
|
7414
|
+
const outcome = await write(scope, state2, change.path, change.bytes);
|
|
7415
|
+
if (outcome === "ok") {
|
|
7416
|
+
if (change.bytes === null) delete state2.files[change.path];
|
|
7417
|
+
else state2.files[change.path] = sha5(change.bytes);
|
|
7418
|
+
continue;
|
|
7419
|
+
}
|
|
7420
|
+
conflicted = true;
|
|
7421
|
+
if (change.bytes !== null) {
|
|
7422
|
+
const copy = conflictPath(change.path, runId);
|
|
7423
|
+
if (await write(scope, state2, copy, change.bytes) === "ok") state2.files[copy] = sha5(change.bytes);
|
|
7424
|
+
warn("drive sync conflict kept as a copy", { scope: scope.scope, path: change.path });
|
|
7425
|
+
}
|
|
7426
|
+
}
|
|
7427
|
+
await saveState(scope, state2);
|
|
7428
|
+
if (conflicted) await pullScope(scope);
|
|
7429
|
+
}
|
|
7430
|
+
const each = async (work, label2) => {
|
|
7431
|
+
for (const scope of options.scopes) {
|
|
7432
|
+
try {
|
|
7433
|
+
await work(scope);
|
|
7434
|
+
} catch (error) {
|
|
7435
|
+
warn(`drive ${label2} failed`, { scope: scope.scope, error: error instanceof Error ? error.name : "Error" });
|
|
7436
|
+
}
|
|
7437
|
+
}
|
|
7438
|
+
};
|
|
7439
|
+
let pushing;
|
|
7440
|
+
return {
|
|
7441
|
+
folders: options.scopes.map((scope) => ({ scope: scope.scope, path: folderOf(scope), write: scope.write })),
|
|
7442
|
+
pull: () => each(pullScope, "pull"),
|
|
7443
|
+
// Pushes never overlap: a checkpoint and the terminal push run one after the other.
|
|
7444
|
+
push: () => pushing = (pushing ?? Promise.resolve()).then(() => each(pushScope, "push"))
|
|
7445
|
+
};
|
|
7446
|
+
}
|
|
7447
|
+
async function createRunDrive(host) {
|
|
7448
|
+
const assigned = host.assignment.mcp;
|
|
7449
|
+
if (!assigned) return void 0;
|
|
7450
|
+
let endpoint;
|
|
7451
|
+
try {
|
|
7452
|
+
endpoint = new URL(assigned.url);
|
|
7453
|
+
} catch {
|
|
7454
|
+
return void 0;
|
|
7455
|
+
}
|
|
7456
|
+
if (endpoint.href !== host.endpoint.href || !trustedServerEndpoint(endpoint) || !/^mkw_[A-Za-z0-9_-]{43}$/.test(assigned.token)) return void 0;
|
|
7457
|
+
let nextId = 0, session = null, version = "2025-03-26";
|
|
7458
|
+
const rpc = async (method, params, notification = false) => {
|
|
7459
|
+
const id5 = ++nextId;
|
|
7460
|
+
const response = await host.fetch(endpoint, {
|
|
7461
|
+
method: "POST",
|
|
7462
|
+
redirect: "error",
|
|
7463
|
+
headers: {
|
|
7464
|
+
...host.headers,
|
|
7465
|
+
"content-type": "application/json",
|
|
7466
|
+
accept: "application/json, text/event-stream",
|
|
7467
|
+
authorization: `Bearer ${assigned.token}`,
|
|
7468
|
+
"MCP-Protocol-Version": version,
|
|
7469
|
+
...session ? { "Mcp-Session-Id": session } : {}
|
|
7470
|
+
},
|
|
7471
|
+
signal: AbortSignal.any([host.signal, AbortSignal.timeout(3e4)]),
|
|
7472
|
+
body: JSON.stringify({ jsonrpc: "2.0", ...!notification ? { id: id5 } : {}, method, params })
|
|
7473
|
+
});
|
|
7474
|
+
if (!response.ok) {
|
|
7475
|
+
await response.body?.cancel();
|
|
7476
|
+
throw new Error(`drive rpc ${response.status}`);
|
|
7477
|
+
}
|
|
7478
|
+
const sid = response.headers.get("mcp-session-id");
|
|
7479
|
+
if (sid && sid.length <= 256 && !/[\r\n]/.test(sid)) session = sid;
|
|
7480
|
+
if (notification) {
|
|
7481
|
+
await response.body?.cancel();
|
|
7482
|
+
return null;
|
|
7483
|
+
}
|
|
7484
|
+
const text4 = await response.text();
|
|
7485
|
+
if (text4.length > 8 * 1024 * 1024) throw new Error("drive rpc too large");
|
|
7486
|
+
const packet = response.headers.get("content-type")?.split(";")[0] === "text/event-stream" ? JSON.parse(text4.split(/\r?\n/).find((line) => line.startsWith("data:"))?.slice(5) ?? "null") : JSON.parse(text4);
|
|
7487
|
+
if (packet?.jsonrpc !== "2.0" || packet.id !== id5 || packet.error || !packet.result) throw new Error("drive rpc failed");
|
|
7488
|
+
return packet.result;
|
|
7489
|
+
};
|
|
7490
|
+
const call = async (name, args) => {
|
|
7491
|
+
const result = await rpc("tools/call", { name, arguments: args });
|
|
7492
|
+
const text4 = result.content?.find((part) => part.type === "text")?.text;
|
|
7493
|
+
if (typeof text4 !== "string") throw new Error("drive tool result missing");
|
|
7494
|
+
return { isError: result.isError === true, value: JSON.parse(text4) };
|
|
7495
|
+
};
|
|
7496
|
+
try {
|
|
7497
|
+
const initialized = await rpc("initialize", { protocolVersion: version, capabilities: {}, clientInfo: { name: "mikka-run-drive", version: "1" } });
|
|
7498
|
+
if (["2025-03-26", "2025-06-18", "2025-11-25"].includes(initialized.protocolVersion)) version = initialized.protocolVersion;
|
|
7499
|
+
await rpc("notifications/initialized", {}, true);
|
|
7500
|
+
const plan = await call("drive_sync_scopes", {});
|
|
7501
|
+
if (plan.isError) return void 0;
|
|
7502
|
+
const scopes = z35.array(scopeSchema).max(8).parse(plan.value.scopes);
|
|
7503
|
+
if (!scopes.length) return void 0;
|
|
7504
|
+
return createDriveMirror({ root: host.root, runId: host.assignment.runId, scopes, call, warn: host.warn });
|
|
7505
|
+
} catch (error) {
|
|
7506
|
+
host.warn?.("drive mirror unavailable", { error: error instanceof Error ? error.name : "Error" });
|
|
7507
|
+
return void 0;
|
|
7508
|
+
}
|
|
7509
|
+
}
|
|
7510
|
+
|
|
7511
|
+
// src/server-link-http.ts
|
|
7512
|
+
import { homedir as homedir4 } from "node:os";
|
|
7513
|
+
import { join as joinPath } from "node:path";
|
|
7514
|
+
|
|
7266
7515
|
// src/tracing.ts
|
|
7267
7516
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7268
|
-
import { createHash as
|
|
7517
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
7269
7518
|
import { ROOT_CONTEXT as ROOT_CONTEXT2, SpanStatusCode as SpanStatusCode3, isSpanContextValid, trace as trace3 } from "@opentelemetry/api";
|
|
7270
7519
|
import { ExportResultCode as ExportResultCode2, W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
7271
7520
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
@@ -7701,7 +7950,7 @@ function daemonSampleRate(settings, env = process.env) {
|
|
|
7701
7950
|
return Math.min(1, Math.max(0, rate));
|
|
7702
7951
|
}
|
|
7703
7952
|
function runIdHash(runId) {
|
|
7704
|
-
return
|
|
7953
|
+
return createHash4("sha256").update(runId).digest("hex").slice(0, 16);
|
|
7705
7954
|
}
|
|
7706
7955
|
function routeTemplate(path3) {
|
|
7707
7956
|
const clean = path3.split(/[?#]/, 1)[0];
|
|
@@ -8121,8 +8370,8 @@ var DaemonTracer = class {
|
|
|
8121
8370
|
let timer;
|
|
8122
8371
|
await Promise.race([
|
|
8123
8372
|
work,
|
|
8124
|
-
new Promise((
|
|
8125
|
-
timer = setTimeout(
|
|
8373
|
+
new Promise((resolve20) => {
|
|
8374
|
+
timer = setTimeout(resolve20, timeoutMs);
|
|
8126
8375
|
timer.unref();
|
|
8127
8376
|
})
|
|
8128
8377
|
]).finally(() => {
|
|
@@ -8433,7 +8682,7 @@ var RunRuntimeTimings = class {
|
|
|
8433
8682
|
var runRuntimeTimings = new RunRuntimeTimings();
|
|
8434
8683
|
|
|
8435
8684
|
// src/server-link-http.ts
|
|
8436
|
-
var deviceSessionRejection =
|
|
8685
|
+
var deviceSessionRejection = z36.object({ error: z36.enum(["Unauthorized", "authRequired"]) }).strict();
|
|
8437
8686
|
var refusalCode = (body) => {
|
|
8438
8687
|
if (typeof body !== "object" || body === null) return void 0;
|
|
8439
8688
|
const { code, error } = body;
|
|
@@ -8541,12 +8790,12 @@ var HttpServerLink = class {
|
|
|
8541
8790
|
}
|
|
8542
8791
|
/** Asks the server's Decisions API for one run. Never throws; null on any failure. */
|
|
8543
8792
|
decide = async (runId, request2, signal) => {
|
|
8544
|
-
const answer =
|
|
8545
|
-
|
|
8546
|
-
|
|
8793
|
+
const answer = z36.discriminatedUnion("type", [
|
|
8794
|
+
z36.object({ type: z36.literal("predicate"), name: z36.string(), probability: z36.number() }),
|
|
8795
|
+
z36.object({ type: z36.literal("choice"), name: z36.string(), choice: z36.string() })
|
|
8547
8796
|
]);
|
|
8548
8797
|
try {
|
|
8549
|
-
const { answers } = await this.call("POST", `/v1/runs/${seg2(runId)}/decision`, { body: request2, schema:
|
|
8798
|
+
const { answers } = await this.call("POST", `/v1/runs/${seg2(runId)}/decision`, { body: request2, schema: z36.object({ answers: z36.array(answer).nullable() }), signal, timeoutMs: 6e3 });
|
|
8550
8799
|
return answers ? new Map(answers.map((item) => [item.name, item])) : null;
|
|
8551
8800
|
} catch {
|
|
8552
8801
|
return null;
|
|
@@ -8585,6 +8834,16 @@ var HttpServerLink = class {
|
|
|
8585
8834
|
headers: { [CLIENT_VERSION_HEADER]: this.clientVersion, ...deviceSessionHeaders, ...this.protectionBypass ? { "x-vercel-protection-bypass": this.protectionBypass } : {} }
|
|
8586
8835
|
});
|
|
8587
8836
|
}
|
|
8837
|
+
async prepareRunDrive(assignment, signal) {
|
|
8838
|
+
return createRunDrive({
|
|
8839
|
+
assignment,
|
|
8840
|
+
signal,
|
|
8841
|
+
endpoint: serverUrl(this.baseUrl, "/api/mcp"),
|
|
8842
|
+
root: joinPath(process.env.HOME || homedir4(), ".mikka", "drive"),
|
|
8843
|
+
fetch: (url, init) => this.taskFetch(assignment.runId, "task_data", url, init),
|
|
8844
|
+
headers: { [CLIENT_VERSION_HEADER]: this.clientVersion, ...deviceSessionHeaders, ...this.protectionBypass ? { "x-vercel-protection-bypass": this.protectionBypass } : {} }
|
|
8845
|
+
});
|
|
8846
|
+
}
|
|
8588
8847
|
async claimCoordinator(deviceId, signal) {
|
|
8589
8848
|
const response = await this.send("POST", `/v1/devices/${seg2(deviceId)}/coordinator`, { operation: "claim" }, this.credential, { signal });
|
|
8590
8849
|
if (response.status === 404) return null;
|
|
@@ -8945,16 +9204,16 @@ var updateRequired = () => new LoginError("failed", "This daemon is too old for
|
|
|
8945
9204
|
var DEVICE_CODE_PATH = `${AUTH_BASE_PATH}/device/code`;
|
|
8946
9205
|
var DEVICE_TOKEN_PATH = `${AUTH_BASE_PATH}/device/token`;
|
|
8947
9206
|
var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
8948
|
-
var deviceCodeResponse =
|
|
8949
|
-
device_code:
|
|
8950
|
-
user_code:
|
|
8951
|
-
verification_uri:
|
|
8952
|
-
verification_uri_complete:
|
|
8953
|
-
expires_in:
|
|
8954
|
-
interval:
|
|
9207
|
+
var deviceCodeResponse = z37.object({
|
|
9208
|
+
device_code: z37.string().min(1),
|
|
9209
|
+
user_code: z37.string().min(1),
|
|
9210
|
+
verification_uri: z37.string(),
|
|
9211
|
+
verification_uri_complete: z37.string().optional(),
|
|
9212
|
+
expires_in: z37.number().positive(),
|
|
9213
|
+
interval: z37.number().positive().default(5)
|
|
8955
9214
|
});
|
|
8956
|
-
var tokenResponse =
|
|
8957
|
-
var errorResponse =
|
|
9215
|
+
var tokenResponse = z37.object({ access_token: z37.string().regex(/^orv_[A-Za-z0-9_-]{43}$/) });
|
|
9216
|
+
var errorResponse = z37.object({ error: z37.string() });
|
|
8958
9217
|
var LoginError = class extends DaemonError {
|
|
8959
9218
|
constructor(reason, message) {
|
|
8960
9219
|
super(4003, message);
|
|
@@ -8986,7 +9245,7 @@ async function post(options, path3, body) {
|
|
|
8986
9245
|
};
|
|
8987
9246
|
}
|
|
8988
9247
|
async function deviceLogin(options) {
|
|
8989
|
-
const sleep3 = options.sleep ?? ((ms2) => new Promise((
|
|
9248
|
+
const sleep3 = options.sleep ?? ((ms2) => new Promise((resolve20) => setTimeout(resolve20, ms2)));
|
|
8990
9249
|
const started = await post(options, DEVICE_CODE_PATH, {
|
|
8991
9250
|
client_id: DAEMON_CLIENT_ID,
|
|
8992
9251
|
device_name: options.deviceName ?? hostname(),
|
|
@@ -9060,7 +9319,7 @@ import {
|
|
|
9060
9319
|
realpathSync as realpathSync15
|
|
9061
9320
|
} from "node:fs";
|
|
9062
9321
|
import { arch as arch3, hostname as hostname2, platform as platform3 } from "node:os";
|
|
9063
|
-
import { join as
|
|
9322
|
+
import { join as join36 } from "node:path";
|
|
9064
9323
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
9065
9324
|
|
|
9066
9325
|
// src/runs/quota-exhausted.ts
|
|
@@ -9144,7 +9403,7 @@ function quotaStopApplies(assignment) {
|
|
|
9144
9403
|
import { spawn as spawn2 } from "node:child_process";
|
|
9145
9404
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
9146
9405
|
import { realpathSync as realpathSync10 } from "node:fs";
|
|
9147
|
-
import { join as
|
|
9406
|
+
import { join as join15 } from "node:path";
|
|
9148
9407
|
|
|
9149
9408
|
// src/adapters/generation-metrics.ts
|
|
9150
9409
|
var record2 = (value) => value && typeof value === "object" ? value : {};
|
|
@@ -9279,14 +9538,14 @@ import { realpathSync as realpathSync2 } from "node:fs";
|
|
|
9279
9538
|
function prepareAgentStart(signal, open5, diagnostics) {
|
|
9280
9539
|
const lifetime = new AbortController();
|
|
9281
9540
|
let accept, refuse2;
|
|
9282
|
-
const finalOptions = new Promise((
|
|
9283
|
-
accept =
|
|
9541
|
+
const finalOptions = new Promise((resolve20, reject) => {
|
|
9542
|
+
accept = resolve20;
|
|
9284
9543
|
refuse2 = reject;
|
|
9285
9544
|
});
|
|
9286
9545
|
void finalOptions.catch(() => void 0);
|
|
9287
9546
|
let parked, failed;
|
|
9288
|
-
const ready = new Promise((
|
|
9289
|
-
parked =
|
|
9547
|
+
const ready = new Promise((resolve20, reject) => {
|
|
9548
|
+
parked = resolve20;
|
|
9290
9549
|
failed = reject;
|
|
9291
9550
|
});
|
|
9292
9551
|
void ready.catch(() => void 0);
|
|
@@ -9369,8 +9628,8 @@ var ClaimedPromptQueue = class {
|
|
|
9369
9628
|
while (!this.closed) {
|
|
9370
9629
|
const item = this.items.shift();
|
|
9371
9630
|
if (item) yield item;
|
|
9372
|
-
else await new Promise((
|
|
9373
|
-
this.wake =
|
|
9631
|
+
else await new Promise((resolve20) => {
|
|
9632
|
+
this.wake = resolve20;
|
|
9374
9633
|
});
|
|
9375
9634
|
}
|
|
9376
9635
|
}
|
|
@@ -9506,7 +9765,7 @@ import {
|
|
|
9506
9765
|
rmSync as rmSync3,
|
|
9507
9766
|
writeFileSync as writeFileSync2
|
|
9508
9767
|
} from "node:fs";
|
|
9509
|
-
import { dirname as
|
|
9768
|
+
import { dirname as dirname5 } from "node:path";
|
|
9510
9769
|
import { execa } from "execa";
|
|
9511
9770
|
|
|
9512
9771
|
// src/agents/harness-home.ts
|
|
@@ -9518,7 +9777,7 @@ import {
|
|
|
9518
9777
|
rmSync as rmSync2,
|
|
9519
9778
|
writeFileSync
|
|
9520
9779
|
} from "node:fs";
|
|
9521
|
-
import { join as
|
|
9780
|
+
import { join as join6 } from "node:path";
|
|
9522
9781
|
|
|
9523
9782
|
// src/credential-globs.ts
|
|
9524
9783
|
var CLOUD_WORKER_STATE_DIR = "/home/user/.mikka/worker/adapters";
|
|
@@ -9573,25 +9832,25 @@ var CODEX_CONFIG = [
|
|
|
9573
9832
|
].join("\n");
|
|
9574
9833
|
function prepareCodexHome(dir, log) {
|
|
9575
9834
|
ownDir(dir);
|
|
9576
|
-
writeOwnFile(
|
|
9577
|
-
if (lstatSync(
|
|
9835
|
+
writeOwnFile(join6(dir, "config.toml"), CODEX_CONFIG);
|
|
9836
|
+
if (lstatSync(join6(dir, "auth.json"), { throwIfNoEntry: false })) {
|
|
9578
9837
|
log.warn("removing a credential file left in the run's codex home");
|
|
9579
|
-
rmSync2(
|
|
9838
|
+
rmSync2(join6(dir, "auth.json"), { force: true, recursive: true });
|
|
9580
9839
|
}
|
|
9581
9840
|
return { home: dir };
|
|
9582
9841
|
}
|
|
9583
9842
|
function wipeRunCredentials(runDir) {
|
|
9584
|
-
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync2(
|
|
9843
|
+
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync2(join6(runDir, path3), { force: true, recursive: true });
|
|
9585
9844
|
}
|
|
9586
9845
|
function sweepRunCredentials(stateDir) {
|
|
9587
|
-
rmSync2(
|
|
9846
|
+
rmSync2(join6(stateDir, "github"), { recursive: true, force: true });
|
|
9588
9847
|
let runs;
|
|
9589
9848
|
try {
|
|
9590
|
-
runs = readdirSync(
|
|
9849
|
+
runs = readdirSync(join6(stateDir, "runs"));
|
|
9591
9850
|
} catch {
|
|
9592
9851
|
return;
|
|
9593
9852
|
}
|
|
9594
|
-
for (const run3 of runs) wipeRunCredentials(
|
|
9853
|
+
for (const run3 of runs) wipeRunCredentials(join6(stateDir, "runs", run3));
|
|
9595
9854
|
}
|
|
9596
9855
|
function writeOwnFile(file, content) {
|
|
9597
9856
|
rmSync2(file, { force: true, recursive: true });
|
|
@@ -9606,9 +9865,9 @@ function carryHistory(from, to, entries) {
|
|
|
9606
9865
|
if (!lstatSync(from, { throwIfNoEntry: false })?.isDirectory()) return;
|
|
9607
9866
|
ownDir(to);
|
|
9608
9867
|
for (const entry of entries) {
|
|
9609
|
-
const source =
|
|
9868
|
+
const source = join6(from, entry);
|
|
9610
9869
|
if (!lstatSync(source, { throwIfNoEntry: false })) continue;
|
|
9611
|
-
cpSync(source,
|
|
9870
|
+
cpSync(source, join6(to, entry), {
|
|
9612
9871
|
recursive: true,
|
|
9613
9872
|
force: true,
|
|
9614
9873
|
filter: (path3) => !lstatSync(path3).isSymbolicLink()
|
|
@@ -9655,8 +9914,8 @@ var EventQueue = class {
|
|
|
9655
9914
|
if (next.type === "exit") return;
|
|
9656
9915
|
continue;
|
|
9657
9916
|
}
|
|
9658
|
-
await new Promise((
|
|
9659
|
-
this.waiter =
|
|
9917
|
+
await new Promise((resolve20) => {
|
|
9918
|
+
this.waiter = resolve20;
|
|
9660
9919
|
});
|
|
9661
9920
|
}
|
|
9662
9921
|
}
|
|
@@ -9723,7 +9982,7 @@ async function spawnCli(sandbox, argv, options) {
|
|
|
9723
9982
|
});
|
|
9724
9983
|
const pgid = child.pid;
|
|
9725
9984
|
if (pgid !== void 0) {
|
|
9726
|
-
mkdirSync4(
|
|
9985
|
+
mkdirSync4(dirname5(options.pidFile), { recursive: true, mode: 448 });
|
|
9727
9986
|
rmSync3(options.pidFile, { force: true });
|
|
9728
9987
|
writeFileSync2(options.pidFile, String(pgid), { flag: "wx", mode: 384 });
|
|
9729
9988
|
}
|
|
@@ -9733,13 +9992,13 @@ async function spawnCli(sandbox, argv, options) {
|
|
|
9733
9992
|
stderr = (stderr + data).slice(-STDERR_TAIL * 4);
|
|
9734
9993
|
});
|
|
9735
9994
|
const exited = new Promise(
|
|
9736
|
-
(
|
|
9995
|
+
(resolve20) => {
|
|
9737
9996
|
child.once("error", (error) => {
|
|
9738
9997
|
stderr += `
|
|
9739
9998
|
${error.message}`;
|
|
9740
|
-
|
|
9999
|
+
resolve20({ code: null, signal: null });
|
|
9741
10000
|
});
|
|
9742
|
-
child.once("exit", (code, signal) =>
|
|
10001
|
+
child.once("exit", (code, signal) => resolve20({ code, signal }));
|
|
9743
10002
|
}
|
|
9744
10003
|
).finally(() => {
|
|
9745
10004
|
signalGroup(pgid, "SIGKILL");
|
|
@@ -9756,8 +10015,8 @@ ${error.message}`;
|
|
|
9756
10015
|
let timer;
|
|
9757
10016
|
await Promise.race([
|
|
9758
10017
|
exited,
|
|
9759
|
-
new Promise((
|
|
9760
|
-
timer = setTimeout(
|
|
10018
|
+
new Promise((resolve20) => {
|
|
10019
|
+
timer = setTimeout(resolve20, graceMs);
|
|
9761
10020
|
})
|
|
9762
10021
|
]);
|
|
9763
10022
|
clearTimeout(timer);
|
|
@@ -9803,16 +10062,16 @@ function errorMessage(error) {
|
|
|
9803
10062
|
|
|
9804
10063
|
// src/agents/github-runtime.ts
|
|
9805
10064
|
import { existsSync as existsSync3, lstatSync as lstatSync4, mkdirSync as mkdirSync6, mkdtempSync as mkdtempSync2, realpathSync as realpathSync7, rmSync as rmSync6, writeFileSync as writeFileSync3 } from "node:fs";
|
|
9806
|
-
import { delimiter as delimiter2, join as
|
|
10065
|
+
import { delimiter as delimiter2, join as join10, resolve as resolve7 } from "node:path";
|
|
9807
10066
|
import { execa as execa4 } from "execa";
|
|
9808
10067
|
|
|
9809
10068
|
// src/path-search.ts
|
|
9810
10069
|
import { accessSync, constants, statSync } from "node:fs";
|
|
9811
|
-
import { delimiter, isAbsolute, join as
|
|
10070
|
+
import { delimiter, isAbsolute, join as join7 } from "node:path";
|
|
9812
10071
|
function findOnPath(command, path3 = process.env.PATH ?? "") {
|
|
9813
10072
|
for (const directory of path3.split(delimiter)) {
|
|
9814
10073
|
if (!directory) continue;
|
|
9815
|
-
const candidate =
|
|
10074
|
+
const candidate = join7(directory, command);
|
|
9816
10075
|
try {
|
|
9817
10076
|
accessSync(candidate, constants.X_OK);
|
|
9818
10077
|
if (statSync(candidate).isFile()) return candidate;
|
|
@@ -9831,7 +10090,7 @@ import {
|
|
|
9831
10090
|
rmSync as rmSync5
|
|
9832
10091
|
} from "node:fs";
|
|
9833
10092
|
import { tmpdir } from "node:os";
|
|
9834
|
-
import { basename, dirname as
|
|
10093
|
+
import { basename, dirname as dirname7, join as join9, resolve as resolve5 } from "node:path";
|
|
9835
10094
|
|
|
9836
10095
|
// src/ids.ts
|
|
9837
10096
|
var SAFE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
@@ -9898,8 +10157,8 @@ import {
|
|
|
9898
10157
|
readFileSync as readFileSync4,
|
|
9899
10158
|
rmSync as rmSync4
|
|
9900
10159
|
} from "node:fs";
|
|
9901
|
-
import { lstat, readdir } from "node:fs/promises";
|
|
9902
|
-
import { dirname as
|
|
10160
|
+
import { lstat as lstat2, readdir as readdir2 } from "node:fs/promises";
|
|
10161
|
+
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join8, relative as relative2, resolve as resolve4 } from "node:path";
|
|
9903
10162
|
import { execa as execa2 } from "execa";
|
|
9904
10163
|
import { simpleGit } from "simple-git";
|
|
9905
10164
|
|
|
@@ -9980,12 +10239,12 @@ function runBranch(runId) {
|
|
|
9980
10239
|
return `mikka/run-${assertSafeId("run id", runId)}`;
|
|
9981
10240
|
}
|
|
9982
10241
|
function isInside(parent, child) {
|
|
9983
|
-
const rel =
|
|
10242
|
+
const rel = relative2(parent, child);
|
|
9984
10243
|
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
9985
10244
|
}
|
|
9986
10245
|
var configWriters = /* @__PURE__ */ new Map();
|
|
9987
10246
|
function withRepoConfig(repoPath, work) {
|
|
9988
|
-
const key2 =
|
|
10247
|
+
const key2 = resolve4(repoPath);
|
|
9989
10248
|
const result = (configWriters.get(key2) ?? Promise.resolve()).then(work, work);
|
|
9990
10249
|
const settled = result.then(() => void 0, () => void 0);
|
|
9991
10250
|
configWriters.set(key2, settled);
|
|
@@ -10006,9 +10265,9 @@ var WorktreeManager = class {
|
|
|
10006
10265
|
usageRefresh = null;
|
|
10007
10266
|
/** The run's worktree dir; never outside the worktree root. */
|
|
10008
10267
|
pathFor(runId) {
|
|
10009
|
-
const root =
|
|
10010
|
-
const path3 =
|
|
10011
|
-
if (
|
|
10268
|
+
const root = resolve4(this.root);
|
|
10269
|
+
const path3 = resolve4(root, assertSafeId("run id", runId));
|
|
10270
|
+
if (dirname6(path3) !== root) {
|
|
10012
10271
|
throw new Error(`worktree path escapes ${root}: ${runId}`);
|
|
10013
10272
|
}
|
|
10014
10273
|
return path3;
|
|
@@ -10020,7 +10279,7 @@ var WorktreeManager = class {
|
|
|
10020
10279
|
async create(runId, repoPath, baseBranch) {
|
|
10021
10280
|
await excludeVerifyArtifacts(repoPath);
|
|
10022
10281
|
const path3 = this.pathFor(runId);
|
|
10023
|
-
if (existsSync2(
|
|
10282
|
+
if (existsSync2(join8(path3, ".git"))) return path3;
|
|
10024
10283
|
mkdirSync5(this.root, { recursive: true });
|
|
10025
10284
|
await withRepoConfig(
|
|
10026
10285
|
repoPath,
|
|
@@ -10084,10 +10343,10 @@ var WorktreeManager = class {
|
|
|
10084
10343
|
*/
|
|
10085
10344
|
async continueFrom(repoPath, previousWorktree, runId) {
|
|
10086
10345
|
await excludeVerifyArtifacts(repoPath);
|
|
10087
|
-
const root =
|
|
10088
|
-
const path3 =
|
|
10089
|
-
if (
|
|
10090
|
-
if (!existsSync2(
|
|
10346
|
+
const root = resolve4(this.root);
|
|
10347
|
+
const path3 = resolve4(previousWorktree);
|
|
10348
|
+
if (dirname6(path3) !== root) return null;
|
|
10349
|
+
if (!existsSync2(join8(path3, ".git"))) return null;
|
|
10091
10350
|
let gitDir;
|
|
10092
10351
|
try {
|
|
10093
10352
|
gitDir = await worktreeGitDir(repoPath, path3);
|
|
@@ -10121,11 +10380,11 @@ var WorktreeManager = class {
|
|
|
10121
10380
|
const repoReal = realpathSync4(repoPath);
|
|
10122
10381
|
const worktreeReal = realpathSync4(worktree);
|
|
10123
10382
|
for (const file of recipe.copyFiles) {
|
|
10124
|
-
const rel =
|
|
10383
|
+
const rel = relative2(repoPath, resolve4(repoPath, file));
|
|
10125
10384
|
if (rel === "" || rel.startsWith("..") || isAbsolute2(rel)) {
|
|
10126
10385
|
throw new Error(`setup recipe copies a file outside the repo: ${file}`);
|
|
10127
10386
|
}
|
|
10128
|
-
const from =
|
|
10387
|
+
const from = join8(repoPath, rel);
|
|
10129
10388
|
const fromStat = lstatSync2(from, { throwIfNoEntry: false });
|
|
10130
10389
|
if (!fromStat) continue;
|
|
10131
10390
|
if (!fromStat.isFile() || !isInside(repoReal, realpathSync4(from))) {
|
|
@@ -10133,10 +10392,10 @@ var WorktreeManager = class {
|
|
|
10133
10392
|
`setup recipe copies a symlink or non-file, or leaves the repo: ${file}`
|
|
10134
10393
|
);
|
|
10135
10394
|
}
|
|
10136
|
-
const to =
|
|
10137
|
-
mkdirSync5(
|
|
10395
|
+
const to = join8(worktree, rel);
|
|
10396
|
+
mkdirSync5(dirname6(to), { recursive: true });
|
|
10138
10397
|
const toStat = lstatSync2(to, { throwIfNoEntry: false });
|
|
10139
|
-
if (!isInside(worktreeReal, realpathSync4(
|
|
10398
|
+
if (!isInside(worktreeReal, realpathSync4(dirname6(to))) || toStat && !toStat.isFile()) {
|
|
10140
10399
|
throw new Error(
|
|
10141
10400
|
`setup recipe would write through a symlink or outside the worktree: ${file}`
|
|
10142
10401
|
);
|
|
@@ -10178,11 +10437,11 @@ var WorktreeManager = class {
|
|
|
10178
10437
|
*/
|
|
10179
10438
|
async discardIfEmpty(runIds, worktree, repoPath) {
|
|
10180
10439
|
if (this.retainResources) return false;
|
|
10181
|
-
const root =
|
|
10182
|
-
const path3 = worktree ?
|
|
10183
|
-
if (path3 &&
|
|
10440
|
+
const root = resolve4(this.root);
|
|
10441
|
+
const path3 = worktree ? resolve4(worktree) : null;
|
|
10442
|
+
if (path3 && dirname6(path3) !== root) return false;
|
|
10184
10443
|
const git3 = simpleGit(repoPath);
|
|
10185
|
-
if (path3 && existsSync2(
|
|
10444
|
+
if (path3 && existsSync2(join8(path3, ".git"))) {
|
|
10186
10445
|
if ((await this.changedFiles(path3)).length > 0) return false;
|
|
10187
10446
|
}
|
|
10188
10447
|
const branches = [];
|
|
@@ -10221,15 +10480,15 @@ var WorktreeManager = class {
|
|
|
10221
10480
|
"mikka/run-*",
|
|
10222
10481
|
"--format=%(refname:short) %(worktreepath)"
|
|
10223
10482
|
]);
|
|
10224
|
-
const root =
|
|
10225
|
-
const repo =
|
|
10483
|
+
const root = resolve4(this.root);
|
|
10484
|
+
const repo = resolve4(repoPath);
|
|
10226
10485
|
const branches = [];
|
|
10227
10486
|
for (const line of out.split("\n")) {
|
|
10228
10487
|
const [name, where = ""] = line.split(" ");
|
|
10229
10488
|
const runId = name?.startsWith("mikka/run-") ? name.slice("mikka/run-".length) : "";
|
|
10230
10489
|
if (!runId) continue;
|
|
10231
|
-
const worktree = where.trim() ?
|
|
10232
|
-
if (worktree && (worktree === repo ||
|
|
10490
|
+
const worktree = where.trim() ? resolve4(where.trim()) : null;
|
|
10491
|
+
if (worktree && (worktree === repo || dirname6(worktree) !== root))
|
|
10233
10492
|
continue;
|
|
10234
10493
|
branches.push({ runId, worktree });
|
|
10235
10494
|
}
|
|
@@ -10281,9 +10540,9 @@ var WorktreeManager = class {
|
|
|
10281
10540
|
async function excludeVerifyArtifacts(repoPath) {
|
|
10282
10541
|
await withRepoConfig(repoPath, async () => {
|
|
10283
10542
|
const common2 = (await simpleGit(repoPath).raw(["rev-parse", "--path-format=absolute", "--git-common-dir"])).trim();
|
|
10284
|
-
const info =
|
|
10543
|
+
const info = join8(common2, "info");
|
|
10285
10544
|
mkdirSync5(info, { recursive: true });
|
|
10286
|
-
const file =
|
|
10545
|
+
const file = join8(info, "exclude");
|
|
10287
10546
|
if (existsSync2(file) && !lstatSync2(file).isFile()) throw new Error("Invalid repository exclude file");
|
|
10288
10547
|
const existing = existsSync2(file) ? readFileSync4(file, "utf8") : "";
|
|
10289
10548
|
if (!existing.split(/\r?\n/).includes("/.verify/")) appendFileSync(file, "\n/.verify/\n");
|
|
@@ -10292,19 +10551,19 @@ async function excludeVerifyArtifacts(repoPath) {
|
|
|
10292
10551
|
async function du(path3) {
|
|
10293
10552
|
let stat3;
|
|
10294
10553
|
try {
|
|
10295
|
-
stat3 = await
|
|
10554
|
+
stat3 = await lstat2(path3);
|
|
10296
10555
|
} catch {
|
|
10297
10556
|
return 0;
|
|
10298
10557
|
}
|
|
10299
10558
|
if (!stat3.isDirectory()) return stat3.size;
|
|
10300
10559
|
let entries;
|
|
10301
10560
|
try {
|
|
10302
|
-
entries = await
|
|
10561
|
+
entries = await readdir2(path3);
|
|
10303
10562
|
} catch {
|
|
10304
10563
|
return 0;
|
|
10305
10564
|
}
|
|
10306
10565
|
let total = 0;
|
|
10307
|
-
for (const entry of entries) total += await du(
|
|
10566
|
+
for (const entry of entries) total += await du(join8(path3, entry));
|
|
10308
10567
|
return total;
|
|
10309
10568
|
}
|
|
10310
10569
|
|
|
@@ -10344,10 +10603,10 @@ async function worktreeGitDir(repoPath, worktree, signal) {
|
|
|
10344
10603
|
}
|
|
10345
10604
|
)).stdout.trim()
|
|
10346
10605
|
);
|
|
10347
|
-
const dotGit =
|
|
10348
|
-
const root =
|
|
10606
|
+
const dotGit = join9(realpathSync5(worktree), ".git");
|
|
10607
|
+
const root = join9(common2, "worktrees");
|
|
10349
10608
|
for (const name of readdirSync3(root)) {
|
|
10350
|
-
const gitdirFile =
|
|
10609
|
+
const gitdirFile = join9(root, name, "gitdir");
|
|
10351
10610
|
let target;
|
|
10352
10611
|
try {
|
|
10353
10612
|
target = readFileSync5(gitdirFile, "utf8").trim();
|
|
@@ -10355,16 +10614,16 @@ async function worktreeGitDir(repoPath, worktree, signal) {
|
|
|
10355
10614
|
continue;
|
|
10356
10615
|
}
|
|
10357
10616
|
if (target === dotGit || safeRealpath(target) === dotGit) {
|
|
10358
|
-
return
|
|
10617
|
+
return join9(root, name);
|
|
10359
10618
|
}
|
|
10360
10619
|
}
|
|
10361
10620
|
throw new Error(`${worktree} is not a worktree of ${repoPath}`);
|
|
10362
10621
|
}
|
|
10363
10622
|
async function worktreeGitWritePaths(repoPath, worktree, runId) {
|
|
10364
10623
|
assertSafeId("run id", runId);
|
|
10365
|
-
const common2 =
|
|
10624
|
+
const common2 = resolve5(await worktreeGitDir(repoPath, worktree), "..", "..");
|
|
10366
10625
|
if (basename(common2) !== ".git") throw new Error(`${repoPath} is not a standard clone`);
|
|
10367
|
-
return [
|
|
10626
|
+
return [dirname7(common2)];
|
|
10368
10627
|
}
|
|
10369
10628
|
function safeRealpath(path3) {
|
|
10370
10629
|
try {
|
|
@@ -10381,7 +10640,7 @@ async function pinnedGit(repoPath, worktree, env = process.env, signal) {
|
|
|
10381
10640
|
signal?.throwIfAborted();
|
|
10382
10641
|
return execa3("git", [...SAFE_GIT, ...args], {
|
|
10383
10642
|
cwd: workTree,
|
|
10384
|
-
env: { ...env, ...extra, GIT_DIR: gitDir, GIT_COMMON_DIR:
|
|
10643
|
+
env: { ...env, ...extra, GIT_DIR: gitDir, GIT_COMMON_DIR: resolve5(gitDir, "..", ".."), GIT_WORK_TREE: workTree },
|
|
10385
10644
|
extendEnv: false,
|
|
10386
10645
|
stdin: "ignore",
|
|
10387
10646
|
cancelSignal: signal,
|
|
@@ -10392,8 +10651,8 @@ async function pinnedGit(repoPath, worktree, env = process.env, signal) {
|
|
|
10392
10651
|
}
|
|
10393
10652
|
async function snapshotTree(repoPath, worktree, env, signal) {
|
|
10394
10653
|
const git3 = await pinnedGit(repoPath, worktree, env, signal);
|
|
10395
|
-
const dir = mkdtempSync(
|
|
10396
|
-
const index = { GIT_INDEX_FILE:
|
|
10654
|
+
const dir = mkdtempSync(join9(tmpdir(), "mikka-index-"));
|
|
10655
|
+
const index = { GIT_INDEX_FILE: join9(dir, "index") };
|
|
10397
10656
|
try {
|
|
10398
10657
|
await git3(["read-tree", "HEAD"], index);
|
|
10399
10658
|
await git3(["add", "--all"], index);
|
|
@@ -10556,14 +10815,14 @@ function gitError(error) {
|
|
|
10556
10815
|
// src/agents/local-git-origin.ts
|
|
10557
10816
|
import { lstatSync as lstatSync3, realpathSync as realpathSync6 } from "node:fs";
|
|
10558
10817
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
10559
|
-
import { basename as basename2, dirname as
|
|
10818
|
+
import { basename as basename2, dirname as dirname8, resolve as resolve6, sep as sep2 } from "node:path";
|
|
10560
10819
|
import { pathToFileURL } from "node:url";
|
|
10561
10820
|
var repository = "https://github.com/mikka-e2e/core-loop.git";
|
|
10562
10821
|
function localGitOrigin(env = process.env) {
|
|
10563
10822
|
if (!localTestAccountsMode(env) || !env.MIKKA_DEV_GIT_ORIGIN) return void 0;
|
|
10564
|
-
const path3 =
|
|
10823
|
+
const path3 = resolve6(env.MIKKA_DEV_GIT_ORIGIN);
|
|
10565
10824
|
const temporary = realpathSync6(tmpdir2());
|
|
10566
|
-
if (basename2(path3) !== "origin.git" || !/^mvp-[a-f0-9-]{36}$/.test(basename2(
|
|
10825
|
+
if (basename2(path3) !== "origin.git" || !/^mvp-[a-f0-9-]{36}$/.test(basename2(dirname8(path3))) || !basename2(dirname8(dirname8(path3))).startsWith("mikka-mvp-origin-") || dirname8(dirname8(dirname8(path3))) !== temporary || !path3.startsWith(`${temporary}${sep2}`) || !lstatSync3(path3).isDirectory() || realpathSync6(path3) !== path3) {
|
|
10567
10826
|
throw new Error("Invalid local acceptance Git origin");
|
|
10568
10827
|
}
|
|
10569
10828
|
return path3;
|
|
@@ -10574,7 +10833,7 @@ function localGitConfig(env = process.env) {
|
|
|
10574
10833
|
}
|
|
10575
10834
|
|
|
10576
10835
|
// src/agents/github-runtime.ts
|
|
10577
|
-
var GITHUB_CREDENTIAL_SCRIPT =
|
|
10836
|
+
var GITHUB_CREDENTIAL_SCRIPT = resolve7(import.meta.dirname, "github-credentials.mjs");
|
|
10578
10837
|
var helper = GITHUB_CREDENTIAL_SCRIPT;
|
|
10579
10838
|
var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
10580
10839
|
function preparedTokenEnvironment(token) {
|
|
@@ -10619,19 +10878,19 @@ function githubReceiptEnvironment(host = process.env) {
|
|
|
10619
10878
|
function prepareGitHubEnvironment(runDir, github, path3, runtime) {
|
|
10620
10879
|
const endpoint = new URL(github.endpoint);
|
|
10621
10880
|
if (!endpoint.pathname.endsWith("/api/runs/github-token") || !trustedServerEndpoint(endpoint)) throw new Error("Invalid run GitHub endpoint");
|
|
10622
|
-
const gh = runtime?.ghBinary ?? path3.split(delimiter2).map((dir2) =>
|
|
10881
|
+
const gh = runtime?.ghBinary ?? path3.split(delimiter2).map((dir2) => join10(dir2, "gh")).find((file) => existsSync3(file));
|
|
10623
10882
|
const node = runtime?.nodeBinary ?? process.execPath;
|
|
10624
10883
|
if (!gh) throw new Error("Install GitHub CLI (gh) before running GitHub tasks");
|
|
10625
|
-
const dir =
|
|
10884
|
+
const dir = join10(runDir, "github");
|
|
10626
10885
|
mkdirSync6(dir, { recursive: true, mode: 448 });
|
|
10627
|
-
if (!lstatSync4(dir).isDirectory() || realpathSync7(dir) !==
|
|
10628
|
-
const config =
|
|
10886
|
+
if (!lstatSync4(dir).isDirectory() || realpathSync7(dir) !== join10(realpathSync7(runDir), "github")) throw new Error("Invalid run GitHub directory");
|
|
10887
|
+
const config = join10(dir, "config.json");
|
|
10629
10888
|
rmSync6(config, { force: true });
|
|
10630
10889
|
writeFileSync3(config, JSON.stringify({ ...github, gh }), { mode: 384, flag: "wx" });
|
|
10631
|
-
const bin =
|
|
10890
|
+
const bin = join10(dir, "bin");
|
|
10632
10891
|
mkdirSync6(bin, { recursive: true, mode: 448 });
|
|
10633
|
-
if (!lstatSync4(bin).isDirectory() || realpathSync7(bin) !==
|
|
10634
|
-
const wrapper =
|
|
10892
|
+
if (!lstatSync4(bin).isDirectory() || realpathSync7(bin) !== join10(realpathSync7(dir), "bin")) throw new Error("Invalid run GitHub executable directory");
|
|
10893
|
+
const wrapper = join10(bin, "gh");
|
|
10635
10894
|
rmSync6(wrapper, { force: true });
|
|
10636
10895
|
const fixtureConfig = localGitConfig();
|
|
10637
10896
|
const fixtureProxy = fixtureConfig.length ? 'case "${HTTP_PROXY:-${http_proxy:-}}" in http://*@localhost:*|http://*@127.0.0.1:*) unset NO_PROXY no_proxy ;; esac\n' : "";
|
|
@@ -10680,7 +10939,7 @@ async function withRunGitCredentials(assignment, privateDir, work, preparedEnvir
|
|
|
10680
10939
|
} });
|
|
10681
10940
|
}
|
|
10682
10941
|
mkdirSync6(privateDir, { recursive: true, mode: 448 });
|
|
10683
|
-
const dir = mkdtempSync2(
|
|
10942
|
+
const dir = mkdtempSync2(join10(privateDir, "github-fetch-"));
|
|
10684
10943
|
try {
|
|
10685
10944
|
let env = {};
|
|
10686
10945
|
try {
|
|
@@ -10704,7 +10963,7 @@ async function agentPublishedReceipt(input) {
|
|
|
10704
10963
|
if (!input.github.branch) throw new Error("No task branch to read back");
|
|
10705
10964
|
const branch = input.github.branch;
|
|
10706
10965
|
mkdirSync6(input.privateDir, { recursive: true, mode: 448 });
|
|
10707
|
-
const receiptDir = mkdtempSync2(
|
|
10966
|
+
const receiptDir = mkdtempSync2(join10(input.privateDir, "github-receipt-"));
|
|
10708
10967
|
const nativeGitHub = input.hosted || Boolean(input.githubEnvironment);
|
|
10709
10968
|
try {
|
|
10710
10969
|
const env = {
|
|
@@ -10734,7 +10993,7 @@ async function agentPublishedReceipt(input) {
|
|
|
10734
10993
|
try {
|
|
10735
10994
|
const gh = (args) => {
|
|
10736
10995
|
input.signal?.throwIfAborted();
|
|
10737
|
-
return execa4(nativeGitHub ? "gh" :
|
|
10996
|
+
return execa4(nativeGitHub ? "gh" : join10(receiptDir, "github", "bin", "gh"), args, { cwd: input.worktree, env, extendEnv: false, stdin: "ignore", cancelSignal: input.signal, killDescendants: true });
|
|
10738
10997
|
};
|
|
10739
10998
|
const [owner, repository2] = input.github.repository.split("/");
|
|
10740
10999
|
const query2 = "query($owner:String!,$repository:String!,$commit:GitObjectID!){repository(owner:$owner,name:$repository){object(oid:$commit){... on Commit {oid statusCheckRollup{state}}}}}";
|
|
@@ -10758,7 +11017,7 @@ async function agentPublishedReceipt(input) {
|
|
|
10758
11017
|
}
|
|
10759
11018
|
|
|
10760
11019
|
// src/agents/run-apps.ts
|
|
10761
|
-
import { resolve as
|
|
11020
|
+
import { resolve as resolve8 } from "node:path";
|
|
10762
11021
|
function runMcp(mcp, traceContext) {
|
|
10763
11022
|
if (!mcp) return void 0;
|
|
10764
11023
|
let url;
|
|
@@ -10810,12 +11069,12 @@ function codexMcpServer(server) {
|
|
|
10810
11069
|
return { name: server.name, transport: "stdio", command: "npx", args: ["--yes", "mcp-remote@0.16.5", server.url, "--transport", "sse-only", ...headers], env };
|
|
10811
11070
|
}
|
|
10812
11071
|
function nativeMcpProcess(server) {
|
|
10813
|
-
return server.cwd ? { command: process.execPath, args: [
|
|
11072
|
+
return server.cwd ? { command: process.execPath, args: [resolve8(import.meta.dirname, "mcp-stdio-launcher.mjs"), server.cwd, server.command, ...server.args], env: server.env } : { command: server.command, args: server.args, env: server.env };
|
|
10814
11073
|
}
|
|
10815
11074
|
|
|
10816
11075
|
// src/agents/run-context.ts
|
|
10817
11076
|
import { execFileSync } from "node:child_process";
|
|
10818
|
-
import { createHash as
|
|
11077
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
10819
11078
|
import {
|
|
10820
11079
|
lstatSync as lstatSync8,
|
|
10821
11080
|
mkdirSync as mkdirSync8,
|
|
@@ -10825,15 +11084,15 @@ import {
|
|
|
10825
11084
|
rmSync as rmSync8,
|
|
10826
11085
|
writeFileSync as writeFileSync4
|
|
10827
11086
|
} from "node:fs";
|
|
10828
|
-
import { homedir as
|
|
10829
|
-
import { dirname as
|
|
11087
|
+
import { homedir as homedir5 } from "node:os";
|
|
11088
|
+
import { dirname as dirname11, join as join14, resolve as resolve11 } from "node:path";
|
|
10830
11089
|
|
|
10831
11090
|
// src/agents/skill-artifact.ts
|
|
10832
|
-
import { createHash as
|
|
11091
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
10833
11092
|
import { lstatSync as lstatSync5, readFileSync as readFileSync6 } from "node:fs";
|
|
10834
11093
|
function verifyAssignedSkills(skills, receipt) {
|
|
10835
11094
|
if (!receipt) return;
|
|
10836
|
-
if (skills?.length !== 1 || skills[0].id !== receipt.artifact.skillId || skills[0].files.length !== 0 ||
|
|
11095
|
+
if (skills?.length !== 1 || skills[0].id !== receipt.artifact.skillId || skills[0].files.length !== 0 || createHash5("sha256").update(skillMarkdown(skills[0]), "utf8").digest("hex") !== receipt.artifact.sha256)
|
|
10837
11096
|
throw new Error("Assigned Skill artifact digest mismatch");
|
|
10838
11097
|
}
|
|
10839
11098
|
function verifySkillAssignment(assignment) {
|
|
@@ -10844,7 +11103,7 @@ function verifySkillAssignment(assignment) {
|
|
|
10844
11103
|
verifyAssignedSkills(assignment.skills, receipt);
|
|
10845
11104
|
}
|
|
10846
11105
|
function verifyMountedSkill(file, receipt) {
|
|
10847
|
-
if (!lstatSync5(file).isFile() || lstatSync5(file).isSymbolicLink() || lstatSync5(file).nlink !== 1 ||
|
|
11106
|
+
if (!lstatSync5(file).isFile() || lstatSync5(file).isSymbolicLink() || lstatSync5(file).nlink !== 1 || createHash5("sha256").update(readFileSync6(file)).digest("hex") !== receipt.artifact.sha256)
|
|
10848
11107
|
throw new Error("Mounted Skill artifact digest mismatch");
|
|
10849
11108
|
}
|
|
10850
11109
|
function verifySkillResume(assignment, current) {
|
|
@@ -10857,11 +11116,11 @@ function verifySkillResume(assignment, current) {
|
|
|
10857
11116
|
import { lstatSync as lstatSync6, readlinkSync, realpathSync as realpathSync8 } from "node:fs";
|
|
10858
11117
|
import {
|
|
10859
11118
|
basename as basename3,
|
|
10860
|
-
dirname as
|
|
11119
|
+
dirname as dirname9,
|
|
10861
11120
|
isAbsolute as isAbsolute3,
|
|
10862
|
-
join as
|
|
10863
|
-
relative as
|
|
10864
|
-
resolve as
|
|
11121
|
+
join as join11,
|
|
11122
|
+
relative as relative3,
|
|
11123
|
+
resolve as resolve9
|
|
10865
11124
|
} from "node:path";
|
|
10866
11125
|
function decide(action, context = {}) {
|
|
10867
11126
|
if (!Object.hasOwn(PERMISSION_DEFAULTS, action))
|
|
@@ -10950,14 +11209,14 @@ function realTarget(path3) {
|
|
|
10950
11209
|
let current = path3;
|
|
10951
11210
|
for (let hops = 0; ; ) {
|
|
10952
11211
|
try {
|
|
10953
|
-
return
|
|
11212
|
+
return join11(realpathSync8(current), ...[...missing2].reverse());
|
|
10954
11213
|
} catch {
|
|
10955
11214
|
if (lstatSync6(current, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
10956
11215
|
if (++hops > 40) return path3;
|
|
10957
|
-
current =
|
|
11216
|
+
current = resolve9(dirname9(current), readlinkSync(current));
|
|
10958
11217
|
continue;
|
|
10959
11218
|
}
|
|
10960
|
-
const parent =
|
|
11219
|
+
const parent = dirname9(current);
|
|
10961
11220
|
if (parent === current) return path3;
|
|
10962
11221
|
missing2.push(basename3(current));
|
|
10963
11222
|
current = parent;
|
|
@@ -10965,28 +11224,28 @@ function realTarget(path3) {
|
|
|
10965
11224
|
}
|
|
10966
11225
|
}
|
|
10967
11226
|
function inside(parent, child) {
|
|
10968
|
-
const rel =
|
|
11227
|
+
const rel = relative3(parent, child);
|
|
10969
11228
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
10970
11229
|
}
|
|
10971
11230
|
function classifyWrite(worktree, target) {
|
|
10972
|
-
const root =
|
|
10973
|
-
const lexical =
|
|
11231
|
+
const root = resolve9(worktree);
|
|
11232
|
+
const lexical = resolve9(root, target);
|
|
10974
11233
|
const ok2 = inside(root, lexical) && inside(realTarget(root), realTarget(lexical));
|
|
10975
11234
|
return ok2 ? "write_in_worktree" : "write_outside_repo";
|
|
10976
11235
|
}
|
|
10977
11236
|
|
|
10978
11237
|
// src/captures.ts
|
|
10979
|
-
import { createHash as
|
|
11238
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
10980
11239
|
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";
|
|
10981
|
-
import { join as
|
|
11240
|
+
import { join as join13 } from "node:path";
|
|
10982
11241
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
10983
11242
|
|
|
10984
11243
|
// src/agents/capture-video.mjs
|
|
10985
11244
|
import { execFile as execFile3 } from "node:child_process";
|
|
10986
|
-
import { createHash as
|
|
11245
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
10987
11246
|
import { constants as constants2, createWriteStream } from "node:fs";
|
|
10988
|
-
import { chmod, lstat as
|
|
10989
|
-
import { dirname as
|
|
11247
|
+
import { chmod, lstat as lstat3, mkdir as mkdir3, mkdtemp, open, readFile as readFile3, rename, rm as rm3, stat } from "node:fs/promises";
|
|
11248
|
+
import { dirname as dirname10, basename as basename4, join as join12, resolve as resolve10 } from "node:path";
|
|
10990
11249
|
import { devNull } from "node:os";
|
|
10991
11250
|
import { pipeline } from "node:stream/promises";
|
|
10992
11251
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
@@ -11047,16 +11306,16 @@ var CaptureVideoError = class extends Error {
|
|
|
11047
11306
|
}
|
|
11048
11307
|
};
|
|
11049
11308
|
async function captureVideoBinaries({ directory = CAPTURE_TOOLS_DIRECTORY, ownerId = 0 } = {}) {
|
|
11050
|
-
const info = await
|
|
11309
|
+
const info = await lstat3(directory).catch((error) => {
|
|
11051
11310
|
if (error.code === "ENOENT") return null;
|
|
11052
11311
|
throw error;
|
|
11053
11312
|
});
|
|
11054
11313
|
if (!info) return { ffmpeg: "ffmpeg", ffprobe: "ffprobe" };
|
|
11055
11314
|
try {
|
|
11056
11315
|
if (!info.isDirectory() || info.uid !== ownerId || info.mode & 18) throw new Error("Private capture tools directory is unsafe");
|
|
11057
|
-
const binaries = { ffmpeg:
|
|
11316
|
+
const binaries = { ffmpeg: join12(directory, "ffmpeg"), ffprobe: join12(directory, "ffprobe") };
|
|
11058
11317
|
for (const path3 of Object.values(binaries)) {
|
|
11059
|
-
const binary = await
|
|
11318
|
+
const binary = await lstat3(path3);
|
|
11060
11319
|
if (!binary.isFile() || binary.uid !== ownerId || binary.mode & 18 || !(binary.mode & 73)) throw new Error("Private capture tool is unsafe");
|
|
11061
11320
|
}
|
|
11062
11321
|
return binaries;
|
|
@@ -11122,7 +11381,7 @@ async function snapshot2(source, destination, signal) {
|
|
|
11122
11381
|
const mp4 = bytesRead >= 12 && header.subarray(4, 8).toString() === "ftyp";
|
|
11123
11382
|
const webm = bytesRead >= 4 && header.subarray(0, 4).equals(Buffer.from([26, 69, 223, 163])) && header.toString("latin1").includes("webm");
|
|
11124
11383
|
if (!mp4 && !webm) throw new CaptureVideoError("captureVideoInputInvalid");
|
|
11125
|
-
const hash2 =
|
|
11384
|
+
const hash2 = createHash6("sha256"), stream = handle.createReadStream({ autoClose: false, start: 0, end: info.size - 1 });
|
|
11126
11385
|
stream.on("data", (bytes) => hash2.update(bytes));
|
|
11127
11386
|
await pipeline(stream, createWriteStream(destination, { flags: "wx", mode: 384 }), { signal });
|
|
11128
11387
|
if ((await stat(destination)).size !== info.size) throw new CaptureVideoError("captureVideoInputChanged");
|
|
@@ -11139,13 +11398,13 @@ function videoFilter(windows, width, fps) {
|
|
|
11139
11398
|
}
|
|
11140
11399
|
async function processCaptureVideo(input, output, options = {}) {
|
|
11141
11400
|
const maximum = options.maxBytes ?? CAPTURE_VIDEO_MAX_BYTES;
|
|
11142
|
-
if (!Number.isSafeInteger(maximum) || maximum < 1 || maximum > CAPTURE_VIDEO_MAX_BYTES ||
|
|
11401
|
+
if (!Number.isSafeInteger(maximum) || maximum < 1 || maximum > CAPTURE_VIDEO_MAX_BYTES || resolve10(input) === resolve10(output))
|
|
11143
11402
|
throw new CaptureVideoError("captureVideoOptionsInvalid");
|
|
11144
11403
|
const steps = normalizeRecordingSteps(options.steps);
|
|
11145
11404
|
const deadline = Date.now() + Math.min(options.timeoutMs ?? 9e4, 18e4);
|
|
11146
11405
|
const binaries = await captureVideoBinaries();
|
|
11147
|
-
await
|
|
11148
|
-
const temporary = await mkdtemp(
|
|
11406
|
+
await mkdir3(dirname10(output), { recursive: true, mode: 448 });
|
|
11407
|
+
const temporary = await mkdtemp(join12(dirname10(output), ".capture-process-"));
|
|
11149
11408
|
await chmod(temporary, 448);
|
|
11150
11409
|
const run3 = async (binary, args) => {
|
|
11151
11410
|
options.signal?.throwIfAborted();
|
|
@@ -11185,12 +11444,12 @@ async function processCaptureVideo(input, output, options = {}) {
|
|
|
11185
11444
|
return { durationMs: Math.round(seconds * 1e3), width: stream.width, height: stream.height };
|
|
11186
11445
|
};
|
|
11187
11446
|
try {
|
|
11188
|
-
const source =
|
|
11447
|
+
const source = join12(temporary, "source.video");
|
|
11189
11448
|
const originalFile = await snapshot2(input, source, options.signal);
|
|
11190
11449
|
const original = await probe(source);
|
|
11191
11450
|
const windows = recordingWindows(original.durationMs, steps);
|
|
11192
11451
|
const retainedMs = windows.reduce((total, window) => total + window.endMs - window.startMs, 0);
|
|
11193
|
-
const result =
|
|
11452
|
+
const result = join12(temporary, "final.mp4");
|
|
11194
11453
|
const base = [
|
|
11195
11454
|
"-y",
|
|
11196
11455
|
"-nostdin",
|
|
@@ -11230,7 +11489,7 @@ async function processCaptureVideo(input, output, options = {}) {
|
|
|
11230
11489
|
"2",
|
|
11231
11490
|
"-pix_fmt",
|
|
11232
11491
|
"yuv420p",
|
|
11233
|
-
...rate ? ["-b:v", `${rate}k`, "-pass", String(pass), "-passlogfile",
|
|
11492
|
+
...rate ? ["-b:v", `${rate}k`, "-pass", String(pass), "-passlogfile", join12(temporary, "pass")] : ["-crf", "28"],
|
|
11234
11493
|
...pass === 1 ? ["-f", "null", devNull] : ["-movflags", "+faststart", result]
|
|
11235
11494
|
]);
|
|
11236
11495
|
};
|
|
@@ -11251,7 +11510,7 @@ async function processCaptureVideo(input, output, options = {}) {
|
|
|
11251
11510
|
if (Math.abs(measured.durationMs - retainedMs) > Math.max(250, windows.length * 100))
|
|
11252
11511
|
throw new CaptureVideoError("captureVideoDurationMismatch");
|
|
11253
11512
|
await chmod(result, 384);
|
|
11254
|
-
if (await
|
|
11513
|
+
if (await lstat3(output).catch(() => null)) throw new CaptureVideoError("captureVideoOutputExists");
|
|
11255
11514
|
options.signal?.throwIfAborted();
|
|
11256
11515
|
await rename(result, output);
|
|
11257
11516
|
return {
|
|
@@ -11271,14 +11530,14 @@ async function processCaptureVideo(input, output, options = {}) {
|
|
|
11271
11530
|
}
|
|
11272
11531
|
};
|
|
11273
11532
|
} finally {
|
|
11274
|
-
await
|
|
11533
|
+
await rm3(temporary, { recursive: true, force: true });
|
|
11275
11534
|
}
|
|
11276
11535
|
}
|
|
11277
|
-
if (process.argv[1] && basename4(process.argv[1]) === "capture-video.mjs" && pathToFileURL2(
|
|
11536
|
+
if (process.argv[1] && basename4(process.argv[1]) === "capture-video.mjs" && pathToFileURL2(resolve10(process.argv[1])).href === import.meta.url) {
|
|
11278
11537
|
try {
|
|
11279
11538
|
const [, , input, output, metadata2] = process.argv;
|
|
11280
11539
|
if (!input || !output || !metadata2 || process.argv.length !== 5) throw new CaptureVideoError("captureVideoOptionsInvalid");
|
|
11281
|
-
const options = JSON.parse(await
|
|
11540
|
+
const options = JSON.parse(await readFile3(metadata2, "utf8"));
|
|
11282
11541
|
const result = await processCaptureVideo(input, output, options);
|
|
11283
11542
|
process.stdout.write(JSON.stringify(result) + "\n");
|
|
11284
11543
|
} catch (error) {
|
|
@@ -11307,7 +11566,7 @@ function readPlain(path3, max) {
|
|
|
11307
11566
|
}
|
|
11308
11567
|
}
|
|
11309
11568
|
var drop = (dir, id5) => {
|
|
11310
|
-
for (const name of [`${id5}.json`, ...EXTENSIONS.map((ext) => `${id5}.${ext}`)]) rmSync7(
|
|
11569
|
+
for (const name of [`${id5}.json`, ...EXTENSIONS.map((ext) => `${id5}.${ext}`)]) rmSync7(join13(dir, name), { force: true });
|
|
11311
11570
|
};
|
|
11312
11571
|
async function hashPlain(path3, signal) {
|
|
11313
11572
|
signal?.throwIfAborted();
|
|
@@ -11315,7 +11574,7 @@ async function hashPlain(path3, signal) {
|
|
|
11315
11574
|
try {
|
|
11316
11575
|
const info = fstatSync(fd);
|
|
11317
11576
|
if (!info.isFile() || info.size < 1 || info.size > CAPTURE_RAW_MAX_BYTES) throw new Error("Invalid capture video input");
|
|
11318
|
-
const hash2 =
|
|
11577
|
+
const hash2 = createHash7("sha256");
|
|
11319
11578
|
for await (const chunk of createReadStream(path3, { fd, autoClose: false, start: 0, end: info.size - 1, signal })) hash2.update(chunk);
|
|
11320
11579
|
signal?.throwIfAborted();
|
|
11321
11580
|
return hash2.digest("hex");
|
|
@@ -11325,12 +11584,12 @@ async function hashPlain(path3, signal) {
|
|
|
11325
11584
|
}
|
|
11326
11585
|
async function prepareVideo(file, id5, steps, pendingDir, signal) {
|
|
11327
11586
|
signal?.throwIfAborted();
|
|
11328
|
-
const directory = pendingDir ?? mkdtempSync3(
|
|
11587
|
+
const directory = pendingDir ?? mkdtempSync3(join13(tmpdir3(), "mikka-capture-pending-"));
|
|
11329
11588
|
mkdirSync7(directory, { recursive: true, mode: 448 });
|
|
11330
|
-
const output =
|
|
11589
|
+
const output = join13(directory, `${id5}.processed.mp4`), receipt = join13(directory, `${id5}.video.json`);
|
|
11331
11590
|
try {
|
|
11332
11591
|
const originalHash = await hashPlain(file, signal);
|
|
11333
|
-
const stepHash =
|
|
11592
|
+
const stepHash = createHash7("sha256").update(JSON.stringify(steps)).digest("hex");
|
|
11334
11593
|
let result;
|
|
11335
11594
|
const previous = readPlain(receipt, 128e3);
|
|
11336
11595
|
if (previous) {
|
|
@@ -11358,7 +11617,7 @@ async function prepareVideo(file, id5, steps, pendingDir, signal) {
|
|
|
11358
11617
|
}
|
|
11359
11618
|
function dropPrepared(pendingDir, id5) {
|
|
11360
11619
|
if (!pendingDir) return;
|
|
11361
|
-
for (const name of [`${id5}.json`, `${id5}.processed.mp4`, `${id5}.video.json`]) rmSync7(
|
|
11620
|
+
for (const name of [`${id5}.json`, `${id5}.processed.mp4`, `${id5}.video.json`]) rmSync7(join13(pendingDir, name), { force: true });
|
|
11362
11621
|
}
|
|
11363
11622
|
function fileType(path3) {
|
|
11364
11623
|
let fd;
|
|
@@ -11385,7 +11644,7 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11385
11644
|
signal?.throwIfAborted();
|
|
11386
11645
|
const id5 = name.endsWith(".json") ? name.slice(0, -5) : "";
|
|
11387
11646
|
if (!ID.test(id5)) continue;
|
|
11388
|
-
const meta = readPlain(
|
|
11647
|
+
const meta = readPlain(join13(dir, name), 128e3);
|
|
11389
11648
|
let title2 = "";
|
|
11390
11649
|
let steps = [];
|
|
11391
11650
|
try {
|
|
@@ -11395,7 +11654,7 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11395
11654
|
} catch {
|
|
11396
11655
|
title2 = "";
|
|
11397
11656
|
}
|
|
11398
|
-
const file = EXTENSIONS.map((ext) =>
|
|
11657
|
+
const file = EXTENSIONS.map((ext) => join13(dir, `${id5}.${ext}`)).find((path3) => lstatSync7(path3, { throwIfNoEntry: false }));
|
|
11399
11658
|
const originalType = file ? fileType(file) : null;
|
|
11400
11659
|
let video;
|
|
11401
11660
|
if (file && title2 && originalType?.startsWith("video/")) {
|
|
@@ -11417,8 +11676,8 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11417
11676
|
continue;
|
|
11418
11677
|
}
|
|
11419
11678
|
try {
|
|
11420
|
-
const sha2562 =
|
|
11421
|
-
const pendingPath = pendingDir ?
|
|
11679
|
+
const sha2562 = createHash7("sha256").update(bytes).digest("hex");
|
|
11680
|
+
const pendingPath = pendingDir ? join13(pendingDir, `${id5}.json`) : null;
|
|
11422
11681
|
let pending;
|
|
11423
11682
|
if (pendingPath) {
|
|
11424
11683
|
try {
|
|
@@ -11476,7 +11735,7 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11476
11735
|
log.warn({ run_id: runId, capture: id5, status: error.code }, "capture reservation unavailable; retry stopped");
|
|
11477
11736
|
if (pendingDir) {
|
|
11478
11737
|
mkdirSync7(pendingDir, { recursive: true, mode: 448 });
|
|
11479
|
-
writeJsonAtomic(
|
|
11738
|
+
writeJsonAtomic(join13(pendingDir, "blocked.json"), { status: error.code });
|
|
11480
11739
|
}
|
|
11481
11740
|
return sent;
|
|
11482
11741
|
}
|
|
@@ -11502,8 +11761,8 @@ var CaptureUploader = class {
|
|
|
11502
11761
|
/** A final signal bounds both this pass and any earlier pass still in flight. */
|
|
11503
11762
|
flush(runId, existingOnly = false, signal) {
|
|
11504
11763
|
if (!/^[A-Za-z0-9_-]{1,64}$/.test(runId)) return Promise.resolve();
|
|
11505
|
-
const pendingDir = this.pendingRoot ?
|
|
11506
|
-
if (pendingDir && lstatSync7(
|
|
11764
|
+
const pendingDir = this.pendingRoot ? join13(this.pendingRoot, runId) : void 0;
|
|
11765
|
+
if (pendingDir && lstatSync7(join13(pendingDir, "blocked.json"), { throwIfNoEntry: false }))
|
|
11507
11766
|
return signal ? Promise.reject(new Error("Capture upload incomplete")) : Promise.resolve();
|
|
11508
11767
|
const pass = this.passes.get(runId) ?? { tail: Promise.resolve(), abort: new AbortController() };
|
|
11509
11768
|
const abort = () => pass.abort.abort(signal?.reason);
|
|
@@ -11548,7 +11807,7 @@ var HARNESS_DOMAINS = {
|
|
|
11548
11807
|
"*.cursorapi.com"
|
|
11549
11808
|
]
|
|
11550
11809
|
};
|
|
11551
|
-
var MCP_SERVER_SCRIPT =
|
|
11810
|
+
var MCP_SERVER_SCRIPT = resolve11(import.meta.dirname, "mikka-mcp.mjs");
|
|
11552
11811
|
var MCP_SERVER_NAME = "mikka";
|
|
11553
11812
|
var COMPUTER_MCP_SERVER_NAME = "mikka_computer";
|
|
11554
11813
|
var RUN_GIT_CONFIG = [["maintenance.auto", "false"], ["gc.auto", "0"]];
|
|
@@ -11561,7 +11820,7 @@ function withGitConfig(env, entries) {
|
|
|
11561
11820
|
});
|
|
11562
11821
|
return out;
|
|
11563
11822
|
}
|
|
11564
|
-
function credentialDenyRead(harness, home =
|
|
11823
|
+
function credentialDenyRead(harness, home = homedir5()) {
|
|
11565
11824
|
return [
|
|
11566
11825
|
".ssh",
|
|
11567
11826
|
".aws",
|
|
@@ -11579,7 +11838,7 @@ function credentialDenyRead(harness, home = homedir4()) {
|
|
|
11579
11838
|
// Other harnesses' logins; each harness still reads its own.
|
|
11580
11839
|
...harness === "codex" ? [] : [".codex/auth.json"],
|
|
11581
11840
|
...harness === "claude_code" ? [] : [".claude/.credentials.json"]
|
|
11582
|
-
].map((path3) =>
|
|
11841
|
+
].map((path3) => join14(home, path3));
|
|
11583
11842
|
}
|
|
11584
11843
|
function daemonSecrets(dataDir) {
|
|
11585
11844
|
const paths = daemonPaths(realpathSync9(dataDir));
|
|
@@ -11590,18 +11849,18 @@ function daemonSecrets(dataDir) {
|
|
|
11590
11849
|
paths.outbox,
|
|
11591
11850
|
paths.logs,
|
|
11592
11851
|
paths.devRepos,
|
|
11593
|
-
|
|
11852
|
+
join14(paths.adapterState, "pids")
|
|
11594
11853
|
];
|
|
11595
11854
|
}
|
|
11596
11855
|
function runPaths(stateDir, runId) {
|
|
11597
11856
|
const id5 = assertSafeId("run id", runId);
|
|
11598
11857
|
return {
|
|
11599
11858
|
/** The daemon's data dir (`stateDir` is `<dataDir>/adapters`). */
|
|
11600
|
-
privateDir:
|
|
11859
|
+
privateDir: resolve11(stateDir, ".."),
|
|
11601
11860
|
/** Writable from the sandbox. */
|
|
11602
|
-
runDir:
|
|
11861
|
+
runDir: join14(stateDir, "runs", id5),
|
|
11603
11862
|
/** Daemon only. */
|
|
11604
|
-
pidFile:
|
|
11863
|
+
pidFile: join14(stateDir, "pids", `${id5}.pgid`)
|
|
11605
11864
|
};
|
|
11606
11865
|
}
|
|
11607
11866
|
function repositorySkill(worktree, slug) {
|
|
@@ -11609,7 +11868,7 @@ function repositorySkill(worktree, slug) {
|
|
|
11609
11868
|
const missing2 = (reason) => ({ id: id5, name: slug, description: "", source: "repository", digest: null, instructions: null, available: false, reason });
|
|
11610
11869
|
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(slug)) return missing2("invalid");
|
|
11611
11870
|
for (const root of [".claude/skills", ".agents/skills"]) {
|
|
11612
|
-
const file =
|
|
11871
|
+
const file = join14(worktree, root, slug, SKILL_BODY_FILE);
|
|
11613
11872
|
const meta = lstatSync8(file, { throwIfNoEntry: false });
|
|
11614
11873
|
if (!meta) continue;
|
|
11615
11874
|
if (!meta.isFile() || meta.isSymbolicLink() || meta.nlink !== 1 || meta.size < 1 || meta.size > MAX_PROFILE_SKILL_INSTRUCTIONS_LENGTH) return missing2("invalid");
|
|
@@ -11631,7 +11890,7 @@ function repositorySkill(worktree, slug) {
|
|
|
11631
11890
|
name: (declaredName || slug).slice(0, 80),
|
|
11632
11891
|
description: description.slice(0, 500),
|
|
11633
11892
|
source: "repository",
|
|
11634
|
-
digest:
|
|
11893
|
+
digest: createHash8("sha256").update(body, "utf8").digest("hex"),
|
|
11635
11894
|
instructions: body,
|
|
11636
11895
|
available: true
|
|
11637
11896
|
};
|
|
@@ -11645,16 +11904,16 @@ function writeProfileSkillManifest(options, runDir, worktree, includeRepository)
|
|
|
11645
11904
|
if (assigned.length > MAX_PROFILE_SKILLS_PER_RUN || declared.length > MAX_PROFILE_SKILLS_PER_RUN) throw new Error("Profile Skill assignment limit");
|
|
11646
11905
|
const entries = [];
|
|
11647
11906
|
for (const skill of assigned) {
|
|
11648
|
-
const digest9 =
|
|
11907
|
+
const digest9 = createHash8("sha256").update(skill.instructions, "utf8").digest("hex");
|
|
11649
11908
|
if (digest9 !== skill.digest) throw new Error("Profile Skill artifact digest mismatch");
|
|
11650
11909
|
entries.push({ id: skill.id, name: skill.name, description: skill.description, source: skill.source, digest: digest9, instructions: skill.instructions, available: true });
|
|
11651
11910
|
}
|
|
11652
11911
|
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" });
|
|
11653
11912
|
const unique = [...new Map(entries.map((entry) => [entry.id, entry])).values()];
|
|
11654
|
-
const dir =
|
|
11913
|
+
const dir = join14(runDir, PROFILE_SKILLS_DIR);
|
|
11655
11914
|
ownDir(dir);
|
|
11656
11915
|
const manifest = { version: 1, skills: unique };
|
|
11657
|
-
const file =
|
|
11916
|
+
const file = join14(dir, PROFILE_SKILL_MANIFEST_FILE);
|
|
11658
11917
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
11659
11918
|
writeFileSync4(tmp, `${JSON.stringify(manifest)}
|
|
11660
11919
|
`, { encoding: "utf8", mode: 384 });
|
|
@@ -11665,11 +11924,11 @@ function prepareRunContextFiles(options) {
|
|
|
11665
11924
|
ownDir(options.runDir);
|
|
11666
11925
|
const runDir = realpathSync9(options.runDir);
|
|
11667
11926
|
const files2 = {
|
|
11668
|
-
worktree:
|
|
11927
|
+
worktree: resolve11(options.worktree),
|
|
11669
11928
|
runDir,
|
|
11670
|
-
handoffFile:
|
|
11671
|
-
tmpDir:
|
|
11672
|
-
capturesDir:
|
|
11929
|
+
handoffFile: join14(runDir, "handoff.json"),
|
|
11930
|
+
tmpDir: join14(runDir, "tmp"),
|
|
11931
|
+
capturesDir: join14(runDir, CAPTURES_DIR)
|
|
11673
11932
|
};
|
|
11674
11933
|
ownDir(files2.tmpDir);
|
|
11675
11934
|
ownDir(files2.capturesDir);
|
|
@@ -11703,7 +11962,7 @@ function runMcpServer(options, files2) {
|
|
|
11703
11962
|
files2.worktree,
|
|
11704
11963
|
"--capture-root",
|
|
11705
11964
|
files2.tmpDir,
|
|
11706
|
-
...options.profileSkills?.length || options.repositorySkills?.length ? ["--profile-skills",
|
|
11965
|
+
...options.profileSkills?.length || options.repositorySkills?.length ? ["--profile-skills", join14(files2.runDir, PROFILE_SKILLS_DIR)] : [],
|
|
11707
11966
|
...options.factoryCheck && (!options.factoryCheck.reportOnly || options.factoryCheck.inferCommand) ? ["--factory-verify", JSON.stringify({ cwd: files2.worktree, command: options.verifyCommand ?? null, infer: options.factoryCheck.inferCommand })] : [],
|
|
11708
11967
|
...options.factoryCheck?.reportOnly || readOnlyInspection ? ["--factory-artifacts", files2.worktree] : [],
|
|
11709
11968
|
...repositoryExecution ? ["--repository-selection", files2.worktree] : []
|
|
@@ -11751,13 +12010,13 @@ var RunContext = class {
|
|
|
11751
12010
|
);
|
|
11752
12011
|
ownDir(options.runDir);
|
|
11753
12012
|
this.runDir = realpathSync9(options.runDir);
|
|
11754
|
-
this.handoffFile =
|
|
11755
|
-
this.skillsDir =
|
|
11756
|
-
this.tmpDir =
|
|
12013
|
+
this.handoffFile = join14(this.runDir, "handoff.json");
|
|
12014
|
+
this.skillsDir = join14(this.runDir, SKILLS_DIR);
|
|
12015
|
+
this.tmpDir = join14(this.runDir, "tmp");
|
|
11757
12016
|
ownDir(this.tmpDir);
|
|
11758
|
-
this.capturesDir =
|
|
12017
|
+
this.capturesDir = join14(this.runDir, CAPTURES_DIR);
|
|
11759
12018
|
ownDir(this.capturesDir);
|
|
11760
|
-
this.profileSkillsDir =
|
|
12019
|
+
this.profileSkillsDir = join14(this.runDir, PROFILE_SKILLS_DIR);
|
|
11761
12020
|
this.writeSkills();
|
|
11762
12021
|
this.writeProfileSkills();
|
|
11763
12022
|
if (options.github && !options.machineEnvironment) {
|
|
@@ -11800,23 +12059,23 @@ var RunContext = class {
|
|
|
11800
12059
|
let slug = base;
|
|
11801
12060
|
for (let n = 2; taken.has(slug); n += 1) slug = `${base}-${n}`;
|
|
11802
12061
|
taken.add(slug);
|
|
11803
|
-
const dir =
|
|
12062
|
+
const dir = join14(this.skillsDir, slug);
|
|
11804
12063
|
if (this.options.skillReceipt) {
|
|
11805
12064
|
const existing = lstatSync8(dir, { throwIfNoEntry: false });
|
|
11806
12065
|
if (existing && (!existing.isDirectory() || existing.isSymbolicLink())) throw new Error("Unsafe Skill artifact directory");
|
|
11807
|
-
const file = lstatSync8(
|
|
12066
|
+
const file = lstatSync8(join14(dir, SKILL_BODY_FILE), { throwIfNoEntry: false });
|
|
11808
12067
|
if (file && (!file.isFile() || file.isSymbolicLink() || file.nlink !== 1)) throw new Error("Unsafe Skill artifact file");
|
|
11809
12068
|
}
|
|
11810
12069
|
mkdirSync8(dir, { recursive: true });
|
|
11811
|
-
const bodyFile =
|
|
12070
|
+
const bodyFile = join14(dir, SKILL_BODY_FILE);
|
|
11812
12071
|
if (this.options.skillReceipt) {
|
|
11813
12072
|
if (!lstatSync8(bodyFile, { throwIfNoEntry: false })) writeFileSync4(bodyFile, skillMarkdown(skill), { encoding: "utf8", flag: "wx", mode: 384 });
|
|
11814
12073
|
} else writeFileSync4(bodyFile, skillMarkdown(skill), "utf8");
|
|
11815
|
-
if (this.options.skillReceipt) verifyMountedSkill(
|
|
12074
|
+
if (this.options.skillReceipt) verifyMountedSkill(join14(dir, SKILL_BODY_FILE), this.options.skillReceipt);
|
|
11816
12075
|
for (const file of skill.files) {
|
|
11817
|
-
const target =
|
|
12076
|
+
const target = resolve11(dir, file.path);
|
|
11818
12077
|
if (!target.startsWith(`${dir}/`)) continue;
|
|
11819
|
-
mkdirSync8(
|
|
12078
|
+
mkdirSync8(dirname11(target), { recursive: true });
|
|
11820
12079
|
writeFileSync4(target, file.content, "utf8");
|
|
11821
12080
|
}
|
|
11822
12081
|
}
|
|
@@ -11850,14 +12109,14 @@ var RunContext = class {
|
|
|
11850
12109
|
denyWrite: [
|
|
11851
12110
|
// The fixture's refs/objects are writable for push; its configuration
|
|
11852
12111
|
// and hooks must remain host-owned because fixture verification runs Git.
|
|
11853
|
-
...fixtureOrigin ? [
|
|
11854
|
-
|
|
11855
|
-
|
|
11856
|
-
|
|
11857
|
-
|
|
12112
|
+
...fixtureOrigin ? [join14(fixtureOrigin, "config"), join14(fixtureOrigin, "hooks")] : [],
|
|
12113
|
+
join14(this.worktree, ".git"),
|
|
12114
|
+
join14(this.gitDir, "commondir"),
|
|
12115
|
+
join14(this.gitDir, "gitdir"),
|
|
12116
|
+
join14(this.gitDir, "config.worktree"),
|
|
11858
12117
|
// A repository's config and hooks in the shared clone, outside the
|
|
11859
12118
|
// working directory, are declared read-only here too.
|
|
11860
|
-
...this.options.gitWritePaths?.length ? [
|
|
12119
|
+
...this.options.gitWritePaths?.length ? [join14(this.gitDir, "..", "..", "config"), join14(this.gitDir, "..", "..", "hooks")] : [],
|
|
11861
12120
|
...readOnly ? [this.worktree, ...this.options.gitWritePaths ?? []] : []
|
|
11862
12121
|
],
|
|
11863
12122
|
denyRead: [
|
|
@@ -11911,7 +12170,7 @@ var RunContext = class {
|
|
|
11911
12170
|
*/
|
|
11912
12171
|
tempEnv() {
|
|
11913
12172
|
if (this.options.machineEnvironment) return this.options.policyHash ? { MIKKA_POLICY_HASH: this.options.policyHash } : {};
|
|
11914
|
-
return { TMPDIR: this.tmpDir, TMPPREFIX:
|
|
12173
|
+
return { TMPDIR: this.tmpDir, TMPPREFIX: join14(this.tmpDir, "zsh"), ...withGitConfig(this.githubEnv, RUN_GIT_CONFIG), ...this.options.policyHash ? { MIKKA_POLICY_HASH: this.options.policyHash } : {} };
|
|
11915
12174
|
}
|
|
11916
12175
|
/**
|
|
11917
12176
|
* The agent delivers this run itself: it commits, pushes to the task
|
|
@@ -12392,8 +12651,8 @@ var PromptQueue = class {
|
|
|
12392
12651
|
continue;
|
|
12393
12652
|
}
|
|
12394
12653
|
if (this.closed) return;
|
|
12395
|
-
await new Promise((
|
|
12396
|
-
this.waiter =
|
|
12654
|
+
await new Promise((resolve20) => {
|
|
12655
|
+
this.waiter = resolve20;
|
|
12397
12656
|
});
|
|
12398
12657
|
}
|
|
12399
12658
|
}
|
|
@@ -12407,8 +12666,8 @@ async function untilSpoken(spoken) {
|
|
|
12407
12666
|
try {
|
|
12408
12667
|
return await Promise.race([
|
|
12409
12668
|
spoken,
|
|
12410
|
-
new Promise((
|
|
12411
|
-
timer = setTimeout(() =>
|
|
12669
|
+
new Promise((resolve20) => {
|
|
12670
|
+
timer = setTimeout(() => resolve20(true), CONTINUE_SILENCE_MS);
|
|
12412
12671
|
})
|
|
12413
12672
|
]);
|
|
12414
12673
|
} finally {
|
|
@@ -12551,15 +12810,15 @@ var ClaudeAdapter = class {
|
|
|
12551
12810
|
throw new Error(SUBSCRIPTION_ERROR, { cause: error });
|
|
12552
12811
|
}
|
|
12553
12812
|
}
|
|
12554
|
-
const nativeHome = options.machineEnvironment ? options.env.HOME :
|
|
12813
|
+
const nativeHome = options.machineEnvironment ? options.env.HOME : join15(runDir, "native-home");
|
|
12555
12814
|
if (!nativeHome) throw new Error("Cloud machine HOME unavailable");
|
|
12556
|
-
const configDir = options.machineEnvironment ? options.env.CLAUDE_CONFIG_DIR ??
|
|
12815
|
+
const configDir = options.machineEnvironment ? options.env.CLAUDE_CONFIG_DIR ?? join15(nativeHome, ".claude") : join15(nativeHome, ".claude");
|
|
12557
12816
|
if (!options.machineEnvironment) {
|
|
12558
12817
|
ownDir(nativeHome);
|
|
12559
12818
|
ownDir(configDir);
|
|
12560
12819
|
}
|
|
12561
12820
|
if (!options.machineEnvironment && mode === "continue" && options.continueSession) {
|
|
12562
|
-
carryHistory(
|
|
12821
|
+
carryHistory(join15(runPaths(this.options.stateDir, options.continueSession.runId).runDir, "native-home", ".claude"), configDir, ["projects"]);
|
|
12563
12822
|
}
|
|
12564
12823
|
if (externalAuth && options.credential) throw new Error(SUBSCRIPTION_ERROR);
|
|
12565
12824
|
const credentialEnv = claudeCredentialEnv(options.credential);
|
|
@@ -12594,8 +12853,8 @@ var ClaudeAdapter = class {
|
|
|
12594
12853
|
privateDir: paths.privateDir,
|
|
12595
12854
|
// Its session store, so `resume` works; keyed by the cwd it sees.
|
|
12596
12855
|
extraWrite: preparing ? [] : [
|
|
12597
|
-
|
|
12598
|
-
|
|
12856
|
+
join15(configDir, "projects", claudeProjectDirName(options.cwd)),
|
|
12857
|
+
join15(
|
|
12599
12858
|
configDir,
|
|
12600
12859
|
"projects",
|
|
12601
12860
|
claudeProjectDirName(realpathSync10(options.cwd))
|
|
@@ -12629,15 +12888,15 @@ var ClaudeAdapter = class {
|
|
|
12629
12888
|
let authTimer;
|
|
12630
12889
|
let stderr = "";
|
|
12631
12890
|
let stderrArrived = () => void 0;
|
|
12632
|
-
const firstStderr = new Promise((
|
|
12633
|
-
stderrArrived =
|
|
12891
|
+
const firstStderr = new Promise((resolve20) => {
|
|
12892
|
+
stderrArrived = resolve20;
|
|
12634
12893
|
});
|
|
12635
12894
|
const stderrTail = () => stderr.slice(-STDERR_TAIL2).trim() || "no output";
|
|
12636
12895
|
let spoke = () => void 0;
|
|
12637
|
-
const spoken = new Promise((
|
|
12896
|
+
const spoken = new Promise((resolve20) => spoke = resolve20);
|
|
12638
12897
|
let checkingContinuation = mode === "continue";
|
|
12639
12898
|
let finished = () => void 0;
|
|
12640
|
-
const gone = new Promise((
|
|
12899
|
+
const gone = new Promise((resolve20) => finished = resolve20);
|
|
12641
12900
|
let nativeExit = Promise.resolve(false);
|
|
12642
12901
|
if (externalAuth && this.options.onHostedSession) {
|
|
12643
12902
|
try {
|
|
@@ -12676,10 +12935,10 @@ var ClaudeAdapter = class {
|
|
|
12676
12935
|
stderr = previousStderr.slice(-STDERR_TAIL2 * 4);
|
|
12677
12936
|
stderrArrived();
|
|
12678
12937
|
}
|
|
12679
|
-
nativeExit = new Promise((
|
|
12680
|
-
child.once("exit", () =>
|
|
12681
|
-
child.once("error", () =>
|
|
12682
|
-
if (child.exitCode !== null || child.signalCode)
|
|
12938
|
+
nativeExit = new Promise((resolve20) => {
|
|
12939
|
+
child.once("exit", () => resolve20(true));
|
|
12940
|
+
child.once("error", () => resolve20(false));
|
|
12941
|
+
if (child.exitCode !== null || child.signalCode) resolve20(true);
|
|
12683
12942
|
});
|
|
12684
12943
|
child.stderr?.on("data", (data) => {
|
|
12685
12944
|
stderr = (stderr + data.toString()).slice(-STDERR_TAIL2 * 4);
|
|
@@ -12738,7 +12997,7 @@ var ClaudeAdapter = class {
|
|
|
12738
12997
|
if (preparation) {
|
|
12739
12998
|
const { binding, control } = preparation;
|
|
12740
12999
|
const fixed = claudePrewarmOptionsKey(options);
|
|
12741
|
-
const parking =
|
|
13000
|
+
const parking = join15(runDir, "claude-parking");
|
|
12742
13001
|
ownDir(parking);
|
|
12743
13002
|
let anonymousAdopted = false;
|
|
12744
13003
|
const prepared = prepareClaudeSession({
|
|
@@ -12905,8 +13164,8 @@ var ClaudeAdapter = class {
|
|
|
12905
13164
|
if (!message.is_error) quota = void 0;
|
|
12906
13165
|
if (message.is_error && externalAuth && !stderr) {
|
|
12907
13166
|
let drainTimer;
|
|
12908
|
-
await Promise.race([firstStderr, new Promise((
|
|
12909
|
-
drainTimer = setTimeout(
|
|
13167
|
+
await Promise.race([firstStderr, new Promise((resolve20) => {
|
|
13168
|
+
drainTimer = setTimeout(resolve20, 100);
|
|
12910
13169
|
})]);
|
|
12911
13170
|
clearTimeout(drainTimer);
|
|
12912
13171
|
}
|
|
@@ -13094,7 +13353,7 @@ function codexFailureMessage(phase, info) {
|
|
|
13094
13353
|
}
|
|
13095
13354
|
|
|
13096
13355
|
// src/adapters/codex.ts
|
|
13097
|
-
import { delimiter as delimiter3, dirname as
|
|
13356
|
+
import { delimiter as delimiter3, dirname as dirname12, isAbsolute as isAbsolute5, join as join17, relative as relative5 } from "node:path";
|
|
13098
13357
|
import { mkdirSync as mkdirSync10 } from "node:fs";
|
|
13099
13358
|
|
|
13100
13359
|
// src/codex-generation-telemetry.ts
|
|
@@ -13514,11 +13773,11 @@ async function startCodexGenerationCollector(emit) {
|
|
|
13514
13773
|
server.requestTimeout = 1e3;
|
|
13515
13774
|
server.headersTimeout = 1e3;
|
|
13516
13775
|
server.maxConnections = 4;
|
|
13517
|
-
await new Promise((
|
|
13776
|
+
await new Promise((resolve20, reject) => {
|
|
13518
13777
|
server.once("error", reject);
|
|
13519
13778
|
server.listen(0, "127.0.0.1", () => {
|
|
13520
13779
|
server.off("error", reject);
|
|
13521
|
-
|
|
13780
|
+
resolve20();
|
|
13522
13781
|
});
|
|
13523
13782
|
});
|
|
13524
13783
|
server.on("error", () => collector.reject());
|
|
@@ -13538,7 +13797,7 @@ async function startCodexGenerationCollector(emit) {
|
|
|
13538
13797
|
"-c",
|
|
13539
13798
|
"otel.log_guardian_assessments=false"
|
|
13540
13799
|
],
|
|
13541
|
-
close: (cliExitObserved = false) => closed ??= new Promise((
|
|
13800
|
+
close: (cliExitObserved = false) => closed ??= new Promise((resolve20) => {
|
|
13542
13801
|
const timer = setTimeout(() => {
|
|
13543
13802
|
collector.truncate();
|
|
13544
13803
|
server.closeAllConnections();
|
|
@@ -13546,7 +13805,7 @@ async function startCodexGenerationCollector(emit) {
|
|
|
13546
13805
|
timer.unref();
|
|
13547
13806
|
server.close(() => {
|
|
13548
13807
|
clearTimeout(timer);
|
|
13549
|
-
|
|
13808
|
+
resolve20(collector.finish(cliExitObserved));
|
|
13550
13809
|
});
|
|
13551
13810
|
})
|
|
13552
13811
|
};
|
|
@@ -13589,11 +13848,11 @@ var JsonlWriter = class extends AbstractMessageWriter {
|
|
|
13589
13848
|
}
|
|
13590
13849
|
stream;
|
|
13591
13850
|
write(message) {
|
|
13592
|
-
return new Promise((
|
|
13851
|
+
return new Promise((resolve20, reject) => {
|
|
13593
13852
|
this.stream.write(
|
|
13594
13853
|
`${JSON.stringify(message)}
|
|
13595
13854
|
`,
|
|
13596
|
-
(error) => error ? reject(error) :
|
|
13855
|
+
(error) => error ? reject(error) : resolve20()
|
|
13597
13856
|
);
|
|
13598
13857
|
});
|
|
13599
13858
|
}
|
|
@@ -13610,7 +13869,7 @@ function jsonlConnection(input, output) {
|
|
|
13610
13869
|
|
|
13611
13870
|
// src/adapters/codex-mailbox.ts
|
|
13612
13871
|
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";
|
|
13613
|
-
import { isAbsolute as isAbsolute4, join as
|
|
13872
|
+
import { isAbsolute as isAbsolute4, join as join16, relative as relative4, sep as sep3 } from "node:path";
|
|
13614
13873
|
import { isDeepStrictEqual } from "node:util";
|
|
13615
13874
|
var unavailable2 = () => new Error("Run mailbox requires a verified original Codex thread");
|
|
13616
13875
|
function codexMailboxResumeVersion(userAgent) {
|
|
@@ -13627,7 +13886,7 @@ function historyParts(value) {
|
|
|
13627
13886
|
return parts;
|
|
13628
13887
|
}
|
|
13629
13888
|
function receiptFile(stateDir, runId) {
|
|
13630
|
-
return
|
|
13889
|
+
return join16(stateDir, "codex-mailbox", assertSafeId("run id", runId) + ".json");
|
|
13631
13890
|
}
|
|
13632
13891
|
function readJson2(file, limit, firstLine = false) {
|
|
13633
13892
|
const fd = openSync3(file, constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK);
|
|
@@ -13647,16 +13906,16 @@ function verifyHistory(home, path3, threadId, catalogue) {
|
|
|
13647
13906
|
const parts = historyParts(path3);
|
|
13648
13907
|
let parent = home;
|
|
13649
13908
|
for (const part of ["", ...parts.slice(0, -1)]) {
|
|
13650
|
-
if (part) parent =
|
|
13909
|
+
if (part) parent = join16(parent, part);
|
|
13651
13910
|
const stat3 = lstatSync9(parent);
|
|
13652
13911
|
if (!stat3.isDirectory() || stat3.isSymbolicLink()) throw unavailable2();
|
|
13653
13912
|
}
|
|
13654
|
-
const header = readJson2(
|
|
13913
|
+
const header = readJson2(join16(home, ...parts), 1024 * 1024, true);
|
|
13655
13914
|
if (header?.type !== "session_meta" || header.payload?.id !== threadId || !isDeepStrictEqual(header.payload.dynamic_tools, catalogue)) throw unavailable2();
|
|
13656
13915
|
}
|
|
13657
13916
|
function verifyCodexMailboxResume(stateDir, sourceRunId, home, threadId, catalogue) {
|
|
13658
13917
|
try {
|
|
13659
|
-
const dir = lstatSync9(
|
|
13918
|
+
const dir = lstatSync9(join16(stateDir, "codex-mailbox"));
|
|
13660
13919
|
if (!dir.isDirectory() || dir.isSymbolicLink()) throw unavailable2();
|
|
13661
13920
|
const receipt = readJson2(receiptFile(stateDir, sourceRunId), 256 * 1024);
|
|
13662
13921
|
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();
|
|
@@ -13669,10 +13928,10 @@ function verifyCodexMailboxResume(stateDir, sourceRunId, home, threadId, catalog
|
|
|
13669
13928
|
function recordCodexMailboxSession(stateDir, runId, home, thread, catalogue, resumed, nativeVersion) {
|
|
13670
13929
|
try {
|
|
13671
13930
|
if (!thread.id || typeof thread.path !== "string" || !isAbsolute4(thread.path)) throw unavailable2();
|
|
13672
|
-
const historyPath =
|
|
13931
|
+
const historyPath = relative4(home, thread.path).split(sep3).join("/");
|
|
13673
13932
|
historyParts(historyPath);
|
|
13674
13933
|
if (resumed) verifyHistory(home, historyPath, thread.id, catalogue);
|
|
13675
|
-
const dir =
|
|
13934
|
+
const dir = join16(stateDir, "codex-mailbox");
|
|
13676
13935
|
mkdirSync9(dir, { recursive: true, mode: 448 });
|
|
13677
13936
|
const stat3 = lstatSync9(dir);
|
|
13678
13937
|
if (!stat3.isDirectory() || stat3.isSymbolicLink()) throw unavailable2();
|
|
@@ -13846,7 +14105,7 @@ function codexItemChunks(phase, item, streamed, worktree) {
|
|
|
13846
14105
|
type: "data-file-change",
|
|
13847
14106
|
data: {
|
|
13848
14107
|
// Codex reports absolute paths; runs report worktree-relative ones.
|
|
13849
|
-
path: isAbsolute5(c.path) ?
|
|
14108
|
+
path: isAbsolute5(c.path) ? relative5(worktree, c.path) : c.path,
|
|
13850
14109
|
change: c.kind.type === "add" ? "added" : c.kind.type === "delete" ? "deleted" : "modified"
|
|
13851
14110
|
}
|
|
13852
14111
|
}))
|
|
@@ -13936,8 +14195,8 @@ var CodexAdapter = class {
|
|
|
13936
14195
|
options.continueSession.runId
|
|
13937
14196
|
).runDir;
|
|
13938
14197
|
carryHistory(
|
|
13939
|
-
|
|
13940
|
-
|
|
14198
|
+
join17(earlier2, "codex-home"),
|
|
14199
|
+
join17(runDir, "codex-home"),
|
|
13941
14200
|
CODEX_HISTORY
|
|
13942
14201
|
);
|
|
13943
14202
|
} catch (error) {
|
|
@@ -13948,7 +14207,7 @@ var CodexAdapter = class {
|
|
|
13948
14207
|
log.info({ err: error }, "could not copy the earlier codex threads");
|
|
13949
14208
|
}
|
|
13950
14209
|
}
|
|
13951
|
-
const codexHome = options.machineEnvironment ? { home: options.env.CODEX_HOME ??
|
|
14210
|
+
const codexHome = options.machineEnvironment ? { home: options.env.CODEX_HOME ?? join17(options.env.HOME, ".codex") } : prepareCodexHome(join17(runDir, "codex-home"), log);
|
|
13952
14211
|
if (options.machineEnvironment) mkdirSync10(codexHome.home, { recursive: true, mode: 448 });
|
|
13953
14212
|
const mailboxResumeVersion = mailboxCatalogue && threadId ? verifyCodexMailboxResume(
|
|
13954
14213
|
this.options.stateDir,
|
|
@@ -13959,7 +14218,7 @@ var CodexAdapter = class {
|
|
|
13959
14218
|
) : null;
|
|
13960
14219
|
const computerMcp = this.options.computerMcp ?? this.options.computerProvider?.(options.runId, options.policy);
|
|
13961
14220
|
const binary = this.options.binary ?? await this.options.ensureBinary?.() ?? "codex";
|
|
13962
|
-
const childPath = isAbsolute5(binary) ?
|
|
14221
|
+
const childPath = isAbsolute5(binary) ? dirname12(binary) + delimiter3 + (options.env.PATH ?? "") : options.env.PATH;
|
|
13963
14222
|
if (externalAuth && options.credential) throw new Error(SUBSCRIPTION_AUTH_ERROR);
|
|
13964
14223
|
const credential = codexCredential(brokerAuth ? { kind: "provider", protocol: "openai", baseUrl: "https://mikka.invalid", key: NATIVE_AUTH_PLACEHOLDER } : options.credential);
|
|
13965
14224
|
const providerDomain = credentialDomain(options.credential);
|
|
@@ -14592,7 +14851,7 @@ var CodexAdapter = class {
|
|
|
14592
14851
|
// src/adapters/cursor.ts
|
|
14593
14852
|
import { Readable, Writable } from "node:stream";
|
|
14594
14853
|
import * as acp from "@agentclientprotocol/sdk";
|
|
14595
|
-
import { join as
|
|
14854
|
+
import { join as join18 } from "node:path";
|
|
14596
14855
|
function cursorAppServers(apps) {
|
|
14597
14856
|
return [
|
|
14598
14857
|
...(apps?.apps ?? []).map((app) => ({ type: "http", name: app.name, url: app.url, headers: [{ name: "Authorization", value: `Bearer ${apps.token}` }] })),
|
|
@@ -14724,15 +14983,15 @@ var CursorAdapter = class {
|
|
|
14724
14983
|
options.continueSession.runId
|
|
14725
14984
|
).runDir;
|
|
14726
14985
|
carryHistory(
|
|
14727
|
-
|
|
14728
|
-
|
|
14986
|
+
join18(earlier2, "cursor-home"),
|
|
14987
|
+
join18(paths.runDir, "cursor-home"),
|
|
14729
14988
|
CURSOR_HISTORY
|
|
14730
14989
|
);
|
|
14731
14990
|
} catch (error) {
|
|
14732
14991
|
log.info({ err: error }, "could not copy the earlier cursor chats");
|
|
14733
14992
|
}
|
|
14734
14993
|
}
|
|
14735
|
-
const configDir = prepareCursorHome(
|
|
14994
|
+
const configDir = prepareCursorHome(join18(paths.runDir, "cursor-home"));
|
|
14736
14995
|
const ctx = new RunContext({
|
|
14737
14996
|
github: options.github,
|
|
14738
14997
|
githubEnvironment: options.githubEnvironment,
|
|
@@ -14967,7 +15226,7 @@ ${firstMessage}` : firstMessage
|
|
|
14967
15226
|
// src/adapters/mock.ts
|
|
14968
15227
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
14969
15228
|
import { mkdirSync as mkdirSync11, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "node:fs";
|
|
14970
|
-
import { dirname as
|
|
15229
|
+
import { dirname as dirname13, join as join19, resolve as resolve12 } from "node:path";
|
|
14971
15230
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
14972
15231
|
import { execa as execa5 } from "execa";
|
|
14973
15232
|
|
|
@@ -14999,7 +15258,7 @@ function isRunChunk(value) {
|
|
|
14999
15258
|
}
|
|
15000
15259
|
|
|
15001
15260
|
// src/adapters/mock.ts
|
|
15002
|
-
var DEFAULT_FIXTURES_DIR =
|
|
15261
|
+
var DEFAULT_FIXTURES_DIR = resolve12(
|
|
15003
15262
|
import.meta.dirname,
|
|
15004
15263
|
true ? "./fixtures" : "../../fixtures"
|
|
15005
15264
|
);
|
|
@@ -15033,7 +15292,7 @@ var MockAdapter = class {
|
|
|
15033
15292
|
fixturesDir;
|
|
15034
15293
|
speed;
|
|
15035
15294
|
stateFile(sessionId) {
|
|
15036
|
-
return
|
|
15295
|
+
return join19(
|
|
15037
15296
|
this.options.stateDir,
|
|
15038
15297
|
`mock-${assertSafeId("session id", sessionId)}.json`
|
|
15039
15298
|
);
|
|
@@ -15077,7 +15336,7 @@ var MockAdapter = class {
|
|
|
15077
15336
|
open(sessionId, state2, options) {
|
|
15078
15337
|
const name = assertSafeId("fixture", state2.fixture.replace(/\.jsonl$/, ""));
|
|
15079
15338
|
const lines = parseFixture(
|
|
15080
|
-
readFileSync9(
|
|
15339
|
+
readFileSync9(join19(this.fixturesDir, `${name}.jsonl`), "utf8"),
|
|
15081
15340
|
name
|
|
15082
15341
|
);
|
|
15083
15342
|
const abort = new AbortController();
|
|
@@ -15115,7 +15374,7 @@ var MockAdapter = class {
|
|
|
15115
15374
|
if (line.hang) {
|
|
15116
15375
|
if (!abort.signal.aborted) {
|
|
15117
15376
|
await new Promise(
|
|
15118
|
-
(
|
|
15377
|
+
(resolve20) => abort.signal.addEventListener("abort", resolve20, { once: true })
|
|
15119
15378
|
);
|
|
15120
15379
|
}
|
|
15121
15380
|
yield { type: "exit", outcome: "cancelled" };
|
|
@@ -15127,8 +15386,8 @@ var MockAdapter = class {
|
|
|
15127
15386
|
`mock fixture writes outside the worktree: ${line.write.path}`
|
|
15128
15387
|
);
|
|
15129
15388
|
}
|
|
15130
|
-
const target =
|
|
15131
|
-
mkdirSync11(
|
|
15389
|
+
const target = resolve12(options.cwd, line.write.path);
|
|
15390
|
+
mkdirSync11(dirname13(target), { recursive: true });
|
|
15132
15391
|
writeFileSync5(target, line.write.content);
|
|
15133
15392
|
}
|
|
15134
15393
|
if (line.chunk) yield { type: "chunk", chunk: line.chunk };
|
|
@@ -15191,13 +15450,13 @@ var MockAdapter = class {
|
|
|
15191
15450
|
|
|
15192
15451
|
// src/agents/local-github.ts
|
|
15193
15452
|
import { mkdirSync as mkdirSync13, mkdtempSync as mkdtempSync4, rmSync as rmSync10, writeFileSync as writeFileSync7 } from "node:fs";
|
|
15194
|
-
import { homedir as
|
|
15195
|
-
import { delimiter as delimiter4, join as
|
|
15453
|
+
import { homedir as homedir6 } from "node:os";
|
|
15454
|
+
import { delimiter as delimiter4, join as join21 } from "node:path";
|
|
15196
15455
|
|
|
15197
15456
|
// src/agents/machine-github.ts
|
|
15198
15457
|
import { existsSync as existsSync4, mkdirSync as mkdirSync12, readFileSync as readFileSync10, renameSync as renameSync3, rmSync as rmSync9, writeFileSync as writeFileSync6 } from "node:fs";
|
|
15199
15458
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
15200
|
-
import { dirname as
|
|
15459
|
+
import { dirname as dirname14, join as join20 } from "node:path";
|
|
15201
15460
|
function githubHosts(contents, token) {
|
|
15202
15461
|
if (!token || /[\r\n\0]/.test(token) || token.length > 32768) throw Error("github_credential_invalid");
|
|
15203
15462
|
const lines = contents.split(/\r?\n/);
|
|
@@ -15222,8 +15481,8 @@ function prepareMachineGitHub(github, host) {
|
|
|
15222
15481
|
if (!github.token) throw Error("github_credential_missing");
|
|
15223
15482
|
const home = host.env.HOME;
|
|
15224
15483
|
if (!home) throw Error("github_home_missing");
|
|
15225
|
-
const directory = host.env.GH_CONFIG_DIR ??
|
|
15226
|
-
const file =
|
|
15484
|
+
const directory = host.env.GH_CONFIG_DIR ?? join20(host.env.XDG_CONFIG_HOME ?? join20(home, ".config"), "gh");
|
|
15485
|
+
const file = join20(directory, "hosts.yml");
|
|
15227
15486
|
const original = existsSync4(file) ? readFileSync10(file, "utf8") : void 0;
|
|
15228
15487
|
let written;
|
|
15229
15488
|
let closed = false;
|
|
@@ -15237,7 +15496,7 @@ function prepareMachineGitHub(github, host) {
|
|
|
15237
15496
|
host.onCredential?.("GITHUB_TOKEN", credential.token);
|
|
15238
15497
|
const latest = existsSync4(file) ? readFileSync10(file, "utf8") : "";
|
|
15239
15498
|
const next = githubHosts(latest, credential.token);
|
|
15240
|
-
mkdirSync12(
|
|
15499
|
+
mkdirSync12(dirname14(file), { recursive: true, mode: 448 });
|
|
15241
15500
|
const temporary = `${file}.${randomUUID4()}`;
|
|
15242
15501
|
writeFileSync6(temporary, next, { mode: 384, flag: "wx" });
|
|
15243
15502
|
renameSync3(temporary, file);
|
|
@@ -15323,19 +15582,19 @@ async function prepareLocalGitHub(assignment, host) {
|
|
|
15323
15582
|
const credential = assignment.github.token ? { token: assignment.github.token, expiresAt: assignment.github.expiresAt ?? null } : await lease();
|
|
15324
15583
|
if (host.signal.aborted) throw Error("github_run_closed");
|
|
15325
15584
|
mkdirSync13(host.stateDir, { recursive: true, mode: 448 });
|
|
15326
|
-
const directory = mkdtempSync4(
|
|
15585
|
+
const directory = mkdtempSync4(join21(host.stateDir, "github-"));
|
|
15327
15586
|
try {
|
|
15328
|
-
const bin =
|
|
15587
|
+
const bin = join21(directory, "bin");
|
|
15329
15588
|
const quote2 = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
15330
15589
|
const helper2 = `${process.versions.electron ? "env ELECTRON_RUN_AS_NODE=1 " : ""}${quote2(process.execPath)} ${quote2(GITHUB_CREDENTIAL_SCRIPT)}`;
|
|
15331
15590
|
if (binary) {
|
|
15332
15591
|
mkdirSync13(bin, { mode: 448 });
|
|
15333
|
-
writeFileSync7(
|
|
15592
|
+
writeFileSync7(join21(bin, "gh"), `#!/bin/sh
|
|
15334
15593
|
exec ${helper2} native-gh ${quote2(binary)} ${quote2(directory)} "$@"
|
|
15335
15594
|
`, { mode: 448, flag: "wx" });
|
|
15336
15595
|
}
|
|
15337
15596
|
const prepared = prepareMachineGitHub({ ...assignment.github, ...credential, issueId: assignment.issueId }, {
|
|
15338
|
-
env: { HOME:
|
|
15597
|
+
env: { HOME: homedir6(), GH_CONFIG_DIR: directory },
|
|
15339
15598
|
signal: host.signal,
|
|
15340
15599
|
refresh: () => runRuntimeTimings.backgroundCredentialRefresh(assignment.runId, lease),
|
|
15341
15600
|
onCredential: host.onCredential,
|
|
@@ -15371,17 +15630,17 @@ exec ${helper2} native-gh ${quote2(binary)} ${quote2(directory)} "$@"
|
|
|
15371
15630
|
|
|
15372
15631
|
// src/agents/verify.ts
|
|
15373
15632
|
import { existsSync as existsSync5, mkdirSync as mkdirSync14, mkdtempSync as mkdtempSync5, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
|
|
15374
|
-
import { join as
|
|
15633
|
+
import { join as join22 } from "node:path";
|
|
15375
15634
|
var OUTPUT_TAIL = 4e3;
|
|
15376
15635
|
var SETUP_ATTEMPTS = 3;
|
|
15377
15636
|
async function runVerify(sandbox, options) {
|
|
15378
15637
|
options.signal?.throwIfAborted();
|
|
15379
15638
|
mkdirSync14(options.tmpRoot, { recursive: true, mode: 448 });
|
|
15380
|
-
const tmpDir = mkdtempSync5(
|
|
15639
|
+
const tmpDir = mkdtempSync5(join22(realpathSync11(options.tmpRoot), "verify-"));
|
|
15381
15640
|
const deadline = Date.now() + options.timeoutMs;
|
|
15382
15641
|
try {
|
|
15383
15642
|
for (let attempt = 1; ; attempt++) {
|
|
15384
|
-
const started =
|
|
15643
|
+
const started = join22(tmpDir, `.started-${attempt}`);
|
|
15385
15644
|
const result = await attemptVerify(sandbox, options, tmpDir, started, deadline - Date.now());
|
|
15386
15645
|
if (result.exitCode === 0 || result.timedOut || options.signal?.aborted || existsSync5(started) || attempt >= SETUP_ATTEMPTS)
|
|
15387
15646
|
return result;
|
|
@@ -15400,7 +15659,7 @@ async function attemptVerify(sandbox, options, tmpDir, started, timeoutMs) {
|
|
|
15400
15659
|
policy: {
|
|
15401
15660
|
allowWrite: options.readOnly ? [tmpDir] : [options.worktree, tmpDir],
|
|
15402
15661
|
denyWrite: [
|
|
15403
|
-
|
|
15662
|
+
join22(options.worktree, ".git"),
|
|
15404
15663
|
...options.readOnly ? [options.worktree] : []
|
|
15405
15664
|
],
|
|
15406
15665
|
denyRead: [
|
|
@@ -15471,7 +15730,7 @@ var NoSandbox = class {
|
|
|
15471
15730
|
|
|
15472
15731
|
// src/fs-browse.ts
|
|
15473
15732
|
import { execFile as execFile4 } from "node:child_process";
|
|
15474
|
-
import { readdir as
|
|
15733
|
+
import { readdir as readdir3, realpath, stat as stat2 } from "node:fs/promises";
|
|
15475
15734
|
import { promisify as promisify4 } from "node:util";
|
|
15476
15735
|
var run = promisify4(execFile4);
|
|
15477
15736
|
async function git(cwd, args) {
|
|
@@ -15498,7 +15757,7 @@ async function verifyExpectedOrigin(path3, expected2) {
|
|
|
15498
15757
|
}
|
|
15499
15758
|
|
|
15500
15759
|
// src/device-type.ts
|
|
15501
|
-
import { readdir as
|
|
15760
|
+
import { readdir as readdir4, readFile as readFile4 } from "node:fs/promises";
|
|
15502
15761
|
import { execa as execa6 } from "execa";
|
|
15503
15762
|
async function detectDeviceType() {
|
|
15504
15763
|
try {
|
|
@@ -15511,10 +15770,10 @@ async function detectDeviceType() {
|
|
|
15511
15770
|
return /MacBook/i.test(stdout) ? "laptop" : "server";
|
|
15512
15771
|
}
|
|
15513
15772
|
if (process.platform === "linux") {
|
|
15514
|
-
const entries = await
|
|
15773
|
+
const entries = await readdir4("/sys/class/power_supply");
|
|
15515
15774
|
const types = await Promise.all(
|
|
15516
15775
|
entries.map(
|
|
15517
|
-
(entry) =>
|
|
15776
|
+
(entry) => readFile4(`/sys/class/power_supply/${entry}/type`, "utf8").catch(
|
|
15518
15777
|
() => ""
|
|
15519
15778
|
)
|
|
15520
15779
|
)
|
|
@@ -15532,10 +15791,10 @@ import { arch as arch2, platform as platform2 } from "node:os";
|
|
|
15532
15791
|
import { execa as execa7 } from "execa";
|
|
15533
15792
|
|
|
15534
15793
|
// harness/install.mjs
|
|
15535
|
-
import { createHash as
|
|
15794
|
+
import { createHash as createHash9, randomBytes as randomBytes2 } from "node:crypto";
|
|
15536
15795
|
import { execFile as execFile5 } from "node:child_process";
|
|
15537
15796
|
import { createWriteStream as createWriteStream2, existsSync as existsSync6, 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";
|
|
15538
|
-
import { dirname as
|
|
15797
|
+
import { dirname as dirname15, join as join23, relative as relative6 } from "node:path";
|
|
15539
15798
|
import { Readable as Readable2, Transform } from "node:stream";
|
|
15540
15799
|
import { pipeline as pipeline2 } from "node:stream/promises";
|
|
15541
15800
|
import { promisify as promisify5 } from "node:util";
|
|
@@ -15584,17 +15843,17 @@ function resolvePin(store, harness) {
|
|
|
15584
15843
|
return { pin, artifact: pin.platforms[store.platform ?? platformKey()] };
|
|
15585
15844
|
}
|
|
15586
15845
|
function versionDir(store, harness) {
|
|
15587
|
-
return
|
|
15846
|
+
return join23(store.root, harness, resolvePin(store, harness).pin.version);
|
|
15588
15847
|
}
|
|
15589
15848
|
function harnessBinaryPath(store, harness) {
|
|
15590
|
-
return
|
|
15849
|
+
return join23(versionDir(store, harness), "bin", resolvePin(store, harness).pin.command);
|
|
15591
15850
|
}
|
|
15592
15851
|
function harnessInstallState(store, harness) {
|
|
15593
15852
|
const { pin, artifact } = resolvePin(store, harness);
|
|
15594
15853
|
if (!artifact) return { state: "unsupported", version: pin.version };
|
|
15595
15854
|
let installed = false;
|
|
15596
15855
|
try {
|
|
15597
|
-
installed = readFileSync11(
|
|
15856
|
+
installed = readFileSync11(join23(versionDir(store, harness), MARKER), "utf8") === installMarker(pin, artifact) && runtimeFiles(store, harness).every((path3) => {
|
|
15598
15857
|
const stat3 = statSync2(path3);
|
|
15599
15858
|
return stat3.isFile() && (stat3.mode & 73) !== 0;
|
|
15600
15859
|
});
|
|
@@ -15604,7 +15863,7 @@ function harnessInstallState(store, harness) {
|
|
|
15604
15863
|
}
|
|
15605
15864
|
function runtimeFiles(store, harness) {
|
|
15606
15865
|
const binary = harnessBinaryPath(store, harness);
|
|
15607
|
-
return harness === "codex" ? [binary,
|
|
15866
|
+
return harness === "codex" ? [binary, join23(dirname15(binary), "codex-code-mode-host")] : [binary];
|
|
15608
15867
|
}
|
|
15609
15868
|
function ensureHarness(store, harness) {
|
|
15610
15869
|
const key2 = `${store.root}\0${harness}`;
|
|
@@ -15621,27 +15880,27 @@ async function install(store, harness) {
|
|
|
15621
15880
|
if (state2 === "unsupported") throw new Error(`${harness} has no build for ${store.platform ?? platformKey()}`);
|
|
15622
15881
|
if (state2 === "installed") return binary;
|
|
15623
15882
|
const { pin, artifact } = resolvePin(store, harness);
|
|
15624
|
-
const parent =
|
|
15883
|
+
const parent = join23(store.root, harness);
|
|
15625
15884
|
mkdirSync15(parent, { recursive: true, mode: 448 });
|
|
15626
|
-
const staging =
|
|
15885
|
+
const staging = join23(parent, `.staging-${randomBytes2(6).toString("hex")}`);
|
|
15627
15886
|
mkdirSync15(staging, { recursive: true, mode: 448 });
|
|
15628
15887
|
try {
|
|
15629
|
-
const tarball =
|
|
15888
|
+
const tarball = join23(staging, "package.tgz");
|
|
15630
15889
|
await download(`${(store.pins ?? HARNESS_PINS).registry.replace(/\/$/, "")}/${artifact.tarball}`, tarball, artifact.integrity);
|
|
15631
15890
|
await run2("tar", ["-xzf", tarball, "-C", staging]);
|
|
15632
15891
|
if (harness === "codex") {
|
|
15633
15892
|
if (!artifact.entry.endsWith("/bin/codex")) throw new Error("Invalid Codex bundle entry");
|
|
15634
|
-
const bundle =
|
|
15635
|
-
for (const name of readdirSync5(
|
|
15893
|
+
const bundle = dirname15(dirname15(artifact.entry));
|
|
15894
|
+
for (const name of readdirSync5(join23(staging, bundle))) symlinkSync(relative6(staging, join23(staging, bundle, name)), join23(staging, name));
|
|
15636
15895
|
for (const name of ["codex", "codex-code-mode-host"]) {
|
|
15637
|
-
const stat3 = statSync2(
|
|
15896
|
+
const stat3 = statSync2(join23(staging, "bin", name));
|
|
15638
15897
|
if (!stat3.isFile() || (stat3.mode & 73) === 0) throw new Error("Incomplete Codex runtime bundle");
|
|
15639
15898
|
}
|
|
15640
15899
|
} else {
|
|
15641
|
-
mkdirSync15(
|
|
15642
|
-
symlinkSync(
|
|
15900
|
+
mkdirSync15(join23(staging, "bin"), { mode: 448 });
|
|
15901
|
+
symlinkSync(relative6(join23(staging, "bin"), join23(staging, artifact.entry)), join23(staging, "bin", pin.command));
|
|
15643
15902
|
}
|
|
15644
|
-
writeFileSync8(
|
|
15903
|
+
writeFileSync8(join23(staging, MARKER), installMarker(pin, artifact), { mode: 384 });
|
|
15645
15904
|
const target = versionDir(store, harness);
|
|
15646
15905
|
const retained = existsSync6(target) ? `${target}.retained-${randomBytes2(6).toString("hex")}` : null;
|
|
15647
15906
|
if (retained) renameSync4(target, retained);
|
|
@@ -15662,7 +15921,7 @@ async function download(url, file, integrity) {
|
|
|
15662
15921
|
if (algorithm !== "sha512" || !expected2) throw new Error("Unsupported harness integrity");
|
|
15663
15922
|
const response = await fetch(url, { redirect: "follow" });
|
|
15664
15923
|
if (!response.ok || !response.body) throw new Error(`Harness download failed (${response.status})`);
|
|
15665
|
-
const hash2 =
|
|
15924
|
+
const hash2 = createHash9("sha512");
|
|
15666
15925
|
const tap = new Transform({ transform(chunk, _encoding, done) {
|
|
15667
15926
|
hash2.update(chunk);
|
|
15668
15927
|
done(null, chunk);
|
|
@@ -15723,7 +15982,7 @@ function harnessFingerprint(store) {
|
|
|
15723
15982
|
// src/model-probe.ts
|
|
15724
15983
|
import { spawn as spawn3 } from "node:child_process";
|
|
15725
15984
|
import { mkdtempSync as mkdtempSync6, readdirSync as readdirSync6, rmSync as rmSync13 } from "node:fs";
|
|
15726
|
-
import { join as
|
|
15985
|
+
import { join as join24 } from "node:path";
|
|
15727
15986
|
|
|
15728
15987
|
// src/process-group.ts
|
|
15729
15988
|
async function stopGroup(child, graceMs = 3e3) {
|
|
@@ -15743,12 +16002,12 @@ async function stopGroup(child, graceMs = 3e3) {
|
|
|
15743
16002
|
};
|
|
15744
16003
|
if (child.exitCode === null && child.signalCode === null) {
|
|
15745
16004
|
signal("SIGTERM");
|
|
15746
|
-
await new Promise((
|
|
15747
|
-
if (child.exitCode !== null || child.signalCode !== null) return
|
|
16005
|
+
await new Promise((resolve20) => {
|
|
16006
|
+
if (child.exitCode !== null || child.signalCode !== null) return resolve20();
|
|
15748
16007
|
const done = () => {
|
|
15749
16008
|
clearTimeout(timer);
|
|
15750
16009
|
child.off("exit", done);
|
|
15751
|
-
|
|
16010
|
+
resolve20();
|
|
15752
16011
|
};
|
|
15753
16012
|
const timer = setTimeout(done, graceMs);
|
|
15754
16013
|
child.once("exit", done);
|
|
@@ -15803,10 +16062,10 @@ function sweepModelProbeHomes(scratchDir) {
|
|
|
15803
16062
|
} catch {
|
|
15804
16063
|
return;
|
|
15805
16064
|
}
|
|
15806
|
-
for (const name of names) if (name.startsWith(HOME_PREFIX)) rmSync13(
|
|
16065
|
+
for (const name of names) if (name.startsWith(HOME_PREFIX)) rmSync13(join24(scratchDir, name), { recursive: true, force: true });
|
|
15807
16066
|
}
|
|
15808
16067
|
async function probeHarnessModels(harness, binary, options) {
|
|
15809
|
-
const home = mkdtempSync6(
|
|
16068
|
+
const home = mkdtempSync6(join24(options.scratchDir, HOME_PREFIX));
|
|
15810
16069
|
try {
|
|
15811
16070
|
return await exchange(harness, binary, home, options);
|
|
15812
16071
|
} finally {
|
|
@@ -15815,15 +16074,15 @@ async function probeHarnessModels(harness, binary, options) {
|
|
|
15815
16074
|
}
|
|
15816
16075
|
function exchange(harness, binary, home, options) {
|
|
15817
16076
|
const args = harness === "codex" ? ["app-server"] : ["-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose"];
|
|
15818
|
-
const env = { PATH: process.env.PATH ?? "", HOME: home, CODEX_HOME: home, CLAUDE_CONFIG_DIR:
|
|
15819
|
-
return new Promise((
|
|
16077
|
+
const env = { PATH: process.env.PATH ?? "", HOME: home, CODEX_HOME: home, CLAUDE_CONFIG_DIR: join24(home, ".claude"), LANG: process.env.LANG ?? "C.UTF-8" };
|
|
16078
|
+
return new Promise((resolve20) => {
|
|
15820
16079
|
const child = (options.spawnImpl ?? spawn3)(binary, args, { env, cwd: home, detached: process.platform !== "win32", stdio: ["pipe", "pipe", "ignore"] });
|
|
15821
16080
|
let result;
|
|
15822
16081
|
let stopping;
|
|
15823
16082
|
const stop = () => stopping ??= Promise.resolve().then(() => stopGroup(child, 0));
|
|
15824
16083
|
const done = () => {
|
|
15825
16084
|
clearTimeout(timer);
|
|
15826
|
-
|
|
16085
|
+
resolve20(result ?? null);
|
|
15827
16086
|
};
|
|
15828
16087
|
const finish = (value) => {
|
|
15829
16088
|
if (result !== void 0) return;
|
|
@@ -15885,14 +16144,14 @@ function exchange(harness, binary, home, options) {
|
|
|
15885
16144
|
}
|
|
15886
16145
|
|
|
15887
16146
|
// src/cloud-registration.ts
|
|
15888
|
-
import { createHash as
|
|
15889
|
-
import { join as
|
|
16147
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
16148
|
+
import { join as join25 } from "node:path";
|
|
15890
16149
|
function writeCloudRegistration(dataDir, deviceId, workspaceId, credential) {
|
|
15891
|
-
writeJsonAtomic(
|
|
16150
|
+
writeJsonAtomic(join25(dataDir, "registration.json"), {
|
|
15892
16151
|
version: 1,
|
|
15893
16152
|
deviceId,
|
|
15894
16153
|
workspaceId,
|
|
15895
|
-
tokenSha256:
|
|
16154
|
+
tokenSha256: createHash10("sha256").update(credential).digest("hex")
|
|
15896
16155
|
});
|
|
15897
16156
|
}
|
|
15898
16157
|
|
|
@@ -15902,16 +16161,16 @@ import { mkdtempSync as mkdtempSync7, rmSync as rmSync14, statSync as statSync3
|
|
|
15902
16161
|
// src/hosted-binaries.ts
|
|
15903
16162
|
import { accessSync as accessSync2, constants as constants5, lstatSync as lstatSync10, readFileSync as readFileSync12, realpathSync as realpathSync12 } from "node:fs";
|
|
15904
16163
|
import { delimiter as delimiter5, isAbsolute as isAbsolute6 } from "node:path";
|
|
15905
|
-
import { z as
|
|
16164
|
+
import { z as z38 } from "zod";
|
|
15906
16165
|
var HOSTED_CLI_MANIFEST = "/opt/mikka/worker/.mikka-original-cli.json";
|
|
15907
16166
|
var LEGACY_HOSTED_CLI_MANIFEST = "/opt/mikka/original-cli.json";
|
|
15908
16167
|
var MANIFEST_PATHS = [HOSTED_CLI_MANIFEST, LEGACY_HOSTED_CLI_MANIFEST];
|
|
15909
|
-
var binarySchema =
|
|
15910
|
-
var manifestSchema =
|
|
15911
|
-
version:
|
|
15912
|
-
kind:
|
|
15913
|
-
original:
|
|
15914
|
-
added:
|
|
16168
|
+
var binarySchema = z38.object({ path: z38.string().min(1), sha256: z38.string().regex(/^[a-f0-9]{64}$/) }).strict();
|
|
16169
|
+
var manifestSchema = z38.object({
|
|
16170
|
+
version: z38.literal(1),
|
|
16171
|
+
kind: z38.enum(["claude", "codex", "desktop", "task"]),
|
|
16172
|
+
original: z38.object({ claude_code: binarySchema.nullable(), codex: binarySchema.nullable() }).strict(),
|
|
16173
|
+
added: z38.object({ claude_code: binarySchema.optional(), codex: binarySchema.optional() }).strict()
|
|
15915
16174
|
}).strict();
|
|
15916
16175
|
function readHostedCliManifest(paths = MANIFEST_PATHS) {
|
|
15917
16176
|
for (const path3 of typeof paths === "string" ? [paths] : paths) {
|
|
@@ -16095,10 +16354,10 @@ async function prepareSubscriptionCredentials(assignment, host) {
|
|
|
16095
16354
|
|
|
16096
16355
|
// src/run-scratch.ts
|
|
16097
16356
|
import { rmSync as rmSync15 } from "node:fs";
|
|
16098
|
-
import { join as
|
|
16357
|
+
import { join as join26 } from "node:path";
|
|
16099
16358
|
function removeRunCredentials(stateDir, runId) {
|
|
16100
16359
|
const { runDir } = runPaths(stateDir, runId);
|
|
16101
|
-
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync15(
|
|
16360
|
+
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync15(join26(runDir, path3), { recursive: true, force: true });
|
|
16102
16361
|
}
|
|
16103
16362
|
|
|
16104
16363
|
// src/subscription-local-runner.ts
|
|
@@ -16197,7 +16456,7 @@ function createLocalSubscriptionRunner(host) {
|
|
|
16197
16456
|
|
|
16198
16457
|
// src/subscription-preflight.ts
|
|
16199
16458
|
import { mkdtempSync as mkdtempSync8, rmSync as rmSync16 } from "node:fs";
|
|
16200
|
-
import { join as
|
|
16459
|
+
import { join as join27 } from "node:path";
|
|
16201
16460
|
import { execa as execa8 } from "execa";
|
|
16202
16461
|
var refused = (detail, cause) => ({
|
|
16203
16462
|
ready: false,
|
|
@@ -16216,7 +16475,7 @@ async function preflightLocalSubscription(harness, options) {
|
|
|
16216
16475
|
const expected2 = (options.store.pins ?? HARNESS_PINS).harnesses[harness].version;
|
|
16217
16476
|
let home;
|
|
16218
16477
|
try {
|
|
16219
|
-
home = mkdtempSync8(
|
|
16478
|
+
home = mkdtempSync8(join27(options.scratchDir, "subscription-preflight-"));
|
|
16220
16479
|
const result = await execa8(binary, ["--version"], {
|
|
16221
16480
|
env: { ...env, HOME: home },
|
|
16222
16481
|
extendEnv: false,
|
|
@@ -16280,8 +16539,8 @@ async function acquireCloudWorkspaceControl(input, root = CLOUD_WORKSPACE_CONTRO
|
|
|
16280
16539
|
});
|
|
16281
16540
|
let acquired = false, releasing = false, settled = false, output = "";
|
|
16282
16541
|
let finished;
|
|
16283
|
-
const done = new Promise((
|
|
16284
|
-
finished =
|
|
16542
|
+
const done = new Promise((resolve20) => {
|
|
16543
|
+
finished = resolve20;
|
|
16285
16544
|
});
|
|
16286
16545
|
child.stdin.on("error", () => {
|
|
16287
16546
|
if (!settled && !releasing) child.kill("SIGTERM");
|
|
@@ -16294,7 +16553,7 @@ async function acquireCloudWorkspaceControl(input, root = CLOUD_WORKSPACE_CONTRO
|
|
|
16294
16553
|
if (!acquired || settled || releasing || !child.stdin.writable) throw new CodedError("terminal_control_unavailable", { detail: "fence_lost" });
|
|
16295
16554
|
child.stdin.write(JSON.stringify(value) + "\n");
|
|
16296
16555
|
};
|
|
16297
|
-
await new Promise((
|
|
16556
|
+
await new Promise((resolve20, reject) => {
|
|
16298
16557
|
const fail = (cause) => reject(new CodedError("terminal_control_unavailable", { detail: "fence_unavailable", cause }));
|
|
16299
16558
|
child.once("error", fail);
|
|
16300
16559
|
child.stdout.on("data", (data) => {
|
|
@@ -16309,7 +16568,7 @@ async function acquireCloudWorkspaceControl(input, root = CLOUD_WORKSPACE_CONTRO
|
|
|
16309
16568
|
fail(input.signal.reason);
|
|
16310
16569
|
return;
|
|
16311
16570
|
}
|
|
16312
|
-
|
|
16571
|
+
resolve20();
|
|
16313
16572
|
} else if (output.length > 32) {
|
|
16314
16573
|
child.kill("SIGTERM");
|
|
16315
16574
|
fail();
|
|
@@ -16349,7 +16608,7 @@ import {
|
|
|
16349
16608
|
rmSync as rmSync17,
|
|
16350
16609
|
truncateSync
|
|
16351
16610
|
} from "node:fs";
|
|
16352
|
-
import { join as
|
|
16611
|
+
import { join as join28 } from "node:path";
|
|
16353
16612
|
var RETRY_MAX_MS = 3e4;
|
|
16354
16613
|
var Outbox = class {
|
|
16355
16614
|
constructor(dir, link, log, retryMs = 1e3, onUndeliverable = () => void 0, retainResources = false, traceContext = () => void 0) {
|
|
@@ -16377,10 +16636,10 @@ var Outbox = class {
|
|
|
16377
16636
|
/** Runs whose file was checked for a torn tail since this process started. */
|
|
16378
16637
|
repaired = /* @__PURE__ */ new Set();
|
|
16379
16638
|
file(runId) {
|
|
16380
|
-
return
|
|
16639
|
+
return join28(this.dir, `${assertSafeId("run id", runId)}.jsonl`);
|
|
16381
16640
|
}
|
|
16382
16641
|
ackFile(runId) {
|
|
16383
|
-
return
|
|
16642
|
+
return join28(this.dir, `${assertSafeId("run id", runId)}.ack.json`);
|
|
16384
16643
|
}
|
|
16385
16644
|
parse(runId) {
|
|
16386
16645
|
let data;
|
|
@@ -16735,9 +16994,9 @@ var RpcServer = class {
|
|
|
16735
16994
|
const { socketPath } = this.options;
|
|
16736
16995
|
rmSync18(socketPath, { force: true });
|
|
16737
16996
|
const server = createServer2((socket) => this.accept(socket));
|
|
16738
|
-
await new Promise((
|
|
16997
|
+
await new Promise((resolve20, reject) => {
|
|
16739
16998
|
server.once("error", reject);
|
|
16740
|
-
server.listen(socketPath, () =>
|
|
16999
|
+
server.listen(socketPath, () => resolve20());
|
|
16741
17000
|
});
|
|
16742
17001
|
chmodSync(socketPath, 384);
|
|
16743
17002
|
this.server = server;
|
|
@@ -16801,9 +17060,9 @@ var RpcServer = class {
|
|
|
16801
17060
|
}
|
|
16802
17061
|
async close() {
|
|
16803
17062
|
for (const socket of this.sockets) socket.destroy();
|
|
16804
|
-
await new Promise((
|
|
16805
|
-
if (!this.server) return
|
|
16806
|
-
this.server.close(() =>
|
|
17063
|
+
await new Promise((resolve20) => {
|
|
17064
|
+
if (!this.server) return resolve20();
|
|
17065
|
+
this.server.close(() => resolve20());
|
|
16807
17066
|
});
|
|
16808
17067
|
this.server = null;
|
|
16809
17068
|
rmSync18(this.options.socketPath, { force: true });
|
|
@@ -17031,7 +17290,7 @@ async function startTaskSecretBridge(options) {
|
|
|
17031
17290
|
};
|
|
17032
17291
|
options.signal.addEventListener("abort", close, { once: true });
|
|
17033
17292
|
try {
|
|
17034
|
-
await new Promise((
|
|
17293
|
+
await new Promise((resolve20, reject) => {
|
|
17035
17294
|
const cleanup = () => {
|
|
17036
17295
|
server.off("error", failed);
|
|
17037
17296
|
options.signal.removeEventListener("abort", cancelled);
|
|
@@ -17052,7 +17311,7 @@ async function startTaskSecretBridge(options) {
|
|
|
17052
17311
|
}
|
|
17053
17312
|
server.listen(0, "127.0.0.1", () => {
|
|
17054
17313
|
cleanup();
|
|
17055
|
-
|
|
17314
|
+
resolve20();
|
|
17056
17315
|
});
|
|
17057
17316
|
});
|
|
17058
17317
|
options.signal.throwIfAborted();
|
|
@@ -17081,37 +17340,37 @@ async function startTaskSecretBridge(options) {
|
|
|
17081
17340
|
}
|
|
17082
17341
|
|
|
17083
17342
|
// src/agents/chat-files.ts
|
|
17084
|
-
import { createHash as
|
|
17085
|
-
import { lstat as
|
|
17086
|
-
import { join as
|
|
17343
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
17344
|
+
import { lstat as lstat4, mkdir as mkdir4, readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
|
|
17345
|
+
import { join as join29 } from "node:path";
|
|
17087
17346
|
async function materializeChatFiles(text4, directory, download2) {
|
|
17088
17347
|
const parsed = splitChatFiles(text4);
|
|
17089
17348
|
if (!parsed.files.length) return text4;
|
|
17090
|
-
await
|
|
17091
|
-
if (!(await
|
|
17349
|
+
await mkdir4(directory, { recursive: true, mode: 448 });
|
|
17350
|
+
if (!(await lstat4(directory)).isDirectory() || (await lstat4(directory)).isSymbolicLink())
|
|
17092
17351
|
throw Error("Attachment directory unavailable");
|
|
17093
17352
|
const entries = [];
|
|
17094
17353
|
for (const ref of parsed.files) {
|
|
17095
17354
|
const file = chatFileDownloadSchema.parse(await download2(ref.id));
|
|
17096
17355
|
if (file.id !== ref.id) throw Error("Attachment identity mismatch");
|
|
17097
17356
|
const bytes = Buffer.from(file.data, "base64");
|
|
17098
|
-
if (bytes.length !== file.size || bytes.toString("base64") !== file.data ||
|
|
17357
|
+
if (bytes.length !== file.size || bytes.toString("base64") !== file.data || createHash11("sha256").update(bytes).digest("hex") !== file.sha256)
|
|
17099
17358
|
throw Error("Attachment content mismatch");
|
|
17100
17359
|
const ext = /\.([a-z0-9]{1,12})$/i.exec(file.name)?.[1]?.toLowerCase() ?? "bin";
|
|
17101
|
-
const path3 =
|
|
17360
|
+
const path3 = join29(directory, `${file.id}.${ext}`);
|
|
17102
17361
|
try {
|
|
17103
|
-
await
|
|
17362
|
+
await writeFile3(path3, bytes, { flag: "wx", mode: 256 });
|
|
17104
17363
|
} catch (error) {
|
|
17105
|
-
if (error.code !== "EEXIST" || (await
|
|
17364
|
+
if (error.code !== "EEXIST" || (await lstat4(path3)).isSymbolicLink() || createHash11("sha256").update(await readFile5(path3)).digest("hex") !== file.sha256)
|
|
17106
17365
|
throw Error("Attachment file unavailable");
|
|
17107
17366
|
}
|
|
17108
17367
|
let textPath;
|
|
17109
17368
|
if (file.text !== null) {
|
|
17110
|
-
textPath =
|
|
17369
|
+
textPath = join29(directory, `${file.id}.extracted.txt`);
|
|
17111
17370
|
try {
|
|
17112
|
-
await
|
|
17371
|
+
await writeFile3(textPath, file.text, { flag: "wx", mode: 256 });
|
|
17113
17372
|
} catch (error) {
|
|
17114
|
-
if (error.code !== "EEXIST" || (await
|
|
17373
|
+
if (error.code !== "EEXIST" || (await lstat4(textPath)).isSymbolicLink() || await readFile5(textPath, "utf8") !== file.text)
|
|
17115
17374
|
throw Error("Attachment text unavailable");
|
|
17116
17375
|
}
|
|
17117
17376
|
}
|
|
@@ -17125,9 +17384,9 @@ ${JSON.stringify(entries)}`;
|
|
|
17125
17384
|
|
|
17126
17385
|
// src/runs/check.ts
|
|
17127
17386
|
import { execa as execa9 } from "execa";
|
|
17128
|
-
async function fixedCheckSnapshot(repoPath, worktree,
|
|
17387
|
+
async function fixedCheckSnapshot(repoPath, worktree, sha6, signal) {
|
|
17129
17388
|
signal?.throwIfAborted();
|
|
17130
|
-
if (!/^[a-f0-9]{40}$/.test(
|
|
17389
|
+
if (!/^[a-f0-9]{40}$/.test(sha6))
|
|
17131
17390
|
throw new Error("Check requires an exact candidate SHA");
|
|
17132
17391
|
const gitDir = await worktreeGitDir(repoPath, worktree, signal);
|
|
17133
17392
|
const git3 = async (...args) => (await execa9(
|
|
@@ -17147,13 +17406,13 @@ async function fixedCheckSnapshot(repoPath, worktree, sha5, signal) {
|
|
|
17147
17406
|
killDescendants: true
|
|
17148
17407
|
}
|
|
17149
17408
|
)).stdout.trim();
|
|
17150
|
-
if (await git3("rev-parse", "HEAD") !==
|
|
17409
|
+
if (await git3("rev-parse", "HEAD") !== sha6)
|
|
17151
17410
|
throw new Error("Check worktree HEAD differs from the fixed candidate");
|
|
17152
17411
|
if (await git3("status", "--porcelain"))
|
|
17153
17412
|
throw new Error(
|
|
17154
17413
|
"Check worktree contains changes outside the fixed candidate"
|
|
17155
17414
|
);
|
|
17156
|
-
return { sha:
|
|
17415
|
+
return { sha: sha6, tree: await git3("rev-parse", `${sha6}^{tree}`) };
|
|
17157
17416
|
}
|
|
17158
17417
|
|
|
17159
17418
|
// src/runs/supervisor.ts
|
|
@@ -17228,21 +17487,21 @@ function createRunMasker(secrets) {
|
|
|
17228
17487
|
return cut;
|
|
17229
17488
|
};
|
|
17230
17489
|
const deep = (value) => {
|
|
17231
|
-
const
|
|
17490
|
+
const walk2 = (input) => {
|
|
17232
17491
|
if (typeof input === "string") return text4(input);
|
|
17233
|
-
if (Array.isArray(input)) return input.map(
|
|
17492
|
+
if (Array.isArray(input)) return input.map(walk2);
|
|
17234
17493
|
if (input && typeof input === "object" && Object.getPrototypeOf(input) === Object.prototype)
|
|
17235
|
-
return Object.fromEntries(Object.entries(input).map(([k, v2]) => [text4(k),
|
|
17494
|
+
return Object.fromEntries(Object.entries(input).map(([k, v2]) => [text4(k), walk2(v2)]));
|
|
17236
17495
|
return input;
|
|
17237
17496
|
};
|
|
17238
|
-
return
|
|
17497
|
+
return walk2(value);
|
|
17239
17498
|
};
|
|
17240
17499
|
const tail = (key2) => {
|
|
17241
17500
|
const held = pending.get(key2);
|
|
17242
17501
|
pending.delete(key2);
|
|
17243
17502
|
if (!held) return null;
|
|
17244
|
-
const
|
|
17245
|
-
const prefix = key2.slice(0,
|
|
17503
|
+
const sep4 = key2.indexOf(":");
|
|
17504
|
+
const prefix = key2.slice(0, sep4), id5 = key2.slice(sep4 + 1);
|
|
17246
17505
|
const masked = text4(held);
|
|
17247
17506
|
return prefix === "tool" ? { type: "tool-input-delta", toolCallId: id5, inputTextDelta: masked } : { type: DELTA_FOR_PREFIX[prefix], id: id5, delta: masked };
|
|
17248
17507
|
};
|
|
@@ -17301,23 +17560,23 @@ function createRunMasker(secrets) {
|
|
|
17301
17560
|
|
|
17302
17561
|
// src/runs/supervisor.ts
|
|
17303
17562
|
import { stdSerializers } from "pino";
|
|
17304
|
-
import { createHash as
|
|
17305
|
-
import { join as
|
|
17563
|
+
import { createHash as createHash13, randomUUID as randomUUID6 } from "node:crypto";
|
|
17564
|
+
import { join as join31, resolve as resolve14 } from "node:path";
|
|
17306
17565
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
17307
17566
|
import { execa as execa12 } from "execa";
|
|
17308
17567
|
|
|
17309
17568
|
// src/agents/checkpoint.ts
|
|
17310
17569
|
import { mkdtempSync as mkdtempSync9, rmSync as rmSync19, writeFileSync as writeFileSync9 } from "node:fs";
|
|
17311
17570
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
17312
|
-
import { join as
|
|
17571
|
+
import { join as join30 } from "node:path";
|
|
17313
17572
|
import { gunzipSync as gunzipSync2, gzipSync as gzipSync2 } from "node:zlib";
|
|
17314
17573
|
import { execa as execa11 } from "execa";
|
|
17315
17574
|
|
|
17316
17575
|
// src/coding-workspace/checkpoint.ts
|
|
17317
|
-
import { createHash as
|
|
17318
|
-
import { resolve as
|
|
17576
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
17577
|
+
import { resolve as resolve13 } from "node:path";
|
|
17319
17578
|
import { execa as execa10 } from "execa";
|
|
17320
|
-
var digest6 = (value) =>
|
|
17579
|
+
var digest6 = (value) => createHash12("sha256").update(value).digest("hex");
|
|
17321
17580
|
var oid = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
17322
17581
|
var MANIFEST_BYTES = 1536 * 1024;
|
|
17323
17582
|
var regular = (mode) => mode === null || mode === "100644" || mode === "100755";
|
|
@@ -17349,7 +17608,7 @@ async function captureCheckpointReview(input) {
|
|
|
17349
17608
|
const env = {
|
|
17350
17609
|
...buildChildEnv({}),
|
|
17351
17610
|
GIT_DIR: gitDir,
|
|
17352
|
-
GIT_COMMON_DIR:
|
|
17611
|
+
GIT_COMMON_DIR: resolve13(gitDir, "..", ".."),
|
|
17353
17612
|
GIT_WORK_TREE: input.worktree,
|
|
17354
17613
|
GIT_CONFIG_NOSYSTEM: "1",
|
|
17355
17614
|
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
@@ -17454,20 +17713,20 @@ async function captureCheckpointReview(input) {
|
|
|
17454
17713
|
return { ...file, binary: false, additions: 0, deletions: 0, fileVersion: digest6(diffFileVersionMaterial(input.repoId, revision2, file)) };
|
|
17455
17714
|
});
|
|
17456
17715
|
if (Buffer.byteLength(JSON.stringify(files2)) > MANIFEST_BYTES) return result([], [], "too_large");
|
|
17457
|
-
const wanted = [...new Set(files2.filter((file) => regular(file.oldMode) && regular(file.newMode) && [file.oldSize, file.newSize].every((size) => size === null || size <= WORKSPACE_DIFF_MAX_BLOB_BYTES)).flatMap((file) => [file.oldBlob, file.newBlob].filter((
|
|
17458
|
-
if (wanted.reduce((total,
|
|
17716
|
+
const wanted = [...new Set(files2.filter((file) => regular(file.oldMode) && regular(file.newMode) && [file.oldSize, file.newSize].every((size) => size === null || size <= WORKSPACE_DIFF_MAX_BLOB_BYTES)).flatMap((file) => [file.oldBlob, file.newBlob].filter((sha6) => sha6 !== null)))];
|
|
17717
|
+
if (wanted.reduce((total, sha6) => total + sizes.get(sha6), 0) > CHECKPOINT_REVIEW_MAX_PROOF_BYTES) return result([], [], "too_large");
|
|
17459
17718
|
const blobs = [];
|
|
17460
17719
|
if (wanted.length) {
|
|
17461
17720
|
exceeded = true;
|
|
17462
17721
|
const content = await git3(["cat-file", "--batch"], wanted.join("\n") + "\n", CHECKPOINT_REVIEW_MAX_PROOF_BYTES + wanted.length * 128);
|
|
17463
17722
|
exceeded = false;
|
|
17464
17723
|
let offset = 0;
|
|
17465
|
-
for (const
|
|
17724
|
+
for (const sha6 of wanted) {
|
|
17466
17725
|
signal.throwIfAborted();
|
|
17467
|
-
const end = content.indexOf(10, offset), size = sizes.get(
|
|
17468
|
-
if (end === -1 || content.subarray(offset, end).toString("ascii") !== `${
|
|
17726
|
+
const end = content.indexOf(10, offset), size = sizes.get(sha6);
|
|
17727
|
+
if (end === -1 || content.subarray(offset, end).toString("ascii") !== `${sha6} blob ${size}` || end + 1 + size >= content.length || content[end + 1 + size] !== 10) return result([], [], "missing_evidence");
|
|
17469
17728
|
const bytes = content.subarray(end + 1, end + 1 + size);
|
|
17470
|
-
blobs.push({ sha:
|
|
17729
|
+
blobs.push({ sha: sha6, base64: bytes.toString("base64") });
|
|
17471
17730
|
offset = end + 2 + size;
|
|
17472
17731
|
}
|
|
17473
17732
|
if (offset !== content.length) return result([], [], "missing_evidence");
|
|
@@ -17536,8 +17795,8 @@ async function takeCheckpoint(options) {
|
|
|
17536
17795
|
}
|
|
17537
17796
|
async function applyCheckpoint(options) {
|
|
17538
17797
|
const git3 = await pinnedGit(options.repoPath, options.worktree);
|
|
17539
|
-
const dir = mkdtempSync9(
|
|
17540
|
-
const file =
|
|
17798
|
+
const dir = mkdtempSync9(join30(tmpdir4(), "mikka-checkpoint-"));
|
|
17799
|
+
const file = join30(dir, "checkpoint.patch");
|
|
17541
17800
|
try {
|
|
17542
17801
|
const patch = gunzipSync2(Buffer.from(options.checkpoint.patch, "base64"));
|
|
17543
17802
|
if (!patch.length && options.checkpoint.files === 0) return true;
|
|
@@ -17853,12 +18112,12 @@ var MemoryServer = class {
|
|
|
17853
18112
|
this.check();
|
|
17854
18113
|
let pending = this.pendingCommands(deviceId, skip);
|
|
17855
18114
|
if (pending.length === 0 && waitSeconds > 0 && !signal?.aborted) {
|
|
17856
|
-
await new Promise((
|
|
17857
|
-
const timer = setTimeout(
|
|
17858
|
-
signal?.addEventListener("abort", () =>
|
|
18115
|
+
await new Promise((resolve20) => {
|
|
18116
|
+
const timer = setTimeout(resolve20, waitSeconds * 1e3);
|
|
18117
|
+
signal?.addEventListener("abort", () => resolve20(), { once: true });
|
|
17859
18118
|
this.wakeCommands.push(() => {
|
|
17860
18119
|
clearTimeout(timer);
|
|
17861
|
-
|
|
18120
|
+
resolve20();
|
|
17862
18121
|
});
|
|
17863
18122
|
});
|
|
17864
18123
|
this.check();
|
|
@@ -17990,6 +18249,7 @@ var RunSupervisor = class {
|
|
|
17990
18249
|
const masker = this.maskers.get(runId);
|
|
17991
18250
|
const checkpoint = taken?.checkpoint ? masker ? masker.checkpoint(taken.checkpoint) : taken.checkpoint : void 0;
|
|
17992
18251
|
if (checkpoint) await save(runId, checkpoint);
|
|
18252
|
+
if (checkpoint) await run3.drive?.push();
|
|
17993
18253
|
if (taken) {
|
|
17994
18254
|
run3.lastCheckpointTree = taken.tree;
|
|
17995
18255
|
run3.lastCheckpointHead = taken.head;
|
|
@@ -18017,6 +18277,7 @@ var RunSupervisor = class {
|
|
|
18017
18277
|
const accepted = runCheckpointReceiptSchema.safeParse(await save(id5, checkpoint2));
|
|
18018
18278
|
if (accepted.success && accepted.data.runId === id5) receipt = accepted.data;
|
|
18019
18279
|
}, Date.now(), true);
|
|
18280
|
+
if (!this.stopping) await run3.drive?.push();
|
|
18020
18281
|
const checkpoint = ready && receipt ? { checkpoint: "ready", checkpointTakenAt: receipt.takenAt } : { checkpoint: "unavailable" };
|
|
18021
18282
|
if (finishingComplete && run3.sessionExited && !this.stopping)
|
|
18022
18283
|
run3.safePoint = { session: "exited", observedAt: receipt?.takenAt ?? (/* @__PURE__ */ new Date()).toISOString(), ...checkpoint };
|
|
@@ -18329,7 +18590,7 @@ var RunSupervisor = class {
|
|
|
18329
18590
|
const entry = this.deps.journal.get(runId);
|
|
18330
18591
|
if (splitChatFiles(text4).files.length) {
|
|
18331
18592
|
if (!entry || !this.deps.downloadChatFile || !this.deps.adapterStateDir) throw Error("Run attachments unavailable");
|
|
18332
|
-
text4 = await materializeChatFiles(text4,
|
|
18593
|
+
text4 = await materializeChatFiles(text4, join31(this.deps.adapterStateDir, "inputs", runId), (id5) => this.deps.downloadChatFile(entry.assignment, id5, run3.abort.signal));
|
|
18333
18594
|
}
|
|
18334
18595
|
await run3.session.send(text4, mode);
|
|
18335
18596
|
}
|
|
@@ -18359,9 +18620,9 @@ var RunSupervisor = class {
|
|
|
18359
18620
|
run3.abort.abort();
|
|
18360
18621
|
}
|
|
18361
18622
|
let timer;
|
|
18362
|
-
const grace = new Promise((
|
|
18623
|
+
const grace = new Promise((resolve20) => {
|
|
18363
18624
|
timer = setTimeout(
|
|
18364
|
-
|
|
18625
|
+
resolve20,
|
|
18365
18626
|
this.deps.stopGraceMs ?? DEFAULT_STOP_GRACE_MS
|
|
18366
18627
|
);
|
|
18367
18628
|
});
|
|
@@ -18688,11 +18949,11 @@ var RunSupervisor = class {
|
|
|
18688
18949
|
if (configured.length === 0) return void 0;
|
|
18689
18950
|
const loaded = [];
|
|
18690
18951
|
if (this.deps.adapterStateDir) {
|
|
18691
|
-
const dir =
|
|
18952
|
+
const dir = join31(runPaths(this.deps.adapterStateDir, runId).runDir, PROFILE_SKILLS_DIR, PROFILE_SKILL_LOADS_DIR);
|
|
18692
18953
|
try {
|
|
18693
18954
|
for (const name of readdirSync8(dir).sort()) {
|
|
18694
18955
|
if (!name.endsWith(".json") || loaded.length >= configured.length) continue;
|
|
18695
|
-
const file =
|
|
18956
|
+
const file = join31(dir, name), meta = lstatSync11(file, { throwIfNoEntry: false });
|
|
18696
18957
|
if (!meta?.isFile() || meta.isSymbolicLink() || meta.nlink !== 1 || meta.size < 2 || meta.size > 4096) continue;
|
|
18697
18958
|
const receipt = profileSkillLoadReceiptSchema.safeParse(JSON.parse(readFileSync14(file, "utf8")));
|
|
18698
18959
|
if (!receipt.success || loaded.some((item) => item.id === receipt.data.id)) continue;
|
|
@@ -18836,7 +19097,7 @@ var RunSupervisor = class {
|
|
|
18836
19097
|
try {
|
|
18837
19098
|
return await withRunGitCredentials(
|
|
18838
19099
|
assignment,
|
|
18839
|
-
runPaths(this.deps.adapterStateDir ??
|
|
19100
|
+
runPaths(this.deps.adapterStateDir ?? join31(tmpdir5(), "mikka-run-state"), runId).privateDir,
|
|
18840
19101
|
(env) => this.deps.worktrees.fetchBranch(
|
|
18841
19102
|
repo.path,
|
|
18842
19103
|
repo.push?.remote ?? "origin",
|
|
@@ -18986,8 +19247,8 @@ var RunSupervisor = class {
|
|
|
18986
19247
|
});
|
|
18987
19248
|
if (readAbort) {
|
|
18988
19249
|
let allowEffects, refuseEffects;
|
|
18989
|
-
const entryReady = new Promise((
|
|
18990
|
-
allowEffects =
|
|
19250
|
+
const entryReady = new Promise((resolve20, reject) => {
|
|
19251
|
+
allowEffects = resolve20;
|
|
18991
19252
|
refuseEffects = reject;
|
|
18992
19253
|
});
|
|
18993
19254
|
const authorized = Promise.all([policyReady, entryReady]);
|
|
@@ -19225,11 +19486,17 @@ var RunSupervisor = class {
|
|
|
19225
19486
|
throw error;
|
|
19226
19487
|
}
|
|
19227
19488
|
}
|
|
19228
|
-
|
|
19489
|
+
if (!run3.drive && this.deps.prepareRunDrive) {
|
|
19490
|
+
run3.drive = await this.deps.prepareRunDrive(assignment, run3.abort.signal).catch(() => void 0);
|
|
19491
|
+
await run3.drive?.pull();
|
|
19492
|
+
}
|
|
19493
|
+
const driveBrief = run3.drive?.folders.length ? `Shared Drive folders on this machine (synced at checkpoints and when you finish; a version conflict keeps your copy beside the newer one):
|
|
19494
|
+
${run3.drive.folders.map((folder) => `- ${folder.scope}: ${folder.path}${folder.write ? "" : " (read-only)"}`).join("\n")}` : void 0;
|
|
19495
|
+
let prompt = [assignment.prompt, run3.secretBridge?.instructions, driveBrief].filter(Boolean).join("\n\n");
|
|
19229
19496
|
let followUp = assignment.followUp;
|
|
19230
19497
|
if (splitChatFiles(prompt).files.length || followUp && splitChatFiles(followUp).files.length) {
|
|
19231
19498
|
if (!this.deps.downloadChatFile || !this.deps.adapterStateDir) throw Error("Run attachments unavailable");
|
|
19232
|
-
const directory =
|
|
19499
|
+
const directory = join31(this.deps.adapterStateDir, "inputs", runId);
|
|
19233
19500
|
const download2 = (id5) => this.deps.downloadChatFile(assignment, id5, run3.abort.signal);
|
|
19234
19501
|
prompt = await materializeChatFiles(prompt, directory, download2);
|
|
19235
19502
|
if (followUp) followUp = await materializeChatFiles(followUp, directory, download2);
|
|
@@ -19242,7 +19509,7 @@ var RunSupervisor = class {
|
|
|
19242
19509
|
gitWritePaths: await worktreeGitWritePaths(repo.path, worktree, runId)
|
|
19243
19510
|
};
|
|
19244
19511
|
const resuming = entry.sessionId !== null && adapter.capabilities.supportsResume;
|
|
19245
|
-
const inEarlierWorktree = continued !== null || entry.worktree !== null &&
|
|
19512
|
+
const inEarlierWorktree = continued !== null || entry.worktree !== null && resolve14(entry.worktree) !== resolve14(this.deps.worktrees.pathFor(runId));
|
|
19246
19513
|
const continueSession = !resuming && assignment.resumeSessionId && assignment.continuesRunId && inEarlierWorktree && adapter.capabilities.supportsResume ? {
|
|
19247
19514
|
sessionId: assignment.resumeSessionId,
|
|
19248
19515
|
runId: assignment.continuesRunId,
|
|
@@ -19251,13 +19518,13 @@ var RunSupervisor = class {
|
|
|
19251
19518
|
if (assignment.requireSessionResume && (!assignment.resumeSessionId || !assignment.continuesRunId || !adapter.capabilities.supportsResume || !resuming && !continueSession || resuming && entry.sessionId !== assignment.resumeSessionId))
|
|
19252
19519
|
throw new Error("factory_question_session_resume_required");
|
|
19253
19520
|
const benchmark = assignment.benchmark;
|
|
19254
|
-
const policyDigest = assignment.skillReceipt ?
|
|
19521
|
+
const policyDigest = assignment.skillReceipt ? createHash13("sha256").update(runPolicyDigestInput(assignment.policy)).digest("hex") : void 0;
|
|
19255
19522
|
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");
|
|
19256
19523
|
let fixtureDigest;
|
|
19257
19524
|
if (benchmark) {
|
|
19258
19525
|
if (runPolicy(assignment.policy).readOnly !== true) throw new Error("Benchmark fixture must be read-only");
|
|
19259
19526
|
const fixed = await fixedCheckSnapshot(repo.path, worktree, benchmark.sourceCommit);
|
|
19260
|
-
fixtureDigest =
|
|
19527
|
+
fixtureDigest = createHash13("sha256").update(fixed.sha).digest("hex");
|
|
19261
19528
|
if (fixtureDigest !== benchmark.fixtureDigest) throw new Error("Frozen benchmark fixture digest mismatch");
|
|
19262
19529
|
}
|
|
19263
19530
|
const previousMount = entry.skillMount;
|
|
@@ -19298,7 +19565,7 @@ var RunSupervisor = class {
|
|
|
19298
19565
|
if (!this.deps.adapterStateDir || assignment.harness === "mock" || !session.sessionId || resuming && session.sessionId !== entry.sessionId || assignment.requireSessionResume && session.sessionId !== assignment.resumeSessionId)
|
|
19299
19566
|
throw new Error("Skill mount requires the actual original harness session");
|
|
19300
19567
|
verifySkillAssignment(assignment);
|
|
19301
|
-
const file =
|
|
19568
|
+
const file = join31(
|
|
19302
19569
|
runPaths(this.deps.adapterStateDir, runId).runDir,
|
|
19303
19570
|
SKILLS_DIR,
|
|
19304
19571
|
skillSlug(assignment.skills[0].name),
|
|
@@ -19416,7 +19683,7 @@ var RunSupervisor = class {
|
|
|
19416
19683
|
try {
|
|
19417
19684
|
if (assignment.benchmark && !run3.cancelRequested) {
|
|
19418
19685
|
const fixed = await fixedCheckSnapshot(repo.path, worktree, assignment.benchmark.sourceCommit, finishingSignal);
|
|
19419
|
-
if (
|
|
19686
|
+
if (createHash13("sha256").update(fixed.sha).digest("hex") !== assignment.benchmark.fixtureDigest)
|
|
19420
19687
|
throw new Error("Benchmark fixture changed during model execution");
|
|
19421
19688
|
}
|
|
19422
19689
|
outcome = await this.report(runId, worktree, repo, assignment, stopReason, error, event.report, finishingSignal);
|
|
@@ -19500,10 +19767,10 @@ function trackParts(open5, chunk) {
|
|
|
19500
19767
|
}
|
|
19501
19768
|
var ABORTED = /* @__PURE__ */ Symbol("aborted");
|
|
19502
19769
|
function abortPromise(signal) {
|
|
19503
|
-
return new Promise((
|
|
19504
|
-
if (signal.aborted)
|
|
19770
|
+
return new Promise((resolve20) => {
|
|
19771
|
+
if (signal.aborted) resolve20(ABORTED);
|
|
19505
19772
|
else
|
|
19506
|
-
signal.addEventListener("abort", () =>
|
|
19773
|
+
signal.addEventListener("abort", () => resolve20(ABORTED), { once: true });
|
|
19507
19774
|
});
|
|
19508
19775
|
}
|
|
19509
19776
|
function pickAgentReport(agent) {
|
|
@@ -19634,7 +19901,7 @@ var DeviceGatewayClosedError = class extends Error {
|
|
|
19634
19901
|
function runDeviceGateway(socket, options) {
|
|
19635
19902
|
const pingMs = options.pingMs ?? DEVICE_GATEWAY_PING_MS;
|
|
19636
19903
|
const silenceMs = options.silenceMs ?? DEVICE_GATEWAY_SILENCE_MS;
|
|
19637
|
-
return new Promise((
|
|
19904
|
+
return new Promise((resolve20, reject) => {
|
|
19638
19905
|
let settled = false;
|
|
19639
19906
|
let opened = false;
|
|
19640
19907
|
let pulling = false;
|
|
@@ -19653,7 +19920,7 @@ function runDeviceGateway(socket, options) {
|
|
|
19653
19920
|
} catch {
|
|
19654
19921
|
}
|
|
19655
19922
|
if (error && !options.signal.aborted) reject(error);
|
|
19656
|
-
else
|
|
19923
|
+
else resolve20();
|
|
19657
19924
|
};
|
|
19658
19925
|
const work = () => {
|
|
19659
19926
|
if (settled) return;
|
|
@@ -19801,11 +20068,11 @@ var DeviceSession = class {
|
|
|
19801
20068
|
}
|
|
19802
20069
|
/** A redial backoff, not a poll: it ends early on `wake` or `stop`. */
|
|
19803
20070
|
pause(ms2) {
|
|
19804
|
-
return new Promise((
|
|
20071
|
+
return new Promise((resolve20) => {
|
|
19805
20072
|
const done = () => {
|
|
19806
20073
|
clearTimeout(timer);
|
|
19807
20074
|
this.wakeUp = null;
|
|
19808
|
-
|
|
20075
|
+
resolve20();
|
|
19809
20076
|
};
|
|
19810
20077
|
const timer = setTimeout(done, ms2);
|
|
19811
20078
|
this.wakeUp = done;
|
|
@@ -19816,20 +20083,20 @@ var DeviceSession = class {
|
|
|
19816
20083
|
|
|
19817
20084
|
// src/coding-workspace/files.ts
|
|
19818
20085
|
import { constants as constants7 } from "node:fs";
|
|
19819
|
-
import { open as open2, readFile as
|
|
20086
|
+
import { open as open2, readFile as readFile6, realpath as realpath2 } from "node:fs/promises";
|
|
19820
20087
|
import { execFile as execFile7 } from "node:child_process";
|
|
19821
20088
|
import { promisify as promisify7 } from "node:util";
|
|
19822
|
-
import { createHash as
|
|
19823
|
-
import { extname, resolve as
|
|
20089
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
20090
|
+
import { extname as extname2, resolve as resolve15 } from "node:path";
|
|
19824
20091
|
var execute2 = promisify7(execFile7);
|
|
19825
|
-
var hash = (value) =>
|
|
20092
|
+
var hash = (value) => createHash14("sha256").update(value).digest("hex");
|
|
19826
20093
|
var denied = () => new CodingWorkspaceError("workspace_path_unavailable");
|
|
19827
20094
|
function isFileReadRequest(request2) {
|
|
19828
20095
|
return request2.kind === "file" || request2.kind === "tree" || request2.kind === "search" || request2.kind === "context";
|
|
19829
20096
|
}
|
|
19830
20097
|
var safeDotfiles2 = /* @__PURE__ */ new Set([".gitignore", ".gitattributes", ".editorconfig", ".prettierignore", ".prettierrc", ".eslintrc", ".dockerignore"]);
|
|
19831
20098
|
async function mountId(handle) {
|
|
19832
|
-
const id5 = /^mnt_id:\s*(\d+)$/m.exec(await
|
|
20099
|
+
const id5 = /^mnt_id:\s*(\d+)$/m.exec(await readFile6(`/proc/self/fdinfo/${handle.fd}`, "utf8"))?.[1];
|
|
19833
20100
|
if (!id5) throw new CodingWorkspaceError("workspace_unsupported");
|
|
19834
20101
|
return id5;
|
|
19835
20102
|
}
|
|
@@ -19869,9 +20136,9 @@ async function safeFile(root, path3, use) {
|
|
|
19869
20136
|
parent = handle;
|
|
19870
20137
|
}
|
|
19871
20138
|
const selected = await realpath2(`/proc/self/fd/${parent.fd}`);
|
|
19872
|
-
if (selected !==
|
|
20139
|
+
if (selected !== resolve15(root.path, path3) || await realpath2(root.gitPath) !== root.path) throw denied();
|
|
19873
20140
|
const result = await use(parent);
|
|
19874
|
-
if (await realpath2(`/proc/self/fd/${parent.fd}`) !== selected || await realpath2(
|
|
20141
|
+
if (await realpath2(`/proc/self/fd/${parent.fd}`) !== selected || await realpath2(resolve15(root.path, path3)) !== selected || await realpath2(root.gitPath) !== root.path) throw new CodingWorkspaceError("workspace_version_conflict");
|
|
19875
20142
|
return result;
|
|
19876
20143
|
} catch (cause) {
|
|
19877
20144
|
if (cause instanceof CodingWorkspaceError) throw cause;
|
|
@@ -19883,7 +20150,7 @@ async function safeFile(root, path3, use) {
|
|
|
19883
20150
|
var textExtensions = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".json", ".jsonc", ".md", ".mdx", ".txt", ".csv", ".tsv", ".yaml", ".yml", ".toml", ".xml", ".html", ".css", ".scss", ".sass", ".less", ".sql", ".py", ".pyi", ".go", ".mod", ".sum", ".rs", ".java", ".kt", ".kts", ".swift", ".c", ".h", ".cpp", ".hpp", ".cs", ".rb", ".php", ".sh", ".bash", ".zsh", ".fish", ".ps1", ".bat", ".cmd", ".vue", ".svelte", ".graphql", ".gql", ".proto", ".prisma", ".ex", ".exs", ".erl", ".hrl", ".clj", ".scala", ".r", ".rmd", ".jl", ".lua", ".pl", ".pm", ".dart", ".lock", ".ini", ".conf", ".cfg", ".rst", ".adoc", ".tex"]);
|
|
19884
20151
|
var textNames = /^(?:Dockerfile(?:\..*)?|Containerfile|Makefile|CMakeLists\.txt|README(?:\..*)?|LICENSE(?:\..*)?|NOTICE|Procfile|Gemfile|Rakefile|Justfile)$/i;
|
|
19885
20152
|
function isText(path3) {
|
|
19886
|
-
return textExtensions.has(
|
|
20153
|
+
return textExtensions.has(extname2(path3).toLowerCase()) || textNames.test(path3.split("/").at(-1)) || safeDotfiles2.has(path3.split("/").at(-1));
|
|
19887
20154
|
}
|
|
19888
20155
|
function revision(headSha2, baseSha, content) {
|
|
19889
20156
|
return { source: "working", headSha: headSha2, baseSha: baseSha && /^[a-f0-9]{40,64}$/.test(baseSha) ? baseSha : null, version: hash(content) };
|
|
@@ -19910,7 +20177,7 @@ async function readWorkspaceReceipt(command, entry) {
|
|
|
19910
20177
|
const remote = entry.assignment.remoteUrl ?? entry.assignment.expectedRepoRemote;
|
|
19911
20178
|
if (!remote || remoteKey(remote) !== identity.repositoryKey) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
19912
20179
|
if (process.platform !== "linux") throw new CodingWorkspaceError("workspace_unsupported");
|
|
19913
|
-
const path3 =
|
|
20180
|
+
const path3 = resolve15(entry.worktree);
|
|
19914
20181
|
if (await realpath2(path3) !== path3) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
19915
20182
|
directory = await open2(path3, constants7.O_RDONLY | constants7.O_DIRECTORY | constants7.O_NOFOLLOW);
|
|
19916
20183
|
const root = {
|
|
@@ -19938,7 +20205,7 @@ async function readWorkspaceReceipt(command, entry) {
|
|
|
19938
20205
|
kind: "file",
|
|
19939
20206
|
path: request3.path,
|
|
19940
20207
|
size,
|
|
19941
|
-
language:
|
|
20208
|
+
language: extname2(request3.path).slice(1) || null,
|
|
19942
20209
|
revision: revision(headSha2, entry.baseCommit, `${headSha2}:${request3.path}:${before.ino}:${before.mtimeNs}:${before.ctimeNs}:${before.size}`),
|
|
19943
20210
|
content: null,
|
|
19944
20211
|
contentSha256: null,
|
|
@@ -20070,9 +20337,9 @@ async function readWorkspaceReceipt(command, entry) {
|
|
|
20070
20337
|
|
|
20071
20338
|
// src/coding-workspace/diff.ts
|
|
20072
20339
|
import { constants as constants8 } from "node:fs";
|
|
20073
|
-
import { open as open3, realpath as realpath3, mkdtemp as mkdtemp2, mkdir as
|
|
20074
|
-
import { createHash as
|
|
20075
|
-
import { resolve as
|
|
20340
|
+
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";
|
|
20341
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
20342
|
+
import { resolve as resolve16, dirname as dirname16, join as join32, posix } from "node:path";
|
|
20076
20343
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
20077
20344
|
import { execa as execa13 } from "execa";
|
|
20078
20345
|
|
|
@@ -20141,7 +20408,7 @@ var CRLFCleaner = class {
|
|
|
20141
20408
|
};
|
|
20142
20409
|
|
|
20143
20410
|
// src/coding-workspace/diff.ts
|
|
20144
|
-
var digest7 = (value) =>
|
|
20411
|
+
var digest7 = (value) => createHash15("sha256").update(value).digest("hex");
|
|
20145
20412
|
var fenceMode = (mode) => mode === "100644" || mode === "100755" || mode === "120000" || mode === "160000" ? mode : null;
|
|
20146
20413
|
var oid2 = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
20147
20414
|
var MAX_SCAN_BYTES = 64 * 1024 * 1024;
|
|
@@ -20166,7 +20433,7 @@ async function gitFor(repoPath, root, signal) {
|
|
|
20166
20433
|
const env = {
|
|
20167
20434
|
...buildChildEnv({}),
|
|
20168
20435
|
GIT_DIR: gitDir,
|
|
20169
|
-
GIT_COMMON_DIR:
|
|
20436
|
+
GIT_COMMON_DIR: resolve16(gitDir, "..", ".."),
|
|
20170
20437
|
// cwd is resolved while the parent's FD is still open. The child does not
|
|
20171
20438
|
// inherit that numeric descriptor, so its work tree must be relative to cwd.
|
|
20172
20439
|
GIT_WORK_TREE: ".",
|
|
@@ -20231,7 +20498,7 @@ async function treeFiles(git3, commit) {
|
|
|
20231
20498
|
}
|
|
20232
20499
|
async function existsWithoutReading(path3) {
|
|
20233
20500
|
try {
|
|
20234
|
-
await
|
|
20501
|
+
await lstat5(path3);
|
|
20235
20502
|
return true;
|
|
20236
20503
|
} catch (error) {
|
|
20237
20504
|
if (missing(error)) return false;
|
|
@@ -20250,12 +20517,12 @@ async function conversionSettings(git3) {
|
|
|
20250
20517
|
const host = buildChildEnv({});
|
|
20251
20518
|
const defaults = ["/etc/gitattributes", "/usr/etc/gitattributes", "/usr/local/etc/gitattributes"];
|
|
20252
20519
|
if (!external) {
|
|
20253
|
-
const configHome = host.XDG_CONFIG_HOME || (host.HOME ?
|
|
20254
|
-
if (configHome) defaults.push(
|
|
20520
|
+
const configHome = host.XDG_CONFIG_HOME || (host.HOME ? join32(host.HOME, ".config") : void 0);
|
|
20521
|
+
if (configHome) defaults.push(join32(configHome, "git", "attributes"));
|
|
20255
20522
|
}
|
|
20256
|
-
const info =
|
|
20523
|
+
const info = join32(git3.commonDir, "info");
|
|
20257
20524
|
if (await existsWithoutReading(info)) {
|
|
20258
|
-
if (!(await
|
|
20525
|
+
if (!(await lstat5(info)).isDirectory() || await existsWithoutReading(join32(info, "attributes")))
|
|
20259
20526
|
throw new CodingWorkspaceError("workspace_unsupported");
|
|
20260
20527
|
}
|
|
20261
20528
|
for (const path3 of defaults) if (await existsWithoutReading(path3)) throw new CodingWorkspaceError("workspace_unsupported");
|
|
@@ -20301,11 +20568,11 @@ async function workingConversion(git3, root, paths, head, signal, budget) {
|
|
|
20301
20568
|
throw new CodingWorkspaceError("workspace_unsupported");
|
|
20302
20569
|
attributeBytes.set(path3, bytes);
|
|
20303
20570
|
}
|
|
20304
|
-
const directory = await mkdtemp2(
|
|
20571
|
+
const directory = await mkdtemp2(join32(tmpdir6(), "mikka-diff-attributes-"));
|
|
20305
20572
|
const actions = /* @__PURE__ */ new Map();
|
|
20306
20573
|
try {
|
|
20307
|
-
const gitDir =
|
|
20308
|
-
await
|
|
20574
|
+
const gitDir = join32(directory, "git"), worktree = join32(directory, "worktree");
|
|
20575
|
+
await mkdir5(worktree, { mode: 448 });
|
|
20309
20576
|
const env = {
|
|
20310
20577
|
...buildChildEnv({}),
|
|
20311
20578
|
GIT_CONFIG_NOSYSTEM: "1",
|
|
@@ -20324,9 +20591,9 @@ async function workingConversion(git3, root, paths, head, signal, budget) {
|
|
|
20324
20591
|
killDescendants: true
|
|
20325
20592
|
});
|
|
20326
20593
|
for (const [path3, bytes] of attributeBytes) {
|
|
20327
|
-
const target =
|
|
20328
|
-
await
|
|
20329
|
-
await
|
|
20594
|
+
const target = join32(worktree, path3);
|
|
20595
|
+
await mkdir5(dirname16(target), { recursive: true, mode: 448 });
|
|
20596
|
+
await writeFile4(target, bytes, { mode: 384, flag: "wx" });
|
|
20330
20597
|
}
|
|
20331
20598
|
const attributes = ["text", "eol", "crlf", "filter", "working-tree-encoding", "ident"];
|
|
20332
20599
|
const allowedPaths = new Set(paths);
|
|
@@ -20367,7 +20634,7 @@ async function workingConversion(git3, root, paths, head, signal, budget) {
|
|
|
20367
20634
|
}
|
|
20368
20635
|
for (const path3 of paths) actions.set(path3, cleanAction(values.get(path3), settings.autoCRLF));
|
|
20369
20636
|
} finally {
|
|
20370
|
-
await
|
|
20637
|
+
await rm4(directory, { recursive: true, force: true });
|
|
20371
20638
|
}
|
|
20372
20639
|
return {
|
|
20373
20640
|
index,
|
|
@@ -20407,7 +20674,7 @@ async function currentFile(root, path3, head, budget, signal, conversion, git3)
|
|
|
20407
20674
|
budget.bytes += size;
|
|
20408
20675
|
if (budget.bytes > MAX_SCAN_BYTES) throw new CodingWorkspaceError("workspace_limit_exceeded");
|
|
20409
20676
|
const algorithm = head.length === 64 ? "sha256" : "sha1";
|
|
20410
|
-
const hasher =
|
|
20677
|
+
const hasher = createHash15(algorithm).update(`blob ${size}\0`), stats = new GitTextStats();
|
|
20411
20678
|
const bytes = size <= WORKSPACE_DIFF_MAX_BLOB_BYTES ? Buffer.alloc(size) : null;
|
|
20412
20679
|
const chunk = Buffer.alloc(64 * 1024);
|
|
20413
20680
|
let offset = 0;
|
|
@@ -20447,7 +20714,7 @@ async function currentFile(root, path3, head, budget, signal, conversion, git3)
|
|
|
20447
20714
|
let blob = rawBlob, cleanSize = size;
|
|
20448
20715
|
if (normalize) {
|
|
20449
20716
|
cleanSize -= stats.crlf;
|
|
20450
|
-
const cleaned =
|
|
20717
|
+
const cleaned = createHash15(algorithm).update(`blob ${cleanSize}\0`), cleaner = new CRLFCleaner();
|
|
20451
20718
|
if (bytes) cleaned.update(cleaner.push(bytes));
|
|
20452
20719
|
else {
|
|
20453
20720
|
budget.bytes += size;
|
|
@@ -20590,7 +20857,7 @@ async function readWorkspaceDiffReceipt(command, entry, repoPath) {
|
|
|
20590
20857
|
if (!entry?.worktree || entry.assignment.runId !== identity.runId || entry.assignment.repoId !== identity.repoId || entry.assignment.deviceId !== identity.deviceId || remoteKey(entry.assignment.remoteUrl ?? entry.assignment.expectedRepoRemote ?? "") !== identity.repositoryKey)
|
|
20591
20858
|
throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20592
20859
|
if (process.platform !== "linux") throw new CodingWorkspaceError("workspace_unsupported");
|
|
20593
|
-
const path3 =
|
|
20860
|
+
const path3 = resolve16(entry.worktree);
|
|
20594
20861
|
if (await realpath3(path3) !== path3) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20595
20862
|
directory = await open3(path3, constants8.O_RDONLY | constants8.O_DIRECTORY | constants8.O_NOFOLLOW);
|
|
20596
20863
|
const root = {
|
|
@@ -20637,8 +20904,8 @@ async function readWorkspaceDiffReceipt(command, entry, repoPath) {
|
|
|
20637
20904
|
if (value.conversion) await verifyConversion(git3, root, value.conversion);
|
|
20638
20905
|
if (Date.parse(expiresAt) <= Date.now()) throw new CodingWorkspaceError("workspace_request_expired");
|
|
20639
20906
|
if (value.revision.source === "working" && (await git3(["rev-parse", "--verify", "HEAD"])).toString().trim() !== value.revision.headSha || await realpath3(root.gitPath) !== root.path) throw new CodingWorkspaceError("workspace_version_conflict");
|
|
20640
|
-
return { result: { ...result, format: "text" }, files: [], blobs: [...blobs].map(([
|
|
20641
|
-
sha:
|
|
20907
|
+
return { result: { ...result, format: "text" }, files: [], blobs: [...blobs].map(([sha6, proof]) => ({
|
|
20908
|
+
sha: sha6,
|
|
20642
20909
|
base64: proof.bytes.toString("base64"),
|
|
20643
20910
|
...proof.rawSha ? { clean: "crlf_to_lf", rawSha: proof.rawSha } : {}
|
|
20644
20911
|
})) };
|
|
@@ -20660,7 +20927,7 @@ async function readWorkspaceRevertPreview(command, entry, repoPath) {
|
|
|
20660
20927
|
if (!entry?.worktree || entry.assignment.runId !== identity.runId || entry.assignment.repoId !== identity.repoId || entry.assignment.deviceId !== identity.deviceId || remoteKey(entry.assignment.remoteUrl ?? entry.assignment.expectedRepoRemote ?? "") !== identity.repositoryKey)
|
|
20661
20928
|
throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20662
20929
|
if (process.platform !== "linux") throw new CodingWorkspaceError("workspace_unsupported");
|
|
20663
|
-
const path3 =
|
|
20930
|
+
const path3 = resolve16(entry.worktree);
|
|
20664
20931
|
if (await realpath3(path3) !== path3) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20665
20932
|
directory = await open3(path3, constants8.O_RDONLY | constants8.O_DIRECTORY | constants8.O_NOFOLLOW);
|
|
20666
20933
|
const root = {
|
|
@@ -20730,9 +20997,9 @@ async function readWorkspaceRevertPreview(command, entry, repoPath) {
|
|
|
20730
20997
|
|
|
20731
20998
|
// src/coding-workspace/git.ts
|
|
20732
20999
|
import { constants as constants9 } from "node:fs";
|
|
20733
|
-
import { lstat as
|
|
20734
|
-
import { createHash as
|
|
20735
|
-
import { join as
|
|
21000
|
+
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";
|
|
21001
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
21002
|
+
import { join as join33, resolve as resolve17 } from "node:path";
|
|
20736
21003
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
20737
21004
|
import { execa as execa14 } from "execa";
|
|
20738
21005
|
|
|
@@ -20835,23 +21102,23 @@ function parseGitLog(output, options) {
|
|
|
20835
21102
|
if (fields.length % 7 !== 0) throw new Error("log_parse");
|
|
20836
21103
|
const commits = [];
|
|
20837
21104
|
for (let offset = 0; offset < fields.length; offset += 7) {
|
|
20838
|
-
const [
|
|
20839
|
-
if (!
|
|
21105
|
+
const [sha6, parents, authorName, authorEmail, authoredAt, committedAt, subject] = fields.slice(offset, offset + 7);
|
|
21106
|
+
if (!sha6 || !oid3.test(sha6)) throw new Error("log_parse");
|
|
20840
21107
|
const time = (value) => {
|
|
20841
21108
|
const parsed = new Date(value ?? "");
|
|
20842
21109
|
if (!Number.isFinite(parsed.getTime())) throw new Error("log_parse");
|
|
20843
21110
|
return parsed.toISOString();
|
|
20844
21111
|
};
|
|
20845
21112
|
commits.push({
|
|
20846
|
-
sha:
|
|
21113
|
+
sha: sha6,
|
|
20847
21114
|
parents: parents ? parents.split(" ").filter(Boolean) : [],
|
|
20848
21115
|
authorName: (authorName ?? "").slice(0, 200),
|
|
20849
21116
|
authorEmail: (authorEmail ?? "").slice(0, 320),
|
|
20850
21117
|
authoredAt: time(authoredAt),
|
|
20851
21118
|
committedAt: time(committedAt),
|
|
20852
21119
|
subject: (subject ?? "").slice(0, 1e3),
|
|
20853
|
-
head:
|
|
20854
|
-
base: options.baseSha !== null &&
|
|
21120
|
+
head: sha6 === options.headSha,
|
|
21121
|
+
base: options.baseSha !== null && sha6 === options.baseSha
|
|
20855
21122
|
});
|
|
20856
21123
|
}
|
|
20857
21124
|
return commits;
|
|
@@ -20866,7 +21133,7 @@ function parseHistoryCursor(cursor, headSha2) {
|
|
|
20866
21133
|
var historyCursor = (headSha2, offset) => `${headSha2}:${offset}`;
|
|
20867
21134
|
|
|
20868
21135
|
// src/coding-workspace/git.ts
|
|
20869
|
-
var digest8 = (value) =>
|
|
21136
|
+
var digest8 = (value) => createHash16("sha256").update(value).digest("hex");
|
|
20870
21137
|
var oid4 = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
20871
21138
|
var STATUS_BYTES = 8 * 1024 * 1024;
|
|
20872
21139
|
var STATUS_SCAN_BYTES = 16 * 1024 * 1024;
|
|
@@ -20888,7 +21155,7 @@ async function openPinnedRoot(command, entry) {
|
|
|
20888
21155
|
if (!entry?.worktree || entry.assignment.runId !== identity.runId || entry.assignment.repoId !== identity.repoId || entry.assignment.deviceId !== identity.deviceId || remoteKey(entry.assignment.remoteUrl ?? entry.assignment.expectedRepoRemote ?? "") !== identity.repositoryKey)
|
|
20889
21156
|
throw unavailable4();
|
|
20890
21157
|
if (process.platform !== "linux") throw new CodingWorkspaceError("workspace_unsupported");
|
|
20891
|
-
const path3 =
|
|
21158
|
+
const path3 = resolve17(entry.worktree);
|
|
20892
21159
|
if (await realpath4(path3) !== path3) throw unavailable4();
|
|
20893
21160
|
const directory = await open4(path3, constants9.O_RDONLY | constants9.O_DIRECTORY | constants9.O_NOFOLLOW);
|
|
20894
21161
|
try {
|
|
@@ -20993,7 +21260,7 @@ async function deletePinnedFile(root, path3, expectedFence) {
|
|
|
20993
21260
|
const { parent, name, parents } = await openParent(root, path3);
|
|
20994
21261
|
try {
|
|
20995
21262
|
const targetPath = `/proc/self/fd/${parent.fd}/${name}`;
|
|
20996
|
-
const stat3 = await
|
|
21263
|
+
const stat3 = await lstat6(targetPath, { bigint: true }).catch((error) => {
|
|
20997
21264
|
if (!missing(error)) throw error;
|
|
20998
21265
|
return null;
|
|
20999
21266
|
});
|
|
@@ -21328,15 +21595,15 @@ function runGit(cwd, args, env, signal, maximum = 8 * 1024 * 1024) {
|
|
|
21328
21595
|
}
|
|
21329
21596
|
async function readTempFile(worktree, path3) {
|
|
21330
21597
|
if (!visibleWorkspacePath(path3)) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
21331
|
-
const full =
|
|
21598
|
+
const full = join33(worktree, ...path3.split("/"));
|
|
21332
21599
|
if (!full.startsWith(`${worktree}/`)) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
21333
21600
|
try {
|
|
21334
|
-
const stat3 = await
|
|
21601
|
+
const stat3 = await lstat6(full);
|
|
21335
21602
|
if (stat3.isSymbolicLink()) return { exists: true, bytes: null, mode: null, reason: "unavailable" };
|
|
21336
21603
|
if (stat3.isDirectory()) return { exists: true, bytes: null, mode: null, reason: "submodule" };
|
|
21337
21604
|
if (!stat3.isFile()) return { exists: true, bytes: null, mode: null, reason: "unavailable" };
|
|
21338
21605
|
if (stat3.size > RESTORE_FILE_BYTES) return { exists: true, bytes: null, mode: null, reason: "binary" };
|
|
21339
|
-
return { exists: true, bytes: await
|
|
21606
|
+
return { exists: true, bytes: await readFile7(full), mode: stat3.mode & 73 ? "100755" : "100644", reason: null };
|
|
21340
21607
|
} catch (error) {
|
|
21341
21608
|
if (missing(error)) return { exists: false, bytes: null, mode: null, reason: null };
|
|
21342
21609
|
throw error;
|
|
@@ -21349,10 +21616,10 @@ async function dryRunCheckpoint(git3, root, identity, statusBase, patchBase, pat
|
|
|
21349
21616
|
} catch (error) {
|
|
21350
21617
|
throw new CodingWorkspaceError("workspace_unsupported", { cause: error });
|
|
21351
21618
|
}
|
|
21352
|
-
const parent = await mkdtemp3(
|
|
21353
|
-
const worktree =
|
|
21619
|
+
const parent = await mkdtemp3(join33(tmpdir7(), "mikka-git-restore-"));
|
|
21620
|
+
const worktree = join33(parent, "wt"), patchFile = join33(parent, "checkpoint.patch");
|
|
21354
21621
|
try {
|
|
21355
|
-
await
|
|
21622
|
+
await writeFile5(patchFile, patch, { mode: 384 });
|
|
21356
21623
|
await runGit(git3.commonDir, ["worktree", "add", "--detach", "--quiet", worktree, head], commonEnv(git3), signal);
|
|
21357
21624
|
let applied = true;
|
|
21358
21625
|
try {
|
|
@@ -21428,7 +21695,7 @@ async function dryRunCheckpoint(git3, root, identity, statusBase, patchBase, pat
|
|
|
21428
21695
|
await runGit(git3.commonDir, ["worktree", "remove", "--force", worktree], commonEnv(git3), AbortSignal.timeout(5e3));
|
|
21429
21696
|
} catch {
|
|
21430
21697
|
}
|
|
21431
|
-
await
|
|
21698
|
+
await rm5(parent, { recursive: true, force: true });
|
|
21432
21699
|
}
|
|
21433
21700
|
}
|
|
21434
21701
|
function checkpointVersion(request2, plan) {
|
|
@@ -21630,9 +21897,9 @@ async function handleWorkspaceGitRequest(command, entry, repoPath) {
|
|
|
21630
21897
|
}
|
|
21631
21898
|
|
|
21632
21899
|
// src/repositories.ts
|
|
21633
|
-
import { createHash as
|
|
21900
|
+
import { createHash as createHash17, randomUUID as randomUUID7 } from "node:crypto";
|
|
21634
21901
|
import { existsSync as existsSync7, lstatSync as lstatSync12, mkdirSync as mkdirSync17, readdirSync as readdirSync9, realpathSync as realpathSync13, renameSync as renameSync5, rmSync as rmSync20 } from "node:fs";
|
|
21635
|
-
import { dirname as
|
|
21902
|
+
import { dirname as dirname17, join as join34, resolve as resolve18 } from "node:path";
|
|
21636
21903
|
import { setTimeout as delay } from "node:timers/promises";
|
|
21637
21904
|
import { execa as execa15 } from "execa";
|
|
21638
21905
|
import lockfile2 from "proper-lockfile";
|
|
@@ -21656,8 +21923,8 @@ var RepositoryCache = class {
|
|
|
21656
21923
|
retainResources;
|
|
21657
21924
|
pathFor(remoteUrl) {
|
|
21658
21925
|
const { key: key2 } = normalizeRepository(remoteUrl, { allowFile: this.allowFile });
|
|
21659
|
-
const path3 =
|
|
21660
|
-
if (!isInside(
|
|
21926
|
+
const path3 = resolve18(this.root, "v2", createHash17("sha256").update(key2).digest("hex"));
|
|
21927
|
+
if (!isInside(resolve18(this.root), path3) || path3 === resolve18(this.root)) throw new Error("Invalid repository cache path");
|
|
21661
21928
|
return path3;
|
|
21662
21929
|
}
|
|
21663
21930
|
/** Serialize clone/fetch against the same cache, including other processes. */
|
|
@@ -21665,7 +21932,7 @@ var RepositoryCache = class {
|
|
|
21665
21932
|
signal?.throwIfAborted();
|
|
21666
21933
|
const { remoteUrl: remote } = normalizeRepository(remoteUrl, { allowFile: this.allowFile });
|
|
21667
21934
|
const path3 = this.pathFor(remote);
|
|
21668
|
-
this.ensureParents(
|
|
21935
|
+
this.ensureParents(dirname17(path3));
|
|
21669
21936
|
const release = await this.lock(path3, signal);
|
|
21670
21937
|
try {
|
|
21671
21938
|
return await withRepoConfig(path3, () => this.update(path3, remote, signal, env, diagnostics));
|
|
@@ -21704,7 +21971,7 @@ var RepositoryCache = class {
|
|
|
21704
21971
|
} else {
|
|
21705
21972
|
this.assertClone(path3);
|
|
21706
21973
|
await git3(["remote", "set-url", "origin", remote], path3);
|
|
21707
|
-
const depth = existsSync7(
|
|
21974
|
+
const depth = existsSync7(join34(path3, ".git", "shallow")) ? ["--depth=50"] : [];
|
|
21708
21975
|
await git3(["fetch", ...depth, ...this.retainResources ? [] : ["--prune"], "--no-tags", "--no-recurse-submodules", "--no-write-fetch-head", "origin"], path3);
|
|
21709
21976
|
}
|
|
21710
21977
|
this.assertClone(path3);
|
|
@@ -21796,28 +22063,28 @@ var RepositoryCache = class {
|
|
|
21796
22063
|
paths() {
|
|
21797
22064
|
const visit = (path3) => {
|
|
21798
22065
|
if (!existsSync7(path3) || lstatSync12(path3).isSymbolicLink()) return [];
|
|
21799
|
-
if (existsSync7(
|
|
22066
|
+
if (existsSync7(join34(path3, ".git"))) {
|
|
21800
22067
|
this.assertClone(path3);
|
|
21801
22068
|
return [path3];
|
|
21802
22069
|
}
|
|
21803
|
-
return readdirSync9(path3, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() && !entry.name.endsWith(".lock") && !entry.name.includes(".clone-") ? visit(
|
|
22070
|
+
return readdirSync9(path3, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() && !entry.name.endsWith(".lock") && !entry.name.includes(".clone-") ? visit(join34(path3, entry.name)) : []);
|
|
21804
22071
|
};
|
|
21805
|
-
return visit(
|
|
22072
|
+
return visit(resolve18(this.root));
|
|
21806
22073
|
}
|
|
21807
22074
|
ensureParents(path3) {
|
|
21808
22075
|
mkdirSync17(this.root, { recursive: true, mode: 448 });
|
|
21809
22076
|
if (lstatSync12(this.root).isSymbolicLink()) throw new Error("Repository cache contains a symlink");
|
|
21810
22077
|
const root = realpathSync13(this.root);
|
|
21811
|
-
let current =
|
|
22078
|
+
let current = resolve18(this.root);
|
|
21812
22079
|
for (const part of path3.slice(current.length + 1).split("/").filter(Boolean)) {
|
|
21813
|
-
current =
|
|
22080
|
+
current = join34(current, part);
|
|
21814
22081
|
if (existsSync7(current) && lstatSync12(current).isSymbolicLink()) throw new Error("Repository cache contains a symlink");
|
|
21815
22082
|
mkdirSync17(current, { recursive: true, mode: 448 });
|
|
21816
22083
|
if (!isInside(root, realpathSync13(current))) throw new Error("Repository cache escapes its directory");
|
|
21817
22084
|
}
|
|
21818
22085
|
}
|
|
21819
22086
|
assertClone(path3) {
|
|
21820
|
-
if (lstatSync12(path3).isSymbolicLink() || !lstatSync12(
|
|
22087
|
+
if (lstatSync12(path3).isSymbolicLink() || !lstatSync12(join34(path3, ".git")).isDirectory() || lstatSync12(join34(path3, ".git")).isSymbolicLink()) throw new Error("Repository cache is not a standard clone");
|
|
21821
22088
|
if (!isInside(realpathSync13(this.root), realpathSync13(path3))) throw new Error("Repository cache escapes its directory");
|
|
21822
22089
|
}
|
|
21823
22090
|
async lock(path3, signal) {
|
|
@@ -21923,11 +22190,11 @@ async function prepareRunRepository(repositories, privateDir, assignment, signal
|
|
|
21923
22190
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
21924
22191
|
import { spawn as spawn5 } from "node:child_process";
|
|
21925
22192
|
import { existsSync as existsSync8, mkdirSync as mkdirSync18, realpathSync as realpathSync14 } from "node:fs";
|
|
21926
|
-
import { dirname as
|
|
22193
|
+
import { dirname as dirname18, join as join35, resolve as resolve19 } from "node:path";
|
|
21927
22194
|
import { fileURLToPath } from "node:url";
|
|
21928
22195
|
|
|
21929
22196
|
// src/official-cli-timing.ts
|
|
21930
|
-
import { createHash as
|
|
22197
|
+
import { createHash as createHash18, randomBytes as randomBytes4 } from "node:crypto";
|
|
21931
22198
|
import { createServer as createServer4 } from "node:http";
|
|
21932
22199
|
|
|
21933
22200
|
// src/mcp-http-timing.ts
|
|
@@ -22251,7 +22518,7 @@ var OfficialCliTimingCollector = class {
|
|
|
22251
22518
|
};
|
|
22252
22519
|
async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, decisionCatalogue }) {
|
|
22253
22520
|
const collector = new OfficialCliTimingCollector(runId, harness);
|
|
22254
|
-
const expectedCatalogueSha256 = decisionCatalogue ?
|
|
22521
|
+
const expectedCatalogueSha256 = decisionCatalogue ? createHash18("sha256").update(JSON.stringify(decisionCatalogue)).digest("hex") : null;
|
|
22255
22522
|
const mcpCollector = new McpHttpTimingCollector(runId, harness, remoteMcpServerCount, Date.now, expectedCatalogueSha256);
|
|
22256
22523
|
const path3 = `/v1/logs/${randomBytes4(16).toString("hex")}`;
|
|
22257
22524
|
const mcpPath = `/v1/mcp-http/${randomBytes4(16).toString("hex")}`;
|
|
@@ -22292,11 +22559,11 @@ async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, d
|
|
|
22292
22559
|
server.requestTimeout = 5e3;
|
|
22293
22560
|
server.headersTimeout = 5e3;
|
|
22294
22561
|
server.maxConnections = 8;
|
|
22295
|
-
await new Promise((
|
|
22562
|
+
await new Promise((resolve20, reject) => {
|
|
22296
22563
|
server.once("error", reject);
|
|
22297
22564
|
server.listen(0, "127.0.0.1", () => {
|
|
22298
22565
|
server.off("error", reject);
|
|
22299
|
-
|
|
22566
|
+
resolve20();
|
|
22300
22567
|
});
|
|
22301
22568
|
});
|
|
22302
22569
|
server.on("error", () => {
|
|
@@ -22345,7 +22612,7 @@ async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, d
|
|
|
22345
22612
|
unsetEnv,
|
|
22346
22613
|
mcpHttpObservationUrl: `${origin}${mcpPath}`,
|
|
22347
22614
|
close: ({ cliExitObserved = false, publish = true } = {}) => closed ??= (async () => {
|
|
22348
|
-
await new Promise((
|
|
22615
|
+
await new Promise((resolve20) => {
|
|
22349
22616
|
const timer = setTimeout(() => {
|
|
22350
22617
|
collector.truncate();
|
|
22351
22618
|
mcpCollector.truncate();
|
|
@@ -22353,7 +22620,7 @@ async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, d
|
|
|
22353
22620
|
}, 1e3);
|
|
22354
22621
|
server.close(() => {
|
|
22355
22622
|
clearTimeout(timer);
|
|
22356
|
-
|
|
22623
|
+
resolve20();
|
|
22357
22624
|
});
|
|
22358
22625
|
});
|
|
22359
22626
|
const official = collector.finish(cliExitObserved), mcp = mcpCollector.finish();
|
|
@@ -22391,7 +22658,7 @@ async function runHostedCommand(worktree, script, _readOnly, timeoutMs, signal)
|
|
|
22391
22658
|
abort();
|
|
22392
22659
|
} else chunks.push(chunk);
|
|
22393
22660
|
};
|
|
22394
|
-
const result = await new Promise((
|
|
22661
|
+
const result = await new Promise((resolve20, reject) => {
|
|
22395
22662
|
child = spawn5("/bin/sh", ["-c", script], {
|
|
22396
22663
|
cwd: realpathSync14(worktree),
|
|
22397
22664
|
env: process.env,
|
|
@@ -22401,7 +22668,7 @@ async function runHostedCommand(worktree, script, _readOnly, timeoutMs, signal)
|
|
|
22401
22668
|
child.stdout?.on("data", (chunk) => collect("stdout", stdout, chunk));
|
|
22402
22669
|
child.stderr?.on("data", (chunk) => collect("stderr", stderr, chunk));
|
|
22403
22670
|
child.once("error", reject);
|
|
22404
|
-
child.once("close", (code, term) =>
|
|
22671
|
+
child.once("close", (code, term) => resolve20({ code, signal: term }));
|
|
22405
22672
|
child.once("exit", abort);
|
|
22406
22673
|
signal?.addEventListener("abort", abort, { once: true });
|
|
22407
22674
|
if (signal?.aborted) abort();
|
|
@@ -22527,7 +22794,7 @@ async function createHostedBotRunner(host) {
|
|
|
22527
22794
|
if (selected && (!options.model || options.model !== subscription?.first.modelId)) throw Error("binding_mismatch");
|
|
22528
22795
|
const paths = runPaths(host.stateDir, assignment.runId);
|
|
22529
22796
|
mkdirSync18(paths.runDir, { recursive: true, mode: 448 });
|
|
22530
|
-
const cwd = preparation ?
|
|
22797
|
+
const cwd = preparation ? resolve19(options.cwd) : realpathSync14(options.cwd);
|
|
22531
22798
|
const env = Object.fromEntries(Object.entries({ ...process.env, ...options.env, ...assignment.taskEnv }).filter((entry) => typeof entry[1] === "string"));
|
|
22532
22799
|
if (runDiagnosticsEnabled(assignment.taskEnv, host.collectCliTiming)) env.CLOUD_STARTUP_TIMING = "1";
|
|
22533
22800
|
const selectedGithub = options.github ?? (assignment.github ? { ...assignment.github, issueId: assignment.issueId, runToken: assignment.mcp?.token } : void 0);
|
|
@@ -22558,7 +22825,7 @@ async function createHostedBotRunner(host) {
|
|
|
22558
22825
|
});
|
|
22559
22826
|
Object.assign(env, github.env);
|
|
22560
22827
|
}
|
|
22561
|
-
const ledger =
|
|
22828
|
+
const ledger = join35(host.stateDir, "native-ledgers", assignment.runId + ".json");
|
|
22562
22829
|
const scope = selected && subscription ? {
|
|
22563
22830
|
runId: assignment.runId,
|
|
22564
22831
|
bindingId: selected.bindingId,
|
|
@@ -22571,12 +22838,12 @@ async function createHostedBotRunner(host) {
|
|
|
22571
22838
|
modelId: subscription.first.modelId
|
|
22572
22839
|
} : void 0;
|
|
22573
22840
|
if (continuation && existsSync8(ledger)) throw unavailable5("ledger_mismatch");
|
|
22574
|
-
const previousLedger = continuation ?
|
|
22841
|
+
const previousLedger = continuation ? join35(host.stateDir, "native-ledgers", continuation.runId + ".json") : ledger;
|
|
22575
22842
|
const previous = scope ? readJson(previousLedger) : void 0;
|
|
22576
22843
|
if (preparation && previous) throw unavailable5("ledger_mismatch");
|
|
22577
22844
|
const expectedScope = scope && continuation ? { ...scope, runId: continuation.runId } : scope;
|
|
22578
22845
|
if (scope && (existsSync8(previousLedger) && (!previous || JSON.stringify(previous.scope) !== JSON.stringify(expectedScope) || typeof previous.sessionId !== "string") || assignment.requireSessionResume && (!previous || previous.sessionId !== assignment.resumeSessionId))) throw unavailable5("ledger_mismatch");
|
|
22579
|
-
if (scope) mkdirSync18(
|
|
22846
|
+
if (scope) mkdirSync18(dirname18(ledger), { recursive: true, mode: 448 });
|
|
22580
22847
|
const record3 = async (sessionId) => {
|
|
22581
22848
|
assertOpen();
|
|
22582
22849
|
if (scope) writeJsonAtomic(ledger, { scope, sessionId });
|
|
@@ -22648,9 +22915,9 @@ async function createHostedBotRunner(host) {
|
|
|
22648
22915
|
signal: lifetime.signal
|
|
22649
22916
|
});
|
|
22650
22917
|
child.stderr?.resume();
|
|
22651
|
-
const exited = new Promise((
|
|
22652
|
-
child.once("exit", (code, signal) =>
|
|
22653
|
-
child.once("error", () =>
|
|
22918
|
+
const exited = new Promise((resolve20) => {
|
|
22919
|
+
child.once("exit", (code, signal) => resolve20({ code, signal }));
|
|
22920
|
+
child.once("error", () => resolve20({ code: null, signal: null }));
|
|
22654
22921
|
});
|
|
22655
22922
|
return {
|
|
22656
22923
|
process: child,
|
|
@@ -22837,7 +23104,7 @@ async function createHostedBotRunner(host) {
|
|
|
22837
23104
|
import {
|
|
22838
23105
|
randomBytes as randomBytes5,
|
|
22839
23106
|
randomUUID as randomUUID9,
|
|
22840
|
-
createHash as
|
|
23107
|
+
createHash as createHash20,
|
|
22841
23108
|
timingSafeEqual as timingSafeEqual2
|
|
22842
23109
|
} from "node:crypto";
|
|
22843
23110
|
import { chmodSync as chmodSync2 } from "node:fs";
|
|
@@ -22847,8 +23114,8 @@ import { createServer as createServer5 } from "node:net";
|
|
|
22847
23114
|
import { spawn as spawn6 } from "node:child_process";
|
|
22848
23115
|
import { execFile as execFile8 } from "node:child_process";
|
|
22849
23116
|
import { promisify as promisify8 } from "node:util";
|
|
22850
|
-
import { createHash as
|
|
22851
|
-
import { readFile as
|
|
23117
|
+
import { createHash as createHash19 } from "node:crypto";
|
|
23118
|
+
import { readFile as readFile8, realpath as realpath5 } from "node:fs/promises";
|
|
22852
23119
|
import { createInterface } from "node:readline";
|
|
22853
23120
|
var exec3 = promisify8(execFile8);
|
|
22854
23121
|
async function detectComputerDriver(binary = "cua-driver") {
|
|
@@ -22864,7 +23131,7 @@ async function detectComputerDriver(binary = "cua-driver") {
|
|
|
22864
23131
|
installed: true,
|
|
22865
23132
|
version,
|
|
22866
23133
|
path: path3,
|
|
22867
|
-
fingerprint:
|
|
23134
|
+
fingerprint: createHash19("sha256").update(await readFile8(path3)).digest("hex")
|
|
22868
23135
|
};
|
|
22869
23136
|
} catch {
|
|
22870
23137
|
return null;
|
|
@@ -22931,7 +23198,7 @@ async function executeDriver(driver, input, display, leaseGuard, assertLive = ()
|
|
|
22931
23198
|
if (display !== void 0 && !/^:[1-9][0-9]{0,3}$/.test(display))
|
|
22932
23199
|
throw new Error("Invalid desktop display");
|
|
22933
23200
|
const call = normalizeCall(input);
|
|
22934
|
-
const fingerprint2 =
|
|
23201
|
+
const fingerprint2 = createHash19("sha256").update(await readFile8(driver.path)).digest("hex");
|
|
22935
23202
|
if (fingerprint2 !== driver.fingerprint)
|
|
22936
23203
|
throw new Error("Driver changed; restart and approve a new request");
|
|
22937
23204
|
const args = driverArguments(call);
|
|
@@ -22994,9 +23261,9 @@ async function executeDriver(driver, input, display, leaseGuard, assertLive = ()
|
|
|
22994
23261
|
)
|
|
22995
23262
|
)
|
|
22996
23263
|
);
|
|
22997
|
-
const request2 = (method, params) => new Promise((
|
|
23264
|
+
const request2 = (method, params) => new Promise((resolve20, reject) => {
|
|
22998
23265
|
const n = ++id5;
|
|
22999
|
-
pending.set(n, { resolve:
|
|
23266
|
+
pending.set(n, { resolve: resolve20, reject });
|
|
23000
23267
|
child.stdin.write(
|
|
23001
23268
|
JSON.stringify({ jsonrpc: "2.0", id: n, method, params }) + "\n"
|
|
23002
23269
|
);
|
|
@@ -23138,10 +23405,10 @@ var ComputerBroker = class {
|
|
|
23138
23405
|
})();
|
|
23139
23406
|
});
|
|
23140
23407
|
});
|
|
23141
|
-
await new Promise((
|
|
23408
|
+
await new Promise((resolve20, reject) => {
|
|
23142
23409
|
this.server.once("error", reject);
|
|
23143
|
-
if (this.transport === "tcp") this.server.listen({ host: "127.0.0.1", port: 0 },
|
|
23144
|
-
else this.server.listen(this.socketPath,
|
|
23410
|
+
if (this.transport === "tcp") this.server.listen({ host: "127.0.0.1", port: 0 }, resolve20);
|
|
23411
|
+
else this.server.listen(this.socketPath, resolve20);
|
|
23145
23412
|
});
|
|
23146
23413
|
if (this.transport === "tcp") this.socketPath = `tcp://127.0.0.1:${this.server.address().port}`;
|
|
23147
23414
|
else chmodSync2(this.socketPath, 384);
|
|
@@ -23226,8 +23493,8 @@ var ComputerBroker = class {
|
|
|
23226
23493
|
call,
|
|
23227
23494
|
expiresAt: this.now() + this.ttl
|
|
23228
23495
|
};
|
|
23229
|
-
const digest9 =
|
|
23230
|
-
return new Promise((
|
|
23496
|
+
const digest9 = createHash20("sha256").update(JSON.stringify(request2)).digest("hex");
|
|
23497
|
+
return new Promise((resolve20, reject) => {
|
|
23231
23498
|
const timer = setTimeout(() => {
|
|
23232
23499
|
this.pending.delete(request2.id);
|
|
23233
23500
|
signal?.removeEventListener("abort", cancel);
|
|
@@ -23245,7 +23512,7 @@ var ComputerBroker = class {
|
|
|
23245
23512
|
assertLive,
|
|
23246
23513
|
cleanup: () => signal?.removeEventListener("abort", cancel),
|
|
23247
23514
|
request: { ...request2, digest: digest9 },
|
|
23248
|
-
resolve:
|
|
23515
|
+
resolve: resolve20,
|
|
23249
23516
|
reject,
|
|
23250
23517
|
timer
|
|
23251
23518
|
});
|
|
@@ -23338,15 +23605,15 @@ var ComputerBroker = class {
|
|
|
23338
23605
|
async close() {
|
|
23339
23606
|
this.suspend();
|
|
23340
23607
|
for (const socket of this.sockets) socket.destroy();
|
|
23341
|
-
if (this.server?.listening) await new Promise((
|
|
23608
|
+
if (this.server?.listening) await new Promise((resolve20) => this.server.close(resolve20));
|
|
23342
23609
|
}
|
|
23343
23610
|
};
|
|
23344
23611
|
|
|
23345
23612
|
// src/computer/credential-executor.ts
|
|
23346
|
-
import { createHash as
|
|
23613
|
+
import { createHash as createHash21 } from "node:crypto";
|
|
23347
23614
|
function credentialAwareExecutor(deps) {
|
|
23348
23615
|
return async (driver, call, display, runId, context) => {
|
|
23349
|
-
const digest9 =
|
|
23616
|
+
const digest9 = createHash21("sha256").update(JSON.stringify(call)).digest("hex");
|
|
23350
23617
|
const resolved = await deps.consumeMatchingIntent(runId, context.actionId, digest9);
|
|
23351
23618
|
context.assertLive();
|
|
23352
23619
|
if (resolved.kind === "ordinary") return deps.executeOrdinary(driver, call, display, runId, context.assertLive);
|
|
@@ -23443,8 +23710,8 @@ async function followWebComputerReviews(broker, deviceId, link, signal, pushes,
|
|
|
23443
23710
|
changed = false;
|
|
23444
23711
|
}
|
|
23445
23712
|
if (signal.aborted) break;
|
|
23446
|
-
await new Promise((
|
|
23447
|
-
wake =
|
|
23713
|
+
await new Promise((resolve20) => {
|
|
23714
|
+
wake = resolve20;
|
|
23448
23715
|
if (signal.aborted) nudge();
|
|
23449
23716
|
});
|
|
23450
23717
|
}
|
|
@@ -23628,7 +23895,7 @@ var Daemon = class {
|
|
|
23628
23895
|
if (this.options.credential)
|
|
23629
23896
|
this.saveDevice({ credential: this.options.credential });
|
|
23630
23897
|
this.journal = new RunJournal(paths.journal);
|
|
23631
|
-
this.captureUploader = new CaptureUploader((runId) =>
|
|
23898
|
+
this.captureUploader = new CaptureUploader((runId) => join36(runPaths(paths.adapterState, runId).runDir, CAPTURES_DIR), this.options.link, this.log, join36(paths.dataDir, "capture-pending"));
|
|
23632
23899
|
this.outbox = new Outbox(
|
|
23633
23900
|
paths.outbox,
|
|
23634
23901
|
this.options.link,
|
|
@@ -23647,7 +23914,7 @@ var Daemon = class {
|
|
|
23647
23914
|
if (this.localComputerDriver && this.options.link.syncComputerReviews) {
|
|
23648
23915
|
this.localComputerBroker = new ComputerBroker({
|
|
23649
23916
|
driver: this.localComputerDriver,
|
|
23650
|
-
socketPath:
|
|
23917
|
+
socketPath: join36(paths.dataDir, "local-computer.sock"),
|
|
23651
23918
|
transport: "tcp",
|
|
23652
23919
|
needsPerson: this.computerNeedsPerson(),
|
|
23653
23920
|
permitted: (runId) => {
|
|
@@ -23690,7 +23957,7 @@ var Daemon = class {
|
|
|
23690
23957
|
};
|
|
23691
23958
|
this.cloudComputerBroker = new ComputerBroker({
|
|
23692
23959
|
driver,
|
|
23693
|
-
socketPath:
|
|
23960
|
+
socketPath: join36(paths.dataDir, "computer.sock"),
|
|
23694
23961
|
needsPerson: this.computerNeedsPerson(),
|
|
23695
23962
|
permitted: (runId) => {
|
|
23696
23963
|
const entry = this.journal.get(runId);
|
|
@@ -23782,9 +24049,10 @@ var Daemon = class {
|
|
|
23782
24049
|
startCredential: hosted?.start,
|
|
23783
24050
|
prepareSubscription: hosted?.prepare,
|
|
23784
24051
|
prepareRunMailbox: this.options.link.prepareRunMailbox?.bind(this.options.link),
|
|
24052
|
+
prepareRunDrive: this.options.link.prepareRunDrive?.bind(this.options.link),
|
|
23785
24053
|
prepareRunToolApproval: this.options.link.prepareRunToolApproval?.bind(this.options.link),
|
|
23786
24054
|
prepareRunGitHub: hosted ? void 0 : (assignment, signal, onCredential) => prepareLocalGitHub(assignment, {
|
|
23787
|
-
stateDir:
|
|
24055
|
+
stateDir: join36(this.paths.adapterState, "github"),
|
|
23788
24056
|
link: this.options.link,
|
|
23789
24057
|
signal,
|
|
23790
24058
|
onCredential,
|
|
@@ -23854,7 +24122,7 @@ var Daemon = class {
|
|
|
23854
24122
|
worktree,
|
|
23855
24123
|
tree,
|
|
23856
24124
|
github: { ...assignment.github, runToken: assignment.mcp?.token, issueId: assignment.issueId },
|
|
23857
|
-
privateDir:
|
|
24125
|
+
privateDir: join36(paths.adapterState, "pids"),
|
|
23858
24126
|
...hosted ? { hosted: true } : {},
|
|
23859
24127
|
env: hosted ? process.env : githubReceiptEnvironment(),
|
|
23860
24128
|
githubEnvironment,
|
|
@@ -23967,11 +24235,11 @@ var Daemon = class {
|
|
|
23967
24235
|
async sessionTicket(signal) {
|
|
23968
24236
|
while (!this.device.credential) {
|
|
23969
24237
|
this.server = "unregistered";
|
|
23970
|
-
await new Promise((
|
|
24238
|
+
await new Promise((resolve20) => {
|
|
23971
24239
|
const done = () => {
|
|
23972
24240
|
this.credentialArrived.delete(done);
|
|
23973
24241
|
signal.removeEventListener("abort", done);
|
|
23974
|
-
|
|
24242
|
+
resolve20();
|
|
23975
24243
|
};
|
|
23976
24244
|
this.credentialArrived.add(done);
|
|
23977
24245
|
signal.addEventListener("abort", done, { once: true });
|
|
@@ -24569,11 +24837,11 @@ var Daemon = class {
|
|
|
24569
24837
|
return runVerify(sandbox, {
|
|
24570
24838
|
command,
|
|
24571
24839
|
worktree: realpathSync15(worktree),
|
|
24572
|
-
tmpRoot:
|
|
24840
|
+
tmpRoot: join36(this.paths.adapterState, "verify", runId),
|
|
24573
24841
|
privateDir: paths.privateDir,
|
|
24574
24842
|
pidFile: paths.pidFile.replace(/\.pgid$/, ".verify.pgid"),
|
|
24575
24843
|
networkAllow: repo.networkAllow,
|
|
24576
|
-
env: { ...buildChildEnv(), ...githubEnvironment, MIKKA_HANDOFF_FILE:
|
|
24844
|
+
env: { ...buildChildEnv(), ...githubEnvironment, MIKKA_HANDOFF_FILE: join36(paths.runDir, "handoff.json") },
|
|
24577
24845
|
timeoutMs,
|
|
24578
24846
|
signal,
|
|
24579
24847
|
readOnly
|
|
@@ -24725,14 +24993,14 @@ var Daemon = class {
|
|
|
24725
24993
|
}
|
|
24726
24994
|
const initialRunId = this.initialRunHint;
|
|
24727
24995
|
let resolveRepositories, rejectRepositories;
|
|
24728
|
-
const repositoriesReady = initialRunId ? new Promise((
|
|
24729
|
-
resolveRepositories =
|
|
24996
|
+
const repositoriesReady = initialRunId ? new Promise((resolve20, reject) => {
|
|
24997
|
+
resolveRepositories = resolve20;
|
|
24730
24998
|
rejectRepositories = reject;
|
|
24731
24999
|
}) : void 0;
|
|
24732
25000
|
if (initialRunId && repositoriesReady) {
|
|
24733
25001
|
let received;
|
|
24734
|
-
const repository2 = this.options.hostedSubscriptions && this.options.e2bContainerRuntime && this.journal.all().length === 0 ? new Promise((
|
|
24735
|
-
received =
|
|
25002
|
+
const repository2 = this.options.hostedSubscriptions && this.options.e2bContainerRuntime && this.journal.all().length === 0 ? new Promise((resolve20) => {
|
|
25003
|
+
received = resolve20;
|
|
24736
25004
|
}) : void 0;
|
|
24737
25005
|
this.initialRepositorySync = { runId: initialRunId, ready: repositoriesReady, repository: repository2, received };
|
|
24738
25006
|
void repositoriesReady.catch(() => void 0);
|
|
@@ -25128,7 +25396,7 @@ var Daemon = class {
|
|
|
25128
25396
|
});
|
|
25129
25397
|
}
|
|
25130
25398
|
get updateStateFile() {
|
|
25131
|
-
return
|
|
25399
|
+
return join36(this.paths.dataDir, "auto-update.json");
|
|
25132
25400
|
}
|
|
25133
25401
|
/** A server named this release (a report answer, a commands read, a 426), or npm did for a refused daemon. */
|
|
25134
25402
|
learnRelease(latest) {
|
|
@@ -25233,7 +25501,7 @@ function isNoDaemon(error) {
|
|
|
25233
25501
|
}
|
|
25234
25502
|
async function connectDaemon(options) {
|
|
25235
25503
|
const socket = connect(options.socketPath);
|
|
25236
|
-
await new Promise((
|
|
25504
|
+
await new Promise((resolve20, reject) => {
|
|
25237
25505
|
const timer = setTimeout(() => {
|
|
25238
25506
|
socket.destroy();
|
|
25239
25507
|
reject(
|
|
@@ -25244,7 +25512,7 @@ async function connectDaemon(options) {
|
|
|
25244
25512
|
}, options.timeoutMs ?? 3e3);
|
|
25245
25513
|
socket.once("connect", () => {
|
|
25246
25514
|
clearTimeout(timer);
|
|
25247
|
-
|
|
25515
|
+
resolve20();
|
|
25248
25516
|
});
|
|
25249
25517
|
socket.once("error", (error) => {
|
|
25250
25518
|
clearTimeout(timer);
|
|
@@ -25281,9 +25549,9 @@ async function connectDaemon(options) {
|
|
|
25281
25549
|
if (isProtocolMismatch(error) && options.drainOnMismatch) {
|
|
25282
25550
|
await Promise.race([
|
|
25283
25551
|
connection.sendRequest("daemon.drain", {}).catch(() => void 0),
|
|
25284
|
-
new Promise((
|
|
25285
|
-
connection.onClose(
|
|
25286
|
-
setTimeout(
|
|
25552
|
+
new Promise((resolve20) => {
|
|
25553
|
+
connection.onClose(resolve20);
|
|
25554
|
+
setTimeout(resolve20, 2e3).unref();
|
|
25287
25555
|
})
|
|
25288
25556
|
]);
|
|
25289
25557
|
}
|
|
@@ -25342,8 +25610,8 @@ async function connectStartingDaemon(dataDir) {
|
|
|
25342
25610
|
}
|
|
25343
25611
|
if (!daemonProcessAlive(dataDir)) return void 0;
|
|
25344
25612
|
if (revision2 !== before) continue;
|
|
25345
|
-
await new Promise((
|
|
25346
|
-
wake =
|
|
25613
|
+
await new Promise((resolve20) => {
|
|
25614
|
+
wake = resolve20;
|
|
25347
25615
|
});
|
|
25348
25616
|
wake = void 0;
|
|
25349
25617
|
}
|