@amaster.ai/employee-runtime-connector 0.1.1-beta.353 → 0.1.1-beta.355
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 +287 -248
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
|
@@ -21,21 +21,37 @@ function canonicalGoalOutcomeValue(value) {
|
|
|
21
21
|
var TASK_CONTEXT_MANIFEST_VERSION = "task-context-v1";
|
|
22
22
|
var TASK_CONTEXT_V2 = "task-context-v2";
|
|
23
23
|
|
|
24
|
-
// src/
|
|
25
|
-
var
|
|
26
|
-
function
|
|
27
|
-
|
|
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);
|
|
28
31
|
if (manifest?.version !== TASK_CONTEXT_V2) return null;
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
const context = record(manifest.goalOutcomeContext);
|
|
33
|
+
if (!record(context?.binding) || !record(context?.snapshotHash)) throw new Error("goal_authority_context_missing");
|
|
34
|
+
return {
|
|
31
35
|
version: manifest.version,
|
|
32
36
|
freshness: manifest.freshness,
|
|
33
37
|
goalOutcomeContext: manifest.goalOutcomeContext,
|
|
34
38
|
...manifest.contributionContext ? {
|
|
35
39
|
contributionContext: manifest.contributionContext,
|
|
36
|
-
constraint:
|
|
40
|
+
constraint: MIRRORX_GOAL_AUTHORITY_CONTRIBUTION_CONSTRAINT
|
|
37
41
|
} : {}
|
|
38
|
-
}
|
|
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);
|
|
39
55
|
}
|
|
40
56
|
function attestGoalContextDelivery({ authority, prompt, systemPrompt, commandId, runId, executorKind }) {
|
|
41
57
|
if (!authority) return null;
|
|
@@ -11485,9 +11501,16 @@ var suggestTasksResultSchema = external_exports.object({
|
|
|
11485
11501
|
rejectionReason: external_exports.string().trim().max(4e3).nullable().optional()
|
|
11486
11502
|
});
|
|
11487
11503
|
var askUserQuestionsFormFieldSchema = secureInteractionFormFieldSchema;
|
|
11504
|
+
var RESERVED_OTHER_OPTION_LABEL = /^(?:(?:其他|其它)(?:选项|方案|回答|情况|内容)?(?:请)?(?:说明|填写|输入|补充|补充说明)?|自定义(?:选项|方案|回答|内容)?(?:请)?(?:说明|填写|输入|补充|补充说明)?|以上都不是|other(?:option|answer|choice|pleasespecify|specify)?|custom(?:option|answer|choice)?|noneoftheabove|somethingelse)$/iu;
|
|
11505
|
+
function isReservedOtherOptionLabel(label) {
|
|
11506
|
+
const normalized = label.toLowerCase().replace(/[\p{P}\p{S}\s]+/gu, "");
|
|
11507
|
+
return RESERVED_OTHER_OPTION_LABEL.test(normalized);
|
|
11508
|
+
}
|
|
11488
11509
|
var askUserQuestionsQuestionOptionSchema = external_exports.object({
|
|
11489
11510
|
id: external_exports.string().trim().min(1).max(120),
|
|
11490
|
-
label: external_exports.string().trim().min(1).max(120)
|
|
11511
|
+
label: external_exports.string().trim().min(1).max(120).describe(
|
|
11512
|
+
"Concrete answer label. Do not add an Other, custom, or none-of-the-above option; the UI always adds one with a free-text input."
|
|
11513
|
+
),
|
|
11491
11514
|
description: external_exports.string().trim().max(500).nullable().optional(),
|
|
11492
11515
|
inputs: external_exports.array(askUserQuestionsFormFieldSchema).max(5).optional()
|
|
11493
11516
|
});
|
|
@@ -11592,6 +11615,27 @@ var askUserQuestionsPayloadSchema = external_exports.object({
|
|
|
11592
11615
|
}
|
|
11593
11616
|
}
|
|
11594
11617
|
});
|
|
11618
|
+
var createAskUserQuestionsPayloadSchema = external_exports.preprocess((value) => {
|
|
11619
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
11620
|
+
const payload = value;
|
|
11621
|
+
if (!Array.isArray(payload.questions)) return value;
|
|
11622
|
+
return {
|
|
11623
|
+
...payload,
|
|
11624
|
+
questions: payload.questions.map((candidate) => {
|
|
11625
|
+
if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) return candidate;
|
|
11626
|
+
const question = candidate;
|
|
11627
|
+
if (!Array.isArray(question.options)) return candidate;
|
|
11628
|
+
return {
|
|
11629
|
+
...question,
|
|
11630
|
+
options: question.options.filter((option) => {
|
|
11631
|
+
if (!option || typeof option !== "object" || Array.isArray(option)) return true;
|
|
11632
|
+
const label = option.label;
|
|
11633
|
+
return typeof label !== "string" || !isReservedOtherOptionLabel(label);
|
|
11634
|
+
})
|
|
11635
|
+
};
|
|
11636
|
+
})
|
|
11637
|
+
};
|
|
11638
|
+
}, askUserQuestionsPayloadSchema);
|
|
11595
11639
|
var askUserQuestionsSecretRefSchema = secureInteractionSecretRefSchema;
|
|
11596
11640
|
var askUserQuestionsAnswerSchema = external_exports.object({
|
|
11597
11641
|
questionId: external_exports.string().trim().min(1).max(120),
|
|
@@ -12207,7 +12251,7 @@ var createIssueThreadInteractionSchema = external_exports.discriminatedUnion("ki
|
|
|
12207
12251
|
summary: external_exports.string().trim().max(1e3).nullable().optional(),
|
|
12208
12252
|
provenance: issueThreadInteractionProvenanceInputSchema.optional(),
|
|
12209
12253
|
continuationPolicy: external_exports.enum(["none", "wake_assignee"]).optional().default("wake_assignee"),
|
|
12210
|
-
payload:
|
|
12254
|
+
payload: createAskUserQuestionsPayloadSchema
|
|
12211
12255
|
}),
|
|
12212
12256
|
external_exports.object({
|
|
12213
12257
|
kind: external_exports.literal("choose_task_disposition"),
|
|
@@ -18406,16 +18450,16 @@ var PI_TOOL_ARGUMENT_GUARD_DEFAULTS = Object.freeze({
|
|
|
18406
18450
|
nearMissAmplificationThreshold: 8,
|
|
18407
18451
|
nearMissReplayRatioThreshold: 0.75
|
|
18408
18452
|
});
|
|
18409
|
-
function
|
|
18453
|
+
function record2(value) {
|
|
18410
18454
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
18411
18455
|
}
|
|
18412
18456
|
function toolCallContentArrays(event) {
|
|
18413
|
-
const root =
|
|
18414
|
-
const assistantEvent =
|
|
18457
|
+
const root = record2(event);
|
|
18458
|
+
const assistantEvent = record2(root.assistantMessageEvent);
|
|
18415
18459
|
return [
|
|
18416
|
-
|
|
18417
|
-
|
|
18418
|
-
|
|
18460
|
+
record2(assistantEvent.partial).content,
|
|
18461
|
+
record2(root.partial).content,
|
|
18462
|
+
record2(root.message).content
|
|
18419
18463
|
].filter(Array.isArray);
|
|
18420
18464
|
}
|
|
18421
18465
|
function toolCallIdentity(item, index) {
|
|
@@ -18437,7 +18481,7 @@ function partialToolCalls(event) {
|
|
|
18437
18481
|
const seen = /* @__PURE__ */ new Set();
|
|
18438
18482
|
for (const content of toolCallContentArrays(event)) {
|
|
18439
18483
|
for (let index = 0; index < content.length; index += 1) {
|
|
18440
|
-
const item =
|
|
18484
|
+
const item = record2(content[index]);
|
|
18441
18485
|
if (readString(item.type)?.toLowerCase() !== "toolcall") continue;
|
|
18442
18486
|
const snapshot = partialArgumentSnapshot(item);
|
|
18443
18487
|
if (snapshot === null) continue;
|
|
@@ -18514,7 +18558,7 @@ function createPiToolArgumentAmplificationTracker(options = {}) {
|
|
|
18514
18558
|
const calls = /* @__PURE__ */ new Map();
|
|
18515
18559
|
let breach = null;
|
|
18516
18560
|
const noteToolExecutionStart = (event) => {
|
|
18517
|
-
const root =
|
|
18561
|
+
const root = record2(event);
|
|
18518
18562
|
const id = readString(root.toolCallId) ?? readString(root.id) ?? readString(root.callId);
|
|
18519
18563
|
const toolName = readString(root.toolName) ?? readString(root.name);
|
|
18520
18564
|
for (const state of calls.values()) {
|
|
@@ -18585,12 +18629,12 @@ function createPiToolArgumentAmplificationTracker(options = {}) {
|
|
|
18585
18629
|
}
|
|
18586
18630
|
|
|
18587
18631
|
// src/amaster-runtime-daemon/pi-output-retention.mjs
|
|
18588
|
-
function
|
|
18632
|
+
function record3(value) {
|
|
18589
18633
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
18590
18634
|
}
|
|
18591
18635
|
function compactIncrementalEvent(event) {
|
|
18592
18636
|
if (event.type !== "message_update") return null;
|
|
18593
|
-
const assistantEvent =
|
|
18637
|
+
const assistantEvent = record3(event.assistantMessageEvent);
|
|
18594
18638
|
const type = typeof assistantEvent.type === "string" ? assistantEvent.type : "";
|
|
18595
18639
|
if (!type.endsWith("_delta") && type !== "text_end" && type !== "thinking_end") return null;
|
|
18596
18640
|
const compact = { type: "message_update", assistantMessageEvent: { type } };
|
|
@@ -20409,7 +20453,7 @@ var SAFE_SHARED_PROVIDER_INTEGER_KEYS = /* @__PURE__ */ new Set([
|
|
|
20409
20453
|
"websocket_connect_timeout_ms"
|
|
20410
20454
|
]);
|
|
20411
20455
|
var BUILT_IN_MODEL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "amazon-bedrock", "ollama", "lmstudio"]);
|
|
20412
|
-
function
|
|
20456
|
+
function record4(value) {
|
|
20413
20457
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
20414
20458
|
}
|
|
20415
20459
|
function nonEmpty(value, label) {
|
|
@@ -20456,7 +20500,7 @@ function findSessionRollout(sessionsRoot, sessionId) {
|
|
|
20456
20500
|
return matches[0];
|
|
20457
20501
|
}
|
|
20458
20502
|
function restoreManagedCodexSessionRollout(input, codexHome, runDir, executorHome, authority) {
|
|
20459
|
-
const session =
|
|
20503
|
+
const session = record4(input.nativeSession);
|
|
20460
20504
|
const governedApprovalContinuation = session.mode === "governed_action_approval" && session.required === true;
|
|
20461
20505
|
const governedTaskSessionContinuation = session.mode === "task_session" && session.required === false;
|
|
20462
20506
|
if (!governedApprovalContinuation && !governedTaskSessionContinuation) return null;
|
|
@@ -20510,7 +20554,7 @@ function resolveManagedCodexSessionRollout(input, codexHome, runDir, executorHom
|
|
|
20510
20554
|
nativeSessionRestoreSkippedReason: null
|
|
20511
20555
|
};
|
|
20512
20556
|
} catch (error) {
|
|
20513
|
-
if (
|
|
20557
|
+
if (record4(input.nativeSession).mode === "task_session" && error instanceof Error && error.message.startsWith("codex_managed_mcp_session_rollout_missing:")) {
|
|
20514
20558
|
return {
|
|
20515
20559
|
restoredNativeSession: null,
|
|
20516
20560
|
nativeSessionRestoreSkippedReason: "native_session_rollout_missing"
|
|
@@ -20551,14 +20595,14 @@ function sharedCodexModelRoute(sourceHome) {
|
|
|
20551
20595
|
}
|
|
20552
20596
|
const providerId = config.model_provider;
|
|
20553
20597
|
if (!providerId) return { root, table: [], mode: config.model ? "shared_model" : "default", protectedValues: [] };
|
|
20554
|
-
const selectedProvider =
|
|
20598
|
+
const selectedProvider = record4(config.model_providers)[providerId];
|
|
20555
20599
|
if (selectedProvider == null) {
|
|
20556
20600
|
if (!BUILT_IN_MODEL_PROVIDERS.has(providerId)) {
|
|
20557
20601
|
throw new Error(`codex_managed_mcp_source_provider_missing: ${providerId}`);
|
|
20558
20602
|
}
|
|
20559
20603
|
return { root, table: [], mode: "shared_builtin_provider", protectedValues: [] };
|
|
20560
20604
|
}
|
|
20561
|
-
if (Object.keys(
|
|
20605
|
+
if (Object.keys(record4(selectedProvider)).length === 0) {
|
|
20562
20606
|
throw new Error(`codex_managed_mcp_provider_config_invalid: model_providers.${providerId} must be a non-empty table`);
|
|
20563
20607
|
}
|
|
20564
20608
|
const projectedProvider = {};
|
|
@@ -20589,7 +20633,7 @@ function sharedCodexModelRoute(sourceHome) {
|
|
|
20589
20633
|
continue;
|
|
20590
20634
|
}
|
|
20591
20635
|
if (key === "http_headers") {
|
|
20592
|
-
const headers =
|
|
20636
|
+
const headers = record4(value);
|
|
20593
20637
|
if (Object.keys(headers).length === 0 || Object.values(headers).some((entry) => typeof entry !== "string")) {
|
|
20594
20638
|
throw new Error("codex_managed_mcp_provider_config_invalid: http_headers must be a non-empty string table");
|
|
20595
20639
|
}
|
|
@@ -20635,18 +20679,18 @@ function runAttestation(executorCommand, env, cwd, gatewayUrl, expectedHeaders)
|
|
|
20635
20679
|
if (!Array.isArray(servers) || servers.length !== 1) {
|
|
20636
20680
|
throw new Error(`codex_managed_mcp_attestation_failed: expected one MCP server, received ${Array.isArray(servers) ? servers.length : "non_array"}`);
|
|
20637
20681
|
}
|
|
20638
|
-
const server =
|
|
20639
|
-
const transport =
|
|
20640
|
-
const effectiveHeaders =
|
|
20682
|
+
const server = record4(servers[0]);
|
|
20683
|
+
const transport = record4(server.transport);
|
|
20684
|
+
const effectiveHeaders = record4(transport.http_headers);
|
|
20641
20685
|
const headersMatch = Object.keys(effectiveHeaders).length === Object.keys(expectedHeaders).length && Object.entries(expectedHeaders).every(([name, value]) => effectiveHeaders[name] === value);
|
|
20642
|
-
if (server.name !== SUPPORTED_SERVER_NAME || server.enabled !== true || transport.type !== "streamable_http" || transport.url !== gatewayUrl || !headersMatch || Object.keys(
|
|
20686
|
+
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) {
|
|
20643
20687
|
throw new Error("codex_managed_mcp_attestation_failed: effective MCP config does not match managed amaster Gateway");
|
|
20644
20688
|
}
|
|
20645
20689
|
return executorVersion;
|
|
20646
20690
|
}
|
|
20647
20691
|
function validateAuthority(input) {
|
|
20648
|
-
const runtimeAuth =
|
|
20649
|
-
const gateway =
|
|
20692
|
+
const runtimeAuth = record4(input.runtimeAuth);
|
|
20693
|
+
const gateway = record4(runtimeAuth.governedMcp);
|
|
20650
20694
|
const runId = nonEmpty(input.runId, "runId");
|
|
20651
20695
|
if (runtimeAuth.runId !== runId) throw new Error("codex_managed_mcp_owner_mismatch: command runId does not match runtime authority");
|
|
20652
20696
|
if (gateway.schemaVersion !== SUPPORTED_SCHEMA_VERSION) throw new Error("codex_managed_mcp_invalid: unsupported schema version");
|
|
@@ -20662,7 +20706,7 @@ function validateAuthority(input) {
|
|
|
20662
20706
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() + 3e4) {
|
|
20663
20707
|
throw new Error("codex_managed_mcp_session_expired: Gateway session must remain valid through spawn preflight");
|
|
20664
20708
|
}
|
|
20665
|
-
const headers =
|
|
20709
|
+
const headers = record4(gateway.headers);
|
|
20666
20710
|
for (const name of REQUIRED_AUTHORITY_HEADERS) nonEmpty(headers[name], `headers.${name}`);
|
|
20667
20711
|
const allowedHeaderNames = /* @__PURE__ */ new Set([...REQUIRED_AUTHORITY_HEADERS, ...runtimeAuth.issueId ? ["x-amaster-issue-id"] : []]);
|
|
20668
20712
|
if (Object.keys(headers).some((name) => !allowedHeaderNames.has(name)) || Object.keys(headers).length !== allowedHeaderNames.size) {
|
|
@@ -20679,7 +20723,7 @@ function validateAuthority(input) {
|
|
|
20679
20723
|
return { gateway, gatewayUrl, sessionToken, headers, runId };
|
|
20680
20724
|
}
|
|
20681
20725
|
function assertInvocationIsolation(input) {
|
|
20682
|
-
for (const name of Object.keys(
|
|
20726
|
+
for (const name of Object.keys(record4(input.commandEnv))) {
|
|
20683
20727
|
if (FORBIDDEN_COMMAND_ENV.has(name)) throw new Error(`codex_managed_mcp_env_override_blocked: ${name}`);
|
|
20684
20728
|
if (!ALLOWED_COMMAND_ENV.has(name)) throw new Error(`codex_managed_mcp_env_injection_blocked: ${name}`);
|
|
20685
20729
|
}
|
|
@@ -20746,7 +20790,7 @@ function buildIsolatedEnvironment(baseEnv, commandEnv) {
|
|
|
20746
20790
|
const value = safeProxyValue(baseEnv?.[name], name);
|
|
20747
20791
|
if (value) env[name] = value;
|
|
20748
20792
|
}
|
|
20749
|
-
return { ...env, ...
|
|
20793
|
+
return { ...env, ...record4(commandEnv) };
|
|
20750
20794
|
}
|
|
20751
20795
|
function assertNoProjectAmasterOverride(cwd, runDir) {
|
|
20752
20796
|
let cursor = resolve4(cwd);
|
|
@@ -20828,7 +20872,7 @@ function prepareManagedCodexMcpProfile(input) {
|
|
|
20828
20872
|
const owner = Object.freeze({ commandId: input.commandId, runId });
|
|
20829
20873
|
writePrivateFile(markerPath, `${JSON.stringify({ version: 1, ...owner, profileRoot })}
|
|
20830
20874
|
`);
|
|
20831
|
-
const runtimeAuth =
|
|
20875
|
+
const runtimeAuth = record4(input.runtimeAuth);
|
|
20832
20876
|
const authority = Object.freeze({
|
|
20833
20877
|
companyId: nonEmpty(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
20834
20878
|
agentId: nonEmpty(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -21196,7 +21240,7 @@ var FULL_DIRECT_TYPED_V1_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
21196
21240
|
...FULL_DIRECT_TYPED_V1_WIKI_TOOL_NAMES,
|
|
21197
21241
|
...FULL_DIRECT_TYPED_V1_CONNECTOR_TOOL_NAMES
|
|
21198
21242
|
]);
|
|
21199
|
-
function
|
|
21243
|
+
function record5(value) {
|
|
21200
21244
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21201
21245
|
}
|
|
21202
21246
|
function requiredString(value, label, fail2) {
|
|
@@ -21209,11 +21253,11 @@ function validateDirectTypedMcpCatalog(catalogValue, options = {}) {
|
|
|
21209
21253
|
throw new Error(`${errorPrefix}: ${detail}`);
|
|
21210
21254
|
};
|
|
21211
21255
|
const admittedToolNames = options.admittedToolNames instanceof Set ? options.admittedToolNames : options.admittedToolNames == null ? null : new Set(options.admittedToolNames);
|
|
21212
|
-
const catalog =
|
|
21256
|
+
const catalog = record5(catalogValue);
|
|
21213
21257
|
if (catalog.schemaVersion !== DIRECT_TYPED_MCP_CATALOG_SCHEMA_VERSION) {
|
|
21214
21258
|
fail2("direct tool catalog schema mismatch");
|
|
21215
21259
|
}
|
|
21216
|
-
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(
|
|
21260
|
+
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(record5) : [];
|
|
21217
21261
|
const names = /* @__PURE__ */ new Set();
|
|
21218
21262
|
const exposedNames = /* @__PURE__ */ new Set();
|
|
21219
21263
|
const tools = rawTools.map((tool) => {
|
|
@@ -21230,7 +21274,7 @@ function validateDirectTypedMcpCatalog(catalogValue, options = {}) {
|
|
|
21230
21274
|
fail2(`direct tool exposed name collision for ${exposedName}`);
|
|
21231
21275
|
}
|
|
21232
21276
|
exposedNames.add(exposedName);
|
|
21233
|
-
const inputSchema =
|
|
21277
|
+
const inputSchema = record5(tool.inputSchema);
|
|
21234
21278
|
if (inputSchema.type !== "object" || inputSchema.additionalProperties !== false) {
|
|
21235
21279
|
fail2(`direct tool schema is not strict for ${name}`);
|
|
21236
21280
|
}
|
|
@@ -21429,7 +21473,7 @@ var CODEBUDDY_PROFILE_COMPATIBILITY_ALLOWLIST = Object.freeze([
|
|
|
21429
21473
|
profileHash: "b310363c97f72b03debd1d6b90cbc49fa17565c1553a8a0c93ee0f29bfadf3c3"
|
|
21430
21474
|
}
|
|
21431
21475
|
]);
|
|
21432
|
-
function
|
|
21476
|
+
function record6(value) {
|
|
21433
21477
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21434
21478
|
}
|
|
21435
21479
|
function fail(detail) {
|
|
@@ -21460,12 +21504,12 @@ function assertFormalCatalogShape(rawTools) {
|
|
|
21460
21504
|
if (!fullCatalog) fail("direct tool catalog size mismatch");
|
|
21461
21505
|
}
|
|
21462
21506
|
function validateCodebuddyFormalToolCatalog(gatewayValue) {
|
|
21463
|
-
const gateway =
|
|
21507
|
+
const gateway = record6(gatewayValue);
|
|
21464
21508
|
if ((gateway.mcpToolMode ?? "direct_typed") !== "direct_typed") {
|
|
21465
21509
|
fail("direct tool mode required");
|
|
21466
21510
|
}
|
|
21467
|
-
const catalog =
|
|
21468
|
-
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(
|
|
21511
|
+
const catalog = record6(gateway.toolCatalog);
|
|
21512
|
+
const rawTools = Array.isArray(catalog.tools) ? catalog.tools.map(record6) : [];
|
|
21469
21513
|
assertFormalCatalogShape(rawTools);
|
|
21470
21514
|
const validated = validateDirectTypedMcpCatalog(catalog, {
|
|
21471
21515
|
admittedToolNames: FULL_DIRECT_TYPED_V1_TOOL_NAMES,
|
|
@@ -21496,9 +21540,9 @@ function schemaBytes(tools) {
|
|
|
21496
21540
|
return tools.reduce((total, tool) => total + Buffer.byteLength(stablePiJson(tool.inputSchema)), 0);
|
|
21497
21541
|
}
|
|
21498
21542
|
function codebuddyProfileSchemaBytesMatchCatalog(catalogValue, attestationValue) {
|
|
21499
|
-
const catalog =
|
|
21500
|
-
const attestation =
|
|
21501
|
-
const tools = Array.isArray(catalog.tools) ? catalog.tools.map(
|
|
21543
|
+
const catalog = record6(catalogValue);
|
|
21544
|
+
const attestation = record6(attestationValue);
|
|
21545
|
+
const tools = Array.isArray(catalog.tools) ? catalog.tools.map(record6) : [];
|
|
21502
21546
|
const mcpMode = attestation.mcpMode;
|
|
21503
21547
|
const total = attestation.totalMcpSchemaBytes;
|
|
21504
21548
|
const direct = attestation.directMcpSchemaBytes;
|
|
@@ -21768,7 +21812,7 @@ var CODEBUDDY_PROVIDER_ENV = /* @__PURE__ */ new Set([
|
|
|
21768
21812
|
"https_proxy",
|
|
21769
21813
|
"all_proxy"
|
|
21770
21814
|
]);
|
|
21771
|
-
function
|
|
21815
|
+
function record7(value) {
|
|
21772
21816
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21773
21817
|
}
|
|
21774
21818
|
function nonEmpty2(value, label) {
|
|
@@ -22004,7 +22048,7 @@ function codebuddyProjectKey(cwd) {
|
|
|
22004
22048
|
return realpathSync5(cwd).replace(/^[/\\]+/, "").replace(/[\\/:]/g, "-").replace(/-+/g, "-");
|
|
22005
22049
|
}
|
|
22006
22050
|
function restoreManagedCodebuddySessionRollout(input, configDir, runDir, executorHome, authority) {
|
|
22007
|
-
const session =
|
|
22051
|
+
const session = record7(input.nativeSession);
|
|
22008
22052
|
const governedApprovalContinuation = session.mode === "governed_action_approval" && session.required === true;
|
|
22009
22053
|
const taskSessionContinuation = session.mode === "task_session" && session.required === false;
|
|
22010
22054
|
if (!governedApprovalContinuation && !taskSessionContinuation) return null;
|
|
@@ -22048,7 +22092,7 @@ function resolveManagedCodebuddySessionRollout(input, configDir, runDir, executo
|
|
|
22048
22092
|
nativeSessionRestoreSkippedReason: null
|
|
22049
22093
|
};
|
|
22050
22094
|
} catch (error) {
|
|
22051
|
-
if (
|
|
22095
|
+
if (record7(input.nativeSession).mode === "task_session" && error instanceof Error && error.message.startsWith("codebuddy_managed_mcp_session_rollout_missing:")) {
|
|
22052
22096
|
return { restoredNativeSession: null, nativeSessionRestoreSkippedReason: "native_session_rollout_missing" };
|
|
22053
22097
|
}
|
|
22054
22098
|
throw error;
|
|
@@ -22056,7 +22100,7 @@ function resolveManagedCodebuddySessionRollout(input, configDir, runDir, executo
|
|
|
22056
22100
|
}
|
|
22057
22101
|
function buildIsolatedEnvironment2(baseEnv, commandEnv) {
|
|
22058
22102
|
const env = {};
|
|
22059
|
-
for (const source of [
|
|
22103
|
+
for (const source of [record7(baseEnv), record7(commandEnv)]) {
|
|
22060
22104
|
for (const [key, value] of Object.entries(source)) {
|
|
22061
22105
|
if (!SAFE_INHERITED_ENV2.has(key) || typeof value !== "string") continue;
|
|
22062
22106
|
env[key] = value;
|
|
@@ -22066,8 +22110,8 @@ function buildIsolatedEnvironment2(baseEnv, commandEnv) {
|
|
|
22066
22110
|
}
|
|
22067
22111
|
function codebuddyAuthSelection(baseEnv, commandEnv) {
|
|
22068
22112
|
const scopes = [
|
|
22069
|
-
{ name: "command_env", value:
|
|
22070
|
-
{ name: "daemon_env", value:
|
|
22113
|
+
{ name: "command_env", value: record7(commandEnv) },
|
|
22114
|
+
{ name: "daemon_env", value: record7(baseEnv) }
|
|
22071
22115
|
];
|
|
22072
22116
|
for (const scope of scopes) {
|
|
22073
22117
|
const apiKey = typeof scope.value.CODEBUDDY_API_KEY === "string" ? scope.value.CODEBUDDY_API_KEY.trim() : "";
|
|
@@ -22105,7 +22149,7 @@ function inspectCodebuddyProviderAuthReadiness(baseEnv = process.env, commandEnv
|
|
|
22105
22149
|
};
|
|
22106
22150
|
}
|
|
22107
22151
|
function codebuddyProviderEnvironment(baseEnv, commandEnv) {
|
|
22108
|
-
const source = { ...
|
|
22152
|
+
const source = { ...record7(baseEnv), ...record7(commandEnv) };
|
|
22109
22153
|
const selectedAuth = codebuddyAuthSelection(baseEnv, commandEnv);
|
|
22110
22154
|
if (selectedAuth.conflict) {
|
|
22111
22155
|
throw new Error("codebuddy_managed_mcp_auth_conflict: configure only one CodeBuddy authentication method");
|
|
@@ -22137,8 +22181,8 @@ function codebuddyProviderEnvironment(baseEnv, commandEnv) {
|
|
|
22137
22181
|
};
|
|
22138
22182
|
}
|
|
22139
22183
|
function validateAuthority2(input) {
|
|
22140
|
-
const runtimeAuth =
|
|
22141
|
-
const gateway =
|
|
22184
|
+
const runtimeAuth = record7(input.runtimeAuth);
|
|
22185
|
+
const gateway = record7(runtimeAuth.governedMcp);
|
|
22142
22186
|
const runId = nonEmpty2(input.runId, "runId");
|
|
22143
22187
|
if (runtimeAuth.runId !== runId) {
|
|
22144
22188
|
throw new Error("codebuddy_managed_mcp_owner_mismatch: command runId does not match runtime authority");
|
|
@@ -22156,7 +22200,7 @@ function validateAuthority2(input) {
|
|
|
22156
22200
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now()) {
|
|
22157
22201
|
throw new Error("codebuddy_managed_mcp_session_expired");
|
|
22158
22202
|
}
|
|
22159
|
-
const headers =
|
|
22203
|
+
const headers = record7(gateway.headers);
|
|
22160
22204
|
for (const name of REQUIRED_AUTHORITY_HEADERS2) nonEmpty2(headers[name], `headers.${name}`);
|
|
22161
22205
|
if (headers["x-amaster-executor-kind"] !== "codebuddy") {
|
|
22162
22206
|
throw new Error("codebuddy_managed_mcp_invalid: executor header must be codebuddy");
|
|
@@ -23624,7 +23668,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23624
23668
|
const PI_VERSION_ATTESTATION_TIMEOUT_MS = 3e4;
|
|
23625
23669
|
const PI_ATTESTATION_MAX_ATTEMPTS = 2;
|
|
23626
23670
|
const livePiVersionProbes = /* @__PURE__ */ new Map();
|
|
23627
|
-
function
|
|
23671
|
+
function record11(value) {
|
|
23628
23672
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
23629
23673
|
}
|
|
23630
23674
|
function readJsonObjectFile(filePath) {
|
|
@@ -23686,7 +23730,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23686
23730
|
return matches[0];
|
|
23687
23731
|
}
|
|
23688
23732
|
function restoreManagedPiSessionRollout(input, sessionsRoot, runDir, executorHome, authority) {
|
|
23689
|
-
const session =
|
|
23733
|
+
const session = record11(input.nativeSession);
|
|
23690
23734
|
const governedApprovalContinuation = session.mode === "governed_action_approval" && session.required === true;
|
|
23691
23735
|
const governedTaskSessionContinuation = session.mode === "task_session" && session.required === false;
|
|
23692
23736
|
if (!governedApprovalContinuation && !governedTaskSessionContinuation) return null;
|
|
@@ -23745,7 +23789,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23745
23789
|
nativeSessionRestoreSkippedReason: null
|
|
23746
23790
|
};
|
|
23747
23791
|
} catch (error) {
|
|
23748
|
-
if (
|
|
23792
|
+
if (record11(input.nativeSession).mode === "task_session" && error instanceof Error && error.message.startsWith("pi_managed_mcp_session_rollout_missing:")) {
|
|
23749
23793
|
return {
|
|
23750
23794
|
restoredNativeSession: null,
|
|
23751
23795
|
nativeSessionRestoreSkippedReason: "native_session_rollout_missing"
|
|
@@ -23817,7 +23861,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23817
23861
|
return version;
|
|
23818
23862
|
}
|
|
23819
23863
|
function managedPiTelemetryExtension(sharedRuntime) {
|
|
23820
|
-
const settings =
|
|
23864
|
+
const settings = record11(sharedRuntime.settings);
|
|
23821
23865
|
const packages = Array.isArray(settings.packages) ? settings.packages : [];
|
|
23822
23866
|
const configuredSources = packages.filter((source) => typeof source === "string" && (source === MANAGED_PI_TELEMETRY_PACKAGE_SOURCE || source.startsWith(`${MANAGED_PI_TELEMETRY_PACKAGE_SOURCE}@`)));
|
|
23823
23867
|
if (configuredSources.length === 0) return null;
|
|
@@ -23838,7 +23882,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23838
23882
|
if (!packageStat.isDirectory() || packageStat.isSymbolicLink()) throw new Error("unsafe package root");
|
|
23839
23883
|
const packageJsonStat = lstatSync7(packageJsonPath);
|
|
23840
23884
|
if (!packageJsonStat.isFile() || packageJsonStat.isSymbolicLink()) throw new Error("unsafe package manifest");
|
|
23841
|
-
packageJson =
|
|
23885
|
+
packageJson = record11(JSON.parse(readFileSync6(packageJsonPath, "utf8")));
|
|
23842
23886
|
} catch {
|
|
23843
23887
|
throw new Error("pi_managed_mcp_telemetry_package_unavailable");
|
|
23844
23888
|
}
|
|
@@ -23849,7 +23893,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23849
23893
|
if (!/^\d+\.\d+\.\d+(?:[-+].+)?$/.test(version)) {
|
|
23850
23894
|
throw new Error("pi_managed_mcp_telemetry_package_version_invalid");
|
|
23851
23895
|
}
|
|
23852
|
-
const declaredExtensions = Array.isArray(
|
|
23896
|
+
const declaredExtensions = Array.isArray(record11(packageJson.pi).extensions) ? record11(packageJson.pi).extensions : [];
|
|
23853
23897
|
if (declaredExtensions.length !== 1 || typeof declaredExtensions[0] !== "string") {
|
|
23854
23898
|
throw new Error("pi_managed_mcp_telemetry_extension_invalid");
|
|
23855
23899
|
}
|
|
@@ -23879,7 +23923,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23879
23923
|
extensionPath,
|
|
23880
23924
|
extensionSha256: sha2563(readFileSync6(extensionPath)),
|
|
23881
23925
|
packageTreeSha256,
|
|
23882
|
-
langfuseEnabled:
|
|
23926
|
+
langfuseEnabled: record11(record11(settings["pi-telemetry"]).langfuse).enabled === true
|
|
23883
23927
|
};
|
|
23884
23928
|
}
|
|
23885
23929
|
function adapterServerConfigHash(definition, adapterVersion) {
|
|
@@ -23938,8 +23982,8 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23938
23982
|
}
|
|
23939
23983
|
}
|
|
23940
23984
|
function validateAuthority3(input) {
|
|
23941
|
-
const runtimeAuth =
|
|
23942
|
-
const gateway =
|
|
23985
|
+
const runtimeAuth = record11(input.runtimeAuth);
|
|
23986
|
+
const gateway = record11(runtimeAuth.governedMcp);
|
|
23943
23987
|
const runId = nonEmpty3(input.runId, "runId");
|
|
23944
23988
|
if (runtimeAuth.runId !== runId) throw new Error("pi_managed_mcp_owner_mismatch: command runId does not match runtime authority");
|
|
23945
23989
|
if (gateway.schemaVersion !== SUPPORTED_SCHEMA_VERSION3) throw new Error("pi_managed_mcp_invalid: unsupported schema version");
|
|
@@ -23955,7 +23999,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
23955
23999
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() + 3e4) {
|
|
23956
24000
|
throw new Error("pi_managed_mcp_session_expired: Gateway session must remain valid through spawn preflight");
|
|
23957
24001
|
}
|
|
23958
|
-
const headers =
|
|
24002
|
+
const headers = record11(gateway.headers);
|
|
23959
24003
|
for (const name of REQUIRED_AUTHORITY_HEADERS3) nonEmpty3(headers[name], `headers.${name}`);
|
|
23960
24004
|
const allowedHeaderNames = /* @__PURE__ */ new Set([...REQUIRED_AUTHORITY_HEADERS3, ...runtimeAuth.issueId ? ["x-amaster-issue-id"] : []]);
|
|
23961
24005
|
if (Object.keys(headers).some((name) => !allowedHeaderNames.has(name)) || Object.keys(headers).length !== allowedHeaderNames.size) {
|
|
@@ -24014,7 +24058,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24014
24058
|
return env;
|
|
24015
24059
|
}
|
|
24016
24060
|
function assertInvocationIsolation2(input) {
|
|
24017
|
-
for (const name of Object.keys(
|
|
24061
|
+
for (const name of Object.keys(record11(input.commandEnv))) {
|
|
24018
24062
|
if (FORBIDDEN_COMMAND_ENV2.has(name)) throw new Error(`pi_managed_mcp_env_override_blocked: ${name}`);
|
|
24019
24063
|
if (!ALLOWED_COMMAND_ENV2.has(name)) throw new Error(`pi_managed_mcp_env_injection_blocked: ${name}`);
|
|
24020
24064
|
}
|
|
@@ -24046,7 +24090,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24046
24090
|
const value = safeProxyValue2(baseEnv?.[name], name);
|
|
24047
24091
|
if (value) env[name] = value;
|
|
24048
24092
|
}
|
|
24049
|
-
return { ...env, ...
|
|
24093
|
+
return { ...env, ...record11(commandEnv) };
|
|
24050
24094
|
}
|
|
24051
24095
|
function projectMcpConfigHasContent(filePath) {
|
|
24052
24096
|
if (!existsSync7(filePath)) return false;
|
|
@@ -24056,8 +24100,8 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24056
24100
|
} catch {
|
|
24057
24101
|
return true;
|
|
24058
24102
|
}
|
|
24059
|
-
const config =
|
|
24060
|
-
return Object.keys(
|
|
24103
|
+
const config = record11(parsed);
|
|
24104
|
+
return Object.keys(record11(config.mcpServers)).length > 0 || Object.keys(record11(config.servers)).length > 0 || Array.isArray(config.imports) && config.imports.length > 0;
|
|
24061
24105
|
}
|
|
24062
24106
|
function walkProjectMcpConfigs(cwd, runDir, visit) {
|
|
24063
24107
|
const start = resolve7(cwd);
|
|
@@ -24131,7 +24175,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24131
24175
|
let settings = {};
|
|
24132
24176
|
if (existsSync7(settingsPath)) {
|
|
24133
24177
|
try {
|
|
24134
|
-
settings =
|
|
24178
|
+
settings = record11(JSON.parse(readFileSync6(settingsPath, "utf8")));
|
|
24135
24179
|
} catch {
|
|
24136
24180
|
throw new Error("pi_managed_mcp_attestation_failed: source Pi settings are invalid");
|
|
24137
24181
|
}
|
|
@@ -24140,8 +24184,8 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24140
24184
|
const mcpPath = join10(home, "mcp.json");
|
|
24141
24185
|
if (existsSync7(mcpPath)) {
|
|
24142
24186
|
try {
|
|
24143
|
-
userMcpServers = Object.fromEntries(Object.entries(
|
|
24144
|
-
|
|
24187
|
+
userMcpServers = Object.fromEntries(Object.entries(record11(
|
|
24188
|
+
record11(JSON.parse(readFileSync6(mcpPath, "utf8"))).mcpServers
|
|
24145
24189
|
)).filter(([serverName]) => serverName !== SUPPORTED_SERVER_NAME3));
|
|
24146
24190
|
} catch {
|
|
24147
24191
|
userMcpServers = {};
|
|
@@ -24174,7 +24218,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24174
24218
|
return segments.join("/") === value ? value : null;
|
|
24175
24219
|
}
|
|
24176
24220
|
function parseManagedSkillBundle(rawBundle) {
|
|
24177
|
-
const bundle =
|
|
24221
|
+
const bundle = record11(rawBundle);
|
|
24178
24222
|
if (Object.keys(bundle).length === 0) return null;
|
|
24179
24223
|
if (bundle.version !== 1) {
|
|
24180
24224
|
throw new Error("pi_managed_mcp_company_skill_bundle_invalid");
|
|
@@ -24184,13 +24228,13 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
24184
24228
|
}
|
|
24185
24229
|
let totalBytes = 0;
|
|
24186
24230
|
const skills = bundle.skills.map((rawSkill) => {
|
|
24187
|
-
const skill =
|
|
24231
|
+
const skill = record11(rawSkill);
|
|
24188
24232
|
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) {
|
|
24189
24233
|
throw new Error("pi_managed_mcp_company_skill_bundle_invalid");
|
|
24190
24234
|
}
|
|
24191
24235
|
const paths = /* @__PURE__ */ new Set();
|
|
24192
24236
|
const files = skill.files.map((rawFile) => {
|
|
24193
|
-
const file =
|
|
24237
|
+
const file = record11(rawFile);
|
|
24194
24238
|
const relativePath = canonicalManagedSkillRelativePath(file.path);
|
|
24195
24239
|
if (!relativePath || paths.has(relativePath) || !Number.isSafeInteger(file.bytes) || file.bytes < 0 || file.bytes > MANAGED_SKILL_BUNDLE_MAX_FILE_BYTES || typeof file.contentBase64 !== "string") {
|
|
24196
24240
|
throw new Error("pi_managed_mcp_company_skill_bundle_invalid");
|
|
@@ -24457,7 +24501,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24457
24501
|
const closureConfigBytes = Buffer.from(`${JSON.stringify({
|
|
24458
24502
|
...input.config,
|
|
24459
24503
|
mcpServers: {
|
|
24460
|
-
...
|
|
24504
|
+
...record11(input.config.mcpServers),
|
|
24461
24505
|
[SUPPORTED_SERVER_NAME3]: closureServerConfig
|
|
24462
24506
|
}
|
|
24463
24507
|
}, null, 2)}
|
|
@@ -24522,7 +24566,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24522
24566
|
workspaceMcpConfigPath
|
|
24523
24567
|
})}
|
|
24524
24568
|
`);
|
|
24525
|
-
const runtimeAuth =
|
|
24569
|
+
const runtimeAuth = record11(input.runtimeAuth);
|
|
24526
24570
|
const authority = Object.freeze({
|
|
24527
24571
|
companyId: nonEmpty3(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
24528
24572
|
agentId: nonEmpty3(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -24744,18 +24788,18 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24744
24788
|
}
|
|
24745
24789
|
function restoreManagedPiRunExitClosureBaseline2(input, expectedOwner) {
|
|
24746
24790
|
if (!input) return { status: "not_required" };
|
|
24747
|
-
const baseline =
|
|
24791
|
+
const baseline = record11(input);
|
|
24748
24792
|
if (baseline.schemaVersion !== "amaster.pi-run-exit-closure-baseline.v3") {
|
|
24749
24793
|
throw new Error("pi_run_exit_closure_baseline_invalid: unsupported schema version");
|
|
24750
24794
|
}
|
|
24751
|
-
const owner =
|
|
24795
|
+
const owner = record11(baseline.owner);
|
|
24752
24796
|
if (owner.commandId !== expectedOwner?.commandId || owner.runId !== expectedOwner?.runId) {
|
|
24753
24797
|
throw new Error("pi_run_exit_closure_baseline_owner_mismatch");
|
|
24754
24798
|
}
|
|
24755
24799
|
const profileRoot = resolve7(nonEmpty3(baseline.profileRoot, "runExitClosureBaseline.profileRoot"));
|
|
24756
24800
|
const cachePath = resolve7(nonEmpty3(baseline.cachePath, "runExitClosureBaseline.cachePath"));
|
|
24757
24801
|
if (!within3(cachePath, profileRoot)) throw new Error("pi_run_exit_closure_baseline_path_mismatch");
|
|
24758
|
-
const closureProfile = Object.keys(
|
|
24802
|
+
const closureProfile = Object.keys(record11(baseline.closureProfile)).length > 0 ? record11(baseline.closureProfile) : null;
|
|
24759
24803
|
const configPath = closureProfile ? resolve7(nonEmpty3(closureProfile.configPath, "closureProfile.configPath")) : null;
|
|
24760
24804
|
for (const path of [cachePath, configPath].filter(Boolean)) {
|
|
24761
24805
|
if (existsSync7(path)) {
|
|
@@ -24765,7 +24809,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24765
24809
|
}
|
|
24766
24810
|
}
|
|
24767
24811
|
}
|
|
24768
|
-
const baselineCacheOwnership =
|
|
24812
|
+
const baselineCacheOwnership = record11(baseline.cacheOwnership);
|
|
24769
24813
|
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;
|
|
24770
24814
|
if (!cacheOwnership) {
|
|
24771
24815
|
throw new Error("pi_run_exit_closure_baseline_cache_owner_missing");
|
|
@@ -24776,7 +24820,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24776
24820
|
label: "config",
|
|
24777
24821
|
path: configPath,
|
|
24778
24822
|
bytes: Buffer.from(nonEmpty3(closureProfile.configContentsBase64, "closureProfile.configContentsBase64"), "base64"),
|
|
24779
|
-
ownership:
|
|
24823
|
+
ownership: record11(closureProfile.configOwnership)
|
|
24780
24824
|
},
|
|
24781
24825
|
{
|
|
24782
24826
|
label: "cache",
|
|
@@ -24827,7 +24871,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24827
24871
|
const owner = Object.freeze({ commandId: input.commandId, runId });
|
|
24828
24872
|
writePrivateFile2(markerPath, `${JSON.stringify({ version: 1, ...owner, profileRoot, piCodingAgentDir })}
|
|
24829
24873
|
`);
|
|
24830
|
-
const runtimeAuth =
|
|
24874
|
+
const runtimeAuth = record11(input.runtimeAuth);
|
|
24831
24875
|
const authority = Object.freeze({
|
|
24832
24876
|
companyId: nonEmpty3(runtimeAuth.companyId, "runtimeAuth.companyId"),
|
|
24833
24877
|
agentId: nonEmpty3(runtimeAuth.agentId, "runtimeAuth.agentId"),
|
|
@@ -24854,7 +24898,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24854
24898
|
const config = {
|
|
24855
24899
|
...sourceMcp,
|
|
24856
24900
|
settings: {
|
|
24857
|
-
...
|
|
24901
|
+
...record11(sourceMcp.settings),
|
|
24858
24902
|
// Governed catalog exposed names are already provider-safe and are the
|
|
24859
24903
|
// exact identities attested by the Server. A desktop user's adapter
|
|
24860
24904
|
// prefix is local presentation state and must not rename this run's
|
|
@@ -24863,7 +24907,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24863
24907
|
...directCatalog ? { directToolResultDetails: "bounded", freezeDirectTools: true } : {}
|
|
24864
24908
|
},
|
|
24865
24909
|
mcpServers: {
|
|
24866
|
-
...
|
|
24910
|
+
...record11(sourceMcp.mcpServers),
|
|
24867
24911
|
[SUPPORTED_SERVER_NAME3]: serverConfig
|
|
24868
24912
|
}
|
|
24869
24913
|
};
|
|
@@ -24906,7 +24950,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24906
24950
|
);
|
|
24907
24951
|
enabledRoleSkillMetadataBytes = roleSkills.serializedMetadataBytes;
|
|
24908
24952
|
}
|
|
24909
|
-
const userMcpServerNames = Object.keys(
|
|
24953
|
+
const userMcpServerNames = Object.keys(record11(sourceMcp.mcpServers)).filter((serverName) => serverName !== SUPPORTED_SERVER_NAME3);
|
|
24910
24954
|
const adapterVersion = desktopAdapterReadiness?.ready ? desktopAdapterReadiness.adapterVersion : null;
|
|
24911
24955
|
const {
|
|
24912
24956
|
cachePath,
|
|
@@ -24929,7 +24973,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24929
24973
|
});
|
|
24930
24974
|
const env = {
|
|
24931
24975
|
...input.baseEnv,
|
|
24932
|
-
...
|
|
24976
|
+
...record11(input.commandEnv),
|
|
24933
24977
|
AMASTER_RUNTIME_RUN_ID: authority.runId,
|
|
24934
24978
|
AMASTER_RUNTIME_COMMAND_ID: authority.commandId,
|
|
24935
24979
|
...authority.issueId ? { AMASTER_RUNTIME_ISSUE_ID: authority.issueId } : {},
|
|
@@ -25467,8 +25511,8 @@ function resultOutboxFileName(commandId, now = Date.now()) {
|
|
|
25467
25511
|
return `${now}-${safeCommandId}.json`;
|
|
25468
25512
|
}
|
|
25469
25513
|
function isValidResultOutboxEntry(entry) {
|
|
25470
|
-
const
|
|
25471
|
-
return
|
|
25514
|
+
const record11 = asRecord(entry);
|
|
25515
|
+
return record11.version === 1 && Boolean(readString(record11.path)) && Object.keys(asRecord(record11.payload)).length > 0;
|
|
25472
25516
|
}
|
|
25473
25517
|
function resultOutboxEntryAgeMs(entry, nowMs) {
|
|
25474
25518
|
const createdAt = Date.parse(readString(entry.createdAt) ?? "");
|
|
@@ -25532,7 +25576,7 @@ function nextRunCompletionPhase(phase, event) {
|
|
|
25532
25576
|
// src/amaster-runtime-daemon/run-completion-state.mjs
|
|
25533
25577
|
var RUN_COMPLETION_STATE_VERSION = 1;
|
|
25534
25578
|
var RUN_COMPLETION_USAGE_SCHEMA_VERSION = "runtime-command-usage-v1";
|
|
25535
|
-
function
|
|
25579
|
+
function record8(value) {
|
|
25536
25580
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
25537
25581
|
}
|
|
25538
25582
|
function nonEmptyString(value, label) {
|
|
@@ -25557,8 +25601,8 @@ function runCompletionStateFileName(commandId) {
|
|
|
25557
25601
|
return `${safeCommandId}.json`;
|
|
25558
25602
|
}
|
|
25559
25603
|
function normalizeRunTurnUsage(turn) {
|
|
25560
|
-
const source =
|
|
25561
|
-
const nestedUsage =
|
|
25604
|
+
const source = record8(turn);
|
|
25605
|
+
const nestedUsage = record8(source.usage);
|
|
25562
25606
|
const usage = Object.keys(nestedUsage).length > 0 ? nestedUsage : source;
|
|
25563
25607
|
const allowedTurnKinds = /* @__PURE__ */ new Set([
|
|
25564
25608
|
"primary",
|
|
@@ -25600,11 +25644,11 @@ function aggregateRunTurnUsage(turns) {
|
|
|
25600
25644
|
};
|
|
25601
25645
|
}
|
|
25602
25646
|
function createRunCompletionState(input) {
|
|
25603
|
-
const command =
|
|
25647
|
+
const command = record8(input.command);
|
|
25604
25648
|
const commandId = nonEmptyString(command.commandId ?? command.id, "command.commandId");
|
|
25605
25649
|
const connectorId = nonEmptyString(input.connectorId ?? command.connectorId, "connectorId");
|
|
25606
25650
|
const now = typeof input.now === "string" && input.now ? input.now : (/* @__PURE__ */ new Date()).toISOString();
|
|
25607
|
-
const firstTurn = normalizeRunTurnUsage({ ...
|
|
25651
|
+
const firstTurn = normalizeRunTurnUsage({ ...record8(input.turn), turn: "primary", recordedAt: now });
|
|
25608
25652
|
return {
|
|
25609
25653
|
version: RUN_COMPLETION_STATE_VERSION,
|
|
25610
25654
|
commandId,
|
|
@@ -25617,10 +25661,10 @@ function createRunCompletionState(input) {
|
|
|
25617
25661
|
terminalDisposition: 0
|
|
25618
25662
|
},
|
|
25619
25663
|
command,
|
|
25620
|
-
executor:
|
|
25621
|
-
completionRequest:
|
|
25664
|
+
executor: record8(input.executor),
|
|
25665
|
+
completionRequest: record8(input.completionRequest),
|
|
25622
25666
|
candidateStatus: nonEmptyString(input.candidateStatus, "candidateStatus"),
|
|
25623
|
-
candidateResult:
|
|
25667
|
+
candidateResult: record8(input.candidateResult),
|
|
25624
25668
|
...typeof input.candidateError === "string" && input.candidateError ? { candidateError: input.candidateError } : {},
|
|
25625
25669
|
usageRecord: {
|
|
25626
25670
|
schemaVersion: RUN_COMPLETION_USAGE_SCHEMA_VERSION,
|
|
@@ -25668,7 +25712,7 @@ function transitionRunCompletionState(state, event, patch = {}, now = (/* @__PUR
|
|
|
25668
25712
|
}
|
|
25669
25713
|
return assertValidRunCompletionState({
|
|
25670
25714
|
...current,
|
|
25671
|
-
...
|
|
25715
|
+
...record8(patch),
|
|
25672
25716
|
phase: nextPhase,
|
|
25673
25717
|
updatedAt: now
|
|
25674
25718
|
});
|
|
@@ -25681,24 +25725,24 @@ function markRunCompletionCostDelivered(state, receipt, now = (/* @__PURE__ */ n
|
|
|
25681
25725
|
...current.usageRecord,
|
|
25682
25726
|
ingestStatus: "delivered",
|
|
25683
25727
|
deliveredAt: now,
|
|
25684
|
-
receipt:
|
|
25728
|
+
receipt: record8(receipt)
|
|
25685
25729
|
}
|
|
25686
25730
|
}, "cost_ingest_delivered", {}, now);
|
|
25687
25731
|
}
|
|
25688
25732
|
function assertValidRunCompletionState(value) {
|
|
25689
|
-
const state =
|
|
25733
|
+
const state = record8(value);
|
|
25690
25734
|
if (state.version !== RUN_COMPLETION_STATE_VERSION) throw new Error("run_completion_state_invalid:version");
|
|
25691
25735
|
const commandId = nonEmptyString(state.commandId, "commandId");
|
|
25692
25736
|
const connectorId = nonEmptyString(state.connectorId, "connectorId");
|
|
25693
25737
|
if (!isRunCompletionPhase(state.phase)) throw new Error("run_completion_state_invalid:phase");
|
|
25694
|
-
const command =
|
|
25738
|
+
const command = record8(state.command);
|
|
25695
25739
|
if (nonEmptyString(command.commandId ?? command.id, "command.commandId") !== commandId) {
|
|
25696
25740
|
throw new Error("run_completion_state_invalid:command_binding");
|
|
25697
25741
|
}
|
|
25698
25742
|
if (nonEmptyString(command.connectorId, "command.connectorId") !== connectorId) {
|
|
25699
25743
|
throw new Error("run_completion_state_invalid:connector_binding");
|
|
25700
25744
|
}
|
|
25701
|
-
const usageRecord =
|
|
25745
|
+
const usageRecord = record8(state.usageRecord);
|
|
25702
25746
|
if (usageRecord.schemaVersion !== RUN_COMPLETION_USAGE_SCHEMA_VERSION) {
|
|
25703
25747
|
throw new Error("run_completion_state_invalid:usage_schema");
|
|
25704
25748
|
}
|
|
@@ -25729,9 +25773,9 @@ function assertValidRunCompletionState(value) {
|
|
|
25729
25773
|
commandId,
|
|
25730
25774
|
connectorId,
|
|
25731
25775
|
command,
|
|
25732
|
-
executor:
|
|
25733
|
-
completionRequest:
|
|
25734
|
-
candidateResult:
|
|
25776
|
+
executor: record8(state.executor),
|
|
25777
|
+
completionRequest: record8(state.completionRequest),
|
|
25778
|
+
candidateResult: record8(state.candidateResult),
|
|
25735
25779
|
usageRecord: {
|
|
25736
25780
|
...usageRecord,
|
|
25737
25781
|
turns,
|
|
@@ -25771,7 +25815,7 @@ var FINALIZATION_PHASES = /* @__PURE__ */ new Set([
|
|
|
25771
25815
|
"profile_cleanup",
|
|
25772
25816
|
"result_post_pending"
|
|
25773
25817
|
]);
|
|
25774
|
-
function
|
|
25818
|
+
function record9(value) {
|
|
25775
25819
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
25776
25820
|
}
|
|
25777
25821
|
function string(value) {
|
|
@@ -25784,13 +25828,13 @@ function truncate(value, limit = 1e3) {
|
|
|
25784
25828
|
return truncateText(value instanceof Error ? value.message : String(value), limit);
|
|
25785
25829
|
}
|
|
25786
25830
|
function defaultErrorCode(error) {
|
|
25787
|
-
const body =
|
|
25788
|
-
const details =
|
|
25831
|
+
const body = record9(error?.responseBody);
|
|
25832
|
+
const details = record9(body.details);
|
|
25789
25833
|
return string(details.code) ?? string(body.code);
|
|
25790
25834
|
}
|
|
25791
25835
|
function defaultTerminalStatus(error) {
|
|
25792
25836
|
if (defaultErrorCode(error) !== "runtime_completion_check_command_not_acknowledged") return null;
|
|
25793
|
-
const status = string(
|
|
25837
|
+
const status = string(record9(record9(error?.responseBody).details).status);
|
|
25794
25838
|
return ["succeeded", "failed", "cancelled"].includes(status ?? "") ? status : null;
|
|
25795
25839
|
}
|
|
25796
25840
|
function defaultCompletionRetryable(error) {
|
|
@@ -25811,20 +25855,20 @@ function defaultCleanupOwnerMismatch(error) {
|
|
|
25811
25855
|
return /^(?:pi|codex|codebuddy)_managed_mcp_cleanup_owner_mismatch:/.test(message) || /^pi_delegated_mcp_cleanup_owner_mismatch:/.test(message);
|
|
25812
25856
|
}
|
|
25813
25857
|
function runCompletionCheckRequest(state) {
|
|
25814
|
-
const prior =
|
|
25815
|
-
const turns = Array.isArray(
|
|
25858
|
+
const prior = record9(state.completionRequest);
|
|
25859
|
+
const turns = Array.isArray(record9(state.usageRecord).turns) ? record9(state.usageRecord).turns.map(record9) : [];
|
|
25816
25860
|
const terminalTextRepairAttempt = turns.some((turn) => turn.turn === "terminal_text_repair") ? 1 : 0;
|
|
25817
25861
|
const closureAttempt = state.closureAttempt === 1 ? 1 : 0;
|
|
25818
25862
|
const closureAttempts = {
|
|
25819
|
-
workDisposition: number(
|
|
25820
|
-
livePath: number(
|
|
25821
|
-
terminalDisposition: number(
|
|
25863
|
+
workDisposition: number(record9(state.closureAttempts).workDisposition) === 1 ? 1 : 0,
|
|
25864
|
+
livePath: number(record9(state.closureAttempts).livePath) === 1 ? 1 : 0,
|
|
25865
|
+
terminalDisposition: number(record9(state.closureAttempts).terminalDisposition) === 1 ? 1 : 0
|
|
25822
25866
|
};
|
|
25823
25867
|
const v2 = prior.contractVersion === "amaster.runtime-connector.completion-check.v2";
|
|
25824
25868
|
const closureTurnCount = v2 ? closureAttempts.workDisposition + closureAttempts.livePath + closureAttempts.terminalDisposition : closureAttempt;
|
|
25825
25869
|
return {
|
|
25826
25870
|
contractVersion: v2 ? "amaster.runtime-connector.completion-check.v2" : "amaster.runtime-connector.completion-check.v1",
|
|
25827
|
-
...string(
|
|
25871
|
+
...string(record9(state.command).leaseId) ? { leaseId: string(record9(state.command).leaseId) } : {},
|
|
25828
25872
|
proposedStatus: state.candidateStatus,
|
|
25829
25873
|
resultSignals: {
|
|
25830
25874
|
productiveSuccessfulRun: prior.resultSignals?.productiveSuccessfulRun === true,
|
|
@@ -25835,7 +25879,7 @@ function runCompletionCheckRequest(state) {
|
|
|
25835
25879
|
};
|
|
25836
25880
|
}
|
|
25837
25881
|
function usageResult(state) {
|
|
25838
|
-
const aggregate =
|
|
25882
|
+
const aggregate = record9(record9(state.usageRecord).aggregate);
|
|
25839
25883
|
const costUsd = number(aggregate.costUsd);
|
|
25840
25884
|
return {
|
|
25841
25885
|
inputTokens: number(aggregate.inputTokens),
|
|
@@ -25849,27 +25893,27 @@ function failedCandidate(state, errorCode, message, evidence, now) {
|
|
|
25849
25893
|
candidateStatus: "failed",
|
|
25850
25894
|
candidateError: message,
|
|
25851
25895
|
candidateResult: {
|
|
25852
|
-
...
|
|
25896
|
+
...record9(state.candidateResult),
|
|
25853
25897
|
errorCode,
|
|
25854
25898
|
completionDeliveryFailure: {
|
|
25855
25899
|
phase: state.phase,
|
|
25856
25900
|
failedAt: now,
|
|
25857
|
-
...
|
|
25901
|
+
...record9(evidence)
|
|
25858
25902
|
}
|
|
25859
25903
|
}
|
|
25860
25904
|
};
|
|
25861
25905
|
}
|
|
25862
25906
|
function resultPayload(state) {
|
|
25863
|
-
const leaseId = string(
|
|
25907
|
+
const leaseId = string(record9(state.command).leaseId);
|
|
25864
25908
|
return {
|
|
25865
25909
|
...leaseId ? { leaseId } : {},
|
|
25866
25910
|
status: state.candidateStatus,
|
|
25867
|
-
result:
|
|
25911
|
+
result: record9(state.candidateResult),
|
|
25868
25912
|
...string(state.candidateError) ? { error: truncate(state.candidateError, 4e3) } : {}
|
|
25869
25913
|
};
|
|
25870
25914
|
}
|
|
25871
25915
|
function closureAttemptKey(response) {
|
|
25872
|
-
const phase = string(
|
|
25916
|
+
const phase = string(record9(response).closurePhase) ?? "disposition_closure";
|
|
25873
25917
|
if (phase === "work_disposition_closure") return "workDisposition";
|
|
25874
25918
|
if (phase === "live_path_closure") return "livePath";
|
|
25875
25919
|
if (phase === "terminal_disposition_closure") return "terminalDisposition";
|
|
@@ -25895,7 +25939,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
25895
25939
|
completionCheckRetryDelayMs: 100,
|
|
25896
25940
|
phaseMaxAttempts: 10,
|
|
25897
25941
|
maxAgeMs: 7 * 24 * 60 * 60 * 1e3,
|
|
25898
|
-
...
|
|
25942
|
+
...record9(ports.limits)
|
|
25899
25943
|
};
|
|
25900
25944
|
const persist = (state) => ports.persistState(state);
|
|
25901
25945
|
const now = () => ports.now();
|
|
@@ -25934,7 +25978,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
25934
25978
|
for (let attempt = 1; attempt <= limits.completionCheckMaxAttempts; attempt += 1) {
|
|
25935
25979
|
try {
|
|
25936
25980
|
const request = runCompletionCheckRequest(state);
|
|
25937
|
-
const response =
|
|
25981
|
+
const response = record9(await ports.completionAuthority({ state, request }));
|
|
25938
25982
|
if (![
|
|
25939
25983
|
"amaster.runtime-connector.completion-check.v1",
|
|
25940
25984
|
"amaster.runtime-connector.completion-check.v2"
|
|
@@ -25947,7 +25991,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
25947
25991
|
state = transitionRunCompletionState(state, event, {
|
|
25948
25992
|
completionResponse: response,
|
|
25949
25993
|
candidateResult: {
|
|
25950
|
-
...
|
|
25994
|
+
...record9(state.candidateResult),
|
|
25951
25995
|
completionObservation: {
|
|
25952
25996
|
outcome: response.outcome,
|
|
25953
25997
|
enforcementMode: response.enforcementMode,
|
|
@@ -25969,7 +26013,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
25969
26013
|
candidateStatus: "failed",
|
|
25970
26014
|
candidateError: message2,
|
|
25971
26015
|
candidateResult: {
|
|
25972
|
-
...
|
|
26016
|
+
...record9(state.candidateResult),
|
|
25973
26017
|
errorCode: ports.errorCode(error) ?? string(error?.code) ?? "runtime_completion_check_authority_rejected",
|
|
25974
26018
|
completionCheckAbort: {
|
|
25975
26019
|
httpStatus: Number(error?.httpStatus) || null,
|
|
@@ -26019,17 +26063,17 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26019
26063
|
}
|
|
26020
26064
|
if (state.phase === "cost_ingest_pending") {
|
|
26021
26065
|
try {
|
|
26022
|
-
const receipt =
|
|
26066
|
+
const receipt = record9(await ports.costIngestor(state));
|
|
26023
26067
|
const aggregateUsage = usageResult(state);
|
|
26024
|
-
const aggregate =
|
|
26068
|
+
const aggregate = record9(record9(state.usageRecord).aggregate);
|
|
26025
26069
|
state = markRunCompletionCostDelivered({
|
|
26026
26070
|
...state,
|
|
26027
26071
|
candidateResult: {
|
|
26028
|
-
...
|
|
26072
|
+
...record9(state.candidateResult),
|
|
26029
26073
|
usage: aggregateUsage,
|
|
26030
|
-
usageBreakdown: Array.isArray(
|
|
26074
|
+
usageBreakdown: Array.isArray(record9(state.usageRecord).turns) ? record9(state.usageRecord).turns : [],
|
|
26031
26075
|
costUsage: {
|
|
26032
|
-
idempotencyKey: string(
|
|
26076
|
+
idempotencyKey: string(record9(state.usageRecord).idempotencyKey),
|
|
26033
26077
|
...string(receipt.costEventId) ? { costEventId: string(receipt.costEventId) } : {},
|
|
26034
26078
|
...aggregateUsage,
|
|
26035
26079
|
costCents: number(aggregate.costCents)
|
|
@@ -26050,7 +26094,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26050
26094
|
diagnose(`AMaster daemon retained cost_ingest_pending state for ${state.commandId}: ${message}`);
|
|
26051
26095
|
return { pending: true, resultDelivered: false, state };
|
|
26052
26096
|
}
|
|
26053
|
-
const usageRecord =
|
|
26097
|
+
const usageRecord = record9(state.usageRecord);
|
|
26054
26098
|
state = persist(transitionRunCompletionState({
|
|
26055
26099
|
...state,
|
|
26056
26100
|
usageRecord: {
|
|
@@ -26075,13 +26119,13 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26075
26119
|
}
|
|
26076
26120
|
if (state.phase === "profile_cleanup") {
|
|
26077
26121
|
try {
|
|
26078
|
-
const cleanup =
|
|
26079
|
-
const candidateResult =
|
|
26122
|
+
const cleanup = record9(await ports.profileCleaner(state));
|
|
26123
|
+
const candidateResult = record9(state.candidateResult);
|
|
26080
26124
|
state = transitionRunCompletionState(state, "profile_cleaned", {
|
|
26081
26125
|
managedMcpCleanup: cleanup,
|
|
26082
26126
|
candidateResult: {
|
|
26083
26127
|
...candidateResult,
|
|
26084
|
-
...Object.keys(
|
|
26128
|
+
...Object.keys(record9(candidateResult.managedMcp)).length > 0 ? { managedMcp: { ...record9(candidateResult.managedMcp), cleanup } } : {}
|
|
26085
26129
|
}
|
|
26086
26130
|
}, now());
|
|
26087
26131
|
state = persist(state);
|
|
@@ -26193,7 +26237,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26193
26237
|
pending: false,
|
|
26194
26238
|
resultDelivered: true,
|
|
26195
26239
|
state,
|
|
26196
|
-
managedMcpCleanup:
|
|
26240
|
+
managedMcpCleanup: record9(state.managedMcpCleanup)
|
|
26197
26241
|
};
|
|
26198
26242
|
}
|
|
26199
26243
|
async function coordinate(inputState, options = {}) {
|
|
@@ -26207,23 +26251,23 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26207
26251
|
}
|
|
26208
26252
|
if (checked.pending) return { pending: true, resultDelivered: false, state };
|
|
26209
26253
|
while (state.phase === "disposition_required") {
|
|
26210
|
-
const response =
|
|
26254
|
+
const response = record9(state.completionResponse);
|
|
26211
26255
|
const attemptKey = closureAttemptKey(response);
|
|
26212
26256
|
const v2 = response.contractVersion === "amaster.runtime-connector.completion-check.v2";
|
|
26213
|
-
const closureTurns =
|
|
26257
|
+
const closureTurns = record9(state.closureTurns);
|
|
26214
26258
|
const alreadyRecorded = attemptKey ? Boolean(closureTurns[attemptKey]) : state.closureTurnRecorded === true;
|
|
26215
26259
|
const recoveryCount = number(state.closureRecoveryCount);
|
|
26216
26260
|
const mayResumeUncertainClosure = recoveringClosure && !alreadyRecorded && recoveryCount < 1;
|
|
26217
|
-
const priorAttempt = attemptKey ? number(
|
|
26261
|
+
const priorAttempt = attemptKey ? number(record9(state.closureAttempts)[attemptKey]) : number(state.closureAttempt);
|
|
26218
26262
|
if (priorAttempt === 0 || mayResumeUncertainClosure) {
|
|
26219
|
-
const nextAttempts = attemptKey ? { ...
|
|
26263
|
+
const nextAttempts = attemptKey ? { ...record9(state.closureAttempts), [attemptKey]: 1 } : record9(state.closureAttempts);
|
|
26220
26264
|
state = persist(transitionRunCompletionState(state, "closure_started", {
|
|
26221
26265
|
...v2 ? { closureAttempts: nextAttempts } : { closureAttempt: 1 },
|
|
26222
26266
|
...mayResumeUncertainClosure ? { closureRecoveryCount: recoveryCount + 1 } : {}
|
|
26223
26267
|
}, now()));
|
|
26224
26268
|
let closure;
|
|
26225
26269
|
try {
|
|
26226
|
-
closure =
|
|
26270
|
+
closure = record9(await ports.closureExecutor({ state, options }));
|
|
26227
26271
|
} catch (error) {
|
|
26228
26272
|
closure = {
|
|
26229
26273
|
succeeded: false,
|
|
@@ -26237,24 +26281,24 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26237
26281
|
}
|
|
26238
26282
|
};
|
|
26239
26283
|
}
|
|
26240
|
-
const candidateResult =
|
|
26284
|
+
const candidateResult = record9(state.candidateResult);
|
|
26241
26285
|
state = appendRunCompletionUsageTurn({
|
|
26242
26286
|
...state,
|
|
26243
|
-
...attemptKey ? { closureTurns: { ...closureTurns, [attemptKey]:
|
|
26287
|
+
...attemptKey ? { closureTurns: { ...closureTurns, [attemptKey]: record9(closure.audit) } } : { closureTurnRecorded: true },
|
|
26244
26288
|
candidateResult: {
|
|
26245
26289
|
...candidateResult,
|
|
26246
|
-
closureTurn:
|
|
26247
|
-
...attemptKey ? { closureTurns: { ...
|
|
26290
|
+
closureTurn: record9(closure.audit),
|
|
26291
|
+
...attemptKey ? { closureTurns: { ...record9(candidateResult.closureTurns), [attemptKey]: record9(closure.audit) } } : {}
|
|
26248
26292
|
}
|
|
26249
26293
|
}, {
|
|
26250
26294
|
turn: closureTurnKind(attemptKey),
|
|
26251
|
-
usage:
|
|
26295
|
+
usage: record9(closure.usage),
|
|
26252
26296
|
recordedAt: now()
|
|
26253
26297
|
});
|
|
26254
26298
|
state = persist({
|
|
26255
26299
|
...state,
|
|
26256
26300
|
completionRequest: {
|
|
26257
|
-
...
|
|
26301
|
+
...record9(state.completionRequest),
|
|
26258
26302
|
resultSignals: runCompletionCheckRequest(state).resultSignals
|
|
26259
26303
|
}
|
|
26260
26304
|
});
|
|
@@ -26269,9 +26313,9 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26269
26313
|
break;
|
|
26270
26314
|
}
|
|
26271
26315
|
if (state.phase === "disposition_required") {
|
|
26272
|
-
const candidateResult =
|
|
26273
|
-
const closureTurn =
|
|
26274
|
-
const response =
|
|
26316
|
+
const candidateResult = record9(state.candidateResult);
|
|
26317
|
+
const closureTurn = record9(candidateResult.closureTurn);
|
|
26318
|
+
const response = record9(state.completionResponse);
|
|
26275
26319
|
const closureFailure = failedCandidate(
|
|
26276
26320
|
state,
|
|
26277
26321
|
AMASTER_RUNTIME_COMPLETION_CLOSURE_EXHAUSTED_ERROR_CODE,
|
|
@@ -26283,7 +26327,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26283
26327
|
...closureFailure,
|
|
26284
26328
|
candidateResult: {
|
|
26285
26329
|
...candidateResult,
|
|
26286
|
-
...
|
|
26330
|
+
...record9(closureFailure.candidateResult),
|
|
26287
26331
|
errorCode: AMASTER_RUNTIME_COMPLETION_CLOSURE_EXHAUSTED_ERROR_CODE,
|
|
26288
26332
|
...Object.keys(closureTurn).length > 0 ? {} : {
|
|
26289
26333
|
closureTurn: {
|
|
@@ -26299,7 +26343,7 @@ function createRunCompletionCoordinator(inputPorts) {
|
|
|
26299
26343
|
attempt: 1,
|
|
26300
26344
|
reasonCode: string(response.reasonCode) ?? "disposition_still_required",
|
|
26301
26345
|
commandId: state.commandId,
|
|
26302
|
-
runId: string(
|
|
26346
|
+
runId: string(record9(state.command).runId) ?? string(record9(record9(state.command).payload).runId)
|
|
26303
26347
|
}
|
|
26304
26348
|
}
|
|
26305
26349
|
}, now()));
|
|
@@ -26773,10 +26817,10 @@ function compactExecutorJsonlForTranscript(event) {
|
|
|
26773
26817
|
const text2 = JSON.stringify(compactExecutorJsonValue(event, stringMaxChars));
|
|
26774
26818
|
if (text2.length <= 15e3) return text2;
|
|
26775
26819
|
}
|
|
26776
|
-
const
|
|
26777
|
-
const item = tcAsRecord(
|
|
26820
|
+
const record11 = tcAsRecord(event);
|
|
26821
|
+
const item = tcAsRecord(record11.item);
|
|
26778
26822
|
return JSON.stringify({
|
|
26779
|
-
type: tcReadString(
|
|
26823
|
+
type: tcReadString(record11.type) ?? "executor.event",
|
|
26780
26824
|
item: item.type ? {
|
|
26781
26825
|
id: tcReadString(item.id),
|
|
26782
26826
|
type: tcReadString(item.type),
|
|
@@ -26789,31 +26833,31 @@ function compactExecutorJsonlForTranscript(event) {
|
|
|
26789
26833
|
});
|
|
26790
26834
|
}
|
|
26791
26835
|
function compactPiToolLifecycleForTranscript(event, readableSummary) {
|
|
26792
|
-
const
|
|
26793
|
-
const type = tcReadString(
|
|
26836
|
+
const record11 = tcAsRecord(event);
|
|
26837
|
+
const type = tcReadString(record11.type);
|
|
26794
26838
|
if (type !== "tool_execution_start" && type !== "tool_execution_end") return null;
|
|
26795
|
-
const toolCallId = tcReadString(
|
|
26839
|
+
const toolCallId = tcReadString(record11.toolCallId);
|
|
26796
26840
|
if (!toolCallId) return null;
|
|
26797
|
-
const toolName = tcReadString(
|
|
26841
|
+
const toolName = tcReadString(record11.toolName) ?? "tool";
|
|
26798
26842
|
const summary = tcTruncateText(readableSummary || `${type === "tool_execution_start" ? "\u5DE5\u5177\u5F00\u59CB" : "\u5DE5\u5177\u5B8C\u6210"}\uFF1A${toolName}`, 500);
|
|
26799
26843
|
return JSON.stringify(type === "tool_execution_start" ? {
|
|
26800
26844
|
type,
|
|
26801
26845
|
toolCallId,
|
|
26802
26846
|
toolName,
|
|
26803
|
-
args:
|
|
26847
|
+
args: record11.args == null ? { summary } : compactToolTranscriptPayload(record11.args)
|
|
26804
26848
|
} : {
|
|
26805
26849
|
type,
|
|
26806
26850
|
toolCallId,
|
|
26807
26851
|
toolName,
|
|
26808
|
-
result:
|
|
26809
|
-
isError:
|
|
26852
|
+
result: record11.result == null ? summary : compactToolTranscriptPayload(record11.result),
|
|
26853
|
+
isError: record11.isError === true
|
|
26810
26854
|
});
|
|
26811
26855
|
}
|
|
26812
26856
|
function summarizeTokenUsage(usage) {
|
|
26813
|
-
const
|
|
26814
|
-
const inputTokens = tcReadNumber(
|
|
26815
|
-
const cachedInputTokens = tcReadNumber(
|
|
26816
|
-
const outputTokens = tcReadNumber(
|
|
26857
|
+
const record11 = tcAsRecord(usage);
|
|
26858
|
+
const inputTokens = tcReadNumber(record11.input_tokens ?? record11.inputTokens, 0);
|
|
26859
|
+
const cachedInputTokens = tcReadNumber(record11.cached_input_tokens ?? record11.cachedInputTokens, 0);
|
|
26860
|
+
const outputTokens = tcReadNumber(record11.output_tokens ?? record11.outputTokens, 0);
|
|
26817
26861
|
const parts = [];
|
|
26818
26862
|
if (inputTokens > 0) parts.push(`\u8F93\u5165 ${inputTokens}`);
|
|
26819
26863
|
if (cachedInputTokens > 0) parts.push(`\u7F13\u5B58 ${cachedInputTokens}`);
|
|
@@ -27075,8 +27119,8 @@ function summarizeClaudeEvent(event) {
|
|
|
27075
27119
|
return null;
|
|
27076
27120
|
}
|
|
27077
27121
|
function tcPiMessageText(message) {
|
|
27078
|
-
const
|
|
27079
|
-
const content =
|
|
27122
|
+
const record11 = tcAsRecord(message);
|
|
27123
|
+
const content = record11.content;
|
|
27080
27124
|
if (typeof content === "string" && content.trim().length > 0) return content.trim();
|
|
27081
27125
|
if (!Array.isArray(content)) return "";
|
|
27082
27126
|
return content.map((entry) => {
|
|
@@ -27090,14 +27134,14 @@ function tcPiAssistantMessageEventText(assistantMessageEvent) {
|
|
|
27090
27134
|
return tcReadString(event.content) ?? "";
|
|
27091
27135
|
}
|
|
27092
27136
|
function tcPiMessageStopReason(message) {
|
|
27093
|
-
const
|
|
27094
|
-
return tcReadString(
|
|
27137
|
+
const record11 = tcAsRecord(message);
|
|
27138
|
+
return tcReadString(record11.stopReason ?? record11.stop_reason);
|
|
27095
27139
|
}
|
|
27096
27140
|
function tcPiMessageErrorText(message) {
|
|
27097
|
-
const
|
|
27098
|
-
const explicitError = tcReadString(
|
|
27141
|
+
const record11 = tcAsRecord(message);
|
|
27142
|
+
const explicitError = tcReadString(record11.errorMessage ?? record11.error_message)?.trim();
|
|
27099
27143
|
if (explicitError) return explicitError;
|
|
27100
|
-
const stopReason = tcPiMessageStopReason(
|
|
27144
|
+
const stopReason = tcPiMessageStopReason(record11);
|
|
27101
27145
|
if (stopReason === "error" || stopReason === "failed" || stopReason === "exception") {
|
|
27102
27146
|
return `Pi Agent message ended with stopReason=${stopReason}`;
|
|
27103
27147
|
}
|
|
@@ -27509,16 +27553,16 @@ function structuredToolResults(value, depth = 0) {
|
|
|
27509
27553
|
return [];
|
|
27510
27554
|
}
|
|
27511
27555
|
}
|
|
27512
|
-
const
|
|
27513
|
-
const structuredContent = structuredToolResults(
|
|
27556
|
+
const record11 = asRecord(value);
|
|
27557
|
+
const structuredContent = structuredToolResults(record11.structuredContent, depth + 1);
|
|
27514
27558
|
if (structuredContent.length > 0) return structuredContent;
|
|
27515
|
-
if (readString(
|
|
27559
|
+
if (readString(record11.status)) return [record11];
|
|
27516
27560
|
const candidates = [];
|
|
27517
27561
|
for (const nested of [
|
|
27518
|
-
|
|
27519
|
-
|
|
27520
|
-
|
|
27521
|
-
|
|
27562
|
+
record11.content,
|
|
27563
|
+
record11.text,
|
|
27564
|
+
record11.result,
|
|
27565
|
+
record11.output
|
|
27522
27566
|
]) {
|
|
27523
27567
|
candidates.push(...structuredToolResults(nested, depth + 1));
|
|
27524
27568
|
}
|
|
@@ -27604,10 +27648,10 @@ function createCodebuddyMcpToolResultTracker(options = {}) {
|
|
|
27604
27648
|
},
|
|
27605
27649
|
record(event) {
|
|
27606
27650
|
if (trackingFailure) return [];
|
|
27607
|
-
const
|
|
27608
|
-
const eventType = readString(
|
|
27651
|
+
const record11 = asRecord(event);
|
|
27652
|
+
const eventType = readString(record11.type);
|
|
27609
27653
|
if (eventType === "assistant") {
|
|
27610
|
-
const message2 = asRecord(
|
|
27654
|
+
const message2 = asRecord(record11.message);
|
|
27611
27655
|
for (const rawBlock of Array.isArray(message2.content) ? message2.content : []) {
|
|
27612
27656
|
const block = asRecord(rawBlock);
|
|
27613
27657
|
if (["tool_use", "toolUse"].includes(readString(block.type) ?? "")) {
|
|
@@ -27622,18 +27666,18 @@ function createCodebuddyMcpToolResultTracker(options = {}) {
|
|
|
27622
27666
|
}
|
|
27623
27667
|
if (eventType === "function_call") {
|
|
27624
27668
|
rememberToolUse(
|
|
27625
|
-
|
|
27626
|
-
|
|
27627
|
-
|
|
27669
|
+
record11.call_id ?? record11.tool_use_id ?? record11.id,
|
|
27670
|
+
record11.name,
|
|
27671
|
+
record11.input ?? record11.arguments
|
|
27628
27672
|
);
|
|
27629
27673
|
return [];
|
|
27630
27674
|
}
|
|
27631
27675
|
if (eventType === "function_call_result") {
|
|
27632
|
-
const callId = readString(
|
|
27633
|
-
return recordResult(callId,
|
|
27676
|
+
const callId = readString(record11.call_id ?? record11.tool_use_id ?? record11.id);
|
|
27677
|
+
return recordResult(callId, record11.output ?? record11.result);
|
|
27634
27678
|
}
|
|
27635
27679
|
if (eventType !== "user") return [];
|
|
27636
|
-
const message = asRecord(
|
|
27680
|
+
const message = asRecord(record11.message);
|
|
27637
27681
|
const results = [];
|
|
27638
27682
|
for (const rawBlock of Array.isArray(message.content) ? message.content : []) {
|
|
27639
27683
|
const block = asRecord(rawBlock);
|
|
@@ -27953,8 +27997,8 @@ function classifyPiOutputFailure(input, options = {}) {
|
|
|
27953
27997
|
};
|
|
27954
27998
|
}
|
|
27955
27999
|
function piMessageText(message) {
|
|
27956
|
-
const
|
|
27957
|
-
const content =
|
|
28000
|
+
const record11 = asRecord(message);
|
|
28001
|
+
const content = record11.content;
|
|
27958
28002
|
if (typeof content === "string") return content.trim();
|
|
27959
28003
|
if (!Array.isArray(content)) return "";
|
|
27960
28004
|
return content.map((entry) => {
|
|
@@ -27963,10 +28007,10 @@ function piMessageText(message) {
|
|
|
27963
28007
|
}).filter(Boolean).join("\n").trim();
|
|
27964
28008
|
}
|
|
27965
28009
|
function piAgentEndHasFinalAssistantText(event) {
|
|
27966
|
-
const
|
|
27967
|
-
if (
|
|
27968
|
-
const messages = Array.isArray(
|
|
27969
|
-
if (Object.keys(asRecord(
|
|
28010
|
+
const record11 = asRecord(event);
|
|
28011
|
+
if (record11.type !== "agent_end") return false;
|
|
28012
|
+
const messages = Array.isArray(record11.messages) ? [...record11.messages] : [];
|
|
28013
|
+
if (Object.keys(asRecord(record11.message)).length > 0) messages.push(record11.message);
|
|
27970
28014
|
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
27971
28015
|
const message = asRecord(messages[index]);
|
|
27972
28016
|
if (message.role !== "assistant") continue;
|
|
@@ -27975,9 +28019,9 @@ function piAgentEndHasFinalAssistantText(event) {
|
|
|
27975
28019
|
return false;
|
|
27976
28020
|
}
|
|
27977
28021
|
function piTurnEndHasFinalAssistantText(event) {
|
|
27978
|
-
const
|
|
27979
|
-
if (
|
|
27980
|
-
const message = asRecord(
|
|
28022
|
+
const record11 = asRecord(event);
|
|
28023
|
+
if (record11.type !== "turn_end") return false;
|
|
28024
|
+
const message = asRecord(record11.message);
|
|
27981
28025
|
return message.role === "assistant" && Boolean(piMessageText(message));
|
|
27982
28026
|
}
|
|
27983
28027
|
function piMessageHasToolCall(message) {
|
|
@@ -28005,10 +28049,10 @@ function piTextValue(value) {
|
|
|
28005
28049
|
return typeof value === "string" && value.length > 0 ? value : "";
|
|
28006
28050
|
}
|
|
28007
28051
|
function piAssistantEventText(assistantEvent) {
|
|
28008
|
-
const
|
|
28009
|
-
const type = readString(
|
|
28010
|
-
if (type === "text_delta") return piTextValue(
|
|
28011
|
-
if (type === "text_end") return piTextValue(
|
|
28052
|
+
const record11 = asRecord(assistantEvent);
|
|
28053
|
+
const type = readString(record11.type);
|
|
28054
|
+
if (type === "text_delta") return piTextValue(record11.delta);
|
|
28055
|
+
if (type === "text_end") return piTextValue(record11.content);
|
|
28012
28056
|
return "";
|
|
28013
28057
|
}
|
|
28014
28058
|
function piMessageUsage(message) {
|
|
@@ -28029,14 +28073,14 @@ function assignPiUsage(target, source) {
|
|
|
28029
28073
|
if (source.costUsd > 0) target.costUsd = source.costUsd;
|
|
28030
28074
|
}
|
|
28031
28075
|
function piMessageStopReason(message) {
|
|
28032
|
-
const
|
|
28033
|
-
return readString(
|
|
28076
|
+
const record11 = asRecord(message);
|
|
28077
|
+
return readString(record11.stopReason ?? record11.stop_reason);
|
|
28034
28078
|
}
|
|
28035
28079
|
function piMessageErrorText(message) {
|
|
28036
|
-
const
|
|
28037
|
-
const explicitError = readString(
|
|
28080
|
+
const record11 = asRecord(message);
|
|
28081
|
+
const explicitError = readString(record11.errorMessage ?? record11.error_message)?.trim();
|
|
28038
28082
|
if (explicitError) return explicitError;
|
|
28039
|
-
const stopReason = piMessageStopReason(
|
|
28083
|
+
const stopReason = piMessageStopReason(record11);
|
|
28040
28084
|
if (stopReason === "error" || stopReason === "failed" || stopReason === "exception") {
|
|
28041
28085
|
return `Pi Agent message ended with stopReason=${stopReason}`;
|
|
28042
28086
|
}
|
|
@@ -28452,13 +28496,13 @@ function parseClaudeStreamJson(stdout) {
|
|
|
28452
28496
|
}
|
|
28453
28497
|
function openCodeErrorText(value) {
|
|
28454
28498
|
if (typeof value === "string") return value;
|
|
28455
|
-
const
|
|
28456
|
-
const message = readString(
|
|
28499
|
+
const record11 = asRecord(value);
|
|
28500
|
+
const message = readString(record11.message);
|
|
28457
28501
|
if (message) return message;
|
|
28458
|
-
const data = asRecord(
|
|
28502
|
+
const data = asRecord(record11.data);
|
|
28459
28503
|
const nestedMessage = readString(data.message);
|
|
28460
28504
|
if (nestedMessage) return nestedMessage;
|
|
28461
|
-
return readString(
|
|
28505
|
+
return readString(record11.name) ?? readString(record11.code) ?? "";
|
|
28462
28506
|
}
|
|
28463
28507
|
function parseOpenCodeJsonl(stdout) {
|
|
28464
28508
|
let sessionId = null;
|
|
@@ -29351,19 +29395,19 @@ function promptContextMode(input) {
|
|
|
29351
29395
|
}
|
|
29352
29396
|
function filterDuplicatedTaskComments(context, mode) {
|
|
29353
29397
|
if (mode !== "cold") return context;
|
|
29354
|
-
const
|
|
29398
|
+
const record11 = asRecord(context);
|
|
29355
29399
|
const included = new Set(
|
|
29356
|
-
(Array.isArray(
|
|
29400
|
+
(Array.isArray(record11.paperclipTaskMarkdownCommentIds) ? record11.paperclipTaskMarkdownCommentIds : []).map((entry) => readString(entry)).filter(Boolean)
|
|
29357
29401
|
);
|
|
29358
29402
|
if (included.size === 0) return context;
|
|
29359
|
-
const wake = asRecord(
|
|
29403
|
+
const wake = asRecord(record11.paperclipWake);
|
|
29360
29404
|
const comments = Array.isArray(wake.comments) ? wake.comments : [];
|
|
29361
29405
|
const kept = comments.filter((entry) => {
|
|
29362
29406
|
const id = readString(asRecord(entry).id);
|
|
29363
29407
|
return !id || !included.has(id);
|
|
29364
29408
|
});
|
|
29365
29409
|
if (kept.length === comments.length) return context;
|
|
29366
|
-
return { ...
|
|
29410
|
+
return { ...record11, paperclipWake: { ...wake, comments: kept } };
|
|
29367
29411
|
}
|
|
29368
29412
|
function commentRefs(context) {
|
|
29369
29413
|
const comments = Array.isArray(asRecord(context.paperclipWake).comments) ? asRecord(context.paperclipWake).comments : [];
|
|
@@ -29550,8 +29594,8 @@ function governedReadSection(context) {
|
|
|
29550
29594
|
const reads = Array.isArray(context.governedReadResults) ? context.governedReadResults : [];
|
|
29551
29595
|
if (reads.length === 0) return { content: "", provenance: [] };
|
|
29552
29596
|
const normalized = reads.map((entry, index) => {
|
|
29553
|
-
const
|
|
29554
|
-
const receipt = asRecord(
|
|
29597
|
+
const record11 = asRecord(entry);
|
|
29598
|
+
const receipt = asRecord(record11.receipt);
|
|
29555
29599
|
const provider = readString(receipt.provider) ?? readString(receipt.transport);
|
|
29556
29600
|
const operation = readString(receipt.operation);
|
|
29557
29601
|
const observedAt = readString(receipt.retrievedAt) ?? readString(receipt.observedAt);
|
|
@@ -29561,7 +29605,7 @@ function governedReadSection(context) {
|
|
|
29561
29605
|
throw new Error(`governed_read_context_provenance_invalid: entry ${index} requires provider, operation, observedAt, and source`);
|
|
29562
29606
|
}
|
|
29563
29607
|
return {
|
|
29564
|
-
content:
|
|
29608
|
+
content: record11.content,
|
|
29565
29609
|
receipt: {
|
|
29566
29610
|
provider,
|
|
29567
29611
|
operation,
|
|
@@ -29604,11 +29648,11 @@ function governedBusinessDetailRead(input, issueId) {
|
|
|
29604
29648
|
return { mode: "canonical", tool: canonicalTool, arguments: argumentsValue };
|
|
29605
29649
|
}
|
|
29606
29650
|
function governedBusinessDecisionProjection(state, detailRead) {
|
|
29607
|
-
const
|
|
29608
|
-
const snapshot = asRecord(
|
|
29609
|
-
const authoritativeObjectRefs = Array.isArray(
|
|
29610
|
-
const capabilities = Array.isArray(
|
|
29611
|
-
const availability = asRecord(
|
|
29651
|
+
const record11 = asRecord(state);
|
|
29652
|
+
const snapshot = asRecord(record11.governed_state_snapshot);
|
|
29653
|
+
const authoritativeObjectRefs = Array.isArray(record11.authoritative_object_refs) ? record11.authoritative_object_refs : [];
|
|
29654
|
+
const capabilities = Array.isArray(record11.capabilities) ? record11.capabilities : [];
|
|
29655
|
+
const availability = asRecord(record11.availability);
|
|
29612
29656
|
const projection = {
|
|
29613
29657
|
status: readString(availability.status) ?? null,
|
|
29614
29658
|
objects: authoritativeObjectRefs.map((entry) => {
|
|
@@ -29623,7 +29667,7 @@ function governedBusinessDecisionProjection(state, detailRead) {
|
|
|
29623
29667
|
}
|
|
29624
29668
|
return compact;
|
|
29625
29669
|
}),
|
|
29626
|
-
missing: (Array.isArray(
|
|
29670
|
+
missing: (Array.isArray(record11.missing_objects) ? record11.missing_objects : []).map((entry) => {
|
|
29627
29671
|
const missing = asRecord(entry);
|
|
29628
29672
|
return {
|
|
29629
29673
|
kind: readString(missing.object_kind) ?? null,
|
|
@@ -29643,22 +29687,22 @@ function governedBusinessDecisionProjection(state, detailRead) {
|
|
|
29643
29687
|
if (unavailableReads.length > 0) {
|
|
29644
29688
|
projection.unavailable_reads = unavailableReads;
|
|
29645
29689
|
}
|
|
29646
|
-
const continuationId = readString(
|
|
29690
|
+
const continuationId = readString(record11.continuation_id);
|
|
29647
29691
|
if (continuationId) projection.continuation_id = continuationId;
|
|
29648
|
-
if (Number.isInteger(
|
|
29649
|
-
const freeTextReason = readString(
|
|
29692
|
+
if (Number.isInteger(record11.outcome_revision)) projection.outcome_revision = record11.outcome_revision;
|
|
29693
|
+
const freeTextReason = readString(record11.free_text_reason);
|
|
29650
29694
|
if (freeTextReason) projection.free_text_reason = freeTextReason;
|
|
29651
29695
|
return projection;
|
|
29652
29696
|
}
|
|
29653
29697
|
function governedBusinessModelView(state, input) {
|
|
29654
|
-
const
|
|
29655
|
-
const snapshot = asRecord(
|
|
29698
|
+
const record11 = asRecord(state);
|
|
29699
|
+
const snapshot = asRecord(record11.governed_state_snapshot);
|
|
29656
29700
|
const detailRead = governedBusinessDetailRead(
|
|
29657
29701
|
input,
|
|
29658
29702
|
readString(snapshot.issue_id) ?? readString(input.issueId)
|
|
29659
29703
|
);
|
|
29660
29704
|
if (detailRead.mode === "unavailable") {
|
|
29661
|
-
const { task_acceptance_contract: _TaskAcceptanceContract, ...stateWithoutAcceptanceContract } =
|
|
29705
|
+
const { task_acceptance_contract: _TaskAcceptanceContract, ...stateWithoutAcceptanceContract } = record11;
|
|
29662
29706
|
return {
|
|
29663
29707
|
mode: "full_snapshot",
|
|
29664
29708
|
content: stateWithoutAcceptanceContract,
|
|
@@ -29667,7 +29711,7 @@ function governedBusinessModelView(state, input) {
|
|
|
29667
29711
|
}
|
|
29668
29712
|
return {
|
|
29669
29713
|
mode: "decision_projection",
|
|
29670
|
-
content: governedBusinessDecisionProjection(
|
|
29714
|
+
content: governedBusinessDecisionProjection(record11, detailRead),
|
|
29671
29715
|
unavailableReason: null
|
|
29672
29716
|
};
|
|
29673
29717
|
}
|
|
@@ -29733,10 +29777,10 @@ ${bodies}`,
|
|
|
29733
29777
|
}
|
|
29734
29778
|
function canonicalJsonValue(value) {
|
|
29735
29779
|
if (Array.isArray(value)) return value.map(canonicalJsonValue);
|
|
29736
|
-
const
|
|
29737
|
-
if (Object.keys(
|
|
29780
|
+
const record11 = asRecord(value);
|
|
29781
|
+
if (Object.keys(record11).length === 0) return value;
|
|
29738
29782
|
return Object.fromEntries(
|
|
29739
|
-
Object.keys(
|
|
29783
|
+
Object.keys(record11).sort().map((key) => [key, canonicalJsonValue(record11[key])])
|
|
29740
29784
|
);
|
|
29741
29785
|
}
|
|
29742
29786
|
function resolvedDependencySections(context, input, contextScope, snapshotFreshness) {
|
|
@@ -33432,7 +33476,7 @@ var USAGE_FIELDS = Object.freeze({
|
|
|
33432
33476
|
output: ["outputTokens", "output_tokens", "output"],
|
|
33433
33477
|
total: ["totalTokens", "total_tokens"]
|
|
33434
33478
|
});
|
|
33435
|
-
function
|
|
33479
|
+
function record10(value) {
|
|
33436
33480
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
33437
33481
|
}
|
|
33438
33482
|
function stringValue(value) {
|
|
@@ -33484,7 +33528,7 @@ function aliasedUsageInteger(usage, aliases, label) {
|
|
|
33484
33528
|
return { present: true, value: entries[0] };
|
|
33485
33529
|
}
|
|
33486
33530
|
function piUsageTotal(usageValue) {
|
|
33487
|
-
const usage =
|
|
33531
|
+
const usage = record10(usageValue);
|
|
33488
33532
|
const input = aliasedUsageInteger(usage, USAGE_FIELDS.input, "input");
|
|
33489
33533
|
const cachedInput = aliasedUsageInteger(usage, USAGE_FIELDS.cachedInput, "cached input");
|
|
33490
33534
|
const cacheCreationInput = aliasedUsageInteger(
|
|
@@ -33513,7 +33557,7 @@ function piUsageTotal(usageValue) {
|
|
|
33513
33557
|
return Math.max(componentTotal, total.present ? total.value : 0);
|
|
33514
33558
|
}
|
|
33515
33559
|
function usageFromContainer(containerValue) {
|
|
33516
|
-
const container =
|
|
33560
|
+
const container = record10(containerValue);
|
|
33517
33561
|
if (!Object.prototype.hasOwnProperty.call(container, "usage")) return null;
|
|
33518
33562
|
const usage = container.usage;
|
|
33519
33563
|
if (!usage || typeof usage !== "object" || Array.isArray(usage)) {
|
|
@@ -33525,7 +33569,7 @@ function usageFromContainer(containerValue) {
|
|
|
33525
33569
|
return usage;
|
|
33526
33570
|
}
|
|
33527
33571
|
function measureRestoredPiNativeHistory(managedMcpProfile) {
|
|
33528
|
-
const restored =
|
|
33572
|
+
const restored = record10(managedMcpProfile?.restoredNativeSession);
|
|
33529
33573
|
const rolloutPath = stringValue(restored.rolloutPath);
|
|
33530
33574
|
if (!rolloutPath) {
|
|
33531
33575
|
return { status: "fresh", tokens: 0, rolloutBytes: 0, usageTokens: 0 };
|
|
@@ -33589,7 +33633,7 @@ function resolvePiModelContextBudget({
|
|
|
33589
33633
|
managedMcpProfile
|
|
33590
33634
|
}) {
|
|
33591
33635
|
const instructionBytes = [...finalAgentInstructionFiles.values()].reduce((total, entry) => total + Number(entry.byteSize ?? 0), 0);
|
|
33592
|
-
const profileAttestation =
|
|
33636
|
+
const profileAttestation = record10(managedMcpProfile?.attestation);
|
|
33593
33637
|
const observedToolSchemaBytes = Number(profileAttestation.catalogToolSchemaBytes);
|
|
33594
33638
|
const toolSchemaBytes = Number.isSafeInteger(observedToolSchemaBytes) && observedToolSchemaBytes >= 0 ? observedToolSchemaBytes : 0;
|
|
33595
33639
|
const observedSkillMetadataBytes = Number(profileAttestation.enabledSkillMetadataBytes ?? 0);
|
|
@@ -33956,7 +34000,7 @@ function assertRequiredTaskAttachmentMaterialized(input, materialized) {
|
|
|
33956
34000
|
}
|
|
33957
34001
|
|
|
33958
34002
|
// src/amaster-runtime-daemon.mjs
|
|
33959
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
34003
|
+
var CONNECTOR_VERSION = "0.1.1-beta.355";
|
|
33960
34004
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
33961
34005
|
var SUPPORTED_TASK_CONTEXT_VERSIONS = Object.freeze([TASK_CONTEXT_MANIFEST_VERSION, TASK_CONTEXT_V2]);
|
|
33962
34006
|
var daemonRequire = createRequire(import.meta.url);
|
|
@@ -35464,7 +35508,7 @@ function requireCommandContextEnvelope(command) {
|
|
|
35464
35508
|
}
|
|
35465
35509
|
const runDecisionContext = asRecord(envelope.runDecisionContext);
|
|
35466
35510
|
const dynamicContext2 = asRecord(runDecisionContext.content);
|
|
35467
|
-
const runDecisionHash = createHash19("sha256").update(
|
|
35511
|
+
const runDecisionHash = createHash19("sha256").update(canonicalGoalOutcomeValue(dynamicContext2), "utf8").digest("hex");
|
|
35468
35512
|
if (!readString(runDecisionContext.revision) || !Number.isInteger(runDecisionContext.authorizationEpoch) || runDecisionContext.authorizationEpoch < 0 || runDecisionHash !== readString(runDecisionContext.contentSha256)) throw new Error("context_envelope_run_decision_invalid");
|
|
35469
35513
|
if (!Array.isArray(envelope.selectedProcedures)) throw new Error("context_envelope_procedures_invalid");
|
|
35470
35514
|
const toolProfile = asRecord(envelope.toolProfile);
|
|
@@ -35474,17 +35518,12 @@ function requireCommandContextEnvelope(command) {
|
|
|
35474
35518
|
throw new Error("context_envelope_session_binding_invalid");
|
|
35475
35519
|
}
|
|
35476
35520
|
const envelopeHashInput = Object.fromEntries(Object.entries(envelope).filter(([key]) => key !== "envelopeSha256"));
|
|
35477
|
-
const envelopeHash = createHash19("sha256").update(
|
|
35521
|
+
const envelopeHash = createHash19("sha256").update(canonicalGoalOutcomeValue(envelopeHashInput), "utf8").digest("hex");
|
|
35478
35522
|
if (envelopeHash !== readString(envelope.envelopeSha256)) {
|
|
35479
35523
|
throw new Error("context_envelope_hash_mismatch");
|
|
35480
35524
|
}
|
|
35481
35525
|
return { envelope, instructions, files, dynamicContext: dynamicContext2 };
|
|
35482
35526
|
}
|
|
35483
|
-
function canonicalContextJson(value) {
|
|
35484
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
|
|
35485
|
-
if (Array.isArray(value)) return `[${value.map(canonicalContextJson).join(",")}]`;
|
|
35486
|
-
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalContextJson(value[key])}`).join(",")}}`;
|
|
35487
|
-
}
|
|
35488
35527
|
async function materializeEffectiveAgentInstructions(config, command, workspace, instructionContract) {
|
|
35489
35528
|
const files = asRecord(instructionContract.files);
|
|
35490
35529
|
const materialized = [];
|