@amaster.ai/employee-runtime-connector 0.1.1-beta.156 → 0.1.1-beta.157

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.
@@ -4121,7 +4121,13 @@ var source_acquisition_compatibility_default = {
4121
4121
  "source_acquisition_prompt_authority_invalid",
4122
4122
  "source_acquisition_direct_tools_unavailable",
4123
4123
  "source_acquisition_profile_canonicalization_failed",
4124
- "source_acquisition_governed_profile_required"
4124
+ "source_acquisition_governed_profile_required",
4125
+ "context_output_reserve_exceeds_model_limit",
4126
+ "model_context_attestation_unavailable",
4127
+ "model_context_fixed_inputs_exceed_budget",
4128
+ "native_session_history_attestation_invalid",
4129
+ "native_session_history_attestation_unavailable",
4130
+ "native_session_history_exceeds_measurement_limit"
4125
4131
  ],
4126
4132
  reasonCodes: [
4127
4133
  "source_profile_setup_failed",
@@ -11204,6 +11210,22 @@ var issueDeliveryAcceptanceGovernanceFindingSchema = external_exports.object({
11204
11210
  code: external_exports.literal("business_outcome_acceptance_policy_mismatch"),
11205
11211
  message: external_exports.string().min(1)
11206
11212
  }).strict();
11213
+ var terminalProducerBlockingRefSchema = external_exports.object({
11214
+ kind: external_exports.enum(["action_call", "artifact_intent", "tool_invocation"]),
11215
+ id: uuidSchema3,
11216
+ status: external_exports.string().min(1),
11217
+ code: external_exports.string().min(1).nullable()
11218
+ }).strict();
11219
+ var terminalProducerCleanlinessSchema = external_exports.object({
11220
+ clean: external_exports.boolean(),
11221
+ reasonCode: external_exports.enum([
11222
+ "terminal_producer_action_rejected",
11223
+ "terminal_producer_effect_pending",
11224
+ "terminal_producer_effect_unknown"
11225
+ ]).nullable(),
11226
+ diagnosticCode: external_exports.literal("terminal_producer_correlation_unknown").nullable(),
11227
+ blockingRefs: external_exports.array(terminalProducerBlockingRefSchema)
11228
+ }).strict();
11207
11229
  var issueDeliveryColdStartFactCoverageContextSchema = external_exports.object({
11208
11230
  worksetId: uuidSchema3,
11209
11231
  worksetItemId: uuidSchema3,
@@ -11229,13 +11251,22 @@ var issueDeliveryAcceptanceReadModelSchema = external_exports.object({
11229
11251
  outcome: external_exports.object({
11230
11252
  current: runtimeBusinessOutcomeReceiptSchema.nullable(),
11231
11253
  latestAcceptance: runtimeBusinessOutcomeAcceptanceRecordSchema.nullable(),
11232
- acceptanceIsCurrent: external_exports.boolean()
11254
+ acceptanceIsCurrent: external_exports.boolean(),
11255
+ terminalProducerCleanliness: terminalProducerCleanlinessSchema.nullable().optional()
11233
11256
  }).strict(),
11234
11257
  pendingInteractions: external_exports.array(issueDeliveryAcceptancePendingInteractionSchema),
11235
11258
  forceDone: issueForceDoneEvidenceSchema.nullable(),
11236
11259
  nextOwner: issueDeliveryAcceptanceNextOwnerSchema,
11237
11260
  coldStartFactCoverage: issueDeliveryColdStartFactCoverageContextSchema.nullable().default(null)
11238
11261
  }).strict();
11262
+ var issueDeliveryAcceptanceReconciliationResponseSchema = external_exports.object({
11263
+ result: external_exports.object({
11264
+ outcome: external_exports.enum(["created", "replayed", "not_eligible", "missing_issue"]),
11265
+ interactionId: uuidSchema3.nullable(),
11266
+ reason: external_exports.string().nullable()
11267
+ }).strict(),
11268
+ deliveryAcceptance: issueDeliveryAcceptanceReadModelSchema
11269
+ }).strict();
11239
11270
 
11240
11271
  // ../shared/src/operating-accounting.ts
11241
11272
  var OPERATING_IDENTITY_MAPPING_VERSION = "operating-identity-v1";
@@ -29011,12 +29042,113 @@ function summarizeAmasterRuntimeVersionDrift(input = {}) {
29011
29042
 
29012
29043
  // src/amaster-runtime-daemon/pi-context-budget.mjs
29013
29044
  import { readFileSync as readFileSync16 } from "node:fs";
29045
+ var CONTEXT_ERROR_CODES = /* @__PURE__ */ new Set([
29046
+ "context_output_reserve_exceeds_model_limit",
29047
+ "model_context_attestation_unavailable",
29048
+ "model_context_fixed_inputs_exceed_budget",
29049
+ "native_session_history_attestation_invalid",
29050
+ "native_session_history_attestation_unavailable",
29051
+ "native_session_history_exceeds_measurement_limit"
29052
+ ]);
29053
+ var USAGE_FIELDS = Object.freeze({
29054
+ input: ["inputTokens", "input_tokens", "input"],
29055
+ cachedInput: ["cachedInputTokens", "cached_input_tokens", "cacheRead"],
29056
+ cacheCreationInput: ["cacheCreationInputTokens", "cache_creation_input_tokens", "cacheWrite"],
29057
+ output: ["outputTokens", "output_tokens", "output"],
29058
+ total: ["totalTokens", "total_tokens"]
29059
+ });
29014
29060
  function record6(value) {
29015
29061
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
29016
29062
  }
29017
29063
  function stringValue(value) {
29018
29064
  return typeof value === "string" && value.trim() ? value.trim() : null;
29019
29065
  }
29066
+ function stableContextError(code, details = "") {
29067
+ if (!CONTEXT_ERROR_CODES.has(code)) {
29068
+ throw new Error("context_error_code_invalid");
29069
+ }
29070
+ const error = new Error(details ? `${code}: ${details}` : code);
29071
+ Object.defineProperty(error, "code", {
29072
+ configurable: false,
29073
+ enumerable: true,
29074
+ value: code,
29075
+ writable: false
29076
+ });
29077
+ return error;
29078
+ }
29079
+ function contextErrorCodeFromMessage(message) {
29080
+ if (typeof message !== "string") return null;
29081
+ const code = message.match(
29082
+ /^((?:model_context|native_session_history|context_output_reserve)_[a-z0-9_]{1,109})(?::|$)/
29083
+ )?.[1];
29084
+ return code && /^[a-z][a-z0-9_]{0,127}$/.test(code) ? code : null;
29085
+ }
29086
+ function assertPiModelContextAttestationInputs(managedMcpProfile, piAgentDir) {
29087
+ if (!managedMcpProfile || !stringValue(piAgentDir)) {
29088
+ throw stableContextError(
29089
+ "model_context_attestation_unavailable",
29090
+ "managed Pi profile or Pi config home is missing"
29091
+ );
29092
+ }
29093
+ }
29094
+ function aliasedUsageInteger(usage, aliases, label) {
29095
+ const entries = aliases.filter((key) => Object.prototype.hasOwnProperty.call(usage, key)).map((key) => usage[key]);
29096
+ if (entries.length === 0) return { present: false, value: 0 };
29097
+ if (entries.some((value) => typeof value !== "number" || !Number.isSafeInteger(value) || value < 0)) {
29098
+ throw stableContextError(
29099
+ "native_session_history_attestation_invalid",
29100
+ `usage ${label} must be a non-negative safe integer`
29101
+ );
29102
+ }
29103
+ if (entries.some((value) => value !== entries[0])) {
29104
+ throw stableContextError(
29105
+ "native_session_history_attestation_invalid",
29106
+ `usage ${label} aliases disagree`
29107
+ );
29108
+ }
29109
+ return { present: true, value: entries[0] };
29110
+ }
29111
+ function piUsageTotal(usageValue) {
29112
+ const usage = record6(usageValue);
29113
+ const input = aliasedUsageInteger(usage, USAGE_FIELDS.input, "input");
29114
+ const cachedInput = aliasedUsageInteger(usage, USAGE_FIELDS.cachedInput, "cached input");
29115
+ const cacheCreationInput = aliasedUsageInteger(
29116
+ usage,
29117
+ USAGE_FIELDS.cacheCreationInput,
29118
+ "cache creation input"
29119
+ );
29120
+ const output = aliasedUsageInteger(usage, USAGE_FIELDS.output, "output");
29121
+ const total = aliasedUsageInteger(usage, USAGE_FIELDS.total, "total");
29122
+ if (![input, cachedInput, cacheCreationInput, output, total].some((field) => field.present)) {
29123
+ return null;
29124
+ }
29125
+ if (!input.present && !total.present) {
29126
+ throw stableContextError(
29127
+ "native_session_history_attestation_invalid",
29128
+ "usage requires input or explicit total tokens"
29129
+ );
29130
+ }
29131
+ const componentTotal = input.value + cachedInput.value + cacheCreationInput.value + output.value;
29132
+ if (!Number.isSafeInteger(componentTotal)) {
29133
+ throw stableContextError(
29134
+ "native_session_history_attestation_invalid",
29135
+ "usage component total exceeds the safe integer range"
29136
+ );
29137
+ }
29138
+ return Math.max(componentTotal, total.present ? total.value : 0);
29139
+ }
29140
+ function usageFromContainer(containerValue) {
29141
+ const container = record6(containerValue);
29142
+ if (!Object.prototype.hasOwnProperty.call(container, "usage")) return null;
29143
+ const usage = container.usage;
29144
+ if (!usage || typeof usage !== "object" || Array.isArray(usage)) {
29145
+ throw stableContextError(
29146
+ "native_session_history_attestation_invalid",
29147
+ "usage must be an object"
29148
+ );
29149
+ }
29150
+ return usage;
29151
+ }
29020
29152
  function measureRestoredPiNativeHistory(managedMcpProfile) {
29021
29153
  const restored = record6(managedMcpProfile?.restoredNativeSession);
29022
29154
  const rolloutPath = stringValue(restored.rolloutPath);
@@ -29026,7 +29158,10 @@ function measureRestoredPiNativeHistory(managedMcpProfile) {
29026
29158
  const rollout = readFileSync16(rolloutPath);
29027
29159
  const maximumRolloutBytes = 64 * 1024 * 1024;
29028
29160
  if (rollout.byteLength > maximumRolloutBytes) {
29029
- throw new Error(`native_session_history_exceeds_measurement_limit: bytes=${rollout.byteLength}`);
29161
+ throw stableContextError(
29162
+ "native_session_history_exceeds_measurement_limit",
29163
+ `bytes=${rollout.byteLength}`
29164
+ );
29030
29165
  }
29031
29166
  let latestUsageTokens = null;
29032
29167
  for (const line of rollout.toString("utf8").split("\n")) {
@@ -29035,27 +29170,27 @@ function measureRestoredPiNativeHistory(managedMcpProfile) {
29035
29170
  try {
29036
29171
  event = JSON.parse(line);
29037
29172
  } catch {
29038
- throw new Error("native_session_history_attestation_invalid: rollout contains invalid JSONL");
29173
+ throw stableContextError(
29174
+ "native_session_history_attestation_invalid",
29175
+ "rollout contains invalid JSONL"
29176
+ );
29039
29177
  }
29040
- const candidates = [
29041
- record6(event.usage),
29042
- record6(record6(event.message).usage),
29043
- record6(record6(event.turn).usage)
29044
- ];
29045
- for (const usage of candidates) {
29046
- const inputTokens = Number(usage.inputTokens ?? usage.input_tokens ?? usage.input);
29047
- const outputTokens = Number(usage.outputTokens ?? usage.output_tokens ?? usage.output ?? 0);
29048
- if (Number.isSafeInteger(inputTokens) && inputTokens >= 0 && Number.isSafeInteger(outputTokens) && outputTokens >= 0) {
29049
- latestUsageTokens = inputTokens + outputTokens;
29050
- }
29178
+ for (const container of [event, event.message, event.turn]) {
29179
+ const usage = usageFromContainer(container);
29180
+ if (!usage) continue;
29181
+ const usageTotal = piUsageTotal(usage);
29182
+ if (usageTotal !== null) latestUsageTokens = usageTotal;
29051
29183
  }
29052
29184
  }
29053
29185
  if (!Number.isSafeInteger(latestUsageTokens)) {
29054
- throw new Error("native_session_history_attestation_unavailable: rollout has no usage-bearing turn");
29186
+ throw stableContextError(
29187
+ "native_session_history_attestation_unavailable",
29188
+ "rollout has no usage-bearing turn"
29189
+ );
29055
29190
  }
29056
29191
  return {
29057
29192
  status: "restored_measured",
29058
- tokens: Math.max(rollout.byteLength, latestUsageTokens),
29193
+ tokens: latestUsageTokens,
29059
29194
  rolloutBytes: rollout.byteLength,
29060
29195
  usageTokens: latestUsageTokens
29061
29196
  };
@@ -29067,19 +29202,26 @@ function resolvePiModelContextBudget({
29067
29202
  managedMcpProfile
29068
29203
  }) {
29069
29204
  if (outputReserveTokens > modelContext.maxOutputTokens) {
29070
- throw new Error(
29071
- `context_output_reserve_exceeds_model_limit: reserve=${outputReserveTokens} modelMax=${modelContext.maxOutputTokens}`
29205
+ throw stableContextError(
29206
+ "context_output_reserve_exceeds_model_limit",
29207
+ `reserve=${outputReserveTokens} modelMax=${modelContext.maxOutputTokens}`
29072
29208
  );
29073
29209
  }
29074
29210
  const instructionBytes = [...finalAgentInstructionFiles.values()].reduce((total, entry) => total + Number(entry.byteSize ?? 0), 0);
29075
29211
  const profileAttestation = record6(managedMcpProfile?.attestation);
29076
29212
  const toolSchemaBytes = Number(profileAttestation.finalEffectiveToolSchemaBytes);
29077
29213
  if (!Number.isSafeInteger(toolSchemaBytes) || toolSchemaBytes < 1) {
29078
- throw new Error("model_context_attestation_unavailable: final tool schema size is missing");
29214
+ throw stableContextError(
29215
+ "model_context_attestation_unavailable",
29216
+ "final tool schema size is missing"
29217
+ );
29079
29218
  }
29080
29219
  const skillMetadataBytes = Number(profileAttestation.enabledSkillMetadataBytes ?? 0);
29081
29220
  if (!Number.isSafeInteger(skillMetadataBytes) || skillMetadataBytes < 0) {
29082
- throw new Error("model_context_attestation_unavailable: skill metadata size is invalid");
29221
+ throw stableContextError(
29222
+ "model_context_attestation_unavailable",
29223
+ "skill metadata size is invalid"
29224
+ );
29083
29225
  }
29084
29226
  const nativeHistory = measureRestoredPiNativeHistory(managedMcpProfile);
29085
29227
  const executorBaseReserveTokens = Math.max(32768, Math.floor(modelContext.contextWindowTokens * 0.05));
@@ -29088,8 +29230,16 @@ function resolvePiModelContextBudget({
29088
29230
  const dynamicInputTokens = modelContext.contextWindowTokens - outputReserveTokens - executorBaseReserveTokens - nativeHistoryReserveTokens - knownFixedInputTokens;
29089
29231
  const dynamicPromptMaxChars = Math.floor(dynamicInputTokens / 4);
29090
29232
  if (dynamicPromptMaxChars < 8192) {
29091
- throw new Error(
29092
- `model_context_fixed_inputs_exceed_budget: context=${modelContext.contextWindowTokens} fixed=${knownFixedInputTokens}`
29233
+ throw stableContextError(
29234
+ "model_context_fixed_inputs_exceed_budget",
29235
+ [
29236
+ `context=${modelContext.contextWindowTokens}`,
29237
+ `output=${outputReserveTokens}`,
29238
+ `base=${executorBaseReserveTokens}`,
29239
+ `history=${nativeHistoryReserveTokens}`,
29240
+ `fixed=${knownFixedInputTokens}`,
29241
+ `dynamic=${dynamicInputTokens}`
29242
+ ].join(" ")
29093
29243
  );
29094
29244
  }
29095
29245
  return {
@@ -30278,7 +30428,7 @@ function createSourceCompletionStopPolicy({
30278
30428
  }
30279
30429
 
30280
30430
  // src/amaster-runtime-daemon.mjs
30281
- var CONNECTOR_VERSION = "0.1.1-beta.156";
30431
+ var CONNECTOR_VERSION = "0.1.1-beta.157";
30282
30432
  var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
30283
30433
  var SOURCE_ACQUISITION_CAPABILITY2 = source_acquisition_compatibility_default.profileVersion;
30284
30434
  var daemonRequire = createRequire(import.meta.url);
@@ -31859,10 +32009,18 @@ function attachPiOutputReserve(profile, outputReserveTokens) {
31859
32009
  return profile;
31860
32010
  }
31861
32011
  function attachPiFinalContextAttestor(profile, input) {
31862
- if (!profile?.profileRoot) throw new Error("model_context_attestation_unavailable: managed Pi profile is missing");
32012
+ if (!profile?.profileRoot) {
32013
+ throw stableContextError(
32014
+ "model_context_attestation_unavailable",
32015
+ "managed Pi profile is missing"
32016
+ );
32017
+ }
31863
32018
  const projectInstruction = input.finalAgentInstructionFiles.get("AGENTS.md");
31864
32019
  if (!projectInstruction || !/^[a-f0-9]{64}$/.test(readString(projectInstruction.sha256) ?? "")) {
31865
- throw new Error("model_context_attestation_unavailable: final AGENTS.md receipt is missing");
32020
+ throw stableContextError(
32021
+ "model_context_attestation_unavailable",
32022
+ "final AGENTS.md receipt is missing"
32023
+ );
31866
32024
  }
31867
32025
  const extensionPath = join18(profile.profileRoot, "extensions", MANAGED_PI_FINAL_CONTEXT_ATTESTOR_FILENAME);
31868
32026
  const projectInstructionExtensionPath = join18(
@@ -33425,7 +33583,7 @@ function commandFailureErrorCode(error) {
33425
33583
  const explicit = readString(asRecord(error).code);
33426
33584
  if (explicit && /^[a-z][a-z0-9_]{0,127}$/.test(explicit)) return explicit;
33427
33585
  const message = error instanceof Error ? error.message : String(error);
33428
- const prefix = message.match(/^(codex_managed_mcp_[a-z0-9_]{1,109})(?::|$)/)?.[1];
33586
+ const prefix = message.match(/^(codex_managed_mcp_[a-z0-9_]{1,109})(?::|$)/)?.[1] ?? contextErrorCodeFromMessage(message);
33429
33587
  return prefix && /^[a-z][a-z0-9_]{0,127}$/.test(prefix) ? prefix : null;
33430
33588
  }
33431
33589
  function terminalCommandStatusFromCompletionCheckError(error) {
@@ -35536,9 +35694,7 @@ async function executeRunCommand(config, command) {
35536
35694
  }
35537
35695
  };
35538
35696
  }
35539
- if (!managedMcpProfile || !piAgentDirForContextBudget) {
35540
- throw new Error("model_context_attestation_unavailable: managed Pi profile or Pi config home is missing");
35541
- }
35697
+ assertPiModelContextAttestationInputs(managedMcpProfile, piAgentDirForContextBudget);
35542
35698
  const modelContext = resolvePiRunModelContext(
35543
35699
  piAgentDirForContextBudget,
35544
35700
  readString(process.env.AMASTER_PI_PROVIDER),
@@ -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.156";
10
+ const CONNECTOR_VERSION = "0.1.1-beta.157";
11
11
 
12
12
  const CONFIG_KEY_MAP = new Map([
13
13
  ["server_url", "AMASTER_EMPLOYEE_SERVER_URL"],
@@ -67,7 +67,13 @@
67
67
  "source_acquisition_prompt_authority_invalid",
68
68
  "source_acquisition_direct_tools_unavailable",
69
69
  "source_acquisition_profile_canonicalization_failed",
70
- "source_acquisition_governed_profile_required"
70
+ "source_acquisition_governed_profile_required",
71
+ "context_output_reserve_exceeds_model_limit",
72
+ "model_context_attestation_unavailable",
73
+ "model_context_fixed_inputs_exceed_budget",
74
+ "native_session_history_attestation_invalid",
75
+ "native_session_history_attestation_unavailable",
76
+ "native_session_history_exceeds_measurement_limit"
71
77
  ],
72
78
  "reasonCodes": [
73
79
  "source_profile_setup_failed",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amaster.ai/employee-runtime-connector",
3
- "version": "0.1.1-beta.156",
3
+ "version": "0.1.1-beta.157",
4
4
  "description": "MirrorX runtime connector CLI and daemon",
5
5
  "license": "MIT",
6
6
  "type": "module",