@amaster.ai/employee-runtime-connector 0.1.1-beta.255 → 0.1.1-beta.257

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.
@@ -5508,6 +5508,32 @@ var amasterRuntimeConnectorLogIngestSchema = external_exports.object({
5508
5508
  message: external_exports.string().max(16e3),
5509
5509
  payload: external_exports.record(external_exports.unknown()).default({})
5510
5510
  });
5511
+ var AMASTER_RUNTIME_CONNECTOR_LOG_BATCH_MAX_ENTRIES = 32;
5512
+ var AMASTER_RUNTIME_CONNECTOR_LOG_BATCH_MAX_BYTES = 128 * 1024;
5513
+ var amasterRuntimeConnectorLogIngestBatchSchema = external_exports.object({
5514
+ entries: external_exports.array(amasterRuntimeConnectorLogIngestSchema).min(1).max(AMASTER_RUNTIME_CONNECTOR_LOG_BATCH_MAX_ENTRIES)
5515
+ }).superRefine((value, ctx) => {
5516
+ const commandIds = new Set(value.entries.flatMap((entry) => entry.commandId ? [entry.commandId] : []));
5517
+ if (commandIds.size > 1) {
5518
+ ctx.addIssue({
5519
+ code: external_exports.ZodIssueCode.custom,
5520
+ path: ["entries"],
5521
+ message: "Runtime connector log batch entries must share one commandId"
5522
+ });
5523
+ }
5524
+ const serializedBytes = new TextEncoder().encode(JSON.stringify(value)).byteLength;
5525
+ if (serializedBytes > AMASTER_RUNTIME_CONNECTOR_LOG_BATCH_MAX_BYTES) {
5526
+ ctx.addIssue({
5527
+ code: external_exports.ZodIssueCode.too_big,
5528
+ type: "array",
5529
+ maximum: AMASTER_RUNTIME_CONNECTOR_LOG_BATCH_MAX_BYTES,
5530
+ inclusive: true,
5531
+ exact: false,
5532
+ path: ["entries"],
5533
+ message: "Runtime connector log batch exceeds 128 KiB"
5534
+ });
5535
+ }
5536
+ });
5511
5537
  var amasterRuntimeConnectorCostIngestSchema = external_exports.object({
5512
5538
  commandId: external_exports.string().uuid(),
5513
5539
  idempotencyKey: external_exports.string().trim().regex(/^runtime-command-cost:[0-9a-f-]{36}$/i).optional(),
@@ -6506,6 +6532,20 @@ var ERROR_PRESENTATIONS = {
6506
6532
  nextAction: "\u5145\u503C\u540E\u7CFB\u7EDF\u4F1A\u5B9A\u65F6\u68C0\u67E5\u5E76\u81EA\u52A8\u6062\u590D\uFF0C\u65E0\u9700\u624B\u52A8\u91CD\u8BD5\u3002",
6507
6533
  tone: "warning"
6508
6534
  },
6535
+ pi_governed_tool_surface_changed: {
6536
+ label: "\u53D7\u7BA1\u5DE5\u5177\u5B9A\u4E49\u5DF2\u53D8\u5316",
6537
+ summary: "\u8FD0\u884C\u671F\u95F4\u7684\u53D7\u7BA1\u5DE5\u5177\u6570\u91CF\u6216\u5B9A\u4E49\u53D1\u751F\u53D8\u5316\uFF0C\u7CFB\u7EDF\u5DF2\u505C\u6B62\u91C7\u4FE1\u672C\u6B21\u8F93\u51FA\u3002",
6538
+ nextAction: "\u68C0\u67E5 Governed MCP \u5DE5\u5177\u76EE\u5F55\u4E0E adapter \u7248\u672C\uFF1B\u7CFB\u7EDF\u4EC5\u4F1A\u5728\u786E\u8BA4\u6CA1\u6709\u672A\u51B3\u526F\u4F5C\u7528\u540E\u8FDB\u884C\u4E00\u6B21\u5B89\u5168\u91CD\u8BD5\u3002",
6539
+ actionTitle: "\u6838\u5BF9\u53D7\u7BA1\u5DE5\u5177\u76EE\u5F55\u540E\u91CD\u8BD5",
6540
+ tone: "danger"
6541
+ },
6542
+ pi_governed_mcp_unavailable: {
6543
+ label: "\u53D7\u7BA1\u5DE5\u5177\u6682\u4E0D\u53EF\u7528",
6544
+ summary: "\u8FD0\u884C\u6240\u9700\u7684\u53D7\u7BA1\u5DE5\u5177\u8FDE\u63A5\u6682\u4E0D\u53EF\u7528\uFF0C\u7CFB\u7EDF\u5DF2\u4FDD\u7559\u672C\u6B21\u8FD0\u884C\u7684\u526F\u4F5C\u7528\u8BC1\u636E\u3002",
6545
+ nextAction: "\u7B49\u5F85\u8FDE\u63A5\u6062\u590D\uFF1B\u53EA\u6709\u5728\u786E\u8BA4\u672C\u6B21\u8FD0\u884C\u6CA1\u6709\u672A\u51B3\u526F\u4F5C\u7528\u65F6\uFF0C\u7CFB\u7EDF\u624D\u4F1A\u8FDB\u884C\u4E00\u6B21\u5B89\u5168\u91CD\u8BD5\u3002",
6546
+ actionTitle: "\u68C0\u67E5\u53D7\u7BA1\u5DE5\u5177\u8FDE\u63A5",
6547
+ tone: "warning"
6548
+ },
6509
6549
  issue_assignee_changed: {
6510
6550
  label: "\u4EFB\u52A1\u5DF2\u6539\u6D3E",
6511
6551
  summary: "\u65E7\u8D1F\u8D23\u4EBA\u7684\u6392\u961F\u8FD0\u884C\u5DF2\u53D6\u6D88\uFF0C\u65B0\u8D1F\u8D23\u4EBA\u4F1A\u81EA\u52A8\u63A5\u624B\u3002",
@@ -18655,6 +18695,12 @@ function requiredInteger(value, name, minimum = 0) {
18655
18695
  if (!Number.isSafeInteger(value) || value < minimum) throw new Error(`pi_final_context_attestor_invalid: ${name}`);
18656
18696
  return value;
18657
18697
  }
18698
+ function optionalSha256(value, name) {
18699
+ if (value === void 0 || value === null) return null;
18700
+ const hash = requiredString(value, name);
18701
+ if (!/^[a-f0-9]{64}$/.test(hash)) throw new Error(`pi_final_context_attestor_invalid: ${name}`);
18702
+ return hash;
18703
+ }
18658
18704
  function managedPiProjectInstructionExtensionSource(input) {
18659
18705
  const projectInstructionPath = resolve3(requiredString(input.projectInstructionPath, "projectInstructionPath"));
18660
18706
  const projectInstructionSha256 = requiredString(input.projectInstructionSha256, "projectInstructionSha256");
@@ -18729,6 +18775,9 @@ function managedPiFinalContextAttestorExtensionSource(input) {
18729
18775
  effectiveToolSchemaBytes: requiredInteger(input.effectiveToolSchemaBytes, "effectiveToolSchemaBytes", 1),
18730
18776
  effectiveToolSetSha256: requiredString(input.effectiveToolSetSha256, "effectiveToolSetSha256"),
18731
18777
  effectiveToolCount: requiredInteger(input.effectiveToolCount, "effectiveToolCount", 1),
18778
+ catalogSetSha256: optionalSha256(input.catalogSetSha256, "catalogSetSha256"),
18779
+ configSha256: optionalSha256(input.configSha256, "configSha256"),
18780
+ cacheSha256: optionalSha256(input.cacheSha256, "cacheSha256"),
18732
18781
  toolSetMode,
18733
18782
  requiredToolEntries,
18734
18783
  skillMetadataBytes: requiredInteger(input.skillMetadataBytes, "skillMetadataBytes"),
@@ -18963,17 +19012,28 @@ export default function amasterFinalModelContextAttestor(pi) {
18963
19012
  requiredToolSet.hash = sha256(stableJson(requiredToolSet.entries));
18964
19013
  if (requiredToolSet.entries.length !== CONTRACT.effectiveToolCount) {
18965
19014
  observe("provider_tool_count_mismatch", {
19015
+ reason: "provider_tool_count_mismatch",
18966
19016
  expectedCount: CONTRACT.effectiveToolCount,
18967
19017
  actualCount: requiredToolSet.entries.length,
18968
- actualEntries: toolSet.entries,
19018
+ providerCallIndex: calls.length + 1,
19019
+ contractToolSetSha256: CONTRACT.effectiveToolSetSha256,
19020
+ ...(CONTRACT.catalogSetSha256 ? { catalogSetSha256: CONTRACT.catalogSetSha256 } : {}),
19021
+ ...(CONTRACT.configSha256 ? { configSha256: CONTRACT.configSha256 } : {}),
19022
+ ...(CONTRACT.cacheSha256 ? { cacheSha256: CONTRACT.cacheSha256 } : {}),
18969
19023
  });
18970
19024
  reject("provider_tool_count_mismatch");
18971
19025
  }
18972
19026
  if (requiredToolSet.hash !== CONTRACT.effectiveToolSetSha256) {
18973
19027
  observe("provider_tool_set_mismatch", {
18974
- expectedToolSetSha256: CONTRACT.effectiveToolSetSha256,
18975
- actualToolSetSha256: toolSet.hash,
18976
- actualEntries: toolSet.entries,
19028
+ reason: "provider_tool_set_mismatch",
19029
+ expectedCount: CONTRACT.effectiveToolCount,
19030
+ actualCount: requiredToolSet.entries.length,
19031
+ providerCallIndex: calls.length + 1,
19032
+ contractToolSetSha256: CONTRACT.effectiveToolSetSha256,
19033
+ actualToolSetSha256: requiredToolSet.hash,
19034
+ ...(CONTRACT.catalogSetSha256 ? { catalogSetSha256: CONTRACT.catalogSetSha256 } : {}),
19035
+ ...(CONTRACT.configSha256 ? { configSha256: CONTRACT.configSha256 } : {}),
19036
+ ...(CONTRACT.cacheSha256 ? { cacheSha256: CONTRACT.cacheSha256 } : {}),
18977
19037
  });
18978
19038
  reject("provider_tool_set_mismatch");
18979
19039
  }
@@ -21744,6 +21804,7 @@ import { spawnSync as spawnSync3 } from "node:child_process";
21744
21804
  // src/amaster-runtime-daemon/pi-mcp-adapter-config.mjs
21745
21805
  var CONFIG_HASH_V2_24_MINIMUM = [2, 24, 0];
21746
21806
  var CONFIG_HASH_V2_26_MINIMUM = [2, 26, 0];
21807
+ var DIRECT_CATALOG_FREEZE_MINIMUM = [2, 32, 1];
21747
21808
  function piMcpAdapterVersionAtLeast(version, minimum) {
21748
21809
  const actual = version.split(/[.-]/, 3).map(Number);
21749
21810
  for (let index = 0; index < minimum.length; index += 1) {
@@ -21752,6 +21813,13 @@ function piMcpAdapterVersionAtLeast(version, minimum) {
21752
21813
  }
21753
21814
  return true;
21754
21815
  }
21816
+ function assertPiMcpAdapterDirectCatalogSupport(version) {
21817
+ if (typeof version !== "string" || !piMcpAdapterVersionAtLeast(version, DIRECT_CATALOG_FREEZE_MINIMUM)) {
21818
+ throw new Error(
21819
+ `pi_managed_mcp_unsupported_adapter_version: direct catalog requires pi-mcp-adapter >=2.32.1; found ${typeof version === "string" ? version : "unknown"}`
21820
+ );
21821
+ }
21822
+ }
21755
21823
  function piMcpAdapterServerConfigIdentity(definition, adapterVersion) {
21756
21824
  const supportsV224Config = piMcpAdapterVersionAtLeast(adapterVersion, CONFIG_HASH_V2_24_MINIMUM);
21757
21825
  return {
@@ -22482,6 +22550,23 @@ function applyManagedPiToolAllowlist(args, profile) {
22482
22550
  ...args.slice(printArgIndex)
22483
22551
  ];
22484
22552
  }
22553
+ function assertManagedPiNonInteractiveInvocation(args, profile) {
22554
+ if (profile?.directCatalogFrozen !== true) return;
22555
+ let effectiveMode = null;
22556
+ for (let index = 0; index < args.length; index += 1) {
22557
+ if (args[index] === "--mode") {
22558
+ effectiveMode = args[index + 1] ?? null;
22559
+ index += 1;
22560
+ } else if (args[index].startsWith("--mode=")) {
22561
+ effectiveMode = args[index].slice("--mode=".length);
22562
+ }
22563
+ }
22564
+ const hasJsonMode = effectiveMode === "json";
22565
+ const hasPrintMode = args.includes("-p") || args.includes("--print");
22566
+ if (!hasJsonMode || !hasPrintMode) {
22567
+ throw new Error("pi_managed_mcp_invocation_invalid: frozen direct catalog requires --mode json and -p/--print");
22568
+ }
22569
+ }
22485
22570
  function applyManagedPiRunExitClosureArgs(args, profile) {
22486
22571
  const narrowedArgs = [...args];
22487
22572
  const toolAllowlist = Array.isArray(profile?.toolAllowlist) ? profile.toolAllowlist.filter((name) => typeof name === "string" && name) : [];
@@ -24239,7 +24324,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
24239
24324
  settings: {
24240
24325
  toolPrefix: "none",
24241
24326
  scriptMode: false,
24242
- ...directCatalog ? { directToolResultDetails: "bounded" } : {}
24327
+ ...directCatalog ? { directToolResultDetails: "bounded", freezeDirectTools: true } : {}
24243
24328
  },
24244
24329
  mcpServers: {
24245
24330
  [SUPPORTED_SERVER_NAME3]: serverConfig
@@ -24278,6 +24363,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
24278
24363
  );
24279
24364
  }
24280
24365
  const adapterVersion = piMcpAdapterVersion(sharedRuntime.home);
24366
+ if (directCatalog) assertPiMcpAdapterDirectCatalogSupport(adapterVersion);
24281
24367
  const {
24282
24368
  cachePath,
24283
24369
  directAttestationInput
@@ -24450,6 +24536,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
24450
24536
  // The attestor verifies the naturally active surface after all extensions
24451
24537
  // load; CLI --tools remains unused so user-level tools stay available.
24452
24538
  toolAllowlist: directAttestationInput?.profileToolAllowlist ?? null,
24539
+ directCatalogFrozen: Boolean(directCatalog),
24453
24540
  protectedValues: [.../* @__PURE__ */ new Set([
24454
24541
  sessionToken,
24455
24542
  ...sharedRuntime.protectedValues,
@@ -24668,7 +24755,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
24668
24755
  // prefix is local presentation state and must not rename this run's
24669
24756
  // governed tools.
24670
24757
  ...directCatalog ? { toolPrefix: "none" } : {},
24671
- ...directCatalog ? { directToolResultDetails: "bounded" } : {}
24758
+ ...directCatalog ? { directToolResultDetails: "bounded", freezeDirectTools: true } : {}
24672
24759
  },
24673
24760
  mcpServers: {
24674
24761
  ...record9(sourceMcp.mcpServers),
@@ -24720,6 +24807,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
24720
24807
  }
24721
24808
  const userMcpServerNames = Object.keys(record9(sourceMcp.mcpServers)).filter((serverName) => serverName !== SUPPORTED_SERVER_NAME3);
24722
24809
  const adapterVersion = desktopAttestationReadiness?.ready ? desktopAttestationReadiness.adapterVersion : null;
24810
+ if (directCatalog) assertPiMcpAdapterDirectCatalogSupport(adapterVersion);
24723
24811
  const {
24724
24812
  cachePath,
24725
24813
  directAttestationInput
@@ -24862,6 +24950,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
24862
24950
  }
24863
24951
  } : {},
24864
24952
  toolAllowlist: directAttestationInput?.profileToolAllowlist ?? null,
24953
+ directCatalogFrozen: Boolean(directCatalog),
24865
24954
  protectedValues: [.../* @__PURE__ */ new Set([sessionToken, ...seededRuntime.protectedValues])],
24866
24955
  attestation: {
24867
24956
  ...attestationFacts,
@@ -27481,6 +27570,17 @@ var PI_PROVIDER_PROTOCOL_RE = /provider[^\n]*finish_reason[^\n]*unexpected_state
27481
27570
  var PI_PROVIDER_RETRY_AFTER_SECONDS_RE = /retry[-\s]?after\s*[:=]?\s*(\d{1,6})\s*(?:seconds?|secs?|s)\b/i;
27482
27571
  var PI_TERMINAL_CLEANUP_PERMISSION_RE = /(?:\bkill\b[^\n]*\bEPERM\b|\bEPERM\b[^\n]*\bkill\b)/i;
27483
27572
  var MAX_PI_PROVIDER_RETRY_AFTER_SECONDS = 7 * 24 * 60 * 60;
27573
+ var PI_GOVERNED_MCP_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
27574
+ "server_unavailable",
27575
+ "not_connected",
27576
+ "init_failed"
27577
+ ]);
27578
+ var PI_GOVERNED_TOOL_SURFACE_REASONS = /* @__PURE__ */ new Set([
27579
+ "provider_tool_count_mismatch",
27580
+ "provider_tool_set_mismatch",
27581
+ "provider_tool_invalid",
27582
+ "provider_tools_missing"
27583
+ ]);
27484
27584
  var PI_DURABLE_RUNTIME_ACTION_WRITE_TOOLS = /* @__PURE__ */ new Set([
27485
27585
  "runtime_action.submit",
27486
27586
  "runtime_action.commit"
@@ -27617,9 +27717,80 @@ function classifyPiProviderError(input, now = /* @__PURE__ */ new Date()) {
27617
27717
  ...retryNotBefore ? { retryNotBefore: retryNotBefore.toISOString() } : {}
27618
27718
  };
27619
27719
  }
27720
+ function safeSha256(value) {
27721
+ const hash = readString(value);
27722
+ return /^[a-f0-9]{64}$/.test(hash ?? "") ? hash : null;
27723
+ }
27724
+ function safeNonNegativeInteger(value) {
27725
+ return Number.isSafeInteger(value) && value >= 0 ? value : null;
27726
+ }
27727
+ function classifyPiGovernedToolSurfaceFailure(options) {
27728
+ if (options.exitCode !== 78) return null;
27729
+ const stderr = String(options.stderr ?? "");
27730
+ const rejectedReason = stderr.split(/\r?\n/).map((line) => line.startsWith("pi_final_model_context_attestation_rejected:") ? line.slice("pi_final_model_context_attestation_rejected:".length).trim() : null).find((reason) => reason && PI_GOVERNED_TOOL_SURFACE_REASONS.has(reason));
27731
+ if (!rejectedReason) return null;
27732
+ const observationPrefix = "pi_final_model_context_attestation_observation:";
27733
+ let observation = {};
27734
+ for (const line of stderr.split(/\r?\n/)) {
27735
+ if (!line.startsWith(observationPrefix) || line.length > 4096) continue;
27736
+ try {
27737
+ const candidate = asRecord(JSON.parse(line.slice(observationPrefix.length)));
27738
+ if (readString(candidate.reason) === rejectedReason && readString(candidate.event) === rejectedReason) {
27739
+ observation = candidate;
27740
+ }
27741
+ } catch {
27742
+ }
27743
+ }
27744
+ const expectedCount = safeNonNegativeInteger(observation.expectedCount);
27745
+ const actualCount = safeNonNegativeInteger(observation.actualCount);
27746
+ const providerCallIndex = safeNonNegativeInteger(observation.providerCallIndex);
27747
+ const contractToolSetSha256 = safeSha256(observation.contractToolSetSha256);
27748
+ const actualToolSetSha256 = safeSha256(observation.actualToolSetSha256);
27749
+ const catalogSetSha256 = safeSha256(observation.catalogSetSha256);
27750
+ const configSha256 = safeSha256(observation.configSha256);
27751
+ const cacheSha256 = safeSha256(observation.cacheSha256);
27752
+ return {
27753
+ errorCode: "pi_governed_tool_surface_changed",
27754
+ errorFamily: "governance_invariant",
27755
+ retryable: false,
27756
+ governedToolSurface: {
27757
+ reason: rejectedReason,
27758
+ ...expectedCount !== null ? { expectedCount } : {},
27759
+ ...actualCount !== null ? { actualCount } : {},
27760
+ ...providerCallIndex !== null ? { providerCallIndex } : {},
27761
+ ...contractToolSetSha256 ? { contractToolSetSha256 } : {},
27762
+ ...actualToolSetSha256 ? { actualToolSetSha256 } : {},
27763
+ ...catalogSetSha256 ? { catalogSetSha256 } : {},
27764
+ ...configSha256 ? { configSha256 } : {},
27765
+ ...cacheSha256 ? { cacheSha256 } : {}
27766
+ }
27767
+ };
27768
+ }
27620
27769
  function classifyPiOutputFailure(input, options = {}) {
27770
+ const commandFailed = Number.isInteger(options.exitCode) && options.exitCode !== 0 || Boolean(readString(options.invalidOutputError)) || Boolean(readString(options.finalContextAttestationError));
27771
+ const governedSurfaceFailure = classifyPiGovernedToolSurfaceFailure(options);
27772
+ if (governedSurfaceFailure) return governedSurfaceFailure;
27773
+ if (readString(options.finalContextAttestationError)) {
27774
+ return {
27775
+ errorCode: "pi_final_context_attestation_failed",
27776
+ errorFamily: "governance_invariant",
27777
+ retryable: false
27778
+ };
27779
+ }
27621
27780
  const providerFailure = classifyPiProviderError(input, options.now);
27622
27781
  if (providerFailure) return providerFailure;
27782
+ const governedMcpUnavailable = asRecord(asRecord(input).governedMcpUnavailable);
27783
+ const governedUnavailableReason = readString(governedMcpUnavailable.reason);
27784
+ if (commandFailed && governedUnavailableReason && PI_GOVERNED_MCP_UNAVAILABLE_REASONS.has(governedUnavailableReason)) {
27785
+ return {
27786
+ errorCode: "pi_governed_mcp_unavailable",
27787
+ errorFamily: "transient_infra",
27788
+ governedMcpUnavailable: {
27789
+ reason: governedUnavailableReason,
27790
+ ...readString(governedMcpUnavailable.toolName) ? { toolName: readString(governedMcpUnavailable.toolName) } : {}
27791
+ }
27792
+ };
27793
+ }
27623
27794
  if (!readString(options.invalidOutputError)) return null;
27624
27795
  return {
27625
27796
  errorCode: "pi_executor_invalid_output",
@@ -27821,6 +27992,34 @@ function piMcpToolResults(event) {
27821
27992
  }
27822
27993
  return results;
27823
27994
  }
27995
+ function piGovernedMcpUnavailableEvidence(event) {
27996
+ const messageToolResults = [
27997
+ event?.message,
27998
+ ...Array.isArray(event?.messages) ? event.messages : [],
27999
+ ...Array.isArray(event?.toolResults) ? event.toolResults : []
28000
+ ];
28001
+ const unavailableEvidence = (rawResult, fallbackToolName = null) => {
28002
+ const result2 = asRecord(rawResult);
28003
+ const details = asRecord(result2.details);
28004
+ const reason = readString(details.error);
28005
+ if (readString(details.server) !== "amaster" || !reason || !PI_GOVERNED_MCP_UNAVAILABLE_REASONS.has(reason)) return null;
28006
+ const toolName = readString(result2.toolName) ?? readString(details.toolName) ?? fallbackToolName;
28007
+ return {
28008
+ reason,
28009
+ ...toolName && /^[A-Za-z][A-Za-z0-9_-]{0,127}$/.test(toolName) ? { toolName } : {}
28010
+ };
28011
+ };
28012
+ for (const rawResult of messageToolResults) {
28013
+ const result2 = asRecord(rawResult);
28014
+ if (readString(result2.role) !== "toolResult") continue;
28015
+ const evidence = unavailableEvidence(result2);
28016
+ if (evidence) return evidence;
28017
+ }
28018
+ if (readString(event?.type) === "tool_execution_end") {
28019
+ return unavailableEvidence(event?.result, readString(event?.toolName));
28020
+ }
28021
+ return null;
28022
+ }
27824
28023
  function piRuntimeWebEvidence(event) {
27825
28024
  if (readString(event?.type) === "amaster_web_evidence" && readString(event?.version) === "runtime_web_evidence_v1") {
27826
28025
  try {
@@ -27885,6 +28084,7 @@ function parsePiJsonl(stdout) {
27885
28084
  const mcpToolResults = [];
27886
28085
  const cleanupDiagnostics = [];
27887
28086
  const diagnostics = [];
28087
+ let governedMcpUnavailable = null;
27888
28088
  const errorEvents = [];
27889
28089
  let retry = null;
27890
28090
  let turnStartIndex = -1;
@@ -27895,6 +28095,7 @@ function parsePiJsonl(stdout) {
27895
28095
  if (!event) continue;
27896
28096
  eventIndex += 1;
27897
28097
  mcpToolResults.push(...piMcpToolResults(event));
28098
+ governedMcpUnavailable = piGovernedMcpUnavailableEvidence(event) ?? governedMcpUnavailable;
27898
28099
  if (event.type === "turn_start") turnStartIndex = eventIndex;
27899
28100
  if (event.type === "auto_retry_start") {
27900
28101
  const message = readString(event.errorMessage);
@@ -28032,6 +28233,7 @@ function parsePiJsonl(stdout) {
28032
28233
  ...nonCleanupErrorCount > 0 ? { nonCleanupErrorCount } : {},
28033
28234
  ...cleanupDiagnostics.length > 0 ? { cleanupDiagnostics } : {},
28034
28235
  ...diagnostics.length > 0 ? { diagnostics } : {},
28236
+ ...governedMcpUnavailable ? { governedMcpUnavailable } : {},
28035
28237
  ...uniqueMcpToolResults.length > 0 ? { mcpToolResults: uniqueMcpToolResults } : {}
28036
28238
  };
28037
28239
  }
@@ -33516,7 +33718,7 @@ function assertRequiredTaskAttachmentMaterialized(input, materialized) {
33516
33718
  }
33517
33719
 
33518
33720
  // src/amaster-runtime-daemon.mjs
33519
- var CONNECTOR_VERSION = "0.1.1-beta.255";
33721
+ var CONNECTOR_VERSION = "0.1.1-beta.257";
33520
33722
  var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
33521
33723
  var daemonRequire = createRequire2(import.meta.url);
33522
33724
  var MAX_CHECKPOINT_BYTES = 20 * 1024 * 1024;
@@ -35183,6 +35385,9 @@ function attachPiFinalContextAttestor(profile, input) {
35183
35385
  effectiveToolSchemaBytes: governedToolContract.effectiveToolSchemaBytes,
35184
35386
  effectiveToolSetSha256: governedToolContract.effectiveToolSetSha256,
35185
35387
  effectiveToolCount: governedToolContract.effectiveToolCount,
35388
+ catalogSetSha256: readString(profileAttestation.catalogSetHash),
35389
+ configSha256: readString(asRecord(profile.runExitClosureBaseline).configSha256) ?? readString(profileAttestation.configSha256),
35390
+ cacheSha256: readString(asRecord(profile.runExitClosureBaseline).cacheSha256),
35186
35391
  toolSetMode: "required_subset",
35187
35392
  requiredToolEntries: governedToolContract.entries.map(({ name, schemaHash }) => ({ name, schemaHash })),
35188
35393
  skillMetadataBytes: Number(profile.attestation?.enabledSkillMetadataBytes ?? 0),
@@ -35645,6 +35850,25 @@ function redactProtectedText(value, protectedValues = []) {
35645
35850
  }
35646
35851
  return text3;
35647
35852
  }
35853
+ var RUNTIME_LOG_BATCH_MAX_ENTRIES = 32;
35854
+ var RUNTIME_LOG_BATCH_MAX_BYTES = 128 * 1024;
35855
+ var RUNTIME_LOG_BATCH_FLUSH_MS = 250;
35856
+ function runtimeLogBatchEntries(command, entries) {
35857
+ return entries.map((entry) => ({
35858
+ commandId: command.commandId,
35859
+ runId: commandRunId(command) ?? void 0,
35860
+ stream: entry.stream,
35861
+ level: entry.level,
35862
+ message: truncateText(entry.message),
35863
+ payload: entry.payload ?? {}
35864
+ }));
35865
+ }
35866
+ function runtimeLogBatchEntryBytes(command, entry) {
35867
+ return Buffer.byteLength(JSON.stringify(runtimeLogBatchEntries(command, [entry])[0]));
35868
+ }
35869
+ function runtimeLogBatchBytes(command, entries) {
35870
+ return Buffer.byteLength(JSON.stringify({ entries: runtimeLogBatchEntries(command, entries) }));
35871
+ }
35648
35872
  function createLiveOutputLogger(config, command, executorKind, protectedValues = [], onMcpToolResults = null, options = {}) {
35649
35873
  const buffers = { stdout: "", stderr: "" };
35650
35874
  const displayCounts = { stdout: 0, stderr: 0, system: 0 };
@@ -35667,6 +35891,16 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
35667
35891
  let liveLogDeliveryFailed = false;
35668
35892
  let failedLiveLogDeliveryCount = 0;
35669
35893
  let skippedLiveLogDeliveryCount = 0;
35894
+ let logEntriesAttempted = 0;
35895
+ let logEntriesAccepted = 0;
35896
+ let logEntriesInvalidDropped = 0;
35897
+ let logEntriesAmbiguousDropped = 0;
35898
+ let logBatchRequestsAttempted = 0;
35899
+ let logBatchRequestsAccepted = 0;
35900
+ let firstLogDeliveryFailureCategory = null;
35901
+ let pendingBatch = [];
35902
+ let pendingBatchBytes = runtimeLogBatchBytes(command, []);
35903
+ let pendingBatchTimer = null;
35670
35904
  const piToolArgumentTracker = executorKind === "pi" ? createPiToolArgumentAmplificationTracker(options.piToolArgumentGuard) : null;
35671
35905
  const fullTranscriptEnabled = executorKind === "pi" && readString(asRecord(asRecord(command).payload).transcriptDetail) === AMASTER_RUNTIME_TRANSCRIPT_DETAIL_FULL;
35672
35906
  const maxEntriesPerStream = parsePositiveInteger(
@@ -35723,34 +35957,66 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
35723
35957
  }
35724
35958
  nonProgressEventCount += 1;
35725
35959
  };
35726
- const deliverLiveLog = async (entry, options2 = {}) => {
35960
+ const deliverLiveLogBatch = async (entries, options2 = {}) => {
35961
+ if (entries.length === 0) return;
35727
35962
  const terminalSummary = options2.terminalSummary === true;
35728
- if (liveLogDeliveryFailed && !terminalSummary) {
35729
- skippedLiveLogDeliveryCount += 1;
35963
+ const bisectRecovery = options2.bisectRecovery === true;
35964
+ if (liveLogDeliveryFailed && !terminalSummary && !bisectRecovery) {
35965
+ skippedLiveLogDeliveryCount += entries.length;
35730
35966
  return;
35731
35967
  }
35732
- let deliveryFailed = false;
35733
- await ingestLog(
35734
- config,
35735
- command,
35736
- entry.stream,
35737
- entry.level,
35738
- truncateText(entry.message),
35739
- entry.payload ?? {},
35740
- {
35741
- timeoutMs: 1e3,
35742
- onError: (message) => {
35743
- deliveryFailed = true;
35744
- process.stderr.write(terminalSummary ? `${message}; terminal live-log summary was not delivered
35968
+ let deliveryError = null;
35969
+ if (!bisectRecovery) logEntriesAttempted += entries.length;
35970
+ logBatchRequestsAttempted += 1;
35971
+ const response = await ingestLogBatch(config, command, entries, {
35972
+ timeoutMs: 1e3,
35973
+ onError: (_message, error) => {
35974
+ deliveryError = error;
35975
+ }
35976
+ });
35977
+ if (response) {
35978
+ logEntriesAccepted += readNumber(response.acceptedCount, entries.length);
35979
+ logBatchRequestsAccepted += 1;
35980
+ return;
35981
+ }
35982
+ if (Number(deliveryError?.httpStatus) === 400) {
35983
+ firstLogDeliveryFailureCategory ??= "invalid";
35984
+ if (entries.length === 1) {
35985
+ logEntriesInvalidDropped += 1;
35986
+ failedLiveLogDeliveryCount += 1;
35987
+ return;
35988
+ }
35989
+ const midpoint = Math.floor(entries.length / 2);
35990
+ const recoveryOptions = { ...options2, bisectRecovery: true };
35991
+ await deliverLiveLogBatch(entries.slice(0, midpoint), recoveryOptions);
35992
+ await deliverLiveLogBatch(entries.slice(midpoint), recoveryOptions);
35993
+ return;
35994
+ }
35995
+ firstLogDeliveryFailureCategory ??= "ambiguous";
35996
+ logEntriesAmbiguousDropped += entries.length;
35997
+ if (!terminalSummary) liveLogDeliveryFailed = true;
35998
+ const message = `AMaster daemon could not determine whether ${entries.length} runtime log entr${entries.length === 1 ? "y was" : "ies were"} accepted`;
35999
+ process.stderr.write(terminalSummary ? `${message}; terminal live-log summary was not delivered
35745
36000
  ` : `${message}; suppressing remaining live logs for this executor turn
35746
36001
  `);
35747
- }
35748
- }
35749
- );
35750
- if (deliveryFailed) {
35751
- liveLogDeliveryFailed = true;
35752
- failedLiveLogDeliveryCount += 1;
36002
+ failedLiveLogDeliveryCount += 1;
36003
+ };
36004
+ const flushPendingBatch = () => {
36005
+ if (pendingBatchTimer) {
36006
+ clearTimeout(pendingBatchTimer);
36007
+ pendingBatchTimer = null;
35753
36008
  }
36009
+ if (pendingBatch.length === 0) return;
36010
+ const entries = pendingBatch;
36011
+ pendingBatch = [];
36012
+ pendingBatchBytes = runtimeLogBatchBytes(command, []);
36013
+ queue = queue.then(() => deliverLiveLogBatch(entries)).catch(() => {
36014
+ });
36015
+ };
36016
+ const schedulePendingBatch = () => {
36017
+ if (pendingBatchTimer) return;
36018
+ pendingBatchTimer = setTimeout(() => flushPendingBatch(), RUNTIME_LOG_BATCH_FLUSH_MS);
36019
+ pendingBatchTimer.unref?.();
35754
36020
  };
35755
36021
  const enqueue = (entry) => {
35756
36022
  const stream = entry.stream === "stderr" || entry.stream === "system" ? entry.stream : "stdout";
@@ -35759,8 +36025,19 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
35759
36025
  return;
35760
36026
  }
35761
36027
  displayCounts[stream] = (displayCounts[stream] ?? 0) + 1;
35762
- queue = queue.then(() => deliverLiveLog(entry)).catch(() => {
35763
- });
36028
+ const entryBytes = runtimeLogBatchEntryBytes(command, entry);
36029
+ let candidateBatchBytes = pendingBatchBytes + (pendingBatch.length > 0 ? 1 : 0) + entryBytes;
36030
+ if (pendingBatch.length > 0 && (pendingBatch.length >= RUNTIME_LOG_BATCH_MAX_ENTRIES || candidateBatchBytes > RUNTIME_LOG_BATCH_MAX_BYTES)) {
36031
+ flushPendingBatch();
36032
+ candidateBatchBytes = pendingBatchBytes + entryBytes;
36033
+ }
36034
+ pendingBatch.push(entry);
36035
+ pendingBatchBytes = candidateBatchBytes;
36036
+ if (pendingBatch.length >= RUNTIME_LOG_BATCH_MAX_ENTRIES || pendingBatchBytes >= RUNTIME_LOG_BATCH_MAX_BYTES) {
36037
+ flushPendingBatch();
36038
+ } else {
36039
+ schedulePendingBatch();
36040
+ }
35764
36041
  };
35765
36042
  const shouldSuppressDuplicatePiAgentMessage = (entry) => {
35766
36043
  if (executorKind !== "pi") return false;
@@ -35890,22 +36167,25 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
35890
36167
  }
35891
36168
  await observationQueue;
35892
36169
  if (observationError) throw observationError;
36170
+ flushPendingBatch();
35893
36171
  await queue;
35894
36172
  const suppressedSummaries = Object.entries(suppressedCounts).filter(([, count2]) => count2 > 0).map(([stream, count2]) => ({ stream, count: count2 }));
35895
- if (suppressedSummaries.length > 0) {
36173
+ if (suppressedSummaries.length > 0 || liveLogDeliveryFailed) {
35896
36174
  const suppressedCount = suppressedSummaries.reduce((total, summary) => total + summary.count, 0);
35897
- await deliverLiveLog({
36175
+ await deliverLiveLogBatch([{
35898
36176
  stream: "system",
35899
- level: "info",
35900
- message: `Runtime output summarized: ${suppressedCount} event(s) suppressed after ${maxEntriesPerStream} live log entries per stream`,
36177
+ level: liveLogDeliveryFailed ? "warn" : "info",
36178
+ message: liveLogDeliveryFailed ? `Runtime output delivery was incomplete: ${logEntriesAmbiguousDropped} entr${logEntriesAmbiguousDropped === 1 ? "y" : "ies"} had an ambiguous server outcome` : `Runtime output summarized: ${suppressedCount} event(s) suppressed after ${maxEntriesPerStream} live log entries per stream`,
35901
36179
  payload: {
35902
36180
  presentationKind: "output_summary",
35903
36181
  executorKind,
35904
36182
  suppressedCount,
35905
36183
  suppressedByStream: suppressedSummaries,
35906
- maxEntriesPerStream
36184
+ maxEntriesPerStream,
36185
+ deliveryIncomplete: liveLogDeliveryFailed,
36186
+ ambiguousDropped: logEntriesAmbiguousDropped
35907
36187
  }
35908
- }, { terminalSummary: true });
36188
+ }], { terminalSummary: true });
35909
36189
  }
35910
36190
  },
35911
36191
  hasStream(stream) {
@@ -35930,10 +36210,17 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
35930
36210
  const normalizedFloodLimitBytes = readNumber(floodLimitBytes, 0);
35931
36211
  return {
35932
36212
  liveLogDelivery: {
35933
- status: liveLogDeliveryFailed ? "partial" : "complete",
36213
+ status: liveLogDeliveryFailed || logEntriesInvalidDropped > 0 ? "partial" : "complete",
35934
36214
  failed: failedLiveLogDeliveryCount,
35935
36215
  skipped: skippedLiveLogDeliveryCount
35936
36216
  },
36217
+ logEntriesAttempted,
36218
+ logEntriesAccepted,
36219
+ logEntriesInvalidDropped,
36220
+ logEntriesAmbiguousDropped,
36221
+ logBatchRequestsAttempted,
36222
+ logBatchRequestsAccepted,
36223
+ ...firstLogDeliveryFailureCategory ? { firstLogDeliveryFailureCategory } : {},
35937
36224
  rawBytesByStream,
35938
36225
  rawOutputBytes,
35939
36226
  retainedBytesByStream,
@@ -36573,6 +36860,15 @@ async function ingestLog(config, command, stream, level, message, payload = {},
36573
36860
  payload
36574
36861
  }, options);
36575
36862
  }
36863
+ async function ingestLogBatch(config, command, entries, options = {}) {
36864
+ const connectorId = requireConnectorId(config);
36865
+ return await bestEffortPostJson(
36866
+ config,
36867
+ `/api/amaster/runtime-connectors/${connectorId}/ingest/logs/batch`,
36868
+ { entries: runtimeLogBatchEntries(command, entries) },
36869
+ options
36870
+ );
36871
+ }
36576
36872
  function parsedUsageCostCents(usage) {
36577
36873
  const costUsd = readNumber(asRecord(usage).costUsd, 0);
36578
36874
  if (!Number.isFinite(costUsd) || costUsd <= 0) return 0;
@@ -38024,6 +38320,9 @@ async function executeRunCommand(config, command) {
38024
38320
  if (executor.kind === "pi" && Array.isArray(managedMcpProfile.extensionArgs) && managedMcpProfile.extensionArgs.length > 0) {
38025
38321
  invocation.args = [...invocation.args, ...managedMcpProfile.extensionArgs];
38026
38322
  }
38323
+ if (executor.kind === "pi") {
38324
+ assertManagedPiNonInteractiveInvocation(invocation.args, managedMcpProfile);
38325
+ }
38027
38326
  await ingestLog(config, command, "system", "info", desktopDelegatedRunnerEnabled(config) && executor.kind === "pi" ? "Prepared desktop delegated Pi runtime action bridge" : `Attested isolated ${executor.kind} managed MCP profile`, {
38028
38327
  presentationKind: "managed_mcp_attestation",
38029
38328
  ...managedMcpProfile.attestation
@@ -38585,7 +38884,12 @@ async function executeRunCommand(config, command) {
38585
38884
  completionOutputType: execution.completionOutputType,
38586
38885
  completionOutputHasFinalAssistantText: terminalTextRepair?.succeeded === true ? true : execution.completionOutputHasFinalAssistantText
38587
38886
  }) : null;
38588
- const piOutputFailure = executor.kind === "pi" && !cancelled && !hasOutputFlood && !hasArgumentAmplification && !hasMemoryLimit && execution.timedOut !== true && !execution.spawnError ? classifyPiOutputFailure(parsedForValidation, { invalidOutputError: piInvalidOutputError }) : null;
38887
+ const piOutputFailure = executor.kind === "pi" && !cancelled && !hasOutputFlood && !hasArgumentAmplification && !hasMemoryLimit && execution.timedOut !== true && !execution.spawnError ? classifyPiOutputFailure(parsedForValidation, {
38888
+ exitCode: execution.exitCode,
38889
+ stderr: execution.stderr,
38890
+ finalContextAttestationError: finalModelContextAttestationError,
38891
+ invalidOutputError: piInvalidOutputError
38892
+ }) : null;
38589
38893
  const piProviderFailure = piOutputFailure?.errorCode !== "pi_executor_invalid_output" ? piOutputFailure : null;
38590
38894
  const parsedErrorMessage = outputFloodError ?? argumentAmplificationError ?? memoryLimitError ?? finalModelContextAttestationError ?? piTurnLimitFailure?.message ?? piInvalidOutputError ?? nativeSessionRolloutError ?? nativeSessionRolloutCleanupError ?? parsedForValidation.errorMessage;
38591
38895
  const codexTransientFailure = executor.kind === "codex" && (execution.exitCode ?? 0) !== 0 ? classifyCodexTransientUpstreamError({
@@ -7,7 +7,7 @@ import { homedir, hostname } from "node:os";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { BUILD_SUPPORTED_CAPABILITIES } from "./amaster-runtime-daemon/capability-registry.mjs";
9
9
 
10
- const CONNECTOR_VERSION = "0.1.1-beta.255";
10
+ const CONNECTOR_VERSION = "0.1.1-beta.257";
11
11
 
12
12
  const CONFIG_KEY_MAP = new Map([
13
13
  ["server_url", "AMASTER_EMPLOYEE_SERVER_URL"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amaster.ai/employee-runtime-connector",
3
- "version": "0.1.1-beta.255",
3
+ "version": "0.1.1-beta.257",
4
4
  "description": "MirrorX runtime connector CLI and daemon",
5
5
  "license": "MIT",
6
6
  "type": "module",