@amaster.ai/employee-runtime-connector 0.1.1-beta.352 → 0.1.1-beta.354
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 +275 -249
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
|
@@ -8,20 +8,50 @@ var __export = (target, all) => {
|
|
|
8
8
|
|
|
9
9
|
// src/amaster-runtime-daemon/goal-context-attestation.mjs
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
11
|
+
|
|
12
|
+
// ../shared/src/canonical-json.ts
|
|
13
|
+
function canonicalGoalOutcomeValue(value) {
|
|
14
|
+
if (value instanceof Date) return JSON.stringify(value.toISOString());
|
|
15
|
+
if (Array.isArray(value)) return `[${Array.from(value, canonicalGoalOutcomeValue).join(",")}]`;
|
|
16
|
+
if (value && typeof value === "object") return `{${Object.entries(value).filter(([, child]) => child !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, child]) => `${JSON.stringify(key)}:${canonicalGoalOutcomeValue(child)}`).join(",")}}`;
|
|
17
|
+
return JSON.stringify(value ?? null);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ../shared/src/task-context-versions.ts
|
|
21
|
+
var TASK_CONTEXT_MANIFEST_VERSION = "task-context-v1";
|
|
22
|
+
var TASK_CONTEXT_V2 = "task-context-v2";
|
|
23
|
+
|
|
24
|
+
// ../shared/src/runtime-context-canonical.ts
|
|
25
|
+
var MIRRORX_GOAL_AUTHORITY_CONTRIBUTION_CONSTRAINT = "Execution contribution only. Parent owns Goal evaluation and business Outcome; this child does not claim independent completion.";
|
|
26
|
+
function record(value) {
|
|
27
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
28
|
+
}
|
|
29
|
+
function mirrorxGoalAuthorityPayload(manifestValue) {
|
|
30
|
+
const manifest = record(manifestValue);
|
|
31
|
+
if (manifest?.version !== TASK_CONTEXT_V2) return null;
|
|
32
|
+
const context = record(manifest.goalOutcomeContext);
|
|
33
|
+
if (!record(context?.binding) || !record(context?.snapshotHash)) throw new Error("goal_authority_context_missing");
|
|
34
|
+
return {
|
|
17
35
|
version: manifest.version,
|
|
18
36
|
freshness: manifest.freshness,
|
|
19
37
|
goalOutcomeContext: manifest.goalOutcomeContext,
|
|
20
38
|
...manifest.contributionContext ? {
|
|
21
39
|
contributionContext: manifest.contributionContext,
|
|
22
|
-
constraint:
|
|
40
|
+
constraint: MIRRORX_GOAL_AUTHORITY_CONTRIBUTION_CONSTRAINT
|
|
23
41
|
} : {}
|
|
24
|
-
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function renderMirrorxGoalAuthority(manifestValue) {
|
|
45
|
+
const payload = mirrorxGoalAuthorityPayload(manifestValue);
|
|
46
|
+
return payload ? `<mirrorx-goal-authority>
|
|
47
|
+
${canonicalGoalOutcomeValue(payload)}
|
|
48
|
+
</mirrorx-goal-authority>` : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/amaster-runtime-daemon/goal-context-attestation.mjs
|
|
52
|
+
var hash = (value) => createHash("sha256").update(value).digest("hex");
|
|
53
|
+
function goalAuthorityBlock(context) {
|
|
54
|
+
return renderMirrorxGoalAuthority(context?.taskContextManifest);
|
|
25
55
|
}
|
|
26
56
|
function attestGoalContextDelivery({ authority, prompt, systemPrompt, commandId, runId, executorKind }) {
|
|
27
57
|
if (!authority) return null;
|
|
@@ -33,7 +63,7 @@ function attestGoalContextDelivery({ authority, prompt, systemPrompt, commandId,
|
|
|
33
63
|
commandId,
|
|
34
64
|
runId,
|
|
35
65
|
executorKind,
|
|
36
|
-
taskContextVersion:
|
|
66
|
+
taskContextVersion: TASK_CONTEXT_V2,
|
|
37
67
|
deliveryStage: "process_spawn",
|
|
38
68
|
transport: deliveredPrompt.transport,
|
|
39
69
|
authoritySha256: hash(authority),
|
|
@@ -7672,7 +7702,6 @@ var TASK_GOVERNANCE_BLOCKER_REASONS = [
|
|
|
7672
7702
|
"missing_expected_outcome",
|
|
7673
7703
|
"missing_acceptance_criteria"
|
|
7674
7704
|
];
|
|
7675
|
-
var TASK_CONTEXT_MANIFEST_VERSION = "task-context-v1";
|
|
7676
7705
|
var TASK_CONTEXT_MEMORY_SCOPES = ["none", "task"];
|
|
7677
7706
|
var TASK_CONTEXT_FRESHNESS_MODES = ["current", "frozen"];
|
|
7678
7707
|
var TASK_CONTEXT_WIKI_MODES = ["disabled", "optional"];
|
|
@@ -18393,16 +18422,16 @@ var PI_TOOL_ARGUMENT_GUARD_DEFAULTS = Object.freeze({
|
|
|
18393
18422
|
nearMissAmplificationThreshold: 8,
|
|
18394
18423
|
nearMissReplayRatioThreshold: 0.75
|
|
18395
18424
|
});
|
|
18396
|
-
function
|
|
18425
|
+
function record2(value) {
|
|
18397
18426
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
18398
18427
|
}
|
|
18399
18428
|
function toolCallContentArrays(event) {
|
|
18400
|
-
const root =
|
|
18401
|
-
const assistantEvent =
|
|
18429
|
+
const root = record2(event);
|
|
18430
|
+
const assistantEvent = record2(root.assistantMessageEvent);
|
|
18402
18431
|
return [
|
|
18403
|
-
|
|
18404
|
-
|
|
18405
|
-
|
|
18432
|
+
record2(assistantEvent.partial).content,
|
|
18433
|
+
record2(root.partial).content,
|
|
18434
|
+
record2(root.message).content
|
|
18406
18435
|
].filter(Array.isArray);
|
|
18407
18436
|
}
|
|
18408
18437
|
function toolCallIdentity(item, index) {
|
|
@@ -18424,7 +18453,7 @@ function partialToolCalls(event) {
|
|
|
18424
18453
|
const seen = /* @__PURE__ */ new Set();
|
|
18425
18454
|
for (const content of toolCallContentArrays(event)) {
|
|
18426
18455
|
for (let index = 0; index < content.length; index += 1) {
|
|
18427
|
-
const item =
|
|
18456
|
+
const item = record2(content[index]);
|
|
18428
18457
|
if (readString(item.type)?.toLowerCase() !== "toolcall") continue;
|
|
18429
18458
|
const snapshot = partialArgumentSnapshot(item);
|
|
18430
18459
|
if (snapshot === null) continue;
|
|
@@ -18501,7 +18530,7 @@ function createPiToolArgumentAmplificationTracker(options = {}) {
|
|
|
18501
18530
|
const calls = /* @__PURE__ */ new Map();
|
|
18502
18531
|
let breach = null;
|
|
18503
18532
|
const noteToolExecutionStart = (event) => {
|
|
18504
|
-
const root =
|
|
18533
|
+
const root = record2(event);
|
|
18505
18534
|
const id = readString(root.toolCallId) ?? readString(root.id) ?? readString(root.callId);
|
|
18506
18535
|
const toolName = readString(root.toolName) ?? readString(root.name);
|
|
18507
18536
|
for (const state of calls.values()) {
|
|
@@ -18572,12 +18601,12 @@ function createPiToolArgumentAmplificationTracker(options = {}) {
|
|
|
18572
18601
|
}
|
|
18573
18602
|
|
|
18574
18603
|
// src/amaster-runtime-daemon/pi-output-retention.mjs
|
|
18575
|
-
function
|
|
18604
|
+
function record3(value) {
|
|
18576
18605
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
18577
18606
|
}
|
|
18578
18607
|
function compactIncrementalEvent(event) {
|
|
18579
18608
|
if (event.type !== "message_update") return null;
|
|
18580
|
-
const assistantEvent =
|
|
18609
|
+
const assistantEvent = record3(event.assistantMessageEvent);
|
|
18581
18610
|
const type = typeof assistantEvent.type === "string" ? assistantEvent.type : "";
|
|
18582
18611
|
if (!type.endsWith("_delta") && type !== "text_end" && type !== "thinking_end") return null;
|
|
18583
18612
|
const compact = { type: "message_update", assistantMessageEvent: { type } };
|
|
@@ -20396,7 +20425,7 @@ var SAFE_SHARED_PROVIDER_INTEGER_KEYS = /* @__PURE__ */ new Set([
|
|
|
20396
20425
|
"websocket_connect_timeout_ms"
|
|
20397
20426
|
]);
|
|
20398
20427
|
var BUILT_IN_MODEL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "amazon-bedrock", "ollama", "lmstudio"]);
|
|
20399
|
-
function
|
|
20428
|
+
function record4(value) {
|
|
20400
20429
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
20401
20430
|
}
|
|
20402
20431
|
function nonEmpty(value, label) {
|
|
@@ -20443,7 +20472,7 @@ function findSessionRollout(sessionsRoot, sessionId) {
|
|
|
20443
20472
|
return matches[0];
|
|
20444
20473
|
}
|
|
20445
20474
|
function restoreManagedCodexSessionRollout(input, codexHome, runDir, executorHome, authority) {
|
|
20446
|
-
const session =
|
|
20475
|
+
const session = record4(input.nativeSession);
|
|
20447
20476
|
const governedApprovalContinuation = session.mode === "governed_action_approval" && session.required === true;
|
|
20448
20477
|
const governedTaskSessionContinuation = session.mode === "task_session" && session.required === false;
|
|
20449
20478
|
if (!governedApprovalContinuation && !governedTaskSessionContinuation) return null;
|
|
@@ -20497,7 +20526,7 @@ function resolveManagedCodexSessionRollout(input, codexHome, runDir, executorHom
|
|
|
20497
20526
|
nativeSessionRestoreSkippedReason: null
|
|
20498
20527
|
};
|
|
20499
20528
|
} catch (error) {
|
|
20500
|
-
if (
|
|
20529
|
+
if (record4(input.nativeSession).mode === "task_session" && error instanceof Error && error.message.startsWith("codex_managed_mcp_session_rollout_missing:")) {
|
|
20501
20530
|
return {
|
|
20502
20531
|
restoredNativeSession: null,
|
|
20503
20532
|
nativeSessionRestoreSkippedReason: "native_session_rollout_missing"
|
|
@@ -20538,14 +20567,14 @@ function sharedCodexModelRoute(sourceHome) {
|
|
|
20538
20567
|
}
|
|
20539
20568
|
const providerId = config.model_provider;
|
|
20540
20569
|
if (!providerId) return { root, table: [], mode: config.model ? "shared_model" : "default", protectedValues: [] };
|
|
20541
|
-
const selectedProvider =
|
|
20570
|
+
const selectedProvider = record4(config.model_providers)[providerId];
|
|
20542
20571
|
if (selectedProvider == null) {
|
|
20543
20572
|
if (!BUILT_IN_MODEL_PROVIDERS.has(providerId)) {
|
|
20544
20573
|
throw new Error(`codex_managed_mcp_source_provider_missing: ${providerId}`);
|
|
20545
20574
|
}
|
|
20546
20575
|
return { root, table: [], mode: "shared_builtin_provider", protectedValues: [] };
|
|
20547
20576
|
}
|
|
20548
|
-
if (Object.keys(
|
|
20577
|
+
if (Object.keys(record4(selectedProvider)).length === 0) {
|
|
20549
20578
|
throw new Error(`codex_managed_mcp_provider_config_invalid: model_providers.${providerId} must be a non-empty table`);
|
|
20550
20579
|
}
|
|
20551
20580
|
const projectedProvider = {};
|
|
@@ -20576,7 +20605,7 @@ function sharedCodexModelRoute(sourceHome) {
|
|
|
20576
20605
|
continue;
|
|
20577
20606
|
}
|
|
20578
20607
|
if (key === "http_headers") {
|
|
20579
|
-
const headers =
|
|
20608
|
+
const headers = record4(value);
|
|
20580
20609
|
if (Object.keys(headers).length === 0 || Object.values(headers).some((entry) => typeof entry !== "string")) {
|
|
20581
20610
|
throw new Error("codex_managed_mcp_provider_config_invalid: http_headers must be a non-empty string table");
|
|
20582
20611
|
}
|
|
@@ -20622,18 +20651,18 @@ function runAttestation(executorCommand, env, cwd, gatewayUrl, expectedHeaders)
|
|
|
20622
20651
|
if (!Array.isArray(servers) || servers.length !== 1) {
|
|
20623
20652
|
throw new Error(`codex_managed_mcp_attestation_failed: expected one MCP server, received ${Array.isArray(servers) ? servers.length : "non_array"}`);
|
|
20624
20653
|
}
|
|
20625
|
-
const server =
|
|
20626
|
-
const transport =
|
|
20627
|
-
const effectiveHeaders =
|
|
20654
|
+
const server = record4(servers[0]);
|
|
20655
|
+
const transport = record4(server.transport);
|
|
20656
|
+
const effectiveHeaders = record4(transport.http_headers);
|
|
20628
20657
|
const headersMatch = Object.keys(effectiveHeaders).length === Object.keys(expectedHeaders).length && Object.entries(expectedHeaders).every(([name, value]) => effectiveHeaders[name] === value);
|
|
20629
|
-
if (server.name !== SUPPORTED_SERVER_NAME || server.enabled !== true || transport.type !== "streamable_http" || transport.url !== gatewayUrl || !headersMatch || Object.keys(
|
|
20658
|
+
if (server.name !== SUPPORTED_SERVER_NAME || server.enabled !== true || transport.type !== "streamable_http" || transport.url !== gatewayUrl || !headersMatch || Object.keys(record4(transport.env_http_headers)).length !== 0 || transport.bearer_token_env_var != null) {
|
|
20630
20659
|
throw new Error("codex_managed_mcp_attestation_failed: effective MCP config does not match managed amaster Gateway");
|
|
20631
20660
|
}
|
|
20632
20661
|
return executorVersion;
|
|
20633
20662
|
}
|
|
20634
20663
|
function validateAuthority(input) {
|
|
20635
|
-
const runtimeAuth =
|
|
20636
|
-
const gateway =
|
|
20664
|
+
const runtimeAuth = record4(input.runtimeAuth);
|
|
20665
|
+
const gateway = record4(runtimeAuth.governedMcp);
|
|
20637
20666
|
const runId = nonEmpty(input.runId, "runId");
|
|
20638
20667
|
if (runtimeAuth.runId !== runId) throw new Error("codex_managed_mcp_owner_mismatch: command runId does not match runtime authority");
|
|
20639
20668
|
if (gateway.schemaVersion !== SUPPORTED_SCHEMA_VERSION) throw new Error("codex_managed_mcp_invalid: unsupported schema version");
|
|
@@ -20649,7 +20678,7 @@ function validateAuthority(input) {
|
|
|
20649
20678
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() + 3e4) {
|
|
20650
20679
|
throw new Error("codex_managed_mcp_session_expired: Gateway session must remain valid through spawn preflight");
|
|
20651
20680
|
}
|
|
20652
|
-
const headers =
|
|
20681
|
+
const headers = record4(gateway.headers);
|
|
20653
20682
|
for (const name of REQUIRED_AUTHORITY_HEADERS) nonEmpty(headers[name], `headers.${name}`);
|
|
20654
20683
|
const allowedHeaderNames = /* @__PURE__ */ new Set([...REQUIRED_AUTHORITY_HEADERS, ...runtimeAuth.issueId ? ["x-amaster-issue-id"] : []]);
|
|
20655
20684
|
if (Object.keys(headers).some((name) => !allowedHeaderNames.has(name)) || Object.keys(headers).length !== allowedHeaderNames.size) {
|
|
@@ -20666,7 +20695,7 @@ function validateAuthority(input) {
|
|
|
20666
20695
|
return { gateway, gatewayUrl, sessionToken, headers, runId };
|
|
20667
20696
|
}
|
|
20668
20697
|
function assertInvocationIsolation(input) {
|
|
20669
|
-
for (const name of Object.keys(
|
|
20698
|
+
for (const name of Object.keys(record4(input.commandEnv))) {
|
|
20670
20699
|
if (FORBIDDEN_COMMAND_ENV.has(name)) throw new Error(`codex_managed_mcp_env_override_blocked: ${name}`);
|
|
20671
20700
|
if (!ALLOWED_COMMAND_ENV.has(name)) throw new Error(`codex_managed_mcp_env_injection_blocked: ${name}`);
|
|
20672
20701
|
}
|
|
@@ -20733,7 +20762,7 @@ function buildIsolatedEnvironment(baseEnv, commandEnv) {
|
|
|
20733
20762
|
const value = safeProxyValue(baseEnv?.[name], name);
|
|
20734
20763
|
if (value) env[name] = value;
|
|
20735
20764
|
}
|
|
20736
|
-
return { ...env, ...
|
|
20765
|
+
return { ...env, ...record4(commandEnv) };
|
|
20737
20766
|
}
|
|
20738
20767
|
function assertNoProjectAmasterOverride(cwd, runDir) {
|
|
20739
20768
|
let cursor = resolve4(cwd);
|
|
@@ -20815,7 +20844,7 @@ function prepareManagedCodexMcpProfile(input) {
|
|
|
20815
20844
|
const owner = Object.freeze({ commandId: input.commandId, runId });
|
|
20816
20845
|
writePrivateFile(markerPath, `${JSON.stringify({ version: 1, ...owner, profileRoot })}
|
|
20817
20846
|
`);
|
|
20818
|
-
const runtimeAuth =
|
|
20847
|
+
const runtimeAuth = record4(input.runtimeAuth);
|
|
20819
20848
|
const authority = Object.freeze({
|
|
20820
20849
|
companyId: nonEmpty(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
20821
20850
|
agentId: nonEmpty(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -21183,7 +21212,7 @@ var FULL_DIRECT_TYPED_V1_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
21183
21212
|
...FULL_DIRECT_TYPED_V1_WIKI_TOOL_NAMES,
|
|
21184
21213
|
...FULL_DIRECT_TYPED_V1_CONNECTOR_TOOL_NAMES
|
|
21185
21214
|
]);
|
|
21186
|
-
function
|
|
21215
|
+
function record5(value) {
|
|
21187
21216
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21188
21217
|
}
|
|
21189
21218
|
function requiredString(value, label, fail2) {
|
|
@@ -21196,11 +21225,11 @@ function validateDirectTypedMcpCatalog(catalogValue, options = {}) {
|
|
|
21196
21225
|
throw new Error(`${errorPrefix}: ${detail}`);
|
|
21197
21226
|
};
|
|
21198
21227
|
const admittedToolNames = options.admittedToolNames instanceof Set ? options.admittedToolNames : options.admittedToolNames == null ? null : new Set(options.admittedToolNames);
|
|
21199
|
-
const catalog =
|
|
21228
|
+
const catalog = record5(catalogValue);
|
|
21200
21229
|
if (catalog.schemaVersion !== DIRECT_TYPED_MCP_CATALOG_SCHEMA_VERSION) {
|
|
21201
21230
|
fail2("direct tool catalog schema mismatch");
|
|
21202
21231
|
}
|
|
21203
|
-
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(
|
|
21232
|
+
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(record5) : [];
|
|
21204
21233
|
const names = /* @__PURE__ */ new Set();
|
|
21205
21234
|
const exposedNames = /* @__PURE__ */ new Set();
|
|
21206
21235
|
const tools = rawTools.map((tool) => {
|
|
@@ -21217,7 +21246,7 @@ function validateDirectTypedMcpCatalog(catalogValue, options = {}) {
|
|
|
21217
21246
|
fail2(`direct tool exposed name collision for ${exposedName}`);
|
|
21218
21247
|
}
|
|
21219
21248
|
exposedNames.add(exposedName);
|
|
21220
|
-
const inputSchema =
|
|
21249
|
+
const inputSchema = record5(tool.inputSchema);
|
|
21221
21250
|
if (inputSchema.type !== "object" || inputSchema.additionalProperties !== false) {
|
|
21222
21251
|
fail2(`direct tool schema is not strict for ${name}`);
|
|
21223
21252
|
}
|
|
@@ -21416,7 +21445,7 @@ var CODEBUDDY_PROFILE_COMPATIBILITY_ALLOWLIST = Object.freeze([
|
|
|
21416
21445
|
profileHash: "b310363c97f72b03debd1d6b90cbc49fa17565c1553a8a0c93ee0f29bfadf3c3"
|
|
21417
21446
|
}
|
|
21418
21447
|
]);
|
|
21419
|
-
function
|
|
21448
|
+
function record6(value) {
|
|
21420
21449
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21421
21450
|
}
|
|
21422
21451
|
function fail(detail) {
|
|
@@ -21447,12 +21476,12 @@ function assertFormalCatalogShape(rawTools) {
|
|
|
21447
21476
|
if (!fullCatalog) fail("direct tool catalog size mismatch");
|
|
21448
21477
|
}
|
|
21449
21478
|
function validateCodebuddyFormalToolCatalog(gatewayValue) {
|
|
21450
|
-
const gateway =
|
|
21479
|
+
const gateway = record6(gatewayValue);
|
|
21451
21480
|
if ((gateway.mcpToolMode ?? "direct_typed") !== "direct_typed") {
|
|
21452
21481
|
fail("direct tool mode required");
|
|
21453
21482
|
}
|
|
21454
|
-
const catalog =
|
|
21455
|
-
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(
|
|
21483
|
+
const catalog = record6(gateway.toolCatalog);
|
|
21484
|
+
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(record6) : [];
|
|
21456
21485
|
assertFormalCatalogShape(rawTools);
|
|
21457
21486
|
const validated = validateDirectTypedMcpCatalog(catalog, {
|
|
21458
21487
|
admittedToolNames: FULL_DIRECT_TYPED_V1_TOOL_NAMES,
|
|
@@ -21483,9 +21512,9 @@ function schemaBytes(tools) {
|
|
|
21483
21512
|
return tools.reduce((total, tool) => total + Buffer.byteLength(stablePiJson(tool.inputSchema)), 0);
|
|
21484
21513
|
}
|
|
21485
21514
|
function codebuddyProfileSchemaBytesMatchCatalog(catalogValue, attestationValue) {
|
|
21486
|
-
const catalog =
|
|
21487
|
-
const attestation =
|
|
21488
|
-
const tools = Array.isArray(catalog.tools) ? catalog.tools.map(
|
|
21515
|
+
const catalog = record6(catalogValue);
|
|
21516
|
+
const attestation = record6(attestationValue);
|
|
21517
|
+
const tools = Array.isArray(catalog.tools) ? catalog.tools.map(record6) : [];
|
|
21489
21518
|
const mcpMode = attestation.mcpMode;
|
|
21490
21519
|
const total = attestation.totalMcpSchemaBytes;
|
|
21491
21520
|
const direct = attestation.directMcpSchemaBytes;
|
|
@@ -21755,7 +21784,7 @@ var CODEBUDDY_PROVIDER_ENV = /* @__PURE__ */ new Set([
|
|
|
21755
21784
|
"https_proxy",
|
|
21756
21785
|
"all_proxy"
|
|
21757
21786
|
]);
|
|
21758
|
-
function
|
|
21787
|
+
function record7(value) {
|
|
21759
21788
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21760
21789
|
}
|
|
21761
21790
|
function nonEmpty2(value, label) {
|
|
@@ -21991,7 +22020,7 @@ function codebuddyProjectKey(cwd) {
|
|
|
21991
22020
|
return realpathSync5(cwd).replace(/^[/\\]+/, "").replace(/[\\/:]/g, "-").replace(/-+/g, "-");
|
|
21992
22021
|
}
|
|
21993
22022
|
function restoreManagedCodebuddySessionRollout(input, configDir, runDir, executorHome, authority) {
|
|
21994
|
-
const session =
|
|
22023
|
+
const session = record7(input.nativeSession);
|
|
21995
22024
|
const governedApprovalContinuation = session.mode === "governed_action_approval" && session.required === true;
|
|
21996
22025
|
const taskSessionContinuation = session.mode === "task_session" && session.required === false;
|
|
21997
22026
|
if (!governedApprovalContinuation && !taskSessionContinuation) return null;
|
|
@@ -22035,7 +22064,7 @@ function resolveManagedCodebuddySessionRollout(input, configDir, runDir, executo
|
|
|
22035
22064
|
nativeSessionRestoreSkippedReason: null
|
|
22036
22065
|
};
|
|
22037
22066
|
} catch (error) {
|
|
22038
|
-
if (
|
|
22067
|
+
if (record7(input.nativeSession).mode === "task_session" && error instanceof Error && error.message.startsWith("codebuddy_managed_mcp_session_rollout_missing:")) {
|
|
22039
22068
|
return { restoredNativeSession: null, nativeSessionRestoreSkippedReason: "native_session_rollout_missing" };
|
|
22040
22069
|
}
|
|
22041
22070
|
throw error;
|
|
@@ -22043,7 +22072,7 @@ function resolveManagedCodebuddySessionRollout(input, configDir, runDir, executo
|
|
|
22043
22072
|
}
|
|
22044
22073
|
function buildIsolatedEnvironment2(baseEnv, commandEnv) {
|
|
22045
22074
|
const env = {};
|
|
22046
|
-
for (const source of [
|
|
22075
|
+
for (const source of [record7(baseEnv), record7(commandEnv)]) {
|
|
22047
22076
|
for (const [key, value] of Object.entries(source)) {
|
|
22048
22077
|
if (!SAFE_INHERITED_ENV2.has(key) || typeof value !== "string") continue;
|
|
22049
22078
|
env[key] = value;
|
|
@@ -22053,8 +22082,8 @@ function buildIsolatedEnvironment2(baseEnv, commandEnv) {
|
|
|
22053
22082
|
}
|
|
22054
22083
|
function codebuddyAuthSelection(baseEnv, commandEnv) {
|
|
22055
22084
|
const scopes = [
|
|
22056
|
-
{ name: "command_env", value:
|
|
22057
|
-
{ name: "daemon_env", value:
|
|
22085
|
+
{ name: "command_env", value: record7(commandEnv) },
|
|
22086
|
+
{ name: "daemon_env", value: record7(baseEnv) }
|
|
22058
22087
|
];
|
|
22059
22088
|
for (const scope of scopes) {
|
|
22060
22089
|
const apiKey = typeof scope.value.CODEBUDDY_API_KEY === "string" ? scope.value.CODEBUDDY_API_KEY.trim() : "";
|
|
@@ -22092,7 +22121,7 @@ function inspectCodebuddyProviderAuthReadiness(baseEnv = process.env, commandEnv
|
|
|
22092
22121
|
};
|
|
22093
22122
|
}
|
|
22094
22123
|
function codebuddyProviderEnvironment(baseEnv, commandEnv) {
|
|
22095
|
-
const source = { ...
|
|
22124
|
+
const source = { ...record7(baseEnv), ...record7(commandEnv) };
|
|
22096
22125
|
const selectedAuth = codebuddyAuthSelection(baseEnv, commandEnv);
|
|
22097
22126
|
if (selectedAuth.conflict) {
|
|
22098
22127
|
throw new Error("codebuddy_managed_mcp_auth_conflict: configure only one CodeBuddy authentication method");
|
|
@@ -22124,8 +22153,8 @@ function codebuddyProviderEnvironment(baseEnv, commandEnv) {
|
|
|
22124
22153
|
};
|
|
22125
22154
|
}
|
|
22126
22155
|
function validateAuthority2(input) {
|
|
22127
|
-
const runtimeAuth =
|
|
22128
|
-
const gateway =
|
|
22156
|
+
const runtimeAuth = record7(input.runtimeAuth);
|
|
22157
|
+
const gateway = record7(runtimeAuth.governedMcp);
|
|
22129
22158
|
const runId = nonEmpty2(input.runId, "runId");
|
|
22130
22159
|
if (runtimeAuth.runId !== runId) {
|
|
22131
22160
|
throw new Error("codebuddy_managed_mcp_owner_mismatch: command runId does not match runtime authority");
|
|
@@ -22143,7 +22172,7 @@ function validateAuthority2(input) {
|
|
|
22143
22172
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now()) {
|
|
22144
22173
|
throw new Error("codebuddy_managed_mcp_session_expired");
|
|
22145
22174
|
}
|
|
22146
|
-
const headers =
|
|
22175
|
+
const headers = record7(gateway.headers);
|
|
22147
22176
|
for (const name of REQUIRED_AUTHORITY_HEADERS2) nonEmpty2(headers[name], `headers.${name}`);
|
|
22148
22177
|
if (headers["x-amaster-executor-kind"] !== "codebuddy") {
|
|
22149
22178
|
throw new Error("codebuddy_managed_mcp_invalid: executor header must be codebuddy");
|
|
@@ -23611,7 +23640,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23611
23640
|
const PI_VERSION_ATTESTATION_TIMEOUT_MS = 3e4;
|
|
23612
23641
|
const PI_ATTESTATION_MAX_ATTEMPTS = 2;
|
|
23613
23642
|
const livePiVersionProbes = /* @__PURE__ */ new Map();
|
|
23614
|
-
function
|
|
23643
|
+
function record11(value) {
|
|
23615
23644
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
23616
23645
|
}
|
|
23617
23646
|
function readJsonObjectFile(filePath) {
|
|
@@ -23673,7 +23702,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23673
23702
|
return matches[0];
|
|
23674
23703
|
}
|
|
23675
23704
|
function restoreManagedPiSessionRollout(input, sessionsRoot, runDir, executorHome, authority) {
|
|
23676
|
-
const session =
|
|
23705
|
+
const session = record11(input.nativeSession);
|
|
23677
23706
|
const governedApprovalContinuation = session.mode === "governed_action_approval" && session.required === true;
|
|
23678
23707
|
const governedTaskSessionContinuation = session.mode === "task_session" && session.required === false;
|
|
23679
23708
|
if (!governedApprovalContinuation && !governedTaskSessionContinuation) return null;
|
|
@@ -23732,7 +23761,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23732
23761
|
nativeSessionRestoreSkippedReason: null
|
|
23733
23762
|
};
|
|
23734
23763
|
} catch (error) {
|
|
23735
|
-
if (
|
|
23764
|
+
if (record11(input.nativeSession).mode === "task_session" && error instanceof Error && error.message.startsWith("pi_managed_mcp_session_rollout_missing:")) {
|
|
23736
23765
|
return {
|
|
23737
23766
|
restoredNativeSession: null,
|
|
23738
23767
|
nativeSessionRestoreSkippedReason: "native_session_rollout_missing"
|
|
@@ -23804,7 +23833,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23804
23833
|
return version;
|
|
23805
23834
|
}
|
|
23806
23835
|
function managedPiTelemetryExtension(sharedRuntime) {
|
|
23807
|
-
const settings =
|
|
23836
|
+
const settings = record11(sharedRuntime.settings);
|
|
23808
23837
|
const packages = Array.isArray(settings.packages) ? settings.packages : [];
|
|
23809
23838
|
const configuredSources = packages.filter((source) => typeof source === "string" && (source === MANAGED_PI_TELEMETRY_PACKAGE_SOURCE || source.startsWith(`${MANAGED_PI_TELEMETRY_PACKAGE_SOURCE}@`)));
|
|
23810
23839
|
if (configuredSources.length === 0) return null;
|
|
@@ -23825,7 +23854,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23825
23854
|
if (!packageStat.isDirectory() || packageStat.isSymbolicLink()) throw new Error("unsafe package root");
|
|
23826
23855
|
const packageJsonStat = lstatSync7(packageJsonPath);
|
|
23827
23856
|
if (!packageJsonStat.isFile() || packageJsonStat.isSymbolicLink()) throw new Error("unsafe package manifest");
|
|
23828
|
-
packageJson =
|
|
23857
|
+
packageJson = record11(JSON.parse(readFileSync6(packageJsonPath, "utf8")));
|
|
23829
23858
|
} catch {
|
|
23830
23859
|
throw new Error("pi_managed_mcp_telemetry_package_unavailable");
|
|
23831
23860
|
}
|
|
@@ -23836,7 +23865,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23836
23865
|
if (!/^\d+\.\d+\.\d+(?:[-+].+)?$/.test(version)) {
|
|
23837
23866
|
throw new Error("pi_managed_mcp_telemetry_package_version_invalid");
|
|
23838
23867
|
}
|
|
23839
|
-
const declaredExtensions = Array.isArray(
|
|
23868
|
+
const declaredExtensions = Array.isArray(record11(packageJson.pi).extensions) ? record11(packageJson.pi).extensions : [];
|
|
23840
23869
|
if (declaredExtensions.length !== 1 || typeof declaredExtensions[0] !== "string") {
|
|
23841
23870
|
throw new Error("pi_managed_mcp_telemetry_extension_invalid");
|
|
23842
23871
|
}
|
|
@@ -23866,7 +23895,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23866
23895
|
extensionPath,
|
|
23867
23896
|
extensionSha256: sha2563(readFileSync6(extensionPath)),
|
|
23868
23897
|
packageTreeSha256,
|
|
23869
|
-
langfuseEnabled:
|
|
23898
|
+
langfuseEnabled: record11(record11(settings["pi-telemetry"]).langfuse).enabled === true
|
|
23870
23899
|
};
|
|
23871
23900
|
}
|
|
23872
23901
|
function adapterServerConfigHash(definition, adapterVersion) {
|
|
@@ -23925,8 +23954,8 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23925
23954
|
}
|
|
23926
23955
|
}
|
|
23927
23956
|
function validateAuthority3(input) {
|
|
23928
|
-
const runtimeAuth =
|
|
23929
|
-
const gateway =
|
|
23957
|
+
const runtimeAuth = record11(input.runtimeAuth);
|
|
23958
|
+
const gateway = record11(runtimeAuth.governedMcp);
|
|
23930
23959
|
const runId = nonEmpty3(input.runId, "runId");
|
|
23931
23960
|
if (runtimeAuth.runId !== runId) throw new Error("pi_managed_mcp_owner_mismatch: command runId does not match runtime authority");
|
|
23932
23961
|
if (gateway.schemaVersion !== SUPPORTED_SCHEMA_VERSION3) throw new Error("pi_managed_mcp_invalid: unsupported schema version");
|
|
@@ -23942,7 +23971,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23942
23971
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() + 3e4) {
|
|
23943
23972
|
throw new Error("pi_managed_mcp_session_expired: Gateway session must remain valid through spawn preflight");
|
|
23944
23973
|
}
|
|
23945
|
-
const headers =
|
|
23974
|
+
const headers = record11(gateway.headers);
|
|
23946
23975
|
for (const name of REQUIRED_AUTHORITY_HEADERS3) nonEmpty3(headers[name], `headers.${name}`);
|
|
23947
23976
|
const allowedHeaderNames = /* @__PURE__ */ new Set([...REQUIRED_AUTHORITY_HEADERS3, ...runtimeAuth.issueId ? ["x-amaster-issue-id"] : []]);
|
|
23948
23977
|
if (Object.keys(headers).some((name) => !allowedHeaderNames.has(name)) || Object.keys(headers).length !== allowedHeaderNames.size) {
|
|
@@ -24001,7 +24030,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24001
24030
|
return env;
|
|
24002
24031
|
}
|
|
24003
24032
|
function assertInvocationIsolation2(input) {
|
|
24004
|
-
for (const name of Object.keys(
|
|
24033
|
+
for (const name of Object.keys(record11(input.commandEnv))) {
|
|
24005
24034
|
if (FORBIDDEN_COMMAND_ENV2.has(name)) throw new Error(`pi_managed_mcp_env_override_blocked: ${name}`);
|
|
24006
24035
|
if (!ALLOWED_COMMAND_ENV2.has(name)) throw new Error(`pi_managed_mcp_env_injection_blocked: ${name}`);
|
|
24007
24036
|
}
|
|
@@ -24033,7 +24062,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24033
24062
|
const value = safeProxyValue2(baseEnv?.[name], name);
|
|
24034
24063
|
if (value) env[name] = value;
|
|
24035
24064
|
}
|
|
24036
|
-
return { ...env, ...
|
|
24065
|
+
return { ...env, ...record11(commandEnv) };
|
|
24037
24066
|
}
|
|
24038
24067
|
function projectMcpConfigHasContent(filePath) {
|
|
24039
24068
|
if (!existsSync7(filePath)) return false;
|
|
@@ -24043,8 +24072,8 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24043
24072
|
} catch {
|
|
24044
24073
|
return true;
|
|
24045
24074
|
}
|
|
24046
|
-
const config =
|
|
24047
|
-
return Object.keys(
|
|
24075
|
+
const config = record11(parsed);
|
|
24076
|
+
return Object.keys(record11(config.mcpServers)).length > 0 || Object.keys(record11(config.servers)).length > 0 || Array.isArray(config.imports) && config.imports.length > 0;
|
|
24048
24077
|
}
|
|
24049
24078
|
function walkProjectMcpConfigs(cwd, runDir, visit) {
|
|
24050
24079
|
const start = resolve7(cwd);
|
|
@@ -24118,7 +24147,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24118
24147
|
let settings = {};
|
|
24119
24148
|
if (existsSync7(settingsPath)) {
|
|
24120
24149
|
try {
|
|
24121
|
-
settings =
|
|
24150
|
+
settings = record11(JSON.parse(readFileSync6(settingsPath, "utf8")));
|
|
24122
24151
|
} catch {
|
|
24123
24152
|
throw new Error("pi_managed_mcp_attestation_failed: source Pi settings are invalid");
|
|
24124
24153
|
}
|
|
@@ -24127,8 +24156,8 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24127
24156
|
const mcpPath = join10(home, "mcp.json");
|
|
24128
24157
|
if (existsSync7(mcpPath)) {
|
|
24129
24158
|
try {
|
|
24130
|
-
userMcpServers = Object.fromEntries(Object.entries(
|
|
24131
|
-
|
|
24159
|
+
userMcpServers = Object.fromEntries(Object.entries(record11(
|
|
24160
|
+
record11(JSON.parse(readFileSync6(mcpPath, "utf8"))).mcpServers
|
|
24132
24161
|
)).filter(([serverName]) => serverName !== SUPPORTED_SERVER_NAME3));
|
|
24133
24162
|
} catch {
|
|
24134
24163
|
userMcpServers = {};
|
|
@@ -24161,7 +24190,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24161
24190
|
return segments.join("/") === value ? value : null;
|
|
24162
24191
|
}
|
|
24163
24192
|
function parseManagedSkillBundle(rawBundle) {
|
|
24164
|
-
const bundle =
|
|
24193
|
+
const bundle = record11(rawBundle);
|
|
24165
24194
|
if (Object.keys(bundle).length === 0) return null;
|
|
24166
24195
|
if (bundle.version !== 1) {
|
|
24167
24196
|
throw new Error("pi_managed_mcp_company_skill_bundle_invalid");
|
|
@@ -24171,13 +24200,13 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24171
24200
|
}
|
|
24172
24201
|
let totalBytes = 0;
|
|
24173
24202
|
const skills = bundle.skills.map((rawSkill) => {
|
|
24174
|
-
const skill =
|
|
24203
|
+
const skill = record11(rawSkill);
|
|
24175
24204
|
if (typeof skill.key !== "string" || !skill.key || Buffer.byteLength(skill.key, "utf8") > 512 || /[\u0000-\u001f\u007f]/.test(skill.key) || typeof skill.runtimeName !== "string" || !MANAGED_SKILL_BUNDLE_RUNTIME_NAME.test(skill.runtimeName) || !Array.isArray(skill.files) || skill.files.length === 0 || skill.files.length > MANAGED_SKILL_BUNDLE_MAX_FILES) {
|
|
24176
24205
|
throw new Error("pi_managed_mcp_company_skill_bundle_invalid");
|
|
24177
24206
|
}
|
|
24178
24207
|
const paths = /* @__PURE__ */ new Set();
|
|
24179
24208
|
const files = skill.files.map((rawFile) => {
|
|
24180
|
-
const file =
|
|
24209
|
+
const file = record11(rawFile);
|
|
24181
24210
|
const relativePath = canonicalManagedSkillRelativePath(file.path);
|
|
24182
24211
|
if (!relativePath || paths.has(relativePath) || !Number.isSafeInteger(file.bytes) || file.bytes < 0 || file.bytes > MANAGED_SKILL_BUNDLE_MAX_FILE_BYTES || typeof file.contentBase64 !== "string") {
|
|
24183
24212
|
throw new Error("pi_managed_mcp_company_skill_bundle_invalid");
|
|
@@ -24444,7 +24473,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24444
24473
|
const closureConfigBytes = Buffer.from(`${JSON.stringify({
|
|
24445
24474
|
...input.config,
|
|
24446
24475
|
mcpServers: {
|
|
24447
|
-
...
|
|
24476
|
+
...record11(input.config.mcpServers),
|
|
24448
24477
|
[SUPPORTED_SERVER_NAME3]: closureServerConfig
|
|
24449
24478
|
}
|
|
24450
24479
|
}, null, 2)}
|
|
@@ -24509,7 +24538,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24509
24538
|
workspaceMcpConfigPath
|
|
24510
24539
|
})}
|
|
24511
24540
|
`);
|
|
24512
|
-
const runtimeAuth =
|
|
24541
|
+
const runtimeAuth = record11(input.runtimeAuth);
|
|
24513
24542
|
const authority = Object.freeze({
|
|
24514
24543
|
companyId: nonEmpty3(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
24515
24544
|
agentId: nonEmpty3(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -24731,18 +24760,18 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24731
24760
|
}
|
|
24732
24761
|
function restoreManagedPiRunExitClosureBaseline2(input, expectedOwner) {
|
|
24733
24762
|
if (!input) return { status: "not_required" };
|
|
24734
|
-
const baseline =
|
|
24763
|
+
const baseline = record11(input);
|
|
24735
24764
|
if (baseline.schemaVersion !== "amaster.pi-run-exit-closure-baseline.v3") {
|
|
24736
24765
|
throw new Error("pi_run_exit_closure_baseline_invalid: unsupported schema version");
|
|
24737
24766
|
}
|
|
24738
|
-
const owner =
|
|
24767
|
+
const owner = record11(baseline.owner);
|
|
24739
24768
|
if (owner.commandId !== expectedOwner?.commandId || owner.runId !== expectedOwner?.runId) {
|
|
24740
24769
|
throw new Error("pi_run_exit_closure_baseline_owner_mismatch");
|
|
24741
24770
|
}
|
|
24742
24771
|
const profileRoot = resolve7(nonEmpty3(baseline.profileRoot, "runExitClosureBaseline.profileRoot"));
|
|
24743
24772
|
const cachePath = resolve7(nonEmpty3(baseline.cachePath, "runExitClosureBaseline.cachePath"));
|
|
24744
24773
|
if (!within3(cachePath, profileRoot)) throw new Error("pi_run_exit_closure_baseline_path_mismatch");
|
|
24745
|
-
const closureProfile = Object.keys(
|
|
24774
|
+
const closureProfile = Object.keys(record11(baseline.closureProfile)).length > 0 ? record11(baseline.closureProfile) : null;
|
|
24746
24775
|
const configPath = closureProfile ? resolve7(nonEmpty3(closureProfile.configPath, "closureProfile.configPath")) : null;
|
|
24747
24776
|
for (const path of [cachePath, configPath].filter(Boolean)) {
|
|
24748
24777
|
if (existsSync7(path)) {
|
|
@@ -24752,7 +24781,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24752
24781
|
}
|
|
24753
24782
|
}
|
|
24754
24783
|
}
|
|
24755
|
-
const baselineCacheOwnership =
|
|
24784
|
+
const baselineCacheOwnership = record11(baseline.cacheOwnership);
|
|
24756
24785
|
const cacheOwnership = Number.isSafeInteger(baselineCacheOwnership.uid) && baselineCacheOwnership.uid >= 0 && Number.isSafeInteger(baselineCacheOwnership.gid) && baselineCacheOwnership.gid >= 0 ? { uid: baselineCacheOwnership.uid, gid: baselineCacheOwnership.gid } : existsSync7(cachePath) ? ownershipStatSyncImpl(cachePath) : null;
|
|
24757
24786
|
if (!cacheOwnership) {
|
|
24758
24787
|
throw new Error("pi_run_exit_closure_baseline_cache_owner_missing");
|
|
@@ -24763,7 +24792,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24763
24792
|
label: "config",
|
|
24764
24793
|
path: configPath,
|
|
24765
24794
|
bytes: Buffer.from(nonEmpty3(closureProfile.configContentsBase64, "closureProfile.configContentsBase64"), "base64"),
|
|
24766
|
-
ownership:
|
|
24795
|
+
ownership: record11(closureProfile.configOwnership)
|
|
24767
24796
|
},
|
|
24768
24797
|
{
|
|
24769
24798
|
label: "cache",
|
|
@@ -24814,7 +24843,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24814
24843
|
const owner = Object.freeze({ commandId: input.commandId, runId });
|
|
24815
24844
|
writePrivateFile2(markerPath, `${JSON.stringify({ version: 1, ...owner, profileRoot, piCodingAgentDir })}
|
|
24816
24845
|
`);
|
|
24817
|
-
const runtimeAuth =
|
|
24846
|
+
const runtimeAuth = record11(input.runtimeAuth);
|
|
24818
24847
|
const authority = Object.freeze({
|
|
24819
24848
|
companyId: nonEmpty3(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
24820
24849
|
agentId: nonEmpty3(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -24841,7 +24870,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24841
24870
|
const config = {
|
|
24842
24871
|
...sourceMcp,
|
|
24843
24872
|
settings: {
|
|
24844
|
-
...
|
|
24873
|
+
...record11(sourceMcp.settings),
|
|
24845
24874
|
// Governed catalog exposed names are already provider-safe and are the
|
|
24846
24875
|
// exact identities attested by the Server. A desktop user's adapter
|
|
24847
24876
|
// prefix is local presentation state and must not rename this run's
|
|
@@ -24850,7 +24879,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24850
24879
|
...directCatalog ? { directToolResultDetails: "bounded", freezeDirectTools: true } : {}
|
|
24851
24880
|
},
|
|
24852
24881
|
mcpServers: {
|
|
24853
|
-
...
|
|
24882
|
+
...record11(sourceMcp.mcpServers),
|
|
24854
24883
|
[SUPPORTED_SERVER_NAME3]: serverConfig
|
|
24855
24884
|
}
|
|
24856
24885
|
};
|
|
@@ -24893,7 +24922,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24893
24922
|
);
|
|
24894
24923
|
enabledRoleSkillMetadataBytes = roleSkills.serializedMetadataBytes;
|
|
24895
24924
|
}
|
|
24896
|
-
const userMcpServerNames = Object.keys(
|
|
24925
|
+
const userMcpServerNames = Object.keys(record11(sourceMcp.mcpServers)).filter((serverName) => serverName !== SUPPORTED_SERVER_NAME3);
|
|
24897
24926
|
const adapterVersion = desktopAdapterReadiness?.ready ? desktopAdapterReadiness.adapterVersion : null;
|
|
24898
24927
|
const {
|
|
24899
24928
|
cachePath,
|
|
@@ -24916,7 +24945,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24916
24945
|
});
|
|
24917
24946
|
const env = {
|
|
24918
24947
|
...input.baseEnv,
|
|
24919
|
-
...
|
|
24948
|
+
...record11(input.commandEnv),
|
|
24920
24949
|
AMASTER_RUNTIME_RUN_ID: authority.runId,
|
|
24921
24950
|
AMASTER_RUNTIME_COMMAND_ID: authority.commandId,
|
|
24922
24951
|
...authority.issueId ? { AMASTER_RUNTIME_ISSUE_ID: authority.issueId } : {},
|
|
@@ -25454,8 +25483,8 @@ function resultOutboxFileName(commandId, now = Date.now()) {
|
|
|
25454
25483
|
return `${now}-${safeCommandId}.json`;
|
|
25455
25484
|
}
|
|
25456
25485
|
function isValidResultOutboxEntry(entry) {
|
|
25457
|
-
const
|
|
25458
|
-
return
|
|
25486
|
+
const record11 = asRecord(entry);
|
|
25487
|
+
return record11.version === 1 && Boolean(readString(record11.path)) && Object.keys(asRecord(record11.payload)).length > 0;
|
|
25459
25488
|
}
|
|
25460
25489
|
function resultOutboxEntryAgeMs(entry, nowMs) {
|
|
25461
25490
|
const createdAt = Date.parse(readString(entry.createdAt) ?? "");
|
|
@@ -25519,7 +25548,7 @@ function nextRunCompletionPhase(phase, event) {
|
|
|
25519
25548
|
// src/amaster-runtime-daemon/run-completion-state.mjs
|
|
25520
25549
|
var RUN_COMPLETION_STATE_VERSION = 1;
|
|
25521
25550
|
var RUN_COMPLETION_USAGE_SCHEMA_VERSION = "runtime-command-usage-v1";
|
|
25522
|
-
function
|
|
25551
|
+
function record8(value) {
|
|
25523
25552
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
25524
25553
|
}
|
|
25525
25554
|
function nonEmptyString(value, label) {
|
|
@@ -25544,8 +25573,8 @@ function runCompletionStateFileName(commandId) {
|
|
|
25544
25573
|
return `${safeCommandId}.json`;
|
|
25545
25574
|
}
|
|
25546
25575
|
function normalizeRunTurnUsage(turn) {
|
|
25547
|
-
const source =
|
|
25548
|
-
const nestedUsage =
|
|
25576
|
+
const source = record8(turn);
|
|
25577
|
+
const nestedUsage = record8(source.usage);
|
|
25549
25578
|
const usage = Object.keys(nestedUsage).length > 0 ? nestedUsage : source;
|
|
25550
25579
|
const allowedTurnKinds = /* @__PURE__ */ new Set([
|
|
25551
25580
|
"primary",
|
|
@@ -25587,11 +25616,11 @@ function aggregateRunTurnUsage(turns) {
|
|
|
25587
25616
|
};
|
|
25588
25617
|
}
|
|
25589
25618
|
function createRunCompletionState(input) {
|
|
25590
|
-
const command =
|
|
25619
|
+
const command = record8(input.command);
|
|
25591
25620
|
const commandId = nonEmptyString(command.commandId ?? command.id, "command.commandId");
|
|
25592
25621
|
const connectorId = nonEmptyString(input.connectorId ?? command.connectorId, "connectorId");
|
|
25593
25622
|
const now = typeof input.now === "string" && input.now ? input.now : (/* @__PURE__ */ new Date()).toISOString();
|
|
25594
|
-
const firstTurn = normalizeRunTurnUsage({ ...
|
|
25623
|
+
const firstTurn = normalizeRunTurnUsage({ ...record8(input.turn), turn: "primary", recordedAt: now });
|
|
25595
25624
|
return {
|
|
25596
25625
|
version: RUN_COMPLETION_STATE_VERSION,
|
|
25597
25626
|
commandId,
|
|
@@ -25604,10 +25633,10 @@ function createRunCompletionState(input) {
|
|
|
25604
25633
|
terminalDisposition: 0
|
|
25605
25634
|
},
|
|
25606
25635
|
command,
|
|
25607
|
-
executor:
|
|
25608
|
-
completionRequest:
|
|
25636
|
+
executor: record8(input.executor),
|
|
25637
|
+
completionRequest: record8(input.completionRequest),
|
|
25609
25638
|
candidateStatus: nonEmptyString(input.candidateStatus, "candidateStatus"),
|
|
25610
|
-
candidateResult:
|
|
25639
|
+
candidateResult: record8(input.candidateResult),
|
|
25611
25640
|
...typeof input.candidateError === "string" && input.candidateError ? { candidateError: input.candidateError } : {},
|
|
25612
25641
|
usageRecord: {
|
|
25613
25642
|
schemaVersion: RUN_COMPLETION_USAGE_SCHEMA_VERSION,
|
|
@@ -25655,7 +25684,7 @@ function transitionRunCompletionState(state, event, patch = {}, now = (/* @__PUR
|
|
|
25655
25684
|
}
|
|
25656
25685
|
return assertValidRunCompletionState({
|
|
25657
25686
|
...current,
|
|
25658
|
-
...
|
|
25687
|
+
...record8(patch),
|
|
25659
25688
|
phase: nextPhase,
|
|
25660
25689
|
updatedAt: now
|
|
25661
25690
|
});
|
|
@@ -25668,24 +25697,24 @@ function markRunCompletionCostDelivered(state, receipt, now = (/* @__PURE__ */ n
|
|
|
25668
25697
|
...current.usageRecord,
|
|
25669
25698
|
ingestStatus: "delivered",
|
|
25670
25699
|
deliveredAt: now,
|
|
25671
|
-
receipt:
|
|
25700
|
+
receipt: record8(receipt)
|
|
25672
25701
|
}
|
|
25673
25702
|
}, "cost_ingest_delivered", {}, now);
|
|
25674
25703
|
}
|
|
25675
25704
|
function assertValidRunCompletionState(value) {
|
|
25676
|
-
const state =
|
|
25705
|
+
const state = record8(value);
|
|
25677
25706
|
if (state.version !== RUN_COMPLETION_STATE_VERSION) throw new Error("run_completion_state_invalid:version");
|
|
25678
25707
|
const commandId = nonEmptyString(state.commandId, "commandId");
|
|
25679
25708
|
const connectorId = nonEmptyString(state.connectorId, "connectorId");
|
|
25680
25709
|
if (!isRunCompletionPhase(state.phase)) throw new Error("run_completion_state_invalid:phase");
|
|
25681
|
-
const command =
|
|
25710
|
+
const command = record8(state.command);
|
|
25682
25711
|
if (nonEmptyString(command.commandId ?? command.id, "command.commandId") !== commandId) {
|
|
25683
25712
|
throw new Error("run_completion_state_invalid:command_binding");
|
|
25684
25713
|
}
|
|
25685
25714
|
if (nonEmptyString(command.connectorId, "command.connectorId") !== connectorId) {
|
|
25686
25715
|
throw new Error("run_completion_state_invalid:connector_binding");
|
|
25687
25716
|
}
|
|
25688
|
-
const usageRecord =
|
|
25717
|
+
const usageRecord = record8(state.usageRecord);
|
|
25689
25718
|
if (usageRecord.schemaVersion !== RUN_COMPLETION_USAGE_SCHEMA_VERSION) {
|
|
25690
25719
|
throw new Error("run_completion_state_invalid:usage_schema");
|
|
25691
25720
|
}
|
|
@@ -25716,9 +25745,9 @@ function assertValidRunCompletionState(value) {
|
|
|
25716
25745
|
commandId,
|
|
25717
25746
|
connectorId,
|
|
25718
25747
|
command,
|
|
25719
|
-
executor:
|
|
25720
|
-
completionRequest:
|
|
25721
|
-
candidateResult:
|
|
25748
|
+
executor: record8(state.executor),
|
|
25749
|
+
completionRequest: record8(state.completionRequest),
|
|
25750
|
+
candidateResult: record8(state.candidateResult),
|
|
25722
25751
|
usageRecord: {
|
|
25723
25752
|
...usageRecord,
|
|
25724
25753
|
turns,
|
|
@@ -25758,7 +25787,7 @@ var FINALIZATION_PHASES = /* @__PURE__ */ new Set([
|
|
|
25758
25787
|
"profile_cleanup",
|
|
25759
25788
|
"result_post_pending"
|
|
25760
25789
|
]);
|
|
25761
|
-
function
|
|
25790
|
+
function record9(value) {
|
|
25762
25791
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
25763
25792
|
}
|
|
25764
25793
|
function string(value) {
|
|
@@ -25771,13 +25800,13 @@ function truncate(value, limit = 1e3) {
|
|
|
25771
25800
|
return truncateText(value instanceof Error ? value.message : String(value), limit);
|
|
25772
25801
|
}
|
|
25773
25802
|
function defaultErrorCode(error) {
|
|
25774
|
-
const body =
|
|
25775
|
-
const details =
|
|
25803
|
+
const body = record9(error?.responseBody);
|
|
25804
|
+
const details = record9(body.details);
|
|
25776
25805
|
return string(details.code) ?? string(body.code);
|
|
25777
25806
|
}
|
|
25778
25807
|
function defaultTerminalStatus(error) {
|
|
25779
25808
|
if (defaultErrorCode(error) !== "runtime_completion_check_command_not_acknowledged") return null;
|
|
25780
|
-
const status = string(
|
|
25809
|
+
const status = string(record9(record9(error?.responseBody).details).status);
|
|
25781
25810
|
return ["succeeded", "failed", "cancelled"].includes(status ?? "") ? status : null;
|
|
25782
25811
|
}
|
|
25783
25812
|
function defaultCompletionRetryable(error) {
|
|
@@ -25798,20 +25827,20 @@ function defaultCleanupOwnerMismatch(error) {
|
|
|
25798
25827
|
return /^(?:pi|codex|codebuddy)_managed_mcp_cleanup_owner_mismatch:/.test(message) || /^pi_delegated_mcp_cleanup_owner_mismatch:/.test(message);
|
|
25799
25828
|
}
|
|
25800
25829
|
function runCompletionCheckRequest(state) {
|
|
25801
|
-
const prior =
|
|
25802
|
-
const turns = Array.isArray(
|
|
25830
|
+
const prior = record9(state.completionRequest);
|
|
25831
|
+
const turns = Array.isArray(record9(state.usageRecord).turns) ? record9(state.usageRecord).turns.map(record9) : [];
|
|
25803
25832
|
const terminalTextRepairAttempt = turns.some((turn) => turn.turn === "terminal_text_repair") ? 1 : 0;
|
|
25804
25833
|
const closureAttempt = state.closureAttempt === 1 ? 1 : 0;
|
|
25805
25834
|
const closureAttempts = {
|
|
25806
|
-
workDisposition: number(
|
|
25807
|
-
livePath: number(
|
|
25808
|
-
terminalDisposition: number(
|
|
25835
|
+
workDisposition: number(record9(state.closureAttempts).workDisposition) === 1 ? 1 : 0,
|
|
25836
|
+
livePath: number(record9(state.closureAttempts).livePath) === 1 ? 1 : 0,
|
|
25837
|
+
terminalDisposition: number(record9(state.closureAttempts).terminalDisposition) === 1 ? 1 : 0
|
|
25809
25838
|
};
|
|
25810
25839
|
const v2 = prior.contractVersion === "amaster.runtime-connector.completion-check.v2";
|
|
25811
25840
|
const closureTurnCount = v2 ? closureAttempts.workDisposition + closureAttempts.livePath + closureAttempts.terminalDisposition : closureAttempt;
|
|
25812
25841
|
return {
|
|
25813
25842
|
contractVersion: v2 ? "amaster.runtime-connector.completion-check.v2" : "amaster.runtime-connector.completion-check.v1",
|
|
25814
|
-
...string(
|
|
25843
|
+
...string(record9(state.command).leaseId) ? { leaseId: string(record9(state.command).leaseId) } : {},
|
|
25815
25844
|
proposedStatus: state.candidateStatus,
|
|
25816
25845
|
resultSignals: {
|
|
25817
25846
|
productiveSuccessfulRun: prior.resultSignals?.productiveSuccessfulRun === true,
|
|
@@ -25822,7 +25851,7 @@ function runCompletionCheckRequest(state) {
|
|
|
25822
25851
|
};
|
|
25823
25852
|
}
|
|
25824
25853
|
function usageResult(state) {
|
|
25825
|
-
const aggregate =
|
|
25854
|
+
const aggregate = record9(record9(state.usageRecord).aggregate);
|
|
25826
25855
|
const costUsd = number(aggregate.costUsd);
|
|
25827
25856
|
return {
|
|
25828
25857
|
inputTokens: number(aggregate.inputTokens),
|
|
@@ -25836,27 +25865,27 @@ function failedCandidate(state, errorCode, message, evidence, now) {
|
|
|
25836
25865
|
candidateStatus: "failed",
|
|
25837
25866
|
candidateError: message,
|
|
25838
25867
|
candidateResult: {
|
|
25839
|
-
...
|
|
25868
|
+
...record9(state.candidateResult),
|
|
25840
25869
|
errorCode,
|
|
25841
25870
|
completionDeliveryFailure: {
|
|
25842
25871
|
phase: state.phase,
|
|
25843
25872
|
failedAt: now,
|
|
25844
|
-
...
|
|
25873
|
+
...record9(evidence)
|
|
25845
25874
|
}
|
|
25846
25875
|
}
|
|
25847
25876
|
};
|
|
25848
25877
|
}
|
|
25849
25878
|
function resultPayload(state) {
|
|
25850
|
-
const leaseId = string(
|
|
25879
|
+
const leaseId = string(record9(state.command).leaseId);
|
|
25851
25880
|
return {
|
|
25852
25881
|
...leaseId ? { leaseId } : {},
|
|
25853
25882
|
status: state.candidateStatus,
|
|
25854
|
-
result:
|
|
25883
|
+
result: record9(state.candidateResult),
|
|
25855
25884
|
...string(state.candidateError) ? { error: truncate(state.candidateError, 4e3) } : {}
|
|
25856
25885
|
};
|
|
25857
25886
|
}
|
|
25858
25887
|
function closureAttemptKey(response) {
|
|
25859
|
-
const phase = string(
|
|
25888
|
+
const phase = string(record9(response).closurePhase) ?? "disposition_closure";
|
|
25860
25889
|
if (phase === "work_disposition_closure") return "workDisposition";
|
|
25861
25890
|
if (phase === "live_path_closure") return "livePath";
|
|
25862
25891
|
if (phase === "terminal_disposition_closure") return "terminalDisposition";
|
|
@@ -25882,7 +25911,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
25882
25911
|
completionCheckRetryDelayMs: 100,
|
|
25883
25912
|
phaseMaxAttempts: 10,
|
|
25884
25913
|
maxAgeMs: 7 * 24 * 60 * 60 * 1e3,
|
|
25885
|
-
...
|
|
25914
|
+
...record9(ports.limits)
|
|
25886
25915
|
};
|
|
25887
25916
|
const persist = (state) => ports.persistState(state);
|
|
25888
25917
|
const now = () => ports.now();
|
|
@@ -25921,7 +25950,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
25921
25950
|
for (let attempt = 1; attempt <= limits.completionCheckMaxAttempts; attempt += 1) {
|
|
25922
25951
|
try {
|
|
25923
25952
|
const request = runCompletionCheckRequest(state);
|
|
25924
|
-
const response =
|
|
25953
|
+
const response = record9(await ports.completionAuthority({ state, request }));
|
|
25925
25954
|
if (![
|
|
25926
25955
|
"amaster.runtime-connector.completion-check.v1",
|
|
25927
25956
|
"amaster.runtime-connector.completion-check.v2"
|
|
@@ -25934,7 +25963,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
25934
25963
|
state = transitionRunCompletionState(state, event, {
|
|
25935
25964
|
completionResponse: response,
|
|
25936
25965
|
candidateResult: {
|
|
25937
|
-
...
|
|
25966
|
+
...record9(state.candidateResult),
|
|
25938
25967
|
completionObservation: {
|
|
25939
25968
|
outcome: response.outcome,
|
|
25940
25969
|
enforcementMode: response.enforcementMode,
|
|
@@ -25956,7 +25985,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
25956
25985
|
candidateStatus: "failed",
|
|
25957
25986
|
candidateError: message2,
|
|
25958
25987
|
candidateResult: {
|
|
25959
|
-
...
|
|
25988
|
+
...record9(state.candidateResult),
|
|
25960
25989
|
errorCode: ports.errorCode(error) ?? string(error?.code) ?? "runtime_completion_check_authority_rejected",
|
|
25961
25990
|
completionCheckAbort: {
|
|
25962
25991
|
httpStatus: Number(error?.httpStatus) || null,
|
|
@@ -26006,17 +26035,17 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26006
26035
|
}
|
|
26007
26036
|
if (state.phase === "cost_ingest_pending") {
|
|
26008
26037
|
try {
|
|
26009
|
-
const receipt =
|
|
26038
|
+
const receipt = record9(await ports.costIngestor(state));
|
|
26010
26039
|
const aggregateUsage = usageResult(state);
|
|
26011
|
-
const aggregate =
|
|
26040
|
+
const aggregate = record9(record9(state.usageRecord).aggregate);
|
|
26012
26041
|
state = markRunCompletionCostDelivered({
|
|
26013
26042
|
...state,
|
|
26014
26043
|
candidateResult: {
|
|
26015
|
-
...
|
|
26044
|
+
...record9(state.candidateResult),
|
|
26016
26045
|
usage: aggregateUsage,
|
|
26017
|
-
usageBreakdown: Array.isArray(
|
|
26046
|
+
usageBreakdown: Array.isArray(record9(state.usageRecord).turns) ? record9(state.usageRecord).turns : [],
|
|
26018
26047
|
costUsage: {
|
|
26019
|
-
idempotencyKey: string(
|
|
26048
|
+
idempotencyKey: string(record9(state.usageRecord).idempotencyKey),
|
|
26020
26049
|
...string(receipt.costEventId) ? { costEventId: string(receipt.costEventId) } : {},
|
|
26021
26050
|
...aggregateUsage,
|
|
26022
26051
|
costCents: number(aggregate.costCents)
|
|
@@ -26037,7 +26066,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26037
26066
|
diagnose(`AMaster daemon retained cost_ingest_pending state for ${state.commandId}: ${message}`);
|
|
26038
26067
|
return { pending: true, resultDelivered: false, state };
|
|
26039
26068
|
}
|
|
26040
|
-
const usageRecord =
|
|
26069
|
+
const usageRecord = record9(state.usageRecord);
|
|
26041
26070
|
state = persist(transitionRunCompletionState({
|
|
26042
26071
|
...state,
|
|
26043
26072
|
usageRecord: {
|
|
@@ -26062,13 +26091,13 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26062
26091
|
}
|
|
26063
26092
|
if (state.phase === "profile_cleanup") {
|
|
26064
26093
|
try {
|
|
26065
|
-
const cleanup =
|
|
26066
|
-
const candidateResult =
|
|
26094
|
+
const cleanup = record9(await ports.profileCleaner(state));
|
|
26095
|
+
const candidateResult = record9(state.candidateResult);
|
|
26067
26096
|
state = transitionRunCompletionState(state, "profile_cleaned", {
|
|
26068
26097
|
managedMcpCleanup: cleanup,
|
|
26069
26098
|
candidateResult: {
|
|
26070
26099
|
...candidateResult,
|
|
26071
|
-
...Object.keys(
|
|
26100
|
+
...Object.keys(record9(candidateResult.managedMcp)).length > 0 ? { managedMcp: { ...record9(candidateResult.managedMcp), cleanup } } : {}
|
|
26072
26101
|
}
|
|
26073
26102
|
}, now());
|
|
26074
26103
|
state = persist(state);
|
|
@@ -26180,7 +26209,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26180
26209
|
pending: false,
|
|
26181
26210
|
resultDelivered: true,
|
|
26182
26211
|
state,
|
|
26183
|
-
managedMcpCleanup:
|
|
26212
|
+
managedMcpCleanup: record9(state.managedMcpCleanup)
|
|
26184
26213
|
};
|
|
26185
26214
|
}
|
|
26186
26215
|
async function coordinate(inputState, options = {}) {
|
|
@@ -26194,23 +26223,23 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26194
26223
|
}
|
|
26195
26224
|
if (checked.pending) return { pending: true, resultDelivered: false, state };
|
|
26196
26225
|
while (state.phase === "disposition_required") {
|
|
26197
|
-
const response =
|
|
26226
|
+
const response = record9(state.completionResponse);
|
|
26198
26227
|
const attemptKey = closureAttemptKey(response);
|
|
26199
26228
|
const v2 = response.contractVersion === "amaster.runtime-connector.completion-check.v2";
|
|
26200
|
-
const closureTurns =
|
|
26229
|
+
const closureTurns = record9(state.closureTurns);
|
|
26201
26230
|
const alreadyRecorded = attemptKey ? Boolean(closureTurns[attemptKey]) : state.closureTurnRecorded === true;
|
|
26202
26231
|
const recoveryCount = number(state.closureRecoveryCount);
|
|
26203
26232
|
const mayResumeUncertainClosure = recoveringClosure && !alreadyRecorded && recoveryCount < 1;
|
|
26204
|
-
const priorAttempt = attemptKey ? number(
|
|
26233
|
+
const priorAttempt = attemptKey ? number(record9(state.closureAttempts)[attemptKey]) : number(state.closureAttempt);
|
|
26205
26234
|
if (priorAttempt === 0 || mayResumeUncertainClosure) {
|
|
26206
|
-
const nextAttempts = attemptKey ? { ...
|
|
26235
|
+
const nextAttempts = attemptKey ? { ...record9(state.closureAttempts), [attemptKey]: 1 } : record9(state.closureAttempts);
|
|
26207
26236
|
state = persist(transitionRunCompletionState(state, "closure_started", {
|
|
26208
26237
|
...v2 ? { closureAttempts: nextAttempts } : { closureAttempt: 1 },
|
|
26209
26238
|
...mayResumeUncertainClosure ? { closureRecoveryCount: recoveryCount + 1 } : {}
|
|
26210
26239
|
}, now()));
|
|
26211
26240
|
let closure;
|
|
26212
26241
|
try {
|
|
26213
|
-
closure =
|
|
26242
|
+
closure = record9(await ports.closureExecutor({ state, options }));
|
|
26214
26243
|
} catch (error) {
|
|
26215
26244
|
closure = {
|
|
26216
26245
|
succeeded: false,
|
|
@@ -26224,24 +26253,24 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26224
26253
|
}
|
|
26225
26254
|
};
|
|
26226
26255
|
}
|
|
26227
|
-
const candidateResult =
|
|
26256
|
+
const candidateResult = record9(state.candidateResult);
|
|
26228
26257
|
state = appendRunCompletionUsageTurn({
|
|
26229
26258
|
...state,
|
|
26230
|
-
...attemptKey ? { closureTurns: { ...closureTurns, [attemptKey]:
|
|
26259
|
+
...attemptKey ? { closureTurns: { ...closureTurns, [attemptKey]: record9(closure.audit) } } : { closureTurnRecorded: true },
|
|
26231
26260
|
candidateResult: {
|
|
26232
26261
|
...candidateResult,
|
|
26233
|
-
closureTurn:
|
|
26234
|
-
...attemptKey ? { closureTurns: { ...
|
|
26262
|
+
closureTurn: record9(closure.audit),
|
|
26263
|
+
...attemptKey ? { closureTurns: { ...record9(candidateResult.closureTurns), [attemptKey]: record9(closure.audit) } } : {}
|
|
26235
26264
|
}
|
|
26236
26265
|
}, {
|
|
26237
26266
|
turn: closureTurnKind(attemptKey),
|
|
26238
|
-
usage:
|
|
26267
|
+
usage: record9(closure.usage),
|
|
26239
26268
|
recordedAt: now()
|
|
26240
26269
|
});
|
|
26241
26270
|
state = persist({
|
|
26242
26271
|
...state,
|
|
26243
26272
|
completionRequest: {
|
|
26244
|
-
...
|
|
26273
|
+
...record9(state.completionRequest),
|
|
26245
26274
|
resultSignals: runCompletionCheckRequest(state).resultSignals
|
|
26246
26275
|
}
|
|
26247
26276
|
});
|
|
@@ -26256,9 +26285,9 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26256
26285
|
break;
|
|
26257
26286
|
}
|
|
26258
26287
|
if (state.phase === "disposition_required") {
|
|
26259
|
-
const candidateResult =
|
|
26260
|
-
const closureTurn =
|
|
26261
|
-
const response =
|
|
26288
|
+
const candidateResult = record9(state.candidateResult);
|
|
26289
|
+
const closureTurn = record9(candidateResult.closureTurn);
|
|
26290
|
+
const response = record9(state.completionResponse);
|
|
26262
26291
|
const closureFailure = failedCandidate(
|
|
26263
26292
|
state,
|
|
26264
26293
|
AMASTER_RUNTIME_COMPLETION_CLOSURE_EXHAUSTED_ERROR_CODE,
|
|
@@ -26270,7 +26299,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26270
26299
|
...closureFailure,
|
|
26271
26300
|
candidateResult: {
|
|
26272
26301
|
...candidateResult,
|
|
26273
|
-
...
|
|
26302
|
+
...record9(closureFailure.candidateResult),
|
|
26274
26303
|
errorCode: AMASTER_RUNTIME_COMPLETION_CLOSURE_EXHAUSTED_ERROR_CODE,
|
|
26275
26304
|
...Object.keys(closureTurn).length > 0 ? {} : {
|
|
26276
26305
|
closureTurn: {
|
|
@@ -26286,7 +26315,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26286
26315
|
attempt: 1,
|
|
26287
26316
|
reasonCode: string(response.reasonCode) ?? "disposition_still_required",
|
|
26288
26317
|
commandId: state.commandId,
|
|
26289
|
-
runId: string(
|
|
26318
|
+
runId: string(record9(state.command).runId) ?? string(record9(record9(state.command).payload).runId)
|
|
26290
26319
|
}
|
|
26291
26320
|
}
|
|
26292
26321
|
}, now()));
|
|
@@ -26760,10 +26789,10 @@ function compactExecutorJsonlForTranscript(event) {
|
|
|
26760
26789
|
const text2 = JSON.stringify(compactExecutorJsonValue(event, stringMaxChars));
|
|
26761
26790
|
if (text2.length <= 15e3) return text2;
|
|
26762
26791
|
}
|
|
26763
|
-
const
|
|
26764
|
-
const item = tcAsRecord(
|
|
26792
|
+
const record11 = tcAsRecord(event);
|
|
26793
|
+
const item = tcAsRecord(record11.item);
|
|
26765
26794
|
return JSON.stringify({
|
|
26766
|
-
type: tcReadString(
|
|
26795
|
+
type: tcReadString(record11.type) ?? "executor.event",
|
|
26767
26796
|
item: item.type ? {
|
|
26768
26797
|
id: tcReadString(item.id),
|
|
26769
26798
|
type: tcReadString(item.type),
|
|
@@ -26776,31 +26805,31 @@ function compactExecutorJsonlForTranscript(event) {
|
|
|
26776
26805
|
});
|
|
26777
26806
|
}
|
|
26778
26807
|
function compactPiToolLifecycleForTranscript(event, readableSummary) {
|
|
26779
|
-
const
|
|
26780
|
-
const type = tcReadString(
|
|
26808
|
+
const record11 = tcAsRecord(event);
|
|
26809
|
+
const type = tcReadString(record11.type);
|
|
26781
26810
|
if (type !== "tool_execution_start" && type !== "tool_execution_end") return null;
|
|
26782
|
-
const toolCallId = tcReadString(
|
|
26811
|
+
const toolCallId = tcReadString(record11.toolCallId);
|
|
26783
26812
|
if (!toolCallId) return null;
|
|
26784
|
-
const toolName = tcReadString(
|
|
26813
|
+
const toolName = tcReadString(record11.toolName) ?? "tool";
|
|
26785
26814
|
const summary = tcTruncateText(readableSummary || `${type === "tool_execution_start" ? "\u5DE5\u5177\u5F00\u59CB" : "\u5DE5\u5177\u5B8C\u6210"}\uFF1A${toolName}`, 500);
|
|
26786
26815
|
return JSON.stringify(type === "tool_execution_start" ? {
|
|
26787
26816
|
type,
|
|
26788
26817
|
toolCallId,
|
|
26789
26818
|
toolName,
|
|
26790
|
-
args:
|
|
26819
|
+
args: record11.args == null ? { summary } : compactToolTranscriptPayload(record11.args)
|
|
26791
26820
|
} : {
|
|
26792
26821
|
type,
|
|
26793
26822
|
toolCallId,
|
|
26794
26823
|
toolName,
|
|
26795
|
-
result:
|
|
26796
|
-
isError:
|
|
26824
|
+
result: record11.result == null ? summary : compactToolTranscriptPayload(record11.result),
|
|
26825
|
+
isError: record11.isError === true
|
|
26797
26826
|
});
|
|
26798
26827
|
}
|
|
26799
26828
|
function summarizeTokenUsage(usage) {
|
|
26800
|
-
const
|
|
26801
|
-
const inputTokens = tcReadNumber(
|
|
26802
|
-
const cachedInputTokens = tcReadNumber(
|
|
26803
|
-
const outputTokens = tcReadNumber(
|
|
26829
|
+
const record11 = tcAsRecord(usage);
|
|
26830
|
+
const inputTokens = tcReadNumber(record11.input_tokens ?? record11.inputTokens, 0);
|
|
26831
|
+
const cachedInputTokens = tcReadNumber(record11.cached_input_tokens ?? record11.cachedInputTokens, 0);
|
|
26832
|
+
const outputTokens = tcReadNumber(record11.output_tokens ?? record11.outputTokens, 0);
|
|
26804
26833
|
const parts = [];
|
|
26805
26834
|
if (inputTokens > 0) parts.push(`\u8F93\u5165 ${inputTokens}`);
|
|
26806
26835
|
if (cachedInputTokens > 0) parts.push(`\u7F13\u5B58 ${cachedInputTokens}`);
|
|
@@ -27062,8 +27091,8 @@ function summarizeClaudeEvent(event) {
|
|
|
27062
27091
|
return null;
|
|
27063
27092
|
}
|
|
27064
27093
|
function tcPiMessageText(message) {
|
|
27065
|
-
const
|
|
27066
|
-
const content =
|
|
27094
|
+
const record11 = tcAsRecord(message);
|
|
27095
|
+
const content = record11.content;
|
|
27067
27096
|
if (typeof content === "string" && content.trim().length > 0) return content.trim();
|
|
27068
27097
|
if (!Array.isArray(content)) return "";
|
|
27069
27098
|
return content.map((entry) => {
|
|
@@ -27077,14 +27106,14 @@ function tcPiAssistantMessageEventText(assistantMessageEvent) {
|
|
|
27077
27106
|
return tcReadString(event.content) ?? "";
|
|
27078
27107
|
}
|
|
27079
27108
|
function tcPiMessageStopReason(message) {
|
|
27080
|
-
const
|
|
27081
|
-
return tcReadString(
|
|
27109
|
+
const record11 = tcAsRecord(message);
|
|
27110
|
+
return tcReadString(record11.stopReason ?? record11.stop_reason);
|
|
27082
27111
|
}
|
|
27083
27112
|
function tcPiMessageErrorText(message) {
|
|
27084
|
-
const
|
|
27085
|
-
const explicitError = tcReadString(
|
|
27113
|
+
const record11 = tcAsRecord(message);
|
|
27114
|
+
const explicitError = tcReadString(record11.errorMessage ?? record11.error_message)?.trim();
|
|
27086
27115
|
if (explicitError) return explicitError;
|
|
27087
|
-
const stopReason = tcPiMessageStopReason(
|
|
27116
|
+
const stopReason = tcPiMessageStopReason(record11);
|
|
27088
27117
|
if (stopReason === "error" || stopReason === "failed" || stopReason === "exception") {
|
|
27089
27118
|
return `Pi Agent message ended with stopReason=${stopReason}`;
|
|
27090
27119
|
}
|
|
@@ -27496,16 +27525,16 @@ function structuredToolResults(value, depth = 0) {
|
|
|
27496
27525
|
return [];
|
|
27497
27526
|
}
|
|
27498
27527
|
}
|
|
27499
|
-
const
|
|
27500
|
-
const structuredContent = structuredToolResults(
|
|
27528
|
+
const record11 = asRecord(value);
|
|
27529
|
+
const structuredContent = structuredToolResults(record11.structuredContent, depth + 1);
|
|
27501
27530
|
if (structuredContent.length > 0) return structuredContent;
|
|
27502
|
-
if (readString(
|
|
27531
|
+
if (readString(record11.status)) return [record11];
|
|
27503
27532
|
const candidates = [];
|
|
27504
27533
|
for (const nested of [
|
|
27505
|
-
|
|
27506
|
-
|
|
27507
|
-
|
|
27508
|
-
|
|
27534
|
+
record11.content,
|
|
27535
|
+
record11.text,
|
|
27536
|
+
record11.result,
|
|
27537
|
+
record11.output
|
|
27509
27538
|
]) {
|
|
27510
27539
|
candidates.push(...structuredToolResults(nested, depth + 1));
|
|
27511
27540
|
}
|
|
@@ -27591,10 +27620,10 @@ function createCodebuddyMcpToolResultTracker(options = {}) {
|
|
|
27591
27620
|
},
|
|
27592
27621
|
record(event) {
|
|
27593
27622
|
if (trackingFailure) return [];
|
|
27594
|
-
const
|
|
27595
|
-
const eventType = readString(
|
|
27623
|
+
const record11 = asRecord(event);
|
|
27624
|
+
const eventType = readString(record11.type);
|
|
27596
27625
|
if (eventType === "assistant") {
|
|
27597
|
-
const message2 = asRecord(
|
|
27626
|
+
const message2 = asRecord(record11.message);
|
|
27598
27627
|
for (const rawBlock of Array.isArray(message2.content) ? message2.content : []) {
|
|
27599
27628
|
const block = asRecord(rawBlock);
|
|
27600
27629
|
if (["tool_use", "toolUse"].includes(readString(block.type) ?? "")) {
|
|
@@ -27609,18 +27638,18 @@ function createCodebuddyMcpToolResultTracker(options = {}) {
|
|
|
27609
27638
|
}
|
|
27610
27639
|
if (eventType === "function_call") {
|
|
27611
27640
|
rememberToolUse(
|
|
27612
|
-
|
|
27613
|
-
|
|
27614
|
-
|
|
27641
|
+
record11.call_id ?? record11.tool_use_id ?? record11.id,
|
|
27642
|
+
record11.name,
|
|
27643
|
+
record11.input ?? record11.arguments
|
|
27615
27644
|
);
|
|
27616
27645
|
return [];
|
|
27617
27646
|
}
|
|
27618
27647
|
if (eventType === "function_call_result") {
|
|
27619
|
-
const callId = readString(
|
|
27620
|
-
return recordResult(callId,
|
|
27648
|
+
const callId = readString(record11.call_id ?? record11.tool_use_id ?? record11.id);
|
|
27649
|
+
return recordResult(callId, record11.output ?? record11.result);
|
|
27621
27650
|
}
|
|
27622
27651
|
if (eventType !== "user") return [];
|
|
27623
|
-
const message = asRecord(
|
|
27652
|
+
const message = asRecord(record11.message);
|
|
27624
27653
|
const results = [];
|
|
27625
27654
|
for (const rawBlock of Array.isArray(message.content) ? message.content : []) {
|
|
27626
27655
|
const block = asRecord(rawBlock);
|
|
@@ -27940,8 +27969,8 @@ function classifyPiOutputFailure(input, options = {}) {
|
|
|
27940
27969
|
};
|
|
27941
27970
|
}
|
|
27942
27971
|
function piMessageText(message) {
|
|
27943
|
-
const
|
|
27944
|
-
const content =
|
|
27972
|
+
const record11 = asRecord(message);
|
|
27973
|
+
const content = record11.content;
|
|
27945
27974
|
if (typeof content === "string") return content.trim();
|
|
27946
27975
|
if (!Array.isArray(content)) return "";
|
|
27947
27976
|
return content.map((entry) => {
|
|
@@ -27950,10 +27979,10 @@ function piMessageText(message) {
|
|
|
27950
27979
|
}).filter(Boolean).join("\n").trim();
|
|
27951
27980
|
}
|
|
27952
27981
|
function piAgentEndHasFinalAssistantText(event) {
|
|
27953
|
-
const
|
|
27954
|
-
if (
|
|
27955
|
-
const messages = Array.isArray(
|
|
27956
|
-
if (Object.keys(asRecord(
|
|
27982
|
+
const record11 = asRecord(event);
|
|
27983
|
+
if (record11.type !== "agent_end") return false;
|
|
27984
|
+
const messages = Array.isArray(record11.messages) ? [...record11.messages] : [];
|
|
27985
|
+
if (Object.keys(asRecord(record11.message)).length > 0) messages.push(record11.message);
|
|
27957
27986
|
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
27958
27987
|
const message = asRecord(messages[index]);
|
|
27959
27988
|
if (message.role !== "assistant") continue;
|
|
@@ -27962,9 +27991,9 @@ function piAgentEndHasFinalAssistantText(event) {
|
|
|
27962
27991
|
return false;
|
|
27963
27992
|
}
|
|
27964
27993
|
function piTurnEndHasFinalAssistantText(event) {
|
|
27965
|
-
const
|
|
27966
|
-
if (
|
|
27967
|
-
const message = asRecord(
|
|
27994
|
+
const record11 = asRecord(event);
|
|
27995
|
+
if (record11.type !== "turn_end") return false;
|
|
27996
|
+
const message = asRecord(record11.message);
|
|
27968
27997
|
return message.role === "assistant" && Boolean(piMessageText(message));
|
|
27969
27998
|
}
|
|
27970
27999
|
function piMessageHasToolCall(message) {
|
|
@@ -27992,10 +28021,10 @@ function piTextValue(value) {
|
|
|
27992
28021
|
return typeof value === "string" && value.length > 0 ? value : "";
|
|
27993
28022
|
}
|
|
27994
28023
|
function piAssistantEventText(assistantEvent) {
|
|
27995
|
-
const
|
|
27996
|
-
const type = readString(
|
|
27997
|
-
if (type === "text_delta") return piTextValue(
|
|
27998
|
-
if (type === "text_end") return piTextValue(
|
|
28024
|
+
const record11 = asRecord(assistantEvent);
|
|
28025
|
+
const type = readString(record11.type);
|
|
28026
|
+
if (type === "text_delta") return piTextValue(record11.delta);
|
|
28027
|
+
if (type === "text_end") return piTextValue(record11.content);
|
|
27999
28028
|
return "";
|
|
28000
28029
|
}
|
|
28001
28030
|
function piMessageUsage(message) {
|
|
@@ -28016,14 +28045,14 @@ function assignPiUsage(target, source) {
|
|
|
28016
28045
|
if (source.costUsd > 0) target.costUsd = source.costUsd;
|
|
28017
28046
|
}
|
|
28018
28047
|
function piMessageStopReason(message) {
|
|
28019
|
-
const
|
|
28020
|
-
return readString(
|
|
28048
|
+
const record11 = asRecord(message);
|
|
28049
|
+
return readString(record11.stopReason ?? record11.stop_reason);
|
|
28021
28050
|
}
|
|
28022
28051
|
function piMessageErrorText(message) {
|
|
28023
|
-
const
|
|
28024
|
-
const explicitError = readString(
|
|
28052
|
+
const record11 = asRecord(message);
|
|
28053
|
+
const explicitError = readString(record11.errorMessage ?? record11.error_message)?.trim();
|
|
28025
28054
|
if (explicitError) return explicitError;
|
|
28026
|
-
const stopReason = piMessageStopReason(
|
|
28055
|
+
const stopReason = piMessageStopReason(record11);
|
|
28027
28056
|
if (stopReason === "error" || stopReason === "failed" || stopReason === "exception") {
|
|
28028
28057
|
return `Pi Agent message ended with stopReason=${stopReason}`;
|
|
28029
28058
|
}
|
|
@@ -28439,13 +28468,13 @@ function parseClaudeStreamJson(stdout) {
|
|
|
28439
28468
|
}
|
|
28440
28469
|
function openCodeErrorText(value) {
|
|
28441
28470
|
if (typeof value === "string") return value;
|
|
28442
|
-
const
|
|
28443
|
-
const message = readString(
|
|
28471
|
+
const record11 = asRecord(value);
|
|
28472
|
+
const message = readString(record11.message);
|
|
28444
28473
|
if (message) return message;
|
|
28445
|
-
const data = asRecord(
|
|
28474
|
+
const data = asRecord(record11.data);
|
|
28446
28475
|
const nestedMessage = readString(data.message);
|
|
28447
28476
|
if (nestedMessage) return nestedMessage;
|
|
28448
|
-
return readString(
|
|
28477
|
+
return readString(record11.name) ?? readString(record11.code) ?? "";
|
|
28449
28478
|
}
|
|
28450
28479
|
function parseOpenCodeJsonl(stdout) {
|
|
28451
28480
|
let sessionId = null;
|
|
@@ -29338,19 +29367,19 @@ function promptContextMode(input) {
|
|
|
29338
29367
|
}
|
|
29339
29368
|
function filterDuplicatedTaskComments(context, mode) {
|
|
29340
29369
|
if (mode !== "cold") return context;
|
|
29341
|
-
const
|
|
29370
|
+
const record11 = asRecord(context);
|
|
29342
29371
|
const included = new Set(
|
|
29343
|
-
(Array.isArray(
|
|
29372
|
+
(Array.isArray(record11.paperclipTaskMarkdownCommentIds) ? record11.paperclipTaskMarkdownCommentIds : []).map((entry) => readString(entry)).filter(Boolean)
|
|
29344
29373
|
);
|
|
29345
29374
|
if (included.size === 0) return context;
|
|
29346
|
-
const wake = asRecord(
|
|
29375
|
+
const wake = asRecord(record11.paperclipWake);
|
|
29347
29376
|
const comments = Array.isArray(wake.comments) ? wake.comments : [];
|
|
29348
29377
|
const kept = comments.filter((entry) => {
|
|
29349
29378
|
const id = readString(asRecord(entry).id);
|
|
29350
29379
|
return !id || !included.has(id);
|
|
29351
29380
|
});
|
|
29352
29381
|
if (kept.length === comments.length) return context;
|
|
29353
|
-
return { ...
|
|
29382
|
+
return { ...record11, paperclipWake: { ...wake, comments: kept } };
|
|
29354
29383
|
}
|
|
29355
29384
|
function commentRefs(context) {
|
|
29356
29385
|
const comments = Array.isArray(asRecord(context.paperclipWake).comments) ? asRecord(context.paperclipWake).comments : [];
|
|
@@ -29537,8 +29566,8 @@ function governedReadSection(context) {
|
|
|
29537
29566
|
const reads = Array.isArray(context.governedReadResults) ? context.governedReadResults : [];
|
|
29538
29567
|
if (reads.length === 0) return { content: "", provenance: [] };
|
|
29539
29568
|
const normalized = reads.map((entry, index) => {
|
|
29540
|
-
const
|
|
29541
|
-
const receipt = asRecord(
|
|
29569
|
+
const record11 = asRecord(entry);
|
|
29570
|
+
const receipt = asRecord(record11.receipt);
|
|
29542
29571
|
const provider = readString(receipt.provider) ?? readString(receipt.transport);
|
|
29543
29572
|
const operation = readString(receipt.operation);
|
|
29544
29573
|
const observedAt = readString(receipt.retrievedAt) ?? readString(receipt.observedAt);
|
|
@@ -29548,7 +29577,7 @@ function governedReadSection(context) {
|
|
|
29548
29577
|
throw new Error(`governed_read_context_provenance_invalid: entry ${index} requires provider, operation, observedAt, and source`);
|
|
29549
29578
|
}
|
|
29550
29579
|
return {
|
|
29551
|
-
content:
|
|
29580
|
+
content: record11.content,
|
|
29552
29581
|
receipt: {
|
|
29553
29582
|
provider,
|
|
29554
29583
|
operation,
|
|
@@ -29591,11 +29620,11 @@ function governedBusinessDetailRead(input, issueId) {
|
|
|
29591
29620
|
return { mode: "canonical", tool: canonicalTool, arguments: argumentsValue };
|
|
29592
29621
|
}
|
|
29593
29622
|
function governedBusinessDecisionProjection(state, detailRead) {
|
|
29594
|
-
const
|
|
29595
|
-
const snapshot = asRecord(
|
|
29596
|
-
const authoritativeObjectRefs = Array.isArray(
|
|
29597
|
-
const capabilities = Array.isArray(
|
|
29598
|
-
const availability = asRecord(
|
|
29623
|
+
const record11 = asRecord(state);
|
|
29624
|
+
const snapshot = asRecord(record11.governed_state_snapshot);
|
|
29625
|
+
const authoritativeObjectRefs = Array.isArray(record11.authoritative_object_refs) ? record11.authoritative_object_refs : [];
|
|
29626
|
+
const capabilities = Array.isArray(record11.capabilities) ? record11.capabilities : [];
|
|
29627
|
+
const availability = asRecord(record11.availability);
|
|
29599
29628
|
const projection = {
|
|
29600
29629
|
status: readString(availability.status) ?? null,
|
|
29601
29630
|
objects: authoritativeObjectRefs.map((entry) => {
|
|
@@ -29610,7 +29639,7 @@ function governedBusinessDecisionProjection(state, detailRead) {
|
|
|
29610
29639
|
}
|
|
29611
29640
|
return compact;
|
|
29612
29641
|
}),
|
|
29613
|
-
missing: (Array.isArray(
|
|
29642
|
+
missing: (Array.isArray(record11.missing_objects) ? record11.missing_objects : []).map((entry) => {
|
|
29614
29643
|
const missing = asRecord(entry);
|
|
29615
29644
|
return {
|
|
29616
29645
|
kind: readString(missing.object_kind) ?? null,
|
|
@@ -29630,22 +29659,22 @@ function governedBusinessDecisionProjection(state, detailRead) {
|
|
|
29630
29659
|
if (unavailableReads.length > 0) {
|
|
29631
29660
|
projection.unavailable_reads = unavailableReads;
|
|
29632
29661
|
}
|
|
29633
|
-
const continuationId = readString(
|
|
29662
|
+
const continuationId = readString(record11.continuation_id);
|
|
29634
29663
|
if (continuationId) projection.continuation_id = continuationId;
|
|
29635
|
-
if (Number.isInteger(
|
|
29636
|
-
const freeTextReason = readString(
|
|
29664
|
+
if (Number.isInteger(record11.outcome_revision)) projection.outcome_revision = record11.outcome_revision;
|
|
29665
|
+
const freeTextReason = readString(record11.free_text_reason);
|
|
29637
29666
|
if (freeTextReason) projection.free_text_reason = freeTextReason;
|
|
29638
29667
|
return projection;
|
|
29639
29668
|
}
|
|
29640
29669
|
function governedBusinessModelView(state, input) {
|
|
29641
|
-
const
|
|
29642
|
-
const snapshot = asRecord(
|
|
29670
|
+
const record11 = asRecord(state);
|
|
29671
|
+
const snapshot = asRecord(record11.governed_state_snapshot);
|
|
29643
29672
|
const detailRead = governedBusinessDetailRead(
|
|
29644
29673
|
input,
|
|
29645
29674
|
readString(snapshot.issue_id) ?? readString(input.issueId)
|
|
29646
29675
|
);
|
|
29647
29676
|
if (detailRead.mode === "unavailable") {
|
|
29648
|
-
const { task_acceptance_contract: _TaskAcceptanceContract, ...stateWithoutAcceptanceContract } =
|
|
29677
|
+
const { task_acceptance_contract: _TaskAcceptanceContract, ...stateWithoutAcceptanceContract } = record11;
|
|
29649
29678
|
return {
|
|
29650
29679
|
mode: "full_snapshot",
|
|
29651
29680
|
content: stateWithoutAcceptanceContract,
|
|
@@ -29654,7 +29683,7 @@ function governedBusinessModelView(state, input) {
|
|
|
29654
29683
|
}
|
|
29655
29684
|
return {
|
|
29656
29685
|
mode: "decision_projection",
|
|
29657
|
-
content: governedBusinessDecisionProjection(
|
|
29686
|
+
content: governedBusinessDecisionProjection(record11, detailRead),
|
|
29658
29687
|
unavailableReason: null
|
|
29659
29688
|
};
|
|
29660
29689
|
}
|
|
@@ -29720,10 +29749,10 @@ ${bodies}`,
|
|
|
29720
29749
|
}
|
|
29721
29750
|
function canonicalJsonValue(value) {
|
|
29722
29751
|
if (Array.isArray(value)) return value.map(canonicalJsonValue);
|
|
29723
|
-
const
|
|
29724
|
-
if (Object.keys(
|
|
29752
|
+
const record11 = asRecord(value);
|
|
29753
|
+
if (Object.keys(record11).length === 0) return value;
|
|
29725
29754
|
return Object.fromEntries(
|
|
29726
|
-
Object.keys(
|
|
29755
|
+
Object.keys(record11).sort().map((key) => [key, canonicalJsonValue(record11[key])])
|
|
29727
29756
|
);
|
|
29728
29757
|
}
|
|
29729
29758
|
function resolvedDependencySections(context, input, contextScope, snapshotFreshness) {
|
|
@@ -33419,7 +33448,7 @@ var USAGE_FIELDS = Object.freeze({
|
|
|
33419
33448
|
output: ["outputTokens", "output_tokens", "output"],
|
|
33420
33449
|
total: ["totalTokens", "total_tokens"]
|
|
33421
33450
|
});
|
|
33422
|
-
function
|
|
33451
|
+
function record10(value) {
|
|
33423
33452
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
33424
33453
|
}
|
|
33425
33454
|
function stringValue(value) {
|
|
@@ -33471,7 +33500,7 @@ function aliasedUsageInteger(usage, aliases, label) {
|
|
|
33471
33500
|
return { present: true, value: entries[0] };
|
|
33472
33501
|
}
|
|
33473
33502
|
function piUsageTotal(usageValue) {
|
|
33474
|
-
const usage =
|
|
33503
|
+
const usage = record10(usageValue);
|
|
33475
33504
|
const input = aliasedUsageInteger(usage, USAGE_FIELDS.input, "input");
|
|
33476
33505
|
const cachedInput = aliasedUsageInteger(usage, USAGE_FIELDS.cachedInput, "cached input");
|
|
33477
33506
|
const cacheCreationInput = aliasedUsageInteger(
|
|
@@ -33500,7 +33529,7 @@ function piUsageTotal(usageValue) {
|
|
|
33500
33529
|
return Math.max(componentTotal, total.present ? total.value : 0);
|
|
33501
33530
|
}
|
|
33502
33531
|
function usageFromContainer(containerValue) {
|
|
33503
|
-
const container =
|
|
33532
|
+
const container = record10(containerValue);
|
|
33504
33533
|
if (!Object.prototype.hasOwnProperty.call(container, "usage")) return null;
|
|
33505
33534
|
const usage = container.usage;
|
|
33506
33535
|
if (!usage || typeof usage !== "object" || Array.isArray(usage)) {
|
|
@@ -33512,7 +33541,7 @@ function usageFromContainer(containerValue) {
|
|
|
33512
33541
|
return usage;
|
|
33513
33542
|
}
|
|
33514
33543
|
function measureRestoredPiNativeHistory(managedMcpProfile) {
|
|
33515
|
-
const restored =
|
|
33544
|
+
const restored = record10(managedMcpProfile?.restoredNativeSession);
|
|
33516
33545
|
const rolloutPath = stringValue(restored.rolloutPath);
|
|
33517
33546
|
if (!rolloutPath) {
|
|
33518
33547
|
return { status: "fresh", tokens: 0, rolloutBytes: 0, usageTokens: 0 };
|
|
@@ -33576,7 +33605,7 @@ function resolvePiModelContextBudget({
|
|
|
33576
33605
|
managedMcpProfile
|
|
33577
33606
|
}) {
|
|
33578
33607
|
const instructionBytes = [...finalAgentInstructionFiles.values()].reduce((total, entry) => total + Number(entry.byteSize ?? 0), 0);
|
|
33579
|
-
const profileAttestation =
|
|
33608
|
+
const profileAttestation = record10(managedMcpProfile?.attestation);
|
|
33580
33609
|
const observedToolSchemaBytes = Number(profileAttestation.catalogToolSchemaBytes);
|
|
33581
33610
|
const toolSchemaBytes = Number.isSafeInteger(observedToolSchemaBytes) && observedToolSchemaBytes >= 0 ? observedToolSchemaBytes : 0;
|
|
33582
33611
|
const observedSkillMetadataBytes = Number(profileAttestation.enabledSkillMetadataBytes ?? 0);
|
|
@@ -33943,8 +33972,9 @@ function assertRequiredTaskAttachmentMaterialized(input, materialized) {
|
|
|
33943
33972
|
}
|
|
33944
33973
|
|
|
33945
33974
|
// src/amaster-runtime-daemon.mjs
|
|
33946
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
33975
|
+
var CONNECTOR_VERSION = "0.1.1-beta.354";
|
|
33947
33976
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
33977
|
+
var SUPPORTED_TASK_CONTEXT_VERSIONS = Object.freeze([TASK_CONTEXT_MANIFEST_VERSION, TASK_CONTEXT_V2]);
|
|
33948
33978
|
var daemonRequire = createRequire(import.meta.url);
|
|
33949
33979
|
var MAX_CHECKPOINT_BYTES = 20 * 1024 * 1024;
|
|
33950
33980
|
var CHECKPOINT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -34515,7 +34545,7 @@ function buildRegisterPayload(config) {
|
|
|
34515
34545
|
arch: process.arch,
|
|
34516
34546
|
metadata: {
|
|
34517
34547
|
daemon: "amaster-runtime-daemon.mjs",
|
|
34518
|
-
taskContextVersions:
|
|
34548
|
+
taskContextVersions: SUPPORTED_TASK_CONTEXT_VERSIONS,
|
|
34519
34549
|
connectorVersion: CONNECTOR_VERSION,
|
|
34520
34550
|
...buildCommit ? { buildCommit } : {},
|
|
34521
34551
|
authMode: config.token ? "bearer_token" : config.authHeader ? "custom_header" : "none",
|
|
@@ -34591,6 +34621,7 @@ function buildHeartbeatPayload(config, options = {}) {
|
|
|
34591
34621
|
},
|
|
34592
34622
|
metadata: {
|
|
34593
34623
|
authMode: config.token ? "bearer_token" : config.authHeader ? "custom_header" : "none",
|
|
34624
|
+
taskContextVersions: SUPPORTED_TASK_CONTEXT_VERSIONS,
|
|
34594
34625
|
capabilityReport: {
|
|
34595
34626
|
...capabilityReport,
|
|
34596
34627
|
connectorVersion: CONNECTOR_VERSION,
|
|
@@ -35449,7 +35480,7 @@ function requireCommandContextEnvelope(command) {
|
|
|
35449
35480
|
}
|
|
35450
35481
|
const runDecisionContext = asRecord(envelope.runDecisionContext);
|
|
35451
35482
|
const dynamicContext2 = asRecord(runDecisionContext.content);
|
|
35452
|
-
const runDecisionHash = createHash19("sha256").update(
|
|
35483
|
+
const runDecisionHash = createHash19("sha256").update(canonicalGoalOutcomeValue(dynamicContext2), "utf8").digest("hex");
|
|
35453
35484
|
if (!readString(runDecisionContext.revision) || !Number.isInteger(runDecisionContext.authorizationEpoch) || runDecisionContext.authorizationEpoch < 0 || runDecisionHash !== readString(runDecisionContext.contentSha256)) throw new Error("context_envelope_run_decision_invalid");
|
|
35454
35485
|
if (!Array.isArray(envelope.selectedProcedures)) throw new Error("context_envelope_procedures_invalid");
|
|
35455
35486
|
const toolProfile = asRecord(envelope.toolProfile);
|
|
@@ -35459,17 +35490,12 @@ function requireCommandContextEnvelope(command) {
|
|
|
35459
35490
|
throw new Error("context_envelope_session_binding_invalid");
|
|
35460
35491
|
}
|
|
35461
35492
|
const envelopeHashInput = Object.fromEntries(Object.entries(envelope).filter(([key]) => key !== "envelopeSha256"));
|
|
35462
|
-
const envelopeHash = createHash19("sha256").update(
|
|
35493
|
+
const envelopeHash = createHash19("sha256").update(canonicalGoalOutcomeValue(envelopeHashInput), "utf8").digest("hex");
|
|
35463
35494
|
if (envelopeHash !== readString(envelope.envelopeSha256)) {
|
|
35464
35495
|
throw new Error("context_envelope_hash_mismatch");
|
|
35465
35496
|
}
|
|
35466
35497
|
return { envelope, instructions, files, dynamicContext: dynamicContext2 };
|
|
35467
35498
|
}
|
|
35468
|
-
function canonicalContextJson(value) {
|
|
35469
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
|
|
35470
|
-
if (Array.isArray(value)) return `[${value.map(canonicalContextJson).join(",")}]`;
|
|
35471
|
-
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalContextJson(value[key])}`).join(",")}}`;
|
|
35472
|
-
}
|
|
35473
35499
|
async function materializeEffectiveAgentInstructions(config, command, workspace, instructionContract) {
|
|
35474
35500
|
const files = asRecord(instructionContract.files);
|
|
35475
35501
|
const materialized = [];
|