@amaster.ai/employee-runtime-connector 0.1.1-beta.272 → 0.1.1-beta.274
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/dist/amaster-runtime-daemon.mjs +52 -416
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
|
@@ -17758,6 +17758,7 @@ function managedPiProviderToolContract(tools) {
|
|
|
17758
17758
|
}
|
|
17759
17759
|
const entries = definitions.map(({ name, schemaHash }) => ({ name, schemaHash }));
|
|
17760
17760
|
return {
|
|
17761
|
+
definitions,
|
|
17761
17762
|
entries,
|
|
17762
17763
|
effectiveToolSchemaBytes: definitions.reduce((total, entry) => total + entry.schemaBytes, 0),
|
|
17763
17764
|
effectiveToolSetSha256: sha256(stableJson(entries)),
|
|
@@ -18353,8 +18354,8 @@ function observedPiFinalContextToolContract(input) {
|
|
|
18353
18354
|
const expectedNames = Array.isArray(input?.toolNames) ? [...input.toolNames] : [];
|
|
18354
18355
|
if (expectedNames.length === 0 || expectedNames.some((name) => typeof name !== "string" || !name) || new Set(expectedNames).size !== expectedNames.length) fail2("observed_tool_contract_invalid");
|
|
18355
18356
|
expectedNames.sort();
|
|
18356
|
-
const
|
|
18357
|
-
const observed = Array.isArray(
|
|
18357
|
+
const finalRequiredTools = input?.profileAttestation?.finalRequiredTools;
|
|
18358
|
+
const observed = Array.isArray(finalRequiredTools) ? finalRequiredTools.filter((entry) => expectedNames.includes(entry?.name)).map((entry) => ({
|
|
18358
18359
|
name: entry.name,
|
|
18359
18360
|
schemaHash: entry.schemaHash,
|
|
18360
18361
|
schemaBytes: entry.schemaBytes
|
|
@@ -21867,7 +21868,7 @@ function piMcpAdapterServerConfigIdentity(definition, adapterVersion) {
|
|
|
21867
21868
|
import { createHash as createHash6 } from "node:crypto";
|
|
21868
21869
|
var MANAGED_PI_EFFECTIVE_TOOLS_ATTESTOR_FILENAME = "amaster-effective-tools-attestor.js";
|
|
21869
21870
|
var MANAGED_PI_EFFECTIVE_TOOLS_SCHEMA_VERSION = "amaster.pi-effective-tools.v1";
|
|
21870
|
-
function
|
|
21871
|
+
function normalizedPiToolSchema(value, adapterNormalized) {
|
|
21871
21872
|
const schema = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21872
21873
|
if (!adapterNormalized) return schema;
|
|
21873
21874
|
const { $schema: _schema, additionalProperties: _additionalProperties, ...normalized } = schema;
|
|
@@ -21883,7 +21884,7 @@ function stablePiJson(value) {
|
|
|
21883
21884
|
return `{${keys.map((key) => `${JSON.stringify(key)}:${stablePiJson(value[key])}`).join(",")}}`;
|
|
21884
21885
|
}
|
|
21885
21886
|
function stablePiToolSchemaHash(schema, options = {}) {
|
|
21886
|
-
return createHash6("sha256").update(stablePiJson(
|
|
21887
|
+
return createHash6("sha256").update(stablePiJson(normalizedPiToolSchema(schema, options.adapterNormalized === true))).digest("hex");
|
|
21887
21888
|
}
|
|
21888
21889
|
function stablePiEffectiveToolSetHash(entries) {
|
|
21889
21890
|
const normalized = entries.map((entry) => ({ name: entry.name, schemaHash: entry.schemaHash ?? entry.effectiveSchemaHash })).sort((left, right) => left.name.localeCompare(right.name));
|
|
@@ -22749,17 +22750,9 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
22749
22750
|
const SESSION_ROLLOUT_MARKER3 = ".amaster-pi-session-rollout.json";
|
|
22750
22751
|
const DEFAULT_SESSION_ROLLOUT_TTL_MS3 = 24 * 60 * 60 * 1e3;
|
|
22751
22752
|
const PI_VERSION_ATTESTATION_TIMEOUT_MS = 3e4;
|
|
22752
|
-
const PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS = 6e4;
|
|
22753
|
-
const PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS = 3e4;
|
|
22754
|
-
const PI_EFFECTIVE_TOOLS_TOTAL_TIMEOUT_MS = PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS + PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS;
|
|
22755
|
-
const PI_EFFECTIVE_TOOLS_SOFT_SLOW_MS = 3e4;
|
|
22756
|
-
const PI_EFFECTIVE_TOOLS_BOOTSTRAP_SCHEMA_VERSION = 1;
|
|
22757
|
-
const PI_EFFECTIVE_TOOLS_CIRCUIT_FAILURE_THRESHOLD = Number.isInteger(options.probeCircuitFailureThreshold) && options.probeCircuitFailureThreshold > 0 ? options.probeCircuitFailureThreshold : 3;
|
|
22758
|
-
const PI_EFFECTIVE_TOOLS_CIRCUIT_COOLDOWN_MS = Number.isFinite(options.probeCircuitCooldownMs) && options.probeCircuitCooldownMs > 0 ? Math.floor(options.probeCircuitCooldownMs) : 6e4;
|
|
22759
22753
|
const PI_ATTESTATION_MAX_ATTEMPTS = 2;
|
|
22760
22754
|
const PI_ATTESTATION_RECENT_LIVE_TTL_MS = Number.isFinite(options.recentLiveTtlMs) && options.recentLiveTtlMs > 0 ? options.recentLiveTtlMs : 30 * 60 * 1e3;
|
|
22761
22755
|
const recentLivePiVersionProbes = /* @__PURE__ */ new Map();
|
|
22762
|
-
const effectiveToolsProbeCircuits = /* @__PURE__ */ new Map();
|
|
22763
22756
|
function record8(value) {
|
|
22764
22757
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
22765
22758
|
}
|
|
@@ -22931,165 +22924,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
22931
22924
|
}
|
|
22932
22925
|
return hash.digest("hex");
|
|
22933
22926
|
}
|
|
22934
|
-
function
|
|
22935
|
-
const source = resolve8(sourcePath);
|
|
22936
|
-
const sourceStat = lstatSync8(source);
|
|
22937
|
-
if (!sourceStat.isDirectory() || sourceStat.isSymbolicLink()) {
|
|
22938
|
-
throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${source}`);
|
|
22939
|
-
}
|
|
22940
|
-
mkdirSync4(targetPath, { recursive: true, mode: 448 });
|
|
22941
|
-
chmodSync6(targetPath, 448);
|
|
22942
|
-
for (const entry of readdirSync4(source, { withFileTypes: true })) {
|
|
22943
|
-
const from = join9(source, entry.name);
|
|
22944
|
-
const to = join9(targetPath, entry.name);
|
|
22945
|
-
if (entry.isSymbolicLink()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${from}`);
|
|
22946
|
-
if (entry.isDirectory()) {
|
|
22947
|
-
copyTrustedTree(from, to);
|
|
22948
|
-
continue;
|
|
22949
|
-
}
|
|
22950
|
-
if (!entry.isFile()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${from}`);
|
|
22951
|
-
copyFileSync(from, to, 0);
|
|
22952
|
-
chmodSync6(to, 384 | lstatSync8(from).mode & 73);
|
|
22953
|
-
}
|
|
22954
|
-
}
|
|
22955
|
-
function makeTrustedTreeReadOnly(rootPath) {
|
|
22956
|
-
const root = resolve8(rootPath);
|
|
22957
|
-
const pending = [root];
|
|
22958
|
-
const directories = [];
|
|
22959
|
-
while (pending.length > 0) {
|
|
22960
|
-
const current = pending.pop();
|
|
22961
|
-
const currentStat = lstatSync8(current);
|
|
22962
|
-
if (currentStat.isSymbolicLink()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${current}`);
|
|
22963
|
-
if (currentStat.isDirectory()) {
|
|
22964
|
-
directories.push(current);
|
|
22965
|
-
for (const entry of readdirSync4(current)) pending.push(join9(current, entry));
|
|
22966
|
-
continue;
|
|
22967
|
-
}
|
|
22968
|
-
if (!currentStat.isFile()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${current}`);
|
|
22969
|
-
chmodSync6(current, 256 | currentStat.mode & 73);
|
|
22970
|
-
}
|
|
22971
|
-
for (const directory of directories.reverse()) chmodSync6(directory, 320);
|
|
22972
|
-
}
|
|
22973
|
-
function makeTrustedTreeWritable(rootPath) {
|
|
22974
|
-
const pending = [resolve8(rootPath)];
|
|
22975
|
-
while (pending.length > 0) {
|
|
22976
|
-
const current = pending.pop();
|
|
22977
|
-
const currentStat = lstatSync8(current);
|
|
22978
|
-
if (currentStat.isSymbolicLink()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${current}`);
|
|
22979
|
-
if (currentStat.isDirectory()) {
|
|
22980
|
-
chmodSync6(current, 448);
|
|
22981
|
-
for (const entry of readdirSync4(current)) pending.push(join9(current, entry));
|
|
22982
|
-
continue;
|
|
22983
|
-
}
|
|
22984
|
-
if (!currentStat.isFile()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${current}`);
|
|
22985
|
-
chmodSync6(current, 384 | currentStat.mode & 73);
|
|
22986
|
-
}
|
|
22987
|
-
}
|
|
22988
|
-
function piLoaderIdentity(executorPath) {
|
|
22989
|
-
let cursor = dirname6(realpathSync6(executorPath));
|
|
22990
|
-
for (let depth = 0; depth < 4; depth += 1) {
|
|
22991
|
-
const packagePath = join9(cursor, "package.json");
|
|
22992
|
-
const loaderPath = join9(cursor, "dist", "core", "extensions", "loader.js");
|
|
22993
|
-
if (existsSync8(packagePath) && existsSync8(loaderPath)) {
|
|
22994
|
-
const packageJson = JSON.parse(readFileSync9(packagePath, "utf8"));
|
|
22995
|
-
return sha2565(stablePiJson({
|
|
22996
|
-
name: packageJson.name,
|
|
22997
|
-
version: packageJson.version,
|
|
22998
|
-
loaderSha256: sha2565(readFileSync9(loaderPath))
|
|
22999
|
-
}));
|
|
23000
|
-
}
|
|
23001
|
-
cursor = dirname6(cursor);
|
|
23002
|
-
}
|
|
23003
|
-
return sha2565(readFileSync9(realpathSync6(executorPath)));
|
|
23004
|
-
}
|
|
23005
|
-
function effectiveToolsBootstrapKey(input, sharedRuntime, executorCommand) {
|
|
23006
|
-
const adapterRoot = sharedRuntime.adapterRoot ? resolve8(nonEmpty3(sharedRuntime.adapterRoot, "sharedRuntime.adapterRoot")) : join9(sharedRuntime.home, "npm", "node_modules", "pi-mcp-adapter");
|
|
23007
|
-
const resolvedExecutorCommand = resolvePiExecutablePath(executorCommand, input.baseEnv);
|
|
23008
|
-
return sha2565(stablePiJson({
|
|
23009
|
-
schemaVersion: PI_EFFECTIVE_TOOLS_BOOTSTRAP_SCHEMA_VERSION,
|
|
23010
|
-
connectorVersion: nonEmpty3(input.connectorVersion, "connectorVersion"),
|
|
23011
|
-
executorIdentity: piExecutableIdentity(resolvedExecutorCommand),
|
|
23012
|
-
loaderIdentity: piLoaderIdentity(resolvedExecutorCommand),
|
|
23013
|
-
nodeVersion: process.version,
|
|
23014
|
-
nodeModulesAbi: process.versions.modules,
|
|
23015
|
-
platform: platform3(),
|
|
23016
|
-
arch: arch3(),
|
|
23017
|
-
// npm may install dependency symlinks under the adapter's nested
|
|
23018
|
-
// node_modules. They resolve at runtime and are not Jiti-owned compiled
|
|
23019
|
-
// source; hash every package-owned adapter file while excluding that
|
|
23020
|
-
// dependency graph so ordinary npm links do not make the cache unusable.
|
|
23021
|
-
adapterTreeSha256: trustedTreeDigest(adapterRoot, { ignoredRootEntries: ["node_modules"] }),
|
|
23022
|
-
attestorSourceSha256: sha2565(managedPiEffectiveToolsAttestorExtensionSource())
|
|
23023
|
-
}));
|
|
23024
|
-
}
|
|
23025
|
-
function prepareEffectiveToolsBootstrapCache(input, sharedRuntime, executorCommand, tmpPath) {
|
|
23026
|
-
const cacheRoot = resolve8(nonEmpty3(input.runtimeCacheRoot ?? join9(dirname6(input.runDir), ".runtime-cache"), "runtimeCacheRoot"));
|
|
23027
|
-
const bootstrapRoot = join9(cacheRoot, "pi-effective-tools-jiti-v1");
|
|
23028
|
-
mkdirSync4(bootstrapRoot, { recursive: true, mode: 448 });
|
|
23029
|
-
const bootstrapRootStat = lstatSync8(bootstrapRoot);
|
|
23030
|
-
if (!bootstrapRootStat.isDirectory() || bootstrapRootStat.isSymbolicLink()) {
|
|
23031
|
-
throw new Error("pi_managed_mcp_bootstrap_cache_unsafe: root");
|
|
23032
|
-
}
|
|
23033
|
-
const key = effectiveToolsBootstrapKey(input, sharedRuntime, executorCommand);
|
|
23034
|
-
const entryPath = join9(bootstrapRoot, key);
|
|
23035
|
-
const markerPath = join9(entryPath, "manifest.json");
|
|
23036
|
-
const sourceCachePath = join9(entryPath, "jiti");
|
|
23037
|
-
const runCachePath = join9(tmpPath, "jiti");
|
|
23038
|
-
let status = "miss";
|
|
23039
|
-
if (existsSync8(entryPath)) {
|
|
23040
|
-
try {
|
|
23041
|
-
const entryStat = lstatSync8(entryPath);
|
|
23042
|
-
const markerStat = lstatSync8(markerPath);
|
|
23043
|
-
const marker = JSON.parse(readFileSync9(markerPath, "utf8"));
|
|
23044
|
-
if (!entryStat.isDirectory() || entryStat.isSymbolicLink() || !markerStat.isFile() || markerStat.isSymbolicLink() || marker.schemaVersion !== PI_EFFECTIVE_TOOLS_BOOTSTRAP_SCHEMA_VERSION || marker.key !== key || marker.treeSha256 !== trustedTreeDigest(sourceCachePath)) throw new Error("bootstrap marker mismatch");
|
|
23045
|
-
copyTrustedTree(sourceCachePath, runCachePath);
|
|
23046
|
-
status = "hit";
|
|
23047
|
-
} catch {
|
|
23048
|
-
const resolvedEntry = resolve8(entryPath);
|
|
23049
|
-
if (!within4(resolvedEntry, bootstrapRoot) || resolvedEntry === bootstrapRoot) {
|
|
23050
|
-
throw new Error("pi_managed_mcp_bootstrap_cache_unsafe: entry");
|
|
23051
|
-
}
|
|
23052
|
-
makeTrustedTreeWritable(resolvedEntry);
|
|
23053
|
-
rmSync5(resolvedEntry, { recursive: true, force: true });
|
|
23054
|
-
status = "invalidated";
|
|
23055
|
-
}
|
|
23056
|
-
}
|
|
23057
|
-
return { bootstrapRoot, entryPath, key, runCachePath, status };
|
|
23058
|
-
}
|
|
23059
|
-
function publishEffectiveToolsBootstrapCache(cache) {
|
|
23060
|
-
if (cache.status === "hit") return "hit";
|
|
23061
|
-
if (!existsSync8(cache.runCachePath)) return `${cache.status}_unavailable`;
|
|
23062
|
-
const runCacheStat = lstatSync8(cache.runCachePath);
|
|
23063
|
-
if (!runCacheStat.isDirectory() || runCacheStat.isSymbolicLink()) {
|
|
23064
|
-
throw new Error("pi_managed_mcp_bootstrap_cache_unsafe: run cache");
|
|
23065
|
-
}
|
|
23066
|
-
if (existsSync8(cache.entryPath)) return "hit_raced";
|
|
23067
|
-
const stagingPath = `${cache.entryPath}.tmp-${process.pid}-${currentTimeMs()}`;
|
|
23068
|
-
try {
|
|
23069
|
-
mkdirSync4(stagingPath, { mode: 448 });
|
|
23070
|
-
const stagingCachePath = join9(stagingPath, "jiti");
|
|
23071
|
-
copyTrustedTree(cache.runCachePath, stagingCachePath);
|
|
23072
|
-
writePrivateFile2(join9(stagingPath, "manifest.json"), `${JSON.stringify({
|
|
23073
|
-
schemaVersion: PI_EFFECTIVE_TOOLS_BOOTSTRAP_SCHEMA_VERSION,
|
|
23074
|
-
key: cache.key,
|
|
23075
|
-
treeSha256: trustedTreeDigest(stagingCachePath)
|
|
23076
|
-
})}
|
|
23077
|
-
`);
|
|
23078
|
-
try {
|
|
23079
|
-
renameSync4(stagingPath, cache.entryPath);
|
|
23080
|
-
makeTrustedTreeReadOnly(cache.entryPath);
|
|
23081
|
-
} catch (error) {
|
|
23082
|
-
if (error?.code !== "EEXIST" && error?.code !== "ENOTEMPTY") throw error;
|
|
23083
|
-
}
|
|
23084
|
-
} finally {
|
|
23085
|
-
if (existsSync8(stagingPath)) {
|
|
23086
|
-
makeTrustedTreeWritable(stagingPath);
|
|
23087
|
-
rmSync5(stagingPath, { recursive: true, force: true });
|
|
23088
|
-
}
|
|
23089
|
-
}
|
|
23090
|
-
return existsSync8(cache.entryPath) ? `${cache.status}_published` : `${cache.status}_unavailable`;
|
|
23091
|
-
}
|
|
23092
|
-
function writeEffectiveToolsProbePhase(phasePath, phase, attempt) {
|
|
22927
|
+
function writeEffectiveToolsPhase(phasePath, phase, attempt) {
|
|
23093
22928
|
let history = [];
|
|
23094
22929
|
if (existsSync8(phasePath)) {
|
|
23095
22930
|
try {
|
|
@@ -23971,189 +23806,6 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
23971
23806
|
liveProbeAgeMs
|
|
23972
23807
|
};
|
|
23973
23808
|
}
|
|
23974
|
-
function inspectEffectiveToolsProbeReceipt(receiptPath, phasePath) {
|
|
23975
|
-
let phase = "missing";
|
|
23976
|
-
let history = [];
|
|
23977
|
-
if (existsSync8(phasePath)) {
|
|
23978
|
-
try {
|
|
23979
|
-
const phaseState = JSON.parse(readFileSync9(phasePath, "utf8"));
|
|
23980
|
-
phase = typeof phaseState.phase === "string" ? phaseState.phase : "present";
|
|
23981
|
-
history = Array.isArray(phaseState.history) ? phaseState.history : [];
|
|
23982
|
-
} catch {
|
|
23983
|
-
phase = "invalid";
|
|
23984
|
-
}
|
|
23985
|
-
}
|
|
23986
|
-
if (!existsSync8(receiptPath)) return { phase, history, receipt: null };
|
|
23987
|
-
try {
|
|
23988
|
-
const receipt = JSON.parse(readFileSync9(receiptPath, "utf8"));
|
|
23989
|
-
const receiptPhase = receipt?.status === "attested" || receipt?.status === "rejected" ? receipt.status : phase === "missing" ? "present" : phase;
|
|
23990
|
-
return { phase: receiptPhase, history, receipt };
|
|
23991
|
-
} catch {
|
|
23992
|
-
return { phase: "invalid", history, receipt: null };
|
|
23993
|
-
}
|
|
23994
|
-
}
|
|
23995
|
-
function effectiveToolsProbePhaseDurations(history, attempt) {
|
|
23996
|
-
const entries = history.filter((entry) => entry?.attempt === attempt && typeof entry.phase === "string" && Number.isFinite(entry.atMs)).sort((left, right) => left.atMs - right.atMs);
|
|
23997
|
-
const at = (phase) => entries.find((entry) => entry.phase === phase)?.atMs;
|
|
23998
|
-
const terminalAt = at("attested") ?? at("rejected");
|
|
23999
|
-
const spawnedAt = at("spawned");
|
|
24000
|
-
const loaderReadyAt = at("loader_ready");
|
|
24001
|
-
const sessionStartAt = at("session_start");
|
|
24002
|
-
return {
|
|
24003
|
-
...Number.isFinite(spawnedAt) && Number.isFinite(loaderReadyAt) ? { spawnedToLoaderReadyMs: Math.max(0, loaderReadyAt - spawnedAt) } : {},
|
|
24004
|
-
...Number.isFinite(loaderReadyAt) && Number.isFinite(sessionStartAt) ? { loaderReadyToSessionStartMs: Math.max(0, sessionStartAt - loaderReadyAt) } : {},
|
|
24005
|
-
...Number.isFinite(sessionStartAt) && Number.isFinite(terminalAt) ? { sessionStartToTerminalMs: Math.max(0, terminalAt - sessionStartAt) } : {}
|
|
24006
|
-
};
|
|
24007
|
-
}
|
|
24008
|
-
function attestDirectPiTools(executorCommand, env, input, spawnIdentity = null, circuitKey = null) {
|
|
24009
|
-
const circuit = circuitKey ? effectiveToolsProbeCircuits.get(circuitKey) : null;
|
|
24010
|
-
if (circuit?.open === true) {
|
|
24011
|
-
const retryAfterMs = Math.max(0, circuit.retryAtMs - currentTimeMs());
|
|
24012
|
-
if (retryAfterMs > 0) {
|
|
24013
|
-
const error = new Error(
|
|
24014
|
-
`pi_managed_mcp_probe_circuit_open: connector generation probe circuit is open failures=${circuit.failures} lastPhase=${circuit.lastPhase} retryAfterMs=${retryAfterMs}`
|
|
24015
|
-
);
|
|
24016
|
-
error.code = "pi_managed_mcp_probe_circuit_open";
|
|
24017
|
-
error.retryAfterMs = retryAfterMs;
|
|
24018
|
-
throw error;
|
|
24019
|
-
}
|
|
24020
|
-
effectiveToolsProbeCircuits.set(circuitKey, { ...circuit, open: false, halfOpen: true });
|
|
24021
|
-
}
|
|
24022
|
-
const startedAtMs = currentTimeMs();
|
|
24023
|
-
const attempts = [PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS, PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS];
|
|
24024
|
-
let result2;
|
|
24025
|
-
let completedAttempts = 0;
|
|
24026
|
-
for (let index = 0; index < attempts.length; index += 1) {
|
|
24027
|
-
const attempt = index + 1;
|
|
24028
|
-
const timeout = attempts[index];
|
|
24029
|
-
completedAttempts = attempt;
|
|
24030
|
-
writeEffectiveToolsProbePhase(input.phasePath, "spawned", attempt);
|
|
24031
|
-
const resolvedExecutorCommand = resolveExecutorCommand(executorCommand, env) ?? executorCommand;
|
|
24032
|
-
result2 = spawnSyncImpl(resolvedExecutorCommand, [
|
|
24033
|
-
"--no-session",
|
|
24034
|
-
"--no-approve",
|
|
24035
|
-
"--no-skills",
|
|
24036
|
-
"--no-context-files",
|
|
24037
|
-
// The enforcement extensions live in the run profile, not an agent dir,
|
|
24038
|
-
// so the probe must load them explicitly alongside the user's normal Pi
|
|
24039
|
-
// extensions and tools to measure the real run surface.
|
|
24040
|
-
...Array.isArray(input.extensionArgs) ? input.extensionArgs : [],
|
|
24041
|
-
"--print",
|
|
24042
|
-
"probe effective tools"
|
|
24043
|
-
], {
|
|
24044
|
-
cwd: env.AMASTER_RUNTIME_EXECUTION_WORKDIR,
|
|
24045
|
-
env: {
|
|
24046
|
-
...env,
|
|
24047
|
-
AMASTER_PI_EFFECTIVE_TOOLS_MODE: "probe",
|
|
24048
|
-
AMASTER_PI_EFFECTIVE_TOOLS_ATTEMPT: String(attempt)
|
|
24049
|
-
},
|
|
24050
|
-
encoding: "utf8",
|
|
24051
|
-
timeout,
|
|
24052
|
-
killSignal: "SIGKILL",
|
|
24053
|
-
maxBuffer: 1024 * 1024,
|
|
24054
|
-
...isWindowsCommandShim(resolvedExecutorCommand) ? { shell: true } : {},
|
|
24055
|
-
...spawnIdentity ?? {}
|
|
24056
|
-
});
|
|
24057
|
-
if (result2.error?.code === "ETIMEDOUT" && attempt < attempts.length) continue;
|
|
24058
|
-
break;
|
|
24059
|
-
}
|
|
24060
|
-
const elapsedMs = Math.max(0, currentTimeMs() - startedAtMs);
|
|
24061
|
-
if (result2.error) {
|
|
24062
|
-
const code = typeof result2.error.code === "string" ? result2.error.code : "UNKNOWN";
|
|
24063
|
-
const receiptDiagnostic = inspectEffectiveToolsProbeReceipt(input.receiptPath, input.phasePath);
|
|
24064
|
-
if (code === "ETIMEDOUT" && circuitKey) {
|
|
24065
|
-
if (receiptDiagnostic.phase === "missing" || receiptDiagnostic.phase === "spawned") {
|
|
24066
|
-
const previous = effectiveToolsProbeCircuits.get(circuitKey);
|
|
24067
|
-
const failures = (previous?.failures ?? 0) + 1;
|
|
24068
|
-
const shouldOpen = previous?.halfOpen === true || failures >= PI_EFFECTIVE_TOOLS_CIRCUIT_FAILURE_THRESHOLD;
|
|
24069
|
-
const observedAtMs = currentTimeMs();
|
|
24070
|
-
effectiveToolsProbeCircuits.set(circuitKey, {
|
|
24071
|
-
failures,
|
|
24072
|
-
lastPhase: receiptDiagnostic.phase,
|
|
24073
|
-
open: shouldOpen,
|
|
24074
|
-
halfOpen: false,
|
|
24075
|
-
retryAtMs: shouldOpen ? observedAtMs + PI_EFFECTIVE_TOOLS_CIRCUIT_COOLDOWN_MS : null
|
|
24076
|
-
});
|
|
24077
|
-
} else {
|
|
24078
|
-
effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24079
|
-
}
|
|
24080
|
-
} else if (circuitKey) {
|
|
24081
|
-
effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24082
|
-
}
|
|
24083
|
-
const error = new Error(
|
|
24084
|
-
`pi_managed_mcp_effective_tools_failed: probe error=${code} elapsedMs=${elapsedMs} timeoutMs=${PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS} retryTimeoutMs=${PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS} totalBudgetMs=${PI_EFFECTIVE_TOOLS_TOTAL_TIMEOUT_MS} attempts=${completedAttempts} receiptPhase=${receiptDiagnostic.phase}`
|
|
24085
|
-
);
|
|
24086
|
-
if (code === "ETIMEDOUT") error.code = "pi_managed_mcp_probe_timeout";
|
|
24087
|
-
throw error;
|
|
24088
|
-
}
|
|
24089
|
-
if (result2.status !== 0) {
|
|
24090
|
-
if (circuitKey) effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24091
|
-
const receiptDiagnostic = inspectEffectiveToolsProbeReceipt(input.receiptPath, input.phasePath);
|
|
24092
|
-
let receiptError = "receipt unavailable";
|
|
24093
|
-
if (typeof receiptDiagnostic.receipt?.error === "string" && receiptDiagnostic.receipt.error.length > 0) {
|
|
24094
|
-
receiptError = receiptDiagnostic.receipt.error.slice(0, 512);
|
|
24095
|
-
}
|
|
24096
|
-
throw new Error(
|
|
24097
|
-
`pi_managed_mcp_effective_tools_failed: probe exit=${result2.status ?? "unknown"} elapsedMs=${elapsedMs} timeoutMs=${PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS} retryTimeoutMs=${PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS} totalBudgetMs=${PI_EFFECTIVE_TOOLS_TOTAL_TIMEOUT_MS} attempts=${completedAttempts} receiptPhase=${receiptDiagnostic.phase} reason=${receiptError}`
|
|
24098
|
-
);
|
|
24099
|
-
}
|
|
24100
|
-
if (circuitKey) effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24101
|
-
let receipt;
|
|
24102
|
-
try {
|
|
24103
|
-
receipt = JSON.parse(readFileSync9(input.receiptPath, "utf8"));
|
|
24104
|
-
} catch {
|
|
24105
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: probe receipt missing");
|
|
24106
|
-
}
|
|
24107
|
-
const proxyPresenceMismatch = input.proxyMode === "required" ? receipt.proxyPresent !== true : input.proxyMode === "forbidden" && receipt.proxyPresent !== false;
|
|
24108
|
-
if (receipt.status !== "attested" || receipt.mode !== "probe" || receipt.proxyMode !== input.proxyMode || proxyPresenceMismatch || receipt.effectiveSetHash !== input.effectiveSetHash || receipt.attestorSourceSha256 !== input.attestorSourceSha256 || receipt.configSha256 !== input.configSha256) {
|
|
24109
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: probe receipt mismatch");
|
|
24110
|
-
}
|
|
24111
|
-
const finalEffectiveTools = Array.isArray(receipt.finalEffectiveTools) ? receipt.finalEffectiveTools : [];
|
|
24112
|
-
const finalEffectiveToolNames = finalEffectiveTools.map((tool) => tool?.name).filter((name) => typeof name === "string").sort();
|
|
24113
|
-
const expectedFinalActiveToolNames = Array.isArray(input.finalActiveToolNames) ? input.finalActiveToolNames.slice().sort() : [];
|
|
24114
|
-
const finalEffectiveSchemaBytes = finalEffectiveTools.reduce((total, tool) => total + (Number.isSafeInteger(tool?.schemaBytes) && tool.schemaBytes >= 0 ? tool.schemaBytes : Number.NaN), 0);
|
|
24115
|
-
const finalEffectiveToolNameSet = new Set(finalEffectiveToolNames);
|
|
24116
|
-
if (finalEffectiveTools.length === 0 || !/^[a-f0-9]{64}$/.test(receipt.finalEffectiveSetHash ?? "") || stablePiEffectiveToolSetHash(finalEffectiveTools) !== receipt.finalEffectiveSetHash || expectedFinalActiveToolNames.some((name) => !finalEffectiveToolNameSet.has(name)) || !Number.isSafeInteger(receipt.finalEffectiveSchemaBytes) || receipt.finalEffectiveSchemaBytes !== finalEffectiveSchemaBytes) {
|
|
24117
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: final tool schema receipt mismatch");
|
|
24118
|
-
}
|
|
24119
|
-
if (sha2565(readFileSync9(input.configPath)) !== input.configSha256) {
|
|
24120
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: config drifted during probe");
|
|
24121
|
-
}
|
|
24122
|
-
const finalCacheBytes = readFileSync9(input.cachePath);
|
|
24123
|
-
if (receipt.cacheSha256 !== sha2565(finalCacheBytes) || stablePiManagedMcpCacheSemanticHash(finalCacheBytes, { ignoredServers: input.userMcpServerNames }) !== input.cacheSemanticHash) {
|
|
24124
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: cache drifted during probe");
|
|
24125
|
-
}
|
|
24126
|
-
if (circuitKey) effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24127
|
-
const phaseDiagnostic = inspectEffectiveToolsProbeReceipt(input.receiptPath, input.phasePath);
|
|
24128
|
-
return {
|
|
24129
|
-
effectiveToolProxyMode: receipt.proxyMode,
|
|
24130
|
-
effectiveToolProxyPresent: receipt.proxyPresent,
|
|
24131
|
-
effectiveToolSetHash: receipt.effectiveSetHash,
|
|
24132
|
-
finalEffectiveToolSetHash: receipt.finalEffectiveSetHash,
|
|
24133
|
-
finalEffectiveToolSchemaBytes: receipt.finalEffectiveSchemaBytes,
|
|
24134
|
-
finalEffectiveToolCount: finalEffectiveTools.length,
|
|
24135
|
-
finalEffectiveTools: finalEffectiveTools.map((tool) => ({
|
|
24136
|
-
name: tool.name,
|
|
24137
|
-
schemaHash: tool.schemaHash,
|
|
24138
|
-
schemaBytes: tool.schemaBytes
|
|
24139
|
-
})),
|
|
24140
|
-
effectiveToolProbeDigest: sha2565(stablePiJson(receipt)),
|
|
24141
|
-
effectiveToolProbeAt: receipt.attestedAt,
|
|
24142
|
-
effectiveToolProbeElapsedMs: elapsedMs,
|
|
24143
|
-
effectiveToolProbeTimeoutMs: PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS,
|
|
24144
|
-
effectiveToolProbeTotalBudgetMs: PI_EFFECTIVE_TOOLS_TOTAL_TIMEOUT_MS,
|
|
24145
|
-
effectiveToolProbeCircuitCooldownMs: PI_EFFECTIVE_TOOLS_CIRCUIT_COOLDOWN_MS,
|
|
24146
|
-
effectiveToolProbeAttempts: completedAttempts,
|
|
24147
|
-
effectiveToolProbeSoftSlow: elapsedMs >= PI_EFFECTIVE_TOOLS_SOFT_SLOW_MS,
|
|
24148
|
-
effectiveToolProbePhase: phaseDiagnostic.phase,
|
|
24149
|
-
effectiveToolProbePhaseHistory: phaseDiagnostic.history,
|
|
24150
|
-
effectiveToolProbePhaseDurationsMs: effectiveToolsProbePhaseDurations(
|
|
24151
|
-
phaseDiagnostic.history,
|
|
24152
|
-
completedAttempts
|
|
24153
|
-
),
|
|
24154
|
-
effectiveToolBindings: receipt.effectiveToolBindings
|
|
24155
|
-
};
|
|
24156
|
-
}
|
|
24157
23809
|
function prepareDirectPiToolAttestation(input) {
|
|
24158
23810
|
const cachePath = join9(input.profileRoot, "mcp-cache.json");
|
|
24159
23811
|
if (!input.directCatalog) {
|
|
@@ -24216,6 +23868,26 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24216
23868
|
};
|
|
24217
23869
|
writePrivateFile2(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
24218
23870
|
`);
|
|
23871
|
+
const providerToolContract = managedPiProviderToolContract(input.directCatalog.tools.map((tool) => ({
|
|
23872
|
+
name: tool.exposedName,
|
|
23873
|
+
description: tool.description,
|
|
23874
|
+
parameters: normalizedPiToolSchema(tool.inputSchema, true)
|
|
23875
|
+
})));
|
|
23876
|
+
const declaredToolContract = {
|
|
23877
|
+
effectiveToolContractSource: "governed_catalog",
|
|
23878
|
+
effectiveToolValidationMode: "same_run_session_start_and_provider_request",
|
|
23879
|
+
effectiveToolProxyMode: manifest.proxyMode,
|
|
23880
|
+
effectiveToolSetHash: manifest.effectiveSetHash,
|
|
23881
|
+
finalRequiredToolSetHash: providerToolContract.effectiveToolSetSha256,
|
|
23882
|
+
finalRequiredToolSchemaBytes: providerToolContract.effectiveToolSchemaBytes,
|
|
23883
|
+
finalRequiredToolCount: providerToolContract.effectiveToolCount,
|
|
23884
|
+
finalRequiredTools: providerToolContract.definitions,
|
|
23885
|
+
effectiveToolBindings: input.directCatalog.tools.map((tool) => ({
|
|
23886
|
+
canonicalName: tool.name,
|
|
23887
|
+
exposedName: tool.exposedName,
|
|
23888
|
+
effectiveSchemaHash: tool.effectiveSchemaHash
|
|
23889
|
+
})).sort((left, right) => left.canonicalName.localeCompare(right.canonicalName))
|
|
23890
|
+
};
|
|
24219
23891
|
const closureTools = input.directCatalog.tools.filter((tool) => RUN_EXIT_CLOSURE_DIRECT_TYPED_TOOL_NAMES.has(tool.name));
|
|
24220
23892
|
const closureProfile = closureTools.length === RUN_EXIT_CLOSURE_DIRECT_TYPED_TOOL_NAMES.size ? (() => {
|
|
24221
23893
|
const closureToolNames = closureTools.map((tool) => tool.exposedName);
|
|
@@ -24272,7 +23944,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24272
23944
|
finalContextToolContract: managedPiProviderToolContract(closureTools.map((tool) => ({
|
|
24273
23945
|
name: tool.exposedName,
|
|
24274
23946
|
description: tool.description,
|
|
24275
|
-
parameters: tool.inputSchema
|
|
23947
|
+
parameters: normalizedPiToolSchema(tool.inputSchema, true)
|
|
24276
23948
|
}))),
|
|
24277
23949
|
cacheContentsBase64: closureCacheBytes.toString("base64"),
|
|
24278
23950
|
cacheSha256: sha2565(closureCacheBytes),
|
|
@@ -24302,6 +23974,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24302
23974
|
finalActiveToolNames: effectiveRunToolAllowlist,
|
|
24303
23975
|
userMcpServerNames: input.userMcpServerNames,
|
|
24304
23976
|
profileToolAllowlist: null,
|
|
23977
|
+
declaredToolContract,
|
|
24305
23978
|
closureProfile
|
|
24306
23979
|
}
|
|
24307
23980
|
};
|
|
@@ -24387,6 +24060,10 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24387
24060
|
if (!existsSync8(adapterExtensionPath)) {
|
|
24388
24061
|
throw new Error("pi_managed_mcp_adapter_extension_missing");
|
|
24389
24062
|
}
|
|
24063
|
+
const adapterRootStat = lstatSync8(dirname6(adapterExtensionPath));
|
|
24064
|
+
if (!adapterRootStat.isDirectory() || adapterRootStat.isSymbolicLink()) {
|
|
24065
|
+
throw new Error("pi_managed_mcp_adapter_extension_unsafe");
|
|
24066
|
+
}
|
|
24390
24067
|
const adapterExtensionStat = lstatSync8(adapterExtensionPath);
|
|
24391
24068
|
if (!adapterExtensionStat.isFile() || adapterExtensionStat.isSymbolicLink()) {
|
|
24392
24069
|
throw new Error("pi_managed_mcp_adapter_extension_unsafe");
|
|
@@ -24469,14 +24146,8 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24469
24146
|
} : {}
|
|
24470
24147
|
};
|
|
24471
24148
|
if (directAttestationInput) {
|
|
24472
|
-
|
|
24149
|
+
writeEffectiveToolsPhase(directAttestationInput.phasePath, "prepared", 0);
|
|
24473
24150
|
}
|
|
24474
|
-
const effectiveToolsBootstrapCache = directAttestationInput ? prepareEffectiveToolsBootstrapCache(
|
|
24475
|
-
input,
|
|
24476
|
-
sharedRuntime,
|
|
24477
|
-
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
24478
|
-
tmp
|
|
24479
|
-
) : null;
|
|
24480
24151
|
const spawnIdentity = typeof input.prepareExecutorAccess === "function" ? input.prepareExecutorAccess({ profileRoot, workspaceRoot: cwd }) : null;
|
|
24481
24152
|
const executorAttestation = attestPi(
|
|
24482
24153
|
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
@@ -24485,14 +24156,6 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24485
24156
|
config,
|
|
24486
24157
|
spawnIdentity
|
|
24487
24158
|
);
|
|
24488
|
-
const effectiveToolsAttestation = directAttestationInput ? attestDirectPiTools(
|
|
24489
|
-
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
24490
|
-
env,
|
|
24491
|
-
directAttestationInput,
|
|
24492
|
-
spawnIdentity,
|
|
24493
|
-
effectiveToolsBootstrapCache?.key ?? null
|
|
24494
|
-
) : {};
|
|
24495
|
-
const effectiveToolProbeBootstrapCache = effectiveToolsBootstrapCache ? publishEffectiveToolsBootstrapCache(effectiveToolsBootstrapCache) : null;
|
|
24496
24159
|
const runExitClosureOwnership = directAttestationInput ? {
|
|
24497
24160
|
cache: ownershipStatSyncImpl(directAttestationInput.cachePath),
|
|
24498
24161
|
manifest: ownershipStatSyncImpl(directAttestationInput.manifestPath),
|
|
@@ -24507,9 +24170,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24507
24170
|
mcpArgsNormalization: "none",
|
|
24508
24171
|
...directCatalog ? {
|
|
24509
24172
|
catalogSetHash: directCatalog.setHash,
|
|
24510
|
-
...
|
|
24511
|
-
effectiveToolProbeBootstrapKey: effectiveToolsBootstrapCache?.key ?? null,
|
|
24512
|
-
effectiveToolProbeBootstrapCache
|
|
24173
|
+
...directAttestationInput.declaredToolContract
|
|
24513
24174
|
} : {},
|
|
24514
24175
|
configMode: MANAGED_PI_CONFIG_MODE_SHARED,
|
|
24515
24176
|
namespace: SUPPORTED_SERVER_NAME3,
|
|
@@ -24891,18 +24552,8 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24891
24552
|
} : {}
|
|
24892
24553
|
};
|
|
24893
24554
|
if (directAttestationInput) {
|
|
24894
|
-
|
|
24555
|
+
writeEffectiveToolsPhase(directAttestationInput.phasePath, "prepared", 0);
|
|
24895
24556
|
}
|
|
24896
|
-
const sharedRuntime = {
|
|
24897
|
-
home: sourcePiHome,
|
|
24898
|
-
...desktopAttestationReadiness?.ready ? { adapterRoot: desktopAttestationReadiness.adapterRoot } : {}
|
|
24899
|
-
};
|
|
24900
|
-
const effectiveToolsBootstrapCache = directAttestationInput ? prepareEffectiveToolsBootstrapCache(
|
|
24901
|
-
input,
|
|
24902
|
-
sharedRuntime,
|
|
24903
|
-
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
24904
|
-
tmp
|
|
24905
|
-
) : null;
|
|
24906
24557
|
const spawnIdentity = typeof input.prepareExecutorAccess === "function" ? input.prepareExecutorAccess({ profileRoot, workspaceRoot: cwd }) : null;
|
|
24907
24558
|
const executorAttestation = directAttestationInput ? attestPi(
|
|
24908
24559
|
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
@@ -24911,14 +24562,6 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24911
24562
|
config,
|
|
24912
24563
|
spawnIdentity
|
|
24913
24564
|
) : {};
|
|
24914
|
-
const effectiveToolsAttestation = directAttestationInput ? attestDirectPiTools(
|
|
24915
|
-
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
24916
|
-
env,
|
|
24917
|
-
directAttestationInput,
|
|
24918
|
-
spawnIdentity,
|
|
24919
|
-
effectiveToolsBootstrapCache?.key ?? null
|
|
24920
|
-
) : {};
|
|
24921
|
-
const effectiveToolProbeBootstrapCache = effectiveToolsBootstrapCache ? publishEffectiveToolsBootstrapCache(effectiveToolsBootstrapCache) : null;
|
|
24922
24565
|
const runExitClosureOwnership = directAttestationInput ? {
|
|
24923
24566
|
cache: ownershipStatSyncImpl(directAttestationInput.cachePath),
|
|
24924
24567
|
manifest: ownershipStatSyncImpl(directAttestationInput.manifestPath),
|
|
@@ -24933,9 +24576,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24933
24576
|
mcpArgsNormalization: "none",
|
|
24934
24577
|
...directCatalog ? {
|
|
24935
24578
|
catalogSetHash: directCatalog.setHash,
|
|
24936
|
-
...
|
|
24937
|
-
effectiveToolProbeBootstrapKey: effectiveToolsBootstrapCache?.key ?? null,
|
|
24938
|
-
effectiveToolProbeBootstrapCache
|
|
24579
|
+
...directAttestationInput.declaredToolContract
|
|
24939
24580
|
} : {},
|
|
24940
24581
|
configMode: "desktop_delegated_runtime_action_bridge",
|
|
24941
24582
|
namespace: SUPPORTED_SERVER_NAME3,
|
|
@@ -33703,11 +33344,11 @@ function resolvePiModelContextBudget({
|
|
|
33703
33344
|
}) {
|
|
33704
33345
|
const instructionBytes = [...finalAgentInstructionFiles.values()].reduce((total, entry) => total + Number(entry.byteSize ?? 0), 0);
|
|
33705
33346
|
const profileAttestation = record7(managedMcpProfile?.attestation);
|
|
33706
|
-
const toolSchemaBytes = Number(profileAttestation.
|
|
33347
|
+
const toolSchemaBytes = Number(profileAttestation.finalRequiredToolSchemaBytes);
|
|
33707
33348
|
if (!Number.isSafeInteger(toolSchemaBytes) || toolSchemaBytes < 1) {
|
|
33708
33349
|
throw stableContextError(
|
|
33709
33350
|
"model_context_attestation_unavailable",
|
|
33710
|
-
"
|
|
33351
|
+
"required governed tool schema size is missing"
|
|
33711
33352
|
);
|
|
33712
33353
|
}
|
|
33713
33354
|
const skillMetadataBytes = Number(profileAttestation.enabledSkillMetadataBytes ?? 0);
|
|
@@ -33736,7 +33377,7 @@ function resolvePiModelContextBudget({
|
|
|
33736
33377
|
knownFixedInputTokens,
|
|
33737
33378
|
fixedInputBreakdown: {
|
|
33738
33379
|
projectInstructionBytes: instructionBytes,
|
|
33739
|
-
|
|
33380
|
+
requiredGovernedToolSchemaBytes: toolSchemaBytes,
|
|
33740
33381
|
skillMetadataBytes
|
|
33741
33382
|
},
|
|
33742
33383
|
dynamicInputTokens,
|
|
@@ -34051,7 +33692,7 @@ function assertRequiredTaskAttachmentMaterialized(input, materialized) {
|
|
|
34051
33692
|
}
|
|
34052
33693
|
|
|
34053
33694
|
// src/amaster-runtime-daemon.mjs
|
|
34054
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
33695
|
+
var CONNECTOR_VERSION = "0.1.1-beta.274";
|
|
34055
33696
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
34056
33697
|
var daemonRequire = createRequire(import.meta.url);
|
|
34057
33698
|
var MAX_CHECKPOINT_BYTES = 20 * 1024 * 1024;
|
|
@@ -35704,11 +35345,12 @@ function requireEffectiveToolSchemaAttestation(contextContract, executorKind, go
|
|
|
35704
35345
|
const attestation = asRecord(managedMcpProfile?.attestation);
|
|
35705
35346
|
const catalogSetHash = readString(attestation.catalogSetHash);
|
|
35706
35347
|
const effectiveToolSetHash = readString(attestation.effectiveToolSetHash);
|
|
35707
|
-
const
|
|
35708
|
-
|
|
35348
|
+
const finalRequiredToolSetHash = readString(attestation.finalRequiredToolSetHash);
|
|
35349
|
+
const catalogToolCount = Array.isArray(catalog.tools) ? catalog.tools.length : 0;
|
|
35350
|
+
if (!/^[a-f0-9]{64}$/.test(declaredSetHash ?? "") || catalogSetHash !== declaredSetHash || readString(attestation.effectiveToolContractSource) !== "governed_catalog" || readString(attestation.effectiveToolValidationMode) !== "same_run_session_start_and_provider_request" || !/^[a-f0-9]{64}$/.test(effectiveToolSetHash ?? "") || !/^[a-f0-9]{64}$/.test(finalRequiredToolSetHash ?? "") || !Number.isSafeInteger(attestation.finalRequiredToolSchemaBytes) || attestation.finalRequiredToolSchemaBytes < 1 || !Number.isSafeInteger(attestation.finalRequiredToolCount) || attestation.finalRequiredToolCount !== catalogToolCount) {
|
|
35709
35351
|
throw stableContextError(
|
|
35710
35352
|
"context_effective_tool_schema_attestation_mismatch",
|
|
35711
|
-
"
|
|
35353
|
+
"the governed Pi tool schema contract is missing or does not match the catalog"
|
|
35712
35354
|
);
|
|
35713
35355
|
}
|
|
35714
35356
|
return {
|
|
@@ -35716,10 +35358,10 @@ function requireEffectiveToolSchemaAttestation(contextContract, executorKind, go
|
|
|
35716
35358
|
executorKind,
|
|
35717
35359
|
declaredCatalogSetHash: declaredSetHash,
|
|
35718
35360
|
effectiveToolSetHash,
|
|
35719
|
-
|
|
35720
|
-
|
|
35721
|
-
|
|
35722
|
-
|
|
35361
|
+
finalRequiredToolSetHash,
|
|
35362
|
+
finalRequiredToolSchemaBytes: attestation.finalRequiredToolSchemaBytes,
|
|
35363
|
+
finalRequiredToolCount: attestation.finalRequiredToolCount,
|
|
35364
|
+
validationMode: attestation.effectiveToolValidationMode,
|
|
35723
35365
|
attestationId: readString(attestation.attestationId)
|
|
35724
35366
|
};
|
|
35725
35367
|
}
|
|
@@ -37387,7 +37029,7 @@ async function executePiTerminalTextRepairTurn(config, command, executor, execut
|
|
|
37387
37029
|
]);
|
|
37388
37030
|
const completionOutputStopped = piCompletionOutputStopped(execution);
|
|
37389
37031
|
const invalidOutput = piOutputValidationError(parsed, {
|
|
37390
|
-
allowMissingTurnEnd:
|
|
37032
|
+
allowMissingTurnEnd: completionOutputStopped || parsed.terminalEventType === "agent_end",
|
|
37391
37033
|
completionOutputType: execution.completionOutputType,
|
|
37392
37034
|
completionOutputHasFinalAssistantText: execution.completionOutputHasFinalAssistantText
|
|
37393
37035
|
});
|
|
@@ -38450,11 +38092,6 @@ function piCompletionCleanupStopped(execution) {
|
|
|
38450
38092
|
function piCompletionOutputStopped(execution) {
|
|
38451
38093
|
return piCompletionCleanupStopped(execution) && PI_COMPLETION_OUTPUT_TYPES.has(readString(execution?.completionOutputType) ?? "") && (execution?.completionOutputType === "approval_required" || execution?.completionOutputHasFinalAssistantText === true);
|
|
38452
38094
|
}
|
|
38453
|
-
function piOutputAllowsMissingTurnEnd(execution, parsed, options = {}) {
|
|
38454
|
-
if (piCompletionOutputStopped(execution)) return true;
|
|
38455
|
-
if (options.allowTerminalAgentEnd === true && parsed?.terminalEventType === "agent_end") return true;
|
|
38456
|
-
return execution?.completionOutputType === "agent_settled" && execution?.completionOutputHasFinalAssistantText === true && execution?.exitCode === 0 && execution?.signal === null;
|
|
38457
|
-
}
|
|
38458
38095
|
function piOutputValidationError(parsed, options = {}) {
|
|
38459
38096
|
if (parsed?.errorMessage) return parsed.errorMessage;
|
|
38460
38097
|
if (options.completionOutputType === "agent_settled" && options.completionOutputHasFinalAssistantText !== true && options.allowMissingFinalAssistantText !== true) {
|
|
@@ -38735,7 +38372,7 @@ async function executeRunCommand(config, command) {
|
|
|
38735
38372
|
if (executor.kind === "pi") {
|
|
38736
38373
|
assertManagedPiNonInteractiveInvocation(invocation.args, managedMcpProfile);
|
|
38737
38374
|
}
|
|
38738
|
-
await ingestLog(config, command, "system", "info", desktopDelegatedRunnerEnabled(config) && executor.kind === "pi" ? "Prepared desktop delegated Pi runtime action bridge" : `Attested isolated ${executor.kind} managed MCP profile`, {
|
|
38375
|
+
await ingestLog(config, command, "system", "info", desktopDelegatedRunnerEnabled(config) && executor.kind === "pi" ? "Prepared desktop delegated Pi runtime action bridge" : executor.kind === "pi" ? "Prepared isolated Pi managed MCP profile" : `Attested isolated ${executor.kind} managed MCP profile`, {
|
|
38739
38376
|
presentationKind: "managed_mcp_attestation",
|
|
38740
38377
|
...managedMcpProfile.attestation
|
|
38741
38378
|
});
|
|
@@ -39298,16 +38935,15 @@ async function executeRunCommand(config, command) {
|
|
|
39298
38935
|
);
|
|
39299
38936
|
}
|
|
39300
38937
|
const parsedForValidation = parsed;
|
|
39301
|
-
const effectiveCompletionOutputHasFinalAssistantText = terminalTextRepair?.succeeded === true ? true : execution.completionOutputHasFinalAssistantText;
|
|
39302
38938
|
const piTurnLimitFailure = executor.kind === "pi" && !cancelled && !hasOutputFlood && !hasArgumentAmplification && !hasMemoryLimit && execution.timedOut !== true && !execution.spawnError ? classifyPiTurnLimitResult(parsedForValidation, {
|
|
39303
38939
|
authoritativeTerminalDisposition: Boolean(terminalRunDisposition)
|
|
39304
38940
|
}) : null;
|
|
39305
38941
|
const piInvalidOutputError = executor.kind === "pi" ? piOutputValidationError(parsedForValidation, {
|
|
39306
|
-
allowMissingTurnEnd:
|
|
38942
|
+
allowMissingTurnEnd: completionOutputStopped,
|
|
39307
38943
|
allowMissingAssistantOutput: execution.completionOutputType === "approval_required" || Boolean(terminalRunDisposition),
|
|
39308
38944
|
allowMissingFinalAssistantText: Boolean(terminalRunDisposition),
|
|
39309
38945
|
completionOutputType: execution.completionOutputType,
|
|
39310
|
-
completionOutputHasFinalAssistantText:
|
|
38946
|
+
completionOutputHasFinalAssistantText: terminalTextRepair?.succeeded === true ? true : execution.completionOutputHasFinalAssistantText
|
|
39311
38947
|
}) : null;
|
|
39312
38948
|
const piOutputFailure = executor.kind === "pi" && !cancelled && !hasOutputFlood && !hasArgumentAmplification && !hasMemoryLimit && execution.timedOut !== true && !execution.spawnError ? classifyPiOutputFailure(parsedForValidation, {
|
|
39313
38949
|
exitCode: execution.exitCode,
|
package/dist/amaster-runtime.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { homedir, hostname } from "node:os";
|
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { BUILD_SUPPORTED_CAPABILITIES } from "./amaster-runtime-daemon/capability-registry.mjs";
|
|
9
9
|
|
|
10
|
-
const CONNECTOR_VERSION = "0.1.1-beta.
|
|
10
|
+
const CONNECTOR_VERSION = "0.1.1-beta.274";
|
|
11
11
|
|
|
12
12
|
const CONFIG_KEY_MAP = new Map([
|
|
13
13
|
["server_url", "AMASTER_EMPLOYEE_SERVER_URL"],
|