@amaster.ai/employee-runtime-connector 0.1.1-beta.14 → 0.1.1-beta.15
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 +8 -0
- package/dist/amaster-runtime-daemon.mjs +181 -115
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,6 +51,14 @@ An enforced stop returns `pi_tool_argument_stream_amplification` with
|
|
|
51
51
|
byte counts, ratios, event/tool identity, thresholds, and near-miss distances;
|
|
52
52
|
it omits the inline argument body.
|
|
53
53
|
|
|
54
|
+
Pi JSON mode can also repeat a cumulative `message` snapshot beside each
|
|
55
|
+
incremental `message_update`. The daemon compacts only that redundant snapshot
|
|
56
|
+
from its retained parse/result buffer while preserving the delta, terminal
|
|
57
|
+
events, live logs, and tool-argument guard input. Output telemetry reports both
|
|
58
|
+
`rawOutputBytes` and `retainedOutputBytes` plus `retentionCompactedBytes`; flood
|
|
59
|
+
limits continue to use raw bytes, so retention compaction never hides transport
|
|
60
|
+
pressure or weakens the 50 MiB safety boundary.
|
|
61
|
+
|
|
54
62
|
## Pi terminal cleanup outcome
|
|
55
63
|
|
|
56
64
|
Pi execution uses three separate evidence layers:
|
|
@@ -244,6 +244,49 @@ function createPiToolArgumentAmplificationTracker(options = {}) {
|
|
|
244
244
|
};
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
// src/amaster-runtime-daemon/pi-output-retention.mjs
|
|
248
|
+
function record2(value) {
|
|
249
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
250
|
+
}
|
|
251
|
+
function compactIncrementalEvent(event) {
|
|
252
|
+
if (event.type !== "message_update") return null;
|
|
253
|
+
const assistantEvent = record2(event.assistantMessageEvent);
|
|
254
|
+
const type = typeof assistantEvent.type === "string" ? assistantEvent.type : "";
|
|
255
|
+
if (!type.endsWith("_delta") && type !== "text_end") return null;
|
|
256
|
+
const compact = { type: "message_update", assistantMessageEvent: { type } };
|
|
257
|
+
if (typeof assistantEvent.delta === "string") compact.assistantMessageEvent.delta = assistantEvent.delta;
|
|
258
|
+
if (typeof assistantEvent.content === "string") compact.assistantMessageEvent.content = assistantEvent.content;
|
|
259
|
+
return compact;
|
|
260
|
+
}
|
|
261
|
+
function compactPiOutputRetentionLine(line) {
|
|
262
|
+
const text = String(line ?? "");
|
|
263
|
+
const trimmed = text.trim();
|
|
264
|
+
if (!trimmed.startsWith("{")) return text;
|
|
265
|
+
try {
|
|
266
|
+
const compact = compactIncrementalEvent(JSON.parse(trimmed));
|
|
267
|
+
return compact ? JSON.stringify(compact) : text;
|
|
268
|
+
} catch {
|
|
269
|
+
return text;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function createPiOutputRetentionCompactor() {
|
|
273
|
+
let buffer = "";
|
|
274
|
+
return {
|
|
275
|
+
write(chunk) {
|
|
276
|
+
const combined = `${buffer}${String(chunk ?? "")}`;
|
|
277
|
+
const lines = combined.split(/\r?\n/);
|
|
278
|
+
buffer = lines.pop() ?? "";
|
|
279
|
+
return lines.map(compactPiOutputRetentionLine).join("\n") + (lines.length > 0 ? "\n" : "");
|
|
280
|
+
},
|
|
281
|
+
flush() {
|
|
282
|
+
if (!buffer) return "";
|
|
283
|
+
const retained = compactPiOutputRetentionLine(buffer);
|
|
284
|
+
buffer = "";
|
|
285
|
+
return retained;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
247
290
|
// src/amaster-runtime-daemon/codex-managed-mcp-profile.mjs
|
|
248
291
|
import { createHash } from "node:crypto";
|
|
249
292
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -1129,7 +1172,7 @@ var SAFE_SHARED_PROVIDER_INTEGER_KEYS = /* @__PURE__ */ new Set([
|
|
|
1129
1172
|
"websocket_connect_timeout_ms"
|
|
1130
1173
|
]);
|
|
1131
1174
|
var BUILT_IN_MODEL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "amazon-bedrock", "ollama", "lmstudio"]);
|
|
1132
|
-
function
|
|
1175
|
+
function record3(value) {
|
|
1133
1176
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
1134
1177
|
}
|
|
1135
1178
|
function nonEmpty(value, label) {
|
|
@@ -1176,7 +1219,7 @@ function findSessionRollout(sessionsRoot, sessionId) {
|
|
|
1176
1219
|
return matches[0];
|
|
1177
1220
|
}
|
|
1178
1221
|
function restoreManagedCodexSessionRollout(input, codexHome, runDir, executorHome, authority) {
|
|
1179
|
-
const session =
|
|
1222
|
+
const session = record3(input.nativeSession);
|
|
1180
1223
|
if (session.mode !== "governed_action_approval" || session.required !== true) return null;
|
|
1181
1224
|
const sessionId = nonEmpty(session.sessionId, "nativeSession.sessionId");
|
|
1182
1225
|
const sourceRunId = nonEmpty(session.sourceRunId, "nativeSession.sourceRunId");
|
|
@@ -1245,14 +1288,14 @@ function sharedCodexModelRoute(sourceHome) {
|
|
|
1245
1288
|
}
|
|
1246
1289
|
const providerId = config.model_provider;
|
|
1247
1290
|
if (!providerId) return { root, table: [], mode: config.model ? "shared_model" : "default", protectedValues: [] };
|
|
1248
|
-
const selectedProvider =
|
|
1291
|
+
const selectedProvider = record3(config.model_providers)[providerId];
|
|
1249
1292
|
if (selectedProvider == null) {
|
|
1250
1293
|
if (!BUILT_IN_MODEL_PROVIDERS.has(providerId)) {
|
|
1251
1294
|
throw new Error(`codex_managed_mcp_source_provider_missing: ${providerId}`);
|
|
1252
1295
|
}
|
|
1253
1296
|
return { root, table: [], mode: "shared_builtin_provider", protectedValues: [] };
|
|
1254
1297
|
}
|
|
1255
|
-
if (Object.keys(
|
|
1298
|
+
if (Object.keys(record3(selectedProvider)).length === 0) {
|
|
1256
1299
|
throw new Error(`codex_managed_mcp_provider_config_invalid: model_providers.${providerId} must be a non-empty table`);
|
|
1257
1300
|
}
|
|
1258
1301
|
const projectedProvider = {};
|
|
@@ -1283,7 +1326,7 @@ function sharedCodexModelRoute(sourceHome) {
|
|
|
1283
1326
|
continue;
|
|
1284
1327
|
}
|
|
1285
1328
|
if (key === "http_headers") {
|
|
1286
|
-
const headers =
|
|
1329
|
+
const headers = record3(value);
|
|
1287
1330
|
if (Object.keys(headers).length === 0 || Object.values(headers).some((entry) => typeof entry !== "string")) {
|
|
1288
1331
|
throw new Error("codex_managed_mcp_provider_config_invalid: http_headers must be a non-empty string table");
|
|
1289
1332
|
}
|
|
@@ -1327,18 +1370,18 @@ function runAttestation(executorCommand, env, cwd, gatewayUrl, expectedHeaders)
|
|
|
1327
1370
|
if (!Array.isArray(servers) || servers.length !== 1) {
|
|
1328
1371
|
throw new Error(`codex_managed_mcp_attestation_failed: expected one MCP server, received ${Array.isArray(servers) ? servers.length : "non_array"}`);
|
|
1329
1372
|
}
|
|
1330
|
-
const server =
|
|
1331
|
-
const transport =
|
|
1332
|
-
const effectiveHeaders =
|
|
1373
|
+
const server = record3(servers[0]);
|
|
1374
|
+
const transport = record3(server.transport);
|
|
1375
|
+
const effectiveHeaders = record3(transport.http_headers);
|
|
1333
1376
|
const headersMatch = Object.keys(effectiveHeaders).length === Object.keys(expectedHeaders).length && Object.entries(expectedHeaders).every(([name, value]) => effectiveHeaders[name] === value);
|
|
1334
|
-
if (server.name !== SUPPORTED_SERVER_NAME || server.enabled !== true || transport.type !== "streamable_http" || transport.url !== gatewayUrl || !headersMatch || Object.keys(
|
|
1377
|
+
if (server.name !== SUPPORTED_SERVER_NAME || server.enabled !== true || transport.type !== "streamable_http" || transport.url !== gatewayUrl || !headersMatch || Object.keys(record3(transport.env_http_headers)).length !== 0 || transport.bearer_token_env_var != null) {
|
|
1335
1378
|
throw new Error("codex_managed_mcp_attestation_failed: effective MCP config does not match managed amaster Gateway");
|
|
1336
1379
|
}
|
|
1337
1380
|
return executorVersion;
|
|
1338
1381
|
}
|
|
1339
1382
|
function validateAuthority(input) {
|
|
1340
|
-
const runtimeAuth =
|
|
1341
|
-
const gateway =
|
|
1383
|
+
const runtimeAuth = record3(input.runtimeAuth);
|
|
1384
|
+
const gateway = record3(runtimeAuth.governedMcp);
|
|
1342
1385
|
const runId = nonEmpty(input.runId, "runId");
|
|
1343
1386
|
if (runtimeAuth.runId !== runId) throw new Error("codex_managed_mcp_owner_mismatch: command runId does not match runtime authority");
|
|
1344
1387
|
if (gateway.schemaVersion !== SUPPORTED_SCHEMA_VERSION) throw new Error("codex_managed_mcp_invalid: unsupported schema version");
|
|
@@ -1354,7 +1397,7 @@ function validateAuthority(input) {
|
|
|
1354
1397
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() + 3e4) {
|
|
1355
1398
|
throw new Error("codex_managed_mcp_session_expired: Gateway session must remain valid through spawn preflight");
|
|
1356
1399
|
}
|
|
1357
|
-
const headers =
|
|
1400
|
+
const headers = record3(gateway.headers);
|
|
1358
1401
|
for (const name of REQUIRED_AUTHORITY_HEADERS) nonEmpty(headers[name], `headers.${name}`);
|
|
1359
1402
|
const allowedHeaderNames = /* @__PURE__ */ new Set([...REQUIRED_AUTHORITY_HEADERS, ...runtimeAuth.issueId ? ["x-amaster-issue-id"] : []]);
|
|
1360
1403
|
if (Object.keys(headers).some((name) => !allowedHeaderNames.has(name)) || Object.keys(headers).length !== allowedHeaderNames.size) {
|
|
@@ -1371,7 +1414,7 @@ function validateAuthority(input) {
|
|
|
1371
1414
|
return { gateway, gatewayUrl, sessionToken, headers, runId };
|
|
1372
1415
|
}
|
|
1373
1416
|
function assertInvocationIsolation(input) {
|
|
1374
|
-
for (const name of Object.keys(
|
|
1417
|
+
for (const name of Object.keys(record3(input.commandEnv))) {
|
|
1375
1418
|
if (FORBIDDEN_COMMAND_ENV.has(name)) throw new Error(`codex_managed_mcp_env_override_blocked: ${name}`);
|
|
1376
1419
|
if (!ALLOWED_COMMAND_ENV.has(name)) throw new Error(`codex_managed_mcp_env_injection_blocked: ${name}`);
|
|
1377
1420
|
}
|
|
@@ -1438,7 +1481,7 @@ function buildIsolatedEnvironment(baseEnv, commandEnv) {
|
|
|
1438
1481
|
const value = safeProxyValue(baseEnv?.[name], name);
|
|
1439
1482
|
if (value) env[name] = value;
|
|
1440
1483
|
}
|
|
1441
|
-
return { ...env, ...
|
|
1484
|
+
return { ...env, ...record3(commandEnv) };
|
|
1442
1485
|
}
|
|
1443
1486
|
function assertNoProjectAmasterOverride(cwd, runDir) {
|
|
1444
1487
|
let cursor = resolve(cwd);
|
|
@@ -1520,7 +1563,7 @@ function prepareManagedCodexMcpProfile(input) {
|
|
|
1520
1563
|
const owner = Object.freeze({ commandId: input.commandId, runId });
|
|
1521
1564
|
writePrivateFile(markerPath, `${JSON.stringify({ version: 1, ...owner, profileRoot })}
|
|
1522
1565
|
`);
|
|
1523
|
-
const runtimeAuth =
|
|
1566
|
+
const runtimeAuth = record3(input.runtimeAuth);
|
|
1524
1567
|
const authority = Object.freeze({
|
|
1525
1568
|
companyId: nonEmpty(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
1526
1569
|
agentId: nonEmpty(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -2502,7 +2545,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2502
2545
|
const PI_ATTESTATION_MAX_ATTEMPTS = 2;
|
|
2503
2546
|
const PI_ATTESTATION_RECENT_LIVE_TTL_MS = Number.isFinite(options.recentLiveTtlMs) && options.recentLiveTtlMs > 0 ? options.recentLiveTtlMs : 30 * 60 * 1e3;
|
|
2504
2547
|
const recentLivePiVersionProbes = /* @__PURE__ */ new Map();
|
|
2505
|
-
function
|
|
2548
|
+
function record8(value) {
|
|
2506
2549
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
2507
2550
|
}
|
|
2508
2551
|
function readJsonObjectFile(filePath) {
|
|
@@ -2570,7 +2613,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2570
2613
|
return matches[0];
|
|
2571
2614
|
}
|
|
2572
2615
|
function restoreManagedPiSessionRollout(input, sessionsRoot, runDir, executorHome, authority) {
|
|
2573
|
-
const session =
|
|
2616
|
+
const session = record8(input.nativeSession);
|
|
2574
2617
|
if (session.mode !== "governed_action_approval" || session.required !== true) return null;
|
|
2575
2618
|
const sessionId = nonEmpty2(session.sessionId, "nativeSession.sessionId");
|
|
2576
2619
|
const sourceRunId = nonEmpty2(session.sourceRunId, "nativeSession.sourceRunId");
|
|
@@ -2643,11 +2686,11 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2643
2686
|
}));
|
|
2644
2687
|
}
|
|
2645
2688
|
function validateDirectCatalog(gateway) {
|
|
2646
|
-
const catalog =
|
|
2689
|
+
const catalog = record8(gateway.toolCatalog);
|
|
2647
2690
|
if (catalog.schemaVersion !== DIRECT_CATALOG_SCHEMA_VERSION) {
|
|
2648
2691
|
throw new Error("pi_managed_mcp_invalid: direct tool catalog schema mismatch");
|
|
2649
2692
|
}
|
|
2650
|
-
const tools = Array.isArray(catalog.tools) ? catalog.tools.map(
|
|
2693
|
+
const tools = Array.isArray(catalog.tools) ? catalog.tools.map(record8) : [];
|
|
2651
2694
|
if (tools.length !== DIRECT_TYPED_V1_TOOL_NAMES.size) {
|
|
2652
2695
|
throw new Error("pi_managed_mcp_invalid: direct tool catalog size mismatch");
|
|
2653
2696
|
}
|
|
@@ -2667,7 +2710,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2667
2710
|
throw new Error(`pi_managed_mcp_invalid: direct tool exposed name collision for ${exposedName}`);
|
|
2668
2711
|
}
|
|
2669
2712
|
exposedNames.add(exposedName);
|
|
2670
|
-
const inputSchema =
|
|
2713
|
+
const inputSchema = record8(tool.inputSchema);
|
|
2671
2714
|
if (inputSchema.type !== "object" || inputSchema.additionalProperties !== false) {
|
|
2672
2715
|
throw new Error(`pi_managed_mcp_invalid: direct tool schema is not strict for ${name}`);
|
|
2673
2716
|
}
|
|
@@ -2743,8 +2786,8 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2743
2786
|
}
|
|
2744
2787
|
}
|
|
2745
2788
|
function validateAuthority2(input) {
|
|
2746
|
-
const runtimeAuth =
|
|
2747
|
-
const gateway =
|
|
2789
|
+
const runtimeAuth = record8(input.runtimeAuth);
|
|
2790
|
+
const gateway = record8(runtimeAuth.governedMcp);
|
|
2748
2791
|
const runId = nonEmpty2(input.runId, "runId");
|
|
2749
2792
|
if (runtimeAuth.runId !== runId) throw new Error("pi_managed_mcp_owner_mismatch: command runId does not match runtime authority");
|
|
2750
2793
|
if (gateway.schemaVersion !== SUPPORTED_SCHEMA_VERSION2) throw new Error("pi_managed_mcp_invalid: unsupported schema version");
|
|
@@ -2760,7 +2803,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2760
2803
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() + 3e4) {
|
|
2761
2804
|
throw new Error("pi_managed_mcp_session_expired: Gateway session must remain valid through spawn preflight");
|
|
2762
2805
|
}
|
|
2763
|
-
const headers =
|
|
2806
|
+
const headers = record8(gateway.headers);
|
|
2764
2807
|
for (const name of REQUIRED_AUTHORITY_HEADERS2) nonEmpty2(headers[name], `headers.${name}`);
|
|
2765
2808
|
const allowedHeaderNames = /* @__PURE__ */ new Set([...REQUIRED_AUTHORITY_HEADERS2, ...runtimeAuth.issueId ? ["x-amaster-issue-id"] : []]);
|
|
2766
2809
|
if (Object.keys(headers).some((name) => !allowedHeaderNames.has(name)) || Object.keys(headers).length !== allowedHeaderNames.size) {
|
|
@@ -2797,7 +2840,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2797
2840
|
return output;
|
|
2798
2841
|
}
|
|
2799
2842
|
function assertInvocationIsolation2(input) {
|
|
2800
|
-
for (const name of Object.keys(
|
|
2843
|
+
for (const name of Object.keys(record8(input.commandEnv))) {
|
|
2801
2844
|
if (FORBIDDEN_COMMAND_ENV2.has(name)) throw new Error(`pi_managed_mcp_env_override_blocked: ${name}`);
|
|
2802
2845
|
if (!ALLOWED_COMMAND_ENV2.has(name)) throw new Error(`pi_managed_mcp_env_injection_blocked: ${name}`);
|
|
2803
2846
|
}
|
|
@@ -2829,7 +2872,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2829
2872
|
const value = safeProxyValue2(baseEnv?.[name], name);
|
|
2830
2873
|
if (value) env[name] = value;
|
|
2831
2874
|
}
|
|
2832
|
-
return { ...env, ...
|
|
2875
|
+
return { ...env, ...record8(commandEnv) };
|
|
2833
2876
|
}
|
|
2834
2877
|
function projectMcpConfigHasContent(filePath) {
|
|
2835
2878
|
if (!existsSync3(filePath)) return false;
|
|
@@ -2839,8 +2882,8 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2839
2882
|
} catch {
|
|
2840
2883
|
return true;
|
|
2841
2884
|
}
|
|
2842
|
-
const config =
|
|
2843
|
-
return Object.keys(
|
|
2885
|
+
const config = record8(parsed);
|
|
2886
|
+
return Object.keys(record8(config.mcpServers)).length > 0 || Object.keys(record8(config.servers)).length > 0 || Array.isArray(config.imports) && config.imports.length > 0;
|
|
2844
2887
|
}
|
|
2845
2888
|
function assertNoProjectMcpOverride(cwd, runDir) {
|
|
2846
2889
|
let cursor = resolve2(cwd);
|
|
@@ -2856,7 +2899,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2856
2899
|
}
|
|
2857
2900
|
}
|
|
2858
2901
|
function selectManagedBrowserUse(sourceSettings, npmSource) {
|
|
2859
|
-
const plugin =
|
|
2902
|
+
const plugin = record8(record8(sourceSettings.plugins)[MANAGED_BROWSER_USE_PLUGIN]);
|
|
2860
2903
|
if (plugin.enabled !== true || plugin.package !== MANAGED_BROWSER_USE_PACKAGE) return null;
|
|
2861
2904
|
const packageSpec = Array.isArray(sourceSettings.packages) ? sourceSettings.packages.find((entry) => npmPackageName(entry) === MANAGED_BROWSER_USE_PACKAGE) : null;
|
|
2862
2905
|
if (typeof packageSpec !== "string") return null;
|
|
@@ -2873,7 +2916,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2873
2916
|
if (packageMetadata.name !== MANAGED_BROWSER_USE_PACKAGE) {
|
|
2874
2917
|
throw new Error(`pi_managed_mcp_attestation_failed: enabled ${MANAGED_BROWSER_USE_PACKAGE} package identity mismatch`);
|
|
2875
2918
|
}
|
|
2876
|
-
const sourceConfig =
|
|
2919
|
+
const sourceConfig = record8(sourceSettings["pi-browser-use"]);
|
|
2877
2920
|
const config = {};
|
|
2878
2921
|
for (const key of MANAGED_BROWSER_USE_BOOLEAN_SETTINGS) {
|
|
2879
2922
|
if (typeof sourceConfig[key] === "boolean") config[key] = sourceConfig[key];
|
|
@@ -2923,7 +2966,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2923
2966
|
}
|
|
2924
2967
|
return {
|
|
2925
2968
|
packageSpec,
|
|
2926
|
-
config:
|
|
2969
|
+
config: record8(sourceSettings["pi-web-access"])
|
|
2927
2970
|
};
|
|
2928
2971
|
}
|
|
2929
2972
|
function selectManagedTelemetry(sourceSettings, npmSource) {
|
|
@@ -2944,7 +2987,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2944
2987
|
}
|
|
2945
2988
|
return {
|
|
2946
2989
|
packageSpec,
|
|
2947
|
-
config:
|
|
2990
|
+
config: record8(sourceSettings["pi-telemetry"])
|
|
2948
2991
|
};
|
|
2949
2992
|
}
|
|
2950
2993
|
function seedPiRuntime(sourceHome, agentDir, sourceAcquisition = null, mcpToolMode = MANAGED_PI_MCP_TOOL_MODE) {
|
|
@@ -2970,7 +3013,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2970
3013
|
let sourceSettings = {};
|
|
2971
3014
|
if (existsSync3(settingsSource)) {
|
|
2972
3015
|
try {
|
|
2973
|
-
sourceSettings =
|
|
3016
|
+
sourceSettings = record8(JSON.parse(readFileSync3(settingsSource, "utf8")));
|
|
2974
3017
|
} catch {
|
|
2975
3018
|
throw new Error("pi_managed_mcp_attestation_failed: source Pi settings are invalid");
|
|
2976
3019
|
}
|
|
@@ -3208,7 +3251,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3208
3251
|
const owner = Object.freeze({ commandId: input.commandId, runId });
|
|
3209
3252
|
writePrivateFile2(markerPath, `${JSON.stringify({ version: 1, ...owner, profileRoot })}
|
|
3210
3253
|
`);
|
|
3211
|
-
const runtimeAuth =
|
|
3254
|
+
const runtimeAuth = record8(input.runtimeAuth);
|
|
3212
3255
|
const authority = Object.freeze({
|
|
3213
3256
|
companyId: nonEmpty2(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
3214
3257
|
agentId: nonEmpty2(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -3382,7 +3425,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3382
3425
|
const owner = Object.freeze({ commandId: input.commandId, runId });
|
|
3383
3426
|
writePrivateFile2(markerPath, `${JSON.stringify({ version: 1, ...owner, profileRoot, piCodingAgentDir })}
|
|
3384
3427
|
`);
|
|
3385
|
-
const runtimeAuth =
|
|
3428
|
+
const runtimeAuth = record8(input.runtimeAuth);
|
|
3386
3429
|
const authority = Object.freeze({
|
|
3387
3430
|
companyId: nonEmpty2(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
3388
3431
|
agentId: nonEmpty2(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -3409,11 +3452,11 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3409
3452
|
const config = {
|
|
3410
3453
|
...sourceMcp,
|
|
3411
3454
|
settings: {
|
|
3412
|
-
...
|
|
3455
|
+
...record8(sourceMcp.settings),
|
|
3413
3456
|
...directCatalog ? { disableProxyTool: true } : {}
|
|
3414
3457
|
},
|
|
3415
3458
|
mcpServers: {
|
|
3416
|
-
...
|
|
3459
|
+
...record8(sourceMcp.mcpServers),
|
|
3417
3460
|
[SUPPORTED_SERVER_NAME2]: serverConfig
|
|
3418
3461
|
}
|
|
3419
3462
|
};
|
|
@@ -3421,7 +3464,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3421
3464
|
`);
|
|
3422
3465
|
const env = {
|
|
3423
3466
|
...input.baseEnv,
|
|
3424
|
-
...
|
|
3467
|
+
...record8(input.commandEnv),
|
|
3425
3468
|
PI_AGENT_HOME: sourcePiHome,
|
|
3426
3469
|
PI_CODING_AGENT_DIR: piCodingAgentDir,
|
|
3427
3470
|
"AMASTER-CLI_CODING_AGENT_DIR": piCodingAgentDir,
|
|
@@ -3692,11 +3735,11 @@ function signalExecutorProcess(child, signal, processGroupId = processGroupIdFor
|
|
|
3692
3735
|
}
|
|
3693
3736
|
|
|
3694
3737
|
// src/amaster-runtime-daemon/executor-spawn.mjs
|
|
3695
|
-
function
|
|
3738
|
+
function record4(value) {
|
|
3696
3739
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3697
3740
|
}
|
|
3698
3741
|
function managedChildSpawnInvocation(command, args, requestedIdentity) {
|
|
3699
|
-
const identity2 =
|
|
3742
|
+
const identity2 = record4(requestedIdentity);
|
|
3700
3743
|
const childUmask = identity2.umask;
|
|
3701
3744
|
if (childUmask !== void 0 && (!Number.isInteger(childUmask) || childUmask < 0 || childUmask > 511)) {
|
|
3702
3745
|
throw new Error("executor_spawn_umask_invalid");
|
|
@@ -3725,8 +3768,8 @@ function resultOutboxFileName(commandId, now = Date.now()) {
|
|
|
3725
3768
|
return `${now}-${safeCommandId}.json`;
|
|
3726
3769
|
}
|
|
3727
3770
|
function isValidResultOutboxEntry(entry) {
|
|
3728
|
-
const
|
|
3729
|
-
return
|
|
3771
|
+
const record8 = asRecord(entry);
|
|
3772
|
+
return record8.version === 1 && Boolean(readString(record8.path)) && Object.keys(asRecord(record8.payload)).length > 0;
|
|
3730
3773
|
}
|
|
3731
3774
|
function resultOutboxEntryAgeMs(entry, nowMs) {
|
|
3732
3775
|
const createdAt = Date.parse(readString(entry.createdAt) ?? "");
|
|
@@ -3780,7 +3823,7 @@ var PHASE_TRANSITIONS = /* @__PURE__ */ new Map([
|
|
|
3780
3823
|
["profile_cleanup:profile_cleanup_abandoned", "result_post_pending"],
|
|
3781
3824
|
["result_post_pending:result_post_delivered", "terminal"]
|
|
3782
3825
|
]);
|
|
3783
|
-
function
|
|
3826
|
+
function record5(value) {
|
|
3784
3827
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3785
3828
|
}
|
|
3786
3829
|
function nonEmptyString(value, label) {
|
|
@@ -3805,8 +3848,8 @@ function runCompletionStateFileName(commandId) {
|
|
|
3805
3848
|
return `${safeCommandId}.json`;
|
|
3806
3849
|
}
|
|
3807
3850
|
function normalizeRunTurnUsage(turn) {
|
|
3808
|
-
const source =
|
|
3809
|
-
const nestedUsage =
|
|
3851
|
+
const source = record5(turn);
|
|
3852
|
+
const nestedUsage = record5(source.usage);
|
|
3810
3853
|
const usage = Object.keys(nestedUsage).length > 0 ? nestedUsage : source;
|
|
3811
3854
|
return {
|
|
3812
3855
|
turn: source.turn === "closure" ? "closure" : "primary",
|
|
@@ -3839,11 +3882,11 @@ function aggregateRunTurnUsage(turns) {
|
|
|
3839
3882
|
};
|
|
3840
3883
|
}
|
|
3841
3884
|
function createRunCompletionState(input) {
|
|
3842
|
-
const command =
|
|
3885
|
+
const command = record5(input.command);
|
|
3843
3886
|
const commandId = nonEmptyString(command.commandId ?? command.id, "command.commandId");
|
|
3844
3887
|
const connectorId = nonEmptyString(input.connectorId ?? command.connectorId, "connectorId");
|
|
3845
3888
|
const now = typeof input.now === "string" && input.now ? input.now : (/* @__PURE__ */ new Date()).toISOString();
|
|
3846
|
-
const firstTurn = normalizeRunTurnUsage({ ...
|
|
3889
|
+
const firstTurn = normalizeRunTurnUsage({ ...record5(input.turn), turn: "primary", recordedAt: now });
|
|
3847
3890
|
return {
|
|
3848
3891
|
version: RUN_COMPLETION_STATE_VERSION,
|
|
3849
3892
|
commandId,
|
|
@@ -3851,10 +3894,10 @@ function createRunCompletionState(input) {
|
|
|
3851
3894
|
phase: "usage_snapshot_persisted",
|
|
3852
3895
|
closureAttempt: 0,
|
|
3853
3896
|
command,
|
|
3854
|
-
executor:
|
|
3855
|
-
completionRequest:
|
|
3897
|
+
executor: record5(input.executor),
|
|
3898
|
+
completionRequest: record5(input.completionRequest),
|
|
3856
3899
|
candidateStatus: nonEmptyString(input.candidateStatus, "candidateStatus"),
|
|
3857
|
-
candidateResult:
|
|
3900
|
+
candidateResult: record5(input.candidateResult),
|
|
3858
3901
|
...typeof input.candidateError === "string" && input.candidateError ? { candidateError: input.candidateError } : {},
|
|
3859
3902
|
usageRecord: {
|
|
3860
3903
|
schemaVersion: RUN_COMPLETION_USAGE_SCHEMA_VERSION,
|
|
@@ -3894,7 +3937,7 @@ function transitionRunCompletionState(state, event, patch = {}, now = (/* @__PUR
|
|
|
3894
3937
|
}
|
|
3895
3938
|
return assertValidRunCompletionState({
|
|
3896
3939
|
...current,
|
|
3897
|
-
...
|
|
3940
|
+
...record5(patch),
|
|
3898
3941
|
phase: nextPhase,
|
|
3899
3942
|
updatedAt: now
|
|
3900
3943
|
});
|
|
@@ -3907,24 +3950,24 @@ function markRunCompletionCostDelivered(state, receipt, now = (/* @__PURE__ */ n
|
|
|
3907
3950
|
...current.usageRecord,
|
|
3908
3951
|
ingestStatus: "delivered",
|
|
3909
3952
|
deliveredAt: now,
|
|
3910
|
-
receipt:
|
|
3953
|
+
receipt: record5(receipt)
|
|
3911
3954
|
}
|
|
3912
3955
|
}, "cost_ingest_delivered", {}, now);
|
|
3913
3956
|
}
|
|
3914
3957
|
function assertValidRunCompletionState(value) {
|
|
3915
|
-
const state =
|
|
3958
|
+
const state = record5(value);
|
|
3916
3959
|
if (state.version !== RUN_COMPLETION_STATE_VERSION) throw new Error("run_completion_state_invalid:version");
|
|
3917
3960
|
const commandId = nonEmptyString(state.commandId, "commandId");
|
|
3918
3961
|
const connectorId = nonEmptyString(state.connectorId, "connectorId");
|
|
3919
3962
|
if (!RUN_COMPLETION_PHASES.has(state.phase)) throw new Error("run_completion_state_invalid:phase");
|
|
3920
|
-
const command =
|
|
3963
|
+
const command = record5(state.command);
|
|
3921
3964
|
if (nonEmptyString(command.commandId ?? command.id, "command.commandId") !== commandId) {
|
|
3922
3965
|
throw new Error("run_completion_state_invalid:command_binding");
|
|
3923
3966
|
}
|
|
3924
3967
|
if (nonEmptyString(command.connectorId, "command.connectorId") !== connectorId) {
|
|
3925
3968
|
throw new Error("run_completion_state_invalid:connector_binding");
|
|
3926
3969
|
}
|
|
3927
|
-
const usageRecord =
|
|
3970
|
+
const usageRecord = record5(state.usageRecord);
|
|
3928
3971
|
if (usageRecord.schemaVersion !== RUN_COMPLETION_USAGE_SCHEMA_VERSION) {
|
|
3929
3972
|
throw new Error("run_completion_state_invalid:usage_schema");
|
|
3930
3973
|
}
|
|
@@ -3944,9 +3987,9 @@ function assertValidRunCompletionState(value) {
|
|
|
3944
3987
|
commandId,
|
|
3945
3988
|
connectorId,
|
|
3946
3989
|
command,
|
|
3947
|
-
executor:
|
|
3948
|
-
completionRequest:
|
|
3949
|
-
candidateResult:
|
|
3990
|
+
executor: record5(state.executor),
|
|
3991
|
+
completionRequest: record5(state.completionRequest),
|
|
3992
|
+
candidateResult: record5(state.candidateResult),
|
|
3950
3993
|
usageRecord: {
|
|
3951
3994
|
...usageRecord,
|
|
3952
3995
|
turns,
|
|
@@ -3978,7 +4021,7 @@ function removeRunCompletionState(directory, commandId) {
|
|
|
3978
4021
|
}
|
|
3979
4022
|
|
|
3980
4023
|
// src/amaster-runtime-daemon/source-output-retention.mjs
|
|
3981
|
-
function
|
|
4024
|
+
function record6(value) {
|
|
3982
4025
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3983
4026
|
}
|
|
3984
4027
|
function string(value) {
|
|
@@ -3986,7 +4029,7 @@ function string(value) {
|
|
|
3986
4029
|
}
|
|
3987
4030
|
function retainedSourceExecutorEntry(entry, executorKind) {
|
|
3988
4031
|
if (!entry) return null;
|
|
3989
|
-
const payload =
|
|
4032
|
+
const payload = record6(entry.payload);
|
|
3990
4033
|
if (string(payload.presentationKind) !== "error") return null;
|
|
3991
4034
|
return {
|
|
3992
4035
|
stream: "system",
|
|
@@ -4049,19 +4092,19 @@ function promptContextMode(input) {
|
|
|
4049
4092
|
}
|
|
4050
4093
|
function filterDuplicatedTaskComments(context, mode) {
|
|
4051
4094
|
if (mode !== "cold") return context;
|
|
4052
|
-
const
|
|
4095
|
+
const record8 = asRecord(context);
|
|
4053
4096
|
const included = new Set(
|
|
4054
|
-
(Array.isArray(
|
|
4097
|
+
(Array.isArray(record8.paperclipTaskMarkdownCommentIds) ? record8.paperclipTaskMarkdownCommentIds : []).map((entry) => readString(entry)).filter(Boolean)
|
|
4055
4098
|
);
|
|
4056
4099
|
if (included.size === 0) return context;
|
|
4057
|
-
const wake = asRecord(
|
|
4100
|
+
const wake = asRecord(record8.paperclipWake);
|
|
4058
4101
|
const comments = Array.isArray(wake.comments) ? wake.comments : [];
|
|
4059
4102
|
const kept = comments.filter((entry) => {
|
|
4060
4103
|
const id = readString(asRecord(entry).id);
|
|
4061
4104
|
return !id || !included.has(id);
|
|
4062
4105
|
});
|
|
4063
4106
|
if (kept.length === comments.length) return context;
|
|
4064
|
-
return { ...
|
|
4107
|
+
return { ...record8, paperclipWake: { ...wake, comments: kept } };
|
|
4065
4108
|
}
|
|
4066
4109
|
function commentRefs(context) {
|
|
4067
4110
|
const comments = Array.isArray(asRecord(context.paperclipWake).comments) ? asRecord(context.paperclipWake).comments : [];
|
|
@@ -4099,8 +4142,8 @@ function governedReadSection(context) {
|
|
|
4099
4142
|
const reads = Array.isArray(context.governedReadResults) ? context.governedReadResults : [];
|
|
4100
4143
|
if (reads.length === 0) return { content: "", provenance: [] };
|
|
4101
4144
|
const normalized = reads.map((entry, index) => {
|
|
4102
|
-
const
|
|
4103
|
-
const receipt = asRecord(
|
|
4145
|
+
const record8 = asRecord(entry);
|
|
4146
|
+
const receipt = asRecord(record8.receipt);
|
|
4104
4147
|
const provider = readString(receipt.provider) ?? readString(receipt.transport);
|
|
4105
4148
|
const operation = readString(receipt.operation);
|
|
4106
4149
|
const observedAt = readString(receipt.retrievedAt) ?? readString(receipt.observedAt);
|
|
@@ -4110,7 +4153,7 @@ function governedReadSection(context) {
|
|
|
4110
4153
|
throw new Error(`governed_read_context_provenance_invalid: entry ${index} requires provider, operation, observedAt, and source`);
|
|
4111
4154
|
}
|
|
4112
4155
|
return {
|
|
4113
|
-
content:
|
|
4156
|
+
content: record8.content,
|
|
4114
4157
|
receipt: {
|
|
4115
4158
|
provider,
|
|
4116
4159
|
operation,
|
|
@@ -4135,10 +4178,10 @@ function governedReadSection(context) {
|
|
|
4135
4178
|
}
|
|
4136
4179
|
function canonicalJsonValue(value) {
|
|
4137
4180
|
if (Array.isArray(value)) return value.map(canonicalJsonValue);
|
|
4138
|
-
const
|
|
4139
|
-
if (Object.keys(
|
|
4181
|
+
const record8 = asRecord(value);
|
|
4182
|
+
if (Object.keys(record8).length === 0) return value;
|
|
4140
4183
|
return Object.fromEntries(
|
|
4141
|
-
Object.keys(
|
|
4184
|
+
Object.keys(record8).sort().map((key) => [key, canonicalJsonValue(record8[key])])
|
|
4142
4185
|
);
|
|
4143
4186
|
}
|
|
4144
4187
|
function resolvedDependencySections(context, input, contextScope, snapshotFreshness) {
|
|
@@ -5408,10 +5451,10 @@ function compactExecutorJsonlForTranscript(event) {
|
|
|
5408
5451
|
const text = JSON.stringify(compactExecutorJsonValue(event, stringMaxChars));
|
|
5409
5452
|
if (text.length <= 15e3) return text;
|
|
5410
5453
|
}
|
|
5411
|
-
const
|
|
5412
|
-
const item = tcAsRecord(
|
|
5454
|
+
const record8 = tcAsRecord(event);
|
|
5455
|
+
const item = tcAsRecord(record8.item);
|
|
5413
5456
|
return JSON.stringify({
|
|
5414
|
-
type: tcReadString(
|
|
5457
|
+
type: tcReadString(record8.type) ?? "executor.event",
|
|
5415
5458
|
item: item.type ? {
|
|
5416
5459
|
id: tcReadString(item.id),
|
|
5417
5460
|
type: tcReadString(item.type),
|
|
@@ -5424,10 +5467,10 @@ function compactExecutorJsonlForTranscript(event) {
|
|
|
5424
5467
|
});
|
|
5425
5468
|
}
|
|
5426
5469
|
function summarizeTokenUsage(usage) {
|
|
5427
|
-
const
|
|
5428
|
-
const inputTokens = tcReadNumber(
|
|
5429
|
-
const cachedInputTokens = tcReadNumber(
|
|
5430
|
-
const outputTokens = tcReadNumber(
|
|
5470
|
+
const record8 = tcAsRecord(usage);
|
|
5471
|
+
const inputTokens = tcReadNumber(record8.input_tokens ?? record8.inputTokens, 0);
|
|
5472
|
+
const cachedInputTokens = tcReadNumber(record8.cached_input_tokens ?? record8.cachedInputTokens, 0);
|
|
5473
|
+
const outputTokens = tcReadNumber(record8.output_tokens ?? record8.outputTokens, 0);
|
|
5431
5474
|
const parts = [];
|
|
5432
5475
|
if (inputTokens > 0) parts.push(`\u8F93\u5165 ${inputTokens}`);
|
|
5433
5476
|
if (cachedInputTokens > 0) parts.push(`\u7F13\u5B58 ${cachedInputTokens}`);
|
|
@@ -5682,8 +5725,8 @@ function summarizeClaudeEvent(event) {
|
|
|
5682
5725
|
return null;
|
|
5683
5726
|
}
|
|
5684
5727
|
function tcPiMessageText(message) {
|
|
5685
|
-
const
|
|
5686
|
-
const content =
|
|
5728
|
+
const record8 = tcAsRecord(message);
|
|
5729
|
+
const content = record8.content;
|
|
5687
5730
|
if (typeof content === "string" && content.trim().length > 0) return content.trim();
|
|
5688
5731
|
if (!Array.isArray(content)) return "";
|
|
5689
5732
|
return content.map((entry) => {
|
|
@@ -5697,14 +5740,14 @@ function tcPiAssistantMessageEventText(assistantMessageEvent) {
|
|
|
5697
5740
|
return tcReadString(event.content) ?? "";
|
|
5698
5741
|
}
|
|
5699
5742
|
function tcPiMessageStopReason(message) {
|
|
5700
|
-
const
|
|
5701
|
-
return tcReadString(
|
|
5743
|
+
const record8 = tcAsRecord(message);
|
|
5744
|
+
return tcReadString(record8.stopReason ?? record8.stop_reason);
|
|
5702
5745
|
}
|
|
5703
5746
|
function tcPiMessageErrorText(message) {
|
|
5704
|
-
const
|
|
5705
|
-
const explicitError = tcReadString(
|
|
5747
|
+
const record8 = tcAsRecord(message);
|
|
5748
|
+
const explicitError = tcReadString(record8.errorMessage ?? record8.error_message)?.trim();
|
|
5706
5749
|
if (explicitError) return explicitError;
|
|
5707
|
-
const stopReason = tcPiMessageStopReason(
|
|
5750
|
+
const stopReason = tcPiMessageStopReason(record8);
|
|
5708
5751
|
if (stopReason === "error" || stopReason === "failed" || stopReason === "exception") {
|
|
5709
5752
|
return `Pi Agent message ended with stopReason=${stopReason}`;
|
|
5710
5753
|
}
|
|
@@ -6327,13 +6370,13 @@ function parseClaudeStreamJson(stdout) {
|
|
|
6327
6370
|
}
|
|
6328
6371
|
function openCodeErrorText(value) {
|
|
6329
6372
|
if (typeof value === "string") return value;
|
|
6330
|
-
const
|
|
6331
|
-
const message = readString(
|
|
6373
|
+
const record8 = asRecord(value);
|
|
6374
|
+
const message = readString(record8.message);
|
|
6332
6375
|
if (message) return message;
|
|
6333
|
-
const data = asRecord(
|
|
6376
|
+
const data = asRecord(record8.data);
|
|
6334
6377
|
const nestedMessage = readString(data.message);
|
|
6335
6378
|
if (nestedMessage) return nestedMessage;
|
|
6336
|
-
return readString(
|
|
6379
|
+
return readString(record8.name) ?? readString(record8.code) ?? "";
|
|
6337
6380
|
}
|
|
6338
6381
|
function parseOpenCodeJsonl(stdout) {
|
|
6339
6382
|
let sessionId = null;
|
|
@@ -6371,8 +6414,8 @@ function parseOpenCodeJsonl(stdout) {
|
|
|
6371
6414
|
return { sessionId, summary, usage, errorMessage };
|
|
6372
6415
|
}
|
|
6373
6416
|
function piMessageText(message) {
|
|
6374
|
-
const
|
|
6375
|
-
const content =
|
|
6417
|
+
const record8 = asRecord(message);
|
|
6418
|
+
const content = record8.content;
|
|
6376
6419
|
if (typeof content === "string") return content.trim();
|
|
6377
6420
|
if (!Array.isArray(content)) return "";
|
|
6378
6421
|
return content.map((entry) => {
|
|
@@ -6405,10 +6448,10 @@ function piTextValue(value) {
|
|
|
6405
6448
|
return typeof value === "string" && value.length > 0 ? value : "";
|
|
6406
6449
|
}
|
|
6407
6450
|
function piAssistantEventText(assistantEvent) {
|
|
6408
|
-
const
|
|
6409
|
-
const type = readString(
|
|
6410
|
-
if (type === "text_delta") return piTextValue(
|
|
6411
|
-
if (type === "text_end") return piTextValue(
|
|
6451
|
+
const record8 = asRecord(assistantEvent);
|
|
6452
|
+
const type = readString(record8.type);
|
|
6453
|
+
if (type === "text_delta") return piTextValue(record8.delta);
|
|
6454
|
+
if (type === "text_end") return piTextValue(record8.content);
|
|
6412
6455
|
return "";
|
|
6413
6456
|
}
|
|
6414
6457
|
function piMessageUsage(message) {
|
|
@@ -6429,14 +6472,14 @@ function assignPiUsage(target, source) {
|
|
|
6429
6472
|
if (source.costUsd > 0) target.costUsd = source.costUsd;
|
|
6430
6473
|
}
|
|
6431
6474
|
function piMessageStopReason(message) {
|
|
6432
|
-
const
|
|
6433
|
-
return readString(
|
|
6475
|
+
const record8 = asRecord(message);
|
|
6476
|
+
return readString(record8.stopReason ?? record8.stop_reason);
|
|
6434
6477
|
}
|
|
6435
6478
|
function piMessageErrorText(message) {
|
|
6436
|
-
const
|
|
6437
|
-
const explicitError = readString(
|
|
6479
|
+
const record8 = asRecord(message);
|
|
6480
|
+
const explicitError = readString(record8.errorMessage ?? record8.error_message)?.trim();
|
|
6438
6481
|
if (explicitError) return explicitError;
|
|
6439
|
-
const stopReason = piMessageStopReason(
|
|
6482
|
+
const stopReason = piMessageStopReason(record8);
|
|
6440
6483
|
if (stopReason === "error" || stopReason === "failed" || stopReason === "exception") {
|
|
6441
6484
|
return `Pi Agent message ended with stopReason=${stopReason}`;
|
|
6442
6485
|
}
|
|
@@ -8179,7 +8222,7 @@ function verifyDeclaredFiles(manifest, root, label, ignoredPaths = [], enforceCo
|
|
|
8179
8222
|
};
|
|
8180
8223
|
visit(root);
|
|
8181
8224
|
}
|
|
8182
|
-
function
|
|
8225
|
+
function record7(value) {
|
|
8183
8226
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8184
8227
|
}
|
|
8185
8228
|
function within3(candidate, root) {
|
|
@@ -8284,16 +8327,16 @@ function materializeRoleSkills(seedRoot, agentDir, skillProfile) {
|
|
|
8284
8327
|
return enabled;
|
|
8285
8328
|
}
|
|
8286
8329
|
function mergeMcp(seedRoot, overlayRoot, governedConfig) {
|
|
8287
|
-
const seed =
|
|
8288
|
-
const overlay =
|
|
8330
|
+
const seed = record7(readJsonFile2(join12(seedRoot, "mcp.json"), "seed_mcp", { mcpServers: {} }));
|
|
8331
|
+
const overlay = record7(readJsonFile2(join12(overlayRoot, "mcp.json"), "overlay_mcp", { mcpServers: {} }));
|
|
8289
8332
|
assertNoPersistentSecrets(seed, ["seed", "mcp.json"]);
|
|
8290
8333
|
assertNoPersistentSecrets(overlay, ["overlay", "mcp.json"]);
|
|
8291
|
-
const seedServers =
|
|
8292
|
-
const overlayServers =
|
|
8334
|
+
const seedServers = record7(seed.mcpServers);
|
|
8335
|
+
const overlayServers = record7(overlay.mcpServers);
|
|
8293
8336
|
if ("amaster" in seedServers || "amaster" in overlayServers) {
|
|
8294
8337
|
throw new Error("pi_trusted_runtime_reserved_mcp_override:amaster");
|
|
8295
8338
|
}
|
|
8296
|
-
const governed =
|
|
8339
|
+
const governed = record7(record7(governedConfig).mcpServers).amaster;
|
|
8297
8340
|
if (!governed) throw new Error("pi_trusted_runtime_governed_mcp_missing");
|
|
8298
8341
|
return {
|
|
8299
8342
|
...deepMerge(seed, overlay),
|
|
@@ -8313,8 +8356,8 @@ function assertEnabledPackagesAvailable(settings, npmRoot) {
|
|
|
8313
8356
|
const requiredNames = new Set(
|
|
8314
8357
|
(Array.isArray(settings.packages) ? settings.packages : []).map(packageName).filter(Boolean)
|
|
8315
8358
|
);
|
|
8316
|
-
for (const plugin of Object.values(
|
|
8317
|
-
const config =
|
|
8359
|
+
for (const plugin of Object.values(record7(settings.plugins))) {
|
|
8360
|
+
const config = record7(plugin);
|
|
8318
8361
|
if (config.enabled === true && typeof config.package === "string") {
|
|
8319
8362
|
requiredNames.add(config.package);
|
|
8320
8363
|
}
|
|
@@ -8356,10 +8399,10 @@ function materializeTrustedPiRuntimeProfile(input) {
|
|
|
8356
8399
|
const merged = deepMerge(seed, overlay);
|
|
8357
8400
|
if (entry === "settings.json") {
|
|
8358
8401
|
merged["pi-security"] = {
|
|
8359
|
-
...
|
|
8402
|
+
...record7(merged["pi-security"]),
|
|
8360
8403
|
enabled: true,
|
|
8361
8404
|
approvals: {
|
|
8362
|
-
...
|
|
8405
|
+
...record7(record7(merged["pi-security"]).approvals),
|
|
8363
8406
|
allowSessionGrants: false
|
|
8364
8407
|
}
|
|
8365
8408
|
};
|
|
@@ -8596,8 +8639,8 @@ function verifyTrustedPiRuntimeAssertion(input) {
|
|
|
8596
8639
|
if (assertion.unknownToolMode === "allow_audited_bounded" && maxCalls < 1) {
|
|
8597
8640
|
throw new Error("pi_trusted_runtime_assertion_invalid:directToolBudget.maxCalls");
|
|
8598
8641
|
}
|
|
8599
|
-
const sourceAssertion =
|
|
8600
|
-
const sourceProfile =
|
|
8642
|
+
const sourceAssertion = record7(assertion.sourceAcquisition);
|
|
8643
|
+
const sourceProfile = record7(input.sourceAcquisitionProfile);
|
|
8601
8644
|
const hasSourceAssertion = Object.keys(sourceAssertion).length > 0;
|
|
8602
8645
|
const hasSourceProfile = Object.keys(sourceProfile).length > 0;
|
|
8603
8646
|
if (hasSourceAssertion !== hasSourceProfile) {
|
|
@@ -8605,8 +8648,8 @@ function verifyTrustedPiRuntimeAssertion(input) {
|
|
|
8605
8648
|
}
|
|
8606
8649
|
let sourceAcquisition = null;
|
|
8607
8650
|
if (hasSourceAssertion) {
|
|
8608
|
-
const exactTools = Array.isArray(
|
|
8609
|
-
const exactActions = Array.isArray(
|
|
8651
|
+
const exactTools = Array.isArray(record7(sourceProfile.tools).exactAllowlist) ? record7(sourceProfile.tools).exactAllowlist : [];
|
|
8652
|
+
const exactActions = Array.isArray(record7(sourceProfile.actions).exactAllowlist) ? record7(sourceProfile.actions).exactAllowlist : [];
|
|
8610
8653
|
const profileHash = createHash9("sha256").update(JSON.stringify(sourceProfile)).digest("hex");
|
|
8611
8654
|
if (assertion.unknownToolMode !== "deny" || maxCalls !== 0 || sourceAssertion.profileVersion !== sourceProfile.purpose || sourceAssertion.profileHash !== profileHash || sourceAssertion.retentionVersion !== sourceProfile.retention || JSON.stringify(sourceAssertion.exactTools) !== JSON.stringify(exactTools) || JSON.stringify(sourceAssertion.exactActions) !== JSON.stringify(exactActions) || sourceAssertion.sourceId !== sourceProfile.sourceId || sourceAssertion.sourceRevisionId !== sourceProfile.sourceRevisionId || sourceAssertion.sourceRevision !== sourceProfile.sourceRevision || sourceAssertion.attemptId !== sourceProfile.attemptId || sourceAssertion.epoch !== sourceProfile.epoch) {
|
|
8612
8655
|
throw new Error("pi_trusted_runtime_assertion_binding_mismatch:sourceAcquisition");
|
|
@@ -9503,7 +9546,7 @@ function assertSourceAcquisitionRuntimeAuthority({
|
|
|
9503
9546
|
}
|
|
9504
9547
|
|
|
9505
9548
|
// src/amaster-runtime-daemon.mjs
|
|
9506
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
9549
|
+
var CONNECTOR_VERSION = "0.1.1-beta.15";
|
|
9507
9550
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
9508
9551
|
var SOURCE_ACQUISITION_CAPABILITY = "source_acquisition_v1";
|
|
9509
9552
|
var SOURCE_ACQUISITION_PROFILE_VERSION = "source_acquisition_v1";
|
|
@@ -11620,17 +11663,27 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
11620
11663
|
hasSourceStream(stream) {
|
|
11621
11664
|
return sourceCounts[stream] > 0;
|
|
11622
11665
|
},
|
|
11623
|
-
snapshot({ outputBytes, floodLimitBytes, outputTokens }) {
|
|
11666
|
+
snapshot({ outputBytes, retainedOutputBytes, floodLimitBytes, outputTokens }) {
|
|
11624
11667
|
const rawBytesByStream = {
|
|
11625
11668
|
stdout: readNumber(outputBytes?.stdout, 0),
|
|
11626
11669
|
stderr: readNumber(outputBytes?.stderr, 0)
|
|
11627
11670
|
};
|
|
11671
|
+
const retainedBytesByStream = {
|
|
11672
|
+
stdout: readNumber(retainedOutputBytes?.stdout, rawBytesByStream.stdout),
|
|
11673
|
+
stderr: readNumber(retainedOutputBytes?.stderr, rawBytesByStream.stderr)
|
|
11674
|
+
};
|
|
11628
11675
|
const rawOutputBytes = rawBytesByStream.stdout + rawBytesByStream.stderr;
|
|
11676
|
+
const retainedBytes = retainedBytesByStream.stdout + retainedBytesByStream.stderr;
|
|
11677
|
+
const retentionCompactedBytes = Math.max(0, rawOutputBytes - retainedBytes);
|
|
11629
11678
|
const maxStreamBytes = Math.max(rawBytesByStream.stdout, rawBytesByStream.stderr);
|
|
11630
11679
|
const normalizedFloodLimitBytes = readNumber(floodLimitBytes, 0);
|
|
11631
11680
|
return {
|
|
11632
11681
|
rawBytesByStream,
|
|
11633
11682
|
rawOutputBytes,
|
|
11683
|
+
retainedBytesByStream,
|
|
11684
|
+
retainedOutputBytes: retainedBytes,
|
|
11685
|
+
retentionCompactedBytes,
|
|
11686
|
+
retentionRatio: Number((retainedBytes / Math.max(1, rawOutputBytes)).toFixed(4)),
|
|
11634
11687
|
jsonlEventCount,
|
|
11635
11688
|
meaningfulProgressEventCount,
|
|
11636
11689
|
incrementalEventCount,
|
|
@@ -11962,6 +12015,8 @@ function runExecutor(command, args, options) {
|
|
|
11962
12015
|
const residentSignalledAt = /* @__PURE__ */ new Map();
|
|
11963
12016
|
let piCompletionOutputLineBuffer = "";
|
|
11964
12017
|
const outputBytes = { stdout: 0, stderr: 0 };
|
|
12018
|
+
const retainedOutputBytes = { stdout: 0, stderr: 0 };
|
|
12019
|
+
const piOutputRetentionCompactor = options.executorKind === "pi" ? createPiOutputRetentionCompactor() : null;
|
|
11965
12020
|
const maxOutputBytes = parsePositiveInteger(options.maxOutputBytes, 50 * 1024 * 1024);
|
|
11966
12021
|
const maxRssMb = parsePositiveInteger(options.maxRssMb, 0);
|
|
11967
12022
|
const maxRssBytes = maxRssMb * 1024 * 1024;
|
|
@@ -11978,6 +12033,11 @@ function runExecutor(command, args, options) {
|
|
|
11978
12033
|
const finish = (result3) => {
|
|
11979
12034
|
if (settled) return;
|
|
11980
12035
|
settled = true;
|
|
12036
|
+
if (piOutputRetentionCompactor) {
|
|
12037
|
+
const retainedTail = piOutputRetentionCompactor.flush();
|
|
12038
|
+
retainedOutputBytes.stdout += Buffer.byteLength(retainedTail);
|
|
12039
|
+
stdout = appendBounded(stdout, retainedTail);
|
|
12040
|
+
}
|
|
11981
12041
|
if (timer) clearTimeout(timer);
|
|
11982
12042
|
if (rssTimer) clearInterval(rssTimer);
|
|
11983
12043
|
if (stopKillTimer) clearTimeout(stopKillTimer);
|
|
@@ -11989,6 +12049,7 @@ function runExecutor(command, args, options) {
|
|
|
11989
12049
|
stdout,
|
|
11990
12050
|
stderr,
|
|
11991
12051
|
outputBytes: { ...outputBytes },
|
|
12052
|
+
retainedOutputBytes: { ...retainedOutputBytes },
|
|
11992
12053
|
outputFlood,
|
|
11993
12054
|
argumentAmplification,
|
|
11994
12055
|
memoryLimit,
|
|
@@ -12146,15 +12207,18 @@ function runExecutor(command, args, options) {
|
|
|
12146
12207
|
child.stdout.on("data", (chunk) => {
|
|
12147
12208
|
const text = chunk.toString("utf8");
|
|
12148
12209
|
outputBytes.stdout += chunk.length;
|
|
12149
|
-
stdout = appendBounded(stdout, text);
|
|
12150
12210
|
const outputControl = options.onOutput?.("stdout", text, chunk.length);
|
|
12151
12211
|
if (outputControl?.enforced === true) killForArgumentAmplification(outputControl);
|
|
12152
12212
|
maybeSchedulePiCompletionDrain(text);
|
|
12213
|
+
const retainedText = piOutputRetentionCompactor?.write(text) ?? text;
|
|
12214
|
+
retainedOutputBytes.stdout += Buffer.byteLength(retainedText);
|
|
12215
|
+
stdout = appendBounded(stdout, retainedText);
|
|
12153
12216
|
if (outputBytes.stdout > maxOutputBytes) killForOutputFlood("stdout");
|
|
12154
12217
|
});
|
|
12155
12218
|
child.stderr.on("data", (chunk) => {
|
|
12156
12219
|
const text = chunk.toString("utf8");
|
|
12157
12220
|
outputBytes.stderr += chunk.length;
|
|
12221
|
+
retainedOutputBytes.stderr += chunk.length;
|
|
12158
12222
|
stderr = appendBounded(stderr, text);
|
|
12159
12223
|
options.onOutput?.("stderr", text, chunk.length);
|
|
12160
12224
|
if (outputBytes.stderr > maxOutputBytes) killForOutputFlood("stderr");
|
|
@@ -12643,6 +12707,7 @@ async function executeRunExitClosureTurn(config, inputState, options = {}) {
|
|
|
12643
12707
|
]);
|
|
12644
12708
|
const outputTelemetry = liveOutputLogger.snapshot({
|
|
12645
12709
|
outputBytes: execution.outputBytes,
|
|
12710
|
+
retainedOutputBytes: execution.retainedOutputBytes,
|
|
12646
12711
|
floodLimitBytes: Math.max(1, readNumber(executionConfig.maxOutputBytes, config.executorMaxOutputBytes)),
|
|
12647
12712
|
outputTokens: readNumber(parsed.usage?.outputTokens, 0)
|
|
12648
12713
|
});
|
|
@@ -14368,6 +14433,7 @@ async function executeRunCommand(config, command) {
|
|
|
14368
14433
|
}
|
|
14369
14434
|
const outputTelemetry = liveOutputLogger.snapshot({
|
|
14370
14435
|
outputBytes: execution.outputBytes,
|
|
14436
|
+
retainedOutputBytes: execution.retainedOutputBytes,
|
|
14371
14437
|
floodLimitBytes: config.executorMaxOutputBytes,
|
|
14372
14438
|
outputTokens: readNumber(parsed.usage?.outputTokens, 0)
|
|
14373
14439
|
});
|
package/dist/amaster-runtime.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { basename, dirname, join, resolve } from "node:path";
|
|
|
6
6
|
import { homedir, hostname } from "node:os";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
|
|
9
|
-
const CONNECTOR_VERSION = "0.1.1-beta.
|
|
9
|
+
const CONNECTOR_VERSION = "0.1.1-beta.15";
|
|
10
10
|
|
|
11
11
|
const CAPABILITIES = [
|
|
12
12
|
"remote_registration",
|