@amaster.ai/employee-runtime-connector 0.1.1-beta.122 → 0.1.1-beta.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,7 @@ Runtime code belongs in the container image. Persist only connector state, the r
37
37
 
38
38
  The Server requires `final_model_context_attestation_v1` for governed Pi runs because that path disables ambient context discovery and injects a run-owned compiled instruction bundle. This is a Pi delivery contract, not a connector-wide requirement: an explicitly selected self-hosted Codex runtime continues through its own Runtime Actions V2 and native-session contracts and cannot borrow the Pi attestation claim. Adding the same final-context guarantee to another executor requires executor-specific proof for scoped project-instruction semantics, the normalized final active tool schemas, the selected model's context/output limits, automatically visible skill metadata, resumed-session history, and the enforced output reserve.
39
39
 
40
- For admitted Pi runs, the daemon compiles source-repository `AGENTS.md` and `AGENTS.override.md` topology into one root `AGENTS.md` with explicit relative scopes, same-scope override semantics, and a higher-authority MirrorX platform block. Governed Pi disables ambient extension, skill, and context-file discovery and injects that exact compiled file through a run-owned final-system-prompt extension. A last-ordered `before_provider_request` hook then validates every provider call, including later calls after tool results: exactly one system message contains the compiled instructions, visible role-skill metadata and the normalized active tool set match their prior attestations, the provider model/output ceiling match the run contract, and the complete serialized payload plus output reserve fits the context window. Each call appends metadata-only hashes and sizes to a bounded chained receipt; a missing, broken, or oversized chain fails the run.
40
+ For admitted Pi runs, the daemon compiles source-repository `AGENTS.md` and `AGENTS.override.md` topology into one root `AGENTS.md` with explicit relative scopes, same-scope override semantics, and a higher-authority MirrorX platform block. Governed Pi disables ambient extension, skill, and context-file discovery and injects that exact compiled file through a run-owned final-system-prompt extension. When the operator-owned Pi settings declare `@amaster.ai/pi-telemetry`, the daemon resolves only that package-owned entry, requires the runtime npm manifest to pin its exact installed version, verifies its name, path, and tree digest, passes it as an explicit extension, and preserves the authoritative runtime run id for trace correlation; every other ambient package extension remains disabled. A last-ordered `before_provider_request` hook then validates every provider call, including later calls after tool results: exactly one system message contains the compiled instructions, visible role-skill metadata and the normalized active tool set match their prior attestations, the provider model/output ceiling match the run contract, and the complete serialized payload plus output reserve fits the context window. Each call appends metadata-only hashes and sizes to a bounded chained receipt; a missing, broken, or oversized chain fails the run.
41
41
 
42
42
  Pi 0.80.10's internal compaction summarizer calls the provider outside `before_provider_request`. The Enabled profile therefore records and cancels every `session_before_compact` attempt and fails immediately if `session_compact` is nevertheless observed. No model-generated compaction summary is accepted until that provider path has equivalent final-context attestation. The Server also enumerates Pi and Codex as the only supported governed executors at configuration and heartbeat dispatch boundaries; missing or unknown executor kinds fail closed.
43
43
 
@@ -5116,10 +5116,13 @@ var amasterRuntimeConnectorCompletionCheckResponseSchema = external_exports.unio
5116
5116
  amasterRuntimeConnectorCompletionCheckV1ResponseSchema,
5117
5117
  amasterRuntimeConnectorCompletionCheckV2ResponseSchema
5118
5118
  ]);
5119
+ var amasterRuntimeConnectorCommandResultSchema = external_exports.object({
5120
+ sessionId: external_exports.string().max(2048).optional()
5121
+ }).catchall(external_exports.unknown());
5119
5122
  var amasterRuntimeConnectorCompleteCommandSchema = external_exports.object({
5120
5123
  leaseId: external_exports.string().trim().min(1).optional(),
5121
5124
  status: external_exports.enum(["succeeded", "failed", "cancelled"]),
5122
- result: external_exports.record(external_exports.unknown()).optional(),
5125
+ result: amasterRuntimeConnectorCommandResultSchema.optional(),
5123
5126
  error: external_exports.string().trim().max(4e3).optional()
5124
5127
  });
5125
5128
  var amasterRuntimeConnectorLogIngestSchema = external_exports.object({
@@ -16791,12 +16794,16 @@ function findSessionRollout(sessionsRoot, sessionId) {
16791
16794
  }
16792
16795
  function restoreManagedCodexSessionRollout(input, codexHome, runDir, executorHome, authority) {
16793
16796
  const session = record3(input.nativeSession);
16794
- if (session.mode !== "governed_action_approval" || session.required !== true) return null;
16797
+ const governedApprovalContinuation = session.mode === "governed_action_approval" && session.required === true;
16798
+ const governedTaskSessionContinuation = session.mode === "task_session" && session.required === false;
16799
+ if (!governedApprovalContinuation && !governedTaskSessionContinuation) return null;
16795
16800
  const sessionId = nonEmpty(session.sessionId, "nativeSession.sessionId");
16796
16801
  const sourceRunId = nonEmpty(session.sourceRunId, "nativeSession.sourceRunId");
16797
16802
  const sourceCommandId = nonEmpty(session.sourceCommandId, "nativeSession.sourceCommandId");
16798
- nonEmpty(session.actionRequestId, "nativeSession.actionRequestId");
16799
- nonEmpty(session.invocationId, "nativeSession.invocationId");
16803
+ if (governedApprovalContinuation) {
16804
+ nonEmpty(session.actionRequestId, "nativeSession.actionRequestId");
16805
+ nonEmpty(session.invocationId, "nativeSession.invocationId");
16806
+ }
16800
16807
  const sourceWorkspacePath = nonEmpty(session.cwd, "nativeSession.cwd");
16801
16808
  const issueRoot = dirname(runDir);
16802
16809
  const managedSourceRunDirName = `${sourceRunId}-${createHash("sha256").update(sourceRunId).digest("hex").slice(0, 8)}`;
@@ -16812,7 +16819,7 @@ function restoreManagedCodexSessionRollout(input, codexHome, runDir, executorHom
16812
16819
  }
16813
16820
  const marker = JSON.parse(readFileSync(markerPath, "utf8"));
16814
16821
  if (marker?.version !== 1 || marker?.companyId !== authority.companyId || marker?.agentId !== authority.agentId || marker?.issueId !== authority.issueId || marker?.sourceRunId !== sourceRunId || marker?.sourceCommandId !== sourceCommandId || marker?.sessionId !== sessionId || marker?.sourceWorkspacePath !== sourceWorkspacePath) {
16815
- throw new Error("codex_managed_mcp_session_rollout_authority_mismatch: source rollout does not match the approved continuation");
16822
+ throw new Error("codex_managed_mcp_session_rollout_authority_mismatch: source rollout does not match the governed continuation");
16816
16823
  }
16817
16824
  const sourceRollout = resolve2(cacheRoot, nonEmpty(marker.rolloutRelativePath, "rolloutRelativePath"));
16818
16825
  if (!within(sourceRollout, cacheRoot) || lstatSync2(sourceRollout).isSymbolicLink() || !lstatSync2(sourceRollout).isFile()) {
@@ -16827,6 +16834,28 @@ function restoreManagedCodexSessionRollout(input, codexHome, runDir, executorHom
16827
16834
  writePrivateFile(targetRollout, readFileSync(sourceRollout));
16828
16835
  return { sessionId, sourceRunId, sourceCommandId, rolloutPath: targetRollout, cacheRoot };
16829
16836
  }
16837
+ function resolveManagedCodexSessionRollout(input, codexHome, runDir, executorHome, authority) {
16838
+ try {
16839
+ return {
16840
+ restoredNativeSession: restoreManagedCodexSessionRollout(
16841
+ input,
16842
+ codexHome,
16843
+ runDir,
16844
+ executorHome,
16845
+ authority
16846
+ ),
16847
+ nativeSessionRestoreSkippedReason: null
16848
+ };
16849
+ } catch (error) {
16850
+ if (record3(input.nativeSession).mode === "task_session" && error instanceof Error && error.message.startsWith("codex_managed_mcp_session_rollout_missing:")) {
16851
+ return {
16852
+ restoredNativeSession: null,
16853
+ nativeSessionRestoreSkippedReason: "native_session_rollout_missing"
16854
+ };
16855
+ }
16856
+ throw error;
16857
+ }
16858
+ }
16830
16859
  function isSensitiveAuthKey(key) {
16831
16860
  const normalized = String(key).trim().toLowerCase().replaceAll("-", "_");
16832
16861
  return /^(?:(?:access|refresh|id)_)?token$/.test(normalized) || normalized.includes("api_key") || normalized.includes("secret") || normalized.includes("password") || normalized.includes("credential") || normalized.includes("authorization") || normalized.includes("cookie");
@@ -17144,7 +17173,10 @@ function prepareManagedCodexMcpProfile(input) {
17144
17173
  runId,
17145
17174
  commandId: input.commandId
17146
17175
  });
17147
- const restoredNativeSession = restoreManagedCodexSessionRollout(input, codexHome, runDir, executorHome, authority);
17176
+ const {
17177
+ restoredNativeSession,
17178
+ nativeSessionRestoreSkippedReason
17179
+ } = resolveManagedCodexSessionRollout(input, codexHome, runDir, executorHome, authority);
17148
17180
  const auth = seedCodexAuth(input, codexHome);
17149
17181
  const configPath = join2(codexHome, "config.toml");
17150
17182
  const allHeaders = { Authorization: `Bearer ${sessionToken}`, ...headers };
@@ -17199,6 +17231,7 @@ function prepareManagedCodexMcpProfile(input) {
17199
17231
  owner,
17200
17232
  authority,
17201
17233
  restoredNativeSession,
17234
+ nativeSessionRestoreSkippedReason,
17202
17235
  protectedValues: [.../* @__PURE__ */ new Set([sessionToken, ...auth.protectedValues])],
17203
17236
  attestation: {
17204
17237
  ...attestationFacts,
@@ -18837,6 +18870,8 @@ var MANAGED_PI_DIRECT_TYPED_MCP_TOOL_MODE = "direct_typed";
18837
18870
  var MANAGED_PI_MCP_ARGS_NORMALIZATION = "json_string_control_characters_v1";
18838
18871
  var MANAGED_PI_MCP_ARGS_NORMALIZER_FILENAME = "amaster-mcp-args-normalizer.js";
18839
18872
  var MANAGED_PI_CONFIG_MODE_SHARED = "shared_agent_dir_workspace_mcp_file";
18873
+ var MANAGED_PI_TELEMETRY_PACKAGE = "@amaster.ai/pi-telemetry";
18874
+ var MANAGED_PI_TELEMETRY_PACKAGE_SOURCE = "npm:@amaster.ai/pi-telemetry";
18840
18875
  function applyManagedPiToolAllowlist(args, profile) {
18841
18876
  const toolAllowlist = Array.isArray(profile?.toolAllowlist) ? profile.toolAllowlist.filter((name) => typeof name === "string" && name) : [];
18842
18877
  if (toolAllowlist.length === 0) return [...args];
@@ -18998,6 +19033,10 @@ function createManagedPiMcpProfileApi(options = {}) {
18998
19033
  "PAPERCLIP_AGENT_ID",
18999
19034
  "PAPERCLIP_COMPANY_ID",
19000
19035
  "AMASTER_EMPLOYEE_COMPANY_ID",
19036
+ // Runtime telemetry is a governed audit channel. The daemon assigns this
19037
+ // correlation id from the authoritative run and the managed profile must
19038
+ // preserve it when rebuilding the child environment.
19039
+ "PI_TELEMETRY_TASK_RUN_ID",
19001
19040
  // The agent dir is operator-owned configuration: governed runs inherit the
19002
19041
  // daemon's single value verbatim. commandEnv cannot inject it
19003
19042
  // (FORBIDDEN_COMMAND_ENV).
@@ -19102,12 +19141,16 @@ function createManagedPiMcpProfileApi(options = {}) {
19102
19141
  }
19103
19142
  function restoreManagedPiSessionRollout(input, sessionsRoot, runDir, executorHome, authority) {
19104
19143
  const session = record8(input.nativeSession);
19105
- if (session.mode !== "governed_action_approval" || session.required !== true) return null;
19144
+ const governedApprovalContinuation = session.mode === "governed_action_approval" && session.required === true;
19145
+ const governedTaskSessionContinuation = session.mode === "task_session" && session.required === false;
19146
+ if (!governedApprovalContinuation && !governedTaskSessionContinuation) return null;
19106
19147
  const sessionId = nonEmpty2(session.sessionId, "nativeSession.sessionId");
19107
19148
  const sourceRunId = nonEmpty2(session.sourceRunId, "nativeSession.sourceRunId");
19108
19149
  const sourceCommandId = nonEmpty2(session.sourceCommandId, "nativeSession.sourceCommandId");
19109
- nonEmpty2(session.actionRequestId, "nativeSession.actionRequestId");
19110
- nonEmpty2(session.invocationId, "nativeSession.invocationId");
19150
+ if (governedApprovalContinuation) {
19151
+ nonEmpty2(session.actionRequestId, "nativeSession.actionRequestId");
19152
+ nonEmpty2(session.invocationId, "nativeSession.invocationId");
19153
+ }
19111
19154
  const sourceWorkspacePath = nonEmpty2(session.cwd, "nativeSession.cwd");
19112
19155
  const issueRoot = dirname4(runDir);
19113
19156
  const managedSourceRunDirName = `${sourceRunId}-${createHash5("sha256").update(sourceRunId).digest("hex").slice(0, 8)}`;
@@ -19122,7 +19165,7 @@ function createManagedPiMcpProfileApi(options = {}) {
19122
19165
  }
19123
19166
  const marker = JSON.parse(readFileSync5(markerPath, "utf8"));
19124
19167
  if (marker?.version !== 1 || marker?.companyId !== authority.companyId || marker?.agentId !== authority.agentId || marker?.issueId !== authority.issueId || marker?.sourceRunId !== sourceRunId || marker?.sourceCommandId !== sourceCommandId || marker?.sessionId !== sessionId || marker?.sourceWorkspacePath !== sourceWorkspacePath) {
19125
- throw new Error("pi_managed_mcp_session_rollout_authority_mismatch: source rollout does not match the approved continuation");
19168
+ throw new Error("pi_managed_mcp_session_rollout_authority_mismatch: source rollout does not match the governed continuation");
19126
19169
  }
19127
19170
  const sourceRollout = resolve3(cacheRoot, nonEmpty2(marker.rolloutRelativePath, "rolloutRelativePath"));
19128
19171
  if (!within2(sourceRollout, cacheRoot) || lstatSync3(sourceRollout).isSymbolicLink() || !lstatSync3(sourceRollout).isFile()) {
@@ -19136,6 +19179,28 @@ function createManagedPiMcpProfileApi(options = {}) {
19136
19179
  writePrivateFile2(targetRollout, readFileSync5(sourceRollout));
19137
19180
  return { sessionId, sourceRunId, sourceCommandId, rolloutPath: targetRollout, cacheRoot };
19138
19181
  }
19182
+ function resolveManagedPiSessionRollout(input, sessionsRoot, runDir, executorHome, authority) {
19183
+ try {
19184
+ return {
19185
+ restoredNativeSession: restoreManagedPiSessionRollout(
19186
+ input,
19187
+ sessionsRoot,
19188
+ runDir,
19189
+ executorHome,
19190
+ authority
19191
+ ),
19192
+ nativeSessionRestoreSkippedReason: null
19193
+ };
19194
+ } catch (error) {
19195
+ if (record8(input.nativeSession).mode === "task_session" && error instanceof Error && error.message.startsWith("pi_managed_mcp_session_rollout_missing:")) {
19196
+ return {
19197
+ restoredNativeSession: null,
19198
+ nativeSessionRestoreSkippedReason: "native_session_rollout_missing"
19199
+ };
19200
+ }
19201
+ throw error;
19202
+ }
19203
+ }
19139
19204
  function parseVersion(stdout, label, minimum) {
19140
19205
  const pattern = label === "Pi" ? /^\s*(?:pi(?: coding agent)?\s+)?(\d+)\.(\d+)\.(\d+)(?:\s|$)/im : /^\s*(\d+)\.(\d+)\.(\d+)(?:\s|$)/;
19141
19206
  const match = String(stdout).match(pattern);
@@ -19382,6 +19447,98 @@ function createManagedPiMcpProfileApi(options = {}) {
19382
19447
  }
19383
19448
  return version;
19384
19449
  }
19450
+ function managedPiTelemetryExtension(sharedRuntime) {
19451
+ const settings = record8(sharedRuntime.settings);
19452
+ const packages = Array.isArray(settings.packages) ? settings.packages : [];
19453
+ const configuredSources = packages.filter((source) => typeof source === "string" && (source === MANAGED_PI_TELEMETRY_PACKAGE_SOURCE || source.startsWith(`${MANAGED_PI_TELEMETRY_PACKAGE_SOURCE}@`)));
19454
+ if (configuredSources.length === 0) return null;
19455
+ if (configuredSources.length !== 1) {
19456
+ throw new Error("pi_managed_mcp_telemetry_package_source_invalid");
19457
+ }
19458
+ const configuredSource = configuredSources[0];
19459
+ const settingsVersion = configuredSource.startsWith(`${MANAGED_PI_TELEMETRY_PACKAGE_SOURCE}@`) ? configuredSource.slice(MANAGED_PI_TELEMETRY_PACKAGE_SOURCE.length + 1) : null;
19460
+ if (settingsVersion !== null && !/^\d+\.\d+\.\d+(?:[-+].+)?$/.test(settingsVersion)) {
19461
+ throw new Error("pi_managed_mcp_telemetry_package_source_unpinned");
19462
+ }
19463
+ const runtimeManifestPath = join5(sharedRuntime.home, "npm", "package.json");
19464
+ let runtimeManifest;
19465
+ try {
19466
+ const runtimeManifestStat = lstatSync3(runtimeManifestPath);
19467
+ if (!runtimeManifestStat.isFile() || runtimeManifestStat.isSymbolicLink()) {
19468
+ throw new Error("unsafe runtime package manifest");
19469
+ }
19470
+ runtimeManifest = record8(JSON.parse(readFileSync5(runtimeManifestPath, "utf8")));
19471
+ } catch {
19472
+ throw new Error("pi_managed_mcp_telemetry_runtime_manifest_unavailable");
19473
+ }
19474
+ const pinnedVersion = typeof record8(runtimeManifest.dependencies)[MANAGED_PI_TELEMETRY_PACKAGE] === "string" ? record8(runtimeManifest.dependencies)[MANAGED_PI_TELEMETRY_PACKAGE].trim() : "";
19475
+ if (!/^\d+\.\d+\.\d+(?:[-+].+)?$/.test(pinnedVersion)) {
19476
+ throw new Error("pi_managed_mcp_telemetry_runtime_manifest_unpinned");
19477
+ }
19478
+ if (settingsVersion !== null && settingsVersion !== pinnedVersion) {
19479
+ throw new Error("pi_managed_mcp_telemetry_package_source_version_mismatch");
19480
+ }
19481
+ const packageRoot = resolve3(
19482
+ sharedRuntime.home,
19483
+ "npm",
19484
+ "node_modules",
19485
+ "@amaster.ai",
19486
+ "pi-telemetry"
19487
+ );
19488
+ const packageJsonPath = join5(packageRoot, "package.json");
19489
+ let packageJson;
19490
+ try {
19491
+ const packageStat = lstatSync3(packageRoot);
19492
+ if (!packageStat.isDirectory() || packageStat.isSymbolicLink()) throw new Error("unsafe package root");
19493
+ const packageJsonStat = lstatSync3(packageJsonPath);
19494
+ if (!packageJsonStat.isFile() || packageJsonStat.isSymbolicLink()) throw new Error("unsafe package manifest");
19495
+ packageJson = record8(JSON.parse(readFileSync5(packageJsonPath, "utf8")));
19496
+ } catch {
19497
+ throw new Error("pi_managed_mcp_telemetry_package_unavailable");
19498
+ }
19499
+ if (packageJson.name !== MANAGED_PI_TELEMETRY_PACKAGE) {
19500
+ throw new Error("pi_managed_mcp_telemetry_package_invalid");
19501
+ }
19502
+ const version = typeof packageJson.version === "string" ? packageJson.version.trim() : "";
19503
+ if (!/^\d+\.\d+\.\d+(?:[-+].+)?$/.test(version)) {
19504
+ throw new Error("pi_managed_mcp_telemetry_package_version_invalid");
19505
+ }
19506
+ if (version !== pinnedVersion) {
19507
+ throw new Error("pi_managed_mcp_telemetry_package_version_mismatch");
19508
+ }
19509
+ const declaredExtensions = Array.isArray(record8(packageJson.pi).extensions) ? record8(packageJson.pi).extensions : [];
19510
+ if (declaredExtensions.length !== 1 || typeof declaredExtensions[0] !== "string") {
19511
+ throw new Error("pi_managed_mcp_telemetry_extension_invalid");
19512
+ }
19513
+ const extensionPath = resolve3(packageRoot, declaredExtensions[0]);
19514
+ if (!within2(extensionPath, packageRoot)) {
19515
+ throw new Error("pi_managed_mcp_telemetry_extension_unsafe");
19516
+ }
19517
+ try {
19518
+ const extensionStat = lstatSync3(extensionPath);
19519
+ if (!extensionStat.isFile() || extensionStat.isSymbolicLink()) throw new Error("unsafe extension entry");
19520
+ const realPackageRoot = realpathSync3(packageRoot);
19521
+ const realExtensionPath = realpathSync3(extensionPath);
19522
+ if (!within2(realExtensionPath, realPackageRoot)) throw new Error("extension escaped package root");
19523
+ } catch {
19524
+ throw new Error("pi_managed_mcp_telemetry_extension_unsafe");
19525
+ }
19526
+ let packageTreeSha256;
19527
+ try {
19528
+ packageTreeSha256 = trustedTreeDigest(packageRoot, { ignoredRootEntries: ["node_modules"] });
19529
+ } catch {
19530
+ throw new Error("pi_managed_mcp_telemetry_package_unsafe");
19531
+ }
19532
+ return {
19533
+ packageName: MANAGED_PI_TELEMETRY_PACKAGE,
19534
+ packageVersion: version,
19535
+ packageVersionSource: "runtime_npm_manifest",
19536
+ extensionPath,
19537
+ extensionSha256: sha2563(readFileSync5(extensionPath)),
19538
+ packageTreeSha256,
19539
+ langfuseEnabled: record8(record8(settings["pi-telemetry"]).langfuse).enabled === true
19540
+ };
19541
+ }
19385
19542
  function adapterServerConfigHash(definition, adapterVersion) {
19386
19543
  const identity2 = piMcpAdapterServerConfigIdentity(definition, adapterVersion);
19387
19544
  return sha2563(stablePiJson(identity2));
@@ -19750,7 +19907,7 @@ function createManagedPiMcpProfileApi(options = {}) {
19750
19907
  for (const [name, value] of Object.entries(settingsEnv)) {
19751
19908
  if (isSensitiveAuthKey2(name)) protectedValues.push(value);
19752
19909
  }
19753
- return { home, settingsEnv, protectedValues };
19910
+ return { home, settings, settingsEnv, protectedValues };
19754
19911
  }
19755
19912
  const SKILL_PROFILE_NAME = /^[a-z0-9-]+$/;
19756
19913
  function readSkillProfile(piHome, skillProfile) {
@@ -20009,6 +20166,11 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
20009
20166
  "--no-approve",
20010
20167
  "--no-skills",
20011
20168
  "--no-context-files",
20169
+ "--no-builtin-tools",
20170
+ // The probe attests only the governed adapter and run-owned attestor.
20171
+ // Ambient Pi extensions may fail independently and must not change this
20172
+ // measured tool surface; explicitly supplied extensions still load.
20173
+ "--no-extensions",
20012
20174
  // The enforcement extensions live in the run profile, not an agent dir,
20013
20175
  // so the probe must load them explicitly to measure the real run surface.
20014
20176
  ...Array.isArray(input.extensionArgs) ? input.extensionArgs : [],
@@ -20166,7 +20328,10 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
20166
20328
  commandId: input.commandId
20167
20329
  });
20168
20330
  const sharedRuntime = sharedPiHomeSettingsEnv(input.baseEnv);
20169
- const restoredNativeSession = restoreManagedPiSessionRollout(input, sessionsRoot, runDir, executorHome, authority);
20331
+ const {
20332
+ restoredNativeSession,
20333
+ nativeSessionRestoreSkippedReason
20334
+ } = resolveManagedPiSessionRollout(input, sessionsRoot, runDir, executorHome, authority);
20170
20335
  const directToolNames = directCatalog?.tools.map((tool) => tool.exposedName) ?? [];
20171
20336
  const serverConfig = {
20172
20337
  type: "http",
@@ -20364,6 +20529,10 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
20364
20529
  ...sourceAttestationProfilePath ? { sourceProfilePath: sourceAttestationProfilePath } : {}
20365
20530
  };
20366
20531
  }
20532
+ const telemetryExtension = managedPiTelemetryExtension(sharedRuntime);
20533
+ if (telemetryExtension) {
20534
+ extensionArgs.push("--extension", telemetryExtension.extensionPath);
20535
+ }
20367
20536
  let enabledRoleSkills = null;
20368
20537
  let enabledRoleSkillMetadataBytes = 0;
20369
20538
  let enabledRoleSkillMetadataSha256 = null;
@@ -20381,6 +20550,9 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
20381
20550
  const env = {
20382
20551
  ...sharedRuntime.settingsEnv,
20383
20552
  ...buildIsolatedEnvironment2(input.baseEnv, input.commandEnv),
20553
+ // The profile owns the final child environment. Never rely on a caller
20554
+ // supplied correlation value when governed telemetry is active.
20555
+ ...telemetryExtension ? { PI_TELEMETRY_TASK_RUN_ID: runId } : {},
20384
20556
  HOME: home,
20385
20557
  PI_AGENT_HOME: piAgentHome,
20386
20558
  PI_CODING_AGENT_SESSION_DIR: sessionsRoot,
@@ -20464,13 +20636,25 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
20464
20636
  enabledRoleSkills,
20465
20637
  enabledRoleSkillMetadataBytes,
20466
20638
  enabledRoleSkillMetadataSha256
20467
- )
20639
+ ),
20640
+ telemetryExtensionStatus: telemetryExtension ? "attested" : "not_configured",
20641
+ ...telemetryExtension ? {
20642
+ telemetryPackageName: telemetryExtension.packageName,
20643
+ telemetryPackageVersion: telemetryExtension.packageVersion,
20644
+ telemetryPackageVersionSource: telemetryExtension.packageVersionSource,
20645
+ telemetryExtensionPath: telemetryExtension.extensionPath,
20646
+ telemetryExtensionSha256: telemetryExtension.extensionSha256,
20647
+ telemetryPackageTreeSha256: telemetryExtension.packageTreeSha256,
20648
+ telemetryLangfuseEnabled: telemetryExtension.langfuseEnabled,
20649
+ telemetryRunCorrelationStatus: "authoritative"
20650
+ } : {}
20468
20651
  };
20469
20652
  return {
20470
20653
  profileRoot,
20471
20654
  owner,
20472
20655
  authority,
20473
20656
  restoredNativeSession,
20657
+ nativeSessionRestoreSkippedReason,
20474
20658
  configPath,
20475
20659
  markerPath,
20476
20660
  env,
@@ -20836,6 +21020,27 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
20836
21020
  `);
20837
21021
  return { status: "preserved", sessionId, rolloutPath: targetRollout, cacheRoot };
20838
21022
  }
21023
+ function cleanupRestoredManagedPiSessionRollout2(profile) {
21024
+ const restored = profile?.restoredNativeSession;
21025
+ if (!restored?.cacheRoot) return { status: "not_restored" };
21026
+ const cacheRoot = resolve3(restored.cacheRoot);
21027
+ if (!existsSync4(cacheRoot)) return { status: "already_removed" };
21028
+ const cacheStat = lstatSync3(cacheRoot);
21029
+ if (!cacheStat.isDirectory() || cacheStat.isSymbolicLink()) {
21030
+ throw new Error("pi_managed_mcp_session_rollout_cleanup_unsafe: cache root is not a private directory");
21031
+ }
21032
+ const markerPath = join5(cacheRoot, SESSION_ROLLOUT_MARKER2);
21033
+ if (!existsSync4(markerPath) || lstatSync3(markerPath).isSymbolicLink() || !lstatSync3(markerPath).isFile()) {
21034
+ throw new Error("pi_managed_mcp_session_rollout_cleanup_unsafe: ownership marker is unavailable");
21035
+ }
21036
+ const marker = JSON.parse(readFileSync5(markerPath, "utf8"));
21037
+ if (marker?.companyId !== profile.authority.companyId || marker?.agentId !== profile.authority.agentId || marker?.issueId !== profile.authority.issueId || marker?.sourceRunId !== restored.sourceRunId || marker?.sourceCommandId !== restored.sourceCommandId || marker?.sessionId !== restored.sessionId) {
21038
+ throw new Error("pi_managed_mcp_session_rollout_cleanup_unsafe: ownership marker does not match restored authority");
21039
+ }
21040
+ rmSync3(cacheRoot, { recursive: true, force: false });
21041
+ if (existsSync4(cacheRoot)) throw new Error("pi_managed_mcp_session_rollout_cleanup_failed: cache root still exists");
21042
+ return { status: "removed" };
21043
+ }
20839
21044
  function removeWorkspaceMcpConfig(configPath, profileRoot) {
20840
21045
  const target = resolve3(configPath);
20841
21046
  if (!workspaceMcpConfigBelongsToProfile(target, profileRoot)) {
@@ -20987,7 +21192,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
20987
21192
  failures
20988
21193
  };
20989
21194
  }
20990
- return { prepareManagedPiMcpProfile: prepareManagedPiMcpProfile2, prepareDelegatedPiMcpProfile: prepareDelegatedPiMcpProfile2, inspectManagedPiRunExitClosureAttestation: inspectManagedPiRunExitClosureAttestation2, restoreManagedPiRunExitClosureBaseline: restoreManagedPiRunExitClosureBaseline2, preserveManagedPiSessionRollout: preserveManagedPiSessionRollout2, cleanupManagedPiMcpProfile: cleanupManagedPiMcpProfile2, cleanupDelegatedPiMcpProfile: cleanupDelegatedPiMcpProfile2, reconcileManagedPiMcpProfiles: reconcileManagedPiMcpProfiles2 };
21195
+ return { prepareManagedPiMcpProfile: prepareManagedPiMcpProfile2, prepareDelegatedPiMcpProfile: prepareDelegatedPiMcpProfile2, inspectManagedPiRunExitClosureAttestation: inspectManagedPiRunExitClosureAttestation2, restoreManagedPiRunExitClosureBaseline: restoreManagedPiRunExitClosureBaseline2, preserveManagedPiSessionRollout: preserveManagedPiSessionRollout2, cleanupRestoredManagedPiSessionRollout: cleanupRestoredManagedPiSessionRollout2, cleanupManagedPiMcpProfile: cleanupManagedPiMcpProfile2, cleanupDelegatedPiMcpProfile: cleanupDelegatedPiMcpProfile2, reconcileManagedPiMcpProfiles: reconcileManagedPiMcpProfiles2 };
20991
21196
  }
20992
21197
  var piManagedMcpProfileApi = createManagedPiMcpProfileApi();
20993
21198
  var prepareManagedPiMcpProfile = piManagedMcpProfileApi.prepareManagedPiMcpProfile;
@@ -20995,6 +21200,7 @@ var prepareDelegatedPiMcpProfile = piManagedMcpProfileApi.prepareDelegatedPiMcpP
20995
21200
  var inspectManagedPiRunExitClosureAttestation = piManagedMcpProfileApi.inspectManagedPiRunExitClosureAttestation;
20996
21201
  var restoreManagedPiRunExitClosureBaseline = piManagedMcpProfileApi.restoreManagedPiRunExitClosureBaseline;
20997
21202
  var preserveManagedPiSessionRollout = piManagedMcpProfileApi.preserveManagedPiSessionRollout;
21203
+ var cleanupRestoredManagedPiSessionRollout = piManagedMcpProfileApi.cleanupRestoredManagedPiSessionRollout;
20998
21204
  var cleanupManagedPiMcpProfile = piManagedMcpProfileApi.cleanupManagedPiMcpProfile;
20999
21205
  var cleanupDelegatedPiMcpProfile = piManagedMcpProfileApi.cleanupDelegatedPiMcpProfile;
21000
21206
  var reconcileManagedPiMcpProfiles = piManagedMcpProfileApi.reconcileManagedPiMcpProfiles;
@@ -28407,7 +28613,7 @@ function createSourceCompletionStopPolicy({
28407
28613
  }
28408
28614
 
28409
28615
  // src/amaster-runtime-daemon.mjs
28410
- var CONNECTOR_VERSION = "0.1.1-beta.122";
28616
+ var CONNECTOR_VERSION = "0.1.1-beta.124";
28411
28617
  var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
28412
28618
  var SOURCE_ACQUISITION_CAPABILITY2 = source_acquisition_compatibility_default.profileVersion;
28413
28619
  var daemonRequire = createRequire(import.meta.url);
@@ -30260,7 +30466,7 @@ function sanitizePiExtraArgs(value) {
30260
30466
  return splitExtraArgs(value).filter((entry) => !AMASTER_PI_PROHIBITED_EXTRA_ARGS.has(entry));
30261
30467
  }
30262
30468
  function nativeSessionResumeEnabled(session) {
30263
- return process.env.AMASTER_RUNTIME_ENABLE_NATIVE_SESSION_RESUME === "true" || readString(session.mode) === "governed_action_approval" && session.required === true;
30469
+ return process.env.AMASTER_RUNTIME_ENABLE_NATIVE_SESSION_RESUME === "true" || readString(session.mode) === "task_session" || readString(session.mode) === "governed_action_approval" && session.required === true;
30264
30470
  }
30265
30471
  function modelCallResponseContract(payload) {
30266
30472
  if (payload.responseContract === void 0) return null;
@@ -30377,8 +30583,8 @@ function buildExecutorInvocation(executor, command = {}, workspace = null, optio
30377
30583
  const args = ["--mode", "json"];
30378
30584
  const governedRun = Object.keys(asRecord(commandRuntimeAuth(command).governedMcp)).length > 0;
30379
30585
  const nativeSessionRequest = asRecord(asRecord(command.payload).nativeSession);
30380
- if (governedRun && nativeSession.used && (nativeSessionRequest.mode !== "governed_action_approval" || nativeSessionRequest.required !== true)) {
30381
- throw new Error("pi_managed_mcp_native_session_resume_blocked: governed Pi runs require exact approval continuation authority");
30586
+ if (governedRun && nativeSession.used && !(nativeSessionRequest.mode === "governed_action_approval" && nativeSessionRequest.required === true || nativeSessionRequest.mode === "task_session" && nativeSessionRequest.required === false)) {
30587
+ throw new Error("pi_managed_mcp_native_session_resume_blocked: governed Pi runs require exact continuation authority");
30382
30588
  }
30383
30589
  const provider = readString(process.env.AMASTER_PI_PROVIDER);
30384
30590
  const model = readString(process.env.AMASTER_PI_MODEL);
@@ -33556,6 +33762,23 @@ async function executeRunCommand(config, command) {
33556
33762
  }
33557
33763
  }
33558
33764
  if (managedMcpProfile) {
33765
+ if (nativeSessionRequest.mode === "task_session" && asRecord(invocation.nativeSession).used === true && !managedMcpProfile.restoredNativeSession) {
33766
+ const freshPayload = { ...asRecord(command.payload) };
33767
+ delete freshPayload.nativeSession;
33768
+ const freshInvocation = buildExecutorInvocation(
33769
+ executor,
33770
+ { ...command, payload: freshPayload },
33771
+ workspace
33772
+ );
33773
+ invocation.args = freshInvocation.args;
33774
+ invocation.stdin = freshInvocation.stdin;
33775
+ invocation.nativeSession = {
33776
+ ...asRecord(invocation.nativeSession),
33777
+ mode: "fresh",
33778
+ used: false,
33779
+ skippedReason: readString(managedMcpProfile.nativeSessionRestoreSkippedReason) ?? "native_session_rollout_missing"
33780
+ };
33781
+ }
33559
33782
  executorEnv = managedMcpProfile.env;
33560
33783
  if (executor.kind === "pi" && managedMcpProfile.spawnIdentity) {
33561
33784
  piExecutorIdentity = managedMcpProfile.spawnIdentity;
@@ -33963,7 +34186,11 @@ async function executeRunCommand(config, command) {
33963
34186
  parsed.hasAssistantOutput = true;
33964
34187
  }
33965
34188
  }
33966
- const shouldPreserveNativeSession = managedMcpProfile && parsed.sessionId && (execution.exitCode === 0 || execution.completionOutputType === "approval_required") && !execution.timedOut && execution.cancelled !== true && !execution.spawnError && ["codex", "pi"].includes(executor.kind) && mcpToolResults.some((result4) => readString(result4.status) === "approval_required");
34189
+ const approvalRequiredSession = mcpToolResults.some(
34190
+ (result4) => readString(result4.status) === "approval_required"
34191
+ );
34192
+ const piTerminalSessionCandidate = executor.kind === "pi" && parsed.hasAssistantOutput === true && ["agent_end", "turn_end"].includes(readString(parsed.terminalEventType) ?? "");
34193
+ const shouldPreserveNativeSession = managedMcpProfile && parsed.sessionId && (execution.exitCode === 0 || execution.completionOutputType === "approval_required" || piTerminalSessionCandidate) && !execution.timedOut && execution.cancelled !== true && !execution.spawnError && ["codex", "pi"].includes(executor.kind) && (execution.exitCode === 0 || approvalRequiredSession || piTerminalSessionCandidate);
33967
34194
  if (shouldPreserveNativeSession) {
33968
34195
  try {
33969
34196
  const preserveSessionRollout = executor.kind === "pi" ? preserveManagedPiSessionRollout : preserveManagedCodexSessionRollout;
@@ -33971,7 +34198,7 @@ async function executeRunCommand(config, command) {
33971
34198
  sessionId: parsed.sessionId,
33972
34199
  sourceWorkspacePath: workspace.sourceWorkspacePath
33973
34200
  });
33974
- const checkpoint = await saveIssueCheckpoint(
34201
+ const checkpoint = approvalRequiredSession ? await saveIssueCheckpoint(
33975
34202
  config,
33976
34203
  command,
33977
34204
  workspace,
@@ -33979,23 +34206,30 @@ async function executeRunCommand(config, command) {
33979
34206
  rawPath: artifact.relativePath,
33980
34207
  filePath: resolve13(cwd, artifact.relativePath)
33981
34208
  }))
33982
- );
34209
+ ) : null;
33983
34210
  nativeSessionRollout = {
33984
34211
  status: preservedRollout.status,
33985
34212
  sessionId: preservedRollout.sessionId,
33986
34213
  ...checkpoint ? { checkpoint: { fileCount: checkpoint.files.length, totalBytes: checkpoint.totalBytes } } : {}
33987
34214
  };
33988
- await ingestLog(config, command, "system", "info", `Preserved ${executor.kind} session rollout for an approved action continuation`, {
34215
+ await ingestLog(config, command, "system", "info", `Preserved ${executor.kind} session rollout for a governed continuation`, {
33989
34216
  presentationKind: "managed_mcp_session_rollout",
33990
34217
  status: nativeSessionRollout.status,
33991
34218
  sessionId: parsed.sessionId
33992
34219
  });
33993
34220
  } catch (err) {
33994
- nativeSessionRolloutError = `${executor.kind}_managed_mcp_session_rollout_failed: ${err instanceof Error ? err.message : String(err)}`;
33995
- await ingestLog(config, command, "system", "error", nativeSessionRolloutError, {
34221
+ const rolloutError = `${executor.kind}_managed_mcp_session_rollout_failed: ${err instanceof Error ? err.message : String(err)}`;
34222
+ if (approvalRequiredSession) {
34223
+ nativeSessionRolloutError = rolloutError;
34224
+ } else {
34225
+ nativeSessionRollout = {
34226
+ status: "unavailable",
34227
+ skippedReason: "native_session_rollout_unavailable"
34228
+ };
34229
+ }
34230
+ await ingestLog(config, command, "system", approvalRequiredSession ? "error" : "warn", approvalRequiredSession ? rolloutError : `Could not preserve the optional ${executor.kind} task-session rollout`, {
33996
34231
  presentationKind: "managed_mcp_session_rollout",
33997
- status: "failed",
33998
- sessionId: parsed.sessionId
34232
+ status: approvalRequiredSession ? "failed" : "unavailable"
33999
34233
  });
34000
34234
  }
34001
34235
  }
@@ -34003,20 +34237,29 @@ async function executeRunCommand(config, command) {
34003
34237
  if (approvedContinuationSucceeded) {
34004
34238
  await clearIssueCheckpoint(config, command, workspace, "approved_action_succeeded");
34005
34239
  }
34006
- if (managedMcpProfile && executor.kind === "codex" && approvedContinuationSucceeded) {
34240
+ const taskSessionContinuationSucceeded = nativeSessionRequest.mode === "task_session" && asRecord(invocation.nativeSession).used === true && shouldPreserveNativeSession && nativeSessionRollout?.status === "preserved";
34241
+ if (managedMcpProfile && (approvedContinuationSucceeded || taskSessionContinuationSucceeded)) {
34007
34242
  try {
34008
- nativeSessionRolloutCleanup = cleanupRestoredManagedCodexSessionRollout(managedMcpProfile);
34009
- await ingestLog(config, command, "system", "info", "Removed the consumed Codex session rollout", {
34243
+ const cleanupRestoredSessionRollout = executor.kind === "pi" ? cleanupRestoredManagedPiSessionRollout : cleanupRestoredManagedCodexSessionRollout;
34244
+ nativeSessionRolloutCleanup = cleanupRestoredSessionRollout(managedMcpProfile);
34245
+ await ingestLog(config, command, "system", "info", `Removed the consumed ${executor.kind} session rollout`, {
34010
34246
  presentationKind: "managed_mcp_session_rollout_cleanup",
34011
34247
  status: nativeSessionRolloutCleanup.status,
34012
34248
  sessionId: readString(nativeSessionRequest.sessionId)
34013
34249
  });
34014
34250
  } catch (err) {
34015
- nativeSessionRolloutCleanupError = `codex_managed_mcp_session_rollout_cleanup_failed: ${err instanceof Error ? err.message : String(err)}`;
34016
- await ingestLog(config, command, "system", "error", nativeSessionRolloutCleanupError, {
34251
+ const cleanupError = `${executor.kind}_managed_mcp_session_rollout_cleanup_failed: ${err instanceof Error ? err.message : String(err)}`;
34252
+ if (approvedContinuationSucceeded) {
34253
+ nativeSessionRolloutCleanupError = cleanupError;
34254
+ } else {
34255
+ nativeSessionRolloutCleanup = {
34256
+ status: "failed",
34257
+ skippedReason: "native_session_rollout_cleanup_failed"
34258
+ };
34259
+ }
34260
+ await ingestLog(config, command, "system", approvedContinuationSucceeded ? "error" : "warn", approvedContinuationSucceeded ? cleanupError : `Could not clean the consumed optional ${executor.kind} task-session rollout`, {
34017
34261
  presentationKind: "managed_mcp_session_rollout_cleanup",
34018
- status: "failed",
34019
- sessionId: readString(nativeSessionRequest.sessionId)
34262
+ status: "failed"
34020
34263
  });
34021
34264
  }
34022
34265
  }
@@ -6,7 +6,7 @@ import { basename, dirname, join, resolve } from "node:path";
6
6
  import { homedir, hostname } from "node:os";
7
7
  import { fileURLToPath } from "node:url";
8
8
 
9
- const CONNECTOR_VERSION = "0.1.1-beta.122";
9
+ const CONNECTOR_VERSION = "0.1.1-beta.124";
10
10
 
11
11
  const CAPABILITIES = [
12
12
  "remote_registration",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amaster.ai/employee-runtime-connector",
3
- "version": "0.1.1-beta.122",
3
+ "version": "0.1.1-beta.124",
4
4
  "description": "MirrorX runtime connector CLI and daemon",
5
5
  "license": "MIT",
6
6
  "type": "module",