@aspectlylabs/mikka 0.0.648 → 0.0.651
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 +1114 -563
- package/client.js +31 -3
- package/http-link.js +70 -17
- package/login.js +57 -6
- package/main.js +1096 -549
- package/mikka-mcp-backend.mjs +36 -5
- package/mikka-release-manifest.json +22 -22
- package/mikka.js +1114 -563
- 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
|
@@ -878,10 +878,10 @@ var require_truncate = __commonJS({
|
|
|
878
878
|
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/truncate.js"(exports, module) {
|
|
879
879
|
"use strict";
|
|
880
880
|
var parse2 = require_parse();
|
|
881
|
-
var
|
|
881
|
+
var constants10 = require_constants();
|
|
882
882
|
var SemVer = require_semver();
|
|
883
883
|
var truncate = (version, truncation, options) => {
|
|
884
|
-
if (!
|
|
884
|
+
if (!constants10.RELEASE_TYPES.includes(truncation)) {
|
|
885
885
|
return null;
|
|
886
886
|
}
|
|
887
887
|
const clonedVersion = cloneInputVersion(version, options);
|
|
@@ -1930,7 +1930,7 @@ var require_semver2 = __commonJS({
|
|
|
1930
1930
|
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/index.js"(exports, module) {
|
|
1931
1931
|
"use strict";
|
|
1932
1932
|
var internalRe = require_re();
|
|
1933
|
-
var
|
|
1933
|
+
var constants10 = require_constants();
|
|
1934
1934
|
var SemVer = require_semver();
|
|
1935
1935
|
var identifiers = require_identifiers();
|
|
1936
1936
|
var parse2 = require_parse();
|
|
@@ -2014,8 +2014,8 @@ var require_semver2 = __commonJS({
|
|
|
2014
2014
|
re: internalRe.re,
|
|
2015
2015
|
src: internalRe.src,
|
|
2016
2016
|
tokens: internalRe.t,
|
|
2017
|
-
SEMVER_SPEC_VERSION:
|
|
2018
|
-
RELEASE_TYPES:
|
|
2017
|
+
SEMVER_SPEC_VERSION: constants10.SEMVER_SPEC_VERSION,
|
|
2018
|
+
RELEASE_TYPES: constants10.RELEASE_TYPES,
|
|
2019
2019
|
compareIdentifiers: identifiers.compareIdentifiers,
|
|
2020
2020
|
rcompareIdentifiers: identifiers.rcompareIdentifiers
|
|
2021
2021
|
};
|
|
@@ -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
|
|
@@ -2937,6 +2937,7 @@ var harnessInfoSchema = z7.object({
|
|
|
2937
2937
|
computerBroker: z7.literal(true).optional(),
|
|
2938
2938
|
/** Run-scoped CLI approvals and policy-version checks are supported. */
|
|
2939
2939
|
toolApproval: z7.literal(true).optional(),
|
|
2940
|
+
activeTurnSteer: z7.literal(true).optional(),
|
|
2940
2941
|
/**
|
|
2941
2942
|
* The CLI exists but `installed` stays false because the daemon cannot run it
|
|
2942
2943
|
* in a sandbox. `missing` names the absent packages; empty means the machine
|
|
@@ -3351,6 +3352,24 @@ function logCodedError(error, fields = {}, log = consoleCodedErrorLog) {
|
|
|
3351
3352
|
|
|
3352
3353
|
// ../protocol/src/user-error-codes.ts
|
|
3353
3354
|
var USER_ERROR_CODES = {
|
|
3355
|
+
review_auth_required: [],
|
|
3356
|
+
review_not_found: [],
|
|
3357
|
+
not_owner_terminal: [],
|
|
3358
|
+
review_machine_gone: [],
|
|
3359
|
+
review_binding_changed: [],
|
|
3360
|
+
review_checkout_unavailable: [],
|
|
3361
|
+
review_preview_unavailable: ["configuration", "runtime", "protocol", "scope_changed", "limit"],
|
|
3362
|
+
terminal_unsupported: ["local_device", "runtime_version"],
|
|
3363
|
+
terminal_already_controlled: [],
|
|
3364
|
+
terminal_binding_changed: [],
|
|
3365
|
+
terminal_ended: [],
|
|
3366
|
+
terminal_input_too_large: [],
|
|
3367
|
+
terminal_invalid_request: [],
|
|
3368
|
+
terminal_request_conflict: [],
|
|
3369
|
+
terminal_input_uncertain: [],
|
|
3370
|
+
terminal_limit: [],
|
|
3371
|
+
terminal_unavailable: ["configuration", "runtime", "protocol", "installation", "lease"],
|
|
3372
|
+
terminal_control_unavailable: ["fence_unavailable", "fence_lost"],
|
|
3354
3373
|
review_scope_denied: ["sponsored_placement"],
|
|
3355
3374
|
workspace_not_found: [],
|
|
3356
3375
|
workspace_snapshot_unavailable: [],
|
|
@@ -3434,6 +3453,8 @@ var USER_ERROR_CODES = {
|
|
|
3434
3453
|
web_auth_exchange_rejected: [],
|
|
3435
3454
|
web_auth_session_expired: [],
|
|
3436
3455
|
factory_spec_approval_required: [],
|
|
3456
|
+
factory_visual_evidence_required: [],
|
|
3457
|
+
factory_public_evidence_required: [],
|
|
3437
3458
|
map_invalid_request: ["invalid_query", "invalid_token"],
|
|
3438
3459
|
map_not_found: [],
|
|
3439
3460
|
map_snapshot_changed: ["source_changed"],
|
|
@@ -4109,6 +4130,7 @@ var runSafePoint = z14.object({
|
|
|
4109
4130
|
checkpoint: z14.enum(["ready", "unavailable"]),
|
|
4110
4131
|
checkpointTakenAt: z14.iso.datetime({ offset: true }).optional()
|
|
4111
4132
|
}).strict().refine((value) => value.checkpoint === "ready" ? value.checkpointTakenAt !== void 0 && Date.parse(value.observedAt) >= Date.parse(value.checkpointTakenAt) : value.checkpointTakenAt === void 0, { message: "A ready final checkpoint requires its acknowledged snapshot time" });
|
|
4133
|
+
var runVisualEvidence = z14.array(z14.object({ captureId: z14.uuid(), publicSafe: z14.literal(true) }).strict()).max(40);
|
|
4112
4134
|
var runReport = z14.object({
|
|
4113
4135
|
repositorySelection: runRepositorySelection.optional(),
|
|
4114
4136
|
/** Worktree base journaled before the adapter started; never agent-supplied. */
|
|
@@ -4177,6 +4199,10 @@ var runReport = z14.object({
|
|
|
4177
4199
|
previewDatabaseBranch: z14.string().trim().min(1).max(500).optional(),
|
|
4178
4200
|
/** Acceptance criteria the agent checked, with evidence. */
|
|
4179
4201
|
criteria: z14.array(runCriterion).max(200).optional(),
|
|
4202
|
+
/** Captures from this run whose full visible content was checked for public sharing.
|
|
4203
|
+
* This is an explicit content review, not an automatic pixel-redaction claim.
|
|
4204
|
+
* The server resolves capture ownership and creates the existing share URL. */
|
|
4205
|
+
visualEvidence: runVisualEvidence.optional(),
|
|
4180
4206
|
/** A review completes once; this verdict never changes daemon-owned verification. */
|
|
4181
4207
|
reviewVerdict: reviewVerdict.optional(),
|
|
4182
4208
|
/**
|
|
@@ -5839,6 +5865,7 @@ var COMMANDS_MAX_SKIP = 100;
|
|
|
5839
5865
|
var COMMANDS_DAEMON_LATEST_PARAM = "daemonLatest";
|
|
5840
5866
|
var COMMANDS_SKIP_DEVICE_COMMANDS_PARAM = "skipDeviceCommands";
|
|
5841
5867
|
var COMMANDS_MAX_SKIP_DEVICE_COMMANDS = 10;
|
|
5868
|
+
var ACTIVE_TURN_STEER_HEADER = "x-mikka-active-turn-steer";
|
|
5842
5869
|
var MAILBOX_NOTICE_HEADER = "x-mikka-mailbox-notices";
|
|
5843
5870
|
var runCommandSchema = z24.discriminatedUnion("kind", [
|
|
5844
5871
|
z24.object({
|
|
@@ -5847,6 +5874,7 @@ var runCommandSchema = z24.discriminatedUnion("kind", [
|
|
|
5847
5874
|
messageId: z24.uuid(),
|
|
5848
5875
|
text: z24.string().min(1).max(1e5)
|
|
5849
5876
|
}),
|
|
5877
|
+
z24.object({ kind: z24.literal("steer"), runId: id3, messageId: z24.uuid(), text: z24.string().min(1).max(1e5) }),
|
|
5850
5878
|
z24.object({ kind: z24.literal("stop"), runId: id3 }),
|
|
5851
5879
|
// A host notification carries addresses only; peer content remains behind
|
|
5852
5880
|
// the authenticated mailbox read and retains its original provenance.
|
|
@@ -5868,7 +5896,8 @@ var runCommandsResponse = z24.object({
|
|
|
5868
5896
|
deviceCommands: z24.array(deviceManagementCommand).max(1).optional().catch(void 0)
|
|
5869
5897
|
});
|
|
5870
5898
|
var runCommandsAck = z24.object({
|
|
5871
|
-
delivered: z24.array(z24.uuid()).max(500)
|
|
5899
|
+
delivered: z24.array(z24.uuid()).max(500),
|
|
5900
|
+
refusedSteers: z24.array(z24.uuid()).max(500).optional()
|
|
5872
5901
|
});
|
|
5873
5902
|
var FS_REQUESTS_MAX_WAIT_SECONDS = 25;
|
|
5874
5903
|
var FS_MAX_ENTRIES = 500;
|
|
@@ -6542,7 +6571,7 @@ import { join as join4 } from "node:path";
|
|
|
6542
6571
|
// package.json
|
|
6543
6572
|
var package_default = {
|
|
6544
6573
|
name: "@mikka/daemon",
|
|
6545
|
-
version: "0.0.
|
|
6574
|
+
version: "0.0.651",
|
|
6546
6575
|
description: "Local Mikka daemon: runs agents through the user's own CLIs",
|
|
6547
6576
|
type: "module",
|
|
6548
6577
|
private: true,
|
|
@@ -6610,7 +6639,7 @@ var package_default = {
|
|
|
6610
6639
|
engines: {
|
|
6611
6640
|
node: ">=22"
|
|
6612
6641
|
},
|
|
6613
|
-
gitHead: "
|
|
6642
|
+
gitHead: "1a57df9c1a1d8e475820afad14e3fa0e6429c60b"
|
|
6614
6643
|
};
|
|
6615
6644
|
|
|
6616
6645
|
// src/paths.ts
|
|
@@ -6786,7 +6815,7 @@ var ToolApprovalGate = class {
|
|
|
6786
6815
|
/** Resolves on the next push or mode switch, or after the mode's cadence.
|
|
6787
6816
|
* A paused run waits here instead of asking the server every second. */
|
|
6788
6817
|
changed(signal) {
|
|
6789
|
-
return new Promise((
|
|
6818
|
+
return new Promise((resolve20, reject) => {
|
|
6790
6819
|
if (signal.aborted || this.revoked) {
|
|
6791
6820
|
reject(new Error("cancelled"));
|
|
6792
6821
|
return;
|
|
@@ -6797,7 +6826,7 @@ var ToolApprovalGate = class {
|
|
|
6797
6826
|
this.changes.delete(wake);
|
|
6798
6827
|
signal.removeEventListener("abort", abort);
|
|
6799
6828
|
if (error) reject(error);
|
|
6800
|
-
else
|
|
6829
|
+
else resolve20();
|
|
6801
6830
|
};
|
|
6802
6831
|
const wake = () => done(this.revoked ? new Error("cancelled") : void 0);
|
|
6803
6832
|
const abort = () => done(new Error("cancelled"));
|
|
@@ -6917,12 +6946,12 @@ import { createHash as createHash2, createPublicKey, verify } from "node:crypto"
|
|
|
6917
6946
|
var policySnapshotHash = (policy) => createHash2("sha256").update(runPolicyDigestInput(policy)).digest("hex");
|
|
6918
6947
|
function verifyPolicySnapshot(value, trusted, expected2, options = {}) {
|
|
6919
6948
|
const context = policyDistributionContextSchema.parse(trusted);
|
|
6920
|
-
const
|
|
6921
|
-
if (policyIssuer(context.issuer) !== context.issuer || policyIssuer(p.issuer) !== context.issuer || p.ownerId !== context.ownerId || p.deviceId !== context.deviceId || p.runId !== context.runId || p.revision !== context.revision || p.policyHash !== policySnapshotHash(p.policy) || p.runId !== expected2.runId || p.deviceId !== expected2.deviceId || p.revision !== expected2.revision ||
|
|
6949
|
+
const snapshot4 = signedPolicySnapshotSchema.parse(value), p = snapshot4.payload, now = options.now ?? Date.now();
|
|
6950
|
+
if (policyIssuer(context.issuer) !== context.issuer || policyIssuer(p.issuer) !== context.issuer || p.ownerId !== context.ownerId || p.deviceId !== context.deviceId || p.runId !== context.runId || p.revision !== context.revision || p.policyHash !== policySnapshotHash(p.policy) || p.runId !== expected2.runId || p.deviceId !== expected2.deviceId || p.revision !== expected2.revision || snapshot4.keyId !== context.keyId || JSON.stringify(p.scope) !== JSON.stringify(context.scope) || expected2.policy && JSON.stringify(p.policy) !== JSON.stringify(runPolicySchema.parse(expected2.policy))) throw Error("policySnapshotBindingInvalid");
|
|
6922
6951
|
if (p.issuedAt > now + 3e4 || p.expiresAt <= p.issuedAt || p.expiresAt - p.issuedAt > POLICY_SNAPSHOT_TTL_MS || !options.allowExpired && p.expiresAt <= now) throw Error("policySnapshotExpired");
|
|
6923
6952
|
const der = Buffer2.from(context.publicKey, "base64url");
|
|
6924
|
-
if (createHash2("sha256").update(der).digest("hex") !== context.keyId || !verify(null, policySnapshotMessage(p), createPublicKey({ key: der, type: "spki", format: "der" }), Buffer2.from(
|
|
6925
|
-
return
|
|
6953
|
+
if (createHash2("sha256").update(der).digest("hex") !== context.keyId || !verify(null, policySnapshotMessage(p), createPublicKey({ key: der, type: "spki", format: "der" }), Buffer2.from(snapshot4.signature, "base64url"))) throw Error("policySnapshotSignatureInvalid");
|
|
6954
|
+
return snapshot4;
|
|
6926
6955
|
}
|
|
6927
6956
|
|
|
6928
6957
|
// ../protocol/src/capture.ts
|
|
@@ -6941,6 +6970,7 @@ var CAPTURE_MAX_BYTES = {
|
|
|
6941
6970
|
video: 1e8
|
|
6942
6971
|
};
|
|
6943
6972
|
var RECORDING_MAX_SECONDS = 300;
|
|
6973
|
+
var CAPTURE_MAX_DURATION_MS = 36e5;
|
|
6944
6974
|
var CAPTURE_TITLE_MAX = 200;
|
|
6945
6975
|
function captureKind(contentType) {
|
|
6946
6976
|
return contentType.startsWith("video/") ? "video" : "image";
|
|
@@ -6971,14 +7001,31 @@ function cleanCaptureTitle(title2) {
|
|
|
6971
7001
|
}
|
|
6972
7002
|
var sha256 = z33.string().regex(/^[a-f0-9]{64}$/);
|
|
6973
7003
|
var title = z33.string().trim().min(1).max(CAPTURE_TITLE_MAX);
|
|
7004
|
+
var recordingStep = z33.object({
|
|
7005
|
+
atMs: z33.number().int().min(0).max(CAPTURE_MAX_DURATION_MS),
|
|
7006
|
+
label: title,
|
|
7007
|
+
source: z33.enum(["action", "mark"]),
|
|
7008
|
+
durationMs: z33.number().int().min(0).max(CAPTURE_MAX_DURATION_MS).nullable().optional()
|
|
7009
|
+
}).strict().refine((step) => step.durationMs == null || step.source === "action" && step.durationMs <= step.atMs, {
|
|
7010
|
+
message: "An action duration must fit its recorded end offset."
|
|
7011
|
+
});
|
|
6974
7012
|
var captureUploadRequest = z33.object({
|
|
6975
7013
|
/** Stable client id, persisted before the first network attempt. */
|
|
6976
7014
|
captureId: z33.uuid().optional(),
|
|
6977
7015
|
title,
|
|
6978
7016
|
contentType: z33.enum(CAPTURE_CONTENT_TYPES),
|
|
6979
7017
|
size: z33.number().int().min(1).max(CAPTURE_MAX_BYTES.video),
|
|
6980
|
-
sha256
|
|
6981
|
-
|
|
7018
|
+
sha256,
|
|
7019
|
+
/** Final, processed video duration and its remapped timeline. */
|
|
7020
|
+
durationMs: z33.number().int().min(1).max(CAPTURE_MAX_DURATION_MS).optional(),
|
|
7021
|
+
steps: z33.array(recordingStep).max(200).optional()
|
|
7022
|
+
}).strict().superRefine((value, ctx) => {
|
|
7023
|
+
if (value.durationMs !== void 0 || value.steps !== void 0) {
|
|
7024
|
+
if (!value.contentType.startsWith("video/")) ctx.addIssue({ code: "custom", message: "Only videos carry a recording timeline." });
|
|
7025
|
+
if (value.steps?.some((step) => value.durationMs === void 0 || step.atMs > value.durationMs))
|
|
7026
|
+
ctx.addIssue({ code: "custom", message: "Recording steps must fit the final video duration." });
|
|
7027
|
+
}
|
|
7028
|
+
});
|
|
6982
7029
|
var captureUploadTarget = z33.discriminatedUnion("target", [
|
|
6983
7030
|
z33.object({ target: z33.literal("storage"), url: z33.url({ protocol: /^https$/ }), headers: z33.record(z33.string(), z33.string()) }),
|
|
6984
7031
|
z33.object({ target: z33.literal("server") })
|
|
@@ -7003,7 +7050,12 @@ var screenCaptureRequest = z33.discriminatedUnion("action", [
|
|
|
7003
7050
|
z33.object({ action: z33.literal("start_recording"), title, maxSeconds: z33.number().int().min(5).max(RECORDING_MAX_SECONDS).optional() }).strict(),
|
|
7004
7051
|
z33.object({ action: z33.literal("stop_recording") }).strict(),
|
|
7005
7052
|
// A step on the recording's timeline: an action's own description, or a moment the agent marks.
|
|
7006
|
-
z33.object({
|
|
7053
|
+
z33.object({
|
|
7054
|
+
action: z33.literal("step"),
|
|
7055
|
+
label: title,
|
|
7056
|
+
source: z33.enum(["action", "mark"]),
|
|
7057
|
+
durationMs: z33.number().int().min(0).max(RECORDING_MAX_SECONDS * 1e3).optional()
|
|
7058
|
+
}).strict().refine((step) => step.durationMs === void 0 || step.source === "action", { message: "Only actions have a duration." })
|
|
7007
7059
|
]);
|
|
7008
7060
|
var screenCaptureResponse = z33.discriminatedUnion("action", [
|
|
7009
7061
|
z33.object({ action: z33.literal("screenshot"), capture: captureView }),
|
|
@@ -8091,8 +8143,8 @@ var DaemonTracer = class {
|
|
|
8091
8143
|
let timer;
|
|
8092
8144
|
await Promise.race([
|
|
8093
8145
|
work,
|
|
8094
|
-
new Promise((
|
|
8095
|
-
timer = setTimeout(
|
|
8146
|
+
new Promise((resolve20) => {
|
|
8147
|
+
timer = setTimeout(resolve20, timeoutMs);
|
|
8096
8148
|
timer.unref();
|
|
8097
8149
|
})
|
|
8098
8150
|
]).finally(() => {
|
|
@@ -8492,13 +8544,13 @@ var HttpServerLink = class {
|
|
|
8492
8544
|
}
|
|
8493
8545
|
if (!assignment.policy || !assignment.policyRevision) throw Error("Run policy unavailable");
|
|
8494
8546
|
const expected2 = { runId: assignment.runId, deviceId: assignment.deviceId, revision: assignment.policyRevision, policy: assignment.policy };
|
|
8495
|
-
let
|
|
8496
|
-
if (
|
|
8497
|
-
const renewed = await this.call("POST", path3, { body: { deviceId: assignment.deviceId, snapshot:
|
|
8498
|
-
|
|
8499
|
-
} else
|
|
8500
|
-
assignment.policySnapshot =
|
|
8501
|
-
assignment.policy =
|
|
8547
|
+
let snapshot4 = verifyPolicySnapshot(assignment.policySnapshot, context, expected2, { allowExpired: true });
|
|
8548
|
+
if (snapshot4.payload.expiresAt - Date.now() <= POLICY_SNAPSHOT_REFRESH_MS) {
|
|
8549
|
+
const renewed = await this.call("POST", path3, { body: { deviceId: assignment.deviceId, snapshot: snapshot4 }, schema: signedPolicySnapshotSchema, signal, timeoutMs: 5e3 });
|
|
8550
|
+
snapshot4 = verifyPolicySnapshot(renewed, context, expected2);
|
|
8551
|
+
} else snapshot4 = verifyPolicySnapshot(snapshot4, context, expected2);
|
|
8552
|
+
assignment.policySnapshot = snapshot4;
|
|
8553
|
+
assignment.policy = snapshot4.payload.policy;
|
|
8502
8554
|
Object.freeze(assignment.policy.permissions);
|
|
8503
8555
|
Object.freeze(assignment.policy.networkAllow);
|
|
8504
8556
|
if (assignment.policy.networkCeiling) Object.freeze(assignment.policy.networkCeiling);
|
|
@@ -8615,6 +8667,7 @@ var HttpServerLink = class {
|
|
|
8615
8667
|
...initialRepository ? { [INITIAL_REPOSITORY_HEADER]: "1" } : {},
|
|
8616
8668
|
[SUBSCRIPTION_MODEL_CATALOGUE_HEADER]: "1",
|
|
8617
8669
|
[MAILBOX_NOTICE_HEADER]: "1",
|
|
8670
|
+
[ACTIVE_TURN_STEER_HEADER]: "1",
|
|
8618
8671
|
[WORKSPACE_REQUEST_HEADER]: "1",
|
|
8619
8672
|
[WORKSPACE_DIFF_REQUEST_HEADER]: "1",
|
|
8620
8673
|
[WORKSPACE_GIT_REQUEST_HEADER]: "1",
|
|
@@ -8748,14 +8801,14 @@ var HttpServerLink = class {
|
|
|
8748
8801
|
}
|
|
8749
8802
|
return { contentType, body: response.body };
|
|
8750
8803
|
}
|
|
8751
|
-
async beginCapture(runId, request2) {
|
|
8752
|
-
return this.call("POST", capturePaths.begin(checkId(runId)), { body: request2, schema: captureUploadResponse });
|
|
8804
|
+
async beginCapture(runId, request2, signal) {
|
|
8805
|
+
return this.call("POST", capturePaths.begin(checkId(runId)), { body: request2, schema: captureUploadResponse, signal });
|
|
8753
8806
|
}
|
|
8754
|
-
async resumeCapture(runId, captureId) {
|
|
8755
|
-
return this.call("POST", capturePaths.upload(checkId(runId), checkId(captureId)), { schema: captureUploadResponse });
|
|
8807
|
+
async resumeCapture(runId, captureId, signal) {
|
|
8808
|
+
return this.call("POST", capturePaths.upload(checkId(runId), checkId(captureId)), { schema: captureUploadResponse, signal });
|
|
8756
8809
|
}
|
|
8757
8810
|
/** Straight to object storage with the signed headers, or to the server when it has no bucket. */
|
|
8758
|
-
async sendCapture(runId, captureId, upload, bytes, contentType) {
|
|
8811
|
+
async sendCapture(runId, captureId, upload, bytes, contentType, signal) {
|
|
8759
8812
|
const server = upload.target === "server";
|
|
8760
8813
|
let response;
|
|
8761
8814
|
try {
|
|
@@ -8764,7 +8817,7 @@ var HttpServerLink = class {
|
|
|
8764
8817
|
headers: server ? { "content-type": contentType, [CLIENT_VERSION_HEADER]: this.clientVersion, ...this.credential ? { authorization: `Bearer ${this.credential}` } : {}, ...this.protectionBypass ? { "x-vercel-protection-bypass": this.protectionBypass } : {} } : upload.headers,
|
|
8765
8818
|
body: bytes,
|
|
8766
8819
|
redirect: "error",
|
|
8767
|
-
signal: AbortSignal.timeout(3e5)
|
|
8820
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(3e5)]) : AbortSignal.timeout(3e5)
|
|
8768
8821
|
});
|
|
8769
8822
|
} catch (error) {
|
|
8770
8823
|
throw new ServerUnreachableError(error);
|
|
@@ -8773,8 +8826,8 @@ var HttpServerLink = class {
|
|
|
8773
8826
|
if (response.status === 401 && server) throw new SessionRejectedError();
|
|
8774
8827
|
if (!response.ok) throw new DaemonError(response.status, `PUT capture failed: ${response.status}`, { status: response.status });
|
|
8775
8828
|
}
|
|
8776
|
-
async completeCapture(runId, captureId) {
|
|
8777
|
-
const { capture } = await this.call("POST", capturePaths.complete(checkId(runId), checkId(captureId)), { schema: captureCompleteResponse, timeoutMs: 12e4 });
|
|
8829
|
+
async completeCapture(runId, captureId, signal) {
|
|
8830
|
+
const { capture } = await this.call("POST", capturePaths.complete(checkId(runId), checkId(captureId)), { schema: captureCompleteResponse, timeoutMs: 12e4, signal });
|
|
8778
8831
|
return capture;
|
|
8779
8832
|
}
|
|
8780
8833
|
async screenCapture(runId, request2, signal) {
|
|
@@ -8850,10 +8903,10 @@ var HttpServerLink = class {
|
|
|
8850
8903
|
}
|
|
8851
8904
|
}
|
|
8852
8905
|
}
|
|
8853
|
-
async ackCommands(deviceId, delivered) {
|
|
8854
|
-
if (delivered.length
|
|
8906
|
+
async ackCommands(deviceId, delivered, refusedSteers = []) {
|
|
8907
|
+
if (!delivered.length && !refusedSteers.length) return;
|
|
8855
8908
|
await this.call("POST", devicePaths.commandsAck(checkId(deviceId)), {
|
|
8856
|
-
body: { delivered }
|
|
8909
|
+
body: { delivered, ...refusedSteers.length ? { refusedSteers } : {} }
|
|
8857
8910
|
});
|
|
8858
8911
|
}
|
|
8859
8912
|
async fetchFsRequests(deviceId, waitSeconds, { signal } = {}) {
|
|
@@ -8925,7 +8978,7 @@ async function post(options, path3, body) {
|
|
|
8925
8978
|
};
|
|
8926
8979
|
}
|
|
8927
8980
|
async function deviceLogin(options) {
|
|
8928
|
-
const sleep3 = options.sleep ?? ((ms2) => new Promise((
|
|
8981
|
+
const sleep3 = options.sleep ?? ((ms2) => new Promise((resolve20) => setTimeout(resolve20, ms2)));
|
|
8929
8982
|
const started = await post(options, DEVICE_CODE_PATH, {
|
|
8930
8983
|
client_id: DAEMON_CLIENT_ID,
|
|
8931
8984
|
device_name: options.deviceName ?? hostname(),
|
|
@@ -8997,7 +9050,7 @@ import {
|
|
|
8997
9050
|
realpathSync as realpathSync15
|
|
8998
9051
|
} from "node:fs";
|
|
8999
9052
|
import { arch as arch2, hostname as hostname2, platform as platform4 } from "node:os";
|
|
9000
|
-
import { join as
|
|
9053
|
+
import { join as join36 } from "node:path";
|
|
9001
9054
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
9002
9055
|
|
|
9003
9056
|
// src/runs/quota-exhausted.ts
|
|
@@ -9081,7 +9134,7 @@ function quotaStopApplies(assignment) {
|
|
|
9081
9134
|
import { spawn as spawn2 } from "node:child_process";
|
|
9082
9135
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
9083
9136
|
import { realpathSync as realpathSync10 } from "node:fs";
|
|
9084
|
-
import { join as
|
|
9137
|
+
import { join as join14 } from "node:path";
|
|
9085
9138
|
|
|
9086
9139
|
// src/adapters/generation-metrics.ts
|
|
9087
9140
|
var record2 = (value) => value && typeof value === "object" ? value : {};
|
|
@@ -9213,17 +9266,17 @@ var CodexGenerationMetrics = class {
|
|
|
9213
9266
|
// src/adapters/claude-prewarm.ts
|
|
9214
9267
|
import { randomUUID } from "node:crypto";
|
|
9215
9268
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
9216
|
-
function prepareAgentStart(signal,
|
|
9269
|
+
function prepareAgentStart(signal, open5, diagnostics) {
|
|
9217
9270
|
const lifetime = new AbortController();
|
|
9218
9271
|
let accept, refuse2;
|
|
9219
|
-
const finalOptions = new Promise((
|
|
9220
|
-
accept =
|
|
9272
|
+
const finalOptions = new Promise((resolve20, reject) => {
|
|
9273
|
+
accept = resolve20;
|
|
9221
9274
|
refuse2 = reject;
|
|
9222
9275
|
});
|
|
9223
9276
|
void finalOptions.catch(() => void 0);
|
|
9224
9277
|
let parked, failed;
|
|
9225
|
-
const ready = new Promise((
|
|
9226
|
-
parked =
|
|
9278
|
+
const ready = new Promise((resolve20, reject) => {
|
|
9279
|
+
parked = resolve20;
|
|
9227
9280
|
failed = reject;
|
|
9228
9281
|
});
|
|
9229
9282
|
void ready.catch(() => void 0);
|
|
@@ -9232,7 +9285,7 @@ function prepareAgentStart(signal, open4, diagnostics) {
|
|
|
9232
9285
|
const starting = Promise.resolve().then(() => {
|
|
9233
9286
|
const work = () => {
|
|
9234
9287
|
lifetime.signal.throwIfAborted();
|
|
9235
|
-
return
|
|
9288
|
+
return open5({ signal: lifetime.signal, finalOptions, parked });
|
|
9236
9289
|
};
|
|
9237
9290
|
return diagnostics ? daemonTracer.preparation(
|
|
9238
9291
|
{ runIdHash: runIdHash(diagnostics.runId), harness: diagnostics.harness },
|
|
@@ -9306,8 +9359,8 @@ var ClaimedPromptQueue = class {
|
|
|
9306
9359
|
while (!this.closed) {
|
|
9307
9360
|
const item = this.items.shift();
|
|
9308
9361
|
if (item) yield item;
|
|
9309
|
-
else await new Promise((
|
|
9310
|
-
this.wake =
|
|
9362
|
+
else await new Promise((resolve20) => {
|
|
9363
|
+
this.wake = resolve20;
|
|
9311
9364
|
});
|
|
9312
9365
|
}
|
|
9313
9366
|
}
|
|
@@ -9489,6 +9542,14 @@ var SNAPSHOT_CREDENTIAL_GLOBS = [
|
|
|
9489
9542
|
"/root/.git-credentials",
|
|
9490
9543
|
// A Bot desktop's cached GitHub credential (lib/computer/desktop-github.ts).
|
|
9491
9544
|
"/home/*/.mikka/github/token.json",
|
|
9545
|
+
// One-use bootstrap handoffs carry the same device credential. The worker
|
|
9546
|
+
// unlinks them after reading, but a pause may race an unconsumed handoff.
|
|
9547
|
+
// The daemon's own `device.json`/`daemon.secret` stay: they are the local
|
|
9548
|
+
// identity over a device token this machine revokes when it pauses, and
|
|
9549
|
+
// removing them would break a same-VM resume before that revocation.
|
|
9550
|
+
"/home/user/.mikka/bootstrap.json",
|
|
9551
|
+
"/home/user/.mikka/anonymous-claude.json",
|
|
9552
|
+
"/home/user/.mikka/anonymous-codex.json",
|
|
9492
9553
|
...runCredentialGlobs(CLOUD_WORKER_STATE_DIR)
|
|
9493
9554
|
];
|
|
9494
9555
|
|
|
@@ -9527,8 +9588,8 @@ function writeOwnFile(file, content) {
|
|
|
9527
9588
|
writeFileSync(file, content, { flag: "wx", mode: 384 });
|
|
9528
9589
|
}
|
|
9529
9590
|
function ownDir(dir) {
|
|
9530
|
-
const
|
|
9531
|
-
if (
|
|
9591
|
+
const stat3 = lstatSync(dir, { throwIfNoEntry: false });
|
|
9592
|
+
if (stat3 && !stat3.isDirectory()) rmSync2(dir, { force: true });
|
|
9532
9593
|
mkdirSync3(dir, { recursive: true, mode: 448 });
|
|
9533
9594
|
}
|
|
9534
9595
|
function carryHistory(from, to, entries) {
|
|
@@ -9584,8 +9645,8 @@ var EventQueue = class {
|
|
|
9584
9645
|
if (next.type === "exit") return;
|
|
9585
9646
|
continue;
|
|
9586
9647
|
}
|
|
9587
|
-
await new Promise((
|
|
9588
|
-
this.waiter =
|
|
9648
|
+
await new Promise((resolve20) => {
|
|
9649
|
+
this.waiter = resolve20;
|
|
9589
9650
|
});
|
|
9590
9651
|
}
|
|
9591
9652
|
}
|
|
@@ -9662,13 +9723,13 @@ async function spawnCli(sandbox, argv, options) {
|
|
|
9662
9723
|
stderr = (stderr + data).slice(-STDERR_TAIL * 4);
|
|
9663
9724
|
});
|
|
9664
9725
|
const exited = new Promise(
|
|
9665
|
-
(
|
|
9726
|
+
(resolve20) => {
|
|
9666
9727
|
child.once("error", (error) => {
|
|
9667
9728
|
stderr += `
|
|
9668
9729
|
${error.message}`;
|
|
9669
|
-
|
|
9730
|
+
resolve20({ code: null, signal: null });
|
|
9670
9731
|
});
|
|
9671
|
-
child.once("exit", (code, signal) =>
|
|
9732
|
+
child.once("exit", (code, signal) => resolve20({ code, signal }));
|
|
9672
9733
|
}
|
|
9673
9734
|
).finally(() => {
|
|
9674
9735
|
signalGroup(pgid, "SIGKILL");
|
|
@@ -9685,8 +9746,8 @@ ${error.message}`;
|
|
|
9685
9746
|
let timer;
|
|
9686
9747
|
await Promise.race([
|
|
9687
9748
|
exited,
|
|
9688
|
-
new Promise((
|
|
9689
|
-
timer = setTimeout(
|
|
9749
|
+
new Promise((resolve20) => {
|
|
9750
|
+
timer = setTimeout(resolve20, graceMs);
|
|
9690
9751
|
})
|
|
9691
9752
|
]);
|
|
9692
9753
|
clearTimeout(timer);
|
|
@@ -10219,13 +10280,13 @@ async function excludeVerifyArtifacts(repoPath) {
|
|
|
10219
10280
|
});
|
|
10220
10281
|
}
|
|
10221
10282
|
async function du(path3) {
|
|
10222
|
-
let
|
|
10283
|
+
let stat3;
|
|
10223
10284
|
try {
|
|
10224
|
-
|
|
10285
|
+
stat3 = await lstat(path3);
|
|
10225
10286
|
} catch {
|
|
10226
10287
|
return 0;
|
|
10227
10288
|
}
|
|
10228
|
-
if (!
|
|
10289
|
+
if (!stat3.isDirectory()) return stat3.size;
|
|
10229
10290
|
let entries;
|
|
10230
10291
|
try {
|
|
10231
10292
|
entries = await readdir(path3);
|
|
@@ -10744,7 +10805,7 @@ function nativeMcpProcess(server) {
|
|
|
10744
10805
|
|
|
10745
10806
|
// src/agents/run-context.ts
|
|
10746
10807
|
import { execFileSync } from "node:child_process";
|
|
10747
|
-
import { createHash as
|
|
10808
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
10748
10809
|
import {
|
|
10749
10810
|
lstatSync as lstatSync8,
|
|
10750
10811
|
mkdirSync as mkdirSync8,
|
|
@@ -10755,7 +10816,7 @@ import {
|
|
|
10755
10816
|
writeFileSync as writeFileSync4
|
|
10756
10817
|
} from "node:fs";
|
|
10757
10818
|
import { homedir as homedir4 } from "node:os";
|
|
10758
|
-
import { dirname as
|
|
10819
|
+
import { dirname as dirname10, join as join13, resolve as resolve10 } from "node:path";
|
|
10759
10820
|
|
|
10760
10821
|
// src/agents/skill-artifact.ts
|
|
10761
10822
|
import { createHash as createHash4 } from "node:crypto";
|
|
@@ -10905,45 +10966,439 @@ function classifyWrite(worktree, target) {
|
|
|
10905
10966
|
}
|
|
10906
10967
|
|
|
10907
10968
|
// src/captures.ts
|
|
10969
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
10970
|
+
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";
|
|
10971
|
+
import { join as join12 } from "node:path";
|
|
10972
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
10973
|
+
|
|
10974
|
+
// src/agents/capture-video.mjs
|
|
10975
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
10908
10976
|
import { createHash as createHash5 } from "node:crypto";
|
|
10909
|
-
import {
|
|
10910
|
-
import {
|
|
10977
|
+
import { constants as constants2, createWriteStream } from "node:fs";
|
|
10978
|
+
import { chmod, lstat as lstat2, mkdir as mkdir2, mkdtemp, open, readFile as readFile2, rename, rm as rm2, stat } from "node:fs/promises";
|
|
10979
|
+
import { dirname as dirname9, basename as basename4, join as join11, resolve as resolve9 } from "node:path";
|
|
10980
|
+
import { devNull } from "node:os";
|
|
10981
|
+
import { pipeline } from "node:stream/promises";
|
|
10982
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
10983
|
+
import { promisify as promisify3 } from "node:util";
|
|
10984
|
+
var execute = promisify3(execFile3);
|
|
10985
|
+
var CAPTURE_RAW_MAX_BYTES = 1e9;
|
|
10986
|
+
var CAPTURE_VIDEO_MAX_BYTES = 1e8;
|
|
10987
|
+
var CAPTURE_TOOLCHAIN = {
|
|
10988
|
+
id: "ffmpeg-static-b6.1.1-linux-x64-e7e7fb30477f-4f231a1960d8",
|
|
10989
|
+
release: "https://github.com/eugeneware/ffmpeg-static/releases/tag/b6.1.1",
|
|
10990
|
+
version: "7.0.2-static",
|
|
10991
|
+
assets: {
|
|
10992
|
+
ffmpeg: {
|
|
10993
|
+
assetId: 316528626,
|
|
10994
|
+
gzip: true,
|
|
10995
|
+
downloadBytes: 29354986,
|
|
10996
|
+
downloadSha256: "bfe8a8fc511530457b528c48d77b5737527b504a3797a9bc4866aeca69c2dffa",
|
|
10997
|
+
bytes: 79826272,
|
|
10998
|
+
sha256: "e7e7fb30477f717e6f55f9180a70386c62677ef8a4d4d1a5d948f4098aa3eb99"
|
|
10999
|
+
},
|
|
11000
|
+
ffprobe: {
|
|
11001
|
+
assetId: 316529539,
|
|
11002
|
+
gzip: true,
|
|
11003
|
+
downloadBytes: 29276839,
|
|
11004
|
+
downloadSha256: "25d9b6ccb05e3d9de9e04e31e2506d8dd7f9f0418981965ac6df12e8d3afd067",
|
|
11005
|
+
bytes: 79665792,
|
|
11006
|
+
sha256: "4f231a1960d83e403d08f7971e271707bec278a9ae18e21b8b5b03186668450d"
|
|
11007
|
+
},
|
|
11008
|
+
LICENSE: {
|
|
11009
|
+
assetId: 316529924,
|
|
11010
|
+
gzip: false,
|
|
11011
|
+
downloadBytes: 35147,
|
|
11012
|
+
downloadSha256: "8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903",
|
|
11013
|
+
bytes: 35147,
|
|
11014
|
+
sha256: "8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903"
|
|
11015
|
+
},
|
|
11016
|
+
README: {
|
|
11017
|
+
assetId: 316529927,
|
|
11018
|
+
gzip: false,
|
|
11019
|
+
downloadBytes: 2235,
|
|
11020
|
+
downloadSha256: "72f4b1b06d419d22ace6e7cc75f06826f90737345aa0b1736158929f4aacc537",
|
|
11021
|
+
bytes: 2235,
|
|
11022
|
+
sha256: "72f4b1b06d419d22ace6e7cc75f06826f90737345aa0b1736158929f4aacc537"
|
|
11023
|
+
}
|
|
11024
|
+
}
|
|
11025
|
+
};
|
|
11026
|
+
var CAPTURE_TOOLS_ROOT = "/opt/mikka/runtime/capture-tools";
|
|
11027
|
+
var CAPTURE_TOOLS_DIRECTORY = `${CAPTURE_TOOLS_ROOT}/${CAPTURE_TOOLCHAIN.id}`;
|
|
11028
|
+
var MAX_STEPS = 200;
|
|
11029
|
+
var MAX_DURATION_MS = 36e5;
|
|
11030
|
+
var PADDING_BEFORE_MS = 1e3;
|
|
11031
|
+
var PADDING_AFTER_MS = 1500;
|
|
11032
|
+
var CaptureVideoError = class extends Error {
|
|
11033
|
+
constructor(code, options) {
|
|
11034
|
+
super(code, options);
|
|
11035
|
+
this.name = "CaptureVideoError";
|
|
11036
|
+
this.code = code;
|
|
11037
|
+
}
|
|
11038
|
+
};
|
|
11039
|
+
async function captureVideoBinaries({ directory = CAPTURE_TOOLS_DIRECTORY, ownerId = 0 } = {}) {
|
|
11040
|
+
const info = await lstat2(directory).catch((error) => {
|
|
11041
|
+
if (error.code === "ENOENT") return null;
|
|
11042
|
+
throw error;
|
|
11043
|
+
});
|
|
11044
|
+
if (!info) return { ffmpeg: "ffmpeg", ffprobe: "ffprobe" };
|
|
11045
|
+
try {
|
|
11046
|
+
if (!info.isDirectory() || info.uid !== ownerId || info.mode & 18) throw new Error("Private capture tools directory is unsafe");
|
|
11047
|
+
const binaries = { ffmpeg: join11(directory, "ffmpeg"), ffprobe: join11(directory, "ffprobe") };
|
|
11048
|
+
for (const path3 of Object.values(binaries)) {
|
|
11049
|
+
const binary = await lstat2(path3);
|
|
11050
|
+
if (!binary.isFile() || binary.uid !== ownerId || binary.mode & 18 || !(binary.mode & 73)) throw new Error("Private capture tool is unsafe");
|
|
11051
|
+
}
|
|
11052
|
+
return binaries;
|
|
11053
|
+
} catch (error) {
|
|
11054
|
+
throw new CaptureVideoError("captureVideoDependencyUnavailable", { cause: error });
|
|
11055
|
+
}
|
|
11056
|
+
}
|
|
11057
|
+
function normalizeRecordingSteps(input = []) {
|
|
11058
|
+
if (!Array.isArray(input) || input.length > MAX_STEPS) throw new CaptureVideoError("captureVideoStepsInvalid");
|
|
11059
|
+
return input.map((step) => {
|
|
11060
|
+
if (!step || typeof step !== "object" || Array.isArray(step) || !Number.isSafeInteger(step.atMs) || step.atMs < 0 || step.atMs > MAX_DURATION_MS || !["action", "mark"].includes(step.source) || typeof step.label !== "string" || !step.label.trim() || step.label.length > 200 || step.durationMs != null && (step.source !== "action" || !Number.isSafeInteger(step.durationMs) || step.durationMs < 0 || step.durationMs > MAX_DURATION_MS))
|
|
11061
|
+
throw new CaptureVideoError("captureVideoStepsInvalid");
|
|
11062
|
+
return {
|
|
11063
|
+
atMs: step.atMs,
|
|
11064
|
+
label: step.label.replace(/\s+/g, " ").trim(),
|
|
11065
|
+
source: step.source,
|
|
11066
|
+
...step.durationMs == null ? {} : { durationMs: step.durationMs }
|
|
11067
|
+
};
|
|
11068
|
+
}).sort((left, right) => left.atMs - right.atMs);
|
|
11069
|
+
}
|
|
11070
|
+
function recordingWindows(durationMs, rawSteps = []) {
|
|
11071
|
+
if (!Number.isSafeInteger(durationMs) || durationMs <= 0 || durationMs > MAX_DURATION_MS)
|
|
11072
|
+
throw new CaptureVideoError("captureVideoDurationInvalid");
|
|
11073
|
+
const steps = normalizeRecordingSteps(rawSteps);
|
|
11074
|
+
const actions = steps.filter((step) => step.source === "action");
|
|
11075
|
+
if (!actions.length || actions.some((step) => step.durationMs == null) || steps.some((step) => step.atMs > durationMs + PADDING_AFTER_MS))
|
|
11076
|
+
return [{ startMs: 0, endMs: durationMs }];
|
|
11077
|
+
const windows = [
|
|
11078
|
+
{ startMs: 0, endMs: Math.min(actions[0].atMs + PADDING_AFTER_MS, durationMs) },
|
|
11079
|
+
...steps.map((step) => ({
|
|
11080
|
+
startMs: Math.max(0, step.atMs - (step.durationMs ?? 0) - PADDING_BEFORE_MS),
|
|
11081
|
+
endMs: Math.min(durationMs, step.atMs + PADDING_AFTER_MS)
|
|
11082
|
+
})),
|
|
11083
|
+
{ startMs: Math.max(0, actions.at(-1).atMs - actions.at(-1).durationMs - PADDING_BEFORE_MS), endMs: durationMs }
|
|
11084
|
+
].filter((window) => window.endMs > window.startMs).sort((a, b) => a.startMs - b.startMs);
|
|
11085
|
+
const merged = [];
|
|
11086
|
+
for (const window of windows) {
|
|
11087
|
+
const previous = merged.at(-1);
|
|
11088
|
+
if (previous && window.startMs <= previous.endMs + 500) previous.endMs = Math.max(previous.endMs, window.endMs);
|
|
11089
|
+
else merged.push({ ...window });
|
|
11090
|
+
}
|
|
11091
|
+
return merged;
|
|
11092
|
+
}
|
|
11093
|
+
function remapRecordingSteps(rawSteps, windows, durationMs) {
|
|
11094
|
+
const point = (atMs) => {
|
|
11095
|
+
let kept = 0;
|
|
11096
|
+
for (const window of windows) {
|
|
11097
|
+
if (atMs <= window.endMs) return Math.min(durationMs, Math.max(0, Math.round(kept + Math.max(0, atMs - window.startMs))));
|
|
11098
|
+
kept += window.endMs - window.startMs;
|
|
11099
|
+
}
|
|
11100
|
+
return Math.min(durationMs, Math.round(kept));
|
|
11101
|
+
};
|
|
11102
|
+
return normalizeRecordingSteps(rawSteps).map((step) => ({ ...step, atMs: point(step.atMs) }));
|
|
11103
|
+
}
|
|
11104
|
+
async function snapshot2(source, destination, signal) {
|
|
11105
|
+
signal?.throwIfAborted();
|
|
11106
|
+
const handle = await open(source, constants2.O_RDONLY | (constants2.O_NOFOLLOW ?? 0));
|
|
11107
|
+
try {
|
|
11108
|
+
const info = await handle.stat();
|
|
11109
|
+
if (!info.isFile() || info.size < 1 || info.size > CAPTURE_RAW_MAX_BYTES) throw new CaptureVideoError("captureVideoInputInvalid");
|
|
11110
|
+
const header = Buffer.alloc(64);
|
|
11111
|
+
const { bytesRead } = await handle.read(header, 0, header.length, 0);
|
|
11112
|
+
const mp4 = bytesRead >= 12 && header.subarray(4, 8).toString() === "ftyp";
|
|
11113
|
+
const webm = bytesRead >= 4 && header.subarray(0, 4).equals(Buffer.from([26, 69, 223, 163])) && header.toString("latin1").includes("webm");
|
|
11114
|
+
if (!mp4 && !webm) throw new CaptureVideoError("captureVideoInputInvalid");
|
|
11115
|
+
const hash2 = createHash5("sha256"), stream = handle.createReadStream({ autoClose: false, start: 0, end: info.size - 1 });
|
|
11116
|
+
stream.on("data", (bytes) => hash2.update(bytes));
|
|
11117
|
+
await pipeline(stream, createWriteStream(destination, { flags: "wx", mode: 384 }), { signal });
|
|
11118
|
+
if ((await stat(destination)).size !== info.size) throw new CaptureVideoError("captureVideoInputChanged");
|
|
11119
|
+
return { size: info.size, sha256: hash2.digest("hex") };
|
|
11120
|
+
} finally {
|
|
11121
|
+
await handle.close();
|
|
11122
|
+
}
|
|
11123
|
+
}
|
|
11124
|
+
function videoFilter(windows, width, fps) {
|
|
11125
|
+
const seconds = (milliseconds2) => (milliseconds2 / 1e3).toFixed(3);
|
|
11126
|
+
const parts = windows.map((window, i) => `[0:v:0]trim=start=${seconds(window.startMs)}:end=${seconds(window.endMs)},setpts=PTS-STARTPTS[v${i}]`);
|
|
11127
|
+
const combined = windows.length === 1 ? "[v0]" : windows.map((_, i) => `[v${i}]`).join("") + `concat=n=${windows.length}:v=1:a=0,`;
|
|
11128
|
+
return `${parts.join(";")};${combined}scale=w='min(${width},iw)':h=-2:force_divisible_by=2,fps=${fps},format=yuv420p[out]`;
|
|
11129
|
+
}
|
|
11130
|
+
async function processCaptureVideo(input, output, options = {}) {
|
|
11131
|
+
const maximum = options.maxBytes ?? CAPTURE_VIDEO_MAX_BYTES;
|
|
11132
|
+
if (!Number.isSafeInteger(maximum) || maximum < 1 || maximum > CAPTURE_VIDEO_MAX_BYTES || resolve9(input) === resolve9(output))
|
|
11133
|
+
throw new CaptureVideoError("captureVideoOptionsInvalid");
|
|
11134
|
+
const steps = normalizeRecordingSteps(options.steps);
|
|
11135
|
+
const deadline = Date.now() + Math.min(options.timeoutMs ?? 9e4, 18e4);
|
|
11136
|
+
const binaries = await captureVideoBinaries();
|
|
11137
|
+
await mkdir2(dirname9(output), { recursive: true, mode: 448 });
|
|
11138
|
+
const temporary = await mkdtemp(join11(dirname9(output), ".capture-process-"));
|
|
11139
|
+
await chmod(temporary, 448);
|
|
11140
|
+
const run3 = async (binary, args) => {
|
|
11141
|
+
options.signal?.throwIfAborted();
|
|
11142
|
+
const remaining = deadline - Date.now();
|
|
11143
|
+
if (remaining <= 0) throw new CaptureVideoError("captureVideoProcessingTimeout");
|
|
11144
|
+
try {
|
|
11145
|
+
return await execute(binary, args, { timeout: remaining, maxBuffer: 256 * 1024, signal: options.signal, windowsHide: true });
|
|
11146
|
+
} catch (error) {
|
|
11147
|
+
throw new CaptureVideoError(["ENOENT", "EACCES", "ENOEXEC"].includes(error.code) ? "captureVideoDependencyUnavailable" : "captureVideoProcessingFailed", { cause: error });
|
|
11148
|
+
}
|
|
11149
|
+
};
|
|
11150
|
+
const probe = async (path3) => {
|
|
11151
|
+
const { stdout } = await run3(binaries.ffprobe, [
|
|
11152
|
+
"-v",
|
|
11153
|
+
"error",
|
|
11154
|
+
"-protocol_whitelist",
|
|
11155
|
+
"file,pipe",
|
|
11156
|
+
"-format_whitelist",
|
|
11157
|
+
"mov,matroska,webm",
|
|
11158
|
+
"-select_streams",
|
|
11159
|
+
"v:0",
|
|
11160
|
+
"-show_entries",
|
|
11161
|
+
"format=duration:stream=width,height,duration,nb_frames",
|
|
11162
|
+
"-of",
|
|
11163
|
+
"json",
|
|
11164
|
+
path3
|
|
11165
|
+
]);
|
|
11166
|
+
let value;
|
|
11167
|
+
try {
|
|
11168
|
+
value = JSON.parse(stdout);
|
|
11169
|
+
} catch (error) {
|
|
11170
|
+
throw new CaptureVideoError("captureVideoProbeInvalid", { cause: error });
|
|
11171
|
+
}
|
|
11172
|
+
const stream = value.streams?.[0], seconds = Number(value.format?.duration ?? stream?.duration);
|
|
11173
|
+
if (!stream || !Number.isFinite(seconds) || seconds <= 0 || seconds * 1e3 > MAX_DURATION_MS || !Number.isSafeInteger(stream.width) || stream.width < 1 || !Number.isSafeInteger(stream.height) || stream.height < 1)
|
|
11174
|
+
throw new CaptureVideoError("captureVideoProbeInvalid");
|
|
11175
|
+
return { durationMs: Math.round(seconds * 1e3), width: stream.width, height: stream.height };
|
|
11176
|
+
};
|
|
11177
|
+
try {
|
|
11178
|
+
const source = join11(temporary, "source.video");
|
|
11179
|
+
const originalFile = await snapshot2(input, source, options.signal);
|
|
11180
|
+
const original = await probe(source);
|
|
11181
|
+
const windows = recordingWindows(original.durationMs, steps);
|
|
11182
|
+
const retainedMs = windows.reduce((total, window) => total + window.endMs - window.startMs, 0);
|
|
11183
|
+
const result = join11(temporary, "final.mp4");
|
|
11184
|
+
const base = [
|
|
11185
|
+
"-y",
|
|
11186
|
+
"-nostdin",
|
|
11187
|
+
"-hide_banner",
|
|
11188
|
+
"-loglevel",
|
|
11189
|
+
"error",
|
|
11190
|
+
"-threads",
|
|
11191
|
+
"2",
|
|
11192
|
+
"-filter_complex_threads",
|
|
11193
|
+
"1",
|
|
11194
|
+
"-protocol_whitelist",
|
|
11195
|
+
"file,pipe",
|
|
11196
|
+
"-format_whitelist",
|
|
11197
|
+
"mov,matroska,webm",
|
|
11198
|
+
"-i",
|
|
11199
|
+
source
|
|
11200
|
+
];
|
|
11201
|
+
const encode2 = async (width, fps, rate, pass) => {
|
|
11202
|
+
await run3(binaries.ffmpeg, [
|
|
11203
|
+
...base,
|
|
11204
|
+
"-filter_complex",
|
|
11205
|
+
videoFilter(windows, width, fps),
|
|
11206
|
+
"-map",
|
|
11207
|
+
"[out]",
|
|
11208
|
+
"-map_metadata",
|
|
11209
|
+
"-1",
|
|
11210
|
+
"-map_chapters",
|
|
11211
|
+
"-1",
|
|
11212
|
+
"-an",
|
|
11213
|
+
"-sn",
|
|
11214
|
+
"-dn",
|
|
11215
|
+
"-c:v",
|
|
11216
|
+
"libx264",
|
|
11217
|
+
"-preset",
|
|
11218
|
+
"veryfast",
|
|
11219
|
+
"-threads",
|
|
11220
|
+
"2",
|
|
11221
|
+
"-pix_fmt",
|
|
11222
|
+
"yuv420p",
|
|
11223
|
+
...rate ? ["-b:v", `${rate}k`, "-pass", String(pass), "-passlogfile", join11(temporary, "pass")] : ["-crf", "28"],
|
|
11224
|
+
...pass === 1 ? ["-f", "null", devNull] : ["-movflags", "+faststart", result]
|
|
11225
|
+
]);
|
|
11226
|
+
};
|
|
11227
|
+
await encode2(1280, 15);
|
|
11228
|
+
if ((await stat(result)).size > maximum) {
|
|
11229
|
+
const rate = Math.floor(maximum * 0.82 * 8 / (retainedMs / 1e3) / 1e3);
|
|
11230
|
+
if (rate < 8) throw new CaptureVideoError("captureVideoTooLarge");
|
|
11231
|
+
for (const [width, fps, fraction] of [[960, 12, 1], [640, 10, 0.8]]) {
|
|
11232
|
+
await encode2(width, fps, Math.max(8, Math.floor(rate * fraction)), 1);
|
|
11233
|
+
await encode2(width, fps, Math.max(8, Math.floor(rate * fraction)), 2);
|
|
11234
|
+
if ((await stat(result)).size <= maximum) break;
|
|
11235
|
+
}
|
|
11236
|
+
}
|
|
11237
|
+
const size = (await stat(result)).size;
|
|
11238
|
+
if (size > maximum || size === 0) throw new CaptureVideoError("captureVideoTooLarge");
|
|
11239
|
+
const measured = await probe(result);
|
|
11240
|
+
if (measured.durationMs > MAX_DURATION_MS) throw new CaptureVideoError("captureVideoDurationInvalid");
|
|
11241
|
+
if (Math.abs(measured.durationMs - retainedMs) > Math.max(250, windows.length * 100))
|
|
11242
|
+
throw new CaptureVideoError("captureVideoDurationMismatch");
|
|
11243
|
+
await chmod(result, 384);
|
|
11244
|
+
if (await lstat2(output).catch(() => null)) throw new CaptureVideoError("captureVideoOutputExists");
|
|
11245
|
+
options.signal?.throwIfAborted();
|
|
11246
|
+
await rename(result, output);
|
|
11247
|
+
return {
|
|
11248
|
+
durationMs: measured.durationMs,
|
|
11249
|
+
size,
|
|
11250
|
+
steps: remapRecordingSteps(steps, windows, measured.durationMs),
|
|
11251
|
+
processing: {
|
|
11252
|
+
version: 1,
|
|
11253
|
+
originalDurationMs: original.durationMs,
|
|
11254
|
+
originalSize: originalFile.size,
|
|
11255
|
+
originalSha256: originalFile.sha256,
|
|
11256
|
+
trimmedMs: original.durationMs - retainedMs,
|
|
11257
|
+
retainedMs,
|
|
11258
|
+
windows,
|
|
11259
|
+
width: measured.width,
|
|
11260
|
+
height: measured.height
|
|
11261
|
+
}
|
|
11262
|
+
};
|
|
11263
|
+
} finally {
|
|
11264
|
+
await rm2(temporary, { recursive: true, force: true });
|
|
11265
|
+
}
|
|
11266
|
+
}
|
|
11267
|
+
if (process.argv[1] && basename4(process.argv[1]) === "capture-video.mjs" && pathToFileURL2(resolve9(process.argv[1])).href === import.meta.url) {
|
|
11268
|
+
try {
|
|
11269
|
+
const [, , input, output, metadata2] = process.argv;
|
|
11270
|
+
if (!input || !output || !metadata2 || process.argv.length !== 5) throw new CaptureVideoError("captureVideoOptionsInvalid");
|
|
11271
|
+
const options = JSON.parse(await readFile2(metadata2, "utf8"));
|
|
11272
|
+
const result = await processCaptureVideo(input, output, options);
|
|
11273
|
+
process.stdout.write(JSON.stringify(result) + "\n");
|
|
11274
|
+
} catch (error) {
|
|
11275
|
+
process.stderr.write((error instanceof CaptureVideoError ? error.code : "captureVideoProcessingFailed") + "\n");
|
|
11276
|
+
process.exitCode = 1;
|
|
11277
|
+
}
|
|
11278
|
+
}
|
|
11279
|
+
|
|
11280
|
+
// src/captures.ts
|
|
10911
11281
|
var CAPTURES_DIR = "captures";
|
|
10912
11282
|
var ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
10913
11283
|
var EXTENSIONS = ["png", "jpg", "webp", "mp4", "webm"];
|
|
10914
11284
|
function readPlain(path3, max) {
|
|
10915
11285
|
let fd;
|
|
10916
11286
|
try {
|
|
10917
|
-
fd = openSync2(path3,
|
|
11287
|
+
fd = openSync2(path3, constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0));
|
|
10918
11288
|
} catch {
|
|
10919
11289
|
return null;
|
|
10920
11290
|
}
|
|
10921
11291
|
try {
|
|
10922
|
-
const
|
|
10923
|
-
if (!
|
|
11292
|
+
const stat3 = fstatSync(fd);
|
|
11293
|
+
if (!stat3.isFile() || stat3.size > max) return null;
|
|
10924
11294
|
return new Uint8Array(readFileSync7(fd));
|
|
10925
11295
|
} finally {
|
|
10926
11296
|
closeSync2(fd);
|
|
10927
11297
|
}
|
|
10928
11298
|
}
|
|
10929
11299
|
var drop = (dir, id5) => {
|
|
10930
|
-
for (const name of [`${id5}.json`, ...EXTENSIONS.map((ext) => `${id5}.${ext}`)]) rmSync7(
|
|
11300
|
+
for (const name of [`${id5}.json`, ...EXTENSIONS.map((ext) => `${id5}.${ext}`)]) rmSync7(join12(dir, name), { force: true });
|
|
10931
11301
|
};
|
|
10932
|
-
async function
|
|
11302
|
+
async function hashPlain(path3, signal) {
|
|
11303
|
+
signal?.throwIfAborted();
|
|
11304
|
+
const fd = openSync2(path3, constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0));
|
|
11305
|
+
try {
|
|
11306
|
+
const info = fstatSync(fd);
|
|
11307
|
+
if (!info.isFile() || info.size < 1 || info.size > CAPTURE_RAW_MAX_BYTES) throw new Error("Invalid capture video input");
|
|
11308
|
+
const hash2 = createHash6("sha256");
|
|
11309
|
+
for await (const chunk of createReadStream(path3, { fd, autoClose: false, start: 0, end: info.size - 1, signal })) hash2.update(chunk);
|
|
11310
|
+
signal?.throwIfAborted();
|
|
11311
|
+
return hash2.digest("hex");
|
|
11312
|
+
} finally {
|
|
11313
|
+
closeSync2(fd);
|
|
11314
|
+
}
|
|
11315
|
+
}
|
|
11316
|
+
async function prepareVideo(file, id5, steps, pendingDir, signal) {
|
|
11317
|
+
signal?.throwIfAborted();
|
|
11318
|
+
const directory = pendingDir ?? mkdtempSync3(join12(tmpdir3(), "mikka-capture-pending-"));
|
|
11319
|
+
mkdirSync7(directory, { recursive: true, mode: 448 });
|
|
11320
|
+
const output = join12(directory, `${id5}.processed.mp4`), receipt = join12(directory, `${id5}.video.json`);
|
|
11321
|
+
try {
|
|
11322
|
+
const originalHash = await hashPlain(file, signal);
|
|
11323
|
+
const stepHash = createHash6("sha256").update(JSON.stringify(steps)).digest("hex");
|
|
11324
|
+
let result;
|
|
11325
|
+
const previous = readPlain(receipt, 128e3);
|
|
11326
|
+
if (previous) {
|
|
11327
|
+
try {
|
|
11328
|
+
const cached = JSON.parse(new TextDecoder().decode(previous));
|
|
11329
|
+
if (cached.originalHash === originalHash && cached.stepHash === stepHash && cached.result?.processing?.version === 1 && cached.result?.durationMs > 0 && cached.result.durationMs <= CAPTURE_MAX_DURATION_MS && await hashPlain(output, signal) === cached.sha256) result = cached.result;
|
|
11330
|
+
} catch {
|
|
11331
|
+
}
|
|
11332
|
+
}
|
|
11333
|
+
signal?.throwIfAborted();
|
|
11334
|
+
if (!result) {
|
|
11335
|
+
rmSync7(output, { force: true });
|
|
11336
|
+
rmSync7(receipt, { force: true });
|
|
11337
|
+
result = await processCaptureVideo(file, output, { steps, maxBytes: CAPTURE_MAX_BYTES.video, signal });
|
|
11338
|
+
if (result.processing.originalSha256 !== originalHash) throw new Error("Capture changed during video processing");
|
|
11339
|
+
writeJsonAtomic(receipt, { originalHash, stepHash, sha256: await hashPlain(output, signal), result });
|
|
11340
|
+
}
|
|
11341
|
+
signal?.throwIfAborted();
|
|
11342
|
+
const bytes = readPlain(output, CAPTURE_MAX_BYTES.video);
|
|
11343
|
+
if (!bytes || captureProblem(bytes, "video/mp4")) throw new Error("Processed capture video is invalid");
|
|
11344
|
+
return { bytes, durationMs: result.durationMs, steps: normalizeRecordingSteps(result.steps) };
|
|
11345
|
+
} finally {
|
|
11346
|
+
if (!pendingDir) rmSync7(directory, { recursive: true, force: true });
|
|
11347
|
+
}
|
|
11348
|
+
}
|
|
11349
|
+
function dropPrepared(pendingDir, id5) {
|
|
11350
|
+
if (!pendingDir) return;
|
|
11351
|
+
for (const name of [`${id5}.json`, `${id5}.processed.mp4`, `${id5}.video.json`]) rmSync7(join12(pendingDir, name), { force: true });
|
|
11352
|
+
}
|
|
11353
|
+
function fileType(path3) {
|
|
11354
|
+
let fd;
|
|
11355
|
+
try {
|
|
11356
|
+
fd = openSync2(path3, constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0));
|
|
11357
|
+
} catch {
|
|
11358
|
+
return null;
|
|
11359
|
+
}
|
|
11360
|
+
try {
|
|
11361
|
+
const info = fstatSync(fd);
|
|
11362
|
+
if (!info.isFile() || info.size < 1 || info.size > CAPTURE_RAW_MAX_BYTES) return null;
|
|
11363
|
+
const head = Buffer.alloc(64);
|
|
11364
|
+
return sniffCaptureType(head.subarray(0, readSync(fd, head, 0, head.length, 0)));
|
|
11365
|
+
} finally {
|
|
11366
|
+
closeSync2(fd);
|
|
11367
|
+
}
|
|
11368
|
+
}
|
|
11369
|
+
async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly = false, signal) {
|
|
11370
|
+
signal?.throwIfAborted();
|
|
10933
11371
|
if (!link.beginCapture || !link.sendCapture || !link.completeCapture) return 0;
|
|
10934
11372
|
if (!lstatSync7(dir, { throwIfNoEntry: false })?.isDirectory()) return 0;
|
|
10935
11373
|
let sent = 0;
|
|
10936
11374
|
for (const name of readdirSync4(dir).sort()) {
|
|
11375
|
+
signal?.throwIfAborted();
|
|
10937
11376
|
const id5 = name.endsWith(".json") ? name.slice(0, -5) : "";
|
|
10938
11377
|
if (!ID.test(id5)) continue;
|
|
10939
|
-
const meta = readPlain(
|
|
11378
|
+
const meta = readPlain(join12(dir, name), 128e3);
|
|
10940
11379
|
let title2 = "";
|
|
11380
|
+
let steps = [];
|
|
10941
11381
|
try {
|
|
10942
|
-
|
|
11382
|
+
const data = JSON.parse(new TextDecoder().decode(meta ?? new Uint8Array()));
|
|
11383
|
+
title2 = cleanCaptureTitle(String(data.title ?? ""));
|
|
11384
|
+
steps = normalizeRecordingSteps(data.steps);
|
|
10943
11385
|
} catch {
|
|
11386
|
+
title2 = "";
|
|
11387
|
+
}
|
|
11388
|
+
const file = EXTENSIONS.map((ext) => join12(dir, `${id5}.${ext}`)).find((path3) => lstatSync7(path3, { throwIfNoEntry: false }));
|
|
11389
|
+
const originalType = file ? fileType(file) : null;
|
|
11390
|
+
let video;
|
|
11391
|
+
if (file && title2 && originalType?.startsWith("video/")) {
|
|
11392
|
+
try {
|
|
11393
|
+
video = await prepareVideo(file, id5, steps, pendingDir, signal);
|
|
11394
|
+
} catch {
|
|
11395
|
+
signal?.throwIfAborted();
|
|
11396
|
+
log.warn({ run_id: runId, capture: id5 }, "capture video processing failed");
|
|
11397
|
+
continue;
|
|
11398
|
+
}
|
|
10944
11399
|
}
|
|
10945
|
-
|
|
10946
|
-
const bytes = file ? readPlain(file, CAPTURE_MAX_BYTES.
|
|
11400
|
+
signal?.throwIfAborted();
|
|
11401
|
+
const bytes = video?.bytes ?? (file && originalType?.startsWith("image/") ? readPlain(file, CAPTURE_MAX_BYTES.image) : null);
|
|
10947
11402
|
const problem = !title2 ? "no title" : !bytes ? "no regular file" : captureProblem(bytes);
|
|
10948
11403
|
const contentType = bytes && sniffCaptureType(bytes);
|
|
10949
11404
|
if (problem || !bytes || !contentType) {
|
|
@@ -10952,8 +11407,8 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
10952
11407
|
continue;
|
|
10953
11408
|
}
|
|
10954
11409
|
try {
|
|
10955
|
-
const sha2562 =
|
|
10956
|
-
const pendingPath = pendingDir ?
|
|
11410
|
+
const sha2562 = createHash6("sha256").update(bytes).digest("hex");
|
|
11411
|
+
const pendingPath = pendingDir ? join12(pendingDir, `${id5}.json`) : null;
|
|
10957
11412
|
let pending;
|
|
10958
11413
|
if (pendingPath) {
|
|
10959
11414
|
try {
|
|
@@ -10966,36 +11421,43 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
10966
11421
|
let target;
|
|
10967
11422
|
if (pending) {
|
|
10968
11423
|
try {
|
|
10969
|
-
await link.completeCapture(runId, pending.captureId);
|
|
11424
|
+
await link.completeCapture(runId, pending.captureId, signal);
|
|
11425
|
+
signal?.throwIfAborted();
|
|
10970
11426
|
drop(dir, id5);
|
|
10971
|
-
|
|
11427
|
+
dropPrepared(pendingDir, id5);
|
|
10972
11428
|
sent += 1;
|
|
10973
11429
|
continue;
|
|
10974
11430
|
} catch (error) {
|
|
11431
|
+
signal?.throwIfAborted();
|
|
10975
11432
|
if (!(error instanceof DaemonError) || error instanceof ServerUnreachableError || error.code !== 404) throw error;
|
|
10976
11433
|
}
|
|
10977
11434
|
if (!link.resumeCapture) return sent;
|
|
10978
11435
|
try {
|
|
10979
|
-
target = await link.resumeCapture(runId, pending.captureId);
|
|
11436
|
+
target = await link.resumeCapture(runId, pending.captureId, signal);
|
|
10980
11437
|
} catch (error) {
|
|
11438
|
+
signal?.throwIfAborted();
|
|
10981
11439
|
if (existingOnly || !(error instanceof DaemonError) || error instanceof ServerUnreachableError || error.code !== 404) throw error;
|
|
10982
|
-
target = await link.beginCapture(runId, { captureId: pending.captureId, title: title2, contentType, size: bytes.length, sha256: sha2562 });
|
|
11440
|
+
target = await link.beginCapture(runId, { captureId: pending.captureId, title: title2, contentType, size: bytes.length, sha256: sha2562, ...video ? { durationMs: video.durationMs, steps: video.steps } : {} }, signal);
|
|
10983
11441
|
}
|
|
10984
11442
|
} else {
|
|
10985
11443
|
if (pendingPath) {
|
|
10986
11444
|
mkdirSync7(pendingDir, { recursive: true, mode: 448 });
|
|
10987
11445
|
writeJsonAtomic(pendingPath, { captureId: id5, sha256: sha2562 });
|
|
10988
11446
|
}
|
|
10989
|
-
target = await link.beginCapture(runId, {
|
|
10990
|
-
if (
|
|
11447
|
+
target = await link.beginCapture(runId, { captureId: id5, title: title2, contentType, size: bytes.length, sha256: sha2562, ...video ? { durationMs: video.durationMs, steps: video.steps } : {} }, signal);
|
|
11448
|
+
if (target.captureId !== id5) throw new Error("Capture reservation id changed");
|
|
10991
11449
|
}
|
|
11450
|
+
signal?.throwIfAborted();
|
|
10992
11451
|
const { captureId, upload } = target;
|
|
10993
|
-
await link.sendCapture(runId, captureId, upload, bytes, contentType);
|
|
10994
|
-
|
|
11452
|
+
await link.sendCapture(runId, captureId, upload, bytes, contentType, signal);
|
|
11453
|
+
signal?.throwIfAborted();
|
|
11454
|
+
await link.completeCapture(runId, captureId, signal);
|
|
11455
|
+
signal?.throwIfAborted();
|
|
10995
11456
|
drop(dir, id5);
|
|
10996
|
-
|
|
11457
|
+
dropPrepared(pendingDir, id5);
|
|
10997
11458
|
sent += 1;
|
|
10998
11459
|
} catch (error) {
|
|
11460
|
+
signal?.throwIfAborted();
|
|
10999
11461
|
if (error instanceof ServerUnreachableError) {
|
|
11000
11462
|
log.warn({ run_id: runId, capture: id5 }, "capture upload deferred");
|
|
11001
11463
|
return sent;
|
|
@@ -11004,13 +11466,13 @@ async function uploadCaptures(dir, runId, link, log, pendingDir, existingOnly =
|
|
|
11004
11466
|
log.warn({ run_id: runId, capture: id5, status: error.code }, "capture reservation unavailable; retry stopped");
|
|
11005
11467
|
if (pendingDir) {
|
|
11006
11468
|
mkdirSync7(pendingDir, { recursive: true, mode: 448 });
|
|
11007
|
-
writeJsonAtomic(
|
|
11469
|
+
writeJsonAtomic(join12(pendingDir, "blocked.json"), { status: error.code });
|
|
11008
11470
|
}
|
|
11009
11471
|
return sent;
|
|
11010
11472
|
}
|
|
11011
11473
|
log.warn({ run_id: runId, capture: id5, status: error instanceof DaemonError ? error.code : void 0 }, "capture refused");
|
|
11012
11474
|
drop(dir, id5);
|
|
11013
|
-
|
|
11475
|
+
dropPrepared(pendingDir, id5);
|
|
11014
11476
|
}
|
|
11015
11477
|
}
|
|
11016
11478
|
return sent;
|
|
@@ -11027,15 +11489,31 @@ var CaptureUploader = class {
|
|
|
11027
11489
|
log;
|
|
11028
11490
|
pendingRoot;
|
|
11029
11491
|
passes = /* @__PURE__ */ new Map();
|
|
11030
|
-
|
|
11492
|
+
/** A final signal bounds both this pass and any earlier pass still in flight. */
|
|
11493
|
+
flush(runId, existingOnly = false, signal) {
|
|
11031
11494
|
if (!/^[A-Za-z0-9_-]{1,64}$/.test(runId)) return Promise.resolve();
|
|
11032
|
-
const pendingDir = this.pendingRoot ?
|
|
11033
|
-
if (pendingDir && lstatSync7(
|
|
11034
|
-
|
|
11035
|
-
const
|
|
11036
|
-
|
|
11495
|
+
const pendingDir = this.pendingRoot ? join12(this.pendingRoot, runId) : void 0;
|
|
11496
|
+
if (pendingDir && lstatSync7(join12(pendingDir, "blocked.json"), { throwIfNoEntry: false }))
|
|
11497
|
+
return signal ? Promise.reject(new Error("Capture upload incomplete")) : Promise.resolve();
|
|
11498
|
+
const pass = this.passes.get(runId) ?? { tail: Promise.resolve(), abort: new AbortController() };
|
|
11499
|
+
const abort = () => pass.abort.abort(signal?.reason);
|
|
11500
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
11501
|
+
if (signal?.aborted) abort();
|
|
11502
|
+
const next = pass.tail.catch(() => void 0).then(async () => {
|
|
11503
|
+
const dir = this.dirFor(runId);
|
|
11504
|
+
await uploadCaptures(dir, runId, this.link, this.log, pendingDir, existingOnly, pass.abort.signal);
|
|
11505
|
+
pass.abort.signal.throwIfAborted();
|
|
11506
|
+
if (signal && lstatSync7(dir, { throwIfNoEntry: false })?.isDirectory() && readdirSync4(dir).some((name) => name.endsWith(".json") && ID.test(name.slice(0, -5))))
|
|
11507
|
+
throw new Error("Capture upload incomplete");
|
|
11508
|
+
}).catch((error) => {
|
|
11509
|
+
if (signal) throw error;
|
|
11510
|
+
this.log.warn({ run_id: runId, reason: pass.abort.signal.aborted ? "cancelled" : "failed" }, "capture upload failed");
|
|
11511
|
+
}).finally(() => {
|
|
11512
|
+
signal?.removeEventListener("abort", abort);
|
|
11513
|
+
if (this.passes.get(runId)?.tail === next) this.passes.delete(runId);
|
|
11037
11514
|
});
|
|
11038
|
-
|
|
11515
|
+
pass.tail = next;
|
|
11516
|
+
this.passes.set(runId, pass);
|
|
11039
11517
|
return next;
|
|
11040
11518
|
}
|
|
11041
11519
|
};
|
|
@@ -11060,7 +11538,7 @@ var HARNESS_DOMAINS = {
|
|
|
11060
11538
|
"*.cursorapi.com"
|
|
11061
11539
|
]
|
|
11062
11540
|
};
|
|
11063
|
-
var MCP_SERVER_SCRIPT =
|
|
11541
|
+
var MCP_SERVER_SCRIPT = resolve10(import.meta.dirname, "mikka-mcp.mjs");
|
|
11064
11542
|
var MCP_SERVER_NAME = "mikka";
|
|
11065
11543
|
var COMPUTER_MCP_SERVER_NAME = "mikka_computer";
|
|
11066
11544
|
var RUN_GIT_CONFIG = [["maintenance.auto", "false"], ["gc.auto", "0"]];
|
|
@@ -11091,7 +11569,7 @@ function credentialDenyRead(harness, home = homedir4()) {
|
|
|
11091
11569
|
// Other harnesses' logins; each harness still reads its own.
|
|
11092
11570
|
...harness === "codex" ? [] : [".codex/auth.json"],
|
|
11093
11571
|
...harness === "claude_code" ? [] : [".claude/.credentials.json"]
|
|
11094
|
-
].map((path3) =>
|
|
11572
|
+
].map((path3) => join13(home, path3));
|
|
11095
11573
|
}
|
|
11096
11574
|
function daemonSecrets(dataDir) {
|
|
11097
11575
|
const paths = daemonPaths(realpathSync9(dataDir));
|
|
@@ -11102,18 +11580,18 @@ function daemonSecrets(dataDir) {
|
|
|
11102
11580
|
paths.outbox,
|
|
11103
11581
|
paths.logs,
|
|
11104
11582
|
paths.devRepos,
|
|
11105
|
-
|
|
11583
|
+
join13(paths.adapterState, "pids")
|
|
11106
11584
|
];
|
|
11107
11585
|
}
|
|
11108
11586
|
function runPaths(stateDir, runId) {
|
|
11109
11587
|
const id5 = assertSafeId("run id", runId);
|
|
11110
11588
|
return {
|
|
11111
11589
|
/** The daemon's data dir (`stateDir` is `<dataDir>/adapters`). */
|
|
11112
|
-
privateDir:
|
|
11590
|
+
privateDir: resolve10(stateDir, ".."),
|
|
11113
11591
|
/** Writable from the sandbox. */
|
|
11114
|
-
runDir:
|
|
11592
|
+
runDir: join13(stateDir, "runs", id5),
|
|
11115
11593
|
/** Daemon only. */
|
|
11116
|
-
pidFile:
|
|
11594
|
+
pidFile: join13(stateDir, "pids", `${id5}.pgid`)
|
|
11117
11595
|
};
|
|
11118
11596
|
}
|
|
11119
11597
|
function repositorySkill(worktree, slug) {
|
|
@@ -11121,7 +11599,7 @@ function repositorySkill(worktree, slug) {
|
|
|
11121
11599
|
const missing2 = (reason) => ({ id: id5, name: slug, description: "", source: "repository", digest: null, instructions: null, available: false, reason });
|
|
11122
11600
|
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(slug)) return missing2("invalid");
|
|
11123
11601
|
for (const root of [".claude/skills", ".agents/skills"]) {
|
|
11124
|
-
const file =
|
|
11602
|
+
const file = join13(worktree, root, slug, SKILL_BODY_FILE);
|
|
11125
11603
|
const meta = lstatSync8(file, { throwIfNoEntry: false });
|
|
11126
11604
|
if (!meta) continue;
|
|
11127
11605
|
if (!meta.isFile() || meta.isSymbolicLink() || meta.nlink !== 1 || meta.size < 1 || meta.size > MAX_PROFILE_SKILL_INSTRUCTIONS_LENGTH) return missing2("invalid");
|
|
@@ -11143,7 +11621,7 @@ function repositorySkill(worktree, slug) {
|
|
|
11143
11621
|
name: (declaredName || slug).slice(0, 80),
|
|
11144
11622
|
description: description.slice(0, 500),
|
|
11145
11623
|
source: "repository",
|
|
11146
|
-
digest:
|
|
11624
|
+
digest: createHash7("sha256").update(body, "utf8").digest("hex"),
|
|
11147
11625
|
instructions: body,
|
|
11148
11626
|
available: true
|
|
11149
11627
|
};
|
|
@@ -11157,16 +11635,16 @@ function writeProfileSkillManifest(options, runDir, worktree, includeRepository)
|
|
|
11157
11635
|
if (assigned.length > MAX_PROFILE_SKILLS_PER_RUN || declared.length > MAX_PROFILE_SKILLS_PER_RUN) throw new Error("Profile Skill assignment limit");
|
|
11158
11636
|
const entries = [];
|
|
11159
11637
|
for (const skill of assigned) {
|
|
11160
|
-
const digest9 =
|
|
11638
|
+
const digest9 = createHash7("sha256").update(skill.instructions, "utf8").digest("hex");
|
|
11161
11639
|
if (digest9 !== skill.digest) throw new Error("Profile Skill artifact digest mismatch");
|
|
11162
11640
|
entries.push({ id: skill.id, name: skill.name, description: skill.description, source: skill.source, digest: digest9, instructions: skill.instructions, available: true });
|
|
11163
11641
|
}
|
|
11164
11642
|
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" });
|
|
11165
11643
|
const unique = [...new Map(entries.map((entry) => [entry.id, entry])).values()];
|
|
11166
|
-
const dir =
|
|
11644
|
+
const dir = join13(runDir, PROFILE_SKILLS_DIR);
|
|
11167
11645
|
ownDir(dir);
|
|
11168
11646
|
const manifest = { version: 1, skills: unique };
|
|
11169
|
-
const file =
|
|
11647
|
+
const file = join13(dir, PROFILE_SKILL_MANIFEST_FILE);
|
|
11170
11648
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
11171
11649
|
writeFileSync4(tmp, `${JSON.stringify(manifest)}
|
|
11172
11650
|
`, { encoding: "utf8", mode: 384 });
|
|
@@ -11177,11 +11655,11 @@ function prepareRunContextFiles(options) {
|
|
|
11177
11655
|
ownDir(options.runDir);
|
|
11178
11656
|
const runDir = realpathSync9(options.runDir);
|
|
11179
11657
|
const files2 = {
|
|
11180
|
-
worktree:
|
|
11658
|
+
worktree: resolve10(options.worktree),
|
|
11181
11659
|
runDir,
|
|
11182
|
-
handoffFile:
|
|
11183
|
-
tmpDir:
|
|
11184
|
-
capturesDir:
|
|
11660
|
+
handoffFile: join13(runDir, "handoff.json"),
|
|
11661
|
+
tmpDir: join13(runDir, "tmp"),
|
|
11662
|
+
capturesDir: join13(runDir, CAPTURES_DIR)
|
|
11185
11663
|
};
|
|
11186
11664
|
ownDir(files2.tmpDir);
|
|
11187
11665
|
ownDir(files2.capturesDir);
|
|
@@ -11215,7 +11693,7 @@ function runMcpServer(options, files2) {
|
|
|
11215
11693
|
files2.worktree,
|
|
11216
11694
|
"--capture-root",
|
|
11217
11695
|
files2.tmpDir,
|
|
11218
|
-
...options.profileSkills?.length || options.repositorySkills?.length ? ["--profile-skills",
|
|
11696
|
+
...options.profileSkills?.length || options.repositorySkills?.length ? ["--profile-skills", join13(files2.runDir, PROFILE_SKILLS_DIR)] : [],
|
|
11219
11697
|
...options.factoryCheck && (!options.factoryCheck.reportOnly || options.factoryCheck.inferCommand) ? ["--factory-verify", JSON.stringify({ cwd: files2.worktree, command: options.verifyCommand ?? null, infer: options.factoryCheck.inferCommand })] : [],
|
|
11220
11698
|
...options.factoryCheck?.reportOnly || readOnlyInspection ? ["--factory-artifacts", files2.worktree] : [],
|
|
11221
11699
|
...repositoryExecution ? ["--repository-selection", files2.worktree] : []
|
|
@@ -11263,13 +11741,13 @@ var RunContext = class {
|
|
|
11263
11741
|
);
|
|
11264
11742
|
ownDir(options.runDir);
|
|
11265
11743
|
this.runDir = realpathSync9(options.runDir);
|
|
11266
|
-
this.handoffFile =
|
|
11267
|
-
this.skillsDir =
|
|
11268
|
-
this.tmpDir =
|
|
11744
|
+
this.handoffFile = join13(this.runDir, "handoff.json");
|
|
11745
|
+
this.skillsDir = join13(this.runDir, SKILLS_DIR);
|
|
11746
|
+
this.tmpDir = join13(this.runDir, "tmp");
|
|
11269
11747
|
ownDir(this.tmpDir);
|
|
11270
|
-
this.capturesDir =
|
|
11748
|
+
this.capturesDir = join13(this.runDir, CAPTURES_DIR);
|
|
11271
11749
|
ownDir(this.capturesDir);
|
|
11272
|
-
this.profileSkillsDir =
|
|
11750
|
+
this.profileSkillsDir = join13(this.runDir, PROFILE_SKILLS_DIR);
|
|
11273
11751
|
this.writeSkills();
|
|
11274
11752
|
this.writeProfileSkills();
|
|
11275
11753
|
if (options.github && !options.machineEnvironment) {
|
|
@@ -11312,23 +11790,23 @@ var RunContext = class {
|
|
|
11312
11790
|
let slug = base;
|
|
11313
11791
|
for (let n = 2; taken.has(slug); n += 1) slug = `${base}-${n}`;
|
|
11314
11792
|
taken.add(slug);
|
|
11315
|
-
const dir =
|
|
11793
|
+
const dir = join13(this.skillsDir, slug);
|
|
11316
11794
|
if (this.options.skillReceipt) {
|
|
11317
11795
|
const existing = lstatSync8(dir, { throwIfNoEntry: false });
|
|
11318
11796
|
if (existing && (!existing.isDirectory() || existing.isSymbolicLink())) throw new Error("Unsafe Skill artifact directory");
|
|
11319
|
-
const file = lstatSync8(
|
|
11797
|
+
const file = lstatSync8(join13(dir, SKILL_BODY_FILE), { throwIfNoEntry: false });
|
|
11320
11798
|
if (file && (!file.isFile() || file.isSymbolicLink() || file.nlink !== 1)) throw new Error("Unsafe Skill artifact file");
|
|
11321
11799
|
}
|
|
11322
11800
|
mkdirSync8(dir, { recursive: true });
|
|
11323
|
-
const bodyFile =
|
|
11801
|
+
const bodyFile = join13(dir, SKILL_BODY_FILE);
|
|
11324
11802
|
if (this.options.skillReceipt) {
|
|
11325
11803
|
if (!lstatSync8(bodyFile, { throwIfNoEntry: false })) writeFileSync4(bodyFile, skillMarkdown(skill), { encoding: "utf8", flag: "wx", mode: 384 });
|
|
11326
11804
|
} else writeFileSync4(bodyFile, skillMarkdown(skill), "utf8");
|
|
11327
|
-
if (this.options.skillReceipt) verifyMountedSkill(
|
|
11805
|
+
if (this.options.skillReceipt) verifyMountedSkill(join13(dir, SKILL_BODY_FILE), this.options.skillReceipt);
|
|
11328
11806
|
for (const file of skill.files) {
|
|
11329
|
-
const target =
|
|
11807
|
+
const target = resolve10(dir, file.path);
|
|
11330
11808
|
if (!target.startsWith(`${dir}/`)) continue;
|
|
11331
|
-
mkdirSync8(
|
|
11809
|
+
mkdirSync8(dirname10(target), { recursive: true });
|
|
11332
11810
|
writeFileSync4(target, file.content, "utf8");
|
|
11333
11811
|
}
|
|
11334
11812
|
}
|
|
@@ -11362,14 +11840,14 @@ var RunContext = class {
|
|
|
11362
11840
|
denyWrite: [
|
|
11363
11841
|
// The fixture's refs/objects are writable for push; its configuration
|
|
11364
11842
|
// and hooks must remain host-owned because fixture verification runs Git.
|
|
11365
|
-
...fixtureOrigin ? [
|
|
11366
|
-
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11843
|
+
...fixtureOrigin ? [join13(fixtureOrigin, "config"), join13(fixtureOrigin, "hooks")] : [],
|
|
11844
|
+
join13(this.worktree, ".git"),
|
|
11845
|
+
join13(this.gitDir, "commondir"),
|
|
11846
|
+
join13(this.gitDir, "gitdir"),
|
|
11847
|
+
join13(this.gitDir, "config.worktree"),
|
|
11370
11848
|
// A repository's config and hooks in the shared clone, outside the
|
|
11371
11849
|
// working directory, are declared read-only here too.
|
|
11372
|
-
...this.options.gitWritePaths?.length ? [
|
|
11850
|
+
...this.options.gitWritePaths?.length ? [join13(this.gitDir, "..", "..", "config"), join13(this.gitDir, "..", "..", "hooks")] : [],
|
|
11373
11851
|
...readOnly ? [this.worktree, ...this.options.gitWritePaths ?? []] : []
|
|
11374
11852
|
],
|
|
11375
11853
|
denyRead: [
|
|
@@ -11423,7 +11901,7 @@ var RunContext = class {
|
|
|
11423
11901
|
*/
|
|
11424
11902
|
tempEnv() {
|
|
11425
11903
|
if (this.options.machineEnvironment) return this.options.policyHash ? { MIKKA_POLICY_HASH: this.options.policyHash } : {};
|
|
11426
|
-
return { TMPDIR: this.tmpDir, TMPPREFIX:
|
|
11904
|
+
return { TMPDIR: this.tmpDir, TMPPREFIX: join13(this.tmpDir, "zsh"), ...withGitConfig(this.githubEnv, RUN_GIT_CONFIG), ...this.options.policyHash ? { MIKKA_POLICY_HASH: this.options.policyHash } : {} };
|
|
11427
11905
|
}
|
|
11428
11906
|
/**
|
|
11429
11907
|
* The agent delivers this run itself: it commits, pushes to the task
|
|
@@ -11439,17 +11917,18 @@ var RunContext = class {
|
|
|
11439
11917
|
}
|
|
11440
11918
|
/** The agent's hand-in as the session's exit, or null if it made none. */
|
|
11441
11919
|
readHandoff(log) {
|
|
11442
|
-
const
|
|
11443
|
-
if (!
|
|
11920
|
+
const stat3 = lstatSync8(this.handoffFile, { throwIfNoEntry: false });
|
|
11921
|
+
if (!stat3) return null;
|
|
11444
11922
|
let file;
|
|
11445
11923
|
try {
|
|
11446
|
-
if (!
|
|
11924
|
+
if (!stat3.isFile()) throw new Error("not a regular file");
|
|
11447
11925
|
file = JSON.parse(readFileSync8(this.handoffFile, "utf8"));
|
|
11448
11926
|
} catch (error) {
|
|
11449
11927
|
log?.warn({ err: error }, "unreadable handoff file; ignoring it");
|
|
11450
11928
|
return null;
|
|
11451
11929
|
}
|
|
11452
11930
|
const plan = this.options.kind === "plan" ? planFromHandoff(file.plan, log) : null;
|
|
11931
|
+
const visualEvidence = runVisualEvidence.safeParse(file.visualEvidence);
|
|
11453
11932
|
const question = runQuestion.safeParse(file.question);
|
|
11454
11933
|
const repositorySelection = !this.options.factoryCheck && ["implement", "fix"].includes(this.options.kind ?? "") ? runRepositorySelection.safeParse(file.repositorySelection) : null;
|
|
11455
11934
|
const report2 = {
|
|
@@ -11462,6 +11941,7 @@ var RunContext = class {
|
|
|
11462
11941
|
...plan ? { plan } : {},
|
|
11463
11942
|
...typeof file.previewDatabaseBranch === "string" ? { previewDatabaseBranch: file.previewDatabaseBranch } : {},
|
|
11464
11943
|
...Array.isArray(file.criteria) ? { criteria: file.criteria } : {},
|
|
11944
|
+
...visualEvidence.success ? { visualEvidence: visualEvidence.data } : {},
|
|
11465
11945
|
...file.reviewVerdict ? { reviewVerdict: file.reviewVerdict } : {},
|
|
11466
11946
|
...file.verificationCommand ? { verificationCommand: file.verificationCommand } : {},
|
|
11467
11947
|
...runQuestion.safeParse(file.question).success ? { question: runQuestion.parse(file.question) } : {}
|
|
@@ -11907,8 +12387,8 @@ var PromptQueue = class {
|
|
|
11907
12387
|
continue;
|
|
11908
12388
|
}
|
|
11909
12389
|
if (this.closed) return;
|
|
11910
|
-
await new Promise((
|
|
11911
|
-
this.waiter =
|
|
12390
|
+
await new Promise((resolve20) => {
|
|
12391
|
+
this.waiter = resolve20;
|
|
11912
12392
|
});
|
|
11913
12393
|
}
|
|
11914
12394
|
}
|
|
@@ -11922,8 +12402,8 @@ async function untilSpoken(spoken) {
|
|
|
11922
12402
|
try {
|
|
11923
12403
|
return await Promise.race([
|
|
11924
12404
|
spoken,
|
|
11925
|
-
new Promise((
|
|
11926
|
-
timer = setTimeout(() =>
|
|
12405
|
+
new Promise((resolve20) => {
|
|
12406
|
+
timer = setTimeout(() => resolve20(true), CONTINUE_SILENCE_MS);
|
|
11927
12407
|
})
|
|
11928
12408
|
]);
|
|
11929
12409
|
} finally {
|
|
@@ -12066,15 +12546,15 @@ var ClaudeAdapter = class {
|
|
|
12066
12546
|
throw new Error(SUBSCRIPTION_ERROR, { cause: error });
|
|
12067
12547
|
}
|
|
12068
12548
|
}
|
|
12069
|
-
const nativeHome = options.machineEnvironment ? options.env.HOME :
|
|
12549
|
+
const nativeHome = options.machineEnvironment ? options.env.HOME : join14(runDir, "native-home");
|
|
12070
12550
|
if (!nativeHome) throw new Error("Cloud machine HOME unavailable");
|
|
12071
|
-
const configDir = options.machineEnvironment ? options.env.CLAUDE_CONFIG_DIR ??
|
|
12551
|
+
const configDir = options.machineEnvironment ? options.env.CLAUDE_CONFIG_DIR ?? join14(nativeHome, ".claude") : join14(nativeHome, ".claude");
|
|
12072
12552
|
if (!options.machineEnvironment) {
|
|
12073
12553
|
ownDir(nativeHome);
|
|
12074
12554
|
ownDir(configDir);
|
|
12075
12555
|
}
|
|
12076
12556
|
if (!options.machineEnvironment && mode === "continue" && options.continueSession) {
|
|
12077
|
-
carryHistory(
|
|
12557
|
+
carryHistory(join14(runPaths(this.options.stateDir, options.continueSession.runId).runDir, "native-home", ".claude"), configDir, ["projects"]);
|
|
12078
12558
|
}
|
|
12079
12559
|
if (externalAuth && options.credential) throw new Error(SUBSCRIPTION_ERROR);
|
|
12080
12560
|
const credentialEnv = claudeCredentialEnv(options.credential);
|
|
@@ -12109,8 +12589,8 @@ var ClaudeAdapter = class {
|
|
|
12109
12589
|
privateDir: paths.privateDir,
|
|
12110
12590
|
// Its session store, so `resume` works; keyed by the cwd it sees.
|
|
12111
12591
|
extraWrite: preparing ? [] : [
|
|
12112
|
-
|
|
12113
|
-
|
|
12592
|
+
join14(configDir, "projects", claudeProjectDirName(options.cwd)),
|
|
12593
|
+
join14(
|
|
12114
12594
|
configDir,
|
|
12115
12595
|
"projects",
|
|
12116
12596
|
claudeProjectDirName(realpathSync10(options.cwd))
|
|
@@ -12144,15 +12624,15 @@ var ClaudeAdapter = class {
|
|
|
12144
12624
|
let authTimer;
|
|
12145
12625
|
let stderr = "";
|
|
12146
12626
|
let stderrArrived = () => void 0;
|
|
12147
|
-
const firstStderr = new Promise((
|
|
12148
|
-
stderrArrived =
|
|
12627
|
+
const firstStderr = new Promise((resolve20) => {
|
|
12628
|
+
stderrArrived = resolve20;
|
|
12149
12629
|
});
|
|
12150
12630
|
const stderrTail = () => stderr.slice(-STDERR_TAIL2).trim() || "no output";
|
|
12151
12631
|
let spoke = () => void 0;
|
|
12152
|
-
const spoken = new Promise((
|
|
12632
|
+
const spoken = new Promise((resolve20) => spoke = resolve20);
|
|
12153
12633
|
let checkingContinuation = mode === "continue";
|
|
12154
12634
|
let finished = () => void 0;
|
|
12155
|
-
const gone = new Promise((
|
|
12635
|
+
const gone = new Promise((resolve20) => finished = resolve20);
|
|
12156
12636
|
let nativeExit = Promise.resolve(false);
|
|
12157
12637
|
if (externalAuth && this.options.onHostedSession) {
|
|
12158
12638
|
try {
|
|
@@ -12191,10 +12671,10 @@ var ClaudeAdapter = class {
|
|
|
12191
12671
|
stderr = previousStderr.slice(-STDERR_TAIL2 * 4);
|
|
12192
12672
|
stderrArrived();
|
|
12193
12673
|
}
|
|
12194
|
-
nativeExit = new Promise((
|
|
12195
|
-
child.once("exit", () =>
|
|
12196
|
-
child.once("error", () =>
|
|
12197
|
-
if (child.exitCode !== null || child.signalCode)
|
|
12674
|
+
nativeExit = new Promise((resolve20) => {
|
|
12675
|
+
child.once("exit", () => resolve20(true));
|
|
12676
|
+
child.once("error", () => resolve20(false));
|
|
12677
|
+
if (child.exitCode !== null || child.signalCode) resolve20(true);
|
|
12198
12678
|
});
|
|
12199
12679
|
child.stderr?.on("data", (data) => {
|
|
12200
12680
|
stderr = (stderr + data.toString()).slice(-STDERR_TAIL2 * 4);
|
|
@@ -12253,7 +12733,7 @@ var ClaudeAdapter = class {
|
|
|
12253
12733
|
if (preparation) {
|
|
12254
12734
|
const { binding, control } = preparation;
|
|
12255
12735
|
const fixed = claudePrewarmOptionsKey(options);
|
|
12256
|
-
const parking =
|
|
12736
|
+
const parking = join14(runDir, "claude-parking");
|
|
12257
12737
|
ownDir(parking);
|
|
12258
12738
|
let anonymousAdopted = false;
|
|
12259
12739
|
const prepared = prepareClaudeSession({
|
|
@@ -12420,8 +12900,8 @@ var ClaudeAdapter = class {
|
|
|
12420
12900
|
if (!message.is_error) quota = void 0;
|
|
12421
12901
|
if (message.is_error && externalAuth && !stderr) {
|
|
12422
12902
|
let drainTimer;
|
|
12423
|
-
await Promise.race([firstStderr, new Promise((
|
|
12424
|
-
drainTimer = setTimeout(
|
|
12903
|
+
await Promise.race([firstStderr, new Promise((resolve20) => {
|
|
12904
|
+
drainTimer = setTimeout(resolve20, 100);
|
|
12425
12905
|
})]);
|
|
12426
12906
|
clearTimeout(drainTimer);
|
|
12427
12907
|
}
|
|
@@ -12609,7 +13089,7 @@ function codexFailureMessage(phase, info) {
|
|
|
12609
13089
|
}
|
|
12610
13090
|
|
|
12611
13091
|
// src/adapters/codex.ts
|
|
12612
|
-
import { delimiter as delimiter3, dirname as
|
|
13092
|
+
import { delimiter as delimiter3, dirname as dirname11, isAbsolute as isAbsolute5, join as join16, relative as relative4 } from "node:path";
|
|
12613
13093
|
import { mkdirSync as mkdirSync10 } from "node:fs";
|
|
12614
13094
|
|
|
12615
13095
|
// src/codex-generation-telemetry.ts
|
|
@@ -13029,11 +13509,11 @@ async function startCodexGenerationCollector(emit) {
|
|
|
13029
13509
|
server.requestTimeout = 1e3;
|
|
13030
13510
|
server.headersTimeout = 1e3;
|
|
13031
13511
|
server.maxConnections = 4;
|
|
13032
|
-
await new Promise((
|
|
13512
|
+
await new Promise((resolve20, reject) => {
|
|
13033
13513
|
server.once("error", reject);
|
|
13034
13514
|
server.listen(0, "127.0.0.1", () => {
|
|
13035
13515
|
server.off("error", reject);
|
|
13036
|
-
|
|
13516
|
+
resolve20();
|
|
13037
13517
|
});
|
|
13038
13518
|
});
|
|
13039
13519
|
server.on("error", () => collector.reject());
|
|
@@ -13053,7 +13533,7 @@ async function startCodexGenerationCollector(emit) {
|
|
|
13053
13533
|
"-c",
|
|
13054
13534
|
"otel.log_guardian_assessments=false"
|
|
13055
13535
|
],
|
|
13056
|
-
close: (cliExitObserved = false) => closed ??= new Promise((
|
|
13536
|
+
close: (cliExitObserved = false) => closed ??= new Promise((resolve20) => {
|
|
13057
13537
|
const timer = setTimeout(() => {
|
|
13058
13538
|
collector.truncate();
|
|
13059
13539
|
server.closeAllConnections();
|
|
@@ -13061,7 +13541,7 @@ async function startCodexGenerationCollector(emit) {
|
|
|
13061
13541
|
timer.unref();
|
|
13062
13542
|
server.close(() => {
|
|
13063
13543
|
clearTimeout(timer);
|
|
13064
|
-
|
|
13544
|
+
resolve20(collector.finish(cliExitObserved));
|
|
13065
13545
|
});
|
|
13066
13546
|
})
|
|
13067
13547
|
};
|
|
@@ -13104,11 +13584,11 @@ var JsonlWriter = class extends AbstractMessageWriter {
|
|
|
13104
13584
|
}
|
|
13105
13585
|
stream;
|
|
13106
13586
|
write(message) {
|
|
13107
|
-
return new Promise((
|
|
13587
|
+
return new Promise((resolve20, reject) => {
|
|
13108
13588
|
this.stream.write(
|
|
13109
13589
|
`${JSON.stringify(message)}
|
|
13110
13590
|
`,
|
|
13111
|
-
(error) => error ? reject(error) :
|
|
13591
|
+
(error) => error ? reject(error) : resolve20()
|
|
13112
13592
|
);
|
|
13113
13593
|
});
|
|
13114
13594
|
}
|
|
@@ -13124,8 +13604,8 @@ function jsonlConnection(input, output) {
|
|
|
13124
13604
|
}
|
|
13125
13605
|
|
|
13126
13606
|
// src/adapters/codex-mailbox.ts
|
|
13127
|
-
import { closeSync as closeSync3, constants as
|
|
13128
|
-
import { isAbsolute as isAbsolute4, join as
|
|
13607
|
+
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";
|
|
13608
|
+
import { isAbsolute as isAbsolute4, join as join15, relative as relative3, sep as sep2 } from "node:path";
|
|
13129
13609
|
import { isDeepStrictEqual } from "node:util";
|
|
13130
13610
|
var unavailable2 = () => new Error("Run mailbox requires a verified original Codex thread");
|
|
13131
13611
|
function codexMailboxResumeVersion(userAgent) {
|
|
@@ -13142,15 +13622,15 @@ function historyParts(value) {
|
|
|
13142
13622
|
return parts;
|
|
13143
13623
|
}
|
|
13144
13624
|
function receiptFile(stateDir, runId) {
|
|
13145
|
-
return
|
|
13625
|
+
return join15(stateDir, "codex-mailbox", assertSafeId("run id", runId) + ".json");
|
|
13146
13626
|
}
|
|
13147
13627
|
function readJson2(file, limit, firstLine = false) {
|
|
13148
|
-
const fd = openSync3(file,
|
|
13628
|
+
const fd = openSync3(file, constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK);
|
|
13149
13629
|
try {
|
|
13150
|
-
const
|
|
13151
|
-
if (!
|
|
13152
|
-
const buffer = Buffer.alloc(Math.min(
|
|
13153
|
-
const length =
|
|
13630
|
+
const stat3 = fstatSync2(fd);
|
|
13631
|
+
if (!stat3.isFile() || stat3.nlink !== 1 || !firstLine && stat3.size > limit) throw unavailable2();
|
|
13632
|
+
const buffer = Buffer.alloc(Math.min(stat3.size, limit + 1));
|
|
13633
|
+
const length = readSync2(fd, buffer, 0, buffer.length, 0);
|
|
13154
13634
|
const end = firstLine ? buffer.subarray(0, length).indexOf(10) : length;
|
|
13155
13635
|
if (end < 0 || end > limit) throw unavailable2();
|
|
13156
13636
|
return JSON.parse(buffer.subarray(0, end).toString("utf8"));
|
|
@@ -13162,16 +13642,16 @@ function verifyHistory(home, path3, threadId, catalogue) {
|
|
|
13162
13642
|
const parts = historyParts(path3);
|
|
13163
13643
|
let parent = home;
|
|
13164
13644
|
for (const part of ["", ...parts.slice(0, -1)]) {
|
|
13165
|
-
if (part) parent =
|
|
13166
|
-
const
|
|
13167
|
-
if (!
|
|
13645
|
+
if (part) parent = join15(parent, part);
|
|
13646
|
+
const stat3 = lstatSync9(parent);
|
|
13647
|
+
if (!stat3.isDirectory() || stat3.isSymbolicLink()) throw unavailable2();
|
|
13168
13648
|
}
|
|
13169
|
-
const header = readJson2(
|
|
13649
|
+
const header = readJson2(join15(home, ...parts), 1024 * 1024, true);
|
|
13170
13650
|
if (header?.type !== "session_meta" || header.payload?.id !== threadId || !isDeepStrictEqual(header.payload.dynamic_tools, catalogue)) throw unavailable2();
|
|
13171
13651
|
}
|
|
13172
13652
|
function verifyCodexMailboxResume(stateDir, sourceRunId, home, threadId, catalogue) {
|
|
13173
13653
|
try {
|
|
13174
|
-
const dir = lstatSync9(
|
|
13654
|
+
const dir = lstatSync9(join15(stateDir, "codex-mailbox"));
|
|
13175
13655
|
if (!dir.isDirectory() || dir.isSymbolicLink()) throw unavailable2();
|
|
13176
13656
|
const receipt = readJson2(receiptFile(stateDir, sourceRunId), 256 * 1024);
|
|
13177
13657
|
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();
|
|
@@ -13187,10 +13667,10 @@ function recordCodexMailboxSession(stateDir, runId, home, thread, catalogue, res
|
|
|
13187
13667
|
const historyPath = relative3(home, thread.path).split(sep2).join("/");
|
|
13188
13668
|
historyParts(historyPath);
|
|
13189
13669
|
if (resumed) verifyHistory(home, historyPath, thread.id, catalogue);
|
|
13190
|
-
const dir =
|
|
13670
|
+
const dir = join15(stateDir, "codex-mailbox");
|
|
13191
13671
|
mkdirSync9(dir, { recursive: true, mode: 448 });
|
|
13192
|
-
const
|
|
13193
|
-
if (!
|
|
13672
|
+
const stat3 = lstatSync9(dir);
|
|
13673
|
+
if (!stat3.isDirectory() || stat3.isSymbolicLink()) throw unavailable2();
|
|
13194
13674
|
writeJsonAtomic(receiptFile(stateDir, runId), { version: 1, nativeVersion, runId, threadId: thread.id, historyPath, catalogue });
|
|
13195
13675
|
} catch {
|
|
13196
13676
|
if (resumed) throw unavailable2();
|
|
@@ -13451,8 +13931,8 @@ var CodexAdapter = class {
|
|
|
13451
13931
|
options.continueSession.runId
|
|
13452
13932
|
).runDir;
|
|
13453
13933
|
carryHistory(
|
|
13454
|
-
|
|
13455
|
-
|
|
13934
|
+
join16(earlier2, "codex-home"),
|
|
13935
|
+
join16(runDir, "codex-home"),
|
|
13456
13936
|
CODEX_HISTORY
|
|
13457
13937
|
);
|
|
13458
13938
|
} catch (error) {
|
|
@@ -13463,7 +13943,7 @@ var CodexAdapter = class {
|
|
|
13463
13943
|
log.info({ err: error }, "could not copy the earlier codex threads");
|
|
13464
13944
|
}
|
|
13465
13945
|
}
|
|
13466
|
-
const codexHome = options.machineEnvironment ? { home: options.env.CODEX_HOME ??
|
|
13946
|
+
const codexHome = options.machineEnvironment ? { home: options.env.CODEX_HOME ?? join16(options.env.HOME, ".codex") } : prepareCodexHome(join16(runDir, "codex-home"), log);
|
|
13467
13947
|
if (options.machineEnvironment) mkdirSync10(codexHome.home, { recursive: true, mode: 448 });
|
|
13468
13948
|
const mailboxResumeVersion = mailboxCatalogue && threadId ? verifyCodexMailboxResume(
|
|
13469
13949
|
this.options.stateDir,
|
|
@@ -13474,7 +13954,7 @@ var CodexAdapter = class {
|
|
|
13474
13954
|
) : null;
|
|
13475
13955
|
const computerMcp = this.options.computerMcp ?? this.options.computerProvider?.(options.runId, options.policy);
|
|
13476
13956
|
const binary = this.options.binary ?? await this.options.ensureBinary?.() ?? "codex";
|
|
13477
|
-
const childPath = isAbsolute5(binary) ?
|
|
13957
|
+
const childPath = isAbsolute5(binary) ? dirname11(binary) + delimiter3 + (options.env.PATH ?? "") : options.env.PATH;
|
|
13478
13958
|
if (externalAuth && options.credential) throw new Error(SUBSCRIPTION_AUTH_ERROR);
|
|
13479
13959
|
const credential = codexCredential(brokerAuth ? { kind: "provider", protocol: "openai", baseUrl: "https://mikka.invalid", key: NATIVE_AUTH_PLACEHOLDER } : options.credential);
|
|
13480
13960
|
const providerDomain = credentialDomain(options.credential);
|
|
@@ -13650,7 +14130,6 @@ var CodexAdapter = class {
|
|
|
13650
14130
|
);
|
|
13651
14131
|
const queue = new EventQueue();
|
|
13652
14132
|
const streamed = /* @__PURE__ */ new Set();
|
|
13653
|
-
const pending = [];
|
|
13654
14133
|
let activeTurn = null;
|
|
13655
14134
|
let pendingTurnStart = null;
|
|
13656
14135
|
let ending = false;
|
|
@@ -13696,11 +14175,6 @@ var CodexAdapter = class {
|
|
|
13696
14175
|
ending = true;
|
|
13697
14176
|
pendingMcp.clear();
|
|
13698
14177
|
options.toolApproval?.revoke();
|
|
13699
|
-
if (pending.length > 0)
|
|
13700
|
-
log.warn(
|
|
13701
|
-
{ dropped: pending.length },
|
|
13702
|
-
"session ended with unsent messages"
|
|
13703
|
-
);
|
|
13704
14178
|
rpc.dispose();
|
|
13705
14179
|
await child.kill();
|
|
13706
14180
|
if (event) {
|
|
@@ -13883,17 +14357,6 @@ var CodexAdapter = class {
|
|
|
13883
14357
|
});
|
|
13884
14358
|
}
|
|
13885
14359
|
}
|
|
13886
|
-
const next = pending.shift();
|
|
13887
|
-
if (next) {
|
|
13888
|
-
await startTurn(next).catch(
|
|
13889
|
-
(error) => finish({
|
|
13890
|
-
outcome: "failed",
|
|
13891
|
-
error: managedAuth ? turnStartFailure ?? subscriptionFailure("turn_start", codexFailureInfo(error)) : error instanceof ProviderFailureError ? error.message : `Codex: ${errorMessage(error)}`,
|
|
13892
|
-
...error instanceof ProviderFailureError ? { providerFailure: error.providerFailure } : {}
|
|
13893
|
-
})
|
|
13894
|
-
);
|
|
13895
|
-
return;
|
|
13896
|
-
}
|
|
13897
14360
|
if (turn.status === "failed" || lastError) {
|
|
13898
14361
|
quota = mergeQuota(quota, codexQuotaSignal(turn.error, rateLimits));
|
|
13899
14362
|
const failure2 = codexFailureInfo(turn.error);
|
|
@@ -14080,7 +14543,7 @@ var CodexAdapter = class {
|
|
|
14080
14543
|
sessionId,
|
|
14081
14544
|
runtimeModel,
|
|
14082
14545
|
events: () => queue.drain(),
|
|
14083
|
-
async send(message) {
|
|
14546
|
+
async send(message, mode2) {
|
|
14084
14547
|
sensitiveText.push(message);
|
|
14085
14548
|
if (ending) throw new Error("The Codex session already ended");
|
|
14086
14549
|
if (activeTurn) {
|
|
@@ -14091,11 +14554,16 @@ var CodexAdapter = class {
|
|
|
14091
14554
|
expectedTurnId: activeTurn
|
|
14092
14555
|
});
|
|
14093
14556
|
return;
|
|
14094
|
-
} catch {
|
|
14557
|
+
} catch (error) {
|
|
14558
|
+
const failure2 = codexFailureInfo(error);
|
|
14559
|
+
const { category, rpcCode } = failure2;
|
|
14560
|
+
const code = rpcCode === void 0 ? "" : `, RPC ${rpcCode}`;
|
|
14561
|
+
throw new Error(`Codex could not steer the active turn (${category}${code})`, { cause: failure2 });
|
|
14095
14562
|
}
|
|
14096
14563
|
}
|
|
14097
|
-
if (
|
|
14098
|
-
|
|
14564
|
+
if (ending) throw new Error("The Codex session already ended");
|
|
14565
|
+
if (mode2 === "steer") throw new Error("The Codex turn is no longer active");
|
|
14566
|
+
await startTurn(message);
|
|
14099
14567
|
},
|
|
14100
14568
|
async cancel() {
|
|
14101
14569
|
cancelling = true;
|
|
@@ -14119,7 +14587,7 @@ var CodexAdapter = class {
|
|
|
14119
14587
|
// src/adapters/cursor.ts
|
|
14120
14588
|
import { Readable, Writable } from "node:stream";
|
|
14121
14589
|
import * as acp from "@agentclientprotocol/sdk";
|
|
14122
|
-
import { join as
|
|
14590
|
+
import { join as join17 } from "node:path";
|
|
14123
14591
|
function cursorAppServers(apps) {
|
|
14124
14592
|
return [
|
|
14125
14593
|
...(apps?.apps ?? []).map((app) => ({ type: "http", name: app.name, url: app.url, headers: [{ name: "Authorization", value: `Bearer ${apps.token}` }] })),
|
|
@@ -14251,15 +14719,15 @@ var CursorAdapter = class {
|
|
|
14251
14719
|
options.continueSession.runId
|
|
14252
14720
|
).runDir;
|
|
14253
14721
|
carryHistory(
|
|
14254
|
-
|
|
14255
|
-
|
|
14722
|
+
join17(earlier2, "cursor-home"),
|
|
14723
|
+
join17(paths.runDir, "cursor-home"),
|
|
14256
14724
|
CURSOR_HISTORY
|
|
14257
14725
|
);
|
|
14258
14726
|
} catch (error) {
|
|
14259
14727
|
log.info({ err: error }, "could not copy the earlier cursor chats");
|
|
14260
14728
|
}
|
|
14261
14729
|
}
|
|
14262
|
-
const configDir = prepareCursorHome(
|
|
14730
|
+
const configDir = prepareCursorHome(join17(paths.runDir, "cursor-home"));
|
|
14263
14731
|
const ctx = new RunContext({
|
|
14264
14732
|
github: options.github,
|
|
14265
14733
|
githubEnvironment: options.githubEnvironment,
|
|
@@ -14494,7 +14962,7 @@ ${firstMessage}` : firstMessage
|
|
|
14494
14962
|
// src/adapters/mock.ts
|
|
14495
14963
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
14496
14964
|
import { mkdirSync as mkdirSync11, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "node:fs";
|
|
14497
|
-
import { dirname as
|
|
14965
|
+
import { dirname as dirname12, join as join18, resolve as resolve11 } from "node:path";
|
|
14498
14966
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
14499
14967
|
import { execa as execa5 } from "execa";
|
|
14500
14968
|
|
|
@@ -14526,7 +14994,7 @@ function isRunChunk(value) {
|
|
|
14526
14994
|
}
|
|
14527
14995
|
|
|
14528
14996
|
// src/adapters/mock.ts
|
|
14529
|
-
var DEFAULT_FIXTURES_DIR =
|
|
14997
|
+
var DEFAULT_FIXTURES_DIR = resolve11(
|
|
14530
14998
|
import.meta.dirname,
|
|
14531
14999
|
true ? "./fixtures" : "../../fixtures"
|
|
14532
15000
|
);
|
|
@@ -14560,7 +15028,7 @@ var MockAdapter = class {
|
|
|
14560
15028
|
fixturesDir;
|
|
14561
15029
|
speed;
|
|
14562
15030
|
stateFile(sessionId) {
|
|
14563
|
-
return
|
|
15031
|
+
return join18(
|
|
14564
15032
|
this.options.stateDir,
|
|
14565
15033
|
`mock-${assertSafeId("session id", sessionId)}.json`
|
|
14566
15034
|
);
|
|
@@ -14604,7 +15072,7 @@ var MockAdapter = class {
|
|
|
14604
15072
|
open(sessionId, state2, options) {
|
|
14605
15073
|
const name = assertSafeId("fixture", state2.fixture.replace(/\.jsonl$/, ""));
|
|
14606
15074
|
const lines = parseFixture(
|
|
14607
|
-
readFileSync9(
|
|
15075
|
+
readFileSync9(join18(this.fixturesDir, `${name}.jsonl`), "utf8"),
|
|
14608
15076
|
name
|
|
14609
15077
|
);
|
|
14610
15078
|
const abort = new AbortController();
|
|
@@ -14642,7 +15110,7 @@ var MockAdapter = class {
|
|
|
14642
15110
|
if (line.hang) {
|
|
14643
15111
|
if (!abort.signal.aborted) {
|
|
14644
15112
|
await new Promise(
|
|
14645
|
-
(
|
|
15113
|
+
(resolve20) => abort.signal.addEventListener("abort", resolve20, { once: true })
|
|
14646
15114
|
);
|
|
14647
15115
|
}
|
|
14648
15116
|
yield { type: "exit", outcome: "cancelled" };
|
|
@@ -14654,8 +15122,8 @@ var MockAdapter = class {
|
|
|
14654
15122
|
`mock fixture writes outside the worktree: ${line.write.path}`
|
|
14655
15123
|
);
|
|
14656
15124
|
}
|
|
14657
|
-
const target =
|
|
14658
|
-
mkdirSync11(
|
|
15125
|
+
const target = resolve11(options.cwd, line.write.path);
|
|
15126
|
+
mkdirSync11(dirname12(target), { recursive: true });
|
|
14659
15127
|
writeFileSync5(target, line.write.content);
|
|
14660
15128
|
}
|
|
14661
15129
|
if (line.chunk) yield { type: "chunk", chunk: line.chunk };
|
|
@@ -14717,14 +15185,14 @@ var MockAdapter = class {
|
|
|
14717
15185
|
};
|
|
14718
15186
|
|
|
14719
15187
|
// src/agents/local-github.ts
|
|
14720
|
-
import { mkdirSync as mkdirSync13, mkdtempSync as
|
|
15188
|
+
import { mkdirSync as mkdirSync13, mkdtempSync as mkdtempSync4, rmSync as rmSync10, writeFileSync as writeFileSync7 } from "node:fs";
|
|
14721
15189
|
import { homedir as homedir5 } from "node:os";
|
|
14722
|
-
import { delimiter as delimiter4, join as
|
|
15190
|
+
import { delimiter as delimiter4, join as join20 } from "node:path";
|
|
14723
15191
|
|
|
14724
15192
|
// src/agents/machine-github.ts
|
|
14725
15193
|
import { existsSync as existsSync4, mkdirSync as mkdirSync12, readFileSync as readFileSync10, renameSync as renameSync3, rmSync as rmSync9, writeFileSync as writeFileSync6 } from "node:fs";
|
|
14726
15194
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
14727
|
-
import { dirname as
|
|
15195
|
+
import { dirname as dirname13, join as join19 } from "node:path";
|
|
14728
15196
|
function githubHosts(contents, token) {
|
|
14729
15197
|
if (!token || /[\r\n\0]/.test(token) || token.length > 32768) throw Error("github_credential_invalid");
|
|
14730
15198
|
const lines = contents.split(/\r?\n/);
|
|
@@ -14749,8 +15217,8 @@ function prepareMachineGitHub(github, host) {
|
|
|
14749
15217
|
if (!github.token) throw Error("github_credential_missing");
|
|
14750
15218
|
const home = host.env.HOME;
|
|
14751
15219
|
if (!home) throw Error("github_home_missing");
|
|
14752
|
-
const directory = host.env.GH_CONFIG_DIR ??
|
|
14753
|
-
const file =
|
|
15220
|
+
const directory = host.env.GH_CONFIG_DIR ?? join19(host.env.XDG_CONFIG_HOME ?? join19(home, ".config"), "gh");
|
|
15221
|
+
const file = join19(directory, "hosts.yml");
|
|
14754
15222
|
const original = existsSync4(file) ? readFileSync10(file, "utf8") : void 0;
|
|
14755
15223
|
let written;
|
|
14756
15224
|
let closed = false;
|
|
@@ -14764,7 +15232,7 @@ function prepareMachineGitHub(github, host) {
|
|
|
14764
15232
|
host.onCredential?.("GITHUB_TOKEN", credential.token);
|
|
14765
15233
|
const latest = existsSync4(file) ? readFileSync10(file, "utf8") : "";
|
|
14766
15234
|
const next = githubHosts(latest, credential.token);
|
|
14767
|
-
mkdirSync12(
|
|
15235
|
+
mkdirSync12(dirname13(file), { recursive: true, mode: 448 });
|
|
14768
15236
|
const temporary = `${file}.${randomUUID4()}`;
|
|
14769
15237
|
writeFileSync6(temporary, next, { mode: 384, flag: "wx" });
|
|
14770
15238
|
renameSync3(temporary, file);
|
|
@@ -14850,14 +15318,14 @@ async function prepareLocalGitHub(assignment, host) {
|
|
|
14850
15318
|
const credential = assignment.github.token ? { token: assignment.github.token, expiresAt: assignment.github.expiresAt ?? null } : await lease();
|
|
14851
15319
|
if (host.signal.aborted) throw Error("github_run_closed");
|
|
14852
15320
|
mkdirSync13(host.stateDir, { recursive: true, mode: 448 });
|
|
14853
|
-
const directory =
|
|
15321
|
+
const directory = mkdtempSync4(join20(host.stateDir, "github-"));
|
|
14854
15322
|
try {
|
|
14855
|
-
const bin =
|
|
15323
|
+
const bin = join20(directory, "bin");
|
|
14856
15324
|
const quote2 = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
14857
15325
|
const helper2 = `${process.versions.electron ? "env ELECTRON_RUN_AS_NODE=1 " : ""}${quote2(process.execPath)} ${quote2(GITHUB_CREDENTIAL_SCRIPT)}`;
|
|
14858
15326
|
if (binary) {
|
|
14859
15327
|
mkdirSync13(bin, { mode: 448 });
|
|
14860
|
-
writeFileSync7(
|
|
15328
|
+
writeFileSync7(join20(bin, "gh"), `#!/bin/sh
|
|
14861
15329
|
exec ${helper2} native-gh ${quote2(binary)} ${quote2(directory)} "$@"
|
|
14862
15330
|
`, { mode: 448, flag: "wx" });
|
|
14863
15331
|
}
|
|
@@ -14897,18 +15365,18 @@ exec ${helper2} native-gh ${quote2(binary)} ${quote2(directory)} "$@"
|
|
|
14897
15365
|
}
|
|
14898
15366
|
|
|
14899
15367
|
// src/agents/verify.ts
|
|
14900
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync14, mkdtempSync as
|
|
14901
|
-
import { join as
|
|
15368
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync14, mkdtempSync as mkdtempSync5, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
|
|
15369
|
+
import { join as join21 } from "node:path";
|
|
14902
15370
|
var OUTPUT_TAIL = 4e3;
|
|
14903
15371
|
var SETUP_ATTEMPTS = 3;
|
|
14904
15372
|
async function runVerify(sandbox, options) {
|
|
14905
15373
|
options.signal?.throwIfAborted();
|
|
14906
15374
|
mkdirSync14(options.tmpRoot, { recursive: true, mode: 448 });
|
|
14907
|
-
const tmpDir =
|
|
15375
|
+
const tmpDir = mkdtempSync5(join21(realpathSync11(options.tmpRoot), "verify-"));
|
|
14908
15376
|
const deadline = Date.now() + options.timeoutMs;
|
|
14909
15377
|
try {
|
|
14910
15378
|
for (let attempt = 1; ; attempt++) {
|
|
14911
|
-
const started =
|
|
15379
|
+
const started = join21(tmpDir, `.started-${attempt}`);
|
|
14912
15380
|
const result = await attemptVerify(sandbox, options, tmpDir, started, deadline - Date.now());
|
|
14913
15381
|
if (result.exitCode === 0 || result.timedOut || options.signal?.aborted || existsSync5(started) || attempt >= SETUP_ATTEMPTS)
|
|
14914
15382
|
return result;
|
|
@@ -14927,7 +15395,7 @@ async function attemptVerify(sandbox, options, tmpDir, started, timeoutMs) {
|
|
|
14927
15395
|
policy: {
|
|
14928
15396
|
allowWrite: options.readOnly ? [tmpDir] : [options.worktree, tmpDir],
|
|
14929
15397
|
denyWrite: [
|
|
14930
|
-
|
|
15398
|
+
join21(options.worktree, ".git"),
|
|
14931
15399
|
...options.readOnly ? [options.worktree] : []
|
|
14932
15400
|
],
|
|
14933
15401
|
denyRead: [
|
|
@@ -14997,12 +15465,12 @@ var NoSandbox = class {
|
|
|
14997
15465
|
};
|
|
14998
15466
|
|
|
14999
15467
|
// src/fs-browse.ts
|
|
15000
|
-
import { execFile as
|
|
15001
|
-
import { readdir as readdir2, realpath, stat } from "node:fs/promises";
|
|
15468
|
+
import { execFile as execFile4 } from "node:child_process";
|
|
15469
|
+
import { readdir as readdir2, realpath, stat as stat2 } from "node:fs/promises";
|
|
15002
15470
|
import { homedir as homedir6, platform as platform2 } from "node:os";
|
|
15003
|
-
import { basename as
|
|
15004
|
-
import { promisify as
|
|
15005
|
-
var run =
|
|
15471
|
+
import { basename as basename5, dirname as dirname14, isAbsolute as isAbsolute6, join as join22, resolve as resolve12 } from "node:path";
|
|
15472
|
+
import { promisify as promisify4 } from "node:util";
|
|
15473
|
+
var run = promisify4(execFile4);
|
|
15006
15474
|
async function git(cwd, args) {
|
|
15007
15475
|
try {
|
|
15008
15476
|
const { stdout } = await run("git", ["-C", cwd, ...args], {
|
|
@@ -15016,14 +15484,14 @@ async function git(cwd, args) {
|
|
|
15016
15484
|
}
|
|
15017
15485
|
async function isDir(path3) {
|
|
15018
15486
|
try {
|
|
15019
|
-
return (await
|
|
15487
|
+
return (await stat2(path3)).isDirectory();
|
|
15020
15488
|
} catch {
|
|
15021
15489
|
return false;
|
|
15022
15490
|
}
|
|
15023
15491
|
}
|
|
15024
15492
|
async function exists(path3) {
|
|
15025
15493
|
try {
|
|
15026
|
-
await
|
|
15494
|
+
await stat2(path3);
|
|
15027
15495
|
return true;
|
|
15028
15496
|
} catch {
|
|
15029
15497
|
return false;
|
|
@@ -15046,7 +15514,7 @@ async function browseFolder(request2) {
|
|
|
15046
15514
|
code: "not_found",
|
|
15047
15515
|
message: "Expected an absolute path."
|
|
15048
15516
|
};
|
|
15049
|
-
const path3 =
|
|
15517
|
+
const path3 = resolve12(wanted);
|
|
15050
15518
|
if (!await exists(path3))
|
|
15051
15519
|
return { ok: false, code: "not_found", message: `${path3} does not exist.` };
|
|
15052
15520
|
if (!await isDir(path3))
|
|
@@ -15070,7 +15538,7 @@ async function browseFolder(request2) {
|
|
|
15070
15538
|
let truncated = false;
|
|
15071
15539
|
const dirs = names.filter((e) => e.isDirectory() || e.isSymbolicLink()).filter((e) => request2.showHidden || !e.name.startsWith(".")).sort((a, b) => a.name.localeCompare(b.name));
|
|
15072
15540
|
for (const entry of dirs) {
|
|
15073
|
-
const full =
|
|
15541
|
+
const full = join22(path3, entry.name);
|
|
15074
15542
|
if (entry.isSymbolicLink() && !await isDir(full)) continue;
|
|
15075
15543
|
if (folders.length >= FS_MAX_ENTRIES) {
|
|
15076
15544
|
truncated = true;
|
|
@@ -15079,14 +15547,14 @@ async function browseFolder(request2) {
|
|
|
15079
15547
|
folders.push({
|
|
15080
15548
|
name: entry.name,
|
|
15081
15549
|
path: full,
|
|
15082
|
-
isRepo: await exists(
|
|
15550
|
+
isRepo: await exists(join22(full, ".git"))
|
|
15083
15551
|
});
|
|
15084
15552
|
}
|
|
15085
|
-
const parent =
|
|
15553
|
+
const parent = dirname14(path3);
|
|
15086
15554
|
return {
|
|
15087
15555
|
ok: true,
|
|
15088
15556
|
path: path3,
|
|
15089
|
-
parent: parent === path3 ||
|
|
15557
|
+
parent: parent === path3 || basename5(path3) === "" ? null : parent,
|
|
15090
15558
|
home,
|
|
15091
15559
|
platform: platform2(),
|
|
15092
15560
|
entries: folders,
|
|
@@ -15107,7 +15575,7 @@ async function verifyExpectedOrigin(path3, expected2) {
|
|
|
15107
15575
|
}
|
|
15108
15576
|
|
|
15109
15577
|
// src/device-type.ts
|
|
15110
|
-
import { readdir as readdir3, readFile as
|
|
15578
|
+
import { readdir as readdir3, readFile as readFile3 } from "node:fs/promises";
|
|
15111
15579
|
import { execa as execa6 } from "execa";
|
|
15112
15580
|
async function detectDeviceType() {
|
|
15113
15581
|
try {
|
|
@@ -15123,7 +15591,7 @@ async function detectDeviceType() {
|
|
|
15123
15591
|
const entries = await readdir3("/sys/class/power_supply");
|
|
15124
15592
|
const types = await Promise.all(
|
|
15125
15593
|
entries.map(
|
|
15126
|
-
(entry) =>
|
|
15594
|
+
(entry) => readFile3(`/sys/class/power_supply/${entry}/type`, "utf8").catch(
|
|
15127
15595
|
() => ""
|
|
15128
15596
|
)
|
|
15129
15597
|
)
|
|
@@ -15141,13 +15609,13 @@ import { arch, platform as platform3 } from "node:os";
|
|
|
15141
15609
|
import { execa as execa7 } from "execa";
|
|
15142
15610
|
|
|
15143
15611
|
// harness/install.mjs
|
|
15144
|
-
import { createHash as
|
|
15145
|
-
import { execFile as
|
|
15146
|
-
import { createWriteStream, 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";
|
|
15147
|
-
import { dirname as
|
|
15612
|
+
import { createHash as createHash8, randomBytes as randomBytes2 } from "node:crypto";
|
|
15613
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
15614
|
+
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";
|
|
15615
|
+
import { dirname as dirname15, join as join23, relative as relative5 } from "node:path";
|
|
15148
15616
|
import { Readable as Readable2, Transform } from "node:stream";
|
|
15149
|
-
import { pipeline } from "node:stream/promises";
|
|
15150
|
-
import { promisify as
|
|
15617
|
+
import { pipeline as pipeline2 } from "node:stream/promises";
|
|
15618
|
+
import { promisify as promisify5 } from "node:util";
|
|
15151
15619
|
|
|
15152
15620
|
// harness/pins.json
|
|
15153
15621
|
var pins_default = {
|
|
@@ -15183,7 +15651,7 @@ var HARNESS_PINS = pins_default;
|
|
|
15183
15651
|
var MARKER = ".mikka-installed";
|
|
15184
15652
|
var INSTALL_FORMAT = "complete-package-v1\n";
|
|
15185
15653
|
var installMarker = (pin, artifact) => INSTALL_FORMAT + artifact.integrity + (pin.companions?.length ? "\n" + pin.companions.join("\n") : "");
|
|
15186
|
-
var run2 =
|
|
15654
|
+
var run2 = promisify5(execFile5);
|
|
15187
15655
|
var inflight = /* @__PURE__ */ new Map();
|
|
15188
15656
|
function platformKey(platform5 = process.platform, arch3 = process.arch) {
|
|
15189
15657
|
return `${platform5}-${arch3}`;
|
|
@@ -15193,19 +15661,19 @@ function resolvePin(store, harness) {
|
|
|
15193
15661
|
return { pin, artifact: pin.platforms[store.platform ?? platformKey()] };
|
|
15194
15662
|
}
|
|
15195
15663
|
function versionDir(store, harness) {
|
|
15196
|
-
return
|
|
15664
|
+
return join23(store.root, harness, resolvePin(store, harness).pin.version);
|
|
15197
15665
|
}
|
|
15198
15666
|
function harnessBinaryPath(store, harness) {
|
|
15199
|
-
return
|
|
15667
|
+
return join23(versionDir(store, harness), "bin", resolvePin(store, harness).pin.command);
|
|
15200
15668
|
}
|
|
15201
15669
|
function harnessInstallState(store, harness) {
|
|
15202
15670
|
const { pin, artifact } = resolvePin(store, harness);
|
|
15203
15671
|
if (!artifact) return { state: "unsupported", version: pin.version };
|
|
15204
15672
|
let installed = false;
|
|
15205
15673
|
try {
|
|
15206
|
-
installed = readFileSync11(
|
|
15207
|
-
const
|
|
15208
|
-
return
|
|
15674
|
+
installed = readFileSync11(join23(versionDir(store, harness), MARKER), "utf8") === installMarker(pin, artifact) && runtimeFiles(store, harness).every((path3) => {
|
|
15675
|
+
const stat3 = statSync2(path3);
|
|
15676
|
+
return stat3.isFile() && (stat3.mode & 73) !== 0;
|
|
15209
15677
|
});
|
|
15210
15678
|
} catch {
|
|
15211
15679
|
}
|
|
@@ -15213,7 +15681,7 @@ function harnessInstallState(store, harness) {
|
|
|
15213
15681
|
}
|
|
15214
15682
|
function runtimeFiles(store, harness) {
|
|
15215
15683
|
const binary = harnessBinaryPath(store, harness);
|
|
15216
|
-
return harness === "codex" ? [binary,
|
|
15684
|
+
return harness === "codex" ? [binary, join23(dirname15(binary), "codex-code-mode-host")] : [binary];
|
|
15217
15685
|
}
|
|
15218
15686
|
function ensureHarness(store, harness) {
|
|
15219
15687
|
const key2 = `${store.root}\0${harness}`;
|
|
@@ -15230,27 +15698,27 @@ async function install(store, harness) {
|
|
|
15230
15698
|
if (state2 === "unsupported") throw new Error(`${harness} has no build for ${store.platform ?? platformKey()}`);
|
|
15231
15699
|
if (state2 === "installed") return binary;
|
|
15232
15700
|
const { pin, artifact } = resolvePin(store, harness);
|
|
15233
|
-
const parent =
|
|
15701
|
+
const parent = join23(store.root, harness);
|
|
15234
15702
|
mkdirSync15(parent, { recursive: true, mode: 448 });
|
|
15235
|
-
const staging =
|
|
15703
|
+
const staging = join23(parent, `.staging-${randomBytes2(6).toString("hex")}`);
|
|
15236
15704
|
mkdirSync15(staging, { recursive: true, mode: 448 });
|
|
15237
15705
|
try {
|
|
15238
|
-
const tarball =
|
|
15706
|
+
const tarball = join23(staging, "package.tgz");
|
|
15239
15707
|
await download(`${(store.pins ?? HARNESS_PINS).registry.replace(/\/$/, "")}/${artifact.tarball}`, tarball, artifact.integrity);
|
|
15240
15708
|
await run2("tar", ["-xzf", tarball, "-C", staging]);
|
|
15241
15709
|
if (harness === "codex") {
|
|
15242
15710
|
if (!artifact.entry.endsWith("/bin/codex")) throw new Error("Invalid Codex bundle entry");
|
|
15243
|
-
const bundle =
|
|
15244
|
-
for (const name of readdirSync5(
|
|
15711
|
+
const bundle = dirname15(dirname15(artifact.entry));
|
|
15712
|
+
for (const name of readdirSync5(join23(staging, bundle))) symlinkSync(relative5(staging, join23(staging, bundle, name)), join23(staging, name));
|
|
15245
15713
|
for (const name of ["codex", "codex-code-mode-host"]) {
|
|
15246
|
-
const
|
|
15247
|
-
if (!
|
|
15714
|
+
const stat3 = statSync2(join23(staging, "bin", name));
|
|
15715
|
+
if (!stat3.isFile() || (stat3.mode & 73) === 0) throw new Error("Incomplete Codex runtime bundle");
|
|
15248
15716
|
}
|
|
15249
15717
|
} else {
|
|
15250
|
-
mkdirSync15(
|
|
15251
|
-
symlinkSync(relative5(
|
|
15718
|
+
mkdirSync15(join23(staging, "bin"), { mode: 448 });
|
|
15719
|
+
symlinkSync(relative5(join23(staging, "bin"), join23(staging, artifact.entry)), join23(staging, "bin", pin.command));
|
|
15252
15720
|
}
|
|
15253
|
-
writeFileSync8(
|
|
15721
|
+
writeFileSync8(join23(staging, MARKER), installMarker(pin, artifact), { mode: 384 });
|
|
15254
15722
|
const target = versionDir(store, harness);
|
|
15255
15723
|
const retained = existsSync6(target) ? `${target}.retained-${randomBytes2(6).toString("hex")}` : null;
|
|
15256
15724
|
if (retained) renameSync4(target, retained);
|
|
@@ -15271,12 +15739,12 @@ async function download(url, file, integrity) {
|
|
|
15271
15739
|
if (algorithm !== "sha512" || !expected2) throw new Error("Unsupported harness integrity");
|
|
15272
15740
|
const response = await fetch(url, { redirect: "follow" });
|
|
15273
15741
|
if (!response.ok || !response.body) throw new Error(`Harness download failed (${response.status})`);
|
|
15274
|
-
const hash2 =
|
|
15742
|
+
const hash2 = createHash8("sha512");
|
|
15275
15743
|
const tap = new Transform({ transform(chunk, _encoding, done) {
|
|
15276
15744
|
hash2.update(chunk);
|
|
15277
15745
|
done(null, chunk);
|
|
15278
15746
|
} });
|
|
15279
|
-
await
|
|
15747
|
+
await pipeline2(Readable2.fromWeb(response.body), tap, createWriteStream2(file, { mode: 384 }));
|
|
15280
15748
|
if (hash2.digest("base64") !== expected2) throw new Error("Harness download failed its integrity check");
|
|
15281
15749
|
}
|
|
15282
15750
|
function managedHarnessReport(store) {
|
|
@@ -15331,8 +15799,8 @@ function harnessFingerprint(store) {
|
|
|
15331
15799
|
|
|
15332
15800
|
// src/model-probe.ts
|
|
15333
15801
|
import { spawn as spawn3 } from "node:child_process";
|
|
15334
|
-
import { mkdtempSync as
|
|
15335
|
-
import { join as
|
|
15802
|
+
import { mkdtempSync as mkdtempSync6, readdirSync as readdirSync6, rmSync as rmSync13 } from "node:fs";
|
|
15803
|
+
import { join as join24 } from "node:path";
|
|
15336
15804
|
|
|
15337
15805
|
// src/process-group.ts
|
|
15338
15806
|
async function stopGroup(child, graceMs = 3e3) {
|
|
@@ -15352,12 +15820,12 @@ async function stopGroup(child, graceMs = 3e3) {
|
|
|
15352
15820
|
};
|
|
15353
15821
|
if (child.exitCode === null && child.signalCode === null) {
|
|
15354
15822
|
signal("SIGTERM");
|
|
15355
|
-
await new Promise((
|
|
15356
|
-
if (child.exitCode !== null || child.signalCode !== null) return
|
|
15823
|
+
await new Promise((resolve20) => {
|
|
15824
|
+
if (child.exitCode !== null || child.signalCode !== null) return resolve20();
|
|
15357
15825
|
const done = () => {
|
|
15358
15826
|
clearTimeout(timer);
|
|
15359
15827
|
child.off("exit", done);
|
|
15360
|
-
|
|
15828
|
+
resolve20();
|
|
15361
15829
|
};
|
|
15362
15830
|
const timer = setTimeout(done, graceMs);
|
|
15363
15831
|
child.once("exit", done);
|
|
@@ -15412,10 +15880,10 @@ function sweepModelProbeHomes(scratchDir) {
|
|
|
15412
15880
|
} catch {
|
|
15413
15881
|
return;
|
|
15414
15882
|
}
|
|
15415
|
-
for (const name of names) if (name.startsWith(HOME_PREFIX)) rmSync13(
|
|
15883
|
+
for (const name of names) if (name.startsWith(HOME_PREFIX)) rmSync13(join24(scratchDir, name), { recursive: true, force: true });
|
|
15416
15884
|
}
|
|
15417
15885
|
async function probeHarnessModels(harness, binary, options) {
|
|
15418
|
-
const home =
|
|
15886
|
+
const home = mkdtempSync6(join24(options.scratchDir, HOME_PREFIX));
|
|
15419
15887
|
try {
|
|
15420
15888
|
return await exchange(harness, binary, home, options);
|
|
15421
15889
|
} finally {
|
|
@@ -15424,15 +15892,15 @@ async function probeHarnessModels(harness, binary, options) {
|
|
|
15424
15892
|
}
|
|
15425
15893
|
function exchange(harness, binary, home, options) {
|
|
15426
15894
|
const args = harness === "codex" ? ["app-server"] : ["-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose"];
|
|
15427
|
-
const env = { PATH: process.env.PATH ?? "", HOME: home, CODEX_HOME: home, CLAUDE_CONFIG_DIR:
|
|
15428
|
-
return new Promise((
|
|
15895
|
+
const env = { PATH: process.env.PATH ?? "", HOME: home, CODEX_HOME: home, CLAUDE_CONFIG_DIR: join24(home, ".claude"), LANG: process.env.LANG ?? "C.UTF-8" };
|
|
15896
|
+
return new Promise((resolve20) => {
|
|
15429
15897
|
const child = (options.spawnImpl ?? spawn3)(binary, args, { env, cwd: home, detached: process.platform !== "win32", stdio: ["pipe", "pipe", "ignore"] });
|
|
15430
15898
|
let result;
|
|
15431
15899
|
let stopping;
|
|
15432
15900
|
const stop = () => stopping ??= Promise.resolve().then(() => stopGroup(child, 0));
|
|
15433
15901
|
const done = () => {
|
|
15434
15902
|
clearTimeout(timer);
|
|
15435
|
-
|
|
15903
|
+
resolve20(result ?? null);
|
|
15436
15904
|
};
|
|
15437
15905
|
const finish = (value) => {
|
|
15438
15906
|
if (result !== void 0) return;
|
|
@@ -15494,22 +15962,22 @@ function exchange(harness, binary, home, options) {
|
|
|
15494
15962
|
}
|
|
15495
15963
|
|
|
15496
15964
|
// src/cloud-registration.ts
|
|
15497
|
-
import { createHash as
|
|
15498
|
-
import { join as
|
|
15965
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
15966
|
+
import { join as join25 } from "node:path";
|
|
15499
15967
|
function writeCloudRegistration(dataDir, deviceId, workspaceId, credential) {
|
|
15500
|
-
writeJsonAtomic(
|
|
15968
|
+
writeJsonAtomic(join25(dataDir, "registration.json"), {
|
|
15501
15969
|
version: 1,
|
|
15502
15970
|
deviceId,
|
|
15503
15971
|
workspaceId,
|
|
15504
|
-
tokenSha256:
|
|
15972
|
+
tokenSha256: createHash9("sha256").update(credential).digest("hex")
|
|
15505
15973
|
});
|
|
15506
15974
|
}
|
|
15507
15975
|
|
|
15508
15976
|
// src/cloud-model-probe.ts
|
|
15509
|
-
import { mkdtempSync as
|
|
15977
|
+
import { mkdtempSync as mkdtempSync7, rmSync as rmSync14, statSync as statSync3 } from "node:fs";
|
|
15510
15978
|
|
|
15511
15979
|
// src/hosted-binaries.ts
|
|
15512
|
-
import { accessSync as accessSync2, constants as
|
|
15980
|
+
import { accessSync as accessSync2, constants as constants5, lstatSync as lstatSync10, readFileSync as readFileSync12, realpathSync as realpathSync12 } from "node:fs";
|
|
15513
15981
|
import { delimiter as delimiter5, isAbsolute as isAbsolute7 } from "node:path";
|
|
15514
15982
|
import { z as z37 } from "zod";
|
|
15515
15983
|
var HOSTED_CLI_MANIFEST = "/opt/mikka/worker/.mikka-original-cli.json";
|
|
@@ -15551,7 +16019,7 @@ function executable(path3) {
|
|
|
15551
16019
|
if (!path3) return void 0;
|
|
15552
16020
|
try {
|
|
15553
16021
|
const resolved = realpathSync12(path3);
|
|
15554
|
-
accessSync2(resolved,
|
|
16022
|
+
accessSync2(resolved, constants5.X_OK);
|
|
15555
16023
|
return lstatSync10(resolved).isFile() ? resolved : void 0;
|
|
15556
16024
|
} catch {
|
|
15557
16025
|
return void 0;
|
|
@@ -15704,10 +16172,10 @@ async function prepareSubscriptionCredentials(assignment, host) {
|
|
|
15704
16172
|
|
|
15705
16173
|
// src/run-scratch.ts
|
|
15706
16174
|
import { rmSync as rmSync15 } from "node:fs";
|
|
15707
|
-
import { join as
|
|
16175
|
+
import { join as join26 } from "node:path";
|
|
15708
16176
|
function removeRunCredentials(stateDir, runId) {
|
|
15709
16177
|
const { runDir } = runPaths(stateDir, runId);
|
|
15710
|
-
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync15(
|
|
16178
|
+
for (const path3 of RUN_CREDENTIAL_PATHS) rmSync15(join26(runDir, path3), { recursive: true, force: true });
|
|
15711
16179
|
}
|
|
15712
16180
|
|
|
15713
16181
|
// src/subscription-local-runner.ts
|
|
@@ -15783,7 +16251,7 @@ function createLocalSubscriptionRunner(host) {
|
|
|
15783
16251
|
finish();
|
|
15784
16252
|
}
|
|
15785
16253
|
},
|
|
15786
|
-
send: (text4) => session.send(text4),
|
|
16254
|
+
send: (text4, mode) => session.send(text4, mode),
|
|
15787
16255
|
cancel: async () => {
|
|
15788
16256
|
try {
|
|
15789
16257
|
await session.cancel();
|
|
@@ -15805,8 +16273,8 @@ function createLocalSubscriptionRunner(host) {
|
|
|
15805
16273
|
}
|
|
15806
16274
|
|
|
15807
16275
|
// src/subscription-preflight.ts
|
|
15808
|
-
import { mkdtempSync as
|
|
15809
|
-
import { join as
|
|
16276
|
+
import { mkdtempSync as mkdtempSync8, rmSync as rmSync16 } from "node:fs";
|
|
16277
|
+
import { join as join27 } from "node:path";
|
|
15810
16278
|
import { execa as execa8 } from "execa";
|
|
15811
16279
|
var refused = (detail, cause) => ({
|
|
15812
16280
|
ready: false,
|
|
@@ -15825,7 +16293,7 @@ async function preflightLocalSubscription(harness, options) {
|
|
|
15825
16293
|
const expected2 = (options.store.pins ?? HARNESS_PINS).harnesses[harness].version;
|
|
15826
16294
|
let home;
|
|
15827
16295
|
try {
|
|
15828
|
-
home =
|
|
16296
|
+
home = mkdtempSync8(join27(options.scratchDir, "subscription-preflight-"));
|
|
15829
16297
|
const result = await execa8(binary, ["--version"], {
|
|
15830
16298
|
env: { ...env, HOME: home },
|
|
15831
16299
|
extendEnv: false,
|
|
@@ -15889,8 +16357,8 @@ async function acquireCloudWorkspaceControl(input, root = CLOUD_WORKSPACE_CONTRO
|
|
|
15889
16357
|
});
|
|
15890
16358
|
let acquired = false, releasing = false, settled = false, output = "";
|
|
15891
16359
|
let finished;
|
|
15892
|
-
const done = new Promise((
|
|
15893
|
-
finished =
|
|
16360
|
+
const done = new Promise((resolve20) => {
|
|
16361
|
+
finished = resolve20;
|
|
15894
16362
|
});
|
|
15895
16363
|
child.stdin.on("error", () => {
|
|
15896
16364
|
if (!settled && !releasing) child.kill("SIGTERM");
|
|
@@ -15903,7 +16371,7 @@ async function acquireCloudWorkspaceControl(input, root = CLOUD_WORKSPACE_CONTRO
|
|
|
15903
16371
|
if (!acquired || settled || releasing || !child.stdin.writable) throw new CodedError("terminal_control_unavailable", { detail: "fence_lost" });
|
|
15904
16372
|
child.stdin.write(JSON.stringify(value) + "\n");
|
|
15905
16373
|
};
|
|
15906
|
-
await new Promise((
|
|
16374
|
+
await new Promise((resolve20, reject) => {
|
|
15907
16375
|
const fail = (cause) => reject(new CodedError("terminal_control_unavailable", { detail: "fence_unavailable", cause }));
|
|
15908
16376
|
child.once("error", fail);
|
|
15909
16377
|
child.stdout.on("data", (data) => {
|
|
@@ -15918,7 +16386,7 @@ async function acquireCloudWorkspaceControl(input, root = CLOUD_WORKSPACE_CONTRO
|
|
|
15918
16386
|
fail(input.signal.reason);
|
|
15919
16387
|
return;
|
|
15920
16388
|
}
|
|
15921
|
-
|
|
16389
|
+
resolve20();
|
|
15922
16390
|
} else if (output.length > 32) {
|
|
15923
16391
|
child.kill("SIGTERM");
|
|
15924
16392
|
fail();
|
|
@@ -15958,7 +16426,7 @@ import {
|
|
|
15958
16426
|
rmSync as rmSync17,
|
|
15959
16427
|
truncateSync
|
|
15960
16428
|
} from "node:fs";
|
|
15961
|
-
import { join as
|
|
16429
|
+
import { join as join28 } from "node:path";
|
|
15962
16430
|
var Outbox = class {
|
|
15963
16431
|
constructor(dir, link, log, retryMs = 1e3, onUndeliverable = () => void 0, retainResources = false, traceContext = () => void 0) {
|
|
15964
16432
|
this.dir = dir;
|
|
@@ -15983,10 +16451,10 @@ var Outbox = class {
|
|
|
15983
16451
|
/** Runs whose file was checked for a torn tail since this process started. */
|
|
15984
16452
|
repaired = /* @__PURE__ */ new Set();
|
|
15985
16453
|
file(runId) {
|
|
15986
|
-
return
|
|
16454
|
+
return join28(this.dir, `${assertSafeId("run id", runId)}.jsonl`);
|
|
15987
16455
|
}
|
|
15988
16456
|
ackFile(runId) {
|
|
15989
|
-
return
|
|
16457
|
+
return join28(this.dir, `${assertSafeId("run id", runId)}.ack.json`);
|
|
15990
16458
|
}
|
|
15991
16459
|
parse(runId) {
|
|
15992
16460
|
let data;
|
|
@@ -16172,11 +16640,11 @@ var Outbox = class {
|
|
|
16172
16640
|
};
|
|
16173
16641
|
|
|
16174
16642
|
// src/quota/files.ts
|
|
16175
|
-
import { execFile as
|
|
16176
|
-
import { constants as
|
|
16177
|
-
import { promisify as
|
|
16178
|
-
var NOFOLLOW =
|
|
16179
|
-
var execFileAsync =
|
|
16643
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
16644
|
+
import { constants as constants6 } from "node:fs";
|
|
16645
|
+
import { promisify as promisify6 } from "node:util";
|
|
16646
|
+
var NOFOLLOW = constants6.O_NOFOLLOW ?? 0;
|
|
16647
|
+
var execFileAsync = promisify6(execFile6);
|
|
16180
16648
|
var MAX_CREDENTIAL_BYTES = 64 * 1024;
|
|
16181
16649
|
function sanitizeError(error) {
|
|
16182
16650
|
const raw = error instanceof Error ? error.message : String(error);
|
|
@@ -16336,9 +16804,9 @@ var RpcServer = class {
|
|
|
16336
16804
|
const { socketPath } = this.options;
|
|
16337
16805
|
rmSync18(socketPath, { force: true });
|
|
16338
16806
|
const server = createServer2((socket) => this.accept(socket));
|
|
16339
|
-
await new Promise((
|
|
16807
|
+
await new Promise((resolve20, reject) => {
|
|
16340
16808
|
server.once("error", reject);
|
|
16341
|
-
server.listen(socketPath, () =>
|
|
16809
|
+
server.listen(socketPath, () => resolve20());
|
|
16342
16810
|
});
|
|
16343
16811
|
chmodSync(socketPath, 384);
|
|
16344
16812
|
this.server = server;
|
|
@@ -16402,9 +16870,9 @@ var RpcServer = class {
|
|
|
16402
16870
|
}
|
|
16403
16871
|
async close() {
|
|
16404
16872
|
for (const socket of this.sockets) socket.destroy();
|
|
16405
|
-
await new Promise((
|
|
16406
|
-
if (!this.server) return
|
|
16407
|
-
this.server.close(() =>
|
|
16873
|
+
await new Promise((resolve20) => {
|
|
16874
|
+
if (!this.server) return resolve20();
|
|
16875
|
+
this.server.close(() => resolve20());
|
|
16408
16876
|
});
|
|
16409
16877
|
this.server = null;
|
|
16410
16878
|
rmSync18(this.options.socketPath, { force: true });
|
|
@@ -16632,7 +17100,7 @@ async function startTaskSecretBridge(options) {
|
|
|
16632
17100
|
};
|
|
16633
17101
|
options.signal.addEventListener("abort", close, { once: true });
|
|
16634
17102
|
try {
|
|
16635
|
-
await new Promise((
|
|
17103
|
+
await new Promise((resolve20, reject) => {
|
|
16636
17104
|
const cleanup = () => {
|
|
16637
17105
|
server.off("error", failed);
|
|
16638
17106
|
options.signal.removeEventListener("abort", cancelled);
|
|
@@ -16653,7 +17121,7 @@ async function startTaskSecretBridge(options) {
|
|
|
16653
17121
|
}
|
|
16654
17122
|
server.listen(0, "127.0.0.1", () => {
|
|
16655
17123
|
cleanup();
|
|
16656
|
-
|
|
17124
|
+
resolve20();
|
|
16657
17125
|
});
|
|
16658
17126
|
});
|
|
16659
17127
|
options.signal.throwIfAborted();
|
|
@@ -16682,37 +17150,37 @@ async function startTaskSecretBridge(options) {
|
|
|
16682
17150
|
}
|
|
16683
17151
|
|
|
16684
17152
|
// src/agents/chat-files.ts
|
|
16685
|
-
import { createHash as
|
|
16686
|
-
import { lstat as
|
|
16687
|
-
import { join as
|
|
17153
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
17154
|
+
import { lstat as lstat3, mkdir as mkdir3, readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
|
|
17155
|
+
import { join as join29 } from "node:path";
|
|
16688
17156
|
async function materializeChatFiles(text4, directory, download2) {
|
|
16689
17157
|
const parsed = splitChatFiles(text4);
|
|
16690
17158
|
if (!parsed.files.length) return text4;
|
|
16691
|
-
await
|
|
16692
|
-
if (!(await
|
|
17159
|
+
await mkdir3(directory, { recursive: true, mode: 448 });
|
|
17160
|
+
if (!(await lstat3(directory)).isDirectory() || (await lstat3(directory)).isSymbolicLink())
|
|
16693
17161
|
throw Error("Attachment directory unavailable");
|
|
16694
17162
|
const entries = [];
|
|
16695
17163
|
for (const ref of parsed.files) {
|
|
16696
17164
|
const file = chatFileDownloadSchema.parse(await download2(ref.id));
|
|
16697
17165
|
if (file.id !== ref.id) throw Error("Attachment identity mismatch");
|
|
16698
17166
|
const bytes = Buffer.from(file.data, "base64");
|
|
16699
|
-
if (bytes.length !== file.size || bytes.toString("base64") !== file.data ||
|
|
17167
|
+
if (bytes.length !== file.size || bytes.toString("base64") !== file.data || createHash10("sha256").update(bytes).digest("hex") !== file.sha256)
|
|
16700
17168
|
throw Error("Attachment content mismatch");
|
|
16701
17169
|
const ext = /\.([a-z0-9]{1,12})$/i.exec(file.name)?.[1]?.toLowerCase() ?? "bin";
|
|
16702
|
-
const path3 =
|
|
17170
|
+
const path3 = join29(directory, `${file.id}.${ext}`);
|
|
16703
17171
|
try {
|
|
16704
17172
|
await writeFile2(path3, bytes, { flag: "wx", mode: 256 });
|
|
16705
17173
|
} catch (error) {
|
|
16706
|
-
if (error.code !== "EEXIST" || (await
|
|
17174
|
+
if (error.code !== "EEXIST" || (await lstat3(path3)).isSymbolicLink() || createHash10("sha256").update(await readFile4(path3)).digest("hex") !== file.sha256)
|
|
16707
17175
|
throw Error("Attachment file unavailable");
|
|
16708
17176
|
}
|
|
16709
17177
|
let textPath;
|
|
16710
17178
|
if (file.text !== null) {
|
|
16711
|
-
textPath =
|
|
17179
|
+
textPath = join29(directory, `${file.id}.extracted.txt`);
|
|
16712
17180
|
try {
|
|
16713
17181
|
await writeFile2(textPath, file.text, { flag: "wx", mode: 256 });
|
|
16714
17182
|
} catch (error) {
|
|
16715
|
-
if (error.code !== "EEXIST" || (await
|
|
17183
|
+
if (error.code !== "EEXIST" || (await lstat3(textPath)).isSymbolicLink() || await readFile4(textPath, "utf8") !== file.text)
|
|
16716
17184
|
throw Error("Attachment text unavailable");
|
|
16717
17185
|
}
|
|
16718
17186
|
}
|
|
@@ -16902,23 +17370,23 @@ function createRunMasker(secrets) {
|
|
|
16902
17370
|
|
|
16903
17371
|
// src/runs/supervisor.ts
|
|
16904
17372
|
import { stdSerializers } from "pino";
|
|
16905
|
-
import { createHash as
|
|
16906
|
-
import { join as
|
|
16907
|
-
import { tmpdir as
|
|
17373
|
+
import { createHash as createHash12, randomUUID as randomUUID6 } from "node:crypto";
|
|
17374
|
+
import { join as join31, resolve as resolve14 } from "node:path";
|
|
17375
|
+
import { tmpdir as tmpdir5 } from "node:os";
|
|
16908
17376
|
import { execa as execa12 } from "execa";
|
|
16909
17377
|
|
|
16910
17378
|
// src/agents/checkpoint.ts
|
|
16911
|
-
import { mkdtempSync as
|
|
16912
|
-
import { tmpdir as
|
|
16913
|
-
import { join as
|
|
17379
|
+
import { mkdtempSync as mkdtempSync9, rmSync as rmSync19, writeFileSync as writeFileSync9 } from "node:fs";
|
|
17380
|
+
import { tmpdir as tmpdir4 } from "node:os";
|
|
17381
|
+
import { join as join30 } from "node:path";
|
|
16914
17382
|
import { gunzipSync as gunzipSync2, gzipSync as gzipSync2 } from "node:zlib";
|
|
16915
17383
|
import { execa as execa11 } from "execa";
|
|
16916
17384
|
|
|
16917
17385
|
// src/coding-workspace/checkpoint.ts
|
|
16918
|
-
import { createHash as
|
|
16919
|
-
import { resolve as
|
|
17386
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
17387
|
+
import { resolve as resolve13 } from "node:path";
|
|
16920
17388
|
import { execa as execa10 } from "execa";
|
|
16921
|
-
var digest6 = (value) =>
|
|
17389
|
+
var digest6 = (value) => createHash11("sha256").update(value).digest("hex");
|
|
16922
17390
|
var oid = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
16923
17391
|
var MANIFEST_BYTES = 1536 * 1024;
|
|
16924
17392
|
var regular = (mode) => mode === null || mode === "100644" || mode === "100755";
|
|
@@ -16950,7 +17418,7 @@ async function captureCheckpointReview(input) {
|
|
|
16950
17418
|
const env = {
|
|
16951
17419
|
...buildChildEnv({}),
|
|
16952
17420
|
GIT_DIR: gitDir,
|
|
16953
|
-
GIT_COMMON_DIR:
|
|
17421
|
+
GIT_COMMON_DIR: resolve13(gitDir, "..", ".."),
|
|
16954
17422
|
GIT_WORK_TREE: input.worktree,
|
|
16955
17423
|
GIT_CONFIG_NOSYSTEM: "1",
|
|
16956
17424
|
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
@@ -17137,8 +17605,8 @@ async function takeCheckpoint(options) {
|
|
|
17137
17605
|
}
|
|
17138
17606
|
async function applyCheckpoint(options) {
|
|
17139
17607
|
const git3 = await pinnedGit(options.repoPath, options.worktree);
|
|
17140
|
-
const dir =
|
|
17141
|
-
const file =
|
|
17608
|
+
const dir = mkdtempSync9(join30(tmpdir4(), "mikka-checkpoint-"));
|
|
17609
|
+
const file = join30(dir, "checkpoint.patch");
|
|
17142
17610
|
try {
|
|
17143
17611
|
const patch = gunzipSync2(Buffer.from(options.checkpoint.patch, "base64"));
|
|
17144
17612
|
if (!patch.length && options.checkpoint.files === 0) return true;
|
|
@@ -17171,7 +17639,7 @@ async function hasCommit(repoPath, commit) {
|
|
|
17171
17639
|
|
|
17172
17640
|
// src/server-link.ts
|
|
17173
17641
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
17174
|
-
import { pathToFileURL as
|
|
17642
|
+
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
17175
17643
|
var MAX_CONTINUES = 3;
|
|
17176
17644
|
var MAX_CRASH_RETRIES = 3;
|
|
17177
17645
|
var MAX_FIX_ROUNDS = 3;
|
|
@@ -17255,7 +17723,7 @@ var MemoryServer = class {
|
|
|
17255
17723
|
const runId = run3.runId ?? randomUUID5();
|
|
17256
17724
|
const fixturePath = this.repos.get(deviceId)?.find((repo) => repo.repoId === run3.repoId)?.path;
|
|
17257
17725
|
this.runs.set(runId, {
|
|
17258
|
-
assignment: { ...run3, runId, remoteUrl: run3.remoteUrl ?? (fixturePath ?
|
|
17726
|
+
assignment: { ...run3, runId, remoteUrl: run3.remoteUrl ?? (fixturePath ? pathToFileURL3(fixturePath).href : void 0) },
|
|
17259
17727
|
deviceId,
|
|
17260
17728
|
state: "queued",
|
|
17261
17729
|
patches: []
|
|
@@ -17393,12 +17861,12 @@ var MemoryServer = class {
|
|
|
17393
17861
|
this.check();
|
|
17394
17862
|
let pending = this.pendingCommands(deviceId, skip);
|
|
17395
17863
|
if (pending.length === 0 && waitSeconds > 0 && !signal?.aborted) {
|
|
17396
|
-
await new Promise((
|
|
17397
|
-
const timer = setTimeout(
|
|
17398
|
-
signal?.addEventListener("abort", () =>
|
|
17864
|
+
await new Promise((resolve20) => {
|
|
17865
|
+
const timer = setTimeout(resolve20, waitSeconds * 1e3);
|
|
17866
|
+
signal?.addEventListener("abort", () => resolve20(), { once: true });
|
|
17399
17867
|
this.wakeCommands.push(() => {
|
|
17400
17868
|
clearTimeout(timer);
|
|
17401
|
-
|
|
17869
|
+
resolve20();
|
|
17402
17870
|
});
|
|
17403
17871
|
});
|
|
17404
17872
|
this.check();
|
|
@@ -17866,10 +18334,11 @@ var RunSupervisor = class {
|
|
|
17866
18334
|
check();
|
|
17867
18335
|
await this.send(runId, mailboxNoticeText(runId, messageIds));
|
|
17868
18336
|
}
|
|
17869
|
-
async send(runId, text4) {
|
|
18337
|
+
async send(runId, text4, mode) {
|
|
17870
18338
|
const run3 = this.active.get(runId);
|
|
17871
18339
|
const adapter = this.adapterFor(runId);
|
|
17872
18340
|
if (!run3?.session) throw new RunNotFoundError(runId);
|
|
18341
|
+
if (mode === "steer" && adapter.harness !== "codex") throw new Error("Active turn steering unavailable");
|
|
17873
18342
|
if (!adapter.capabilities.supportsInterject) {
|
|
17874
18343
|
throw new Error(
|
|
17875
18344
|
`Harness "${adapter.harness}" cannot take messages mid-run`
|
|
@@ -17879,9 +18348,9 @@ var RunSupervisor = class {
|
|
|
17879
18348
|
const entry = this.deps.journal.get(runId);
|
|
17880
18349
|
if (splitChatFiles(text4).files.length) {
|
|
17881
18350
|
if (!entry || !this.deps.downloadChatFile || !this.deps.adapterStateDir) throw Error("Run attachments unavailable");
|
|
17882
|
-
text4 = await materializeChatFiles(text4,
|
|
18351
|
+
text4 = await materializeChatFiles(text4, join31(this.deps.adapterStateDir, "inputs", runId), (id5) => this.deps.downloadChatFile(entry.assignment, id5, run3.abort.signal));
|
|
17883
18352
|
}
|
|
17884
|
-
await run3.session.send(text4);
|
|
18353
|
+
await run3.session.send(text4, mode);
|
|
17885
18354
|
}
|
|
17886
18355
|
async cancel(runId) {
|
|
17887
18356
|
const entry = this.deps.journal.get(runId);
|
|
@@ -17909,9 +18378,9 @@ var RunSupervisor = class {
|
|
|
17909
18378
|
run3.abort.abort();
|
|
17910
18379
|
}
|
|
17911
18380
|
let timer;
|
|
17912
|
-
const grace = new Promise((
|
|
18381
|
+
const grace = new Promise((resolve20) => {
|
|
17913
18382
|
timer = setTimeout(
|
|
17914
|
-
|
|
18383
|
+
resolve20,
|
|
17915
18384
|
this.deps.stopGraceMs ?? DEFAULT_STOP_GRACE_MS
|
|
17916
18385
|
);
|
|
17917
18386
|
});
|
|
@@ -17937,10 +18406,10 @@ var RunSupervisor = class {
|
|
|
17937
18406
|
this.active.get(runId)?.runtimeTiming?.chunk(chunk);
|
|
17938
18407
|
if (chunk.type.startsWith("data-") && "transient" in chunk && chunk.transient)
|
|
17939
18408
|
return this.append(runId, chunk);
|
|
17940
|
-
const
|
|
17941
|
-
this.openParts.set(runId,
|
|
17942
|
-
if (this.cutMessages.has(runId) &&
|
|
17943
|
-
trackParts(
|
|
18409
|
+
const open5 = this.openParts.get(runId) ?? /* @__PURE__ */ new Set();
|
|
18410
|
+
this.openParts.set(runId, open5);
|
|
18411
|
+
if (this.cutMessages.has(runId) && open5.size === 0) this.endMessage(runId);
|
|
18412
|
+
trackParts(open5, chunk);
|
|
17944
18413
|
if (chunk.type === "start") {
|
|
17945
18414
|
this.endMessage(runId);
|
|
17946
18415
|
this.openMessages.add(runId);
|
|
@@ -17948,7 +18417,7 @@ var RunSupervisor = class {
|
|
|
17948
18417
|
if (!this.openMessages.has(runId)) return;
|
|
17949
18418
|
this.openMessages.delete(runId);
|
|
17950
18419
|
this.cutMessages.delete(runId);
|
|
17951
|
-
|
|
18420
|
+
open5.clear();
|
|
17952
18421
|
} else if (!this.openMessages.has(runId)) {
|
|
17953
18422
|
this.append(runId, { type: "start", messageId: randomUUID6() });
|
|
17954
18423
|
this.openMessages.add(runId);
|
|
@@ -18199,16 +18668,22 @@ var RunSupervisor = class {
|
|
|
18199
18668
|
}
|
|
18200
18669
|
});
|
|
18201
18670
|
}
|
|
18202
|
-
/**
|
|
18203
|
-
async flushCaptures(runId) {
|
|
18671
|
+
/** One minute for preparation and upload; cancellation drains before the terminal event. */
|
|
18672
|
+
async flushCaptures(runId, signal) {
|
|
18204
18673
|
if (!this.deps.captures) return true;
|
|
18205
|
-
|
|
18206
|
-
|
|
18207
|
-
|
|
18208
|
-
|
|
18209
|
-
|
|
18210
|
-
|
|
18211
|
-
|
|
18674
|
+
const deadline = new AbortController();
|
|
18675
|
+
const finishing = AbortSignal.any([signal, deadline.signal]);
|
|
18676
|
+
const timer = setTimeout(() => deadline.abort(new Error("Capture finalization deadline exceeded")), 6e4);
|
|
18677
|
+
try {
|
|
18678
|
+
await this.deps.captures.flush(runId, false, finishing);
|
|
18679
|
+
finishing.throwIfAborted();
|
|
18680
|
+
return true;
|
|
18681
|
+
} catch (error) {
|
|
18682
|
+
if (signal.aborted) return false;
|
|
18683
|
+
throw error;
|
|
18684
|
+
} finally {
|
|
18685
|
+
clearTimeout(timer);
|
|
18686
|
+
}
|
|
18212
18687
|
}
|
|
18213
18688
|
/** Only the local lease and pushed stop state govern host finishing work. */
|
|
18214
18689
|
assertFinishingRunLive(runId, signal) {
|
|
@@ -18232,11 +18707,11 @@ var RunSupervisor = class {
|
|
|
18232
18707
|
if (configured.length === 0) return void 0;
|
|
18233
18708
|
const loaded = [];
|
|
18234
18709
|
if (this.deps.adapterStateDir) {
|
|
18235
|
-
const dir =
|
|
18710
|
+
const dir = join31(runPaths(this.deps.adapterStateDir, runId).runDir, PROFILE_SKILLS_DIR, PROFILE_SKILL_LOADS_DIR);
|
|
18236
18711
|
try {
|
|
18237
18712
|
for (const name of readdirSync8(dir).sort()) {
|
|
18238
18713
|
if (!name.endsWith(".json") || loaded.length >= configured.length) continue;
|
|
18239
|
-
const file =
|
|
18714
|
+
const file = join31(dir, name), meta = lstatSync11(file, { throwIfNoEntry: false });
|
|
18240
18715
|
if (!meta?.isFile() || meta.isSymbolicLink() || meta.nlink !== 1 || meta.size < 2 || meta.size > 4096) continue;
|
|
18241
18716
|
const receipt = profileSkillLoadReceiptSchema.safeParse(JSON.parse(readFileSync14(file, "utf8")));
|
|
18242
18717
|
if (!receipt.success || loaded.some((item) => item.id === receipt.data.id)) continue;
|
|
@@ -18380,7 +18855,7 @@ var RunSupervisor = class {
|
|
|
18380
18855
|
try {
|
|
18381
18856
|
return await withRunGitCredentials(
|
|
18382
18857
|
assignment,
|
|
18383
|
-
runPaths(this.deps.adapterStateDir ??
|
|
18858
|
+
runPaths(this.deps.adapterStateDir ?? join31(tmpdir5(), "mikka-run-state"), runId).privateDir,
|
|
18384
18859
|
(env) => this.deps.worktrees.fetchBranch(
|
|
18385
18860
|
repo.path,
|
|
18386
18861
|
repo.push?.remote ?? "origin",
|
|
@@ -18451,7 +18926,15 @@ var RunSupervisor = class {
|
|
|
18451
18926
|
}, { root: true, traceContext: assignment?.traceContext }).catch(async (error) => {
|
|
18452
18927
|
run3.repositoryPreparing?.refuseEffects(error);
|
|
18453
18928
|
run3.repositoryPreparing?.abort.abort();
|
|
18454
|
-
await Promise.all([
|
|
18929
|
+
await Promise.all([
|
|
18930
|
+
run3.repositoryPreparing?.done.catch(() => void 0),
|
|
18931
|
+
this.closePrepared(run3),
|
|
18932
|
+
Promise.resolve().then(() => this.deps.captures?.flush(
|
|
18933
|
+
runId,
|
|
18934
|
+
false,
|
|
18935
|
+
AbortSignal.abort(new Error("Capture finalization cancelled"))
|
|
18936
|
+
)).catch(() => void 0)
|
|
18937
|
+
]);
|
|
18455
18938
|
run3.runtimeTiming?.finishing();
|
|
18456
18939
|
const message = error instanceof Error ? error.message : String(error);
|
|
18457
18940
|
this.deps.log.error({ run_id: runId, err: this.logError(runId, error) }, "run failed");
|
|
@@ -18522,8 +19005,8 @@ var RunSupervisor = class {
|
|
|
18522
19005
|
});
|
|
18523
19006
|
if (readAbort) {
|
|
18524
19007
|
let allowEffects, refuseEffects;
|
|
18525
|
-
const entryReady = new Promise((
|
|
18526
|
-
allowEffects =
|
|
19008
|
+
const entryReady = new Promise((resolve20, reject) => {
|
|
19009
|
+
allowEffects = resolve20;
|
|
18527
19010
|
refuseEffects = reject;
|
|
18528
19011
|
});
|
|
18529
19012
|
const authorized = Promise.all([policyReady, entryReady]);
|
|
@@ -18757,7 +19240,7 @@ var RunSupervisor = class {
|
|
|
18757
19240
|
let followUp = assignment.followUp;
|
|
18758
19241
|
if (splitChatFiles(prompt).files.length || followUp && splitChatFiles(followUp).files.length) {
|
|
18759
19242
|
if (!this.deps.downloadChatFile || !this.deps.adapterStateDir) throw Error("Run attachments unavailable");
|
|
18760
|
-
const directory =
|
|
19243
|
+
const directory = join31(this.deps.adapterStateDir, "inputs", runId);
|
|
18761
19244
|
const download2 = (id5) => this.deps.downloadChatFile(assignment, id5, run3.abort.signal);
|
|
18762
19245
|
prompt = await materializeChatFiles(prompt, directory, download2);
|
|
18763
19246
|
if (followUp) followUp = await materializeChatFiles(followUp, directory, download2);
|
|
@@ -18770,7 +19253,7 @@ var RunSupervisor = class {
|
|
|
18770
19253
|
gitWritePaths: await worktreeGitWritePaths(repo.path, worktree, runId)
|
|
18771
19254
|
};
|
|
18772
19255
|
const resuming = entry.sessionId !== null && adapter.capabilities.supportsResume;
|
|
18773
|
-
const inEarlierWorktree = continued !== null || entry.worktree !== null &&
|
|
19256
|
+
const inEarlierWorktree = continued !== null || entry.worktree !== null && resolve14(entry.worktree) !== resolve14(this.deps.worktrees.pathFor(runId));
|
|
18774
19257
|
const continueSession = !resuming && assignment.resumeSessionId && assignment.continuesRunId && inEarlierWorktree && adapter.capabilities.supportsResume ? {
|
|
18775
19258
|
sessionId: assignment.resumeSessionId,
|
|
18776
19259
|
runId: assignment.continuesRunId,
|
|
@@ -18779,13 +19262,13 @@ var RunSupervisor = class {
|
|
|
18779
19262
|
if (assignment.requireSessionResume && (!assignment.resumeSessionId || !assignment.continuesRunId || !adapter.capabilities.supportsResume || !resuming && !continueSession || resuming && entry.sessionId !== assignment.resumeSessionId))
|
|
18780
19263
|
throw new Error("factory_question_session_resume_required");
|
|
18781
19264
|
const benchmark = assignment.benchmark;
|
|
18782
|
-
const policyDigest = assignment.skillReceipt ?
|
|
19265
|
+
const policyDigest = assignment.skillReceipt ? createHash12("sha256").update(runPolicyDigestInput(assignment.policy)).digest("hex") : void 0;
|
|
18783
19266
|
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");
|
|
18784
19267
|
let fixtureDigest;
|
|
18785
19268
|
if (benchmark) {
|
|
18786
19269
|
if (runPolicy(assignment.policy).readOnly !== true) throw new Error("Benchmark fixture must be read-only");
|
|
18787
19270
|
const fixed = await fixedCheckSnapshot(repo.path, worktree, benchmark.sourceCommit);
|
|
18788
|
-
fixtureDigest =
|
|
19271
|
+
fixtureDigest = createHash12("sha256").update(fixed.sha).digest("hex");
|
|
18789
19272
|
if (fixtureDigest !== benchmark.fixtureDigest) throw new Error("Frozen benchmark fixture digest mismatch");
|
|
18790
19273
|
}
|
|
18791
19274
|
const previousMount = entry.skillMount;
|
|
@@ -18826,7 +19309,7 @@ var RunSupervisor = class {
|
|
|
18826
19309
|
if (!this.deps.adapterStateDir || assignment.harness === "mock" || !session.sessionId || resuming && session.sessionId !== entry.sessionId || assignment.requireSessionResume && session.sessionId !== assignment.resumeSessionId)
|
|
18827
19310
|
throw new Error("Skill mount requires the actual original harness session");
|
|
18828
19311
|
verifySkillAssignment(assignment);
|
|
18829
|
-
const file =
|
|
19312
|
+
const file = join31(
|
|
18830
19313
|
runPaths(this.deps.adapterStateDir, runId).runDir,
|
|
18831
19314
|
SKILLS_DIR,
|
|
18832
19315
|
skillSlug(assignment.skills[0].name),
|
|
@@ -18943,7 +19426,7 @@ var RunSupervisor = class {
|
|
|
18943
19426
|
try {
|
|
18944
19427
|
if (assignment.benchmark && !run3.cancelRequested) {
|
|
18945
19428
|
const fixed = await fixedCheckSnapshot(repo.path, worktree, assignment.benchmark.sourceCommit, finishingSignal);
|
|
18946
|
-
if (
|
|
19429
|
+
if (createHash12("sha256").update(fixed.sha).digest("hex") !== assignment.benchmark.fixtureDigest)
|
|
18947
19430
|
throw new Error("Benchmark fixture changed during model execution");
|
|
18948
19431
|
}
|
|
18949
19432
|
outcome = await this.report(runId, worktree, repo, assignment, stopReason, error, event.report, finishingSignal);
|
|
@@ -18980,7 +19463,7 @@ var RunSupervisor = class {
|
|
|
18980
19463
|
report2 = { ...report2, publish };
|
|
18981
19464
|
stopReason = stopReasonOf(event, run3, assignment);
|
|
18982
19465
|
}
|
|
18983
|
-
const capturesSaved = !this.stopping && await this.flushCaptures(runId);
|
|
19466
|
+
const capturesSaved = !this.stopping && await this.flushCaptures(runId, finishingSignal);
|
|
18984
19467
|
stopReason = stopReasonOf(event, run3, assignment);
|
|
18985
19468
|
const checkpoint = await this.saveTerminalCheckpoint(runId, run3, capturesSaved);
|
|
18986
19469
|
if (stopReason === "provider_failure" || stopReason === "quota_exhausted") report2 = { ...report2, providerCheckpoint: checkpoint.checkpoint };
|
|
@@ -19004,33 +19487,33 @@ var RunSupervisor = class {
|
|
|
19004
19487
|
}
|
|
19005
19488
|
}
|
|
19006
19489
|
};
|
|
19007
|
-
function trackParts(
|
|
19490
|
+
function trackParts(open5, chunk) {
|
|
19008
19491
|
switch (chunk.type) {
|
|
19009
19492
|
case "text-start":
|
|
19010
19493
|
case "reasoning-start":
|
|
19011
|
-
|
|
19494
|
+
open5.add(`${chunk.type.split("-")[0]}:${chunk.id}`);
|
|
19012
19495
|
break;
|
|
19013
19496
|
case "text-end":
|
|
19014
19497
|
case "reasoning-end":
|
|
19015
|
-
|
|
19498
|
+
open5.delete(`${chunk.type.split("-")[0]}:${chunk.id}`);
|
|
19016
19499
|
break;
|
|
19017
19500
|
case "tool-input-start":
|
|
19018
19501
|
case "tool-input-available":
|
|
19019
|
-
|
|
19502
|
+
open5.add(`tool:${chunk.toolCallId}`);
|
|
19020
19503
|
break;
|
|
19021
19504
|
case "tool-output-available":
|
|
19022
19505
|
case "tool-output-error":
|
|
19023
19506
|
case "tool-output-denied":
|
|
19024
|
-
|
|
19507
|
+
open5.delete(`tool:${chunk.toolCallId}`);
|
|
19025
19508
|
break;
|
|
19026
19509
|
}
|
|
19027
19510
|
}
|
|
19028
19511
|
var ABORTED = /* @__PURE__ */ Symbol("aborted");
|
|
19029
19512
|
function abortPromise(signal) {
|
|
19030
|
-
return new Promise((
|
|
19031
|
-
if (signal.aborted)
|
|
19513
|
+
return new Promise((resolve20) => {
|
|
19514
|
+
if (signal.aborted) resolve20(ABORTED);
|
|
19032
19515
|
else
|
|
19033
|
-
signal.addEventListener("abort", () =>
|
|
19516
|
+
signal.addEventListener("abort", () => resolve20(ABORTED), { once: true });
|
|
19034
19517
|
});
|
|
19035
19518
|
}
|
|
19036
19519
|
function pickAgentReport(agent) {
|
|
@@ -19039,6 +19522,8 @@ function pickAgentReport(agent) {
|
|
|
19039
19522
|
if (agent.repositorySelection) picked.repositorySelection = agent.repositorySelection;
|
|
19040
19523
|
if (agent.verificationCommand && typeof agent.verificationCommand.command === "string" && agent.verificationCommand.command.trim() && typeof agent.verificationCommand.basis === "string" && agent.verificationCommand.basis.trim())
|
|
19041
19524
|
picked.verificationCommand = { command: agent.verificationCommand.command.trim().slice(0, 2e3), basis: agent.verificationCommand.basis.trim().slice(0, 2e3) };
|
|
19525
|
+
const visualEvidence = runVisualEvidence.safeParse(agent.visualEvidence);
|
|
19526
|
+
if (visualEvidence.success) picked.visualEvidence = visualEvidence.data;
|
|
19042
19527
|
const verdict = reviewVerdict.safeParse(agent.reviewVerdict);
|
|
19043
19528
|
if (verdict.success) picked.reviewVerdict = verdict.data;
|
|
19044
19529
|
if (typeof agent.summary === "string")
|
|
@@ -19154,7 +19639,7 @@ var DeviceGatewayClosedError = class extends Error {
|
|
|
19154
19639
|
};
|
|
19155
19640
|
function runDeviceGateway(socket, options) {
|
|
19156
19641
|
const pingMs = options.pingMs ?? DEVICE_GATEWAY_PING_MS;
|
|
19157
|
-
return new Promise((
|
|
19642
|
+
return new Promise((resolve20, reject) => {
|
|
19158
19643
|
let settled = false;
|
|
19159
19644
|
let opened = false;
|
|
19160
19645
|
let pulling = false;
|
|
@@ -19173,7 +19658,7 @@ function runDeviceGateway(socket, options) {
|
|
|
19173
19658
|
} catch {
|
|
19174
19659
|
}
|
|
19175
19660
|
if (error && !options.signal.aborted) reject(error);
|
|
19176
|
-
else
|
|
19661
|
+
else resolve20();
|
|
19177
19662
|
};
|
|
19178
19663
|
const work = () => {
|
|
19179
19664
|
if (settled) return;
|
|
@@ -19240,27 +19725,27 @@ function openDeviceGateway(url, protocol) {
|
|
|
19240
19725
|
}
|
|
19241
19726
|
|
|
19242
19727
|
// src/coding-workspace/files.ts
|
|
19243
|
-
import { constants as
|
|
19244
|
-
import { open, readFile as
|
|
19245
|
-
import { execFile as
|
|
19246
|
-
import { promisify as
|
|
19247
|
-
import { createHash as
|
|
19248
|
-
import { extname, resolve as
|
|
19249
|
-
var
|
|
19250
|
-
var hash = (value) =>
|
|
19728
|
+
import { constants as constants7 } from "node:fs";
|
|
19729
|
+
import { open as open2, readFile as readFile5, realpath as realpath2 } from "node:fs/promises";
|
|
19730
|
+
import { execFile as execFile7 } from "node:child_process";
|
|
19731
|
+
import { promisify as promisify7 } from "node:util";
|
|
19732
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
19733
|
+
import { extname, resolve as resolve15 } from "node:path";
|
|
19734
|
+
var execute2 = promisify7(execFile7);
|
|
19735
|
+
var hash = (value) => createHash13("sha256").update(value).digest("hex");
|
|
19251
19736
|
var denied = () => new CodingWorkspaceError("workspace_path_unavailable");
|
|
19252
19737
|
function isFileReadRequest(request2) {
|
|
19253
19738
|
return request2.kind === "file" || request2.kind === "tree" || request2.kind === "search" || request2.kind === "context";
|
|
19254
19739
|
}
|
|
19255
19740
|
var safeDotfiles2 = /* @__PURE__ */ new Set([".gitignore", ".gitattributes", ".editorconfig", ".prettierignore", ".prettierrc", ".eslintrc", ".dockerignore"]);
|
|
19256
19741
|
async function mountId(handle) {
|
|
19257
|
-
const id5 = /^mnt_id:\s*(\d+)$/m.exec(await
|
|
19742
|
+
const id5 = /^mnt_id:\s*(\d+)$/m.exec(await readFile5(`/proc/self/fdinfo/${handle.fd}`, "utf8"))?.[1];
|
|
19258
19743
|
if (!id5) throw new CodingWorkspaceError("workspace_unsupported");
|
|
19259
19744
|
return id5;
|
|
19260
19745
|
}
|
|
19261
19746
|
async function git2(root, args, maxBuffer = 2 * 1024 * 1024) {
|
|
19262
19747
|
try {
|
|
19263
|
-
const { stdout } = await
|
|
19748
|
+
const { stdout } = await execute2("git", ["--no-optional-locks", "-c", "core.fsmonitor=false", "-c", "core.hooksPath=/dev/null", ...args], {
|
|
19264
19749
|
// chdir resolves the parent's open directory before exec closes FDs.
|
|
19265
19750
|
// /proc/self works even when the visible procfs uses another PID namespace.
|
|
19266
19751
|
cwd: root.gitPath,
|
|
@@ -19287,16 +19772,16 @@ async function safeFile(root, path3, use) {
|
|
|
19287
19772
|
const parts = path3.split("/");
|
|
19288
19773
|
for (let index = 0; index < parts.length; index++) {
|
|
19289
19774
|
const directory = index < parts.length - 1;
|
|
19290
|
-
const handle = await
|
|
19775
|
+
const handle = await open2(`/proc/self/fd/${parent.fd}/${parts[index]}`, constants7.O_RDONLY | constants7.O_NOFOLLOW | constants7.O_NONBLOCK | (directory ? constants7.O_DIRECTORY : 0));
|
|
19291
19776
|
handles.push(handle);
|
|
19292
|
-
const
|
|
19293
|
-
if (
|
|
19777
|
+
const stat3 = await handle.stat({ bigint: true });
|
|
19778
|
+
if (stat3.dev !== root.device || await mountId(handle) !== root.mountId || !directory && (!stat3.isFile() || stat3.nlink !== 1n)) throw denied();
|
|
19294
19779
|
parent = handle;
|
|
19295
19780
|
}
|
|
19296
19781
|
const selected = await realpath2(`/proc/self/fd/${parent.fd}`);
|
|
19297
|
-
if (selected !==
|
|
19782
|
+
if (selected !== resolve15(root.path, path3) || await realpath2(root.gitPath) !== root.path) throw denied();
|
|
19298
19783
|
const result = await use(parent);
|
|
19299
|
-
if (await realpath2(`/proc/self/fd/${parent.fd}`) !== selected || await realpath2(
|
|
19784
|
+
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");
|
|
19300
19785
|
return result;
|
|
19301
19786
|
} catch (cause) {
|
|
19302
19787
|
if (cause instanceof CodingWorkspaceError) throw cause;
|
|
@@ -19335,9 +19820,9 @@ async function readWorkspaceReceipt(command, entry) {
|
|
|
19335
19820
|
const remote = entry.assignment.remoteUrl ?? entry.assignment.expectedRepoRemote;
|
|
19336
19821
|
if (!remote || remoteKey(remote) !== identity.repositoryKey) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
19337
19822
|
if (process.platform !== "linux") throw new CodingWorkspaceError("workspace_unsupported");
|
|
19338
|
-
const path3 =
|
|
19823
|
+
const path3 = resolve15(entry.worktree);
|
|
19339
19824
|
if (await realpath2(path3) !== path3) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
19340
|
-
directory = await
|
|
19825
|
+
directory = await open2(path3, constants7.O_RDONLY | constants7.O_DIRECTORY | constants7.O_NOFOLLOW);
|
|
19341
19826
|
const root = {
|
|
19342
19827
|
path: path3,
|
|
19343
19828
|
handle: directory,
|
|
@@ -19494,11 +19979,11 @@ async function readWorkspaceReceipt(command, entry) {
|
|
|
19494
19979
|
}
|
|
19495
19980
|
|
|
19496
19981
|
// src/coding-workspace/diff.ts
|
|
19497
|
-
import { constants as
|
|
19498
|
-
import { open as
|
|
19499
|
-
import { createHash as
|
|
19500
|
-
import { resolve as
|
|
19501
|
-
import { tmpdir as
|
|
19982
|
+
import { constants as constants8 } from "node:fs";
|
|
19983
|
+
import { open as open3, realpath as realpath3, mkdtemp as mkdtemp2, mkdir as mkdir4, writeFile as writeFile3, rm as rm3, lstat as lstat4 } from "node:fs/promises";
|
|
19984
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
19985
|
+
import { resolve as resolve16, dirname as dirname16, join as join32, posix } from "node:path";
|
|
19986
|
+
import { tmpdir as tmpdir6 } from "node:os";
|
|
19502
19987
|
import { execa as execa13 } from "execa";
|
|
19503
19988
|
|
|
19504
19989
|
// src/coding-workspace/eol.ts
|
|
@@ -19566,12 +20051,12 @@ var CRLFCleaner = class {
|
|
|
19566
20051
|
};
|
|
19567
20052
|
|
|
19568
20053
|
// src/coding-workspace/diff.ts
|
|
19569
|
-
var digest7 = (value) =>
|
|
20054
|
+
var digest7 = (value) => createHash14("sha256").update(value).digest("hex");
|
|
19570
20055
|
var fenceMode = (mode) => mode === "100644" || mode === "100755" || mode === "120000" || mode === "160000" ? mode : null;
|
|
19571
20056
|
var oid2 = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
19572
20057
|
var MAX_SCAN_BYTES = 64 * 1024 * 1024;
|
|
19573
20058
|
var MAX_MANIFEST_BYTES = 1536 * 1024;
|
|
19574
|
-
var statFence = (
|
|
20059
|
+
var statFence = (stat3) => digest7(`${stat3.dev}:${stat3.ino}:${stat3.mtimeNs}:${stat3.ctimeNs}:${stat3.size}:${stat3.mode}`);
|
|
19575
20060
|
function pathsText(bytes) {
|
|
19576
20061
|
try {
|
|
19577
20062
|
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
@@ -19591,7 +20076,7 @@ async function gitFor(repoPath, root, signal) {
|
|
|
19591
20076
|
const env = {
|
|
19592
20077
|
...buildChildEnv({}),
|
|
19593
20078
|
GIT_DIR: gitDir,
|
|
19594
|
-
GIT_COMMON_DIR:
|
|
20079
|
+
GIT_COMMON_DIR: resolve16(gitDir, "..", ".."),
|
|
19595
20080
|
// cwd is resolved while the parent's FD is still open. The child does not
|
|
19596
20081
|
// inherit that numeric descriptor, so its work tree must be relative to cwd.
|
|
19597
20082
|
GIT_WORK_TREE: ".",
|
|
@@ -19656,7 +20141,7 @@ async function treeFiles(git3, commit) {
|
|
|
19656
20141
|
}
|
|
19657
20142
|
async function existsWithoutReading(path3) {
|
|
19658
20143
|
try {
|
|
19659
|
-
await
|
|
20144
|
+
await lstat4(path3);
|
|
19660
20145
|
return true;
|
|
19661
20146
|
} catch (error) {
|
|
19662
20147
|
if (missing(error)) return false;
|
|
@@ -19675,12 +20160,12 @@ async function conversionSettings(git3) {
|
|
|
19675
20160
|
const host = buildChildEnv({});
|
|
19676
20161
|
const defaults = ["/etc/gitattributes", "/usr/etc/gitattributes", "/usr/local/etc/gitattributes"];
|
|
19677
20162
|
if (!external) {
|
|
19678
|
-
const configHome = host.XDG_CONFIG_HOME || (host.HOME ?
|
|
19679
|
-
if (configHome) defaults.push(
|
|
20163
|
+
const configHome = host.XDG_CONFIG_HOME || (host.HOME ? join32(host.HOME, ".config") : void 0);
|
|
20164
|
+
if (configHome) defaults.push(join32(configHome, "git", "attributes"));
|
|
19680
20165
|
}
|
|
19681
|
-
const info =
|
|
20166
|
+
const info = join32(git3.commonDir, "info");
|
|
19682
20167
|
if (await existsWithoutReading(info)) {
|
|
19683
|
-
if (!(await
|
|
20168
|
+
if (!(await lstat4(info)).isDirectory() || await existsWithoutReading(join32(info, "attributes")))
|
|
19684
20169
|
throw new CodingWorkspaceError("workspace_unsupported");
|
|
19685
20170
|
}
|
|
19686
20171
|
for (const path3 of defaults) if (await existsWithoutReading(path3)) throw new CodingWorkspaceError("workspace_unsupported");
|
|
@@ -19726,11 +20211,11 @@ async function workingConversion(git3, root, paths, head, signal, budget) {
|
|
|
19726
20211
|
throw new CodingWorkspaceError("workspace_unsupported");
|
|
19727
20212
|
attributeBytes.set(path3, bytes);
|
|
19728
20213
|
}
|
|
19729
|
-
const directory = await
|
|
20214
|
+
const directory = await mkdtemp2(join32(tmpdir6(), "mikka-diff-attributes-"));
|
|
19730
20215
|
const actions = /* @__PURE__ */ new Map();
|
|
19731
20216
|
try {
|
|
19732
|
-
const gitDir =
|
|
19733
|
-
await
|
|
20217
|
+
const gitDir = join32(directory, "git"), worktree = join32(directory, "worktree");
|
|
20218
|
+
await mkdir4(worktree, { mode: 448 });
|
|
19734
20219
|
const env = {
|
|
19735
20220
|
...buildChildEnv({}),
|
|
19736
20221
|
GIT_CONFIG_NOSYSTEM: "1",
|
|
@@ -19749,8 +20234,8 @@ async function workingConversion(git3, root, paths, head, signal, budget) {
|
|
|
19749
20234
|
killDescendants: true
|
|
19750
20235
|
});
|
|
19751
20236
|
for (const [path3, bytes] of attributeBytes) {
|
|
19752
|
-
const target =
|
|
19753
|
-
await
|
|
20237
|
+
const target = join32(worktree, path3);
|
|
20238
|
+
await mkdir4(dirname16(target), { recursive: true, mode: 448 });
|
|
19754
20239
|
await writeFile3(target, bytes, { mode: 384, flag: "wx" });
|
|
19755
20240
|
}
|
|
19756
20241
|
const attributes = ["text", "eol", "crlf", "filter", "working-tree-encoding", "ident"];
|
|
@@ -19792,7 +20277,7 @@ async function workingConversion(git3, root, paths, head, signal, budget) {
|
|
|
19792
20277
|
}
|
|
19793
20278
|
for (const path3 of paths) actions.set(path3, cleanAction(values.get(path3), settings.autoCRLF));
|
|
19794
20279
|
} finally {
|
|
19795
|
-
await
|
|
20280
|
+
await rm3(directory, { recursive: true, force: true });
|
|
19796
20281
|
}
|
|
19797
20282
|
return {
|
|
19798
20283
|
index,
|
|
@@ -19832,7 +20317,7 @@ async function currentFile(root, path3, head, budget, signal, conversion, git3)
|
|
|
19832
20317
|
budget.bytes += size;
|
|
19833
20318
|
if (budget.bytes > MAX_SCAN_BYTES) throw new CodingWorkspaceError("workspace_limit_exceeded");
|
|
19834
20319
|
const algorithm = head.length === 64 ? "sha256" : "sha1";
|
|
19835
|
-
const hasher =
|
|
20320
|
+
const hasher = createHash14(algorithm).update(`blob ${size}\0`), stats = new GitTextStats();
|
|
19836
20321
|
const bytes = size <= WORKSPACE_DIFF_MAX_BLOB_BYTES ? Buffer.alloc(size) : null;
|
|
19837
20322
|
const chunk = Buffer.alloc(64 * 1024);
|
|
19838
20323
|
let offset = 0;
|
|
@@ -19872,7 +20357,7 @@ async function currentFile(root, path3, head, budget, signal, conversion, git3)
|
|
|
19872
20357
|
let blob = rawBlob, cleanSize = size;
|
|
19873
20358
|
if (normalize) {
|
|
19874
20359
|
cleanSize -= stats.crlf;
|
|
19875
|
-
const cleaned =
|
|
20360
|
+
const cleaned = createHash14(algorithm).update(`blob ${cleanSize}\0`), cleaner = new CRLFCleaner();
|
|
19876
20361
|
if (bytes) cleaned.update(cleaner.push(bytes));
|
|
19877
20362
|
else {
|
|
19878
20363
|
budget.bytes += size;
|
|
@@ -19942,7 +20427,7 @@ function metadata(repoId, revision2, old, next) {
|
|
|
19942
20427
|
fileVersion: digest7(diffFileVersionMaterial(repoId, revision2, file))
|
|
19943
20428
|
};
|
|
19944
20429
|
}
|
|
19945
|
-
async function
|
|
20430
|
+
async function snapshot3(git3, root, entry, request2, signal) {
|
|
19946
20431
|
const currentHead = (await git3(["rev-parse", "--verify", "HEAD"])).toString().trim();
|
|
19947
20432
|
if (!oid2.test(currentHead)) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
19948
20433
|
const headSha2 = request2.source === "commit" ? request2.headSha : currentHead;
|
|
@@ -20015,9 +20500,9 @@ async function readWorkspaceDiffReceipt(command, entry, repoPath) {
|
|
|
20015
20500
|
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)
|
|
20016
20501
|
throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20017
20502
|
if (process.platform !== "linux") throw new CodingWorkspaceError("workspace_unsupported");
|
|
20018
|
-
const path3 =
|
|
20503
|
+
const path3 = resolve16(entry.worktree);
|
|
20019
20504
|
if (await realpath3(path3) !== path3) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20020
|
-
directory = await
|
|
20505
|
+
directory = await open3(path3, constants8.O_RDONLY | constants8.O_DIRECTORY | constants8.O_NOFOLLOW);
|
|
20021
20506
|
const root = {
|
|
20022
20507
|
path: path3,
|
|
20023
20508
|
handle: directory,
|
|
@@ -20029,7 +20514,7 @@ async function readWorkspaceDiffReceipt(command, entry, repoPath) {
|
|
|
20029
20514
|
if (remoteKey((await git3(["config", "--get", "remote.origin.url"])).toString().trim()) !== identity.repositoryKey)
|
|
20030
20515
|
throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20031
20516
|
const selection = request2.kind === "diff_snapshot" ? request2 : request2.revision.source === "working" ? { kind: "diff_snapshot", source: "working" } : { kind: "diff_snapshot", source: "commit", headSha: request2.revision.headSha, baseSha: request2.revision.baseSha };
|
|
20032
|
-
const value = await
|
|
20517
|
+
const value = await snapshot3(git3, root, entry, selection, signal);
|
|
20033
20518
|
if (Date.parse(expiresAt) <= Date.now()) throw new CodingWorkspaceError("workspace_request_expired");
|
|
20034
20519
|
const observation2 = { ok: true, identity, revision: value.revision, availability: "online", observedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
20035
20520
|
signal.throwIfAborted();
|
|
@@ -20085,9 +20570,9 @@ async function readWorkspaceRevertPreview(command, entry, repoPath) {
|
|
|
20085
20570
|
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)
|
|
20086
20571
|
throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20087
20572
|
if (process.platform !== "linux") throw new CodingWorkspaceError("workspace_unsupported");
|
|
20088
|
-
const path3 =
|
|
20573
|
+
const path3 = resolve16(entry.worktree);
|
|
20089
20574
|
if (await realpath3(path3) !== path3) throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20090
|
-
directory = await
|
|
20575
|
+
directory = await open3(path3, constants8.O_RDONLY | constants8.O_DIRECTORY | constants8.O_NOFOLLOW);
|
|
20091
20576
|
const root = {
|
|
20092
20577
|
path: path3,
|
|
20093
20578
|
handle: directory,
|
|
@@ -20098,7 +20583,7 @@ async function readWorkspaceRevertPreview(command, entry, repoPath) {
|
|
|
20098
20583
|
const signal = AbortSignal.timeout(remaining), git3 = await gitFor(repoPath, root, signal);
|
|
20099
20584
|
if (remoteKey((await git3(["config", "--get", "remote.origin.url"])).toString().trim()) !== identity.repositoryKey)
|
|
20100
20585
|
throw new CodingWorkspaceError("workspace_checkout_unavailable");
|
|
20101
|
-
const value = await
|
|
20586
|
+
const value = await snapshot3(git3, root, entry, { kind: "diff_snapshot", source: "working" }, signal);
|
|
20102
20587
|
if (value.revision.version !== request2.revision.version) throw new CodingWorkspaceError("workspace_version_conflict");
|
|
20103
20588
|
const file = value.files.find((candidate) => candidate.path === request2.file.path);
|
|
20104
20589
|
if (!file || file.fileVersion !== request2.file.fileVersion || file.path !== request2.file.path || file.previousPath !== request2.file.previousPath || file.status !== request2.file.status || file.oldBlob !== request2.file.oldBlob || file.newBlob !== request2.file.newBlob || file.oldMode !== request2.file.oldMode || file.newMode !== request2.file.newMode) throw new CodingWorkspaceError("workspace_version_conflict");
|
|
@@ -20154,11 +20639,11 @@ async function readWorkspaceRevertPreview(command, entry, repoPath) {
|
|
|
20154
20639
|
}
|
|
20155
20640
|
|
|
20156
20641
|
// src/coding-workspace/git.ts
|
|
20157
|
-
import { constants as
|
|
20158
|
-
import { lstat as
|
|
20159
|
-
import { createHash as
|
|
20160
|
-
import { join as
|
|
20161
|
-
import { tmpdir as
|
|
20642
|
+
import { constants as constants9 } from "node:fs";
|
|
20643
|
+
import { lstat as lstat5, mkdtemp as mkdtemp3, open as open4, readFile as readFile6, realpath as realpath4, rm as rm4, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
20644
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
20645
|
+
import { join as join33, resolve as resolve17 } from "node:path";
|
|
20646
|
+
import { tmpdir as tmpdir7 } from "node:os";
|
|
20162
20647
|
import { execa as execa14 } from "execa";
|
|
20163
20648
|
|
|
20164
20649
|
// src/coding-workspace/git-parse.ts
|
|
@@ -20291,7 +20776,7 @@ function parseHistoryCursor(cursor, headSha2) {
|
|
|
20291
20776
|
var historyCursor = (headSha2, offset) => `${headSha2}:${offset}`;
|
|
20292
20777
|
|
|
20293
20778
|
// src/coding-workspace/git.ts
|
|
20294
|
-
var digest8 = (value) =>
|
|
20779
|
+
var digest8 = (value) => createHash15("sha256").update(value).digest("hex");
|
|
20295
20780
|
var oid4 = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
20296
20781
|
var STATUS_BYTES = 8 * 1024 * 1024;
|
|
20297
20782
|
var STATUS_SCAN_BYTES = 16 * 1024 * 1024;
|
|
@@ -20313,9 +20798,9 @@ async function openPinnedRoot(command, entry) {
|
|
|
20313
20798
|
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)
|
|
20314
20799
|
throw unavailable4();
|
|
20315
20800
|
if (process.platform !== "linux") throw new CodingWorkspaceError("workspace_unsupported");
|
|
20316
|
-
const path3 =
|
|
20801
|
+
const path3 = resolve17(entry.worktree);
|
|
20317
20802
|
if (await realpath4(path3) !== path3) throw unavailable4();
|
|
20318
|
-
const directory = await
|
|
20803
|
+
const directory = await open4(path3, constants9.O_RDONLY | constants9.O_DIRECTORY | constants9.O_NOFOLLOW);
|
|
20319
20804
|
try {
|
|
20320
20805
|
const root = {
|
|
20321
20806
|
path: path3,
|
|
@@ -20363,13 +20848,13 @@ async function openParent(root, path3) {
|
|
|
20363
20848
|
let parent = root.handle;
|
|
20364
20849
|
try {
|
|
20365
20850
|
for (let index = 0; index < parts.length - 1; index++) {
|
|
20366
|
-
const handle = await
|
|
20851
|
+
const handle = await open4(
|
|
20367
20852
|
`/proc/self/fd/${parent.fd}/${parts[index]}`,
|
|
20368
|
-
|
|
20853
|
+
constants9.O_RDONLY | constants9.O_DIRECTORY | constants9.O_NOFOLLOW
|
|
20369
20854
|
);
|
|
20370
20855
|
parents.push(handle);
|
|
20371
|
-
const
|
|
20372
|
-
if (
|
|
20856
|
+
const stat3 = await handle.stat({ bigint: true });
|
|
20857
|
+
if (stat3.dev !== root.device || await mountId(handle) !== root.mountId) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
20373
20858
|
parent = handle;
|
|
20374
20859
|
}
|
|
20375
20860
|
return { parent, name: parts.at(-1), parents };
|
|
@@ -20395,8 +20880,8 @@ async function writePinnedFile(root, path3, bytes, executable2, expectation) {
|
|
|
20395
20880
|
let target;
|
|
20396
20881
|
try {
|
|
20397
20882
|
const targetPath = `/proc/self/fd/${parent.fd}/${name}`;
|
|
20398
|
-
const flags =
|
|
20399
|
-
target = await
|
|
20883
|
+
const flags = constants9.O_WRONLY | constants9.O_NOFOLLOW | (expectation.createOnly ? constants9.O_CREAT | constants9.O_EXCL : 0);
|
|
20884
|
+
target = await open4(targetPath, flags, executable2 ? 493 : 420);
|
|
20400
20885
|
const before = await target.stat({ bigint: true });
|
|
20401
20886
|
if (!before.isFile() || before.nlink !== 1n) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
20402
20887
|
if (expectation.fence && statFence(before) !== expectation.fence) throw conflict();
|
|
@@ -20418,16 +20903,16 @@ async function deletePinnedFile(root, path3, expectedFence) {
|
|
|
20418
20903
|
const { parent, name, parents } = await openParent(root, path3);
|
|
20419
20904
|
try {
|
|
20420
20905
|
const targetPath = `/proc/self/fd/${parent.fd}/${name}`;
|
|
20421
|
-
const
|
|
20906
|
+
const stat3 = await lstat5(targetPath, { bigint: true }).catch((error) => {
|
|
20422
20907
|
if (!missing(error)) throw error;
|
|
20423
20908
|
return null;
|
|
20424
20909
|
});
|
|
20425
|
-
if (!
|
|
20910
|
+
if (!stat3) {
|
|
20426
20911
|
if (expectedFence !== void 0) throw conflict();
|
|
20427
20912
|
return;
|
|
20428
20913
|
}
|
|
20429
|
-
if (
|
|
20430
|
-
if (expectedFence === void 0 || statFence(
|
|
20914
|
+
if (stat3.isSymbolicLink() || !stat3.isFile() || stat3.nlink !== 1n) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
20915
|
+
if (expectedFence === void 0 || statFence(stat3) !== expectedFence) throw conflict();
|
|
20431
20916
|
await unlink(targetPath);
|
|
20432
20917
|
} catch (error) {
|
|
20433
20918
|
if (error instanceof CodingWorkspaceError) throw error;
|
|
@@ -20753,15 +21238,15 @@ function runGit(cwd, args, env, signal, maximum = 8 * 1024 * 1024) {
|
|
|
20753
21238
|
}
|
|
20754
21239
|
async function readTempFile(worktree, path3) {
|
|
20755
21240
|
if (!visibleWorkspacePath(path3)) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
20756
|
-
const full =
|
|
21241
|
+
const full = join33(worktree, ...path3.split("/"));
|
|
20757
21242
|
if (!full.startsWith(`${worktree}/`)) throw new CodingWorkspaceError("workspace_path_unavailable");
|
|
20758
21243
|
try {
|
|
20759
|
-
const
|
|
20760
|
-
if (
|
|
20761
|
-
if (
|
|
20762
|
-
if (!
|
|
20763
|
-
if (
|
|
20764
|
-
return { exists: true, bytes: await
|
|
21244
|
+
const stat3 = await lstat5(full);
|
|
21245
|
+
if (stat3.isSymbolicLink()) return { exists: true, bytes: null, mode: null, reason: "unavailable" };
|
|
21246
|
+
if (stat3.isDirectory()) return { exists: true, bytes: null, mode: null, reason: "submodule" };
|
|
21247
|
+
if (!stat3.isFile()) return { exists: true, bytes: null, mode: null, reason: "unavailable" };
|
|
21248
|
+
if (stat3.size > RESTORE_FILE_BYTES) return { exists: true, bytes: null, mode: null, reason: "binary" };
|
|
21249
|
+
return { exists: true, bytes: await readFile6(full), mode: stat3.mode & 73 ? "100755" : "100644", reason: null };
|
|
20765
21250
|
} catch (error) {
|
|
20766
21251
|
if (missing(error)) return { exists: false, bytes: null, mode: null, reason: null };
|
|
20767
21252
|
throw error;
|
|
@@ -20774,8 +21259,8 @@ async function dryRunCheckpoint(git3, root, identity, statusBase, patchBase, pat
|
|
|
20774
21259
|
} catch (error) {
|
|
20775
21260
|
throw new CodingWorkspaceError("workspace_unsupported", { cause: error });
|
|
20776
21261
|
}
|
|
20777
|
-
const parent = await
|
|
20778
|
-
const worktree =
|
|
21262
|
+
const parent = await mkdtemp3(join33(tmpdir7(), "mikka-git-restore-"));
|
|
21263
|
+
const worktree = join33(parent, "wt"), patchFile = join33(parent, "checkpoint.patch");
|
|
20779
21264
|
try {
|
|
20780
21265
|
await writeFile4(patchFile, patch, { mode: 384 });
|
|
20781
21266
|
await runGit(git3.commonDir, ["worktree", "add", "--detach", "--quiet", worktree, head], commonEnv(git3), signal);
|
|
@@ -20853,7 +21338,7 @@ async function dryRunCheckpoint(git3, root, identity, statusBase, patchBase, pat
|
|
|
20853
21338
|
await runGit(git3.commonDir, ["worktree", "remove", "--force", worktree], commonEnv(git3), AbortSignal.timeout(5e3));
|
|
20854
21339
|
} catch {
|
|
20855
21340
|
}
|
|
20856
|
-
await
|
|
21341
|
+
await rm4(parent, { recursive: true, force: true });
|
|
20857
21342
|
}
|
|
20858
21343
|
}
|
|
20859
21344
|
function checkpointVersion(request2, plan) {
|
|
@@ -21055,9 +21540,9 @@ async function handleWorkspaceGitRequest(command, entry, repoPath) {
|
|
|
21055
21540
|
}
|
|
21056
21541
|
|
|
21057
21542
|
// src/repositories.ts
|
|
21058
|
-
import { createHash as
|
|
21543
|
+
import { createHash as createHash16, randomUUID as randomUUID7 } from "node:crypto";
|
|
21059
21544
|
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";
|
|
21060
|
-
import { dirname as
|
|
21545
|
+
import { dirname as dirname17, join as join34, resolve as resolve18 } from "node:path";
|
|
21061
21546
|
import { setTimeout as delay } from "node:timers/promises";
|
|
21062
21547
|
import { execa as execa15 } from "execa";
|
|
21063
21548
|
import lockfile2 from "proper-lockfile";
|
|
@@ -21081,8 +21566,8 @@ var RepositoryCache = class {
|
|
|
21081
21566
|
retainResources;
|
|
21082
21567
|
pathFor(remoteUrl) {
|
|
21083
21568
|
const { key: key2 } = normalizeRepository(remoteUrl, { allowFile: this.allowFile });
|
|
21084
|
-
const path3 =
|
|
21085
|
-
if (!isInside(
|
|
21569
|
+
const path3 = resolve18(this.root, "v2", createHash16("sha256").update(key2).digest("hex"));
|
|
21570
|
+
if (!isInside(resolve18(this.root), path3) || path3 === resolve18(this.root)) throw new Error("Invalid repository cache path");
|
|
21086
21571
|
return path3;
|
|
21087
21572
|
}
|
|
21088
21573
|
/** Serialize clone/fetch against the same cache, including other processes. */
|
|
@@ -21090,7 +21575,7 @@ var RepositoryCache = class {
|
|
|
21090
21575
|
signal?.throwIfAborted();
|
|
21091
21576
|
const { remoteUrl: remote } = normalizeRepository(remoteUrl, { allowFile: this.allowFile });
|
|
21092
21577
|
const path3 = this.pathFor(remote);
|
|
21093
|
-
this.ensureParents(
|
|
21578
|
+
this.ensureParents(dirname17(path3));
|
|
21094
21579
|
const release = await this.lock(path3, signal);
|
|
21095
21580
|
try {
|
|
21096
21581
|
return await withRepoConfig(path3, () => this.update(path3, remote, signal, env, diagnostics));
|
|
@@ -21101,18 +21586,18 @@ var RepositoryCache = class {
|
|
|
21101
21586
|
async update(path3, remote, signal, env = {}, diagnostics) {
|
|
21102
21587
|
signal?.throwIfAborted();
|
|
21103
21588
|
const git3 = (args, cwd) => {
|
|
21104
|
-
const
|
|
21589
|
+
const execute3 = () => execa15("git", [
|
|
21105
21590
|
...FETCH_GIT,
|
|
21106
21591
|
"-c",
|
|
21107
21592
|
`protocol.file.allow=${this.allowFile ? "always" : "never"}`,
|
|
21108
21593
|
...args
|
|
21109
21594
|
], { cwd, env: { ...process.env, ...env, GIT_TERMINAL_PROMPT: "0" }, stdin: "ignore", timeout: FETCH_TIMEOUT_MS, cancelSignal: signal, killDescendants: true });
|
|
21110
|
-
if (!diagnostics) return
|
|
21595
|
+
if (!diagnostics) return execute3();
|
|
21111
21596
|
const phase = args[0] === "clone" ? "clone" : args[0] === "fetch" ? "fetch" : args[0] === "remote" && args[1] === "set-head" ? "remote_head" : args[0] === "ls-remote" ? "remote_refs" : "local";
|
|
21112
21597
|
const traced = () => daemonTracer.span(
|
|
21113
21598
|
`daemon.repository.git.${phase}`,
|
|
21114
21599
|
{ "mikka.run.id_hash": diagnostics.runIdHash, "mikka.harness": diagnostics.harness },
|
|
21115
|
-
|
|
21600
|
+
execute3
|
|
21116
21601
|
);
|
|
21117
21602
|
return diagnostics.timer ? diagnostics.timer.measure(phase, traced) : traced();
|
|
21118
21603
|
};
|
|
@@ -21129,7 +21614,7 @@ var RepositoryCache = class {
|
|
|
21129
21614
|
} else {
|
|
21130
21615
|
this.assertClone(path3);
|
|
21131
21616
|
await git3(["remote", "set-url", "origin", remote], path3);
|
|
21132
|
-
const depth = existsSync7(
|
|
21617
|
+
const depth = existsSync7(join34(path3, ".git", "shallow")) ? ["--depth=50"] : [];
|
|
21133
21618
|
await git3(["fetch", ...depth, ...this.retainResources ? [] : ["--prune"], "--no-tags", "--no-recurse-submodules", "--no-write-fetch-head", "origin"], path3);
|
|
21134
21619
|
}
|
|
21135
21620
|
this.assertClone(path3);
|
|
@@ -21221,28 +21706,28 @@ var RepositoryCache = class {
|
|
|
21221
21706
|
paths() {
|
|
21222
21707
|
const visit = (path3) => {
|
|
21223
21708
|
if (!existsSync7(path3) || lstatSync12(path3).isSymbolicLink()) return [];
|
|
21224
|
-
if (existsSync7(
|
|
21709
|
+
if (existsSync7(join34(path3, ".git"))) {
|
|
21225
21710
|
this.assertClone(path3);
|
|
21226
21711
|
return [path3];
|
|
21227
21712
|
}
|
|
21228
|
-
return readdirSync9(path3, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() && !entry.name.endsWith(".lock") && !entry.name.includes(".clone-") ? visit(
|
|
21713
|
+
return readdirSync9(path3, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() && !entry.name.endsWith(".lock") && !entry.name.includes(".clone-") ? visit(join34(path3, entry.name)) : []);
|
|
21229
21714
|
};
|
|
21230
|
-
return visit(
|
|
21715
|
+
return visit(resolve18(this.root));
|
|
21231
21716
|
}
|
|
21232
21717
|
ensureParents(path3) {
|
|
21233
21718
|
mkdirSync17(this.root, { recursive: true, mode: 448 });
|
|
21234
21719
|
if (lstatSync12(this.root).isSymbolicLink()) throw new Error("Repository cache contains a symlink");
|
|
21235
21720
|
const root = realpathSync13(this.root);
|
|
21236
|
-
let current =
|
|
21721
|
+
let current = resolve18(this.root);
|
|
21237
21722
|
for (const part of path3.slice(current.length + 1).split("/").filter(Boolean)) {
|
|
21238
|
-
current =
|
|
21723
|
+
current = join34(current, part);
|
|
21239
21724
|
if (existsSync7(current) && lstatSync12(current).isSymbolicLink()) throw new Error("Repository cache contains a symlink");
|
|
21240
21725
|
mkdirSync17(current, { recursive: true, mode: 448 });
|
|
21241
21726
|
if (!isInside(root, realpathSync13(current))) throw new Error("Repository cache escapes its directory");
|
|
21242
21727
|
}
|
|
21243
21728
|
}
|
|
21244
21729
|
assertClone(path3) {
|
|
21245
|
-
if (lstatSync12(path3).isSymbolicLink() || !lstatSync12(
|
|
21730
|
+
if (lstatSync12(path3).isSymbolicLink() || !lstatSync12(join34(path3, ".git")).isDirectory() || lstatSync12(join34(path3, ".git")).isSymbolicLink()) throw new Error("Repository cache is not a standard clone");
|
|
21246
21731
|
if (!isInside(realpathSync13(this.root), realpathSync13(path3))) throw new Error("Repository cache escapes its directory");
|
|
21247
21732
|
}
|
|
21248
21733
|
async lock(path3, signal) {
|
|
@@ -21348,11 +21833,11 @@ async function prepareRunRepository(repositories, privateDir, assignment, signal
|
|
|
21348
21833
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
21349
21834
|
import { spawn as spawn5 } from "node:child_process";
|
|
21350
21835
|
import { existsSync as existsSync8, mkdirSync as mkdirSync18, realpathSync as realpathSync14 } from "node:fs";
|
|
21351
|
-
import { dirname as
|
|
21836
|
+
import { dirname as dirname18, join as join35, resolve as resolve19 } from "node:path";
|
|
21352
21837
|
import { fileURLToPath } from "node:url";
|
|
21353
21838
|
|
|
21354
21839
|
// src/official-cli-timing.ts
|
|
21355
|
-
import { createHash as
|
|
21840
|
+
import { createHash as createHash17, randomBytes as randomBytes4 } from "node:crypto";
|
|
21356
21841
|
import { createServer as createServer4 } from "node:http";
|
|
21357
21842
|
|
|
21358
21843
|
// src/mcp-http-timing.ts
|
|
@@ -21676,7 +22161,7 @@ var OfficialCliTimingCollector = class {
|
|
|
21676
22161
|
};
|
|
21677
22162
|
async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, decisionCatalogue }) {
|
|
21678
22163
|
const collector = new OfficialCliTimingCollector(runId, harness);
|
|
21679
|
-
const expectedCatalogueSha256 = decisionCatalogue ?
|
|
22164
|
+
const expectedCatalogueSha256 = decisionCatalogue ? createHash17("sha256").update(JSON.stringify(decisionCatalogue)).digest("hex") : null;
|
|
21680
22165
|
const mcpCollector = new McpHttpTimingCollector(runId, harness, remoteMcpServerCount, Date.now, expectedCatalogueSha256);
|
|
21681
22166
|
const path3 = `/v1/logs/${randomBytes4(16).toString("hex")}`;
|
|
21682
22167
|
const mcpPath = `/v1/mcp-http/${randomBytes4(16).toString("hex")}`;
|
|
@@ -21717,11 +22202,11 @@ async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, d
|
|
|
21717
22202
|
server.requestTimeout = 5e3;
|
|
21718
22203
|
server.headersTimeout = 5e3;
|
|
21719
22204
|
server.maxConnections = 8;
|
|
21720
|
-
await new Promise((
|
|
22205
|
+
await new Promise((resolve20, reject) => {
|
|
21721
22206
|
server.once("error", reject);
|
|
21722
22207
|
server.listen(0, "127.0.0.1", () => {
|
|
21723
22208
|
server.off("error", reject);
|
|
21724
|
-
|
|
22209
|
+
resolve20();
|
|
21725
22210
|
});
|
|
21726
22211
|
});
|
|
21727
22212
|
server.on("error", () => {
|
|
@@ -21770,7 +22255,7 @@ async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, d
|
|
|
21770
22255
|
unsetEnv,
|
|
21771
22256
|
mcpHttpObservationUrl: `${origin}${mcpPath}`,
|
|
21772
22257
|
close: ({ cliExitObserved = false, publish = true } = {}) => closed ??= (async () => {
|
|
21773
|
-
await new Promise((
|
|
22258
|
+
await new Promise((resolve20) => {
|
|
21774
22259
|
const timer = setTimeout(() => {
|
|
21775
22260
|
collector.truncate();
|
|
21776
22261
|
mcpCollector.truncate();
|
|
@@ -21778,7 +22263,7 @@ async function startCliTimingCollector({ runId, harness, remoteMcpServerCount, d
|
|
|
21778
22263
|
}, 1e3);
|
|
21779
22264
|
server.close(() => {
|
|
21780
22265
|
clearTimeout(timer);
|
|
21781
|
-
|
|
22266
|
+
resolve20();
|
|
21782
22267
|
});
|
|
21783
22268
|
});
|
|
21784
22269
|
const official = collector.finish(cliExitObserved), mcp = mcpCollector.finish();
|
|
@@ -21816,7 +22301,7 @@ async function runHostedCommand(worktree, script, _readOnly, timeoutMs, signal)
|
|
|
21816
22301
|
abort();
|
|
21817
22302
|
} else chunks.push(chunk);
|
|
21818
22303
|
};
|
|
21819
|
-
const result = await new Promise((
|
|
22304
|
+
const result = await new Promise((resolve20, reject) => {
|
|
21820
22305
|
child = spawn5("/bin/sh", ["-c", script], {
|
|
21821
22306
|
cwd: realpathSync14(worktree),
|
|
21822
22307
|
env: process.env,
|
|
@@ -21826,7 +22311,7 @@ async function runHostedCommand(worktree, script, _readOnly, timeoutMs, signal)
|
|
|
21826
22311
|
child.stdout?.on("data", (chunk) => collect("stdout", stdout, chunk));
|
|
21827
22312
|
child.stderr?.on("data", (chunk) => collect("stderr", stderr, chunk));
|
|
21828
22313
|
child.once("error", reject);
|
|
21829
|
-
child.once("close", (code, term) =>
|
|
22314
|
+
child.once("close", (code, term) => resolve20({ code, signal: term }));
|
|
21830
22315
|
child.once("exit", abort);
|
|
21831
22316
|
signal?.addEventListener("abort", abort, { once: true });
|
|
21832
22317
|
if (signal?.aborted) abort();
|
|
@@ -21952,7 +22437,7 @@ async function createHostedBotRunner(host) {
|
|
|
21952
22437
|
if (selected && (!options.model || options.model !== subscription?.first.modelId)) throw Error("binding_mismatch");
|
|
21953
22438
|
const paths = runPaths(host.stateDir, assignment.runId);
|
|
21954
22439
|
mkdirSync18(paths.runDir, { recursive: true, mode: 448 });
|
|
21955
|
-
const cwd = preparation ?
|
|
22440
|
+
const cwd = preparation ? resolve19(options.cwd) : realpathSync14(options.cwd);
|
|
21956
22441
|
const env = Object.fromEntries(Object.entries({ ...process.env, ...options.env, ...assignment.taskEnv }).filter((entry) => typeof entry[1] === "string"));
|
|
21957
22442
|
if (runDiagnosticsEnabled(assignment.taskEnv, host.collectCliTiming)) env.CLOUD_STARTUP_TIMING = "1";
|
|
21958
22443
|
const selectedGithub = options.github ?? (assignment.github ? { ...assignment.github, issueId: assignment.issueId, runToken: assignment.mcp?.token } : void 0);
|
|
@@ -21983,7 +22468,7 @@ async function createHostedBotRunner(host) {
|
|
|
21983
22468
|
});
|
|
21984
22469
|
Object.assign(env, github.env);
|
|
21985
22470
|
}
|
|
21986
|
-
const ledger =
|
|
22471
|
+
const ledger = join35(host.stateDir, "native-ledgers", assignment.runId + ".json");
|
|
21987
22472
|
const scope = selected && subscription ? {
|
|
21988
22473
|
runId: assignment.runId,
|
|
21989
22474
|
bindingId: selected.bindingId,
|
|
@@ -21996,12 +22481,12 @@ async function createHostedBotRunner(host) {
|
|
|
21996
22481
|
modelId: subscription.first.modelId
|
|
21997
22482
|
} : void 0;
|
|
21998
22483
|
if (continuation && existsSync8(ledger)) throw unavailable5("ledger_mismatch");
|
|
21999
|
-
const previousLedger = continuation ?
|
|
22484
|
+
const previousLedger = continuation ? join35(host.stateDir, "native-ledgers", continuation.runId + ".json") : ledger;
|
|
22000
22485
|
const previous = scope ? readJson(previousLedger) : void 0;
|
|
22001
22486
|
if (preparation && previous) throw unavailable5("ledger_mismatch");
|
|
22002
22487
|
const expectedScope = scope && continuation ? { ...scope, runId: continuation.runId } : scope;
|
|
22003
22488
|
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");
|
|
22004
|
-
if (scope) mkdirSync18(
|
|
22489
|
+
if (scope) mkdirSync18(dirname18(ledger), { recursive: true, mode: 448 });
|
|
22005
22490
|
const record3 = async (sessionId) => {
|
|
22006
22491
|
assertOpen();
|
|
22007
22492
|
if (scope) writeJsonAtomic(ledger, { scope, sessionId });
|
|
@@ -22073,9 +22558,9 @@ async function createHostedBotRunner(host) {
|
|
|
22073
22558
|
signal: lifetime.signal
|
|
22074
22559
|
});
|
|
22075
22560
|
child.stderr?.resume();
|
|
22076
|
-
const exited = new Promise((
|
|
22077
|
-
child.once("exit", (code, signal) =>
|
|
22078
|
-
child.once("error", () =>
|
|
22561
|
+
const exited = new Promise((resolve20) => {
|
|
22562
|
+
child.once("exit", (code, signal) => resolve20({ code, signal }));
|
|
22563
|
+
child.once("error", () => resolve20({ code: null, signal: null }));
|
|
22079
22564
|
});
|
|
22080
22565
|
return {
|
|
22081
22566
|
process: child,
|
|
@@ -22179,9 +22664,9 @@ async function createHostedBotRunner(host) {
|
|
|
22179
22664
|
await close();
|
|
22180
22665
|
}
|
|
22181
22666
|
},
|
|
22182
|
-
send: async (text4) => {
|
|
22667
|
+
send: async (text4, mode) => {
|
|
22183
22668
|
assertOpen();
|
|
22184
|
-
await session.send(text4);
|
|
22669
|
+
await session.send(text4, mode);
|
|
22185
22670
|
},
|
|
22186
22671
|
cancel: async () => {
|
|
22187
22672
|
try {
|
|
@@ -22262,7 +22747,7 @@ async function createHostedBotRunner(host) {
|
|
|
22262
22747
|
import {
|
|
22263
22748
|
randomBytes as randomBytes5,
|
|
22264
22749
|
randomUUID as randomUUID9,
|
|
22265
|
-
createHash as
|
|
22750
|
+
createHash as createHash19,
|
|
22266
22751
|
timingSafeEqual as timingSafeEqual2
|
|
22267
22752
|
} from "node:crypto";
|
|
22268
22753
|
import { chmodSync as chmodSync2 } from "node:fs";
|
|
@@ -22270,12 +22755,12 @@ import { createServer as createServer5 } from "node:net";
|
|
|
22270
22755
|
|
|
22271
22756
|
// src/computer/driver.mjs
|
|
22272
22757
|
import { spawn as spawn6 } from "node:child_process";
|
|
22273
|
-
import { execFile as
|
|
22274
|
-
import { promisify as
|
|
22275
|
-
import { createHash as
|
|
22276
|
-
import { readFile as
|
|
22758
|
+
import { execFile as execFile8 } from "node:child_process";
|
|
22759
|
+
import { promisify as promisify8 } from "node:util";
|
|
22760
|
+
import { createHash as createHash18 } from "node:crypto";
|
|
22761
|
+
import { readFile as readFile7, realpath as realpath5 } from "node:fs/promises";
|
|
22277
22762
|
import { createInterface } from "node:readline";
|
|
22278
|
-
var exec3 =
|
|
22763
|
+
var exec3 = promisify8(execFile8);
|
|
22279
22764
|
async function detectComputerDriver(binary = "cua-driver") {
|
|
22280
22765
|
try {
|
|
22281
22766
|
const { stdout: located } = await exec3("which", [binary], {
|
|
@@ -22289,7 +22774,7 @@ async function detectComputerDriver(binary = "cua-driver") {
|
|
|
22289
22774
|
installed: true,
|
|
22290
22775
|
version,
|
|
22291
22776
|
path: path3,
|
|
22292
|
-
fingerprint:
|
|
22777
|
+
fingerprint: createHash18("sha256").update(await readFile7(path3)).digest("hex")
|
|
22293
22778
|
};
|
|
22294
22779
|
} catch {
|
|
22295
22780
|
return null;
|
|
@@ -22356,7 +22841,7 @@ async function executeDriver(driver, input, display, leaseGuard, assertLive = ()
|
|
|
22356
22841
|
if (display !== void 0 && !/^:[1-9][0-9]{0,3}$/.test(display))
|
|
22357
22842
|
throw new Error("Invalid desktop display");
|
|
22358
22843
|
const call = normalizeCall(input);
|
|
22359
|
-
const fingerprint2 =
|
|
22844
|
+
const fingerprint2 = createHash18("sha256").update(await readFile7(driver.path)).digest("hex");
|
|
22360
22845
|
if (fingerprint2 !== driver.fingerprint)
|
|
22361
22846
|
throw new Error("Driver changed; restart and approve a new request");
|
|
22362
22847
|
const args = driverArguments(call);
|
|
@@ -22419,9 +22904,9 @@ async function executeDriver(driver, input, display, leaseGuard, assertLive = ()
|
|
|
22419
22904
|
)
|
|
22420
22905
|
)
|
|
22421
22906
|
);
|
|
22422
|
-
const request2 = (method, params) => new Promise((
|
|
22907
|
+
const request2 = (method, params) => new Promise((resolve20, reject) => {
|
|
22423
22908
|
const n = ++id5;
|
|
22424
|
-
pending.set(n, { resolve:
|
|
22909
|
+
pending.set(n, { resolve: resolve20, reject });
|
|
22425
22910
|
child.stdin.write(
|
|
22426
22911
|
JSON.stringify({ jsonrpc: "2.0", id: n, method, params }) + "\n"
|
|
22427
22912
|
);
|
|
@@ -22459,6 +22944,8 @@ var ComputerBroker = class {
|
|
|
22459
22944
|
grants = /* @__PURE__ */ new Map();
|
|
22460
22945
|
// runId → when its screen recording stops by itself; only set while one runs.
|
|
22461
22946
|
recordingUntil = /* @__PURE__ */ new Map();
|
|
22947
|
+
recordingSteps = /* @__PURE__ */ new Map();
|
|
22948
|
+
recordingTimingFailed = /* @__PURE__ */ new Set();
|
|
22462
22949
|
pending = /* @__PURE__ */ new Map();
|
|
22463
22950
|
sockets = /* @__PURE__ */ new Set();
|
|
22464
22951
|
suspended = false;
|
|
@@ -22467,13 +22954,13 @@ var ComputerBroker = class {
|
|
|
22467
22954
|
socketPath,
|
|
22468
22955
|
transport = "unix",
|
|
22469
22956
|
permitted,
|
|
22470
|
-
execute:
|
|
22957
|
+
execute: execute3 = (driver2, call, display, _runId, context) => executeDriver(driver2, call, display, void 0, context.assertLive),
|
|
22471
22958
|
capture,
|
|
22472
22959
|
now = Date.now,
|
|
22473
22960
|
ttl = 3e5,
|
|
22474
22961
|
needsPerson
|
|
22475
22962
|
}) {
|
|
22476
|
-
Object.assign(this, { driver, socketPath, permitted, execute:
|
|
22963
|
+
Object.assign(this, { driver, socketPath, permitted, execute: execute3, capture, now, ttl, transport, needsPerson });
|
|
22477
22964
|
}
|
|
22478
22965
|
// runId → the last few action kinds, evidence for the Decisions API.
|
|
22479
22966
|
recent = /* @__PURE__ */ new Map();
|
|
@@ -22535,10 +23022,10 @@ var ComputerBroker = class {
|
|
|
22535
23022
|
})();
|
|
22536
23023
|
});
|
|
22537
23024
|
});
|
|
22538
|
-
await new Promise((
|
|
23025
|
+
await new Promise((resolve20, reject) => {
|
|
22539
23026
|
this.server.once("error", reject);
|
|
22540
|
-
if (this.transport === "tcp") this.server.listen({ host: "127.0.0.1", port: 0 },
|
|
22541
|
-
else this.server.listen(this.socketPath,
|
|
23027
|
+
if (this.transport === "tcp") this.server.listen({ host: "127.0.0.1", port: 0 }, resolve20);
|
|
23028
|
+
else this.server.listen(this.socketPath, resolve20);
|
|
22542
23029
|
});
|
|
22543
23030
|
if (this.transport === "tcp") this.socketPath = `tcp://127.0.0.1:${this.server.address().port}`;
|
|
22544
23031
|
else chmodSync2(this.socketPath, 384);
|
|
@@ -22549,23 +23036,39 @@ var ComputerBroker = class {
|
|
|
22549
23036
|
return Promise.reject(new Error("Not permitted"));
|
|
22550
23037
|
const call = normalizeCall(value);
|
|
22551
23038
|
const step = actionStep(value);
|
|
22552
|
-
return this.requestCall(token, grant, call, signal)
|
|
22553
|
-
this.markStep(grant.runId, step);
|
|
22554
|
-
return result;
|
|
22555
|
-
});
|
|
23039
|
+
return this.requestCall(token, grant, call, signal, step);
|
|
22556
23040
|
}
|
|
22557
|
-
/**
|
|
22558
|
-
|
|
23041
|
+
/** Timings cover execution itself, excluding decision and human-approval waits. */
|
|
23042
|
+
async executeRecorded(driver, call, display, runId, context, step) {
|
|
23043
|
+
const started = this.now();
|
|
23044
|
+
try {
|
|
23045
|
+
return await this.execute(driver, call, display, runId, context);
|
|
23046
|
+
} finally {
|
|
23047
|
+
const label2 = step ?? { get_desktop_state: "Read the screen", click: "Click", type_text: "Type text", press_key: "Press a key", scroll: "Scroll" }[call.name];
|
|
23048
|
+
this.markStep(runId, label2, Math.max(0, Math.round(this.now() - started)));
|
|
23049
|
+
}
|
|
23050
|
+
}
|
|
23051
|
+
/** Pending timing writes drain before stop, so the last action cannot disappear. */
|
|
23052
|
+
markStep(runId, label2, durationMs) {
|
|
22559
23053
|
const until = this.recordingUntil.get(runId);
|
|
22560
23054
|
if (!label2 || !this.capture || until === void 0) return;
|
|
22561
|
-
if (this.now() > until) {
|
|
23055
|
+
if (this.now() > until + 3e4) {
|
|
22562
23056
|
this.recordingUntil.delete(runId);
|
|
22563
23057
|
return;
|
|
22564
23058
|
}
|
|
22565
|
-
|
|
23059
|
+
const pending = this.recordingSteps.get(runId) ?? /* @__PURE__ */ new Set();
|
|
23060
|
+
const write = Promise.resolve().then(() => this.capture(runId, { action: "step", label: label2, source: "action", durationMs: Math.min(durationMs, 3e5) }, AbortSignal.timeout(5e3))).then((result) => {
|
|
23061
|
+
if (result?.recorded === false) this.recordingTimingFailed.add(runId);
|
|
23062
|
+
}).catch(() => {
|
|
23063
|
+
this.recordingTimingFailed.add(runId);
|
|
23064
|
+
}).finally(() => {
|
|
23065
|
+
pending.delete(write);
|
|
23066
|
+
if (!pending.size) this.recordingSteps.delete(runId);
|
|
22566
23067
|
});
|
|
23068
|
+
pending.add(write);
|
|
23069
|
+
this.recordingSteps.set(runId, pending);
|
|
22567
23070
|
}
|
|
22568
|
-
requestCall(token, grant, call, signal) {
|
|
23071
|
+
requestCall(token, grant, call, signal, step) {
|
|
22569
23072
|
const actionId = randomUUID9();
|
|
22570
23073
|
const assertLive = () => {
|
|
22571
23074
|
if (this.suspended || signal?.aborted || this.grants.get(token) !== grant || this.driver?.fingerprint !== grant.fingerprint || !this.permitted(grant.runId))
|
|
@@ -22574,7 +23077,7 @@ var ComputerBroker = class {
|
|
|
22574
23077
|
if (grant.permission === "allow") {
|
|
22575
23078
|
return Promise.resolve().then(() => {
|
|
22576
23079
|
assertLive();
|
|
22577
|
-
return this.
|
|
23080
|
+
return this.executeRecorded(this.driver, call, grant.display, grant.runId, { actionId, assertLive }, step);
|
|
22578
23081
|
});
|
|
22579
23082
|
}
|
|
22580
23083
|
if (this.needsPerson) {
|
|
@@ -22589,15 +23092,15 @@ var ComputerBroker = class {
|
|
|
22589
23092
|
}).then((needsPerson) => {
|
|
22590
23093
|
if (needsPerson !== false) {
|
|
22591
23094
|
if (needsPerson !== true) console.warn(`Decision fallback: computer action ${call.name} reviewed as before without a judgment`);
|
|
22592
|
-
return this.review(token, grant, call, actionId, assertLive, signal);
|
|
23095
|
+
return this.review(token, grant, call, actionId, assertLive, signal, step);
|
|
22593
23096
|
}
|
|
22594
23097
|
assertLive();
|
|
22595
|
-
return this.
|
|
23098
|
+
return this.executeRecorded(this.driver, call, grant.display, grant.runId, { actionId, assertLive }, step);
|
|
22596
23099
|
});
|
|
22597
23100
|
}
|
|
22598
|
-
return this.review(token, grant, call, actionId, assertLive, signal);
|
|
23101
|
+
return this.review(token, grant, call, actionId, assertLive, signal, step);
|
|
22599
23102
|
}
|
|
22600
|
-
review(token, grant, call, actionId, assertLive, signal) {
|
|
23103
|
+
review(token, grant, call, actionId, assertLive, signal, step) {
|
|
22601
23104
|
if (this.pending.size >= 20) return Promise.reject(new Error("Not permitted"));
|
|
22602
23105
|
const request2 = {
|
|
22603
23106
|
id: actionId,
|
|
@@ -22607,8 +23110,8 @@ var ComputerBroker = class {
|
|
|
22607
23110
|
call,
|
|
22608
23111
|
expiresAt: this.now() + this.ttl
|
|
22609
23112
|
};
|
|
22610
|
-
const digest9 =
|
|
22611
|
-
return new Promise((
|
|
23113
|
+
const digest9 = createHash19("sha256").update(JSON.stringify(request2)).digest("hex");
|
|
23114
|
+
return new Promise((resolve20, reject) => {
|
|
22612
23115
|
const timer = setTimeout(() => {
|
|
22613
23116
|
this.pending.delete(request2.id);
|
|
22614
23117
|
signal?.removeEventListener("abort", cancel);
|
|
@@ -22622,10 +23125,11 @@ var ComputerBroker = class {
|
|
|
22622
23125
|
signal?.addEventListener("abort", cancel, { once: true });
|
|
22623
23126
|
this.pending.set(request2.id, {
|
|
22624
23127
|
token,
|
|
23128
|
+
step,
|
|
22625
23129
|
assertLive,
|
|
22626
23130
|
cleanup: () => signal?.removeEventListener("abort", cancel),
|
|
22627
23131
|
request: { ...request2, digest: digest9 },
|
|
22628
|
-
resolve:
|
|
23132
|
+
resolve: resolve20,
|
|
22629
23133
|
reject,
|
|
22630
23134
|
timer
|
|
22631
23135
|
});
|
|
@@ -22639,9 +23143,20 @@ var ComputerBroker = class {
|
|
|
22639
23143
|
return { error: "Not permitted" };
|
|
22640
23144
|
const call = normalizeCaptureCall(value);
|
|
22641
23145
|
try {
|
|
23146
|
+
if (call.action === "stop_recording") {
|
|
23147
|
+
await Promise.all(this.recordingSteps.get(grant.runId) ?? []);
|
|
23148
|
+
if (this.recordingTimingFailed.has(grant.runId))
|
|
23149
|
+
await this.capture(grant.runId, { action: "step", label: "Recording timing incomplete", source: "action" }, signal);
|
|
23150
|
+
}
|
|
22642
23151
|
const result = await this.capture(grant.runId, call, signal);
|
|
22643
|
-
if (call.action === "start_recording" && typeof result?.stopsAt === "string")
|
|
22644
|
-
|
|
23152
|
+
if (call.action === "start_recording" && typeof result?.stopsAt === "string") {
|
|
23153
|
+
this.recordingUntil.set(grant.runId, Date.parse(result.stopsAt));
|
|
23154
|
+
this.recordingTimingFailed.delete(grant.runId);
|
|
23155
|
+
}
|
|
23156
|
+
if (call.action === "stop_recording") {
|
|
23157
|
+
this.recordingUntil.delete(grant.runId);
|
|
23158
|
+
this.recordingTimingFailed.delete(grant.runId);
|
|
23159
|
+
}
|
|
22645
23160
|
return { result };
|
|
22646
23161
|
} catch (error) {
|
|
22647
23162
|
const detail = typeof error?.safeMessage === "string" ? error.safeMessage.slice(0, 300) : void 0;
|
|
@@ -22686,7 +23201,7 @@ var ComputerBroker = class {
|
|
|
22686
23201
|
throw new Error("Not permitted");
|
|
22687
23202
|
};
|
|
22688
23203
|
assertLive();
|
|
22689
|
-
row.resolve(await this.
|
|
23204
|
+
row.resolve(await this.executeRecorded(this.driver, call, display, runId, { actionId: id5, assertLive }, row.step));
|
|
22690
23205
|
} catch (error) {
|
|
22691
23206
|
row.reject(error);
|
|
22692
23207
|
}
|
|
@@ -22707,15 +23222,15 @@ var ComputerBroker = class {
|
|
|
22707
23222
|
async close() {
|
|
22708
23223
|
this.suspend();
|
|
22709
23224
|
for (const socket of this.sockets) socket.destroy();
|
|
22710
|
-
if (this.server?.listening) await new Promise((
|
|
23225
|
+
if (this.server?.listening) await new Promise((resolve20) => this.server.close(resolve20));
|
|
22711
23226
|
}
|
|
22712
23227
|
};
|
|
22713
23228
|
|
|
22714
23229
|
// src/computer/credential-executor.ts
|
|
22715
|
-
import { createHash as
|
|
23230
|
+
import { createHash as createHash20 } from "node:crypto";
|
|
22716
23231
|
function credentialAwareExecutor(deps) {
|
|
22717
23232
|
return async (driver, call, display, runId, context) => {
|
|
22718
|
-
const digest9 =
|
|
23233
|
+
const digest9 = createHash20("sha256").update(JSON.stringify(call)).digest("hex");
|
|
22719
23234
|
const resolved = await deps.consumeMatchingIntent(runId, context.actionId, digest9);
|
|
22720
23235
|
context.assertLive();
|
|
22721
23236
|
if (resolved.kind === "ordinary") return deps.executeOrdinary(driver, call, display, runId, context.assertLive);
|
|
@@ -22754,8 +23269,8 @@ function createHostedComputerExecutor(deps) {
|
|
|
22754
23269
|
// src/computer/web-review.ts
|
|
22755
23270
|
async function applyWebComputerDecisions(broker, decisions) {
|
|
22756
23271
|
for (const decision of decisions) {
|
|
22757
|
-
const
|
|
22758
|
-
if (!
|
|
23272
|
+
const snapshot4 = broker.list().find((row) => row.id === decision.id);
|
|
23273
|
+
if (!snapshot4 || snapshot4.digest !== decision.digest) continue;
|
|
22759
23274
|
await broker.decide(decision.id, decision.digest, decision.approve).catch(() => void 0);
|
|
22760
23275
|
}
|
|
22761
23276
|
}
|
|
@@ -22782,9 +23297,9 @@ async function pollWebComputerReviews(broker, deviceId, link, signal, intervalMs
|
|
|
22782
23297
|
});
|
|
22783
23298
|
try {
|
|
22784
23299
|
while (!signal.aborted) {
|
|
22785
|
-
const
|
|
22786
|
-
const pending =
|
|
22787
|
-
const key2 = snapshotKey(
|
|
23300
|
+
const snapshot4 = broker.list();
|
|
23301
|
+
const pending = snapshot4.length > 0;
|
|
23302
|
+
const key2 = snapshotKey(snapshot4);
|
|
22788
23303
|
const everyCheck = (pushes?.mode("computerReviews") ?? "legacy") !== "push";
|
|
22789
23304
|
if (key2 !== synced || pending && (pushed || everyCheck || Date.now() - syncedAt >= presenceMs)) {
|
|
22790
23305
|
pushed = false;
|
|
@@ -22797,11 +23312,11 @@ async function pollWebComputerReviews(broker, deviceId, link, signal, intervalMs
|
|
|
22797
23312
|
}
|
|
22798
23313
|
if (signal.aborted) break;
|
|
22799
23314
|
if (pushes) await pushes.next(intervalMs, signal);
|
|
22800
|
-
else await new Promise((
|
|
23315
|
+
else await new Promise((resolve20) => {
|
|
22801
23316
|
const done = () => {
|
|
22802
23317
|
clearTimeout(timer);
|
|
22803
23318
|
signal.removeEventListener("abort", done);
|
|
22804
|
-
|
|
23319
|
+
resolve20();
|
|
22805
23320
|
};
|
|
22806
23321
|
const timer = setTimeout(done, intervalMs);
|
|
22807
23322
|
signal.addEventListener("abort", done, { once: true });
|
|
@@ -22846,16 +23361,16 @@ var DeviceWorkSignal = class {
|
|
|
22846
23361
|
}
|
|
22847
23362
|
/** Resolves on the next push or mode change, after `ms`, or on abort. */
|
|
22848
23363
|
next(ms2, signal) {
|
|
22849
|
-
return new Promise((
|
|
23364
|
+
return new Promise((resolve20) => {
|
|
22850
23365
|
if (signal?.aborted) {
|
|
22851
|
-
|
|
23366
|
+
resolve20();
|
|
22852
23367
|
return;
|
|
22853
23368
|
}
|
|
22854
23369
|
const done = () => {
|
|
22855
23370
|
clearTimeout(timer);
|
|
22856
23371
|
off();
|
|
22857
23372
|
signal?.removeEventListener("abort", done);
|
|
22858
|
-
|
|
23373
|
+
resolve20();
|
|
22859
23374
|
};
|
|
22860
23375
|
const timer = setTimeout(done, Math.max(0, ms2));
|
|
22861
23376
|
const off = this.subscribe(done);
|
|
@@ -22888,8 +23403,8 @@ var HARNESS_RESCAN_MS = 5 * 6e4;
|
|
|
22888
23403
|
var MODEL_PROBE_MS = 6 * 60 * 6e4;
|
|
22889
23404
|
function cloudComputerGrantMatches(assignment, runId, deviceId) {
|
|
22890
23405
|
if (!assignment?.computer || !deviceId || assignment.runId !== runId || assignment.deviceId !== deviceId) return false;
|
|
22891
|
-
const
|
|
22892
|
-
return !
|
|
23406
|
+
const snapshot4 = assignment.policySnapshot?.payload;
|
|
23407
|
+
return !snapshot4 || snapshot4.runId === runId && snapshot4.deviceId === deviceId && snapshot4.ownerId === assignment.computer.ownerId;
|
|
22893
23408
|
}
|
|
22894
23409
|
var Daemon = class {
|
|
22895
23410
|
constructor(options) {
|
|
@@ -22962,6 +23477,7 @@ var Daemon = class {
|
|
|
22962
23477
|
localComputerBroker = null;
|
|
22963
23478
|
/** Messages handed to an agent whose delivery the server has not taken yet. */
|
|
22964
23479
|
unacked = /* @__PURE__ */ new Set();
|
|
23480
|
+
refusedSteers = /* @__PURE__ */ new Set();
|
|
22965
23481
|
/** Runs this daemon already started cancelling for a stop request. */
|
|
22966
23482
|
stopping = /* @__PURE__ */ new Set();
|
|
22967
23483
|
/** Runs this daemon has ended, whose end the server may not have yet. */
|
|
@@ -23000,7 +23516,7 @@ var Daemon = class {
|
|
|
23000
23516
|
if (this.options.credential)
|
|
23001
23517
|
this.saveDevice({ credential: this.options.credential });
|
|
23002
23518
|
this.journal = new RunJournal(paths.journal);
|
|
23003
|
-
this.captureUploader = new CaptureUploader((runId) =>
|
|
23519
|
+
this.captureUploader = new CaptureUploader((runId) => join36(runPaths(paths.adapterState, runId).runDir, CAPTURES_DIR), this.options.link, this.log, join36(paths.dataDir, "capture-pending"));
|
|
23004
23520
|
this.outbox = new Outbox(
|
|
23005
23521
|
paths.outbox,
|
|
23006
23522
|
this.options.link,
|
|
@@ -23019,7 +23535,7 @@ var Daemon = class {
|
|
|
23019
23535
|
if (this.localComputerDriver && this.options.link.syncComputerReviews) {
|
|
23020
23536
|
this.localComputerBroker = new ComputerBroker({
|
|
23021
23537
|
driver: this.localComputerDriver,
|
|
23022
|
-
socketPath:
|
|
23538
|
+
socketPath: join36(paths.dataDir, "local-computer.sock"),
|
|
23023
23539
|
transport: "tcp",
|
|
23024
23540
|
needsPerson: this.computerNeedsPerson(),
|
|
23025
23541
|
permitted: (runId) => {
|
|
@@ -23062,7 +23578,7 @@ var Daemon = class {
|
|
|
23062
23578
|
};
|
|
23063
23579
|
this.cloudComputerBroker = new ComputerBroker({
|
|
23064
23580
|
driver,
|
|
23065
|
-
socketPath:
|
|
23581
|
+
socketPath: join36(paths.dataDir, "computer.sock"),
|
|
23066
23582
|
needsPerson: this.computerNeedsPerson(),
|
|
23067
23583
|
permitted: (runId) => {
|
|
23068
23584
|
const entry = this.journal.get(runId);
|
|
@@ -23141,7 +23657,7 @@ var Daemon = class {
|
|
|
23141
23657
|
) : this.realAdapters()
|
|
23142
23658
|
]);
|
|
23143
23659
|
this.supervisor = new RunSupervisor({
|
|
23144
|
-
acquireWorkspaceControl: this.options.taskRegistered ? (assignment, signal, onLost) => acquireCloudWorkspaceControl({ runId: assignment.runId, deviceId: assignment.deviceId, signal, onLost }) : void 0,
|
|
23660
|
+
acquireWorkspaceControl: this.options.e2bContainerRuntime || this.options.taskRegistered ? (assignment, signal, onLost) => acquireCloudWorkspaceControl({ runId: assignment.runId, deviceId: assignment.deviceId, signal, onLost }) : void 0,
|
|
23145
23661
|
collectCliTiming: this.options.collectCliTiming,
|
|
23146
23662
|
journal: this.journal,
|
|
23147
23663
|
adapterStateDir: this.paths.adapterState,
|
|
@@ -23156,7 +23672,7 @@ var Daemon = class {
|
|
|
23156
23672
|
prepareRunMailbox: this.options.link.prepareRunMailbox?.bind(this.options.link),
|
|
23157
23673
|
prepareRunToolApproval: this.options.link.prepareRunToolApproval?.bind(this.options.link),
|
|
23158
23674
|
prepareRunGitHub: hosted ? void 0 : (assignment, signal, onCredential) => prepareLocalGitHub(assignment, {
|
|
23159
|
-
stateDir:
|
|
23675
|
+
stateDir: join36(this.paths.adapterState, "github"),
|
|
23160
23676
|
link: this.options.link,
|
|
23161
23677
|
signal,
|
|
23162
23678
|
onCredential,
|
|
@@ -23226,7 +23742,7 @@ var Daemon = class {
|
|
|
23226
23742
|
worktree,
|
|
23227
23743
|
tree,
|
|
23228
23744
|
github: { ...assignment.github, runToken: assignment.mcp?.token, issueId: assignment.issueId },
|
|
23229
|
-
privateDir:
|
|
23745
|
+
privateDir: join36(paths.adapterState, "pids"),
|
|
23230
23746
|
...hosted ? { hosted: true } : {},
|
|
23231
23747
|
env: hosted ? process.env : githubReceiptEnvironment(),
|
|
23232
23748
|
githubEnvironment,
|
|
@@ -23273,6 +23789,7 @@ var Daemon = class {
|
|
|
23273
23789
|
...this.modelReports.get(info.harness),
|
|
23274
23790
|
// The run's live gate stops a revoked run; Codex also verifies its
|
|
23275
23791
|
// pinned interface at initialize.
|
|
23792
|
+
...info.harness === "codex" && info.installed ? { activeTurnSteer: true } : {},
|
|
23276
23793
|
toolApproval: this.supportsToolApproval(info),
|
|
23277
23794
|
coordinator: false
|
|
23278
23795
|
})) : await Promise.all(supported.map((info) => this.localHarnessReport(info)));
|
|
@@ -23323,10 +23840,13 @@ var Daemon = class {
|
|
|
23323
23840
|
await this.pauseCommands(1e3, signal);
|
|
23324
23841
|
continue;
|
|
23325
23842
|
}
|
|
23326
|
-
if (this.unacked.size > 0) {
|
|
23843
|
+
if (this.unacked.size > 0 || this.refusedSteers.size > 0) {
|
|
23327
23844
|
const ids = [...this.unacked].slice(0, 500);
|
|
23328
|
-
|
|
23845
|
+
const refused2 = [...this.refusedSteers].slice(0, 500);
|
|
23846
|
+
if (refused2.length) await link.ackCommands(deviceId, ids, refused2);
|
|
23847
|
+
else await link.ackCommands(deviceId, ids);
|
|
23329
23848
|
for (const id5 of ids) this.unacked.delete(id5);
|
|
23849
|
+
for (const id5 of refused2) this.refusedSteers.delete(id5);
|
|
23330
23850
|
}
|
|
23331
23851
|
if (await this.holdGateway(deviceId, signal)) {
|
|
23332
23852
|
backoff = 1e3;
|
|
@@ -23374,7 +23894,7 @@ var Daemon = class {
|
|
|
23374
23894
|
await this.pauseCommands(500, signal);
|
|
23375
23895
|
continue;
|
|
23376
23896
|
}
|
|
23377
|
-
if (this.unacked.size > 0) continue;
|
|
23897
|
+
if (this.unacked.size > 0 || this.refusedSteers.size > 0) continue;
|
|
23378
23898
|
if (news) continue;
|
|
23379
23899
|
if (commands.length === 0 && !signal.aborted) {
|
|
23380
23900
|
const remaining = Math.max(1e3, wait * 1e3) - (performance.now() - started);
|
|
@@ -23417,10 +23937,13 @@ var Daemon = class {
|
|
|
23417
23937
|
if (this.stopped || signal.aborted) return;
|
|
23418
23938
|
await this.applyCommands(commands);
|
|
23419
23939
|
if (queued.length > 0) this.claimQueued(queued);
|
|
23420
|
-
while (this.unacked.size > 0 && !signal.aborted) {
|
|
23940
|
+
while ((this.unacked.size > 0 || this.refusedSteers.size > 0) && !signal.aborted) {
|
|
23421
23941
|
const ids = [...this.unacked].slice(0, 500);
|
|
23422
|
-
|
|
23942
|
+
const refused2 = [...this.refusedSteers].slice(0, 500);
|
|
23943
|
+
if (refused2.length) await this.options.link.ackCommands(deviceId, ids, refused2);
|
|
23944
|
+
else await this.options.link.ackCommands(deviceId, ids);
|
|
23423
23945
|
for (const id5 of ids) this.unacked.delete(id5);
|
|
23946
|
+
for (const id5 of refused2) this.refusedSteers.delete(id5);
|
|
23424
23947
|
}
|
|
23425
23948
|
}
|
|
23426
23949
|
/**
|
|
@@ -23449,8 +23972,8 @@ var Daemon = class {
|
|
|
23449
23972
|
}
|
|
23450
23973
|
if (signal.aborted) return false;
|
|
23451
23974
|
const socket = openDeviceGateway(ticket.url, ticket.protocol);
|
|
23452
|
-
void daemonTracer.span("daemon.gateway.connect", { "mikka.gateway.mode": this.runControlPush ? "push" : "legacy" }, () => new Promise((
|
|
23453
|
-
gatewayOpened =
|
|
23975
|
+
void daemonTracer.span("daemon.gateway.connect", { "mikka.gateway.mode": this.runControlPush ? "push" : "legacy" }, () => new Promise((resolve20, reject) => {
|
|
23976
|
+
gatewayOpened = resolve20;
|
|
23454
23977
|
gatewayFailed = reject;
|
|
23455
23978
|
}), { root: true }).catch(() => void 0);
|
|
23456
23979
|
await runDeviceGateway(socket, {
|
|
@@ -23575,12 +24098,12 @@ var Daemon = class {
|
|
|
23575
24098
|
/** Waits `ms`, or less if the daemon stops or the device registers. */
|
|
23576
24099
|
pauseCommands(ms2, signal) {
|
|
23577
24100
|
if (signal.aborted) return Promise.resolve();
|
|
23578
|
-
return new Promise((
|
|
24101
|
+
return new Promise((resolve20) => {
|
|
23579
24102
|
const done = () => {
|
|
23580
24103
|
clearTimeout(timer);
|
|
23581
24104
|
signal.removeEventListener("abort", done);
|
|
23582
24105
|
this.wakeCommands = null;
|
|
23583
|
-
|
|
24106
|
+
resolve20();
|
|
23584
24107
|
};
|
|
23585
24108
|
const timer = setTimeout(done, ms2);
|
|
23586
24109
|
signal.addEventListener("abort", done, { once: true });
|
|
@@ -23616,6 +24139,33 @@ var Daemon = class {
|
|
|
23616
24139
|
for (const command of commands) {
|
|
23617
24140
|
const entry = this.journal.get(command.runId);
|
|
23618
24141
|
if (!entry) continue;
|
|
24142
|
+
if (command.kind === "steer") {
|
|
24143
|
+
const id5 = command.messageId;
|
|
24144
|
+
const prior = entry.steerReceipts?.[id5];
|
|
24145
|
+
if (prior === "accepted") {
|
|
24146
|
+
this.unacked.add(id5);
|
|
24147
|
+
continue;
|
|
24148
|
+
}
|
|
24149
|
+
if (prior || isTerminalRunState(entry.state)) {
|
|
24150
|
+
this.refusedSteers.add(id5);
|
|
24151
|
+
continue;
|
|
24152
|
+
}
|
|
24153
|
+
const record3 = (outcome) => this.journal.update(
|
|
24154
|
+
command.runId,
|
|
24155
|
+
{ steerReceipts: { ...this.journal.get(command.runId)?.steerReceipts, [id5]: outcome } }
|
|
24156
|
+
);
|
|
24157
|
+
record3("starting");
|
|
24158
|
+
try {
|
|
24159
|
+
await this.supervisor.send(command.runId, command.text, "steer");
|
|
24160
|
+
record3("accepted");
|
|
24161
|
+
this.unacked.add(id5);
|
|
24162
|
+
} catch {
|
|
24163
|
+
record3("refused");
|
|
24164
|
+
this.refusedSteers.add(id5);
|
|
24165
|
+
}
|
|
24166
|
+
acted = true;
|
|
24167
|
+
continue;
|
|
24168
|
+
}
|
|
23619
24169
|
if (isTerminalRunState(entry.state)) {
|
|
23620
24170
|
if (command.kind === "stop")
|
|
23621
24171
|
void this.supervisor.discardIfEmpty(command.runId, command.runId);
|
|
@@ -23684,6 +24234,7 @@ var Daemon = class {
|
|
|
23684
24234
|
const report2 = {
|
|
23685
24235
|
...info,
|
|
23686
24236
|
...this.modelReports.get(info.harness),
|
|
24237
|
+
...info.harness === "codex" && info.installed ? { activeTurnSteer: true } : {},
|
|
23687
24238
|
toolApproval: this.supportsToolApproval(info),
|
|
23688
24239
|
coordinator: false
|
|
23689
24240
|
};
|
|
@@ -23824,11 +24375,11 @@ var Daemon = class {
|
|
|
23824
24375
|
return runVerify(sandbox, {
|
|
23825
24376
|
command,
|
|
23826
24377
|
worktree: realpathSync15(worktree),
|
|
23827
|
-
tmpRoot:
|
|
24378
|
+
tmpRoot: join36(this.paths.adapterState, "verify", runId),
|
|
23828
24379
|
privateDir: paths.privateDir,
|
|
23829
24380
|
pidFile: paths.pidFile.replace(/\.pgid$/, ".verify.pgid"),
|
|
23830
24381
|
networkAllow: repo.networkAllow,
|
|
23831
|
-
env: { ...buildChildEnv(), ...githubEnvironment, MIKKA_HANDOFF_FILE:
|
|
24382
|
+
env: { ...buildChildEnv(), ...githubEnvironment, MIKKA_HANDOFF_FILE: join36(paths.runDir, "handoff.json") },
|
|
23832
24383
|
timeoutMs,
|
|
23833
24384
|
signal,
|
|
23834
24385
|
readOnly
|
|
@@ -23918,7 +24469,7 @@ var Daemon = class {
|
|
|
23918
24469
|
}
|
|
23919
24470
|
/** Idle on the push socket: no runs, nothing waiting to upload. The database can sleep. */
|
|
23920
24471
|
gatewayIdle() {
|
|
23921
|
-
return this.gatewayLive && this.server === "online" && this.supervisor.heartbeatRuns().length === 0 && this.queuedClaims.size === 0 && this.unacked.size === 0 && this.outbox.pending() === 0 && !this.draining && !this.updating && this.deviceReceiptsVersion === this.deviceReceiptsAcknowledged;
|
|
24472
|
+
return this.gatewayLive && this.server === "online" && this.supervisor.heartbeatRuns().length === 0 && this.queuedClaims.size === 0 && this.unacked.size === 0 && this.refusedSteers.size === 0 && this.outbox.pending() === 0 && !this.draining && !this.updating && this.deviceReceiptsVersion === this.deviceReceiptsAcknowledged;
|
|
23922
24473
|
}
|
|
23923
24474
|
schedule(delay2) {
|
|
23924
24475
|
if (this.stopped) return;
|
|
@@ -24000,14 +24551,14 @@ var Daemon = class {
|
|
|
24000
24551
|
}
|
|
24001
24552
|
const initialRunId = this.initialRunHint;
|
|
24002
24553
|
let resolveRepositories, rejectRepositories;
|
|
24003
|
-
const repositoriesReady = initialRunId ? new Promise((
|
|
24004
|
-
resolveRepositories =
|
|
24554
|
+
const repositoriesReady = initialRunId ? new Promise((resolve20, reject) => {
|
|
24555
|
+
resolveRepositories = resolve20;
|
|
24005
24556
|
rejectRepositories = reject;
|
|
24006
24557
|
}) : void 0;
|
|
24007
24558
|
if (initialRunId && repositoriesReady) {
|
|
24008
24559
|
let received;
|
|
24009
|
-
const repository2 = this.options.hostedSubscriptions && this.options.e2bContainerRuntime && this.journal.all().length === 0 ? new Promise((
|
|
24010
|
-
received =
|
|
24560
|
+
const repository2 = this.options.hostedSubscriptions && this.options.e2bContainerRuntime && this.journal.all().length === 0 ? new Promise((resolve20) => {
|
|
24561
|
+
received = resolve20;
|
|
24011
24562
|
}) : void 0;
|
|
24012
24563
|
this.initialRepositorySync = { runId: initialRunId, ready: repositoriesReady, repository: repository2, received };
|
|
24013
24564
|
void repositoriesReady.catch(() => void 0);
|
|
@@ -24436,7 +24987,7 @@ var Daemon = class {
|
|
|
24436
24987
|
});
|
|
24437
24988
|
}
|
|
24438
24989
|
get updateStateFile() {
|
|
24439
|
-
return
|
|
24990
|
+
return join36(this.paths.dataDir, "auto-update.json");
|
|
24440
24991
|
}
|
|
24441
24992
|
/** A server named this release (heartbeat, commands poll or refused claim); older servers name none. */
|
|
24442
24993
|
learnRelease(latest) {
|
|
@@ -24535,7 +25086,7 @@ function isNoDaemon(error) {
|
|
|
24535
25086
|
}
|
|
24536
25087
|
async function connectDaemon(options) {
|
|
24537
25088
|
const socket = connect(options.socketPath);
|
|
24538
|
-
await new Promise((
|
|
25089
|
+
await new Promise((resolve20, reject) => {
|
|
24539
25090
|
const timer = setTimeout(() => {
|
|
24540
25091
|
socket.destroy();
|
|
24541
25092
|
reject(
|
|
@@ -24546,7 +25097,7 @@ async function connectDaemon(options) {
|
|
|
24546
25097
|
}, options.timeoutMs ?? 3e3);
|
|
24547
25098
|
socket.once("connect", () => {
|
|
24548
25099
|
clearTimeout(timer);
|
|
24549
|
-
|
|
25100
|
+
resolve20();
|
|
24550
25101
|
});
|
|
24551
25102
|
socket.once("error", (error) => {
|
|
24552
25103
|
clearTimeout(timer);
|
|
@@ -24583,9 +25134,9 @@ async function connectDaemon(options) {
|
|
|
24583
25134
|
if (isProtocolMismatch(error) && options.drainOnMismatch) {
|
|
24584
25135
|
await Promise.race([
|
|
24585
25136
|
connection.sendRequest("daemon.drain", {}).catch(() => void 0),
|
|
24586
|
-
new Promise((
|
|
24587
|
-
connection.onClose(
|
|
24588
|
-
setTimeout(
|
|
25137
|
+
new Promise((resolve20) => {
|
|
25138
|
+
connection.onClose(resolve20);
|
|
25139
|
+
setTimeout(resolve20, 2e3).unref();
|
|
24589
25140
|
})
|
|
24590
25141
|
]);
|
|
24591
25142
|
}
|
|
@@ -24644,8 +25195,8 @@ async function connectStartingDaemon(dataDir) {
|
|
|
24644
25195
|
}
|
|
24645
25196
|
if (!daemonProcessAlive(dataDir)) return void 0;
|
|
24646
25197
|
if (revision2 !== before) continue;
|
|
24647
|
-
await new Promise((
|
|
24648
|
-
wake =
|
|
25198
|
+
await new Promise((resolve20) => {
|
|
25199
|
+
wake = resolve20;
|
|
24649
25200
|
});
|
|
24650
25201
|
wake = void 0;
|
|
24651
25202
|
}
|