@jigging/jig 0.1.0-alpha.10 → 0.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -11
- package/bin/jig +2 -0
- package/dist/index.js +17 -1
- package/dist/project/author.d.ts +2 -0
- package/libexec/evaluator/project-authoring-1.schema.json +7 -1
- package/libexec/evaluator/project-evaluator-sdk.bundle.js +17 -1
- package/libexec/installed-cli.js +1252 -1004
- package/package.json +1 -1
package/libexec/installed-cli.js
CHANGED
|
@@ -6995,7 +6995,7 @@ var require_x509_transport_state = __commonJS((exports, module) => {
|
|
|
6995
6995
|
});
|
|
6996
6996
|
|
|
6997
6997
|
// src/installed-cli.ts
|
|
6998
|
-
import { realpath as
|
|
6998
|
+
import { realpath as realpath14 } from "fs/promises";
|
|
6999
6999
|
import { dirname as dirname7 } from "path";
|
|
7000
7000
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
7001
7001
|
|
|
@@ -9289,10 +9289,20 @@ function normalizeFlowSlots(value) {
|
|
|
9289
9289
|
const output = Object.create(null);
|
|
9290
9290
|
for (const name of Object.keys(input).sort(compareUtf8)) {
|
|
9291
9291
|
validateLocalName(name, "slot name");
|
|
9292
|
-
|
|
9292
|
+
const target = parseRunTargetSelector(input[name], `slot ${name}`);
|
|
9293
|
+
output[name] = target.kind === "flow" ? `flow:${target.path}` : `binding:${target.id}`;
|
|
9293
9294
|
}
|
|
9294
9295
|
return Object.freeze(output);
|
|
9295
9296
|
}
|
|
9297
|
+
function parseRunTargetSelector(value, label) {
|
|
9298
|
+
if (typeof value !== "string")
|
|
9299
|
+
throw new TypeError(`${label} must be a target selector`);
|
|
9300
|
+
if (value.startsWith("flow:"))
|
|
9301
|
+
return flowRef(normalizeProjectPath(value.slice(5), label));
|
|
9302
|
+
if (value.startsWith("binding:"))
|
|
9303
|
+
return bindingRef(validateLocalName(value.slice(8), label));
|
|
9304
|
+
throw new TypeError(`${label} must select flow:<path> or binding:<id>`);
|
|
9305
|
+
}
|
|
9296
9306
|
function normalizeSource(value, field, canonical) {
|
|
9297
9307
|
if (value === undefined)
|
|
9298
9308
|
throw new TypeError(`${field} cannot be undefined`);
|
|
@@ -10039,7 +10049,8 @@ function renderFailure(error, runtime) {
|
|
|
10039
10049
|
}
|
|
10040
10050
|
if (error instanceof ProjectAdministrationError) {
|
|
10041
10051
|
const projected = projectError(error.code);
|
|
10042
|
-
|
|
10052
|
+
const hint = error.diagnostic?.code === "PROJECT_AGENT_UNAVAILABLE" ? "configure the host Agent before review; check credentials, model, and selected client" : error.diagnostic?.code === "PACKAGE_BUN_PREPARATION_FAILED" ? "locked dependencies could not be prepared; check registry access and package availability" : undefined;
|
|
10053
|
+
runtime.writeError(error.diagnostic !== undefined ? renderProjectDiagnostic(error, hint ?? projected.message) : renderDiagnostic(error.code, projected.message));
|
|
10043
10054
|
return projected.exitCode;
|
|
10044
10055
|
}
|
|
10045
10056
|
if (error instanceof RootAdministrationError) {
|
|
@@ -10113,7 +10124,7 @@ if (false) {}
|
|
|
10113
10124
|
|
|
10114
10125
|
// src/internal/installed-bun-support.ts
|
|
10115
10126
|
import { constants } from "fs";
|
|
10116
|
-
import { access, lstat, realpath } from "fs/promises";
|
|
10127
|
+
import { access, lstat, realpath as realpath2 } from "fs/promises";
|
|
10117
10128
|
import { dirname, join as join2 } from "path";
|
|
10118
10129
|
|
|
10119
10130
|
// src/internal/identity.ts
|
|
@@ -10136,6 +10147,29 @@ async function privateFileDigest(path) {
|
|
|
10136
10147
|
return `sha256:${hash.digest("hex")}`;
|
|
10137
10148
|
}
|
|
10138
10149
|
|
|
10150
|
+
// src/internal/linux-host-paths.ts
|
|
10151
|
+
import { realpath } from "fs/promises";
|
|
10152
|
+
function privateLinuxHostToolCandidates(name) {
|
|
10153
|
+
return [`/usr/bin/${name}`, `/bin/${name}`, `/run/current-system/sw/bin/${name}`];
|
|
10154
|
+
}
|
|
10155
|
+
async function resolvePrivateLinuxHostPath(candidates, resolve2 = realpath) {
|
|
10156
|
+
for (const path of candidates) {
|
|
10157
|
+
try {
|
|
10158
|
+
return await resolve2(path);
|
|
10159
|
+
} catch (error) {
|
|
10160
|
+
if (error.code !== "ENOENT")
|
|
10161
|
+
throw error;
|
|
10162
|
+
}
|
|
10163
|
+
}
|
|
10164
|
+
throw new Error("the required system-owned host file is unavailable");
|
|
10165
|
+
}
|
|
10166
|
+
function resolvePrivateLinuxHostLoader(resolve2 = realpath) {
|
|
10167
|
+
return resolvePrivateLinuxHostPath([
|
|
10168
|
+
"/run/current-system/sw/share/nix-ld/lib/ld.so",
|
|
10169
|
+
"/lib64/ld-linux-x86-64.so.2"
|
|
10170
|
+
], resolve2);
|
|
10171
|
+
}
|
|
10172
|
+
|
|
10139
10173
|
// src/internal/installed-bun-support.ts
|
|
10140
10174
|
var ELF_INTERPRETER = "/lib64/ld-linux-x86-64.so.2";
|
|
10141
10175
|
var LIBRARIES = Object.freeze([
|
|
@@ -10185,7 +10219,7 @@ async function openPrivateInstalledBunSupport(location) {
|
|
|
10185
10219
|
})));
|
|
10186
10220
|
const preparationWorkerPath = await exactRegularFile(join2(releaseRoot, "libexec", "preparation", "bun-native-preparation-worker.js"), false, "installed Bun preparation worker");
|
|
10187
10221
|
const agentWorkerPath = await exactRegularFile(join2(releaseRoot, "libexec", "agent", "openai-agent-worker.js"), false, "installed Agent provider worker");
|
|
10188
|
-
const loaderPath = await exactRegularFile(
|
|
10222
|
+
const loaderPath = await exactRegularFile(await resolvePrivateLinuxHostLoader(), true, "supported-host ELF interpreter");
|
|
10189
10223
|
const hostLibraryDirectory = dirname(loaderPath);
|
|
10190
10224
|
const libraries = await Promise.all(LIBRARIES.map(async (name) => Object.freeze({
|
|
10191
10225
|
name,
|
|
@@ -10296,7 +10330,7 @@ async function resolveInstalledBun(releaseRoot) {
|
|
|
10296
10330
|
throw new Error("the exact installed Bun dependency is unavailable");
|
|
10297
10331
|
}
|
|
10298
10332
|
async function exactRegularFile(path, executable, label) {
|
|
10299
|
-
const resolved = await
|
|
10333
|
+
const resolved = await realpath2(path);
|
|
10300
10334
|
const information = await lstat(resolved);
|
|
10301
10335
|
if (!information.isFile() || information.isSymbolicLink() || executable && (information.mode & 73) === 0) {
|
|
10302
10336
|
throw new Error(`${label} is unavailable`);
|
|
@@ -10306,7 +10340,7 @@ async function exactRegularFile(path, executable, label) {
|
|
|
10306
10340
|
return resolved;
|
|
10307
10341
|
}
|
|
10308
10342
|
async function exactDirectory(path, label) {
|
|
10309
|
-
const resolved = await
|
|
10343
|
+
const resolved = await realpath2(path);
|
|
10310
10344
|
const information = await lstat(resolved);
|
|
10311
10345
|
if (!information.isDirectory() || information.isSymbolicLink()) {
|
|
10312
10346
|
throw new Error(`${label} is unavailable`);
|
|
@@ -10325,7 +10359,7 @@ import {
|
|
|
10325
10359
|
open,
|
|
10326
10360
|
readFile as readFile2,
|
|
10327
10361
|
readdir as readdir2,
|
|
10328
|
-
realpath as
|
|
10362
|
+
realpath as realpath4,
|
|
10329
10363
|
rm,
|
|
10330
10364
|
rmdir as rmdir2,
|
|
10331
10365
|
statfs as statfs2,
|
|
@@ -10344,14 +10378,13 @@ import {
|
|
|
10344
10378
|
access as access2,
|
|
10345
10379
|
readFile,
|
|
10346
10380
|
readdir,
|
|
10347
|
-
realpath as
|
|
10381
|
+
realpath as realpath3,
|
|
10348
10382
|
stat,
|
|
10349
10383
|
statfs
|
|
10350
10384
|
} from "fs/promises";
|
|
10351
10385
|
import { posix } from "path";
|
|
10352
10386
|
var CGROUP_ROOT = "/sys/fs/cgroup";
|
|
10353
10387
|
var CGROUP2_SUPER_MAGIC = 0x6367_7270n;
|
|
10354
|
-
var BUBBLEWRAP_PATH = "/usr/bin/bwrap";
|
|
10355
10388
|
var MAX_PROCESS_OUTPUT_BYTES = 16 * 1024;
|
|
10356
10389
|
var REQUIRED_CONTROLLERS = Object.freeze(["cpu", "memory", "pids"]);
|
|
10357
10390
|
var REQUIRED_BUBBLEWRAP_FEATURES = Object.freeze([
|
|
@@ -10444,7 +10477,11 @@ async function observe(dependencies, retained, activeRunCgroups = Object.freeze(
|
|
|
10444
10477
|
}
|
|
10445
10478
|
await dependencies.requireAccess(`${currentCgroup}/cgroup.events`, constants2.R_OK);
|
|
10446
10479
|
await dependencies.requireAccess(`${currentCgroup}/cgroup.kill`, constants2.W_OK);
|
|
10447
|
-
const
|
|
10480
|
+
const selectedPath = dependencies.bubblewrapPath?.();
|
|
10481
|
+
if (selectedPath !== undefined && (!posix.isAbsolute(selectedPath) || selectedPath.includes("\x00"))) {
|
|
10482
|
+
throw new Error("JIG_BWRAP_PATH must be an absolute executable path");
|
|
10483
|
+
}
|
|
10484
|
+
const bubblewrapPath = await resolvePrivateLinuxHostPath(selectedPath === undefined ? privateLinuxHostToolCandidates("bwrap") : [selectedPath], dependencies.resolve);
|
|
10448
10485
|
if (!bubblewrapPath.startsWith("/") || bubblewrapPath.includes("\x00")) {
|
|
10449
10486
|
throw new Error("Bubblewrap did not resolve to an absolute path");
|
|
10450
10487
|
}
|
|
@@ -10541,13 +10578,14 @@ function bubblewrapFeatureProbe(path) {
|
|
|
10541
10578
|
return Object.freeze(arguments_);
|
|
10542
10579
|
}
|
|
10543
10580
|
var systemDependencies = Object.freeze({
|
|
10581
|
+
bubblewrapPath: () => process.env.JIG_BWRAP_PATH,
|
|
10544
10582
|
uid: () => process.getuid?.(),
|
|
10545
10583
|
gid: () => process.getgid?.(),
|
|
10546
10584
|
readText: (path) => readFile(path, "utf8"),
|
|
10547
10585
|
listDirectories: async (path) => (await readdir(path, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name),
|
|
10548
10586
|
information: (path) => stat(path),
|
|
10549
10587
|
filesystemType: async (path) => (await statfs(path)).type,
|
|
10550
|
-
resolve: (path) =>
|
|
10588
|
+
resolve: (path) => realpath3(path),
|
|
10551
10589
|
requireAccess: (path, mode) => access2(path, mode),
|
|
10552
10590
|
execute: runExecutable
|
|
10553
10591
|
});
|
|
@@ -10935,7 +10973,7 @@ function requirePrivateLinuxCgroupBackend(value) {
|
|
|
10935
10973
|
async function planPrivateLinuxOwnerStateAllocation(location) {
|
|
10936
10974
|
if (!OWNER_NAME.test(location.name))
|
|
10937
10975
|
throw new TypeError("Linux owner-state name is invalid");
|
|
10938
|
-
const parent = await
|
|
10976
|
+
const parent = await realpath4(requireAbsolute(location.parent, "Linux owner-state parent"));
|
|
10939
10977
|
if (parent !== location.parent)
|
|
10940
10978
|
throw new TypeError("Linux owner-state parent must be canonical");
|
|
10941
10979
|
const information = await lstat2(parent, { bigint: true });
|
|
@@ -11301,9 +11339,9 @@ async function observeInitialMechanism(options) {
|
|
|
11301
11339
|
}
|
|
11302
11340
|
async function observeMechanismWithAuthority(options, authority) {
|
|
11303
11341
|
const [bunPath, bunHostLibraryPath, supervisorPath] = await Promise.all([
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
|
|
11342
|
+
realpath4(options.bunPath),
|
|
11343
|
+
realpath4(options.bunHostLibraryPath),
|
|
11344
|
+
realpath4(options.supervisorPath)
|
|
11307
11345
|
]);
|
|
11308
11346
|
if (bunPath !== options.bunPath || bunHostLibraryPath !== options.bunHostLibraryPath || supervisorPath !== options.supervisorPath) {
|
|
11309
11347
|
throw new Error("rootless Linux support paths must be canonical");
|
|
@@ -11357,7 +11395,7 @@ async function observeMechanismWithAuthority(options, authority) {
|
|
|
11357
11395
|
}
|
|
11358
11396
|
async function observeLinuxBootId() {
|
|
11359
11397
|
const [resolved, information, filesystem, text] = await Promise.all([
|
|
11360
|
-
|
|
11398
|
+
realpath4(BOOT_ID_PATH),
|
|
11361
11399
|
lstat2(BOOT_ID_PATH),
|
|
11362
11400
|
statfs2(BOOT_ID_PATH),
|
|
11363
11401
|
readFile2(BOOT_ID_PATH, "utf8")
|
|
@@ -11434,7 +11472,7 @@ async function sealPlan(plan) {
|
|
|
11434
11472
|
const snapshot = snapshotPlan(plan);
|
|
11435
11473
|
const mounts = [];
|
|
11436
11474
|
for (const mount of snapshot.readOnlyMounts) {
|
|
11437
|
-
const source = await
|
|
11475
|
+
const source = await realpath4(mount.source);
|
|
11438
11476
|
const [information, filesystem] = await Promise.all([
|
|
11439
11477
|
lstat2(source, { bigint: true }),
|
|
11440
11478
|
statfs2(source)
|
|
@@ -13633,13 +13671,13 @@ function requireApi(value) {
|
|
|
13633
13671
|
}
|
|
13634
13672
|
|
|
13635
13673
|
// src/internal/codex-agent-provider.ts
|
|
13636
|
-
import { lstat as lstat4, readFile as readFile3, realpath as
|
|
13674
|
+
import { lstat as lstat4, readFile as readFile3, realpath as realpath6 } from "fs/promises";
|
|
13637
13675
|
import { homedir } from "os";
|
|
13638
13676
|
import { join as join4 } from "path";
|
|
13639
13677
|
|
|
13640
13678
|
// src/internal/acp-agent-provider.ts
|
|
13641
13679
|
import { constants as constants3 } from "fs";
|
|
13642
|
-
import { access as access3, lstat as lstat3, realpath as
|
|
13680
|
+
import { access as access3, lstat as lstat3, realpath as realpath5 } from "fs/promises";
|
|
13643
13681
|
var IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._:/+-]{0,255}$/;
|
|
13644
13682
|
var SECRET_ENVIRONMENT_NAME = /(AUTH|CREDENTIAL|KEY|SECRET|TOKEN)/i;
|
|
13645
13683
|
var STARTUP_INPUT_BYTES = 64 * 1024;
|
|
@@ -13850,7 +13888,7 @@ function requireSandboxPath(value) {
|
|
|
13850
13888
|
}
|
|
13851
13889
|
}
|
|
13852
13890
|
async function exactFile(path, executable, label) {
|
|
13853
|
-
const resolved = await
|
|
13891
|
+
const resolved = await realpath5(path);
|
|
13854
13892
|
const information = await lstat3(resolved);
|
|
13855
13893
|
if (!information.isFile() || information.isSymbolicLink() || executable && (information.mode & 73) === 0) {
|
|
13856
13894
|
throw new Error(`${label} is unavailable`);
|
|
@@ -14111,7 +14149,7 @@ async function nativeBubblewrapFor(executablePath) {
|
|
|
14111
14149
|
return path;
|
|
14112
14150
|
}
|
|
14113
14151
|
async function ordinaryFile(path, label) {
|
|
14114
|
-
const exact = await
|
|
14152
|
+
const exact = await realpath6(path);
|
|
14115
14153
|
const information = await lstat4(exact);
|
|
14116
14154
|
if (!information.isFile() || information.isSymbolicLink()) {
|
|
14117
14155
|
throw new Error(`${label} is invalid`);
|
|
@@ -14166,7 +14204,7 @@ function requireSubscriptionCredential(value) {
|
|
|
14166
14204
|
return bytes;
|
|
14167
14205
|
}
|
|
14168
14206
|
async function exactFile2(path, label) {
|
|
14169
|
-
const exact = await
|
|
14207
|
+
const exact = await realpath6(path);
|
|
14170
14208
|
const information = await lstat4(exact);
|
|
14171
14209
|
if (exact !== path || !information.isFile() || information.isSymbolicLink()) {
|
|
14172
14210
|
throw new Error(`${label} is invalid`);
|
|
@@ -14223,7 +14261,7 @@ function requireBaseURL(value) {
|
|
|
14223
14261
|
}
|
|
14224
14262
|
|
|
14225
14263
|
// src/internal/claude-agent-provider.ts
|
|
14226
|
-
import { lstat as lstat5, realpath as
|
|
14264
|
+
import { lstat as lstat5, realpath as realpath7 } from "fs/promises";
|
|
14227
14265
|
import { dirname as dirname3, join as join5 } from "path";
|
|
14228
14266
|
var CLAUDE_CLIENT = "anthropic-claude-code";
|
|
14229
14267
|
var DEFAULT_MODEL = "default";
|
|
@@ -14232,7 +14270,6 @@ var SANDBOX_ADAPTER_PATH2 = "/agent/claude-agent-acp.js";
|
|
|
14232
14270
|
var SANDBOX_EXECUTABLE_PATH2 = "/agent/claude";
|
|
14233
14271
|
var HOST_CERTIFICATES_PATH2 = "/etc/ssl/certs/ca-certificates.crt";
|
|
14234
14272
|
var SANDBOX_CERTIFICATES_PATH2 = "/etc/ssl/certs/ca-certificates.crt";
|
|
14235
|
-
var HOST_ELF_INTERPRETER_PATH = "/lib64/ld-linux-x86-64.so.2";
|
|
14236
14273
|
var SANDBOX_RUNTIME_LIBRARY_PATH = "/jig-runtime/lib/librt.so.1";
|
|
14237
14274
|
var MAX_TOKEN_BYTES = 16 * 1024;
|
|
14238
14275
|
var MAX_BASE_URL_CHARACTERS3 = 4096;
|
|
@@ -14248,7 +14285,7 @@ async function openPrivateClaudeAgentProvider(releaseRoot, environment = process
|
|
|
14248
14285
|
adapterPath: join5(releaseRoot, "libexec", "agent", "claude-agent-acp.js"),
|
|
14249
14286
|
executablePath,
|
|
14250
14287
|
certificatesPath: await ordinaryFile2(HOST_CERTIFICATES_PATH2, "host certificate bundle"),
|
|
14251
|
-
runtimeLibraryPath: await ordinaryFile2(join5(dirname3(await
|
|
14288
|
+
runtimeLibraryPath: await ordinaryFile2(join5(dirname3(await resolvePrivateLinuxHostLoader()), "librt.so.1"), "Claude runtime library")
|
|
14252
14289
|
});
|
|
14253
14290
|
const apiKey = environment.ANTHROPIC_API_KEY;
|
|
14254
14291
|
const authToken = environment.ANTHROPIC_AUTH_TOKEN;
|
|
@@ -14408,7 +14445,7 @@ function frameStartupInput2(value) {
|
|
|
14408
14445
|
return framed;
|
|
14409
14446
|
}
|
|
14410
14447
|
async function ordinaryFile2(path, label) {
|
|
14411
|
-
const exact = await
|
|
14448
|
+
const exact = await realpath7(path);
|
|
14412
14449
|
const information = await lstat5(exact);
|
|
14413
14450
|
if (!information.isFile() || information.isSymbolicLink()) {
|
|
14414
14451
|
throw new Error(`${label} is invalid`);
|
|
@@ -14418,7 +14455,7 @@ async function ordinaryFile2(path, label) {
|
|
|
14418
14455
|
|
|
14419
14456
|
// src/internal/pi-agent-provider.ts
|
|
14420
14457
|
import { constants as constants4 } from "fs";
|
|
14421
|
-
import { access as access4, lstat as lstat6, readFile as readFile4, realpath as
|
|
14458
|
+
import { access as access4, lstat as lstat6, readFile as readFile4, realpath as realpath8 } from "fs/promises";
|
|
14422
14459
|
import { homedir as homedir2 } from "os";
|
|
14423
14460
|
import { dirname as dirname4, join as join6, resolve as resolve2 } from "path";
|
|
14424
14461
|
var PI_CLIENT = "pi";
|
|
@@ -14721,7 +14758,7 @@ async function executableFile(path, label) {
|
|
|
14721
14758
|
return exact;
|
|
14722
14759
|
}
|
|
14723
14760
|
async function ordinaryFile3(path, label) {
|
|
14724
|
-
const exact = await
|
|
14761
|
+
const exact = await realpath8(path);
|
|
14725
14762
|
const information = await lstat6(exact);
|
|
14726
14763
|
if (!information.isFile() || information.isSymbolicLink()) {
|
|
14727
14764
|
throw new Error(`${label} is invalid`);
|
|
@@ -14742,7 +14779,7 @@ async function piManifestFile(path) {
|
|
|
14742
14779
|
return exact;
|
|
14743
14780
|
}
|
|
14744
14781
|
async function readCredentialFile(path) {
|
|
14745
|
-
const exact = await
|
|
14782
|
+
const exact = await realpath8(path);
|
|
14746
14783
|
const information = await lstat6(exact);
|
|
14747
14784
|
const uid = process.getuid?.();
|
|
14748
14785
|
if (!information.isFile() || information.isSymbolicLink() || information.nlink !== 1 || information.size <= 0 || information.size > MAX_CREDENTIAL_BYTES2 || uid === undefined || information.uid !== uid || (information.mode & 63) !== 0) {
|
|
@@ -14792,7 +14829,7 @@ import {
|
|
|
14792
14829
|
mkdir as mkdir3,
|
|
14793
14830
|
readFile as readFile5,
|
|
14794
14831
|
readdir as readdir3,
|
|
14795
|
-
realpath as
|
|
14832
|
+
realpath as realpath9,
|
|
14796
14833
|
stat as stat3,
|
|
14797
14834
|
statfs as statfs3,
|
|
14798
14835
|
writeFile as writeFile2
|
|
@@ -14802,14 +14839,8 @@ import { isAbsolute, posix as posix3 } from "path";
|
|
|
14802
14839
|
var CGROUP_ROOT2 = "/sys/fs/cgroup";
|
|
14803
14840
|
var CGROUP2_SUPER_MAGIC3 = 0x6367_7270n;
|
|
14804
14841
|
var CHILD_NAME = "jig";
|
|
14805
|
-
var MANAGER_CANDIDATES =
|
|
14806
|
-
|
|
14807
|
-
"/bin/systemd-run"
|
|
14808
|
-
]);
|
|
14809
|
-
var CONTROL_CANDIDATES = Object.freeze([
|
|
14810
|
-
"/usr/bin/systemctl",
|
|
14811
|
-
"/bin/systemctl"
|
|
14812
|
-
]);
|
|
14842
|
+
var MANAGER_CANDIDATES = privateLinuxHostToolCandidates("systemd-run");
|
|
14843
|
+
var CONTROL_CANDIDATES = privateLinuxHostToolCandidates("systemctl");
|
|
14813
14844
|
var REQUIRED_CONTROLLERS2 = Object.freeze(["cpu", "memory", "pids"]);
|
|
14814
14845
|
var UNIT = /^jig-[0-9a-f]{24}\.scope$/;
|
|
14815
14846
|
var TOKEN2 = /^[0-9a-f]{64}$/;
|
|
@@ -14990,7 +15021,7 @@ function requireWords2(input, expected) {
|
|
|
14990
15021
|
async function resolveManager() {
|
|
14991
15022
|
for (const candidate of MANAGER_CANDIDATES) {
|
|
14992
15023
|
try {
|
|
14993
|
-
const resolved = await
|
|
15024
|
+
const resolved = await realpath9(candidate);
|
|
14994
15025
|
const information = await stat3(resolved);
|
|
14995
15026
|
if (isAbsolute(resolved) && information.isFile() && (information.mode & 73) !== 0 && (information.mode & 3072) === 0) {
|
|
14996
15027
|
return resolved;
|
|
@@ -15114,7 +15145,7 @@ function waitForStartup(acknowledged, completion, timeoutMs) {
|
|
|
15114
15145
|
async function resolveControl() {
|
|
15115
15146
|
for (const candidate of CONTROL_CANDIDATES) {
|
|
15116
15147
|
try {
|
|
15117
|
-
const resolved = await
|
|
15148
|
+
const resolved = await realpath9(candidate);
|
|
15118
15149
|
const information = await stat3(resolved);
|
|
15119
15150
|
if (isAbsolute(resolved) && information.isFile() && (information.mode & 73) !== 0 && (information.mode & 3072) === 0) {
|
|
15120
15151
|
return resolved;
|
|
@@ -15197,7 +15228,7 @@ async function observeControlGroup(controlPath, unit, environment, timeoutMs) {
|
|
|
15197
15228
|
throw new Error("the user manager returned an invalid transient scope path");
|
|
15198
15229
|
}
|
|
15199
15230
|
const path = `${CGROUP_ROOT2}${relative}`;
|
|
15200
|
-
if (await
|
|
15231
|
+
if (await realpath9(path) !== path)
|
|
15201
15232
|
throw new Error("the transient scope path is not canonical");
|
|
15202
15233
|
return path;
|
|
15203
15234
|
}
|
|
@@ -15419,7 +15450,7 @@ var scopeDependencies = Object.freeze({
|
|
|
15419
15450
|
listDirectories: async (path) => (await readdir3(path, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name),
|
|
15420
15451
|
information: (path) => stat3(path),
|
|
15421
15452
|
filesystemType: async (path) => (await statfs3(path)).type,
|
|
15422
|
-
resolve: (path) =>
|
|
15453
|
+
resolve: (path) => realpath9(path),
|
|
15423
15454
|
requireAccess: (path, mode) => access5(path, mode),
|
|
15424
15455
|
makeDirectory: (path) => mkdir3(path, { mode: 493 }),
|
|
15425
15456
|
writeText: (path, value) => writeFile2(path, value)
|
|
@@ -17878,9 +17909,10 @@ function linkPackageProject(input, maximumActivationTargets) {
|
|
|
17878
17909
|
if (maximumActivationTargets !== undefined && activationTargetCount > maximumActivationTargets) {
|
|
17879
17910
|
invalid("PROJECT_ACTIVATION_TARGET_LIMIT", `project contains ${activationTargetCount} activation targets, exceeding the caller bound ${maximumActivationTargets}`);
|
|
17880
17911
|
}
|
|
17912
|
+
const bindingById = new Map(preparedBindings.map((binding) => [binding.id, binding]));
|
|
17881
17913
|
const value = Object.freeze({
|
|
17882
17914
|
flows: Object.freeze(flows.map((flow) => flow.value)),
|
|
17883
|
-
bindings: Object.freeze(preparedBindings.map(linkBinding))
|
|
17915
|
+
bindings: Object.freeze(preparedBindings.map((binding) => linkBinding(binding, flowByPath, bindingById)))
|
|
17884
17916
|
});
|
|
17885
17917
|
authenticPackageProjects.add(value);
|
|
17886
17918
|
return value;
|
|
@@ -17987,14 +18019,13 @@ function prepareBindings(values, flowByPath, budget) {
|
|
|
17987
18019
|
invalid("PROJECT_BINDING_ATTACHMENTS_UNSUPPORTED", `Binding ${id} selects a package that requires attachments, which the direct alpha does not project`, declarationPath, "/package");
|
|
17988
18020
|
}
|
|
17989
18021
|
validateSettings(definition.settings, flow.inspected, declarationPath);
|
|
17990
|
-
validateFlowSlots(id, definition.package, definition.slots, flowByPath, declarationPath);
|
|
17991
18022
|
return Object.freeze({ id, declarationPath, definition, flow });
|
|
17992
18023
|
});
|
|
17993
18024
|
bindings.sort((left, right) => compareProjectPaths(left.id, right.id));
|
|
17994
18025
|
assertUniqueBindings(bindings);
|
|
17995
18026
|
return Object.freeze(bindings);
|
|
17996
18027
|
}
|
|
17997
|
-
function linkBinding(prepared) {
|
|
18028
|
+
function linkBinding(prepared, flowByPath, bindingById) {
|
|
17998
18029
|
const { id, declarationPath, definition } = prepared;
|
|
17999
18030
|
return Object.freeze({
|
|
18000
18031
|
kind: "package",
|
|
@@ -18002,23 +18033,32 @@ function linkBinding(prepared) {
|
|
|
18002
18033
|
declarationPath,
|
|
18003
18034
|
packagePath: definition.package,
|
|
18004
18035
|
settings: definition.settings,
|
|
18005
|
-
slots:
|
|
18036
|
+
slots: linkFlowSlots(prepared, flowByPath, bindingById)
|
|
18006
18037
|
});
|
|
18007
18038
|
}
|
|
18008
|
-
function
|
|
18009
|
-
|
|
18039
|
+
function linkFlowSlots(binding, flowByPath, bindingById) {
|
|
18040
|
+
const { id: bindingId, declarationPath, definition } = binding;
|
|
18041
|
+
const slots = Object.create(null);
|
|
18042
|
+
for (const [name, selector] of Object.entries(definition.slots)) {
|
|
18010
18043
|
const pointer = `/slots/${pointerToken(name)}`;
|
|
18011
|
-
const
|
|
18044
|
+
const identity2 = parseRunTargetSelector(selector, `slot ${name}`);
|
|
18045
|
+
const childBinding = identity2.kind === "binding" ? bindingById.get(identity2.id) : undefined;
|
|
18046
|
+
const target = identity2.kind === "flow" ? flowByPath.get(identity2.path) : childBinding?.flow;
|
|
18012
18047
|
if (target === undefined) {
|
|
18013
|
-
invalid("PROJECT_BINDING_SLOT_MISSING", `Binding ${bindingId} slot ${name} selects unknown
|
|
18048
|
+
invalid("PROJECT_BINDING_SLOT_MISSING", `Binding ${bindingId} slot ${name} selects unknown target ${selector}`, declarationPath, pointer);
|
|
18014
18049
|
}
|
|
18015
|
-
if (
|
|
18050
|
+
if (target.value.provenance.projectPath === definition.package) {
|
|
18016
18051
|
invalid("PROJECT_BINDING_SLOT_RECURSIVE", `Binding ${bindingId} slot ${name} selects its own Flow package`, declarationPath, pointer);
|
|
18017
18052
|
}
|
|
18018
|
-
if (
|
|
18019
|
-
invalid("PROJECT_BINDING_SLOT_NOT_DIRECT", `Binding ${bindingId} slot ${name} must select a
|
|
18053
|
+
if (identity2.kind === "flow" && !target.value.directRun) {
|
|
18054
|
+
invalid("PROJECT_BINDING_SLOT_NOT_DIRECT", `Binding ${bindingId} slot ${name} must select a direct Flow target or configured Binding`, declarationPath, pointer);
|
|
18055
|
+
}
|
|
18056
|
+
if (childBinding !== undefined && Object.keys(childBinding.definition.slots).length !== 0) {
|
|
18057
|
+
invalid("PROJECT_BINDING_SLOT_NOT_LEAF", `Binding ${bindingId} slot ${name} selects a Binding with child slots`, declarationPath, pointer);
|
|
18020
18058
|
}
|
|
18059
|
+
slots[name] = identity2;
|
|
18021
18060
|
}
|
|
18061
|
+
return Object.freeze(slots);
|
|
18022
18062
|
}
|
|
18023
18063
|
function pointerToken(value) {
|
|
18024
18064
|
return value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
@@ -19963,7 +20003,20 @@ function normalizeRequestFlowSlots(value) {
|
|
|
19963
20003
|
const output = Object.create(null);
|
|
19964
20004
|
for (const name of Object.keys(input).sort()) {
|
|
19965
20005
|
requireLocalName3(name, "activation Flow slot");
|
|
19966
|
-
|
|
20006
|
+
const target = exactRecord4(input[name], `activation Flow slot ${name}`);
|
|
20007
|
+
if (target.kind === "flow") {
|
|
20008
|
+
output[name] = Object.freeze({
|
|
20009
|
+
kind: "flow",
|
|
20010
|
+
path: normalizeProjectPath(exactObject(target, ["kind", "path"], `activation Flow slot ${name}`).path, `activation Flow slot ${name}`)
|
|
20011
|
+
});
|
|
20012
|
+
} else if (target.kind === "binding") {
|
|
20013
|
+
output[name] = Object.freeze({
|
|
20014
|
+
kind: "binding",
|
|
20015
|
+
id: requireLocalName3(exactObject(target, ["kind", "id"], `activation Binding slot ${name}`).id, `activation Binding slot ${name}`)
|
|
20016
|
+
});
|
|
20017
|
+
} else {
|
|
20018
|
+
throw new TypeError(`activation Flow slot ${name} must select a Flow or Binding target`);
|
|
20019
|
+
}
|
|
19967
20020
|
}
|
|
19968
20021
|
return Object.freeze(output);
|
|
19969
20022
|
}
|
|
@@ -20152,7 +20205,12 @@ function validateReferences(packages, bindings) {
|
|
|
20152
20205
|
const selected = packages[binding.packagePath];
|
|
20153
20206
|
if (selected === undefined)
|
|
20154
20207
|
throw new TypeError(`Binding ${id} selects an unknown package`);
|
|
20155
|
-
for (const [name,
|
|
20208
|
+
for (const [name, identity2] of Object.entries(binding.slots)) {
|
|
20209
|
+
const childBinding = identity2.kind === "binding" ? bindings[identity2.id] : undefined;
|
|
20210
|
+
const path = identity2.kind === "flow" ? identity2.path : childBinding?.packagePath;
|
|
20211
|
+
if (path === undefined) {
|
|
20212
|
+
throw new TypeError(`Binding ${id} slot ${name} selects an unknown Binding`);
|
|
20213
|
+
}
|
|
20156
20214
|
const target = packages[path];
|
|
20157
20215
|
if (target === undefined) {
|
|
20158
20216
|
throw new TypeError(`Binding ${id} slot ${name} selects an unknown package`);
|
|
@@ -20160,8 +20218,11 @@ function validateReferences(packages, bindings) {
|
|
|
20160
20218
|
if (path === binding.packagePath) {
|
|
20161
20219
|
throw new TypeError(`Binding ${id} slot ${name} selects its own package`);
|
|
20162
20220
|
}
|
|
20163
|
-
if (
|
|
20164
|
-
throw new TypeError(`Binding ${id} slot ${name} must select a
|
|
20221
|
+
if (identity2.kind === "flow" && !target.directRun) {
|
|
20222
|
+
throw new TypeError(`Binding ${id} slot ${name} must select a direct Run package or configured Binding`);
|
|
20223
|
+
}
|
|
20224
|
+
if (childBinding !== undefined && Object.keys(childBinding.slots).length !== 0) {
|
|
20225
|
+
throw new TypeError(`Binding ${id} slot ${name} selects a Binding with child slots`);
|
|
20165
20226
|
}
|
|
20166
20227
|
}
|
|
20167
20228
|
}
|
|
@@ -20174,7 +20235,20 @@ function normalizeSlots(value, label) {
|
|
|
20174
20235
|
const output = Object.create(null);
|
|
20175
20236
|
for (const name of names.sort()) {
|
|
20176
20237
|
localName(name, `${label} slot`);
|
|
20177
|
-
|
|
20238
|
+
const target = object(input[name], `${label} slot ${name}`);
|
|
20239
|
+
if (target.kind === "flow") {
|
|
20240
|
+
output[name] = Object.freeze({
|
|
20241
|
+
kind: "flow",
|
|
20242
|
+
path: projectPath(exactObject2(target, ["kind", "path"], `${label} slot ${name}`).path, `${label} slot ${name}`)
|
|
20243
|
+
});
|
|
20244
|
+
} else if (target.kind === "binding") {
|
|
20245
|
+
output[name] = Object.freeze({
|
|
20246
|
+
kind: "binding",
|
|
20247
|
+
id: localName(exactObject2(target, ["kind", "id"], `${label} slot ${name}`).id, `${label} slot ${name}`)
|
|
20248
|
+
});
|
|
20249
|
+
} else {
|
|
20250
|
+
throw new TypeError(`${label} slot ${name} must select a Flow or Binding target`);
|
|
20251
|
+
}
|
|
20178
20252
|
}
|
|
20179
20253
|
return Object.freeze(output);
|
|
20180
20254
|
}
|
|
@@ -20280,6 +20354,9 @@ async function planPrivateBunDirectRun(input) {
|
|
|
20280
20354
|
}
|
|
20281
20355
|
}
|
|
20282
20356
|
const capabilityUses = Object.values(request.capabilities);
|
|
20357
|
+
if (capabilityUses.length > 0 && input.agentProvider === undefined) {
|
|
20358
|
+
unavailable("PROJECT_AGENT_UNAVAILABLE", "the target requires a configured host Agent", `${request.packagePath}/FLOW.md`);
|
|
20359
|
+
}
|
|
20283
20360
|
const agentProvider = capabilityUses.length === 0 ? undefined : requirePrivateAgentProvider(input.agentProvider);
|
|
20284
20361
|
if (capabilityUses.some(({ digest: digest3 }) => digest3 !== AGENT_RUN_CONTRACT_DIGEST) || capabilityUses.length > 1 || agentProvider !== undefined && agentProvider.contractDigest !== AGENT_RUN_CONTRACT_DIGEST) {
|
|
20285
20362
|
throw new TypeError("private Bun recipe requires the exact supported Agent capability");
|
|
@@ -21347,7 +21424,7 @@ var CREATE_COORDINATOR_HEAD = "CREATE TABLE coordinator_head (singleton INTEGER
|
|
|
21347
21424
|
var CREATE_ROOT_RUNS = "CREATE TABLE root_runs (run_id TEXT PRIMARY KEY, origin_digest TEXT NOT NULL UNIQUE, origin_bytes BLOB NOT NULL CHECK (length(origin_bytes) BETWEEN 1 AND 16777216), admission_digest TEXT NOT NULL REFERENCES admissions(admission_digest), candidate_revision INTEGER NOT NULL REFERENCES candidates(revision), coordinator_epoch INTEGER NOT NULL CHECK (coordinator_epoch BETWEEN 1 AND 9007199254740991), request_bytes BLOB NOT NULL CHECK (length(request_bytes) BETWEEN 1 AND 16777216)) STRICT";
|
|
21348
21425
|
var CREATE_ROOT_SPAWN_INTENTS = "CREATE TABLE root_spawn_intents (run_id TEXT PRIMARY KEY REFERENCES root_runs(run_id), intent_digest TEXT NOT NULL UNIQUE, intent_bytes BLOB NOT NULL CHECK (length(intent_bytes) BETWEEN 1 AND 16777216)) STRICT";
|
|
21349
21426
|
var CREATE_ROOT_EXECUTION_LIFECYCLES = "CREATE TABLE root_execution_lifecycles (run_id TEXT PRIMARY KEY REFERENCES root_spawn_intents(run_id), allocation_digest TEXT NOT NULL UNIQUE, allocation_bytes BLOB NOT NULL CHECK (length(allocation_bytes) BETWEEN 1 AND 16777216), plan_digest TEXT UNIQUE, plan_bytes BLOB, backing_digest TEXT UNIQUE, backing_bytes BLOB, sandbox_digest TEXT UNIQUE, sandbox_bytes BLOB, prepared_digest TEXT UNIQUE, prepared_bytes BLOB, provisional_digest TEXT UNIQUE, provisional_bytes BLOB, fence_digest TEXT UNIQUE, fence_bytes BLOB, release_digest TEXT UNIQUE, release_bytes BLOB, admitted_digest TEXT UNIQUE, admitted_bytes BLOB, CHECK ((plan_digest IS NULL) = (plan_bytes IS NULL)), CHECK ((backing_digest IS NULL) = (backing_bytes IS NULL)), CHECK ((sandbox_digest IS NULL) = (sandbox_bytes IS NULL)), CHECK ((prepared_digest IS NULL) = (prepared_bytes IS NULL)), CHECK ((provisional_digest IS NULL) = (provisional_bytes IS NULL)), CHECK ((fence_digest IS NULL) = (fence_bytes IS NULL)), CHECK ((release_digest IS NULL) = (release_bytes IS NULL)), CHECK ((admitted_digest IS NULL) = (admitted_bytes IS NULL)), CHECK (backing_digest IS NULL OR plan_digest IS NOT NULL), CHECK (sandbox_digest IS NULL OR backing_digest IS NOT NULL), CHECK (prepared_digest IS NULL OR sandbox_digest IS NOT NULL), CHECK (fence_digest IS NULL OR sandbox_digest IS NOT NULL), CHECK (admitted_digest IS NULL OR (provisional_digest IS NOT NULL AND release_digest IS NOT NULL))) STRICT";
|
|
21350
|
-
var CREATE_ROOT_CHILD_OWNERS = "CREATE TABLE root_child_owners (parent_run_id TEXT NOT NULL REFERENCES root_execution_lifecycles(run_id), operation_id TEXT NOT NULL, allocation_digest TEXT NOT NULL UNIQUE, allocation_bytes BLOB NOT NULL CHECK (length(allocation_bytes) BETWEEN 1 AND 16777216), sandbox_digest TEXT UNIQUE, sandbox_bytes BLOB, fence_digest TEXT UNIQUE, fence_bytes BLOB, cleanup_digest TEXT UNIQUE, cleanup_bytes BLOB, CHECK ((sandbox_digest IS NULL) = (sandbox_bytes IS NULL)), CHECK ((fence_digest IS NULL) = (fence_bytes IS NULL)), CHECK ((cleanup_digest IS NULL) = (cleanup_bytes IS NULL)), CHECK (fence_digest IS NULL OR sandbox_digest IS NOT NULL), CHECK (cleanup_digest IS NULL OR fence_digest IS NOT NULL), PRIMARY KEY (parent_run_id, operation_id)) STRICT";
|
|
21427
|
+
var CREATE_ROOT_CHILD_OWNERS = "CREATE TABLE root_child_owners (parent_run_id TEXT NOT NULL REFERENCES root_execution_lifecycles(run_id), scope_operation_id TEXT NOT NULL, operation_id TEXT NOT NULL, allocation_digest TEXT NOT NULL UNIQUE, allocation_bytes BLOB NOT NULL CHECK (length(allocation_bytes) BETWEEN 1 AND 16777216), sandbox_digest TEXT UNIQUE, sandbox_bytes BLOB, fence_digest TEXT UNIQUE, fence_bytes BLOB, cleanup_digest TEXT UNIQUE, cleanup_bytes BLOB, CHECK ((sandbox_digest IS NULL) = (sandbox_bytes IS NULL)), CHECK ((fence_digest IS NULL) = (fence_bytes IS NULL)), CHECK ((cleanup_digest IS NULL) = (cleanup_bytes IS NULL)), CHECK (fence_digest IS NULL OR sandbox_digest IS NOT NULL), CHECK (cleanup_digest IS NULL OR fence_digest IS NOT NULL), PRIMARY KEY (parent_run_id, scope_operation_id, operation_id)) STRICT";
|
|
21351
21428
|
var CREATE_ROOT_TERMINALS = "CREATE TABLE root_terminals (run_id TEXT PRIMARY KEY REFERENCES root_runs(run_id), terminal_digest TEXT NOT NULL, terminal_bytes BLOB NOT NULL CHECK (length(terminal_bytes) BETWEEN 1 AND 16777216)) STRICT";
|
|
21352
21429
|
var CREATE_COORDINATOR_LOCK = "CREATE TABLE coordinator_lock (singleton INTEGER PRIMARY KEY CHECK (singleton = 1)) STRICT";
|
|
21353
21430
|
var EXPECTED_SCHEMA = Object.freeze([
|
|
@@ -21777,6 +21854,8 @@ async function allocatePrivateRootChildOwner(input) {
|
|
|
21777
21854
|
await coordinator.verify();
|
|
21778
21855
|
requireDigest4(input.parentRunId, "parent root Run");
|
|
21779
21856
|
requireWireId(input.operationId, "child operation");
|
|
21857
|
+
if (input.parentOperationId !== undefined)
|
|
21858
|
+
requireWireId(input.parentOperationId, "parent child operation");
|
|
21780
21859
|
const bytes = canonicalJson(input.allocation);
|
|
21781
21860
|
requireStoredSize(bytes, "child owner allocation");
|
|
21782
21861
|
const digest4 = privateDomainDigest("JIG-Private-Root-Child-Owner-Allocation/1", input.allocation);
|
|
@@ -21793,7 +21872,7 @@ async function allocatePrivateRootChildOwner(input) {
|
|
|
21793
21872
|
if (run.coordinatorEpoch !== coordinator.epoch) {
|
|
21794
21873
|
invalid("RUN_OWNER_CHANGED", "only the active parent coordinator may allocate child work");
|
|
21795
21874
|
}
|
|
21796
|
-
const existing = findRootChildOwner(owner.database, input.parentRunId, input.operationId);
|
|
21875
|
+
const existing = findRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId);
|
|
21797
21876
|
if (existing !== null) {
|
|
21798
21877
|
const loaded = loadRootChildOwner(existing);
|
|
21799
21878
|
if (loaded.allocation.digest !== digest4 || !sameBytes4(existing.allocation_bytes, bytes)) {
|
|
@@ -21801,11 +21880,15 @@ async function allocatePrivateRootChildOwner(input) {
|
|
|
21801
21880
|
}
|
|
21802
21881
|
return loaded;
|
|
21803
21882
|
}
|
|
21804
|
-
|
|
21883
|
+
requireActiveChildScope(owner.database, input.parentRunId, input.parentOperationId);
|
|
21884
|
+
if (input.parentOperationId !== undefined && (input.allocation === null || typeof input.allocation !== "object" || Array.isArray(input.allocation) || input.allocation.kind !== "private-root-agent-owner-allocation/1")) {
|
|
21885
|
+
invalid("RUN_CHILD_OWNER_CONFLICT", "a child Flow may own only one Agent operation");
|
|
21886
|
+
}
|
|
21887
|
+
if (countScopedRootChildOwners(owner.database, input.parentRunId, input.parentOperationId) !== 0n) {
|
|
21805
21888
|
invalid("RUN_CHILD_CAPACITY", "the parent Run already has an active child operation");
|
|
21806
21889
|
}
|
|
21807
|
-
runFinalized(owner.database, "INSERT INTO root_child_owners(parent_run_id, operation_id, allocation_digest, allocation_bytes) VALUES (?1, ?2, ?3, ?4)", [input.parentRunId, input.operationId, digest4, bytes]);
|
|
21808
|
-
return loadRootChildOwner(requireRootChildOwner(owner.database, input.parentRunId, input.operationId));
|
|
21890
|
+
runFinalized(owner.database, "INSERT INTO root_child_owners(parent_run_id, scope_operation_id, operation_id, allocation_digest, allocation_bytes) VALUES (?1, ?2, ?3, ?4, ?5)", [input.parentRunId, input.parentOperationId ?? "", input.operationId, digest4, bytes]);
|
|
21891
|
+
return loadRootChildOwner(requireRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId));
|
|
21809
21892
|
});
|
|
21810
21893
|
await owner.finish();
|
|
21811
21894
|
return lifecycle;
|
|
@@ -21821,6 +21904,8 @@ async function recordPrivateRootChildSandbox(input) {
|
|
|
21821
21904
|
await coordinator.verify();
|
|
21822
21905
|
requireDigest4(input.parentRunId, "parent root Run");
|
|
21823
21906
|
requireWireId(input.operationId, "child operation");
|
|
21907
|
+
if (input.parentOperationId !== undefined)
|
|
21908
|
+
requireWireId(input.parentOperationId, "parent child operation");
|
|
21824
21909
|
requireDigest4(input.allocationDigest, "child allocation");
|
|
21825
21910
|
const bytes = canonicalJson(input.sandbox);
|
|
21826
21911
|
requireStoredSize(bytes, "child sandbox owner");
|
|
@@ -21831,7 +21916,7 @@ async function recordPrivateRootChildSandbox(input) {
|
|
|
21831
21916
|
requireCoordinatorRoot(coordinator, owner.root);
|
|
21832
21917
|
const lifecycle = await immediate(owner, async () => {
|
|
21833
21918
|
await coordinator.verify();
|
|
21834
|
-
const row = requireRootChildOwner(owner.database, input.parentRunId, input.operationId);
|
|
21919
|
+
const row = requireRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId);
|
|
21835
21920
|
if (row.allocation_digest !== input.allocationDigest) {
|
|
21836
21921
|
invalid("RUN_CHILD_OWNER_CONFLICT", "child sandbox names a different allocation");
|
|
21837
21922
|
}
|
|
@@ -21848,10 +21933,11 @@ async function recordPrivateRootChildSandbox(input) {
|
|
|
21848
21933
|
if (run.coordinatorEpoch !== coordinator.epoch) {
|
|
21849
21934
|
invalid("RUN_OWNER_CHANGED", "only the active parent coordinator may seal child work");
|
|
21850
21935
|
}
|
|
21851
|
-
|
|
21936
|
+
requireActiveChildScope(owner.database, input.parentRunId, input.parentOperationId);
|
|
21937
|
+
const changed = runFinalized(owner.database, "UPDATE root_child_owners SET sandbox_digest = ?1, sandbox_bytes = ?2 WHERE parent_run_id = ?3 AND operation_id = ?4 AND scope_operation_id = ?5 AND sandbox_digest IS NULL", [digest4, bytes, input.parentRunId, input.operationId, input.parentOperationId ?? ""]).changes;
|
|
21852
21938
|
if (changed !== 1)
|
|
21853
21939
|
corrupt("child sandbox owner compare-and-set failed");
|
|
21854
|
-
return loadRootChildOwner(requireRootChildOwner(owner.database, input.parentRunId, input.operationId));
|
|
21940
|
+
return loadRootChildOwner(requireRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId));
|
|
21855
21941
|
});
|
|
21856
21942
|
await owner.finish();
|
|
21857
21943
|
return lifecycle;
|
|
@@ -21867,6 +21953,8 @@ async function recordPrivateRootChildFence(input) {
|
|
|
21867
21953
|
await coordinator.verify();
|
|
21868
21954
|
requireDigest4(input.parentRunId, "parent root Run");
|
|
21869
21955
|
requireWireId(input.operationId, "child operation");
|
|
21956
|
+
if (input.parentOperationId !== undefined)
|
|
21957
|
+
requireWireId(input.parentOperationId, "parent child operation");
|
|
21870
21958
|
requireDigest4(input.allocationDigest, "child allocation");
|
|
21871
21959
|
requireDigest4(input.sandboxDigest, "child sandbox");
|
|
21872
21960
|
const bytes = canonicalJson(input.fence);
|
|
@@ -21878,7 +21966,7 @@ async function recordPrivateRootChildFence(input) {
|
|
|
21878
21966
|
requireCoordinatorRoot(coordinator, owner.root);
|
|
21879
21967
|
const lifecycle = await immediate(owner, async () => {
|
|
21880
21968
|
await coordinator.verify();
|
|
21881
|
-
const row = requireRootChildOwner(owner.database, input.parentRunId, input.operationId);
|
|
21969
|
+
const row = requireRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId);
|
|
21882
21970
|
if (row.allocation_digest !== input.allocationDigest || row.sandbox_digest !== input.sandboxDigest) {
|
|
21883
21971
|
invalid("RUN_CHILD_OWNER_CONFLICT", "child fence names a different owner");
|
|
21884
21972
|
}
|
|
@@ -21888,10 +21976,10 @@ async function recordPrivateRootChildFence(input) {
|
|
|
21888
21976
|
}
|
|
21889
21977
|
return loadRootChildOwner(row);
|
|
21890
21978
|
}
|
|
21891
|
-
const changed = runFinalized(owner.database, "UPDATE root_child_owners SET fence_digest = ?1, fence_bytes = ?2 WHERE parent_run_id = ?3 AND operation_id = ?4 AND fence_digest IS NULL", [digest4, bytes, input.parentRunId, input.operationId]).changes;
|
|
21979
|
+
const changed = runFinalized(owner.database, "UPDATE root_child_owners SET fence_digest = ?1, fence_bytes = ?2 WHERE parent_run_id = ?3 AND operation_id = ?4 AND scope_operation_id = ?5 AND fence_digest IS NULL", [digest4, bytes, input.parentRunId, input.operationId, input.parentOperationId ?? ""]).changes;
|
|
21892
21980
|
if (changed !== 1)
|
|
21893
21981
|
corrupt("child fence compare-and-set failed");
|
|
21894
|
-
return loadRootChildOwner(requireRootChildOwner(owner.database, input.parentRunId, input.operationId));
|
|
21982
|
+
return loadRootChildOwner(requireRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId));
|
|
21895
21983
|
});
|
|
21896
21984
|
await owner.finish();
|
|
21897
21985
|
return lifecycle;
|
|
@@ -21907,6 +21995,8 @@ async function recordPrivateRootChildCleanup(input) {
|
|
|
21907
21995
|
await coordinator.verify();
|
|
21908
21996
|
requireDigest4(input.parentRunId, "parent root Run");
|
|
21909
21997
|
requireWireId(input.operationId, "child operation");
|
|
21998
|
+
if (input.parentOperationId !== undefined)
|
|
21999
|
+
requireWireId(input.parentOperationId, "parent child operation");
|
|
21910
22000
|
requireDigest4(input.allocationDigest, "child allocation");
|
|
21911
22001
|
requireDigest4(input.sandboxDigest, "child sandbox");
|
|
21912
22002
|
requireDigest4(input.fenceDigest, "child fence");
|
|
@@ -21919,7 +22009,7 @@ async function recordPrivateRootChildCleanup(input) {
|
|
|
21919
22009
|
requireCoordinatorRoot(coordinator, owner.root);
|
|
21920
22010
|
const lifecycle = await immediate(owner, async () => {
|
|
21921
22011
|
await coordinator.verify();
|
|
21922
|
-
const row = requireRootChildOwner(owner.database, input.parentRunId, input.operationId);
|
|
22012
|
+
const row = requireRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId);
|
|
21923
22013
|
if (row.allocation_digest !== input.allocationDigest || row.sandbox_digest !== input.sandboxDigest || row.fence_digest !== input.fenceDigest) {
|
|
21924
22014
|
invalid("RUN_CHILD_OWNER_CONFLICT", "child cleanup names different durable evidence");
|
|
21925
22015
|
}
|
|
@@ -21929,10 +22019,10 @@ async function recordPrivateRootChildCleanup(input) {
|
|
|
21929
22019
|
}
|
|
21930
22020
|
return loadRootChildOwner(row);
|
|
21931
22021
|
}
|
|
21932
|
-
const changed = runFinalized(owner.database, "UPDATE root_child_owners SET cleanup_digest = ?1, cleanup_bytes = ?2 WHERE parent_run_id = ?3 AND operation_id = ?4 AND cleanup_digest IS NULL", [digest4, bytes, input.parentRunId, input.operationId]).changes;
|
|
22022
|
+
const changed = runFinalized(owner.database, "UPDATE root_child_owners SET cleanup_digest = ?1, cleanup_bytes = ?2 WHERE parent_run_id = ?3 AND operation_id = ?4 AND scope_operation_id = ?5 AND cleanup_digest IS NULL", [digest4, bytes, input.parentRunId, input.operationId, input.parentOperationId ?? ""]).changes;
|
|
21933
22023
|
if (changed !== 1)
|
|
21934
22024
|
corrupt("child cleanup compare-and-set failed");
|
|
21935
|
-
return loadRootChildOwner(requireRootChildOwner(owner.database, input.parentRunId, input.operationId));
|
|
22025
|
+
return loadRootChildOwner(requireRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId));
|
|
21936
22026
|
});
|
|
21937
22027
|
await owner.finish();
|
|
21938
22028
|
return lifecycle;
|
|
@@ -21952,8 +22042,8 @@ async function listPrivateRootChildOwners(input) {
|
|
|
21952
22042
|
try {
|
|
21953
22043
|
requireCoordinatorRoot(coordinator, owner.root);
|
|
21954
22044
|
const query = statement(owner.database, [
|
|
21955
|
-
"SELECT parent_run_id, operation_id, allocation_digest, allocation_bytes, sandbox_digest, sandbox_bytes, fence_digest, fence_bytes, cleanup_digest, cleanup_bytes",
|
|
21956
|
-
"FROM root_child_owners WHERE parent_run_id = ?1 ORDER BY operation_id"
|
|
22045
|
+
"SELECT parent_run_id, scope_operation_id, operation_id, allocation_digest, allocation_bytes, sandbox_digest, sandbox_bytes, fence_digest, fence_bytes, cleanup_digest, cleanup_bytes",
|
|
22046
|
+
"FROM root_child_owners WHERE parent_run_id = ?1 ORDER BY scope_operation_id DESC, operation_id"
|
|
21957
22047
|
].join(" "));
|
|
21958
22048
|
let rows;
|
|
21959
22049
|
try {
|
|
@@ -21976,6 +22066,8 @@ async function closePrivateRootChildOwner(input) {
|
|
|
21976
22066
|
await coordinator.verify();
|
|
21977
22067
|
requireDigest4(input.parentRunId, "parent root Run");
|
|
21978
22068
|
requireWireId(input.operationId, "child operation");
|
|
22069
|
+
if (input.parentOperationId !== undefined)
|
|
22070
|
+
requireWireId(input.parentOperationId, "parent child operation");
|
|
21979
22071
|
requireDigest4(input.allocationDigest, "child allocation");
|
|
21980
22072
|
if (input.sandboxDigest !== null)
|
|
21981
22073
|
requireDigest4(input.sandboxDigest, "child sandbox");
|
|
@@ -21989,13 +22081,16 @@ async function closePrivateRootChildOwner(input) {
|
|
|
21989
22081
|
requireCoordinatorRoot(coordinator, owner.root);
|
|
21990
22082
|
await immediate(owner, async () => {
|
|
21991
22083
|
await coordinator.verify();
|
|
21992
|
-
const row = findRootChildOwner(owner.database, input.parentRunId, input.operationId);
|
|
22084
|
+
const row = findRootChildOwner(owner.database, input.parentRunId, input.operationId, input.parentOperationId);
|
|
22085
|
+
if (input.parentOperationId === undefined && countScopedRootChildOwners(owner.database, input.parentRunId, input.operationId) !== 0n) {
|
|
22086
|
+
invalid("RUN_EXECUTION_INCOMPLETE", "child Flow still has an active Agent owner");
|
|
22087
|
+
}
|
|
21993
22088
|
if (row === null)
|
|
21994
22089
|
return;
|
|
21995
22090
|
if (row.allocation_digest !== input.allocationDigest || row.sandbox_digest !== input.sandboxDigest || row.fence_digest !== input.fenceDigest || row.cleanup_digest !== input.cleanupDigest || row.sandbox_digest !== null && row.cleanup_digest === null) {
|
|
21996
22091
|
invalid("RUN_CHILD_OWNER_CONFLICT", "child owner close differs from durable ownership");
|
|
21997
22092
|
}
|
|
21998
|
-
const changed = runFinalized(owner.database, "DELETE FROM root_child_owners WHERE parent_run_id = ?1 AND operation_id = ?2 AND allocation_digest = ?3", [input.parentRunId, input.operationId, input.allocationDigest]).changes;
|
|
22093
|
+
const changed = runFinalized(owner.database, "DELETE FROM root_child_owners WHERE parent_run_id = ?1 AND operation_id = ?2 AND allocation_digest = ?3 AND scope_operation_id = ?4", [input.parentRunId, input.operationId, input.allocationDigest, input.parentOperationId ?? ""]).changes;
|
|
21999
22094
|
if (changed !== 1)
|
|
22000
22095
|
corrupt("child owner close compare-and-delete failed");
|
|
22001
22096
|
});
|
|
@@ -22154,6 +22249,29 @@ function countRootChildOwners(database, parentRunId) {
|
|
|
22154
22249
|
query.finalize();
|
|
22155
22250
|
}
|
|
22156
22251
|
}
|
|
22252
|
+
function countScopedRootChildOwners(database, parentRunId, parentOperationId) {
|
|
22253
|
+
const query = statement(database, "SELECT count(*) AS count FROM root_child_owners WHERE parent_run_id = ?1 AND scope_operation_id = ?2");
|
|
22254
|
+
try {
|
|
22255
|
+
return query.get(parentRunId, parentOperationId ?? "")?.count ?? 0n;
|
|
22256
|
+
} finally {
|
|
22257
|
+
query.finalize();
|
|
22258
|
+
}
|
|
22259
|
+
}
|
|
22260
|
+
function requireActiveChildScope(database, parentRunId, parentOperationId) {
|
|
22261
|
+
if (requireRootExecutionLifecycle(database, parentRunId).fence_digest !== null) {
|
|
22262
|
+
invalid("RUN_CHILD_PARENT_INACTIVE", "the parent root Run is fenced");
|
|
22263
|
+
}
|
|
22264
|
+
if (parentOperationId === undefined)
|
|
22265
|
+
return;
|
|
22266
|
+
const parent = findRootChildOwner(database, parentRunId, parentOperationId);
|
|
22267
|
+
if (parent === null || parent.sandbox_digest === null || parent.fence_digest !== null) {
|
|
22268
|
+
invalid("RUN_CHILD_PARENT_INACTIVE", "the parent child Flow has no active sandbox");
|
|
22269
|
+
}
|
|
22270
|
+
const allocation = loadRootChildOwner(parent).allocation.value;
|
|
22271
|
+
if (allocation === null || typeof allocation !== "object" || Array.isArray(allocation) || allocation.kind !== "private-root-child-owner-allocation/1") {
|
|
22272
|
+
invalid("RUN_CHILD_PARENT_INACTIVE", "only a direct child Flow may own an Agent");
|
|
22273
|
+
}
|
|
22274
|
+
}
|
|
22157
22275
|
async function loadPrivateRootRunForCoordinator(input) {
|
|
22158
22276
|
const coordinator = requirePrivateProjectCoordinator(input.coordinator);
|
|
22159
22277
|
await coordinator.verify();
|
|
@@ -22382,20 +22500,20 @@ function requireRootExecutionLifecycle(database, runId) {
|
|
|
22382
22500
|
invalid("RUN_EXECUTION_UNALLOCATED", "root Run has no durable execution allocation");
|
|
22383
22501
|
return row;
|
|
22384
22502
|
}
|
|
22385
|
-
function findRootChildOwner(database, parentRunId, operationId) {
|
|
22503
|
+
function findRootChildOwner(database, parentRunId, operationId, parentOperationId) {
|
|
22386
22504
|
const query = statement(database, [
|
|
22387
|
-
"SELECT parent_run_id, operation_id, allocation_digest, allocation_bytes, sandbox_digest, sandbox_bytes, fence_digest, fence_bytes, cleanup_digest, cleanup_bytes",
|
|
22388
|
-
"FROM root_child_owners WHERE parent_run_id = ?1 AND operation_id = ?2"
|
|
22505
|
+
"SELECT parent_run_id, scope_operation_id, operation_id, allocation_digest, allocation_bytes, sandbox_digest, sandbox_bytes, fence_digest, fence_bytes, cleanup_digest, cleanup_bytes",
|
|
22506
|
+
"FROM root_child_owners WHERE parent_run_id = ?1 AND operation_id = ?2 AND scope_operation_id = ?3"
|
|
22389
22507
|
].join(" "));
|
|
22390
22508
|
try {
|
|
22391
|
-
const row = query.get(parentRunId, operationId);
|
|
22509
|
+
const row = query.get(parentRunId, operationId, parentOperationId ?? "");
|
|
22392
22510
|
return row === null ? null : copiedRootChildOwnerRow(row);
|
|
22393
22511
|
} finally {
|
|
22394
22512
|
query.finalize();
|
|
22395
22513
|
}
|
|
22396
22514
|
}
|
|
22397
|
-
function requireRootChildOwner(database, parentRunId, operationId) {
|
|
22398
|
-
const row = findRootChildOwner(database, parentRunId, operationId);
|
|
22515
|
+
function requireRootChildOwner(database, parentRunId, operationId, parentOperationId) {
|
|
22516
|
+
const row = findRootChildOwner(database, parentRunId, operationId, parentOperationId);
|
|
22399
22517
|
if (row === null)
|
|
22400
22518
|
invalid("RUN_CHILD_OWNER_MISSING", "child operation has no durable cleanup owner");
|
|
22401
22519
|
return row;
|
|
@@ -22403,6 +22521,7 @@ function requireRootChildOwner(database, parentRunId, operationId) {
|
|
|
22403
22521
|
function copiedRootChildOwnerRow(row) {
|
|
22404
22522
|
return Object.freeze({
|
|
22405
22523
|
parent_run_id: row.parent_run_id,
|
|
22524
|
+
scope_operation_id: row.scope_operation_id,
|
|
22406
22525
|
operation_id: row.operation_id,
|
|
22407
22526
|
allocation_digest: row.allocation_digest,
|
|
22408
22527
|
allocation_bytes: copiedBlob(row.allocation_bytes, "stored child owner allocation"),
|
|
@@ -22416,6 +22535,8 @@ function copiedRootChildOwnerRow(row) {
|
|
|
22416
22535
|
}
|
|
22417
22536
|
function loadRootChildOwner(row) {
|
|
22418
22537
|
requireDigest4(row.parent_run_id, "stored child parent Run");
|
|
22538
|
+
if (row.scope_operation_id !== "")
|
|
22539
|
+
requireWireId(row.scope_operation_id, "stored child parent operation");
|
|
22419
22540
|
requireWireId(row.operation_id, "stored child operation");
|
|
22420
22541
|
requireProtectedDigest(row.allocation_digest, "stored child allocation");
|
|
22421
22542
|
const allocation = decodeCanonicalChildFact(row.allocation_bytes, row.allocation_digest, "JIG-Private-Root-Child-Owner-Allocation/1", "stored child owner allocation");
|
|
@@ -22454,6 +22575,7 @@ function loadRootChildOwner(row) {
|
|
|
22454
22575
|
}
|
|
22455
22576
|
return Object.freeze({
|
|
22456
22577
|
parentRunId: row.parent_run_id,
|
|
22578
|
+
...row.scope_operation_id === "" ? {} : { parentOperationId: row.scope_operation_id },
|
|
22457
22579
|
operationId: row.operation_id,
|
|
22458
22580
|
allocation: Object.freeze({ digest: row.allocation_digest, value: allocation }),
|
|
22459
22581
|
...sandbox === undefined ? {} : { sandbox },
|
|
@@ -24402,7 +24524,7 @@ function limit(code, message, path) {
|
|
|
24402
24524
|
}
|
|
24403
24525
|
|
|
24404
24526
|
// src/internal/bun-native-preparation.ts
|
|
24405
|
-
import { lstat as lstat14, mkdir as mkdir6, realpath as
|
|
24527
|
+
import { lstat as lstat14, mkdir as mkdir6, realpath as realpath10 } from "fs/promises";
|
|
24406
24528
|
import { join as join9 } from "path";
|
|
24407
24529
|
|
|
24408
24530
|
// src/internal/bun-native-preparation-protocol.ts
|
|
@@ -24667,7 +24789,7 @@ function normalizeCheckpoint(value) {
|
|
|
24667
24789
|
return Object.freeze({ allocation, owner, fence });
|
|
24668
24790
|
}
|
|
24669
24791
|
async function preparationOwnerParent(projectRoot) {
|
|
24670
|
-
const state = await
|
|
24792
|
+
const state = await realpath10(join9(projectRoot, ".jig"));
|
|
24671
24793
|
const parent = join9(state, "private-preparation-linux-owners");
|
|
24672
24794
|
await mkdir6(parent, { mode: 448 }).catch((error) => {
|
|
24673
24795
|
if (!hasCode4(error, "EEXIST"))
|
|
@@ -24675,7 +24797,7 @@ async function preparationOwnerParent(projectRoot) {
|
|
|
24675
24797
|
});
|
|
24676
24798
|
const information = await lstat14(parent);
|
|
24677
24799
|
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
24678
|
-
if (!information.isDirectory() || information.isSymbolicLink() || information.uid !== uid || (information.mode & 63) !== 0 || await
|
|
24800
|
+
if (!information.isDirectory() || information.isSymbolicLink() || information.uid !== uid || (information.mode & 63) !== 0 || await realpath10(parent) !== parent) {
|
|
24679
24801
|
throw new Error("private Bun preparation owner directory is not protected");
|
|
24680
24802
|
}
|
|
24681
24803
|
return parent;
|
|
@@ -24881,15 +25003,19 @@ function projectChanges(current, proposed, currentTargets, proposedTargets) {
|
|
|
24881
25003
|
function changedBindingSlotDependencies(current, proposed, currentTargets, proposedTargets) {
|
|
24882
25004
|
if (current === null)
|
|
24883
25005
|
return [];
|
|
24884
|
-
const
|
|
24885
|
-
const
|
|
25006
|
+
const currentByTarget = new Map(currentTargets.map((target) => [targetKey2(target.request.target), target]));
|
|
25007
|
+
const proposedByTarget = new Map(proposedTargets.map((target) => [targetKey2(target.request.target), target]));
|
|
24886
25008
|
const changed = [];
|
|
24887
25009
|
for (const [id, binding] of Object.entries(proposed.portablePolicy.bindings)) {
|
|
24888
25010
|
const prior = current.portablePolicy.bindings[id];
|
|
24889
25011
|
if (prior === undefined)
|
|
24890
25012
|
continue;
|
|
24891
|
-
const
|
|
24892
|
-
if ([...
|
|
25013
|
+
const keys = new Set([...Object.values(prior.slots), ...Object.values(binding.slots)].map(targetKey2));
|
|
25014
|
+
if ([...keys].some((key) => {
|
|
25015
|
+
const before = currentByTarget.get(key);
|
|
25016
|
+
const after = proposedByTarget.get(key);
|
|
25017
|
+
return JSON.stringify(before) !== JSON.stringify(after) || before !== undefined && after !== undefined && current.portablePolicy.packages[before.request.packagePath]?.digest !== proposed.portablePolicy.packages[after.request.packagePath]?.digest;
|
|
25018
|
+
}))
|
|
24893
25019
|
changed.push(id);
|
|
24894
25020
|
}
|
|
24895
25021
|
return changed.sort(compareUtf162);
|
|
@@ -25299,7 +25425,7 @@ function isProjectIdentityLoss(error) {
|
|
|
25299
25425
|
}
|
|
25300
25426
|
|
|
25301
25427
|
// src/internal/root-run-controller.ts
|
|
25302
|
-
import { lstat as lstat18, mkdir as mkdir10, realpath as
|
|
25428
|
+
import { lstat as lstat18, mkdir as mkdir10, realpath as realpath13 } from "fs/promises";
|
|
25303
25429
|
import { join as join13 } from "path";
|
|
25304
25430
|
|
|
25305
25431
|
// src/run/session.ts
|
|
@@ -27083,487 +27209,12 @@ function invalidResult(terminal, message, details) {
|
|
|
27083
27209
|
}
|
|
27084
27210
|
|
|
27085
27211
|
// src/internal/root-flow-call-controller.ts
|
|
27086
|
-
import { lstat as
|
|
27087
|
-
import { join as
|
|
27088
|
-
var ALLOCATION_KIND2 = "private-root-child-owner-allocation/1";
|
|
27089
|
-
var SANDBOX_KIND = "private-root-child-sandbox/1";
|
|
27090
|
-
var CLEANUP_KIND = "private-root-child-cleanup/1";
|
|
27091
|
-
var CANCELLATION_GRACE_MS = 1000;
|
|
27092
|
-
async function executePrivateRootFlowCall(input) {
|
|
27093
|
-
const selected = selectChild(input.parent, input.call.slot);
|
|
27094
|
-
if (selected === undefined) {
|
|
27095
|
-
return failed("UNAVAILABLE", "the requested slot has no admitted child Flow");
|
|
27096
|
-
}
|
|
27097
|
-
if (selected.disposition.state !== "ready") {
|
|
27098
|
-
return failed("UNAVAILABLE", "the admitted child Flow is unavailable on this host");
|
|
27099
|
-
}
|
|
27100
|
-
if (input.signal.aborted)
|
|
27101
|
-
return failed("CANCELLED", "the child Flow call was cancelled");
|
|
27102
|
-
const invalidInput = await validateChildInput(input.packageStoreRoot, selected.request.package, input.call.input);
|
|
27103
|
-
if (invalidInput !== undefined)
|
|
27104
|
-
return invalidInput;
|
|
27105
|
-
let recipe;
|
|
27106
|
-
try {
|
|
27107
|
-
recipe = await planPrivateDirectRun({
|
|
27108
|
-
request: selected.request,
|
|
27109
|
-
executionPackage: selected.disposition.executionPackage,
|
|
27110
|
-
installedSupport: input.installedSupport,
|
|
27111
|
-
backend: input.backend
|
|
27112
|
-
});
|
|
27113
|
-
} catch {
|
|
27114
|
-
return failed("UNAVAILABLE", "the admitted child recipe cannot be reproduced");
|
|
27115
|
-
}
|
|
27116
|
-
if (recipe.digest !== selected.disposition.recipeDigest || recipe.observation.digest !== selected.disposition.observationDigest) {
|
|
27117
|
-
return failed("UNAVAILABLE", "the admitted child recipe cannot be reproduced");
|
|
27118
|
-
}
|
|
27119
|
-
const effectiveDeadlineUnixMs = Math.min(input.parentDeadlineUnixMs, Date.now() + recipe.wallClockCeilingMs);
|
|
27120
|
-
if (Date.now() >= effectiveDeadlineUnixMs) {
|
|
27121
|
-
return failed("DEADLINE_EXCEEDED", "the child Flow deadline elapsed before dispatch");
|
|
27122
|
-
}
|
|
27123
|
-
const existing = (await listPrivateRootChildOwners({
|
|
27124
|
-
coordinator: input.coordinator,
|
|
27125
|
-
projectRoot: input.projectRoot,
|
|
27126
|
-
parentRunId: input.parent.run.runId
|
|
27127
|
-
})).find(({ operationId }) => operationId === input.call.operationId);
|
|
27128
|
-
if (existing !== undefined) {
|
|
27129
|
-
await recoverOne(input, existing);
|
|
27130
|
-
return failed("UNCERTAIN", "a prior child dispatch was fenced without a proved result");
|
|
27131
|
-
}
|
|
27132
|
-
const roots = await protectedWorkRoots(input.projectRoot);
|
|
27133
|
-
const identity2 = childIdentity(input.parent.run.runId, input.call.operationId);
|
|
27134
|
-
const [packageAllocation, ownerAllocation] = await Promise.all([
|
|
27135
|
-
allocatePrivatePackageMaterialization({
|
|
27136
|
-
protectedParent: roots.materializations,
|
|
27137
|
-
name: `child-${identity2.slice(0, 48)}`,
|
|
27138
|
-
packageDigest: recipe.executionPackage.digest,
|
|
27139
|
-
ownerToken: `sha256:${identity2}`
|
|
27140
|
-
}),
|
|
27141
|
-
planPrivateLinuxOwnerStateAllocation({
|
|
27142
|
-
parent: roots.owners,
|
|
27143
|
-
name: `c-${identity2.slice(0, 47)}`
|
|
27144
|
-
})
|
|
27145
|
-
]);
|
|
27146
|
-
const allocation = Object.freeze({
|
|
27147
|
-
kind: ALLOCATION_KIND2,
|
|
27148
|
-
parentRunId: input.parent.run.runId,
|
|
27149
|
-
coordinatorEpoch: input.parent.run.coordinatorEpoch,
|
|
27150
|
-
operationId: input.call.operationId,
|
|
27151
|
-
requestDigest: selected.request.digest,
|
|
27152
|
-
effectiveDeadlineUnixMs,
|
|
27153
|
-
packageAllocation,
|
|
27154
|
-
ownerAllocation
|
|
27155
|
-
});
|
|
27156
|
-
let lifecycle;
|
|
27157
|
-
try {
|
|
27158
|
-
lifecycle = await allocatePrivateRootChildOwner({
|
|
27159
|
-
coordinator: input.coordinator,
|
|
27160
|
-
projectRoot: input.projectRoot,
|
|
27161
|
-
parentRunId: input.parent.run.runId,
|
|
27162
|
-
operationId: input.call.operationId,
|
|
27163
|
-
allocation
|
|
27164
|
-
});
|
|
27165
|
-
} catch (error) {
|
|
27166
|
-
if (error instanceof CheckError && error.code === "RUN_CHILD_CAPACITY") {
|
|
27167
|
-
return failed("RESOURCE_EXHAUSTED", "the parent Run already has an active child operation");
|
|
27168
|
-
}
|
|
27169
|
-
throw error;
|
|
27170
|
-
}
|
|
27171
|
-
let attemptedDispatch = false;
|
|
27172
|
-
try {
|
|
27173
|
-
const lease = await materializeChild(input.packageStoreRoot, recipe, packageAllocation);
|
|
27174
|
-
await revalidateRecipe(recipe);
|
|
27175
|
-
const sealed = await input.backend.seal(backendPlan(recipe, lease.root, identity2, effectiveDeadlineUnixMs), ownerAllocation);
|
|
27176
|
-
const sandbox = Object.freeze({ kind: SANDBOX_KIND, owner: sealed.identity });
|
|
27177
|
-
lifecycle = await recordPrivateRootChildSandbox({
|
|
27178
|
-
coordinator: input.coordinator,
|
|
27179
|
-
projectRoot: input.projectRoot,
|
|
27180
|
-
parentRunId: input.parent.run.runId,
|
|
27181
|
-
operationId: input.call.operationId,
|
|
27182
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
27183
|
-
sandbox
|
|
27184
|
-
});
|
|
27185
|
-
const startup = startupSignal(input.signal);
|
|
27186
|
-
let component;
|
|
27187
|
-
try {
|
|
27188
|
-
attemptedDispatch = true;
|
|
27189
|
-
component = await sealed.admit(startup.signal);
|
|
27190
|
-
} finally {
|
|
27191
|
-
startup.dispose();
|
|
27192
|
-
}
|
|
27193
|
-
const provisional = await new RunHostSession(component, {
|
|
27194
|
-
input: input.call.input,
|
|
27195
|
-
settings: selected.request.settings,
|
|
27196
|
-
attachments: Object.freeze({}),
|
|
27197
|
-
scratch: recipe.scratch,
|
|
27198
|
-
deadlineUnixMs: effectiveDeadlineUnixMs,
|
|
27199
|
-
signal: input.signal
|
|
27200
|
-
}, { cancellationGraceMs: CANCELLATION_GRACE_MS }).run();
|
|
27201
|
-
const fence = await component.enforcement;
|
|
27202
|
-
await releaseKnownChild(input, lifecycle, lease, fence);
|
|
27203
|
-
return await admitOperationResult(input.packageStoreRoot, selected.request.package, provisional);
|
|
27204
|
-
} catch (error) {
|
|
27205
|
-
try {
|
|
27206
|
-
const active = await findLifecycle(input, input.call.operationId);
|
|
27207
|
-
if (active !== undefined)
|
|
27208
|
-
await recoverOne(input, active);
|
|
27209
|
-
} catch (cleanupError) {
|
|
27210
|
-
if (attemptedDispatch && cleanupError instanceof PrivateLinuxFenceUnconfirmedError) {
|
|
27211
|
-
return failed("UNCERTAIN", "child dispatch may have occurred but its fence is not yet confirmed");
|
|
27212
|
-
}
|
|
27213
|
-
throw new AggregateError([error, cleanupError], "child Flow execution and cleanup failed");
|
|
27214
|
-
}
|
|
27215
|
-
if (input.signal.aborted)
|
|
27216
|
-
return failed("CANCELLED", "the child Flow call was cancelled");
|
|
27217
|
-
if (Date.now() >= effectiveDeadlineUnixMs) {
|
|
27218
|
-
return failed("DEADLINE_EXCEEDED", "the child Flow deadline elapsed");
|
|
27219
|
-
}
|
|
27220
|
-
return attemptedDispatch ? failed("UNCERTAIN", "child dispatch may have occurred but no result was proved") : failed("EXECUTION_FAILED", "child Flow execution failed before dispatch");
|
|
27221
|
-
}
|
|
27222
|
-
}
|
|
27223
|
-
async function recoverPrivateRootFlowCallOwners(input) {
|
|
27224
|
-
const owners = await listPrivateRootChildOwners({
|
|
27225
|
-
coordinator: input.coordinator,
|
|
27226
|
-
projectRoot: input.projectRoot,
|
|
27227
|
-
parentRunId: input.parent.run.runId
|
|
27228
|
-
});
|
|
27229
|
-
for (const owner of owners) {
|
|
27230
|
-
if (isPrivateRootFlowCallOwner(owner))
|
|
27231
|
-
await recoverOne(input, owner);
|
|
27232
|
-
}
|
|
27233
|
-
}
|
|
27234
|
-
function isPrivateRootFlowCallOwner(lifecycle) {
|
|
27235
|
-
const value = lifecycle.allocation.value;
|
|
27236
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) && value.kind === ALLOCATION_KIND2;
|
|
27237
|
-
}
|
|
27238
|
-
function selectChild(parent, slot) {
|
|
27239
|
-
const parentTarget = findPrivateActivationCandidateTargetV5(parent.candidate, parent.run.target);
|
|
27240
|
-
if (parentTarget === undefined || parentTarget.request.digest !== parent.intent.requestDigest) {
|
|
27241
|
-
throw new Error("parent Run differs from its admitted target");
|
|
27242
|
-
}
|
|
27243
|
-
const path = parentTarget.request.flowSlots[slot];
|
|
27244
|
-
if (path === undefined)
|
|
27245
|
-
return;
|
|
27246
|
-
const child = findPrivateActivationCandidateTargetV5(parent.candidate, { kind: "flow", path });
|
|
27247
|
-
if (child === undefined || child.request.target.kind !== "flow" || child.request.packagePath !== path || Object.keys(child.request.flowSlots).length !== 0 || Object.keys(child.request.capabilities).length !== 0) {
|
|
27248
|
-
throw new Error("admitted Flow slot does not name one direct child target");
|
|
27249
|
-
}
|
|
27250
|
-
return child;
|
|
27251
|
-
}
|
|
27252
|
-
async function validateChildInput(store, reference, value) {
|
|
27253
|
-
const captured = await captureStoredPackage(store, reference);
|
|
27254
|
-
try {
|
|
27255
|
-
const inspected = await inspectCapturedPackage(captured);
|
|
27256
|
-
try {
|
|
27257
|
-
inspected.schemas.input?.validate(value, "INVALID_INPUT");
|
|
27258
|
-
} catch (error) {
|
|
27259
|
-
if (!(error instanceof SchemaDiagnostic))
|
|
27260
|
-
throw error;
|
|
27261
|
-
return failed("INVALID_INPUT", "child Flow input does not satisfy its declared schema");
|
|
27262
|
-
}
|
|
27263
|
-
return;
|
|
27264
|
-
} finally {
|
|
27265
|
-
await captured.dispose();
|
|
27266
|
-
}
|
|
27267
|
-
}
|
|
27268
|
-
async function admitOperationResult(store, reference, provisional) {
|
|
27269
|
-
let admitted = provisional;
|
|
27270
|
-
if (provisional.status === "succeeded") {
|
|
27271
|
-
const captured = await captureStoredPackage(store, reference);
|
|
27272
|
-
try {
|
|
27273
|
-
admitted = admitPrivatePackageResult(await inspectCapturedPackage(captured), provisional);
|
|
27274
|
-
} finally {
|
|
27275
|
-
await captured.dispose();
|
|
27276
|
-
}
|
|
27277
|
-
}
|
|
27278
|
-
if (admitted.status === "succeeded") {
|
|
27279
|
-
return Object.freeze({ status: "succeeded", result: admitted.result });
|
|
27280
|
-
}
|
|
27281
|
-
if (admitted.code === "PROTOCOL_ERROR" || admitted.code === "CHANNEL_LOST") {
|
|
27282
|
-
return failed("EXECUTION_FAILED", "the child Flow execution channel failed");
|
|
27283
|
-
}
|
|
27284
|
-
return failed(admitted.code, admitted.message, admitted.details);
|
|
27285
|
-
}
|
|
27286
|
-
async function materializeChild(store, recipe, allocation) {
|
|
27287
|
-
const captured = await captureStoredPackage(store, recipe.executionPackage);
|
|
27288
|
-
try {
|
|
27289
|
-
return await materializePrivatePackageLease(captured, allocation);
|
|
27290
|
-
} finally {
|
|
27291
|
-
await captured.dispose();
|
|
27292
|
-
}
|
|
27293
|
-
}
|
|
27294
|
-
async function revalidateRecipe(recipe) {
|
|
27295
|
-
const [mechanism] = await Promise.all([
|
|
27296
|
-
recipe.backend.observeMechanism(),
|
|
27297
|
-
revalidatePrivateInstalledBunSupport(recipe.installedSupport)
|
|
27298
|
-
]);
|
|
27299
|
-
if (mechanism.support.digest !== recipe.mechanismDigest) {
|
|
27300
|
-
throw new Error("child recipe no longer matches retained host support");
|
|
27301
|
-
}
|
|
27302
|
-
}
|
|
27303
|
-
function backendPlan(recipe, packageRoot, identity2, deadlineUnixMs) {
|
|
27304
|
-
return Object.freeze({
|
|
27305
|
-
runId: `child-${identity2.slice(0, 42)}`,
|
|
27306
|
-
limits: Object.freeze({
|
|
27307
|
-
...recipe.resourceCeilings,
|
|
27308
|
-
deadlineUnixMs,
|
|
27309
|
-
cancellationGraceMs: CANCELLATION_GRACE_MS
|
|
27310
|
-
}),
|
|
27311
|
-
readOnlyMounts: Object.freeze([
|
|
27312
|
-
...recipe.installedSupport.runtimeMounts,
|
|
27313
|
-
{ source: packageRoot, destination: recipe.packageDestination }
|
|
27314
|
-
]),
|
|
27315
|
-
command: Object.freeze([
|
|
27316
|
-
recipe.sandboxExecutablePath,
|
|
27317
|
-
...recipe.bunPolicy,
|
|
27318
|
-
`${recipe.packageDestination}/${recipe.request.entrypoint.path}`
|
|
27319
|
-
])
|
|
27320
|
-
});
|
|
27321
|
-
}
|
|
27322
|
-
async function releaseKnownChild(input, lifecycleValue, lease, fence) {
|
|
27323
|
-
let lifecycle = lifecycleValue;
|
|
27324
|
-
const sandbox = parseSandbox(lifecycle);
|
|
27325
|
-
lifecycle = await recordPrivateRootChildFence({
|
|
27326
|
-
coordinator: input.coordinator,
|
|
27327
|
-
projectRoot: input.projectRoot,
|
|
27328
|
-
parentRunId: lifecycle.parentRunId,
|
|
27329
|
-
operationId: lifecycle.operationId,
|
|
27330
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
27331
|
-
sandboxDigest: lifecycle.sandbox.digest,
|
|
27332
|
-
fence
|
|
27333
|
-
});
|
|
27334
|
-
await disposePrivatePackageMaterializationLease(lease.identity.allocation.parent.path, lease.identity);
|
|
27335
|
-
const ownerRelease = await releasePrivateLinuxOwnerState(sandbox.owner, fence);
|
|
27336
|
-
const cleanup = childCleanup(ownerRelease);
|
|
27337
|
-
lifecycle = await recordPrivateRootChildCleanup({
|
|
27338
|
-
coordinator: input.coordinator,
|
|
27339
|
-
projectRoot: input.projectRoot,
|
|
27340
|
-
parentRunId: lifecycle.parentRunId,
|
|
27341
|
-
operationId: lifecycle.operationId,
|
|
27342
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
27343
|
-
sandboxDigest: lifecycle.sandbox.digest,
|
|
27344
|
-
fenceDigest: lifecycle.fence.digest,
|
|
27345
|
-
cleanup
|
|
27346
|
-
});
|
|
27347
|
-
await closePrivateRootChildOwner({
|
|
27348
|
-
coordinator: input.coordinator,
|
|
27349
|
-
projectRoot: input.projectRoot,
|
|
27350
|
-
parentRunId: lifecycle.parentRunId,
|
|
27351
|
-
operationId: lifecycle.operationId,
|
|
27352
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
27353
|
-
sandboxDigest: lifecycle.sandbox.digest,
|
|
27354
|
-
fenceDigest: lifecycle.fence.digest,
|
|
27355
|
-
cleanupDigest: lifecycle.cleanup.digest
|
|
27356
|
-
});
|
|
27357
|
-
}
|
|
27358
|
-
async function recoverOne(input, lifecycle) {
|
|
27359
|
-
const allocation = parseAllocation2(lifecycle);
|
|
27360
|
-
await requireAllocationMatchesParent(input, lifecycle, allocation);
|
|
27361
|
-
if (lifecycle.sandbox === undefined) {
|
|
27362
|
-
const cancelled = await cancelPrivateLinuxOwnerStateAllocation(allocation.ownerAllocation);
|
|
27363
|
-
await releasePrivateLinuxOwnerState(allocation.ownerAllocation, cancelled);
|
|
27364
|
-
} else {
|
|
27365
|
-
const sandbox = parseSandbox(lifecycle);
|
|
27366
|
-
let fence;
|
|
27367
|
-
if (lifecycle.fence === undefined) {
|
|
27368
|
-
fence = await input.backend.recoverFence(sandbox.owner);
|
|
27369
|
-
lifecycle = await recordPrivateRootChildFence({
|
|
27370
|
-
coordinator: input.coordinator,
|
|
27371
|
-
projectRoot: input.projectRoot,
|
|
27372
|
-
parentRunId: lifecycle.parentRunId,
|
|
27373
|
-
operationId: lifecycle.operationId,
|
|
27374
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
27375
|
-
sandboxDigest: lifecycle.sandbox.digest,
|
|
27376
|
-
fence
|
|
27377
|
-
});
|
|
27378
|
-
} else {
|
|
27379
|
-
fence = parseFence(lifecycle);
|
|
27380
|
-
}
|
|
27381
|
-
const recovered = await recoverPrivatePackageMaterializationAllocation(allocation.packageAllocation.parent.path, allocation.packageAllocation);
|
|
27382
|
-
if (recovered.state === "complete")
|
|
27383
|
-
await recovered.lease.dispose();
|
|
27384
|
-
const ownerRelease = await releasePrivateLinuxOwnerState(sandbox.owner, fence);
|
|
27385
|
-
const cleanup = childCleanup(ownerRelease);
|
|
27386
|
-
if (lifecycle.cleanup === undefined) {
|
|
27387
|
-
lifecycle = await recordPrivateRootChildCleanup({
|
|
27388
|
-
coordinator: input.coordinator,
|
|
27389
|
-
projectRoot: input.projectRoot,
|
|
27390
|
-
parentRunId: lifecycle.parentRunId,
|
|
27391
|
-
operationId: lifecycle.operationId,
|
|
27392
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
27393
|
-
sandboxDigest: lifecycle.sandbox.digest,
|
|
27394
|
-
fenceDigest: lifecycle.fence.digest,
|
|
27395
|
-
cleanup
|
|
27396
|
-
});
|
|
27397
|
-
} else {
|
|
27398
|
-
requireCleanupMatches(lifecycle, cleanup);
|
|
27399
|
-
}
|
|
27400
|
-
}
|
|
27401
|
-
if (lifecycle.sandbox === undefined) {
|
|
27402
|
-
const recovered = await recoverPrivatePackageMaterializationAllocation(allocation.packageAllocation.parent.path, allocation.packageAllocation);
|
|
27403
|
-
if (recovered.state === "complete")
|
|
27404
|
-
await recovered.lease.dispose();
|
|
27405
|
-
}
|
|
27406
|
-
await closePrivateRootChildOwner({
|
|
27407
|
-
coordinator: input.coordinator,
|
|
27408
|
-
projectRoot: input.projectRoot,
|
|
27409
|
-
parentRunId: lifecycle.parentRunId,
|
|
27410
|
-
operationId: lifecycle.operationId,
|
|
27411
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
27412
|
-
sandboxDigest: lifecycle.sandbox?.digest ?? null,
|
|
27413
|
-
fenceDigest: lifecycle.fence?.digest ?? null,
|
|
27414
|
-
cleanupDigest: lifecycle.cleanup?.digest ?? null
|
|
27415
|
-
});
|
|
27416
|
-
}
|
|
27417
|
-
async function findLifecycle(input, operationId) {
|
|
27418
|
-
return (await listPrivateRootChildOwners({
|
|
27419
|
-
coordinator: input.coordinator,
|
|
27420
|
-
projectRoot: input.projectRoot,
|
|
27421
|
-
parentRunId: input.parent.run.runId
|
|
27422
|
-
})).find((item) => item.operationId === operationId);
|
|
27423
|
-
}
|
|
27424
|
-
function parseAllocation2(lifecycle) {
|
|
27425
|
-
const value = exactObject4(lifecycle.allocation.value, [
|
|
27426
|
-
"kind",
|
|
27427
|
-
"parentRunId",
|
|
27428
|
-
"coordinatorEpoch",
|
|
27429
|
-
"operationId",
|
|
27430
|
-
"requestDigest",
|
|
27431
|
-
"effectiveDeadlineUnixMs",
|
|
27432
|
-
"packageAllocation",
|
|
27433
|
-
"ownerAllocation"
|
|
27434
|
-
], "child allocation");
|
|
27435
|
-
if (value.kind !== ALLOCATION_KIND2 || value.parentRunId !== lifecycle.parentRunId || value.operationId !== lifecycle.operationId || typeof value.coordinatorEpoch !== "number" || !Number.isSafeInteger(value.coordinatorEpoch) || value.coordinatorEpoch < 1 || typeof value.requestDigest !== "string" || typeof value.effectiveDeadlineUnixMs !== "number" || !Number.isSafeInteger(value.effectiveDeadlineUnixMs) || value.effectiveDeadlineUnixMs < 0) {
|
|
27436
|
-
throw new TypeError("child allocation is invalid");
|
|
27437
|
-
}
|
|
27438
|
-
return Object.freeze({
|
|
27439
|
-
kind: ALLOCATION_KIND2,
|
|
27440
|
-
parentRunId: value.parentRunId,
|
|
27441
|
-
coordinatorEpoch: value.coordinatorEpoch,
|
|
27442
|
-
operationId: value.operationId,
|
|
27443
|
-
requestDigest: value.requestDigest,
|
|
27444
|
-
effectiveDeadlineUnixMs: value.effectiveDeadlineUnixMs,
|
|
27445
|
-
packageAllocation: normalizePrivatePackageMaterializationAllocationIdentity(value.packageAllocation),
|
|
27446
|
-
ownerAllocation: normalizePrivateLinuxOwnerStateAllocationIdentity(value.ownerAllocation)
|
|
27447
|
-
});
|
|
27448
|
-
}
|
|
27449
|
-
function parseSandbox(lifecycle) {
|
|
27450
|
-
if (lifecycle.sandbox === undefined)
|
|
27451
|
-
throw new TypeError("child sandbox owner is absent");
|
|
27452
|
-
const value = exactObject4(lifecycle.sandbox.value, ["kind", "owner"], "child sandbox");
|
|
27453
|
-
if (value.kind !== SANDBOX_KIND)
|
|
27454
|
-
throw new TypeError("child sandbox kind is invalid");
|
|
27455
|
-
return Object.freeze({
|
|
27456
|
-
kind: SANDBOX_KIND,
|
|
27457
|
-
owner: normalizePrivateLinuxSealedOwnerIdentity(value.owner)
|
|
27458
|
-
});
|
|
27459
|
-
}
|
|
27460
|
-
function parseFence(lifecycle) {
|
|
27461
|
-
if (lifecycle.fence === undefined)
|
|
27462
|
-
throw new TypeError("child fence is absent");
|
|
27463
|
-
return normalizePrivateLinuxConfirmedEnforcementReceipt(lifecycle.fence.value);
|
|
27464
|
-
}
|
|
27465
|
-
function childCleanup(ownerRelease) {
|
|
27466
|
-
return Object.freeze({
|
|
27467
|
-
kind: CLEANUP_KIND,
|
|
27468
|
-
packageReleased: true,
|
|
27469
|
-
ownerRelease
|
|
27470
|
-
});
|
|
27471
|
-
}
|
|
27472
|
-
function parseCleanup(lifecycle) {
|
|
27473
|
-
if (lifecycle.cleanup === undefined)
|
|
27474
|
-
throw new TypeError("child cleanup is absent");
|
|
27475
|
-
const value = exactObject4(lifecycle.cleanup.value, ["kind", "ownerRelease", "packageReleased"], "child cleanup");
|
|
27476
|
-
if (value.kind !== CLEANUP_KIND || value.packageReleased !== true) {
|
|
27477
|
-
throw new TypeError("child cleanup is invalid");
|
|
27478
|
-
}
|
|
27479
|
-
return childCleanup(normalizePrivateLinuxOwnerStateReleaseReceipt(value.ownerRelease));
|
|
27480
|
-
}
|
|
27481
|
-
function requireCleanupMatches(lifecycle, expected) {
|
|
27482
|
-
const actual = parseCleanup(lifecycle);
|
|
27483
|
-
if (actual.ownerRelease.digest !== expected.ownerRelease.digest) {
|
|
27484
|
-
throw new Error("durable child cleanup differs from the released owner");
|
|
27485
|
-
}
|
|
27486
|
-
}
|
|
27487
|
-
async function requireAllocationMatchesParent(input, lifecycle, allocation) {
|
|
27488
|
-
const parentTarget = findPrivateActivationCandidateTargetV5(input.parent.candidate, input.parent.run.target);
|
|
27489
|
-
if (parentTarget === undefined || parentTarget.request.digest !== input.parent.intent.requestDigest || allocation.parentRunId !== input.parent.run.runId || allocation.coordinatorEpoch !== input.parent.run.coordinatorEpoch || allocation.operationId !== lifecycle.operationId || allocation.effectiveDeadlineUnixMs > input.parent.intent.deadlineUnixMs) {
|
|
27490
|
-
throw new Error("durable child allocation differs from its parent Run");
|
|
27491
|
-
}
|
|
27492
|
-
const selected = Object.values(parentTarget.request.flowSlots).map((path) => findPrivateActivationCandidateTargetV5(input.parent.candidate, { kind: "flow", path })).find((target) => target?.request.digest === allocation.requestDigest);
|
|
27493
|
-
if (selected === undefined || selected.request.target.kind !== "flow" || selected.disposition.state !== "ready" || Object.keys(selected.request.flowSlots).length !== 0 || Object.keys(selected.request.capabilities).length !== 0) {
|
|
27494
|
-
throw new Error("durable child allocation is not an admitted direct Flow");
|
|
27495
|
-
}
|
|
27496
|
-
const roots = await protectedWorkRoots(input.projectRoot);
|
|
27497
|
-
const identity2 = childIdentity(lifecycle.parentRunId, lifecycle.operationId);
|
|
27498
|
-
if (allocation.packageAllocation.parent.path !== roots.materializations || allocation.packageAllocation.name !== `child-${identity2.slice(0, 48)}` || allocation.packageAllocation.packageDigest !== selected.disposition.executionPackage.digest || allocation.packageAllocation.ownerToken !== `sha256:${identity2}` || allocation.ownerAllocation.parent !== roots.owners || allocation.ownerAllocation.name !== `c-${identity2.slice(0, 47)}`) {
|
|
27499
|
-
throw new Error("durable child allocation differs from its admitted resources");
|
|
27500
|
-
}
|
|
27501
|
-
}
|
|
27502
|
-
function exactObject4(value, fields, label) {
|
|
27503
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
27504
|
-
throw new TypeError(`${label} must be an object`);
|
|
27505
|
-
}
|
|
27506
|
-
const record2 = value;
|
|
27507
|
-
const actual = Object.keys(record2).sort();
|
|
27508
|
-
const expected = [...fields].sort();
|
|
27509
|
-
if (actual.length !== expected.length || actual.some((field, index) => field !== expected[index])) {
|
|
27510
|
-
throw new TypeError(`${label} must contain exactly ${expected.join(", ")}`);
|
|
27511
|
-
}
|
|
27512
|
-
return record2;
|
|
27513
|
-
}
|
|
27514
|
-
function childIdentity(parentRunId, operationId) {
|
|
27515
|
-
return privateDomainDigest("JIG-Private-Root-Child-Identity/1", {
|
|
27516
|
-
parentRunId,
|
|
27517
|
-
operationId
|
|
27518
|
-
}).slice("sha256:".length);
|
|
27519
|
-
}
|
|
27520
|
-
async function protectedWorkRoots(projectRoot) {
|
|
27521
|
-
const state = await realpath10(join11(projectRoot, ".jig"));
|
|
27522
|
-
const materializations = join11(state, "private-root-materializations");
|
|
27523
|
-
const owners = join11(state, "private-root-linux-owners");
|
|
27524
|
-
await Promise.all([ensureProtectedDirectory(materializations), ensureProtectedDirectory(owners)]);
|
|
27525
|
-
return Object.freeze({ materializations, owners });
|
|
27526
|
-
}
|
|
27527
|
-
async function ensureProtectedDirectory(path) {
|
|
27528
|
-
await mkdir8(path, { mode: 448 }).catch((error) => {
|
|
27529
|
-
if (!hasCode6(error, "EEXIST"))
|
|
27530
|
-
throw error;
|
|
27531
|
-
});
|
|
27532
|
-
const information = await lstat16(path);
|
|
27533
|
-
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
27534
|
-
if (!information.isDirectory() || information.isSymbolicLink() || information.uid !== uid || (information.mode & 63) !== 0 || await realpath10(path) !== path) {
|
|
27535
|
-
throw new Error("child execution owner directory is not protected");
|
|
27536
|
-
}
|
|
27537
|
-
}
|
|
27538
|
-
function startupSignal(signal) {
|
|
27539
|
-
const controller = new AbortController;
|
|
27540
|
-
const abort = () => controller.abort(signal.reason);
|
|
27541
|
-
if (signal.aborted)
|
|
27542
|
-
abort();
|
|
27543
|
-
else
|
|
27544
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
27545
|
-
return Object.freeze({
|
|
27546
|
-
signal: controller.signal,
|
|
27547
|
-
dispose() {
|
|
27548
|
-
signal.removeEventListener("abort", abort);
|
|
27549
|
-
}
|
|
27550
|
-
});
|
|
27551
|
-
}
|
|
27552
|
-
function failed(code, message, details) {
|
|
27553
|
-
return Object.freeze({
|
|
27554
|
-
status: "failed",
|
|
27555
|
-
code,
|
|
27556
|
-
message,
|
|
27557
|
-
...details === undefined ? {} : { details }
|
|
27558
|
-
});
|
|
27559
|
-
}
|
|
27560
|
-
function hasCode6(error, code) {
|
|
27561
|
-
return error !== null && typeof error === "object" && error.code === code;
|
|
27562
|
-
}
|
|
27212
|
+
import { lstat as lstat17, mkdir as mkdir9, realpath as realpath12 } from "fs/promises";
|
|
27213
|
+
import { join as join12 } from "path";
|
|
27563
27214
|
|
|
27564
27215
|
// src/internal/root-agent-run-controller.ts
|
|
27565
|
-
import { lstat as
|
|
27566
|
-
import { join as
|
|
27216
|
+
import { lstat as lstat16, mkdir as mkdir8, realpath as realpath11 } from "fs/promises";
|
|
27217
|
+
import { join as join11 } from "path";
|
|
27567
27218
|
|
|
27568
27219
|
// node_modules/@agentclientprotocol/sdk/dist/schema/index.js
|
|
27569
27220
|
var AGENT_METHODS = {
|
|
@@ -46341,7 +45992,7 @@ function createAbortableSSESource(body, signal) {
|
|
|
46341
45992
|
abort();
|
|
46342
45993
|
}
|
|
46343
45994
|
},
|
|
46344
|
-
async cleanup(
|
|
45995
|
+
async cleanup(failed) {
|
|
46345
45996
|
let cleanupError;
|
|
46346
45997
|
try {
|
|
46347
45998
|
signal.removeEventListener("abort", abort);
|
|
@@ -46350,7 +46001,7 @@ function createAbortableSSESource(body, signal) {
|
|
|
46350
46001
|
}
|
|
46351
46002
|
if (!closed) {
|
|
46352
46003
|
const pending = cancel();
|
|
46353
|
-
if (pending && !
|
|
46004
|
+
if (pending && !failed && !signal.aborted) {
|
|
46354
46005
|
try {
|
|
46355
46006
|
await pending;
|
|
46356
46007
|
} catch (error48) {
|
|
@@ -46365,7 +46016,7 @@ function createAbortableSSESource(body, signal) {
|
|
|
46365
46016
|
cleanupError ?? (cleanupError = error48);
|
|
46366
46017
|
}
|
|
46367
46018
|
}
|
|
46368
|
-
if (cleanupError !== undefined && !
|
|
46019
|
+
if (cleanupError !== undefined && !failed && !signal.aborted) {
|
|
46369
46020
|
throw cleanupError;
|
|
46370
46021
|
}
|
|
46371
46022
|
}
|
|
@@ -46383,7 +46034,7 @@ async function* _iterSSEMessages(response, controller) {
|
|
|
46383
46034
|
const lineDecoder = new LineDecoder;
|
|
46384
46035
|
const { signal } = controller;
|
|
46385
46036
|
const source = createAbortableSSESource(response.body, signal);
|
|
46386
|
-
let
|
|
46037
|
+
let failed = false;
|
|
46387
46038
|
try {
|
|
46388
46039
|
source.start();
|
|
46389
46040
|
for await (const sseChunk of iterSSEChunks(source.iterator)) {
|
|
@@ -46413,12 +46064,12 @@ async function* _iterSSEMessages(response, controller) {
|
|
|
46413
46064
|
}
|
|
46414
46065
|
}
|
|
46415
46066
|
} catch (error48) {
|
|
46416
|
-
|
|
46067
|
+
failed = true;
|
|
46417
46068
|
if (!signal.aborted || !isAbortError2(error48) && error48 !== signal.reason) {
|
|
46418
46069
|
throw error48;
|
|
46419
46070
|
}
|
|
46420
46071
|
} finally {
|
|
46421
|
-
await source.cleanup(
|
|
46072
|
+
await source.cleanup(failed);
|
|
46422
46073
|
}
|
|
46423
46074
|
}
|
|
46424
46075
|
var DOUBLE_NEWLINE_DELIMITER_MAX_OVERLAP_BYTES = 3;
|
|
@@ -49980,12 +49631,12 @@ class EventStream {
|
|
|
49980
49631
|
}
|
|
49981
49632
|
_run(executor) {
|
|
49982
49633
|
setTimeout(() => {
|
|
49983
|
-
let
|
|
49634
|
+
let failed = false;
|
|
49984
49635
|
Promise.resolve().then(executor).catch((error49) => {
|
|
49985
|
-
|
|
49636
|
+
failed = true;
|
|
49986
49637
|
__classPrivateFieldGet(this, _EventStream_instances, "m", _EventStream_handleError).call(this, error49);
|
|
49987
49638
|
}).then(() => {
|
|
49988
|
-
if (
|
|
49639
|
+
if (failed) {
|
|
49989
49640
|
return;
|
|
49990
49641
|
}
|
|
49991
49642
|
try {
|
|
@@ -59006,10 +58657,10 @@ function exactKeys5(value, expected) {
|
|
|
59006
58657
|
}
|
|
59007
58658
|
|
|
59008
58659
|
// src/internal/root-agent-run-controller.ts
|
|
59009
|
-
var
|
|
59010
|
-
var
|
|
59011
|
-
var
|
|
59012
|
-
var
|
|
58660
|
+
var ALLOCATION_KIND2 = "private-root-agent-owner-allocation/1";
|
|
58661
|
+
var SANDBOX_KIND = "private-root-agent-sandbox/1";
|
|
58662
|
+
var CLEANUP_KIND = "private-root-agent-cleanup/1";
|
|
58663
|
+
var CANCELLATION_GRACE_MS = 1000;
|
|
59013
58664
|
var PROVIDER_STDERR_BYTES = 64 * 1024;
|
|
59014
58665
|
var AGENT_PROVIDER_MINIMUM_PIDS = 128;
|
|
59015
58666
|
var PROVIDER_INSTRUCTION_BYTES = 1048576;
|
|
@@ -59017,15 +58668,15 @@ var DIGEST11 = /^sha256:[0-9a-f]{64}$/;
|
|
|
59017
58668
|
var decoder10 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
59018
58669
|
var encoder11 = new TextEncoder;
|
|
59019
58670
|
async function executePrivateRootAgentRun(input) {
|
|
59020
|
-
const selected = selectAgentCapability(input
|
|
58671
|
+
const selected = selectAgentCapability(input, input.call);
|
|
59021
58672
|
if (selected === undefined) {
|
|
59022
|
-
return
|
|
58673
|
+
return failed("UNAVAILABLE", "the requested slot has no admitted Agent Run capability");
|
|
59023
58674
|
}
|
|
59024
58675
|
if (input.call.method !== "run") {
|
|
59025
|
-
return
|
|
58676
|
+
return failed("UNAVAILABLE", "the Agent Run capability has no requested method");
|
|
59026
58677
|
}
|
|
59027
58678
|
if (input.signal.aborted)
|
|
59028
|
-
return
|
|
58679
|
+
return failed("CANCELLED", "the Agent Run was cancelled");
|
|
59029
58680
|
let provider;
|
|
59030
58681
|
let recipe;
|
|
59031
58682
|
try {
|
|
@@ -59035,54 +58686,58 @@ async function executePrivateRootAgentRun(input) {
|
|
|
59035
58686
|
}
|
|
59036
58687
|
recipe = await reproduceParentRecipe(input);
|
|
59037
58688
|
} catch {
|
|
59038
|
-
return
|
|
58689
|
+
return failed("UNAVAILABLE", "the admitted Agent provider cannot be reproduced");
|
|
59039
58690
|
}
|
|
59040
58691
|
let prepared;
|
|
59041
58692
|
try {
|
|
59042
58693
|
prepared = await prepareCall(input, provider);
|
|
59043
58694
|
} catch (error49) {
|
|
59044
58695
|
if (error49 instanceof AgentInstructionLimitError || error49 instanceof SchemaDiagnostic && error49.code === "SCHEMA_LIMIT_EXCEEDED" || error49 instanceof AgentRunValidationError && error49.code === "AGENT_RUN_SKILL_PROJECTION_LIMIT") {
|
|
59045
|
-
return
|
|
58696
|
+
return failed("RESOURCE_EXHAUSTED", "the Agent Run input exceeds its fixed provider bound");
|
|
59046
58697
|
}
|
|
59047
58698
|
if (error49 instanceof AgentRunValidationError || error49 instanceof CheckError || error49 instanceof SchemaDiagnostic || error49 instanceof TypeError) {
|
|
59048
|
-
return
|
|
58699
|
+
return failed("INVALID_INPUT", "the Agent Run input or skill selection is invalid");
|
|
59049
58700
|
}
|
|
59050
58701
|
throw error49;
|
|
59051
58702
|
}
|
|
59052
|
-
const effectiveDeadlineUnixMs = Math.min(input.parentDeadlineUnixMs, Date.now() + recipe.wallClockCeilingMs);
|
|
58703
|
+
const effectiveDeadlineUnixMs = Math.min(input.parentDeadlineUnixMs, input.parent.intent.deadlineUnixMs, Date.now() + recipe.wallClockCeilingMs);
|
|
59053
58704
|
if (Date.now() >= effectiveDeadlineUnixMs) {
|
|
59054
|
-
return
|
|
58705
|
+
return failed("DEADLINE_EXCEEDED", "the Agent Run deadline elapsed before dispatch");
|
|
59055
58706
|
}
|
|
59056
58707
|
if (input.signal.aborted)
|
|
59057
|
-
return
|
|
59058
|
-
|
|
58708
|
+
return failed("CANCELLED", "the Agent Run was cancelled");
|
|
58709
|
+
if (input.parentFlow !== undefined) {
|
|
58710
|
+
await requireParentFlowOwner(input, input.parentFlow, effectiveDeadlineUnixMs);
|
|
58711
|
+
}
|
|
58712
|
+
const owners = (await listPrivateRootChildOwners({
|
|
59059
58713
|
coordinator: input.coordinator,
|
|
59060
58714
|
projectRoot: input.projectRoot,
|
|
59061
58715
|
parentRunId: input.parent.run.runId
|
|
59062
|
-
});
|
|
58716
|
+
})).filter((owner) => owner.parentOperationId === input.parentFlow?.operationId);
|
|
59063
58717
|
const existing = owners.find(({ operationId }) => operationId === input.call.operationId);
|
|
59064
58718
|
if (existing !== undefined) {
|
|
59065
58719
|
if (!isPrivateRootAgentRunOwner(existing)) {
|
|
59066
58720
|
throw new Error("one operation identity names a different durable child owner");
|
|
59067
58721
|
}
|
|
59068
58722
|
await recoverPrivateRootAgentRunOwner(input, existing);
|
|
59069
|
-
return
|
|
58723
|
+
return failed("UNCERTAIN", "a prior Agent dispatch was fenced without a proved result");
|
|
59070
58724
|
}
|
|
59071
58725
|
if (owners.length !== 0) {
|
|
59072
|
-
return
|
|
58726
|
+
return failed("RESOURCE_EXHAUSTED", "the parent Run already has an active child operation");
|
|
59073
58727
|
}
|
|
59074
58728
|
const ownerParent = await protectedOwnerRoot(input.projectRoot);
|
|
59075
|
-
const identity2 = agentIdentity(input.parent.run.runId, input.call.operationId);
|
|
58729
|
+
const identity2 = agentIdentity(input.parent.run.runId, input.call.operationId, input.parentFlow?.operationId);
|
|
59076
58730
|
const ownerAllocation = await planPrivateLinuxOwnerStateAllocation({
|
|
59077
58731
|
parent: ownerParent,
|
|
59078
58732
|
name: `a-${identity2.slice(0, 62)}`
|
|
59079
58733
|
});
|
|
59080
58734
|
const allocation = Object.freeze({
|
|
59081
|
-
kind:
|
|
58735
|
+
kind: ALLOCATION_KIND2,
|
|
59082
58736
|
parentRunId: input.parent.run.runId,
|
|
59083
58737
|
coordinatorEpoch: input.parent.run.coordinatorEpoch,
|
|
59084
58738
|
operationId: input.call.operationId,
|
|
59085
|
-
parentRequestDigest: input.
|
|
58739
|
+
parentRequestDigest: requireParentTarget(input).request.digest,
|
|
58740
|
+
parentFlow: input.parentFlow ?? null,
|
|
59086
58741
|
requestDigest: prepared.digest,
|
|
59087
58742
|
providerDigest: provider.digest,
|
|
59088
58743
|
effectiveDeadlineUnixMs,
|
|
@@ -59094,6 +58749,7 @@ async function executePrivateRootAgentRun(input) {
|
|
|
59094
58749
|
coordinator: input.coordinator,
|
|
59095
58750
|
projectRoot: input.projectRoot,
|
|
59096
58751
|
parentRunId: input.parent.run.runId,
|
|
58752
|
+
...input.parentFlow === undefined ? {} : { parentOperationId: input.parentFlow.operationId },
|
|
59097
58753
|
operationId: input.call.operationId,
|
|
59098
58754
|
allocation
|
|
59099
58755
|
});
|
|
@@ -59104,7 +58760,7 @@ async function executePrivateRootAgentRun(input) {
|
|
|
59104
58760
|
throw new AggregateError([error49, cleanupError], "Agent owner allocation failed and its unused owner could not be released");
|
|
59105
58761
|
}
|
|
59106
58762
|
if (error49 instanceof CheckError && error49.code === "RUN_CHILD_CAPACITY") {
|
|
59107
|
-
return
|
|
58763
|
+
return failed("RESOURCE_EXHAUSTED", "the parent Run already has an active child operation");
|
|
59108
58764
|
}
|
|
59109
58765
|
throw error49;
|
|
59110
58766
|
}
|
|
@@ -59112,12 +58768,13 @@ async function executePrivateRootAgentRun(input) {
|
|
|
59112
58768
|
let execution;
|
|
59113
58769
|
try {
|
|
59114
58770
|
await revalidateProviderSupport(recipe, provider);
|
|
59115
|
-
const sealed = await input.backend.seal(
|
|
59116
|
-
const sandbox = Object.freeze({ kind:
|
|
58771
|
+
const sealed = await input.backend.seal(backendPlan(recipe, provider, effectiveDeadlineUnixMs, identity2), ownerAllocation);
|
|
58772
|
+
const sandbox = Object.freeze({ kind: SANDBOX_KIND, owner: sealed.identity });
|
|
59117
58773
|
lifecycle = await recordPrivateRootChildSandbox({
|
|
59118
58774
|
coordinator: input.coordinator,
|
|
59119
58775
|
projectRoot: input.projectRoot,
|
|
59120
58776
|
parentRunId: input.parent.run.runId,
|
|
58777
|
+
...input.parentFlow === undefined ? {} : { parentOperationId: input.parentFlow.operationId },
|
|
59121
58778
|
operationId: input.call.operationId,
|
|
59122
58779
|
allocationDigest: lifecycle.allocation.digest,
|
|
59123
58780
|
sandbox
|
|
@@ -59128,33 +58785,33 @@ async function executePrivateRootAgentRun(input) {
|
|
|
59128
58785
|
await releaseKnownAgent(input, lifecycle, execution.fence);
|
|
59129
58786
|
} catch (error49) {
|
|
59130
58787
|
try {
|
|
59131
|
-
const active = await
|
|
58788
|
+
const active = await findLifecycle(input, input.call.operationId);
|
|
59132
58789
|
if (active !== undefined)
|
|
59133
58790
|
await recoverPrivateRootAgentRunOwner(input, active);
|
|
59134
58791
|
} catch (cleanupError) {
|
|
59135
58792
|
if (attemptedDispatch && cleanupError instanceof PrivateLinuxFenceUnconfirmedError) {
|
|
59136
|
-
return
|
|
58793
|
+
return failed("UNCERTAIN", "Agent dispatch may have occurred but its fence is not yet confirmed");
|
|
59137
58794
|
}
|
|
59138
58795
|
throw new AggregateError([error49, cleanupError], "Agent Run execution and cleanup failed");
|
|
59139
58796
|
}
|
|
59140
58797
|
if (input.signal.aborted)
|
|
59141
|
-
return
|
|
58798
|
+
return failed("CANCELLED", "the Agent Run was cancelled");
|
|
59142
58799
|
if (Date.now() >= effectiveDeadlineUnixMs) {
|
|
59143
|
-
return
|
|
58800
|
+
return failed("DEADLINE_EXCEEDED", "the Agent Run deadline elapsed");
|
|
59144
58801
|
}
|
|
59145
|
-
return attemptedDispatch ?
|
|
58802
|
+
return attemptedDispatch ? failed("UNCERTAIN", "Agent dispatch may have occurred but no result was proved") : failed("EXECUTION_FAILED", "Agent Run execution failed before dispatch");
|
|
59146
58803
|
}
|
|
59147
58804
|
if (execution.fence.stopReason === "cancelled" || input.signal.aborted) {
|
|
59148
|
-
return
|
|
58805
|
+
return failed("CANCELLED", "the Agent Run was cancelled");
|
|
59149
58806
|
}
|
|
59150
58807
|
if (execution.fence.stopReason === "deadline" || Date.now() >= effectiveDeadlineUnixMs) {
|
|
59151
|
-
return
|
|
58808
|
+
return failed("DEADLINE_EXCEEDED", "the Agent Run deadline elapsed");
|
|
59152
58809
|
}
|
|
59153
58810
|
if (execution.fence.exitCode !== 0 || execution.fence.signal !== null) {
|
|
59154
|
-
return
|
|
58811
|
+
return failed("EXECUTION_FAILED", "the Agent provider process failed");
|
|
59155
58812
|
}
|
|
59156
58813
|
if (execution.cancelled) {
|
|
59157
|
-
return
|
|
58814
|
+
return failed("CANCELLED", "the Agent Run was cancelled");
|
|
59158
58815
|
}
|
|
59159
58816
|
if (execution.failure !== undefined)
|
|
59160
58817
|
return providerFailure(execution.failure);
|
|
@@ -59165,12 +58822,12 @@ async function executePrivateRootAgentRun(input) {
|
|
|
59165
58822
|
result: Object.freeze({ value })
|
|
59166
58823
|
});
|
|
59167
58824
|
} catch {
|
|
59168
|
-
return
|
|
58825
|
+
return failed("INVALID_RESULT", "the Agent provider result does not satisfy Agent Run/1");
|
|
59169
58826
|
}
|
|
59170
58827
|
}
|
|
59171
58828
|
function isPrivateRootAgentRunOwner(lifecycle) {
|
|
59172
58829
|
const value = lifecycle.allocation.value;
|
|
59173
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) && value.kind ===
|
|
58830
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && value.kind === ALLOCATION_KIND2;
|
|
59174
58831
|
}
|
|
59175
58832
|
async function recoverPrivateRootAgentRunOwners(input) {
|
|
59176
58833
|
const owners = await listPrivateRootChildOwners({
|
|
@@ -59179,15 +58836,905 @@ async function recoverPrivateRootAgentRunOwners(input) {
|
|
|
59179
58836
|
parentRunId: input.parent.run.runId
|
|
59180
58837
|
});
|
|
59181
58838
|
for (const owner of owners) {
|
|
59182
|
-
if (isPrivateRootAgentRunOwner(owner)) {
|
|
58839
|
+
if (isPrivateRootAgentRunOwner(owner) && (input.parentFlow === undefined || owner.parentOperationId === input.parentFlow.operationId)) {
|
|
59183
58840
|
await recoverPrivateRootAgentRunOwner(input, owner);
|
|
59184
58841
|
}
|
|
59185
58842
|
}
|
|
59186
58843
|
}
|
|
59187
58844
|
async function recoverPrivateRootAgentRunOwner(input, lifecycleValue) {
|
|
59188
58845
|
let lifecycle = lifecycleValue;
|
|
58846
|
+
const allocation = parseAllocation2(lifecycle);
|
|
58847
|
+
await requireAllocationMatchesParent(input, lifecycle, allocation);
|
|
58848
|
+
if (lifecycle.sandbox === undefined) {
|
|
58849
|
+
const cancelled = await cancelPrivateLinuxOwnerStateAllocation(allocation.ownerAllocation);
|
|
58850
|
+
await releasePrivateLinuxOwnerState(allocation.ownerAllocation, cancelled);
|
|
58851
|
+
} else {
|
|
58852
|
+
const sandbox = parseSandbox(lifecycle);
|
|
58853
|
+
let fence;
|
|
58854
|
+
if (lifecycle.fence === undefined) {
|
|
58855
|
+
fence = await input.backend.recoverFence(sandbox.owner);
|
|
58856
|
+
lifecycle = await recordPrivateRootChildFence({
|
|
58857
|
+
coordinator: input.coordinator,
|
|
58858
|
+
projectRoot: input.projectRoot,
|
|
58859
|
+
parentRunId: lifecycle.parentRunId,
|
|
58860
|
+
...lifecycle.parentOperationId === undefined ? {} : { parentOperationId: lifecycle.parentOperationId },
|
|
58861
|
+
operationId: lifecycle.operationId,
|
|
58862
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
58863
|
+
sandboxDigest: lifecycle.sandbox.digest,
|
|
58864
|
+
fence
|
|
58865
|
+
});
|
|
58866
|
+
} else {
|
|
58867
|
+
fence = parseFence(lifecycle);
|
|
58868
|
+
}
|
|
58869
|
+
const ownerRelease = await releasePrivateLinuxOwnerState(sandbox.owner, fence);
|
|
58870
|
+
const cleanup = agentCleanup(ownerRelease);
|
|
58871
|
+
if (lifecycle.cleanup === undefined) {
|
|
58872
|
+
lifecycle = await recordPrivateRootChildCleanup({
|
|
58873
|
+
coordinator: input.coordinator,
|
|
58874
|
+
projectRoot: input.projectRoot,
|
|
58875
|
+
parentRunId: lifecycle.parentRunId,
|
|
58876
|
+
...lifecycle.parentOperationId === undefined ? {} : { parentOperationId: lifecycle.parentOperationId },
|
|
58877
|
+
operationId: lifecycle.operationId,
|
|
58878
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
58879
|
+
sandboxDigest: lifecycle.sandbox.digest,
|
|
58880
|
+
fenceDigest: lifecycle.fence.digest,
|
|
58881
|
+
cleanup
|
|
58882
|
+
});
|
|
58883
|
+
} else {
|
|
58884
|
+
requireCleanupMatches(lifecycle, cleanup);
|
|
58885
|
+
}
|
|
58886
|
+
}
|
|
58887
|
+
await closePrivateRootChildOwner({
|
|
58888
|
+
coordinator: input.coordinator,
|
|
58889
|
+
projectRoot: input.projectRoot,
|
|
58890
|
+
parentRunId: lifecycle.parentRunId,
|
|
58891
|
+
...lifecycle.parentOperationId === undefined ? {} : { parentOperationId: lifecycle.parentOperationId },
|
|
58892
|
+
operationId: lifecycle.operationId,
|
|
58893
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
58894
|
+
sandboxDigest: lifecycle.sandbox?.digest ?? null,
|
|
58895
|
+
fenceDigest: lifecycle.fence?.digest ?? null,
|
|
58896
|
+
cleanupDigest: lifecycle.cleanup?.digest ?? null
|
|
58897
|
+
});
|
|
58898
|
+
}
|
|
58899
|
+
function renderPrivateAgentRunInstructions(instructions, manifest) {
|
|
58900
|
+
const skills = manifest.skills.map((skill) => ({
|
|
58901
|
+
name: skill.name,
|
|
58902
|
+
files: skill.files.map((file2) => {
|
|
58903
|
+
let content;
|
|
58904
|
+
try {
|
|
58905
|
+
content = decoder10.decode(file2.bytes());
|
|
58906
|
+
} catch {
|
|
58907
|
+
throw new AgentRunValidationError("AGENT_RUN_SKILL_CONTENT_INVALID", `Agent Run skill file ${skill.name}/${file2.path} is not UTF-8 text`);
|
|
58908
|
+
}
|
|
58909
|
+
return { path: file2.path, content };
|
|
58910
|
+
})
|
|
58911
|
+
}));
|
|
58912
|
+
const payload = decoder10.decode(canonicalJson({ instructions, skills }));
|
|
58913
|
+
const rendered = [
|
|
58914
|
+
"Execute one Jig Agent Run. Treat the author instructions as the task and the selected package-local skill files as guidance.",
|
|
58915
|
+
"The following value is canonical JSON:",
|
|
58916
|
+
payload
|
|
58917
|
+
].join(`
|
|
58918
|
+
`);
|
|
58919
|
+
if (encoder11.encode(rendered).byteLength > PROVIDER_INSTRUCTION_BYTES) {
|
|
58920
|
+
throw new AgentInstructionLimitError;
|
|
58921
|
+
}
|
|
58922
|
+
return rendered;
|
|
58923
|
+
}
|
|
58924
|
+
function renderPrivateAcpStructuredInstructions(instructions, responseSchema) {
|
|
58925
|
+
const schema = decoder10.decode(canonicalJson(projectPrivateAgentResponseSchema(responseSchema)));
|
|
58926
|
+
const rendered = [
|
|
58927
|
+
instructions,
|
|
58928
|
+
"Return only one JSON value matching this canonical FLOW Schema/1 schema:",
|
|
58929
|
+
"Do not wrap the JSON value in Markdown or a code fence.",
|
|
58930
|
+
schema
|
|
58931
|
+
].join(`
|
|
58932
|
+
`);
|
|
58933
|
+
if (encoder11.encode(rendered).byteLength > PROVIDER_INSTRUCTION_BYTES) {
|
|
58934
|
+
throw new AgentInstructionLimitError;
|
|
58935
|
+
}
|
|
58936
|
+
return rendered;
|
|
58937
|
+
}
|
|
58938
|
+
async function prepareCall(input, provider) {
|
|
58939
|
+
const target = requireParentTarget(input);
|
|
58940
|
+
const captured = await captureStoredPackage(input.packageStoreRoot, target.request.package);
|
|
58941
|
+
try {
|
|
58942
|
+
const inspected = await inspectCapturedPackage(captured);
|
|
58943
|
+
const reference = inspected.usedContracts.find(({ slot }) => slot === input.call.slot);
|
|
58944
|
+
if (reference === undefined) {
|
|
58945
|
+
throw new AgentRunValidationError("AGENT_RUN_CONTRACT_MISMATCH", "Agent Run capability descriptor is absent from the admitted package");
|
|
58946
|
+
}
|
|
58947
|
+
assertAgentRunContract(reference.contract);
|
|
58948
|
+
const prepared = parseAgentRunInput(reference.contract, input.call.input);
|
|
58949
|
+
const manifest = await projectAgentRunSkills(captured, prepared.selectedSkills);
|
|
58950
|
+
let instructions = renderPrivateAgentRunInstructions(prepared.input.instructions, manifest);
|
|
58951
|
+
const responseSchema = prepared.input.responseSchema;
|
|
58952
|
+
if (responseSchema !== undefined)
|
|
58953
|
+
assertPrivateAgentResponseSchema(responseSchema);
|
|
58954
|
+
if (provider.kind === "private-acp-agent-provider/1" && responseSchema !== undefined) {
|
|
58955
|
+
instructions = renderPrivateAcpStructuredInstructions(instructions, responseSchema);
|
|
58956
|
+
}
|
|
58957
|
+
const requestIdentity = Object.freeze({
|
|
58958
|
+
providerDigest: provider.digest,
|
|
58959
|
+
instructions,
|
|
58960
|
+
...responseSchema === undefined ? {} : { responseSchema }
|
|
58961
|
+
});
|
|
58962
|
+
return Object.freeze({
|
|
58963
|
+
input: prepared,
|
|
58964
|
+
contract: reference.contract,
|
|
58965
|
+
instructions,
|
|
58966
|
+
...responseSchema === undefined ? {} : { responseSchema },
|
|
58967
|
+
digest: privateDomainDigest("JIG-Private-Agent-Request/1", requestIdentity)
|
|
58968
|
+
});
|
|
58969
|
+
} finally {
|
|
58970
|
+
await captured.dispose();
|
|
58971
|
+
}
|
|
58972
|
+
}
|
|
58973
|
+
function selectAgentCapability(input, call) {
|
|
58974
|
+
const target = requireParentTarget(input);
|
|
58975
|
+
const selected = target.request.capabilities[call.slot];
|
|
58976
|
+
if (selected === undefined)
|
|
58977
|
+
return;
|
|
58978
|
+
if (selected.id !== AGENT_RUN_CONTRACT_ID || selected.version !== AGENT_RUN_CONTRACT_VERSION || selected.digest !== AGENT_RUN_CONTRACT_DIGEST) {
|
|
58979
|
+
throw new Error("admitted Agent Run capability identity is invalid");
|
|
58980
|
+
}
|
|
58981
|
+
return selected;
|
|
58982
|
+
}
|
|
58983
|
+
function requireParentTarget(input) {
|
|
58984
|
+
const { parent, parentFlow } = input;
|
|
58985
|
+
const root = findPrivateActivationCandidateTargetV5(parent.candidate, parent.run.target);
|
|
58986
|
+
if (root === undefined || root.request.digest !== parent.intent.requestDigest || root.disposition.state !== "ready") {
|
|
58987
|
+
throw new Error("parent Run differs from its admitted target");
|
|
58988
|
+
}
|
|
58989
|
+
if (parentFlow === undefined)
|
|
58990
|
+
return root;
|
|
58991
|
+
const target = findPrivateActivationCandidateTargetV5(parent.candidate, parentFlow.target);
|
|
58992
|
+
if (target === undefined || target.request.digest !== parentFlow.requestDigest || target.disposition.state !== "ready" || Object.keys(target.request.flowSlots).length !== 0 || !Object.values(root.request.flowSlots).some((identity2) => findPrivateActivationCandidateTargetV5(parent.candidate, identity2)?.request.digest === target.request.digest)) {
|
|
58993
|
+
throw new Error("Agent parent Flow differs from its admitted child target");
|
|
58994
|
+
}
|
|
58995
|
+
return target;
|
|
58996
|
+
}
|
|
58997
|
+
async function reproduceParentRecipe(input) {
|
|
58998
|
+
const target = requireParentTarget(input);
|
|
58999
|
+
if (target.disposition.state !== "ready") {
|
|
59000
|
+
throw new Error("parent Run target is unavailable");
|
|
59001
|
+
}
|
|
59002
|
+
const recipe = await planPrivateDirectRun({
|
|
59003
|
+
request: target.request,
|
|
59004
|
+
executionPackage: target.disposition.executionPackage,
|
|
59005
|
+
installedSupport: input.installedSupport,
|
|
59006
|
+
backend: input.backend,
|
|
59007
|
+
agentProvider: input.agentProvider
|
|
59008
|
+
});
|
|
59009
|
+
if (recipe.digest !== target.disposition.recipeDigest || recipe.observation.digest !== target.disposition.observationDigest || recipe.agentProvider?.digest !== input.agentProvider.digest) {
|
|
59010
|
+
throw new Error("parent Agent recipe differs from its admission");
|
|
59011
|
+
}
|
|
59012
|
+
return recipe;
|
|
59013
|
+
}
|
|
59014
|
+
async function revalidateProviderSupport(recipe, provider) {
|
|
59015
|
+
const [mechanism] = await Promise.all([
|
|
59016
|
+
recipe.backend.observeMechanism(),
|
|
59017
|
+
revalidatePrivateInstalledBunSupport(recipe.installedSupport),
|
|
59018
|
+
provider.kind === "private-acp-agent-provider/1" ? revalidatePrivateAcpAgentProvider(provider) : Promise.resolve()
|
|
59019
|
+
]);
|
|
59020
|
+
if (mechanism.support.digest !== recipe.mechanismDigest || provider.kind === "private-openai-agent-provider/1" && recipe.installedSupport.agentWorkerDigest !== provider.workerDigest || recipe.agentProvider?.digest !== provider.digest) {
|
|
59021
|
+
throw new Error("Agent provider support changed after admission");
|
|
59022
|
+
}
|
|
59023
|
+
}
|
|
59024
|
+
function backendPlan(recipe, provider, deadlineUnixMs, identity2) {
|
|
59025
|
+
const acp = provider.kind === "private-acp-agent-provider/1" ? privateAcpAgentRuntime(provider) : undefined;
|
|
59026
|
+
return Object.freeze({
|
|
59027
|
+
runId: `agent-${identity2.slice(0, 42)}`,
|
|
59028
|
+
limits: Object.freeze({
|
|
59029
|
+
...recipe.resourceCeilings,
|
|
59030
|
+
pids: Math.max(recipe.resourceCeilings.pids, AGENT_PROVIDER_MINIMUM_PIDS),
|
|
59031
|
+
deadlineUnixMs,
|
|
59032
|
+
cancellationGraceMs: CANCELLATION_GRACE_MS
|
|
59033
|
+
}),
|
|
59034
|
+
readOnlyMounts: Object.freeze([
|
|
59035
|
+
...recipe.installedSupport.runtimeMounts,
|
|
59036
|
+
{ source: "/etc/resolv.conf", destination: "/etc/resolv.conf" },
|
|
59037
|
+
...acp === undefined ? [{
|
|
59038
|
+
source: recipe.installedSupport.agentWorkerPath,
|
|
59039
|
+
destination: recipe.installedSupport.sandboxAgentWorkerPath
|
|
59040
|
+
}] : [
|
|
59041
|
+
{ source: acp.adapterPath, destination: acp.sandboxAdapterPath },
|
|
59042
|
+
{ source: acp.executablePath, destination: acp.sandboxExecutablePath },
|
|
59043
|
+
...acp.readOnlyMounts
|
|
59044
|
+
]
|
|
59045
|
+
]),
|
|
59046
|
+
command: Object.freeze(acp === undefined ? [
|
|
59047
|
+
recipe.sandboxExecutablePath,
|
|
59048
|
+
...recipe.bunPolicy,
|
|
59049
|
+
recipe.installedSupport.sandboxAgentWorkerPath
|
|
59050
|
+
] : [recipe.sandboxExecutablePath, ...recipe.bunPolicy, acp.sandboxAdapterPath]),
|
|
59051
|
+
...acp === undefined ? {} : { environment: acp.environment },
|
|
59052
|
+
network: "inherited",
|
|
59053
|
+
...acp?.nestedUserNamespaces === true ? { nestedUserNamespaces: true } : {}
|
|
59054
|
+
});
|
|
59055
|
+
}
|
|
59056
|
+
async function interactWithProvider(component, provider, prepared, signal) {
|
|
59057
|
+
if (provider.kind === "private-acp-agent-provider/1") {
|
|
59058
|
+
return await interactWithAcpProvider(component, provider, prepared, signal);
|
|
59059
|
+
}
|
|
59060
|
+
return await interactWithOpenAIProvider(component, provider, prepared);
|
|
59061
|
+
}
|
|
59062
|
+
async function interactWithOpenAIProvider(component, provider, prepared) {
|
|
59063
|
+
const output = collectBounded3(component.stdout, PRIVATE_OPENAI_AGENT_RESPONSE_BYTES);
|
|
59064
|
+
const stderr = discardBounded(component.stderr, PROVIDER_STDERR_BYTES);
|
|
59065
|
+
try {
|
|
59066
|
+
await component.write(encodePrivateOpenAIAgentRequest({
|
|
59067
|
+
protocol: PRIVATE_OPENAI_AGENT_PROTOCOL,
|
|
59068
|
+
apiKey: privateOpenAIAgentCredential(provider),
|
|
59069
|
+
api: provider.api,
|
|
59070
|
+
baseURL: provider.baseURL,
|
|
59071
|
+
model: provider.model,
|
|
59072
|
+
instructions: prepared.instructions,
|
|
59073
|
+
...prepared.responseSchema === undefined ? {} : {
|
|
59074
|
+
responseSchema: prepared.responseSchema
|
|
59075
|
+
}
|
|
59076
|
+
}));
|
|
59077
|
+
await component.closeInput();
|
|
59078
|
+
const [bytes, fence] = await Promise.all([output, component.enforcement, stderr]).then(([bytes2, fence2]) => [bytes2, fence2]);
|
|
59079
|
+
let response;
|
|
59080
|
+
try {
|
|
59081
|
+
response = decodePrivateOpenAIAgentResponse(bytes);
|
|
59082
|
+
} catch {
|
|
59083
|
+
return Object.freeze({
|
|
59084
|
+
fence,
|
|
59085
|
+
failure: "AGENT_PROVIDER_RESPONSE_INVALID",
|
|
59086
|
+
cancelled: false
|
|
59087
|
+
});
|
|
59088
|
+
}
|
|
59089
|
+
return response.status === "error" ? Object.freeze({ fence, failure: response.code, cancelled: false }) : Object.freeze({ fence, value: response.value, cancelled: false });
|
|
59090
|
+
} catch (error49) {
|
|
59091
|
+
await component.terminate().catch(() => {
|
|
59092
|
+
return;
|
|
59093
|
+
});
|
|
59094
|
+
await Promise.allSettled([output, stderr, component.enforcement]);
|
|
59095
|
+
throw error49;
|
|
59096
|
+
}
|
|
59097
|
+
}
|
|
59098
|
+
async function interactWithAcpProvider(component, provider, prepared, signal) {
|
|
59099
|
+
const runtime = privateAcpAgentRuntime(provider);
|
|
59100
|
+
const stderr = discardBounded(component.stderr, PROVIDER_STDERR_BYTES);
|
|
59101
|
+
try {
|
|
59102
|
+
if (runtime.startupInput !== undefined) {
|
|
59103
|
+
await component.write(runtime.startupInput());
|
|
59104
|
+
}
|
|
59105
|
+
const turn = await runPrivateAcpTurn(privateAcpComponentStream(component), {
|
|
59106
|
+
cwd: "/work",
|
|
59107
|
+
instructions: prepared.instructions,
|
|
59108
|
+
signal,
|
|
59109
|
+
configuration: runtime.configuration,
|
|
59110
|
+
...runtime.modeId === undefined ? {} : { modeId: runtime.modeId },
|
|
59111
|
+
...runtime.sessionMeta === undefined ? {} : { sessionMeta: runtime.sessionMeta },
|
|
59112
|
+
...runtime.authentication === undefined ? {} : {
|
|
59113
|
+
authentication: {
|
|
59114
|
+
request: runtime.authentication.request,
|
|
59115
|
+
...runtime.authentication.clientAuthCapabilities === undefined ? {} : {
|
|
59116
|
+
clientAuthCapabilities: runtime.authentication.clientAuthCapabilities
|
|
59117
|
+
}
|
|
59118
|
+
}
|
|
59119
|
+
}
|
|
59120
|
+
});
|
|
59121
|
+
await component.closeInput();
|
|
59122
|
+
const [fence] = await Promise.all([component.enforcement, stderr]);
|
|
59123
|
+
if (turn.stopReason === "cancelled") {
|
|
59124
|
+
return Object.freeze({ fence, cancelled: true });
|
|
59125
|
+
}
|
|
59126
|
+
try {
|
|
59127
|
+
return Object.freeze({
|
|
59128
|
+
fence,
|
|
59129
|
+
value: acpResultValue(turn, prepared.responseSchema !== undefined),
|
|
59130
|
+
cancelled: false
|
|
59131
|
+
});
|
|
59132
|
+
} catch {
|
|
59133
|
+
return Object.freeze({
|
|
59134
|
+
fence,
|
|
59135
|
+
failure: "AGENT_PROVIDER_RESPONSE_INVALID",
|
|
59136
|
+
cancelled: false
|
|
59137
|
+
});
|
|
59138
|
+
}
|
|
59139
|
+
} catch (error49) {
|
|
59140
|
+
await component.terminate().catch(() => {
|
|
59141
|
+
return;
|
|
59142
|
+
});
|
|
59143
|
+
await Promise.allSettled([stderr, component.enforcement]);
|
|
59144
|
+
if (error49 instanceof PrivateAcpProtocolError) {
|
|
59145
|
+
throw error49;
|
|
59146
|
+
}
|
|
59147
|
+
throw error49;
|
|
59148
|
+
}
|
|
59149
|
+
}
|
|
59150
|
+
function acpResultValue(turn, structuredRequested) {
|
|
59151
|
+
const outcome = turn.stopReason === "end_turn" ? "completed" : turn.stopReason === "refusal" ? "blocked" : "limit";
|
|
59152
|
+
if (!structuredRequested || outcome !== "completed") {
|
|
59153
|
+
return Object.freeze({ outcome, text: turn.text });
|
|
59154
|
+
}
|
|
59155
|
+
return Object.freeze({
|
|
59156
|
+
outcome,
|
|
59157
|
+
text: turn.text,
|
|
59158
|
+
structured: decodePrivateAcpStructuredText(turn.text)
|
|
59159
|
+
});
|
|
59160
|
+
}
|
|
59161
|
+
function decodePrivateAcpStructuredText(text) {
|
|
59162
|
+
try {
|
|
59163
|
+
return decodeJson1(encoder11.encode(text));
|
|
59164
|
+
} catch (rawError) {
|
|
59165
|
+
const match = /^```json\r?\n([\s\S]*)\r?\n```$/.exec(text.trim());
|
|
59166
|
+
if (match === null)
|
|
59167
|
+
throw rawError;
|
|
59168
|
+
return decodeJson1(encoder11.encode(match[1]));
|
|
59169
|
+
}
|
|
59170
|
+
}
|
|
59171
|
+
async function releaseKnownAgent(input, lifecycleValue, fence) {
|
|
59172
|
+
let lifecycle = lifecycleValue;
|
|
59173
|
+
const sandbox = parseSandbox(lifecycle);
|
|
59174
|
+
lifecycle = await recordPrivateRootChildFence({
|
|
59175
|
+
coordinator: input.coordinator,
|
|
59176
|
+
projectRoot: input.projectRoot,
|
|
59177
|
+
parentRunId: lifecycle.parentRunId,
|
|
59178
|
+
...lifecycle.parentOperationId === undefined ? {} : { parentOperationId: lifecycle.parentOperationId },
|
|
59179
|
+
operationId: lifecycle.operationId,
|
|
59180
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
59181
|
+
sandboxDigest: lifecycle.sandbox.digest,
|
|
59182
|
+
fence
|
|
59183
|
+
});
|
|
59184
|
+
const ownerRelease = await releasePrivateLinuxOwnerState(sandbox.owner, fence);
|
|
59185
|
+
const cleanup = agentCleanup(ownerRelease);
|
|
59186
|
+
lifecycle = await recordPrivateRootChildCleanup({
|
|
59187
|
+
coordinator: input.coordinator,
|
|
59188
|
+
projectRoot: input.projectRoot,
|
|
59189
|
+
parentRunId: lifecycle.parentRunId,
|
|
59190
|
+
...lifecycle.parentOperationId === undefined ? {} : { parentOperationId: lifecycle.parentOperationId },
|
|
59191
|
+
operationId: lifecycle.operationId,
|
|
59192
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
59193
|
+
sandboxDigest: lifecycle.sandbox.digest,
|
|
59194
|
+
fenceDigest: lifecycle.fence.digest,
|
|
59195
|
+
cleanup
|
|
59196
|
+
});
|
|
59197
|
+
await closePrivateRootChildOwner({
|
|
59198
|
+
coordinator: input.coordinator,
|
|
59199
|
+
projectRoot: input.projectRoot,
|
|
59200
|
+
parentRunId: lifecycle.parentRunId,
|
|
59201
|
+
...lifecycle.parentOperationId === undefined ? {} : { parentOperationId: lifecycle.parentOperationId },
|
|
59202
|
+
operationId: lifecycle.operationId,
|
|
59203
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
59204
|
+
sandboxDigest: lifecycle.sandbox.digest,
|
|
59205
|
+
fenceDigest: lifecycle.fence.digest,
|
|
59206
|
+
cleanupDigest: lifecycle.cleanup.digest
|
|
59207
|
+
});
|
|
59208
|
+
}
|
|
59209
|
+
async function findLifecycle(input, operationId) {
|
|
59210
|
+
return (await listPrivateRootChildOwners({
|
|
59211
|
+
coordinator: input.coordinator,
|
|
59212
|
+
projectRoot: input.projectRoot,
|
|
59213
|
+
parentRunId: input.parent.run.runId
|
|
59214
|
+
})).find((item) => item.operationId === operationId && item.parentOperationId === input.parentFlow?.operationId);
|
|
59215
|
+
}
|
|
59216
|
+
function parseAllocation2(lifecycle) {
|
|
59217
|
+
const value = exactObject4(lifecycle.allocation.value, [
|
|
59218
|
+
"kind",
|
|
59219
|
+
"parentRunId",
|
|
59220
|
+
"coordinatorEpoch",
|
|
59221
|
+
"operationId",
|
|
59222
|
+
"parentRequestDigest",
|
|
59223
|
+
"parentFlow",
|
|
59224
|
+
"requestDigest",
|
|
59225
|
+
"providerDigest",
|
|
59226
|
+
"effectiveDeadlineUnixMs",
|
|
59227
|
+
"ownerAllocation"
|
|
59228
|
+
], "Agent allocation");
|
|
59229
|
+
if (value.kind !== ALLOCATION_KIND2 || value.parentRunId !== lifecycle.parentRunId || value.operationId !== lifecycle.operationId || typeof value.coordinatorEpoch !== "number" || !Number.isSafeInteger(value.coordinatorEpoch) || value.coordinatorEpoch < 1 || !isDigest(value.parentRequestDigest) || !isDigest(value.requestDigest) || !isDigest(value.providerDigest) || typeof value.effectiveDeadlineUnixMs !== "number" || !Number.isSafeInteger(value.effectiveDeadlineUnixMs) || value.effectiveDeadlineUnixMs < 0) {
|
|
59230
|
+
throw new TypeError("Agent allocation is invalid");
|
|
59231
|
+
}
|
|
59232
|
+
return Object.freeze({
|
|
59233
|
+
kind: ALLOCATION_KIND2,
|
|
59234
|
+
parentRunId: value.parentRunId,
|
|
59235
|
+
coordinatorEpoch: value.coordinatorEpoch,
|
|
59236
|
+
operationId: value.operationId,
|
|
59237
|
+
parentRequestDigest: value.parentRequestDigest,
|
|
59238
|
+
parentFlow: normalizeParentFlow(value.parentFlow, lifecycle.parentOperationId),
|
|
59239
|
+
requestDigest: value.requestDigest,
|
|
59240
|
+
providerDigest: value.providerDigest,
|
|
59241
|
+
effectiveDeadlineUnixMs: value.effectiveDeadlineUnixMs,
|
|
59242
|
+
ownerAllocation: normalizePrivateLinuxOwnerStateAllocationIdentity(value.ownerAllocation)
|
|
59243
|
+
});
|
|
59244
|
+
}
|
|
59245
|
+
function parseSandbox(lifecycle) {
|
|
59246
|
+
if (lifecycle.sandbox === undefined)
|
|
59247
|
+
throw new TypeError("Agent sandbox owner is absent");
|
|
59248
|
+
const value = exactObject4(lifecycle.sandbox.value, ["kind", "owner"], "Agent sandbox");
|
|
59249
|
+
if (value.kind !== SANDBOX_KIND)
|
|
59250
|
+
throw new TypeError("Agent sandbox kind is invalid");
|
|
59251
|
+
return Object.freeze({
|
|
59252
|
+
kind: SANDBOX_KIND,
|
|
59253
|
+
owner: normalizePrivateLinuxSealedOwnerIdentity(value.owner)
|
|
59254
|
+
});
|
|
59255
|
+
}
|
|
59256
|
+
function parseFence(lifecycle) {
|
|
59257
|
+
if (lifecycle.fence === undefined)
|
|
59258
|
+
throw new TypeError("Agent fence is absent");
|
|
59259
|
+
return normalizePrivateLinuxConfirmedEnforcementReceipt(lifecycle.fence.value);
|
|
59260
|
+
}
|
|
59261
|
+
function agentCleanup(ownerRelease) {
|
|
59262
|
+
return Object.freeze({ kind: CLEANUP_KIND, ownerRelease });
|
|
59263
|
+
}
|
|
59264
|
+
function parseCleanup(lifecycle) {
|
|
59265
|
+
if (lifecycle.cleanup === undefined)
|
|
59266
|
+
throw new TypeError("Agent cleanup is absent");
|
|
59267
|
+
const value = exactObject4(lifecycle.cleanup.value, ["kind", "ownerRelease"], "Agent cleanup");
|
|
59268
|
+
if (value.kind !== CLEANUP_KIND)
|
|
59269
|
+
throw new TypeError("Agent cleanup kind is invalid");
|
|
59270
|
+
return agentCleanup(normalizePrivateLinuxOwnerStateReleaseReceipt(value.ownerRelease));
|
|
59271
|
+
}
|
|
59272
|
+
function requireCleanupMatches(lifecycle, expected) {
|
|
59273
|
+
const actual = parseCleanup(lifecycle);
|
|
59274
|
+
if (actual.ownerRelease.digest !== expected.ownerRelease.digest) {
|
|
59275
|
+
throw new Error("durable Agent cleanup differs from the released owner");
|
|
59276
|
+
}
|
|
59277
|
+
}
|
|
59278
|
+
async function requireAllocationMatchesParent(input, lifecycle, allocation) {
|
|
59279
|
+
const { parentFlow: requestedParentFlow, ...rootInput } = input;
|
|
59280
|
+
const parentFlow = allocation.parentFlow;
|
|
59281
|
+
if (requestedParentFlow !== undefined && (parentFlow === null || requestedParentFlow.operationId !== parentFlow.operationId || requestedParentFlow.requestDigest !== parentFlow.requestDigest)) {
|
|
59282
|
+
throw new Error("durable Agent allocation differs from the requested parent Flow");
|
|
59283
|
+
}
|
|
59284
|
+
const target = requireParentTarget({
|
|
59285
|
+
...rootInput,
|
|
59286
|
+
...parentFlow === null ? {} : { parentFlow }
|
|
59287
|
+
});
|
|
59288
|
+
if (allocation.parentRunId !== input.parent.run.runId || allocation.coordinatorEpoch !== input.parent.run.coordinatorEpoch || allocation.operationId !== lifecycle.operationId || allocation.parentRequestDigest !== target.request.digest || allocation.effectiveDeadlineUnixMs > input.parent.intent.deadlineUnixMs || Object.values(target.request.capabilities).length !== 1 || Object.values(target.request.capabilities)[0]?.digest !== AGENT_RUN_CONTRACT_DIGEST) {
|
|
59289
|
+
throw new Error("durable Agent allocation differs from its admitted parent or provider");
|
|
59290
|
+
}
|
|
59291
|
+
if (parentFlow !== null) {
|
|
59292
|
+
await requireParentFlowOwner(input, parentFlow, allocation.effectiveDeadlineUnixMs);
|
|
59293
|
+
}
|
|
59294
|
+
const ownerParent = await protectedOwnerRoot(input.projectRoot);
|
|
59295
|
+
const identity2 = agentIdentity(lifecycle.parentRunId, lifecycle.operationId, lifecycle.parentOperationId);
|
|
59296
|
+
if (allocation.ownerAllocation.parent !== ownerParent || allocation.ownerAllocation.name !== `a-${identity2.slice(0, 62)}`) {
|
|
59297
|
+
throw new Error("durable Agent allocation differs from its admitted owner resource");
|
|
59298
|
+
}
|
|
59299
|
+
}
|
|
59300
|
+
async function requireParentFlowOwner(input, parentFlow, deadlineUnixMs) {
|
|
59301
|
+
const owners = await listPrivateRootChildOwners({
|
|
59302
|
+
coordinator: input.coordinator,
|
|
59303
|
+
projectRoot: input.projectRoot,
|
|
59304
|
+
parentRunId: input.parent.run.runId
|
|
59305
|
+
});
|
|
59306
|
+
const parent = owners.find((owner) => owner.parentOperationId === undefined && owner.operationId === parentFlow.operationId);
|
|
59307
|
+
const allocation = parent?.allocation.value;
|
|
59308
|
+
if (allocation === null || typeof allocation !== "object" || Array.isArray(allocation) || allocation.kind !== "private-root-child-owner-allocation/1" || allocation.parentRunId !== input.parent.run.runId || allocation.coordinatorEpoch !== input.parent.run.coordinatorEpoch || allocation.operationId !== parentFlow.operationId || allocation.requestDigest !== parentFlow.requestDigest || typeof allocation.effectiveDeadlineUnixMs !== "number" || !Number.isSafeInteger(allocation.effectiveDeadlineUnixMs) || allocation.effectiveDeadlineUnixMs > input.parent.intent.deadlineUnixMs || allocation.effectiveDeadlineUnixMs < deadlineUnixMs || parent?.sandbox === undefined) {
|
|
59309
|
+
throw new Error("Agent parent Flow differs from its durable execution owner");
|
|
59310
|
+
}
|
|
59311
|
+
}
|
|
59312
|
+
function normalizeParentFlow(value, parentOperationId) {
|
|
59313
|
+
if (parentOperationId === undefined) {
|
|
59314
|
+
if (value !== null)
|
|
59315
|
+
throw new TypeError("root Agent allocation has a nested parent");
|
|
59316
|
+
return null;
|
|
59317
|
+
}
|
|
59318
|
+
const parent = exactObject4(value, ["operationId", "target", "requestDigest"], "Agent parent Flow");
|
|
59319
|
+
if (parent.operationId !== parentOperationId || !isDigest(parent.requestDigest)) {
|
|
59320
|
+
throw new TypeError("Agent parent Flow identity is invalid");
|
|
59321
|
+
}
|
|
59322
|
+
const target = exactObject4(parent.target, parent.target?.kind === "flow" ? ["kind", "path"] : ["kind", "id"], "Agent parent Flow target");
|
|
59323
|
+
let identity2;
|
|
59324
|
+
if (target.kind === "flow" && typeof target.path === "string") {
|
|
59325
|
+
validateProjectPath(target.path, "Agent parent Flow target");
|
|
59326
|
+
identity2 = Object.freeze({ kind: "flow", path: target.path });
|
|
59327
|
+
} else if (target.kind === "binding" && typeof target.id === "string" && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(target.id)) {
|
|
59328
|
+
identity2 = Object.freeze({ kind: "binding", id: target.id });
|
|
59329
|
+
} else {
|
|
59330
|
+
throw new TypeError("Agent parent Flow target is invalid");
|
|
59331
|
+
}
|
|
59332
|
+
return Object.freeze({ operationId: parentOperationId, target: identity2, requestDigest: parent.requestDigest });
|
|
59333
|
+
}
|
|
59334
|
+
function providerFailure(code) {
|
|
59335
|
+
if (code === "AGENT_PROVIDER_OUTPUT_LIMIT") {
|
|
59336
|
+
return failed("RESOURCE_EXHAUSTED", "the Agent provider result exceeded its fixed bound");
|
|
59337
|
+
}
|
|
59338
|
+
if (code === "AGENT_PROVIDER_RESPONSE_INVALID") {
|
|
59339
|
+
return failed("INVALID_RESULT", "the Agent provider returned an invalid result");
|
|
59340
|
+
}
|
|
59341
|
+
return failed("EXECUTION_FAILED", "the Agent provider request failed");
|
|
59342
|
+
}
|
|
59343
|
+
async function collectBounded3(source, maximum) {
|
|
59344
|
+
const chunks = [];
|
|
59345
|
+
let total = 0;
|
|
59346
|
+
for await (const chunk of source) {
|
|
59347
|
+
total += chunk.byteLength;
|
|
59348
|
+
if (total > maximum)
|
|
59349
|
+
throw new Error("Agent provider output exceeds its byte bound");
|
|
59350
|
+
chunks.push(Uint8Array.from(chunk));
|
|
59351
|
+
}
|
|
59352
|
+
const output = new Uint8Array(total);
|
|
59353
|
+
let offset = 0;
|
|
59354
|
+
for (const chunk of chunks) {
|
|
59355
|
+
output.set(chunk, offset);
|
|
59356
|
+
offset += chunk.byteLength;
|
|
59357
|
+
}
|
|
59358
|
+
return output;
|
|
59359
|
+
}
|
|
59360
|
+
async function discardBounded(source, maximum) {
|
|
59361
|
+
let total = 0;
|
|
59362
|
+
for await (const chunk of source) {
|
|
59363
|
+
total += chunk.byteLength;
|
|
59364
|
+
if (total > maximum)
|
|
59365
|
+
throw new Error("Agent provider diagnostics exceed their byte bound");
|
|
59366
|
+
}
|
|
59367
|
+
}
|
|
59368
|
+
async function cancelUnusedAllocation(allocation) {
|
|
59369
|
+
const cancelled = await cancelPrivateLinuxOwnerStateAllocation(allocation);
|
|
59370
|
+
await releasePrivateLinuxOwnerState(allocation, cancelled);
|
|
59371
|
+
}
|
|
59372
|
+
function exactObject4(value, fields, label) {
|
|
59373
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
59374
|
+
throw new TypeError(`${label} must be an object`);
|
|
59375
|
+
}
|
|
59376
|
+
const record3 = value;
|
|
59377
|
+
const actual = Object.keys(record3).sort();
|
|
59378
|
+
const expected = [...fields].sort();
|
|
59379
|
+
if (actual.length !== expected.length || actual.some((field, index) => field !== expected[index])) {
|
|
59380
|
+
throw new TypeError(`${label} must contain exactly ${expected.join(", ")}`);
|
|
59381
|
+
}
|
|
59382
|
+
return record3;
|
|
59383
|
+
}
|
|
59384
|
+
function agentIdentity(parentRunId, operationId, parentOperationId) {
|
|
59385
|
+
return privateDomainDigest("JIG-Private-Root-Agent-Identity/1", {
|
|
59386
|
+
parentRunId,
|
|
59387
|
+
parentOperationId: parentOperationId ?? null,
|
|
59388
|
+
operationId
|
|
59389
|
+
}).slice("sha256:".length);
|
|
59390
|
+
}
|
|
59391
|
+
async function protectedOwnerRoot(projectRoot) {
|
|
59392
|
+
const state2 = await realpath11(join11(projectRoot, ".jig"));
|
|
59393
|
+
const owners = join11(state2, "private-root-linux-owners");
|
|
59394
|
+
await mkdir8(owners, { mode: 448 }).catch((error49) => {
|
|
59395
|
+
if (!hasCode6(error49, "EEXIST"))
|
|
59396
|
+
throw error49;
|
|
59397
|
+
});
|
|
59398
|
+
const information = await lstat16(owners);
|
|
59399
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
59400
|
+
if (!information.isDirectory() || information.isSymbolicLink() || information.uid !== uid || (information.mode & 63) !== 0 || await realpath11(owners) !== owners) {
|
|
59401
|
+
throw new Error("Agent execution owner directory is not protected");
|
|
59402
|
+
}
|
|
59403
|
+
return owners;
|
|
59404
|
+
}
|
|
59405
|
+
function isDigest(value) {
|
|
59406
|
+
return typeof value === "string" && DIGEST11.test(value);
|
|
59407
|
+
}
|
|
59408
|
+
function failed(code, message, details) {
|
|
59409
|
+
return Object.freeze({
|
|
59410
|
+
status: "failed",
|
|
59411
|
+
code,
|
|
59412
|
+
message,
|
|
59413
|
+
...details === undefined ? {} : { details }
|
|
59414
|
+
});
|
|
59415
|
+
}
|
|
59416
|
+
function hasCode6(error49, code) {
|
|
59417
|
+
return error49 !== null && typeof error49 === "object" && error49.code === code;
|
|
59418
|
+
}
|
|
59419
|
+
|
|
59420
|
+
class AgentInstructionLimitError extends Error {
|
|
59421
|
+
}
|
|
59422
|
+
|
|
59423
|
+
// src/internal/root-flow-call-controller.ts
|
|
59424
|
+
var ALLOCATION_KIND3 = "private-root-child-owner-allocation/1";
|
|
59425
|
+
var SANDBOX_KIND2 = "private-root-child-sandbox/1";
|
|
59426
|
+
var CLEANUP_KIND2 = "private-root-child-cleanup/1";
|
|
59427
|
+
var CANCELLATION_GRACE_MS2 = 1000;
|
|
59428
|
+
async function executePrivateRootFlowCall(input) {
|
|
59429
|
+
const selected = selectChild(input.parent, input.call.slot);
|
|
59430
|
+
if (selected === undefined) {
|
|
59431
|
+
return failed2("UNAVAILABLE", "the requested slot has no admitted child Flow");
|
|
59432
|
+
}
|
|
59433
|
+
if (selected.disposition.state !== "ready") {
|
|
59434
|
+
return failed2("UNAVAILABLE", "the admitted child Flow is unavailable on this host");
|
|
59435
|
+
}
|
|
59436
|
+
if (input.signal.aborted)
|
|
59437
|
+
return failed2("CANCELLED", "the child Flow call was cancelled");
|
|
59438
|
+
const invalidInput = await validateChildInput(input.packageStoreRoot, selected.request.package, input.call.input);
|
|
59439
|
+
if (invalidInput !== undefined)
|
|
59440
|
+
return invalidInput;
|
|
59441
|
+
let recipe;
|
|
59442
|
+
try {
|
|
59443
|
+
recipe = await planPrivateDirectRun({
|
|
59444
|
+
request: selected.request,
|
|
59445
|
+
executionPackage: selected.disposition.executionPackage,
|
|
59446
|
+
installedSupport: input.installedSupport,
|
|
59447
|
+
backend: input.backend,
|
|
59448
|
+
agentProvider: input.agentProvider
|
|
59449
|
+
});
|
|
59450
|
+
} catch {
|
|
59451
|
+
return failed2("UNAVAILABLE", "the admitted child recipe cannot be reproduced");
|
|
59452
|
+
}
|
|
59453
|
+
if (recipe.digest !== selected.disposition.recipeDigest || recipe.observation.digest !== selected.disposition.observationDigest) {
|
|
59454
|
+
return failed2("UNAVAILABLE", "the admitted child recipe cannot be reproduced");
|
|
59455
|
+
}
|
|
59456
|
+
const effectiveDeadlineUnixMs = Math.min(input.parentDeadlineUnixMs, input.parent.intent.deadlineUnixMs, Date.now() + recipe.wallClockCeilingMs);
|
|
59457
|
+
if (Date.now() >= effectiveDeadlineUnixMs) {
|
|
59458
|
+
return failed2("DEADLINE_EXCEEDED", "the child Flow deadline elapsed before dispatch");
|
|
59459
|
+
}
|
|
59460
|
+
const existing = (await listPrivateRootChildOwners({
|
|
59461
|
+
coordinator: input.coordinator,
|
|
59462
|
+
projectRoot: input.projectRoot,
|
|
59463
|
+
parentRunId: input.parent.run.runId
|
|
59464
|
+
})).find(({ operationId, parentOperationId }) => parentOperationId === undefined && operationId === input.call.operationId);
|
|
59465
|
+
if (existing !== undefined) {
|
|
59466
|
+
await recoverOne(input, existing);
|
|
59467
|
+
return failed2("UNCERTAIN", "a prior child dispatch was fenced without a proved result");
|
|
59468
|
+
}
|
|
59469
|
+
const roots = await protectedWorkRoots(input.projectRoot);
|
|
59470
|
+
const identity2 = childIdentity(input.parent.run.runId, input.call.operationId);
|
|
59471
|
+
const [packageAllocation, ownerAllocation] = await Promise.all([
|
|
59472
|
+
allocatePrivatePackageMaterialization({
|
|
59473
|
+
protectedParent: roots.materializations,
|
|
59474
|
+
name: `child-${identity2.slice(0, 48)}`,
|
|
59475
|
+
packageDigest: recipe.executionPackage.digest,
|
|
59476
|
+
ownerToken: `sha256:${identity2}`
|
|
59477
|
+
}),
|
|
59478
|
+
planPrivateLinuxOwnerStateAllocation({
|
|
59479
|
+
parent: roots.owners,
|
|
59480
|
+
name: `c-${identity2.slice(0, 47)}`
|
|
59481
|
+
})
|
|
59482
|
+
]);
|
|
59483
|
+
const allocation = Object.freeze({
|
|
59484
|
+
kind: ALLOCATION_KIND3,
|
|
59485
|
+
parentRunId: input.parent.run.runId,
|
|
59486
|
+
coordinatorEpoch: input.parent.run.coordinatorEpoch,
|
|
59487
|
+
operationId: input.call.operationId,
|
|
59488
|
+
requestDigest: selected.request.digest,
|
|
59489
|
+
effectiveDeadlineUnixMs,
|
|
59490
|
+
packageAllocation,
|
|
59491
|
+
ownerAllocation
|
|
59492
|
+
});
|
|
59493
|
+
let lifecycle;
|
|
59494
|
+
try {
|
|
59495
|
+
lifecycle = await allocatePrivateRootChildOwner({
|
|
59496
|
+
coordinator: input.coordinator,
|
|
59497
|
+
projectRoot: input.projectRoot,
|
|
59498
|
+
parentRunId: input.parent.run.runId,
|
|
59499
|
+
operationId: input.call.operationId,
|
|
59500
|
+
allocation
|
|
59501
|
+
});
|
|
59502
|
+
} catch (error49) {
|
|
59503
|
+
if (error49 instanceof CheckError && error49.code === "RUN_CHILD_CAPACITY") {
|
|
59504
|
+
return failed2("RESOURCE_EXHAUSTED", "the parent Run already has an active child operation");
|
|
59505
|
+
}
|
|
59506
|
+
throw error49;
|
|
59507
|
+
}
|
|
59508
|
+
let attemptedDispatch = false;
|
|
59509
|
+
try {
|
|
59510
|
+
const lease = await materializeChild(input.packageStoreRoot, recipe, packageAllocation);
|
|
59511
|
+
await revalidateRecipe(recipe);
|
|
59512
|
+
const sealed = await input.backend.seal(backendPlan2(recipe, lease.root, identity2, effectiveDeadlineUnixMs), ownerAllocation);
|
|
59513
|
+
const sandbox = Object.freeze({ kind: SANDBOX_KIND2, owner: sealed.identity });
|
|
59514
|
+
lifecycle = await recordPrivateRootChildSandbox({
|
|
59515
|
+
coordinator: input.coordinator,
|
|
59516
|
+
projectRoot: input.projectRoot,
|
|
59517
|
+
parentRunId: input.parent.run.runId,
|
|
59518
|
+
operationId: input.call.operationId,
|
|
59519
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
59520
|
+
sandbox
|
|
59521
|
+
});
|
|
59522
|
+
const startup = startupSignal(input.signal);
|
|
59523
|
+
let component;
|
|
59524
|
+
try {
|
|
59525
|
+
attemptedDispatch = true;
|
|
59526
|
+
component = await sealed.admit(startup.signal);
|
|
59527
|
+
} finally {
|
|
59528
|
+
startup.dispose();
|
|
59529
|
+
}
|
|
59530
|
+
const provisional = await new RunHostSession(component, {
|
|
59531
|
+
input: input.call.input,
|
|
59532
|
+
settings: selected.request.settings,
|
|
59533
|
+
attachments: Object.freeze({}),
|
|
59534
|
+
scratch: recipe.scratch,
|
|
59535
|
+
deadlineUnixMs: effectiveDeadlineUnixMs,
|
|
59536
|
+
signal: input.signal
|
|
59537
|
+
}, { cancellationGraceMs: CANCELLATION_GRACE_MS2 }, specialistDispatcher(input, selected, effectiveDeadlineUnixMs)).run();
|
|
59538
|
+
const fence = await component.enforcement;
|
|
59539
|
+
await releaseKnownChild(input, lifecycle, lease, fence);
|
|
59540
|
+
return await admitOperationResult(input.packageStoreRoot, selected.request.package, provisional);
|
|
59541
|
+
} catch (error49) {
|
|
59542
|
+
try {
|
|
59543
|
+
const active = await findLifecycle2(input, input.call.operationId);
|
|
59544
|
+
if (active !== undefined)
|
|
59545
|
+
await recoverOne(input, active);
|
|
59546
|
+
} catch (cleanupError) {
|
|
59547
|
+
if (attemptedDispatch && cleanupError instanceof PrivateLinuxFenceUnconfirmedError) {
|
|
59548
|
+
return failed2("UNCERTAIN", "child dispatch may have occurred but its fence is not yet confirmed");
|
|
59549
|
+
}
|
|
59550
|
+
throw new AggregateError([error49, cleanupError], "child Flow execution and cleanup failed");
|
|
59551
|
+
}
|
|
59552
|
+
if (input.signal.aborted)
|
|
59553
|
+
return failed2("CANCELLED", "the child Flow call was cancelled");
|
|
59554
|
+
if (Date.now() >= effectiveDeadlineUnixMs) {
|
|
59555
|
+
return failed2("DEADLINE_EXCEEDED", "the child Flow deadline elapsed");
|
|
59556
|
+
}
|
|
59557
|
+
return attemptedDispatch ? failed2("UNCERTAIN", "child dispatch may have occurred but no result was proved") : failed2("EXECUTION_FAILED", "child Flow execution failed before dispatch");
|
|
59558
|
+
}
|
|
59559
|
+
}
|
|
59560
|
+
async function recoverPrivateRootFlowCallOwners(input) {
|
|
59561
|
+
const owners = await listPrivateRootChildOwners({
|
|
59562
|
+
coordinator: input.coordinator,
|
|
59563
|
+
projectRoot: input.projectRoot,
|
|
59564
|
+
parentRunId: input.parent.run.runId
|
|
59565
|
+
});
|
|
59566
|
+
for (const owner of owners) {
|
|
59567
|
+
if (isPrivateRootFlowCallOwner(owner))
|
|
59568
|
+
await recoverOne(input, owner);
|
|
59569
|
+
}
|
|
59570
|
+
}
|
|
59571
|
+
function isPrivateRootFlowCallOwner(lifecycle) {
|
|
59572
|
+
const value = lifecycle.allocation.value;
|
|
59573
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && lifecycle.parentOperationId === undefined && value.kind === ALLOCATION_KIND3;
|
|
59574
|
+
}
|
|
59575
|
+
function selectChild(parent, slot) {
|
|
59576
|
+
const parentTarget = findPrivateActivationCandidateTargetV5(parent.candidate, parent.run.target);
|
|
59577
|
+
if (parentTarget === undefined || parentTarget.request.digest !== parent.intent.requestDigest) {
|
|
59578
|
+
throw new Error("parent Run differs from its admitted target");
|
|
59579
|
+
}
|
|
59580
|
+
const target = parentTarget.request.flowSlots[slot];
|
|
59581
|
+
if (target === undefined)
|
|
59582
|
+
return;
|
|
59583
|
+
const child = findPrivateActivationCandidateTargetV5(parent.candidate, target);
|
|
59584
|
+
if (child === undefined || Object.keys(child.request.flowSlots).length !== 0) {
|
|
59585
|
+
throw new Error("admitted Flow slot does not name one leaf child target");
|
|
59586
|
+
}
|
|
59587
|
+
return child;
|
|
59588
|
+
}
|
|
59589
|
+
function specialistDispatcher(input, selected, parentDeadlineUnixMs) {
|
|
59590
|
+
if (Object.keys(selected.request.capabilities).length === 0)
|
|
59591
|
+
return;
|
|
59592
|
+
let active = false;
|
|
59593
|
+
return {
|
|
59594
|
+
async callEffect(call, signal) {
|
|
59595
|
+
if (input.agentProvider === undefined) {
|
|
59596
|
+
return failed2("UNAVAILABLE", "the admitted Agent provider is unavailable");
|
|
59597
|
+
}
|
|
59598
|
+
if (active)
|
|
59599
|
+
return failed2("RESOURCE_EXHAUSTED", "the specialist already has an active Agent operation");
|
|
59600
|
+
active = true;
|
|
59601
|
+
try {
|
|
59602
|
+
return await executePrivateRootAgentRun({
|
|
59603
|
+
...input,
|
|
59604
|
+
agentProvider: input.agentProvider,
|
|
59605
|
+
parentFlow: {
|
|
59606
|
+
operationId: input.call.operationId,
|
|
59607
|
+
target: selected.request.target,
|
|
59608
|
+
requestDigest: selected.request.digest
|
|
59609
|
+
},
|
|
59610
|
+
call,
|
|
59611
|
+
parentDeadlineUnixMs,
|
|
59612
|
+
signal
|
|
59613
|
+
});
|
|
59614
|
+
} finally {
|
|
59615
|
+
active = false;
|
|
59616
|
+
}
|
|
59617
|
+
}
|
|
59618
|
+
};
|
|
59619
|
+
}
|
|
59620
|
+
async function validateChildInput(store, reference, value) {
|
|
59621
|
+
const captured = await captureStoredPackage(store, reference);
|
|
59622
|
+
try {
|
|
59623
|
+
const inspected = await inspectCapturedPackage(captured);
|
|
59624
|
+
try {
|
|
59625
|
+
inspected.schemas.input?.validate(value, "INVALID_INPUT");
|
|
59626
|
+
} catch (error49) {
|
|
59627
|
+
if (!(error49 instanceof SchemaDiagnostic))
|
|
59628
|
+
throw error49;
|
|
59629
|
+
return failed2("INVALID_INPUT", "child Flow input does not satisfy its declared schema");
|
|
59630
|
+
}
|
|
59631
|
+
return;
|
|
59632
|
+
} finally {
|
|
59633
|
+
await captured.dispose();
|
|
59634
|
+
}
|
|
59635
|
+
}
|
|
59636
|
+
async function admitOperationResult(store, reference, provisional) {
|
|
59637
|
+
let admitted = provisional;
|
|
59638
|
+
if (provisional.status === "succeeded") {
|
|
59639
|
+
const captured = await captureStoredPackage(store, reference);
|
|
59640
|
+
try {
|
|
59641
|
+
admitted = admitPrivatePackageResult(await inspectCapturedPackage(captured), provisional);
|
|
59642
|
+
} finally {
|
|
59643
|
+
await captured.dispose();
|
|
59644
|
+
}
|
|
59645
|
+
}
|
|
59646
|
+
if (admitted.status === "succeeded") {
|
|
59647
|
+
return Object.freeze({ status: "succeeded", result: admitted.result });
|
|
59648
|
+
}
|
|
59649
|
+
if (admitted.code === "PROTOCOL_ERROR" || admitted.code === "CHANNEL_LOST") {
|
|
59650
|
+
return failed2("EXECUTION_FAILED", "the child Flow execution channel failed");
|
|
59651
|
+
}
|
|
59652
|
+
return failed2(admitted.code, admitted.message, admitted.details);
|
|
59653
|
+
}
|
|
59654
|
+
async function materializeChild(store, recipe, allocation) {
|
|
59655
|
+
const captured = await captureStoredPackage(store, recipe.executionPackage);
|
|
59656
|
+
try {
|
|
59657
|
+
return await materializePrivatePackageLease(captured, allocation);
|
|
59658
|
+
} finally {
|
|
59659
|
+
await captured.dispose();
|
|
59660
|
+
}
|
|
59661
|
+
}
|
|
59662
|
+
async function revalidateRecipe(recipe) {
|
|
59663
|
+
const [mechanism] = await Promise.all([
|
|
59664
|
+
recipe.backend.observeMechanism(),
|
|
59665
|
+
revalidatePrivateInstalledBunSupport(recipe.installedSupport)
|
|
59666
|
+
]);
|
|
59667
|
+
if (mechanism.support.digest !== recipe.mechanismDigest) {
|
|
59668
|
+
throw new Error("child recipe no longer matches retained host support");
|
|
59669
|
+
}
|
|
59670
|
+
}
|
|
59671
|
+
function backendPlan2(recipe, packageRoot, identity2, deadlineUnixMs) {
|
|
59672
|
+
return Object.freeze({
|
|
59673
|
+
runId: `child-${identity2.slice(0, 42)}`,
|
|
59674
|
+
limits: Object.freeze({
|
|
59675
|
+
...recipe.resourceCeilings,
|
|
59676
|
+
deadlineUnixMs,
|
|
59677
|
+
cancellationGraceMs: CANCELLATION_GRACE_MS2
|
|
59678
|
+
}),
|
|
59679
|
+
readOnlyMounts: Object.freeze([
|
|
59680
|
+
...recipe.installedSupport.runtimeMounts,
|
|
59681
|
+
{ source: packageRoot, destination: recipe.packageDestination }
|
|
59682
|
+
]),
|
|
59683
|
+
command: Object.freeze([
|
|
59684
|
+
recipe.sandboxExecutablePath,
|
|
59685
|
+
...recipe.bunPolicy,
|
|
59686
|
+
`${recipe.packageDestination}/${recipe.request.entrypoint.path}`
|
|
59687
|
+
])
|
|
59688
|
+
});
|
|
59689
|
+
}
|
|
59690
|
+
async function releaseKnownChild(input, lifecycleValue, lease, fence) {
|
|
59691
|
+
let lifecycle = lifecycleValue;
|
|
59692
|
+
const selected = await requireAllocationMatchesParent2(input, lifecycle, parseAllocation3(lifecycle));
|
|
59693
|
+
const sandbox = parseSandbox2(lifecycle);
|
|
59694
|
+
lifecycle = await recordPrivateRootChildFence({
|
|
59695
|
+
coordinator: input.coordinator,
|
|
59696
|
+
projectRoot: input.projectRoot,
|
|
59697
|
+
parentRunId: lifecycle.parentRunId,
|
|
59698
|
+
operationId: lifecycle.operationId,
|
|
59699
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
59700
|
+
sandboxDigest: lifecycle.sandbox.digest,
|
|
59701
|
+
fence
|
|
59702
|
+
});
|
|
59703
|
+
await recoverPrivateRootAgentRunOwners({
|
|
59704
|
+
...input,
|
|
59705
|
+
parentFlow: {
|
|
59706
|
+
operationId: lifecycle.operationId,
|
|
59707
|
+
target: selected.request.target,
|
|
59708
|
+
requestDigest: selected.request.digest
|
|
59709
|
+
}
|
|
59710
|
+
});
|
|
59711
|
+
await disposePrivatePackageMaterializationLease(lease.identity.allocation.parent.path, lease.identity);
|
|
59712
|
+
const ownerRelease = await releasePrivateLinuxOwnerState(sandbox.owner, fence);
|
|
59713
|
+
const cleanup = childCleanup(ownerRelease);
|
|
59714
|
+
lifecycle = await recordPrivateRootChildCleanup({
|
|
59715
|
+
coordinator: input.coordinator,
|
|
59716
|
+
projectRoot: input.projectRoot,
|
|
59717
|
+
parentRunId: lifecycle.parentRunId,
|
|
59718
|
+
operationId: lifecycle.operationId,
|
|
59719
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
59720
|
+
sandboxDigest: lifecycle.sandbox.digest,
|
|
59721
|
+
fenceDigest: lifecycle.fence.digest,
|
|
59722
|
+
cleanup
|
|
59723
|
+
});
|
|
59724
|
+
await closePrivateRootChildOwner({
|
|
59725
|
+
coordinator: input.coordinator,
|
|
59726
|
+
projectRoot: input.projectRoot,
|
|
59727
|
+
parentRunId: lifecycle.parentRunId,
|
|
59728
|
+
operationId: lifecycle.operationId,
|
|
59729
|
+
allocationDigest: lifecycle.allocation.digest,
|
|
59730
|
+
sandboxDigest: lifecycle.sandbox.digest,
|
|
59731
|
+
fenceDigest: lifecycle.fence.digest,
|
|
59732
|
+
cleanupDigest: lifecycle.cleanup.digest
|
|
59733
|
+
});
|
|
59734
|
+
}
|
|
59735
|
+
async function recoverOne(input, lifecycle) {
|
|
59189
59736
|
const allocation = parseAllocation3(lifecycle);
|
|
59190
|
-
await requireAllocationMatchesParent2(input, lifecycle, allocation);
|
|
59737
|
+
const selected = await requireAllocationMatchesParent2(input, lifecycle, allocation);
|
|
59191
59738
|
if (lifecycle.sandbox === undefined) {
|
|
59192
59739
|
const cancelled = await cancelPrivateLinuxOwnerStateAllocation(allocation.ownerAllocation);
|
|
59193
59740
|
await releasePrivateLinuxOwnerState(allocation.ownerAllocation, cancelled);
|
|
@@ -59208,8 +59755,19 @@ async function recoverPrivateRootAgentRunOwner(input, lifecycleValue) {
|
|
|
59208
59755
|
} else {
|
|
59209
59756
|
fence = parseFence2(lifecycle);
|
|
59210
59757
|
}
|
|
59758
|
+
await recoverPrivateRootAgentRunOwners({
|
|
59759
|
+
...input,
|
|
59760
|
+
parentFlow: {
|
|
59761
|
+
operationId: lifecycle.operationId,
|
|
59762
|
+
target: selected.request.target,
|
|
59763
|
+
requestDigest: selected.request.digest
|
|
59764
|
+
}
|
|
59765
|
+
});
|
|
59766
|
+
const recovered = await recoverPrivatePackageMaterializationAllocation(allocation.packageAllocation.parent.path, allocation.packageAllocation);
|
|
59767
|
+
if (recovered.state === "complete")
|
|
59768
|
+
await recovered.lease.dispose();
|
|
59211
59769
|
const ownerRelease = await releasePrivateLinuxOwnerState(sandbox.owner, fence);
|
|
59212
|
-
const cleanup =
|
|
59770
|
+
const cleanup = childCleanup(ownerRelease);
|
|
59213
59771
|
if (lifecycle.cleanup === undefined) {
|
|
59214
59772
|
lifecycle = await recordPrivateRootChildCleanup({
|
|
59215
59773
|
coordinator: input.coordinator,
|
|
@@ -59225,6 +59783,11 @@ async function recoverPrivateRootAgentRunOwner(input, lifecycleValue) {
|
|
|
59225
59783
|
requireCleanupMatches2(lifecycle, cleanup);
|
|
59226
59784
|
}
|
|
59227
59785
|
}
|
|
59786
|
+
if (lifecycle.sandbox === undefined) {
|
|
59787
|
+
const recovered = await recoverPrivatePackageMaterializationAllocation(allocation.packageAllocation.parent.path, allocation.packageAllocation);
|
|
59788
|
+
if (recovered.state === "complete")
|
|
59789
|
+
await recovered.lease.dispose();
|
|
59790
|
+
}
|
|
59228
59791
|
await closePrivateRootChildOwner({
|
|
59229
59792
|
coordinator: input.coordinator,
|
|
59230
59793
|
projectRoot: input.projectRoot,
|
|
@@ -59236,312 +59799,12 @@ async function recoverPrivateRootAgentRunOwner(input, lifecycleValue) {
|
|
|
59236
59799
|
cleanupDigest: lifecycle.cleanup?.digest ?? null
|
|
59237
59800
|
});
|
|
59238
59801
|
}
|
|
59239
|
-
function renderPrivateAgentRunInstructions(instructions, manifest) {
|
|
59240
|
-
const skills = manifest.skills.map((skill) => ({
|
|
59241
|
-
name: skill.name,
|
|
59242
|
-
files: skill.files.map((file2) => {
|
|
59243
|
-
let content;
|
|
59244
|
-
try {
|
|
59245
|
-
content = decoder10.decode(file2.bytes());
|
|
59246
|
-
} catch {
|
|
59247
|
-
throw new AgentRunValidationError("AGENT_RUN_SKILL_CONTENT_INVALID", `Agent Run skill file ${skill.name}/${file2.path} is not UTF-8 text`);
|
|
59248
|
-
}
|
|
59249
|
-
return { path: file2.path, content };
|
|
59250
|
-
})
|
|
59251
|
-
}));
|
|
59252
|
-
const payload = decoder10.decode(canonicalJson({ instructions, skills }));
|
|
59253
|
-
const rendered = [
|
|
59254
|
-
"Execute one Jig Agent Run. Treat the author instructions as the task and the selected package-local skill files as guidance.",
|
|
59255
|
-
"The following value is canonical JSON:",
|
|
59256
|
-
payload
|
|
59257
|
-
].join(`
|
|
59258
|
-
`);
|
|
59259
|
-
if (encoder11.encode(rendered).byteLength > PROVIDER_INSTRUCTION_BYTES) {
|
|
59260
|
-
throw new AgentInstructionLimitError;
|
|
59261
|
-
}
|
|
59262
|
-
return rendered;
|
|
59263
|
-
}
|
|
59264
|
-
function renderPrivateAcpStructuredInstructions(instructions, responseSchema) {
|
|
59265
|
-
const schema = decoder10.decode(canonicalJson(projectPrivateAgentResponseSchema(responseSchema)));
|
|
59266
|
-
const rendered = [
|
|
59267
|
-
instructions,
|
|
59268
|
-
"Return only one JSON value matching this canonical FLOW Schema/1 schema:",
|
|
59269
|
-
"Do not wrap the JSON value in Markdown or a code fence.",
|
|
59270
|
-
schema
|
|
59271
|
-
].join(`
|
|
59272
|
-
`);
|
|
59273
|
-
if (encoder11.encode(rendered).byteLength > PROVIDER_INSTRUCTION_BYTES) {
|
|
59274
|
-
throw new AgentInstructionLimitError;
|
|
59275
|
-
}
|
|
59276
|
-
return rendered;
|
|
59277
|
-
}
|
|
59278
|
-
async function prepareCall(input, provider) {
|
|
59279
|
-
const target = requireParentTarget(input.parent);
|
|
59280
|
-
const captured = await captureStoredPackage(input.packageStoreRoot, target.request.package);
|
|
59281
|
-
try {
|
|
59282
|
-
const inspected = await inspectCapturedPackage(captured);
|
|
59283
|
-
const reference = inspected.usedContracts.find(({ slot }) => slot === input.call.slot);
|
|
59284
|
-
if (reference === undefined) {
|
|
59285
|
-
throw new AgentRunValidationError("AGENT_RUN_CONTRACT_MISMATCH", "Agent Run capability descriptor is absent from the admitted package");
|
|
59286
|
-
}
|
|
59287
|
-
assertAgentRunContract(reference.contract);
|
|
59288
|
-
const prepared = parseAgentRunInput(reference.contract, input.call.input);
|
|
59289
|
-
const manifest = await projectAgentRunSkills(captured, prepared.selectedSkills);
|
|
59290
|
-
let instructions = renderPrivateAgentRunInstructions(prepared.input.instructions, manifest);
|
|
59291
|
-
const responseSchema = prepared.input.responseSchema;
|
|
59292
|
-
if (responseSchema !== undefined)
|
|
59293
|
-
assertPrivateAgentResponseSchema(responseSchema);
|
|
59294
|
-
if (provider.kind === "private-acp-agent-provider/1" && responseSchema !== undefined) {
|
|
59295
|
-
instructions = renderPrivateAcpStructuredInstructions(instructions, responseSchema);
|
|
59296
|
-
}
|
|
59297
|
-
const requestIdentity = Object.freeze({
|
|
59298
|
-
providerDigest: provider.digest,
|
|
59299
|
-
instructions,
|
|
59300
|
-
...responseSchema === undefined ? {} : { responseSchema }
|
|
59301
|
-
});
|
|
59302
|
-
return Object.freeze({
|
|
59303
|
-
input: prepared,
|
|
59304
|
-
contract: reference.contract,
|
|
59305
|
-
instructions,
|
|
59306
|
-
...responseSchema === undefined ? {} : { responseSchema },
|
|
59307
|
-
digest: privateDomainDigest("JIG-Private-Agent-Request/1", requestIdentity)
|
|
59308
|
-
});
|
|
59309
|
-
} finally {
|
|
59310
|
-
await captured.dispose();
|
|
59311
|
-
}
|
|
59312
|
-
}
|
|
59313
|
-
function selectAgentCapability(parent, call) {
|
|
59314
|
-
const target = requireParentTarget(parent);
|
|
59315
|
-
const selected = target.request.capabilities[call.slot];
|
|
59316
|
-
if (selected === undefined)
|
|
59317
|
-
return;
|
|
59318
|
-
if (selected.id !== AGENT_RUN_CONTRACT_ID || selected.version !== AGENT_RUN_CONTRACT_VERSION || selected.digest !== AGENT_RUN_CONTRACT_DIGEST) {
|
|
59319
|
-
throw new Error("admitted Agent Run capability identity is invalid");
|
|
59320
|
-
}
|
|
59321
|
-
return selected;
|
|
59322
|
-
}
|
|
59323
|
-
function requireParentTarget(parent) {
|
|
59324
|
-
const target = findPrivateActivationCandidateTargetV5(parent.candidate, parent.run.target);
|
|
59325
|
-
if (target === undefined || target.request.digest !== parent.intent.requestDigest || target.disposition.state !== "ready") {
|
|
59326
|
-
throw new Error("parent Run differs from its admitted target");
|
|
59327
|
-
}
|
|
59328
|
-
return target;
|
|
59329
|
-
}
|
|
59330
|
-
async function reproduceParentRecipe(input) {
|
|
59331
|
-
const target = requireParentTarget(input.parent);
|
|
59332
|
-
if (target.disposition.state !== "ready") {
|
|
59333
|
-
throw new Error("parent Run target is unavailable");
|
|
59334
|
-
}
|
|
59335
|
-
const recipe = await planPrivateDirectRun({
|
|
59336
|
-
request: target.request,
|
|
59337
|
-
executionPackage: target.disposition.executionPackage,
|
|
59338
|
-
installedSupport: input.installedSupport,
|
|
59339
|
-
backend: input.backend,
|
|
59340
|
-
agentProvider: input.agentProvider
|
|
59341
|
-
});
|
|
59342
|
-
if (recipe.digest !== target.disposition.recipeDigest || recipe.observation.digest !== target.disposition.observationDigest || recipe.agentProvider?.digest !== input.agentProvider.digest) {
|
|
59343
|
-
throw new Error("parent Agent recipe differs from its admission");
|
|
59344
|
-
}
|
|
59345
|
-
return recipe;
|
|
59346
|
-
}
|
|
59347
|
-
async function revalidateProviderSupport(recipe, provider) {
|
|
59348
|
-
const [mechanism] = await Promise.all([
|
|
59349
|
-
recipe.backend.observeMechanism(),
|
|
59350
|
-
revalidatePrivateInstalledBunSupport(recipe.installedSupport),
|
|
59351
|
-
provider.kind === "private-acp-agent-provider/1" ? revalidatePrivateAcpAgentProvider(provider) : Promise.resolve()
|
|
59352
|
-
]);
|
|
59353
|
-
if (mechanism.support.digest !== recipe.mechanismDigest || provider.kind === "private-openai-agent-provider/1" && recipe.installedSupport.agentWorkerDigest !== provider.workerDigest || recipe.agentProvider?.digest !== provider.digest) {
|
|
59354
|
-
throw new Error("Agent provider support changed after admission");
|
|
59355
|
-
}
|
|
59356
|
-
}
|
|
59357
|
-
function backendPlan2(recipe, provider, deadlineUnixMs, identity2) {
|
|
59358
|
-
const acp = provider.kind === "private-acp-agent-provider/1" ? privateAcpAgentRuntime(provider) : undefined;
|
|
59359
|
-
return Object.freeze({
|
|
59360
|
-
runId: `agent-${identity2.slice(0, 42)}`,
|
|
59361
|
-
limits: Object.freeze({
|
|
59362
|
-
...recipe.resourceCeilings,
|
|
59363
|
-
pids: Math.max(recipe.resourceCeilings.pids, AGENT_PROVIDER_MINIMUM_PIDS),
|
|
59364
|
-
deadlineUnixMs,
|
|
59365
|
-
cancellationGraceMs: CANCELLATION_GRACE_MS2
|
|
59366
|
-
}),
|
|
59367
|
-
readOnlyMounts: Object.freeze([
|
|
59368
|
-
...recipe.installedSupport.runtimeMounts,
|
|
59369
|
-
{ source: "/etc/resolv.conf", destination: "/etc/resolv.conf" },
|
|
59370
|
-
...acp === undefined ? [{
|
|
59371
|
-
source: recipe.installedSupport.agentWorkerPath,
|
|
59372
|
-
destination: recipe.installedSupport.sandboxAgentWorkerPath
|
|
59373
|
-
}] : [
|
|
59374
|
-
{ source: acp.adapterPath, destination: acp.sandboxAdapterPath },
|
|
59375
|
-
{ source: acp.executablePath, destination: acp.sandboxExecutablePath },
|
|
59376
|
-
...acp.readOnlyMounts
|
|
59377
|
-
]
|
|
59378
|
-
]),
|
|
59379
|
-
command: Object.freeze(acp === undefined ? [
|
|
59380
|
-
recipe.sandboxExecutablePath,
|
|
59381
|
-
...recipe.bunPolicy,
|
|
59382
|
-
recipe.installedSupport.sandboxAgentWorkerPath
|
|
59383
|
-
] : [recipe.sandboxExecutablePath, ...recipe.bunPolicy, acp.sandboxAdapterPath]),
|
|
59384
|
-
...acp === undefined ? {} : { environment: acp.environment },
|
|
59385
|
-
network: "inherited",
|
|
59386
|
-
...acp?.nestedUserNamespaces === true ? { nestedUserNamespaces: true } : {}
|
|
59387
|
-
});
|
|
59388
|
-
}
|
|
59389
|
-
async function interactWithProvider(component, provider, prepared, signal) {
|
|
59390
|
-
if (provider.kind === "private-acp-agent-provider/1") {
|
|
59391
|
-
return await interactWithAcpProvider(component, provider, prepared, signal);
|
|
59392
|
-
}
|
|
59393
|
-
return await interactWithOpenAIProvider(component, provider, prepared);
|
|
59394
|
-
}
|
|
59395
|
-
async function interactWithOpenAIProvider(component, provider, prepared) {
|
|
59396
|
-
const output = collectBounded3(component.stdout, PRIVATE_OPENAI_AGENT_RESPONSE_BYTES);
|
|
59397
|
-
const stderr = discardBounded(component.stderr, PROVIDER_STDERR_BYTES);
|
|
59398
|
-
try {
|
|
59399
|
-
await component.write(encodePrivateOpenAIAgentRequest({
|
|
59400
|
-
protocol: PRIVATE_OPENAI_AGENT_PROTOCOL,
|
|
59401
|
-
apiKey: privateOpenAIAgentCredential(provider),
|
|
59402
|
-
api: provider.api,
|
|
59403
|
-
baseURL: provider.baseURL,
|
|
59404
|
-
model: provider.model,
|
|
59405
|
-
instructions: prepared.instructions,
|
|
59406
|
-
...prepared.responseSchema === undefined ? {} : {
|
|
59407
|
-
responseSchema: prepared.responseSchema
|
|
59408
|
-
}
|
|
59409
|
-
}));
|
|
59410
|
-
await component.closeInput();
|
|
59411
|
-
const [bytes, fence] = await Promise.all([output, component.enforcement, stderr]).then(([bytes2, fence2]) => [bytes2, fence2]);
|
|
59412
|
-
let response;
|
|
59413
|
-
try {
|
|
59414
|
-
response = decodePrivateOpenAIAgentResponse(bytes);
|
|
59415
|
-
} catch {
|
|
59416
|
-
return Object.freeze({
|
|
59417
|
-
fence,
|
|
59418
|
-
failure: "AGENT_PROVIDER_RESPONSE_INVALID",
|
|
59419
|
-
cancelled: false
|
|
59420
|
-
});
|
|
59421
|
-
}
|
|
59422
|
-
return response.status === "error" ? Object.freeze({ fence, failure: response.code, cancelled: false }) : Object.freeze({ fence, value: response.value, cancelled: false });
|
|
59423
|
-
} catch (error49) {
|
|
59424
|
-
await component.terminate().catch(() => {
|
|
59425
|
-
return;
|
|
59426
|
-
});
|
|
59427
|
-
await Promise.allSettled([output, stderr, component.enforcement]);
|
|
59428
|
-
throw error49;
|
|
59429
|
-
}
|
|
59430
|
-
}
|
|
59431
|
-
async function interactWithAcpProvider(component, provider, prepared, signal) {
|
|
59432
|
-
const runtime = privateAcpAgentRuntime(provider);
|
|
59433
|
-
const stderr = discardBounded(component.stderr, PROVIDER_STDERR_BYTES);
|
|
59434
|
-
try {
|
|
59435
|
-
if (runtime.startupInput !== undefined) {
|
|
59436
|
-
await component.write(runtime.startupInput());
|
|
59437
|
-
}
|
|
59438
|
-
const turn = await runPrivateAcpTurn(privateAcpComponentStream(component), {
|
|
59439
|
-
cwd: "/work",
|
|
59440
|
-
instructions: prepared.instructions,
|
|
59441
|
-
signal,
|
|
59442
|
-
configuration: runtime.configuration,
|
|
59443
|
-
...runtime.modeId === undefined ? {} : { modeId: runtime.modeId },
|
|
59444
|
-
...runtime.sessionMeta === undefined ? {} : { sessionMeta: runtime.sessionMeta },
|
|
59445
|
-
...runtime.authentication === undefined ? {} : {
|
|
59446
|
-
authentication: {
|
|
59447
|
-
request: runtime.authentication.request,
|
|
59448
|
-
...runtime.authentication.clientAuthCapabilities === undefined ? {} : {
|
|
59449
|
-
clientAuthCapabilities: runtime.authentication.clientAuthCapabilities
|
|
59450
|
-
}
|
|
59451
|
-
}
|
|
59452
|
-
}
|
|
59453
|
-
});
|
|
59454
|
-
await component.closeInput();
|
|
59455
|
-
const [fence] = await Promise.all([component.enforcement, stderr]);
|
|
59456
|
-
if (turn.stopReason === "cancelled") {
|
|
59457
|
-
return Object.freeze({ fence, cancelled: true });
|
|
59458
|
-
}
|
|
59459
|
-
try {
|
|
59460
|
-
return Object.freeze({
|
|
59461
|
-
fence,
|
|
59462
|
-
value: acpResultValue(turn, prepared.responseSchema !== undefined),
|
|
59463
|
-
cancelled: false
|
|
59464
|
-
});
|
|
59465
|
-
} catch {
|
|
59466
|
-
return Object.freeze({
|
|
59467
|
-
fence,
|
|
59468
|
-
failure: "AGENT_PROVIDER_RESPONSE_INVALID",
|
|
59469
|
-
cancelled: false
|
|
59470
|
-
});
|
|
59471
|
-
}
|
|
59472
|
-
} catch (error49) {
|
|
59473
|
-
await component.terminate().catch(() => {
|
|
59474
|
-
return;
|
|
59475
|
-
});
|
|
59476
|
-
await Promise.allSettled([stderr, component.enforcement]);
|
|
59477
|
-
if (error49 instanceof PrivateAcpProtocolError) {
|
|
59478
|
-
throw error49;
|
|
59479
|
-
}
|
|
59480
|
-
throw error49;
|
|
59481
|
-
}
|
|
59482
|
-
}
|
|
59483
|
-
function acpResultValue(turn, structuredRequested) {
|
|
59484
|
-
const outcome = turn.stopReason === "end_turn" ? "completed" : turn.stopReason === "refusal" ? "blocked" : "limit";
|
|
59485
|
-
if (!structuredRequested || outcome !== "completed") {
|
|
59486
|
-
return Object.freeze({ outcome, text: turn.text });
|
|
59487
|
-
}
|
|
59488
|
-
return Object.freeze({
|
|
59489
|
-
outcome,
|
|
59490
|
-
text: turn.text,
|
|
59491
|
-
structured: decodePrivateAcpStructuredText(turn.text)
|
|
59492
|
-
});
|
|
59493
|
-
}
|
|
59494
|
-
function decodePrivateAcpStructuredText(text) {
|
|
59495
|
-
try {
|
|
59496
|
-
return decodeJson1(encoder11.encode(text));
|
|
59497
|
-
} catch (rawError) {
|
|
59498
|
-
const match = /^```json\r?\n([\s\S]*)\r?\n```$/.exec(text.trim());
|
|
59499
|
-
if (match === null)
|
|
59500
|
-
throw rawError;
|
|
59501
|
-
return decodeJson1(encoder11.encode(match[1]));
|
|
59502
|
-
}
|
|
59503
|
-
}
|
|
59504
|
-
async function releaseKnownAgent(input, lifecycleValue, fence) {
|
|
59505
|
-
let lifecycle = lifecycleValue;
|
|
59506
|
-
const sandbox = parseSandbox2(lifecycle);
|
|
59507
|
-
lifecycle = await recordPrivateRootChildFence({
|
|
59508
|
-
coordinator: input.coordinator,
|
|
59509
|
-
projectRoot: input.projectRoot,
|
|
59510
|
-
parentRunId: lifecycle.parentRunId,
|
|
59511
|
-
operationId: lifecycle.operationId,
|
|
59512
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
59513
|
-
sandboxDigest: lifecycle.sandbox.digest,
|
|
59514
|
-
fence
|
|
59515
|
-
});
|
|
59516
|
-
const ownerRelease = await releasePrivateLinuxOwnerState(sandbox.owner, fence);
|
|
59517
|
-
const cleanup = agentCleanup(ownerRelease);
|
|
59518
|
-
lifecycle = await recordPrivateRootChildCleanup({
|
|
59519
|
-
coordinator: input.coordinator,
|
|
59520
|
-
projectRoot: input.projectRoot,
|
|
59521
|
-
parentRunId: lifecycle.parentRunId,
|
|
59522
|
-
operationId: lifecycle.operationId,
|
|
59523
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
59524
|
-
sandboxDigest: lifecycle.sandbox.digest,
|
|
59525
|
-
fenceDigest: lifecycle.fence.digest,
|
|
59526
|
-
cleanup
|
|
59527
|
-
});
|
|
59528
|
-
await closePrivateRootChildOwner({
|
|
59529
|
-
coordinator: input.coordinator,
|
|
59530
|
-
projectRoot: input.projectRoot,
|
|
59531
|
-
parentRunId: lifecycle.parentRunId,
|
|
59532
|
-
operationId: lifecycle.operationId,
|
|
59533
|
-
allocationDigest: lifecycle.allocation.digest,
|
|
59534
|
-
sandboxDigest: lifecycle.sandbox.digest,
|
|
59535
|
-
fenceDigest: lifecycle.fence.digest,
|
|
59536
|
-
cleanupDigest: lifecycle.cleanup.digest
|
|
59537
|
-
});
|
|
59538
|
-
}
|
|
59539
59802
|
async function findLifecycle2(input, operationId) {
|
|
59540
59803
|
return (await listPrivateRootChildOwners({
|
|
59541
59804
|
coordinator: input.coordinator,
|
|
59542
59805
|
projectRoot: input.projectRoot,
|
|
59543
59806
|
parentRunId: input.parent.run.runId
|
|
59544
|
-
})).find((item) => item.operationId === operationId);
|
|
59807
|
+
})).find((item) => item.parentOperationId === undefined && item.operationId === operationId);
|
|
59545
59808
|
}
|
|
59546
59809
|
function parseAllocation3(lifecycle) {
|
|
59547
59810
|
const value = exactObject5(lifecycle.allocation.value, [
|
|
@@ -59549,33 +59812,31 @@ function parseAllocation3(lifecycle) {
|
|
|
59549
59812
|
"parentRunId",
|
|
59550
59813
|
"coordinatorEpoch",
|
|
59551
59814
|
"operationId",
|
|
59552
|
-
"parentRequestDigest",
|
|
59553
59815
|
"requestDigest",
|
|
59554
|
-
"providerDigest",
|
|
59555
59816
|
"effectiveDeadlineUnixMs",
|
|
59817
|
+
"packageAllocation",
|
|
59556
59818
|
"ownerAllocation"
|
|
59557
|
-
], "
|
|
59558
|
-
if (value.kind !== ALLOCATION_KIND3 || value.parentRunId !== lifecycle.parentRunId || value.operationId !== lifecycle.operationId || typeof value.coordinatorEpoch !== "number" || !Number.isSafeInteger(value.coordinatorEpoch) || value.coordinatorEpoch < 1 ||
|
|
59559
|
-
throw new TypeError("
|
|
59819
|
+
], "child allocation");
|
|
59820
|
+
if (value.kind !== ALLOCATION_KIND3 || lifecycle.parentOperationId !== undefined || value.parentRunId !== lifecycle.parentRunId || value.operationId !== lifecycle.operationId || typeof value.coordinatorEpoch !== "number" || !Number.isSafeInteger(value.coordinatorEpoch) || value.coordinatorEpoch < 1 || typeof value.requestDigest !== "string" || typeof value.effectiveDeadlineUnixMs !== "number" || !Number.isSafeInteger(value.effectiveDeadlineUnixMs) || value.effectiveDeadlineUnixMs < 0) {
|
|
59821
|
+
throw new TypeError("child allocation is invalid");
|
|
59560
59822
|
}
|
|
59561
59823
|
return Object.freeze({
|
|
59562
59824
|
kind: ALLOCATION_KIND3,
|
|
59563
59825
|
parentRunId: value.parentRunId,
|
|
59564
59826
|
coordinatorEpoch: value.coordinatorEpoch,
|
|
59565
59827
|
operationId: value.operationId,
|
|
59566
|
-
parentRequestDigest: value.parentRequestDigest,
|
|
59567
59828
|
requestDigest: value.requestDigest,
|
|
59568
|
-
providerDigest: value.providerDigest,
|
|
59569
59829
|
effectiveDeadlineUnixMs: value.effectiveDeadlineUnixMs,
|
|
59830
|
+
packageAllocation: normalizePrivatePackageMaterializationAllocationIdentity(value.packageAllocation),
|
|
59570
59831
|
ownerAllocation: normalizePrivateLinuxOwnerStateAllocationIdentity(value.ownerAllocation)
|
|
59571
59832
|
});
|
|
59572
59833
|
}
|
|
59573
59834
|
function parseSandbox2(lifecycle) {
|
|
59574
59835
|
if (lifecycle.sandbox === undefined)
|
|
59575
|
-
throw new TypeError("
|
|
59576
|
-
const value = exactObject5(lifecycle.sandbox.value, ["kind", "owner"], "
|
|
59836
|
+
throw new TypeError("child sandbox owner is absent");
|
|
59837
|
+
const value = exactObject5(lifecycle.sandbox.value, ["kind", "owner"], "child sandbox");
|
|
59577
59838
|
if (value.kind !== SANDBOX_KIND2)
|
|
59578
|
-
throw new TypeError("
|
|
59839
|
+
throw new TypeError("child sandbox kind is invalid");
|
|
59579
59840
|
return Object.freeze({
|
|
59580
59841
|
kind: SANDBOX_KIND2,
|
|
59581
59842
|
owner: normalizePrivateLinuxSealedOwnerIdentity(value.owner)
|
|
@@ -59583,74 +59844,46 @@ function parseSandbox2(lifecycle) {
|
|
|
59583
59844
|
}
|
|
59584
59845
|
function parseFence2(lifecycle) {
|
|
59585
59846
|
if (lifecycle.fence === undefined)
|
|
59586
|
-
throw new TypeError("
|
|
59847
|
+
throw new TypeError("child fence is absent");
|
|
59587
59848
|
return normalizePrivateLinuxConfirmedEnforcementReceipt(lifecycle.fence.value);
|
|
59588
59849
|
}
|
|
59589
|
-
function
|
|
59590
|
-
return Object.freeze({
|
|
59850
|
+
function childCleanup(ownerRelease) {
|
|
59851
|
+
return Object.freeze({
|
|
59852
|
+
kind: CLEANUP_KIND2,
|
|
59853
|
+
packageReleased: true,
|
|
59854
|
+
ownerRelease
|
|
59855
|
+
});
|
|
59591
59856
|
}
|
|
59592
59857
|
function parseCleanup2(lifecycle) {
|
|
59593
59858
|
if (lifecycle.cleanup === undefined)
|
|
59594
|
-
throw new TypeError("
|
|
59595
|
-
const value = exactObject5(lifecycle.cleanup.value, ["kind", "ownerRelease"], "
|
|
59596
|
-
if (value.kind !== CLEANUP_KIND2)
|
|
59597
|
-
throw new TypeError("
|
|
59598
|
-
|
|
59859
|
+
throw new TypeError("child cleanup is absent");
|
|
59860
|
+
const value = exactObject5(lifecycle.cleanup.value, ["kind", "ownerRelease", "packageReleased"], "child cleanup");
|
|
59861
|
+
if (value.kind !== CLEANUP_KIND2 || value.packageReleased !== true) {
|
|
59862
|
+
throw new TypeError("child cleanup is invalid");
|
|
59863
|
+
}
|
|
59864
|
+
return childCleanup(normalizePrivateLinuxOwnerStateReleaseReceipt(value.ownerRelease));
|
|
59599
59865
|
}
|
|
59600
59866
|
function requireCleanupMatches2(lifecycle, expected) {
|
|
59601
59867
|
const actual = parseCleanup2(lifecycle);
|
|
59602
59868
|
if (actual.ownerRelease.digest !== expected.ownerRelease.digest) {
|
|
59603
|
-
throw new Error("durable
|
|
59869
|
+
throw new Error("durable child cleanup differs from the released owner");
|
|
59604
59870
|
}
|
|
59605
59871
|
}
|
|
59606
59872
|
async function requireAllocationMatchesParent2(input, lifecycle, allocation) {
|
|
59607
|
-
const
|
|
59608
|
-
if (allocation.parentRunId !== input.parent.run.runId || allocation.coordinatorEpoch !== input.parent.run.coordinatorEpoch || allocation.operationId !== lifecycle.operationId || allocation.
|
|
59609
|
-
throw new Error("durable
|
|
59610
|
-
}
|
|
59611
|
-
const ownerParent = await protectedOwnerRoot(input.projectRoot);
|
|
59612
|
-
const identity2 = agentIdentity(lifecycle.parentRunId, lifecycle.operationId);
|
|
59613
|
-
if (allocation.ownerAllocation.parent !== ownerParent || allocation.ownerAllocation.name !== `a-${identity2.slice(0, 62)}`) {
|
|
59614
|
-
throw new Error("durable Agent allocation differs from its admitted owner resource");
|
|
59615
|
-
}
|
|
59616
|
-
}
|
|
59617
|
-
function providerFailure(code) {
|
|
59618
|
-
if (code === "AGENT_PROVIDER_OUTPUT_LIMIT") {
|
|
59619
|
-
return failed2("RESOURCE_EXHAUSTED", "the Agent provider result exceeded its fixed bound");
|
|
59620
|
-
}
|
|
59621
|
-
if (code === "AGENT_PROVIDER_RESPONSE_INVALID") {
|
|
59622
|
-
return failed2("INVALID_RESULT", "the Agent provider returned an invalid result");
|
|
59623
|
-
}
|
|
59624
|
-
return failed2("EXECUTION_FAILED", "the Agent provider request failed");
|
|
59625
|
-
}
|
|
59626
|
-
async function collectBounded3(source, maximum) {
|
|
59627
|
-
const chunks = [];
|
|
59628
|
-
let total = 0;
|
|
59629
|
-
for await (const chunk of source) {
|
|
59630
|
-
total += chunk.byteLength;
|
|
59631
|
-
if (total > maximum)
|
|
59632
|
-
throw new Error("Agent provider output exceeds its byte bound");
|
|
59633
|
-
chunks.push(Uint8Array.from(chunk));
|
|
59873
|
+
const parentTarget = findPrivateActivationCandidateTargetV5(input.parent.candidate, input.parent.run.target);
|
|
59874
|
+
if (parentTarget === undefined || parentTarget.request.digest !== input.parent.intent.requestDigest || allocation.parentRunId !== input.parent.run.runId || allocation.coordinatorEpoch !== input.parent.run.coordinatorEpoch || allocation.operationId !== lifecycle.operationId || allocation.effectiveDeadlineUnixMs > input.parent.intent.deadlineUnixMs) {
|
|
59875
|
+
throw new Error("durable child allocation differs from its parent Run");
|
|
59634
59876
|
}
|
|
59635
|
-
const
|
|
59636
|
-
|
|
59637
|
-
|
|
59638
|
-
output.set(chunk, offset);
|
|
59639
|
-
offset += chunk.byteLength;
|
|
59877
|
+
const selected = Object.values(parentTarget.request.flowSlots).map((target) => findPrivateActivationCandidateTargetV5(input.parent.candidate, target)).find((target) => target?.request.digest === allocation.requestDigest);
|
|
59878
|
+
if (selected === undefined || selected.disposition.state !== "ready" || Object.keys(selected.request.flowSlots).length !== 0) {
|
|
59879
|
+
throw new Error("durable child allocation is not an admitted leaf Flow");
|
|
59640
59880
|
}
|
|
59641
|
-
|
|
59642
|
-
|
|
59643
|
-
|
|
59644
|
-
|
|
59645
|
-
for await (const chunk of source) {
|
|
59646
|
-
total += chunk.byteLength;
|
|
59647
|
-
if (total > maximum)
|
|
59648
|
-
throw new Error("Agent provider diagnostics exceed their byte bound");
|
|
59881
|
+
const roots = await protectedWorkRoots(input.projectRoot);
|
|
59882
|
+
const identity2 = childIdentity(lifecycle.parentRunId, lifecycle.operationId);
|
|
59883
|
+
if (allocation.packageAllocation.parent.path !== roots.materializations || allocation.packageAllocation.name !== `child-${identity2.slice(0, 48)}` || allocation.packageAllocation.packageDigest !== selected.disposition.executionPackage.digest || allocation.packageAllocation.ownerToken !== `sha256:${identity2}` || allocation.ownerAllocation.parent !== roots.owners || allocation.ownerAllocation.name !== `c-${identity2.slice(0, 47)}`) {
|
|
59884
|
+
throw new Error("durable child allocation differs from its admitted resources");
|
|
59649
59885
|
}
|
|
59650
|
-
|
|
59651
|
-
async function cancelUnusedAllocation(allocation) {
|
|
59652
|
-
const cancelled = await cancelPrivateLinuxOwnerStateAllocation(allocation);
|
|
59653
|
-
await releasePrivateLinuxOwnerState(allocation, cancelled);
|
|
59886
|
+
return selected;
|
|
59654
59887
|
}
|
|
59655
59888
|
function exactObject5(value, fields, label) {
|
|
59656
59889
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -59664,28 +59897,43 @@ function exactObject5(value, fields, label) {
|
|
|
59664
59897
|
}
|
|
59665
59898
|
return record3;
|
|
59666
59899
|
}
|
|
59667
|
-
function
|
|
59668
|
-
return privateDomainDigest("JIG-Private-Root-
|
|
59900
|
+
function childIdentity(parentRunId, operationId) {
|
|
59901
|
+
return privateDomainDigest("JIG-Private-Root-Child-Identity/1", {
|
|
59669
59902
|
parentRunId,
|
|
59670
59903
|
operationId
|
|
59671
59904
|
}).slice("sha256:".length);
|
|
59672
59905
|
}
|
|
59673
|
-
async function
|
|
59674
|
-
const state2 = await
|
|
59906
|
+
async function protectedWorkRoots(projectRoot) {
|
|
59907
|
+
const state2 = await realpath12(join12(projectRoot, ".jig"));
|
|
59908
|
+
const materializations = join12(state2, "private-root-materializations");
|
|
59675
59909
|
const owners = join12(state2, "private-root-linux-owners");
|
|
59676
|
-
await
|
|
59910
|
+
await Promise.all([ensureProtectedDirectory(materializations), ensureProtectedDirectory(owners)]);
|
|
59911
|
+
return Object.freeze({ materializations, owners });
|
|
59912
|
+
}
|
|
59913
|
+
async function ensureProtectedDirectory(path2) {
|
|
59914
|
+
await mkdir9(path2, { mode: 448 }).catch((error49) => {
|
|
59677
59915
|
if (!hasCode7(error49, "EEXIST"))
|
|
59678
59916
|
throw error49;
|
|
59679
59917
|
});
|
|
59680
|
-
const information = await lstat17(
|
|
59918
|
+
const information = await lstat17(path2);
|
|
59681
59919
|
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
59682
|
-
if (!information.isDirectory() || information.isSymbolicLink() || information.uid !== uid || (information.mode & 63) !== 0 || await
|
|
59683
|
-
throw new Error("
|
|
59920
|
+
if (!information.isDirectory() || information.isSymbolicLink() || information.uid !== uid || (information.mode & 63) !== 0 || await realpath12(path2) !== path2) {
|
|
59921
|
+
throw new Error("child execution owner directory is not protected");
|
|
59684
59922
|
}
|
|
59685
|
-
return owners;
|
|
59686
59923
|
}
|
|
59687
|
-
function
|
|
59688
|
-
|
|
59924
|
+
function startupSignal(signal) {
|
|
59925
|
+
const controller = new AbortController;
|
|
59926
|
+
const abort = () => controller.abort(signal.reason);
|
|
59927
|
+
if (signal.aborted)
|
|
59928
|
+
abort();
|
|
59929
|
+
else
|
|
59930
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
59931
|
+
return Object.freeze({
|
|
59932
|
+
signal: controller.signal,
|
|
59933
|
+
dispose() {
|
|
59934
|
+
signal.removeEventListener("abort", abort);
|
|
59935
|
+
}
|
|
59936
|
+
});
|
|
59689
59937
|
}
|
|
59690
59938
|
function failed2(code, message, details) {
|
|
59691
59939
|
return Object.freeze({
|
|
@@ -59699,9 +59947,6 @@ function hasCode7(error49, code) {
|
|
|
59699
59947
|
return error49 !== null && typeof error49 === "object" && error49.code === code;
|
|
59700
59948
|
}
|
|
59701
59949
|
|
|
59702
|
-
class AgentInstructionLimitError extends Error {
|
|
59703
|
-
}
|
|
59704
|
-
|
|
59705
59950
|
// src/internal/root-run-controller.ts
|
|
59706
59951
|
var PLAN_KIND = "private-direct-root-plan/1";
|
|
59707
59952
|
var BACKING_KIND = "private-direct-root-backing/1";
|
|
@@ -60196,7 +60441,7 @@ async function reacquire(input) {
|
|
|
60196
60441
|
});
|
|
60197
60442
|
}
|
|
60198
60443
|
async function protectedWorkRoots2(projectRoot) {
|
|
60199
|
-
const state2 = await
|
|
60444
|
+
const state2 = await realpath13(join13(projectRoot, ".jig"));
|
|
60200
60445
|
const materializations = join13(state2, "private-root-materializations");
|
|
60201
60446
|
const owners = join13(state2, "private-root-linux-owners");
|
|
60202
60447
|
await Promise.all([ensureProtectedDirectory2(materializations), ensureProtectedDirectory2(owners)]);
|
|
@@ -60209,7 +60454,7 @@ async function ensureProtectedDirectory2(path2) {
|
|
|
60209
60454
|
});
|
|
60210
60455
|
const information = await lstat18(path2);
|
|
60211
60456
|
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
60212
|
-
if (!information.isDirectory() || information.isSymbolicLink() || information.uid !== uid || (information.mode & 63) !== 0 || await
|
|
60457
|
+
if (!information.isDirectory() || information.isSymbolicLink() || information.uid !== uid || (information.mode & 63) !== 0 || await realpath13(path2) !== path2) {
|
|
60213
60458
|
throw new Error("private root execution work directory is not protected");
|
|
60214
60459
|
}
|
|
60215
60460
|
}
|
|
@@ -60905,13 +61150,16 @@ function projectError2(error49, operation) {
|
|
|
60905
61150
|
return new ProjectAdministrationError("INTERNAL", `${operation} failed`);
|
|
60906
61151
|
}
|
|
60907
61152
|
function scopePrivatePackagePlanningError(error49, packagePath) {
|
|
60908
|
-
if (!(error49 instanceof CheckError) || error49.kind !== "unavailable"
|
|
61153
|
+
if (!(error49 instanceof CheckError) || error49.kind !== "unavailable") {
|
|
60909
61154
|
return error49;
|
|
60910
61155
|
}
|
|
60911
|
-
|
|
61156
|
+
const relativePath = error49.code === "PACKAGE_BUN_SOURCE_UNSUPPORTED" && error49.path === "bun.lock" ? "bun.lock" : error49.code === "PACKAGE_BUN_PREPARATION_FAILED" && error49.path === undefined ? "package.json" : undefined;
|
|
61157
|
+
if (relativePath === undefined)
|
|
61158
|
+
return error49;
|
|
61159
|
+
return new CheckError(error49.kind, error49.code, error49.message, `${packagePath}/${relativePath}`, error49.pointer);
|
|
60912
61160
|
}
|
|
60913
61161
|
function isUnavailableDiagnosticCode(code) {
|
|
60914
|
-
return code === "PACKAGE_BUN_SOURCE_UNSUPPORTED";
|
|
61162
|
+
return code === "PACKAGE_BUN_SOURCE_UNSUPPORTED" || code === "PACKAGE_BUN_PREPARATION_FAILED" || code === "PROJECT_AGENT_UNAVAILABLE";
|
|
60915
61163
|
}
|
|
60916
61164
|
function isCandidateDiagnosticCode(code) {
|
|
60917
61165
|
return code.startsWith("CAPABILITY_") || code.startsWith("METADATA_") || code.startsWith("SCHEMA_") || code.startsWith("PACKAGE_BUN_") || code.startsWith("PROJECT_BINDING_") || code.startsWith("PROJECT_DECLARATION_") || code.startsWith("PROJECT_EVALUATION_") || code.startsWith("PROJECT_EVALUATOR_") || code.startsWith("PROJECT_MEMBER_") || code.startsWith("PROJECT_SOURCE_") || [
|
|
@@ -60954,10 +61202,10 @@ var BUN_POLICY5 = Object.freeze([
|
|
|
60954
61202
|
"--no-install",
|
|
60955
61203
|
"--config=/dev/null"
|
|
60956
61204
|
]);
|
|
60957
|
-
var installedCliPath = await
|
|
61205
|
+
var installedCliPath = await realpath14(fileURLToPath2(import.meta.url));
|
|
60958
61206
|
var releaseRoot = dirname7(dirname7(installedCliPath));
|
|
60959
|
-
var executablePath = await
|
|
60960
|
-
if (process.argv[0] !== executablePath || process.argv[1] !== installedCliPath || await
|
|
61207
|
+
var executablePath = await realpath14(process.execPath);
|
|
61208
|
+
if (process.argv[0] !== executablePath || process.argv[1] !== installedCliPath || await realpath14("/proc/self/exe") !== executablePath || process.execArgv.length !== BUN_POLICY5.length || process.execArgv.some((value, index) => value !== BUN_POLICY5[index])) {
|
|
60961
61209
|
throw new Error("the installed Jig command has an invalid startup posture");
|
|
60962
61210
|
}
|
|
60963
61211
|
async function runPrivateInstalledCli(arguments_ = process.argv.slice(2), signal) {
|
|
@@ -60971,7 +61219,7 @@ async function runPrivateInstalledCli(arguments_ = process.argv.slice(2), signal
|
|
|
60971
61219
|
if (delegation.kind === "private-rootless-linux-reexecuted/1")
|
|
60972
61220
|
return delegation;
|
|
60973
61221
|
const installedHost = await openPrivateInstalledBunHost({
|
|
60974
|
-
releaseRoot: await
|
|
61222
|
+
releaseRoot: await realpath14(releaseRoot),
|
|
60975
61223
|
executablePath,
|
|
60976
61224
|
installedCliPath
|
|
60977
61225
|
});
|